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

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

Merge "Expand support for summarization" into main

parents 3008506a 82db42b8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6535,6 +6535,7 @@ package android.app {
    method public String getShortcutId();
    method public android.graphics.drawable.Icon getSmallIcon();
    method public String getSortKey();
    method @FlaggedApi("android.app.nm_summarization_all") @Nullable public CharSequence getSummarizedContent();
    method public long getTimeoutAfter();
    method public boolean hasImage();
    method @FlaggedApi("android.app.api_rich_ongoing") public boolean hasPromotableCharacteristics();
@@ -6874,6 +6875,7 @@ package android.app {
    method @Deprecated public android.app.Notification.Builder setSound(android.net.Uri, android.media.AudioAttributes);
    method @NonNull public android.app.Notification.Builder setStyle(android.app.Notification.Style);
    method @NonNull public android.app.Notification.Builder setSubText(CharSequence);
    method @FlaggedApi("android.app.nm_summarization_all") @NonNull public android.app.Notification.Builder setSummarizedContent(@Nullable CharSequence);
    method @NonNull public android.app.Notification.Builder setTicker(CharSequence);
    method @Deprecated public android.app.Notification.Builder setTicker(CharSequence, android.widget.RemoteViews);
    method @NonNull public android.app.Notification.Builder setTimeoutAfter(long);
+36 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.app;
import static android.annotation.Dimension.DP;
import static android.app.Flags.FLAG_NM_SUMMARIZATION;
import static android.app.Flags.FLAG_NM_SUMMARIZATION_ALL;
import static android.app.Flags.FLAG_NOTIFICATION_IS_ANIMATED_ACTION_API;
import static android.app.Flags.FLAG_HIDE_STATUS_BAR_NOTIFICATION;
import static android.app.Flags.notificationsRedesignTemplates;
@@ -1249,6 +1250,12 @@ public class Notification implements Parcelable
    public static final String EXTRA_CONTAINS_SUMMARIZATION
            = "android.app.extra.contains_summarization";
    /**
     * @hide
     */
    public static final String EXTRA_APP_SUMMARIZATION
            = "android.app.extra.app_summarization";
    /**
     * {@link #extras} key: this is the title of the notification,
     * as supplied to {@link Builder#setContentTitle(CharSequence)}.
@@ -4847,6 +4854,22 @@ public class Notification implements Parcelable
            return this;
        }
        /**
         * Sets the text that was computationally summarized from other sources, if applicable. The
         * OS may choose to display this content instead of the original notification content on
         * some surfaces and may add styling to indicate to the user that this was computationally
         * generated.
         */
        @FlaggedApi(FLAG_NM_SUMMARIZATION_ALL)
        @NonNull
        public Builder setSummarizedContent(@Nullable CharSequence summarizedContent) {
            mN.extras.putCharSequence(EXTRA_APP_SUMMARIZATION, summarizedContent);
            if (Flags.nmSummarization()) {
                setHasSummarizedContent(!TextUtils.isEmpty(summarizedContent));
            }
            return this;
        }
        private ContrastColorUtil getColorUtil() {
            if (mColorUtil == null) {
                mColorUtil = ContrastColorUtil.getInstance(mContext);
@@ -8381,13 +8404,25 @@ public class Notification implements Parcelable
    }
    /**
     * Returns whether this notification contains computationally summarized text.
     * Returns whether this notification contains computationally summarized text. The
     * OS may choose to display this content instead of the original notification content on
     * some surfaces and may add styling to indicate to the user that this was computationally
     * generated.
     */
    @FlaggedApi(FLAG_NM_SUMMARIZATION)
    public boolean hasSummarizedContent() {
        return extras != null && extras.getBoolean(EXTRA_CONTAINS_SUMMARIZATION);
    }
    /**
     * Returns app provided computationally summarized text that represents the content of the
     * notification.
     */
    @FlaggedApi(FLAG_NM_SUMMARIZATION_ALL)
    public @Nullable CharSequence getSummarizedContent() {
        return extras != null ? extras.getCharSequence(EXTRA_APP_SUMMARIZATION) : null;
    }
    /**
     * Returns #when, unless it's set to 0, which should be shown as/treated as a 'current'
     * notification. 0 is treated as a special value because it was special in an old version of
+7 −0
Original line number Diff line number Diff line
@@ -375,6 +375,13 @@ flag {
  }
}

flag {
  name: "nm_summarization_all"
  namespace: "notifications"
  description: "Allows the NAS to summarize notifications of any type"
  bug: "430487852"
}

# End: exported flags that cannot be removed


+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.systemui.statusbar.notification

import android.app.Flags;
import com.android.systemui.flags.FlagToken
import com.android.systemui.flags.RefactorFlagUtils

/**
 * Helper for android.app.nm_summarization_all.
 */
@Suppress("NOTHING_TO_INLINE")
object NmSummarizationAllFlag {
    const val FLAG_NAME = Flags.FLAG_NM_SUMMARIZATION_ALL

    /** A token used for dependency declaration */
    val token: FlagToken
        get() = FlagToken(FLAG_NAME, isEnabled)

    /** Is the notification minimalism enabled */
    @JvmStatic
    inline val isEnabled
        get() = Flags.nmSummarizationAll()

    /**
     * Called to ensure code is only run when the flag is enabled. This protects users from the
     * unintended behaviors caused by accidentally running new logic, while also crashing on an eng
     * build to ensure that the refactor author catches issues in testing.
     */
    @JvmStatic
    inline fun isUnexpectedlyInLegacyMode() =
            RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, FLAG_NAME)

    /**
     * Called to ensure code is only run when the flag is disabled. This will throw an exception if
     * the flag is enabled to ensure that the refactor author catches issues in testing.
     */
    @JvmStatic
    inline fun assertInLegacyMode() =
        RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME)
}
 No newline at end of file