From 468b1a7a7b31abe52216da53824bac37c4125b96 Mon Sep 17 00:00:00 2001 From: 18242988924 Date: Thu, 17 Aug 2023 11:39:48 +0000 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8Dapi10=E5=A4=A7=E6=95=B4?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 18242988924 Change-Id: I572afd69dd4e833e0d503730c1bf5b22052b5f76 --- .../bundlemgr_lite/src/gt_bundle_parser.cpp | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/services/bundlemgr_lite/src/gt_bundle_parser.cpp b/services/bundlemgr_lite/src/gt_bundle_parser.cpp index dcbcf77..7ba4298 100644 --- a/services/bundlemgr_lite/src/gt_bundle_parser.cpp +++ b/services/bundlemgr_lite/src/gt_bundle_parser.cpp @@ -15,6 +15,8 @@ #include "gt_bundle_parser.h" +#include + #include "ability_info_utils.h" #include "adapter.h" #include "appexecfwk_errors.h" @@ -34,6 +36,9 @@ namespace OHOS { const int32_t BASE_API_VERSION = 3; +const int32_t API_VERSION_MASK = 1000; +static const char* DEVICE_API_VERSION_KEY = "const.product.os.dist.apiversion"; +const int32_t DEVICE_API_VERSION_LEN = 16; int32_t GtBundleParser::ParseValue(const cJSON *object, const char *key, int32_t defaultValue) { @@ -210,12 +215,25 @@ uint8_t GtBundleParser::ParseJsonInfo(const cJSON *appObject, const cJSON *confi if (cJSON_HasObjectItem(appObject, PROFILE_KEY_APIVERSION)) { object = ParseValue(appObject, PROFILE_KEY_APIVERSION, nullptr); CHECK_NULL(object, ERR_APPEXECFWK_INSTALL_FAILED_PARSE_API_VERSION_ERROR); - bundleProfile.profileApiVersion.minApiVersion = ParseValue(object, PROFILE_KEY_APIVERSION_COMPATIBLE, -1); - if (cJSON_HasObjectItem(object, PROFILE_KEY_APIVERSION_TARGET)) { + if (cJSON_HasObjectItem(object, PROFILE_KEY_APIVERSION_COMPATIBLE) && + cJSON_HasObjectItem(object, PROFILE_KEY_APIVERSION_TARGET)) { + bundleProfile.profileApiVersion.minApiVersion = ParseValue(object, PROFILE_KEY_APIVERSION_COMPATIBLE, -1); bundleProfile.profileApiVersion.maxApiVersion = ParseValue(object, PROFILE_KEY_APIVERSION_TARGET, -1); CHECK_IS_TRUE( (bundleProfile.profileApiVersion.maxApiVersion >= bundleProfile.profileApiVersion.minApiVersion), ERR_APPEXECFWK_INSTALL_FAILED_PARSE_API_VERSION_ERROR); + // API 10 + if (bundleProfile.profileApiVersion.minApiVersion >= API_VERSION_MASK && + bundleProfile.profileApiVersion.maxApiVersion >= API_VERSION_MASK) { + int32_t apiLevel = GetSdkApiVersion(); + char value[DEVICE_API_VERSION_LEN] = {0}; + int32_t ret = GetParameter(DEVICE_API_VERSION_KEY, "", value, DEVICE_API_VERSION_LEN); + CHECK_IS_TRUE((ret >= 0), ERR_APPEXECFWK_INSTALL_FAILED_PARSE_API_VERSION_ERROR); + int32_t apiVersion = static_cast(std::atoi(value)); + int32_t deviceVersion = apiVersion * API_VERSION_MASK + apiLevel; + CHECK_IS_TRUE((deviceVersion >= bundleProfile.profileApiVersion.minApiVersion), + ERR_APPEXECFWK_INSTALL_FAILED_PARSE_API_VERSION_ERROR); + } } } else { // parse deviceConfig -- Gitee