diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 2979cd8a5d..7a1d85c93d 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -1720,14 +1720,8 @@ public class ConnectivityManager { // ignored } - /** - * Return quota status for the current active network, or {@code null} if no - * network is active. Quota status can change rapidly, so these values - * shouldn't be cached. - * - * @hide - */ - @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) + /** {@hide} */ + @Deprecated public NetworkQuotaInfo getActiveNetworkQuotaInfo() { try { return mService.getActiveNetworkQuotaInfo(); diff --git a/core/java/android/net/NetworkInfo.java b/core/java/android/net/NetworkInfo.java index 84c32bec8e..818aa21162 100644 --- a/core/java/android/net/NetworkInfo.java +++ b/core/java/android/net/NetworkInfo.java @@ -16,8 +16,8 @@ package android.net; -import android.os.Parcelable; import android.os.Parcel; +import android.os.Parcelable; import com.android.internal.annotations.VisibleForTesting; @@ -121,7 +121,6 @@ public class NetworkInfo implements Parcelable { private boolean mIsFailover; private boolean mIsAvailable; private boolean mIsRoaming; - private boolean mIsMetered; /** * @hide @@ -154,7 +153,6 @@ public class NetworkInfo implements Parcelable { mIsFailover = source.mIsFailover; mIsAvailable = source.mIsAvailable; 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. * @return the coarse-grained state @@ -434,7 +407,6 @@ public class NetworkInfo implements Parcelable { append(", failover: ").append(mIsFailover). append(", available: ").append(mIsAvailable). append(", roaming: ").append(mIsRoaming). - append(", metered: ").append(mIsMetered). append("]"); return builder.toString(); } @@ -457,7 +429,6 @@ public class NetworkInfo implements Parcelable { dest.writeInt(mIsFailover ? 1 : 0); dest.writeInt(mIsAvailable ? 1 : 0); dest.writeInt(mIsRoaming ? 1 : 0); - dest.writeInt(mIsMetered ? 1 : 0); dest.writeString(mReason); dest.writeString(mExtraInfo); } @@ -476,7 +447,6 @@ public class NetworkInfo implements Parcelable { netInfo.mIsFailover = in.readInt() != 0; netInfo.mIsAvailable = in.readInt() != 0; netInfo.mIsRoaming = in.readInt() != 0; - netInfo.mIsMetered = in.readInt() != 0; netInfo.mReason = in.readString(); netInfo.mExtraInfo = in.readString(); return netInfo; diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index a2e74b6a38..8200289a76 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -1036,8 +1036,7 @@ public class ConnectivityService extends IConnectivityManager.Stub /** * Apply any relevant filters to {@link NetworkState} for the given UID. For * example, this may mark the network as {@link DetailedState#BLOCKED} based - * on {@link #isNetworkWithLinkPropertiesBlocked}, or - * {@link NetworkInfo#isMetered()} based on network policies. + * on {@link #isNetworkWithLinkPropertiesBlocked}. */ private void filterNetworkStateForUid(NetworkState state, int uid, boolean ignoreBlocked) { if (state == null || state.networkInfo == null || state.linkProperties == null) return; @@ -1048,15 +1047,6 @@ public class ConnectivityService extends IConnectivityManager.Stub if (mLockdownTracker != null) { 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 + @Deprecated public NetworkQuotaInfo getActiveNetworkQuotaInfo() { - enforceAccessPermission(); - final int uid = Binder.getCallingUid(); - final long token = Binder.clearCallingIdentity(); - try { - final NetworkState state = getUnfilteredActiveNetworkState(uid); - if (state.networkInfo != null) { - try { - return mPolicyManager.getNetworkQuotaInfo(state); - } catch (RemoteException e) { - } - } - return null; - } finally { - Binder.restoreCallingIdentity(token); - } + Log.w(TAG, "Shame on UID " + Binder.getCallingUid() + + " for calling the hidden API getNetworkQuotaInfo(). Shame!"); + return new NetworkQuotaInfo(); } @Override public boolean isActiveNetworkMetered() { enforceAccessPermission(); - final NetworkInfo info = getActiveNetworkInfo(); - return (info != null) ? info.isMetered() : false; + final NetworkCapabilities caps = getNetworkCapabilities(getActiveNetwork()); + 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() { @@ -2759,7 +2743,8 @@ public class ConnectivityService extends IConnectivityManager.Stub enforceAccessPermission(); 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; }