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

Commit e31734e9 authored by Xiao Ma's avatar Xiao Ma
Browse files

Support customized DHCP client options.

Provide a new API in ProvisioningConfiguration class to allow OEMs
appending customized DHCP client options, these new options should
be only sent to the target network for the networking interoperability
compatibility via checking the vendor-specific IE OUI and Type in the
ScanResultInfo class passed from Wi-Fi, if the specific IE isn't found,
then preserve the default options.

Bug: 169128961
Test: atest NetworkStackIntegrationTest
Test: atest NetworkStackTests
Change-Id: I8c9cc0a0f91167cde32a960ee9f57b1b0549c089
parent 3c141ccc
Loading
Loading
Loading
Loading
+46 −6
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.net.ScanResultInfoParcelable;
import android.net.StaticIpConfiguration;
import android.net.apf.ApfCapabilities;
import android.net.ip.IIpClient;
import android.net.networkstack.aidl.dhcp.DhcpOption;
import android.util.Log;

import java.nio.BufferUnderflowException;
@@ -226,6 +227,17 @@ public class ProvisioningConfiguration {
            return this;
        }

        /**
         * Specify the customized DHCP options to be put in the PRL or in the DHCP packet. Options
         * with null value will be put in the PRL.
         *
         * @param: options customized DHCP option stable parcelable list.
         */
        public Builder withDhcpOptions(List<DhcpOption> options) {
            mConfig.mDhcpOptions = options;
            return this;
        }

        /**
         * Build the configuration using previously specified parameters.
         */
@@ -430,6 +442,7 @@ public class ProvisioningConfiguration {
    public String mDisplayName = null;
    public ScanResultInfo mScanResultInfo;
    public Layer2Information mLayer2Info;
    public List<DhcpOption> mDhcpOptions;

    public ProvisioningConfiguration() {} // used by Builder

@@ -451,6 +464,7 @@ public class ProvisioningConfiguration {
        mDisplayName = other.mDisplayName;
        mScanResultInfo = other.mScanResultInfo;
        mLayer2Info = other.mLayer2Info;
        mDhcpOptions = other.mDhcpOptions;
    }

    /**
@@ -464,8 +478,8 @@ public class ProvisioningConfiguration {
        p.usingMultinetworkPolicyTracker = mUsingMultinetworkPolicyTracker;
        p.usingIpReachabilityMonitor = mUsingIpReachabilityMonitor;
        p.requestedPreDhcpActionMs = mRequestedPreDhcpActionMs;
        p.initialConfig = mInitialConfig == null ? null : mInitialConfig.toStableParcelable();
        p.staticIpConfig = mStaticIpConfig == null
        p.initialConfig = (mInitialConfig == null) ? null : mInitialConfig.toStableParcelable();
        p.staticIpConfig = (mStaticIpConfig == null)
                ? null
                : new StaticIpConfiguration(mStaticIpConfig);
        p.apfCapabilities = mApfCapabilities; // ApfCapabilities is immutable
@@ -473,8 +487,9 @@ public class ProvisioningConfiguration {
        p.ipv6AddrGenMode = mIPv6AddrGenMode;
        p.network = mNetwork;
        p.displayName = mDisplayName;
        p.scanResultInfo = mScanResultInfo == null ? null : mScanResultInfo.toStableParcelable();
        p.layer2Info = mLayer2Info == null ? null : mLayer2Info.toStableParcelable();
        p.scanResultInfo = (mScanResultInfo == null) ? null : mScanResultInfo.toStableParcelable();
        p.layer2Info = (mLayer2Info == null) ? null : mLayer2Info.toStableParcelable();
        p.options = (mDhcpOptions == null) ? null : new ArrayList<>(mDhcpOptions);
        return p;
    }

@@ -492,7 +507,7 @@ public class ProvisioningConfiguration {
        config.mUsingIpReachabilityMonitor = p.usingIpReachabilityMonitor;
        config.mRequestedPreDhcpActionMs = p.requestedPreDhcpActionMs;
        config.mInitialConfig = InitialConfiguration.fromStableParcelable(p.initialConfig);
        config.mStaticIpConfig = p.staticIpConfig == null
        config.mStaticIpConfig = (p.staticIpConfig == null)
                ? null
                : new StaticIpConfiguration(p.staticIpConfig);
        config.mApfCapabilities = p.apfCapabilities; // ApfCapabilities is immutable
@@ -502,6 +517,7 @@ public class ProvisioningConfiguration {
        config.mDisplayName = p.displayName;
        config.mScanResultInfo = ScanResultInfo.fromStableParcelable(p.scanResultInfo);
        config.mLayer2Info = Layer2Information.fromStableParcelable(p.layer2Info);
        config.mDhcpOptions = (p.options == null) ? null : new ArrayList<>(p.options);
        return config;
    }

@@ -523,9 +539,32 @@ public class ProvisioningConfiguration {
                .add("mDisplayName: " + mDisplayName)
                .add("mScanResultInfo: " + mScanResultInfo)
                .add("mLayer2Info: " + mLayer2Info)
                .add("mDhcpOptions: " + mDhcpOptions)
                .toString();
    }

    // TODO: mark DhcpOption stable parcelable with @JavaDerive(equals=true, toString=true)
    // and @JavaOnlyImmutable.
    private static boolean dhcpOptionEquals(@Nullable DhcpOption obj1, @Nullable DhcpOption obj2) {
        if (obj1 == obj2) return true;
        if (obj1 == null || obj2 == null) return false;
        return obj1.type == obj2.type && Arrays.equals(obj1.value, obj2.value);
    }

    // TODO: use Objects.equals(List<DhcpOption>, List<DhcpOption>) method instead once
    // auto-generated equals() method of stable parcelable is supported in mainline-prod.
    private static boolean dhcpOptionListEquals(@Nullable List<DhcpOption> l1,
            @Nullable List<DhcpOption> l2) {
        if (l1 == l2) return true;
        if (l1 == null || l2 == null) return false;
        if (l1.size() != l2.size()) return false;

        for (int i = 0; i < l1.size(); i++) {
            if (!dhcpOptionEquals(l1.get(i), l2.get(i))) return false;
        }
        return true;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ProvisioningConfiguration)) return false;
@@ -544,7 +583,8 @@ public class ProvisioningConfiguration {
                && Objects.equals(mNetwork, other.mNetwork)
                && Objects.equals(mDisplayName, other.mDisplayName)
                && Objects.equals(mScanResultInfo, other.mScanResultInfo)
                && Objects.equals(mLayer2Info, other.mLayer2Info);
                && Objects.equals(mLayer2Info, other.mLayer2Info)
                && dhcpOptionListEquals(mDhcpOptions, other.mDhcpOptions);
    }

    public boolean isValid() {
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ aidl_interface {
        "src/android/net/ip/IIpClientCallbacks.aidl",
        // New AIDL classes should go into android.net.networkstack.aidl so they can be clearly
        // identified
        "src/android/net/networkstack/aidl/dhcp/DhcpOption.aidl",
    ],
    backend: {
        java: {
+7 −6
Original line number Diff line number Diff line
@@ -2,13 +2,14 @@
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
///////////////////////////////////////////////////////////////////////////////

// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
// edit this file. It looks like you are doing that because you have modified
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
// from an interface or a field from a parcelable and it broke the build. That
// breakage is intended.
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
// two cases:
// 1). this is a frozen version file - do not edit this in any case.
// 2). this is a 'current' file. If you make a backwards compatible change to
//     the interface (from the latest frozen version), the build system will
//     prompt you to update this file with `m <name>-update-api`.
//
// You must not make a backward incompatible changes to the AIDL files built
// You must not make a backward incompatible change to any AIDL file built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
+7 −6
Original line number Diff line number Diff line
@@ -2,13 +2,14 @@
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
///////////////////////////////////////////////////////////////////////////////

// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
// edit this file. It looks like you are doing that because you have modified
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
// from an interface or a field from a parcelable and it broke the build. That
// breakage is intended.
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
// two cases:
// 1). this is a frozen version file - do not edit this in any case.
// 2). this is a 'current' file. If you make a backwards compatible change to
//     the interface (from the latest frozen version), the build system will
//     prompt you to update this file with `m <name>-update-api`.
//
// You must not make a backward incompatible changes to the AIDL files built
// You must not make a backward incompatible change to any AIDL file built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
+7 −6
Original line number Diff line number Diff line
@@ -2,13 +2,14 @@
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
///////////////////////////////////////////////////////////////////////////////

// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
// edit this file. It looks like you are doing that because you have modified
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
// from an interface or a field from a parcelable and it broke the build. That
// breakage is intended.
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
// two cases:
// 1). this is a frozen version file - do not edit this in any case.
// 2). this is a 'current' file. If you make a backwards compatible change to
//     the interface (from the latest frozen version), the build system will
//     prompt you to update this file with `m <name>-update-api`.
//
// You must not make a backward incompatible changes to the AIDL files built
// You must not make a backward incompatible change to any AIDL file built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
Loading