diff --git a/frameworks/c/ability_runtime/src/application_context.cpp b/frameworks/c/ability_runtime/src/application_context.cpp index a46616f751ac97d13bade606d21d2fddd15d7256..45cdf8c092c145e4ff651a554f617e730b435c9a 100644 --- a/frameworks/c/ability_runtime/src/application_context.cpp +++ b/frameworks/c/ability_runtime/src/application_context.cpp @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -29,6 +30,7 @@ #include "ffrt.h" #include "hilog_tag_wrapper.h" #include "load_ability_callback_impl.h" +#include "load_ability_callback_manager.h" #include "start_options_impl.h" #include "sys_mgr_client.h" #include "system_ability_definition.h" @@ -37,6 +39,7 @@ using namespace OHOS::AbilityRuntime; using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; using namespace OHOS; namespace { @@ -105,6 +108,12 @@ AbilityRuntime_ErrorCode CheckAppMainThread() } return ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; } + +uint64_t GenerateCallbackId() +{ + return static_cast(std::chrono::duration_cast( + std::chrono::high_resolution_clock::now().time_since_epoch()).count()); +} } AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetCacheDir( @@ -451,10 +460,9 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetVersionCode(int6 return ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; } -AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbilityWithPidResult(AbilityBase_Want *want, +AbilityRuntime_ErrorCode StartSelfUIAbilityWithPidResultPrecheck(AbilityBase_Want *want, AbilityRuntime_StartOptions *options, int32_t *targetPid) { - TAG_LOGD(AAFwkTag::APPKIT, "StartSelfUIAbilityWithPidResult called"); auto ret = CheckAppMainThread(); if (ret != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { TAG_LOGE(AAFwkTag::APPKIT, "CheckAppMainThread failed, ret=%{public}d", ret); @@ -469,6 +477,16 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbilityWithPidResult(Abili TAG_LOGE(AAFwkTag::APPKIT, "null options or targetPid"); return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; } + return ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; +} + +AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbilityWithPidResult(AbilityBase_Want *want, + AbilityRuntime_StartOptions *options, int32_t *targetPid) +{ + auto ret = StartSelfUIAbilityWithPidResultPrecheck(want, options, targetPid); + if (ret != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { + return ret; + } Want abilityWant; AbilityBase_ErrorCode errCode = CWantManager::TransformToWant(*want, false, abilityWant); if (errCode != ABILITY_BASE_ERROR_CODE_NO_ERROR) { @@ -484,20 +502,30 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_StartSelfUIAbilityWithPidResult(Abili callbackDoneCv.notify_all(); }; sptr callback = sptr::MakeSptr(std::move(task)); - auto result = AbilityManagerClient::GetInstance()->StartSelfUIAbilityWithPidResult( - abilityWant, startOptions, callback); + uint64_t callbackId = GenerateCallbackId(); + auto result = LoadAbilityCallbackManager::GetInstance().AddLoadAbilityCallback(callbackId, callback); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "add callback error:%{public}d", result); + return ABILITY_RUNTIME_ERROR_CODE_INTERNAL; + } + result = AbilityManagerClient::GetInstance()->StartSelfUIAbilityWithPidResult( + abilityWant, startOptions, callbackId); if (result != ERR_OK) { callback->Cancel(); + LoadAbilityCallbackManager::GetInstance().RemoveCallback(callback); return ConvertToAPI21BusinessErrorCode(result); } - auto condition = [&done] { - return done.load(); - }; ffrt::mutex callbackDoneMutex; std::unique_lock lock(callbackDoneMutex); - if (!callbackDoneCv.wait_for(lock, std::chrono::milliseconds(ATTACH_ABILITY_THREAD_TIMEOUT_TIME), condition) || - *targetPid < 0) { + if (!callbackDoneCv.wait_for(lock, std::chrono::milliseconds(ATTACH_ABILITY_THREAD_TIMEOUT_TIME), + [&done] { return done.load(); })) { + TAG_LOGE(AAFwkTag::APPKIT, "wait for loadability callback timeout"); callback->Cancel(); + LoadAbilityCallbackManager::GetInstance().RemoveCallback(callback); + return ABILITY_RUNTIME_ERROR_CODE_START_TIMEOUT; + } + if (*targetPid < 0) { + TAG_LOGE(AAFwkTag::APPKIT, "loadability failed"); return ABILITY_RUNTIME_ERROR_CODE_START_TIMEOUT; } return ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; diff --git a/frameworks/native/appkit/app/child_main_thread.cpp b/frameworks/native/appkit/app/child_main_thread.cpp index b33a982990d37039e7b108c3836941dff2c2fb19..5bf8207c98d73068dc0890aa5d2c1f49f72e154c 100644 --- a/frameworks/native/appkit/app/child_main_thread.cpp +++ b/frameworks/native/appkit/app/child_main_thread.cpp @@ -24,6 +24,7 @@ #endif // SUPPORT_CHILD_PROCESS #include "constants.h" #include "hilog_tag_wrapper.h" +#include "load_ability_callback_manager.h" #include "js_runtime.h" #include "native_lib_util.h" #include "sys_mgr_client.h" @@ -444,5 +445,10 @@ void ChildMainThread::GetNativeLibPath(const BundleInfo &bundleInfo, const HspLi GetHspNativeLibPath(hspInfo, appLibPaths, hspInfo.hapPath.find(ABS_CODE_PATH) != 0u); } } + +void ChildMainThread::OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) +{ + LoadAbilityCallbackManager::GetInstance().OnLoadAbilityFinished(callbackId, pid); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 1136b33f06cfceaac38cba4e6cad4f754eacdeb7..f53342c9c1483f45b5902902c81b07ee107d9c81 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -65,6 +65,7 @@ #include "file_path_utils.h" #include "freeze_util.h" #include "hilog_tag_wrapper.h" +#include "load_ability_callback_manager.h" #include "resource_config_helper.h" #ifdef SUPPORT_SCREEN #include "locale_config_ext.h" @@ -4156,5 +4157,10 @@ bool MainThread::GetTestRunnerTypeAndPath(const std::string bundleName, const st } return true; } + +void MainThread::OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) +{ + LoadAbilityCallbackManager::GetInstance().OnLoadAbilityFinished(callbackId, pid); +} } // namespace AppExecFwk } // namespace OHOS 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 b77015da00ba829a59703ec066c317063357073a..5543ab97125ec9717664bb434ad8505f6607b3a4 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -30,12 +30,8 @@ #include "want.h" #include "intent_exemption_info.h" #include "ihidden_start_observer.h" -#include "iload_ability_callback.h" namespace OHOS { -namespace AppExecFwk { -class ILoadAbilityCallback; -} namespace AAFwk { class Snapshot; class ISnapshotHandler; @@ -72,11 +68,10 @@ public: * * @param want, the want of the ability to start. * @param options, the startOptions of the ability to start. - * @param callback, the callback to get target process id. + * @param callbackId, the id of the callback to get target process id. * @return Returns ERR_OK on success, others on failure. */ - ErrCode StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, - sptr callback); + ErrCode StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, uint64_t callbackId); /** * AttachAbilityThread, ability call this interface after loaded. 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 300da7ba8cbd716f0ba27e6a6d1221ab0c9b0816..38a9f619a73a79da7924d190f78f71ee039e3cb2 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -38,7 +38,6 @@ #include "iability_controller.h" #include "iability_manager_collaborator.h" #include "iacquire_share_data_callback_interface.h" -#include "iload_ability_callback.h" #include "insight_intent/insight_intent_execute_param.h" #include "insight_intent/insight_intent_execute_result.h" #include "insight_intent/insight_intent_info_for_query.h" @@ -137,11 +136,10 @@ public: * * @param want, the want of the ability to start. * @param options, the startOptions of the ability to start. - * @param callback, the callback to get target process id. + * @param callbackId, the id of the callback to get target process id. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, - sptr callback) + virtual int StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, uint64_t callbackId) { return 0; } diff --git a/interfaces/inner_api/ability_manager/include/process_options.h b/interfaces/inner_api/ability_manager/include/process_options.h index d6924e8241d510b4ebf87b5fd7e08f5eff0726f3..5e5e7c13b55c0b02d62757c5dad28b18a2d98ec4 100644 --- a/interfaces/inner_api/ability_manager/include/process_options.h +++ b/interfaces/inner_api/ability_manager/include/process_options.h @@ -58,10 +58,11 @@ public: bool isRestartKeepAlive = false; bool isStartFromNDK = false; bool isPreloadStart = false; - bool shouldReturnPid = false; ProcessMode processMode = ProcessMode::UNSPECIFIED; StartupVisibility startupVisibility = StartupVisibility::UNSPECIFIED; std::string processName; + uint64_t loadAbilityCallbackId = 0; + pid_t callingPid = -1; }; } // namespace AAFwk } // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/include/start_options.h b/interfaces/inner_api/ability_manager/include/start_options.h index cf5f0c4d23bcb2a74ff3e9a72cc641aa3516013d..2941add21d5a6a72e30ed84afe282c933173b045 100644 --- a/interfaces/inner_api/ability_manager/include/start_options.h +++ b/interfaces/inner_api/ability_manager/include/start_options.h @@ -81,7 +81,6 @@ public: std::vector supportWindowModes_; std::string requestId_; std::shared_ptr windowCreateParams_ = nullptr; - sptr loadAbilityCallback_ = nullptr; StartOptions() = default; ~StartOptions() = default; diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index ae46afd971711bd1473c5ab1f45c790cbdd476c4..865a6a57fc5325aad0a03d3a0b8d048a038507bd 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -49,6 +49,7 @@ ohos_shared_library("app_manager") { "${ability_runtime_services_path}/appdfr/include", "${ability_runtime_services_path}/appmgr/include", "${ability_runtime_services_path}/common/include", + "${ability_runtime_utils_path}/global/constant", ] sources = [ @@ -104,6 +105,7 @@ ohos_shared_library("app_manager") { "src/appmgr/fault_data.cpp", "src/appmgr/kia_interceptor_proxy.cpp", "src/appmgr/kia_interceptor_stub.cpp", + "src/appmgr/load_ability_callback_manager.cpp", "src/appmgr/load_ability_callback_proxy.cpp", "src/appmgr/load_ability_callback_stub.cpp", "src/appmgr/memory_level_info.cpp", 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 bde4ece9b723245c9335a8ac6823c5f232a7127f..fa96e9fdbd044a93d4a0736cca93f3a8bb11ed04 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 @@ -23,7 +23,6 @@ #include "application_info.h" #include "configuration.h" #include "iapp_state_callback.h" -#include "iload_ability_callback.h" #include "iremote_broker.h" #include "iremote_object.h" #include "istart_specified_ability_response.h" @@ -46,13 +45,20 @@ public: * @param preToken, the unique identification to call the ability. * @param abilityInfo, the ability information. * @param appInfo, the app information. - * @param callback, the callback to get 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, - sptr callback = nullptr) {}; + const std::shared_ptr &appInfo, const std::shared_ptr &want, + std::shared_ptr loadParam) {}; + + /** + * notify load ability finished. + * + * @param callingPid, the pid of the caller. + * @param targetPid, the pid of the target ability. + * @param callbackId, the id of the callback. + */ + virtual void NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId) {}; /** * TerminateAbility, call TerminateAbility() through the proxy object, terminate the token ability. @@ -582,6 +588,7 @@ public: NOTIFY_PRELOAD_ABILITY_STATE_CHANGED, CHECK_PRELOAD_APP_RECORD_EXIST, VERIFY_KILL_PROCESS_PERMISSION, + NOTIFY_LOAD_ABILITY_FINISHED, // Add enumeration values above END }; 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 53fb4abff965122fa5265386ac9aa42e15242039..4c1d1f586a5f2e34930c2c7fd12e84304d723451 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,13 +34,20 @@ public: * @param preToken, the unique identification to call the ability. * @param abilityInfo, the ability information. * @param appInfo, the app information. - * @param callback, the callback to get 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, - sptr callback = nullptr) override; + const std::shared_ptr &appInfo, const std::shared_ptr &want, + std::shared_ptr loadParam) override; + + /** + * notify load ability finished. + * + * @param callingPid, the pid of the caller. + * @param targetPid, the pid of the target ability. + * @param callbackId, the id of the callback. + */ + virtual void NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId) override; /** * TerminateAbility, call TerminateAbility() through the proxy object, terminate the token ability. diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h index e903a0c4bcd5ad33b5b994530694f958cc891199..c6ce9810744d9fc0eeffa58fea5f11bac19787f8 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h @@ -44,6 +44,7 @@ public: private: void CreateMemberFuncMap(); int32_t HandleLoadAbility(MessageParcel &data, MessageParcel &reply); + int32_t HandleNotifyLoadAbilityFinished(MessageParcel &data, MessageParcel &reply); int32_t HandleTerminateAbility(MessageParcel &data, MessageParcel &reply); int32_t HandleUpdateAbilityState(MessageParcel &data, MessageParcel &reply); int32_t HandleUpdateExtensionState(MessageParcel &data, MessageParcel &reply); 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 7a1bc1288b8ca3a7084eea5dc80615c57c2416ae..9090e59cc8b0342a973f3f2694855d2b15fc80e5 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 @@ -63,12 +63,19 @@ public: * @param appInfo Application information. * @param want Want. * @param loadParam load ability param. - * @param callback, the callback to get 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, - sptr callback = nullptr); + const AAFwk::Want &want, AbilityRuntime::LoadParam loadParam); + + /** + * notify load ability finished. + * + * @param callingPid, the pid of the caller. + * @param targetPid, the pid of the target ability. + * @param callbackId, the id of the callback. + */ + virtual void NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId); /** * Terminate ability. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h index 1d9d37965851a3b47db126956da96be0504ed115..a626f4a451c5b8154711d180454b93c07600595d 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h @@ -70,6 +70,7 @@ private: int32_t HandleScheduleCacheProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleDumpFfrt(MessageParcel &data, MessageParcel &reply); int32_t HandleSetWatchdogBackgroundStatus(MessageParcel &data, MessageParcel &reply); + int32_t HandleOnLoadAbilityFinished(MessageParcel &data, MessageParcel &reply); int32_t OnRemoteRequestInner(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); int32_t OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data, diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h index e56177a989cacc0d65ba8bdca55487e619bedf7c..da4280e2e6b25330cc5c3582934f0a5acec61d90 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h @@ -329,6 +329,13 @@ public: */ virtual void SetWatchdogBackgroundStatus(bool status) = 0; + /** + * Call the callback to send the pid of the started ability. + * @param callbackId The id of the callback to send the pid. + * @param pid The resultant process id of the started ability. + */ + virtual void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) = 0; + enum class Message { SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION = 0, SCHEDULE_BACKGROUND_APPLICATION_TRANSACTION, @@ -364,6 +371,7 @@ public: SCHEDULE_PREPARE_TERMINATE, WATCHDOG_BACKGROUND_STATUS_TRANSACTION, SCHEDULE_CJHEAP_MEMORY_APPLICATION_TRANSACTION, + ON_LOAD_ABILITY_FINISHED, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h index 6e402c41b6fafd8834a68df4de7ed70bfe3b7b52..5609ec282aee6eda3e3a2828532e9623435d1cf1 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h @@ -320,6 +320,13 @@ public: */ virtual void SetWatchdogBackgroundStatus(bool status) override; + /** + * Call the callback to send the pid of the started ability. + * @param callbackId The id of the callback to send the pid. + * @param pid The resultant process id of the started ability. + */ + virtual void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) override; + private: bool WriteInterfaceToken(MessageParcel &data); void ScheduleMemoryCommon(const int32_t level, const uint32_t operation); diff --git a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_interface.h b/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_interface.h index 35ec3c60b70af7d375d703ed7ece9ac31cbff929..ba5c924dc9af7c2e6ff5f8ae408b1133ae20e566 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_interface.h @@ -40,10 +40,18 @@ public: */ virtual bool ScheduleRunNativeProc(const sptr &mainProcessCb) = 0; + /** + * Call the callback to send the pid of the started ability. + * @param callbackId The id of the callback to send the pid. + * @param pid The resultant process id of the started ability. + */ + virtual void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) = 0; + enum class Message { SCHEDULE_LOAD_JS = 0, SCHEDULE_EXIT_PROCESS_SAFELY = 1, SCHEDULE_RUN_NATIVE_PROC = 2, + ON_LOAD_ABILITY_FINISHED = 3, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_proxy.h index d57785e961798dc79c31f18ef3b3705e0647b8c3..759d66723882f4776160b065f93ad10f1493dab7 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_proxy.h @@ -30,6 +30,7 @@ public: bool ScheduleLoadChild() override; bool ScheduleExitProcessSafely() override; bool ScheduleRunNativeProc(const sptr &mainProcessCb) override; + void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) override; private: bool WriteInterfaceToken(MessageParcel &data); diff --git a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_stub.h b/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_stub.h index 02ec8428a1acb41945f57ea4183f9aad72a2d91d..065aaf029204fb978fd13124b67550e7cb8fc75c 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_stub.h @@ -37,6 +37,7 @@ private: int32_t HandleScheduleLoadChild(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleExitProcessSafely(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleRunNativeProc(MessageParcel &data, MessageParcel &reply); + int32_t HandleOnLoadAbilityFinished(MessageParcel &data, MessageParcel &reply); DISALLOW_COPY_AND_MOVE(ChildSchedulerStub); }; diff --git a/test/mock/services_abilitymgr_test/libs/aakit/include/mock_load_ability_callback.h b/interfaces/inner_api/app_manager/include/appmgr/load_ability_callback_manager.h similarity index 40% rename from test/mock/services_abilitymgr_test/libs/aakit/include/mock_load_ability_callback.h rename to interfaces/inner_api/app_manager/include/appmgr/load_ability_callback_manager.h index beace93518713d2fce93d904ec05ca99cc57368f..052cd0b0b5175eb426fdc49d607923c15f3ddf9d 100644 --- a/test/mock/services_abilitymgr_test/libs/aakit/include/mock_load_ability_callback.h +++ b/interfaces/inner_api/app_manager/include/appmgr/load_ability_callback_manager.h @@ -13,20 +13,38 @@ * limitations under the License. */ -#ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_LOAD_ABILITY_CALLBACK_H -#define MOCK_OHOS_ABILITY_RUNTIME_MOCK_LOAD_ABILITY_CALLBACK_H +#ifndef OHOS_ABILITY_RUNTIME_LOAD_ABILITY_CALLBACK_MANAGER_H +#define OHOS_ABILITY_RUNTIME_LOAD_ABILITY_CALLBACK_MANAGER_H -#include "load_ability_callback_stub.h" +#include +#include +#include +#include "cpp/mutex.h" + +#include "iload_ability_callback.h" +#include "singleton.h" namespace OHOS { -namespace AbilityRuntime { -class MockLoadAbilityCallback : public AppExecFwk::LoadAbilityCallbackStub { +namespace AppExecFwk { +class LoadAbilityCallbackManager { public: - MockLoadAbilityCallback() {}; - virtual ~MockLoadAbilityCallback() {}; - virtual void OnFinish(int32_t pid) override; -}; -} // namespace AAFwk -} // namespace OHOS + static LoadAbilityCallbackManager &GetInstance(); + + int32_t AddLoadAbilityCallback(uint64_t callbackId, sptr callback); + + int32_t RemoveCallback(sptr callback); -#endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_LOAD_ABILITY_CALLBACK_H + void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid); + +private: + LoadAbilityCallbackManager(); + ~LoadAbilityCallbackManager(); + + DISALLOW_COPY_AND_MOVE(LoadAbilityCallbackManager); + + ffrt::mutex callbackLock_; + std::unordered_map> callbacks_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_LOAD_ABILITY_CALLBACK_MANAGER_H \ No newline at end of file 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 927d8950842df0e0240f4830ebfa12f7e305e67e..465f0b363da3dd837f31b1bfa03aa86c967dfdd6 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 @@ -68,8 +68,7 @@ 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, - sptr callback) + const std::shared_ptr &want, std::shared_ptr loadParam) { TAG_LOGD(AAFwkTag::APPMGR, "start"); if (!abilityInfo || !appInfo) { @@ -99,17 +98,6 @@ void AmsMgrProxy::LoadAbility(const std::shared_ptr &abilityInfo, TAG_LOGE(AAFwkTag::APPMGR, "Write data loadParam failed"); return; } - if (callback != nullptr && callback->AsObject() != nullptr) { - if (!data.WriteBool(true) || !data.WriteRemoteObject(callback->AsObject())) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag and callback"); - return; - } - } else { - if (!data.WriteBool(false)) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag"); - return; - } - } int32_t ret = SendTransactCmd(static_cast(IAmsMgr::Message::LOAD_ABILITY), data, reply, option); if (ret != NO_ERROR) { @@ -120,6 +108,34 @@ void AmsMgrProxy::LoadAbility(const std::shared_ptr &abilityInfo, TAG_LOGD(AAFwkTag::APPMGR, "end"); } +void AmsMgrProxy::NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteInt32(callingPid)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write callingPid failed"); + return; + } + if (!data.WriteInt32(targetPid)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write targetPid failed"); + return; + } + if (!data.WriteUint64(callbackId)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write callbackId failed"); + return; + } + + int32_t ret = SendTransactCmd(static_cast(IAmsMgr::Message::NOTIFY_LOAD_ABILITY_FINISHED), + data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret); + } +} + void AmsMgrProxy::TerminateAbility(const sptr &token, bool clearMissionFlag) { TAG_LOGD(AAFwkTag::APPMGR, "start"); 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 2f19a48db721d9e950d24fa1b5d1a092132fb532..eceddd587ba1d01a1df92f7ce01c18eefceac5a4 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 @@ -235,6 +235,8 @@ int32_t AmsMgrStub::OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &dat return HandleCheckPreloadAppRecordExist(data, reply); case static_cast(IAmsMgr::Message::VERIFY_KILL_PROCESS_PERMISSION): return HandleVerifyKillProcessPermission(data, reply); + case static_cast(IAmsMgr::Message::NOTIFY_LOAD_ABILITY_FINISHED): + return HandleNotifyLoadAbilityFinished(data, reply); } return AAFwk::ERR_CODE_NOT_EXIST; } @@ -264,13 +266,17 @@ ErrCode AmsMgrStub::HandleLoadAbility(MessageParcel &data, MessageParcel &reply) TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable loadParam failed"); return ERR_APPEXECFWK_PARCEL_ERROR; } - sptr callback = nullptr; - if (data.ReadBool()) { - sptr obj = data.ReadRemoteObject(); - callback = iface_cast(obj); - } + LoadAbility(abilityInfo, appInfo, want, loadParam); + return NO_ERROR; +} - LoadAbility(abilityInfo, appInfo, want, loadParam, callback); +ErrCode AmsMgrStub::HandleNotifyLoadAbilityFinished(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + int32_t callingPid = data.ReadInt32(); + int32_t targetPid = data.ReadInt32(); + uint64_t callbackId = data.ReadUint64(); + NotifyLoadAbilityFinished(callingPid, targetPid, callbackId); 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 9d188d1f20af9f3aa28d17ea533c23e126bb2f0b..cb62cd59c5cf510450c3428c5d49dd87408abe78 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, sptr callback) + const AAFwk::Want &want, AbilityRuntime::LoadParam loadParam) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); if (service != nullptr) { @@ -171,13 +171,24 @@ 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, callback); + amsService->LoadAbility(abilityInfoPtr, appInfoPtr, wantPtr, loadParamPtr); return AppMgrResultCode::RESULT_OK; } } return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } +void AppMgrClient::NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId) +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service != nullptr) { + sptr amsService = service->GetAmsMgr(); + if (amsService != nullptr) { + amsService->NotifyLoadAbilityFinished(callingPid, targetPid, callbackId); + } + } +} + AppMgrResultCode AppMgrClient::TerminateAbility(const sptr &token, bool clearMissionFlag) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp index fbff8d8f992a7f7e0521fb56a4616d992c125251..69fd35b52ea40dd7ad2335adc6e43136827e8b30 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp @@ -157,6 +157,8 @@ int32_t AppSchedulerHost::OnRemoteRequestInnerThird(uint32_t code, MessageParcel return HandleScheduleCacheProcess(data, reply); case static_cast(IAppScheduler::Message::WATCHDOG_BACKGROUND_STATUS_TRANSACTION): return HandleSetWatchdogBackgroundStatus(data, reply); + case static_cast(IAppScheduler::Message::ON_LOAD_ABILITY_FINISHED): + return HandleOnLoadAbilityFinished(data, reply); } return INVALID_FD; } @@ -533,5 +535,14 @@ int32_t AppSchedulerHost::HandleSetWatchdogBackgroundStatus(MessageParcel &data, SetWatchdogBackgroundStatus(status); return NO_ERROR; } + +int32_t AppSchedulerHost::HandleOnLoadAbilityFinished(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + uint64_t callbackId = data.ReadUint64(); + int32_t pid = data.ReadInt32(); + OnLoadAbilityFinished(callbackId, pid); + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp index 04cfa6b86f35213cf4b969b2e3bb167d929fd547..4971c0f964ebcd2efefe3e3a1036b416dbea4e8a 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp @@ -902,5 +902,28 @@ void AppSchedulerProxy::ScheduleCacheProcess() TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); } } + +void AppSchedulerProxy::OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteUint64(callbackId)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write callbackId failed."); + return; + } + if (!data.WriteInt32(pid)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write pid failed."); + return; + } + int32_t ret = SendTransactCmd(static_cast(IAppScheduler::Message::ON_LOAD_ABILITY_FINISHED), + data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is wrong, error code: %{public}d", ret); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_proxy.cpp index 94bddd23a0c54f22a4588da1c1c72ddd7a55896a..442f1ff4ac4b90f28e1fd2e9786ab4e469b098ca 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_proxy.cpp @@ -117,5 +117,34 @@ bool ChildSchedulerProxy::ScheduleRunNativeProc(const sptr &mainP return true; } +void ChildSchedulerProxy::OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return; + } + if (!data.WriteUint64(callbackId)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write callbackId failed."); + return; + } + if (!data.WriteInt32(pid)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write pid failed."); + return; + } + + sptr remote = Remote(); + if (remote == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "Remote() is null."); + return; + } + int32_t ret = remote->SendRequest( + static_cast(IChildScheduler::Message::ON_LOAD_ABILITY_FINISHED), data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d.", ret); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_stub.cpp index 42e81559dfc6d4c64574d04d3aa8ffb8ce125c90..93e559dab713838d1d1f95c5b8fdae905997d183 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_stub.cpp @@ -43,6 +43,8 @@ int32_t ChildSchedulerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, return HandleScheduleExitProcessSafely(data, reply); case static_cast(IChildScheduler::Message::SCHEDULE_RUN_NATIVE_PROC): return HandleScheduleRunNativeProc(data, reply); + case static_cast(IChildScheduler::Message::ON_LOAD_ABILITY_FINISHED): + return HandleOnLoadAbilityFinished(data, reply); } TAG_LOGI(AAFwkTag::APPMGR, "ChildSchedulerStub::OnRemoteRequest end"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -67,5 +69,12 @@ int32_t ChildSchedulerStub::HandleScheduleRunNativeProc(MessageParcel &data, Mes return ERR_NONE; } +int32_t ChildSchedulerStub::HandleOnLoadAbilityFinished(MessageParcel &data, MessageParcel &reply) +{ + uint64_t callbackId = data.ReadUint64(); + int32_t pid = data.ReadInt32(); + OnLoadAbilityFinished(callbackId, pid); + return ERR_NONE; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/app_manager/src/appmgr/load_ability_callback_manager.cpp b/interfaces/inner_api/app_manager/src/appmgr/load_ability_callback_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e7868425f2e1de609a0e65d7f404d4e63989d2f9 --- /dev/null +++ b/interfaces/inner_api/app_manager/src/appmgr/load_ability_callback_manager.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "load_ability_callback_manager.h" + +#include "ffrt.h" +#include "global_constant.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +LoadAbilityCallbackManager::LoadAbilityCallbackManager() +{ +} + +LoadAbilityCallbackManager::~LoadAbilityCallbackManager() +{} + +LoadAbilityCallbackManager &LoadAbilityCallbackManager::GetInstance() +{ + static LoadAbilityCallbackManager manager; + return manager; +} + +int32_t LoadAbilityCallbackManager::AddLoadAbilityCallback(uint64_t callbackId, sptr callback) +{ + if (callbackId == 0 || callback == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "invalid callbackId or null callback"); + return ERR_INVALID_VALUE; + } + + std::lock_guard lock(callbackLock_); + callbacks_[callbackId] = callback; + + return ERR_OK; +} + +int32_t LoadAbilityCallbackManager::RemoveCallback(sptr callback) +{ + if (callback == nullptr) { + return ERR_INVALID_VALUE; + } + TAG_LOGI(AAFwkTag::APPMGR, "remove callback"); + std::lock_guard lock(callbackLock_); + for (const auto &cb : callbacks_) { + if (cb.second && cb.second->AsObject() == callback->AsObject()) { + callbacks_.erase(cb.first); + return ERR_OK; + } + } + TAG_LOGI(AAFwkTag::APPMGR, "callback null or removed"); + return ERR_INVALID_VALUE; +} + +void LoadAbilityCallbackManager::OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) +{ + sptr callback = nullptr; + { + std::lock_guard lock(callbackLock_); + auto iter = callbacks_.find(callbackId); + if (iter == callbacks_.end()) { + TAG_LOGE(AAFwkTag::APPMGR, "no such callback, callbackId=%{public}s", std::to_string(callbackId).c_str()); + return; + } + callback = iter->second; + callbacks_.erase(iter); + } + if (callback == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "null callback"); + return; + } + callback->OnFinish(pid); +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/native/appkit/app/child_main_thread.h b/interfaces/kits/native/appkit/app/child_main_thread.h index 44e96a1ad687fdb38bff8ba42acf1c0bbff80faf..ec529de593c28b294b1d7a2130d0d8db6047c0b7 100644 --- a/interfaces/kits/native/appkit/app/child_main_thread.h +++ b/interfaces/kits/native/appkit/app/child_main_thread.h @@ -45,6 +45,7 @@ public: bool ScheduleLoadChild() override; bool ScheduleExitProcessSafely() override; bool ScheduleRunNativeProc(const sptr &mainProcessCb) override; + void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) override; private: static int32_t GetChildProcessInfo(ChildProcessInfo &info); diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index 6bd4acfe17b86071be130edb587e072581f6846e..70bb9e9fd86741dd9464eae3109fad96ba02b1d6 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -393,6 +393,8 @@ public: */ void SetWatchdogBackgroundStatus(bool status) override; + void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) override; + private: /** * diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 08b6615645db03d9e211bc8b25749b3106e62a56..fb6b82f9078f4a4db2ebca11720276d266f812ba 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -60,11 +60,10 @@ public: * * @param want, the want of the ability to start. * @param options, the startOptions of the ability to start. - * @param callback, the callback to get target process id. + * @param callbackId, the id of the callback to get target process id. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, - sptr callback) override; + virtual int StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, uint64_t callbackId) override; /** * StartAbility with want, send want to ability manager service. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 1b56ecbe3f0a57962d59bc88c731df1558916546..6a3ab51373a4fad56edabe4554fb61c5eb6fa68f 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -146,11 +146,10 @@ public: * * @param want, the want of the ability to start. * @param options, the startOptions of the ability to start. - * @param callback, the callback to get target process id. + * @param callbackId, the id of the callback to get target process id. * @return Returns ERR_OK on success, others on failure. */ - virtual int StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, - sptr callback) override; + virtual int StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, uint64_t callbackId) override; /** * StartAbility with want, send want to ability manager service. diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index f8d5faa523c9e5867992df56246f46d4a7fc8ade..8b1c93ee50f492bef1b577631bdec50bc0c427a2 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -52,9 +52,6 @@ #endif namespace OHOS { -namespace AppExecFwk { -class ILoadAbilityCallback; -} namespace AAFwk { using Closure = std::function; @@ -377,6 +374,16 @@ public: std::string perfCmd; }; +struct ForegroundOptions { + uint32_t sceneFlag = 0; + bool isShellCall = false; + bool isStartupHide = false; + pid_t callingPid = -1; + uint64_t loadAbilityCallbackId = 0; +}; + +static ForegroundOptions DEFAULT_FOREGROUND_OPTIONS; + /** * @class AbilityRecord * AbilityRecord records ability info and states and used to schedule ability life. @@ -414,8 +421,8 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - int LoadAbility(bool isShellCall = false, bool isStartupHide = false, - sptr callback = nullptr); + int LoadAbility(bool isShellCall = false, bool isStartupHide = false, pid_t callingPid = -1, + uint64_t loadAbilityCallbackId = 0); /** * foreground the ability. @@ -428,9 +435,7 @@ public: * process request of foregrounding the ability. * */ - void ProcessForegroundAbility( - uint32_t tokenId, uint32_t sceneFlag = 0, bool isShellCall = false, bool isStartupHide = false, - sptr callback = nullptr); + void ProcessForegroundAbility(uint32_t tokenId, const ForegroundOptions &options = DEFAULT_FOREGROUND_OPTIONS); /** * post foreground timeout task for ui ability. @@ -1275,16 +1280,6 @@ 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); @@ -1410,7 +1405,6 @@ 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/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 8ce434fd6749714b225022887159b66146162b73..e923f7bcdcb423420744f879506f8cd8a7db327d 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -159,12 +159,19 @@ public: * @param abilityInfo, ability info. * @param applicationInfo, application info. * @param want ability want - * @param callback, the callback to get 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, - sptr callback = nullptr); + const AppExecFwk::ApplicationInfo &applicationInfo, const Want &want); + + /** + * notify load ability finished. + * + * @param callingPid, the pid of the caller. + * @param targetPid, the pid of the target ability. + * @param callbackId, the id of the callback. + */ + void NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId); /** * terminate ability with token. diff --git a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h index 26ed1bfb4b144d4d55167ab9831a6bccd40d176c..b984ca2a9b65dc8fdfa5f69c871bbfb6be5351c2 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -529,7 +529,6 @@ private: void HandleAbilitiesNormalSessionInfo(AbilityRequest &abilityRequest, std::shared_ptr abilitiesRequest, int32_t requestId); void RemoveInstanceKey(const AbilityRequest &abilityRequest) const; - sptr GetLoadAbilityCallback(int32_t requestId); int32_t userId_ = -1; mutable ffrt::mutex sessionLock_; @@ -537,7 +536,6 @@ private: std::unordered_map> lowMemKillAbilityMap_; std::unordered_map> tmpAbilityMap_; std::unordered_map, std::list> callRequestCache_; - std::map> loadAbilityCallbackMap_; std::list> terminateAbilityList_; sptr rootSceneSession_; sptr handler_; diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 7e1ade3b0c80b1c52366d589d0c045eef37429d2..fcc57c3d3f1f22c225c042a8ecf86c000f185f6e 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -20,7 +20,6 @@ #endif // WITH_DLP #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" -#include "iload_ability_callback.h" #include "iservice_registry.h" #ifdef SUPPORT_SCREEN #include "scene_board_judgement.h" @@ -2209,12 +2208,12 @@ ErrCode AbilityManagerClient::StartSelfUIAbilityWithStartOptions(const Want &wan } ErrCode AbilityManagerClient::StartSelfUIAbilityWithPidResult(const Want &want, - StartOptions &options, sptr callback) + StartOptions &options, uint64_t callbackId) { TAG_LOGI(AAFwkTag::ABILITYMGR, "call StartSelfUIAbilityWithPidResult"); auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->StartSelfUIAbilityWithPidResult(want, options, callback); + return abms->StartSelfUIAbilityWithPidResult(want, options, callbackId); } void AbilityManagerClient::PrepareTerminateAbilityDone(sptr token, bool isTerminate) diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 995c6007215ed87e27780bd94f8d424d657e3be1..3a46f66e28ecb8a7264925abbe1118f1f31dfb49 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -6495,17 +6495,12 @@ int32_t AbilityManagerProxy::StartSelfUIAbilityWithStartOptions(const Want &want } int32_t AbilityManagerProxy::StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, - sptr callback) + uint64_t callbackId) { MessageParcel data; MessageParcel reply; MessageOption option; - if (callback == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null callback"); - return INVALID_REMOTE_PARAMETERS_ERR; - } - if (!WriteInterfaceToken(data)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail"); return ERR_WRITE_INTERFACE_CODE; @@ -6521,9 +6516,9 @@ int32_t AbilityManagerProxy::StartSelfUIAbilityWithPidResult(const Want &want, S return ERR_WRITE_START_OPTIONS; } - if (!data.WriteRemoteObject(callback->AsObject())) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "write callback fail"); - return INVALID_REMOTE_PARAMETERS_ERR; + if (!data.WriteUint64(callbackId)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write callbackId fail"); + return ERR_WRITE_INT_FAILED; } auto error = SendRequest(AbilityManagerInterfaceCode::START_SELF_UI_ABILITY_WITH_PID_RESULT, diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 079930e113987ed147cf67bb5d7e85cec60354a7..e49b26dabf868aa99c979d4eadefe0c42af9155e 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -14826,17 +14826,16 @@ int AbilityManagerService::StartSelfUIAbilityWithStartOptions(const Want &want, } int AbilityManagerService::StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, - sptr callback) + uint64_t callbackId) { XCOLLIE_TIMER_LESS(__PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "StartSelfUIAbilityWithPidResult"); - CHECK_POINTER_AND_RETURN(callback, ERR_INVALID_VALUE); if (options.processOptions == nullptr) { options.processOptions = std::make_shared(); } - options.processOptions->shouldReturnPid = true; - options.loadAbilityCallback_ = callback->AsObject(); + options.processOptions->loadAbilityCallbackId = callbackId; + options.processOptions->callingPid = IPCSkeleton::GetCallingPid(); auto ret = StartSelfUIAbilityWithStartOptions(want, options); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "StartSelfUIAbilityWithStartOptions failed:%{public}d", ret); diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index f2307a350349a6ff3a981119732265537fe333e7..d66a2194eae70f0176edcb55040cfca97ebe4d42 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -4631,8 +4631,8 @@ int32_t AbilityManagerStub::StartSelfUIAbilityWithPidResultInner(MessageParcel & TAG_LOGE(AAFwkTag::ABILITYMGR, "startOptions null"); return ERR_READ_START_OPTIONS; } - auto callback = iface_cast(data.ReadRemoteObject()); - int32_t result = StartSelfUIAbilityWithPidResult(*want, *options, callback); + auto callbackId = data.ReadUint64(); + int32_t result = StartSelfUIAbilityWithPidResult(*want, *options, callbackId); if (!reply.WriteInt32(result)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "write StartSelfUIAbilityWithPidResult result fail"); return ERR_WRITE_START_SELF_UI_ABILITY_RESULT; diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index a8f331781e9e87b44efa63406f63dc7cada73d7b..e8d61af9f0a83f9f4fb7c75159fa9c0ace7631bc 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -247,10 +247,8 @@ std::shared_ptr AbilityRecord::CreateAbilityRecord(const AbilityR abilityRecord->SetSecurityFlag(abilityRequest.want.GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false)); abilityRecord->SetCallerAccessTokenId(abilityRequest.callerAccessTokenId); if (abilityRequest.processOptions != nullptr) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "isPreloadStart:%{public}d,shouldReturnPid:%{public}d", - abilityRequest.processOptions->isPreloadStart, abilityRequest.processOptions->shouldReturnPid); + TAG_LOGD(AAFwkTag::ABILITYMGR, "isPreloadStart:%{public}d", abilityRequest.processOptions->isPreloadStart); abilityRecord->SetPreloadStart(abilityRequest.processOptions->isPreloadStart); - abilityRecord->SetShouldReturnPid(abilityRequest.processOptions->shouldReturnPid); } abilityRecord->sessionInfo_ = abilityRequest.sessionInfo; if (AppUtils::GetInstance().IsMultiProcessModel() && abilityRequest.abilityInfo.isStageBasedModel && @@ -340,7 +338,8 @@ void AbilityRecord::LoadUIAbility() g_addLifecycleEventTask(token_, methodName); } -int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, sptr callback) +int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, pid_t callingPid, + uint64_t loadAbilityCallbackId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "LoadLifecycle: abilityName:%{public}s", abilityInfo_.name.c_str()); @@ -376,13 +375,15 @@ int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, sptr::GetInstance()->LoadAbility( - loadParam, abilityInfo_, abilityInfo_.applicationInfo, want_, callback); + loadParam, abilityInfo_, abilityInfo_.applicationInfo, want_); want_.RemoveParam(IS_HOOK); want_.RemoveParam(ABILITY_OWNER_USERID); want_.RemoveParam(Want::PARAMS_REAL_CALLER_KEY); @@ -490,9 +491,7 @@ void AbilityRecord::ForegroundUIExtensionAbility(uint32_t sceneFlag) } } -void AbilityRecord::ProcessForegroundAbility( - uint32_t tokenId, uint32_t sceneFlag, bool isShellCall, bool isStartupHide, - sptr callback) +void AbilityRecord::ProcessForegroundAbility(uint32_t tokenId, const ForegroundOptions &options) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); std::string element = GetElementName().GetURI(); @@ -505,11 +504,14 @@ void AbilityRecord::ProcessForegroundAbility( #endif // SUPPORT_UPMS if (!isReady_) { TAG_LOGD(AAFwkTag::ABILITYMGR, "To load ability."); - lifeCycleStateInfo_.sceneFlagBak = sceneFlag; - LoadAbility(isShellCall, isStartupHide, callback); + lifeCycleStateInfo_.sceneFlagBak = options.sceneFlag; + LoadAbility(options.isShellCall, options.isStartupHide, options.callingPid, options.loadAbilityCallbackId); return; } + DelayedSingleton::GetInstance()->NotifyLoadAbilityFinished(options.callingPid, + GetPid(), options.loadAbilityCallbackId); + PostForegroundTimeoutTask(); if (IsAbilityState(AbilityState::FOREGROUND)) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Activate %{public}s", element.c_str()); @@ -519,12 +521,12 @@ void AbilityRecord::ProcessForegroundAbility( DelayedSingleton::GetInstance()->NotifyPreloadAbilityStateChanged(token_, false); TAG_LOGI(AAFwkTag::ABILITYMGR, "NotifyPreloadAbilityStateChanged by start, ret: %{public}d", ret); } - ForegroundAbility(sceneFlag); + ForegroundAbility(options.sceneFlag); return; } // background to active state TAG_LOGD(AAFwkTag::ABILITYMGR, "MoveToForeground, %{public}s", element.c_str()); - lifeCycleStateInfo_.sceneFlagBak = sceneFlag; + lifeCycleStateInfo_.sceneFlagBak = options.sceneFlag; ResSchedUtil::GetInstance().ReportEventToRSS(GetUid(), GetAbilityInfo().bundleName, "THAW_BY_FOREGROUND_ABILITY", GetPid(), GetCallerRecord() ? GetCallerRecord()->GetPid() : -1); SendAppStartupTypeEvent(AppExecFwk::AppStartType::HOT); diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 6679214022a4fbfe5c74e9b308e318f576ef08e9..f2932a5e400f48bedcfa1fc15e8ad152ca30446c 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -68,27 +68,34 @@ 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, - sptr callback) + const AppExecFwk::ApplicationInfo &applicationInfo, const Want &want) { if (AppUtils::GetInstance().IsForbidStart()) { TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", abilityInfo.bundleName.c_str()); return INNER_ERR; } HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGD(AAFwkTag::SERVICE_EXT, "called"); + TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); /* 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, callback))); + appMgrClient_->LoadAbility(abilityInfo, applicationInfo, want, loadParam))); if (ret != ERR_OK) { - TAG_LOGE(AAFwkTag::SERVICE_EXT, "AppScheduler fail to LoadAbility. ret %{public}d", ret); + TAG_LOGE(AAFwkTag::ABILITYMGR, "AppScheduler fail to LoadAbility. ret %{public}d", ret); return INNER_ERR; } return ERR_OK; } +void AppScheduler::NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::ABILITYMGR, "NotifyLoadAbilityFinished called"); + CHECK_POINTER(appMgrClient_); + IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->NotifyLoadAbilityFinished(callingPid, targetPid, callbackId)); +} + int AppScheduler::TerminateAbility(const sptr &token, bool clearMissionFlag) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/services/abilitymgr/src/mission/mission_list_manager.cpp b/services/abilitymgr/src/mission/mission_list_manager.cpp index 838b6eca1f0c513b269f25db308819a180acb6d3..abed629a99e67c2dd4a34cba1e591701c9fa9a56 100644 --- a/services/abilitymgr/src/mission/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission/mission_list_manager.cpp @@ -4138,7 +4138,9 @@ int MissionListManager::DoAbilityForeground(std::shared_ptr &abil TAG_LOGD(AAFwkTag::ABILITYMGR, "pending state is not FOREGROUND."); abilityRecord->SetPendingState(AbilityState::FOREGROUND); } - abilityRecord->ProcessForegroundAbility(0, flag); + ForegroundOptions options; + options.sceneFlag = flag; + abilityRecord->ProcessForegroundAbility(0, options); return ERR_OK; } diff --git a/services/abilitymgr/src/process_options.cpp b/services/abilitymgr/src/process_options.cpp index 353d89fec46777bcddbc79ed2e65216e536d1976..853cef24663fd74419164d93ad3ab54cfb60c1bd 100644 --- a/services/abilitymgr/src/process_options.cpp +++ b/services/abilitymgr/src/process_options.cpp @@ -27,7 +27,8 @@ bool ProcessOptions::ReadFromParcel(Parcel &parcel) isRestartKeepAlive = parcel.ReadBool(); isStartFromNDK = parcel.ReadBool(); isPreloadStart = parcel.ReadBool(); - shouldReturnPid = parcel.ReadBool(); + loadAbilityCallbackId = parcel.ReadUint64(); + callingPid = parcel.ReadInt32(); return true; } @@ -72,8 +73,12 @@ 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"); + if (!parcel.WriteUint64(loadAbilityCallbackId)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "loadAbilityCallbackId write failed"); + return false; + } + if (!parcel.WriteInt32(callingPid)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "callingPid 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 67acc910bd52becc0b1df8423a14b55a90e2af9b..48c3242431133f1c22f8a6bb566bdd0ec64d5711 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -203,7 +203,8 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp return ERR_OK; } - bool shouldReturnPid = sessionInfo->processOptions != nullptr && sessionInfo->processOptions->shouldReturnPid; + bool shouldReturnPid = + sessionInfo->processOptions != nullptr && sessionInfo->processOptions->loadAbilityCallbackId > 0; if (preloadStartCheck || shouldReturnPid) { TAG_LOGI(AAFwkTag::ABILITYMGR, "scb call, preloadStartCheck=%{public}d,shouldReturnPid=%{public}d", preloadStartCheck, shouldReturnPid); @@ -270,8 +271,12 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp if (abilityRequest.processOptions) { isStartupHide = abilityRequest.processOptions->startupVisibility == StartupVisibility::STARTUP_HIDE; } - sptr callback = GetLoadAbilityCallback(sessionInfo->requestId); - uiAbilityRecord->ProcessForegroundAbility(callerTokenId, sceneFlag, isShellCall, isStartupHide, callback); + ForegroundOptions options = { sceneFlag, isShellCall, isStartupHide }; + if (shouldReturnPid) { + options.callingPid = abilityRequest.processOptions->callingPid; + options.loadAbilityCallbackId = abilityRequest.processOptions->loadAbilityCallbackId; + } + uiAbilityRecord->ProcessForegroundAbility(callerTokenId, options); if (uiAbilityRecord->GetSpecifiedFlag().empty() && !sessionInfo->specifiedFlag.empty()) { TAG_LOGI(AAFwkTag::ABILITYMGR, "update specified: %{public}d--%{public}s", sessionInfo->requestId, sessionInfo->specifiedFlag.c_str()); @@ -281,18 +286,6 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp return ERR_OK; } -sptr UIAbilityLifecycleManager::GetLoadAbilityCallback(int32_t requestId) -{ - sptr callback = nullptr; - auto iter = loadAbilityCallbackMap_.find(requestId); - if (iter != loadAbilityCallbackMap_.end()) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "find loadability callback, requestId: %{public}d", requestId); - callback = iter->second; - loadAbilityCallbackMap_.erase(iter); - } - return callback; -} - std::shared_ptr UIAbilityLifecycleManager::GenerateAbilityRecord(AbilityRequest &abilityRequest, sptr sessionInfo, bool &isColdStart) { @@ -1431,8 +1424,7 @@ int UIAbilityLifecycleManager::CallAbilityLocked(const AbilityRequest &abilityRe return NotifySCBPendingActivation(sessionInfo, abilityRequest, errMsg); } uiAbilityRecord->SetPendingState(AbilityState::FOREGROUND); - sptr callback = GetLoadAbilityCallback(requestId); - uiAbilityRecord->ProcessForegroundAbility(sessionInfo->callingTokenId, 0, false, false, callback); + uiAbilityRecord->ProcessForegroundAbility(sessionInfo->callingTokenId); return NotifySCBPendingActivation(sessionInfo, abilityRequest, errMsg); } else { if ((persistentId != 0) && abilityRequest.want.GetBoolParam(IS_CALLING_FROM_DMS, false)) { @@ -1547,12 +1539,6 @@ sptr UIAbilityLifecycleManager::CreateSessionInfo(const AbilityRequ sessionInfo->callingTokenId = static_cast(abilityRequest.want.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, IPCSkeleton::GetCallingTokenID())); sessionInfo->instanceKey = abilityRequest.want.GetStringParam(Want::APP_INSTANCE_KEY); - if (abilityRequest.startOptions.loadAbilityCallback_ != nullptr) { - auto callback = iface_cast(abilityRequest.startOptions.loadAbilityCallback_); - if (callback != nullptr) { - loadAbilityCallbackMap_.emplace(requestId, callback); - } - } return sessionInfo; } @@ -4001,9 +3987,8 @@ bool UIAbilityLifecycleManager::HandleColdAcceptWantDone(const AAFwk::Want &want UpdateSpecifiedFlag(uiAbilityRecord, flag); uiAbilityRecord->SetSpecifiedFlag(flag); auto isShellCall = specifiedRequest.abilityRequest.want.GetBoolParam(IS_SHELL_CALL, false); - sptr callback = GetLoadAbilityCallback(specifiedRequest.requestId); - uiAbilityRecord->ProcessForegroundAbility(specifiedRequest.callingTokenId, - specifiedRequest.sceneFlag, isShellCall, callback); + ForegroundOptions options = { specifiedRequest.sceneFlag, isShellCall }; + uiAbilityRecord->ProcessForegroundAbility(specifiedRequest.callingTokenId, options); SendKeyEvent(specifiedRequest.abilityRequest); return true; } diff --git a/services/abilitymgr/src/start_options.cpp b/services/abilitymgr/src/start_options.cpp index ece65b195d5e1e6ed838cd936395448753c223a6..33e384b97e41bb3d88874e303c6922c2b9b3a094 100644 --- a/services/abilitymgr/src/start_options.cpp +++ b/services/abilitymgr/src/start_options.cpp @@ -52,7 +52,6 @@ StartOptions::StartOptions(const StartOptions &other) supportWindowModes_ = other.supportWindowModes_; requestId_ = other.requestId_; windowCreateParams_ = other.windowCreateParams_; - loadAbilityCallback_ = other.loadAbilityCallback_; } StartOptions &StartOptions::operator=(const StartOptions &other) @@ -84,7 +83,6 @@ StartOptions &StartOptions::operator=(const StartOptions &other) supportWindowModes_ = other.supportWindowModes_; requestId_ = other.requestId_; windowCreateParams_ = other.windowCreateParams_; - loadAbilityCallback_ = other.loadAbilityCallback_; } return *this; } diff --git a/services/abilitymgr/src/utils/start_options_utils.cpp b/services/abilitymgr/src/utils/start_options_utils.cpp index 5b18907d6e96729c7d58fb19e0966ca9ba44c418..d6df8c5c0a926f28a40de43f54c3b2ab21f555b1 100644 --- a/services/abilitymgr/src/utils/start_options_utils.cpp +++ b/services/abilitymgr/src/utils/start_options_utils.cpp @@ -113,7 +113,7 @@ int32_t StartOptionsUtils::CheckStartSelfUIAbilityStartOptions(const Want &want, ERR_CAPABILITY_NOT_SUPPORT, "not support process options"); if (options.processOptions->startupVisibility == StartupVisibility::UNSPECIFIED && - options.processOptions->shouldReturnPid) { + options.processOptions->loadAbilityCallbackId > 0) { return ERR_OK; } diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index b1394ec0722813a0827c62b88e968fc54f9c7e81..94a773aa050a6b320bb6aa706eedb7b43878569d 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -49,12 +49,19 @@ public: * @param abilityInfo, the ability information. * @param appInfo, the app information. * @param want, the starting information. - * @param callback, the callback to get process id. */ virtual void LoadAbility(const std::shared_ptr &abilityInfo, - const std::shared_ptr &appInfo, - const std::shared_ptr &want, std::shared_ptr loadParam, - sptr callback = nullptr) override; + const std::shared_ptr &appInfo, const std::shared_ptr &want, + std::shared_ptr loadParam) override; + + /** + * notify load ability finished. + * + * @param callingPid, the pid of the caller. + * @param targetPid, the pid of the target ability. + * @param callbackId, the id of the callback. + */ + virtual void NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId) 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 19af2a59a135a675008b89194bd4339f6b39c4dd..1393166d5a7b37973803c6ded05a9716ca6132d4 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -62,7 +62,6 @@ #include "iapp_state_callback.h" #include "iapplication_state_observer.h" #include "iconfiguration_observer.h" -#include "iload_ability_callback.h" #include "iremote_object.h" #include "irender_state_observer.h" #include "istart_specified_ability_response.h" @@ -103,16 +102,19 @@ class WindowPidVisibilityChangedListener; using LoadAbilityTaskFunc = std::function; constexpr int32_t BASE_USER_RANGE = 200000; -struct LoadAbilityCallbackGuard { - sptr callback_ = nullptr; - std::shared_ptr appRecord_ = nullptr; - - LoadAbilityCallbackGuard(sptr callback) : callback_(callback) {} - ~LoadAbilityCallbackGuard(); -}; - class AppMgrServiceInner : public std::enable_shared_from_this { public: + struct LoadAbilityCallbackGuard { + uint64_t callbackId_ = 0; + pid_t callingPid_ = -1; + pid_t targetPid_ = -1; + std::shared_ptr appRecord_ = nullptr; + std::weak_ptr serviceInner_; + + LoadAbilityCallbackGuard(uint64_t callbackId, pid_t callingPid, std::weak_ptr serviceInner) + : callbackId_(callbackId), callingPid_(callingPid), serviceInner_(serviceInner) {} + ~LoadAbilityCallbackGuard(); + }; struct ConfigurationObserverWithUserId { sptr observer; int32_t userId = -1; @@ -137,13 +139,20 @@ public: * @param abilityInfo, the ability information. * @param appInfo, the app information. * @param want the ability want. - * @param callback, the callback to get process id. * * @return */ virtual void LoadAbility(std::shared_ptr abilityInfo, std::shared_ptr appInfo, - std::shared_ptr want, std::shared_ptr loadParam, - sptr callback = nullptr); + std::shared_ptr want, std::shared_ptr loadParam); + + /** + * notify load ability finished. + * + * @param callingPid, the pid of the caller. + * @param targetPid, the pid of the target ability. + * @param callbackId, the id of the callback. + */ + virtual void NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId); /** * TerminateAbility, terminate the token ability. diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 1e4a68c9f046baf65524c2af87ec54752ef6d226..fec4b2d7d107d7d0bdc59ac93c5099fcb9ab4d4d 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -44,6 +44,7 @@ constexpr const char* TASK_KILL_PROCESSES_BY_USERID = "KillProcessesByUserIdTask constexpr const char* TASK_ATTACH_PID_TO_PARENT = "AttachPidToParent"; constexpr const char* TASK_KILL_APPLICATION = "KillApplicationTask"; constexpr const char* TASK_CLEAR_PROCESS_BY_ABILITY_TOKEN = "ClearProcessByAbilityTokenTask"; +constexpr const char* TASK_NOTIFY_LOAD_ABILITY_FINISHED = "NotifyLoadAbilityFinished"; constexpr const char* FOUNDATION_NAME = "foundation"; constexpr const char* SCENE_BOARD_BUNDLE_NAME = "com.ohos.sceneboard"; constexpr const char* SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility"; @@ -67,9 +68,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, - sptr callback) + const std::shared_ptr &appInfo, const std::shared_ptr &want, + std::shared_ptr loadParam) { if (!abilityInfo || !appInfo) { TAG_LOGE(AAFwkTag::APPMGR, "param error"); @@ -88,8 +88,8 @@ void AmsMgrScheduler::LoadAbility(const std::shared_ptr &abilityInf TAG_LOGI(AAFwkTag::APPMGR, "SubmitLoadTask: %{public}s-%{public}s", abilityInfo->bundleName.c_str(), abilityInfo->name.c_str()); std::function loadAbilityFunc = [amsMgrServiceInner = amsMgrServiceInner_, - abilityInfo, appInfo, want, loadParam, callback]() { - amsMgrServiceInner->LoadAbility(abilityInfo, appInfo, want, loadParam, callback); + abilityInfo, appInfo, want, loadParam]() { + amsMgrServiceInner->LoadAbility(abilityInfo, appInfo, want, loadParam); }; // cache other application load ability task before scene board attach @@ -126,6 +126,26 @@ void AmsMgrScheduler::LoadAbility(const std::shared_ptr &abilityInf amsHandler_->SubmitTask(loadAbilityFunc, taskAttr); } +void AmsMgrScheduler::NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId) +{ + if (!IsReady()) { + return; + } + + if (!AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_NAME)) { + TAG_LOGE(AAFwkTag::APPMGR, "not foundation call"); + return; + } + std::function notifyFunc = [amsMgrServiceInner = amsMgrServiceInner_, callingPid, targetPid, + callbackId] () { + amsMgrServiceInner->NotifyLoadAbilityFinished(callingPid, targetPid, callbackId); + }; + amsHandler_->SubmitTask(notifyFunc, AAFwk::TaskAttribute{ + .taskName_ = TASK_NOTIFY_LOAD_ABILITY_FINISHED, + .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE + }); +} + void AmsMgrScheduler::UpdateAbilityState(const sptr &token, const AbilityState state) { if (!IsReady()) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 397e8d9ba389e3b5f82d8a8eb8039a472bd010f5..f88dce24bb7998ae915ac8ae2814945d528d6bd8 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -872,25 +872,45 @@ void AppMgrServiceInner::ReportEventToRSS(const AppExecFwk::AbilityInfo &ability }); } -LoadAbilityCallbackGuard::~LoadAbilityCallbackGuard() +AppMgrServiceInner::LoadAbilityCallbackGuard::~LoadAbilityCallbackGuard() { - if (callback_ == nullptr) { + if (callbackId_ == 0 || callingPid_ < 0) { return; } - if (appRecord_ == nullptr || appRecord_->GetPriorityObject() == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "loadability failed"); - callback_->OnFinish(-1); + auto serviceInner = serviceInner_.lock(); + CHECK_POINTER_AND_RETURN_LOG(serviceInner, "null serviceInner"); + int32_t resultPid = (appRecord_ == nullptr || appRecord_->GetPriorityObject() == nullptr) ? + targetPid_ : appRecord_->GetPriorityObject()->GetPid(); + TAG_LOGI(AAFwkTag::APPMGR, "loadability callback, callingPid: %{public}d, targetPid:%{public}d", + callingPid_, resultPid); + auto callingAppRecord = serviceInner->GetAppRunningRecordByPid(callingPid_); + if (callingAppRecord != nullptr) { + auto client = callingAppRecord->GetApplicationClient(); + CHECK_POINTER_AND_RETURN_LOG(client, "null application client"); + client->OnLoadAbilityFinished(callbackId_, resultPid); return; } - TAG_LOGI(AAFwkTag::APPMGR, "loadability callback, pid:%{public}d", appRecord_->GetPriorityObject()->GetPid()); - callback_->OnFinish(appRecord_->GetPriorityObject()->GetPid()); + CHECK_POINTER_AND_RETURN_LOG(serviceInner->appRunningManager_, "null appRunningManager"); + callingAppRecord = serviceInner->appRunningManager_->GetAppRunningRecordByChildProcessPid(callingPid_); + CHECK_POINTER_AND_RETURN_LOG(callingAppRecord, "null callingAppRecord"); + auto childAppRecord = callingAppRecord->GetChildProcessRecordByPid(callingPid_); + CHECK_POINTER_AND_RETURN_LOG(childAppRecord, "null childAppRecord"); + auto childScheduler = childAppRecord->GetScheduler(); + CHECK_POINTER_AND_RETURN_LOG(childScheduler, "null childScheduler"); + + TAG_LOGI(AAFwkTag::APPMGR, "loadability from child process"); + childScheduler->OnLoadAbilityFinished(callbackId_, resultPid); +} + +void AppMgrServiceInner::NotifyLoadAbilityFinished(pid_t callingPid, pid_t targetPid, uint64_t callbackId) +{ + LoadAbilityCallbackGuard guard(callbackId, callingPid, weak_from_this()); + guard.targetPid_ = targetPid; } void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, std::shared_ptr appInfo, - std::shared_ptr want, std::shared_ptr loadParam, - sptr callback) + std::shared_ptr want, std::shared_ptr loadParam) { - LoadAbilityCallbackGuard guard(callback); if (AAFwk::AppUtils::GetInstance().IsForbidStart()) { TAG_LOGW(AAFwkTag::APPMGR, "forbid start: %{public}s", abilityInfo ? abilityInfo->bundleName.c_str() : ""); return; @@ -900,6 +920,7 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s TAG_LOGE(AAFwkTag::APPMGR, "null loadParam"); return; } + LoadAbilityCallbackGuard guard(loadParam->loadAbilityCallbackId, loadParam->callingPid, weak_from_this()); if (!CheckLoadAbilityConditions(loadParam->token, abilityInfo, appInfo)) { TAG_LOGE(AAFwkTag::APPMGR, "checkLoadAbilityConditions fail"); return; diff --git a/test/fuzztest/abilityinterfacesappmgrchildschedulerstub_fuzzer/abilityinterfacesappmgrchildschedulerstub_fuzzer.cpp b/test/fuzztest/abilityinterfacesappmgrchildschedulerstub_fuzzer/abilityinterfacesappmgrchildschedulerstub_fuzzer.cpp index 668d6c657e04ee952e21b31ca5d578acfd78131d..33b3d87f019b7e2601f942bf36920f0a64d25ccd 100644 --- a/test/fuzztest/abilityinterfacesappmgrchildschedulerstub_fuzzer/abilityinterfacesappmgrchildschedulerstub_fuzzer.cpp +++ b/test/fuzztest/abilityinterfacesappmgrchildschedulerstub_fuzzer/abilityinterfacesappmgrchildschedulerstub_fuzzer.cpp @@ -46,6 +46,7 @@ public: bool ScheduleLoadChild() override{ return true; }; bool ScheduleExitProcessSafely() override{ return true; }; bool ScheduleRunNativeProc(const sptr &mainProcessCb) override{ return true; }; + void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) override {}; }; bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) diff --git a/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h b/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h index 7fba21931b8f9af848e3255f087ae0afd92f6fb7..bd772cbfae9e8656a34c689ceaa647b372f25461 100644 --- a/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h +++ b/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h @@ -30,9 +30,8 @@ public: virtual ~MockAppMgrServiceInner() {} - MOCK_METHOD5(LoadAbility, void(std::shared_ptr abilityInfo, std::shared_ptr appInfo, - std::shared_ptr want, std::shared_ptr loadParam, - sptr callback)); + MOCK_METHOD4(LoadAbility, void(std::shared_ptr abilityInfo, std::shared_ptr appInfo, + std::shared_ptr want, std::shared_ptr loadParam)); MOCK_METHOD2(AttachApplication, void(const pid_t pid, const sptr& app)); MOCK_METHOD1(ApplicationForegrounded, void(const int32_t recordId)); MOCK_METHOD1(ApplicationBackgrounded, void(const int32_t recordId)); 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 fb71b1946ae22a9440b0f74252e7164741b76ca1..a0bb844a3cb7ee73dc8c5e1f00e5d37aba7dae34 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, sptr callback) + const AAFwk::Want &want, AbilityRuntime::LoadParam loadParam) { TAG_LOGI(AAFwkTag::TEST, "MockAppMgrClient LoadAbility enter."); token_ = loadParam.token; diff --git a/test/mock/services_abilitymgr_test/libs/aakit/src/mock_load_ability_callback.cpp b/test/mock/services_abilitymgr_test/libs/aakit/src/mock_load_ability_callback.cpp deleted file mode 100644 index e46a32efc3565cce3275fe594c329df45c78ffc2..0000000000000000000000000000000000000000 --- a/test/mock/services_abilitymgr_test/libs/aakit/src/mock_load_ability_callback.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "mock_load_ability_callback.h" -#include "hilog_tag_wrapper.h" - -namespace OHOS { -namespace AbilityRuntime { -void MockLoadAbilityCallback::OnFinish(int32_t __attribute__((unused)) pid) -{ - TAG_LOGD(AAFwkTag::TEST, "mock MockLoadAbilityCallback::OnFinish"); -} -} // namespace AAFwk -} // namespace OHOS 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 ec0d07af809b50274ed2e5cd3fe22c1b18f0fa19..25e8f2e6f963ee7c35e2053e82ec9bc69b072bb6 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,8 +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, - sptr callback) + const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want) { TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::LoadAbility()"); if (applicationInfo.bundleName.find("com.ix.First.Test") != std::string::npos) { diff --git a/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h b/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h index ced6f904f28699209e120de1c8a2629a638670c9..5a8c6a0b8477cb2a2a9517f813bd2a96685b4c82 100644 --- a/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h +++ b/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h @@ -26,10 +26,9 @@ struct LoadParam; namespace AppExecFwk { class MockAmsMgrScheduler : public AmsMgrStub { public: - MOCK_METHOD5(LoadAbility, + MOCK_METHOD4(LoadAbility, void(const std::shared_ptr& abilityInfo, const std::shared_ptr& appInfo, - const std::shared_ptr& want, std::shared_ptr loadParam, - sptr callback)); + const std::shared_ptr& want, std::shared_ptr loadParam)); MOCK_METHOD2(TerminateAbility, void(const sptr& token, bool clearMissionFlag)); MOCK_METHOD2(UpdateAbilityState, void(const sptr& token, const AbilityState state)); MOCK_METHOD0(Reset, void()); diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h index b9362eda98d9dd329ed27af7ed9cf79040a89e05..8568cb7de196733aad3c9b6ec890f5bb34c1d92b 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h @@ -32,9 +32,8 @@ public: virtual ~MockAppMgrServiceInner() {} - MOCK_METHOD5(LoadAbility, void(std::shared_ptr abilityInfo, std::shared_ptr appInfo, - std::shared_ptr want, std::shared_ptr loadParam, - sptr callback)); + MOCK_METHOD4(LoadAbility, void(std::shared_ptr abilityInfo, std::shared_ptr appInfo, + std::shared_ptr want, std::shared_ptr loadParam)); MOCK_METHOD2(AttachApplication, void(const pid_t pid, const sptr& app)); MOCK_METHOD1(ApplicationForegrounded, void(const int32_t recordId)); MOCK_METHOD1(ApplicationBackgrounded, void(const int32_t recordId)); diff --git a/test/mock/services_appmgr_test/include/mock_app_scheduler.h b/test/mock/services_appmgr_test/include/mock_app_scheduler.h index e61101bce048d73319f8fbec2c3d9f714da18663..714f128d20534a2d70a8354578fab9b0afdd6377 100644 --- a/test/mock/services_appmgr_test/include/mock_app_scheduler.h +++ b/test/mock/services_appmgr_test/include/mock_app_scheduler.h @@ -72,6 +72,7 @@ public: MOCK_METHOD0(ScheduleClearPageStack, void()); MOCK_METHOD0(IsMemorySizeSufficent, bool()); MOCK_METHOD0(ScheduleCacheProcess, void()); + MOCK_METHOD2(OnLoadAbilityFinished, void(uint64_t, int32_t)); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/services_appmgr_test/include/mock_application.h b/test/mock/services_appmgr_test/include/mock_application.h index 29de3437db069f2308b73ac397b754b6219baabc..a565a8c77203706d0897d86b3676f25b5eee34ce 100644 --- a/test/mock/services_appmgr_test/include/mock_application.h +++ b/test/mock/services_appmgr_test/include/mock_application.h @@ -66,6 +66,7 @@ public: MOCK_METHOD1(SetWatchdogBackgroundStatus, void(bool status)); MOCK_METHOD0(ScheduleClearPageStack, void()); MOCK_METHOD0(ScheduleCacheProcess, void()); + MOCK_METHOD2(OnLoadAbilityFinished, void(uint64_t, int32_t)); void Post() { diff --git a/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp b/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp index 9b53ebd5c20ed530d734580218b51101c4189cda..2165807865d82f19d5fc8258d4f319fd4820942f 100644 --- a/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp +++ b/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp @@ -368,7 +368,7 @@ HWTEST_F(AbilityManagerClientTest, StartSelfUIAbilityWithPidResult_0100, TestSiz TAG_LOGI(AAFwkTag::TEST, "StartSelfUIAbilityWithPidResult_0100 start"); AAFwk::Want want; AAFwk::StartOptions options; - auto result = AbilityManagerClient::GetInstance()->StartSelfUIAbilityWithPidResult(want, options, nullptr); + auto result = AbilityManagerClient::GetInstance()->StartSelfUIAbilityWithPidResult(want, options, 12345); sptr token_(new IPCObjectStub()); AbilityManagerClient::GetInstance()->SubmitSaveRecoveryInfo(token_); EXPECT_EQ(result, ERR_OK); diff --git a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp index 7755e7050401495f9265959707c88ae97419e060..cf03997ef0ce5d3b29bde6afd1188c3b78e8cc89 100644 --- a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp +++ b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp @@ -223,6 +223,9 @@ public: void ScheduleClearPageStack() override {} + void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) override + {} + private: int abilityLaunchTime = 0; int appLaunchTime = 0; diff --git a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp index a4c56e83567a70177e7bd6894c5d90ddeb4f1570..b9e3b21acdaead2fee76dc90b64e7809cda9e8e4 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp +++ b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp @@ -144,6 +144,9 @@ public: void ScheduleClearPageStack() override {} + + void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) override + {} }; class AppMgrServiceModuleTest : public testing::Test { public: diff --git a/test/moduletest/mock/include/mock_app_mgr_client.h b/test/moduletest/mock/include/mock_app_mgr_client.h index 56b2f0e75007149543fb55e280ce5dd81551c36b..04408b97aa3a2c2832dfbf84e817b03d673d0925 100644 --- a/test/moduletest/mock/include/mock_app_mgr_client.h +++ b/test/moduletest/mock/include/mock_app_mgr_client.h @@ -26,8 +26,8 @@ class MockAppMgrClient : public AppMgrClient { public: MockAppMgrClient(); ~MockAppMgrClient(); - MOCK_METHOD5(LoadAbility, AppMgrResultCode(const AbilityInfo&, const ApplicationInfo&, - const AAFwk::Want&, AbilityRuntime::LoadParam, sptr)); + MOCK_METHOD4(LoadAbility, AppMgrResultCode(const AbilityInfo&, const ApplicationInfo&, + const AAFwk::Want&, AbilityRuntime::LoadParam)); MOCK_METHOD2(TerminateAbility, AppMgrResultCode(const sptr&, bool)); MOCK_METHOD2(UpdateAbilityState, AppMgrResultCode(const sptr& token, const AbilityState state)); MOCK_METHOD3(KillApplication, AppMgrResultCode(const std::string&, const bool clearPageStack, int32_t)); diff --git a/test/moduletest/mock/include/mock_app_scheduler.h b/test/moduletest/mock/include/mock_app_scheduler.h index 325e983f2f6b563e3727dbe7d767ab538e7444bd..5d78540f5a919113b5411d898e8d6015d944f9e5 100644 --- a/test/moduletest/mock/include/mock_app_scheduler.h +++ b/test/moduletest/mock/include/mock_app_scheduler.h @@ -54,6 +54,7 @@ public: MOCK_METHOD1(ScheduleJsHeapMemory, void(OHOS::AppExecFwk::JsHeapDumpInfo &info)); MOCK_METHOD1(ScheduleCjHeapMemory, void(OHOS::AppExecFwk::CjHeapDumpInfo &info)); MOCK_METHOD1(SetWatchdogBackgroundStatus, void(bool status)); + MOCK_METHOD2(OnLoadAbilityFinished, void(uint64_t, int32_t)); }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_proxy_third_test/BUILD.gn b/test/unittest/ability_manager_proxy_third_test/BUILD.gn index 0b46fba2e80d47358616ae3eabf7c34e09287dc9..0d9b9756c8a623a17c37adea9681274d066ca367 100644 --- a/test/unittest/ability_manager_proxy_third_test/BUILD.gn +++ b/test/unittest/ability_manager_proxy_third_test/BUILD.gn @@ -30,7 +30,6 @@ ohos_unittest("ability_manager_proxy_third_test") { sources = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", - "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/src/mock_load_ability_callback.cpp", "ability_manager_proxy_third_test.cpp", ] diff --git a/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp b/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp index 386a6f2e486655347c8cdfb1dec27d926b8072bb..1d5e1d381b1c199aa6c41609ec6dc6df4e11271f 100644 --- a/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp +++ b/test/unittest/ability_manager_proxy_third_test/ability_manager_proxy_third_test.cpp @@ -27,7 +27,6 @@ #include "mission_snapshot.h" #include "mock_ability_connect_callback.h" #include "mock_ability_token.h" -#include "mock_load_ability_callback.h" #include "want_sender_info.h" using namespace testing::ext; @@ -230,8 +229,7 @@ HWTEST_F(AbilityManagerProxyTest, StartSelfUIAbilityWithPidResult_0100, TestSize .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeErrorSendRequest)); Want want; StartOptions options; - sptr callback = sptr::MakeSptr(); - int32_t result = proxy_->StartSelfUIAbilityWithPidResult(want, options, callback); + int32_t result = proxy_->StartSelfUIAbilityWithPidResult(want, options, 123456); EXPECT_EQ( static_cast(AbilityManagerInterfaceCode::START_SELF_UI_ABILITY_WITH_PID_RESULT), mock_->code_); EXPECT_NE(result, NO_ERROR); @@ -239,7 +237,7 @@ HWTEST_F(AbilityManagerProxyTest, StartSelfUIAbilityWithPidResult_0100, TestSize EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); - result = proxy_->StartSelfUIAbilityWithPidResult(want, options, callback); + result = proxy_->StartSelfUIAbilityWithPidResult(want, options, 123456); EXPECT_EQ( static_cast(AbilityManagerInterfaceCode::START_SELF_UI_ABILITY_WITH_PID_RESULT), mock_->code_); EXPECT_EQ(result, NO_ERROR); 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 595af525aa42f777ce71c5f14bec0fec43a4aa37..4cd1d79d82fc22e7cfed417b496ffae5f62ae59e 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 @@ -295,7 +295,7 @@ void AbilityRecord::LoadUIAbility() g_addLifecycleEventTask(token_, methodName); } -int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, sptr callback) +int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, pid_t callingPid, uint64_t callbackId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "LoadLifecycle: abilityName:%{public}s", abilityInfo_.name.c_str()); @@ -366,9 +366,7 @@ void AbilityRecord::ForegroundUIExtensionAbility(uint32_t sceneFlag) { } -void AbilityRecord::ProcessForegroundAbility( - uint32_t tokenId, uint32_t sceneFlag, bool isShellCall, bool isStartupHide, - sptr callback) +void AbilityRecord::ProcessForegroundAbility(uint32_t tokenId, const ForegroundOptions &options) { } 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 06c4b5ffa561f18b978ca022a13f0bfca2e7af65..0c108d1ad8505e5308c6c856c6d5a32401a00427 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 @@ -307,7 +307,7 @@ void AbilityRecord::LoadUIAbility() g_addLifecycleEventTask(token_, methodName); } -int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, sptr callback) +int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, pid_t callingPid, uint64_t callbackId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "LoadLifecycle: abilityName:%{public}s", abilityInfo_.name.c_str()); @@ -378,9 +378,7 @@ void AbilityRecord::ForegroundUIExtensionAbility(uint32_t sceneFlag) { } -void AbilityRecord::ProcessForegroundAbility( - uint32_t tokenId, uint32_t sceneFlag, bool isShellCall, bool isStartupHide, - sptr callback) +void AbilityRecord::ProcessForegroundAbility(uint32_t tokenId, const ForegroundOptions &options) { } diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp index 91ad5f80fef12b38201cd23730d922cd6b94f274..44f449932ec4f4ef8b1b0b46278da1423096eeb2 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_scheduler.cpp @@ -41,8 +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, - sptr callback) + const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want) { TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::LoadAbility()"); if (applicationInfo.bundleName.find("com.ix.First.Test") != std::string::npos) { 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 66d8c840d5b2f9720f1d96c8f0d65c425a9ee99b..2c3558700742b361fcbc4985a5667e0029d1a36e 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,8 +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, - sptr callback) + const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want) { 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_mgr_client_test/ams_app_mgr_client_test.cpp b/test/unittest/ams_app_mgr_client_test/ams_app_mgr_client_test.cpp index 8be1d3bd1576527710911d502242cd513e5c0f78..0a127051166fe3d31a6c72a24b70f7e8536704ef 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()) 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 4c967563353711db2d6ca5f7d1c8cdbc46094a93..05f2d875821c3235f608c2f1b644b7c3417496e9 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,7 +114,7 @@ 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(); @@ -150,7 +150,7 @@ 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(); @@ -158,7 +158,7 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_002, TestSize.Level1) amsMgrScheduler->LoadAbility(nullptr, applicationInfo, nullptr, loadParamPtr); // check pretoken parameter - EXPECT_CALL(*mockAppMgrServiceInner, LoadAbility(_, _, _, _, _)).Times(0); + EXPECT_CALL(*mockAppMgrServiceInner, LoadAbility(_, _, _, _)).Times(0); amsMgrScheduler->LoadAbility(abilityInfo, nullptr, nullptr, loadParamPtr); TAG_LOGD(AAFwkTag::TEST, "AmsMgrScheduler_002 end."); 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 923313941a64b770d082188b4cc5851e80e19bf1..4a27fcc3775f91130c2a15ee3a8e2620bf918f6b 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,8 +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, - sptr callback) + const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want) { 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_eighth_test/app_mgr_service_inner_eighth_test.cpp b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp index cdc642e7683f3f3af7def6a00632b0c2d4dbb597..bff8e6210941933c511b062e9d779a09de67422e 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp @@ -91,6 +91,8 @@ public: { return nullptr; } + void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) override + {} }; class MyRenderScheduler : public IRenderScheduler { public: diff --git a/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_app_scheduler.h b/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_app_scheduler.h index d801ce602092030f6b651004010b4c3c958f6c45..9e251bcbc50b088e44c4908c989d0d186f9b99cd 100644 --- a/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_app_scheduler.h +++ b/test/unittest/app_mgr_service_inner_ninth_test/mock/include/mock_app_scheduler.h @@ -73,6 +73,7 @@ public: MOCK_METHOD1(VerifyKillProcessPermission, int32_t(const std::string &bundleName)); MOCK_METHOD0(ScheduleCacheProcess, void()); MOCK_METHOD1(ScheduleCjHeapMemory, void(OHOS::AppExecFwk::CjHeapDumpInfo &info)); + MOCK_METHOD2(OnLoadAbilityFinished, void(uint64_t, int32_t)); bool AddDeathRecipient(const sptr &recipient) override { diff --git a/test/unittest/app_running_manager_third_test/app_running_manager_third_test.cpp b/test/unittest/app_running_manager_third_test/app_running_manager_third_test.cpp index 88cf4c5cec3d7bf054e2d22cd0126d333afc0e26..04eb74b9ca63e63094a7a66298afd7189e69fbee 100644 --- a/test/unittest/app_running_manager_third_test/app_running_manager_third_test.cpp +++ b/test/unittest/app_running_manager_third_test/app_running_manager_third_test.cpp @@ -109,6 +109,8 @@ public: { return nullptr; } + void OnLoadAbilityFinished(uint64_t callbackId, int32_t pid) override + {} }; /** diff --git a/test/unittest/app_scheduler_test/app_mgr_client_mock.h b/test/unittest/app_scheduler_test/app_mgr_client_mock.h index fdf2fcfbbf4ba086da6479764c9bc540a30b7e3c..584e3821021fa557f54275b5e4783f10ec526dc3 100755 --- a/test/unittest/app_scheduler_test/app_mgr_client_mock.h +++ b/test/unittest/app_scheduler_test/app_mgr_client_mock.h @@ -31,8 +31,8 @@ public: {} MOCK_METHOD0(ConnectAppMgrService, AppMgrResultCode()); MOCK_METHOD1(RegisterAppStateCallback, AppMgrResultCode(const sptr &callback)); - MOCK_METHOD5(LoadAbility, AppMgrResultCode(const AbilityInfo&, const ApplicationInfo&, - const AAFwk::Want&, AbilityRuntime::LoadParam, sptr)); + MOCK_METHOD4(LoadAbility, AppMgrResultCode(const AbilityInfo&, const ApplicationInfo&, + const AAFwk::Want&, AbilityRuntime::LoadParam)); MOCK_METHOD2(TerminateAbility, AppMgrResultCode(const sptr&, bool)); MOCK_METHOD2(UpdateExtensionState, AppMgrResultCode(const sptr &token, const ExtensionState state)); MOCK_METHOD4(UpdateApplicationInfoInstalled, AppMgrResultCode(const std::string &bundleName, const int uid, diff --git a/test/unittest/app_scheduler_test/app_scheduler_test.cpp b/test/unittest/app_scheduler_test/app_scheduler_test.cpp index 3a05eac8ee06f93f0e1051df9b63195236340f2b..688148b6ca67f888d8b0df1dcd8c0e6ffd3fe50f 100644 --- a/test/unittest/app_scheduler_test/app_scheduler_test.cpp +++ b/test/unittest/app_scheduler_test/app_scheduler_test.cpp @@ -248,7 +248,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; diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp index 9fc866572d4696cb6c0c8523136c6c63fed240a8..4d3f5ddbb9d093ab0ba529fcaa551636f56b8d52 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_ability_manager_client.cpp @@ -1044,7 +1044,7 @@ ErrCode AbilityManagerClient::StartSelfUIAbilityWithStartOptions(const Want &wan } int AbilityManagerClient::StartSelfUIAbilityWithPidResult(const Want &want, StartOptions &options, - sptr callback) + uint64_t callbackId) { return ERR_OK; } diff --git a/test/unittest/start_options_utils_test/start_options_utils_test.cpp b/test/unittest/start_options_utils_test/start_options_utils_test.cpp index 1fc7be076deea86c77017465e5e0c61a98facf73..82bec1870dc2492a3bf63c88bafa8858f492529a 100644 --- a/test/unittest/start_options_utils_test/start_options_utils_test.cpp +++ b/test/unittest/start_options_utils_test/start_options_utils_test.cpp @@ -261,7 +261,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckStartSelfUIAbilityStartOptions_007, TestSiz StartOptions startOptions; startOptions.processOptions = std::make_shared(); startOptions.processOptions->startupVisibility = StartupVisibility::UNSPECIFIED; - startOptions.processOptions->shouldReturnPid = true; + startOptions.processOptions->loadAbilityCallbackId = 12345; auto ret = StartOptionsUtils::CheckStartSelfUIAbilityStartOptions(want, startOptions); EXPECT_EQ(ret, ERR_OK); diff --git a/utils/server/startup/include/param.h b/utils/server/startup/include/param.h index b553ecbe8a4873f19f365116d4a3046411640910..f8e2d011fe43e8357ddbec2101f1264d3c8ce9a1 100644 --- a/utils/server/startup/include/param.h +++ b/utils/server/startup/include/param.h @@ -54,6 +54,8 @@ struct LoadParam : public Parcelable { uint32_t extensionProcessMode = 0; ExtensionLoadParam extensionLoadParam; bool isStartupHide = false; + pid_t callingPid = -1; + uint64_t loadAbilityCallbackId = 0; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/utils/server/startup/src/param.cpp b/utils/server/startup/src/param.cpp index 9836f70cc65f827f4ba179aadb4db5b142103101..580ecb7522927a43b43eb5b9752049644cd83248 100644 --- a/utils/server/startup/src/param.cpp +++ b/utils/server/startup/src/param.cpp @@ -74,6 +74,12 @@ bool LoadParam::MarshallingTwo(Parcel &parcel) const if (!parcel.WriteBool(isMainElementRunning)) { return false; } + if (!parcel.WriteInt32(callingPid)) { + return false; + } + if (!parcel.WriteUint64(loadAbilityCallbackId)) { + return false; + } return true; } @@ -104,6 +110,8 @@ bool LoadParam::ReadFromParcel(Parcel &parcel) extensionLoadParam = *extensionParamRead; isStartupHide = parcel.ReadBool(); isMainElementRunning = parcel.ReadBool(); + callingPid = parcel.ReadInt32(); + loadAbilityCallbackId = parcel.ReadUint64(); return true; }