From 3f6c3e134fb4887a660e71c10d6c09cd48d354c8 Mon Sep 17 00:00:00 2001 From: Vinit Nayak Date: Mon, 26 Apr 2021 15:15:18 -0700 Subject: [PATCH] Initialize RotationTouchHelper with RecentsAnimationDeviceState ctor Added logs to debug why multiple instances of RotationTouchHelper are being created to begin with. Ran labtest on CF, passes. Fixes: 177316094 Change-Id: Ibb980980c61965f456a84a9d85a72ec4ec6e0b19 --- .../OrientationTouchTransformer.java | 38 ++++++++++--- .../RecentsAnimationDeviceState.java | 20 ++++++- .../quickstep/RotationTouchHelper.java | 56 +++++++++++++++---- .../quickstep/TouchInteractionService.java | 4 +- 4 files changed, 95 insertions(+), 23 deletions(-) diff --git a/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java b/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java index 2a6e478461..c47300cd5f 100644 --- a/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java +++ b/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java @@ -92,7 +92,7 @@ class OrientationTouchTransformer { }; private static final String TAG = "OrientationTouchTransformer"; - private static final boolean DEBUG = false; + private static final boolean DEBUG = true; private static final int QUICKSTEP_ROTATION_UNINITIALIZED = -1; @@ -163,6 +163,10 @@ class OrientationTouchTransformer { void setNavigationMode(SysUINavigationMode.Mode newMode, Info info, Resources newRes) { + if (DEBUG) { + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "setNavigationMode new: " + newMode + + " oldMode: " + mMode + " " + this); + } if (mMode == newMode) { return; } @@ -254,10 +258,18 @@ class OrientationTouchTransformer { mCurrentDisplay = new CurrentDisplay(region.realSize, region.rotation); OrientationRectF regionToKeep = mSwipeTouchRegions.get(mCurrentDisplay); + if (DEBUG) { + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "cached region: " + regionToKeep + + " mCurrentDisplay: " + mCurrentDisplay + " " + this); + } if (regionToKeep == null) { regionToKeep = createRegionForDisplay(region); } mSwipeTouchRegions.clear(); + if (DEBUG) { + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "adding region: " + regionToKeep + + " mCurrentDisplay: " + mCurrentDisplay + " " + this); + } mSwipeTouchRegions.put(mCurrentDisplay, regionToKeep); updateAssistantRegions(regionToKeep); } @@ -273,7 +285,8 @@ class OrientationTouchTransformer { private OrientationRectF createRegionForDisplay(Info display) { if (DEBUG) { - Log.d(TAG, "creating rotation region for: " + mCurrentDisplay.rotation); + Log.d(TAG, "creating rotation region for: " + mCurrentDisplay.rotation + + " with mode: " + mMode + " displayRotation: " + display.rotation); } Point size = display.realSize; @@ -287,14 +300,19 @@ class OrientationTouchTransformer { } else { mAssistantLeftRegion.setEmpty(); mAssistantRightRegion.setEmpty(); + int navbarSize = getNavbarSize(ResourceUtils.NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE); + if (DEBUG) { + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "else case mode: " + mMode + + " getNavbarSize: " + navbarSize + " rotation: " + rotation + " " + this); + } switch (rotation) { case Surface.ROTATION_90: orientationRectF.left = orientationRectF.right - - getNavbarSize(ResourceUtils.NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE); + - navbarSize; break; case Surface.ROTATION_270: orientationRectF.right = orientationRectF.left - + getNavbarSize(ResourceUtils.NAVBAR_LANDSCAPE_LEFT_RIGHT_SIZE); + + navbarSize; break; default: orientationRectF.top = orientationRectF.bottom - touchHeight; @@ -339,7 +357,7 @@ class OrientationTouchTransformer { boolean touchInValidSwipeRegions(float x, float y) { if (TestProtocol.sDebugTracing) { Log.d(TestProtocol.NO_SWIPE_TO_HOME, "touchInValidSwipeRegions " + x + "," + y + " in " - + mLastRectTouched); + + mLastRectTouched + " this: " + this); } if (mLastRectTouched != null) { return mLastRectTouched.contains(x, y); @@ -462,7 +480,8 @@ class OrientationTouchTransformer { if (DEBUG) { Log.d(TAG, "Transforming rotation due to forceTransform, " + "mCurrentRotation: " + mCurrentDisplay.rotation - + "mRotation: " + mRotation); + + "mRotation: " + mRotation + + " this: " + this); } event.transform(mTmpMatrix); return true; @@ -473,9 +492,10 @@ class OrientationTouchTransformer { if (DEBUG) { Log.d(TAG, "original: " + event.getX() + ", " + event.getY() - + " new: " + mTmpPoint[0] + ", " + mTmpPoint[1] - + " rect: " + this + " forceTransform: " + forceTransform - + " contains: " + contains(mTmpPoint[0], mTmpPoint[1])); + + " new: " + mTmpPoint[0] + ", " + mTmpPoint[1] + + " rect: " + this + " forceTransform: " + forceTransform + + " contains: " + contains(mTmpPoint[0], mTmpPoint[1]) + + " this: " + this); } if (contains(mTmpPoint[0], mTmpPoint[1])) { diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java index b4f13307a4..ef09957c9d 100644 --- a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java +++ b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java @@ -54,6 +54,7 @@ import android.os.UserManager; import android.provider.Settings; import android.text.TextUtils; import android.util.DisplayMetrics; +import android.util.Log; import android.view.MotionEvent; import android.view.Surface; @@ -61,6 +62,7 @@ import androidx.annotation.BinderThread; import com.android.launcher3.R; import com.android.launcher3.Utilities; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener; import com.android.launcher3.util.DisplayController.Info; @@ -127,14 +129,27 @@ public class RecentsAnimationDeviceState implements private boolean mIsUserSetupComplete; public RecentsAnimationDeviceState(Context context) { + this(context, false); + } + + /** + * @param isInstanceForTouches {@code true} if this is the persistent instance being used for + * gesture touch handling + */ + public RecentsAnimationDeviceState(Context context, boolean isInstanceForTouches) { mContext = context; mDisplayController = DisplayController.INSTANCE.get(context); mSysUiNavMode = SysUINavigationMode.INSTANCE.get(context); mDisplayId = mDisplayController.getInfo().id; mIsOneHandedModeSupported = SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false); runOnDestroy(() -> mDisplayController.removeChangeListener(this)); - mRotationTouchHelper = new RotationTouchHelper(context, mDisplayController); - runOnDestroy(mRotationTouchHelper::destroy); + mRotationTouchHelper = RotationTouchHelper.INSTANCE.get(context); + if (isInstanceForTouches) { + // rotationTouchHelper doesn't get initialized after being destroyed, so only destroy + // if primary TouchInteractionService instance needs to be destroyed. + mRotationTouchHelper.init(); + runOnDestroy(mRotationTouchHelper::destroy); + } // Register for user unlocked if necessary mIsUserUnlocked = context.getSystemService(UserManager.class) @@ -214,6 +229,7 @@ public class RecentsAnimationDeviceState implements * Cleans up all the registered listeners and receivers. */ public void destroy() { + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "destroying RADS", new Throwable()); for (Runnable r : mOnDestroyActions) { r.run(); } diff --git a/quickstep/src/com/android/quickstep/RotationTouchHelper.java b/quickstep/src/com/android/quickstep/RotationTouchHelper.java index f4688a1dc1..fd0de4212f 100644 --- a/quickstep/src/com/android/quickstep/RotationTouchHelper.java +++ b/quickstep/src/com/android/quickstep/RotationTouchHelper.java @@ -24,6 +24,7 @@ import static com.android.quickstep.SysUINavigationMode.Mode.THREE_BUTTONS; import android.content.Context; import android.content.res.Resources; +import android.util.Log; import android.view.MotionEvent; import android.view.OrientationEventListener; @@ -31,6 +32,7 @@ import com.android.launcher3.testing.TestProtocol; 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.quickstep.util.RecentsOrientedState; import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.QuickStepContract; @@ -43,10 +45,13 @@ public class RotationTouchHelper implements SysUINavigationMode.NavigationModeChangeListener, DisplayInfoChangeListener { - private final OrientationTouchTransformer mOrientationTouchTransformer; - private final DisplayController mDisplayController; - private final SysUINavigationMode mSysUiNavMode; - private final int mDisplayId; + public static final MainThreadInitializedObject INSTANCE = + new MainThreadInitializedObject<>(RotationTouchHelper::new); + + private OrientationTouchTransformer mOrientationTouchTransformer; + private DisplayController mDisplayController; + private SysUINavigationMode mSysUiNavMode; + private int mDisplayId; private int mDisplayRotation; private final ArrayList mOnDestroyActions = new ArrayList<>(); @@ -117,25 +122,46 @@ public class RotationTouchHelper implements */ private boolean mInOverview; private boolean mTaskListFrozen; - - private final Context mContext; - public RotationTouchHelper(Context context, DisplayController displayController) { + /** + * Keeps track of whether destroy has been called for this instance. Mainly used for TAPL tests + * where multiple instances of RotationTouchHelper are being created. b/177316094 + */ + private boolean mNeedsInit = true; + + private RotationTouchHelper(Context context) { mContext = context; - mDisplayController = displayController; + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "RotationTouchHelper ctor init? " + mNeedsInit + + " " + this); + if (mNeedsInit) { + init(); + } + } + + public void init() { + if (!mNeedsInit) { + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "Did not need init? " + " " + this); + return; + } + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "RotationTouchHelper init() " + this, + new Throwable()); + mDisplayController = DisplayController.INSTANCE.get(mContext); Resources resources = mContext.getResources(); - mSysUiNavMode = SysUINavigationMode.INSTANCE.get(context); + mSysUiNavMode = SysUINavigationMode.INSTANCE.get(mContext); mDisplayId = mDisplayController.getInfo().id; mOrientationTouchTransformer = new OrientationTouchTransformer(resources, mMode, () -> QuickStepContract.getWindowCornerRadius(resources)); // Register for navigation mode changes - onNavigationModeChanged(mSysUiNavMode.addModeChangeListener(this)); + SysUINavigationMode.Mode newMode = mSysUiNavMode.addModeChangeListener(this); + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "AddedModeChangeListener: " + this + + " currentMode: " + newMode); + onNavigationModeChanged(newMode); runOnDestroy(() -> mSysUiNavMode.removeModeChangeListener(this)); - mOrientationListener = new OrientationEventListener(context) { + mOrientationListener = new OrientationEventListener(mContext) { @Override public void onOrientationChanged(int degrees) { int newRotation = RecentsOrientedState.getRotationForUserDegreesRotated(degrees, @@ -154,6 +180,7 @@ public class RotationTouchHelper implements } } }; + mNeedsInit = false; } private void setupOrientationSwipeHandler() { @@ -176,9 +203,11 @@ public class RotationTouchHelper implements * Cleans up all the registered listeners and receivers. */ public void destroy() { + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "destroying " + this); for (Runnable r : mOnDestroyActions) { r.run(); } + mNeedsInit = true; } public boolean isTaskListFrozen() { @@ -223,6 +252,7 @@ public class RotationTouchHelper implements @Override public void onNavigationModeChanged(SysUINavigationMode.Mode newMode) { + Log.d(TestProtocol.NO_SWIPE_TO_HOME, "nav mode changed: " + newMode); mDisplayController.removeChangeListener(this); mDisplayController.addChangeListener(this); onDisplayInfoChanged(mContext, mDisplayController.getInfo(), CHANGE_ALL); @@ -374,4 +404,8 @@ public class RotationTouchHelper implements pw.println(" displayRotation=" + getDisplayRotation()); mOrientationTouchTransformer.dump(pw); } + + public OrientationTouchTransformer getOrientationTouchTransformer() { + return mOrientationTouchTransformer; + } } diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 18c0b7a1ef..4fc97702ed 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -300,7 +300,9 @@ public class TouchInteractionService extends Service implements PluginListener