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

Unverified Commit 98e86b50 authored by Marc K's avatar Marc K Committed by Michael Bestas
Browse files

Add importance level to block lock screen notifications (fixed) (1/2)



One feature that is still missing in the handling of notifications in
N is the possibility to block them app-wise for relevance/importance
reasons rather than for privacy reasons – i.e. also on the insecure
lock screen.

This patch plugs the hole by introducing a new importance level "very
low" between "min" and "low" in the power notification controls that
allows notifications on the status bar, but not on the lock screen.

It brings back most of the functionality of
Ib166db1b1673aeaea132c8eeb16c650d2f254a82 excluding the ability of
blocking only ongoing (persistent) notifications.

This fixed version does not break the API.

Change-Id: I31d915a0624185503a71412e231b2295e1913c58
Signed-off-by: default avatarMarc K <morckx@gmail.com>
parent 4f27751d
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ public class NotificationManager

    /** @hide */
    @IntDef({VISIBILITY_NO_OVERRIDE, IMPORTANCE_UNSPECIFIED, IMPORTANCE_NONE,
            IMPORTANCE_MIN, IMPORTANCE_LOW, IMPORTANCE_DEFAULT, IMPORTANCE_HIGH,
            IMPORTANCE_MIN, IMPORTANCE_VERY_LOW, IMPORTANCE_LOW, IMPORTANCE_DEFAULT, IMPORTANCE_HIGH,
            IMPORTANCE_MAX})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Importance {}
@@ -208,6 +208,13 @@ public class NotificationManager
     */
    public static final int IMPORTANCE_MIN = 1;

    /**
     * Very low notification importance: shows on the status bar, but never
     * on the lock screen and is not intrusive.
     */
    /** @hide */
    public static final int IMPORTANCE_VERY_LOW = 6;

    /**
     * Low notification importance: shows everywhere, but is not intrusive.
     */
+58 −1
Original line number Diff line number Diff line
@@ -1038,6 +1038,13 @@ public abstract class NotificationListenerService extends Service {
         */
        public static final int IMPORTANCE_MIN = NotificationManager.IMPORTANCE_MIN;

        /**
         * Very low notification importance: not on lock screen and not intrusive.
         *
         * @hide
         */
        public static final int IMPORTANCE_VERY_LOW = NotificationManager.IMPORTANCE_VERY_LOW;

        /**
         * Low notification importance: shows everywhere, but is not intrusive.
         *
@@ -1169,7 +1176,7 @@ public abstract class NotificationListenerService extends Service {
                CharSequence explanation, String overrideGroupKey) {
            mKey = key;
            mRank = rank;
            mIsAmbient = importance < IMPORTANCE_LOW;
            mIsAmbient = importanceToLevel(importance) < importanceToLevel(IMPORTANCE_VERY_LOW);
            mMatchesInterruptionFilter = matchesInterruptionFilter;
            mVisibilityOverride = visibilityOverride;
            mSuppressedVisualEffects = suppressedVisualEffects;
@@ -1189,6 +1196,8 @@ public abstract class NotificationListenerService extends Service {
                    return "NONE";
                case IMPORTANCE_MIN:
                    return "MIN";
                case IMPORTANCE_VERY_LOW:
                    return "VERY_LOW";
                case IMPORTANCE_LOW:
                    return "LOW";
                case IMPORTANCE_DEFAULT:
@@ -1201,6 +1210,54 @@ public abstract class NotificationListenerService extends Service {
                    return "UNKNOWN(" + String.valueOf(importance) + ")";
            }
        }

        /**
         * {@hide}
         */
        public static int importanceToLevel(int importance) {
            switch (importance) {
                case IMPORTANCE_NONE:
                    return 0;
                case IMPORTANCE_MIN:
                    return 1;
                case IMPORTANCE_VERY_LOW:
                    return 2;
                case IMPORTANCE_LOW:
                    return 3;
                case IMPORTANCE_DEFAULT:
                    return 4;
                case IMPORTANCE_HIGH:
                    return 5;
                case IMPORTANCE_MAX:
                    return 6;
                default:
                    return 4;
            }
        }

        /**
         * {@hide}
         */
        public static int levelToImportance(int level) {
            switch (level) {
                case 0:
                    return IMPORTANCE_NONE;
                case 1:
                    return IMPORTANCE_MIN;
                case 2:
                    return IMPORTANCE_VERY_LOW;
                case 3:
                    return IMPORTANCE_LOW;
                case 4:
                    return IMPORTANCE_DEFAULT;
                case 5:
                    return IMPORTANCE_HIGH;
                case 6:
                    return IMPORTANCE_MAX;
                default:
                    return IMPORTANCE_UNSPECIFIED;
            }
        }
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -25,6 +25,6 @@
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:text="@string/power_notification_controls_description"/>
            android:text="@string/cm_power_notification_controls_description"/>

</LinearLayout>
+38 −0
Original line number Diff line number Diff line
@@ -33,6 +33,44 @@
    <string name="quick_settings_tile_flashlight_not_title">Flashlight is on</string>
    <string name="quick_settings_tile_flashlight_not_summary">Tap to turn off</string>

    <!-- [CHAR LIMIT=NONE] Importance Tuner setting title -->
    <string name="cm_power_notification_controls_description">With power notification controls, you can set an importance level from 0 to 6 for an app\'s notifications.
        \n\n<b>Level 6</b>
        \n- Show at the top of the notification list
        \n- Allow full screen interruption
        \n- Always peek
        \n\n<b>Level 5</b>
        \n- Prevent full screen interruption
        \n- Always peek
        \n\n<b>Level 4</b>
        \n- Prevent full screen interruption
        \n- Never peek
        \n\n<b>Level 3</b>
        \n- Prevent full screen interruption
        \n- Never peek
        \n- Never make sound and vibration
        \n\n<b>Level 2</b>
        \n- Prevent full screen interruption
        \n- Never peek
        \n- Never make sound or vibrate
        \n- Hide from lock screen
        \n- Show at the bottom of the notification list
        \n\n<b>Level 1</b>
        \n- Prevent full screen interruption
        \n- Never peek
        \n- Never make sound or vibrate
        \n- Hide from lock screen and status bar
        \n- Show at the bottom of the notification list
        \n\n<b>Level 0</b>
        \n- Block all notifications from the app
    </string>

    <!-- Notification importance level title-->
    <string name="importance_level_title">Importance: Level %1$d</string>

    <!-- [CHAR LIMIT=100] Notification Importance slider: very low importance level description -->
    <string name="notification_importance_very_low">No full screen interruption, peeking, sound, or vibration. Hide from lock screen.</string>

    <!-- Screen pinning dialog description (for devices without navbar) -->
    <string name="screen_pinning_description_no_navbar">This keeps it in view until you unpin. Touch and hold the Back button to unpin.</string>

+0 −36
Original line number Diff line number Diff line
@@ -1290,45 +1290,9 @@
    <string name="tuner_full_importance_settings">Power notification controls</string>
    <string name="tuner_full_importance_settings_on">On</string>
    <string name="tuner_full_importance_settings_off">Off</string>
    <string name="power_notification_controls_description">With power notification controls, you can set an importance level from 0 to 5 for an app\'s notifications.
        \n\n<b>Level 5</b>
        \n- Show at the top of the notification list
        \n- Allow full screen interruption
        \n- Always peek
        \n\n<b>Level 4</b>
        \n- Prevent full screen interruption
        \n- Always peek
        \n\n<b>Level 3</b>
        \n- Prevent full screen interruption
        \n- Never peek
        \n\n<b>Level 2</b>
        \n- Prevent full screen interruption
        \n- Never peek
        \n- Never make sound and vibration
        \n\n<b>Level 1</b>
        \n- Prevent full screen interruption
        \n- Never peek
        \n- Never make sound or vibrate
        \n- Hide from lock screen and status bar
        \n- Show at the bottom of the notification list
        \n\n<b>Level 0</b>
        \n- Block all notifications from the app
    </string>

    <!-- Notification importance title, user unspecified status-->
    <string name="user_unspecified_importance">Importance: Automatic</string>
    <!-- Notification importance title, blocked status-->
    <string name="blocked_importance">Importance: Level 0</string>
    <!-- Notification importance title, min status-->
    <string name="min_importance">Importance: Level 1</string>
    <!-- Notification importance title, low status-->
    <string name="low_importance">Importance: Level 2</string>
    <!-- Notification importance title, normal status-->
    <string name="default_importance">Importance: Level 3</string>
    <!-- Notification importance title, high status-->
    <string name="high_importance">Importance: Level 4</string>
    <!-- Notification importance title, max status-->
    <string name="max_importance">Importance: Level 5</string>

    <!-- [CHAR LIMIT=100] Notification Importance slider: blocked importance level description -->
    <string name="notification_importance_user_unspecified">App determines importance for each notification.</string>
Loading