From 542c622baf25cde663e0e6de2a5117abbf395697 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Wed, 20 Mar 2019 16:35:05 +0900 Subject: [PATCH] Define DhcpErrorEvent constants at compile time Addresses API review comments. Bug: 126700007 Test: m Change-Id: I8c32a0e8bcf2d63eaf33c9ac884afd4fdbe0fdd3 --- api/system-current.txt | 32 ++++++++++---------- api/test-current.txt | 32 ++++++++++---------- core/java/android/net/metrics/DhcpErrorEvent.java | 36 ++++++++++------------- 3 files changed, 48 insertions(+), 52 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 2a6a187e3d04..b126f575c232 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -3413,27 +3413,27 @@ package android.net.metrics { public final class DhcpErrorEvent implements android.net.metrics.IpConnectivityLog.Event { ctor public DhcpErrorEvent(int); method public static int errorCodeWithOption(int, int); - field public static final int BOOTP_TOO_SHORT; - field public static final int BUFFER_UNDERFLOW; - field public static final int DHCP_BAD_MAGIC_COOKIE; + field public static final int BOOTP_TOO_SHORT = 67174400; // 0x4010000 + field public static final int BUFFER_UNDERFLOW = 83951616; // 0x5010000 + field public static final int DHCP_BAD_MAGIC_COOKIE = 67239936; // 0x4020000 field public static final int DHCP_ERROR = 4; // 0x4 - field public static final int DHCP_INVALID_OPTION_LENGTH; - field public static final int DHCP_NO_COOKIE; - field public static final int DHCP_NO_MSG_TYPE; - field public static final int DHCP_UNKNOWN_MSG_TYPE; + field public static final int DHCP_INVALID_OPTION_LENGTH = 67305472; // 0x4030000 + field public static final int DHCP_NO_COOKIE = 67502080; // 0x4060000 + field public static final int DHCP_NO_MSG_TYPE = 67371008; // 0x4040000 + field public static final int DHCP_UNKNOWN_MSG_TYPE = 67436544; // 0x4050000 field public static final int L2_ERROR = 1; // 0x1 - field public static final int L2_TOO_SHORT; - field public static final int L2_WRONG_ETH_TYPE; + field public static final int L2_TOO_SHORT = 16842752; // 0x1010000 + field public static final int L2_WRONG_ETH_TYPE = 16908288; // 0x1020000 field public static final int L3_ERROR = 2; // 0x2 - field public static final int L3_INVALID_IP; - field public static final int L3_NOT_IPV4; - field public static final int L3_TOO_SHORT; + field public static final int L3_INVALID_IP = 33751040; // 0x2030000 + field public static final int L3_NOT_IPV4 = 33685504; // 0x2020000 + field public static final int L3_TOO_SHORT = 33619968; // 0x2010000 field public static final int L4_ERROR = 3; // 0x3 - field public static final int L4_NOT_UDP; - field public static final int L4_WRONG_PORT; + field public static final int L4_NOT_UDP = 50397184; // 0x3010000 + field public static final int L4_WRONG_PORT = 50462720; // 0x3020000 field public static final int MISC_ERROR = 5; // 0x5 - field public static final int PARSING_ERROR; - field public static final int RECEIVE_ERROR; + field public static final int PARSING_ERROR = 84082688; // 0x5030000 + field public static final int RECEIVE_ERROR = 84017152; // 0x5020000 } public class IpConnectivityLog { diff --git a/api/test-current.txt b/api/test-current.txt index 6372197b86b5..024aa10de2bf 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -823,27 +823,27 @@ package android.net.metrics { public final class DhcpErrorEvent implements android.net.metrics.IpConnectivityLog.Event { ctor public DhcpErrorEvent(int); method public static int errorCodeWithOption(int, int); - field public static final int BOOTP_TOO_SHORT; - field public static final int BUFFER_UNDERFLOW; - field public static final int DHCP_BAD_MAGIC_COOKIE; + field public static final int BOOTP_TOO_SHORT = 67174400; // 0x4010000 + field public static final int BUFFER_UNDERFLOW = 83951616; // 0x5010000 + field public static final int DHCP_BAD_MAGIC_COOKIE = 67239936; // 0x4020000 field public static final int DHCP_ERROR = 4; // 0x4 - field public static final int DHCP_INVALID_OPTION_LENGTH; - field public static final int DHCP_NO_COOKIE; - field public static final int DHCP_NO_MSG_TYPE; - field public static final int DHCP_UNKNOWN_MSG_TYPE; + field public static final int DHCP_INVALID_OPTION_LENGTH = 67305472; // 0x4030000 + field public static final int DHCP_NO_COOKIE = 67502080; // 0x4060000 + field public static final int DHCP_NO_MSG_TYPE = 67371008; // 0x4040000 + field public static final int DHCP_UNKNOWN_MSG_TYPE = 67436544; // 0x4050000 field public static final int L2_ERROR = 1; // 0x1 - field public static final int L2_TOO_SHORT; - field public static final int L2_WRONG_ETH_TYPE; + field public static final int L2_TOO_SHORT = 16842752; // 0x1010000 + field public static final int L2_WRONG_ETH_TYPE = 16908288; // 0x1020000 field public static final int L3_ERROR = 2; // 0x2 - field public static final int L3_INVALID_IP; - field public static final int L3_NOT_IPV4; - field public static final int L3_TOO_SHORT; + field public static final int L3_INVALID_IP = 33751040; // 0x2030000 + field public static final int L3_NOT_IPV4 = 33685504; // 0x2020000 + field public static final int L3_TOO_SHORT = 33619968; // 0x2010000 field public static final int L4_ERROR = 3; // 0x3 - field public static final int L4_NOT_UDP; - field public static final int L4_WRONG_PORT; + field public static final int L4_NOT_UDP = 50397184; // 0x3010000 + field public static final int L4_WRONG_PORT = 50462720; // 0x3020000 field public static final int MISC_ERROR = 5; // 0x5 - field public static final int PARSING_ERROR; - field public static final int RECEIVE_ERROR; + field public static final int PARSING_ERROR = 84082688; // 0x5030000 + field public static final int RECEIVE_ERROR = 84017152; // 0x5020000 } public class IpConnectivityLog { diff --git a/core/java/android/net/metrics/DhcpErrorEvent.java b/core/java/android/net/metrics/DhcpErrorEvent.java index 18fde80b69b0..8beaa40ec2fc 100644 --- a/core/java/android/net/metrics/DhcpErrorEvent.java +++ b/core/java/android/net/metrics/DhcpErrorEvent.java @@ -37,26 +37,26 @@ public final class DhcpErrorEvent implements IpConnectivityLog.Event { 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 L2_TOO_SHORT = (L2_ERROR << 24) | (1 << 16); + public static final int L2_WRONG_ETH_TYPE = (L2_ERROR << 24) | (2 << 16); - 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 L3_TOO_SHORT = (L3_ERROR << 24) | (1 << 16); + public static final int L3_NOT_IPV4 = (L3_ERROR << 24) | (2 << 16); + public static final int L3_INVALID_IP = (L3_ERROR << 24) | (3 << 16); - 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 L4_NOT_UDP = (L4_ERROR << 24) | (1 << 16); + public static final int L4_WRONG_PORT = (L4_ERROR << 24) | (2 << 16); - 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 BOOTP_TOO_SHORT = (DHCP_ERROR << 24) | (1 << 16); + public static final int DHCP_BAD_MAGIC_COOKIE = (DHCP_ERROR << 24) | (2 << 16); + public static final int DHCP_INVALID_OPTION_LENGTH = (DHCP_ERROR << 24) | (3 << 16); + public static final int DHCP_NO_MSG_TYPE = (DHCP_ERROR << 24) | (4 << 16); + public static final int DHCP_UNKNOWN_MSG_TYPE = (DHCP_ERROR << 24) | (5 << 16); + public static final int DHCP_NO_COOKIE = (DHCP_ERROR << 24) | (6 << 16); - 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 static final int BUFFER_UNDERFLOW = (MISC_ERROR << 24) | (1 << 16); + public static final int RECEIVE_ERROR = (MISC_ERROR << 24) | (2 << 16); + public static final int PARSING_ERROR = (MISC_ERROR << 24) | (3 << 16); // error code byte format (MSB to LSB): // byte 0: error type @@ -102,10 +102,6 @@ public final class DhcpErrorEvent implements IpConnectivityLog.Event { 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)); -- 2.11.0