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. This also cleans up how meteredness is communicated through NetworkAgents to rely completely on NET_CAPABILITY_NOT_METERED by removing the metered flag on NetworkInfo, which has caused confusion and staleness. Migrates any existing user-configured metered networks over to WifiConfiguration once the device finishes booting. Remove support for NetworkQuotaInfo, since this information can no longer be made available to apps. Frustratingly, some apps are using it, so keep the object around returning stub values, and shame them in the logs. Bug: 63391323 Test: builds, boots, Wi-Fi policy is upgraded Exempt-From-Owner-Approval: Bug 63673347 Change-Id: I64f865ddeb65cfcd330f8d2a847368abdf960a07
This commit is contained in:
@@ -1720,14 +1720,8 @@ public class ConnectivityManager {
|
|||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** {@hide} */
|
||||||
* Return quota status for the current active network, or {@code null} if no
|
@Deprecated
|
||||||
* network is active. Quota status can change rapidly, so these values
|
|
||||||
* shouldn't be cached.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
||||||
public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
|
public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
|
||||||
try {
|
try {
|
||||||
return mService.getActiveNetworkQuotaInfo();
|
return mService.getActiveNetworkQuotaInfo();
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
|
||||||
@@ -121,7 +121,6 @@ public class NetworkInfo implements Parcelable {
|
|||||||
private boolean mIsFailover;
|
private boolean mIsFailover;
|
||||||
private boolean mIsAvailable;
|
private boolean mIsAvailable;
|
||||||
private boolean mIsRoaming;
|
private boolean mIsRoaming;
|
||||||
private boolean mIsMetered;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
@@ -154,7 +153,6 @@ public class NetworkInfo implements Parcelable {
|
|||||||
mIsFailover = source.mIsFailover;
|
mIsFailover = source.mIsFailover;
|
||||||
mIsAvailable = source.mIsAvailable;
|
mIsAvailable = source.mIsAvailable;
|
||||||
mIsRoaming = source.mIsRoaming;
|
mIsRoaming = source.mIsRoaming;
|
||||||
mIsMetered = source.mIsMetered;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -326,31 +324,6 @@ public class NetworkInfo implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if this network is metered. A network is classified as metered
|
|
||||||
* when the user is sensitive to heavy data usage on that connection due to
|
|
||||||
* monetary costs, data limitations or battery/performance issues. You
|
|
||||||
* should check this before doing large data transfers, and warn the user or
|
|
||||||
* delay the operation until another network is available.
|
|
||||||
*
|
|
||||||
* @return {@code true} if large transfers should be avoided, otherwise
|
|
||||||
* {@code false}.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public boolean isMetered() {
|
|
||||||
synchronized (this) {
|
|
||||||
return mIsMetered;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@hide} */
|
|
||||||
@VisibleForTesting
|
|
||||||
public void setMetered(boolean isMetered) {
|
|
||||||
synchronized (this) {
|
|
||||||
mIsMetered = isMetered;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reports the current coarse-grained state of the network.
|
* Reports the current coarse-grained state of the network.
|
||||||
* @return the coarse-grained state
|
* @return the coarse-grained state
|
||||||
@@ -434,7 +407,6 @@ public class NetworkInfo implements Parcelable {
|
|||||||
append(", failover: ").append(mIsFailover).
|
append(", failover: ").append(mIsFailover).
|
||||||
append(", available: ").append(mIsAvailable).
|
append(", available: ").append(mIsAvailable).
|
||||||
append(", roaming: ").append(mIsRoaming).
|
append(", roaming: ").append(mIsRoaming).
|
||||||
append(", metered: ").append(mIsMetered).
|
|
||||||
append("]");
|
append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
@@ -457,7 +429,6 @@ public class NetworkInfo implements Parcelable {
|
|||||||
dest.writeInt(mIsFailover ? 1 : 0);
|
dest.writeInt(mIsFailover ? 1 : 0);
|
||||||
dest.writeInt(mIsAvailable ? 1 : 0);
|
dest.writeInt(mIsAvailable ? 1 : 0);
|
||||||
dest.writeInt(mIsRoaming ? 1 : 0);
|
dest.writeInt(mIsRoaming ? 1 : 0);
|
||||||
dest.writeInt(mIsMetered ? 1 : 0);
|
|
||||||
dest.writeString(mReason);
|
dest.writeString(mReason);
|
||||||
dest.writeString(mExtraInfo);
|
dest.writeString(mExtraInfo);
|
||||||
}
|
}
|
||||||
@@ -476,7 +447,6 @@ public class NetworkInfo implements Parcelable {
|
|||||||
netInfo.mIsFailover = in.readInt() != 0;
|
netInfo.mIsFailover = in.readInt() != 0;
|
||||||
netInfo.mIsAvailable = in.readInt() != 0;
|
netInfo.mIsAvailable = in.readInt() != 0;
|
||||||
netInfo.mIsRoaming = in.readInt() != 0;
|
netInfo.mIsRoaming = in.readInt() != 0;
|
||||||
netInfo.mIsMetered = in.readInt() != 0;
|
|
||||||
netInfo.mReason = in.readString();
|
netInfo.mReason = in.readString();
|
||||||
netInfo.mExtraInfo = in.readString();
|
netInfo.mExtraInfo = in.readString();
|
||||||
return netInfo;
|
return netInfo;
|
||||||
|
|||||||
@@ -1036,8 +1036,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
/**
|
/**
|
||||||
* Apply any relevant filters to {@link NetworkState} for the given UID. For
|
* Apply any relevant filters to {@link NetworkState} for the given UID. For
|
||||||
* example, this may mark the network as {@link DetailedState#BLOCKED} based
|
* example, this may mark the network as {@link DetailedState#BLOCKED} based
|
||||||
* on {@link #isNetworkWithLinkPropertiesBlocked}, or
|
* on {@link #isNetworkWithLinkPropertiesBlocked}.
|
||||||
* {@link NetworkInfo#isMetered()} based on network policies.
|
|
||||||
*/
|
*/
|
||||||
private void filterNetworkStateForUid(NetworkState state, int uid, boolean ignoreBlocked) {
|
private void filterNetworkStateForUid(NetworkState state, int uid, boolean ignoreBlocked) {
|
||||||
if (state == null || state.networkInfo == null || state.linkProperties == null) return;
|
if (state == null || state.networkInfo == null || state.linkProperties == null) return;
|
||||||
@@ -1048,15 +1047,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (mLockdownTracker != null) {
|
if (mLockdownTracker != null) {
|
||||||
mLockdownTracker.augmentNetworkInfo(state.networkInfo);
|
mLockdownTracker.augmentNetworkInfo(state.networkInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: apply metered state closer to NetworkAgentInfo
|
|
||||||
final long token = Binder.clearCallingIdentity();
|
|
||||||
try {
|
|
||||||
state.networkInfo.setMetered(mPolicyManager.isNetworkMetered(state));
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
} finally {
|
|
||||||
Binder.restoreCallingIdentity(token);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1326,30 +1316,24 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
|
public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
|
||||||
enforceAccessPermission();
|
Log.w(TAG, "Shame on UID " + Binder.getCallingUid()
|
||||||
final int uid = Binder.getCallingUid();
|
+ " for calling the hidden API getNetworkQuotaInfo(). Shame!");
|
||||||
final long token = Binder.clearCallingIdentity();
|
return new NetworkQuotaInfo();
|
||||||
try {
|
|
||||||
final NetworkState state = getUnfilteredActiveNetworkState(uid);
|
|
||||||
if (state.networkInfo != null) {
|
|
||||||
try {
|
|
||||||
return mPolicyManager.getNetworkQuotaInfo(state);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
Binder.restoreCallingIdentity(token);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActiveNetworkMetered() {
|
public boolean isActiveNetworkMetered() {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
|
|
||||||
final NetworkInfo info = getActiveNetworkInfo();
|
final NetworkCapabilities caps = getNetworkCapabilities(getActiveNetwork());
|
||||||
return (info != null) ? info.isMetered() : false;
|
if (caps != null) {
|
||||||
|
return !caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
||||||
|
} else {
|
||||||
|
// Always return the most conservative value
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private INetworkManagementEventObserver mDataActivityObserver = new BaseNetworkObserver() {
|
private INetworkManagementEventObserver mDataActivityObserver = new BaseNetworkObserver() {
|
||||||
@@ -2759,7 +2743,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
|
|
||||||
NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
|
||||||
if (nai != null && !nai.networkInfo.isMetered()) {
|
if (nai != null && nai.networkCapabilities
|
||||||
|
.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)) {
|
||||||
return ConnectivityManager.MULTIPATH_PREFERENCE_UNMETERED;
|
return ConnectivityManager.MULTIPATH_PREFERENCE_UNMETERED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user