Commit a2f69efc authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[gIRA] Add the ability to find WebAPKs by manifestURLs.

This is limited to bound WebAPKs. This is the first step to make WebAPKs
discoverable via getInstalledRelatedApps.

Bug: 1043970
Change-Id: I1cbb86159d15554c129894b6c405c1efefa42587
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2012287
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734214}
parent e76d2356
...@@ -7,6 +7,7 @@ package org.chromium.webapk.lib.client; ...@@ -7,6 +7,7 @@ package org.chromium.webapk.lib.client;
import static org.chromium.webapk.lib.common.WebApkConstants.WEBAPK_PACKAGE_PREFIX; import static org.chromium.webapk.lib.common.WebApkConstants.WEBAPK_PACKAGE_PREFIX;
import static org.chromium.webapk.lib.common.WebApkMetaDataKeys.SCOPE; import static org.chromium.webapk.lib.common.WebApkMetaDataKeys.SCOPE;
import static org.chromium.webapk.lib.common.WebApkMetaDataKeys.START_URL; import static org.chromium.webapk.lib.common.WebApkMetaDataKeys.START_URL;
import static org.chromium.webapk.lib.common.WebApkMetaDataKeys.WEB_MANIFEST_URL;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -356,6 +357,40 @@ public class WebApkValidator { ...@@ -356,6 +357,40 @@ public class WebApkValidator {
} }
} }
/**
* Determines if a bound WebAPK generated from |manifestUrl| is installed on the device.
* @param context The context to use to check whether WebAPK is valid.
* @param manifestUrl The URL of the manifest that was used to generate the WebAPK.
* @return The WebAPK's package name if installed, or null otherwise.
*/
public static @Nullable String queryBoundWebApkForManifestUrl(
Context context, String manifestUrl) {
assert manifestUrl != null;
List<PackageInfo> packages = context.getPackageManager().getInstalledPackages(
PackageManager.GET_SIGNATURES | PackageManager.GET_META_DATA);
// Filter out unbound & invalid WebAPKs.
for (int i = 0; i < packages.size(); i++) {
PackageInfo info = packages.get(i);
if (!verifyV1WebApk(info, info.packageName)) {
continue;
}
// |info| belongs to a valid, bound, WebAPK. Check that the metadata contains
// |manifestUrl|.
String packageManifestUrl = info.applicationInfo.metaData.getString(WEB_MANIFEST_URL);
if (!TextUtils.equals(packageManifestUrl, manifestUrl)) {
continue;
}
return info.packageName;
}
return null;
}
/** /**
* Initializes the WebApkValidator. * Initializes the WebApkValidator.
* @param expectedSignature V1 WebAPK RSA signature. * @param expectedSignature V1 WebAPK RSA signature.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment