blob: 3b5a144a4e61cbcb121abfc36e26bf25b8341d1f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
Mark Salyzyn7933c292013-12-05 10:06:18 -08002 * Copyright (C) 2007-2014 The Android Open Source Project
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003 *
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
Andreas Gampe2e220ef2017-10-09 16:21:11 -070017#include <android-base/macros.h>
18#include <log/log_id.h>
Mark Salyzyn96bf5982016-09-28 16:15:30 -070019
Steven Moreland2279b252017-07-19 09:50:45 -070020#include <nativehelper/JNIHelp.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021#include "jni.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022
Andreas Gampe2e220ef2017-10-09 16:21:11 -070023#include "core_jni_helpers.h"
24#include "eventlog_helper.h"
Mark Salyzyn3ed8e2e62013-11-07 11:16:22 -080025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026namespace android {
27
Andreas Gampe2e220ef2017-10-09 16:21:11 -070028constexpr char kEventLogEventClass[] = "android/util/EventLog$Event";
29template class EventLogHelper<log_id_t::LOG_ID_EVENTS, kEventLogEventClass>;
30using ELog = EventLogHelper<log_id_t::LOG_ID_EVENTS, kEventLogEventClass>;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
Jim Miller95ff2402009-07-01 18:03:41 -070032/*
Chris Wrend09bf822016-12-02 17:43:23 -050033 * In class android.util.EventLog:
34 * static native void readEvents(int[] tags, Collection<Event> output)
35 *
36 * Reads events from the event log
37 */
Andreas Gampe2e220ef2017-10-09 16:21:11 -070038static void android_util_EventLog_readEvents(JNIEnv* env, jobject clazz ATTRIBUTE_UNUSED,
Chris Wrend09bf822016-12-02 17:43:23 -050039 jintArray tags,
40 jobject out) {
41
42 if (tags == NULL || out == NULL) {
43 jniThrowNullPointerException(env, NULL);
44 return;
45 }
46
Andreas Gampe2e220ef2017-10-09 16:21:11 -070047 ELog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, tags, 0, out);
Chris Wrend09bf822016-12-02 17:43:23 -050048 }
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 */
Andreas Gampe2e220ef2017-10-09 16:21:11 -070055static void android_util_EventLog_readEventsOnWrapping(JNIEnv* env, jobject clazz ATTRIBUTE_UNUSED,
Chris Wrend09bf822016-12-02 17:43:23 -050056 jintArray tags,
57 jlong timestamp,
58 jobject out) {
59 if (tags == NULL || out == NULL) {
60 jniThrowNullPointerException(env, NULL);
61 return;
62 }
Andreas Gampe2e220ef2017-10-09 16:21:11 -070063 ELog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK | ANDROID_LOG_WRAP, tags,
64 timestamp, out);
Chris Wrend09bf822016-12-02 17:43:23 -050065}
66
67/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 * JNI registration.
69 */
Daniel Micay76f6a862015-09-19 17:31:01 -040070static const JNINativeMethod gRegisterMethods[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 /* name, signature, funcPtr */
Andreas Gampe2e220ef2017-10-09 16:21:11 -070072 { "writeEvent", "(II)I", (void*) ELog::writeEventInteger },
73 { "writeEvent", "(IJ)I", (void*) ELog::writeEventLong },
74 { "writeEvent", "(IF)I", (void*) ELog::writeEventFloat },
75 { "writeEvent", "(ILjava/lang/String;)I", (void*) ELog::writeEventString },
76 { "writeEvent", "(I[Ljava/lang/Object;)I", (void*) ELog::writeEventArray },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 { "readEvents",
78 "([ILjava/util/Collection;)V",
79 (void*) android_util_EventLog_readEvents
Jim Miller95ff2402009-07-01 18:03:41 -070080 },
Chris Wrend09bf822016-12-02 17:43:23 -050081 { "readEventsOnWrapping",
82 "([IJLjava/util/Collection;)V",
83 (void*) android_util_EventLog_readEventsOnWrapping
84 },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085};
86
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087int register_android_util_EventLog(JNIEnv* env) {
Andreas Gampe2e220ef2017-10-09 16:21:11 -070088 ELog::Init(env);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089
Andreas Gampeed6b9df2014-11-20 22:02:20 -080090 return RegisterMethodsOrDie(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 env,
92 "android/util/EventLog",
93 gRegisterMethods, NELEM(gRegisterMethods));
94}
95
96}; // namespace android