diff options
-rw-r--r-- | java/com/android/server/ethernet/EthernetNetworkFactory.java | 16 | ||||
-rw-r--r-- | tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java | 16 |
2 files changed, 32 insertions, 0 deletions
diff --git a/java/com/android/server/ethernet/EthernetNetworkFactory.java b/java/com/android/server/ethernet/EthernetNetworkFactory.java index 26532d7..2886cf1 100644 --- a/java/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/java/com/android/server/ethernet/EthernetNetworkFactory.java @@ -347,6 +347,11 @@ public class EthernetNetworkFactory extends NetworkFactory { } @Override + public void onReachabilityLost(String logMsg) { + mHandler.post(() -> updateNeighborLostEvent(logMsg)); + } + + @Override public void onQuit() { mIpClient = null; mIpClientShutdownCv.open(); @@ -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/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java b/tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java index 0cd9c18..6422358 100644 --- a/tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java +++ b/tests/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()); + } } |