Merge "Keystore2: Integrate getState method of IKeystoreMaintenance AIDL."
This commit is contained in:
@@ -121,4 +121,22 @@ public class AndroidKeyStoreMaintenance {
|
||||
return SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries user state from Keystore 2.0.
|
||||
*
|
||||
* @param userId - Android user id of the user.
|
||||
* @return UserState enum variant as integer if successful or an error
|
||||
*/
|
||||
public static int getState(int userId) {
|
||||
try {
|
||||
return getService().getState(userId);
|
||||
} catch (ServiceSpecificException e) {
|
||||
Log.e(TAG, "getState failed", e);
|
||||
return e.errorCode;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Can not connect to keystore", e);
|
||||
return SYSTEM_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import android.security.keystore.KeyPermanentlyInvalidatedException;
|
||||
import android.security.keystore.KeyProperties;
|
||||
import android.security.keystore.KeystoreResponse;
|
||||
import android.security.keystore.UserNotAuthenticatedException;
|
||||
import android.security.maintenance.UserState;
|
||||
import android.system.keystore2.Domain;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -196,6 +197,19 @@ public class KeyStore {
|
||||
public State state(int userId) {
|
||||
final int ret;
|
||||
try {
|
||||
if (android.security.keystore2.AndroidKeyStoreProvider.isInstalled()) {
|
||||
int userState = AndroidKeyStoreMaintenance.getState(userId);
|
||||
switch (userState) {
|
||||
case UserState.UNINITIALIZED:
|
||||
return KeyStore.State.UNINITIALIZED;
|
||||
case UserState.LSKF_UNLOCKED:
|
||||
return KeyStore.State.UNLOCKED;
|
||||
case UserState.LSKF_LOCKED:
|
||||
return KeyStore.State.LOCKED;
|
||||
default:
|
||||
throw new AssertionError(KeyStore.VALUE_CORRUPTED);
|
||||
}
|
||||
}
|
||||
ret = mBinder.getState(userId);
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "Cannot connect to keystore", e);
|
||||
|
||||
Reference in New Issue
Block a user