!19514 merge cz_pc_0602 into master

在开发者模式下,支持PC三方应用安装调试包

Created-by: zhongshield1
Commit-by: zhongshield1
Merged-by: openharmony_ci
Description: **IssueNo**:
https://gitcode.com/openharmony/bundlemanager_bundle_framework/issues/9477
**Description**:

**稳定性自检:**
| 自检项                                                       | 自检结果  |
| ------------------------------------------------------------ | -------- |
| 涉及跨进程调用的相关操作需要抛至主线程或加锁防止并发              |     ok     |
| 成员变量进行赋值或创建需要排查并发                               |     ok     |
| 谨慎在lambda表达式中使用引用捕获                                |     ok     |
| 谨慎在未经拷贝的情况下使用外部传入的string、C字符串               |     ok     |
| map\vector\list\set等stl模板类使用时需要排查并发                |     ok     |
| 谨慎考虑加锁范围                                               |     ok     |
| 在IPC通信中谨慎使用同步通信方式                                 |     ok     |
| 禁止传递this指针至其他模块或线程(特别是eventhandler任务)        |     ok     |
| 禁止将外部传入的裸指针在内部直接构造智能指针                      |     ok     |
| 禁止多个独立创建的智能指针管理同一地址                           |     ok     |
| 禁止在析构函数中抛异步任务                                      |     ok     |
| 禁止js对象在非js线程(例如在IPC线程)创建、使用或销毁             |     ok     |
| 禁止在对外接口中未经判空直接使用外部传入的指针                    |     ok     |
| 禁止接口返回局部变量引用                                        |     ok     |
| 禁止在信号函数中加锁                                            |     ok     |
| 禁止在关键流程(SA启动、应用启动等主流程)执行耗时的操作           |     ok     |
| 禁止将同一个cpp编译在不同的so中                                 |     ok     |

**安全编码自检:**
| 自检项                                                          | 自检结果 |
| -------------------------------------------------------------- | -------- |
| 裸指针避免通过隐式转换构造为sptr                                 |     ok     |
| json对象在取值之前必须先判断类型,避免类型不匹配                   |     ok     |
| 序列化时必须对传入的数组大小进行校验,避免出现超大数组              |     ok     |
| 避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型            |     ok     |
| 外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验 |     ok     |
| 指针变量、表示资源描述符的变量、bool变量必须赋初值                  |     ok     |
| readParcelable获取的对象使用前需要判空                            |     ok     |
| 分配和释放内存的函数需要成对出现                                   |     ok     |
| 申请内存后异常退出前需要及时进行内存释放                            |     ok     |
| 内存申请前必须对内存大小进行合法性校验                              |     ok     |
| 内存分配后必须判断是否成功                                         |     ok     |
| 禁止使用realloc、alloca函数                                       |     ok     |
| 禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰          |     ok     |
| 禁止打印内存地址                                                  |     ok     |
| 整数之间运算时必须严格检查,确保不会出现溢出、反转、除0               |     ok     |
| 禁止对有符号整数进行位操作符运算                                    |     ok     |
| 禁止对指针进行逻辑或位运算                                         |     ok     |
| 循环次数如果收外部数据控制,需要检验其合法性                         |     ok     |
| 禁止使用内存操作类危险函数,需要使用安全函数                         |     ok     |
| 谨慎使用不可重入函数                                               |     ok     |
| 必须检查安全函数的返回值,并进行正确处理                             |     ok     |
| 禁止仅通过TokenType类型判断绕过权限校验                             |     ok     |

**TDD Result**:
![image.png](https://raw.gitcode.com/user-images/assets/4421702/5dff156d-069b-4d81-9590-5145d04416ec/image.png 'image.png')
**XTS Result**:
失败XTS单独执行 pass
![image.png](https://raw.gitcode.com/user-images/assets/4421702/b038149d-b31d-4822-aad9-caa8d1814a94/image.png 'image.png')
### 是否已执行L0用例
- [ ] 已验证
- [ ] 不涉及。如不涉及,请写明理由


See merge request: openharmony/ability_ability_runtime!19514
This commit is contained in:
openharmony_ci
2026-06-26 15:49:27 +08:00
15 changed files with 285 additions and 23 deletions
@@ -1810,6 +1810,10 @@ public:
int32_t EnableDelayedProcessExit(int32_t pid, bool enabled);
void CancelDelayedExitTask(int32_t pid);
int32_t CheckAppProvisionType(
const std::string &bundleName, int32_t callerUid, int32_t appCloneIndex, int32_t userId);
private:
int32_t ForceKillApplicationInner(const std::string &bundleName, const int userId = -1,
const int appIndex = 0);
+21 -4
View File
@@ -35,6 +35,7 @@
#include "hitrace_meter.h"
#include "in_process_call_wrapper.h"
#include "ipc_skeleton.h"
#include "parameters.h"
#include "perf_profile.h"
#include "permission_constants.h"
#include "permission_verification.h"
@@ -93,6 +94,7 @@ constexpr const char* BS_PROCESS_NAME = "resource_schedule_service";
constexpr int32_t USER_UID = 2000;
constexpr const char* HIVIEW_PROCESS_NAME = "hiview";
constexpr const char* DEBUG_FROM = "ohos.param.debugFrom";
constexpr const char* DEVELOPER_MODE_STATE = "const.security.developermode.state";
} // namespace
REGISTER_SYSTEM_ABILITY_BY_ID(AppMgrService, APP_MGR_SERVICE_ID, true);
@@ -453,7 +455,10 @@ sptr<IAmsMgr> AppMgrService::GetAmsMgr()
int32_t AppMgrService::ClearUpApplicationData(const std::string &bundleName, int32_t appCloneIndex, int32_t userId)
{
if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) {
bool isDeveloperMode = OHOS::system::GetBoolParameter(DEVELOPER_MODE_STATE, false);
bool isSACaller = AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI();
if (!isSACaller && (!isDeveloperMode || !AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(
AAFwk::PermissionConstants::PERMISSION_ALLOW_USE_BM))) {
TAG_LOGE(AAFwkTag::APPMGR, "caller is not SA");
return AAFwk::ERR_NOT_SYSTEM_APP;
}
@@ -471,18 +476,30 @@ int32_t AppMgrService::ClearUpApplicationData(const std::string &bundleName, int
return ERR_INVALID_OPERATION;
}
int32_t callingUid = IPCSkeleton::GetCallingUid();
bool isCheckDebugApp = false;
if ((callingUid != 0 && callingUid != USER_UID) || userId < 0) {
auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(
AAFwk::PermissionConstants::PERMISSION_CLEAN_APPLICATION_DATA);
if (!isCallingPerm) {
TAG_LOGE(AAFwkTag::APPMGR, "verification failed");
return AAFwk::CHECK_PERMISSION_FAILED;
if (!isSACaller || !isCallingPerm) {
if (!isDeveloperMode ||
!AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(
AAFwk::PermissionConstants::PERMISSION_ALLOW_USE_BM)) {
TAG_LOGE(AAFwkTag::APPMGR, "verification failed");
return AAFwk::CHECK_PERMISSION_FAILED;
}
isCheckDebugApp = true;
}
}
if (appCloneIndex < 0 || appCloneIndex > AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
TAG_LOGE(AAFwkTag::APPMGR, "appCloneIndex invalid");
return AAFwk::ERR_APP_CLONE_INDEX_INVALID;
}
if (isCheckDebugApp) {
auto ret = appMgrServiceInner_->CheckAppProvisionType(bundleName, callingUid, appCloneIndex, userId);
if (ret != ERR_OK) {
return ret;
}
}
pid_t pid = IPCSkeleton::GetCallingPid();
return appMgrServiceInner_->ClearUpApplicationData(bundleName, callingUid, pid, appCloneIndex, userId);
}
@@ -3727,6 +3727,33 @@ int32_t AppMgrServiceInner::KillApplicationByUserIdLocked(
return WaitProcessesExitAndKill(pids, startTime, "KillApplicationByUserId");
}
int32_t AppMgrServiceInner::CheckAppProvisionType(
const std::string &bundleName, int32_t callerUid, int32_t appCloneIndex, int32_t userId)
{
int32_t newUserId = userId;
if (userId == DEFAULT_INVAL_VALUE) {
newUserId = GetUserIdByUid(callerUid);
if (newUserId == U0_USER_ID || newUserId == U1_USER_ID) {
newUserId = UserController::GetInstance().GetForegroundUserId(DEFAULT_DISPLAY_ID);
}
}
auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper();
if (bundleMgrHelper == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "bundleMgrHelper null");
return ERR_INVALID_OPERATION;
}
ApplicationInfo appInfo;
if (!IN_PROCESS_CALL(
bundleMgrHelper->GetApplicationInfoWithAppIndex(bundleName, appCloneIndex, newUserId, appInfo))) {
TAG_LOGE(AAFwkTag::APPMGR, "delete user data fail");
return AAFwk::ERR_APP_CLONE_INDEX_INVALID;
}
if (appInfo.appProvisionType != AppExecFwk::Constants::APP_PROVISION_TYPE_DEBUG) {
return AAFwk::CHECK_PERMISSION_FAILED;
}
return ERR_OK;
}
int32_t AppMgrServiceInner::ClearUpApplicationData(const std::string &bundleName,
int32_t callerUid, pid_t callerPid, int32_t appCloneIndex, int32_t userId)
{
@@ -90,6 +90,7 @@ constexpr const char* PERMISSION_MODIFY_AGENT_CARD = "ohos.permission.MODIFY_AGE
constexpr const char* PERMISSION_START_ABILITY_TO_PAGE = "ohos.permission.START_ABILITY_TO_PAGE";
constexpr const char* PERMISSION_CONTINUATION_NOTIFY = "ohos.permission.CONTINUATION_NOTIFY";
constexpr const char* PERMISSION_EXECUTE_DISTRIBUTED_INTENT = "ohos.permission.EXECUTE_DISTRIBUTED_INTENT";
constexpr const char* PERMISSION_ALLOW_USE_BM = "ohos.permission.ALLOW_USE_BM";
} // namespace PermissionConstants
} // namespace AAFwk
} // namespace OHOS
+2
View File
@@ -72,6 +72,7 @@ ohos_shared_library("quickfixms") {
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_single",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
@@ -110,6 +111,7 @@ ohos_static_library("quickfixms_static") {
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_single",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
@@ -38,7 +38,8 @@ public:
QUICK_FIX_REVOKE,
};
void Run(const std::vector<std::string> &quickFixFiles, bool isDebug = false, bool isReplace = false);
void Run(const std::vector<std::string> &quickFixFiles, bool isDebug = false, bool isReplace = false,
bool isCheckDebugApp = false);
void HandlePatchDeployed();
void HandlePatchSwitched();
void HandlePatchDeleted();
@@ -66,7 +67,7 @@ public:
void PostRevokeQuickFixProcessDiedTask();
private:
void PostDeployQuickFixTask(const std::vector<std::string> &quickFixFiles, bool isDebug = false,
bool isReplace = false);
bool isReplace = false, bool isCheckDebugApp = false);
void PostTimeOutTask();
void PostNotifyLoadRepairPatchTask();
void PostNotifyUnloadRepairPatchTask();
@@ -307,12 +307,13 @@ QuickFixManagerApplyTask::~QuickFixManagerApplyTask()
TAG_LOGD(AAFwkTag::QUICKFIX, "destroyed");
}
void QuickFixManagerApplyTask::Run(const std::vector<std::string> &quickFixFiles, bool isDebug, bool isReplace)
void QuickFixManagerApplyTask::Run(const std::vector<std::string> &quickFixFiles, bool isDebug, bool isReplace,
bool isCheckDebugApp)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::QUICKFIX, "Run apply task");
taskType_ = TaskType::QUICK_FIX_APPLY;
PostDeployQuickFixTask(quickFixFiles, isDebug, isReplace);
PostDeployQuickFixTask(quickFixFiles, isDebug, isReplace, isCheckDebugApp);
}
void QuickFixManagerApplyTask::RunRevoke()
@@ -386,7 +387,7 @@ void QuickFixManagerApplyTask::HandlePatchDeleted()
}
void QuickFixManagerApplyTask::PostDeployQuickFixTask(const std::vector<std::string> &quickFixFiles, bool isDebug,
bool isReplace)
bool isReplace, bool isCheckDebugApp)
{
auto callback = sptr<QuickFixManagerStatusCallback>::MakeSptr(shared_from_this());
if (callback == nullptr) {
@@ -397,7 +398,7 @@ void QuickFixManagerApplyTask::PostDeployQuickFixTask(const std::vector<std::str
}
std::weak_ptr<QuickFixManagerApplyTask> thisWeakPtr(weak_from_this());
auto deployTask = [thisWeakPtr, quickFixFiles, callback, isDebug, isReplace]() {
auto deployTask = [thisWeakPtr, quickFixFiles, callback, isDebug, isReplace, isCheckDebugApp]() {
auto applyTask = thisWeakPtr.lock();
if (applyTask == nullptr) {
TAG_LOGE(AAFwkTag::QUICKFIX, "null apply task");
@@ -411,8 +412,10 @@ void QuickFixManagerApplyTask::PostDeployQuickFixTask(const std::vector<std::str
return;
}
TAG_LOGD(AAFwkTag::QUICKFIX, "isDebug is %{public}d isReplace is %{public}d", isDebug, isReplace);
auto ret = applyTask->bundleQfMgr_->DeployQuickFix(quickFixFiles, callback, isDebug, "", isReplace);
TAG_LOGD(AAFwkTag::QUICKFIX, "isDebug is %{public}d isReplace is %{public}d isCheckDebugApp is %{public}d",
isDebug, isReplace, isCheckDebugApp);
auto ret =
applyTask->bundleQfMgr_->DeployQuickFix(quickFixFiles, callback, isDebug, "", isReplace, isCheckDebugApp);
if (ret != 0) {
TAG_LOGE(AAFwkTag::QUICKFIX, "failed: %{public}d", ret);
applyTask->NotifyApplyStatus(QUICK_FIX_DEPLOY_FAILED);
@@ -18,12 +18,16 @@
#include "bundle_mgr_helper.h"
#include "hilog_tag_wrapper.h"
#include "hitrace_meter.h"
#include "parameters.h"
#include "permission_constants.h"
#include "permission_verification.h"
#include "quick_fix_error_utils.h"
#include "quick_fix_utils.h"
namespace OHOS {
namespace AAFwk {
constexpr const char* DEVELOPER_MODE_STATE = "const.security.developermode.state";
std::mutex QuickFixManagerService::mutex_;
sptr<QuickFixManagerService> QuickFixManagerService::instance_;
@@ -60,12 +64,21 @@ int32_t QuickFixManagerService::ApplyQuickFix(const std::vector<std::string> &qu
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGD(AAFwkTag::QUICKFIX, "called");
if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) {
bool isSACaller = AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI();
bool isDeveloperMode = OHOS::system::GetBoolParameter(DEVELOPER_MODE_STATE, false);
if (!isSACaller && (!isDeveloperMode || !AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(
AAFwk::PermissionConstants::PERMISSION_ALLOW_USE_BM))) {
TAG_LOGE(AAFwkTag::QUICKFIX, "caller not system-app,not use system-api");
return QUICK_FIX_NOT_SYSTEM_APP;
}
if (!AAFwk::PermissionVerification::GetInstance()->VerifyInstallBundlePermission()) {
return QUICK_FIX_VERIFY_PERMISSION_FAILED;
bool isCheckDebugApp = false;
if (!isSACaller || !AAFwk::PermissionVerification::GetInstance()->VerifyInstallBundlePermission()) {
if (!isDeveloperMode ||
!AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(
AAFwk::PermissionConstants::PERMISSION_ALLOW_USE_BM)) {
return QUICK_FIX_VERIFY_PERMISSION_FAILED;
}
isCheckDebugApp = true;
}
auto bundleQfMgr = QuickFixUtil::GetBundleQuickFixMgrProxy();
@@ -81,7 +94,7 @@ int32_t QuickFixManagerService::ApplyQuickFix(const std::vector<std::string> &qu
}
auto applyTask = std::make_shared<QuickFixManagerApplyTask>(bundleQfMgr, appMgr, eventHandler_, this);
AddApplyTask(applyTask);
applyTask->Run(quickFixFiles, isDebug, isReplace);
applyTask->Run(quickFixFiles, isDebug, isReplace, isCheckDebugApp);
return QUICK_FIX_OK;
}
@@ -91,12 +104,21 @@ int32_t QuickFixManagerService::GetApplyedQuickFixInfo(const std::string &bundle
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGD(AAFwkTag::QUICKFIX, "called");
if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) {
bool isSACaller = AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI();
bool isDeveloperMode = OHOS::system::GetBoolParameter(DEVELOPER_MODE_STATE, false);
if (!isSACaller && (!isDeveloperMode || !AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(
AAFwk::PermissionConstants::PERMISSION_ALLOW_USE_BM))) {
TAG_LOGE(AAFwkTag::QUICKFIX, "caller not system-app,not use system-api");
return QUICK_FIX_NOT_SYSTEM_APP;
}
if (!AAFwk::PermissionVerification::GetInstance()->VerifyGetBundleInfoPrivilegedPermission()) {
return QUICK_FIX_VERIFY_PERMISSION_FAILED;
bool isCheckDebugApp = false;
if (!isSACaller || !AAFwk::PermissionVerification::GetInstance()->VerifyGetBundleInfoPrivilegedPermission()) {
if (!isDeveloperMode ||
!AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(
AAFwk::PermissionConstants::PERMISSION_ALLOW_USE_BM)) {
return QUICK_FIX_VERIFY_PERMISSION_FAILED;
}
isCheckDebugApp = true;
}
auto bundleMgrHelper = DelayedSingleton<AppExecFwk::BundleMgrHelper>::GetInstance();
@@ -111,6 +133,11 @@ int32_t QuickFixManagerService::GetApplyedQuickFixInfo(const std::string &bundle
TAG_LOGE(AAFwkTag::QUICKFIX, "get bundleInfo failed");
return QUICK_FIX_GET_BUNDLE_INFO_FAILED;
}
if (isCheckDebugApp &&
bundleInfo.applicationInfo.appProvisionType != AppExecFwk::Constants::APP_PROVISION_TYPE_DEBUG) {
TAG_LOGE(AAFwkTag::QUICKFIX, "not debug version");
return QUICK_FIX_VERIFY_PERMISSION_FAILED;
}
quickFixInfo.bundleName = bundleName;
quickFixInfo.bundleVersionCode = bundleInfo.versionCode;
@@ -168,9 +168,9 @@ public:
class QuickFixManagerHostImpl : public QuickFixManagerHost {
public:
MOCK_METHOD5(DeployQuickFix, ErrCode(const std::vector<std::string>& bundleFilePaths,
MOCK_METHOD6(DeployQuickFix, ErrCode(const std::vector<std::string>& bundleFilePaths,
const sptr<IQuickFixStatusCallback>& statusCallback, bool isDebug, const std::string& targetPath,
bool isReplace));
bool isReplace, bool isCheckDebugApp));
MOCK_METHOD3(SwitchQuickFix, ErrCode(const std::string& bundleName, bool enable,
const sptr<IQuickFixStatusCallback>& statusCallback));
MOCK_METHOD2(DeleteQuickFix, ErrCode(const std::string& bundleName,
@@ -36,6 +36,8 @@ using namespace OHOS::Rosen;
using OHOS::AppExecFwk::ExtensionAbilityType;
constexpr int32_t FOUNDATION_UID = 5523;
constexpr int32_t SHADER_CACHE_GROUPID = 3099;
constexpr int32_t DEFAULT_INVAL_VALUE = -1;
constexpr int32_t BASE_USER_RANGE = 200000;
namespace OHOS {
namespace AppExecFwk {
class AppMgrServiceInnerSeventhTest : public testing::Test {
@@ -3147,5 +3149,80 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, GetBackgroundAppInfo_012, TestSize.Level
EXPECT_EQ(res.size(), 0);
TAG_LOGI(AAFwkTag::TEST, "GetBackgroundAppInfo_012 end");
}
/**
* @tc.name: CheckAppProvisionType_0100
* @tc.desc: test CheckAppProvisionType
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerSeventhTest, CheckAppProvisionType_0100, TestSize.Level1)
{
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(appMgrServiceInner, nullptr);
AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = nullptr;
std::string bundleName = "testBundleName";
int32_t callerUid = 0;
int32_t appCloneIndex = 0;
int32_t userId = DEFAULT_INVAL_VALUE;
auto ret = appMgrServiceInner->CheckAppProvisionType(bundleName, callerUid, appCloneIndex, userId);
EXPECT_EQ(ret, ERR_INVALID_OPERATION);
callerUid = BASE_USER_RANGE;
ret = appMgrServiceInner->CheckAppProvisionType(bundleName, callerUid, appCloneIndex, userId);
EXPECT_EQ(ret, ERR_INVALID_OPERATION);
userId = 100;
ret = appMgrServiceInner->CheckAppProvisionType(bundleName, callerUid, appCloneIndex, userId);
EXPECT_EQ(ret, ERR_INVALID_OPERATION);
callerUid = 100;
ret = appMgrServiceInner->CheckAppProvisionType(bundleName, callerUid, appCloneIndex, userId);
EXPECT_EQ(ret, ERR_INVALID_OPERATION);
}
/**
* @tc.name: CheckAppProvisionType_0200
* @tc.desc: test CheckAppProvisionType
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerSeventhTest, CheckAppProvisionType_0200, TestSize.Level1)
{
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(appMgrServiceInner, nullptr);
AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared<BundleMgrHelper>();
const std::string bundleName = "";
int32_t callerUid = BASE_USER_RANGE;
int32_t appCloneIndex = 1;
int32_t userId = DEFAULT_INVAL_VALUE;
auto ret = appMgrServiceInner->CheckAppProvisionType(bundleName, callerUid, appCloneIndex, userId);
EXPECT_EQ(ret, AAFwk::ERR_APP_CLONE_INDEX_INVALID);
}
/**
* @tc.name: CheckAppProvisionType_0300
* @tc.desc: test CheckAppProvisionType
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerSeventhTest, CheckAppProvisionType_0300, TestSize.Level1)
{
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(appMgrServiceInner, nullptr);
AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared<BundleMgrHelper>();
AAFwk::MyStatus::GetInstance().getApplicationInfoWithAppIndexRet_ = true;
AAFwk::MyStatus::GetInstance().applicationInfo_ = {};
const std::string bundleName = "";
int32_t callerUid = BASE_USER_RANGE;
int32_t appCloneIndex = 1;
int32_t userId = DEFAULT_INVAL_VALUE;
auto ret = appMgrServiceInner->CheckAppProvisionType(bundleName, callerUid, appCloneIndex, userId);
EXPECT_EQ(ret, AAFwk::CHECK_PERMISSION_FAILED);
AAFwk::MyStatus::GetInstance().applicationInfo_.appProvisionType = "debug";
ret = appMgrServiceInner->CheckAppProvisionType(bundleName, callerUid, appCloneIndex, userId);
EXPECT_EQ(ret, ERR_OK);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -101,6 +101,7 @@ public:
int getSpawnClientCall_ = 0;
// app spawn client
int32_t startProcess_ = ERR_OK;
bool getApplicationInfoWithAppIndexRet_ = false;
private:
MyStatus() = default;
};
@@ -219,7 +219,8 @@ bool BundleMgrHelper::GetApplicationInfo(const std::string& appName,
bool BundleMgrHelper::GetApplicationInfoWithAppIndex(
const std::string& appName, int32_t appIndex, int32_t userId, ApplicationInfo& appInfo)
{
return false;
appInfo = AAFwk::MyStatus::GetInstance().applicationInfo_;
return AAFwk::MyStatus::GetInstance().getApplicationInfoWithAppIndexRet_;
}
ErrCode BundleMgrHelper::GetJsonProfile(ProfileType profileType, const std::string& bundleName,
@@ -2636,5 +2636,22 @@ HWTEST_F(AppMgrServiceTest, IsChildProcessSupported_0100, TestSize.Level1)
auto ret = appMgrService->IsChildProcessSupported(false, isSupported);
EXPECT_EQ(ret, ERR_INVALID_OPERATION);
}
/**
* @tc.name: ClearUpApplicationData_0100
* @tc.desc: test ClearUpApplicationData
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceTest, ClearUpApplicationData_0100, TestSize.Level1)
{
auto appMgrService = std::make_shared<AppMgrService>();
ASSERT_NE(appMgrService, nullptr);
appMgrService->SetInnerService(std::make_shared<AppMgrServiceInner>());
appMgrService->taskHandler_ = taskHandler_;
appMgrService->eventHandler_ = std::make_shared<AMSEventHandler>(taskHandler_, appMgrService->appMgrServiceInner_);
std::string bundleName = "bundleName";
auto ret = appMgrService->ClearUpApplicationData(bundleName, 0);
EXPECT_EQ(ret, AAFwk::CHECK_PERMISSION_FAILED);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -287,5 +287,89 @@ HWTEST_F(QuickFixManagerServiceTest, RevokeQuickFix_0300, TestSize.Level1)
TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
}
/**
* @tc.name: ApplyQuickFix_0600
* @tc.desc: test ApplyQuickFix
* @tc.type: FUNC
*/
HWTEST_F(QuickFixManagerServiceTest, ApplyQuickFix_0600, TestSize.Level1)
{
MyFlag::isAllowedToUseSystemAPIFlag_ = false;
MyFlag::verifyCallingPermissionFlag_ = false;
std::vector<std::string> quickFixFiles;
auto ret = quickFixMs_->ApplyQuickFix(quickFixFiles);
EXPECT_EQ(ret, QUICK_FIX_NOT_SYSTEM_APP);
MyFlag::verifyCallingPermissionFlag_ = true;
ret = quickFixMs_->ApplyQuickFix(quickFixFiles);
EXPECT_EQ(ret, QUICK_FIX_CONNECT_FAILED);
}
/**
* @tc.name: ApplyQuickFix_0700
* @tc.desc: test ApplyQuickFix
* @tc.type: FUNC
*/
HWTEST_F(QuickFixManagerServiceTest, ApplyQuickFix_0700, TestSize.Level1)
{
MyFlag::isAllowedToUseSystemAPIFlag_ = true;
MyFlag::isVerifyInstallBundlePermission_ = true;
std::vector<std::string> quickFixFiles;
auto ret = quickFixMs_->ApplyQuickFix(quickFixFiles);
EXPECT_EQ(ret, QUICK_FIX_CONNECT_FAILED);
MyFlag::isVerifyInstallBundlePermission_ = false;
MyFlag::verifyCallingPermissionFlag_ = false;
ret = quickFixMs_->ApplyQuickFix(quickFixFiles);
EXPECT_EQ(ret, QUICK_FIX_VERIFY_PERMISSION_FAILED);
MyFlag::verifyCallingPermissionFlag_ = true;
ret = quickFixMs_->ApplyQuickFix(quickFixFiles);
EXPECT_EQ(ret, QUICK_FIX_CONNECT_FAILED);
}
/**
* @tc.name: GetApplyedQuickFixInfo_0400
* @tc.desc: test GetApplyedQuickFixInfo
* @tc.type: FUNC
*/
HWTEST_F(QuickFixManagerServiceTest, GetApplyedQuickFixInfo_0400, TestSize.Level1)
{
MyFlag::isAllowedToUseSystemAPIFlag_ = false;
MyFlag::verifyCallingPermissionFlag_ = false;
std::string bundleName = "test bundleName";
ApplicationQuickFixInfo quickFixFileInfo;
auto ret = quickFixMs_->GetApplyedQuickFixInfo(bundleName, quickFixFileInfo);
EXPECT_EQ(ret, QUICK_FIX_NOT_SYSTEM_APP);
MyFlag::verifyCallingPermissionFlag_ = true;
ret = quickFixMs_->GetApplyedQuickFixInfo(bundleName, quickFixFileInfo);
EXPECT_EQ(ret, QUICK_FIX_GET_BUNDLE_INFO_FAILED);
}
/**
* @tc.name: GetApplyedQuickFixInfo_0500
* @tc.desc: test GetApplyedQuickFixInfo
* @tc.type: FUNC
*/
HWTEST_F(QuickFixManagerServiceTest, GetApplyedQuickFixInfo_0500, TestSize.Level1)
{
MyFlag::isAllowedToUseSystemAPIFlag_ = true;
MyFlag::isVerifyPrivilegedPermission_ = true;
std::string bundleName = "test bundleName";
ApplicationQuickFixInfo quickFixFileInfo;
auto ret = quickFixMs_->GetApplyedQuickFixInfo(bundleName, quickFixFileInfo);
EXPECT_EQ(ret, QUICK_FIX_GET_BUNDLE_INFO_FAILED);
MyFlag::isVerifyPrivilegedPermission_ = false;
MyFlag::verifyCallingPermissionFlag_ = false;
ret = quickFixMs_->GetApplyedQuickFixInfo(bundleName, quickFixFileInfo);
EXPECT_EQ(ret, QUICK_FIX_VERIFY_PERMISSION_FAILED);
MyFlag::verifyCallingPermissionFlag_ = true;
ret = quickFixMs_->GetApplyedQuickFixInfo(bundleName, quickFixFileInfo);
EXPECT_EQ(ret, QUICK_FIX_GET_BUNDLE_INFO_FAILED);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -147,7 +147,7 @@ HWTEST_F(QuickFixManagerApplyTaskTest, Run_0100, TestSize.Level1)
quickFixMs_->eventHandler_, quickFixMs_);
ASSERT_NE(applyTask, nullptr);
EXPECT_CALL(*bundleQfMgr_, DeployQuickFix(_, _, _, _, _)).Times(1);
EXPECT_CALL(*bundleQfMgr_, DeployQuickFix(_, _, _, _, _, _)).Times(1);
std::vector<std::string> quickFixFiles;
applyTask->Run(quickFixFiles);
WaitUntilTaskDone(quickFixMs_->eventHandler_);