Commit 73a5c4c7 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

VR: Avoid showing 2D UI when returning to Daydream Home

This moves the tearing down of VR UI into onStop instead of onPause.
However, this means we have to handle cases where Chrome pauses without
stopping while in VR. The only case I'm aware of where this is possible
is when the user enters multi-window mode while in VR.

(Even if there are other unhandled cases, the only problem is we keep
showing VR UI where we would prefer not to, and the user would have to
more explicitly exit VR)

Bug: 673528
Change-Id: Ia890875e1cf813b47443c4bb0883401506e6e55d
Reviewed-on: https://chromium-review.googlesource.com/527379
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarYash Malik <ymalik@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478701}
parent 2a35c6ab
......@@ -1758,6 +1758,8 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
MultiWindowUtils.getInstance().isInMultiWindowMode(this));
}
VrShellDelegate.onMultiWindowModeChanged(isInMultiWindowMode);
super.onMultiWindowModeChanged(isInMultiWindowMode);
}
......
......@@ -342,6 +342,13 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
unregisterDaydreamIntent(api);
}
public static void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
if (isInMultiWindowMode && isInVr()) {
sInstance.shutdownVr(
true /* disableVrMode */, false /* canReenter */, true /* stayingInChrome */);
}
}
@CalledByNative
private static VrShellDelegate getInstance() {
Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
......@@ -480,12 +487,12 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
if (activity == mActivity) destroy();
break;
case ActivityState.PAUSED:
if (activity == mActivity) pauseVr();
if (activity == mActivity) onPause();
// Other activities should only pause while we're paused due to Android lifecycle.
assert mPaused;
break;
case ActivityState.STOPPED:
if (activity == mActivity) cancelPendingVrEntry();
if (activity == mActivity) onStop();
break;
case ActivityState.RESUMED:
if (mInVr && activity != mActivity) {
......@@ -501,7 +508,7 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
}
if (!activitySupportsPresentation(activity)) return;
swapHostActivity((ChromeActivity) activity);
resumeVr();
onResume();
break;
default:
break;
......@@ -797,7 +804,7 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
return true;
}
private void resumeVr() {
private void onResume() {
mPaused = false;
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
......@@ -849,7 +856,7 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
}
}
private void pauseVr() {
private void onPause() {
mPaused = true;
unregisterDaydreamIntent(mVrDaydreamApi);
if (mVrSupportLevel == VR_NOT_AVAILABLE) return;
......@@ -867,16 +874,19 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
if (mNativeVrShellDelegate != 0) nativeOnPause(mNativeVrShellDelegate);
if (mShowingDaydreamDoff) {
mVrShell.pause();
return;
}
mIsDaydreamCurrentViewer = null;
}
private void onStop() {
cancelPendingVrEntry();
// We defer pausing of VrShell until the app is stopped to keep head tracking working for
// as long as possible while going to daydream home.
if (mInVr) mVrShell.pause();
if (mShowingDaydreamDoff) return;
// TODO(mthiesse): When VR Shell lives in its own activity, and integrates with Daydream
// home, pause instead of exiting VR here. For now, because VR Apps shouldn't show up in the
// non-VR recents, and we don't want ChromeTabbedActivity disappearing, exit VR.
// 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 */, true /* canReenter */, false /* stayingInChrome */);
mIsDaydreamCurrentViewer = null;
}
private boolean onBackPressedInternal() {
......
......@@ -110,6 +110,7 @@ public class VrShellImpl
private float mLastContentWidth;
private float mLastContentHeight;
private float mLastContentDpr;
private boolean mPaused;
private MotionEventSynthesizer mMotionEventSynthesizer;
......@@ -457,6 +458,8 @@ public class VrShellImpl
@Override
public void onResume() {
if (!mPaused) return;
mPaused = false;
super.onResume();
if (mNativeVrShell != 0) {
// Refreshing the viewer profile may accesses disk under some circumstances outside of
......@@ -472,6 +475,8 @@ public class VrShellImpl
@Override
public void onPause() {
if (mPaused) return;
mPaused = true;
super.onPause();
if (mNativeVrShell != 0) {
nativeOnPause(mNativeVrShell);
......
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