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

Commit 222ebe48 authored by Hugo Benichi's avatar Hugo Benichi Committed by Lorenzo Colitti
Browse files

Netd events: record connect() success/errno

Test: $ runtest frameworks-net pass
Bug: 32198976

(cherry picked from commit 8b06bcdf)

Change-Id: Ib3be06d2678c3fcfe4fa9d7b77f50c6e8812db3d
parent bea525ef
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.net.NetworkRequest;
import android.net.metrics.DnsEvent;
import android.net.metrics.INetdEventListener;
import android.net.metrics.IpConnectivityLog;
import android.os.RemoteException;
import android.util.Log;

import com.android.internal.annotations.GuardedBy;
@@ -44,7 +45,7 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
    public static final String SERVICE_NAME = "netd_listener";

    private static final String TAG = NetdEventListenerService.class.getSimpleName();
    private static final boolean DBG = true;
    private static final boolean DBG = false;
    private static final boolean VDBG = false;

    // TODO: read this constant from system property
@@ -86,7 +87,7 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
            byte[] returnCodes = Arrays.copyOf(mReturnCodes, mEventCount);
            int[] latenciesMs = Arrays.copyOf(mLatenciesMs, mEventCount);
            mMetricsLog.log(new DnsEvent(mNetId, eventTypes, returnCodes, latenciesMs));
            maybeLog(String.format("Logging %d results for netId %d", mEventCount, mNetId));
            maybeLog("Logging %d results for netId %d", mEventCount, mNetId);
            mEventCount = 0;
        }

@@ -136,9 +137,9 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
    // Called concurrently by multiple binder threads.
    // This method must not block or perform long-running operations.
    public synchronized void onDnsEvent(int netId, int eventType, int returnCode, int latencyMs,
            String hostname, String[] ipAddresses, int ipAddressesCount, int uid) {
        maybeVerboseLog(String.format("onDnsEvent(%d, %d, %d, %d)",
                netId, eventType, returnCode, latencyMs));
            String hostname, String[] ipAddresses, int ipAddressesCount, int uid)
            throws RemoteException {
        maybeVerboseLog("onDnsEvent(%d, %d, %d, %dms)", netId, eventType, returnCode, latencyMs);

        DnsEventBatch batch = mEventBatches.get(netId);
        if (batch == null) {
@@ -151,9 +152,9 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
    @Override
    // Called concurrently by multiple binder threads.
    // This method must not block or perform long-running operations.
    public synchronized void onConnectEvent(int netId, int latencyMs, String ipAddr, int port,
            int uid) {
        maybeVerboseLog(String.format("onConnectEvent(%d, %d)", netId, latencyMs));
    public synchronized void onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port,
            int uid) throws RemoteException {
        maybeVerboseLog("onConnectEvent(%d, %d, %dms)", netId, error, latencyMs);
    }

    public synchronized void dump(PrintWriter writer) {
@@ -166,11 +167,11 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
        pw.decreaseIndent();
    }

    private static void maybeLog(String s) {
        if (DBG) Log.d(TAG, s);
    private static void maybeLog(String s, Object... args) {
        if (DBG) Log.d(TAG, String.format(s, args));
    }

    private static void maybeVerboseLog(String s) {
        if (VDBG) Log.d(TAG, s);
    private static void maybeVerboseLog(String s, Object... args) {
        if (VDBG) Log.d(TAG, String.format(s, args));
    }
}
+8 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.net.Network;
import android.net.metrics.DnsEvent;
import android.net.metrics.INetdEventListener;
import android.net.metrics.IpConnectivityLog;
import android.os.RemoteException;

import junit.framework.TestCase;
import org.junit.Before;
@@ -157,9 +158,13 @@ public class NetdEventListenerServiceTest extends TestCase {
    }

    void log(int netId, int[] latencies) {
        try {
            for (int l : latencies) {
            mNetdEventListenerService.onDnsEvent(netId, EVENT_TYPE, RETURN_CODE, l, null, null, 0,
                    0);
                mNetdEventListenerService.onDnsEvent(netId, EVENT_TYPE, RETURN_CODE, l, null, null,
                        0, 0);
            }
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }