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

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

Merge "DO NOT MERGE Allow NAS to suggest importances for notifications" into tm-qpr-dev

parents 11f8189e 4ca6d026
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ public final class Adjustment implements Parcelable {
    /** @hide */
    @StringDef (prefix = { "KEY_" }, value = {
            KEY_CONTEXTUAL_ACTIONS, KEY_GROUP_KEY, KEY_IMPORTANCE, KEY_PEOPLE, KEY_SNOOZE_CRITERIA,
            KEY_TEXT_REPLIES, KEY_USER_SENTIMENT
            KEY_TEXT_REPLIES, KEY_USER_SENTIMENT, KEY_IMPORTANCE_PROPOSAL
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Keys {}
@@ -121,6 +121,19 @@ public final class Adjustment implements Parcelable {
     */
    public static final String KEY_IMPORTANCE = "key_importance";

    /**
     * Weaker than {@link #KEY_IMPORTANCE}, this adjustment suggests an importance rather than
     * mandates an importance change.
     *
     * A notification listener can interpet this suggestion to show the user a prompt to change
     * notification importance for the notification (or type, or app) moving forward.
     *
     * Data type: int, one of importance values e.g.
     * {@link android.app.NotificationManager#IMPORTANCE_MIN}.
     * @hide
     */
    public static final String KEY_IMPORTANCE_PROPOSAL = "key_importance_proposal";

    /**
     * Data type: float, a ranking score from 0 (lowest) to 1 (highest).
     * Used to rank notifications inside that fall under the same classification (i.e. alerting,
+26 −3
Original line number Diff line number Diff line
@@ -1711,6 +1711,8 @@ public abstract class NotificationListenerService extends Service {
        private ShortcutInfo mShortcutInfo;
        private @RankingAdjustment int mRankingAdjustment;
        private boolean mIsBubble;
        // Notification assistant importance suggestion
        private int mProposedImportance;

        private static final int PARCEL_VERSION = 2;

@@ -1748,6 +1750,7 @@ public abstract class NotificationListenerService extends Service {
            out.writeParcelable(mShortcutInfo, flags);
            out.writeInt(mRankingAdjustment);
            out.writeBoolean(mIsBubble);
            out.writeInt(mProposedImportance);
        }

        /** @hide */
@@ -1786,6 +1789,7 @@ public abstract class NotificationListenerService extends Service {
            mShortcutInfo = in.readParcelable(cl, android.content.pm.ShortcutInfo.class);
            mRankingAdjustment = in.readInt();
            mIsBubble = in.readBoolean();
            mProposedImportance = in.readInt();
        }


@@ -1877,6 +1881,22 @@ public abstract class NotificationListenerService extends Service {
            return mRankingScore;
        }

        /**
         * Returns the proposed importance provided by the {@link NotificationAssistantService}.
         *
         * This can be used to suggest that the user change the importance of this type of
         * notification moving forward. A value of
         * {@link NotificationManager#IMPORTANCE_UNSPECIFIED} means that the NAS has not recommended
         * a change to the importance, and no UI should be shown to the user. See
         * {@link Adjustment#KEY_IMPORTANCE_PROPOSAL}.
         *
         * @return the importance of the notification
         * @hide
         */
        public @NotificationManager.Importance int getProposedImportance() {
            return mProposedImportance;
        }

        /**
         * If the system has overridden the group key, then this will be non-null, and this
         * key should be used to bundle notifications.
@@ -2041,7 +2061,7 @@ public abstract class NotificationListenerService extends Service {
                boolean noisy, ArrayList<Notification.Action> smartActions,
                ArrayList<CharSequence> smartReplies, boolean canBubble,
                boolean isTextChanged, boolean isConversation, ShortcutInfo shortcutInfo,
                int rankingAdjustment, boolean isBubble) {
                int rankingAdjustment, boolean isBubble, int proposedImportance) {
            mKey = key;
            mRank = rank;
            mIsAmbient = importance < NotificationManager.IMPORTANCE_LOW;
@@ -2067,6 +2087,7 @@ public abstract class NotificationListenerService extends Service {
            mShortcutInfo = shortcutInfo;
            mRankingAdjustment = rankingAdjustment;
            mIsBubble = isBubble;
            mProposedImportance = proposedImportance;
        }

        /**
@@ -2107,7 +2128,8 @@ public abstract class NotificationListenerService extends Service {
                    other.mIsConversation,
                    other.mShortcutInfo,
                    other.mRankingAdjustment,
                    other.mIsBubble);
                    other.mIsBubble,
                    other.mProposedImportance);
        }

        /**
@@ -2166,7 +2188,8 @@ public abstract class NotificationListenerService extends Service {
                    &&  Objects.equals((mShortcutInfo == null ? 0 : mShortcutInfo.getId()),
                    (other.mShortcutInfo == null ? 0 : other.mShortcutInfo.getId()))
                    && Objects.equals(mRankingAdjustment, other.mRankingAdjustment)
                    && Objects.equals(mIsBubble, other.mIsBubble);
                    && Objects.equals(mIsBubble, other.mIsBubble)
                    && Objects.equals(mProposedImportance, other.mProposedImportance);
        }
    }

+2 −1
Original line number Diff line number Diff line
@@ -290,7 +290,8 @@ public class NotificationListener extends NotificationListenerWithPlugins implem
                    false,
                    null,
                    0,
                    false
                    false,
                    0
            );
        }
        return ranking;
+1 −1
Original line number Diff line number Diff line
@@ -127,6 +127,6 @@ class TargetSdkResolverTest : SysuiTestCase() {
                NotificationManager.IMPORTANCE_DEFAULT,
                null, null,
                null, null, null, true, 0, false, -1, false, null, null, false, false,
                false, null, 0, false)
                false, null, 0, false, 0)
    }
}
+11 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar;

import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;

import android.annotation.NonNull;
import android.app.Notification;
import android.app.NotificationChannel;
@@ -57,6 +59,7 @@ public class RankingBuilder {
    private ShortcutInfo mShortcutInfo = null;
    private int mRankingAdjustment = 0;
    private boolean mIsBubble = false;
    private int mProposedImportance = IMPORTANCE_UNSPECIFIED;

    public RankingBuilder() {
    }
@@ -86,6 +89,7 @@ public class RankingBuilder {
        mShortcutInfo = ranking.getConversationShortcutInfo();
        mRankingAdjustment = ranking.getRankingAdjustment();
        mIsBubble = ranking.isBubble();
        mProposedImportance = ranking.getProposedImportance();
    }

    public Ranking build() {
@@ -114,7 +118,8 @@ public class RankingBuilder {
                mIsConversation,
                mShortcutInfo,
                mRankingAdjustment,
                mIsBubble);
                mIsBubble,
                mProposedImportance);
        return ranking;
    }

@@ -214,6 +219,11 @@ public class RankingBuilder {
        return this;
    }

    public RankingBuilder setProposedImportance(@Importance int importance) {
        mProposedImportance = importance;
        return this;
    }

    public RankingBuilder setUserSentiment(int userSentiment) {
        mUserSentiment = userSentiment;
        return this;
Loading