diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java index 74ca64f5cc..7d2997ecb8 100644 --- a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java +++ b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java @@ -17,7 +17,6 @@ package com.android.quickstep; import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; -import static android.content.Intent.ACTION_USER_UNLOCKED; import static android.view.Display.DEFAULT_DISPLAY; import static com.android.launcher3.util.DisplayController.CHANGE_ALL; @@ -52,10 +51,8 @@ import android.content.Context; import android.graphics.Region; import android.inputmethodservice.InputMethodService; import android.net.Uri; -import android.os.Process; import android.os.RemoteException; import android.os.SystemProperties; -import android.os.UserManager; import android.provider.Settings; import android.view.MotionEvent; import android.view.ViewConfiguration; @@ -68,7 +65,6 @@ import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener; import com.android.launcher3.util.DisplayController.Info; import com.android.launcher3.util.NavigationMode; import com.android.launcher3.util.SettingsCache; -import com.android.launcher3.util.SimpleBroadcastReceiver; import com.android.quickstep.TopTaskTracker.CachedTaskInfo; import com.android.quickstep.util.NavBarPosition; import com.android.systemui.shared.system.ActivityManagerWrapper; @@ -116,15 +112,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener { private final boolean mIsOneHandedModeSupported; private boolean mPipIsActive; - private boolean mIsUserUnlocked; - private final ArrayList mUserUnlockedActions = new ArrayList<>(); - private final SimpleBroadcastReceiver mUserUnlockedReceiver = new SimpleBroadcastReceiver(i -> { - if (ACTION_USER_UNLOCKED.equals(i.getAction())) { - mIsUserUnlocked = true; - notifyUserUnlocked(); - } - }); - private int mGestureBlockingTaskId = -1; private @NonNull Region mExclusionRegion = new Region(); private SystemGestureExclusionListenerCompat mExclusionListener; @@ -150,14 +137,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener { runOnDestroy(mRotationTouchHelper::destroy); } - // Register for user unlocked if necessary - mIsUserUnlocked = context.getSystemService(UserManager.class) - .isUserUnlocked(Process.myUserHandle()); - if (!mIsUserUnlocked) { - mUserUnlockedReceiver.register(mContext, ACTION_USER_UNLOCKED); - } - runOnDestroy(() -> mUserUnlockedReceiver.unregisterReceiverSafely(mContext)); - // Register for exclusion updates mExclusionListener = new SystemGestureExclusionListenerCompat(mDisplayId) { @Override @@ -316,25 +295,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener { return mDisplayId; } - /** - * Adds a callback for when a user is unlocked. If the user is already unlocked, this listener - * will be called back immediately. - */ - public void runOnUserUnlocked(Runnable action) { - if (mIsUserUnlocked) { - action.run(); - } else { - mUserUnlockedActions.add(action); - } - } - - /** - * @return whether the user is unlocked. - */ - public boolean isUserUnlocked() { - return mIsUserUnlocked; - } - /** * @return whether the user has completed setup wizard */ @@ -342,14 +302,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener { return mIsUserSetupComplete; } - private void notifyUserUnlocked() { - for (Runnable action : mUserUnlockedActions) { - action.run(); - } - mUserUnlockedActions.clear(); - mUserUnlockedReceiver.unregisterReceiverSafely(mContext); - } - /** * Sets the task id where gestures should be blocked */ @@ -607,7 +559,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener { pw.println(" assistantAvailable=" + mAssistantAvailable); pw.println(" assistantDisabled=" + QuickStepContract.isAssistantGestureDisabled(mSystemUiStateFlags)); - pw.println(" isUserUnlocked=" + mIsUserUnlocked); pw.println(" isOneHandedModeEnabled=" + mIsOneHandedModeEnabled); pw.println(" isSwipeToNotificationEnabled=" + mIsSwipeToNotificationEnabled); pw.println(" deferredGestureRegion=" + mDeferredGestureRegion.getBounds()); diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 4ed68aaf53..8d05fa9003 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -100,6 +100,7 @@ import com.android.launcher3.tracing.TouchInteractionServiceProto; import com.android.launcher3.uioverrides.flags.FlagsFactory; import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; import com.android.launcher3.util.DisplayController; +import com.android.launcher3.util.LockedUserState; import com.android.launcher3.util.OnboardingPrefs; import com.android.launcher3.util.TraceHelper; import com.android.quickstep.inputconsumers.AccessibilityInputConsumer; @@ -113,9 +114,9 @@ import com.android.quickstep.inputconsumers.OverviewWithoutFocusInputConsumer; import com.android.quickstep.inputconsumers.ProgressDelegateInputConsumer; import com.android.quickstep.inputconsumers.ResetGestureInputConsumer; import com.android.quickstep.inputconsumers.ScreenPinnedInputConsumer; -import com.android.quickstep.inputconsumers.TrackpadStatusBarInputConsumer; import com.android.quickstep.inputconsumers.SysUiOverlayInputConsumer; import com.android.quickstep.inputconsumers.TaskbarUnstashInputConsumer; +import com.android.quickstep.inputconsumers.TrackpadStatusBarInputConsumer; import com.android.quickstep.util.ActiveGestureLog; import com.android.quickstep.util.ActiveGestureLog.CompoundString; import com.android.quickstep.util.ProtoTracer; @@ -445,8 +446,8 @@ public class TouchInteractionService extends Service BootAwarePreloader.start(this); // Call runOnUserUnlocked() before any other callbacks to ensure everything is initialized. - mDeviceState.runOnUserUnlocked(this::onUserUnlocked); - mDeviceState.runOnUserUnlocked(mTaskbarManager::onUserUnlocked); + LockedUserState.get(this).runOnUserUnlocked(this::onUserUnlocked); + LockedUserState.get(this).runOnUserUnlocked(mTaskbarManager::onUserUnlocked); mDeviceState.addNavigationModeChangedCallback(this::onNavigationModeChanged); ProtoTracer.INSTANCE.get(this).add(this); @@ -516,7 +517,7 @@ public class TouchInteractionService extends Service } private void resetHomeBounceSeenOnQuickstepEnabledFirstTime() { - if (!mDeviceState.isUserUnlocked() || mDeviceState.isButtonNavMode()) { + if (!LockedUserState.get(this).isUserUnlocked() || mDeviceState.isButtonNavMode()) { // Skip if not yet unlocked (can't read user shared prefs) or if the current navigation // mode doesn't have gestures return; @@ -559,7 +560,7 @@ public class TouchInteractionService extends Service @UiThread private void onSystemUiFlagsChanged(int lastSysUIFlags) { - if (mDeviceState.isUserUnlocked()) { + if (LockedUserState.get(this).isUserUnlocked()) { int systemUiStateFlags = mDeviceState.getSystemUiStateFlags(); SystemUiProxy.INSTANCE.get(this).setLastSystemUiStateFlags(systemUiStateFlags); mOverviewComponentObserver.onSystemUiStateChanged(); @@ -604,7 +605,7 @@ public class TouchInteractionService extends Service @UiThread private void onAssistantVisibilityChanged() { - if (mDeviceState.isUserUnlocked()) { + if (LockedUserState.get(this).isUserUnlocked()) { mOverviewComponentObserver.getActivityInterface().onAssistantVisibilityChanged( mDeviceState.getAssistantVisibility()); } @@ -614,7 +615,7 @@ public class TouchInteractionService extends Service public void onDestroy() { Log.d(TAG, "Touch service destroyed: user=" + getUserId()); sIsInitialized = false; - if (mDeviceState.isUserUnlocked()) { + if (LockedUserState.get(this).isUserUnlocked()) { mInputConsumer.unregisterInputConsumer(); mOverviewComponentObserver.onDestroy(); } @@ -648,7 +649,7 @@ public class TouchInteractionService extends Service TestLogging.recordMotionEvent( TestProtocol.SEQUENCE_TIS, "TouchInteractionService.onInputEvent", event); - if (!mDeviceState.isUserUnlocked() || (mDeviceState.isButtonNavMode() + if (!LockedUserState.get(this).isUserUnlocked() || (mDeviceState.isButtonNavMode() && !isTrackpadMotionEvent(event))) { return; } @@ -677,7 +678,7 @@ public class TouchInteractionService extends Service mGestureState = newGestureState; mConsumer = newConsumer(prevGestureState, mGestureState, event); mUncheckedConsumer = mConsumer; - } else if (mDeviceState.isUserUnlocked() + } else if (LockedUserState.get(this).isUserUnlocked() && (mDeviceState.isFullyGesturalNavMode() || isTrackpadMultiFingerSwipe(event)) && mDeviceState.canTriggerAssistantAction(event)) { mGestureState = createGestureState(mGestureState, @@ -819,7 +820,7 @@ public class TouchInteractionService extends Service boolean canStartSystemGesture = mDeviceState.canStartSystemGesture(); - if (!mDeviceState.isUserUnlocked()) { + if (!LockedUserState.get(this).isUserUnlocked()) { CompoundString reasonString = newCompoundString("device locked"); InputConsumer consumer; if (canStartSystemGesture) { @@ -1178,7 +1179,7 @@ public class TouchInteractionService extends Service } private void preloadOverview(boolean fromInit, boolean forSUWAllSet) { - if (!mDeviceState.isUserUnlocked()) { + if (!LockedUserState.get(this).isUserUnlocked()) { return; } @@ -1214,7 +1215,7 @@ public class TouchInteractionService extends Service @Override public void onConfigurationChanged(Configuration newConfig) { - if (!mDeviceState.isUserUnlocked()) { + if (!LockedUserState.get(this).isUserUnlocked()) { return; } final BaseActivityInterface activityInterface = @@ -1255,7 +1256,7 @@ public class TouchInteractionService extends Service } else { // Dump everything FlagsFactory.dump(pw); - if (mDeviceState.isUserUnlocked()) { + if (LockedUserState.get(this).isUserUnlocked()) { PluginManagerWrapper.INSTANCE.get(getBaseContext()).dump(pw); } mDeviceState.dump(pw); diff --git a/src/com/android/launcher3/util/LockedUserState.kt b/src/com/android/launcher3/util/LockedUserState.kt index 1231604780..0a87594fde 100644 --- a/src/com/android/launcher3/util/LockedUserState.kt +++ b/src/com/android/launcher3/util/LockedUserState.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.android.launcher3.util import android.content.Context diff --git a/tests/src/com/android/launcher3/util/LockedUserStateTest.kt b/tests/src/com/android/launcher3/util/LockedUserStateTest.kt index 84156e7101..92ab2cb90b 100644 --- a/tests/src/com/android/launcher3/util/LockedUserStateTest.kt +++ b/tests/src/com/android/launcher3/util/LockedUserStateTest.kt @@ -32,7 +32,7 @@ import org.mockito.Mockito.verifyZeroInteractions import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations -/** Unit tests for {@link LockedUserUtil} */ +/** Unit tests for {@link LockedUserState} */ @SmallTest @RunWith(AndroidJUnit4::class) class LockedUserStateTest { @@ -49,40 +49,31 @@ class LockedUserStateTest { @Test fun runOnUserUnlocked_runs_action_immediately_if_already_unlocked() { `when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(true) - LockedUserState.INSTANCE.initializeForTesting(LockedUserState(context)) val action: Runnable = mock() - - LockedUserState.get(context).runOnUserUnlocked(action) + LockedUserState(context).runOnUserUnlocked(action) verify(action).run() } @Test fun runOnUserUnlocked_waits_to_run_action_until_user_is_unlocked() { `when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(false) - LockedUserState.INSTANCE.initializeForTesting(LockedUserState(context)) val action: Runnable = mock() - - LockedUserState.get(context).runOnUserUnlocked(action) + val state = LockedUserState(context) + state.runOnUserUnlocked(action) verifyZeroInteractions(action) - - LockedUserState.get(context) - .mUserUnlockedReceiver - .onReceive(context, Intent(Intent.ACTION_USER_UNLOCKED)) - + state.mUserUnlockedReceiver.onReceive(context, Intent(Intent.ACTION_USER_UNLOCKED)) verify(action).run() } @Test fun isUserUnlocked_returns_true_when_user_is_unlocked() { `when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(true) - LockedUserState.INSTANCE.initializeForTesting(LockedUserState(context)) - assertThat(LockedUserState.get(context).isUserUnlocked).isTrue() + assertThat(LockedUserState(context).isUserUnlocked).isTrue() } @Test fun isUserUnlocked_returns_false_when_user_is_locked() { `when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(false) - LockedUserState.INSTANCE.initializeForTesting(LockedUserState(context)) - assertThat(LockedUserState.get(context).isUserUnlocked).isFalse() + assertThat(LockedUserState(context).isUserUnlocked).isFalse() } }