From bbafc6d79d89d9763ea1a4a27038c4b2b3bc405f Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Mon, 7 Apr 2025 12:44:29 +0100 Subject: [PATCH] Inject and use WindowContext in RotationTouchHelper - Provides a per-display instance of WindowContext to avoid creation of Context - Inject WindowContext instead of ApplicaitonContext in RotationTouchHelper to have a display associated context required by ScreenDecorationsUtils, as well as being able to have updated Resources upon configuration changes Bug: 407878199 Test: Verified mWindowContexxt.resources.configuration is updated upon fold/unfold/rotate, Flag: EXEMPT refactor Change-Id: Ic032ae3c8c818b150f5e6fca0d531a19ad38986b --- .../launcher3/dagger/PerDisplayModule.kt | 35 +++++++++++++++++-- .../quickstep/RotationTouchHelper.java | 34 ++++++++---------- .../launcher3/dagger/WindowContext.java | 32 +++++++++++++++++ 3 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 src/com/android/launcher3/dagger/WindowContext.java diff --git a/quickstep/src/com/android/launcher3/dagger/PerDisplayModule.kt b/quickstep/src/com/android/launcher3/dagger/PerDisplayModule.kt index 0d3fd24608..54438c007d 100644 --- a/quickstep/src/com/android/launcher3/dagger/PerDisplayModule.kt +++ b/quickstep/src/com/android/launcher3/dagger/PerDisplayModule.kt @@ -21,6 +21,7 @@ import android.hardware.display.DisplayManager import android.os.Handler import android.util.Log import android.view.Display.DEFAULT_DISPLAY +import android.view.WindowManager.LayoutParams.TYPE_APPLICATION import com.android.app.displaylib.DisplayLibBackground import com.android.app.displaylib.DisplayLibComponent import com.android.app.displaylib.DisplayRepository @@ -94,20 +95,48 @@ object PerDisplayRepositoriesModule { @Provides fun provideRotationTouchHandlerRepo( repositoryFactory: PerDisplayInstanceRepositoryImpl.Factory, + @WindowContext windowContextRepository: PerDisplayRepository, instanceFactory: RotationTouchHelper.Factory, - displayRepository: DisplayRepository, ): PerDisplayRepository { return if (enableOverviewOnConnectedDisplays()) { repositoryFactory.create( "RotationTouchHelperRepo", { displayId -> - displayRepository.getDisplay(displayId)?.let { instanceFactory.create(it) } + windowContextRepository[displayId]?.let { instanceFactory.create(it) } }, ) } else { SingleInstanceRepositoryImpl( "RotationTouchHelperRepo", - instanceFactory.create(displayRepository.getDisplay(DEFAULT_DISPLAY)), + instanceFactory.create(windowContextRepository[DEFAULT_DISPLAY]), + ) + } + } + + @Provides + @WindowContext + fun provideWindowContext( + repositoryFactory: PerDisplayInstanceRepositoryImpl.Factory, + @ApplicationContext context: Context, + displayRepository: DisplayRepository, + ): PerDisplayRepository { + return if (enableOverviewOnConnectedDisplays()) { + repositoryFactory.create( + "WindowContextRepo", + { displayId -> + displayRepository.getDisplay(displayId)?.let { + context.createWindowContext(it, TYPE_APPLICATION, /* options= */ null) + } + }, + ) + } else { + SingleInstanceRepositoryImpl( + "WindowContextRepo", + context.createWindowContext( + displayRepository.getDisplay(DEFAULT_DISPLAY)!!, + TYPE_APPLICATION, + /* options = */ null, + ), ) } } diff --git a/quickstep/src/com/android/quickstep/RotationTouchHelper.java b/quickstep/src/com/android/quickstep/RotationTouchHelper.java index 739d022a1e..78d2c9ceae 100644 --- a/quickstep/src/com/android/quickstep/RotationTouchHelper.java +++ b/quickstep/src/com/android/quickstep/RotationTouchHelper.java @@ -29,12 +29,11 @@ import static com.android.launcher3.util.NavigationMode.THREE_BUTTONS; import android.content.Context; import android.content.res.Resources; -import android.view.Display; import android.view.MotionEvent; import android.view.OrientationEventListener; import com.android.app.displaylib.PerDisplayRepository; -import com.android.launcher3.dagger.ApplicationContext; +import com.android.launcher3.dagger.WindowContext; import com.android.launcher3.testing.shared.TestProtocol; import com.android.launcher3.util.DaggerSingletonObject; import com.android.launcher3.util.DaggerSingletonTracker; @@ -49,12 +48,12 @@ import com.android.systemui.shared.system.QuickStepContract; import com.android.systemui.shared.system.TaskStackChangeListener; import com.android.systemui.shared.system.TaskStackChangeListeners; -import java.io.PrintWriter; - import dagger.assisted.Assisted; import dagger.assisted.AssistedFactory; import dagger.assisted.AssistedInject; +import java.io.PrintWriter; + /** * Helper class for transforming touch events */ @@ -134,31 +133,28 @@ public class RotationTouchHelper implements DisplayInfoChangeListener { */ private boolean mInOverview; private boolean mTaskListFrozen; - private final Context mApplicationContext; - private final Context mDisplayContext; + private final Context mWindowContext; @AssistedInject - RotationTouchHelper(@ApplicationContext Context context, + RotationTouchHelper(@Assisted Context windowContext, DisplayController displayController, SystemUiProxy systemUiProxy, - DaggerSingletonTracker lifeCycle, - @Assisted Display display) { - mApplicationContext = context; + DaggerSingletonTracker lifeCycle) { + mWindowContext = windowContext; mDisplayController = displayController; mSystemUiProxy = systemUiProxy; - mDisplayContext = mApplicationContext.createDisplayContext(display); - mDisplayId = display.getDisplayId(); + mDisplayId = windowContext.getDisplayId(); - Resources resources = mApplicationContext.getResources(); + Resources resources = mWindowContext.getResources(); mOrientationTouchTransformer = new OrientationTouchTransformer(resources, mMode, - () -> QuickStepContract.getWindowCornerRadius(mDisplayContext)); + () -> QuickStepContract.getWindowCornerRadius(mWindowContext)); // Register for navigation mode and rotation changes mDisplayController.addChangeListenerForDisplay(this, mDisplayId); DisplayController.Info info = mDisplayController.getInfoForDisplay(mDisplayId); - onDisplayInfoChanged(context, info, CHANGE_ALL); + onDisplayInfoChanged(windowContext, info, CHANGE_ALL); - mOrientationListener = new OrientationEventListener(mApplicationContext) { + mOrientationListener = new OrientationEventListener(mWindowContext) { @Override public void onOrientationChanged(int degrees) { int newRotation = RecentsOrientedState.getRotationForUserDegreesRotated(degrees, @@ -266,7 +262,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener { NavigationMode newMode = info.getNavigationMode(); mOrientationTouchTransformer.setNavigationMode(newMode, mDisplayController.getInfoForDisplay(mDisplayId), - mApplicationContext.getResources()); + mWindowContext.getResources()); TaskStackChangeListeners.getInstance() .unregisterTaskStackListener(mFrozenTaskListener); @@ -288,7 +284,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener { void setGesturalHeight(int newGesturalHeight) { mOrientationTouchTransformer.setGesturalHeight( newGesturalHeight, mDisplayController.getInfoForDisplay(mDisplayId), - mApplicationContext.getResources()); + mWindowContext.getResources()); } /** @@ -399,6 +395,6 @@ public class RotationTouchHelper implements DisplayInfoChangeListener { @AssistedFactory public interface Factory { /** Creates a new instance of [RotationTouchHelper] for a given [display]. */ - RotationTouchHelper create(Display display); + RotationTouchHelper create(@WindowContext Context context); } } diff --git a/src/com/android/launcher3/dagger/WindowContext.java b/src/com/android/launcher3/dagger/WindowContext.java new file mode 100644 index 0000000000..d5d53f4f41 --- /dev/null +++ b/src/com/android/launcher3/dagger/WindowContext.java @@ -0,0 +1,32 @@ +/* + * 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 java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.inject.Qualifier; + +/** + * Qualifier for Launcher application context. + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Qualifier +public @interface WindowContext { +}