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

Commit 329d99b4 authored by Alex Mang's avatar Alex Mang Committed by Android (Google) Code Review
Browse files

Merge "Passing notification rank to NLS#Ranking as a hidden api."

parents 88814052 f36cbffd
Loading
Loading
Loading
Loading
+41 −3
Original line number Diff line number Diff line
@@ -1543,6 +1543,29 @@ public abstract class NotificationListenerService extends Service {
        @Retention(RetentionPolicy.SOURCE)
        public @interface UserSentiment {}

        /**
         * Notification was demoted in shade
         * @hide
         */
        public static final int RANKING_DEMOTED = -1;
        /**
         * Notification was unchanged
         * @hide
         */
        public static final int RANKING_UNCHANGED = 0;
        /**
         * Notification was promoted in shade
         * @hide
         */
        public static final int RANKING_PROMOTED = 1;

        /** @hide */
        @IntDef(prefix = { "RANKING_" }, value = {
                RANKING_PROMOTED, RANKING_DEMOTED, RANKING_UNCHANGED
        })
        @Retention(RetentionPolicy.SOURCE)
        public @interface RankingAdjustment {}

        private @NonNull String mKey;
        private int mRank = -1;
        private boolean mIsAmbient;
@@ -1570,6 +1593,7 @@ public abstract class NotificationListenerService extends Service {
        private boolean mVisuallyInterruptive;
        private boolean mIsConversation;
        private ShortcutInfo mShortcutInfo;
        private @RankingAdjustment int mRankingAdjustment;

        private static final int PARCEL_VERSION = 2;

@@ -1604,6 +1628,7 @@ public abstract class NotificationListenerService extends Service {
            out.writeBoolean(mVisuallyInterruptive);
            out.writeBoolean(mIsConversation);
            out.writeParcelable(mShortcutInfo, flags);
            out.writeInt(mRankingAdjustment);
        }

        /** @hide */
@@ -1639,6 +1664,7 @@ public abstract class NotificationListenerService extends Service {
            mVisuallyInterruptive = in.readBoolean();
            mIsConversation = in.readBoolean();
            mShortcutInfo = in.readParcelable(cl);
            mRankingAdjustment = in.readInt();
        }


@@ -1850,6 +1876,14 @@ public abstract class NotificationListenerService extends Service {
            return mShortcutInfo;
        }

        /**
         * Returns the intended transition to ranking passed by {@link NotificationAssistantService}
         * @hide
         */
        public @RankingAdjustment int getRankingAdjustment() {
            return mRankingAdjustment;
        }

        /**
         * @hide
         */
@@ -1862,7 +1896,8 @@ public abstract class NotificationListenerService extends Service {
                int userSentiment, boolean hidden, long lastAudiblyAlertedMs,
                boolean noisy, ArrayList<Notification.Action> smartActions,
                ArrayList<CharSequence> smartReplies, boolean canBubble,
                boolean visuallyInterruptive, boolean isConversation, ShortcutInfo shortcutInfo) {
                boolean visuallyInterruptive, boolean isConversation, ShortcutInfo shortcutInfo,
                int rankingAdjustment) {
            mKey = key;
            mRank = rank;
            mIsAmbient = importance < NotificationManager.IMPORTANCE_LOW;
@@ -1886,6 +1921,7 @@ public abstract class NotificationListenerService extends Service {
            mVisuallyInterruptive = visuallyInterruptive;
            mIsConversation = isConversation;
            mShortcutInfo = shortcutInfo;
            mRankingAdjustment = rankingAdjustment;
        }

        /**
@@ -1913,7 +1949,8 @@ public abstract class NotificationListenerService extends Service {
                    other.mCanBubble,
                    other.mVisuallyInterruptive,
                    other.mIsConversation,
                    other.mShortcutInfo);
                    other.mShortcutInfo,
                    other.mRankingAdjustment);
        }

        /**
@@ -1970,7 +2007,8 @@ public abstract class NotificationListenerService extends Service {
                    && Objects.equals(mIsConversation, other.mIsConversation)
                    // Shortcutinfo doesn't have equals either; use id
                    &&  Objects.equals((mShortcutInfo == null ? 0 : mShortcutInfo.getId()),
                    (other.mShortcutInfo == null ? 0 : other.mShortcutInfo.getId()));
                    (other.mShortcutInfo == null ? 0 : other.mShortcutInfo.getId()))
                    && Objects.equals(mRankingAdjustment, other.mRankingAdjustment);
        }
    }

+2 −1
Original line number Diff line number Diff line
@@ -206,7 +206,8 @@ public class NotificationListener extends NotificationListenerWithPlugins {
                    false,
                    false,
                    false,
                    null
                    null,
                    0
            );
        }
        return ranking;
+9 −1
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public class RankingBuilder {
    private boolean mIsVisuallyInterruptive = false;
    private boolean mIsConversation = false;
    private ShortcutInfo mShortcutInfo = null;
    private int mRankingAdjustment = 0;

    public RankingBuilder() {
    }
@@ -82,6 +83,7 @@ public class RankingBuilder {
        mIsVisuallyInterruptive = ranking.visuallyInterruptive();
        mIsConversation = ranking.isConversation();
        mShortcutInfo = ranking.getShortcutInfo();
        mRankingAdjustment = ranking.getRankingAdjustment();
    }

    public Ranking build() {
@@ -108,7 +110,8 @@ public class RankingBuilder {
                mCanBubble,
                mIsVisuallyInterruptive,
                mIsConversation,
                mShortcutInfo);
                mShortcutInfo,
                mRankingAdjustment);
        return ranking;
    }

@@ -198,6 +201,11 @@ public class RankingBuilder {
        return this;
    }

    public RankingBuilder setRankingAdjustment(int rankingAdjustment) {
        mRankingAdjustment = rankingAdjustment;
        return this;
    }

    public RankingBuilder setImportance(@Importance int importance) {
        mImportance = importance;
        return this;
+2 −2
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
                    IMPORTANCE_DEFAULT,
                    null, null,
                    null, null, null, true, sentiment, false, -1, false, null, null, false, false,
                    false, null);
                    false, null, 0);
            return true;
        }).when(mRankingMap).getRanking(eq(key), any(Ranking.class));
    }
@@ -162,7 +162,7 @@ public class NotificationEntryManagerTest extends SysuiTestCase {
                    null, null,
                    null, null, null, true,
                    Ranking.USER_SENTIMENT_NEUTRAL, false, -1,
                    false, smartActions, null, false, false, false, null);
                    false, smartActions, null, false, false, false, null, 0);
            return true;
        }).when(mRankingMap).getRanking(eq(key), any(Ranking.class));
    }
+3 −1
Original line number Diff line number Diff line
@@ -284,7 +284,9 @@ public class NotificationEntryManagerInflationTest extends SysuiTestCase {
                false,
                false,
                false,
                null);
                null,
                0
            );
        mRankingMap = new NotificationListenerService.RankingMap(new Ranking[] {ranking});

        TestableLooper.get(this).processAllMessages();
Loading