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..dc7beb8481000dc2dc634a6303b67d24649fdc38 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; |
@@ -27,7 +30,7 @@ import java.io.File; |
* Contains functionality to install / update WebAPKs. |
* This Java object is created by and owned by the native WebApkInstaller. |
*/ |
-public class WebApkInstaller { |
+public class WebApkInstaller implements WebApkInstallClientDelegate.Observer { |
private static final String TAG = "WebApkInstaller"; |
/** The WebAPK's package name. */ |
@@ -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,26 @@ public class WebApkInstaller { |
mNativePointer = nativePtr; |
} |
+ /** Sets the WebApkInstallClientDelegate. */ |
+ public static void setWebApkInstallClientDelegate(WebApkInstallClientDelegate delegate) { |
+ if (sWebApkInstallClientDelegate != null) { |
+ sWebApkInstallClientDelegate.reset(); |
+ } |
+ sWebApkInstallClientDelegate = delegate; |
+ } |
+ |
+ /** Gets the WebApkInstallClientDelegate. */ |
+ public static WebApkInstallClientDelegate getWebApkInstallClientDelegate() { |
+ return sWebApkInstallClientDelegate; |
+ } |
+ |
+ @Override |
+ public void onInstallStateChanged(boolean success) { |
+ if (mNativePointer != 0) { |
+ nativeOnInstallFinished(mNativePointer, success); |
+ } |
+ } |
+ |
@CalledByNative |
private static WebApkInstaller create(long nativePtr) { |
return new WebApkInstaller(nativePtr); |
@@ -86,6 +112,45 @@ 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; |
+ sWebApkInstallClientDelegate.installAsync(this, packageName, createInstallOptions( |
+ version, title, createNotificationPendingIntent(), token)); |
+ } |
+ |
+ /** 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. |
*/ |