Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4bb83df1 authored by Yifan Hong's avatar Yifan Hong
Browse files

VintfRuntimeInfo: do not fetch files that are not needed

... to avoid unnecessary denials.

Test: CtsDeviceInfo
Bug: 66960848
Change-Id: I28821c44285a7de424a79b8a374feac6718605b1
parent f8c7572b
Loading
Loading
Loading
Loading
+17 −12
Original line number Original line Diff line number Diff line
@@ -29,28 +29,33 @@ namespace android {
using vintf::RuntimeInfo;
using vintf::RuntimeInfo;
using vintf::VintfObject;
using vintf::VintfObject;


#define MAP_STRING_METHOD(javaMethod, cppString)                                       \
#define MAP_STRING_METHOD(javaMethod, cppString, flags)                                \
    static jstring android_os_VintfRuntimeInfo_##javaMethod(JNIEnv* env, jclass clazz) \
    static jstring android_os_VintfRuntimeInfo_##javaMethod(JNIEnv* env, jclass clazz) \
    {                                                                                  \
    {                                                                                  \
        std::shared_ptr<const RuntimeInfo> info = VintfObject::GetRuntimeInfo();       \
        std::shared_ptr<const RuntimeInfo> info = VintfObject::GetRuntimeInfo(         \
                false /* skipCache */, flags);                                         \
        if (info == nullptr) return nullptr;                                           \
        if (info == nullptr) return nullptr;                                           \
        return env->NewStringUTF((cppString).c_str());                                 \
        return env->NewStringUTF((cppString).c_str());                                 \
    }                                                                                  \
    }                                                                                  \


MAP_STRING_METHOD(getCpuInfo, info->cpuInfo());
MAP_STRING_METHOD(getCpuInfo, info->cpuInfo(), RuntimeInfo::FetchFlag::CPU_INFO);
MAP_STRING_METHOD(getOsName, info->osName());
MAP_STRING_METHOD(getOsName, info->osName(), RuntimeInfo::FetchFlag::CPU_VERSION);
MAP_STRING_METHOD(getNodeName, info->nodeName());
MAP_STRING_METHOD(getNodeName, info->nodeName(), RuntimeInfo::FetchFlag::CPU_VERSION);
MAP_STRING_METHOD(getOsRelease, info->osRelease());
MAP_STRING_METHOD(getOsRelease, info->osRelease(), RuntimeInfo::FetchFlag::CPU_VERSION);
MAP_STRING_METHOD(getOsVersion, info->osVersion());
MAP_STRING_METHOD(getOsVersion, info->osVersion(), RuntimeInfo::FetchFlag::CPU_VERSION);
MAP_STRING_METHOD(getHardwareId, info->hardwareId());
MAP_STRING_METHOD(getHardwareId, info->hardwareId(), RuntimeInfo::FetchFlag::CPU_VERSION);
MAP_STRING_METHOD(getKernelVersion, vintf::to_string(info->kernelVersion()));
MAP_STRING_METHOD(getKernelVersion, vintf::to_string(info->kernelVersion()),
MAP_STRING_METHOD(getBootAvbVersion, vintf::to_string(info->bootAvbVersion()));
                  RuntimeInfo::FetchFlag::CPU_VERSION);
MAP_STRING_METHOD(getBootVbmetaAvbVersion, vintf::to_string(info->bootVbmetaAvbVersion()));
MAP_STRING_METHOD(getBootAvbVersion, vintf::to_string(info->bootAvbVersion()),
                  RuntimeInfo::FetchFlag::AVB);
MAP_STRING_METHOD(getBootVbmetaAvbVersion, vintf::to_string(info->bootVbmetaAvbVersion()),
                  RuntimeInfo::FetchFlag::AVB);




static jlong android_os_VintfRuntimeInfo_getKernelSepolicyVersion(JNIEnv *env, jclass clazz)
static jlong android_os_VintfRuntimeInfo_getKernelSepolicyVersion(JNIEnv *env, jclass clazz)
{
{
    std::shared_ptr<const RuntimeInfo> info = VintfObject::GetRuntimeInfo();
    std::shared_ptr<const RuntimeInfo> info = VintfObject::GetRuntimeInfo(
        false /* skipCache */, RuntimeInfo::FetchFlag::POLICYVERS);
    if (info == nullptr) return 0;
    if (info == nullptr) return 0;
    return static_cast<jlong>(info->kernelSepolicyVersion());
    return static_cast<jlong>(info->kernelSepolicyVersion());
}
}