summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorChalard Jean <jchalard@google.com>2020-03-18 22:59:05 +0900
committerChalard Jean <jchalard@google.com>2020-03-19 21:16:08 +0900
commit0f9e833ac35f34b949cc0b9a2808a1d3becb679c (patch)
tree5e054b654439d456171868ec120c7567f455a214 /service
parent27d2604a9a7c5673ba9c8779400d8a660093d7a9 (diff)
Create a builder for NetworkCapabilities.
This is in response to API council feedback. Bug: 151322799 Test: FrameworksWifiTests Change-Id: Ice50310e2f8d70c49144a97a73954d7936fab947
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/ClientModeImpl.java73
-rw-r--r--service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java71
2 files changed, 75 insertions, 69 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index f5f96a134..90e1c59d3 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -451,7 +451,7 @@ public class ClientModeImpl extends StateMachine {
private byte[] mRssiRanges;
// Used to filter out requests we couldn't possibly satisfy.
- private final NetworkCapabilities mNetworkCapabilitiesFilter = new NetworkCapabilities();
+ private final NetworkCapabilities mNetworkCapabilitiesFilter;
private final ExternalCallbackTracker<IActionListener> mProcessingActionListeners;
private final ExternalCallbackTracker<ITxPacketCountListener> mProcessingTxPacketCountListeners;
@@ -813,16 +813,18 @@ public class ClientModeImpl extends StateMachine {
mWifiMetrics, mWifiInfo, mWifiNative, mBssidBlocklistMonitor,
mWifiInjector.getWifiThreadRunner());
- mNetworkCapabilitiesFilter.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
- mNetworkCapabilitiesFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
- mNetworkCapabilitiesFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
- mNetworkCapabilitiesFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING);
- mNetworkCapabilitiesFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED);
- mNetworkCapabilitiesFilter.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);
- // TODO - needs to be a bit more dynamic
- mNetworkCapabilitiesFilter.setLinkUpstreamBandwidthKbps(1024 * 1024);
- mNetworkCapabilitiesFilter.setLinkDownstreamBandwidthKbps(1024 * 1024);
- mNetworkCapabilitiesFilter.setNetworkSpecifier(new MatchAllNetworkSpecifier());
+ mNetworkCapabilitiesFilter = new NetworkCapabilities.Builder()
+ .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
+ // TODO - needs to be a bit more dynamic
+ .setLinkUpstreamBandwidthKbps(1024 * 1024)
+ .setLinkDownstreamBandwidthKbps(1024 * 1024)
+ .setNetworkSpecifier(new MatchAllNetworkSpecifier())
+ .build();
// Make the network factories.
mNetworkFactory = mWifiInjector.makeWifiNetworkFactory(
mNetworkCapabilitiesFilter, mWifiConnectivityManager);
@@ -4333,43 +4335,42 @@ public class ClientModeImpl extends StateMachine {
}
private NetworkCapabilities getCapabilities(WifiConfiguration currentWifiConfiguration) {
- final NetworkCapabilities result = new NetworkCapabilities(mNetworkCapabilitiesFilter);
+ final NetworkCapabilities.Builder builder =
+ new NetworkCapabilities.Builder(mNetworkCapabilitiesFilter);
// MatchAllNetworkSpecifier set in the mNetworkCapabilitiesFilter should never be set in the
// agent's specifier.
- result.setNetworkSpecifier(null);
+ builder.setNetworkSpecifier(null);
if (currentWifiConfiguration == null) {
- return result;
+ return builder.build();
}
- if (!mWifiInfo.isTrusted()) {
- result.removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED);
+ if (mWifiInfo.isTrusted()) {
+ builder.addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED);
} else {
- result.addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED);
+ builder.removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED);
}
- result.setOwnerUid(currentWifiConfiguration.creatorUid);
- result.setAdministratorUids(new int[] {currentWifiConfiguration.creatorUid});
+ builder.setOwnerUid(currentWifiConfiguration.creatorUid);
+ builder.setAdministratorUids(new int[] {currentWifiConfiguration.creatorUid});
if (!WifiConfiguration.isMetered(currentWifiConfiguration, mWifiInfo)) {
- result.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
+ builder.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
} else {
- result.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
+ builder.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
}
if (mWifiInfo.getRssi() != WifiInfo.INVALID_RSSI) {
- result.setSignalStrength(mWifiInfo.getRssi());
+ builder.setSignalStrength(mWifiInfo.getRssi());
} else {
- result.setSignalStrength(NetworkCapabilities.SIGNAL_STRENGTH_UNSPECIFIED);
+ builder.setSignalStrength(NetworkCapabilities.SIGNAL_STRENGTH_UNSPECIFIED);
}
if (currentWifiConfiguration.osu) {
- result.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
+ builder.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
}
if (!mWifiInfo.getSSID().equals(WifiManager.UNKNOWN_SSID)) {
- result.setSSID(mWifiInfo.getSSID());
- } else {
- result.setSSID(null);
+ builder.setSsid(mWifiInfo.getSSID());
}
Pair<Integer, String> specificRequestUidAndPackageName =
mNetworkFactory.getSpecificNetworkRequestUidAndPackageName(
@@ -4377,19 +4378,19 @@ public class ClientModeImpl extends StateMachine {
// There is an active specific request.
if (specificRequestUidAndPackageName.first != Process.INVALID_UID) {
// Remove internet capability.
- result.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
+ builder.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
// Fill up the uid/packageName for this connection.
- result.setRequestorUid(specificRequestUidAndPackageName.first);
- result.setRequestorPackageName(specificRequestUidAndPackageName.second);
+ builder.setRequestorUid(specificRequestUidAndPackageName.first);
+ builder.setRequestorPackageName(specificRequestUidAndPackageName.second);
// Fill up the network agent specifier for this connection.
- result.setNetworkSpecifier(createNetworkAgentSpecifier(
+ builder.setNetworkSpecifier(createNetworkAgentSpecifier(
currentWifiConfiguration, getCurrentBSSID()));
}
- updateLinkBandwidth(result);
- return result;
+ updateLinkBandwidth(builder);
+ return builder.build();
}
- private void updateLinkBandwidth(NetworkCapabilities networkCapabilities) {
+ private void updateLinkBandwidth(NetworkCapabilities.Builder networkCapabilitiesBuilder) {
int rssiDbm = mWifiInfo.getRssi();
int txTputKbps = INVALID_THROUGHPUT;
int rxTputKbps = INVALID_THROUGHPUT;
@@ -4417,10 +4418,10 @@ public class ClientModeImpl extends StateMachine {
logd("rx tput in kbps: " + rxTputKbps);
}
if (txTputKbps > 0) {
- networkCapabilities.setLinkUpstreamBandwidthKbps(txTputKbps);
+ networkCapabilitiesBuilder.setLinkUpstreamBandwidthKbps(txTputKbps);
}
if (rxTputKbps > 0) {
- networkCapabilities.setLinkDownstreamBandwidthKbps(rxTputKbps);
+ networkCapabilitiesBuilder.setLinkDownstreamBandwidthKbps(rxTputKbps);
}
}
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
index 867587720..682af56f2 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java
@@ -104,7 +104,8 @@ public class WifiAwareDataPathStateManager {
private final WifiAwareStateManager mMgr;
private final Clock mClock;
public NetworkInterfaceWrapper mNiWrapper = new NetworkInterfaceWrapper();
- private static final NetworkCapabilities sNetworkCapabilitiesFilter = new NetworkCapabilities();
+ private static final NetworkCapabilities sNetworkCapabilitiesFilter =
+ makeNetworkCapabilitiesFilter();
private final Set<String> mInterfaces = new HashSet<>();
private final Map<WifiAwareNetworkSpecifier, AwareNetworkRequestInformation>
mNetworkRequestsCache = new ArrayMap<>();
@@ -125,6 +126,23 @@ public class WifiAwareDataPathStateManager {
mClock = clock;
}
+ private static NetworkCapabilities makeNetworkCapabilitiesFilter() {
+ return new NetworkCapabilities.Builder()
+ .addTransportType(NetworkCapabilities.TRANSPORT_WIFI_AWARE)
+ .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED)
+ .setNetworkSpecifier(new MatchAllNetworkSpecifier())
+ .setLinkUpstreamBandwidthKbps(NETWORK_FACTORY_BANDWIDTH_AVAIL)
+ .setLinkDownstreamBandwidthKbps(NETWORK_FACTORY_BANDWIDTH_AVAIL)
+ .setSignalStrength(NETWORK_FACTORY_SIGNAL_STRENGTH_AVAIL)
+ .build();
+ }
+
/**
* Initialize the Aware data-path state manager. Specifically register the network factory with
* connectivity service.
@@ -142,19 +160,6 @@ public class WifiAwareDataPathStateManager {
mLooper = looper;
mHandler = new Handler(mLooper);
- sNetworkCapabilitiesFilter.clearAll();
- sNetworkCapabilitiesFilter.addTransportType(NetworkCapabilities.TRANSPORT_WIFI_AWARE);
- sNetworkCapabilitiesFilter
- .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
- .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
- .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING)
- .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED)
- .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
- .addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED);
- sNetworkCapabilitiesFilter.setNetworkSpecifier(new MatchAllNetworkSpecifier());
- sNetworkCapabilitiesFilter.setLinkUpstreamBandwidthKbps(NETWORK_FACTORY_BANDWIDTH_AVAIL);
- sNetworkCapabilitiesFilter.setLinkDownstreamBandwidthKbps(NETWORK_FACTORY_BANDWIDTH_AVAIL);
- sNetworkCapabilitiesFilter.setSignalStrength(NETWORK_FACTORY_SIGNAL_STRENGTH_AVAIL);
mNetworkFactory = new WifiAwareNetworkFactory(looper, context, sNetworkCapabilitiesFilter);
mNetworkFactory.setScoreFilter(NETWORK_FACTORY_SCORE_AVAIL);
@@ -556,7 +561,7 @@ public class WifiAwareDataPathStateManager {
nnri.peerDataMac = mac;
nnri.channelInfo = channelInfo;
- NetworkCapabilities networkCapabilities = new NetworkCapabilities(
+ final NetworkCapabilities.Builder ncBuilder = new NetworkCapabilities.Builder(
sNetworkCapabilitiesFilter);
LinkProperties linkProperties = new LinkProperties();
@@ -625,17 +630,16 @@ public class WifiAwareDataPathStateManager {
}
if (nnri.peerIpv6 != null) {
- networkCapabilities.setTransportInfo(
- new WifiAwareNetworkInfo(nnri.peerIpv6, nnri.peerPort,
- nnri.peerTransportProtocol));
- }
- if (VDBG) {
- Log.v(TAG, "onDataPathConfirm: AwareNetworkInfo="
- + networkCapabilities.getTransportInfo());
+ final WifiAwareNetworkInfo ni = new WifiAwareNetworkInfo(
+ nnri.peerIpv6, nnri.peerPort, nnri.peerTransportProtocol);
+ ncBuilder.setTransportInfo(ni);
+ if (VDBG) {
+ Log.v(TAG, "onDataPathConfirm: AwareNetworkInfo=" + ni);
+ }
}
if (!mNiWrapper.configureAgentProperties(nnri, nnri.equivalentRequests, ndpId,
- networkCapabilities, linkProperties)) {
+ ncBuilder, linkProperties)) {
declareUnfullfillableAndEndDp(nnri, ndpId);
return networkSpecifier;
}
@@ -646,8 +650,8 @@ public class WifiAwareDataPathStateManager {
.build();
nnri.networkAgent = new WifiAwareNetworkAgent(mLooper, mContext,
- AGENT_TAG_PREFIX + nnri.ndpId,
- networkCapabilities, linkProperties, NETWORK_FACTORY_SCORE_AVAIL,
+ AGENT_TAG_PREFIX + nnri.ndpId, ncBuilder.build(),
+ linkProperties, NETWORK_FACTORY_SCORE_AVAIL,
naConfig, mNetworkFactory.getProvider(), nnri);
nnri.startValidationTimestamp = mClock.getElapsedSinceBootMillis();
handleAddressValidation(nnri, linkProperties, ndpId, networkSpecifier.isOutOfBand());
@@ -1206,16 +1210,17 @@ public class WifiAwareDataPathStateManager {
}
private NetworkCapabilities getNetworkCapabilities() {
- NetworkCapabilities nc = new NetworkCapabilities(sNetworkCapabilitiesFilter);
- nc.setNetworkSpecifier(new WifiAwareAgentNetworkSpecifier(
+ final NetworkCapabilities.Builder builder =
+ new NetworkCapabilities.Builder(sNetworkCapabilitiesFilter);
+ builder.setNetworkSpecifier(new WifiAwareAgentNetworkSpecifier(
equivalentRequests.stream()
.map(NetworkRequest::getNetworkSpecifier)
.toArray(WifiAwareNetworkSpecifier[]::new)));
if (peerIpv6 != null) {
- nc.setTransportInfo(
+ builder.setTransportInfo(
new WifiAwareNetworkInfo(peerIpv6, peerPort, peerTransportProtocol));
}
- return nc;
+ return builder.build();
}
/**
@@ -1471,7 +1476,7 @@ public class WifiAwareDataPathStateManager {
*/
public boolean configureAgentProperties(AwareNetworkRequestInformation nnri,
Set<NetworkRequest> networkRequests, int ndpId,
- NetworkCapabilities networkCapabilities, LinkProperties linkProperties) {
+ NetworkCapabilities.Builder ncBuilder, LinkProperties linkProperties) {
// find link-local address
InetAddress linkLocal = null;
NetworkInterface ni;
@@ -1507,9 +1512,9 @@ public class WifiAwareDataPathStateManager {
return false;
}
- networkCapabilities.setRequestorUid(nnri.uid);
- networkCapabilities.setRequestorPackageName(nnri.packageName);
- networkCapabilities.setNetworkSpecifier(new WifiAwareAgentNetworkSpecifier(
+ ncBuilder.setRequestorUid(nnri.uid);
+ ncBuilder.setRequestorPackageName(nnri.packageName);
+ ncBuilder.setNetworkSpecifier(new WifiAwareAgentNetworkSpecifier(
networkRequests.stream()
.map(NetworkRequest::getNetworkSpecifier)
.toArray(WifiAwareNetworkSpecifier[]::new)));