Commit 38456c37 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

VR: Prevent crash from double-removing black overlay.

The static member variable to keep track of whether the black overlay
is added can fail when we switch Activities while entering VR when the
black overlay is added.

In practice without other bugs this should be borderline impossible to
make happen, but it crops up now and again, like in the linked bug.

We should instead just track the overlay per-activity.

Bug: 850741
Change-Id: I8849786972f216d7b628e2c8938579261ecd66b6
Reviewed-on: https://chromium-review.googlesource.com/1091699Reviewed-by: default avatarBiao She <bshe@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565639}
parent 0cd00af0
......@@ -150,7 +150,6 @@ public class VrShellDelegate
private static VrCoreVersionChecker sVrCoreVersionChecker;
private static Set<Activity> sVrModeEnabledActivitys = new HashSet<>();
private static boolean sRegisteredDaydreamHook;
private static boolean sAddedBlackOverlayView;
private static boolean sRegisteredVrAssetsComponent;
private static Boolean sIconComponentEnabled;
......@@ -962,22 +961,20 @@ public class VrShellDelegate
}
private static void addBlackOverlayViewForActivity(ChromeActivity activity) {
if (sAddedBlackOverlayView) return;
View overlay = activity.getWindow().findViewById(R.id.vr_overlay_view);
if (overlay != null) return;
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
View v = new View(activity);
v.setId(R.id.vr_overlay_view);
v.setBackgroundColor(Color.BLACK);
activity.getWindow().addContentView(v, params);
sAddedBlackOverlayView = true;
}
private static void removeBlackOverlayView(ChromeActivity activity) {
if (!sAddedBlackOverlayView) return;
View v = activity.getWindow().findViewById(R.id.vr_overlay_view);
assert v != null;
UiUtils.removeViewFromParent(v);
sAddedBlackOverlayView = false;
View overlay = activity.getWindow().findViewById(R.id.vr_overlay_view);
if (overlay == null) return;
UiUtils.removeViewFromParent(overlay);
}
private static boolean isVrCoreCompatible(final Tab tabToShowInfobarIn) {
......
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