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

Commit 5b655c39 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Add setting for silent notifs on lockscreen

Test: atest
Bug: 128445911
Change-Id: If07b593aa0588f494691c7399e471a142fb585c6
parent 0f6db7d1
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -7982,6 +7982,16 @@ public final class Settings {
        public static final String LOCK_SCREEN_SHOW_NOTIFICATIONS =
                "lock_screen_show_notifications";
        /**
         * Indicates whether the lock screen should display silent notifications.
         * <p>
         * Type: int (0 for false, 1 for true)
         *
         * @hide
         */
        public static final String LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS =
                "lock_screen_show_silent_notifications";
        /**
         * List of TV inputs that are currently hidden. This is a string
         * containing the IDs of all hidden TV inputs. Each ID is encoded by
@@ -8838,6 +8848,7 @@ public final class Settings {
            LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
            LOCK_SCREEN_CUSTOM_CLOCK_FACE,
            LOCK_SCREEN_SHOW_NOTIFICATIONS,
            LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS,
            ZEN_DURATION,
            SHOW_ZEN_UPGRADE_NOTIFICATION,
            SHOW_ZEN_SETTINGS_SUGGESTION,
@@ -9013,6 +9024,7 @@ public final class Settings {
            VALIDATORS.put(IN_CALL_NOTIFICATION_ENABLED, IN_CALL_NOTIFICATION_ENABLED_VALIDATOR);
            VALIDATORS.put(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, BOOLEAN_VALIDATOR);
            VALIDATORS.put(LOCK_SCREEN_SHOW_NOTIFICATIONS, BOOLEAN_VALIDATOR);
            VALIDATORS.put(LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, BOOLEAN_VALIDATOR);
            VALIDATORS.put(ZEN_DURATION, ZEN_DURATION_VALIDATOR);
            VALIDATORS.put(SHOW_ZEN_UPGRADE_NOTIFICATION, BOOLEAN_VALIDATOR);
            VALIDATORS.put(SHOW_ZEN_SETTINGS_SUGGESTION, BOOLEAN_VALIDATOR);
+7 −1
Original line number Diff line number Diff line
@@ -306,7 +306,8 @@ public class NotificationLockscreenUserManagerImpl implements
            return false;
        }
        boolean exceedsPriorityThreshold;
        if (NotificationUtils.useNewInterruptionModel(mContext)) {
        if (NotificationUtils.useNewInterruptionModel(mContext)
                && hideSilentNotificationsOnLockscreen()) {
            exceedsPriorityThreshold = getEntryManager().getNotificationData().isHighPriority(sbn);
        } else {
            exceedsPriorityThreshold =
@@ -315,6 +316,11 @@ public class NotificationLockscreenUserManagerImpl implements
        return mShowLockscreenNotifications && exceedsPriorityThreshold;
    }

    private boolean hideSilentNotificationsOnLockscreen() {
        return Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0) == 0;
    }

    private void setShowLockscreenNotifications(boolean show) {
        mShowLockscreenNotifications = show;
    }
+32 −1
Original line number Diff line number Diff line
@@ -17,10 +17,13 @@
package com.android.systemui.statusbar;

import static android.content.Intent.ACTION_USER_SWITCHED;
import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -35,6 +38,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.UserManager;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

@@ -152,7 +156,34 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
        assertTrue(mLockscreenUserManager.isLockscreenPublicMode(mCurrentUserId));
    }

    private class TestNotificationLockscreenUserManager extends NotificationLockscreenUserManagerImpl {
    @Test
    public void testShowSilentNotifications_settingSaysShow() {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
        Settings.Secure.putInt(mContext.getContentResolver(),
                NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
        when(mNotificationData.isHighPriority(any())).thenReturn(false);

        assertTrue(mLockscreenUserManager.shouldShowOnKeyguard(mock(StatusBarNotification.class)));
    }

    @Test
    public void testShowSilentNotifications_settingSaysHide() {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
        Settings.Secure.putInt(mContext.getContentResolver(),
                NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
        when(mNotificationData.isHighPriority(any())).thenReturn(false);

        assertFalse(mLockscreenUserManager.shouldShowOnKeyguard(mock(StatusBarNotification.class)));
    }

    private class TestNotificationLockscreenUserManager
            extends NotificationLockscreenUserManagerImpl {
        public TestNotificationLockscreenUserManager(Context context) {
            super(context);
        }