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

Commit 6df7f126 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by android-build-merger
Browse files

Merge "Fix linter errors in IpServer and its dependencies" am: a9be76c3 am: 4adb05b6

am: c922a838

Change-Id: I4724c27872dc11eb53ed4561743a648ef87bf434
parents ee57097d c922a838
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -34,32 +34,53 @@ import java.util.ArrayList;
 * @hide
 */
public class TetheringDependencies {
    /**
     * Get a reference to the offload hardware interface to be used by tethering.
     */
    public OffloadHardwareInterface getOffloadHardwareInterface(Handler h, SharedLog log) {
        return new OffloadHardwareInterface(h, log);
    }

    /**
     * Get a reference to the UpstreamNetworkMonitor to be used by tethering.
     */
    public UpstreamNetworkMonitor getUpstreamNetworkMonitor(Context ctx, StateMachine target,
            SharedLog log, int what) {
        return new UpstreamNetworkMonitor(ctx, target, log, what);
    }

    /**
     * Get a reference to the IPv6TetheringCoordinator to be used by tethering.
     */
    public IPv6TetheringCoordinator getIPv6TetheringCoordinator(
            ArrayList<IpServer> notifyList, SharedLog log) {
        return new IPv6TetheringCoordinator(notifyList, log);
    }

    /**
     * Get dependencies to be used by IpServer.
     */
    public IpServer.Dependencies getIpServerDependencies() {
        return new IpServer.Dependencies();
    }

    /**
     * Indicates whether tethering is supported on the device.
     */
    public boolean isTetheringSupported() {
        return true;
    }

    /**
     * Get the NetworkRequest that should be fulfilled by the default network.
     */
    public NetworkRequest getDefaultNetworkRequest() {
        return null;
    }

    /**
     * Get a reference to the EntitlementManager to be used by tethering.
     */
    public EntitlementManager getEntitlementManager(Context ctx, SharedLog log,
            MockableSystemProperties systemProperties) {
        return new EntitlementManager(ctx, log, systemProperties);
+11 −1
Original line number Diff line number Diff line
@@ -58,6 +58,11 @@ public class DhcpLease {
        mHostname = hostname;
    }

    /**
     * Get the clientId associated with this lease, if any.
     *
     * <p>If the lease is not associated to a clientId, this returns null.
     */
    @Nullable
    public byte[] getClientId() {
        if (mClientId == null) {
@@ -97,6 +102,11 @@ public class DhcpLease {
                (hostname == null ? mHostname : hostname));
    }

    /**
     * Determine whether this lease matches a client with the specified parameters.
     * @param clientId clientId of the client if any, or null otherwise.
     * @param hwAddr Hardware address of the client.
     */
    public boolean matchesClient(@Nullable byte[] clientId, @NonNull MacAddress hwAddr) {
        if (mClientId != null) {
            return Arrays.equals(mClientId, clientId);
+4 −4
Original line number Diff line number Diff line
@@ -29,8 +29,8 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.net.IpPrefix;
import android.net.MacAddress;
import android.net.util.SharedLog;
import android.net.dhcp.DhcpServer.Clock;
import android.net.util.SharedLog;
import android.util.ArrayMap;

import java.net.Inet4Address;
@@ -117,7 +117,7 @@ class DhcpLeaseRepository {
     */
    private final LinkedHashMap<Inet4Address, Long> mDeclinedAddrs = new LinkedHashMap<>();

    public DhcpLeaseRepository(@NonNull IpPrefix prefix, @NonNull Set<Inet4Address> reservedAddrs,
    DhcpLeaseRepository(@NonNull IpPrefix prefix, @NonNull Set<Inet4Address> reservedAddrs,
            long leaseTimeMs, @NonNull SharedLog log, @NonNull Clock clock) {
        updateParams(prefix, reservedAddrs, leaseTimeMs);
        mLog = log;
@@ -250,8 +250,8 @@ class DhcpLeaseRepository {
                // reqAddr null (RENEWING/REBINDING): client renewing its own lease for clientAddr.
                // reqAddr set with sid not set (INIT-REBOOT): client verifying configuration.
                // In both cases, throw if clientAddr or reqAddr does not match the known lease.
                throw new InvalidAddressException("Incorrect address for client in " +
                        (reqAddr != null ? "INIT-REBOOT" : "RENEWING/REBINDING"));
                throw new InvalidAddressException("Incorrect address for client in "
                        + (reqAddr != null ? "INIT-REBOOT" : "RENEWING/REBINDING"));
            }
        }

+12 −12
Original line number Diff line number Diff line
@@ -32,32 +32,32 @@ import java.net.InetSocketAddress;
 */
abstract class DhcpPacketListener extends FdEventsReader<DhcpPacketListener.Payload> {
    static final class Payload {
        final byte[] bytes = new byte[DhcpPacket.MAX_LENGTH];
        Inet4Address srcAddr;
        int srcPort;
        protected final byte[] mBytes = new byte[DhcpPacket.MAX_LENGTH];
        protected Inet4Address mSrcAddr;
        protected int mSrcPort;
    }

    public DhcpPacketListener(@NonNull Handler handler) {
    DhcpPacketListener(@NonNull Handler handler) {
        super(handler, new Payload());
    }

    @Override
    protected int recvBufSize(@NonNull Payload buffer) {
        return buffer.bytes.length;
        return buffer.mBytes.length;
    }

    @Override
    protected final void handlePacket(@NonNull Payload recvbuf, int length) {
        if (recvbuf.srcAddr == null) {
        if (recvbuf.mSrcAddr == null) {
            return;
        }

        try {
            final DhcpPacket packet = DhcpPacket.decodeFullPacket(recvbuf.bytes, length,
            final DhcpPacket packet = DhcpPacket.decodeFullPacket(recvbuf.mBytes, length,
                    DhcpPacket.ENCAP_BOOTP);
            onReceive(packet, recvbuf.srcAddr, recvbuf.srcPort);
            onReceive(packet, recvbuf.mSrcAddr, recvbuf.mSrcPort);
        } catch (DhcpPacket.ParseException e) {
            logParseError(recvbuf.bytes, length, e);
            logParseError(recvbuf.mBytes, length, e);
        }
    }

@@ -66,11 +66,11 @@ abstract class DhcpPacketListener extends FdEventsReader<DhcpPacketListener.Payl
            throws Exception {
        final InetSocketAddress addr = new InetSocketAddress();
        final int read = Os.recvfrom(
                fd, packetBuffer.bytes, 0, packetBuffer.bytes.length, 0 /* flags */, addr);
                fd, packetBuffer.mBytes, 0, packetBuffer.mBytes.length, 0 /* flags */, addr);

        // Buffers with null srcAddr will be dropped in handlePacket()
        packetBuffer.srcAddr = inet4AddrOrNull(addr);
        packetBuffer.srcPort = addr.getPort();
        packetBuffer.mSrcAddr = inet4AddrOrNull(addr);
        packetBuffer.mSrcPort = addr.getPort();
        return read;
    }

+45 −6
Original line number Diff line number Diff line
@@ -101,6 +101,13 @@ public class DhcpServer {
    @NonNull
    private DhcpServingParams mServingParams;

    /**
     * Clock to be used by DhcpServer to track time for lease expiration.
     *
     * <p>The clock should track time as may be measured by clients obtaining a lease. It does not
     * need to be monotonous across restarts of the server as long as leases are cleared when the
     * server is stopped.
     */
    public static class Clock {
        /**
         * @see SystemClock#elapsedRealtime()
@@ -110,13 +117,43 @@ public class DhcpServer {
        }
    }

    /**
     * Dependencies for the DhcpServer. Useful to be mocked in tests.
     */
    public interface Dependencies {
        /**
         * Send a packet to the specified datagram socket.
         *
         * @param fd File descriptor of the socket.
         * @param buffer Data to be sent.
         * @param dst Destination address of the packet.
         */
        void sendPacket(@NonNull FileDescriptor fd, @NonNull ByteBuffer buffer,
                @NonNull InetAddress dst) throws ErrnoException, IOException;

        /**
         * Create a DhcpLeaseRepository for the server.
         * @param servingParams Parameters used to serve DHCP requests.
         * @param log Log to be used by the repository.
         * @param clock Clock that the repository must use to track time.
         */
        DhcpLeaseRepository makeLeaseRepository(@NonNull DhcpServingParams servingParams,
                @NonNull SharedLog log, @NonNull Clock clock);

        /**
         * Create a packet listener that will send packets to be processed.
         */
        DhcpPacketListener makePacketListener();

        /**
         * Create a clock that the server will use to track time.
         */
        Clock makeClock();

        /**
         * Add an entry to the ARP cache table.
         * @param fd Datagram socket file descriptor that must use the new entry.
         */
        void addArpEntry(@NonNull Inet4Address ipv4Addr, @NonNull MacAddress ethAddr,
                @NonNull String ifname, @NonNull FileDescriptor fd) throws IOException;
    }
@@ -212,7 +249,7 @@ public class DhcpServer {
    }

    private class ServerHandler extends Handler {
        public ServerHandler(@NonNull Looper looper) {
        ServerHandler(@NonNull Looper looper) {
            super(looper);
        }

@@ -496,22 +533,24 @@ public class DhcpServer {
    }

    private class PacketListener extends DhcpPacketListener {
        public PacketListener() {
        PacketListener() {
            super(mHandler);
        }

        @Override
        protected void onReceive(DhcpPacket packet, Inet4Address srcAddr, int srcPort) {
        protected void onReceive(@NonNull DhcpPacket packet, @NonNull Inet4Address srcAddr,
                int srcPort) {
            processPacket(packet, srcPort);
        }

        @Override
        protected void logError(String msg, Exception e) {
        protected void logError(@NonNull String msg, Exception e) {
            mLog.e("Error receiving packet: " + msg, e);
        }

        @Override
        protected void logParseError(byte[] packet, int length, DhcpPacket.ParseException e) {
        protected void logParseError(@NonNull byte[] packet, int length,
                @NonNull DhcpPacket.ParseException e) {
            mLog.e("Error parsing packet", e);
        }

Loading