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

Commit 8953c119 authored by Adrian Roos's avatar Adrian Roos Committed by Android Git Automerger
Browse files

am 4dfc666c: Merge "Disable LockPatternUtilsCache" into lmp-mr1-dev automerge: a0ecc714

* commit '4dfc666c':
  Disable LockPatternUtilsCache
parents 050ea856 4dfc666c
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -18,5 +18,14 @@ package com.android.internal.widget;


/** {@hide} */
/** {@hide} */
oneway interface ILockSettingsObserver {
oneway interface ILockSettingsObserver {
    /**
     * Called when a lock setting has changed.
     *
     * Note: Impementations of this should do as little work as possible, because this may be
     * called synchronously while writing a setting.
     *
     * @param key the key of the setting that has changed or {@code null} if any may have changed.
     * @param userId the user whose setting has changed.
     */
    void onLockSettingChanged(in String key, in int userId);
    void onLockSettingChanged(in String key, in int userId);
}
}
+14 −2
Original line number Original line Diff line number Diff line
@@ -64,6 +64,13 @@ public class LockPatternUtils {
    private static final String TAG = "LockPatternUtils";
    private static final String TAG = "LockPatternUtils";
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;


    /**
     * If true, LockPatternUtils will cache its values in-process. While this leads to faster reads,
     * it can cause problems because writes to to the settings are no longer synchronous
     * across all processes.
     */
    private static final boolean ENABLE_CLIENT_CACHE = false;

    /**
    /**
     * The maximum number of incorrect attempts before the user is prevented
     * The maximum number of incorrect attempts before the user is prevented
     * from trying again for {@link #FAILED_ATTEMPT_TIMEOUT_MS}.
     * from trying again for {@link #FAILED_ATTEMPT_TIMEOUT_MS}.
@@ -207,8 +214,13 @@ public class LockPatternUtils {


    private ILockSettings getLockSettings() {
    private ILockSettings getLockSettings() {
        if (mLockSettingsService == null) {
        if (mLockSettingsService == null) {
            mLockSettingsService = LockPatternUtilsCache.getInstance(
            ILockSettings service = ILockSettings.Stub.asInterface(
                    ILockSettings.Stub.asInterface(ServiceManager.getService("lock_settings")));
                    ServiceManager.getService("lock_settings"));
            if (ENABLE_CLIENT_CACHE) {
                mLockSettingsService = LockPatternUtilsCache.getInstance(service);
            } else {
                mLockSettingsService = service;
            }
        }
        }
        return mLockSettingsService;
        return mLockSettingsService;
    }
    }
+24 −5
Original line number Original line Diff line number Diff line
@@ -18,7 +18,9 @@ package com.android.internal.widget;


import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;


/**
/**
 * A decorator for {@link ILockSettings} that caches the key-value responses in memory.
 * A decorator for {@link ILockSettings} that caches the key-value responses in memory.
@@ -28,9 +30,11 @@ import android.util.ArrayMap;
 */
 */
public class LockPatternUtilsCache implements ILockSettings {
public class LockPatternUtilsCache implements ILockSettings {


    private static final String HAS_LOCK_PATTERN_CACHE_KEY
    private static final String TAG = "LockPatternUtilsCache";

    public static final String HAS_LOCK_PATTERN_CACHE_KEY
            = "LockPatternUtils.Cache.HasLockPatternCacheKey";
            = "LockPatternUtils.Cache.HasLockPatternCacheKey";
    private static final String HAS_LOCK_PASSWORD_CACHE_KEY
    public static final String HAS_LOCK_PASSWORD_CACHE_KEY
            = "LockPatternUtils.Cache.HasLockPasswordCacheKey";
            = "LockPatternUtils.Cache.HasLockPasswordCacheKey";


    private static LockPatternUtilsCache sInstance;
    private static LockPatternUtilsCache sInstance;
@@ -53,7 +57,7 @@ public class LockPatternUtilsCache implements ILockSettings {


    // ILockSettings
    // ILockSettings


    private LockPatternUtilsCache(ILockSettings service) {
    public LockPatternUtilsCache(ILockSettings service) {
        mService = service;
        mService = service;
        try {
        try {
            service.registerObserver(mObserver);
            service.registerObserver(mObserver);
@@ -186,6 +190,7 @@ public class LockPatternUtilsCache implements ILockSettings {
    // Caching
    // Caching


    private Object peekCache(String key, int userId) {
    private Object peekCache(String key, int userId) {
        if (!validateUserId(userId)) return null;
        synchronized (mCache) {
        synchronized (mCache) {
            // Safe to reuse mCacheKey, because it is not stored in the map.
            // Safe to reuse mCacheKey, because it is not stored in the map.
            return mCache.get(mCacheKey.set(key, userId));
            return mCache.get(mCacheKey.set(key, userId));
@@ -193,6 +198,7 @@ public class LockPatternUtilsCache implements ILockSettings {
    }
    }


    private void putCache(String key, int userId, Object value) {
    private void putCache(String key, int userId, Object value) {
        if (!validateUserId(userId)) return;
        synchronized (mCache) {
        synchronized (mCache) {
            // Create a new key, because this will be stored in the map.
            // Create a new key, because this will be stored in the map.
            mCache.put(new CacheKey().set(key, userId), value);
            mCache.put(new CacheKey().set(key, userId), value);
@@ -200,9 +206,14 @@ public class LockPatternUtilsCache implements ILockSettings {
    }
    }


    private void invalidateCache(String key, int userId) {
    private void invalidateCache(String key, int userId) {
        if (!validateUserId(userId)) return;
        synchronized (mCache) {
        synchronized (mCache) {
            if (key != null) {
                // Safe to reuse mCacheKey, because it is not stored in the map.
                // Safe to reuse mCacheKey, because it is not stored in the map.
                mCache.remove(mCacheKey.set(key, userId));
                mCache.remove(mCacheKey.set(key, userId));
            } else {
                mCache.clear();
            }
        }
        }
    }
    }


@@ -213,6 +224,14 @@ public class LockPatternUtilsCache implements ILockSettings {
        }
        }
    };
    };


    private final boolean validateUserId(int userId) {
        if (userId < UserHandle.USER_OWNER) {
            Log.e(TAG, "User " + userId + " not supported: Must be a concrete user.");
            return false;
        }
        return true;
    }

    private static final class CacheKey {
    private static final class CacheKey {
        String key;
        String key;
        int userId;
        int userId;
+3 −0
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@ import android.util.Slog;
import com.android.internal.widget.ILockSettings;
import com.android.internal.widget.ILockSettings;
import com.android.internal.widget.ILockSettingsObserver;
import com.android.internal.widget.ILockSettingsObserver;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockPatternUtilsCache;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
@@ -348,6 +349,7 @@ public class LockSettingsService extends ILockSettings.Stub {
        final byte[] hash = LockPatternUtils.patternToHash(
        final byte[] hash = LockPatternUtils.patternToHash(
                LockPatternUtils.stringToPattern(pattern));
                LockPatternUtils.stringToPattern(pattern));
        mStorage.writePatternHash(hash, userId);
        mStorage.writePatternHash(hash, userId);
        notifyObservers(LockPatternUtilsCache.HAS_LOCK_PATTERN_CACHE_KEY, userId);
    }
    }


    @Override
    @Override
@@ -357,6 +359,7 @@ public class LockSettingsService extends ILockSettings.Stub {
        maybeUpdateKeystore(password, userId);
        maybeUpdateKeystore(password, userId);


        mStorage.writePasswordHash(mLockPatternUtils.passwordToHash(password, userId), userId);
        mStorage.writePasswordHash(mLockPatternUtils.passwordToHash(password, userId), userId);
        notifyObservers(LockPatternUtilsCache.HAS_LOCK_PASSWORD_CACHE_KEY, userId);
    }
    }


    @Override
    @Override