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

Commit 2d0e124d authored by Mark Teffeteller's avatar Mark Teffeteller Committed by Android (Google) Code Review
Browse files

Merge "Add a subclass of IntrusionDetectionEventTransport that overrides the...

Merge "Add a subclass of IntrusionDetectionEventTransport that overrides the methods for a real datasource." into main
parents 60dfe7ed a4fa0cc0
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ import android.os.test.TestLooper;
import android.security.intrusiondetection.IIntrusionDetectionServiceCommandCallback;
import android.security.intrusiondetection.IIntrusionDetectionServiceStateCallback;
import android.security.intrusiondetection.IntrusionDetectionEvent;
import android.security.intrusiondetection.IntrusionDetectionEventTransport;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import android.util.Log;
@@ -71,6 +70,7 @@ import com.android.bedstead.nene.exceptions.NeneException;
import com.android.bedstead.permissions.CommonPermissions;
import com.android.bedstead.permissions.PermissionContext;
import com.android.bedstead.permissions.annotations.EnsureHasPermission;
import com.android.coretests.apps.testapp.LocalIntrusionDetectionEventTransport;
import com.android.internal.infra.AndroidFuture;
import com.android.server.ServiceThread;

@@ -601,7 +601,8 @@ public class IntrusionDetectionServiceTest {
    private ServiceConnection startTestService() throws SecurityException, InterruptedException {
        final String TAG = "startTestService";
        final CountDownLatch latch = new CountDownLatch(1);
        IntrusionDetectionEventTransport transport = new IntrusionDetectionEventTransport();
        LocalIntrusionDetectionEventTransport transport =
                new LocalIntrusionDetectionEventTransport();

        ServiceConnection serviceConnection = new ServiceConnection() {
            // Called when connection with the service is established.
@@ -625,6 +626,16 @@ public class IntrusionDetectionServiceTest {
        mContext.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
        latch.await(5, TimeUnit.SECONDS);

        // call the methods on the transport object
        IntrusionDetectionEvent event =
                new IntrusionDetectionEvent(new SecurityEvent(123, new byte[15]));
        List<IntrusionDetectionEvent> events = new ArrayList<>();
        events.add(event);
        assertTrue(transport.initialize());
        assertTrue(transport.addData(events));
        assertTrue(transport.release());
        assertEquals(1, transport.getEvents().size());

        return serviceConnection;
    }

+0 −10
Original line number Diff line number Diff line
@@ -26,19 +26,9 @@ android_test_helper_app {
    name: "TestIntrusionDetectionApp",

    static_libs: [
        "androidx.test.core",
        "androidx.test.rules",
        "androidx.test.runner",
        "compatibility-device-util-axt",
        "frameworks-base-testutils",
        "junit",
        "platform-test-annotations",
        "services.core",
        "servicestests-utils",
        "coretests-aidl",
        "truth",
        "Nene",
        "Harrier",
    ],

    srcs: ["**/*.java"],
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance
 with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.

 */

package com.android.coretests.apps.testapp;

import android.security.intrusiondetection.IntrusionDetectionEvent;
import android.security.intrusiondetection.IntrusionDetectionEventTransport;

import java.util.ArrayList;
import java.util.List;

/**
 * A class that extends {@link IntrusionDetectionEventTransport} to provide a
 * local transport mechanism for testing purposes. This implementation overrides
 * the {@link #initialize()}, {@link #addData(List)}, and {@link #release()} methods
 * to manage events locally within the test environment.
 *
 * For now, the implementation returns true for all methods since we don't
 * have a real data source to send events to.
 */
public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEventTransport {
    private List<IntrusionDetectionEvent> mEvents = new ArrayList<>();

    @Override
    public boolean initialize() {
        return true;
    }

    @Override
    public boolean addData(List<IntrusionDetectionEvent> events) {
        mEvents.addAll(events);
        return true;
    }

    @Override
    public boolean release() {
        return true;
    }

    public List<IntrusionDetectionEvent> getEvents() {
        return mEvents;
    }
}
 No newline at end of file
+3 −5
Original line number Diff line number Diff line
@@ -21,22 +21,20 @@ import android.content.Intent;
import android.os.IBinder;
import android.os.Process;

import android.security.intrusiondetection.IntrusionDetectionEventTransport;

import com.android.internal.infra.AndroidFuture;


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

    public TestLoggingService() {
        mIntrusionDetectionEventTransport = new IntrusionDetectionEventTransport();
        mLocalIntrusionDetectionEventTransport = new LocalIntrusionDetectionEventTransport();
    }

    // Binder given to clients.
    @Override
    public IBinder onBind(Intent intent) {
        return mIntrusionDetectionEventTransport.getBinder();
        return mLocalIntrusionDetectionEventTransport.getBinder();
    }
}