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

Commit a13007ad authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

Add DhcpServer

This first version can serve discover/request/release, although there
are some small behavior changes with current implementation which will
be addressed later.

Also removes final modifiers on start() and stop() in FdEventsReader, to
allow mocking the methods in tests with the current mockito lib.

Test: Added tests pass, manual: flashed a device using the server
Change-Id: I025366ff7d51c4ba31152af50f3dd2b5e280a54d
parent a7587203
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -139,6 +139,8 @@ public class TrafficStats {
    public static final int TAG_SYSTEM_GPS = 0xFFFFFF44;
    public static final int TAG_SYSTEM_GPS = 0xFFFFFF44;
    /** @hide */
    /** @hide */
    public static final int TAG_SYSTEM_PAC = 0xFFFFFF45;
    public static final int TAG_SYSTEM_PAC = 0xFFFFFF45;
    /** @hide */
    public static final int TAG_SYSTEM_DHCP_SERVER = 0xFFFFFF46;


    private static INetworkStatsService sStatsService;
    private static INetworkStatsService sStatsService;


+1 −10
Original line number Original line Diff line number Diff line
@@ -29,7 +29,7 @@ import android.annotation.Nullable;
import android.net.IpPrefix;
import android.net.IpPrefix;
import android.net.MacAddress;
import android.net.MacAddress;
import android.net.util.SharedLog;
import android.net.util.SharedLog;
import android.os.SystemClock;
import android.net.dhcp.DhcpServer.Clock;
import android.util.ArrayMap;
import android.util.ArrayMap;


import java.net.Inet4Address;
import java.net.Inet4Address;
@@ -73,15 +73,6 @@ class DhcpLeaseRepository {
    private int mNumAddresses;
    private int mNumAddresses;
    private long mLeaseTimeMs;
    private long mLeaseTimeMs;


    public static class Clock {
        /**
         * @see SystemClock#elapsedRealtime()
         */
        public long elapsedRealtime() {
            return SystemClock.elapsedRealtime();
        }
    }

    /**
    /**
     * Next timestamp when committed or declined leases should be checked for expired ones. This
     * Next timestamp when committed or declined leases should be checked for expired ones. This
     * will always be lower than or equal to the time for the first lease to expire: it's OK not to
     * will always be lower than or equal to the time for the first lease to expire: it's OK not to
+9 −0
Original line number Original line Diff line number Diff line
@@ -9,6 +9,7 @@ import android.os.Build;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.system.OsConstants;
import android.system.OsConstants;
import android.text.TextUtils;
import android.text.TextUtils;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;


import java.io.UnsupportedEncodingException;
import java.io.UnsupportedEncodingException;
@@ -350,6 +351,14 @@ public abstract class DhcpPacket {
        return mClientId != null;
        return mClientId != null;
    }
    }


    /**
     * Convenience method to return the client ID if it was set explicitly, or null otherwise.
     */
    @Nullable
    public byte[] getExplicitClientIdOrNull() {
        return hasExplicitClientId() ? getClientId() : null;
    }

    /**
    /**
     * Returns the client ID. If not set explicitly, this follows RFC 2132 and creates a client ID
     * Returns the client ID. If not set explicitly, this follows RFC 2132 and creates a client ID
     * based on the hardware address.
     * based on the hardware address.
+511 −0

File added.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Original line Diff line number Diff line
@@ -89,7 +89,7 @@ public abstract class FdEventsReader<BufferType> {
        mBuffer = buffer;
        mBuffer = buffer;
    }
    }


    public final void start() {
    public void start() {
        if (onCorrectThread()) {
        if (onCorrectThread()) {
            createAndRegisterFd();
            createAndRegisterFd();
        } else {
        } else {
@@ -100,7 +100,7 @@ public abstract class FdEventsReader<BufferType> {
        }
        }
    }
    }


    public final void stop() {
    public void stop() {
        if (onCorrectThread()) {
        if (onCorrectThread()) {
            unregisterAndDestroyFd();
            unregisterAndDestroyFd();
        } else {
        } else {
Loading