diff options
author | Iliyan Malchev <malchev@google.com> | 2012-08-14 11:11:49 -0700 |
---|---|---|
committer | Iliyan Malchev <malchev@google.com> | 2012-08-14 11:17:21 -0700 |
commit | 578531082b8e8c8aa03868e69591b7613b0e8b8e (patch) | |
tree | 3a3454f3792d4305158bf75b961326164e438923 /wifi | |
parent | 73025eda13e19672534974efa06d1e2313bceb30 (diff) | |
download | frameworks_base-578531082b8e8c8aa03868e69591b7613b0e8b8e.zip frameworks_base-578531082b8e8c8aa03868e69591b7613b0e8b8e.tar.gz frameworks_base-578531082b8e8c8aa03868e69591b7613b0e8b8e.tar.bz2 |
Revert "Add timestamp in scan results"
Temporarily reverting this until all devices switch to using wpa_supplicant_8.
This reverts commit b31f78f93768fef269617ec788a5c6655a375f80.
Change-Id: I33fcb8415288d95289dcd46fa71e950e0f2b87ec
Signed-off-by: Iliyan Malchev <malchev@google.com>
Diffstat (limited to 'wifi')
-rw-r--r-- | wifi/java/android/net/wifi/ScanResult.java | 30 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiNative.java | 16 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 198 |
3 files changed, 115 insertions, 129 deletions
diff --git a/wifi/java/android/net/wifi/ScanResult.java b/wifi/java/android/net/wifi/ScanResult.java index 3e20756..32261de 100644 --- a/wifi/java/android/net/wifi/ScanResult.java +++ b/wifi/java/android/net/wifi/ScanResult.java @@ -47,37 +47,19 @@ public class ScanResult implements Parcelable { public int frequency; /** - * Time Synchronization Function (tsf) timestamp in microseconds when - * this result was last seen. - */ - public long timestamp; - - /** * We'd like to obtain the following attributes, * but they are not reported via the socket * interface, even though they are known * internally by wpa_supplicant. * {@hide} */ - public ScanResult(String SSID, String BSSID, String caps, int level, int frequency, long tsf) { + public ScanResult(String SSID, String BSSID, String caps, int level, int frequency) { this.SSID = SSID; this.BSSID = BSSID; this.capabilities = caps; this.level = level; this.frequency = frequency; - this.timestamp = tsf; - } - - /** copy constructor {@hide} */ - public ScanResult(ScanResult source) { - if (source != null) { - SSID = source.SSID; - BSSID = source.BSSID; - capabilities = source.capabilities; - level = source.level; - frequency = source.frequency; - timestamp = source.timestamp; - } + //networkConfig = null; } @Override @@ -94,9 +76,7 @@ public class ScanResult implements Parcelable { append(", level: "). append(level). append(", frequency: "). - append(frequency). - append(", timestamp: "). - append(timestamp); + append(frequency); return sb.toString(); } @@ -113,7 +93,6 @@ public class ScanResult implements Parcelable { dest.writeString(capabilities); dest.writeInt(level); dest.writeInt(frequency); - dest.writeLong(timestamp); } /** Implement the Parcelable interface {@hide} */ @@ -125,8 +104,7 @@ public class ScanResult implements Parcelable { in.readString(), in.readString(), in.readInt(), - in.readInt(), - in.readLong() + in.readInt() ); } diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index 1b7e378..84c565b 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -197,22 +197,8 @@ public class WifiNative { return null; } - /** - * Format of results: - * ================= - * bssid=68:7f:74:d7:1b:6e - * freq=2412 - * level=-43 - * tsf=1344621975160944 - * age=2623 - * flags=[WPA2-PSK-CCMP][WPS][ESS] - * ssid=zubyb - * - * RANGE=ALL gets all scan results - * MASK=<N> see wpa_supplicant/src/common/wpa_ctrl.h for details - */ public String scanResults() { - return doStringCommand("BSS RANGE=ALL MASK=0x1986"); + return doStringCommand("SCAN_RESULTS"); } public boolean startDriver() { diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index bdb02c5..28c1c5c 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -891,13 +891,7 @@ public class WifiStateMachine extends StateMachine { * TODO: doc */ public List<ScanResult> syncGetScanResultsList() { - synchronized (mScanResultCache) { - List<ScanResult> scanList = new ArrayList<ScanResult>(); - for(ScanResult result: mScanResults) { - scanList.add(new ScanResult(result)); - } - return scanList; - } + return mScanResults; } /** @@ -1363,103 +1357,131 @@ public class WifiStateMachine extends StateMachine { mContext.sendStickyBroadcast(intent); } - private static final String BSSID_STR = "bssid="; - private static final String FREQ_STR = "freq="; - private static final String LEVEL_STR = "level="; - private static final String TSF_STR = "tsf="; - private static final String FLAGS_STR = "flags="; - private static final String SSID_STR = "ssid="; - private static final String DELIMITER_STR = "===="; /** - * Format: - * bssid=68:7f:76:d7:1a:6e - * freq=2412 - * level=-44 - * tsf=1344626243700342 - * flags=[WPA2-PSK-CCMP][WPS][ESS] - * ssid=zfdy - * ==== - * bssid=68:5f:74:d7:1a:6f - * freq=5180 - * level=-73 - * tsf=1344626243700373 - * flags=[WPA2-PSK-CCMP][WPS][ESS] - * ssid=zuby - * ==== + * Parse the scan result line passed to us by wpa_supplicant (helper). + * @param line the line to parse + * @return the {@link ScanResult} object */ - private void setScanResults(String scanResults) { - String bssid = ""; - int level = 0; - int freq = 0; - long tsf = 0; - String flags = ""; - String ssid = ""; - - if (scanResults == null) { - return; - } - - synchronized(mScanResultCache) { - mScanResults = new ArrayList<ScanResult>(); - String[] lines = scanResults.split("\n"); - - for (String line : lines) { - if (line.startsWith(BSSID_STR)) { - bssid = line.substring(BSSID_STR.length()); - } else if (line.startsWith(FREQ_STR)) { - try { - freq = Integer.parseInt(line.substring(FREQ_STR.length())); - } catch (NumberFormatException e) { - freq = 0; - } - } else if (line.startsWith(LEVEL_STR)) { + private ScanResult parseScanResult(String line) { + ScanResult scanResult = null; + if (line != null) { + /* + * Cache implementation (LinkedHashMap) is not synchronized, thus, + * must synchronized here! + */ + synchronized (mScanResultCache) { + String[] result = scanResultPattern.split(line); + if (3 <= result.length && result.length <= 5) { + String bssid = result[0]; + // bssid | frequency | level | flags | ssid + int frequency; + int level; try { - level = Integer.parseInt(line.substring(LEVEL_STR.length())); + frequency = Integer.parseInt(result[1]); + level = Integer.parseInt(result[2]); /* some implementations avoid negative values by adding 256 * so we need to adjust for that here. */ if (level > 0) level -= 256; - } catch(NumberFormatException e) { + } catch (NumberFormatException e) { + frequency = 0; level = 0; } - } else if (line.startsWith(TSF_STR)) { - try { - tsf = Long.parseLong(line.substring(TSF_STR.length())); - } catch (NumberFormatException e) { - tsf = 0; - } - } else if (line.startsWith(FLAGS_STR)) { - flags = line.substring(FLAGS_STR.length()); - } else if (line.startsWith(SSID_STR)) { - ssid = line.substring(SSID_STR.length()); - if (ssid == null) ssid = ""; - } else if (line.startsWith(DELIMITER_STR)) { - if (bssid != null) { - String key = bssid + ssid; - ScanResult scanResult = mScanResultCache.get(key); - if (scanResult != null) { - scanResult.level = level; - scanResult.SSID = ssid; - scanResult.capabilities = flags; - scanResult.frequency = freq; - scanResult.timestamp = tsf; + + /* + * The formatting of the results returned by + * wpa_supplicant is intended to make the fields + * line up nicely when printed, + * not to make them easy to parse. So we have to + * apply some heuristics to figure out which field + * is the SSID and which field is the flags. + */ + String ssid; + String flags; + if (result.length == 4) { + if (result[3].charAt(0) == '[') { + flags = result[3]; + ssid = ""; } else { + flags = ""; + ssid = result[3]; + } + } else if (result.length == 5) { + flags = result[3]; + ssid = result[4]; + } else { + // Here, we must have 3 fields: no flags and ssid + // set + flags = ""; + ssid = ""; + } + + // bssid + ssid is the hash key + String key = bssid + ssid; + scanResult = mScanResultCache.get(key); + if (scanResult != null) { + scanResult.level = level; + scanResult.SSID = ssid; + scanResult.capabilities = flags; + scanResult.frequency = frequency; + } else { + // Do not add scan results that have no SSID set + if (0 < ssid.trim().length()) { scanResult = new ScanResult( - ssid, bssid, flags, level, freq, tsf); + ssid, bssid, flags, level, frequency); mScanResultCache.put(key, scanResult); } - mScanResults.add(scanResult); - } - bssid = null; - level = 0; - freq = 0; - tsf = 0; - flags = ""; - ssid = ""; + } + } else { + loge("Misformatted scan result text with " + + result.length + " fields: " + line); + } + } + } + + return scanResult; + } + + /** + * scanResults input format + * 00:bb:cc:dd:cc:ee 2427 166 [WPA-EAP-TKIP][WPA2-EAP-CCMP] Net1 + * 00:bb:cc:dd:cc:ff 2412 165 [WPA-EAP-TKIP][WPA2-EAP-CCMP] Net2 + */ + private void setScanResults(String scanResults) { + if (scanResults == null) { + return; + } + + List<ScanResult> scanList = new ArrayList<ScanResult>(); + + int lineCount = 0; + + int scanResultsLen = scanResults.length(); + // Parse the result string, keeping in mind that the last line does + // not end with a newline. + for (int lineBeg = 0, lineEnd = 0; lineEnd <= scanResultsLen; ++lineEnd) { + if (lineEnd == scanResultsLen || scanResults.charAt(lineEnd) == '\n') { + ++lineCount; + + if (lineCount == 1) { + lineBeg = lineEnd + 1; + continue; } + if (lineEnd > lineBeg) { + String line = scanResults.substring(lineBeg, lineEnd); + ScanResult scanResult = parseScanResult(line); + if (scanResult != null) { + scanList.add(scanResult); + } else { + //TODO: hidden network handling + } + } + lineBeg = lineEnd + 1; } } + + mScanResults = scanList; } /* @@ -2805,7 +2827,7 @@ public class WifiStateMachine extends StateMachine { if (DBG) log(getName() + "\n"); mIsRunning = false; updateBatteryWorkSource(null); - mScanResults = new ArrayList<ScanResult>(); + mScanResults = null; if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P); mContext.unregisterReceiver(mScreenReceiver); |