Force initialize task stack callback for gesture modes on init

This handles an edge case where RotationTouchHelper#mMode starts as 3 button (by default)
* then changes to gesture nav.
* then onDestroy called
* then on re-initialization mMode will be gesture nav instead of 3-button
(it maintains state because of it being singleton).

The check to register the callback won't happen because we register only if previous mode and
current mode differ.
Don't rely on default value of mMode being 3 button when initializing

Bug: 181928969
Test: Followed repo steps in bug.
Restarted phone in all 3 nav modes and verified
expected quickswitch behavior

Change-Id: I381eba7417c4cde593edf4b9a34da55b50774e98
This commit is contained in:
Vinit Nayak committed 2021-05-27 19:01:09 -07:00
1 parent 96793bdfe1
commit 23aa129016
1 file changed
+12 -3
@@ -152,7 +152,7 @@ public class RotationTouchHelper implements
// Register for navigation mode changes
SysUINavigationMode.Mode newMode = mSysUiNavMode.addModeChangeListener(this);
onNavigationModeChanged(newMode);
onNavModeChangedInternal(newMode, newMode.hasGestures);
runOnDestroy(() -> mSysUiNavMode.removeModeChangeListener(this));
mOrientationListener = new OrientationEventListener(mContext) {
@@ -245,13 +245,22 @@ public class RotationTouchHelper implements
@Override
public void onNavigationModeChanged(SysUINavigationMode.Mode newMode) {
onNavModeChangedInternal(newMode, false);
}
/**
* @param forceRegister if {@code true}, this will register {@link #mFrozenTaskListener} via
* {@link #setupOrientationSwipeHandler()}
*/
private void onNavModeChangedInternal(SysUINavigationMode.Mode newMode, boolean forceRegister) {
mDisplayController.removeChangeListener(this);
mDisplayController.addChangeListener(this);
onDisplayInfoChanged(mContext, mDisplayController.getInfo(), CHANGE_ALL);
mOrientationTouchTransformer.setNavigationMode(newMode, mDisplayController.getInfo(),
mContext.getResources());
if (!mMode.hasGestures && newMode.hasGestures) {
mContext.getResources());
if (forceRegister || (!mMode.hasGestures && newMode.hasGestures)) {
setupOrientationSwipeHandler();
} else if (mMode.hasGestures && !newMode.hasGestures){
destroyOrientationSwipeHandlerCallback();