diff options
-rw-r--r-- | service/java/com/android/server/wifi/WifiStateMachine.java | 4 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index b2a649cea..2d24d2002 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -3139,11 +3139,11 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss } private WifiInfo getWiFiInfoForUid(int uid) { + WifiInfo result = new WifiInfo(mWifiInfo); if (Binder.getCallingUid() == Process.myUid()) { - return mWifiInfo; + return result; } - WifiInfo result = new WifiInfo(mWifiInfo); result.setMacAddress(WifiInfo.DEFAULT_MAC_ADDRESS); IBinder binder = mFacade.getService("package"); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 427d700b1..4dd0621bd 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -2141,4 +2141,20 @@ public class WifiStateMachineTest { currentConfig.networkId = lastSelectedNetworkId - 1; assertFalse(mWsm.shouldEvaluateWhetherToSendExplicitlySelected(currentConfig)); } + + /** + * Test that {@link WifiStateMachine#syncRequestConnectionInfo()} always returns a copy of + * WifiInfo. + */ + @Test + public void testSyncRequestConnectionInfoDoesNotReturnLocalReference() { + WifiInfo wifiInfo = mWsm.getWifiInfo(); + wifiInfo.setBSSID(sBSSID); + wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(sSSID)); + + WifiInfo syncWifiInfo = mWsm.syncRequestConnectionInfo(); + assertEquals(wifiInfo.getSSID(), syncWifiInfo.getSSID()); + assertEquals(wifiInfo.getBSSID(), syncWifiInfo.getBSSID()); + assertFalse(wifiInfo == syncWifiInfo); + } } |