Package org.robolectric.shadows
Class ShadowPackageManager
- java.lang.Object
-
- org.robolectric.shadows.ShadowPackageManager
-
- Direct Known Subclasses:
ShadowApplicationPackageManager
@Implements(android.content.pm.PackageManager.class) public class ShadowPackageManager extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classShadowPackageManager.ComponentStatestatic classShadowPackageManager.IntentComparatorstatic classShadowPackageManager.PackageSettingSettings for a particular package.
-
Constructor Summary
Constructors Constructor Description ShadowPackageManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddActivityIcon(ComponentName component, Drawable drawable)voidaddActivityIcon(Intent intent, Drawable drawable)ActivityInfoaddActivityIfNotPresent(ComponentName componentName)Makes sure that given activity exists.voidaddCanonicalName(String currentName, String canonicalName)Adds a canonical package name for a package.voidaddChangedPackage(int sequenceNumber, String packageName)AddspackageNameto the list of changed packages for the particularsequenceNumber.voidaddCurrentToCannonicalName(String currentName, String canonicalName)Deprecated.voidaddDrawableResolution(String packageName, int resourceId, Drawable drawable)voidaddIntentFilterForActivity(ComponentName componentName, IntentFilter filter)Add intent filter for given activity.voidaddIntentFilterForProvider(ComponentName componentName, IntentFilter filter)Add intent filter for given provider.voidaddIntentFilterForReceiver(ComponentName componentName, IntentFilter filter)Add intent filter for given receiver.voidaddIntentFilterForService(ComponentName componentName, IntentFilter filter)Add intent filter for given service.voidaddOrUpdateActivity(ActivityInfo activityInfo)Adds or updates given activity in the system.voidaddOrUpdateProvider(ProviderInfo providerInfo)Adds or updates given content provider in the system.voidaddOrUpdateReceiver(ActivityInfo receiverInfo)Adds or updates given broadcast receiver in the system.voidaddOrUpdateService(ServiceInfo serviceInfo)Adds or updates given service in the system.voidaddPackage(PackageInfo packageInfo)Deprecated.voidaddPackage(PackageInfo packageInfo, PackageStats packageStats)Installs a package with its stats with thePackageManager.voidaddPackage(String packageName)Deprecated.UseinstallPackage(PackageInfo)instead.voidaddPackageInternal(PackageParser.Package appPackage)Internal use only.voidaddPackageNoDefaults(PackageInfo packageInfo)Adds a package to thePackageManager, but doesn't set any default values on it.voidaddPermissionGroupInfo(PermissionGroupInfo permissionGroupInfo)Allows overriding or adding permission-group elements.voidaddPermissionInfo(PermissionInfo permissionInfo)protected static voidaddPreferredActivityInternal(IntentFilter filter, ComponentName activity, SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap)ProviderInfoaddProviderIfNotPresent(ComponentName componentName)Makes sure that given provider exists.ActivityInfoaddReceiverIfNotPresent(ComponentName componentName)Makes sure that given receiver exists.voidaddResolveInfoForIntent(Intent intent, ResolveInfo info)Deprecated.useaddIntentFilterForComponent(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 ofinstallPackage(android.content.pm.PackageInfo),addOrUpdateActivity(android.content.pm.ActivityInfo),addActivityIfNotPresent(android.content.ComponentName)or their counterparts for other types of components.voidaddResolveInfoForIntent(Intent intent, List<ResolveInfo> info)Deprecated.see note onaddResolveInfoForIntent(Intent, ResolveInfo).voidaddResolveInfoForIntentNoDefaults(Intent intent, ResolveInfo info)Deprecated.see the note onaddResolveInfoForIntent(Intent, ResolveInfo).ServiceInfoaddServiceIfNotPresent(ComponentName componentName)Makes sure that given service exists.voidaddStringResource(String packageName, int resId, String text)Adds a String resource withresIdcorresponding topackageName.voidaddSystemAvailableFeature(FeatureInfo featureInfo)voidaddSystemSharedLibraryName(String name)Adds a value to be returned byPackageManager.getSystemSharedLibraryNames().voidclearIntentFilterForActivity(ComponentName componentName)Clears intent filters for given activity.voidclearIntentFilterForProvider(ComponentName componentName)Clears intent filters for given provider.voidclearIntentFilterForReceiver(ComponentName componentName)Clears intent filters for given receiver.voidclearIntentFilterForService(ComponentName componentName)Clears intent filters for given service.protected static voidclearPackagePreferredActivitiesInternal(String packageName, SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap)voidclearSystemAvailableFeatures()voidclearSystemSharedLibraryNames()Clears the values returned byPackageManager.getSystemSharedLibraryNames().ObjectdeleteModule(String packageName)Deletes a module when given the module's package nameModuleInfobe sure to give the correct name as this method does not ensure existence of the module before deletion.voiddeletePackage(String packageName)Uninstalls the package from the system in a way, that will allow its discovery throughPackageManager.MATCH_UNINSTALLED_PACKAGES.protected voiddeletePackage(String packageName, IPackageDeleteObserver observer, int flags)voiddoPendingUninstallCallbacks()Runs the callbacks pending from calls toPackageManager.deletePackage(String, IPackageDeleteObserver, int)protected voidfreeStorage(long freeStorageSize, IntentSender pi)protected voidfreeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer)protected PackageInfogeneratePackageInfo(PackageParser.Package appPackage, int flags)intgetComponentEnabledSettingFlags(ComponentName componentName)Return the flags set in call toApplicationPackageManager.setComponentEnabledSetting(ComponentName, int, int).Set<String>getDeletedPackages()Returns package names successfully deleted withPackageManager.deletePackage(String, IPackageDeleteObserver, int)Note that like realPackageManagerthe calling context must haveManifest.permission.DELETE_PACKAGESpermission set.intgetDistractingPackageRestrictions(String pkg)Returns the last value provided tosetDistractingPackageRestrictionsforpkg.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.PackageInfogetInternalMutablePackageInfo(String packageName)Testing API allowing to retrieve internal package representation.protected PackageInfogetPackageArchiveInfo(String archiveFilePath, int flags)PackageInfogetPackageInfoForTesting(String packageName)Deprecated.UsegetInternalMutablePackageInfo(java.lang.String)instead.ShadowPackageManager.PackageSettinggetPackageSetting(String packageName)Returns the currentShadowPackageManager.PackageSettingofpackageName.protected String[]getPackagesForUid(int uid)intgetPersistentPreferredActivities(List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName)Method to retrieve persistent preferred activities as set byDevicePolicyManager.addPersistentPreferredActivity(android.content.ComponentName, android.content.IntentFilter, android.content.ComponentName).protected static intgetPreferredActivitiesInternal(List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName, SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap)protected PackageInfogetShadowPackageArchiveInfo(String archiveFilePath, int flags)longgetVerificationExtendedTimeout(int id)intgetVerificationResult(int id)voidinstallModule(Object moduleInfoObject)Installs a module with thePackageManageras long as it is notnullvoidinstallPackage(PackageInfo packageInfo)Installs a package with thePackageManager.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)ActivityInforemoveActivity(ComponentName componentName)Removes activity from the package manager.voidremovePackage(String packageName)ProviderInforemoveProvider(ComponentName componentName)Removes content provider from the package manager.ActivityInforemoveReceiver(ComponentName componentName)Removes broadcast receiver from the package manager.voidremoveResolveInfosForIntent(Intent intent, String packageName)Deprecated.see note onaddResolveInfoForIntent(Intent, ResolveInfo).ServiceInforemoveService(ComponentName componentName)Removes service from the package manager.static voidreset()voidsetApplicationIcon(String packageName, Drawable drawable)voidsetAutoRevokeWhitelisted(boolean whitelisted)Set value to be returned byPackageManager.isAutoRevokeWhitelisted(java.lang.String).voidsetCanRequestPackageInstalls(boolean canRequestPackageInstalls)Sets if thePackageManageris allowed to request package installs through package installer.voidsetInstallSourceInfo(String packageName, String initiatingPackage, String installerPackage)Adds install source information for a package.voidsetNameForUid(int uid, String name)voidsetPackageArchiveInfo(String archiveFilePath, PackageInfo packageInfo)voidsetPackagesForCallingUid(String... packagesForCallingUid)voidsetPackagesForUid(int uid, String... packagesForCallingUid)voidsetResolveInfosForIntent(Intent intent, List<ResolveInfo> info)Deprecated.see the note onaddResolveInfoForIntent(Intent, ResolveInfo).voidsetSafeMode(boolean safeMode)Set value to be returned byPackageManager.isSafeMode().voidsetShouldShowActivityChooser(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.voidsetShouldShowRequestPermissionRationale(String permission, boolean show)voidsetSystemFeature(String name, boolean supported)voidsetUnbadgedApplicationIcon(String packageName, Drawable drawable)
-
-
-
Method Detail
-
addActivityIfNotPresent
public ActivityInfo addActivityIfNotPresent(ComponentName componentName)
Makes sure that given activity exists. If the activity doesn't exist yet, it will be created withapplicationInfoset to an existing application, or if it doesn't exist, a new package will be created.- Returns:
- existing or newly created activity info.
-
addServiceIfNotPresent
public ServiceInfo addServiceIfNotPresent(ComponentName componentName)
Makes sure that given service exists. If the service doesn't exist yet, it will be created withapplicationInfoset to an existing application, or if it doesn't exist, a new package will be created.- Returns:
- existing or newly created service info.
-
addReceiverIfNotPresent
public ActivityInfo addReceiverIfNotPresent(ComponentName componentName)
Makes sure that given receiver exists. If the receiver doesn't exist yet, it will be created withapplicationInfoset to an existing application, or if it doesn't exist, a new package will be created.- Returns:
- existing or newly created receiver info.
-
addProviderIfNotPresent
public ProviderInfo addProviderIfNotPresent(ComponentName componentName)
Makes sure that given provider exists. If the provider doesn't exist yet, it will be created withapplicationInfoset to an existing application, or if it doesn't exist, a new package will be created.- Returns:
- existing or newly created provider info.
-
addOrUpdateActivity
public void addOrUpdateActivity(ActivityInfo activityInfo)
Adds or updates given activity in the system. If activity with the samePackageItemInfo.nameandComponentInfo#packageNameexists it will be updated. ItsComponentInfo.applicationInfois always set toApplicationInfoalready existing in the system, but if no application exists a new one will be created usingComponentInfo.applicationInfoin this component.
-
addOrUpdateService
public void addOrUpdateService(ServiceInfo serviceInfo)
Adds or updates given service in the system. If service with the samePackageItemInfo.nameandComponentInfo#packageNameexists it will be updated. ItsComponentInfo.applicationInfois always set toApplicationInfoalready existing in the system, but if no application exists a new one will be created usingComponentInfo.applicationInfoin this component.
-
addOrUpdateReceiver
public void addOrUpdateReceiver(ActivityInfo receiverInfo)
Adds or updates given broadcast receiver in the system. If broadcast receiver with the samePackageItemInfo.nameandComponentInfo#packageNameexists it will be updated. ItsComponentInfo.applicationInfois always set toApplicationInfoalready existing in the system, but if no application exists a new one will be created usingComponentInfo.applicationInfoin this component.
-
addOrUpdateProvider
public void addOrUpdateProvider(ProviderInfo providerInfo)
Adds or updates given content provider in the system. If content provider with the samePackageItemInfo.nameandComponentInfo#packageNameexists it will be updated. ItsComponentInfo.applicationInfois always set toApplicationInfoalready existing in the system, but if no application exists a new one will be created usingComponentInfo.applicationInfoin this component.
-
removeActivity
@Nullable public ActivityInfo removeActivity(ComponentName componentName)
Removes activity from the package manager.- Returns:
- the removed component or
nullif no such component existed.
-
removeService
@Nullable public ServiceInfo removeService(ComponentName componentName)
Removes service from the package manager.- Returns:
- the removed component or
nullif no such component existed.
-
removeProvider
@Nullable public ProviderInfo removeProvider(ComponentName componentName)
Removes content provider from the package manager.- Returns:
- the removed component or
nullif no such component existed.
-
removeReceiver
@Nullable public ActivityInfo removeReceiver(ComponentName componentName)
Removes broadcast receiver from the package manager.- Returns:
- the removed component or
nullif no such component existed.
-
setResolveInfosForIntent
@Deprecated public void setResolveInfosForIntent(Intent intent, List<ResolveInfo> info)
Deprecated.see the note onaddResolveInfoForIntent(Intent, ResolveInfo).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 haveResolveInfo.isDefaultfield set totrueto 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 tofalse.
-
addResolveInfoForIntent
@Deprecated public void addResolveInfoForIntent(Intent intent, List<ResolveInfo> info)
Deprecated.see note onaddResolveInfoForIntent(Intent, ResolveInfo).
-
addResolveInfoForIntent
@Deprecated public void addResolveInfoForIntent(Intent intent, ResolveInfo info)
Deprecated.useaddIntentFilterForComponent(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 ofinstallPackage(android.content.pm.PackageInfo),addOrUpdateActivity(android.content.pm.ActivityInfo),addActivityIfNotPresent(android.content.ComponentName)or their counterparts for other types of components.Adds extra resolve info for an intent. Note that this resolve info will haveResolveInfo.isDefaultfield set totrueto allow its resolution for implicit intents. If this is not what you want, then please useaddResolveInfoForIntentNoDefaults(android.content.Intent, android.content.pm.ResolveInfo)instead.
-
addResolveInfoForIntentNoDefaults
@Deprecated public void addResolveInfoForIntentNoDefaults(Intent intent, ResolveInfo info)
Deprecated.see the note onaddResolveInfoForIntent(Intent, ResolveInfo).Adds theinfoasResolveInfofor the intent but without applying any default values. In particular it will not make theResolveInfo.isDefaultfieldtrue, that means that this resolve info will not resolve forIntent.resolveActivity(android.content.pm.PackageManager)andContext.startActivity(android.content.Intent).
-
removeResolveInfosForIntent
@Deprecated public void removeResolveInfosForIntent(Intent intent, String packageName)
Deprecated.see note onaddResolveInfoForIntent(Intent, ResolveInfo).RemovesResolveInfos registered usingaddResolveInfoForIntent(android.content.Intent, java.util.List<android.content.pm.ResolveInfo>).
-
addActivityIcon
public void addActivityIcon(ComponentName component, Drawable drawable)
-
setUnbadgedApplicationIcon
public void setUnbadgedApplicationIcon(String packageName, Drawable drawable)
-
getComponentEnabledSettingFlags
public int getComponentEnabledSettingFlags(ComponentName componentName)
Return the flags set in call toApplicationPackageManager.setComponentEnabledSetting(ComponentName, int, int).- Parameters:
componentName- The component name.- Returns:
- The flags.
-
installModule
public void installModule(Object moduleInfoObject)
Installs a module with thePackageManageras long as it is notnullIn order to create ModuleInfo objects in a valid state please use
ModuleInfoBuilder.
-
deleteModule
public Object deleteModule(String packageName)
Deletes a module when given the module's package nameModuleInfobe 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.- Parameters:
packageName- should be the value ofModuleInfo.getPackageName().- Returns:
- deleted module of
nullif no module with this name exists.
-
installPackage
public void installPackage(PackageInfo packageInfo)
Installs a package with thePackageManager. In order to create PackageInfo objects in a valid state please useandroidx.test.core.content.pm.PackageInfoBuilder. This method automatically simulates instalation of a package in the system, so it adds a flagApplicationInfo.FLAG_INSTALLEDto 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, useaddPackageNoDefaults(android.content.pm.PackageInfo)instead.
-
setInstallSourceInfo
public void setInstallSourceInfo(String packageName, String initiatingPackage, String installerPackage)
Adds install source information for a package.
-
addPackageNoDefaults
public void addPackageNoDefaults(PackageInfo packageInfo)
Adds a package to thePackageManager, but doesn't set any default values on it.Right now it will not set
ApplicationInfo.FLAG_INSTALLEDflag on its application, so if not set explicitly, it will be treated as not installed.
-
addPackage
public void addPackage(PackageInfo packageInfo, PackageStats packageStats)
Installs a package with its stats with thePackageManager.This method doesn't add any defaults to the
packageInfoparameters. You should make sure it is valid (seeinstallPackage(PackageInfo)).
-
addPackage
@Deprecated public void addPackage(String packageName)
Deprecated.UseinstallPackage(PackageInfo)instead.
-
addPackage
@Deprecated public void addPackage(PackageInfo packageInfo)
Deprecated.This method is getting renamed to {linkinstallPackage(android.content.pm.PackageInfo).
-
getInternalMutablePackageInfo
public PackageInfo getInternalMutablePackageInfo(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 usingPackageManager.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.
-
getPackageInfoForTesting
@Deprecated public PackageInfo getPackageInfoForTesting(String packageName)
Deprecated.UsegetInternalMutablePackageInfo(java.lang.String)instead. It has better name.
-
addPermissionInfo
public void addPermissionInfo(PermissionInfo permissionInfo)
-
addChangedPackage
public void addChangedPackage(int sequenceNumber, String packageName)AddspackageNameto the list of changed packages for the particularsequenceNumber.- Parameters:
sequenceNumber- has to be >= 0packageName- name of the package that was changed
-
addPermissionGroupInfo
public void addPermissionGroupInfo(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 manifestPackageParser.PermissionGroups added through this method have precedence over those specified with the same name by one of the aforementioned methods.
-
removePackage
public void removePackage(String packageName)
-
setSystemFeature
public void setSystemFeature(String name, boolean supported)
-
addDrawableResolution
public void addDrawableResolution(String packageName, int resourceId, Drawable drawable)
-
setNameForUid
public void setNameForUid(int uid, String name)
-
setPackagesForCallingUid
public void setPackagesForCallingUid(String... packagesForCallingUid)
-
setPackagesForUid
public void setPackagesForUid(int uid, String... packagesForCallingUid)
-
getPackagesForUid
@Implementation @Nullable protected String[] getPackagesForUid(int uid)
-
setPackageArchiveInfo
public void setPackageArchiveInfo(String archiveFilePath, PackageInfo packageInfo)
-
getVerificationResult
public int getVerificationResult(int id)
-
getVerificationExtendedTimeout
public long getVerificationExtendedTimeout(int id)
-
setShouldShowRequestPermissionRationale
public void setShouldShowRequestPermissionRationale(String permission, boolean show)
-
addSystemAvailableFeature
public void addSystemAvailableFeature(FeatureInfo featureInfo)
-
clearSystemAvailableFeatures
public void clearSystemAvailableFeatures()
-
addSystemSharedLibraryName
public void addSystemSharedLibraryName(String name)
Adds a value to be returned byPackageManager.getSystemSharedLibraryNames().
-
clearSystemSharedLibraryNames
public void clearSystemSharedLibraryNames()
Clears the values returned byPackageManager.getSystemSharedLibraryNames().
-
addCurrentToCannonicalName
@Deprecated public void addCurrentToCannonicalName(String currentName, String canonicalName)
Deprecated.
-
addCanonicalName
public void addCanonicalName(String currentName, String canonicalName)
Adds a canonical package name for a package.This will be reflected when calling
PackageManager.currentToCanonicalPackageNames(String[])orPackageManager.canonicalToCurrentPackageNames(String[])(String[])}.
-
setCanRequestPackageInstalls
public void setCanRequestPackageInstalls(boolean canRequestPackageInstalls)
Sets if thePackageManageris allowed to request package installs through package installer.
-
queryBroadcastReceiversAsUser
@Implementation(minSdk=24) protected List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, UserHandle userHandle)
-
queryBroadcastReceivers
@Implementation(minSdk=17) protected List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId)
-
getPackageArchiveInfo
@Implementation protected PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags)
-
getShadowPackageArchiveInfo
protected PackageInfo getShadowPackageArchiveInfo(String archiveFilePath, int flags)
-
freeStorageAndNotify
@Implementation protected void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer)
-
freeStorage
@Implementation protected void freeStorage(long freeStorageSize, IntentSender pi)
-
deletePackage
public void deletePackage(String packageName)
Uninstalls the package from the system in a way, that will allow its discovery throughPackageManager.MATCH_UNINSTALLED_PACKAGES.
-
deletePackage
@Implementation protected void deletePackage(String packageName, IPackageDeleteObserver observer, int flags)
-
doPendingUninstallCallbacks
public void doPendingUninstallCallbacks()
Runs the callbacks pending from calls toPackageManager.deletePackage(String, IPackageDeleteObserver, int)
-
getDeletedPackages
public Set<String> getDeletedPackages()
Returns package names successfully deleted withPackageManager.deletePackage(String, IPackageDeleteObserver, int)Note that like realPackageManagerthe calling context must haveManifest.permission.DELETE_PACKAGESpermission set.
-
queryOverriddenIntents
protected List<ResolveInfo> queryOverriddenIntents(Intent intent, int flags)
-
addPackageInternal
public void addPackageInternal(PackageParser.Package appPackage)
Internal use only.- Parameters:
appPackage-
-
generatePackageInfo
protected PackageInfo generatePackageInfo(PackageParser.Package appPackage, int flags)
-
getIntentFiltersForActivity
public List<IntentFilter> getIntentFiltersForActivity(ComponentName componentName) throws PackageManager.NameNotFoundException
Get list of intent filters defined for given activity.- Parameters:
componentName- Name of the activity whose intent filters are to be retrieved- Returns:
- the activity's intent filters
- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
getIntentFiltersForService
public List<IntentFilter> getIntentFiltersForService(ComponentName componentName) throws PackageManager.NameNotFoundException
Get list of intent filters defined for given service.- Parameters:
componentName- Name of the service whose intent filters are to be retrieved- Returns:
- the service's intent filters
- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
getIntentFiltersForReceiver
public List<IntentFilter> getIntentFiltersForReceiver(ComponentName componentName) throws PackageManager.NameNotFoundException
Get list of intent filters defined for given receiver.- Parameters:
componentName- Name of the receiver whose intent filters are to be retrieved- Returns:
- the receiver's intent filters
- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
getIntentFiltersForProvider
public List<IntentFilter> getIntentFiltersForProvider(ComponentName componentName) throws PackageManager.NameNotFoundException
Get list of intent filters defined for given provider.- Parameters:
componentName- Name of the provider whose intent filters are to be retrieved- Returns:
- the provider's intent filters
- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
addIntentFilterForActivity
public void addIntentFilterForActivity(ComponentName componentName, IntentFilter filter) throws PackageManager.NameNotFoundException
Add intent filter for given activity.- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
addIntentFilterForService
public void addIntentFilterForService(ComponentName componentName, IntentFilter filter) throws PackageManager.NameNotFoundException
Add intent filter for given service.- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
addIntentFilterForReceiver
public void addIntentFilterForReceiver(ComponentName componentName, IntentFilter filter) throws PackageManager.NameNotFoundException
Add intent filter for given receiver.- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
addIntentFilterForProvider
public void addIntentFilterForProvider(ComponentName componentName, IntentFilter filter) throws PackageManager.NameNotFoundException
Add intent filter for given provider.- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
clearIntentFilterForActivity
public void clearIntentFilterForActivity(ComponentName componentName) throws PackageManager.NameNotFoundException
Clears intent filters for given activity.- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
clearIntentFilterForService
public void clearIntentFilterForService(ComponentName componentName) throws PackageManager.NameNotFoundException
Clears intent filters for given service.- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
clearIntentFilterForReceiver
public void clearIntentFilterForReceiver(ComponentName componentName) throws PackageManager.NameNotFoundException
Clears intent filters for given receiver.- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
clearIntentFilterForProvider
public void clearIntentFilterForProvider(ComponentName componentName) throws PackageManager.NameNotFoundException
Clears intent filters for given provider.- Throws:
PackageManager.NameNotFoundException- if component with given name doesn't exist.
-
getPersistentPreferredActivities
public int getPersistentPreferredActivities(List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName)
Method to retrieve persistent preferred activities as set byDevicePolicyManager.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.
-
getPreferredActivitiesInternal
protected static int getPreferredActivitiesInternal(List<IntentFilter> outFilters, List<ComponentName> outActivities, String packageName, SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap)
-
clearPackagePreferredActivitiesInternal
protected static void clearPackagePreferredActivitiesInternal(String packageName, SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap)
-
addPreferredActivityInternal
protected static void addPreferredActivityInternal(IntentFilter filter, ComponentName activity, SortedMap<ComponentName,List<IntentFilter>> preferredActivitiesMap)
-
mapForPackage
protected static <V> SortedMap<ComponentName,V> mapForPackage(SortedMap<ComponentName,V> input, @Nullable String packageName)
-
getPackageSetting
public ShadowPackageManager.PackageSetting getPackageSetting(String packageName)
Returns the currentShadowPackageManager.PackageSettingofpackageName. IfpackageNameis not present in thisShadowPackageManager, this method will return null.
-
setShouldShowActivityChooser
public 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.
-
setSafeMode
public void setSafeMode(boolean safeMode)
Set value to be returned byPackageManager.isSafeMode().
-
getDistractingPackageRestrictions
public int getDistractingPackageRestrictions(String pkg)
Returns the last value provided tosetDistractingPackageRestrictionsforpkg. Defaults toPackageManager.RESTRICTION_NONEifsetDistractingPackageRestrictionshas not been called forpkg.
-
addStringResource
public void addStringResource(String packageName, int resId, String text)
Adds a String resource withresIdcorresponding topackageName. This is retrieved in shadow implementation ofPackageManager.getText(String, int, ApplicationInfo).
-
setAutoRevokeWhitelisted
public void setAutoRevokeWhitelisted(boolean whitelisted)
Set value to be returned byPackageManager.isAutoRevokeWhitelisted(java.lang.String).
-
reset
@Resetter public static void reset()
-
-