Tej Singh | be0482b | 2019-03-19 22:01:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #define LOG_NAMESPACE "StatsLog.tag." |
| 18 | #define LOG_TAG "StatsLog_println" |
| 19 | |
| 20 | #include <assert.h> |
| 21 | #include <cutils/properties.h> |
| 22 | |
| 23 | #include "jni.h" |
| 24 | #include <nativehelper/JNIHelp.h> |
| 25 | #include "utils/misc.h" |
| 26 | #include "core_jni_helpers.h" |
| 27 | #include "stats_event_list.h" |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | static void android_util_StatsLog_writeRaw(JNIEnv* env, jobject clazz, jbyteArray buf, jint size) |
| 32 | { |
| 33 | if (buf == NULL) { |
| 34 | return; |
| 35 | } |
| 36 | jint actualSize = env->GetArrayLength(buf); |
| 37 | if (actualSize < size) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | jbyte* bufferArray = env->GetByteArrayElements(buf, NULL); |
| 42 | if (bufferArray == NULL) { |
| 43 | return; |
| 44 | } |
| 45 | const uint32_t statsEventTag = 1937006964; |
| 46 | struct iovec vec[2]; |
| 47 | vec[0].iov_base = (void*) &statsEventTag; |
| 48 | vec[0].iov_len = sizeof(statsEventTag); |
| 49 | vec[1].iov_base = (void*) bufferArray; |
| 50 | vec[1].iov_len = size; |
| 51 | write_to_statsd(vec, 2); |
| 52 | |
| 53 | env->ReleaseByteArrayElements(buf, bufferArray, 0); |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * JNI registration. |
| 58 | */ |
| 59 | static const JNINativeMethod gMethods[] = { |
| 60 | /* name, signature, funcPtr */ |
| 61 | { "writeRaw", "([BI)V", (void*) android_util_StatsLog_writeRaw }, |
| 62 | }; |
| 63 | |
| 64 | int register_android_util_StatsLog(JNIEnv* env) |
| 65 | { |
| 66 | return RegisterMethodsOrDie(env, "android/util/StatsLog", gMethods, NELEM(gMethods)); |
| 67 | } |
| 68 | |
| 69 | }; // namespace android |