Loading services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/LocalIntrusionDetectionEventTransport.java +49 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; } Loading services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/TestLoggingService.java +7 −6 Original line number Diff line number Diff line Loading @@ -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. Loading Loading
services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/LocalIntrusionDetectionEventTransport.java +49 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; } Loading
services/tests/security/intrusiondetection/src/com/android/server/security/intrusiondetection/TestApp/src/com/android/coretests/apps/testapp/TestLoggingService.java +7 −6 Original line number Diff line number Diff line Loading @@ -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. Loading