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

Commit ea2bcc66 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:5d85254e025ceba2c89ab03427bd1e2f8b68cc45
Merged-In: I3cccad4e85e77916cff020eb7087ac2c355e3e23
Change-Id: I3cccad4e85e77916cff020eb7087ac2c355e3e23
parent 5ec1cdae
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;
@@ -74,6 +75,8 @@ public class DisassociationProcessor {
    @NonNull
    private final PackageManagerInternal mPackageManagerInternal;
    @NonNull
    private final PackageManager mPackageManager;
    @NonNull
    private final DevicePresenceProcessor mDevicePresenceMonitor;
    @NonNull
    private final SystemDataTransferRequestStore mSystemDataTransferRequestStore;
@@ -105,6 +108,7 @@ public class DisassociationProcessor {
        mSystemDataTransferRequestStore = systemDataTransferRequestStore;
        mTransportManager = companionTransportManager;
        mNotificationManager = notificationManager;
        mPackageManager = context.getPackageManager();
    }

    /**
@@ -287,17 +291,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();