Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.payments; | |
| 6 | |
| 7 import android.content.Intent; | |
| 8 import android.content.pm.PackageInfo; | |
| 9 import android.content.pm.PackageManager; | |
| 10 import android.content.pm.PackageManager.NameNotFoundException; | |
| 11 import android.content.pm.ResolveInfo; | |
| 12 import android.graphics.drawable.Drawable; | |
| 13 import android.os.StrictMode; | |
| 14 import android.os.StrictMode.ThreadPolicy; | |
| 15 | |
| 16 import org.chromium.base.ContextUtils; | |
| 17 | |
| 18 import java.util.List; | |
| 19 | |
| 20 /** Abstraction of Android's package manager to enable unit testing. */ | |
| 21 public class PackageManagerDelegate { | |
|
Ted C
2017/03/13 21:13:34
Potentially out of scope of this change, but I won
please use gerrit instead
2017/03/13 22:19:54
That sounds like a good plan in general for a futu
| |
| 22 /** | |
| 23 * Retrieves package information of an installed application. | |
| 24 * | |
| 25 * @param packageName The package name of an installed application. | |
| 26 * @return The package information of the installed application. | |
| 27 */ | |
| 28 public PackageInfo getPackageInfoWithSignatures(String packageName) { | |
| 29 try { | |
| 30 return ContextUtils.getApplicationContext().getPackageManager().getP ackageInfo( | |
| 31 packageName, PackageManager.GET_SIGNATURES); | |
| 32 } catch (NameNotFoundException e) { | |
| 33 return null; | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 /** | |
| 38 * Retrieves the single activity that matches the given intent, or null if n one found. | |
| 39 * @param intent The intent to query. | |
| 40 * @return The matching activity. | |
| 41 */ | |
| 42 public ResolveInfo resolveActivity(Intent intent) { | |
| 43 ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | |
| 44 try { | |
| 45 return ContextUtils.getApplicationContext().getPackageManager().reso lveActivity( | |
| 46 intent, 0); | |
| 47 } finally { | |
| 48 StrictMode.setThreadPolicy(oldPolicy); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * Retrieves the list of activities that can respond to the given intent. | |
| 54 * @param intent The intent to query. | |
| 55 * @return The list of activities that can respond to the intent. | |
| 56 */ | |
| 57 public List<ResolveInfo> getActivitiesThatCanRespondToIntent(Intent intent) { | |
| 58 ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | |
| 59 try { | |
| 60 return ContextUtils.getApplicationContext().getPackageManager().quer yIntentActivities( | |
| 61 intent, 0); | |
| 62 } finally { | |
| 63 StrictMode.setThreadPolicy(oldPolicy); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 /** | |
| 68 * Retrieves the list of services that can respond to the given intent. | |
| 69 * @param intent The intent to query. | |
| 70 * @return The list of services that can respond to the intent. | |
| 71 */ | |
| 72 public List<ResolveInfo> getServicesThatCanRespondToIntent(Intent intent) { | |
| 73 ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | |
| 74 try { | |
| 75 return ContextUtils.getApplicationContext().getPackageManager().quer yIntentServices( | |
| 76 intent, 0); | |
| 77 } finally { | |
| 78 StrictMode.setThreadPolicy(oldPolicy); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 /** | |
| 83 * Retrieves the label of the app. | |
| 84 * @param resolveInfo The identifying information for an app. | |
| 85 * @return The label for this app. | |
| 86 */ | |
| 87 public CharSequence getAppLabel(ResolveInfo resolveInfo) { | |
| 88 return resolveInfo.loadLabel(ContextUtils.getApplicationContext().getPac kageManager()); | |
| 89 } | |
| 90 | |
| 91 /** | |
| 92 * Retrieves the icon of the app. | |
| 93 * @param resolveInfo The identifying information for an app. | |
| 94 * @return The icon for this app. | |
| 95 */ | |
| 96 public Drawable getAppIcon(ResolveInfo resolveInfo) { | |
| 97 return resolveInfo.loadIcon(ContextUtils.getApplicationContext().getPack ageManager()); | |
| 98 } | |
| 99 } | |
| OLD | NEW |