diff options
| author | 2021-03-31 16:53:16 +0000 | |
|---|---|---|
| committer | 2021-03-31 16:53:16 +0000 | |
| commit | 3da85d8e80a393ce2bd453a90d0a716c32111b0e (patch) | |
| tree | 2c0735ccbf006516253f9c4c0654393020aee65d | |
| parent | 65da93d3fd34dd545de4b57bac52812de10169b2 (diff) | |
| parent | c5561c9c5c8aac7b257adfcac7c66a872865cb8c (diff) | |
Merge "API: Expose whether bubbles are enabled or not" into sc-dev
5 files changed, 59 insertions, 1 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 897b3e6d55e3..10851e881246 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -6202,6 +6202,7 @@ package android.app { public class NotificationManager { method public String addAutomaticZenRule(android.app.AutomaticZenRule); method @Deprecated public boolean areBubblesAllowed(); + method public boolean areBubblesEnabled(); method public boolean areNotificationsEnabled(); method public boolean areNotificationsPaused(); method public boolean canNotifyAsPackage(@NonNull String); diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index a5f8f103e437..d0e17f00e990 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -85,6 +85,7 @@ interface INotificationManager void setBubblesAllowed(String pkg, int uid, int bubblePreference); boolean areBubblesAllowed(String pkg); + boolean areBubblesEnabled(in UserHandle user); int getBubblePreferenceForPackage(String pkg, int uid); void createNotificationChannelGroups(String pkg, in ParceledListSlice channelGroupList); diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index 6cce270bc5a3..f0d580f066d8 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -1326,7 +1326,6 @@ public class NotificationManager { } } - /** * Gets whether all notifications posted by this app can appear outside of the * notification shade, floating over other apps' content. @@ -1348,6 +1347,21 @@ public class NotificationManager { } /** + * Returns whether bubbles are enabled at the feature level for the current user. When enabled, + * notifications able to bubble will display an affordance allowing the user to bubble them. + * + * @see Notification.Builder#setBubbleMetadata(Notification.BubbleMetadata) + */ + public boolean areBubblesEnabled() { + INotificationManager service = getService(); + try { + return service.areBubblesEnabled(mContext.getUser()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** * Gets the bubble preference for the app. This preference only applies to notifications that * have been properly configured to bubble. * diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 68990ba77297..4ee90d6e0956 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3304,6 +3304,20 @@ public class NotificationManagerService extends SystemService { == BUBBLE_PREFERENCE_ALL; } + /** + * @return true if this user has bubbles enabled at the feature-level. + */ + @Override + public boolean areBubblesEnabled(UserHandle user) { + if (UserHandle.getCallingUserId() != user.getIdentifier()) { + getContext().enforceCallingPermission( + android.Manifest.permission.INTERACT_ACROSS_USERS, + "areBubblesEnabled for user " + user.getIdentifier()); + } + // TODO: incorporate uid / per-user prefs once settings moves off global table. + return mPreferencesHelper.bubblesEnabled(); + } + @Override public int getBubblePreferenceForPackage(String pkg, int uid) { enforceSystemOrSystemUIOrSamePackage(pkg, diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index bb70c79328c3..b24e78828f86 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -4707,6 +4707,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test + public void testAreBubblesEnabled() throws Exception { + assertTrue(mBinderService.areBubblesEnabled(UserHandle.getUserHandleForUid(mUid))); + } + + @Test + public void testAreBubblesEnabled_false() throws Exception { + Settings.Global.putInt(mContext.getContentResolver(), + Settings.Global.NOTIFICATION_BUBBLES, 0); + mService.mPreferencesHelper.updateBubblesEnabled(); + assertFalse(mBinderService.areBubblesEnabled(UserHandle.getUserHandleForUid(mUid))); + } + + @Test + public void testAreBubblesEnabled_exception() throws Exception { + try { + assertTrue(mBinderService.areBubblesEnabled( + UserHandle.getUserHandleForUid(mUid + UserHandle.PER_USER_RANGE))); + fail("Cannot call cross user without permission"); + } catch (SecurityException e) { + // pass + } + // cross user, with permission, no problem + enableInteractAcrossUsers(); + assertTrue(mBinderService.areBubblesEnabled( + UserHandle.getUserHandleForUid(mUid + UserHandle.PER_USER_RANGE))); + } + + @Test public void testIsCallerInstantApp_primaryUser() throws Exception { ApplicationInfo info = new ApplicationInfo(); info.privateFlags = ApplicationInfo.PRIVATE_FLAG_INSTANT; |