Issue: #I76QBP

Description:add bundle extension
Sig: SIG_ApplicaitonFramework
Feature or Bugfix: Feature
Binary Source: No

Signed-off-by: zhaogan <zhaogan2@huawei.com>
This commit is contained in:
zhaogan 2023-05-19 14:34:31 +08:00
parent 8e66133adc
commit 5c0efb9159
20 changed files with 624 additions and 4 deletions

View File

@ -19,6 +19,7 @@ group("bms_target") {
"common:common_target",
"interfaces/inner_api/appexecfwk_base:appexecfwk_base",
"interfaces/inner_api/appexecfwk_core:appexecfwk_core",
"interfaces/inner_api/appexecfwk_extension:appexecfwk_extension",
"interfaces/kits/js:napi_packages",
"interfaces/kits/native/app_detail_ability:app_detail_ability",
"interfaces/kits/native/bundle:bundle_ndk",

View File

@ -33,6 +33,7 @@ inner_api_path = "${bundle_framework_path}/interfaces/inner_api"
tools_path = "${bundle_framework_path}/tools"
base_path = "${bundle_framework_path}/interfaces/inner_api/appexecfwk_base"
core_path = "${bundle_framework_path}/interfaces/inner_api/appexecfwk_core"
extension_path = "${bundle_framework_path}/interfaces/inner_api/appexecfwk_extension"
declare_args() {
bundle_framework_graphics = true

View File

@ -119,6 +119,19 @@
]
},
"name": "//foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_core:appexecfwk_core"
},
{
"header": {
"header_base": "//foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_extension/include",
"header_files": [
"bms_extension_data_mgr.h",
"bms_extension_profile.h",
"bms_extension.h",
"bundle_mgr_ext_register.h",
"bundle_mgr_ext.h"
]
},
"name": "//foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_extension:appexecfwk_extension"
}
],
"test": [

View File

@ -240,6 +240,9 @@ struct ApplicationInfo : public Parcelable {
bool split = true;
BundleType bundleType = BundleType::APP;
std::string compileSdkVersion;
std::string compileSdkType = "OpenHarmony";
bool ReadFromParcel(Parcel &parcel);
bool ReadMetaDataFromParcel(Parcel &parcel);
virtual bool Marshalling(Parcel &parcel) const override;

View File

@ -112,6 +112,8 @@ const std::string APPLICATION_ASAN_ENABLED = "asanEnabled";
const std::string APPLICATION_ASAN_LOG_PATH = "asanLogPath";
const std::string APPLICATION_SPLIT = "split";
const std::string APPLICATION_APP_TYPE = "bundleType";
const std::string APPLICATION_COMPILE_SDK_VERSION = "compileSdkVersion";
const std::string APPLICATION_COMPILE_SDK_TYPE = "compileSdkType";
}
Metadata::Metadata(const std::string &paramName, const std::string &paramValue, const std::string &paramResource)
@ -399,6 +401,8 @@ bool ApplicationInfo::ReadFromParcel(Parcel &parcel)
asanLogPath = Str16ToStr8(parcel.ReadString16());
split = parcel.ReadBool();
bundleType = static_cast<BundleType>(parcel.ReadInt32());
compileSdkVersion = Str16ToStr8(parcel.ReadString16());
compileSdkType = Str16ToStr8(parcel.ReadString16());
return true;
}
@ -541,6 +545,8 @@ bool ApplicationInfo::Marshalling(Parcel &parcel) const
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(asanLogPath));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, split);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(bundleType));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(compileSdkVersion));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(compileSdkType));
return true;
}
@ -723,6 +729,8 @@ void to_json(nlohmann::json &jsonObject, const ApplicationInfo &applicationInfo)
{APPLICATION_ASAN_LOG_PATH, applicationInfo.asanLogPath},
{APPLICATION_SPLIT, applicationInfo.split},
{APPLICATION_APP_TYPE, applicationInfo.bundleType},
{APPLICATION_COMPILE_SDK_VERSION, applicationInfo.compileSdkVersion},
{APPLICATION_COMPILE_SDK_TYPE, applicationInfo.compileSdkType},
};
}
@ -1346,6 +1354,22 @@ void from_json(const nlohmann::json &jsonObject, ApplicationInfo &applicationInf
false,
parseResult,
ArrayType::NOT_ARRAY);
GetValueIfFindKey<std::string>(jsonObject,
jsonObjectEnd,
APPLICATION_COMPILE_SDK_VERSION,
applicationInfo.compileSdkVersion,
JsonType::STRING,
false,
parseResult,
ArrayType::NOT_ARRAY);
GetValueIfFindKey<std::string>(jsonObject,
jsonObjectEnd,
APPLICATION_COMPILE_SDK_TYPE,
applicationInfo.compileSdkType,
JsonType::STRING,
false,
parseResult,
ArrayType::NOT_ARRAY);
if (parseResult != ERR_OK) {
APP_LOGE("from_json error, error code : %{public}d", parseResult);
}

View File

@ -0,0 +1,52 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("../../../appexecfwk.gni")
config("appexecfwk_core_ex_sdk_config") {
include_dirs = [
"include",
"../../inner_api/appexecfwk_base/include",
]
}
ohos_shared_library("appexecfwk_extension") {
sources = [
"src/bms_extension_data_mgr.cpp",
"src/bms_extension_profile.cpp",
"src/bundle_mgr_ext_register.cpp"
]
public_configs = [ ":appexecfwk_core_ex_sdk_config" ]
defines = [
"APP_LOG_TAG = \"BundleMgrService\"",
"LOG_DOMAIN = 0xD001120",
]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [ "${common_path}:libappexecfwk_common" ]
external_deps = [
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
]
subsystem_name = "bundlemanager"
part_name = "bundle_framework"
}

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BMS_EXTENSION_H
#define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BMS_EXTENSION_H
#include <string>
namespace OHOS {
namespace AppExecFwk {
struct BmsExtensionBundleMgr
{
std::string extensionName;
std::string libPath;
std::string lib64Path;
std::string ToString() const
{
return "[ extensionName = " + extensionName
+ ", libPath = " + libPath
+ ", lib64Path = " + lib64Path + "]";
}
};
struct BmsExtension
{
BmsExtensionBundleMgr bmsExtensionBundleMgr;
std::string ToString() const
{
return bmsExtensionBundleMgr.ToString();
}
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BMS_EXTENSION_H

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BMS_EXTENSION_DATA_MGR_H
#define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BMS_EXTENSION_DATA_MGR_H
#include <mutex>
#include <string>
#include "bms_extension.h"
#include "bundle_info.h"
namespace OHOS {
namespace AppExecFwk {
class BmsExtensionDataMgr {
public:
BmsExtensionDataMgr();
bool CheckApiInfo(const BundleInfo &bundleInfo) const;
private:
void init();
bool OpenHandler();
static BmsExtension bmsExtension;
static void *handler;
mutable std::mutex stateMutex_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BMS_EXTENSION_DATA_MGR_H

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "appexecfwk_errors.h"
#include "bms_extension.h"
#include "json_util.h"
namespace OHOS {
namespace AppExecFwk {
class BmsExtensionProfile {
public:
/**
* @brief Parse bms extension file, then save in BmsExtension info.
* @param jsonPath Indicates the bms-extension.json File.
* @param bmsExtension Indicates the obtained BmsExtension object.
* @return Returns ERR_OK if the json file successfully parsed; returns ErrCode otherwise.
*/
ErrCode ParseBmsExtension(const std::string &jsonPath, BmsExtension &bmsExtension) const;
private:
bool ReadFileIntoJson(const std::string &filePath, nlohmann::json &jsonBuf) const;
ErrCode TransformTo(const nlohmann::json &jsonObject, BmsExtension &bmsExtension) const;
};
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_INNERKITS_APPEXECFWK_CORE_EXT_INCLUDE_BUNDLE_MGR_EX_H
#define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_INNERKITS_APPEXECFWK_CORE_EXT_INCLUDE_BUNDLE_MGR_EX_H
#include "bundle_info.h"
namespace OHOS {
namespace AppExecFwk {
class BundleMgrExt {
public:
virtual bool CheckApiInfo(const BundleInfo& bundleInfo) = 0;
virtual ~BundleMgrExt() = default;
};
} // AppExecFwk
} // OHOS
#endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_INNERKITS_APPEXECFWK_CORE_EXT_INCLUDE_BUNDLE_MGR_EX_H

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_INNERKITS_APPEXECFWK_CORE_EXT_INCLUDE_BUNDLE_MGR_EX_REGISTER_H
#define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_INNERKITS_APPEXECFWK_CORE_EXT_INCLUDE_BUNDLE_MGR_EX_REGISTER_H
#include <functional>
#include <string>
#include <unordered_map>
#include "bundle_mgr_ext.h"
#include "nocopyable.h"
namespace OHOS {
namespace AppExecFwk {
using CreateFunc = std::function<std::shared_ptr<BundleMgrExt>(void)>;
class BundleMgrExtRegister {
public:
static BundleMgrExtRegister &GetInstance();
~BundleMgrExtRegister() = default;
void RegisterBundleMgrExt(const std::string& bundleExtName, const CreateFunc& createFunc);
std::shared_ptr<BundleMgrExt> GetBundleMgrExt(const std::string &bundleExtName);
private:
BundleMgrExtRegister() = default;
std::unordered_map<std::string, CreateFunc> bundleMgrExts_;
DISALLOW_COPY_AND_MOVE(BundleMgrExtRegister);
};
#define REGISTER_BUNDLEMGR_EXT(className) \
__attribute__((constructor)) void RegisterBundleMgrExt##className() { \
BundleMgrExtRegister::GetInstance().RegisterBundleMgrExt(#className, []()->std::shared_ptr<BundleMgrExt> { \
return std::make_shared<className>(); \
}); \
}
} // AppExecFwk
} // OHOS
#endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_INNERKITS_APPEXECFWK_CORE_EXT_INCLUDE_BUNDLE_MGR_EX_REGISTER_H

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <dlfcn.h>
#include "bms_extension_data_mgr.h"
#include "bms_extension_profile.h"
#include "bundle_mgr_ext_register.h"
#include "app_log_wrapper.h"
namespace OHOS {
namespace AppExecFwk {
BmsExtension BmsExtensionDataMgr::bmsExtension;
void* BmsExtensionDataMgr::handler = nullptr;
namespace {
const std::string BMS_EXTENSION_PATH = "/system/etc/app/bms-extensions.json";
}
BmsExtensionDataMgr::BmsExtensionDataMgr()
{
init();
APP_LOGI("base bundle installer instance is created");
auto message = bmsExtension.ToString();
bool isNullptr = (handler == nullptr);
APP_LOGD("bms-extension: %{public}s, handler is nullptr: %{public}d", message.c_str(), isNullptr);
}
void BmsExtensionDataMgr::init()
{
std::lock_guard<std::mutex> stateLock(stateMutex_);
if (bmsExtension.bmsExtensionBundleMgr.extensionName.empty() || !handler) {
BmsExtensionProfile bmsExtensionProfile;
auto res = bmsExtensionProfile.ParseBmsExtension(BMS_EXTENSION_PATH, bmsExtension);
if (res != ERR_OK) {
APP_LOGE("ParseBmsExtension failed, errCode is %{public}d", res);
return;
}
APP_LOGD("parse bms-extension.json success, which is: %{public}s", bmsExtension.ToString().c_str());
if (OpenHandler()) {
APP_LOGD("dlopen bms-extension so success");
}
}
}
bool BmsExtensionDataMgr::OpenHandler()
{
APP_LOGI("OpenHandler start");
auto handle = &handler;
if (handle == nullptr) {
APP_LOGE("OpenHandler error handle is nullptr.");
return false;
}
auto libPath = bmsExtension.bmsExtensionBundleMgr.libPath.c_str();
auto lib64Path = bmsExtension.bmsExtensionBundleMgr.lib64Path.c_str();
*handle = dlopen(lib64Path, RTLD_NOW | RTLD_GLOBAL);
if (*handle == nullptr) {
APP_LOGW("failed to open %{public}s, err:%{public}s", lib64Path, dlerror());
*handle = dlopen(libPath, RTLD_NOW | RTLD_GLOBAL);
}
if (*handle == nullptr) {
APP_LOGE("failed to open %{public}s, err:%{public}s", libPath, dlerror());
return false;
}
APP_LOGI("OpenHandler end");
return true;
}
bool BmsExtensionDataMgr::CheckApiInfo(const BundleInfo &bundleInfo) const
{
if (handler) {
auto bundleMgrExtPtr =
BundleMgrExtRegister::GetInstance().GetBundleMgrExt(bmsExtension.bmsExtensionBundleMgr.extensionName);
return bundleMgrExtPtr->CheckApiInfo(bundleInfo);
}
return false;
}
} // AppExecFwk
} // OHOS

View File

@ -0,0 +1,133 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <fstream>
#include <sstream>
#include <unistd.h>
#include "app_log_wrapper.h"
#include "bms_extension_profile.h"
namespace OHOS {
namespace AppExecFwk {
namespace {
static const std::string BMS_EXTENSION_PROFILE = "bms-extensions";
static const std::string BMS_EXTENSION_PROFILE_BUNDLE_MGR = "bundle-mgr";
static const std::string BUNDLE_MGR_KEY_EXTENSION_NAME = "extension-name";
static const std::string BUNDLE_MGR_KEY_LIB_PATH = "libpath";
static const std::string BUNDLE_MGR_KEY_LIB64_PATH = "lib64path";
}
ErrCode BmsExtensionProfile::ParseBmsExtension(
const std::string &jsonPath, BmsExtension &bmsExtension) const
{
APP_LOGD("Parse BmsExtension from %{private}s", jsonPath.c_str());
nlohmann::json jsonBuf;
if (!ReadFileIntoJson(jsonPath, jsonBuf)) {
APP_LOGE("Parse bms-extension.json file failed, jsonPath: %{public}s", jsonPath.c_str());
return ERR_APPEXECFWK_PARSE_FILE_FAILED;
}
return TransformTo(jsonBuf, bmsExtension);
}
bool BmsExtensionProfile::ReadFileIntoJson(const std::string &filePath, nlohmann::json &jsonBuf) const
{
if (access(filePath.c_str(), F_OK) != 0) {
APP_LOGE("can not access the file: %{public}s", filePath.c_str());
return false;
}
std::fstream in;
char errBuf[256];
errBuf[0] = '\0';
in.open(filePath, std::ios_base::in);
if (!in.is_open()) {
strerror_r(errno, errBuf, sizeof(errBuf));
APP_LOGE("the file cannot be open due to %{public}s", errBuf);
return false;
}
in.seekg(0, std::ios::end);
int64_t size = in.tellg();
if (size <= 0) {
APP_LOGE("the file is an empty file");
in.close();
return false;
}
in.seekg(0, std::ios::beg);
jsonBuf = nlohmann::json::parse(in, nullptr, false);
in.close();
if (jsonBuf.is_discarded()) {
APP_LOGE("bad profile file");
return false;
}
return true;
}
ErrCode BmsExtensionProfile::TransformTo(const nlohmann::json &jsonObject,
BmsExtension &bmsExtension) const
{
APP_LOGE("transform bms-extension.json stream to BmsExtension");
if (jsonObject.is_discarded()) {
APP_LOGE("profile format error");
return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
}
if (jsonObject.find(BMS_EXTENSION_PROFILE) == jsonObject.end()) {
APP_LOGE("bms-extensions no exist");
return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
}
nlohmann::json bmsExtensionJson = jsonObject.at(BMS_EXTENSION_PROFILE);
if (!bmsExtensionJson.is_object()) {
APP_LOGE("bms-extension.json file lacks of invalid bms-extensions property");
return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
}
nlohmann::json bundleMgrJson = bmsExtensionJson.at(BMS_EXTENSION_PROFILE_BUNDLE_MGR);
if (!bundleMgrJson.is_object()) {
APP_LOGE("bms-extension.json file lacks of invalid bundle-mgr property");
return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
}
const auto &jsonObjectEnd = bundleMgrJson.end();
int32_t parseResult = ERR_OK;
GetValueIfFindKey<std::string>(bundleMgrJson,
jsonObjectEnd,
BUNDLE_MGR_KEY_EXTENSION_NAME,
bmsExtension.bmsExtensionBundleMgr.extensionName,
JsonType::STRING,
true,
parseResult,
ArrayType::NOT_ARRAY);
GetValueIfFindKey<std::string>(bundleMgrJson,
jsonObjectEnd,
BUNDLE_MGR_KEY_LIB_PATH,
bmsExtension.bmsExtensionBundleMgr.libPath,
JsonType::STRING,
true,
parseResult,
ArrayType::NOT_ARRAY);
GetValueIfFindKey<std::string>(bundleMgrJson,
jsonObjectEnd,
BUNDLE_MGR_KEY_LIB64_PATH,
bmsExtension.bmsExtensionBundleMgr.lib64Path,
JsonType::STRING,
true,
parseResult,
ArrayType::NOT_ARRAY);
return parseResult;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bundle_mgr_ext_register.h"
#include "app_log_wrapper.h"
namespace OHOS {
namespace AppExecFwk {
BundleMgrExtRegister &BundleMgrExtRegister::GetInstance()
{
APP_LOGE("zhaogan BundleMgrExtRegister::GetInstance");
static BundleMgrExtRegister bundleMgrExt;
return bundleMgrExt;
}
void BundleMgrExtRegister::RegisterBundleMgrExt(const std::string& bundleExtName, const CreateFunc& createFunc)
{
bundleMgrExts_.emplace(bundleExtName, createFunc);
}
std::shared_ptr<BundleMgrExt> BundleMgrExtRegister::GetBundleMgrExt(const std::string &bundleExtName)
{
APP_LOGE("zhaogan BundleMgrExtRegister::GetBundleMgrExt");
auto it = bundleMgrExts_.find(bundleExtName);
if (it == bundleMgrExts_.end()) {
APP_LOGE("zhaogan BundleMgrExtRegister::GetBundleMgrExt11");
return nullptr;
} else {
APP_LOGE("zhaogan BundleMgrExtRegister::GetBundleMgrExt22");
return it->second();
}
}
} // AppExecFwk
} // OHOS

View File

@ -28,6 +28,7 @@ config("bundlemgr_common_config") {
"include/shared",
"include/quick_fix/state/include",
"../../interfaces/inner_api/appexecfwk_base/include",
"../../interfaces/inner_api/appexecfwk_extension/include",
]
include_dirs += bundle_mgr_impl_include_dirs
@ -78,6 +79,7 @@ ohos_source_set("parser_common") {
external_deps = [
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_extension",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
]
@ -139,6 +141,7 @@ ohos_source_set("bundle_parser") {
"ability_base:want",
"access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_extension",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"init:libbegetutil",
@ -218,6 +221,7 @@ ohos_shared_library("libbms") {
"appverify:libhapverify",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"bundle_framework:appexecfwk_extension",
"common_event_service:cesfwk_innerkits",
"device_info_manager:distributed_device_profile_client",
"eventhandler:libeventhandler",

View File

@ -575,6 +575,7 @@ private:
bool CheckDuplicateProxyData(const std::unordered_map<std::string, InnerBundleInfo> &newInfos);
bool CheckDuplicateProxyData(const InnerBundleInfo &newInfo, const InnerBundleInfo &oldInfo);
bool CheckDuplicateProxyData(const std::vector<ProxyData> &proxyDatas);
bool CheckApiInfoByCompileSdk(const std::unordered_map<std::string, InnerBundleInfo> &infos);
InstallerState state_ = InstallerState::INSTALL_START;
std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr; // this pointer will get when public functions called
std::string bundleName_;

View File

@ -460,6 +460,11 @@ constexpr const char* PRELOADS_MODULE_NAME = "moduleName";
constexpr const char* BUNDLE_TYPE_APP = "app";
constexpr const char* BUNDLE_TYPE_ATOMIC_SERVICE = "atomicService";
constexpr const char* BUNDLE_TYPE_SHARED = "shared";
// compileSdkType
constexpr const char* COMPILE_SDK_VERSION = "compileSdkVersion";
constexpr const char* COMPILE_SDK_TYPE = "compileSdkType";
constexpr const char* COMPILE_SDK_TYPE_OPEN_HARMONY = "OpenHarmony";
} // namespace Profile
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -39,6 +39,7 @@
#include "ability_manager_helper.h"
#include "app_log_wrapper.h"
#include "app_provision_info_manager.h"
#include "bms_extension_data_mgr.h"
#include "bundle_constants.h"
#include "bundle_extractor.h"
#include "bundle_mgr_service.h"
@ -68,6 +69,7 @@ using namespace OHOS::Security;
namespace {
const std::string ARK_CACHE_PATH = "/data/local/ark-cache/";
const std::string ARK_PROFILE_PATH = "/data/local/ark-profile/";
const std::string COMPILE_SDK_TYPE_OPEN_HARMONY = "OpenHarmony";
const std::string LOG = "log";
const std::string HSP_VERSION_PREFIX = "v";
const std::string PRE_INSTALL_HSP_PATH = "/shared_bundles/";
@ -2604,11 +2606,29 @@ ErrCode BaseBundleInstaller::CheckAppLabelInfo(const std::unordered_map<std::str
return ret;
}
if (!CheckApiInfoByCompileSdk(infos)) {
APP_LOGE("CheckApiInfoByCompileSdk failed.");
return ERR_APPEXECFWK_INSTALL_SDK_INCOMPATIBLE;
}
bundleName_ = (infos.begin()->second).GetBundleName();
versionCode_ = (infos.begin()->second).GetVersionCode();
return ERR_OK;
}
bool BaseBundleInstaller::CheckApiInfoByCompileSdk(const std::unordered_map<std::string, InnerBundleInfo> &infos)
{
std::string compileSdkType = infos.begin()->second.GetBaseApplicationInfo().compileSdkType;
auto bundleInfo = infos.begin()->second.GetBaseBundleInfo();
if (compileSdkType == COMPILE_SDK_TYPE_OPEN_HARMONY) {
return bundleInfo.compatibleVersion <= static_cast<uint32_t>(GetSdkApiVersion());
} else {
BmsExtensionDataMgr bmsExtensionDataMgr;
return bmsExtensionDataMgr.CheckApiInfo(infos.begin()->second.GetBaseBundleInfo());
}
return true;
}
ErrCode BaseBundleInstaller::CheckMultiNativeFile(
std::unordered_map<std::string, InnerBundleInfo> &infos)
{

View File

@ -732,10 +732,6 @@ ErrCode BundleInstallChecker::CheckAppLabelInfo(
return ERR_APPEXECFWK_INSTALL_DEBUG_NOT_SAME;
}
}
// check api sdk version
if ((infos.begin()->second).GetCompatibleVersion() > static_cast<uint32_t>(GetSdkApiVersion())) {
return ERR_APPEXECFWK_INSTALL_SDK_INCOMPATIBLE;
}
APP_LOGD("finish check APP label");
return ret;
}

View File

@ -222,6 +222,8 @@ struct App {
int32_t targetPriority = 0;
bool asanEnabled = false;
std::string bundleType = Profile::BUNDLE_TYPE_APP;
std::string compileSdkVersion;
std::string compileSdkType = Profile::COMPILE_SDK_TYPE_OPEN_HARMONY;
};
struct Module {
@ -1107,6 +1109,22 @@ void from_json(const nlohmann::json &jsonObject, App &app)
false,
g_parseResult,
ArrayType::NOT_ARRAY);
GetValueIfFindKey<std::string>(jsonObject,
jsonObjectEnd,
COMPILE_SDK_VERSION,
app.compileSdkVersion,
JsonType::STRING,
false,
g_parseResult,
ArrayType::NOT_ARRAY);
GetValueIfFindKey<std::string>(jsonObject,
jsonObjectEnd,
COMPILE_SDK_TYPE,
app.compileSdkType,
JsonType::STRING,
false,
g_parseResult,
ArrayType::NOT_ARRAY);
}
void from_json(const nlohmann::json &jsonObject, Module &module)
@ -1726,6 +1744,8 @@ bool ToApplicationInfo(
if (iterBundleType != Profile::BUNDLE_TYPE_MAP.end()) {
applicationInfo.bundleType = iterBundleType->second;
}
applicationInfo.compileSdkVersion = app.compileSdkVersion;
applicationInfo.compileSdkType = app.compileSdkType;
return true;
}