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 7e84233cbe..4a30c45da0 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 static java.util.concurrent.TimeUnit.SECONDS; 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.List; 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 final class ThreadNetworkControllerWrapper { 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 @@ public final class ThreadNetworkControllerWrapper { future.get(CALLBACK_TIMEOUT.toSeconds(), SECONDS); } + public ThreadConfiguration getConfiguration() throws Exception { + CompletableFuture future = new CompletableFuture<>(); + Consumer 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 future = new CompletableFuture<>(); + runAsShell( + PERMISSION_THREAD_NETWORK_PRIVILEGED, + () -> + mController.setConfiguration( + config, directExecutor(), newOutcomeReceiver(future))); + future.get(CALLBACK_TIMEOUT.toSeconds(), SECONDS); + } + private static OutcomeReceiver newOutcomeReceiver( CompletableFuture future) { return new OutcomeReceiver() {