| 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 5f75e9039dcbd26b0a0300d16524615433debdee..e12690f63cc5cd1825b91ca2b3b7e380551f3544 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
|
| @@ -4,14 +4,21 @@
|
|
|
| package org.chromium.chrome.browser.webapps;
|
|
|
| +import android.content.Context;
|
| +import android.content.DialogInterface;
|
| +import android.content.Intent;
|
| import android.os.StrictMode;
|
| +import android.provider.Settings;
|
| +import android.support.v7.app.AlertDialog;
|
|
|
| import org.chromium.base.CommandLine;
|
| 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.ChromeFeatureList;
|
| import org.chromium.chrome.browser.ChromeSwitches;
|
| +import org.chromium.chrome.browser.ChromeVersionInfo;
|
| import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
|
| import org.chromium.webapk.lib.client.WebApkValidator;
|
|
|
| @@ -60,19 +67,97 @@ public class ChromeWebApkHost {
|
| }
|
|
|
| /**
|
| + * Show dialog warning user that "installation from unknown sources" is required by the WebAPK
|
| + * experiment if:
|
| + * - The user toggled the --enable-webapk command line flag via chrome://flags
|
| + * AND
|
| + * - WebAPKs are not disabled via variations kill switch.
|
| + * Must be run prior to {@link cacheEnabledStateForNextLaunch}.
|
| + */
|
| + public static void launchWebApkRequirementsDialogIfNeeded(Context context) {
|
| + // Show dialog on Canary & Dev. Installation via "unknown sources" is disabled via
|
| + // variations on other channels.
|
| + if (!ChromeVersionInfo.isCanaryBuild() && !ChromeVersionInfo.isDevBuild()) return;
|
| +
|
| + Context applicationContext = ContextUtils.getApplicationContext();
|
| + boolean wasCommandLineFlagEnabled = ChromePreferenceManager.getInstance(applicationContext)
|
| + .getCachedWebApkCommandLineEnabled();
|
| + if (computeEnabled() && !wasCommandLineFlagEnabled
|
| + && !installingFromUnknownSourcesAllowed(applicationContext)) {
|
| + showUnknownSourcesNeededDialog(context);
|
| + }
|
| + }
|
| +
|
| + /**
|
| * Once native is loaded we can consult the command-line (set via about:flags) and also finch
|
| * state to see if we should enable WebAPKs.
|
| */
|
| public static void cacheEnabledStateForNextLaunch() {
|
| - boolean wasEnabled = isEnabledInPrefs();
|
| - CommandLine instance = CommandLine.getInstance();
|
| - boolean isEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.WEBAPKS)
|
| - && instance.hasSwitch(ChromeSwitches.ENABLE_WEBAPK);
|
| + ChromePreferenceManager preferenceManager =
|
| + ChromePreferenceManager.getInstance(ContextUtils.getApplicationContext());
|
| +
|
| + boolean wasCommandLineEnabled = preferenceManager.getCachedWebApkCommandLineEnabled();
|
| + boolean isCommandLineEnabled = isCommandLineFlagSet();
|
| + if (isCommandLineEnabled != wasCommandLineEnabled) {
|
| + // {@link launchWebApkRequirementsDialogIfNeeded()} is skipped the first time Chrome is
|
| + // launched so do caching here instead.
|
| + preferenceManager.setCachedWebApkCommandLineEnabled(isCommandLineEnabled);
|
| + }
|
|
|
| + boolean wasEnabled = isEnabledInPrefs();
|
| + boolean isEnabled = computeEnabled();
|
| if (isEnabled != wasEnabled) {
|
| Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnabled);
|
| - ChromePreferenceManager.getInstance(ContextUtils.getApplicationContext())
|
| - .setCachedWebApkRuntimeEnabled(isEnabled);
|
| + preferenceManager.setCachedWebApkRuntimeEnabled(isEnabled);
|
| + }
|
| + }
|
| +
|
| + /** Returns whether the --enable-webapk command line flag is set */
|
| + private static boolean isCommandLineFlagSet() {
|
| + return CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK);
|
| + }
|
| +
|
| + /** Returns whether we should enable WebAPKs */
|
| + private static boolean computeEnabled() {
|
| + return isCommandLineFlagSet() && ChromeFeatureList.isEnabled(ChromeFeatureList.WEBAPKS);
|
| + }
|
| +
|
| + /**
|
| + * Returns whether the user has enabled installing apps from sources other than the Google Play
|
| + * Store.
|
| + */
|
| + private static boolean installingFromUnknownSourcesAllowed(Context context) {
|
| + try {
|
| + return Settings.Secure.getInt(
|
| + context.getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS)
|
| + == 1;
|
| + } catch (Settings.SettingNotFoundException e) {
|
| + return false;
|
| }
|
| }
|
| +
|
| + /**
|
| + * Show dialog warning user that "installation from unknown sources" is required by the WebAPK
|
| + * experiment.
|
| + */
|
| + private static void showUnknownSourcesNeededDialog(final Context context) {
|
| + AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
| + builder.setTitle(R.string.webapk_unknown_sources_dialog_title);
|
| + builder.setMessage(R.string.webapk_unknown_sources_dialog_message);
|
| + builder.setPositiveButton(R.string.webapk_unknown_sources_settings_button,
|
| + new DialogInterface.OnClickListener() {
|
| + @Override
|
| + public void onClick(DialogInterface dialog, int id) {
|
| + // Open Android Security settings.
|
| + Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
|
| + context.startActivity(intent);
|
| + }
|
| + });
|
| + builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
| + @Override
|
| + public void onClick(DialogInterface dialog, int id) {}
|
| + });
|
| + AlertDialog dialog = builder.create();
|
| + dialog.show();
|
| + }
|
| }
|
|
|