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

Commit 2ca759db authored by Jim Miller's avatar Jim Miller Committed by Android (Google) Code Review
Browse files

Merge "Fix 2463886: Allow delayed fetching of DevicePolicyManager in LockPatternUtils."

parents d7d22eba 5b0fb3a7
Loading
Loading
Loading
Loading
+24 −14
Original line number Original line Diff line number Diff line
@@ -104,14 +104,24 @@ public class LockPatternUtils {
    private static String sLockPatternFilename;
    private static String sLockPatternFilename;
    private static String sLockPasswordFilename;
    private static String sLockPasswordFilename;


    DevicePolicyManager getDevicePolicyManager() {
        if (mDevicePolicyManager == null) {
            mDevicePolicyManager =
                (DevicePolicyManager)mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
            if (mDevicePolicyManager == null) {
                Log.e(TAG, "Can't get DevicePolicyManagerService: is it running?",
                        new IllegalStateException("Stack trace:"));
            }
        }
        return mDevicePolicyManager;
    }
    /**
    /**
     * @param contentResolver Used to look up and save settings.
     * @param contentResolver Used to look up and save settings.
     */
     */
    public LockPatternUtils(Context context) {
    public LockPatternUtils(Context context) {
        mContext = context;
        mContext = context;
        mContentResolver = context.getContentResolver();
        mContentResolver = context.getContentResolver();
        mDevicePolicyManager =
        mDevicePolicyManager = getDevicePolicyManager();
                (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        // Initialize the location of gesture lock file
        // Initialize the location of gesture lock file
        if (sLockPatternFilename == null) {
        if (sLockPatternFilename == null) {
            sLockPatternFilename = android.os.Environment.getDataDirectory()
            sLockPatternFilename = android.os.Environment.getDataDirectory()
@@ -123,7 +133,7 @@ public class LockPatternUtils {
    }
    }


    public int getRequestedMinimumPasswordLength() {
    public int getRequestedMinimumPasswordLength() {
        return mDevicePolicyManager.getPasswordMinimumLength(null);
        return getDevicePolicyManager().getPasswordMinimumLength(null);
    }
    }


    /**
    /**
@@ -133,7 +143,7 @@ public class LockPatternUtils {
     * @return
     * @return
     */
     */
    public int getRequestedPasswordMode() {
    public int getRequestedPasswordMode() {
        int policyMode = mDevicePolicyManager.getPasswordQuality(null);
        int policyMode = getDevicePolicyManager().getPasswordQuality(null);
        switch (policyMode) {
        switch (policyMode) {
            case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
            case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
                return MODE_PASSWORD;
                return MODE_PASSWORD;
@@ -151,11 +161,11 @@ public class LockPatternUtils {
     * @return
     * @return
     */
     */
    public void reportFailedPasswordAttempt() {
    public void reportFailedPasswordAttempt() {
        mDevicePolicyManager.reportFailedPasswordAttempt();
        getDevicePolicyManager().reportFailedPasswordAttempt();
    }
    }


    public void reportSuccessfulPasswordAttempt() {
    public void reportSuccessfulPasswordAttempt() {
        mDevicePolicyManager.reportSuccessfulPasswordAttempt();
        getDevicePolicyManager().reportSuccessfulPasswordAttempt();
    }
    }


    public void setActivePasswordState(int mode, int length) {
    public void setActivePasswordState(int mode, int length) {
@@ -171,7 +181,7 @@ public class LockPatternUtils {
                policyMode = DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
                policyMode = DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
                break;
                break;
        }
        }
        mDevicePolicyManager.setActivePasswordState(policyMode, length);
        getDevicePolicyManager().setActivePasswordState(policyMode, length);
    }
    }


    /**
    /**