Skip to content

Commit

Permalink
Merge "Calculate ro.vendor.api_level with the new vendor API format" …
Browse files Browse the repository at this point in the history
…into main am: 698c6f9 am: dfeb7be

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2839486

Change-Id: I5ee6359029809a00c60ae36b172a4a7a645d5d90
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
  • Loading branch information
Justin Yun authored and android-build-merge-worker-robot committed Dec 7, 2023
2 parents ca0cfac + dfeb7be commit d454b50
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions init/property_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ using namespace std::literals;

using android::base::ErrnoError;
using android::base::Error;
using android::base::GetIntProperty;
using android::base::GetProperty;
using android::base::ParseInt;
using android::base::ReadFileToString;
Expand Down Expand Up @@ -112,7 +113,7 @@ constexpr auto ID_PROP = "ro.build.id";
constexpr auto LEGACY_ID_PROP = "ro.build.legacy.id";
constexpr auto VBMETA_DIGEST_PROP = "ro.boot.vbmeta.digest";
constexpr auto DIGEST_SIZE_USED = 8;
constexpr auto API_LEVEL_CURRENT = 10000;
constexpr auto MAX_VENDOR_API_LEVEL = 1000000;

static bool persistent_properties_loaded = false;

Expand Down Expand Up @@ -1084,36 +1085,44 @@ static void property_initialize_ro_cpu_abilist() {
}
}

static int read_api_level_props(const std::vector<std::string>& api_level_props) {
int api_level = API_LEVEL_CURRENT;
for (const auto& api_level_prop : api_level_props) {
api_level = android::base::GetIntProperty(api_level_prop, API_LEVEL_CURRENT);
if (api_level != API_LEVEL_CURRENT) {
break;
}
static int vendor_api_level_of(int sdk_api_level) {
if (sdk_api_level < __ANDROID_API_V__) {
return sdk_api_level;
}
return api_level;
// In Android V, vendor API level started with version 202404.
// The calculation assumes that the SDK api level bumps once a year.
if (sdk_api_level < __ANDROID_API_FUTURE__) {
return 202404 + ((sdk_api_level - __ANDROID_API_V__) * 100);
}
return MAX_VENDOR_API_LEVEL;
}

static void property_initialize_ro_vendor_api_level() {
// ro.vendor.api_level shows the api_level that the vendor images (vendor, odm, ...) are
// required to support.
constexpr auto VENDOR_API_LEVEL_PROP = "ro.vendor.api_level";

// Api level properties of the board. The order of the properties must be kept.
std::vector<std::string> BOARD_API_LEVEL_PROPS = {"ro.board.api_level",
"ro.board.first_api_level"};
// Api level properties of the device. The order of the properties must be kept.
std::vector<std::string> DEVICE_API_LEVEL_PROPS = {"ro.product.first_api_level",
"ro.build.version.sdk"};
auto vendor_api_level = GetIntProperty("ro.board.first_api_level", MAX_VENDOR_API_LEVEL);
if (vendor_api_level != MAX_VENDOR_API_LEVEL) {
// Update the vendor_api_level with "ro.board.api_level" only if both "ro.board.api_level"
// and "ro.board.first_api_level" are defined.
vendor_api_level = GetIntProperty("ro.board.api_level", vendor_api_level);
}

auto product_first_api_level =
GetIntProperty("ro.product.first_api_level", __ANDROID_API_FUTURE__);
if (product_first_api_level == __ANDROID_API_FUTURE__) {
// Fallback to "ro.build.version.sdk" if the "ro.product.first_api_level" is not defined.
product_first_api_level = GetIntProperty("ro.build.version.sdk", __ANDROID_API_FUTURE__);
}

vendor_api_level = std::min(vendor_api_level_of(product_first_api_level), vendor_api_level);

int api_level = std::min(read_api_level_props(BOARD_API_LEVEL_PROPS),
read_api_level_props(DEVICE_API_LEVEL_PROPS));
std::string error;
auto res = PropertySetNoSocket(VENDOR_API_LEVEL_PROP, std::to_string(api_level), &error);
auto res = PropertySetNoSocket(VENDOR_API_LEVEL_PROP, std::to_string(vendor_api_level), &error);
if (res != PROP_SUCCESS) {
LOG(ERROR) << "Failed to set " << VENDOR_API_LEVEL_PROP << " with " << api_level << ": "
<< error << "(" << res << ")";
LOG(ERROR) << "Failed to set " << VENDOR_API_LEVEL_PROP << " with " << vendor_api_level
<< ": " << error << "(" << res << ")";
}
}

Expand Down

0 comments on commit d454b50

Please sign in to comment.