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

Commit 4c2d2d54 authored by junyulai's avatar junyulai Committed by Chiachang Wang
Browse files

Extend onDnsEvent callback to report more fields.

When native layer reports onDnsEvent, netId, eventType and
returnCode are available only in NetdEventListenerService, but
not for the clients who register event on it.

Thus, extend the callback to give clients more detail on the
network the look up was performed on and the result of the
lookup.

Bug: 113916551
Test: 1. runtest frameworks-net
      2. runtest frameworks-services -c com.android.server. \
         net.watchlist.NetworkWatchlistServiceTests
Change-Id: If7beecea50e1baf18cb5c6775ad3ecb1a60b312a
parent 0d63da86
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -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.
+2 −2
Original line number Diff line number Diff line
@@ -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
    }

+2 −1
Original line number Diff line number Diff line
@@ -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);
            }
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -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;
            }
+2 −2
Original line number Diff line number Diff line
@@ -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;
            }
Loading