Loading core/java/android/app/Notification.java +1 −1 Original line number Diff line number Diff line Loading @@ -6994,7 +6994,7 @@ public class Notification implements Parcelable */ public boolean isColorized() { return extras.getBoolean(EXTRA_COLORIZED) && (hasColorizedPermission() || isForegroundService()); && (hasColorizedPermission() || isFgsOrUij()); } /** Loading services/core/java/com/android/server/notification/NotificationManagerService.java +4 −4 Original line number Diff line number Diff line Loading @@ -7213,12 +7213,12 @@ public class NotificationManagerService extends SystemService { } if (n.isStyle(Notification.CallStyle.class)) { boolean isForegroundService = (n.flags & FLAG_FOREGROUND_SERVICE) != 0; boolean hasFullScreenIntent = n.fullScreenIntent != null; if (!isForegroundService && !hasFullScreenIntent) { boolean requestedFullScreenIntent = (n.flags & FLAG_FSI_REQUESTED_BUT_DENIED) != 0; if (!n.isFgsOrUij() && !hasFullScreenIntent && !requestedFullScreenIntent) { throw new IllegalArgumentException(r.getKey() + " Not posted." + " CallStyle notifications must either be for a foreground Service or" + " use a fullScreenIntent."); + " CallStyle notifications must be for a foreground service or" + " user initated job or use a fullScreenIntent."); } } Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +84 −0 Original line number Diff line number Diff line Loading @@ -10591,6 +10591,90 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertFalse(n.hasColorizedPermission()); } @Test public void checkCallStyleNotification_withoutAnyValidUseCase_throws() throws Exception { Person person = new Person.Builder().setName("caller").build(); Notification n = new Notification.Builder(mContext, "test") .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); try { mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(), r.getSbn().getId(), r.getSbn().getTag(), r, false); assertFalse("CallStyle should not be allowed without a valid use case", true); } catch (IllegalArgumentException error) { assertThat(error.getMessage()).contains("CallStyle"); } } @Test public void checkCallStyleNotification_allowedForFgs() throws Exception { Person person = new Person.Builder().setName("caller").build(); Notification n = new Notification.Builder(mContext, "test") .setFlag(FLAG_FOREGROUND_SERVICE, true) .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(), r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue(); } @Test public void checkCallStyleNotification_allowedForUij() throws Exception { Person person = new Person.Builder().setName("caller").build(); Notification n = new Notification.Builder(mContext, "test") .setFlag(FLAG_USER_INITIATED_JOB, true) .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(), r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue(); } @Test public void checkCallStyleNotification_allowedForFsiAllowed() throws Exception { Person person = new Person.Builder().setName("caller").build(); Notification n = new Notification.Builder(mContext, "test") .setFullScreenIntent(mock(PendingIntent.class), true) .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(), r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue(); } @Test public void checkCallStyleNotification_allowedForFsiDenied() throws Exception { Person person = new Person.Builder().setName("caller").build(); Notification n = new Notification.Builder(mContext, "test") .setFlag(Notification.FLAG_FSI_REQUESTED_BUT_DENIED, true) .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(), r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue(); } @Test public void fixSystemNotification_withOnGoingFlag_shouldBeDismissible() throws Exception { Loading Loading
core/java/android/app/Notification.java +1 −1 Original line number Diff line number Diff line Loading @@ -6994,7 +6994,7 @@ public class Notification implements Parcelable */ public boolean isColorized() { return extras.getBoolean(EXTRA_COLORIZED) && (hasColorizedPermission() || isForegroundService()); && (hasColorizedPermission() || isFgsOrUij()); } /** Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +4 −4 Original line number Diff line number Diff line Loading @@ -7213,12 +7213,12 @@ public class NotificationManagerService extends SystemService { } if (n.isStyle(Notification.CallStyle.class)) { boolean isForegroundService = (n.flags & FLAG_FOREGROUND_SERVICE) != 0; boolean hasFullScreenIntent = n.fullScreenIntent != null; if (!isForegroundService && !hasFullScreenIntent) { boolean requestedFullScreenIntent = (n.flags & FLAG_FSI_REQUESTED_BUT_DENIED) != 0; if (!n.isFgsOrUij() && !hasFullScreenIntent && !requestedFullScreenIntent) { throw new IllegalArgumentException(r.getKey() + " Not posted." + " CallStyle notifications must either be for a foreground Service or" + " use a fullScreenIntent."); + " CallStyle notifications must be for a foreground service or" + " user initated job or use a fullScreenIntent."); } } Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +84 −0 Original line number Diff line number Diff line Loading @@ -10591,6 +10591,90 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertFalse(n.hasColorizedPermission()); } @Test public void checkCallStyleNotification_withoutAnyValidUseCase_throws() throws Exception { Person person = new Person.Builder().setName("caller").build(); Notification n = new Notification.Builder(mContext, "test") .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); try { mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(), r.getSbn().getId(), r.getSbn().getTag(), r, false); assertFalse("CallStyle should not be allowed without a valid use case", true); } catch (IllegalArgumentException error) { assertThat(error.getMessage()).contains("CallStyle"); } } @Test public void checkCallStyleNotification_allowedForFgs() throws Exception { Person person = new Person.Builder().setName("caller").build(); Notification n = new Notification.Builder(mContext, "test") .setFlag(FLAG_FOREGROUND_SERVICE, true) .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(), r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue(); } @Test public void checkCallStyleNotification_allowedForUij() throws Exception { Person person = new Person.Builder().setName("caller").build(); Notification n = new Notification.Builder(mContext, "test") .setFlag(FLAG_USER_INITIATED_JOB, true) .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(), r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue(); } @Test public void checkCallStyleNotification_allowedForFsiAllowed() throws Exception { Person person = new Person.Builder().setName("caller").build(); Notification n = new Notification.Builder(mContext, "test") .setFullScreenIntent(mock(PendingIntent.class), true) .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(), r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue(); } @Test public void checkCallStyleNotification_allowedForFsiDenied() throws Exception { Person person = new Person.Builder().setName("caller").build(); Notification n = new Notification.Builder(mContext, "test") .setFlag(Notification.FLAG_FSI_REQUESTED_BUT_DENIED, true) .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(), r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue(); } @Test public void fixSystemNotification_withOnGoingFlag_shouldBeDismissible() throws Exception { Loading