Ignore rotations while the view is not yet attached

Fixes: 191227230
Test: atest SystemUITests

Change-Id: I813d631fd3a5ccf98010f5a114e702208839714e
This commit is contained in:
Winson Chung
2021-07-26 20:48:10 -07:00
parent ae5d3b43ae
commit 08fcb4dc9a
2 changed files with 7 additions and 2 deletions

View File

@@ -597,6 +597,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
} }
public void destroyView() { public void destroyView() {
setAutoHideController(/* autoHideController */ null);
mCommandQueue.removeCallback(this); mCommandQueue.removeCallback(this);
mContext.getSystemService(WindowManager.class).removeViewImmediate( mContext.getSystemService(WindowManager.class).removeViewImmediate(
mNavigationBarView.getRootView()); mNavigationBarView.getRootView());
@@ -919,6 +920,11 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
@Override @Override
public void onRotationProposal(final int rotation, boolean isValid) { public void onRotationProposal(final int rotation, boolean isValid) {
// The CommandQueue callbacks are added when the view is created to ensure we track other
// states, but until the view is attached (at the next traversal), the view's display is
// not valid. Just ignore the rotation in this case.
if (!mNavigationBarView.isAttachedToWindow()) return;
final int winRotation = mNavigationBarView.getDisplay().getRotation(); final int winRotation = mNavigationBarView.getDisplay().getRotation();
final boolean rotateSuggestionsDisabled = RotationButtonController final boolean rotateSuggestionsDisabled = RotationButtonController
.hasDisable2RotateSuggestionFlag(mDisabledFlags2); .hasDisable2RotateSuggestionFlag(mDisabledFlags2);
@@ -1484,7 +1490,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
} }
/** Sets {@link AutoHideController} to the navigation bar. */ /** Sets {@link AutoHideController} to the navigation bar. */
public void setAutoHideController(AutoHideController autoHideController) { private void setAutoHideController(AutoHideController autoHideController) {
mAutoHideController = autoHideController; mAutoHideController = autoHideController;
if (mAutoHideController != null) { if (mAutoHideController != null) {
mAutoHideController.setNavigationBar(mAutoHideUiElement); mAutoHideController.setNavigationBar(mAutoHideUiElement);

View File

@@ -402,7 +402,6 @@ public class NavigationBarController implements Callbacks,
void removeNavigationBar(int displayId) { void removeNavigationBar(int displayId) {
NavigationBar navBar = mNavigationBars.get(displayId); NavigationBar navBar = mNavigationBars.get(displayId);
if (navBar != null) { if (navBar != null) {
navBar.setAutoHideController(/* autoHideController */ null);
navBar.destroyView(); navBar.destroyView();
mNavigationBars.remove(displayId); mNavigationBars.remove(displayId);
} }