diff --git a/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java b/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java index 0623b87dd4..12095c7374 100644 --- a/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java +++ b/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java @@ -489,7 +489,14 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub @Override public void onAvailable(@NonNull Network network) { checkOnHandlerThread(); - Log.i(TAG, "Thread network available: " + network); + Log.i(TAG, "Thread network is available: " + network); + } + + @Override + public void onLost(@NonNull Network network) { + checkOnHandlerThread(); + Log.i(TAG, "Thread network is lost: " + network); + disableBorderRouting(); } @Override @@ -504,7 +511,7 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub + localNetworkInfo + "}"); if (localNetworkInfo.getUpstreamNetwork() == null) { - mUpstreamNetwork = null; + disableBorderRouting(); return; } if (!localNetworkInfo.getUpstreamNetwork().equals(mUpstreamNetwork)) { @@ -936,23 +943,22 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub mBorderRouterConfig.isBorderRoutingEnabled = true; mOtDaemon.configureBorderRouter( - mBorderRouterConfig, - new IOtStatusReceiver.Stub() { - @Override - public void onSuccess() { - Log.i(TAG, "configure border router successfully"); - } + mBorderRouterConfig, new ConfigureBorderRouterStatusReceiver()); + } catch (RemoteException | IOException e) { + Log.w(TAG, "Failed to enable border routing", e); + } + } - @Override - public void onError(int i, String s) { - Log.w( - TAG, - String.format( - "failed to configure border router: %d %s", i, s)); - } - }); - } catch (Exception e) { - Log.w(TAG, "enableBorderRouting failed: " + e); + private void disableBorderRouting() { + mUpstreamNetwork = null; + mBorderRouterConfig.infraInterfaceName = null; + mBorderRouterConfig.infraInterfaceIcmp6Socket = null; + mBorderRouterConfig.isBorderRoutingEnabled = false; + try { + mOtDaemon.configureBorderRouter( + mBorderRouterConfig, new ConfigureBorderRouterStatusReceiver()); + } catch (RemoteException e) { + Log.w(TAG, "Failed to disable border routing", e); } } @@ -1073,6 +1079,20 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub } } + private static final class ConfigureBorderRouterStatusReceiver extends IOtStatusReceiver.Stub { + public ConfigureBorderRouterStatusReceiver() {} + + @Override + public void onSuccess() { + Log.i(TAG, "Configured border router successfully"); + } + + @Override + public void onError(int i, String s) { + Log.w(TAG, String.format("Failed to configure border router: %d %s", i, s)); + } + } + /** * Handles and forwards Thread daemon callbacks. This class must be accessed from the thread of * {@code mHandler}. diff --git a/thread/tests/integration/src/android/net/thread/BorderRoutingTest.java b/thread/tests/integration/src/android/net/thread/BorderRoutingTest.java index ee21405025..88ee47e5bb 100644 --- a/thread/tests/integration/src/android/net/thread/BorderRoutingTest.java +++ b/thread/tests/integration/src/android/net/thread/BorderRoutingTest.java @@ -177,7 +177,7 @@ public class BorderRoutingTest { } @Test - public void unicastRouting_infraDevicePingTheadDeviceOmr_replyReceived() throws Exception { + public void unicastRouting_infraDevicePingThreadDeviceOmr_replyReceived() throws Exception { /* *
          * Topology:
@@ -198,6 +198,30 @@ public class BorderRoutingTest {
         assertNotNull(pollForPacketOnInfraNetwork(ICMPV6_ECHO_REPLY_TYPE, null /* srcAddress */));
     }
 
+    @Test
+    public void unicastRouting_afterFactoryResetInfraDevicePingThreadDeviceOmr_replyReceived()
+            throws Exception {
+        /*
+         * 
+         * Topology:
+         *                 infra network                       Thread
+         * infra device -------------------- Border Router -------------- Full Thread device
+         *                                   (Cuttlefish)
+         * 
+ */ + + // Form the network. + mOtCtl.factoryReset(); + startBrLeader(); + startInfraDevice(); + FullThreadDevice ftd = mFtds.get(0); + startFtdChild(ftd); + + mInfraDevice.sendEchoRequest(ftd.getOmrAddress()); + + assertNotNull(pollForPacketOnInfraNetwork(ICMPV6_ECHO_REPLY_TYPE, ftd.getOmrAddress())); + } + @Test public void unicastRouting_borderRouterSendsUdpToThreadDevice_datagramReceived() throws Exception {