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

Commit 915460ff authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Automerger Merge Worker
Browse files

Merge changes I638ed5cd,I29f15571,I21a22ed1 am: 892589c5 am: 3df38d48 am: 114c3e30

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1648068

Change-Id: I6d897cdcfb5b0e4809a32312071eb77623754f94
parents a8456883 114c3e30
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ package android.net {
    method @Nullable public android.net.ProxyInfo getGlobalProxy();
    method @NonNull public static android.util.Range<java.lang.Integer> getIpSecNetIdRange();
    method @NonNull public static String getPrivateDnsMode(@NonNull android.content.Context);
    method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void registerDefaultNetworkCallbackAsUid(int, @NonNull android.net.ConnectivityManager.NetworkCallback, @NonNull android.os.Handler);
    method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_SETTINGS}) public void registerSystemDefaultNetworkCallback(@NonNull android.net.ConnectivityManager.NetworkCallback, @NonNull android.os.Handler);
    method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public void requestBackgroundNetwork(@NonNull android.net.NetworkRequest, @NonNull android.os.Handler, @NonNull android.net.ConnectivityManager.NetworkCallback);
    method @Deprecated public boolean requestRouteToHostAddress(int, java.net.InetAddress);
+44 −5
Original line number Diff line number Diff line
@@ -3704,8 +3704,9 @@ public class ConnectivityManager {
    private static final HashMap<NetworkRequest, NetworkCallback> sCallbacks = new HashMap<>();
    private static CallbackHandler sCallbackHandler;

    private NetworkRequest sendRequestForNetwork(NetworkCapabilities need, NetworkCallback callback,
            int timeoutMs, NetworkRequest.Type reqType, int legacyType, CallbackHandler handler) {
    private NetworkRequest sendRequestForNetwork(int asUid, NetworkCapabilities need,
            NetworkCallback callback, int timeoutMs, NetworkRequest.Type reqType, int legacyType,
            CallbackHandler handler) {
        printStackTrace();
        checkCallbackNotNull(callback);
        if (reqType != TRACK_DEFAULT && reqType != TRACK_SYSTEM_DEFAULT && need == null) {
@@ -3730,8 +3731,8 @@ public class ConnectivityManager {
                            getAttributionTag());
                } else {
                    request = mService.requestNetwork(
                            need, reqType.ordinal(), messenger, timeoutMs, binder, legacyType,
                            callbackFlags, callingPackageName, getAttributionTag());
                            asUid, need, reqType.ordinal(), messenger, timeoutMs, binder,
                            legacyType, callbackFlags, callingPackageName, getAttributionTag());
                }
                if (request != null) {
                    sCallbacks.put(request, callback);
@@ -3746,6 +3747,12 @@ public class ConnectivityManager {
        return request;
    }

    private NetworkRequest sendRequestForNetwork(NetworkCapabilities need, NetworkCallback callback,
            int timeoutMs, NetworkRequest.Type reqType, int legacyType, CallbackHandler handler) {
        return sendRequestForNetwork(Process.INVALID_UID, need, callback, timeoutMs, reqType,
                legacyType, handler);
    }

    /**
     * Helper function to request a network with a particular legacy type.
     *
@@ -4231,8 +4238,40 @@ public class ConnectivityManager {
    @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
    public void registerDefaultNetworkCallback(@NonNull NetworkCallback networkCallback,
            @NonNull Handler handler) {
        registerDefaultNetworkCallbackAsUid(Process.INVALID_UID, networkCallback, handler);
    }

    /**
     * Registers to receive notifications about changes in the default network for the specified
     * UID. This may be a physical network or a virtual network, such as a VPN that applies to the
     * UID. The callbacks will continue to be called until either the application exits or
     * {@link #unregisterNetworkCallback(NetworkCallback)} is called.
     *
     * <p>To avoid performance issues due to apps leaking callbacks, the system will limit the
     * number of outstanding requests to 100 per app (identified by their UID), shared with
     * all variants of this method, of {@link #requestNetwork} as well as
     * {@link ConnectivityDiagnosticsManager#registerConnectivityDiagnosticsCallback}.
     * Requesting a network with this method will count toward this limit. If this limit is
     * exceeded, an exception will be thrown. To avoid hitting this issue and to conserve resources,
     * make sure to unregister the callbacks with
     * {@link #unregisterNetworkCallback(NetworkCallback)}.
     *
     * @param uid the UID for which to track default network changes.
     * @param networkCallback The {@link NetworkCallback} that the system will call as the
     *                        UID's default network changes.
     * @param handler {@link Handler} to specify the thread upon which the callback will be invoked.
     * @throws RuntimeException if the app already has too many callbacks registered.
     * @hide
     */
    @SystemApi(client = MODULE_LIBRARIES)
    @SuppressLint({"ExecutorRegistration", "PairedRegistration"})
    @RequiresPermission(anyOf = {
            NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
            android.Manifest.permission.NETWORK_SETTINGS})
    public void registerDefaultNetworkCallbackAsUid(int uid,
            @NonNull NetworkCallback networkCallback, @NonNull Handler handler) {
        CallbackHandler cbHandler = new CallbackHandler(handler);
        sendRequestForNetwork(null /* NetworkCapabilities need */, networkCallback, 0,
        sendRequestForNetwork(uid, null /* need */, networkCallback, 0 /* timeoutMs */,
                TRACK_DEFAULT, TYPE_NONE, cbHandler);
    }

+1 −1
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ interface IConnectivityManager
            in NetworkCapabilities nc, in NetworkScore score, in NetworkAgentConfig config,
            in int factorySerialNumber);

    NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities, int reqType,
    NetworkRequest requestNetwork(int uid, in NetworkCapabilities networkCapabilities, int reqType,
            in Messenger messenger, int timeoutSec, in IBinder binder, int legacy,
            int callbackFlags, String callingPackageName, String callingAttributionTag);

Loading