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

VR: Turn VR mode off when restoring Activity from saved instance.

When Chrome is killed in the background while VR mode is on, we can't
turn VR mode off (the platform doesn't respect VR mode changes for
backgrounded apps).

We also can't check whether VR mode is currently on on Android N, so
instead this CL records whether we were in VR mode when killed using
saved instance state, and turns VR mode off on startup when restoring.

Test/Repro steps:
1. Turn on "Don't keep activities" in developer settings
2. Launch Chrome in VR
3. Press the Daydream controller Home button
4. Exit VR
5. Use task switcher to return to Chrome.

> Chrome should resume without VR mode on (the display will flicker
if it's on)

Bug: 854740
Change-Id: I4fc8e9c076a8cb31ca2bdb74be1124bec3826193
Reviewed-on: https://chromium-review.googlesource.com/1167116
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581957}
parent 8b90885e
...@@ -318,11 +318,7 @@ public abstract class ChromeActivity extends AsyncInitializationActivity ...@@ -318,11 +318,7 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
public void preInflationStartup() { public void preInflationStartup() {
super.preInflationStartup(); super.preInflationStartup();
// We need to explicitly enable VR mode here so that the system doesn't kick us out of VR, VrModuleProvider.getDelegate().doPreInflationStartup(this, getSavedInstanceState());
// or drop us into the 2D-in-VR rendering mode, while we prepare for VR rendering.
if (VrModuleProvider.getIntentDelegate().isLaunchingIntoVr(this, getIntent())) {
VrModuleProvider.getDelegate().setVrModeEnabled(this, true);
}
// Force a partner customizations refresh if it has yet to be initialized. This can happen // Force a partner customizations refresh if it has yet to be initialized. This can happen
// if Chrome is killed and you refocus a previous activity from Android recents, which does // if Chrome is killed and you refocus a previous activity from Android recents, which does
...@@ -1196,6 +1192,12 @@ public abstract class ChromeActivity extends AsyncInitializationActivity ...@@ -1196,6 +1192,12 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
return super.getOnCreateTimestampMs(); return super.getOnCreateTimestampMs();
} }
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
VrModuleProvider.getDelegate().onSaveInstanceState(outState);
}
/** /**
* This cannot be overridden in order to preserve destruction order. Override * This cannot be overridden in order to preserve destruction order. Override
* {@link #onDestroyInternal()} instead to perform clean up tasks. * {@link #onDestroyInternal()} instead to perform clean up tasks.
......
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.vr; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.vr;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
...@@ -34,8 +35,10 @@ public interface VrDelegate { ...@@ -34,8 +35,10 @@ public interface VrDelegate {
void onNewIntentWithNative(ChromeActivity activity, Intent intent); void onNewIntentWithNative(ChromeActivity activity, Intent intent);
void maybeHandleVrIntentPreNative(ChromeActivity activity, Intent intent); void maybeHandleVrIntentPreNative(ChromeActivity activity, Intent intent);
void setVrModeEnabled(Activity activity, boolean enabled); void setVrModeEnabled(Activity activity, boolean enabled);
void doPreInflationStartup(ChromeActivity activity, Bundle savedInstanceState);
boolean bootsToVr(); boolean bootsToVr();
boolean isDaydreamReadyDevice(); boolean isDaydreamReadyDevice();
boolean isDaydreamCurrentViewer(); boolean isDaydreamCurrentViewer();
boolean willChangeDensityInVr(ChromeActivity activity); boolean willChangeDensityInVr(ChromeActivity activity);
void onSaveInstanceState(Bundle outState);
} }
...@@ -107,6 +107,9 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -107,6 +107,9 @@ import org.chromium.chrome.browser.ChromeActivity;
assert false; assert false;
} }
@Override
public void doPreInflationStartup(ChromeActivity activity, Bundle savedInstanceState) {}
@Override @Override
public boolean bootsToVr() { public boolean bootsToVr() {
return false; return false;
...@@ -149,4 +152,7 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -149,4 +152,7 @@ import org.chromium.chrome.browser.ChromeActivity;
assert false; assert false;
return false; return false;
} }
@Override
public void onSaveInstanceState(Bundle outState) {}
} }
...@@ -128,6 +128,11 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -128,6 +128,11 @@ import org.chromium.chrome.browser.ChromeActivity;
VrShellDelegate.setVrModeEnabled(activity, enabled); VrShellDelegate.setVrModeEnabled(activity, enabled);
} }
@Override
public void doPreInflationStartup(ChromeActivity activity, Bundle savedInstanceState) {
VrShellDelegate.doPreInflationStartup(activity, savedInstanceState);
}
@Override @Override
public boolean bootsToVr() { public boolean bootsToVr() {
return VrShellDelegate.bootsToVr(); return VrShellDelegate.bootsToVr();
...@@ -167,4 +172,9 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -167,4 +172,9 @@ import org.chromium.chrome.browser.ChromeActivity;
public boolean willChangeDensityInVr(ChromeActivity activity) { public boolean willChangeDensityInVr(ChromeActivity activity) {
return VrShellDelegate.willChangeDensityInVr(activity); return VrShellDelegate.willChangeDensityInVr(activity);
} }
@Override
public void onSaveInstanceState(Bundle outState) {
VrShellDelegate.onSaveInstanceState(outState);
}
} }
...@@ -144,6 +144,9 @@ public class VrShellDelegate ...@@ -144,6 +144,9 @@ public class VrShellDelegate
private static final String VR_BOOT_SYSTEM_PROPERTY = "ro.boot.vr"; private static final String VR_BOOT_SYSTEM_PROPERTY = "ro.boot.vr";
/** ID for SavedInstanceState Bundle for whether Chrome was in VR when killed. */
private static final String IN_VR = "in_vr";
private static VrShellDelegate sInstance; private static VrShellDelegate sInstance;
private static VrBroadcastReceiver sVrBroadcastReceiver; private static VrBroadcastReceiver sVrBroadcastReceiver;
private static VrLifecycleObserver sVrLifecycleObserver; private static VrLifecycleObserver sVrLifecycleObserver;
...@@ -664,6 +667,30 @@ public class VrShellDelegate ...@@ -664,6 +667,30 @@ public class VrShellDelegate
} }
} }
/**
* Performs pre-inflation VR-related startup.
*/
public static void doPreInflationStartup(ChromeActivity activity, Bundle savedInstanceState) {
// We need to explicitly enable VR mode here so that the system doesn't kick us out of VR,
// or drop us into the 2D-in-VR rendering mode, while we prepare for VR rendering.
if (VrIntentUtils.isLaunchingIntoVr(activity, activity.getIntent())) {
setVrModeEnabled(activity, true);
} else if (savedInstanceState != null && savedInstanceState.getBoolean(IN_VR, false)) {
// When Chrome is restored from a SavedInstanceState with VR mode still on we need to
// Explicitly turn VR mode off even though we can't really know for sure whether or not
// it's currently on.
AndroidCompat.setVrModeEnabled(activity, false);
sVrModeEnabledActivitys.remove(activity);
}
}
/**
* See {@link Activity#onSaveInstanceState(Bundle)}
*/
public static void onSaveInstanceState(Bundle outState) {
if (isInVr()) outState.putBoolean(IN_VR, true);
}
/** /**
* See VrClassesWrapper#bootsToVr(). * See VrClassesWrapper#bootsToVr().
*/ */
......
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