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

Commit 9e6d9390 authored by Steve Elliott's avatar Steve Elliott Committed by Automerger Merge Worker
Browse files

Merge "Delete unused code from NotifLockscreenUserManager" into tm-qpr-dev am: ddda11f3

parents 5a5a8a5c ddda11f3
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -49,12 +49,6 @@ public interface NotificationLockscreenUserManager {
    /** Adds a listener to be notified when the current user changes. */
    void addUserChangedListener(UserChangedListener listener);

    /**
     * Registers a [KeyguardNotificationSuppressor] that will be consulted during
     * {@link #shouldShowOnKeyguard(NotificationEntry)}
     */
    void addKeyguardNotificationSuppressor(KeyguardNotificationSuppressor suppressor);

    /**
     * Removes a listener previously registered with
     * {@link #addUserChangedListener(UserChangedListener)}
@@ -63,14 +57,8 @@ public interface NotificationLockscreenUserManager {

    SparseArray<UserInfo> getCurrentProfiles();

    void setLockscreenPublicMode(boolean isProfilePublic, int userId);

    boolean shouldShowLockscreenNotifications();

    boolean shouldHideNotifications(int userId);
    boolean shouldHideNotifications(String key);
    boolean shouldShowOnKeyguard(NotificationEntry entry);

    boolean isAnyProfilePublicMode();

    void updatePublicMode();
@@ -108,11 +96,6 @@ public interface NotificationLockscreenUserManager {
        default void onUserRemoved(int userId) {}
    }

    /** Used to hide notifications on the lockscreen */
    interface KeyguardNotificationSuppressor {
        boolean shouldSuppressOnKeyguard(NotificationEntry entry);
    }

    /**
     * Notified when any state pertaining to Notifications has changed; any methods pertaining to
     * notifications should be re-queried.
+4 −73
Original line number Diff line number Diff line
@@ -15,17 +15,13 @@
 */
package com.android.systemui.statusbar;

import static android.app.Notification.VISIBILITY_SECRET;
import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED;

import static com.android.systemui.DejankUtils.whitelistIpcs;
import static com.android.systemui.statusbar.notification.stack.NotificationPriorityBucketKt.BUCKET_MEDIA_CONTROLS;
import static com.android.systemui.statusbar.notification.stack.NotificationPriorityBucketKt.BUCKET_SILENT;

import android.app.ActivityManager;
import android.app.KeyguardManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -42,9 +38,10 @@ import android.util.Log;
import android.util.SparseArray;
import android.util.SparseBooleanArray;

import androidx.annotation.VisibleForTesting;

import com.android.internal.statusbar.NotificationVisibility;
import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.Dependency;
import com.android.systemui.Dumpable;
import com.android.systemui.broadcast.BroadcastDispatcher;
@@ -110,7 +107,6 @@ public class NotificationLockscreenUserManagerImpl implements
    private LockPatternUtils mLockPatternUtils;
    protected KeyguardManager mKeyguardManager;
    private int mState = StatusBarState.SHADE;
    private List<KeyguardNotificationSuppressor> mKeyguardSuppressors = new ArrayList<>();
    private final ListenerSet<NotificationStateChangedListener> mNotifStateChangedListeners =
            new ListenerSet<>();

@@ -344,67 +340,6 @@ public class NotificationLockscreenUserManagerImpl implements
        }
    }

    /**
     * Returns true if notifications are temporarily disabled for this user for security reasons,
     * regardless of the normal settings for that user.
     */
    private boolean shouldTemporarilyHideNotifications(int userId) {
        if (userId == UserHandle.USER_ALL) {
            userId = mCurrentUserId;
        }
        boolean inLockdown = Dependency.get(KeyguardUpdateMonitor.class).isUserInLockdown(userId);
        mUsersInLockdownLatestResult.put(userId, inLockdown);
        return inLockdown;
    }

    /**
     * Returns true if we're on a secure lockscreen and the user wants to hide notification data.
     * If so, notifications should be hidden.
     */
    public boolean shouldHideNotifications(int userId) {
        boolean hide = isLockscreenPublicMode(userId) && !userAllowsNotificationsInPublic(userId)
                || (userId != mCurrentUserId && shouldHideNotifications(mCurrentUserId))
                || shouldTemporarilyHideNotifications(userId);
        mShouldHideNotifsLatestResult.put(userId, hide);
        return hide;
    }

    /**
     * Returns true if we're on a secure lockscreen and the user wants to hide notifications via
     * package-specific override.
     */
    public boolean shouldHideNotifications(String key) {
        if (mCommonNotifCollectionLazy.get() == null) {
            Log.wtf(TAG, "mCommonNotifCollectionLazy was null!", new Throwable());
            return true;
        }
        NotificationEntry visibleEntry = mCommonNotifCollectionLazy.get().getEntry(key);
        return isLockscreenPublicMode(mCurrentUserId) && visibleEntry != null
                && visibleEntry.getRanking().getLockscreenVisibilityOverride() == VISIBILITY_SECRET;
    }

    public boolean shouldShowOnKeyguard(NotificationEntry entry) {
        if (mCommonNotifCollectionLazy.get() == null) {
            Log.wtf(TAG, "mCommonNotifCollectionLazy was null!", new Throwable());
            return false;
        }
        for (int i = 0; i < mKeyguardSuppressors.size(); i++) {
            if (mKeyguardSuppressors.get(i).shouldSuppressOnKeyguard(entry)) {
                return false;
            }
        }
        boolean exceedsPriorityThreshold;
        if (mHideSilentNotificationsOnLockscreen) {
            exceedsPriorityThreshold =
                    entry.getBucket() == BUCKET_MEDIA_CONTROLS
                            || (entry.getBucket() != BUCKET_SILENT
                            && entry.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT);
        } else {
            exceedsPriorityThreshold = !entry.getRanking().isAmbient();
        }
        return mShowLockscreenNotifications && exceedsPriorityThreshold;
    }

    private void setShowLockscreenNotifications(boolean show) {
        mShowLockscreenNotifications = show;
    }
@@ -491,7 +426,8 @@ public class NotificationLockscreenUserManagerImpl implements
    /**
     * Save the current "public" (locked and secure) state of the lockscreen.
     */
    public void setLockscreenPublicMode(boolean publicMode, int userId) {
    @VisibleForTesting
    void setLockscreenPublicMode(boolean publicMode, int userId) {
        mLockscreenPublicMode.put(userId, publicMode);
    }

@@ -673,11 +609,6 @@ public class NotificationLockscreenUserManagerImpl implements
        mListeners.add(listener);
    }

    @Override
    public void addKeyguardNotificationSuppressor(KeyguardNotificationSuppressor suppressor) {
        mKeyguardSuppressors.add(suppressor);
    }

    @Override
    public void removeUserChangedListener(UserChangedListener listener) {
        mListeners.remove(listener);
+0 −108
Original line number Diff line number Diff line
@@ -16,15 +16,8 @@

package com.android.systemui.statusbar;

import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.content.Intent.ACTION_USER_SWITCHED;

import static com.android.systemui.statusbar.notification.stack.NotificationPriorityBucketKt.BUCKET_ALERTING;
import static com.android.systemui.statusbar.notification.stack.NotificationPriorityBucketKt.BUCKET_MEDIA_CONTROLS;
import static com.android.systemui.statusbar.notification.stack.NotificationPriorityBucketKt.BUCKET_PEOPLE;
import static com.android.systemui.statusbar.notification.stack.NotificationPriorityBucketKt.BUCKET_SILENT;

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

@@ -60,7 +53,6 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationLockscreenUserManager.KeyguardNotificationSuppressor;
import com.android.systemui.statusbar.NotificationLockscreenUserManager.NotificationStateChangedListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -359,93 +351,6 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
        verify(listener, never()).onNotificationStateChanged();
    }

    @Test
    public void testShowSilentNotifications_settingSaysShow() {
        mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
        mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
        mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);

        NotificationEntry entry = new NotificationEntryBuilder()
                .setImportance(IMPORTANCE_LOW)
                .build();
        entry.setBucket(BUCKET_SILENT);

        assertTrue(mLockscreenUserManager.shouldShowOnKeyguard(entry));
    }

    @Test
    public void testShowSilentNotifications_settingSaysHide() {
        mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
        mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
        mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);

        final Notification notification = mock(Notification.class);
        when(notification.isForegroundService()).thenReturn(true);
        NotificationEntry entry = new NotificationEntryBuilder()
                .setImportance(IMPORTANCE_LOW)
                .setNotification(notification)
                .build();
        entry.setBucket(BUCKET_SILENT);
        assertFalse(mLockscreenUserManager.shouldShowOnKeyguard(entry));
    }

    @Test
    public void testShowSilentNotificationsPeopleBucket_settingSaysHide() {
        mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
        mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
        mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);

        final Notification notification = mock(Notification.class);
        when(notification.isForegroundService()).thenReturn(true);
        NotificationEntry entry = new NotificationEntryBuilder()
                .setImportance(IMPORTANCE_LOW)
                .setNotification(notification)
                .build();
        entry.setBucket(BUCKET_PEOPLE);
        assertFalse(mLockscreenUserManager.shouldShowOnKeyguard(entry));
    }

    @Test
    public void testShowSilentNotificationsMediaBucket_settingSaysHide() {
        mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
        mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
        mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);

        final Notification notification = mock(Notification.class);
        when(notification.isForegroundService()).thenReturn(true);
        NotificationEntry entry = new NotificationEntryBuilder()
                .setImportance(IMPORTANCE_LOW)
                .setNotification(notification)
                .build();
        entry.setBucket(BUCKET_MEDIA_CONTROLS);
        // always show media controls, even if they're silent
        assertTrue(mLockscreenUserManager.shouldShowOnKeyguard(entry));
    }

    @Test
    public void testKeyguardNotificationSuppressors() {
        // GIVEN a notification that should be shown on the lockscreen
        mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
        mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
        final NotificationEntry entry = new NotificationEntryBuilder()
                .setImportance(IMPORTANCE_HIGH)
                .build();
        entry.setBucket(BUCKET_ALERTING);

        // WHEN a suppressor is added that filters out all entries
        FakeKeyguardSuppressor suppressor = new FakeKeyguardSuppressor();
        mLockscreenUserManager.addKeyguardNotificationSuppressor(suppressor);

        // THEN it's filtered out
        assertFalse(mLockscreenUserManager.shouldShowOnKeyguard(entry));

        // WHEN the suppressor no longer filters out entries
        suppressor.setShouldSuppress(false);

        // THEN it's no longer filtered out
        assertTrue(mLockscreenUserManager.shouldShowOnKeyguard(entry));
    }

    private class TestNotificationLockscreenUserManager
            extends NotificationLockscreenUserManagerImpl {
        public TestNotificationLockscreenUserManager(Context context) {
@@ -478,17 +383,4 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
            return mSettingsObserver;
        }
    }

    private static class FakeKeyguardSuppressor implements KeyguardNotificationSuppressor {
        private boolean mShouldSuppress = true;

        @Override
        public boolean shouldSuppressOnKeyguard(NotificationEntry entry) {
            return mShouldSuppress;
        }

        public void setShouldSuppress(boolean shouldSuppress) {
            mShouldSuppress = shouldSuppress;
        }
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.notification;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
@@ -128,8 +127,6 @@ public class DynamicPrivacyControllerTest extends SysuiTestCase {
    @Test
    public void testNotNotifiedWithoutNotifications() {
        when(mKeyguardStateController.canDismissLockScreen()).thenReturn(true);
        when(mLockScreenUserManager.shouldHideNotifications(anyInt())).thenReturn(
                true);
        mDynamicPrivacyController.onUnlockedChanged();
        verifyNoMoreInteractions(mListener);
    }