Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java

Issue 2675803004: Fall back to shortcut A2HS when Phonesky is out of date or unavailable. (Closed)
Patch Set: Rebase. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.webapps; 5 package org.chromium.chrome.browser.webapps;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.DialogInterface; 8 import android.content.DialogInterface;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.os.StrictMode; 10 import android.os.StrictMode;
11 import android.provider.Settings; 11 import android.provider.Settings;
12 import android.support.v7.app.AlertDialog; 12 import android.support.v7.app.AlertDialog;
13 13
14 import org.chromium.base.Callback;
14 import org.chromium.base.ContextUtils; 15 import org.chromium.base.ContextUtils;
15 import org.chromium.base.Log; 16 import org.chromium.base.Log;
16 import org.chromium.base.annotations.CalledByNative; 17 import org.chromium.base.annotations.CalledByNative;
17 import org.chromium.chrome.R; 18 import org.chromium.chrome.R;
19 import org.chromium.chrome.browser.ChromeApplication;
18 import org.chromium.chrome.browser.ChromeFeatureList; 20 import org.chromium.chrome.browser.ChromeFeatureList;
19 import org.chromium.chrome.browser.ChromeVersionInfo; 21 import org.chromium.chrome.browser.ChromeVersionInfo;
22 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
23 import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler;
20 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; 24 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
21 import org.chromium.webapk.lib.client.WebApkValidator; 25 import org.chromium.webapk.lib.client.WebApkValidator;
22 26
23 /** 27 /**
24 * Contains functionality needed for Chrome to host WebAPKs. 28 * Contains functionality needed for Chrome to host WebAPKs.
25 */ 29 */
26 public class ChromeWebApkHost { 30 public class ChromeWebApkHost {
27 private static final String TAG = "ChromeWebApkHost"; 31 private static final String TAG = "ChromeWebApkHost";
28 32
33 /** Whether installing WebAPks from Google Play is possible. */
34 private static Boolean sCanUseGooglePlayInstall;
35
29 private static Boolean sEnabledForTesting; 36 private static Boolean sEnabledForTesting;
30 37
31 public static void init() { 38 public static void init() {
32 WebApkValidator.initWithBrowserHostSignature(ChromeWebApkHostSignature.E XPECTED_SIGNATURE); 39 WebApkValidator.initWithBrowserHostSignature(ChromeWebApkHostSignature.E XPECTED_SIGNATURE);
33 } 40 }
34 41
35 public static void initForTesting(boolean enabled) { 42 public static void initForTesting(boolean enabled) {
36 sEnabledForTesting = enabled; 43 sEnabledForTesting = enabled;
37 } 44 }
38 45
39 public static boolean isEnabled() { 46 public static boolean isEnabled() {
40 if (sEnabledForTesting != null) return sEnabledForTesting; 47 if (sEnabledForTesting != null) return sEnabledForTesting;
41 48
42 return isEnabledInPrefs(); 49 return isEnabledInPrefs();
43 } 50 }
44 51
45 // Returns whether updating the WebAPK is enabled. 52 // Returns whether updating the WebAPK is enabled.
46 public static boolean areUpdatesEnabled() { 53 public static boolean areUpdatesEnabled() {
47 if (!isEnabled()) return false; 54 if (!isEnabled()) return false;
48 55
49 // Updating a WebAPK without going through Google Play requires "install ation from unknown 56 // Updating a WebAPK without going through Google Play requires "install ation from unknown
50 // sources" to be enabled. It is confusing for a user to see a dialog as king them to enable 57 // sources" to be enabled. It is confusing for a user to see a dialog as king them to enable
51 // "installation from unknown sources" when they are in the middle of us ing the WebAPK (as 58 // "installation from unknown sources" when they are in the middle of us ing the WebAPK (as
52 // opposed to after requesting to add a WebAPK to the homescreen). 59 // opposed to after requesting to add a WebAPK to the homescreen).
53 return installingFromUnknownSourcesAllowed() || canUseGooglePlayToInstal lWebApk(); 60 return installingFromUnknownSourcesAllowed() || canUseGooglePlayToInstal lWebApk();
54 } 61 }
55 62
56 /** Return whether installing WebAPKs using Google Play is enabled. */ 63 /**
64 * Initializes {@link sCanUseGooglePlayInstall}. It checks whether:
65 * 1) WebAPKs are enabled.
66 * 2) Google Play Service is available on the device.
67 * 3) Google Play install is enabled by Chrome.
68 * 4) Google Play is up-to-date and with gServices flags turned on.
69 * It calls the Google Play Install API to update {@link sCanUseGooglePlayIn stall}
70 * asynchronously.
71 */
72 public static void initCanUseGooglePlayToInstallWebApk() {
73 if (!isGooglePlayInstallEnabledByChromeFeature()
74 || !ExternalAuthUtils.getInstance().canUseGooglePlayServices(
75 ContextUtils.getApplicationContext(),
76 new UserRecoverableErrorHandler.Silent())) {
77 sCanUseGooglePlayInstall = false;
78 return;
79 }
80
81 ChromeApplication application = (ChromeApplication) ContextUtils.getAppl icationContext();
82 GooglePlayWebApkInstallDelegate delegate = application.getGooglePlayWebA pkInstallDelegate();
83 if (delegate == null) {
84 sCanUseGooglePlayInstall = false;
85 return;
86 }
87
88 Callback<Boolean> callback = new Callback<Boolean>() {
89 @Override
90 public void onResult(Boolean success) {
91 sCanUseGooglePlayInstall = success;
92 }
93 };
94 delegate.canInstallWebApk(callback);
95 }
96
97 /**
98 * Returns whether installing WebAPKs from Google Play is possible.
99 * If {@link sCanUseGooglePlayInstall} hasn't been set yet, it returns false immediately and
100 * calls the Google Play Install API to update {@link sCanUseGooglePlayInsta ll} asynchronously.
101 */
57 public static boolean canUseGooglePlayToInstallWebApk() { 102 public static boolean canUseGooglePlayToInstallWebApk() {
103 if (sCanUseGooglePlayInstall == null) {
104 sCanUseGooglePlayInstall = false;
105 initCanUseGooglePlayToInstallWebApk();
106 }
107 return sCanUseGooglePlayInstall;
108 }
109
110 /**
111 * Returns whether Google Play install is enabled by Chrome. Does not check whether installing
112 * from Google Play is possible.
113 */
114 public static boolean isGooglePlayInstallEnabledByChromeFeature() {
58 return isEnabled() && nativeCanUseGooglePlayToInstallWebApk(); 115 return isEnabled() && nativeCanUseGooglePlayToInstallWebApk();
59 } 116 }
60 117
118 /**
119 * Returns whether installing WebAPKs is possible either from "unknown resou rces" or Google
120 * Play.
121 */
61 @CalledByNative 122 @CalledByNative
62 private static boolean areWebApkEnabled() { 123 private static boolean canInstallWebApk() {
63 return ChromeWebApkHost.isEnabled(); 124 return isEnabled()
125 && (canUseGooglePlayToInstallWebApk() || nativeCanInstallFromUnk nownSources());
64 } 126 }
65 127
66 /** 128 /**
67 * Check the cached value to figure out if the feature is enabled. We have t o use the cached 129 * Check the cached value to figure out if the feature is enabled. We have t o use the cached
68 * value because native library may not yet been loaded. 130 * value because native library may not yet been loaded.
69 * @return Whether the feature is enabled. 131 * @return Whether the feature is enabled.
70 */ 132 */
71 private static boolean isEnabledInPrefs() { 133 private static boolean isEnabledInPrefs() {
72 // Will go away once the feature is enabled for everyone by default. 134 // Will go away once the feature is enabled for everyone by default.
73 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); 135 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 }); 210 });
149 builder.setNegativeButton(android.R.string.cancel, new DialogInterface.O nClickListener() { 211 builder.setNegativeButton(android.R.string.cancel, new DialogInterface.O nClickListener() {
150 @Override 212 @Override
151 public void onClick(DialogInterface dialog, int id) {} 213 public void onClick(DialogInterface dialog, int id) {}
152 }); 214 });
153 AlertDialog dialog = builder.create(); 215 AlertDialog dialog = builder.create();
154 dialog.show(); 216 dialog.show();
155 } 217 }
156 218
157 private static native boolean nativeCanUseGooglePlayToInstallWebApk(); 219 private static native boolean nativeCanUseGooglePlayToInstallWebApk();
220 private static native boolean nativeCanInstallFromUnknownSources();
158 } 221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698