Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b7c53bb9 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Update KEY_SUMMARIZATION to accept CharSequence" into main

parents f18caa57 26e38075
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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.
     */
+7 −1
Original line number Diff line number Diff line
@@ -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));
                }
+59 −0
Original line number Diff line number Diff line
@@ -1008,6 +1008,65 @@ public class NotificationRecordTest extends UiServiceTestCase {
        assertFalse(record.getIsAppImportanceLocked());
    }

    @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 */,