diff options
author | 2024-10-02 17:00:19 +0000 | |
---|---|---|
committer | 2024-10-02 21:54:34 +0000 | |
commit | fb138f4865c733270a293d90f196bbc8c2632d53 (patch) | |
tree | d1c5c8f2bef9b3fc7f0e003215323709a202d8e3 /wifi/java/src | |
parent | f7af3c7dfee94f25479d0d9b273097fa2b6130ac (diff) |
Convert migrateLegacyKeystoreToWifiBlobstore to
an asynchronous method.
API council suggested that the migration can
be a heavy operation, so it is best handled
in the background.
Bug: 358618927
Flag: android.net.wifi.flags.legacy_keystore_to_wifi_blobstore_migration_read_only
Test: atest WifiMigrationTest
Change-Id: I1a61eda93e9f3e2cf0081326777d20a618acb456
Diffstat (limited to 'wifi/java/src')
-rw-r--r-- | wifi/java/src/android/net/wifi/WifiMigration.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/wifi/java/src/android/net/wifi/WifiMigration.java b/wifi/java/src/android/net/wifi/WifiMigration.java index f1850dd91b5f..28e9c45fb6cb 100644 --- a/wifi/java/src/android/net/wifi/WifiMigration.java +++ b/wifi/java/src/android/net/wifi/WifiMigration.java @@ -38,6 +38,8 @@ import android.util.AtomicFile; import android.util.Log; import android.util.SparseArray; +import com.android.internal.os.BackgroundThread; + import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; @@ -48,6 +50,8 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.concurrent.Executor; +import java.util.function.IntConsumer; /** * Class used to provide one time hooks for existing OEM devices to migrate their config store @@ -605,13 +609,35 @@ 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. + * Operation will be handled on the BackgroundThread, and the result will be posted + * to the provided Executor. + * + * @param executor The executor on which callback will be invoked + * @param resultsCallback Callback to receive the status code * * @hide */ @FlaggedApi(Flags.FLAG_LEGACY_KEYSTORE_TO_WIFI_BLOBSTORE_MIGRATION_READ_ONLY) @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) - public static @KeystoreMigrationStatus int migrateLegacyKeystoreToWifiBlobstore() { + public static void migrateLegacyKeystoreToWifiBlobstore( + @NonNull Executor executor, @NonNull IntConsumer resultsCallback) { + Objects.requireNonNull(executor, "executor cannot be null"); + Objects.requireNonNull(resultsCallback, "resultsCallback cannot be null"); + BackgroundThread.getHandler().post(() -> { + int status = migrateLegacyKeystoreToWifiBlobstoreInternal(); + executor.execute(() -> { + resultsCallback.accept(status); + }); + }); + } + + /** + * Synchronously perform the Keystore migration described in + * {@link #migrateLegacyKeystoreToWifiBlobstore(Executor, IntConsumer)} + * + * @hide + */ + public static @KeystoreMigrationStatus int migrateLegacyKeystoreToWifiBlobstoreInternal() { if (!WifiBlobStore.supplicantCanAccessBlobstore()) { // Supplicant cannot access WifiBlobstore, so keep the certs in Legacy Keystore Log.i(TAG, "Avoiding migration since supplicant cannot access WifiBlobstore"); |