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

Commit 30812fb5 authored by Guojing Yuan's avatar Guojing Yuan Committed by Android Build Coastguard Worker
Browse files

[CDM] Limit NLS revoke to applicable roles.

Bug: 421919075
Flag: EXEMPT bugfix
Test: CTS
(cherry picked from commit 8ccb7103)
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:56058a86e795905cd1f143edfa7fd5d030a4dde8
Merged-In: Icd3cdb3234a516ff7f752f39d7b1d8e6f5cde1ef
Change-Id: Icd3cdb3234a516ff7f752f39d7b1d8e6f5cde1ef
parent 529f2402
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_VISIB
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;
@@ -139,6 +140,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()
@@ -147,7 +150,8 @@ public class DisassociationProcessor {
                        if (service.getComponentInfo().getComponentName().getPackageName()
                                .equals(packageName)) {
                            mNotificationManager.setNotificationListenerAccessGranted(
                                service.getComponentInfo().getComponentName(), false);
                                    service.getComponentInfo().getComponentName(), false, false);
                        }
                    }
                }
            }
+11 −0
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@
package com.android.server.companion.utils;

import static android.app.role.RoleManager.MANAGE_HOLDERS_FLAG_DONT_KILL_APP;
import static android.companion.AssociationRequest.DEVICE_PROFILE_APP_STREAMING;
import static android.companion.AssociationRequest.DEVICE_PROFILE_COMPUTER;
import static android.companion.AssociationRequest.DEVICE_PROFILE_GLASSES;
import static android.companion.AssociationRequest.DEVICE_PROFILE_WATCH;

import android.annotation.NonNull;
import android.annotation.SuppressLint;
@@ -29,6 +33,7 @@ import android.os.UserHandle;
import android.util.Slog;

import java.util.List;
import java.util.Set;
import java.util.function.Consumer;

/** Utility methods for accessing {@link RoleManager} APIs. */
@@ -37,6 +42,12 @@ public final class RolesUtils {

    private static final String TAG = "CDM_RolesUtils";

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

    /**
     * Check if the package holds the role.
     */