blob: a125290d3f79e4fa86aa4ca2669201cfd9091849 [file] [log] [blame]
Mingguang Xu2d87c612021-10-29 00:18:55 -07001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.net;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemApi;
22import android.os.Parcel;
23import android.os.Parcelable;
24
25/**
26 * A class representing an option in the DHCP protocol.
27 *
28 * @hide
29 */
30@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
31public final class DhcpOption implements Parcelable {
32 private final byte mType;
33 private final byte[] mValue;
34
35 /**
36 * Constructs a DhcpOption object.
37 *
38 * @param type the type of this option
39 * @param value the value of this option. If {@code null}, DHCP packets containing this option
40 * will include the option type in the Parameter Request List. Otherwise, DHCP
41 * packets containing this option will include the option in the options section.
42 */
43 public DhcpOption(byte type, @Nullable byte[] value) {
44 mType = type;
45 mValue = value;
46 }
47
48 @Override
49 public int describeContents() {
50 return 0;
51 }
52
53 @Override
54 public void writeToParcel(@NonNull Parcel dest, int flags) {
55 dest.writeByte(mType);
56 dest.writeByteArray(mValue);
57 }
58
59 /** Implement the Parcelable interface */
60 public static final @NonNull Creator<DhcpOption> CREATOR =
61 new Creator<DhcpOption>() {
62 public DhcpOption createFromParcel(Parcel in) {
63 return new DhcpOption(in.readByte(), in.createByteArray());
64 }
65
66 public DhcpOption[] newArray(int size) {
67 return new DhcpOption[size];
68 }
69 };
70
71 /** Get the type of DHCP option */
72 public byte getType() {
73 return mType;
74 }
75
76 /** Get the value of DHCP option */
77 @Nullable public byte[] getValue() {
78 return mValue == null ? null : mValue.clone();
79 }
80}