Commit dc55fd14 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

VR: Use isInVrSession API to keep Chrome in VR until user has left VR

This fixes the Daydream Dashboard issues so that if Chrome is simply
stopped/started in VR without any intents, Chrome stays in VR.

Also makes resuming Chrome from DD home way faster if Chrome was
already in VR.

Bug: 780887
Change-Id: Iab7f713bfc5b85972f908ea141e3b495297d7286
Reviewed-on: https://chromium-review.googlesource.com/944547Reviewed-by: default avatarYash Malik <ymalik@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540403}
parent 2183758a
......@@ -77,6 +77,12 @@ public interface VrDaydreamApi {
*/
Intent setupVrIntent(Intent intent);
/**
* Whether the user is currently in a VR session. Note that this should be treated as heuristic,
* and may at times be wrong.
*/
boolean isInVrSession();
/**
* Closes this DaydreamApi instance.
*/
......
......@@ -134,6 +134,11 @@ public class VrDaydreamApiImpl implements VrDaydreamApi {
return DaydreamApi.setupVrIntent(intent);
}
@Override
public boolean isInVrSession() {
return DaydreamApi.isInVrSession(mContext);
}
@Override
public void close() {
if (mDaydreamApi == null) return;
......
......@@ -971,16 +971,16 @@ public class VrShellDelegate
}
private void onVrIntent() {
mNeedsAnimationCancel = true;
mInVrAtChromeLaunch = true;
if (mInVr) return;
mNeedsAnimationCancel = true;
mEnterVrOnStartup = true;
// TODO(mthiesse): Assuming we've gone through DON flow saves ~2 seconds on VR entry. See
// the comments in enterVr(). This may not always be the case in the future, but for now
// it's a reasonable assumption.
mDonSucceeded = true;
mInVrAtChromeLaunch = true;
if (!mPaused) enterVrAfterDon();
}
......@@ -1362,24 +1362,23 @@ public class VrShellDelegate
});
}
mCancellingEntryAnimation = false;
if (mEnterVrOnStartup) {
// This means that Chrome was started with a VR intent, so we should enter VR.
// TODO(crbug.com/776235): VR intents are dispatched to ChromeActivity via a launcher
// which should handle the DON flow to simplify the logic in VrShellDelegate.
assert !mProbablyInDon;
if (DEBUG_LOGS) Log.i(TAG, "onResume: entering VR mode for VR intent");
mCancellingEntryAnimation = false;
if (enterVrInternal() == ENTER_VR_CANCELLED) {
cancelPendingVrEntry();
}
} else if (mDonSucceeded) {
mCancellingEntryAnimation = false;
handleDonFlowSuccess();
} else {
if (mProbablyInDon) {
// This means the user backed out of the DON flow, and we won't be entering VR.
maybeSetPresentResult(false, mDonSucceeded);
shutdownVr(true, false);
}
// If we were resumed at the wrong density, we need to trigger activity recreation.
......@@ -1426,10 +1425,6 @@ public class VrShellDelegate
// are safe.
if (mInVr) mVrShell.pause();
if (mShowingDaydreamDoff || mProbablyInDon) return;
// TODO(mthiesse): When the user resumes Chrome in a 2D context, we don't want to tear down
// VR UI, so for now, exit VR.
shutdownVr(true /* disableVrMode */, false /* stayingInChrome */);
}
protected void onPause() {
......@@ -1440,10 +1435,6 @@ public class VrShellDelegate
unregisterDaydreamIntent(mVrDaydreamApi);
if (mVrSupportLevel == VrSupportLevel.VR_NOT_AVAILABLE) return;
// TODO(ymalik): We should be able to remove this if we handle it for multi-window in
// {@link onMultiWindowModeChanged} since we're calling it in onStop.
if (!mInVr && !mProbablyInDon) cancelPendingVrEntry();
// When the active web page has a vrdisplayactivate event handler,
// mListeningForWebVrActivate should be set to true, which means a vrdisplayactive event
// should be fired once DON flow finished. However, DON flow will pause our activity,
......@@ -1462,12 +1453,12 @@ public class VrShellDelegate
private void onStart() {
mStopped = false;
if (mDonSucceeded) setWindowModeForVr();
if (mInVr && !mVrDaydreamApi.isInVrSession()) shutdownVr(true, false);
}
private void onStop() {
if (DEBUG_LOGS) Log.i(TAG, "onStop");
mStopped = true;
if (!mProbablyInDon) cancelPendingVrEntry();
assert !mCancellingEntryAnimation;
}
......
......@@ -100,4 +100,9 @@ public class MockVrDaydreamApi implements VrDaydreamApi {
public void setForwardSetupIntent(boolean forward) {
mForwardSetupIntent = forward;
}
@Override
public boolean isInVrSession() {
return true;
}
}
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