From ce5d913387c7fa4792ccb0dd13d79b6636c300a7 Mon Sep 17 00:00:00 2001 From: Christopher Wiley Date: Tue, 13 Sep 2016 12:07:58 -0700 Subject: [PATCH] Allow WiFi components to manage interface up state Setting the WiFi network interface up or down is racy because it is not synchronized with the WiFi components managing the interface. This causes a problem for hostapd when the interface is marked down before hostapd starts because it causes the driver to enter the de-initialization process. hostapd does not know how to react to this change of events. Bug: 31205821 Test: bug no longer reproduces on upcoming devices, unit tests pass Change-Id: I96938e2aef89b400593d42ce1b0a6ccc2d2e5754 --- core/java/android/net/InterfaceConfiguration.java | 8 ++++++++ .../tethering/TetherInterfaceStateMachine.java | 13 ++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/core/java/android/net/InterfaceConfiguration.java b/core/java/android/net/InterfaceConfiguration.java index 8cdd153050183..ea53a71245a5a 100644 --- a/core/java/android/net/InterfaceConfiguration.java +++ b/core/java/android/net/InterfaceConfiguration.java @@ -80,6 +80,14 @@ public class InterfaceConfiguration implements Parcelable { mFlags.add(FLAG_DOWN); } + /** + * Set flags so that no changes will be made to the up/down status. + */ + public void ignoreInterfaceUpDownStatus() { + mFlags.remove(FLAG_UP); + mFlags.remove(FLAG_DOWN); + } + public LinkAddress getLinkAddress() { return mAddr; } diff --git a/services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java b/services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java index 50bb022ef3f04..76ad9d75bb2d5 100644 --- a/services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java +++ b/services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java @@ -136,10 +136,17 @@ public class TetherInterfaceStateMachine extends StateMachine { if (ifcg != null) { InetAddress addr = NetworkUtils.numericToInetAddress(ipAsString); ifcg.setLinkAddress(new LinkAddress(addr, prefixLen)); - if (enabled) { - ifcg.setInterfaceUp(); + if (mInterfaceType == ConnectivityManager.TETHERING_WIFI) { + // The WiFi stack has ownership of the interface up/down state. + // It is unclear whether the bluetooth or USB stacks will manage their own + // state. + ifcg.ignoreInterfaceUpDownStatus(); } else { - ifcg.setInterfaceDown(); + if (enabled) { + ifcg.setInterfaceUp(); + } else { + ifcg.setInterfaceDown(); + } } ifcg.clearFlag("running"); mNMService.setInterfaceConfig(mIfaceName, ifcg);