From a70feeca7ad97aa6145b38da0209d5096f6b3f48 Mon Sep 17 00:00:00 2001 From: Jianpeng Li Date: Fri, 24 May 2019 17:40:15 +0900 Subject: [PATCH] Update wifi interface ip state upon receiving ap disable event When turning on/off SoftAp with high frequency, sometime calling WifiManager#updateInterfaceIpState with IFACE_IP_MODE_TETHERED is performed after handling WIFI_AP_STATE_DISABLED event in WifiServiceImpl while SoftAp is being terminated. This leads to the issue that SoftAp is unable to start as startSoftAp always returns "false". This is because mIfaceIpModes in WifiServiceImpl keeps the mode WifiManager.IFACE_IP_MODE_TETHERED and the CL below rejects SoftAp start request. e257c5c9e79e3675375ca20731cfb74df02b1064 @ frameworks/opt/net/wifi (WifiServiceImpl: Reject startSoftAp when already tethering) This CL updates the interface ip state upon receiving ap disable event from Tethering class to set proper state to mIfaceIpModes. Bug: 134806980 Test: Ran script to turn on/off soft ap frequently Signed-off-by: Daichi Ueura Change-Id: I2f89214414d93f1aa942fb8a21264a9baae3452a --- .../com/android/server/connectivity/Tethering.java | 6 +++++- .../android/server/connectivity/TetheringTest.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java index 4957eed21c70e..712044115c44c 100644 --- a/services/core/java/com/android/server/connectivity/Tethering.java +++ b/services/core/java/com/android/server/connectivity/Tethering.java @@ -1315,11 +1315,15 @@ public class Tethering extends BaseNetworkObserver { mOffload.excludeDownstreamInterface(who.interfaceName()); mForwardedDownstreams.remove(who); - // If this is a Wi-Fi interface, tell WifiManager of any errors. + // If this is a Wi-Fi interface, tell WifiManager of any errors + // or the inactive serving state. if (who.interfaceType() == TETHERING_WIFI) { if (who.lastError() != TETHER_ERROR_NO_ERROR) { getWifiManager().updateInterfaceIpState( who.interfaceName(), IFACE_IP_MODE_CONFIGURATION_ERROR); + } else { + getWifiManager().updateInterfaceIpState( + who.interfaceName(), IFACE_IP_MODE_UNSPECIFIED); } } } diff --git a/tests/net/java/com/android/server/connectivity/TetheringTest.java b/tests/net/java/com/android/server/connectivity/TetheringTest.java index 8c522f48cfd2d..c030c3e9ac865 100644 --- a/tests/net/java/com/android/server/connectivity/TetheringTest.java +++ b/tests/net/java/com/android/server/connectivity/TetheringTest.java @@ -469,6 +469,8 @@ public class TetheringTest { if (emulateInterfaceStatusChanged) { assertEquals(1, mTetheringDependencies.isTetheringSupportedCalls); verifyTetheringBroadcast(TEST_WLAN_IFNAME, EXTRA_AVAILABLE_TETHER); + verify(mWifiManager).updateInterfaceIpState( + TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_UNSPECIFIED); } verifyNoMoreInteractions(mNMService); verifyNoMoreInteractions(mWifiManager); @@ -533,6 +535,8 @@ public class TetheringTest { verify(mNMService, times(1)).setIpForwardingEnabled(true); verify(mNMService, times(1)).startTethering(any(String[].class)); verifyNoMoreInteractions(mNMService); + verify(mWifiManager).updateInterfaceIpState( + TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_UNSPECIFIED); verify(mWifiManager).updateInterfaceIpState( TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_LOCAL_ONLY); verifyNoMoreInteractions(mWifiManager); @@ -554,6 +558,8 @@ public class TetheringTest { .setInterfaceConfig(eq(TEST_WLAN_IFNAME), any(InterfaceConfiguration.class)); verify(mNMService, times(1)).stopTethering(); verify(mNMService, times(1)).setIpForwardingEnabled(false); + verify(mWifiManager, times(3)).updateInterfaceIpState( + TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_UNSPECIFIED); verifyNoMoreInteractions(mNMService); verifyNoMoreInteractions(mWifiManager); // Asking for the last error after the per-interface state machine @@ -739,6 +745,8 @@ public class TetheringTest { assertEquals(1, mTetheringDependencies.isTetheringSupportedCalls); verifyTetheringBroadcast(TEST_WLAN_IFNAME, EXTRA_AVAILABLE_TETHER); + verify(mWifiManager).updateInterfaceIpState( + TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_UNSPECIFIED); verifyNoMoreInteractions(mNMService); verifyNoMoreInteractions(mWifiManager); } @@ -767,6 +775,8 @@ public class TetheringTest { verify(mNMService, times(1)).setIpForwardingEnabled(true); verify(mNMService, times(1)).startTethering(any(String[].class)); verifyNoMoreInteractions(mNMService); + verify(mWifiManager).updateInterfaceIpState( + TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_UNSPECIFIED); verify(mWifiManager).updateInterfaceIpState( TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_TETHERED); verifyNoMoreInteractions(mWifiManager); @@ -805,6 +815,8 @@ public class TetheringTest { .setInterfaceConfig(eq(TEST_WLAN_IFNAME), any(InterfaceConfiguration.class)); verify(mNMService, times(1)).stopTethering(); verify(mNMService, times(1)).setIpForwardingEnabled(false); + verify(mWifiManager, times(3)).updateInterfaceIpState( + TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_UNSPECIFIED); verifyNoMoreInteractions(mNMService); verifyNoMoreInteractions(mWifiManager); // Asking for the last error after the per-interface state machine @@ -841,6 +853,8 @@ public class TetheringTest { .setInterfaceConfig(eq(TEST_WLAN_IFNAME), any(InterfaceConfiguration.class)); verify(mNetd, times(1)).interfaceSetCfg(argThat(p -> TEST_WLAN_IFNAME.equals(p.ifName))); verify(mNMService, times(1)).tetherInterface(TEST_WLAN_IFNAME); + verify(mWifiManager).updateInterfaceIpState( + TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_UNSPECIFIED); verify(mWifiManager).updateInterfaceIpState( TEST_WLAN_IFNAME, WifiManager.IFACE_IP_MODE_TETHERED); // TODO: Figure out why this isn't exactly once, for sendTetherStateChangedBroadcast().