diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 2f3e802639024bec4033705a26c479e464bfeeb5..be9866e5874dda36ea66c681149c71ec4cfa86d0 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2834,7 +2834,7 @@ private: std::mutex prepareTermiationCallbackMutex_; std::map> prepareTermiationCallbacks_; - std::shared_ptr abilityEventHelper_; + AbilityEventUtil abilityEventHelper_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/utils/ability_event_util.h b/services/abilitymgr/include/utils/ability_event_util.h index 4e6d67254b9eaf5e5783351e16803c6f2168621f..99d90e178e54b796830cb8d8e697b985b75c251c 100644 --- a/services/abilitymgr/include/utils/ability_event_util.h +++ b/services/abilitymgr/include/utils/ability_event_util.h @@ -20,7 +20,7 @@ #include "bundle_pack_info.h" #include "event_report.h" -#include "task_handler_wrap.h" +#include "ffrt.h" namespace OHOS { namespace AAFwk { @@ -28,14 +28,11 @@ class AbilityEventUtil { public: AbilityEventUtil() = default; - AbilityEventUtil(std::shared_ptr taskHandler) : taskHandler_(taskHandler) {} void HandleModuleInfoUpdated(const std::string &bundleName, const int uid, const std::string &moduleName, bool isPlugin); void SendStartAbilityErrorEvent(EventInfo &eventInfo, int32_t errCode, const std::string errMsg, bool isSystemError = false); -private: - std::shared_ptr taskHandler_; }; } // namespace AAFwk diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 87192be9a16ba880e2089033df01afb0a76897d6..7d39b34e06064baba1a405111f8bec779b4a7356 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -432,7 +432,6 @@ bool AbilityManagerService::Init() appExitReasonHelper_ = std::make_shared(subManagersHelper_); insightIntentEventMgr_ = std::make_shared(); insightIntentEventMgr_->SubscribeSysEventReceiver(); - abilityEventHelper_ = std::make_shared(taskHandler_); TAG_LOGI(AAFwkTag::ABILITYMGR, "init success"); return true; } @@ -658,7 +657,7 @@ int32_t AbilityManagerService::StartAbilityByFreeInstall(const Want &want, sptr< if ((flags & Want::FLAG_ABILITY_CONTINUATION) == Want::FLAG_ABILITY_CONTINUATION) { TAG_LOGE(AAFwkTag::ABILITYMGR, "not allow startAbility with continuation flags:%{public}d", ERR_INVALID_CONTINUATION_FLAG); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, "continuation flags not allowed"); return ERR_INVALID_CONTINUATION_FLAG; } @@ -696,7 +695,7 @@ int AbilityManagerService::StartAbilityWithSpecifyTokenIdInner(const Want &want, if ((flags & Want::FLAG_ABILITY_CONTINUATION) == Want::FLAG_ABILITY_CONTINUATION) { TAG_LOGE(AAFwkTag::ABILITYMGR, "startAbility with continuation flags not allowed:%{public}d", ERR_INVALID_CONTINUATION_FLAG); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, "continuation flags not allowed"); return ERR_INVALID_CONTINUATION_FLAG; } @@ -836,7 +835,7 @@ int AbilityManagerService::StartAbilityOnlyUIAbility(const Want &want, const spt SendAbilityEvent(EventName::START_ABILITY, HiSysEventType::BEHAVIOR, eventInfo); if ((flags & Want::FLAG_ABILITY_CONTINUATION) == Want::FLAG_ABILITY_CONTINUATION) { TAG_LOGE(AAFwkTag::ABILITYMGR, "StartAbility not allowed:%{public}d", ERR_INVALID_CONTINUATION_FLAG); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, "not allowed"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, "not allowed"); return ERR_INVALID_CONTINUATION_FLAG; } @@ -877,7 +876,7 @@ int AbilityManagerService::StartAbilityAsCallerDetails(const Want &want, const s if ((flags & Want::FLAG_ABILITY_CONTINUATION) == Want::FLAG_ABILITY_CONTINUATION) { TAG_LOGE(AAFwkTag::ABILITYMGR, "startAbility with continuation flags not allowed:%{public}d", ERR_INVALID_CONTINUATION_FLAG); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, "continuation flags not allowed"); return ERR_INVALID_CONTINUATION_FLAG; } @@ -1156,7 +1155,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrSendStartAbilityErrorEvent(eventInfo, CHECK_PERMISSION_FAILED, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, CHECK_PERMISSION_FAILED, "permission verification failed"); return CHECK_PERMISSION_FAILED; } @@ -1179,7 +1178,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrVerifyFusionAccessPermission(); if (!isSpecificSA) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s verificationAllToken failed", __func__); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CALLER, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CALLER, "verificationAllToken failed"); return ERR_INVALID_CALLER; } @@ -1208,7 +1207,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrDoProcess(interceptorParam); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "interceptorExecuter_ null or DoProcess error"); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "DoProcess error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "DoProcess error"); return result; } @@ -1225,7 +1224,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrSendStartAbilityErrorEvent(eventInfo, ERR_CROSS_USER, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_CROSS_USER, "multi-user non-concurrent unsatisfied"); return ERR_CROSS_USER; } @@ -1252,7 +1251,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrImplicitStartAbility(abilityRequest, validUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "implicit start ability error:%{public}d", result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "implicit start error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "implicit start error"); } return result; } @@ -1304,7 +1303,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrSendStartAbilityErrorEvent(eventInfo, result, "GenerateAbilityRequest error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "GenerateAbilityRequest error"); return result; } @@ -1346,7 +1345,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrSendStartAbilityErrorEvent(eventInfo, result, "checkStaticCfgPermission error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "checkStaticCfgPermission error"); return ERR_STATIC_CFG_PERMISSION; } @@ -1355,7 +1354,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrSendStartAbilityErrorEvent(eventInfo, result, "checkCallPermission error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "checkCallPermission error"); return result; } if (!HandleExecuteSAInterceptor(want, callerToken, abilityRequest, result)) { @@ -1391,7 +1390,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrSendStartAbilityErrorEvent(eventInfo, result, "app data ability preloading failed"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "app data ability preloading failed"); return result; } } @@ -1405,7 +1404,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrSendStartAbilityErrorEvent(eventInfo, ERR_WOULD_BLOCK, "isAbilityControllerStart failed"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_WOULD_BLOCK, "isAbilityControllerStart failed"); return ERR_WOULD_BLOCK; } @@ -1562,7 +1561,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt !DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: permission verification failed:%{public}d", __func__, CHECK_PERMISSION_FAILED); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, CHECK_PERMISSION_FAILED, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, CHECK_PERMISSION_FAILED, "permission verification failed"); return CHECK_PERMISSION_FAILED; } @@ -1575,13 +1574,13 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt IPCSkeleton::GetCallingUid() != DMS_UID) { TAG_LOGE(AAFwkTag::ABILITYMGR, "The flag only support for DMS, flag:%{public}d, error:%{public}d", want.GetFlags(), ERR_INVALID_CONTINUATION_FLAG); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, "flags not allowed"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, "flags not allowed"); return ERR_INVALID_CONTINUATION_FLAG; } if (callerToken != nullptr && !VerificationAllToken(callerToken)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "verify callerToken failed:%{public}d", ERR_INVALID_CALLER); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CALLER, "verify callerToken failed"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CALLER, "verify callerToken failed"); return ERR_INVALID_CALLER; } @@ -1604,7 +1603,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt interceptorExecuter_->DoProcess(interceptorParam); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "interceptorExecuter_ null or doProcess error:%{public}d", result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "doProcess error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "doProcess error"); return result; } @@ -1623,7 +1622,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt if (!JudgeMultiUserConcurrency(validUserId)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "multi-user non-concurrent unsatisfied:%{publid}d", ERR_CROSS_USER); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_CROSS_USER, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_CROSS_USER, "multi-user non-concurrent unsatisfied"); return ERR_CROSS_USER; } @@ -1643,7 +1642,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt result = implicitStartProcessor_->ImplicitStartAbility(abilityRequest, validUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "implicit start ability error:%{public}d", result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "implicit start error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "implicit start error"); } return result; } @@ -1654,7 +1653,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt result = GenerateAbilityRequest(want, requestCode, abilityRequest, callerToken, validUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request local error:%{public}d", result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "GenerateAbilityRequest error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "GenerateAbilityRequest error"); return result; } abilityRequest.want.RemoveParam(PARAM_SPECIFIED_PROCESS_FLAG); @@ -1667,14 +1666,14 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt result = CheckStaticCfgPermission(abilityRequest, false, -1, false, false, isImplicit); if (result != AppExecFwk::Constants::PERMISSION_GRANTED) { TAG_LOGE(AAFwkTag::ABILITYMGR, "checkStaticCfgPermission error, result:%{public}d", result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "checkStaticCfgPermission error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "checkStaticCfgPermission error"); return ERR_STATIC_CFG_PERMISSION; } result = CheckCallAbilityPermission(abilityRequest); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s checkCallAbilityPermission error:%{public}d", __func__, result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "checkCallAbilityPermission error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "checkCallAbilityPermission error"); return result; } @@ -1683,7 +1682,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt if (abilityInfo.type == AppExecFwk::AbilityType::DATA) { TAG_LOGE(AAFwkTag::ABILITYMGR, "cannot start data ability, use 'AcquireDataAbility()':%{public}d", ERR_WRONG_INTERFACE_CALL); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_WRONG_INTERFACE_CALL, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_WRONG_INTERFACE_CALL, "cannot start data ability"); return ERR_WRONG_INTERFACE_CALL; } @@ -1702,21 +1701,21 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "startAbility: app data ability preloading failed, '%{public}s', %{public}d", abilityInfo.bundleName.c_str(), result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "app data ability preloading failed"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "app data ability preloading failed"); return result; } } #ifdef SUPPORT_GRAPHICS if (abilityInfo.type != AppExecFwk::AbilityType::PAGE) { TAG_LOGE(AAFwkTag::ABILITYMGR, "only support page type ability:%{public}d", ERR_WRONG_INTERFACE_CALL); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_WRONG_INTERFACE_CALL, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_WRONG_INTERFACE_CALL, "only support page ability"); return ERR_WRONG_INTERFACE_CALL; } #endif if (!IsAbilityControllerStart(want, abilityInfo.bundleName)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "ability controller start failed:%{public}d", ERR_WOULD_BLOCK); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_WOULD_BLOCK, "ability controller start failed"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_WOULD_BLOCK, "ability controller start failed"); return ERR_WOULD_BLOCK; } auto callerTokenId = IPCSkeleton::GetCallingTokenID(); @@ -1739,7 +1738,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt auto ret = missionListManager->StartAbility(abilityRequest); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "missionlist start ability error:%{public}d", ret); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ret, "missionlist start ability error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ret, "missionlist start ability error"); } return ret; } @@ -1883,7 +1882,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED || !DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "permission verify failed:%{public}d", CHECK_PERMISSION_FAILED); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, CHECK_PERMISSION_FAILED, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, CHECK_PERMISSION_FAILED, "permission verify failed"); return CHECK_PERMISSION_FAILED; } @@ -1896,14 +1895,14 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St IPCSkeleton::GetCallingUid() != DMS_UID) { TAG_LOGE(AAFwkTag::ABILITYMGR, "The flag only support for DMS, flag:%{public}d, error:%{publicd}d", want.GetFlags(), ERR_INVALID_CONTINUATION_FLAG); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CONTINUATION_FLAG, "flags not allowed"); return ERR_INVALID_CONTINUATION_FLAG; } if (callerToken != nullptr && !VerificationAllToken(callerToken)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "verify callerToken failed:%{public}d", ERR_INVALID_CALLER); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CALLER, "verify callerToken failed"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CALLER, "verify callerToken failed"); return ERR_INVALID_CALLER; } @@ -1927,7 +1926,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St interceptorExecuter_->DoProcess(interceptorParam); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "interceptorExecuter_ null or doProcess error:%{public}d", result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "doProcess error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "doProcess error"); return result; } @@ -1951,7 +1950,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St } if (!JudgeMultiUserConcurrency(validUserId)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "multi-user non-concurrent unsatisfied:%{publid}d", ERR_CROSS_USER); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_CROSS_USER, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_CROSS_USER, "multi-user non-concurrent unsatisfied"); return ERR_CROSS_USER; } @@ -1996,7 +1995,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St startOptions.GetWindowMode()); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "implicit start ability error:%{public}d", result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "implicit start error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "implicit start error"); } return result; } @@ -2007,7 +2006,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St result = GenerateAbilityRequest(want, requestCode, abilityRequest, callerToken, validUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request local error:%{public}d", result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "GenerateAbilityRequest error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "GenerateAbilityRequest error"); return result; } @@ -2042,20 +2041,20 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St abilityRequest.want.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, 0), false, false, isImplicit); if (result != AppExecFwk::Constants::PERMISSION_GRANTED) { TAG_LOGE(AAFwkTag::ABILITYMGR, "checkStaticCfgPermission error, result=%{public}d", result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "checkStaticCfgPermission error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "checkStaticCfgPermission error"); return ERR_STATIC_CFG_PERMISSION; } result = CheckCallAbilityPermission(abilityRequest, 0, isCallByShortcut); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s CheckCallAbilityPermission error:%{public}d", __func__, result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "CheckCallAbilityPermission error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "CheckCallAbilityPermission error"); return result; } if (abilityInfo.type != AppExecFwk::AbilityType::PAGE) { TAG_LOGE(AAFwkTag::ABILITYMGR, "only support page type ability:%{public}d", ERR_ABILITY_TYPE_INVALID); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_ABILITY_TYPE_INVALID, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_ABILITY_TYPE_INVALID, "only support page ability"); return ERR_ABILITY_TYPE_INVALID; } @@ -2065,14 +2064,14 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "startAbility:app data ability preloading failed, '%{public}s', %{public}d", abilityInfo.bundleName.c_str(), result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "app data ability preloading failed"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "app data ability preloading failed"); return result; } } if (!IsAbilityControllerStart(want, abilityInfo.bundleName)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "ability controller start failed:%{public}d", ERR_WOULD_BLOCK); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_WOULD_BLOCK, "controller start failed"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_WOULD_BLOCK, "controller start failed"); return ERR_WOULD_BLOCK; } #ifdef SUPPORT_SCREEN @@ -2165,7 +2164,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St auto ret = missionListManager->StartAbility(abilityRequest); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListManager start ability errror:%{public}d", ret); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ret, "missionListManager start errror"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ret, "missionListManager start errror"); } return ret; } @@ -2346,7 +2345,7 @@ int AbilityManagerService::StartUIAbilityBySCB(sptr sessionInfo, bo EventInfo eventInfo = BuildEventInfo(sessionInfo->want, -1); if (sessionInfo == nullptr || sessionInfo->sessionToken == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionInfo null"); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_VALUE, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_VALUE, "sessionInfo null", true); return ERR_INVALID_VALUE; } @@ -2370,7 +2369,7 @@ int AbilityManagerService::StartUIAbilityBySCB(sptr sessionInfo, bo #endif if (!IsCallerSceneBoard()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "no sceneboard, no allowed"); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_WRONG_INTERFACE_CALL, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_WRONG_INTERFACE_CALL, "not sceneboard", true); return ERR_WRONG_INTERFACE_CALL; } @@ -2457,7 +2456,7 @@ int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionI sessionInfo->callerToken, currentUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request local error"); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "generate ability request local error", true); return result; } @@ -2471,7 +2470,7 @@ int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionI interceptorExecuter_->DoProcess(interceptorParam); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "interceptorExecuter_ null or DoProcess error:%{public}d", result); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, "DoProcess error"); + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "DoProcess error"); return result; } if (!HandleExecuteSAInterceptor(sessionInfo->want, sessionInfo->callerToken, abilityRequest, result)) { @@ -2500,7 +2499,7 @@ int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionI if (!AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall() && abilityInfo.type != AppExecFwk::AbilityType::PAGE) { TAG_LOGE(AAFwkTag::ABILITYMGR, "only support page type ability"); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_VALUE, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_VALUE, "only support page type ability", true); return ERR_INVALID_VALUE; } @@ -2523,7 +2522,7 @@ int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionI if (result != ERR_OK) { if (isReplaceWantExist == false) { TAG_LOGE(AAFwkTag::ABILITYMGR, "doProcess failed or replaceWant absent"); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, result, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "doProcess failed or replaceWant absent", true); return result; } @@ -13303,7 +13302,7 @@ int32_t AbilityManagerService::PreStartInner(const FreeInstallInfo& taskInfo) if (callerToken != nullptr && !VerificationAllToken(callerToken)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "PreStartInner StartAbilityError:%{public}d", ERR_INVALID_CALLER); - abilityEventHelper_->SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CALLER, + abilityEventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CALLER, "PreStartInner StartAbilityError"); return ERR_INVALID_CALLER; } diff --git a/services/abilitymgr/src/utils/ability_event_util.cpp b/services/abilitymgr/src/utils/ability_event_util.cpp index a285e61ff3e87337bc0ff1a7d5c5e4f2c3841791..59f42bb2b17ba56179dbbe06d65fd00c1e85c902 100644 --- a/services/abilitymgr/src/utils/ability_event_util.cpp +++ b/services/abilitymgr/src/utils/ability_event_util.cpp @@ -19,7 +19,7 @@ namespace OHOS { namespace AAFwk { - +constexpr int32_t FFRT_TASK_TIMEOUT = 5 * 1000 * 1000; // 5s void AbilityEventUtil::HandleModuleInfoUpdated(const std::string &bundleName, const int uid, const std::string& moduleName, bool isPlugin) { @@ -31,16 +31,12 @@ void AbilityEventUtil::HandleModuleInfoUpdated(const std::string &bundleName, co void AbilityEventUtil::SendStartAbilityErrorEvent(EventInfo &eventInfo, int32_t errCode, const std::string errMsg, bool isSystemError) { - if (taskHandler_ == nullptr) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "task handler null"); - return; - } EventName name = isSystemError ? EventName::START_ABILITY_SYSTEM_ERROR : EventName::START_ABILITY_ERROR; eventInfo.errCode = errCode; eventInfo.errMsg = errMsg; - taskHandler_->SubmitTask([eventInfo, name]() { + ffrt::submit([name, eventInfo]() { EventReport::SendAbilityEvent(name, HiSysEventType::FAULT, eventInfo); - }); + }, ffrt::task_attr().timeout(FFRT_TASK_TIMEOUT)); } } // namespace AAFwk } // namespace OHOS diff --git a/services/common/src/event_report.cpp b/services/common/src/event_report.cpp index 0d66f98814882bf09bce9232a724235c330af943..3c1981e228453e00459cff4f0b8cce543db62bcc 100644 --- a/services/common/src/event_report.cpp +++ b/services/common/src/event_report.cpp @@ -810,7 +810,7 @@ std::string EventReport::ConvertEventName(const EventName &eventName) "START_ABILITY_ERROR", "TERMINATE_ABILITY_ERROR", "START_EXTENSION_ERROR", "STOP_EXTENSION_ERROR", "CONNECT_SERVICE_ERROR", "DISCONNECT_SERVICE_ERROR", "UI_EXTENSION_ERROR", "UI_SERVICE_EXTENSION_ERROR", "EXECUTE_INSIGHT_INTENT_ERROR", - "STARTUP_TASK_ERROR", + "STARTUP_TASK_ERROR", "START_ABILITY_SYSTEM_ERROR", // ability behavior event "START_ABILITY", "TERMINATE_ABILITY", "CLOSE_ABILITY", diff --git a/test/fuzztest/abilityeventutil_fuzzer/BUILD.gn b/test/fuzztest/abilityeventutil_fuzzer/BUILD.gn index 07beda529be4570f818d31667cc24d5b90482a99..32a5c85235f14b0dbcf6c5b320b22d1b12f23f62 100644 --- a/test/fuzztest/abilityeventutil_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityeventutil_fuzzer/BUILD.gn @@ -61,6 +61,7 @@ ohos_fuzztest("AbilityEventUtilFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "hisysevent:libhisysevent", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/fuzztest/abilityeventutil_fuzzer/abilityeventutil_fuzzer.cpp b/test/fuzztest/abilityeventutil_fuzzer/abilityeventutil_fuzzer.cpp index ea5913e36648f49f0dadff9be99e4d802539d934..a435d19665edd46d5c3a961a07eab71622e782b8 100644 --- a/test/fuzztest/abilityeventutil_fuzzer/abilityeventutil_fuzzer.cpp +++ b/test/fuzztest/abilityeventutil_fuzzer/abilityeventutil_fuzzer.cpp @@ -52,11 +52,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) abilityEventUtil->HandleModuleInfoUpdated(strParam, intParam, "", false); EventInfo eventInfo = {}; - if (abilityEventUtil->taskHandler_ == nullptr) { - return false; - } - abilityEventUtil->SendStartAbilityErrorEvent(eventInfo, 1, "SendStartAbilityErrorEvent Test"); - abilityEventUtil->taskHandler_ = nullptr; abilityEventUtil->SendStartAbilityErrorEvent(eventInfo, 1, "SendStartAbilityErrorEvent Test"); return true; } diff --git a/test/unittest/ability_event_util_test/BUILD.gn b/test/unittest/ability_event_util_test/BUILD.gn index 9ffe4ffef5c6318a87d4fa1605a872c469074dd8..cce726809bbcf1dabe88ed674e364a849d24407e 100644 --- a/test/unittest/ability_event_util_test/BUILD.gn +++ b/test/unittest/ability_event_util_test/BUILD.gn @@ -55,6 +55,7 @@ ohos_unittest("ability_event_util_test") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "hisysevent:libhisysevent", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/unittest/ability_event_util_test/ability_event_util_test.cpp b/test/unittest/ability_event_util_test/ability_event_util_test.cpp index 20869093a311a38e9588bbb9e7856d8cba1f62d6..23ff2c4d774eed9cc2229132578d909d801e0398 100644 --- a/test/unittest/ability_event_util_test/ability_event_util_test.cpp +++ b/test/unittest/ability_event_util_test/ability_event_util_test.cpp @@ -52,8 +52,7 @@ void AbilityEventUtilTest::TearDown() {} HWTEST_F(AbilityEventUtilTest, AbilityEventUtil_SendStartAbilityError_0100, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0100 start"); - std::shared_ptr taskHandler = TaskHandlerWrap::CreateQueueHandler("TestQueueHandler"); - std::shared_ptr eventUtil = std::make_shared(taskHandler); + std::shared_ptr eventUtil = std::make_shared(); EventInfo eventInfo = {}; int32_t errCode = -1; std::string errMsg = "test event"; @@ -71,8 +70,7 @@ HWTEST_F(AbilityEventUtilTest, AbilityEventUtil_SendStartAbilityError_0100, Test HWTEST_F(AbilityEventUtilTest, AbilityEventUtil_SendStartAbilityError_0200, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "AbilityEventUtil_SendStartAbilityError_0200 start"); - std::shared_ptr taskHandler = TaskHandlerWrap::CreateQueueHandler("TestQueueHandler"); - std::shared_ptr eventUtil = std::make_shared(taskHandler); + std::shared_ptr eventUtil = std::make_shared(); EventInfo eventInfo = {}; int32_t errCode = -1; std::string errMsg = "test event"; diff --git a/test/unittest/ability_manager_service_mock_test/ability_manager_service_mock_test.cpp b/test/unittest/ability_manager_service_mock_test/ability_manager_service_mock_test.cpp index 32e771aec477c236980726ffed39a5847dc0b3b4..5fcd996f9eedc4d3b2f13573e56c51d86bca9a40 100644 --- a/test/unittest/ability_manager_service_mock_test/ability_manager_service_mock_test.cpp +++ b/test/unittest/ability_manager_service_mock_test/ability_manager_service_mock_test.cpp @@ -231,8 +231,6 @@ HWTEST_F(AbilityManagerServiceMockTest, ExecuteIntent_0200, TestSize.Level1) { auto abilityMs = std::make_shared(); ASSERT_NE(abilityMs, nullptr); - abilityMs->abilityEventHelper_ = std::make_shared(); - ASSERT_NE(abilityMs->abilityEventHelper_, nullptr); AppExecFwk::InsightIntentExecuteParam param; param.bundleName_ = "test.bundleName"; param.moduleName_ = "test.entry"; @@ -256,8 +254,6 @@ HWTEST_F(AbilityManagerServiceMockTest, ExecuteIntent_0300, TestSize.Level1) { auto abilityMs = std::make_shared(); ASSERT_NE(abilityMs, nullptr); - abilityMs->abilityEventHelper_ = std::make_shared(); - ASSERT_NE(abilityMs->abilityEventHelper_, nullptr); AppExecFwk::InsightIntentExecuteParam param; param.bundleName_ = "test.bundleName"; param.moduleName_ = "test.entry"; diff --git a/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp b/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp index 5b7c3d368d0d2b7c790df59d68b1d7c320cbf69b..c0d9008ef2a5d4f222cc5344e7e7e5a6cb8c769d 100644 --- a/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp +++ b/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp @@ -884,42 +884,6 @@ HWTEST_F(AppMgrServiceInnerTest, GenerateRenderUid_001, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "GenerateRenderUid_001 end"); } -/** - * @tc.name: StartRenderProcessImpl_001 - * @tc.desc: start render process. - * @tc.type: FUNC - * @tc.Function: StartRenderProcessImpl - * @tc.SubFunction: NA - * @tc.EnvConditions: NA - */ -HWTEST_F(AppMgrServiceInnerTest, StartRenderProcessImpl_001, TestSize.Level2) -{ - TAG_LOGI(AAFwkTag::TEST, "StartRenderProcessImpl_001 start"); - auto appMgrServiceInner = std::make_shared(); - appMgrServiceInner->Init(); - EXPECT_NE(appMgrServiceInner, nullptr); - BundleInfo bundleInfo; - std::string appName = "test_appName"; - std::string processName = "test_processName"; - std::string bundleName = "test_bundleName"; - sptr token = new MockAbilityToken(); - std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); - EXPECT_NE(appRecord, nullptr); - pid_t hostPid = 1; - std::string renderParam = "test_render_param"; - int32_t ipcFd = 1; - int32_t sharedFd = 1; - int32_t crashFd = 1; - std::shared_ptr renderRecord = RenderRecord::CreateRenderRecord(hostPid, renderParam, - FdGuard(ipcFd), FdGuard(sharedFd), FdGuard(crashFd), appRecord); - EXPECT_NE(renderRecord, nullptr); - pid_t renderPid = 1; - appMgrServiceInner->StartRenderProcessImpl(nullptr, nullptr, renderPid); - appMgrServiceInner->StartRenderProcessImpl(renderRecord, appRecord, renderPid); - TAG_LOGI(AAFwkTag::TEST, "StartRenderProcessImpl_001 end"); -} - /** * @tc.name: NotifyAppFault_001 * @tc.desc: Verify that the NotifyAppFault interface calls normally @@ -1243,5 +1207,243 @@ HWTEST_F(AppMgrServiceInnerTest, GetKernelPermissions_001, TestSize.Level1) EXPECT_EQ(permissionsMap.size(), 0); TAG_LOGI(AAFwkTag::TEST, "GetKernelPermissions_001 end"); } + +/** + * @tc.name: KillSubProcessBypidInner + * @tc.desc: Kill subProcess inner + * @tc.type: FUNC + * @tc.Function: KillSubProcessBypidInner + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppMgrServiceInnerTest, KillSubProcessBypidInner_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypidInner_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + pid_t pid = 0; + std::string reason = "test"; + AAFwk::EventInfo eventInfo; + auto ret = appMgrServiceInner->KillSubProcessBypidInner(pid, reason, eventInfo); + EXPECT_EQ(ret, AAFwk::ERR_KILL_PROCESS_NOT_EXIST); + + pid = 65536; + ret = appMgrServiceInner->KillSubProcessBypidInner(pid, reason, eventInfo); + EXPECT_NE(ret, 0); + + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypidInner_001 end"); +} + +/** + * @tc.name: KillSubProcessBypidInner + * @tc.desc: Kill subProcess inner + * @tc.type: FUNC + * @tc.Function: KillSubProcessBypidInner + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppMgrServiceInnerTest, KillSubProcessBypidInner_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypidInner_002 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + pid_t pid = 0; + std::string reason = "test"; + AAFwk::EventInfo eventInfo; + + pid = fork(); + if (pid == -1) { + TAG_LOGI(AAFwkTag::TEST, "fork process failed"); + } else if (pid == 0) { + TAG_LOGI(AAFwkTag::TEST, "fork process success"); + sleep(3); + exit(0); + } + auto ret = appMgrServiceInner->KillSubProcessBypidInner(pid, reason, eventInfo); + EXPECT_EQ(ret, 0); + + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypidInner_002 end"); +} + +/** + * @tc.name: KillSubProcessBypid + * @tc.desc: Kill subProcess + * @tc.type: FUNC + * @tc.Function: KillSubProcessBypid + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppMgrServiceInnerTest, KillSubProcessBypid_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypid_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + pid_t pid = 111; + std::string reason = "test"; + auto ret = 0; + appMgrServiceInner->appRunningManager_ = nullptr; + ret = appMgrServiceInner->KillSubProcessBypid(pid, reason); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypid_001 end"); +} + +/** + * @tc.name: KillSubProcessBypid + * @tc.desc: Kill subProcess + * @tc.type: FUNC + * @tc.Function: KillSubProcessBypid + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppMgrServiceInnerTest, KillSubProcessBypid_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypid_002 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + pid_t pid = 1; + std::string reason = "test"; + auto ret = 0; + auto appRunningManager = std::make_shared(); + + int32_t recordId = 1; + std::shared_ptr appInfo = std::make_shared(); + std::string processName = "testProcess"; + auto appRecord = std::make_shared(appInfo, recordId, processName); + + std::map> renderRecordMap; + int32_t uid = 1; + std::shared_ptr renderRecord = std::make_shared( + pid, "param", FdGuard(0), FdGuard(0), FdGuard(0), appRecord); + renderRecord->SetPid(pid); + renderRecordMap.emplace(uid, renderRecord); + appRecord->renderRecordMap_ = renderRecordMap; + + appRunningManager->appRunningRecordMap_.emplace(recordId, appRecord); + + appMgrServiceInner->appRunningManager_ = appRunningManager; + ret = appMgrServiceInner->KillSubProcessBypid(pid, reason); + EXPECT_EQ(ret, 0); + + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypid_002 end"); +} + +/** + * @tc.name: KillSubProcessBypid + * @tc.desc: Kill subProcess + * @tc.type: FUNC + * @tc.Function: KillSubProcessBypid + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppMgrServiceInnerTest, KillSubProcessBypid_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypid_003 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + pid_t pid = 1; + std::string reason = "test"; + auto ret = 0; + auto appRunningManager = std::make_shared(); + + int32_t recordId = 1; + std::shared_ptr appInfo = std::make_shared(); + std::string processName = "testProcess"; + auto appRecord = std::make_shared(appInfo, recordId, processName); + + std::map> childProcessRecordMap; + std::string subProcessName = "subTestProcess"; + std::shared_ptr subAppInfo = std::make_shared(); + auto subAppRecord = std::make_shared(subAppInfo, recordId, subProcessName); + ChildProcessRequest request; + auto childProcessRecord = std::make_shared(pid, request, subAppRecord); + + childProcessRecordMap.emplace(pid, childProcessRecord); + appRecord->childProcessRecordMap_ = childProcessRecordMap; + + appRunningManager->appRunningRecordMap_.emplace(recordId, appRecord); + appMgrServiceInner->appRunningManager_ = appRunningManager; + ret = appMgrServiceInner->KillSubProcessBypid(pid, reason); + EXPECT_EQ(ret, 0); + + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypid_003 end"); +} + +/** + * @tc.name: KillSubProcessBypid + * @tc.desc: Kill subProcess + * @tc.type: FUNC + * @tc.Function: KillSubProcessBypid + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppMgrServiceInnerTest, KillSubProcessBypid_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypid_004 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + pid_t pid = 1; + std::string reason = "test"; + auto ret = 0; + auto appRunningManager = std::make_shared(); + + int32_t recordId = 1; + std::shared_ptr appInfo = std::make_shared(); + std::string processName = "testProcess"; + auto appRecord = std::make_shared(appInfo, recordId, processName); + + // std::map> renderRecordMap; + std::map> childAppRecordMap; + std::shared_ptr subAppInfo = std::make_shared(); + std::string subProcessName = "subTestProcess"; + auto subAppRecord = std::make_shared(subAppInfo, recordId, subProcessName); + childAppRecordMap.emplace(pid, subAppRecord); + appRecord->childAppRecordMap_ = childAppRecordMap; + + appRunningManager->appRunningRecordMap_.emplace(recordId, appRecord); + appMgrServiceInner->appRunningManager_ = appRunningManager; + ret = appMgrServiceInner->KillSubProcessBypid(pid, reason); + EXPECT_EQ(ret, 0); + + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypid_004 end"); +} + +/** + * @tc.name: KillSubProcessBypid + * @tc.desc: Kill subProcess + * @tc.type: FUNC + * @tc.Function: KillSubProcessBypid + * @tc.SubFunction: NA + * @tc.EnvConditions: NA + */ +HWTEST_F(AppMgrServiceInnerTest, KillSubProcessBypid_005, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypid_005 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + pid_t pid = 2; + std::string reason = "test"; + auto ret = 0; + auto appRunningManager = std::make_shared(); + + int32_t recordId = 1; + std::shared_ptr appInfo = std::make_shared(); + std::string processName = "testProcess"; + auto appRecord = std::make_shared(appInfo, recordId, processName); + + // std::map> renderRecordMap; + std::map> childAppRecordMap; + std::shared_ptr subAppInfo = std::make_shared(); + std::string subProcessName = "subTestProcess"; + auto subAppRecord = std::make_shared(subAppInfo, recordId, subProcessName); + childAppRecordMap.emplace(pid, subAppRecord); + appRecord->childAppRecordMap_ = childAppRecordMap; + + appRunningManager->appRunningRecordMap_.emplace(recordId, appRecord); + appMgrServiceInner->appRunningManager_ = appRunningManager; + ret = appMgrServiceInner->KillSubProcessBypid(pid, reason); + EXPECT_EQ(ret, 0); + + TAG_LOGI(AAFwkTag::TEST, "KillSubProcessBypid_005 end"); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file