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

Commit ce4d2705 authored by Liz Prucka's avatar Liz Prucka Committed by Android (Google) Code Review
Browse files

Merge "[IntrusionLogging] Add DNS receiver for DNSConnection event" into main

parents dab91059 9115ec9b
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -265,7 +265,11 @@ public class IntrusionDetectionService extends SystemService {
    }

    private void transport(List<IntrusionDetectionEvent> events) {
        try {
            mIntrusionDetectionEventTransportConnection.addData(events);
        } catch (Throwable t) {
            Slog.e(TAG, "Failed to transport data: ", t);
        }
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ public class NetworkLogSource implements DataSource {
            return;
        }
        try {
            if (!mIpConnectivityMetrics.removeNetdEventCallback(
            if (mIpConnectivityMetrics.removeNetdEventCallback(
                    INetdEventCallback.CALLBACK_CALLER_DEVICE_POLICY)) {

                mIsNetworkLoggingEnabled.set(false);
+25 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

package com.android.coretests.apps.testapp;

import android.app.admin.DnsEvent;
import android.app.admin.SecurityLog;
import android.app.admin.SecurityLog.SecurityEvent;
import android.content.Context;
@@ -43,8 +44,11 @@ public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEve

    private static final String ACTION_SECURITY_EVENT_RECEIVED =
            "com.android.coretests.apps.testapp.ACTION_SECURITY_EVENT_RECEIVED";
    private static final String ACTION_DNS_EVENT_RECEIVED =
            "com.android.coretests.apps.testapp.ACTION_DNS_EVENT_RECEIVED";
    private static final String TAG = "LocalIntrusionDetectionEventTransport";
    private static final String TEST_SECURITY_EVENT_TAG = "test_security_event_tag";
    private static final String TEST_DNS_EVENT_TAG = "google.com";
    private static Context sContext;

    public LocalIntrusionDetectionEventTransport(Context context) {
@@ -57,13 +61,23 @@ public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEve
        try {
            Intent intent = new Intent(ACTION_SECURITY_EVENT_RECEIVED);
            sContext.sendBroadcast(intent);
            Log.i(TAG, "LIZ_TESTING: sent broadcast");
        } catch (Exception e) {
            Log.e(TAG, "Exception sending broadcast", e);
            Log.e(TAG, "Exception sending security event broadcast", e);
        }
    }

    private static void checkIfSecurityEventReceivedFromCts(List<IntrusionDetectionEvent> events) {
    // Broadcast an intent to the CTS test service to indicate that the DNS
    // event was received.
    private static void broadcastDnsEventReceived() {
        try {
            Intent intent = new Intent(ACTION_DNS_EVENT_RECEIVED);
            sContext.sendBroadcast(intent);
        } catch (Exception e) {
            Log.e(TAG, "Exception sending network event broadcast", e);
        }
    }

    private static void checkIfCtsEventReceived(List<IntrusionDetectionEvent> events) {
        // Loop through the events and check if any of them are the security event
        // that uses the TEST_SECURITY_EVENT_TAG tag, which is set by the CTS test.
        for (IntrusionDetectionEvent event : events) {
@@ -76,6 +90,13 @@ public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEve
                    return;
                }
            }
            if (event.getType() == IntrusionDetectionEvent.NETWORK_EVENT_DNS) {
                DnsEvent dnsEvent = event.getDnsEvent();
                if (dnsEvent.getHostname().equals(TEST_DNS_EVENT_TAG)) {
                    broadcastDnsEventReceived();
                    return;
                }
            }
        }
    }

@@ -90,7 +111,7 @@ public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEve
        // verify the event is received with the appropriate data, we will
        // check the events locally and set a property value that can be
        // read by the test.
        checkIfSecurityEventReceivedFromCts(events);
        checkIfCtsEventReceived(events);
        mEvents.addAll(events);
        return true;
    }