From c0659f0107014651f24d7d14cc8ce301e6a0467d Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Tue, 30 Apr 2024 10:43:45 +0900 Subject: [PATCH] libvendorsupport provides an API to replace vndk version ro.vndk.version cannot be simply replaced with ro.board.api_level with the vndk deprecation. Even with the latest system updates, devices may still run on old vendor images that do not define ro.board.api_level, but define ro.vndk.version. To provide the replacement of ro.vndk.version, provide a platform API AVendorSupport_getVendorApiLevel() to return the expected vendor version. Bug: 312311458 Bug: 312315580 Test: manual test for AVendorSupport_getVendorApiLevel() Change-Id: Id7c04483956d95fd49414cebde41d7cc4d2fb1d1 --- libvendorsupport/Android.bp | 3 ++- .../include/vendorsupport/api_level.h | 18 ++++++++++++++++++ .../{version_props.c => version_props.cpp} | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) rename libvendorsupport/{version_props.c => version_props.cpp} (79%) diff --git a/libvendorsupport/Android.bp b/libvendorsupport/Android.bp index e87959ec4..a22737c06 100644 --- a/libvendorsupport/Android.bp +++ b/libvendorsupport/Android.bp @@ -23,7 +23,7 @@ cc_library { llndk: { symbol_file: "libvendorsupport.map.txt", }, - srcs: ["version_props.c"], + srcs: ["version_props.cpp"], cflags: [ "-Wall", "-Werror", @@ -32,6 +32,7 @@ cc_library { export_include_dirs: ["include"], shared_libs: [ "liblog", + "libbase", ], } diff --git a/libvendorsupport/include/vendorsupport/api_level.h b/libvendorsupport/include/vendorsupport/api_level.h index d365075e0..3427bc614 100644 --- a/libvendorsupport/include/vendorsupport/api_level.h +++ b/libvendorsupport/include/vendorsupport/api_level.h @@ -44,4 +44,22 @@ int AVendorSupport_getVendorApiLevelOf(int sdkApiLevel); */ int AVendorSupport_getSdkApiLevelOf(int vendorApiLevel); +#if !defined(__ANDROID_VENDOR__) +/** + * @brief Provide vendor API level to system modules. + * + * @details + * Before deprecating VNDK, system modules read ro.vndk.version to find the + * API level that vendor image had implemented. With the VNDK deprecation, this + * must be replaced with ro.board.api_level. However, there still are devices + * keeping old vendor partitions with the new system upgraded. In this case, the + * VNDK version can be used as before. + * This API is for platform only. + * + * @return ro.vndk.version if exist. Otherwise fallback to ro.board.api_level. + * 0 if none of these properties are found. This is unexpected, though. + */ +int AVendorSupport_getVendorApiLevel(); +#endif // __ANDROID_VENDOR__ + __END_DECLS diff --git a/libvendorsupport/version_props.c b/libvendorsupport/version_props.cpp similarity index 79% rename from libvendorsupport/version_props.c rename to libvendorsupport/version_props.cpp index 835828c0a..ecba89991 100644 --- a/libvendorsupport/version_props.c +++ b/libvendorsupport/version_props.cpp @@ -16,6 +16,10 @@ #include +#if !defined(__ANDROID_VENDOR__) +#include +#endif + int AVendorSupport_getVendorApiLevelOf(int sdkApiLevel) { if (sdkApiLevel < __ANDROID_API_V__) { return sdkApiLevel; @@ -39,3 +43,13 @@ int AVendorSupport_getSdkApiLevelOf(int vendorApiLevel) { ALOGE("Unexpected vendor api level: %d", vendorApiLevel); return __INVALID_API_LEVEL; } + +#if !defined(__ANDROID_VENDOR__) +int AVendorSupport_getVendorApiLevel() { + int vendorApiLevel = android::base::GetIntProperty("ro.vndk.version", 0); + if (vendorApiLevel) { + return vendorApiLevel; + } + return android::base::GetIntProperty("ro.board.api_level", 0); +} +#endif // __ANDROID_VENDOR__