Merge "Add a subclass of IntrusionDetectionEventTransport that overrides the methods for a real datasource." into main
diff --git a/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/IntrusionDetectionServiceTest.java b/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/IntrusionDetectionServiceTest.java
index da5e9f6..e505ebe 100644
--- a/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/IntrusionDetectionServiceTest.java
+++ b/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/IntrusionDetectionServiceTest.java
@@ -54,7 +54,6 @@
 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.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 @@
     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 @@
         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;
     }
 
diff --git a/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/Android.bp b/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/Android.bp
index 57d0de4..ca5952b 100644
--- a/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/Android.bp
+++ b/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/Android.bp
@@ -26,19 +26,9 @@
     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"],
diff --git a/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/LocalIntrusionDetectionEventTransport.java b/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/LocalIntrusionDetectionEventTransport.java
new file mode 100644
index 0000000..f0012da
--- /dev/null
+++ b/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/LocalIntrusionDetectionEventTransport.java
@@ -0,0 +1,58 @@
+/*
+ * 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
diff --git a/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/TestLoggingService.java b/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/TestLoggingService.java
index 9e38b1c..e4bf987 100644
--- a/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/TestLoggingService.java
+++ b/services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/TestLoggingService.java
@@ -21,22 +21,20 @@
 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();
     }
 }