Files
android_packages_modules_Co…/framework/src/android/net/DhcpOption.java
Mingguang Xu 2d87c6152d Create DhcpOption object and make it a SystemApi
This allows OEM apps to pass their custom DHCP options for establishing
network connection.

Bug: 177278970

Test: atest FrameworksNetTests
Test: atest NetworkStackTests

Signed-off-by: Mingguang Xu <mingguangxu@google.com>
Change-Id: I2b8c38ee9a948ad6edb666312c989d27a8ff904b
2021-12-09 19:37:40 -08:00

81 lines
2.4 KiB
Java

/*
* Copyright (C) 2021 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;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
/**
* A class representing an option in the DHCP protocol.
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public final class DhcpOption implements Parcelable {
private final byte mType;
private final byte[] mValue;
/**
* Constructs a DhcpOption object.
*
* @param type the type of this option
* @param value the value of this option. If {@code null}, DHCP packets containing this option
* will include the option type in the Parameter Request List. Otherwise, DHCP
* packets containing this option will include the option in the options section.
*/
public DhcpOption(byte type, @Nullable byte[] value) {
mType = type;
mValue = value;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeByte(mType);
dest.writeByteArray(mValue);
}
/** Implement the Parcelable interface */
public static final @NonNull Creator<DhcpOption> CREATOR =
new Creator<DhcpOption>() {
public DhcpOption createFromParcel(Parcel in) {
return new DhcpOption(in.readByte(), in.createByteArray());
}
public DhcpOption[] newArray(int size) {
return new DhcpOption[size];
}
};
/** Get the type of DHCP option */
public byte getType() {
return mType;
}
/** Get the value of DHCP option */
@Nullable public byte[] getValue() {
return mValue == null ? null : mValue.clone();
}
}