Merge branch '7.16' into dev

This commit is contained in:
laizeyuan 2024-07-19 17:24:36 +08:00
commit 7f0273b365
59 changed files with 2301 additions and 59 deletions

View File

@ -70,6 +70,7 @@ declare_args() {
bms_device_info_manager_part_enabled = true
app_domain_verify_enabled = true
device_usage_statistics_enabled = true
dfx_sigdump_handler_enabled = true
if (defined(global_parts_info) &&
!defined(global_parts_info.resourceschedule_device_usage_statistics)) {
@ -182,6 +183,11 @@ declare_args() {
!defined(global_parts_info.bundlemanager_app_domain_verify)) {
app_domain_verify_enabled = false
}
if (defined(global_parts_info) &&
!defined(global_parts_info.hiviewdfx_faultloggerd)) {
dfx_sigdump_handler_enabled = false
}
}
print("bundle_framework_power_mgr_enable = " +

View File

@ -52,6 +52,7 @@
"display_manager",
"ecological_rule_manager",
"eventhandler",
"faultloggerd",
"ffrt",
"hicollie",
"hisysevent",
@ -93,7 +94,7 @@
"build": {
"sub_component": [
"//foundation/bundlemanager/bundle_framework:bms_target",
"//foundation/bundlemanager/bundle_framework/etc:bms.para.dac"
"//foundation/bundlemanager/bundle_framework/etc:bms_para"
],
"inner_kits": [
{

View File

@ -13,6 +13,20 @@
import("//build/ohos.gni")
group("bms_para") {
deps = [
":bms.para",
":bms.para.dac",
]
}
ohos_prebuilt_etc("bms.para") {
source = "bms.para"
part_name = "bundle_framework"
subsystem_name = "bundlemanager"
module_install_dir = "etc/param"
}
ohos_prebuilt_etc("bms.para.dac") {
source = "bms.para.dac"
part_name = "bundle_framework"

14
etc/bms.para Normal file
View File

@ -0,0 +1,14 @@
# Copyright (c) 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
#
# 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.
bootevent.bms.main.bundles.ready = false

View File

@ -13,4 +13,5 @@
const.bms.optimizing_apps.switch = foundation:foundation:0755
bms.optimizing_apps.status = foundation:foundation:0755
bootevent.bms.main.bundles.ready = foundation:foundation:0755

View File

@ -139,6 +139,7 @@ enum {
ERR_APPEXECFWK_INSTALL_FAILED_CHECK_HAP_HASH_PARAM = 8519758,
ERR_BUNDLEMANAGER_INSTALL_FAILED_SIGNATURE_EXTENSION_NOT_EXISTED = 8519759,
ERR_APPEXECFWK_INSTALL_CHECK_ENCRYPTION_FAILED = 8519760,
ERR_APPEXECFWK_INSTALLD_SERVICE_DIED = 8519761,
ERR_APPEXECFWK_INSTALL_ENTERPRISE_BUNDLE_NOT_ALLOWED = 8519780,
ERR_APPEXECFWK_INSTALL_SELF_UPDATE_NOT_MDM = 8519781,

View File

@ -416,7 +416,7 @@ bool Skill::MatchUri(const std::string &uriString, const SkillUri &skillUri) con
if (regex_match(optParamUri, regex)) {
return true;
}
} catch(...) {
} catch (const std::regex_error& e) {
APP_LOGE("regex error");
}
}

View File

@ -33,6 +33,7 @@ ohos_shared_library("bundle_ndk") {
cflags_cc = [ "-Os" ]
use_exceptions = true
use_rtti = true
deps = [
"${base_path}:appexecfwk_base",
"${common_path}:libappexecfwk_common",

View File

@ -508,6 +508,11 @@ ohos_shared_library("installs") {
cflags += [ "-DWITH_SELINUX" ]
}
if (dfx_sigdump_handler_enabled) {
external_deps += [ "faultloggerd:dfx_sigdump_handler" ]
defines += [ "DFX_SIGDUMP_HANDLER_ENABLE" ]
}
install_enable = true
subsystem_name = "bundlemanager"
part_name = "bundle_framework"

View File

@ -173,6 +173,7 @@ bundle_mgr_source = [
"${services_path}/bundlemgr/src/app_provision_info/app_provision_info_manager.cpp",
"${services_path}/bundlemgr/src/app_provision_info/app_provision_info_rdb.cpp",
"${services_path}/bundlemgr/src/bms_extension/bms_extension_client.cpp",
"${services_path}/bundlemgr/src/bms_key_event_mgr.cpp",
"${services_path}/bundlemgr/src/bms_param.cpp",
"${services_path}/bundlemgr/src/bundle_common_event_mgr.cpp",
"${services_path}/bundlemgr/src/bundle_data_mgr.cpp",

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 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
*
* 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_SERVICES_BMS_KEY_EVENT_MGR_H
#define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BMS_KEY_EVENT_MGR_H
#include <string>
namespace OHOS {
namespace AppExecFwk {
class BmsKeyEventMgr {
public:
static void ProcessMainBundleStatusFinally();
static void ProcessMainBundleInstallFailed(const std::string &bundleName, int32_t errCode);
private:
static std::atomic_uint isMainBundleReady_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BMS_KEY_EVENT_MGR_H

View File

@ -594,6 +594,7 @@ private:
void SendBundleUpdateFailedEvent(const BundleInfo &bundleInfo);
void UpdatePreinstallDBForUninstalledBundle(const std::string &bundleName,
const std::unordered_map<std::string, InnerBundleInfo> &innerBundleInfos);
void InnerProcessRebootUninstallWrongBundle();
// Used to save the information parsed by Hap in the scanned directory.
std::map<std::string, std::unordered_map<std::string, InnerBundleInfo>> hapParseInfoMap_;
// Used to save application information that already exists in the Db.

View File

@ -69,8 +69,6 @@ private:
*/
bool InitDir(const std::string &path);
void DisableDfx();
private:
bool isReady_ = false;
sptr<InstalldHostImpl> hostImpl_;

View File

@ -24,6 +24,7 @@
#include "nocopyable.h"
#include "singleton.h"
#include "app_log_wrapper.h"
#include "appexecfwk_errors.h"
#include "bundle_constants.h"
#include "ipc/installd_interface.h"
@ -242,10 +243,26 @@ private:
template<typename F, typename... Args>
ErrCode CallService(F func, Args&&... args)
{
if (!GetInstalldProxy()) {
return ERR_APPEXECFWK_INSTALLD_GET_PROXY_ERROR;
int32_t maxRetryTimes = 2;
ErrCode errCode = ERR_APPEXECFWK_INSTALLD_SERVICE_DIED;
for (int32_t retryTimes = 0; retryTimes < maxRetryTimes; retryTimes++) {
if (!GetInstalldProxy()) {
return ERR_APPEXECFWK_INSTALLD_GET_PROXY_ERROR;
}
{
std::lock_guard<std::mutex> lock(mutex_);
if (installdProxy_ != nullptr) {
errCode = (installdProxy_->*func)(std::forward<Args>(args)...);
}
}
if (errCode == ERR_APPEXECFWK_INSTALLD_SERVICE_DIED) {
APP_LOGE("CallService failed, retry times: %{public}d", retryTimes + 1);
ResetInstalldProxy();
} else {
return errCode;
}
}
return (installdProxy_->*func)(std::forward<Args>(args)...);
return errCode;
}
private:

View File

@ -73,6 +73,8 @@ public:
* @return Returns true if this function called successfully; returns false otherwise.
*/
bool UninstallSystemBundle(const std::string &bundleName);
bool UninstallSystemBundle(const std::string &bundleName, const InstallParam &installParam);
/**
* @brief Deleting apps while retaining user data.
* @param bundleName Indicates the bundle name.

View File

@ -108,6 +108,7 @@ constexpr const char* BMS_TRUE = "true";
const int32_t BMS_ACTIVATION_LOCK_VAL_LEN = 20;
const std::set<std::string> SINGLETON_WHITE_LIST = {
"com.ohos.formrenderservice",
"com.ohos.sceneboard",
"com.ohos.callui",
"com.ohos.mms",

View File

@ -135,7 +135,7 @@ bool BaseExtractor::IsStageBasedModel(std::string abilityName)
{
auto &entryMap = zipFile_.GetAllEntries();
std::vector<std::string> splitStrs;
OHOS::SplitStr(abilityName, "", splitStrs);
OHOS::SplitStr(abilityName, ".", splitStrs);
std::string name = splitStrs.empty() ? abilityName : splitStrs.back();
std::string entry = "assets/js/" + name + "/" + name + ".js";
bool isStageBasedModel = entryMap.find(entry) != entryMap.end();

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 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
*
* 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 "bms_key_event_mgr.h"
#include "app_log_tag_wrapper.h"
#include "inner_bundle_info.h"
#include "parameters.h"
#include <set>
namespace OHOS {
namespace AppExecFwk {
namespace {
const std::string BOOTEVENT_BMS_MAIN_BUNDLES_READY = "bootevent.bms.main.bundles.ready";
const std::string MAIN_BUNDLE_NAME_SCENE_BOARD = "com.ohos.sceneboard";
const std::string MAIN_BUNDLE_NAME_SCENE_BOARD_PATH = "/system/app/SceneBoard";
const std::set<std::string> MAIN_BUNDLES_SET = {
MAIN_BUNDLE_NAME_SCENE_BOARD,
MAIN_BUNDLE_NAME_SCENE_BOARD_PATH
};
constexpr const char *BMS_PARAM_TRUE = "true";
constexpr const char *BMS_PARAM_FALSE = "false";
}
std::atomic_uint BmsKeyEventMgr::isMainBundleReady_ = true;
void BmsKeyEventMgr::ProcessMainBundleStatusFinally()
{
LOG_I(BMS_TAG_DEFAULT, "ProcessMainBundleStatus start");
if (isMainBundleReady_) {
if (!system::SetParameter(BOOTEVENT_BMS_MAIN_BUNDLES_READY, BMS_PARAM_TRUE)) {
LOG_E(BMS_TAG_DEFAULT, "bms set parameter failed");
}
} else {
LOG_E(BMS_TAG_DEFAULT, "ProcessMainBundleStatus main bundle not ready");
}
LOG_I(BMS_TAG_DEFAULT, "ProcessMainBundleStatus end");
}
void BmsKeyEventMgr::ProcessMainBundleInstallFailed(const std::string &bundleName, int32_t errCode)
{
if (MAIN_BUNDLES_SET.find(bundleName) == MAIN_BUNDLES_SET.end()) {
return;
}
LOG_I(BMS_TAG_DEFAULT, "bundleName:%{public}s install failed, errCode:%{public}d", bundleName.c_str(), errCode);
isMainBundleReady_ = false;
if (!system::SetParameter(BOOTEVENT_BMS_MAIN_BUNDLES_READY, BMS_PARAM_FALSE)) {
LOG_E(BMS_TAG_DEFAULT, "bms set parameter failed");
}
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -44,6 +44,8 @@ constexpr const char* SANDBOX_APP_INDEX = "sandbox_app_index";
constexpr const char* BUNDLE_TYPE = "bundleType";
constexpr const char* ATOMIC_SERVICE_MODULE_UPGRADE = "atomicServiceModuleUpgrade";
constexpr const char* BUNDLE_RESOURCE_CHANGE_TYPE = "bundleResourceChangeType";
constexpr const char* TYPE = "type";
constexpr const char* RESULT_CODE = "resultCode";
}
BundleCommonEventMgr::BundleCommonEventMgr()
@ -137,6 +139,8 @@ void BundleCommonEventMgr::SetNotifyWant(OHOS::AAFwk::Want& want, const NotifyBu
want.SetParam(APP_INDEX, installResult.appIndex);
want.SetParam(BUNDLE_TYPE, installResult.bundleType);
want.SetParam(ATOMIC_SERVICE_MODULE_UPGRADE, installResult.atomicServiceModuleUpgrade);
want.SetParam(TYPE, static_cast<int32_t>(installResult.type));
want.SetParam(RESULT_CODE, installResult.resultCode);
}
ErrCode BundleCommonEventMgr::NotifySandboxAppStatus(const InnerBundleInfo &info, int32_t uid, int32_t userId,

View File

@ -1525,7 +1525,7 @@ void BundleDataMgr::GetMatchAbilityInfos(const Want &want, int32_t flags, const
}
if (CheckAbilityInfoFlagExist(flags, GET_ABILITY_INFO_WITH_APPLICATION)) {
info.GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT,
userId, abilityinfo.applicationInfo);
userId, abilityinfo.applicationInfo, appIndex);
}
if (!CheckAbilityInfoFlagExist(flags, GET_ABILITY_INFO_WITH_PERMISSION)) {
abilityinfo.permissions.clear();

View File

@ -29,6 +29,7 @@
#include "app_provision_info_manager.h"
#include "app_privilege_capability.h"
#include "app_service_fwk_installer.h"
#include "bms_key_event_mgr.h"
#include "bundle_install_checker.h"
#include "bundle_mgr_host_impl.h"
#include "bundle_mgr_service.h"
@ -357,6 +358,8 @@ void BMSEventHandler::BundleRebootStartEvent()
ProcessRebootQuickFixUnInstallAndRecover(QUICK_FIX_APP_RECOVER_FILE);
CheckALLResourceInfo();
}
// need process main bundle status
BmsKeyEventMgr::ProcessMainBundleStatusFinally();
if (IsModuleUpdate()) {
HandleModuleUpdate();
@ -1120,6 +1123,7 @@ void BMSEventHandler::ProcessRebootBundle()
ProcessRebootDeleteArkAp();
LoadAllPreInstallBundleInfos();
BundleResourceHelper::DeleteNotExistResourceInfo();
InnerProcessRebootUninstallWrongBundle();
ProcessRebootBundleInstall();
ProcessRebootBundleUninstall();
ProcessRebootQuickFixBundleInstall(QUICK_FIX_APP_PATH, true);
@ -1674,6 +1678,7 @@ void BMSEventHandler::InnerProcessRebootBundleInstall(
std::unordered_map<std::string, InnerBundleInfo> infos;
if (!ParseHapFiles(scanPathIter, infos) || infos.empty()) {
LOG_E(BMS_TAG_DEFAULT, "obtain bundleinfo failed : %{public}s ", scanPathIter.c_str());
BmsKeyEventMgr::ProcessMainBundleInstallFailed(scanPathIter, ERR_APPEXECFWK_PARSE_UNEXPECTED);
SavePreInstallException(scanPathIter);
continue;
}
@ -3424,5 +3429,23 @@ void BMSEventHandler::ProcessRebootQuickFixUnInstallAndRecover(const std::string
}
LOG_I(BMS_TAG_DEFAULT, "ProcessRebootQuickFixUnInstallAndRecover end");
}
void BMSEventHandler::InnerProcessRebootUninstallWrongBundle()
{
InstallParam installParam;
installParam.userId = Constants::DEFAULT_USERID;
installParam.noSkipsKill = false;
installParam.needSendEvent = false;
std::vector<std::string> wrongBundleNameList;
wrongBundleNameList.emplace_back(Constants::SCENE_BOARD_BUNDLE_NAME);
for (const auto &bundle : wrongBundleNameList) {
SystemBundleInstaller installer;
if (!installer.UninstallSystemBundle(bundle, installParam)) {
LOG_W(BMS_TAG_DEFAULT, "OTA uninstall bundle %{public}s userId %{public}d error", bundle.c_str(),
installParam.userId);
}
}
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -17,6 +17,7 @@
#include "app_log_wrapper.h"
#include "bms_extension_data_mgr.h"
#include "bms_key_event_mgr.h"
#include "bundle_mgr_service.h"
#include "bundle_mgr_service_event_handler.h"
#include "bundle_permission_mgr.h"
@ -85,6 +86,7 @@ public:
if (resultCode != ERR_OK && resultCode !=
ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON && needReInstall_) {
APP_LOGI("needReInstall bundleName: %{public}s", bundleName_.c_str());
BmsKeyEventMgr::ProcessMainBundleInstallFailed(bundleName_, resultCode);
SavePreInstallException(bundleName_);
}
}
@ -213,6 +215,8 @@ void BundleUserMgrHostImpl::AfterCreateNewUser(int32_t userId)
{
if (userId == Constants::START_USERID) {
DelayedSingleton<BundleMgrService>::GetInstance()->NotifyBundleScanStatus();
// need process main bundle status
BmsKeyEventMgr::ProcessMainBundleStatusFinally();
}
#ifdef BUNDLE_FRAMEWORK_DEFAULT_APP

View File

@ -236,7 +236,7 @@ std::unordered_map<BMSEventType, void (*)(const EventInfo& eventInfo)>
} },
{ BMSEventType::QUERY_OF_CONTINUE_TYPE,
[](const EventInfo& eventInfo) {
InnerSendCpuSceneEvent(eventInfo);
InnerSendQueryOfContinueTypeEvent(eventInfo);
} },
{ BMSEventType::FREE_INSTALL_EVENT,
[](const EventInfo& eventInfo) {

View File

@ -16,7 +16,6 @@
#include "installd/installd_service.h"
#include <chrono>
#include <csignal>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
@ -30,13 +29,16 @@
#include "system_ability_definition.h"
#include "system_ability_helper.h"
#ifdef DFX_SIGDUMP_HANDLER_ENABLE
#include "dfx_sigdump_handler.h"
#endif
using namespace std::chrono_literals;
namespace OHOS {
namespace AppExecFwk {
namespace {
constexpr unsigned int INSTALLD_UMASK = 0000;
constexpr int32_t DFX_SIGNAL = 35;
}
REGISTER_SYSTEM_ABILITY_BY_ID(InstalldService, INSTALLD_SERVICE_ID, true);
@ -63,11 +65,17 @@ void InstalldService::OnStart()
if (!Publish(hostImpl_)) {
LOG_E(BMS_TAG_INSTALLD, "Publish failed");
}
#ifdef DFX_SIGDUMP_HANDLER_ENABLE
InitSigDumpHandler();
#endif
}
void InstalldService::OnStop()
{
Stop();
#ifdef DFX_SIGDUMP_HANDLER_ENABLE
DeinitSigDumpHandler();
#endif
LOG_I(BMS_TAG_INSTALLD, "installd OnStop");
}
@ -128,13 +136,5 @@ void InstalldService::Stop()
isReady_ = false;
LOG_I(BMS_TAG_INSTALLD, "installd service stop successfully");
}
__attribute__((constructor)) void InstalldService::DisableDfx()
{
sigset_t set;
sigemptyset(&set);
sigaddset(&set, DFX_SIGNAL);
sigprocmask(SIG_BLOCK, &set, NULL);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -15,7 +15,6 @@
#include "installd_client.h"
#include "app_log_wrapper.h"
#include "bundle_constants.h"
#include "if_system_ability_manager.h"
#include "installd/installd_load_callback.h"

View File

@ -906,7 +906,7 @@ ErrCode InstalldProxy::TransactInstalldCmd(InstalldInterfaceCode code, MessagePa
if (remote->SendRequest(static_cast<uint32_t>(code), data, reply, option) != OHOS::NO_ERROR) {
LOG_E(BMS_TAG_INSTALLD, "fail to send %{public}u request to service due to transact error", code);
return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
return ERR_APPEXECFWK_INSTALLD_SERVICE_DIED;
}
return reply.ReadInt32();
}

View File

@ -16,6 +16,7 @@
#include "system_bundle_installer.h"
#include "app_log_wrapper.h"
#include "bms_key_event_mgr.h"
#include "bundle_mgr_service.h"
namespace OHOS {
@ -39,6 +40,9 @@ ErrCode SystemBundleInstaller::InstallSystemBundle(
ErrCode result = InstallBundle(filePath, installParam, appType);
if (result != ERR_OK) {
APP_LOGE("install system bundle fail, error: %{public}d", result);
if (result != ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON) {
BmsKeyEventMgr::ProcessMainBundleInstallFailed(filePath, result);
}
}
return result;
}
@ -78,6 +82,9 @@ ErrCode SystemBundleInstaller::OTAInstallSystemBundle(
if ((errCode != ERR_OK) && (errCode != ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON)) {
APP_LOGE("install system bundle fail, error: %{public}d", errCode);
result = errCode;
if (!filePaths.empty()) {
BmsKeyEventMgr::ProcessMainBundleInstallFailed(filePaths[0], result);
}
}
ResetInstallProperties();
}
@ -119,6 +126,7 @@ ErrCode SystemBundleInstaller::OTAInstallSystemBundleNeedCheckUser(
if ((errCode != ERR_OK) && (errCode != ERR_APPEXECFWK_INSTALL_ZERO_USER_WITH_NO_SINGLETON)) {
APP_LOGE("install system bundle %{public}s fail err %{public}d", bundleName.c_str(), errCode);
result = errCode;
BmsKeyEventMgr::ProcessMainBundleInstallFailed(bundleName, result);
}
ResetInstallProperties();
}
@ -207,6 +215,23 @@ bool SystemBundleInstaller::UninstallSystemBundle(const std::string &bundleName,
return true;
}
bool SystemBundleInstaller::UninstallSystemBundle(const std::string &bundleName, const InstallParam &installParam)
{
auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
if (dataMgr == nullptr) {
APP_LOGE("Get dataMgr shared_ptr nullptr");
return false;
}
MarkPreBundleSyeEventBootTag(false);
ErrCode result = UninstallBundle(bundleName, installParam);
if ((result != ERR_OK) && (result != ERR_APPEXECFWK_USER_NOT_INSTALL_HAP)) {
APP_LOGW("uninstall system bundle %{public}s userId %{public}d fail, error: %{public}d", bundleName.c_str(),
installParam.userId, result);
return false;
}
return true;
}
void SystemBundleInstaller::CheckUninstallSystemHsp(const std::string &bundleName)
{
auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();

View File

@ -69,8 +69,6 @@ private:
*/
bool InitDir(const std::string &path);
void DisableDfx();
private:
bool isReady_ = false;
sptr<InstalldHostImpl> hostImpl_;

View File

@ -16,7 +16,6 @@
#include "installd/installd_service.h"
#include <chrono>
#include <csignal>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
@ -29,13 +28,16 @@
#include "system_ability_definition.h"
#include "system_ability_helper.h"
#ifdef DFX_SIGDUMP_HANDLER_ENABLE
#include "dfx_sigdump_handler.h"
#endif
using namespace std::chrono_literals;
namespace OHOS {
namespace AppExecFwk {
namespace {
constexpr unsigned int INSTALLD_UMASK = 0000;
constexpr int32_t DFX_SIGNAL = 35;
}
InstalldService::InstalldService() : SystemAbility(INSTALLD_SERVICE_ID, true)
{
@ -54,11 +56,17 @@ void InstalldService::OnStart()
if (!Publish(hostImpl_)) {
APP_LOGE("Publish failed");
}
#ifdef DFX_SIGDUMP_HANDLER_ENABLE
InitSigDumpHandler();
#endif
}
void InstalldService::OnStop()
{
Stop();
#ifdef DFX_SIGDUMP_HANDLER_ENABLE
DeinitSigDumpHandler();
#endif
APP_LOGI("installd OnStop");
}
@ -122,13 +130,5 @@ void InstalldService::Stop()
isReady_ = false;
APP_LOGI("installd service stop successfully");
}
__attribute__((constructor)) void InstalldService::DisableDfx()
{
sigset_t set;
sigemptyset(&set);
sigaddset(&set, DFX_SIGNAL);
sigprocmask(SIG_BLOCK, &set, NULL);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -64,9 +64,11 @@ const std::string DEPENDENT_NAME = "DependentModule";
const std::string CONTINUE_TYPES = "Test";
const std::string HNPPACKAGE = "hnpPackage";
const std::string HNPPACKAGETYPE = "type";
const std::string URI = "dataability://test";
int32_t state = 0;
int32_t versionCode = 0;
int32_t userId = 1;
int32_t userId2 = 2;
int32_t appIndex = 1;
const int32_t FLAG = 0;
// This field is used to ensure OTA upgrade and cannot be added randomly.
@ -2668,6 +2670,240 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_4300, Function | Smal
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.number: InnerBundleInfo_4400
* @tc.name: Test SetInnerModuleNeedDelete
* @tc.desc: 1.Test the SetInnerModuleNeedDelete of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_4400, Function | SmallTest | Level1)
{
InnerBundleInfo info;
info.innerModuleInfos_.clear();
InnerModuleInfo innerModuleInfo;
innerModuleInfo.moduleName = MODULE_NAME;
info.innerModuleInfos_.insert(std::make_pair(MODULE_NAME, innerModuleInfo));
info.SetInnerModuleNeedDelete(MODULE_NAME, true);
EXPECT_TRUE(info.innerModuleInfos_.at(MODULE_NAME).needDelete);
}
/**
* @tc.number: InnerBundleInfo_4500
* @tc.name: Test SetCloneApplicationEnabled
* @tc.desc: 1.Test the SetCloneApplicationEnabled of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_4500, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
InnerBundleUserInfo innerBundleUserInfo;
bundleInfo.innerBundleUserInfos_.insert(std::make_pair(MODULE_NAME, innerBundleUserInfo));
auto ret = bundleInfo.SetCloneApplicationEnabled(true, appIndex, userId);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_INVALID_USER_ID);
}
/**
* @tc.number: InnerBundleInfo_4600
* @tc.name: Test SetCloneApplicationEnabled
* @tc.desc: 1.Test the SetCloneApplicationEnabled of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_4600, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
InnerBundleUserInfo innerBundleUserInfo;
std::map<std::string, InnerBundleCloneInfo> cloneInfos;
InnerBundleCloneInfo innerBundleCloneInfo;
std::vector<std::string> disabledAbilities;
disabledAbilities.push_back(MODULE_NAME);
innerBundleCloneInfo.disabledAbilities = disabledAbilities;
cloneInfos.insert(std::make_pair(MODULE_NAME, innerBundleCloneInfo));
innerBundleUserInfo.cloneInfos = cloneInfos;
bundleInfo.innerBundleUserInfos_.insert(std::make_pair("_1", innerBundleUserInfo));
auto ret = bundleInfo.SetCloneApplicationEnabled(true, appIndex, userId);
EXPECT_EQ(ret, ERR_APPEXECFWK_SANDBOX_INSTALL_INVALID_APP_INDEX);
}
/**
* @tc.number: InnerBundleInfo_4700
* @tc.name: Test SetCloneApplicationEnabled
* @tc.desc: 1.Test the SetCloneApplicationEnabled of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_4700, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
InnerBundleUserInfo innerBundleUserInfo;
std::map<std::string, InnerBundleCloneInfo> cloneInfos;
InnerBundleCloneInfo innerBundleCloneInfo;
std::vector<std::string> disabledAbilities;
disabledAbilities.push_back("");
innerBundleCloneInfo.disabledAbilities = disabledAbilities;
cloneInfos.insert(std::make_pair("1", innerBundleCloneInfo));
innerBundleUserInfo.cloneInfos = cloneInfos;
bundleInfo.innerBundleUserInfos_.insert(std::make_pair("_1", innerBundleUserInfo));
auto ret = bundleInfo.SetCloneApplicationEnabled(true, appIndex, userId);
EXPECT_EQ(ret, ERR_OK);
}
/**
* @tc.number: InnerBundleInfo_4800
* @tc.name: Test GetQuickFixHqfInfos
* @tc.desc: 1.Test the GetQuickFixHqfInfos of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_4800, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
HqfInfo hqfInfo;
hqfInfo.moduleName = MODULE_NAME;
bundleInfo.hqfInfos_.push_back(hqfInfo);
std::vector<HqfInfo> hqfInfos;
hqfInfos = bundleInfo.GetQuickFixHqfInfos();
EXPECT_FALSE(hqfInfos.empty());
}
/**
* @tc.number: InnerBundleInfo_4900
* @tc.name: Test RemoveOverlayModuleInfo
* @tc.desc: 1.Test the RemoveOverlayModuleInfo of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_4900, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
InnerModuleInfo innerModuleInfo;
bundleInfo.innerModuleInfos_.insert(std::make_pair(MODULE_NAME, innerModuleInfo));
bundleInfo.RemoveOverlayModuleInfo(MODULE_NAME, BUNDLE_NAME, MODULE_NAME);
EXPECT_FALSE(bundleInfo.innerModuleInfos_.empty());
}
/**
* @tc.number: InnerBundleInfo_5000
* @tc.name: Test RemoveOverlayModuleInfo
* @tc.desc: 1.Test the RemoveOverlayModuleInfo of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5000, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
InnerModuleInfo innerModuleInfo;
std::vector<OverlayModuleInfo> overlayModuleInfos;
OverlayModuleInfo overlayModuleInfo;
overlayModuleInfo.bundleName = BUNDLE_NAME;
overlayModuleInfo.moduleName = MODULE_NAME;
overlayModuleInfos.push_back(overlayModuleInfo);
innerModuleInfo.overlayModuleInfo = overlayModuleInfos;
bundleInfo.innerModuleInfos_.insert(std::make_pair(MODULE_NAME, innerModuleInfo));
bundleInfo.RemoveOverlayModuleInfo(MODULE_NAME, BUNDLE_NAME, MODULE_NAME);
EXPECT_FALSE(bundleInfo.innerModuleInfos_.empty());
}
/**
* @tc.number: InnerBundleInfo_5100
* @tc.name: Test KeepOldOverlayConnection
* @tc.desc: 1.Test the KeepOldOverlayConnection of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5100, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
InnerBundleInfo bundleInfoNew;
InnerModuleInfo innerModuleInfo;
InnerModuleInfo innerModuleInfoNew;
std::vector<OverlayModuleInfo> overlayModuleInfos;
OverlayModuleInfo overlayModuleInfo;
overlayModuleInfo.bundleName = BUNDLE_NAME;
overlayModuleInfo.moduleName = MODULE_NAME;
overlayModuleInfos.push_back(overlayModuleInfo);
innerModuleInfo.overlayModuleInfo = overlayModuleInfos;
innerModuleInfo.moduleName = MODULE_NAME;
bundleInfo.innerModuleInfos_.insert(std::make_pair(MODULE_NAME, innerModuleInfo));
bundleInfoNew.innerModuleInfos_.insert(std::make_pair(MODULE_NAME, innerModuleInfoNew));
bundleInfo.KeepOldOverlayConnection(bundleInfoNew);
EXPECT_FALSE(bundleInfoNew.innerModuleInfos_[MODULE_NAME].overlayModuleInfo.empty());
}
/**
* @tc.number: InnerBundleInfo_5200
* @tc.name: Test FindExtensionAbilityInfoByUri
* @tc.desc: 1.Test the FindExtensionAbilityInfoByUri of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5200, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
ExtensionAbilityInfo extensionAbilityInfo;
extensionAbilityInfo.uri = URI;
ExtensionAbilityInfo baseExtensionInfo;
bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, extensionAbilityInfo));
bool ret = bundleInfo.FindExtensionAbilityInfoByUri(URI, baseExtensionInfo);
EXPECT_TRUE(ret);
}
/**
* @tc.number: InnerBundleInfo_5300
* @tc.name: Test FindExtensionAbilityInfoByUri
* @tc.desc: 1.Test the FindExtensionAbilityInfoByUri of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5300, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
bundleInfo.baseExtensionInfos_.clear();
ExtensionAbilityInfo extensionAbilityInfo;
extensionAbilityInfo.uri = URI;
ExtensionAbilityInfo baseExtensionInfo;
bool ret = bundleInfo.FindExtensionAbilityInfoByUri(URI, baseExtensionInfo);
EXPECT_FALSE(ret);
bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, extensionAbilityInfo));
ret = bundleInfo.FindExtensionAbilityInfoByUri("URI", baseExtensionInfo);
EXPECT_FALSE(ret);
}
/**
* @tc.number: InnerBundleInfo_5400
* @tc.name: Test FindAbilityInfosByUri
* @tc.desc: 1.Test the FindAbilityInfosByUri of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5400, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
AbilityInfo abilityInfo;
abilityInfo.uri = URI;
std::vector<AbilityInfo> abilityInfos;
bundleInfo.baseAbilityInfos_.insert(std::make_pair(TEST_ABILITY_NAME, abilityInfo));
bundleInfo.FindAbilityInfosByUri("test", abilityInfos, userId);
EXPECT_FALSE(abilityInfos.empty());
}
/**
* @tc.number: InnerBundleInfo_5500
* @tc.name: Test FindAbilityInfosByUri
* @tc.desc: 1.Test the FindAbilityInfosByUri of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5500, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
AbilityInfo abilityInfo;
abilityInfo.uri = URI;
std::vector<AbilityInfo> abilityInfos;
bundleInfo.baseAbilityInfos_.insert(std::make_pair(TEST_ABILITY_NAME, abilityInfo));
bundleInfo.FindAbilityInfosByUri(URI, abilityInfos, userId);
EXPECT_TRUE(abilityInfos.empty());
}
/**
* @tc.number: InnerBundleInfo_5600
* @tc.name: Test RemoveGroupInfos
* @tc.desc: 1.Test the RemoveGroupInfos of InnerBundleInfo
*/
HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5600, Function | SmallTest | Level1)
{
InnerBundleInfo bundleInfo;
std::vector<DataGroupInfo> dataGroupInfos;
DataGroupInfo dataGroupInfo;
dataGroupInfo.userId = userId;
dataGroupInfos.push_back(dataGroupInfo);
bundleInfo.dataGroupInfos_.insert(std::make_pair(TEST_NAME, dataGroupInfos));
bundleInfo.RemoveGroupInfos(userId, "1");
EXPECT_FALSE(bundleInfo.dataGroupInfos_.empty());
bundleInfo.RemoveGroupInfos(userId2, TEST_NAME);
EXPECT_FALSE(bundleInfo.dataGroupInfos_.empty());
bundleInfo.RemoveGroupInfos(userId, TEST_NAME);
EXPECT_FALSE(bundleInfo.dataGroupInfos_.empty());
}
/**
* @tc.number: Test_0500
* @tc.name: Test Unmarshalling

View File

@ -2191,4 +2191,333 @@ HWTEST_F(BmsDataMgrTest, UpateCurDynamicIconModule_0100, Function | SmallTest |
ret = dataMgr->UpateCurDynamicIconModule(BUNDLE_NAME, moduleName);
EXPECT_EQ(ret, true);
}
/**
* @tc.number: GetInnerBundleInfoUsers_0100
* @tc.name: test GetInnerBundleInfoUsers
* @tc.desc: 1.test obtain internal bundle information for users
*/
HWTEST_F(BmsDataMgrTest, GetInnerBundleInfoUsers_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
std::string bundleName = "";
std::set<int32_t> userIds;
bool ret = dataMgr->GetInnerBundleInfoUsers(bundleName, userIds);
EXPECT_EQ(ret, false);
std::map<std::string, InnerBundleInfo> infos;
InnerBundleInfo innerBundleInfo;
infos.emplace(BUNDLE_NAME, innerBundleInfo);
dataMgr->bundleInfos_.swap(infos);
ret = dataMgr->GetInnerBundleInfoUsers(BUNDLE_NAME, userIds);
EXPECT_EQ(ret, true);
}
/**
* @tc.number: ResetAOTCompileStatus_0100
* @tc.name: test ResetAOTCompileStatus
* @tc.desc: 1.test reset AOT compilation status
*/
HWTEST_F(BmsDataMgrTest, ResetAOTCompileStatus_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
std::string bundleName = "";
std::string moduleName = "";
int32_t triggerMode = 0;
ErrCode ret = dataMgr->ResetAOTCompileStatus(bundleName, moduleName, triggerMode);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST);
dataMgr->ResetAOTFlagsCommand(bundleName);
std::map<std::string, InnerBundleInfo> infos;
InnerBundleInfo innerBundleInfo;
infos.emplace(BUNDLE_NAME, innerBundleInfo);
dataMgr->bundleInfos_.swap(infos);
dataMgr->ResetAOTFlagsCommand(BUNDLE_NAME);
ret = dataMgr->ResetAOTCompileStatus(BUNDLE_NAME, moduleName, triggerMode);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number: GetAllExtensionInfos_0100
* @tc.name: test GetAllExtensionInfos
* @tc.desc: 1.test get all extended information
*/
HWTEST_F(BmsDataMgrTest, GetAllExtensionInfos_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
uint32_t flags = 0;
int32_t userId = 0;
InnerBundleInfo info;
std::vector<ExtensionAbilityInfo> infos;
int32_t appIndex = 0;
dataMgr->GetAllExtensionInfos(flags, userId, info, infos, appIndex);
EXPECT_EQ(infos.empty(), true);
ExtensionAbilityInfo extensionAbilityInfo;
info.InsertExtensionInfo("", extensionAbilityInfo);
dataMgr->GetAllExtensionInfos(flags, userId, info, infos, appIndex);
EXPECT_EQ(infos.empty(), false);
flags = 1;
dataMgr->GetAllExtensionInfos(flags, userId, info, infos, appIndex);
EXPECT_EQ(infos.empty(), false);
}
/**
* @tc.number: GetAppServiceHspBundleInfo_0100
* @tc.name: test GetAppServiceHspBundleInfo
* @tc.desc: 1.obtain information on the Hsp bundle for application service
*/
HWTEST_F(BmsDataMgrTest, GetAppServiceHspBundleInfo_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
std::string bundleName = "";
BundleInfo bundleInfo;
ErrCode ret = dataMgr->GetAppServiceHspBundleInfo(bundleName, bundleInfo);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_PERMISSION_DENIED);
std::map<std::string, InnerBundleInfo> infos;
InnerBundleInfo innerBundleInfo;
infos.emplace(BUNDLE_NAME, innerBundleInfo);
dataMgr->bundleInfos_.swap(infos);
ret = dataMgr->GetAppServiceHspBundleInfo(BUNDLE_NAME, bundleInfo);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_PERMISSION_DENIED);
}
/**
* @tc.number: CanOpenLink_0100
* @tc.name: test CanOpenLink
* @tc.desc: 1.judge open link
*/
HWTEST_F(BmsDataMgrTest, CanOpenLink_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
std::string link = "";
bool canOpen = false;
ErrCode ret = dataMgr->CanOpenLink(link, canOpen);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_SCHEME_NOT_IN_QUERYSCHEMES);
}
/**
* @tc.number:GetOdid_0100
* @tc.name: test GetOdid
* @tc.desc: 1.test get odid
*/
HWTEST_F(BmsDataMgrTest, GetOdid_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
std::string odid = "";
std::string developerId = "";
dataMgr->GenerateOdid(developerId, odid);
ErrCode ret = dataMgr->GetOdid(odid);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST);
}
/**
* @tc.number:GetDeveloperIds_0100
* @tc.name: test GetDeveloperIds
* @tc.desc: 1.test get developer ids
*/
HWTEST_F(BmsDataMgrTest, GetDeveloperIds_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
std::string appDistributionType = "";
std::vector<std::string> developerIdList;
int32_t userId = -1;
ErrCode ret = dataMgr->GetDeveloperIds(appDistributionType, developerIdList, userId);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_INVALID_USER_ID);
userId = Constants::ANY_USERID;
InnerBundleInfo innerBundleInfo;
dataMgr->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo);
ret = dataMgr->GetDeveloperIds(appDistributionType, developerIdList, userId);
EXPECT_EQ(ret, ERR_OK);
dataMgr->bundleInfos_.clear();
ret = dataMgr->GetDeveloperIds(appDistributionType, developerIdList, userId);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_INTERNAL_ERROR);
}
/**
* @tc.number:AddCloneBundle_0100
* @tc.name: test AddCloneBundle
* @tc.desc: 1.test add clone bundle
*/
HWTEST_F(BmsDataMgrTest, AddCloneBundle_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
std::string bundleName = "";
InnerBundleCloneInfo attr;
ErrCode ret = dataMgr->AddCloneBundle(bundleName, attr);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST);
InnerBundleInfo innerBundleInfo;
dataMgr->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo);
ret = dataMgr->AddCloneBundle(BUNDLE_NAME, attr);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number:RemoveCloneBundle_0100
* @tc.name: test RemoveCloneBundle
* @tc.desc: 1.test remove clone bundle
*/
HWTEST_F(BmsDataMgrTest, RemoveCloneBundle_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
std::string bundleName = "";
int32_t userId = -1;
int32_t appIndex = 0;
ErrCode ret = dataMgr->RemoveCloneBundle(bundleName, userId, appIndex);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST);
InnerBundleInfo innerBundleInfo;
dataMgr->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo);
ret = dataMgr->RemoveCloneBundle(BUNDLE_NAME, userId, appIndex);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number:QueryAbilityInfoByContinueType_0100
* @tc.name: test QueryAbilityInfoByContinueType
* @tc.desc: 1.query capability information by continuous type
*/
HWTEST_F(BmsDataMgrTest, QueryAbilityInfoByContinueType_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
std::string bundleName = "";
std::string continueType = "";
AbilityInfo abilityInfo;
int32_t userId = -1;
int32_t appIndex = 0;
ErrCode ret = dataMgr->QueryAbilityInfoByContinueType(bundleName, continueType, abilityInfo, userId, appIndex);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_INVALID_USER_ID);
userId = Constants::ANY_USERID;
ret = dataMgr->QueryAbilityInfoByContinueType(bundleName, continueType, abilityInfo, userId, appIndex);
EXPECT_NE(ret, ERR_OK);
appIndex = 1;
ret = dataMgr->QueryAbilityInfoByContinueType(bundleName, continueType, abilityInfo, userId, appIndex);
EXPECT_NE(ret, ERR_OK);
dataMgr->bundleInfos_.clear();
ret = dataMgr->QueryAbilityInfoByContinueType(bundleName, continueType, abilityInfo, userId, appIndex);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_INTERNAL_ERROR);
}
/**
* @tc.number:QueryAbilityInfoByContinueType_0200
* @tc.name: test QueryAbilityInfoByContinueType
* @tc.desc: 1.query capability information by continuous type
*/
HWTEST_F(BmsDataMgrTest, QueryAbilityInfoByContinueType_0200, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
ApplicationInfo applicationInfo;
applicationInfo.bundleName = BUNDLE_NAME;
InnerBundleInfo innerBundleInfo;
innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
int32_t userId = Constants::ALL_USERID;
BundleUserInfo userInfo;
userInfo.userId = userId;
InnerBundleUserInfo innerBundleUserInfo;
innerBundleUserInfo.bundleUserInfo = userInfo;
innerBundleInfo.AddInnerBundleUserInfo(innerBundleUserInfo);
innerBundleInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::ENABLED);
dataMgr->multiUserIdsSet_.insert(userId);
dataMgr->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo);
std::string bundleName = "";
std::string continueType = "";
AbilityInfo abilityInfo;
int32_t appIndex = 0;
ErrCode ret = dataMgr->QueryAbilityInfoByContinueType(BUNDLE_NAME, continueType, abilityInfo, userId, appIndex);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST);
}
/**
* @tc.number:QueryCloneAbilityInfo_0100
* @tc.name: test QueryCloneAbilityInfo
* @tc.desc: 1.query cloning capability information
*/
HWTEST_F(BmsDataMgrTest, QueryCloneAbilityInfo_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
ElementName element;
int32_t flags = 0;
int32_t userId = -1;
int32_t appIndex = 0;
AbilityInfo abilityInfo;
ErrCode ret = dataMgr->QueryCloneAbilityInfo(element, flags, userId, appIndex, abilityInfo);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_INVALID_USER_ID);
userId = Constants::ANY_USERID;
ret = dataMgr->QueryCloneAbilityInfo(element, flags, userId, appIndex, abilityInfo);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number:ExplicitQueryCloneAbilityInfo_0100
* @tc.name: test ExplicitQueryCloneAbilityInfo
* @tc.desc: 1.explicitly query cloning capability information
*/
HWTEST_F(BmsDataMgrTest, ExplicitQueryCloneAbilityInfo_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
ElementName element;
int32_t flags = 0;
int32_t userId = -1;
int32_t appIndex = 0;
AbilityInfo abilityInfo;
ErrCode ret = dataMgr->ExplicitQueryCloneAbilityInfoV9(element, flags, userId, appIndex, abilityInfo);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_INVALID_USER_ID);
}
/**
* @tc.number:GetCloneBundleInfo_0100
* @tc.name: test GetCloneBundleInfo
* @tc.desc: 1.get clone bundle information
*/
HWTEST_F(BmsDataMgrTest, GetCloneBundleInfo_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
std::string bundleName = "";
int32_t flags = 0;
int32_t appIndex = 0;
BundleInfo bundleInfo;
int32_t userId = -1;
ErrCode ret = dataMgr->GetCloneBundleInfo(bundleName, flags, appIndex, bundleInfo, userId);
EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_INVALID_USER_ID);
userId = Constants::ANY_USERID;
ret = dataMgr->GetCloneBundleInfo(bundleName, flags, appIndex, bundleInfo, userId);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number:GetInnerBundleInfoWithFlags_0100
* @tc.name: test GetInnerBundleInfoWithFlags
* @tc.desc: 1.test using flags to obtain internal bundling information
*/
HWTEST_F(BmsDataMgrTest, GetInnerBundleInfoWithFlags_0100, Function | SmallTest | Level1)
{
auto dataMgr = GetDataMgr();
ASSERT_NE(dataMgr, nullptr);
InnerBundleInfo innerBundleInfo;
ApplicationInfo applicationInfo;
applicationInfo.bundleName = BUNDLE_NAME;
innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
int32_t userId = Constants::ALL_USERID;
innerBundleInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::ENABLED);
BundleUserInfo userInfo;
userInfo.userId = userId;
InnerBundleUserInfo innerBundleUserInfo;
innerBundleUserInfo.bundleUserInfo = userInfo;
innerBundleInfo.AddInnerBundleUserInfo(innerBundleUserInfo);
dataMgr->multiUserIdsSet_.insert(userId);
dataMgr->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo);
ErrCode res =
dataMgr->GetInnerBundleInfoWithFlagsV9(BUNDLE_NAME, GET_ABILITY_INFO_DEFAULT, innerBundleInfo, userId);
EXPECT_EQ(res, ERR_OK);
}
} // OHOS

View File

@ -162,6 +162,23 @@ bool SystemBundleInstaller::UninstallSystemBundle(const std::string &bundleName,
return true;
}
bool SystemBundleInstaller::UninstallSystemBundle(const std::string &bundleName, const InstallParam &installParam)
{
auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
if (dataMgr == nullptr) {
APP_LOGE("Get dataMgr shared_ptr nullptr");
return false;
}
MarkPreBundleSyeEventBootTag(false);
ErrCode result = UninstallBundle(bundleName, installParam);
if ((result != ERR_OK) && (result != ERR_APPEXECFWK_USER_NOT_INSTALL_HAP)) {
APP_LOGW("uninstall system bundle %{public}s userId %{public}d fail, error: %{public}d", bundleName.c_str(),
installParam.userId, result);
return false;
}
return true;
}
bool SystemBundleInstaller::InstallSystemSharedBundle(
InstallParam &installParam,
bool isOTA,

View File

@ -1055,31 +1055,13 @@ HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_5900, Function | Sma
EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR);
}
/**
* @tc.number: InstalldHostImplTest_6000
* @tc.name: test function of InstallHostImpl
* @tc.desc: 1. calling CleanBundleDataDirByName of hostImpl
* @tc.require: issueI5VW01
*/
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6000, Function | SmallTest | Level0)
{
sptr<InstalldProxy> installdProxy = new (std::nothrow) InstalldProxy(nullptr);
EXPECT_NE(installdProxy, nullptr);
std::string bundleName = "com.acts.example";
int userid = 0;
int appIndex = 0;
ErrCode ret = installdProxy->CleanBundleDataDirByName(bundleName, userid, appIndex);
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.number: InstalldHostImplTest_6100
* @tc.name: test function of InstallHostImpl
* @tc.desc: 1. calling DeliverySignProfile of hostImpl
* @tc.require: issueI5VW01
*/
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6100, Function | SmallTest | Level0)
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6000, Function | SmallTest | Level0)
{
sptr<InstalldProxy> installdProxy = new (std::nothrow) InstalldProxy(nullptr);
EXPECT_NE(installdProxy, nullptr);
@ -1097,7 +1079,7 @@ HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6100, Function | Sma
* @tc.desc: 1. calling RemoveExtensionDir of hostImpl
* @tc.require: issueI5VW01
*/
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6200, Function | SmallTest | Level0)
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6100, Function | SmallTest | Level0)
{
sptr<InstalldProxy> installdProxy = new (std::nothrow) InstalldProxy(nullptr);
EXPECT_NE(installdProxy, nullptr);
@ -1114,7 +1096,7 @@ HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6200, Function | Sma
* @tc.desc: 1. calling RemoveExtensionDir of hostImpl
* @tc.require: issueI5VW01
*/
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6300, Function | SmallTest | Level0)
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6200, Function | SmallTest | Level0)
{
sptr<InstalldProxy> installdProxy = new (std::nothrow) InstalldProxy(nullptr);
EXPECT_NE(installdProxy, nullptr);
@ -1132,7 +1114,7 @@ HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6300, Function | Sma
* @tc.desc: 1. calling RemoveExtensionDir of hostImpl
* @tc.require: issueI5VW01
*/
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6400, Function | SmallTest | Level0)
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6300, Function | SmallTest | Level0)
{
sptr<InstalldProxy> installdProxy = new (std::nothrow) InstalldProxy(nullptr);
EXPECT_NE(installdProxy, nullptr);
@ -1150,7 +1132,7 @@ HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6400, Function | Sma
* @tc.desc: 1. calling IsExistExtensionDir of hostImpl
* @tc.require: issueI5VW01
*/
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6500, Function | SmallTest | Level0)
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6400, Function | SmallTest | Level0)
{
sptr<InstalldProxy> installdProxy = new (std::nothrow) InstalldProxy(nullptr);
EXPECT_NE(installdProxy, nullptr);
@ -1168,7 +1150,7 @@ HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6500, Function | Sma
* @tc.desc: 1. calling CreateExtensionDataDir of hostImpl
* @tc.require: issueI5VW01
*/
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6600, Function | SmallTest | Level0)
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6500, Function | SmallTest | Level0)
{
sptr<InstalldProxy> installdProxy = new (std::nothrow) InstalldProxy(nullptr);
EXPECT_NE(installdProxy, nullptr);
@ -1186,7 +1168,7 @@ HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6600, Function | Sma
* @tc.desc: 1. calling CreateExtensionDataDir of hostImpl
* @tc.require: issueI5VW01
*/
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6700, Function | SmallTest | Level0)
HWTEST_F(BmsInstallDaemonHostImplTest, InstalldHostImplTest_6600, Function | SmallTest | Level0)
{
sptr<InstalldProxy> installdProxy = new (std::nothrow) InstalldProxy(nullptr);
EXPECT_NE(installdProxy, nullptr);

View File

@ -105,6 +105,7 @@ group("fuzztest") {
"fuzztest_others/basebundleinstallercheckuninstallinnerbundleinfo_fuzzer:BaseBundleInstallerCheckUninstallInnerBundleInfoFuzzTest",
"fuzztest_others/basebundleinstallercreatebundleanddatadir_fuzzer:BaseBundleInstallerCreateBundleAndDataDirFuzzTest",
"fuzztest_others/basebundleinstallerextractmodule_fuzzer:BaseBundleInstallerExtractModuleFuzzTest",
"fuzztest_others/basebundleinstallerextractmodulefiles_fuzzer:BaseBundleInstallerExtractModuleFilesFuzzTest",
"fuzztest_others/basebundleinstallerinnerprocessbundleinstall_fuzzer:BaseBundleInstallerInnerProcessBundleInstallFuzzTest",
"fuzztest_others/basebundleinstallerinstallbundle_fuzzer:BaseBundleInstallerInstallBundleFuzzTest",
"fuzztest_others/basebundleinstallerinstallbundlebybundlename_fuzzer:BaseBundleInstallerInstallBundleByBundleNameFuzzTest",
@ -116,9 +117,13 @@ group("fuzztest") {
"fuzztest_others/basebundleinstallerprocessbundleuninstall_fuzzer:BaseBundleInstallerProcessBundleUninstallFuzzTest",
"fuzztest_others/basebundleinstallerprocessbundleuninstallnative_fuzzer:BaseBundleInstallerProcessBundleUnInstallNativeFuzzTest",
"fuzztest_others/basebundleinstallerprocessbundleupdatestatus_fuzzer:BaseBundleInstallerProcessBundleUpdateStatusFuzzTest",
"fuzztest_others/basebundleinstallerprocessmoduleupdate_fuzzer:BaseBundleInstallerProcessModuleUpdateFuzzTest",
"fuzztest_others/basebundleinstallerrecover_fuzzer:BaseBundleInstallerRecoverFuzzTest",
"fuzztest_others/basebundleinstallerremovebundle_fuzzer:BaseBundleInstallerRemoveBundleFuzzTest",
"fuzztest_others/basebundleinstallerremovebundleanddatadir_fuzzer:BaseBundleInstallerRemoveBundleAndDataDirFuzzTest",
"fuzztest_others/basebundleinstallerremovemoduleanddatadir_fuzzer:BaseBundleInstallerRemoveModuleAndDataDirFuzzTest",
"fuzztest_others/basebundleinstallerremovemoduledir_fuzzer:BaseBundleInstallerRemoveModuleDirFuzzTest",
"fuzztest_others/basebundleinstallerrenamemoduledir_fuzzer:BaseBundleInstallerRenameModuleDirFuzzTest",
"fuzztest_others/basebundleinstallersetcheckresultmsg_fuzzer:BaseBundleInstallerSetCheckResultMsgFuzzTest",
"fuzztest_others/basebundleinstalleruninstallbundle_fuzzer:BaseBundleInstallerUnInstallBundleFuzzTest",
"fuzztest_others/basebundleinstalleruninstallbundlebyuninstallparam_fuzzer:BaseBundleInstallerUninstallBundleByUninstallParamFuzzTest",

View File

@ -0,0 +1,161 @@
# Copyright (c) 2021-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/test.gni")
import("../../../../appexecfwk.gni")
import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni")
module_output_path = fuzz_test_path
ohos_fuzztest("BaseBundleInstallerExtractModuleFilesFuzzTest") {
fuzz_config_file = "../../../fuzztest/fuzztest_others/basebundleinstallerextractmodulefiles_fuzzer"
use_exceptions = true
module_out_path = module_output_path
include_dirs = [
"//third_party/jsoncpp/include",
"${services_path}/bundlemgr/test/mock/include/parameter",
]
sources = bundle_mgr_source
sources -= [ "${services_path}/bundlemgr/src/bms_param.cpp" ]
sources += [ "${services_path}/bundlemgr/test/mock/src/bms_param.cpp" ]
sources -= [ "${services_path}/bundlemgr/src/system_ability_helper.cpp" ]
sources += bundle_install_sources
sources -= [ "${services_path}/bundlemgr/src/installd_client.cpp" ]
sources += [ "${services_path}/bundlemgr/test/mock/src/installd_client.cpp" ]
sources += [
"${services_path}/bundlemgr/test/mock/src/accesstoken_kit.cpp",
"${services_path}/bundlemgr/test/mock/src/installd_permission_mgr.cpp",
"${services_path}/bundlemgr/test/mock/src/mock_status_receiver.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/parameter.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/parameters.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/systemcapability.cpp",
"${services_path}/bundlemgr/test/mock/src/system_ability_helper.cpp",
]
sources += [ "basebundleinstallerextractmodulefiles_fuzzer.cpp" ]
configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
deps = [ "${core_path}:appexecfwk_core" ]
deps += bundle_install_deps
external_deps = [
"ability_base:want",
"ability_runtime:app_manager",
"access_token:el5_filekey_manager_sdk",
"access_token:libprivacy_sdk",
"access_token:libtokenid_sdk",
"appverify:libhapverify",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbegetutil",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
external_deps += bundle_install_external_deps
if (bundle_framework_graphics) {
external_deps += [ "image_framework:image_native" ]
}
defines = []
if (configpolicy_enable) {
external_deps += [ "config_policy:configpolicy_util" ]
defines += [ "CONFIG_POLOCY_ENABLE" ]
}
if (build_selinux) {
external_deps += [ "selinux_adapter:libhap_restorecon" ]
}
if (account_enable) {
external_deps += [ "os_account:os_account_innerkits" ]
defines += [ "ACCOUNT_ENABLE" ]
}
if (bundle_framework_free_install) {
sources += aging
sources += free_install
sources += distributed_manager
external_deps += [
"ability_runtime:ability_manager",
"ability_runtime:app_manager",
"battery_manager:batterysrv_client",
"device_usage_statistics:usagestatsinner",
"display_manager:displaymgr",
"power_manager:powermgr_client",
"syscap_codec:syscap_interface_shared",
]
defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ]
}
if (hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (global_resmgr_enable) {
defines += [ "GLOBAL_RESMGR_ENABLE" ]
external_deps += [ "resource_management:global_resmgr" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
if (storage_service_enable) {
external_deps += [ "storage_service:storage_manager_sa_proxy" ]
defines += [ "STORAGE_SERVICE_ENABLE" ]
}
configs += [ "${services_path}/bundlemgr:rdb_config" ]
external_deps += [ "relational_store:native_rdb" ]
sources += [
"${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp",
"${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp",
"${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp",
"${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp",
]
if (bundle_framework_app_control) {
defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ]
sources += [
"${services_path}/bundlemgr/src/app_control/app_control_manager.cpp",
"${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp",
"${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp",
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp",
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp",
]
include_dirs += [ "${services_path}/bundlemgr/include/app_control" ]
external_deps += [ "c_utils:utils" ]
}
if (udmf_enabled) {
defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ]
external_deps += [ "udmf:udmf_client" ]
}
if (bms_device_info_manager_part_enabled) {
external_deps += [
"device_info_manager:distributed_device_profile_common",
"device_info_manager:distributed_device_profile_sdk",
]
defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ]
}
}

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 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
*
* 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.
*/
#define private public
#include <cstddef>
#include <cstdint>
#include "basebundleinstallerextractmodulefiles_fuzzer.h"
#include "base_bundle_installer.h"
#include "securec.h"
using namespace OHOS::AppExecFwk;
namespace OHOS {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
bool DoSomethingInterestingWithMyAPI(const char *data, size_t size)
{
BaseBundleInstaller basebundleinstall;
InnerBundleInfo info;
std::string modulePath;
std::string targetSoPath;
std::string cpuAbi;
auto ret1 = basebundleinstall.ExtractModuleFiles(info, modulePath, targetSoPath, cpuAbi);
return true;
}
}
// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
/* Run your code on data */
if (data == nullptr) {
return 0;
}
if (size < OHOS::U32_AT_SIZE) {
return 0;
}
/* Validate the length of size */
if (size > OHOS::FOO_MAX_LEN) {
return 0;
}
char *ch = static_cast<char *>(malloc(size + 1));
if (ch == nullptr) {
return 0;
}
(void)memset_s(ch, size + 1, 0x00, size + 1);
if (memcpy_s(ch, size, data, size) != EOK) {
free(ch);
ch = nullptr;
return 0;
}
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
free(ch);
ch = nullptr;
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 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
*
* 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 TEST_FUZZTEST_BASEBUNDLEINSTALLEREXTRACTMODULEFILES_FUZZER_H
#define TEST_FUZZTEST_BASEBUNDLEINSTALLEREXTRACTMODULEFILES_FUZZER_H
#define FUZZ_PROJECT_NAME "basebundleinstallerextractmodulefiles_fuzzer"
#endif

View File

@ -0,0 +1,14 @@
# Copyright (c) 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
#
# 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.
FUZZ

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 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
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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,161 @@
# Copyright (c) 2021-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/test.gni")
import("../../../../appexecfwk.gni")
import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni")
module_output_path = fuzz_test_path
ohos_fuzztest("BaseBundleInstallerProcessModuleUpdateFuzzTest") {
fuzz_config_file = "../../../fuzztest/fuzztest_others/basebundleinstallerprocessmoduleupdate_fuzzer"
use_exceptions = true
module_out_path = module_output_path
include_dirs = [
"//third_party/jsoncpp/include",
"${services_path}/bundlemgr/test/mock/include/parameter",
]
sources = bundle_mgr_source
sources -= [ "${services_path}/bundlemgr/src/bms_param.cpp" ]
sources += [ "${services_path}/bundlemgr/test/mock/src/bms_param.cpp" ]
sources -= [ "${services_path}/bundlemgr/src/system_ability_helper.cpp" ]
sources += bundle_install_sources
sources -= [ "${services_path}/bundlemgr/src/installd_client.cpp" ]
sources += [ "${services_path}/bundlemgr/test/mock/src/installd_client.cpp" ]
sources += [
"${services_path}/bundlemgr/test/mock/src/accesstoken_kit.cpp",
"${services_path}/bundlemgr/test/mock/src/installd_permission_mgr.cpp",
"${services_path}/bundlemgr/test/mock/src/mock_status_receiver.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/parameter.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/parameters.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/systemcapability.cpp",
"${services_path}/bundlemgr/test/mock/src/system_ability_helper.cpp",
]
sources += [ "basebundleinstallerprocessmoduleupdate_fuzzer.cpp" ]
configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
deps = [ "${core_path}:appexecfwk_core" ]
deps += bundle_install_deps
external_deps = [
"ability_base:want",
"ability_runtime:app_manager",
"access_token:el5_filekey_manager_sdk",
"access_token:libprivacy_sdk",
"access_token:libtokenid_sdk",
"appverify:libhapverify",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbegetutil",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
external_deps += bundle_install_external_deps
if (bundle_framework_graphics) {
external_deps += [ "image_framework:image_native" ]
}
defines = []
if (configpolicy_enable) {
external_deps += [ "config_policy:configpolicy_util" ]
defines += [ "CONFIG_POLOCY_ENABLE" ]
}
if (build_selinux) {
external_deps += [ "selinux_adapter:libhap_restorecon" ]
}
if (account_enable) {
external_deps += [ "os_account:os_account_innerkits" ]
defines += [ "ACCOUNT_ENABLE" ]
}
if (bundle_framework_free_install) {
sources += aging
sources += free_install
sources += distributed_manager
external_deps += [
"ability_runtime:ability_manager",
"ability_runtime:app_manager",
"battery_manager:batterysrv_client",
"device_usage_statistics:usagestatsinner",
"display_manager:displaymgr",
"power_manager:powermgr_client",
"syscap_codec:syscap_interface_shared",
]
defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ]
}
if (hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (global_resmgr_enable) {
defines += [ "GLOBAL_RESMGR_ENABLE" ]
external_deps += [ "resource_management:global_resmgr" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
if (storage_service_enable) {
external_deps += [ "storage_service:storage_manager_sa_proxy" ]
defines += [ "STORAGE_SERVICE_ENABLE" ]
}
configs += [ "${services_path}/bundlemgr:rdb_config" ]
external_deps += [ "relational_store:native_rdb" ]
sources += [
"${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp",
"${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp",
"${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp",
"${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp",
]
if (bundle_framework_app_control) {
defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ]
sources += [
"${services_path}/bundlemgr/src/app_control/app_control_manager.cpp",
"${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp",
"${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp",
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp",
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp",
]
include_dirs += [ "${services_path}/bundlemgr/include/app_control" ]
external_deps += [ "c_utils:utils" ]
}
if (udmf_enabled) {
defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ]
external_deps += [ "udmf:udmf_client" ]
}
if (bms_device_info_manager_part_enabled) {
external_deps += [
"device_info_manager:distributed_device_profile_common",
"device_info_manager:distributed_device_profile_sdk",
]
defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ]
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright (c) 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
*
* 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.
*/
#define private public
#include <cstddef>
#include <cstdint>
#include "basebundleinstallerprocessmoduleupdate_fuzzer.h"
#include "base_bundle_installer.h"
#include "securec.h"
using namespace OHOS::AppExecFwk;
namespace OHOS {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
bool DoSomethingInterestingWithMyAPI(const char *data, size_t size)
{
BaseBundleInstaller basebundleinstall;
InnerBundleInfo newInfo;
InnerBundleInfo oldInfo;
bool isReplace = true;
auto ret1 = basebundleinstall.ProcessModuleUpdate(newInfo, oldInfo, isReplace);
return true;
}
}
// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
/* Run your code on data */
if (data == nullptr) {
return 0;
}
if (size < OHOS::U32_AT_SIZE) {
return 0;
}
/* Validate the length of size */
if (size > OHOS::FOO_MAX_LEN) {
return 0;
}
char *ch = static_cast<char *>(malloc(size + 1));
if (ch == nullptr) {
return 0;
}
(void)memset_s(ch, size + 1, 0x00, size + 1);
if (memcpy_s(ch, size, data, size) != EOK) {
free(ch);
ch = nullptr;
return 0;
}
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
free(ch);
ch = nullptr;
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 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
*
* 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 TEST_FUZZTEST_BASEBUNDLEINSTALLERPROCESSMODULEUPDATE_FUZZER_H
#define TEST_FUZZTEST_BASEBUNDLEINSTALLERPROCESSMODULEUPDATE_FUZZER_H
#define FUZZ_PROJECT_NAME "basebundleinstallerprocessmoduleupdate_fuzzer"
#endif

View File

@ -0,0 +1,14 @@
# Copyright (c) 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
#
# 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.
FUZZ

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 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
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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,161 @@
# Copyright (c) 2021-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/test.gni")
import("../../../../appexecfwk.gni")
import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni")
module_output_path = fuzz_test_path
ohos_fuzztest("BaseBundleInstallerRemoveModuleAndDataDirFuzzTest") {
fuzz_config_file = "../../../fuzztest/fuzztest_others/basebundleinstallerremovemoduleanddatadir_fuzzer"
use_exceptions = true
module_out_path = module_output_path
include_dirs = [
"//third_party/jsoncpp/include",
"${services_path}/bundlemgr/test/mock/include/parameter",
]
sources = bundle_mgr_source
sources -= [ "${services_path}/bundlemgr/src/bms_param.cpp" ]
sources += [ "${services_path}/bundlemgr/test/mock/src/bms_param.cpp" ]
sources -= [ "${services_path}/bundlemgr/src/system_ability_helper.cpp" ]
sources += bundle_install_sources
sources -= [ "${services_path}/bundlemgr/src/installd_client.cpp" ]
sources += [ "${services_path}/bundlemgr/test/mock/src/installd_client.cpp" ]
sources += [
"${services_path}/bundlemgr/test/mock/src/accesstoken_kit.cpp",
"${services_path}/bundlemgr/test/mock/src/installd_permission_mgr.cpp",
"${services_path}/bundlemgr/test/mock/src/mock_status_receiver.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/parameter.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/parameters.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/systemcapability.cpp",
"${services_path}/bundlemgr/test/mock/src/system_ability_helper.cpp",
]
sources += [ "basebundleinstallerremovemoduleanddatadir_fuzzer.cpp" ]
configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
deps = [ "${core_path}:appexecfwk_core" ]
deps += bundle_install_deps
external_deps = [
"ability_base:want",
"ability_runtime:app_manager",
"access_token:el5_filekey_manager_sdk",
"access_token:libprivacy_sdk",
"access_token:libtokenid_sdk",
"appverify:libhapverify",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbegetutil",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
external_deps += bundle_install_external_deps
if (bundle_framework_graphics) {
external_deps += [ "image_framework:image_native" ]
}
defines = []
if (configpolicy_enable) {
external_deps += [ "config_policy:configpolicy_util" ]
defines += [ "CONFIG_POLOCY_ENABLE" ]
}
if (build_selinux) {
external_deps += [ "selinux_adapter:libhap_restorecon" ]
}
if (account_enable) {
external_deps += [ "os_account:os_account_innerkits" ]
defines += [ "ACCOUNT_ENABLE" ]
}
if (bundle_framework_free_install) {
sources += aging
sources += free_install
sources += distributed_manager
external_deps += [
"ability_runtime:ability_manager",
"ability_runtime:app_manager",
"battery_manager:batterysrv_client",
"device_usage_statistics:usagestatsinner",
"display_manager:displaymgr",
"power_manager:powermgr_client",
"syscap_codec:syscap_interface_shared",
]
defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ]
}
if (hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (global_resmgr_enable) {
defines += [ "GLOBAL_RESMGR_ENABLE" ]
external_deps += [ "resource_management:global_resmgr" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
if (storage_service_enable) {
external_deps += [ "storage_service:storage_manager_sa_proxy" ]
defines += [ "STORAGE_SERVICE_ENABLE" ]
}
configs += [ "${services_path}/bundlemgr:rdb_config" ]
external_deps += [ "relational_store:native_rdb" ]
sources += [
"${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp",
"${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp",
"${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp",
"${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp",
]
if (bundle_framework_app_control) {
defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ]
sources += [
"${services_path}/bundlemgr/src/app_control/app_control_manager.cpp",
"${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp",
"${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp",
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp",
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp",
]
include_dirs += [ "${services_path}/bundlemgr/include/app_control" ]
external_deps += [ "c_utils:utils" ]
}
if (udmf_enabled) {
defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ]
external_deps += [ "udmf:udmf_client" ]
}
if (bms_device_info_manager_part_enabled) {
external_deps += [
"device_info_manager:distributed_device_profile_common",
"device_info_manager:distributed_device_profile_sdk",
]
defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ]
}
}

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 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
*
* 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.
*/
#define private public
#include <cstddef>
#include <cstdint>
#include "basebundleinstallerremovemoduleanddatadir_fuzzer.h"
#include "base_bundle_installer.h"
#include "securec.h"
using namespace OHOS::AppExecFwk;
namespace OHOS {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
bool DoSomethingInterestingWithMyAPI(const char *data, size_t size)
{
BaseBundleInstaller basebundleinstall;
InnerBundleInfo info;
std::string modulePackage;
int32_t userId = 0;
bool isKeepData = true;
auto ret1 = basebundleinstall.RemoveModuleAndDataDir(info, modulePackage, userId, isKeepData);
return true;
}
}
// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
/* Run your code on data */
if (data == nullptr) {
return 0;
}
if (size < OHOS::U32_AT_SIZE) {
return 0;
}
/* Validate the length of size */
if (size > OHOS::FOO_MAX_LEN) {
return 0;
}
char *ch = static_cast<char *>(malloc(size + 1));
if (ch == nullptr) {
return 0;
}
(void)memset_s(ch, size + 1, 0x00, size + 1);
if (memcpy_s(ch, size, data, size) != EOK) {
free(ch);
ch = nullptr;
return 0;
}
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
free(ch);
ch = nullptr;
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 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
*
* 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 TEST_FUZZTEST_BASEBUNDLEINSTALLERREMOVEMODULEANDDATADIR_FUZZER_H
#define TEST_FUZZTEST_BASEBUNDLEINSTALLERREMOVEMODULEANDDATADIR_FUZZER_H
#define FUZZ_PROJECT_NAME "basebundleinstallerremovemoduleanddatadir_fuzzer"
#endif

View File

@ -0,0 +1,14 @@
# Copyright (c) 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
#
# 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.
FUZZ

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 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
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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,161 @@
# Copyright (c) 2021-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/test.gni")
import("../../../../appexecfwk.gni")
import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni")
module_output_path = fuzz_test_path
ohos_fuzztest("BaseBundleInstallerRemoveModuleDirFuzzTest") {
fuzz_config_file = "../../../fuzztest/fuzztest_others/basebundleinstallerremovemoduledir_fuzzer"
use_exceptions = true
module_out_path = module_output_path
include_dirs = [
"//third_party/jsoncpp/include",
"${services_path}/bundlemgr/test/mock/include/parameter",
]
sources = bundle_mgr_source
sources -= [ "${services_path}/bundlemgr/src/bms_param.cpp" ]
sources += [ "${services_path}/bundlemgr/test/mock/src/bms_param.cpp" ]
sources -= [ "${services_path}/bundlemgr/src/system_ability_helper.cpp" ]
sources += bundle_install_sources
sources -= [ "${services_path}/bundlemgr/src/installd_client.cpp" ]
sources += [ "${services_path}/bundlemgr/test/mock/src/installd_client.cpp" ]
sources += [
"${services_path}/bundlemgr/test/mock/src/accesstoken_kit.cpp",
"${services_path}/bundlemgr/test/mock/src/installd_permission_mgr.cpp",
"${services_path}/bundlemgr/test/mock/src/mock_status_receiver.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/parameter.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/parameters.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/systemcapability.cpp",
"${services_path}/bundlemgr/test/mock/src/system_ability_helper.cpp",
]
sources += [ "basebundleinstallerremovemoduledir_fuzzer.cpp" ]
configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
deps = [ "${core_path}:appexecfwk_core" ]
deps += bundle_install_deps
external_deps = [
"ability_base:want",
"ability_runtime:app_manager",
"access_token:el5_filekey_manager_sdk",
"access_token:libprivacy_sdk",
"access_token:libtokenid_sdk",
"appverify:libhapverify",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbegetutil",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
external_deps += bundle_install_external_deps
if (bundle_framework_graphics) {
external_deps += [ "image_framework:image_native" ]
}
defines = []
if (configpolicy_enable) {
external_deps += [ "config_policy:configpolicy_util" ]
defines += [ "CONFIG_POLOCY_ENABLE" ]
}
if (build_selinux) {
external_deps += [ "selinux_adapter:libhap_restorecon" ]
}
if (account_enable) {
external_deps += [ "os_account:os_account_innerkits" ]
defines += [ "ACCOUNT_ENABLE" ]
}
if (bundle_framework_free_install) {
sources += aging
sources += free_install
sources += distributed_manager
external_deps += [
"ability_runtime:ability_manager",
"ability_runtime:app_manager",
"battery_manager:batterysrv_client",
"device_usage_statistics:usagestatsinner",
"display_manager:displaymgr",
"power_manager:powermgr_client",
"syscap_codec:syscap_interface_shared",
]
defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ]
}
if (hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (global_resmgr_enable) {
defines += [ "GLOBAL_RESMGR_ENABLE" ]
external_deps += [ "resource_management:global_resmgr" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
if (storage_service_enable) {
external_deps += [ "storage_service:storage_manager_sa_proxy" ]
defines += [ "STORAGE_SERVICE_ENABLE" ]
}
configs += [ "${services_path}/bundlemgr:rdb_config" ]
external_deps += [ "relational_store:native_rdb" ]
sources += [
"${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp",
"${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp",
"${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp",
"${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp",
]
if (bundle_framework_app_control) {
defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ]
sources += [
"${services_path}/bundlemgr/src/app_control/app_control_manager.cpp",
"${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp",
"${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp",
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp",
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp",
]
include_dirs += [ "${services_path}/bundlemgr/include/app_control" ]
external_deps += [ "c_utils:utils" ]
}
if (udmf_enabled) {
defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ]
external_deps += [ "udmf:udmf_client" ]
}
if (bms_device_info_manager_part_enabled) {
external_deps += [
"device_info_manager:distributed_device_profile_common",
"device_info_manager:distributed_device_profile_sdk",
]
defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ]
}
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 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
*
* 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.
*/
#define private public
#include <cstddef>
#include <cstdint>
#include "basebundleinstallerremovemoduledir_fuzzer.h"
#include "base_bundle_installer.h"
#include "securec.h"
using namespace OHOS::AppExecFwk;
namespace OHOS {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
bool DoSomethingInterestingWithMyAPI(const char *data, size_t size)
{
BaseBundleInstaller basebundleinstall;
std::string modulePath;
auto ret1 = basebundleinstall.RemoveModuleDir(modulePath);
return true;
}
}
// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
/* Run your code on data */
if (data == nullptr) {
return 0;
}
if (size < OHOS::U32_AT_SIZE) {
return 0;
}
/* Validate the length of size */
if (size > OHOS::FOO_MAX_LEN) {
return 0;
}
char *ch = static_cast<char *>(malloc(size + 1));
if (ch == nullptr) {
return 0;
}
(void)memset_s(ch, size + 1, 0x00, size + 1);
if (memcpy_s(ch, size, data, size) != EOK) {
free(ch);
ch = nullptr;
return 0;
}
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
free(ch);
ch = nullptr;
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 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
*
* 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 TEST_FUZZTEST_BASEBUNDLEINSTALLERREMOVEMODULEDIR_FUZZER_H
#define TEST_FUZZTEST_BASEBUNDLEINSTALLERREMOVEMODULEDIR_FUZZER_H
#define FUZZ_PROJECT_NAME "basebundleinstallerremovemoduledir_fuzzer"
#endif

View File

@ -0,0 +1,14 @@
# Copyright (c) 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
#
# 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.
FUZZ

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 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
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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,161 @@
# Copyright (c) 2021-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/test.gni")
import("../../../../appexecfwk.gni")
import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni")
module_output_path = fuzz_test_path
ohos_fuzztest("BaseBundleInstallerRenameModuleDirFuzzTest") {
fuzz_config_file = "../../../fuzztest/fuzztest_others/basebundleinstallerrenamemoduledir_fuzzer"
use_exceptions = true
module_out_path = module_output_path
include_dirs = [
"//third_party/jsoncpp/include",
"${services_path}/bundlemgr/test/mock/include/parameter",
]
sources = bundle_mgr_source
sources -= [ "${services_path}/bundlemgr/src/bms_param.cpp" ]
sources += [ "${services_path}/bundlemgr/test/mock/src/bms_param.cpp" ]
sources -= [ "${services_path}/bundlemgr/src/system_ability_helper.cpp" ]
sources += bundle_install_sources
sources -= [ "${services_path}/bundlemgr/src/installd_client.cpp" ]
sources += [ "${services_path}/bundlemgr/test/mock/src/installd_client.cpp" ]
sources += [
"${services_path}/bundlemgr/test/mock/src/accesstoken_kit.cpp",
"${services_path}/bundlemgr/test/mock/src/installd_permission_mgr.cpp",
"${services_path}/bundlemgr/test/mock/src/mock_status_receiver.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/parameter.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/parameters.cpp",
"${services_path}/bundlemgr/test/mock/src/parameter/systemcapability.cpp",
"${services_path}/bundlemgr/test/mock/src/system_ability_helper.cpp",
]
sources += [ "basebundleinstallerrenamemoduledir_fuzzer.cpp" ]
configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
deps = [ "${core_path}:appexecfwk_core" ]
deps += bundle_install_deps
external_deps = [
"ability_base:want",
"ability_runtime:app_manager",
"access_token:el5_filekey_manager_sdk",
"access_token:libprivacy_sdk",
"access_token:libtokenid_sdk",
"appverify:libhapverify",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbegetutil",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
external_deps += bundle_install_external_deps
if (bundle_framework_graphics) {
external_deps += [ "image_framework:image_native" ]
}
defines = []
if (configpolicy_enable) {
external_deps += [ "config_policy:configpolicy_util" ]
defines += [ "CONFIG_POLOCY_ENABLE" ]
}
if (build_selinux) {
external_deps += [ "selinux_adapter:libhap_restorecon" ]
}
if (account_enable) {
external_deps += [ "os_account:os_account_innerkits" ]
defines += [ "ACCOUNT_ENABLE" ]
}
if (bundle_framework_free_install) {
sources += aging
sources += free_install
sources += distributed_manager
external_deps += [
"ability_runtime:ability_manager",
"ability_runtime:app_manager",
"battery_manager:batterysrv_client",
"device_usage_statistics:usagestatsinner",
"display_manager:displaymgr",
"power_manager:powermgr_client",
"syscap_codec:syscap_interface_shared",
]
defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ]
}
if (hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (global_resmgr_enable) {
defines += [ "GLOBAL_RESMGR_ENABLE" ]
external_deps += [ "resource_management:global_resmgr" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
if (storage_service_enable) {
external_deps += [ "storage_service:storage_manager_sa_proxy" ]
defines += [ "STORAGE_SERVICE_ENABLE" ]
}
configs += [ "${services_path}/bundlemgr:rdb_config" ]
external_deps += [ "relational_store:native_rdb" ]
sources += [
"${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp",
"${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp",
"${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp",
"${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp",
]
if (bundle_framework_app_control) {
defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ]
sources += [
"${services_path}/bundlemgr/src/app_control/app_control_manager.cpp",
"${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp",
"${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp",
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp",
"${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp",
]
include_dirs += [ "${services_path}/bundlemgr/include/app_control" ]
external_deps += [ "c_utils:utils" ]
}
if (udmf_enabled) {
defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ]
external_deps += [ "udmf:udmf_client" ]
}
if (bms_device_info_manager_part_enabled) {
external_deps += [
"device_info_manager:distributed_device_profile_common",
"device_info_manager:distributed_device_profile_sdk",
]
defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ]
}
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 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
*
* 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.
*/
#define private public
#include <cstddef>
#include <cstdint>
#include "basebundleinstallerrenamemoduledir_fuzzer.h"
#include "base_bundle_installer.h"
#include "securec.h"
using namespace OHOS::AppExecFwk;
namespace OHOS {
constexpr size_t FOO_MAX_LEN = 1024;
constexpr size_t U32_AT_SIZE = 4;
bool DoSomethingInterestingWithMyAPI(const char *data, size_t size)
{
BaseBundleInstaller basebundleinstall;
InnerBundleInfo info;
auto ret1 = basebundleinstall.RenameModuleDir(info);
return true;
}
}
// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
/* Run your code on data */
if (data == nullptr) {
return 0;
}
if (size < OHOS::U32_AT_SIZE) {
return 0;
}
/* Validate the length of size */
if (size > OHOS::FOO_MAX_LEN) {
return 0;
}
char *ch = static_cast<char *>(malloc(size + 1));
if (ch == nullptr) {
return 0;
}
(void)memset_s(ch, size + 1, 0x00, size + 1);
if (memcpy_s(ch, size, data, size) != EOK) {
free(ch);
ch = nullptr;
return 0;
}
OHOS::DoSomethingInterestingWithMyAPI(ch, size);
free(ch);
ch = nullptr;
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 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
*
* 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 TEST_FUZZTEST_BASEBUNDLEINSTALLERRENAMEMODULEDIR_FUZZER_H
#define TEST_FUZZTEST_BASEBUNDLEINSTALLERRENAMEMODULEDIR_FUZZER_H
#define FUZZ_PROJECT_NAME "basebundleinstallerrenamemoduledir_fuzzer"
#endif

View File

@ -0,0 +1,14 @@
# Copyright (c) 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
#
# 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.
FUZZ

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 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
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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>