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

Commit 2cae9f62 authored by Robin Lee's avatar Robin Lee
Browse files

shell pm: move context creation to where it's used

If something went wrong with the shell package, it's useful for pm
commands to still work so that a developer is still able to put
things back the way they were.

Test: atest CtsNativeMediaAAudioTestCases --user-type secondary_user
Bug: 159157348
Change-Id: I9d3b4f8f93496a5df2055681bd88c61adc435408
parent ad448160
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ class PackageManagerShellCommand extends ShellCommand {

    final IPackageManager mInterface;
    final IPermissionManager mPermissionManager;
    final Context mShellPackageContext;
    final Context mContext;
    final private WeakHashMap<String, Resources> mResourceCache =
            new WeakHashMap<String, Resources>();
    int mTargetUser;
@@ -158,13 +158,7 @@ class PackageManagerShellCommand extends ShellCommand {
            PackageManagerService service, IPermissionManager permissionManager, Context context) {
        mInterface = service;
        mPermissionManager = permissionManager;
        try {
            mShellPackageContext = context.createPackageContextAsUser(
                    "com.android.shell", 0, Binder.getCallingUserHandle());
        } catch (NameNotFoundException e) {
            // should not happen
            throw new RuntimeException(e);
        }
        mContext = context;
    }

    @Override
@@ -487,8 +481,17 @@ class PackageManagerShellCommand extends ShellCommand {
            return 1;
        }

        final Context shellPackageContext;
        try {
            shellPackageContext = mContext.createPackageContextAsUser(
                    "com.android.shell", 0, Binder.getCallingUserHandle());
        } catch (NameNotFoundException e) {
            // should not happen
            throw new RuntimeException(e);
        }

        final LocalIntentReceiver receiver = new LocalIntentReceiver();
        RollbackManager rm = mShellPackageContext.getSystemService(RollbackManager.class);
        RollbackManager rm = shellPackageContext.getSystemService(RollbackManager.class);
        RollbackInfo rollback = null;
        for (RollbackInfo r : rm.getAvailableRollbacks()) {
            for (PackageRollbackInfo info : r.getPackages()) {