diff options
author | Roshan Pius <rpius@google.com> | 2020-05-29 22:38:32 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-05-29 22:38:32 +0000 |
commit | a6fe29a0ad0b6f84dc82820d6f8d520c4bdf4511 (patch) | |
tree | 5997862d65056305083d41ad48ca4bec75d25217 | |
parent | 6e47907012246db4d4440190199b913b0ae3d66a (diff) | |
parent | 3eb812da9de7644281495554afbdfeace6e5de52 (diff) |
Merge changes I88af4e2d,I85cc20bd into rvc-dev am: 47d386420f am: 3eb812da9d
Change-Id: I85076e2dd3948738566100e207c2ce3ce3604182
5 files changed, 83 insertions, 12 deletions
diff --git a/service/java/com/android/server/wifi/ConfigurationMap.java b/service/java/com/android/server/wifi/ConfigurationMap.java index 1f21891e3..a050b9cd8 100644 --- a/service/java/com/android/server/wifi/ConfigurationMap.java +++ b/service/java/com/android/server/wifi/ConfigurationMap.java @@ -49,8 +49,12 @@ public class ConfigurationMap { if (config.shared || currentUser.equals(creatorUser) || mUserManager.isSameProfileGroup(currentUser, creatorUser)) { mPerIDForCurrentUser.put(config.networkId, config); - mScanResultMatchInfoMapForCurrentUser.put( - ScanResultMatchInfo.fromWifiConfiguration(config), config); + // TODO (b/142035508): Add a more generic fix. This cache should only hold saved + // networks. + if (!config.fromWifiNetworkSpecifier) { + mScanResultMatchInfoMapForCurrentUser.put( + ScanResultMatchInfo.fromWifiConfiguration(config), config); + } } return current; } diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 209044a65..d607b7893 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -2364,6 +2364,9 @@ public class WifiConfigManager { * @param scanDetail ScanDetail instance to use for looking up the network. * @return WifiConfiguration object representing the network corresponding to the scanDetail, * null if none exists. + * + * TODO (b/142035508): This should only return saved networks (and rename to + * getSavedNetworkForScanDetail()). */ public WifiConfiguration getConfiguredNetworkForScanDetail(ScanDetail scanDetail) { ScanResult scanResult = scanDetail.getScanResult(); @@ -2391,6 +2394,8 @@ public class WifiConfigManager { * {@link #mScanDetailCaches} for the retrieved network. * * @param scanDetail input a scanDetail from the scan result + * TODO (b/142035508): This should only return saved networks (and rename to + * updateScanDetailCacheFromScanDetail()). */ public void updateScanDetailCacheFromScanDetail(ScanDetail scanDetail) { WifiConfiguration network = getConfiguredNetworkForScanDetail(scanDetail); @@ -2407,6 +2412,8 @@ public class WifiConfigManager { * @param scanDetail input a scanDetail from the scan result * @return WifiConfiguration object representing the network corresponding to the scanDetail, * null if none exists. + * TODO (b/142035508): This should only return saved networks (and rename to + * getSavedNetworkForScanDetailAndCache()). */ public WifiConfiguration getConfiguredNetworkForScanDetailAndCache(ScanDetail scanDetail) { WifiConfiguration network = getConfiguredNetworkForScanDetail(scanDetail); diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java index 98ba5bc94..9dc89addc 100644 --- a/service/java/com/android/server/wifi/WifiNetworkFactory.java +++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java @@ -146,6 +146,7 @@ public class WifiNetworkFactory extends NetworkFactory { private boolean mVerboseLoggingEnabled = false; private boolean mPeriodicScanTimerSet = false; private boolean mConnectionTimeoutSet = false; + private boolean mIsPeriodicScanEnabled = false; private boolean mIsPeriodicScanPaused = false; // We sent a new connection request and are waiting for connection success. private boolean mPendingConnectionSuccess = false; @@ -256,6 +257,7 @@ public class WifiNetworkFactory extends NetworkFactory { public void onAlarm() { // Trigger the next scan. startScan(); + mPeriodicScanTimerSet = false; } } @@ -264,6 +266,7 @@ public class WifiNetworkFactory extends NetworkFactory { public void onAlarm() { Log.e(TAG, "Timed-out connecting to network"); handleNetworkConnectionFailure(mUserSelectedNetwork); + mConnectionTimeoutSet = false; } } @@ -819,6 +822,7 @@ public class WifiNetworkFactory extends NetworkFactory { // Cancel the ongoing scans after user selection. cancelPeriodicScans(); + mIsPeriodicScanEnabled = false; // Trigger connection attempts. handleConnectToNetworkUserSelectionInternal(network); @@ -918,13 +922,13 @@ public class WifiNetworkFactory extends NetworkFactory { public void handleScreenStateChanged(boolean screenOn) { // If there is no active request or if the user has already selected a network, // ignore screen state changes. - if (mActiveSpecificNetworkRequest == null || mUserSelectedNetwork != null) return; + if (mActiveSpecificNetworkRequest == null || !mIsPeriodicScanEnabled) return; // Pause periodic scans when the screen is off & resume when the screen is on. if (screenOn) { if (mVerboseLoggingEnabled) Log.v(TAG, "Resuming scans on screen on"); - startScan(); mIsPeriodicScanPaused = false; + startScan(); } else { if (mVerboseLoggingEnabled) Log.v(TAG, "Pausing scans on screen off"); cancelPeriodicScans(); @@ -971,6 +975,7 @@ public class WifiNetworkFactory extends NetworkFactory { mActiveSpecificNetworkRequestSpecifier = null; mUserSelectedNetwork = null; mUserSelectedNetworkConnectRetryCount = 0; + mIsPeriodicScanEnabled = false; mIsPeriodicScanPaused = false; mActiveMatchedScanResults = null; mPendingConnectionSuccess = false; @@ -1075,6 +1080,7 @@ public class WifiNetworkFactory extends NetworkFactory { mScanSettings.hiddenNetworks.add(new WifiScanner.ScanSettings.HiddenNetwork( addEnclosingQuotes(wns.ssidPatternMatcher.getPath()))); } + mIsPeriodicScanEnabled = true; startScan(); } @@ -1103,6 +1109,10 @@ public class WifiNetworkFactory extends NetworkFactory { Log.e(TAG, "Scan triggered when there is no active network request. Ignoring..."); return; } + if (!mIsPeriodicScanEnabled) { + Log.e(TAG, "Scan triggered after user selected network. Ignoring..."); + return; + } if (mVerboseLoggingEnabled) { Log.v(TAG, "Starting the next scan for " + mActiveSpecificNetworkRequestSpecifier); } diff --git a/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java b/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java index b433d94cf..02994ecad 100644 --- a/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ConfigurationMapTest.java @@ -333,4 +333,23 @@ public class ConfigurationMapTest extends WifiBaseTest { mConfigs.clear(); assertNull(mConfigs.getByScanResultForCurrentUser(scanResult)); } + + @Test + public void testScanResultDoesNotMatchForWifiNetworkSpecifier() { + // Add regular saved network, this should create a scan result match info cache entry. + WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork(); + ScanResult scanResult = createScanResultForNetwork(config); + config.networkId = 5; + mConfigs.put(config); + assertNotNull(mConfigs.getByScanResultForCurrentUser(scanResult)); + + mConfigs.clear(); + + // Create WifiNetworkSpecifier network, this should not create a scan result match info + // cache entry. + config.ephemeral = true; + config.fromWifiNetworkSpecifier = true; + mConfigs.put(config); + assertNull(mConfigs.getByScanResultForCurrentUser(scanResult)); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java index 25aaeffd6..5f9e0333e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java @@ -644,6 +644,35 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { } /** + * Verify the periodic scan back off to find a network matching the network specifier + * is cancelled when the user selects a network. + */ + @Test + public void testPeriodicScanCancelOnUserSelectNetwork() throws Exception { + attachDefaultWifiNetworkSpecifierAndAppInfo(TEST_UID_1, false); + mWifiNetworkFactory.needNetworkFor(mNetworkRequest, 0); + + mWifiNetworkFactory.addCallback(mAppBinder, mNetworkRequestMatchCallback, + TEST_CALLBACK_IDENTIFIER); + verify(mNetworkRequestMatchCallback).onUserSelectionCallbackRegistration( + mNetworkRequestUserSelectionCallback.capture()); + + verifyPeriodicScans(0, + PERIODIC_SCAN_INTERVAL_MS, // 10s + PERIODIC_SCAN_INTERVAL_MS); // 10s + + // Now trigger user selection to one of the network. + mSelectedNetwork = WifiConfigurationTestUtil.createPskNetwork(); + mSelectedNetwork.SSID = "\"" + TEST_SSID_1 + "\""; + sendUserSelectionSelect(mNetworkRequestUserSelectionCallback.getValue(), mSelectedNetwork); + mLooper.dispatchAll(); + + // Cancel the alarm set for the next scan. + verify(mAlarmManager).cancel(mPeriodicScanListenerArgumentCaptor.getValue()); + } + + + /** * Verify callback registration/unregistration. */ @Test @@ -1345,7 +1374,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { } mInOrder = inOrder(mAlarmManager, mClientModeImpl); - validateConnectionRetryAttempts(); + validateConnectionRetryAttempts(true); // Fail the request after all the retries are exhausted. verify(mNetworkRequestMatchCallback).onAbort(); @@ -1373,7 +1402,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { mLooper.dispatchAll(); mInOrder = inOrder(mAlarmManager, mClientModeImpl); - validateConnectionRetryAttempts(); + validateConnectionRetryAttempts(false); // Fail the request after all the retries are exhausted. verify(mNetworkRequestMatchCallback).onAbort(); @@ -1407,7 +1436,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { } mInOrder = inOrder(mAlarmManager, mClientModeImpl); - validateConnectionRetryAttempts(); + validateConnectionRetryAttempts(false); verify(mNetworkRequestMatchCallback).onAbort(); // Verify that we sent the connection failure callback. @@ -1453,7 +1482,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { } mInOrder = inOrder(mAlarmManager, mClientModeImpl); - validateConnectionRetryAttempts(); + validateConnectionRetryAttempts(false); // Verify that we sent the connection failure callback. verify(mNetworkRequestMatchCallback).onUserSelectionConnectFailure( @@ -2783,11 +2812,13 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { } } - private void validateConnectionRetryAttempts() { + private void validateConnectionRetryAttempts(boolean onTimeout) { for (int i = 0; i < WifiNetworkFactory.USER_SELECTED_NETWORK_CONNECT_RETRY_MAX; i++) { - // Cancel the existing connection timeout. - mInOrder.verify(mAlarmManager).cancel( - mConnectionTimeoutAlarmListenerArgumentCaptor.getValue()); + if (!onTimeout) { + // Cancel the existing connection timeout. + mInOrder.verify(mAlarmManager).cancel( + mConnectionTimeoutAlarmListenerArgumentCaptor.getValue()); + } // Trigger new connection. mInOrder.verify(mClientModeImpl).connect(eq(null), eq(TEST_NETWORK_ID_1), |