diff options
| author | 2016-10-31 15:04:37 +0900 | |
|---|---|---|
| committer | 2016-12-09 14:34:39 +0900 | |
| commit | 5d0f28c7fdd8432c41ed38659d920fa9fad291fb (patch) | |
| tree | 1013060c4fbe931aca7b2b72a2111fe61d99b618 | |
| parent | 744b02069d7589dc192b19fac6c3e7d62d02e88a (diff) | |
DO NOT MERGE: Netd events: record connect() success/errno
Test: $ runtest frameworks-net pass
Bug: 32198976
(cherry picked from commit 8b06bcdfd24100302818ae0e11ee751dd813d5cf)
| -rw-r--r-- | services/core/java/com/android/server/connectivity/NetdEventListenerService.java | 25 | ||||
| -rw-r--r-- | tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java | 11 |
2 files changed, 21 insertions, 15 deletions
diff --git a/services/core/java/com/android/server/connectivity/NetdEventListenerService.java b/services/core/java/com/android/server/connectivity/NetdEventListenerService.java index 4b175d7a5af8..f8638c544e8e 100644 --- a/services/core/java/com/android/server/connectivity/NetdEventListenerService.java +++ b/services/core/java/com/android/server/connectivity/NetdEventListenerService.java @@ -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)); } } diff --git a/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java b/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java index 9e2fd6231ba9..af4a374bffdd 100644 --- a/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java +++ b/tests/net/java/com/android/server/connectivity/NetdEventListenerServiceTest.java @@ -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(); } } |