diff options
author | Raphael Kim <raphk@google.com> | 2023-10-26 23:42:20 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-06 22:44:26 +0000 |
commit | 8141e8f4dd77b9f8fb485e23ddf028c57fcd4fca (patch) | |
tree | 0212979cc856c3d9b60154bc08265e2803c2af26 | |
parent | f2b2554115ac27cf1d7f231717e18388881c84d6 (diff) | |
download | Permission-8141e8f4dd77b9f8fb485e23ddf028c57fcd4fca.tar.gz |
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
-rw-r--r-- | PermissionController/src/com/android/permissioncontroller/role/model/CompanionDeviceWatchRoleBehavior.java | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/role/model/CompanionDeviceWatchRoleBehavior.java b/PermissionController/src/com/android/permissioncontroller/role/model/CompanionDeviceWatchRoleBehavior.java index 98d56de42..a8b24378f 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.Intent; 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.ArrayList; 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 @@ public class CompanionDeviceWatchRoleBehavior implements RoleBehavior { @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 @@ public class CompanionDeviceWatchRoleBehavior implements RoleBehavior { @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); + } } } |