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
diff --git a/core/java/android/net/metrics/IpManagerEvent.java b/core/java/android/net/metrics/IpManagerEvent.java
index 6328ccb..9b534d7 100644
--- a/core/java/android/net/metrics/IpManagerEvent.java
+++ b/core/java/android/net/metrics/IpManagerEvent.java
@@ -22,23 +22,27 @@
/**
* {@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 static void logEvent(int eventType, String ifName, long durationMs) {
- IpConnectivityEvent.logEvent(eventType, new IpManagerEvent(ifName, durationMs));
+ logEvent(eventType, new IpManagerEvent(ifName, durationMs));
}
};