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

Commit 6c0f42b3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Ability to hide/unhide suspended app notifications" into pi-dev

parents 5d5d6aa2 5a20a5ed
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40058,6 +40058,7 @@ package android.service.notification {
    method public int getSuppressedVisualEffects();
    method public int getUserSentiment();
    method public boolean isAmbient();
    method public boolean isSuspended();
    method public boolean matchesInterruptionFilter();
    field public static final int USER_SENTIMENT_NEGATIVE = -1; // 0xffffffff
    field public static final int USER_SENTIMENT_NEUTRAL = 0; // 0x0
+34 −2
Original line number Diff line number Diff line
@@ -1418,6 +1418,7 @@ public abstract class NotificationListenerService extends Service {
        private ArrayList<SnoozeCriterion> mSnoozeCriteria;
        private boolean mShowBadge;
        private @UserSentiment int mUserSentiment = USER_SENTIMENT_NEUTRAL;
        private boolean mHidden;

        public Ranking() {}

@@ -1556,6 +1557,16 @@ public abstract class NotificationListenerService extends Service {
            return mShowBadge;
        }

        /**
         * Returns whether the app that posted this notification is suspended, so this notification
         * should be hidden.
         *
         * @return true if the notification should be hidden, false otherwise.
         */
        public boolean isSuspended() {
            return mHidden;
        }

        /**
         * @hide
         */
@@ -1565,7 +1576,7 @@ public abstract class NotificationListenerService extends Service {
                CharSequence explanation, String overrideGroupKey,
                NotificationChannel channel, ArrayList<String> overridePeople,
                ArrayList<SnoozeCriterion> snoozeCriteria, boolean showBadge,
                int userSentiment) {
                int userSentiment, boolean hidden) {
            mKey = key;
            mRank = rank;
            mIsAmbient = importance < NotificationManager.IMPORTANCE_LOW;
@@ -1580,6 +1591,7 @@ public abstract class NotificationListenerService extends Service {
            mSnoozeCriteria = snoozeCriteria;
            mShowBadge = showBadge;
            mUserSentiment = userSentiment;
            mHidden = hidden;
        }

        /**
@@ -1628,6 +1640,7 @@ public abstract class NotificationListenerService extends Service {
        private ArrayMap<String, ArrayList<SnoozeCriterion>> mSnoozeCriteria;
        private ArrayMap<String, Boolean> mShowBadge;
        private ArrayMap<String, Integer> mUserSentiment;
        private ArrayMap<String, Boolean> mHidden;

        private RankingMap(NotificationRankingUpdate rankingUpdate) {
            mRankingUpdate = rankingUpdate;
@@ -1656,7 +1669,7 @@ public abstract class NotificationListenerService extends Service {
                    getVisibilityOverride(key), getSuppressedVisualEffects(key),
                    getImportance(key), getImportanceExplanation(key), getOverrideGroupKey(key),
                    getChannel(key), getOverridePeople(key), getSnoozeCriteria(key),
                    getShowBadge(key), getUserSentiment(key));
                    getShowBadge(key), getUserSentiment(key), getHidden(key));
            return rank >= 0;
        }

@@ -1784,6 +1797,16 @@ public abstract class NotificationListenerService extends Service {
                    ? Ranking.USER_SENTIMENT_NEUTRAL : userSentiment.intValue();
        }

        private boolean getHidden(String key) {
            synchronized (this) {
                if (mHidden == null) {
                    buildHiddenLocked();
                }
            }
            Boolean hidden = mHidden.get(key);
            return hidden == null ? false : hidden.booleanValue();
        }

        // Locked by 'this'
        private void buildRanksLocked() {
            String[] orderedKeys = mRankingUpdate.getOrderedKeys();
@@ -1892,6 +1915,15 @@ public abstract class NotificationListenerService extends Service {
            }
        }

        // Locked by 'this'
        private void buildHiddenLocked() {
            Bundle hidden = mRankingUpdate.getHidden();
            mHidden = new ArrayMap<>(hidden.size());
            for (String key : hidden.keySet()) {
                mHidden.put(key, hidden.getBoolean(key));
            }
        }

        // ----------- Parcelable

        @Override
+9 −1
Original line number Diff line number Diff line
@@ -36,12 +36,13 @@ public class NotificationRankingUpdate implements Parcelable {
    private final Bundle mSnoozeCriteria;
    private final Bundle mShowBadge;
    private final Bundle mUserSentiment;
    private final Bundle mHidden;

    public NotificationRankingUpdate(String[] keys, String[] interceptedKeys,
            Bundle visibilityOverrides, Bundle suppressedVisualEffects,
            int[] importance, Bundle explanation, Bundle overrideGroupKeys,
            Bundle channels, Bundle overridePeople, Bundle snoozeCriteria,
            Bundle showBadge, Bundle userSentiment) {
            Bundle showBadge, Bundle userSentiment, Bundle hidden) {
        mKeys = keys;
        mInterceptedKeys = interceptedKeys;
        mVisibilityOverrides = visibilityOverrides;
@@ -54,6 +55,7 @@ public class NotificationRankingUpdate implements Parcelable {
        mSnoozeCriteria = snoozeCriteria;
        mShowBadge = showBadge;
        mUserSentiment = userSentiment;
        mHidden = hidden;
    }

    public NotificationRankingUpdate(Parcel in) {
@@ -70,6 +72,7 @@ public class NotificationRankingUpdate implements Parcelable {
        mSnoozeCriteria = in.readBundle();
        mShowBadge = in.readBundle();
        mUserSentiment = in.readBundle();
        mHidden = in.readBundle();
    }

    @Override
@@ -91,6 +94,7 @@ public class NotificationRankingUpdate implements Parcelable {
        out.writeBundle(mSnoozeCriteria);
        out.writeBundle(mShowBadge);
        out.writeBundle(mUserSentiment);
        out.writeBundle(mHidden);
    }

    public static final Parcelable.Creator<NotificationRankingUpdate> CREATOR
@@ -151,4 +155,8 @@ public class NotificationRankingUpdate implements Parcelable {
    public Bundle getUserSentiment() {
        return mUserSentiment;
    }

    public Bundle getHidden() {
        return mHidden;
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -529,6 +529,14 @@ public class NotificationData {
        return null;
    }

    public boolean shouldHide(String key) {
        if (mRankingMap != null) {
            getRanking(key, mTmpRanking);
            return mTmpRanking.isSuspended();
        }
        return false;
    }

    private void updateRankingAndSort(RankingMap ranking) {
        if (ranking != null) {
            mRankingMap = ranking;
@@ -618,6 +626,10 @@ public class NotificationData {
            return true;
        }

        if (shouldHide(sbn.getKey())) {
            return true;
        }

        if (!StatusBar.ENABLE_CHILD_NOTIFICATIONS
                && mGroupManager.isChildInGroupWithSummary(sbn)) {
            return true;
+32 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class NotificationDataTest extends SysuiTestCase {

    private static final int UID_NORMAL = 123;
    private static final int UID_ALLOW_DURING_SETUP = 456;
    private static final String TEST_HIDDEN_NOTIFICATION_KEY = "testHiddenNotificationKey";

    private final StatusBarNotification mMockStatusBarNotification =
            mock(StatusBarNotification.class);
@@ -247,6 +248,22 @@ public class NotificationDataTest extends SysuiTestCase {
        assertFalse(mNotificationData.shouldFilterOut(mRow.getEntry().notification));
    }

    @Test
    public void testShouldFilterHiddenNotifications() {
        // setup
        when(mFsc.isSystemAlertWarningNeeded(anyInt(), anyString())).thenReturn(false);
        when(mFsc.isSystemAlertNotification(any())).thenReturn(false);

        // test should filter out hidden notifications:
        // hidden
        when(mMockStatusBarNotification.getKey()).thenReturn(TEST_HIDDEN_NOTIFICATION_KEY);
        assertTrue(mNotificationData.shouldFilterOut(mMockStatusBarNotification));

        // not hidden
        when(mMockStatusBarNotification.getKey()).thenReturn("not hidden");
        assertFalse(mNotificationData.shouldFilterOut(mMockStatusBarNotification));
    }

    private void initStatusBarNotification(boolean allowDuringSetup) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, allowDuringSetup);
@@ -269,6 +286,21 @@ public class NotificationDataTest extends SysuiTestCase {
        @Override
        protected boolean getRanking(String key, NotificationListenerService.Ranking outRanking) {
            super.getRanking(key, outRanking);
            if (key.equals(TEST_HIDDEN_NOTIFICATION_KEY)) {
                outRanking.populate(key, outRanking.getRank(),
                        outRanking.matchesInterruptionFilter(),
                        outRanking.getVisibilityOverride(), outRanking.getSuppressedVisualEffects(),
                        outRanking.getImportance(), outRanking.getImportanceExplanation(),
                        outRanking.getOverrideGroupKey(), outRanking.getChannel(), null, null,
                        outRanking.canShowBadge(), outRanking.getUserSentiment(), true);
            } else {
                outRanking.populate(key, outRanking.getRank(),
                        outRanking.matchesInterruptionFilter(),
                        outRanking.getVisibilityOverride(), outRanking.getSuppressedVisualEffects(),
                        outRanking.getImportance(), outRanking.getImportanceExplanation(),
                        outRanking.getOverrideGroupKey(), outRanking.getChannel(), null, null,
                        outRanking.canShowBadge(), outRanking.getUserSentiment(), false);
            }
            return true;
        }
    }
Loading