| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java
|
| index b73fc416d8e6d1a06968dc2a2f29075eb7b6b524..d3d48b4a73400c0708ecc8eb4f845d64a69837b1 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java
|
| @@ -11,12 +11,16 @@ import android.os.StrictMode;
|
| import android.provider.Settings;
|
| import android.support.v7.app.AlertDialog;
|
|
|
| +import org.chromium.base.Callback;
|
| import org.chromium.base.ContextUtils;
|
| import org.chromium.base.Log;
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.chrome.R;
|
| +import org.chromium.chrome.browser.ChromeApplication;
|
| import org.chromium.chrome.browser.ChromeFeatureList;
|
| import org.chromium.chrome.browser.ChromeVersionInfo;
|
| +import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
|
| +import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler;
|
| import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
|
| import org.chromium.webapk.lib.client.WebApkValidator;
|
|
|
| @@ -26,6 +30,9 @@ import org.chromium.webapk.lib.client.WebApkValidator;
|
| public class ChromeWebApkHost {
|
| private static final String TAG = "ChromeWebApkHost";
|
|
|
| + /** Whether installing WebAPks from Google Play is possible. */
|
| + private static Boolean sCanUseGooglePlayInstall;
|
| +
|
| private static Boolean sEnabledForTesting;
|
|
|
| public static void init() {
|
| @@ -53,14 +60,69 @@ public class ChromeWebApkHost {
|
| return installingFromUnknownSourcesAllowed() || canUseGooglePlayToInstallWebApk();
|
| }
|
|
|
| - /** Return whether installing WebAPKs using Google Play is enabled. */
|
| + /**
|
| + * Initializes {@link sCanUseGooglePlayInstall}. It checks whether:
|
| + * 1) WebAPKs are enabled.
|
| + * 2) Google Play Service is available on the device.
|
| + * 3) Google Play install is enabled by Chrome.
|
| + * 4) Google Play is up-to-date and with gServices flags turned on.
|
| + * It calls the Google Play Install API to update {@link sCanUseGooglePlayInstall}
|
| + * asynchronously.
|
| + */
|
| + public static void initCanUseGooglePlayToInstallWebApk() {
|
| + if (!isGooglePlayInstallEnabledByChromeFeature()
|
| + || !ExternalAuthUtils.getInstance().canUseGooglePlayServices(
|
| + ContextUtils.getApplicationContext(),
|
| + new UserRecoverableErrorHandler.Silent())) {
|
| + sCanUseGooglePlayInstall = false;
|
| + return;
|
| + }
|
| +
|
| + ChromeApplication application = (ChromeApplication) ContextUtils.getApplicationContext();
|
| + GooglePlayWebApkInstallDelegate delegate = application.getGooglePlayWebApkInstallDelegate();
|
| + if (delegate == null) {
|
| + sCanUseGooglePlayInstall = false;
|
| + return;
|
| + }
|
| +
|
| + Callback<Boolean> callback = new Callback<Boolean>() {
|
| + @Override
|
| + public void onResult(Boolean success) {
|
| + sCanUseGooglePlayInstall = success;
|
| + }
|
| + };
|
| + delegate.canInstallWebApk(callback);
|
| + }
|
| +
|
| + /**
|
| + * Returns whether installing WebAPKs from Google Play is possible.
|
| + * If {@link sCanUseGooglePlayInstall} hasn't been set yet, it returns false immediately and
|
| + * calls the Google Play Install API to update {@link sCanUseGooglePlayInstall} asynchronously.
|
| + */
|
| public static boolean canUseGooglePlayToInstallWebApk() {
|
| + if (sCanUseGooglePlayInstall == null) {
|
| + sCanUseGooglePlayInstall = false;
|
| + initCanUseGooglePlayToInstallWebApk();
|
| + }
|
| + return sCanUseGooglePlayInstall;
|
| + }
|
| +
|
| + /**
|
| + * Returns whether Google Play install is enabled by Chrome. Does not check whether installing
|
| + * from Google Play is possible.
|
| + */
|
| + public static boolean isGooglePlayInstallEnabledByChromeFeature() {
|
| return isEnabled() && nativeCanUseGooglePlayToInstallWebApk();
|
| }
|
|
|
| + /**
|
| + * Returns whether installing WebAPKs is possible either from "unknown resources" or Google
|
| + * Play.
|
| + */
|
| @CalledByNative
|
| - private static boolean areWebApkEnabled() {
|
| - return ChromeWebApkHost.isEnabled();
|
| + private static boolean canInstallWebApk() {
|
| + return isEnabled()
|
| + && (canUseGooglePlayToInstallWebApk() || nativeCanInstallFromUnknownSources());
|
| }
|
|
|
| /**
|
| @@ -155,4 +217,5 @@ public class ChromeWebApkHost {
|
| }
|
|
|
| private static native boolean nativeCanUseGooglePlayToInstallWebApk();
|
| + private static native boolean nativeCanInstallFromUnknownSources();
|
| }
|
|
|