Index: chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
index 9bb166773ac1199ec993a12a54d29685cb851db7..49731f362f479f61394401697d2caa93a685081b 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
@@ -9,6 +9,7 @@ import android.app.ActivityManager; |
import android.content.Context; |
import android.content.Intent; |
import android.content.pm.ApplicationInfo; |
+import android.content.pm.PackageInfo; |
import android.content.pm.PackageManager; |
import android.content.pm.PackageManager.NameNotFoundException; |
import android.content.pm.ResolveInfo; |
@@ -22,6 +23,7 @@ import android.graphics.drawable.BitmapDrawable; |
import android.graphics.drawable.Drawable; |
import android.net.Uri; |
import android.os.AsyncTask; |
+import android.support.annotation.NonNull; |
import android.text.TextUtils; |
import android.util.Base64; |
@@ -34,6 +36,7 @@ import org.chromium.base.annotations.CalledByNative; |
import org.chromium.blink_public.platform.WebDisplayMode; |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.webapps.ChromeWebApkHost; |
+import org.chromium.chrome.browser.webapps.WebApkInfo; |
import org.chromium.chrome.browser.webapps.WebappActivity; |
import org.chromium.chrome.browser.webapps.WebappAuthenticator; |
import org.chromium.chrome.browser.webapps.WebappDataStorage; |
@@ -45,6 +48,7 @@ import org.chromium.ui.widget.Toast; |
import org.chromium.webapk.lib.client.WebApkValidator; |
import java.io.ByteArrayOutputStream; |
+import java.util.ArrayList; |
import java.util.List; |
/** |
@@ -648,5 +652,50 @@ public class ShortcutHelper { |
return null; |
} |
+ /** |
+ * Fetches the information of all WebAPKs installed and returns them to the caller using a |
dominickn
2017/01/23 00:48:07
"Calls the native |callbackPointer| with lists of
gonzalon
2017/01/23 16:58:50
Done.
|
+ * callback. |
+ * |
+ * @param callbackPointer Callback to call with the information on the WebAPKs found. |
+ */ |
+ @CalledByNative |
+ public static void listWebApks(long callbackPointer) { |
dominickn
2017/01/23 00:48:07
Call this method "retrieveWebApks" - "listWebApks"
gonzalon
2017/01/23 16:58:50
Done.
|
+ List<String> shortNames = new ArrayList<>(); |
+ List<String> packageNames = new ArrayList<>(); |
+ List<Integer> shellApkVersions = new ArrayList<>(); |
+ List<Integer> versionCodes = new ArrayList<>(); |
+ |
+ PackageManager packageManager = ContextUtils.getApplicationContext().getPackageManager(); |
dominickn
2017/01/23 00:48:07
Since you're reusing the context a lot, stick it i
gonzalon
2017/01/23 16:58:50
Done.
|
+ for (PackageInfo packageInfo : packageManager.getInstalledPackages(0)) { |
+ if (WebApkValidator.isValidWebApk( |
+ ContextUtils.getApplicationContext(), packageInfo.packageName)) { |
+ // Pass non-null URL parameter so that {@link WebApkInfo#create()} |
+ // return value is non-null |
+ WebApkInfo webApkInfo = |
+ WebApkInfo.create(packageInfo.packageName, "", ShortcutSource.UNKNOWN); |
+ if (webApkInfo != null) { |
+ shortNames.add(webApkInfo.shortName()); |
+ packageNames.add(webApkInfo.webApkPackageName()); |
+ shellApkVersions.add(webApkInfo.shellApkVersion()); |
+ versionCodes.add(packageInfo.versionCode); |
+ } |
+ } |
+ } |
+ nativeOnWebApksFound(callbackPointer, shortNames.toArray(new String[0]), |
+ packageNames.toArray(new String[0]), integerListToIntArray(shellApkVersions), |
+ integerListToIntArray(versionCodes)); |
+ } |
+ |
+ private static int[] integerListToIntArray(@NonNull List<Integer> list) { |
+ int[] array = new int[list.size()]; |
+ int i = 0; |
+ for (Integer value : list) { |
dominickn
2017/01/23 00:48:07
Just do:
for (int i = 0; i < list.size(); ++i) {
gonzalon
2017/01/23 16:58:50
Done.
|
+ array[i++] = value; |
+ } |
+ return array; |
+ } |
+ |
private static native void nativeOnWebappDataStored(long callbackPointer); |
+ private static native void nativeOnWebApksFound(long callbackPointer, String[] shortNames, |
dominickn
2017/01/23 00:48:07
Call this nativeOnWebApksRetrieved to match retrie
gonzalon
2017/01/23 16:58:50
Done.
|
+ String[] packageName, int[] shellApkVersions, int[] versionCodes); |
} |