summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Julia Reynolds <juliacr@google.com> 2025-03-03 11:45:32 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-03 11:45:32 -0800
commitb7c53bb9a08eb456bff4c95b8c88ac13ae8bd565 (patch)
treedca9b1fa5da7afd833c69c6f190b05919ec0a13b
parentf18caa571e52a1209c2ebc7d798c76607bd73f84 (diff)
parent26e380755244d7197dca446e05d67908dd3b4024 (diff)
Merge "Update KEY_SUMMARIZATION to accept CharSequence" into main
-rw-r--r--core/java/android/service/notification/Adjustment.java2
-rw-r--r--services/core/java/com/android/server/notification/NotificationRecord.java8
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java59
3 files changed, 67 insertions, 2 deletions
diff --git a/core/java/android/service/notification/Adjustment.java b/core/java/android/service/notification/Adjustment.java
index 505db30ca719..772fd968e507 100644
--- a/core/java/android/service/notification/Adjustment.java
+++ b/core/java/android/service/notification/Adjustment.java
@@ -225,7 +225,7 @@ public final class Adjustment implements Parcelable {
public static final int TYPE_CONTENT_RECOMMENDATION = 4;
/**
- * Data type: String, a summarization of the text of the notification, or, if provided for
+ * Data type: CharSequence, a summarization of the text of the notification, or, if provided for
* a group summary, a summarization of the text of all of the notificatrions in the group.
* Send this key with a null value to remove an existing summarization.
*/
diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java
index 398894bf5273..cec5a93a2a15 100644
--- a/services/core/java/com/android/server/notification/NotificationRecord.java
+++ b/services/core/java/com/android/server/notification/NotificationRecord.java
@@ -817,7 +817,13 @@ public final class NotificationRecord {
}
if ((android.app.Flags.nmSummarizationUi() || android.app.Flags.nmSummarization())
&& signals.containsKey(KEY_SUMMARIZATION)) {
- mSummarization = signals.getString(KEY_SUMMARIZATION);
+ CharSequence summary = signals.getCharSequence(KEY_SUMMARIZATION,
+ signals.getString(KEY_SUMMARIZATION));
+ if (summary != null) {
+ mSummarization = summary.toString();
+ } else {
+ mSummarization = null;
+ }
EventLogTags.writeNotificationAdjusted(getKey(),
KEY_SUMMARIZATION, Boolean.toString(mSummarization != null));
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java
index 4391152220c0..e9cf036d0fb3 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java
@@ -1009,6 +1009,65 @@ public class NotificationRecordTest extends UiServiceTestCase {
}
@Test
+ @EnableFlags(Flags.FLAG_NM_SUMMARIZATION)
+ public void testSummarization_null() {
+ StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */,
+ true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */,
+ false /* lights */, false /* defaultLights */, groupId /* group */);
+ NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
+
+ assertThat(record.getSummarization()).isNull();
+
+ Bundle signals = new Bundle();
+ signals.putCharSequence(Adjustment.KEY_SUMMARIZATION, null);
+ record.addAdjustment(new Adjustment(mPkg, record.getKey(), signals, null, sbn.getUserId()));
+
+ record.applyAdjustments();
+
+ assertThat(record.getSummarization()).isNull();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_NM_SUMMARIZATION)
+ public void testSummarization_charSequence() {
+ CharSequence summary = "hello";
+ StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */,
+ true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */,
+ false /* lights */, false /* defaultLights */, groupId /* group */);
+ NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
+
+ assertThat(record.getSummarization()).isNull();
+
+ Bundle signals = new Bundle();
+ signals.putCharSequence(Adjustment.KEY_SUMMARIZATION, summary);
+ record.addAdjustment(new Adjustment(mPkg, record.getKey(), signals, null, sbn.getUserId()));
+
+ record.applyAdjustments();
+
+ assertThat(record.getSummarization()).isEqualTo(summary.toString());
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_NM_SUMMARIZATION)
+ public void testSummarization_string() {
+ String summary = "hello";
+ StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */,
+ true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */,
+ false /* lights */, false /* defaultLights */, groupId /* group */);
+ NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel);
+
+ assertThat(record.getSummarization()).isNull();
+
+ Bundle signals = new Bundle();
+ signals.putCharSequence(Adjustment.KEY_SUMMARIZATION, summary);
+ record.addAdjustment(new Adjustment(mPkg, record.getKey(), signals, null, sbn.getUserId()));
+
+ record.applyAdjustments();
+
+ assertThat(record.getSummarization()).isEqualTo(summary);
+ }
+
+ @Test
public void testSensitiveContent() {
StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */,
true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */,