diff options
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 */, |