[NS04.8] Address comments from NS04 and NS04.5

Bug: 167544279
Test: ConnectivityServiceTest
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: Ia930b3d3e723075cb47e267d589c576ee2d4490f
Change-Id: Ia930b3d3e723075cb47e267d589c576ee2d4490f
  (cherry-picked from ag/13982288)
This commit is contained in:
Chalard Jean
2021-03-24 17:43:10 +09:00
committed by Junyu Lai
parent dd35f2dab0
commit a88fd95294
3 changed files with 46 additions and 43 deletions

View File

@@ -3341,9 +3341,10 @@ public class ConnectivityManager {
* Register or update a network offer with ConnectivityService. * Register or update a network offer with ConnectivityService.
* *
* ConnectivityService keeps track of offers made by the various providers and matches * ConnectivityService keeps track of offers made by the various providers and matches
* them to networking requests made by apps or the system. The provider supplies a score * them to networking requests made by apps or the system. A callback identifies an offer
* and the capabilities of the network it might be able to bring up ; these act as filters * uniquely, and later calls with the same callback update the offer. The provider supplies a
* used by ConnectivityService to only send those requests that can be fulfilled by the * score and the capabilities of the network it might be able to bring up ; these act as
* filters used by ConnectivityService to only send those requests that can be fulfilled by the
* provider. * provider.
* *
* The provider is under no obligation to be able to bring up the network it offers at any * The provider is under no obligation to be able to bring up the network it offers at any

View File

@@ -22,15 +22,16 @@ import android.net.NetworkRequest;
* A callback registered with connectivity by network providers together with * A callback registered with connectivity by network providers together with
* a NetworkOffer. * a NetworkOffer.
* *
* When the offer is needed to satisfy some application or system component, * When the network for this offer is needed to satisfy some application or
* connectivity will call onOfferNeeded on this callback. When this happens, * system component, connectivity will call onNetworkNeeded on this callback.
* the provider should try and bring up the network. * When this happens, the provider should try and bring up the network.
* *
* When the offer is no longer needed, for example because the application has * When the network for this offer is no longer needed, for example because
* withdrawn the request or if the request is being satisfied by a network * the application has withdrawn the request or if the request is being
* that this offer will never be able to beat, connectivity calls * satisfied by a network that this offer will never be able to beat,
* onOfferUnneeded. When this happens, the provider should stop trying to * connectivity calls onNetworkUnneeded. When this happens, the provider
* bring up the network, or tear it down if it has already been brought up. * should stop trying to bring up the network, or tear it down if it has
* already been brought up.
* *
* When NetworkProvider#offerNetwork is called, the provider can expect to * When NetworkProvider#offerNetwork is called, the provider can expect to
* immediately receive all requests that can be fulfilled by that offer and * immediately receive all requests that can be fulfilled by that offer and
@@ -38,25 +39,25 @@ import android.net.NetworkRequest;
* request is currently outstanding, because no requests have been made that * request is currently outstanding, because no requests have been made that
* can be satisfied by this offer, or because all such requests are already * can be satisfied by this offer, or because all such requests are already
* satisfied by a better network. * satisfied by a better network.
* onOfferNeeded can be called at any time after registration and until the * onNetworkNeeded can be called at any time after registration and until the
* offer is withdrawn with NetworkProvider#unofferNetwork is called. This * offer is withdrawn with NetworkProvider#unofferNetwork is called. This
* typically happens when a new network request is filed by an application, * typically happens when a new network request is filed by an application,
* or when the network satisfying a request disconnects and this offer now * or when the network satisfying a request disconnects and this offer now
* stands a chance to be the best network for it. * stands a chance to supply the best network for it.
* *
* @hide * @hide
*/ */
oneway interface INetworkOfferCallback { oneway interface INetworkOfferCallback {
/** /**
* Informs the registrant that the offer is needed to fulfill this request. * Called when a network for this offer is needed to fulfill this request.
* @param networkRequest the request to satisfy * @param networkRequest the request to satisfy
* @param providerId the ID of the provider currently satisfying * @param providerId the ID of the provider currently satisfying
* this request, or NetworkProvider.ID_NONE if none. * this request, or NetworkProvider.ID_NONE if none.
*/ */
void onOfferNeeded(in NetworkRequest networkRequest, int providerId); void onNetworkNeeded(in NetworkRequest networkRequest, int providerId);
/** /**
* Informs the registrant that the offer is no longer needed to fulfill this request. * Informs the registrant that the offer is no longer valuable to fulfill this request.
*/ */
void onOfferUnneeded(in NetworkRequest networkRequest); void onNetworkUnneeded(in NetworkRequest networkRequest);
} }

View File

@@ -170,10 +170,11 @@ public class NetworkProvider {
/** @hide */ /** @hide */
// TODO : make @SystemApi when the impl is complete // TODO : make @SystemApi when the impl is complete
public interface NetworkOfferCallback { public interface NetworkOfferCallback {
/** Called by the system when this offer is needed to satisfy some networking request. */ /** Called by the system when a network for this offer is needed to satisfy some
void onOfferNeeded(@NonNull NetworkRequest request, int providerId); * networking request. */
/** Called by the system when this offer is no longer needed. */ void onNetworkNeeded(@NonNull NetworkRequest request, int providerId);
void onOfferUnneeded(@NonNull NetworkRequest request); /** Called by the system when this offer is no longer valuable for this request. */
void onNetworkUnneeded(@NonNull NetworkRequest request);
} }
private class NetworkOfferCallbackProxy extends INetworkOfferCallback.Stub { private class NetworkOfferCallbackProxy extends INetworkOfferCallback.Stub {
@@ -187,14 +188,14 @@ public class NetworkProvider {
} }
@Override @Override
public void onOfferNeeded(final @NonNull NetworkRequest request, public void onNetworkNeeded(final @NonNull NetworkRequest request,
final int providerId) { final int providerId) {
mExecutor.execute(() -> callback.onOfferNeeded(request, providerId)); mExecutor.execute(() -> callback.onNetworkNeeded(request, providerId));
} }
@Override @Override
public void onOfferUnneeded(final @NonNull NetworkRequest request) { public void onNetworkUnneeded(final @NonNull NetworkRequest request) {
mExecutor.execute(() -> callback.onOfferUnneeded(request)); mExecutor.execute(() -> callback.onNetworkUnneeded(request));
} }
} }
@@ -213,41 +214,41 @@ public class NetworkProvider {
} }
/** /**
* Register or update an offer for network with the passed caps and score. * Register or update an offer for network with the passed capabilities and score.
* *
* A NetworkProvider's job is to provide networks. This function is how a provider tells the * A NetworkProvider's role is to provide networks. This method is how a provider tells the
* connectivity stack what kind of network it may provide. The score and caps arguments act * connectivity stack what kind of network it may provide. The score and caps arguments act
* as filters that the connectivity stack uses to tell when the offer is necessary. When an * as filters that the connectivity stack uses to tell when the offer is valuable. When an
* offer might be advantageous over existing networks, the provider will receive a call to * offer might be preferred over existing networks, the provider will receive a call to
* the associated callback's {@link NetworkOfferCallback#onOfferNeeded} method. The provider * the associated callback's {@link NetworkOfferCallback#onNetworkNeeded} method. The provider
* should then try to bring up this network. When an offer is no longer needed, the stack * should then try to bring up this network. When an offer is no longer useful, the stack
* will inform the provider by calling {@link NetworkOfferCallback#onOfferUnneeded}. The * will inform the provider by calling {@link NetworkOfferCallback#onNetworkUnneeded}. The
* provider should stop trying to bring up such a network, or disconnect it if it already has * provider should stop trying to bring up such a network, or disconnect it if it already has
* one. * one.
* *
* The stack determines what offers are needed according to what networks are currently * The stack determines what offers are valuable according to what networks are currently
* available to the system, and what networking requests are made by applications. If an * available to the system, and what networking requests are made by applications. If an
* offer looks like it could be a better choice than any existing network for any particular * offer looks like it could connect a better network than any existing network for any
* request, that's when the stack decides the offer is needed. If the current networking * particular request, that's when the stack decides the network is needed. If the current
* requests are all satisfied by networks that this offer can't possibly be a better match * networking requests are all satisfied by networks that this offer couldn't possibly be a
* for, that's when the offer is unneeded. An offer starts off as unneeded ; the provider * better match for, that's when the offer is no longer valuable. An offer starts out as
* should not try to bring up the network until {@link NetworkOfferCallback#onOfferNeeded} * unneeded ; the provider should not try to bring up the network until
* is called. * {@link NetworkOfferCallback#onNetworkNeeded} is called.
* *
* Note that the offers are non-binding to the providers, in particular because providers * Note that the offers are non-binding to the providers, in particular because providers
* often don't know if they will be able to bring up such a network at any given time. For * often don't know if they will be able to bring up such a network at any given time. For
* example, no wireless network may be in range when the offer is needed. This is fine and * example, no wireless network may be in range when the offer would be valuable. This is fine
* expected ; the provider should simply continue to try to bring up the network and do so * and expected ; the provider should simply continue to try to bring up the network and do so
* if/when it becomes possible. In the mean time, the stack will continue to satisfy requests * if/when it becomes possible. In the mean time, the stack will continue to satisfy requests
* with the best network currently available, or if none, keep the apps informed that no * with the best network currently available, or if none, keep the apps informed that no
* network can currently satisfy this request. When/if the provider can bring up the network, * network can currently satisfy this request. When/if the provider can bring up the network,
* the connectivity stack will match it against requests, and inform interested apps of the * the connectivity stack will match it against requests, and inform interested apps of the
* availability of this network. This may, in turn, render the offer of some other provider * availability of this network. This may, in turn, render the offer of some other provider
* unneeded if all requests it used to satisfy are now better served by this network. * low-value if all requests it used to satisfy are now better served by this network.
* *
* A network can become unneeded for a reason like the above : whether the provider managed * A network can become unneeded for a reason like the above : whether the provider managed
* to bring up the offered network after it became needed or not, some other provider may * to bring up the offered network after it became needed or not, some other provider may
* bring up a better network than this one, making this offer unneeded. A network may also * bring up a better network than this one, making this network unneeded. A network may also
* become unneeded if the application making the request withdrew it (for example, after it * become unneeded if the application making the request withdrew it (for example, after it
* is done transferring data, or if the user canceled an operation). * is done transferring data, or if the user canceled an operation).
* *