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

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

Issue 2261343002: [WebApk] Installation adds a homescreen shortcut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/ShortcutHelper.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 1bbf42a4e68a252c21baf61d0042326e46762ceb..fa7633e5d192a15fef52043d68a79bb7d9d46609 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
@@ -5,14 +5,17 @@
package org.chromium.chrome.browser.webapps;
import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
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.ShortcutHelper;
import java.io.File;
@@ -42,6 +45,7 @@ public class WebApkInstaller {
intent.setDataAndType(fileUri, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
+ listenForPackageInstallation(packageName);
ContextUtils.getApplicationContext().startActivity(intent);
} catch (ActivityNotFoundException e) {
return false;
@@ -49,6 +53,34 @@ public class WebApkInstaller {
return true;
}
+ private static class WebApkInstallObserver extends BroadcastReceiver {
+ private final String mPackageName;
+ public WebApkInstallObserver(String packageName) {
+ mPackageName = packageName;
+ }
+
+ private static String getPackageName(Intent intent) {
+ Uri uri = intent.getData();
+ String pkg = uri != null ? uri.getSchemeSpecificPart() : null;
+ return pkg;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (mPackageName.equals(getPackageName(intent))) {
+ ShortcutHelper.addWebApkShortcut(context, mPackageName);
+ context.unregisterReceiver(this);
+ }
+ }
+ }
+
+ private static void listenForPackageInstallation(String packageName) {
+ IntentFilter iFilter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
+ iFilter.addDataScheme("package");
+ ContextUtils.getApplicationContext().registerReceiver(
+ new WebApkInstallObserver(packageName), iFilter);
+ }
+
/**
* Updates a WebAPK.
* @param filePath File to update.
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698