1 /*
2 * Copyright (C) 2017 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_TAG "VintfRuntimeInfo"
18 //#define LOG_NDEBUG 0
19
20 #include <nativehelper/JNIHelp.h>
21 #include <vintf/VintfObject.h>
22 #include <vintf/parse_string.h>
23 #include <vintf/parse_xml.h>
24
25 #include "core_jni_helpers.h"
26
27 namespace android {
28
29 using vintf::RuntimeInfo;
30 using vintf::VintfObject;
31
32 #define MAP_STRING_METHOD(javaMethod, cppString, flags) \
33 static jstring android_os_VintfRuntimeInfo_##javaMethod(JNIEnv* env, jclass clazz) { \
34 std::shared_ptr<const RuntimeInfo> info = VintfObject::GetRuntimeInfo(flags); \
35 if (info == nullptr) return nullptr; \
36 return env->NewStringUTF((cppString).c_str()); \
37 }
38
39 MAP_STRING_METHOD(getCpuInfo, info->cpuInfo(), RuntimeInfo::FetchFlag::CPU_INFO);
40 MAP_STRING_METHOD(getOsName, info->osName(), RuntimeInfo::FetchFlag::CPU_VERSION);
41 MAP_STRING_METHOD(getNodeName, info->nodeName(), RuntimeInfo::FetchFlag::CPU_VERSION);
42 MAP_STRING_METHOD(getOsRelease, info->osRelease(), RuntimeInfo::FetchFlag::CPU_VERSION);
43 MAP_STRING_METHOD(getOsVersion, info->osVersion(), RuntimeInfo::FetchFlag::CPU_VERSION);
44 MAP_STRING_METHOD(getHardwareId, info->hardwareId(), RuntimeInfo::FetchFlag::CPU_VERSION);
45 MAP_STRING_METHOD(getKernelVersion, vintf::to_string(info->kernelVersion()),
46 RuntimeInfo::FetchFlag::CPU_VERSION);
47 MAP_STRING_METHOD(getBootAvbVersion, vintf::to_string(info->bootAvbVersion()),
48 RuntimeInfo::FetchFlag::AVB);
49 MAP_STRING_METHOD(getBootVbmetaAvbVersion, vintf::to_string(info->bootVbmetaAvbVersion()),
50 RuntimeInfo::FetchFlag::AVB);
51
52
android_os_VintfRuntimeInfo_getKernelSepolicyVersion(JNIEnv * env,jclass clazz)53 static jlong android_os_VintfRuntimeInfo_getKernelSepolicyVersion(JNIEnv *env, jclass clazz)
54 {
55 std::shared_ptr<const RuntimeInfo> info =
56 VintfObject::GetRuntimeInfo(RuntimeInfo::FetchFlag::POLICYVERS);
57 if (info == nullptr) return 0;
58 return static_cast<jlong>(info->kernelSepolicyVersion());
59 }
60
61 // ----------------------------------------------------------------------------
62
63 static const JNINativeMethod gVintfRuntimeInfoMethods[] = {
64 {"getKernelSepolicyVersion", "()J", (void*)android_os_VintfRuntimeInfo_getKernelSepolicyVersion},
65 {"getCpuInfo", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getCpuInfo},
66 {"getOsName", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getOsName},
67 {"getNodeName", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getNodeName},
68 {"getOsRelease", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getOsRelease},
69 {"getOsVersion", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getOsVersion},
70 {"getHardwareId", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getHardwareId},
71 {"getKernelVersion", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getKernelVersion},
72 {"getBootAvbVersion", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getBootAvbVersion},
73 {"getBootVbmetaAvbVersion", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getBootVbmetaAvbVersion},
74 };
75
76 const char* const kVintfRuntimeInfoPathName = "android/os/VintfRuntimeInfo";
77
register_android_os_VintfRuntimeInfo(JNIEnv * env)78 int register_android_os_VintfRuntimeInfo(JNIEnv* env)
79 {
80 return RegisterMethodsOrDie(env, kVintfRuntimeInfoPathName, gVintfRuntimeInfoMethods, NELEM(gVintfRuntimeInfoMethods));
81 }
82
83 };
84