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

Commit 737f6f7a authored by JW Wang's avatar JW Wang
Browse files

Restore the isModule check when enabling rollback for apps

This is effectively a revert of ag/12874515.

Bug: 171852511
Test: atest RollbackTest StagedRollbackTest
Change-Id: I566ffe0417ed460006917e1f2e08981a7943c63b
parent d00e7d7c
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ 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;
@@ -1088,8 +1089,8 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub implements Rollba
                Manifest.permission.TEST_MANAGE_ROLLBACKS,
                installerPackageName) == PackageManager.PERMISSION_GRANTED;

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

@@ -1097,8 +1098,24 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub implements Rollba
     * Returns true is this package is eligible for enabling rollback.
     */
    @AnyThread
    private boolean isRollbackAllowlisted(String packageName) {
        return SystemConfig.getInstance().getRollbackWhitelistedPackages().contains(packageName);
    private boolean isRollbackAllowed(String packageName) {
        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;
    }

    /**