Merge "Allow NetworkFactories to match any network specifier on a request" into mm-wireless-dev

This commit is contained in:
Etan Cohen 2016-01-28 18:20:09 +00:00 • committed by Android Partner Code Review
commit c4752acb32
2 changed files with 58 additions and 1 deletions

View file

@ -196,6 +196,19 @@ public final class NetworkCapabilities implements Parcelable {
(1 << NET_CAPABILITY_VALIDATED) |
(1 << NET_CAPABILITY_CAPTIVE_PORTAL);
/**
* Network specifier for factories which want to match any network specifier
* (NS) in a request. Behavior:
* <li>Empty NS in request matches any network factory NS</li>
* <li>Empty NS in the network factory NS only matches a request with an
* empty NS</li>
* <li>"*" (this constant) NS in the network factory matches requests with
* any NS</li>
*
* @hide
*/
public static final String MATCH_ALL_REQUESTS_NETWORK_SPECIFIER = "*";
/**
* Network capabilities that are not allowed in NetworkRequests. This exists because the
* NetworkFactory / NetworkAgent model does not deal well with the situation where a
@ -596,7 +609,8 @@ public final class NetworkCapabilities implements Parcelable {
}
private boolean satisfiedBySpecifier(NetworkCapabilities nc) {
return (TextUtils.isEmpty(mNetworkSpecifier) ||
mNetworkSpecifier.equals(nc.mNetworkSpecifier));
mNetworkSpecifier.equals(nc.mNetworkSpecifier) ||
MATCH_ALL_REQUESTS_NETWORK_SPECIFIER.equals(nc.mNetworkSpecifier));
}
private boolean equalsSpecifier(NetworkCapabilities nc) {
if (TextUtils.isEmpty(mNetworkSpecifier)) {

View file

@ -188,6 +188,10 @@ public class NetworkRequest implements Parcelable {
* networks.
*/
public Builder setNetworkSpecifier(String networkSpecifier) {
if (NetworkCapabilities.MATCH_ALL_REQUESTS_NETWORK_SPECIFIER.equals(networkSpecifier)) {
throw new IllegalArgumentException("Invalid network specifier - must not be '"
+ NetworkCapabilities.MATCH_ALL_REQUESTS_NETWORK_SPECIFIER + "'");
}
mNetworkCapabilities.setNetworkSpecifier(networkSpecifier);
return this;
}