@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)
Deprecated.
|
void |
addPackage(android.content.pm.PackageInfo packageInfo,
android.content.pm.PackageStats packageStats)
Installs a package with its stats with the
PackageManager . |
void |
addPackage(java.lang.String packageName)
Deprecated.
Use
installPackage(PackageInfo) instead. |
void |
addPackageInternal(android.content.pm.PackageParser.Package appPackage)
Internal use only.
|
void |
addPackageNoDefaults(android.content.pm.PackageInfo packageInfo)
Adds a package to the
PackageManager , but doesn’t set any default values on it. |
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)
Adds extra resolve info for an intent.
|
void |
addResolveInfoForIntentNoDefaults(android.content.Intent intent,
android.content.pm.ResolveInfo info)
Adds the
info as ResolveInfo for the intent but without applying any default values. |
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.
|
android.content.pm.PackageInfo |
getInternalMutablePackageInfo(java.lang.String packageName)
Testing API allowing to retrieve internal package representation.
|
protected android.content.pm.PackageInfo |
getPackageArchiveInfo(java.lang.String archiveFilePath,
int flags) |
android.content.pm.PackageInfo |
getPackageInfoForTesting(java.lang.String packageName)
Deprecated.
Use
getInternalMutablePackageInfo(java.lang.String) instead. It has better name. |
ShadowPackageManager.PackageSetting |
getPackageSetting(java.lang.String packageName)
Returns the current
ShadowPackageManager.PackageSetting of packageName . |
protected java.lang.String[] |
getPackagesForUid(int uid) |
long |
getVerificationExtendedTimeout(int id) |
int |
getVerificationResult(int id) |
void |
installPackage(android.content.pm.PackageInfo packageInfo)
Installs a package with the
PackageManager . |
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.
Note that all resolve infos will have ResolveInfo.isDefault
field set to true
to allow their resolution for implicit intents. If this is not what you want, then you still have the reference to those ResolveInfos, and you can set the field back to false
.
@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)
Adds extra resolve info for an intent.
Note that this resolve info will have ResolveInfo.isDefault
field set to true
to allow its resolution for implicit intents. If this is not what you want, then please use addResolveInfoForIntentNoDefaults(android.content.Intent, android.content.pm.ResolveInfo)
instead.
public void addResolveInfoForIntentNoDefaults(android.content.Intent intent, android.content.pm.ResolveInfo info)
Adds the info
as ResolveInfo
for the intent but without applying any default values.
In particular it will not make the ResolveInfo.isDefault
field true
, that means that this resolve info will not resolve for Intent.resolveActivity(android.content.pm.PackageManager)
and Context.startActivity(android.content.Intent)
.
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.public void installPackage(android.content.pm.PackageInfo packageInfo)
Installs a package with the PackageManager
.
In order to create PackageInfo objects in a valid state please use androidx.test.core.content.pm.PackageInfoBuilder
.
This method automatically simulates instalation of a package in the system, so it adds a flag ApplicationInfo.FLAG_INSTALLED
to the application info and makes sure it exits. It will update applicationInfo in package components as well.
If you don’t want the package to be installed, use addPackageNoDefaults(android.content.pm.PackageInfo)
instead.
public void addPackageNoDefaults(android.content.pm.PackageInfo packageInfo)
Adds a package to the PackageManager
, but doesn’t set any default values on it.
Right now it will not set ApplicationInfo.FLAG_INSTALLED
flag on its application, so if not set explicitly, it will be treated as not installed.
public void addPackage(android.content.pm.PackageInfo packageInfo, android.content.pm.PackageStats packageStats)
Installs a package with its stats with the PackageManager
.
This method doesn’t add any defaults to the packageInfo
parameters. You should make sure it is valid (see installPackage(PackageInfo)
).
@Deprecated public void addPackage(java.lang.String packageName)
installPackage(PackageInfo)
instead.@Deprecated public void addPackage(android.content.pm.PackageInfo packageInfo)
This method is getting renamed to {link installPackage(android.content.pm.PackageInfo)
.
public android.content.pm.PackageInfo getInternalMutablePackageInfo(java.lang.String packageName)
Testing API allowing to retrieve internal package representation.
This will allow to modify the package in a way visible to Robolectric, as this is Robolectric’s internal full package representation.
Note that maybe a better way is to just modify the test manifest to make those modifications in a standard way.
Retrieving package info using PackageManager.getPackageInfo(java.lang.String, int)
/ PackageManager.getApplicationInfo(java.lang.String, int)
will return defensive copies that will be stripped out of information according to provided flags. Don’t use it to modify Robolectric state.
@Deprecated public android.content.pm.PackageInfo getPackageInfoForTesting(java.lang.String packageName)
getInternalMutablePackageInfo(java.lang.String)
instead. It has better name.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)
@Implementation protected java.lang.String[] getPackagesForUid(int uid)
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()