Add float support to binary event log.
Bug: 20664753
Change-Id: I90456400b878f943e39cbddec45649662176e2aa
diff --git a/api/current.txt b/api/current.txt
index 035b372..9434419 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -33998,6 +33998,7 @@
method public static void readEvents(int[], 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);
method public static int writeEvent(int, java.lang.String);
method public static int writeEvent(int, java.lang.Object...);
}
diff --git a/api/system-current.txt b/api/system-current.txt
index e49ef9d..6ac12aa 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -36202,6 +36202,7 @@
method public static void readEvents(int[], 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);
method public static int writeEvent(int, java.lang.String);
method public static int writeEvent(int, java.lang.Object...);
}
diff --git a/core/java/android/util/EventLog.java b/core/java/android/util/EventLog.java
index aefced8..558b8f5 100644
--- a/core/java/android/util/EventLog.java
+++ b/core/java/android/util/EventLog.java
@@ -74,6 +74,7 @@
private static final byte LONG_TYPE = 1;
private static final byte STRING_TYPE = 2;
private static final byte LIST_TYPE = 3;
+ private static final byte FLOAT_TYPE = 4;
/** @param data containing event, read from the system */
/*package*/ Event(byte[] data) {
@@ -106,7 +107,7 @@
return mBuffer.getInt(offset);
}
- /** @return one of Integer, Long, String, null, or Object[] of same. */
+ /** @return one of Integer, Long, Float, String, null, or Object[] of same. */
public synchronized Object getData() {
try {
int offset = mBuffer.getShort(HEADER_SIZE_OFFSET);
@@ -130,10 +131,13 @@
byte type = mBuffer.get();
switch (type) {
case INT_TYPE:
- return (Integer) mBuffer.getInt();
+ return mBuffer.getInt();
case LONG_TYPE:
- return (Long) mBuffer.getLong();
+ return mBuffer.getLong();
+
+ case FLOAT_TYPE:
+ return mBuffer.getFloat();
case STRING_TYPE:
try {
@@ -180,6 +184,14 @@
/**
* Record an event log message.
* @param tag The event type tag code
+ * @param value A value to log
+ * @return The number of bytes written
+ */
+ public static native int writeEvent(int tag, float value);
+
+ /**
+ * Record an event log message.
+ * @param tag The event type tag code
* @param str A value to log
* @return The number of bytes written
*/
diff --git a/core/jni/android_util_EventLog.cpp b/core/jni/android_util_EventLog.cpp
index 5cb8b2e..05bc125 100644
--- a/core/jni/android_util_EventLog.cpp
+++ b/core/jni/android_util_EventLog.cpp
@@ -40,6 +40,9 @@
static jclass gLongClass;
static jfieldID gLongValueID;
+static jclass gFloatClass;
+static jfieldID gFloatValueID;
+
static jclass gStringClass;
/*
@@ -66,6 +69,17 @@
/*
* In class android.util.EventLog:
+ * static native int writeEvent(long tag, float value)
+ */
+static jint android_util_EventLog_writeEvent_Float(JNIEnv* env UNUSED,
+ jobject clazz UNUSED,
+ jint tag, jfloat value)
+{
+ return android_btWriteLog(tag, EVENT_TYPE_FLOAT, &value, sizeof(value));
+}
+
+/*
+ * In class android.util.EventLog:
* static native int writeEvent(int tag, String value)
*/
static jint android_util_EventLog_writeEvent_String(JNIEnv* env,
@@ -128,6 +142,12 @@
buf[pos++] = EVENT_TYPE_LONG;
memcpy(&buf[pos], &longVal, sizeof(longVal));
pos += sizeof(longVal);
+ } else if (env->IsInstanceOf(item, gFloatClass)) {
+ jfloat floatVal = env->GetFloatField(item, gFloatValueID);
+ if (pos + 1 + sizeof(floatVal) > max) break;
+ buf[pos++] = EVENT_TYPE_FLOAT;
+ memcpy(&buf[pos], &floatVal, sizeof(floatVal));
+ pos += sizeof(floatVal);
} else {
jniThrowException(env,
"java/lang/IllegalArgumentException",
@@ -233,6 +253,7 @@
/* name, signature, funcPtr */
{ "writeEvent", "(II)I", (void*) android_util_EventLog_writeEvent_Integer },
{ "writeEvent", "(IJ)I", (void*) android_util_EventLog_writeEvent_Long },
+ { "writeEvent", "(IF)I", (void*) android_util_EventLog_writeEvent_Float },
{ "writeEvent",
"(ILjava/lang/String;)I",
(void*) android_util_EventLog_writeEvent_String
@@ -251,6 +272,7 @@
{ "android/util/EventLog$Event", &gEventClass },
{ "java/lang/Integer", &gIntegerClass },
{ "java/lang/Long", &gLongClass },
+ { "java/lang/Float", &gFloatClass },
{ "java/lang/String", &gStringClass },
{ "java/util/Collection", &gCollectionClass },
};
@@ -258,6 +280,7 @@
static struct { jclass *c; const char *name, *ft; jfieldID *id; } gFields[] = {
{ &gIntegerClass, "value", "I", &gIntegerValueID },
{ &gLongClass, "value", "J", &gLongValueID },
+ { &gFloatClass, "value", "F", &gFloatValueID },
};
static struct { jclass *c; const char *name, *mt; jmethodID *id; } gMethods[] = {