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

Commit 73477d35 authored by Guojing Yuan's avatar Guojing Yuan Committed by Android (Google) Code Review
Browse files

Merge "[CDM] Limit NLS revoke to applicable roles." into main

parents 725bc77a 8ccb7103
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREG
import static android.companion.AssociationRequest.DEVICE_PROFILE_AUTOMOTIVE_PROJECTION;

import static com.android.internal.util.CollectionUtils.any;
import static com.android.server.companion.utils.RolesUtils.NLS_PROFILES;
import static com.android.server.companion.utils.RolesUtils.removeRoleHolderForAssociation;

import static java.util.concurrent.TimeUnit.DAYS;
@@ -148,6 +149,8 @@ public class DisassociationProcessor {
        // Revoke NLS if the last association has been removed for the package
        Binder.withCleanCallingIdentity(() -> {
            if (mAssociationStore.getAssociationsByPackage(userId, packageName).isEmpty()) {
                if (association.getDeviceProfile() != null
                        && NLS_PROFILES.contains(association.getDeviceProfile())) {
                    Intent nlsIntent = new Intent(
                            NotificationListenerService.SERVICE_INTERFACE);
                    List<ResolveInfo> matchedServiceList = mContext.getPackageManager()
@@ -160,6 +163,7 @@ public class DisassociationProcessor {
                        }
                    }
                }
            }
        });

        // If role is not in use by other associations, revoke the role.
+6 −0
Original line number Diff line number Diff line
@@ -91,6 +91,12 @@ public final class RolesUtils {
                            PERMISSION_NEARBY_DEVICES, PERMISSION_POST_NOTIFICATIONS)
    );

    public static final Set<String> NLS_PROFILES = Set.of(
            DEVICE_PROFILE_WATCH,
            DEVICE_PROFILE_GLASSES,
            DEVICE_PROFILE_APP_STREAMING,
            DEVICE_PROFILE_COMPUTER);

    private static final Set<String> ROLELESS_DEVICE_PROFILES;
    static {
        final Set<String> profiles = new ArraySet<>();