| 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 f62054e97d86bc617fe921bee9646d6b23d24720..2fc1e46694f8cdc92fbab00bdff47e7cd9de9809 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
|
| @@ -15,6 +15,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
| import android.content.pm.ResolveInfo;
|
| import android.content.pm.Signature;
|
| import android.os.StrictMode;
|
| +import android.support.annotation.Nullable;
|
| import android.text.TextUtils;
|
| import android.util.Log;
|
|
|
| @@ -56,7 +57,8 @@ public class WebApkValidator {
|
| * handled by a WebAPK.
|
| */
|
| public static String queryWebApkPackage(Context context, String url) {
|
| - return findWebApkPackage(context, resolveInfosForUrl(context, url));
|
| + return findWebApkPackage(
|
| + context, resolveInfosForUrlAndOptionalPackage(context, url, null /* package*/));
|
| }
|
|
|
| /**
|
| @@ -72,7 +74,33 @@ public class WebApkValidator {
|
| * handled by a WebAPK.
|
| */
|
| public static ResolveInfo queryResolveInfo(Context context, String url) {
|
| - return findResolveInfo(context, resolveInfosForUrl(context, url));
|
| + return findResolveInfo(
|
| + context, resolveInfosForUrlAndOptionalPackage(context, url, null /* package */));
|
| + }
|
| +
|
| + /**
|
| + * @param context The context to use to check whether WebAPK is valid.
|
| + * @param infos The ResolveInfos to search.
|
| + * @return Package name of the ResolveInfo which corresponds to a WebAPK. Null if none of the
|
| + * ResolveInfos corresponds to a WebAPK.
|
| + */
|
| + public static String findWebApkPackage(Context context, List<ResolveInfo> infos) {
|
| + ResolveInfo resolveInfo = findResolveInfo(context, infos);
|
| + if (resolveInfo != null) {
|
| + return resolveInfo.activityInfo.packageName;
|
| + }
|
| + return null;
|
| + }
|
| +
|
| + public static boolean canWebApkHandleUrl(Context context, String webApkPackage, String url) {
|
| + List<ResolveInfo> infos = resolveInfosForUrlAndOptionalPackage(context, url, webApkPackage);
|
| + for (ResolveInfo info : infos) {
|
| + if (info.activityInfo != null
|
| + && isValidWebApk(context, info.activityInfo.packageName)) {
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| }
|
|
|
| /**
|
| @@ -80,9 +108,11 @@ public class WebApkValidator {
|
| *
|
| * @param context The application context.
|
| * @param url The url to check.
|
| + * @param applicationPackage The optional package name to set for intent resolution.
|
| * @return The list of resolve infos found that can handle the URL.
|
| */
|
| - private static List<ResolveInfo> resolveInfosForUrl(Context context, String url) {
|
| + private static List<ResolveInfo> resolveInfosForUrlAndOptionalPackage(
|
| + Context context, String url, @Nullable String applicationPackage) {
|
| Intent intent;
|
| try {
|
| intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
|
| @@ -91,7 +121,11 @@ public class WebApkValidator {
|
| }
|
|
|
| intent.addCategory(Intent.CATEGORY_BROWSABLE);
|
| - intent.setComponent(null);
|
| + if (applicationPackage != null) {
|
| + intent.setPackage(applicationPackage);
|
| + } else {
|
| + intent.setComponent(null);
|
| + }
|
| Intent selector = intent.getSelector();
|
| if (selector != null) {
|
| selector.addCategory(Intent.CATEGORY_BROWSABLE);
|
| @@ -101,20 +135,6 @@ public class WebApkValidator {
|
| intent, PackageManager.GET_RESOLVED_FILTER);
|
| }
|
|
|
| - /**
|
| - * @param context The context to use to check whether WebAPK is valid.
|
| - * @param infos The ResolveInfos to search.
|
| - * @return Package name of the ResolveInfo which corresponds to a WebAPK. Null if none of the
|
| - * ResolveInfos corresponds to a WebAPK.
|
| - */
|
| - public static String findWebApkPackage(Context context, List<ResolveInfo> infos) {
|
| - ResolveInfo resolveInfo = findResolveInfo(context, infos);
|
| - if (resolveInfo != null) {
|
| - return resolveInfo.activityInfo.packageName;
|
| - }
|
| - return null;
|
| - }
|
| -
|
| /**
|
| * @param context The context to use to check whether WebAPK is valid.
|
| * @param infos The ResolveInfos to search.
|
|
|