From c4713c9006b236bf1c7d0bf82b50bfb6b1eb53b6 Mon Sep 17 00:00:00 2001 From: David Su Date: Wed, 8 Jul 2020 12:57:54 -0700 Subject: ScanRequestProxy: Return copy of list in getScanResults Return a copy of internal list to prevent external modification. Bug: 160751554 Test: atest FrameworksWifiTests Change-Id: Id7f8c05160d0d480077327d56dec03080708b375 Merged-In: Id7f8c05160d0d480077327d56dec03080708b375 (cherry picked from commit 48e1bcfb68371999d968c4527791d302be3140b4) --- .../src/com/android/server/wifi/ScanRequestProxyTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java index b065f823c..cc96602d5 100644 --- a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java @@ -22,6 +22,8 @@ import static com.android.server.wifi.ScanRequestProxy.SCAN_REQUEST_THROTTLE_MAX import static com.android.server.wifi.ScanRequestProxy.SCAN_REQUEST_THROTTLE_TIME_WINDOW_FG_APPS_MS; import static com.android.server.wifi.WifiSettingsConfigStore.WIFI_SCAN_THROTTLE_ENABLED; +import static com.google.common.truth.Truth.assertThat; + import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -1009,6 +1011,19 @@ public class ScanRequestProxyTest extends WifiBaseTest { mLooper.dispatchAll(); validateScanResultsAvailableBroadcastSent(true); verify(mScanResultsCallback, never()).onScanResultsAvailable(); + } + + /** Test that modifying the returned scan results list does not change the original. */ + @Test + public void testGetScanResults_modifyReturnedList_doesNotChangeOriginal() { + // initialize scan results + testStartScanSuccess(); + + List scanResults = mScanRequestProxy.getScanResults(); + int scanResultsOriginalSize = scanResults.size(); + + scanResults.add(new ScanResult()); + assertThat(mScanRequestProxy.getScanResults()).hasSize(scanResultsOriginalSize); } } -- cgit v1.2.3