| Index: chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java
|
| index d16b4d45d162d6deac6b87e0479de233bc6a4e5d..7908aa6e91e324f58620cfb3297d5acd699d2611 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/vr_shell/VrShellDelegate.java
|
| @@ -393,7 +393,6 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
|
| if (mPaused) {
|
| // We can't enter VR before the application resumes, or we encounter bizarre crashes
|
| // related to gpu surfaces. Set this flag to enter VR on the next resume.
|
| - setWindowModeForVr();
|
| mEnteringVr = true;
|
| } else {
|
| enterVR();
|
| @@ -405,7 +404,7 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
|
| if (mNativeVrShellDelegate == 0) return;
|
| if (mInVr) return;
|
| if (!isWindowModeCorrectForVr()) {
|
| - setWindowModeForVr();
|
| + setWindowModeForVr(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
| new Handler().post(new Runnable() {
|
| @Override
|
| public void run() {
|
| @@ -416,14 +415,14 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
|
| }
|
| mEnteringVr = false;
|
| if (!createVrShell()) {
|
| - if (mRestoreOrientation != null) mActivity.setRequestedOrientation(mRestoreOrientation);
|
| - mRestoreOrientation = null;
|
| - clearVrModeWindowFlags();
|
| + restoreWindowMode();
|
| setEnterVRResult(false);
|
| return;
|
| }
|
| mVrClassesWrapper.setVrModeEnabled(mActivity, true);
|
| mInVr = true;
|
| + // Lock orientation to landscape after enter VR.
|
| + mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
|
| addVrViews();
|
| mVrShell.initializeNative(mActivity.getActivityTab(), mRequestedWebVR);
|
| @@ -437,7 +436,9 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
|
|
|
| @Override
|
| public void onSystemUiVisibilityChange(int visibility) {
|
| - if (mInVr && !isWindowModeCorrectForVr()) setWindowModeForVr();
|
| + if (mInVr && !isWindowModeCorrectForVr()) {
|
| + setWindowModeForVr(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
| + }
|
| }
|
|
|
| private boolean isWindowModeCorrectForVr() {
|
| @@ -446,14 +447,20 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
|
| return flags == VR_SYSTEM_UI_FLAGS && orientation == Configuration.ORIENTATION_LANDSCAPE;
|
| }
|
|
|
| - private void setWindowModeForVr() {
|
| + private void setWindowModeForVr(int requestedOrientation) {
|
| if (mRestoreOrientation == null) {
|
| mRestoreOrientation = mActivity.getRequestedOrientation();
|
| }
|
| - mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
| + mActivity.setRequestedOrientation(requestedOrientation);
|
| setupVrModeWindowFlags();
|
| }
|
|
|
| + private void restoreWindowMode() {
|
| + if (mRestoreOrientation != null) mActivity.setRequestedOrientation(mRestoreOrientation);
|
| + mRestoreOrientation = null;
|
| + clearVrModeWindowFlags();
|
| + }
|
| +
|
| private void setEnterVRResult(boolean success) {
|
| if (mRequestedWebVR) nativeSetPresentResult(mNativeVrShellDelegate, success);
|
| if (!success && !mVrDaydreamApi.exitFromVr(EXIT_VR_RESULT, new Intent())) {
|
| @@ -531,7 +538,12 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
|
| // due to the lack of support for unexported activities.
|
| enterVR();
|
| } else {
|
| + // LANDSCAPE orientation is needed before we can safely enter VR. DON can make sure that
|
| + // the device is at LANDSCAPE orientation once it is finished. So here we use SENSOR to
|
| + // avoid forcing LANDSCAPE orientation in order to have a smoother transition.
|
| + setWindowModeForVr(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
|
| if (!mVrDaydreamApi.launchInVr(getEnterVRPendingIntent(mVrDaydreamApi, mActivity))) {
|
| + restoreWindowMode();
|
| return ENTER_VR_CANCELLED;
|
| }
|
| }
|
| @@ -570,6 +582,7 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
|
| // If this is still set, it means the user backed out of the DON flow, and we won't be
|
| // receiving an intent from daydream.
|
| nativeSetPresentResult(mNativeVrShellDelegate, false);
|
| + restoreWindowMode();
|
| mRequestedWebVR = false;
|
| }
|
|
|
| @@ -681,11 +694,9 @@ public class VrShellDelegate implements ApplicationStatus.ActivityStateListener,
|
| mVrClassesWrapper.setVrModeEnabled(mActivity, false);
|
| mLastVRExit = SystemClock.uptimeMillis();
|
| }
|
| - if (mRestoreOrientation != null) mActivity.setRequestedOrientation(mRestoreOrientation);
|
| - mRestoreOrientation = null;
|
| + restoreWindowMode();
|
| mVrShell.pause();
|
| removeVrViews();
|
| - clearVrModeWindowFlags();
|
| destroyVrShell();
|
| mActivity.getFullscreenManager().setPositionsForTabToNonFullscreen();
|
| }
|
|
|