Class ShadowDevicePolicyManager
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void__constructor__(Context context, boolean parentInstance) protected void__constructor__(Context context, IDevicePolicyManager service) protected void__constructor__(Context context, Handler handler) booleanactivateResetToken(ComponentName admin) Activates reset token for given admin.protected voidaddPersistentPreferredActivity(ComponentName admin, IntentFilter filter, ComponentName activity) protected voidaddUserRestriction(ComponentName admin, String key) protected booleanbindDeviceAdminServiceAsUser(ComponentName admin, Intent serviceIntent, ServiceConnection conn, int flags, UserHandle targetUser) Bind to the same package in another user.protected voidclearPackagePersistentPreferredActivities(ComponentName admin, String packageName) protected voidclearProfileOwner(ComponentName admin) protected voidclearUserRestriction(ComponentName admin, String key) protected voidenableSystemApp(ComponentName admin, String packageName) voidfailSetApplicationHiddenFor(Collection<String> packagesToFail) Set package names for witchDevicePolicyManager.setApplicationHidden(android.content.ComponentName, java.lang.String, boolean)should fail.protected voidfinalizeWorkProfileProvisioning(UserHandle managedProfileUser, Account migratedAccount) protected String[]protected List<ComponentName>getAffiliationIds(ComponentName admin) protected BundlegetApplicationRestrictions(ComponentName admin, String packageName) getApplicationRestrictions(String packageName) Returns all application restrictions of thepackageNamein aBundle.protected booleangetAutoTimeEnabled(ComponentName admin) protected booleanprotected booleanprotected List<UserHandle>Returns the list of target users that the calling device or profile owner can use when callingbindDeviceAdminServiceAsUser(android.content.ComponentName, android.content.Intent, android.content.ServiceConnection, int, android.os.UserHandle).protected booleangetCameraDisabled(ComponentName admin) getDelegatedScopes(ComponentName admin, String delegatePackage) protected Stringprotected Stringprotected ObjectReturn a stub value set bysetDevicePolicyState(DevicePolicyState policyState)protected intRetrieves last password set throughDevicePolicyManager.resetPassword(java.lang.String, int)orDevicePolicyManager.resetPasswordWithToken(android.content.ComponentName, java.lang.String, byte[], int).protected intgetLockTaskFeatures(ComponentName admin) protected String[]getLockTaskPackages(ComponentName admin) protected CharSequenceprotected intprotected longprotected intprotected intprotected intprotected CharSequencegetOrganizationName(ComponentName admin) Returns organization name.protected intprotected longprotected longprotected intprotected intprotected intprotected intprotected intprotected intprotected intprotected intprotected intgetPasswordQuality(ComponentName admin) protected intgetPermissionGrantState(ComponentName admin, String packageName, String permission) protected intgetPermissionPolicy(ComponentName admin) protected List<UserHandle>getPolicyManagedProfiles(UserHandle userHandle) Returns the managed profiles set insetPolicyManagedProfiles(List).protected ComponentNameprotected StringgetProfileOwnerNameAsUser(int userId) Returns the human-readable name of the profile owner for a user if set usingsetProfileOwnerName(int, java.lang.String), otherwise null.protected CharSequenceprotected booleanprotected intprotected SystemUpdatePolicyReturns the time zone set by setTimeZone.protected PersistableBundleprotected intReturns the provisioning state set insetUserProvisioningState(int), orDevicePolicyManager.STATE_USER_UNMANAGEDif none is set.intgetUserProvisioningStateForUser(int userId) Returns the user provisioning state set bysetUserProvisioningState(int, UserHandle), orDevicePolicyManager.STATE_USER_UNMANAGEDif none is set.longvoidgrantPolicy(ComponentName admin, int usesPolicy) Grants a particular device policy for an active ComponentName.protected booleanhasGrantedPolicy(ComponentName admin, int usesPolicy) protected booleanprotected booleanprotected booleanisApplicationHidden(ComponentName admin, String packageName) booleanprotected booleanisDeviceOwnerApp(String packageName) protected booleanprotected booleanprotected booleanprotected booleanReturns the value stored using in the shadow, while the real method returns the value store on the device.protected booleanisPackageSuspended(ComponentName admin, String packageName) booleanisPermissionGranted(String packageName, String permission) protected booleanisProfileOwnerApp(String packageName) protected booleanprotected booleanisUninstallBlocked(ComponentName admin, String packageName) protected booleanprotected booleanbooleanisWorkProfileProvisioningFinalized(UserHandle userHandle, Account migratedAccount) Returns iffinalizeWorkProfileProvisioning(UserHandle, Account)was called with the provided parameters.protected voidlockNow()protected voidremoveActiveAdmin(ComponentName admin) protected booleanresetPassword(String password, int flags) protected booleanresetPasswordWithToken(ComponentName admin, String password, byte[] token, int flags) protected voidsetAccountManagementDisabled(ComponentName admin, String accountType, boolean disabled) voidsetActiveAdmin(ComponentName componentName) Sets the givencomponentNameas one of the active admins.voidsetActivePasswordSufficient(boolean sufficient) Sets if the password meets the current requirements.protected voidsetAffiliationIds(ComponentName admin, Set<String> ids) protected booleansetApplicationHidden(ComponentName admin, String packageName, boolean hidden) protected voidsetApplicationRestrictions(ComponentName admin, String packageName, Bundle applicationRestrictions) voidsetApplicationRestrictions(String packageName, Bundle applicationRestrictions) Sets the application restrictions of thepackageName.protected voidsetAutoTimeEnabled(ComponentName admin, boolean enabled) protected voidsetAutoTimeRequired(ComponentName admin, boolean required) protected voidsetAutoTimeZoneEnabled(ComponentName admin, boolean enabled) voidsetBindDeviceAdminTargetUsers(List<UserHandle> bindDeviceAdminTargetUsers) Set the list of target users that the calling device or profile owner can use when callingbindDeviceAdminServiceAsUser(android.content.ComponentName, android.content.Intent, android.content.ServiceConnection, int, android.os.UserHandle).protected voidsetCameraDisabled(ComponentName admin, boolean disabled) protected voidsetDelegatedScopes(ComponentName admin, String delegatePackage, List<String> scopes) booleansetDeviceOwner(ComponentName admin) Sets the admin as active admin and device owner.voidsetDevicePolicyManagementRoleHolderPackage(String packageName) Sets the package name of the device policy management role holder.voidsetDevicePolicyState(Object policyState) Set theDevicePolicyStatewhich can be constructed fromDevicePolicyStateBuildervoidsetDeviceProvisioned(boolean isProvisioned) Sets whether the device is provisioned.protected voidvoidsetIsUniqueDeviceAttestationSupported(boolean supported) voidsetIsUsbDataSignalingEnabled(boolean isEnabled) Sets USB signaling device restriction.protected voidsetKeyguardDisabledFeatures(ComponentName admin, int which) protected voidsetLockTaskFeatures(ComponentName admin, int flags) protected voidsetLockTaskPackages(ComponentName admin, String[] packages) protected voidsetLongSupportMessage(ComponentName admin, CharSequence message) protected voidsetMaximumFailedPasswordsForWipe(ComponentName admin, int num) protected voidsetMaximumTimeToLock(ComponentName admin, long timeMs) protected voidsetNearbyAppStreamingPolicy(int policy) protected voidsetNearbyNotificationStreamingPolicy(int policy) protected voidsetOrganizationColor(ComponentName admin, int color) protected voidsetOrganizationName(ComponentName admin, CharSequence name) Sets organization name.voidsetOrganizationOwnedDeviceWithManagedProfile(boolean value) Sets the return value of theDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()method (only for Android R+).protected String[]setPackagesSuspended(ComponentName admin, String[] packageNames, boolean suspended) voidsetPasswordComplexity(int passwordComplexity) Sets the password complexity.voidsetPasswordExpiration(ComponentName admin, long timeout) Sets the password expiration time for a particular admin.protected voidsetPasswordExpirationTimeout(ComponentName admin, long timeout) protected voidsetPasswordHistoryLength(ComponentName admin, int length) protected voidsetPasswordMinimumLength(ComponentName admin, int length) protected voidsetPasswordMinimumLetters(ComponentName admin, int length) protected voidsetPasswordMinimumLowerCase(ComponentName admin, int length) protected voidsetPasswordMinimumNonLetter(ComponentName admin, int length) protected voidsetPasswordMinimumNumeric(ComponentName admin, int length) protected voidsetPasswordMinimumSymbols(ComponentName admin, int length) protected voidsetPasswordMinimumUpperCase(ComponentName admin, int length) protected voidsetPasswordQuality(ComponentName admin, int quality) protected booleansetPermissionGrantState(ComponentName admin, String packageName, String permission, int grantState) protected voidsetPermissionPolicy(ComponentName admin, int policy) protected booleansetPermittedAccessibilityServices(ComponentName admin, List<String> packageNames) Sets permitted accessibility services.protected booleansetPermittedInputMethods(ComponentName admin, List<String> packageNames) Sets permitted input methods.voidsetPolicyManagedProfiles(List<UserHandle> policyManagedProfiles) Sets the value returned bygetPolicyManagedProfiles(UserHandle).voidsetProfileOwner(ComponentName admin) Sets the admin as active admin and profile owner.voidsetProfileOwnerName(int userId, String name) protected booleansetResetPasswordToken(ComponentName admin, byte[] token) protected voidsetShortSupportMessage(ComponentName admin, CharSequence message) protected intsetStorageEncryption(ComponentName admin, boolean encrypt) voidsetStorageEncryptionStatus(int status) Setter forDevicePolicyManager.getStorageEncryptionStatus().voidSets the system update policy.protected voidsetSystemUpdatePolicy(ComponentName admin, SystemUpdatePolicy policy) protected booleansetTimeZone(ComponentName admin, String timeZone) protected voidsetUninstallBlocked(ComponentName admin, String packageName, boolean uninstallBlocked) voidsetUserProvisioningState(int state) Sets the user provisioning state.protected voidsetUserProvisioningState(int state, UserHandle userHandle) protected voidtransferOwnership(ComponentName admin, ComponentName target, PersistableBundle bundle) booleanwasPackageEverHidden(String packageName) Returnstrueif the givenpackageNamewas ever hidden.booleanwasSystemAppEnabled(String packageName) Returnstrueif the givenpackageNamewas a system app and was enabled.protected voidwipeData(int flags)
-
Constructor Details
-
ShadowDevicePolicyManager
public ShadowDevicePolicyManager()
-
-
Method Details
-
__constructor__
-
__constructor__
@Implementation(minSdk=24, maxSdk=25) protected void __constructor__(Context context, boolean parentInstance) -
__constructor__
@Implementation(minSdk=26) protected void __constructor__(Context context, IDevicePolicyManager service) -
isDeviceOwnerApp
-
isProfileOwnerApp
-
isAdminActive
-
getActiveAdmins
-
addUserRestriction
-
clearUserRestriction
-
setApplicationHidden
@Implementation protected boolean setApplicationHidden(ComponentName admin, String packageName, boolean hidden) -
failSetApplicationHiddenFor
Set package names for witchDevicePolicyManager.setApplicationHidden(android.content.ComponentName, java.lang.String, boolean)should fail.- Parameters:
packagesToFail- collection of package names ornullto clear the packages.
-
isApplicationHidden
-
wasPackageEverHidden
Returnstrueif the givenpackageNamewas ever hidden. -
enableSystemApp
-
wasSystemAppEnabled
Returnstrueif the givenpackageNamewas a system app and was enabled. -
setUninstallBlocked
@Implementation protected void setUninstallBlocked(ComponentName admin, String packageName, boolean uninstallBlocked) -
isUninstallBlocked
-
setIsUniqueDeviceAttestationSupported
public void setIsUniqueDeviceAttestationSupported(boolean supported) -
isUniqueDeviceAttestationSupported
-
setIsUsbDataSignalingEnabled
public void setIsUsbDataSignalingEnabled(boolean isEnabled) Sets USB signaling device restriction. -
isUsbDataSignalingEnabled
-
getDeviceOwner
- See Also:
-
isDeviceManaged
- See Also:
-
getProfileOwner
- See Also:
-
getProfileOwnerNameAsUser
Returns the human-readable name of the profile owner for a user if set usingsetProfileOwnerName(int, java.lang.String), otherwise null. -
transferOwnership
@Implementation(minSdk=28) protected void transferOwnership(ComponentName admin, ComponentName target, PersistableBundle bundle) -
getTransferOwnershipBundle
-
setDeviceOwner
Sets the admin as active admin and device owner.- See Also:
-
setProfileOwner
Sets the admin as active admin and profile owner.- See Also:
-
setProfileOwnerName
-
setActiveAdmin
Sets the givencomponentNameas one of the active admins. -
removeActiveAdmin
-
clearProfileOwner
-
getApplicationRestrictions
@Implementation protected Bundle getApplicationRestrictions(ComponentName admin, String packageName) -
getApplicationRestrictions
Returns all application restrictions of thepackageNamein aBundle. -
setApplicationRestrictions
@Implementation protected void setApplicationRestrictions(ComponentName admin, String packageName, Bundle applicationRestrictions) -
setApplicationRestrictions
Sets the application restrictions of thepackageName.The new
applicationRestrictionsalways completely overwrites any existing ones. -
setDelegatedScopes
@Implementation(minSdk=26) protected void setDelegatedScopes(ComponentName admin, String delegatePackage, List<String> scopes) -
getDelegatedScopes
@Implementation(minSdk=26) protected List<String> getDelegatedScopes(ComponentName admin, String delegatePackage) -
setAccountManagementDisabled
@Implementation protected void setAccountManagementDisabled(ComponentName admin, String accountType, boolean disabled) -
getAccountTypesWithManagementDisabled
-
setOrganizationName
@Implementation(minSdk=24) protected void setOrganizationName(ComponentName admin, CharSequence name) Sets organization name.The API can only be called by profile owner since Android N and can be called by both of profile owner and device owner since Android O.
-
setPackagesSuspended
@Implementation(minSdk=24) protected String[] setPackagesSuspended(ComponentName admin, String[] packageNames, boolean suspended) -
isPackageSuspended
@Implementation(minSdk=24) protected boolean isPackageSuspended(ComponentName admin, String packageName) throws PackageManager.NameNotFoundException -
setOrganizationColor
-
getOrganizationName
Returns organization name.The API can only be called by profile owner since Android N.
Android framework has a hidden API for getting the organization name for device owner since Android O. This method, however, is extended to return the organization name for device owners too to make testing of
setOrganizationName(ComponentName, CharSequence)easier for device owner cases. -
getOrganizationColor
-
setAutoTimeEnabled
-
getAutoTimeEnabled
-
setAutoTimeRequired
-
getAutoTimeRequired
-
setAutoTimeZoneEnabled
@Implementation(minSdk=30) protected void setAutoTimeZoneEnabled(ComponentName admin, boolean enabled) -
getAutoTimeZoneEnabled
-
setTimeZone
-
getTimeZone
Returns the time zone set by setTimeZone. -
setPermittedAccessibilityServices
@Implementation protected boolean setPermittedAccessibilityServices(ComponentName admin, List<String> packageNames) Sets permitted accessibility services.The API can be called by either a profile or device owner.
This method does not check already enabled non-system accessibility services, so will always set the restriction and return true.
-
getPermittedAccessibilityServices
-
setPermittedInputMethods
@Implementation protected boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) Sets permitted input methods.The API can be called by either a profile or device owner.
This method does not check already enabled non-system input methods, so will always set the restriction and return true.
-
getPermittedInputMethods
-
getStorageEncryptionStatus
- Returns:
- the previously set status; default is
DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED - See Also:
-
setStorageEncryptionStatus
public void setStorageEncryptionStatus(int status) Setter forDevicePolicyManager.getStorageEncryptionStatus(). -
setStorageEncryption
-
getStorageEncryption
-
getPermissionGrantState
@Implementation(minSdk=23) protected int getPermissionGrantState(ComponentName admin, String packageName, String permission) -
isPermissionGranted
-
setPermissionGrantState
@Implementation(minSdk=23) protected boolean setPermissionGrantState(ComponentName admin, String packageName, String permission, int grantState) -
lockNow
-
wipeData
-
getWipeCalledTimes
public long getWipeCalledTimes() -
setPasswordQuality
-
getPasswordQuality
-
resetPassword
-
resetPasswordWithToken
@Implementation(minSdk=26) protected boolean resetPasswordWithToken(ComponentName admin, String password, byte[] token, int flags) -
isResetPasswordTokenActive
-
setResetPasswordToken
@Implementation(minSdk=26) protected boolean setResetPasswordToken(ComponentName admin, byte[] token) -
setPasswordMinimumLength
-
getPasswordMinimumLength
-
setPasswordMinimumLetters
-
getPasswordMinimumLetters
-
setPasswordMinimumLowerCase
-
getPasswordMinimumLowerCase
-
setPasswordMinimumUpperCase
-
getPasswordMinimumUpperCase
-
setPasswordMinimumNonLetter
-
getPasswordMinimumNonLetter
-
setPasswordMinimumNumeric
-
getPasswordMinimumNumeric
-
setPasswordMinimumSymbols
-
getPasswordMinimumSymbols
-
setMaximumFailedPasswordsForWipe
-
getMaximumFailedPasswordsForWipe
-
setCameraDisabled
-
getCameraDisabled
-
setPasswordExpirationTimeout
-
getPasswordExpirationTimeout
-
setPasswordExpiration
Sets the password expiration time for a particular admin.- Parameters:
admin- which DeviceAdminReceiver this request is associated with.timeout- the password expiration time, in milliseconds since epoch.
-
getPasswordExpiration
-
setMaximumTimeToLock
-
getMaximumTimeToLock
-
setPasswordHistoryLength
-
getPasswordHistoryLength
-
setActivePasswordSufficient
public void setActivePasswordSufficient(boolean sufficient) Sets if the password meets the current requirements.- Parameters:
sufficient- indicates the password meets the current requirements
-
isActivePasswordSufficient
-
setDeviceProvisioned
public void setDeviceProvisioned(boolean isProvisioned) Sets whether the device is provisioned. -
isDeviceProvisioned
-
setDeviceProvisioningConfigApplied
-
isDeviceProvisioningConfigApplied
-
setPasswordComplexity
public void setPasswordComplexity(int passwordComplexity) Sets the password complexity. -
getPasswordComplexity
-
getLastSetPassword
Retrieves last password set throughDevicePolicyManager.resetPassword(java.lang.String, int)orDevicePolicyManager.resetPasswordWithToken(android.content.ComponentName, java.lang.String, byte[], int). -
activateResetToken
Activates reset token for given admin.- Parameters:
admin- WhichDeviceAdminReceiverthis request is associated with.- Returns:
- if the activation state changed.
- Throws:
IllegalArgumentException- if there is no token set for this admin.
-
addPersistentPreferredActivity
@Implementation protected void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter, ComponentName activity) -
clearPackagePersistentPreferredActivities
@Implementation protected void clearPackagePersistentPreferredActivities(ComponentName admin, String packageName) -
setKeyguardDisabledFeatures
-
getKeyguardDisabledFeatures
-
setUserProvisioningState
public void setUserProvisioningState(int state) Sets the user provisioning state.- Parameters:
state- to store provisioning state
-
setUserProvisioningState
@Implementation(minSdk=33) protected void setUserProvisioningState(int state, UserHandle userHandle) -
getUserProvisioningState
Returns the provisioning state set insetUserProvisioningState(int), orDevicePolicyManager.STATE_USER_UNMANAGEDif none is set. -
hasGrantedPolicy
-
getLockTaskFeatures
-
setLockTaskFeatures
-
setLockTaskPackages
-
getLockTaskPackages
-
isLockTaskPermitted
-
setAffiliationIds
-
getAffiliationIds
-
setPermissionPolicy
-
getPermissionPolicy
-
grantPolicy
Grants a particular device policy for an active ComponentName.- Parameters:
admin- the ComponentName which DeviceAdminReceiver this request is associated with. Must be an active administrator, or an exception will be thrown. This value must never be null.usesPolicy- the uses-policy to check
-
getSystemUpdatePolicy
-
setSystemUpdatePolicy
@Implementation(minSdk=23) protected void setSystemUpdatePolicy(ComponentName admin, SystemUpdatePolicy policy) -
setSystemUpdatePolicy
Sets the system update policy. -
setBindDeviceAdminTargetUsers
Set the list of target users that the calling device or profile owner can use when callingbindDeviceAdminServiceAsUser(android.content.ComponentName, android.content.Intent, android.content.ServiceConnection, int, android.os.UserHandle). -
getBindDeviceAdminTargetUsers
@Implementation(minSdk=26) protected List<UserHandle> getBindDeviceAdminTargetUsers(ComponentName admin) Returns the list of target users that the calling device or profile owner can use when callingbindDeviceAdminServiceAsUser(android.content.ComponentName, android.content.Intent, android.content.ServiceConnection, int, android.os.UserHandle).- See Also:
-
bindDeviceAdminServiceAsUser
@Implementation(minSdk=26) protected boolean bindDeviceAdminServiceAsUser(ComponentName admin, Intent serviceIntent, ServiceConnection conn, int flags, UserHandle targetUser) Bind to the same package in another user.This validates that the targetUser is one from
getBindDeviceAdminTargetUsers(ComponentName)but does not actually bind to a different user, instead binding to the same user.It also does not validate the service being bound to.
-
setShortSupportMessage
@Implementation(minSdk=24) protected void setShortSupportMessage(ComponentName admin, CharSequence message) -
getShortSupportMessage
-
setLongSupportMessage
@Implementation(minSdk=24) protected void setLongSupportMessage(ComponentName admin, CharSequence message) -
getLongSupportMessage
-
setOrganizationOwnedDeviceWithManagedProfile
public void setOrganizationOwnedDeviceWithManagedProfile(boolean value) Sets the return value of theDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()method (only for Android R+). -
isOrganizationOwnedDeviceWithManagedProfile
Returns the value stored using in the shadow, while the real method returns the value store on the device.The value can be set by
setOrganizationOwnedDeviceWithManagedProfile(boolean)and isfalseby default. -
getNearbyNotificationStreamingPolicy
-
setNearbyNotificationStreamingPolicy
-
getNearbyAppStreamingPolicy
-
setNearbyAppStreamingPolicy
-
getDevicePolicyManagementRoleHolderPackage
-
setDevicePolicyManagementRoleHolderPackage
Sets the package name of the device policy management role holder. -
finalizeWorkProfileProvisioning
@Implementation(minSdk=33) protected void finalizeWorkProfileProvisioning(UserHandle managedProfileUser, Account migratedAccount) -
isWorkProfileProvisioningFinalized
Returns iffinalizeWorkProfileProvisioning(UserHandle, Account)was called with the provided parameters. -
getPolicyManagedProfiles
@Implementation(minSdk=33) protected List<UserHandle> getPolicyManagedProfiles(UserHandle userHandle) Returns the managed profiles set insetPolicyManagedProfiles(List). This value does not take the user handle parameter into account. -
setPolicyManagedProfiles
Sets the value returned bygetPolicyManagedProfiles(UserHandle). -
getUserProvisioningStateForUser
public int getUserProvisioningStateForUser(int userId) Returns the user provisioning state set bysetUserProvisioningState(int, UserHandle), orDevicePolicyManager.STATE_USER_UNMANAGEDif none is set. -
getDevicePolicyState
Return a stub value set bysetDevicePolicyState(DevicePolicyState policyState) -
setDevicePolicyState
Set theDevicePolicyStatewhich can be constructed fromDevicePolicyStateBuilder
-