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

Commit f50484fe authored by Avichal Rakesh's avatar Avichal Rakesh
Browse files

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
parent a54cf01e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -227,3 +227,13 @@ flag {
       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
     }
}
+1 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ cc_defaults {
        "libsensorprivacy",
        "libstagefright",
        "libstagefright_foundation",
        "libvendorsupport",
        "libxml2",
        "libyuv",
        "android.companion.virtual.virtualdevice_aidl-cpp",
+24 −4
Original line number Diff line number Diff line
@@ -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;

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 @@ int getVNDKVersionFromProp(int defaultVersion) {
    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)) {