summaryrefslogtreecommitdiffstats
path: root/keystore
diff options
context:
space:
mode:
authorChad Brubaker <cbrubaker@google.com>2015-05-12 15:19:52 -0700
committerChad Brubaker <cbrubaker@google.com>2015-05-19 13:45:00 -0700
commite35d49f0d2853b79470ec890113bf4dcef03ab88 (patch)
tree0904b4cb840c97f826a2667b814d12c5ec9ffb15 /keystore
parent0e2d3f2f871ae11d642eb576173d73ada9dcc292 (diff)
downloadframeworks_base-e35d49f0d2853b79470ec890113bf4dcef03ab88.zip
frameworks_base-e35d49f0d2853b79470ec890113bf4dcef03ab88.tar.gz
frameworks_base-e35d49f0d2853b79470ec890113bf4dcef03ab88.tar.bz2
Cleanup Keystore API
Rename confusingly named methods, add userID arguments to all methods that operate on user state and delete methods that have been replaced by the onUser* methods. Some of the old methods have been kept in KeyStore.java in order to ease the transition of various system packages to the new methods. (cherry-picked from commit d8aacca3a197f65021e9b520807b7315b7a59d68) Change-Id: Ic271689d62c36d255c5adee26c7abc2e7ed24df5
Diffstat (limited to 'keystore')
-rw-r--r--keystore/java/android/security/KeyStore.java85
1 files changed, 41 insertions, 44 deletions
diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java
index 06f5b06..72eda23 100644
--- a/keystore/java/android/security/KeyStore.java
+++ b/keystore/java/android/security/KeyStore.java
@@ -146,10 +146,10 @@ public class KeyStore {
}
}
- public State state() {
+ public State state(int userId) {
final int ret;
try {
- ret = mBinder.test();
+ ret = mBinder.getState(userId);
} catch (RemoteException e) {
Log.w(TAG, "Cannot connect to keystore", e);
throw new AssertionError(e);
@@ -163,6 +163,10 @@ public class KeyStore {
}
}
+ public State state() {
+ return state(UserHandle.myUserId());
+ }
+
public boolean isUnlocked() {
return state() == State.UNLOCKED;
}
@@ -211,15 +215,26 @@ public class KeyStore {
return contains(key, UID_SELF);
}
- public String[] saw(String prefix, int uid) {
+ /**
+ * List all entries in the keystore for {@code uid} starting with {@code prefix}.
+ */
+ public String[] list(String prefix, int uid) {
try {
- return mBinder.saw(prefix, uid);
+ return mBinder.list(prefix, uid);
} catch (RemoteException e) {
Log.w(TAG, "Cannot connect to keystore", e);
return null;
}
}
+ public String[] list(String prefix) {
+ return list(prefix, UID_SELF);
+ }
+
+ public String[] saw(String prefix, int uid) {
+ return list(prefix, uid);
+ }
+
public String[] saw(String prefix) {
return saw(prefix, UID_SELF);
}
@@ -233,15 +248,25 @@ public class KeyStore {
}
}
- public boolean lock() {
+ /**
+ * Attempt to lock the keystore for {@code user}.
+ *
+ * @param user Android user to lock.
+ * @return whether {@code user}'s keystore was locked.
+ */
+ public boolean lock(int userId) {
try {
- return mBinder.lock() == NO_ERROR;
+ return mBinder.lock(userId) == NO_ERROR;
} catch (RemoteException e) {
Log.w(TAG, "Cannot connect to keystore", e);
return false;
}
}
+ public boolean lock() {
+ return lock(UserHandle.myUserId());
+ }
+
/**
* Attempt to unlock the keystore for {@code user} with the password {@code password}.
* This is required before keystore entries created with FLAG_ENCRYPTED can be accessed or
@@ -267,15 +292,22 @@ public class KeyStore {
return unlock(UserHandle.getUserId(Process.myUid()), password);
}
- public boolean isEmpty() {
+ /**
+ * Check if the keystore for {@code userId} is empty.
+ */
+ public boolean isEmpty(int userId) {
try {
- return mBinder.zero() == KEY_NOT_FOUND;
+ return mBinder.isEmpty(userId) != 0;
} catch (RemoteException e) {
Log.w(TAG, "Cannot connect to keystore", e);
return false;
}
}
+ public boolean isEmpty() {
+ return isEmpty(UserHandle.myUserId());
+ }
+
public boolean generate(String key, int uid, int keyType, int keySize, int flags,
byte[][] args) {
try {
@@ -306,12 +338,7 @@ public class KeyStore {
}
public boolean delKey(String key, int uid) {
- try {
- return mBinder.del_key(key, uid) == NO_ERROR;
- } catch (RemoteException e) {
- Log.w(TAG, "Cannot connect to keystore", e);
- return false;
- }
+ return delete(key, uid);
}
public boolean delKey(String key) {
@@ -404,36 +431,6 @@ public class KeyStore {
}
}
- public boolean resetUid(int uid) {
- try {
- mError = mBinder.reset_uid(uid);
- return mError == NO_ERROR;
- } catch (RemoteException e) {
- Log.w(TAG, "Cannot connect to keystore", e);
- return false;
- }
- }
-
- public boolean syncUid(int sourceUid, int targetUid) {
- try {
- mError = mBinder.sync_uid(sourceUid, targetUid);
- return mError == NO_ERROR;
- } catch (RemoteException e) {
- Log.w(TAG, "Cannot connect to keystore", e);
- return false;
- }
- }
-
- public boolean passwordUid(String password, int uid) {
- try {
- mError = mBinder.password_uid(password, uid);
- return mError == NO_ERROR;
- } catch (RemoteException e) {
- Log.w(TAG, "Cannot connect to keystore", e);
- return false;
- }
- }
-
public int getLastError() {
return mError;
}