DO NOT MERGE: Netd events: record connect() success/errno
Test: $ runtest frameworks-net pass
Bug: 32198976
(cherry picked from commit 8b06bcdfd2)
This commit is contained in:
committed by
Lorenzo Colitti
parent
744b02069d
commit
5d0f28c7fd
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
for (int l : latencies) {
|
||||
mNetdEventListenerService.onDnsEvent(netId, EVENT_TYPE, RETURN_CODE, l, null, null, 0,
|
||||
0);
|
||||
try {
|
||||
for (int l : latencies) {
|
||||
mNetdEventListenerService.onDnsEvent(netId, EVENT_TYPE, RETURN_CODE, l, null, null,
|
||||
0, 0);
|
||||
}
|
||||
} catch (RemoteException re) {
|
||||
throw re.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user