| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 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 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 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 |
|
| 87 |
@Override |
| 88 |
public void writeToParcel(Parcel out, int flags) { |
| 89 |
out.writeInt(errorCode); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
@Override |
| 94 |
public int describeContents() { |
| 95 |
return 0; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 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 |
} |