From d44de5a6245e82a0ca6a216958d22d7fc0f6a70b Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Wed, 18 Mar 2020 11:42:25 +0900 Subject: [PATCH] Release the interface request when Ethernet tethering is stopped. When the Ethernet interface becomes unavailable (e.g., because the cable was unplugged or the interface was removed), or when setEthernetTethering(false) is called, release the Ethernet interface request. This ensures that: - The Ethernet interface immediately becomes available for use in client mode. - If an interface later becomes available, tethering is not automatically started. This is consistent with what happens for other downstream types such as wifi and USB. Evey time one of those downstreams goes down, tethering is stopped and will not be restarted. Test: manual Bug: 148824036 Change-Id: Iaf85e800569f2e08c39f7ebb96f8aa34f6e53133 --- .../connectivity/tethering/Tethering.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Tethering/src/com/android/server/connectivity/tethering/Tethering.java b/Tethering/src/com/android/server/connectivity/tethering/Tethering.java index a9e9a752fc..1cfc04b481 100644 --- a/Tethering/src/com/android/server/connectivity/tethering/Tethering.java +++ b/Tethering/src/com/android/server/connectivity/tethering/Tethering.java @@ -640,21 +640,21 @@ public class Tethering { mEthernetIfaceRequest = em.requestTetheredInterface(mExecutor, mEthernetCallback); } else { stopEthernetTetheringLocked(); - if (mEthernetCallback != null) { - mEthernetIfaceRequest.release(); - mEthernetCallback = null; - mEthernetIfaceRequest = null; - } } } return TETHER_ERROR_NO_ERROR; } private void stopEthernetTetheringLocked() { - if (mConfiguredEthernetIface == null) return; - changeInterfaceState(mConfiguredEthernetIface, IpServer.STATE_AVAILABLE); - stopTrackingInterfaceLocked(mConfiguredEthernetIface); - mConfiguredEthernetIface = null; + if (mConfiguredEthernetIface != null) { + stopTrackingInterfaceLocked(mConfiguredEthernetIface); + mConfiguredEthernetIface = null; + } + if (mEthernetCallback != null) { + mEthernetIfaceRequest.release(); + mEthernetCallback = null; + mEthernetIfaceRequest = null; + } } private class EthernetCallback implements EthernetManager.TetheredInterfaceCallback {