Add hidden constants for communicating about local network agents
Test: FrameworksNetTests Change-Id: Ic490fee6ee70d74acff0a290199b2946817173d0
This commit is contained in:
@@ -453,6 +453,7 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
NET_CAPABILITY_MMTEL,
|
||||
NET_CAPABILITY_PRIORITIZE_LATENCY,
|
||||
NET_CAPABILITY_PRIORITIZE_BANDWIDTH,
|
||||
NET_CAPABILITY_LOCAL_NETWORK,
|
||||
})
|
||||
public @interface NetCapability { }
|
||||
|
||||
@@ -714,7 +715,21 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
*/
|
||||
public static final int NET_CAPABILITY_PRIORITIZE_BANDWIDTH = 35;
|
||||
|
||||
private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_PRIORITIZE_BANDWIDTH;
|
||||
/**
|
||||
* This is a local network, e.g. a tethering downstream or a P2P direct network.
|
||||
*
|
||||
* <p>
|
||||
* Note that local networks are not sent to callbacks by default. To receive callbacks about
|
||||
* them, the {@link NetworkRequest} instance must be prepared to see them, either by
|
||||
* adding the capability with {@link NetworkRequest.Builder#addCapability}, by removing
|
||||
* this forbidden capability with {@link NetworkRequest.Builder#removeForbiddenCapability},
|
||||
* or by clearing all capabilites with {@link NetworkRequest.Builder#clearCapabilities()}.
|
||||
* </p>
|
||||
* @hide
|
||||
*/
|
||||
public static final int NET_CAPABILITY_LOCAL_NETWORK = 36;
|
||||
|
||||
private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_LOCAL_NETWORK;
|
||||
|
||||
// Set all bits up to the MAX_NET_CAPABILITY-th bit
|
||||
private static final long ALL_VALID_CAPABILITIES = (2L << MAX_NET_CAPABILITY) - 1;
|
||||
@@ -859,7 +874,7 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes (if found) the given forbidden capability from this {@code NetworkCapability}
|
||||
* Removes (if found) the given forbidden capability from this {@link NetworkCapabilities}
|
||||
* instance that were added via addForbiddenCapability(int) or setCapabilities(int[], int[]).
|
||||
*
|
||||
* @param capability the capability to be removed.
|
||||
@@ -872,6 +887,16 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all forbidden capabilities from this {@link NetworkCapabilities} instance.
|
||||
* @return This NetworkCapabilities instance, to facilitate chaining.
|
||||
* @hide
|
||||
*/
|
||||
public @NonNull NetworkCapabilities removeAllForbiddenCapabilities() {
|
||||
mForbiddenNetworkCapabilities = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets (or clears) the given capability on this {@link NetworkCapabilities}
|
||||
* instance.
|
||||
@@ -1039,11 +1064,12 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this NetworkCapabilities has system managed capabilities or not.
|
||||
* Check if this NetworkCapabilities has connectivity-managed capabilities or not.
|
||||
* @hide
|
||||
*/
|
||||
public boolean hasConnectivityManagedCapability() {
|
||||
return ((mNetworkCapabilities & CONNECTIVITY_MANAGED_CAPABILITIES) != 0);
|
||||
return (mNetworkCapabilities & CONNECTIVITY_MANAGED_CAPABILITIES) != 0
|
||||
|| mForbiddenNetworkCapabilities != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2523,6 +2549,7 @@ public final class NetworkCapabilities implements Parcelable {
|
||||
case NET_CAPABILITY_MMTEL: return "MMTEL";
|
||||
case NET_CAPABILITY_PRIORITIZE_LATENCY: return "PRIORITIZE_LATENCY";
|
||||
case NET_CAPABILITY_PRIORITIZE_BANDWIDTH: return "PRIORITIZE_BANDWIDTH";
|
||||
case NET_CAPABILITY_LOCAL_NETWORK: return "LOCAL_NETWORK";
|
||||
default: return Integer.toString(capability);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_FOREGROUND;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_LOCAL_NETWORK;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED;
|
||||
@@ -283,6 +284,15 @@ public class NetworkRequest implements Parcelable {
|
||||
NET_CAPABILITY_TRUSTED,
|
||||
NET_CAPABILITY_VALIDATED);
|
||||
|
||||
/**
|
||||
* Capabilities that are forbidden by default.
|
||||
* Forbidden capabilities only make sense in NetworkRequest, not for network agents.
|
||||
* Therefore these capabilities are only in NetworkRequest.
|
||||
*/
|
||||
private static final int[] DEFAULT_FORBIDDEN_CAPABILITIES = new int[] {
|
||||
NET_CAPABILITY_LOCAL_NETWORK
|
||||
};
|
||||
|
||||
private final NetworkCapabilities mNetworkCapabilities;
|
||||
|
||||
// A boolean that represents whether the NOT_VCN_MANAGED capability should be deduced when
|
||||
@@ -298,6 +308,16 @@ public class NetworkRequest implements Parcelable {
|
||||
// it for apps that do not have the NETWORK_SETTINGS permission.
|
||||
mNetworkCapabilities = new NetworkCapabilities();
|
||||
mNetworkCapabilities.setSingleUid(Process.myUid());
|
||||
// Default forbidden capabilities are foremost meant to help with backward
|
||||
// compatibility. When adding new types of network identified by a capability that
|
||||
// might confuse older apps, a default forbidden capability will have apps not see
|
||||
// these networks unless they explicitly ask for it.
|
||||
// If the app called clearCapabilities() it will see everything, but then it
|
||||
// can be argued that it's fair to send them too, since it asked for everything
|
||||
// explicitly.
|
||||
for (final int forbiddenCap : DEFAULT_FORBIDDEN_CAPABILITIES) {
|
||||
mNetworkCapabilities.addForbiddenCapability(forbiddenCap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,8 @@ public final class NetworkScore implements Parcelable {
|
||||
@IntDef(value = {
|
||||
KEEP_CONNECTED_NONE,
|
||||
KEEP_CONNECTED_FOR_HANDOVER,
|
||||
KEEP_CONNECTED_FOR_TEST
|
||||
KEEP_CONNECTED_FOR_TEST,
|
||||
KEEP_CONNECTED_DOWNSTREAM_NETWORK
|
||||
})
|
||||
public @interface KeepConnectedReason { }
|
||||
|
||||
@@ -64,6 +65,12 @@ public final class NetworkScore implements Parcelable {
|
||||
* @hide
|
||||
*/
|
||||
public static final int KEEP_CONNECTED_FOR_TEST = 2;
|
||||
/**
|
||||
* Keep this network connected even if there is no outstanding request for it, because
|
||||
* it is a downstream network.
|
||||
* @hide
|
||||
*/
|
||||
public static final int KEEP_CONNECTED_DOWNSTREAM_NETWORK = 3;
|
||||
|
||||
// Agent-managed policies
|
||||
// This network should lose to a wifi that has ever been validated
|
||||
|
||||
Reference in New Issue
Block a user