OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.webapk.lib.client; | 5 package org.chromium.webapk.lib.client; |
6 | 6 |
7 import static org.chromium.webapk.lib.common.WebApkConstants.WEBAPK_PACKAGE_PREF IX; | 7 import static org.chromium.webapk.lib.common.WebApkConstants.WEBAPK_PACKAGE_PREF IX; |
8 | 8 |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 } | 61 } |
62 | 62 |
63 /** | 63 /** |
64 * @param context The context to use to check whether WebAPK is valid. | 64 * @param context The context to use to check whether WebAPK is valid. |
65 * @param infos The ResolveInfos to search. | 65 * @param infos The ResolveInfos to search. |
66 * @return Package name of the ResolveInfo which corresponds to a WebAPK. Nu ll if none of the | 66 * @return Package name of the ResolveInfo which corresponds to a WebAPK. Nu ll if none of the |
67 * ResolveInfos corresponds to a WebAPK. | 67 * ResolveInfos corresponds to a WebAPK. |
68 */ | 68 */ |
69 public static String findWebApkPackage(Context context, List<ResolveInfo> in fos) { | 69 public static String findWebApkPackage(Context context, List<ResolveInfo> in fos) { |
70 for (ResolveInfo info : infos) { | 70 for (ResolveInfo info : infos) { |
71 if (info.activityInfo != null | 71 if (info.activityInfo != null |
pkotwicz
2017/01/18 02:08:21
Can you move line 72 to the isValidWebApk() functi
pkotwicz
2017/01/19 19:37:16
^^^ I think you missed this comment
gonzalon
2017/01/19 23:50:15
Done.
| |
72 && info.activityInfo.packageName.startsWith(WEBAPK_PACKAGE_P REFIX) | 72 && info.activityInfo.packageName.startsWith(WEBAPK_PACKAGE_P REFIX) |
73 && isValidWebApk(context, info.activityInfo.packageName)) { | 73 && isValidWebApk(context, info.activityInfo.packageName)) { |
74 return info.activityInfo.packageName; | 74 return info.activityInfo.packageName; |
75 } | 75 } |
76 } | 76 } |
77 return null; | 77 return null; |
78 } | 78 } |
79 | 79 |
80 /** | 80 /** |
81 * Returns whether the provided WebAPK is installed and passes signature che cks. | 81 * Returns whether the provided WebAPK is installed and passes signature che cks. |
82 * @param context A context | 82 * @param context A context |
83 * @param webappPackageName The package name to check | 83 * @param webappPackageName The package name to check |
84 * @return true iff the WebAPK is installed and passes security checks | 84 * @return true iff the WebAPK is installed and passes security checks |
85 */ | 85 */ |
86 private static boolean isValidWebApk(Context context, String webappPackageNa me) { | 86 public static boolean isValidWebApk(Context context, String webappPackageNam e) { |
87 if (sExpectedSignature == null) { | 87 if (sExpectedSignature == null) { |
88 Log.wtf(TAG, "WebApk validation failure - expected signature not set ." | 88 Log.wtf(TAG, "WebApk validation failure - expected signature not set ." |
89 + "missing call to WebApkValidator.initWithBrowserHostSignat ure"); | 89 + "missing call to WebApkValidator.initWithBrowserHostSignat ure"); |
90 } | 90 } |
91 // check signature | 91 // check signature |
92 PackageInfo packageInfo = null; | 92 PackageInfo packageInfo = null; |
93 try { | 93 try { |
94 packageInfo = context.getPackageManager().getPackageInfo(webappPacka geName, | 94 packageInfo = context.getPackageManager().getPackageInfo(webappPacka geName, |
95 PackageManager.GET_SIGNATURES); | 95 PackageManager.GET_SIGNATURES); |
96 } catch (NameNotFoundException e) { | 96 } catch (NameNotFoundException e) { |
(...skipping 20 matching lines...) Expand all Loading... | |
117 * with for the current host. | 117 * with for the current host. |
118 * @param expectedSignature | 118 * @param expectedSignature |
119 */ | 119 */ |
120 public static void initWithBrowserHostSignature(byte[] expectedSignature) { | 120 public static void initWithBrowserHostSignature(byte[] expectedSignature) { |
121 if (sExpectedSignature != null) { | 121 if (sExpectedSignature != null) { |
122 return; | 122 return; |
123 } | 123 } |
124 sExpectedSignature = Arrays.copyOf(expectedSignature, expectedSignature. length); | 124 sExpectedSignature = Arrays.copyOf(expectedSignature, expectedSignature. length); |
125 } | 125 } |
126 } | 126 } |
OLD | NEW |