summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/api/module-lib-current.txt2
-rw-r--r--wifi/java/src/android/net/wifi/WifiMigration.java30
-rw-r--r--wifi/tests/src/android/net/wifi/WifiMigrationTest.java12
3 files changed, 35 insertions, 9 deletions
diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt
index 8447a7feb54e..d38a4e7505fd 100644
--- a/core/api/module-lib-current.txt
+++ b/core/api/module-lib-current.txt
@@ -321,7 +321,7 @@ package android.net.netstats {
package android.net.wifi {
public final class WifiMigration {
- method @FlaggedApi("android.net.wifi.flags.legacy_keystore_to_wifi_blobstore_migration_read_only") public static int migrateLegacyKeystoreToWifiBlobstore();
+ method @FlaggedApi("android.net.wifi.flags.legacy_keystore_to_wifi_blobstore_migration_read_only") public static void migrateLegacyKeystoreToWifiBlobstore(@NonNull java.util.concurrent.Executor, @NonNull java.util.function.IntConsumer);
field @FlaggedApi("android.net.wifi.flags.legacy_keystore_to_wifi_blobstore_migration_read_only") public static final int KEYSTORE_MIGRATION_FAILURE_ENCOUNTERED_EXCEPTION = 2; // 0x2
field @FlaggedApi("android.net.wifi.flags.legacy_keystore_to_wifi_blobstore_migration_read_only") public static final int KEYSTORE_MIGRATION_SUCCESS_MIGRATION_COMPLETE = 0; // 0x0
field @FlaggedApi("android.net.wifi.flags.legacy_keystore_to_wifi_blobstore_migration_read_only") public static final int KEYSTORE_MIGRATION_SUCCESS_MIGRATION_NOT_NEEDED = 1; // 0x1
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");
diff --git a/wifi/tests/src/android/net/wifi/WifiMigrationTest.java b/wifi/tests/src/android/net/wifi/WifiMigrationTest.java
index 0aa299f959fe..ce5b60a2da9f 100644
--- a/wifi/tests/src/android/net/wifi/WifiMigrationTest.java
+++ b/wifi/tests/src/android/net/wifi/WifiMigrationTest.java
@@ -81,7 +81,7 @@ public class WifiMigrationTest {
public void testKeystoreMigrationAvoidedOnLegacyVendorPartition() {
when(WifiBlobStore.supplicantCanAccessBlobstore()).thenReturn(false);
assertEquals(WifiMigration.KEYSTORE_MIGRATION_SUCCESS_MIGRATION_NOT_NEEDED,
- WifiMigration.migrateLegacyKeystoreToWifiBlobstore());
+ WifiMigration.migrateLegacyKeystoreToWifiBlobstoreInternal());
verifyNoMoreInteractions(mLegacyKeystore, mWifiBlobStore);
}
@@ -93,7 +93,7 @@ public class WifiMigrationTest {
public void testKeystoreMigrationNoLegacyAliases() throws Exception {
when(mLegacyKeystore.list(anyString(), anyInt())).thenReturn(new String[0]);
assertEquals(WifiMigration.KEYSTORE_MIGRATION_SUCCESS_MIGRATION_NOT_NEEDED,
- WifiMigration.migrateLegacyKeystoreToWifiBlobstore());
+ WifiMigration.migrateLegacyKeystoreToWifiBlobstoreInternal());
verify(mLegacyKeystore).list(anyString(), anyInt());
verifyNoMoreInteractions(mLegacyKeystore, mWifiBlobStore);
}
@@ -110,7 +110,7 @@ public class WifiMigrationTest {
when(mWifiBlobStore.list(anyString())).thenReturn(blobstoreAliases);
assertEquals(WifiMigration.KEYSTORE_MIGRATION_SUCCESS_MIGRATION_COMPLETE,
- WifiMigration.migrateLegacyKeystoreToWifiBlobstore());
+ WifiMigration.migrateLegacyKeystoreToWifiBlobstoreInternal());
verify(mWifiBlobStore, times(legacyAliases.length)).put(anyString(), any(byte[].class));
}
@@ -129,7 +129,7 @@ public class WifiMigrationTest {
// Expect that only the unique legacy alias is migrated to the blobstore
assertEquals(WifiMigration.KEYSTORE_MIGRATION_SUCCESS_MIGRATION_COMPLETE,
- WifiMigration.migrateLegacyKeystoreToWifiBlobstore());
+ WifiMigration.migrateLegacyKeystoreToWifiBlobstoreInternal());
verify(mWifiBlobStore).list(anyString());
verify(mWifiBlobStore).put(eq(uniqueLegacyAlias), any(byte[].class));
verifyNoMoreInteractions(mWifiBlobStore);
@@ -146,7 +146,7 @@ public class WifiMigrationTest {
when(mLegacyKeystore.list(anyString(), anyInt())).thenThrow(
new ServiceSpecificException(ILegacyKeystore.ERROR_SYSTEM_ERROR));
assertEquals(WifiMigration.KEYSTORE_MIGRATION_SUCCESS_MIGRATION_NOT_NEEDED,
- WifiMigration.migrateLegacyKeystoreToWifiBlobstore());
+ WifiMigration.migrateLegacyKeystoreToWifiBlobstoreInternal());
}
/**
@@ -157,6 +157,6 @@ public class WifiMigrationTest {
public void testKeystoreMigrationFailsIfExceptionEncountered() throws Exception {
when(mLegacyKeystore.list(anyString(), anyInt())).thenThrow(new RemoteException());
assertEquals(WifiMigration.KEYSTORE_MIGRATION_FAILURE_ENCOUNTERED_EXCEPTION,
- WifiMigration.migrateLegacyKeystoreToWifiBlobstore());
+ WifiMigration.migrateLegacyKeystoreToWifiBlobstoreInternal());
}
}