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

Commit cd924e57 authored by junyulai's avatar junyulai Committed by Chalard Jean
Browse files

[KA04] Expose TCP socket keepalive API

The new set of API allows applications to request keepalives
offload for established TCP sockets over wifi.

However, the application must not write to or read from the
socket after calling this method, until specific callbacks are
called.

Bug: 114151147
Test: atest FrameworksNetTests FrameworksWifiTests NetworkStackTests

Change-Id: I3880505dbc35fefa34ef6c79555458ecf5d296a4
parent 00ca6045
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.TcpKeepalivePacketDataParcelable;
import android.net.apf.ApfGenerator.IllegalInstructionException;
import android.net.apf.ApfGenerator.Register;
import android.net.ip.IpClient.IpClientCallbacksWrapper;
@@ -1489,6 +1490,29 @@ public class ApfFilter {
        installNewProgramLocked();
    }

    /**
     * Add keepalive packet filter.
     *
     * @param slot The index used to access the filter.
     * @param pkt Parameters needed to compose the filter.
     */
    public synchronized void addKeepalivePacketFilter(int slot,
            TcpKeepalivePacketDataParcelable pkt) {
        // TODO: implement this.
        Log.e(TAG, "APF function is not implemented: addKeepalivePacketFilter(" + slot + ", "
                + pkt + ")");
    }

    /**
     * Remove keepalive packet filter.
     *
     * @param slot The index used to access the filter.
     */
    public synchronized void removeKeepalivePacketFilter(int slot) {
        // TODO: implement this.
        Log.e(TAG, "APF function is not implemented: removeKeepalivePacketFilter(" + slot + ")");
    }

    static public long counterValue(byte[] data, Counter counter)
            throws ArrayIndexOutOfBoundsException {
        // Follow the same wrap-around addressing scheme of the interpreter.
+47 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.net.shared.LinkPropertiesParcelableUtil.toStableParcelable

import static com.android.server.util.PermissionUtil.checkNetworkStackCallingPermission;

import android.annotation.NonNull;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.DhcpResults;
@@ -34,6 +35,7 @@ import android.net.ProvisioningConfigurationParcelable;
import android.net.ProxyInfo;
import android.net.ProxyInfoParcelable;
import android.net.RouteInfo;
import android.net.TcpKeepalivePacketDataParcelable;
import android.net.apf.ApfCapabilities;
import android.net.apf.ApfFilter;
import android.net.dhcp.DhcpClient;
@@ -292,6 +294,8 @@ public class IpClient extends StateMachine {
    private static final int EVENT_PROVISIONING_TIMEOUT           = 10;
    private static final int EVENT_DHCPACTION_TIMEOUT             = 11;
    private static final int EVENT_READ_PACKET_FILTER_COMPLETE    = 12;
    private static final int CMD_ADD_KEEPALIVE_PACKET_FILTER_TO_APF = 13;
    private static final int CMD_REMOVE_KEEPALIVE_PACKET_FILTER_FROM_APF = 14;

    // Internal commands to use instead of trying to call transitionTo() inside
    // a given State's enter() method. Calling transitionTo() from enter/exit
@@ -522,6 +526,16 @@ public class IpClient extends StateMachine {
            checkNetworkStackCallingPermission();
            IpClient.this.setMulticastFilter(enabled);
        }
        @Override
        public void addKeepalivePacketFilter(int slot, TcpKeepalivePacketDataParcelable pkt) {
            checkNetworkStackCallingPermission();
            IpClient.this.addKeepalivePacketFilter(slot, pkt);
        }
        @Override
        public void removeKeepalivePacketFilter(int slot) {
            checkNetworkStackCallingPermission();
            IpClient.this.removeKeepalivePacketFilter(slot);
        }
    }

    public String getInterfaceName() {
@@ -643,6 +657,22 @@ public class IpClient extends StateMachine {
        sendMessage(CMD_SET_MULTICAST_FILTER, enabled);
    }

    /**
     * Called by WifiStateMachine to add keepalive packet filter before setting up
     * keepalive offload.
     */
    public void addKeepalivePacketFilter(int slot, @NonNull TcpKeepalivePacketDataParcelable pkt) {
        sendMessage(CMD_ADD_KEEPALIVE_PACKET_FILTER_TO_APF, slot, 0 /* Unused */, pkt);
    }

    /**
     * Called by WifiStateMachine to remove keepalive packet filter after stopping keepalive
     * offload.
     */
    public void removeKeepalivePacketFilter(int slot) {
        sendMessage(CMD_REMOVE_KEEPALIVE_PACKET_FILTER_FROM_APF, slot, 0 /* Unused */);
    }

    /**
     * Dump logs of this IpClient.
     */
@@ -1512,6 +1542,23 @@ public class IpClient extends StateMachine {
                    break;
                }

                case CMD_ADD_KEEPALIVE_PACKET_FILTER_TO_APF: {
                    final int slot = msg.arg1;
                    if (mApfFilter != null) {
                        mApfFilter.addKeepalivePacketFilter(slot,
                                (TcpKeepalivePacketDataParcelable) msg.obj);
                    }
                    break;
                }

                case CMD_REMOVE_KEEPALIVE_PACKET_FILTER_FROM_APF: {
                    final int slot = msg.arg1;
                    if (mApfFilter != null) {
                        mApfFilter.removeKeepalivePacketFilter(slot);
                    }
                    break;
                }

                case EVENT_DHCPACTION_TIMEOUT:
                    stopDhcpAction();
                    break;
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ android_test {
        "libhidlbase",
        "libhidltransport",
        "libhwbinder",
        "libjsoncpp",
        "liblog",
        "liblzma",
        "libnativehelper",