diff options
author | Ningyuan Wang <nywang@google.com> | 2017-08-03 16:51:00 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-08-03 16:51:00 +0000 |
commit | d8cab05bd605e4255dd6f77293329fbeb65b3249 (patch) | |
tree | 3c0f354c004180e3d09c7edc74490d57d94776aa | |
parent | 184f668983529067537f6265f53700ad6120ecab (diff) | |
parent | 784d5bf21e29baab7c8c5a815897ffc476d6b099 (diff) |
Merge "Dump latest unfiltered scan result" into oc-dr1-dev
am: 784d5bf21e
Change-Id: Ic4996a875179ed615fd8a71bdb3b10b566cbc08b
5 files changed, 86 insertions, 11 deletions
diff --git a/service/java/com/android/server/wifi/scanner/HalWifiScannerImpl.java b/service/java/com/android/server/wifi/scanner/HalWifiScannerImpl.java index 211e62a0d..0fadd804b 100644 --- a/service/java/com/android/server/wifi/scanner/HalWifiScannerImpl.java +++ b/service/java/com/android/server/wifi/scanner/HalWifiScannerImpl.java @@ -27,6 +27,9 @@ import com.android.server.wifi.Clock; import com.android.server.wifi.WifiMonitor; import com.android.server.wifi.WifiNative; +import java.io.FileDescriptor; +import java.io.PrintWriter; + /** * WifiScanner implementation that takes advantage of the gscan HAL API * The gscan API is used to perform background scans and wificond is used for oneshot scans. @@ -151,4 +154,9 @@ public class HalWifiScannerImpl extends WifiScannerImpl implements Handler.Callb return mWificondScannerDelegate.shouldScheduleBackgroundScanForHwPno(); } } + + @Override + protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + mWificondScannerDelegate.dump(fd, pw, args); + } } diff --git a/service/java/com/android/server/wifi/scanner/WifiScannerImpl.java b/service/java/com/android/server/wifi/scanner/WifiScannerImpl.java index e0fb535dd..5281b3abe 100644 --- a/service/java/com/android/server/wifi/scanner/WifiScannerImpl.java +++ b/service/java/com/android/server/wifi/scanner/WifiScannerImpl.java @@ -26,6 +26,8 @@ import com.android.server.wifi.WifiInjector; import com.android.server.wifi.WifiMonitor; import com.android.server.wifi.WifiNative; +import java.io.FileDescriptor; +import java.io.PrintWriter; import java.util.Comparator; /** @@ -158,4 +160,6 @@ public abstract class WifiScannerImpl { * @return true if background scan needs to be started, false otherwise. */ public abstract boolean shouldScheduleBackgroundScanForHwPno(); + + protected abstract void dump(FileDescriptor fd, PrintWriter pw, String[] args); } diff --git a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java index af874b9e2..ab2a5dca3 100644 --- a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java +++ b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java @@ -2156,6 +2156,9 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { } pw.println(); } + if (mScannerImpl != null) { + mScannerImpl.dump(fd, pw, args); + } } void logScanRequest(String request, ClientInfo ci, int id, WorkSource workSource, diff --git a/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java b/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java index fd7fddb73..84105ee61 100644 --- a/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java +++ b/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java @@ -32,6 +32,8 @@ import com.android.server.wifi.WifiMonitor; import com.android.server.wifi.WifiNative; import com.android.server.wifi.scanner.ChannelHelper.ChannelCollection; +import java.io.FileDescriptor; +import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; @@ -81,6 +83,7 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call private boolean mBackgroundScanPaused = false; private ScanBuffer mBackgroundScanBuffer = new ScanBuffer(SCAN_BUFFER_CAPACITY); + private ArrayList<ScanDetail> mNativeScanResults; private WifiScanner.ScanData mLatestSingleScanResult = new WifiScanner.ScanData(0, 0, new ScanResult[0]); @@ -535,11 +538,11 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call // got a scan before we started scanning or after scan was canceled return; } - ArrayList<ScanDetail> nativeResults = mWifiNative.getScanResults(); + mNativeScanResults = mWifiNative.getScanResults(); List<ScanResult> hwPnoScanResults = new ArrayList<>(); int numFilteredScanResults = 0; - for (int i = 0; i < nativeResults.size(); ++i) { - ScanResult result = nativeResults.get(i).getScanResult(); + for (int i = 0; i < mNativeScanResults.size(); ++i) { + ScanResult result = mNativeScanResults.get(i).getScanResult(); long timestamp_ms = result.timestamp / 1000; // convert us -> ms if (timestamp_ms > mLastScanSettings.startTime) { if (mLastScanSettings.hwPnoScanActive) { @@ -556,11 +559,8 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call if (mLastScanSettings.hwPnoScanActive && mLastScanSettings.pnoScanEventHandler != null) { - ScanResult[] pnoScanResultsArray = new ScanResult[hwPnoScanResults.size()]; - for (int i = 0; i < pnoScanResultsArray.length; ++i) { - ScanResult result = nativeResults.get(i).getScanResult(); - pnoScanResultsArray[i] = hwPnoScanResults.get(i); - } + ScanResult[] pnoScanResultsArray = + hwPnoScanResults.toArray(new ScanResult[hwPnoScanResults.size()]); mLastScanSettings.pnoScanEventHandler.onPnoNetworkFound(pnoScanResultsArray); } // On pno scan result event, we are expecting a mLastScanSettings for pno scan. @@ -598,12 +598,12 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call } if (DBG) Log.d(TAG, "Polling scan data for scan: " + mLastScanSettings.scanId); - ArrayList<ScanDetail> nativeResults = mWifiNative.getScanResults(); + mNativeScanResults = mWifiNative.getScanResults(); List<ScanResult> singleScanResults = new ArrayList<>(); List<ScanResult> backgroundScanResults = new ArrayList<>(); int numFilteredScanResults = 0; - for (int i = 0; i < nativeResults.size(); ++i) { - ScanResult result = nativeResults.get(i).getScanResult(); + for (int i = 0; i < mNativeScanResults.size(); ++i) { + ScanResult result = mNativeScanResults.get(i).getScanResult(); long timestamp_ms = result.timestamp / 1000; // convert us -> ms if (timestamp_ms > mLastScanSettings.startTime) { if (mLastScanSettings.backgroundScanActive) { @@ -772,6 +772,40 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call return false; } + @Override + protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + synchronized (mSettingsLock) { + pw.println("Latest native scan results:"); + if (mNativeScanResults != null && mNativeScanResults.size() != 0) { + long nowMs = mClock.getElapsedSinceBootMillis(); + pw.println(" BSSID Frequency RSSI Age(sec) SSID " + + " Flags"); + for (ScanDetail scanDetail : mNativeScanResults) { + ScanResult r = scanDetail.getScanResult(); + long timeStampMs = r.timestamp / 1000; + String age; + if (timeStampMs <= 0) { + age = "___?___"; + } else if (nowMs < timeStampMs) { + age = " 0.000"; + } else if (timeStampMs < nowMs - 1000000) { + age = ">1000.0"; + } else { + age = String.format("%3.3f", (nowMs - timeStampMs) / 1000.0); + } + String ssid = r.SSID == null ? "" : r.SSID; + pw.printf(" %17s %9d %5d %7s %-32s %s\n", + r.BSSID, + r.frequency, + r.level, + age, + String.format("%1.32s", ssid), + r.capabilities); + } + } + } + } + private static class LastScanSettings { public long startTime; diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WificondScannerTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WificondScannerTest.java index 3a5f6b973..ed7c58298 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WificondScannerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WificondScannerTest.java @@ -37,8 +37,12 @@ import org.junit.Before; import org.junit.Test; import org.mockito.InOrder; +import java.io.FileDescriptor; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; import java.util.Set; +import java.util.regex.Pattern; /** * Unit tests for {@link com.android.server.wifi.scanner.WificondScannerImpl}. @@ -554,6 +558,28 @@ public class WificondScannerTest extends BaseWifiScannerImplTest { } /** + * Test that dump() of WificondScannerImpl dumps native scan results. + */ + @Test + public void dumpContainsNativeScanResults() { + assertDumpContainsRequestLog("Latest native scan results:"); + } + + private void assertDumpContainsRequestLog(String log) { + String objectDump = dumpObject(); + Pattern logLineRegex = Pattern.compile(".*" + log + ".*"); + assertTrue("dump did not contain log = " + log + "\n " + objectDump + "\n", + logLineRegex.matcher(objectDump).find()); + } + + private String dumpObject() { + StringWriter stringWriter = new StringWriter(); + mScanner.dump(new FileDescriptor(), new PrintWriter(stringWriter), + new String[0]); + return stringWriter.toString(); + } + + /** * Run a test with the given settings where all native scans succeed * This will execute expectedPeriods.length scan periods by first * starting the scan settings and then dispatching the scan period alarm to start the |