Loading services/java/com/android/server/WifiService.java +34 −77 Original line number Diff line number Diff line Loading @@ -165,7 +165,6 @@ public class WifiService extends IWifiManager.Stub { * Character buffer used to parse scan results (optimization) */ private static final int SCAN_RESULT_BUFFER_SIZE = 512; private char[] mScanResultBuffer; private boolean mNeedReconfig; /* Loading Loading @@ -204,8 +203,6 @@ public class WifiService extends IWifiManager.Stub { } }; mScanResultBuffer = new char [SCAN_RESULT_BUFFER_SIZE]; HandlerThread wifiThread = new HandlerThread("WifiService"); wifiThread.start(); mWifiHandler = new WifiHandler(wifiThread.getLooper()); Loading Loading @@ -1217,61 +1214,13 @@ public class WifiService extends IWifiManager.Stub { lineBeg = lineEnd + 1; continue; } int lineLen = lineEnd - lineBeg; if (0 < lineLen && lineLen <= SCAN_RESULT_BUFFER_SIZE) { int scanResultLevel = 0; /* * At most one thread should have access to the buffer at a time! */ synchronized(mScanResultBuffer) { boolean parsingScanResultLevel = false; for (int i = lineBeg; i < lineEnd; ++i) { char ch = reply.charAt(i); /* * Assume that the signal level starts with a '-' */ if (ch == '-') { /* * Skip whatever instances of '-' we may have * after we parse the signal level */ parsingScanResultLevel = (scanResultLevel == 0); } else if (parsingScanResultLevel) { int digit = Character.digit(ch, 10); if (0 <= digit) { scanResultLevel = 10 * scanResultLevel + digit; /* * Replace the signal level number in * the string with 0's for caching */ ch = '0'; } else { /* * Reset the flag if we meet a non-digit * character */ parsingScanResultLevel = false; } } mScanResultBuffer[i - lineBeg] = ch; } if (scanResultLevel != 0) { ScanResult scanResult = parseScanResult( new String(mScanResultBuffer, 0, lineLen)); if (lineEnd > lineBeg) { String line = reply.substring(lineBeg, lineEnd); ScanResult scanResult = parseScanResult(line); if (scanResult != null) { scanResult.level = -scanResultLevel; scanList.add(scanResult); } } else if (DBG) { Log.w(TAG, "ScanResult.level=0: misformatted scan result?"); } } } else if (0 < lineLen) { if (DBG) { Log.w(TAG, "Scan result line is too long: " + (lineEnd - lineBeg) + ", skipping the line!"); Log.w(TAG, "misformatted scan result for: " + line); } } lineBeg = lineEnd + 1; Loading @@ -1294,21 +1243,29 @@ public class WifiService extends IWifiManager.Stub { * must synchronized here! */ synchronized (mScanResultCache) { scanResult = mScanResultCache.get(line); if (scanResult == null) { 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 { 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) { frequency = 0; level = 0; } // bssid is the hash key scanResult = mScanResultCache.get(bssid); if (scanResult != null) { scanResult.level = level; } else { /* * The formatting of the results returned by * wpa_supplicant is intended to make the fields Loading Loading @@ -1341,8 +1298,9 @@ public class WifiService extends IWifiManager.Stub { if (0 < ssid.trim().length()) { scanResult = new ScanResult( ssid, result[0], flags, level, frequency); mScanResultCache.put(line, scanResult); ssid, bssid, flags, level, frequency); mScanResultCache.put(bssid, scanResult); } } } else { Log.w(TAG, "Misformatted scan result text with " + Loading @@ -1350,7 +1308,6 @@ public class WifiService extends IWifiManager.Stub { } } } } return scanResult; } Loading Loading
services/java/com/android/server/WifiService.java +34 −77 Original line number Diff line number Diff line Loading @@ -165,7 +165,6 @@ public class WifiService extends IWifiManager.Stub { * Character buffer used to parse scan results (optimization) */ private static final int SCAN_RESULT_BUFFER_SIZE = 512; private char[] mScanResultBuffer; private boolean mNeedReconfig; /* Loading Loading @@ -204,8 +203,6 @@ public class WifiService extends IWifiManager.Stub { } }; mScanResultBuffer = new char [SCAN_RESULT_BUFFER_SIZE]; HandlerThread wifiThread = new HandlerThread("WifiService"); wifiThread.start(); mWifiHandler = new WifiHandler(wifiThread.getLooper()); Loading Loading @@ -1217,61 +1214,13 @@ public class WifiService extends IWifiManager.Stub { lineBeg = lineEnd + 1; continue; } int lineLen = lineEnd - lineBeg; if (0 < lineLen && lineLen <= SCAN_RESULT_BUFFER_SIZE) { int scanResultLevel = 0; /* * At most one thread should have access to the buffer at a time! */ synchronized(mScanResultBuffer) { boolean parsingScanResultLevel = false; for (int i = lineBeg; i < lineEnd; ++i) { char ch = reply.charAt(i); /* * Assume that the signal level starts with a '-' */ if (ch == '-') { /* * Skip whatever instances of '-' we may have * after we parse the signal level */ parsingScanResultLevel = (scanResultLevel == 0); } else if (parsingScanResultLevel) { int digit = Character.digit(ch, 10); if (0 <= digit) { scanResultLevel = 10 * scanResultLevel + digit; /* * Replace the signal level number in * the string with 0's for caching */ ch = '0'; } else { /* * Reset the flag if we meet a non-digit * character */ parsingScanResultLevel = false; } } mScanResultBuffer[i - lineBeg] = ch; } if (scanResultLevel != 0) { ScanResult scanResult = parseScanResult( new String(mScanResultBuffer, 0, lineLen)); if (lineEnd > lineBeg) { String line = reply.substring(lineBeg, lineEnd); ScanResult scanResult = parseScanResult(line); if (scanResult != null) { scanResult.level = -scanResultLevel; scanList.add(scanResult); } } else if (DBG) { Log.w(TAG, "ScanResult.level=0: misformatted scan result?"); } } } else if (0 < lineLen) { if (DBG) { Log.w(TAG, "Scan result line is too long: " + (lineEnd - lineBeg) + ", skipping the line!"); Log.w(TAG, "misformatted scan result for: " + line); } } lineBeg = lineEnd + 1; Loading @@ -1294,21 +1243,29 @@ public class WifiService extends IWifiManager.Stub { * must synchronized here! */ synchronized (mScanResultCache) { scanResult = mScanResultCache.get(line); if (scanResult == null) { 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 { 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) { frequency = 0; level = 0; } // bssid is the hash key scanResult = mScanResultCache.get(bssid); if (scanResult != null) { scanResult.level = level; } else { /* * The formatting of the results returned by * wpa_supplicant is intended to make the fields Loading Loading @@ -1341,8 +1298,9 @@ public class WifiService extends IWifiManager.Stub { if (0 < ssid.trim().length()) { scanResult = new ScanResult( ssid, result[0], flags, level, frequency); mScanResultCache.put(line, scanResult); ssid, bssid, flags, level, frequency); mScanResultCache.put(bssid, scanResult); } } } else { Log.w(TAG, "Misformatted scan result text with " + Loading @@ -1350,7 +1308,6 @@ public class WifiService extends IWifiManager.Stub { } } } } return scanResult; } Loading