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..66715bfd0c8ef2420878c54907dd842a860dcc44 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 |
| @@ -40,6 +40,48 @@ public class WebApkValidator { |
| * handled by a WebAPK. |
| */ |
| public static String queryWebApkPackage(Context context, String url) { |
| + List<ResolveInfo> resolveInfos = resolveInfosForUrl(context, url); |
| + if (resolveInfos == null) { |
| + return null; |
| + } |
| + return findWebApkPackage(context, resolveInfos); |
| + } |
| + |
| + /** |
| + * 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 |
| + * handled by a WebAPK. |
| + */ |
| + public static ResolveInfo queryWebApk(Context context, String url) { |
| + List<ResolveInfo> resolveInfos = resolveInfosForUrl(context, url); |
| + if (resolveInfos == null) { |
| + return null; |
| + } |
| + |
| + for (ResolveInfo info : resolveInfos) { |
| + 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) { |
|
dominickn
2017/02/21 23:04:42
It would be nice if this method never returned nul
gonzalon
2017/02/22 15:50:49
Done.
|
| Intent intent; |
| try { |
| intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); |
| @@ -54,10 +96,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); |
| } |
| /** |