Chromium Code Reviews| Index: chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java |
| diff --git a/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java b/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java |
| index bb1e2ec37140302172b5b7efc06dda697d881154..1be7119bb654bce4f70baf2e2257c3471ccb92fe 100644 |
| --- a/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java |
| +++ b/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java |
| @@ -16,6 +16,7 @@ import android.content.pm.Signature; |
| import android.util.Log; |
| import java.util.Arrays; |
| +import java.util.LinkedList; |
| import java.util.List; |
| /** |
| @@ -40,11 +41,44 @@ public class WebApkValidator { |
| * handled by a WebAPK. |
| */ |
| public static String queryWebApkPackage(Context context, String url) { |
|
pkotwicz
2017/02/22 16:50:20
Can you make this function use queryResolveInfo()?
gonzalon
2017/02/22 17:17:40
I don't understand why. Isn't that what findWebApk
pkotwicz
2017/02/22 20:26:09
I wanted to merge resolveInfosForUrl() and queryRe
|
| + return findWebApkPackage(context, resolveInfosForUrl(context, url)); |
| + } |
| + |
| + /** |
| + * Queries the PackageManager to determine whether a WebAPK can handle the URL. Ignores |
| + * whether the user has selected a default handler for the URL and whether the default |
| + * handler is the WebAPK. |
| + * |
| + * NOTE: This can fail if multiple WebAPKs can match the supplied url. |
| + * |
| + * @param context The application context. |
| + * @param url The url to check. |
| + * @return Resolve Info of a WebAPK which can handle the URL. Null if the url should not be |
|
pkotwicz
2017/02/22 20:26:09
Nit: "Resolve Info of a WebAPK" -> "ResolveInfo of
|
| + * handled by a WebAPK. |
| + */ |
| + public static ResolveInfo queryWebApk(Context context, String url) { |
|
pkotwicz
2017/02/22 16:50:20
Can you rename this function to queryResolveInfo()
gonzalon
2017/02/22 17:17:40
Done.
|
| + for (ResolveInfo info : resolveInfosForUrl(context, url)) { |
| + if (info.activityInfo != null |
| + && isValidWebApk(context, info.activityInfo.packageName)) { |
| + return info; |
| + } |
| + } |
| + return null; |
| + } |
| + |
| + /** |
| + * Fetches the list of resolve infos from the PackageManager that can handle the URL. |
| + * |
| + * @param context The application context. |
| + * @param url The url to check. |
| + * @return The list of resolve infos found that can handle the URL. |
| + */ |
| + private static List<ResolveInfo> resolveInfosForUrl(Context context, String url) { |
| Intent intent; |
| try { |
| intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); |
| } catch (Exception e) { |
| - return null; |
| + return new LinkedList<>(); |
| } |
| intent.addCategory(Intent.CATEGORY_BROWSABLE); |
| @@ -54,10 +88,8 @@ public class WebApkValidator { |
| selector.addCategory(Intent.CATEGORY_BROWSABLE); |
| selector.setComponent(null); |
| } |
| - |
| - List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities( |
| + return context.getPackageManager().queryIntentActivities( |
| intent, PackageManager.GET_RESOLVED_FILTER); |
| - return findWebApkPackage(context, resolveInfos); |
| } |
| /** |