Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f16d215 authored by junyulai's avatar junyulai
Browse files

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

Test: atest ConnectivityServiceTest#testRegisterBestMatchingNetworkCallback
Bug: 175662146
Change-Id: Ifa411c7b53da789c74fff7e1a95f9c9ebf5bd05c
parent a517079d
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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
+5 −0
Original line number Diff line number Diff line
@@ -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,
    };

    /**
+2 −0
Original line number Diff line number Diff line
@@ -5547,6 +5547,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
                //  request if the app changes network state. http://b/29964605
                enforceMeteredApnPolicy(networkCapabilities);
                break;
            case TRACK_BEST:
                throw new UnsupportedOperationException("Not implemented yet");
            default:
                throw new IllegalArgumentException("Unsupported request type " + reqType);
        }
+9 −1
Original line number Diff line number Diff line
@@ -11026,4 +11026,12 @@ public class ConnectivityServiceTest {
        verifyNoNetwork();
        mCm.unregisterNetworkCallback(cellCb);
    }
    @Test
    public void testRegisterBestMatchingNetworkCallback() throws Exception {
        final NetworkRequest request = new NetworkRequest.Builder().build();
        assertThrows(UnsupportedOperationException.class,
                () -> mCm.registerBestMatchingNetworkCallback(request, new NetworkCallback(),
                        mCsHandlerThread.getThreadHandler()));
    }
}