Do not grant notification access for work apps.
Bug: 295549388
Test: Manual test on debug app
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:01d29a44678752f317d5489424a03bcfd1a9deb8)
Merged-In: Ie6078a1081bf9f98466bfbf2bc0b54a7af7b4951
Change-Id: Ie6078a1081bf9f98466bfbf2bc0b54a7af7b4951
diff --git a/PermissionController/src/com/android/permissioncontroller/role/model/CompanionDeviceWatchRoleBehavior.java b/PermissionController/src/com/android/permissioncontroller/role/model/CompanionDeviceWatchRoleBehavior.java
index 98d56de..a8b2437 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/model/CompanionDeviceWatchRoleBehavior.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/model/CompanionDeviceWatchRoleBehavior.java
@@ -23,6 +23,8 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
+import android.os.Process;
+import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.util.Log;
@@ -32,6 +34,8 @@
import java.util.List;
import java.util.Objects;
+import com.android.permissioncontroller.role.utils.UserUtils;
+
/**
* Class for behavior of the "watch" Companion device profile role.
*/
@@ -41,9 +45,12 @@
@Override
public void grant(@NonNull Role role, @NonNull String packageName, @NonNull Context context) {
- List<ComponentName> notificationListenersForPackage =
- getNotificationListenersForPackage(packageName, context);
- setNotificationGrantState(context, notificationListenersForPackage, true);
+ UserHandle user = Process.myUserHandle();
+ if (!UserUtils.isWorkProfile(user, context)) {
+ List<ComponentName> notificationListenersForPackage =
+ getNotificationListenersForPackage(packageName, context);
+ setNotificationGrantState(context, notificationListenersForPackage, true);
+ }
}
private void setNotificationGrantState(@NonNull Context context,
@@ -80,10 +87,13 @@
@Override
public void revoke(@NonNull Role role, @NonNull String packageName, @NonNull Context context) {
- NotificationManager notificationManager =
- context.getSystemService(NotificationManager.class);
- List<ComponentName> enabledNotificationListeners =
- notificationManager.getEnabledNotificationListeners();
- setNotificationGrantState(context, enabledNotificationListeners, false);
+ UserHandle user = Process.myUserHandle();
+ if (!UserUtils.isWorkProfile(user, context)) {
+ NotificationManager notificationManager =
+ context.getSystemService(NotificationManager.class);
+ List<ComponentName> enabledNotificationListeners =
+ notificationManager.getEnabledNotificationListeners();
+ setNotificationGrantState(context, enabledNotificationListeners, false);
+ }
}
}