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

Commit 38bdaef0 authored by Gavin Corkery's avatar Gavin Corkery
Browse files

Remove redundant module check when enabling rollback

The rollback allowlist configuration now covers all packages
which may be rolled back, so this extra isModule check can
be safely removed.

Test: atest RollbackTest
Bug: 171197192
Change-Id: I2627628d845bd0772638f8006d9867fc86ad3d7d
parent bc89f3ea
Loading
Loading
Loading
Loading
+4 −22
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.pm.ApplicationInfo;
import android.content.pm.ModuleInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
@@ -1089,8 +1088,8 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub implements Rollba
                Manifest.permission.TEST_MANAGE_ROLLBACKS,
                installerPackageName) == PackageManager.PERMISSION_GRANTED;

        // For now only allow rollbacks for modules or for testing.
        return (isRollbackWhitelisted(packageName) && manageRollbacksGranted)
        // For now only allow rollbacks for allowlisted packages or for testing.
        return (isRollbackAllowlisted(packageName) && manageRollbacksGranted)
            || testManageRollbacksGranted;
    }

@@ -1098,25 +1097,8 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub implements Rollba
     * Returns true is this package is eligible for enabling rollback.
     */
    @AnyThread
    private boolean isRollbackWhitelisted(String packageName) {
        // TODO: Remove #isModule when the allowlist is ready.
        return SystemConfig.getInstance().getRollbackWhitelistedPackages().contains(packageName)
                || isModule(packageName);
    }
    /**
     * Returns true if the package name is the name of a module.
     */
    @AnyThread
    private boolean isModule(String packageName) {
        PackageManager pm = mContext.getPackageManager();
        final ModuleInfo moduleInfo;
        try {
            moduleInfo = pm.getModuleInfo(packageName, 0);
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }

        return moduleInfo != null;
    private boolean isRollbackAllowlisted(String packageName) {
        return SystemConfig.getInstance().getRollbackWhitelistedPackages().contains(packageName);
    }

    /**