blob: 9379ea6dcd1073ff10192d94d4436d5018a78aa4 [file] [log] [blame]
Yifan Hong1bda6732017-04-26 11:38:01 -07001/*
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
Steven Moreland2279b252017-07-19 09:50:45 -070020#include <nativehelper/JNIHelp.h>
Yifan Hong1bda6732017-04-26 11:38:01 -070021#include <vintf/VintfObject.h>
22#include <vintf/parse_string.h>
23#include <vintf/parse_xml.h>
24
25#include "core_jni_helpers.h"
26
27namespace android {
28
29using vintf::RuntimeInfo;
30using vintf::VintfObject;
31
Yifan Hong4bb83df2017-09-26 15:07:34 -070032#define MAP_STRING_METHOD(javaMethod, cppString, flags) \
Yifan Hong1bda6732017-04-26 11:38:01 -070033 static jstring android_os_VintfRuntimeInfo_##javaMethod(JNIEnv* env, jclass clazz) \
34 { \
Yifan Hong4bb83df2017-09-26 15:07:34 -070035 std::shared_ptr<const RuntimeInfo> info = VintfObject::GetRuntimeInfo( \
36 false /* skipCache */, flags); \
Yifan Hong1bda6732017-04-26 11:38:01 -070037 if (info == nullptr) return nullptr; \
38 return env->NewStringUTF((cppString).c_str()); \
39 } \
40
Yifan Hong4bb83df2017-09-26 15:07:34 -070041MAP_STRING_METHOD(getCpuInfo, info->cpuInfo(), RuntimeInfo::FetchFlag::CPU_INFO);
42MAP_STRING_METHOD(getOsName, info->osName(), RuntimeInfo::FetchFlag::CPU_VERSION);
43MAP_STRING_METHOD(getNodeName, info->nodeName(), RuntimeInfo::FetchFlag::CPU_VERSION);
44MAP_STRING_METHOD(getOsRelease, info->osRelease(), RuntimeInfo::FetchFlag::CPU_VERSION);
45MAP_STRING_METHOD(getOsVersion, info->osVersion(), RuntimeInfo::FetchFlag::CPU_VERSION);
46MAP_STRING_METHOD(getHardwareId, info->hardwareId(), RuntimeInfo::FetchFlag::CPU_VERSION);
47MAP_STRING_METHOD(getKernelVersion, vintf::to_string(info->kernelVersion()),
48 RuntimeInfo::FetchFlag::CPU_VERSION);
49MAP_STRING_METHOD(getBootAvbVersion, vintf::to_string(info->bootAvbVersion()),
50 RuntimeInfo::FetchFlag::AVB);
51MAP_STRING_METHOD(getBootVbmetaAvbVersion, vintf::to_string(info->bootVbmetaAvbVersion()),
52 RuntimeInfo::FetchFlag::AVB);
Yifan Hong1bda6732017-04-26 11:38:01 -070053
54
55static jlong android_os_VintfRuntimeInfo_getKernelSepolicyVersion(JNIEnv *env, jclass clazz)
56{
Yifan Hong4bb83df2017-09-26 15:07:34 -070057 std::shared_ptr<const RuntimeInfo> info = VintfObject::GetRuntimeInfo(
58 false /* skipCache */, RuntimeInfo::FetchFlag::POLICYVERS);
Yifan Hong1bda6732017-04-26 11:38:01 -070059 if (info == nullptr) return 0;
60 return static_cast<jlong>(info->kernelSepolicyVersion());
61}
62
63// ----------------------------------------------------------------------------
64
65static const JNINativeMethod gVintfRuntimeInfoMethods[] = {
66 {"getKernelSepolicyVersion", "()J", (void*)android_os_VintfRuntimeInfo_getKernelSepolicyVersion},
67 {"getCpuInfo", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getCpuInfo},
68 {"getOsName", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getOsName},
69 {"getNodeName", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getNodeName},
70 {"getOsRelease", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getOsRelease},
71 {"getOsVersion", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getOsVersion},
72 {"getHardwareId", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getHardwareId},
73 {"getKernelVersion", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getKernelVersion},
74 {"getBootAvbVersion", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getBootAvbVersion},
75 {"getBootVbmetaAvbVersion", "()Ljava/lang/String;", (void*)android_os_VintfRuntimeInfo_getBootVbmetaAvbVersion},
76};
77
78const char* const kVintfRuntimeInfoPathName = "android/os/VintfRuntimeInfo";
79
80int register_android_os_VintfRuntimeInfo(JNIEnv* env)
81{
82 return RegisterMethodsOrDie(env, kVintfRuntimeInfoPathName, gVintfRuntimeInfoMethods, NELEM(gVintfRuntimeInfoMethods));
83}
84
85};