diff options
author | 2024-09-13 19:11:26 +0000 | |
---|---|---|
committer | 2024-09-13 21:37:25 +0000 | |
commit | d57a9813e638d81db32ef906c73f42b1c4ba050b (patch) | |
tree | 71bbac77dfd743edfbc140c1f2cf246b673f23b4 /wifi/java/src | |
parent | 56707cdda60dcb15df5989d19c8c387100ee2e07 (diff) |
Return an status code from
WifiMigration#migrateLegacyKeystoreToWifiBlobstore.
Bug: 358618927
Flag: android.net.wifi.flags.legacy_keystore_to_wifi_blobstore_migration_read_only
Test: atest WifiMigrationTest
Change-Id: I310819dcb2d47286326d4f808efba9136ae5f5c0
Diffstat (limited to 'wifi/java/src')
-rw-r--r-- | wifi/java/src/android/net/wifi/WifiMigration.java | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/wifi/java/src/android/net/wifi/WifiMigration.java b/wifi/java/src/android/net/wifi/WifiMigration.java index 7df1d4b47204..f1850dd91b5f 100644 --- a/wifi/java/src/android/net/wifi/WifiMigration.java +++ b/wifi/java/src/android/net/wifi/WifiMigration.java @@ -100,6 +100,39 @@ public final class WifiMigration { public @interface UserStoreFileId { } /** + * Keystore migration was completed successfully. + * @hide + */ + @FlaggedApi(Flags.FLAG_LEGACY_KEYSTORE_TO_WIFI_BLOBSTORE_MIGRATION_READ_ONLY) + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + public static final int KEYSTORE_MIGRATION_SUCCESS_MIGRATION_COMPLETE = 0; + + /** + * Keystore migration was not needed. + * @hide + */ + @FlaggedApi(Flags.FLAG_LEGACY_KEYSTORE_TO_WIFI_BLOBSTORE_MIGRATION_READ_ONLY) + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + public static final int KEYSTORE_MIGRATION_SUCCESS_MIGRATION_NOT_NEEDED = 1; + + /** + * Keystore migration failed because an exception was encountered. + * @hide + */ + @FlaggedApi(Flags.FLAG_LEGACY_KEYSTORE_TO_WIFI_BLOBSTORE_MIGRATION_READ_ONLY) + @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) + public static final int KEYSTORE_MIGRATION_FAILURE_ENCOUNTERED_EXCEPTION = 2; + + /** @hide */ + @IntDef(prefix = { "KEYSTORE_MIGRATION_" }, value = { + KEYSTORE_MIGRATION_SUCCESS_MIGRATION_COMPLETE, + KEYSTORE_MIGRATION_SUCCESS_MIGRATION_NOT_NEEDED, + KEYSTORE_MIGRATION_FAILURE_ENCOUNTERED_EXCEPTION + }) + @Retention(RetentionPolicy.SOURCE) + public @interface KeystoreMigrationStatus { } + + /** * Mapping of Store file Id to Store file names. * * NOTE: This is the default path for the files on AOSP devices. If the OEM has modified @@ -572,14 +605,17 @@ public final class WifiMigration { /** * Migrate any certificates in Legacy Keystore to the newer WifiBlobstore database. * + * If there are no certificates to migrate, this method will return immediately. + * * @hide */ @FlaggedApi(Flags.FLAG_LEGACY_KEYSTORE_TO_WIFI_BLOBSTORE_MIGRATION_READ_ONLY) @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) - public static void migrateLegacyKeystoreToWifiBlobstore() { + public static @KeystoreMigrationStatus int migrateLegacyKeystoreToWifiBlobstore() { if (!WifiBlobStore.supplicantCanAccessBlobstore()) { + // Supplicant cannot access WifiBlobstore, so keep the certs in Legacy Keystore Log.i(TAG, "Avoiding migration since supplicant cannot access WifiBlobstore"); - return; + return KEYSTORE_MIGRATION_SUCCESS_MIGRATION_NOT_NEEDED; } final long identity = Binder.clearCallingIdentity(); try { @@ -587,7 +623,7 @@ public final class WifiMigration { String[] legacyAliases = legacyKeystore.list("", Process.WIFI_UID); if (legacyAliases == null || legacyAliases.length == 0) { Log.i(TAG, "No aliases need to be migrated"); - return; + return KEYSTORE_MIGRATION_SUCCESS_MIGRATION_NOT_NEEDED; } WifiBlobStore wifiBlobStore = WifiBlobStore.getInstance(); @@ -605,14 +641,17 @@ public final class WifiMigration { legacyKeystore.remove(legacyAlias, Process.WIFI_UID); } Log.i(TAG, "Successfully migrated aliases from Legacy Keystore"); + return KEYSTORE_MIGRATION_SUCCESS_MIGRATION_COMPLETE; } catch (ServiceSpecificException e) { if (e.errorCode == ILegacyKeystore.ERROR_SYSTEM_ERROR) { Log.i(TAG, "Legacy Keystore service has been deprecated"); - } else { - Log.e(TAG, "Encountered an exception while migrating aliases. " + e); + return KEYSTORE_MIGRATION_SUCCESS_MIGRATION_NOT_NEEDED; } + Log.e(TAG, "Encountered a ServiceSpecificException while migrating aliases. " + e); + return KEYSTORE_MIGRATION_FAILURE_ENCOUNTERED_EXCEPTION; } catch (Exception e) { Log.e(TAG, "Encountered an exception while migrating aliases. " + e); + return KEYSTORE_MIGRATION_FAILURE_ENCOUNTERED_EXCEPTION; } finally { Binder.restoreCallingIdentity(identity); } |