| 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.
|
|
|