Commit 8deb2011 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

VR: Prevent VR mode from being set on standalone VR devices.

VR is disabled on standalone devices, but the intent handling and
2D-in-VR support paths don't account for this and erroneously turn on
VR mode, or try to launch Chrome in VR, leaving the user stuck on a
black screen.

This CL ensures that we never set VR mode on standalone devices, and
forward VR intents back to the 2D launcher on these devices.

Change-Id: I3f8d41f66549f4c24e3056253299c10486f468df
Reviewed-on: https://chromium-review.googlesource.com/1003112
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarYash Malik <ymalik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549898}
parent d458cc58
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.vr; package org.chromium.chrome.browser.vr;
import android.app.Activity; import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -39,7 +40,19 @@ public class VrMainActivity extends Activity { ...@@ -39,7 +40,19 @@ public class VrMainActivity extends Activity {
try { try {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (!VrShellDelegate.isDaydreamReadyDevice()) { // TODO(mthiesse, https://crbug.com/831175): Support WebVR launches on standalone VR
// devices.
if (!VrShellDelegate.deviceSupportsVrLaunches()) {
// If the device doesn't support VR launches, forward the intent back to the 2D
// launcher. We should only get here on standalone VR devices, or from bad intents
// probably sent by testers.
VrIntentUtils.removeVrExtras(getIntent());
getIntent().setComponent(null);
getIntent().setPackage(getPackageName());
// Daydream drops the MAIN action for unknown reasons...
if (getIntent().getAction() == null) getIntent().setAction(Intent.ACTION_MAIN);
startActivity(getIntent());
finish(); finish();
return; return;
} }
......
...@@ -179,7 +179,7 @@ public class VrIntentUtils { ...@@ -179,7 +179,7 @@ public class VrIntentUtils {
*/ */
public static boolean maybeForwardToVrLauncher(Intent intent, Activity activity) { public static boolean maybeForwardToVrLauncher(Intent intent, Activity activity) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) return false; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) return false;
if (wouldUse2DInVrRenderingMode(activity)) { if (wouldUse2DInVrRenderingMode(activity) && VrShellDelegate.deviceSupportsVrLaunches()) {
Intent vrIntent = new Intent(intent); Intent vrIntent = new Intent(intent);
vrIntent.setComponent(null); vrIntent.setComponent(null);
vrIntent.setPackage(activity.getPackageName()); vrIntent.setPackage(activity.getPackageName());
...@@ -214,7 +214,7 @@ public class VrIntentUtils { ...@@ -214,7 +214,7 @@ public class VrIntentUtils {
/** /**
* Removes VR specific extras from the given intent to make it a non-VR intent. * Removes VR specific extras from the given intent to make it a non-VR intent.
*/ */
/* package */ static void removeVrExtras(Intent intent) { public static void removeVrExtras(Intent intent) {
if (intent == null) return; if (intent == null) return;
intent.removeCategory(DAYDREAM_CATEGORY); intent.removeCategory(DAYDREAM_CATEGORY);
assert !isVrIntent(intent); assert !isVrIntent(intent);
......
...@@ -655,7 +655,10 @@ public class VrShellDelegate ...@@ -655,7 +655,10 @@ public class VrShellDelegate
*/ */
public static void maybeHandleVrIntentPreNative(ChromeActivity activity, Intent intent) { public static void maybeHandleVrIntentPreNative(ChromeActivity activity, Intent intent) {
if (!VrIntentUtils.isVrIntent(intent)) { if (!VrIntentUtils.isVrIntent(intent)) {
if (!VrIntentUtils.wouldUse2DInVrRenderingMode(activity)) return; if (!VrIntentUtils.wouldUse2DInVrRenderingMode(activity)
|| !deviceSupportsVrLaunches()) {
return;
}
// This is to handle intents that are sent directly to ChromeActivitys, bypassing the // This is to handle intents that are sent directly to ChromeActivitys, bypassing the
// launcher. // launcher.
intent.addCategory(VrIntentUtils.DAYDREAM_CATEGORY); intent.addCategory(VrIntentUtils.DAYDREAM_CATEGORY);
...@@ -689,7 +692,7 @@ public class VrShellDelegate ...@@ -689,7 +692,7 @@ public class VrShellDelegate
*/ */
public static void setVrModeEnabled(Activity activity, boolean enabled) { public static void setVrModeEnabled(Activity activity, boolean enabled) {
VrClassesWrapper wrapper = getVrClassesWrapper(); VrClassesWrapper wrapper = getVrClassesWrapper();
if (wrapper == null) return; if (wrapper == null || wrapper.bootsToVr()) return;
ensureLifecycleObserverInitialized(); ensureLifecycleObserverInitialized();
if (enabled) { if (enabled) {
if (sVrModeEnabledActivitys.contains(activity)) return; if (sVrModeEnabledActivitys.contains(activity)) return;
...@@ -864,6 +867,10 @@ public class VrShellDelegate ...@@ -864,6 +867,10 @@ public class VrShellDelegate
return getVrClassesWrapper() != null && getVrClassesWrapper().isDaydreamReadyDevice(); return getVrClassesWrapper() != null && getVrClassesWrapper().isDaydreamReadyDevice();
} }
public static boolean deviceSupportsVrLaunches() {
return isDaydreamReadyDevice() && !getVrClassesWrapper().bootsToVr();
}
// TODO(mthiesse): Should have package visibility only. We need to unify our vr and vr_shell // TODO(mthiesse): Should have package visibility only. We need to unify our vr and vr_shell
// packages. // packages.
public static boolean willChangeDensityInVr(ChromeActivity activity) { public static boolean willChangeDensityInVr(ChromeActivity activity) {
...@@ -930,7 +937,7 @@ public class VrShellDelegate ...@@ -930,7 +937,7 @@ public class VrShellDelegate
* @return Whether or not VR is supported on this platform. * @return Whether or not VR is supported on this platform.
*/ */
/* package */ static boolean isVrEnabled() { /* package */ static boolean isVrEnabled() {
return getVrClassesWrapper() != null; return getVrClassesWrapper() != null && !getVrClassesWrapper().bootsToVr();
} }
private static void addBlackOverlayViewForActivity(ChromeActivity activity) { private static void addBlackOverlayViewForActivity(ChromeActivity activity) {
......
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