add a signaled reader to the eventlog

Test: manual using a logspammer app
Change-Id: I89e3dda82d4d1d3fc6d343b634642687e550f70a
This commit is contained in:
Chris Wren
2016-12-02 17:43:23 -05:00
parent 8652d71982
commit d09bf8271e
4 changed files with 68 additions and 17 deletions

View File

@@ -44639,6 +44639,7 @@ package android.util {
method public static int getTagCode(java.lang.String);
method public static java.lang.String getTagName(int);
method public static void readEvents(int[], java.util.Collection<android.util.EventLog.Event>) throws java.io.IOException;
method public static void readEventsOnWrapping(int[], long, java.util.Collection<android.util.EventLog.Event>) throws java.io.IOException;
method public static int writeEvent(int, int);
method public static int writeEvent(int, long);
method public static int writeEvent(int, float);

View File

@@ -16,6 +16,8 @@
package android.util;
import android.annotation.SystemApi;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
@@ -252,6 +254,19 @@ public class EventLog {
public static native void readEvents(int[] tags, Collection<Event> output)
throws IOException;
/**
* Read events from the log, filtered by type, blocking until logs are about to be overwritten.
* @param tags to search for
* @param timestamp timestamp allow logs before this time to be overwritten.
* @param output container to add events into
* @throws IOException if something goes wrong reading events
* @hide
*/
@SystemApi
public static native void readEventsOnWrapping(int[] tags, long timestamp,
Collection<Event> output)
throws IOException;
/**
* Get the name associated with an event type tag code.
* @param tag code to look up

View File

@@ -178,7 +178,7 @@ public class EventLogCollector {
public void readEvents(int[] tags, Collection<Event> events) throws IOException {
// Testing in Android: the Static Final Class Strikes Back!
ArrayList<EventLog.Event> nativeEvents = new ArrayList<>();
EventLog.readEvents(tags, nativeEvents);
EventLog.readEventsOnWrapping(tags, 0L, nativeEvents);
for (EventLog.Event nativeEvent : nativeEvents) {
Event event = new Event(nativeEvent);
events.add(event);

View File

@@ -144,26 +144,22 @@ static jint android_util_EventLog_writeEvent_Array(JNIEnv* env, jobject clazz,
return ctx.write();
}
/*
* In class android.util.EventLog:
* static native void readEvents(int[] tags, Collection<Event> output)
*
* Reads events from the event log
*/
static void android_util_EventLog_readEvents(JNIEnv* env, jobject clazz UNUSED,
jintArray tags,
jobject out) {
if (tags == NULL || out == NULL) {
jniThrowNullPointerException(env, NULL);
static void readEvents(JNIEnv* env, int loggerMode, jintArray tags, jlong startTime, jobject out) {
struct logger_list *logger_list;
if (startTime) {
logger_list = android_logger_list_alloc_time(loggerMode,
log_time(startTime / NS_PER_SEC, startTime % NS_PER_SEC), 0);
} else {
logger_list = android_logger_list_alloc(loggerMode, 0, 0);
}
if (!logger_list) {
jniThrowIOException(env, errno);
return;
}
struct logger_list *logger_list = android_logger_list_open(
LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 0, 0);
if (!logger_list) {
if (!android_logger_open(logger_list, LOG_ID_EVENTS)) {
jniThrowIOException(env, errno);
android_logger_list_free(logger_list);
return;
}
@@ -227,6 +223,41 @@ static void android_util_EventLog_readEvents(JNIEnv* env, jobject clazz UNUSED,
env->ReleaseIntArrayElements(tags, tagValues, 0);
}
/*
* In class android.util.EventLog:
* static native void readEvents(int[] tags, Collection<Event> output)
*
* Reads events from the event log
*/
static void android_util_EventLog_readEvents(JNIEnv* env, jobject clazz UNUSED,
jintArray tags,
jobject out) {
if (tags == NULL || out == NULL) {
jniThrowNullPointerException(env, NULL);
return;
}
readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, tags, 0, out);
}
/*
* In class android.util.EventLog:
* static native void readEventsOnWrapping(int[] tags, long timestamp, Collection<Event> output)
*
* Reads events from the event log, blocking until events after timestamp are to be overwritten.
*/
static void android_util_EventLog_readEventsOnWrapping(JNIEnv* env, jobject clazz UNUSED,
jintArray tags,
jlong timestamp,
jobject out) {
if (tags == NULL || out == NULL) {
jniThrowNullPointerException(env, NULL);
return;
}
readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK | ANDROID_LOG_WRAP,
tags, timestamp, out);
}
/*
* JNI registration.
*/
@@ -247,6 +278,10 @@ static const JNINativeMethod gRegisterMethods[] = {
"([ILjava/util/Collection;)V",
(void*) android_util_EventLog_readEvents
},
{ "readEventsOnWrapping",
"([IJLjava/util/Collection;)V",
(void*) android_util_EventLog_readEventsOnWrapping
},
};
static struct { const char *name; jclass *clazz; } gClasses[] = {