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

Commit 48b9b0d0 authored by Jim Miller's avatar Jim Miller
Browse files

Make DPM API for disabling keyguard widgets more generic

This change renames the widget-specific API to be more generic
to allow further disabling of keyguard-specific customizations
in the future.  Currently only allows disabling widgets and the
secure camera but can now easily be extended to disable other
features we add.

Fixes bug: 7021368

Change-Id: I3934cc2e7c64e0c6d511efb86980fc38a849708d
parent 6704a48b
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -4207,7 +4207,7 @@ package android.app.admin {
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final int USES_ENCRYPTED_STORAGE = 7; // 0x7
    field public static final int USES_POLICY_DISABLE_CAMERA = 8; // 0x8
    field public static final int USES_POLICY_DISABLE_KEYGUARD_WIDGETS = 9; // 0x9
    field public static final int USES_POLICY_DISABLE_KEYGUARD_FEATURES = 9; // 0x9
    field public static final int USES_POLICY_EXPIRE_PASSWORD = 6; // 0x6
    field public static final int USES_POLICY_FORCE_LOCK = 3; // 0x3
    field public static final int USES_POLICY_LIMIT_PASSWORD = 0; // 0x0
@@ -4243,7 +4243,7 @@ package android.app.admin {
    method public java.util.List<android.content.ComponentName> getActiveAdmins();
    method public boolean getCameraDisabled(android.content.ComponentName);
    method public int getCurrentFailedPasswordAttempts();
    method public int getKeyguardWidgetsDisabled(android.content.ComponentName);
    method public int getKeyguardDisabledFeatures(android.content.ComponentName);
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public long getPasswordExpiration(android.content.ComponentName);
@@ -4267,7 +4267,7 @@ package android.app.admin {
    method public void removeActiveAdmin(android.content.ComponentName);
    method public boolean resetPassword(java.lang.String, int);
    method public void setCameraDisabled(android.content.ComponentName, boolean);
    method public void setKeyguardWidgetsDisabled(android.content.ComponentName, int);
    method public void setKeyguardDisabledFeatures(android.content.ComponentName, int);
    method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
    method public void setMaximumTimeToLock(android.content.ComponentName, long);
    method public void setPasswordExpirationTimeout(android.content.ComponentName, long);
@@ -4291,8 +4291,10 @@ package android.app.admin {
    field public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0; // 0x0
    field public static final java.lang.String EXTRA_ADD_EXPLANATION = "android.app.extra.ADD_EXPLANATION";
    field public static final java.lang.String EXTRA_DEVICE_ADMIN = "android.app.extra.DEVICE_ADMIN";
    field public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 2147483647; // 0x7fffffff
    field public static final int KEYGUARD_DISABLE_WIDGETS_NONE = 0; // 0x0
    field public static final int KEYGUARD_DISABLE_FEATURES_ALL = 2147483647; // 0x7fffffff
    field public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0; // 0x0
    field public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 2; // 0x2
    field public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1; // 0x1
    field public static final int PASSWORD_QUALITY_ALPHABETIC = 262144; // 0x40000
    field public static final int PASSWORD_QUALITY_ALPHANUMERIC = 327680; // 0x50000
    field public static final int PASSWORD_QUALITY_BIOMETRIC_WEAK = 32768; // 0x8000
+4 −4
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ public final class DeviceAdminInfo implements Parcelable {
     * <p>To control this policy, the device admin must have a "disable-keyguard-widgets"
     * tag in the "uses-policies" section of its meta-data.
     */
    public static final int USES_POLICY_DISABLE_KEYGUARD_WIDGETS = 9;
    public static final int USES_POLICY_DISABLE_KEYGUARD_FEATURES = 9;

    /** @hide */
    public static class PolicyInfo {
@@ -194,9 +194,9 @@ public final class DeviceAdminInfo implements Parcelable {
                com.android.internal.R.string.policylab_disableCamera,
                com.android.internal.R.string.policydesc_disableCamera));
        sPoliciesDisplayOrder.add(new PolicyInfo(
                USES_POLICY_DISABLE_KEYGUARD_WIDGETS, "disable-keyguard-widgets",
                com.android.internal.R.string.policylab_disableKeyguardWidgets,
                com.android.internal.R.string.policydesc_disableKeyguardWidgets));
                USES_POLICY_DISABLE_KEYGUARD_FEATURES, "disable-keyguard-features",
                com.android.internal.R.string.policylab_disableKeyguardFeatures,
                com.android.internal.R.string.policydesc_disableKeyguardFeatures));

        for (int i=0; i<sPoliciesDisplayOrder.size(); i++) {
            PolicyInfo pi = sPoliciesDisplayOrder.get(i);
+26 −16
Original line number Diff line number Diff line
@@ -1215,12 +1215,22 @@ public class DevicePolicyManager {
    /**
     * Widgets are enabled in keyguard
     */
    public static final int KEYGUARD_DISABLE_WIDGETS_NONE = 0;
    public static final int KEYGUARD_DISABLE_FEATURES_NONE = 0;

    /**
     * Disable all keyguard widgets
     */
    public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 0x7fffffff;
    public static final int KEYGUARD_DISABLE_WIDGETS_ALL = 1 << 0;

    /**
     * Disable the camera on secure keyguard screens (e.g. PIN/Pattern/Password)
     */
    public static final int KEYGUARD_DISABLE_SECURE_CAMERA = 1 << 1;

    /**
     * Disable all current and future keyguard customizations
     */
    public static final int KEYGUARD_DISABLE_FEATURES_ALL = 0x7fffffff;

    /**
     * Called by an application that is administering the device to
@@ -1362,22 +1372,22 @@ public class DevicePolicyManager {
    }

    /**
     * Called by an application that is administering the device to disable adding widgets to
     * keyguard.  After setting this, keyguard widgets will be disabled according to the state
     * provided.
     * Called by an application that is administering the device to disable keyguard customizations,
     * such as widgets. After setting this, keyguard features will be disabled according to the
     * provided feature list.
     *
     * <p>The calling device admin must have requested
     * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_WIDGETS} to be able to call
     * {@link DeviceAdminInfo#USES_POLICY_DISABLE_KEYGUARD_FEATURES} to be able to call
     * this method; if it has not, a security exception will be thrown.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param which {@link DevicePolicyManager#KEYGUARD_DISABLE_WIDGETS_ALL} or
     * {@link DevicePolicyManager#KEYGUARD_DISABLE_WIDGETS_NONE} (the default).
     * {@link DevicePolicyManager#KEYGUARD_DISABLE_FEATURES_NONE} (the default).
     */
    public void setKeyguardWidgetsDisabled(ComponentName admin, int which) {
    public void setKeyguardDisabledFeatures(ComponentName admin, int which) {
        if (mService != null) {
            try {
                mService.setKeyguardWidgetsDisabled(admin, which, UserHandle.myUserId());
                mService.setKeyguardDisabledFeatures(admin, which, UserHandle.myUserId());
            } catch (RemoteException e) {
                Log.w(TAG, "Failed talking with device policy service", e);
            }
@@ -1385,25 +1395,25 @@ public class DevicePolicyManager {
    }

    /**
     * Determine whether or not widgets have been disabled in keyguard either by the current
     * Determine whether or not features have been disabled in keyguard either by the current
     * admin, if specified, or all admins.
     * @param admin The name of the admin component to check, or null to check if any admins
     * have disabled widgets in keyguard.
     * have disabled features in keyguard.
     */
    public int getKeyguardWidgetsDisabled(ComponentName admin) {
        return getKeyguardWidgetsDisabled(admin, UserHandle.myUserId());
    public int getKeyguardDisabledFeatures(ComponentName admin) {
        return getKeyguardDisabledFeatures(admin, UserHandle.myUserId());
    }

    /** @hide per-user version */
    public int getKeyguardWidgetsDisabled(ComponentName admin, int userHandle) {
    public int getKeyguardDisabledFeatures(ComponentName admin, int userHandle) {
        if (mService != null) {
            try {
                return mService.getKeyguardWidgetsDisabled(admin, userHandle);
                return mService.getKeyguardDisabledFeatures(admin, userHandle);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed talking with device policy service", e);
            }
        }
        return KEYGUARD_DISABLE_WIDGETS_NONE;
        return KEYGUARD_DISABLE_FEATURES_NONE;
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -82,8 +82,8 @@ interface IDevicePolicyManager {
    void setCameraDisabled(in ComponentName who, boolean disabled, int userHandle);
    boolean getCameraDisabled(in ComponentName who, int userHandle);

    void setKeyguardWidgetsDisabled(in ComponentName who, int which, int userHandle);
    int getKeyguardWidgetsDisabled(in ComponentName who, int userHandle);
    void setKeyguardDisabledFeatures(in ComponentName who, int which, int userHandle);
    int getKeyguardDisabledFeatures(in ComponentName who, int userHandle);

    void setActiveAdmin(in ComponentName policyReceiver, boolean refreshing, int userHandle);
    boolean isAdminActive(in ComponentName policyReceiver, int userHandle);
+3 −3
Original line number Diff line number Diff line
@@ -1810,9 +1810,9 @@
    <!-- Description of policy access to disable all device cameras [CHAR LIMIT=110]-->
    <string name="policydesc_disableCamera">Prevent use of all device cameras.</string>
    <!-- Title of policy access to disable all device cameras [CHAR LIMIT=30]-->
    <string name="policylab_disableKeyguardWidgets">Disable widgets on keyguard</string>
    <string name="policylab_disableKeyguardFeatures">Disable features in keyguard</string>
    <!-- Description of policy access to disable all device cameras [CHAR LIMIT=110]-->
    <string name="policydesc_disableKeyguardWidgets">Prevent use of some or all widgets on keyguard.</string>
    <string name="policydesc_disableKeyguardFeatures">Prevent use of some features in keyguard.</string>

    <!-- The order of these is important, don't reorder without changing Contacts.java --> <skip />
    <!-- Phone number types from android.provider.Contacts. This could be used when adding a new phone number for a contact, for example. -->
Loading