diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 8d98c33fcd..ba376fcdca 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -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); diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 7272014710..8fe0c7c885 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -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 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); } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index ad3d3a474b..da48aa33a1 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -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) { diff --git a/services/common/include/permission_constants.h b/services/common/include/permission_constants.h index 2d4ecd7d62..73f78d2c3a 100644 --- a/services/common/include/permission_constants.h +++ b/services/common/include/permission_constants.h @@ -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 diff --git a/services/quickfixmgr/BUILD.gn b/services/quickfixmgr/BUILD.gn index 524e859aa3..d845102734 100644 --- a/services/quickfixmgr/BUILD.gn +++ b/services/quickfixmgr/BUILD.gn @@ -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", diff --git a/services/quickfixmgr/include/quick_fix_manager_apply_task.h b/services/quickfixmgr/include/quick_fix_manager_apply_task.h index 014ead32aa..e749cbdc36 100644 --- a/services/quickfixmgr/include/quick_fix_manager_apply_task.h +++ b/services/quickfixmgr/include/quick_fix_manager_apply_task.h @@ -38,7 +38,8 @@ public: QUICK_FIX_REVOKE, }; - void Run(const std::vector &quickFixFiles, bool isDebug = false, bool isReplace = false); + void Run(const std::vector &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 &quickFixFiles, bool isDebug = false, - bool isReplace = false); + bool isReplace = false, bool isCheckDebugApp = false); void PostTimeOutTask(); void PostNotifyLoadRepairPatchTask(); void PostNotifyUnloadRepairPatchTask(); diff --git a/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp b/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp index c3df24f70b..a5c6734ce8 100644 --- a/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp +++ b/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp @@ -307,12 +307,13 @@ QuickFixManagerApplyTask::~QuickFixManagerApplyTask() TAG_LOGD(AAFwkTag::QUICKFIX, "destroyed"); } -void QuickFixManagerApplyTask::Run(const std::vector &quickFixFiles, bool isDebug, bool isReplace) +void QuickFixManagerApplyTask::Run(const std::vector &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 &quickFixFiles, bool isDebug, - bool isReplace) + bool isReplace, bool isCheckDebugApp) { auto callback = sptr::MakeSptr(shared_from_this()); if (callback == nullptr) { @@ -397,7 +398,7 @@ void QuickFixManagerApplyTask::PostDeployQuickFixTask(const std::vector 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::vectorbundleQfMgr_->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); diff --git a/services/quickfixmgr/src/quick_fix_manager_service.cpp b/services/quickfixmgr/src/quick_fix_manager_service.cpp index 472bc29f76..74aad0def4 100644 --- a/services/quickfixmgr/src/quick_fix_manager_service.cpp +++ b/services/quickfixmgr/src/quick_fix_manager_service.cpp @@ -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::instance_; @@ -60,12 +64,21 @@ int32_t QuickFixManagerService::ApplyQuickFix(const std::vector &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 &qu } auto applyTask = std::make_shared(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::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; diff --git a/test/mock/services_appmgr_test/include/mock_bundle_manager.h b/test/mock/services_appmgr_test/include/mock_bundle_manager.h index 78c15388e1..704c75989e 100644 --- a/test/mock/services_appmgr_test/include/mock_bundle_manager.h +++ b/test/mock/services_appmgr_test/include/mock_bundle_manager.h @@ -168,9 +168,9 @@ public: class QuickFixManagerHostImpl : public QuickFixManagerHost { public: - MOCK_METHOD5(DeployQuickFix, ErrCode(const std::vector& bundleFilePaths, + MOCK_METHOD6(DeployQuickFix, ErrCode(const std::vector& bundleFilePaths, const sptr& 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& statusCallback)); MOCK_METHOD2(DeleteQuickFix, ErrCode(const std::string& bundleName, diff --git a/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp b/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp index 8f9bd434c8..625a10160a 100644 --- a/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp +++ b/test/unittest/app_mgr_service_inner_seventh_test/app_mgr_service_inner_seventh_test.cpp @@ -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(); + 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(); + EXPECT_NE(appMgrServiceInner, nullptr); + AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); + + 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(); + EXPECT_NE(appMgrServiceInner, nullptr); + AAFwk::MyStatus::GetInstance().getBundleManagerHelper_ = std::make_shared(); + 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 diff --git a/test/unittest/app_mgr_service_inner_seventh_test/mock/include/mock_my_status.h b/test/unittest/app_mgr_service_inner_seventh_test/mock/include/mock_my_status.h index 471bd195e7..8d097a55b7 100755 --- a/test/unittest/app_mgr_service_inner_seventh_test/mock/include/mock_my_status.h +++ b/test/unittest/app_mgr_service_inner_seventh_test/mock/include/mock_my_status.h @@ -101,6 +101,7 @@ public: int getSpawnClientCall_ = 0; // app spawn client int32_t startProcess_ = ERR_OK; + bool getApplicationInfoWithAppIndexRet_ = false; private: MyStatus() = default; }; diff --git a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp index f84ee1be7f..d2d254e99d 100755 --- a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp @@ -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, diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index 63977f8635..eb6cde3069 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -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(); + ASSERT_NE(appMgrService, nullptr); + appMgrService->SetInnerService(std::make_shared()); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); + std::string bundleName = "bundleName"; + auto ret = appMgrService->ClearUpApplicationData(bundleName, 0); + EXPECT_EQ(ret, AAFwk::CHECK_PERMISSION_FAILED); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/quick_fix/quick_fix_manager_service_second_test/quick_fix_manager_service_second_test.cpp b/test/unittest/quick_fix/quick_fix_manager_service_second_test/quick_fix_manager_service_second_test.cpp index 6190f0b50a..9ac07e5404 100644 --- a/test/unittest/quick_fix/quick_fix_manager_service_second_test/quick_fix_manager_service_second_test.cpp +++ b/test/unittest/quick_fix/quick_fix_manager_service_second_test/quick_fix_manager_service_second_test.cpp @@ -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 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 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 \ No newline at end of file diff --git a/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_apply_task_test.cpp b/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_apply_task_test.cpp index 9e4c48916b..eb77f99041 100644 --- a/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_apply_task_test.cpp +++ b/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_apply_task_test.cpp @@ -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 quickFixFiles; applyTask->Run(quickFixFiles); WaitUntilTaskDone(quickFixMs_->eventHandler_);