KeyStore: stop using state()

Change-Id: I721974fd95f8d1ab06a3fd1bbb4c9b4d9d1d7752
diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java
index 9dd2b0d..4b69317 100644
--- a/keystore/java/android/security/KeyStore.java
+++ b/keystore/java/android/security/KeyStore.java
@@ -74,6 +74,10 @@
         }
     }
 
+    public boolean isUnlocked() {
+        return state() == State.UNLOCKED;
+    }
+
     public byte[] get(String key) {
         try {
             return mBinder.get(key);
diff --git a/keystore/tests/src/android/security/AndroidKeyPairGeneratorTest.java b/keystore/tests/src/android/security/AndroidKeyPairGeneratorTest.java
index d108caaa..cd031b4 100644
--- a/keystore/tests/src/android/security/AndroidKeyPairGeneratorTest.java
+++ b/keystore/tests/src/android/security/AndroidKeyPairGeneratorTest.java
@@ -62,11 +62,10 @@
 
         assertTrue(mAndroidKeyStore.reset());
 
-        assertEquals(android.security.KeyStore.State.UNINITIALIZED, mAndroidKeyStore.state());
+        assertFalse(mAndroidKeyStore.isUnlocked());
 
         assertTrue(mAndroidKeyStore.password("1111"));
-
-        assertEquals(android.security.KeyStore.State.UNLOCKED, mAndroidKeyStore.state());
+        assertTrue(mAndroidKeyStore.isUnlocked());
 
         assertEquals(0, mAndroidKeyStore.saw("").length);
 
diff --git a/keystore/tests/src/android/security/AndroidKeyStoreTest.java b/keystore/tests/src/android/security/AndroidKeyStoreTest.java
index c376f3d..8928e06 100644
--- a/keystore/tests/src/android/security/AndroidKeyStoreTest.java
+++ b/keystore/tests/src/android/security/AndroidKeyStoreTest.java
@@ -467,12 +467,10 @@
         mAndroidKeyStore = android.security.KeyStore.getInstance();
 
         assertTrue(mAndroidKeyStore.reset());
-
-        assertEquals(android.security.KeyStore.State.UNINITIALIZED, mAndroidKeyStore.state());
+        assertFalse(mAndroidKeyStore.isUnlocked());
 
         assertTrue(mAndroidKeyStore.password("1111"));
-
-        assertEquals(android.security.KeyStore.State.UNLOCKED, mAndroidKeyStore.state());
+        assertTrue(mAndroidKeyStore.isUnlocked());
 
         assertEquals(0, mAndroidKeyStore.saw("").length);
 
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index cccaf1c..e5cfdf6 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -3384,7 +3384,7 @@
         // Tear down existing lockdown if profile was removed
         mLockdownEnabled = LockdownVpnTracker.isEnabled();
         if (mLockdownEnabled) {
-            if (mKeyStore.state() != KeyStore.State.UNLOCKED) {
+            if (!mKeyStore.isUnlocked()) {
                 Slog.w(TAG, "KeyStore locked; unable to create LockdownTracker");
                 return false;
             }
diff --git a/services/java/com/android/server/connectivity/Vpn.java b/services/java/com/android/server/connectivity/Vpn.java
index bb19cc7..bb7334a 100644
--- a/services/java/com/android/server/connectivity/Vpn.java
+++ b/services/java/com/android/server/connectivity/Vpn.java
@@ -462,7 +462,7 @@
      * secondary thread to perform connection work, returning quickly.
      */
     public void startLegacyVpn(VpnProfile profile, KeyStore keyStore, LinkProperties egress) {
-        if (keyStore.state() != KeyStore.State.UNLOCKED) {
+        if (!keyStore.isUnlocked()) {
             throw new IllegalStateException("KeyStore isn't unlocked");
         }