Commit 9f8158c1 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

VR: Ensure we remove black overlay if VR is exited while entering.

This fixes a failure mode where we shutdownVR after handling the VR NFC
broadcast, and fail to properly cancel VR entry.

Also does some other random cleanup of comments/visibility.

Bug: 862829
Change-Id: Ic382692d7255aa5893391a602a6c949b4b4d498b
Reviewed-on: https://chromium-review.googlesource.com/1138726Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575388}
parent 96753422
...@@ -16,19 +16,15 @@ import org.chromium.chrome.browser.modaldialog.ModalDialogView; ...@@ -16,19 +16,15 @@ import org.chromium.chrome.browser.modaldialog.ModalDialogView;
* This class implements a VrAlertDialog which is similar to Android AlertDialog in VR. * This class implements a VrAlertDialog which is similar to Android AlertDialog in VR.
*/ */
public class VrAlertDialog extends AlertDialog { public class VrAlertDialog extends AlertDialog {
private VrDialogManager mVrDialogManager;
private ModalDialogManager mModalDialogManager; private ModalDialogManager mModalDialogManager;
private ModalDialogView mModalDialogView; private ModalDialogView mModalDialogView;
private boolean mIsShowing;
private CharSequence mMessage; private CharSequence mMessage;
private DialogButton mButtonPositive; private DialogButton mButtonPositive;
private DialogButton mButtonNegative; private DialogButton mButtonNegative;
protected View mView; protected View mView;
public VrAlertDialog(Context context, VrDialogManager vrDialogManager, public VrAlertDialog(Context context, ModalDialogManager modalDialogManager) {
ModalDialogManager modalDialogManager) {
super(context); super(context);
mVrDialogManager = vrDialogManager;
mModalDialogManager = modalDialogManager; mModalDialogManager = modalDialogManager;
} }
...@@ -60,7 +56,6 @@ public class VrAlertDialog extends AlertDialog { ...@@ -60,7 +56,6 @@ public class VrAlertDialog extends AlertDialog {
public void show() { public void show() {
mModalDialogView = createView(); mModalDialogView = createView();
mModalDialogManager.showDialog(mModalDialogView, ModalDialogManager.APP_MODAL); mModalDialogManager.showDialog(mModalDialogView, ModalDialogManager.APP_MODAL);
mIsShowing = true;
} }
/** /**
...@@ -103,7 +98,6 @@ public class VrAlertDialog extends AlertDialog { ...@@ -103,7 +98,6 @@ public class VrAlertDialog extends AlertDialog {
*/ */
@Override @Override
public void dismiss() { public void dismiss() {
mIsShowing = false;
mModalDialogManager.cancelDialog(mModalDialogView); mModalDialogManager.cancelDialog(mModalDialogView);
} }
......
...@@ -24,8 +24,6 @@ public class VrFirstRunActivity extends Activity { ...@@ -24,8 +24,6 @@ public class VrFirstRunActivity extends Activity {
private static final BooleanHistogramSample sFreNotCompleteBrowserHistogram = private static final BooleanHistogramSample sFreNotCompleteBrowserHistogram =
new BooleanHistogramSample("VRFreNotComplete.Browser"); new BooleanHistogramSample("VRFreNotComplete.Browser");
private static final BooleanHistogramSample sFreNotCompleteAutopresentHistogram =
new BooleanHistogramSample("VRFreNotComplete.WebVRAutopresent");
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
......
...@@ -42,6 +42,7 @@ import org.chromium.base.ContextUtils; ...@@ -42,6 +42,7 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.PackageUtils; import org.chromium.base.PackageUtils;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryLoader;
...@@ -206,6 +207,7 @@ public class VrShellDelegate ...@@ -206,6 +207,7 @@ public class VrShellDelegate
private static final List<VrModeObserver> sVrModeObservers = new ArrayList<>(); private static final List<VrModeObserver> sVrModeObservers = new ArrayList<>();
@VisibleForTesting
protected boolean mTestWorkaroundDontCancelVrEntryOnResume; protected boolean mTestWorkaroundDontCancelVrEntryOnResume;
private long mNativeVrShellDelegate; private long mNativeVrShellDelegate;
...@@ -906,7 +908,7 @@ public class VrShellDelegate ...@@ -906,7 +908,7 @@ public class VrShellDelegate
} }
/** /**
* @return Whether or not VR is supported on this platform. * @return Whether or not VR is enabled in this build.
*/ */
/* package */ static boolean isVrEnabled() { /* package */ static boolean isVrEnabled() {
return getVrClassesWrapper() != null; return getVrClassesWrapper() != null;
...@@ -1042,8 +1044,8 @@ public class VrShellDelegate ...@@ -1042,8 +1044,8 @@ public class VrShellDelegate
// If an activity isn't resumed at the point, it must have been paused. // If an activity isn't resumed at the point, it must have been paused.
mPaused = ApplicationStatus.getStateForActivity(activity) != ActivityState.RESUMED; mPaused = ApplicationStatus.getStateForActivity(activity) != ActivityState.RESUMED;
mVisible = activity.hasWindowFocus(); mVisible = activity.hasWindowFocus();
updateVrSupportLevel(null);
mNativeVrShellDelegate = nativeInit(); mNativeVrShellDelegate = nativeInit();
updateVrSupportLevel(null);
mFeedbackFrequency = VrFeedbackStatus.getFeedbackFrequency(); mFeedbackFrequency = VrFeedbackStatus.getFeedbackFrequency();
ensureLifecycleObserverInitialized(); ensureLifecycleObserverInitialized();
if (!mPaused) onResume(); if (!mPaused) onResume();
...@@ -1159,6 +1161,7 @@ public class VrShellDelegate ...@@ -1159,6 +1161,7 @@ public class VrShellDelegate
buttonText, null, true); buttonText, null, true);
} }
@VisibleForTesting
protected boolean isVrBrowsingEnabled() { protected boolean isVrBrowsingEnabled() {
return isVrBrowsingEnabled(mActivity, getVrSupportLevel()); return isVrBrowsingEnabled(mActivity, getVrSupportLevel());
} }
...@@ -1215,16 +1218,11 @@ public class VrShellDelegate ...@@ -1215,16 +1218,11 @@ public class VrShellDelegate
} }
private void enterVr(final boolean tentativeWebVrMode) { private void enterVr(final boolean tentativeWebVrMode) {
// We can't enter VR before the application resumes, or we encounter bizarre crashes // We should only enter VR when we're the resumed Activity or our changes to things like
// related to gpu surfaces. // system UI flags might get lost.
// TODO(mthiesse): Is the above comment still accurate? It may have been tied to our HTML
// UI which is gone.
assert !mPaused; assert !mPaused;
assert mNativeVrShellDelegate != 0;
if (mInVr) return; if (mInVr) return;
if (mNativeVrShellDelegate == 0) {
cancelPendingVrEntry();
return;
}
mInVr = true; mInVr = true;
setVrModeEnabled(mActivity, true); setVrModeEnabled(mActivity, true);
...@@ -1244,11 +1242,11 @@ public class VrShellDelegate ...@@ -1244,11 +1242,11 @@ public class VrShellDelegate
mExitedDueToUnsupportedMode = false; mExitedDueToUnsupportedMode = false;
addVrViews(); addVrViews();
boolean webVrMode = mRequestedWebVr || tentativeWebVrMode;
// Make sure that assets component is registered when creating native VR shell. // Make sure that assets component is registered when creating native VR shell.
if (!sRegisteredVrAssetsComponent) { if (!sRegisteredVrAssetsComponent) {
registerVrAssetsComponentIfDaydreamUser(isDaydreamCurrentViewer()); registerVrAssetsComponentIfDaydreamUser(isDaydreamCurrentViewer());
} }
boolean webVrMode = mRequestedWebVr || tentativeWebVrMode;
mVrShell.initializeNative(webVrMode, getVrClassesWrapper().bootsToVr()); mVrShell.initializeNative(webVrMode, getVrClassesWrapper().bootsToVr());
mVrShell.setWebVrModeEnabled(webVrMode); mVrShell.setWebVrModeEnabled(webVrMode);
...@@ -1290,6 +1288,9 @@ public class VrShellDelegate ...@@ -1290,6 +1288,9 @@ public class VrShellDelegate
// Nothing to do if we were launched by an internal intent. // Nothing to do if we were launched by an internal intent.
if (mInternalIntentUsedToStartVr) { if (mInternalIntentUsedToStartVr) {
mInternalIntentUsedToStartVr = false; mInternalIntentUsedToStartVr = false;
// This is extremely unlikely in practice. Some code must have called shutdownVR() while
// we were entering VR through NFC insertion.
if (!mDonSucceeded) cancelPendingVrEntry();
return; return;
} }
...@@ -1544,6 +1545,7 @@ public class VrShellDelegate ...@@ -1544,6 +1545,7 @@ public class VrShellDelegate
return true; return true;
} }
@VisibleForTesting
protected void onResume() { protected void onResume() {
if (DEBUG_LOGS) Log.i(TAG, "onResume"); if (DEBUG_LOGS) Log.i(TAG, "onResume");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) return; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) return;
...@@ -1664,7 +1666,7 @@ public class VrShellDelegate ...@@ -1664,7 +1666,7 @@ public class VrShellDelegate
if (mInVr) mVrShell.pause(); if (mInVr) mVrShell.pause();
} }
protected void onPause() { private void onPause() {
if (DEBUG_LOGS) Log.i(TAG, "onPause"); if (DEBUG_LOGS) Log.i(TAG, "onPause");
mPaused = true; mPaused = true;
if (mCancellingEntryAnimation) return; if (mCancellingEntryAnimation) return;
...@@ -1755,13 +1757,9 @@ public class VrShellDelegate ...@@ -1755,13 +1757,9 @@ public class VrShellDelegate
mShowingDaydreamDoff = false; mShowingDaydreamDoff = false;
if (mShowingDoffForGvrUpdate) { if (mShowingDoffForGvrUpdate) mShowVrServicesUpdatePrompt = success;
mShowVrServicesUpdatePrompt = success;
}
if (success) { if (success) shutdownVr(true /* disableVrMode */, true /* stayingInChrome */);
shutdownVr(true /* disableVrMode */, true /* stayingInChrome */);
}
callOnExitVrRequestListener(success); callOnExitVrRequestListener(success);
mShowingDoffForGvrUpdate = false; mShowingDoffForGvrUpdate = false;
...@@ -1778,8 +1776,7 @@ public class VrShellDelegate ...@@ -1778,8 +1776,7 @@ public class VrShellDelegate
@CalledByNative @CalledByNative
private void setListeningForWebVrActivate(boolean listening) { private void setListeningForWebVrActivate(boolean listening) {
if (DEBUG_LOGS) Log.i(TAG, "WebVR page listening for vrdisplayactivate: " + listening); if (DEBUG_LOGS) Log.i(TAG, "WebVR page listening for vrdisplayactivate: " + listening);
// Non-Daydream devices may not have the concept of display activate. So disable // Non-Daydream devices do not have the concept of activation.
// mListeningForWebVrActivate for them.
if (getVrSupportLevel() != VrSupportLevel.VR_DAYDREAM) return; if (getVrSupportLevel() != VrSupportLevel.VR_DAYDREAM) return;
if (mListeningForWebVrActivate == listening) return; if (mListeningForWebVrActivate == listening) return;
mListeningForWebVrActivate = listening; mListeningForWebVrActivate = listening;
...@@ -1824,7 +1821,7 @@ public class VrShellDelegate ...@@ -1824,7 +1821,7 @@ public class VrShellDelegate
/** /**
* Exits VR Shell, performing all necessary cleanup. * Exits VR Shell, performing all necessary cleanup.
*/ */
protected void shutdownVr(boolean disableVrMode, boolean stayingInChrome) { private void shutdownVr(boolean disableVrMode, boolean stayingInChrome) {
if (DEBUG_LOGS) Log.i(TAG, "shuttdown VR"); if (DEBUG_LOGS) Log.i(TAG, "shuttdown VR");
cancelPendingVrEntry(); cancelPendingVrEntry();
...@@ -1941,11 +1938,13 @@ public class VrShellDelegate ...@@ -1941,11 +1938,13 @@ public class VrShellDelegate
GVR_KEYBOARD_UPDATE_RESULT); GVR_KEYBOARD_UPDATE_RESULT);
} }
@VisibleForTesting
protected boolean canLaunch2DIntentsInternal() { protected boolean canLaunch2DIntentsInternal() {
return getVrClassesWrapper().supports2dInVr() return getVrClassesWrapper().supports2dInVr()
&& !sVrModeEnabledActivitys.contains(sInstance.mActivity); && !sVrModeEnabledActivitys.contains(sInstance.mActivity);
} }
@VisibleForTesting
protected boolean createVrShell() { protected boolean createVrShell() {
assert mVrShell == null; assert mVrShell == null;
if (getVrClassesWrapper() == null) return false; if (getVrClassesWrapper() == null) return false;
...@@ -1972,6 +1971,7 @@ public class VrShellDelegate ...@@ -1972,6 +1971,7 @@ public class VrShellDelegate
mActivity.onEnterVr(); mActivity.onEnterVr();
} }
@VisibleForTesting
protected boolean isBlackOverlayVisible() { protected boolean isBlackOverlayVisible() {
View overlay = mActivity.getWindow().findViewById(R.id.vr_overlay_view); View overlay = mActivity.getWindow().findViewById(R.id.vr_overlay_view);
return overlay != null; return overlay != null;
...@@ -1997,6 +1997,7 @@ public class VrShellDelegate ...@@ -1997,6 +1997,7 @@ public class VrShellDelegate
/** /**
* @param api The VrDaydreamApi object this delegate will use instead of the default one * @param api The VrDaydreamApi object this delegate will use instead of the default one
*/ */
@VisibleForTesting
protected void overrideDaydreamApi(VrDaydreamApi api) { protected void overrideDaydreamApi(VrDaydreamApi api) {
sVrDaydreamApi = api; sVrDaydreamApi = api;
} }
...@@ -2004,6 +2005,7 @@ public class VrShellDelegate ...@@ -2004,6 +2005,7 @@ public class VrShellDelegate
/** /**
* @return The VrShell for the VrShellDelegate instance * @return The VrShell for the VrShellDelegate instance
*/ */
@VisibleForTesting
protected VrShell getVrShell() { protected VrShell getVrShell() {
return mVrShell; return mVrShell;
} }
...@@ -2011,6 +2013,7 @@ public class VrShellDelegate ...@@ -2011,6 +2013,7 @@ public class VrShellDelegate
/** /**
* @param versionChecker The VrCoreVersionChecker object this delegate will use * @param versionChecker The VrCoreVersionChecker object this delegate will use
*/ */
@VisibleForTesting
protected void overrideVrCoreVersionChecker(VrCoreVersionChecker versionChecker) { protected void overrideVrCoreVersionChecker(VrCoreVersionChecker versionChecker) {
sVrCoreVersionChecker = versionChecker; sVrCoreVersionChecker = versionChecker;
updateVrSupportLevel(null); updateVrSupportLevel(null);
...@@ -2019,24 +2022,30 @@ public class VrShellDelegate ...@@ -2019,24 +2022,30 @@ public class VrShellDelegate
/** /**
* @param frequency Sets how often to show the feedback prompt. * @param frequency Sets how often to show the feedback prompt.
*/ */
@VisibleForTesting
protected void setFeedbackFrequency(int frequency) { protected void setFeedbackFrequency(int frequency) {
mFeedbackFrequency = frequency; mFeedbackFrequency = frequency;
} }
@VisibleForTesting
protected boolean isListeningForWebVrActivate() { protected boolean isListeningForWebVrActivate() {
return mListeningForWebVrActivate; return mListeningForWebVrActivate;
} }
@VisibleForTesting
protected boolean isVrEntryComplete() { protected boolean isVrEntryComplete() {
return mInVr && !mProbablyInDon; return mInVr && !mProbablyInDon;
} }
@VisibleForTesting
protected boolean isShowingDoff() { protected boolean isShowingDoff() {
return mShowingDaydreamDoff; return mShowingDaydreamDoff;
} }
@VisibleForTesting
protected void onBroadcastReceived() {} protected void onBroadcastReceived() {}
@VisibleForTesting
protected void setExpectingIntent(boolean expectingIntent) {} protected void setExpectingIntent(boolean expectingIntent) {}
/** /**
......
...@@ -12,7 +12,6 @@ import android.widget.TextView; ...@@ -12,7 +12,6 @@ import android.widget.TextView;
/** /**
* This class implements a Toast which is similar to Android Toast in VR. * This class implements a Toast which is similar to Android Toast in VR.
*/ */
public class VrToast extends android.widget.Toast { public class VrToast extends android.widget.Toast {
private VrToastManager mVrToastManager; private VrToastManager mVrToastManager;
......
...@@ -36,7 +36,7 @@ public class VrUiWidgetFactory extends UiWidgetFactory { ...@@ -36,7 +36,7 @@ public class VrUiWidgetFactory extends UiWidgetFactory {
@Override @Override
public AlertDialog createAlertDialog(Context context) { public AlertDialog createAlertDialog(Context context) {
return new VrAlertDialog(context, mVrShell, mModalDialogManager); return new VrAlertDialog(context, mModalDialogManager);
} }
@Override @Override
......
...@@ -48,11 +48,6 @@ public class TestVrShellDelegate extends VrShellDelegate { ...@@ -48,11 +48,6 @@ public class TestVrShellDelegate extends VrShellDelegate {
return TestVrShellDelegate.getInstance().getVrShell(); return TestVrShellDelegate.getInstance().getVrShell();
} }
@Override
public void shutdownVr(boolean disableVrMode, boolean stayingInChrome) {
super.shutdownVr(disableVrMode, stayingInChrome);
}
public void overrideDaydreamApiForTesting(VrDaydreamApi api) { public void overrideDaydreamApiForTesting(VrDaydreamApi api) {
super.overrideDaydreamApi(api); super.overrideDaydreamApi(api);
} }
......
...@@ -69,8 +69,7 @@ public class TransitionUtils { ...@@ -69,8 +69,7 @@ public class TransitionUtils {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
VrShellDelegateUtils.getDelegateInstance().shutdownVr( VrShellDelegate.forceExitVrImmediately();
true /* disableVrMode */, true /* stayingInChrome */);
} }
}); });
} }
......
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