summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chiachang Wang <chiachangwang@google.com> 2021-03-22 17:24:11 +0800
committer Chiachang Wang <chiachangwang@google.com> 2021-03-22 13:05:10 +0000
commit26ab6df3c8ba96d1b59d6674b3f46976d0dad33b (patch)
tree6c16e12fca224c58e246d5cba09dea43797636d8
parent15615ed0f28b51d138d4379e83ca057190202370 (diff)
Add NetworkRequest.Builder creating from an existing instance
Provide a formal way to construct a new NetworkRequest from an existing instance. The network capabilities inside the NetworkRequest is hidden. There is no way to pass a NetworkRequest and update its capabilities. Add NetworkRequest.Builder creating from an existing instance to allow to clone the network capabilities. Bug: 172183305 Test: make update-api Change-Id: I068462b2a1410daf67b0c95f2b643d396f079531 CTS-Coverage-Bug: 172183305
-rw-r--r--packages/Connectivity/framework/api/current.txt1
-rw-r--r--packages/Connectivity/framework/src/android/net/NetworkRequest.java8
2 files changed, 9 insertions, 0 deletions
diff --git a/packages/Connectivity/framework/api/current.txt b/packages/Connectivity/framework/api/current.txt
index e415e01fea3a..ad44b27f6d0b 100644
--- a/packages/Connectivity/framework/api/current.txt
+++ b/packages/Connectivity/framework/api/current.txt
@@ -396,6 +396,7 @@ package android.net {
public static class NetworkRequest.Builder {
ctor public NetworkRequest.Builder();
+ ctor public NetworkRequest.Builder(@NonNull android.net.NetworkRequest);
method public android.net.NetworkRequest.Builder addCapability(int);
method public android.net.NetworkRequest.Builder addTransportType(int);
method public android.net.NetworkRequest build();
diff --git a/packages/Connectivity/framework/src/android/net/NetworkRequest.java b/packages/Connectivity/framework/src/android/net/NetworkRequest.java
index cf131f0df607..f9b3db12c087 100644
--- a/packages/Connectivity/framework/src/android/net/NetworkRequest.java
+++ b/packages/Connectivity/framework/src/android/net/NetworkRequest.java
@@ -216,6 +216,14 @@ public class NetworkRequest implements Parcelable {
}
/**
+ * Creates a new Builder of NetworkRequest from an existing instance.
+ */
+ public Builder(@NonNull final NetworkRequest request) {
+ Objects.requireNonNull(request);
+ mNetworkCapabilities = request.networkCapabilities;
+ }
+
+ /**
* Build {@link NetworkRequest} give the current set of capabilities.
*/
public NetworkRequest build() {