Merge "Use Assisted Injection for EdgeBackGestureHandler" into main
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarModule.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarModule.java
index a8b979e0..914e0f7 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarModule.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarModule.java
@@ -28,7 +28,6 @@
import com.android.app.viewcapture.ViewCaptureAwareWindowManager;
import com.android.systemui.dagger.qualifiers.DisplayId;
import com.android.systemui.navigationbar.NavigationBarComponent.NavigationBarScope;
-import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
import com.android.systemui.navigationbar.views.NavigationBarFrame;
import com.android.systemui.navigationbar.views.NavigationBarView;
import com.android.systemui.res.R;
@@ -64,14 +63,6 @@
return barView.findViewById(R.id.navigation_bar_view);
}
- /** */
- @Provides
- @NavigationBarScope
- static EdgeBackGestureHandler provideEdgeBackGestureHandler(
- EdgeBackGestureHandler.Factory factory, @DisplayId Context context) {
- return factory.create(context);
- }
-
/** A WindowManager specific to the display's context. */
@Provides
@NavigationBarScope
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt
index 7e07e4d..44c8287 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt
@@ -41,11 +41,11 @@
import com.android.systemui.statusbar.VibratorHelper
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.ViewController
-import com.android.systemui.util.concurrency.BackPanelUiThread
-import com.android.systemui.util.concurrency.UiThreadContext
import com.android.systemui.util.time.SystemClock
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedFactory
+import dagger.assisted.AssistedInject
import java.io.PrintWriter
-import javax.inject.Inject
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
@@ -82,11 +82,12 @@
private const val DEBUG = false
class BackPanelController
-internal constructor(
- context: Context,
+@AssistedInject
+constructor(
+ @Assisted context: Context,
private val windowManager: ViewCaptureAwareWindowManager,
private val viewConfiguration: ViewConfiguration,
- private val mainHandler: Handler,
+ @Assisted private val mainHandler: Handler,
private val systemClock: SystemClock,
private val vibratorHelper: VibratorHelper,
private val configurationController: ConfigurationController,
@@ -94,40 +95,9 @@
private val interactionJankMonitor: InteractionJankMonitor,
) : ViewController<BackPanel>(BackPanel(context, latencyTracker)), NavigationEdgeBackPlugin {
- /**
- * Injectable instance to create a new BackPanelController.
- *
- * Necessary because EdgeBackGestureHandler sometimes needs to create new instances of
- * BackPanelController, and we need to match EdgeBackGestureHandler's context.
- */
- class Factory
- @Inject
- constructor(
- private val windowManager: ViewCaptureAwareWindowManager,
- private val viewConfiguration: ViewConfiguration,
- @BackPanelUiThread private val uiThreadContext: UiThreadContext,
- private val systemClock: SystemClock,
- private val vibratorHelper: VibratorHelper,
- private val configurationController: ConfigurationController,
- private val latencyTracker: LatencyTracker,
- private val interactionJankMonitor: InteractionJankMonitor,
- ) {
- /** Construct a [BackPanelController]. */
- fun create(context: Context): BackPanelController {
- uiThreadContext.isCurrentThread()
- return BackPanelController(
- context,
- windowManager,
- viewConfiguration,
- uiThreadContext.handler,
- systemClock,
- vibratorHelper,
- configurationController,
- latencyTracker,
- interactionJankMonitor,
- )
- .also { it.init() }
- }
+ @AssistedFactory
+ interface Factory {
+ fun create(context: Context, handler: Handler): BackPanelController
}
@VisibleForTesting internal var params: EdgePanelParams = EdgePanelParams(resources)
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java
index b3463bd..53177de 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java
@@ -103,6 +103,10 @@
import com.android.wm.shell.desktopmode.DesktopMode;
import com.android.wm.shell.pip.Pip;
+import dagger.assisted.Assisted;
+import dagger.assisted.AssistedFactory;
+import dagger.assisted.AssistedInject;
+
import kotlinx.coroutines.Job;
import java.io.PrintWriter;
@@ -117,7 +121,6 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
-import javax.inject.Inject;
import javax.inject.Provider;
/**
@@ -414,8 +417,21 @@
}
};
+ /**
+ * Factory for EdgeBackGestureHandler. Necessary because per-display contexts can't be injected.
+ * With this, you can pass in a specific context that knows what display it is in.
+ */
+ @AssistedFactory
+ public interface Factory {
+ /**
+ * Creates a new EdgeBackGestureHandler with the given context.
+ */
+ EdgeBackGestureHandler create(Context context);
+ }
+
+ @AssistedInject
EdgeBackGestureHandler(
- Context context,
+ @Assisted Context context,
OverviewProxyService overviewProxyService,
SysUiState sysUiState,
PluginManager pluginManager,
@@ -751,7 +767,10 @@
}
private void resetEdgeBackPlugin() {
- setEdgeBackPlugin(mBackPanelControllerFactory.create(mContext));
+ BackPanelController backPanelController = mBackPanelControllerFactory.create(mContext,
+ mUiThreadContext.getHandler());
+ backPanelController.init();
+ setEdgeBackPlugin(backPanelController);
}
private void setEdgeBackPlugin(NavigationEdgeBackPlugin edgeBackPlugin) {
@@ -1329,113 +1348,6 @@
}
}
- /**
- * Injectable instance to create a new EdgeBackGestureHandler.
- *
- * Necessary because we don't have good handling of per-display contexts at the moment. With
- * this, you can pass in a specific context that knows what display it is in.
- */
- public static class Factory {
- private final OverviewProxyService mOverviewProxyService;
- private final SysUiState mSysUiState;
- private final PluginManager mPluginManager;
- private final UiThreadContext mUiThreadContext;
- private final Executor mBackgroundExecutor;
- private final Handler mBgHandler;
- private final UserTracker mUserTracker;
- private final NavigationModeController mNavigationModeController;
- private final BackPanelController.Factory mBackPanelControllerFactory;
- private final ViewConfiguration mViewConfiguration;
- private final WindowManager mWindowManager;
- private final IWindowManager mWindowManagerService;
- private final InputManager mInputManager;
- private final Optional<Pip> mPipOptional;
- private final Optional<DesktopMode> mDesktopModeOptional;
- private final FalsingManager mFalsingManager;
- private final Provider<BackGestureTfClassifierProvider>
- mBackGestureTfClassifierProviderProvider;
- private final Provider<LightBarController> mLightBarControllerProvider;
- private final NotificationShadeWindowController mNotificationShadeWindowController;
-
- private final GestureInteractor mGestureInteractor;
-
- private final JavaAdapter mJavaAdapter;
-
- @Inject
- public Factory(OverviewProxyService overviewProxyService,
- SysUiState sysUiState,
- PluginManager pluginManager,
- @BackPanelUiThread UiThreadContext uiThreadContext,
- @Background Executor backgroundExecutor,
- @Background Handler bgHandler,
- UserTracker userTracker,
- NavigationModeController navigationModeController,
- BackPanelController.Factory backPanelControllerFactory,
- ViewConfiguration viewConfiguration,
- WindowManager windowManager,
- IWindowManager windowManagerService,
- InputManager inputManager,
- Optional<Pip> pipOptional,
- Optional<DesktopMode> desktopModeOptional,
- FalsingManager falsingManager,
- Provider<BackGestureTfClassifierProvider>
- backGestureTfClassifierProviderProvider,
- Provider<LightBarController> lightBarControllerProvider,
- NotificationShadeWindowController notificationShadeWindowController,
- GestureInteractor gestureInteractor,
- JavaAdapter javaAdapter) {
- mOverviewProxyService = overviewProxyService;
- mSysUiState = sysUiState;
- mPluginManager = pluginManager;
- mUiThreadContext = uiThreadContext;
- mBackgroundExecutor = backgroundExecutor;
- mBgHandler = bgHandler;
- mUserTracker = userTracker;
- mNavigationModeController = navigationModeController;
- mBackPanelControllerFactory = backPanelControllerFactory;
- mViewConfiguration = viewConfiguration;
- mWindowManager = windowManager;
- mWindowManagerService = windowManagerService;
- mInputManager = inputManager;
- mPipOptional = pipOptional;
- mDesktopModeOptional = desktopModeOptional;
- mFalsingManager = falsingManager;
- mBackGestureTfClassifierProviderProvider = backGestureTfClassifierProviderProvider;
- mLightBarControllerProvider = lightBarControllerProvider;
- mNotificationShadeWindowController = notificationShadeWindowController;
- mGestureInteractor = gestureInteractor;
- mJavaAdapter = javaAdapter;
- }
-
- /** Construct a {@link EdgeBackGestureHandler}. */
- public EdgeBackGestureHandler create(Context context) {
- return mUiThreadContext.runWithScissors(
- () -> new EdgeBackGestureHandler(
- context,
- mOverviewProxyService,
- mSysUiState,
- mPluginManager,
- mUiThreadContext,
- mBackgroundExecutor,
- mBgHandler,
- mUserTracker,
- mNavigationModeController,
- mBackPanelControllerFactory,
- mViewConfiguration,
- mWindowManager,
- mWindowManagerService,
- mInputManager,
- mPipOptional,
- mDesktopModeOptional,
- mFalsingManager,
- mBackGestureTfClassifierProviderProvider,
- mLightBarControllerProvider,
- mNotificationShadeWindowController,
- mGestureInteractor,
- mJavaAdapter));
- }
- }
-
private static class LogArray extends ArrayDeque<String> {
private final int mLength;