diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index 870dfefc01a19a74c5fd96323896bb8be7865fa1..d5a000e8f7acefbebde58c01a3f4818227a5283f 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -978,6 +978,12 @@ enum { */ ERR_PROCESS_START_INVALID_PID = 2097386, + ERR_DO_CLOSURE_CALLBACK_FAILED = 2097397, + + ERR_DMS_START_REMOTE_FAILED = 2097398, + + ERR_PRELOAD_APP_DATA_ABILITIES_FAILED = 2097399, + /** * Native error(3000000) for target bundle not exist. */ @@ -1225,6 +1231,80 @@ enum NativeFreeInstallError { */ UNDEFINE_ERROR_CODE = 3, }; + +enum { + /** + * Result (2098000-2098049) Error code refinement INVALID_VALUE. + */ + ERR_REFINEMENT_INVALID_VALUE_BEGIN = 2098000, + + ERR_CONNECT_MANAGER_NULL_ABILITY_RECORD = 2098001, + + ERR_UI_ABILITY_MANAGER_NULL_ABILITY_RECORD = 2098002, + + ERR_NULL_APP_MGR_CLIENT = 2098004, + + ERR_ADD_START_CONTROL_PARAM_FAILED = 2098005, + + ERR_NULL_FREE_INSTALL_MANAGER = 2098006, + + ERR_GET_MISSION_ID_BY_ABILITY_TOKEN_FAILED = 2098007, + + ERR_INVALID_MISSION_ID = 2098008, + + ERR_NULL_SYS_DIALOG_SCHEDULER = 2098009, + + ERR_CHECK_CALL_FROM_BACKGROUND_FAILED = 2098010, + + ERR_TOO_LARGE_APPINDEXES = 2098011, + + ERR_FREQ_START_ABILITY = 2098012, + + ERR_CALLER_IS_KILLING = 2098013, + + ERR_NOTIFY_SCB_PENDING_ACTIVATION_FAILED = 2098014, + + ERR_FREE_INSTALL_REMOTE_WANT = 2098015, + + ERR_REFINEMENT_INVALID_VALUE_END = 2098049 +}; + +enum { + /** + * Result (2098050-2098099) Error code refinement INNERR_ERROR. + */ + ERR_REFINEMENT_INNER_ERROR_BEGIN = 2098050, + + ERR_APP_MGR_TERMINATTE_ABILITY_FAILED = 2098051, + + ERR_REFINEMENT_INNER_ERROR_END = 2098099 +}; + +enum { + /** + * Result (2099100-2099149) Error code refinement RESOLVE_ABILITY_ERR. + */ + ERR_REFINEMENT_RESOLVE_ABILITY_BEGIN = 2099100, + + ERR_CHECK_PLUGIN_NULL_RECORD = 2099101, + + ERR_CALLER_IS_PLUGIN_ABILITY = 2099102, + + ERR_CHECK_PLUGIN_INVALID_TYPE = 2099103, + + ERR_REFINEMENT_RESOLVE_ABILITY_END = 2099149 +}; + +enum { + /** + * Result (2099150-2099199) Error code refinement ERR_INVALID_CALLER. + */ + ERR_REFINEMENT_INVALID_CALLER_BEGIN = 2099150, + + ERR_IS_NOT_SPECIFIED_SA = 2099151, + + ERR_REFINEMENT_INVALID_CALLER_END = 2099199 +}; } // namespace AAFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_ERRORS_H diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index dd65f9c61d14fb5a1cff68fd96c585b0d2f8aaeb..f981c2e0072f1850f1ad7c73751367892fc25f1e 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -1280,6 +1280,8 @@ public: const std::string &taskName = ""); void UpdateUIExtensionBindInfo(const WantParams &wantParams); + + void SendTerminateAbilityErrorEvent(int32_t errCode); protected: sptr token_ = {}; // used to interact with kit and wms @@ -1334,6 +1336,8 @@ private: void CancelPrepareTerminate(); + void BuildTerminateAbiltityEventInfo(EventInfo &eventInfo, int32_t errCode); + #ifdef SUPPORT_SCREEN std::shared_ptr GetWantFromMission() const; void SetShowWhenLocked(const AppExecFwk::AbilityInfo &abilityInfo, sptr &info) const; diff --git a/services/abilitymgr/include/utils/ability_errors_util.h b/services/abilitymgr/include/utils/ability_errors_util.h new file mode 100644 index 0000000000000000000000000000000000000000..a5530d2ba07c640677f504b6ab1debaeef9e9e81 --- /dev/null +++ b/services/abilitymgr/include/utils/ability_errors_util.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_ABILITY_ERRORS_UTIL_H +#define OHOS_ABILITY_RUNTIME_ABILITY_ERRORS_UTIL_H + +#include "ability_manager_errors.h" + +namespace OHOS { +namespace AAFwk { +namespace AbilityErrorUtil { + +static int32_t ConvertToOriginErrorCode(int32_t errCode) +{ + if (errCode >= ERR_REFINEMENT_INVALID_VALUE_BEGIN && errCode <= ERR_REFINEMENT_INVALID_VALUE_END) { + return ERR_INVALID_VALUE; + } + if (errCode >= ERR_REFINEMENT_INNER_ERROR_BEGIN && errCode <= ERR_REFINEMENT_INNER_ERROR_END) { + return INNER_ERR; + } + if (errCode >= ERR_REFINEMENT_RESOLVE_ABILITY_BEGIN && errCode <= ERR_REFINEMENT_RESOLVE_ABILITY_END) { + return RESOLVE_ABILITY_ERR; + } + if (errCode >= ERR_REFINEMENT_INVALID_CALLER_BEGIN && errCode <= ERR_REFINEMENT_INVALID_CALLER_END) { + return ERR_INVALID_CALLER; + } + return errCode; +} + +} // AbilityErrorUtil +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ABILITY_ERRORS_UTIL_H diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 43d3c1db85f150b28da6e80b1fafae12efc501fe..8dea24a8189028fd51b7f34b72c4dc9a8a0529c1 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -136,7 +136,7 @@ int AbilityConnectManager::TerminateAbilityInner(const sptr &toke if (abilityRecord == nullptr) { abilityRecord = AbilityCacheManager::GetInstance().FindRecordByToken(token); } - CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + CHECK_POINTER_AND_RETURN(abilityRecord, ERR_CONNECT_MANAGER_NULL_ABILITY_RECORD); std::string element = abilityRecord->GetURI(); TAG_LOGD(AAFwkTag::SERVICE_EXT, "terminate ability, ability is %{public}s", element.c_str()); if (IsUIExtensionAbility(abilityRecord)) { @@ -349,7 +349,7 @@ int AbilityConnectManager::TerminateAbilityLocked(const sptr &tok HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::SERVICE_EXT, "called"); auto abilityRecord = GetExtensionByTokenFromTerminatingMap(token); - CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + CHECK_POINTER_AND_RETURN(abilityRecord, ERR_CONNECT_MANAGER_NULL_ABILITY_RECORD); if (abilityRecord->IsTerminating()) { TAG_LOGD(AAFwkTag::SERVICE_EXT, "Ability is on terminating."); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index faf7a2c839102631c3c5e715dc0e3ab63178bab8..0e0a7bc23c3556889ade2b8448f33da349f89e10 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -20,6 +20,7 @@ #include "ability_background_connection.h" #include "ability_business_error.h" #include "ability_connect_manager.h" +#include "ability_errors_util.h" #include "ability_manager_radar.h" #include "ability_start_by_call_helper.h" #include "ability_start_with_wait_observer_utils.h" @@ -1163,7 +1164,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(want)); @@ -1188,7 +1189,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrVerifyFusionAccessPermission(); if (!isSpecificSA) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s verificationAllToken failed", __func__); - eventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_CALLER, "verificationAllToken failed"); + eventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_IS_NOT_SPECIFIED_SA, "verificationAllToken failed"); return ERR_INVALID_CALLER; } TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s:caller specific system ability", __func__); @@ -1206,6 +1207,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(want), validUserId, appIndex, callerToken, false); if (checkRet != ERR_OK) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "CheckMultiInstanceAndAppClone failed: %{public}d", checkRet); eventHelper_.SendStartAbilityErrorEvent(eventInfo, checkRet, "CheckMultiInstanceAndAppClone failed"); return checkRet; } @@ -1233,7 +1235,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrspecifyTokenId = specifyTokenId; result = freeInstallManager_->StartFreeInstall(localWant, validUserId, requestCode, callerToken, param); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "StartFreeInstall failed"); - return result; + return AbilityErrorUtil::ConvertToOriginErrorCode(result); } int32_t ret = freeInstallManager_->StartFreeInstall(localWant, validUserId, requestCode, callerToken); if (ret == ERR_OK) { @@ -1347,7 +1349,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(abilityInfo), isStartAsCaller, appIndex); - result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : + result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); bool isReplaceWantExist = newWant.GetBoolParam("queryWantFromErms", false); newWant.RemoveParam("queryWantFromErms"); @@ -1416,7 +1420,8 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrNotifySCBToStartUIAbility(abilityRequest); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "NotifySCBToStartUIAbility failed"); - return result; + return AbilityErrorUtil::ConvertToOriginErrorCode(result); } auto missionListManager = GetMissionListManagerByUserId(oriValidUserId); @@ -1500,7 +1505,7 @@ int AbilityManagerService::PreStartFreeInstall(const Want &want, sptr(want)).RemoveParam("send_to_erms_embedded"); localWant = want; @@ -1524,7 +1529,7 @@ int AbilityManagerService::StartAbilityByConnectManager(const Want& want, const auto connectManager = GetConnectManagerByUserId(validUserId); if (!connectManager) { TAG_LOGE(AAFwkTag::ABILITYMGR, "connectManager null userId=%{public}d", validUserId); - return ERR_INVALID_VALUE; + return CONNECT_MAMAGER_NOT_FIND_BY_USERID; } TAG_LOGD(AAFwkTag::ABILITYMGR, "start service or extension, name is %{public}s", abilityInfo.name.c_str()); InsightIntentExecuteParam::RemoveInsightIntent(const_cast(want)); @@ -1606,7 +1611,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt #endif // WITH_DLP if (auto pluginRet = CheckStartPlugin(want, callerToken); pluginRet != ERR_OK) { eventHelper_.SendStartAbilityErrorEvent(eventInfo, pluginRet, "CheckStartPlugin failed"); - return pluginRet; + return AbilityErrorUtil::ConvertToOriginErrorCode(pluginRet); } if ((want.GetFlags() & Want::FLAG_ABILITY_PREPARE_CONTINUATION) == Want::FLAG_ABILITY_PREPARE_CONTINUATION && @@ -1651,7 +1656,8 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt if (AbilityUtil::IsStartFreeInstall(want)) { if (CheckIfOperateRemote(want) || freeInstallManager_ == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "can not start remote free install"); - eventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_VALUE, "can not start remote free install"); + eventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_FREE_INSTALL_REMOTE_WANT, + "can not start remote free install"); return ERR_INVALID_VALUE; } (const_cast(want)).RemoveParam("send_to_erms_embedded"); @@ -1661,7 +1667,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt param->isAsync = true; result = freeInstallManager_->StartFreeInstall(localWant, validUserId, requestCode, callerToken, param); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "StartFreeInstall failed"); - return result; + return AbilityErrorUtil::ConvertToOriginErrorCode(result); } if (!JudgeMultiUserConcurrency(validUserId)) { @@ -1688,7 +1694,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt TAG_LOGE(AAFwkTag::ABILITYMGR, "implicit start ability error:%{public}d", result); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "implicit start error"); } - return result; + return AbilityErrorUtil::ConvertToOriginErrorCode(result); } if (want.GetAction().compare(ACTION_CHOOSE) == 0) { result = ShowPickerDialog(want, validUserId, callerToken); @@ -1746,9 +1752,10 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt if (!AbilityUtil::IsSystemDialogAbility(abilityInfo.bundleName, abilityInfo.name)) { result = PreLoadAppDataAbilities(abilityInfo.bundleName, validUserId); if (result != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "startAbility: app data ability preloading failed, '%{public}s', %{public}d", + TAG_LOGE(AAFwkTag::ABILITYMGR, "startAbility:app data ability preloading failed, '%{public}s', %{public}d", abilityInfo.bundleName.c_str(), result); - eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "app data ability preloading failed"); + eventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_PRELOAD_APP_DATA_ABILITIES_FAILED, + "app data ability preloading failed"); return result; } } @@ -1774,7 +1781,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); result = uiAbilityManager->NotifySCBToStartUIAbility(abilityRequest); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "NotifySCBToStartUIAbility failed"); - return result; + return AbilityErrorUtil::ConvertToOriginErrorCode(result); } auto missionListManager = GetMissionListManagerByUserId(oriValidUserId); if (missionListManager == nullptr) { @@ -1939,7 +1946,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St #endif // WITH_DLP if (auto pluginRet = CheckStartPlugin(want, callerToken); pluginRet != ERR_OK) { eventHelper_.SendStartAbilityErrorEvent(eventInfo, pluginRet, "CheckStartPlugin failed"); - return pluginRet; + return AbilityErrorUtil::ConvertToOriginErrorCode(pluginRet); } if ((want.GetFlags() & Want::FLAG_ABILITY_PREPARE_CONTINUATION) == Want::FLAG_ABILITY_PREPARE_CONTINUATION && @@ -2001,7 +2008,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St param->startOptions = std::make_shared(startOptions); result = freeInstallManager_->StartFreeInstall(localWant, validUserId, requestCode, callerToken, param); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "StartFreeInstall failed"); - return result; + return AbilityErrorUtil::ConvertToOriginErrorCode(result); } if (!JudgeMultiUserConcurrency(validUserId)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "multi-user non-concurrent unsatisfied:%{publid}d", ERR_CROSS_USER); @@ -2053,7 +2060,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St TAG_LOGE(AAFwkTag::ABILITYMGR, "implicit start ability error:%{public}d", result); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "implicit start error"); } - return result; + return AbilityErrorUtil::ConvertToOriginErrorCode(result); } if (want.GetAction().compare(ACTION_CHOOSE) == 0) { result = ShowPickerDialog(want, validUserId, callerToken); @@ -2124,7 +2131,8 @@ 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); - eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "app data ability preloading failed"); + eventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_PRELOAD_APP_DATA_ABILITIES_FAILED, + "app data ability preloading failed"); return result; } } @@ -2168,7 +2176,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St Want newWant = abilityRequest.want; AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), true, callerToken, std::make_shared(abilityInfo), isStartAsCaller, appIndex); - result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : + result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); bool isReplaceWantExist = newWant.GetBoolParam("queryWantFromErms", false); newWant.RemoveParam("queryWantFromErms"); @@ -2222,7 +2230,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_NULL_UI_ABILITY_MANAGER); result = uiAbilityManager->NotifySCBToStartUIAbility(abilityRequest); eventHelper_.SendStartAbilityErrorEvent(eventInfo, result, "NotifySCBToStartUIAbility failed"); - return result; + return AbilityErrorUtil::ConvertToOriginErrorCode(result); } auto missionListManager = GetMissionListManagerByUserId(oriValidUserId); if (missionListManager == nullptr) { @@ -2449,7 +2457,7 @@ int32_t AbilityManagerService::StartUIAbilitiesInterceptorCheck(const Want &want AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), true, callerToken, std::make_shared(abilityInfo), false, appIndex); - result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : + result = afterCheckExecuter_ == nullptr ? ERR_NULL_AFTER_CHECK_EXECUTER : afterCheckExecuter_->DoProcess(afterCheckParam); if (result == ERR_CROWDTEST_EXPIRED) { TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities ERR_CROWDTEST_EXPIRED"); @@ -3572,7 +3580,7 @@ int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, cons eventInfo.errCode = result; EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); } - return result; + return AbilityErrorUtil::ConvertToOriginErrorCode(result); } if (!JudgeMultiUserConcurrency(validUserId)) { @@ -3592,7 +3600,7 @@ int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, cons CHECK_POINTER_AND_RETURN(implicitStartProcessor_, ERR_IMPLICIT_START_ABILITY_FAIL); result = implicitStartProcessor_->ImplicitStartAbility(abilityRequest, validUserId); if (result != ERR_OK) { - TAG_LOGE(AAFwkTag::SERVICE_EXT, "implicit start ability error"); + TAG_LOGE(AAFwkTag::SERVICE_EXT, "implicit start ability error:%{public}d", result); if (extensionType == AppExecFwk::ExtensionAbilityType::UI_SERVICE) { eventInfo.errReason = "implicit start ability error"; eventInfo.appIndex = appIndex; @@ -3602,7 +3610,7 @@ int32_t AbilityManagerService::StartExtensionAbilityInner(const Want &want, cons EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); } } - return result; + return AbilityErrorUtil::ConvertToOriginErrorCode(result); } #endif result = GenerateExtensionAbilityRequest(want, abilityRequest, callerToken, validUserId); @@ -4503,7 +4511,7 @@ int AbilityManagerService::CloseUIAbilityBySCB(const sptr &sessionI TAG_LOGE(AAFwkTag::ABILITYMGR, "close UIAbility by SCB failed: %{public}d", eventInfo.errCode); SendAbilityEvent(EventName::TERMINATE_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); } - return eventInfo.errCode; + return AbilityErrorUtil::ConvertToOriginErrorCode(eventInfo.errCode); } int AbilityManagerService::SendResultToAbility(int32_t requestCode, int32_t resultCode, Want &resultWant) @@ -4545,10 +4553,10 @@ int AbilityManagerService::StartRemoteAbility(const Want &want, int requestCode, UpdateCallerInfoUtil::GetInstance().UpdateDmsCallerInfo(remoteWant, callerToken); if (AddStartControlParam(remoteWant, callerToken) != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s addStartControlParam failed", __func__); - return ERR_INVALID_VALUE; + return ERR_ADD_START_CONTROL_PARAM_FAILED; } if (AbilityUtil::IsStartFreeInstall(remoteWant)) { - return freeInstallManager_ == nullptr ? ERR_INVALID_VALUE : + return freeInstallManager_ == nullptr ? ERR_NULL_FREE_INSTALL_MANAGER : freeInstallManager_->StartRemoteFreeInstall(remoteWant, requestCode, validUserId, callerToken); } if (remoteWant.GetBoolParam(Want::PARAM_RESV_FOR_RESULT, false)) { @@ -4558,13 +4566,13 @@ int AbilityManagerService::StartRemoteAbility(const Want &want, int requestCode, missionId = GetMissionIdByAbilityTokenInner(callerToken); if (!missionId) { TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid missionId id"); - return ERR_INVALID_VALUE; + return ERR_GET_MISSION_ID_BY_ABILITY_TOKEN_FAILED; } } else { missionId = GetMissionIdByAbilityToken(callerToken); } if (missionId < 0) { - return ERR_INVALID_VALUE; + return ERR_INVALID_MISSION_ID; } remoteWant.SetParam(DMS_MISSION_ID, missionId); } @@ -12620,7 +12628,8 @@ int AbilityManagerService::CreateCloneSelectorDialog(AbilityRequest &request, in const std::string &replaceWantString) { CHECK_POINTER_AND_RETURN(implicitStartProcessor_, ERR_IMPLICIT_START_ABILITY_FAIL); - return implicitStartProcessor_->ImplicitStartAbility(request, userId, 0, replaceWantString, true); + auto ret = implicitStartProcessor_->ImplicitStartAbility(request, userId, 0, replaceWantString, true); + return AbilityErrorUtil::ConvertToOriginErrorCode(ret); } #endif // SUPPORT_SCREEN void AbilityManagerService::RemoveSelectorIdentity(int32_t tokenId) @@ -14178,6 +14187,7 @@ void AbilityManagerService::ReportCleanSession(const sptr &sessionI eventInfo.errCode = errCode; SendAbilityEvent(EventName::CLOSE_ABILITY, HiSysEventType::BEHAVIOR, eventInfo); if (eventInfo.errCode != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to terminate ability: %{public}d", eventInfo.errCode); SendAbilityEvent(EventName::TERMINATE_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); } } @@ -14607,17 +14617,17 @@ int32_t AbilityManagerService::CheckStartPlugin(const Want& want, sptrGetAbilityInfo().type == AppExecFwk::AbilityType::PAGE || (abilityRecord->GetAbilityInfo().type == AppExecFwk::AbilityType::EXTENSION && abilityRecord->GetAbilityInfo().extensionAbilityType == AppExecFwk::ExtensionAbilityType::EMBEDDED_UI))) { TAG_LOGE(AAFwkTag::ABILITYMGR, "type is not UIAbility or embedded_ui"); - return RESOLVE_ABILITY_ERR; + return ERR_CHECK_PLUGIN_INVALID_TYPE; } if (abilityRecord->IsPluginAbility()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "not host ability"); - return RESOLVE_ABILITY_ERR; + return ERR_CALLER_IS_PLUGIN_ABILITY; } return ERR_OK; } diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 393a1a225648ec0f311f428b4971a512a7110cd7..08cefc03aaf94aa28e8a5d5f10e5a9f17f5afb55 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -1423,9 +1423,7 @@ int AbilityRecord::TerminateAbility() HandleDlpClosed(); #endif // WITH_DLP AAFwk::EventInfo eventInfo; - eventInfo.bundleName = GetAbilityInfo().bundleName; - eventInfo.abilityName = GetAbilityInfo().name; - eventInfo.appIndex = abilityInfo_.applicationInfo.appIndex; + BuildTerminateAbiltityEventInfo(eventInfo, 0); if (clearMissionFlag_) { TAG_LOGD(AAFwkTag::ABILITYMGR, "deleteAbilityRecoverInfo before clearMission"); (void)DelayedSingleton::GetInstance()-> @@ -1435,13 +1433,26 @@ int AbilityRecord::TerminateAbility() ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::DESTROY_END, GetPid(), GetUid(), 0, GetRecordId()); AAFwk::EventReport::SendAbilityEvent(AAFwk::EventName::TERMINATE_ABILITY, HiSysEventType::BEHAVIOR, eventInfo); - eventInfo.errCode = DelayedSingleton::GetInstance()->TerminateAbility(token_, clearMissionFlag_); - if (eventInfo.errCode != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "terminate ability failed: %{public}d", eventInfo.errCode); - AAFwk::EventReport::SendAbilityEvent( - AAFwk::EventName::TERMINATE_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); + auto ret = DelayedSingleton::GetInstance()->TerminateAbility(token_, clearMissionFlag_); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "terminate ability failed: %{public}d", ret); } - return eventInfo.errCode; + return ret; +} + +void AbilityRecord::BuildTerminateAbiltityEventInfo(EventInfo &eventInfo, int32_t errCode) +{ + eventInfo.bundleName = GetAbilityInfo().bundleName; + eventInfo.abilityName = GetAbilityInfo().name; + eventInfo.appIndex = abilityInfo_.applicationInfo.appIndex; + eventInfo.errCode = errCode; +} + +void AbilityRecord::SendTerminateAbilityErrorEvent(int32_t errCode) +{ + EventInfo eventInfo; + BuildTerminateAbiltityEventInfo(eventInfo, errCode); + EventReport::SendAbilityEvent(EventName::TERMINATE_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); } const AppExecFwk::AbilityInfo &AbilityRecord::GetAbilityInfo() const diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 0049dca370f76fdc44e532632615406442be7a74..5fb6f97263da77247d61900c975b8f5a3e291365 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -87,13 +87,13 @@ int AppScheduler::TerminateAbility(const sptr &token, bool clearM { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::ABILITYMGR, "Terminate ability."); - CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); + CHECK_POINTER_AND_RETURN(appMgrClient_, ERR_NULL_APP_MGR_CLIENT); /* because the errcode type of AppMgr Client API will be changed to int, * so must to covert the return result */ int ret = static_cast(IN_PROCESS_CALL(appMgrClient_->TerminateAbility(token, clearMissionFlag))); if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "AppScheduler fail to TerminateAbility. ret %d", ret); - return INNER_ERR; + TAG_LOGE(AAFwkTag::ABILITYMGR, "AppScheduler fail to TerminateAbility. ret %{public}d", ret); + return ERR_APP_MGR_TERMINATTE_ABILITY_FAILED; } return ERR_OK; } diff --git a/services/abilitymgr/src/free_install_manager.cpp b/services/abilitymgr/src/free_install_manager.cpp index 977415ffedff585e20db1e9dd9c95e783f04ff29..95904c82b19db02ac903fc3c0fd4972bcced164e 100644 --- a/services/abilitymgr/src/free_install_manager.cpp +++ b/services/abilitymgr/src/free_install_manager.cpp @@ -694,7 +694,7 @@ int FreeInstallManager::SetAppRunningState(Want &want) auto appMgr = AppMgrUtil::GetAppMgr(); if (appMgr == nullptr) { TAG_LOGE(AAFwkTag::FREE_INSTALL, "null appMgr"); - return ERR_INVALID_VALUE; + return ERR_NULL_APP_MGR_CLIENT; } bool isAppRunning = appMgr->GetAppRunningStateByBundleName(want.GetElement().GetBundleName()); diff --git a/services/abilitymgr/src/implicit_start_processor.cpp b/services/abilitymgr/src/implicit_start_processor.cpp index b42865a41cbe84eba7c502d728e1e169edd85a56..64e0cd7c02e3568749ac6897fe13f5d87e72588b 100644 --- a/services/abilitymgr/src/implicit_start_processor.cpp +++ b/services/abilitymgr/src/implicit_start_processor.cpp @@ -103,7 +103,7 @@ int ImplicitStartProcessor::CheckImplicitCallPermission(const AbilityRequest& ab CHECK_POINTER_AND_RETURN(abilityMgr, ERR_INVALID_VALUE); bool isBackgroundCall = true; if (abilityMgr->IsCallFromBackground(abilityRequest, isBackgroundCall) != ERR_OK) { - return ERR_INVALID_VALUE; + return ERR_CHECK_CALL_FROM_BACKGROUND_FAILED; } if (!isBackgroundCall) { TAG_LOGD(AAFwkTag::ABILITYMGR, "hap not background"); @@ -124,7 +124,7 @@ int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_ TAG_LOGI(AAFwkTag::ABILITYMGR, "implicit start ability by type: %{public}d", request.callType); bool isNfcCalling = (IPCSkeleton::GetCallingUid() == NFC_CALLER_UID); auto sysDialogScheduler = DelayedSingleton::GetInstance(); - CHECK_POINTER_AND_RETURN(sysDialogScheduler, ERR_INVALID_VALUE); + CHECK_POINTER_AND_RETURN(sysDialogScheduler, ERR_NULL_SYS_DIALOG_SCHEDULER); auto result = CheckImplicitCallPermission(request); if (ERR_OK != result) { @@ -613,7 +613,7 @@ int ImplicitStartProcessor::GenerateAbilityRequestByAppIndexes(int32_t userId, A auto appIndexes = StartAbilityUtils::GetCloneAppIndexes(request.want.GetBundle(), userId); if (appIndexes.size() > AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) { TAG_LOGE(AAFwkTag::ABILITYMGR, "too large appIndexes"); - return ERR_INVALID_VALUE; + return ERR_TOO_LARGE_APPINDEXES; } auto bms = GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED); @@ -808,8 +808,9 @@ int ImplicitStartProcessor::CallStartAbilityInner(int32_t userId, auto ret = callBack(); if (ret != ERR_OK) { - eventInfo.errCode = ret; + TAG_LOGE(AAFwkTag::ABILITYMGR, "CallStartAbilityInner failed: %{public}d", ret); if (callType == AbilityCallType::INVALID_TYPE) { + eventInfo.errCode = ERR_DO_CLOSURE_CALLBACK_FAILED; SendAbilityEvent(EventName::START_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); } } diff --git a/services/abilitymgr/src/interceptor/control_interceptor.cpp b/services/abilitymgr/src/interceptor/control_interceptor.cpp index a16512aad2d1ce5d2158caae64eade245f2e5410..127904d976549de55bf4e75ac46d19642fb6a58a 100644 --- a/services/abilitymgr/src/interceptor/control_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/control_interceptor.cpp @@ -56,7 +56,7 @@ ErrCode ControlInterceptor::DoProcess(AbilityInterceptorParam param) int ret = IN_PROCESS_CALL(AbilityManagerClient::GetInstance()->StartAbility(*controlRule.controlWant, param.requestCode, param.userId)); if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "start failed"); + TAG_LOGE(AAFwkTag::ABILITYMGR, "ControlInterceptor start failed:%{public}d", ret); return ret; } #endif diff --git a/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp b/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp index 262578a830a19fae1e87885e91e457a96cd14f1c..cad08a9932fcb0a615ab18e4391aa7cbaedc3db6 100644 --- a/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp @@ -36,7 +36,7 @@ ErrCode CrowdTestInterceptor::DoProcess(AbilityInterceptorParam param) int ret = IN_PROCESS_CALL(AbilityUtil::StartAppgallery(param.want.GetBundle(), param.requestCode, param.userId, ACTION_MARKET_CROWDTEST)); if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "start appGallery failed"); + TAG_LOGE(AAFwkTag::ABILITYMGR, "start appGallery failed:%{public}d", ret); return ret; } } diff --git a/services/abilitymgr/src/mission/mission_list_manager.cpp b/services/abilitymgr/src/mission/mission_list_manager.cpp index ed299adeca0956473cf0c45f29c1ef686ca967e9..68be75d1cc348111b80185d4a27b6773db74b9a3 100644 --- a/services/abilitymgr/src/mission/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission/mission_list_manager.cpp @@ -1894,9 +1894,11 @@ void MissionListManager::CompleteTerminate(const std::shared_ptr abilityRecord->RemoveAbilityDeathRecipient(); // notify AppMS terminate - if (abilityRecord->TerminateAbility() != ERR_OK) { + auto ret = abilityRecord->TerminateAbility(); + if (ret != ERR_OK) { // Don't return here - TAG_LOGE(AAFwkTag::ABILITYMGR, "AppMS fail to terminate ability"); + TAG_LOGE(AAFwkTag::ABILITYMGR, "AppMS fail to terminate ability:%{public}d", ret); + abilityRecord->SendTerminateAbilityErrorEvent(ret); } auto&& preAbilityRecord = abilityRecord->GetPreAbilityRecord(); diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index 7f4f20cbc1834bfd406342437109a77f9c990f42..399a65086bf376f9477ab42d58f8c6b38c0869f8 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -592,7 +592,7 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &ability { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (!AddStartCallerTimestamp(abilityRequest.want.GetIntParam(Want::PARAM_RESV_CALLER_UID, -1))) { - return ERR_INVALID_VALUE; + return ERR_FREQ_START_ABILITY; } abilityRequest.want.SetParam(IS_SHELL_CALL, AAFwk::PermissionVerification::GetInstance()->IsShellCall()); std::string callerKey = std::to_string(IPCSkeleton::GetCallingPid()) + ":" + @@ -600,7 +600,7 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &ability bool isCallerKilling = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->IsCallerKilling(callerKey)); if (isCallerKilling) { TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is killing"); - return ERR_INVALID_VALUE; + return ERR_CALLER_IS_KILLING; } abilityRequest.want.SetParam(Want::PARAMS_REAL_CALLER_KEY, callerKey); std::lock_guard guard(sessionLock_); @@ -627,21 +627,22 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &ability if (IsHookModule(abilityRequest)) { auto abilityRecord = FindRecordFromSessionMap(abilityRequest); - if (abilityRecord != nullptr) { - if (abilityRecord->IsHook() && !abilityRecord->GetHookOff()) { - AbilityRequest request; - request.callerToken = abilityRequest.callerToken; - sptr hookSessionInfo = abilityRecord->GetSessionInfo(); - if (hookSessionInfo != nullptr) { - hookSessionInfo->want = abilityRequest.want; - } - std::string errMsg; - int ret = NotifySCBPendingActivation(hookSessionInfo, request, errMsg); - if (hookSessionInfo != nullptr) { - hookSessionInfo->want.RemoveAllFd(); - } - return ret; + if (abilityRecord != nullptr && abilityRecord->IsHook() && !abilityRecord->GetHookOff()) { + AbilityRequest request; + request.callerToken = abilityRequest.callerToken; + sptr hookSessionInfo = abilityRecord->GetSessionInfo(); + if (hookSessionInfo != nullptr) { + hookSessionInfo->want = abilityRequest.want; } + std::string errMsg; + int ret = NotifySCBPendingActivation(hookSessionInfo, request, errMsg); + if (hookSessionInfo != nullptr) { + hookSessionInfo->want.RemoveAllFd(); + } + if (ret == ERR_INVALID_VALUE) { + ret = ERR_NOTIFY_SCB_PENDING_ACTIVATION_FAILED; + } + return ret; } } auto sessionInfo = CreateSessionInfo(abilityRequest); @@ -658,6 +659,9 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &ability sessionInfo->persistentId, userId_, requestId); std::string errMsg; int ret = NotifySCBPendingActivation(sessionInfo, abilityRequest, errMsg); + if (ret == ERR_INVALID_VALUE) { + ret = ERR_NOTIFY_SCB_PENDING_ACTIVATION_FAILED; + } sessionInfo->want.RemoveAllFd(); return ret; } @@ -1578,7 +1582,11 @@ int UIAbilityLifecycleManager::NotifySCBPendingActivation(sptr &ses const_cast(abilityRequest).want.RemoveParam(KEY_REQUEST_ID); TAG_LOGI(AAFwkTag::ABILITYMGR, "scb call, NotifySCBPendingActivation for callerSession, target: %{public}s" "requestId:%{public}s", sessionInfo->want.GetElement().GetAbilityName().c_str(), requestId.c_str()); - return static_cast(callerSession->PendingSessionActivation(sessionInfo)); + auto ret = static_cast(callerSession->PendingSessionActivation(sessionInfo)); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "PendingSessionActivation failed:%{public}d", ret); + } + return ret; } auto tmpSceneSession = iface_cast(rootSceneSession_); if (tmpSceneSession == nullptr) { @@ -1598,7 +1606,11 @@ int UIAbilityLifecycleManager::NotifySCBPendingActivation(sptr &ses sessionInfo->canStartAbilityFromBackground = true; TAG_LOGI(AAFwkTag::ABILITYMGR, "scb call, NotifySCBPendingActivation for rootSceneSession, target: %{public}s", sessionInfo->want.GetElement().GetAbilityName().c_str()); - return static_cast(tmpSceneSession->PendingSessionActivation(sessionInfo)); + auto ret = static_cast(tmpSceneSession->PendingSessionActivation(sessionInfo)); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "PendingSessionActivation failed:%{public}d", ret); + } + return ret; } bool UIAbilityLifecycleManager::IsHookModule(const AbilityRequest &abilityRequest) const @@ -1869,7 +1881,7 @@ int UIAbilityLifecycleManager::CloseUIAbility(const std::shared_ptr guard(sessionLock_); - CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + CHECK_POINTER_AND_RETURN(abilityRecord, ERR_UI_ABILITY_MANAGER_NULL_ABILITY_RECORD); std::string element = abilityRecord->GetElementName().GetURI(); TAG_LOGI(AAFwkTag::ABILITYMGR, "CloseUIAbility call: %{public}s", element.c_str()); if (abilityRecord->IsTerminating() && !abilityRecord->IsForeground()) { @@ -1929,7 +1941,7 @@ void UIAbilityLifecycleManager::PrepareCloseUIAbility(std::shared_ptr abilityRecord) { - CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + CHECK_POINTER_AND_RETURN(abilityRecord, ERR_UI_ABILITY_MANAGER_NULL_ABILITY_RECORD); if (abilityRecord->IsAbilityState(FOREGROUND) || abilityRecord->IsAbilityState(FOREGROUNDING)) { abilityRecord->SetPendingState(AbilityState::BACKGROUND); MoveToBackground(abilityRecord); @@ -1978,11 +1990,12 @@ void UIAbilityLifecycleManager::CompleteTerminateLocked(const std::shared_ptrRemoveAbilityDeathRecipient(); - + auto ret = abilityRecord->TerminateAbility(); // notify AppMS terminate - if (abilityRecord->TerminateAbility() != ERR_OK) { + if (ret != ERR_OK) { // Don't return here TAG_LOGE(AAFwkTag::ABILITYMGR, "appMS fail to terminate ability"); + abilityRecord->SendTerminateAbilityErrorEvent(ret); } terminateAbilityList_.remove(abilityRecord); } @@ -3694,7 +3707,7 @@ int32_t UIAbilityLifecycleManager::CleanUIAbility( const std::shared_ptr &abilityRecord) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); - CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + CHECK_POINTER_AND_RETURN(abilityRecord, ERR_UI_ABILITY_MANAGER_NULL_ABILITY_RECORD); HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); std::string element = abilityRecord->GetElementName().GetURI(); if (DelayedSingleton::GetInstance()->CleanAbilityByUserRequest(abilityRecord->GetToken())) { diff --git a/test/new_test/unit_test/ability_errors_util_test/BUILD.gn b/test/new_test/unit_test/ability_errors_util_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c748a7da643f3a4035cf8ac3c089b36b7b61c0d2 --- /dev/null +++ b/test/new_test/unit_test/ability_errors_util_test/BUILD.gn @@ -0,0 +1,47 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("ability_errors_util_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_path}/services/abilitymgr/include/utils/ability_errors_util.h", + ] + + sources = [ + "ability_errors_util_test.cpp", + ] + + deps = [ + "${ability_runtime_native_path}/ability/native:ability_business_error", + ] + + external_deps = [ + "c_utils:utils", + "ffrt:libffrt", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "json:nlohmann_json_static" + ] +} + +group("unittest") { + testonly = true + deps = [ ":ability_errors_util_test" ] +} \ No newline at end of file diff --git a/test/new_test/unit_test/ability_errors_util_test/ability_errors_util_test.cpp b/test/new_test/unit_test/ability_errors_util_test/ability_errors_util_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9af87f0be49b9143ea38af7961dafdd730d0ac1d --- /dev/null +++ b/test/new_test/unit_test/ability_errors_util_test/ability_errors_util_test.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "ability_errors_util.h + +using namespace testing; +using namespace testing::ext; + + +namespace OHOS { +namespace AppExecFwk { +class UserControllerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void UserControllerTest::SetUpTestCase() +{} + +void UserControllerTest::TearDownTestCase() +{} + +void UserControllerTest::SetUp() +{} + +void UserControllerTest::TearDown() +{} + +/** + * @tc.name: ConvertToOriginErrorCode_Test_001 + * @tc.desc: test refiniment ERR_INVALID_VALUE. + * @tc.type: FUNC + */ +HWTEST_F(UserControllerTest, ConvertToOriginErrorCode_Test_001, TestSize.Level1) +{ + auto oriRet = AAFWK::AbilityErrorUtil::ConvertToOriginErrorCode(ERR_CONNECT_MANAGER_NULL_ABILITY_RECORD); + EXPECT_EQ(oriRet, ERR_INVALID_VALUE); +} + +/** + * @tc.name: ConvertToOriginErrorCode_Test_002 + * @tc.desc: test refiniment INNER_ERR. + * @tc.type: FUNC + */ +HWTEST_F(UserControllerTest, ConvertToOriginErrorCode_Test_002, TestSize.Level1) +{ + auto oriRet = AAFWK::AbilityErrorUtil::ConvertToOriginErrorCode(ERR_APP_MGR_TERMINATTE_ABILITY_FAILED); + EXPECT_EQ(oriRet, INNER_ERR); +} + +/** + * @tc.name: ConvertToOriginErrorCode_Test_003 + * @tc.desc: test refiniment RESOLVE_ABILITY_ERR. + * @tc.type: FUNC + */ +HWTEST_F(UserControllerTest, ConvertToOriginErrorCode_Test_003, TestSize.Level1) +{ + auto oriRet = AAFWK::AbilityErrorUtil::ConvertToOriginErrorCode(ERR_CONNECT_MANAGER_NULL_ABILITY_RECORD); + EXPECT_EQ(oriRet, RESOLVE_ABILITY_ERR); +} + +/** + * @tc.name: ConvertToOriginErrorCode_Test_004 + * @tc.desc: test refiniment ERR_INVALID_CALLER. + * @tc.type: FUNC + */ +HWTEST_F(UserControllerTest, ConvertToOriginErrorCode_Test_004, TestSize.Level1) +{ + auto oriRet = AAFWK::AbilityErrorUtil::ConvertToOriginErrorCode(ERR_IS_NOT_SPECIFIED_SA); + EXPECT_EQ(oriRet, ERR_INVALID_CALLER); +} + +/** + * @tc.name: ConvertToOriginErrorCode_Test_005 + * @tc.desc: test refiniment ERR_OK. + * @tc.type: FUNC + */ +HWTEST_F(UserControllerTest, ConvertToOriginErrorCode_Test_005, TestSize.Level1) +{ + auto oriRet = AAFWK::AbilityErrorUtil::ConvertToOriginErrorCode(ERR_OK); + EXPECT_EQ(oriRet, ERR_OK); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ability_record.cpp b/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ability_record.cpp index e7723d95d9e49cc1658d943f4381d30e14a1fd6f..a2e135f9a3039e5237dc875248cbe0692beb7ef0 100644 --- a/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ability_record.cpp +++ b/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ability_record.cpp @@ -1984,5 +1984,9 @@ void AbilityRecord::NotifyAbilityRequestFailure(const std::string &requestId, co void AbilityRecord::UpdateUIExtensionBindInfo(const WantParams &wantParams) { } + +void AbilityRecord::SendTerminateAbilityErrorEvent(int32_t errCode) +{ +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ability_record.cpp b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ability_record.cpp index 67239e86f44f555691e6dadf4efc636579773be4..2d26ddb48f6b877a580cdad93246a4420d2dde7f 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ability_record.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ability_record.cpp @@ -2013,5 +2013,8 @@ void AbilityRecord::NotifyAbilityRequestFailure(const std::string &requestId, co void AbilityRecord::UpdateUIExtensionBindInfo(const WantParams &wantParams) { } +void AbilityRecord::SendTerminateAbilityErrorEvent(int32_t errCode) +{ +} } // namespace AAFwk } // namespace OHOS