Merge "Revert "Migrating RecentsAnimationDeviceState and dependent obje..."" into main

This commit is contained in:
Liana Kazanova (xWF)
2025-01-22 14:05:04 -08:00
committed by Android (Google) Code Review
18 changed files with 171 additions and 271 deletions
@@ -1,25 +0,0 @@
/*
* Copyright (C) 2025 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.dagger
import dagger.Module
/**
* Module containing bindings for the final derivative app, an implementation of this module should
* be included in the final app code.
*/
@Module abstract class AppModule {}
+1
View File
@@ -34,6 +34,7 @@
<string name="launcher_restore_event_logger_class" translatable="false">com.android.quickstep.LauncherRestoreEventLoggerImpl</string>
<string name="taskbar_edu_tooltip_controller_class" translatable="false">com.android.launcher3.taskbar.TaskbarEduTooltipController</string>
<string name="nav_handle_long_press_handler_class" translatable="false"></string>
<string name="contextual_search_state_manager_class" translatable="false"></string>
<!-- The number of thumbnails and icons to keep in the cache. The thumbnail cache size also
determines how many thumbnails will be fetched in the background. -->
@@ -21,11 +21,9 @@ import com.android.launcher3.uioverrides.plugins.PluginManagerWrapperImpl
import com.android.launcher3.util.ApiWrapper
import com.android.launcher3.util.PluginManagerWrapper
import com.android.launcher3.util.window.WindowManagerProxy
import com.android.quickstep.util.GestureExclusionManager
import com.android.quickstep.util.SystemWindowManagerProxy
import dagger.Binds
import dagger.Module
import dagger.Provides
private object Modules {}
@@ -44,11 +42,3 @@ abstract class PluginManagerWrapperModule {
@Binds
abstract fun bindPluginManagerWrapper(impl: PluginManagerWrapperImpl): PluginManagerWrapper
}
@Module
object StaticObjectModule {
@Provides
@JvmStatic
fun provideGestureExclusionManager(): GestureExclusionManager = GestureExclusionManager.INSTANCE
}
@@ -64,15 +64,12 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.dagger.LauncherAppComponent;
import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.util.DaggerSingletonObject;
import com.android.launcher3.util.DaggerSingletonTracker;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.NavigationMode;
import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.util.SettingsCache;
import com.android.quickstep.TopTaskTracker.CachedTaskInfo;
import com.android.quickstep.util.ActiveGestureLog;
@@ -88,14 +85,13 @@ import com.android.systemui.shared.system.TaskStackChangeListener;
import com.android.systemui.shared.system.TaskStackChangeListeners;
import java.io.PrintWriter;
import javax.inject.Inject;
import java.util.ArrayList;
/**
* Manages the state of the system during a swipe up gesture.
*/
@LauncherAppSingleton
public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, ExclusionListener {
public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, ExclusionListener,
SafeCloseable {
static final String SUPPORT_ONE_HANDED_MODE = "ro.support_one_handed_mode";
@@ -103,8 +99,8 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E
private static final float QUICKSTEP_TOUCH_SLOP_RATIO_TWO_BUTTON = 3f;
private static final float QUICKSTEP_TOUCH_SLOP_RATIO_GESTURAL = 1.414f;
public static DaggerSingletonObject<RecentsAnimationDeviceState> INSTANCE =
new DaggerSingletonObject<>(LauncherAppComponent::getRecentsAnimationDeviceState);
public static MainThreadInitializedObject<RecentsAnimationDeviceState> INSTANCE =
new MainThreadInitializedObject<>(RecentsAnimationDeviceState::new);
private final Context mContext;
private final DisplayController mDisplayController;
@@ -114,11 +110,12 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E
private final RotationTouchHelper mRotationTouchHelper;
private final TaskStackChangeListener mPipListener;
private final DaggerSingletonTracker mLifeCycle;
// Cache for better performance since it doesn't change at runtime.
private final boolean mCanImeRenderGesturalNavButtons =
InputMethodService.canImeRenderGesturalNavButtons();
private final ArrayList<Runnable> mOnDestroyActions = new ArrayList<>();
private @SystemUiStateFlags long mSystemUiStateFlags = QuickStepContract.SYSUI_STATE_AWAKE;
private NavigationMode mMode = THREE_BUTTONS;
private NavBarPosition mNavBarPosition;
@@ -137,39 +134,35 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E
private @NonNull Region mExclusionRegion = GestureExclusionManager.EMPTY_REGION;
private boolean mExclusionListenerRegistered;
private RecentsAnimationDeviceState(Context context) {
this(context, GestureExclusionManager.INSTANCE);
}
@VisibleForTesting
@Inject
RecentsAnimationDeviceState(
@ApplicationContext Context context,
GestureExclusionManager exclusionManager,
DisplayController displayController,
ContextualSearchStateManager contextualSearchStateManager,
RotationTouchHelper rotationTouchHelper,
SettingsCache settingsCache,
DaggerSingletonTracker lifeCycle) {
RecentsAnimationDeviceState(Context context, GestureExclusionManager exclusionManager) {
mContext = context;
mDisplayController = displayController;
mDisplayController = DisplayController.INSTANCE.get(context);
mExclusionManager = exclusionManager;
mContextualSearchStateManager = contextualSearchStateManager;
mRotationTouchHelper = rotationTouchHelper;
mLifeCycle = lifeCycle;
mContextualSearchStateManager = ContextualSearchStateManager.INSTANCE.get(context);
mIsOneHandedModeSupported = SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false);
mRotationTouchHelper = RotationTouchHelper.INSTANCE.get(context);
// Register for exclusion updates
mLifeCycle.addCloseable(this::unregisterExclusionListener);
runOnDestroy(this::unregisterExclusionListener);
// Register for display changes changes
mDisplayController.addChangeListener(this);
onDisplayInfoChanged(context, mDisplayController.getInfo(), CHANGE_ALL);
mLifeCycle.addCloseable(() -> mDisplayController.removeChangeListener(this));
runOnDestroy(() -> mDisplayController.removeChangeListener(this));
SettingsCache settingsCache = SettingsCache.INSTANCE.get(mContext);
if (mIsOneHandedModeSupported) {
Uri oneHandedUri = Settings.Secure.getUriFor(ONE_HANDED_ENABLED);
SettingsCache.OnChangeListener onChangeListener =
enabled -> mIsOneHandedModeEnabled = enabled;
settingsCache.register(oneHandedUri, onChangeListener);
mIsOneHandedModeEnabled = settingsCache.getValue(oneHandedUri);
mLifeCycle.addCloseable(() -> settingsCache.unregister(oneHandedUri, onChangeListener));
runOnDestroy(() -> settingsCache.unregister(oneHandedUri, onChangeListener));
} else {
mIsOneHandedModeEnabled = false;
}
@@ -180,16 +173,14 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E
enabled -> mIsSwipeToNotificationEnabled = enabled;
settingsCache.register(swipeBottomNotificationUri, onChangeListener);
mIsSwipeToNotificationEnabled = settingsCache.getValue(swipeBottomNotificationUri);
mLifeCycle.addCloseable(
() -> settingsCache.unregister(swipeBottomNotificationUri, onChangeListener));
runOnDestroy(() -> settingsCache.unregister(swipeBottomNotificationUri, onChangeListener));
Uri setupCompleteUri = Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE);
mIsUserSetupComplete = settingsCache.getValue(setupCompleteUri, 0);
if (!mIsUserSetupComplete) {
SettingsCache.OnChangeListener userSetupChangeListener = e -> mIsUserSetupComplete = e;
settingsCache.register(setupCompleteUri, userSetupChangeListener);
mLifeCycle.addCloseable(
() -> settingsCache.unregister(setupCompleteUri, userSetupChangeListener));
runOnDestroy(() -> settingsCache.unregister(setupCompleteUri, userSetupChangeListener));
}
try {
@@ -210,10 +201,21 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E
}
};
TaskStackChangeListeners.getInstance().registerTaskStackListener(mPipListener);
mLifeCycle.addCloseable(() ->
runOnDestroy(() ->
TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mPipListener));
}
private void runOnDestroy(Runnable action) {
mOnDestroyActions.add(action);
}
@Override
public void close() {
for (Runnable r : mOnDestroyActions) {
r.run();
}
}
/**
* Adds a listener for the nav mode change, guaranteed to be called after the device state's
* mode has changed.
@@ -226,7 +228,7 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener, E
};
mDisplayController.addChangeListener(listener);
callback.run();
mLifeCycle.addCloseable(() -> mDisplayController.removeChangeListener(listener));
runOnDestroy(() -> mDisplayController.removeChangeListener(listener));
}
@Override
@@ -33,16 +33,13 @@ import android.content.res.Resources;
import android.view.MotionEvent;
import android.view.OrientationEventListener;
import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.dagger.LauncherAppComponent;
import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.DaggerSingletonObject;
import com.android.launcher3.util.DaggerSingletonTracker;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.NavigationMode;
import com.android.launcher3.util.SafeCloseable;
import com.android.quickstep.util.RecentsOrientedState;
import com.android.systemui.shared.Flags;
import com.android.systemui.shared.system.QuickStepContract;
@@ -51,20 +48,16 @@ import com.android.systemui.shared.system.TaskStackChangeListeners;
import java.io.PrintWriter;
import javax.inject.Inject;
/**
* Helper class for transforming touch events
*/
@LauncherAppSingleton
public class RotationTouchHelper implements DisplayInfoChangeListener {
public class RotationTouchHelper implements DisplayInfoChangeListener, SafeCloseable {
public static final DaggerSingletonObject<RotationTouchHelper> INSTANCE =
new DaggerSingletonObject<>(LauncherAppComponent::getRotationTouchHelper);
public static final MainThreadInitializedObject<RotationTouchHelper> INSTANCE =
new MainThreadInitializedObject<>(RotationTouchHelper::new);
private final OrientationTouchTransformer mOrientationTouchTransformer;
private final DisplayController mDisplayController;
private final SystemUiProxy mSystemUiProxy;
private final int mDisplayId;
private int mDisplayRotation;
@@ -134,17 +127,12 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
private boolean mTaskListFrozen;
private final Context mContext;
@Inject
RotationTouchHelper(@ApplicationContext Context context,
DisplayController displayController,
SystemUiProxy systemUiProxy,
DaggerSingletonTracker lifeCycle) {
private RotationTouchHelper(Context context) {
mContext = context;
mDisplayController = displayController;
mSystemUiProxy = systemUiProxy;
mDisplayController = DisplayController.INSTANCE.get(mContext);
Resources resources = mContext.getResources();
mDisplayId = DEFAULT_DISPLAY;
Resources resources = mContext.getResources();
mOrientationTouchTransformer = new OrientationTouchTransformer(resources, mMode,
() -> QuickStepContract.getWindowCornerRadius(mContext));
@@ -172,13 +160,14 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
}
}
};
}
lifeCycle.addCloseable(() -> {
mDisplayController.removeChangeListener(this);
mOrientationListener.disable();
TaskStackChangeListeners.getInstance()
.unregisterTaskStackListener(mFrozenTaskListener);
});
@Override
public void close() {
mDisplayController.removeChangeListener(this);
mOrientationListener.disable();
TaskStackChangeListeners.getInstance()
.unregisterTaskStackListener(mFrozenTaskListener);
}
public boolean isTaskListFrozen() {
@@ -351,7 +340,8 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
}
private void notifySysuiOfCurrentRotation(int rotation) {
UI_HELPER_EXECUTOR.execute(() -> mSystemUiProxy.notifyPrioritizedRotation(rotation));
UI_HELPER_EXECUTOR.execute(() -> SystemUiProxy.INSTANCE.get(mContext)
.notifyPrioritizedRotation(rotation));
}
/**
@@ -21,13 +21,10 @@ import com.android.launcher3.dagger.LauncherBaseAppComponent;
import com.android.launcher3.model.WellbeingModel;
import com.android.launcher3.statehandlers.DesktopVisibilityController;
import com.android.quickstep.OverviewComponentObserver;
import com.android.quickstep.RecentsAnimationDeviceState;
import com.android.quickstep.RotationTouchHelper;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.TopTaskTracker;
import com.android.quickstep.fallback.window.RecentsDisplayModel;
import com.android.quickstep.util.AsyncClockEventDelegate;
import com.android.quickstep.util.ContextualSearchStateManager;
/**
* Launcher Quickstep base component for Dagger injection.
@@ -52,10 +49,4 @@ public interface QuickstepBaseAppComponent extends LauncherBaseAppComponent {
DesktopVisibilityController getDesktopVisibilityController();
TopTaskTracker getTopTaskTracker();
RotationTouchHelper getRotationTouchHelper();
ContextualSearchStateManager getContextualSearchStateManager();
RecentsAnimationDeviceState getRecentsAnimationDeviceState();
}
@@ -21,6 +21,7 @@ import static android.app.contextualsearch.ContextualSearchManager.FEATURE_CONTE
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_LAUNCH_OMNI_SUCCESSFUL_SYSTEM_ACTION;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.MainThreadInitializedObject.forOverride;
import static com.android.quickstep.util.SystemActionConstants.SYSTEM_ACTION_ID_SEARCH_SCREEN;
import android.app.PendingIntent;
@@ -43,13 +44,11 @@ import androidx.annotation.CallSuper;
import androidx.annotation.VisibleForTesting;
import com.android.launcher3.R;
import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.dagger.LauncherAppComponent;
import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.util.DaggerSingletonObject;
import com.android.launcher3.util.DaggerSingletonTracker;
import com.android.launcher3.util.EventLogArray;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.ResourceBasedOverride;
import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.util.SettingsCache;
import com.android.launcher3.util.SimpleBroadcastReceiver;
import com.android.quickstep.DeviceConfigWrapper;
@@ -59,14 +58,12 @@ import com.android.quickstep.TopTaskTracker;
import java.io.PrintWriter;
import java.util.Optional;
import javax.inject.Inject;
/** Long-lived class to manage Contextual Search states like the user setting and availability. */
@LauncherAppSingleton
public class ContextualSearchStateManager {
public class ContextualSearchStateManager implements ResourceBasedOverride, SafeCloseable {
public static final DaggerSingletonObject<ContextualSearchStateManager> INSTANCE =
new DaggerSingletonObject<>(LauncherAppComponent::getContextualSearchStateManager);
public static final MainThreadInitializedObject<ContextualSearchStateManager> INSTANCE =
forOverride(ContextualSearchStateManager.class,
R.string.contextual_search_state_manager_class);
private static final String TAG = "ContextualSearchStMgr";
private static final int MAX_DEBUG_EVENT_SIZE = 20;
@@ -76,29 +73,23 @@ public class ContextualSearchStateManager {
private final Runnable mSysUiStateChangeListener = this::updateOverridesToSysUi;
private final SimpleBroadcastReceiver mContextualSearchPackageReceiver =
new SimpleBroadcastReceiver(UI_HELPER_EXECUTOR, (unused) -> requestUpdateProperties());
private final SettingsCache.OnChangeListener mContextualSearchSettingChangedListener =
this::onContextualSearchSettingChanged;
protected final EventLogArray mEventLogArray = new EventLogArray(TAG, MAX_DEBUG_EVENT_SIZE);
// Cached value whether the ContextualSearch intent filter matched any enabled components.
private boolean mIsContextualSearchIntentAvailable;
private boolean mIsContextualSearchSettingEnabled;
protected final Context mContext;
protected final String mContextualSearchPackage;
protected final SystemUiProxy mSystemUiProxy;
protected final TopTaskTracker mTopTaskTracker;
protected Context mContext;
protected String mContextualSearchPackage;
@Inject
public ContextualSearchStateManager(
@ApplicationContext Context context,
SettingsCache settingsCache,
SystemUiProxy systemUiProxy,
TopTaskTracker topTaskTracker,
DaggerSingletonTracker lifeCycle) {
public ContextualSearchStateManager() {}
public ContextualSearchStateManager(Context context) {
mContext = context;
mContextualSearchPackage = mContext.getResources().getString(
com.android.internal.R.string.config_defaultContextualSearchPackageName);
mSystemUiProxy = systemUiProxy;
mTopTaskTracker = topTaskTracker;
if (areAllContextualSearchFlagsDisabled()
|| !context.getPackageManager().hasSystemFeature(FEATURE_CONTEXTUAL_SEARCH)) {
@@ -115,20 +106,11 @@ public class ContextualSearchStateManager {
context, mContextualSearchPackage, Intent.ACTION_PACKAGE_ADDED,
Intent.ACTION_PACKAGE_CHANGED, Intent.ACTION_PACKAGE_REMOVED);
SettingsCache.OnChangeListener settingChangedListener =
isEnabled -> mIsContextualSearchSettingEnabled = isEnabled;
settingsCache.register(SEARCH_ALL_ENTRYPOINTS_ENABLED_URI, settingChangedListener);
mIsContextualSearchSettingEnabled =
settingsCache.getValue(SEARCH_ALL_ENTRYPOINTS_ENABLED_URI);
systemUiProxy.addOnStateChangeListener(mSysUiStateChangeListener);
lifeCycle.addCloseable(() -> {
mContextualSearchPackageReceiver.unregisterReceiverSafely(mContext);
unregisterSearchScreenSystemAction();
settingsCache.unregister(SEARCH_ALL_ENTRYPOINTS_ENABLED_URI, settingChangedListener);
systemUiProxy.removeOnStateChangeListener(mSysUiStateChangeListener);
});
SettingsCache.INSTANCE.get(context).register(SEARCH_ALL_ENTRYPOINTS_ENABLED_URI,
mContextualSearchSettingChangedListener);
onContextualSearchSettingChanged(
SettingsCache.INSTANCE.get(context).getValue(SEARCH_ALL_ENTRYPOINTS_ENABLED_URI));
SystemUiProxy.INSTANCE.get(mContext).addOnStateChangeListener(mSysUiStateChangeListener);
}
/** Return {@code true} if the Settings toggle is enabled. */
@@ -136,6 +118,10 @@ public class ContextualSearchStateManager {
return mIsContextualSearchSettingEnabled;
}
private void onContextualSearchSettingChanged(boolean isEnabled) {
mIsContextualSearchSettingEnabled = isEnabled;
}
/** Whether search supports showing on the lockscreen. */
protected boolean supportsShowWhenLocked() {
return false;
@@ -222,7 +208,7 @@ public class ContextualSearchStateManager {
protected final void updateOverridesToSysUi() {
// LPH commit haptic is always enabled
mSystemUiProxy.setOverrideHomeButtonLongPress(
SystemUiProxy.INSTANCE.get(mContext).setOverrideHomeButtonLongPress(
getLPHDurationMillis().orElse(0L), getLPHCustomSlopMultiplier().orElse(0f), true);
Log.i(TAG, "Sent LPH override to sysui: " + getLPHDurationMillis().orElse(0L) + ";"
+ getLPHCustomSlopMultiplier().orElse(0f));
@@ -241,8 +227,10 @@ public class ContextualSearchStateManager {
new ContextualSearchInvoker(mContext).show(
ENTRYPOINT_SYSTEM_ACTION);
if (contextualSearchInvoked) {
String runningPackage = mTopTaskTracker.getCachedTopTask(
/* filterOnlyVisibleRecents */ true).getPackageName();
String runningPackage =
TopTaskTracker.INSTANCE.get(mContext).getCachedTopTask(
/* filterOnlyVisibleRecents */
true).getPackageName();
StatsLogManager.newInstance(mContext).logger()
.withPackageName(runningPackage)
.log(LAUNCHER_LAUNCH_OMNI_SUCCESSFUL_SYSTEM_ACTION);
@@ -271,6 +259,15 @@ public class ContextualSearchStateManager {
}
}
@Override
public void close() {
mContextualSearchPackageReceiver.unregisterReceiverSafely(mContext);
unregisterSearchScreenSystemAction();
SettingsCache.INSTANCE.get(mContext).unregister(SEARCH_ALL_ENTRYPOINTS_ENABLED_URI,
mContextualSearchSettingChangedListener);
SystemUiProxy.INSTANCE.get(mContext).removeOnStateChangeListener(mSysUiStateChangeListener);
}
protected final void addEventLog(String event) {
synchronized (mEventLogArray) {
mEventLogArray.addLog(event);
@@ -86,11 +86,17 @@ class LauncherSwipeHandlerV2Test {
whenever(displayManager.displays).thenReturn(arrayOf(display))
sandboxContext.initDaggerComponent(
DaggerTestComponent.builder()
.bindSystemUiProxy(systemUiProxy)
.bindRotationHelper(mock(RotationTouchHelper::class.java))
.bindRecentsState(mock(RecentsAnimationDeviceState::class.java))
DaggerTestComponent.builder().bindSystemUiProxy(systemUiProxy)
)
sandboxContext.putObject(
RotationTouchHelper.INSTANCE,
mock(RotationTouchHelper::class.java),
)
sandboxContext.putObject(
RecentsAnimationDeviceState.INSTANCE,
mock(RecentsAnimationDeviceState::class.java),
)
gestureState = spy(GestureState(OverviewComponentObserver.INSTANCE.get(sandboxContext), 0))
underTest =
@@ -111,14 +117,20 @@ class LauncherSwipeHandlerV2Test {
gestureState.setTrackpadGestureType(GestureState.TrackpadGestureType.THREE_FINGER)
underTest.onGestureEnded(flingSpeed, PointF())
verify(systemUiProxy)
.updateContextualEduStats(/* isTrackpadGesture= */ eq(true), eq(GestureType.HOME))
.updateContextualEduStats(
/* isTrackpadGesture= */ eq(true),
eq(GestureType.HOME),
)
}
@Test
fun goHomeFromAppByTouch_updateEduStats() {
underTest.onGestureEnded(flingSpeed, PointF())
verify(systemUiProxy)
.updateContextualEduStats(/* isTrackpadGesture= */ eq(false), eq(GestureType.HOME))
.updateContextualEduStats(
/* isTrackpadGesture= */ eq(false),
eq(GestureType.HOME),
)
}
}
@@ -129,10 +141,6 @@ interface TestComponent : LauncherAppComponent {
interface Builder : LauncherAppComponent.Builder {
@BindsInstance fun bindSystemUiProxy(proxy: SystemUiProxy): Builder
@BindsInstance fun bindRotationHelper(helper: RotationTouchHelper): Builder
@BindsInstance fun bindRecentsState(state: RecentsAnimationDeviceState): Builder
override fun build(): TestComponent
}
}
@@ -1,8 +1,9 @@
package com.android.quickstep
import android.content.Context
import androidx.test.annotation.UiThreadTest
import androidx.test.core.app.ApplicationProvider
import androidx.test.filters.SmallTest
import com.android.launcher3.dagger.LauncherComponentProvider
import com.android.launcher3.util.DisplayController.CHANGE_DENSITY
import com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE
import com.android.launcher3.util.DisplayController.CHANGE_ROTATION
@@ -11,7 +12,6 @@ import com.android.launcher3.util.Executors.MAIN_EXECUTOR
import com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR
import com.android.launcher3.util.LauncherMultivalentJUnit
import com.android.launcher3.util.NavigationMode
import com.android.launcher3.util.SandboxApplication
import com.android.quickstep.util.GestureExclusionManager
import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_ALLOW_GESTURE_IGNORING_BAR_VISIBILITY
import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_DEVICE_DREAMING
@@ -27,7 +27,6 @@ import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_TOUCHPAD
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
@@ -44,32 +43,21 @@ import org.mockito.kotlin.whenever
@RunWith(LauncherMultivalentJUnit::class)
class RecentsAnimationDeviceStateTest {
@get:Rule val context = SandboxApplication()
@Mock private lateinit var exclusionManager: GestureExclusionManager
@Mock private lateinit var info: Info
private val context = ApplicationProvider.getApplicationContext() as Context
private lateinit var underTest: RecentsAnimationDeviceState
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
val component = LauncherComponentProvider.get(context)
underTest =
RecentsAnimationDeviceState(
context,
exclusionManager,
component.displayController,
component.contextualSearchStateManager,
component.rotationTouchHelper,
component.settingsCache,
component.daggerSingletonTracker,
)
underTest = RecentsAnimationDeviceState(context, exclusionManager)
}
@After
fun tearDown() {
underTest.close()
UI_HELPER_EXECUTOR.submit {}.get()
MAIN_EXECUTOR.submit {}.get()
}
@@ -16,6 +16,8 @@
package com.android.quickstep;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.android.quickstep.InputConsumerUtils.newBaseConsumer;
import static com.android.quickstep.InputConsumerUtils.newConsumer;
@@ -38,9 +40,6 @@ import androidx.test.platform.app.InstrumentationRegistry;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.dagger.LauncherAppComponent;
import com.android.launcher3.dagger.LauncherAppModule;
import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.taskbar.TaskbarActivityContext;
import com.android.launcher3.taskbar.TaskbarManager;
import com.android.launcher3.taskbar.bubbles.BubbleBarController;
@@ -55,7 +54,7 @@ import com.android.launcher3.taskbar.bubbles.BubblePinController;
import com.android.launcher3.taskbar.bubbles.BubbleStashedHandleViewController;
import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController;
import com.android.launcher3.util.LockedUserState;
import com.android.launcher3.util.SandboxApplication;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.views.BaseDragLayer;
import com.android.quickstep.inputconsumers.AccessibilityInputConsumer;
import com.android.quickstep.inputconsumers.BubbleBarInputConsumer;
@@ -76,9 +75,6 @@ import com.android.quickstep.views.RecentsViewContainer;
import com.android.systemui.shared.system.InputChannelCompat;
import com.android.systemui.shared.system.InputMonitorCompat;
import dagger.BindsInstance;
import dagger.Component;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -97,8 +93,8 @@ import javax.inject.Provider;
@RunWith(AndroidJUnit4.class)
public class InputConsumerUtilsTest {
@Rule public final SandboxApplication mContext = new SandboxApplication();
@NonNull private final MainThreadInitializedObject.SandboxContext mContext =
new MainThreadInitializedObject.SandboxContext(getApplicationContext());
@NonNull private final InputMonitorCompat mInputMonitorCompat = new InputMonitorCompat("", 0);
private TaskAnimationManager mTaskAnimationManager;
@@ -129,12 +125,10 @@ public class InputConsumerUtilsTest {
}
@Before
public void setupDaggerGraphOverrides() {
mContext.initDaggerComponent(DaggerInputConsumerUtilsTest_TestComponent
.builder()
.bindLockedState(mLockedUserState)
.bindRotationHelper(mock(RotationTouchHelper.class))
.bindRecentsState(mDeviceState));
public void setupMainThreadInitializedObjects() {
mContext.putObject(LockedUserState.INSTANCE, mLockedUserState);
mContext.putObject(RotationTouchHelper.INSTANCE, mock(RotationTouchHelper.class));
mContext.putObject(RecentsAnimationDeviceState.INSTANCE, mDeviceState);
}
@Before
@@ -601,18 +595,4 @@ public class InputConsumerUtilsTest {
return bubbleControllers;
}
@LauncherAppSingleton
@Component(modules = {LauncherAppModule.class})
interface TestComponent extends LauncherAppComponent {
@Component.Builder
interface Builder extends LauncherAppComponent.Builder {
@BindsInstance Builder bindLockedState(LockedUserState state);
@BindsInstance Builder bindRotationHelper(RotationTouchHelper helper);
@BindsInstance Builder bindRecentsState(RecentsAnimationDeviceState state);
@Override
TestComponent build();
}
}
}
@@ -21,9 +21,7 @@ import dagger.Module;
@Module(includes = {
WindowManagerProxyModule.class,
ApiWrapperModule.class,
PluginManagerWrapperModule.class,
StaticObjectModule.class,
AppModule.class
PluginManagerWrapperModule.class
})
public class LauncherAppModule {
}
@@ -27,7 +27,6 @@ import com.android.launcher3.util.ApiWrapper;
import com.android.launcher3.util.DaggerSingletonTracker;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DynamicResource;
import com.android.launcher3.util.LockedUserState;
import com.android.launcher3.util.MSDLPlayerWrapper;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PluginManagerWrapper;
@@ -69,7 +68,6 @@ public interface LauncherBaseAppComponent {
ThemeManager getThemeManager();
DisplayController getDisplayController();
WallpaperColorHints getWallpaperColorHints();
LockedUserState getLockedUserState();
/** Builder for LauncherBaseAppComponent. */
interface Builder {
@@ -20,17 +20,10 @@ import android.content.Intent
import android.os.Process
import android.os.UserManager
import androidx.annotation.VisibleForTesting
import com.android.launcher3.dagger.ApplicationContext
import com.android.launcher3.dagger.LauncherAppComponent
import com.android.launcher3.dagger.LauncherAppSingleton
import com.android.launcher3.util.Executors.MAIN_EXECUTOR
import com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR
import javax.inject.Inject
@LauncherAppSingleton
class LockedUserState
@Inject
constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerSingletonTracker) {
class LockedUserState(private val mContext: Context) : SafeCloseable {
val isUserUnlockedAtLauncherStartup: Boolean
var isUserUnlocked = false
private set(value) {
@@ -43,7 +36,7 @@ constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerS
private val mUserUnlockedActions: RunnableList = RunnableList()
@VisibleForTesting
val userUnlockedReceiver =
val mUserUnlockedReceiver =
SimpleBroadcastReceiver(UI_HELPER_EXECUTOR) {
if (Intent.ACTION_USER_UNLOCKED == it.action) {
isUserUnlocked = true
@@ -60,8 +53,8 @@ constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerS
isUserUnlocked = checkIsUserUnlocked()
isUserUnlockedAtLauncherStartup = isUserUnlocked
if (!isUserUnlocked) {
userUnlockedReceiver.register(
context,
mUserUnlockedReceiver.register(
mContext,
{
// If user is unlocked while registering broadcast receiver, we should update
// [isUserUnlocked], which will call [notifyUserUnlocked] in setter
@@ -69,18 +62,22 @@ constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerS
MAIN_EXECUTOR.execute { isUserUnlocked = true }
}
},
Intent.ACTION_USER_UNLOCKED,
Intent.ACTION_USER_UNLOCKED
)
}
lifeCycle.addCloseable { userUnlockedReceiver.unregisterReceiverSafely(context) }
}
private fun checkIsUserUnlocked() =
context.getSystemService(UserManager::class.java)!!.isUserUnlocked(Process.myUserHandle())
mContext.getSystemService(UserManager::class.java)!!.isUserUnlocked(Process.myUserHandle())
private fun notifyUserUnlocked() {
mUserUnlockedActions.executeAllAndDestroy()
userUnlockedReceiver.unregisterReceiverSafely(context)
mUserUnlockedReceiver.unregisterReceiverSafely(mContext)
}
/** Stops the receiver from listening for ACTION_USER_UNLOCK broadcasts. */
override fun close() {
mUserUnlockedReceiver.unregisterReceiverSafely(mContext)
}
/**
@@ -91,7 +88,9 @@ constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerS
mUserUnlockedActions.add(action)
}
/** Removes a previously queued `Runnable` to be run when the user is unlocked. */
/**
* Removes a previously queued `Runnable` to be run when the user is unlocked.
*/
fun removeOnUserUnlockedRunnable(action: Runnable) {
mUserUnlockedActions.remove(action)
}
@@ -99,7 +98,7 @@ constructor(@ApplicationContext private val context: Context, lifeCycle: DaggerS
companion object {
@VisibleForTesting
@JvmField
val INSTANCE = DaggerSingletonObject(LauncherAppComponent::getLockedUserState)
val INSTANCE = MainThreadInitializedObject { LockedUserState(it) }
@JvmStatic fun get(context: Context): LockedUserState = INSTANCE.get(context)
}
@@ -34,11 +34,11 @@ import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.dagger.LauncherBaseAppComponent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Function;
import javax.inject.Inject;
@@ -57,7 +57,7 @@ import javax.inject.Inject;
* Cache will also be updated if a key queried is missing (even if it has no listeners registered).
*/
@LauncherAppSingleton
public class SettingsCache extends ContentObserver {
public class SettingsCache extends ContentObserver implements SafeCloseable {
/** Hidden field Settings.Secure.NOTIFICATION_BADGING */
public static final Uri NOTIFICATION_BADGING_URI =
@@ -79,17 +79,11 @@ public class SettingsCache extends ContentObserver {
private static final String SYSTEM_URI_PREFIX = Settings.System.CONTENT_URI.toString();
private static final String GLOBAL_URI_PREFIX = Settings.Global.CONTENT_URI.toString();
private final Function<Uri, CopyOnWriteArrayList<OnChangeListener>> mListenerMapper = uri -> {
registerUriAsync(uri);
return new CopyOnWriteArrayList<>();
};
/**
* Caches the last seen value for registered keys.
*/
private final Map<Uri, Boolean> mKeyCache = new ConcurrentHashMap<>();
private final Map<Uri, CopyOnWriteArrayList<OnChangeListener>> mListenerMap =
new ConcurrentHashMap<>();
private Map<Uri, Boolean> mKeyCache = new ConcurrentHashMap<>();
private final Map<Uri, CopyOnWriteArrayList<OnChangeListener>> mListenerMap = new HashMap<>();
protected final ContentResolver mResolver;
/**
@@ -102,8 +96,12 @@ public class SettingsCache extends ContentObserver {
SettingsCache(@ApplicationContext Context context, DaggerSingletonTracker tracker) {
super(new Handler(Looper.getMainLooper()));
mResolver = context.getContentResolver();
tracker.addCloseable(() ->
UI_HELPER_EXECUTOR.execute(() -> mResolver.unregisterContentObserver(this)));
tracker.addCloseable(this);
}
@Override
public void close() {
UI_HELPER_EXECUTOR.execute(() -> mResolver.unregisterContentObserver(this));
}
@Override
@@ -111,12 +109,11 @@ public class SettingsCache extends ContentObserver {
// We use default of 1, but if we're getting an onChange call, can assume a non-default
// value will exist
boolean newVal = updateValue(uri, 1 /* Effectively Unused */);
List<OnChangeListener> listeners = mListenerMap.get(uri);
if (listeners == null) {
if (!mListenerMap.containsKey(uri)) {
return;
}
for (OnChangeListener listener : listeners) {
for (OnChangeListener listener : mListenerMap.get(uri)) {
listener.onSettingsChanged(newVal);
}
}
@@ -141,17 +138,22 @@ public class SettingsCache extends ContentObserver {
}
}
private void registerUriAsync(Uri uri) {
UI_HELPER_EXECUTOR.execute(() -> mResolver.registerContentObserver(uri, false, this));
}
/**
* Does not de-dupe if you add same listeners for the same key multiple times.
* Unregister once complete using {@link #unregister(Uri, OnChangeListener)}
*/
@UiThread
public void register(Uri uri, OnChangeListener changeListener) {
mListenerMap.computeIfAbsent(uri, mListenerMapper).add(changeListener);
Preconditions.assertUIThread();
if (mListenerMap.containsKey(uri)) {
mListenerMap.get(uri).add(changeListener);
} else {
CopyOnWriteArrayList<OnChangeListener> l = new CopyOnWriteArrayList<>();
l.add(changeListener);
mListenerMap.put(uri, l);
UI_HELPER_EXECUTOR.execute(
() -> mResolver.registerContentObserver(uri, false, this));
}
}
private boolean updateValue(Uri keyUri, int defaultValue) {
@@ -25,8 +25,3 @@ private object Modules {}
@Module abstract class ApiWrapperModule {}
@Module abstract class PluginManagerWrapperModule {}
@Module object StaticObjectModule {}
// Module containing bindings for the final derivative app
@Module abstract class AppModule {}
@@ -19,8 +19,6 @@ package com.android.launcher3.util
import com.android.launcher3.FakeLauncherPrefs
import com.android.launcher3.LauncherPrefs
import com.android.launcher3.dagger.ApiWrapperModule
import com.android.launcher3.dagger.AppModule
import com.android.launcher3.dagger.StaticObjectModule
import com.android.launcher3.dagger.WindowManagerProxyModule
import dagger.Binds
import dagger.Module
@@ -33,21 +31,11 @@ abstract class FakePrefsModule {
}
/** All modules. We also exclude the plugin module from tests */
@Module(
includes =
[
ApiWrapperModule::class,
WindowManagerProxyModule::class,
StaticObjectModule::class,
AppModule::class,
]
)
@Module(includes = [ApiWrapperModule::class, WindowManagerProxyModule::class])
class AllModulesForTest
/** All modules except the WMProxy */
@Module(includes = [ApiWrapperModule::class, StaticObjectModule::class, AppModule::class])
class AllModulesMinusWMProxy
@Module(includes = [ApiWrapperModule::class]) class AllModulesMinusWMProxy
/** All modules except the ApiWrapper */
@Module(includes = [WindowManagerProxyModule::class, StaticObjectModule::class, AppModule::class])
class AllModulesMinusApiWrapper
@Module(includes = [WindowManagerProxyModule::class]) class AllModulesMinusApiWrapper
@@ -38,7 +38,6 @@ class LockedUserStateTest {
private val userManager: UserManager = mock()
private val context: Context = mock()
private val lifeCycle: DaggerSingletonTracker = mock()
@Before
fun setup() {
@@ -49,7 +48,7 @@ class LockedUserStateTest {
fun runOnUserUnlocked_runs_action_immediately_if_already_unlocked() {
whenever(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(true)
val action: Runnable = mock()
LockedUserState(context, lifeCycle).runOnUserUnlocked(action)
LockedUserState(context).runOnUserUnlocked(action)
verify(action).run()
}
@@ -57,23 +56,23 @@ class LockedUserStateTest {
fun runOnUserUnlocked_waits_to_run_action_until_user_is_unlocked() {
whenever(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(false)
val action: Runnable = mock()
val state = LockedUserState(context, lifeCycle)
val state = LockedUserState(context)
state.runOnUserUnlocked(action)
// b/343530737
verifyNoMoreInteractions(action)
state.userUnlockedReceiver.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() {
whenever(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(true)
assertThat(LockedUserState(context, lifeCycle).isUserUnlocked).isTrue()
assertThat(LockedUserState(context).isUserUnlocked).isTrue()
}
@Test
fun isUserUnlocked_returns_false_when_user_is_locked() {
whenever(userManager.isUserUnlocked(Process.myUserHandle())).thenReturn(false)
assertThat(LockedUserState(context, lifeCycle).isUserUnlocked).isFalse()
assertThat(LockedUserState(context).isUserUnlocked).isFalse()
}
}
@@ -48,7 +48,6 @@ import org.junit.runners.model.Statement
class SandboxApplication private constructor(private val base: SandboxApplicationWrapper) :
SandboxModelContext(base), TestRule {
@JvmOverloads
constructor(
base: Context = ApplicationProvider.getApplicationContext()
) : this(SandboxApplicationWrapper(base))