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

Commit 303f6160 authored by Julia Tuttle's avatar Julia Tuttle Committed by Android (Google) Code Review
Browse files

Merge "Flexiglass: use Interactor for device public logic in LS user manager" into main

parents e0fa05ba 453f286b
Loading
Loading
Loading
Loading
+73 −2
Original line number Diff line number Diff line
@@ -71,7 +71,11 @@ import androidx.test.filters.SmallTest;
import com.android.internal.widget.LockPatternUtils;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.deviceentry.domain.interactor.DeviceUnlockedInteractor;
import com.android.systemui.deviceentry.shared.model.DeviceUnlockStatus;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.DisableSceneContainer;
import com.android.systemui.flags.EnableSceneContainer;
import com.android.systemui.flags.FakeFeatureFlagsClassic;
import com.android.systemui.log.LogWtfHandlerRule;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
@@ -90,6 +94,10 @@ import com.android.systemui.util.time.FakeSystemClock;

import com.google.android.collect.Lists;

import dagger.Lazy;

import kotlinx.coroutines.flow.StateFlow;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -152,6 +160,12 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
    private BroadcastDispatcher mBroadcastDispatcher;
    @Mock
    private KeyguardStateController mKeyguardStateController;
    @Mock
    private Lazy<DeviceUnlockedInteractor> mDeviceUnlockedInteractorLazy;
    @Mock
    private DeviceUnlockedInteractor mDeviceUnlockedInteractor;
    @Mock
    private StateFlow<DeviceUnlockStatus> mDeviceUnlockStatusStateFlow;

    private UserInfo mCurrentUser;
    private UserInfo mSecondaryUser;
@@ -238,6 +252,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
        mLockscreenUserManager = new TestNotificationLockscreenUserManager(mContext);
        mLockscreenUserManager.setUpWithPresenter(mPresenter);

        when(mDeviceUnlockedInteractor.getDeviceUnlockStatus())
                .thenReturn(mDeviceUnlockStatusStateFlow);

        mBackgroundExecutor.runAllReady();
    }

@@ -493,7 +510,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
    }

    @Test
    public void testUpdateIsPublicMode() {
    @DisableSceneContainer
    public void testUpdateIsPublicMode_sceneContainerDisabled() {
        when(mKeyguardStateController.isMethodSecure()).thenReturn(true);
        when(mKeyguardStateController.isShowing()).thenReturn(false);

@@ -527,6 +545,57 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
        mBackgroundExecutor.runAllReady();
        assertTrue(mLockscreenUserManager.isLockscreenPublicMode(0));
        verify(listener, never()).onNotificationStateChanged();

        verify(mDeviceUnlockedInteractorLazy, never()).get();
    }

    @Test
    @EnableSceneContainer
    public void testUpdateIsPublicMode_sceneContainerEnabled() {
        when(mDeviceUnlockedInteractorLazy.get()).thenReturn(mDeviceUnlockedInteractor);

        // device is unlocked
        when(mDeviceUnlockStatusStateFlow.getValue()).thenReturn(new DeviceUnlockStatus(
                /* isUnlocked = */ true,
                /* deviceUnlockSource = */ null
        ));

        NotificationStateChangedListener listener = mock(NotificationStateChangedListener.class);
        mLockscreenUserManager.addNotificationStateChangedListener(listener);
        mLockscreenUserManager.mCurrentProfiles.append(0, mock(UserInfo.class));

        // first call explicitly sets user 0 to not public; notifies
        mLockscreenUserManager.updatePublicMode();
        mBackgroundExecutor.runAllReady();
        assertFalse(mLockscreenUserManager.isLockscreenPublicMode(0));
        verify(listener).onNotificationStateChanged();
        clearInvocations(listener);

        // calling again has no changes; does not notify
        mLockscreenUserManager.updatePublicMode();
        mBackgroundExecutor.runAllReady();
        assertFalse(mLockscreenUserManager.isLockscreenPublicMode(0));
        verify(listener, never()).onNotificationStateChanged();

        // device is not unlocked
        when(mDeviceUnlockStatusStateFlow.getValue()).thenReturn(new DeviceUnlockStatus(
                /* isUnlocked = */ false,
                /* deviceUnlockSource = */ null
        ));

        // Calling again with device now not unlocked makes user 0 public; notifies
        when(mKeyguardStateController.isShowing()).thenReturn(true);
        mLockscreenUserManager.updatePublicMode();
        mBackgroundExecutor.runAllReady();
        assertTrue(mLockscreenUserManager.isLockscreenPublicMode(0));
        verify(listener).onNotificationStateChanged();
        clearInvocations(listener);

        // calling again has no changes; does not notify
        mLockscreenUserManager.updatePublicMode();
        mBackgroundExecutor.runAllReady();
        assertTrue(mLockscreenUserManager.isLockscreenPublicMode(0));
        verify(listener, never()).onNotificationStateChanged();
    }

    @Test
@@ -972,7 +1041,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
                    mSettings,
                    mock(DumpManager.class),
                    mock(LockPatternUtils.class),
                    mFakeFeatureFlags);
                    mFakeFeatureFlags,
                    mDeviceUnlockedInteractorLazy
            );
        }

        public BroadcastReceiver getBaseBroadcastReceiverForTest() {
+14 −3
Original line number Diff line number Diff line
@@ -62,11 +62,13 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.deviceentry.domain.interactor.DeviceUnlockedInteractor;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FeatureFlagsClassic;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.scene.shared.flag.SceneContainerFlag;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection;
@@ -286,6 +288,8 @@ public class NotificationLockscreenUserManagerImpl implements
    protected ContentObserver mLockscreenSettingsObserver;
    protected ContentObserver mSettingsObserver;

    private final Lazy<DeviceUnlockedInteractor> mDeviceUnlockedInteractorLazy;

    @Inject
    public NotificationLockscreenUserManagerImpl(Context context,
            BroadcastDispatcher broadcastDispatcher,
@@ -305,7 +309,8 @@ public class NotificationLockscreenUserManagerImpl implements
            SecureSettings secureSettings,
            DumpManager dumpManager,
            LockPatternUtils lockPatternUtils,
            FeatureFlagsClassic featureFlags) {
            FeatureFlagsClassic featureFlags,
            Lazy<DeviceUnlockedInteractor> deviceUnlockedInteractorLazy) {
        mContext = context;
        mMainExecutor = mainExecutor;
        mBackgroundExecutor = backgroundExecutor;
@@ -325,6 +330,7 @@ public class NotificationLockscreenUserManagerImpl implements
        mSecureSettings = secureSettings;
        mKeyguardStateController = keyguardStateController;
        mFeatureFlags = featureFlags;
        mDeviceUnlockedInteractorLazy = deviceUnlockedInteractorLazy;

        mLockScreenUris.add(SHOW_LOCKSCREEN);
        mLockScreenUris.add(SHOW_PRIVATE_LOCKSCREEN);
@@ -748,8 +754,13 @@ public class NotificationLockscreenUserManagerImpl implements
        // camera on the keyguard has a state of SHADE but the keyguard is still showing.
        final boolean showingKeyguard = mState != StatusBarState.SHADE
                || mKeyguardStateController.isShowing();
        final boolean devicePublic = showingKeyguard && mKeyguardStateController.isMethodSecure();

        final boolean devicePublic;
        if (SceneContainerFlag.isEnabled()) {
            devicePublic = !mDeviceUnlockedInteractorLazy.get()
                    .getDeviceUnlockStatus().getValue().isUnlocked();
        } else {
            devicePublic = showingKeyguard && mKeyguardStateController.isMethodSecure();
        }

        // Look for public mode users. Users are considered public in either case of:
        //   - device keyguard is shown in secure mode;