Merge "API: Expose whether bubbles are enabled or not" into sc-dev
This commit is contained in:
@@ -6202,6 +6202,7 @@ package android.app {
|
|||||||
public class NotificationManager {
|
public class NotificationManager {
|
||||||
method public String addAutomaticZenRule(android.app.AutomaticZenRule);
|
method public String addAutomaticZenRule(android.app.AutomaticZenRule);
|
||||||
method @Deprecated public boolean areBubblesAllowed();
|
method @Deprecated public boolean areBubblesAllowed();
|
||||||
|
method public boolean areBubblesEnabled();
|
||||||
method public boolean areNotificationsEnabled();
|
method public boolean areNotificationsEnabled();
|
||||||
method public boolean areNotificationsPaused();
|
method public boolean areNotificationsPaused();
|
||||||
method public boolean canNotifyAsPackage(@NonNull String);
|
method public boolean canNotifyAsPackage(@NonNull String);
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ interface INotificationManager
|
|||||||
|
|
||||||
void setBubblesAllowed(String pkg, int uid, int bubblePreference);
|
void setBubblesAllowed(String pkg, int uid, int bubblePreference);
|
||||||
boolean areBubblesAllowed(String pkg);
|
boolean areBubblesAllowed(String pkg);
|
||||||
|
boolean areBubblesEnabled(in UserHandle user);
|
||||||
int getBubblePreferenceForPackage(String pkg, int uid);
|
int getBubblePreferenceForPackage(String pkg, int uid);
|
||||||
|
|
||||||
void createNotificationChannelGroups(String pkg, in ParceledListSlice channelGroupList);
|
void createNotificationChannelGroups(String pkg, in ParceledListSlice channelGroupList);
|
||||||
|
|||||||
@@ -1326,7 +1326,6 @@ public class NotificationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether all notifications posted by this app can appear outside of the
|
* Gets whether all notifications posted by this app can appear outside of the
|
||||||
* notification shade, floating over other apps' content.
|
* notification shade, floating over other apps' content.
|
||||||
@@ -1347,6 +1346,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
|
* Gets the bubble preference for the app. This preference only applies to notifications that
|
||||||
* have been properly configured to bubble.
|
* have been properly configured to bubble.
|
||||||
|
|||||||
@@ -3304,6 +3304,20 @@ public class NotificationManagerService extends SystemService {
|
|||||||
== BUBBLE_PREFERENCE_ALL;
|
== 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
|
@Override
|
||||||
public int getBubblePreferenceForPackage(String pkg, int uid) {
|
public int getBubblePreferenceForPackage(String pkg, int uid) {
|
||||||
enforceSystemOrSystemUIOrSamePackage(pkg,
|
enforceSystemOrSystemUIOrSamePackage(pkg,
|
||||||
|
|||||||
@@ -4706,6 +4706,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
assertFalse(mBinderService.areBubblesAllowed(PKG));
|
assertFalse(mBinderService.areBubblesAllowed(PKG));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void testIsCallerInstantApp_primaryUser() throws Exception {
|
public void testIsCallerInstantApp_primaryUser() throws Exception {
|
||||||
ApplicationInfo info = new ApplicationInfo();
|
ApplicationInfo info = new ApplicationInfo();
|
||||||
|
|||||||
Reference in New Issue
Block a user