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

Commit c0068881 authored by Guojing Yuan's avatar Guojing Yuan Committed by Joseph Annareddy
Browse files

Restrict automatic NLS revocation to specific device profiles.

When a companion device association is removed, only revoke Notification Listener Service access if the association's device profile is one of the predefined profiles that typically require NLS access, such as Watch, Glasses, App Streaming, or Computer.

Bug: 421919075
Flag: EXEMPT bugfix
Test: CTS
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:cc54924cb4a5aef045db5e64c3eaf8e47ea1fd02
Merged-In: Ie98a90b5cb3c040873a1d4b9b1159ba6ff0d6309
Change-Id: Ie98a90b5cb3c040873a1d4b9b1159ba6ff0d6309
parent 6b3e127d
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import static com.android.server.companion.utils.PermissionsUtils.enforceCallerC
import static com.android.server.companion.utils.PermissionsUtils.enforceCallerIsSystemOr;
import static com.android.server.companion.utils.PermissionsUtils.enforceCallerIsSystemOrCanInteractWithUserId;
import static com.android.server.companion.utils.PermissionsUtils.sanitizeWithCallerChecks;
import static com.android.server.companion.utils.RolesUtils.NLS_PROFILES;

import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.DAYS;
@@ -552,6 +553,8 @@ public class CompanionDeviceManagerService extends SystemService {
            // Revoke NLS if the last association has been removed for the package
            Binder.withCleanCallingIdentity(() -> {
                if (mAssociationStore.getAssociationsForPackage(userId, packageName).isEmpty()) {
                    if (association.getDeviceProfile() != null
                        && NLS_PROFILES.contains(association.getDeviceProfile())) {
                        NotificationManager nm = getContext().getSystemService(
                                NotificationManager.class);
                        Intent nlsIntent = new Intent(
@@ -562,7 +565,8 @@ public class CompanionDeviceManagerService extends SystemService {
                            if (service.getComponentInfo().getComponentName().getPackageName()
                                    .equals(packageName)) {
                                nm.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.
     */