package android.net.metrics;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.SparseArray;
import com.android.internal.util.MessageUtils;
public final class DhcpErrorEvent implements Parcelable {
public static final int L2_ERROR = 1;
public static final int L3_ERROR = 2;
public static final int L4_ERROR = 3;
public static final int DHCP_ERROR = 4;
public static final int MISC_ERROR = 5;
public static final int L2_TOO_SHORT = makeErrorCode(L2_ERROR, 1);
public static final int L2_WRONG_ETH_TYPE = makeErrorCode(L2_ERROR, 2);
public static final int L3_TOO_SHORT = makeErrorCode(L3_ERROR, 1);
public static final int L3_NOT_IPV4 = makeErrorCode(L3_ERROR, 2);
public static final int L3_INVALID_IP = makeErrorCode(L3_ERROR, 3);
public static final int L4_NOT_UDP = makeErrorCode(L4_ERROR, 1);
public static final int L4_WRONG_PORT = makeErrorCode(L4_ERROR, 2);
public static final int BOOTP_TOO_SHORT = makeErrorCode(DHCP_ERROR, 1);
public static final int DHCP_BAD_MAGIC_COOKIE = makeErrorCode(DHCP_ERROR, 2);
public static final int DHCP_INVALID_OPTION_LENGTH = makeErrorCode(DHCP_ERROR, 3);
public static final int DHCP_NO_MSG_TYPE = makeErrorCode(DHCP_ERROR, 4);
public static final int DHCP_UNKNOWN_MSG_TYPE = makeErrorCode(DHCP_ERROR, 5);
public static final int DHCP_NO_COOKIE = makeErrorCode(DHCP_ERROR, 6);
public static final int BUFFER_UNDERFLOW = makeErrorCode(MISC_ERROR, 1);
public static final int RECEIVE_ERROR = makeErrorCode(MISC_ERROR, 2);
public static final int PARSING_ERROR = makeErrorCode(MISC_ERROR, 3);
public final int errorCode;
public DhcpErrorEvent(int errorCode) {
this.errorCode = errorCode;
}
private DhcpErrorEvent(Parcel in) {
this.errorCode = in.readInt();
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(errorCode);
}
@Override
public int describeContents() {
return 0;
}
public static final Parcelable.Creator<DhcpErrorEvent> CREATOR
= new Parcelable.Creator<DhcpErrorEvent>() {
public DhcpErrorEvent createFromParcel(Parcel in) {
return new DhcpErrorEvent(in);
}
public DhcpErrorEvent[] newArray(int size) {
return new DhcpErrorEvent[size];
}
};
public static int errorCodeWithOption(int errorCode, int option) {
return (0xFFFF0000 & errorCode) | (0xFF & option);
}
private static int makeErrorCode(int type, int subtype) {
return (type << 24) | ((0xFF & subtype) << 16);
}
@Override
public String toString() {
return String.format("DhcpErrorEvent(%s)", Decoder.constants.get(errorCode));
}
final static class Decoder {
static final SparseArray<String> constants = MessageUtils.findMessageNames(
new Class[]{DhcpErrorEvent.class},
new String[]{"L2_", "L3_", "L4_", "BOOTP_", "DHCP_", "BUFFER_", "RECEIVE_",
"PARSING_"});
}
}