Loading core/java/android/app/INotificationManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -258,7 +258,7 @@ interface INotificationManager @EnforcePermission(allOf={"INTERACT_ACROSS_USERS", "ACCESS_NOTIFICATIONS"}) void unregisterCallNotificationEventListener(String packageName, in UserHandle userHandle, in ICallNotificationEventCallback listener); void setCanBePromoted(String pkg, int uid, boolean promote); void setCanBePromoted(String pkg, int uid, boolean promote, boolean fromUser); boolean appCanBePromoted(String pkg, int uid); boolean canBePromoted(String pkg); } core/java/android/app/NotificationManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -976,7 +976,7 @@ public class NotificationManager { public void setCanPostPromotedNotifications(@NonNull String pkg, int uid, boolean allowed) { INotificationManager service = getService(); try { service.setCanBePromoted(pkg, uid, allowed); service.setCanBePromoted(pkg, uid, allowed, true); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading services/core/java/com/android/server/notification/NotificationManagerService.java +6 −2 Original line number Diff line number Diff line Loading @@ -4136,14 +4136,18 @@ public class NotificationManagerService extends SystemService { } /** * Any changes from SystemUI or Settings should be fromUser == true. Any changes the * allowlist should be fromUser == false. */ @Override @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING) public void setCanBePromoted(String pkg, int uid, boolean promote) { public void setCanBePromoted(String pkg, int uid, boolean promote, boolean fromUser) { checkCallerIsSystemOrSystemUiOrShell(); if (!android.app.Flags.apiRichOngoing()) { return; } boolean changed = mPreferencesHelper.setCanBePromoted(pkg, uid, promote); boolean changed = mPreferencesHelper.setCanBePromoted(pkg, uid, promote, fromUser); if (changed) { // check for pending/posted notifs from this app and update the flag synchronized (mNotificationLock) { Loading services/core/java/com/android/server/notification/PreferencesHelper.java +15 −5 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_P import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__DENIED; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__GRANTED; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__NOT_REQUESTED; import static com.android.server.notification.PreferencesHelper.LockableAppFields.USER_LOCKED_PROMOTABLE; import android.annotation.FlaggedApi; import android.annotation.IntDef; Loading Loading @@ -192,10 +193,13 @@ public class PreferencesHelper implements RankingConfig { /** * All user-lockable fields for a given application. */ @IntDef({LockableAppFields.USER_LOCKED_IMPORTANCE}) @IntDef({LockableAppFields.USER_LOCKED_IMPORTANCE, LockableAppFields.USER_LOCKED_BUBBLE, LockableAppFields.USER_LOCKED_PROMOTABLE}) public @interface LockableAppFields { int USER_LOCKED_IMPORTANCE = 0x00000001; int USER_LOCKED_BUBBLE = 0x00000002; int USER_LOCKED_PROMOTABLE = 0x00000004; } private final Object mLock = new Object(); Loading Loading @@ -858,15 +862,21 @@ public class PreferencesHelper implements RankingConfig { } @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING) public boolean setCanBePromoted(String packageName, int uid, boolean promote) { public boolean setCanBePromoted(String packageName, int uid, boolean promote, boolean fromUser) { boolean changed = false; synchronized (mLock) { PackagePreferences pkgPrefs = getOrCreatePackagePreferencesLocked(packageName, uid); if (fromUser || ((pkgPrefs.lockedAppFields & USER_LOCKED_PROMOTABLE) == 0)) { if (pkgPrefs.canHavePromotedNotifs != promote) { pkgPrefs.canHavePromotedNotifs = promote; if (fromUser) { pkgPrefs.lockedAppFields |= USER_LOCKED_PROMOTABLE; } changed = true; } } } // no need to send a ranking update because we need to update the flag value on all pending // and posted notifs and NMS will take care of that return changed; Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +10 −10 Original line number Diff line number Diff line Loading @@ -16611,7 +16611,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); mService.addEnqueuedNotification(r1); mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); waitForIdle(); Loading Loading @@ -16651,9 +16651,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); waitForIdle(); mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); waitForIdle(); ArgumentCaptor<NotificationRecord> captor = Loading @@ -16668,7 +16668,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); // start from true state mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); // qualifying posted notification Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId()) Loading Loading @@ -16709,7 +16709,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); mService.addEnqueuedNotification(r1); mBinderService.setCanBePromoted(mPkg, mUid, false); mBinderService.setCanBePromoted(mPkg, mUid, false, true); waitForIdle(); Loading @@ -16733,7 +16733,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); // start from true state mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); // qualifying posted notification Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId()) Loading @@ -16751,9 +16751,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); mBinderService.setCanBePromoted(mPkg, mUid, false); mBinderService.setCanBePromoted(mPkg, mUid, false, true); waitForIdle(); mBinderService.setCanBePromoted(mPkg, mUid, false); mBinderService.setCanBePromoted(mPkg, mUid, false, true); waitForIdle(); ArgumentCaptor<NotificationRecord> captor = Loading @@ -16765,7 +16765,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test @EnableFlags(android.app.Flags.FLAG_API_RICH_ONGOING) public void testPostPromotableNotification() throws Exception { mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); assertThat(mBinderService.appCanBePromoted(mPkg, mUid)).isTrue(); mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); Loading Loading @@ -16823,7 +16823,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test @EnableFlags(android.app.Flags.FLAG_API_RICH_ONGOING) public void testPostPromotableNotification_unimportantNotification() throws Exception { mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); Notification n = new Notification.Builder(mContext, mMinChannel.getId()) Loading
core/java/android/app/INotificationManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -258,7 +258,7 @@ interface INotificationManager @EnforcePermission(allOf={"INTERACT_ACROSS_USERS", "ACCESS_NOTIFICATIONS"}) void unregisterCallNotificationEventListener(String packageName, in UserHandle userHandle, in ICallNotificationEventCallback listener); void setCanBePromoted(String pkg, int uid, boolean promote); void setCanBePromoted(String pkg, int uid, boolean promote, boolean fromUser); boolean appCanBePromoted(String pkg, int uid); boolean canBePromoted(String pkg); }
core/java/android/app/NotificationManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -976,7 +976,7 @@ public class NotificationManager { public void setCanPostPromotedNotifications(@NonNull String pkg, int uid, boolean allowed) { INotificationManager service = getService(); try { service.setCanBePromoted(pkg, uid, allowed); service.setCanBePromoted(pkg, uid, allowed, true); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +6 −2 Original line number Diff line number Diff line Loading @@ -4136,14 +4136,18 @@ public class NotificationManagerService extends SystemService { } /** * Any changes from SystemUI or Settings should be fromUser == true. Any changes the * allowlist should be fromUser == false. */ @Override @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING) public void setCanBePromoted(String pkg, int uid, boolean promote) { public void setCanBePromoted(String pkg, int uid, boolean promote, boolean fromUser) { checkCallerIsSystemOrSystemUiOrShell(); if (!android.app.Flags.apiRichOngoing()) { return; } boolean changed = mPreferencesHelper.setCanBePromoted(pkg, uid, promote); boolean changed = mPreferencesHelper.setCanBePromoted(pkg, uid, promote, fromUser); if (changed) { // check for pending/posted notifs from this app and update the flag synchronized (mNotificationLock) { Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +15 −5 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_P import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__DENIED; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__GRANTED; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__NOT_REQUESTED; import static com.android.server.notification.PreferencesHelper.LockableAppFields.USER_LOCKED_PROMOTABLE; import android.annotation.FlaggedApi; import android.annotation.IntDef; Loading Loading @@ -192,10 +193,13 @@ public class PreferencesHelper implements RankingConfig { /** * All user-lockable fields for a given application. */ @IntDef({LockableAppFields.USER_LOCKED_IMPORTANCE}) @IntDef({LockableAppFields.USER_LOCKED_IMPORTANCE, LockableAppFields.USER_LOCKED_BUBBLE, LockableAppFields.USER_LOCKED_PROMOTABLE}) public @interface LockableAppFields { int USER_LOCKED_IMPORTANCE = 0x00000001; int USER_LOCKED_BUBBLE = 0x00000002; int USER_LOCKED_PROMOTABLE = 0x00000004; } private final Object mLock = new Object(); Loading Loading @@ -858,15 +862,21 @@ public class PreferencesHelper implements RankingConfig { } @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING) public boolean setCanBePromoted(String packageName, int uid, boolean promote) { public boolean setCanBePromoted(String packageName, int uid, boolean promote, boolean fromUser) { boolean changed = false; synchronized (mLock) { PackagePreferences pkgPrefs = getOrCreatePackagePreferencesLocked(packageName, uid); if (fromUser || ((pkgPrefs.lockedAppFields & USER_LOCKED_PROMOTABLE) == 0)) { if (pkgPrefs.canHavePromotedNotifs != promote) { pkgPrefs.canHavePromotedNotifs = promote; if (fromUser) { pkgPrefs.lockedAppFields |= USER_LOCKED_PROMOTABLE; } changed = true; } } } // no need to send a ranking update because we need to update the flag value on all pending // and posted notifs and NMS will take care of that return changed; Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +10 −10 Original line number Diff line number Diff line Loading @@ -16611,7 +16611,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); mService.addEnqueuedNotification(r1); mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); waitForIdle(); Loading Loading @@ -16651,9 +16651,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); waitForIdle(); mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); waitForIdle(); ArgumentCaptor<NotificationRecord> captor = Loading @@ -16668,7 +16668,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); // start from true state mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); // qualifying posted notification Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId()) Loading Loading @@ -16709,7 +16709,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); mService.addEnqueuedNotification(r1); mBinderService.setCanBePromoted(mPkg, mUid, false); mBinderService.setCanBePromoted(mPkg, mUid, false, true); waitForIdle(); Loading @@ -16733,7 +16733,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); // start from true state mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); // qualifying posted notification Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId()) Loading @@ -16751,9 +16751,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); mBinderService.setCanBePromoted(mPkg, mUid, false); mBinderService.setCanBePromoted(mPkg, mUid, false, true); waitForIdle(); mBinderService.setCanBePromoted(mPkg, mUid, false); mBinderService.setCanBePromoted(mPkg, mUid, false, true); waitForIdle(); ArgumentCaptor<NotificationRecord> captor = Loading @@ -16765,7 +16765,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test @EnableFlags(android.app.Flags.FLAG_API_RICH_ONGOING) public void testPostPromotableNotification() throws Exception { mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); assertThat(mBinderService.appCanBePromoted(mPkg, mUid)).isTrue(); mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); Loading Loading @@ -16823,7 +16823,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test @EnableFlags(android.app.Flags.FLAG_API_RICH_ONGOING) public void testPostPromotableNotification_unimportantNotification() throws Exception { mBinderService.setCanBePromoted(mPkg, mUid, true); mBinderService.setCanBePromoted(mPkg, mUid, true, true); mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); Notification n = new Notification.Builder(mContext, mMinChannel.getId())