Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 627b4249 authored by Hugo Benichi's avatar Hugo Benichi
Browse files

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
parent 2677b195
Loading
Loading
Loading
Loading
+16 −15
Original line number Original line Diff line number Diff line
@@ -22,25 +22,27 @@ import android.os.Parcelable;
/**
/**
 * {@hide}
 * {@hide}
 */
 */
public class CaptivePortalCheckResultEvent extends IpConnectivityEvent implements Parcelable {
public final class CaptivePortalCheckResultEvent extends IpConnectivityEvent implements Parcelable {
    public static final String TAG = "CaptivePortalCheckResultEvent";
    public final int netId;
    public final int result;


    private int mNetId;
    private CaptivePortalCheckResultEvent(int netId, int result) {
    private int mResult;
        this.netId = netId;

        this.result = result;
    public CaptivePortalCheckResultEvent(int netId, int result) {
        mNetId = netId;
        mResult = result;
    }
    }


    public CaptivePortalCheckResultEvent(Parcel in) {
    private CaptivePortalCheckResultEvent(Parcel in) {
        mNetId = in.readInt();
        this.netId = in.readInt();
        mResult = in.readInt();
        this.result = in.readInt();
    }
    }


    public void writeToParcel(Parcel out, int flags) {
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mNetId);
        out.writeInt(netId);
        out.writeInt(mResult);
        out.writeInt(result);
    }

    public int describeContents() {
        return 0;
    }
    }


    public static final Parcelable.Creator<CaptivePortalCheckResultEvent> CREATOR
    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) {
    public static void logEvent(int netId, int result) {
        IpConnectivityEvent.logEvent(IpConnectivityEvent.IPCE_NETMON_CHECK_RESULT,
        logEvent(IPCE_NETMON_CHECK_RESULT, new CaptivePortalCheckResultEvent(netId, result));
                new CaptivePortalCheckResultEvent(netId, result));
    }
    }
};
};
+13 −11
Original line number Original line Diff line number Diff line
@@ -22,24 +22,27 @@ import android.os.Parcelable;
/**
/**
 * {@hide}
 * {@hide}
 */
 */
public class CaptivePortalStateChangeEvent extends IpConnectivityEvent implements Parcelable {
public final class CaptivePortalStateChangeEvent extends IpConnectivityEvent implements Parcelable {
    public static final String TAG = "CaptivePortalStateChangeEvent";

    public static final int NETWORK_MONITOR_CONNECTED    = 0;
    public static final int NETWORK_MONITOR_CONNECTED    = 0;
    public static final int NETWORK_MONITOR_DISCONNECTED = 1;
    public static final int NETWORK_MONITOR_DISCONNECTED = 1;
    public static final int NETWORK_MONITOR_VALIDATED    = 2;
    public static final int NETWORK_MONITOR_VALIDATED    = 2;
    private int mState;

    public final int state;


    public CaptivePortalStateChangeEvent(int state) {
    public CaptivePortalStateChangeEvent(int state) {
        mState = state;
        this.state = state;
    }
    }


    public CaptivePortalStateChangeEvent(Parcel in) {
    public CaptivePortalStateChangeEvent(Parcel in) {
        mState = in.readInt();
        state = in.readInt();
    }
    }


    public void writeToParcel(Parcel out, int flags) {
    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
    public static final Parcelable.Creator<CaptivePortalStateChangeEvent> CREATOR
@@ -54,7 +57,6 @@ public class CaptivePortalStateChangeEvent extends IpConnectivityEvent implement
    };
    };


    public static void logEvent(int state) {
    public static void logEvent(int state) {
        IpConnectivityEvent.logEvent(IpConnectivityEvent.IPCE_NETMON_STATE_CHANGE,
        logEvent(IPCE_NETMON_STATE_CHANGE, new CaptivePortalStateChangeEvent(state));
                new CaptivePortalStateChangeEvent(state));
    }
    }
};
};
+29 −26
Original line number Original line Diff line number Diff line
@@ -22,43 +22,46 @@ import android.os.Parcelable;
/**
/**
 * {@hide}
 * {@hide}
 */
 */
public class ConnectivityServiceChangeEvent extends IpConnectivityEvent implements Parcelable {
public final class ConnectivityServiceChangeEvent extends IpConnectivityEvent
    public static final String TAG = "ConnectivityServiceChangeEvent";
        implements Parcelable {

    // The ID of the network that has become the new default or NETID_UNSET if none.
    // 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
    // The list of transport types of the new default network, for example TRANSPORT_WIFI, as
    // defined in NetworkCapabilities.java.
    // 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.
    // 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.
    // Whether the previous network had IPv4/IPv6 connectivity.
    private final boolean mPrevIPv4;
    public final boolean prevIPv4;
    private final boolean mPrevIPv6;
    public final boolean prevIPv6;


    public ConnectivityServiceChangeEvent(int netId, int[] transportTypes,
    private ConnectivityServiceChangeEvent(int netId, int[] transportTypes,
                int prevNetId, boolean prevIPv4, boolean prevIPv6) {
                int prevNetId, boolean prevIPv4, boolean prevIPv6) {
        mNetId = netId;
        this.netId = netId;
        mTransportTypes = transportTypes;
        this.transportTypes = transportTypes;
        mPrevNetId = prevNetId;
        this.prevNetId = prevNetId;
        mPrevIPv4 = prevIPv4;
        this.prevIPv4 = prevIPv4;
        mPrevIPv6 = prevIPv6;
        this.prevIPv6 = prevIPv6;
    }
    }


    public ConnectivityServiceChangeEvent(Parcel in) {
    private ConnectivityServiceChangeEvent(Parcel in) {
        mNetId = in.readInt();
        this.netId = in.readInt();
        mTransportTypes = in.createIntArray();
        this.transportTypes = in.createIntArray();
        mPrevNetId = in.readInt();
        this.prevNetId = in.readInt();
        mPrevIPv4 = (in.readByte() > 0);
        this.prevIPv4 = (in.readByte() > 0);
        mPrevIPv6 = (in.readByte() > 0);
        this.prevIPv6 = (in.readByte() > 0);
    }
    }


    public void writeToParcel(Parcel out, int flags) {
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mNetId);
        out.writeInt(netId);
        out.writeIntArray(mTransportTypes);
        out.writeIntArray(transportTypes);
        out.writeInt(mPrevNetId);
        out.writeInt(prevNetId);
        out.writeByte(mPrevIPv4 ? (byte) 1 : (byte) 0);
        out.writeByte(prevIPv4 ? (byte) 1 : (byte) 0);
        out.writeByte(mPrevIPv6 ? (byte) 1 : (byte) 0);
        out.writeByte(prevIPv6 ? (byte) 1 : (byte) 0);
    }

    public int describeContents() {
        return 0;
    }
    }


    public static final Parcelable.Creator<ConnectivityServiceChangeEvent> CREATOR
    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,
    public static void logEvent(int netId, int[] transportTypes,
            int prevNetId, boolean prevIPv4, boolean prevIPv6) {
            int prevNetId, boolean prevIPv4, boolean prevIPv6) {
        IpConnectivityEvent.logEvent(IpConnectivityEvent.IPCE_CONSRV_DEFAULT_NET_CHANGE,
        logEvent(IPCE_CONSRV_DEFAULT_NET_CHANGE,
                new ConnectivityServiceChangeEvent(
                new ConnectivityServiceChangeEvent(
                        netId, transportTypes, prevNetId, prevIPv4, prevIPv6));
                        netId, transportTypes, prevNetId, prevIPv4, prevIPv6));
    }
    }
+16 −14
Original line number Original line Diff line number Diff line
@@ -22,25 +22,27 @@ import android.os.Parcelable;
/**
/**
 * {@hide}
 * {@hide}
 */
 */
public class DhcpClientEvent extends IpConnectivityEvent implements Parcelable {
public final class DhcpClientEvent extends IpConnectivityEvent implements Parcelable {
    public static final String TAG = "DhcpClientEvent";
    public final String ifName;
    public final String msg;


    private String mIfName;
    private DhcpClientEvent(String ifName, String msg) {
    private String mMsg;
        this.ifName = ifName;

        this.msg = msg;
    public DhcpClientEvent(String ifName, String msg) {
        mIfName = ifName;
        mMsg = msg;
    }
    }


    public DhcpClientEvent(Parcel in) {
    private DhcpClientEvent(Parcel in) {
        mIfName = in.readString();
        this.ifName = in.readString();
        mMsg = in.readString();
        this.msg = in.readString();
    }
    }


    public void writeToParcel(Parcel out, int flags) {
    public void writeToParcel(Parcel out, int flags) {
        out.writeString(mIfName);
        out.writeString(ifName);
        out.writeString(mMsg);
        out.writeString(msg);
    }

    public int describeContents() {
        return 0;
    }
    }


    public static final Parcelable.Creator<DhcpClientEvent> CREATOR
    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) {
    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));
    }
    }
};
};
+6 −4
Original line number Original line Diff line number Diff line
@@ -22,9 +22,7 @@ import android.os.Parcelable;
/**
/**
 * {@hide} Event class used to record error events when parsing DHCP response packets.
 * {@hide} Event class used to record error events when parsing DHCP response packets.
 */
 */
public class DhcpErrorEvent extends IpConnectivityEvent implements Parcelable {
public final class DhcpErrorEvent extends IpConnectivityEvent implements Parcelable {
    public static final String TAG = "DhcpErrorEvent";

    public static final int L2_ERROR   = 1;
    public static final int L2_ERROR   = 1;
    public static final int L3_ERROR   = 2;
    public static final int L3_ERROR   = 2;
    public static final int L4_ERROR   = 3;
    public static final int L4_ERROR   = 3;
@@ -73,6 +71,10 @@ public class DhcpErrorEvent extends IpConnectivityEvent implements Parcelable {
        out.writeInt(errorCode);
        out.writeInt(errorCode);
    }
    }


    public int describeContents() {
        return 0;
    }

    public static final Parcelable.Creator<DhcpErrorEvent> CREATOR
    public static final Parcelable.Creator<DhcpErrorEvent> CREATOR
        = new Parcelable.Creator<DhcpErrorEvent>() {
        = new Parcelable.Creator<DhcpErrorEvent>() {
        public DhcpErrorEvent createFromParcel(Parcel in) {
        public DhcpErrorEvent createFromParcel(Parcel in) {
@@ -85,7 +87,7 @@ public class DhcpErrorEvent extends IpConnectivityEvent implements Parcelable {
    };
    };


    public static void logParseError(String ifName, int errorCode) {
    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) {
    public static void logReceiveError(String ifName) {
Loading