summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorAdrian Roos <roosa@google.com>2014-05-23 12:58:19 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-23 12:58:19 +0000
commit98157e8dbb29bef0d10899d88e87a5c1f8dcd3dc (patch)
tree0c941f64eb5f00c2640301e34c24eee92368e3a0 /services
parent8a4729d87181df6eb739c473554e5a89c65b180d (diff)
parent4f7884542ce8fba5bfed01ed834a32e6d3e2dea5 (diff)
downloadframeworks_base-98157e8dbb29bef0d10899d88e87a5c1f8dcd3dc.zip
frameworks_base-98157e8dbb29bef0d10899d88e87a5c1f8dcd3dc.tar.gz
frameworks_base-98157e8dbb29bef0d10899d88e87a5c1f8dcd3dc.tar.bz2
Merge "Add a cache to LockPatternUtils" into lmp-preview-dev
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/LockSettingsService.java63
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);
+ }
+ }
}