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

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: move <meta-data> to pay activity 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 28 matching lines...) Expand all
58 ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); 62 ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
59 try { 63 try {
60 return ContextUtils.getApplicationContext().getPackageManager().quer yIntentActivities( 64 return ContextUtils.getApplicationContext().getPackageManager().quer yIntentActivities(
61 intent, 0); 65 intent, 0);
62 } finally { 66 } finally {
63 StrictMode.setThreadPolicy(oldPolicy); 67 StrictMode.setThreadPolicy(oldPolicy);
64 } 68 }
65 } 69 }
66 70
67 /** 71 /**
72 * Retrieves the list of activities that can respond to the given intent. An d returns the
73 * activites' meta data in ResolveInfo.
74 *
75 * @param intent The intent to query.
76 * @return The list of activities that can respond to the intent.
77 */
78 public List<ResolveInfo> getActivitiesThatCanRespondToIntentWithMetaData(Int ent intent) {
79 ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
80 try {
81 return ContextUtils.getApplicationContext().getPackageManager().quer yIntentActivities(
82 intent, PackageManager.GET_META_DATA);
83 } finally {
84 StrictMode.setThreadPolicy(oldPolicy);
85 }
86 }
87
88 /**
68 * Retrieves the list of services that can respond to the given intent. 89 * Retrieves the list of services that can respond to the given intent.
69 * @param intent The intent to query. 90 * @param intent The intent to query.
70 * @return The list of services that can respond to the intent. 91 * @return The list of services that can respond to the intent.
71 */ 92 */
72 public List<ResolveInfo> getServicesThatCanRespondToIntent(Intent intent) { 93 public List<ResolveInfo> getServicesThatCanRespondToIntent(Intent intent) {
73 ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); 94 ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
74 try { 95 try {
75 return ContextUtils.getApplicationContext().getPackageManager().quer yIntentServices( 96 return ContextUtils.getApplicationContext().getPackageManager().quer yIntentServices(
76 intent, 0); 97 intent, 0);
77 } finally { 98 } finally {
(...skipping 11 matching lines...) Expand all
89 } 110 }
90 111
91 /** 112 /**
92 * Retrieves the icon of the app. 113 * Retrieves the icon of the app.
93 * @param resolveInfo The identifying information for an app. 114 * @param resolveInfo The identifying information for an app.
94 * @return The icon for this app. 115 * @return The icon for this app.
95 */ 116 */
96 public Drawable getAppIcon(ResolveInfo resolveInfo) { 117 public Drawable getAppIcon(ResolveInfo resolveInfo) {
97 return resolveInfo.loadIcon(ContextUtils.getApplicationContext().getPack ageManager()); 118 return resolveInfo.loadIcon(ContextUtils.getApplicationContext().getPack ageManager());
98 } 119 }
120
121 /**
122 * Gets the resources of the given application.
123 *
124 * @param applicationInfo The given application info.
125 * @return The resources.
126 */
127 @Nullable
128 public Resources getResourcesForApplication(ApplicationInfo applicationInfo) {
129 Resources resources;
130 try {
131 resources = ContextUtils.getApplicationContext()
132 .getPackageManager()
133 .getResourcesForApplication(applicationInfo);
134 } catch (NameNotFoundException e) {
135 return null;
136 }
137 return resources;
138 }
99 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698