Use AVendorSupport_getVendorApiLevel instead of ro.board.api_level
ro.board.api_level is currently being used to get the API version
the vendor partition was built against. However, ro.board.api_level
is not present on all devices, and the deprecated ro.vndk.version
should be used for those instead.
AVendorSupport_getVendorApiLevel was added to wrap all these
complications and return the API level that vendor partition
is built against. This patch removes the logic to manually read
system properties and replaces it with a call to
AVendorSupport_getVendorApiLevel instead.
libvendorsupport also provides a utility function to map the new
YYYYMM format of Vendor API back to SDK version, so this patch
also replaces the hardcoded logic used by cameraservice with a
call to AVendorSupport_getSdkApiLevelOf.
Flag: com.android.internal.camera.flags.use_system_api_for_vndk_version
Bug: 312315580
Bug: 332651718
Test: Manually verified that the reported API level is correct.
Test: Verified by vendors that upgrading devices report their
API level correctly.
Change-Id: Ifde2743a1f341931d0c15bad316ae1ebd4aacde2
diff --git a/camera/camera_platform.aconfig b/camera/camera_platform.aconfig
index 2620074..2722317 100644
--- a/camera/camera_platform.aconfig
+++ b/camera/camera_platform.aconfig
@@ -227,3 +227,13 @@
purpose: PURPOSE_BUGFIX
}
}
+
+flag {
+ namespace: "camera_platform"
+ name: "use_system_api_for_vndk_version"
+ description: "ro.board.api_level isn't reliable. Use system api to replace ro.vndk.version"
+ bug: "312315580"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
diff --git a/services/camera/libcameraservice/Android.bp b/services/camera/libcameraservice/Android.bp
index 30e4baf..38476a4 100644
--- a/services/camera/libcameraservice/Android.bp
+++ b/services/camera/libcameraservice/Android.bp
@@ -72,6 +72,7 @@
"libsensorprivacy",
"libstagefright",
"libstagefright_foundation",
+ "libvendorsupport",
"libxml2",
"libyuv",
"android.companion.virtual.virtualdevice_aidl-cpp",
diff --git a/services/camera/libcameraservice/utils/Utils.cpp b/services/camera/libcameraservice/utils/Utils.cpp
index 34c0ed8..76517dc 100644
--- a/services/camera/libcameraservice/utils/Utils.cpp
+++ b/services/camera/libcameraservice/utils/Utils.cpp
@@ -21,18 +21,20 @@
#include <com_android_internal_camera_flags.h>
#include <utils/Errors.h>
#include <utils/Log.h>
+#include <vendorsupport/api_level.h>
namespace android {
namespace flags = com::android::internal::camera::flags;
-constexpr const char *LEGACY_VNDK_VERSION_PROP = "ro.vndk.version";
-constexpr const char *BOARD_API_LEVEL_PROP = "ro.board.api_level";
+namespace {
+constexpr const char* LEGACY_VNDK_VERSION_PROP = "ro.vndk.version";
+constexpr const char* BOARD_API_LEVEL_PROP = "ro.board.api_level";
constexpr int MAX_VENDOR_API_LEVEL = 1000000;
constexpr int FIRST_VNDK_VERSION = 202404;
-int getVNDKVersionFromProp(int defaultVersion) {
- if (!com_android_internal_camera_flags_use_ro_board_api_level_for_vndk_version()) {
+int legacyGetVNDKVersionFromProp(int defaultVersion) {
+ if (!flags::use_ro_board_api_level_for_vndk_version()) {
return base::GetIntProperty(LEGACY_VNDK_VERSION_PROP, defaultVersion);
}
@@ -54,6 +56,24 @@
vndkVersion = (vndkVersion - FIRST_VNDK_VERSION) / 100;
return __ANDROID_API_V__ + vndkVersion;
}
+} // anonymous namespace
+
+int getVNDKVersionFromProp(int defaultVersion) {
+ if (!flags::use_system_api_for_vndk_version()) {
+ return legacyGetVNDKVersionFromProp(defaultVersion);
+ }
+
+ int vendorApiLevel = AVendorSupport_getVendorApiLevel();
+ if (vendorApiLevel == 0) {
+ // Couldn't find vendor API level, return default
+ return defaultVersion;
+ }
+
+ // Vendor API level for Android V and above are of the format YYYYMM starting with 202404.
+ // AVendorSupport_getSdkApiLevelOf maps them back to SDK API levels while leaving older
+ // values unchanged.
+ return AVendorSupport_getSdkApiLevelOf(vendorApiLevel);
+}
RunThreadWithRealtimePriority::RunThreadWithRealtimePriority(int tid)
: mTid(tid), mPreviousPolicy(sched_getscheduler(tid)) {