Added in API level 1
public interface

IAfexAdminManager

com.ardic.android.managers.afexadmin.IAfexAdminManager

Class Overview

Provides a set of APIs for self activated AFEX device admin. All device administration operations provided by AFEX admin manager.

Summary

Public Methods
abstract ComponentName getActiveAdmin()
Returns activated device admin ComponentName to be used for getting admin configurations.
abstract int getActivePasswordQuality()
Returns the active password quality.
abstract Bitmap getLockViewIcon()
Returns the lock view message icon.
abstract String getLockViewText()
Returns the lock view message text.
abstract int getPasswordMaximumLetterSequence()
Returns the maximum letter sequence length allowed in the device password.
abstract int getPasswordMaximumNumericSequence()
Returns the maximum numeric sequence length allowed in the device password.
abstract int getPasswordMaximumSymbolSequence()
Returns the maximum symbol sequence length allowed in the device password.
abstract String getRequiredPasswordPattern()
Returns a pattern for password match.
abstract boolean isActivePasswordSufficient()
Determine whether the current password the user has set is sufficient to meet the policy requirements (quality, minimum length) that have been requested.
abstract boolean isCameraDisabled()
Returns camera disabled state.
abstract boolean isLocked()
Returns lock screen status.
abstract boolean isPasswordChangeEnforced()
Returns password change enforced state.
abstract void lockNow()
Make the device lock immediately, as if the lock screen timeout has expired at the point of this call.
abstract boolean resetPassword(String password, int flags)
Force a new device unlock password (the password needed to access the entire device, not for individual accounts) on the user.
abstract void setCameraDisabled(boolean disabled)
Called by an application that is administering the device to disable all cameras on the device.
abstract boolean setLockViewIcon(Bitmap icon)
Sets the lock view message icon by the given bitmap icon.
abstract boolean setLockViewText(String text)
Sets the lock view message text by the given text.
abstract void setMaximumFailedPasswordsForWipe(int num)
Setting this to a value greater than zero enables a built-in policy that will perform a device wipe after too many incorrect device-unlock passwords have been entered.
abstract void setMaximumTimeToLock(long timeMs)
Called by an application that is administering the device to set the maximum time for user activity until the device will lock.
abstract boolean setPasswordChangeEnforced(boolean state)
Sets password change state enforced.
abstract void setPasswordExpirationTimeout(long timeout)
Called by a device admin to set the password expiration timeout.
abstract void setPasswordHistoryLength(int length)
Called by an application that is administering the device to set the length of the password history.
abstract boolean setPasswordMaximumLetterSequence(int length)
Sets the maximum letter sequence length allowed in the device.
abstract boolean setPasswordMaximumNumericSequence(int length)
Sets the maximum numeric sequence length allowed in the device.
abstract boolean setPasswordMaximumSymbolSequence(int length)
Sets the maximum symbol sequence length allowed in the device.
abstract void setPasswordMinimumLength(int length)
Called by an application that is administering the device to set the minimum allowed password length.
abstract void setPasswordMinimumLetters(int length)
Called by an application that is administering the device to set the minimum number of letters required in the password.
abstract void setPasswordMinimumLowerCase(int length)
Called by an application that is administering the device to set the minimum number of lower case letters required in the password.
abstract void setPasswordMinimumNonLetter(int length)
Called by an application that is administering the device to set the minimum number of non-letter characters (numerical digits or symbols) required in the password.
abstract void setPasswordMinimumNumeric(int length)
Called by an application that is administering the device to set the minimum number of numerical digits required in the password.
abstract void setPasswordMinimumSymbols(int length)
Called by an application that is administering the device to set the minimum number of symbols required in the password.
abstract void setPasswordMinimumUpperCase(int length)
Called by an application that is administering the device to set the minimum number of upper case letters required in the password.
abstract void setPasswordQuality(int quality)
Called by an application that is administering the device to set the password restrictions it is imposing.
abstract boolean setRequiredPasswordPattern(String regex)
Sets a pattern for password match.
abstract int setStorageEncryption(boolean encrypt)
Called by an application that is administering the device to request that the storage system be encrypted.
abstract boolean startStorageEncryption()
Starts by an application that is administering the device to request that the storage system encryption to be started.
abstract String validatePasswordPattern(String password)
Validates password if password pattern is set.
abstract String validatePasswordSequence(String password)
Validates password if password sequence length is set.
abstract void wipeData(int flags)
Ask the user data be wiped.

Public Methods

public abstract ComponentName getActiveAdmin ()

Added in API level 1

Returns activated device admin ComponentName to be used for getting admin configurations.

Returns
ComponentName Device admin ComponentName
Throws
AfexException

public abstract int getActivePasswordQuality ()

Added in API level 2

public abstract Bitmap getLockViewIcon ()

Added in API level 1

Returns the lock view message icon.

Returns
Bitmap Bitmap if lock icon exist else null
Throws
AfexException

public abstract String getLockViewText ()

Added in API level 1

Returns the lock view message text.

Returns
String String if lock message exist else null
Throws
AfexException

public abstract int getPasswordMaximumLetterSequence ()

Added in API level 2

Returns the maximum letter sequence length allowed in the device password.

Returns
int The maximum allowed letter sequence length. A value of '0' specifies that no such letter sequence restrictions are applied.
Throws
AfexException

public abstract int getPasswordMaximumNumericSequence ()

Added in API level 2

Returns the maximum numeric sequence length allowed in the device password.

Returns
int The maximum allowed numeric sequence length. A value of '0' specifies that no such numeric sequence restrictions are applied.
Throws
AfexException

public abstract int getPasswordMaximumSymbolSequence ()

Added in API level 2

Returns the maximum symbol sequence length allowed in the device password.

Returns
int The maximum allowed symbol sequence length. A value of '0' specifies that no such symbol sequence restrictions are applied.
Throws
AfexException

public abstract String getRequiredPasswordPattern ()

Added in API level 2

Returns a pattern for password match.

Returns
String Regex pattern.
Throws
AfexException
AfexException

See also:

public abstract boolean isActivePasswordSufficient ()

Added in API level 1

Determine whether the current password the user has set is sufficient to meet the policy requirements (quality, minimum length) that have been requested.

Returns
boolean true if the password meets the current requirements else false
Throws
AfexException

public abstract boolean isCameraDisabled ()

Added in API level 1

Returns camera disabled state.

Returns
boolean true if camera disabled else false
Throws
AfexException

public abstract boolean isLocked ()

Added in API level 1

Returns lock screen status. Warning; If screenlock set to none, this api always returns false.

Returns
boolean true if lock screen is locked state else false
Throws
AfexException

public abstract boolean isPasswordChangeEnforced ()

Added in API level 2

Returns password change enforced state.

Returns
boolean true if password change is enforced state else false
Throws
AfexException

public abstract void lockNow ()

Added in API level 1

Make the device lock immediately, as if the lock screen timeout has expired at the point of this call.

Throws
AfexException

public abstract boolean resetPassword (String password, int flags)

Added in API level 1

Force a new device unlock password (the password needed to access the entire device, not for individual accounts) on the user. This takes effect immediately.

The given password must be sufficient for the current password quality and length constraints as returned by getPasswordQuality(ComponentName) and getPasswordMinimumLength(ComponentName); if it does not meet these constraints, then it will be rejected and false returned.

Note that the password may be a stronger quality (containing alphanumeric characters when the requested quality is only numeric), in which case the currently active quality will be increased to match.

To reject password entry try following code;

 setPasswordQuality(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
 resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
 
Warning: If there is any installed certificates while resetting password by preceding way can not be applied and it returns false.

Parameters
password String: The new password for the user.
flags int: May be 0 or RESET_PASSWORD_REQUIRE_ENTRY.
Returns
boolean true if the password was applied, or false if it is not acceptable for the current constraints.
Throws
AfexException

public abstract void setCameraDisabled (boolean disabled)

Added in API level 1

Called by an application that is administering the device to disable all cameras on the device. After setting this, no applications will be able to access any cameras on the device.

Parameters
disabled boolean: Whether or not the camera should be disabled.
Throws
AfexException

public abstract boolean setLockViewIcon (Bitmap icon)

Added in API level 1

Sets the lock view message icon by the given bitmap icon.

 int width = 50, height = 50;
 Bitmap.Config config = Bitmap.Config.ARGB_8888;
 Bitmap bitmap = Bitmap.createBitmap(width, height, config); // this creates a
 // mutable bitmap
 bitmap.eraseColor(Color.RED);
 setLockViewIcon(bitmap);
 

Parameters
icon Bitmap: Bitmap to set lock icon or null to delete icon.
Returns
boolean true if the operation succeeds else false
Throws
AfexException

public abstract boolean setLockViewText (String text)

Added in API level 1

Sets the lock view message text by the given text.

Parameters
text String: String to set lock message or null to delete message.
Returns
boolean true if the operation succeeds else false
Throws
AfexException

public abstract void setMaximumFailedPasswordsForWipe (int num)

Added in API level 1

Setting this to a value greater than zero enables a built-in policy that will perform a device wipe after too many incorrect device-unlock passwords have been entered.

This built-in policy combines watching for failed passwords and wiping the device, and requires that you request both USES_POLICY_WATCH_LOGIN and USES_POLICY_WIPE_DATA.

To implement any other policy (for example wiping data for a particular application only, erasing or revoking credentials, or reporting the failure to a server), you should implement onPasswordFailed(Context, android.content.Intent) instead. Do not use this API, because if the maximum count is reached, the device will be wiped immediately, and your callback will not be invoked.

Parameters
num int: The number of failed password attempts at which point the device will wipe its data.
Throws
AfexException

public abstract void setMaximumTimeToLock (long timeMs)

Added in API level 1

Called by an application that is administering the device to set the maximum time for user activity until the device will lock.

This limits the length that the user can set. It takes effect immediately.

Parameters
timeMs long: The new desired maximum time to lock in milliseconds. A value of 0 means there is no restriction.
Throws
AfexException

public abstract boolean setPasswordChangeEnforced (boolean state)

Added in API level 2

Sets password change state enforced.

Usage

Called by an application that is managing the device to enforce an existing password to be changed (or created if device has no password). Admin can use it to present user a password dialog to change or setup new password. If a password is already set in the device and admin wants to let user cancel the password dialog for a period of time, he can use setPasswordExpirationTimeout(int) to set the period (in minutes) that the user can keep using the device before changing existing password (Default value is 0 - no option to cancel). If device has no password set, user will be enforced to set a password and will be given no option to cancel and the password change timeout will be ignored in this case.
 IAfexAdminManager aam = AfexAdminManager.getInterface(getApplicationContext());
 try {
     // Condition-1
     // if Device has no password and password change timeout is 0.
     boolean result = aam.setPasswordChangeEnforced(true);
     if (true == result) {
         // if successful user will be enforced to create a password with
         // no option to cancel dialog.
     }
 
     // Condition-2
     // if Device already has password and password change timeout is 0 .
     boolean result = aam.setPasswordChangeEnforced(true);
     if (true == result) {
         // if successful user will be enforced to change existing
         // password with no option to cancel dialog.
     }
 
     // Condition-3
     // if Device has no password and we set password change timeout to
     // some positive value.
     aam.setPasswordExpirationTimeout(10 * 60 * 1000); // minute * second * millisecond
     boolean result = aam.setPasswordChangeEnforced(true);
     if (true == result) {
         // if successful user will be enforced to create a password with
         // no option to cancel dialog because password change timeout is
         // only used for password changes, not new passwords.
     }
 
     // Condition-4
     // if Device already has password and we set password change timeout
     // to some positive value.
     aam.setPasswordExpirationTimeout(10);
     boolean result = aam.setPasswordChangeEnforced(true);
     if (true == result) {
         // if successful user will be enforced to change existing
         // password with the option to cancel it for the first time and
         // then after 10 minutes he will be prompted again with no
         // option to cancel.
     }
 } catch (AfexException e) {
     Log.w(TAG, "AfexException: " + e);
 }
 

Parameters
state boolean: true to enforce password change else false
Returns
boolean true if the operation succeeds else false
Throws
AfexException

public abstract void setPasswordExpirationTimeout (long timeout)

Added in API level 1

Called by a device admin to set the password expiration timeout.

Calling this method will restart the countdown for password expiration for the given admin, as will changing the device password (for all admins).

The provided timeout is the time delta in ms and will be added to the current time. For example, to have the password expire 5 days from now, timeout would be 5 * 86400 * 1000 = 432000000 ms for timeout.

To disable password expiration, a value of 0 may be used for timeout.

Parameters
timeout long: The limit (in ms) that a password can remain in effect. A value of 0 means there is no restriction (unlimited).
Throws
AfexException

public abstract void setPasswordHistoryLength (int length)

Added in API level 1

Called by an application that is administering the device to set the length of the password history.

After setting this, the user will not be able to enter a new password that is the same as any password in the history. Note that the current password will remain until the user has set a new one, so the change does not take place immediately. To prompt the user for a new password, use ACTION_SET_NEW_PASSWORD after setting this value. This constraint is only imposed if the administrator has also requested either PASSWORD_QUALITY_NUMERIC, PASSWORD_QUALITY_ALPHABETIC, PASSWORD_QUALITY_ALPHANUMERIC with setPasswordQuality(ComponentName, int).

Parameters
length int: The new desired length of password history. A value of 0 means there is no restriction.
Throws
AfexException

public abstract boolean setPasswordMaximumLetterSequence (int length)

Added in API level 2

Sets the maximum letter sequence length allowed in the device. For instance, if the length value is '4' then "12ab", "12qwe", "12zxcv" would all be letter sequences of length '4' and will be allowed in the device password.

Parameters
length int: The maximum allowed letter sequence length. A value of '0' specifies that no such letter sequence restrictions are applied.
Returns
boolean true if the operation succeeds else false
Throws
AfexException

public abstract boolean setPasswordMaximumNumericSequence (int length)

Added in API level 2

Sets the maximum numeric sequence length allowed in the device. For instance, if the length value is '4' then "ab12", "ab987", "ab4444" would all be numeric sequences of length '4' and will be allowed in the device password.

Parameters
length int: The maximum allowed numeric sequence length. A value of '0' specifies that no such numeric sequence restrictions are applied.
Returns
boolean true if the operation succeeds else false
Throws
AfexException

public abstract boolean setPasswordMaximumSymbolSequence (int length)

Added in API level 2

Sets the maximum symbol sequence length allowed in the device. For instance, if the length value is '4' then "12!@", "12%^&", "12()[]" would all be symbol sequences of length '4' and will be allowed in the device password.

Parameters
length int: The maximum allowed symbol sequence length. A value of '0' specifies that no such symbol sequence restrictions are applied.
Returns
boolean true if the operation succeeds else false
Throws
AfexException

public abstract void setPasswordMinimumLength (int length)

Added in API level 1

Called by an application that is administering the device to set the minimum allowed password length.

After setting this, the user will not be able to enter a new password that is not at least as restrictive as what has been set. Note that the current password will remain until the user has set a new one, so the change does not take place immediately. To prompt the user for a new password, use ACTION_SET_NEW_PASSWORD after setting this value. This constraint is only imposed if the administrator has also requested either PASSWORD_QUALITY_NUMERIC, PASSWORD_QUALITY_ALPHABETIC, PASSWORD_QUALITY_ALPHANUMERIC, PASSWORD_QUALITY_COMPLEX with setPasswordQuality(ComponentName, int).

Parameters
length int: The new desired minimum password length. A value of 0 means there is no restriction.
Throws
AfexException

public abstract void setPasswordMinimumLetters (int length)

Added in API level 1

Called by an application that is administering the device to set the minimum number of letters required in the password.

After setting this, the user will not be able to enter a new password that is not at least as restrictive as what has been set. Note that the current password will remain until the user has set a new one, so the change does not take place immediately. To prompt the user for a new password, use ACTION_SET_NEW_PASSWORD after setting this value. This constraint is only imposed if the administrator has also requested PASSWORD_QUALITY_COMPLEX with setPasswordQuality(ComponentName, int). The default value is 1.

Parameters
length int: The new desired minimum number of letters required in the password. A value of 0 means there is no restriction.
Throws
AfexException

public abstract void setPasswordMinimumLowerCase (int length)

Added in API level 1

Called by an application that is administering the device to set the minimum number of lower case letters required in the password.

After setting this, the user will not be able to enter a new password that is not at least as restrictive as what has been set. Note that the current password will remain until the user has set a new one, so the change does not take place immediately. To prompt the user for a new password, use ACTION_SET_NEW_PASSWORD after setting this value. This constraint is only imposed if the administrator has also requested PASSWORD_QUALITY_COMPLEX with setPasswordQuality(ComponentName, int). The default value is 0.

Parameters
length int: The new desired minimum number of lower case letters required in the password. A value of 0 means there is no restriction.
Throws
AfexException

public abstract void setPasswordMinimumNonLetter (int length)

Added in API level 1

Called by an application that is administering the device to set the minimum number of non-letter characters (numerical digits or symbols) required in the password.

After setting this, the user will not be able to enter a new password that is not at least as restrictive as what has been set. Note that the current password will remain until the user has set a new one, so the change does not take place immediately. To prompt the user for a new password, use ACTION_SET_NEW_PASSWORD after setting this value. This constraint is only imposed if the administrator has also requested PASSWORD_QUALITY_COMPLEX with setPasswordQuality(ComponentName, int). The default value is 0.

Parameters
length int: The new desired minimum number of letters required in the password. A value of 0 means there is no restriction.
Throws
AfexException

public abstract void setPasswordMinimumNumeric (int length)

Added in API level 1

Called by an application that is administering the device to set the minimum number of numerical digits required in the password.

After setting this, the user will not be able to enter a new password that is not at least as restrictive as what has been set. Note that the current password will remain until the user has set a new one, so the change does not take place immediately. To prompt the user for a new password, use ACTION_SET_NEW_PASSWORD after setting this value. This constraint is only imposed if the administrator has also requested PASSWORD_QUALITY_COMPLEX with setPasswordQuality(ComponentName, int). The default value is 1.

Parameters
length int: The new desired minimum number of numerical digits required in the password. A value of 0 means there is no restriction.
Throws
AfexException

public abstract void setPasswordMinimumSymbols (int length)

Added in API level 1

Called by an application that is administering the device to set the minimum number of symbols required in the password.

After setting this, the user will not be able to enter a new password that is not at least as restrictive as what has been set. Note that the current password will remain until the user has set a new one, so the change does not take place immediately. To prompt the user for a new password, use ACTION_SET_NEW_PASSWORD after setting this value. This constraint is only imposed if the administrator has also requested PASSWORD_QUALITY_COMPLEX with setPasswordQuality(ComponentName, int). The default value is 1.

Parameters
length int: The new desired minimum number of symbols required in the password. A value of 0 means there is no restriction.
Throws
AfexException

public abstract void setPasswordMinimumUpperCase (int length)

Added in API level 1

Called by an application that is administering the device to set the minimum number of upper case letters required in the password.

After setting this, the user will not be able to enter a new password that is not at least as restrictive as what has been set. Note that the current password will remain until the user has set a new one, so the change does not take place immediately. To prompt the user for a new password, use ACTION_SET_NEW_PASSWORD after setting this value. This constraint is only imposed if the administrator has also requested PASSWORD_QUALITY_COMPLEX with setPasswordQuality(ComponentName, int). The default value is 0.

Parameters
length int: The new desired minimum number of upper case letters required in the password. A value of 0 means there is no restriction.
Throws
AfexException

public abstract void setPasswordQuality (int quality)

Added in API level 1

Called by an application that is administering the device to set the password restrictions it is imposing.

After setting this, the user will not be able to enter a new password that is not at least as restrictive as what has been set. Note that the current password will remain until the user has set a new one, so the change does not take place immediately. To prompt the user for a new password, use ACTION_SET_NEW_PASSWORD after setting this value.

Quality constants are ordered so that higher values are more restrictive; thus the highest requested quality constant (between the policy set here, the user's preference, and any other considerations) is the one that is in effect.

To reject password entry try following code;

 setPasswordQuality(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
 resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
 

Parameters
quality int: The new desired quality. One of PASSWORD_QUALITY_UNSPECIFIED, PASSWORD_QUALITY_SOMETHING, PASSWORD_QUALITY_NUMERIC, PASSWORD_QUALITY_ALPHABETIC, PASSWORD_QUALITY_ALPHANUMERIC, PASSWORD_QUALITY_COMPLEX.
Throws
AfexException

public abstract boolean setRequiredPasswordPattern (String regex)

Added in API level 2

Sets a pattern for password match. MDM that last set the password pattern will become the password pattern owner, meaning that only his patterns will used to match the new passwords. Forces user to enter password based on a regular expression. For example if regular expression is [a-zA-Z]{2,4}[\d]{2,4}. Admin can force user to enter at least 4 and at most 8 character password with first at least 2 and at most 4 alphabetic characters and next at least 2 and at most 4 numeric characters. Admin must take care when setting this pattern. Warning: If user sets required password pattern, other password restrictions disregarded while password checking. Pattern has higher priority than other password maximum and minimum sequences.

Parameters
regex String: The required pattern to be matched or null to reset pattern.
Returns
boolean true if the operation succeeds else false
Throws
AfexException
AfexException

See also:

public abstract int setStorageEncryption (boolean encrypt)

Added in API level 1

Called by an application that is administering the device to request that the storage system be encrypted.

When multiple device administrators attempt to control device encryption, the most secure, supported setting will always be used. If any device administrator requests device encryption, it will be enabled; Conversely, if a device administrator attempts to disable device encryption while another device administrator has enabled it, the call to disable will fail (most commonly returning ENCRYPTION_STATUS_ACTIVE).

This policy controls encryption of the secure (application data) storage area. Data written to other storage areas may or may not be encrypted, and this policy does not require or control the encryption of any other storage areas. There is one exception: If isExternalStorageEmulated() is true, then the directory returned by getExternalStorageDirectory() must be written to disk within the encrypted storage area.

Important Note: On some devices, it is possible to encrypt storage without requiring the user to create a device PIN or Password. In this case, the storage is encrypted, but the encryption key may not be fully secured. For maximum security, the administrator should also require (and check for) a pattern, PIN, or password.

Parameters
encrypt boolean: true to request encryption, false to release any previous request
Returns
int the new request status (for all active admins) - will be one of ENCRYPTION_STATUS_UNSUPPORTED, ENCRYPTION_STATUS_INACTIVE, or ENCRYPTION_STATUS_ACTIVE. This is the value of the requests; Use getStorageEncryptionStatus() to query the actual device state.
Throws
AfexException

public abstract boolean startStorageEncryption ()

Added in API level 1

Starts by an application that is administering the device to request that the storage system encryption to be started.

Returns
boolean true if encryption started, false encryption is not supported.
Throws
AfexException

public abstract String validatePasswordPattern (String password)

Added in API level 2

Validates password if password pattern is set.

Warning : This api works on only Password Security mode. Which means password quality something of;

  • PASSWORD_QUALITY_ALPHABETIC
  • PASSWORD_QUALITY_ALPHANUMERIC
  • PASSWORD_QUALITY_COMPLEX
  • Parameters
    password String: Password string
    Returns
    String

    null if pattern control is passive

    empty String if pattern control is active and validation succeeded

    error String if pattern control is active and validation failed

    Throws
    AfexException

    public abstract String validatePasswordSequence (String password)

    Added in API level 2

    Validates password if password sequence length is set.

    Warning : This api works on only Password Security mode. Which means password quality something of;

  • PASSWORD_QUALITY_ALPHABETIC
  • PASSWORD_QUALITY_ALPHANUMERIC
  • PASSWORD_QUALITY_COMPLEX
  • Parameters
    password String: Password string
    Returns
    String

    null if sequence control is passive

    empty String if sequence control is active and validation succeeded

    error String if sequence control is active and validation failed

    Throws
    AfexException

    public abstract void wipeData (int flags)

    Added in API level 1

    Ask the user data be wiped. This will cause the device to reboot, erasing all user data while next booting up.

    External storage such as SD cards will be also erased if the flag WIPE_EXTERNAL_STORAGE is set.

    Parameters
    flags int: Bit mask of additional options: currently 0 and WIPE_EXTERNAL_STORAGE are supported.
    Throws
    AfexException