diff options
author | Adrian Roos <roosa@google.com> | 2014-05-22 20:45:59 +0200 |
---|---|---|
committer | Adrian Roos <roosa@google.com> | 2014-05-23 14:38:33 +0200 |
commit | 4f7884542ce8fba5bfed01ed834a32e6d3e2dea5 (patch) | |
tree | d367df561f85cdf89e30ba0dc681713225dd1d63 /services | |
parent | 42b30e1b832df5bbf109db2f4f864f8ba4cfd44a (diff) | |
download | frameworks_base-4f7884542ce8fba5bfed01ed834a32e6d3e2dea5.zip frameworks_base-4f7884542ce8fba5bfed01ed834a32e6d3e2dea5.tar.gz frameworks_base-4f7884542ce8fba5bfed01ed834a32e6d3e2dea5.tar.bz2 |
Add a cache to LockPatternUtils
Caches responses from LockSettingsService in the client process.
Bug: 15088101
Change-Id: If77c5ec45f52a02c800d50cb8550bfcb180f301d
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/LockSettingsService.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/LockSettingsService.java b/services/core/java/com/android/server/LockSettingsService.java index 0d2cee8..5cfc49c 100644 --- a/services/core/java/com/android/server/LockSettingsService.java +++ b/services/core/java/com/android/server/LockSettingsService.java @@ -47,12 +47,14 @@ import android.util.Log; import android.util.Slog; import com.android.internal.widget.ILockSettings; +import com.android.internal.widget.ILockSettingsObserver; import com.android.internal.widget.LockPatternUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -65,6 +67,9 @@ import java.util.List; public class LockSettingsService extends ILockSettings.Stub { private static final String PERMISSION = "android.permission.ACCESS_KEYGUARD_SECURE_STORAGE"; + + private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; + private final DatabaseHelper mOpenHelper; private static final String TAG = "LockSettingsService"; @@ -85,6 +90,8 @@ public class LockSettingsService extends ILockSettings.Stub { private LockPatternUtils mLockPatternUtils; private boolean mFirstCallToVold; + private final ArrayList<LockSettingsObserver> mObservers = new ArrayList<>(); + public LockSettingsService(Context context) { mContext = context; // Open the database @@ -222,6 +229,52 @@ public class LockSettingsService extends ILockSettings.Stub { return readFromDb(key, defaultValue, userId); } + @Override + public void registerObserver(ILockSettingsObserver remote) throws RemoteException { + synchronized (mObservers) { + for (int i = 0; i < mObservers.size(); i++) { + if (mObservers.get(i).remote.asBinder() == remote.asBinder()) { + boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); + if (isDebuggable) { + throw new IllegalStateException("Observer was already registered."); + } else { + Log.e(TAG, "Observer was already registered."); + return; + } + } + } + LockSettingsObserver o = new LockSettingsObserver(); + o.remote = remote; + o.remote.asBinder().linkToDeath(o, 0); + mObservers.add(o); + } + } + + @Override + public void unregisterObserver(ILockSettingsObserver remote) throws RemoteException { + synchronized (mObservers) { + for (int i = 0; i < mObservers.size(); i++) { + if (mObservers.get(i).remote.asBinder() == remote.asBinder()) { + mObservers.remove(i); + return; + } + } + } + } + + public void notifyObservers(String key, int userId) { + synchronized (mObservers) { + for (int i = 0; i < mObservers.size(); i++) { + try { + mObservers.get(i).remote.onLockSettingChanged(key, userId); + } catch (RemoteException e) { + // The stack trace is not really helpful here. + Log.e(TAG, "Failed to notify ILockSettingsObserver: " + e); + } + } + } + } + private String getLockPatternFilename(int userId) { String dataSystemDirectory = android.os.Environment.getDataDirectory().getAbsolutePath() + @@ -438,6 +491,7 @@ public class LockSettingsService extends ILockSettings.Stub { private void writeToDb(String key, String value, int userId) { writeToDb(mOpenHelper.getWritableDatabase(), key, value, userId); + notifyObservers(key, userId); } private void writeToDb(SQLiteDatabase db, String key, String value, int userId) { @@ -583,4 +637,13 @@ public class LockSettingsService extends ILockSettings.Stub { } return null; } + + private class LockSettingsObserver implements DeathRecipient { + ILockSettingsObserver remote; + + @Override + public void binderDied() { + mObservers.remove(this); + } + } } |