[Thread] add configuration methods in ThreadNetworkControllerWrapper
Change-Id: I56b4ca76e7f62d924f99527b36eac24ed151c53b
diff --git a/thread/tests/integration/src/android/net/thread/utils/ThreadNetworkControllerWrapper.java b/thread/tests/integration/src/android/net/thread/utils/ThreadNetworkControllerWrapper.java
index 7e84233..4a30c45 100644
--- a/thread/tests/integration/src/android/net/thread/utils/ThreadNetworkControllerWrapper.java
+++ b/thread/tests/integration/src/android/net/thread/utils/ThreadNetworkControllerWrapper.java
@@ -29,6 +29,7 @@
import android.annotation.Nullable;
import android.content.Context;
import android.net.thread.ActiveOperationalDataset;
+import android.net.thread.ThreadConfiguration;
import android.net.thread.ThreadNetworkController;
import android.net.thread.ThreadNetworkController.StateCallback;
import android.net.thread.ThreadNetworkException;
@@ -40,6 +41,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
+import java.util.function.Consumer;
/** A helper class which provides synchronous API wrappers for {@link ThreadNetworkController}. */
public final class ThreadNetworkControllerWrapper {
@@ -47,6 +49,7 @@
public static final Duration LEAVE_TIMEOUT = Duration.ofSeconds(2);
private static final Duration CALLBACK_TIMEOUT = Duration.ofSeconds(1);
private static final Duration SET_ENABLED_TIMEOUT = Duration.ofSeconds(2);
+ private static final Duration CONFIG_TIMEOUT = Duration.ofSeconds(1);
private final ThreadNetworkController mController;
@@ -191,6 +194,29 @@
future.get(CALLBACK_TIMEOUT.toSeconds(), SECONDS);
}
+ public ThreadConfiguration getConfiguration() throws Exception {
+ CompletableFuture<ThreadConfiguration> future = new CompletableFuture<>();
+ Consumer<ThreadConfiguration> callback = future::complete;
+ runAsShell(
+ PERMISSION_THREAD_NETWORK_PRIVILEGED,
+ () -> mController.registerConfigurationCallback(directExecutor(), callback));
+ future.get(CALLBACK_TIMEOUT.toSeconds(), SECONDS);
+ runAsShell(
+ PERMISSION_THREAD_NETWORK_PRIVILEGED,
+ () -> mController.unregisterConfigurationCallback(callback));
+ return future.getNow(null);
+ }
+
+ public void setConfigurationAndWait(ThreadConfiguration config) throws Exception {
+ CompletableFuture<Void> future = new CompletableFuture<>();
+ runAsShell(
+ PERMISSION_THREAD_NETWORK_PRIVILEGED,
+ () ->
+ mController.setConfiguration(
+ config, directExecutor(), newOutcomeReceiver(future)));
+ future.get(CALLBACK_TIMEOUT.toSeconds(), SECONDS);
+ }
+
private static <V> OutcomeReceiver<V, ThreadNetworkException> newOutcomeReceiver(
CompletableFuture<V> future) {
return new OutcomeReceiver<V, ThreadNetworkException>() {