diff options
author | Mitchell Wills <mwills@google.com> | 2016-05-18 23:17:29 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-05-18 23:17:29 +0000 |
commit | b4cf1c90ec3a5940fb1bed391c1b2e3cad53e830 (patch) | |
tree | 0bcb26b7c91b92751da35854b6c46f9d526b4b45 /tests | |
parent | fcdfc493e30a7c928a0842830469c425745fb950 (diff) | |
parent | 5a09481c2e7c9519ad0dc882b4be0ea2e7e5fcda (diff) |
Merge "Fix crash when scanner gets results that don\'t match the request" into nyc-dev am: bf984686a3 am: a426c873a4
am: 5a09481c2e
* commit '5a09481c2e7c9519ad0dc882b4be0ea2e7e5fcda':
Fix crash when scanner gets results that don't match the request
Change-Id: Ic1d01560bc6f6cc4c385da9450ab709e91431d0a
Diffstat (limited to 'tests')
3 files changed, 61 insertions, 15 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ScanResults.java b/tests/wifitests/src/com/android/server/wifi/ScanResults.java index bc76d0f90..160902081 100644 --- a/tests/wifitests/src/com/android/server/wifi/ScanResults.java +++ b/tests/wifitests/src/com/android/server/wifi/ScanResults.java @@ -37,12 +37,14 @@ import java.util.Random; public class ScanResults { private final ArrayList<ScanDetail> mScanDetails = new ArrayList<>(); private final ScanData mScanData; + private final ScanData mRawScanData; private final ScanResult[] mScanResults; private ScanResults(ArrayList<ScanDetail> scanDetails, ScanData scanData, ScanResult[] scanResults) { mScanDetails.addAll(scanDetails); mScanData = scanData; + mRawScanData = scanData; mScanResults = scanResults; } @@ -127,7 +129,7 @@ public class ScanResults { /** * Create scan results with no IE information. */ - private static ScanDetail[] generateNativeResults(int seed, int... freqs) { + public static ScanDetail[] generateNativeResults(int seed, int... freqs) { return generateNativeResults(true, seed, freqs); } @@ -171,8 +173,9 @@ public class ScanResults { } ScanResult[] sortedScanResults = Arrays.copyOf(mScanResults, mScanResults.length); Arrays.sort(sortedScanResults, SCAN_RESULT_RSSI_COMPARATOR); + mRawScanData = new ScanData(id, 0, sortedScanResults); if (maxResults == -1) { - mScanData = new ScanData(id, 0, sortedScanResults); + mScanData = mRawScanData; } else { ScanResult[] reducedScanResults = Arrays.copyOf(sortedScanResults, Math.min(sortedScanResults.length, maxResults)); @@ -191,4 +194,8 @@ public class ScanResults { public ScanResult[] getRawScanResults() { return mScanResults; } + + public ScanData getRawScanData() { + return mRawScanData; + } } diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/ScanScheduleUtilFilterTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/ScanScheduleUtilFilterTest.java index 3117fd96c..b8e20b5f0 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/ScanScheduleUtilFilterTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/ScanScheduleUtilFilterTest.java @@ -71,7 +71,7 @@ public class ScanScheduleUtilFilterTest { ); assertFalse(ScanScheduleUtil.shouldReportFullScanResultForSettings(mChannelHelper, - createScanResult(5150), 0, settings, -1)); + createScanResult(5150), 0, settings, 0)); } @Test @@ -82,7 +82,7 @@ public class ScanScheduleUtilFilterTest { ); assertTrue(ScanScheduleUtil.shouldReportFullScanResultForSettings(mChannelHelper, - createScanResult(2400), 0, settings, -1)); + createScanResult(2400), 0, settings, 0)); } @Test @@ -93,7 +93,7 @@ public class ScanScheduleUtilFilterTest { ); assertFalse(ScanScheduleUtil.shouldReportFullScanResultForSettings(mChannelHelper, - createScanResult(5175), 0, settings, -1)); + createScanResult(5175), 0, settings, 0)); } @Test @@ -138,11 +138,23 @@ public class ScanScheduleUtilFilterTest { ); ScanData[] results = ScanScheduleUtil.filterResultsForSettings(mChannelHelper, - createScanDatas(new int[][]{ { 2450 } }), settings, -1); + createScanDatas(new int[][]{ { 2450 } }), settings, 0); assertScanDataFreqsEquals(null, results); } @Test + public void filterScanDataSingleNotMatchingWithDefinitlyScannedBucketIndex() { + ScanSettings settings = createRequest( + channelsToSpec(2400, 5150), 30000, 0, 20, + WifiScanner.REPORT_EVENT_FULL_SCAN_RESULT + ); + + ScanData[] results = ScanScheduleUtil.filterResultsForSettings(mChannelHelper, + createScanDatas(new int[][]{ { 2450 } }), settings, -1); + assertScanDataFreqsEquals(new int[][]{ { } }, results); + } + + @Test public void filterScanDataSingleNotMatchingWithBucketDefinitlyScanned() { ScanSettings settings = createRequest( channelsToSpec(2400, 5150), 30000, 0, 20, @@ -162,7 +174,7 @@ public class ScanScheduleUtilFilterTest { ); ScanData[] results = ScanScheduleUtil.filterResultsForSettings(mChannelHelper, - createScanDatas(new int[][]{ { 2400 } }), settings, -1); + createScanDatas(new int[][]{ { 2400 } }), settings, 0); assertScanDataFreqsEquals(new int[][]{ { 2400 } }, results); } @@ -188,7 +200,7 @@ public class ScanScheduleUtilFilterTest { ); ScanData[] results = ScanScheduleUtil.filterResultsForSettings(mChannelHelper, - createScanDatas(new int[][]{ { 2400, 2450, 5150, 5175 } }), settings, -1); + createScanDatas(new int[][]{ { 2400, 2450, 5150, 5175 } }), settings, 0); assertScanDataFreqsEquals(new int[][]{ { 2400, 5150 } }, results); } @@ -201,7 +213,7 @@ public class ScanScheduleUtilFilterTest { ); ScanData[] results = ScanScheduleUtil.filterResultsForSettings(mChannelHelper, - createScanDatas(new int[][]{ { 2450 }, { 2450, 5175 } }), settings, -1); + createScanDatas(new int[][]{ { 2450 }, { 2450, 5175 } }), settings, 0); assertScanDataFreqsEquals(null, results); } @@ -226,7 +238,7 @@ public class ScanScheduleUtilFilterTest { ); ScanData[] results = ScanScheduleUtil.filterResultsForSettings(mChannelHelper, - createScanDatas(new int[][]{ { 2400 }, {2400, 5150} }), settings, -1); + createScanDatas(new int[][]{ { 2400 }, {2400, 5150} }), settings, 0); assertScanDataFreqsEquals(new int[][]{ { 2400 }, {2400, 5150} }, results); } @@ -256,7 +268,7 @@ public class ScanScheduleUtilFilterTest { createScanDatas(new int[][]{ { 2400, 2450, 5150, 5175, 2400 }, { 2400, 2450, 5175 }, - { 5175, 5175, 5150 } }), settings, -1); + { 5175, 5175, 5150 } }), settings, 0); assertScanDataFreqsEquals(new int[][]{ { 2400, 5150, 2400 }, { 2400 }, { 5150 } }, results); } @@ -272,7 +284,7 @@ public class ScanScheduleUtilFilterTest { createScanDatas(new int[][]{ { 2400, 2450, 5150, 5175, 2400 }, { 5175 }, - { 5175, 5175, 5150 } }), settings, -1); + { 5175, 5175, 5150 } }), settings, 0); assertScanDataFreqsEquals(new int[][]{ { 2400, 5150, 2400 }, { 5150 } }, results); } @@ -288,7 +300,7 @@ public class ScanScheduleUtilFilterTest { createScanDatas(new int[][]{ { 2400, 2450, 5150, 5175, 2400, 2400}, { 5175 }, - { 5175, 5175, 5150, 2400, 2400, 5150 } }), settings, -1); + { 5175, 5175, 5150, 2400, 2400, 5150 } }), settings, 0); assertScanDataFreqsEquals(new int[][]{ { 2400, 5150, 2400 }, { 5150, 2400, 2400 } }, results); diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java index 1fb0f951a..c0e0a102e 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java @@ -374,7 +374,7 @@ public class WifiScanningServiceTest { verifySuccessfulResponse(order, handler, requestId); when(mWifiScannerImpl.getLatestSingleScanResults()) - .thenReturn(results.getScanData()); + .thenReturn(results.getRawScanData()); eventHandler.onScanStatus(WifiNative.WIFI_SCAN_RESULTS_AVAILABLE); mLooper.dispatchAll(); @@ -383,7 +383,7 @@ public class WifiScanningServiceTest { verifyNoMoreInteractions(handler); assertDumpContainsRequestLog("addSingleScanRequest", requestId); assertDumpContainsCallbackLog("singleScanResults", requestId, - "results=" + results.getRawScanResults().length); + "results=" + results.getScanData().getResults().length); } /** @@ -409,6 +409,33 @@ public class WifiScanningServiceTest { } /** + * Do a single scan with no results and verify that it is successful. + */ + @Test + public void sendSingleScanRequestWithNoResults() throws Exception { + WifiScanner.ScanSettings requestSettings = createRequest(WifiScanner.WIFI_BAND_BOTH, 0, + 0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN); + doSuccessfulSingleScan(requestSettings, computeSingleScanNativeSettings(requestSettings), + ScanResults.create(0, new int[0])); + } + + /** + * Do a single scan with results that do not match the requested scan and verify that it is + * still successful (and returns no results). + */ + @Test + public void sendSingleScanRequestWithBadRawResults() throws Exception { + WifiScanner.ScanSettings requestSettings = createRequest(WifiScanner.WIFI_BAND_24_GHZ, 0, + 0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN); + // Create a set of scan results that has results not matching the request settings, but is + // limited to zero results for the expected results. + ScanResults results = ScanResults.createOverflowing(0, 0, + ScanResults.generateNativeResults(0, 5150, 5171)); + doSuccessfulSingleScan(requestSettings, computeSingleScanNativeSettings(requestSettings), + results); + } + + /** * Do a single scan, which the hardware fails to start, and verify that a failure response is * delivered. */ |