Commit e81f3ae3 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Prevent accessing BottomSheetController after destruction

With https://crrev.com/c/1898161, HistoryNavigationDelegate returns
nulled-out BottomSheetController when the activity is already destroyed.
All the public methods of NavigationSheetCoordinator should take it
into account and early out in any calls to them when it is detected.

Bug: 1022285
Change-Id: I605a136f73c4e33ac880142321c3205b12eff940
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1906846
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713911}
parent b4ede666
...@@ -195,6 +195,8 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet ...@@ -195,6 +195,8 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
@Override @Override
public boolean startAndExpand(boolean forward, boolean animate) { public boolean startAndExpand(boolean forward, boolean animate) {
// Called from activity for navigation popup. No need to check
// bottom sheet controller since it is guaranteed to available.
start(forward, /* showCloseIndicator= */ false); start(forward, /* showCloseIndicator= */ false);
mOpenedAsPopup = true; mOpenedAsPopup = true;
...@@ -242,6 +244,7 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet ...@@ -242,6 +244,7 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
@Override @Override
public void close(boolean animate) { public void close(boolean animate) {
if (mBottomSheetController.get() == null) return;
if (!isHidden()) mBottomSheetController.get().hideContent(this, animate); if (!isHidden()) mBottomSheetController.get().hideContent(this, animate);
mBottomSheetController.get().removeObserver(mSheetObserver); mBottomSheetController.get().removeObserver(mSheetObserver);
mMediator.clear(); mMediator.clear();
...@@ -309,7 +312,9 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet ...@@ -309,7 +312,9 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
@Override @Override
public int getPeekHeight() { public int getPeekHeight() {
if (mOpenedAsPopup) return BottomSheetContent.HeightMode.DISABLED; if (mBottomSheetController.get() == null || mOpenedAsPopup) {
return BottomSheetContent.HeightMode.DISABLED;
}
// Makes peek state as 'not present' when bottom sheet is in expanded state (i.e. animating // Makes peek state as 'not present' when bottom sheet is in expanded state (i.e. animating
// from expanded to close state). It avoids the sheet animating in two distinct steps, which // from expanded to close state). It avoids the sheet animating in two distinct steps, which
// looks awkward. // looks awkward.
......
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