Loading core/java/android/app/Notification.java +35 −9 Original line number Diff line number Diff line Loading @@ -3253,9 +3253,24 @@ public class Notification implements Parcelable * @hide */ public boolean hasTitle() { return extras != null && (!TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE)) || !TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE_BIG))); if (extras == null) { return false; } // CallStyle notifications only use the other person's name as the title. if (isStyle(CallStyle.class)) { Person person = extras.getParcelable(EXTRA_CALL_PERSON, Person.class); return person != null && !TextUtils.isEmpty(person.getName()); } // non-CallStyle notifications can use EXTRA_TITLE if (!TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE))) { return true; } // BigTextStyle notifications first use EXTRA_TITLE_BIG if (isStyle(BigTextStyle.class)) { return !TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE_BIG)); } else { return false; } } /** Loading @@ -3280,12 +3295,23 @@ public class Notification implements Parcelable */ @FlaggedApi(Flags.FLAG_API_RICH_ONGOING) public boolean hasPromotableCharacteristics() { return isColorizedRequested() && isOngoingEvent() && hasTitle() && !isGroupSummary() && !containsCustomViews() && hasPromotableStyle(); if (!isOngoingEvent() || isGroupSummary() || containsCustomViews() || !hasTitle()) { return false; } // Only "Ongoing CallStyle" notifications are promotable without EXTRA_COLORIZED if (isOngoingCallStyle()) { return true; } return isColorizedRequested() && hasPromotableStyle(); } /** Returns whether the notification is CallStyle.forOngoingCall(). */ private boolean isOngoingCallStyle() { if (!isStyle(CallStyle.class)) { return false; } int callType = extras.getInt(EXTRA_CALL_TYPE, CallStyle.CALL_TYPE_UNKNOWN); return callType == CallStyle.CALL_TYPE_ONGOING; } /** Loading core/tests/coretests/src/android/app/NotificationTest.java +60 −1 Original line number Diff line number Diff line Loading @@ -462,7 +462,7 @@ public class NotificationTest { @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics() { public void testHasPromotableCharacteristics_bigText_bigTitle() { Notification n = new Notification.Builder(mContext, "test") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG")) Loading @@ -473,6 +473,20 @@ public class NotificationTest { assertThat(n.hasPromotableCharacteristics()).isTrue(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_bigText_normalTitle() { Notification n = new Notification.Builder(mContext, "test") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setStyle(new Notification.BigTextStyle()) .setContentTitle("TITLE") .setColor(Color.WHITE) .setColorized(true) .setOngoing(true) .build(); assertThat(n.hasPromotableCharacteristics()).isTrue(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_notOngoing() { Loading Loading @@ -524,6 +538,51 @@ public class NotificationTest { assertThat(n.hasPromotableCharacteristics()).isFalse(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_noStyle_onlyBigTitle() { Bundle extras = new Bundle(); extras.putString(Notification.EXTRA_TITLE_BIG, "BIG"); Notification n = new Notification.Builder(mContext, "test") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setColor(Color.WHITE) .setColorized(true) .setOngoing(true) .addExtras(extras) .build(); assertThat(n.hasPromotableCharacteristics()).isFalse(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_ongoingCallStyle_notColorized() { PendingIntent intent = PendingIntent.getActivity( mContext, 0, new Intent("test1"), PendingIntent.FLAG_IMMUTABLE); Person person = new Person.Builder().setName("Caller").build(); Notification n = new Notification.Builder(mContext, "test") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setStyle(Notification.CallStyle.forOngoingCall(person, intent)) .setColor(Color.WHITE) .setOngoing(true) .build(); assertThat(n.hasPromotableCharacteristics()).isTrue(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_incomingCallStyle_notColorized() { PendingIntent intent = PendingIntent.getActivity( mContext, 0, new Intent("test1"), PendingIntent.FLAG_IMMUTABLE); Person person = new Person.Builder().setName("Caller").build(); Notification n = new Notification.Builder(mContext, "test") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setStyle(Notification.CallStyle.forIncomingCall(person, intent, intent)) .setColor(Color.WHITE) .setOngoing(true) .build(); assertThat(n.hasPromotableCharacteristics()).isFalse(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_groupSummary() { Loading Loading
core/java/android/app/Notification.java +35 −9 Original line number Diff line number Diff line Loading @@ -3253,9 +3253,24 @@ public class Notification implements Parcelable * @hide */ public boolean hasTitle() { return extras != null && (!TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE)) || !TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE_BIG))); if (extras == null) { return false; } // CallStyle notifications only use the other person's name as the title. if (isStyle(CallStyle.class)) { Person person = extras.getParcelable(EXTRA_CALL_PERSON, Person.class); return person != null && !TextUtils.isEmpty(person.getName()); } // non-CallStyle notifications can use EXTRA_TITLE if (!TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE))) { return true; } // BigTextStyle notifications first use EXTRA_TITLE_BIG if (isStyle(BigTextStyle.class)) { return !TextUtils.isEmpty(extras.getCharSequence(EXTRA_TITLE_BIG)); } else { return false; } } /** Loading @@ -3280,12 +3295,23 @@ public class Notification implements Parcelable */ @FlaggedApi(Flags.FLAG_API_RICH_ONGOING) public boolean hasPromotableCharacteristics() { return isColorizedRequested() && isOngoingEvent() && hasTitle() && !isGroupSummary() && !containsCustomViews() && hasPromotableStyle(); if (!isOngoingEvent() || isGroupSummary() || containsCustomViews() || !hasTitle()) { return false; } // Only "Ongoing CallStyle" notifications are promotable without EXTRA_COLORIZED if (isOngoingCallStyle()) { return true; } return isColorizedRequested() && hasPromotableStyle(); } /** Returns whether the notification is CallStyle.forOngoingCall(). */ private boolean isOngoingCallStyle() { if (!isStyle(CallStyle.class)) { return false; } int callType = extras.getInt(EXTRA_CALL_TYPE, CallStyle.CALL_TYPE_UNKNOWN); return callType == CallStyle.CALL_TYPE_ONGOING; } /** Loading
core/tests/coretests/src/android/app/NotificationTest.java +60 −1 Original line number Diff line number Diff line Loading @@ -462,7 +462,7 @@ public class NotificationTest { @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics() { public void testHasPromotableCharacteristics_bigText_bigTitle() { Notification n = new Notification.Builder(mContext, "test") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setStyle(new Notification.BigTextStyle().setBigContentTitle("BIG")) Loading @@ -473,6 +473,20 @@ public class NotificationTest { assertThat(n.hasPromotableCharacteristics()).isTrue(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_bigText_normalTitle() { Notification n = new Notification.Builder(mContext, "test") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setStyle(new Notification.BigTextStyle()) .setContentTitle("TITLE") .setColor(Color.WHITE) .setColorized(true) .setOngoing(true) .build(); assertThat(n.hasPromotableCharacteristics()).isTrue(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_notOngoing() { Loading Loading @@ -524,6 +538,51 @@ public class NotificationTest { assertThat(n.hasPromotableCharacteristics()).isFalse(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_noStyle_onlyBigTitle() { Bundle extras = new Bundle(); extras.putString(Notification.EXTRA_TITLE_BIG, "BIG"); Notification n = new Notification.Builder(mContext, "test") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setColor(Color.WHITE) .setColorized(true) .setOngoing(true) .addExtras(extras) .build(); assertThat(n.hasPromotableCharacteristics()).isFalse(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_ongoingCallStyle_notColorized() { PendingIntent intent = PendingIntent.getActivity( mContext, 0, new Intent("test1"), PendingIntent.FLAG_IMMUTABLE); Person person = new Person.Builder().setName("Caller").build(); Notification n = new Notification.Builder(mContext, "test") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setStyle(Notification.CallStyle.forOngoingCall(person, intent)) .setColor(Color.WHITE) .setOngoing(true) .build(); assertThat(n.hasPromotableCharacteristics()).isTrue(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_incomingCallStyle_notColorized() { PendingIntent intent = PendingIntent.getActivity( mContext, 0, new Intent("test1"), PendingIntent.FLAG_IMMUTABLE); Person person = new Person.Builder().setName("Caller").build(); Notification n = new Notification.Builder(mContext, "test") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setStyle(Notification.CallStyle.forIncomingCall(person, intent, intent)) .setColor(Color.WHITE) .setOngoing(true) .build(); assertThat(n.hasPromotableCharacteristics()).isFalse(); } @Test @EnableFlags(Flags.FLAG_UI_RICH_ONGOING) public void testHasPromotableCharacteristics_groupSummary() { Loading