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

Commit 9abc5064 authored by Gus Prevas's avatar Gus Prevas
Browse files

Adds silence toggle to notification settings.

This change modifies the UI that appears when a notification is
long-pressed to include a third option when the notification could
potentially buzz or make sound, allowing the user to promote or demote
the notification's channel such that it will not alert (or will start
alerting) for future notifications.

Test: atest SystemUITests
Bug: 116622974
Change-Id: Ia070d0ef1b181b4de8b3d49ace9ff2a65fed8deb
parent a3226490
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -1462,6 +1462,7 @@ public abstract class NotificationListenerService extends Service {
        private @UserSentiment int mUserSentiment = USER_SENTIMENT_NEUTRAL;
        private boolean mHidden;
        private boolean mAudiblyAlerted;
        private boolean mNoisy;
        private ArrayList<Notification.Action> mSmartActions;
        private ArrayList<CharSequence> mSmartReplies;

@@ -1636,6 +1637,11 @@ public abstract class NotificationListenerService extends Service {
            return mAudiblyAlerted;
        }

        /** @hide */
        public boolean isNoisy() {
            return mNoisy;
        }

        /**
         * @hide
         */
@@ -1646,7 +1652,8 @@ public abstract class NotificationListenerService extends Service {
                NotificationChannel channel, ArrayList<String> overridePeople,
                ArrayList<SnoozeCriterion> snoozeCriteria, boolean showBadge,
                int userSentiment, boolean hidden, boolean audiblyAlerted,
                ArrayList<Notification.Action> smartActions, ArrayList<CharSequence> smartReplies) {
                boolean noisy, ArrayList<Notification.Action> smartActions,
                ArrayList<CharSequence> smartReplies) {
            mKey = key;
            mRank = rank;
            mIsAmbient = importance < NotificationManager.IMPORTANCE_LOW;
@@ -1663,6 +1670,7 @@ public abstract class NotificationListenerService extends Service {
            mUserSentiment = userSentiment;
            mHidden = hidden;
            mAudiblyAlerted = audiblyAlerted;
            mNoisy = noisy;
            mSmartActions = smartActions;
            mSmartReplies = smartReplies;
        }
@@ -1715,6 +1723,7 @@ public abstract class NotificationListenerService extends Service {
        private ArrayMap<String, Integer> mUserSentiment;
        private ArrayMap<String, Boolean> mHidden;
        private ArrayMap<String, Boolean> mAudiblyAlerted;
        private ArrayMap<String, Boolean> mNoisy;
        private ArrayMap<String, ArrayList<Notification.Action>> mSmartActions;
        private ArrayMap<String, ArrayList<CharSequence>> mSmartReplies;

@@ -1746,7 +1755,8 @@ public abstract class NotificationListenerService extends Service {
                    getImportance(key), getImportanceExplanation(key), getOverrideGroupKey(key),
                    getChannel(key), getOverridePeople(key), getSnoozeCriteria(key),
                    getShowBadge(key), getUserSentiment(key), getHidden(key),
                    getAudiblyAlerted(key), getSmartActions(key), getSmartReplies(key));
                    getAudiblyAlerted(key), getNoisy(key), getSmartActions(key),
                    getSmartReplies(key));
            return rank >= 0;
        }

@@ -1894,6 +1904,16 @@ public abstract class NotificationListenerService extends Service {
            return audiblyAlerted == null ? false : audiblyAlerted.booleanValue();
        }

        private boolean getNoisy(String key) {
            synchronized (this) {
                if (mNoisy == null) {
                    buildNoisyLocked();
                }
            }
            Boolean noisy = mNoisy.get(key);
            return noisy == null ? false : noisy.booleanValue();
        }

        private ArrayList<Notification.Action> getSmartActions(String key) {
            synchronized (this) {
                if (mSmartActions == null) {
@@ -2033,6 +2053,11 @@ public abstract class NotificationListenerService extends Service {
            mAudiblyAlerted = buildBooleanMapFromBundle(mRankingUpdate.getAudiblyAlerted());
        }

        // Locked by 'this'
        private void buildNoisyLocked() {
            mNoisy = buildBooleanMapFromBundle(mRankingUpdate.getNoisy());
        }

        // Locked by 'this'
        private void buildSmartActions() {
            Bundle smartActions = mRankingUpdate.getSmartActions();
+9 −1
Original line number Diff line number Diff line
@@ -40,13 +40,14 @@ public class NotificationRankingUpdate implements Parcelable {
    private final Bundle mSmartActions;
    private final Bundle mSmartReplies;
    private final Bundle mAudiblyAlerted;
    private final Bundle mNoisy;

    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 hidden, Bundle smartActions,
            Bundle smartReplies, Bundle audiblyAlerted) {
            Bundle smartReplies, Bundle audiblyAlerted, Bundle noisy) {
        mKeys = keys;
        mInterceptedKeys = interceptedKeys;
        mVisibilityOverrides = visibilityOverrides;
@@ -63,6 +64,7 @@ public class NotificationRankingUpdate implements Parcelable {
        mSmartActions = smartActions;
        mSmartReplies = smartReplies;
        mAudiblyAlerted = audiblyAlerted;
        mNoisy = noisy;
    }

    public NotificationRankingUpdate(Parcel in) {
@@ -83,6 +85,7 @@ public class NotificationRankingUpdate implements Parcelable {
        mSmartActions = in.readBundle();
        mSmartReplies = in.readBundle();
        mAudiblyAlerted = in.readBundle();
        mNoisy = in.readBundle();
    }

    @Override
@@ -108,6 +111,7 @@ public class NotificationRankingUpdate implements Parcelable {
        out.writeBundle(mSmartActions);
        out.writeBundle(mSmartReplies);
        out.writeBundle(mAudiblyAlerted);
        out.writeBundle(mNoisy);
    }

    public static final Parcelable.Creator<NotificationRankingUpdate> CREATOR
@@ -184,4 +188,8 @@ public class NotificationRankingUpdate implements Parcelable {
    public Bundle getAudiblyAlerted() {
        return mAudiblyAlerted;
    }

    public Bundle getNoisy() {
        return mNoisy;
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -151,6 +151,13 @@
                android:layout_height="match_parent"
                android:layout_marginStart="@dimen/notification_guts_button_horizontal_spacing"
                style="@style/TextAppearance.NotificationInfo.Button" />
            <TextView
                android:id="@+id/toggle_silent"
                android:text="@string/inline_silent_button_silent"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginStart="@dimen/notification_guts_button_horizontal_spacing"
                style="@style/TextAppearance.NotificationInfo.Button" />
            <TextView
                android:id="@+id/keep"
                android:minWidth="48dp"
+12 −0
Original line number Diff line number Diff line
@@ -1540,6 +1540,12 @@
    <!-- Notification inline controls: Shown when a channel's notifications are minimized -->
    <string name="notification_channel_minimized">These notifications will be minimized</string>

    <!-- Notification inline controls: Shown when a channel's notifications are silenced [CHAR_LIMIT=100] -->
    <string name="notification_channel_silenced">These notifications will be shown silently</string>

    <!-- Notification inline controls: Shown when a channel's notifications are set to alert [CHAR_LIMIT=100] -->
    <string name="notification_channel_unsilenced">These notifications will alert you</string>

    <!-- Notification Inline controls: continue receiving notifications prompt, channel level -->
    <string name="inline_blocking_helper">You usually dismiss these notifications.
    \nKeep showing them?</string>
@@ -1556,6 +1562,12 @@
    <!-- Notification inline controls: minimize notifications button -->
    <string name="inline_minimize_button">Minimize</string>

    <!-- Notification inline controls: show notifications silently button [CHAR_LIMIT=25] -->
    <string name="inline_silent_button_silent">Show silently</string>

    <!-- Notification inline controls: show and alert button [CHAR_LIMIT=25] -->
    <string name="inline_silent_button_alert">Show and alert</string>

    <!-- Notification Inline controls: continue receiving notifications prompt, app level -->
    <string name="inline_keep_showing_app">Keep showing notifications from this app?</string>

+4 −0
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@ public class NotificationData {
        public StatusBarNotification notification;
        public NotificationChannel channel;
        public boolean audiblyAlerted;
        public boolean noisy;
        public int importance;
        public StatusBarIconView icon;
        public StatusBarIconView expandedIcon;
        public ExpandableNotificationRow row; // the outer expanded view
@@ -155,6 +157,8 @@ public class NotificationData {
        public void populateFromRanking(@NonNull Ranking ranking) {
            channel = ranking.getChannel();
            audiblyAlerted = ranking.audiblyAlerted();
            noisy = ranking.isNoisy();
            importance = ranking.getImportance();
            snoozeCriteria = ranking.getSnoozeCriteria();
            userSentiment = ranking.getUserSentiment();
            smartActions = ranking.getSmartActions() == null
Loading