| 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 2b3a2c9fb66f47a8b1437241f5ee51515d29292a..5121141e5f4ae922c55ddaae776771b8d56f0ea4 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,11 +4,13 @@
|
|
|
| package org.chromium.chrome.browser.webapps;
|
|
|
| +import android.app.PendingIntent;
|
| import android.content.Context;
|
| import android.content.Intent;
|
| import android.content.pm.PackageManager;
|
| import android.net.Uri;
|
| import android.os.Build;
|
| +import android.os.Bundle;
|
| import android.os.Looper;
|
|
|
| import org.chromium.base.ApplicationState;
|
| @@ -18,6 +20,7 @@ import org.chromium.base.ContextUtils;
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.chrome.browser.ShortcutHelper;
|
| import org.chromium.chrome.browser.banners.InstallerDelegate;
|
| +import org.chromium.chrome.browser.document.ChromeLauncherActivity;
|
| import org.chromium.chrome.browser.util.IntentUtils;
|
|
|
| import java.io.File;
|
| @@ -42,6 +45,9 @@ public class WebApkInstaller {
|
| /** Indicates whether to install or update a WebAPK. */
|
| private boolean mIsInstall;
|
|
|
| + /** Talks to Play Store to install WebAPKs. **/
|
| + private static WebApkInstallClientDelegate sWebApkInstallClientDelegate;
|
| +
|
| /** Weak pointer to the native WebApkInstaller. */
|
| private long mNativePointer;
|
|
|
| @@ -49,6 +55,14 @@ public class WebApkInstaller {
|
| mNativePointer = nativePtr;
|
| }
|
|
|
| + /** Sets the WebApkInstallClientDelegate. **/
|
| + public static void setWebApkInstallClientDelegate(WebApkInstallClientDelegate delegate) {
|
| + if (sWebApkInstallClientDelegate != null) {
|
| + sWebApkInstallClientDelegate.reset();
|
| + }
|
| + sWebApkInstallClientDelegate = delegate;
|
| + }
|
| +
|
| @CalledByNative
|
| private static WebApkInstaller create(long nativePtr) {
|
| return new WebApkInstaller(nativePtr);
|
| @@ -74,10 +88,7 @@ public class WebApkInstaller {
|
| mWebApkPackageName = packageName;
|
|
|
| // Start monitoring the installation.
|
| - PackageManager packageManager = ContextUtils.getApplicationContext().getPackageManager();
|
| - mInstallTask = new InstallerDelegate(Looper.getMainLooper(), packageManager,
|
| - createInstallerDelegateObserver(), mWebApkPackageName);
|
| - mInstallTask.start();
|
| + setupInstallProcessMonitering();
|
| // Start monitoring the application state changes.
|
| mListener = createApplicationStateListener();
|
| ApplicationStatus.registerApplicationStateListener(mListener);
|
| @@ -86,6 +97,54 @@ public class WebApkInstaller {
|
| }
|
|
|
| /**
|
| + * Install a WebAPK from Play Store and monitors the installation.
|
| + * @param packageName The package name of the WebAPK to install.
|
| + * @param version The version of WebAPK to install.
|
| + * @param title The title of the WebAPK to display during installation.
|
| + * @param token The token from WebAPK Minter Server
|
| + */
|
| + @CalledByNative
|
| + private void installWebApkFromPlayStoreAsyncAndMonitorInstallation(
|
| + final String packageName, final int version, final String title, final String token) {
|
| + if (sWebApkInstallClientDelegate == null) return;
|
| +
|
| + mWebApkPackageName = packageName;
|
| + setupInstallProcessMonitering();
|
| + sWebApkInstallClientDelegate.installAsync(packageName, createInstallOptions(
|
| + version, title, createNotificationPendingIntent(), token));
|
| + }
|
| +
|
| + /** Start monitoring the installation. **/
|
| + private void setupInstallProcessMonitering() {
|
| + PackageManager packageManager = ContextUtils.getApplicationContext().getPackageManager();
|
| + mInstallTask = new InstallerDelegate(Looper.getMainLooper(), packageManager,
|
| + createInstallerDelegateObserver(), mWebApkPackageName);
|
| + mInstallTask.start();
|
| + }
|
| +
|
| + /** Returns a bundle with all the installation options. **/
|
| + private Bundle createInstallOptions(int version, String title, PendingIntent notificationIntent,
|
| + String token) {
|
| + Bundle installOptions = new Bundle();
|
| + installOptions.putInt("version_number", version);
|
| + installOptions.putString("title", title);
|
| + installOptions.putParcelable("notification_intent", notificationIntent);
|
| + installOptions.putString("wam_token", token);
|
| + return installOptions;
|
| + }
|
| +
|
| + /**
|
| + * Creates a PendingIntent used to redirect users if notifications are clicked during the
|
| + * installation.
|
| + */
|
| + private PendingIntent createNotificationPendingIntent() {
|
| + Context context = ContextUtils.getApplicationContext();
|
| + Intent intent = new Intent(context, ChromeLauncherActivity.class);
|
| + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
| + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
| + }
|
| +
|
| + /**
|
| * Send intent to Android to show prompt and install downloaded WebAPK.
|
| * @param filePath File to install.
|
| */
|
|
|