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

Commit dd49bba6 authored by Yasin Kilicdere's avatar Yasin Kilicdere
Browse files

Load the notifications of the target user before unfreezing the screen

This CL moves NotificationLockscreenUserManagerImpl from onUserChanged
to onUserChanging, in order to hide the previous user's notifications
and load the target user's notifications before the user switch is
complete.

Flag: LOAD_NOTIFICATIONS_BEFORE_THE_USER_SWITCH_IS_COMPLETE
Bug: 275042474
Test: atest NotificationLockscreenUserManagerTest
Change-Id: I2e8498668ee34c726abe21aef7bade5f3222508b
parent 03cfdfb8
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar;

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

import static com.android.systemui.DejankUtils.whitelistIpcs;

import android.app.KeyguardManager;
@@ -47,6 +48,8 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.recents.OverviewProxyService;
@@ -59,14 +62,14 @@ import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.ListenerSet;
import com.android.systemui.util.settings.SecureSettings;

import dagger.Lazy;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import dagger.Lazy;

/**
 * Handles keeping track of the current user, profiles, and various things related to hiding
 * contents, redacting notifications, and the lockscreen.
@@ -99,7 +102,7 @@ public class NotificationLockscreenUserManagerImpl implements
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final NotificationClickNotifier mClickNotifier;
    private final Lazy<OverviewProxyService> mOverviewProxyServiceLazy;

    private final FeatureFlags mFeatureFlags;
    private boolean mShowLockscreenNotifications;
    private boolean mAllowLockscreenRemoteInput;
    private LockPatternUtils mLockPatternUtils;
@@ -174,6 +177,21 @@ public class NotificationLockscreenUserManagerImpl implements
            new UserTracker.Callback() {
                @Override
                public void onUserChanged(int newUser, @NonNull Context userContext) {
                    if (!mFeatureFlags.isEnabled(
                            Flags.LOAD_NOTIFICATIONS_BEFORE_THE_USER_SWITCH_IS_COMPLETE)) {
                        handleUserChange(newUser);
                    }
                }

                @Override
                public void onUserChanging(int newUser, @NonNull Context userContext) {
                    if (mFeatureFlags.isEnabled(
                            Flags.LOAD_NOTIFICATIONS_BEFORE_THE_USER_SWITCH_IS_COMPLETE)) {
                        handleUserChange(newUser);
                    }
                }

                private void handleUserChange(int newUser) {
                    mCurrentUserId = newUser;
                    updateCurrentProfilesCache();

@@ -216,7 +234,8 @@ public class NotificationLockscreenUserManagerImpl implements
            KeyguardStateController keyguardStateController,
            SecureSettings secureSettings,
            DumpManager dumpManager,
            LockPatternUtils lockPatternUtils) {
            LockPatternUtils lockPatternUtils,
            FeatureFlags featureFlags) {
        mContext = context;
        mMainHandler = mainHandler;
        mDevicePolicyManager = devicePolicyManager;
@@ -234,6 +253,7 @@ public class NotificationLockscreenUserManagerImpl implements
        mDeviceProvisionedController = deviceProvisionedController;
        mSecureSettings = secureSettings;
        mKeyguardStateController = keyguardStateController;
        mFeatureFlags = featureFlags;

        dumpManager.registerDumpable(this);
    }
+14 −1
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ import com.android.systemui.Dependency;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FakeFeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.settings.UserTracker;
@@ -110,6 +112,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
    private NotificationEntry mCurrentUserNotif;
    private NotificationEntry mSecondaryUserNotif;
    private NotificationEntry mWorkProfileNotif;
    private final FakeFeatureFlags mFakeFeatureFlags = new FakeFeatureFlags();

    @Before
    public void setUp() {
@@ -290,8 +293,17 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
        assertTrue(mLockscreenUserManager.needsRedaction(mSecondaryUserNotif));
    }

    @Test
    public void testUserSwitchedCallsOnUserSwitching() {
        mFakeFeatureFlags.set(Flags.LOAD_NOTIFICATIONS_BEFORE_THE_USER_SWITCH_IS_COMPLETE, true);
        mLockscreenUserManager.getUserTrackerCallbackForTest().onUserChanging(mSecondaryUser.id,
                mContext);
        verify(mPresenter, times(1)).onUserSwitched(mSecondaryUser.id);
    }

    @Test
    public void testUserSwitchedCallsOnUserSwitched() {
        mFakeFeatureFlags.set(Flags.LOAD_NOTIFICATIONS_BEFORE_THE_USER_SWITCH_IS_COMPLETE, false);
        mLockscreenUserManager.getUserTrackerCallbackForTest().onUserChanged(mSecondaryUser.id,
                mContext);
        verify(mPresenter, times(1)).onUserSwitched(mSecondaryUser.id);
@@ -356,7 +368,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
                    mKeyguardStateController,
                    mSettings,
                    mock(DumpManager.class),
                    mock(LockPatternUtils.class));
                    mock(LockPatternUtils.class),
                    mFakeFeatureFlags);
        }

        public BroadcastReceiver getBaseBroadcastReceiverForTest() {