Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 11e32482 authored by Hasini Gunasinghe's avatar Hasini Gunasinghe Committed by Gerrit Code Review
Browse files

Merge "Keystore2: Integrate getState method of IKeystoreMaintenance AIDL."

parents 420476e0 e92adf72
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -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);