Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 254cb446 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

More device admin.

- Clean up device policy manager APIs.
- Implement lockNow().  For now this just turns the screen off to lock the device.
parent 2fd75f35
Loading
Loading
Loading
Loading
+34 −2
Original line number Diff line number Diff line
@@ -20421,6 +20421,19 @@
 visibility="public"
>
</method>
<method name="getMaximumFailedPasswordsForWipe"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="admin" type="android.content.ComponentName">
</parameter>
</method>
<method name="getMaximumTimeToLock"
 return="long"
 abstract="false"
@@ -20431,8 +20444,23 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="admin" type="android.content.ComponentName">
</parameter>
</method>
<method name="getPasswordMaximumLength"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="mode" type="int">
</parameter>
</method>
<method name="getMinimumPasswordLength"
<method name="getPasswordMinimumLength"
 return="int"
 abstract="false"
 native="false"
@@ -20442,6 +20470,8 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="admin" type="android.content.ComponentName">
</parameter>
</method>
<method name="getPasswordMode"
 return="int"
@@ -20453,6 +20483,8 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="admin" type="android.content.ComponentName">
</parameter>
</method>
<method name="isActivePasswordSufficient"
 return="boolean"
@@ -20545,7 +20577,7 @@
<parameter name="timeMs" type="long">
</parameter>
</method>
<method name="setMinimumPasswordLength"
<method name="setPasswordMinimumLength"
 return="void"
 abstract="false"
 native="false"
+6 −7
Original line number Diff line number Diff line
@@ -99,11 +99,10 @@ public class DeviceAdmin extends BroadcastReceiver {
    /**
     * Action sent to a device administrator when the user has changed the
     * password of their device.  You can at this point check the characteristics
     * of the new password with {@link DevicePolicyManager#getPasswordMode()
     * DevicePolicyManager.getActivePasswordMode()} and
     * {@link DevicePolicyManager#getMinimumPasswordLength()
     * DevicePolicyManager.getMinimumPasswordLength()}.  You will generally
     * handle this in {@link DeviceAdmin#onPasswordChanged(Context, Intent)}.
     * of the new password with {@link DevicePolicyManager#isActivePasswordSufficient()
     * DevicePolicyManager.isActivePasswordSufficient()}.
     * You will generally
     * handle this in {@link DeviceAdmin#onPasswordChanged}.
     * 
     * <p>The calling device admin must have requested
     * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to receive
@@ -117,9 +116,9 @@ public class DeviceAdmin extends BroadcastReceiver {
     * Action sent to a device administrator when the user has failed at
     * attempted to enter the password.  You can at this point check the
     * number of failed password attempts there have been with
     * {@link DevicePolicyManager#getCurrentFailedPasswordAttempts()
     * {@link DevicePolicyManager#getCurrentFailedPasswordAttempts
     * DevicePolicyManager.getCurrentFailedPasswordAttempts()}.  You will generally
     * handle this in {@link DeviceAdmin#onPasswordFailed(Context, Intent)}.
     * handle this in {@link DeviceAdmin#onPasswordFailed}.
     * 
     * <p>The calling device admin must have requested
     * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to receive
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public final class DeviceAdminInfo implements Parcelable {
    /**
     * A type of policy that this device admin can use: limit the passwords
     * that the user can select, via {@link DevicePolicyManager#setPasswordMode}
     * and {@link DevicePolicyManager#setMinimumPasswordLength}.
     * and {@link DevicePolicyManager#setPasswordMinimumLength}.
     * 
     * <p>To control this policy, the device admin must have a "limit-password"
     * tag in the "uses-policies" section of its meta-data.
+52 −16
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ public class DevicePolicyManager {
    /**
     * Activity action: have the user enter a new password.  This activity
     * should be launched after using {@link #setPasswordMode(ComponentName, int)}
     * or {@link #setMinimumPasswordLength(ComponentName, int)} to have the
     * or {@link #setPasswordMinimumLength(ComponentName, int)} to have the
     * user enter a new password that meets the current requirements.  You can
     * use {@link #isActivePasswordSufficient()} to determine whether you need
     * to have the user select a new password in order to meet the current
@@ -210,13 +210,15 @@ public class DevicePolicyManager {
    }
    
    /**
     * Retrieve the current password mode that is in effect due to all
     * device admins.
     * Retrieve the current minimum password mode for all admins
     * or a particular one.
     * @param admin The name of the admin component to check, or null to aggregate
     * all admins.
     */
    public int getPasswordMode() {
    public int getPasswordMode(ComponentName admin) {
        if (mService != null) {
            try {
                return mService.getPasswordMode();
                return mService.getPasswordMode(admin);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed talking with device policy service", e);
            }
@@ -244,10 +246,10 @@ public class DevicePolicyManager {
     * @param length The new desired minimum password length.  A value of 0
     * means there is no restriction.
     */
    public void setMinimumPasswordLength(ComponentName admin, int length) {
    public void setPasswordMinimumLength(ComponentName admin, int length) {
        if (mService != null) {
            try {
                mService.setMinimumPasswordLength(admin, length);
                mService.setPasswordMinimumLength(admin, length);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed talking with device policy service", e);
            }
@@ -255,13 +257,15 @@ public class DevicePolicyManager {
    }
    
    /**
     * Retrieve the current minimum password length that is in effect due to all
     * device admins.
     * Retrieve the current minimum password length for all admins
     * or a particular one.
     * @param admin The name of the admin component to check, or null to aggregate
     * all admins.
     */
    public int getMinimumPasswordLength() {
    public int getPasswordMinimumLength(ComponentName admin) {
        if (mService != null) {
            try {
                return mService.getMinimumPasswordLength();
                return mService.getPasswordMinimumLength(admin);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed talking with device policy service", e);
            }
@@ -269,6 +273,17 @@ public class DevicePolicyManager {
        return 0;
    }
    
    /**
     * Return the maximum password length that the device supports for a
     * particular password mode.
     * @param mode The mode being interrogated.
     * @return Returns the maximum length that the user can enter.
     */
    public int getPasswordMaximumLength(int mode) {
        // Kind-of arbitrary.
        return 16;
    }
    
    /**
     * Determine whether the current password the user has set is sufficient
     * to meet the policy requirements (mode, minimum length) that have been
@@ -334,12 +349,31 @@ public class DevicePolicyManager {
        }
    }
    
    /**
     * Retrieve the current maximum number of login attempts that are allowed
     * before the device wipes itself, for all admins
     * or a particular one.
     * @param admin The name of the admin component to check, or null to aggregate
     * all admins.
     */
    public int getMaximumFailedPasswordsForWipe(ComponentName admin) {
        if (mService != null) {
            try {
                return mService.getMaximumFailedPasswordsForWipe(admin);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed talking with device policy service", e);
            }
        }
        return 0;
    }
    
    /**
     * Force a new password on the user.  This takes effect immediately.  The
     * given password must meet the current password minimum length constraint
     * or it will be rejected.  The given password will be accepted regardless
     * of the current password mode, automatically adjusting the password mode
     * higher if needed.  (The string you give here is acceptable for any mode;
     * higher if needed to meet the requirements of all active administrators.
     * (The string you give here is acceptable for any mode;
     * if it contains only digits, that is still an acceptable alphanumeric
     * password.)
     * 
@@ -386,13 +420,15 @@ public class DevicePolicyManager {
    }
    
    /**
     * Retrieve the current maximum time to lock that is in effect due to all
     * device admins.  Returns 0 if no maximum is set.
     * Retrieve the current maximum time to unlock for all admins
     * or a particular one.
     * @param admin The name of the admin component to check, or null to aggregate
     * all admins.
     */
    public long getMaximumTimeToLock() {
    public long getMaximumTimeToLock(ComponentName admin) {
        if (mService != null) {
            try {
                return mService.getMaximumTimeToLock();
                return mService.getMaximumTimeToLock(admin);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed talking with device policy service", e);
            }
+6 −4
Original line number Diff line number Diff line
@@ -26,19 +26,21 @@ import android.os.RemoteCallback;
 */
interface IDevicePolicyManager {
    void setPasswordMode(in ComponentName who, int mode);
    int getPasswordMode();
    int getPasswordMode(in ComponentName who);
    
    void setMinimumPasswordLength(in ComponentName who, int length);
    int getMinimumPasswordLength();
    void setPasswordMinimumLength(in ComponentName who, int length);
    int getPasswordMinimumLength(in ComponentName who);
    
    boolean isActivePasswordSufficient();
    int getCurrentFailedPasswordAttempts();
    
    void setMaximumFailedPasswordsForWipe(in ComponentName admin, int num);
    int getMaximumFailedPasswordsForWipe(in ComponentName admin);
    
    boolean resetPassword(String password);
    
    void setMaximumTimeToLock(in ComponentName who, long timeMs);
    long getMaximumTimeToLock();
    long getMaximumTimeToLock(in ComponentName who);
    
    void lockNow();
    
Loading