Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2469)

Unified Diff: chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java

Issue 2109033002: Cleanup usage of WebApkValidator in notification code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into notification_platform_bridge Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 44971ea2c8493e9ab7264b58dae138581aedf15f..f51087599cd4cb43741e472c9cd4db31023f7406 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
@@ -57,18 +57,20 @@ public class WebApkValidator {
List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(
intent, PackageManager.GET_RESOLVED_FILTER);
- return findWebApkPackage(resolveInfos);
+ return findWebApkPackage(context, resolveInfos);
}
/**
- * @param The ResolveInfos to search.
+ * @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(List<ResolveInfo> infos) {
+ public static String findWebApkPackage(Context context, List<ResolveInfo> infos) {
for (ResolveInfo info : infos) {
if (info.activityInfo != null
- && info.activityInfo.packageName.startsWith(WEBAPK_PACKAGE_PREFIX)) {
+ && info.activityInfo.packageName.startsWith(WEBAPK_PACKAGE_PREFIX)
+ && isValidWebApk(context, info.activityInfo.packageName)) {
return info.activityInfo.packageName;
}
}
@@ -81,30 +83,28 @@ public class WebApkValidator {
* @param webappPackageName The package name to check
* @return true iff the WebAPK is installed and passes security checks
*/
- public static boolean isValidWebApk(Context context, String webappPackageName) {
+ private static boolean isValidWebApk(Context context, String webappPackageName) {
if (sExpectedSignature == null) {
Log.wtf(TAG, "WebApk validation failure - expected signature not set."
+ "missing call to WebApkValidator.initWithBrowserHostSignature");
}
- if (webappPackageName != null && webappPackageName.startsWith(WEBAPK_PACKAGE_PREFIX)) {
- // check signature
- PackageInfo packageInfo = null;
- try {
- packageInfo = context.getPackageManager().getPackageInfo(webappPackageName,
- PackageManager.GET_SIGNATURES);
- } catch (NameNotFoundException e) {
- e.printStackTrace();
- Log.d(TAG, "WebApk not found");
- return false;
- }
+ // check signature
+ PackageInfo packageInfo = null;
+ try {
+ packageInfo = context.getPackageManager().getPackageInfo(webappPackageName,
+ PackageManager.GET_SIGNATURES);
+ } catch (NameNotFoundException e) {
+ e.printStackTrace();
+ Log.d(TAG, "WebApk not found");
+ return false;
+ }
- final Signature[] arrSignatures = packageInfo.signatures;
- if (arrSignatures != null) {
- for (Signature signature : arrSignatures) {
- if (Arrays.equals(sExpectedSignature, signature.toByteArray())) {
- Log.d(TAG, "WebApk valid - signature match!");
- return true;
- }
+ final Signature[] arrSignatures = packageInfo.signatures;
+ if (arrSignatures != null) {
+ for (Signature signature : arrSignatures) {
+ if (Arrays.equals(sExpectedSignature, signature.toByteArray())) {
+ Log.d(TAG, "WebApk valid - signature match!");
+ return true;
}
}
}

Powered by Google App Engine
This is Rietveld 408576698