Chromium Code Reviews| 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..2c3c3052188c312a8ed47a20df4ffa5a7bc3bf4e 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 on the device and returns them to the |
| + * caller using a callback. |
|
pkotwicz
2017/01/19 19:37:16
Nit: "installed on the device" -> "installed"
I t
gonzalon
2017/01/19 23:50:16
Done.
|
| + * |
| + * @param callbackPointer Callback to be called with the information on the WebAPKs found. |
|
pkotwicz
2017/01/19 19:37:16
Nit: "to be called" -> "to call"
gonzalon
2017/01/19 23:50:16
Done.
|
| + */ |
| + @CalledByNative |
| + public static void listWebApks(long callbackPointer) { |
| + 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(); |
| + for (PackageInfo packageInfo : packageManager.getInstalledPackages(0)) { |
| + if (WebApkValidator.isValidWebApk( |
| + ContextUtils.getApplicationContext(), packageInfo.packageName)) { |
| + // We need to pass in a non-null URL as second parameter to fetch all the |
| + // information about the WebAPK. |
|
pkotwicz
2017/01/19 19:37:16
How about: "Pass non-null URL parameter so that {@
gonzalon
2017/01/19 23:50:16
Done.
|
| + WebApkInfo webApkInfo = |
| + WebApkInfo.create(packageInfo.packageName, "", ShortcutSource.UNKNOWN); |
| + if (webApkInfo != null) { |
| + shortNames.add(webApkInfo.shortName()); |
| + packageNames.add(packageInfo.packageName); |
|
pkotwicz
2017/01/19 19:37:16
Nit: packageInfo.packageName -> webApkInfo.webApkP
gonzalon
2017/01/19 23:50:16
Done.
|
| + 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) { |
| + array[i++] = value; |
| + } |
| + return array; |
| + } |
| + |
| private static native void nativeOnWebappDataStored(long callbackPointer); |
| + private static native void nativeOnWebApksFound(long callbackPointer, String[] shortNames, |
| + String[] packageName, int[] shellApkVersions, int[] versionCodes); |
| } |