[NS05] Feed network offer callbacks
The design is very simply expressed :
An offer is needed for a request if and only if that offer
might beat the satisfier for that request.
The implementation of "might beat" is NetworkRanker#mightBeat.
Test: FrameworksNetTests FrameworksWifiTests NetworkStackTests
Bug: 167544279
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: I0fe911eef2483ecbac48c733d56283b81538690a
Change-Id: I0fe911eef2483ecbac48c733d56283b81538690a
(cherry-picked from 7b6a33bd504e88ac051db9511eafe915d80e7539)
diff --git a/framework/api/system-current.txt b/framework/api/system-current.txt
index 27bf114..f8ffb58 100644
--- a/framework/api/system-current.txt
+++ b/framework/api/system-current.txt
@@ -316,9 +316,16 @@
method public int getProviderId();
method public void onNetworkRequestWithdrawn(@NonNull android.net.NetworkRequest);
method public void onNetworkRequested(@NonNull android.net.NetworkRequest, @IntRange(from=0, to=99) int, int);
+ method @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public void registerNetworkOffer(@NonNull android.net.NetworkScore, @NonNull android.net.NetworkCapabilities, @NonNull java.util.concurrent.Executor, @NonNull android.net.NetworkProvider.NetworkOfferCallback);
+ method @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public void unregisterNetworkOffer(@NonNull android.net.NetworkProvider.NetworkOfferCallback);
field public static final int ID_NONE = -1; // 0xffffffff
}
+ public static interface NetworkProvider.NetworkOfferCallback {
+ method public void onNetworkNeeded(@NonNull android.net.NetworkRequest);
+ method public void onNetworkUnneeded(@NonNull android.net.NetworkRequest);
+ }
+
public class NetworkReleasedException extends java.lang.Exception {
}
diff --git a/framework/src/android/net/ConnectivityManager.java b/framework/src/android/net/ConnectivityManager.java
index a64a9e6..20f3853 100644
--- a/framework/src/android/net/ConnectivityManager.java
+++ b/framework/src/android/net/ConnectivityManager.java
@@ -3360,7 +3360,7 @@
* @param score The prospective score of the network.
* @param caps The prospective capabilities of the network.
* @param callback The callback to call when this offer is needed or unneeded.
- * @hide
+ * @hide exposed via the NetworkProvider class.
*/
@RequiresPermission(anyOf = {
NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
@@ -3383,7 +3383,7 @@
*
* @param callback The callback passed at registration time. This must be the same object
* that was passed to {@link #offerNetwork}
- * @hide
+ * @hide exposed via the NetworkProvider class.
*/
public void unofferNetwork(@NonNull final INetworkOfferCallback callback) {
try {
diff --git a/framework/src/android/net/INetworkOfferCallback.aidl b/framework/src/android/net/INetworkOfferCallback.aidl
index a6de173..ecfba21 100644
--- a/framework/src/android/net/INetworkOfferCallback.aidl
+++ b/framework/src/android/net/INetworkOfferCallback.aidl
@@ -51,10 +51,8 @@
/**
* Called when a network for this offer is needed to fulfill this request.
* @param networkRequest the request to satisfy
- * @param providerId the ID of the provider currently satisfying
- * this request, or NetworkProvider.ID_NONE if none.
*/
- void onNetworkNeeded(in NetworkRequest networkRequest, int providerId);
+ void onNetworkNeeded(in NetworkRequest networkRequest);
/**
* Informs the registrant that the offer is no longer valuable to fulfill this request.
diff --git a/framework/src/android/net/NetworkProvider.java b/framework/src/android/net/NetworkProvider.java
index d859022..cfb7325 100644
--- a/framework/src/android/net/NetworkProvider.java
+++ b/framework/src/android/net/NetworkProvider.java
@@ -168,12 +168,16 @@
}
/** @hide */
- // TODO : make @SystemApi when the impl is complete
+ @SystemApi
public interface NetworkOfferCallback {
- /** Called by the system when a network for this offer is needed to satisfy some
- * networking request. */
- void onNetworkNeeded(@NonNull NetworkRequest request, int providerId);
- /** Called by the system when this offer is no longer valuable for this request. */
+ /**
+ * Called by the system when a network for this offer is needed to satisfy some
+ * networking request.
+ */
+ void onNetworkNeeded(@NonNull NetworkRequest request);
+ /**
+ * Called by the system when this offer is no longer valuable for this request.
+ */
void onNetworkUnneeded(@NonNull NetworkRequest request);
}
@@ -188,9 +192,8 @@
}
@Override
- public void onNetworkNeeded(final @NonNull NetworkRequest request,
- final int providerId) {
- mExecutor.execute(() -> callback.onNetworkNeeded(request, providerId));
+ public void onNetworkNeeded(final @NonNull NetworkRequest request) {
+ mExecutor.execute(() -> callback.onNetworkNeeded(request));
}
@Override
@@ -254,8 +257,11 @@
*
* The capabilities and score act as filters as to what requests the provider will see.
* They are not promises, but for best performance, the providers should strive to put
- * as much known information as possible in the offer. For capabilities in particular, it
- * should put all NetworkAgent-managed capabilities a network may have, even if it doesn't
+ * as much known information as possible in the offer. For the score, it should put as
+ * strong a score as the networks will have, since this will filter what requests the
+ * provider sees – it's not a promise, it only serves to avoid sending requests that
+ * the provider can't ever hope to satisfy better than any current network. For capabilities,
+ * it should put all NetworkAgent-managed capabilities a network may have, even if it doesn't
* have them at first. This applies to INTERNET, for example ; if a provider thinks the
* network it can bring up for this offer may offer Internet access it should include the
* INTERNET bit. It's fine if the brought up network ends up not actually having INTERNET.
@@ -268,9 +274,9 @@
*
* @hide
*/
- // TODO : make @SystemApi when the impl is complete
+ @SystemApi
@RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
- public void offerNetwork(@NonNull final NetworkScore score,
+ public void registerNetworkOffer(@NonNull final NetworkScore score,
@NonNull final NetworkCapabilities caps, @NonNull final Executor executor,
@NonNull final NetworkOfferCallback callback) {
// Can't offer a network with a provider that is not yet registered or already unregistered.
@@ -307,9 +313,9 @@
*
* @hide
*/
- // TODO : make @SystemApi when the impl is complete
+ @SystemApi
@RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
- public void unofferNetwork(final @NonNull NetworkOfferCallback callback) {
+ public void unregisterNetworkOffer(final @NonNull NetworkOfferCallback callback) {
final NetworkOfferCallbackProxy proxy = findProxyForCallback(callback);
if (null == proxy) return;
mProxies.remove(proxy);