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

Commit 436d9313 authored by Evan Chen's avatar Evan Chen Committed by Mohammed Althaf T
Browse files

Make sure to disassociate all the packages with shared UID

Test: cts
Bug: 427206637
Flag: Flag: EXEMPT bugfix
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:a11c34ec2986e88d166a51c1d7835ca25be27d16
Merged-In: I751d724cefe415000646d1640c65e74af52a6688
Change-Id: I751d724cefe415000646d1640c65e74af52a6688
parent 1c0e8626
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.companion.AssociationInfo;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.os.Binder;
import android.os.UserHandle;
@@ -62,6 +63,7 @@ public class AssociationRevokeProcessor {
    private final @NonNull CompanionApplicationController mCompanionAppController;
    private final OnPackageVisibilityChangeListener mOnPackageVisibilityChangeListener;
    private final ActivityManager mActivityManager;
    private final PackageManager mPackageManager;

    /**
     * A structure that consists of a set of revoked associations that pending for role holder
@@ -101,6 +103,7 @@ public class AssociationRevokeProcessor {
        mActivityManager = mContext.getSystemService(ActivityManager.class);
        mAssociationStore = associationStore;
        mPackageManagerInternal = packageManager;
        mPackageManager = mContext.getPackageManager();
        mOnPackageVisibilityChangeListener =
                new OnPackageVisibilityChangeListener(mActivityManager);
        mDevicePresenceMonitor = devicePresenceMonitor;
@@ -339,8 +342,10 @@ public class AssociationRevokeProcessor {
                return;
            }

            final String packageName = getPackageNameByUid(uid);
            if (packageName == null) {
            // A UID can be shared by multiple packages if android:sharedUserId is used.
            // We must get all packages for the UID to ensure we find the correct one.
            final String[] packageNames = mPackageManager.getPackagesForUid(uid);
            if (packageNames == null || packageNames.length == 0) {
                // Not interested in this uid.
                return;
            }
@@ -349,6 +354,7 @@ public class AssociationRevokeProcessor {

            boolean needToPersistStateForUser = false;

            for (String packageName : packageNames) {
                for (AssociationInfo association :
                        getPendingRoleHolderRemovalAssociationsForUser(userId)) {
                    if (!packageName.equals(association.getPackageName())) continue;
@@ -361,6 +367,7 @@ public class AssociationRevokeProcessor {
                    removeFromPendingRoleHolderRemoval(association);
                    needToPersistStateForUser = true;
                }
            }

            if (needToPersistStateForUser) {
                mService.postPersistUserState(userId);