blob: b3bcaa0f7f03db3438d1047b5bcb5a3a1d710df3 [file] [log] [blame]
Michal Karpinski6235a942016-03-15 12:07:23 +00001/*
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 Gampec1211c42017-10-09 12:01:25 -070017#include <log/log_id.h>
18#include <private/android_logger.h>
19
Steven Moreland2279b252017-07-19 09:50:45 -070020#include <nativehelper/JNIHelp.h>
Michal Karpinski6235a942016-03-15 12:07:23 +000021#include "jni.h"
Michal Karpinski6235a942016-03-15 12:07:23 +000022
Andreas Gampe2e220ef2017-10-09 16:21:11 -070023#include "core_jni_helpers.h"
24#include "eventlog_helper.h"
25
Michal Karpinski6235a942016-03-15 12:07:23 +000026namespace android {
27
Andreas Gampe2e220ef2017-10-09 16:21:11 -070028constexpr char kSecurityLogEventClass[] = "android/app/admin/SecurityLog$SecurityEvent";
29template class EventLogHelper<log_id_t::LOG_ID_SECURITY, kSecurityLogEventClass>;
30using SLog = EventLogHelper<log_id_t::LOG_ID_SECURITY, kSecurityLogEventClass>;
Michal Karpinski6235a942016-03-15 12:07:23 +000031
32static jboolean android_app_admin_SecurityLog_isLoggingEnabled(JNIEnv* env,
33 jobject /* clazz */) {
34 return (bool)__android_log_security();
35}
36
Michal Karpinski6235a942016-03-15 12:07:23 +000037static 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 Gampe2e220ef2017-10-09 16:21:11 -070044 SLog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 0, out);
Michal Karpinski6235a942016-03-15 12:07:23 +000045}
46
47static 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 Gampe2e220ef2017-10-09 16:21:11 -070055 SLog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, timestamp, out);
Michal Karpinski6235a942016-03-15 12:07:23 +000056}
57
58static 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 Gampe2e220ef2017-10-09 16:21:11 -070065 SLog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK | ANDROID_LOG_PSTORE, 0, out);
Michal Karpinski6235a942016-03-15 12:07:23 +000066}
67
68static 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 Gampe2e220ef2017-10-09 16:21:11 -070075 SLog::readEvents(env, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK | ANDROID_LOG_WRAP, timestamp,
76 out);
Michal Karpinski6235a942016-03-15 12:07:23 +000077}
78
79/*
80 * JNI registration.
81 */
82static 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 Gampe2e220ef2017-10-09 16:21:11 -070090 (void*) SLog::writeEventString
Michal Karpinski6235a942016-03-15 12:07:23 +000091 },
92 { "writeEvent",
93 "(I[Ljava/lang/Object;)I",
Andreas Gampe2e220ef2017-10-09 16:21:11 -070094 (void*) SLog::writeEventArray
Michal Karpinski6235a942016-03-15 12:07:23 +000095 },
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 Karpinski6235a942016-03-15 12:07:23 +0000114int register_android_app_admin_SecurityLog(JNIEnv* env) {
Andreas Gampe2e220ef2017-10-09 16:21:11 -0700115 SLog::Init(env);
Michal Karpinski6235a942016-03-15 12:07:23 +0000116
117 return RegisterMethodsOrDie(
118 env,
119 "android/app/admin/SecurityLog",
120 gRegisterMethods, NELEM(gRegisterMethods));
121}
122
123}; // namespace android