Merge "Extend onDnsEvent callback to report more fields."
This commit is contained in:
@@ -28,6 +28,11 @@ oneway interface INetdEventCallback {
|
||||
* Reports a single DNS lookup function call.
|
||||
* This method must not block or perform long-running operations.
|
||||
*
|
||||
* @param netId the ID of the network the lookup was performed on.
|
||||
* @param eventType one of the EVENT_* constants in {@link INetdEventListener}.
|
||||
* @param returnCode the return value of the query, may vary based on {@code eventType}. See
|
||||
* {@code getaddrinfo()}, {@code gethostbyaddr()} and {@code gethostbyname()} section in
|
||||
* bionic/libc/include/netdb.h.
|
||||
* @param hostname the name that was looked up.
|
||||
* @param ipAddresses (possibly a subset of) the IP addresses returned.
|
||||
* At most {@link #DNS_REPORTED_IP_ADDRESSES_LIMIT} addresses are logged.
|
||||
@@ -36,8 +41,8 @@ oneway interface INetdEventCallback {
|
||||
* @param timestamp the timestamp at which the query was reported by netd.
|
||||
* @param uid the UID of the application that performed the query.
|
||||
*/
|
||||
void onDnsEvent(String hostname, in String[] ipAddresses, int ipAddressesCount, long timestamp,
|
||||
int uid);
|
||||
void onDnsEvent(int netId, int eventType, int returnCode, String hostname,
|
||||
in String[] ipAddresses, int ipAddressesCount, long timestamp, int uid);
|
||||
|
||||
/**
|
||||
* Represents a private DNS validation success or failure.
|
||||
|
||||
@@ -26,8 +26,8 @@ import android.net.INetdEventCallback;
|
||||
*/
|
||||
public class BaseNetdEventCallback extends INetdEventCallback.Stub {
|
||||
@Override
|
||||
public void onDnsEvent(String hostname, String[] ipAddresses,
|
||||
int ipAddressesCount, long timestamp, int uid) {
|
||||
public void onDnsEvent(int netId, int eventType, int returnCode, String hostname,
|
||||
String[] ipAddresses, int ipAddressesCount, long timestamp, int uid) {
|
||||
// default no-op
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,8 @@ public class NetdEventListenerService extends INetdEventListener.Stub {
|
||||
|
||||
for (INetdEventCallback callback : mNetdEventCallbackList) {
|
||||
if (callback != null) {
|
||||
callback.onDnsEvent(hostname, ipAddresses, ipAddressesCount, timestamp, uid);
|
||||
callback.onDnsEvent(netId, eventType, returnCode, hostname, ipAddresses,
|
||||
ipAddressesCount, timestamp, uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +142,8 @@ public class NetworkWatchlistService extends INetworkWatchlistManager.Stub {
|
||||
|
||||
private final INetdEventCallback mNetdEventCallback = new BaseNetdEventCallback() {
|
||||
@Override
|
||||
public void onDnsEvent(String hostname, String[] ipAddresses, int ipAddressesCount,
|
||||
long timestamp, int uid) {
|
||||
public void onDnsEvent(int netId, int eventType, int returnCode, String hostname,
|
||||
String[] ipAddresses, int ipAddressesCount, long timestamp, int uid) {
|
||||
if (!mIsLoggingEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ final class NetworkLogger {
|
||||
|
||||
private final INetdEventCallback mNetdEventCallback = new BaseNetdEventCallback() {
|
||||
@Override
|
||||
public void onDnsEvent(String hostname, String[] ipAddresses, int ipAddressesCount,
|
||||
long timestamp, int uid) {
|
||||
public void onDnsEvent(int netId, int eventType, int returnCode, String hostname,
|
||||
String[] ipAddresses, int ipAddressesCount, long timestamp, int uid) {
|
||||
if (!mIsLoggingEnabled.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,9 @@ import java.util.concurrent.TimeUnit;
|
||||
@MediumTest
|
||||
public class NetworkWatchlistServiceTests {
|
||||
|
||||
private static final long NETWOR_EVENT_TIMEOUT_SEC = 1;
|
||||
private static final long NETWORK_EVENT_TIMEOUT_SEC = 1;
|
||||
private static final int TEST_NETID = 100;
|
||||
private static final int TEST_EVENT_TYPE = 1;
|
||||
private static final String TEST_HOST = "testhost.com";
|
||||
private static final String TEST_IP = "7.6.8.9";
|
||||
private static final String[] TEST_IPS =
|
||||
@@ -180,8 +182,9 @@ public class NetworkWatchlistServiceTests {
|
||||
}
|
||||
};
|
||||
mWatchlistService.mNetworkWatchlistHandler = testDnsHandler;
|
||||
connectivityMetrics.callback.onDnsEvent(TEST_HOST, TEST_IPS, TEST_IPS.length, 123L, 456);
|
||||
if (!testDnsLatch.await(NETWOR_EVENT_TIMEOUT_SEC, TimeUnit.SECONDS)) {
|
||||
connectivityMetrics.callback.onDnsEvent(TEST_NETID, TEST_EVENT_TYPE, 0,
|
||||
TEST_HOST, TEST_IPS, TEST_IPS.length, 123L, 456);
|
||||
if (!testDnsLatch.await(NETWORK_EVENT_TIMEOUT_SEC, TimeUnit.SECONDS)) {
|
||||
fail("Timed out waiting for network event");
|
||||
}
|
||||
assertEquals(TEST_HOST, dnsParams[0]);
|
||||
@@ -206,7 +209,7 @@ public class NetworkWatchlistServiceTests {
|
||||
};
|
||||
mWatchlistService.mNetworkWatchlistHandler = testConnectHandler;
|
||||
connectivityMetrics.callback.onConnectEvent(TEST_IP, 80, 123L, 456);
|
||||
if (!testConnectLatch.await(NETWOR_EVENT_TIMEOUT_SEC, TimeUnit.SECONDS)) {
|
||||
if (!testConnectLatch.await(NETWORK_EVENT_TIMEOUT_SEC, TimeUnit.SECONDS)) {
|
||||
fail("Timed out waiting for network event");
|
||||
}
|
||||
assertNull(connectParams[0]);
|
||||
|
||||
Reference in New Issue
Block a user