Chromium Code Reviews| 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..89231d8a31780eacb26976a035c15271107d0bf3 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,74 @@ public class ChromeWebApkHost { |
| return installingFromUnknownSourcesAllowed() || canUseGooglePlayToInstallWebApk(); |
| } |
| - /** Return whether installing WebAPKs using Google Play is enabled. */ |
| + /** |
| + * Initializes {@link sCanUseGooglePlayInstall}. It checks whether: |
| + * 1) WebAPK is 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() |
|
pkotwicz
2017/02/05 02:13:54
I don't think that having a separate isGooglePlayI
Xi Han
2017/02/06 18:03:43
This function is also callded by ChromeApplication
|
| + || !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.canUseInstallApi(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. */ |
| + public static boolean isGooglePlayInstallEnabledByChromeFeature() { |
| return isEnabled() && nativeCanUseGooglePlayToInstallWebApk(); |
|
dominickn
2017/02/06 05:22:49
I would move isEnabled() up to canInstallWebApk()
Xi Han
2017/02/06 18:03:43
Removed. Also, I added additional call in WebApkIn
|
| } |
| + /** |
| + * Returns whether installing WebAPKs is possible either from "unknown resources" or Google |
| + * Play. |
| + */ |
| + public static boolean canInstallWebApk() { |
| + return canUseGooglePlayToInstallWebApk() || canInstallFromUnknownSources(); |
| + } |
| + |
| + /** Returns whether installing WebAPKs from "unknown resources" is enabled. */ |
| + private static boolean canInstallFromUnknownSources() { |
| + return isEnabled() && nativeCanInstallFromUnknownSources(); |
|
dominickn
2017/02/06 05:22:49
I would move the isEnabled() check up to canInstal
Xi Han
2017/02/06 18:03:43
Remove |canInstallFromUnknownSources()|, since it
|
| + } |
| + |
| @CalledByNative |
| - private static boolean areWebApkEnabled() { |
| - return ChromeWebApkHost.isEnabled(); |
| + private static boolean isWebApkInstallFlowAvailable() { |
|
dominickn
2017/02/06 05:22:49
Call this canInstallWebApk() to match the native s
Xi Han
2017/02/06 18:03:43
Done.
|
| + return ChromeWebApkHost.canInstallWebApk(); |
| } |
| /** |
| @@ -155,4 +222,5 @@ public class ChromeWebApkHost { |
| } |
| private static native boolean nativeCanUseGooglePlayToInstallWebApk(); |
| + private static native boolean nativeCanInstallFromUnknownSources(); |
| } |