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

Commit 485d8093 authored by Manjeet Rulhania's avatar Manjeet Rulhania
Browse files

make upgrade version combination resilient

With "==" the version combination was rigid and there could
be edge cases where the exact combination is not matched.
This may result in upgrade steps being not executed and could
impact users. With "<=" we are trying to be more flexible in
terms of version combination and also allowing packages upgrade
even in case of no combination mach.

Fix: 276508167
Test: presubmit/build
Change-Id: If5f489b726c2a82889b16a399ebf63beaa3b5593
parent 24a7d468
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -43,4 +43,9 @@ public interface AppOpMigrationHelper {
     * @return AppOps file version, the version is same for all the user.
     */
    int getLegacyAppOpVersion();

    /**
     * @return Whether app-op state exists or not.
     */
    boolean hasLegacyAppOpState();
}
+18 −1
Original line number Diff line number Diff line
@@ -77,7 +77,19 @@ public class AppOpMigrationHelperImpl implements AppOpMigrationHelper {
                new SparseArray<>();

        LegacyAppOpStateParser parser = new LegacyAppOpStateParser();
        mVersionAtBoot = parser.readState(appOpFile, uidAppOpModes, packageAppOpModes);
        final int version = parser.readState(appOpFile, uidAppOpModes, packageAppOpModes);
        // -1 No app ops data available
        // 0 appops.xml exist w/o any version
        switch (version) {
            case -2:
                mVersionAtBoot = -1;
                break;
            case -1:
                mVersionAtBoot = 0;
                break;
            default:
                mVersionAtBoot = version;
        }
        mAppIdAppOpModes = getAppIdAppOpModes(uidAppOpModes);
        mPackageAppOpModes = getPackageAppOpModes(packageAppOpModes);
    }
@@ -152,4 +164,9 @@ public class AppOpMigrationHelperImpl implements AppOpMigrationHelper {
        }
        return mVersionAtBoot;
    }

    @Override
    public boolean hasLegacyAppOpState() {
        return getLegacyAppOpVersion() > -1;
    }
}
+11 −1
Original line number Diff line number Diff line
@@ -27,6 +27,11 @@ import java.util.Map;
 * @hide
 */
public interface PermissionMigrationHelper {
    /**
     * Whether legacy permission definitions/trees exist or not.
     */
    boolean hasLegacyPermission();

    /**
     * @return legacy permission definitions.
     */
@@ -48,7 +53,12 @@ public interface PermissionMigrationHelper {
    /**
     * @return permissions file version for the given user.
     */
    int getLegacyPermissionsVersion(int userId);
    int getLegacyPermissionStateVersion(int userId);

    /**
     * @return true if permissions state exists or not.
     */
    boolean hasLegacyPermissionState(int userId);

    /**
     * Legacy permission definition.
+26 −2
Original line number Diff line number Diff line
@@ -39,6 +39,15 @@ import java.util.Map;
public class PermissionMigrationHelperImpl implements PermissionMigrationHelper {
    private static final String LOG_TAG = PermissionMigrationHelperImpl.class.getSimpleName();

    @Override
    public boolean hasLegacyPermission() {
        PackageManagerInternal packageManagerInternal =
                LocalServices.getService(PackageManagerInternal.class);
        LegacyPermissionSettings legacySettings = packageManagerInternal.getLegacyPermissions();
        return !(legacySettings.getPermissions().isEmpty()
                && legacySettings.getPermissionTrees().isEmpty());
    }

    /**
     * @return legacy permission definitions.
     */
@@ -122,10 +131,25 @@ public class PermissionMigrationHelperImpl implements PermissionMigrationHelper
    }

    @Override
    public int getLegacyPermissionsVersion(int userId) {
    public int getLegacyPermissionStateVersion(int userId) {
        PackageManagerInternal packageManagerInternal =
                LocalServices.getService(PackageManagerInternal.class);
        return packageManagerInternal.getLegacyPermissionsVersion(userId);
        int version = packageManagerInternal.getLegacyPermissionsVersion(userId);
        // -1 No permission data available
        // 0 runtime-permissions.xml exist w/o any version
        switch (version) {
            case -1:
                return 0;
            case 0:
                return -1;
            default:
                return version;
        }
    }

    @Override
    public boolean hasLegacyPermissionState(int userId) {
        return getLegacyPermissionStateVersion(userId) > -1;
    }

    @NonNull
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@ import com.android.server.permission.access.util.PackageVersionMigration
class AppIdAppOpMigration {
    fun migrateUserState(state: MutableAccessState, userId: Int) {
        val legacyAppOpsManager = LocalServices.getService(AppOpMigrationHelper::class.java)!!
        if (!legacyAppOpsManager.hasLegacyAppOpState()) {
            return
        }

        val legacyAppIdAppOpModes = legacyAppOpsManager.getLegacyAppIdAppOpModes(userId)
        val version = PackageVersionMigration.getVersion(userId)

Loading