diff options
2 files changed, 56 insertions, 7 deletions
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 index f0012da44fa4..b0b781575cb3 100644 --- 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 @@ -18,8 +18,13 @@ 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.IntrusionDetectionEventTransport; +import android.util.Log; import java.util.ArrayList; import java.util.List; @@ -36,6 +41,44 @@ import java.util.List; public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEventTransport { 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 public boolean initialize() { return true; @@ -43,6 +86,11 @@ public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEve @Override 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); return true; } @@ -55,4 +103,4 @@ public class LocalIntrusionDetectionEventTransport extends IntrusionDetectionEve 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 e4bf987402fd..9183a75580ff 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 @@ -17,19 +17,20 @@ package com.android.coretests.apps.testapp; import android.app.Service; +import android.content.Context; import android.content.Intent; import android.os.IBinder; -import android.os.Process; - -import com.android.internal.infra.AndroidFuture; - public class TestLoggingService extends Service { private static final String TAG = "TestLoggingService"; private LocalIntrusionDetectionEventTransport mLocalIntrusionDetectionEventTransport; - public TestLoggingService() { - mLocalIntrusionDetectionEventTransport = new LocalIntrusionDetectionEventTransport(); + @Override + public void onCreate() { + super.onCreate(); + + Context context = getApplicationContext(); + mLocalIntrusionDetectionEventTransport = new LocalIntrusionDetectionEventTransport(context); } // Binder given to clients. |