diff options
| author | 2016-04-15 16:56:28 +0900 | |
|---|---|---|
| committer | 2016-04-18 11:29:03 +0900 | |
| commit | 627b42494d82eca4fd51abfc0a5d7f330862b881 (patch) | |
| tree | 9cd762051ffc2ed2cb9ccfc251666f3aeb3b2bee | |
| parent | 2677b1957b444e2dae5737feee989109b811547c (diff) | |
Fixes fatal linter errors in android.net.metrics
This patch changes how Event classes are organized:
- Base IpConnectivityEvent class does not implement Parcelable because
it cannot be final (has children). It also becomes abstract because
it is not supposed to be instantiated and logged directly.
- All children classes becomes final because they are Parcelable.
- All constructors of all children classes become private, because they
are supposed to be instantiated with their associated logEvent()
methods.
- All instance fields of all children classes become public final.
Rational: if private, the ConnectivityMetrics app cannot read
their data.
Bug: 28204408
Change-Id: I1a4689c422230c6ed034307dec54a61daf8a6598
11 files changed, 171 insertions, 154 deletions
diff --git a/core/java/android/net/metrics/CaptivePortalCheckResultEvent.java b/core/java/android/net/metrics/CaptivePortalCheckResultEvent.java index 2239a254c8a0..2c071a0de20d 100644 --- a/core/java/android/net/metrics/CaptivePortalCheckResultEvent.java +++ b/core/java/android/net/metrics/CaptivePortalCheckResultEvent.java @@ -22,25 +22,27 @@ import android.os.Parcelable; /** * {@hide} */ -public class CaptivePortalCheckResultEvent extends IpConnectivityEvent implements Parcelable { - public static final String TAG = "CaptivePortalCheckResultEvent"; +public final class CaptivePortalCheckResultEvent extends IpConnectivityEvent implements Parcelable { + public final int netId; + public final int result; - private int mNetId; - private int mResult; - - public CaptivePortalCheckResultEvent(int netId, int result) { - mNetId = netId; - mResult = result; + private CaptivePortalCheckResultEvent(int netId, int result) { + this.netId = netId; + this.result = result; } - public CaptivePortalCheckResultEvent(Parcel in) { - mNetId = in.readInt(); - mResult = in.readInt(); + private CaptivePortalCheckResultEvent(Parcel in) { + this.netId = in.readInt(); + this.result = in.readInt(); } public void writeToParcel(Parcel out, int flags) { - out.writeInt(mNetId); - out.writeInt(mResult); + out.writeInt(netId); + out.writeInt(result); + } + + public int describeContents() { + return 0; } public static final Parcelable.Creator<CaptivePortalCheckResultEvent> CREATOR @@ -55,7 +57,6 @@ public class CaptivePortalCheckResultEvent extends IpConnectivityEvent implement }; public static void logEvent(int netId, int result) { - IpConnectivityEvent.logEvent(IpConnectivityEvent.IPCE_NETMON_CHECK_RESULT, - new CaptivePortalCheckResultEvent(netId, result)); + logEvent(IPCE_NETMON_CHECK_RESULT, new CaptivePortalCheckResultEvent(netId, result)); } }; diff --git a/core/java/android/net/metrics/CaptivePortalStateChangeEvent.java b/core/java/android/net/metrics/CaptivePortalStateChangeEvent.java index 00808c180069..587a9a8a47aa 100644 --- a/core/java/android/net/metrics/CaptivePortalStateChangeEvent.java +++ b/core/java/android/net/metrics/CaptivePortalStateChangeEvent.java @@ -22,24 +22,27 @@ import android.os.Parcelable; /** * {@hide} */ -public class CaptivePortalStateChangeEvent extends IpConnectivityEvent implements Parcelable { - public static final String TAG = "CaptivePortalStateChangeEvent"; - - public static final int NETWORK_MONITOR_CONNECTED = 0; +public final class CaptivePortalStateChangeEvent extends IpConnectivityEvent implements Parcelable { + public static final int NETWORK_MONITOR_CONNECTED = 0; public static final int NETWORK_MONITOR_DISCONNECTED = 1; - public static final int NETWORK_MONITOR_VALIDATED = 2; - private int mState; + public static final int NETWORK_MONITOR_VALIDATED = 2; + + public final int state; public CaptivePortalStateChangeEvent(int state) { - mState = state; + this.state = state; } public CaptivePortalStateChangeEvent(Parcel in) { - mState = in.readInt(); + state = in.readInt(); } public void writeToParcel(Parcel out, int flags) { - out.writeInt(mState); + out.writeInt(state); + } + + public int describeContents() { + return 0; } public static final Parcelable.Creator<CaptivePortalStateChangeEvent> CREATOR @@ -54,7 +57,6 @@ public class CaptivePortalStateChangeEvent extends IpConnectivityEvent implement }; public static void logEvent(int state) { - IpConnectivityEvent.logEvent(IpConnectivityEvent.IPCE_NETMON_STATE_CHANGE, - new CaptivePortalStateChangeEvent(state)); + logEvent(IPCE_NETMON_STATE_CHANGE, new CaptivePortalStateChangeEvent(state)); } }; diff --git a/core/java/android/net/metrics/ConnectivityServiceChangeEvent.java b/core/java/android/net/metrics/ConnectivityServiceChangeEvent.java index a491ffccad1f..a70649d8f6aa 100644 --- a/core/java/android/net/metrics/ConnectivityServiceChangeEvent.java +++ b/core/java/android/net/metrics/ConnectivityServiceChangeEvent.java @@ -22,43 +22,46 @@ import android.os.Parcelable; /** * {@hide} */ -public class ConnectivityServiceChangeEvent extends IpConnectivityEvent implements Parcelable { - public static final String TAG = "ConnectivityServiceChangeEvent"; - +public final class ConnectivityServiceChangeEvent extends IpConnectivityEvent + implements Parcelable { // The ID of the network that has become the new default or NETID_UNSET if none. - private final int mNetId; + public final int netId; // The list of transport types of the new default network, for example TRANSPORT_WIFI, as // defined in NetworkCapabilities.java. - private final int[] mTransportTypes; + public final int[] transportTypes; // The ID of the network that was the default before or NETID_UNSET if none. - private final int mPrevNetId; + public final int prevNetId; // Whether the previous network had IPv4/IPv6 connectivity. - private final boolean mPrevIPv4; - private final boolean mPrevIPv6; + public final boolean prevIPv4; + public final boolean prevIPv6; - public ConnectivityServiceChangeEvent(int netId, int[] transportTypes, + private ConnectivityServiceChangeEvent(int netId, int[] transportTypes, int prevNetId, boolean prevIPv4, boolean prevIPv6) { - mNetId = netId; - mTransportTypes = transportTypes; - mPrevNetId = prevNetId; - mPrevIPv4 = prevIPv4; - mPrevIPv6 = prevIPv6; + this.netId = netId; + this.transportTypes = transportTypes; + this.prevNetId = prevNetId; + this.prevIPv4 = prevIPv4; + this.prevIPv6 = prevIPv6; } - public ConnectivityServiceChangeEvent(Parcel in) { - mNetId = in.readInt(); - mTransportTypes = in.createIntArray(); - mPrevNetId = in.readInt(); - mPrevIPv4 = (in.readByte() > 0); - mPrevIPv6 = (in.readByte() > 0); + private ConnectivityServiceChangeEvent(Parcel in) { + this.netId = in.readInt(); + this.transportTypes = in.createIntArray(); + this.prevNetId = in.readInt(); + this.prevIPv4 = (in.readByte() > 0); + this.prevIPv6 = (in.readByte() > 0); } public void writeToParcel(Parcel out, int flags) { - out.writeInt(mNetId); - out.writeIntArray(mTransportTypes); - out.writeInt(mPrevNetId); - out.writeByte(mPrevIPv4 ? (byte) 1 : (byte) 0); - out.writeByte(mPrevIPv6 ? (byte) 1 : (byte) 0); + out.writeInt(netId); + out.writeIntArray(transportTypes); + out.writeInt(prevNetId); + out.writeByte(prevIPv4 ? (byte) 1 : (byte) 0); + out.writeByte(prevIPv6 ? (byte) 1 : (byte) 0); + } + + public int describeContents() { + return 0; } public static final Parcelable.Creator<ConnectivityServiceChangeEvent> CREATOR @@ -74,7 +77,7 @@ public class ConnectivityServiceChangeEvent extends IpConnectivityEvent implemen public static void logEvent(int netId, int[] transportTypes, int prevNetId, boolean prevIPv4, boolean prevIPv6) { - IpConnectivityEvent.logEvent(IpConnectivityEvent.IPCE_CONSRV_DEFAULT_NET_CHANGE, + logEvent(IPCE_CONSRV_DEFAULT_NET_CHANGE, new ConnectivityServiceChangeEvent( netId, transportTypes, prevNetId, prevIPv4, prevIPv6)); } diff --git a/core/java/android/net/metrics/DhcpClientEvent.java b/core/java/android/net/metrics/DhcpClientEvent.java index 9213744940a1..51f1740b95cb 100644 --- a/core/java/android/net/metrics/DhcpClientEvent.java +++ b/core/java/android/net/metrics/DhcpClientEvent.java @@ -22,25 +22,27 @@ import android.os.Parcelable; /** * {@hide} */ -public class DhcpClientEvent extends IpConnectivityEvent implements Parcelable { - public static final String TAG = "DhcpClientEvent"; +public final class DhcpClientEvent extends IpConnectivityEvent implements Parcelable { + public final String ifName; + public final String msg; - private String mIfName; - private String mMsg; - - public DhcpClientEvent(String ifName, String msg) { - mIfName = ifName; - mMsg = msg; + private DhcpClientEvent(String ifName, String msg) { + this.ifName = ifName; + this.msg = msg; } - public DhcpClientEvent(Parcel in) { - mIfName = in.readString(); - mMsg = in.readString(); + private DhcpClientEvent(Parcel in) { + this.ifName = in.readString(); + this.msg = in.readString(); } public void writeToParcel(Parcel out, int flags) { - out.writeString(mIfName); - out.writeString(mMsg); + out.writeString(ifName); + out.writeString(msg); + } + + public int describeContents() { + return 0; } public static final Parcelable.Creator<DhcpClientEvent> CREATOR @@ -55,6 +57,6 @@ public class DhcpClientEvent extends IpConnectivityEvent implements Parcelable { }; public static void logStateEvent(String ifName, String state) { - logEvent(IpConnectivityEvent.IPCE_DHCP_STATE_CHANGE, new DhcpClientEvent(ifName, state)); + logEvent(IPCE_DHCP_STATE_CHANGE, new DhcpClientEvent(ifName, state)); } }; diff --git a/core/java/android/net/metrics/DhcpErrorEvent.java b/core/java/android/net/metrics/DhcpErrorEvent.java index f6f98495d77c..ef8a2abbdf1e 100644 --- a/core/java/android/net/metrics/DhcpErrorEvent.java +++ b/core/java/android/net/metrics/DhcpErrorEvent.java @@ -22,9 +22,7 @@ import android.os.Parcelable; /** * {@hide} Event class used to record error events when parsing DHCP response packets. */ -public class DhcpErrorEvent extends IpConnectivityEvent implements Parcelable { - public static final String TAG = "DhcpErrorEvent"; - +public final class DhcpErrorEvent extends IpConnectivityEvent implements Parcelable { public static final int L2_ERROR = 1; public static final int L3_ERROR = 2; public static final int L4_ERROR = 3; @@ -73,6 +71,10 @@ public class DhcpErrorEvent extends IpConnectivityEvent implements Parcelable { out.writeInt(errorCode); } + public int describeContents() { + return 0; + } + public static final Parcelable.Creator<DhcpErrorEvent> CREATOR = new Parcelable.Creator<DhcpErrorEvent>() { public DhcpErrorEvent createFromParcel(Parcel in) { @@ -85,7 +87,7 @@ public class DhcpErrorEvent extends IpConnectivityEvent implements Parcelable { }; public static void logParseError(String ifName, int errorCode) { - IpConnectivityEvent.logEvent(IPCE_DHCP_PARSE_ERROR, new DhcpErrorEvent(ifName, errorCode)); + logEvent(IPCE_DHCP_PARSE_ERROR, new DhcpErrorEvent(ifName, errorCode)); } public static void logReceiveError(String ifName) { diff --git a/core/java/android/net/metrics/DnsEvent.java b/core/java/android/net/metrics/DnsEvent.java index 200b81645409..9f5fd4fff822 100644 --- a/core/java/android/net/metrics/DnsEvent.java +++ b/core/java/android/net/metrics/DnsEvent.java @@ -22,7 +22,7 @@ import android.os.Parcelable; /** * {@hide} */ -public class DnsEvent extends IpConnectivityEvent implements Parcelable { +final public class DnsEvent extends IpConnectivityEvent implements Parcelable { public final int netId; // The event type is currently only 1 or 2, so we store it as a byte. @@ -43,10 +43,10 @@ public class DnsEvent extends IpConnectivityEvent implements Parcelable { } private DnsEvent(Parcel in) { - netId = in.readInt(); - eventTypes = in.createByteArray(); - returnCodes = in.createByteArray(); - latenciesMs = in.createIntArray(); + this.netId = in.readInt(); + this.eventTypes = in.createByteArray(); + this.returnCodes = in.createByteArray(); + this.latenciesMs = in.createIntArray(); } @Override @@ -57,6 +57,10 @@ public class DnsEvent extends IpConnectivityEvent implements Parcelable { out.writeIntArray(latenciesMs); } + public int describeContents() { + return 0; + } + public static final Parcelable.Creator<DnsEvent> CREATOR = new Parcelable.Creator<DnsEvent>() { @Override public DnsEvent createFromParcel(Parcel in) { @@ -71,7 +75,6 @@ public class DnsEvent extends IpConnectivityEvent implements Parcelable { public static void logEvent( int netId, byte[] eventTypes, byte[] returnCodes, int[] latenciesMs) { - IpConnectivityEvent.logEvent(IPCE_DNS_LOOKUPS, - new DnsEvent(netId, eventTypes, returnCodes, latenciesMs)); + logEvent(IPCE_DNS_LOOKUPS, new DnsEvent(netId, eventTypes, returnCodes, latenciesMs)); } } diff --git a/core/java/android/net/metrics/IpConnectivityEvent.java b/core/java/android/net/metrics/IpConnectivityEvent.java index f0a3c902a355..2680b4238bc4 100644 --- a/core/java/android/net/metrics/IpConnectivityEvent.java +++ b/core/java/android/net/metrics/IpConnectivityEvent.java @@ -23,14 +23,13 @@ import android.os.Parcelable; /** * {@hide} */ -public class IpConnectivityEvent implements Parcelable { - public static final String TAG = "IpConnectivityEvent"; - +public abstract class IpConnectivityEvent { // IPRM = IpReachabilityMonitor // DHCP = DhcpClient // NETMON = NetworkMonitorEvent // CONSRV = ConnectivityServiceEvent // IPMGR = IpManager + // DNS = DnsEvent public static final int IPCE_IPRM_BASE = 0 * 1024; public static final int IPCE_DHCP_BASE = 1 * 1024; public static final int IPCE_NETMON_BASE = 2 * 1024; @@ -60,16 +59,10 @@ public class IpConnectivityEvent implements Parcelable { private static ConnectivityMetricsLogger mMetricsLogger = new ConnectivityMetricsLogger(); - public int describeContents() { - return 0; - } - - public void writeToParcel(Parcel out, int flags) { - } - - public static void logEvent(int tag, IpConnectivityEvent event) { - long timestamp = System.currentTimeMillis(); - mMetricsLogger.logEvent(timestamp, ConnectivityMetricsLogger.COMPONENT_TAG_CONNECTIVITY, - tag, event); + public static <T extends IpConnectivityEvent & Parcelable> void logEvent(int tag, T event) { + final long timestamp = System.currentTimeMillis(); + final int componentTag = ConnectivityMetricsLogger.COMPONENT_TAG_CONNECTIVITY; + // TODO: consider using different component for DNS event. + mMetricsLogger.logEvent(timestamp, componentTag, tag, event); } }; diff --git a/core/java/android/net/metrics/IpManagerEvent.java b/core/java/android/net/metrics/IpManagerEvent.java index 6328ccb38256..9b534d778302 100644 --- a/core/java/android/net/metrics/IpManagerEvent.java +++ b/core/java/android/net/metrics/IpManagerEvent.java @@ -22,23 +22,27 @@ import android.os.Parcelable; /** * {@hide} */ -public class IpManagerEvent extends IpConnectivityEvent implements Parcelable { - private String mIfName; - private long mDurationMs; +public final class IpManagerEvent extends IpConnectivityEvent implements Parcelable { + public final String ifName; + public final long durationMs; - public IpManagerEvent(String ifName, long duration) { - mIfName = ifName; - mDurationMs = duration; + private IpManagerEvent(String ifName, long duration) { + this.ifName = ifName; + this.durationMs = duration; } - public IpManagerEvent(Parcel in) { - mIfName = in.readString(); - mDurationMs = in.readLong(); + private IpManagerEvent(Parcel in) { + this.ifName = in.readString(); + this.durationMs = in.readLong(); } public void writeToParcel(Parcel out, int flags) { - out.writeString(mIfName); - out.writeLong(mDurationMs); + out.writeString(ifName); + out.writeLong(durationMs); + } + + public int describeContents() { + return 0; } public static final Parcelable.Creator<IpManagerEvent> CREATOR @@ -53,6 +57,6 @@ public class IpManagerEvent extends IpConnectivityEvent implements Parcelable { }; public static void logEvent(int eventType, String ifName, long durationMs) { - IpConnectivityEvent.logEvent(eventType, new IpManagerEvent(ifName, durationMs)); + logEvent(eventType, new IpManagerEvent(ifName, durationMs)); } }; diff --git a/core/java/android/net/metrics/IpReachabilityMonitorLostEvent.java b/core/java/android/net/metrics/IpReachabilityMonitorLostEvent.java index 0f1421065e66..3033e4dd798a 100644 --- a/core/java/android/net/metrics/IpReachabilityMonitorLostEvent.java +++ b/core/java/android/net/metrics/IpReachabilityMonitorLostEvent.java @@ -22,20 +22,24 @@ import android.os.Parcelable; /** * {@hide} */ -public class IpReachabilityMonitorLostEvent extends IpConnectivityEvent +public final class IpReachabilityMonitorLostEvent extends IpConnectivityEvent implements Parcelable { - private String mIfName; + public final String ifName; - public IpReachabilityMonitorLostEvent(String ifName) { - mIfName = ifName; + private IpReachabilityMonitorLostEvent(String ifName) { + this.ifName = ifName; } - public IpReachabilityMonitorLostEvent(Parcel in) { - mIfName = in.readString(); + private IpReachabilityMonitorLostEvent(Parcel in) { + this.ifName = in.readString(); } public void writeToParcel(Parcel out, int flags) { - out.writeString(mIfName); + out.writeString(ifName); + } + + public int describeContents() { + return 0; } public static final Parcelable.Creator<IpReachabilityMonitorLostEvent> CREATOR @@ -50,7 +54,6 @@ public class IpReachabilityMonitorLostEvent extends IpConnectivityEvent }; public static void logEvent(String ifName) { - IpConnectivityEvent.logEvent(IpConnectivityEvent.IPCE_IPRM_REACHABILITY_LOST, - new IpReachabilityMonitorLostEvent(ifName)); + logEvent(IPCE_IPRM_REACHABILITY_LOST, new IpReachabilityMonitorLostEvent(ifName)); } }; diff --git a/core/java/android/net/metrics/IpReachabilityMonitorMessageEvent.java b/core/java/android/net/metrics/IpReachabilityMonitorMessageEvent.java index e71b0bedd36e..8b1b9258e5a4 100644 --- a/core/java/android/net/metrics/IpReachabilityMonitorMessageEvent.java +++ b/core/java/android/net/metrics/IpReachabilityMonitorMessageEvent.java @@ -22,35 +22,37 @@ import android.os.Parcelable; /** * {@hide} */ -public class IpReachabilityMonitorMessageEvent extends IpConnectivityEvent - implements Parcelable { - public static final String TAG = "IpReachabilityMonitorMessageEvent"; +public final class IpReachabilityMonitorMessageEvent extends IpConnectivityEvent + implements Parcelable { + public final String ifName; + public final String destination; + public final int msgType; + public final int nudState; - private String mIfName; - private String mDestination; - private int mMsgType; - private int mNudState; - - public IpReachabilityMonitorMessageEvent(String ifName, String destination, int msgType, + private IpReachabilityMonitorMessageEvent(String ifName, String destination, int msgType, int nudState) { - mIfName = ifName; - mDestination = destination; - mMsgType = msgType; - mNudState = nudState; + this.ifName = ifName; + this.destination = destination; + this.msgType = msgType; + this.nudState = nudState; } - public IpReachabilityMonitorMessageEvent(Parcel in) { - mIfName = in.readString(); - mDestination = in.readString(); - mMsgType = in.readInt(); - mNudState = in.readInt(); + private IpReachabilityMonitorMessageEvent(Parcel in) { + this.ifName = in.readString(); + this.destination = in.readString(); + this.msgType = in.readInt(); + this.nudState = in.readInt(); } public void writeToParcel(Parcel out, int flags) { - out.writeString(mIfName); - out.writeString(mDestination); - out.writeInt(mMsgType); - out.writeInt(mNudState); + out.writeString(ifName); + out.writeString(destination); + out.writeInt(msgType); + out.writeInt(nudState); + } + + public int describeContents() { + return 0; } public static final Parcelable.Creator<IpReachabilityMonitorMessageEvent> CREATOR @@ -65,7 +67,7 @@ public class IpReachabilityMonitorMessageEvent extends IpConnectivityEvent }; public static void logEvent(String ifName, String destination, int msgType, int nudState) { - IpConnectivityEvent.logEvent(IpConnectivityEvent.IPCE_IPRM_MESSAGE_RECEIVED, + logEvent(IPCE_IPRM_MESSAGE_RECEIVED, new IpReachabilityMonitorMessageEvent(ifName, destination, msgType, nudState)); } }; diff --git a/core/java/android/net/metrics/IpReachabilityMonitorProbeEvent.java b/core/java/android/net/metrics/IpReachabilityMonitorProbeEvent.java index 182b7780241c..b1698d98db6e 100644 --- a/core/java/android/net/metrics/IpReachabilityMonitorProbeEvent.java +++ b/core/java/android/net/metrics/IpReachabilityMonitorProbeEvent.java @@ -22,30 +22,32 @@ import android.os.Parcelable; /** * {@hide} */ -public class IpReachabilityMonitorProbeEvent extends IpConnectivityEvent - implements Parcelable { - public static final String TAG = "IpReachabilityMonitorProbeEvent"; +public final class IpReachabilityMonitorProbeEvent extends IpConnectivityEvent + implements Parcelable { + public final String ifName; + public final String destination; + public final boolean success; - private String mIfName; - private String mDestination; - private boolean mSuccess; - - public IpReachabilityMonitorProbeEvent(String ifName, String destination, boolean success) { - mIfName = ifName; - mDestination = destination; - mSuccess = success; + private IpReachabilityMonitorProbeEvent(String ifName, String destination, boolean success) { + this.ifName = ifName; + this.destination = destination; + this.success = success; } - public IpReachabilityMonitorProbeEvent(Parcel in) { - mIfName = in.readString(); - mDestination = in.readString(); - mSuccess = in.readByte() > 0 ? true : false; + private IpReachabilityMonitorProbeEvent(Parcel in) { + this.ifName = in.readString(); + this.destination = in.readString(); + this.success = in.readByte() > 0 ? true : false; } public void writeToParcel(Parcel out, int flags) { - out.writeString(mIfName); - out.writeString(mDestination); - out.writeByte((byte)(mSuccess ? 1 : 0)); + out.writeString(ifName); + out.writeString(destination); + out.writeByte((byte)(success ? 1 : 0)); + } + + public int describeContents() { + return 0; } public static final Parcelable.Creator<IpReachabilityMonitorProbeEvent> CREATOR @@ -60,7 +62,7 @@ public class IpReachabilityMonitorProbeEvent extends IpConnectivityEvent }; public static void logEvent(String ifName, String destination, boolean success) { - IpConnectivityEvent.logEvent(IpConnectivityEvent.IPCE_IPRM_PROBE_RESULT, + logEvent(IPCE_IPRM_PROBE_RESULT, new IpReachabilityMonitorProbeEvent(ifName, destination, success)); } }; |