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

Android: Stop accessing BrowserControlsManager on destroyed Activity

There are several classes accessing BrowserControlsManager on Chrome-
Activity already (being) destroyed. These are abnormal situations
where previously BCM has never been instantiated.

Rather than letting the flow go through and an exception be thrown,
this CL adds the check against the state of the Activity before
getting BrowserControlsManager, to prevent the crash in all the reported
cases.

Bug: 990987
Change-Id: I5fb26495c80af471eeef1929573bd9ede8d3bd09
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2326551Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793479}
parent 0d8ebfb1
......@@ -98,7 +98,7 @@ public class AutofillAssistantFacade {
waitForTabWithWebContents(activity, tab -> {
AutofillAssistantModuleEntryProvider.INSTANCE.getModuleEntry(
tab, (moduleEntry) -> {
if (moduleEntry == null) {
if (moduleEntry == null || activity.isActivityFinishingOrDestroyed()) {
AutofillAssistantMetrics.recordDropOut(
DropOutReason.DFM_INSTALL_FAILED);
return;
......
......@@ -1128,7 +1128,7 @@ public class ChromeTabbedActivity extends ChromeActivity<ChromeActivityComponent
mPendingInitialTabCreation = true;
PartnerBrowserCustomizations.getInstance().setOnInitializeAsyncFinished(() -> {
createInitialTab();
if (!isActivityFinishingOrDestroyed()) createInitialTab();
}, INITIAL_TAB_CREATION_TIMEOUT_MS);
}
} finally {
......
......@@ -150,6 +150,9 @@ public class RevampedContextMenuCoordinator implements ContextMenuUi {
mListView.setOnItemClickListener((p, v, pos, id) -> {
assert id != INVALID_ITEM_ID;
// Do not start any action when the activity is on the way to destruction.
// See https://crbug.com/990987
if (activity.isFinishing() || activity.isDestroyed()) return;
onItemClicked.onResult((int) id);
mDialog.dismiss();
});
......
......@@ -224,7 +224,8 @@ public class PictureInPictureController {
}
};
activity.getFullscreenManager().addObserver(fullscreenListener);
FullscreenManager fullscreenManager = activity.getFullscreenManager();
fullscreenManager.addObserver(fullscreenListener);
activityTab.addObserver(tabObserver);
tabModelSelector.addObserver(tabModelSelectorObserver);
webContents.addObserver(webContentsObserver);
......@@ -235,7 +236,7 @@ public class PictureInPictureController {
activityTab.removeObserver(tabObserver);
tabModelSelector.removeObserver(tabModelSelectorObserver);
webContents.removeObserver(webContentsObserver);
activity.getFullscreenManager().removeObserver(fullscreenListener);
fullscreenManager.removeObserver(fullscreenListener);
}
});
......
......@@ -65,7 +65,10 @@ class TabViewManagerImpl implements TabViewManager, Comparator<TabViewProvider>
}
private void initMarginSupplier() {
if (mTab.getActivity() == null || mMarginSupplier != null) return;
if (mTab.getActivity() == null || mTab.getActivity().isActivityFinishingOrDestroyed()
|| mMarginSupplier != null) {
return;
}
mMarginSupplier =
new BrowserControlsMarginSupplier(mTab.getActivity().getBrowserControlsManager());
......
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