| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java
|
| index 86aa4f5ad46bfb55e4e1b59918aa0a6f5b735d88..fd0629e9ad4b94a5327049be5bd2eb96efba4fad 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java
|
| @@ -4,17 +4,25 @@
|
|
|
| package org.chromium.chrome.browser.webapps;
|
|
|
| +import android.content.ActivityNotFoundException;
|
| import android.content.Context;
|
| +import android.content.Intent;
|
| +import android.net.Uri;
|
| +import android.provider.Settings;
|
|
|
| import org.chromium.base.ContextUtils;
|
| +import org.chromium.base.Log;
|
| import org.chromium.base.annotations.CalledByNative;
|
| -import org.chromium.chrome.browser.ChromeApplication;
|
| +
|
| +import java.io.File;
|
|
|
| /**
|
| * Java counterpart to webapk_installer.h
|
| * Contains functionality to install WebAPKs.
|
| */
|
| -public abstract class WebApkInstaller {
|
| +public class WebApkInstaller {
|
| + private static final String TAG = "WebApkInstaller";
|
| +
|
| /**
|
| * Installs a WebAPK.
|
| * @param filePath File to install.
|
| @@ -22,16 +30,40 @@ public abstract class WebApkInstaller {
|
| * @return True if the install was started. A "true" return value does not guarantee that the
|
| * install succeeds.
|
| */
|
| - public abstract boolean installAsync(String filePath, String packageName);
|
| -
|
| @CalledByNative
|
| static boolean installAsyncFromNative(String filePath, String packageName) {
|
| - Context context = ContextUtils.getApplicationContext();
|
| - WebApkInstaller apkInstaller = ((ChromeApplication) context).createWebApkInstaller();
|
| - if (apkInstaller == null) {
|
| + if (!installingFromUnknownSourcesAllowed()) {
|
| + Log.e(TAG,
|
| + "WebAPK install failed because installation from unknown sources is disabled.");
|
| + return false;
|
| + }
|
| + if (!new File(filePath).exists()) {
|
| + return false;
|
| + }
|
| + Intent intent = new Intent(Intent.ACTION_VIEW);
|
| + Uri fileUri = Uri.fromFile(new File(filePath));
|
| + intent.setDataAndType(fileUri, "application/vnd.android.package-archive");
|
| + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
| + try {
|
| + ContextUtils.getApplicationContext().startActivity(intent);
|
| + } catch (ActivityNotFoundException e) {
|
| return false;
|
| }
|
| - apkInstaller.installAsync(filePath, packageName);
|
| return true;
|
| }
|
| +
|
| + /**
|
| + * Returns whether the user has enabled installing apps from sources other than the Google Play
|
| + * Store.
|
| + */
|
| + private static boolean installingFromUnknownSourcesAllowed() {
|
| + Context context = ContextUtils.getApplicationContext();
|
| + try {
|
| + return Settings.Secure.getInt(
|
| + context.getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS)
|
| + == 1;
|
| + } catch (Settings.SettingNotFoundException e) {
|
| + return false;
|
| + }
|
| + }
|
| }
|
|
|