diff options
author | Xiao Ma <xiaom@google.com> | 2019-08-26 17:24:26 +0900 |
---|---|---|
committer | Xiao Ma <xiaom@google.com> | 2019-12-27 17:03:09 +0900 |
commit | 8bcd6735907353caa493d232f01a3fa191bc2f4c (patch) | |
tree | 8fefdb16aa50f0a31662a37c6f29d44bfa8ff6c1 /src/android/net/dhcp/DhcpPacket.java | |
parent | 7b60bfa137ad7ec9213ec4c2169cea4f303e2ce0 (diff) |
Provide RRO configuration to send DHCP client hostname option.
Add a configurable option in the RRO which controls whether or not to
send the hostname set in the Settings->About phone->Device name. The
option in RRO is false by default, that means DHCP Request still not
include any hostname by default. Once the option is overlaid and enabled,
the device name after transliteration will be wrote into hostname option.
Bug: 131783527
Test: atest NetworkStackTests NetworkStackIntegrationTests
Test: manual test, create empty APK to overlay the RRO configuration.
Change-Id: I9af0b0d9e7bb526d3a3c1003bb99d0a3d69b1e9e
Diffstat (limited to 'src/android/net/dhcp/DhcpPacket.java')
-rw-r--r-- | src/android/net/dhcp/DhcpPacket.java | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/src/android/net/dhcp/DhcpPacket.java b/src/android/net/dhcp/DhcpPacket.java index c5700b3..9eca0b5 100644 --- a/src/android/net/dhcp/DhcpPacket.java +++ b/src/android/net/dhcp/DhcpPacket.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package android.net.dhcp; import static com.android.server.util.NetworkStackConstants.IPV4_ADDR_ALL; @@ -15,6 +31,8 @@ import android.text.TextUtils; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; +import com.android.networkstack.apishim.ShimUtils; + import java.io.UnsupportedEncodingException; import java.net.Inet4Address; import java.net.UnknownHostException; @@ -350,7 +368,6 @@ public abstract class DhcpPacket { // Set in unit tests, to ensure that the test does not break when run on different devices and // on different releases. static String testOverrideVendorId = null; - static String testOverrideHostname = null; protected DhcpPacket(int transId, short secs, Inet4Address clientIp, Inet4Address yourIp, Inet4Address nextIp, Inet4Address relayIp, @@ -724,9 +741,16 @@ public abstract class DhcpPacket { return "android-dhcp-" + Build.VERSION.RELEASE; } - private String getHostname() { - if (testOverrideHostname != null) return testOverrideHostname; - return SystemProperties.get("net.hostname"); + /** + * Get the DHCP client hostname after transliteration. + */ + @VisibleForTesting + public String getHostname() { + if (mHostName == null + && !ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) { + return SystemProperties.get("net.hostname"); + } + return mHostName; } /** @@ -1328,10 +1352,11 @@ public abstract class DhcpPacket { */ public static ByteBuffer buildDiscoverPacket(int encap, int transactionId, short secs, byte[] clientMac, boolean broadcast, byte[] expectedParams, - boolean rapidCommit) { + boolean rapidCommit, String hostname) { DhcpPacket pkt = new DhcpDiscoverPacket(transactionId, secs, INADDR_ANY /* relayIp */, clientMac, broadcast, INADDR_ANY /* srcIp */, rapidCommit); pkt.mRequestedParams = expectedParams; + pkt.mHostName = hostname; return pkt.buildPacket(encap, DHCP_SERVER, DHCP_CLIENT); } |