Class ShadowDevicePolicyManager
@Implements(android.app.admin.DevicePolicyManager.class) public class ShadowDevicePolicyManager extends Object
-
Constructor Summary
Constructors Constructor Description ShadowDevicePolicyManager()
-
Method Summary
Modifier and Type Method Description protected void
__constructor__(Context context, boolean parentInstance)
protected void
__constructor__(Context context, IDevicePolicyManager service)
protected void
__constructor__(Context context, Handler handler)
boolean
activateResetToken(ComponentName admin)
Activates reset token for given admin.protected void
addPersistentPreferredActivity(ComponentName admin, IntentFilter filter, ComponentName activity)
protected void
addUserRestriction(ComponentName admin, String key)
protected boolean
bindDeviceAdminServiceAsUser(ComponentName admin, Intent serviceIntent, ServiceConnection conn, int flags, UserHandle targetUser)
Bind to the same package in another user.protected void
clearPackagePersistentPreferredActivities(ComponentName admin, String packageName)
protected void
clearProfileOwner(ComponentName admin)
protected void
clearUserRestriction(ComponentName admin, String key)
protected void
enableSystemApp(ComponentName admin, String packageName)
void
failSetApplicationHiddenFor(Collection<String> packagesToFail)
Set package names for witchDevicePolicyManager.setApplicationHidden(android.content.ComponentName, java.lang.String, boolean)
should fail.protected String[]
getAccountTypesWithManagementDisabled()
protected List<ComponentName>
getActiveAdmins()
protected Set<String>
getAffiliationIds(ComponentName admin)
protected Bundle
getApplicationRestrictions(ComponentName admin, String packageName)
Bundle
getApplicationRestrictions(String packageName)
Returns all application restrictions of thepackageName
in aBundle
.protected boolean
getAutoTimeRequired()
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)
.protected boolean
getCameraDisabled(ComponentName admin)
protected String
getDeviceOwner()
protected int
getKeyguardDisabledFeatures(ComponentName admin)
String
getLastSetPassword()
Retrieves last password set throughDevicePolicyManager.resetPassword(java.lang.String, int)
orDevicePolicyManager.resetPasswordWithToken(android.content.ComponentName, java.lang.String, byte[], int)
.protected String[]
getLockTaskPackages(ComponentName admin)
protected CharSequence
getLongSupportMessage(ComponentName admin)
protected int
getMaximumFailedPasswordsForWipe(ComponentName admin)
protected long
getMaximumTimeToLock(ComponentName admin)
protected int
getNearbyAppStreamingPolicy()
protected int
getNearbyNotificationStreamingPolicy()
protected int
getOrganizationColor(ComponentName admin)
protected CharSequence
getOrganizationName(ComponentName admin)
Returns organization name.protected int
getPasswordComplexity()
protected long
getPasswordExpiration(ComponentName admin)
protected long
getPasswordExpirationTimeout(ComponentName admin)
protected int
getPasswordHistoryLength(ComponentName admin)
protected int
getPasswordMinimumLength(ComponentName admin)
protected int
getPasswordMinimumLetters(ComponentName admin)
protected int
getPasswordMinimumLowerCase(ComponentName admin)
protected int
getPasswordMinimumNonLetter(ComponentName admin)
protected int
getPasswordMinimumNumeric(ComponentName admin)
protected int
getPasswordMinimumSymbols(ComponentName admin)
protected int
getPasswordMinimumUpperCase(ComponentName admin)
protected int
getPasswordQuality(ComponentName admin)
protected int
getPermissionGrantState(ComponentName admin, String packageName, String permission)
protected int
getPermissionPolicy(ComponentName admin)
protected List<String>
getPermittedAccessibilityServices(ComponentName admin)
protected List<String>
getPermittedInputMethods(ComponentName admin)
protected ComponentName
getProfileOwner()
protected String
getProfileOwnerNameAsUser(int userId)
Returns the human-readable name of the profile owner for a user if set usingsetProfileOwnerName(int, java.lang.String)
, otherwise null.protected CharSequence
getShortSupportMessage(ComponentName admin)
protected boolean
getStorageEncryption(ComponentName admin)
protected int
getStorageEncryptionStatus()
protected SystemUpdatePolicy
getSystemUpdatePolicy()
protected int
getUserProvisioningState()
long
getWipeCalledTimes()
void
grantPolicy(ComponentName admin, int usesPolicy)
Grants a particular device policy for an active ComponentName.protected boolean
hasGrantedPolicy(ComponentName admin, int usesPolicy)
protected boolean
isActivePasswordSufficient()
protected boolean
isAdminActive(ComponentName who)
protected boolean
isApplicationHidden(ComponentName admin, String packageName)
boolean
isDeviceManaged()
protected boolean
isDeviceOwnerApp(String packageName)
protected boolean
isDeviceProvisioned()
protected boolean
isDeviceProvisioningConfigApplied()
protected boolean
isLockTaskPermitted(String pkg)
protected boolean
isOrganizationOwnedDeviceWithManagedProfile()
Returns the value stored using in the shadow, while the real method returns the value store on the device.protected boolean
isPackageSuspended(ComponentName admin, String packageName)
boolean
isPermissionGranted(String packageName, String permission)
protected boolean
isProfileOwnerApp(String packageName)
protected boolean
isResetPasswordTokenActive(ComponentName admin)
protected boolean
isUninstallBlocked(ComponentName admin, String packageName)
protected void
lockNow()
protected void
removeActiveAdmin(ComponentName admin)
protected boolean
resetPassword(String password, int flags)
protected boolean
resetPasswordWithToken(ComponentName admin, String password, byte[] token, int flags)
protected void
setAccountManagementDisabled(ComponentName admin, String accountType, boolean disabled)
void
setActiveAdmin(ComponentName componentName)
Sets the givencomponentName
as one of the active admins.void
setActivePasswordSufficient(boolean sufficient)
Sets if the password meets the current requirements.protected void
setAffiliationIds(ComponentName admin, Set<String> ids)
protected boolean
setApplicationHidden(ComponentName admin, String packageName, boolean hidden)
protected void
setApplicationRestrictions(ComponentName admin, String packageName, Bundle applicationRestrictions)
void
setApplicationRestrictions(String packageName, Bundle applicationRestrictions)
Sets the application restrictions of thepackageName
.protected void
setAutoTimeRequired(ComponentName admin, boolean required)
void
setBindDeviceAdminTargetUsers(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 void
setCameraDisabled(ComponentName admin, boolean disabled)
void
setDeviceOwner(ComponentName admin)
Sets the admin as active admin and device owner.void
setDeviceProvisioned(boolean isProvisioned)
Sets whether the device is provisioned.protected void
setDeviceProvisioningConfigApplied()
protected void
setKeyguardDisabledFeatures(ComponentName admin, int which)
protected void
setLockTaskPackages(ComponentName admin, String[] packages)
protected void
setLongSupportMessage(ComponentName admin, CharSequence message)
protected void
setMaximumFailedPasswordsForWipe(ComponentName admin, int num)
protected void
setMaximumTimeToLock(ComponentName admin, long timeMs)
protected void
setNearbyAppStreamingPolicy(int policy)
protected void
setNearbyNotificationStreamingPolicy(int policy)
protected void
setOrganizationColor(ComponentName admin, int color)
protected void
setOrganizationName(ComponentName admin, CharSequence name)
Sets organization name.void
setOrganizationOwnedDeviceWithManagedProfile(boolean value)
Sets the return value of theDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()
method (only for Android R+).protected String[]
setPackagesSuspended(ComponentName admin, String[] packageNames, boolean suspended)
void
setPasswordComplexity(int passwordComplexity)
Sets the password complexity.void
setPasswordExpiration(ComponentName admin, long timeout)
Sets the password expiration time for a particular admin.protected void
setPasswordExpirationTimeout(ComponentName admin, long timeout)
protected void
setPasswordHistoryLength(ComponentName admin, int length)
protected void
setPasswordMinimumLength(ComponentName admin, int length)
protected void
setPasswordMinimumLetters(ComponentName admin, int length)
protected void
setPasswordMinimumLowerCase(ComponentName admin, int length)
protected void
setPasswordMinimumNonLetter(ComponentName admin, int length)
protected void
setPasswordMinimumNumeric(ComponentName admin, int length)
protected void
setPasswordMinimumSymbols(ComponentName admin, int length)
protected void
setPasswordMinimumUpperCase(ComponentName admin, int length)
protected void
setPasswordQuality(ComponentName admin, int quality)
protected boolean
setPermissionGrantState(ComponentName admin, String packageName, String permission, int grantState)
protected void
setPermissionPolicy(ComponentName admin, int policy)
protected boolean
setPermittedAccessibilityServices(ComponentName admin, List<String> packageNames)
Sets permitted accessibility services.protected boolean
setPermittedInputMethods(ComponentName admin, List<String> packageNames)
Sets permitted input methods.void
setProfileOwner(ComponentName admin)
Sets the admin as active admin and profile owner.void
setProfileOwnerName(int userId, String name)
protected boolean
setResetPasswordToken(ComponentName admin, byte[] token)
protected void
setShortSupportMessage(ComponentName admin, CharSequence message)
protected int
setStorageEncryption(ComponentName admin, boolean encrypt)
void
setStorageEncryptionStatus(int status)
Setter forDevicePolicyManager.getStorageEncryptionStatus()
.void
setSystemUpdatePolicy(SystemUpdatePolicy policy)
Sets the system update policy.protected void
setSystemUpdatePolicy(ComponentName admin, SystemUpdatePolicy policy)
protected void
setUninstallBlocked(ComponentName admin, String packageName, boolean uninstallBlocked)
void
setUserProvisioningState(int state)
Sets the user provisioning state.boolean
wasPackageEverHidden(String packageName)
Returnstrue
if the givenpackageName
was ever hidden.boolean
wasSystemAppEnabled(String packageName)
Returnstrue
if the givenpackageName
was a system app and was enabled.protected void
wipeData(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(minSdk=21) 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 ornull
to clear the packages.
-
isApplicationHidden
@Implementation(minSdk=21) protected boolean isApplicationHidden(ComponentName admin, String packageName) -
wasPackageEverHidden
Returnstrue
if the givenpackageName
was ever hidden. -
enableSystemApp
-
wasSystemAppEnabled
Returnstrue
if the givenpackageName
was a system app and was enabled. -
setUninstallBlocked
@Implementation(minSdk=21) protected void setUninstallBlocked(ComponentName admin, String packageName, boolean uninstallBlocked) -
isUninstallBlocked
@Implementation(minSdk=21) protected boolean isUninstallBlocked(ComponentName admin, String packageName) -
getDeviceOwner
- See Also:
setDeviceOwner(ComponentName)
-
isDeviceManaged
- See Also:
setDeviceOwner(ComponentName)
-
getProfileOwner
- See Also:
setProfileOwner(ComponentName)
-
getProfileOwnerNameAsUser
Returns the human-readable name of the profile owner for a user if set usingsetProfileOwnerName(int, java.lang.String)
, otherwise null. -
setDeviceOwner
Sets the admin as active admin and device owner.- See Also:
DevicePolicyManager.getDeviceOwner()
-
setProfileOwner
Sets the admin as active admin and profile owner.- See Also:
DevicePolicyManager.getProfileOwner()
-
setProfileOwnerName
-
setActiveAdmin
Sets the givencomponentName
as one of the active admins. -
removeActiveAdmin
-
clearProfileOwner
-
getApplicationRestrictions
@Implementation(minSdk=21) protected Bundle getApplicationRestrictions(ComponentName admin, String packageName) -
getApplicationRestrictions
Returns all application restrictions of thepackageName
in aBundle
. -
setApplicationRestrictions
@Implementation(minSdk=21) protected void setApplicationRestrictions(ComponentName admin, String packageName, Bundle applicationRestrictions) -
setApplicationRestrictions
Sets the application restrictions of thepackageName
.The new
applicationRestrictions
always completely overwrites any existing ones. -
setAccountManagementDisabled
@Implementation(minSdk=21) 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
-
setAutoTimeRequired
@Implementation(minSdk=21) protected void setAutoTimeRequired(ComponentName admin, boolean required) -
getAutoTimeRequired
-
setPermittedAccessibilityServices
@Implementation(minSdk=21) 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
@Implementation(minSdk=21) protected List<String> getPermittedAccessibilityServices(ComponentName admin) -
setPermittedInputMethods
@Implementation(minSdk=21) 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(int)
-
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
- WhichDeviceAdminReceiver
this request is associated with.- Returns:
- if the activation state changed.
- Throws:
IllegalArgumentException
- if there is no token set for this admin.
-
addPersistentPreferredActivity
@Implementation(minSdk=21) protected void addPersistentPreferredActivity(ComponentName admin, IntentFilter filter, ComponentName activity) -
clearPackagePersistentPreferredActivities
@Implementation(minSdk=21) protected void clearPackagePersistentPreferredActivities(ComponentName admin, String packageName) -
setKeyguardDisabledFeatures
@Implementation(minSdk=17) protected void setKeyguardDisabledFeatures(ComponentName admin, int which) -
getKeyguardDisabledFeatures
-
setUserProvisioningState
public void setUserProvisioningState(int state)Sets the user provisioning state.- Parameters:
state
- to store provisioning state
-
getUserProvisioningState
- Returns:
- Returns the provisioning state for the current user.
-
hasGrantedPolicy
-
setLockTaskPackages
@Implementation(minSdk=21) protected void setLockTaskPackages(ComponentName admin, String[] packages) -
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:
setBindDeviceAdminTargetUsers(List)
-
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 isfalse
by default. -
getNearbyNotificationStreamingPolicy
-
setNearbyNotificationStreamingPolicy
-
getNearbyAppStreamingPolicy
-
setNearbyAppStreamingPolicy
-