Loading common/networkstackclient/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -61,7 +61,9 @@ aidl_interface { "src/android/net/ProvisioningConfigurationParcelable.aidl", "src/android/net/ScanResultInfoParcelable.aidl", "src/android/net/TcpKeepalivePacketDataParcelable.aidl", "src/android/net/dhcp/DhcpLeaseParcelable.aidl", "src/android/net/dhcp/DhcpServingParamsParcel.aidl", "src/android/net/dhcp/IDhcpLeaseCallbacks.aidl", "src/android/net/dhcp/IDhcpServer.aidl", "src/android/net/dhcp/IDhcpServerCallbacks.aidl", "src/android/net/ip/IIpClient.aidl", Loading common/networkstackclient/src/android/net/dhcp/DhcpLeaseParcelable.aidl 0 → 100644 +32 −0 Original line number Diff line number Diff line /** * Copyright (c) 2020, 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 perNmissions and * limitations under the License. */ package android.net.dhcp; parcelable DhcpLeaseParcelable { // Client ID of the lease; may be null. byte[] clientId; // MAC address provided by the client. byte[] hwAddr; // IPv4 address of the lease, in network byte order. int netAddr; // Prefix length of the lease (0-32) int prefixLength; // Expiration time of the lease, to compare with SystemClock.elapsedRealtime(). long expTime; // Hostname provided by the client, if any, or null. String hostname; } No newline at end of file common/networkstackclient/src/android/net/dhcp/IDhcpLeaseCallbacks.aidl 0 → 100644 +30 −0 Original line number Diff line number Diff line /** * Copyright (c) 2020, 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 perNmissions and * limitations under the License. */ package android.net.dhcp; import android.net.dhcp.DhcpLeaseParcelable; oneway interface IDhcpLeaseCallbacks { /** * Called when a lease is committed or released on the DHCP server. * * <p>This only reports lease changes after assigning a lease, or after releasing a lease * following a DHCPRELEASE: this callback will not be fired when a lease just expires. * @param newLeases The new list of leases tracked by the server. */ void onLeasesChanged(in List<DhcpLeaseParcelable> newLeases); } No newline at end of file common/networkstackclient/src/android/net/dhcp/IDhcpServer.aidl +8 −3 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.net.dhcp; import android.net.INetworkStackStatusCallback; import android.net.dhcp.DhcpServingParamsParcel; import android.net.dhcp.IDhcpLeaseCallbacks; /** @hide */ oneway interface IDhcpServer { Loading @@ -26,7 +27,11 @@ oneway interface IDhcpServer { const int STATUS_INVALID_ARGUMENT = 2; const int STATUS_UNKNOWN_ERROR = 3; void start(in INetworkStackStatusCallback cb); void updateParams(in DhcpServingParamsParcel params, in INetworkStackStatusCallback cb); void stop(in INetworkStackStatusCallback cb); void start(in INetworkStackStatusCallback cb) = 0; void startWithCallbacks(in INetworkStackStatusCallback statusCb, in IDhcpLeaseCallbacks leaseCb) = 3; void updateParams(in DhcpServingParamsParcel params, in INetworkStackStatusCallback cb) = 1; void stop(in INetworkStackStatusCallback cb) = 2; // Next available ID: 4 } src/android/net/dhcp/DhcpLease.java +32 −5 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.net.dhcp; import static android.net.shared.Inet4AddressUtils.inet4AddressToIntHTH; import android.net.MacAddress; import android.os.SystemClock; import android.text.TextUtils; Loading Loading @@ -43,6 +45,7 @@ public class DhcpLease { private final MacAddress mHwAddr; @NonNull private final Inet4Address mNetAddr; private final int mPrefixLength; /** * Expiration time for the lease, to compare with {@link SystemClock#elapsedRealtime()}. */ Loading @@ -51,10 +54,12 @@ public class DhcpLease { private final String mHostname; public DhcpLease(@Nullable byte[] clientId, @NonNull MacAddress hwAddr, @NonNull Inet4Address netAddr, long expTime, @Nullable String hostname) { @NonNull Inet4Address netAddr, int prefixLength, long expTime, @Nullable String hostname) { mClientId = (clientId == null ? null : Arrays.copyOf(clientId, clientId.length)); mHwAddr = hwAddr; mNetAddr = netAddr; mPrefixLength = prefixLength; mExpTime = expTime; mHostname = hostname; } Loading Loading @@ -87,6 +92,10 @@ public class DhcpLease { return mNetAddr; } public int getPrefixLength() { return mPrefixLength; } public long getExpTime() { return mExpTime; } Loading @@ -99,7 +108,8 @@ public class DhcpLease { * @return A {@link DhcpLease} with expiration time set to max(expTime, currentExpTime) */ public DhcpLease renewedLease(long expTime, @Nullable String hostname) { return new DhcpLease(mClientId, mHwAddr, mNetAddr, Math.max(expTime, mExpTime), return new DhcpLease(mClientId, mHwAddr, mNetAddr, mPrefixLength, Math.max(expTime, mExpTime), (hostname == null ? mHostname : hostname)); } Loading @@ -125,13 +135,14 @@ public class DhcpLease { return Arrays.equals(mClientId, other.mClientId) && mHwAddr.equals(other.mHwAddr) && mNetAddr.equals(other.mNetAddr) && mPrefixLength == other.mPrefixLength && mExpTime == other.mExpTime && TextUtils.equals(mHostname, other.mHostname); } @Override public int hashCode() { return Objects.hash(mClientId, mHwAddr, mNetAddr, mHostname, mExpTime); return Objects.hash(mClientId, mHwAddr, mNetAddr, mPrefixLength, mHostname, mExpTime); } static String clientIdToString(byte[] bytes) { Loading @@ -147,8 +158,24 @@ public class DhcpLease { @Override public String toString() { return String.format("clientId: %s, hwAddr: %s, netAddr: %s, expTime: %d, hostname: %s", return String.format("clientId: %s, hwAddr: %s, netAddr: %s/%d, expTime: %d," + "hostname: %s", clientIdToString(mClientId), mHwAddr.toString(), inet4AddrToString(mNetAddr), mExpTime, mHostname); mPrefixLength, mExpTime, mHostname); } /** * Create a {@link DhcpLeaseParcelable} containing the information held in this lease. */ public DhcpLeaseParcelable toParcelable() { final DhcpLeaseParcelable p = new DhcpLeaseParcelable(); p.clientId = mClientId == null ? null : Arrays.copyOf(mClientId, mClientId.length); p.hwAddr = mHwAddr.toByteArray(); p.netAddr = inet4AddressToIntHTH(mNetAddr); p.prefixLength = mPrefixLength; p.expTime = mExpTime; p.hostname = mHostname; return p; } } Loading
common/networkstackclient/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -61,7 +61,9 @@ aidl_interface { "src/android/net/ProvisioningConfigurationParcelable.aidl", "src/android/net/ScanResultInfoParcelable.aidl", "src/android/net/TcpKeepalivePacketDataParcelable.aidl", "src/android/net/dhcp/DhcpLeaseParcelable.aidl", "src/android/net/dhcp/DhcpServingParamsParcel.aidl", "src/android/net/dhcp/IDhcpLeaseCallbacks.aidl", "src/android/net/dhcp/IDhcpServer.aidl", "src/android/net/dhcp/IDhcpServerCallbacks.aidl", "src/android/net/ip/IIpClient.aidl", Loading
common/networkstackclient/src/android/net/dhcp/DhcpLeaseParcelable.aidl 0 → 100644 +32 −0 Original line number Diff line number Diff line /** * Copyright (c) 2020, 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 perNmissions and * limitations under the License. */ package android.net.dhcp; parcelable DhcpLeaseParcelable { // Client ID of the lease; may be null. byte[] clientId; // MAC address provided by the client. byte[] hwAddr; // IPv4 address of the lease, in network byte order. int netAddr; // Prefix length of the lease (0-32) int prefixLength; // Expiration time of the lease, to compare with SystemClock.elapsedRealtime(). long expTime; // Hostname provided by the client, if any, or null. String hostname; } No newline at end of file
common/networkstackclient/src/android/net/dhcp/IDhcpLeaseCallbacks.aidl 0 → 100644 +30 −0 Original line number Diff line number Diff line /** * Copyright (c) 2020, 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 perNmissions and * limitations under the License. */ package android.net.dhcp; import android.net.dhcp.DhcpLeaseParcelable; oneway interface IDhcpLeaseCallbacks { /** * Called when a lease is committed or released on the DHCP server. * * <p>This only reports lease changes after assigning a lease, or after releasing a lease * following a DHCPRELEASE: this callback will not be fired when a lease just expires. * @param newLeases The new list of leases tracked by the server. */ void onLeasesChanged(in List<DhcpLeaseParcelable> newLeases); } No newline at end of file
common/networkstackclient/src/android/net/dhcp/IDhcpServer.aidl +8 −3 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.net.dhcp; import android.net.INetworkStackStatusCallback; import android.net.dhcp.DhcpServingParamsParcel; import android.net.dhcp.IDhcpLeaseCallbacks; /** @hide */ oneway interface IDhcpServer { Loading @@ -26,7 +27,11 @@ oneway interface IDhcpServer { const int STATUS_INVALID_ARGUMENT = 2; const int STATUS_UNKNOWN_ERROR = 3; void start(in INetworkStackStatusCallback cb); void updateParams(in DhcpServingParamsParcel params, in INetworkStackStatusCallback cb); void stop(in INetworkStackStatusCallback cb); void start(in INetworkStackStatusCallback cb) = 0; void startWithCallbacks(in INetworkStackStatusCallback statusCb, in IDhcpLeaseCallbacks leaseCb) = 3; void updateParams(in DhcpServingParamsParcel params, in INetworkStackStatusCallback cb) = 1; void stop(in INetworkStackStatusCallback cb) = 2; // Next available ID: 4 }
src/android/net/dhcp/DhcpLease.java +32 −5 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.net.dhcp; import static android.net.shared.Inet4AddressUtils.inet4AddressToIntHTH; import android.net.MacAddress; import android.os.SystemClock; import android.text.TextUtils; Loading Loading @@ -43,6 +45,7 @@ public class DhcpLease { private final MacAddress mHwAddr; @NonNull private final Inet4Address mNetAddr; private final int mPrefixLength; /** * Expiration time for the lease, to compare with {@link SystemClock#elapsedRealtime()}. */ Loading @@ -51,10 +54,12 @@ public class DhcpLease { private final String mHostname; public DhcpLease(@Nullable byte[] clientId, @NonNull MacAddress hwAddr, @NonNull Inet4Address netAddr, long expTime, @Nullable String hostname) { @NonNull Inet4Address netAddr, int prefixLength, long expTime, @Nullable String hostname) { mClientId = (clientId == null ? null : Arrays.copyOf(clientId, clientId.length)); mHwAddr = hwAddr; mNetAddr = netAddr; mPrefixLength = prefixLength; mExpTime = expTime; mHostname = hostname; } Loading Loading @@ -87,6 +92,10 @@ public class DhcpLease { return mNetAddr; } public int getPrefixLength() { return mPrefixLength; } public long getExpTime() { return mExpTime; } Loading @@ -99,7 +108,8 @@ public class DhcpLease { * @return A {@link DhcpLease} with expiration time set to max(expTime, currentExpTime) */ public DhcpLease renewedLease(long expTime, @Nullable String hostname) { return new DhcpLease(mClientId, mHwAddr, mNetAddr, Math.max(expTime, mExpTime), return new DhcpLease(mClientId, mHwAddr, mNetAddr, mPrefixLength, Math.max(expTime, mExpTime), (hostname == null ? mHostname : hostname)); } Loading @@ -125,13 +135,14 @@ public class DhcpLease { return Arrays.equals(mClientId, other.mClientId) && mHwAddr.equals(other.mHwAddr) && mNetAddr.equals(other.mNetAddr) && mPrefixLength == other.mPrefixLength && mExpTime == other.mExpTime && TextUtils.equals(mHostname, other.mHostname); } @Override public int hashCode() { return Objects.hash(mClientId, mHwAddr, mNetAddr, mHostname, mExpTime); return Objects.hash(mClientId, mHwAddr, mNetAddr, mPrefixLength, mHostname, mExpTime); } static String clientIdToString(byte[] bytes) { Loading @@ -147,8 +158,24 @@ public class DhcpLease { @Override public String toString() { return String.format("clientId: %s, hwAddr: %s, netAddr: %s, expTime: %d, hostname: %s", return String.format("clientId: %s, hwAddr: %s, netAddr: %s/%d, expTime: %d," + "hostname: %s", clientIdToString(mClientId), mHwAddr.toString(), inet4AddrToString(mNetAddr), mExpTime, mHostname); mPrefixLength, mExpTime, mHostname); } /** * Create a {@link DhcpLeaseParcelable} containing the information held in this lease. */ public DhcpLeaseParcelable toParcelable() { final DhcpLeaseParcelable p = new DhcpLeaseParcelable(); p.clientId = mClientId == null ? null : Arrays.copyOf(mClientId, mClientId.length); p.hwAddr = mHwAddr.toByteArray(); p.netAddr = inet4AddressToIntHTH(mNetAddr); p.prefixLength = mPrefixLength; p.expTime = mExpTime; p.hostname = mHostname; return p; } }