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

Commit 056ed98e authored by Mark Teffeteller's avatar Mark Teffeteller Committed by Liz Prucka
Browse files

Verify CTS test data is received in `addData` method.

Confirm the events received by the test app are the expected CTS security and network events, and sets a property value if they are received so that the CTS tests can verify the data was received.

Bug: 400790619
Test: atest frameworks/base/services/tests/security/intrusiondetection/src/com/android
/server/security/intrusiondetection/IntrusionDetectionServiceTest.java
Ignore-AOSP-First: security feature
Flag: android.security.internal_log_event_listener

Change-Id: Id25633e4ef425fdd65eed74e644f9c9c5e84240b
parent 10c537fe
Loading
Loading
Loading
Loading
+49 −1
Original line number Original line Diff line number Diff line
@@ -18,8 +18,13 @@


package com.android.coretests.apps.testapp;
package com.android.coretests.apps.testapp;


import android.app.admin.SecurityLog;
import android.app.admin.SecurityLog.SecurityEvent;
import android.content.Context;
import android.content.Intent;
import android.security.intrusiondetection.IntrusionDetectionEvent;
import android.security.intrusiondetection.IntrusionDetectionEvent;
import android.security.intrusiondetection.IntrusionDetectionEventTransport;
import android.security.intrusiondetection.IntrusionDetectionEventTransport;
import android.util.Log;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
@@ -36,6 +41,44 @@ import java.util.List;
public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEventTransport {
public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEventTransport {
    private List<IntrusionDetectionEvent> mEvents = new ArrayList<>();
    private List<IntrusionDetectionEvent> mEvents = new ArrayList<>();


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

    public LocalIntrusionDetectionEventTransport(Context context) {
        sContext = context;
    }

    // Broadcast an intent to the CTS test service to indicate that the security
    // event was received.
    private static void broadcastSecurityEventReceived() {
        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);
        }
    }

    private static void checkIfSecurityEventReceivedFromCts(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) {
            if (event.getType() == IntrusionDetectionEvent.SECURITY_EVENT) {
                SecurityEvent securityEvent = event.getSecurityEvent();
                Object[] eventData = (Object[]) securityEvent.getData();
                if (securityEvent.getTag() == SecurityLog.TAG_KEY_GENERATED
                        && eventData[1].equals(TEST_SECURITY_EVENT_TAG)) {
                    broadcastSecurityEventReceived();
                    return;
                }
            }
        }
    }

    @Override
    @Override
    public boolean initialize() {
    public boolean initialize() {
        return true;
        return true;
@@ -43,6 +86,11 @@ public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEve


    @Override
    @Override
    public boolean addData(List<IntrusionDetectionEvent> events) {
    public boolean addData(List<IntrusionDetectionEvent> events) {
        // Our CTS tests will generate a security event. In order to
        // 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);
        mEvents.addAll(events);
        mEvents.addAll(events);
        return true;
        return true;
    }
    }
+7 −6
Original line number Original line Diff line number Diff line
@@ -17,19 +17,20 @@
package com.android.coretests.apps.testapp;
package com.android.coretests.apps.testapp;


import android.app.Service;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Process;

import com.android.internal.infra.AndroidFuture;



public class TestLoggingService extends Service {
public class TestLoggingService extends Service {
    private static final String TAG = "TestLoggingService";
    private static final String TAG = "TestLoggingService";
    private LocalIntrusionDetectionEventTransport mLocalIntrusionDetectionEventTransport;
    private LocalIntrusionDetectionEventTransport mLocalIntrusionDetectionEventTransport;


    public TestLoggingService() {
    @Override
        mLocalIntrusionDetectionEventTransport = new LocalIntrusionDetectionEventTransport();
    public void onCreate() {
        super.onCreate();

        Context context = getApplicationContext();
        mLocalIntrusionDetectionEventTransport = new LocalIntrusionDetectionEventTransport(context);
    }
    }


    // Binder given to clients.
    // Binder given to clients.