[VCN10] Add new API to listen for highest score network

Test: atest ConnectivityServiceTest#testRegisterBestMatchingNetworkCallback
Bug: 175662146
Change-Id: Ifa411c7b53da789c74fff7e1a95f9c9ebf5bd05c
This commit is contained in:
junyulai
2021-03-05 15:51:17 +08:00
parent e2e358f666
commit 5a5c99b84e
2 changed files with 18 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ import static android.net.IpSecManager.INVALID_RESOURCE_ID;
import static android.net.NetworkRequest.Type.BACKGROUND_REQUEST;
import static android.net.NetworkRequest.Type.LISTEN;
import static android.net.NetworkRequest.Type.REQUEST;
import static android.net.NetworkRequest.Type.TRACK_BEST;
import static android.net.NetworkRequest.Type.TRACK_DEFAULT;
import static android.net.NetworkRequest.Type.TRACK_SYSTEM_DEFAULT;
import static android.net.QosCallback.QosCallbackRegistrationException;
@@ -4189,6 +4190,18 @@ public class ConnectivityManager {
TRACK_SYSTEM_DEFAULT, TYPE_NONE, cbHandler);
}
/**
* @hide
*/
// TODO: Make it public api.
@SuppressLint("ExecutorRegistration")
public void registerBestMatchingNetworkCallback(@NonNull NetworkRequest request,
@NonNull NetworkCallback networkCallback, @NonNull Handler handler) {
final NetworkCapabilities nc = request.networkCapabilities;
final CallbackHandler cbHandler = new CallbackHandler(handler);
sendRequestForNetwork(nc, networkCallback, 0, TRACK_BEST, TYPE_NONE, cbHandler);
}
/**
* Requests bandwidth update for a given {@link Network} and returns whether the update request
* is accepted by ConnectivityService. Once accepted, ConnectivityService will poll underlying

View File

@@ -113,6 +113,10 @@ public class NetworkRequest implements Parcelable {
* for the network (if any) that satisfies the default Internet
* request.
*
* - TRACK_BEST, which causes the framework to send callbacks about
* the single, highest scoring current network (if any) that matches
* the specified NetworkCapabilities.
*
* - BACKGROUND_REQUEST, like REQUEST but does not cause any networks
* to retain the NET_CAPABILITY_FOREGROUND capability. A network with
* no foreground requests is in the background. A network that has
@@ -135,6 +139,7 @@ public class NetworkRequest implements Parcelable {
REQUEST,
BACKGROUND_REQUEST,
TRACK_SYSTEM_DEFAULT,
TRACK_BEST,
};
/**