From d2fc66d4bb3bcc843be2b45ecc1fde555b77ec88 Mon Sep 17 00:00:00 2001 From: Kangping Dong Date: Fri, 10 Jan 2025 11:52:50 +0800 Subject: [PATCH] [Thread] allow disabling border router auto-join MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test: verified that when the config is set to `false`, thread won't start up after reboots: ``` ➜ main-aosp-2 adb shell ot-ctl state leader Done ➜ main-aosp-2 adb reboot ➜ main-aosp-2 adb shell ot-ctl state /system/bin/sh: ot-ctl: inaccessible or not found ➜ main-aosp-2 adb root ➜ main-aosp-2 adb shell ot-ctl state disabled Done ``` Bug: 378587036 Change-Id: I4d1c90ab3121f39219cbaf795879a7ba91db02a3 --- .../res/values/config_thread.xml | 6 ++++++ .../ServiceConnectivityResources/res/values/overlayable.xml | 1 + .../server/thread/ThreadNetworkControllerService.java | 3 +++ .../server/thread/ThreadNetworkControllerServiceTest.java | 5 +++++ 4 files changed, 15 insertions(+) diff --git a/service/ServiceConnectivityResources/res/values/config_thread.xml b/service/ServiceConnectivityResources/res/values/config_thread.xml index 3627157f0a..d1d9e5292e 100644 --- a/service/ServiceConnectivityResources/res/values/config_thread.xml +++ b/service/ServiceConnectivityResources/res/values/config_thread.xml @@ -79,4 +79,10 @@ to the devices, or reaching to Thread end devices doesn't require border routing to work. --> true + + + true diff --git a/service/ServiceConnectivityResources/res/values/overlayable.xml b/service/ServiceConnectivityResources/res/values/overlayable.xml index 121cbc4826..7ac86aacd6 100644 --- a/service/ServiceConnectivityResources/res/values/overlayable.xml +++ b/service/ServiceConnectivityResources/res/values/overlayable.xml @@ -53,6 +53,7 @@ + diff --git a/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java b/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java index c2959f4d8c..af16d19ea2 100644 --- a/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java +++ b/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java @@ -626,11 +626,14 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub private OtDaemonConfiguration newOtDaemonConfig(ThreadConfiguration threadConfig) { int srpServerConfig = R.bool.config_thread_srp_server_wait_for_border_routing_enabled; boolean srpServerWaitEnabled = mResources.get().getBoolean(srpServerConfig); + int autoJoinConfig = R.bool.config_thread_border_router_auto_join_enabled; + boolean autoJoinEnabled = mResources.get().getBoolean(autoJoinConfig); return new OtDaemonConfiguration.Builder() .setBorderRouterEnabled(threadConfig.isBorderRouterEnabled()) .setNat64Enabled(threadConfig.isNat64Enabled()) .setDhcpv6PdEnabled(threadConfig.isDhcpv6PdEnabled()) .setSrpServerWaitForBorderRoutingEnabled(srpServerWaitEnabled) + .setBorderRouterAutoJoinEnabled(autoJoinEnabled) .build(); } diff --git a/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java b/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java index 1d44ccb0bd..bc8da8b81b 100644 --- a/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java +++ b/thread/tests/unit/src/com/android/server/thread/ThreadNetworkControllerServiceTest.java @@ -234,6 +234,8 @@ public final class ThreadNetworkControllerServiceTest { when(mResources.getBoolean( eq(R.bool.config_thread_srp_server_wait_for_border_routing_enabled))) .thenReturn(true); + when(mResources.getBoolean(eq(R.bool.config_thread_border_router_auto_join_enabled))) + .thenReturn(true); when(mResources.getString(eq(R.string.config_thread_vendor_name))) .thenReturn(TEST_VENDOR_NAME); when(mResources.getString(eq(R.string.config_thread_vendor_oui))) @@ -291,6 +293,8 @@ public final class ThreadNetworkControllerServiceTest { when(mResources.getBoolean( eq(R.bool.config_thread_srp_server_wait_for_border_routing_enabled))) .thenReturn(false); + when(mResources.getBoolean(eq(R.bool.config_thread_border_router_auto_join_enabled))) + .thenReturn(false); when(mResources.getString(eq(R.string.config_thread_vendor_name))) .thenReturn(TEST_VENDOR_NAME); when(mResources.getString(eq(R.string.config_thread_vendor_oui))) @@ -304,6 +308,7 @@ public final class ThreadNetworkControllerServiceTest { mTestLooper.dispatchAll(); assertThat(mFakeOtDaemon.getConfiguration().srpServerWaitForBorderRoutingEnabled).isFalse(); + assertThat(mFakeOtDaemon.getConfiguration().borderRouterAutoJoinEnabled).isFalse(); MeshcopTxtAttributes meshcopTxts = mFakeOtDaemon.getOverriddenMeshcopTxtAttributes(); assertThat(meshcopTxts.vendorName).isEqualTo(TEST_VENDOR_NAME); assertThat(meshcopTxts.vendorOui).isEqualTo(TEST_VENDOR_OUI_BYTES);