1 /*
2 * Copyright (C) 2007-2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <android-base/macros.h>
18 #include <log/log_id.h>
19
20 #include <nativehelper/JNIHelp.h>
21 #include "jni.h"
22
23 #include "core_jni_helpers.h"
24 #include "eventlog_helper.h"
25
26 namespace android {
27
28 constexpr char kEventLogEventClass[] = "android/util/EventLog$Event";
29 template class EventLogHelper<log_id_t::LOG_ID_EVENTS, kEventLogEventClass>;
30 using ELog = EventLogHelper<log_id_t::LOG_ID_EVENTS, kEventLogEventClass>;
31
32 /*
33 * In class android.util.EventLog:
34 * static native void readEvents(int[] tags, Collection<Event> output)
35 *
36 * Reads events from the event log
37 */
android_util_EventLog_readEvents(JNIEnv * env,jobject clazz ATTRIBUTE_UNUSED,jintArray tags,jobject out)38 static void android_util_EventLog_readEvents(JNIEnv* env, jobject clazz ATTRIBUTE_UNUSED,
39 jintArray tags,
40 jobject out) {
41
42 if (tags == NULL || out == NULL) {
43 jniThrowNullPointerException(env, NULL);
44 return;
45 }
46
47 ELog::readEvents(env, ANDROID_LOG_NONBLOCK, tags, 0, out);
48 }
49 /*
50 * In class android.util.EventLog:
51 * static native void readEventsOnWrapping(int[] tags, long timestamp, Collection<Event> output)
52 *
53 * Reads events from the event log, blocking until events after timestamp are to be overwritten.
54 */
android_util_EventLog_readEventsOnWrapping(JNIEnv * env,jobject clazz ATTRIBUTE_UNUSED,jintArray tags,jlong timestamp,jobject out)55 static void android_util_EventLog_readEventsOnWrapping(JNIEnv* env, jobject clazz ATTRIBUTE_UNUSED,
56 jintArray tags,
57 jlong timestamp,
58 jobject out) {
59 if (tags == NULL || out == NULL) {
60 jniThrowNullPointerException(env, NULL);
61 return;
62 }
63 ELog::readEvents(env, ANDROID_LOG_NONBLOCK | ANDROID_LOG_WRAP, tags, timestamp, out);
64 }
65
66 /*
67 * JNI registration.
68 */
69 static const JNINativeMethod gRegisterMethods[] = {
70 /* name, signature, funcPtr */
71 { "writeEvent", "(II)I", (void*) ELog::writeEventInteger },
72 { "writeEvent", "(IJ)I", (void*) ELog::writeEventLong },
73 { "writeEvent", "(IF)I", (void*) ELog::writeEventFloat },
74 { "writeEvent", "(ILjava/lang/String;)I", (void*) ELog::writeEventString },
75 { "writeEvent", "(I[Ljava/lang/Object;)I", (void*) ELog::writeEventArray },
76 { "readEvents",
77 "([ILjava/util/Collection;)V",
78 (void*) android_util_EventLog_readEvents
79 },
80 { "readEventsOnWrapping",
81 "([IJLjava/util/Collection;)V",
82 (void*) android_util_EventLog_readEventsOnWrapping
83 },
84 };
85
register_android_util_EventLog(JNIEnv * env)86 int register_android_util_EventLog(JNIEnv* env) {
87 ELog::Init(env);
88
89 return RegisterMethodsOrDie(
90 env,
91 "android/util/EventLog",
92 gRegisterMethods, NELEM(gRegisterMethods));
93 }
94
95 }; // namespace android
96