From eb3dfcbab191efe0532294b75a5e2ce6837ce1c9 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 30 Aug 2017 16:25:43 -0600 Subject: Meteredness should reflect user opinion. While cleaning up the original meteredness refactoring CL, I must have dropped the usage of WifiConfiguration.isMetered() which blends together all the various options to decide if a network should be treated as metered or not. Fix that bug. Also update the capabilities whenever a configuration is updated, since the user (or tests) may have just changed their meteredness opinion. Test: cts-tradefed run commandAndExit cts-dev -m CtsHostsideNetworkTests Bug: 64274313 Change-Id: I6b4df07b6222810f7b3790a5c2f1685dfe3535c9 --- .../android/server/wifi/WifiConnectivityManager.java | 2 ++ .../com/android/server/wifi/WifiStateMachine.java | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 93db5ab67..e417fde2c 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -512,6 +512,8 @@ public class WifiConnectivityManager { } @Override public void onSavedNetworkUpdated(int networkId) { + // User might have changed meteredOverride, so update capabilties + mStateMachine.updateCapabilities(); updatePnoScan(); } @Override diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 5ebe25902..f1ca17dfd 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -3482,14 +3482,14 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss final WifiConfiguration config = getCurrentWifiConfiguration(); if (config != null) { mWifiInfo.setEphemeral(config.ephemeral); + } - // Set meteredHint if DHCP result says network is metered - if (dhcpResults.hasMeteredHint()) { - mWifiInfo.setMeteredHint(true); - } + // Set meteredHint if DHCP result says network is metered + if (dhcpResults.hasMeteredHint()) { + mWifiInfo.setMeteredHint(true); } - updateCapabilities(); + updateCapabilities(config); } private void handleSuccessfulIpConfiguration() { @@ -3501,7 +3501,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss WifiConfiguration.NetworkSelectionStatus.DISABLED_DHCP_FAILURE); // Tell the framework whether the newly connected network is trusted or untrusted. - updateCapabilities(); + updateCapabilities(c); } if (c != null) { ScanResult result = getCurrentScanResult(); @@ -5507,7 +5507,11 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss } } - private void updateCapabilities() { + public void updateCapabilities() { + updateCapabilities(getCurrentWifiConfiguration()); + } + + private void updateCapabilities(WifiConfiguration config) { final NetworkCapabilities result = new NetworkCapabilities(mDfltNetworkCapabilities); if (mWifiInfo != null && !mWifiInfo.isEphemeral()) { @@ -5516,7 +5520,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss result.removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED); } - if (mWifiInfo != null && !mWifiInfo.getMeteredHint()) { + if (mWifiInfo != null && !WifiConfiguration.isMetered(config, mWifiInfo)) { result.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED); } else { result.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED); -- cgit v1.2.3