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

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

Merge "Restrict automatic NLS revocation to specific device profiles." into udc-dev

parents 09b2101d 8577610f
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import static com.android.server.companion.PermissionsUtils.enforceCallerCanMana
import static com.android.server.companion.PermissionsUtils.enforceCallerIsSystemOr;
import static com.android.server.companion.PermissionsUtils.enforceCallerIsSystemOrCanInteractWithUserId;
import static com.android.server.companion.PermissionsUtils.sanitizeWithCallerChecks;
import static com.android.server.companion.RolesUtils.NLS_PROFILES;
import static com.android.server.companion.RolesUtils.removeRoleHolderForAssociation;

import static java.util.Objects.requireNonNull;
@@ -442,6 +443,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(
@@ -452,7 +455,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;

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 static com.android.server.companion.CompanionDeviceManagerService.DEBUG;
import static com.android.server.companion.CompanionDeviceManagerService.TAG;
@@ -33,12 +37,19 @@ import android.util.Log;
import android.util.Slog;

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

/** Utility methods for accessing {@link RoleManager} APIs. */
@SuppressLint("LongLogTag")
final class RolesUtils {

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

    static boolean isRoleHolder(@NonNull Context context, @UserIdInt int userId,
            @NonNull String packageName, @NonNull String role) {
        final RoleManager roleManager = context.getSystemService(RoleManager.class);