add code and tdd for dataPreload

Signed-off-by: sunjiakun <sunjiakun5@huawei.com>
This commit is contained in:
sunjiakun 2024-11-01 09:24:36 +08:00
parent 0fe05b18f7
commit 9c1f97fff8
18 changed files with 372 additions and 14 deletions

View File

@ -12,3 +12,4 @@
# limitations under the License.
bootevent.bms.main.bundles.ready = false
persist.bms.data.preload = true

View File

@ -14,4 +14,4 @@
const.bms.optimizing_apps.switch = foundation:foundation:0755
bms.optimizing_apps.status = foundation:foundation:0755
bootevent.bms.main.bundles.ready = foundation:foundation:0755
persist.bms.data.preload = foundation:foundation:0755

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -91,6 +91,8 @@ struct InstallParam : public Parcelable {
std::string specifiedDistributionType = "";
// Indicates the additional Info
std::string additionalInfo = "";
bool isDataPreloadHap = false;
std::string appIdentifier;
// utilizing for code-signature
std::map<std::string, std::string> verifyCodeParams;
ApplicationInfoFlag preinstallSourceFlag = ApplicationInfoFlag::FLAG_INSTALLED;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -56,6 +56,8 @@ bool InstallParam::ReadFromParcel(Parcel &parcel)
}
specifiedDistributionType = Str16ToStr8(parcel.ReadString16());
additionalInfo = Str16ToStr8(parcel.ReadString16());
isDataPreloadHap = parcel.ReadBool();
appIdentifier = Str16ToStr8(parcel.ReadString16());
int32_t verifyCodeParamSize;
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, verifyCodeParamSize);
@ -110,6 +112,8 @@ bool InstallParam::Marshalling(Parcel &parcel) const
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(specifiedDistributionType));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(additionalInfo));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDataPreloadHap);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appIdentifier));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(verifyCodeParams.size()));
for (const auto &verifyCodeParam : verifyCodeParams) {
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(verifyCodeParam.first));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -596,6 +596,8 @@ private:
ErrCode CreateArkProfile(
const std::string &bundleName, int32_t userId, int32_t uid, int32_t gid) const;
ErrCode DeleteArkProfile(const std::string &bundleName, int32_t userId) const;
bool RemoveDataPreloadHapFiles(const std::string &bundleName) const;
bool IsDataPreloadHap(const std::string &path) const;
ErrCode ExtractArkProfileFile(const std::string &modulePath, const std::string &bundleName,
int32_t userId) const;
ErrCode ExtractAllArkProfileFile(const InnerBundleInfo &oldInfo, bool checkRepeat = false) const;

View File

@ -543,7 +543,7 @@ private:
bool IsTestSystemUpgrade();
bool IsSystemFingerprintChanged();
std::string GetCurSystemFingerprint();
std::string GetOldSystemFingerprint();
static std::string GetOldSystemFingerprint();
bool GetSystemParameter(const std::string &key, std::string &value);
void SaveSystemFingerprint();
void HandlePreInstallException();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -58,6 +58,13 @@ public:
*/
ErrCode ParsePreInstallConfig(
const std::string &configFile, std::set<PreScanInfo> &scanInfos) const;
/**
* @brief Parse scanAppInfos by the configFile.
* @param configFile Indicates the path of configFile.
* @param scanInfos Indicates the obtained InnerBundleInfo object.
* @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise.
*/
ErrCode ParsePreAppListConfig(const std::string &configFile, std::set<PreScanInfo> &scanAppInfos) const;
/**
* @brief Parse bundleNames by the configFile.
* @param configFile Indicates the path of configFile.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -155,6 +155,7 @@ constexpr const char* PGO_FILE_SUFFIX = ".ap";
constexpr const char* ALLOW_ENTERPRISE_BUNDLE = "const.bms.allowenterprisebundle";
constexpr const char* IS_ENTERPRISE_DEVICE = "const.edm.is_enterprise_device";
constexpr const char* DEVELOPERMODE_STATE = "const.security.developermode.state";
constexpr const char* BMS_DATA_PRELOAD = "persist.bms.data.preload";
//extResource
constexpr const char* EXT_RESOURCE_FILE_PATH = "ext_resource";
// hmdfs and sharefs config

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -35,6 +35,13 @@ public:
ErrCode TransformTo(
const nlohmann::json &jsonBuf,
std::set<PreScanInfo> &scanInfos) const;
/**
* @brief Transform the jsonBuf to scanAppListInfos.
* @param jsonBuf Indicates the jsonBuf.
* @param scanAppInfos Indicates the scanAppInfos.
* @return Returns ERR_OK if the information transformed successfully; returns error code otherwise.
*/
ErrCode TransformToAppList(const nlohmann::json &jsonBuf, std::set<PreScanInfo> &scanAppInfos) const;
/**
* @brief Transform the jsonBuf to bundleNames.
* @param jsonBuf Indicates the jsonBuf.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -102,6 +102,8 @@ struct PreScanInfo {
std::string bundleDir;
bool removable = true;
int32_t priority = 0;
std::string appIdentifier;
bool isDataPreloadHap = false;
bool operator < (const PreScanInfo &preScanInfo) const
{
@ -122,12 +124,16 @@ struct PreScanInfo {
bundleDir.clear();
removable = true;
priority = 0;
appIdentifier.clear();
isDataPreloadHap = false;
}
std::string ToString() const
{
return "[ bundleDir = " + bundleDir
+ ", removable = " + GetBoolStrVal(removable)
+ ", appIdentifier = " + appIdentifier
+ ", isDataPreloadHap = " + GetBoolStrVal(isDataPreloadHap)
+ ", priority = " + std::to_string(priority) + "]";
}
};

View File

@ -72,6 +72,7 @@ namespace AppExecFwk {
using namespace OHOS::Security;
namespace {
constexpr const char* ARK_CACHE_PATH = "/data/local/ark-cache/";
constexpr const char* DATA_PRELOAD_APP = "/data/preload/app/";
constexpr const char* ARK_PROFILE_PATH = "/data/local/ark-profile/";
constexpr const char* COMPILE_SDK_TYPE_OPEN_HARMONY = "OpenHarmony";
constexpr const char* LOG = "log";
@ -101,6 +102,7 @@ constexpr const char* BMS_KEY_SHELL_UID = "const.product.shell.uid";
constexpr const char* IS_ROOT_MODE_PARAM = "const.debuggable";
constexpr const char* BMS_ACTIVATION_LOCK = "persist.bms.activation-lock";
constexpr const char* BMS_TRUE = "true";
constexpr const char* BMS_FALSE = "false";
constexpr int8_t BMS_ACTIVATION_LOCK_VAL_LEN = 20;
const std::set<std::string> SINGLETON_WHITE_LIST = {
@ -203,6 +205,11 @@ ErrCode BaseBundleInstaller::InstallBundle(
int32_t uid = Constants::INVALID_UID;
ErrCode result = ProcessBundleInstall(bundlePaths, installParam, appType, uid);
if (result != ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON && result != ERR_OK &&
installParam.isDataPreloadHap && GetUserId(installParam.userId) == Constants::DEFAULT_USERID) {
LOG_E(BMS_TAG_INSTALLER, "set parameter BMS_DATA_PRELOAD false");
OHOS::system::SetParameter(ServiceConstants::BMS_DATA_PRELOAD, BMS_FALSE);
}
if (installParam.needSendEvent && dataMgr_ && !bundleName_.empty()) {
NotifyBundleEvents installRes = {
.isModuleUpdate = isModuleUpdate_,
@ -1151,6 +1158,11 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector<std::string>
std::unordered_map<std::string, InnerBundleInfo> newInfos;
result = ParseHapFiles(bundlePaths, installParam, appType, hapVerifyResults, newInfos);
CHECK_RESULT(result, "parse haps file failed %{public}d");
if (userId_ == Constants::DEFAULT_USERID && installParam.isDataPreloadHap &&
installParam.appIdentifier != appIdentifier_) {
result = ERR_APPEXECFWK_INSTALL_VERIFICATION_FAILED;
}
CHECK_RESULT(result, "check DataPreloadHap appIdentifier failed %{public}d");
// washing machine judge
if (!installParam.isPreInstallApp) {
for (const auto &infoIter: newInfos) {
@ -1257,6 +1269,13 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector<std::string>
result = SaveHapToInstallPath(newInfos);
CHECK_RESULT_WITH_ROLLBACK(result, "copy hap to install path failed %{public}d", newInfos, oldInfo);
}
if (installParam.isDataPreloadHap) {
// Verify Code Signature For Data Preload Hap
for (const auto &preinstalledAppPath : bundlePaths) {
VerifyCodeSignatureForHap(newInfos, preinstalledAppPath, preinstalledAppPath);
}
}
// delete old native library path
if (NeedDeleteOldNativeLib(newInfos, oldInfo)) {
LOG_I(BMS_TAG_INSTALLER, "Delete old library");
@ -1333,6 +1352,9 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector<std::string>
groupDirGuard.Dismiss();
extensionDirGuard.Dismiss();
ScreenLockFileProtectionDirGuard.Dismiss();
if (isAppExist_) {
RemoveDataPreloadHapFiles(bundleName_);
}
RemoveOldGroupDirs();
RemoveOldExtensionDirs();
/* process quick fix when install new moudle */
@ -1630,6 +1652,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall(
}
#endif
LOG_D(BMS_TAG_INSTALLER, "finish to process %{public}s bundle uninstall", bundleName.c_str());
RemoveDataPreloadHapFiles(bundleName);
// remove drive so file
std::shared_ptr driverInstaller = std::make_shared<DriverInstaller>();
@ -1794,6 +1817,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall(
return result;
}
RemoveDataPreloadHapFiles(bundleName);
if (oldInfo.IsPreInstallApp()) {
LOG_I(BMS_TAG_INSTALLER, "%{public}s detected, Marking as uninstalled", bundleName.c_str());
MarkPreInstallState(bundleName, true);
@ -1981,7 +2005,13 @@ ErrCode BaseBundleInstaller::InnerProcessInstallByPreInstallInfo(
innerInstallParam.isPreInstallApp = true;
innerInstallParam.removable = preInstallBundleInfo.IsRemovable();
innerInstallParam.copyHapToInstallPath = false;
return ProcessBundleInstall(pathVec, innerInstallParam, preInstallBundleInfo.GetAppType(), uid);
innerInstallParam.isDataPreloadHap = IsDataPreloadHap(pathVec.front());
ErrCode resultCode = ProcessBundleInstall(pathVec, innerInstallParam, preInstallBundleInfo.GetAppType(), uid);
if (resultCode != ERR_OK && innerInstallParam.isDataPreloadHap) {
LOG_E(BMS_TAG_INSTALLER, "set parameter BMS_DATA_PRELOAD false");
OHOS::system::SetParameter(ServiceConstants::BMS_DATA_PRELOAD, BMS_FALSE);
}
return resultCode;
}
ErrCode BaseBundleInstaller::RemoveBundle(InnerBundleInfo &info, bool isKeepData)
@ -3321,6 +3351,45 @@ ErrCode BaseBundleInstaller::DeleteArkProfile(const std::string &bundleName, int
return InstalldClient::GetInstance()->RemoveDir(arkProfilePath);
}
bool BaseBundleInstaller::RemoveDataPreloadHapFiles(const std::string &bundleName) const
{
if (dataMgr_ == nullptr) {
LOG_E(BMS_TAG_INSTALLER, "null dataMgr_");
return false;
}
PreInstallBundleInfo preInstallBundleInfo;
preInstallBundleInfo.SetBundleName(bundleName);
if (!dataMgr_->GetPreInstallBundleInfo(bundleName, preInstallBundleInfo)) {
LOG_I(BMS_TAG_INSTALLER, "no PreInstallBundleInfo(%{public}s) in db", bundleName.c_str());
return true;
}
if (preInstallBundleInfo.GetBundlePaths().empty()) {
LOG_W(BMS_TAG_INSTALLER, "path is empty , bundleName: %{public}s", bundleName.c_str());
return false;
}
auto preinstalledAppPath = preInstallBundleInfo.GetBundlePaths().front();
LOG_D(BMS_TAG_INSTALLER, "removeDataPreloadHapFiles %{public}s", preinstalledAppPath.c_str());
if (IsDataPreloadHap(preinstalledAppPath)) {
std::filesystem::path apFilePath(preinstalledAppPath);
std::string delDir = apFilePath.parent_path().string();
if (InstalldClient::GetInstance()->RemoveDir(delDir) != ERR_OK) {
LOG_E(BMS_TAG_INSTALLER, "removeDir failed :%{public}s", delDir.c_str());
}
if (!dataMgr_->DeletePreInstallBundleInfo(bundleName, preInstallBundleInfo)) {
LOG_E(BMS_TAG_INSTALLER, "deletePreInfoInDb bundle %{public}s failed", bundleName.c_str());
}
}
return true;
}
bool BaseBundleInstaller::IsDataPreloadHap(const std::string &path) const
{
return path.find(DATA_PRELOAD_APP) == 0;
}
ErrCode BaseBundleInstaller::ExtractModule(InnerBundleInfo &info, const std::string &modulePath)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
@ -5282,7 +5351,7 @@ ErrCode BaseBundleInstaller::VerifyCodeSignatureForNativeFiles(InnerBundleInfo &
codeSignatureParam.isEnterpriseBundle = isEnterpriseBundle_;
codeSignatureParam.isInternaltestingBundle = isInternaltestingBundle_;
codeSignatureParam.appIdentifier = appIdentifier_;
codeSignatureParam.isPreInstalledBundle = info.IsPreInstallApp();
codeSignatureParam.isPreInstalledBundle = IsDataPreloadHap(modulePath_) ? false : info.IsPreInstallApp();
codeSignatureParam.isCompileSdkOpenHarmony = (compileSdkType == COMPILE_SDK_TYPE_OPEN_HARMONY);
return InstalldClient::GetInstance()->VerifyCodeSignature(codeSignatureParam);
}
@ -5317,7 +5386,7 @@ ErrCode BaseBundleInstaller::VerifyCodeSignatureForHap(const std::unordered_map<
codeSignatureParam.isInternaltestingBundle = isInternaltestingBundle_;
codeSignatureParam.appIdentifier = appIdentifier_;
codeSignatureParam.isCompileSdkOpenHarmony = (compileSdkType == COMPILE_SDK_TYPE_OPEN_HARMONY);
codeSignatureParam.isPreInstalledBundle = (iter->second).IsPreInstallApp();
codeSignatureParam.isPreInstalledBundle = IsDataPreloadHap(realHapPath) ? false : (iter->second).IsPreInstallApp();
return InstalldClient::GetInstance()->VerifyCodeSignatureForHap(codeSignatureParam);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -89,6 +89,7 @@ constexpr const char* HSP_VERSION_PREFIX = "v";
constexpr const char* OTA_FLAG = "otaFlag";
// pre bundle profile
constexpr const char* DEFAULT_PRE_BUNDLE_ROOT_DIR = "/system";
constexpr const char* DEFAULT_DATA_PRE_BUNDLE_DIR = "/app_list.json";
constexpr const char* PRODUCT_SUFFIX = "/etc/app";
constexpr const char* MODULE_UPDATE_PRODUCT_SUFFIX = "/etc/app/module_update";
constexpr const char* INSTALL_LIST_CONFIG = "/install_list.json";
@ -677,6 +678,14 @@ void BMSEventHandler::ParsePreBundleProFile(const std::string &dir)
dir + EXTENSION_TYPE_LIST_CONFIG, extensiontype_);
bundleParser.ParsePreInstallConfig(
dir + SHARED_BUNDLES_INSTALL_LIST_CONFIG, installList_);
std::string oldSystemFingerprint = GetOldSystemFingerprint();
if (oldSystemFingerprint.empty()) {
LOG_W(BMS_TAG_DEFAULT, "only scan app_list.json on first startup");
bundleParser.ParsePreAppListConfig(dir + DEFAULT_DATA_PRE_BUNDLE_DIR, installList_);
} else {
LOG_W(BMS_TAG_DEFAULT, "data preload app is not support OTA");
}
}
void BMSEventHandler::GetPreInstallDir(std::vector<std::string> &bundleDirs)
@ -1063,6 +1072,8 @@ void BMSEventHandler::ProcessSystemBundleInstall(
installParam.removable = preScanInfo.removable;
installParam.needSavePreInstallInfo = true;
installParam.copyHapToInstallPath = false;
installParam.isDataPreloadHap = preScanInfo.isDataPreloadHap;
installParam.appIdentifier = preScanInfo.appIdentifier;
installParam.preinstallSourceFlag = ApplicationInfoFlag::FLAG_BOOT_INSTALLED;
SystemBundleInstaller installer;
ErrCode ret = installer.InstallSystemBundle(preScanInfo.bundleDir, installParam, appType);

View File

@ -19,8 +19,11 @@
#include <sstream>
#include "bundle_profile.h"
#include "bundle_service_constants.h"
#include "default_permission_profile.h"
#include "module_profile.h"
#include "parameter.h"
#include "parameters.h"
#include "pre_bundle_profile.h"
#include "rpcid_decode/syscap_tool.h"
#include "securec.h"
@ -230,6 +233,24 @@ ErrCode BundleParser::ParsePreInstallConfig(
return preBundleProfile.TransformTo(jsonBuf, scanInfos);
}
ErrCode BundleParser::ParsePreAppListConfig(const std::string &configFile, std::set<PreScanInfo> &scanAppInfos) const
{
APP_LOGD("parse preAppListInstallConfig from %{public}s", configFile.c_str());
nlohmann::json jsonBuf;
if (!ReadFileIntoJson(configFile, jsonBuf)) {
APP_LOGE_NOFUNC("parse file %{public}s failed", configFile.c_str());
return ERR_APPEXECFWK_PARSE_FILE_FAILED;
}
PreBundleProfile preBundleProfile;
ErrCode ret = preBundleProfile.TransformToAppList(jsonBuf, scanAppInfos);
if (ret != ERR_OK) {
APP_LOGE_NOFUNC("set parameter BMS_DATA_PRELOAD false");
OHOS::system::SetParameter(ServiceConstants::BMS_DATA_PRELOAD, "false");
}
return ret;
}
ErrCode BundleParser::ParsePreUnInstallConfig(
const std::string &configFile,
std::set<std::string> &uninstallList) const

View File

@ -33,6 +33,7 @@ namespace OHOS {
namespace AppExecFwk {
std::atomic_uint g_installedHapNum = 0;
constexpr const char* ARK_PROFILE_PATH = "/data/local/ark-profile/";
constexpr const char* DATA_PRELOAD_APP = "/data/preload/app/";
constexpr uint8_t FACTOR = 8;
constexpr uint8_t INTERVAL = 6;
constexpr const char* QUICK_FIX_APP_PATH = "/data/update/quickfix/app/temp/cold";
@ -157,6 +158,11 @@ void BundleUserMgrHostImpl::OnCreateNewUser(int32_t userId, const std::vector<st
installParam.isPreInstallApp = !info.GetIsNonPreDriverApp();
installParam.installFlag = InstallFlag::NORMAL;
installParam.preinstallSourceFlag = ApplicationInfoFlag::FLAG_BOOT_INSTALLED;
if (!info.GetBundlePaths().empty() && (info.GetBundlePaths().front().find(DATA_PRELOAD_APP) == 0) &&
userId != Constants::START_USERID) {
APP_LOGW("data preload app only install in 100 ,bundleName: %{public}s", info.GetBundleName().c_str());
continue;
}
sptr<UserReceiverImpl> userReceiverImpl(
new (std::nothrow) UserReceiverImpl(info.GetBundleName(), needReinstall));
userReceiverImpl->SetBundlePromise(bundlePromise);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2024 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
@ -21,11 +21,13 @@ namespace {
constexpr int8_t COMMON_PRIORITY = 0;
constexpr int8_t HIGH_PRIORITY = 1;
constexpr const char* INSTALL_LIST = "install_list";
constexpr const char* APP_LIST = "app_list";
constexpr const char* UNINSTALL_LIST = "uninstall_list";
constexpr const char* EXTENSION_TYPE = "extensionType";
constexpr const char* RECOVER_LIST = "recover_list";
constexpr const char* APP_DIR = "app_dir";
constexpr const char* REMOVABLE = "removable";
constexpr const char* APPIDENTIFIER = "appIdentifier";
constexpr const char* BUNDLE_NAME = "bundleName";
constexpr const char* TYPE_NAME = "name";
constexpr const char* KEEP_ALIVE = "keepAlive";
@ -36,6 +38,7 @@ constexpr const char* APP_SIGNATURE = "app_signature";
constexpr const char* ASSOCIATED_WAKE_UP = "associatedWakeUp";
constexpr const char* RESOURCES_PATH_1 = "/app/ohos.global.systemres";
constexpr const char* RESOURCES_PATH_2 = "/app/SystemResources";
constexpr const char* DATA_PRELOAD_APP = "/data/preload/app/";
constexpr const char* ALLOW_APP_DATA_NOT_CLEARED = "allowAppDataNotCleared";
constexpr const char* ALLOW_APP_MULTI_PROCESS = "allowAppMultiProcess";
constexpr const char* ALLOW_APP_DESKTOP_ICON_HIDE = "allowAppDesktopIconHide";
@ -120,6 +123,61 @@ ErrCode PreBundleProfile::TransformTo(
return result;
}
ErrCode PreBundleProfile::TransformToAppList(const nlohmann::json &jsonBuf, std::set<PreScanInfo> &scanAppInfos) const
{
if (jsonBuf.is_discarded()) {
return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
}
if (jsonBuf.find(APP_LIST) == jsonBuf.end()) {
return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
}
auto arrays = jsonBuf.at(APP_LIST);
if (!arrays.is_array() || arrays.empty()) {
APP_LOGE("value is not array");
return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
}
int32_t result = ERR_OK;
PreScanInfo preScanInfo;
for (const auto &array : arrays) {
if (!array.is_object()) {
APP_LOGE("array is not json object");
return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
}
preScanInfo.Reset();
const auto &jsonObjectEnd = array.end();
int32_t parseResult = ERR_OK;
BMSJsonUtil::GetStrValueIfFindKey(array, jsonObjectEnd, APP_DIR, preScanInfo.bundleDir, true, parseResult);
BMSJsonUtil::GetStrValueIfFindKey(
array, jsonObjectEnd, APPIDENTIFIER, preScanInfo.appIdentifier, true, parseResult);
preScanInfo.priority = COMMON_PRIORITY;
preScanInfo.isDataPreloadHap = (preScanInfo.bundleDir.find(DATA_PRELOAD_APP) == 0);
if (!preScanInfo.isDataPreloadHap || preScanInfo.bundleDir.empty() || preScanInfo.appIdentifier.empty()) {
APP_LOGE("set parameter BMS_DATA_PRELOAD false");
result = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP;
continue;
}
if (parseResult != ERR_OK) {
APP_LOGE("parse from install json failed, error %{public}d", parseResult);
result = parseResult;
continue;
}
auto iter = std::find(scanAppInfos.begin(), scanAppInfos.end(), preScanInfo);
if (iter != scanAppInfos.end()) {
APP_LOGD("replace old preScanInfo(%{public}s)", preScanInfo.bundleDir.c_str());
scanAppInfos.erase(iter);
}
scanAppInfos.insert(preScanInfo);
}
return result;
}
ErrCode PreBundleProfile::TransformTo(
const nlohmann::json &jsonBuf,
std::set<std::string> &uninstallList) const

View File

@ -1921,6 +1921,35 @@ HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1800, Function | SmallTest
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.number: baseBundleInstaller_1900
* @tc.name: test RemoveDataPreloadHapFiles
* @tc.desc: 1.Test the RemoveDataPreloadHapFiles of BaseBundleInstaller
*/
HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_1900, Function | SmallTest | Level0)
{
BaseBundleInstaller installer;
installer.dataMgr_ = nullptr;
bool ret = installer.RemoveDataPreloadHapFiles(BUNDLE_NAME);
EXPECT_EQ(ret, false);
installer.dataMgr_ = GetBundleDataMgr();
ret = installer.RemoveDataPreloadHapFiles(BUNDLE_NAME);
EXPECT_EQ(ret, true);
}
/**
* @tc.number: baseBundleInstaller_2000
* @tc.name: test IsDataPreloadHap
* @tc.desc: 1.Test the IsDataPreloadHap of BaseBundleInstaller
*/
HWTEST_F(BmsBundleInstallerTest, baseBundleInstaller_2000, Function | SmallTest | Level0)
{
BaseBundleInstaller installer;
bool ret = installer.IsDataPreloadHap(SYSTEMFIEID_HAP_PATH);
EXPECT_EQ(ret, false);
}
/**
* @tc.number: baseBundleInstaller_2100
* @tc.name: test baseBundleInstaller

View File

@ -155,6 +155,45 @@ const std::string TEST_URI_HTTP = "http://www.test.com";
const std::string META_DATA_SHORTCUTS_NAME = "ohos.ability.shortcuts";
constexpr int32_t MOCK_BUNDLE_MGR_EXT_FLAG = 10;
const std::string BMS_EXTENSION_PATH = "/system/etc/app/bms-extensions.json";
const nlohmann::json APP_LIST0 = R"(
{
"app_list": [
{
"app_dir":"/data/preload/app/app_dir",
"appIdentifier":"5765880207853134833"
}
]
}
)"_json;
const nlohmann::json APP_LIST1 = R"(
{
"app_list": [
{
"app_dir":"app_dir",
"appIdentifier":"5765880207853134833"
}
]
}
)"_json;
const nlohmann::json APP_LIST2 = R"(
{
"app_list": [
{
"app_dir1":"app_dir",
"appIdentifier":""
}
]
}
)"_json;
const nlohmann::json APP_LIST3 = R"(
{
"app_list":
{
"app_dir1":"app_dir",
"appIdentifier1":"5765880207853134833"
}
}
)"_json;
const nlohmann::json INSTALL_LIST = R"(
{
"install_list": [
@ -3951,6 +3990,71 @@ HWTEST_F(BmsBundleDataMgrTest, PreBundleProfile_1600, Function | SmallTest | Lev
EXPECT_EQ(res, ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR);
}
/**
* @tc.number: PreBundleProfile_1700
* @tc.name: test TransformToAppList
* @tc.desc: 1. call TransformToAppList, return ERR_OK
*/
HWTEST_F(BmsBundleDataMgrTest, PreBundleProfile_1700, Function | SmallTest | Level1)
{
PreBundleProfile preBundleProfile;
std::set<PreScanInfo> scanInfos;
ErrCode res = preBundleProfile.TransformToAppList(APP_LIST0, scanInfos);
EXPECT_EQ(res, ERR_OK);
}
/**
* @tc.number: PreBundleProfile_1900
* @tc.name: test TransformToAppList
* @tc.desc: 1. call TransformToAppList, return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR
*/
HWTEST_F(BmsBundleDataMgrTest, PreBundleProfile_1900, Function | SmallTest | Level1)
{
PreBundleProfile preBundleProfile;
std::set<PreScanInfo> scanInfos;
ErrCode res = preBundleProfile.TransformToAppList(INSTALL_LIST, scanInfos);
EXPECT_EQ(res, ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR);
}
/**
* @tc.number: PreBundleProfile_2000
* @tc.name: test TransformToAppList
* @tc.desc: 1. call TransformToAppList, return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR
*/
HWTEST_F(BmsBundleDataMgrTest, PreBundleProfile_2000, Function | SmallTest | Level1)
{
PreBundleProfile preBundleProfile;
std::set<PreScanInfo> scanInfos;
ErrCode res = preBundleProfile.TransformToAppList(APP_LIST3, scanInfos);
EXPECT_EQ(res, ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR);
}
/**
* @tc.number: PreBundleProfile_2100
* @tc.name: test TransformToAppList
* @tc.desc: 1. call TransformToAppList, return ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP
*/
HWTEST_F(BmsBundleDataMgrTest, PreBundleProfile_2100, Function | SmallTest | Level1)
{
PreBundleProfile preBundleProfile;
std::set<PreScanInfo> scanInfos;
ErrCode res = preBundleProfile.TransformToAppList(APP_LIST1, scanInfos);
EXPECT_EQ(res, ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP);
}
/**
* @tc.number: PreBundleProfile_2200
* @tc.name: test TransformToAppList
* @tc.desc: 1. call TransformToAppList, return ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP
*/
HWTEST_F(BmsBundleDataMgrTest, PreBundleProfile_2200, Function | SmallTest | Level1)
{
PreBundleProfile preBundleProfile;
std::set<PreScanInfo> scanInfos;
ErrCode res = preBundleProfile.TransformToAppList(APP_LIST2, scanInfos);
EXPECT_EQ(res, ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP);
}
/**
* @tc.number: SetExtNameOrMIMEToApp_0001
* @tc.name: SetExtNameOrMIMEToApp

View File

@ -3110,4 +3110,34 @@ HWTEST_F(BmsBundleParserTest, BundleParser_2100, Function | MediumTest | Level1)
auto ret = bundleParser.CheckRouterData(data);
EXPECT_FALSE(ret);
}
/**
* @tc.number: BundleParser_2200
* @tc.name: Test ParsePreAppListConfig
* @tc.desc: test the interface of BundleParser
*/
HWTEST_F(BmsBundleParserTest, BundleParser_2200, Function | MediumTest | Level1)
{
BundleParser bundleParser;
std::string configFile;
std::set<PreScanInfo> scanInfos;
ErrCode ret = bundleParser.ParsePreAppListConfig(configFile, scanInfos);
EXPECT_EQ(ret, ERR_APPEXECFWK_PARSE_FILE_FAILED);
}
/**
* @tc.number: BundleParser_2300
* @tc.name: Test ParsePreAppListConfig
* @tc.desc: test the interface of BundleParser
*/
HWTEST_F(BmsBundleParserTest, BundleParser_2300, Function | MediumTest | Level1)
{
BundleParser bundleParser;
std::string configFile = "config.cfg";
std::set<PreScanInfo> scanInfos;
ErrCode ret = bundleParser.ParsePreAppListConfig(configFile, scanInfos);
EXPECT_EQ(ret, ERR_APPEXECFWK_PARSE_FILE_FAILED);
}
} // OHOS