Merge "Add new callback to inform blocking of network on specific uid." am: f41deeb4a9 am: 118cf0e236

am: b4e045b1b8

Change-Id: I2bec503c5ffac156b679a48c09591458ab716789
This commit is contained in:
Junyu Lai
2018-10-19 09:47:40 -07:00
committed by android-build-merger
4 changed files with 255 additions and 13 deletions

View File

@@ -2816,10 +2816,11 @@ public class ConnectivityManager {
* @param network The {@link Network} of the satisfying network.
* @param networkCapabilities The {@link NetworkCapabilities} of the satisfying network.
* @param linkProperties The {@link LinkProperties} of the satisfying network.
* @param blocked Whether access to the {@link Network} is blocked due to system policy.
* @hide
*/
public void onAvailable(Network network, NetworkCapabilities networkCapabilities,
LinkProperties linkProperties) {
LinkProperties linkProperties, boolean blocked) {
// Internally only this method is called when a new network is available, and
// it calls the callback in the same way and order that older versions used
// to call so as not to change the behavior.
@@ -2830,6 +2831,7 @@ public class ConnectivityManager {
}
onCapabilitiesChanged(network, networkCapabilities);
onLinkPropertiesChanged(network, linkProperties);
onBlockedStatusChanged(network, blocked);
}
/**
@@ -2837,7 +2839,8 @@ public class ConnectivityManager {
* This callback may be called more than once if the {@link Network} that is
* satisfying the request changes. This will always immediately be followed by a
* call to {@link #onCapabilitiesChanged(Network, NetworkCapabilities)} then by a
* call to {@link #onLinkPropertiesChanged(Network, LinkProperties)}.
* call to {@link #onLinkPropertiesChanged(Network, LinkProperties)}, and a call to
* {@link #onBlockedStatusChanged(Network, boolean)}.
*
* @param network The {@link Network} of the satisfying network.
*/
@@ -2916,6 +2919,14 @@ public class ConnectivityManager {
*/
public void onNetworkResumed(Network network) {}
/**
* Called when access to the specified network is blocked or unblocked.
*
* @param network The {@link Network} whose blocked status has changed.
* @param blocked The blocked status of this {@link Network}.
*/
public void onBlockedStatusChanged(Network network, boolean blocked) {}
private NetworkRequest networkRequest;
}
@@ -2962,6 +2973,8 @@ public class ConnectivityManager {
public static final int CALLBACK_SUSPENDED = BASE + 9;
/** @hide */
public static final int CALLBACK_RESUMED = BASE + 10;
/** @hide */
public static final int CALLBACK_BLK_CHANGED = BASE + 11;
/** @hide */
public static String getCallbackName(int whichCallback) {
@@ -2976,6 +2989,7 @@ public class ConnectivityManager {
case EXPIRE_LEGACY_REQUEST: return "EXPIRE_LEGACY_REQUEST";
case CALLBACK_SUSPENDED: return "CALLBACK_SUSPENDED";
case CALLBACK_RESUMED: return "CALLBACK_RESUMED";
case CALLBACK_BLK_CHANGED: return "CALLBACK_BLK_CHANGED";
default:
return Integer.toString(whichCallback);
}
@@ -3022,7 +3036,7 @@ public class ConnectivityManager {
case CALLBACK_AVAILABLE: {
NetworkCapabilities cap = getObject(message, NetworkCapabilities.class);
LinkProperties lp = getObject(message, LinkProperties.class);
callback.onAvailable(network, cap, lp);
callback.onAvailable(network, cap, lp, message.arg1 != 0);
break;
}
case CALLBACK_LOSING: {
@@ -3055,6 +3069,10 @@ public class ConnectivityManager {
callback.onNetworkResumed(network);
break;
}
case CALLBACK_BLK_CHANGED: {
boolean blocked = message.arg1 != 0;
callback.onBlockedStatusChanged(network, blocked);
}
}
}

View File

@@ -1590,4 +1590,14 @@ public final class NetworkCapabilities implements Parcelable {
Preconditions.checkArgument(isValidCapability(capability),
"NetworkCapability " + capability + "out of range");
}
/**
* Check if this {@code NetworkCapability} instance is metered.
*
* @return {@code true} if {@code NET_CAPABILITY_NOT_METERED} is not set on this instance.
* @hide
*/
public boolean isMetered() {
return !hasCapability(NET_CAPABILITY_NOT_METERED);
}
}

View File

@@ -202,7 +202,9 @@ public class NetworkInfo implements Parcelable {
* Return a network-type-specific integer describing the subtype
* of the network.
* @return the network subtype
* @deprecated Use {@link android.telephony.TelephonyManager#getDataNetworkType} instead.
*/
@Deprecated
public int getSubtype() {
synchronized (this) {
return mSubtype;
@@ -243,7 +245,9 @@ public class NetworkInfo implements Parcelable {
/**
* Return a human-readable name describing the subtype of the network.
* @return the name of the network subtype
* @deprecated Use {@link android.telephony.TelephonyManager#getDataNetworkType} instead.
*/
@Deprecated
public String getSubtypeName() {
synchronized (this) {
return mSubtypeName;
@@ -278,7 +282,15 @@ public class NetworkInfo implements Parcelable {
* connections and pass data.
* <p>Always call this before attempting to perform data transactions.
* @return {@code true} if network connectivity exists, {@code false} otherwise.
* @deprecated Apps should instead use the
* {@link android.net.ConnectivityManager.NetworkCallback} API to
* learn about connectivity changes. See
* {@link ConnectivityManager#registerDefaultNetworkCallback} and
* {@link ConnectivityManager#registerNetworkCallback}. These will
* give a more accurate picture of the connectivity state of
* the device and let apps react more easily and quickly to changes.
*/
@Deprecated
public boolean isConnected() {
synchronized (this) {
return mState == State.CONNECTED;
@@ -411,7 +423,15 @@ public class NetworkInfo implements Parcelable {
/**
* Reports the current fine-grained state of the network.
* @return the fine-grained state
* @deprecated Apps should instead use the
* {@link android.net.ConnectivityManager.NetworkCallback} API to
* learn about connectivity changes. See
* {@link ConnectivityManager#registerDefaultNetworkCallback} and
* {@link ConnectivityManager#registerNetworkCallback}. These will
* give a more accurate picture of the connectivity state of
* the device and let apps react more easily and quickly to changes.
*/
@Deprecated
public DetailedState getDetailedState() {
synchronized (this) {
return mDetailedState;