diff options
author | Vinit Deshapnde <vinitd@google.com> | 2013-08-30 19:48:12 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-08-30 19:48:13 +0000 |
commit | 90b9180580128b337b76a5de72d8f76646ec5aec (patch) | |
tree | d1eb7baaa85fab79e67d61f3be34cc63fc111790 | |
parent | 7ef3bfec0aa171460d0c0a1072a887a1ce830206 (diff) | |
parent | fab5c2b28ede33879372e559f14648a83da8252e (diff) | |
download | frameworks_base-90b9180580128b337b76a5de72d8f76646ec5aec.zip frameworks_base-90b9180580128b337b76a5de72d8f76646ec5aec.tar.gz frameworks_base-90b9180580128b337b76a5de72d8f76646ec5aec.tar.bz2 |
Merge "Synchronize access to single supplicant path" into klp-dev
-rw-r--r-- | wifi/java/android/net/wifi/WifiNative.java | 97 |
1 files changed, 61 insertions, 36 deletions
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index 53c00d8..f86a51c9 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -48,6 +48,10 @@ public class WifiNative { static final int SCAN_WITHOUT_CONNECTION_SETUP = 1; static final int SCAN_WITH_CONNECTION_SETUP = 2; + // Hold this lock before calling supplicant - it is required to + // mutually exclude access from Wifi and P2p state machines + static final Object mLock = new Object(); + public final String mInterfaceName; public final String mInterfacePrefix; @@ -92,18 +96,17 @@ public class WifiNative { } } - private static final LocalLog mLocalLog = new LocalLog(1024); + + // hold mLock before accessing mCmdIdLock private int mCmdId; public LocalLog getLocalLog() { return mLocalLog; } - private int getNewCmdId() { - synchronized (mLocalLog) { - return mCmdId++; - } + private int getNewCmdIdLocked() { + return mCmdId++; } private void localLog(String s) { @@ -112,6 +115,7 @@ public class WifiNative { } public boolean connectToSupplicant() { + // No synchronization necessary .. it is implemented in WifiMonitor localLog(mInterfacePrefix + "connectToSupplicant"); return connectToSupplicantNative(); } @@ -122,39 +126,48 @@ public class WifiNative { } public String waitForEvent() { + // No synchronization necessary .. it is implemented in WifiMonitor return waitForEventNative(); } private boolean doBooleanCommand(String command) { if (DBG) Log.d(mTAG, "doBoolean: " + command); - int cmdId = getNewCmdId(); - localLog(cmdId + "->" + mInterfacePrefix + command); - boolean result = doBooleanCommandNative(mInterfacePrefix + command); - localLog(cmdId + "<-" + result); - return result; + synchronized (mLock) { + int cmdId = getNewCmdIdLocked(); + localLog(cmdId + "->" + mInterfacePrefix + command); + boolean result = doBooleanCommandNative(mInterfacePrefix + command); + localLog(cmdId + "<-" + result); + return result; + } } private int doIntCommand(String command) { if (DBG) Log.d(mTAG, "doInt: " + command); - int cmdId = getNewCmdId(); - localLog(cmdId + "->" + mInterfacePrefix + command); - int result = doIntCommandNative(mInterfacePrefix + command); - localLog(cmdId + "<-" + result); - return result; + synchronized (mLock) { + int cmdId = getNewCmdIdLocked(); + localLog(cmdId + "->" + mInterfacePrefix + command); + int result = doIntCommandNative(mInterfacePrefix + command); + localLog(cmdId + "<-" + result); + return result; + } } private String doStringCommand(String command) { if (DBG) Log.d(mTAG, "doString: " + command); - int cmdId = getNewCmdId(); - localLog(cmdId + "->" + mInterfacePrefix + command); - String result = doStringCommandNative(mInterfacePrefix + command); - localLog(cmdId + "<-" + result); - return result; + synchronized (mLock) { + int cmdId = getNewCmdIdLocked(); + localLog(cmdId + "->" + mInterfacePrefix + command); + String result = doStringCommandNative(mInterfacePrefix + command); + localLog(cmdId + "<-" + result); + return result; + } } private String doStringCommandWithoutLogging(String command) { if (DBG) Log.d(mTAG, "doString: " + command); - return doStringCommandNative(mInterfacePrefix + command); + synchronized (mLock) { + return doStringCommandNative(mInterfacePrefix + command); + } } public boolean ping() { @@ -499,10 +512,12 @@ public class WifiNative { } public boolean startWpsPbc(String iface, String bssid) { - if (TextUtils.isEmpty(bssid)) { - return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC"); - } else { - return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC " + bssid); + synchronized (mLock) { + if (TextUtils.isEmpty(bssid)) { + return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC"); + } else { + return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC " + bssid); + } } } @@ -513,7 +528,9 @@ public class WifiNative { public boolean startWpsPinKeypad(String iface, String pin) { if (TextUtils.isEmpty(pin)) return false; - return doBooleanCommandNative("IFNAME=" + iface + " WPS_PIN any " + pin); + synchronized (mLock) { + return doBooleanCommandNative("IFNAME=" + iface + " WPS_PIN any " + pin); + } } @@ -526,10 +543,12 @@ public class WifiNative { } public String startWpsPinDisplay(String iface, String bssid) { - if (TextUtils.isEmpty(bssid)) { - return doStringCommandNative("IFNAME=" + iface + " WPS_PIN any"); - } else { - return doStringCommandNative("IFNAME=" + iface + " WPS_PIN " + bssid); + synchronized (mLock) { + if (TextUtils.isEmpty(bssid)) { + return doStringCommandNative("IFNAME=" + iface + " WPS_PIN any"); + } else { + return doStringCommandNative("IFNAME=" + iface + " WPS_PIN " + bssid); + } } } @@ -581,7 +600,9 @@ public class WifiNative { } public boolean setP2pGroupIdle(String iface, int time) { - return doBooleanCommandNative("IFNAME=" + iface + " SET p2p_group_idle " + time); + synchronized (mLock) { + return doBooleanCommandNative("IFNAME=" + iface + " SET p2p_group_idle " + time); + } } public void setPowerSave(boolean enabled) { @@ -593,10 +614,12 @@ public class WifiNative { } public boolean setP2pPowerSave(String iface, boolean enabled) { - if (enabled) { - return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 1"); - } else { - return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 0"); + synchronized (mLock) { + if (enabled) { + return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 1"); + } else { + return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 0"); + } } } @@ -765,7 +788,9 @@ public class WifiNative { public boolean p2pGroupRemove(String iface) { if (TextUtils.isEmpty(iface)) return false; - return doBooleanCommandNative("IFNAME=" + iface + " P2P_GROUP_REMOVE " + iface); + synchronized (mLock) { + return doBooleanCommandNative("IFNAME=" + iface + " P2P_GROUP_REMOVE " + iface); + } } public boolean p2pReject(String deviceAddress) { |