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

Commit 5b0fb3a7 authored by Jim Miller's avatar Jim Miller
Browse files

Fix 2463886: Allow delayed fetching of DevicePolicyManager in LockPatternUtils.

Today we're seeing a crash that's likely caused by a change in the order in which
system services start.

The crash we're seeing happens in response to user interaction which happens after the
boot process completes, so we should re-fetch the DevicePolicyManager if we weren't
able to get it when LockPatternUtils was constructed.
parent c0e147d4
Loading
Loading
Loading
Loading
+24 −14
Original line number Diff line number Diff line
@@ -104,14 +104,24 @@ public class LockPatternUtils {
    private static String sLockPatternFilename;
    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.
     */
    public LockPatternUtils(Context context) {
        mContext = context;
        mContentResolver = context.getContentResolver();
        mDevicePolicyManager =
                (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        mDevicePolicyManager = getDevicePolicyManager();
        // Initialize the location of gesture lock file
        if (sLockPatternFilename == null) {
            sLockPatternFilename = android.os.Environment.getDataDirectory()
@@ -123,7 +133,7 @@ public class LockPatternUtils {
    }

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

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

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

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

    /**