ShadowApplicationPackageManager
@Implements(android.content.pm.PackageManager.class) public class ShadowPackageManager extends Object
Modifier and Type | Class | Description |
---|---|---|
protected static class |
ShadowPackageManager.ComponentState |
|
static class |
ShadowPackageManager.IntentComparator |
|
static class |
ShadowPackageManager.PackageSetting |
Settings for a particular package.
|
Constructor | Description |
---|---|
ShadowPackageManager() |
Modifier and Type | Method | Description |
---|---|---|
void |
addActivityIcon(ComponentName component,
Drawable drawable) |
|
void |
addActivityIcon(Intent intent,
Drawable drawable) |
|
ActivityInfo |
addActivityIfNotPresent(ComponentName componentName) |
Makes sure that given activity exists.
|
void |
addCanonicalName(String currentName,
String canonicalName) |
Adds a canonical package name for a package.
|
void |
addChangedPackage(int sequenceNumber,
String packageName) |
Adds
packageName to the list of changed packages for the particular
sequenceNumber . |
void |
addCurrentToCannonicalName(String currentName,
String canonicalName) |
Deprecated.
|
void |
addDrawableResolution(String packageName,
int resourceId,
Drawable drawable) |
|
void |
addIntentFilterForActivity(ComponentName componentName,
IntentFilter filter) |
Add intent filter for given activity.
|
void |
addIntentFilterForProvider(ComponentName componentName,
IntentFilter filter) |
Add intent filter for given provider.
|
void |
addIntentFilterForReceiver(ComponentName componentName,
IntentFilter filter) |
Add intent filter for given receiver.
|
void |
addIntentFilterForService(ComponentName componentName,
IntentFilter filter) |
Add intent filter for given service.
|
void |
addOrUpdateActivity(ActivityInfo activityInfo) |
Adds or updates given activity in the system.
|
void |
addOrUpdateProvider(ProviderInfo providerInfo) |
Adds or updates given content provider in the system.
|
void |
addOrUpdateReceiver(ActivityInfo receiverInfo) |
Adds or updates given broadcast receiver in the system.
|
void |
addOrUpdateService(ServiceInfo serviceInfo) |
Adds or updates given service in the system.
|
void |
addPackage(PackageInfo packageInfo) |
Deprecated.
|
void |
addPackage(PackageInfo packageInfo,
PackageStats packageStats) |
Installs a package with its stats with the
PackageManager . |
void |
addPackage(String packageName) |
Deprecated.
Use
installPackage(PackageInfo) instead. |
void |
addPackageInternal(PackageParser.Package appPackage) |
Internal use only.
|
void |
addPackageNoDefaults(PackageInfo packageInfo) |
Adds a package to the
PackageManager , but doesn't set any default values on it. |
void |
addPermissionGroupInfo(PermissionGroupInfo permissionGroupInfo) |
Allows overriding or adding permission-group elements.
|
void |
addPermissionInfo(PermissionInfo permissionInfo) |
|
protected static void |
addPreferredActivityInternal(IntentFilter filter,
ComponentName activity,
SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap) |
|
ProviderInfo |
addProviderIfNotPresent(ComponentName componentName) |
Makes sure that given provider exists.
|
ActivityInfo |
addReceiverIfNotPresent(ComponentName componentName) |
Makes sure that given receiver exists.
|
void |
addResolveInfoForIntent(Intent intent,
ResolveInfo info) |
Deprecated.
use
addIntentFilterForComponent(android.content.ComponentName, android.content.IntentFilter, java.util.Map<android.content.ComponentName, java.util.List<android.content.IntentFilter>>) instead and if the component doesn't exist
add it using any of installPackage(android.content.pm.PackageInfo) , addOrUpdateActivity(android.content.pm.ActivityInfo) , addActivityIfNotPresent(android.content.ComponentName) or their counterparts for other types of components. |
void |
addResolveInfoForIntent(Intent intent,
List<ResolveInfo> info) |
Deprecated.
see note on
addResolveInfoForIntent(Intent, ResolveInfo) . |
void |
addResolveInfoForIntentNoDefaults(Intent intent,
ResolveInfo info) |
Deprecated.
see the note on
addResolveInfoForIntent(Intent, ResolveInfo) . |
ServiceInfo |
addServiceIfNotPresent(ComponentName componentName) |
Makes sure that given service exists.
|
void |
addSystemAvailableFeature(FeatureInfo featureInfo) |
|
void |
addSystemSharedLibraryName(String name) |
Adds a value to be returned by
PackageManager.getSystemSharedLibraryNames() . |
void |
clearIntentFilterForActivity(ComponentName componentName) |
Clears intent filters for given activity.
|
void |
clearIntentFilterForProvider(ComponentName componentName) |
Clears intent filters for given provider.
|
void |
clearIntentFilterForReceiver(ComponentName componentName) |
Clears intent filters for given receiver.
|
void |
clearIntentFilterForService(ComponentName componentName) |
Clears intent filters for given service.
|
protected static void |
clearPackagePreferredActivitiesInternal(String packageName,
SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap) |
|
void |
clearSystemAvailableFeatures() |
|
void |
clearSystemSharedLibraryNames() |
Clears the values returned by
PackageManager.getSystemSharedLibraryNames() . |
Object |
deleteModule(String packageName) |
Deletes a module when given the module's package name
ModuleInfo be sure to give the
correct name as this method does not ensure existence of the module before deletion. |
void |
deletePackage(String packageName) |
Uninstalls the package from the system in a way, that will allow its discovery through
PackageManager.MATCH_UNINSTALLED_PACKAGES . |
protected void |
deletePackage(String packageName,
IPackageDeleteObserver observer,
int flags) |
|
void |
doPendingUninstallCallbacks() |
Runs the callbacks pending from calls to
PackageManager.deletePackage(String,
IPackageDeleteObserver, int) |
protected void |
freeStorage(long freeStorageSize,
IntentSender pi) |
|
protected void |
freeStorageAndNotify(long freeStorageSize,
IPackageDataObserver observer) |
|
int |
getComponentEnabledSettingFlags(ComponentName componentName) |
Return the flags set in call to
ApplicationPackageManager.setComponentEnabledSetting(ComponentName, int, int) . |
Set<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. |
int |
getDistractingPackageRestrictions(String pkg) |
Returns the last value provided to
setDistractingPackageRestrictions for pkg . |
List<IntentFilter> |
getIntentFiltersForActivity(ComponentName componentName) |
Get list of intent filters defined for given activity.
|
List<IntentFilter> |
getIntentFiltersForProvider(ComponentName componentName) |
Get list of intent filters defined for given provider.
|
List<IntentFilter> |
getIntentFiltersForReceiver(ComponentName componentName) |
Get list of intent filters defined for given receiver.
|
List<IntentFilter> |
getIntentFiltersForService(ComponentName componentName) |
Get list of intent filters defined for given service.
|
PackageInfo |
getInternalMutablePackageInfo(String packageName) |
Testing API allowing to retrieve internal package representation.
|
protected PackageInfo |
getPackageArchiveInfo(String archiveFilePath,
int flags) |
|
PackageInfo |
getPackageInfoForTesting(String packageName) |
Deprecated.
Use
getInternalMutablePackageInfo(java.lang.String) instead. It has better name. |
ShadowPackageManager.PackageSetting |
getPackageSetting(String packageName) |
Returns the current
ShadowPackageManager.PackageSetting of packageName . |
protected String[] |
getPackagesForUid(int uid) |
|
int |
getPersistentPreferredActivities(List<IntentFilter> outFilters,
List<ComponentName> outActivities,
String packageName) |
Method to retrieve persistent preferred activities as set by
DevicePolicyManager.addPersistentPreferredActivity(android.content.ComponentName, android.content.IntentFilter, android.content.ComponentName) . |
protected static int |
getPreferredActivitiesInternal(List<IntentFilter> outFilters,
List<ComponentName> outActivities,
String packageName,
SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap) |
|
long |
getVerificationExtendedTimeout(int id) |
|
int |
getVerificationResult(int id) |
|
void |
installModule(Object moduleInfoObject) |
Installs a module with the
PackageManager as long as it is not null |
void |
installPackage(PackageInfo packageInfo) |
Installs a package with the
PackageManager . |
protected static <V> SortedMap<ComponentName,V> |
mapForPackage(SortedMap<ComponentName,V> input,
String packageName) |
|
protected List<ResolveInfo> |
queryBroadcastReceivers(Intent intent,
int flags,
int userId) |
|
protected List<ResolveInfo> |
queryBroadcastReceiversAsUser(Intent intent,
int flags,
UserHandle userHandle) |
|
protected List<ResolveInfo> |
queryOverriddenIntents(Intent intent,
int flags) |
|
ActivityInfo |
removeActivity(ComponentName componentName) |
Removes activity from the package manager.
|
void |
removePackage(String packageName) |
|
ProviderInfo |
removeProvider(ComponentName componentName) |
Removes content provider from the package manager.
|
ActivityInfo |
removeReceiver(ComponentName componentName) |
Removes broadcast receiver from the package manager.
|
void |
removeResolveInfosForIntent(Intent intent,
String packageName) |
Deprecated.
see note on
addResolveInfoForIntent(Intent, ResolveInfo) . |
ServiceInfo |
removeService(ComponentName componentName) |
Removes service from the package manager.
|
static void |
reset() |
|
void |
setApplicationIcon(String packageName,
Drawable drawable) |
|
void |
setCanRequestPackageInstalls(boolean canRequestPackageInstalls) |
Sets if the
PackageManager is allowed to request package installs through package
installer. |
void |
setNameForUid(int uid,
String name) |
|
void |
setPackageArchiveInfo(String archiveFilePath,
PackageInfo packageInfo) |
|
void |
setPackagesForCallingUid(String... packagesForCallingUid) |
|
void |
setPackagesForUid(int uid,
String... packagesForCallingUid) |
|
void |
setResolveInfosForIntent(Intent intent,
List<ResolveInfo> info) |
Deprecated.
see the note on
addResolveInfoForIntent(Intent, ResolveInfo) . |
void |
setSafeMode(boolean safeMode) |
Set value to be returned by
PackageManager.isSafeMode() . |
void |
setShouldShowActivityChooser(boolean shouldShowActivityChooser) |
If this method has been called with true, then in cases where many activities match a filter,
an activity chooser will be resolved instead of just the first pick.
|
void |
setShouldShowRequestPermissionRationale(String permission,
boolean show) |
|
void |
setSystemFeature(String name,
boolean supported) |
|
void |
setUnbadgedApplicationIcon(String packageName,
Drawable drawable) |
public ActivityInfo addActivityIfNotPresent(ComponentName componentName)
applicationInfo
set to an
existing application, or if it doesn't exist, a new package will be created.public ServiceInfo addServiceIfNotPresent(ComponentName componentName)
applicationInfo
set to an
existing application, or if it doesn't exist, a new package will be created.public ActivityInfo addReceiverIfNotPresent(ComponentName componentName)
applicationInfo
set to an
existing application, or if it doesn't exist, a new package will be created.public ProviderInfo addProviderIfNotPresent(ComponentName componentName)
applicationInfo
set to an
existing application, or if it doesn't exist, a new package will be created.public void addOrUpdateActivity(ActivityInfo activityInfo)
PackageItemInfo.name
and ComponentInfo#packageName
exists it will be updated. Its ComponentInfo.applicationInfo
is always set to ApplicationInfo
already existing in the system, but if no application exists a new one will
be created using ComponentInfo.applicationInfo
in this component.public void addOrUpdateService(ServiceInfo serviceInfo)
PackageItemInfo.name
and ComponentInfo#packageName
exists it will be updated. Its ComponentInfo.applicationInfo
is always set to ApplicationInfo
already existing in the system, but if no application exists a new one will be
created using ComponentInfo.applicationInfo
in this component.public void addOrUpdateReceiver(ActivityInfo receiverInfo)
PackageItemInfo.name
and
ComponentInfo#packageName
exists it will be updated. Its ComponentInfo.applicationInfo
is always set to ApplicationInfo
already existing in the system, but if no
application exists a new one will be created using ComponentInfo.applicationInfo
in
this component.public void addOrUpdateProvider(ProviderInfo providerInfo)
PackageItemInfo.name
and
ComponentInfo#packageName
exists it will be updated. Its ComponentInfo.applicationInfo
is always set to ApplicationInfo
already existing in the system, but if no
application exists a new one will be created using ComponentInfo.applicationInfo
in
this component.@Nullable public ActivityInfo removeActivity(ComponentName componentName)
null
if no such component existed.@Nullable public ServiceInfo removeService(ComponentName componentName)
null
if no such component existed.@Nullable public ProviderInfo removeProvider(ComponentName componentName)
null
if no such component existed.@Nullable public ActivityInfo removeReceiver(ComponentName componentName)
null
if no such component existed.@Deprecated public void setResolveInfosForIntent(Intent intent, List<ResolveInfo> info)
addResolveInfoForIntent(Intent, ResolveInfo)
.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(Intent intent, List<ResolveInfo> info)
addResolveInfoForIntent(Intent, ResolveInfo)
.@Deprecated public void addResolveInfoForIntent(Intent intent, ResolveInfo info)
addIntentFilterForComponent(android.content.ComponentName, android.content.IntentFilter, java.util.Map<android.content.ComponentName, java.util.List<android.content.IntentFilter>>)
instead and if the component doesn't exist
add it using any of installPackage(android.content.pm.PackageInfo)
, addOrUpdateActivity(android.content.pm.ActivityInfo)
, addActivityIfNotPresent(android.content.ComponentName)
or their counterparts for other types of components.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.@Deprecated public void addResolveInfoForIntentNoDefaults(Intent intent, ResolveInfo info)
addResolveInfoForIntent(Intent, ResolveInfo)
.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)
.@Deprecated public void removeResolveInfosForIntent(Intent intent, String packageName)
addResolveInfoForIntent(Intent, ResolveInfo)
.ResolveInfo
s registered using addResolveInfoForIntent(android.content.Intent, java.util.List<android.content.pm.ResolveInfo>)
.public void addActivityIcon(ComponentName component, Drawable drawable)
public void setUnbadgedApplicationIcon(String packageName, Drawable drawable)
public int getComponentEnabledSettingFlags(ComponentName componentName)
ApplicationPackageManager.setComponentEnabledSetting(ComponentName, int, int)
.componentName
- The component name.public void installModule(Object moduleInfoObject)
PackageManager
as long as it is not null
In order to create ModuleInfo objects in a valid state please use ModuleInfoBuilder
.
public Object deleteModule(String packageName)
ModuleInfo
be sure to give the
correct name as this method does not ensure existence of the module before deletion. Since
module installation ensures that a package exists in the device, also delete the package for
full deletion.packageName
- should be the value of ModuleInfo.getPackageName()
.null
if no module with this name exists.public void installPackage(PackageInfo packageInfo)
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(PackageInfo packageInfo)
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(PackageInfo packageInfo, PackageStats packageStats)
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(String packageName)
installPackage(PackageInfo)
instead.@Deprecated public void addPackage(PackageInfo packageInfo)
installPackage(android.content.pm.PackageInfo)
.public PackageInfo getInternalMutablePackageInfo(String packageName)
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 PackageInfo getPackageInfoForTesting(String packageName)
getInternalMutablePackageInfo(java.lang.String)
instead. It has better name.public void addPermissionInfo(PermissionInfo permissionInfo)
public void addChangedPackage(int sequenceNumber, String packageName)
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(PermissionGroupInfo permissionGroupInfo)
PackageParser.PermissionGroup
s added through this method have
precedence over those specified with the same name by one of the aforementioned methods.public void removePackage(String packageName)
public void setSystemFeature(String name, boolean supported)
public void addDrawableResolution(String packageName, int resourceId, Drawable drawable)
public void setNameForUid(int uid, String name)
public void setPackagesForCallingUid(String... packagesForCallingUid)
public void setPackagesForUid(int uid, String... packagesForCallingUid)
@Implementation @Nullable protected String[] getPackagesForUid(int uid)
public void setPackageArchiveInfo(String archiveFilePath, PackageInfo packageInfo)
public int getVerificationResult(int id)
public long getVerificationExtendedTimeout(int id)
public void setShouldShowRequestPermissionRationale(String permission, boolean show)
public void addSystemAvailableFeature(FeatureInfo featureInfo)
public void clearSystemAvailableFeatures()
public void addSystemSharedLibraryName(String name)
PackageManager.getSystemSharedLibraryNames()
.public void clearSystemSharedLibraryNames()
PackageManager.getSystemSharedLibraryNames()
.@Deprecated public void addCurrentToCannonicalName(String currentName, String canonicalName)
public void addCanonicalName(String currentName, String canonicalName)
This will be reflected when calling PackageManager.currentToCanonicalPackageNames(String[])
or PackageManager.canonicalToCurrentPackageNames(String[])
(String[])}.
public void setCanRequestPackageInstalls(boolean canRequestPackageInstalls)
PackageManager
is allowed to request package installs through package
installer.@Implementation(minSdk=24) protected List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, UserHandle userHandle)
@Implementation(minSdk=17) protected List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId)
@Implementation protected PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags)
@Implementation protected void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer)
@Implementation protected void freeStorage(long freeStorageSize, IntentSender pi)
public void deletePackage(String packageName)
PackageManager.MATCH_UNINSTALLED_PACKAGES
.protected void deletePackage(String packageName, IPackageDeleteObserver observer, int flags)
public void doPendingUninstallCallbacks()
PackageManager.deletePackage(String,
IPackageDeleteObserver, int)
public Set<String> getDeletedPackages()
PackageManager.deletePackage(String,
IPackageDeleteObserver, int)
Note that like real PackageManager
the calling context
must have Manifest.permission.DELETE_PACKAGES
permission set.protected List<ResolveInfo> queryOverriddenIntents(Intent intent, int flags)
public void addPackageInternal(PackageParser.Package appPackage)
appPackage
- public List<IntentFilter> getIntentFiltersForActivity(ComponentName componentName) throws PackageManager.NameNotFoundException
componentName
- Name of the activity whose intent filters are to be retrievedPackageManager.NameNotFoundException
- if component with given name doesn't exist.public List<IntentFilter> getIntentFiltersForService(ComponentName componentName) throws PackageManager.NameNotFoundException
componentName
- Name of the service whose intent filters are to be retrievedPackageManager.NameNotFoundException
- if component with given name doesn't exist.public List<IntentFilter> getIntentFiltersForReceiver(ComponentName componentName) throws PackageManager.NameNotFoundException
componentName
- Name of the receiver whose intent filters are to be retrievedPackageManager.NameNotFoundException
- if component with given name doesn't exist.public List<IntentFilter> getIntentFiltersForProvider(ComponentName componentName) throws PackageManager.NameNotFoundException
componentName
- Name of the provider whose intent filters are to be retrievedPackageManager.NameNotFoundException
- if component with given name doesn't exist.public void addIntentFilterForActivity(ComponentName componentName, IntentFilter filter) throws PackageManager.NameNotFoundException
PackageManager.NameNotFoundException
- if component with given name doesn't exist.public void addIntentFilterForService(ComponentName componentName, IntentFilter filter) throws PackageManager.NameNotFoundException
PackageManager.NameNotFoundException
- if component with given name doesn't exist.public void addIntentFilterForReceiver(ComponentName componentName, IntentFilter filter) throws PackageManager.NameNotFoundException
PackageManager.NameNotFoundException
- if component with given name doesn't exist.public void addIntentFilterForProvider(ComponentName componentName, IntentFilter filter) throws PackageManager.NameNotFoundException
PackageManager.NameNotFoundException
- if component with given name doesn't exist.public void clearIntentFilterForActivity(ComponentName componentName) throws PackageManager.NameNotFoundException
PackageManager.NameNotFoundException
- if component with given name doesn't exist.public void clearIntentFilterForService(ComponentName componentName) throws PackageManager.NameNotFoundException
PackageManager.NameNotFoundException
- if component with given name doesn't exist.public void clearIntentFilterForReceiver(ComponentName componentName) throws PackageManager.NameNotFoundException
PackageManager.NameNotFoundException
- if component with given name doesn't exist.public void clearIntentFilterForProvider(ComponentName componentName) throws PackageManager.NameNotFoundException
PackageManager.NameNotFoundException
- if component with given name doesn't exist.public int getPersistentPreferredActivities(List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName)
DevicePolicyManager.addPersistentPreferredActivity(android.content.ComponentName, android.content.IntentFilter, android.content.ComponentName)
.
Works the same way as analogous PackageManager.getPreferredActivities(java.util.List<android.content.IntentFilter>, java.util.List<android.content.ComponentName>, java.lang.String)
for regular
preferred activities.protected static int getPreferredActivitiesInternal(List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName, SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap)
protected static void clearPackagePreferredActivitiesInternal(String packageName, SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap)
protected static void addPreferredActivityInternal(IntentFilter filter, ComponentName activity, SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap)
protected static <V> SortedMap<ComponentName,V> mapForPackage(SortedMap<ComponentName,V> input, @Nullable String packageName)
public ShadowPackageManager.PackageSetting getPackageSetting(String packageName)
ShadowPackageManager.PackageSetting
of packageName
.
If packageName
is not present in this ShadowPackageManager
, this method will
return null.public void setShouldShowActivityChooser(boolean shouldShowActivityChooser)
public void setSafeMode(boolean safeMode)
PackageManager.isSafeMode()
.public int getDistractingPackageRestrictions(String pkg)
setDistractingPackageRestrictions
for pkg
.
Defaults to PackageManager.RESTRICTION_NONE
if
setDistractingPackageRestrictions
has not been called for pkg
.@Resetter public static void reset()