Loading core/java/com/android/internal/widget/ILockSettingsObserver.aidl +9 −0 Original line number Diff line number Diff line Loading @@ -18,5 +18,14 @@ package com.android.internal.widget; /** {@hide} */ 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); } core/java/com/android/internal/widget/LockPatternUtils.java +14 −2 Original line number Diff line number Diff line Loading @@ -64,6 +64,13 @@ public class LockPatternUtils { private static final String TAG = "LockPatternUtils"; 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 * from trying again for {@link #FAILED_ATTEMPT_TIMEOUT_MS}. Loading Loading @@ -207,8 +214,13 @@ public class LockPatternUtils { private ILockSettings getLockSettings() { if (mLockSettingsService == null) { mLockSettingsService = LockPatternUtilsCache.getInstance( ILockSettings.Stub.asInterface(ServiceManager.getService("lock_settings"))); ILockSettings service = ILockSettings.Stub.asInterface( ServiceManager.getService("lock_settings")); if (ENABLE_CLIENT_CACHE) { mLockSettingsService = LockPatternUtilsCache.getInstance(service); } else { mLockSettingsService = service; } } return mLockSettingsService; } Loading core/java/com/android/internal/widget/LockPatternUtilsCache.java +24 −5 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ package com.android.internal.widget; import android.os.IBinder; import android.os.RemoteException; import android.os.UserHandle; import android.util.ArrayMap; import android.util.Log; /** * A decorator for {@link ILockSettings} that caches the key-value responses in memory. Loading @@ -28,9 +30,11 @@ import android.util.ArrayMap; */ 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"; private static final String HAS_LOCK_PASSWORD_CACHE_KEY public static final String HAS_LOCK_PASSWORD_CACHE_KEY = "LockPatternUtils.Cache.HasLockPasswordCacheKey"; private static LockPatternUtilsCache sInstance; Loading @@ -53,7 +57,7 @@ public class LockPatternUtilsCache implements ILockSettings { // ILockSettings private LockPatternUtilsCache(ILockSettings service) { public LockPatternUtilsCache(ILockSettings service) { mService = service; try { service.registerObserver(mObserver); Loading Loading @@ -186,6 +190,7 @@ public class LockPatternUtilsCache implements ILockSettings { // Caching private Object peekCache(String key, int userId) { if (!validateUserId(userId)) return null; synchronized (mCache) { // Safe to reuse mCacheKey, because it is not stored in the map. return mCache.get(mCacheKey.set(key, userId)); Loading @@ -193,6 +198,7 @@ public class LockPatternUtilsCache implements ILockSettings { } private void putCache(String key, int userId, Object value) { if (!validateUserId(userId)) return; synchronized (mCache) { // Create a new key, because this will be stored in the map. mCache.put(new CacheKey().set(key, userId), value); Loading @@ -200,9 +206,14 @@ public class LockPatternUtilsCache implements ILockSettings { } private void invalidateCache(String key, int userId) { if (!validateUserId(userId)) return; synchronized (mCache) { if (key != null) { // Safe to reuse mCacheKey, because it is not stored in the map. mCache.remove(mCacheKey.set(key, userId)); } else { mCache.clear(); } } } Loading @@ -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 { String key; int userId; Loading services/core/java/com/android/server/LockSettingsService.java +3 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import android.util.Slog; import com.android.internal.widget.ILockSettings; import com.android.internal.widget.ILockSettingsObserver; import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtilsCache; import java.util.ArrayList; import java.util.Arrays; Loading Loading @@ -348,6 +349,7 @@ public class LockSettingsService extends ILockSettings.Stub { final byte[] hash = LockPatternUtils.patternToHash( LockPatternUtils.stringToPattern(pattern)); mStorage.writePatternHash(hash, userId); notifyObservers(LockPatternUtilsCache.HAS_LOCK_PATTERN_CACHE_KEY, userId); } @Override Loading @@ -357,6 +359,7 @@ public class LockSettingsService extends ILockSettings.Stub { maybeUpdateKeystore(password, userId); mStorage.writePasswordHash(mLockPatternUtils.passwordToHash(password, userId), userId); notifyObservers(LockPatternUtilsCache.HAS_LOCK_PASSWORD_CACHE_KEY, userId); } @Override Loading Loading
core/java/com/android/internal/widget/ILockSettingsObserver.aidl +9 −0 Original line number Diff line number Diff line Loading @@ -18,5 +18,14 @@ package com.android.internal.widget; /** {@hide} */ 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); }
core/java/com/android/internal/widget/LockPatternUtils.java +14 −2 Original line number Diff line number Diff line Loading @@ -64,6 +64,13 @@ public class LockPatternUtils { private static final String TAG = "LockPatternUtils"; 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 * from trying again for {@link #FAILED_ATTEMPT_TIMEOUT_MS}. Loading Loading @@ -207,8 +214,13 @@ public class LockPatternUtils { private ILockSettings getLockSettings() { if (mLockSettingsService == null) { mLockSettingsService = LockPatternUtilsCache.getInstance( ILockSettings.Stub.asInterface(ServiceManager.getService("lock_settings"))); ILockSettings service = ILockSettings.Stub.asInterface( ServiceManager.getService("lock_settings")); if (ENABLE_CLIENT_CACHE) { mLockSettingsService = LockPatternUtilsCache.getInstance(service); } else { mLockSettingsService = service; } } return mLockSettingsService; } Loading
core/java/com/android/internal/widget/LockPatternUtilsCache.java +24 −5 Original line number Diff line number Diff line Loading @@ -18,7 +18,9 @@ package com.android.internal.widget; import android.os.IBinder; import android.os.RemoteException; import android.os.UserHandle; import android.util.ArrayMap; import android.util.Log; /** * A decorator for {@link ILockSettings} that caches the key-value responses in memory. Loading @@ -28,9 +30,11 @@ import android.util.ArrayMap; */ 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"; private static final String HAS_LOCK_PASSWORD_CACHE_KEY public static final String HAS_LOCK_PASSWORD_CACHE_KEY = "LockPatternUtils.Cache.HasLockPasswordCacheKey"; private static LockPatternUtilsCache sInstance; Loading @@ -53,7 +57,7 @@ public class LockPatternUtilsCache implements ILockSettings { // ILockSettings private LockPatternUtilsCache(ILockSettings service) { public LockPatternUtilsCache(ILockSettings service) { mService = service; try { service.registerObserver(mObserver); Loading Loading @@ -186,6 +190,7 @@ public class LockPatternUtilsCache implements ILockSettings { // Caching private Object peekCache(String key, int userId) { if (!validateUserId(userId)) return null; synchronized (mCache) { // Safe to reuse mCacheKey, because it is not stored in the map. return mCache.get(mCacheKey.set(key, userId)); Loading @@ -193,6 +198,7 @@ public class LockPatternUtilsCache implements ILockSettings { } private void putCache(String key, int userId, Object value) { if (!validateUserId(userId)) return; synchronized (mCache) { // Create a new key, because this will be stored in the map. mCache.put(new CacheKey().set(key, userId), value); Loading @@ -200,9 +206,14 @@ public class LockPatternUtilsCache implements ILockSettings { } private void invalidateCache(String key, int userId) { if (!validateUserId(userId)) return; synchronized (mCache) { if (key != null) { // Safe to reuse mCacheKey, because it is not stored in the map. mCache.remove(mCacheKey.set(key, userId)); } else { mCache.clear(); } } } Loading @@ -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 { String key; int userId; Loading
services/core/java/com/android/server/LockSettingsService.java +3 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import android.util.Slog; import com.android.internal.widget.ILockSettings; import com.android.internal.widget.ILockSettingsObserver; import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtilsCache; import java.util.ArrayList; import java.util.Arrays; Loading Loading @@ -348,6 +349,7 @@ public class LockSettingsService extends ILockSettings.Stub { final byte[] hash = LockPatternUtils.patternToHash( LockPatternUtils.stringToPattern(pattern)); mStorage.writePatternHash(hash, userId); notifyObservers(LockPatternUtilsCache.HAS_LOCK_PATTERN_CACHE_KEY, userId); } @Override Loading @@ -357,6 +359,7 @@ public class LockSettingsService extends ILockSettings.Stub { maybeUpdateKeystore(password, userId); mStorage.writePasswordHash(mLockPatternUtils.passwordToHash(password, userId), userId); notifyObservers(LockPatternUtilsCache.HAS_LOCK_PASSWORD_CACHE_KEY, userId); } @Override Loading