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

Commit 9c8c99ba authored by Evan Chen's avatar Evan Chen Committed by Android Build Coastguard Worker
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:90756fe1878be807c0cc0f6e7d9ad263cce0d4f0
Merged-In: I3cccad4e85e77916cff020eb7087ac2c355e3e23
Change-Id: I3cccad4e85e77916cff020eb7087ac2c355e3e23
parent 30812fb5
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.app.NotificationManager;
import android.companion.AssociationInfo;
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;
@@ -67,6 +68,8 @@ public class DisassociationProcessor {
    @NonNull
    private final PackageManagerInternal mPackageManagerInternal;
    @NonNull
    private final PackageManager mPackageManager;
    @NonNull
    private final DevicePresenceProcessor mDevicePresenceMonitor;
    @NonNull
    private final SystemDataTransferRequestStore mSystemDataTransferRequestStore;
@@ -98,6 +101,7 @@ public class DisassociationProcessor {
        mSystemDataTransferRequestStore = systemDataTransferRequestStore;
        mTransportManager = companionTransportManager;
        mNotificationManager = notificationManager;
        mPackageManager = context.getPackageManager();
    }

    /**
@@ -276,17 +280,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());
                }
            }

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