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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/PackageManagerDelegate.java

Issue 2793573002: [Payments] Use <meta-data> tag instead of intent filter data to detect supported payment methods. (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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.chrome.browser.payments; 5 package org.chromium.chrome.browser.payments;
6 6
7 import android.content.Intent; 7 import android.content.Intent;
8 import android.content.pm.ApplicationInfo;
8 import android.content.pm.PackageInfo; 9 import android.content.pm.PackageInfo;
9 import android.content.pm.PackageManager; 10 import android.content.pm.PackageManager;
10 import android.content.pm.PackageManager.NameNotFoundException; 11 import android.content.pm.PackageManager.NameNotFoundException;
11 import android.content.pm.ResolveInfo; 12 import android.content.pm.ResolveInfo;
13 import android.content.res.Resources;
12 import android.graphics.drawable.Drawable; 14 import android.graphics.drawable.Drawable;
13 import android.os.StrictMode; 15 import android.os.StrictMode;
14 import android.os.StrictMode.ThreadPolicy; 16 import android.os.StrictMode.ThreadPolicy;
15 17
16 import org.chromium.base.ContextUtils; 18 import org.chromium.base.ContextUtils;
17 19
18 import java.util.List; 20 import java.util.List;
19 21
22 import javax.annotation.Nullable;
23
20 /** Abstraction of Android's package manager to enable unit testing. */ 24 /** Abstraction of Android's package manager to enable unit testing. */
21 public class PackageManagerDelegate { 25 public class PackageManagerDelegate {
22 /** 26 /**
23 * Retrieves package information of an installed application. 27 * Retrieves package information of an installed application.
24 * 28 *
25 * @param packageName The package name of an installed application. 29 * @param packageName The package name of an installed application.
26 * @return The package information of the installed application. 30 * @return The package information of the installed application.
27 */ 31 */
28 public PackageInfo getPackageInfoWithSignatures(String packageName) { 32 public PackageInfo getPackageInfoWithSignatures(String packageName) {
29 try { 33 try {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 93 }
90 94
91 /** 95 /**
92 * Retrieves the icon of the app. 96 * Retrieves the icon of the app.
93 * @param resolveInfo The identifying information for an app. 97 * @param resolveInfo The identifying information for an app.
94 * @return The icon for this app. 98 * @return The icon for this app.
95 */ 99 */
96 public Drawable getAppIcon(ResolveInfo resolveInfo) { 100 public Drawable getAppIcon(ResolveInfo resolveInfo) {
97 return resolveInfo.loadIcon(ContextUtils.getApplicationContext().getPack ageManager()); 101 return resolveInfo.loadIcon(ContextUtils.getApplicationContext().getPack ageManager());
98 } 102 }
103
104 /**
105 * Gets the given string array meta data from the given app.
106 *
107 * @param packageName The package name of the app containing the meta data.
108 * @param metaDataName The meta data name of the string array.
109 * @return The string array or null.
110 */
111 @Nullable
112 public String[] getStringArrayMetaData(String packageName, String metaDataNa me) {
113 try {
114 PackageManager packageManager =
115 ContextUtils.getApplicationContext().getPackageManager();
116 ApplicationInfo appInfo =
117 packageManager.getApplicationInfo(packageName, PackageManage r.GET_META_DATA);
118 if (appInfo.metaData == null) return null;
119
120 int resId = appInfo.metaData.getInt(metaDataName);
121 Resources resources = packageManager.getResourcesForApplication(appI nfo);
122 return resources.getStringArray(resId);
123 } catch (NameNotFoundException e) {
please use gerrit instead 2017/03/31 15:47:08 Let's wrap in try-catch only the function that thr
gogerald1 2017/03/31 16:18:44 Done. getResourcesForApplication might also throug
124 return null;
125 }
126 }
127
128 /**
129 * Gets the given string meta data from the given app.
130 *
131 * @param packageName The package name of the app containing the meta data.
132 * @param metaDataName The meta data name of the string.
133 * @return The string or null.
134 */
135 @Nullable
136 public String getStringMetaData(String packageName, String metaDataName) {
137 try {
138 PackageManager packageManager =
139 ContextUtils.getApplicationContext().getPackageManager();
140 ApplicationInfo appInfo =
141 packageManager.getApplicationInfo(packageName, PackageManage r.GET_META_DATA);
142 if (appInfo.metaData == null) return null;
143
144 return appInfo.metaData.getString(metaDataName);
145 } catch (NameNotFoundException e) {
please use gerrit instead 2017/03/31 15:47:08 Ditto.
gogerald1 2017/03/31 16:18:44 Done. Ditto
146 return null;
147 }
148 }
99 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698