From e8daf2a7000e12dc0d62cb98b06ca849cf40564a Mon Sep 17 00:00:00 2001 From: Irfan Sheriff Date: Sun, 24 Jul 2011 14:28:15 -0700 Subject: Fix interface notification race In one use case, I see that if we go straight from wifi client mode to tethering operation, the interface change notifications are reported in an order that causes to enter tethered state without actually tethering through connectivity service. It is because an interface down notification (from wifi going down) comes after we have started soft ap and we think we have tethered after calling startTethering and switch to Tethered state Instead, we should make sure tethering has started before going to Tethered state. Change-Id: Iba7e8fab0feeb5637d40938862a8638871df8b02 --- wifi/java/android/net/wifi/WifiStateMachine.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 1e3afbd..98f47f2 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -1055,7 +1055,7 @@ public class WifiStateMachine extends StateMachine { } } - private void startTethering(ArrayList available) { + private boolean startTethering(ArrayList available) { boolean wifiAvailable = false; @@ -1081,18 +1081,20 @@ public class WifiStateMachine extends StateMachine { } catch (Exception e) { Log.e(TAG, "Error configuring interface " + intf + ", :" + e); setWifiApEnabled(null, false); - return; + return false; } if(mCm.tether(intf) != ConnectivityManager.TETHER_ERROR_NO_ERROR) { Log.e(TAG, "Error tethering on " + intf); setWifiApEnabled(null, false); - return; + return false; } - break; + return true; } } } + // We found no interfaces to tether + return false; } private void stopTethering() { @@ -3163,8 +3165,9 @@ public class WifiStateMachine extends StateMachine { break; case CMD_TETHER_INTERFACE: ArrayList available = (ArrayList) message.obj; - startTethering(available); - transitionTo(mTetheredState); + if (startTethering(available)) { + transitionTo(mTetheredState); + } break; default: return NOT_HANDLED; -- cgit v1.1