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

Commit bf048715 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Allow NAS to suggest importances for notifications

(In addition to the existing 'change importance' adjustment).

Fixes: 262578968
Test: NotificationListenerServiceTest
Test: NotificationRecordExtractorDataTest
Test: NotificationRecordTest
TesT: CTS in same topic
Change-Id: I510414cba256cfb9fb19fa659947e7737f6fd4e1
parent 0451de39
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -11785,6 +11785,7 @@ package android.service.notification {
    field @NonNull public static final android.os.Parcelable.Creator<android.service.notification.Adjustment> CREATOR;
    field public static final String KEY_CONTEXTUAL_ACTIONS = "key_contextual_actions";
    field public static final String KEY_IMPORTANCE = "key_importance";
    field public static final String KEY_IMPORTANCE_PROPOSAL = "key_importance_proposal";
    field public static final String KEY_NOT_CONVERSATION = "key_not_conversation";
    field public static final String KEY_PEOPLE = "key_people";
    field public static final String KEY_RANKING_SCORE = "key_ranking_score";
@@ -11825,6 +11826,10 @@ package android.service.notification {
    method public void onNotificationRemoved(@NonNull android.service.notification.StatusBarNotification, @NonNull android.service.notification.NotificationListenerService.RankingMap, @NonNull android.service.notification.NotificationStats, int);
  }
  public static class NotificationListenerService.Ranking {
    method public int getProposedImportance();
  }
  public final class NotificationStats implements android.os.Parcelable {
    ctor public NotificationStats();
    ctor protected NotificationStats(android.os.Parcel);
+13 −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,18 @@ 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}.
     */
    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,
+27 −3
Original line number Diff line number Diff line
@@ -1730,6 +1730,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;

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

        /** @hide */
@@ -1805,6 +1808,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();
        }


@@ -1896,6 +1900,23 @@ 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
         */
        @SystemApi
        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.
@@ -2060,7 +2081,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;
@@ -2086,6 +2107,7 @@ public abstract class NotificationListenerService extends Service {
            mShortcutInfo = shortcutInfo;
            mRankingAdjustment = rankingAdjustment;
            mIsBubble = isBubble;
            mProposedImportance = proposedImportance;
        }

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

        /**
@@ -2185,7 +2208,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)
    }
}
Loading