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

Commit 237c6dea authored by Lars Greiss's avatar Lars Greiss Committed by d34d
Browse files

Settings: Add per app controls for LP keyguard notifications (2/2)

Nice done by google but the UX is a problem especially for ppl who are using a lot apps and just want
to see from important apps the notifications on the lockscreen.

This commit adds the ability to

- enable/disable per app the keyguard notification at all
- enable/disable per app ongoing notifications on the keyguard

We handle this over the app policy conf file like the other per app notification options

TICKET: CRACKLING-1127
Change-Id: I12df484379621c3baba333d30a8b545b3a0ec0ae
parent b2b14fdf
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1213,4 +1213,10 @@
    <string name="restrict_cellular_access_dialog_title">Restrict cellular data access?</string>
    <string name="restrict_cellular_access_dialog_summary">This feature may cause an app that depends on network access to stop working when only cellular networks are available.\n\nYou can find more appropriate data usage controls in the settings available within the app.</string>

    <!-- Per app controls for LP keyguard notifications -->
    <string name="app_notification_show_on_keyguard_title">Show on lockscreen</string>
    <string name="app_notification_show_on_keyguard_summary">Show notifications from this app on the lockscreen</string>
    <string name="app_notification_no_ongoing_on_keyguard_title">Disable persistent notification on lockscreen</string>
    <string name="app_notification_no_ongoing_on_keyguard_summary">Never show persistent notifications from this app on the lockscreen</string>

</resources>
+17 −1
Original line number Diff line number Diff line
@@ -50,11 +50,27 @@
            android:order="4"
            android:persistent="false" />

    <!-- Keyguard options -->
    <SwitchPreference
            android:key="show_on_keyguard"
            android:title="@string/app_notification_show_on_keyguard_title"
            android:summary="@string/app_notification_show_on_keyguard_summary"
            android:order="5"
            android:persistent="false" />

    <SwitchPreference
            android:key="no_ongoing_on_keyguard"
            android:title="@string/app_notification_no_ongoing_on_keyguard_title"
            android:summary="@string/app_notification_no_ongoing_on_keyguard_summary"
            android:order="6"
            android:dependency="show_on_keyguard"
            android:persistent="false" />

    <!-- App notification preferences -->
    <Preference
            android:key="app_settings"
            android:title="@string/app_notification_preferences"
            android:order="5"
            android:order="7"
            android:persistent="false" />

</PreferenceScreen>
+49 −0
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
    private static final String KEY_PEEKABLE = "peekable";
    private static final String KEY_SENSITIVE = "sensitive";
    private static final String KEY_APP_SETTINGS = "app_settings";
    private static final String KEY_SHOW_ON_KEYGUARD = "show_on_keyguard";
    private static final String KEY_NO_ONGOING_ON_KEYGUARD = "no_ongoing_on_keyguard";

    private static final Intent APP_NOTIFICATION_PREFS_CATEGORY_INTENT
            = new Intent(Intent.ACTION_MAIN)
@@ -71,6 +73,8 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
    private SwitchPreference mPriority;
    private SwitchPreference mPeekable;
    private SwitchPreference mSensitive;
    private SwitchPreference mShowOnKeyguard;
    private SwitchPreference mShowNoOngoingOnKeyguard;
    private AppRow mAppRow;
    private boolean mCreated;
    private boolean mIsSystemPackage;
@@ -137,6 +141,8 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
        mPriority = (SwitchPreference) findPreference(KEY_PRIORITY);
        mPeekable = (SwitchPreference) findPreference(KEY_PEEKABLE);
        mSensitive = (SwitchPreference) findPreference(KEY_SENSITIVE);
        mShowOnKeyguard = (SwitchPreference) findPreference(KEY_SHOW_ON_KEYGUARD);
        mShowNoOngoingOnKeyguard = (SwitchPreference) findPreference(KEY_NO_ONGOING_ON_KEYGUARD);

        mAppRow = mBackend.loadAppRow(pm, info.applicationInfo);

@@ -202,6 +208,47 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
        } else {
            removePreference(KEY_APP_SETTINGS);
        }

        int keyguard = mBackend.getShowNotificationForPackageOnKeyguard(pkg, mUid);
        mShowOnKeyguard.setChecked((keyguard & Notification.SHOW_ALL_NOTI_ON_KEYGUARD) != 0);
        mShowNoOngoingOnKeyguard.setChecked(
                (keyguard & Notification.SHOW_NO_ONGOING_NOTI_ON_KEYGUARD) != 0);

        mShowOnKeyguard.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final boolean showOnKeyguard = (Boolean) newValue;
                int keyguard = mBackend.getShowNotificationForPackageOnKeyguard(pkg, mUid);

                if (showOnKeyguard && (keyguard & Notification.SHOW_ALL_NOTI_ON_KEYGUARD) == 0) {
                    keyguard |= Notification.SHOW_ALL_NOTI_ON_KEYGUARD;
                } else {
                    keyguard &= ~Notification.SHOW_ALL_NOTI_ON_KEYGUARD;
                }
                return mBackend.setShowNotificationForPackageOnKeyguard(pkg, mUid, keyguard);
            }
        });

        mShowNoOngoingOnKeyguard.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final boolean showNoOngoingOnKeyguard = (Boolean) newValue;
                int keyguard = mBackend.getShowNotificationForPackageOnKeyguard(pkg, mUid);
                if (showNoOngoingOnKeyguard
                        && (keyguard & Notification.SHOW_NO_ONGOING_NOTI_ON_KEYGUARD) == 0) {
                    keyguard |= Notification.SHOW_NO_ONGOING_NOTI_ON_KEYGUARD;
                } else {
                    keyguard &= ~Notification.SHOW_NO_ONGOING_NOTI_ON_KEYGUARD;
                }
                return mBackend.setShowNotificationForPackageOnKeyguard(pkg, mUid, keyguard);
            }
        });

        // Users cannot block notifications from system/signature packages
        if (mIsSystemPackage || !getLockscreenNotificationsEnabled()) {
            getPreferenceScreen().removePreference(mShowNoOngoingOnKeyguard);
            getPreferenceScreen().removePreference(mShowOnKeyguard);
        }
    }

    @Override
@@ -226,6 +273,8 @@ public class AppNotificationSettings extends SettingsPreferenceFragment {
        setVisible(mPeekable, mIsSystemPackage || !banned && headsUpEnabled);
        setVisible(mSensitive, mIsSystemPackage || !banned && lockscreenSecure
                && lockscreenNotificationsEnabled && allowPrivate);
        setVisible(mShowOnKeyguard, mIsSystemPackage || !banned);
        setVisible(mShowNoOngoingOnKeyguard, mIsSystemPackage || !banned);
    }

    private void setVisible(Preference p, boolean visible) {
+19 −0
Original line number Diff line number Diff line
@@ -130,6 +130,25 @@ public class NotificationBackend {
        }
    }

    public int getShowNotificationForPackageOnKeyguard(String pkg, int uid) {
        try {
            return sINM.getShowNotificationForPackageOnKeyguard(pkg, uid);
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
            return Notification.SHOW_ALL_NOTI_ON_KEYGUARD;
        }
    }

    public boolean setShowNotificationForPackageOnKeyguard(String pkg, int uid, int status) {
        try {
            sINM.setShowNotificationForPackageOnKeyguard(pkg, uid, status);
            return true;
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
            return false;
        }
    }

    static class Row {
        public String section;
    }