Commit c4911c48 authored by amp's avatar amp Committed by Commit bot

Show an infobar when VR services need to be installed or updated.

BUG=670166

Review-Url: https://codereview.chromium.org/2699643003
Cr-Commit-Position: refs/heads/master@{#451372}
parent 2d215401
...@@ -11,6 +11,7 @@ import android.content.Context; ...@@ -11,6 +11,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.StrictMode; import android.os.StrictMode;
...@@ -26,13 +27,18 @@ import android.view.WindowManager; ...@@ -26,13 +27,18 @@ import android.view.WindowManager;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.PackageUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeTabbedActivity; import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.infobar.InfoBarIdentifier;
import org.chromium.chrome.browser.infobar.SimpleConfirmInfoBarBuilder;
import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel;
...@@ -79,6 +85,9 @@ public class VrShellDelegate { ...@@ -79,6 +85,9 @@ public class VrShellDelegate {
private static final String VR_ACTIVITY_ALIAS = private static final String VR_ACTIVITY_ALIAS =
"org.chromium.chrome.browser.VRChromeTabbedActivity"; "org.chromium.chrome.browser.VRChromeTabbedActivity";
private static final String VR_CORE_PACKAGE_ID = "com.google.vr.vrcore";
private static final int VR_CORE_MIN_VERSION = 160723800;
private static final long REENTER_VR_TIMEOUT_MS = 1000; private static final long REENTER_VR_TIMEOUT_MS = 1000;
private final ChromeTabbedActivity mActivity; private final ChromeTabbedActivity mActivity;
...@@ -107,7 +116,6 @@ public class VrShellDelegate { ...@@ -107,7 +116,6 @@ public class VrShellDelegate {
public VrShellDelegate(ChromeTabbedActivity activity) { public VrShellDelegate(ChromeTabbedActivity activity) {
mActivity = activity; mActivity = activity;
mVrClassesWrapper = createVrClassesWrapper(); mVrClassesWrapper = createVrClassesWrapper();
updateVrSupportLevel();
} }
/** /**
...@@ -129,19 +137,15 @@ public class VrShellDelegate { ...@@ -129,19 +137,15 @@ public class VrShellDelegate {
// Check cardboard support for non-daydream devices. // Check cardboard support for non-daydream devices.
if (!mVrDaydreamApi.isDaydreamReadyDevice()) { if (!mVrDaydreamApi.isDaydreamReadyDevice()) {
// Native libraries may not be ready in which case skip for now and check later. // Supported Build version is determined by the webvr cardboard support feature.
if (LibraryLoader.isInitialized()) { // Default is KITKAT unless specified via server side finch config.
// Supported Build version is determined by the webvr cardboard support feature. if (Build.VERSION.SDK_INT < ChromeFeatureList.getFieldTrialParamByFeatureAsInt(
// Default is KITKAT unless specified via server side finch config. ChromeFeatureList.WEBVR_CARDBOARD_SUPPORT,
if (Build.VERSION.SDK_INT MIN_SDK_VERSION_PARAM_NAME,
< ChromeFeatureList.getFieldTrialParamByFeatureAsInt( Build.VERSION_CODES.KITKAT)) {
ChromeFeatureList.WEBVR_CARDBOARD_SUPPORT, mVrSupportLevel = VR_NOT_AVAILABLE;
MIN_SDK_VERSION_PARAM_NAME, mEnterVRIntent = null;
Build.VERSION_CODES.KITKAT)) { return;
mVrSupportLevel = VR_NOT_AVAILABLE;
mEnterVRIntent = null;
return;
}
} }
} }
...@@ -152,12 +156,53 @@ public class VrShellDelegate { ...@@ -152,12 +156,53 @@ public class VrShellDelegate {
mVrSupportLevel = mVrDaydreamApi.isDaydreamReadyDevice() ? VR_DAYDREAM : VR_CARDBOARD; mVrSupportLevel = mVrDaydreamApi.isDaydreamReadyDevice() ? VR_DAYDREAM : VR_CARDBOARD;
} }
private boolean verifyOrUpdateVrServices(Tab tab) {
if (!LibraryLoader.isInitialized()) {
return false;
}
int vrCoreVersion = PackageUtils.getPackageVersion(mActivity, VR_CORE_PACKAGE_ID);
if (vrCoreVersion < VR_CORE_MIN_VERSION) {
// Assume upgrade as most common case.
String infobarText =
mActivity.getString(R.string.vr_services_check_infobar_update_text);
String buttonText =
mActivity.getString(R.string.vr_services_check_infobar_update_button);
if (vrCoreVersion == -1) {
// VrCore not installed, make sure it's supported before showing the user a prompt.
if (Build.VERSION.SDK_INT < ChromeFeatureList.getFieldTrialParamByFeatureAsInt(
ChromeFeatureList.WEBVR_CARDBOARD_SUPPORT,
MIN_SDK_VERSION_PARAM_NAME,
Build.VERSION_CODES.KITKAT)) {
return false;
}
// Supported, but not installed. Ask user to install instead of upgrade.
infobarText = mActivity.getString(R.string.vr_services_check_infobar_install_text);
buttonText = mActivity.getString(R.string.vr_services_check_infobar_install_button);
}
SimpleConfirmInfoBarBuilder.create(tab,
new SimpleConfirmInfoBarBuilder.Listener() {
@Override
public void onInfoBarDismissed() {}
@Override
public boolean onInfoBarButtonClicked(boolean isPrimary) {
mActivity.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + VR_CORE_PACKAGE_ID)));
return false;
}
},
InfoBarIdentifier.VR_SERVICES_UPGRADE_ANDROID, R.drawable.vr_services,
infobarText, buttonText, null, true);
return false;
}
return true;
}
/** /**
* Should be called once the native library is loaded so that the native portion of this class * Should be called once the native library is loaded so that the native portion of this class
* can be initialized. * can be initialized.
*/ */
public void onNativeLibraryReady() { public void onNativeLibraryReady() {
// Libraries may not have been loaded when we first set the support level, so check again.
updateVrSupportLevel(); updateVrSupportLevel();
if (mVrSupportLevel == VR_NOT_AVAILABLE) return; if (mVrSupportLevel == VR_NOT_AVAILABLE) return;
mNativeVrShellDelegate = nativeInit(); mNativeVrShellDelegate = nativeInit();
...@@ -336,6 +381,8 @@ public class VrShellDelegate { ...@@ -336,6 +381,8 @@ public class VrShellDelegate {
*/ */
@EnterVRResult @EnterVRResult
public int enterVRIfNecessary() { public int enterVRIfNecessary() {
// TODO(amp): Move the UpdateVrService check to where it can check after a WebVR API call.
if (!verifyOrUpdateVrServices(mActivity.getActivityTab())) return ENTER_VR_CANCELLED;
if (mVrSupportLevel == VR_NOT_AVAILABLE) return ENTER_VR_CANCELLED; if (mVrSupportLevel == VR_NOT_AVAILABLE) return ENTER_VR_CANCELLED;
if (mInVr) return ENTER_VR_NOT_NECESSARY; if (mInVr) return ENTER_VR_NOT_NECESSARY;
if (!canEnterVR(mActivity.getActivityTab())) return ENTER_VR_CANCELLED; if (!canEnterVR(mActivity.getActivityTab())) return ENTER_VR_CANCELLED;
......
...@@ -2744,6 +2744,20 @@ You can control the Physical Web in Chrome Settings. ...@@ -2744,6 +2744,20 @@ You can control the Physical Web in Chrome Settings.
<message name="IDS_KEYBOARD_SHORTCUT_WEBPAGE_GROUP_HEADER" desc="A text label that appears above a list of shortcuts that are related to manipulation of the current tab window. This group is part of several groups of keyboard shortcuts all shown in a dialog."> <message name="IDS_KEYBOARD_SHORTCUT_WEBPAGE_GROUP_HEADER" desc="A text label that appears above a list of shortcuts that are related to manipulation of the current tab window. This group is part of several groups of keyboard shortcuts all shown in a dialog.">
Webpage shortcuts Webpage shortcuts
</message> </message>
<!-- VR services check infobar -->
<message name="IDS_VR_SERVICES_CHECK_INFOBAR_INSTALL_TEXT" desc="Text to be displayed in the VR Services check infobar. When a WebVR page is loaded if the VR services that are needed to display WebVR don't exist an infobar will be shown to the user prompting them to install VR services.">
To view virtual reality content, install Google VR Services
</message>
<message name="IDS_VR_SERVICES_CHECK_INFOBAR_UPDATE_TEXT" desc="Text to be displayed in the VR Services check infobar. When a WebVR page is loaded if the VR services that are needed to display WebVR are out of date an infobar will be shown to the user prompting them to update VR services.">
To view virtual reality content, update Google VR Services
</message>
<message name="IDS_VR_SERVICES_CHECK_INFOBAR_INSTALL_BUTTON" desc="Text to be displayed in the VR Services check infobar confirm button for installing.">
Install
</message>
<message name="IDS_VR_SERVICES_CHECK_INFOBAR_UPDATE_BUTTON" desc="Text to be displayed in the VR Services check infobar confirm button for updating.">
Update
</message>
</messages> </messages>
</release> </release>
</grit> </grit>
...@@ -145,6 +145,7 @@ class InfoBarDelegate { ...@@ -145,6 +145,7 @@ class InfoBarDelegate {
OFFLINE_PAGE_INFOBAR_DELEGATE = 71, OFFLINE_PAGE_INFOBAR_DELEGATE = 71,
SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE = 72, SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE = 72,
AUTOMATION_INFOBAR_DELEGATE = 73, AUTOMATION_INFOBAR_DELEGATE = 73,
VR_SERVICES_UPGRADE_ANDROID = 74,
}; };
// Describes navigation events, used to decide whether infobars should be // Describes navigation events, used to decide whether infobars should be
......
...@@ -94760,6 +94760,7 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -94760,6 +94760,7 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<int value="71" label="OFFLINE_PAGE_INFOBAR_DELEGATE"/> <int value="71" label="OFFLINE_PAGE_INFOBAR_DELEGATE"/>
<int value="72" label="SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE"/> <int value="72" label="SEARCH_GEOLOCATION_DISCLOSURE_INFOBAR_DELEGATE"/>
<int value="73" label="AUTOMATION_INFOBAR_DELEGATE"/> <int value="73" label="AUTOMATION_INFOBAR_DELEGATE"/>
<int value="74" label="VR_SERVICES_UPGRADE_ANDROID"/>
</enum> </enum>
<enum name="InfoBarResponse" type="int"> <enum name="InfoBarResponse" type="int">
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