summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff DeCew <jeffdq@google.com> 2025-03-20 18:44:45 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-20 18:44:45 -0700
commita8f4747e6f72e6ecbf0de28f9097fe74d96bf932 (patch)
tree933db437f8b9f4f929f9035711303114a118ba4b
parent807a9c6f647f46ddf4540084c83c85064e4f1b27 (diff)
parent68fd88e3f297ee636d924aef3d1b92b2b1e000e0 (diff)
Merge "Ongoing CallStyle notifications can be promoted even without being colorized." into main
-rw-r--r--core/java/android/app/Notification.java44
-rw-r--r--core/tests/coretests/src/android/app/NotificationTest.java61
2 files changed, 95 insertions, 10 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index f5277fd86a57..4c3deada4d76 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -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;
+ }
}
/**
@@ -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;
}
/**
diff --git a/core/tests/coretests/src/android/app/NotificationTest.java b/core/tests/coretests/src/android/app/NotificationTest.java
index 157c74abc5de..0287956bd07f 100644
--- a/core/tests/coretests/src/android/app/NotificationTest.java
+++ b/core/tests/coretests/src/android/app/NotificationTest.java
@@ -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"))
@@ -475,6 +475,20 @@ public class NotificationTest {
@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() {
Notification n = new Notification.Builder(mContext, "test")
.setSmallIcon(android.R.drawable.sym_def_app_icon)
@@ -526,6 +540,51 @@ public class NotificationTest {
@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() {
Notification n = new Notification.Builder(mContext, "test")
.setSmallIcon(android.R.drawable.sym_def_app_icon)