summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2017-07-12 10:53:55 -0600
committerJeff Sharkey <jsharkey@android.com>2017-07-13 16:59:13 -0600
commit4befdc216d00e2dce59097fb1f8195afe489fd32 (patch)
tree4aadfb803a95f4bcfd0bb28b85ac836ef81ababd /service
parentd9730aa504ed133340267051f35743d102f192df (diff)
Move "metered" persistence to WifiConfiguration.
For a long time we've had a nasty tangled dependency between Wi-Fi and NPMS, since they both persisted different details for configured networks. As part of preparing for new carrier data plan APIs, move the tracking of meteredness over to WifiConfiguration. Persist both meteredHint and meteredOverride, and flesh out more documentation for them both. Allow them to be mutated to support both upgrade from NPMS and modification by Settings. When we notice a strong signal that a network is metered, persist that fact in meteredHint for future reference to be as conservative as possible; user always has the option to override. More explicit setting of values in updateCapabilities(). Bug: 63391323 Test: builds, boots, Wi-Fi policy is upgraded Change-Id: Id7c282b007a23892ee739bd2132c3b63243bd0ce
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java32
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkHistory.java9
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java72
-rw-r--r--service/java/com/android/server/wifi/util/XmlUtil.java5
4 files changed, 74 insertions, 44 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index 67583a397..93cdfa64f 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -34,6 +34,7 @@ import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiScanner;
+import android.os.Binder;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
@@ -652,6 +653,12 @@ public class WifiConfigManager {
* @param ignoreLockdown Ignore the configuration lockdown checks for connection attempts.
*/
private boolean canModifyNetwork(WifiConfiguration config, int uid, boolean ignoreLockdown) {
+ // System internals can always update networks; they're typically only
+ // making meteredHint or meteredOverride changes
+ if (uid == Process.SYSTEM_UID) {
+ return true;
+ }
+
// Passpoint configurations are generated and managed by PasspointManager. They can be
// added by either PasspointNetworkEvaluator (for auto connection) or Settings app
// (for manual connection), and need to be removed once the connection is completed.
@@ -710,16 +717,24 @@ public class WifiConfigManager {
}
/**
- * Method to check if the provided UID belongs to the current foreground user or some other
- * app (only SysUI today) running on behalf of the user.
- * This is used to prevent any background user apps from modifying network configurations.
+ * Check if the given UID belongs to the current foreground user. This is
+ * used to prevent apps running in background users from modifying network
+ * configurations.
+ * <p>
+ * UIDs belonging to system internals (such as SystemUI) are always allowed,
+ * since they always run as {@link UserHandle#USER_SYSTEM}.
*
* @param uid uid of the app.
- * @return true if the UID belongs to the current foreground app or SystemUI, false otherwise.
+ * @return true if the given UID belongs to the current foreground user,
+ * otherwise false.
*/
private boolean doesUidBelongToCurrentUser(int uid) {
- return (WifiConfigurationUtil.doesUidBelongToAnyProfile(
- uid, mUserManager.getProfiles(mCurrentUserId)) || (uid == mSystemUiUid));
+ if (uid == android.os.Process.SYSTEM_UID || uid == mSystemUiUid) {
+ return true;
+ } else {
+ return WifiConfigurationUtil.doesUidBelongToAnyProfile(
+ uid, mUserManager.getProfiles(mCurrentUserId));
+ }
}
/**
@@ -828,6 +843,10 @@ public class WifiConfigManager {
internalConfig.enterpriseConfig.copyFromExternal(
externalConfig.enterpriseConfig, PASSWORD_MASK);
}
+
+ // Copy over any metered information.
+ internalConfig.meteredHint = externalConfig.meteredHint;
+ internalConfig.meteredOverride = externalConfig.meteredOverride;
}
/**
@@ -890,7 +909,6 @@ public class WifiConfigManager {
newInternalConfig.requirePMF = externalConfig.requirePMF;
newInternalConfig.noInternetAccessExpected = externalConfig.noInternetAccessExpected;
newInternalConfig.ephemeral = externalConfig.ephemeral;
- newInternalConfig.meteredHint = externalConfig.meteredHint;
newInternalConfig.useExternalScores = externalConfig.useExternalScores;
newInternalConfig.shared = externalConfig.shared;
diff --git a/service/java/com/android/server/wifi/WifiNetworkHistory.java b/service/java/com/android/server/wifi/WifiNetworkHistory.java
index f8457cd8a..534567086 100644
--- a/service/java/com/android/server/wifi/WifiNetworkHistory.java
+++ b/service/java/com/android/server/wifi/WifiNetworkHistory.java
@@ -17,16 +17,13 @@
package com.android.server.wifi;
import android.content.Context;
-
import android.net.wifi.ScanResult;
-
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.NetworkSelectionStatus;
import android.net.wifi.WifiSsid;
import android.os.Environment;
import android.os.Process;
import android.text.TextUtils;
-
import android.util.Log;
import com.android.server.net.DelayedDiskWrite;
@@ -91,6 +88,7 @@ public class WifiNetworkHistory {
private static final String EPHEMERAL_KEY = "EPHEMERAL";
private static final String USE_EXTERNAL_SCORES_KEY = "USE_EXTERNAL_SCORES";
private static final String METERED_HINT_KEY = "METERED_HINT";
+ private static final String METERED_OVERRIDE_KEY = "METERED_OVERRIDE";
private static final String NUM_ASSOCIATION_KEY = "NUM_ASSOCIATION";
private static final String DELETED_EPHEMERAL_KEY = "DELETED_EPHEMERAL";
private static final String CREATOR_NAME_KEY = "CREATOR_NAME";
@@ -213,6 +211,8 @@ public class WifiNetworkHistory {
+ Boolean.toString(config.ephemeral) + NL);
out.writeUTF(METERED_HINT_KEY + SEPARATOR
+ Boolean.toString(config.meteredHint) + NL);
+ out.writeUTF(METERED_OVERRIDE_KEY + SEPARATOR
+ + Integer.toString(config.meteredOverride) + NL);
out.writeUTF(USE_EXTERNAL_SCORES_KEY + SEPARATOR
+ Boolean.toString(config.useExternalScores) + NL);
if (config.creationTime != null) {
@@ -427,6 +427,9 @@ public class WifiNetworkHistory {
case METERED_HINT_KEY:
config.meteredHint = Boolean.parseBoolean(value);
break;
+ case METERED_OVERRIDE_KEY:
+ config.meteredOverride = Integer.parseInt(value);
+ break;
case USE_EXTERNAL_SCORES_KEY:
config.useExternalScores = Boolean.parseBoolean(value);
break;
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index c58f83b74..ed9d6960d 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -275,7 +275,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
// the rssi thresholds and raised event to host. This would be eggregious if this
// value is invalid
mWifiInfo.setRssi(curRssi);
- updateCapabilities(getCurrentWifiConfiguration());
+ updateCapabilities();
int ret = startRssiMonitoringOffload(maxRssi, minRssi);
Log.d(TAG, "Re-program RSSI thresholds for " + smToString(reason) +
": [" + minRssi + ", " + maxRssi + "], curRssi=" + curRssi + " ret=" + ret);
@@ -2954,13 +2954,13 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
*/
int newSignalLevel = WifiManager.calculateSignalLevel(newRssi, WifiManager.RSSI_LEVELS);
if (newSignalLevel != mLastSignalLevel) {
- updateCapabilities(getCurrentWifiConfiguration());
+ updateCapabilities();
sendRssiChangeBroadcast(newRssi);
}
mLastSignalLevel = newSignalLevel;
} else {
mWifiInfo.setRssi(WifiInfo.INVALID_RSSI);
- updateCapabilities(getCurrentWifiConfiguration());
+ updateCapabilities();
}
if (newLinkSpeed != null) {
@@ -3234,12 +3234,13 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
}
mWifiInfo.setBSSID(stateChangeResult.BSSID);
-
mWifiInfo.setSSID(stateChangeResult.wifiSsid);
- WifiConfiguration config = getCurrentWifiConfiguration();
+
+ final WifiConfiguration config = getCurrentWifiConfiguration();
if (config != null) {
- // Set meteredHint to true if the access network type of the connecting/connected AP
- // is a chargeable public network.
+ mWifiInfo.setEphemeral(config.ephemeral);
+
+ // Set meteredHint if scan result says network is expensive
ScanDetailCache scanDetailCache = mWifiConfigManager.getScanDetailCacheForNetwork(
config.networkId);
if (scanDetailCache != null) {
@@ -3252,15 +3253,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
}
}
}
-
- mWifiInfo.setEphemeral(config.ephemeral);
- if (!mWifiInfo.getMeteredHint()) { // don't override the value if already set.
- mWifiInfo.setMeteredHint(config.meteredHint);
- }
}
mSupplicantStateTracker.sendMessage(Message.obtain(message));
-
return state;
}
@@ -3450,11 +3445,20 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
mWifiInfo + " got: " + addr);
}
}
+
mWifiInfo.setInetAddress(addr);
- if (!mWifiInfo.getMeteredHint()) { // don't override the value if already set.
- mWifiInfo.setMeteredHint(dhcpResults.hasMeteredHint());
- updateCapabilities(getCurrentWifiConfiguration());
+
+ 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);
+ }
}
+
+ updateCapabilities();
}
private void handleSuccessfulIpConfiguration() {
@@ -3466,7 +3470,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(c);
+ updateCapabilities();
}
if (c != null) {
ScanResult result = getCurrentScanResult();
@@ -5406,28 +5410,28 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
}
}
- private void updateCapabilities(WifiConfiguration config) {
- NetworkCapabilities networkCapabilities = new NetworkCapabilities(mDfltNetworkCapabilities);
- if (config != null) {
- if (config.ephemeral) {
- networkCapabilities.removeCapability(
- NetworkCapabilities.NET_CAPABILITY_TRUSTED);
- } else {
- networkCapabilities.addCapability(
- NetworkCapabilities.NET_CAPABILITY_TRUSTED);
- }
+ private void updateCapabilities() {
+ final NetworkCapabilities result = new NetworkCapabilities(mDfltNetworkCapabilities);
+
+ if (mWifiInfo != null && !mWifiInfo.isEphemeral()) {
+ result.addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED);
+ } else {
+ result.removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED);
+ }
- networkCapabilities.setSignalStrength(
- (mWifiInfo.getRssi() != WifiInfo.INVALID_RSSI)
- ? mWifiInfo.getRssi()
- : NetworkCapabilities.SIGNAL_STRENGTH_UNSPECIFIED);
+ if (mWifiInfo != null && !mWifiInfo.getMeteredHint()) {
+ result.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
+ } else {
+ result.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
}
- if (mWifiInfo.getMeteredHint()) {
- networkCapabilities.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
+ if (mWifiInfo != null && mWifiInfo.getRssi() != WifiInfo.INVALID_RSSI) {
+ result.setSignalStrength(mWifiInfo.getRssi());
+ } else {
+ result.setSignalStrength(NetworkCapabilities.SIGNAL_STRENGTH_UNSPECIFIED);
}
- mNetworkAgent.sendNetworkCapabilities(networkCapabilities);
+ mNetworkAgent.sendNetworkCapabilities(result);
}
/**
diff --git a/service/java/com/android/server/wifi/util/XmlUtil.java b/service/java/com/android/server/wifi/util/XmlUtil.java
index 853136b90..f4c3ab1af 100644
--- a/service/java/com/android/server/wifi/util/XmlUtil.java
+++ b/service/java/com/android/server/wifi/util/XmlUtil.java
@@ -332,6 +332,7 @@ public class XmlUtil {
public static final String XML_TAG_NO_INTERNET_ACCESS_EXPECTED = "NoInternetAccessExpected";
public static final String XML_TAG_USER_APPROVED = "UserApproved";
public static final String XML_TAG_METERED_HINT = "MeteredHint";
+ public static final String XML_TAG_METERED_OVERRIDE = "MeteredOverride";
public static final String XML_TAG_USE_EXTERNAL_SCORES = "UseExternalScores";
public static final String XML_TAG_NUM_ASSOCIATION = "NumAssociation";
public static final String XML_TAG_CREATOR_UID = "CreatorUid";
@@ -445,6 +446,7 @@ public class XmlUtil {
configuration.noInternetAccessExpected);
XmlUtil.writeNextValue(out, XML_TAG_USER_APPROVED, configuration.userApproved);
XmlUtil.writeNextValue(out, XML_TAG_METERED_HINT, configuration.meteredHint);
+ XmlUtil.writeNextValue(out, XML_TAG_METERED_OVERRIDE, configuration.meteredOverride);
XmlUtil.writeNextValue(
out, XML_TAG_USE_EXTERNAL_SCORES, configuration.useExternalScores);
XmlUtil.writeNextValue(out, XML_TAG_NUM_ASSOCIATION, configuration.numAssociation);
@@ -591,6 +593,9 @@ public class XmlUtil {
case XML_TAG_METERED_HINT:
configuration.meteredHint = (boolean) value;
break;
+ case XML_TAG_METERED_OVERRIDE:
+ configuration.meteredOverride = (int) value;
+ break;
case XML_TAG_USE_EXTERNAL_SCORES:
configuration.useExternalScores = (boolean) value;
break;