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

Commit 34d37a95 authored by Guojing Yuan's avatar Guojing Yuan Committed by Automerger Merge Worker
Browse files

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

Merge "Restrict automatic NLS revocation to specific device profiles." into tm-dev am: 46bbe61b am: ddb7e2f1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/34957285



Change-Id: Id6504de6a4234b387fa7b0cbdb13838eee7ad860
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 56d05104 ddb7e2f1
Loading
Loading
Loading
Loading
+15 −11
Original line number Original line 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.enforceCallerIsSystemOr;
import static com.android.server.companion.PermissionsUtils.enforceCallerIsSystemOrCanInteractWithUserId;
import static com.android.server.companion.PermissionsUtils.enforceCallerIsSystemOrCanInteractWithUserId;
import static com.android.server.companion.PermissionsUtils.sanitizeWithCallerChecks;
import static com.android.server.companion.PermissionsUtils.sanitizeWithCallerChecks;
import static com.android.server.companion.RolesUtils.NLS_PROFILES;
import static com.android.server.companion.RolesUtils.addRoleHolderForAssociation;
import static com.android.server.companion.RolesUtils.addRoleHolderForAssociation;
import static com.android.server.companion.RolesUtils.removeRoleHolderForAssociation;
import static com.android.server.companion.RolesUtils.removeRoleHolderForAssociation;


@@ -407,6 +408,8 @@ public class CompanionDeviceManagerService extends SystemService {
            // Revoke NLS if the last association has been removed for the package
            // Revoke NLS if the last association has been removed for the package
            Binder.withCleanCallingIdentity(() -> {
            Binder.withCleanCallingIdentity(() -> {
                if (mAssociationStore.getAssociationsForPackage(userId, packageName).isEmpty()) {
                if (mAssociationStore.getAssociationsForPackage(userId, packageName).isEmpty()) {
                    if (association.getDeviceProfile() != null
                        && NLS_PROFILES.contains(association.getDeviceProfile())) {
                        NotificationManager nm = getContext().getSystemService(
                        NotificationManager nm = getContext().getSystemService(
                                NotificationManager.class);
                                NotificationManager.class);
                        Intent nlsIntent = new Intent(
                        Intent nlsIntent = new Intent(
@@ -417,7 +420,8 @@ public class CompanionDeviceManagerService extends SystemService {
                            if (service.getComponentInfo().getComponentName().getPackageName()
                            if (service.getComponentInfo().getComponentName().getPackageName()
                                    .equals(packageName)) {
                                    .equals(packageName)) {
                                nm.setNotificationListenerAccessGranted(
                                nm.setNotificationListenerAccessGranted(
                                    service.getComponentInfo().getComponentName(), false);
                                        service.getComponentInfo().getComponentName(), false, false);
                            }
                        }
                        }
                    }
                    }
                }
                }
+9 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,9 @@
package com.android.server.companion;
package com.android.server.companion;


import static android.app.role.RoleManager.MANAGE_HOLDERS_FLAG_DONT_KILL_APP;
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_WATCH;


import static com.android.server.companion.CompanionDeviceManagerService.DEBUG;
import static com.android.server.companion.CompanionDeviceManagerService.DEBUG;
import static com.android.server.companion.CompanionDeviceManagerService.TAG;
import static com.android.server.companion.CompanionDeviceManagerService.TAG;
@@ -32,11 +35,17 @@ import android.util.Log;
import android.util.Slog;
import android.util.Slog;


import java.util.List;
import java.util.List;
import java.util.Set;


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


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

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