1. 程式人生 > >某個應用 獲取許可權組

某個應用 獲取許可權組

hbw.net.com.work包名
AppPermissions.java --->AppPermissionGroup.java


0 = "android.permission.CALL_PHONE"
1 = "android.permission.READ_EXTERNAL_STORAGE"
2 = "android.permission.INTERNET"
3 = "android.permission.ACCESS_NETWORK_STATE"
4 = "android.permission.ACCESS_WIFI_STATE"
5 = "android.permission.READ_PHONE_STATE"
6 = "android.permission.ACCESS_COARSE_LOCATION"
7 = "android.permission.WRITE_SETTINGS"
8 = "android.permission.WRITE_EXTERNAL_STORAGE"
9 = "android.permission.READ_CONTACTS"
10 = "android.permission.READ_SMS"
11 = "android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"
12 = "android.permission.CAMERA"
13 = "android.hardware.camera"
14 = "android.permission.FLASHLIGHT"
15 = "org.fidoalliance.uaf.permissions.FIDO_CLIENT"
16 = "android.permission.USE_FINGERPRINT"
17 = "com.fingerprints.service.ACCESS_FINGERPRINT_MANAGER"
18 = "com.sec.feature.fingerprint_manager_service"
19 = "android.permission.ACCESS_FINE_LOCATION"
20 = "android.permission.CHANGE_WIFI_STATE"
21 = "android.permission.WAKE_LOCK"
22 = "android.permission.CHANGE_NETWORK_STATE"
23 = "android.permission.GET_TASKS"
24 = "android.permission.RECEIVE_BOOT_COMPLETED"
25 = "android.permission.BROADCAST_PACKAGE_ADDED"
26 = "android.permission.BROADCAST_PACKAGE_CHANGED"
27 = "android.permission.BROADCAST_PACKAGE_INSTALL"
28 = "android.permission.BROADCAST_PACKAGE_REPLACED"
29 = "android.permission.RESTART_PACKAGES"
30 = "android.permission.GET_ACCOUNTS"
31 = "android.permission.VIBRATE"
32 = "android.permission.SEND_SMS"
33 = "android.permission.RECEIVE_SMS"

 

 

     for (String requestedPerm : mPackageInfo.requestedPermissions) {
                addPermissionGroupIfNeeded(requestedPerm);
            }
=====>

    private void addPermissionGroupIfNeeded(String permission) {
        if (getGroupForPermission(permission) != null) {
            return;
        }

        AppPermissionGroup group = AppPermissionGroup.create(mContext,
                mPackageInfo, permission);
        if (group == null) {
            return;
        }

        mGroups.add(group);
    }


====>
 public static AppPermissionGroup create(Context context, PackageInfo packageInfo,
            String permissionName) {
        PermissionInfo permissionInfo;
        try {
            permissionInfo = context.getPackageManager().getPermissionInfo(permissionName, 0);
        } catch (PackageManager.NameNotFoundException e) {
            return null;
        }

        if ((permissionInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE)
                != PermissionInfo.PROTECTION_DANGEROUS
                || (permissionInfo.flags & PermissionInfo.FLAG_INSTALLED) == 0
                || (permissionInfo.flags & PermissionInfo.FLAG_REMOVED) != 0) {
            return null;
        }

        PackageItemInfo groupInfo = permissionInfo;
        if (permissionInfo.group != null) {
            try {
                groupInfo = context.getPackageManager().getPermissionGroupInfo(
                        permissionInfo.group, 0);
            } catch (PackageManager.NameNotFoundException e) {
                /* ignore */
            }
        }

        List<PermissionInfo> permissionInfos = null;
        if (groupInfo instanceof PermissionGroupInfo) {
            try {
                permissionInfos = context.getPackageManager().queryPermissionsByGroup(
                        groupInfo.name, 0);
            } catch (PackageManager.NameNotFoundException e) {
                /* ignore */
            }
        }

        return create(context, packageInfo, groupInfo, permissionInfos,
                Process.myUserHandle());
    }


===>
public static AppPermissionGroup create(Context context, PackageInfo packageInfo,
            PackageItemInfo groupInfo, List<PermissionInfo> permissionInfos,
            UserHandle userHandle) {

        AppPermissionGroup group = new AppPermissionGroup(context, packageInfo, groupInfo.name,
                groupInfo.packageName, groupInfo.loadLabel(context.getPackageManager()),
                loadGroupDescription(context, groupInfo), groupInfo.packageName, groupInfo.icon,
                userHandle);

        if (groupInfo instanceof PermissionInfo) {
            permissionInfos = new ArrayList<>();
            permissionInfos.add((PermissionInfo) groupInfo);
        }

        if (permissionInfos == null || permissionInfos.isEmpty()) {
            return null;
        }

        final int permissionCount = packageInfo.requestedPermissions.length;
        for (int i = 0; i < permissionCount; i++) {
            String requestedPermission = packageInfo.requestedPermissions[i];

            PermissionInfo requestedPermissionInfo = null;

            for (PermissionInfo permissionInfo : permissionInfos) {
                if (requestedPermission.equals(permissionInfo.name)) {
                    requestedPermissionInfo = permissionInfo;
                    break;
                }
            }

            if (requestedPermissionInfo == null) {
                continue;
            }

            // Collect only runtime permissions.
            if ((requestedPermissionInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE)
                    != PermissionInfo.PROTECTION_DANGEROUS) {
                continue;
            }

            // Don't allow toggling non-platform permission groups for legacy apps via app ops.
            if (packageInfo.applicationInfo.targetSdkVersion <= Build.VERSION_CODES.LOLLIPOP_MR1
                    && !PLATFORM_PACKAGE_NAME.equals(groupInfo.packageName)) {
                continue;
            }

            final boolean granted = (packageInfo.requestedPermissionsFlags[i]
                    & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;

            final String appOp = PLATFORM_PACKAGE_NAME.equals(requestedPermissionInfo.packageName)
                    ? AppOpsManager.permissionToOp(requestedPermissionInfo.name) : null;

            final boolean appOpAllowed = appOp != null
                    && context.getSystemService(AppOpsManager.class).checkOpNoThrow(appOp,
                    packageInfo.applicationInfo.uid, packageInfo.packageName)
                    == AppOpsManager.MODE_ALLOWED;

            final int flags = context.getPackageManager().getPermissionFlags(
                    requestedPermission, packageInfo.packageName, userHandle);

            Permission permission = new Permission(requestedPermission, granted,
                    appOp, appOpAllowed, flags, requestedPermissionInfo.protectionLevel);
            group.addPermission(permission);
        }

        return group;
    }