From 67b3fbf49c0c92641e19e3278a1feab7b68aa7b8 Mon Sep 17 00:00:00 2001 From: Dmitry Shmidt Date: Tue, 26 Feb 2013 14:47:16 -0800 Subject: wifi: Get full scan results BUG: 8236341 Change-Id: Ic0b769eed6bfcdc12644bf461060d3e42ab18e86 Signed-off-by: Dmitry Shmidt --- wifi/java/android/net/wifi/WifiNative.java | 6 ++-- wifi/java/android/net/wifi/WifiStateMachine.java | 40 +++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) (limited to 'wifi') diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index 59f1889..9e77b8c 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -202,6 +202,7 @@ public class WifiNative { /** * Format of results: * ================= + * id=1 * bssid=68:7f:74:d7:1b:6e * freq=2412 * level=-43 @@ -211,10 +212,11 @@ public class WifiNative { * ssid=zubyb * * RANGE=ALL gets all scan results + * RANGE=ID- gets results from ID * MASK= see wpa_supplicant/src/common/wpa_ctrl.h for details */ - public String scanResults() { - return doStringCommand("BSS RANGE=ALL MASK=0x1986"); + public String scanResults(int sid) { + return doStringCommand("BSS RANGE=" + sid + "- MASK=0x1987"); } public boolean startDriver() { diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 7da4caa..b3ada43 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -72,6 +72,7 @@ import android.os.WorkSource; import android.provider.Settings; import android.util.Log; import android.util.LruCache; +import android.text.TextUtils; import com.android.internal.R; import com.android.internal.app.IBatteryStats; @@ -1369,6 +1370,7 @@ public class WifiStateMachine extends StateMachine { mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } + private static final String ID_STR = "id="; private static final String BSSID_STR = "bssid="; private static final String FREQ_STR = "freq="; private static final String LEVEL_STR = "level="; @@ -1376,8 +1378,12 @@ public class WifiStateMachine extends StateMachine { private static final String FLAGS_STR = "flags="; private static final String SSID_STR = "ssid="; private static final String DELIMITER_STR = "===="; + private static final int SCAN_BUF_RANGE = 3900; + /** * Format: + * + * id=1 * bssid=68:7f:76:d7:1a:6e * freq=2412 * level=-44 @@ -1385,6 +1391,7 @@ public class WifiStateMachine extends StateMachine { * flags=[WPA2-PSK-CCMP][WPS][ESS] * ssid=zfdy * ==== + * id=2 * bssid=68:5f:74:d7:1a:6f * freq=5180 * level=-73 @@ -1393,16 +1400,41 @@ public class WifiStateMachine extends StateMachine { * ssid=zuby * ==== */ - private void setScanResults(String scanResults) { + private void setScanResults() { String bssid = ""; int level = 0; int freq = 0; long tsf = 0; String flags = ""; WifiSsid wifiSsid = null; + String scanResults; + String tmpResults; + StringBuffer scanResultsBuf = new StringBuffer(); + int sid = 0; + + while (true) { + tmpResults = mWifiNative.scanResults(sid); + if (TextUtils.isEmpty(tmpResults)) break; + scanResultsBuf.append(tmpResults); + if (tmpResults.length() < SCAN_BUF_RANGE) break; + String[] lines = tmpResults.split("\n"); + sid = -1; + for (int i=lines.length - 1; i >= 0; i--) { + if (lines[i].startsWith(ID_STR)) { + try { + sid = Integer.parseInt(lines[i].substring(ID_STR.length())) + 1; + } catch (NumberFormatException e) { + // Nothing to do + } + break; + } + } + if (sid == -1) break; + } - if (scanResults == null) { - return; + scanResults = scanResultsBuf.toString(); + if (TextUtils.isEmpty(scanResults)) { + return; } synchronized(mScanResultCache) { @@ -2407,7 +2439,7 @@ public class WifiStateMachine extends StateMachine { sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS); break; case WifiMonitor.SCAN_RESULTS_EVENT: - setScanResults(mWifiNative.scanResults()); + setScanResults(); sendScanResultsAvailableBroadcast(); mScanResultIsPending = false; break; -- cgit v1.1