The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
Mark Salyzyn | 7933c29 | 2013-12-05 10:06:18 -0800 | [diff] [blame] | 2 | * Copyright (C) 2007-2014 The Android Open Source Project |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 17 | #include <android-base/macros.h> |
| 18 | #include <log/log_id.h> |
Mark Salyzyn | 96bf598 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 19 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 20 | #include <nativehelper/JNIHelp.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include "jni.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 23 | #include "core_jni_helpers.h" |
| 24 | #include "eventlog_helper.h" |
Mark Salyzyn | 3ed8e2e6 | 2013-11-07 11:16:22 -0800 | [diff] [blame] | 25 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 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>; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
Jim Miller | 95ff240 | 2009-07-01 18:03:41 -0700 | [diff] [blame] | 32 | /* |
Chris Wren | d09bf82 | 2016-12-02 17:43:23 -0500 | [diff] [blame] | 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 | */ |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 38 | static void android_util_EventLog_readEvents(JNIEnv* env, jobject clazz ATTRIBUTE_UNUSED, |
Chris Wren | d09bf82 | 2016-12-02 17:43:23 -0500 | [diff] [blame] | 39 | jintArray tags, |
| 40 | jobject out) { |
| 41 | |
| 42 | if (tags == NULL || out == NULL) { |
| 43 | jniThrowNullPointerException(env, NULL); |
| 44 | return; |
| 45 | } |
| 46 | |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 47 | ELog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, tags, 0, out); |
Chris Wren | d09bf82 | 2016-12-02 17:43:23 -0500 | [diff] [blame] | 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 | */ |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 55 | static void android_util_EventLog_readEventsOnWrapping(JNIEnv* env, jobject clazz ATTRIBUTE_UNUSED, |
Chris Wren | d09bf82 | 2016-12-02 17:43:23 -0500 | [diff] [blame] | 56 | jintArray tags, |
| 57 | jlong timestamp, |
| 58 | jobject out) { |
| 59 | if (tags == NULL || out == NULL) { |
| 60 | jniThrowNullPointerException(env, NULL); |
| 61 | return; |
| 62 | } |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 63 | ELog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK | ANDROID_LOG_WRAP, tags, |
| 64 | timestamp, out); |
Chris Wren | d09bf82 | 2016-12-02 17:43:23 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | * JNI registration. |
| 69 | */ |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 70 | static const JNINativeMethod gRegisterMethods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | /* name, signature, funcPtr */ |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 72 | { "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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | { "readEvents", |
| 78 | "([ILjava/util/Collection;)V", |
| 79 | (void*) android_util_EventLog_readEvents |
Jim Miller | 95ff240 | 2009-07-01 18:03:41 -0700 | [diff] [blame] | 80 | }, |
Chris Wren | d09bf82 | 2016-12-02 17:43:23 -0500 | [diff] [blame] | 81 | { "readEventsOnWrapping", |
| 82 | "([IJLjava/util/Collection;)V", |
| 83 | (void*) android_util_EventLog_readEventsOnWrapping |
| 84 | }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | int register_android_util_EventLog(JNIEnv* env) { |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 88 | ELog::Init(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 90 | return RegisterMethodsOrDie( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | env, |
| 92 | "android/util/EventLog", |
| 93 | gRegisterMethods, NELEM(gRegisterMethods)); |
| 94 | } |
| 95 | |
| 96 | }; // namespace android |