diff options
-rw-r--r-- | service/java/com/android/server/wifi/ScanRequestProxy.java | 3 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java | 15 |
2 files changed, 17 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/ScanRequestProxy.java b/service/java/com/android/server/wifi/ScanRequestProxy.java index c054b90a4..622fcdab9 100644 --- a/service/java/com/android/server/wifi/ScanRequestProxy.java +++ b/service/java/com/android/server/wifi/ScanRequestProxy.java @@ -464,7 +464,8 @@ public class ScanRequestProxy { * @return the list of results */ public List<ScanResult> getScanResults() { - return mLastScanResults; + // return a copy to prevent external modification + return new ArrayList<>(mLastScanResults); } /** 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<ScanResult> scanResults = mScanRequestProxy.getScanResults(); + int scanResultsOriginalSize = scanResults.size(); + + scanResults.add(new ScanResult()); + assertThat(mScanRequestProxy.getScanResults()).hasSize(scanResultsOriginalSize); } } |