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

Commit 69baf67a authored by Evan Chen's avatar Evan Chen
Browse files

Make sure to disassociate all the packages with shared UID

Test: cts
Bug: 427206637
Flag: Flag: EXEMPT bugfix
Change-Id: I3cccad4e85e77916cff020eb7087ac2c355e3e23
parent 85ed67cc
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.companion.AssociationInfo;
import android.companion.Flags;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ResolveInfo;
import android.os.Binder;
@@ -75,6 +76,8 @@ public class DisassociationProcessor {
    @NonNull
    private final PackageManagerInternal mPackageManagerInternal;
    @NonNull
    private final PackageManager mPackageManager;
    @NonNull
    private final DevicePresenceProcessor mDevicePresenceMonitor;
    @NonNull
    private final SystemDataTransferRequestStore mSystemDataTransferRequestStore;
@@ -106,6 +109,7 @@ public class DisassociationProcessor {
        mSystemDataTransferRequestStore = systemDataTransferRequestStore;
        mTransportManager = companionTransportManager;
        mNotificationManager = notificationManager;
        mPackageManager = context.getPackageManager();
    }

    /**
@@ -301,17 +305,21 @@ public class DisassociationProcessor {
                return;
            }

            final String packageName = mPackageManagerInternal.getNameForUid(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;
            }

            int userId = UserHandle.getUserId(uid);
            for (String packageName : packageNames) {
                for (AssociationInfo association : mAssociationStore.getRevokedAssociations(userId,
                        packageName)) {
                    disassociate(association.getId(), REASON_REVOKED);
                }
            }

            if (mAssociationStore.getRevokedAssociations().isEmpty()) {
                stopListening();