Debian Codegraph @

core/java/android/net/metrics/DhcpErrorEvent.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 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
17 package android.net.metrics;
18
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.util.SparseArray;
24
25 import com.android.internal.util.MessageUtils;
26
27 /**
28 * Event class used to record error events when parsing DHCP response packets.
29 * {@hide}
30 * @deprecated The event may not be sent in Android S and above. The events
31 * are logged by a single caller in the system using signature permissions
32 * and that caller is migrating to statsd.
33 */
34 @Deprecated
35 @SystemApi
36 public final class DhcpErrorEvent implements IpConnectivityLog.Event {
37 public static final int L2_ERROR = 1;
38 public static final int L3_ERROR = 2;
39 public static final int L4_ERROR = 3;
40 public static final int DHCP_ERROR = 4;
41 public static final int MISC_ERROR = 5;
42
43 // error code byte format (MSB to LSB):
44 // byte 0: error type
45 // byte 1: error subtype
46 // byte 2: unused
47 // byte 3: optional code
48 /** @hide */
49 public final int errorCode;
50
51 private static final int L2_ERROR_TYPE = L2_ERROR << 8;
52 private static final int L3_ERROR_TYPE = L3_ERROR << 8;
53 private static final int L4_ERROR_TYPE = L4_ERROR << 8;
54 private static final int DHCP_ERROR_TYPE = DHCP_ERROR << 8;
55 private static final int MISC_ERROR_TYPE = MISC_ERROR << 8;
56
57 public static final int L2_TOO_SHORT = (L2_ERROR_TYPE | 0x1) << 16;
58 public static final int L2_WRONG_ETH_TYPE = (L2_ERROR_TYPE | 0x2) << 16;
59
60 public static final int L3_TOO_SHORT = (L3_ERROR_TYPE | 0x1) << 16;
61 public static final int L3_NOT_IPV4 = (L3_ERROR_TYPE | 0x2) << 16;
62 public static final int L3_INVALID_IP = (L3_ERROR_TYPE | 0x3) << 16;
63
64 public static final int L4_NOT_UDP = (L4_ERROR_TYPE | 0x1) << 16;
65 public static final int L4_WRONG_PORT = (L4_ERROR_TYPE | 0x2) << 16;
66
67 public static final int BOOTP_TOO_SHORT = (DHCP_ERROR_TYPE | 0x1) << 16;
68 public static final int DHCP_BAD_MAGIC_COOKIE = (DHCP_ERROR_TYPE | 0x2) << 16;
69 public static final int DHCP_INVALID_OPTION_LENGTH = (DHCP_ERROR_TYPE | 0x3) << 16;
70 public static final int DHCP_NO_MSG_TYPE = (DHCP_ERROR_TYPE | 0x4) << 16;
71 public static final int DHCP_UNKNOWN_MSG_TYPE = (DHCP_ERROR_TYPE | 0x5) << 16;
72 public static final int DHCP_NO_COOKIE = (DHCP_ERROR_TYPE | 0x6) << 16;
73
74 public static final int BUFFER_UNDERFLOW = (MISC_ERROR_TYPE | 0x1) << 16;
75 public static final int RECEIVE_ERROR = (MISC_ERROR_TYPE | 0x2) << 16;
76 public static final int PARSING_ERROR = (MISC_ERROR_TYPE | 0x3) << 16;
77
78 public DhcpErrorEvent(int errorCode) {
79 this.errorCode = errorCode;
80 }
81
82 private DhcpErrorEvent(Parcel in) {
83 this.errorCode = in.readInt();
84 }
85
86 /** @hide */
87 @Override
88 public void writeToParcel(Parcel out, int flags) {
89 out.writeInt(errorCode);
90 }
91
92 /** @hide */
93 @Override
94 public int describeContents() {
95 return 0;
96 }
97
98 /** @hide */
99 public static final @android.annotation.NonNull Parcelable.Creator<DhcpErrorEvent> CREATOR
100 = new Parcelable.Creator<DhcpErrorEvent>() {
101 public DhcpErrorEvent createFromParcel(Parcel in) {
102 return new DhcpErrorEvent(in);
103 }
104
105 public DhcpErrorEvent[] newArray(int size) {
106 return new DhcpErrorEvent[size];
107 }
108 };
109
110 public static int errorCodeWithOption(int errorCode, int option) {
111 return (0xFFFF0000 & errorCode) | (0xFF & option);
112 }
113
114 @NonNull
115 @Override
116 public String toString() {
117 return String.format("DhcpErrorEvent(%s)", Decoder.constants.get(errorCode));
118 }
119
120 final static class Decoder {
121 static final SparseArray<String> constants = MessageUtils.findMessageNames(
122 new Class[]{DhcpErrorEvent.class},
123 new String[]{"L2_", "L3_", "L4_", "BOOTP_", "DHCP_", "BUFFER_", "RECEIVE_",
124 "PARSING_"});
125 }
126 }