diff options
author | Randy Pan <zpan@google.com> | 2017-04-03 12:52:18 -0700 |
---|---|---|
committer | Randy Pan <zpan@google.com> | 2017-04-03 16:57:33 -0700 |
commit | 5d0addadb370bcbb8900414fb9597bd415e6fea0 (patch) | |
tree | 2be20ca77da224e1b63e46e49ba3c2f769e253d9 | |
parent | d44fca25d34d80d98c242423c3a5504a325553ab (diff) |
Update PNO scan network list upon network update
Add a listener interface in WifiConfigManager to notify events
such as network being enabled, disabled, blacklisted or
un-blacklisted.
WifiConnectivityManager listens to the above events and update
the PNO scan network list if necessary.
Bug: 30399964
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: I75523a3a53ff62b14d485fd722354c4d6c3b18c1
4 files changed, 50 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 63168e995..361f0eacf 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -147,6 +147,17 @@ public class WifiConfigManager { Integer.MAX_VALUE // threshold for DISABLED_BY_USER_SWITCH }; /** + * Interface for other modules to listen to the saved network updated + * events. + */ + public interface OnSavedNetworkUpdateListener { + /** + * Invoked on saved network being enabled, disabled, blacklisted or + * un-blacklisted. + */ + void onSavedNetworkUpdate(); + } + /** * Max size of scan details to cache in {@link #mScanDetailCaches}. */ @VisibleForTesting @@ -298,6 +309,9 @@ public class WifiConfigManager { private final NetworkListStoreData mNetworkListStoreData; private final DeletedEphemeralSsidsStoreData mDeletedEphemeralSsidsStoreData; + // Store the saved network update listener. + private OnSavedNetworkUpdateListener mListener = null; + /** * Create new instance of WifiConfigManager. */ @@ -1012,6 +1026,7 @@ public class WifiConfigManager { // Unless the added network is ephemeral or Passpoint, persist the network update/addition. if (!config.ephemeral && !config.isPasspoint()) { saveToStore(true); + if (mListener != null) mListener.onSavedNetworkUpdate(); } return result; } @@ -1076,6 +1091,7 @@ public class WifiConfigManager { // Unless the removed network is ephemeral or Passpoint, persist the network removal. if (!config.ephemeral && !config.isPasspoint()) { saveToStore(true); + if (mListener != null) mListener.onSavedNetworkUpdate(); } return true; } @@ -1145,6 +1161,7 @@ public class WifiConfigManager { // Clear out all the disable reason counters. status.clearDisableReasonCounter(); + if (mListener != null) mListener.onSavedNetworkUpdate(); } /** @@ -1169,6 +1186,7 @@ public class WifiConfigManager { status.setDisableTime( NetworkSelectionStatus.INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP); status.setNetworkSelectionDisableReason(disableReason); + if (mListener != null) mListener.onSavedNetworkUpdate(); } /** @@ -2763,4 +2781,11 @@ public class WifiConfigManager { } return false; } + + /** + * Set the saved network update event listener + */ + public void setOnSavedNetworkUpdateListener(OnSavedNetworkUpdateListener listener) { + mListener = listener; + } } diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index bb03488e7..bd00b3f5b 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -490,6 +490,18 @@ public class WifiConnectivityManager { private final PnoScanListener mPnoScanListener = new PnoScanListener(); + private class OnSavedNetworkUpdateListener implements + WifiConfigManager.OnSavedNetworkUpdateListener { + public void onSavedNetworkUpdate() { + // Update the PNO scan network list when screen is off. Here we + // rely on startConnectivityScan() to perform all the checks and clean up. + if (!mScreenOn) { + localLog("Saved networks updated"); + startConnectivityScan(false); + } + } + } + /** * WifiConnectivityManager constructor */ @@ -563,6 +575,9 @@ public class WifiConnectivityManager { // Register for all single scan results mScanner.registerScanListener(mAllSingleScanListener); + // Listen to WifiConfigManager network update events + mConfigManager.setOnSavedNetworkUpdateListener(new OnSavedNetworkUpdateListener()); + mWifiConnectivityManagerEnabled = enable; localLog("ConnectivityScanManager initialized and " diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 951f8e114..b9a8266f4 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -109,6 +109,7 @@ public class WifiConfigManagerTest { @Mock private WifiPermissionsWrapper mWifiPermissionsWrapper; @Mock private NetworkListStoreData mNetworkListStoreData; @Mock private DeletedEphemeralSsidsStoreData mDeletedEphemeralSsidsStoreData; + @Mock private WifiConfigManager.OnSavedNetworkUpdateListener mWcmListener; private MockResources mResources; private InOrder mContextConfigStoreMockOrder; @@ -177,6 +178,7 @@ public class WifiConfigManagerTest { when(mWifiPermissionsWrapper.getDevicePolicyManagerInternal()) .thenReturn(mDevicePolicyManagerInternal); createWifiConfigManager(); + mWifiConfigManager.setOnSavedNetworkUpdateListener(mWcmListener); } /** @@ -240,6 +242,7 @@ public class WifiConfigManagerTest { mWifiConfigManager.getConfiguredNetworksWithPasswords(); WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( networks, retrievedNetworks); + verify(mWcmListener, times(2)).onSavedNetworkUpdate(); } /** @@ -263,6 +266,7 @@ public class WifiConfigManagerTest { // Ensure that this is not returned in the saved network list. assertTrue(mWifiConfigManager.getSavedNetworks().isEmpty()); + verify(mWcmListener, never()).onSavedNetworkUpdate(); } /** @@ -440,6 +444,7 @@ public class WifiConfigManagerTest { verifyRemoveNetworkFromWifiConfigManager(openNetwork); // Ensure that configured network list is empty now. assertTrue(mWifiConfigManager.getConfiguredNetworks().isEmpty()); + verify(mWcmListener, times(2)).onSavedNetworkUpdate(); } /** @@ -458,6 +463,7 @@ public class WifiConfigManagerTest { verifyRemoveEphemeralNetworkFromWifiConfigManager(ephemeralNetwork); // Ensure that configured network list is empty now. assertTrue(mWifiConfigManager.getConfiguredNetworks().isEmpty()); + verify(mWcmListener, never()).onSavedNetworkUpdate(); } /** @@ -475,6 +481,7 @@ public class WifiConfigManagerTest { verifyRemovePasspointNetworkFromWifiConfigManager(passpointNetwork); // Ensure that configured network list is empty now. assertTrue(mWifiConfigManager.getConfiguredNetworks().isEmpty()); + verify(mWcmListener, never()).onSavedNetworkUpdate(); } /** @@ -582,10 +589,12 @@ public class WifiConfigManagerTest { // Now set it to permanently disabled. verifyUpdateNetworkSelectionStatus( result.getNetworkId(), NetworkSelectionStatus.DISABLED_BY_WIFI_MANAGER, 0); + verify(mWcmListener, times(3)).onSavedNetworkUpdate(); // Now set it back to enabled. verifyUpdateNetworkSelectionStatus( result.getNetworkId(), NetworkSelectionStatus.NETWORK_SELECTION_ENABLE, 0); + verify(mWcmListener, times(4)).onSavedNetworkUpdate(); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 55438449e..68c2ca359 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -87,6 +87,7 @@ public class WifiConnectivityManagerTest { mWifiConnectivityHelper = mockWifiConnectivityHelper(); mWifiNS = mockWifiNetworkSelector(); mWifiConnectivityManager = createConnectivityManager(); + verify(mWifiConfigManager).setOnSavedNetworkUpdateListener(anyObject()); mWifiConnectivityManager.setWifiEnabled(true); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()); } |