diff options
author | Ningyuan Wang <nywang@google.com> | 2017-05-17 15:32:35 -0700 |
---|---|---|
committer | Ningyuan Wang <nywang@google.com> | 2017-05-31 15:11:10 -0700 |
commit | 403df479e25031276c738dbea334f09bb7e4bf37 (patch) | |
tree | 1d7bde92560948651f46062b16887f189e4af680 /service | |
parent | ff27ddf1923d9d4d4cfa8cc1a1ddb8748d0f2426 (diff) |
Remove network from supplicant when it is disabled
This CL expands OnSavedNetworkUpdateListener interface by
replacing onSavedNetworkUpdate() event with a list of
detailed events.
This CL also removes a network from supplicant when it's
disabled.
Bug: 37406637
Test: compile, unit tests, manual tests, integration test
Change-Id: Idfa29cd15b8ad75de3bb7448abd7f3c93f9778f0
Diffstat (limited to 'service')
5 files changed, 103 insertions, 14 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java index c0576dc0e..e9c20db32 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java @@ -511,6 +511,21 @@ public class SupplicantStaIfaceHal { } /** + * Remove the request |networkId| from supplicant if it's the current network, + * if the current configured network matches |networkId|. + * + * @param networkId network id of the network to be removed from supplicant. + */ + public void removeNetworkIfCurrent(int networkId) { + synchronized (mLock) { + if (getCurrentNetworkId() == networkId) { + // Currently we only save 1 network in supplicant. + removeAllNetworks(); + } + } + } + + /** * Remove all networks from supplicant */ public boolean removeAllNetworks() { diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 3f31c7ff8..4b2bb1c49 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -152,10 +152,29 @@ public class WifiConfigManager { */ public interface OnSavedNetworkUpdateListener { /** - * Invoked on saved network being enabled, disabled, blacklisted or - * un-blacklisted. + * Invoked on saved network being added. */ - void onSavedNetworkUpdate(); + void onSavedNetworkAdded(int networkId); + /** + * Invoked on saved network being enabled. + */ + void onSavedNetworkEnabled(int networkId); + /** + * Invoked on saved network being permanently disabled. + */ + void onSavedNetworkPermanentlyDisabled(int networkId); + /** + * Invoked on saved network being removed. + */ + void onSavedNetworkRemoved(int networkId); + /** + * Invoked on saved network being temporarily disabled. + */ + void onSavedNetworkTemporarilyDisabled(int networkId); + /** + * Invoked on saved network being updated. + */ + void onSavedNetworkUpdated(int networkId); } /** * Max size of scan details to cache in {@link #mScanDetailCaches}. @@ -1039,7 +1058,13 @@ 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(); + if (mListener != null) { + if (result.isNewNetwork()) { + mListener.onSavedNetworkAdded(newConfig.networkId); + } else { + mListener.onSavedNetworkUpdated(newConfig.networkId); + } + } } return result; } @@ -1104,7 +1129,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(); + if (mListener != null) mListener.onSavedNetworkRemoved(networkId); } return true; } @@ -1165,7 +1190,8 @@ public class WifiConfigManager { /** * Helper method to mark a network enabled for network selection. */ - private void setNetworkSelectionEnabled(NetworkSelectionStatus status) { + private void setNetworkSelectionEnabled(WifiConfiguration config) { + NetworkSelectionStatus status = config.getNetworkSelectionStatus(); status.setNetworkSelectionStatus( NetworkSelectionStatus.NETWORK_SELECTION_ENABLED); status.setDisableTime( @@ -1174,32 +1200,35 @@ public class WifiConfigManager { // Clear out all the disable reason counters. status.clearDisableReasonCounter(); - if (mListener != null) mListener.onSavedNetworkUpdate(); + if (mListener != null) mListener.onSavedNetworkEnabled(config.networkId); } /** * Helper method to mark a network temporarily disabled for network selection. */ private void setNetworkSelectionTemporarilyDisabled( - NetworkSelectionStatus status, int disableReason) { + WifiConfiguration config, int disableReason) { + NetworkSelectionStatus status = config.getNetworkSelectionStatus(); status.setNetworkSelectionStatus( NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED); // Only need a valid time filled in for temporarily disabled networks. status.setDisableTime(mClock.getElapsedSinceBootMillis()); status.setNetworkSelectionDisableReason(disableReason); + if (mListener != null) mListener.onSavedNetworkTemporarilyDisabled(config.networkId); } /** * Helper method to mark a network permanently disabled for network selection. */ private void setNetworkSelectionPermanentlyDisabled( - NetworkSelectionStatus status, int disableReason) { + WifiConfiguration config, int disableReason) { + NetworkSelectionStatus status = config.getNetworkSelectionStatus(); status.setNetworkSelectionStatus( NetworkSelectionStatus.NETWORK_SELECTION_PERMANENTLY_DISABLED); status.setDisableTime( NetworkSelectionStatus.INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP); status.setNetworkSelectionDisableReason(disableReason); - if (mListener != null) mListener.onSavedNetworkUpdate(); + if (mListener != null) mListener.onSavedNetworkPermanentlyDisabled(config.networkId); } /** @@ -1230,12 +1259,12 @@ public class WifiConfigManager { return false; } if (reason == NetworkSelectionStatus.NETWORK_SELECTION_ENABLE) { - setNetworkSelectionEnabled(networkStatus); + setNetworkSelectionEnabled(config); setNetworkStatus(config, WifiConfiguration.Status.ENABLED); } else if (reason < NetworkSelectionStatus.DISABLED_TLS_VERSION_MISMATCH) { - setNetworkSelectionTemporarilyDisabled(networkStatus, reason); + setNetworkSelectionTemporarilyDisabled(config, reason); } else { - setNetworkSelectionPermanentlyDisabled(networkStatus, reason); + setNetworkSelectionPermanentlyDisabled(config, reason); setNetworkStatus(config, WifiConfiguration.Status.DISABLED); } localLog("setNetworkSelectionStatus: configKey=" + config.configKey() diff --git a/service/java/com/android/server/wifi/WifiConnectivityHelper.java b/service/java/com/android/server/wifi/WifiConnectivityHelper.java index 6016b57b5..4aac31168 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityHelper.java +++ b/service/java/com/android/server/wifi/WifiConnectivityHelper.java @@ -161,4 +161,14 @@ public class WifiConnectivityHelper { return mWifiNative.configureRoaming(roamConfig); } + + /** + * Remove the request |networkId| from supplicant if it's the current network, + * if the current configured network matches |networkId|. + * + * @param networkId network id of the network to be removed from supplicant. + */ + public void removeNetworkIfCurrent(int networkId) { + mWifiNative.removeNetworkIfCurrent(networkId); + } } diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 6d82ce869..f45d17b41 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -487,7 +487,32 @@ public class WifiConnectivityManager { private class OnSavedNetworkUpdateListener implements WifiConfigManager.OnSavedNetworkUpdateListener { - public void onSavedNetworkUpdate() { + @Override + public void onSavedNetworkAdded(int networkId) { + updatePnoScan(); + } + @Override + public void onSavedNetworkEnabled(int networkId) { + updatePnoScan(); + } + @Override + public void onSavedNetworkRemoved(int networkId) { + updatePnoScan(); + } + @Override + public void onSavedNetworkUpdated(int networkId) { + updatePnoScan(); + } + @Override + public void onSavedNetworkTemporarilyDisabled(int networkId) { + mConnectivityHelper.removeNetworkIfCurrent(networkId); + } + @Override + public void onSavedNetworkPermanentlyDisabled(int networkId) { + mConnectivityHelper.removeNetworkIfCurrent(networkId); + updatePnoScan(); + } + private void updatePnoScan() { // 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) { diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index abe692346..90f6ac195 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -787,6 +787,16 @@ public class WifiNative { public String getCurrentNetworkWpsNfcConfigurationToken() { return mSupplicantStaIfaceHal.getCurrentNetworkWpsNfcConfigurationToken(); } + + /** Remove the request |networkId| from supplicant if it's the current network, + * if the current configured network matches |networkId|. + * + * @param networkId network id of the network to be removed from supplicant. + */ + public void removeNetworkIfCurrent(int networkId) { + mSupplicantStaIfaceHal.removeNetworkIfCurrent(networkId); + } + /******************************************************** * Vendor HAL operations ********************************************************/ |