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

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

Issue 1965583002: Move //webapk to //chrome/android/webapk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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: webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java
diff --git a/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java b/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java
deleted file mode 100644
index 5acdc7d3ef1a46e41ffcf86861b94bfa66efb74a..0000000000000000000000000000000000000000
--- a/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkValidator.java
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.webapk.lib.client;
-
-import static org.chromium.webapk.lib.common.WebApkConstants.WEB_APK_PACKAGE_PREFIX;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.ResolveInfo;
-import android.content.pm.Signature;
-import android.util.Log;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Checks whether a URL belongs to a WebAPK.
- */
-public class WebApkValidator {
-
- private static final String TAG = "WebApkValidator";
- private static byte[] sExpectedSignature;
-
- /**
- * 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(yfriedman): This can fail if multiple WebAPKs can match the supplied url.
- *
- * @param context The application context.
- * @param url The url to check.
- * @return Package name of WebAPK which can handle the URL. Null if the url should not be
- * handled by a WebAPK.
- */
- public static String queryWebAPKPackage(Context context, String url) {
- Intent intent;
- try {
- intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
- } catch (Exception e) {
- return null;
- }
-
- intent.addCategory(Intent.CATEGORY_BROWSABLE);
- intent.setComponent(null);
- Intent selector = intent.getSelector();
- if (selector != null) {
- selector.addCategory(Intent.CATEGORY_BROWSABLE);
- selector.setComponent(null);
- }
-
- List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(
- intent, PackageManager.GET_RESOLVED_FILTER);
- return findWebAPKPackage(resolveInfos);
- }
-
- /**
- * @param 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) {
- for (ResolveInfo info : infos) {
- if (info.activityInfo != null
- && info.activityInfo.packageName.startsWith(WEB_APK_PACKAGE_PREFIX)) {
- return info.activityInfo.packageName;
- }
- }
- return null;
- }
-
- /**
- * Returns whether the provided WebAPK is installed and passes signature checks.
- * @param context A context
- * @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) {
- if (sExpectedSignature == null) {
- Log.wtf(TAG, "WebApk validation failure - expected signature not set."
- + "missing call to WebApkValidator.initWithBrowserHostSignature");
- }
- if (webappPackageName != null && webappPackageName.startsWith(WEB_APK_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;
- }
-
- 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;
- }
- }
- }
- }
- Log.d(TAG, "WebApk invalid");
- return false;
- }
-
- /**
- * Initializes the WebApkValidator with the expected signature that WebAPKs must be signed
- * with for the current host.
- * @param expectedSignature
- */
- public static void initWithBrowserHostSignature(byte[] expectedSignature) {
- sExpectedSignature = expectedSignature;
- }
-}

Powered by Google App Engine
This is Rietveld 408576698