Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Andreas Gampe | c1211c4 | 2017-10-09 12:01:25 -0700 | [diff] [blame] | 17 | #include <log/log_id.h> |
| 18 | #include <private/android_logger.h> |
| 19 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 20 | #include <nativehelper/JNIHelp.h> |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 21 | #include "jni.h" |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [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" |
| 25 | |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 26 | namespace android { |
| 27 | |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 28 | constexpr char kSecurityLogEventClass[] = "android/app/admin/SecurityLog$SecurityEvent"; |
| 29 | template class EventLogHelper<log_id_t::LOG_ID_SECURITY, kSecurityLogEventClass>; |
| 30 | using SLog = EventLogHelper<log_id_t::LOG_ID_SECURITY, kSecurityLogEventClass>; |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 31 | |
| 32 | static jboolean android_app_admin_SecurityLog_isLoggingEnabled(JNIEnv* env, |
| 33 | jobject /* clazz */) { |
| 34 | return (bool)__android_log_security(); |
| 35 | } |
| 36 | |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 37 | static void android_app_admin_SecurityLog_readEvents(JNIEnv* env, jobject /* clazz */, |
| 38 | jobject out) { |
| 39 | |
| 40 | if (out == NULL) { |
| 41 | jniThrowNullPointerException(env, NULL); |
| 42 | return; |
| 43 | } |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 44 | SLog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 0, out); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static void android_app_admin_SecurityLog_readEventsSince(JNIEnv* env, jobject /* clazz */, |
| 48 | jlong timestamp, |
| 49 | jobject out) { |
| 50 | |
| 51 | if (out == NULL) { |
| 52 | jniThrowNullPointerException(env, NULL); |
| 53 | return; |
| 54 | } |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 55 | SLog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, timestamp, out); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static void android_app_admin_SecurityLog_readPreviousEvents(JNIEnv* env, jobject /* clazz */, |
| 59 | jobject out) { |
| 60 | |
| 61 | if (out == NULL) { |
| 62 | jniThrowNullPointerException(env, NULL); |
| 63 | return; |
| 64 | } |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 65 | SLog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK | ANDROID_LOG_PSTORE, 0, out); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static void android_app_admin_SecurityLog_readEventsOnWrapping(JNIEnv* env, jobject /* clazz */, |
| 69 | jlong timestamp, |
| 70 | jobject out) { |
| 71 | if (out == NULL) { |
| 72 | jniThrowNullPointerException(env, NULL); |
| 73 | return; |
| 74 | } |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 75 | SLog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK | ANDROID_LOG_WRAP, timestamp, |
| 76 | out); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* |
| 80 | * JNI registration. |
| 81 | */ |
| 82 | static const JNINativeMethod gRegisterMethods[] = { |
| 83 | /* name, signature, funcPtr */ |
| 84 | { "isLoggingEnabled", |
| 85 | "()Z", |
| 86 | (void*) android_app_admin_SecurityLog_isLoggingEnabled |
| 87 | }, |
| 88 | { "writeEvent", |
| 89 | "(ILjava/lang/String;)I", |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 90 | (void*) SLog::writeEventString |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 91 | }, |
| 92 | { "writeEvent", |
| 93 | "(I[Ljava/lang/Object;)I", |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 94 | (void*) SLog::writeEventArray |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 95 | }, |
| 96 | { "readEvents", |
| 97 | "(Ljava/util/Collection;)V", |
| 98 | (void*) android_app_admin_SecurityLog_readEvents |
| 99 | }, |
| 100 | { "readEventsSince", |
| 101 | "(JLjava/util/Collection;)V", |
| 102 | (void*) android_app_admin_SecurityLog_readEventsSince |
| 103 | }, |
| 104 | { "readPreviousEvents", |
| 105 | "(Ljava/util/Collection;)V", |
| 106 | (void*) android_app_admin_SecurityLog_readPreviousEvents |
| 107 | }, |
| 108 | { "readEventsOnWrapping", |
| 109 | "(JLjava/util/Collection;)V", |
| 110 | (void*) android_app_admin_SecurityLog_readEventsOnWrapping |
| 111 | }, |
| 112 | }; |
| 113 | |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 114 | int register_android_app_admin_SecurityLog(JNIEnv* env) { |
Andreas Gampe | 2e220ef | 2017-10-09 16:21:11 -0700 | [diff] [blame] | 115 | SLog::Init(env); |
Michal Karpinski | 6235a94 | 2016-03-15 12:07:23 +0000 | [diff] [blame] | 116 | |
| 117 | return RegisterMethodsOrDie( |
| 118 | env, |
| 119 | "android/app/admin/SecurityLog", |
| 120 | gRegisterMethods, NELEM(gRegisterMethods)); |
| 121 | } |
| 122 | |
| 123 | }; // namespace android |