Commit 2d3158e3 authored by Yash Malik's avatar Yash Malik Committed by Commit Bot

VR: Exit to Daydream home if the vrcore on the user's device is out-of-date

In this CL, if we detect that a VR intent requires a VR core update, we simply
ignore it. This is needed because we may enter Chrome in VR mode but can't
do anything else (such as show a toast in VR), because we don't have the correct
version of gvr. The long term solution here is to have VrCore itself prompt the
user to upgrade.

Bug: 772514
Change-Id: I18b5a0ec11f4f68edfb408a71ce54c724e50cc3a
Reviewed-on: https://chromium-review.googlesource.com/797734
Commit-Queue: Yash Malik <ymalik@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarBiao She <bshe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520682}
parent b670fbd9
......@@ -225,6 +225,11 @@ public class LaunchIntentDispatcher implements IntentHandler.IntentHandlerDelega
return Action.FINISH_ACTIVITY;
}
// Ignore this VR intent if we can't handle it in Chrome.
if (mIsVrIntent && !VrIntentUtils.canHandleVrIntent(mActivity)) {
return Action.FINISH_ACTIVITY;
}
// Check if we should push the user through First Run.
if (FirstRunFlowSequencer.launch(mActivity, mIntent, false /* requiresBroadcast */,
false /* preferLightweightFre */)) {
......
......@@ -25,12 +25,18 @@ public class VrCoreVersionCheckerImpl implements VrCoreVersionChecker {
private static final String MIN_SDK_VERSION_PARAM_NAME = "min_sdk_version";
public VrCoreInfo getVrCoreInfo() {
int minSdkVersion = Build.VERSION_CODES.KITKAT;
// Supported Build version is determined by the webvr cardboard support feature.
// Default is KITKAT unless specified via server side finch config.
if (Build.VERSION.SDK_INT < ChromeFeatureList.getFieldTrialParamByFeatureAsInt(
ChromeFeatureList.WEBVR_CARDBOARD_SUPPORT,
MIN_SDK_VERSION_PARAM_NAME,
Build.VERSION_CODES.KITKAT)) {
// Note that this may be called before native initialization, in which case the callsite
// must be aware that we're using the lowest supported build version and not the one that's
// set in the origin trial.
if (ChromeFeatureList.isInitialized()) {
minSdkVersion = ChromeFeatureList.getFieldTrialParamByFeatureAsInt(
ChromeFeatureList.WEBVR_CARDBOARD_SUPPORT, MIN_SDK_VERSION_PARAM_NAME,
Build.VERSION_CODES.KITKAT);
}
if (Build.VERSION.SDK_INT < minSdkVersion) {
return new VrCoreInfo(null, VrCoreCompatibility.VR_NOT_SUPPORTED);
}
try {
......
......@@ -62,5 +62,5 @@ public interface VrDaydreamApi {
/**
* Launch the stereoscopic, 3D VR launcher homescreen.
*/
void launchVrHomescreen();
boolean launchVrHomescreen();
}
......@@ -105,10 +105,11 @@ public class VrDaydreamApiImpl implements VrDaydreamApi {
}
@Override
public void launchVrHomescreen() {
public boolean launchVrHomescreen() {
DaydreamApi daydreamApi = DaydreamApi.create(mContext);
if (daydreamApi == null) return;
if (daydreamApi == null) return false;
daydreamApi.launchVrHomescreen();
daydreamApi.close();
return true;
}
}
......@@ -33,6 +33,8 @@ public class VrIntentUtils {
/**
* Handles VR intent checking for VrShellDelegate.
* TODO(ymalik): There's no reason for this to be an interface, refactor
* into default implementation that tests can override.
*/
public interface VrIntentHandler {
/**
......@@ -49,6 +51,13 @@ public class VrIntentUtils {
* @return Whether the intent should be allowed to auto-present.
*/
boolean isTrustedAutopresentIntent(Intent intent);
/**
* Determines whether the installed version of Chrome can handle VR intents.
* @param context The context for the caller.
* @return Whether VR intents can be handled.
*/
boolean canHandleVrIntent(Context context);
}
private static VrIntentHandler createInternalVrIntentHandler() {
......@@ -69,6 +78,16 @@ public class VrIntentUtils {
return isTrustedDaydreamIntent(intent)
&& IntentUtils.safeGetBooleanExtra(intent, AUTOPRESENT_WEVBVR_EXTRA, false);
}
@Override
public boolean canHandleVrIntent(Context context) {
VrClassesWrapper wrapper = VrShellDelegate.getVrClassesWrapper();
if (wrapper == null) return false;
int supportLevel =
VrShellDelegate.getVrSupportLevel(wrapper.createVrDaydreamApi(context),
wrapper.createVrCoreVersionChecker(), null);
return supportLevel == VrShellDelegate.VR_DAYDREAM;
}
};
}
......@@ -115,6 +134,13 @@ public class VrIntentUtils {
&& getHandlerInstance().isTrustedDaydreamIntent(intent);
}
/**
* @return whether the installed version of Chrome can handle VR intents.
*/
public static boolean canHandleVrIntent(Context context) {
return getHandlerInstance().canHandleVrIntent(context);
}
/**
* This function returns an intent that will launch a VR activity that will prompt the
* user to take off their headset and foward the freIntent to the standard
......
......@@ -95,7 +95,8 @@ public class VrShellDelegate
private static final int VR_NOT_AVAILABLE = 0;
private static final int VR_CARDBOARD = 1;
private static final int VR_DAYDREAM = 2; // Supports both Cardboard and Daydream viewer.
/* package */
static final int VR_DAYDREAM = 2; // Supports both Cardboard and Daydream viewer.
@Retention(RetentionPolicy.SOURCE)
@IntDef({VR_NOT_AVAILABLE, VR_CARDBOARD, VR_DAYDREAM})
......@@ -894,7 +895,9 @@ public class VrShellDelegate
// We remove the VR-specific system UI flags here so that the system UI shows up properly
// when Chrome is resumed in non-VR mode.
mActivity.getWindow().getDecorView().setSystemUiVisibility(0);
mVrDaydreamApi.launchVrHomescreen();
boolean launched = mVrDaydreamApi.launchVrHomescreen();
assert launched;
// Some Samsung devices change the screen density after exiting VR mode which causes
// us to restart Chrome with the VR intent that originally started it. We don't want to
......@@ -922,6 +925,7 @@ public class VrShellDelegate
if (VrIntentUtils.getHandlerInstance().isTrustedDaydreamIntent(intent)) {
if (DEBUG_LOGS) Log.i(TAG, "onNewIntentWithNative: autopresent");
assert activitySupportsAutopresentation(activity);
assert instance.getVrSupportLevel() == VR_DAYDREAM;
instance.mAutopresentWebVr = true;
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEBVR_AUTOPRESENT_FROM_INTENT)) {
instance.onEnterVrUnsupported();
......
......@@ -58,7 +58,9 @@ public class MockVrDaydreamApi implements VrDaydreamApi {
}
@Override
public void launchVrHomescreen() {}
public boolean launchVrHomescreen() {
return true;
}
public boolean getLaunchInVrCalled() {
return mLaunchInVrCalled;
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.vr_shell.mock;
import android.content.Context;
import android.content.Intent;
import org.chromium.chrome.browser.vr_shell.VrIntentUtils;
......@@ -33,6 +34,11 @@ public class MockVrIntentHandler implements VrIntentUtils.VrIntentHandler {
return false;
}
@Override
public boolean canHandleVrIntent(Context context) {
return true;
}
public void setUseMockImplementation(boolean enabled) {
mUseMockImplementation = enabled;
}
......
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