From e600bef8f93405507b3c633d9559a2b38e5daf02 Mon Sep 17 00:00:00 2001 From: Pavan Kumar M Date: Mon, 8 Feb 2021 21:17:20 +0530 Subject: [PATCH] Handle neighbor lost event Neighbor lost event is received when gateway is not reachable. Ethernet Factory currently doesn't handle the neighbor lost event and network will not be brought down. This results in loss of connectivity even if there are other networks like WiFi. Restart NetworkInterfaceState when neighbor lost event is received. If there is a better network like WiFi, it will become default and apps will be able to use internet. If ethernet gets connected again, and has backhaul connectivity, it will become default. Bug: 180077540 Tests: Builds, Boots, EthernetServiceTests Change-Id: I26d720994ecb35f6529358a53e115091e7817c2f --- .../server/ethernet/EthernetNetworkFactory.java | 16 ++++++++++++++++ .../ethernet/EthernetNetworkFactoryTest.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java index 26532d7355..2886cf1e3d 100644 --- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java @@ -346,6 +346,11 @@ public class EthernetNetworkFactory extends NetworkFactory { mHandler.post(() -> updateLinkProperties(newLp)); } + @Override + public void onReachabilityLost(String logMsg) { + mHandler.post(() -> updateNeighborLostEvent(logMsg)); + } + @Override public void onQuit() { mIpClient = null; @@ -479,6 +484,17 @@ public class EthernetNetworkFactory extends NetworkFactory { } } + void updateNeighborLostEvent(String logMsg) { + Log.i(TAG, "updateNeighborLostEvent " + logMsg); + // Reachability lost will be seen only if the gateway is not reachable. + // Since ethernet FW doesn't have the mechanism to scan for new networks + // like WiFi, simply restart. + // If there is a better network, that will become default and apps + // will be able to use internet. If ethernet gets connected again, + // and has backhaul connectivity, it will become default. + restart(); + } + /** Returns true if state has been modified */ boolean updateLinkState(boolean up) { if (mLinkUp == up) return false; diff --git a/tests/ethernet/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java b/tests/ethernet/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java index 0cd9c1811e..6422358068 100644 --- a/tests/ethernet/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java +++ b/tests/ethernet/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java @@ -434,4 +434,20 @@ public class EthernetNetworkFactoryTest { ConnectivityManager.TYPE_NONE); mNetFactory.removeInterface(iface); } + + @Test + public void testReachabilityLoss() throws Exception { + String iface = "eth0"; + createAndVerifyProvisionedInterface(iface); + + mIpClientCallbacks.onReachabilityLost("ReachabilityLost"); + mLooper.dispatchAll(); + + // Reachability loss should trigger a stop and start, since the interface is still there + verify(mIpClient).shutdown(); + verify(mNetworkAgent).unregister(); + + verify(mDeps).makeIpClient(any(Context.class), anyString(), any()); + verify(mIpClient).startProvisioning(any()); + } }