diff options
author | 2020-03-18 20:28:34 +0000 | |
---|---|---|
committer | 2020-03-18 20:28:34 +0000 | |
commit | 9663a531e161277c91f43d15e5b56b73f68bb7cf (patch) | |
tree | 6e57188aaf3905f1784d78e4835305f7883e4f9c | |
parent | 8bb60d66e3cabaf05948dfdb7730f592d1293a2f (diff) | |
parent | c050bb41b04b6d49c53ff6115801f9adf780675c (diff) |
Merge "Fix crash when remove network" into rvc-dev
-rw-r--r-- | service/java/com/android/server/wifi/WifiConnectivityManager.java | 7 | ||||
-rw-r--r-- | service/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java | 44 |
2 files changed, 50 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index ea876d73a9..31fcfca28f 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -1510,6 +1510,11 @@ public class WifiConnectivityManager { * 2. The device is connected to that network. */ private boolean useSingleSavedNetworkSchedule() { + WifiConfiguration currentNetwork = mStateMachine.getCurrentWifiConfiguration(); + if (currentNetwork == null) { + localLog("Current network is missing, may caused by remove network and disconnecting "); + return false; + } List<WifiConfiguration> savedNetworks = mConfigManager.getSavedNetworks(Process.WIFI_UID); // If we have multiple saved networks, then no need to proceed @@ -1532,7 +1537,7 @@ public class WifiConnectivityManager { } // Next verify that this network is the one device is connected to - int currentNetworkId = mStateMachine.getCurrentWifiConfiguration().networkId; + int currentNetworkId = currentNetwork.networkId; // If we have a single saved network, and we are connected to it, return true. if (savedNetworks.size() == 1) { diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 616cd7d069..028bf024d2 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -1563,6 +1563,50 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { } /** + * Remove network will trigger update scan and meet single network requirement. + * Verify before disconnect finished, will not trigger single network scan schedule. + */ + @Test + public void checkScanScheduleForCurrentConnectedNetworkIsNull() { + long currentTimeStamp = CURRENT_SYSTEM_TIME_MS; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + + // Set screen to ON + mWifiConnectivityManager.handleScreenStateChanged(true); + + // Wait for max scanning interval so that any impact triggered + // by screen state change can settle + currentTimeStamp += MAX_SCAN_INTERVAL_IN_SCHEDULE_SEC * 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + + mResources.setIntArray( + R.array.config_wifiSingleSavedNetworkConnectedScanIntervalScheduleSec, + VALID_CONNECTED_SINGLE_SAVED_NETWORK_SCHEDULE_SEC); + + // Set firmware roaming to enabled + when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(true); + + // Set up single saved network + WifiConfiguration wifiConfiguration = new WifiConfiguration(); + wifiConfiguration.networkId = TEST_CONNECTED_NETWORK_ID; + List<WifiConfiguration> wifiConfigurationList = new ArrayList<WifiConfiguration>(); + wifiConfigurationList.add(wifiConfiguration); + when(mWifiConfigManager.getSavedNetworks(anyInt())).thenReturn(wifiConfigurationList); + + // Set WiFi to connected state. + setWifiStateConnected(); + // Simulate remove network, disconnect not finished. + when(mClientModeImpl.getCurrentWifiConfiguration()).thenReturn(null); + mNetworkUpdateListenerCaptor.getValue().onNetworkRemoved(null); + + // Get the first periodic scan interval + long firstIntervalMs = mAlarmManager + .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG) + - currentTimeStamp; + assertEquals(VALID_CONNECTED_SINGLE_SCAN_SCHEDULE_SEC[0] * 1000, firstIntervalMs); + } + + /** * When screen on trigger a disconnected state change event then a connected state * change event back to back to verify that the minium scan interval is enforced. * |