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

Commit 8324c3e7 authored by Junyu Lai's avatar Junyu Lai Committed by Gerrit Code Review
Browse files

Merge "Fix SocketKeepalive APIs which do not meet API review requirement"

parents 743a4b78 0c666977
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -27116,7 +27116,7 @@ package android.net {
  public class ConnectivityManager {
    method public void addDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener);
    method public boolean bindProcessToNetwork(@Nullable android.net.Network);
    method public android.net.SocketKeepalive createSocketKeepalive(@NonNull android.net.Network, @NonNull android.net.IpSecManager.UdpEncapsulationSocket, @NonNull java.net.InetAddress, @NonNull java.net.InetAddress, @NonNull java.util.concurrent.Executor, @NonNull android.net.SocketKeepalive.Callback);
    method @NonNull public android.net.SocketKeepalive createSocketKeepalive(@NonNull android.net.Network, @NonNull android.net.IpSecManager.UdpEncapsulationSocket, @NonNull java.net.InetAddress, @NonNull java.net.InetAddress, @NonNull java.util.concurrent.Executor, @NonNull android.net.SocketKeepalive.Callback);
    method @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @Nullable public android.net.Network getActiveNetwork();
    method @Deprecated @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) public android.net.NetworkInfo getActiveNetworkInfo();
    method @Deprecated @NonNull @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) public android.net.NetworkInfo[] getAllNetworkInfo();
@@ -27194,7 +27194,7 @@ package android.net {
  public static class ConnectivityManager.NetworkCallback {
    ctor public ConnectivityManager.NetworkCallback();
    method public void onAvailable(android.net.Network);
    method public void onBlockedStatusChanged(android.net.Network, boolean);
    method public void onBlockedStatusChanged(@NonNull android.net.Network, boolean);
    method public void onCapabilitiesChanged(android.net.Network, android.net.NetworkCapabilities);
    method public void onLinkPropertiesChanged(android.net.Network, android.net.LinkProperties);
    method public void onLosing(android.net.Network, int);
@@ -27650,7 +27650,7 @@ package android.net {
    method public final void start(@IntRange(from=0xa, to=0xe10) int);
    method public final void stop();
    field public static final int ERROR_HARDWARE_ERROR = -31; // 0xffffffe1
    field public static final int ERROR_HARDWARE_UNSUPPORTED = -30; // 0xffffffe2
    field public static final int ERROR_INSUFFICIENT_RESOURCES = -32; // 0xffffffe0
    field public static final int ERROR_INVALID_INTERVAL = -24; // 0xffffffe8
    field public static final int ERROR_INVALID_IP_ADDRESS = -21; // 0xffffffeb
    field public static final int ERROR_INVALID_LENGTH = -23; // 0xffffffe9
@@ -27658,6 +27658,7 @@ package android.net {
    field public static final int ERROR_INVALID_PORT = -22; // 0xffffffea
    field public static final int ERROR_INVALID_SOCKET = -25; // 0xffffffe7
    field public static final int ERROR_SOCKET_NOT_IDLE = -26; // 0xffffffe6
    field public static final int ERROR_UNSUPPORTED = -30; // 0xffffffe2
  }
  public static class SocketKeepalive.Callback {
+2 −2
Original line number Diff line number Diff line
@@ -3094,8 +3094,8 @@ package android.net {
  }
  public class ConnectivityManager {
    method @RequiresPermission(android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD) public android.net.SocketKeepalive createNattKeepalive(@NonNull android.net.Network, @NonNull java.io.FileDescriptor, @NonNull java.net.InetAddress, @NonNull java.net.InetAddress, @NonNull java.util.concurrent.Executor, @NonNull android.net.SocketKeepalive.Callback);
    method @RequiresPermission(android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD) public android.net.SocketKeepalive createSocketKeepalive(@NonNull android.net.Network, @NonNull java.net.Socket, @NonNull java.util.concurrent.Executor, @NonNull android.net.SocketKeepalive.Callback);
    method @NonNull @RequiresPermission(android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD) public android.net.SocketKeepalive createNattKeepalive(@NonNull android.net.Network, @NonNull android.os.ParcelFileDescriptor, @NonNull java.net.InetAddress, @NonNull java.net.InetAddress, @NonNull java.util.concurrent.Executor, @NonNull android.net.SocketKeepalive.Callback);
    method @NonNull @RequiresPermission(android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD) public android.net.SocketKeepalive createSocketKeepalive(@NonNull android.net.Network, @NonNull java.net.Socket, @NonNull java.util.concurrent.Executor, @NonNull android.net.SocketKeepalive.Callback);
    method @RequiresPermission(android.Manifest.permission.LOCAL_MAC_ADDRESS) public String getCaptivePortalServerUrl();
    method @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) public void getLatestTetheringEntitlementResult(int, boolean, @NonNull java.util.concurrent.Executor, @NonNull android.net.ConnectivityManager.OnTetheringEntitlementResultListener);
    method @RequiresPermission(anyOf={android.Manifest.permission.TETHER_PRIVILEGED, android.Manifest.permission.WRITE_SETTINGS}) public boolean isTetheringSupported();
+40 −13
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.os.INetworkManagementService;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
@@ -64,6 +65,8 @@ import com.android.internal.util.Protocol;
import libcore.net.event.NetworkEventDispatcher;

import java.io.FileDescriptor;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.InetAddress;
@@ -1923,14 +1926,22 @@ public class ConnectivityManager {
     * @return A {@link SocketKeepalive} object that can be used to control the keepalive on the
     *         given socket.
     **/
    public SocketKeepalive createSocketKeepalive(@NonNull Network network,
    public @NonNull SocketKeepalive createSocketKeepalive(@NonNull Network network,
            @NonNull UdpEncapsulationSocket socket,
            @NonNull InetAddress source,
            @NonNull InetAddress destination,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull Callback callback) {
        return new NattSocketKeepalive(mService, network, socket.getFileDescriptor(),
            socket.getResourceId(), source, destination, executor, callback);
        ParcelFileDescriptor dup;
        try {
            dup = ParcelFileDescriptor.dup(socket.getFileDescriptor());
        } catch (IOException ignored) {
            // Construct an invalid fd, so that if the user later calls start(), it will fail with
            // ERROR_INVALID_SOCKET.
            dup = new ParcelFileDescriptor(new FileDescriptor());
        }
        return new NattSocketKeepalive(mService, network, dup, socket.getResourceId(), source,
                destination, executor, callback);
    }

    /**
@@ -1938,9 +1949,9 @@ public class ConnectivityManager {
     * by system apps which don't use IpSecService to create {@link UdpEncapsulationSocket}.
     *
     * @param network The {@link Network} the socket is on.
     * @param fd The {@link FileDescriptor} that needs to be kept alive. The provided
     *        {@link FileDescriptor} must be bound to a port and the keepalives will be sent from
     *        that port.
     * @param pfd The {@link ParcelFileDescriptor} that needs to be kept alive. The provided
     *        {@link ParcelFileDescriptor} must be bound to a port and the keepalives will be sent
     *        from that port.
     * @param source The source address of the {@link UdpEncapsulationSocket}.
     * @param destination The destination address of the {@link UdpEncapsulationSocket}. The
     *        keepalive packets will always be sent to port 4500 of the given {@code destination}.
@@ -1956,14 +1967,22 @@ public class ConnectivityManager {
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD)
    public SocketKeepalive createNattKeepalive(@NonNull Network network,
            @NonNull FileDescriptor fd,
    public @NonNull SocketKeepalive createNattKeepalive(@NonNull Network network,
            @NonNull ParcelFileDescriptor pfd,
            @NonNull InetAddress source,
            @NonNull InetAddress destination,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull Callback callback) {
        return new NattSocketKeepalive(mService, network, fd, INVALID_RESOURCE_ID /* Unused */,
                source, destination, executor, callback);
        ParcelFileDescriptor dup;
        try {
            dup = pfd.dup();
        } catch (IOException ignored) {
            // Construct an invalid fd, so that if the user later calls start(), it will fail with
            // ERROR_INVALID_SOCKET.
            dup = new ParcelFileDescriptor(new FileDescriptor());
        }
        return new NattSocketKeepalive(mService, network, dup,
                INVALID_RESOURCE_ID /* Unused */, source, destination, executor, callback);
    }

    /**
@@ -1987,11 +2006,19 @@ public class ConnectivityManager {
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD)
    public SocketKeepalive createSocketKeepalive(@NonNull Network network,
    public @NonNull SocketKeepalive createSocketKeepalive(@NonNull Network network,
            @NonNull Socket socket,
            @NonNull Executor executor,
            @NonNull Callback callback) {
        return new TcpSocketKeepalive(mService, network, socket, executor, callback);
        ParcelFileDescriptor dup;
        try {
            dup = ParcelFileDescriptor.fromSocket(socket);
        } catch (UncheckedIOException ignored) {
            // Construct an invalid fd, so that if the user later calls start(), it will fail with
            // ERROR_INVALID_SOCKET.
            dup = new ParcelFileDescriptor(new FileDescriptor());
        }
        return new TcpSocketKeepalive(mService, network, dup, executor, callback);
    }

    /**
@@ -3323,7 +3350,7 @@ public class ConnectivityManager {
         * @param network The {@link Network} whose blocked status has changed.
         * @param blocked The blocked status of this {@link Network}.
         */
        public void onBlockedStatusChanged(Network network, boolean blocked) {}
        public void onBlockedStatusChanged(@NonNull Network network, boolean blocked) {}

        private NetworkRequest networkRequest;
    }
+5 −8
Original line number Diff line number Diff line
@@ -17,10 +17,10 @@
package android.net;

import android.annotation.NonNull;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.util.Log;

import java.io.FileDescriptor;
import java.net.InetAddress;
import java.util.concurrent.Executor;

@@ -31,21 +31,19 @@ public final class NattSocketKeepalive extends SocketKeepalive {

    @NonNull private final InetAddress mSource;
    @NonNull private final InetAddress mDestination;
    @NonNull private final FileDescriptor mFd;
    private final int mResourceId;

    NattSocketKeepalive(@NonNull IConnectivityManager service,
            @NonNull Network network,
            @NonNull FileDescriptor fd,
            @NonNull ParcelFileDescriptor pfd,
            int resourceId,
            @NonNull InetAddress source,
            @NonNull InetAddress destination,
            @NonNull Executor executor,
            @NonNull Callback callback) {
        super(service, network, executor, callback);
        super(service, network, pfd, executor, callback);
        mSource = source;
        mDestination = destination;
        mFd = fd;
        mResourceId = resourceId;
    }

@@ -53,8 +51,8 @@ public final class NattSocketKeepalive extends SocketKeepalive {
    void startImpl(int intervalSec) {
        mExecutor.execute(() -> {
            try {
                mService.startNattKeepaliveWithFd(mNetwork, mFd, mResourceId, intervalSec,
                        mCallback,
                mService.startNattKeepaliveWithFd(mNetwork, mPfd.getFileDescriptor(), mResourceId,
                        intervalSec, mCallback,
                        mSource.getHostAddress(), mDestination.getHostAddress());
            } catch (RemoteException e) {
                Log.e(TAG, "Error starting socket keepalive: ", e);
@@ -75,6 +73,5 @@ public final class NattSocketKeepalive extends SocketKeepalive {
                throw e.rethrowFromSystemServer();
            }
        });

    }
}
+4 −4
Original line number Diff line number Diff line
@@ -488,14 +488,14 @@ public abstract class NetworkAgent extends Handler {
     * Requests that the network hardware send the specified packet at the specified interval.
     */
    protected void startSocketKeepalive(Message msg) {
        onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_HARDWARE_UNSUPPORTED);
        onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_UNSUPPORTED);
    }

    /**
     * Requests that the network hardware stops sending keepalive packets.
     */
    protected void stopSocketKeepalive(Message msg) {
        onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_HARDWARE_UNSUPPORTED);
        onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_UNSUPPORTED);
    }

    /**
@@ -511,7 +511,7 @@ public abstract class NetworkAgent extends Handler {
     * override this method.
     */
    protected void addKeepalivePacketFilter(Message msg) {
        onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_HARDWARE_UNSUPPORTED);
        onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_UNSUPPORTED);
    }

    /**
@@ -520,7 +520,7 @@ public abstract class NetworkAgent extends Handler {
     * must override this method.
     */
    protected void removeKeepalivePacketFilter(Message msg) {
        onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_HARDWARE_UNSUPPORTED);
        onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_UNSUPPORTED);
    }

    /**
Loading