diff options
author | 2024-03-27 23:21:35 +0000 | |
---|---|---|
committer | 2024-03-27 23:29:06 +0000 | |
commit | 922a1531aaf34ac6e16206d6a80a994ddc4150d3 (patch) | |
tree | da1f6215bda091755e05c3e97cef861cab89040c | |
parent | cd81a00c72588d2e356e871e675d6063be729a16 (diff) |
Move getLegacyKeystore to the WifiBlobStore class.
Will allow for easier mocking of the database
objects in the unit tests.
Bug: 304553176
Test: m
Change-Id: I5111a20af7a1057bdc29107c34ae1ccc9ae50114
-rw-r--r-- | wifi/java/src/android/net/wifi/WifiBlobStore.java | 10 | ||||
-rw-r--r-- | wifi/java/src/android/net/wifi/WifiKeystore.java | 14 |
2 files changed, 14 insertions, 10 deletions
diff --git a/wifi/java/src/android/net/wifi/WifiBlobStore.java b/wifi/java/src/android/net/wifi/WifiBlobStore.java index 8bfaae72f932..8737c7e91454 100644 --- a/wifi/java/src/android/net/wifi/WifiBlobStore.java +++ b/wifi/java/src/android/net/wifi/WifiBlobStore.java @@ -16,6 +16,9 @@ package android.net.wifi; +import android.os.ServiceManager; +import android.security.legacykeystore.ILegacyKeystore; + import com.android.internal.net.ConnectivityBlobStore; /** @@ -24,6 +27,7 @@ import com.android.internal.net.ConnectivityBlobStore; */ public class WifiBlobStore extends ConnectivityBlobStore { private static final String DB_NAME = "WifiBlobStore.db"; + private static final String LEGACY_KEYSTORE_SERVICE_NAME = "android.security.legacykeystore"; private static WifiBlobStore sInstance; private WifiBlobStore() { super(DB_NAME); @@ -36,4 +40,10 @@ public class WifiBlobStore extends ConnectivityBlobStore { } return sInstance; } + + /** Returns an interface to access the Legacy Keystore service. */ + public static ILegacyKeystore getLegacyKeystore() { + return ILegacyKeystore.Stub.asInterface( + ServiceManager.checkService(LEGACY_KEYSTORE_SERVICE_NAME)); + } } diff --git a/wifi/java/src/android/net/wifi/WifiKeystore.java b/wifi/java/src/android/net/wifi/WifiKeystore.java index a06d0eeade72..2ba7468a8c9c 100644 --- a/wifi/java/src/android/net/wifi/WifiKeystore.java +++ b/wifi/java/src/android/net/wifi/WifiKeystore.java @@ -20,7 +20,6 @@ import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.os.Binder; import android.os.Process; -import android.os.ServiceManager; import android.os.ServiceSpecificException; import android.security.legacykeystore.ILegacyKeystore; import android.util.Log; @@ -37,12 +36,6 @@ import java.util.Set; @SuppressLint("UnflaggedApi") // Promoting from @SystemApi(MODULE_LIBRARIES) public final class WifiKeystore { private static final String TAG = "WifiKeystore"; - private static final String LEGACY_KEYSTORE_SERVICE_NAME = "android.security.legacykeystore"; - - private static ILegacyKeystore getLegacyKeystore() { - return ILegacyKeystore.Stub.asInterface( - ServiceManager.checkService(LEGACY_KEYSTORE_SERVICE_NAME)); - } /** @hide */ WifiKeystore() { @@ -93,7 +86,7 @@ public final class WifiKeystore { return blob; } Log.i(TAG, "Searching for blob in Legacy Keystore"); - return getLegacyKeystore().get(alias, Process.WIFI_UID); + return WifiBlobStore.getLegacyKeystore().get(alias, Process.WIFI_UID); } catch (ServiceSpecificException e) { if (e.errorCode != ILegacyKeystore.ERROR_ENTRY_NOT_FOUND) { Log.e(TAG, "Failed to get blob.", e); @@ -122,7 +115,7 @@ public final class WifiKeystore { Log.i(TAG, "remove blob. alias " + alias); blobStoreSuccess = WifiBlobStore.getInstance().remove(alias); // Legacy Keystore will throw an exception if the alias is not found. - getLegacyKeystore().remove(alias, Process.WIFI_UID); + WifiBlobStore.getLegacyKeystore().remove(alias, Process.WIFI_UID); legacyKsSuccess = true; } catch (ServiceSpecificException e) { if (e.errorCode != ILegacyKeystore.ERROR_ENTRY_NOT_FOUND) { @@ -151,7 +144,8 @@ public final class WifiKeystore { try { // Aliases from WifiBlobStore will be pre-trimmed. final String[] blobStoreAliases = WifiBlobStore.getInstance().list(prefix); - final String[] legacyAliases = getLegacyKeystore().list(prefix, Process.WIFI_UID); + final String[] legacyAliases = + WifiBlobStore.getLegacyKeystore().list(prefix, Process.WIFI_UID); for (int i = 0; i < legacyAliases.length; ++i) { legacyAliases[i] = legacyAliases[i].substring(prefix.length()); } |