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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkInstaller.java

Issue 2231803003: Install downloaded WebAPK when "installation from unknown sources" is enabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into webapk_install Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ChromeApplication.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+ }
+ }
}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ChromeApplication.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698