Commit 05e112bc authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Fix NPE in gesture navigation.

We evaluate gesture navigation enabled status every time Chrome app is
resumed in order to deal with the system gesture navigation mode
change while the app was in background. When testing, the parent view
(CompositorViewHolder) is always in attached state when the activity
is resumed, but it can happen that it is in detached state as reported
in the bug. This caused an exception, since WindowInsets will be null
in that state.

This CL skips the check if the state is queried while the view is
detached from its window. The only scenario that could potentially
be affected is when user switched the system gesture navigation on
the settings and resume the app later. But experiment shows that
this re-creates ChromeActivity and attaches the views before
resuming, and the mode change rarely happens in the field. So the
change is not likely to be risky.

Bug: 1045942
Change-Id: I7ac11796737b1f355786c65f309182b107c39f20
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2029547Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737552}
parent 7f6020b3
......@@ -148,7 +148,10 @@ public class HistoryNavigationCoordinator implements InsetObserverView.WindowIns
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
return true;
} else {
assert mCompositorViewHolder.isAttachedToWindow();
// Preserve the previous enabled status if queried when the view is in detached state.
if (mCompositorViewHolder == null || !mCompositorViewHolder.isAttachedToWindow()) {
return mEnabled;
}
Insets insets = mCompositorViewHolder.getRootWindowInsets().getSystemGestureInsets();
return insets.left == 0 && insets.right == 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment