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
This commit is contained in:
Vinit Nayak committed 2021-04-26 15:17:07 -07:00
1 parent a7fc3ee4c7
commit 3f6c3e134f
4 files changed
+95 -23

No files matched your search

@@ -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<RotationTouchHelper> INSTANCE =
new MainThreadInitializedObject<>(RotationTouchHelper::new);
private OrientationTouchTransformer mOrientationTouchTransformer;
private DisplayController mDisplayController;
private SysUINavigationMode mSysUiNavMode;
private int mDisplayId;
private int mDisplayRotation;
private final ArrayList<Runnable> 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;
}
}