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

Commit cfddd687 authored by Hugo Benichi's avatar Hugo Benichi
Browse files

Refactor IP connectivity event logging

This patch removes static methods for logging IP connectivity events
defined in android.net.metrics and replaces them with a single log()
instance method defined on IpConnectivityLog. Event constructors are
now public also. Every classes logging such events now create an
instance of IpConnectivityLog for logging event objects directly
instantiated with new.

Removing static dependencies allow straightforward testing of logging.

This patch also removes the base IpConnectivityEvent class which is not
needed any more.

Bug: 29035129
Change-Id: I3de700f93f46deaa48a759f938f7d00e1d8bff98
parent 5bf74ae1
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.os.Parcelable;
 * {@hide}
 */
@SystemApi
public final class DefaultNetworkEvent extends IpConnectivityEvent implements Parcelable {
public final class DefaultNetworkEvent implements Parcelable {
    // The ID of the network that has become the new default or NETID_UNSET if none.
    public final int netId;
    // The list of transport types of the new default network, for example TRANSPORT_WIFI, as
@@ -37,7 +37,8 @@ public final class DefaultNetworkEvent extends IpConnectivityEvent implements Pa
    public final boolean prevIPv4;
    public final boolean prevIPv6;

    private DefaultNetworkEvent(int netId, int[] transportTypes,
    /** {@hide} */
    public DefaultNetworkEvent(int netId, int[] transportTypes,
                int prevNetId, boolean prevIPv4, boolean prevIPv6) {
        this.netId = netId;
        this.transportTypes = transportTypes;
@@ -105,6 +106,5 @@ public final class DefaultNetworkEvent extends IpConnectivityEvent implements Pa

    public static void logEvent(
            int netId, int[] transports, int prevNetId, boolean hadIPv4, boolean hadIPv6) {
        logEvent(new DefaultNetworkEvent(netId, transports, prevNetId, hadIPv4, hadIPv6));
    }
};
}
+4 −4
Original line number Diff line number Diff line
@@ -24,11 +24,12 @@ import android.os.Parcelable;
 * {@hide}
 */
@SystemApi
public final class DhcpClientEvent extends IpConnectivityEvent implements Parcelable {
public final class DhcpClientEvent implements Parcelable {
    public final String ifName;
    public final String msg;

    private DhcpClientEvent(String ifName, String msg) {
    /** {@hide} */
    public DhcpClientEvent(String ifName, String msg) {
        this.ifName = ifName;
        this.msg = msg;
    }
@@ -64,6 +65,5 @@ public final class DhcpClientEvent extends IpConnectivityEvent implements Parcel
    };

    public static void logStateEvent(String ifName, String state) {
        logEvent(new DhcpClientEvent(ifName, state));
    }
};
}
+3 −4
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import com.android.internal.util.MessageUtils;
 * {@hide} Event class used to record error events when parsing DHCP response packets.
 */
@SystemApi
public final class DhcpErrorEvent extends IpConnectivityEvent implements Parcelable {
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;
@@ -61,7 +61,8 @@ public final class DhcpErrorEvent extends IpConnectivityEvent implements Parcela
    // byte 3: optional code
    public final int errorCode;

    private DhcpErrorEvent(String ifName, int errorCode) {
    /** {@hide} */
    public DhcpErrorEvent(String ifName, int errorCode) {
        this.ifName = ifName;
        this.errorCode = errorCode;
    }
@@ -92,11 +93,9 @@ public final class DhcpErrorEvent extends IpConnectivityEvent implements Parcela
    };

    public static void logParseError(String ifName, int errorCode) {
        logEvent(new DhcpErrorEvent(ifName, errorCode));
    }

    public static void logReceiveError(String ifName) {
        logEvent(new DhcpErrorEvent(ifName, RECEIVE_ERROR));
    }

    public static int errorCodeWithOption(int errorCode, int option) {
+3 −3
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import android.os.Parcelable;
 * {@hide}
 */
@SystemApi
final public class DnsEvent extends IpConnectivityEvent implements Parcelable {
final public class DnsEvent implements Parcelable {
    public final int netId;

    // The event type is currently only 1 or 2, so we store it as a byte.
@@ -37,7 +37,8 @@ final public class DnsEvent extends IpConnectivityEvent implements Parcelable {
    // queries.
    public final int[] latenciesMs;

    private DnsEvent(int netId, byte[] eventTypes, byte[] returnCodes, int[] latenciesMs) {
    /** {@hide} */
    public DnsEvent(int netId, byte[] eventTypes, byte[] returnCodes, int[] latenciesMs) {
        this.netId = netId;
        this.eventTypes = eventTypes;
        this.returnCodes = returnCodes;
@@ -82,6 +83,5 @@ final public class DnsEvent extends IpConnectivityEvent implements Parcelable {

    public static void logEvent(
            int netId, byte[] eventTypes, byte[] returnCodes, int[] latenciesMs) {
        logEvent(new DnsEvent(netId, eventTypes, returnCodes, latenciesMs));
    }
}
+0 −28
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.metrics;

import android.os.Parcelable;

/** {@hide} */
public abstract class IpConnectivityEvent {
    private static final IpConnectivityLog sMetricsLog = new IpConnectivityLog();

    static <T extends IpConnectivityEvent & Parcelable> void logEvent(T event) {
        sMetricsLog.log(System.currentTimeMillis(), event);
    }
}
Loading