diff options
author | Nate Jiang <qiangjiang@google.com> | 2020-03-18 20:28:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-03-18 20:28:34 +0000 |
commit | 06610231a412585e265e297afa7a11619b7d0fa0 (patch) | |
tree | cc731c261029e2329789482598cee0630891f655 | |
parent | 69990a626e4aa4175ceeecd662564593bebb5c31 (diff) | |
parent | a6196e42a9830e0129a834a38c93d84c28c29883 (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-- | 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 ea876d73a..31fcfca28 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/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 616cd7d06..028bf024d 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/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. * |