@Implements(value=android.content.pm.PackageManager.class) public class ShadowPackageManager extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected static class |
ShadowPackageManager.ComponentState |
static class |
ShadowPackageManager.IntentComparator |
protected static class |
ShadowPackageManager.IntentFilterWrapper
This class wraps
IntentFilter so it has reasonable ShadowPackageManager.IntentFilterWrapper.equals(java.lang.Object) and ShadowPackageManager.IntentFilterWrapper.hashCode() methods. |
static class |
ShadowPackageManager.PackageSetting
Settings for a particular package.
|
Modifier and Type | Field and Description |
---|---|
static java.util.Map<java.lang.String,android.content.res.Resources> |
resources |
Constructor and Description |
---|
ShadowPackageManager() |
Modifier and Type | Method and Description |
---|---|
void |
addActivityIcon(android.content.ComponentName component,
android.graphics.drawable.Drawable drawable) |
void |
addActivityIcon(android.content.Intent intent,
android.graphics.drawable.Drawable drawable) |
void |
addChangedPackage(int sequenceNumber,
java.lang.String packageName)
Adds
packageName to the list of changed packages for the particular sequenceNumber . |
void |
addCurrentToCannonicalName(java.lang.String currentName,
java.lang.String canonicalName) |
void |
addDrawableResolution(java.lang.String packageName,
int resourceId,
android.graphics.drawable.Drawable drawable) |
void |
addPackage(android.content.pm.PackageInfo packageInfo)
Registers (“installs”) a package with the PackageManager.
|
void |
addPackage(android.content.pm.PackageInfo packageInfo,
android.content.pm.PackageStats packageStats) |
void |
addPackage(java.lang.String packageName)
Deprecated.
Use
addPackage(PackageInfo) instead. |
void |
addPackageInternal(android.content.pm.PackageParser.Package appPackage)
Internal use only.
|
void |
addPermissionGroupInfo(android.content.pm.PermissionGroupInfo permissionGroupInfo)
Allows overriding or adding permission-group elements.
|
void |
addPermissionInfo(android.content.pm.PermissionInfo permissionInfo) |
void |
addResolveInfoForIntent(android.content.Intent intent,
java.util.List<android.content.pm.ResolveInfo> info)
Deprecated.
|
void |
addResolveInfoForIntent(android.content.Intent intent,
android.content.pm.ResolveInfo info) |
void |
addSystemAvailableFeature(android.content.pm.FeatureInfo featureInfo) |
void |
addSystemSharedLibraryName(java.lang.String name)
Adds a value to be returned by
PackageManager.getSystemSharedLibraryNames() . |
void |
clearSystemAvailableFeatures() |
void |
clearSystemSharedLibraryNames()
Clears the values returned by
PackageManager.getSystemSharedLibraryNames() . |
void |
doPendingUninstallCallbacks()
Runs the callbacks pending from calls to
PackageManager.deletePackage(String,
IPackageDeleteObserver, int) |
protected void |
freeStorage(long freeStorageSize,
android.content.IntentSender pi) |
protected void |
freeStorageAndNotify(long freeStorageSize,
android.content.pm.IPackageDataObserver observer) |
int |
getComponentEnabledSettingFlags(android.content.ComponentName componentName)
Return the flags set in call to
ApplicationPackageManager.setComponentEnabledSetting(ComponentName, int, int) . |
java.util.Set<java.lang.String> |
getDeletedPackages()
Returns package names successfully deleted with
PackageManager.deletePackage(String,
IPackageDeleteObserver, int) Note that like real PackageManager the calling context must have Manifest.permission.DELETE_PACKAGES permission set. |
java.util.List<android.content.IntentFilter> |
getIntentFiltersForActivity(android.content.ComponentName componentName)
Get list of intent filters defined for given activity.
|
java.util.List<android.content.IntentFilter> |
getIntentFiltersForReceiver(android.content.ComponentName componentName)
Get list of intent filters defined for given receiver.
|
java.util.List<android.content.IntentFilter> |
getIntentFiltersForService(android.content.ComponentName componentName)
Get list of intent filters defined for given service.
|
protected android.content.pm.PackageInfo |
getPackageArchiveInfo(java.lang.String archiveFilePath,
int flags) |
ShadowPackageManager.PackageSetting |
getPackageSetting(java.lang.String packageName)
Returns the current
ShadowPackageManager.PackageSetting of packageName . |
long |
getVerificationExtendedTimeout(int id) |
int |
getVerificationResult(int id) |
protected java.util.List<android.content.pm.ResolveInfo> |
queryBroadcastReceivers(android.content.Intent intent,
int flags,
int userId) |
protected java.util.List<android.content.pm.ResolveInfo> |
queryBroadcastReceiversAsUser(android.content.Intent intent,
int flags,
android.os.UserHandle userHandle) |
protected java.util.List<android.content.pm.ResolveInfo> |
queryOverriddenIntents(android.content.Intent intent,
int flags) |
void |
removePackage(java.lang.String packageName) |
void |
removeResolveInfosForIntent(android.content.Intent intent,
java.lang.String packageName) |
static void |
reset() |
void |
setApplicationIcon(java.lang.String packageName,
android.graphics.drawable.Drawable drawable) |
void |
setCanRequestPackageInstalls(boolean canRequestPackageInstalls)
Sets if the
PackageManager is allowed to request package installs through package installer. |
void |
setNameForUid(int uid,
java.lang.String name) |
void |
setPackageArchiveInfo(java.lang.String archiveFilePath,
android.content.pm.PackageInfo packageInfo) |
void |
setPackagesForCallingUid(java.lang.String... packagesForCallingUid) |
void |
setPackagesForUid(int uid,
java.lang.String... packagesForCallingUid) |
void |
setResolveInfosForIntent(android.content.Intent intent,
java.util.List<android.content.pm.ResolveInfo> info)
Sets extra resolve infos for an intent.
|
void |
setShouldShowRequestPermissionRationale(java.lang.String permission,
boolean show) |
void |
setSystemFeature(java.lang.String name,
boolean supported) |
void |
setUnbadgedApplicationIcon(java.lang.String packageName,
android.graphics.drawable.Drawable drawable) |
public static java.util.Map<java.lang.String,android.content.res.Resources> resources
public void setResolveInfosForIntent(android.content.Intent intent, java.util.List<android.content.pm.ResolveInfo> info)
Sets extra resolve infos for an intent.
Those entries are added to whatever might be in the manifest already.
@Deprecated public void addResolveInfoForIntent(android.content.Intent intent, java.util.List<android.content.pm.ResolveInfo> info)
setResolveInfosForIntent(android.content.Intent, java.util.List<android.content.pm.ResolveInfo>)
or addResolveInfoForIntent(Intent, ResolveInfo)
instead.public void addResolveInfoForIntent(android.content.Intent intent, android.content.pm.ResolveInfo info)
public void removeResolveInfosForIntent(android.content.Intent intent, java.lang.String packageName)
public void addActivityIcon(android.content.ComponentName component, android.graphics.drawable.Drawable drawable)
public void addActivityIcon(android.content.Intent intent, android.graphics.drawable.Drawable drawable)
public void setApplicationIcon(java.lang.String packageName, android.graphics.drawable.Drawable drawable)
public void setUnbadgedApplicationIcon(java.lang.String packageName, android.graphics.drawable.Drawable drawable)
public int getComponentEnabledSettingFlags(android.content.ComponentName componentName)
Return the flags set in call to ApplicationPackageManager.setComponentEnabledSetting(ComponentName, int, int)
.
componentName
- The component name.@Deprecated public void addPackage(java.lang.String packageName)
addPackage(PackageInfo)
instead.public void addPackage(android.content.pm.PackageInfo packageInfo)
Registers (“installs”) a package with the PackageManager.
In order to create PackageInfo objects in a valid state please use androidx.test.core.content.pm.PackageInfoBuilder
.
public void addPackage(android.content.pm.PackageInfo packageInfo, android.content.pm.PackageStats packageStats)
public void addPermissionInfo(android.content.pm.PermissionInfo permissionInfo)
public void addChangedPackage(int sequenceNumber, java.lang.String packageName)
Adds packageName
to the list of changed packages for the particular sequenceNumber
.
sequenceNumber
- has to be >= 0packageName
- name of the package that was changedpublic void addPermissionGroupInfo(android.content.pm.PermissionGroupInfo permissionGroupInfo)
Allows overriding or adding permission-group elements. These would be otherwise specified by either (the system)[https://developer.android.com/guide/topics/permissions/requesting.html#perm-groups] or by (the app itself)[https://developer.android.com/guide/topics/manifest/permission-group-element.html], as part of its manifest
PackageParser.PermissionGroup
s added through this method have precedence over those specified with the same name by one of the aforementioned methods.
PackageManager.getAllPermissionGroups(int)
,
PackageManager.getPermissionGroupInfo(String, int)
public void removePackage(java.lang.String packageName)
public void setSystemFeature(java.lang.String name, boolean supported)
public void addDrawableResolution(java.lang.String packageName, int resourceId, android.graphics.drawable.Drawable drawable)
public void setNameForUid(int uid, java.lang.String name)
public void setPackagesForCallingUid(java.lang.String... packagesForCallingUid)
public void setPackagesForUid(int uid, java.lang.String... packagesForCallingUid)
public void setPackageArchiveInfo(java.lang.String archiveFilePath, android.content.pm.PackageInfo packageInfo)
public int getVerificationResult(int id)
public long getVerificationExtendedTimeout(int id)
public void setShouldShowRequestPermissionRationale(java.lang.String permission, boolean show)
public void addSystemAvailableFeature(android.content.pm.FeatureInfo featureInfo)
public void clearSystemAvailableFeatures()
public void addSystemSharedLibraryName(java.lang.String name)
Adds a value to be returned by PackageManager.getSystemSharedLibraryNames()
.
public void clearSystemSharedLibraryNames()
Clears the values returned by PackageManager.getSystemSharedLibraryNames()
.
public void addCurrentToCannonicalName(java.lang.String currentName, java.lang.String canonicalName)
public void setCanRequestPackageInstalls(boolean canRequestPackageInstalls)
Sets if the PackageManager
is allowed to request package installs through package installer.
@Implementation(minSdk=24) protected java.util.List<android.content.pm.ResolveInfo> queryBroadcastReceiversAsUser(android.content.Intent intent, int flags, android.os.UserHandle userHandle)
@Implementation(minSdk=17) protected java.util.List<android.content.pm.ResolveInfo> queryBroadcastReceivers(android.content.Intent intent, int flags, int userId)
@Implementation protected android.content.pm.PackageInfo getPackageArchiveInfo(java.lang.String archiveFilePath, int flags)
@Implementation protected void freeStorageAndNotify(long freeStorageSize, android.content.pm.IPackageDataObserver observer)
@Implementation protected void freeStorage(long freeStorageSize, android.content.IntentSender pi)
public void doPendingUninstallCallbacks()
Runs the callbacks pending from calls to PackageManager.deletePackage(String,
IPackageDeleteObserver, int)
public java.util.Set<java.lang.String> getDeletedPackages()
Returns package names successfully deleted with PackageManager.deletePackage(String,
IPackageDeleteObserver, int)
Note that like real PackageManager
the calling context must have Manifest.permission.DELETE_PACKAGES
permission set.
protected java.util.List<android.content.pm.ResolveInfo> queryOverriddenIntents(android.content.Intent intent, int flags)
public void addPackageInternal(android.content.pm.PackageParser.Package appPackage)
Internal use only.
appPackage
- public java.util.List<android.content.IntentFilter> getIntentFiltersForActivity(android.content.ComponentName componentName) throws android.content.pm.PackageManager.NameNotFoundException
Get list of intent filters defined for given activity.
componentName
- Name of the activity whose intent filters are to be retrievedandroid.content.pm.PackageManager.NameNotFoundException
public java.util.List<android.content.IntentFilter> getIntentFiltersForService(android.content.ComponentName componentName) throws android.content.pm.PackageManager.NameNotFoundException
Get list of intent filters defined for given service.
componentName
- Name of the service whose intent filters are to be retrievedandroid.content.pm.PackageManager.NameNotFoundException
public java.util.List<android.content.IntentFilter> getIntentFiltersForReceiver(android.content.ComponentName componentName) throws android.content.pm.PackageManager.NameNotFoundException
Get list of intent filters defined for given receiver.
componentName
- Name of the receiver whose intent filters are to be retrievedandroid.content.pm.PackageManager.NameNotFoundException
public ShadowPackageManager.PackageSetting getPackageSetting(java.lang.String packageName)
Returns the current ShadowPackageManager.PackageSetting
of packageName
.
If packageName
is not present in this ShadowPackageManager
, this method will return null.
@Resetter public static void reset()