Merge "Use LockedUserState in TouchInteractionService." into udc-qpr-dev am: 4439bec7aa

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/23450434

Change-Id: Iea7c15a5372a6403c5172b4b3f870d48c9157cc1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Stefan Andonian
2023-05-30 19:53:53 +00:00
committed by Automerger Merge Worker
4 changed files with 36 additions and 78 deletions
@@ -17,7 +17,6 @@ package com.android.quickstep;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; 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 android.view.Display.DEFAULT_DISPLAY;
import static com.android.launcher3.util.DisplayController.CHANGE_ALL; import static com.android.launcher3.util.DisplayController.CHANGE_ALL;
@@ -52,10 +51,8 @@ import android.content.Context;
import android.graphics.Region; import android.graphics.Region;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
import android.net.Uri; import android.net.Uri;
import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.ViewConfiguration; 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.DisplayController.Info;
import com.android.launcher3.util.NavigationMode; import com.android.launcher3.util.NavigationMode;
import com.android.launcher3.util.SettingsCache; import com.android.launcher3.util.SettingsCache;
import com.android.launcher3.util.SimpleBroadcastReceiver;
import com.android.quickstep.TopTaskTracker.CachedTaskInfo; import com.android.quickstep.TopTaskTracker.CachedTaskInfo;
import com.android.quickstep.util.NavBarPosition; import com.android.quickstep.util.NavBarPosition;
import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.ActivityManagerWrapper;
@@ -116,15 +112,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener {
private final boolean mIsOneHandedModeSupported; private final boolean mIsOneHandedModeSupported;
private boolean mPipIsActive; private boolean mPipIsActive;
private boolean mIsUserUnlocked;
private final ArrayList<Runnable> 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 int mGestureBlockingTaskId = -1;
private @NonNull Region mExclusionRegion = new Region(); private @NonNull Region mExclusionRegion = new Region();
private SystemGestureExclusionListenerCompat mExclusionListener; private SystemGestureExclusionListenerCompat mExclusionListener;
@@ -150,14 +137,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener {
runOnDestroy(mRotationTouchHelper::destroy); 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 // Register for exclusion updates
mExclusionListener = new SystemGestureExclusionListenerCompat(mDisplayId) { mExclusionListener = new SystemGestureExclusionListenerCompat(mDisplayId) {
@Override @Override
@@ -316,25 +295,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener {
return mDisplayId; 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 * @return whether the user has completed setup wizard
*/ */
@@ -342,14 +302,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener {
return mIsUserSetupComplete; 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 * Sets the task id where gestures should be blocked
*/ */
@@ -607,7 +559,6 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener {
pw.println(" assistantAvailable=" + mAssistantAvailable); pw.println(" assistantAvailable=" + mAssistantAvailable);
pw.println(" assistantDisabled=" pw.println(" assistantDisabled="
+ QuickStepContract.isAssistantGestureDisabled(mSystemUiStateFlags)); + QuickStepContract.isAssistantGestureDisabled(mSystemUiStateFlags));
pw.println(" isUserUnlocked=" + mIsUserUnlocked);
pw.println(" isOneHandedModeEnabled=" + mIsOneHandedModeEnabled); pw.println(" isOneHandedModeEnabled=" + mIsOneHandedModeEnabled);
pw.println(" isSwipeToNotificationEnabled=" + mIsSwipeToNotificationEnabled); pw.println(" isSwipeToNotificationEnabled=" + mIsSwipeToNotificationEnabled);
pw.println(" deferredGestureRegion=" + mDeferredGestureRegion.getBounds()); pw.println(" deferredGestureRegion=" + mDeferredGestureRegion.getBounds());
@@ -100,6 +100,7 @@ import com.android.launcher3.tracing.TouchInteractionServiceProto;
import com.android.launcher3.uioverrides.flags.FlagsFactory; import com.android.launcher3.uioverrides.flags.FlagsFactory;
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.LockedUserState;
import com.android.launcher3.util.OnboardingPrefs; import com.android.launcher3.util.OnboardingPrefs;
import com.android.launcher3.util.TraceHelper; import com.android.launcher3.util.TraceHelper;
import com.android.quickstep.inputconsumers.AccessibilityInputConsumer; 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.ProgressDelegateInputConsumer;
import com.android.quickstep.inputconsumers.ResetGestureInputConsumer; import com.android.quickstep.inputconsumers.ResetGestureInputConsumer;
import com.android.quickstep.inputconsumers.ScreenPinnedInputConsumer; import com.android.quickstep.inputconsumers.ScreenPinnedInputConsumer;
import com.android.quickstep.inputconsumers.TrackpadStatusBarInputConsumer;
import com.android.quickstep.inputconsumers.SysUiOverlayInputConsumer; import com.android.quickstep.inputconsumers.SysUiOverlayInputConsumer;
import com.android.quickstep.inputconsumers.TaskbarUnstashInputConsumer; import com.android.quickstep.inputconsumers.TaskbarUnstashInputConsumer;
import com.android.quickstep.inputconsumers.TrackpadStatusBarInputConsumer;
import com.android.quickstep.util.ActiveGestureLog; import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.ActiveGestureLog.CompoundString; import com.android.quickstep.util.ActiveGestureLog.CompoundString;
import com.android.quickstep.util.ProtoTracer; import com.android.quickstep.util.ProtoTracer;
@@ -445,8 +446,8 @@ public class TouchInteractionService extends Service
BootAwarePreloader.start(this); BootAwarePreloader.start(this);
// Call runOnUserUnlocked() before any other callbacks to ensure everything is initialized. // Call runOnUserUnlocked() before any other callbacks to ensure everything is initialized.
mDeviceState.runOnUserUnlocked(this::onUserUnlocked); LockedUserState.get(this).runOnUserUnlocked(this::onUserUnlocked);
mDeviceState.runOnUserUnlocked(mTaskbarManager::onUserUnlocked); LockedUserState.get(this).runOnUserUnlocked(mTaskbarManager::onUserUnlocked);
mDeviceState.addNavigationModeChangedCallback(this::onNavigationModeChanged); mDeviceState.addNavigationModeChangedCallback(this::onNavigationModeChanged);
ProtoTracer.INSTANCE.get(this).add(this); ProtoTracer.INSTANCE.get(this).add(this);
@@ -516,7 +517,7 @@ public class TouchInteractionService extends Service
} }
private void resetHomeBounceSeenOnQuickstepEnabledFirstTime() { 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 // Skip if not yet unlocked (can't read user shared prefs) or if the current navigation
// mode doesn't have gestures // mode doesn't have gestures
return; return;
@@ -559,7 +560,7 @@ public class TouchInteractionService extends Service
@UiThread @UiThread
private void onSystemUiFlagsChanged(int lastSysUIFlags) { private void onSystemUiFlagsChanged(int lastSysUIFlags) {
if (mDeviceState.isUserUnlocked()) { if (LockedUserState.get(this).isUserUnlocked()) {
int systemUiStateFlags = mDeviceState.getSystemUiStateFlags(); int systemUiStateFlags = mDeviceState.getSystemUiStateFlags();
SystemUiProxy.INSTANCE.get(this).setLastSystemUiStateFlags(systemUiStateFlags); SystemUiProxy.INSTANCE.get(this).setLastSystemUiStateFlags(systemUiStateFlags);
mOverviewComponentObserver.onSystemUiStateChanged(); mOverviewComponentObserver.onSystemUiStateChanged();
@@ -604,7 +605,7 @@ public class TouchInteractionService extends Service
@UiThread @UiThread
private void onAssistantVisibilityChanged() { private void onAssistantVisibilityChanged() {
if (mDeviceState.isUserUnlocked()) { if (LockedUserState.get(this).isUserUnlocked()) {
mOverviewComponentObserver.getActivityInterface().onAssistantVisibilityChanged( mOverviewComponentObserver.getActivityInterface().onAssistantVisibilityChanged(
mDeviceState.getAssistantVisibility()); mDeviceState.getAssistantVisibility());
} }
@@ -614,7 +615,7 @@ public class TouchInteractionService extends Service
public void onDestroy() { public void onDestroy() {
Log.d(TAG, "Touch service destroyed: user=" + getUserId()); Log.d(TAG, "Touch service destroyed: user=" + getUserId());
sIsInitialized = false; sIsInitialized = false;
if (mDeviceState.isUserUnlocked()) { if (LockedUserState.get(this).isUserUnlocked()) {
mInputConsumer.unregisterInputConsumer(); mInputConsumer.unregisterInputConsumer();
mOverviewComponentObserver.onDestroy(); mOverviewComponentObserver.onDestroy();
} }
@@ -648,7 +649,7 @@ public class TouchInteractionService extends Service
TestLogging.recordMotionEvent( TestLogging.recordMotionEvent(
TestProtocol.SEQUENCE_TIS, "TouchInteractionService.onInputEvent", event); TestProtocol.SEQUENCE_TIS, "TouchInteractionService.onInputEvent", event);
if (!mDeviceState.isUserUnlocked() || (mDeviceState.isButtonNavMode() if (!LockedUserState.get(this).isUserUnlocked() || (mDeviceState.isButtonNavMode()
&& !isTrackpadMotionEvent(event))) { && !isTrackpadMotionEvent(event))) {
return; return;
} }
@@ -677,7 +678,7 @@ public class TouchInteractionService extends Service
mGestureState = newGestureState; mGestureState = newGestureState;
mConsumer = newConsumer(prevGestureState, mGestureState, event); mConsumer = newConsumer(prevGestureState, mGestureState, event);
mUncheckedConsumer = mConsumer; mUncheckedConsumer = mConsumer;
} else if (mDeviceState.isUserUnlocked() } else if (LockedUserState.get(this).isUserUnlocked()
&& (mDeviceState.isFullyGesturalNavMode() || isTrackpadMultiFingerSwipe(event)) && (mDeviceState.isFullyGesturalNavMode() || isTrackpadMultiFingerSwipe(event))
&& mDeviceState.canTriggerAssistantAction(event)) { && mDeviceState.canTriggerAssistantAction(event)) {
mGestureState = createGestureState(mGestureState, mGestureState = createGestureState(mGestureState,
@@ -819,7 +820,7 @@ public class TouchInteractionService extends Service
boolean canStartSystemGesture = mDeviceState.canStartSystemGesture(); boolean canStartSystemGesture = mDeviceState.canStartSystemGesture();
if (!mDeviceState.isUserUnlocked()) { if (!LockedUserState.get(this).isUserUnlocked()) {
CompoundString reasonString = newCompoundString("device locked"); CompoundString reasonString = newCompoundString("device locked");
InputConsumer consumer; InputConsumer consumer;
if (canStartSystemGesture) { if (canStartSystemGesture) {
@@ -1178,7 +1179,7 @@ public class TouchInteractionService extends Service
} }
private void preloadOverview(boolean fromInit, boolean forSUWAllSet) { private void preloadOverview(boolean fromInit, boolean forSUWAllSet) {
if (!mDeviceState.isUserUnlocked()) { if (!LockedUserState.get(this).isUserUnlocked()) {
return; return;
} }
@@ -1214,7 +1215,7 @@ public class TouchInteractionService extends Service
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
if (!mDeviceState.isUserUnlocked()) { if (!LockedUserState.get(this).isUserUnlocked()) {
return; return;
} }
final BaseActivityInterface activityInterface = final BaseActivityInterface activityInterface =
@@ -1255,7 +1256,7 @@ public class TouchInteractionService extends Service
} else { } else {
// Dump everything // Dump everything
FlagsFactory.dump(pw); FlagsFactory.dump(pw);
if (mDeviceState.isUserUnlocked()) { if (LockedUserState.get(this).isUserUnlocked()) {
PluginManagerWrapper.INSTANCE.get(getBaseContext()).dump(pw); PluginManagerWrapper.INSTANCE.get(getBaseContext()).dump(pw);
} }
mDeviceState.dump(pw); mDeviceState.dump(pw);
@@ -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 package com.android.launcher3.util
import android.content.Context import android.content.Context
@@ -32,7 +32,7 @@ import org.mockito.Mockito.verifyZeroInteractions
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations import org.mockito.MockitoAnnotations
/** Unit tests for {@link LockedUserUtil} */ /** Unit tests for {@link LockedUserState} */
@SmallTest @SmallTest
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class LockedUserStateTest { class LockedUserStateTest {
@@ -49,40 +49,31 @@ class LockedUserStateTest {
@Test @Test
fun runOnUserUnlocked_runs_action_immediately_if_already_unlocked() { fun runOnUserUnlocked_runs_action_immediately_if_already_unlocked() {
`when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(true) `when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(true)
LockedUserState.INSTANCE.initializeForTesting(LockedUserState(context))
val action: Runnable = mock() val action: Runnable = mock()
LockedUserState(context).runOnUserUnlocked(action)
LockedUserState.get(context).runOnUserUnlocked(action)
verify(action).run() verify(action).run()
} }
@Test @Test
fun runOnUserUnlocked_waits_to_run_action_until_user_is_unlocked() { fun runOnUserUnlocked_waits_to_run_action_until_user_is_unlocked() {
`when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(false) `when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(false)
LockedUserState.INSTANCE.initializeForTesting(LockedUserState(context))
val action: Runnable = mock() val action: Runnable = mock()
val state = LockedUserState(context)
LockedUserState.get(context).runOnUserUnlocked(action) state.runOnUserUnlocked(action)
verifyZeroInteractions(action) verifyZeroInteractions(action)
state.mUserUnlockedReceiver.onReceive(context, Intent(Intent.ACTION_USER_UNLOCKED))
LockedUserState.get(context)
.mUserUnlockedReceiver
.onReceive(context, Intent(Intent.ACTION_USER_UNLOCKED))
verify(action).run() verify(action).run()
} }
@Test @Test
fun isUserUnlocked_returns_true_when_user_is_unlocked() { fun isUserUnlocked_returns_true_when_user_is_unlocked() {
`when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(true) `when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(true)
LockedUserState.INSTANCE.initializeForTesting(LockedUserState(context)) assertThat(LockedUserState(context).isUserUnlocked).isTrue()
assertThat(LockedUserState.get(context).isUserUnlocked).isTrue()
} }
@Test @Test
fun isUserUnlocked_returns_false_when_user_is_locked() { fun isUserUnlocked_returns_false_when_user_is_locked() {
`when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(false) `when`(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(false)
LockedUserState.INSTANCE.initializeForTesting(LockedUserState(context)) assertThat(LockedUserState(context).isUserUnlocked).isFalse()
assertThat(LockedUserState.get(context).isUserUnlocked).isFalse()
} }
} }