From c493e69068c5a0b8c990e7fef26767cf40b044cd Mon Sep 17 00:00:00 2001 From: Nathan Yang Date: Tue, 5 Aug 2025 10:58:10 +0800 Subject: [PATCH 1/2] feat: add StartSelfUIAbilityWithReceivingPid Signed-off-by: Nathan Yang --- .../include/ability_business_error_utils.h | 4 +- .../src/ability_business_error_utils.cpp | 30 ++++- .../src/application_context.cpp | 26 ++++- .../ability/native/ui_ability_thread.cpp | 1 + .../include/ability_manager_client.h | 19 +++ .../include/ability_manager_errors.h | 5 + .../include/ability_manager_interface.h | 23 ++++ .../ability_manager_ipc_interface_code.h | 6 + .../ability_manager/include/process_options.h | 1 + .../ability_runtime/ability_runtime_common.h | 5 + .../c/ability_runtime/application_context.h | 37 ++++++ .../include/ability_manager_proxy.h | 19 +++ .../include/ability_manager_service.h | 33 ++++++ .../abilitymgr/include/ability_manager_stub.h | 2 + services/abilitymgr/include/ability_record.h | 11 ++ .../abilitymgr/src/ability_manager_client.cpp | 21 +++- .../abilitymgr/src/ability_manager_proxy.cpp | 56 +++++++++ .../src/ability_manager_service.cpp | 109 +++++++++++++++++- .../abilitymgr/src/ability_manager_stub.cpp | 40 +++++++ services/abilitymgr/src/ability_record.cpp | 8 +- services/abilitymgr/src/process_options.cpp | 5 + .../ui_ability_lifecycle_manager.cpp | 6 +- ...ility_runtime_application_context_test.cpp | 62 +++++----- utils/global/constant/global_constant.h | 1 + 24 files changed, 484 insertions(+), 46 deletions(-) diff --git a/frameworks/c/ability_runtime/include/ability_business_error_utils.h b/frameworks/c/ability_runtime/include/ability_business_error_utils.h index 83d34646962..4cc296078f3 100644 --- a/frameworks/c/ability_runtime/include/ability_business_error_utils.h +++ b/frameworks/c/ability_runtime/include/ability_business_error_utils.h @@ -22,6 +22,8 @@ AbilityRuntime_ErrorCode ConvertToCommonBusinessErrorCode(int32_t abilityManagerErrorCode); -AbilityRuntime_ErrorCode ConvertToAPI18BusinessErrorCode(int32_t abilityManagerErrorCode); +AbilityRuntime_ErrorCode ConvertToAPI17BusinessErrorCode(int32_t abilityManagerErrorCode); + +AbilityRuntime_ErrorCode ConvertToAPI21BusinessErrorCode(int32_t abilityManagerErrorCode); #endif // ABILITY_RUNTIME_ABILITY_BUSINESS_ERROR_UTILS_H diff --git a/frameworks/c/ability_runtime/src/ability_business_error_utils.cpp b/frameworks/c/ability_runtime/src/ability_business_error_utils.cpp index 05099eaa108..43e4219c6cd 100644 --- a/frameworks/c/ability_runtime/src/ability_business_error_utils.cpp +++ b/frameworks/c/ability_runtime/src/ability_business_error_utils.cpp @@ -42,13 +42,17 @@ std::unordered_map g_innerToBusinessErrorComm { OHOS::AAFwk::ERR_APP_INSTANCE_KEY_NOT_SUPPORT, ABILITY_RUNTIME_ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORTED }, { OHOS::AAFwk::ERR_NOT_SELF_APPLICATION, ABILITY_RUNTIME_ERROR_CODE_CROSS_APP }, }; - -std::unordered_map g_innerToBusinessErrorApi18Map { + +std::unordered_map g_innerToBusinessErrorApi17Map { { OHOS::AAFwk::ERR_MULTI_APP_NOT_SUPPORTED, ABILITY_RUNTIME_ERROR_CODE_MULTI_APP_NOT_SUPPORTED }, { OHOS::AAFwk::ERR_INVALID_APP_INSTANCE_KEY, ABILITY_RUNTIME_ERROR_CODE_INVALID_APP_INSTANCE_KEY }, { OHOS::AAFwk::ERR_MULTI_INSTANCE_NOT_SUPPORTED, ABILITY_RUNTIME_ERROR_MULTI_INSTANCE_NOT_SUPPORTED }, }; +std::unordered_map g_innerToBusinessErrorApi21Map { +{ OHOS::AAFwk::ERR_ATTACH_ABILITY_THREAD_FAILED, ABILITY_RUNTIME_ERROR_CODE_START_TIMEOUT }, +}; + AbilityRuntime_ErrorCode ConvertToCommonBusinessErrorCode(int32_t abilityManagerErrorCode) { TAG_LOGI(AAFwkTag::APPKIT, "ability errCode:%{public}d", abilityManagerErrorCode); @@ -60,7 +64,7 @@ AbilityRuntime_ErrorCode ConvertToCommonBusinessErrorCode(int32_t abilityManager return ABILITY_RUNTIME_ERROR_CODE_INTERNAL; } -AbilityRuntime_ErrorCode ConvertToAPI18BusinessErrorCode(int32_t abilityManagerErrorCode) +AbilityRuntime_ErrorCode ConvertToAPI17BusinessErrorCode(int32_t abilityManagerErrorCode) { TAG_LOGI(AAFwkTag::APPKIT, "ability errCode:%{public}d", abilityManagerErrorCode); auto errCode = ConvertToCommonBusinessErrorCode(abilityManagerErrorCode); @@ -68,8 +72,24 @@ AbilityRuntime_ErrorCode ConvertToAPI18BusinessErrorCode(int32_t abilityManagerE return errCode; } - auto it = g_innerToBusinessErrorApi18Map.find(abilityManagerErrorCode); - if (it != g_innerToBusinessErrorApi18Map.end()) { + auto it = g_innerToBusinessErrorApi17Map.find(abilityManagerErrorCode); + if (it != g_innerToBusinessErrorApi17Map.end()) { + return it->second; + } + + return ABILITY_RUNTIME_ERROR_CODE_INTERNAL; +} + +AbilityRuntime_ErrorCode ConvertToAPI21BusinessErrorCode(int32_t abilityManagerErrorCode) +{ + TAG_LOGI(AAFwkTag::APPKIT, "ability errCode:%{public}d", abilityManagerErrorCode); + auto errCode = ConvertToAPI17BusinessErrorCode(abilityManagerErrorCode); + if (errCode != ABILITY_RUNTIME_ERROR_CODE_INTERNAL) { + return errCode; + } + + auto it = g_innerToBusinessErrorApi21Map.find(abilityManagerErrorCode); + if (it != g_innerToBusinessErrorApi21Map.end()) { return it->second; } diff --git a/frameworks/c/ability_runtime/src/application_context.cpp b/frameworks/c/ability_runtime/src/application_context.cpp index b4a34372ee4..86b7d530e29 100644 --- a/frameworks/c/ability_runtime/src/application_context.cpp +++ b/frameworks/c/ability_runtime/src/application_context.cpp @@ -340,6 +340,30 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbilityWithStartOptions(Ab return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; } OHOS::AAFwk::StartOptions startOptions = options->GetInnerStartOptions(); - return ConvertToAPI18BusinessErrorCode(AbilityManagerClient::GetInstance()->StartSelfUIAbilityWithStartOptions( + return ConvertToAPI17BusinessErrorCode(AbilityManagerClient::GetInstance()->StartSelfUIAbilityWithStartOptions( abilityWant, startOptions)); +} + +AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbilityWithPidResult(AbilityBase_Want *want, + AbilityRuntime_StartOptions *options, int32_t &targetPid) +{ + TAG_LOGD(AAFwkTag::APPKIT, "StartSelfUIAbilityWithPidResult called"); + auto ret = CheckWant(want); + if (ret != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { + TAG_LOGE(AAFwkTag::APPKIT, "CheckWant failed: %{public}d", ret); + return ret; + } + if (options == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "null options"); + return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; + } + Want abilityWant; + AbilityBase_ErrorCode errCode = CWantManager::TransformToWant(*want, false, abilityWant); + if (errCode != ABILITY_BASE_ERROR_CODE_NO_ERROR) { + TAG_LOGE(AAFwkTag::APPKIT, "transform error:%{public}d", errCode); + return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; + } + OHOS::AAFwk::StartOptions startOptions = options->GetInnerStartOptions(); + return ConvertToAPI21BusinessErrorCode(AbilityManagerClient::GetInstance()->StartSelfUIAbilityWithPidResult( + abilityWant, startOptions, targetPid)); } \ No newline at end of file diff --git a/frameworks/native/ability/native/ui_ability_thread.cpp b/frameworks/native/ability/native/ui_ability_thread.cpp index 98685a8a16a..730d6dc2754 100644 --- a/frameworks/native/ability/native/ui_ability_thread.cpp +++ b/frameworks/native/ability/native/ui_ability_thread.cpp @@ -170,6 +170,7 @@ void UIAbilityThread::AttachInner(const std::shared_ptrAttachAbilityThread(this, token_); + AbilityManagerClient::GetInstance()->NotifyAttachAbilityThreadDone(token_, err); if (err != ERR_OK) { entry = std::string("AbilityThread::Attach; error ") + std::to_string(err); FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 60e6e80a814..e2fe27b0fe5 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -63,6 +63,17 @@ public: */ ErrCode StartSelfUIAbilityWithStartOptions(const Want &want, const StartOptions &options); + /** + * Starts self UIAbility with start options and receives the process ID. Supported only on 2-in-1 devices. + * + * @param want, the want of the ability to start. + * @param options, the startOptions of the ability to start. + * @param pid, the process id of the started ability. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode StartSelfUIAbilityWithPidResult(const Want &want, const StartOptions &options, + int32_t &pid); + /** * AttachAbilityThread, ability call this interface after loaded. * @@ -72,6 +83,14 @@ public: */ ErrCode AttachAbilityThread(sptr scheduler, sptr token); + /** + * NotifyAttachAbilityThreadDone, ability call this interface after loaded. + * + * @param token, ability's token. + * @param errCode, the error code of AttachAbilityThread. + */ + void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode); + /** * AbilityTransitionDone, ability call this interface after lift cycle was changed. * 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 4d87bac9f82..e27c532e82e 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -1231,6 +1231,11 @@ enum NativeFreeInstallError { */ ERR_WRITE_INT_FAILED = 29360221, + /* + * Result(29360222) for attaching ability failed. + */ + ERR_ATTACH_ABILITY_THREAD_FAILED = 29360222, + /** * Undefine error code. */ diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index c04c88ea43a..17103165d84 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -131,6 +131,20 @@ public: return 0; } + /** + * Starts self UIAbility with start options and receives the process ID. Supported only on 2-in-1 devices. + * + * @param want, the want of the ability to start. + * @param options, the startOptions of the ability to start. + * @param pid, the process id of the started ability. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int StartSelfUIAbilityWithPidResult(const Want &want, const StartOptions &options, + int32_t &pid) + { + return 0; + } + /** * StartAbility with want, send want to ability manager service. * @@ -764,6 +778,15 @@ public: */ virtual int AttachAbilityThread(const sptr &scheduler, const sptr &token) = 0; + /** + * NotifyAttachAbilityThreadDone, ability call this interface after loaded. + * + * @param token, ability's token. + * @param errCode, the error code of AttachAbilityThread. + */ + virtual void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode) + {} + /** * AbilityTransitionDone, ability call this interface after life cycle was changed. * diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h index 38921bbefa8..0e4445b659e 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h @@ -670,6 +670,12 @@ enum class AbilityManagerInterfaceCode { // preload application PRELOAD_APPLICATION = 6151, + + // start self uiability with startOptions and receives the pid + START_SELF_UI_ABILITY_WITH_PID_RESULT = 6152, + + // notify ability thread attach result + NOTIFY_ATTACH_ABILITY_THREAD_DONE = 6153, }; } // namespace AAFwk } // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/include/process_options.h b/interfaces/inner_api/ability_manager/include/process_options.h index 5a4a540bf2b..2f0c22ddb01 100644 --- a/interfaces/inner_api/ability_manager/include/process_options.h +++ b/interfaces/inner_api/ability_manager/include/process_options.h @@ -58,6 +58,7 @@ public: bool isRestartKeepAlive = false; bool isStartFromNDK = false; bool isPreloadStart = false; + bool shouldReturnPid = false; ProcessMode processMode = ProcessMode::UNSPECIFIED; StartupVisibility startupVisibility = StartupVisibility::UNSPECIFIED; std::string processName; diff --git a/interfaces/kits/c/ability_runtime/ability_runtime_common.h b/interfaces/kits/c/ability_runtime/ability_runtime_common.h index 704d6c80fb9..a12876fda14 100644 --- a/interfaces/kits/c/ability_runtime/ability_runtime_common.h +++ b/interfaces/kits/c/ability_runtime/ability_runtime_common.h @@ -138,6 +138,11 @@ typedef enum { * @since 17 */ ABILITY_RUNTIME_ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORTED = 16000079, + /** + * @error Start UIAbility time out. + * @since 21 + */ + ABILITY_RUNTIME_ERROR_CODE_START_TIMEOUT = 16000133, } AbilityRuntime_ErrorCode; #ifdef __cplusplus diff --git a/interfaces/kits/c/ability_runtime/application_context.h b/interfaces/kits/c/ability_runtime/application_context.h index 95356eb1266..61512bfda32 100644 --- a/interfaces/kits/c/ability_runtime/application_context.h +++ b/interfaces/kits/c/ability_runtime/application_context.h @@ -297,6 +297,43 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbilityWithStartOptions(Ab AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetResourceDir(const char* moduleName, char* buffer, const int32_t bufferSize, int32_t* writeLength); +/** + * @brief Starts self UIAbility with start options and receives the process ID. + * + * @permission {@code ohos.permission.NDK_START_SELF_UI_ABILITY} + * @param want The arguments passed to start self UIAbility. + * For details, see {@link AbilityBase_Want}. + * @param options The start options passed to start self UIAbility. + * For details, see {@link AbilityRuntime_StartOptions}. + * @param pid The process ID of the started UIAbility. + * @return Returns {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the call is successful. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_PERMISSION_DENIED} if the caller has no correct permission. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the arguments provided is invalid. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_NOT_SUPPORTED} if the device does not support starting self uiability. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_NO_SUCH_ABILITY} if the target ability does not exist. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_INCORRECT_ABILITY_TYPE} if the ability type is incorrect. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_CROWDTEST_EXPIRED} if the crowdtesting application expires. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_WUKONG_MODE} if the ability cannot be started in Wukong mode. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_CONTROLLED} if the app is controlled. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_EDM_CONTROLLED} if the app is controlled by EDM. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_CROSS_APP} if the caller tries to start a different application. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_INTERNAL} if internal error occurs. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_NOT_TOP_ABILITY} if the caller is not foreground process. + * Returns {@link ABILITY_RUNTIME_ERROR_VISIBILITY_SETTING_DISABLED} if setting visibility is disabled. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_MULTI_APP_NOT_SUPPORTED} + * if the app clone or multi-instance is not supported. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_INVALID_APP_INSTANCE_KEY} if the app instance key is invalid. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_UPPER_LIMIT_REACHED} if the number of app instances reached the limit. + * Returns {@link ABILITY_RUNTIME_ERROR_MULTI_INSTANCE_NOT_SUPPORTED} if the multi-instance is not supported. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORTED} + * if the APP_INSTANCE_KEY cannot be specified. + * Returns {@link ABILITY_RUNTIME_ERROR_CODE_START_TIMEOUT} Start UIAbility time out. + * For details, see {@link AbilityRuntime_ErrorCode}. + * @since 21 + */ +AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbilityWithPidResult(AbilityBase_Want *want, + AbilityRuntime_StartOptions *options, int32_t &targetPid); + #ifdef __cplusplus } // extern "C" #endif diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 90aa5002ea4..d75ff7cb4e6 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -55,6 +55,17 @@ public: virtual int StartSelfUIAbilityWithStartOptions(const Want &want, const StartOptions &options) override; + /** + * Starts self UIAbility with start options and receives the process ID. Supported only on 2-in-1 devices. + * + * @param want, the want of the ability to start. + * @param options, the startOptions of the ability to start. + * @param pid, the process id of the started ability. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int StartSelfUIAbilityWithPidResult(const Want &want, const StartOptions &options, + int32_t &pid) override; + /** * StartAbility with want, send want to ability manager service. * @@ -543,6 +554,14 @@ public: virtual int AttachAbilityThread( const sptr &scheduler, const sptr &token) override; + /** + * NotifyAttachAbilityThreadDone, ability call this interface after loaded. + * + * @param token, ability's token. + * @param errCode, the error code of AttachAbilityThread. + */ + virtual void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode) override; + /** * AbilityTransitionDone, ability call this interface after lift cycle was changed. * diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 01a1152b878..08abb7db6bd 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -139,6 +139,17 @@ public: virtual int StartSelfUIAbilityWithStartOptions(const Want &want, const StartOptions &options) override; + /** + * Starts self UIAbility with start options and receives the process ID. Supported only on 2-in-1 devices. + * + * @param want, the want of the ability to start. + * @param options, the startOptions of the ability to start. + * @param pid, the process id of the started ability. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int StartSelfUIAbilityWithPidResult(const Want &want, const StartOptions &options, + int32_t &pid) override; + /** * StartAbility with want, send want to ability manager service. * @@ -795,6 +806,14 @@ public: virtual int AttachAbilityThread( const sptr &scheduler, const sptr &token) override; + /** + * NotifyAttachAbilityThreadDone, ability call this interface after loaded. + * + * @param token, ability's token. + * @param errCode, the error code of AttachAbilityThread. + */ + virtual void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode) override; + /** * AbilityTransitionDone, ability call this interface after lift cycle was changed. * @@ -2848,6 +2867,20 @@ private: std::mutex prepareTermiationCallbackMutex_; std::map> prepareTermiationCallbacks_; AbilityEventUtil eventHelper_; + + std::mutex ndkStartMutex_; + std::condition_variable ndkStartCv_; + struct NDKStartRecord { + std::string bundleName_; + std::string abilityName_; + std::atomic_bool done_ = false; + std::atomic_int pid_ = -1; + + NDKStartRecord(const std::string &bundleName, const std::string &abilityName) + : bundleName_(bundleName), abilityName_(abilityName) + {} + }; + std::vector> ndkStartRecords_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index d98997a8075..823d8ab26ca 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -81,6 +81,7 @@ private: int MinimizeUIExtensionAbilityInner(MessageParcel &data, MessageParcel &reply); int MinimizeUIAbilityBySCBInner(MessageParcel &data, MessageParcel &reply); int AttachAbilityThreadInner(MessageParcel &data, MessageParcel &reply); + int NotifyAttachAbilityThreadDoneInner(MessageParcel &data, MessageParcel &reply); int AbilityTransitionDoneInner(MessageParcel &data, MessageParcel &reply); int AbilityWindowConfigTransitionDoneInner(MessageParcel &data, MessageParcel &reply); int ScheduleConnectAbilityDoneInner(MessageParcel &data, MessageParcel &reply); @@ -95,6 +96,7 @@ private: int32_t UpgradeAppInner(MessageParcel &data, MessageParcel &reply); int StartSelfUIAbilityInner(MessageParcel &data, MessageParcel &reply); int StartSelfUIAbilityWithStartOptionsInner(MessageParcel &data, MessageParcel &reply); + int StartSelfUIAbilityWithPidResultInner(MessageParcel &data, MessageParcel &reply); int StartAbilityInner(MessageParcel &data, MessageParcel &reply); int StartAbilityInnerSpecifyTokenId(MessageParcel &data, MessageParcel &reply); int StartAbilityByUIContentSessionAddCallerInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 79b765ebba5..d272c547c0e 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -1267,6 +1267,16 @@ public: return isPreloadStart_.load(); } + inline void SetShouldReturnPid(bool shouldReturnPid) + { + shouldReturnPid_.store(shouldReturnPid); + } + + inline bool ShouldReturnPid() const + { + return shouldReturnPid_.load(); + } + inline void SetPreloaded() { isPreloaded_.store(true); @@ -1392,6 +1402,7 @@ private: #endif void SendAppStartupTypeEvent(const AppExecFwk::AppStartType startType); std::atomic isPreloadStart_ = false; // is ability started via preload + std::atomic shouldReturnPid_ = false; static std::atomic abilityRecordId; bool isReady_ = false; // is ability thread attached? diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index e4149b294d1..0f9a881e082 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -91,6 +91,14 @@ ErrCode AbilityManagerClient::AttachAbilityThread( return abms->AttachAbilityThread(scheduler, token); } +void AbilityManagerClient::NotifyAttachAbilityThreadDone( + sptr token, int32_t errCode) +{ + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN(abms); + abms->NotifyAttachAbilityThreadDone(token, errCode); +} + ErrCode AbilityManagerClient::AbilityTransitionDone(sptr token, int state, const PacMap &saveData) { auto abms = GetAbilityManager(); @@ -2173,7 +2181,7 @@ ErrCode AbilityManagerClient::QueryAtomicServiceStartupRule(sptr ErrCode AbilityManagerClient::StartSelfUIAbility(const Want &want) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); + TAG_LOGI(AAFwkTag::ABILITYMGR, "call StartSelfUIAbilityWithStartOptions"); auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); return abms->StartSelfUIAbility(want); @@ -2182,12 +2190,21 @@ ErrCode AbilityManagerClient::StartSelfUIAbility(const Want &want) ErrCode AbilityManagerClient::StartSelfUIAbilityWithStartOptions(const Want &want, const StartOptions &options) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); + TAG_LOGI(AAFwkTag::ABILITYMGR, "call StartSelfUIAbilityWithStartOptions"); auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); return abms->StartSelfUIAbilityWithStartOptions(want, options); } +ErrCode AbilityManagerClient::StartSelfUIAbilityWithPidResult(const Want &want, + const StartOptions &options, int32_t &pid) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, "call StartSelfUIAbilityWithPidResult"); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abms); + return abms->StartSelfUIAbilityWithPidResult(want, options, pid); +} + void AbilityManagerClient::PrepareTerminateAbilityDone(sptr token, bool isTerminate) { TAG_LOGI(AAFwkTag::ABILITYMGR, "call PrepareTerminateAbilityDone"); diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 8ab7a0ec36f..12857ae3fe0 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -1560,6 +1560,30 @@ int AbilityManagerProxy::AttachAbilityThread(const sptr &sche return reply.ReadInt32(); } +void AbilityManagerProxy::NotifyAttachAbilityThreadDone(sptr token, int32_t errCode) +{ + int error; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteRemoteObject(token)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail"); + return; + } + if (!data.WriteInt32(errCode)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write errCode fail"); + return; + } + + error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_ATTACH_ABILITY_THREAD_DONE, data, reply, option); + if (error != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error); + } +} + int AbilityManagerProxy::AbilityTransitionDone(const sptr &token, int state, const PacMap &saveData) { int error; @@ -6447,6 +6471,38 @@ int32_t AbilityManagerProxy::StartSelfUIAbilityWithStartOptions(const Want &want return reply.ReadInt32(); } +int32_t AbilityManagerProxy::StartSelfUIAbilityWithPidResult(const Want &want, const StartOptions &options, + int32_t &pid) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail"); + return ERR_WRITE_INTERFACE_CODE; + } + + if (!data.WriteParcelable(&want)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write want fail"); + return ERR_WRITE_WANT; + } + + if (!data.WriteParcelable(&options)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write startOptions fail"); + return ERR_WRITE_START_OPTIONS; + } + + auto error = SendRequest(AbilityManagerInterfaceCode::START_SELF_UI_ABILITY_WITH_PID_RESULT, + data, reply, option); + if (error != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error); + return error; + } + pid = reply.ReadInt32(); + return reply.ReadInt32(); +} + void AbilityManagerProxy::PrepareTerminateAbilityDone(const sptr &token, bool isTerminate) { MessageParcel data; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index b69764e9456..5a9a18bcb3c 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -6331,7 +6331,7 @@ int AbilityManagerService::AttachAbilityThread( { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); XCOLLIE_TIMER_LESS(__PRETTY_FUNCTION__); - TAG_LOGI(AAFwkTag::ABILITYMGR, "called"); + TAG_LOGI(AAFwkTag::ABILITYMGR, "AttachAbilityThread called"); CHECK_POINTER_AND_RETURN(scheduler, ERR_INVALID_VALUE); if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && !VerificationAllToken(token)) { return ERR_INVALID_VALUE; @@ -12129,6 +12129,11 @@ int32_t AbilityManagerService::CheckStartSelfUIAbilityStartOptions(const Want &w CHECK_TRUE_RETURN_RET(!Rosen::SceneBoardJudgement::IsSceneBoardEnabled() || !isEnable, ERR_CAPABILITY_NOT_SUPPORT, "not support process options"); + if (startOptions.processOptions->startupVisibility == StartupVisibility::UNSPECIFIED && + startOptions.processOptions->shouldReturnPid) { + return ERR_OK; + } + auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid()); CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); @@ -14581,6 +14586,108 @@ int AbilityManagerService::StartSelfUIAbilityWithStartOptions(const Want &want, return StartSelfUIAbilityInner(param); } +void AbilityManagerService::NotifyAttachAbilityThreadDone(sptr token, int32_t errCode) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, "NotifyAttachAbilityThreadDone called, errCode=%{public}d", errCode); + CHECK_POINTER(token); + + auto record = Token::GetAbilityRecordByToken(token); + CHECK_POINTER(record); + + if (!JudgeSelfCalled(record)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "not self call"); + return; + } + if (!record->ShouldReturnPid()) { + return; + } + auto pid = IPCSkeleton::GetCallingPid(); + TAG_LOGI(AAFwkTag::ABILITYMGR, "start from capi, pid=%{public}d", pid); + std::string bundleName = record->GetAbilityInfo().bundleName; + std::string abilityName = record->GetAbilityInfo().name; + ffrt::submit([weak = weak_from_this(), bundleName, abilityName, errCode, pid]() { + auto pThis = weak.lock(); + CHECK_POINTER(pThis); + + std::unique_lock lock(pThis->ndkStartMutex_); + auto iter = std::find_if(pThis->ndkStartRecords_.begin(), pThis->ndkStartRecords_.end(), + [bundleName, abilityName](const std::shared_ptr &record) { + return record != nullptr && record->bundleName_ == bundleName && record->abilityName_ == abilityName; + }); + if (iter == pThis->ndkStartRecords_.end()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "record with (bundle=%{public}s,abiliity=%{public}s) not exist", + bundleName.c_str(), abilityName.c_str()); + return; + } + if (*iter == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "record is nullptr"); + pThis->ndkStartRecords_.erase(iter); + return; + } + TAG_LOGI(AAFwkTag::ABILITYMGR, "attach result:%{public}d", errCode); + if (errCode == ERR_OK) { + (*iter)->pid_.store(pid); + } + (*iter)->done_.store(true); + pThis->ndkStartCv_.notify_one(); + pThis->ndkStartRecords_.erase(iter); + }, ffrt::task_attr().timeout(AbilityRuntime::GlobalConstant::DEFAULT_FFRT_TASK_TIMEOUT)); +} + +int AbilityManagerService::StartSelfUIAbilityWithPidResult(const Want &want, const StartOptions &options, + int32_t &pid) +{ + XCOLLIE_TIMER_LESS(__PRETTY_FUNCTION__); + TAG_LOGI(AAFwkTag::ABILITYMGR, "StartSelfUIAbilityWithPidResult"); + + if (options.processOptions == nullptr) { + const_cast(options).processOptions = std::make_shared(); + } + const_cast(options).processOptions->shouldReturnPid = true; + auto ret = StartSelfUIAbilityWithStartOptions(want, options); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartSelfUIAbilityWithStartOptions failed:%{public}d", ret); + return ret; + } + + std::string bundleName = want.GetElement().GetBundleName(); + std::string abilityName = want.GetElement().GetAbilityName(); + std::unique_lock lock(ndkStartMutex_); + auto iter = std::find_if(ndkStartRecords_.begin(), ndkStartRecords_.end(), + [bundleName, abilityName](const std::shared_ptr &record) { + return record != nullptr && record->bundleName_ == bundleName && record->abilityName_ == abilityName; + }); + if (iter != ndkStartRecords_.end()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "record with (bundle=%{public}s,ability=%{public}s) already exists", + bundleName.c_str(), abilityName.c_str()); + return ERR_ABILITY_ALREADY_RUNNING; + } + auto record = std::make_shared(bundleName, abilityName); + ndkStartRecords_.emplace_back(record); + auto condition = [record] { + if (record == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null record"); + return false; + } + return record->done_.load(); + }; + if (!ndkStartCv_.wait_for(lock, + std::chrono::milliseconds(GlobalConstant::ATTACH_ABILITY_THREAD_TIMEOUT_TIME), condition) || + record->pid_ < 0) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "wait attach timeout"); + iter = std::find_if(ndkStartRecords_.begin(), ndkStartRecords_.end(), [bundleName, abilityName]( + const std::shared_ptr &record) { + return record != nullptr && record->bundleName_ == bundleName && record->abilityName_ == abilityName; + }); + if (iter != ndkStartRecords_.end()) { + ndkStartRecords_.erase(iter); + } + return ERR_ATTACH_ABILITY_THREAD_FAILED; + } + pid = record->pid_.load(); + return ERR_OK; +} + bool AbilityManagerService::CheckCrossUser(const int32_t userId, AppExecFwk::ExtensionAbilityType extensionType) { if (AAFwk::UIExtensionUtils::IsEnterpriseAdmin(extensionType) || JudgeMultiUserConcurrency(userId)) { diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index e5d8a75a12e..87946d1dc71 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -903,6 +903,12 @@ int AbilityManagerStub::OnRemoteRequestInnerTwentyFirst(uint32_t code, MessagePa if (interfaceCode == AbilityManagerInterfaceCode::PRELOAD_APPLICATION) { return PreloadApplicationInner(data, reply); } + if (interfaceCode == AbilityManagerInterfaceCode::START_SELF_UI_ABILITY_WITH_PID_RESULT) { + return StartSelfUIAbilityWithPidResultInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::NOTIFY_ATTACH_ABILITY_THREAD_DONE) { + return NotifyAttachAbilityThreadDoneInner(data, reply); + } return ERR_CODE_NOT_EXIST; } @@ -1246,6 +1252,14 @@ int AbilityManagerStub::AttachAbilityThreadInner(MessageParcel &data, MessagePar return NO_ERROR; } +int AbilityManagerStub::NotifyAttachAbilityThreadDoneInner(MessageParcel &data, MessageParcel &reply) +{ + auto token = data.ReadRemoteObject(); + int32_t errCode = data.ReadInt32(); + NotifyAttachAbilityThreadDone(token, errCode); + return NO_ERROR; +} + int AbilityManagerStub::AbilityTransitionDoneInner(MessageParcel &data, MessageParcel &reply) { auto token = data.ReadRemoteObject(); @@ -4575,6 +4589,32 @@ int32_t AbilityManagerStub::StartSelfUIAbilityWithStartOptionsInner(MessageParce return NO_ERROR; } +int32_t AbilityManagerStub::StartSelfUIAbilityWithPidResultInner(MessageParcel &data, MessageParcel &reply) +{ + sptr want = data.ReadParcelable(); + if (want == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "want null"); + return ERR_READ_WANT; + } + sptr options = data.ReadParcelable(); + if (options == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "startOptions null"); + return ERR_READ_START_OPTIONS; + } + int32_t pid = -1; + int32_t result = StartSelfUIAbilityWithPidResult(*want, *options, pid); + if (!reply.WriteInt32(pid)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write StartSelfUIAbilityWithPidResult pid fail"); + return ERR_WRITE_INT_FAILED; + } + if (!reply.WriteInt32(result)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write StartSelfUIAbilityWithPidResult result fail"); + return ERR_WRITE_START_SELF_UI_ABILITY_RESULT; + } + want->CloseAllFd(); + return NO_ERROR; +} + int32_t AbilityManagerStub::PrepareTerminateAbilityDoneInner(MessageParcel &data, MessageParcel &reply) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call PrepareTerminateAbilityDoneInner"); diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 590bb0a7f23..5511ecf78fb 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -246,9 +246,11 @@ std::shared_ptr AbilityRecord::CreateAbilityRecord(const AbilityR abilityRecord->SetAppIndex(appIndex); abilityRecord->SetSecurityFlag(abilityRequest.want.GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false)); abilityRecord->SetCallerAccessTokenId(abilityRequest.callerAccessTokenId); - if (abilityRequest.processOptions != nullptr && abilityRequest.processOptions->isPreloadStart) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "start by preload"); - abilityRecord->SetPreloadStart(true); + if (abilityRequest.processOptions != nullptr) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "isPreloadStart:%{public}d,shouldReturnPid:%{public}d", + abilityRequest.processOptions->isPreloadStart, abilityRequest.processOptions->shouldReturnPid); + abilityRecord->SetPreloadStart(abilityRequest.processOptions->isPreloadStart); + abilityRecord->SetShouldReturnPid(abilityRequest.processOptions->shouldReturnPid); } abilityRecord->sessionInfo_ = abilityRequest.sessionInfo; if (AppUtils::GetInstance().IsMultiProcessModel() && abilityRequest.abilityInfo.isStageBasedModel && diff --git a/services/abilitymgr/src/process_options.cpp b/services/abilitymgr/src/process_options.cpp index f2b3780be35..f4dcd586feb 100644 --- a/services/abilitymgr/src/process_options.cpp +++ b/services/abilitymgr/src/process_options.cpp @@ -27,6 +27,7 @@ bool ProcessOptions::ReadFromParcel(Parcel &parcel) isRestartKeepAlive = parcel.ReadBool(); isStartFromNDK = parcel.ReadBool(); isPreloadStart = parcel.ReadBool(); + shouldReturnPid = parcel.ReadBool(); return true; } @@ -71,6 +72,10 @@ bool ProcessOptions::Marshalling(Parcel &parcel) const TAG_LOGE(AAFwkTag::ABILITYMGR, "isPreloadStart write failed"); return false; } + if (!parcel.WriteBool(shouldReturnPid)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "shouldReturnPid write failed"); + return false; + } return true; } 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 bc818202701..9ae98060d3c 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -203,8 +203,10 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp return ERR_OK; } - if (preloadStartCheck) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "scb call, preload start"); + bool shouldReturnPid = sessionInfo->processOptions != nullptr && sessionInfo->processOptions->shouldReturnPid; + if (preloadStartCheck || shouldReturnPid) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "scb call, preloadStartCheck=%{public}d,shouldReturnPid=%{public}d", + preloadStartCheck, shouldReturnPid); abilityRequest.processOptions = sessionInfo->processOptions; } auto isCallBySCB = sessionInfo->want.GetBoolParam(ServerConstant::IS_CALL_BY_SCB, true); diff --git a/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_test.cpp b/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_test.cpp index 97c9b3d77f9..4ee50db6632 100644 --- a/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_test.cpp +++ b/test/unittest/capi_ability_runtime_application_context_test/capi_ability_runtime_application_context_test.cpp @@ -2504,124 +2504,124 @@ HWTEST_F(CapiAbilityRuntimeApplicationContextTest, ConvertToCommonBusinessErrorC } /** - * @tc.number: ConvertToAPI18BusinessErrorCode_001 - * @tc.desc: ConvertToAPI18BusinessErrorCode + * @tc.number: ConvertToAPI17BusinessErrorCode_001 + * @tc.desc: ConvertToAPI17BusinessErrorCode * @tc.type: FUNC */ -HWTEST_F(CapiAbilityRuntimeApplicationContextTest, ConvertToAPI18BusinessErrorCode_001, TestSize.Level2) +HWTEST_F(CapiAbilityRuntimeApplicationContextTest, ConvertToAPI17BusinessErrorCode_001, TestSize.Level2) { int32_t abilityManagerError = OHOS::ERR_OK; AbilityRuntime_ErrorCode errCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; abilityManagerError = OHOS::ERR_OK; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_NO_ERROR); abilityManagerError = OHOS::AAFwk::CHECK_PERMISSION_FAILED; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_PERMISSION_DENIED); abilityManagerError = OHOS::ERR_PERMISSION_DENIED; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_PERMISSION_DENIED); abilityManagerError = OHOS::AAFwk::ERR_CAPABILITY_NOT_SUPPORT; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_NOT_SUPPORTED); abilityManagerError = OHOS::AAFwk::RESOLVE_ABILITY_ERR; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_NO_SUCH_ABILITY); abilityManagerError = OHOS::AAFwk::TARGET_BUNDLE_NOT_EXIST; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_NO_SUCH_ABILITY); abilityManagerError = OHOS::AAFwk::ERR_NOT_ALLOW_IMPLICIT_START; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_NO_SUCH_ABILITY); abilityManagerError = OHOS::AAFwk::ERR_WRONG_INTERFACE_CALL; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_INCORRECT_ABILITY_TYPE); abilityManagerError = OHOS::AAFwk::TARGET_ABILITY_NOT_SERVICE; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_INCORRECT_ABILITY_TYPE); abilityManagerError = OHOS::AAFwk::RESOLVE_CALL_ABILITY_TYPE_ERR; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_INCORRECT_ABILITY_TYPE); abilityManagerError = OHOS::AAFwk::ERR_CROWDTEST_EXPIRED; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_CROWDTEST_EXPIRED); abilityManagerError = OHOS::ERR_WOULD_BLOCK; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_WUKONG_MODE); abilityManagerError = -1; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_INTERNAL); } /** - * @tc.number: ConvertToAPI18BusinessErrorCode_002 - * @tc.desc: ConvertToAPI18BusinessErrorCode + * @tc.number: ConvertToAPI17BusinessErrorCode_002 + * @tc.desc: ConvertToAPI17BusinessErrorCode * @tc.type: FUNC */ -HWTEST_F(CapiAbilityRuntimeApplicationContextTest, ConvertToAPI18BusinessErrorCode_002, TestSize.Level2) +HWTEST_F(CapiAbilityRuntimeApplicationContextTest, ConvertToAPI17BusinessErrorCode_002, TestSize.Level2) { int32_t abilityManagerError = OHOS::ERR_OK; AbilityRuntime_ErrorCode errCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; abilityManagerError = OHOS::AAFwk::ERR_APP_CONTROLLED; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_CONTROLLED); abilityManagerError = OHOS::AAFwk::ERR_EDM_APP_CONTROLLED; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_EDM_CONTROLLED); abilityManagerError = OHOS::AAFwk::ERR_START_OTHER_APP_FAILED; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_CROSS_APP); abilityManagerError = OHOS::AAFwk::NOT_TOP_ABILITY; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_NOT_TOP_ABILITY); abilityManagerError = OHOS::AAFwk::ERR_START_OPTIONS_CHECK_FAILED; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_VISIBILITY_SETTING_DISABLED); abilityManagerError = OHOS::AAFwk::ERR_UPPER_LIMIT; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_UPPER_LIMIT_REACHED); abilityManagerError = OHOS::AAFwk::ERR_APP_INSTANCE_KEY_NOT_SUPPORT; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORTED); abilityManagerError = OHOS::AAFwk::ERR_NOT_SELF_APPLICATION; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_CROSS_APP); abilityManagerError = OHOS::AAFwk::ERR_MULTI_APP_NOT_SUPPORTED; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_MULTI_APP_NOT_SUPPORTED); abilityManagerError = OHOS::AAFwk::ERR_INVALID_APP_INSTANCE_KEY; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_INVALID_APP_INSTANCE_KEY); abilityManagerError = OHOS::AAFwk::ERR_MULTI_INSTANCE_NOT_SUPPORTED; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_MULTI_INSTANCE_NOT_SUPPORTED); abilityManagerError = -1; - errCode = ConvertToAPI18BusinessErrorCode(abilityManagerError); + errCode = ConvertToAPI17BusinessErrorCode(abilityManagerError); EXPECT_EQ(errCode, ABILITY_RUNTIME_ERROR_CODE_INTERNAL); } } // namespace OHOS::AbilityRuntime diff --git a/utils/global/constant/global_constant.h b/utils/global/constant/global_constant.h index 0d4255baaf8..0e0920e654a 100644 --- a/utils/global/constant/global_constant.h +++ b/utils/global/constant/global_constant.h @@ -24,6 +24,7 @@ constexpr int32_t TIMEOUT_UNIT_TIME = 1000; constexpr int32_t TIMEOUT_UNIT_TIME_MICRO = 1000 * 1000; constexpr int32_t PREPARE_TERMINATE_TIMEOUT_TIME = 10000; +constexpr int32_t ATTACH_ABILITY_THREAD_TIMEOUT_TIME = 100 * 1000; // attach ability thread timeout, 100s constexpr int32_t DEFAULT_FFRT_TASK_TIMEOUT = 60 * 1000 * 1000; // 60s = 60 000 000us constexpr int32_t FFRT_TASK_TIMEOUT = 5 * 1000 * 1000; // 5s constexpr const char* LOW_MEMORY_KILL = "LowMemoryKill"; -- Gitee From 4d033b9f463852512f5adca3c864965be82ee0b3 Mon Sep 17 00:00:00 2001 From: Nathan Yang Date: Tue, 12 Aug 2025 19:22:33 +0800 Subject: [PATCH 2/2] fix: main thread block Signed-off-by: Nathan Yang --- .../include/ability_manager_client.h | 3 +- .../include/ability_manager_interface.h | 3 +- .../include/appmgr/ams_mgr_interface.h | 5 +- .../include/appmgr/ams_mgr_proxy.h | 5 +- .../include/appmgr/app_mgr_client.h | 3 +- .../app_manager/src/appmgr/ams_mgr_proxy.cpp | 7 +- .../app_manager/src/appmgr/ams_mgr_stub.cpp | 4 +- .../app_manager/src/appmgr/app_mgr_client.cpp | 4 +- .../include/ability_manager_proxy.h | 3 +- .../include/ability_manager_service.h | 3 +- services/abilitymgr/include/app_scheduler.h | 5 +- .../src/ability_connect_manager.cpp | 11 +-- .../abilitymgr/src/ability_manager_client.cpp | 4 +- .../abilitymgr/src/ability_manager_proxy.cpp | 7 +- .../src/ability_manager_service.cpp | 59 ++++++++------- .../abilitymgr/src/ability_manager_stub.cpp | 3 +- services/abilitymgr/src/ability_record.cpp | 6 +- services/abilitymgr/src/app_scheduler.cpp | 4 +- services/appmgr/include/ams_mgr_scheduler.h | 5 +- .../appmgr/include/app_mgr_service_inner.h | 3 +- services/appmgr/src/ams_mgr_scheduler.cpp | 6 +- services/appmgr/src/app_mgr_service_inner.cpp | 3 +- .../amsmgrscheduler_fuzzer.cpp | 3 +- .../loadability_fuzzer/loadability_fuzzer.cpp | 3 +- .../include/mock_app_mgr_client.h | 2 +- .../src/appmgr/mock_app_scheduler.cpp | 2 +- .../ams_app_life_cycle_module_test.cpp | 6 +- .../mock/src/mock_ability_record.cpp | 3 +- .../mock/src/mock_ability_record.cpp | 3 +- .../mock/src/mock_app_scheduler.cpp | 2 +- .../ams_app_death_recipient_test.cpp | 3 +- .../ams_app_mgr_client_test.cpp | 8 ++- .../ams_app_running_record_test.cpp | 6 +- .../ams_mgr_scheduler_second_test.cpp | 18 +++-- .../ams_mgr_scheduler_test.cpp | 26 ++++--- .../ams_service_load_ability_process_test.cpp | 72 ++++++++++++------- .../mock/src/mock_app_scheduler.cpp | 2 +- .../app_mgr_service_inner_test.cpp | 7 +- .../app_running_processes_info_test.cpp | 3 +- .../app_scheduler_test/app_scheduler_test.cpp | 9 ++- 40 files changed, 204 insertions(+), 130 deletions(-) diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index e2fe27b0fe5..c5377114748 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -88,8 +88,9 @@ public: * * @param token, ability's token. * @param errCode, the error code of AttachAbilityThread. + * @param pid, the process id. */ - void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode); + void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode, int32_t pid = -1); /** * AbilityTransitionDone, ability call this interface after lift cycle was changed. diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 17103165d84..3a50a6cda2b 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -783,8 +783,9 @@ public: * * @param token, ability's token. * @param errCode, the error code of AttachAbilityThread. + * @param pid, the process id. */ - virtual void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode) + virtual void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode, int32_t pid = -1) {} /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h index f262db3cdb6..e816ee363b9 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h @@ -45,11 +45,12 @@ public: * @param preToken, the unique identification to call the ability. * @param abilityInfo, the ability information. * @param appInfo, the app information. + * @param pid, the return process id. * @return */ virtual void LoadAbility(const std::shared_ptr &abilityInfo, - const std::shared_ptr &appInfo, - const std::shared_ptr &want, std::shared_ptr loadParam) {}; + const std::shared_ptr &appInfo, const std::shared_ptr &want, + std::shared_ptr loadParam, int32_t &pid) {}; /** * TerminateAbility, call TerminateAbility() through the proxy object, terminate the token ability. diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h index 432c6fdb494..bc999bdd56a 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h @@ -34,11 +34,12 @@ public: * @param preToken, the unique identification to call the ability. * @param abilityInfo, the ability information. * @param appInfo, the app information. + * @param pid, the return process id. * @return */ virtual void LoadAbility(const std::shared_ptr &abilityInfo, - const std::shared_ptr &appInfo, - const std::shared_ptr &want, std::shared_ptr loadParam) override; + const std::shared_ptr &appInfo, const std::shared_ptr &want, + std::shared_ptr loadParam, int32_t &pid) override; /** * TerminateAbility, call TerminateAbility() through the proxy object, terminate the token ability. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index 89149bd4b8d..57712cd6e3b 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -62,10 +62,11 @@ public: * @param appInfo Application information. * @param want Want. * @param loadParam load ability param. + * @param pid, the return process id. * @return Returns RESULT_OK on success, others on failure. */ virtual AppMgrResultCode LoadAbility(const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, - const AAFwk::Want &want, AbilityRuntime::LoadParam loadParam); + const AAFwk::Want &want, AbilityRuntime::LoadParam loadParam, int32_t &pid); /** * Terminate ability. diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp index efeb449774e..4d0d6e9064d 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -67,10 +67,10 @@ bool AmsMgrProxy::WriteInterfaceToken(MessageParcel &data) } void AmsMgrProxy::LoadAbility(const std::shared_ptr &abilityInfo, - const std::shared_ptr &appInfo, - const std::shared_ptr &want, std::shared_ptr loadParam) + const std::shared_ptr &appInfo, const std::shared_ptr &want, + std::shared_ptr loadParam, int32_t &pid) { - TAG_LOGD(AAFwkTag::APPMGR, "start"); + TAG_LOGD(AAFwkTag::APPMGR, "start LoadAbility"); if (!abilityInfo || !appInfo) { TAG_LOGE(AAFwkTag::APPMGR, "param error"); return; @@ -105,6 +105,7 @@ void AmsMgrProxy::LoadAbility(const std::shared_ptr &abilityInfo, AbilityRuntime::FreezeUtil::GetInstance().AddLifecycleEvent(loadParam->token, "AmsMgrProxy::LoadAbility fail, ipc error " + std::to_string(ret)); } + pid = reply.ReadInt32(); TAG_LOGD(AAFwkTag::APPMGR, "end"); } diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp index 40aa1fc3bec..5ea4cba4f4b 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -265,7 +265,9 @@ ErrCode AmsMgrStub::HandleLoadAbility(MessageParcel &data, MessageParcel &reply) return ERR_APPEXECFWK_PARCEL_ERROR; } - LoadAbility(abilityInfo, appInfo, want, loadParam); + int32_t pid = -1; + LoadAbility(abilityInfo, appInfo, want, loadParam, pid); + reply.WriteInt32(pid); return NO_ERROR; } diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index e27824f685c..5f3bb16cada 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -160,7 +160,7 @@ AppMgrClient::~AppMgrClient() {} AppMgrResultCode AppMgrClient::LoadAbility(const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, - const AAFwk::Want &want, AbilityRuntime::LoadParam loadParam) + const AAFwk::Want &want, AbilityRuntime::LoadParam loadParam, int32_t &pid) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); if (service != nullptr) { @@ -171,7 +171,7 @@ AppMgrResultCode AppMgrClient::LoadAbility(const AbilityInfo &abilityInfo, const std::shared_ptr appInfoPtr = std::make_shared(appInfo); std::shared_ptr wantPtr = std::make_shared(want); auto loadParamPtr = std::make_shared(loadParam); - amsService->LoadAbility(abilityInfoPtr, appInfoPtr, wantPtr, loadParamPtr); + amsService->LoadAbility(abilityInfoPtr, appInfoPtr, wantPtr, loadParamPtr, pid); return AppMgrResultCode::RESULT_OK; } } diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index d75ff7cb4e6..bdc3df4bcae 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -559,8 +559,9 @@ public: * * @param token, ability's token. * @param errCode, the error code of AttachAbilityThread. + * @param pid, the process id. */ - virtual void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode) override; + virtual void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode, int32_t pid = -1) override; /** * AbilityTransitionDone, ability call this interface after lift cycle was changed. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 08abb7db6bd..cd726c46033 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -811,8 +811,9 @@ public: * * @param token, ability's token. * @param errCode, the error code of AttachAbilityThread. + * @param pid, the process id. */ - virtual void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode) override; + virtual void NotifyAttachAbilityThreadDone(sptr token, int32_t errCode, int32_t pid = -1) override; /** * AbilityTransitionDone, ability call this interface after lift cycle was changed. diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index d8722122d0b..49d408b3f21 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -158,11 +158,12 @@ public: * @param loadParam, the loadParam of ability. * @param abilityInfo, ability info. * @param applicationInfo, application info. - * @param want ability want + * @param want ability want. + * @param pid, the return process id. * @return true on success ,false on failure. */ int LoadAbility(const AbilityRuntime::LoadParam &loadParam, const AppExecFwk::AbilityInfo &abilityInfo, - const AppExecFwk::ApplicationInfo &applicationInfo, const Want &want); + const AppExecFwk::ApplicationInfo &applicationInfo, const Want &want, int32_t &pid); /** * terminate ability with token. diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 6085e0b6c20..2a6d6c61027 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -1657,8 +1657,9 @@ void AbilityConnectManager::HandleLoadAbilityOrStartSpecifiedProcess( StartSpecifiedProcess(context, abilityRecord); } else { TAG_LOGD(AAFwkTag::EXT, "LoadAbility"); - DelayedSingleton::GetInstance()->LoadAbility( - loadParam, abilityRecord->GetAbilityInfo(), abilityRecord->GetApplicationInfo(), abilityRecord->GetWant()); + int32_t pid = -1; + DelayedSingleton::GetInstance()->LoadAbility(loadParam, abilityRecord->GetAbilityInfo(), + abilityRecord->GetApplicationInfo(), abilityRecord->GetWant(), pid); } } @@ -1687,8 +1688,9 @@ void AbilityConnectManager::OnStartSpecifiedProcessResponse(const std::string &f TAG_LOGD(AAFwkTag::ABILITYMGR, "OnStartSpecifiedProcessResponse LoadAbility"); auto &front = loadAbilityQueue_.front(); front[requestId].want->SetParam(PARAM_SPECIFIED_PROCESS_FLAG, flag); + int32_t pid = -1; DelayedSingleton::GetInstance()->LoadAbility(*front[requestId].loadParam, - *(front[requestId].abilityInfo), *(front[requestId].appInfo), *(front[requestId].want)); + *(front[requestId].abilityInfo), *(front[requestId].appInfo), *(front[requestId].want), pid); loadAbilityQueue_.pop_front(); } } @@ -1700,8 +1702,9 @@ void AbilityConnectManager::OnStartSpecifiedProcessTimeoutResponse(int32_t reque if (!loadAbilityQueue_.empty()) { auto &front = loadAbilityQueue_.front(); + int32_t pid = -1; DelayedSingleton::GetInstance()->LoadAbility(*(front[requestId].loadParam), - *(front[requestId].abilityInfo), *(front[requestId].appInfo), *(front[requestId].want)); + *(front[requestId].abilityInfo), *(front[requestId].appInfo), *(front[requestId].want), pid); loadAbilityQueue_.pop_front(); } } diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 0f9a881e082..9deed5401cb 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -92,11 +92,11 @@ ErrCode AbilityManagerClient::AttachAbilityThread( } void AbilityManagerClient::NotifyAttachAbilityThreadDone( - sptr token, int32_t errCode) + sptr token, int32_t errCode, int32_t pid) { auto abms = GetAbilityManager(); CHECK_POINTER_RETURN(abms); - abms->NotifyAttachAbilityThreadDone(token, errCode); + abms->NotifyAttachAbilityThreadDone(token, errCode, pid); } ErrCode AbilityManagerClient::AbilityTransitionDone(sptr token, int state, const PacMap &saveData) diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 12857ae3fe0..95dccffa61e 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -1560,7 +1560,8 @@ int AbilityManagerProxy::AttachAbilityThread(const sptr &sche return reply.ReadInt32(); } -void AbilityManagerProxy::NotifyAttachAbilityThreadDone(sptr token, int32_t errCode) +void AbilityManagerProxy::NotifyAttachAbilityThreadDone(sptr token, int32_t errCode, + int32_t pid) { int error; MessageParcel data; @@ -1577,6 +1578,10 @@ void AbilityManagerProxy::NotifyAttachAbilityThreadDone(sptr toke TAG_LOGE(AAFwkTag::ABILITYMGR, "write errCode fail"); return; } + if (!data.WriteInt32(pid)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write pid fail"); + return; + } error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_ATTACH_ABILITY_THREAD_DONE, data, reply, option); if (error != NO_ERROR) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 5a9a18bcb3c..24c88c6aca5 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -14586,7 +14586,8 @@ int AbilityManagerService::StartSelfUIAbilityWithStartOptions(const Want &want, return StartSelfUIAbilityInner(param); } -void AbilityManagerService::NotifyAttachAbilityThreadDone(sptr token, int32_t errCode) +void AbilityManagerService::NotifyAttachAbilityThreadDone(sptr token, int32_t errCode, + int32_t pid) { TAG_LOGI(AAFwkTag::ABILITYMGR, "NotifyAttachAbilityThreadDone called, errCode=%{public}d", errCode); CHECK_POINTER(token); @@ -14594,44 +14595,40 @@ void AbilityManagerService::NotifyAttachAbilityThreadDone(sptr to auto record = Token::GetAbilityRecordByToken(token); CHECK_POINTER(record); - if (!JudgeSelfCalled(record)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "not self call"); + if (!JudgeSelfCalled(record) && + !PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS_NAME)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "not self call or foundation call"); return; } if (!record->ShouldReturnPid()) { return; } - auto pid = IPCSkeleton::GetCallingPid(); + pid = pid < 0 ? IPCSkeleton::GetCallingPid() : pid; TAG_LOGI(AAFwkTag::ABILITYMGR, "start from capi, pid=%{public}d", pid); std::string bundleName = record->GetAbilityInfo().bundleName; std::string abilityName = record->GetAbilityInfo().name; - ffrt::submit([weak = weak_from_this(), bundleName, abilityName, errCode, pid]() { - auto pThis = weak.lock(); - CHECK_POINTER(pThis); - - std::unique_lock lock(pThis->ndkStartMutex_); - auto iter = std::find_if(pThis->ndkStartRecords_.begin(), pThis->ndkStartRecords_.end(), - [bundleName, abilityName](const std::shared_ptr &record) { - return record != nullptr && record->bundleName_ == bundleName && record->abilityName_ == abilityName; - }); - if (iter == pThis->ndkStartRecords_.end()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "record with (bundle=%{public}s,abiliity=%{public}s) not exist", - bundleName.c_str(), abilityName.c_str()); - return; - } - if (*iter == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "record is nullptr"); - pThis->ndkStartRecords_.erase(iter); - return; - } - TAG_LOGI(AAFwkTag::ABILITYMGR, "attach result:%{public}d", errCode); - if (errCode == ERR_OK) { - (*iter)->pid_.store(pid); - } - (*iter)->done_.store(true); - pThis->ndkStartCv_.notify_one(); - pThis->ndkStartRecords_.erase(iter); - }, ffrt::task_attr().timeout(AbilityRuntime::GlobalConstant::DEFAULT_FFRT_TASK_TIMEOUT)); + std::unique_lock lock(ndkStartMutex_); + auto iter = std::find_if(ndkStartRecords_.begin(), ndkStartRecords_.end(), + [bundleName, abilityName](const std::shared_ptr &record) { + return record != nullptr && record->bundleName_ == bundleName && record->abilityName_ == abilityName; + }); + if (iter == ndkStartRecords_.end()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "record with (bundle=%{public}s,abiliity=%{public}s) not exist", + bundleName.c_str(), abilityName.c_str()); + return; + } + if (*iter == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "record is nullptr"); + ndkStartRecords_.erase(iter); + return; + } + TAG_LOGI(AAFwkTag::ABILITYMGR, "attach result:%{public}d,pid=%{public}d", errCode, pid); + if (errCode == ERR_OK) { + (*iter)->pid_.store(pid); + } + (*iter)->done_.store(true); + ndkStartCv_.notify_one(); + ndkStartRecords_.erase(iter); } int AbilityManagerService::StartSelfUIAbilityWithPidResult(const Want &want, const StartOptions &options, diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 87946d1dc71..f812c32fb36 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -1256,7 +1256,8 @@ int AbilityManagerStub::NotifyAttachAbilityThreadDoneInner(MessageParcel &data, { auto token = data.ReadRemoteObject(); int32_t errCode = data.ReadInt32(); - NotifyAttachAbilityThreadDone(token, errCode); + int32_t pid = data.ReadInt32(); + NotifyAttachAbilityThreadDone(token, errCode, pid); return NO_ERROR; } diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 5511ecf78fb..57b4f60e0bd 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -383,8 +383,12 @@ int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide) MainElementUtils::IsMainUIAbility(abilityInfo_.bundleName, abilityInfo_.name, userId); MainElementUtils::SetMainUIAbilityKeepAliveFlag(isMainUIAbility, abilityInfo_.bundleName, loadParam); + int32_t pid = -1; auto result = DelayedSingleton::GetInstance()->LoadAbility( - loadParam, abilityInfo_, abilityInfo_.applicationInfo, want_); + loadParam, abilityInfo_, abilityInfo_.applicationInfo, want_, pid); + IN_PROCESS_CALL( + DelayedSingleton::GetInstance()->NotifyAttachAbilityThreadDone( + GetToken(), result, pid)); want_.RemoveParam(IS_HOOK); want_.RemoveParam(ABILITY_OWNER_USERID); want_.RemoveParam(Want::PARAMS_REAL_CALLER_KEY); diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 201fbe30f21..02888736d13 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -68,7 +68,7 @@ bool AppScheduler::Init(const std::weak_ptr &callback) } int AppScheduler::LoadAbility(const AbilityRuntime::LoadParam &loadParam, const AppExecFwk::AbilityInfo &abilityInfo, - const AppExecFwk::ApplicationInfo &applicationInfo, const Want &want) + const AppExecFwk::ApplicationInfo &applicationInfo, const Want &want, int32_t &pid) { if (AppUtils::GetInstance().IsForbidStart()) { TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", abilityInfo.bundleName.c_str()); @@ -80,7 +80,7 @@ int AppScheduler::LoadAbility(const AbilityRuntime::LoadParam &loadParam, const /* 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_->LoadAbility(abilityInfo, applicationInfo, want, loadParam))); + appMgrClient_->LoadAbility(abilityInfo, applicationInfo, want, loadParam, pid))); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::SERVICE_EXT, "AppScheduler fail to LoadAbility. ret %{public}d", ret); return INNER_ERR; diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index c25df4d8e00..3729da28a7d 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -49,10 +49,11 @@ public: * @param abilityInfo, the ability information. * @param appInfo, the app information. * @param want, the starting information. + * @param pid, the return process id. */ virtual void LoadAbility(const std::shared_ptr &abilityInfo, - const std::shared_ptr &appInfo, - const std::shared_ptr &want, std::shared_ptr loadParam) override; + const std::shared_ptr &appInfo, const std::shared_ptr &want, + std::shared_ptr loadParam, int32_t &pid) override; /** * TerminateAbility, call TerminateAbility() through the proxy object, terminate the token ability. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 3753aa74533..33433e49b09 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -127,11 +127,12 @@ public: * @param abilityInfo, the ability information. * @param appInfo, the app information. * @param want the ability want. + * @param pid, the return process id. * * @return */ virtual void LoadAbility(std::shared_ptr abilityInfo, std::shared_ptr appInfo, - std::shared_ptr want, std::shared_ptr loadParam); + std::shared_ptr want, std::shared_ptr loadParam, int32_t &targetPid); /** * TerminateAbility, terminate the token ability. diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index c2c35f0cc44..e200775f4ed 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -67,8 +67,8 @@ AmsMgrScheduler::~AmsMgrScheduler() } void AmsMgrScheduler::LoadAbility(const std::shared_ptr &abilityInfo, - const std::shared_ptr &appInfo, - const std::shared_ptr &want, std::shared_ptr loadParam) + const std::shared_ptr &appInfo, const std::shared_ptr &want, + std::shared_ptr loadParam, int32_t &pid) { if (!abilityInfo || !appInfo) { TAG_LOGE(AAFwkTag::APPMGR, "param error"); @@ -88,7 +88,7 @@ void AmsMgrScheduler::LoadAbility(const std::shared_ptr &abilityInf abilityInfo->name.c_str()); std::function loadAbilityFunc = [amsMgrServiceInner = amsMgrServiceInner_, abilityInfo, appInfo, want, loadParam]() { - amsMgrServiceInner->LoadAbility(abilityInfo, appInfo, want, loadParam); + amsMgrServiceInner->LoadAbility(abilityInfo, appInfo, want, loadParam, pid); }; // cache other application load ability task before scene board attach diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index c5695bf6184..527842ec63c 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -866,7 +866,7 @@ void AppMgrServiceInner::ReportEventToRSS(const AppExecFwk::AbilityInfo &ability } void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, std::shared_ptr appInfo, - std::shared_ptr want, std::shared_ptr loadParam) + std::shared_ptr want, std::shared_ptr loadParam, int32_t &targetPid) { if (AAFwk::AppUtils::GetInstance().IsForbidStart()) { TAG_LOGW(AAFwkTag::APPMGR, "forbid start: %{public}s", abilityInfo ? abilityInfo->bundleName.c_str() : ""); @@ -1049,6 +1049,7 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s want->RemoveParam(UIEXTENSION_BIND_ABILITY_ID); } AfterLoadAbility(appRecord, abilityInfo, loadParam); + targetPid = appRecord && appRecord->GetPriorityObject() ? appRecord->GetPriorityObject()->GetPid() : -1; } void AppMgrServiceInner::AfterLoadAbility(std::shared_ptr appRecord, diff --git a/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp b/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp index ed18c7d9e7a..cedebd6d4d7 100755 --- a/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp +++ b/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp @@ -78,7 +78,8 @@ std::shared_ptr DoSomethingInterestingWithMyAPI1(sptr(loadParam); - amsMgrScheduler->LoadAbility(abilityInfoptr, appInfo, wantptr, loadParamPtr); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfoptr, appInfo, wantptr, loadParamPtr, pid); bool clearMissionFlag = *data % ENABLE; amsMgrScheduler->TerminateAbility(token, clearMissionFlag); return amsMgrScheduler; diff --git a/test/fuzztest/loadability_fuzzer/loadability_fuzzer.cpp b/test/fuzztest/loadability_fuzzer/loadability_fuzzer.cpp index 6118e9562b4..129a79cbbda 100755 --- a/test/fuzztest/loadability_fuzzer/loadability_fuzzer.cpp +++ b/test/fuzztest/loadability_fuzzer/loadability_fuzzer.cpp @@ -92,7 +92,8 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) if (wantParcel.WriteBuffer(data, size)) { want = Want::Unmarshalling(wantParcel); if (want) { - appMgrClient->LoadAbility(abilityInfo, appInfo, *want, loadParam); + int32_t pid = -1; + appMgrClient->LoadAbility(abilityInfo, appInfo, *want, loadParam, pid); } } diff --git a/test/mock/services_abilitymgr_test/include/mock_app_mgr_client.h b/test/mock/services_abilitymgr_test/include/mock_app_mgr_client.h index 241c47ba8b1..4896ba2ad22 100644 --- a/test/mock/services_abilitymgr_test/include/mock_app_mgr_client.h +++ b/test/mock/services_abilitymgr_test/include/mock_app_mgr_client.h @@ -30,7 +30,7 @@ public: virtual ~MockAppMgrClient() {}; virtual AppMgrResultCode LoadAbility(const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, - const AAFwk::Want &want, AbilityRuntime::LoadParam loadParam) + const AAFwk::Want &want, AbilityRuntime::LoadParam loadParam, int32_t &pid) { TAG_LOGI(AAFwkTag::TEST, "MockAppMgrClient LoadAbility enter."); token_ = loadParam.token; diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp index 22b55ad7549..8fcc553fd0a 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp @@ -42,7 +42,7 @@ bool AppScheduler::Init(const std::weak_ptr& callback) } int AppScheduler::LoadAbility(const AbilityRuntime::LoadParam &loadParam, const AppExecFwk::AbilityInfo& abilityInfo, - const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want) + const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want, int32_t &pid) { TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::LoadAbility()"); if (applicationInfo.bundleName.find("com.ix.First.Test") != std::string::npos) { diff --git a/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp b/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp index 6db73504f55..b576d6d6985 100644 --- a/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp +++ b/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp @@ -181,7 +181,8 @@ std::shared_ptr AmsAppLifeCycleModuleTest::StartProcessAndLoad AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - serviceInner_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + serviceInner_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; EXPECT_TRUE(serviceInner_->GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo)); @@ -360,7 +361,8 @@ void AmsAppLifeCycleModuleTest::CreateAppRecentList(const int32_t appNum) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - serviceInner_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + serviceInner_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); } return; } 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 9f259563bff..bb462c29b1e 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 @@ -336,8 +336,9 @@ int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide) want_.SetParam(Want::PARAM_APP_KEEP_ALIVE_ENABLED, true); loadParam.isKeepAlive = true; } + int32_t pid = -1; auto result = DelayedSingleton::GetInstance()->LoadAbility( - loadParam, abilityInfo_, abilityInfo_.applicationInfo, want_); + loadParam, abilityInfo_, abilityInfo_.applicationInfo, want_, pid); want_.RemoveParam(IS_HOOK); want_.RemoveParam(ABILITY_OWNER_USERID); want_.RemoveParam(Want::PARAMS_REAL_CALLER_KEY); 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 dc03e69042a..2e01e1a10ea 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 @@ -348,8 +348,9 @@ int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide) want_.SetParam(Want::PARAM_APP_KEEP_ALIVE_ENABLED, true); loadParam.isKeepAlive = true; } + int32_t pid = -1; auto result = DelayedSingleton::GetInstance()->LoadAbility( - loadParam, abilityInfo_, abilityInfo_.applicationInfo, want_); + loadParam, abilityInfo_, abilityInfo_.applicationInfo, want_, pid); want_.RemoveParam(IS_HOOK); want_.RemoveParam(ABILITY_OWNER_USERID); want_.RemoveParam(Want::PARAMS_REAL_CALLER_KEY); diff --git a/test/unittest/ability_permission_util_second_test/mock/src/mock_app_scheduler.cpp b/test/unittest/ability_permission_util_second_test/mock/src/mock_app_scheduler.cpp index 2357e05e606..359a50f0202 100644 --- a/test/unittest/ability_permission_util_second_test/mock/src/mock_app_scheduler.cpp +++ b/test/unittest/ability_permission_util_second_test/mock/src/mock_app_scheduler.cpp @@ -42,7 +42,7 @@ bool AppScheduler::Init(const std::weak_ptr& callback) } int AppScheduler::LoadAbility(const AbilityRuntime::LoadParam& loadParam, const AppExecFwk::AbilityInfo& abilityInfo, - const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want) + const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want, int32_t &pid) { TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::LoadAbility()"); if (applicationInfo.bundleName.find("com.ix.First.Test") != std::string::npos) { diff --git a/test/unittest/ams_app_death_recipient_test/ams_app_death_recipient_test.cpp b/test/unittest/ams_app_death_recipient_test/ams_app_death_recipient_test.cpp index fb3f597cd7e..25c50f7e015 100644 --- a/test/unittest/ams_app_death_recipient_test/ams_app_death_recipient_test.cpp +++ b/test/unittest/ams_app_death_recipient_test/ams_app_death_recipient_test.cpp @@ -176,7 +176,8 @@ sptr AppDeathRecipientTest::GetApp(int32_t pid, int size) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - appMgrServiceInner_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + appMgrServiceInner_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); auto appRecord = GetAppRunningRecordByIndex(pid); diff --git a/test/unittest/ams_app_mgr_client_test/ams_app_mgr_client_test.cpp b/test/unittest/ams_app_mgr_client_test/ams_app_mgr_client_test.cpp index a60326fea58..c9164482402 100644 --- a/test/unittest/ams_app_mgr_client_test/ams_app_mgr_client_test.cpp +++ b/test/unittest/ams_app_mgr_client_test/ams_app_mgr_client_test.cpp @@ -122,7 +122,7 @@ HWTEST_F(AmsAppMgrClientTest, AppMgrClient_001, TestSize.Level1) sptr amsMgrScheduler(new MockAmsMgrScheduler()); EXPECT_CALL(*(static_cast(amsMgrScheduler.GetRefPtr())), - LoadAbility(_, _, _, _)).Times(1); + LoadAbility(_, _, _, _, _)).Times(1); EXPECT_CALL(*(static_cast((iface_cast(client_->GetRemoteObject())).GetRefPtr())), GetAmsMgr()) @@ -131,7 +131,8 @@ HWTEST_F(AmsAppMgrClientTest, AppMgrClient_001, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token_; loadParam.preToken = preToken_; - EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->LoadAbility(abilityInfo, appInfo, want, loadParam)); + int32_t pid = -1; + EXPECT_EQ(AppMgrResultCode::RESULT_OK, client_->LoadAbility(abilityInfo, appInfo, want, loadParam, pid)); TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_001 end"); } @@ -152,8 +153,9 @@ HWTEST_F(AmsAppMgrClientTest, AppMgrClient_002, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token_; loadParam.preToken = preToken_; + int32_t pid = -1; EXPECT_EQ( - AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED, client_->LoadAbility(abilityInfo, appInfo, want, loadParam)); + AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED, client_->LoadAbility(abilityInfo, appInfo, want, loadParam, pid)); TAG_LOGI(AAFwkTag::TEST, "ams_app_mgr_client_test_002 end"); } diff --git a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp index 48f591a7daa..05ad98942dd 100644 --- a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp +++ b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp @@ -185,7 +185,8 @@ std::shared_ptr AmsAppRunningRecordTest::StartLoadAbility(cons AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -1121,7 +1122,8 @@ HWTEST_F(AmsAppRunningRecordTest, LaunchAbilityForApp_004, TestSize.Level1) EXPECT_CALL(*mockAppSchedulerClient_, ScheduleLaunchApplication(_, _)).Times(0); loadParam->token = new (std::nothrow) MockAbilityToken(); - service_->LoadAbility(abilityInfo2, appInfo, nullptr, loadParam); + int32_t pid = -1; + service_->LoadAbility(abilityInfo2, appInfo, nullptr, loadParam, pid); TAG_LOGI(AAFwkTag::TEST, "AmsAppRunningRecordTest LaunchAbilityForApp_004 end"); } diff --git a/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp b/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp index c7a43830ebf..2e72b126544 100644 --- a/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp +++ b/test/unittest/ams_mgr_scheduler_second_test/ams_mgr_scheduler_second_test.cpp @@ -101,7 +101,8 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_LoadAbility_001, T * @tc.steps: step2. LoadAbility with null abilityInfo * @tc.expected: step2. expect GetSceneBoardAttachFlag true */ - amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam, pid); EXPECT_TRUE(appMgrServiceInner_->GetSceneBoardAttachFlag()); // not changed } @@ -127,7 +128,8 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_LoadAbility_002, T * @tc.steps: step2. LoadAbility with null appInfo * @tc.expected: step2. expect GetSceneBoardAttachFlag true */ - amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam, pid); EXPECT_TRUE(appMgrServiceInner_->GetSceneBoardAttachFlag()); // not changed } @@ -154,7 +156,8 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_LoadAbility_003, T * @tc.expected: step2. expect GetSceneBoardAttachFlag true */ IPCSkeleton::SetCallingUid(-1); - amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam, pid); EXPECT_TRUE(appMgrServiceInner_->GetSceneBoardAttachFlag()); } @@ -181,7 +184,8 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_LoadAbility_004, T * @tc.expected: step2. expect taskhandler executed at least one time */ IPCSkeleton::SetCallingUid(Constants::FOUNDATION_UID); - amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam, pid); EXPECT_TRUE(appMgrServiceInner_->GetSceneBoardAttachFlag()); } @@ -211,7 +215,8 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_LoadAbility_005, T * @tc.expected: step2. expect appMgrServiceInner_ GetSceneBoardAttachFlag false */ IPCSkeleton::SetCallingUid(Constants::FOUNDATION_UID); - amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam, pid); EXPECT_FALSE(appMgrServiceInner_->GetSceneBoardAttachFlag()); // false } @@ -241,7 +246,8 @@ HWTEST_F(AmsMgrSchedulerSecondTest, AmsMgrSchedulerSecondTest_LoadAbility_006, T * @tc.expected: step2. expect appMgrServiceInner_ GetSceneBoardAttachFlag true */ IPCSkeleton::SetCallingUid(Constants::FOUNDATION_UID); - amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParam, pid); EXPECT_TRUE(appMgrServiceInner_->GetSceneBoardAttachFlag()); } diff --git a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp index 7878a257134..312ccfac17d 100644 --- a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp +++ b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp @@ -114,13 +114,14 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_001, TestSize.Level1) std::shared_ptr applicationInfo = std::make_shared(); applicationInfo->name = GetTestAppName(); - EXPECT_CALL(*mockAppMgrServiceInner, LoadAbility(_, _, _, _)) + EXPECT_CALL(*mockAppMgrServiceInner, LoadAbility(_, _, _, _, _)) .WillOnce(InvokeWithoutArgs(mockAppMgrServiceInner.get(), &MockAppMgrServiceInner::Post)); AbilityRuntime::LoadParam loadParam; loadParam.token = new MockAbilityToken(); loadParam.preToken = new MockAbilityToken(); auto loadParamPtr = std::make_shared(loadParam); - amsMgrScheduler->LoadAbility(abilityInfo, applicationInfo, nullptr, loadParamPtr); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, applicationInfo, nullptr, loadParamPtr, pid); mockAppMgrServiceInner->Wait(); TAG_LOGD(AAFwkTag::TEST, "AmsMgrScheduler_001 end."); @@ -150,16 +151,17 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_002, TestSize.Level1) applicationInfo->name = GetTestAppName(); // check token parameter - EXPECT_CALL(*mockAppMgrServiceInner, LoadAbility(_, _, _, _)).Times(0); + EXPECT_CALL(*mockAppMgrServiceInner, LoadAbility(_, _, _, _, _)).Times(0); AbilityRuntime::LoadParam loadParam; loadParam.token = new MockAbilityToken(); loadParam.preToken = new MockAbilityToken(); auto loadParamPtr = std::make_shared(loadParam); - amsMgrScheduler->LoadAbility(nullptr, applicationInfo, nullptr, loadParamPtr); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(nullptr, applicationInfo, nullptr, loadParamPtr, pid); // check pretoken parameter - EXPECT_CALL(*mockAppMgrServiceInner, LoadAbility(_, _, _, _)).Times(0); - amsMgrScheduler->LoadAbility(abilityInfo, nullptr, nullptr, loadParamPtr); + EXPECT_CALL(*mockAppMgrServiceInner, LoadAbility(_, _, _, _, _)).Times(0); + amsMgrScheduler->LoadAbility(abilityInfo, nullptr, nullptr, loadParamPtr, pid); TAG_LOGD(AAFwkTag::TEST, "AmsMgrScheduler_002 end."); } @@ -377,7 +379,8 @@ HWTEST_F(AmsMgrSchedulerTest, LoadAbility_001, TestSize.Level0) loadParam.token = token; loadParam.preToken = preToken; auto loadParamPtr = std::make_shared(loadParam); - amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParamPtr); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParamPtr, pid); } /* @@ -401,7 +404,8 @@ HWTEST_F(AmsMgrSchedulerTest, LoadAbility_002, TestSize.Level0) loadParam.token = token; loadParam.preToken = preToken; auto loadParamPtr = std::make_shared(loadParam); - amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParamPtr); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParamPtr, pid); } /* @@ -425,7 +429,8 @@ HWTEST_F(AmsMgrSchedulerTest, LoadAbility_003, TestSize.Level0) loadParam.token = token; loadParam.preToken = preToken; auto loadParamPtr = std::make_shared(loadParam); - amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParamPtr); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParamPtr, pid); } /* @@ -451,7 +456,8 @@ HWTEST_F(AmsMgrSchedulerTest, LoadAbility_004, TestSize.Level0) loadParam.token = token; loadParam.preToken = preToken; auto loadParamPtr = std::make_shared(loadParam); - amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParamPtr); + int32_t pid = -1; + amsMgrScheduler->LoadAbility(abilityInfo, appInfo, want, loadParamPtr, pid); } /* diff --git a/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp b/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp index 1f733461a2d..5a2b0567634 100644 --- a/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp +++ b/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp @@ -111,7 +111,8 @@ std::shared_ptr AmsServiceLoadAbilityProcessTest::StartLoadAbi loadParam.token = token; loadParam.preToken = preToken; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -149,7 +150,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_001, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -198,7 +200,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_002, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); const auto& recordMap = service_->appRunningManager_->GetAppRunningRecordMap(); EXPECT_EQ(recordMap.size(), 0); @@ -233,7 +236,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_002, TestSize.Level1) loadParam2.token = token2; loadParam2.preToken = token; auto loadParamPtr2 = std::make_shared(loadParam2); - service_->LoadAbility(abilityInfo2, appInfo2, nullptr, loadParamPtr2); + service_->LoadAbility(abilityInfo2, appInfo2, nullptr, loadParamPtr2, pid); const uint32_t EXPECT_MAP_SIZE = 2; if (recordMap.size() == EXPECT_MAP_SIZE) { auto record2 = service_->appRunningManager_->CheckAppRunningRecordIsExist( @@ -275,7 +278,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_003, TestSize.Level1) service_->SetAppSpawnClient(mockClientPtr); auto loadParamPtr = std::make_shared(); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); const auto& recordMap = service_->appRunningManager_->GetAppRunningRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)0); @@ -311,7 +315,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_004, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = GetMockToken(); auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); const auto& recordMap = service_->appRunningManager_->GetAppRunningRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)0); testing::Mock::AllowLeak(clientPtr); @@ -345,7 +350,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_005, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = GetMockToken(); auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); const auto& recordMap = service_->appRunningManager_->GetAppRunningRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)0); testing::Mock::AllowLeak(clientPtr); @@ -380,7 +386,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_006, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = GetMockToken(); auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); const auto& recordMap = service_->appRunningManager_->GetAppRunningRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)0); testing::Mock::AllowLeak(clientPtr); @@ -413,7 +420,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_007, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); const auto& recordMap = service_->appRunningManager_->GetAppRunningRecordMap(); EXPECT_EQ(recordMap.size(), 0); BundleInfo bundleInfo; @@ -434,7 +442,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_007, TestSize.Level1) EXPECT_CALL(*mockClientPtr, StartProcess(_, _)).Times(0); service_->SetAppSpawnClient(mockClientPtr); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record2 = service_->appRunningManager_->CheckAppRunningRecordIsExist( @@ -471,7 +480,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_008, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); const auto& recordMap = service_->appRunningManager_->GetAppRunningRecordMap(); EXPECT_EQ(recordMap.size(), 0); BundleInfo bundleInfo; @@ -503,7 +513,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_008, TestSize.Level1) loadParam2.token = token2; loadParam2.preToken = preToken; auto loadParamPtr2 = std::make_shared(loadParam2); - service_->LoadAbility(abilityInfo2, appInfo, nullptr, loadParamPtr2); + service_->LoadAbility(abilityInfo2, appInfo, nullptr, loadParamPtr2, pid); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record2 = service_->appRunningManager_->CheckAppRunningRecordIsExist( appInfo->name, GetTestAppName(), appInfo->uid, bundleInfo); @@ -545,7 +555,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, RequestProcess_001, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = GetMockToken(); auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -586,7 +597,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, RequestProcess_002, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = GetMockToken(); auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); const auto& recordMap = service_->appRunningManager_->GetAppRunningRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)0); @@ -621,7 +633,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, SavePid_001, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = GetMockToken(); auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -657,7 +670,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, SavePid_002, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = GetMockToken(); auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -694,7 +708,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LaunchMode_001, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -739,7 +754,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LaunchMode_002, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -763,7 +779,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LaunchMode_002, TestSize.Level1) loadParam2.token = token2; loadParam2.preToken = preToken; auto loadParamPtr2 = std::make_shared(loadParam2); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr2); + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr2, pid); auto record2 = service_->appRunningManager_->CheckAppRunningRecordIsExist( appInfo->name, GetTestAppName(), appInfo->uid, bundleInfo); EXPECT_EQ(record2, record); @@ -798,7 +814,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_001, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -866,7 +883,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_002, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -931,7 +949,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_003, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -995,7 +1014,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_004, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -1058,7 +1078,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_005, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; @@ -1123,7 +1144,8 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_006, TestSize.Level1) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; diff --git a/test/unittest/app_exit_reason_helper_fourth_test/mock/src/mock_app_scheduler.cpp b/test/unittest/app_exit_reason_helper_fourth_test/mock/src/mock_app_scheduler.cpp index ca9010b5e24..2dce0953a4b 100644 --- a/test/unittest/app_exit_reason_helper_fourth_test/mock/src/mock_app_scheduler.cpp +++ b/test/unittest/app_exit_reason_helper_fourth_test/mock/src/mock_app_scheduler.cpp @@ -41,7 +41,7 @@ bool AppScheduler::Init(const std::weak_ptr& callback) } int AppScheduler::LoadAbility(const AbilityRuntime::LoadParam& loadParam, const AppExecFwk::AbilityInfo& abilityInfo, - const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want) + const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want, int32_t &pid) { TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::LoadAbility()"); if (applicationInfo.bundleName.find("com.ix.First.Test") != std::string::npos) { diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 5e71b1afaed..54a83b19193 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -428,18 +428,19 @@ HWTEST_F(AppMgrServiceInnerTest, LoadAbility_001, TestSize.Level0) AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - appMgrServiceInner->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr); + int32_t pid = -1; + appMgrServiceInner->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr, pid); auto appMgrServiceInner1 = std::make_shared(); EXPECT_NE(appMgrServiceInner1, nullptr); appMgrServiceInner1->remoteClientManager_->SetBundleManagerHelper(nullptr); - appMgrServiceInner1->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr); + appMgrServiceInner1->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr, pid); auto appMgrServiceInner2 = std::make_shared(); EXPECT_NE(appMgrServiceInner2, nullptr); - appMgrServiceInner2->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr); + appMgrServiceInner2->LoadAbility(abilityInfo_, applicationInfo_, nullptr, loadParamPtr, pid); TAG_LOGI(AAFwkTag::TEST, "LoadAbility_001 end"); } diff --git a/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp b/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp index 5b0a8b67a98..487a9d6f0c5 100644 --- a/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp +++ b/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp @@ -182,7 +182,8 @@ std::shared_ptr AppRunningProcessesInfoTest::StartLoadAbility( AbilityRuntime::LoadParam loadParam; loadParam.token = token; auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr); + int32_t pid = -1; + service_->LoadAbility(abilityInfo, appInfo, nullptr, loadParamPtr, pid); BundleInfo bundleInfo; bundleInfo.appId = "com.ohos.test.helloworld_code123"; diff --git a/test/unittest/app_scheduler_test/app_scheduler_test.cpp b/test/unittest/app_scheduler_test/app_scheduler_test.cpp index 2fcde2b8d16..1777ed10a2d 100644 --- a/test/unittest/app_scheduler_test/app_scheduler_test.cpp +++ b/test/unittest/app_scheduler_test/app_scheduler_test.cpp @@ -234,8 +234,9 @@ HWTEST_F(AppSchedulerTest, AppScheduler_oprator_004, TestSize.Level1) loadParam.abilityRecordId = 0; loadParam.token = token; loadParam.preToken = preToken; + int32_t pid = -1; EXPECT_NE((int)ERR_OK, DelayedSingleton::GetInstance()->LoadAbility( - loadParam, record->GetAbilityInfo(), record->GetApplicationInfo(), record->GetWant())); + loadParam, record->GetAbilityInfo(), record->GetApplicationInfo(), record->GetWant(), pid)); } /* @@ -248,7 +249,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_oprator_004, TestSize.Level1) */ HWTEST_F(AppSchedulerTest, AppScheduler_LoadAbility_001, TestSize.Level1) { - EXPECT_CALL(*clientMock_, LoadAbility(_, _, _, _)).Times(1) + EXPECT_CALL(*clientMock_, LoadAbility(_, _, _, _, _)).Times(1) .WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY)); sptr token; sptr preToken; @@ -260,7 +261,9 @@ HWTEST_F(AppSchedulerTest, AppScheduler_LoadAbility_001, TestSize.Level1) loadParam.abilityRecordId = 0; loadParam.token = token; loadParam.preToken = preToken; - int res = DelayedSingleton::GetInstance()->LoadAbility(loadParam, abilityInfo, applicationInfo, want); + int32_t pid = -1; + int res = DelayedSingleton::GetInstance()->LoadAbility(loadParam, abilityInfo, + applicationInfo, want, pid); EXPECT_EQ(res, INNER_ERR); } -- Gitee