Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3f8f673c authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Expand loc bg perm after grandfathering it

The loc bg perm is restricted. Hence it cannot be granted unless
whitelisted. Hence we need to grandfather==whitelist is before we try to
grand it later in the "Expanding location permissions" step.

Test: Upgraded P->Q and saw permissions expanded
Fixes: 118661683
Change-Id: Icf653eda9a51a9687d832ec225ccbe6a2c7686e9
parent 203be033
Loading
Loading
Loading
Loading
+41 −36
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ class RuntimePermissionsUpgradeController {
    private static final String LOG_TAG = RuntimePermissionsUpgradeController.class.getSimpleName();

    // The latest version of the runtime permissions database
    private static final int LATEST_VERSION = 4;
    private static final int LATEST_VERSION = 5;

    private RuntimePermissionsUpgradeController() {
        /* do nothing - hide constructor */
@@ -116,41 +116,7 @@ class RuntimePermissionsUpgradeController {
        }

        if (currentVersion == 1) {
            if (sdkUpgradedFromP) {
                Log.i(LOG_TAG, "Expanding location permissions");

                for (int i = 0; i < appCount; i++) {
                    final PackageInfo app = apps.get(i);
                    if (app.requestedPermissions == null) {
                        continue;
                    }

                    for (String perm : app.requestedPermissions) {
                        String groupName = Utils.getGroupOfPlatformPermission(perm);

                        if (!TextUtils.equals(groupName, Manifest.permission_group.LOCATION)) {
                            continue;
                        }

                        final AppPermissionGroup group = AppPermissionGroup.create(context, app,
                                perm, false);
                        final AppPermissionGroup bgGroup = group.getBackgroundPermissions();

                        if (group.areRuntimePermissionsGranted()
                                && bgGroup != null
                                && !bgGroup.isUserSet() && !bgGroup.isSystemFixed()
                                && !bgGroup.isPolicyFixed()) {
                            bgGroup.grantRuntimePermissions(group.isUserFixed());
                        }

                        break;
                    }
                }
            } else {
                Log.i(LOG_TAG, "Not expanding location permissions as this is not an upgrade "
                        + "from Android P");
            }

            // moved to step 4->5 as it has to be after the grandfathering of loc bg perms
            currentVersion = 2;
        }

@@ -201,6 +167,45 @@ class RuntimePermissionsUpgradeController {
            currentVersion = 4;
        }

        if (currentVersion == 4) {
            if (sdkUpgradedFromP) {
                Log.i(LOG_TAG, "Expanding location permissions");

                for (int i = 0; i < appCount; i++) {
                    final PackageInfo app = apps.get(i);
                    if (app.requestedPermissions == null) {
                        continue;
                    }

                    for (String perm : app.requestedPermissions) {
                        String groupName = Utils.getGroupOfPlatformPermission(perm);

                        if (!TextUtils.equals(groupName, Manifest.permission_group.LOCATION)) {
                            continue;
                        }

                        final AppPermissionGroup group = AppPermissionGroup.create(context, app,
                                perm, false);
                        final AppPermissionGroup bgGroup = group.getBackgroundPermissions();

                        if (group.areRuntimePermissionsGranted()
                                && bgGroup != null
                                && !bgGroup.isUserSet() && !bgGroup.isSystemFixed()
                                && !bgGroup.isPolicyFixed()) {
                            bgGroup.grantRuntimePermissions(group.isUserFixed());
                        }

                        break;
                    }
                }
            } else {
                Log.i(LOG_TAG, "Not expanding location permissions as this is not an upgrade "
                        + "from Android P");
            }

            currentVersion = 5;
        }

        // XXX: Add new upgrade steps above this point.

        return currentVersion;