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

Commit 888da80d authored by Clara Bayarri's avatar Clara Bayarri Committed by Android (Google) Code Review
Browse files

Merge "Create parent APIs in DevicePolicyManager"

parents 9d9294cc 3e826eff
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5762,6 +5762,7 @@ package android.app.admin {
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public boolean getPackageSuspended(android.content.ComponentName, java.lang.String);
    method public android.app.admin.DevicePolicyManager getParentProfileInstance(android.content.ComponentName);
    method public long getPasswordExpiration(android.content.ComponentName);
    method public long getPasswordExpirationTimeout(android.content.ComponentName);
    method public int getPasswordHistoryLength(android.content.ComponentName);
+1 −0
Original line number Diff line number Diff line
@@ -5890,6 +5890,7 @@ package android.app.admin {
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public boolean getPackageSuspended(android.content.ComponentName, java.lang.String);
    method public android.app.admin.DevicePolicyManager getParentProfileInstance(android.content.ComponentName);
    method public long getPasswordExpiration(android.content.ComponentName);
    method public long getPasswordExpirationTimeout(android.content.ComponentName);
    method public int getPasswordHistoryLength(android.content.ComponentName);
+1 −0
Original line number Diff line number Diff line
@@ -5764,6 +5764,7 @@ package android.app.admin {
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public boolean getPackageSuspended(android.content.ComponentName, java.lang.String);
    method public android.app.admin.DevicePolicyManager getParentProfileInstance(android.content.ComponentName);
    method public long getPasswordExpiration(android.content.ComponentName);
    method public long getPasswordExpirationTimeout(android.content.ComponentName);
    method public int getPasswordHistoryLength(android.content.ComponentName);
+29 −5
Original line number Diff line number Diff line
@@ -88,13 +88,15 @@ public class DevicePolicyManager {

    private final Context mContext;
    private final IDevicePolicyManager mService;
    private boolean mParentInstance;

    private static final String REMOTE_EXCEPTION_MESSAGE =
            "Failed to talk with device policy manager service";

    private DevicePolicyManager(Context context) {
    private DevicePolicyManager(Context context, boolean parentInstance) {
        this(context, IDevicePolicyManager.Stub.asInterface(
                        ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)));
        mParentInstance = parentInstance;
    }

    /** @hide */
@@ -106,7 +108,7 @@ public class DevicePolicyManager {

    /** @hide */
    public static DevicePolicyManager create(Context context) {
        DevicePolicyManager me = new DevicePolicyManager(context);
        DevicePolicyManager me = new DevicePolicyManager(context, false);
        return me.mService != null ? me : null;
    }

@@ -1031,7 +1033,7 @@ public class DevicePolicyManager {
    public void setPasswordQuality(@NonNull ComponentName admin, int quality) {
        if (mService != null) {
            try {
                mService.setPasswordQuality(admin, quality);
                mService.setPasswordQuality(admin, quality, mParentInstance);
            } catch (RemoteException e) {
                Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
            }
@@ -1052,7 +1054,7 @@ public class DevicePolicyManager {
    public int getPasswordQuality(@Nullable ComponentName admin, int userHandle) {
        if (mService != null) {
            try {
                return mService.getPasswordQuality(admin, userHandle);
                return mService.getPasswordQuality(admin, userHandle, mParentInstance);
            } catch (RemoteException e) {
                Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
            }
@@ -1622,7 +1624,7 @@ public class DevicePolicyManager {
    public boolean isActivePasswordSufficient() {
        if (mService != null) {
            try {
                return mService.isActivePasswordSufficient(myUserId());
                return mService.isActivePasswordSufficient(myUserId(), mParentInstance);
            } catch (RemoteException e) {
                Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
            }
@@ -1791,6 +1793,9 @@ public class DevicePolicyManager {
     * not acceptable for the current constraints or if the user has not been decrypted yet.
     */
    public boolean resetPassword(String password, int flags) {
        if (mParentInstance) {
            throw new SecurityException("Reset password does not work across profiles.");
        }
        if (mService != null) {
            try {
                return mService.resetPassword(password, flags);
@@ -4927,4 +4932,23 @@ public class DevicePolicyManager {
        }
        return null;
    }

    /**
     * Obtains a {@link DevicePolicyManager} whose calls act on the parent profile.
     *
     * <p> Note only some methods will work on the parent Manager.
     *
     * @return a new instance of {@link DevicePolicyManager} that acts on the parent profile.
     */
    public DevicePolicyManager getParentProfileInstance(@NonNull ComponentName admin) {
        try {
            if (!mService.isManagedProfile(admin)) {
                throw new SecurityException("The current user does not have a parent profile.");
            }
            return new DevicePolicyManager(mContext, true);
        } catch (RemoteException re) {
            Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
            return null;
        }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -35,8 +35,8 @@ import java.util.List;
 * {@hide}
 */
interface IDevicePolicyManager {
    void setPasswordQuality(in ComponentName who, int quality);
    int getPasswordQuality(in ComponentName who, int userHandle);
    void setPasswordQuality(in ComponentName who, int quality, boolean parent);
    int getPasswordQuality(in ComponentName who, int userHandle, boolean parent);

    void setPasswordMinimumLength(in ComponentName who, int length);
    int getPasswordMinimumLength(in ComponentName who, int userHandle);
@@ -67,7 +67,7 @@ interface IDevicePolicyManager {

    long getPasswordExpiration(in ComponentName who, int userHandle);

    boolean isActivePasswordSufficient(int userHandle);
    boolean isActivePasswordSufficient(int userHandle, boolean parent);
    int getCurrentFailedPasswordAttempts(int userHandle);
    int getProfileWithMinimumFailedPasswordsForWipe(int userHandle);

Loading