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

Commit 2d40d217 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge "Add Notification.shortCriticalText API." into main

parents 5328f80a 6233e05d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6396,6 +6396,7 @@ package android.app {
    method public android.graphics.drawable.Icon getLargeIcon();
    method @Nullable public android.content.LocusId getLocusId();
    method public CharSequence getSettingsText();
    method @FlaggedApi("android.app.api_rich_ongoing") @Nullable public String getShortCriticalText();
    method public String getShortcutId();
    method public android.graphics.drawable.Icon getSmallIcon();
    method public String getSortKey();
@@ -6719,6 +6720,7 @@ package android.app {
    method @NonNull public android.app.Notification.Builder setPublicVersion(android.app.Notification);
    method @NonNull public android.app.Notification.Builder setRemoteInputHistory(CharSequence[]);
    method @NonNull public android.app.Notification.Builder setSettingsText(CharSequence);
    method @FlaggedApi("android.app.api_rich_ongoing") @NonNull public android.app.Notification.Builder setShortCriticalText(@Nullable String);
    method @NonNull public android.app.Notification.Builder setShortcutId(String);
    method @NonNull public android.app.Notification.Builder setShowWhen(boolean);
    method @NonNull public android.app.Notification.Builder setSmallIcon(@DrawableRes int);
+32 −0
Original line number Diff line number Diff line
@@ -1280,6 +1280,15 @@ public class Notification implements Parcelable
     */
    public static final String EXTRA_BIG_TEXT = "android.bigText";
    /**
     * {@link #extras} key: very short text summarizing the most critical information contained in
     * the notification.
     *
     * @hide
     */
    @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
    public static final String EXTRA_SHORT_CRITICAL_TEXT = "android.shortCriticalText";
    /**
     * {@link #extras} key: this is the resource ID of the notification's main small icon, as
     * supplied to {@link Builder#setSmallIcon(int)}.
@@ -4050,6 +4059,17 @@ public class Notification implements Parcelable
        return String.join("|", defaultStrings);
    }
    /**
     * Returns the very short text summarizing the most critical information contained in the
     * notification, or null if this field was not set.
     */
    @Nullable
    @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
    public String getShortCriticalText() {
        return extras.getString(EXTRA_SHORT_CRITICAL_TEXT);
    }
    /**
     * @hide
     */
@@ -4990,6 +5010,18 @@ public class Notification implements Parcelable
            return this;
        }
        /**
         * Sets a very short string summarizing the most critical information contained in the
         * notification. Suggested max length is 5 characters, and there is no guarantee how much or
         * how little of this text will be shown.
         */
        @FlaggedApi(Flags.FLAG_API_RICH_ONGOING)
        @NonNull
        public Builder setShortCriticalText(@Nullable String shortCriticalText) {
            mN.extras.putString(EXTRA_SHORT_CRITICAL_TEXT, shortCriticalText);
            return this;
        }
        /**
         * Set the progress this notification represents.
         *
+19 −0
Original line number Diff line number Diff line
@@ -214,6 +214,25 @@ public class NotificationTest {
        assertFalse(n.hasCompletedProgress());
    }

    @Test
    @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
    public void testGetShortCriticalText_noneSet() {
        Notification n = new Notification.Builder(mContext, "test")
                .build();

        assertSame(n.getShortCriticalText(), null);
    }

    @Test
    @EnableFlags(Flags.FLAG_API_RICH_ONGOING)
    public void testGetShortCriticalText_isSet() {
        Notification n = new Notification.Builder(mContext, "test")
                .setShortCriticalText("short critical text here")
                .build();

        assertSame(n.getShortCriticalText(), "short critical text here");
    }

    @Test
    public void largeIconMultipleReferences_keptAfterParcelling() {
        Icon originalIcon = Icon.createWithBitmap(BitmapFactory.decodeResource(