Publish FOREGROUND and add NOT_SUSPENDED capabilities.
NOT_SUSPENDED and FOREGROUND are capabilities that need to be public so as to reach feature parity with what information can be gotten through the use of CONNECTIVITY_ACTION and synchronous calls to ConnectivityManager. This change makes them public, and wires up the NOT_SUSPENDED capability. This deprecates in effect the old onSuspended and onResumed callbacks, but these have never been public. This also converts the onAvailable path from a multiple binder call design to a simpler, single binder call. This is only for internal convenience Test: runtest frameworks-net Test: cts Test: also manual testing Change-Id: I6ea524bb361ecef0569ea2f9006c1e516378bc25
This commit is contained in:
@@ -2685,6 +2685,32 @@ public class ConnectivityManager {
|
||||
* satisfying the request changes.
|
||||
*
|
||||
* @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.
|
||||
* @hide
|
||||
*/
|
||||
public void onAvailable(Network network, NetworkCapabilities networkCapabilities,
|
||||
LinkProperties linkProperties) {
|
||||
// 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.
|
||||
onAvailable(network);
|
||||
if (!networkCapabilities.hasCapability(
|
||||
NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED)) {
|
||||
onNetworkSuspended(network);
|
||||
}
|
||||
onCapabilitiesChanged(network, networkCapabilities);
|
||||
onLinkPropertiesChanged(network, linkProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the framework connects and has declared a new network ready for use.
|
||||
* 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)}.
|
||||
*
|
||||
* @param network The {@link Network} of the satisfying network.
|
||||
*/
|
||||
public void onAvailable(Network network) {}
|
||||
|
||||
@@ -2727,7 +2753,8 @@ public class ConnectivityManager {
|
||||
* changes capabilities but still satisfies the stated need.
|
||||
*
|
||||
* @param network The {@link Network} whose capabilities have changed.
|
||||
* @param networkCapabilities The new {@link android.net.NetworkCapabilities} for this network.
|
||||
* @param networkCapabilities The new {@link android.net.NetworkCapabilities} for this
|
||||
* network.
|
||||
*/
|
||||
public void onCapabilitiesChanged(Network network,
|
||||
NetworkCapabilities networkCapabilities) {}
|
||||
@@ -2743,7 +2770,7 @@ public class ConnectivityManager {
|
||||
|
||||
/**
|
||||
* Called when the network the framework connected to for this request
|
||||
* goes into {@link NetworkInfo.DetailedState.SUSPENDED}.
|
||||
* goes into {@link NetworkInfo.State#SUSPENDED}.
|
||||
* This generally means that while the TCP connections are still live,
|
||||
* temporarily network data fails to transfer. Specifically this is used
|
||||
* on cellular networks to mask temporary outages when driving through
|
||||
@@ -2754,9 +2781,8 @@ public class ConnectivityManager {
|
||||
|
||||
/**
|
||||
* Called when the network the framework connected to for this request
|
||||
* returns from a {@link NetworkInfo.DetailedState.SUSPENDED} state.
|
||||
* This should always be preceeded by a matching {@code onNetworkSuspended}
|
||||
* call.
|
||||
* returns from a {@link NetworkInfo.State#SUSPENDED} state. This should always be
|
||||
* preceded by a matching {@link NetworkCallback#onNetworkSuspended} call.
|
||||
* @hide
|
||||
*/
|
||||
public void onNetworkResumed(Network network) {}
|
||||
@@ -2865,7 +2891,9 @@ public class ConnectivityManager {
|
||||
break;
|
||||
}
|
||||
case CALLBACK_AVAILABLE: {
|
||||
callback.onAvailable(network);
|
||||
NetworkCapabilities cap = getObject(message, NetworkCapabilities.class);
|
||||
LinkProperties lp = getObject(message, LinkProperties.class);
|
||||
callback.onAvailable(network, cap, lp);
|
||||
break;
|
||||
}
|
||||
case CALLBACK_LOSING: {
|
||||
|
||||
@@ -116,6 +116,7 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
NET_CAPABILITY_NOT_ROAMING,
|
||||
NET_CAPABILITY_FOREGROUND,
|
||||
NET_CAPABILITY_NOT_CONGESTED,
|
||||
NET_CAPABILITY_NOT_SUSPENDED,
|
||||
})
|
||||
public @interface NetCapability { }
|
||||
|
||||
@@ -239,7 +240,6 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
/**
|
||||
* Indicates that this network is available for use by apps, and not a network that is being
|
||||
* kept up in the background to facilitate fast network switching.
|
||||
* @hide
|
||||
*/
|
||||
public static final int NET_CAPABILITY_FOREGROUND = 19;
|
||||
|
||||
@@ -252,8 +252,20 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
*/
|
||||
public static final int NET_CAPABILITY_NOT_CONGESTED = 20;
|
||||
|
||||
/**
|
||||
* Indicates that this network is not currently suspended.
|
||||
* <p>
|
||||
* When a network is suspended, the network's IP addresses and any connections
|
||||
* established on the network remain valid, but the network is temporarily unable
|
||||
* to transfer data. This can happen, for example, if a cellular network experiences
|
||||
* a temporary loss of signal, such as when driving through a tunnel, etc.
|
||||
* A network with this capability is not suspended, so is expected to be able to
|
||||
* transfer data.
|
||||
*/
|
||||
public static final int NET_CAPABILITY_NOT_SUSPENDED = 21;
|
||||
|
||||
private static final int MIN_NET_CAPABILITY = NET_CAPABILITY_MMS;
|
||||
private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_NOT_CONGESTED;
|
||||
private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_NOT_SUSPENDED;
|
||||
|
||||
/**
|
||||
* Network capabilities that are expected to be mutable, i.e., can change while a particular
|
||||
@@ -262,12 +274,13 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
private static final long MUTABLE_CAPABILITIES =
|
||||
// TRUSTED can change when user explicitly connects to an untrusted network in Settings.
|
||||
// http://b/18206275
|
||||
(1 << NET_CAPABILITY_TRUSTED) |
|
||||
(1 << NET_CAPABILITY_VALIDATED) |
|
||||
(1 << NET_CAPABILITY_CAPTIVE_PORTAL) |
|
||||
(1 << NET_CAPABILITY_NOT_ROAMING) |
|
||||
(1 << NET_CAPABILITY_FOREGROUND) |
|
||||
(1 << NET_CAPABILITY_NOT_CONGESTED);
|
||||
(1 << NET_CAPABILITY_TRUSTED)
|
||||
| (1 << NET_CAPABILITY_VALIDATED)
|
||||
| (1 << NET_CAPABILITY_CAPTIVE_PORTAL)
|
||||
| (1 << NET_CAPABILITY_NOT_ROAMING)
|
||||
| (1 << NET_CAPABILITY_FOREGROUND)
|
||||
| (1 << NET_CAPABILITY_NOT_CONGESTED)
|
||||
| (1 << NET_CAPABILITY_NOT_SUSPENDED);
|
||||
|
||||
/**
|
||||
* Network capabilities that are not allowed in NetworkRequests. This exists because the
|
||||
@@ -1276,6 +1289,7 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
case NET_CAPABILITY_NOT_ROAMING: return "NOT_ROAMING";
|
||||
case NET_CAPABILITY_FOREGROUND: return "FOREGROUND";
|
||||
case NET_CAPABILITY_NOT_CONGESTED: return "NOT_CONGESTED";
|
||||
case NET_CAPABILITY_NOT_SUSPENDED: return "NOT_SUSPENDED";
|
||||
default: return Integer.toString(capability);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user