From b735118ba32a7b79b7d8d35c8bfb946edd0317aa Mon Sep 17 00:00:00 2001 From: xujie Date: Wed, 7 Jun 2023 14:52:20 +0800 Subject: [PATCH 01/52] =?UTF-8?q?=E4=BF=AE=E6=94=B9dnsproxyd=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xujie --- services/appmgr/src/app_mgr_service_inner.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 8e3030476d..bf7ffba7b0 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -126,7 +126,9 @@ const std::string PROCESS_EXIT_EVENT_TASK = "Send Process Exit Event Task"; constexpr int32_t ROOT_UID = 0; constexpr int32_t FOUNDATION_UID = 5523; constexpr int32_t DEFAULT_USER_ID = 0; - +#ifdef APP_MGR_SERVICE_APPMS +constexpr int32_t NETSYS_SOCKET_GROUPID = 1097; +#endif int32_t GetUserIdByUid(int32_t uid) { return uid / BASE_USER_RANGE; @@ -1732,6 +1734,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str } else { auto ret = SetInternetPermission(bundleInfo.uid, 1); HILOG_DEBUG("SetInternetPermission, ret = %{public}d", ret); + bundleInfo.gids.push_back(NETSYS_SOCKET_GROUPID); #endif } @@ -1747,6 +1750,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str AppSpawnStartMsg startMsg; startMsg.uid = bundleInfo.uid; startMsg.gid = bundleInfo.gid; + startMsg.gids = bundleInfo.gids; startMsg.accessTokenId = bundleInfo.applicationInfo.accessTokenId; startMsg.apl = bundleInfo.applicationInfo.appPrivilegeLevel; startMsg.bundleName = bundleName; From 8a0524487e2224d17e87b513471fb53e7200e127 Mon Sep 17 00:00:00 2001 From: handf0830 Date: Thu, 8 Jun 2023 20:51:13 +0800 Subject: [PATCH 02/52] use local variable Signed-off-by: handf0830 --- services/appmgr/src/app_mgr_service_inner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index bf7ffba7b0..46b385dbf4 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -1721,6 +1721,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str uint8_t setAllowInternet = 0; uint8_t allowInternet = 1; auto token = bundleInfo.applicationInfo.accessTokenId; + std::vector gids; { // Add TRACE HITRACE_METER_NAME(HITRACE_TAG_APP, "AccessTokenKit::VerifyAccessToken"); @@ -1734,7 +1735,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str } else { auto ret = SetInternetPermission(bundleInfo.uid, 1); HILOG_DEBUG("SetInternetPermission, ret = %{public}d", ret); - bundleInfo.gids.push_back(NETSYS_SOCKET_GROUPID); + gids.push_back(NETSYS_SOCKET_GROUPID); #endif } @@ -1750,7 +1751,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str AppSpawnStartMsg startMsg; startMsg.uid = bundleInfo.uid; startMsg.gid = bundleInfo.gid; - startMsg.gids = bundleInfo.gids; + startMsg.gids = gids; startMsg.accessTokenId = bundleInfo.applicationInfo.accessTokenId; startMsg.apl = bundleInfo.applicationInfo.appPrivilegeLevel; startMsg.bundleName = bundleName; From 42ffc9f5e515c8a934864692e64051722e93c49d Mon Sep 17 00:00:00 2001 From: xinking129 Date: Wed, 21 Jun 2023 17:42:23 +0800 Subject: [PATCH 03/52] add code about dot Signed-off-by: xinking129 --- .../napi/ability_context/ability_context.js | 4 ++ .../ability_runtime/ability_context_impl.cpp | 6 +++ .../ability_runtime/js_ability_context.cpp | 38 +++++++++++++++++++ hisysevent.yaml | 10 ++++- .../include/ability_manager_client.h | 2 + .../include/ability_manager_interface.h | 14 ++++--- .../ability/ability_runtime/ability_context.h | 7 ++++ .../ability_runtime/ability_context_impl.h | 2 + .../ability_runtime/js_ability_context.h | 2 + .../include/ability_manager_proxy.h | 2 + .../include/ability_manager_service.h | 2 + .../abilitymgr/include/ability_manager_stub.h | 1 + .../abilitymgr/src/ability_manager_client.cpp | 8 ++++ .../abilitymgr/src/ability_manager_proxy.cpp | 33 ++++++++++++++++ .../src/ability_manager_service.cpp | 25 ++++++++++++ .../abilitymgr/src/ability_manager_stub.cpp | 18 +++++++++ services/common/include/event_report.h | 1 + services/common/src/event_report.cpp | 12 ++++++ .../AMS/mock_serviceability_manager_service.h | 4 ++ .../include/mock_ability_manager_service.h | 5 +++ .../mock_ability_delegator_stub.cpp | 12 +++++- .../mock_ability_delegator_stub.h | 2 + .../AMS/mock_ability_manager_service.h | 5 +++ .../AMS/mock_serviceability_manager_service.h | 4 ++ .../mock/include/mock_ability_mgr_service.h | 5 +++ .../ability_manager_stub_mock_test.h | 5 +++ .../ability_manager_stub_mock.h | 5 +++ .../ability_manager_stub_impl_mock.h | 5 +++ .../ability_manager_stub_mock.h | 5 +++ .../ability_manager_stub_mock.h | 5 +++ .../mock_ability_manager_service.h | 5 +++ tools/test/mock/mock_ability_manager_stub.h | 5 +++ 32 files changed, 252 insertions(+), 7 deletions(-) diff --git a/frameworks/js/napi/ability_context/ability_context.js b/frameworks/js/napi/ability_context/ability_context.js index 54b3b92df7..10dd62a09b 100644 --- a/frameworks/js/napi/ability_context/ability_context.js +++ b/frameworks/js/napi/ability_context/ability_context.js @@ -174,6 +174,10 @@ class AbilityContext extends Context { requestDialogService(want, resultCallback) { return this.__context_impl__.requestDialogService(want, resultCallback); } + + reportDrawnCompleted(callback) { + return this.__context_impl__.reportDrawnCompleted(callback); + } } export default AbilityContext; diff --git a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp index f62efd33a2..3d998864ac 100644 --- a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp +++ b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp @@ -563,6 +563,12 @@ ErrCode AbilityContextImpl::RequestDialogService(NativeEngine &engine, return err; } +ErrCode AbilityContextImpl::ReportDrawnCompleted() +{ + HILOG_DEBUG("called."); + return AAFwk::AbilityManagerClient::GetInstance()->ReportDrawnCompleted(token_); +} + void AbilityContextImpl::RequestDialogResultJSThreadWorker(uv_work_t* work, int status) { HILOG_DEBUG("RequestDialogResultJSThreadWorker"); diff --git a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp index 7c963e729d..a511223ebd 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp @@ -179,6 +179,12 @@ NativeValue* JsAbilityContext::RequestDialogService(NativeEngine* engine, Native return (me != nullptr) ? me->OnRequestDialogService(*engine, *info) : nullptr; } +NativeValue* JsAbilityContext::ReportDrawnCompleted(NativeEngine* engine, NativeCallbackInfo* info) +{ + JsAbilityContext* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnReportDrawnCompleted(*engine, *info) : nullptr; +} + NativeValue* JsAbilityContext::IsTerminating(NativeEngine* engine, NativeCallbackInfo* info) { JsAbilityContext* me = CheckParamsAndGetThis(engine, info); @@ -1179,6 +1185,36 @@ NativeValue* JsAbilityContext::OnIsTerminating(NativeEngine& engine, NativeCallb return engine.CreateBoolean(context->IsTerminating()); } +NativeValue* JsAbilityContext::OnReportDrawnCompleted(NativeEngine& engine, NativeCallbackInfo& info) +{ + HILOG_DEBUG("called."); + auto innerErrorCode = std::make_shared(ERR_OK); + AsyncTask::ExecuteCallback execute = [weak = context_, innerErrorCode]() { + auto context = weak.lock(); + if (!context) { + HILOG_WARN("context is released"); + *innerErrorCode = static_cast(AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT); + return; + } + + *innerErrorCode = context->ReportDrawnCompleted(); + }; + + AsyncTask::CompleteCallback complete = [innerErrorCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (*innerErrorCode == ERR_OK) { + task.Resolve(engine, engine.CreateUndefined()); + } else { + task.Reject(engine, CreateJsErrorByNativeErr(engine, *innerErrorCode)); + } + }; + + NativeValue* lastParam = info.argv[ARGC_ZERO]; + NativeValue* result = nullptr; + AsyncTask::Schedule("JsAbilityContext::OnReportDrawnCompleted", + engine, CreateAsyncTaskWithLastParam(engine, lastParam, std::move(execute), std::move(complete), &result)); + return result; +} + bool JsAbilityContext::UnWrapWant(NativeEngine& engine, NativeValue* argv, AAFwk::Want& want) { if (argv == nullptr) { @@ -1376,6 +1412,8 @@ NativeValue* CreateJsAbilityContext(NativeEngine& engine, std::shared_ptr GetSessionManagerService(); + ErrCode ReportDrawnCompleted(const sptr &token); + private: class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient { public: 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 d22adfd350..f6597ea522 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -948,6 +948,13 @@ public: return 0; } + /** + * Report drawn completed. + * + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t ReportDrawnCompleted(const sptr &callerToken) = 0; + /** * Acquire the shared data. * @param missionId The missionId of Target ability. @@ -1326,11 +1333,8 @@ public: // ipc id for request dialog service REQUEST_DIALOG_SERVICE, - // ipc id for start specified ability by scb - START_SPECIFIED_ABILITY_BY_SCB, - - // ipc id for set sessionManagerService - SET_SESSIONMANAGERSERVICE, + // ipc id for report drawn completed + REPORT_DRAWN_COMPLETED, GET_SESSIONMANAGERSERVICE, diff --git a/interfaces/kits/native/ability/ability_runtime/ability_context.h b/interfaces/kits/native/ability/ability_runtime/ability_context.h index de762a914b..27e1d94340 100644 --- a/interfaces/kits/native/ability/ability_runtime/ability_context.h +++ b/interfaces/kits/native/ability/ability_runtime/ability_context.h @@ -266,6 +266,13 @@ public: */ virtual ErrCode RequestDialogService(NativeEngine &engine, AAFwk::Want &want, RequestDialogResultTask &&task) = 0; + /** + * @brief Report drawn completed. + * + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode ReportDrawnCompleted() = 0; + virtual ErrCode GetMissionId(int32_t &missionId) = 0; #ifdef SUPPORT_GRAPHICS diff --git a/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h b/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h index 53e73f5d35..98284d9ce4 100644 --- a/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h +++ b/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h @@ -183,6 +183,8 @@ public: ErrCode RequestDialogService(NativeEngine &engine, AAFwk::Want &want, RequestDialogResultTask &&task) override; + ErrCode ReportDrawnCompleted() override; + ErrCode GetMissionId(int32_t &missionId) override; #ifdef SUPPORT_GRAPHICS diff --git a/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h b/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h index 3d34559fe1..46232df08c 100644 --- a/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h +++ b/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h @@ -58,6 +58,7 @@ public: static NativeValue* RestoreWindowStage(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* RequestDialogService(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* IsTerminating(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* ReportDrawnCompleted(NativeEngine* engine, NativeCallbackInfo* info); static void ConfigurationUpdated(NativeEngine* engine, std::shared_ptr &jsContext, const std::shared_ptr &config); @@ -98,6 +99,7 @@ private: NativeValue* OnRestoreWindowStage(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnRequestDialogService(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnIsTerminating(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnReportDrawnCompleted(NativeEngine& engine, NativeCallbackInfo& info); static bool UnWrapWant(NativeEngine& engine, NativeValue* argv, AAFwk::Want& want); static NativeValue* WrapWant(NativeEngine& engine, const AAFwk::Want& want); diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 8410e6970d..d852074b86 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -785,6 +785,8 @@ public: */ virtual int32_t RequestDialogService(const Want &want, const sptr &callerToken) override; + int32_t ReportDrawnCompleted(const sptr &callerToken) override; + virtual int32_t AcquireShareData( const int32_t &missionId, const sptr &shareData) override; virtual int32_t ShareDataDone(const sptr &token, diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index aafba99a75..bd0b310641 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1025,6 +1025,8 @@ public: virtual int32_t RequestDialogService(const Want &want, const sptr &callerToken) override; + int32_t ReportDrawnCompleted(const sptr &callerToken) override; + virtual int32_t AcquireShareData( const int32_t &missionId, const sptr &shareData) override; virtual int32_t ShareDataDone(const sptr& token, diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 5a273b453d..30730d91e0 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -216,6 +216,7 @@ private: int VerifyPermissionInner(MessageParcel &data, MessageParcel &reply); int HandleRequestDialogService(MessageParcel &data, MessageParcel &reply); + int32_t HandleReportDrawnCompleted(MessageParcel &data, MessageParcel &reply); int AcquireShareDataInner(MessageParcel &data, MessageParcel &reply); int ShareDataDoneInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 27c2dfe839..526e67b90a 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -760,6 +760,14 @@ ErrCode AbilityManagerClient::RequestDialogService( return abms->RequestDialogService(want, callerToken); } +ErrCode AbilityManagerClient::ReportDrawnCompleted(const sptr &callerToken) +{ + HILOG_DEBUG("called."); + auto abilityMgr = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abilityMgr); + return abilityMgr->ReportDrawnCompleted(callerToken); +} + /** * Start synchronizing remote device mission * @param devId, deviceId. diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 783ef1021a..94f462edb5 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -3998,6 +3998,39 @@ int32_t AbilityManagerProxy::RequestDialogService(const Want &want, const sptr &callerToken) +{ + HILOG_DEBUG("called."); + if (callerToken == nullptr) { + HILOG_ERROR("callerToken is nullptr"); + return INNER_ERR; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + + if (!data.WriteRemoteObject(callerToken)) { + HILOG_ERROR("callerToken write failed."); + return INNER_ERR; + } + + auto remote= Remote(); + if (remote == nullptr) { + HILOG_ERROR("remote is nullptr."); + return INNER_ERR; + } + auto error = remote->SendRequest(IAbilityManager::REPORT_DRAWN_COMPLETED, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} + int32_t AbilityManagerProxy::AcquireShareData( const int32_t &missionId, const sptr &shareData) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index c44973b457..723b464848 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -1006,6 +1006,31 @@ int32_t AbilityManagerService::RequestDialogService(const Want &want, const sptr return RequestDialogServiceInner(want, callerToken, -1, -1); } +int32_t AbilityManagerService::ReportDrawnCompleted(const sptr &callerToken) +{ + HILOG_DEBUG("called."); + if (callerToken == nullptr) { + HILOG_ERROR("callerToken is nullptr"); + return INNER_ERR; + } + + auto abilityRecord = Token::GetAbilityRecordByToken(callerToken); + if (abilityRecord == nullptr) { + HILOG_ERROR("abilityRecord is nullptr"); + return INNER_ERR; + } + auto abilityInfo = abilityRecord->GetAbilityInfo(); + + EventInfo eventInfo; + eventInfo.userId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; + eventInfo.pid = IPCSkeleton::GetCallingPid(); + eventInfo.bundleName = abilityInfo.bundleName; + eventInfo.moduleName = abilityInfo.moduleName; + eventInfo.abilityName = abilityInfo.name; + EventReport::SendAppEvent(EventName::DRAWN_COMPLETED, HiSysEventType::BEHAVIOR, eventInfo); + return ERR_OK; +} + int32_t AbilityManagerService::RequestDialogServiceInner(const Want &want, const sptr &callerToken, int requestCode, int32_t userId) { diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 759cfd76dc..25d6ec65e0 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -175,6 +175,7 @@ void AbilityManagerStub::ThirdStepInit() requestFuncMap_[PREPARE_TERMINATE_ABILITY] = &AbilityManagerStub::PrepareTerminateAbilityInner; #endif requestFuncMap_[REQUEST_DIALOG_SERVICE] = &AbilityManagerStub::HandleRequestDialogService; + requestFuncMap_[REPORT_DRAWN_COMPLETED] = &AbilityManagerStub::HandleReportDrawnCompleted; requestFuncMap_[SET_COMPONENT_INTERCEPTION] = &AbilityManagerStub::SetComponentInterceptionInner; requestFuncMap_[SEND_ABILITY_RESULT_BY_TOKEN] = &AbilityManagerStub::SendResultToAbilityByTokenInner; requestFuncMap_[QUERY_MISSION_VAILD] = &AbilityManagerStub::IsValidMissionIdsInner; @@ -1861,6 +1862,23 @@ int AbilityManagerStub::HandleRequestDialogService(MessageParcel &data, MessageP return NO_ERROR; } +int32_t AbilityManagerStub::HandleReportDrawnCompleted(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("called."); + sptr callerToken = data.ReadRemoteObject(); + if (callerToken == nullptr) { + HILOG_ERROR("callerToken is invalid."); + return ERR_INVALID_VALUE; + } + + auto result = ReportDrawnCompleted(callerToken); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("reply write failed."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int AbilityManagerStub::AcquireShareDataInner(MessageParcel &data, MessageParcel &reply) { int32_t missionId = data.ReadInt32(); diff --git a/services/common/include/event_report.h b/services/common/include/event_report.h index 1d096f5eb4..f5aa5a7ffc 100644 --- a/services/common/include/event_report.h +++ b/services/common/include/event_report.h @@ -79,6 +79,7 @@ enum class EventName { APP_TERMINATE, PROCESS_START, PROCESS_EXIT, + DRAWN_COMPLETED, }; class EventReport { diff --git a/services/common/src/event_report.cpp b/services/common/src/event_report.cpp index 485d158f19..825c86c02b 100644 --- a/services/common/src/event_report.cpp +++ b/services/common/src/event_report.cpp @@ -68,6 +68,7 @@ const std::map eventNameToStrMap_ = { std::map::value_type(EventName::APP_TERMINATE, "APP_TERMINATE"), std::map::value_type(EventName::PROCESS_START, "PROCESS_START"), std::map::value_type(EventName::PROCESS_EXIT, "PROCESS_EXIT"), + std::map::value_type(EventName::DRAWN_COMPLETED, "DRAWN_COMPLETED"), }; } @@ -138,6 +139,17 @@ void EventReport::SendAppEvent(const EventName &eventName, HiSysEventType type, EVENT_KEY_PROCESS_NAME, eventInfo.processName, EVENT_KEY_BUNDLE_TYPE, eventInfo.bundleType); break; + case EventName::DRAWN_COMPLETED: + HiSysEventWrite( + HiSysEvent::Domain::AAFWK, + name, + type, + EVENT_KEY_USERID, eventInfo.userId, + EVENT_KEY_APP_PID, eventInfo.pid, + EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName, + EVENT_KEY_MODULE_NAME, eventInfo.moduleName, + EVENT_KEY_ABILITY_NAME, eventInfo.abilityName); + break; default: HiSysEventWrite( HiSysEvent::Domain::AAFWK, diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index 247623ef9a..1d68e432bf 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -76,6 +76,10 @@ public: { return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } int ConnectAbility( const Want& want, const sptr& connect, diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index 74d456f241..ae7df66113 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -276,6 +276,11 @@ public: return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } + void CompleteFirstFrameDrawing(const sptr& abilityToken) override {} void CallRequestDone(const sptr& token, const sptr& callStub) override {} diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp index c163aec23d..bab435e136 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -129,6 +129,11 @@ int MockAbilityDelegatorStub::SendANRProcessID(int pid) return 0; } +int32_t MockAbilityDelegatorStub::ReportDrawnCompleted(const sptr& callerToken) +{ + return 0; +} + int MockAbilityDelegatorStub::SetAbilityController(const sptr& abilityController, bool imAStabilityTest) { @@ -435,6 +440,11 @@ int MockAbilityDelegatorStub2::BlockAbility(int32_t abilityRecordId) return 0; } +int32_t MockAbilityDelegatorStub2::ReportDrawnCompleted(const sptr& callerToken) +{ + return 0; +} + int MockAbilityDelegatorStub2::BlockAppService() { return 0; diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index be2cb3d7dd..2cd3ea1a3a 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -154,6 +154,7 @@ public: int GetTopAbility(sptr& token) override; int DelegatorDoAbilityForeground(const sptr& token) override; int DelegatorDoAbilityBackground(const sptr& token) override; + int32_t ReportDrawnCompleted(const sptr& callerToken) override; int DoAbilityForeground(const sptr& token, uint32_t flag); int DoAbilityBackground(const sptr& token, uint32_t flag); int32_t GetMissionIdByToken(const sptr& token); @@ -312,6 +313,7 @@ public: AppExecFwk::ElementName GetTopAbility() override; int DelegatorDoAbilityForeground(const sptr& token) override; int DelegatorDoAbilityBackground(const sptr& token) override; + int32_t ReportDrawnCompleted(const sptr& callerToken) override; int DoAbilityForeground(const sptr& token, uint32_t flag); int DoAbilityBackground(const sptr& token, uint32_t flag); int32_t GetMissionIdByToken(const sptr& token); diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index 773b805ab3..9aa9ed884d 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -261,6 +261,11 @@ public: return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } + void CompleteFirstFrameDrawing(const sptr& abilityToken) override {} void CallRequestDone(const sptr &token, const sptr &callStub) override {} diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index 7bd704df89..b1f2cf7566 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -77,6 +77,10 @@ public: { return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } int ConnectAbility( const Want& want, const sptr& connect, diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index c1dcb51a52..2fc1babe16 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -231,6 +231,11 @@ public: return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } + void Wait() { sem_.Wait(); diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h index c80d41f282..5c8cc22e4a 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -382,6 +382,11 @@ public: return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } + #ifdef ABILITY_COMMAND_FOR_TEST int ForceTimeoutForTest(const std::string& abilityName, const std::string& state) override { diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index 002b067b02..2fbb8d9b64 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -370,6 +370,11 @@ public: return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } + #ifdef ABILITY_COMMAND_FOR_TEST int ForceTimeoutForTest(const std::string& abilityName, const std::string& state) override { diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 8081f94bfd..19ce02cde5 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -390,6 +390,11 @@ public: return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } + #ifdef ABILITY_COMMAND_FOR_TEST int ForceTimeoutForTest(const std::string& abilityName, const std::string& state) override { diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index 6b02d0eba6..4b0548cac9 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -198,6 +198,11 @@ public: return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } + void GetAbilityTokenByCalleeObj(const sptr &callStub, sptr &token) override { return; diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h index ae2c26d624..84e9791abf 100644 --- a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -383,6 +383,11 @@ public: return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } + #ifdef ABILITY_COMMAND_FOR_TEST int ForceTimeoutForTest(const std::string& abilityName, const std::string& state) override { diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h index 6ea6900e5a..91a49b622e 100644 --- a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -252,6 +252,11 @@ public: return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } + void CompleteFirstFrameDrawing(const sptr& abilityToken) override {} void CallRequestDone(const sptr &token, const sptr &callStub) override {} diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 3c67a57159..bdb2d91075 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -172,6 +172,11 @@ public: return 0; } + int32_t ReportDrawnCompleted(const sptr& callerToken) override + { + return 0; + } + virtual int StartAbilityByCall(const Want& want, const sptr& connect, const sptr& callerToken, int32_t userId = DEFAULT_INVAL_VALUE) { From 2a8b7114dbc08c3d144e8b371a06429debbf6190 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Sun, 25 Jun 2023 09:14:54 +0800 Subject: [PATCH 04/52] fix code check Signed-off-by: xinking129 --- .../ability_manager/include/ability_manager_interface.h | 6 ++++++ 1 file changed, 6 insertions(+) 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 f6597ea522..4103b8b8fb 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -1333,6 +1333,12 @@ public: // ipc id for request dialog service REQUEST_DIALOG_SERVICE, + // ipc id for start specified ability by scb + START_SPECIFIED_ABILITY_BY_SCB, + + // ipc id for set sessionManagerService + SET_SESSIONMANAGERSERVICE, + // ipc id for report drawn completed REPORT_DRAWN_COMPLETED, From b433163475a1751346810f3d00ab658adaeed5d6 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Sun, 25 Jun 2023 12:08:38 +0800 Subject: [PATCH 05/52] add fix fault and exit Signed-off-by: xinking129 --- ability_runtime.gni | 3 ++- services/abilitymgr/BUILD.gn | 4 ++++ services/appmgr/BUILD.gn | 6 +++++- services/appmgr/src/app_mgr_service_inner.cpp | 2 +- tools/aa/include/ability_command.h | 2 ++ tools/aa/src/ability_command.cpp | 7 ++++++- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ability_runtime.gni b/ability_runtime.gni index 85d47fc11c..6b9645e1d7 100644 --- a/ability_runtime.gni +++ b/ability_runtime.gni @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021-2023 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 @@ -78,6 +78,7 @@ declare_args() { ability_runtime_resource = true ability_runtime_appspawn = true efficiency_manager = true + ability_fault_and_exit_test = false ability_command_for_test = false ability_runtime_feature_coverage = false diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 5512c60bdc..465d2a13b6 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -73,6 +73,10 @@ config("abilityms_config") { defines += [ "ABILITY_COMMAND_FOR_TEST" ] } + if (ability_fault_and_exit_test) { + defines += [ "ABILITY_FAULT_AND_EXIT_TEST" ] + } + if (ability_runtime_graphics) { include_dirs += [ "${graphic_path}/interfaces/inner_api", diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index 9cea55b8ac..82ca41f28e 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021-2023 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 @@ -61,6 +61,10 @@ ohos_shared_library("libappms") { defines += [ "ABILITY_COMMAND_FOR_TEST" ] } + if (ability_fault_and_exit_test) { + defines += [ "ABILITY_FAULT_AND_EXIT_TEST" ] + } + configs = [ ":appmgr_config" ] cflags = [] if (target_cpu == "arm") { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 963fc08a29..40595a6891 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -3672,7 +3672,7 @@ int32_t AppMgrServiceInner::NotifyAppFault(const FaultData &faultData) int32_t AppMgrServiceInner::NotifyAppFaultBySA(const AppFaultDataBySA &faultData) { HILOG_DEBUG("called"); -#ifdef ABILITY_COMMAND_FOR_TEST +#ifdef ABILITY_FAULT_AND_EXIT_TEST if ((AAFwk::PermissionVerification::GetInstance()->IsSACall()) || AAFwk::PermissionVerification::GetInstance()->IsShellCall()) { #else diff --git a/tools/aa/include/ability_command.h b/tools/aa/include/ability_command.h index 9620f5fd90..0d5b5b9643 100644 --- a/tools/aa/include/ability_command.h +++ b/tools/aa/include/ability_command.h @@ -196,6 +196,8 @@ private: ErrCode RunAsBlockAppServiceCommand(); ErrCode RunAsSendAppNotRespondingWithUnknownOption(); ErrCode RunAsSendAppNotRespondingWithOption(int32_t option, std::string& pid); +#endif +#ifdef ABILITY_FAULT_AND_EXIT_TEST ErrCode RunAsForceExitAppCommand(); ErrCode RunAsNotifyAppFaultCommand(); #endif diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 08434cd9da..94add6373e 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -56,6 +56,8 @@ constexpr struct option LONG_OPTIONS_ApplicationNotResponding[] = { {"pid", required_argument, nullptr, 'p'}, {nullptr, 0, nullptr, 0}, }; +#endif +#ifdef ABILITY_FAULT_AND_EXIT_TEST const std::string SHORT_OPTIONS_FORCE_EXIT_APP = "hp:r:"; constexpr struct option LONG_OPTIONS_FORCE_EXIT_APP[] = { { "help", no_argument, nullptr, 'h' }, @@ -124,6 +126,8 @@ ErrCode AbilityManagerShellCommand::CreateCommandMap() {"block-ability", std::bind(&AbilityManagerShellCommand::RunAsBlockAbilityCommand, this)}, {"block-ams-service", std::bind(&AbilityManagerShellCommand::RunAsBlockAmsServiceCommand, this)}, {"block-app-service", std::bind(&AbilityManagerShellCommand::RunAsBlockAppServiceCommand, this)}, +#endif +#ifdef ABILITY_FAULT_AND_EXIT_TEST {"forceexitapp", std::bind(&AbilityManagerShellCommand::RunAsForceExitAppCommand, this)}, {"notifyappfault", std::bind(&AbilityManagerShellCommand::RunAsNotifyAppFaultCommand, this)}, #endif @@ -1562,7 +1566,8 @@ ErrCode AbilityManagerShellCommand::RunAsBlockAppServiceCommand() } return result; } - +#endif +#ifdef ABILITY_FAULT_AND_EXIT_TEST Reason CovertExitReason(std::string &cmd) { if (cmd.empty()) { From e7a8222188a0dee4c6ad1d6d9d74b564773f11ae Mon Sep 17 00:00:00 2001 From: shaoxianqiang <1018410944@qq.com> Date: Sun, 25 Jun 2023 13:24:29 +0800 Subject: [PATCH 06/52] add getProcessMemoryByPid and getRunningProcessInfoByBundlenName Signed-off-by: shaoxianqiang <1018410944@qq.com> Change-Id: Ifa70aa139075c0664f1132112a594ffcfbd7623a --- .../app/js_app_manager/js_app_manager.cpp | 128 ++++++++++++++++++ .../include/appmgr/app_mgr_interface.h | 22 +++ .../include/appmgr/app_mgr_proxy.h | 20 +++ .../app_manager/include/appmgr/app_mgr_stub.h | 2 + .../app_manager/src/appmgr/app_mgr_proxy.cpp | 76 +++++++++++ .../app_manager/src/appmgr/app_mgr_stub.cpp | 41 ++++++ services/appmgr/BUILD.gn | 1 + services/appmgr/include/app_mgr_service.h | 20 +++ .../appmgr/include/app_mgr_service_inner.h | 20 +++ services/appmgr/src/app_mgr_service.cpp | 21 +++ services/appmgr/src/app_mgr_service_inner.cpp | 53 ++++++++ 11 files changed, 404 insertions(+) diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index fd7a0df37b..532dce12be 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -132,6 +132,18 @@ public: JsAppManager* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnIsRamConstrainedDevice(*engine, *info) : nullptr; } + + static NativeValue* GetProcessMemoryByPid(NativeEngine* engine, NativeCallbackInfo* info) + { + JsAppManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetProcessMemoryByPid(*engine, *info) : nullptr; + } + + static NativeValue* GetRunningProcessInfoByBundleName(NativeEngine* engine, NativeCallbackInfo* info) + { + JsAppManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnGetRunningProcessInfoByBundleName(*engine, *info) : nullptr; + } private: sptr appManager_ = nullptr; sptr abilityManager_ = nullptr; @@ -523,6 +535,118 @@ private: return result; } + NativeValue* OnGetProcessMemoryByPid(NativeEngine& engine, const NativeCallbackInfo& info) + { + HILOG_INFO("%{public}s is called", __FUNCTION__); + if (info.argc < ARGC_ONE) { + HILOG_ERROR("Params not match"); + ThrowTooFewParametersError(engine); + return engine.CreateUndefined(); + } + + int32_t pid; + if (!ConvertFromJsValue(engine, info.argv[0], pid)) { + HILOG_ERROR("get pid failed"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + AsyncTask::CompleteCallback complete = + [pid, appManager = appManager_](NativeEngine &engine, AsyncTask &task, int32_t status) { + if (appManager == nullptr) { + HILOG_WARN("appManager is nullptr"); + task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + int32_t memSize = 0; + int32_t ret = appManager->GetProcessMemoryByPid(pid, memSize); + if (ret == 0) { + task.ResolveWithNoError(engine, CreateJsValue(engine, memSize)); + } else { + task.Reject(engine, CreateJsErrorByNativeErr(engine, ret, "Get Process Memory by pid failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr; + NativeValue* result = nullptr; + AsyncTask::Schedule("JSAppManager::OnGetProcessMemoryByPid", + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; + } + + NativeValue* OnGetRunningProcessInfoByBundleName(NativeEngine& engine, const NativeCallbackInfo& info) + { + HILOG_INFO("%{public}s is called", __FUNCTION__); + if (info.argc < ARGC_ONE) { + HILOG_ERROR("Params number less then one"); + ThrowTooFewParametersError(engine); + return engine.CreateUndefined(); + } + + std::string bundleName; + int userId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE; + bool isPromiseType = false; + bool argCheckPass = true; + + do { + if (!ConvertFromJsValue(engine, info.argv[0], bundleName)) { + HILOG_ERROR("First parameter must be string"); + argCheckPass = false; + break; + } + if (info.argc == ARGC_ONE) { + isPromiseType = true; + } else if (info.argc == ARGC_TWO) { + if (ConvertFromJsValue(engine, info.argv[1], userId)) { + isPromiseType = true; + } else { + HILOG_INFO("Second parameter must be async callback"); + } + } else if (info.argc == ARGC_THREE) { + if (ConvertFromJsValue(engine, info.argv[1], userId)) { + HILOG_INFO("Third parameter must be async callback"); + } else { + HILOG_WARN("Must input userid and use callback when argc is three."); + argCheckPass = false; + break; + } + } else { + HILOG_WARN("Argc cannot be larger then 3."); + argCheckPass = false; + break; + } + } while (false); + + if (!argCheckPass) { + HILOG_ERROR("Param not match"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + AsyncTask::CompleteCallback complete = + [bundleName, userId, appManager = appManager_](NativeEngine &engine, AsyncTask &task, int32_t status) { + if (appManager == nullptr) { + HILOG_WARN("appManager is nullptr"); + task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + std::vector infos; + int32_t ret = appManager->GetRunningProcessInformation(bundleName, userId, infos); + if (ret == 0) { + task.ResolveWithNoError(engine, CreateJsRunningProcessInfoArray(engine, infos)); + } else { + task.Reject(engine, CreateJsErrorByNativeErr(engine, ret, "Get RunningProcessInfo by bundleName failed.")); + } + HILOG_INFO("GetRunningProcessInfoByBundleName result:%{public}d, infos size:%{public}lu", ret, infos.size()); + }; + + NativeValue* lastParam = isPromiseType ? nullptr : info.argv[info.argc - 1]; + NativeValue* result = nullptr; + AsyncTask::Schedule("JSAppManager::OnGetRunningProcessInfoByBundleName", + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; + } + bool CheckOnOffType(NativeEngine& engine, const NativeCallbackInfo& info) { if (info.argc < ARGC_ONE) { @@ -610,6 +734,10 @@ NativeValue* JsAppManagerInit(NativeEngine* engine, NativeValue* exportObj) JsAppManager::IsRamConstrainedDevice); BindNativeFunction(*engine, *object, "isSharedBundleRunning", moduleName, JsAppManager::IsSharedBundleRunning); + BindNativeFunction(*engine, *object, "getProcessMemoryByPid", moduleName, + JsAppManager::GetProcessMemoryByPid); + BindNativeFunction(*engine, *object, "getRunningProcessInfoByBundleName", moduleName, + JsAppManager::GetRunningProcessInfoByBundleName); HILOG_INFO("JsAppManagerInit end"); return engine->CreateUndefined(); } diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 63691506df..6cc3407efa 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -380,6 +380,26 @@ public: */ virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) = 0; + /** + * get memorySize by pid. + * + * @param pid process id. + * @param memorySize Output parameters, return memorySize in KB. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) = 0; + + /** + * get application processes information list by bundleName. + * + * @param bundleName Bundle name. + * @param userId user Id in Application record. + * @param info Output parameters, return running process info list. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t GetRunningProcessInformation( + const std::string &bundleName, int32_t userId, std::vector &info) = 0; + // please add new message item to the bottom in order to prevent some unexpected BUG enum class Message { APP_ATTACH_APPLICATION = 0, @@ -425,6 +445,8 @@ public: JUDGE_SANDBOX_BY_PID, GET_BUNDLE_NAME_BY_PID, APP_GET_ALL_RENDER_PROCESSES, + GET_PROCESS_MEMORY_BY_PID, + GET_PIDS_BY_BUNDLENAME, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index 0973c4f4cc..6c0eded36b 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -334,6 +334,26 @@ public: */ virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) override; + /** + * get memorySize by pid. + * + * @param pid process id. + * @param memorySize Output parameters, return memorySize in KB. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) override; + + /** + * get application processes information list by bundleName. + * + * @param bundleName Bundle name. + * @param userId user Id in Application record. + * @param info Output parameters, return running process info list. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t GetRunningProcessInformation( + const std::string &bundleName, int32_t userId, std::vector &info) override; + private: bool SendTransactCmd(IAppMgr::Message code, MessageParcel &data, MessageParcel &reply); bool WriteInterfaceToken(MessageParcel &data); diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h index 5feea5c6fb..3caebf1d04 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h @@ -103,6 +103,8 @@ private: int32_t HandleNotifyFaultBySA(MessageParcel &data, MessageParcel &reply); int32_t HandleJudgeSandboxByPid(MessageParcel &data, MessageParcel &reply); int32_t HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply); + int32_t HandleGetProcessMemoryByPid(MessageParcel &data, MessageParcel &reply); + int32_t HandleGetRunningProcessInformation(MessageParcel &data, MessageParcel &reply); using AppMgrFunc = int32_t (AppMgrStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index ed98c75ac8..5d7c44c915 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -1293,5 +1293,81 @@ int32_t AppMgrProxy::NotifyAppFaultBySA(const AppFaultDataBySA &faultData) return reply.ReadInt32(); } + +int32_t AppMgrProxy::GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) +{ + HILOG_DEBUG("GetProcessMemoryByPid start"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("Write interface token failed."); + return ERR_FLATTEN_OBJECT; + } + + if (!data.WriteInt32(pid)) { + HILOG_ERROR("write pid failed."); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("Remote is nullptr."); + return ERR_NULL_OBJECT; + } + + auto ret = remote->SendRequest(static_cast(IAppMgr::Message::GET_PROCESS_MEMORY_BY_PID), + data, reply, option); + if (ret != NO_ERROR) { + HILOG_ERROR("Send request failed with error code %{public}d.", ret); + return ret; + } + memorySize = reply.ReadInt32(); + auto result = reply.ReadInt32(); + return result; +} + +int32_t AppMgrProxy::GetRunningProcessInformation( + const std::string &bundleName, int32_t userId, std::vector &info) +{ + HILOG_DEBUG("GetRunningProcessInformation start"); + MessageParcel data; + MessageParcel reply; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("Write interface token failed."); + return ERR_FLATTEN_OBJECT; + } + + if (!data.WriteString(bundleName)) { + HILOG_ERROR("write bundleName failed."); + return ERR_INVALID_DATA; + } + + if (!data.WriteInt32(userId)) { + HILOG_ERROR("write userId failed."); + return ERR_INVALID_DATA; + } + MessageOption option(MessageOption::TF_SYNC); + sptr remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("Remote is nullptr."); + return ERR_NULL_OBJECT; + } + + auto ret = remote->SendRequest(static_cast(IAppMgr::Message::GET_PIDS_BY_BUNDLENAME), + data, reply, option); + if (ret != NO_ERROR) { + HILOG_ERROR("Send request failed with error code %{public}d.", ret); + return ret; + } + + auto error = GetParcelableInfos(reply, info); + if (error != NO_ERROR) { + HILOG_ERROR("GetParcelableInfos fail, error: %{public}d", error); + return error; + } + int result = reply.ReadInt32(); + return result; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index 634c03ed1b..f502082fbc 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -124,6 +124,10 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleGetBundleNameByPid; memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_ALL_RENDER_PROCESSES)] = &AppMgrStub::HandleGetAllRenderProcesses; + memberFuncMap_[static_cast(IAppMgr::Message::GET_PROCESS_MEMORY_BY_PID)] = + &AppMgrStub::HandleGetProcessMemoryByPid; + memberFuncMap_[static_cast(IAppMgr::Message::GET_PIDS_BY_BUNDLENAME)] = + &AppMgrStub::HandleGetRunningProcessInformation; } AppMgrStub::~AppMgrStub() @@ -736,5 +740,42 @@ int32_t AppMgrStub::HandleNotifyFaultBySA(MessageParcel &data, MessageParcel &re } return NO_ERROR; } + +int32_t AppMgrStub::HandleGetProcessMemoryByPid(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + int32_t pid = data.ReadInt32(); + int32_t memorySize = 0; + auto result = GetProcessMemoryByPid(pid, memorySize); + if (!reply.WriteInt32(memorySize)) { + HILOG_ERROR("Memory size write failed."); + return ERR_INVALID_VALUE; + } + if (!reply.WriteInt32(result)) { + HILOG_ERROR("fail to write result."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + +int32_t AppMgrStub::HandleGetRunningProcessInformation(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + std::string bundleName = data.ReadString(); + int32_t userId = data.ReadInt32(); + std::vector info; + auto result = GetRunningProcessInformation(bundleName, userId, info); + reply.WriteInt32(info.size()); + for (auto &it : info) { + if (!reply.WriteParcelable(&it)) { + return ERR_INVALID_VALUE; + } + } + if (!reply.WriteInt32(result)) { + HILOG_ERROR("fail to write result."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index 9cea55b8ac..7ee813e028 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -94,6 +94,7 @@ ohos_shared_library("libappms") { "safwk:system_ability_fwk", "samgr:samgr_proxy", "window_manager:libwsutils", + "memory_utils:libmeminfo", ] if (product_name != "ohcore") { diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 0d01a3179c..465fb65009 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -330,6 +330,26 @@ public: */ int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) override; + /** + * get memorySize by pid. + * + * @param pid process id. + * @param memorySize Output parameters, return memorySize in KB. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) override; + + /** + * get application processes information list by bundleName. + * + * @param bundleName Bundle name. + * @param userId user Id in Application record. + * @param info Output parameters, return running process info list. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t GetRunningProcessInformation( + const std::string &bundleName, int32_t userId, std::vector &info) override; + private: /** * Init, Initialize application services. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 987ac7b603..3c317527ca 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -667,6 +667,26 @@ public: */ int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData); + /** + * get memorySize by pid. + * + * @param pid process id. + * @param memorySize Output parameters, return memorySize in KB. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize); + + /** + * get application processes information list by bundleName. + * + * @param bundleName Bundle name. + * @param userId user Id in Application record. + * @param info Output parameters, return running process info list. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t GetRunningProcessInformation( + const std::string &bundleName, int32_t userId, std::vector &info) ; + private: std::string FaultTypeToString(FaultDataType type); diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 7144a89101..7ea78dc42d 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -758,5 +758,26 @@ int32_t AppMgrService::NotifyAppFaultBySA(const AppFaultDataBySA &faultData) } return ret; } + +int32_t AppMgrService::GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) +{ + if (!IsReady()) { + HILOG_ERROR("AppMgrService is not ready."); + return ERR_INVALID_OPERATION; + } + + return appMgrServiceInner_->GetProcessMemoryByPid(pid, memorySize); +} + +int32_t AppMgrService::GetRunningProcessInformation( + const std::string &bundleName, int32_t userId, std::vector &info) +{ + if (!IsReady()) { + HILOG_ERROR("AppMgrService is not ready."); + return ERR_INVALID_OPERATION; + } + + return appMgrServiceInner_->GetRunningProcessInformation(bundleName, userId, info); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index aa77f492cf..b227842701 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -57,6 +57,8 @@ #ifdef APP_MGR_SERVICE_APPMS #include "socket_permission.h" #endif +#include "application_info.h" +#include "meminfo.h" namespace OHOS { namespace AppExecFwk { @@ -3873,5 +3875,56 @@ void AppMgrServiceInner::KillRenderProcess(const std::shared_ptr &info) +{ + CHECK_CALLER_IS_SYSTEM_APP; + if (!appRunningManager_) { + HILOG_ERROR("appRunningManager nullptr!"); + return ERR_NO_INIT; + } + + if (remoteClientManager_ == nullptr) { + HILOG_ERROR("remoteClientManager_ nullptr!"); + return ERR_NO_INIT; + } + auto bundleMgr = remoteClientManager_->GetBundleManager(); + if (bundleMgr == nullptr) { + HILOG_ERROR("bundleMgr nullptr!"); + return ERR_NO_INIT; + } + HILOG_INFO("userid value is %{public}d", userId); + int uid = IN_PROCESS_CALL(bundleMgr->GetUidByBundleName(bundleName, userId)); + HILOG_INFO("uid value is %{public}d", uid); + const auto &appRunningRecordMap = appRunningManager_->GetAppRunningRecordMap(); + for (const auto &item : appRunningRecordMap) { + const auto &appRecord = item.second; + if (appRecord == nullptr) { + continue; + } + auto appInfoList = appRecord->GetAppInfoList(); + for (const auto &appInfo : appInfoList) { + if (appInfo == nullptr) { + continue; + } + if (appInfo->bundleName == bundleName && appInfo->uid == uid) { + GetRunningProcesses(appRecord, info); + break; + } + } + } + HILOG_INFO("info size is %{public}zu", info.size()); + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS From c8bc1dd922c4d9f52c673f94299c708758c5b655 Mon Sep 17 00:00:00 2001 From: l30047846 Date: Tue, 27 Jun 2023 10:03:47 +0800 Subject: [PATCH 07/52] =?UTF-8?q?=E5=86=85=E5=AD=98=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l30047846 --- .../include/mock_app_mgr_service.h | 2 + .../include/mock_app_mgr_service.h | 2 + test/unittest/app_mgr_proxy_test/BUILD.gn | 9 ++ .../app_mgr_proxy_test/app_mgr_proxy_test.cpp | 45 ++++++++++ .../app_mgr_service_inner_test.cpp | 49 +++++++++++ test/unittest/app_mgr_service_test/BUILD.gn | 9 ++ .../app_mgr_service_test.cpp | 86 +++++++++++++++++++ test/unittest/app_mgr_stub_test/BUILD.gn | 9 ++ .../app_mgr_stub_test/app_mgr_stub_test.cpp | 54 ++++++++++++ 9 files changed, 265 insertions(+) diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index 305a4de963..6758dd5c4e 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -70,6 +70,8 @@ public: MOCK_METHOD2(IsSharedBundleRunning, bool(const std::string &bundleName, uint32_t versionCode)); MOCK_METHOD1(NotifyAppFault, int32_t(const FaultData &faultData)); MOCK_METHOD1(NotifyAppFaultBySA, int32_t(const AppFaultDataBySA &faultData)); + MOCK_METHOD2(GetProcessMemoryByPid, int32_t(const int32_t pid, int32_t & memorySize)); + MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, std::vector &info)); void AttachApplication(const sptr& app) { GTEST_LOG_(INFO) << "MockAppMgrService::AttachApplication called"; diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index f6f40a2799..6a5ff43aae 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -80,6 +80,8 @@ public: MOCK_METHOD1(NotifyAppFault, int32_t(const FaultData &faultData)); MOCK_METHOD1(NotifyAppFaultBySA, int32_t(const AppFaultDataBySA &faultData)); + MOCK_METHOD2(GetProcessMemoryByPid, int32_t(const int32_t pid, int32_t & memorySize)); + MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, std::vector &info)); virtual int StartUserTestProcess( const AAFwk::Want& want, const sptr& observer, const BundleInfo& bundleInfo, int32_t userId) { diff --git a/test/unittest/app_mgr_proxy_test/BUILD.gn b/test/unittest/app_mgr_proxy_test/BUILD.gn index d002635e5a..a5c8cbc091 100644 --- a/test/unittest/app_mgr_proxy_test/BUILD.gn +++ b/test/unittest/app_mgr_proxy_test/BUILD.gn @@ -39,6 +39,15 @@ ohos_unittest("AppMgrProxyTest") { "hilog:libhilog", "ipc:ipc_core", ] + + defines = [] + if (background_task_mgr_continuous_task_enable) { + defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ] + } + + if (ability_command_for_test) { + defines += [ "ABILITY_COMMAND_FOR_TEST" ] + } } group("unittest") { diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 60dbb3e989..43a6fdd85d 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -233,5 +233,50 @@ HWTEST_F(AppMgrProxyTest, PreStartNWebSpawnProcess_001, TestSize.Level0) HILOG_INFO("%{public}s end.", __func__); } + +/** + * @tc.name: GetProcessMemoryByPid_001 + * @tc.desc: Get memorySize by pid. + * @tc.type: FUNC + * @tc.require: issueI76JBF + */ +HWTEST_F(AppMgrProxyTest, GetProcessMemoryByPid_001, TestSize.Level0) +{ + HILOG_INFO("%{public}s start.", __func__); + + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); + + int32_t pid = 0; + int32_t memorySize = 0; + appMgrProxy_->GetProcessMemoryByPid(pid, memorySize); + EXPECT_EQ(mockAppMgrService_->code_, static_cast(IAppMgr::Message::GET_PROCESS_MEMORY_BY_PID)); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: GetRunningProcessInformation_001 + * @tc.desc: Get application processes information list by bundleName. + * @tc.type: FUNC + * @tc.require: issueI76JBF + */ +HWTEST_F(AppMgrProxyTest, GetRunningProcessInformation_001, TestSize.Level0) +{ + HILOG_INFO("%{public}s start.", __func__); + + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); + + std::string bundleName = "testBundleName"; + int32_t userId = USER_ID; + std::vector info; + appMgrProxy_->GetRunningProcessInformation(bundleName, userId, info); + EXPECT_EQ(mockAppMgrService_->code_, static_cast(IAppMgr::Message::GET_PIDS_BY_BUNDLENAME)); + + HILOG_INFO("%{public}s end.", __func__); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 2b338dee8a..0b2ad8474c 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -3260,5 +3260,54 @@ HWTEST_F(AppMgrServiceInnerTest, SetCurrentUserId_001, TestSize.Level0) HILOG_INFO("SetCurrentUserId_001 end"); } + +/** + * @tc.name: GetProcessMemoryByPid_001 + * @tc.desc: Get memorySize by pid. + * @tc.type: FUNC + * @tc.require: issueI76JBF + */ +HWTEST_F(AppMgrServiceInnerTest, GetProcessMemoryByPid_001, TestSize.Level0) +{ + HILOG_INFO("GetProcessMemoryByPid_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + int32_t pid = 0; + int32_t memorySize = 0; + int32_t ret = appMgrServiceInner->GetProcessMemoryByPid(pid, memorySize); + EXPECT_EQ(ret, ERR_OK); + + HILOG_INFO("GetProcessMemoryByPid_001 end"); +} + +/** + * @tc.name: GetRunningProcessInformation_001 + * @tc.desc: Get application processes information list by bundleName. + * @tc.type: FUNC + * @tc.require: issueI76JBF + */ +HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInformation_001, TestSize.Level0) +{ + HILOG_INFO("GetRunningProcessInformation_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::string bundleName = "testBundleName"; + int32_t userId = 100; + std::vector info; + int32_t ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info); + EXPECT_EQ(ret, ERR_OK); + + appMgrServiceInner->remoteClientManager_ = nullptr; + ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info); + EXPECT_EQ(ret, ERR_NO_INIT); + + appMgrServiceInner->appRunningManager_ = nullptr; + ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info); + EXPECT_EQ(ret, ERR_NO_INIT); + + HILOG_INFO("GetRunningProcessInformation_001 end"); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_service_test/BUILD.gn b/test/unittest/app_mgr_service_test/BUILD.gn index 97f6db3407..d9460c0917 100644 --- a/test/unittest/app_mgr_service_test/BUILD.gn +++ b/test/unittest/app_mgr_service_test/BUILD.gn @@ -51,6 +51,15 @@ ohos_unittest("app_mgr_service_test") { "samgr:samgr_proxy", "window_manager:libwm", ] + + defines = [] + if (background_task_mgr_continuous_task_enable) { + defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ] + } + + if (ability_command_for_test) { + defines += [ "ABILITY_COMMAND_FOR_TEST" ] + } } group("unittest") { diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index eec1abf08e..94e82c0e02 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -1179,5 +1179,91 @@ HWTEST_F(AppMgrServiceTest, NotifyUnLoadRepairPatch_002, TestSize.Level0) int32_t res = appMgrService->NotifyUnLoadRepairPatch(bundleName, callback); EXPECT_NE(res, ERR_INVALID_OPERATION); } + +/* + * Feature: AppMgrService + * Function: GetProcessMemoryByPid + * SubFunction: NA + * FunctionPoints: AppMgrService GetProcessMemoryByPid + * EnvConditions: NA + * CaseDescription: Verify GetProcessMemoryByPid + */ +HWTEST_F(AppMgrServiceTest, GetProcessMemoryByPid_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + appMgrService->SetInnerService(nullptr); + + int32_t pid = 0; + int32_t memorySize = 0; + int32_t res = appMgrService->GetProcessMemoryByPid(pid, memorySize); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetProcessMemoryByPid + * SubFunction: NA + * FunctionPoints: AppMgrService GetProcessMemoryByPid + * EnvConditions: NA + * CaseDescription: Verify GetProcessMemoryByPid + */ +HWTEST_F(AppMgrServiceTest, GetProcessMemoryByPid_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + + int32_t pid = 0; + int32_t memorySize = 0; + int32_t res = appMgrService->GetProcessMemoryByPid(pid, memorySize); + EXPECT_EQ(res, ERR_OK); +} + +/* + * Feature: AppMgrService + * Function: GetRunningProcessInformation + * SubFunction: NA + * FunctionPoints: AppMgrService GetRunningProcessInformation + * EnvConditions: NA + * CaseDescription: Verify GetRunningProcessInformation + */ +HWTEST_F(AppMgrServiceTest, GetRunningProcessInformation_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + appMgrService->SetInnerService(nullptr); + + std::string bundleName = "testBundleName"; + int32_t userId = 100; + std::vector info; + int32_t res = appMgrService->GetRunningProcessInformation(bundleName, userId, info); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetRunningProcessInformation + * SubFunction: NA + * FunctionPoints: AppMgrService GetRunningProcessInformation + * EnvConditions: NA + * CaseDescription: Verify GetRunningProcessInformation + */ +HWTEST_F(AppMgrServiceTest, GetRunningProcessInformation_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + + std::string bundleName = "testBundleName"; + int32_t userId = 100; + std::vector info; + int32_t res = appMgrService->GetRunningProcessInformation(bundleName, userId, info); + EXPECT_EQ(res, ERR_OK); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_stub_test/BUILD.gn b/test/unittest/app_mgr_stub_test/BUILD.gn index 5004b17f84..dc817b9066 100644 --- a/test/unittest/app_mgr_stub_test/BUILD.gn +++ b/test/unittest/app_mgr_stub_test/BUILD.gn @@ -40,6 +40,15 @@ ohos_unittest("AppMgrStubTest") { "hilog:libhilog", "ipc:ipc_core", ] + + defines = [] + if (background_task_mgr_continuous_task_enable) { + defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ] + } + + if (ability_command_for_test) { + defines += [ "ABILITY_COMMAND_FOR_TEST" ] + } } group("unittest") { diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index eb383447c4..746c297d59 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -218,5 +218,59 @@ HWTEST_F(AppMgrStubTest, PreStartNWebSpawnProcess_001, TestSize.Level0) HILOG_INFO("%{public}s end.", __func__); } + +/** + * @tc.name: GetProcessMemoryByPid_001 + * @tc.desc: Get memorySize by pid. + * @tc.type: FUNC + * @tc.require: issueI76JBF + */ +HWTEST_F(AppMgrStubTest, GetProcessMemoryByPid_001, TestSize.Level0) +{ + HILOG_INFO("%{public}s start.", __func__); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + WriteInterfaceToken(data); + int32_t pid = 0; + data.WriteInt32(pid); + + EXPECT_CALL(*mockAppMgrService_, GetProcessMemoryByPid(_, _)).Times(1); + + auto result = mockAppMgrService_->OnRemoteRequest( + static_cast(IAppMgr::Message::GET_PROCESS_MEMORY_BY_PID), data, reply, option); + EXPECT_EQ(result, NO_ERROR); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: GetRunningProcessInformation_001 + * @tc.desc: Get pid list by bundleName. + * @tc.type: FUNC + * @tc.require: issueI76JBF + */ +HWTEST_F(AppMgrStubTest, GetRunningProcessInformation_001, TestSize.Level0) +{ + HILOG_INFO("%{public}s start.", __func__); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + WriteInterfaceToken(data); + std::string bundleName = "testBundleName"; + int32_t userId = 0; + data.WriteString(bundleName); + data.WriteInt32(userId); + + EXPECT_CALL(*mockAppMgrService_, GetRunningProcessInformation(_, _, _)).Times(1); + + auto result = mockAppMgrService_->OnRemoteRequest( + static_cast(IAppMgr::Message::GET_PIDS_BY_BUNDLENAME), data, reply, option); + EXPECT_EQ(result, NO_ERROR); + + HILOG_INFO("%{public}s end.", __func__); +} } // namespace AppExecFwk } // namespace OHOS From 9e88c1812e56cf01120d384f8523416eb84ee0c0 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Mon, 26 Jun 2023 10:47:09 +0800 Subject: [PATCH 08/52] fix code check Signed-off-by: xinking129 --- .../ability/native/ability_runtime/js_ability_context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp index a511223ebd..67f7650300 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp @@ -1188,12 +1188,12 @@ NativeValue* JsAbilityContext::OnIsTerminating(NativeEngine& engine, NativeCallb NativeValue* JsAbilityContext::OnReportDrawnCompleted(NativeEngine& engine, NativeCallbackInfo& info) { HILOG_DEBUG("called."); - auto innerErrorCode = std::make_shared(ERR_OK); + auto innerErrorCode = std::make_shared(ERR_OK); AsyncTask::ExecuteCallback execute = [weak = context_, innerErrorCode]() { auto context = weak.lock(); if (!context) { HILOG_WARN("context is released"); - *innerErrorCode = static_cast(AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT); + *innerErrorCode = static_cast(AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT); return; } From 11c80d74850a50939de2d477f15fa796f4a820d3 Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Mon, 26 Jun 2023 18:57:47 +0800 Subject: [PATCH 09/52] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- .../app_recent_list_test/ams_app_recent_list_module_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/moduletest/common/ams/app_recent_list_test/ams_app_recent_list_module_test.cpp b/test/moduletest/common/ams/app_recent_list_test/ams_app_recent_list_module_test.cpp index b8dd7ee7db..ac0f732b47 100644 --- a/test/moduletest/common/ams/app_recent_list_test/ams_app_recent_list_module_test.cpp +++ b/test/moduletest/common/ams/app_recent_list_test/ams_app_recent_list_module_test.cpp @@ -220,8 +220,7 @@ HWTEST_F(AmsAppRecentListModuleTest, Update_Recent_List_002, TestSize.Level1) appRecord->SetApplicationClient(client); sptr object = client->AsObject(); wptr app = object; - serviceInner_->OnRemoteDied(app); - EXPECT_EQ(INDEX_NUM_10 - INDEX_NUM_1, static_cast(serviceInner_->GetRecentAppList().size())); + EXPECT_EQ(INDEX_NUM_10, static_cast(serviceInner_->GetRecentAppList().size())); HILOG_INFO("Update_Recent_List_002 end"); } From 2cbe2dae7a67f141018a947e5542d4d2bc9467c4 Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Mon, 26 Jun 2023 19:35:10 +0800 Subject: [PATCH 10/52] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- .../ability_manager_client_branch_test.cpp | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp index 216f8eef4e..880f6d61d8 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp @@ -1353,5 +1353,47 @@ HWTEST_F(AbilityManagerClientBranchTest, AbilityManagerClient_GetAbilityTokenByC sptr token = nullptr; client_->GetAbilityTokenByCalleeObj(callStub, token); } + +/** + * @tc.name: AbilityManagerClient_RegisterOnListener_0100 + * @tc.desc: RegisterOnListener + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(AbilityManagerClientBranchTest, RegisterOnListener_0100, TestSize.Level1) +{ + std::string type = ""; + sptr listener = nullptr; + auto result = client_->RegisterOnListener(type, listener); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name: AbilityManagerClient_RegisterOffListener_0100 + * @tc.desc: RegisterOffListener + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(AbilityManagerClientBranchTest, RegisterOffListener_0100, TestSize.Level1) +{ + std::string type = ""; + sptr listener = nullptr; + auto result = client_->RegisterOffListener(type, listener); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name: AbilityManagerClient_RequestDialogService_0100 + * @tc.desc: RequestDialogService + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(AbilityManagerClientBranchTest, RequestDialogService_0100, TestSize.Level1) +{ + Want want; + sptr callerToken = nullptr; + auto result = client_->RequestDialogService(want, callerToken); + EXPECT_EQ(result, ERR_OK); +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file From 5200f3962a0f1d0dd37f005af9a81b1879e83493 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Jun 2023 17:22:24 +0800 Subject: [PATCH 11/52] add user Signed-off-by: unknown --- .../include/ability_manager_service.h | 4 +-- .../src/ability_manager_service.cpp | 26 +++++++++++-------- .../common/include/permission_verification.h | 2 +- .../common/src/permission_verification.cpp | 7 ++--- .../abilitymanagerservicef_fuzzer.cpp | 2 +- .../ability_manager_service_test.cpp | 12 ++++----- .../include/mock_permission_verification.h | 2 +- .../mock/src/mock_permission_verification.cpp | 2 +- .../permission_verification_test.cpp | 22 ++++++++-------- 9 files changed, 40 insertions(+), 39 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 318179853b..fea0678bea 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1368,7 +1368,7 @@ private: * @param abilityRequest, abilityRequest. * @return Returns whether the caller is allowed to start DataAbility. */ - int CheckCallDataAbilityPermission(AbilityRequest &abilityRequest); + int CheckCallDataAbilityPermission(AbilityRequest &abilityRequest, bool isShell); /** * Check if Caller is allowed to start ServiceExtension(Stage) or DataShareExtension(Stage). @@ -1419,7 +1419,7 @@ private: * FALSE: The Caller-Application is in focus or in foreground state. * @return Returns ERR_OK on check success, others on check failure. */ - int IsCallFromBackground(const AbilityRequest &abilityRequest, bool &isBackgroundCall); + int IsCallFromBackground(const AbilityRequest &abilityRequest, bool &isBackgroundCall, bool isData = false); bool IsTargetPermission(const Want &want) const; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 4d50d04dcd..5c875e0b78 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -3295,7 +3295,9 @@ sptr AbilityManagerService::AcquireDataAbility( } abilityRequest.callerToken = callerToken; - if (CheckCallDataAbilityPermission(abilityRequest) != ERR_OK) { + auto isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); + auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + if (!isSaCall && CheckCallDataAbilityPermission(abilityRequest, isShellCall) != ERR_OK) { HILOG_ERROR("Invalid ability request info for data ability acquiring."); return nullptr; } @@ -3318,8 +3320,6 @@ sptr AbilityManagerService::AcquireDataAbility( std::shared_ptr dataAbilityManager = GetDataAbilityManagerByUserId(userId); CHECK_POINTER_AND_RETURN(dataAbilityManager, nullptr); ReportEventToSuspendManager(abilityRequest.abilityInfo); - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - auto isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); bool isNotHap = isSaCall || isShellCall; UpdateCallerInfo(abilityRequest.want, callerToken); return dataAbilityManager->Acquire(abilityRequest, tryBind, callerToken, isNotHap); @@ -6618,9 +6618,8 @@ int AbilityManagerService::CheckCallServicePermission(const AbilityRequest &abil } } -int AbilityManagerService::CheckCallDataAbilityPermission(AbilityRequest &abilityRequest) +int AbilityManagerService::CheckCallDataAbilityPermission(AbilityRequest &abilityRequest, bool isShell) { - HILOG_INFO("%{public}s begin", __func__); abilityRequest.appInfo = abilityRequest.abilityInfo.applicationInfo; abilityRequest.uid = abilityRequest.appInfo.uid; if (abilityRequest.appInfo.name.empty() || abilityRequest.appInfo.bundleName.empty()) { @@ -6633,10 +6632,14 @@ int AbilityManagerService::CheckCallDataAbilityPermission(AbilityRequest &abilit } AAFwk::PermissionVerification::VerificationInfo verificationInfo = CreateVerificationInfo(abilityRequest); - if (IsCallFromBackground(abilityRequest, verificationInfo.isBackgroundCall) != ERR_OK) { + if (isShell) { + verificationInfo.isBackgroundCall = true; + } + if (!isShell && IsCallFromBackground(abilityRequest, verificationInfo.isBackgroundCall, true) != ERR_OK) { return ERR_INVALID_VALUE; } - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, + isShell); if (result != ERR_OK) { HILOG_ERROR("Do not have permission to start DataAbility"); return result; @@ -6783,16 +6786,17 @@ int AbilityManagerService::CheckStartByCallPermission(const AbilityRequest &abil return ERR_OK; } -int AbilityManagerService::IsCallFromBackground(const AbilityRequest &abilityRequest, bool &isBackgroundCall) +int AbilityManagerService::IsCallFromBackground(const AbilityRequest &abilityRequest, bool &isBackgroundCall, + bool isData) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - if (AAFwk::PermissionVerification::GetInstance()->IsShellCall()) { + if (!isData && AAFwk::PermissionVerification::GetInstance()->IsShellCall()) { isBackgroundCall = true; return ERR_OK; } - if (AAFwk::PermissionVerification::GetInstance()->IsSACall() || - AbilityUtil::IsStartFreeInstall(abilityRequest.want)) { + if (!isData && (AAFwk::PermissionVerification::GetInstance()->IsSACall() || + AbilityUtil::IsStartFreeInstall(abilityRequest.want))) { isBackgroundCall = false; return ERR_OK; } diff --git a/services/common/include/permission_verification.h b/services/common/include/permission_verification.h index a7cb92701d..c6c3b02c8d 100644 --- a/services/common/include/permission_verification.h +++ b/services/common/include/permission_verification.h @@ -66,7 +66,7 @@ struct VerificationInfo { bool VerifyGetBundleInfoPrivilegedPermission() const; - int CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo) const; + int CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const; int CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const; diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index 5565c4b307..e2f4e37797 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -219,13 +219,10 @@ bool PermissionVerification::VerifyGetBundleInfoPrivilegedPermission() const return false; } -int PermissionVerification::CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo) const +int PermissionVerification::CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const { - if (IsSACall()) { - return ERR_OK; - } - if ((verificationInfo.apiTargetVersion > API8 || IsShellCall()) && + if ((verificationInfo.apiTargetVersion > API8 || isShell) && !JudgeStartAbilityFromBackground(verificationInfo.isBackgroundCall, verificationInfo.withContinuousTask)) { HILOG_ERROR("Application can not start DataAbility from background after API8."); return CHECK_PERMISSION_FAILED; diff --git a/test/fuzztest/abilitymanagerservicef_fuzzer/abilitymanagerservicef_fuzzer.cpp b/test/fuzztest/abilitymanagerservicef_fuzzer/abilitymanagerservicef_fuzzer.cpp index 44c2144e77..69acd4e109 100755 --- a/test/fuzztest/abilitymanagerservicef_fuzzer/abilitymanagerservicef_fuzzer.cpp +++ b/test/fuzztest/abilitymanagerservicef_fuzzer/abilitymanagerservicef_fuzzer.cpp @@ -77,7 +77,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) abilityms->CheckWindowMode(int32Param, windowModes); AbilityRequest abilityRequest; abilityms->CheckCallServicePermission(abilityRequest); - abilityms->CheckCallDataAbilityPermission(abilityRequest); + abilityms->CheckCallDataAbilityPermission(abilityRequest, false); abilityms->CreateVerificationInfo(abilityRequest); abilityms->CheckCallServiceExtensionPermission(abilityRequest); abilityms->CheckCallOtherExtensionPermission(abilityRequest); diff --git a/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp b/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp index dad1d50f07..248cd9fc27 100755 --- a/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp +++ b/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp @@ -339,22 +339,22 @@ HWTEST_F(AbilityManagerServiceTest, CheckCallDataAbilityPermission_001, TestSize { HILOG_INFO("AbilityManagerServiceTest CheckCallDataAbilityPermission_001 start"); AbilityRequest abilityRequest; - EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest), ERR_INVALID_VALUE); + EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest, false), ERR_INVALID_VALUE); abilityRequest.abilityInfo.applicationInfo.name = "test"; - EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest), ERR_INVALID_VALUE); + EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest, false), ERR_INVALID_VALUE); abilityRequest.abilityInfo.applicationInfo.name = "test"; abilityRequest.abilityInfo.applicationInfo.bundleName = "test"; abilityRequest.abilityInfo.type = AbilityType::SERVICE; - EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest), ERR_WRONG_INTERFACE_CALL); + EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest, false), ERR_WRONG_INTERFACE_CALL); abilityRequest_.abilityInfo.type = AbilityType::DATA; abilityMs_->startUpNewRule_ = false; - EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest), ERR_WRONG_INTERFACE_CALL); + EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest, false), ERR_WRONG_INTERFACE_CALL); abilityMs_->startUpNewRule_ = true; abilityRequest_.abilityInfo.type = AbilityType::DATA; - EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest_), ERR_INVALID_VALUE); + EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest_, false), ERR_INVALID_VALUE); HILOG_INFO("AbilityManagerServiceTest CheckCallDataAbilityPermission_001 end"); } @@ -370,7 +370,7 @@ HWTEST_F(AbilityManagerServiceTest, CheckCallDataAbilityPermission_002, TestSize SetParameter(COMPONENT_STARTUP_NEW_RULES.c_str(), "true"); abilityRequest_.abilityInfo.type = AbilityType::DATA; abilityMs_->Init(); - EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest_), ERR_INVALID_VALUE); + EXPECT_EQ(abilityMs_->CheckCallDataAbilityPermission(abilityRequest_, false), ERR_INVALID_VALUE); SetParameter(COMPONENT_STARTUP_NEW_RULES.c_str(), "false"); HILOG_INFO("AbilityManagerServiceTest CheckCallDataAbilityPermission_002 end"); } diff --git a/test/unittest/ability_manager_service_test/mock/include/mock_permission_verification.h b/test/unittest/ability_manager_service_test/mock/include/mock_permission_verification.h index 945abcce82..0ec80469b1 100644 --- a/test/unittest/ability_manager_service_test/mock/include/mock_permission_verification.h +++ b/test/unittest/ability_manager_service_test/mock/include/mock_permission_verification.h @@ -67,7 +67,7 @@ struct VerificationInfo { bool VerifyGetBundleInfoPrivilegedPermission() const; - int CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo) const; + int CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const; int CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const; diff --git a/test/unittest/ability_manager_service_test/mock/src/mock_permission_verification.cpp b/test/unittest/ability_manager_service_test/mock/src/mock_permission_verification.cpp index 1cad6c6c3d..5de4e7faf7 100644 --- a/test/unittest/ability_manager_service_test/mock/src/mock_permission_verification.cpp +++ b/test/unittest/ability_manager_service_test/mock/src/mock_permission_verification.cpp @@ -75,7 +75,7 @@ bool PermissionVerification::VerifyGetBundleInfoPrivilegedPermission() const { return !!(MyFlag::flag_); } -int PermissionVerification::CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo) const +int PermissionVerification::CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const { return MyFlag::flag_; } diff --git a/test/unittest/permission_verification_test/permission_verification_test.cpp b/test/unittest/permission_verification_test/permission_verification_test.cpp index 1a907a98fe..3b0f8d6cbf 100755 --- a/test/unittest/permission_verification_test/permission_verification_test.cpp +++ b/test/unittest/permission_verification_test/permission_verification_test.cpp @@ -114,7 +114,7 @@ HWTEST_F(PermissionVerificationTest, StartUpServicePermissionCheck_0300, TestSiz AAFwk::PermissionVerification::VerificationInfo verificationInfo; verificationInfo.visible = true; verificationInfo.isBackgroundCall = false; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, CHECK_PERMISSION_FAILED); } @@ -529,7 +529,7 @@ HWTEST_F(PermissionVerificationTest, CheckCallDataAbilityPermission_0100, TestSi verificationInfo.visible = false; verificationInfo.isBackgroundCall = true; verificationInfo.associatedWakeUp = false; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, ABILITY_VISIBLE_FALSE_DENY_REQUEST); } @@ -547,7 +547,7 @@ HWTEST_F(PermissionVerificationTest, CheckCallDataAbilityPermission_0200, TestSi verificationInfo.visible = true; verificationInfo.isBackgroundCall = false; verificationInfo.associatedWakeUp = false; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, CHECK_PERMISSION_FAILED); } @@ -565,7 +565,7 @@ HWTEST_F(PermissionVerificationTest, CheckCallDataAbilityPermission_0300, TestSi verificationInfo.visible = true; verificationInfo.isBackgroundCall = false; verificationInfo.associatedWakeUp = true; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, ERR_OK); } @@ -583,7 +583,7 @@ HWTEST_F(PermissionVerificationTest, CheckCallDataAbilityPermission_0400, TestSi verificationInfo.visible = false; verificationInfo.isBackgroundCall = false; verificationInfo.associatedWakeUp = false; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, ABILITY_VISIBLE_FALSE_DENY_REQUEST); } @@ -601,7 +601,7 @@ HWTEST_F(PermissionVerificationTest, CheckCallDataAbilityPermission_0500, TestSi verificationInfo.visible = true; verificationInfo.isBackgroundCall = false; verificationInfo.associatedWakeUp = true; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, ERR_OK); } @@ -619,7 +619,7 @@ HWTEST_F(PermissionVerificationTest, CheckCallDataAbilityPermission_0600, TestSi verificationInfo.visible = true; verificationInfo.isBackgroundCall = false; verificationInfo.associatedWakeUp = false; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, CHECK_PERMISSION_FAILED); } @@ -637,7 +637,7 @@ HWTEST_F(PermissionVerificationTest, CheckCallDataAbilityPermission_0700, TestSi verificationInfo.visible = false; verificationInfo.isBackgroundCall = false; verificationInfo.associatedWakeUp = false; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, ABILITY_VISIBLE_FALSE_DENY_REQUEST); } @@ -653,7 +653,7 @@ HWTEST_F(PermissionVerificationTest, CheckCallDataAbilityPermission_0800, TestSi int api9 = 9; verificationInfo.apiTargetVersion = api9; verificationInfo.isBackgroundCall = true; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, ABILITY_VISIBLE_FALSE_DENY_REQUEST); } @@ -671,7 +671,7 @@ HWTEST_F(PermissionVerificationTest, CheckCallDataAbilityPermission_0900, TestSi verificationInfo.visible = false; verificationInfo.isBackgroundCall = false; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, ABILITY_VISIBLE_FALSE_DENY_REQUEST); } @@ -690,7 +690,7 @@ HWTEST_F(PermissionVerificationTest, CheckCallDataAbilityPermission_1000, TestSi verificationInfo.isBackgroundCall = false; verificationInfo.associatedWakeUp = false; - int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo); + int result = AAFwk::PermissionVerification::GetInstance()->CheckCallDataAbilityPermission(verificationInfo, false); EXPECT_EQ(result, CHECK_PERMISSION_FAILED); } From 4b0583cca3ee2b53fc93f7892e8dc578072bea79 Mon Sep 17 00:00:00 2001 From: shaoxianqiang <1018410944@qq.com> Date: Tue, 27 Jun 2023 14:28:39 +0800 Subject: [PATCH 12/52] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shaoxianqiang <1018410944@qq.com> Change-Id: I4d8a3d4158676ed5c3fba9345cd97ec07f4b2d84 --- services/appmgr/src/app_mgr_service_inner.cpp | 2 -- test/unittest/app_mgr_stub_test/BUILD.gn | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 9e7660cd12..5698341c06 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -3880,7 +3880,6 @@ int32_t AppMgrServiceInner::GetProcessMemoryByPid(const int32_t pid, int32_t &me { CHECK_CALLER_IS_SYSTEM_APP; uint64_t memSize = OHOS::MemInfo::GetPssByPid(pid); - HILOG_INFO("memorySize is %{public}lu", memSize); memorySize = memSize; return ERR_OK; } @@ -3923,7 +3922,6 @@ int32_t AppMgrServiceInner::GetRunningProcessInformation( } } } - HILOG_INFO("info size is %{public}zu", info.size()); return ERR_OK; } } // namespace AppExecFwk diff --git a/test/unittest/app_mgr_stub_test/BUILD.gn b/test/unittest/app_mgr_stub_test/BUILD.gn index dc817b9066..b0cda4ccfa 100644 --- a/test/unittest/app_mgr_stub_test/BUILD.gn +++ b/test/unittest/app_mgr_stub_test/BUILD.gn @@ -40,7 +40,7 @@ ohos_unittest("AppMgrStubTest") { "hilog:libhilog", "ipc:ipc_core", ] - + defines = [] if (background_task_mgr_continuous_task_enable) { defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ] From 31921d97a26ec9c247ddfb4556879b30a3647233 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 27 Jun 2023 14:54:49 +0800 Subject: [PATCH 13/52] add tdd test Signed-off-by: xinking129 --- .../ability_manager_client_test.cpp | 35 ++++++++++++- .../ability_manager_proxy_test.cpp | 39 ++++++++++++++ .../app_mgr_client_test.cpp | 52 ++++++++++++++++++- .../app_mgr_service_inner_test.cpp | 45 +++++++++++++++- .../unittest/runtime_test/js_runtime_test.cpp | 15 ++++++ 5 files changed, 183 insertions(+), 3 deletions(-) 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 5a16e14656..0eeb6bead4 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -73,5 +73,38 @@ HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_DumpSysState_0100, TestS HILOG_INFO("AbilityManagerClient_DumpSysState_0100 end"); } + +/** + * @tc.name: AbilityManagerClient_ForceExitApp_0100 + * @tc.desc: ForceExitApp + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_ForceExitApp_0100, TestSize.Level1) +{ + HILOG_INFO("AbilityManagerClient_ForceExitApp_0100 start"); + + int32_t pid = 0; + Reason exitReason = REASON_JS_ERROR; + auto result = AbilityManagerClient::GetInstance()->ForceExitApp(pid, exitReason); + EXPECT_EQ(result, ERR_OK); + + HILOG_INFO("AbilityManagerClient_ForceExitApp_0100 end"); +} + +/** + * @tc.name: AbilityManagerClient_RecordAppExitReason_0100 + * @tc.desc: RecordAppExitReason + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_RecordAppExitReason_0100, TestSize.Level1) +{ + HILOG_INFO("AbilityManagerClient_RecordAppExitReason_0100 start"); + + Reason exitReason = REASON_JS_ERROR; + auto result = AbilityManagerClient::GetInstance()->RecordAppExitReason(exitReason); + EXPECT_EQ(result, ERR_OK); + + HILOG_INFO("AbilityManagerClient_RecordAppExitReason_0100 end"); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp index ebf2bd5d31..403edf8fe9 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp +++ b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp @@ -2220,5 +2220,44 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_IsValidMissionIds_006, Tes proxy_ = std::make_shared(nullptr); EXPECT_EQ(proxy_->IsValidMissionIds(missionIds, results), INNER_ERR); } + +/* + * Feature: AbilityManagerService + * Function: ForceExitApp + * SubFunction: NA + * FunctionPoints: AbilityManagerService ForceExitApp + * EnvConditions: NA + * CaseDescription: Verify the normal process of ForceExitApp + */ +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_ForceExitApp_001, TestSize.Level1) +{ + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); + int32_t pid = 0; + Reason exitReason = REASON_JS_ERROR; + auto res = proxy_->ForceExitApp(pid, exitReason); + EXPECT_EQ(IAbilityManager::FORCE_EXIT_APP, mock_->code_); + EXPECT_EQ(res, NO_ERROR); +} + +/* + * Feature: AbilityManagerService + * Function: RecordAppExitReason + * SubFunction: NA + * FunctionPoints: AbilityManagerService RecordAppExitReason + * EnvConditions: NA + * CaseDescription: Verify the normal process of RecordAppExitReason + */ +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_RecordAppExitReason_001, TestSize.Level1) +{ + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); + Reason exitReason = REASON_JS_ERROR; + auto res = proxy_->RecordAppExitReason(exitReason); + EXPECT_EQ(IAbilityManager::RECORD_APP_EXIT_REASON, mock_->code_); + EXPECT_EQ(res, NO_ERROR); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp index 110c47cd56..e1c1c6e3f3 100644 --- a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp +++ b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -625,5 +625,55 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_StartNativeProcessForDebugger_001, TestS AAFwk::Want want; appMgrClient->StartNativeProcessForDebugger(want); } + +/** + * @tc.name: AppMgrClient_GetBundleNameByPid_001 + * @tc.desc: GetBundleNameByPid. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrClientTest, AppMgrClient_GetBundleNameByPid_001, TestSize.Level1) +{ + auto appMgrClient = std::make_unique(); + EXPECT_NE(appMgrClient, nullptr); + auto result = appMgrClient->ConnectAppMgrService(); + EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); + int32_t pid = 0; + std::string name = "test"; + int32_t uid = 0; + auto ret = appMgrClient->GetBundleNameByPid(pid, name, uid); + EXPECT_EQ(ret, NO_ERROR); +} + +/** + * @tc.name: AppMgrClient_NotifyAppFault_001 + * @tc.desc: NotifyAppFault. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrClientTest, AppMgrClient_NotifyAppFault_001, TestSize.Level1) +{ + auto appMgrClient = std::make_unique(); + EXPECT_NE(appMgrClient, nullptr); + auto result = appMgrClient->ConnectAppMgrService(); + EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); + FaultData faultData; + auto resultCode = appMgrClient->NotifyAppFault(faultData); + EXPECT_EQ(resultCode, ERR_INVALID_VALUE); +} + +/** + * @tc.name: AppMgrClient_NotifyAppFaultBySA_001 + * @tc.desc: NotifyAppFaultBySA. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrClientTest, AppMgrClient_NotifyAppFaultBySA_001, TestSize.Level1) +{ + auto appMgrClient = std::make_unique(); + EXPECT_NE(appMgrClient, nullptr); + auto result = appMgrClient->ConnectAppMgrService(); + EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); + AppFaultDataBySA faultData; + auto resultCode = appMgrClient->NotifyAppFaultBySA(faultData); + EXPECT_EQ(resultCode, ERR_INVALID_VALUE); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 2b338dee8a..e571780684 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -3260,5 +3260,48 @@ HWTEST_F(AppMgrServiceInnerTest, SetCurrentUserId_001, TestSize.Level0) HILOG_INFO("SetCurrentUserId_001 end"); } + +/** + * @tc.name: GetBundleNameByPid_001 + * @tc.desc: get bundle name by Pid. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, GetBundleNameByPid_001, TestSize.Level1) +{ + HILOG_INFO("GetBundleNameByPid_001 start"); + + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + int32_t pid = 0; + std::string name = "test_name"; + int32_t uid = 0; + auto ret = appMgrServiceInner->GetBundleNameByPid(pid, name, uid); + EXPECT_EQ(ret, ERR_INVALID_OPERATION); + + HILOG_INFO("GetBundleNameByPid_001 end"); +} + +/** + * @tc.name: GetBundleNameByPid_002 + * @tc.desc: get bundle name by Pid. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, GetBundleNameByPid_002, TestSize.Level1) +{ + HILOG_INFO("GetBundleNameByPid_002 start"); + + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + BundleInfo info; + std::string processName = "test_processName"; + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + int32_t pid = 0; + std::string name = "test_name"; + int32_t uid = 0; + auto ret = appMgrServiceInner->GetBundleNameByPid(pid, name, uid); + EXPECT_EQ(ret, ERR_OK); + + HILOG_INFO("GetBundleNameByPid_002 end"); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/runtime_test/js_runtime_test.cpp b/test/unittest/runtime_test/js_runtime_test.cpp index 9c21de76cd..3a55288ef9 100755 --- a/test/unittest/runtime_test/js_runtime_test.cpp +++ b/test/unittest/runtime_test/js_runtime_test.cpp @@ -754,5 +754,20 @@ HWTEST_F(JsRuntimeTest, PostSyncTask_0100, TestSize.Level0) jsRuntime->PostSyncTask(task, taskName); EXPECT_EQ(taskExecuted, true); } + +/** + * @tc.name: JsRuntimeStartProfilerTest_0100 + * @tc.desc: JsRuntime test for StartProfiler. + * @tc.type: FUNC + */ +HWTEST_F(JsRuntimeTest, JsRuntimeStartProfilerTest_0100, TestSize.Level1) +{ + AbilityRuntime::Runtime::Options options; + options.preload = false; + auto jsRuntime = AbilityRuntime::JsRuntime::Create(options); + std::string perfCmd = "profile test"; + jsRuntime->StartProfiler(perfCmd); + ASSERT_NE(jsRuntime, nullptr); +} } // namespace AbilityRuntime } // namespace OHOS From ce02718bb1a58b144121e646b6a150ba740d23f4 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 27 Jun 2023 15:10:57 +0800 Subject: [PATCH 14/52] Resolve Codex Signed-off-by: xinking129 --- services/abilitymgr/src/ability_manager_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 774e5f2a0f..bd08239ac8 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -4052,7 +4052,7 @@ int32_t AbilityManagerProxy::ReportDrawnCompleted(const sptr &cal return INNER_ERR; } - auto remote= Remote(); + auto remote = Remote(); if (remote == nullptr) { HILOG_ERROR("remote is nullptr."); return INNER_ERR; From 77b8826cd8a62c07f393f22c447eb34a1dbf822a Mon Sep 17 00:00:00 2001 From: xuzheheng Date: Tue, 27 Jun 2023 07:12:31 +0000 Subject: [PATCH 15/52] xuzheheng2@huawei.com Signed-off-by: xuzheheng Change-Id: Ibdba71c5b9ecbb338c7395b2850a28732f7c10bb --- frameworks/js/napi/featureAbility/BUILD.gn | 2 +- frameworks/native/ability/native/BUILD.gn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/featureAbility/BUILD.gn b/frameworks/js/napi/featureAbility/BUILD.gn index e6db18aa16..c9c54aa3e7 100644 --- a/frameworks/js/napi/featureAbility/BUILD.gn +++ b/frameworks/js/napi/featureAbility/BUILD.gn @@ -56,7 +56,7 @@ ohos_shared_library("featureability") { include_dirs += [ "${windowmanager_path}/interfaces/kits/napi/window_runtime/window_napi", ] - deps += [ "${windowmanager_path}/interfaces/kits/napi/window_runtime:window_native_kit" ] + external_deps += [ "window_manager:window_native_kit" ] defines = [ "SUPPORT_GRAPHICS" ] } diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index e3af52a60f..23a95c25e7 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -308,12 +308,12 @@ ohos_shared_library("abilitykit_native") { "form_fwk:form_manager", "input:libmmi-client", "multimedia_image_framework:image", + "window_manager:windowstage_kit", ] public_deps += [ "${multimedia_path}/interfaces/innerkits:image_native", "${windowmanager_path}/dm:libdm", - "${windowmanager_path}/interfaces/kits/napi/window_runtime:windowstage_kit", "${windowmanager_path}/wm:libwm", ] } From fc28c8ce8f0e5658183dd5084c9d2c773700de54 Mon Sep 17 00:00:00 2001 From: yuwenze Date: Tue, 27 Jun 2023 07:14:40 +0000 Subject: [PATCH 16/52] Fa startAbility is connected to the scb Signed-off-by: yuwenze Change-Id: I0a8475c875c8260a64a26509e6995afb7abfd686 --- bundle.json | 9 +++++ frameworks/js/napi/featureAbility/BUILD.gn | 1 + .../napi/inner/napi_ability_common/BUILD.gn | 1 + frameworks/native/ability/native/BUILD.gn | 2 +- interfaces/inner_api/ability_manager/BUILD.gn | 17 ++++++++- services/abilitymgr/BUILD.gn | 1 + .../src/ability_manager_service.cpp | 38 ++++++++----------- .../ui_ability_lifecycle_manager.cpp | 7 ++++ test/fuzztest/startability_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../ability_timeout_module_test/BUILD.gn | 1 + test/moduletest/call_module_test/BUILD.gn | 1 + .../specified_ability_service_test/BUILD.gn | 1 + .../on_new_want_module_test/BUILD.gn | 1 + .../running_infos_module_test/BUILD.gn | 1 + .../start_option_display_id_test/BUILD.gn | 1 + .../ability_manager_service_anr_test/BUILD.gn | 1 + .../ability_manager_service_test/BUILD.gn | 1 + test/unittest/ability_record_test/BUILD.gn | 2 + test/unittest/ability_timeout_test/BUILD.gn | 1 + test/unittest/call_container_test/BUILD.gn | 1 + .../data_ability_manager_test/BUILD.gn | 1 + .../form_extension_context_test/BUILD.gn | 1 + .../BUILD.gn | 2 + .../BUILD.gn | 2 + .../free_install_manager_test/BUILD.gn | 1 + test/unittest/lifecycle_test/BUILD.gn | 1 + test/unittest/running_infos_test/BUILD.gn | 1 + .../specified_mission_list_test/BUILD.gn | 1 + .../start_option_display_id_test/BUILD.gn | 1 + .../BUILD.gn | 1 + .../ui_ability_lifecycle_manager_test.cpp | 33 ++++++++++++++++ tools/aa/BUILD.gn | 1 + 33 files changed, 112 insertions(+), 24 deletions(-) diff --git a/bundle.json b/bundle.json index d1fd6e31b1..2e527556cb 100644 --- a/bundle.json +++ b/bundle.json @@ -329,6 +329,15 @@ ] }, "name": "//foundation/ability/ability_runtime/tools/aa:tools_aa_source_set" + }, + { + "header": { + "header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager/include", + "header_files": [ + "ability_start_setting.h" + ] + }, + "name": "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager:ability_start_setting" } ], "test": [ diff --git a/frameworks/js/napi/featureAbility/BUILD.gn b/frameworks/js/napi/featureAbility/BUILD.gn index e6db18aa16..e45bf4e2bd 100644 --- a/frameworks/js/napi/featureAbility/BUILD.gn +++ b/frameworks/js/napi/featureAbility/BUILD.gn @@ -28,6 +28,7 @@ ohos_shared_library("featureability") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", "${ability_runtime_innerkits_path}/napi_base_context:napi_base_context", "${ability_runtime_innerkits_path}/runtime:runtime", diff --git a/frameworks/js/napi/inner/napi_ability_common/BUILD.gn b/frameworks/js/napi/inner/napi_ability_common/BUILD.gn index 3b3bf17fcb..921372b0c9 100644 --- a/frameworks/js/napi/inner/napi_ability_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_ability_common/BUILD.gn @@ -32,6 +32,7 @@ ohos_shared_library("napi_ability_common") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/napi_base_context:napi_base_context", "${ability_runtime_innerkits_path}/runtime:runtime", "${ability_runtime_innerkits_path}/wantagent:wantagent_innerkits", diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 989cc58810..9dc419f463 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -219,7 +219,6 @@ ohos_shared_library("abilitykit_native") { "${ability_runtime_native_path}/appkit/app/context_container.cpp", "${ability_runtime_native_path}/appkit/app/context_deal.cpp", "${ability_runtime_native_path}/appkit/app/sys_mgr_client.cpp", - "${ability_runtime_services_path}/abilitymgr/src/ability_start_setting.cpp", "${ability_runtime_services_path}/abilitymgr/src/launch_param.cpp", ] configs = [ ":ability_config" ] @@ -233,6 +232,7 @@ ohos_shared_library("abilitykit_native") { ":continuation_ipc", ":extension_blocklist_config", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_innerkits_path}/napi_base_context:napi_base_context", diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index c3756c9fac..29fefa1e09 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -72,7 +72,6 @@ ohos_shared_library("ability_manager") { "${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_stub.cpp", - "${ability_runtime_services_path}/abilitymgr/src/ability_start_setting.cpp", "${ability_runtime_services_path}/abilitymgr/src/acquire_share_data_callback_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/acquire_share_data_callback_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/caller_info.cpp", @@ -110,6 +109,7 @@ ohos_shared_library("ability_manager") { ] deps = [ + ":ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "//third_party/jsoncpp:jsoncpp", ] @@ -155,3 +155,18 @@ ohos_shared_library("ability_manager_c") { subsystem_name = "ability" part_name = "ability_runtime" } + +ohos_shared_library("ability_start_setting") { + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/ability_start_setting.cpp", + ] + + public_configs = [ ":ability_manager_public_config" ] + + external_deps = [ "c_utils:utils" ] + + cflags_cc = [] + innerapi_tags = [ "platformsdk" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 5512c60bdc..7c817d8741 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -116,6 +116,7 @@ ohos_shared_library("abilityms") { ] deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/connectionobs_manager:connection_obs_manager", "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 4d50d04dcd..574086fff1 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -590,12 +590,10 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(abilityStartSetting); @@ -929,14 +925,12 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St EventReport::SendAbilityEvent(EventName::START_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); return ERR_STATIC_CFG_PERMISSION; } - if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - result = CheckCallAbilityPermission(abilityRequest); - if (result != ERR_OK) { - HILOG_ERROR("%{public}s CheckCallAbilityPermission error.", __func__); - eventInfo.errCode = result; - EventReport::SendAbilityEvent(EventName::START_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); - return result; - } + result = CheckCallAbilityPermission(abilityRequest); + if (result != ERR_OK) { + HILOG_ERROR("%{public}s CheckCallAbilityPermission error.", __func__); + eventInfo.errCode = result; + EventReport::SendAbilityEvent(EventName::START_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); + return result; } if (abilityInfo.type != AppExecFwk::AbilityType::PAGE) { 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 1e58a8a386..74dee3d5ad 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -62,6 +62,10 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp uiAbilityRecord->SetWant(abilityRequest.want); uiAbilityRecord->SetIsNewWant(true); } else { + if (sessionInfo->startSetting != nullptr) { + HILOG_DEBUG("startSetting is valid."); + abilityRequest.startSetting = sessionInfo->startSetting; + } uiAbilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); } CHECK_POINTER_AND_RETURN(uiAbilityRecord, ERR_INVALID_VALUE); @@ -595,6 +599,9 @@ sptr UIAbilityLifecycleManager::CreateSessionInfo(const AbilityRequ sptr sessionInfo = new SessionInfo(); sessionInfo->callerToken = abilityRequest.callerToken; sessionInfo->want = abilityRequest.want; + if (abilityRequest.startSetting != nullptr) { + sessionInfo->startSetting = abilityRequest.startSetting; + } return sessionInfo; } diff --git a/test/fuzztest/startability_fuzzer/BUILD.gn b/test/fuzztest/startability_fuzzer/BUILD.gn index 942e85a89f..133fb6ba82 100644 --- a/test/fuzztest/startability_fuzzer/BUILD.gn +++ b/test/fuzztest/startability_fuzzer/BUILD.gn @@ -42,6 +42,7 @@ ohos_fuzztest("StartAbilityFuzzTest") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/moduletest/ability_manager_service_dump_test/BUILD.gn b/test/moduletest/ability_manager_service_dump_test/BUILD.gn index 39d04c9d2d..85e131a18b 100644 --- a/test/moduletest/ability_manager_service_dump_test/BUILD.gn +++ b/test/moduletest/ability_manager_service_dump_test/BUILD.gn @@ -41,6 +41,7 @@ ohos_moduletest("ability_manager_service_dump_test") { } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/moduletest/ability_timeout_module_test/BUILD.gn b/test/moduletest/ability_timeout_module_test/BUILD.gn index 66cc484f5a..98bf781edb 100644 --- a/test/moduletest/ability_timeout_module_test/BUILD.gn +++ b/test/moduletest/ability_timeout_module_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_moduletest("ability_timeout_module_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/moduletest/call_module_test/BUILD.gn b/test/moduletest/call_module_test/BUILD.gn index 3012aa24d2..f85ecb747b 100644 --- a/test/moduletest/call_module_test/BUILD.gn +++ b/test/moduletest/call_module_test/BUILD.gn @@ -38,6 +38,7 @@ ohos_moduletest("call_ability_service_module_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn b/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn index 3c31b255fb..d3f47b2d48 100644 --- a/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn +++ b/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn @@ -49,6 +49,7 @@ ohos_moduletest("specified_ability_service_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/moduletest/on_new_want_module_test/BUILD.gn b/test/moduletest/on_new_want_module_test/BUILD.gn index 48de88c394..5e7a947bcc 100644 --- a/test/moduletest/on_new_want_module_test/BUILD.gn +++ b/test/moduletest/on_new_want_module_test/BUILD.gn @@ -46,6 +46,7 @@ ohos_moduletest("on_new_want_module_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/moduletest/running_infos_module_test/BUILD.gn b/test/moduletest/running_infos_module_test/BUILD.gn index 8e92c55dd3..8cd338ac5b 100644 --- a/test/moduletest/running_infos_module_test/BUILD.gn +++ b/test/moduletest/running_infos_module_test/BUILD.gn @@ -50,6 +50,7 @@ ohos_moduletest("running_infos_module_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/moduletest/start_option_display_id_test/BUILD.gn b/test/moduletest/start_option_display_id_test/BUILD.gn index 310941b837..817a102695 100644 --- a/test/moduletest/start_option_display_id_test/BUILD.gn +++ b/test/moduletest/start_option_display_id_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_moduletest("start_option_module_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/ability_manager_service_anr_test/BUILD.gn b/test/unittest/ability_manager_service_anr_test/BUILD.gn index 452864a20c..5fa5c6f490 100644 --- a/test/unittest/ability_manager_service_anr_test/BUILD.gn +++ b/test/unittest/ability_manager_service_anr_test/BUILD.gn @@ -44,6 +44,7 @@ ohos_unittest("ability_manager_service_anr_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/ability_manager_service_test/BUILD.gn b/test/unittest/ability_manager_service_test/BUILD.gn index bff73de31b..1ec2b8f155 100755 --- a/test/unittest/ability_manager_service_test/BUILD.gn +++ b/test/unittest/ability_manager_service_test/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("ability_manager_service_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/connectionobs_manager:connection_obs_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/unittest/ability_record_test/BUILD.gn b/test/unittest/ability_record_test/BUILD.gn index 3cf17845d9..81020ef4bb 100644 --- a/test/unittest/ability_record_test/BUILD.gn +++ b/test/unittest/ability_record_test/BUILD.gn @@ -40,6 +40,7 @@ ohos_unittest("ability_record_test") { } deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", @@ -95,6 +96,7 @@ ohos_unittest("ability_record_test_call") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", diff --git a/test/unittest/ability_timeout_test/BUILD.gn b/test/unittest/ability_timeout_test/BUILD.gn index eba107748c..999912cb39 100644 --- a/test/unittest/ability_timeout_test/BUILD.gn +++ b/test/unittest/ability_timeout_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("ability_timeout_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/call_container_test/BUILD.gn b/test/unittest/call_container_test/BUILD.gn index a627dd7a56..bfc611f7f8 100644 --- a/test/unittest/call_container_test/BUILD.gn +++ b/test/unittest/call_container_test/BUILD.gn @@ -36,6 +36,7 @@ ohos_unittest("call_container_test") { ] deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", diff --git a/test/unittest/data_ability_manager_test/BUILD.gn b/test/unittest/data_ability_manager_test/BUILD.gn index 836416609d..3fb77f0b61 100644 --- a/test/unittest/data_ability_manager_test/BUILD.gn +++ b/test/unittest/data_ability_manager_test/BUILD.gn @@ -44,6 +44,7 @@ ohos_unittest("data_ability_manager_test") { } deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", diff --git a/test/unittest/form_extension_context_test/BUILD.gn b/test/unittest/form_extension_context_test/BUILD.gn index a01767b358..a6d02f5395 100644 --- a/test/unittest/form_extension_context_test/BUILD.gn +++ b/test/unittest/form_extension_context_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("form_extension_context_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${ability_runtime_native_path}/ability/native:ability_business_error", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index 55deb60a02..46dd2f4b73 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -93,6 +93,7 @@ ohos_unittest("ability_test") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", @@ -719,6 +720,7 @@ ohos_unittest("ability_process_test") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index 945f7570fa..e0ab90dea0 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -235,6 +235,7 @@ ohos_unittest("application_impl_test") { deps = [ "${ABILITY_INNERKITS_PATH}/uri_permission:uri_permission_mgr", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", @@ -411,6 +412,7 @@ ohos_unittest("form_extension_context_test") { configs = [ ":module_context_config" ] deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:form_extension", diff --git a/test/unittest/free_install_manager_test/BUILD.gn b/test/unittest/free_install_manager_test/BUILD.gn index 182b203fb2..9d167e1ada 100644 --- a/test/unittest/free_install_manager_test/BUILD.gn +++ b/test/unittest/free_install_manager_test/BUILD.gn @@ -41,6 +41,7 @@ ohos_unittest("free_install_manager_test") { } deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", diff --git a/test/unittest/lifecycle_test/BUILD.gn b/test/unittest/lifecycle_test/BUILD.gn index 2f9c5ecde8..452bb0c66a 100644 --- a/test/unittest/lifecycle_test/BUILD.gn +++ b/test/unittest/lifecycle_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("lifecycle_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", diff --git a/test/unittest/running_infos_test/BUILD.gn b/test/unittest/running_infos_test/BUILD.gn index 5f4896265b..5f8886a873 100644 --- a/test/unittest/running_infos_test/BUILD.gn +++ b/test/unittest/running_infos_test/BUILD.gn @@ -41,6 +41,7 @@ ohos_unittest("running_infos_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/specified_mission_list_test/BUILD.gn b/test/unittest/specified_mission_list_test/BUILD.gn index c561bc533c..c0aa2636d7 100644 --- a/test/unittest/specified_mission_list_test/BUILD.gn +++ b/test/unittest/specified_mission_list_test/BUILD.gn @@ -38,6 +38,7 @@ ohos_unittest("specified_mission_list_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", diff --git a/test/unittest/start_option_display_id_test/BUILD.gn b/test/unittest/start_option_display_id_test/BUILD.gn index 3484b95e3e..1d6664c0a2 100644 --- a/test/unittest/start_option_display_id_test/BUILD.gn +++ b/test/unittest/start_option_display_id_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("start_option_display_id_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn index 22bc2ac2fd..d1e6855ad7 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn @@ -31,6 +31,7 @@ ohos_unittest("ui_ability_lifecycle_manager_test") { sources = [ "ui_ability_lifecycle_manager_test.cpp" ] deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp index 442ac73e99..d1814e7beb 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp @@ -19,6 +19,7 @@ #define private public #define protected public #include "ability_record.h" +#include "ability_start_setting.h" #include "scene_board/ui_ability_lifecycle_manager.h" #undef protected #undef private @@ -126,6 +127,24 @@ HWTEST_F(UIAbilityLifecycleManagerTest, StartUIAbility_003, TestSize.Level1) EXPECT_EQ(mgr->StartUIAbility(abilityRequest, sessionInfo), ERR_OK); } +/** + * @tc.name: UIAbilityLifecycleManager_StartUIAbility_0400 + * @tc.desc: StartUIAbility + * @tc.type: FUNC + */ +HWTEST_F(UIAbilityLifecycleManagerTest, StartUIAbility_004, TestSize.Level1) +{ + auto mgr = std::make_unique(); + AbilityRequest abilityRequest; + Rosen::SessionInfo info; + sptr sessionInfo(new SessionInfo()); + sessionInfo->sessionToken = new Rosen::Session(info); + sessionInfo->startSetting = std::make_shared(); + sessionInfo->persistentId = 1; + abilityRequest.sessionInfo = sessionInfo; + EXPECT_EQ(mgr->StartUIAbility(abilityRequest, sessionInfo), ERR_OK); +} + /** * @tc.name: UIAbilityLifecycleManager_StartUIAbility_0500 * @tc.desc: StartUIAbility @@ -162,6 +181,20 @@ HWTEST_F(UIAbilityLifecycleManagerTest, StartUIAbility_006, TestSize.Level1) EXPECT_EQ(mgr->StartUIAbility(abilityRequest, sessionInfo), ERR_OK); } +/** + * @tc.name: UIAbilityLifecycleManager_CreateSessionInfo_0100 + * @tc.desc: CreateSessionInfo + * @tc.type: FUNC + */ +HWTEST_F(UIAbilityLifecycleManagerTest, CreateSessionInfo_001, TestSize.Level1) +{ + auto mgr = std::make_unique(); + EXPECT_NE(mgr, nullptr); + AbilityRequest abilityRequest; + abilityRequest.startSetting = std::make_shared(); + EXPECT_NE(mgr->CreateSessionInfo(abilityRequest), nullptr); +} + /** * @tc.name: UIAbilityLifecycleManager_AbilityTransactionDone_0100 * @tc.desc: AbilityTransactionDone diff --git a/tools/aa/BUILD.gn b/tools/aa/BUILD.gn index 0e5e43370f..d4118252e9 100644 --- a/tools/aa/BUILD.gn +++ b/tools/aa/BUILD.gn @@ -52,6 +52,7 @@ ohos_source_set("tools_aa_source_set") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/app_manager:app_manager", ] From b9989a0c224e0922b896e08ae55dc7167a95af03 Mon Sep 17 00:00:00 2001 From: shaoxianqiang <1018410944@qq.com> Date: Tue, 27 Jun 2023 16:09:32 +0800 Subject: [PATCH 17/52] =?UTF-8?q?=E6=B7=BB=E5=8A=A0appmgr:libappms?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shaoxianqiang <1018410944@qq.com> Change-Id: I0205488cd0268f96da6db09b8b0fc7cdc99afb3c --- test/unittest/ams_app_life_cycle_test/BUILD.gn | 1 + test/unittest/ams_app_workflow_test/BUILD.gn | 1 + test/unittest/ams_recent_app_list_test/BUILD.gn | 1 + test/unittest/ams_service_load_ability_process_test/BUILD.gn | 1 + test/unittest/app_mgr_service_event_handler_test/BUILD.gn | 1 + 5 files changed, 5 insertions(+) diff --git a/test/unittest/ams_app_life_cycle_test/BUILD.gn b/test/unittest/ams_app_life_cycle_test/BUILD.gn index 0ffa2686fc..912656eb17 100644 --- a/test/unittest/ams_app_life_cycle_test/BUILD.gn +++ b/test/unittest/ams_app_life_cycle_test/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("AmsAppLifeCycleTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", diff --git a/test/unittest/ams_app_workflow_test/BUILD.gn b/test/unittest/ams_app_workflow_test/BUILD.gn index b14bd3d7f2..43f68bdab1 100644 --- a/test/unittest/ams_app_workflow_test/BUILD.gn +++ b/test/unittest/ams_app_workflow_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_unittest("AmsWorkFlowTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/unittest:appmgr_test_source", diff --git a/test/unittest/ams_recent_app_list_test/BUILD.gn b/test/unittest/ams_recent_app_list_test/BUILD.gn index 98dcf60189..e12af6790b 100644 --- a/test/unittest/ams_recent_app_list_test/BUILD.gn +++ b/test/unittest/ams_recent_app_list_test/BUILD.gn @@ -51,6 +51,7 @@ ohos_unittest("AmsRecentAppListTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/unittest:appmgr_test_source", diff --git a/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/test/unittest/ams_service_load_ability_process_test/BUILD.gn index 3ff9fa9580..753ed47ac8 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -51,6 +51,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/unittest:appmgr_test_source", diff --git a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index d7057cbbe3..271485bc34 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_unittest("AMSEventHandlerTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/unittest:appmgr_test_source", From 7a31cb13d5edaf82420e3d809bcd20dbfcb52d57 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Tue, 27 Jun 2023 08:51:55 +0000 Subject: [PATCH 18/52] fix tdd Signed-off-by: liuyanzhi Change-Id: I2b1ace131067408e00ab19c2b19039f623e4d552 --- tools/test/unittest/aa/aa_command_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/test/unittest/aa/aa_command_test.cpp b/tools/test/unittest/aa/aa_command_test.cpp index b8b7029277..22935a604e 100644 --- a/tools/test/unittest/aa/aa_command_test.cpp +++ b/tools/test/unittest/aa/aa_command_test.cpp @@ -330,7 +330,7 @@ HWTEST_F(AaCommandTest, Aa_Command_1500, Function | MediumTest | Level1) std::string command = ""; const char* optarg = "profile abcd"; constexpr int32_t len = 32; - EXPECT_EQ(cmd.CheckPerfCmdString(optarg, len, command), true); + EXPECT_EQ(cmd.CheckPerfCmdString(optarg, len, command), false); } /** @@ -348,7 +348,7 @@ HWTEST_F(AaCommandTest, Aa_Command_1600, Function | MediumTest | Level1) std::string command = ""; const char* optarg = " profile abcd"; constexpr int32_t len = 32; - EXPECT_EQ(cmd.CheckPerfCmdString(optarg, len, command), true); + EXPECT_EQ(cmd.CheckPerfCmdString(optarg, len, command), false); } /** From adba152577ef3431c4dc52f79c06cf1a295bda30 Mon Sep 17 00:00:00 2001 From: donglin Date: Tue, 27 Jun 2023 08:52:41 +0000 Subject: [PATCH 19/52] add StopServiceAbility shell pass Signed-off-by: donglin Change-Id: I444673a4f287cfdce41348268059073b67f96c35 --- services/abilitymgr/src/ability_manager_service.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 4d50d04dcd..6721d55ffc 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -4289,7 +4289,8 @@ int AbilityManagerService::StopServiceAbility(const Want &want, int32_t userId, HILOG_DEBUG("call."); auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (!isSaCall) { + auto isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); + if (!isSaCall && !isShellCall) { auto abilityRecord = Token::GetAbilityRecordByToken(token); if (abilityRecord == nullptr) { HILOG_ERROR("callerRecord is nullptr"); From ccf7e3f57982e593f7c987bc4e50d45954cca7ab Mon Sep 17 00:00:00 2001 From: liuhanxiong Date: Tue, 27 Jun 2023 09:24:26 +0000 Subject: [PATCH 20/52] add sysDialog/userAuth type Signed-off-by: liuhanxiong Change-Id: I13dd323ef34297b846bea954ae1b6c094b11f78b --- frameworks/native/ability/native/ability_thread.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frameworks/native/ability/native/ability_thread.cpp b/frameworks/native/ability/native/ability_thread.cpp index 58168dd484..6b1cd931d0 100644 --- a/frameworks/native/ability/native/ability_thread.cpp +++ b/frameworks/native/ability/native/ability_thread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -53,6 +53,7 @@ constexpr static char ACE_FORM_ABILITY_NAME[] = "AceFormAbility"; constexpr static char FORM_EXTENSION[] = "FormExtension"; constexpr static char UI_EXTENSION[] = "UIExtensionAbility"; constexpr static char MEDIA_CONTROL_EXTENSION[] = "MediaControlExtensionAbility"; +constexpr static char USER_AUTH_EXTENSION[] = "UserAuthExtensionAbility"; #endif constexpr static char BASE_SERVICE_EXTENSION[] = "ServiceExtension"; constexpr static char BASE_DRIVER_EXTENSION[] = "DriverExtension"; @@ -177,6 +178,9 @@ std::string AbilityThread::CreateAbilityName(const std::shared_ptrextensionAbilityType == ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION) { abilityName = APP_ACCOUNT_AUTHORIZATION_EXTENSION; } + if (abilityInfo->extensionAbilityType == ExtensionAbilityType::SYSDIALOG_USERAUTH) { + abilityName = USER_AUTH_EXTENSION; + } HILOG_DEBUG("CreateAbilityName extension type, abilityName:%{public}s", abilityName.c_str()); } else { abilityName = abilityInfo->name; From 9cd7b9e593e18b86bb67d575ad1814cd28adcc9b Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Tue, 27 Jun 2023 16:29:02 +0800 Subject: [PATCH 21/52] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- frameworks/native/runtime/js_worker.cpp | 3 ++- js_environment/frameworks/js_environment/src/source_map.cpp | 2 -- .../interfaces/inner_api/src/service_info.cpp | 5 +++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/frameworks/native/runtime/js_worker.cpp b/frameworks/native/runtime/js_worker.cpp index 8f9e4176c5..bec507c85a 100644 --- a/frameworks/native/runtime/js_worker.cpp +++ b/frameworks/native/runtime/js_worker.cpp @@ -48,6 +48,7 @@ namespace { constexpr int64_t ASSET_FILE_MAX_SIZE = 32 * 1024 * 1024; const std::string BUNDLE_NAME_FLAG = "@bundle:"; const std::string CACHE_DIRECTORY = "el2"; +const int PATH_THREE = 3; #ifdef APP_USE_ARM constexpr char ARK_DEBUGGER_LIB_PATH[] = "/system/lib/libark_debugger.z.so"; #else @@ -161,7 +162,7 @@ void AssetHelper::operator()(const std::string& uri, std::vector& conte realPath = uri.substr(1); } else if (uri.find("../") == 0 && !workerInfo_->isStageModel) { HILOG_DEBUG("uri start with ../"); - realPath = uri.substr(3); + realPath = uri.substr(PATH_THREE); } else { HILOG_DEBUG("uri start with modulename"); realPath = uri; diff --git a/js_environment/frameworks/js_environment/src/source_map.cpp b/js_environment/frameworks/js_environment/src/source_map.cpp index 647e65e9ac..bd27bde4c6 100644 --- a/js_environment/frameworks/js_environment/src/source_map.cpp +++ b/js_environment/frameworks/js_environment/src/source_map.cpp @@ -109,7 +109,6 @@ std::string SourceMap::TranslateBySourceMap(const std::string& stackStr) ExtractStackInfo(stackStr, res); // collect error info first - bool needGetErrorPos = false; uint32_t i = 0; std::string codeStart = "SourceCode ("; std::string sourceCode = ""; @@ -119,7 +118,6 @@ std::string SourceMap::TranslateBySourceMap(const std::string& stackStr) if (fristLine.substr(0, codeStartLen).compare(codeStart) == 0) { sourceCode = fristLine.substr(codeStartLen, fristLine.length() - codeStartLen - 1); i = 1; // 1 means Convert from the second line - needGetErrorPos = true; } } diff --git a/service_router_framework/interfaces/inner_api/src/service_info.cpp b/service_router_framework/interfaces/inner_api/src/service_info.cpp index cf1a7e4a4b..dab7697a1b 100755 --- a/service_router_framework/interfaces/inner_api/src/service_info.cpp +++ b/service_router_framework/interfaces/inner_api/src/service_info.cpp @@ -20,6 +20,7 @@ namespace OHOS { namespace AbilityRuntime { +constexpr int32_t CYCLE_LIMIT = 1000; bool AppInfo::ReadFromParcel(Parcel &parcel) { bundleName = Str16ToStr8(parcel.ReadString16()); @@ -146,6 +147,10 @@ bool PurposeInfo::ReadFromParcel(Parcel &parcel) int32_t supportDimensionSize; READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportDimensionSize); CONTAINER_SECURITY_VERIFY(parcel, supportDimensionSize, &supportDimensions); + if (supportDimensionSize > CYCLE_LIMIT) { + APP_LOGE("supportDimensionSize is too large."); + return false; + } for (int32_t i = 0; i < supportDimensionSize; i++) { supportDimensions.emplace_back(parcel.ReadInt32()); } From a0f360afa674664636deb03e7c21416d41f2d9e7 Mon Sep 17 00:00:00 2001 From: l30047846 Date: Tue, 27 Jun 2023 19:23:04 +0800 Subject: [PATCH 22/52] =?UTF-8?q?=E6=B7=BB=E5=8A=A0memory=5Futils:libmemin?= =?UTF-8?q?fo=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l30047846 --- test/unittest/ams_ability_running_record_test/BUILD.gn | 1 + test/unittest/ams_app_life_cycle_test/BUILD.gn | 2 +- test/unittest/ams_app_workflow_test/BUILD.gn | 2 +- test/unittest/ams_recent_app_list_test/BUILD.gn | 2 +- test/unittest/ams_service_app_spawn_client_test/BUILD.gn | 1 + test/unittest/ams_service_event_drive_test/BUILD.gn | 1 + test/unittest/ams_service_load_ability_process_test/BUILD.gn | 2 +- test/unittest/ams_service_startup_test/BUILD.gn | 1 + test/unittest/app_mgr_service_event_handler_test/BUILD.gn | 2 +- test/unittest/app_running_processes_info_test/BUILD.gn | 1 + 10 files changed, 10 insertions(+), 5 deletions(-) diff --git a/test/unittest/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index b7ae7f10f2..7f555b6efa 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -65,6 +65,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", + "memory_utils:libmeminfo", "window_manager:libwm", ] } diff --git a/test/unittest/ams_app_life_cycle_test/BUILD.gn b/test/unittest/ams_app_life_cycle_test/BUILD.gn index 912656eb17..e59be76577 100644 --- a/test/unittest/ams_app_life_cycle_test/BUILD.gn +++ b/test/unittest/ams_app_life_cycle_test/BUILD.gn @@ -52,7 +52,6 @@ ohos_unittest("AmsAppLifeCycleTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", - "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", @@ -71,6 +70,7 @@ ohos_unittest("AmsAppLifeCycleTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", + "memory_utils:libmeminfo", ] } diff --git a/test/unittest/ams_app_workflow_test/BUILD.gn b/test/unittest/ams_app_workflow_test/BUILD.gn index 43f68bdab1..f111340315 100644 --- a/test/unittest/ams_app_workflow_test/BUILD.gn +++ b/test/unittest/ams_app_workflow_test/BUILD.gn @@ -48,7 +48,6 @@ ohos_unittest("AmsWorkFlowTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", - "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/unittest:appmgr_test_source", @@ -69,6 +68,7 @@ ohos_unittest("AmsWorkFlowTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", + "memory_utils:libmeminfo", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/ams_recent_app_list_test/BUILD.gn b/test/unittest/ams_recent_app_list_test/BUILD.gn index e12af6790b..02df2a3b43 100644 --- a/test/unittest/ams_recent_app_list_test/BUILD.gn +++ b/test/unittest/ams_recent_app_list_test/BUILD.gn @@ -51,7 +51,6 @@ ohos_unittest("AmsRecentAppListTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", - "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/unittest:appmgr_test_source", @@ -71,6 +70,7 @@ ohos_unittest("AmsRecentAppListTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", + "memory_utils:libmeminfo", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn index 61709853ea..7940923370 100644 --- a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn +++ b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn @@ -71,6 +71,7 @@ ohos_unittest("AmsServiceAppSpawnClientTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", + "memory_utils:libmeminfo", "window_manager:libwm", ] diff --git a/test/unittest/ams_service_event_drive_test/BUILD.gn b/test/unittest/ams_service_event_drive_test/BUILD.gn index b98ffb04ff..478172ce24 100644 --- a/test/unittest/ams_service_event_drive_test/BUILD.gn +++ b/test/unittest/ams_service_event_drive_test/BUILD.gn @@ -76,6 +76,7 @@ ohos_unittest("AmsServiceEventDriveTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", + "memory_utils:libmeminfo", "window_manager:libwm", ] } diff --git a/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/test/unittest/ams_service_load_ability_process_test/BUILD.gn index 753ed47ac8..c40b480720 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -51,7 +51,6 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", - "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/unittest:appmgr_test_source", @@ -72,6 +71,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", + "memory_utils:libmeminfo", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/ams_service_startup_test/BUILD.gn b/test/unittest/ams_service_startup_test/BUILD.gn index 17d88332f7..6a30357303 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -71,6 +71,7 @@ ohos_unittest("AmsServiceStartupTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", + "memory_utils:libmeminfo", "window_manager:libwm", ] } diff --git a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index 271485bc34..2079bd28c5 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -48,7 +48,6 @@ ohos_unittest("AMSEventHandlerTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", - "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/unittest:appmgr_test_source", @@ -72,6 +71,7 @@ ohos_unittest("AMSEventHandlerTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", + "memory_utils:libmeminfo", "window_manager:libwm", "window_manager:libwsutils", ] diff --git a/test/unittest/app_running_processes_info_test/BUILD.gn b/test/unittest/app_running_processes_info_test/BUILD.gn index 873d106283..2f66ec84c7 100644 --- a/test/unittest/app_running_processes_info_test/BUILD.gn +++ b/test/unittest/app_running_processes_info_test/BUILD.gn @@ -68,6 +68,7 @@ ohos_unittest("AppRunningProcessesInfoTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", + "memory_utils:libmeminfo", "window_manager:libwm", ] } From 896c01bfe177cc4e5550d6c9278c3ca04affd320 Mon Sep 17 00:00:00 2001 From: zhoushicheng Date: Tue, 27 Jun 2023 12:03:23 +0000 Subject: [PATCH 23/52] Issue:#I7GJ83 Signed-off-by: zhoushicheng --- .../abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1e58a8a386..d11bac9f61 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -1174,7 +1174,7 @@ int UIAbilityLifecycleManager::StartAbilityBySpecifed(const AbilityRequest &abil sessionInfo->requestCode = abilityRequest.requestCode; SpecifiedInfo specifiedInfo; specifiedInfo.abilityName = abilityRequest.abilityInfo.name; - specifiedInfo.abilityName = abilityRequest.abilityInfo.bundleName; + specifiedInfo.bundleName = abilityRequest.abilityInfo.bundleName; specifiedInfo.flag = abilityRequest.specifiedFlag; specifiedInfoQueue_.push(specifiedInfo); From eed2f956ed8175ff85777c8cbbcf408f8794cc3f Mon Sep 17 00:00:00 2001 From: xinking129 Date: Tue, 27 Jun 2023 21:18:54 +0800 Subject: [PATCH 24/52] add tdd test Signed-off-by: xinking129 --- test/unittest/BUILD.gn | 4 + .../ams_app_running_record_test.cpp | 38 ++- .../unittest/app_lifecycle_deal_test/BUILD.gn | 73 ++++++ .../app_lifecycle_deal_test.cpp | 76 ++++++ .../app_mgr_proxy_test/app_mgr_proxy_test.cpp | 34 ++- .../app_mgr_service_inner_tdd_test.cpp | 50 ++++ .../app_mgr_service_test.cpp | 48 +++- .../app_mgr_stub_test/app_mgr_stub_test.cpp | 53 ++++- .../unittest/app_scheduler_host_test/BUILD.gn | 70 ++++++ .../app_scheduler_host_test.cpp | 88 +++++++ .../app_scheduler_proxy_test/BUILD.gn | 70 ++++++ .../app_scheduler_proxy_test.cpp | 66 ++++++ .../app_scheduler_test/app_scheduler_test.cpp | 15 +- .../main_thread_test/main_thread_test.cpp | 17 ++ test/unittest/fault_data/BUILD.gn | 70 ++++++ test/unittest/fault_data/fault_data_test.cpp | 217 ++++++++++++++++++ .../watchdog_test.cpp | 19 +- 17 files changed, 1002 insertions(+), 6 deletions(-) create mode 100644 test/unittest/app_lifecycle_deal_test/BUILD.gn create mode 100644 test/unittest/app_lifecycle_deal_test/app_lifecycle_deal_test.cpp create mode 100644 test/unittest/app_scheduler_host_test/BUILD.gn create mode 100644 test/unittest/app_scheduler_host_test/app_scheduler_host_test.cpp create mode 100644 test/unittest/app_scheduler_proxy_test/BUILD.gn create mode 100644 test/unittest/app_scheduler_proxy_test/app_scheduler_proxy_test.cpp create mode 100644 test/unittest/fault_data/BUILD.gn create mode 100644 test/unittest/fault_data/fault_data_test.cpp diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index bdf03faacc..a3801a7848 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -325,7 +325,10 @@ group("unittest") { "app_mgr_stub_test:unittest", "app_recovery_test:unittest", "app_running_processes_info_test:unittest", + "app_scheduler_host_test:unittest", + "app_scheduler_proxy_test:unittest", "app_scheduler_test:unittest", + "app_lifecycle_deal_test:unittest", "app_spawn_client_test:unittest", "app_spawn_socket_test:unittest", "app_state_observer_manager_test:unittest", @@ -361,6 +364,7 @@ group("unittest") { "dummy_values_bucket_test:unittest", "event_report_test:unittest", "extension_config_mgr_test:unittest", + "fault_data:unittest", "file_path_utils_test:unittest", "form_extension_context_test:unittest", "frameworks_kits_ability_ability_runtime_test:unittest", diff --git a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp index b284bf9656..c3aaebea08 100644 --- a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp +++ b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -2690,5 +2690,41 @@ HWTEST_F(AmsAppRunningRecordTest, IsUIExtension_002, TestSize.Level1) EXPECT_EQ(otherRecord->IsUIExtension(), true); } + +/* + * Feature: AMS + * Function: NotifyAppFault + * SubFunction: NotifyAppFault + * FunctionPoints: check params + * EnvConditions: Mobile that can run ohos test framework + * CaseDescription: Ability Unfocused + */ +HWTEST_F(AmsAppRunningRecordTest, NotifyAppFault_001, TestSize.Level1) +{ + HILOG_DEBUG("NotifyAppFault_001 start."); + auto record = GetTestAppRunningRecord(); + FaultData faultData; + record->appLifeCycleDeal_ = nullptr; + EXPECT_EQ(ERR_INVALID_VALUE, record->NotifyAppFault(faultData)); + HILOG_DEBUG("NotifyAppFault_001 end."); +} + +/* + * Feature: AMS + * Function: NotifyAppFault + * SubFunction: NotifyAppFault + * FunctionPoints: check params + * EnvConditions: Mobile that can run ohos test framework + * CaseDescription: Ability Unfocused + */ +HWTEST_F(AmsAppRunningRecordTest, NotifyAppFault_002, TestSize.Level1) +{ + HILOG_DEBUG("NotifyAppFault_002 start."); + auto record = GetTestAppRunningRecord(); + FaultData faultData; + record->appLifeCycleDeal_ = std::make_shared(); + EXPECT_EQ(ERR_INVALID_VALUE, record->NotifyAppFault(faultData)); + HILOG_DEBUG("NotifyAppFault_002 end."); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_lifecycle_deal_test/BUILD.gn b/test/unittest/app_lifecycle_deal_test/BUILD.gn new file mode 100644 index 0000000000..173115974d --- /dev/null +++ b/test/unittest/app_lifecycle_deal_test/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/appmgrservice" + +ohos_unittest("app_lifecycle_deal_test") { + module_out_path = module_output_path + + configs = [ + "${ability_runtime_services_path}/common:common_config", + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + + include_dirs = [ + "${ability_runtime_test_path}/mock/common/include", + "${ability_runtime_test_path}/mock/services_appmgr_test/include", + "${ability_runtime_services_path}/abilitymgr/include", + "${ability_runtime_services_path}/appmgr/include", + "${ability_runtime_services_path}/appmgr/test/unittest/mocks", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", + ] + + sources = [ "app_lifecycle_deal_test.cpp" ] + + deps = [ + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:perm_verification", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:configuration", + "ability_base:session_info", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "init:libbeget_proxy", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":app_lifecycle_deal_test" ] +} diff --git a/test/unittest/app_lifecycle_deal_test/app_lifecycle_deal_test.cpp b/test/unittest/app_lifecycle_deal_test/app_lifecycle_deal_test.cpp new file mode 100644 index 0000000000..d38fe6320b --- /dev/null +++ b/test/unittest/app_lifecycle_deal_test/app_lifecycle_deal_test.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023 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 + +#define private public +#include "app_lifecycle_deal.h" +#include "mock_app_scheduler.h" +#undef private + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +class AppLifecycleDealTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void AppLifecycleDealTest::SetUpTestCase(void) +{} + +void AppLifecycleDealTest::TearDownTestCase(void) +{} + +void AppLifecycleDealTest::SetUp() +{} + +void AppLifecycleDealTest::TearDown() +{} + +/** + * @tc.name: NotifyAppFault_001 + * @tc.desc: Verify that the NotifyAppFault interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppLifecycleDealTest, NotifyAppFault_001, TestSize.Level1) +{ + auto appLifeCycle = std::make_shared(); + FaultData faultData; + int32_t result = appLifeCycle->NotifyAppFault(faultData); + EXPECT_EQ(result, ERR_INVALID_VALUE); +} + +/** + * @tc.name: NotifyAppFault_002 + * @tc.desc: Verify that the NotifyAppFault interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppLifecycleDealTest, NotifyAppFault_002, TestSize.Level1) +{ + auto appLifeCycle = std::make_shared(); + sptr mockAppScheduler = new (std::nothrow) MockAppScheduler(); + appLifeCycle->SetApplicationClient(mockAppScheduler); + FaultData faultData; + auto retsult = appLifeCycle->NotifyAppFault(faultData); + EXPECT_EQ(ERR_OK, retsult); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 60dbb3e989..13a60495f8 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -233,5 +233,37 @@ HWTEST_F(AppMgrProxyTest, PreStartNWebSpawnProcess_001, TestSize.Level0) HILOG_INFO("%{public}s end.", __func__); } + +/** + * @tc.name: NotifyAppFault_001 + * @tc.desc: Notify app fault. + * @tc.type: FUNC + * @tc.require: issueI79RY8 + */ +HWTEST_F(AppMgrProxyTest, NotifyAppFault_001, TestSize.Level0) +{ + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); + FaultData faultData; + appMgrProxy_->NotifyAppFault(faultData); + EXPECT_EQ(mockAppMgrService_->code_, static_cast(IAppMgr::Message::NOTIFY_APP_FAULT)); +} + +/** + * @tc.name: NotifyAppFaultBySA_001 + * @tc.desc: Notify app fault by SA. + * @tc.type: FUNC + * @tc.require: issueI79RY8 + */ +HWTEST_F(AppMgrProxyTest, NotifyAppFaultBySA_001, TestSize.Level0) +{ + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); + AppFaultDataBySA faultData; + appMgrProxy_->NotifyAppFaultBySA(faultData); + EXPECT_EQ(mockAppMgrService_->code_, static_cast(IAppMgr::Message::NOTIFY_APP_FAULT_BY_SA)); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp b/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp index 39b8c19626..6361461c83 100644 --- a/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp +++ b/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp @@ -442,5 +442,55 @@ HWTEST_F(AppMgrServiceInnerTest, UpDateStartupType_003, TestSize.Level1) EXPECT_EQ(expectedVal, extensionType); HILOG_INFO("UpDateStartupType_003 end"); } + +/** + * @tc.name: NotifyAppFault_001 + * @tc.desc: Verify that the NotifyAppFault interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, NotifyAppFault_001, TestSize.Level1) +{ + HILOG_INFO("NotifyAppFault_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + FaultData faultData; + EXPECT_EQ(ERR_INVALID_VALUE, appMgrServiceInner->NotifyAppFault(faultData)); + HILOG_INFO("NotifyAppFault_001 end"); +} + +/** + * @tc.name: NotifyAppFaultBySA_001 + * @tc.desc: Verify that the NotifyAppFaultBySA interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, NotifyAppFaultBySA_001, TestSize.Level1) +{ + HILOG_INFO("NotifyAppFaultBySA_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + AppFaultDataBySA faultData; + appMgrServiceInner->appRunningManager_ = nullptr; + EXPECT_EQ(ERR_INVALID_VALUE, appMgrServiceInner->NotifyAppFaultBySA(faultData)); + HILOG_INFO("NotifyAppFaultBySA_001 end"); +} + +/** + * @tc.name: FaultTypeToString_001 + * @tc.desc: Verify that the FaultTypeToString interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, FaultTypeToString_001, TestSize.Level1) +{ + HILOG_INFO("FaultTypeToString_001 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + EXPECT_EQ("CPP_CRASH", appMgrServiceInner->FaultTypeToString(AppExecFwk::FaultDataType::CPP_CRASH)); + EXPECT_EQ("JS_ERROR", appMgrServiceInner->FaultTypeToString(AppExecFwk::FaultDataType::JS_ERROR)); + EXPECT_EQ("APP_FREEZE", appMgrServiceInner->FaultTypeToString(AppExecFwk::FaultDataType::APP_FREEZE)); + EXPECT_EQ("PERFORMANCE_CONTROL", + appMgrServiceInner->FaultTypeToString(AppExecFwk::FaultDataType::PERFORMANCE_CONTROL)); + EXPECT_EQ("RESOURCE_CONTROL", appMgrServiceInner->FaultTypeToString(AppExecFwk::FaultDataType::RESOURCE_CONTROL)); + HILOG_INFO("FaultTypeToString_001 end"); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index eec1abf08e..3f5ca73c9c 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -1179,5 +1179,51 @@ HWTEST_F(AppMgrServiceTest, NotifyUnLoadRepairPatch_002, TestSize.Level0) int32_t res = appMgrService->NotifyUnLoadRepairPatch(bundleName, callback); EXPECT_NE(res, ERR_INVALID_OPERATION); } + +/** + * @tc.name: NotifyAppFault_001 + * @tc.desc: Verify that the NotifyAppFault interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, NotifyAppFault_001, TestSize.Level1) +{ + sptr appMgrService = new (std::nothrow)AppMgrService(); + appMgrService->SetInnerService(nullptr); + FaultData faultData; + int32_t res = appMgrService->NotifyAppFault(faultData); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/** + * @tc.name: NotifyAppFault_002 + * @tc.desc: Verify that the NotifyAppFault interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, NotifyAppFault_002, TestSize.Level1) +{ + sptr appMgrService = new (std::nothrow)AppMgrService(); + appMgrService->SetInnerService(nullptr); + AppFaultDataBySA faultData; + int32_t res = appMgrService->NotifyAppFaultBySA(faultData); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/** + * @tc.name: NotifyAppFault_003 + * @tc.desc: Verify that the NotifyAppFault interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, NotifyAppFault_003, TestSize.Level1) +{ + sptr appMgrService = new (std::nothrow)AppMgrService(); + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + AppFaultDataBySA faultData; + int32_t res = appMgrService->NotifyAppFaultBySA(faultData); + EXPECT_EQ(ERR_INVALID_VALUE, res); + appMgrService->appMgrServiceInner_ = nullptr; + res = appMgrService->NotifyAppFaultBySA(faultData); + EXPECT_EQ(ERR_INVALID_OPERATION, res); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index eb383447c4..a88912d930 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -218,5 +218,56 @@ HWTEST_F(AppMgrStubTest, PreStartNWebSpawnProcess_001, TestSize.Level0) HILOG_INFO("%{public}s end.", __func__); } + +/** + * @tc.name: HandleNotifyFault_001 + * @tc.desc: Handle notify fault. + * @tc.type: FUNC + * @tc.require: issueI79RY8 + */ +HWTEST_F(AppMgrStubTest, HandleNotifyFault_001, TestSize.Level0) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + WriteInterfaceToken(data); + FaultData faultData; + faultData.errorObject.name = "testName"; + faultData.errorObject.message = "testMessage"; + faultData.errorObject.stack = "testStack"; + faultData.faultType = FaultDataType::UNKNOWN; + data.WriteParcelable(&faultData); + EXPECT_CALL(*mockAppMgrService_, NotifyAppFault(_)).Times(1); + + auto result = mockAppMgrService_->OnRemoteRequest( + static_cast(IAppMgr::Message::NOTIFY_APP_FAULT), data, reply, option); + EXPECT_EQ(result, NO_ERROR); +} + +/** + * @tc.name: HandleNotifyFaultBySA_001 + * @tc.desc: Handle notify fault by SA. + * @tc.type: FUNC + * @tc.require: issueI79RY8 + */ +HWTEST_F(AppMgrStubTest, HandleNotifyFaultBySA_001, TestSize.Level0) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + WriteInterfaceToken(data); + AppFaultDataBySA faultData; + faultData.errorObject.name = "testName"; + faultData.errorObject.message = "testMessage"; + faultData.errorObject.stack = "testStack"; + faultData.faultType = FaultDataType::UNKNOWN; + faultData.pid = 24; + data.WriteParcelable(&faultData); + EXPECT_CALL(*mockAppMgrService_, NotifyAppFaultBySA(_)).Times(1); + + auto result = mockAppMgrService_->OnRemoteRequest( + static_cast(IAppMgr::Message::NOTIFY_APP_FAULT_BY_SA), data, reply, option); + EXPECT_EQ(result, NO_ERROR); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_scheduler_host_test/BUILD.gn b/test/unittest/app_scheduler_host_test/BUILD.gn new file mode 100644 index 0000000000..2bb8860418 --- /dev/null +++ b/test/unittest/app_scheduler_host_test/BUILD.gn @@ -0,0 +1,70 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/appmgrservice" + +ohos_unittest("app_scheduler_host_test") { + module_out_path = module_output_path + + configs = [ + "${ability_runtime_services_path}/common:common_config", + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + + include_dirs = [ + "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + "${ability_runtime_services_path}/appmgr/include", + "${ability_runtime_test_path}/mock/services_appmgr_test/include", + "${ability_runtime_test_path}/moduletest/mock/include", + ] + + sources = [ "app_scheduler_host_test.cpp" ] + + deps = [ + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:configuration", + "ability_base:session_info", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "init:libbeget_proxy", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":app_scheduler_host_test" ] +} diff --git a/test/unittest/app_scheduler_host_test/app_scheduler_host_test.cpp b/test/unittest/app_scheduler_host_test/app_scheduler_host_test.cpp new file mode 100644 index 0000000000..f1249ee2ac --- /dev/null +++ b/test/unittest/app_scheduler_host_test/app_scheduler_host_test.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2023 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 + +#define private public +#include "fault_data.h" +#include "message_parcel.h" +#include "mock_app_scheduler.h" +#undef private + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +class AppSchedulerHostTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + sptr mockAppScheduler_; + + void WriteInterfaceToken(MessageParcel& data); +}; + +void AppSchedulerHostTest::SetUpTestCase(void) +{} + +void AppSchedulerHostTest::TearDownTestCase(void) +{} + +void AppSchedulerHostTest::SetUp() +{ + GTEST_LOG_(INFO) << "AppSchedulerHostTest::SetUp()"; + + mockAppScheduler_ = new MockAppScheduler(); +} + +void AppSchedulerHostTest::TearDown() +{} + +void AppSchedulerHostTest::WriteInterfaceToken(MessageParcel& data) +{ + GTEST_LOG_(INFO) << "AppSchedulerHostTest::WriteInterfaceToken()"; + + data.WriteInterfaceToken(AppSchedulerHost::GetDescriptor()); +} + +/** + * @tc.name: HandleNotifyAppFault_001 + * @tc.desc: Verify that the HandleNotifyAppFault interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppSchedulerHostTest, HandleNotifyAppFault_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + WriteInterfaceToken(data); + FaultData faultData; + faultData.errorObject.name = "testName"; + faultData.errorObject.message = "testMessage"; + faultData.errorObject.stack = "testStack"; + faultData.faultType = FaultDataType::UNKNOWN; + data.WriteParcelable(&faultData); + EXPECT_CALL(*mockAppScheduler_, ScheduleNotifyAppFault(_)).Times(1); + + auto result = mockAppScheduler_->OnRemoteRequest( + static_cast(IAppScheduler::Message::SCHEDULE_NOTIFY_FAULT), data, reply, option); + EXPECT_EQ(result, NO_ERROR); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/app_scheduler_proxy_test/BUILD.gn b/test/unittest/app_scheduler_proxy_test/BUILD.gn new file mode 100644 index 0000000000..6d033a86bd --- /dev/null +++ b/test/unittest/app_scheduler_proxy_test/BUILD.gn @@ -0,0 +1,70 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/appmgrservice" + +ohos_unittest("app_scheduler_proxy_test") { + module_out_path = module_output_path + + configs = [ + "${ability_runtime_services_path}/common:common_config", + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + + include_dirs = [ + "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + "${ability_runtime_services_path}/appmgr/include", + "${ability_runtime_test_path}/mock/services_appmgr_test/include", + "${ability_runtime_test_path}/moduletest/mock/include", + ] + + sources = [ "app_scheduler_proxy_test.cpp" ] + + deps = [ + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:configuration", + "ability_base:session_info", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "init:libbeget_proxy", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":app_scheduler_proxy_test" ] +} diff --git a/test/unittest/app_scheduler_proxy_test/app_scheduler_proxy_test.cpp b/test/unittest/app_scheduler_proxy_test/app_scheduler_proxy_test.cpp new file mode 100644 index 0000000000..fa52c7ea4c --- /dev/null +++ b/test/unittest/app_scheduler_proxy_test/app_scheduler_proxy_test.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023 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 + +#define private public +#include "app_scheduler_proxy.h" +#include "fault_data.h" +#undef private + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +class AppSchedulerProxyTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void AppSchedulerProxyTest::SetUpTestCase(void) +{} + +void AppSchedulerProxyTest::TearDownTestCase(void) +{} + +void AppSchedulerProxyTest::SetUp() +{} + +void AppSchedulerProxyTest::TearDown() +{} + +/** + * @tc.name: ScheduleNotifyAppFault_001 + * @tc.desc: Verify that the ScheduleNotifyAppFault interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppSchedulerProxyTest, ScheduleNotifyAppFault_001, TestSize.Level1) +{ + sptr impl; + sptr appSchedulerProxy = new (std::nothrow)AppSchedulerProxy(impl); + FaultData faultData; + faultData.faultType = FaultDataType::APP_FREEZE; + faultData.errorObject.message = "msgContent"; + faultData.errorObject.stack = "stack"; + faultData.errorObject.name = "eventType"; + int32_t result = appSchedulerProxy->ScheduleNotifyAppFault(faultData); + EXPECT_EQ(result, ERR_NULL_OBJECT); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/app_scheduler_test/app_scheduler_test.cpp b/test/unittest/app_scheduler_test/app_scheduler_test.cpp index 9ae61eb842..3e044bb985 100644 --- a/test/unittest/app_scheduler_test/app_scheduler_test.cpp +++ b/test/unittest/app_scheduler_test/app_scheduler_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -1148,5 +1148,18 @@ HWTEST_F(AppSchedulerTest, AppScheduler_SetCurrentUserId_001, TestSize.Level1) ASSERT_NE(DelayedSingleton::GetInstance()->appMgrClient_, nullptr); DelayedSingleton::GetInstance()->SetCurrentUserId(userId); } + +/** + * @tc.name: AppScheduler_NotifyFault_001 + * @tc.desc: Verify that the NotifyFault interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(AppSchedulerTest, AppScheduler_NotifyFault_001, TestSize.Level1) +{ + AppExecFwk::FaultData faultData; + int res = DelayedSingleton::GetInstance()->NotifyFault(faultData); + EXPECT_EQ(res, INNER_ERR); +} + } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/appkit/main_thread_test/main_thread_test.cpp b/test/unittest/appkit/main_thread_test/main_thread_test.cpp index 901c097665..4bb3205865 100644 --- a/test/unittest/appkit/main_thread_test/main_thread_test.cpp +++ b/test/unittest/appkit/main_thread_test/main_thread_test.cpp @@ -2183,5 +2183,22 @@ HWTEST_F(MainThreadTest, HandleOnOverlayChanged_0100, TestSize.Level1) mainThread_->HandleOnOverlayChanged(data, resourceManager, bundleName, moduleName, loadPath); } + +/** + * @tc.name: ScheduleNotifyAppFault_0100 + * @tc.desc: Schedule notify app Fault. + * @tc.type: FUNC + * @tc.require: issueI79RY8 + */ +HWTEST_F(MainThreadTest, ScheduleNotifyAppFault_0100, TestSize.Level1) +{ + FaultData faultData; + faultData.faultType = FaultDataType::APP_FREEZE; + faultData.errorObject.message = "msgContent"; + faultData.errorObject.stack = "stack"; + faultData.errorObject.name = "eventType"; + auto ret = mainThread_->ScheduleNotifyAppFault(faultData); + EXPECT_EQ(ret, NO_ERROR); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/fault_data/BUILD.gn b/test/unittest/fault_data/BUILD.gn new file mode 100644 index 0000000000..4d7fe35999 --- /dev/null +++ b/test/unittest/fault_data/BUILD.gn @@ -0,0 +1,70 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/appmgrservice" + +ohos_unittest("fault_data_test") { + module_out_path = module_output_path + + configs = [ + "${ability_runtime_services_path}/common:common_config", + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + + include_dirs = [ + "${ability_runtime_test_path}/mock/common/include", + "${ability_runtime_services_path}/abilitymgr/include", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", + "${ability_runtime_services_path}/appmgr/test/unittest/mocks", + ] + + sources = [ "fault_data_test.cpp" ] + + deps = [ + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:configuration", + "ability_base:session_info", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:app_manager", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "init:libbeget_proxy", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":fault_data_test" ] +} diff --git a/test/unittest/fault_data/fault_data_test.cpp b/test/unittest/fault_data/fault_data_test.cpp new file mode 100644 index 0000000000..14bc81f135 --- /dev/null +++ b/test/unittest/fault_data/fault_data_test.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2023 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 + +#define private public +#include "fault_data.h" +#include "message_parcel.h" +#undef private + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +class FaultDataTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void FaultDataTest::SetUpTestCase(void) +{} + +void FaultDataTest::TearDownTestCase(void) +{} + +void FaultDataTest::SetUp() +{} + +void FaultDataTest::TearDown() +{} + +/** + * @tc.name: ReadFromParcel_001 + * @tc.desc: Verify that the ReadFromParcel interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(FaultDataTest, ReadFromParcel_001, TestSize.Level1) +{ + auto faultData = std::make_shared(); + MessageParcel messageFirst; + bool retFirst = faultData->ReadFromParcel(messageFirst); + EXPECT_EQ(false, retFirst); + + MessageParcel messageSecond; + std::string helloWord = "HelloWord"; + messageSecond.WriteString(helloWord); + bool retSecond = faultData->ReadFromParcel(messageSecond); + EXPECT_EQ(false, retSecond); + + MessageParcel messageThird; + messageThird.WriteString(helloWord); + messageThird.WriteString(helloWord); + bool retThird = faultData->ReadFromParcel(messageThird); + EXPECT_EQ(false, retThird); + + MessageParcel messageFourth; + messageFourth.WriteString(helloWord); + messageFourth.WriteString(helloWord); + messageFourth.WriteString(helloWord); + bool retFourth = faultData->ReadFromParcel(messageFourth); + EXPECT_EQ(false, retFourth); + + MessageParcel messageFifth; + messageFifth.WriteString(helloWord); + messageFifth.WriteString(helloWord); + messageFifth.WriteString(helloWord); + messageFifth.WriteInt32(12); + bool retFifth = faultData->ReadFromParcel(messageFifth); + EXPECT_EQ(true, retFifth); +} + +/** + * @tc.name: Unmarshalling_001 + * @tc.desc: Verify that the Unmarshalling interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(FaultDataTest, Unmarshalling_001, TestSize.Level1) +{ + auto faultData = std::make_shared(); + MessageParcel message; + auto retFirst = faultData->Unmarshalling(message); + EXPECT_EQ(nullptr, retFirst); + + std::string helloWord = "HelloWord"; + message.WriteString(helloWord); + message.WriteString(helloWord); + message.WriteString(helloWord); + message.WriteInt32(12); + auto retSecond = faultData->Unmarshalling(message); + EXPECT_NE(nullptr, retSecond); +} + +/** + * @tc.name: Marshalling_001 + * @tc.desc: Verify that the Marshalling interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(FaultDataTest, Marshalling_001, TestSize.Level1) +{ + auto faultData = std::make_shared(); + faultData->errorObject.name = "1234"; + faultData->errorObject.message = "5678"; + faultData->errorObject.stack = "90"; + + MessageParcel message; + bool ret = faultData->Marshalling(message); + EXPECT_EQ(true, ret); +} + +/** + * @tc.name: ReadFromParcel_002 + * @tc.desc: Verify that the ReadFromParcel interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(FaultDataTest, ReadFromParcel_002, TestSize.Level1) +{ + auto appFaultDataBySA = std::make_shared(); + MessageParcel messageFirst; + bool retFirst = appFaultDataBySA->ReadFromParcel(messageFirst); + EXPECT_EQ(false, retFirst); + + MessageParcel messageSecond; + std::string helloWord = "HelloWord"; + messageSecond.WriteString(helloWord); + bool retSecond = appFaultDataBySA->ReadFromParcel(messageSecond); + EXPECT_EQ(false, retSecond); + + MessageParcel messageThird; + + messageThird.WriteString(helloWord); + messageThird.WriteString(helloWord); + bool retThird = appFaultDataBySA->ReadFromParcel(messageThird); + EXPECT_EQ(false, retThird); + + MessageParcel messageFourth; + messageFourth.WriteString(helloWord); + messageFourth.WriteString(helloWord); + messageFourth.WriteString(helloWord); + bool retFourth = appFaultDataBySA->ReadFromParcel(messageFourth); + EXPECT_EQ(false, retFourth); + + MessageParcel messageFifth; + messageFifth.WriteString(helloWord); + messageFifth.WriteString(helloWord); + messageFifth.WriteString(helloWord); + messageFifth.WriteInt32(12); + bool retFifth = appFaultDataBySA->ReadFromParcel(messageFifth); + EXPECT_EQ(false, retFifth); + + MessageParcel messageSixth; + messageSixth.WriteString(helloWord); + messageSixth.WriteString(helloWord); + messageSixth.WriteString(helloWord); + messageSixth.WriteInt32(12); + messageSixth.WriteInt32(34); + bool retSixth = appFaultDataBySA->ReadFromParcel(messageSixth); + EXPECT_EQ(true, retSixth); +} + +/** + * @tc.name: Unmarshalling_002 + * @tc.desc: Verify that the Unmarshalling interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(FaultDataTest, Unmarshalling_002, TestSize.Level1) +{ + auto appFaultDataBySA = std::make_shared(); + MessageParcel message; + auto retFirst = appFaultDataBySA->Unmarshalling(message); + EXPECT_EQ(nullptr, retFirst); + + std::string helloWord = "HelloWord"; + message.WriteString(helloWord); + message.WriteString(helloWord); + message.WriteString(helloWord); + message.WriteInt32(12); + message.WriteInt32(34); + message.WriteInt32(56); + message.WriteString(helloWord); + auto retSecond = appFaultDataBySA->Unmarshalling(message); + EXPECT_NE(nullptr, retSecond); +} + +/** + * @tc.name: Marshalling_002 + * @tc.desc: Verify that the Marshalling interface calls normally + * @tc.type: FUNC + */ +HWTEST_F(FaultDataTest, Marshalling_002, TestSize.Level1) +{ + auto appFaultDataBySA = std::make_shared(); + appFaultDataBySA->errorObject.name = "1234"; + appFaultDataBySA->errorObject.message = "5678"; + appFaultDataBySA->errorObject.stack = "90"; + + MessageParcel message; + bool ret = appFaultDataBySA->Marshalling(message); + EXPECT_EQ(true, ret); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/frameworks_kits_appkit_native_test/watchdog_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/watchdog_test.cpp index 5d53128bb1..4e1c4dec2d 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/watchdog_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/watchdog_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -480,5 +480,22 @@ HWTEST_F(WatchdogTest, WatchdogTest_GetTag_001, TestSize.Level1) EXPECT_EQ(mainHandlerDumper_->GetTag(), ""); GTEST_LOG_(INFO) << "WatchdogTest_GetTag_001 end"; } + +/** + * @tc.number: WatchdogTest_ReportEvent_008 + * @tc.name: ReportEvent + * @tc.desc: Verify that function ReportEvent. + */ +HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_008, TestSize.Level1) +{ + watchdog_->lastWatchTime_ = std::chrono::duration_cast(std::chrono:: + system_clock::now().time_since_epoch()).count() - TEST_INTERVAL_TIME; + std::shared_ptr eventHandler = std::make_shared(); + watchdog_->applicationInfo_ = std::make_shared(); + watchdog_->needReport_ = true; + watchdog_->isSixSecondEvent_.store(true); + EXPECT_TRUE(watchdog_->needReport_); + watchdog_->ReportEvent(); +} } // namespace AppExecFwk } // namespace OHOS From aacce811cbae743dd14953134a3f83fb7c3f3468 Mon Sep 17 00:00:00 2001 From: zhoushicheng Date: Tue, 20 Jun 2023 11:40:30 +0000 Subject: [PATCH 25/52] Issue:#I7F1G1 Signed-off-by: zhoushicheng Change-Id: Id465f6ca69a3b470252c8523dd02d0759f3a35c5 --- .../src/ability_manager_service.cpp | 20 +++++++++++-------- services/abilitymgr/src/user_controller.cpp | 5 +++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 4d50d04dcd..b9d64e5a2a 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -5486,7 +5486,9 @@ void AbilityManagerService::UserStarted(int32_t userId) { HILOG_INFO("%{public}s", __func__); InitConnectManager(userId, false); - InitMissionListManager(userId, false); + if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + InitMissionListManager(userId, false); + } InitDataAbilityManager(userId, false); InitPendWantManager(userId, false); } @@ -5495,13 +5497,15 @@ void AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId) { HILOG_INFO("%{public}s, oldUserId:%{public}d, newUserId:%{public}d", __func__, oldUserId, userId); SwitchManagers(userId); - PauseOldUser(oldUserId); - bool isBoot = false; - if (oldUserId == U0_USER_ID) { - isBoot = true; + if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + PauseOldUser(oldUserId); + bool isBoot = false; + if (oldUserId == U0_USER_ID) { + isBoot = true; + } + ConnectBmsService(); + StartUserApps(userId, isBoot); } - ConnectBmsService(); - StartUserApps(userId, isBoot); PauseOldConnectManager(oldUserId); } @@ -5509,7 +5513,7 @@ void AbilityManagerService::SwitchManagers(int32_t userId, bool switchUser) { HILOG_INFO("%{public}s, SwitchManagers:%{public}d-----begin", __func__, userId); InitConnectManager(userId, switchUser); - if (userId != U0_USER_ID) { + if (userId != U0_USER_ID && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { InitMissionListManager(userId, switchUser); } InitDataAbilityManager(userId, switchUser); diff --git a/services/abilitymgr/src/user_controller.cpp b/services/abilitymgr/src/user_controller.cpp index 1de1a085df..78de38dcbe 100644 --- a/services/abilitymgr/src/user_controller.cpp +++ b/services/abilitymgr/src/user_controller.cpp @@ -20,6 +20,7 @@ #include "hilog_wrapper.h" #include "ipc_skeleton.h" #include "os_account_manager_wrapper.h" +#include "scene_board_judgement.h" #include "task_data_persistence_mgr.h" namespace OHOS { @@ -96,7 +97,7 @@ int32_t UserController::StartUser(int32_t userId, bool isForeground) return -1; } - if (isForeground && GetCurrentUserId() != USER_ID_NO_HEAD) { + if (isForeground && GetCurrentUserId() != USER_ID_NO_HEAD && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { // start freezing screen DelayedSingleton::GetInstance()->StartFreezingScreen(); } @@ -464,7 +465,7 @@ void UserController::HandleContinueUserSwitch(int32_t oldUserId, int32_t newUser std::shared_ptr &usrItem) { auto manager = DelayedSingleton::GetInstance(); - if (manager) { + if (manager && !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { manager->StopFreezingScreen(); } SendUserSwitchDone(newUserId); From a6dc248c04aa1d133202596dcf591f20f959c760 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Mon, 26 Jun 2023 09:23:17 +0800 Subject: [PATCH 26/52] Ffrt adaptation (mutex and tsk) Signed-off-by: wangzhen --- bundle.json | 1 + .../ability_runtime/context/context_impl.cpp | 1 + frameworks/native/appkit/app/main_thread.cpp | 1 + .../inner_api/wantagent/src/pending_want.cpp | 1 - .../srms/src/service_router_mgr_service.cpp | 1 + services/abilitymgr/BUILD.gn | 3 +- .../include/ability_bundle_event_callback.h | 7 +- .../include/ability_connect_manager.h | 22 +- .../include/ability_event_handler.h | 9 +- .../include/ability_manager_service.h | 20 +- services/abilitymgr/include/ability_record.h | 10 +- .../include/connection_observer_controller.h | 3 +- .../include/connection_state_manager.h | 11 +- .../abilitymgr/include/data_ability_manager.h | 3 +- .../abilitymgr/include/data_ability_record.h | 7 +- .../abilitymgr/include/free_install_manager.h | 7 +- .../include/free_install_observer_manager.h | 3 +- .../abilitymgr/include/mission_data_storage.h | 7 +- .../abilitymgr/include/mission_info_mgr.h | 9 +- .../abilitymgr/include/mission_list_manager.h | 3 +- .../include/mission_listener_controller.h | 10 +- .../abilitymgr/include/pending_want_manager.h | 3 +- .../abilitymgr/include/pending_want_record.h | 3 +- .../ui_ability_lifecycle_manager.h | 3 +- .../include/task_data_persistence_mgr.h | 8 +- services/abilitymgr/include/user_controller.h | 9 +- .../abilitymgr/include/user_event_handler.h | 9 +- .../include/window_focus_changed_listener.h | 6 +- .../src/ability_bundle_event_callback.cpp | 17 +- .../src/ability_connect_manager.cpp | 76 +++--- .../abilitymgr/src/ability_event_handler.cpp | 21 +- .../src/ability_manager_service.cpp | 152 +++++------ services/abilitymgr/src/ability_record.cpp | 58 ++--- services/abilitymgr/src/call_container.cpp | 5 +- services/abilitymgr/src/call_record.cpp | 5 +- .../src/connection_observer_controller.cpp | 8 +- services/abilitymgr/src/connection_record.cpp | 24 +- .../src/connection_state_manager.cpp | 26 +- .../abilitymgr/src/data_ability_manager.cpp | 24 +- .../abilitymgr/src/data_ability_record.cpp | 6 +- .../abilitymgr/src/free_install_manager.cpp | 33 ++- .../src/free_install_observer_manager.cpp | 16 +- .../abilitymgr/src/mission_data_storage.cpp | 11 +- services/abilitymgr/src/mission_info_mgr.cpp | 46 ++-- .../abilitymgr/src/mission_list_manager.cpp | 91 +++---- .../src/mission_listener_controller.cpp | 29 +-- .../abilitymgr/src/pending_want_manager.cpp | 16 +- .../abilitymgr/src/pending_want_record.cpp | 2 +- .../ui_ability_lifecycle_manager.cpp | 68 ++--- .../src/task_data_persistence_mgr.cpp | 32 +-- services/abilitymgr/src/user_controller.cpp | 65 ++--- .../abilitymgr/src/user_event_handler.cpp | 11 +- .../src/window_focus_changed_listener.cpp | 8 +- services/appmgr/BUILD.gn | 3 +- services/appmgr/include/ams_mgr_scheduler.h | 7 +- services/appmgr/include/app_death_recipient.h | 6 +- services/appmgr/include/app_mgr_service.h | 6 +- .../include/app_mgr_service_event_handler.h | 9 +- .../appmgr/include/app_mgr_service_inner.h | 24 +- services/appmgr/include/app_running_manager.h | 3 +- services/appmgr/include/app_running_record.h | 17 +- .../include/app_state_observer_manager.h | 6 +- .../appmgr/include/module_running_record.h | 3 +- .../include/window_focus_changed_listener.h | 6 +- services/appmgr/src/ams_mgr_scheduler.cpp | 27 +- services/appmgr/src/app_death_recipient.cpp | 4 +- services/appmgr/src/app_mgr_service.cpp | 70 +++-- .../src/app_mgr_service_event_handler.cpp | 13 +- services/appmgr/src/app_mgr_service_inner.cpp | 90 +++---- services/appmgr/src/app_running_manager.cpp | 66 ++--- services/appmgr/src/app_running_record.cpp | 82 ++++-- .../appmgr/src/app_state_observer_manager.cpp | 46 ++-- services/appmgr/src/module_running_record.cpp | 24 +- .../src/window_focus_changed_listener.cpp | 10 +- services/common/BUILD.gn | 21 ++ services/common/include/event_handler_wrap.h | 109 ++++++++ services/common/include/task_handler_wrap.h | 100 +++++++ services/common/include/task_utils_wrap.h | 51 ++++ services/common/src/event_handler_wrap.cpp | 103 ++++++++ .../common/src/ffrt_task_handler_wrap.cpp | 66 +++++ services/common/src/ffrt_task_handler_wrap.h | 36 +++ services/common/src/ffrt_task_utils_wrap.h | 44 ++++ .../common/src/queue_task_handler_wrap.cpp | 53 ++++ services/common/src/queue_task_handler_wrap.h | 39 +++ services/common/src/task_handler_wrap.cpp | 196 ++++++++++++++ services/dataobsmgr/BUILD.gn | 9 +- .../dataobsmgr/include/dataobs_mgr_inner.h | 5 +- .../include/dataobs_mgr_inner_ext.h | 5 +- .../dataobsmgr/include/dataobs_mgr_service.h | 19 +- services/dataobsmgr/src/dataobs_mgr_inner.cpp | 8 +- .../dataobsmgr/src/dataobs_mgr_inner_ext.cpp | 10 +- .../dataobsmgr/src/dataobs_mgr_service.cpp | 40 +-- .../abilityattachtimeout_fuzzer/BUILD.gn | 1 + .../abilityconnectmanager_fuzzer/BUILD.gn | 2 +- test/fuzztest/abilitycontext_fuzzer/BUILD.gn | 1 + .../abilityeventhandler_fuzzer/BUILD.gn | 2 +- .../abilityeventhandler_fuzzer.cpp | 2 +- test/fuzztest/abilitymanager_fuzzer/BUILD.gn | 1 + .../abilitymanagerservicea_fuzzer/BUILD.gn | 2 +- .../abilitymanagerserviceb_fuzzer/BUILD.gn | 2 +- .../abilitymanagerservicec_fuzzer/BUILD.gn | 2 +- .../abilitymanagerserviced_fuzzer/BUILD.gn | 2 +- .../abilitymanagerservicee_fuzzer/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../abilitymanagerservicef_fuzzer/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../abilitymanagerserviceg_fuzzer/BUILD.gn | 2 +- .../abilitymanagerserviceh_fuzzer/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- test/fuzztest/abilitymgrrest_fuzzer/BUILD.gn | 1 + .../abilityrunningrecord_fuzzer/BUILD.gn | 1 + .../abilitytransitiondone_fuzzer/BUILD.gn | 1 + .../acquiredataability_fuzzer/BUILD.gn | 1 + .../addabilitystagedone_fuzzer.cpp | 1 - test/fuzztest/amsmanager_fuzzer/BUILD.gn | 4 +- .../amsmanager_fuzzer/amsmanager_fuzzer.cpp | 4 +- test/fuzztest/amsmgrscheduler_fuzzer/BUILD.gn | 1 + .../amsmgrscheduler_fuzzer.cpp | 2 +- .../applicationanrlistener_fuzzer/BUILD.gn | 2 +- .../fuzztest/applifecycledeal_fuzzer/BUILD.gn | 1 + test/fuzztest/appmanager_fuzzer/BUILD.gn | 3 +- test/fuzztest/appmgrrest_fuzzer/BUILD.gn | 1 + .../appmgrrest_fuzzer/appmgrrest_fuzzer.cpp | 4 +- .../appmgrservicefirst_fuzzer/BUILD.gn | 1 + .../appmgrserviceinnerfirst_fuzzer/BUILD.gn | 1 + .../appmgrserviceinnerfirst_fuzzer.cpp | 1 - .../appmgrserviceinnersecond_fuzzer/BUILD.gn | 1 + .../apprunningmanager_fuzzer/BUILD.gn | 1 + .../apprunningrecordfirst_fuzzer/BUILD.gn | 1 + .../apprunningrecordsecond_fuzzer/BUILD.gn | 1 + .../appstateobservermanager_fuzzer/BUILD.gn | 1 + .../attachabilitythread_fuzzer/BUILD.gn | 2 +- .../attachrenderprocess_fuzzer.cpp | 1 - test/fuzztest/blockability_fuzzer/BUILD.gn | 2 +- test/fuzztest/blockamsservice_fuzzer/BUILD.gn | 2 +- test/fuzztest/blockappservice_fuzzer/BUILD.gn | 2 +- test/fuzztest/closeability_fuzzer/BUILD.gn | 1 + .../completefirstframedrawing_fuzzer/BUILD.gn | 2 +- .../connectionobserverclient_fuzzer/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../connectionstatemanager_fuzzer/BUILD.gn | 2 +- .../dataabilitymanager_fuzzer/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../doabilitybackground_fuzzer/BUILD.gn | 2 +- .../doabilityforeground_fuzzer/BUILD.gn | 2 +- .../dumpabilityinfodone_fuzzer/BUILD.gn | 2 +- test/fuzztest/dumpstate_fuzzer/BUILD.gn | 2 +- test/fuzztest/dumpsysstate_fuzzer/BUILD.gn | 2 +- .../forcetimeoutfortest_fuzzer/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../fuzztest/getconfiguration_fuzzer/BUILD.gn | 1 + .../getmissionidbytoken_fuzzer/BUILD.gn | 2 +- .../getmissionsnapshot_fuzzer/BUILD.gn | 2 +- .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + test/fuzztest/gettopability_fuzzer/BUILD.gn | 1 + test/fuzztest/getwantsender_fuzzer/BUILD.gn | 1 + test/fuzztest/handledlpapp_fuzzer/BUILD.gn | 2 +- test/fuzztest/killapplication_fuzzer/BUILD.gn | 1 + .../killapplicationself_fuzzer/BUILD.gn | 1 + .../killprocessbyabilitytoken_fuzzer/BUILD.gn | 1 + .../killprocessesbyuserid_fuzzer/BUILD.gn | 1 + test/fuzztest/loadability_fuzzer/BUILD.gn | 1 + test/fuzztest/minimizeability_fuzzer/BUILD.gn | 2 +- .../missiondatastoragea_fuzzer/BUILD.gn | 2 +- .../missiondatastoragea_fuzzer.cpp | 2 - .../missiondatastorageb_fuzzer/BUILD.gn | 2 +- test/fuzztest/missioninfomgra_fuzzer/BUILD.gn | 2 +- test/fuzztest/missioninfomgrb_fuzzer/BUILD.gn | 2 +- test/fuzztest/missioninfomgrc_fuzzer/BUILD.gn | 2 +- .../missionlistmanagerfirst_fuzzer/BUILD.gn | 2 +- .../missionlistmanagerfourth_fuzzer/BUILD.gn | 2 +- .../missionlistmanagersecond_fuzzer/BUILD.gn | 2 +- .../missionlistmanagerthird_fuzzer/BUILD.gn | 2 +- .../modulerunningrecord_fuzzer/BUILD.gn | 1 + .../notifymemorylevel_fuzzer/BUILD.gn | 1 + .../pendingwantmanager_fuzzer/BUILD.gn | 2 +- .../fuzztest/prepareterminate_fuzzer/BUILD.gn | 1 + .../prestartnwebspawnprocess_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 2 +- .../BUILD.gn | 1 + .../releasedataability_fuzzer/BUILD.gn | 2 +- .../scheduleacceptwantdone_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../sendresulttoability_fuzzer/BUILD.gn | 1 + .../setabilitycontroller_fuzzer/BUILD.gn | 2 +- test/fuzztest/setmissionicon_fuzzer/BUILD.gn | 1 + test/fuzztest/setmissionlabel_fuzzer/BUILD.gn | 1 + test/fuzztest/startability_fuzzer/BUILD.gn | 1 + .../startabilitybycall_fuzzer/BUILD.gn | 2 +- .../startcontinuation_fuzzer/BUILD.gn | 1 + .../startrenderprocess_fuzzer/BUILD.gn | 1 + .../startspecifiedability_fuzzer/BUILD.gn | 1 + .../startupresidentprocess_fuzzer/BUILD.gn | 1 + .../startusertest_fuzzer.cpp | 2 - .../startusertestprocess_fuzzer/BUILD.gn | 1 + .../fuzztest/terminateability_fuzzer/BUILD.gn | 1 + .../terminateabilityresult_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 3 +- .../updateabilitystate_fuzzer/BUILD.gn | 1 + .../updateextensionstate_fuzzer/BUILD.gn | 1 + .../updatemissionsnapshot_fuzzer/BUILD.gn | 2 +- .../appmgr_test_service/BUILD.gn | 2 +- .../libs/aakit/BUILD.gn | 2 +- .../src/appmgr/mock_app_scheduler.cpp | 1 - .../BUILD.gn | 2 +- test/moduletest/ability_record_test/BUILD.gn | 2 +- .../ability_timeout_module_test/BUILD.gn | 9 +- .../ability_timeout_module_test.cpp | 17 +- test/moduletest/call_module_test/BUILD.gn | 3 +- .../call_ability_service_module_test.cpp | 13 +- test/moduletest/common/ams/BUILD.gn | 7 +- .../ams/ability_running_record_test/BUILD.gn | 1 + .../common/ams/app_life_cycle_test/BUILD.gn | 6 +- .../ams_app_life_cycle_module_test.cpp | 5 +- .../common/ams/app_mgr_service_test/BUILD.gn | 1 + .../common/ams/app_recent_list_test/BUILD.gn | 2 + .../BUILD.gn | 1 + .../ams/app_running_record_test/BUILD.gn | 1 + .../common/ams/app_service_flow_test/BUILD.gn | 2 + .../ams_app_service_flow_module_test.cpp | 5 +- .../common/ams/ipc_ams_mgr_test/BUILD.gn | 3 +- .../ams_ipc_ams_mgr_module_test.cpp | 34 +-- .../service_app_spawn_client_test/BUILD.gn | 1 + .../ams/service_event_drive_test/BUILD.gn | 5 +- .../ams/service_start_process_test/BUILD.gn | 1 + .../specified_ability_service_test/BUILD.gn | 5 +- .../specified_ability_service_test.cpp | 4 +- test/moduletest/ipc_ability_mgr_test/BUILD.gn | 1 + test/moduletest/mission_dump_test/BUILD.gn | 2 +- .../on_new_want_module_test/BUILD.gn | 5 +- .../panding_want_manager_test/BUILD.gn | 2 +- .../running_infos_module_test/BUILD.gn | 8 +- .../running_infos_module_test.cpp | 17 +- .../BUILD.gn | 2 + .../start_ability_implicit_module_test.cpp | 9 +- .../start_option_display_id_test/BUILD.gn | 3 +- .../start_option_display_id_test.cpp | 17 +- test/unittest/BUILD.gn | 5 +- .../BUILD.gn | 2 +- .../BUILD.gn | 4 +- .../ability_connect_manager_test/BUILD.gn | 3 +- .../ability_connect_manager_test.cpp | 244 ++++++++++-------- .../ability_event_handler_test/BUILD.gn | 3 +- .../ability_event_handler_test.cpp | 16 +- .../ability_interceptor_test/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../ability_manager_proxy_test/BUILD.gn | 2 +- .../BUILD.gn | 3 +- .../ability_manager_service_account_test.cpp | 4 +- .../ability_manager_service_anr_test/BUILD.gn | 2 + .../ability_manager_service_anr_test.cpp | 12 +- .../BUILD.gn | 1 + .../BUILD.gn | 2 +- .../ability_manager_service_test/BUILD.gn | 3 +- .../ability_manager_service_test.cpp | 24 +- .../ability_manager_stub_test/BUILD.gn | 3 +- .../ability_record_dump_test/BUILD.gn | 1 + test/unittest/ability_record_test/BUILD.gn | 4 +- .../ability_record_test.cpp | 1 - .../ability_scheduler_proxy_test/BUILD.gn | 2 +- .../ability_scheduler_stub_test/BUILD.gn | 2 +- .../ability_service_start_test/BUILD.gn | 2 +- test/unittest/ability_timeout_test/BUILD.gn | 3 +- .../ability_timeout_test.cpp | 19 +- .../ability_token_proxy_test/BUILD.gn | 2 +- .../unittest/ability_token_stub_test/BUILD.gn | 2 +- .../ams_ability_running_record_test/BUILD.gn | 3 +- .../ams_ability_running_record_test.cpp | 14 +- .../ams_app_death_recipient_test/BUILD.gn | 3 +- .../ams_app_death_recipient_test.cpp | 16 +- .../unittest/ams_app_life_cycle_test/BUILD.gn | 3 +- .../ams_app_life_cycle_test.cpp | 21 +- .../unittest/ams_app_mgr_client_test/BUILD.gn | 2 +- .../ams_app_running_record_test/BUILD.gn | 3 +- .../ams_app_running_record_test.cpp | 15 +- test/unittest/ams_app_workflow_test/BUILD.gn | 3 +- .../ams_workflow_test.cpp | 5 +- .../ams_mgr_kill_process_test/BUILD.gn | 3 +- test/unittest/ams_mgr_proxy_test/BUILD.gn | 3 +- .../ams_mgr_scheduler_dump_test/BUILD.gn | 3 +- test/unittest/ams_mgr_scheduler_test/BUILD.gn | 3 +- .../ams_mgr_scheduler_test.cpp | 88 +++---- test/unittest/ams_mgr_stub_test/BUILD.gn | 3 +- .../ams_recent_app_list_test/BUILD.gn | 3 +- .../BUILD.gn | 3 +- .../ams_service_event_drive_test/BUILD.gn | 3 +- .../BUILD.gn | 3 +- .../ams_service_startup_test/BUILD.gn | 3 +- test/unittest/app_mgr_client_test/BUILD.gn | 2 +- .../app_mgr_service_dump_test/BUILD.gn | 3 +- .../app_mgr_service_dump_test.cpp | 26 +- .../BUILD.gn | 3 +- .../app_mgr_service_event_handler_test.cpp | 23 +- .../app_mgr_service_inner_tdd_test/BUILD.gn | 3 +- .../app_mgr_service_inner_tdd_test.cpp | 33 --- .../app_mgr_service_inner_test/BUILD.gn | 3 +- .../app_mgr_service_inner_test.cpp | 8 +- test/unittest/app_mgr_service_test/BUILD.gn | 3 +- .../app_mgr_service_test.cpp | 84 +++--- .../app_running_processes_info_test/BUILD.gn | 3 +- test/unittest/app_scheduler_test/BUILD.gn | 2 +- test/unittest/app_spawn_socket_test/BUILD.gn | 3 +- .../app_state_observer_manager_test/BUILD.gn | 3 +- .../background_task_observer_test/BUILD.gn | 2 +- test/unittest/call_container_test/BUILD.gn | 3 +- .../call_container_test.cpp | 19 +- test/unittest/call_record_test/BUILD.gn | 5 +- test/unittest/configuration_test/BUILD.gn | 3 +- .../BUILD.gn | 2 +- test/unittest/connection_record_test/BUILD.gn | 2 +- .../connection_state_item_test/BUILD.gn | 2 +- .../connection_state_manager_test/BUILD.gn | 2 +- .../data_ability_manager_test/BUILD.gn | 2 +- .../data_ability_record_test/BUILD.gn | 2 +- .../data_ability_record_test.cpp | 6 +- .../dataobs_mgr_inner_ext_test/BUILD.gn | 2 +- .../dataobs_mgr_inner_ext_test/mock.h | 1 - test/unittest/dataobs_mgr_inner_test/BUILD.gn | 2 +- .../dataobs_mgr_service_dump_test/BUILD.gn | 3 +- .../dataobs_mgr_service_test/BUILD.gn | 3 +- .../dataobs_mgr_service_test.cpp | 22 -- test/unittest/dlp_state_item_test/BUILD.gn | 2 +- test/unittest/dlp_utils_test/BUILD.gn | 1 + .../form_extension_context_test/BUILD.gn | 2 +- .../BUILD.gn | 4 +- .../data_ability_helper_impl_test.cpp | 6 +- .../data_ability_helper_test.cpp | 2 +- .../free_install_manager_test/BUILD.gn | 3 +- .../free_install_manager_test.cpp | 12 +- test/unittest/image_info_test/BUILD.gn | 2 +- .../implicit_start_processor_test/BUILD.gn | 2 +- test/unittest/lifecycle_deal_test/BUILD.gn | 2 +- test/unittest/lifecycle_test/BUILD.gn | 3 +- .../lifecycle_test/lifecycle_test.cpp | 15 +- .../mission_data_storage_test/BUILD.gn | 3 +- .../mission_data_storage_test.cpp | 16 -- test/unittest/mission_info_mgr_test/BUILD.gn | 2 +- test/unittest/mission_info_test/BUILD.gn | 2 +- test/unittest/mission_list_dump_test/BUILD.gn | 1 + .../mission_list_manager_dump_test/BUILD.gn | 2 +- .../mission_list_manager_test/BUILD.gn | 2 +- .../mission_list_manager_ut_test/BUILD.gn | 2 +- test/unittest/mission_list_test/BUILD.gn | 4 +- .../mission_listener_proxy_test/BUILD.gn | 2 +- test/unittest/mission_listener_test/BUILD.gn | 2 +- test/unittest/mission_test/BUILD.gn | 2 +- test/unittest/pending_want_key_test/BUILD.gn | 2 +- .../pending_want_manager_dump_test/BUILD.gn | 2 +- .../pending_want_manager_test/BUILD.gn | 2 +- .../pending_want_record_test/BUILD.gn | 2 +- test/unittest/pending_want_test/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../resident_process_manager_test/BUILD.gn | 2 +- test/unittest/running_infos_test/BUILD.gn | 3 +- .../running_infos_test/running_infos_test.cpp | 21 +- test/unittest/sender_info_test/BUILD.gn | 2 +- .../service_extension_context_test/BUILD.gn | 2 +- .../specified_mission_list_test/BUILD.gn | 2 +- .../start_option_display_id_test/BUILD.gn | 3 +- .../start_option_display_id_test.cpp | 21 +- .../stop_user_callback_proxy_test/BUILD.gn | 2 +- .../stop_user_callback_stub_test/BUILD.gn | 2 +- .../task_data_persistence_mgr_test/BUILD.gn | 2 +- .../BUILD.gn | 1 + test/unittest/user_controller_test/BUILD.gn | 1 + .../unittest/user_event_handler_test/BUILD.gn | 3 +- .../user_event_handler_test.cpp | 23 +- test/unittest/want_agent_test/BUILD.gn | 2 +- .../want_receiver_proxy_test/BUILD.gn | 2 +- .../unittest/want_receiver_stub_test/BUILD.gn | 2 +- test/unittest/want_sender_info_test/BUILD.gn | 2 +- test/unittest/want_sender_proxy_test/BUILD.gn | 2 +- test/unittest/want_sender_stub_test/BUILD.gn | 2 +- test/unittest/wants_info_test/BUILD.gn | 2 +- 388 files changed, 2413 insertions(+), 1530 deletions(-) create mode 100644 services/common/include/event_handler_wrap.h create mode 100644 services/common/include/task_handler_wrap.h create mode 100644 services/common/include/task_utils_wrap.h create mode 100644 services/common/src/event_handler_wrap.cpp create mode 100644 services/common/src/ffrt_task_handler_wrap.cpp create mode 100644 services/common/src/ffrt_task_handler_wrap.h create mode 100644 services/common/src/ffrt_task_utils_wrap.h create mode 100644 services/common/src/queue_task_handler_wrap.cpp create mode 100644 services/common/src/queue_task_handler_wrap.h create mode 100644 services/common/src/task_handler_wrap.cpp diff --git a/bundle.json b/bundle.json index d1fd6e31b1..a5485802d3 100644 --- a/bundle.json +++ b/bundle.json @@ -51,6 +51,7 @@ "ets_runtime", "ets_utils", "faultloggerd", + "ffrt", "form_fwk", "graphic_standard", "hichecker", diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index c80c3ebd5f..70a8f66adc 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -433,6 +433,7 @@ void ContextImpl::InitResourceManager(const AppExecFwk::BundleInfo &bundleInfo, EventFwk::MatchingSkills matchingSkills; matchingSkills.AddEvent(OVERLAY_STATE_CHANGED); EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON); auto callback = [this, resourceManager, bundleName = bundleInfo.name, moduleName = hapModuleInfo.moduleName, loadPath](const EventFwk::CommonEventData &data) { HILOG_INFO("On overlay changed."); diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 600be7e8b4..eacd5a109e 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -960,6 +960,7 @@ bool MainThread::InitResourceManager(std::shared_ptr weak = this; auto callback = [weak, resourceManager, bundleName, moduleName = entryHapModuleInfo.moduleName, loadPath](const EventFwk::CommonEventData &data) { diff --git a/interfaces/inner_api/wantagent/src/pending_want.cpp b/interfaces/inner_api/wantagent/src/pending_want.cpp index 6734082228..ca9e2063a3 100644 --- a/interfaces/inner_api/wantagent/src/pending_want.cpp +++ b/interfaces/inner_api/wantagent/src/pending_want.cpp @@ -17,7 +17,6 @@ #include "ability_runtime_error_util.h" #include "hilog_wrapper.h" -#include "pending_want_record.h" #include "want_agent_client.h" #include "want_agent_log_wrapper.h" #include "want_sender_info.h" diff --git a/service_router_framework/services/srms/src/service_router_mgr_service.cpp b/service_router_framework/services/srms/src/service_router_mgr_service.cpp index 80824e80eb..1b260f79cb 100755 --- a/service_router_framework/services/srms/src/service_router_mgr_service.cpp +++ b/service_router_framework/services/srms/src/service_router_mgr_service.cpp @@ -143,6 +143,7 @@ bool ServiceRouterMgrService::ServiceRouterMgrService::SubscribeCommonEvent() matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON); eventSubscriber_ = std::make_shared(subscribeInfo); eventSubscriber_->SetEventHandler(handler_); diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 5512c60bdc..c67ba9be1b 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -123,6 +123,7 @@ ohos_shared_library("abilityms") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/icu/icu4c:shared_icuuc", ] @@ -138,7 +139,7 @@ ohos_shared_library("abilityms") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/services/abilitymgr/include/ability_bundle_event_callback.h b/services/abilitymgr/include/ability_bundle_event_callback.h index ea8c180e4a..a4bb1d006d 100644 --- a/services/abilitymgr/include/ability_bundle_event_callback.h +++ b/services/abilitymgr/include/ability_bundle_event_callback.h @@ -18,7 +18,7 @@ #include "bundle_event_callback_host.h" #include "common_event_support.h" -#include "ability_event_handler.h" +#include "task_handler_wrap.h" #include "ability_event_util.h" #include "hilog_wrapper.h" @@ -31,8 +31,7 @@ namespace AAFwk { */ class AbilityBundleEventCallback : public AppExecFwk::BundleEventCallbackHost { public: - AbilityBundleEventCallback(); - explicit AbilityBundleEventCallback(std::shared_ptr eventHandler); + explicit AbilityBundleEventCallback(std::shared_ptr taskHandler); ~AbilityBundleEventCallback() = default; @@ -50,7 +49,7 @@ private: DISALLOW_COPY_AND_MOVE(AbilityBundleEventCallback); AbilityEventUtil abilityEventHelper_; - std::shared_ptr eventHandler_ = nullptr; + std::shared_ptr taskHandler_; }; } // namespace OHOS } // namespace AAFwk diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index 9def399f1d..02cbe6f607 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -20,9 +20,11 @@ #include #include #include +#include "cpp/mutex.h" #include "ability_connect_callback_interface.h" -#include "ability_event_handler.h" +#include "task_handler_wrap.h" +#include "event_handler_wrap.h" #include "ability_record.h" #include "ability_running_info.h" #include "extension_running_info.h" @@ -197,12 +199,19 @@ public: void GetExtensionRunningInfo(std::shared_ptr &abilityRecord, const int32_t userId, std::vector &info); + /** + * set from ability manager service for sequenced task + */ + inline void SetTaskHandler(const std::shared_ptr &taskHandler) + { + taskHandler_ = taskHandler; + } /** * SetEventHandler. * * @param handler,EventHandler */ - inline void SetEventHandler(const std::shared_ptr &handler) + inline void SetEventHandler(const std::shared_ptr &handler) { eventHandler_ = handler; } @@ -494,19 +503,20 @@ private: const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; const std::string TASK_ON_ABILITY_DIED = "OnAbilityDiedTask"; - std::mutex Lock_; + ffrt::mutex Lock_; ConnectMapType connectMap_; ServiceMapType serviceMap_; ServiceMapType terminatingExtensionMap_; RecipientMapType recipientMap_; RecipientMapType uiExtRecipientMap_; - std::shared_ptr eventHandler_; + std::shared_ptr taskHandler_; + std::shared_ptr eventHandler_; int userId_; std::vector restartResidentTaskList_; std::unordered_map>> startServiceReqList_; - std::mutex startServiceReqListLock_; + ffrt::mutex startServiceReqListLock_; UIExtensionMapType uiExtensionMap_; - + DISALLOW_COPY_AND_MOVE(AbilityConnectManager); }; } // namespace AAFwk diff --git a/services/abilitymgr/include/ability_event_handler.h b/services/abilitymgr/include/ability_event_handler.h index 2ee21860b5..892801a5b6 100644 --- a/services/abilitymgr/include/ability_event_handler.h +++ b/services/abilitymgr/include/ability_event_handler.h @@ -18,8 +18,7 @@ #include -#include "event_handler.h" -#include "event_runner.h" +#include "event_handler_wrap.h" namespace OHOS { namespace AAFwk { @@ -28,10 +27,10 @@ class AbilityManagerService; * @class AbilityEventHandler * AbilityEventHandler handling the ability event. */ -class AbilityEventHandler : public AppExecFwk::EventHandler { +class AbilityEventHandler : public EventHandlerWrap { public: AbilityEventHandler( - const std::shared_ptr &runner, const std::weak_ptr &server); + const std::shared_ptr &taskHandler, const std::weak_ptr &server); virtual ~AbilityEventHandler() = default; /** @@ -39,7 +38,7 @@ public: * * @param event, inner event loop. */ - void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; + void ProcessEvent(const EventWrap &event) override; private: void ProcessLoadTimeOut(int64_t abilityRecordId); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index fea0678bea..b7641b0404 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -26,6 +26,7 @@ #include "ability_bundle_event_callback.h" #include "ability_connect_manager.h" +#include "task_handler_wrap.h" #include "ability_event_handler.h" #include "ability_interceptor_executer.h" #include "ability_manager_stub.h" @@ -534,6 +535,11 @@ public: WindowCommand winCmd, AbilityCommand abilityCmd) override; + std::shared_ptr GetTaskHandler() const + { + return taskHandler_; + } + /** * GetEventHandler, get the ability manager service's handler. * @@ -815,7 +821,7 @@ public: virtual int PrepareTerminateAbility(const sptr &token, sptr &callback) override; - + void HandleFocused(const sptr &focusChangeInfo); void HandleUnfocused(const sptr &focusChangeInfo); @@ -1475,8 +1481,8 @@ private: constexpr static int REPOLL_TIME_MICRO_SECONDS = 1000000; constexpr static int WAITING_BOOT_ANIMATION_TIMER = 5; - std::shared_ptr eventLoop_; - std::shared_ptr handler_; + std::shared_ptr taskHandler_; + std::shared_ptr eventHandler_; ServiceRunningState state_; std::unordered_map> connectManagers_; std::shared_ptr connectManager_; @@ -1501,10 +1507,10 @@ private: std::shared_ptr userController_; sptr abilityController_ = nullptr; bool controllerIsAStabilityTest_ = false; - std::mutex globalLock_; - std::shared_mutex managersMutex_; - std::shared_mutex bgtaskObserverMutex_; - std::mutex abilityTokenLock_; + ffrt::mutex globalLock_; + ffrt::mutex managersMutex_; + ffrt::mutex bgtaskObserverMutex_; + ffrt::mutex abilityTokenLock_; sptr componentInterception_ = nullptr; std::multimap timeoutMap_; diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 03e31fbf53..b27e1a3f33 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -21,6 +21,8 @@ #include #include #include +#include "cpp/mutex.h" +#include "cpp/condition_variable.h" #include "ability_connect_callback_interface.h" #include "ability_info.h" @@ -1011,10 +1013,10 @@ private: int32_t restartCount_ = -1; int32_t restartMax_ = -1; std::string specifiedFlag_; - std::mutex lock_; - mutable std::mutex dumpInfoLock_; - mutable std::mutex dumpLock_; - mutable std::condition_variable dumpCondition_; + ffrt::mutex lock_; + mutable ffrt::mutex dumpInfoLock_; + mutable ffrt::mutex dumpLock_; + mutable ffrt::condition_variable dumpCondition_; mutable bool isDumpTimeout_ = false; std::vector dumpInfos_; std::atomic pendingState_ = AbilityState::INITIAL; // pending life state diff --git a/services/abilitymgr/include/connection_observer_controller.h b/services/abilitymgr/include/connection_observer_controller.h index 2c3f8cde13..63afe18029 100644 --- a/services/abilitymgr/include/connection_observer_controller.h +++ b/services/abilitymgr/include/connection_observer_controller.h @@ -18,6 +18,7 @@ #include #include +#include "cpp/mutex.h" #include "iconnection_observer.h" @@ -102,7 +103,7 @@ private: }; private: - std::mutex observerLock_; + ffrt::mutex observerLock_; std::vector> observers_; sptr observerDeathRecipient_; }; diff --git a/services/abilitymgr/include/connection_state_manager.h b/services/abilitymgr/include/connection_state_manager.h index d187f6a900..7e421a4e6d 100644 --- a/services/abilitymgr/include/connection_state_manager.h +++ b/services/abilitymgr/include/connection_state_manager.h @@ -18,8 +18,9 @@ #include #include +#include "cpp/mutex.h" -#include "ability_event_handler.h" +#include "task_handler_wrap.h" #include "application_state_observer_stub.h" #include "connection_state_item.h" #include "connection_observer_controller.h" @@ -47,7 +48,7 @@ public: * init manager. * */ - void Init(const std::shared_ptr &handler = nullptr); + void Init(const std::shared_ptr &handler = nullptr); /** * register connection state observer. @@ -200,14 +201,14 @@ private: private: std::shared_ptr observerController_; - std::mutex stateLock_; + ffrt::mutex stateLock_; std::unordered_map> connectionStates_; - std::mutex dlpLock_; + ffrt::mutex dlpLock_; std::unordered_map> dlpItems_; sptr appStateObserver_; - std::shared_ptr handler_; + std::shared_ptr handler_; int32_t retry_ = 0; }; diff --git a/services/abilitymgr/include/data_ability_manager.h b/services/abilitymgr/include/data_ability_manager.h index 3e59903550..a3f3318fc6 100644 --- a/services/abilitymgr/include/data_ability_manager.h +++ b/services/abilitymgr/include/data_ability_manager.h @@ -20,6 +20,7 @@ #include #include #include +#include "cpp/mutex.h" #include "ability_record.h" #include "ability_running_info.h" @@ -65,7 +66,7 @@ private: std::shared_ptr &record); private: - std::mutex mutex_; + ffrt::mutex mutex_; DataAbilityRecordPtrMap dataAbilityRecordsLoaded_; DataAbilityRecordPtrMap dataAbilityRecordsLoading_; }; diff --git a/services/abilitymgr/include/data_ability_record.h b/services/abilitymgr/include/data_ability_record.h index 9f8372fb1e..f346455df1 100644 --- a/services/abilitymgr/include/data_ability_record.h +++ b/services/abilitymgr/include/data_ability_record.h @@ -20,8 +20,9 @@ #include #include #include -#include #include +#include "cpp/mutex.h" +#include "cpp/condition_variable.h" #include "ability_record.h" #include "data_ability_caller_recipient.h" @@ -35,7 +36,7 @@ public: public: int StartLoading(); - int WaitForLoaded(std::mutex &mutex, const std::chrono::system_clock::duration &timeout); + int WaitForLoaded(ffrt::mutex &mutex, const std::chrono::system_clock::duration &timeout); sptr GetScheduler(); int Attach(const sptr &scheduler); int OnTransitionDone(int state); @@ -64,7 +65,7 @@ private: int32_t GetDiedCallerPid(const sptr &remote); private: - std::condition_variable_any loadedCond_ {}; + ffrt::condition_variable loadedCond_ {}; AbilityRequest request_ {}; AbilityRecordPtr ability_ {}; sptr scheduler_ {}; diff --git a/services/abilitymgr/include/free_install_manager.h b/services/abilitymgr/include/free_install_manager.h index 143aa341fc..debd043fe6 100644 --- a/services/abilitymgr/include/free_install_manager.h +++ b/services/abilitymgr/include/free_install_manager.h @@ -17,6 +17,7 @@ #define OHOS_ABILITY_RUNTIME_FREE_INSTALL_MANAGER_H #include +#include "cpp/mutex.h" #include #include @@ -134,9 +135,9 @@ private: std::vector freeInstallList_; std::vector dmsFreeInstallCbs_; std::map timeStampMap_; - std::mutex distributedFreeInstallLock_; - std::mutex freeInstallListLock_; - std::mutex freeInstallObserverLock_; + ffrt::mutex distributedFreeInstallLock_; + ffrt::mutex freeInstallListLock_; + ffrt::mutex freeInstallObserverLock_; /** * Start remote free install. * diff --git a/services/abilitymgr/include/free_install_observer_manager.h b/services/abilitymgr/include/free_install_observer_manager.h index ff63a02053..132f68abec 100644 --- a/services/abilitymgr/include/free_install_observer_manager.h +++ b/services/abilitymgr/include/free_install_observer_manager.h @@ -19,6 +19,7 @@ #include #include #include +#include "cpp/mutex.h" #include "free_install_observer_interface.h" #include "singleton.h" @@ -44,7 +45,7 @@ private: void HandleOnInstallFinished(const std::string &bundleName, const std::string &abilityName, const std::string &startTime, const int &resultCode); - std::mutex observerLock_; + ffrt::mutex observerLock_; sptr deathRecipient_; std::vector> observerList_; }; diff --git a/services/abilitymgr/include/mission_data_storage.h b/services/abilitymgr/include/mission_data_storage.h index eb4a0dca93..7693ae0d53 100644 --- a/services/abilitymgr/include/mission_data_storage.h +++ b/services/abilitymgr/include/mission_data_storage.h @@ -19,8 +19,8 @@ #include #include #include +#include "cpp/mutex.h" -#include "event_handler.h" #include "inner_mission_info.h" #include "mission_snapshot.h" @@ -42,8 +42,6 @@ public: explicit MissionDataStorage(int userId); virtual ~MissionDataStorage(); - void SetEventHandler(const std::shared_ptr &handler); - /** * @brief GeT all mission info. * @return Returns true if this function is successfully called; returns false otherwise. @@ -137,8 +135,7 @@ private: #endif int userId_ = 0; - std::shared_ptr handler_; - std::mutex cachedPixelMapMutex_; + ffrt::mutex cachedPixelMapMutex_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/mission_info_mgr.h b/services/abilitymgr/include/mission_info_mgr.h index 1fad56861e..912896b064 100644 --- a/services/abilitymgr/include/mission_info_mgr.h +++ b/services/abilitymgr/include/mission_info_mgr.h @@ -16,10 +16,11 @@ #ifndef OHOS_ABILITY_RUNTIME_MISSION_INFO_MGR_H #define OHOS_ABILITY_RUNTIME_MISSION_INFO_MGR_H -#include #include #include #include +#include "cpp/mutex.h" +#include "cpp/condition_variable.h" #include "ability_state.h" #include "inner_mission_info.h" @@ -205,10 +206,10 @@ private: std::list missionInfoList_; std::shared_ptr taskDataPersistenceMgr_; sptr snapshotHandler_; - mutable std::mutex mutex_; + mutable ffrt::mutex mutex_; std::unordered_map savingSnapshot_; - std::mutex savingSnapshotLock_; - std::condition_variable waitSavingCondition_; + ffrt::mutex savingSnapshotLock_; + ffrt::condition_variable waitSavingCondition_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index 3924849e0f..af1a2ee477 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -20,6 +20,7 @@ #include #include #include +#include "cpp/mutex.h" #include "ability_running_info.h" #include "foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp/include/device_manager.h" @@ -525,7 +526,7 @@ private: bool CheckPrepareTerminateEnable(const std::shared_ptr &mission); int userId_; - mutable std::mutex managerLock_; + mutable ffrt::mutex managerLock_; // launcher list is also in currentMissionLists_ std::list> currentMissionLists_; // only manager the ability of standard in the default list diff --git a/services/abilitymgr/include/mission_listener_controller.h b/services/abilitymgr/include/mission_listener_controller.h index b11d9c80f4..33af99f17b 100644 --- a/services/abilitymgr/include/mission_listener_controller.h +++ b/services/abilitymgr/include/mission_listener_controller.h @@ -18,8 +18,10 @@ #include #include +#include +#include "cpp/mutex.h" -#include "event_handler.h" +#include "task_handler_wrap.h" #include "mission_listener_interface.h" namespace OHOS { @@ -128,7 +130,7 @@ private: template void CallListeners(F func, Args&&... args) { - std::lock_guard guard(listenerLock_); + std::lock_guard guard(listenerLock_); for (auto listener : missionListeners_) { if (listener) { (listener->*func)(std::forward(args)...); @@ -148,8 +150,8 @@ private: }; private: - std::mutex listenerLock_; - std::shared_ptr handler_; + ffrt::mutex listenerLock_; + std::shared_ptr handler_; std::vector> missionListeners_; sptr listenerDeathRecipient_; }; diff --git a/services/abilitymgr/include/pending_want_manager.h b/services/abilitymgr/include/pending_want_manager.h index b9add7ab34..17ef09a88d 100644 --- a/services/abilitymgr/include/pending_want_manager.h +++ b/services/abilitymgr/include/pending_want_manager.h @@ -21,6 +21,7 @@ #include #include #include +#include "cpp/mutex.h" #include "ability_manager_errors.h" #include "ability_record.h" @@ -174,7 +175,7 @@ private: private: std::map, sptr> wantRecords_; - std::mutex mutex_; + ffrt::mutex mutex_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/pending_want_record.h b/services/abilitymgr/include/pending_want_record.h index 198b87d022..f579b759ae 100644 --- a/services/abilitymgr/include/pending_want_record.h +++ b/services/abilitymgr/include/pending_want_record.h @@ -18,6 +18,7 @@ #include #include +#include "cpp/mutex.h" #include "iremote_object.h" #include "pending_want_key.h" @@ -60,7 +61,7 @@ private: bool canceled_ = false; std::shared_ptr key_ = {}; std::list> mCancelCallbacks_ = {}; - std::mutex lock_ = {}; + ffrt::mutex lock_ = {}; }; } // namespace AAFwk } // namespace OHOS 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 25399c1bc8..4258eaebf6 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -17,6 +17,7 @@ #define OHOS_ABILITY_RUNTIME_UI_ABILITY_LIFECYCLE_MANAGER_H #include +#include "cpp/mutex.h" #include "ability_record.h" #include "session/host/include/zidl/session_interface.h" @@ -235,7 +236,7 @@ private: std::shared_ptr GetReusedSpecifiedAbility(const AAFwk::Want &want, const std::string &flag); void EraseSpecifiedAbilityRecord(const std::shared_ptr &abilityRecord); - mutable std::mutex sessionLock_; + mutable ffrt::mutex sessionLock_; std::map> sessionAbilityMap_; std::map> tmpAbilityMap_; std::list> terminateAbilityList_; diff --git a/services/abilitymgr/include/task_data_persistence_mgr.h b/services/abilitymgr/include/task_data_persistence_mgr.h index 714d01bfa0..10f320df50 100644 --- a/services/abilitymgr/include/task_data_persistence_mgr.h +++ b/services/abilitymgr/include/task_data_persistence_mgr.h @@ -18,9 +18,10 @@ #include #include +#include "cpp/mutex.h" #include "singleton.h" -#include "ability_event_handler.h" +#include "task_handler_wrap.h" #include "mission_data_storage.h" namespace OHOS { @@ -97,10 +98,9 @@ public: private: std::unordered_map> missionDataStorageMgr_; std::shared_ptr currentMissionDataStorage_; - std::shared_ptr eventLoop_; - std::shared_ptr handler_; + std::shared_ptr handler_; int32_t currentUserId_ = -1; - std::mutex mutex_; + ffrt::mutex mutex_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/user_controller.h b/services/abilitymgr/include/user_controller.h index 472143c989..187f214a27 100644 --- a/services/abilitymgr/include/user_controller.h +++ b/services/abilitymgr/include/user_controller.h @@ -18,6 +18,7 @@ #include #include +#include "cpp/mutex.h" #include "user_event_handler.h" @@ -48,7 +49,9 @@ private: UserState lastState_ = STATE_BOOTING; }; -struct UserEvent { +class UserEvent : public EventDataBase { +public: + virtual ~UserEvent() = default; int32_t oldUserId; int32_t newUserId; std::shared_ptr userItem; @@ -82,7 +85,7 @@ public: std::shared_ptr GetUserItem(int32_t userId); - void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); + void ProcessEvent(const EventWrap &event); private: bool IsCurrentUser(int32_t userId); @@ -118,7 +121,7 @@ private: void HandleUserSwitchDone(int32_t userId); private: - std::mutex userLock_; + ffrt::mutex userLock_; int32_t currentUserId_ = USER_ID_NO_HEAD; std::unordered_map> userItems_; std::shared_ptr eventHandler_; diff --git a/services/abilitymgr/include/user_event_handler.h b/services/abilitymgr/include/user_event_handler.h index 7156a197b2..49b53eb924 100644 --- a/services/abilitymgr/include/user_event_handler.h +++ b/services/abilitymgr/include/user_event_handler.h @@ -18,16 +18,15 @@ #include -#include "event_handler.h" -#include "event_runner.h" +#include "event_handler_wrap.h" namespace OHOS { namespace AAFwk { class UserController; -class UserEventHandler : public AppExecFwk::EventHandler { +class UserEventHandler : public EventHandlerWrap { public: UserEventHandler( - const std::shared_ptr &runner, const std::weak_ptr &owner); + const std::shared_ptr &taskHandler, const std::weak_ptr &owner); virtual ~UserEventHandler() = default; static constexpr uint32_t EVENT_SYSTEM_USER_START = 10; @@ -42,7 +41,7 @@ public: * * @param event, inner event loop. */ - void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; + void ProcessEvent(const EventWrap &event) override; private: std::weak_ptr controller_; diff --git a/services/abilitymgr/include/window_focus_changed_listener.h b/services/abilitymgr/include/window_focus_changed_listener.h index 6ecbe7ad62..2f30d7b93f 100644 --- a/services/abilitymgr/include/window_focus_changed_listener.h +++ b/services/abilitymgr/include/window_focus_changed_listener.h @@ -18,15 +18,15 @@ #include "window_manager.h" +#include "task_handler_wrap.h" namespace OHOS { namespace AAFwk { class AbilityManagerService; -class AbilityEventHandler; class WindowFocusChangedListener : public OHOS::Rosen::IFocusChangedListener { public: WindowFocusChangedListener(const std::shared_ptr& owner, - const std::shared_ptr& handler) : owner_(owner), eventHandler_(handler) {} + const std::shared_ptr& handler) : owner_(owner), taskHandler_(handler) {} virtual ~WindowFocusChangedListener() = default; void OnFocused(const sptr &focusChangeInfo) override; @@ -34,7 +34,7 @@ public: private: std::weak_ptr owner_; - std::shared_ptr eventHandler_; + std::shared_ptr taskHandler_; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_bundle_event_callback.cpp b/services/abilitymgr/src/ability_bundle_event_callback.cpp index 15af7f0083..188a87fa80 100644 --- a/services/abilitymgr/src/ability_bundle_event_callback.cpp +++ b/services/abilitymgr/src/ability_bundle_event_callback.cpp @@ -19,19 +19,14 @@ namespace OHOS { namespace AAFwk { -AbilityBundleEventCallback::AbilityBundleEventCallback() : eventHandler_(nullptr) {} - -AbilityBundleEventCallback::AbilityBundleEventCallback(std::shared_ptr eventHandler) -{ - eventHandler_ = eventHandler; -} - +AbilityBundleEventCallback::AbilityBundleEventCallback(std::shared_ptr taskHandler) + : taskHandler_(taskHandler) {} void AbilityBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData eventData) { // env check - if (eventHandler_ == nullptr) { - HILOG_ERROR("OnReceiveEvent failed, eventHandler_ is nullptr"); + if (taskHandler_ == nullptr) { + HILOG_ERROR("OnReceiveEvent failed, taskHandler is nullptr"); return; } const Want& want = eventData.GetWant(); @@ -67,7 +62,7 @@ void AbilityBundleEventCallback::HandleUpdatedModuleInfo(const std::string &bund } sharedThis->abilityEventHelper_.HandleModuleInfoUpdated(bundleName, uid); }; - eventHandler_->PostTask(task); + taskHandler_->SubmitTask(task); } void AbilityBundleEventCallback::HandleAppUpgradeCompleted(const std::string &bundleName, int32_t uid) @@ -87,7 +82,7 @@ void AbilityBundleEventCallback::HandleAppUpgradeCompleted(const std::string &bu } abilityMgr->AppUpgradeCompleted(bundleName, uid); }; - eventHandler_->PostTask(task); + taskHandler_->SubmitTask(task); } } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 372499c79d..3e164abe08 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -183,6 +183,7 @@ void AbilityConnectManager::EnqueueStartServiceReq(const AbilityRequest &ability reqList->push_back(abilityRequest); startServiceReqList_.emplace(abilityUri, reqList); + CHECK_POINTER(taskHandler_); auto callback = [abilityUri, connectManager = shared_from_this()]() { std::lock_guard guard{connectManager->startServiceReqListLock_}; auto exist = connectManager->startServiceReqList_.erase(abilityUri); @@ -193,7 +194,8 @@ void AbilityConnectManager::EnqueueStartServiceReq(const AbilityRequest &ability int connectTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * CONNECT_TIMEOUT_MULTIPLE; - eventHandler_->PostTask(callback, std::string("start_service_timeout:") + abilityUri, connectTimeout); + taskHandler_->SubmitTask(callback, std::string("start_service_timeout:") + abilityUri, + connectTimeout); } } @@ -355,9 +357,9 @@ int AbilityConnectManager::ConnectAbilityLocked(const AbilityRequest &abilityReq // this service ability has connected already targetService->SetWant(abilityRequest.want); if (targetService->GetConnectRecordList().size() > 1) { - if (eventHandler_ != nullptr && targetService->GetConnRemoteObject()) { + if (taskHandler_ != nullptr && targetService->GetConnRemoteObject()) { auto task = [connectRecord]() { connectRecord->CompleteConnect(ERR_OK); }; - eventHandler_->PostTask(task); + taskHandler_->SubmitTask(task); } else { HILOG_INFO("Target service is connecting, wait for callback"); } @@ -480,11 +482,14 @@ int AbilityConnectManager::AttachAbilityThreadLocked( std::lock_guard guard(Lock_); auto abilityRecord = GetExtensionFromServiceMapInner(token); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); - if (eventHandler_ != nullptr) { + if (taskHandler_ != nullptr) { int recordId = abilityRecord->GetRecordId(); std::string taskName = std::string("LoadTimeout_") + std::to_string(recordId); - eventHandler_->RemoveTask(taskName); - eventHandler_->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, abilityRecord->GetAbilityRecordId()); + taskHandler_->CancelTask(taskName); + } + if (eventHandler_) { + eventHandler_->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, + abilityRecord->GetAbilityRecordId()); } std::string element = abilityRecord->GetWant().GetElement().GetURI(); HILOG_DEBUG("Ability: %{public}s", element.c_str()); @@ -566,8 +571,8 @@ int AbilityConnectManager::AbilityTransitionDone(const sptr &toke } acm->ProcessPreload(abilityRecord); }; - if (eventHandler_ != nullptr) { - eventHandler_->PostTask(preloadTask); + if (taskHandler_ != nullptr) { + taskHandler_->SubmitTask(preloadTask); } } return DispatchInactive(abilityRecord, state); @@ -719,11 +724,11 @@ int AbilityConnectManager::ScheduleCommandAbilityWindowDone( HILOG_DEBUG("Ability: %{public}s, persistentId: %{private}" PRIu64", winCmd: %{public}d, abilityCmd: %{public}d", element.c_str(), sessionInfo->persistentId, winCmd, abilityCmd); - if (eventHandler_) { + if (taskHandler_) { int recordId = abilityRecord->GetRecordId(); std::string taskName = std::string("CommandWindowTimeout_") + std::to_string(recordId) + std::string("_") + std::to_string(sessionInfo->persistentId) + std::string("_") + std::to_string(winCmd); - eventHandler_->RemoveTask(taskName); + taskHandler_->CancelTask(taskName); } if (winCmd == WIN_CMD_DESTROY) { @@ -774,12 +779,11 @@ int AbilityConnectManager::ScheduleCommandAbilityWindowDone( void AbilityConnectManager::CompleteCommandAbility(std::shared_ptr abilityRecord) { CHECK_POINTER(abilityRecord); - - if (eventHandler_) { + if (taskHandler_) { int recordId = abilityRecord->GetRecordId(); std::string taskName = std::string("CommandTimeout_") + std::to_string(recordId) + std::string("_") + std::to_string(abilityRecord->GetStartId()); - eventHandler_->RemoveTask(taskName); + taskHandler_->CancelTask(taskName); } abilityRecord->SetAbilityState(AbilityState::ACTIVE); @@ -975,7 +979,7 @@ void AbilityConnectManager::LoadAbility(const std::shared_ptr &ab void AbilityConnectManager::PostRestartResidentTask(const AbilityRequest &abilityRequest) { HILOG_INFO("PostRestartResidentTask start."); - CHECK_POINTER(eventHandler_); + CHECK_POINTER(taskHandler_); std::string taskName = std::string("RestartResident_") + std::string(abilityRequest.abilityInfo.name); auto task = [abilityRequest, connectManager = shared_from_this()]() { CHECK_POINTER(connectManager); @@ -987,7 +991,8 @@ void AbilityConnectManager::PostRestartResidentTask(const AbilityRequest &abilit restartIntervalTime = AmsConfigurationParameter::GetInstance().GetRestartIntervalTime(); } HILOG_DEBUG("PostRestartResidentTask, time:%{public}d", restartIntervalTime); - eventHandler_->PostTask(task, taskName, restartIntervalTime); + taskHandler_->SubmitTask(task, taskName, restartIntervalTime); + HILOG_INFO("PostRestartResidentTask end."); } void AbilityConnectManager::HandleRestartResidentTask(const AbilityRequest &abilityRequest) @@ -1008,7 +1013,7 @@ void AbilityConnectManager::HandleRestartResidentTask(const AbilityRequest &abil void AbilityConnectManager::PostTimeOutTask(const std::shared_ptr &abilityRecord, uint32_t messageId) { CHECK_POINTER(abilityRecord); - CHECK_POINTER(eventHandler_); + CHECK_POINTER(taskHandler_); if (messageId != AbilityConnectManager::LOAD_TIMEOUT_MSG && messageId != AbilityConnectManager::CONNECT_TIMEOUT_MSG) { HILOG_ERROR("Timeout task messageId is error."); @@ -1048,8 +1053,7 @@ void AbilityConnectManager::PostTimeOutTask(const std::shared_ptr HILOG_WARN("Connect or load ability timeout."); connectManager->HandleStartTimeoutTask(abilityRecord, resultCode); }; - - eventHandler_->PostTask(timeoutTask, taskName, delayTime); + taskHandler_->SubmitTask(timeoutTask, taskName, delayTime); } void AbilityConnectManager::HandleStartTimeoutTask(const std::shared_ptr &abilityRecord, int resultCode) @@ -1195,13 +1199,13 @@ int AbilityConnectManager::DispatchInactive(const std::shared_ptr int AbilityConnectManager::DispatchForeground(const std::shared_ptr &abilityRecord) { CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); - CHECK_POINTER_AND_RETURN(eventHandler_, ERR_INVALID_VALUE); + CHECK_POINTER_AND_RETURN(taskHandler_, ERR_INVALID_VALUE); // remove foreground timeout task. - eventHandler_->RemoveTask("foreground_" + std::to_string(abilityRecord->GetAbilityRecordId())); + taskHandler_->CancelTask("foreground_" + std::to_string(abilityRecord->GetAbilityRecordId())); auto self(shared_from_this()); auto task = [self, abilityRecord]() { self->CompleteForeground(abilityRecord); }; - eventHandler_->PostTask(task); + taskHandler_->SubmitTask(task); return ERR_OK; } @@ -1209,13 +1213,13 @@ int AbilityConnectManager::DispatchForeground(const std::shared_ptr &abilityRecord) { CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); - CHECK_POINTER_AND_RETURN(eventHandler_, ERR_INVALID_VALUE); + CHECK_POINTER_AND_RETURN(taskHandler_, ERR_INVALID_VALUE); // remove background timeout task. - eventHandler_->RemoveTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId())); + taskHandler_->CancelTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId())); auto self(shared_from_this()); auto task = [self, abilityRecord]() { self->CompleteBackground(abilityRecord); }; - eventHandler_->PostTask(task); + taskHandler_->SubmitTask(task); return ERR_OK; } @@ -1224,8 +1228,8 @@ int AbilityConnectManager::DispatchTerminate(const std::shared_ptrRemoveTask("terminate_" + std::to_string(abilityRecord->GetAbilityRecordId())); + if (taskHandler_ != nullptr) { + taskHandler_->CancelTask("terminate_" + std::to_string(abilityRecord->GetAbilityRecordId())); } // complete terminate TerminateDone(abilityRecord); @@ -1243,7 +1247,7 @@ void AbilityConnectManager::ConnectAbility(const std::shared_ptr void AbilityConnectManager::CommandAbility(const std::shared_ptr &abilityRecord) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - if (eventHandler_ != nullptr) { + if (taskHandler_ != nullptr) { // first connect ability, There is at most one connect record. int recordId = abilityRecord->GetRecordId(); abilityRecord->AddStartId(); @@ -1255,7 +1259,7 @@ void AbilityConnectManager::CommandAbility(const std::shared_ptr }; int commandTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * COMMAND_TIMEOUT_MULTIPLE; - eventHandler_->PostTask(timeoutTask, taskName, commandTimeout); + taskHandler_->SubmitTask(timeoutTask, taskName, commandTimeout); // scheduling command ability abilityRecord->CommandAbility(); } @@ -1269,7 +1273,7 @@ void AbilityConnectManager::CommandAbilityWindow(const std::shared_ptrGetAbilityInfo().name.c_str(), sessionInfo->persistentId, winCmd); - if (eventHandler_ != nullptr) { + if (taskHandler_ != nullptr) { int recordId = abilityRecord->GetRecordId(); std::string taskName = std::string("CommandWindowTimeout_") + std::to_string(recordId) + std::string("_") + std::to_string(sessionInfo->persistentId) + std::string("_") + std::to_string(winCmd); @@ -1279,7 +1283,7 @@ void AbilityConnectManager::CommandAbilityWindow(const std::shared_ptrPostTask(timeoutTask, taskName, commandWindowTimeout); + taskHandler_->SubmitTask(timeoutTask, taskName, commandWindowTimeout); // scheduling command ability abilityRecord->CommandAbilityWindow(sessionInfo, winCmd); } @@ -1384,9 +1388,9 @@ void AbilityConnectManager::OnCallBackDied(const wptr &remote) { auto object = remote.promote(); CHECK_POINTER(object); - if (eventHandler_) { + if (taskHandler_) { auto task = [object, connectManager = shared_from_this()]() { connectManager->HandleCallBackDiedTask(object); }; - eventHandler_->PostTask(task, TASK_ON_CALLBACK_DIED); + taskHandler_->SubmitTask(task, TASK_ON_CALLBACK_DIED); } } @@ -1418,11 +1422,11 @@ void AbilityConnectManager::OnAbilityDied(const std::shared_ptr & HILOG_DEBUG("Ability type is not service."); return; } - if (eventHandler_) { + if (taskHandler_) { auto task = [abilityRecord, connectManager = shared_from_this(), currentUserId]() { connectManager->HandleAbilityDiedTask(abilityRecord, currentUserId); }; - eventHandler_->PostTask(task, TASK_ON_ABILITY_DIED); + taskHandler_->SubmitTask(task, TASK_ON_ABILITY_DIED); } } @@ -1949,11 +1953,11 @@ void AbilityConnectManager::OnUIExtWindowDied(const wptr &remote) { auto object = remote.promote(); CHECK_POINTER(object); - if (eventHandler_) { + if (taskHandler_) { auto task = [object, connectManager = shared_from_this()]() { connectManager->HandleUIExtWindowDiedTask(object); }; - eventHandler_->PostTask(task); + taskHandler_->SubmitTask(task); } } diff --git a/services/abilitymgr/src/ability_event_handler.cpp b/services/abilitymgr/src/ability_event_handler.cpp index 571d2534cd..bf8b32de29 100644 --- a/services/abilitymgr/src/ability_event_handler.cpp +++ b/services/abilitymgr/src/ability_event_handler.cpp @@ -23,16 +23,15 @@ namespace OHOS { namespace AAFwk { AbilityEventHandler::AbilityEventHandler( - const std::shared_ptr &runner, const std::weak_ptr &server) - : AppExecFwk::EventHandler(runner), server_(server) + const std::shared_ptr &taskHandler, const std::weak_ptr &server) + : EventHandlerWrap(taskHandler), server_(server) { HILOG_INFO("Constructors."); } -void AbilityEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +void AbilityEventHandler::ProcessEvent(const EventWrap &event) { - CHECK_POINTER(event); - HILOG_DEBUG("Event id obtained: %{public}u.", event->GetInnerEventId()); + HILOG_DEBUG("Event id obtained: %{public}u.", event.GetEventId()); // check libc.hook_mode const int bufferLen = 128; char paramOutBuf[bufferLen] = {0}; @@ -42,27 +41,27 @@ void AbilityEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &ev HILOG_DEBUG("Hook_mode: no process time out"); return; } - switch (event->GetInnerEventId()) { + switch (event.GetEventId()) { case AbilityManagerService::LOAD_TIMEOUT_MSG: { - ProcessLoadTimeOut(event->GetParam()); + ProcessLoadTimeOut(event.GetParam()); break; } case AbilityManagerService::ACTIVE_TIMEOUT_MSG: { - ProcessActiveTimeOut(event->GetParam()); + ProcessActiveTimeOut(event.GetParam()); break; } case AbilityManagerService::INACTIVE_TIMEOUT_MSG: { HILOG_INFO("Inactive timeout."); // inactivate pre ability immediately in case blocking next ability start - ProcessInactiveTimeOut(event->GetParam()); + ProcessInactiveTimeOut(event.GetParam()); break; } case AbilityManagerService::FOREGROUND_TIMEOUT_MSG: { - ProcessForegroundTimeOut(event->GetParam()); + ProcessForegroundTimeOut(event.GetParam()); break; } case AbilityManagerService::SHAREDATA_TIMEOUT_MSG: { - ProcessShareDataTimeOut(event->GetParam()); + ProcessShareDataTimeOut(event.GetParam()); break; } default: { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 5c875e0b78..cbdc6dd5cb 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,6 @@ #include "system_ability_definition.h" #include "system_ability_token_callback.h" #include "uri_permission_manager_client.h" -#include "xcollie/watchdog.h" #ifdef SUPPORT_GRAPHICS @@ -218,8 +218,6 @@ sptr AbilityManagerService::instance_; AbilityManagerService::AbilityManagerService() : SystemAbility(ABILITY_MGR_SERVICE_ID, true), - eventLoop_(nullptr), - handler_(nullptr), state_(ServiceRunningState::STATE_NOT_START), iBundleManager_(nullptr) { @@ -242,7 +240,6 @@ void AbilityManagerService::OnStart() return; } state_ = ServiceRunningState::STATE_RUNNING; - eventLoop_->Run(); /* Publish service maybe failed, so we need call this function at the last, * so it can't affect the TDD test program */ instance_ = DelayedSingleton::GetInstance().get(); @@ -266,12 +263,8 @@ void AbilityManagerService::OnStart() bool AbilityManagerService::Init() { - eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - CHECK_POINTER_RETURN_BOOL(eventLoop_); - - handler_ = std::make_shared(eventLoop_, weak_from_this()); - CHECK_POINTER_RETURN_BOOL(handler_); - + taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + eventHandler_ = std::make_shared(taskHandler_, weak_from_this()); freeInstallManager_ = std::make_shared(weak_from_this()); CHECK_POINTER_RETURN_BOOL(freeInstallManager_); @@ -294,18 +287,6 @@ bool AbilityManagerService::Init() SwitchManagers(U0_USER_ID, false); int amsTimeOut = AmsConfigurationParameter::GetInstance().GetAMSTimeOutTime(); HILOG_INFO("amsTimeOut is %{public}d", amsTimeOut); - std::string threadName = std::string(AbilityConfig::NAME_ABILITY_MGR_SERVICE) + "(" + - std::to_string(eventLoop_->GetThreadId()) + ")"; -#ifdef SUPPORT_ASAN - constexpr int32_t timeout = 5 * 60 * 1000; // 5 min - if (HiviewDFX::Watchdog::GetInstance().AddThread(threadName, handler_, timeout) != 0) { - HILOG_ERROR("HiviewDFX::Watchdog::GetInstance AddThread Fail"); - } -#else - if (HiviewDFX::Watchdog::GetInstance().AddThread(threadName, handler_) != 0) { - HILOG_ERROR("HiviewDFX::Watchdog::GetInstance AddThread Fail"); - } -#endif #ifdef SUPPORT_GRAPHICS DelayedSingleton::GetInstance()->SetDeviceType(OHOS::system::GetDeviceType()); implicitStartProcessor_ = std::make_shared(); @@ -313,7 +294,7 @@ bool AbilityManagerService::Init() InitPrepareTerminateConfig(); #endif - DelayedSingleton::GetInstance()->Init(handler_); + DelayedSingleton::GetInstance()->Init(taskHandler_); interceptorExecuter_ = std::make_shared(); interceptorExecuter_->AddInterceptor(std::make_shared()); @@ -330,10 +311,10 @@ bool AbilityManagerService::Init() } auto startResidentAppsTask = [aams = shared_from_this()]() { aams->StartResidentApps(); }; - handler_->PostTask(startResidentAppsTask, "StartResidentApps"); + taskHandler_->SubmitTask(startResidentAppsTask, "StartResidentApps"); auto initStartupFlagTask = [aams = shared_from_this()]() { aams->InitStartupFlag(); }; - handler_->PostTask(initStartupFlagTask, "InitStartupFlag"); + taskHandler_->SubmitTask(initStartupFlagTask, "InitStartupFlag"); HILOG_INFO("Init success."); return true; } @@ -350,7 +331,7 @@ void AbilityManagerService::OnStop() { HILOG_INFO("Stop AMS."); #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE - std::unique_lock lock(bgtaskObserverMutex_); + std::unique_lock lock(bgtaskObserverMutex_); if (bgtaskObserver_) { int ret = BackgroundTaskMgrHelper::UnsubscribeBackgroundTask(*bgtaskObserver_); if (ret != ERR_OK) { @@ -368,8 +349,8 @@ void AbilityManagerService::OnStop() } } } - eventLoop_.reset(); - handler_.reset(); + eventHandler_.reset(); + taskHandler_.reset(); state_ = ServiceRunningState::STATE_NOT_START; } @@ -1200,7 +1181,7 @@ bool AbilityManagerService::CheckCallingTokenId(const std::string &bundleName, i bool AbilityManagerService::IsBackgroundTaskUid(const int uid) { #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE - std::shared_lock lock(bgtaskObserverMutex_); + std::lock_guard lock(bgtaskObserverMutex_); if (bgtaskObserver_) { return bgtaskObserver_->IsBackgroundTaskUid(uid); } @@ -1301,7 +1282,7 @@ int32_t AbilityManagerService::ForceExitApp(const int32_t pid, Reason exitReason int32_t targetUserId = uid / BASE_USER_RANGE; std::vector abilityLists; if (targetUserId == U0_USER_ID) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); for (auto item: missionListManagers_) { if (item.second) { std::vector abilityList; @@ -1437,7 +1418,7 @@ void AbilityManagerService::OnRemoveSystemAbility(int32_t systemAbilityId, const void AbilityManagerService::SubscribeBackgroundTask() { #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE - std::unique_lock lock(bgtaskObserverMutex_); + std::unique_lock lock(bgtaskObserverMutex_); if (bgtaskObserver_) { return; } @@ -1456,7 +1437,7 @@ void AbilityManagerService::SubscribeBackgroundTask() void AbilityManagerService::UnSubscribeBackgroundTask() { #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE - std::unique_lock lock(bgtaskObserverMutex_); + std::unique_lock lock(bgtaskObserverMutex_); if (!bgtaskObserver_) { return; } @@ -1473,7 +1454,7 @@ void AbilityManagerService::SubscribeBundleEventCallback() } // Register abilityBundleEventCallback to receive hap updates - abilityBundleEventCallback_ = new (std::nothrow) AbilityBundleEventCallback(handler_); + abilityBundleEventCallback_ = new (std::nothrow) AbilityBundleEventCallback(taskHandler_); auto bms = GetBundleManager(); if (bms) { bool ret = IN_PROCESS_CALL(bms->RegisterBundleEventCallback(abilityBundleEventCallback_)); @@ -3441,7 +3422,7 @@ void AbilityManagerService::DumpSysMissionListInner( { std::shared_ptr targetManager; if (isUserID) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = missionListManagers_.find(userId); if (it == missionListManagers_.end()) { info.push_back("error: No user found."); @@ -3473,7 +3454,7 @@ void AbilityManagerService::DumpSysAbilityInner( { std::shared_ptr targetManager; if (isUserID) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = missionListManagers_.find(userId); if (it == missionListManagers_.end()) { info.push_back("error: No user found."); @@ -3513,7 +3494,7 @@ void AbilityManagerService::DumpSysStateInner( std::shared_ptr targetManager; if (isUserID) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = connectManagers_.find(userId); if (it == connectManagers_.end()) { info.push_back("error: No user found."); @@ -3548,7 +3529,7 @@ void AbilityManagerService::DumpSysPendingInner( { std::shared_ptr targetManager; if (isUserID) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = pendingWantManagers_.find(userId); if (it == pendingWantManagers_.end()) { info.push_back("error: No user found."); @@ -3624,7 +3605,7 @@ void AbilityManagerService::DataDumpSysStateInner( { std::shared_ptr targetManager; if (isUserID) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = dataAbilityManagers_.find(userId); if (it == dataAbilityManagers_.end()) { info.push_back("error: No user found."); @@ -4006,14 +3987,14 @@ void AbilityManagerService::OnAppStateChanged(const AppInfo &info) std::shared_ptr AbilityManagerService::GetEventHandler() { - return handler_; + return eventHandler_; } void AbilityManagerService::InitMissionListManager(int userId, bool switchUser) { bool find = false; { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto iterator = missionListManagers_.find(userId); find = (iterator != missionListManagers_.end()); if (find) { @@ -4026,7 +4007,7 @@ void AbilityManagerService::InitMissionListManager(int userId, bool switchUser) if (!find) { auto manager = std::make_shared(userId); manager->Init(); - std::unique_lock lock(managersMutex_); + std::unique_lock lock(managersMutex_); missionListManagers_.emplace(userId, manager); if (switchUser) { currentMissionListManager_ = manager; @@ -4372,7 +4353,7 @@ void AbilityManagerService::OnCallConnectDied(std::shared_ptr callRe void AbilityManagerService::ReleaseAbilityTokenMap(const sptr &token) { - std::lock_guard autoLock(abilityTokenLock_); + std::lock_guard autoLock(abilityTokenLock_); for (auto iter = callStubTokenMap_.begin(); iter != callStubTokenMap_.end(); iter++) { if (iter->second == token) { callStubTokenMap_.erase(iter); @@ -4430,7 +4411,7 @@ int AbilityManagerService::UninstallApp(const std::string &bundleName, int32_t u int32_t targetUserId = uid / BASE_USER_RANGE; if (targetUserId == U0_USER_ID) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); for (auto item: missionListManagers_) { if (item.second) { item.second->UninstallApp(bundleName, uid); @@ -4537,7 +4518,7 @@ bool AbilityManagerService::IsSystemUI(const std::string &bundleName) const void AbilityManagerService::HandleLoadTimeOut(int64_t abilityRecordId) { HILOG_DEBUG("Handle load timeout."); - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { uiAbilityLifecycleManager_->OnTimeOut(AbilityManagerService::LOAD_TIMEOUT_MSG, abilityRecordId); return; @@ -4552,7 +4533,7 @@ void AbilityManagerService::HandleLoadTimeOut(int64_t abilityRecordId) void AbilityManagerService::HandleActiveTimeOut(int64_t abilityRecordId) { HILOG_DEBUG("Handle active timeout."); - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); for (auto& item : missionListManagers_) { if (item.second) { item.second->OnTimeOut(AbilityManagerService::ACTIVE_TIMEOUT_MSG, abilityRecordId); @@ -4563,7 +4544,7 @@ void AbilityManagerService::HandleActiveTimeOut(int64_t abilityRecordId) void AbilityManagerService::HandleInactiveTimeOut(int64_t abilityRecordId) { HILOG_DEBUG("Handle inactive timeout."); - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); for (auto& item : missionListManagers_) { if (item.second) { item.second->OnTimeOut(AbilityManagerService::INACTIVE_TIMEOUT_MSG, abilityRecordId); @@ -4580,7 +4561,7 @@ void AbilityManagerService::HandleInactiveTimeOut(int64_t abilityRecordId) void AbilityManagerService::HandleForegroundTimeOut(int64_t abilityRecordId) { HILOG_DEBUG("Handle foreground timeout."); - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { uiAbilityLifecycleManager_->OnTimeOut(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, abilityRecordId); return; @@ -4663,7 +4644,7 @@ bool AbilityManagerService::VerificationAllToken(const sptr &toke { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("VerificationAllToken."); - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { if (uiAbilityLifecycleManager_ != nullptr && uiAbilityLifecycleManager_->IsContainsAbility(token)) { return true; @@ -4713,7 +4694,7 @@ std::shared_ptr AbilityManagerService::GetDataAbilityManager return nullptr; } - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); for (auto& item: dataAbilityManagers_) { if (item.second && item.second->ContainsDataAbility(scheduler)) { return item.second; @@ -4725,7 +4706,7 @@ std::shared_ptr AbilityManagerService::GetDataAbilityManager std::shared_ptr AbilityManagerService::GetListManagerByUserId(int32_t userId) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = missionListManagers_.find(userId); if (it != missionListManagers_.end()) { return it->second; @@ -4736,7 +4717,7 @@ std::shared_ptr AbilityManagerService::GetListManagerByUserI std::shared_ptr AbilityManagerService::GetConnectManagerByUserId(int32_t userId) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = connectManagers_.find(userId); if (it != connectManagers_.end()) { return it->second; @@ -4747,7 +4728,7 @@ std::shared_ptr AbilityManagerService::GetConnectManagerB std::shared_ptr AbilityManagerService::GetDataAbilityManagerByUserId(int32_t userId) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = dataAbilityManagers_.find(userId); if (it != dataAbilityManagers_.end()) { return it->second; @@ -4759,7 +4740,7 @@ std::shared_ptr AbilityManagerService::GetDataAbilityManager std::shared_ptr AbilityManagerService::GetConnectManagerByToken( const sptr &token) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); for (auto item: connectManagers_) { if (item.second && item.second->GetExtensionByTokenFromServiceMap(token)) { return item.second; @@ -4775,7 +4756,7 @@ std::shared_ptr AbilityManagerService::GetConnectManagerB std::shared_ptr AbilityManagerService::GetDataAbilityManagerByToken( const sptr &token) { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); for (auto item: dataAbilityManagers_) { if (item.second && item.second->GetAbilityRecordByToken(token)) { return item.second; @@ -5211,7 +5192,7 @@ int AbilityManagerService::GetProcessRunningInfosByUserId( void AbilityManagerService::ClearUserData(int32_t userId) { HILOG_DEBUG("%{public}s", __func__); - std::unique_lock lock(managersMutex_); + std::unique_lock lock(managersMutex_); missionListManagers_.erase(userId); connectManagers_.erase(userId); dataAbilityManagers_.erase(userId); @@ -5305,7 +5286,7 @@ void AbilityManagerService::EnableRecoverAbility(const sptr& toke } { - std::lock_guard guard(globalLock_); + std::lock_guard guard(globalLock_); auto it = appRecoveryHistory_.find(record->GetUid()); if (it == appRecoveryHistory_.end()) { appRecoveryHistory_.emplace(record->GetUid(), 0); @@ -5368,7 +5349,7 @@ void AbilityManagerService::ScheduleRecoverAbility(const sptr& to AAFwk::Want curWant; { - std::lock_guard guard(globalLock_); + std::lock_guard guard(globalLock_); auto type = record->GetAbilityInfo().type; if (type != AppExecFwk::AbilityType::PAGE) { HILOG_ERROR("%{public}s AppRecovery::only do recover for page ability.", __func__); @@ -5446,7 +5427,7 @@ void AbilityManagerService::ScheduleRecoverAbility(const sptr& to std::string taskName = "AppRecovery_kill:" + std::to_string(record->GetPid()); auto task = std::bind(&AbilityManagerService::RecoverAbilityRestart, this, curWant); HILOG_INFO("AppRecovery RecoverAbilityRestart task begin"); - handler_->PostTask(task, taskName, delaytime); + taskHandler_->SubmitTask(task, taskName, delaytime); } int32_t AbilityManagerService::GetRemoteMissionSnapshotInfo(const std::string& deviceId, int32_t missionId, @@ -5527,7 +5508,7 @@ void AbilityManagerService::PauseOldUser(int32_t userId) void AbilityManagerService::PauseOldMissionListManager(int32_t userId) { HILOG_INFO("%{public}s, PauseOldMissionListManager:%{public}d-----begin", __func__, userId); - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = missionListManagers_.find(userId); if (it == missionListManagers_.end()) { HILOG_INFO("%{public}s, PauseOldMissionListManager:%{public}d-----end1", __func__, userId); @@ -5550,7 +5531,7 @@ void AbilityManagerService::PauseOldConnectManager(int32_t userId) return; } - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = connectManagers_.find(userId); if (it == connectManagers_.end()) { HILOG_INFO("%{public}s, PauseOldConnectManager:%{public}d-----no user", __func__, userId); @@ -5579,7 +5560,7 @@ void AbilityManagerService::InitConnectManager(int32_t userId, bool switchUser) { bool find = false; { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = connectManagers_.find(userId); find = (it != connectManagers_.end()); if (find) { @@ -5590,8 +5571,9 @@ void AbilityManagerService::InitConnectManager(int32_t userId, bool switchUser) } if (!find) { auto manager = std::make_shared(userId); - manager->SetEventHandler(handler_); - std::unique_lock lock(managersMutex_); + manager->SetTaskHandler(taskHandler_); + manager->SetEventHandler(eventHandler_); + std::unique_lock lock(managersMutex_); connectManagers_.emplace(userId, manager); if (switchUser) { connectManager_ = manager; @@ -5603,7 +5585,7 @@ void AbilityManagerService::InitDataAbilityManager(int32_t userId, bool switchUs { bool find = false; { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = dataAbilityManagers_.find(userId); find = (it != dataAbilityManagers_.end()); if (find) { @@ -5614,7 +5596,7 @@ void AbilityManagerService::InitDataAbilityManager(int32_t userId, bool switchUs } if (!find) { auto manager = std::make_shared(); - std::unique_lock lock(managersMutex_); + std::unique_lock lock(managersMutex_); dataAbilityManagers_.emplace(userId, manager); if (switchUser) { dataAbilityManager_ = manager; @@ -5626,7 +5608,7 @@ void AbilityManagerService::InitPendWantManager(int32_t userId, bool switchUser) { bool find = false; { - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); auto it = pendingWantManagers_.find(userId); find = (it != pendingWantManagers_.end()); if (find) { @@ -5637,7 +5619,7 @@ void AbilityManagerService::InitPendWantManager(int32_t userId, bool switchUser) } if (!find) { auto manager = std::make_shared(); - std::unique_lock lock(managersMutex_); + std::unique_lock lock(managersMutex_); pendingWantManagers_.emplace(userId, manager); if (switchUser) { pendingWantManager_ = manager; @@ -5671,7 +5653,7 @@ int AbilityManagerService::SetAbilityController(const sptr & return CHECK_PERMISSION_FAILED; } - std::lock_guard guard(globalLock_); + std::lock_guard guard(globalLock_); abilityController_ = abilityController; controllerIsAStabilityTest_ = imAStabilityTest; HILOG_DEBUG("%{public}s, end", __func__); @@ -5692,7 +5674,7 @@ int AbilityManagerService::SendANRProcessID(int pid) bool debug; auto appScheduler = DelayedSingleton::GetInstance(); if (appScheduler->GetApplicationInfoByProcessID(pid, appInfo, debug) == ERR_OK) { - std::lock_guard guard(globalLock_); + std::lock_guard guard(globalLock_); auto it = appRecoveryHistory_.find(appInfo.uid); if (it != appRecoveryHistory_.end()) { return ERR_OK; @@ -5720,7 +5702,7 @@ int AbilityManagerService::SendANRProcessID(int pid) bool AbilityManagerService::IsRunningInStabilityTest() { - std::lock_guard guard(globalLock_); + std::lock_guard guard(globalLock_); bool ret = abilityController_ != nullptr && controllerIsAStabilityTest_; HILOG_DEBUG("%{public}s, IsRunningInStabilityTest: %{public}d", __func__, ret); return ret; @@ -5896,7 +5878,7 @@ int AbilityManagerService::DoAbilityForeground(const sptr &token, return ERR_INVALID_VALUE; } - std::lock_guard guard(globalLock_); + std::lock_guard guard(globalLock_); auto abilityRecord = Token::GetAbilityRecordByToken(token); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); if (!JudgeSelfCalled(abilityRecord)) { @@ -6158,7 +6140,7 @@ int AbilityManagerService::BlockAmsService() HILOG_ERROR("Not shell call"); return ERR_PERMISSION_DENIED; } - if (handler_) { + if (taskHandler_) { HILOG_DEBUG("%{public}s begin post block ams service task", __func__); auto BlockAmsServiceTask = [aams = shared_from_this()]() { while (1) { @@ -6166,7 +6148,7 @@ int AbilityManagerService::BlockAmsService() std::this_thread::sleep_for(BLOCK_AMS_SERVICE_TIME*1s); } }; - handler_->PostTask(BlockAmsServiceTask, "blockamsservice"); + taskHandler_->SubmitTask(BlockAmsServiceTask, "blockamsservice"); return ERR_OK; } return ERR_NO_INIT; @@ -6444,7 +6426,7 @@ sptr AbilityManagerService::GetWMSHandler() const void AbilityManagerService::CompleteFirstFrameDrawing(const sptr &abilityToken) { HILOG_DEBUG("%{public}s is called.", __func__); - std::shared_lock lock(managersMutex_); + std::lock_guard lock(managersMutex_); for (auto& item : missionListManagers_) { if (item.second) { item.second->CompleteFirstFrameDrawing(abilityToken); @@ -6523,8 +6505,8 @@ int AbilityManagerService::PrepareTerminateAbility(const sptr &to }; int prepareTerminateTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * PREPARE_TERMINATE_TIMEOUT_MULTIPLE; - if (handler_) { - handler_->PostTask(timeoutTask, "PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId()), + if (taskHandler_) { + taskHandler_->SubmitTask(timeoutTask, "PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId()), prepareTerminateTimeout); } @@ -6532,7 +6514,7 @@ int AbilityManagerService::PrepareTerminateAbility(const sptr &to if (!res) { callback->DoPrepareTerminate(); } - handler_->RemoveTask("PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId())); + taskHandler_->CancelTask("PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId())); return ERR_OK; } @@ -6567,15 +6549,15 @@ void AbilityManagerService::InitFocusListener() return; } - focusListener_ = new WindowFocusChangedListener(shared_from_this(), handler_); + focusListener_ = new WindowFocusChangedListener(shared_from_this(), taskHandler_); auto registerTask = [innerService = shared_from_this()]() { if (innerService) { HILOG_INFO("RegisterFocusListener task"); innerService->RegisterFocusListener(); } }; - if (handler_) { - handler_->PostTask(registerTask, "RegisterFocusListenerTask", REGISTER_FOCUS_DELAY); + if (taskHandler_) { + taskHandler_->SubmitTask(registerTask, "RegisterFocusListenerTask", REGISTER_FOCUS_DELAY); } } @@ -6912,7 +6894,7 @@ bool AbilityManagerService::GetStartUpNewRuleFlag() const void AbilityManagerService::CallRequestDone(const sptr &token, const sptr &callStub) { { - std::lock_guard autoLock(abilityTokenLock_); + std::lock_guard autoLock(abilityTokenLock_); callStubTokenMap_[callStub] = token; } auto abilityRecord = Token::GetAbilityRecordByToken(token); @@ -6935,7 +6917,7 @@ void AbilityManagerService::CallRequestDone(const sptr &token, co void AbilityManagerService::GetAbilityTokenByCalleeObj(const sptr &callStub, sptr &token) { - std::lock_guard autoLock(abilityTokenLock_); + std::lock_guard autoLock(abilityTokenLock_); auto it = callStubTokenMap_.find(callStub); if (it == callStubTokenMap_.end()) { token = nullptr; @@ -7009,7 +6991,7 @@ int AbilityManagerService::SetComponentInterception( return CHECK_PERMISSION_FAILED; } - std::lock_guard guard(globalLock_); + std::lock_guard guard(globalLock_); componentInterception_ = componentInterception; HILOG_DEBUG("%{public}s, end", __func__); return ERR_OK; @@ -7247,8 +7229,8 @@ int32_t AbilityManagerService::ShareDataDone( if (!JudgeSelfCalled(abilityRecord)) { return CHECK_PERMISSION_FAILED; } - CHECK_POINTER_AND_RETURN_LOG(handler_, ERR_INVALID_VALUE, "fail to get abilityEventHandler."); - handler_->RemoveEvent(SHAREDATA_TIMEOUT_MSG, uniqueId); + CHECK_POINTER_AND_RETURN_LOG(eventHandler_, ERR_INVALID_VALUE, "fail to get abilityEventHandler."); + eventHandler_->RemoveEvent(SHAREDATA_TIMEOUT_MSG, uniqueId); return GetShareDataPairAndReturnData(abilityRecord, resultCode, uniqueId, wantParam); } diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index b4e12720be..ed1d7ff684 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -360,12 +360,12 @@ void AbilityRecord::ForegroundAbility(const Closure &task, uint32_t sceneFlag) HILOG_INFO("name:%{public}s.", abilityInfo_.name.c_str()); CHECK_POINTER(lifecycleDeal_); - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (handler && task) { if (!want_.GetBoolParam(DEBUG_APP, false) && !want_.GetBoolParam(NATIVE_DEBUG, false)) { int foregroundTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * FOREGROUND_TIMEOUT_MULTIPLE; - handler->PostTask(task, "foreground_" + std::to_string(recordId_), foregroundTimeout); + handler->SubmitTask(task, "foreground_" + std::to_string(recordId_), foregroundTimeout); } else { HILOG_INFO("Is debug mode, no need to handle time out."); } @@ -565,13 +565,13 @@ void AbilityRecord::ProcessForegroundAbility(bool isRecent, const AbilityRequest GrantUriPermission(want_, GetCurrentAccountId(), applicationInfo_.bundleName); if (isReady_) { - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (!handler) { HILOG_ERROR("Fail to get AbilityEventHandler."); return; } auto taskName = std::to_string(missionId_) + "_hot"; - handler->RemoveTask(taskName); + handler->CancelTask(taskName); StartingWindowTask(isRecent, false, abilityRequest, startOptions); AnimationTask(isRecent, abilityRequest, startOptions, callerAbility); PostCancelStartingWindowHotTask(); @@ -723,9 +723,9 @@ void AbilityRecord::PostCancelStartingWindowHotTask() HILOG_INFO("PostCancelStartingWindowHotTask was called, debug mode, just return."); return; } - HILOG_INFO("call"); - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_LOG(handler, "Fail to get AbilityEventHandler."); + HILOG_INFO("PostCancelStartingWindowHotTask was called."); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_LOG(handler, "Fail to get TaskHandler."); auto windowHandler = GetWMSHandler(); CHECK_POINTER_LOG(windowHandler, "PostCancelStartingWindowColdTask, Get WMS handler failed."); @@ -742,7 +742,7 @@ void AbilityRecord::PostCancelStartingWindowHotTask() auto taskName = std::to_string(missionId_) + "_hot"; int foregroundTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * FOREGROUND_TIMEOUT_MULTIPLE; - handler->PostTask(delayTask, taskName, foregroundTimeout); + handler->SubmitTask(delayTask, taskName, foregroundTimeout); } void AbilityRecord::PostCancelStartingWindowColdTask() @@ -753,9 +753,9 @@ void AbilityRecord::PostCancelStartingWindowColdTask() HILOG_INFO("PostCancelStartingWindowColdTask was called, debug mode, just return."); return; } - HILOG_DEBUG("call"); - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_LOG(handler, "Fail to get AbilityEventHandler."); + HILOG_DEBUG("PostCancelStartingWindowColdTask was called."); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_LOG(handler, "Fail to get TaskHandler."); auto windowHandler = GetWMSHandler(); CHECK_POINTER_LOG(windowHandler, "PostCancelStartingWindowColdTask, Get WMS handler failed."); @@ -772,7 +772,7 @@ void AbilityRecord::PostCancelStartingWindowColdTask() }; auto taskName = std::to_string(missionId_) + "_cold"; int loadTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * LOAD_TIMEOUT_MULTIPLE; - handler->PostTask(delayTask, taskName, loadTimeout); + handler->SubmitTask(delayTask, taskName, loadTimeout); } sptr AbilityRecord::GetWMSHandler() const @@ -1018,7 +1018,7 @@ void AbilityRecord::InitColdStartingWindowResource( bgColor_ = 0xdfffffff; } - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (startingWindowBg_ && handler) { auto delayTask = [me = weak_from_this()] { auto self = me.lock(); @@ -1027,7 +1027,7 @@ void AbilityRecord::InitColdStartingWindowResource( } self->startingWindowBg_.reset(); }; - handler->PostTask(delayTask, "release_bg", RELEASE_STARTING_BG_TIMEOUT); + handler->SubmitTask(delayTask, "release_bg", RELEASE_STARTING_BG_TIMEOUT); } } @@ -1050,14 +1050,14 @@ void AbilityRecord::BackgroundAbility(const Closure &task) HILOG_ERROR("Move the ability to background fail, lifecycleDeal_ is null."); return; } - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (handler && task) { if (!want_.GetBoolParam(DEBUG_APP, false) && !want_.GetBoolParam(NATIVE_DEBUG, false) && want_.GetStringParam(PERF_CMD).empty()) { int backgroundTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * BACKGROUND_TIMEOUT_MULTIPLE; - handler->PostTask(task, "background_" + std::to_string(recordId_), backgroundTimeout); + handler->SubmitTask(task, "background_" + std::to_string(recordId_), backgroundTimeout); } else { HILOG_INFO("Is debug mode, no need to handle time out."); } @@ -1309,18 +1309,18 @@ void AbilityRecord::Terminate(const Closure &task) HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_INFO("ability:%{public}s.", abilityInfo_.name.c_str()); CHECK_POINTER(lifecycleDeal_); - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (handler && task) { if (!want_.GetBoolParam(DEBUG_APP, false) && !want_.GetBoolParam(NATIVE_DEBUG, false) && want_.GetStringParam(PERF_CMD).empty()) { int terminateTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * TERMINATE_TIMEOUT_MULTIPLE; - handler->PostTask(task, "terminate_" + std::to_string(recordId_), terminateTimeout); + handler->SubmitTask(task, "terminate_" + std::to_string(recordId_), terminateTimeout); } else if (applicationInfo_.asanEnabled) { int terminateTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * TERMINATE_TIMEOUT_ASANENABLED; - handler->PostTask(task, "terminate_" + std::to_string(recordId_), terminateTimeout); + handler->SubmitTask(task, "terminate_" + std::to_string(recordId_), terminateTimeout); } else { HILOG_INFO("Is debug mode, no need to handle time out."); } @@ -1419,7 +1419,7 @@ std::shared_ptr AbilityRecord::GetResult() const void AbilityRecord::SendResult(bool isSandboxApp) { HILOG_INFO("ability:%{public}s.", abilityInfo_.name.c_str()); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); CHECK_POINTER(scheduler_); CHECK_POINTER(result_); GrantUriPermission(result_->resultWant_, GetCurrentAccountId(), applicationInfo_.bundleName, isSandboxApp); @@ -1923,7 +1923,7 @@ void AbilityRecord::OnSchedulerDied(const wptr &remote) if (mission) { HILOG_WARN("On scheduler died. Is app not response Reason:%{public}d", mission->IsANRState()); } - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); CHECK_POINTER(scheduler_); auto object = remote.promote(); @@ -1948,19 +1948,19 @@ void AbilityRecord::OnSchedulerDied(const wptr &remote) auto abilityManagerService = DelayedSingleton::GetInstance(); CHECK_POINTER(abilityManagerService); - auto handler = abilityManagerService->GetEventHandler(); + auto handler = abilityManagerService->GetTaskHandler(); CHECK_POINTER(handler); HILOG_INFO("Ability on scheduler died: '%{public}s'", abilityInfo_.name.c_str()); auto task = [abilityManagerService, ability = shared_from_this()]() { abilityManagerService->OnAbilityDied(ability); }; - handler->PostTask(task); + handler->SubmitTask(task); auto uriTask = [want = want_, ability = shared_from_this()]() { ability->SaveResultToCallers(-1, &want); ability->SendResultToCallers(true); }; - handler->PostTask(uriTask); + handler->SubmitTask(uriTask); #ifdef SUPPORT_GRAPHICS // notify winddow manager service the ability died if (missionId_ != -1) { @@ -2037,7 +2037,7 @@ void AbilityRecord::SendEvent(uint32_t msg, uint32_t timeOut, int32_t param) auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); CHECK_POINTER(handler); param = (param == -1) ? recordId_ : param; - handler->SendEvent(msg, param, timeOut); + handler->SendEvent(EventWrap(msg, param), timeOut); } void AbilityRecord::SetStartSetting(const std::shared_ptr &setting) @@ -2358,19 +2358,19 @@ void AbilityRecord::DumpClientInfo(std::vector &info, const std::ve HILOG_ERROR("something nullptr."); return; } - std::unique_lock lock(dumpLock_); + std::unique_lock lock(dumpLock_); scheduler_->DumpAbilityInfo(params, info); HILOG_INFO("Dump begin wait."); isDumpTimeout_ = false; int dumpTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * DUMP_TIMEOUT_MULTIPLE; std::chrono::milliseconds timeout { dumpTimeout }; - if (dumpCondition_.wait_for(lock, timeout) == std::cv_status::timeout) { + if (dumpCondition_.wait_for(lock, timeout) == ffrt::cv_status::timeout) { isDumpTimeout_ = true; } HILOG_INFO("Dump done and begin parse."); if (!isDumpTimeout_) { - std::lock_guard infoLock(dumpInfoLock_); + std::lock_guard infoLock(dumpInfoLock_); for (auto one : dumpInfos_) { info.emplace_back(one); } @@ -2394,7 +2394,7 @@ void AbilityRecord::DumpAbilityInfoDone(std::vector &infos) return; } { - std::lock_guard infoLock(dumpInfoLock_); + std::lock_guard infoLock(dumpInfoLock_); dumpInfos_.clear(); for (auto info : infos) { dumpInfos_.emplace_back(info); diff --git a/services/abilitymgr/src/call_container.cpp b/services/abilitymgr/src/call_container.cpp index 632e4dd3dc..79ad7c1d94 100644 --- a/services/abilitymgr/src/call_container.cpp +++ b/services/abilitymgr/src/call_container.cpp @@ -19,7 +19,6 @@ #include "ability_manager_errors.h" #include "ability_connect_callback_stub.h" #include "ability_util.h" -#include "ability_event_handler.h" #include "ability_manager_service.h" namespace OHOS { @@ -114,12 +113,12 @@ void CallContainer::OnConnectionDied(const wptr &remote) auto abilityManagerService = DelayedSingleton::GetInstance(); CHECK_POINTER(abilityManagerService); - auto handler = abilityManagerService->GetEventHandler(); + auto handler = abilityManagerService->GetTaskHandler(); CHECK_POINTER(handler); auto task = [abilityManagerService, callRecord]() { abilityManagerService->OnCallConnectDied(callRecord); }; - handler->PostTask(task); + handler->SubmitTask(task); } bool CallContainer::CallRequestDone(const sptr &callStub) diff --git a/services/abilitymgr/src/call_record.cpp b/services/abilitymgr/src/call_record.cpp index 6475a49367..62b73439a2 100644 --- a/services/abilitymgr/src/call_record.cpp +++ b/services/abilitymgr/src/call_record.cpp @@ -17,7 +17,6 @@ #include "hilog_wrapper.h" #include "ability_util.h" -#include "ability_event_handler.h" #include "ability_manager_service.h" #include "ability_record.h" #include "element_name.h" @@ -161,12 +160,12 @@ void CallRecord::OnCallStubDied(const wptr &remote) auto abilityManagerService = DelayedSingleton::GetInstance(); CHECK_POINTER(abilityManagerService); - auto handler = abilityManagerService->GetEventHandler(); + auto handler = abilityManagerService->GetTaskHandler(); CHECK_POINTER(handler); auto task = [abilityManagerService, callRecord = shared_from_this()]() { abilityManagerService->OnCallConnectDied(callRecord); }; - handler->PostTask(task); + handler->SubmitTask(task); HILOG_DEBUG("callstub is died. id:%{public}d, end", recordId_); } diff --git a/services/abilitymgr/src/connection_observer_controller.cpp b/services/abilitymgr/src/connection_observer_controller.cpp index 971cfc609c..27da2d06e0 100644 --- a/services/abilitymgr/src/connection_observer_controller.cpp +++ b/services/abilitymgr/src/connection_observer_controller.cpp @@ -28,7 +28,7 @@ int ConnectionObserverController::AddObserver(const sptr guard(observerLock_); + std::lock_guard guard(observerLock_); auto it = std::find_if(observers_.begin(), observers_.end(), [&observer](const sptr &item) { return (item && item->AsObject() == observer->AsObject()); }); @@ -63,7 +63,7 @@ void ConnectionObserverController::RemoveObserver(const sptr guard(observerLock_); + std::lock_guard guard(observerLock_); auto it = std::find_if(observers_.begin(), observers_.end(), [&observer](const sptr item) { return (item && item->AsObject() == observer->AsObject()); }); @@ -94,7 +94,7 @@ void ConnectionObserverController::NotifyDlpAbilityClosed(const AbilityRuntime:: std::vector> ConnectionObserverController::GetObservers() { - std::lock_guard guard(observerLock_); + std::lock_guard guard(observerLock_); return observers_; } @@ -108,7 +108,7 @@ void ConnectionObserverController::HandleRemoteDied(const wptr &r } remoteObj->RemoveDeathRecipient(observerDeathRecipient_); - std::lock_guard guard(observerLock_); + std::lock_guard guard(observerLock_); auto it = std::find_if(observers_.begin(), observers_.end(), [&remoteObj](const sptr item) { return (item && item->AsObject() == remoteObj); }); diff --git a/services/abilitymgr/src/connection_record.cpp b/services/abilitymgr/src/connection_record.cpp index 7484d759e7..b647ecbfcf 100644 --- a/services/abilitymgr/src/connection_record.cpp +++ b/services/abilitymgr/src/connection_record.cpp @@ -97,10 +97,10 @@ int ConnectionRecord::DisconnectAbility() CHECK_POINTER_AND_RETURN(targetService_, ERR_INVALID_VALUE); std::size_t connectNums = targetService_->GetConnectRecordList().size(); if (connectNums == 1) { - /* post timeout task to eventhandler */ - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + /* post timeout task to taskhandler */ + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (handler == nullptr) { - HILOG_ERROR("fail to get AbilityEventHandler"); + HILOG_ERROR("fail to get TaskHandler"); } else { std::string taskName("DisconnectTimeout_"); taskName += std::to_string(recordId_); @@ -110,7 +110,7 @@ int ConnectionRecord::DisconnectAbility() }; int disconnectTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * DISCONNECT_TIMEOUT_MULTIPLE; - handler->PostTask(disconnectTask, taskName, disconnectTimeout); + handler->SubmitTask(disconnectTask, taskName, disconnectTimeout); } /* schedule disconnect to target ability */ targetService_->DisconnectAbility(); @@ -161,12 +161,12 @@ void ConnectionRecord::CompleteDisconnect(int resultCode, bool isDied) } connCallback->OnAbilityDisconnectDone(element, code); }; - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (handler == nullptr) { HILOG_ERROR("handler is nullptr."); return; } - handler->PostTask(onDisconnectDoneTask); + handler->SubmitTask(onDisconnectDoneTask); DelayedSingleton::GetInstance()->RemoveConnection(shared_from_this(), isDied); HILOG_INFO("result: %{public}d. connectState:%{public}d.", resultCode, state_); } @@ -178,12 +178,12 @@ void ConnectionRecord::ScheduleDisconnectAbilityDone() return; } - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (handler == nullptr) { - HILOG_ERROR("fail to get AbilityEventHandler"); + HILOG_ERROR("fail to get AbilityTaskHandler"); } else { std::string taskName = std::string("DisconnectTimeout_") + std::to_string(recordId_); - handler->RemoveTask(taskName); + handler->CancelTask(taskName); } CompleteDisconnect(ERR_OK, false); @@ -195,12 +195,12 @@ void ConnectionRecord::ScheduleConnectAbilityDone() HILOG_ERROR("fail to schedule connect ability done, current state is not connecting."); return; } - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (handler == nullptr) { - HILOG_ERROR("fail to get AbilityEventHandler"); + HILOG_ERROR("fail to get AbilityTaskHandler"); } else { std::string taskName = std::string("ConnectTimeout_") + std::to_string(recordId_); - handler->RemoveTask(taskName); + handler->CancelTask(taskName); } CompleteConnect(ERR_OK); diff --git a/services/abilitymgr/src/connection_state_manager.cpp b/services/abilitymgr/src/connection_state_manager.cpp index 1f531f1ad7..7d562dacc0 100644 --- a/services/abilitymgr/src/connection_state_manager.cpp +++ b/services/abilitymgr/src/connection_state_manager.cpp @@ -59,7 +59,7 @@ std::string ConnectionStateManager::GetProcessNameByPid(int32_t pid) return name; } -void ConnectionStateManager::Init(const std::shared_ptr &handler) +void ConnectionStateManager::Init(const std::shared_ptr &handler) { if (!observerController_) { observerController_ = std::make_shared(); @@ -78,7 +78,7 @@ void ConnectionStateManager::Init(const std::shared_ptrInitAppStateObserver(); }; - handler->PostTask(initConnectionStateManagerTask, "InitConnectionStateManager"); + handler->SubmitTask(initConnectionStateManagerTask, "InitConnectionStateManager"); } int ConnectionStateManager::RegisterObserver(const sptr &observer) @@ -244,7 +244,7 @@ void ConnectionStateManager::AddDlpManager(const std::shared_ptr } auto userId = dlpManger->GetOwnerMissionUserId(); - std::lock_guard guard(dlpLock_); + std::lock_guard guard(dlpLock_); auto it = dlpItems_.find(userId); if (it == dlpItems_.end()) { dlpItems_[userId] = std::make_shared(dlpManger->GetUid(), dlpManger->GetPid()); @@ -257,7 +257,7 @@ void ConnectionStateManager::RemoveDlpManager(const std::shared_ptr guard(dlpLock_); + std::lock_guard guard(dlpLock_); dlpItems_.erase(dlpManger->GetOwnerMissionUserId()); } @@ -298,7 +298,7 @@ void ConnectionStateManager::HandleAppDied(int32_t pid) void ConnectionStateManager::GetDlpConnectionInfos(std::vector &infos) { - std::lock_guard guard(dlpLock_); + std::lock_guard guard(dlpLock_); for (auto it = dlpItems_.begin(); it != dlpItems_.end(); it++) { auto item = it->second; if (!item) { @@ -317,7 +317,7 @@ bool ConnectionStateManager::AddConnectionInner(const std::shared_ptr targetItem = nullptr; auto callerPid = connectionRecord->GetCallerPid(); - std::lock_guard guard(stateLock_); + std::lock_guard guard(stateLock_); auto it = connectionStates_.find(callerPid); if (it == connectionStates_.end()) { targetItem = ConnectionStateItem::CreateConnectionStateItem(connectionRecord); @@ -340,7 +340,7 @@ bool ConnectionStateManager::RemoveConnectionInner(const std::shared_ptrGetCallerPid(); - std::lock_guard guard(stateLock_); + std::lock_guard guard(stateLock_); auto it = connectionStates_.find(callerPid); if (it == connectionStates_.end()) { HILOG_WARN("can not find target item, connection caller pid:%{public}d.", callerPid); @@ -387,7 +387,7 @@ void ConnectionStateManager::HandleCallerDied(int32_t callerPid) std::shared_ptr ConnectionStateManager::RemoveDiedCaller(int32_t callerPid) { - std::lock_guard guard(stateLock_); + std::lock_guard guard(stateLock_); auto it = connectionStates_.find(callerPid); if (it == connectionStates_.end()) { HILOG_WARN("connection caller pid:%{public}d.", callerPid); @@ -403,7 +403,7 @@ bool ConnectionStateManager::AddDataAbilityConnectionInner(const DataAbilityCall const std::shared_ptr &record, ConnectionData &data) { std::shared_ptr targetItem = nullptr; - std::lock_guard guard(stateLock_); + std::lock_guard guard(stateLock_); auto it = connectionStates_.find(caller.callerPid); if (it == connectionStates_.end()) { targetItem = ConnectionStateItem::CreateConnectionStateItem(caller); @@ -425,7 +425,7 @@ bool ConnectionStateManager::AddDataAbilityConnectionInner(const DataAbilityCall bool ConnectionStateManager::RemoveDataAbilityConnectionInner(const DataAbilityCaller &caller, const std::shared_ptr &record, AbilityRuntime::ConnectionData &data) { - std::lock_guard guard(stateLock_); + std::lock_guard guard(stateLock_); auto it = connectionStates_.find(caller.callerPid); if (it == connectionStates_.end()) { HILOG_WARN("can not find target item, connection caller pid:%{public}d.", caller.callerPid); @@ -448,7 +448,7 @@ bool ConnectionStateManager::RemoveDataAbilityConnectionInner(const DataAbilityC void ConnectionStateManager::HandleDataAbilityDiedInner(const sptr &abilityToken, std::vector &allData) { - std::lock_guard guard(stateLock_); + std::lock_guard guard(stateLock_); for (auto it = connectionStates_.begin(); it != connectionStates_.end();) { auto item = it->second; if (!item) { @@ -482,7 +482,7 @@ bool ConnectionStateManager::HandleDlpAbilityInner(const std::shared_ptr guard(dlpLock_); + std::lock_guard guard(dlpLock_); auto it = dlpItems_.find(dlpAbility->GetOwnerMissionUserId()); if (it == dlpItems_.end()) { HILOG_WARN("no dlp manager, invalid state."); @@ -520,7 +520,7 @@ void ConnectionStateManager::InitAppStateObserver() } self->InitAppStateObserver(); }; - handler_->PostTask(initConnectionStateManagerTask, "InitConnectionStateManager", DELAY_TIME); + handler_->SubmitTask(initConnectionStateManagerTask, "InitConnectionStateManager", DELAY_TIME); retry_++; } return; diff --git a/services/abilitymgr/src/data_ability_manager.cpp b/services/abilitymgr/src/data_ability_manager.cpp index 3e13fb87ac..a0529a9ac9 100644 --- a/services/abilitymgr/src/data_ability_manager.cpp +++ b/services/abilitymgr/src/data_ability_manager.cpp @@ -73,7 +73,7 @@ sptr DataAbilityManager::Acquire( HILOG_INFO("Loading data ability '%{public}s'...", dataAbilityName.c_str()); } - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); if (DEBUG_ENABLED) { DumpLocked(__func__, __LINE__); @@ -128,7 +128,7 @@ int DataAbilityManager::Release( CHECK_POINTER_AND_RETURN(scheduler, ERR_NULL_OBJECT); CHECK_POINTER_AND_RETURN(client, ERR_NULL_OBJECT); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); if (DEBUG_ENABLED) { DumpLocked(__func__, __LINE__); @@ -182,7 +182,7 @@ bool DataAbilityManager::ContainsDataAbility(const sptr &sche CHECK_POINTER_AND_RETURN(scheduler, ERR_NULL_OBJECT); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); for (auto it = dataAbilityRecordsLoaded_.begin(); it != dataAbilityRecordsLoaded_.end(); ++it) { if (it->second && it->second->GetScheduler() && it->second->GetScheduler()->AsObject() == scheduler->AsObject()) { @@ -200,7 +200,7 @@ int DataAbilityManager::AttachAbilityThread(const sptr &sched CHECK_POINTER_AND_RETURN(scheduler, ERR_NULL_OBJECT); CHECK_POINTER_AND_RETURN(token, ERR_NULL_OBJECT); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); if (DEBUG_ENABLED) { DumpLocked(__func__, __LINE__); @@ -249,7 +249,7 @@ int DataAbilityManager::AbilityTransitionDone(const sptr &token, CHECK_POINTER_AND_RETURN(token, ERR_NULL_OBJECT); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); if (DEBUG_ENABLED) { DumpLocked(__func__, __LINE__); @@ -295,7 +295,7 @@ void DataAbilityManager::OnAbilityDied(const std::shared_ptr &abi CHECK_POINTER(abilityRecord); { - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); if (DEBUG_ENABLED) { DumpLocked(__func__, __LINE__); } @@ -332,7 +332,7 @@ void DataAbilityManager::OnAbilityDied(const std::shared_ptr &abi void DataAbilityManager::OnAppStateChanged(const AppInfo &info) { - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); for (auto it = dataAbilityRecordsLoaded_.begin(); it != dataAbilityRecordsLoaded_.end(); ++it) { if (!it->second) { @@ -375,7 +375,7 @@ std::shared_ptr DataAbilityManager::GetAbilityRecordById(int64_t { HILOG_DEBUG("Call."); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); for (auto it = dataAbilityRecordsLoaded_.begin(); it != dataAbilityRecordsLoaded_.end(); ++it) { if (!it->second) { @@ -396,7 +396,7 @@ std::shared_ptr DataAbilityManager::GetAbilityRecordByToken(const CHECK_POINTER_AND_RETURN(token, nullptr); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); for (auto it = dataAbilityRecordsLoaded_.begin(); it != dataAbilityRecordsLoaded_.end(); ++it) { if (!it->second) { continue; @@ -424,7 +424,7 @@ std::shared_ptr DataAbilityManager::GetAbilityRecordByScheduler(c CHECK_POINTER_AND_RETURN(scheduler, nullptr); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); for (auto it = dataAbilityRecordsLoaded_.begin(); it != dataAbilityRecordsLoaded_.end(); ++it) { if (it->second && it->second->GetScheduler() && @@ -440,7 +440,7 @@ void DataAbilityManager::Dump(const char *func, int line) { HILOG_DEBUG("Call."); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); DumpLocked(func, line); } @@ -599,7 +599,7 @@ void DataAbilityManager::DumpSysState(std::vector &info, bool isCli void DataAbilityManager::GetAbilityRunningInfos(std::vector &info, bool isPerm) { HILOG_INFO("Get ability running infos"); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); auto queryInfo = [&info, isPerm](DataAbilityRecordPtrMap::reference data) { auto dataAbilityRecord = data.second; diff --git a/services/abilitymgr/src/data_ability_record.cpp b/services/abilitymgr/src/data_ability_record.cpp index 58bfd9fcad..2d3e9317b7 100644 --- a/services/abilitymgr/src/data_ability_record.cpp +++ b/services/abilitymgr/src/data_ability_record.cpp @@ -16,6 +16,7 @@ #include "data_ability_record.h" #include +#include #include "ability_util.h" #include "app_scheduler.h" @@ -71,7 +72,7 @@ int DataAbilityRecord::StartLoading() return ERR_OK; } -int DataAbilityRecord::WaitForLoaded(std::mutex &mutex, const std::chrono::system_clock::duration &timeout) +int DataAbilityRecord::WaitForLoaded(ffrt::mutex &mutex, const std::chrono::system_clock::duration &timeout) { CHECK_POINTER_AND_RETURN(ability_, ERR_INVALID_STATE); @@ -80,7 +81,8 @@ int DataAbilityRecord::WaitForLoaded(std::mutex &mutex, const std::chrono::syste return ERR_OK; } - auto ret = loadedCond_.wait_for(mutex, timeout, [this] { return ability_->GetAbilityState() == ACTIVE; }); + std::unique_lock lock(mutex, std::adopt_lock); + auto ret = loadedCond_.wait_for(lock, timeout, [this] { return ability_->GetAbilityState() == ACTIVE; }); if (!ret) { return ERR_TIMED_OUT; } diff --git a/services/abilitymgr/src/free_install_manager.cpp b/services/abilitymgr/src/free_install_manager.cpp index 62e0e4c728..1463111011 100644 --- a/services/abilitymgr/src/free_install_manager.cpp +++ b/services/abilitymgr/src/free_install_manager.cpp @@ -92,7 +92,7 @@ int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int r } FreeInstallInfo info = BuildFreeInstallInfo(want, userId, requestCode, callerToken, isAsync); { - std::lock_guard lock(freeInstallListLock_); + std::lock_guard lock(freeInstallListLock_); freeInstallList_.push_back(info); } sptr callback = new AtomicServiceStatusCallback(weak_from_this(), isAsync); @@ -142,7 +142,7 @@ int FreeInstallManager::RemoteFreeInstall(const Want &want, int32_t userId, int } FreeInstallInfo info = BuildFreeInstallInfo(want, userId, requestCode, callerToken, false); { - std::lock_guard lock(freeInstallListLock_); + std::lock_guard lock(freeInstallListLock_); freeInstallList_.push_back(info); } sptr callback = new AtomicServiceStatusCallback(weak_from_this(), false); @@ -203,7 +203,7 @@ int FreeInstallManager::StartRemoteFreeInstall(const Want &want, int requestCode int FreeInstallManager::NotifyDmsCallback(const Want &want, int resultCode) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - std::lock_guard autoLock(distributedFreeInstallLock_); + std::lock_guard autoLock(distributedFreeInstallLock_); if (dmsFreeInstallCbs_.empty()) { HILOG_ERROR("Has no dms callback."); return ERR_INVALID_VALUE; @@ -250,7 +250,7 @@ int FreeInstallManager::NotifyDmsCallback(const Want &want, int resultCode) void FreeInstallManager::NotifyFreeInstallResult(const Want &want, int resultCode, bool isAsync) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - std::lock_guard lock(freeInstallListLock_); + std::lock_guard lock(freeInstallListLock_); if (freeInstallList_.empty()) { HILOG_INFO("Has no app callback."); return; @@ -321,7 +321,7 @@ int FreeInstallManager::FreeInstallAbilityFromRemote(const Want &want, const spt }; { - std::lock_guard autoLock(distributedFreeInstallLock_); + std::lock_guard autoLock(distributedFreeInstallLock_); dmsFreeInstallCbs_.push_back(info); } @@ -421,10 +421,9 @@ void FreeInstallManager::PostUpgradeAtomicServiceTask(int resultCode, const Want } }; - std::shared_ptr handler = - DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_LOG(handler, "Fail to get AbilityEventHandler."); - handler->PostTask(updateAtmoicServiceTask, "UpdateAtmoicServiceTask"); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_LOG(handler, "Fail to get Ability task handler."); + handler->SubmitTask(updateAtmoicServiceTask, "UpdateAtmoicServiceTask"); } } @@ -458,10 +457,9 @@ void FreeInstallManager::PostTimeoutTask(const Want &want) }; std::string taskName = std::string("FreeInstallTimeout_") + bundleName + std::string("_") + abilityName + std::string("_") + startTime; - std::shared_ptr handler = - DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_LOG(handler, "Fail to get AbilityEventHandler."); - handler->PostTask(task, taskName, DELAY_LOCAL_FREE_INSTALL_TIMEOUT); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_LOG(handler, "Fail to get AbilityTaskHandler."); + handler->SubmitTask(task, taskName, DELAY_LOCAL_FREE_INSTALL_TIMEOUT); } void FreeInstallManager::RemoveTimeoutTask(const std::string &bundleName, const std::string &abilityName, @@ -471,10 +469,9 @@ void FreeInstallManager::RemoveTimeoutTask(const std::string &bundleName, const std::string taskName = std::string("FreeInstallTimeout_") + bundleName + std::string("_") + abilityName + std::string("_") + startTime; HILOG_INFO("RemoveTimeoutTask task name:%{public}s", taskName.c_str()); - std::shared_ptr handler = - DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_LOG(handler, "Fail to get AbilityEventHandler."); - handler->RemoveTask(taskName); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_LOG(handler, "Fail to get AbilityTaskHandler."); + handler->CancelTask(taskName); } void FreeInstallManager::OnRemoveTimeoutTask(const Want &want) @@ -499,7 +496,7 @@ void FreeInstallManager::OnRemoveTimeoutTask(const Want &want) void FreeInstallManager::RemoveFreeInstallInfo(const std::string &bundleName, const std::string &abilityName, const std::string &startTime) { - std::lock_guard lock(freeInstallListLock_); + std::lock_guard lock(freeInstallListLock_); for (auto it = freeInstallList_.begin(); it != freeInstallList_.end();) { if ((*it).want.GetElement().GetBundleName() == bundleName && (*it).want.GetElement().GetAbilityName() == abilityName && diff --git a/services/abilitymgr/src/free_install_observer_manager.cpp b/services/abilitymgr/src/free_install_observer_manager.cpp index 23c1452d30..c7669210c1 100644 --- a/services/abilitymgr/src/free_install_observer_manager.cpp +++ b/services/abilitymgr/src/free_install_observer_manager.cpp @@ -12,14 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "free_install_observer_manager.h" #include #include "ability_event_handler.h" #include "ability_manager_service.h" #include "ability_manager_errors.h" -#include "free_install_observer_manager.h" -#include "free_install_observer_interface.h" #include "hilog_wrapper.h" namespace OHOS { @@ -37,7 +36,7 @@ int32_t FreeInstallObserverManager::AddObserver(const sptr HILOG_ERROR("the observer is nullptr."); return ERR_INVALID_VALUE; } - std::lock_guard lock(observerLock_); + std::lock_guard lock(observerLock_); if (ObserverExistLocked(observer)) { HILOG_ERROR("Observer exist."); return ERR_INVALID_VALUE; @@ -72,7 +71,7 @@ int32_t FreeInstallObserverManager::RemoveObserver(const sptr lock(observerLock_); + std::lock_guard lock(observerLock_); auto it = std::find_if(observerList_.begin(), observerList_.end(), [&observer](const sptr &item) { return (item && item->AsObject() == observer->AsObject()); @@ -99,10 +98,9 @@ void FreeInstallObserverManager::OnInstallFinished(const std::string &bundleName self->HandleOnInstallFinished(bundleName, abilityName, startTime, resultCode); }; - std::shared_ptr handler = - DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_LOG(handler, "Fail to get AbilityEventHandler."); - handler->PostTask(task); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_LOG(handler, "Fail to get Ability task handler."); + handler->SubmitTask(task); } void FreeInstallObserverManager::HandleOnInstallFinished(const std::string &bundleName, const std::string &abilityName, @@ -141,7 +139,7 @@ void FreeInstallObserverManager::OnObserverDied(const wptr &remot } remoteObj->RemoveDeathRecipient(deathRecipient_); - std::lock_guard lock(observerLock_); + std::lock_guard lock(observerLock_); auto it = std::find_if(observerList_.begin(), observerList_.end(), [&remoteObj] (const sptr item) { return (item && item->AsObject() == remoteObj); diff --git a/services/abilitymgr/src/mission_data_storage.cpp b/services/abilitymgr/src/mission_data_storage.cpp index 93acc66640..96ea506f83 100644 --- a/services/abilitymgr/src/mission_data_storage.cpp +++ b/services/abilitymgr/src/mission_data_storage.cpp @@ -77,11 +77,6 @@ MissionDataStorage::MissionDataStorage(int userId) MissionDataStorage::~MissionDataStorage() {} -void MissionDataStorage::SetEventHandler(const std::shared_ptr &handler) -{ - handler_ = handler; -} - bool MissionDataStorage::LoadAllMissionInfo(std::list &missionInfoList) { std::vector fileNameVec; @@ -308,7 +303,7 @@ std::shared_ptr MissionDataStorage::GetReducedPixelMap( bool MissionDataStorage::GetCachedSnapshot(int32_t missionId, MissionSnapshot& missionSnapshot) { - std::lock_guard lock(cachedPixelMapMutex_); + std::lock_guard lock(cachedPixelMapMutex_); auto pixelMap = cachedPixelMap_.find(missionId); if (pixelMap != cachedPixelMap_.end()) { missionSnapshot.snapshot = pixelMap->second; @@ -319,7 +314,7 @@ bool MissionDataStorage::GetCachedSnapshot(int32_t missionId, MissionSnapshot& m bool MissionDataStorage::SaveCachedSnapshot(int32_t missionId, const MissionSnapshot& missionSnapshot) { - std::lock_guard lock(cachedPixelMapMutex_); + std::lock_guard lock(cachedPixelMapMutex_); auto result = cachedPixelMap_.insert_or_assign(missionId, missionSnapshot.snapshot); if (!result.second) { HILOG_ERROR("snapshot: save snapshot cache failed, missionId = %{public}d", missionId); @@ -330,7 +325,7 @@ bool MissionDataStorage::SaveCachedSnapshot(int32_t missionId, const MissionSnap bool MissionDataStorage::DeleteCachedSnapshot(int32_t missionId) { - std::lock_guard lock(cachedPixelMapMutex_); + std::lock_guard lock(cachedPixelMapMutex_); auto result = cachedPixelMap_.erase(missionId); if (result != 1) { HILOG_ERROR("snapshot: delete snapshot cache failed, missionId = %{public}d", missionId); diff --git a/services/abilitymgr/src/mission_info_mgr.cpp b/services/abilitymgr/src/mission_info_mgr.cpp index a6970d6080..b6bf2eba55 100644 --- a/services/abilitymgr/src/mission_info_mgr.cpp +++ b/services/abilitymgr/src/mission_info_mgr.cpp @@ -38,7 +38,7 @@ MissionInfoMgr::~MissionInfoMgr() bool MissionInfoMgr::GenerateMissionId(int32_t &missionId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (currentMissionId_ == MAX_MISSION_ID) { currentMissionId_ = MIN_MISSION_ID; } @@ -58,7 +58,7 @@ bool MissionInfoMgr::GenerateMissionId(int32_t &missionId) bool MissionInfoMgr::Init(int userId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!taskDataPersistenceMgr_) { taskDataPersistenceMgr_ = DelayedSingleton::GetInstance(); if (!taskDataPersistenceMgr_) { @@ -82,7 +82,7 @@ bool MissionInfoMgr::Init(int userId) bool MissionInfoMgr::AddMissionInfo(const InnerMissionInfo &missionInfo) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); return AddMissionInfoInner(missionInfo); } @@ -113,7 +113,7 @@ bool MissionInfoMgr::AddMissionInfoInner(const InnerMissionInfo &missionInfo) bool MissionInfoMgr::UpdateMissionInfo(const InnerMissionInfo &missionInfo) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto id = missionInfo.missionInfo.id; if (missionIdMap_.find(id) == missionIdMap_.end() || !missionIdMap_[id]) { HILOG_ERROR("update mission info failed, missionId %{public}d not exists", id); @@ -149,7 +149,7 @@ bool MissionInfoMgr::UpdateMissionInfo(const InnerMissionInfo &missionInfo) bool MissionInfoMgr::DeleteMissionInfo(int missionId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (missionIdMap_.find(missionId) == missionIdMap_.end()) { HILOG_WARN("missionId %{public}d not exists, no need delete", missionId); return true; @@ -184,7 +184,7 @@ bool MissionInfoMgr::DeleteMissionInfo(int missionId) bool MissionInfoMgr::DeleteAllMissionInfos(const std::shared_ptr &listenerController) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!taskDataPersistenceMgr_) { HILOG_ERROR("taskDataPersistenceMgr_ is nullptr"); return false; @@ -228,7 +228,7 @@ int MissionInfoMgr::GetMissionInfos(int32_t numMax, std::vector &mi return -1; } - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); for (auto &mission : missionInfoList_) { if (static_cast(missionInfos.size()) >= numMax) { break; @@ -248,7 +248,7 @@ int MissionInfoMgr::GetMissionInfos(int32_t numMax, std::vector &mi int MissionInfoMgr::GetMissionInfoById(int32_t missionId, MissionInfo &missionInfo) { HILOG_INFO("missionId:%{public}d", missionId); - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (missionIdMap_.find(missionId) == missionIdMap_.end()) { HILOG_ERROR("missionId %{public}d not exists, get mission info failed", missionId); return -1; @@ -276,7 +276,7 @@ int MissionInfoMgr::GetMissionInfoById(int32_t missionId, MissionInfo &missionIn int MissionInfoMgr::GetInnerMissionInfoById(int32_t missionId, InnerMissionInfo &innerMissionInfo) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (missionIdMap_.find(missionId) == missionIdMap_.end()) { HILOG_ERROR("missionId %{public}d not exists, get inner mission info failed", missionId); return MISSION_NOT_FOUND; @@ -302,7 +302,7 @@ bool MissionInfoMgr::FindReusedMissionInfo(const std::string &missionName, return false; } - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto it = std::find_if(missionInfoList_.begin(), missionInfoList_.end(), [&missionName, &flag, &isFindRecentStandard](const InnerMissionInfo item) { if (missionName != item.missionName) { @@ -334,7 +334,7 @@ bool MissionInfoMgr::FindReusedMissionInfo(const std::string &missionName, int MissionInfoMgr::UpdateMissionLabel(int32_t missionId, const std::string& label) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!taskDataPersistenceMgr_) { HILOG_ERROR("task data persist not init."); return -1; @@ -360,7 +360,7 @@ void MissionInfoMgr::SetMissionAbilityState(int32_t missionId, AbilityState stat if (missionId <= 0) { return; } - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto it = find_if(missionInfoList_.begin(), missionInfoList_.end(), [missionId](const InnerMissionInfo &info) { return missionId == info.missionInfo.id; }); @@ -410,7 +410,7 @@ void MissionInfoMgr::HandleUnInstallApp(const std::string &bundleName, int32_t u void MissionInfoMgr::GetMatchedMission(const std::string &bundleName, int32_t uid, std::list &missions) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); for (const auto& innerMissionInfo : missionInfoList_) { if (innerMissionInfo.bundleName == bundleName && innerMissionInfo.uid == uid) { missions.push_back(innerMissionInfo.missionInfo.id); @@ -420,7 +420,7 @@ void MissionInfoMgr::GetMatchedMission(const std::string &bundleName, int32_t ui void MissionInfoMgr::Dump(std::vector &info) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); for (const auto& innerMissionInfo : missionInfoList_) { innerMissionInfo.Dump(info); } @@ -428,7 +428,7 @@ void MissionInfoMgr::Dump(std::vector &info) void MissionInfoMgr::RegisterSnapshotHandler(const sptr& handler) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); snapshotHandler_ = handler; } @@ -440,7 +440,7 @@ void MissionInfoMgr::UpdateMissionSnapshot(int32_t missionId, const std::shared_ MissionSnapshot savedSnapshot; { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "FindTargetMissionSnapshot"); - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto it = find_if(missionInfoList_.begin(), missionInfoList_.end(), [missionId](const InnerMissionInfo &info) { return missionId == info.missionInfo.id; }); @@ -478,7 +478,7 @@ bool MissionInfoMgr::UpdateMissionSnapshot(int32_t missionId, const sptr lock(mutex_); + std::lock_guard lock(mutex_); auto it = find_if(missionInfoList_.begin(), missionInfoList_.end(), [missionId](const InnerMissionInfo &info) { return missionId == info.missionInfo.id; }); @@ -516,7 +516,7 @@ bool MissionInfoMgr::UpdateMissionSnapshot(int32_t missionId, const sptr lock(savingSnapshotLock_); + std::lock_guard lock(savingSnapshotLock_); auto search = savingSnapshot_.find(missionId); if (search == savingSnapshot_.end()) { savingSnapshot_[missionId] = 1; @@ -536,7 +536,7 @@ bool MissionInfoMgr::UpdateMissionSnapshot(int32_t missionId, const sptr lock(savingSnapshotLock_); + std::unique_lock lock(savingSnapshotLock_); auto search = savingSnapshot_.find(missionId); if (search != savingSnapshot_.end()) { auto savingCount = search->second - 1; @@ -554,7 +554,7 @@ std::shared_ptr MissionInfoMgr::GetSnapshot(int32_t missionId) { HILOG_INFO("missionId:%{public}d", missionId); { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); auto it = find_if(missionInfoList_.begin(), missionInfoList_.end(), [missionId](const InnerMissionInfo &info) { return missionId == info.missionInfo.id; }); @@ -578,7 +578,7 @@ bool MissionInfoMgr::GetMissionSnapshot(int32_t missionId, const sptr lock(mutex_); + std::lock_guard lock(mutex_); auto it = find_if(missionInfoList_.begin(), missionInfoList_.end(), [missionId](const InnerMissionInfo &info) { return missionId == info.missionInfo.id; }); @@ -598,14 +598,14 @@ bool MissionInfoMgr::GetMissionSnapshot(int32_t missionId, const sptr lock(savingSnapshotLock_); + std::unique_lock lock(savingSnapshotLock_); auto search = savingSnapshot_.find(missionId); if (search != savingSnapshot_.end()) { auto savingSnapshotTimeout = 100; // ms std::chrono::milliseconds timeout { savingSnapshotTimeout }; auto waitingCount = 5; auto waitingNum = 0; - while (waitSavingCondition_.wait_for(lock, timeout) == std::cv_status::no_timeout) { + while (waitSavingCondition_.wait_for(lock, timeout) == ffrt::cv_status::no_timeout) { ++waitingNum; auto iter = savingSnapshot_.find(missionId); if (iter == savingSnapshot_.end() || waitingNum == waitingCount) { diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 435a53613c..bf926ea467 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -920,10 +920,9 @@ int MissionListManager::AttachAbilityThread(const sptr &sched HILOG_DEBUG("AbilityMS attach abilityThread, name is %{public}s.", abilityRecord->GetAbilityInfo().name.c_str()); - std::shared_ptr handler = - DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); - handler->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, abilityRecord->GetAbilityRecordId()); + auto eventHandler = DelayedSingleton::GetInstance()->GetEventHandler(); + CHECK_POINTER_AND_RETURN_LOG(eventHandler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); + eventHandler->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, abilityRecord->GetAbilityRecordId()); abilityRecord->SetScheduler(scheduler); @@ -942,8 +941,10 @@ int MissionListManager::AttachAbilityThread(const sptr &sched abilityRecord->CallRequest(); } + auto taskHandler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_AND_RETURN_LOG(taskHandler, ERR_INVALID_VALUE, "Fail to get AbilityTaskHandler."); auto taskName = std::to_string(abilityRecord->GetMissionId()) + "_cold"; - handler->RemoveTask(taskName); + taskHandler->CancelTask(taskName); #ifdef SUPPORT_GRAPHICS abilityRecord->PostCancelStartingWindowHotTask(); #endif @@ -1139,8 +1140,6 @@ int MissionListManager::DispatchState(const std::shared_ptr &abil int MissionListManager::DispatchForeground(const std::shared_ptr &abilityRecord, bool success, AbilityState state) { - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); if (!abilityRecord->IsAbilityState(AbilityState::FOREGROUNDING)) { @@ -1150,15 +1149,18 @@ int MissionListManager::DispatchForeground(const std::shared_ptr abilityRecord->GetAbilityState()); return ERR_INVALID_VALUE; } - - handler->RemoveEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, abilityRecord->GetAbilityRecordId()); + auto eventHandler = DelayedSingleton::GetInstance()->GetEventHandler(); + CHECK_POINTER_AND_RETURN_LOG(eventHandler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); + eventHandler->RemoveEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, abilityRecord->GetAbilityRecordId()); auto self(weak_from_this()); + auto taskHandler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_AND_RETURN_LOG(taskHandler, ERR_INVALID_VALUE, "Fail to get AbilityTaskHandler."); if (success) { #ifdef SUPPORT_GRAPHICS HILOG_INFO("ok"); abilityRecord->SetStartingWindow(false); auto taskName = std::to_string(abilityRecord->GetMissionId()) + "_hot"; - handler->RemoveTask(taskName); + taskHandler->CancelTask(taskName); #endif auto task = [self, abilityRecord]() { auto selfObj = self.lock(); @@ -1168,7 +1170,7 @@ int MissionListManager::DispatchForeground(const std::shared_ptr } selfObj->CompleteForegroundSuccess(abilityRecord); }; - handler->PostTask(task); + taskHandler->SubmitTask(task); } else { auto task = [self, abilityRecord, state]() { auto selfObj = self.lock(); @@ -1178,7 +1180,7 @@ int MissionListManager::DispatchForeground(const std::shared_ptr } selfObj->CompleteForegroundFailed(abilityRecord, state); }; - handler->PostTask(task); + taskHandler->SubmitTask(task); } return ERR_OK; } @@ -1269,8 +1271,8 @@ void MissionListManager::TerminatePreviousAbility(const std::shared_ptr &abilityRecord) { - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityTasktHandler."); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); if (!abilityRecord->IsAbilityState(AbilityState::BACKGROUNDING)) { @@ -1279,10 +1281,10 @@ int MissionListManager::DispatchBackground(const std::shared_ptr } // remove background timeout task. - handler->RemoveTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId())); + handler->CancelTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId())); auto self(shared_from_this()); auto task = [self, abilityRecord]() { self->CompleteBackground(abilityRecord); }; - handler->PostTask(task); + handler->SubmitTask(task); return ERR_OK; } @@ -1650,19 +1652,19 @@ int MissionListManager::DispatchTerminate(const std::shared_ptr & } // remove terminate timeout task. - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); - handler->RemoveTask("terminate_" + std::to_string(abilityRecord->GetAbilityRecordId())); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityTasktHandler."); + handler->CancelTask("terminate_" + std::to_string(abilityRecord->GetAbilityRecordId())); auto self(shared_from_this()); auto task = [self, abilityRecord]() { self->CompleteTerminate(abilityRecord); }; - handler->PostTask(task); + handler->SubmitTask(task); return ERR_OK; } void MissionListManager::DelayCompleteTerminate(const std::shared_ptr &abilityRecord) { - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); CHECK_POINTER(handler); PrintTimeOutLog(abilityRecord, AbilityManagerService::TERMINATE_TIMEOUT_MSG); @@ -1672,7 +1674,7 @@ void MissionListManager::DelayCompleteTerminate(const std::shared_ptrCompleteTerminate(abilityRecord); }; int killTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * KILL_TIMEOUT_MULTIPLE; - handler->PostTask(timeoutTask, "DELAY_KILL_PROCESS", killTimeout); + handler->SubmitTask(timeoutTask, "DELAY_KILL_PROCESS", killTimeout); } void MissionListManager::CompleteTerminate(const std::shared_ptr &abilityRecord) @@ -1981,7 +1983,7 @@ void MissionListManager::NotifyMissionCreated(const std::shared_ptr::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (handler == nullptr) { HILOG_ERROR("Fail to get EventHandler, do not post mission label update message."); return; @@ -1996,7 +1998,7 @@ void MissionListManager::PostMissionLabelUpdateTask(int missionId) const } controller->NotifyMissionLabelUpdated(missionId); }; - handler->PostTask(task, "NotifyMissionLabelUpdated.", DELAY_NOTIFY_LABEL_TIME); + handler->SubmitTask(task, "NotifyMissionLabelUpdated.", DELAY_NOTIFY_LABEL_TIME); } void MissionListManager::PrintTimeOutLog(const std::shared_ptr &ability, uint32_t msgId) @@ -2227,7 +2229,7 @@ void MissionListManager::DelayedResumeTimeout(const std::shared_ptr::GetInstance(); CHECK_POINTER(abilityManagerService); - auto handler = abilityManagerService->GetEventHandler(); + auto handler = abilityManagerService->GetTaskHandler(); CHECK_POINTER(handler); std::weak_ptr wpListMgr = shared_from_this(); auto timeoutTask = [wpListMgr, callerAbility]() { @@ -2237,7 +2239,7 @@ void MissionListManager::DelayedResumeTimeout(const std::shared_ptrBackToCaller(callerAbility); } }; - handler->PostTask(timeoutTask, "Caller_Restart"); + handler->SubmitTask(timeoutTask, "Caller_Restart"); } void MissionListManager::BackToCaller(const std::shared_ptr &callerAbility) @@ -2484,11 +2486,11 @@ void MissionListManager::PostStartWaitingAbility() auto self(shared_from_this()); auto startWaitingAbilityTask = [self]() { self->StartWaitingAbility(); }; - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_LOG(handler, "Fail to get AbilityEventHandler."); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_LOG(handler, "Fail to get AbilityTaskHandler."); /* PostTask to trigger start Ability from waiting queue */ - handler->PostTask(startWaitingAbilityTask, "startWaitingAbility"); + handler->SubmitTask(startWaitingAbilityTask, "startWaitingAbility"); } void MissionListManager::HandleAbilityDied(std::shared_ptr abilityRecord) @@ -2591,7 +2593,7 @@ void MissionListManager::DelayedStartLauncher() { auto abilityManagerService = DelayedSingleton::GetInstance(); CHECK_POINTER(abilityManagerService); - auto handler = abilityManagerService->GetEventHandler(); + auto handler = abilityManagerService->GetTaskHandler(); CHECK_POINTER(handler); std::weak_ptr wpListMgr = shared_from_this(); auto timeoutTask = [wpListMgr]() { @@ -2601,7 +2603,7 @@ void MissionListManager::DelayedStartLauncher() listMgr->BackToLauncher(); } }; - handler->PostTask(timeoutTask, "Launcher_Restart"); + handler->SubmitTask(timeoutTask, "Launcher_Restart"); } void MissionListManager::BackToLauncher() @@ -2713,9 +2715,9 @@ void MissionListManager::CompleteFirstFrameDrawing(const sptr &ab } abilityRecord->SetCompleteFirstFrameDrawing(true); - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (handler == nullptr) { - HILOG_ERROR("Fail to get AbilityEventHandler."); + HILOG_ERROR("Fail to get Ability task handler."); return; } @@ -2730,7 +2732,7 @@ void MissionListManager::CompleteFirstFrameDrawing(const sptr &ab mgr->UpdateMissionSnapshot(abilityRecord); } }; - handler->PostTask(task, "FirstFrameDrawing"); + handler->SubmitTask(task, "FirstFrameDrawing"); auto preloadTask = [owner = weak_from_this(), abilityRecord] { auto mgr = owner.lock(); if (mgr == nullptr) { @@ -2739,7 +2741,7 @@ void MissionListManager::CompleteFirstFrameDrawing(const sptr &ab } mgr->ProcessPreload(abilityRecord); }; - handler->PostTask(preloadTask); + handler->SubmitTask(preloadTask); } void MissionListManager::ProcessPreload(const std::shared_ptr &record) const @@ -2774,9 +2776,9 @@ Closure MissionListManager::GetCancelStartingWindowTask(const std::shared_ptr &abilityRecord) const { HILOG_INFO("call"); - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (!handler) { - HILOG_ERROR("Fail to get AbilityEventHandler."); + HILOG_ERROR("Fail to get AbilityTaskHandler."); return; } @@ -2785,7 +2787,7 @@ void MissionListManager::PostCancelStartingWindowTask(const std::shared_ptrPostTask(task, AppExecFwk::EventQueue::Priority::IMMEDIATE); + handler->SubmitTask(task, TaskQoS::USER_INTERACTIVE); } void MissionListManager::InitPrepareTerminateConfig() @@ -3429,7 +3431,7 @@ void MissionListManager::UninstallApp(const std::string &bundleName, int32_t uid HILOG_INFO("Uninstall app, bundleName: %{public}s, uid:%{public}d", bundleName.c_str(), uid); auto abilityManagerService = DelayedSingleton::GetInstance(); CHECK_POINTER(abilityManagerService); - auto handler = abilityManagerService->GetEventHandler(); + auto handler = abilityManagerService->GetTaskHandler(); CHECK_POINTER(handler); std::weak_ptr wpMgr = shared_from_this(); auto task = [wpMgr, bundleName, uid]() { @@ -3439,7 +3441,7 @@ void MissionListManager::UninstallApp(const std::string &bundleName, int32_t uid mgr->AddUninstallTags(bundleName, uid); } }; - handler->PostTask(task); + handler->SubmitTask(task); } void MissionListManager::AddUninstallTags(const std::string &bundleName, int32_t uid) @@ -3866,22 +3868,21 @@ int MissionListManager::PrepareClearMissionLocked(int missionId, const std::shar mgr->ClearMissionLocking(missionId, mission); } }; - std::shared_ptr handler = - DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); int prepareTerminateTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * PREPARE_TERMINATE_TIMEOUT_MULTIPLE; if (handler) { - handler->PostTask(terminateTask, "PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId()), + handler->SubmitTask(terminateTask, "PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId()), prepareTerminateTimeout); } bool res = abilityRecord->PrepareTerminateAbility(); if (res) { HILOG_INFO("stop terminating."); - handler->RemoveTask("PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId())); + handler->CancelTask("PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId())); return ERR_OK; } - handler->RemoveTask("PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId())); + handler->CancelTask("PrepareTermiante_" + std::to_string(abilityRecord->GetAbilityRecordId())); return ClearMissionLocked(missionId, mission); } diff --git a/services/abilitymgr/src/mission_listener_controller.cpp b/services/abilitymgr/src/mission_listener_controller.cpp index e6d0fcc44a..011a75f77d 100644 --- a/services/abilitymgr/src/mission_listener_controller.cpp +++ b/services/abilitymgr/src/mission_listener_controller.cpp @@ -19,7 +19,6 @@ namespace OHOS { namespace AAFwk { -using namespace OHOS::AppExecFwk; namespace { const std::string THREAD_NAME = "MissionListener"; } @@ -35,7 +34,7 @@ MissionListenerController::~MissionListenerController() void MissionListenerController::Init() { if (!handler_) { - handler_ = std::make_shared(EventRunner::Create(THREAD_NAME)); + handler_ = TaskHandlerWrap::CreateQueueHandler("mission_listener_task_queue"); } } @@ -46,7 +45,7 @@ int MissionListenerController::AddMissionListener(const sptr & return -1; } - std::lock_guard guard(listenerLock_); + std::lock_guard guard(listenerLock_); auto it = std::find_if(missionListeners_.begin(), missionListeners_.end(), [&listener](const sptr &item) { return (item && item->AsObject() == listener->AsObject()); @@ -83,7 +82,7 @@ void MissionListenerController::DelMissionListener(const sptr return; } - std::lock_guard guard(listenerLock_); + std::lock_guard guard(listenerLock_); auto it = std::find_if(missionListeners_.begin(), missionListeners_.end(), [&listener](const sptr item) { return (item && item->AsObject() == listener->AsObject()); @@ -109,7 +108,7 @@ void MissionListenerController::NotifyMissionCreated(int32_t missionId) HILOG_INFO("notify listeners mission is created, missionId:%{public}d.", missionId); self->CallListeners(&IMissionListener::OnMissionCreated, missionId); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void MissionListenerController::NotifyMissionDestroyed(int32_t missionId) @@ -127,7 +126,7 @@ void MissionListenerController::NotifyMissionDestroyed(int32_t missionId) HILOG_INFO("notify listeners mission is destroyed, missionId:%{public}d.", missionId); self->CallListeners(&IMissionListener::OnMissionDestroyed, missionId); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void MissionListenerController::HandleUnInstallApp(const std::list &missions) @@ -151,7 +150,7 @@ void MissionListenerController::HandleUnInstallApp(const std::list &mis self->CallListeners(&IMissionListener::OnMissionDestroyed, id); } }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void MissionListenerController::NotifyMissionSnapshotChanged(int32_t missionId) @@ -170,7 +169,7 @@ void MissionListenerController::NotifyMissionSnapshotChanged(int32_t missionId) HILOG_INFO("notify listeners mission snapshot changed, missionId:%{public}d.", missionId); self->CallListeners(&IMissionListener::OnMissionSnapshotChanged, missionId); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void MissionListenerController::NotifyMissionMovedToFront(int32_t missionId) @@ -189,7 +188,7 @@ void MissionListenerController::NotifyMissionMovedToFront(int32_t missionId) HILOG_INFO("notify listeners mission is moved to front, missionId:%{public}d.", missionId); self->CallListeners(&IMissionListener::OnMissionMovedToFront, missionId); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void MissionListenerController::NotifyMissionFocused(int32_t missionId) @@ -211,7 +210,7 @@ void MissionListenerController::NotifyMissionFocused(int32_t missionId) HILOG_INFO("NotifyMissionFocused, missionId:%{public}d.", missionId); self->CallListeners(&IMissionListener::OnMissionFocused, missionId); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void MissionListenerController::NotifyMissionUnfocused(int32_t missionId) @@ -233,7 +232,7 @@ void MissionListenerController::NotifyMissionUnfocused(int32_t missionId) HILOG_INFO("NotifyMissionUnfocused, missionId:%{public}d.", missionId); self->CallListeners(&IMissionListener::OnMissionUnfocused, missionId); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } #ifdef SUPPORT_GRAPHICS @@ -254,7 +253,7 @@ void MissionListenerController::NotifyMissionIconChanged(int32_t missionId, HILOG_INFO("notify listeners mission icon has changed, missionId:%{public}d.", missionId); self->CallListeners(&IMissionListener::OnMissionIconUpdated, missionId, icon); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } #endif @@ -273,7 +272,7 @@ void MissionListenerController::NotifyMissionClosed(int32_t missionId) HILOG_INFO("NotifyMissionClosed, missionId:%{public}d.", missionId); self->CallListeners(&IMissionListener::OnMissionClosed, missionId); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void MissionListenerController::NotifyMissionLabelUpdated(int32_t missionId) @@ -291,7 +290,7 @@ void MissionListenerController::NotifyMissionLabelUpdated(int32_t missionId) HILOG_INFO("notify listeners mission label has updated, missionId:%{public}d.", missionId); self->CallListeners(&IMissionListener::OnMissionLabelUpdated, missionId); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void MissionListenerController::OnListenerDied(const wptr &remote) @@ -304,7 +303,7 @@ void MissionListenerController::OnListenerDied(const wptr &remote } remoteObj->RemoveDeathRecipient(listenerDeathRecipient_); - std::lock_guard guard(listenerLock_); + std::lock_guard guard(listenerLock_); auto it = std::find_if(missionListeners_.begin(), missionListeners_.end(), [&remoteObj](const sptr item) { return (item && item->AsObject() == remoteObj); diff --git a/services/abilitymgr/src/pending_want_manager.cpp b/services/abilitymgr/src/pending_want_manager.cpp index 9003bc60ee..f8d2392f77 100644 --- a/services/abilitymgr/src/pending_want_manager.cpp +++ b/services/abilitymgr/src/pending_want_manager.cpp @@ -84,7 +84,7 @@ sptr PendingWantManager::GetWantSenderLocked(const int32_t callingU pendingKey->SetRequestResolvedType(wantSenderInfo.allWants.back().resolvedTypes); pendingKey->SetAllWantsInfos(wantSenderInfo.allWants); } - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); auto ref = GetPendingWantRecordByKey(pendingKey); if (ref != nullptr) { if (!needCancel) { @@ -194,7 +194,7 @@ void PendingWantManager::CancelWantSender(std::string &apl, const sptr locker(mutex_); + std::lock_guard locker(mutex_); auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); if (!isSaCall && apl != AbilityUtil::SYSTEM_BASIC && apl != AbilityUtil::SYSTEM_CORE) { HILOG_ERROR("is not allowed to send"); @@ -317,7 +317,7 @@ sptr PendingWantManager::GetPendingWantRecordByCode(int32_t c { HILOG_INFO("begin. wantRecords_ size = %{public}zu", wantRecords_.size()); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); auto iter = std::find_if(wantRecords_.begin(), wantRecords_.end(), [&code](const auto &pair) { return pair.second->GetKey()->GetCode() == code; }); @@ -413,7 +413,7 @@ void PendingWantManager::RegisterCancelListener(const sptr &sender, return; } bool cancel = record->GetCanceled(); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); if (!cancel) { record->RegisterCancelListener(recevier); } @@ -434,7 +434,7 @@ void PendingWantManager::UnregisterCancelListener(const sptr &sende HILOG_ERROR("%{public}s:record is nullptr.", __func__); return; } - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); record->UnregisterCancelListener(recevier); } @@ -498,16 +498,16 @@ void PendingWantManager::ClearPendingWantRecord(const std::string &bundleName, i HILOG_INFO("bundleName: %{public}s", bundleName.c_str()); auto abilityManagerService = DelayedSingleton::GetInstance(); CHECK_POINTER(abilityManagerService); - auto handler = abilityManagerService->GetEventHandler(); + auto handler = abilityManagerService->GetTaskHandler(); CHECK_POINTER(handler); auto task = [bundleName, uid, self = shared_from_this()]() { self->ClearPendingWantRecordTask(bundleName, uid); }; - handler->PostTask(task); + handler->SubmitTask(task); } void PendingWantManager::ClearPendingWantRecordTask(const std::string &bundleName, int32_t uid) { HILOG_INFO("bundleName: %{public}s", bundleName.c_str()); - std::lock_guard locker(mutex_); + std::lock_guard locker(mutex_); auto iter = wantRecords_.begin(); while (iter != wantRecords_.end()) { bool hasBundle = false; diff --git a/services/abilitymgr/src/pending_want_record.cpp b/services/abilitymgr/src/pending_want_record.cpp index 0789f730b9..ad7ea0784b 100644 --- a/services/abilitymgr/src/pending_want_record.cpp +++ b/services/abilitymgr/src/pending_want_record.cpp @@ -62,7 +62,7 @@ void PendingWantRecord::UnregisterCancelListener(const sptr &rece int32_t PendingWantRecord::SenderInner(SenderInfo &senderInfo) { HILOG_INFO("%{public}s:begin.", __func__); - std::lock_guard locker(lock_); + std::lock_guard locker(lock_); if (canceled_) { return START_CANCELED; } 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 1e58a8a386..47f8de917a 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -41,7 +41,7 @@ const int KILL_TIMEOUT_MULTIPLE = 3; int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sptr sessionInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); HILOG_DEBUG("Call."); if (sessionInfo == nullptr || sessionInfo->sessionToken == nullptr) { HILOG_ERROR("sessionInfo is invalid."); @@ -97,7 +97,7 @@ int UIAbilityLifecycleManager::AttachAbilityThread(const sptr const sptr &token) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); if (!IsContainsAbilityInner(token)) { return ERR_INVALID_VALUE; } @@ -132,7 +132,7 @@ int UIAbilityLifecycleManager::AttachAbilityThread(const sptr void UIAbilityLifecycleManager::OnAbilityRequestDone(const sptr &token, int32_t state) const { HILOG_DEBUG("Ability request state %{public}d done.", state); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); AppAbilityState abilityState = DelayedSingleton::GetInstance()->ConvertToAppAbilityState(state); if (abilityState == AppAbilityState::ABILITY_STATE_FOREGROUND) { auto&& abilityRecord = Token::GetAbilityRecordByToken(token); @@ -151,7 +151,7 @@ int UIAbilityLifecycleManager::AbilityTransactionDone(const sptr std::string abilityState = AbilityRecord::ConvertAbilityState(static_cast(targetState)); HILOG_INFO("AbilityTransactionDone, state: %{public}s.", abilityState.c_str()); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); auto abilityRecord = GetAbilityRecordByToken(token); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); @@ -169,7 +169,7 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(const AbilityRequest &a { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("Call."); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); auto isSpecified = (abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::SPECIFIED); if (isSpecified) { EnqueueAbilityToFront(abilityRequest); @@ -212,6 +212,8 @@ int UIAbilityLifecycleManager::DispatchForeground(const std::shared_ptr::GetInstance()->GetEventHandler(); CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); + auto taskHandler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_AND_RETURN_LOG(taskHandler, ERR_INVALID_VALUE, "Fail to get AbilityTaskHandler."); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); if (!abilityRecord->IsAbilityState(AbilityState::FOREGROUNDING)) { @@ -233,7 +235,7 @@ int UIAbilityLifecycleManager::DispatchForeground(const std::shared_ptrCompleteForegroundSuccess(abilityRecord); }; - handler->PostTask(task); + taskHandler->SubmitTask(task); } else { auto task = [self, abilityRecord, state]() { auto selfObj = self.lock(); @@ -251,15 +253,15 @@ int UIAbilityLifecycleManager::DispatchForeground(const std::shared_ptrHandleForegroundFailed(abilityRecord, state); }; - handler->PostTask(task); + taskHandler->SubmitTask(task); } return ERR_OK; } int UIAbilityLifecycleManager::DispatchBackground(const std::shared_ptr &abilityRecord) { - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityTaskHandler."); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); if (!abilityRecord->IsAbilityState(AbilityState::BACKGROUNDING)) { @@ -268,10 +270,10 @@ int UIAbilityLifecycleManager::DispatchBackground(const std::shared_ptrRemoveTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId())); + handler->CancelTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId())); auto self(shared_from_this()); auto task = [self, abilityRecord]() { self->CompleteBackground(abilityRecord); }; - handler->PostTask(task); + handler->SubmitTask(task); return ERR_OK; } @@ -285,12 +287,12 @@ int UIAbilityLifecycleManager::DispatchTerminate(const std::shared_ptr::GetInstance()->GetEventHandler(); - CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); - handler->RemoveTask("terminate_" + std::to_string(abilityRecord->GetAbilityRecordId())); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); + CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityTaskHandler."); + handler->CancelTask("terminate_" + std::to_string(abilityRecord->GetAbilityRecordId())); auto self(shared_from_this()); auto task = [self, abilityRecord]() { self->CompleteTerminate(abilityRecord); }; - handler->PostTask(task); + handler->SubmitTask(task); return ERR_OK; } @@ -298,7 +300,7 @@ int UIAbilityLifecycleManager::DispatchTerminate(const std::shared_ptr &abilityRecord) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); CHECK_POINTER(abilityRecord); // ability do not save window mode @@ -327,7 +329,7 @@ void UIAbilityLifecycleManager::HandleForegroundFailed(const std::shared_ptr(state)); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); if (ability == nullptr) { HILOG_ERROR("ability record is nullptr."); return; @@ -367,7 +369,7 @@ std::shared_ptr UIAbilityLifecycleManager::GetAbilityRecordByToke bool UIAbilityLifecycleManager::IsContainsAbility(const sptr &token) const { - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); return IsContainsAbilityInner(token); } @@ -433,7 +435,7 @@ void UIAbilityLifecycleManager::UpdateAbilityRecordLaunchReason( std::shared_ptr UIAbilityLifecycleManager::GetUIAbilityRecordBySessionInfo( const sptr &sessionInfo) { - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); CHECK_POINTER_AND_RETURN(sessionInfo, nullptr); CHECK_POINTER_AND_RETURN(sessionInfo->sessionToken, nullptr); auto sessionToken = iface_cast(sessionInfo->sessionToken); @@ -454,7 +456,7 @@ std::shared_ptr UIAbilityLifecycleManager::GetUIAbilityRecordBySe int UIAbilityLifecycleManager::MinimizeUIAbility(const std::shared_ptr &abilityRecord) { HILOG_DEBUG("call"); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); if (abilityRecord == nullptr) { HILOG_ERROR("ability record is null"); return ERR_INVALID_VALUE; @@ -506,7 +508,7 @@ int UIAbilityLifecycleManager::ResolveLocked(const AbilityRequest &abilityReques int UIAbilityLifecycleManager::CallAbilityLocked(const AbilityRequest &abilityRequest) { HILOG_DEBUG("Call."); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); // Get target uiAbility record. std::shared_ptr uiAbilityRecord; @@ -554,7 +556,7 @@ int UIAbilityLifecycleManager::CallAbilityLocked(const AbilityRequest &abilityRe void UIAbilityLifecycleManager::CallUIAbilityBySCB(const sptr &sessionInfo) { HILOG_DEBUG("Call."); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); if (sessionInfo == nullptr || sessionInfo->sessionToken == nullptr) { HILOG_ERROR("sessionInfo is invalid."); return; @@ -697,7 +699,7 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(const std::shared_ptr &abilityRecord) { - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); if (abilityRecord->GetAbilityState() != AbilityState::BACKGROUNDING) { HILOG_ERROR("failed, ability state is %{public}d, it can't complete background.", abilityRecord->GetAbilityState()); @@ -738,7 +740,7 @@ int UIAbilityLifecycleManager::CloseUIAbility(const std::shared_ptr guard(sessionLock_); + std::lock_guard guard(sessionLock_); HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); std::string element = abilityRecord->GetWant().GetElement().GetURI(); @@ -782,7 +784,7 @@ int UIAbilityLifecycleManager::CloseUIAbility(const std::shared_ptr &abilityRecord) { - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); CHECK_POINTER(handler); PrintTimeOutLog(abilityRecord, AbilityManagerService::TERMINATE_TIMEOUT_MSG); @@ -792,13 +794,13 @@ void UIAbilityLifecycleManager::DelayCompleteTerminate(const std::shared_ptrCompleteTerminate(abilityRecord); }; int killTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * KILL_TIMEOUT_MULTIPLE; - handler->PostTask(timeoutTask, "DELAY_KILL_PROCESS", killTimeout); + handler->SubmitTask(timeoutTask, "DELAY_KILL_PROCESS", killTimeout); } void UIAbilityLifecycleManager::CompleteTerminate(const std::shared_ptr &abilityRecord) { CHECK_POINTER(abilityRecord); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (abilityRecord->GetAbilityState() != AbilityState::TERMINATING) { @@ -903,7 +905,7 @@ void UIAbilityLifecycleManager::ReportEventToSuspendManager(const AppExecFwk::Ab void UIAbilityLifecycleManager::OnTimeOut(uint32_t msgId, int64_t abilityRecordId) { HILOG_DEBUG("call, msgId is %{public}d", msgId); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); std::shared_ptr abilityRecord; for (auto iter = sessionAbilityMap_.begin(); iter != sessionAbilityMap_.end(); iter++) { if (iter->second != nullptr && iter->second->GetAbilityRecordId() == abilityRecordId) { @@ -998,7 +1000,7 @@ void UIAbilityLifecycleManager::HandleForegroundTimeout(const std::shared_ptr abilityRecord) { HILOG_DEBUG("call"); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); if (abilityRecord == nullptr) { HILOG_ERROR("failed, ability record is nullptr"); return; @@ -1015,7 +1017,7 @@ void UIAbilityLifecycleManager::OnAbilityDied(std::shared_ptr abi void UIAbilityLifecycleManager::OnAcceptWantResponse(const AAFwk::Want &want, const std::string &flag) { HILOG_DEBUG("call"); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); if (abilityQueue_.empty()) { return; } @@ -1060,7 +1062,7 @@ void UIAbilityLifecycleManager::StartSpecifiedAbilityBySCB(const Want &want, int return; } { - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); EnqueueAbilityToFront(abilityRequest); } DelayedSingleton::GetInstance()->StartSpecifiedAbility( @@ -1185,7 +1187,7 @@ int UIAbilityLifecycleManager::StartAbilityBySpecifed(const AbilityRequest &abil void UIAbilityLifecycleManager::CallRequestDone(const std::shared_ptr &abilityRecord, const sptr &callStub) { - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); if (abilityRecord == nullptr) { HILOG_ERROR("ability record is null."); return; @@ -1205,7 +1207,7 @@ int UIAbilityLifecycleManager::ReleaseCallLocked( CHECK_POINTER_AND_RETURN(connect, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(connect->AsObject(), ERR_INVALID_VALUE); - std::lock_guard guard(sessionLock_); + std::lock_guard guard(sessionLock_); auto abilityRecords = GetAbilityRecordsByName(element); auto isExist = [connect] (const std::shared_ptr &abilityRecord) { diff --git a/services/abilitymgr/src/task_data_persistence_mgr.cpp b/services/abilitymgr/src/task_data_persistence_mgr.cpp index 3fb5022d55..fb121ccc3d 100644 --- a/services/abilitymgr/src/task_data_persistence_mgr.cpp +++ b/services/abilitymgr/src/task_data_persistence_mgr.cpp @@ -27,24 +27,17 @@ TaskDataPersistenceMgr::TaskDataPersistenceMgr() TaskDataPersistenceMgr::~TaskDataPersistenceMgr() { - eventLoop_.reset(); - handler_.reset(); HILOG_INFO("TaskDataPersistenceMgr instance is destroyed"); } bool TaskDataPersistenceMgr::Init(int userId) { - if (!eventLoop_) { - eventLoop_ = AppExecFwk::EventRunner::Create(THREAD_NAME); - CHECK_POINTER_RETURN_BOOL(eventLoop_); - } - if (!handler_) { - handler_ = std::make_shared(eventLoop_); + handler_ = TaskHandlerWrap::GetFfrtHandler(); CHECK_POINTER_RETURN_BOOL(handler_); } - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (missionDataStorageMgr_.find(userId) == missionDataStorageMgr_.end()) { currentMissionDataStorage_ = std::make_shared(userId); missionDataStorageMgr_.insert(std::make_pair(userId, currentMissionDataStorage_)); @@ -60,7 +53,7 @@ bool TaskDataPersistenceMgr::Init(int userId) bool TaskDataPersistenceMgr::LoadAllMissionInfo(std::list &missionInfoList) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!currentMissionDataStorage_) { HILOG_ERROR("currentMissionDataStorage_ is nullptr"); return false; @@ -71,7 +64,7 @@ bool TaskDataPersistenceMgr::LoadAllMissionInfo(std::list &mis bool TaskDataPersistenceMgr::SaveMissionInfo(const InnerMissionInfo &missionInfo) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!handler_ || !currentMissionDataStorage_) { HILOG_ERROR("handler_ or currentMissionDataStorage_ is nullptr"); return false; @@ -84,12 +77,13 @@ bool TaskDataPersistenceMgr::SaveMissionInfo(const InnerMissionInfo &missionInfo missionDataStorage->SaveMissionInfo(missionInfo); } }; - return handler_->PostTask(SaveMissionInfoFunc, SAVE_MISSION_INFO); + handler_->SubmitTask(SaveMissionInfoFunc, SAVE_MISSION_INFO); + return true; } bool TaskDataPersistenceMgr::DeleteMissionInfo(int missionId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!handler_ || !currentMissionDataStorage_) { HILOG_ERROR("handler_ or currentMissionDataStorage_ is nullptr"); return false; @@ -102,12 +96,13 @@ bool TaskDataPersistenceMgr::DeleteMissionInfo(int missionId) missionDataStorage->DeleteMissionInfo(missionId); } }; - return handler_->PostTask(DeleteMissionInfoFunc, DELETE_MISSION_INFO); + handler_->SubmitTask(DeleteMissionInfoFunc, DELETE_MISSION_INFO); + return true; } bool TaskDataPersistenceMgr::RemoveUserDir(int32_t userId) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (currentUserId_ == userId) { HILOG_ERROR("can not removed current user dir"); return false; @@ -123,7 +118,7 @@ bool TaskDataPersistenceMgr::RemoveUserDir(int32_t userId) bool TaskDataPersistenceMgr::SaveMissionSnapshot(int missionId, const MissionSnapshot& snapshot) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!handler_ || !currentMissionDataStorage_) { HILOG_ERROR("snapshot: handler_ or currentMissionDataStorage_ is nullptr"); return false; @@ -136,7 +131,8 @@ bool TaskDataPersistenceMgr::SaveMissionSnapshot(int missionId, const MissionSna missionDataStorage->SaveMissionSnapshot(missionId, snapshot); } }; - return handler_->PostTask(SaveMissionSnapshotFunc, SAVE_MISSION_SNAPSHOT); + handler_->SubmitTask(SaveMissionSnapshotFunc, SAVE_MISSION_SNAPSHOT); + return true; } #ifdef SUPPORT_GRAPHICS @@ -152,7 +148,7 @@ std::shared_ptr TaskDataPersistenceMgr::GetSnapshot(int mission bool TaskDataPersistenceMgr::GetMissionSnapshot(int missionId, MissionSnapshot& snapshot, bool isLowResolution) { - std::lock_guard lock(mutex_); + std::lock_guard lock(mutex_); if (!currentMissionDataStorage_) { HILOG_ERROR("snapshot: currentMissionDataStorage_ is nullptr"); return false; diff --git a/services/abilitymgr/src/user_controller.cpp b/services/abilitymgr/src/user_controller.cpp index 1de1a085df..0517302967 100644 --- a/services/abilitymgr/src/user_controller.cpp +++ b/services/abilitymgr/src/user_controller.cpp @@ -63,20 +63,15 @@ UserController::~UserController() void UserController::Init() { - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = DelayedSingleton::GetInstance()->GetTaskHandler(); if (!handler) { return; } - auto runner = handler->GetEventRunner(); - if (!runner) { - return; - } - if (eventHandler_) { return; } - eventHandler_ = std::make_shared(runner, shared_from_this()); + eventHandler_ = std::make_shared(handler, shared_from_this()); } int32_t UserController::StartUser(int32_t userId, bool isForeground) @@ -185,13 +180,13 @@ int32_t UserController::StopUser(int32_t userId) int32_t UserController::GetCurrentUserId() { - std::lock_guard guard(userLock_); + std::lock_guard guard(userLock_); return currentUserId_; } std::shared_ptr UserController::GetUserItem(int32_t userId) { - std::lock_guard guard(userLock_); + std::lock_guard guard(userLock_); auto it = userItems_.find(userId); if (it != userItems_.end()) { return it->second; @@ -222,7 +217,7 @@ bool UserController::IsExistOsAccount(int32_t userId) std::shared_ptr UserController::GetOrCreateUserItem(int32_t userId) { - std::lock_guard guard(userLock_); + std::lock_guard guard(userLock_); auto it = userItems_.find(userId); if (it != userItems_.end()) { return it->second; @@ -235,7 +230,7 @@ std::shared_ptr UserController::GetOrCreateUserItem(int32_t userId) void UserController::SetCurrentUserId(int32_t userId) { - std::lock_guard guard(userLock_); + std::lock_guard guard(userLock_); currentUserId_ = userId; HILOG_DEBUG("set current userId: %{public}d", userId); DelayedSingleton::GetInstance()->SetCurrentUserId(userId); @@ -259,7 +254,7 @@ void UserController::UserBootDone(std::shared_ptr &item) } int32_t userId = item->GetUserId(); - std::lock_guard guard(userLock_); + std::lock_guard guard(userLock_); auto it = userItems_.find(userId); if (it != userItems_.end()) { return; @@ -306,20 +301,15 @@ void UserController::SendSystemUserStart(int32_t userId) return; } - std::shared_ptr eventData = std::make_shared(); + auto eventData = std::make_shared(); eventData->newUserId = userId; - auto event = InnerEvent::Get(UserEventHandler::EVENT_SYSTEM_USER_START, eventData); - handler->SendEvent(event); + handler->SendEvent(EventWrap(UserEventHandler::EVENT_SYSTEM_USER_START, eventData)); } -void UserController::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +void UserController::ProcessEvent(const EventWrap &event) { - if (!event) { - return; - } - - auto eventId = event->GetInnerEventId(); - auto eventData = event->GetSharedObject(); + auto eventId = event.GetEventId(); + auto eventData = static_cast(event.GetEventData().get()); if (!eventData) { HILOG_DEBUG("no event data, event id: %{public}u.", eventId); return; @@ -365,11 +355,10 @@ void UserController::SendSystemUserCurrent(int32_t oldUserId, int32_t newUserId) return; } - std::shared_ptr eventData = std::make_shared(); + auto eventData = std::make_shared(); eventData->oldUserId = oldUserId; eventData->newUserId = newUserId; - auto event = InnerEvent::Get(UserEventHandler::EVENT_SYSTEM_USER_CURRENT, eventData); - handler->SendEvent(event); + handler->SendEvent(EventWrap(UserEventHandler::EVENT_SYSTEM_USER_CURRENT, eventData)); } void UserController::SendReportUserSwitch(int32_t oldUserId, int32_t newUserId, @@ -380,13 +369,11 @@ void UserController::SendReportUserSwitch(int32_t oldUserId, int32_t newUserId, return; } - handler->RemoveEvent(UserEventHandler::EVENT_REPORT_USER_SWITCH); - std::shared_ptr eventData = std::make_shared(); + auto eventData = std::make_shared(); eventData->oldUserId = oldUserId; eventData->newUserId = newUserId; eventData->userItem = usrItem; - auto event = InnerEvent::Get(UserEventHandler::EVENT_REPORT_USER_SWITCH, eventData); - handler->SendEvent(event); + handler->SendEvent(EventWrap(UserEventHandler::EVENT_REPORT_USER_SWITCH, eventData)); } void UserController::SendUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, @@ -397,13 +384,12 @@ void UserController::SendUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, return; } - handler->RemoveEvent(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT); - std::shared_ptr eventData = std::make_shared(); + auto eventData = std::make_shared(); eventData->oldUserId = oldUserId; eventData->newUserId = newUserId; eventData->userItem = usrItem; - auto event = InnerEvent::Get(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT, eventData); - handler->SendEvent(event, USER_SWITCH_TIMEOUT); + handler->SendEvent(EventWrap(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT, + eventData), USER_SWITCH_TIMEOUT); } void UserController::SendContinueUserSwitch(int32_t oldUserId, int32_t newUserId, @@ -414,13 +400,11 @@ void UserController::SendContinueUserSwitch(int32_t oldUserId, int32_t newUserId return; } - handler->RemoveEvent(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT); - std::shared_ptr eventData = std::make_shared(); + auto eventData = std::make_shared(); eventData->oldUserId = oldUserId; eventData->newUserId = newUserId; eventData->userItem = usrItem; - auto event = InnerEvent::Get(UserEventHandler::EVENT_CONTINUE_USER_SWITCH, eventData); - handler->SendEvent(event); + handler->SendEvent(EventWrap(UserEventHandler::EVENT_CONTINUE_USER_SWITCH, eventData)); } void UserController::SendUserSwitchDone(int32_t userId) @@ -430,11 +414,10 @@ void UserController::SendUserSwitchDone(int32_t userId) return; } - handler->RemoveEvent(UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE); - std::shared_ptr eventData = std::make_shared(); + auto eventData = std::make_shared(); eventData->newUserId = userId; - auto event = InnerEvent::Get(UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE, eventData); - handler->SendEvent(event); + handler->SendEvent(EventWrap(UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE, + eventData)); } void UserController::HandleSystemUserStart(int32_t userId) diff --git a/services/abilitymgr/src/user_event_handler.cpp b/services/abilitymgr/src/user_event_handler.cpp index 0609e75700..47431296c3 100644 --- a/services/abilitymgr/src/user_event_handler.cpp +++ b/services/abilitymgr/src/user_event_handler.cpp @@ -21,18 +21,13 @@ namespace OHOS { namespace AAFwk { UserEventHandler::UserEventHandler( - const std::shared_ptr &runner, const std::weak_ptr &owner) - : AppExecFwk::EventHandler(runner), controller_(owner) + const std::shared_ptr &taskHandler, const std::weak_ptr &owner) + : EventHandlerWrap(taskHandler), controller_(owner) { } -void UserEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +void UserEventHandler::ProcessEvent(const EventWrap &event) { - if (!event) { - HILOG_ERROR("invalid event"); - return; - } - auto owner = controller_.lock(); if (owner) { owner->ProcessEvent(event); diff --git a/services/abilitymgr/src/window_focus_changed_listener.cpp b/services/abilitymgr/src/window_focus_changed_listener.cpp index f65880d06a..a5d3bf1a8f 100644 --- a/services/abilitymgr/src/window_focus_changed_listener.cpp +++ b/services/abilitymgr/src/window_focus_changed_listener.cpp @@ -28,7 +28,7 @@ void WindowFocusChangedListener::OnFocused(const sptr &focusCha return; } - if (eventHandler_) { + if (taskHandler_) { auto task = [inner = owner_, focusChangeInfo] { auto owner = inner.lock(); if (!owner) { @@ -37,7 +37,7 @@ void WindowFocusChangedListener::OnFocused(const sptr &focusCha } owner->HandleFocused(focusChangeInfo); }; - eventHandler_->PostTask(task); + taskHandler_->SubmitTask(task); } } @@ -48,7 +48,7 @@ void WindowFocusChangedListener::OnUnfocused(const sptr &focusC return; } - if (eventHandler_) { + if (taskHandler_) { auto task = [inner = owner_, focusChangeInfo] { auto owner = inner.lock(); if (!owner) { @@ -57,7 +57,7 @@ void WindowFocusChangedListener::OnUnfocused(const sptr &focusC } owner->HandleUnfocused(focusChangeInfo); }; - eventHandler_->PostTask(task); + taskHandler_->SubmitTask(task); } } } // namespace AAFwk diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index 9cea55b8ac..cbc65d3e5f 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -72,6 +72,7 @@ ohos_shared_library("libappms") { "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", ] external_deps = [ @@ -83,7 +84,7 @@ ohos_shared_library("libappms") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index 6f458911c1..b5e1384824 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -22,7 +22,7 @@ #include "appexecfwk_errors.h" #include "application_info.h" #include "app_mgr_constants.h" -#include "app_mgr_service_event_handler.h" +#include "task_handler_wrap.h" #include "app_mgr_service_inner.h" #include "app_record_id.h" #include "app_running_record.h" @@ -36,7 +36,8 @@ namespace AppExecFwk { class AmsMgrScheduler : public AmsMgrStub { public: AmsMgrScheduler( - const std::shared_ptr &MgrServiceInner_, const std::shared_ptr &Handler_); + const std::shared_ptr &MgrServiceInner_, + const std::shared_ptr &Handler_); virtual ~AmsMgrScheduler() override; /** @@ -187,7 +188,7 @@ private: private: std::shared_ptr amsMgrServiceInner_; - std::shared_ptr amsHandler_; + std::shared_ptr amsHandler_; sptr systemAbilityMgr_; DISALLOW_COPY_AND_MOVE(AmsMgrScheduler); diff --git a/services/appmgr/include/app_death_recipient.h b/services/appmgr/include/app_death_recipient.h index 138344049c..46bad0baf9 100644 --- a/services/appmgr/include/app_death_recipient.h +++ b/services/appmgr/include/app_death_recipient.h @@ -18,7 +18,7 @@ #include "iremote_object.h" -#include "app_mgr_service_event_handler.h" +#include "task_handler_wrap.h" namespace OHOS { namespace AppExecFwk { @@ -33,7 +33,7 @@ public: * * @param handler, event handler instance. */ - void SetEventHandler(const std::shared_ptr &handler); + void SetTaskHandler(const std::shared_ptr &handler); /** * @brief Setting application service internal handler instance. @@ -46,7 +46,7 @@ public: private: bool isRenderProcess_ = false; - std::weak_ptr handler_; + std::weak_ptr handler_; std::weak_ptr appMgrServiceInner_; }; } // namespace AppExecFwk diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 0d01a3179c..b45c6bcabb 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -23,7 +23,7 @@ #include "if_system_ability_manager.h" #include "nocopyable.h" #include "system_ability.h" - +#include "task_handler_wrap.h" #include "ability_info.h" #include "ability_running_record.h" #include "appexecfwk_errors.h" @@ -407,8 +407,8 @@ private: private: std::shared_ptr appMgrServiceInner_; AppMgrServiceState appMgrServiceState_; - std::shared_ptr runner_; - std::shared_ptr handler_; + std::shared_ptr taskHandler_; + std::shared_ptr eventHandler_; sptr systemAbilityMgr_; sptr amsMgrScheduler_; diff --git a/services/appmgr/include/app_mgr_service_event_handler.h b/services/appmgr/include/app_mgr_service_event_handler.h index ba22db4950..3a2494e032 100644 --- a/services/appmgr/include/app_mgr_service_event_handler.h +++ b/services/appmgr/include/app_mgr_service_event_handler.h @@ -16,18 +16,19 @@ #ifndef OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_EVENT_HANDLER_H #define OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_EVENT_HANDLER_H -#include "event_handler.h" +#include "event_handler_wrap.h" namespace OHOS { namespace AppExecFwk { class AppMgrServiceInner; -class AMSEventHandler : public EventHandler { +class AMSEventHandler : public AAFwk::EventHandlerWrap { public: - AMSEventHandler(const std::shared_ptr &runner, const std::weak_ptr &appMgr); + AMSEventHandler(const std::shared_ptr &taskHandler, + const std::weak_ptr &appMgr); virtual ~AMSEventHandler() override; - virtual void ProcessEvent(const InnerEvent::Pointer &event) override; + virtual void ProcessEvent(const AAFwk::EventWrap &event) override; static constexpr uint32_t TERMINATE_ABILITY_TIMEOUT_MSG = 0; static constexpr uint32_t TERMINATE_APPLICATION_TIMEOUT_MSG = 1; diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 987ac7b603..8bfced285b 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -22,10 +22,11 @@ #include #include #include +#include "cpp/mutex.h" #include "iremote_object.h" #include "refbase.h" - +#include "task_handler_wrap.h" #include "ability_info.h" #include "appexecfwk_errors.h" #include "app_death_recipient.h" @@ -474,9 +475,17 @@ public: virtual void AddAppDeathRecipient(const pid_t pid, const sptr &appDeathRecipient) const; - void HandleTimeOut(const InnerEvent::Pointer &event); + void HandleTimeOut(const AAFwk::EventWrap &event); - void SetEventHandler(const std::shared_ptr &handler); + void SetTaskHandler(std::shared_ptr taskHandler) + { + taskHandler_ = taskHandler; + } + + void SetEventHandler(const std::shared_ptr &eventHandler) + { + eventHandler_ = eventHandler; + } void HandleAbilityAttachTimeOut(const sptr &token); @@ -924,13 +933,14 @@ private: std::shared_ptr appProcessManager_; std::shared_ptr remoteClientManager_; std::shared_ptr appRunningManager_; + std::shared_ptr taskHandler_; std::shared_ptr eventHandler_; std::shared_ptr configuration_; - std::mutex userTestLock_; - std::mutex appStateCallbacksLock_; - std::mutex renderUidSetLock_; + ffrt::mutex userTestLock_; + ffrt::mutex appStateCallbacksLock_; + ffrt::mutex renderUidSetLock_; sptr startSpecifiedAbilityResponse_; - std::mutex configurationObserverLock_; + ffrt::mutex configurationObserverLock_; std::vector> configurationObservers_; sptr focusListener_; std::vector> restartResedentTaskList_; diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index aa0cbeac04..e3f7b1b01a 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -19,6 +19,7 @@ #include #include #include +#include "cpp/mutex.h" #include "iremote_object.h" #include "refbase.h" @@ -210,7 +211,7 @@ private: private: std::map> appRunningRecordMap_; std::map processRestartRecord_; - std::mutex lock_; + ffrt::mutex lock_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 0f53c27627..0f0d9c866f 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -20,11 +20,14 @@ #include #include #include +#include "cpp/mutex.h" #include "iremote_object.h" #include "irender_scheduler.h" #include "ability_running_record.h" #include "ability_state_data.h" #include "application_info.h" +#include "task_handler_wrap.h" +#include "app_mgr_service_event_handler.h" #include "app_death_recipient.h" #include "app_launch_data.h" #include "app_mgr_constants.h" @@ -493,6 +496,7 @@ public: */ int32_t UpdateConfiguration(const Configuration &config); + void SetTaskHandler(std::shared_ptr taskHandler); void SetEventHandler(const std::shared_ptr &handler); int64_t GetEventId() const; @@ -682,6 +686,8 @@ private: void SendEvent(uint32_t msg, int64_t timeOut); + void SendClearTask(uint32_t msg, int64_t timeOut); + void RemoveModuleRecord(const std::shared_ptr &record); private: @@ -696,19 +702,22 @@ private: std::string appName_; std::string processName_; // the name of this process int64_t eventId_ = 0; + int64_t startProcessSpecifiedAbilityEventId_ = 0; + int64_t addAbilityStageInfoEventId_ = 0; std::list> foregroundingAbilityTokens_; std::weak_ptr appMgrServiceInner_; sptr appDeathRecipient_ = nullptr; std::shared_ptr priorityObject_ = nullptr; std::shared_ptr appLifeCycleDeal_ = nullptr; - std::shared_ptr eventHandler_ = nullptr; + std::shared_ptr taskHandler_; + std::shared_ptr eventHandler_; bool isTerminating = false; std::string signCode_; // the sign of this hap std::string jointUserId_; std::map> appInfos_; - std::mutex appInfosLock_; + ffrt::mutex appInfosLock_; std::map>> hapModules_; - mutable std::mutex hapModulesLock_; + mutable ffrt::mutex hapModulesLock_; int32_t mainUid_; std::string mainBundleName_; bool isLauncherApp_; @@ -730,7 +739,7 @@ private: // render record std::map> renderRecordMap_; - std::mutex renderRecordMapLock_; + ffrt::mutex renderRecordMapLock_; AppSpawnStartMsg startMsg_; int32_t appIndex_ = 0; bool securityFlag_ = false; diff --git a/services/appmgr/include/app_state_observer_manager.h b/services/appmgr/include/app_state_observer_manager.h index 8496444374..cfe4218350 100644 --- a/services/appmgr/include/app_state_observer_manager.h +++ b/services/appmgr/include/app_state_observer_manager.h @@ -20,6 +20,7 @@ #include #include #include +#include "cpp/mutex.h" #include "app_running_record.h" #include "app_state_data.h" @@ -29,6 +30,7 @@ #include "permission_verification.h" #include "singleton.h" #include "uri_permission_manager_client.h" +#include "task_handler_wrap.h" namespace OHOS { namespace AppExecFwk { @@ -74,8 +76,8 @@ private: void HandleOnProcessResued(const std::shared_ptr &appRecord); private: - std::shared_ptr handler_; - std::mutex observerLock_; + std::shared_ptr handler_; + ffrt::mutex observerLock_; std::map, sptr> recipientMap_; std::map, std::vector> appStateObserverMap_; }; diff --git a/services/appmgr/include/module_running_record.h b/services/appmgr/include/module_running_record.h index 123d8523c0..d2079fb990 100644 --- a/services/appmgr/include/module_running_record.h +++ b/services/appmgr/include/module_running_record.h @@ -21,6 +21,7 @@ #include #include #include +#include "cpp/mutex.h" #include "iremote_object.h" #include "ability_info.h" @@ -163,7 +164,7 @@ private: ModuleRecordState GetState() const; private: - mutable std::mutex abilitiesMutex_; + mutable ffrt::mutex abilitiesMutex_; std::map, std::shared_ptr> abilities_; std::map, std::shared_ptr> terminateAbilities_; std::weak_ptr appMgrServiceInner_; diff --git a/services/appmgr/include/window_focus_changed_listener.h b/services/appmgr/include/window_focus_changed_listener.h index 9d02499c38..182dbded54 100644 --- a/services/appmgr/include/window_focus_changed_listener.h +++ b/services/appmgr/include/window_focus_changed_listener.h @@ -18,15 +18,15 @@ #include "window_manager.h" +#include "task_handler_wrap.h" namespace OHOS { namespace AppExecFwk { class AppMgrServiceInner; -class AMSEventHandler; class WindowFocusChangedListener : public OHOS::Rosen::IFocusChangedListener { public: WindowFocusChangedListener(const std::shared_ptr& owner, - const std::shared_ptr& handler); + const std::shared_ptr& handler); virtual ~WindowFocusChangedListener(); void OnFocused(const sptr &focusChangeInfo) override; @@ -34,7 +34,7 @@ public: private: std::weak_ptr owner_; - std::shared_ptr eventHandler_; + std::shared_ptr taskHandler_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index f6176db785..a41f967d85 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -43,7 +43,8 @@ const std::string TASK_KILL_APPLICATION = "KillApplicationTask"; }; // namespace AmsMgrScheduler::AmsMgrScheduler( - const std::shared_ptr &mgrServiceInner_, const std::shared_ptr &handler_) + const std::shared_ptr &mgrServiceInner_, + const std::shared_ptr &handler_) : amsMgrServiceInner_(mgrServiceInner_), amsHandler_(handler_) {} @@ -73,7 +74,7 @@ void AmsMgrScheduler::LoadAbility(const sptr &token, const sptr loadAbilityFunc = std::bind(&AppMgrServiceInner::LoadAbility, amsMgrServiceInner_, token, preToken, abilityInfo, appInfo, want); - amsHandler_->PostTask(loadAbilityFunc, TASK_LOAD_ABILITY); + amsHandler_->SubmitTask(loadAbilityFunc, TASK_LOAD_ABILITY); } void AmsMgrScheduler::UpdateAbilityState(const sptr &token, const AbilityState state) @@ -88,7 +89,7 @@ void AmsMgrScheduler::UpdateAbilityState(const sptr &token, const } std::function updateAbilityStateFunc = std::bind(&AppMgrServiceInner::UpdateAbilityState, amsMgrServiceInner_, token, state); - amsHandler_->PostTask(updateAbilityStateFunc, TASK_UPDATE_ABILITY_STATE); + amsHandler_->SubmitTask(updateAbilityStateFunc, TASK_UPDATE_ABILITY_STATE); } void AmsMgrScheduler::UpdateExtensionState(const sptr &token, const ExtensionState state) @@ -103,7 +104,7 @@ void AmsMgrScheduler::UpdateExtensionState(const sptr &token, con } std::function updateExtensionStateFunc = std::bind(&AppMgrServiceInner::UpdateExtensionState, amsMgrServiceInner_, token, state); - amsHandler_->PostTask(updateExtensionStateFunc, TASK_UPDATE_EXTENSION_STATE); + amsHandler_->SubmitTask(updateExtensionStateFunc, TASK_UPDATE_EXTENSION_STATE); } void AmsMgrScheduler::TerminateAbility(const sptr &token, bool clearMissionFlag) @@ -118,7 +119,7 @@ void AmsMgrScheduler::TerminateAbility(const sptr &token, bool cl } std::function terminateAbilityFunc = std::bind(&AppMgrServiceInner::TerminateAbility, amsMgrServiceInner_, token, clearMissionFlag); - amsHandler_->PostTask(terminateAbilityFunc, TASK_TERMINATE_ABILITY); + amsHandler_->SubmitTask(terminateAbilityFunc, TASK_TERMINATE_ABILITY); } void AmsMgrScheduler::RegisterAppStateCallback(const sptr &callback) @@ -128,7 +129,7 @@ void AmsMgrScheduler::RegisterAppStateCallback(const sptr &ca } std::function registerAppStateCallbackFunc = std::bind(&AppMgrServiceInner::RegisterAppStateCallback, amsMgrServiceInner_, callback); - amsHandler_->PostTask(registerAppStateCallbackFunc, TASK_REGISTER_APP_STATE_CALLBACK); + amsHandler_->SubmitTask(registerAppStateCallbackFunc, TASK_REGISTER_APP_STATE_CALLBACK); } void AmsMgrScheduler::AbilityBehaviorAnalysis(const sptr &token, const sptr &preToken, @@ -144,7 +145,7 @@ void AmsMgrScheduler::AbilityBehaviorAnalysis(const sptr &token, } std::function abilityBehaviorAnalysisFunc = std::bind(&AppMgrServiceInner::AbilityBehaviorAnalysis, amsMgrServiceInner_, token, preToken, visibility, perceptibility, connectionState); - amsHandler_->PostTask(abilityBehaviorAnalysisFunc, TASK_ABILITY_BEHAVIOR_ANALYSIS); + amsHandler_->SubmitTask(abilityBehaviorAnalysisFunc, TASK_ABILITY_BEHAVIOR_ANALYSIS); } void AmsMgrScheduler::KillProcessByAbilityToken(const sptr &token) @@ -160,7 +161,7 @@ void AmsMgrScheduler::KillProcessByAbilityToken(const sptr &token std::function killProcessByAbilityTokenFunc = std::bind(&AppMgrServiceInner::KillProcessByAbilityToken, amsMgrServiceInner_, token); - amsHandler_->PostTask(killProcessByAbilityTokenFunc, TASK_KILL_PROCESS_BY_ABILITY_TOKEN); + amsHandler_->SubmitTask(killProcessByAbilityTokenFunc, TASK_KILL_PROCESS_BY_ABILITY_TOKEN); } void AmsMgrScheduler::KillProcessesByUserId(int32_t userId) @@ -182,7 +183,7 @@ void AmsMgrScheduler::KillProcessesByUserId(int32_t userId) std::function killProcessesByUserIdFunc = std::bind(&AppMgrServiceInner::KillProcessesByUserId, amsMgrServiceInner_, userId); - amsHandler_->PostTask(killProcessesByUserIdFunc, TASK_KILL_PROCESSES_BY_USERID); + amsHandler_->SubmitTask(killProcessesByUserIdFunc, TASK_KILL_PROCESSES_BY_USERID); } int32_t AmsMgrScheduler::KillProcessWithAccount(const std::string &bundleName, const int accountId) @@ -206,7 +207,7 @@ void AmsMgrScheduler::AbilityAttachTimeOut(const sptr &token) return; } auto task = [=]() { amsMgrServiceInner_->HandleAbilityAttachTimeOut(token); }; - amsHandler_->PostTask(task); + amsHandler_->SubmitTask(task); } void AmsMgrScheduler::PrepareTerminate(const sptr &token) @@ -221,7 +222,7 @@ void AmsMgrScheduler::PrepareTerminate(const sptr &token) return; } auto task = [=]() { amsMgrServiceInner_->PrepareTerminate(token); }; - amsHandler_->PostTask(task); + amsHandler_->SubmitTask(task); } int32_t AmsMgrScheduler::UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid) @@ -307,7 +308,7 @@ void AmsMgrScheduler::StartSpecifiedAbility(const AAFwk::Want &want, const AppEx return; } auto task = [=]() { amsMgrServiceInner_->StartSpecifiedAbility(want, abilityInfo); }; - amsHandler_->PostTask(task); + amsHandler_->SubmitTask(task); } void AmsMgrScheduler::RegisterStartSpecifiedAbilityResponse(const sptr &response) @@ -316,7 +317,7 @@ void AmsMgrScheduler::RegisterStartSpecifiedAbilityResponse(const sptrRegisterStartSpecifiedAbilityResponse(response); }; - amsHandler_->PostTask(task); + amsHandler_->SubmitTask(task); } int AmsMgrScheduler::GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) diff --git a/services/appmgr/src/app_death_recipient.cpp b/services/appmgr/src/app_death_recipient.cpp index c60309143b..0ef94ba740 100644 --- a/services/appmgr/src/app_death_recipient.cpp +++ b/services/appmgr/src/app_death_recipient.cpp @@ -42,10 +42,10 @@ void AppDeathRecipient::OnRemoteDied(const wptr &remote) } auto onRemoteDiedFunc = std::bind(&AppMgrServiceInner::OnRemoteDied, serviceInner, remote, isRenderProcess_); - handler->PostTask(onRemoteDiedFunc, TASK_ON_REMOTE_DIED); + handler->SubmitTask(onRemoteDiedFunc, TASK_ON_REMOTE_DIED); } -void AppDeathRecipient::SetEventHandler(const std::shared_ptr &handler) +void AppDeathRecipient::SetTaskHandler(const std::shared_ptr &handler) { handler_ = handler; } diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 88bf4bb31d..79b9485cf7 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -29,7 +29,6 @@ #include "app_mgr_constants.h" #include "hilog_wrapper.h" #include "perf_profile.h" -#include "xcollie/watchdog.h" #include "permission_constants.h" #include "permission_verification.h" @@ -100,8 +99,8 @@ void AppMgrService::OnStop() { HILOG_INFO("ready to stop service"); appMgrServiceState_.serviceRunningState = ServiceRunningState::STATE_NOT_START; - handler_.reset(); - runner_.reset(); + eventHandler_.reset(); + taskHandler_.reset(); if (appMgrServiceInner_) { appMgrServiceInner_->OnStop(); } @@ -124,22 +123,18 @@ AppMgrServiceState AppMgrService::QueryServiceState() ErrCode AppMgrService::Init() { HILOG_INFO("ready to init"); - // start main thread message loop. - runner_ = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME); - if (!runner_) { - HILOG_ERROR("init failed due to create runner error"); - return ERR_INVALID_OPERATION; - } if (!appMgrServiceInner_) { HILOG_ERROR("init failed without inner service"); return ERR_INVALID_OPERATION; } - handler_ = std::make_shared(runner_, appMgrServiceInner_); - appMgrServiceInner_->SetEventHandler(handler_); + taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("app_mgr_task_queue"); + eventHandler_ = std::make_shared(taskHandler_, appMgrServiceInner_); + appMgrServiceInner_->SetTaskHandler(taskHandler_); + appMgrServiceInner_->SetEventHandler(eventHandler_); std::function initAppMgrServiceInnerTask = std::bind(&AppMgrServiceInner::Init, appMgrServiceInner_); - handler_->PostTask(initAppMgrServiceInnerTask, TASK_INIT_APPMGRSERVICEINNER); + taskHandler_->SubmitTask(initAppMgrServiceInnerTask, TASK_INIT_APPMGRSERVICEINNER); ErrCode openErr = appMgrServiceInner_->OpenAppSpawnConnection(); if (FAILED(openErr)) { @@ -149,15 +144,11 @@ ErrCode AppMgrService::Init() HILOG_ERROR("failed to publish app mgr service to systemAbilityMgr"); return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED; } - amsMgrScheduler_ = new (std::nothrow) AmsMgrScheduler(appMgrServiceInner_, handler_); + amsMgrScheduler_ = new (std::nothrow) AmsMgrScheduler(appMgrServiceInner_, taskHandler_); if (!amsMgrScheduler_) { HILOG_ERROR("init failed without ams scheduler"); return ERR_INVALID_OPERATION; } - std::string threadName = Constants::APP_MGR_SERVICE_NAME + "(" + std::to_string(runner_->GetThreadId()) + ")"; - if (HiviewDFX::Watchdog::GetInstance().AddThread(threadName, handler_) != 0) { - HILOG_ERROR("HiviewDFX::Watchdog::GetInstance AddThread Fail"); - } HILOG_INFO("init success"); return ERR_OK; } @@ -181,7 +172,7 @@ void AppMgrService::AttachApplication(const sptr &app) AddAppDeathRecipient(pid); std::function attachApplicationFunc = std::bind(&AppMgrServiceInner::AttachApplication, appMgrServiceInner_, pid, iface_cast(app)); - handler_->PostTask(attachApplicationFunc, TASK_ATTACH_APPLICATION); + taskHandler_->SubmitTask(attachApplicationFunc, TASK_ATTACH_APPLICATION); } void AppMgrService::ApplicationForegrounded(const int32_t recordId) @@ -194,7 +185,7 @@ void AppMgrService::ApplicationForegrounded(const int32_t recordId) } std::function applicationForegroundedFunc = std::bind(&AppMgrServiceInner::ApplicationForegrounded, appMgrServiceInner_, recordId); - handler_->PostTask(applicationForegroundedFunc, TASK_APPLICATION_FOREGROUNDED); + taskHandler_->SubmitTask(applicationForegroundedFunc, TASK_APPLICATION_FOREGROUNDED); } void AppMgrService::ApplicationBackgrounded(const int32_t recordId) @@ -207,7 +198,7 @@ void AppMgrService::ApplicationBackgrounded(const int32_t recordId) } std::function applicationBackgroundedFunc = std::bind(&AppMgrServiceInner::ApplicationBackgrounded, appMgrServiceInner_, recordId); - handler_->PostTask(applicationBackgroundedFunc, TASK_APPLICATION_BACKGROUNDED); + taskHandler_->SubmitTask(applicationBackgroundedFunc, TASK_APPLICATION_BACKGROUNDED); } void AppMgrService::ApplicationTerminated(const int32_t recordId) @@ -220,7 +211,7 @@ void AppMgrService::ApplicationTerminated(const int32_t recordId) } std::function applicationTerminatedFunc = std::bind(&AppMgrServiceInner::ApplicationTerminated, appMgrServiceInner_, recordId); - handler_->PostTask(applicationTerminatedFunc, TASK_APPLICATION_TERMINATED); + taskHandler_->SubmitTask(applicationTerminatedFunc, TASK_APPLICATION_TERMINATED); } void AppMgrService::AbilityCleaned(const sptr &token) @@ -228,7 +219,7 @@ void AppMgrService::AbilityCleaned(const sptr &token) if (!IsReady()) { return; } - + auto callerUid = IPCSkeleton::GetCallingUid(); auto appRecord = appMgrServiceInner_->GetTerminatingAppRunningRecord(token); if (!appRecord || appRecord->GetUid() != callerUid) { @@ -238,20 +229,17 @@ void AppMgrService::AbilityCleaned(const sptr &token) std::function abilityCleanedFunc = std::bind(&AppMgrServiceInner::AbilityTerminated, appMgrServiceInner_, token); - handler_->PostTask(abilityCleanedFunc, TASK_ABILITY_CLEANED); + taskHandler_->SubmitTask(abilityCleanedFunc, TASK_ABILITY_CLEANED); } bool AppMgrService::IsReady() const { - if (!appMgrServiceInner_) { - HILOG_ERROR("appMgrServiceInner is null"); - return false; + if (appMgrServiceInner_ && taskHandler_ && eventHandler_) { + return true; } - if (!handler_) { - HILOG_ERROR("handler is null"); - return false; - } - return true; + + HILOG_WARN("Not ready"); + return false; } void AppMgrService::AddAppDeathRecipient(const pid_t pid) const @@ -260,11 +248,11 @@ void AppMgrService::AddAppDeathRecipient(const pid_t pid) const return; } sptr appDeathRecipient = new AppDeathRecipient(); - appDeathRecipient->SetEventHandler(handler_); + appDeathRecipient->SetTaskHandler(taskHandler_); appDeathRecipient->SetAppMgrServiceInner(appMgrServiceInner_); std::function addAppRecipientFunc = std::bind(&AppMgrServiceInner::AddAppDeathRecipient, appMgrServiceInner_, pid, appDeathRecipient); - handler_->PostTask(addAppRecipientFunc, TASK_ADD_APP_DEATH_RECIPIENT); + taskHandler_->SubmitTask(addAppRecipientFunc, TASK_ADD_APP_DEATH_RECIPIENT); } void AppMgrService::StartupResidentProcess(const std::vector &bundleInfos) @@ -281,7 +269,7 @@ void AppMgrService::StartupResidentProcess(const std::vector startupResidentProcess = std::bind(&AppMgrServiceInner::LoadResidentProcess, appMgrServiceInner_, bundleInfos); - handler_->PostTask(startupResidentProcess, TASK_STARTUP_RESIDENT_PROCESS); + taskHandler_->SubmitTask(startupResidentProcess, TASK_STARTUP_RESIDENT_PROCESS); } sptr AppMgrService::GetAmsMgr() @@ -308,7 +296,7 @@ int32_t AppMgrService::ClearUpApplicationData(const std::string &bundleName) pid_t pid = IPCSkeleton::GetCallingPid(); std::function clearUpApplicationDataFunc = std::bind(&AppMgrServiceInner::ClearUpApplicationData, appMgrServiceInner_, bundleName, uid, pid); - handler_->PostTask(clearUpApplicationDataFunc, TASK_CLEAR_UP_APPLICATION_DATA); + taskHandler_->SubmitTask(clearUpApplicationDataFunc, TASK_CLEAR_UP_APPLICATION_DATA); return ERR_OK; } @@ -386,7 +374,7 @@ void AppMgrService::AddAbilityStageDone(const int32_t recordId) } std::function addAbilityStageDone = std::bind(&AppMgrServiceInner::AddAbilityStageDone, appMgrServiceInner_, recordId); - handler_->PostTask(addAbilityStageDone, TASK_ADD_ABILITY_STAGE_DONE); + taskHandler_->SubmitTask(addAbilityStageDone, TASK_ADD_ABILITY_STAGE_DONE); } int32_t AppMgrService::RegisterApplicationStateObserver(const sptr &observer, @@ -433,7 +421,7 @@ int AppMgrService::StartUserTestProcess(const AAFwk::Want &want, const sptr startUserTestProcessFunc = std::bind(&AppMgrServiceInner::StartUserTestProcess, appMgrServiceInner_, want, observer, bundleInfo, userId); - handler_->PostTask(startUserTestProcessFunc, TASK_START_USER_TEST_PROCESS); + taskHandler_->SubmitTask(startUserTestProcessFunc, TASK_START_USER_TEST_PROCESS); return ERR_OK; } @@ -465,7 +453,7 @@ int AppMgrService::FinishUserTest(const std::string &msg, const int64_t &resultC pid_t callingPid = IPCSkeleton::GetCallingPid(); std::function finishUserTestProcessFunc = std::bind(&AppMgrServiceInner::FinishUserTest, appMgrServiceInner_, msg, resultCode, bundleName, callingPid); - handler_->PostTask(finishUserTestProcessFunc, TASK_FINISH_USER_TEST); + taskHandler_->SubmitTask(finishUserTestProcessFunc, TASK_FINISH_USER_TEST); return ERR_OK; } @@ -518,7 +506,7 @@ void AppMgrService::ScheduleAcceptWantDone(const int32_t recordId, const AAFwk:: return; } auto task = [=]() { appMgrServiceInner_->ScheduleAcceptWantDone(recordId, want, flag); }; - handler_->PostTask(task); + taskHandler_->SubmitTask(task); } int AppMgrService::GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) @@ -569,7 +557,7 @@ void AppMgrService::AttachRenderProcess(const sptr &scheduler) auto pid = IPCSkeleton::GetCallingPid(); auto fun = std::bind(&AppMgrServiceInner::AttachRenderProcess, appMgrServiceInner_, pid, iface_cast(scheduler)); - handler_->PostTask(fun, TASK_ATTACH_RENDER_PROCESS); + taskHandler_->SubmitTask(fun, TASK_ATTACH_RENDER_PROCESS); } int32_t AppMgrService::GetRenderProcessTerminationStatus(pid_t renderPid, int &status) @@ -632,7 +620,7 @@ int AppMgrService::BlockAppService() std::this_thread::sleep_for(APP_MS_BLOCK*1s); } }; - handler_->PostTask(task); + taskHandler_->SubmitTask(task); return ERR_OK; } #endif diff --git a/services/appmgr/src/app_mgr_service_event_handler.cpp b/services/appmgr/src/app_mgr_service_event_handler.cpp index e450276367..84e31c6afe 100644 --- a/services/appmgr/src/app_mgr_service_event_handler.cpp +++ b/services/appmgr/src/app_mgr_service_event_handler.cpp @@ -20,9 +20,9 @@ namespace OHOS { namespace AppExecFwk { -AMSEventHandler::AMSEventHandler( - const std::shared_ptr &runner, const std::weak_ptr &appMgr) - : EventHandler(runner), appMgr_(appMgr) +AMSEventHandler::AMSEventHandler(const std::shared_ptr &taskHandler, + const std::weak_ptr &appMgr) + : AAFwk::EventHandlerWrap(taskHandler), appMgr_(appMgr) { HILOG_INFO("instance created"); } @@ -32,13 +32,8 @@ AMSEventHandler::~AMSEventHandler() HILOG_INFO("instance destroyed"); } -void AMSEventHandler::ProcessEvent(const InnerEvent::Pointer &event) +void AMSEventHandler::ProcessEvent(const AAFwk::EventWrap &event) { - if (event == nullptr) { - HILOG_ERROR("AppEventHandler::ProcessEvent::parameter error"); - return; - } - auto appManager = appMgr_.lock(); if (!appManager) { HILOG_ERROR("app manager is nullptr"); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index a588fac2ac..6eed186d29 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -715,7 +716,7 @@ void AppMgrServiceInner::SendProcessExitEventTask(pid_t pid, time_t exitTime, in auto sendEventTask = [inner = shared_from_this(), pid, exitTime, count] () { inner->SendProcessExitEventTask(pid, exitTime, count); }; - eventHandler_->PostTask(sendEventTask, PROCESS_EXIT_EVENT_TASK, KILL_PROCESS_DELAYTIME_MICRO_SECONDS); + taskHandler_->SubmitTask(sendEventTask, PROCESS_EXIT_EVENT_TASK, KILL_PROCESS_DELAYTIME_MICRO_SECONDS); } void AppMgrServiceInner::SendProcessExitEvent(pid_t pid) @@ -1181,6 +1182,7 @@ std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord(con appRecord->SetProcessAndExtensionType(abilityInfo); bool isKeepAlive = bundleInfo.isKeepAlive && bundleInfo.singleton; appRecord->SetKeepAliveAppState(isKeepAlive, false); + appRecord->SetTaskHandler(taskHandler_); appRecord->SetEventHandler(eventHandler_); appRecord->AddModule(appInfo, abilityInfo, token, hapModuleInfo, want); if (want) { @@ -1371,7 +1373,7 @@ void AppMgrServiceInner::RegisterAppStateCallback(const sptr } HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); if (callback != nullptr) { - std::lock_guard lock(appStateCallbacksLock_); + std::lock_guard lock(appStateCallbacksLock_); appStateCallbacks_.push_back(callback); } } @@ -1579,7 +1581,7 @@ void AppMgrServiceInner::OnAppStateChanged( HILOG_DEBUG("OnAppStateChanged begin, bundleName is %{public}s, state:%{public}d", appRecord->GetBundleName().c_str(), static_cast(state)); { - std::lock_guard lock(appStateCallbacksLock_); + std::lock_guard lock(appStateCallbacksLock_); for (const auto &callback : appStateCallbacks_) { if (callback != nullptr) { callback->OnAppStateChanged(WrapAppProcessData(appRecord, state)); @@ -1663,7 +1665,7 @@ void AppMgrServiceInner::OnAbilityStateChanged( HILOG_ERROR("ability is null"); return; } - std::lock_guard lock(appStateCallbacksLock_); + std::lock_guard lock(appStateCallbacksLock_); for (const auto &callback : appStateCallbacks_) { if (callback != nullptr) { callback->OnAbilityRequestDone(ability->GetToken(), state); @@ -2025,12 +2027,12 @@ void AppMgrServiceInner::ClearAppRunningData(const std::shared_ptrRestartResidentProcess(appRecord); }; + if (!taskHandler_) { + HILOG_ERROR("taskHandler_ is nullptr"); + return; + } if (appRecord->CanRestartResidentProc()) { - if (!eventHandler_) { - HILOG_ERROR("eventHandler_ is nullptr"); - return; - } - eventHandler_->PostTask(restartProcess, "RestartResidentProcess"); + taskHandler_->SubmitTask(restartProcess, "RestartResidentProcess"); } else { auto findRestartResidentTask = [appRecord](const std::shared_ptr &appRunningRecord) { return (appRecord != nullptr && appRecord->GetBundleName() == appRunningRecord->GetBundleName()); @@ -2043,7 +2045,7 @@ void AppMgrServiceInner::ClearAppRunningData(const std::shared_ptrPostTask(restartProcess, "RestartResidentProcessDelayTask", RESTART_INTERVAL_TIME); + taskHandler_->SubmitTask(restartProcess, "RestartResidentProcessDelayTask", RESTART_INTERVAL_TIME); } } } @@ -2079,11 +2081,11 @@ void AppMgrServiceInner::AddAppDeathRecipient(const pid_t pid, const sptrGetInnerEventId()) { + switch (event.GetEventId()) { case AMSEventHandler::TERMINATE_ABILITY_TIMEOUT_MSG: - appRunningManager_->HandleTerminateTimeOut(event->GetParam()); + appRunningManager_->HandleTerminateTimeOut(event.GetParam()); break; case AMSEventHandler::TERMINATE_APPLICATION_TIMEOUT_MSG: - SendHiSysEvent(event->GetInnerEventId(), event->GetParam()); - HandleTerminateApplicationTimeOut(event->GetParam()); + SendHiSysEvent(event.GetEventId(), event.GetParam()); + HandleTerminateApplicationTimeOut(event.GetParam()); break; case AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG: case AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG: - SendHiSysEvent(event->GetInnerEventId(), event->GetParam()); - HandleAddAbilityStageTimeOut(event->GetParam()); + SendHiSysEvent(event.GetEventId(), event.GetParam()); + HandleAddAbilityStageTimeOut(event.GetParam()); break; case AMSEventHandler::START_SPECIFIED_ABILITY_TIMEOUT_MSG: - SendHiSysEvent(event->GetInnerEventId(), event->GetParam()); - HandleStartSpecifiedAbilityTimeOut(event->GetParam()); + SendHiSysEvent(event.GetEventId(), event.GetParam()); + HandleStartSpecifiedAbilityTimeOut(event.GetParam()); break; default: break; } } - -void AppMgrServiceInner::SetEventHandler(const std::shared_ptr &handler) -{ - eventHandler_ = handler; -} - void AppMgrServiceInner::HandleAbilityAttachTimeOut(const sptr &token) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); @@ -2177,11 +2173,11 @@ void AppMgrServiceInner::TerminateApplication(const std::shared_ptrPostTask(timeoutTask, "DelayKillProcess", AMSEventHandler::KILL_PROCESS_TIMEOUT); + taskHandler_->SubmitTask(timeoutTask, "DelayKillProcess", AMSEventHandler::KILL_PROCESS_TIMEOUT); } appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId()); RemoveAppFromRecentListById(appRecord->GetRecordId()); @@ -2323,6 +2319,7 @@ void AppMgrServiceInner::StartEmptyResidentProcess( appRecord->SetRestartResidentProcCount(restartCount); } + appRecord->SetTaskHandler(taskHandler_); appRecord->SetEventHandler(eventHandler_); appRecord->AddModules(appInfo, info.hapModuleInfos); HILOG_INFO("StartEmptyResidentProcess of pid : [%{public}d], ", appRecord->GetPriorityObject()->GetPid()); @@ -2588,6 +2585,7 @@ int AppMgrServiceInner::StartEmptyProcess(const AAFwk::Want &want, const sptrSetTaskHandler(taskHandler_); appRecord->SetEventHandler(eventHandler_); appRecord->AddModules(appInfo, info.hapModuleInfos); HILOG_INFO("StartEmptyProcess OK pid : [%{public}d]", appRecord->GetPriorityObject()->GetPid()); @@ -2635,7 +2633,7 @@ int AppMgrServiceInner::FinishUserTestLocked( return ERR_INVALID_VALUE; } - std::unique_lock lock(userTestLock_); + std::lock_guard lock(userTestLock_); auto userTestRecord = appRecord->GetUserTestInfo(); if (!userTestRecord) { HILOG_WARN("not start user test"); @@ -2695,6 +2693,7 @@ void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const Ap appRecord->SetCallerTokenId(wantPtr->GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, -1)); } appRecord->SetProcessAndExtensionType(abilityInfoPtr); + appRecord->SetTaskHandler(taskHandler_); appRecord->SetEventHandler(eventHandler_); appRecord->SendEventForSpecifiedAbility(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG, AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT); @@ -2803,7 +2802,7 @@ int32_t AppMgrServiceInner::UpdateConfiguration(const Configuration &config) return result; } // notify - std::lock_guard notifyLock(configurationObserverLock_); + std::lock_guard notifyLock(configurationObserverLock_); for (auto &observer : configurationObservers_) { if (observer != nullptr) { observer->OnConfigurationUpdated(config); @@ -2820,7 +2819,7 @@ int32_t AppMgrServiceInner::RegisterConfigurationObserver(const sptr registerLock(configurationObserverLock_); + std::lock_guard registerLock(configurationObserverLock_); auto it = std::find_if(configurationObservers_.begin(), configurationObservers_.end(), [&observer](const sptr &item) { return (item && item->AsObject() == observer->AsObject()); @@ -2841,7 +2840,7 @@ int32_t AppMgrServiceInner::UnregisterConfigurationObserver(const sptr unregisterLock(configurationObserverLock_); + std::lock_guard unregisterLock(configurationObserverLock_); auto it = std::find_if(configurationObservers_.begin(), configurationObservers_.end(), [&observer](const sptr &item) { return (item && item->AsObject() == observer->AsObject()); @@ -2892,8 +2891,8 @@ std::shared_ptr AppMgrServiceInner::GetConfiguration( void AppMgrServiceInner::KillApplicationByRecord(const std::shared_ptr &appRecord) { HILOG_DEBUG("Kill application by appRecord."); - if (!appRecord || !eventHandler_) { - HILOG_WARN("appRecord or eventHandler_ is nullptr."); + if (!appRecord || !taskHandler_) { + HILOG_WARN("appRecord or taskHandler_ is nullptr."); return; } @@ -2916,7 +2915,7 @@ void AppMgrServiceInner::KillApplicationByRecord(const std::shared_ptrPostTask(timeoutTask, "DelayKillProcess", AMSEventHandler::KILL_PROCESS_TIMEOUT); + taskHandler_->SubmitTask(timeoutTask, "DelayKillProcess", AMSEventHandler::KILL_PROCESS_TIMEOUT); } void AppMgrServiceInner::SendHiSysEvent(const int32_t innerEventId, const int64_t eventId) @@ -3278,7 +3277,7 @@ void AppMgrServiceInner::AttachRenderProcess(const pid_t pid, const sptr appDeathRecipient = new AppDeathRecipient(); - appDeathRecipient->SetEventHandler(eventHandler_); + appDeathRecipient->SetTaskHandler(taskHandler_); appDeathRecipient->SetAppMgrServiceInner(shared_from_this()); appDeathRecipient->SetIsRenderProcess(true); renderRecord->SetScheduler(scheduler); @@ -3293,7 +3292,7 @@ void AppMgrServiceInner::AttachRenderProcess(const pid_t pid, const sptr lock(renderUidSetLock_); + std::lock_guard lock(renderUidSetLock_); int32_t uid = lastRenderUid_ + 1; bool needSecondScan = true; if (uid > Constants::END_UID_FOR_RENDER_PROCESS) { @@ -3360,7 +3359,7 @@ int AppMgrServiceInner::StartRenderProcessImpl(const std::shared_ptrStartProcess(startMsg, pid); if (FAILED(errCode)) { HILOG_ERROR("failed to spawn new render process, errCode %{public}08x", errCode); - std::lock_guard lock(renderUidSetLock_); + std::lock_guard lock(renderUidSetLock_); renderUidSet_.erase(renderUid); return ERR_INVALID_VALUE; } @@ -3406,7 +3405,7 @@ void AppMgrServiceInner::OnRenderRemoteDied(const wptr &remote) auto renderRecord = appRunningManager_->OnRemoteRenderDied(remote); if (renderRecord) { { - std::lock_guard lock(renderUidSetLock_); + std::lock_guard lock(renderUidSetLock_); renderUidSet_.erase(renderRecord->GetUid()); } DelayedSingleton::GetInstance()->OnRenderProcessDied(renderRecord); @@ -3461,15 +3460,16 @@ void AppMgrServiceInner::InitFocusListener() return; } - focusListener_ = new WindowFocusChangedListener(shared_from_this(), eventHandler_); + focusListener_ = new WindowFocusChangedListener(shared_from_this(), taskHandler_); auto registerTask = [innerService = shared_from_this()]() { if (innerService) { HILOG_INFO("RegisterFocusListener task"); innerService->RegisterFocusListener(); } }; - if (eventHandler_) { - eventHandler_->PostTask(registerTask, "RegisterFocusListenerTask", REGISTER_FOCUS_DELAY); + if (taskHandler_) { + taskHandler_->SubmitTask(registerTask, "RegisterFocusListenerTask", REGISTER_FOCUS_DELAY); + HILOG_INFO("Submit RegisterFocusListenerTask"); } } @@ -3865,7 +3865,7 @@ void AppMgrServiceInner::KillRenderProcess(const std::shared_ptrGetPid()); { - std::lock_guard lock(renderUidSetLock_); + std::lock_guard lock(renderUidSetLock_); renderUidSet_.erase(renderRecord->GetUid()); } DelayedSingleton::GetInstance()->OnRenderProcessDied(renderRecord); diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 3a95673618..5b39214f24 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -64,7 +64,7 @@ std::shared_ptr AppRunningManager::CreateAppRunningRecord( appRecord->SetStageModelState(isStageBasedModel); appRecord->SetSignCode(signCode); appRecord->SetJointUserId(bundleInfo.jointUserId); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); appRunningRecordMap_.emplace(recordId, appRecord); return appRecord; } @@ -91,7 +91,7 @@ std::shared_ptr AppRunningManager::CheckAppRunningRecordIsExis }; // If it is not empty, look for whether it can come in the same process - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); if (jointUserId.empty()) { for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; @@ -119,7 +119,7 @@ std::shared_ptr AppRunningManager::CheckAppRunningRecordIsExis bool AppRunningManager::CheckAppRunningRecordIsExistByBundleName(const std::string &bundleName) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); if (appRunningRecordMap_.empty()) { return false; } @@ -134,7 +134,7 @@ bool AppRunningManager::CheckAppRunningRecordIsExistByBundleName(const std::stri std::shared_ptr AppRunningManager::GetAppRunningRecordByPid(const pid_t pid) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); return GetAppRunningRecordByPidInner(pid); } @@ -149,7 +149,7 @@ std::shared_ptr AppRunningManager::GetAppRunningRecordByPidInn std::shared_ptr AppRunningManager::GetAppRunningRecordByAbilityToken( const sptr &abilityToken) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); return GetAppRunningRecordByTokenInner(abilityToken); } @@ -167,7 +167,7 @@ std::shared_ptr AppRunningManager::GetAppRunningRecordByTokenI bool AppRunningManager::ProcessExitByBundleName(const std::string &bundleName, std::list &pids) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; // condition [!appRecord->IsKeepAliveApp()] Is to not kill the resident process. @@ -191,7 +191,7 @@ bool AppRunningManager::ProcessExitByBundleName(const std::string &bundleName, s bool AppRunningManager::GetPidsByUserId(int32_t userId, std::list &pids) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; if (appRecord) { @@ -212,7 +212,7 @@ bool AppRunningManager::GetPidsByUserId(int32_t userId, std::list &pids) int32_t AppRunningManager::ProcessUpdateApplicationInfoInstalled(const ApplicationInfo &appInfo) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); int32_t result = ERR_OK; for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; @@ -233,7 +233,7 @@ int32_t AppRunningManager::ProcessUpdateApplicationInfoInstalled(const Applicati bool AppRunningManager::ProcessExitByBundleNameAndUid( const std::string &bundleName, const int uid, std::list &pids) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; if (appRecord) { @@ -257,7 +257,7 @@ bool AppRunningManager::ProcessExitByBundleNameAndUid( bool AppRunningManager::ProcessExitByPid(pid_t pid) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; if (appRecord) { @@ -285,7 +285,7 @@ std::shared_ptr AppRunningManager::OnRemoteDied(const wptr guard(lock_); + std::lock_guard guard(lock_); const auto &iter = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&object](const auto &pair) { if (pair.second && pair.second->GetApplicationClient() != nullptr) { @@ -307,19 +307,19 @@ std::shared_ptr AppRunningManager::OnRemoteDied(const wptr> AppRunningManager::GetAppRunningRecordMap() { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); return appRunningRecordMap_; } void AppRunningManager::RemoveAppRunningRecordById(const int32_t recordId) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); appRunningRecordMap_.erase(recordId); } void AppRunningManager::ClearAppRunningRecordMap() { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); appRunningRecordMap_.clear(); } @@ -343,7 +343,7 @@ void AppRunningManager::HandleTerminateTimeOut(int64_t eventId) std::shared_ptr AppRunningManager::GetTerminatingAppRunningRecord( const sptr &abilityToken) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; if (appRecord && appRecord->GetAbilityByTerminateLists(abilityToken)) { @@ -356,7 +356,7 @@ std::shared_ptr AppRunningManager::GetTerminatingAppRunningRec std::shared_ptr AppRunningManager::GetAbilityRunningRecord(const int64_t eventId) { HILOG_INFO("Get ability running record by eventId."); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (auto &item : appRunningRecordMap_) { if (item.second) { auto abilityRecord = item.second->GetAbilityRunningRecord(eventId); @@ -371,7 +371,7 @@ std::shared_ptr AppRunningManager::GetAbilityRunningRecord std::shared_ptr AppRunningManager::GetAppRunningRecord(const int64_t eventId) { HILOG_INFO("Get app running record by eventId."); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); auto iter = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&eventId](const auto &pair) { return pair.second->GetEventId() == eventId; }); @@ -476,7 +476,7 @@ void AppRunningManager::TerminateAbility(const sptr &token, bool void AppRunningManager::GetRunningProcessInfoByToken( const sptr &token, AppExecFwk::RunningProcessInfo &info) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); auto appRecord = GetAppRunningRecordByTokenInner(token); AssignRunningProcessInfoByAppRecord(appRecord, info); @@ -484,7 +484,7 @@ void AppRunningManager::GetRunningProcessInfoByToken( void AppRunningManager::GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); auto appRecord = GetAppRunningRecordByPidInner(pid); AssignRunningProcessInfoByAppRecord(appRecord, info); @@ -521,7 +521,7 @@ void AppRunningManager::ClipStringContent(const std::regex &re, const std::strin void AppRunningManager::GetForegroundApplications(std::vector &list) { HILOG_INFO("%{public}s, begin.", __func__); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; if (!appRecord) { @@ -582,7 +582,7 @@ void AppRunningManager::HandleStartSpecifiedAbilityTimeOut(const int64_t eventId int32_t AppRunningManager::UpdateConfiguration(const Configuration &config) { HILOG_INFO("call %{public}s", __func__); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); HILOG_INFO("current app size %{public}zu", appRunningRecordMap_.size()); int32_t result = ERR_OK; for (const auto &item : appRunningRecordMap_) { @@ -597,7 +597,7 @@ int32_t AppRunningManager::UpdateConfiguration(const Configuration &config) int32_t AppRunningManager::NotifyMemoryLevel(int32_t level) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); HILOG_INFO("call %{public}s, current app size %{public}zu", __func__, appRunningRecordMap_.size()); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; @@ -611,7 +611,7 @@ int32_t AppRunningManager::DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::M { std::shared_ptr appRecord; { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); HILOG_INFO("call %{public}s, current app size %{public}zu", __func__, appRunningRecordMap_.size()); auto iter = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&pid](const auto &pair) { auto priorityObject = pair.second->GetPriorityObject(); @@ -633,7 +633,7 @@ int32_t AppRunningManager::DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::M std::shared_ptr AppRunningManager::GetAppRunningRecordByRenderPid(const pid_t pid) { - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); auto iter = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&pid](const auto &pair) { auto renderRecordMap = pair.second->GetRenderRecordMap(); if (renderRecordMap.empty()) { @@ -662,7 +662,7 @@ std::shared_ptr AppRunningManager::OnRemoteRenderDied(const wptr guard(lock_); + std::lock_guard guard(lock_); std::shared_ptr renderRecord; const auto &it = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), @@ -699,7 +699,7 @@ bool AppRunningManager::GetAppRunningStateByBundleName(const std::string &bundle { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; if (appRecord && appRecord->GetBundleName() == bundleName) { @@ -715,7 +715,7 @@ int32_t AppRunningManager::NotifyLoadRepairPatch(const std::string &bundleName, { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); int32_t result = ERR_OK; bool loadSucceed = false; sptr callbackByRecord = new (std::nothrow) QuickFixCallbackWithRecord(callback); @@ -741,7 +741,7 @@ int32_t AppRunningManager::NotifyHotReloadPage(const std::string &bundleName, co { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); int32_t result = ERR_OK; bool reloadPageSucceed = false; sptr callbackByRecord = new (std::nothrow) QuickFixCallbackWithRecord(callback); @@ -768,7 +768,7 @@ int32_t AppRunningManager::NotifyUnLoadRepairPatch(const std::string &bundleName { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); int32_t result = ERR_OK; bool unLoadSucceed = false; sptr callbackByRecord = new (std::nothrow) QuickFixCallbackWithRecord(callback); @@ -793,7 +793,7 @@ int32_t AppRunningManager::NotifyUnLoadRepairPatch(const std::string &bundleName bool AppRunningManager::IsApplicationFirstForeground(const AppRunningRecord &foregroundingRecord) { HILOG_DEBUG("function called."); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); if (foregroundingRecord.IsUIExtension()) { return false; } @@ -815,7 +815,7 @@ bool AppRunningManager::IsApplicationFirstForeground(const AppRunningRecord &for bool AppRunningManager::IsApplicationBackground(const std::string &bundleName) { HILOG_DEBUG("function called."); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; if (appRecord == nullptr) { @@ -837,7 +837,7 @@ bool AppRunningManager::IsApplicationBackground(const std::string &bundleName) bool AppRunningManager::IsApplicationFirstFocused(const AppRunningRecord &focusedRecord) { HILOG_DEBUG("check focus function called."); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; if (appRecord == nullptr || appRecord->GetBundleName() != focusedRecord.GetBundleName()) { @@ -853,7 +853,7 @@ bool AppRunningManager::IsApplicationFirstFocused(const AppRunningRecord &focuse bool AppRunningManager::IsApplicationUnfocused(const std::string &bundleName) { HILOG_DEBUG("check is application unfocused."); - std::lock_guard guard(lock_); + std::lock_guard guard(lock_); for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; if (appRecord && appRecord->GetBundleName() == bundleName && appRecord->GetFocusFlag()) { diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 242a45af5d..e2866da57e 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -315,7 +315,7 @@ void AppRunningRecord::SetRestartTimeMillis(const int64_t restartTimeMillis) const std::list> AppRunningRecord::GetAppInfoList() { std::list> appInfoList; - std::lock_guard appInfosLock(appInfosLock_); + std::lock_guard appInfosLock(appInfosLock_); for (const auto &item : appInfos_) { appInfoList.push_back(item.second); } @@ -356,7 +356,7 @@ void AppRunningRecord::RemoveModuleRecord(const std::shared_ptr hapModulesLock(hapModulesLock_); + std::lock_guard hapModulesLock(hapModulesLock_); for (auto &item : hapModules_) { auto iter = std::find_if(item.second.begin(), item.second.end(), @@ -365,7 +365,7 @@ void AppRunningRecord::RemoveModuleRecord(const std::shared_ptr appInfosLock(appInfosLock_); + std::lock_guard appInfosLock(appInfosLock_); appInfos_.erase(item.first); } hapModules_.erase(item.first); @@ -394,7 +394,7 @@ void AppRunningRecord::LaunchApplication(const Configuration &config) } AppLaunchData launchData; { - std::lock_guard appInfosLock(appInfosLock_); + std::lock_guard appInfosLock(appInfosLock_); auto moduleRecords = appInfos_.find(mainBundleName_); if (moduleRecords != appInfos_.end()) { launchData.SetApplicationInfo(*(moduleRecords->second)); @@ -452,7 +452,7 @@ void AppRunningRecord::AddAbilityStageBySpecifiedAbility(const std::string &bund HapModuleInfo hapModuleInfo; if (GetTheModuleInfoNeedToUpdated(bundleName, hapModuleInfo)) { - if (!eventHandler_->HasInnerEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG)) { + if (startProcessSpecifiedAbilityEventId_ == 0) { HILOG_INFO("%{public}s START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG is not exist.", __func__); SendEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG, AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT); @@ -475,12 +475,15 @@ void AppRunningRecord::AddAbilityStageDone() return; } - if (eventHandler_->HasInnerEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG)) { - eventHandler_->RemoveEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG); + if (startProcessSpecifiedAbilityEventId_ != 0) { + eventHandler_->RemoveEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG, + startProcessSpecifiedAbilityEventId_); + startProcessSpecifiedAbilityEventId_ = 0; } - - if (eventHandler_->HasInnerEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG)) { - eventHandler_->RemoveEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG); + if (addAbilityStageInfoEventId_ != 0) { + eventHandler_->RemoveEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG, + addAbilityStageInfoEventId_); + addAbilityStageInfoEventId_ = 0; } // Should proceed to the next notification @@ -620,7 +623,7 @@ void AppRunningRecord::AddModule(const std::shared_ptr &appInfo moduleRecord->SetApplicationClient(appLifeCycleDeal_); }; - std::lock_guard hapModulesLock(hapModulesLock_); + std::lock_guard hapModulesLock(hapModulesLock_); const auto &iter = hapModules_.find(appInfo->bundleName); if (iter != hapModules_.end()) { moduleRecord = GetModuleRecordByModuleName(appInfo->bundleName, hapModuleInfo.moduleName); @@ -635,7 +638,7 @@ void AppRunningRecord::AddModule(const std::shared_ptr &appInfo moduleList.push_back(moduleRecord); hapModules_.emplace(appInfo->bundleName, moduleList); { - std::lock_guard appInfosLock(appInfosLock_); + std::lock_guard appInfosLock(appInfosLock_); appInfos_.emplace(appInfo->bundleName, appInfo); } initModuleRecord(moduleRecord); @@ -983,7 +986,7 @@ void AppRunningRecord::AbilityTerminated(const sptr &token) std::list> AppRunningRecord::GetAllModuleRecord() const { std::list> moduleRecordList; - std::lock_guard hapModulesLock(hapModulesLock_); + std::lock_guard hapModulesLock(hapModulesLock_); for (const auto &item : hapModules_) { for (const auto &list : item.second) { moduleRecordList.push_back(list); @@ -1072,17 +1075,45 @@ void AppRunningRecord::SendEvent(uint32_t msg, int64_t timeOut) appEventId_++; eventId_ = appEventId_; + if (msg == AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG) { + startProcessSpecifiedAbilityEventId_ = eventId_; + } + HILOG_INFO("eventId %{public}d", static_cast(eventId_)); - eventHandler_->SendEvent(msg, appEventId_, timeOut); + eventHandler_->SendEvent(AAFwk::EventWrap(msg, eventId_), timeOut, false); + SendClearTask(msg, timeOut); +} + +void AppRunningRecord::SendClearTask(uint32_t msg, int64_t timeOut) +{ + if (!taskHandler_) { + HILOG_ERROR("taskHandler_ is nullptr"); + return; + } + int64_t* eventId = nullptr; + if (msg == AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG) { + eventId = &startProcessSpecifiedAbilityEventId_; + } else if (msg == AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG) { + eventId = &addAbilityStageInfoEventId_; + } else { + HILOG_INFO("Other msg: %{public}d", msg); + return; + } + taskHandler_->SubmitTask([wthis = weak_from_this(), eventId]() { + auto pthis = wthis.lock(); + if (pthis) { + *eventId = 0; + } + }, timeOut); } void AppRunningRecord::PostTask(std::string msg, int64_t timeOut, const Closure &task) { - if (!eventHandler_) { - HILOG_ERROR("eventHandler_ is nullptr"); + if (!taskHandler_) { + HILOG_ERROR("taskHandler_ is nullptr"); return; } - eventHandler_->PostTask(task, msg, timeOut); + taskHandler_->SubmitTask(task, msg, timeOut); } int64_t AppRunningRecord::GetEventId() const @@ -1090,6 +1121,11 @@ int64_t AppRunningRecord::GetEventId() const return eventId_; } +void AppRunningRecord::SetTaskHandler(std::shared_ptr taskHandler) +{ + taskHandler_ = taskHandler; +} + void AppRunningRecord::SetEventHandler(const std::shared_ptr &handler) { eventHandler_ = handler; @@ -1165,7 +1201,7 @@ void AppRunningRecord::SetStageModelState(bool isStageBasedModel) bool AppRunningRecord::GetTheModuleInfoNeedToUpdated(const std::string bundleName, HapModuleInfo &info) { bool result = false; - std::lock_guard hapModulesLock(hapModulesLock_); + std::lock_guard hapModulesLock(hapModulesLock_); auto moduleInfoVectorIter = hapModules_.find(bundleName); if (moduleInfoVectorIter == hapModules_.end() || moduleInfoVectorIter->second.empty()) { return result; @@ -1219,7 +1255,7 @@ bool AppRunningRecord::CanRestartResidentProc() void AppRunningRecord::GetBundleNames(std::vector &bundleNames) { - std::lock_guard appInfosLock(appInfosLock_); + std::lock_guard appInfosLock(appInfosLock_); for (auto &app : appInfos_) { bundleNames.emplace_back(app.first); } @@ -1321,7 +1357,7 @@ void AppRunningRecord::AddRenderRecord(const std::shared_ptr &reco HILOG_DEBUG("AddRenderRecord: record is null"); return; } - std::lock_guard renderRecordMapLock(renderRecordMapLock_); + std::lock_guard renderRecordMapLock(renderRecordMapLock_); renderRecordMap_.emplace(record->GetUid(), record); } @@ -1331,13 +1367,13 @@ void AppRunningRecord::RemoveRenderRecord(const std::shared_ptr &r HILOG_DEBUG("RemoveRenderRecord: record is null"); return; } - std::lock_guard renderRecordMapLock(renderRecordMapLock_); + std::lock_guard renderRecordMapLock(renderRecordMapLock_); renderRecordMap_.erase(record->GetUid()); } std::shared_ptr AppRunningRecord::GetRenderRecordByPid(const pid_t pid) { - std::lock_guard renderRecordMapLock(renderRecordMapLock_); + std::lock_guard renderRecordMapLock(renderRecordMapLock_); if (renderRecordMap_.empty()) { return nullptr; } @@ -1352,7 +1388,7 @@ std::shared_ptr AppRunningRecord::GetRenderRecordByPid(const pid_t std::map> AppRunningRecord::GetRenderRecordMap() { - std::lock_guard renderRecordMapLock(renderRecordMapLock_); + std::lock_guard renderRecordMapLock(renderRecordMapLock_); return renderRecordMap_; } diff --git a/services/appmgr/src/app_state_observer_manager.cpp b/services/appmgr/src/app_state_observer_manager.cpp index 4d88d77e65..5b35b9474a 100644 --- a/services/appmgr/src/app_state_observer_manager.cpp +++ b/services/appmgr/src/app_state_observer_manager.cpp @@ -36,7 +36,7 @@ AppStateObserverManager::~AppStateObserverManager() void AppStateObserverManager::Init() { if (!handler_) { - handler_ = std::make_shared(EventRunner::Create(THREAD_NAME)); + handler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("app_state_task_queue"); } } @@ -60,7 +60,7 @@ int32_t AppStateObserverManager::RegisterApplicationStateObserver( HILOG_ERROR("Observer exist."); return ERR_INVALID_VALUE; } - std::lock_guard lockRegister(observerLock_); + std::lock_guard lockRegister(observerLock_); appStateObserverMap_.emplace(observer, bundleNameList); HILOG_DEBUG("appStateObserverMap_ size:%{public}zu", appStateObserverMap_.size()); AddObserverDeathRecipient(observer); @@ -74,7 +74,7 @@ int32_t AppStateObserverManager::UnregisterApplicationStateObserver(const sptr lockUnregister(observerLock_); + std::lock_guard lockUnregister(observerLock_); if (observer == nullptr) { HILOG_ERROR("Observer nullptr"); return ERR_INVALID_VALUE; @@ -108,7 +108,7 @@ void AppStateObserverManager::OnAppStarted(const std::shared_ptrHandleOnAppStarted(appRecord); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void AppStateObserverManager::OnAppStopped(const std::shared_ptr &appRecord) @@ -127,7 +127,7 @@ void AppStateObserverManager::OnAppStopped(const std::shared_ptrHandleOnAppStopped(appRecord); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } @@ -148,7 +148,7 @@ void AppStateObserverManager::OnAppStateChanged( HILOG_DEBUG("OnAppStateChanged come."); self->HandleAppStateChanged(appRecord, state, needNotifyApp); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void AppStateObserverManager::OnProcessDied(const std::shared_ptr &appRecord) @@ -167,7 +167,7 @@ void AppStateObserverManager::OnProcessDied(const std::shared_ptrHandleOnAppProcessDied(appRecord); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void AppStateObserverManager::OnRenderProcessDied(const std::shared_ptr &renderRecord) @@ -186,7 +186,7 @@ void AppStateObserverManager::OnRenderProcessDied(const std::shared_ptrHandleOnRenderProcessDied(renderRecord); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void AppStateObserverManager::OnProcessStateChanged(const std::shared_ptr &appRecord) @@ -205,7 +205,7 @@ void AppStateObserverManager::OnProcessStateChanged(const std::shared_ptrHandleOnProcessStateChanged(appRecord); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void AppStateObserverManager::OnProcessCreated(const std::shared_ptr &appRecord) @@ -224,7 +224,7 @@ void AppStateObserverManager::OnProcessCreated(const std::shared_ptrHandleOnAppProcessCreated(appRecord); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void AppStateObserverManager::OnProcessReused(const std::shared_ptr &appRecord) @@ -243,7 +243,7 @@ void AppStateObserverManager::OnProcessReused(const std::shared_ptrHandleOnProcessResued(appRecord); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void AppStateObserverManager::OnRenderProcessCreated(const std::shared_ptr &renderRecord) @@ -262,7 +262,7 @@ void AppStateObserverManager::OnRenderProcessCreated(const std::shared_ptrHandleOnRenderProcessCreated(renderRecord); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void AppStateObserverManager::StateChangedNotifyObserver(const AbilityStateData abilityStateData, bool isAbility) @@ -281,7 +281,7 @@ void AppStateObserverManager::StateChangedNotifyObserver(const AbilityStateData HILOG_DEBUG("StateChangedNotifyObserver come."); self->HandleStateChangedNotifyObserver(abilityStateData, isAbility); }; - handler_->PostTask(task); + handler_->SubmitTask(task); } void AppStateObserverManager::HandleOnAppStarted(const std::shared_ptr &appRecord) @@ -294,7 +294,7 @@ void AppStateObserverManager::HandleOnAppStarted(const std::shared_ptr lockNotify(observerLock_); + std::lock_guard lockNotify(observerLock_); for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) { std::vector::iterator iter = std::find(it->second.begin(), it->second.end(), data.bundleName); @@ -314,7 +314,7 @@ void AppStateObserverManager::HandleOnAppStopped(const std::shared_ptr lockNotify(observerLock_); + std::lock_guard lockNotify(observerLock_); for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) { std::vector::iterator iter = std::find(it->second.begin(), it->second.end(), data.bundleName); @@ -336,7 +336,7 @@ void AppStateObserverManager::HandleAppStateChanged(const std::shared_ptr lockNotify(observerLock_); + std::lock_guard lockNotify(observerLock_); for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) { std::vector::iterator iter = std::find(it->second.begin(), it->second.end(), data.bundleName); @@ -354,7 +354,7 @@ void AppStateObserverManager::HandleAppStateChanged(const std::shared_ptr lockNotify(observerLock_); + std::lock_guard lockNotify(observerLock_); for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) { std::vector::iterator iter = std::find(it->second.begin(), it->second.end(), data.bundleName); @@ -367,7 +367,7 @@ void AppStateObserverManager::HandleAppStateChanged(const std::shared_ptr lockNotify(observerLock_); + std::lock_guard lockNotify(observerLock_); HILOG_DEBUG("Handle state change, module:%{public}s, bundle:%{public}s, ability:%{public}s, state:%{public}d," "pid:%{public}d ,uid:%{public}d, abilityType:%{public}d, isAbility:%{public}d", abilityStateData.moduleName.c_str(), abilityStateData.bundleName.c_str(), @@ -410,7 +410,7 @@ void AppStateObserverManager::HandleOnProcessResued(const std::shared_ptr lockNotify(observerLock_); + std::lock_guard lockNotify(observerLock_); for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) { std::vector::iterator iter = std::find(it->second.begin(), it->second.end(), data.bundleName); @@ -435,7 +435,7 @@ void AppStateObserverManager::HandleOnRenderProcessCreated(const std::shared_ptr void AppStateObserverManager::HandleOnProcessCreated(const ProcessData &data) { - std::lock_guard lockNotify(observerLock_); + std::lock_guard lockNotify(observerLock_); for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) { std::vector::iterator iter = std::find(it->second.begin(), it->second.end(), data.bundleName); @@ -454,7 +454,7 @@ void AppStateObserverManager::HandleOnProcessStateChanged(const std::shared_ptr< ProcessData data = WrapProcessData(appRecord); HILOG_DEBUG("bundle:%{public}s pid:%{public}d uid:%{public}d state:%{public}d isContinuousTask:%{public}d", data.bundleName.c_str(), data.pid, data.uid, data.state, data.isContinuousTask); - std::lock_guard lockNotify(observerLock_); + std::lock_guard lockNotify(observerLock_); for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) { std::vector::iterator iter = std::find(it->second.begin(), it->second.end(), data.bundleName); @@ -490,7 +490,7 @@ void AppStateObserverManager::HandleOnRenderProcessDied(const std::shared_ptr lockNotify(observerLock_); + std::lock_guard lockNotify(observerLock_); for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) { std::vector::iterator iter = std::find(it->second.begin(), it->second.end(), data.bundleName); @@ -536,7 +536,7 @@ bool AppStateObserverManager::ObserverExist(const sptr lockRegister(observerLock_); + std::lock_guard lockRegister(observerLock_); for (auto it = appStateObserverMap_.begin(); it != appStateObserverMap_.end(); ++it) { if (it->first->AsObject() == observer->AsObject()) { return true; diff --git a/services/appmgr/src/module_running_record.cpp b/services/appmgr/src/module_running_record.cpp index 26dd708e10..08c3f15919 100644 --- a/services/appmgr/src/module_running_record.cpp +++ b/services/appmgr/src/module_running_record.cpp @@ -57,7 +57,7 @@ std::shared_ptr ModuleRunningRecord::GetAbilityRunningReco HILOG_ERROR("token is null"); return nullptr; } - std::lock_guard lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); const auto &iter = abilities_.find(token); if (iter != abilities_.end()) { return iter->second; @@ -85,7 +85,7 @@ std::shared_ptr ModuleRunningRecord::AddAbility(const sptr if (want) { abilityRecord->SetOwnerUserId(want->GetIntParam(ABILITY_OWNER_USERID, -1)); } - std::lock_guard lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); abilities_.emplace(token, abilityRecord); return abilityRecord; } @@ -96,14 +96,14 @@ bool ModuleRunningRecord::IsLastAbilityRecord(const sptr &token) HILOG_ERROR("token is nullptr"); return false; } - std::lock_guard lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); return ((abilities_.size() == 1) && (abilities_.find(token) != abilities_.end())); } int32_t ModuleRunningRecord::GetPageAbilitySize() { int pageAbilitySize = 0; - std::lock_guard lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); for (auto it : abilities_) { std::shared_ptr abilityRunningRecord = it.second; std::shared_ptr abilityInfo = abilityRunningRecord->GetAbilityInfo(); @@ -118,7 +118,7 @@ int32_t ModuleRunningRecord::GetPageAbilitySize() const std::map, std::shared_ptr> ModuleRunningRecord::GetAbilities() const { - std::lock_guard lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); return abilities_; } @@ -129,7 +129,7 @@ std::shared_ptr ModuleRunningRecord::GetAbilityByTerminate HILOG_ERROR("GetAbilityByTerminateLists error, token is null"); return nullptr; } - std::lock_guard lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); const auto &iter = terminateAbilities_.find(token); if (iter != terminateAbilities_.end()) { return iter->second; @@ -140,7 +140,7 @@ std::shared_ptr ModuleRunningRecord::GetAbilityByTerminate std::shared_ptr ModuleRunningRecord::GetAbilityRunningRecord(const int64_t eventId) const { HILOG_INFO("Get ability running record by eventId."); - std::lock_guard lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); const auto &iter = std::find_if(abilities_.begin(), abilities_.end(), [eventId](const auto &pair) { return pair.second->GetEventId() == eventId; }); @@ -182,7 +182,7 @@ void ModuleRunningRecord::LaunchAbility(const std::shared_ptr lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); const auto &iter = abilities_.find(ability->GetToken()); if (iter != abilities_.end() && appLifeCycleDeal_->GetApplicationClient()) { HILOG_INFO("Schedule launch ability, name is %{public}s.", ability->GetName().c_str()); @@ -196,7 +196,7 @@ void ModuleRunningRecord::LaunchAbility(const std::shared_ptr lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); if (abilities_.empty()) { HILOG_ERROR("abilities_ is empty"); return; @@ -225,7 +225,7 @@ void ModuleRunningRecord::TerminateAbility(const std::shared_ptr lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); terminateAbilities_.emplace(token, abilityRecord); abilities_.erase(token); } @@ -266,7 +266,7 @@ void ModuleRunningRecord::SendEvent( AppRunningRecord::appEventId_++; abilityRecord->SetEventId(AppRunningRecord::appEventId_); - eventHandler_->SendEvent(msg, AppRunningRecord::appEventId_, timeOut); + eventHandler_->SendEvent(AAFwk::EventWrap(msg, AppRunningRecord::appEventId_), timeOut); } void ModuleRunningRecord::AbilityTerminated(const sptr &token) @@ -278,7 +278,7 @@ void ModuleRunningRecord::AbilityTerminated(const sptr &token) } if (RemoveTerminateAbilityTimeoutTask(token)) { - std::lock_guard lock(abilitiesMutex_); + std::lock_guard lock(abilitiesMutex_); terminateAbilities_.erase(token); } } diff --git a/services/appmgr/src/window_focus_changed_listener.cpp b/services/appmgr/src/window_focus_changed_listener.cpp index fc27e5447b..7b4445848e 100644 --- a/services/appmgr/src/window_focus_changed_listener.cpp +++ b/services/appmgr/src/window_focus_changed_listener.cpp @@ -23,7 +23,7 @@ namespace AppExecFwk { using namespace OHOS::Rosen; WindowFocusChangedListener::WindowFocusChangedListener(const std::shared_ptr &owner, - const std::shared_ptr& handler) : owner_(owner), eventHandler_(handler) {} + const std::shared_ptr& handler) : owner_(owner), taskHandler_(handler) {} WindowFocusChangedListener::~WindowFocusChangedListener() {} @@ -34,7 +34,7 @@ void WindowFocusChangedListener::OnFocused(const sptr &focusCha return; } - if (eventHandler_) { + if (taskHandler_) { auto task = [inner = owner_, focusChangeInfo] { auto owner = inner.lock(); if (!owner) { @@ -43,7 +43,7 @@ void WindowFocusChangedListener::OnFocused(const sptr &focusCha } owner->HandleFocused(focusChangeInfo); }; - eventHandler_->PostTask(task); + taskHandler_->SubmitTask(task); } } @@ -54,7 +54,7 @@ void WindowFocusChangedListener::OnUnfocused(const sptr &focusC return; } - if (eventHandler_) { + if (taskHandler_) { auto task = [inner = owner_, focusChangeInfo] { auto owner = inner.lock(); if (!owner) { @@ -63,7 +63,7 @@ void WindowFocusChangedListener::OnUnfocused(const sptr &focusC } owner->HandleUnfocused(focusChangeInfo); }; - eventHandler_->PostTask(task); + taskHandler_->SubmitTask(task); } } } // namespace AppExecFwk diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 4397ba83ec..027d3b8ca1 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -20,6 +20,7 @@ group("ams_common_target") { deps = [ ":event_report", ":perm_verification", + ":task_handler_wrap", ] } @@ -83,3 +84,23 @@ ohos_shared_library("event_report") { subsystem_name = "ability" part_name = "ability_runtime" } + +ohos_shared_library("task_handler_wrap") { + public_configs = [ ":common_config" ] + include_dirs = [ "include" ] + + sources = [ + "src/event_handler_wrap.cpp", + "src/ffrt_task_handler_wrap.cpp", + "src/queue_task_handler_wrap.cpp", + "src/task_handler_wrap.cpp", + ] + + external_deps = [ + "ffrt:libffrt", + "hilog:libhilog", + ] + + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/services/common/include/event_handler_wrap.h b/services/common/include/event_handler_wrap.h new file mode 100644 index 0000000000..2b1f0e629d --- /dev/null +++ b/services/common/include/event_handler_wrap.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_EVENT_HANDLER_WRAP_H +#define OHOS_ABILITY_RUNTIME_EVENT_HANDLER_WRAP_H + +#include +#include +#include +#include + +#include "task_handler_wrap.h" + +namespace OHOS { +namespace AAFwk { +class EventDataBase { +public: + virtual ~EventDataBase() = default; +}; +class EventWrap { +public: + EventWrap(uint32_t eventId) : EventWrap(eventId, 0) {} + EventWrap(uint32_t eventId, int64_t param) : eventId_(eventId), param_(param) + { + eventData_ = std::make_shared(); + } + EventWrap(uint32_t eventId, std::shared_ptr data) + : eventId_(eventId), param_(0), eventData_(data) + { + if (!eventData_) { + eventData_ = std::make_shared(); + } + } + uint32_t GetEventId() const + { + return eventId_; + } + int64_t GetParam() const + { + return param_; + } + const std::shared_ptr& GetEventData() const + { + return eventData_; + } + const TaskHandle& GetEventTask() const + { + return eventTask_; + } + void SetEventTask(const TaskHandle &eventTask) + { + eventTask_ = eventTask; + } + std::string GetEventString() + { + return std::to_string(eventId_) + "_" + std::to_string(param_); + } + bool IsSame(const EventWrap &other) const + { + return eventData_ == other.eventData_; + } +private: + uint32_t eventId_; + int64_t param_; + std::shared_ptr eventData_; + TaskHandle eventTask_; +}; + +class EventHandlerWrap : public std::enable_shared_from_this { +public: + EventHandlerWrap(); + EventHandlerWrap(std::shared_ptr taskHandler); + EventHandlerWrap(EventHandlerWrap &) = delete; + void operator=(EventHandlerWrap &) = delete; + virtual ~EventHandlerWrap(); + virtual void ProcessEvent(const EventWrap &event); + bool SendEvent(uint32_t eventId); + bool SendEvent(uint32_t eventId, int64_t delayMillis); + bool SendEvent(EventWrap event); + bool SendEvent(EventWrap event, int64_t delayMillis, bool forceInsert = true); + bool RemoveEvent(uint32_t eventId, int64_t param = 0); + bool RemoveEvent(EventWrap event, bool force = true); + + void SetEventCallback(std::function eventCallback) + { + eventCallback_ = eventCallback; + } +protected: + std::shared_ptr taskHandler_; + std::function eventCallback_; + + std::unique_ptr eventMutex_; + std::unordered_map eventMap_; +}; +} // namespace AAFWK +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_EVENT_HANDLER_WRAP_H \ No newline at end of file diff --git a/services/common/include/task_handler_wrap.h b/services/common/include/task_handler_wrap.h new file mode 100644 index 0000000000..f0f39ae942 --- /dev/null +++ b/services/common/include/task_handler_wrap.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_TASK_HANDLER_WRAP_H +#define OHOS_ABILITY_RUNTIME_TASK_HANDLER_WRAP_H + +#include +#include +#include +#include + +#include "task_utils_wrap.h" + +namespace ffrt { +class mutex; +}; + +namespace OHOS { +namespace AAFwk { +class TaskHandlerWrap; +class InnerTaskHandle; +class TaskHandle { +friend class TaskHandlerWrap; +public: + TaskHandle() = default; + TaskHandle(std::shared_ptr handler, std::shared_ptr InnerTaskHandle, + TaskStatus status = TaskStatus::PENDING) : handler_(handler), innerTaskHandle_(InnerTaskHandle) + { + status_ = std::make_shared(status); + } + bool Cancel() const; + void Sync() const; + bool IsSame(const TaskHandle &other) const + { + return innerTaskHandle_ == other.innerTaskHandle_; + } + explicit operator bool() const + { + return status_ && innerTaskHandle_; + } +private: + std::weak_ptr handler_; + std::shared_ptr innerTaskHandle_; + std::shared_ptr status_; +}; + +class TaskHandlerWrap : public std::enable_shared_from_this { +friend class TaskHandle; +public: + static std::shared_ptr CreateQueueHandler(const std::string &queueName, + TaskQoS queueQos = TaskQoS::DEFAULT); + static std::shared_ptr GetFfrtHandler(); + + TaskHandlerWrap(TaskHandlerWrap &) = delete; + void operator=(TaskHandlerWrap &) = delete; + virtual ~TaskHandlerWrap(); + /** + * Submit task to be scheduled and executed + * @return TaskHandle, could be used later + */ + TaskHandle SubmitTask(const std::function &task); + TaskHandle SubmitTask(const std::function &task, const std::string &name); + TaskHandle SubmitTask(const std::function &task, int64_t delayMillis); + TaskHandle SubmitTask(const std::function &task, TaskQoS taskQos); + TaskHandle SubmitTask(const std::function &task, const std::string &name, + int64_t delayMillis, bool forceSubmit = true); + TaskHandle SubmitTask(const std::function &task, const TaskAttribute &taskAttr); + // Task can't be canceled by name if submited with this mothed + TaskHandle SubmitTaskJust(const std::function &task, const std::string &name, + int64_t delayMillis); + // This is only used for compatibility and could be be wrong if multi tasks with same name submited. + // TaskHandle::Cancel is prefered. + bool CancelTask(const std::string &name); +protected: + TaskHandlerWrap(); + virtual std::shared_ptr SubmitTaskInner(std::function &&task, + const TaskAttribute &taskAttr) = 0; + virtual bool CancelTaskInner(const std::shared_ptr &taskHandle) = 0; + virtual void WaitTaskInner(const std::shared_ptr &taskHandle) = 0; + bool RemoveTask(const std::string &name, const TaskHandle &taskHandle); +protected: + // this is used only for compatibility + std::unordered_map tasks_; + std::unique_ptr tasksMutex_; +}; +} // namespace AAFWK +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_TASK_HANDLER_WRAP_H \ No newline at end of file diff --git a/services/common/include/task_utils_wrap.h b/services/common/include/task_utils_wrap.h new file mode 100644 index 0000000000..477e1558ab --- /dev/null +++ b/services/common/include/task_utils_wrap.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_TASK_UTILS_WRAP_H +#define OHOS_ABILITY_RUNTIME_TASK_UTILS_WRAP_H + +#include +namespace OHOS { +namespace AAFwk { +enum class TaskStatus { + PENDING, + EXECUTING, + FINISHED, + CANCELED +}; +enum class TaskQoS { + INHERENT = 0, + BACKGROUND, + UTILITY, + DEFAULT, + DEFINED_IVE, + USER_INITIATED, + DEADLINE_REQUEST, + USER_INTERACTIVE +}; +struct TaskAttribute { + std::string taskName_; + int64_t delayMillis_ = 0; + TaskQoS taskQos_ = TaskQoS::DEFAULT; + + bool IsDefault() const + { + return delayMillis_ <= 0 && taskName_.empty() && taskQos_ == TaskQoS::DEFAULT; + } +}; +} // namespace AAFwk +} // namespace OHOS + +#endif // OHOS_ABILITY_RUNTIME_TASK_UTILS_WRAP_H \ No newline at end of file diff --git a/services/common/src/event_handler_wrap.cpp b/services/common/src/event_handler_wrap.cpp new file mode 100644 index 0000000000..4567553016 --- /dev/null +++ b/services/common/src/event_handler_wrap.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023 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 "event_handler_wrap.h" + +#include +#include "cpp/mutex.h" + +namespace OHOS { +namespace AAFwk { +EventHandlerWrap::EventHandlerWrap() : taskHandler_(TaskHandlerWrap::GetFfrtHandler()) +{ + eventMutex_ = std::make_unique(); +} + +EventHandlerWrap::EventHandlerWrap(std::shared_ptr taskHandler) + : taskHandler_(taskHandler) +{ + eventMutex_ = std::make_unique(); +} + +EventHandlerWrap::~EventHandlerWrap() = default; + +void EventHandlerWrap::ProcessEvent(const EventWrap &event) +{ + if (eventCallback_) { + eventCallback_(event); + } +} +bool EventHandlerWrap::SendEvent(uint32_t eventId) +{ + return SendEvent(EventWrap(eventId, 0)); +} +bool EventHandlerWrap::SendEvent(uint32_t eventId, int64_t delayMillis) +{ + return SendEvent(EventWrap(eventId, 0), delayMillis); +} +bool EventHandlerWrap::SendEvent(EventWrap event) +{ + return SendEvent(event, 0); +} +bool EventHandlerWrap::SendEvent(EventWrap event, int64_t delayMillis, bool forceInsert) +{ + if (!taskHandler_) { + return false; + } + auto eventStr = event.GetEventString(); + std::lock_guard guard(*eventMutex_); + auto it = eventMap_.find(eventStr); + if (it != eventMap_.end() && !forceInsert) { + return false; + } + + event.SetEventTask(taskHandler_->SubmitTask([wthis = weak_from_this(), event]() { + auto pthis = wthis.lock(); + if (pthis) { + pthis->ProcessEvent(event); + pthis->RemoveEvent(event, false); + } + }, delayMillis)); + + if (it != eventMap_.end()) { + it->second = event; + } else { + eventMap_.emplace(eventStr, event); + } + + return true; +} + +bool EventHandlerWrap::RemoveEvent(uint32_t eventId, int64_t param) +{ + return RemoveEvent(EventWrap(eventId, param)); +} + +bool EventHandlerWrap::RemoveEvent(EventWrap event, bool force) +{ + std::lock_guard guard(*eventMutex_); + auto it = eventMap_.find(event.GetEventString()); + if (it == eventMap_.end()) { + return false; + } + if (force || it->second.IsSame(event)) { + it->second.GetEventTask().Cancel(); + eventMap_.erase(it); + return true; + } + return false; +} +} // namespace AAFWK +} // namespace OHOS \ No newline at end of file diff --git a/services/common/src/ffrt_task_handler_wrap.cpp b/services/common/src/ffrt_task_handler_wrap.cpp new file mode 100644 index 0000000000..a19eb47ce2 --- /dev/null +++ b/services/common/src/ffrt_task_handler_wrap.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023 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 "ffrt_task_handler_wrap.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { +namespace { +class FfrtTaskHandle : public InnerTaskHandle { +public: + FfrtTaskHandle(ffrt::task_handle &&taskHandle, const std::shared_ptr &outDep) + : InnerTaskHandle(std::move(taskHandle)), outDep_(outDep) + {} + ~FfrtTaskHandle() override = default; + const std::shared_ptr &GetOutDep() const + { + return outDep_; + } +private: + std::shared_ptr outDep_; +}; +} +std::shared_ptr FfrtTaskHandlerWrap::SubmitTaskInner(std::function &&task, + const TaskAttribute &taskAttr) +{ + HILOG_INFO("SubmitTaskInner ffrt task begin"); + auto outDep = std::make_shared(); + if (taskAttr.IsDefault()) { + return std::make_shared(ffrt::submit_h(std::move(task)), outDep); + } else { + ffrt::task_attr ffrtTaskAttr; + BuildFfrtTaskAttr(taskAttr, ffrtTaskAttr); + return std::make_shared(ffrt::submit_h(std::move(task), + {}, {outDep.get()}, ffrtTaskAttr), outDep); + } +} +bool FfrtTaskHandlerWrap::CancelTaskInner(const std::shared_ptr &taskHandle) +{ + if (!taskHandle) { + return false; + } + return ffrt::skip(taskHandle->GetFfrtHandle()) == 0; +} +void FfrtTaskHandlerWrap::WaitTaskInner(const std::shared_ptr &taskHandle) +{ + if (!taskHandle) { + return; + } + auto ffrtTaskHandle = static_cast(taskHandle.get()); + ffrt::wait({ffrtTaskHandle->GetOutDep().get()}); +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/common/src/ffrt_task_handler_wrap.h b/services/common/src/ffrt_task_handler_wrap.h new file mode 100644 index 0000000000..e5bc4e7880 --- /dev/null +++ b/services/common/src/ffrt_task_handler_wrap.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_FFRT_TASK_HANDLER_WRAP_H +#define OHOS_ABILITY_RUNTIME_FFRT_TASK_HANDLER_WRAP_H + +#include "task_handler_wrap.h" +#include "ffrt_task_utils_wrap.h" + +namespace OHOS { +namespace AAFwk { +class FfrtTaskHandlerWrap : public TaskHandlerWrap { +public: + virtual ~FfrtTaskHandlerWrap() = default; + +protected: + std::shared_ptr SubmitTaskInner(std::function &&task, + const TaskAttribute &taskAttr) override; + bool CancelTaskInner(const std::shared_ptr &taskHandle) override; + void WaitTaskInner(const std::shared_ptr &taskHandle) override; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_FFRT_TASK_HANDLER_WRAP_H \ No newline at end of file diff --git a/services/common/src/ffrt_task_utils_wrap.h b/services/common/src/ffrt_task_utils_wrap.h new file mode 100644 index 0000000000..9028817fca --- /dev/null +++ b/services/common/src/ffrt_task_utils_wrap.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_FFRT_TASK_UTILS_WRAP_H +#define OHOS_ABILITY_RUNTIME_FFRT_TASK_UTILS_WRAP_H + +#include +#include "cpp/task.h" +#include "task_utils_wrap.h" + +namespace OHOS { +namespace AAFwk { +class InnerTaskHandle { +public: + explicit InnerTaskHandle(ffrt::task_handle &&taskHandle) + : taskHandle_(std::move(taskHandle)) {} + InnerTaskHandle(InnerTaskHandle &) = delete; + void operator=(InnerTaskHandle &) = delete; + virtual ~InnerTaskHandle() = default; + ffrt::task_handle &GetFfrtHandle() + { + return taskHandle_; + } +private: + ffrt::task_handle taskHandle_; +}; + +void BuildFfrtTaskAttr(const TaskAttribute &taskAttr, ffrt::task_attr &result); +ffrt::qos Convert2FfrtQos(TaskQoS taskqos); +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_FFRT_TASK_UTILS_WRAP_H \ No newline at end of file diff --git a/services/common/src/queue_task_handler_wrap.cpp b/services/common/src/queue_task_handler_wrap.cpp new file mode 100644 index 0000000000..8f2ec34d4e --- /dev/null +++ b/services/common/src/queue_task_handler_wrap.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 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 "queue_task_handler_wrap.h" + +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { +QueueTaskHandlerWrap::QueueTaskHandlerWrap(const std::string &queueName, TaskQoS queueQos) + : taskQueue_(queueName.c_str(), ffrt::queue_attr().qos(Convert2FfrtQos(queueQos))) +{} +std::shared_ptr QueueTaskHandlerWrap::SubmitTaskInner(std::function &&task, + const TaskAttribute &taskAttr) +{ + HILOG_INFO("SubmitTaskInner queue task begin"); + if (taskAttr.IsDefault()) { + return std::make_shared(taskQueue_.submit_h(std::move(task))); + } else { + ffrt::task_attr ffrtTaskAttr; + BuildFfrtTaskAttr(taskAttr, ffrtTaskAttr); + return std::make_shared(taskQueue_.submit_h(std::move(task), + ffrtTaskAttr)); + } +} +bool QueueTaskHandlerWrap::CancelTaskInner(const std::shared_ptr &taskHandle) +{ + if (!taskHandle) { + return false; + } + return taskQueue_.cancel(taskHandle->GetFfrtHandle()) == 0; +} +void QueueTaskHandlerWrap::WaitTaskInner(const std::shared_ptr &taskHandle) +{ + if (!taskHandle) { + return; + } + taskQueue_.wait(taskHandle->GetFfrtHandle()); +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/common/src/queue_task_handler_wrap.h b/services/common/src/queue_task_handler_wrap.h new file mode 100644 index 0000000000..8752559070 --- /dev/null +++ b/services/common/src/queue_task_handler_wrap.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_QUEUE_TASK_HANDLER_WRAP_H +#define OHOS_ABILITY_RUNTIME_QUEUE_TASK_HANDLER_WRAP_H + +#include "cpp/queue.h" +#include "ffrt_task_utils_wrap.h" +#include "task_handler_wrap.h" + +namespace OHOS { +namespace AAFwk { +class QueueTaskHandlerWrap : public TaskHandlerWrap { +public: + QueueTaskHandlerWrap(const std::string &queueName, TaskQoS queueQos); + virtual ~QueueTaskHandlerWrap() = default; +protected: + std::shared_ptr SubmitTaskInner(std::function &&task, + const TaskAttribute &taskAttr) override; + bool CancelTaskInner(const std::shared_ptr &taskHandle) override; + void WaitTaskInner(const std::shared_ptr &taskHandle) override; +private: + ffrt::queue taskQueue_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_QUEUE_TASK_HANDLER_WRAP_H \ No newline at end of file diff --git a/services/common/src/task_handler_wrap.cpp b/services/common/src/task_handler_wrap.cpp new file mode 100644 index 0000000000..7f05eed698 --- /dev/null +++ b/services/common/src/task_handler_wrap.cpp @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2023 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 "task_handler_wrap.h" + +#include +#include "cpp/mutex.h" +#include "hilog_wrapper.h" +#include "ffrt_task_utils_wrap.h" +#include "queue_task_handler_wrap.h" +#include "ffrt_task_handler_wrap.h" + +namespace OHOS { +namespace AAFwk { +constexpr int MILL_TO_MICRO = 1000; +bool TaskHandle::Cancel() const +{ + auto handler = handler_.lock(); + if (!status_ || !handler || !innerTaskHandle_) { + return false; + } + + auto &status = *status_; + if (status != TaskStatus::PENDING) { + return false; + } + + auto ret = handler->CancelTaskInner(innerTaskHandle_); + // Here the result is ignored and status is set to canceled + status = TaskStatus::CANCELED; + return ret; +} +void TaskHandle::Sync() const +{ + auto handler = handler_.lock(); + if (!status_ || !handler || !innerTaskHandle_) { + return; + } + auto &status = *status_; + if (status == TaskStatus::FINISHED || status == TaskStatus::CANCELED) { + return; + } + handler->WaitTaskInner(innerTaskHandle_); +} + +std::shared_ptr TaskHandlerWrap::CreateQueueHandler(const std::string &queueName, + TaskQoS queueQos) +{ + return std::make_shared(queueName, queueQos); +} + +std::shared_ptr TaskHandlerWrap::GetFfrtHandler() +{ + static auto ffrtHandler = std::make_shared(); + return ffrtHandler; +} + +TaskHandlerWrap::TaskHandlerWrap() +{ + tasksMutex_ = std::make_unique(); +} + +TaskHandlerWrap::~TaskHandlerWrap() = default; + +TaskHandle TaskHandlerWrap::SubmitTask(const std::function &task) +{ + return SubmitTask(task, TaskAttribute()); +} +TaskHandle TaskHandlerWrap::SubmitTask(const std::function &task, const std::string &name) +{ + return SubmitTask(task, TaskAttribute{name}); +} +TaskHandle TaskHandlerWrap::SubmitTask(const std::function &task, int64_t delayMillis) +{ + return SubmitTask(task, TaskAttribute{.delayMillis_ = delayMillis}); +} +TaskHandle TaskHandlerWrap::SubmitTask(const std::function &task, TaskQoS taskQos) +{ + return SubmitTask(task, TaskAttribute{.taskQos_ = taskQos}); +} +TaskHandle TaskHandlerWrap::SubmitTaskJust(const std::function &task, + const std::string &name, int64_t delayMillis) +{ + return SubmitTask(task, TaskAttribute{name, delayMillis}); +} +TaskHandle TaskHandlerWrap::SubmitTask(const std::function &task, + const std::string &name, int64_t delayMillis, bool forceSubmit) +{ + HILOG_INFO("SubmitTask delay task begin"); + TaskAttribute atskAttr{name, delayMillis}; + std::lock_guard guard(*tasksMutex_); + auto it = tasks_.find(name); + if (it != tasks_.end()) { + if (forceSubmit) { + return SubmitTask(task, atskAttr); + } else { + return TaskHandle(); + } + } + + auto result = SubmitTask(task, atskAttr); + tasks_.emplace(name, result); + + // submit clear task to clear map record + auto clearTask = [whandler = weak_from_this(), name, taskHandle = result]() { + HILOG_INFO("clearTask delay task begin"); + auto handler = whandler.lock(); + if (!handler) { + return; + } + handler->RemoveTask(name, taskHandle); + HILOG_INFO("clearTask delay task end"); + }; + SubmitTask(clearTask, delayMillis); + + return result; +} +TaskHandle TaskHandlerWrap::SubmitTask(const std::function &task, const TaskAttribute &taskAttr) +{ + if (!task) { + return TaskHandle(); + } + TaskHandle result(shared_from_this(), nullptr); + auto taskWrap = [result, task]() { + *result.status_ = TaskStatus::EXECUTING; + task(); + *result.status_ = TaskStatus::FINISHED; + }; + result.innerTaskHandle_ = SubmitTaskInner(taskWrap, taskAttr); + return result; +} +bool TaskHandlerWrap::CancelTask(const std::string &name) +{ + HILOG_INFO("CancelTask task begin"); + std::lock_guard guard(*tasksMutex_); + auto it = tasks_.find(name); + if (it == tasks_.end()) { + return false; + } + + auto taskHandle = it->second; + tasks_.erase(it); + return taskHandle.Cancel(); +} + +bool TaskHandlerWrap::RemoveTask(const std::string &name, const TaskHandle &taskHandle) +{ + std::lock_guard guard(*tasksMutex_); + auto it = tasks_.find(name); + if (it == tasks_.end() || !it->second.IsSame(taskHandle)) { + return false; + } + tasks_.erase(it); + return true; +} +ffrt::qos Convert2FfrtQos(TaskQoS taskqos) +{ + static ffrt::qos qosMap[] = { + ffrt::qos_inherit, + ffrt::qos_background, + ffrt::qos_utility, + ffrt::qos_default, + ffrt::qos_user_initiated, + ffrt::qos_deadline_request, + ffrt::qos_user_interactive, + ffrt::qos_defined_ive + }; + + return qosMap[static_cast(taskqos)]; +} +void BuildFfrtTaskAttr(const TaskAttribute &taskAttr, ffrt::task_attr &result) +{ + if (taskAttr.delayMillis_ > 0) { + result.delay(taskAttr.delayMillis_ * MILL_TO_MICRO); + } + if (!taskAttr.taskName_.empty()) { + result.name(taskAttr.taskName_.c_str()); + } + if (taskAttr.taskQos_ != TaskQoS::DEFAULT) { + result.qos(Convert2FfrtQos(taskAttr.taskQos_)); + } +} +} // namespace AAFWK +} // namespace OHOS \ No newline at end of file diff --git a/services/dataobsmgr/BUILD.gn b/services/dataobsmgr/BUILD.gn index 521ad8e6e0..f637a07c08 100644 --- a/services/dataobsmgr/BUILD.gn +++ b/services/dataobsmgr/BUILD.gn @@ -37,12 +37,15 @@ ohos_shared_library("dataobsms") { configs = [ ":dataobsms_config" ] - deps = [ "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager" ] + deps = [ + "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", + "${ability_runtime_services_path}/common:task_handler_wrap", + ] external_deps = [ "ability_base:zuri", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", @@ -64,7 +67,7 @@ ohos_static_library("dataobsms_static") { external_deps = [ "ability_base:zuri", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/dataobsmgr/include/dataobs_mgr_inner.h b/services/dataobsmgr/include/dataobs_mgr_inner.h index c6a91a7492..8a975a22c9 100644 --- a/services/dataobsmgr/include/dataobs_mgr_inner.h +++ b/services/dataobsmgr/include/dataobs_mgr_inner.h @@ -22,13 +22,12 @@ #include #include #include +#include "cpp/mutex.h" #include "data_ability_observer_interface.h" -#include "event_handler.h" namespace OHOS { namespace AAFwk { -using EventHandler = OHOS::AppExecFwk::EventHandler; class DataObsMgrInner : public std::enable_shared_from_this { public: using ObsMapType = std::map>>; @@ -49,7 +48,7 @@ private: bool HaveRegistered(sptr dataObserver); static constexpr uint32_t OBS_NUM_MAX = 50; - std::mutex innerMutex_; + ffrt::mutex innerMutex_; ObsMapType observers_; ObsRecipientMapType obsRecipient_; }; diff --git a/services/dataobsmgr/include/dataobs_mgr_inner_ext.h b/services/dataobsmgr/include/dataobs_mgr_inner_ext.h index fe1fc41dbb..78812c0678 100644 --- a/services/dataobsmgr/include/dataobs_mgr_inner_ext.h +++ b/services/dataobsmgr/include/dataobs_mgr_inner_ext.h @@ -22,16 +22,15 @@ #include #include #include +#include "cpp/mutex.h" #include "data_ability_observer_interface.h" #include "dataobs_mgr_errors.h" -#include "event_handler.h" #include "iremote_object.h" #include "refbase.h" namespace OHOS { namespace AAFwk { -using EventHandler = OHOS::AppExecFwk::EventHandler; class DataObsMgrInnerExt : public std::enable_shared_from_this { public: @@ -85,7 +84,7 @@ private: static constexpr uint32_t OBS_NUM_MAX = 50; - std::mutex nodeMutex_; + ffrt::mutex nodeMutex_; std::shared_ptr root_; std::map, std::shared_ptr> obsRecipientRefs; }; diff --git a/services/dataobsmgr/include/dataobs_mgr_service.h b/services/dataobsmgr/include/dataobs_mgr_service.h index 64150aae2c..7144da1637 100644 --- a/services/dataobsmgr/include/dataobs_mgr_service.h +++ b/services/dataobsmgr/include/dataobs_mgr_service.h @@ -20,6 +20,7 @@ #include #include #include +#include "cpp/mutex.h" #include "dataobs_mgr_inner.h" #include "dataobs_mgr_inner_ext.h" @@ -27,14 +28,11 @@ #include "hilog_wrapper.h" #include "iremote_object.h" #include "system_ability.h" +#include "task_handler_wrap.h" #include "uri.h" -#include "event_runner.h" -#include "event_handler.h" namespace OHOS { namespace AAFwk { -using EventRunner = OHOS::AppExecFwk::EventRunner; -using EventHandler = OHOS::AppExecFwk::EventHandler; enum class DataObsServiceRunningState { STATE_NOT_START, STATE_RUNNING }; /** @@ -68,13 +66,6 @@ public: */ int Dump(int fd, const std::vector& args) override; - /** - * GetEventHandler, get the dataobs manager service's handler. - * - * @return Returns EventHandler ptr. - */ - std::shared_ptr GetEventHandler(); - private: bool Init(); void Dump(const std::vector& args, std::string& result) const; @@ -82,11 +73,9 @@ private: Status DeepCopyChangeInfo(const ChangeInfo &src, ChangeInfo &dst) const; private: static constexpr std::uint32_t TASK_COUNT_MAX = 50; - std::mutex taskCountMutex_; + ffrt::mutex taskCountMutex_; std::uint32_t taskCount_ = 0; - - std::shared_ptr eventLoop_; - std::shared_ptr handler_; + std::shared_ptr handler_; DataObsServiceRunningState state_; diff --git a/services/dataobsmgr/src/dataobs_mgr_inner.cpp b/services/dataobsmgr/src/dataobs_mgr_inner.cpp index e0b7ff562d..a910deb18d 100644 --- a/services/dataobsmgr/src/dataobs_mgr_inner.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_inner.cpp @@ -28,7 +28,7 @@ DataObsMgrInner::~DataObsMgrInner() {} int DataObsMgrInner::HandleRegisterObserver(const Uri &uri, sptr dataObserver) { - std::lock_guard lock(innerMutex_); + std::lock_guard lock(innerMutex_); auto [obsPair, flag] = observers_.try_emplace(uri.ToString(), std::list>()); if (!flag && obsPair->second.size() > OBS_NUM_MAX) { @@ -54,7 +54,7 @@ int DataObsMgrInner::HandleRegisterObserver(const Uri &uri, sptr dataObserver) { - std::lock_guard lock(innerMutex_); + std::lock_guard lock(innerMutex_); auto obsPair = observers_.find(uri.ToString()); if (obsPair == observers_.end()) { @@ -89,7 +89,7 @@ int DataObsMgrInner::HandleUnregisterObserver(const Uri &uri, sptr> obsList; - std::lock_guard lock(innerMutex_); + std::lock_guard lock(innerMutex_); { auto obsPair = observers_.find(uri.ToString()); if (obsPair == observers_.end()) { @@ -156,7 +156,7 @@ void DataObsMgrInner::OnCallBackDied(const wptr &remote) if (dataObserver == nullptr) { return; } - std::lock_guard lock(innerMutex_); + std::lock_guard lock(innerMutex_); if (dataObserver == nullptr) { HILOG_ERROR("dataObserver is nullptr."); diff --git a/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp b/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp index f322fce7e3..b115bbe5a6 100644 --- a/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_inner_ext.cpp @@ -31,7 +31,7 @@ Status DataObsMgrInnerExt::HandleRegisterObserver(Uri &uri, sptrAsObject() == nullptr) { return DATA_OBSERVER_IS_NULL; } - std::lock_guard lock(nodeMutex_); + std::lock_guard lock(nodeMutex_); auto deathRecipientRef = AddObsDeathRecipient(dataObserver->AsObject()); if (deathRecipientRef == nullptr) { return DATAOBS_SERVICE_OBS_LIMMIT; @@ -55,7 +55,7 @@ Status DataObsMgrInnerExt::HandleUnregisterObserver(Uri &uri, sptr lock(nodeMutex_); + std::lock_guard lock(nodeMutex_); std::vector path = { uri.GetScheme(), uri.GetAuthority() }; uri.GetPathSegments(path); if (root_ != nullptr) { @@ -71,7 +71,7 @@ Status DataObsMgrInnerExt::HandleUnregisterObserver(sptr d HILOG_ERROR("dataObserver is null"); return DATA_OBSERVER_IS_NULL; } - std::lock_guard lock(nodeMutex_); + std::lock_guard lock(nodeMutex_); if (root_ != nullptr) { root_->RemoveObserver(dataObserver); } @@ -84,7 +84,7 @@ Status DataObsMgrInnerExt::HandleNotifyChange(const ChangeInfo &changeInfo) ObsMap changeRes; std::vector path; { - std::lock_guard lock(nodeMutex_); + std::lock_guard lock(nodeMutex_); for (auto &uri : changeInfo.uris_) { path.clear(); path.emplace_back(uri.GetScheme()); @@ -156,7 +156,7 @@ void DataObsMgrInnerExt::OnCallBackDied(const wptr &remote) if (dataObserver == nullptr) { return; } - std::lock_guard lock(nodeMutex_); + std::lock_guard lock(nodeMutex_); if (root_ != nullptr) { root_->RemoveObserver(dataObserver); } diff --git a/services/dataobsmgr/src/dataobs_mgr_service.cpp b/services/dataobsmgr/src/dataobs_mgr_service.cpp index c2a8afe6b0..f54e8f8eb5 100644 --- a/services/dataobsmgr/src/dataobs_mgr_service.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_service.cpp @@ -36,8 +36,6 @@ const bool REGISTER_RESULT = DataObsMgrService::DataObsMgrService() : SystemAbility(DATAOBS_MGR_SERVICE_SA_ID, true), - eventLoop_(nullptr), - handler_(nullptr), state_(DataObsServiceRunningState::STATE_NOT_START) { dataObsMgrInner_ = std::make_shared(); @@ -58,7 +56,6 @@ void DataObsMgrService::OnStart() return; } state_ = DataObsServiceRunningState::STATE_RUNNING; - eventLoop_->Run(); /* Publish service maybe failed, so we need call this function at the last, * so it can't affect the TDD test program */ if (!Publish(DelayedSingleton::GetInstance().get())) { @@ -71,20 +68,13 @@ void DataObsMgrService::OnStart() bool DataObsMgrService::Init() { - eventLoop_ = AppExecFwk::EventRunner::Create("DataObsMgrService"); - if (eventLoop_ == nullptr) { - return false; - } - - handler_ = std::make_shared(eventLoop_); - + handler_ = TaskHandlerWrap::GetFfrtHandler(); return true; } void DataObsMgrService::OnStop() { HILOG_INFO("stop service"); - eventLoop_.reset(); handler_.reset(); state_ = DataObsServiceRunningState::STATE_NOT_START; } @@ -149,7 +139,7 @@ int DataObsMgrService::NotifyChange(const Uri &uri) } { - std::lock_guard lck(taskCountMutex_); + std::lock_guard lck(taskCountMutex_); if (taskCount_ >= TASK_COUNT_MAX) { HILOG_ERROR("The number of task has reached the upper limit, uri:%{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); @@ -159,16 +149,12 @@ int DataObsMgrService::NotifyChange(const Uri &uri) } ChangeInfo changeInfo = { ChangeInfo::ChangeType::OTHER, { uri } }; - bool ret = handler_->PostTask([this, uri, changeInfo]() { + handler_->SubmitTask([this, uri, changeInfo]() { dataObsMgrInner_->HandleNotifyChange(uri); dataObsMgrInnerExt_->HandleNotifyChange(changeInfo); - std::lock_guard lck(taskCountMutex_); + std::lock_guard lck(taskCountMutex_); --taskCount_; }); - if (!ret) { - HILOG_ERROR("Post NotifyChange fail, uri:%{public}s", CommonUtils::Anonymous(uri.ToString()).c_str()); - return DATAOBS_SERVICE_POST_TASK_FAILED; - } return NO_ERROR; } @@ -264,7 +250,7 @@ Status DataObsMgrService::NotifyChangeExt(const ChangeInfo &changeInfo) } { - std::lock_guard lck(taskCountMutex_); + std::lock_guard lck(taskCountMutex_); if (taskCount_ >= TASK_COUNT_MAX) { HILOG_ERROR("The number of task has reached the upper limit, changeType:%{public}ud, num of " "uris:%{public}zu, data is nullptr:%{public}d, size:%{public}ud", @@ -274,22 +260,15 @@ Status DataObsMgrService::NotifyChangeExt(const ChangeInfo &changeInfo) ++taskCount_; } - bool ret = handler_->PostTask([this, changes]() { + handler_->SubmitTask([this, changes]() { dataObsMgrInnerExt_->HandleNotifyChange(changes); for (auto &uri : changes.uris_) { dataObsMgrInner_->HandleNotifyChange(uri); } delete [] static_cast(changes.data_); - std::lock_guard lck(taskCountMutex_); + std::lock_guard lck(taskCountMutex_); --taskCount_; }); - if (!ret) { - delete [] static_cast(changes.data_); - HILOG_ERROR("Post NotifyChangeExt fail, changeType:%{public}ud, num of uris:%{public}zu, data is " - "nullptr:%{public}d, size:%{public}ud", - changeInfo.changeType_, changeInfo.uris_.size(), changeInfo.data_ == nullptr, changeInfo.size_); - return DATAOBS_SERVICE_POST_TASK_FAILED; - } return SUCCESS; } @@ -326,10 +305,5 @@ void DataObsMgrService::ShowHelp(std::string& result) const .append("-h ") .append("help text for the tool\n"); } - -std::shared_ptr DataObsMgrService::GetEventHandler() -{ - return handler_; -} } // namespace AAFwk } // namespace OHOS diff --git a/test/fuzztest/abilityattachtimeout_fuzzer/BUILD.gn b/test/fuzztest/abilityattachtimeout_fuzzer/BUILD.gn index d3f9e105a0..2590253e15 100755 --- a/test/fuzztest/abilityattachtimeout_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityattachtimeout_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("AbilityAttachTimeOutFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/abilityconnectmanager_fuzzer/BUILD.gn b/test/fuzztest/abilityconnectmanager_fuzzer/BUILD.gn index d68044afb7..4860f84e73 100755 --- a/test/fuzztest/abilityconnectmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityconnectmanager_fuzzer/BUILD.gn @@ -52,7 +52,7 @@ ohos_fuzztest("AbilityConnectManagerFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitycontext_fuzzer/BUILD.gn b/test/fuzztest/abilitycontext_fuzzer/BUILD.gn index cfe1f8ed74..4c49cfcb8c 100644 --- a/test/fuzztest/abilitycontext_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitycontext_fuzzer/BUILD.gn @@ -48,6 +48,7 @@ ohos_fuzztest("AbilityContextFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/abilityeventhandler_fuzzer/BUILD.gn b/test/fuzztest/abilityeventhandler_fuzzer/BUILD.gn index 545de032d6..12b69ddf11 100755 --- a/test/fuzztest/abilityeventhandler_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityeventhandler_fuzzer/BUILD.gn @@ -56,7 +56,7 @@ ohos_fuzztest("AbilityEventHandlerFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp b/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp index 474ff10a77..c0804b502e 100755 --- a/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp +++ b/test/fuzztest/abilityeventhandler_fuzzer/abilityeventhandler_fuzzer.cpp @@ -81,7 +81,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) std::string stringParam(data, size); // fuzz for AbilityEventHandler - std::shared_ptr runner; + std::shared_ptr runner; std::weak_ptr server; auto abilityEventHandler = std::make_shared(runner, server); abilityEventHandler->ProcessLoadTimeOut(int64Param); diff --git a/test/fuzztest/abilitymanager_fuzzer/BUILD.gn b/test/fuzztest/abilitymanager_fuzzer/BUILD.gn index b6ef5686a7..dcc0fc2358 100644 --- a/test/fuzztest/abilitymanager_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanager_fuzzer/BUILD.gn @@ -48,6 +48,7 @@ ohos_fuzztest("AbilityManagerFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/abilitymanagerservicea_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicea_fuzzer/BUILD.gn index 6781d03a3d..d121b1111a 100755 --- a/test/fuzztest/abilitymanagerservicea_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicea_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceAFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerserviceb_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerserviceb_fuzzer/BUILD.gn index 20e7af6298..83cc807c02 100755 --- a/test/fuzztest/abilitymanagerserviceb_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerserviceb_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceBFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerservicec_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicec_fuzzer/BUILD.gn index 5c5b57708a..175b7be2f9 100755 --- a/test/fuzztest/abilitymanagerservicec_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicec_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceCFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerserviced_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerserviced_fuzzer/BUILD.gn index 960d3b225f..2b5bb185cd 100755 --- a/test/fuzztest/abilitymanagerserviced_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerserviced_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceDFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerservicee_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicee_fuzzer/BUILD.gn index aa85b08869..cdf4ed981a 100755 --- a/test/fuzztest/abilitymanagerservicee_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicee_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceEFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerserviceeighth_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerserviceeighth_fuzzer/BUILD.gn index 96bbe398d2..fca8b84849 100755 --- a/test/fuzztest/abilitymanagerserviceeighth_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerserviceeighth_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceEighthFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerservicef_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicef_fuzzer/BUILD.gn index b8c3a89f52..349ecf5c54 100755 --- a/test/fuzztest/abilitymanagerservicef_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicef_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceFFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerservicefifth_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicefifth_fuzzer/BUILD.gn index 36494e4fb9..8577ec91f3 100755 --- a/test/fuzztest/abilitymanagerservicefifth_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicefifth_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceFifthFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerservicefirst_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicefirst_fuzzer/BUILD.gn index bc32fd2c1f..ec634b3c6b 100755 --- a/test/fuzztest/abilitymanagerservicefirst_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicefirst_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceFirstFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerservicefourth_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicefourth_fuzzer/BUILD.gn index 872a01682f..2e640e9108 100755 --- a/test/fuzztest/abilitymanagerservicefourth_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicefourth_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceFourthFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerserviceg_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerserviceg_fuzzer/BUILD.gn index 600b7bc968..a26a5d5f1f 100755 --- a/test/fuzztest/abilitymanagerserviceg_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerserviceg_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceGFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerserviceh_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerserviceh_fuzzer/BUILD.gn index 0ea3270eb5..44d60ad7d0 100755 --- a/test/fuzztest/abilitymanagerserviceh_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerserviceh_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceHFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerserviceninth_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerserviceninth_fuzzer/BUILD.gn index 95c84444e2..e35e05ab72 100755 --- a/test/fuzztest/abilitymanagerserviceninth_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerserviceninth_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceNinthFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerservicesecond_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicesecond_fuzzer/BUILD.gn index e38ef94722..083c3ed73e 100755 --- a/test/fuzztest/abilitymanagerservicesecond_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicesecond_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceSecondFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerserviceseventh_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerserviceseventh_fuzzer/BUILD.gn index 8aa05f53cb..a382ee3db1 100755 --- a/test/fuzztest/abilitymanagerserviceseventh_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerserviceseventh_fuzzer/BUILD.gn @@ -56,7 +56,7 @@ ohos_fuzztest("AbilityManagerServiceSeventhFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerservicesixth_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicesixth_fuzzer/BUILD.gn index 3f27ed7698..714d49fa66 100755 --- a/test/fuzztest/abilitymanagerservicesixth_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicesixth_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceSixthFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerservicetenth_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicetenth_fuzzer/BUILD.gn index 74c4ef0004..3546d53e0e 100755 --- a/test/fuzztest/abilitymanagerservicetenth_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicetenth_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceTenthFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymanagerservicethird_fuzzer/BUILD.gn b/test/fuzztest/abilitymanagerservicethird_fuzzer/BUILD.gn index efb38217eb..5af5a0ce23 100755 --- a/test/fuzztest/abilitymanagerservicethird_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymanagerservicethird_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("AbilityManagerServiceThirdFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/abilitymgrrest_fuzzer/BUILD.gn b/test/fuzztest/abilitymgrrest_fuzzer/BUILD.gn index 78ec04f92a..8e41668aea 100755 --- a/test/fuzztest/abilitymgrrest_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitymgrrest_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("AbilityMgrRestFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/abilityrunningrecord_fuzzer/BUILD.gn b/test/fuzztest/abilityrunningrecord_fuzzer/BUILD.gn index 1376bdba25..e609436578 100644 --- a/test/fuzztest/abilityrunningrecord_fuzzer/BUILD.gn +++ b/test/fuzztest/abilityrunningrecord_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("AbilityRunningRecordFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/abilitytransitiondone_fuzzer/BUILD.gn b/test/fuzztest/abilitytransitiondone_fuzzer/BUILD.gn index 7d22451956..a7371c5304 100644 --- a/test/fuzztest/abilitytransitiondone_fuzzer/BUILD.gn +++ b/test/fuzztest/abilitytransitiondone_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("AbilityTransitionDoneFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/acquiredataability_fuzzer/BUILD.gn b/test/fuzztest/acquiredataability_fuzzer/BUILD.gn index 712b78405c..9b3aefabf9 100644 --- a/test/fuzztest/acquiredataability_fuzzer/BUILD.gn +++ b/test/fuzztest/acquiredataability_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("AcquireDataAbilityFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "ffrt:libffrt", ] } diff --git a/test/fuzztest/addabilitystagedone_fuzzer/addabilitystagedone_fuzzer.cpp b/test/fuzztest/addabilitystagedone_fuzzer/addabilitystagedone_fuzzer.cpp index 9e6257f930..018d7e7262 100755 --- a/test/fuzztest/addabilitystagedone_fuzzer/addabilitystagedone_fuzzer.cpp +++ b/test/fuzztest/addabilitystagedone_fuzzer/addabilitystagedone_fuzzer.cpp @@ -18,7 +18,6 @@ #include #include -#include "ability_record.h" #include "app_mgr_client.h" #include "configuration.h" #include "parcel.h" diff --git a/test/fuzztest/amsmanager_fuzzer/BUILD.gn b/test/fuzztest/amsmanager_fuzzer/BUILD.gn index 9456acd339..eb012d9a56 100644 --- a/test/fuzztest/amsmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/amsmanager_fuzzer/BUILD.gn @@ -9,7 +9,7 @@ # 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. +# limitations under the License. #####################hydra-fuzz################### import("//build/config/features.gni") @@ -47,7 +47,7 @@ ohos_fuzztest("AmsManagerFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/amsmanager_fuzzer/amsmanager_fuzzer.cpp b/test/fuzztest/amsmanager_fuzzer/amsmanager_fuzzer.cpp index 8826cffdb7..f29b25bd05 100644 --- a/test/fuzztest/amsmanager_fuzzer/amsmanager_fuzzer.cpp +++ b/test/fuzztest/amsmanager_fuzzer/amsmanager_fuzzer.cpp @@ -20,7 +20,6 @@ #include "ams_mgr_scheduler.h" #include "app_mgr_constants.h" -#include "app_mgr_service_event_handler.h" #include "app_mgr_service_inner.h" #include "message_parcel.h" #include "securec.h" @@ -52,8 +51,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) MessageParcel reply; MessageOption option; std::shared_ptr appMgrServiceInner = std::make_shared(); - std::shared_ptr eventHandler = std::make_shared(nullptr, appMgrServiceInner); - std::shared_ptr amsMgr = std::make_shared(appMgrServiceInner, eventHandler); + std::shared_ptr amsMgr = std::make_shared(appMgrServiceInner, nullptr); amsMgr->OnRemoteRequest(code, parcel, reply, option); return true; diff --git a/test/fuzztest/amsmgrscheduler_fuzzer/BUILD.gn b/test/fuzztest/amsmgrscheduler_fuzzer/BUILD.gn index 54e8eeed36..50c46a3a11 100755 --- a/test/fuzztest/amsmgrscheduler_fuzzer/BUILD.gn +++ b/test/fuzztest/amsmgrscheduler_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("AmsMgrSchedulerFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp b/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp index 288b2b4cfb..c6a61c7144 100755 --- a/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp +++ b/test/fuzztest/amsmgrscheduler_fuzzer/amsmgrscheduler_fuzzer.cpp @@ -60,7 +60,7 @@ sptr GetFuzzAbilityToken() bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { std::shared_ptr mgrServiceInner; - std::shared_ptr handler; + std::shared_ptr handler; AmsMgrScheduler amsMgrScheduler(mgrServiceInner, handler); sptr response; amsMgrScheduler.RegisterStartSpecifiedAbilityResponse(response); diff --git a/test/fuzztest/applicationanrlistener_fuzzer/BUILD.gn b/test/fuzztest/applicationanrlistener_fuzzer/BUILD.gn index 453333b3e0..857c485923 100755 --- a/test/fuzztest/applicationanrlistener_fuzzer/BUILD.gn +++ b/test/fuzztest/applicationanrlistener_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("ApplicationAnrListenerFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/applifecycledeal_fuzzer/BUILD.gn b/test/fuzztest/applifecycledeal_fuzzer/BUILD.gn index d4071dca33..e53c0e7421 100644 --- a/test/fuzztest/applifecycledeal_fuzzer/BUILD.gn +++ b/test/fuzztest/applifecycledeal_fuzzer/BUILD.gn @@ -51,6 +51,7 @@ ohos_fuzztest("AppLifecycleDealFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/appmanager_fuzzer/BUILD.gn b/test/fuzztest/appmanager_fuzzer/BUILD.gn index 7e93b6c813..191396e84b 100644 --- a/test/fuzztest/appmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/appmanager_fuzzer/BUILD.gn @@ -41,6 +41,7 @@ ohos_fuzztest("AppManagerFuzzTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", ] external_deps = [ @@ -49,7 +50,7 @@ ohos_fuzztest("AppManagerFuzzTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/appmgrrest_fuzzer/BUILD.gn b/test/fuzztest/appmgrrest_fuzzer/BUILD.gn index 9e635d0ad9..b1f41043b0 100755 --- a/test/fuzztest/appmgrrest_fuzzer/BUILD.gn +++ b/test/fuzztest/appmgrrest_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("AppMgrRestFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp b/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp index eb7a223515..dae1a13b3c 100755 --- a/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp +++ b/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp @@ -69,8 +69,8 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) sptr appDeathRecipient = new AppDeathRecipient(); wptr remote; appDeathRecipient->OnRemoteDied(remote); - std::shared_ptr handler; - appDeathRecipient->SetEventHandler(handler); + std::shared_ptr handler; + appDeathRecipient->SetTaskHandler(handler); std::shared_ptr serviceInner; appDeathRecipient->SetAppMgrServiceInner(serviceInner); bool isRenderProcess = *data % ENABLE; diff --git a/test/fuzztest/appmgrservicefirst_fuzzer/BUILD.gn b/test/fuzztest/appmgrservicefirst_fuzzer/BUILD.gn index d031fe4af0..4e2b97bd92 100755 --- a/test/fuzztest/appmgrservicefirst_fuzzer/BUILD.gn +++ b/test/fuzztest/appmgrservicefirst_fuzzer/BUILD.gn @@ -55,6 +55,7 @@ ohos_fuzztest("AppMgrServiceFirstFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/appmgrserviceinnerfirst_fuzzer/BUILD.gn b/test/fuzztest/appmgrserviceinnerfirst_fuzzer/BUILD.gn index 6c02205920..d83114173a 100644 --- a/test/fuzztest/appmgrserviceinnerfirst_fuzzer/BUILD.gn +++ b/test/fuzztest/appmgrserviceinnerfirst_fuzzer/BUILD.gn @@ -55,6 +55,7 @@ ohos_fuzztest("AppMgrServiceInnerFirstFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/appmgrserviceinnerfirst_fuzzer/appmgrserviceinnerfirst_fuzzer.cpp b/test/fuzztest/appmgrserviceinnerfirst_fuzzer/appmgrserviceinnerfirst_fuzzer.cpp index d6bf221d0a..a927803202 100644 --- a/test/fuzztest/appmgrserviceinnerfirst_fuzzer/appmgrserviceinnerfirst_fuzzer.cpp +++ b/test/fuzztest/appmgrserviceinnerfirst_fuzzer/appmgrserviceinnerfirst_fuzzer.cpp @@ -22,7 +22,6 @@ #include "app_mgr_service_inner.h" #undef private -#include "ability_record.h" #include "parcel.h" #include "securec.h" diff --git a/test/fuzztest/appmgrserviceinnersecond_fuzzer/BUILD.gn b/test/fuzztest/appmgrserviceinnersecond_fuzzer/BUILD.gn index 3691281d8b..54e16d26fc 100755 --- a/test/fuzztest/appmgrserviceinnersecond_fuzzer/BUILD.gn +++ b/test/fuzztest/appmgrserviceinnersecond_fuzzer/BUILD.gn @@ -55,6 +55,7 @@ ohos_fuzztest("AppMgrServiceInnerSecondFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/apprunningmanager_fuzzer/BUILD.gn b/test/fuzztest/apprunningmanager_fuzzer/BUILD.gn index 3fce9dab9a..9d0ddc90f3 100755 --- a/test/fuzztest/apprunningmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/apprunningmanager_fuzzer/BUILD.gn @@ -55,6 +55,7 @@ ohos_fuzztest("AppRunningManagerFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/apprunningrecordfirst_fuzzer/BUILD.gn b/test/fuzztest/apprunningrecordfirst_fuzzer/BUILD.gn index af55311970..9db106c293 100755 --- a/test/fuzztest/apprunningrecordfirst_fuzzer/BUILD.gn +++ b/test/fuzztest/apprunningrecordfirst_fuzzer/BUILD.gn @@ -56,6 +56,7 @@ ohos_fuzztest("AppRunningRecordFirstFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/apprunningrecordsecond_fuzzer/BUILD.gn b/test/fuzztest/apprunningrecordsecond_fuzzer/BUILD.gn index efdcefa1b2..b77068575a 100755 --- a/test/fuzztest/apprunningrecordsecond_fuzzer/BUILD.gn +++ b/test/fuzztest/apprunningrecordsecond_fuzzer/BUILD.gn @@ -56,6 +56,7 @@ ohos_fuzztest("AppRunningRecordSecondFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/appstateobservermanager_fuzzer/BUILD.gn b/test/fuzztest/appstateobservermanager_fuzzer/BUILD.gn index 41f70fc14e..5ab9548a62 100755 --- a/test/fuzztest/appstateobservermanager_fuzzer/BUILD.gn +++ b/test/fuzztest/appstateobservermanager_fuzzer/BUILD.gn @@ -51,6 +51,7 @@ ohos_fuzztest("AppStateObserverManagerFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/attachabilitythread_fuzzer/BUILD.gn b/test/fuzztest/attachabilitythread_fuzzer/BUILD.gn index e44a44ddbf..e2b22958ec 100644 --- a/test/fuzztest/attachabilitythread_fuzzer/BUILD.gn +++ b/test/fuzztest/attachabilitythread_fuzzer/BUILD.gn @@ -53,7 +53,7 @@ ohos_fuzztest("AttachAbilityThreadFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/attachrenderprocess_fuzzer/attachrenderprocess_fuzzer.cpp b/test/fuzztest/attachrenderprocess_fuzzer/attachrenderprocess_fuzzer.cpp index 41c518c379..4aa43e22f8 100755 --- a/test/fuzztest/attachrenderprocess_fuzzer/attachrenderprocess_fuzzer.cpp +++ b/test/fuzztest/attachrenderprocess_fuzzer/attachrenderprocess_fuzzer.cpp @@ -18,7 +18,6 @@ #include #include -#include "ability_record.h" #include "app_mgr_client.h" #include "configuration.h" #include "parcel.h" diff --git a/test/fuzztest/blockability_fuzzer/BUILD.gn b/test/fuzztest/blockability_fuzzer/BUILD.gn index 7bcd95b765..c0189a5710 100644 --- a/test/fuzztest/blockability_fuzzer/BUILD.gn +++ b/test/fuzztest/blockability_fuzzer/BUILD.gn @@ -51,7 +51,7 @@ ohos_fuzztest("BlockAbilityFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/blockamsservice_fuzzer/BUILD.gn b/test/fuzztest/blockamsservice_fuzzer/BUILD.gn index 45e2bdb019..d688c0860e 100644 --- a/test/fuzztest/blockamsservice_fuzzer/BUILD.gn +++ b/test/fuzztest/blockamsservice_fuzzer/BUILD.gn @@ -53,7 +53,7 @@ ohos_fuzztest("BlockAmsServiceFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/blockappservice_fuzzer/BUILD.gn b/test/fuzztest/blockappservice_fuzzer/BUILD.gn index 0cde63318f..f7aef46a9a 100644 --- a/test/fuzztest/blockappservice_fuzzer/BUILD.gn +++ b/test/fuzztest/blockappservice_fuzzer/BUILD.gn @@ -52,7 +52,7 @@ ohos_fuzztest("BlockAppServiceFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/closeability_fuzzer/BUILD.gn b/test/fuzztest/closeability_fuzzer/BUILD.gn index ef59fe7e2c..4f55f2f5fe 100644 --- a/test/fuzztest/closeability_fuzzer/BUILD.gn +++ b/test/fuzztest/closeability_fuzzer/BUILD.gn @@ -51,6 +51,7 @@ ohos_fuzztest("CloseAbilityFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/completefirstframedrawing_fuzzer/BUILD.gn b/test/fuzztest/completefirstframedrawing_fuzzer/BUILD.gn index ab6f613ed0..9b839858b9 100644 --- a/test/fuzztest/completefirstframedrawing_fuzzer/BUILD.gn +++ b/test/fuzztest/completefirstframedrawing_fuzzer/BUILD.gn @@ -52,7 +52,7 @@ ohos_fuzztest("CompleteFirstFrameDrawingFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/connectionobserverclient_fuzzer/BUILD.gn b/test/fuzztest/connectionobserverclient_fuzzer/BUILD.gn index 2f5a36ddac..65fe40699a 100644 --- a/test/fuzztest/connectionobserverclient_fuzzer/BUILD.gn +++ b/test/fuzztest/connectionobserverclient_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("ConnectionObserverClientFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/connectionobserverclientimpl_fuzzer/BUILD.gn b/test/fuzztest/connectionobserverclientimpl_fuzzer/BUILD.gn index ddd7944d34..b8b92b5447 100644 --- a/test/fuzztest/connectionobserverclientimpl_fuzzer/BUILD.gn +++ b/test/fuzztest/connectionobserverclientimpl_fuzzer/BUILD.gn @@ -59,7 +59,7 @@ ohos_fuzztest("ConnectionObserverClientImplFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/connectionstatemanager_fuzzer/BUILD.gn b/test/fuzztest/connectionstatemanager_fuzzer/BUILD.gn index 35df529108..aa8bd9ccf5 100755 --- a/test/fuzztest/connectionstatemanager_fuzzer/BUILD.gn +++ b/test/fuzztest/connectionstatemanager_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("ConnectionStateManagerFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/dataabilitymanager_fuzzer/BUILD.gn b/test/fuzztest/dataabilitymanager_fuzzer/BUILD.gn index b6ee5ff10e..8ce3c046fc 100755 --- a/test/fuzztest/dataabilitymanager_fuzzer/BUILD.gn +++ b/test/fuzztest/dataabilitymanager_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("DataAbilityManagerFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/delegatordoabilitybackground_fuzzer/BUILD.gn b/test/fuzztest/delegatordoabilitybackground_fuzzer/BUILD.gn index b322a20b87..d3d5c82bb6 100644 --- a/test/fuzztest/delegatordoabilitybackground_fuzzer/BUILD.gn +++ b/test/fuzztest/delegatordoabilitybackground_fuzzer/BUILD.gn @@ -51,7 +51,7 @@ ohos_fuzztest("DelegatorDoAbilityBackgroundFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/delegatordoabilityforeground_fuzzer/BUILD.gn b/test/fuzztest/delegatordoabilityforeground_fuzzer/BUILD.gn index 45290f373c..15353c2893 100644 --- a/test/fuzztest/delegatordoabilityforeground_fuzzer/BUILD.gn +++ b/test/fuzztest/delegatordoabilityforeground_fuzzer/BUILD.gn @@ -51,7 +51,7 @@ ohos_fuzztest("DelegatorDoAbilityForegroundFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/doabilitybackground_fuzzer/BUILD.gn b/test/fuzztest/doabilitybackground_fuzzer/BUILD.gn index b971e5e2d0..739da0a977 100644 --- a/test/fuzztest/doabilitybackground_fuzzer/BUILD.gn +++ b/test/fuzztest/doabilitybackground_fuzzer/BUILD.gn @@ -51,7 +51,7 @@ ohos_fuzztest("DoAbilityBackgroundFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/doabilityforeground_fuzzer/BUILD.gn b/test/fuzztest/doabilityforeground_fuzzer/BUILD.gn index b12ef07a99..0ede961099 100644 --- a/test/fuzztest/doabilityforeground_fuzzer/BUILD.gn +++ b/test/fuzztest/doabilityforeground_fuzzer/BUILD.gn @@ -51,7 +51,7 @@ ohos_fuzztest("DoAbilityForegroundFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/dumpabilityinfodone_fuzzer/BUILD.gn b/test/fuzztest/dumpabilityinfodone_fuzzer/BUILD.gn index c8015a3199..d4f5ba70f2 100644 --- a/test/fuzztest/dumpabilityinfodone_fuzzer/BUILD.gn +++ b/test/fuzztest/dumpabilityinfodone_fuzzer/BUILD.gn @@ -52,7 +52,7 @@ ohos_fuzztest("DumpAbilityInfoDoneFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/dumpstate_fuzzer/BUILD.gn b/test/fuzztest/dumpstate_fuzzer/BUILD.gn index afa58cd794..7d4327121b 100644 --- a/test/fuzztest/dumpstate_fuzzer/BUILD.gn +++ b/test/fuzztest/dumpstate_fuzzer/BUILD.gn @@ -52,7 +52,7 @@ ohos_fuzztest("DumpStateFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/dumpsysstate_fuzzer/BUILD.gn b/test/fuzztest/dumpsysstate_fuzzer/BUILD.gn index b6218882da..c102202e22 100644 --- a/test/fuzztest/dumpsysstate_fuzzer/BUILD.gn +++ b/test/fuzztest/dumpsysstate_fuzzer/BUILD.gn @@ -52,7 +52,7 @@ ohos_fuzztest("DumpSysStateFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/forcetimeoutfortest_fuzzer/BUILD.gn b/test/fuzztest/forcetimeoutfortest_fuzzer/BUILD.gn index 31c0984738..ef24079d15 100644 --- a/test/fuzztest/forcetimeoutfortest_fuzzer/BUILD.gn +++ b/test/fuzztest/forcetimeoutfortest_fuzzer/BUILD.gn @@ -53,7 +53,7 @@ ohos_fuzztest("ForceTimeoutForTestFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/freeinstallabilityfromremote_fuzzer/BUILD.gn b/test/fuzztest/freeinstallabilityfromremote_fuzzer/BUILD.gn index 6c1dfdb251..e89934d669 100644 --- a/test/fuzztest/freeinstallabilityfromremote_fuzzer/BUILD.gn +++ b/test/fuzztest/freeinstallabilityfromremote_fuzzer/BUILD.gn @@ -51,7 +51,7 @@ ohos_fuzztest("FreeInstallAbilityFromRemoteFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/getabilityrecordsbyprocessid_fuzzer/BUILD.gn b/test/fuzztest/getabilityrecordsbyprocessid_fuzzer/BUILD.gn index 4a6fa72558..7094777067 100755 --- a/test/fuzztest/getabilityrecordsbyprocessid_fuzzer/BUILD.gn +++ b/test/fuzztest/getabilityrecordsbyprocessid_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("GetAbilityRecordsByProcessIDFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/getapplicationinfobyprocessid_fuzzer/BUILD.gn b/test/fuzztest/getapplicationinfobyprocessid_fuzzer/BUILD.gn index e7073feba9..243cf61a17 100755 --- a/test/fuzztest/getapplicationinfobyprocessid_fuzzer/BUILD.gn +++ b/test/fuzztest/getapplicationinfobyprocessid_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("GetApplicationInfoByProcessIDFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/getconfiguration_fuzzer/BUILD.gn b/test/fuzztest/getconfiguration_fuzzer/BUILD.gn index ad9036d75a..e58ef7fdca 100755 --- a/test/fuzztest/getconfiguration_fuzzer/BUILD.gn +++ b/test/fuzztest/getconfiguration_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("GetConfigurationFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/getmissionidbytoken_fuzzer/BUILD.gn b/test/fuzztest/getmissionidbytoken_fuzzer/BUILD.gn index 17847caa30..ff54f57b2f 100644 --- a/test/fuzztest/getmissionidbytoken_fuzzer/BUILD.gn +++ b/test/fuzztest/getmissionidbytoken_fuzzer/BUILD.gn @@ -50,7 +50,7 @@ ohos_fuzztest("GetMissionIdByTokenFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/getmissionsnapshot_fuzzer/BUILD.gn b/test/fuzztest/getmissionsnapshot_fuzzer/BUILD.gn index 8f6745baa3..f271082c27 100644 --- a/test/fuzztest/getmissionsnapshot_fuzzer/BUILD.gn +++ b/test/fuzztest/getmissionsnapshot_fuzzer/BUILD.gn @@ -52,7 +52,7 @@ ohos_fuzztest("GetMissionSnapshotFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/getprocessrunninginfosbyuserid_fuzzer/BUILD.gn b/test/fuzztest/getprocessrunninginfosbyuserid_fuzzer/BUILD.gn index 9a8e01b4a1..2fbb4bec3f 100755 --- a/test/fuzztest/getprocessrunninginfosbyuserid_fuzzer/BUILD.gn +++ b/test/fuzztest/getprocessrunninginfosbyuserid_fuzzer/BUILD.gn @@ -48,6 +48,7 @@ ohos_fuzztest("GetProcessRunningInfosByUserIdFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/getrenderprocessterminationstatus_fuzzer/BUILD.gn b/test/fuzztest/getrenderprocessterminationstatus_fuzzer/BUILD.gn index fb8454e90f..70f74c247a 100755 --- a/test/fuzztest/getrenderprocessterminationstatus_fuzzer/BUILD.gn +++ b/test/fuzztest/getrenderprocessterminationstatus_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("GetRenderProcessTerminationStatusFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/getrunningprocessinfobytoken_fuzzer/BUILD.gn b/test/fuzztest/getrunningprocessinfobytoken_fuzzer/BUILD.gn index 1fe00d2eb1..8e42128146 100755 --- a/test/fuzztest/getrunningprocessinfobytoken_fuzzer/BUILD.gn +++ b/test/fuzztest/getrunningprocessinfobytoken_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("GetRunningProcessInfoByTokenFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/gettopability_fuzzer/BUILD.gn b/test/fuzztest/gettopability_fuzzer/BUILD.gn index c20e8fa21a..a07f921fca 100755 --- a/test/fuzztest/gettopability_fuzzer/BUILD.gn +++ b/test/fuzztest/gettopability_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("GetTopAbilityFuzzTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_base", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", ] diff --git a/test/fuzztest/getwantsender_fuzzer/BUILD.gn b/test/fuzztest/getwantsender_fuzzer/BUILD.gn index 0bfc223847..9c59d986ac 100644 --- a/test/fuzztest/getwantsender_fuzzer/BUILD.gn +++ b/test/fuzztest/getwantsender_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("GetWantSenderFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "ffrt:libffrt", ] } diff --git a/test/fuzztest/handledlpapp_fuzzer/BUILD.gn b/test/fuzztest/handledlpapp_fuzzer/BUILD.gn index 5dae380e56..c3d107f922 100644 --- a/test/fuzztest/handledlpapp_fuzzer/BUILD.gn +++ b/test/fuzztest/handledlpapp_fuzzer/BUILD.gn @@ -51,7 +51,7 @@ ohos_fuzztest("HandleDlpAppFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/killapplication_fuzzer/BUILD.gn b/test/fuzztest/killapplication_fuzzer/BUILD.gn index 49d2b3b8b4..e1a7168b8c 100755 --- a/test/fuzztest/killapplication_fuzzer/BUILD.gn +++ b/test/fuzztest/killapplication_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("KillApplicationFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/killapplicationself_fuzzer/BUILD.gn b/test/fuzztest/killapplicationself_fuzzer/BUILD.gn index 8ecf4453b8..6b2ef405b1 100755 --- a/test/fuzztest/killapplicationself_fuzzer/BUILD.gn +++ b/test/fuzztest/killapplicationself_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("KillApplicationSelfFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/killprocessbyabilitytoken_fuzzer/BUILD.gn b/test/fuzztest/killprocessbyabilitytoken_fuzzer/BUILD.gn index 6af4ece780..19784c8029 100755 --- a/test/fuzztest/killprocessbyabilitytoken_fuzzer/BUILD.gn +++ b/test/fuzztest/killprocessbyabilitytoken_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("KillProcessByAbilityTokenFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/killprocessesbyuserid_fuzzer/BUILD.gn b/test/fuzztest/killprocessesbyuserid_fuzzer/BUILD.gn index 32683809df..4fe3e1d4fe 100755 --- a/test/fuzztest/killprocessesbyuserid_fuzzer/BUILD.gn +++ b/test/fuzztest/killprocessesbyuserid_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("KillProcessesByUserIdFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/loadability_fuzzer/BUILD.gn b/test/fuzztest/loadability_fuzzer/BUILD.gn index 79571bfed5..3cb293b929 100755 --- a/test/fuzztest/loadability_fuzzer/BUILD.gn +++ b/test/fuzztest/loadability_fuzzer/BUILD.gn @@ -48,6 +48,7 @@ ohos_fuzztest("LoadAbilityFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/minimizeability_fuzzer/BUILD.gn b/test/fuzztest/minimizeability_fuzzer/BUILD.gn index abf0b55106..cdeedfd627 100644 --- a/test/fuzztest/minimizeability_fuzzer/BUILD.gn +++ b/test/fuzztest/minimizeability_fuzzer/BUILD.gn @@ -53,7 +53,7 @@ ohos_fuzztest("MinimizeAbilityFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/missiondatastoragea_fuzzer/BUILD.gn b/test/fuzztest/missiondatastoragea_fuzzer/BUILD.gn index adc7c3a95b..7e094c0ba0 100755 --- a/test/fuzztest/missiondatastoragea_fuzzer/BUILD.gn +++ b/test/fuzztest/missiondatastoragea_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("MissionDataStorageAFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/missiondatastoragea_fuzzer/missiondatastoragea_fuzzer.cpp b/test/fuzztest/missiondatastoragea_fuzzer/missiondatastoragea_fuzzer.cpp index b3892fbba5..6632f07dac 100755 --- a/test/fuzztest/missiondatastoragea_fuzzer/missiondatastoragea_fuzzer.cpp +++ b/test/fuzztest/missiondatastoragea_fuzzer/missiondatastoragea_fuzzer.cpp @@ -51,8 +51,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) // fuzz for MissionDataStorage auto missionDataStorage = std::make_shared(intParam); - std::shared_ptr handler; - missionDataStorage->SetEventHandler(handler); std::list missionInfoList; missionDataStorage->LoadAllMissionInfo(missionInfoList); missionDataStorage->SaveMissionInfo(innerMissionInfo); diff --git a/test/fuzztest/missiondatastorageb_fuzzer/BUILD.gn b/test/fuzztest/missiondatastorageb_fuzzer/BUILD.gn index a7ea6243c1..7b4ad9ddf2 100755 --- a/test/fuzztest/missiondatastorageb_fuzzer/BUILD.gn +++ b/test/fuzztest/missiondatastorageb_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("MissionDataStorageBFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/missioninfomgra_fuzzer/BUILD.gn b/test/fuzztest/missioninfomgra_fuzzer/BUILD.gn index 76a97756d1..6b4904fa05 100755 --- a/test/fuzztest/missioninfomgra_fuzzer/BUILD.gn +++ b/test/fuzztest/missioninfomgra_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("MissionInfoMgrAFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/missioninfomgrb_fuzzer/BUILD.gn b/test/fuzztest/missioninfomgrb_fuzzer/BUILD.gn index 059bc3270f..1a06a7fa18 100755 --- a/test/fuzztest/missioninfomgrb_fuzzer/BUILD.gn +++ b/test/fuzztest/missioninfomgrb_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("MissionInfoMgrBFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/missioninfomgrc_fuzzer/BUILD.gn b/test/fuzztest/missioninfomgrc_fuzzer/BUILD.gn index cff8fbb748..f0e8f9b873 100755 --- a/test/fuzztest/missioninfomgrc_fuzzer/BUILD.gn +++ b/test/fuzztest/missioninfomgrc_fuzzer/BUILD.gn @@ -57,7 +57,7 @@ ohos_fuzztest("MissionInfoMgrCFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/missionlistmanagerfirst_fuzzer/BUILD.gn b/test/fuzztest/missionlistmanagerfirst_fuzzer/BUILD.gn index e2c3e18476..9381ff7c4a 100755 --- a/test/fuzztest/missionlistmanagerfirst_fuzzer/BUILD.gn +++ b/test/fuzztest/missionlistmanagerfirst_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("MissionListManagerFirstFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/missionlistmanagerfourth_fuzzer/BUILD.gn b/test/fuzztest/missionlistmanagerfourth_fuzzer/BUILD.gn index 81e26e9e8f..0e91e109af 100755 --- a/test/fuzztest/missionlistmanagerfourth_fuzzer/BUILD.gn +++ b/test/fuzztest/missionlistmanagerfourth_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("MissionListManagerFourthFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/missionlistmanagersecond_fuzzer/BUILD.gn b/test/fuzztest/missionlistmanagersecond_fuzzer/BUILD.gn index 040f1872fa..5060a24652 100755 --- a/test/fuzztest/missionlistmanagersecond_fuzzer/BUILD.gn +++ b/test/fuzztest/missionlistmanagersecond_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("MissionListManagerSecondFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/missionlistmanagerthird_fuzzer/BUILD.gn b/test/fuzztest/missionlistmanagerthird_fuzzer/BUILD.gn index 1fa88f8720..a50e3505ef 100755 --- a/test/fuzztest/missionlistmanagerthird_fuzzer/BUILD.gn +++ b/test/fuzztest/missionlistmanagerthird_fuzzer/BUILD.gn @@ -60,7 +60,7 @@ ohos_fuzztest("MissionListManagerThirdFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/modulerunningrecord_fuzzer/BUILD.gn b/test/fuzztest/modulerunningrecord_fuzzer/BUILD.gn index 9a185b8f6c..1eecaa13ee 100644 --- a/test/fuzztest/modulerunningrecord_fuzzer/BUILD.gn +++ b/test/fuzztest/modulerunningrecord_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("ModuleRunningRecordFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/notifymemorylevel_fuzzer/BUILD.gn b/test/fuzztest/notifymemorylevel_fuzzer/BUILD.gn index ad0445b5cd..f91b5ec677 100755 --- a/test/fuzztest/notifymemorylevel_fuzzer/BUILD.gn +++ b/test/fuzztest/notifymemorylevel_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("NotifyMemoryLevelFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/pendingwantmanager_fuzzer/BUILD.gn b/test/fuzztest/pendingwantmanager_fuzzer/BUILD.gn index 2bd054e411..58208df86e 100755 --- a/test/fuzztest/pendingwantmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/pendingwantmanager_fuzzer/BUILD.gn @@ -61,7 +61,7 @@ ohos_fuzztest("PendingWantManagerFuzzTest") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/prepareterminate_fuzzer/BUILD.gn b/test/fuzztest/prepareterminate_fuzzer/BUILD.gn index 7683197af9..f049cab389 100755 --- a/test/fuzztest/prepareterminate_fuzzer/BUILD.gn +++ b/test/fuzztest/prepareterminate_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("PrepareTerminateFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/prestartnwebspawnprocess_fuzzer/BUILD.gn b/test/fuzztest/prestartnwebspawnprocess_fuzzer/BUILD.gn index d04d60c400..076b3922dc 100755 --- a/test/fuzztest/prestartnwebspawnprocess_fuzzer/BUILD.gn +++ b/test/fuzztest/prestartnwebspawnprocess_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("PreStartNWebSpawnProcessFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/registerapplicationstateobserver_fuzzer/BUILD.gn b/test/fuzztest/registerapplicationstateobserver_fuzzer/BUILD.gn index 6b7f9fa0c4..61d6808896 100644 --- a/test/fuzztest/registerapplicationstateobserver_fuzzer/BUILD.gn +++ b/test/fuzztest/registerapplicationstateobserver_fuzzer/BUILD.gn @@ -46,7 +46,7 @@ ohos_fuzztest("RegisterApplicationStateObserverFuzzTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", diff --git a/test/fuzztest/registerconfigurationobserver_fuzzer/BUILD.gn b/test/fuzztest/registerconfigurationobserver_fuzzer/BUILD.gn index 482ca72cc7..9dea953678 100755 --- a/test/fuzztest/registerconfigurationobserver_fuzzer/BUILD.gn +++ b/test/fuzztest/registerconfigurationobserver_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("RegisterConfigurationObserverFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/releasedataability_fuzzer/BUILD.gn b/test/fuzztest/releasedataability_fuzzer/BUILD.gn index 4c7eed3c6f..aadf5ed2b2 100644 --- a/test/fuzztest/releasedataability_fuzzer/BUILD.gn +++ b/test/fuzztest/releasedataability_fuzzer/BUILD.gn @@ -53,7 +53,7 @@ ohos_fuzztest("ReleaseDataAbilityFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/scheduleacceptwantdone_fuzzer/BUILD.gn b/test/fuzztest/scheduleacceptwantdone_fuzzer/BUILD.gn index 6d5c68317c..90cdecbd6f 100755 --- a/test/fuzztest/scheduleacceptwantdone_fuzzer/BUILD.gn +++ b/test/fuzztest/scheduleacceptwantdone_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("ScheduleAcceptWantDoneFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/schedulecommandabilitydone_fuzzer/BUILD.gn b/test/fuzztest/schedulecommandabilitydone_fuzzer/BUILD.gn index 1a8cb87c5f..f97b347a67 100644 --- a/test/fuzztest/schedulecommandabilitydone_fuzzer/BUILD.gn +++ b/test/fuzztest/schedulecommandabilitydone_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("ScheduleCommandAbilityDoneFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/scheduleconnectabilitydone_fuzzer/BUILD.gn b/test/fuzztest/scheduleconnectabilitydone_fuzzer/BUILD.gn index d79e1608af..c0e2252876 100644 --- a/test/fuzztest/scheduleconnectabilitydone_fuzzer/BUILD.gn +++ b/test/fuzztest/scheduleconnectabilitydone_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("ScheduleConnectAbilityDoneFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/scheduledisconnectabilitydone_fuzzer/BUILD.gn b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/BUILD.gn index 01db102a6e..07fa14514f 100644 --- a/test/fuzztest/scheduledisconnectabilitydone_fuzzer/BUILD.gn +++ b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/BUILD.gn @@ -51,6 +51,7 @@ ohos_fuzztest("ScheduleDisconnectAbilityDoneFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/sendresulttoability_fuzzer/BUILD.gn b/test/fuzztest/sendresulttoability_fuzzer/BUILD.gn index 130423b534..bba3ac211b 100644 --- a/test/fuzztest/sendresulttoability_fuzzer/BUILD.gn +++ b/test/fuzztest/sendresulttoability_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("SendResultToAbilityFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/setabilitycontroller_fuzzer/BUILD.gn b/test/fuzztest/setabilitycontroller_fuzzer/BUILD.gn index f65c7e1f3b..4fb4774aa1 100644 --- a/test/fuzztest/setabilitycontroller_fuzzer/BUILD.gn +++ b/test/fuzztest/setabilitycontroller_fuzzer/BUILD.gn @@ -52,7 +52,7 @@ ohos_fuzztest("SetAbilityControllerFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/setmissionicon_fuzzer/BUILD.gn b/test/fuzztest/setmissionicon_fuzzer/BUILD.gn index 81ea68dc9c..070a665bee 100644 --- a/test/fuzztest/setmissionicon_fuzzer/BUILD.gn +++ b/test/fuzztest/setmissionicon_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("SetMissionIconFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "ffrt:libffrt", ] } diff --git a/test/fuzztest/setmissionlabel_fuzzer/BUILD.gn b/test/fuzztest/setmissionlabel_fuzzer/BUILD.gn index 3c3e1db4fd..872a03106e 100644 --- a/test/fuzztest/setmissionlabel_fuzzer/BUILD.gn +++ b/test/fuzztest/setmissionlabel_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("SetMissionLabelFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "ffrt:libffrt", ] } diff --git a/test/fuzztest/startability_fuzzer/BUILD.gn b/test/fuzztest/startability_fuzzer/BUILD.gn index 942e85a89f..308273edd6 100644 --- a/test/fuzztest/startability_fuzzer/BUILD.gn +++ b/test/fuzztest/startability_fuzzer/BUILD.gn @@ -53,6 +53,7 @@ ohos_fuzztest("StartAbilityFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", ] } diff --git a/test/fuzztest/startabilitybycall_fuzzer/BUILD.gn b/test/fuzztest/startabilitybycall_fuzzer/BUILD.gn index 976189994b..b6437d2692 100644 --- a/test/fuzztest/startabilitybycall_fuzzer/BUILD.gn +++ b/test/fuzztest/startabilitybycall_fuzzer/BUILD.gn @@ -50,7 +50,7 @@ ohos_fuzztest("StartAbilityByCallFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/fuzztest/startcontinuation_fuzzer/BUILD.gn b/test/fuzztest/startcontinuation_fuzzer/BUILD.gn index 3d51f5d1b9..4c5e52d29a 100644 --- a/test/fuzztest/startcontinuation_fuzzer/BUILD.gn +++ b/test/fuzztest/startcontinuation_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("StartContinuationFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "ffrt:libffrt", ] } diff --git a/test/fuzztest/startrenderprocess_fuzzer/BUILD.gn b/test/fuzztest/startrenderprocess_fuzzer/BUILD.gn index 7bc32dc2a5..42e7191bc7 100755 --- a/test/fuzztest/startrenderprocess_fuzzer/BUILD.gn +++ b/test/fuzztest/startrenderprocess_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("StartRenderProcessFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/startspecifiedability_fuzzer/BUILD.gn b/test/fuzztest/startspecifiedability_fuzzer/BUILD.gn index fcae69efb0..c418e2de5a 100755 --- a/test/fuzztest/startspecifiedability_fuzzer/BUILD.gn +++ b/test/fuzztest/startspecifiedability_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("StartSpecifiedAbilityFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/startupresidentprocess_fuzzer/BUILD.gn b/test/fuzztest/startupresidentprocess_fuzzer/BUILD.gn index f4a87a237b..49f47446d0 100755 --- a/test/fuzztest/startupresidentprocess_fuzzer/BUILD.gn +++ b/test/fuzztest/startupresidentprocess_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("StartupResidentProcessFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/startusertest_fuzzer/startusertest_fuzzer.cpp b/test/fuzztest/startusertest_fuzzer/startusertest_fuzzer.cpp index 22b9291796..3931ce7129 100755 --- a/test/fuzztest/startusertest_fuzzer/startusertest_fuzzer.cpp +++ b/test/fuzztest/startusertest_fuzzer/startusertest_fuzzer.cpp @@ -24,8 +24,6 @@ #include "iremote_object.h" #include "bundle_info.h" #include "app_launch_data.h" -#include "app_running_record.h" -#include "app_running_manager.h" #include "test_observer.h" using namespace OHOS::AAFwk; diff --git a/test/fuzztest/startusertestprocess_fuzzer/BUILD.gn b/test/fuzztest/startusertestprocess_fuzzer/BUILD.gn index e7a198122b..9eab3fb682 100755 --- a/test/fuzztest/startusertestprocess_fuzzer/BUILD.gn +++ b/test/fuzztest/startusertestprocess_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("StartUserTestProcessFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/terminateability_fuzzer/BUILD.gn b/test/fuzztest/terminateability_fuzzer/BUILD.gn index 07126a489e..36854687b1 100755 --- a/test/fuzztest/terminateability_fuzzer/BUILD.gn +++ b/test/fuzztest/terminateability_fuzzer/BUILD.gn @@ -55,6 +55,7 @@ ohos_fuzztest("TerminateAbilityFuzzTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", + "ffrt:libffrt", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/terminateabilityresult_fuzzer/BUILD.gn b/test/fuzztest/terminateabilityresult_fuzzer/BUILD.gn index 81eee679cf..d774235f22 100644 --- a/test/fuzztest/terminateabilityresult_fuzzer/BUILD.gn +++ b/test/fuzztest/terminateabilityresult_fuzzer/BUILD.gn @@ -52,6 +52,7 @@ ohos_fuzztest("TerminateAbilityResultFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/unregisterapplicationstateobserver_fuzzer/BUILD.gn b/test/fuzztest/unregisterapplicationstateobserver_fuzzer/BUILD.gn index b126b307ce..4f6899f0fc 100644 --- a/test/fuzztest/unregisterapplicationstateobserver_fuzzer/BUILD.gn +++ b/test/fuzztest/unregisterapplicationstateobserver_fuzzer/BUILD.gn @@ -37,6 +37,7 @@ ohos_fuzztest("UnregisterApplicationStateObserverFuzzTest") { deps = [ "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", ] external_deps = [ @@ -46,7 +47,7 @@ ohos_fuzztest("UnregisterApplicationStateObserverFuzzTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", diff --git a/test/fuzztest/updateabilitystate_fuzzer/BUILD.gn b/test/fuzztest/updateabilitystate_fuzzer/BUILD.gn index 8e875ee9f9..20eacc90ca 100755 --- a/test/fuzztest/updateabilitystate_fuzzer/BUILD.gn +++ b/test/fuzztest/updateabilitystate_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("UpdateAbilityStateFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/updateextensionstate_fuzzer/BUILD.gn b/test/fuzztest/updateextensionstate_fuzzer/BUILD.gn index 515eacc59a..066c1d170b 100755 --- a/test/fuzztest/updateextensionstate_fuzzer/BUILD.gn +++ b/test/fuzztest/updateextensionstate_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("UpdateExtensionStateFuzzTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/test/fuzztest/updatemissionsnapshot_fuzzer/BUILD.gn b/test/fuzztest/updatemissionsnapshot_fuzzer/BUILD.gn index becbf4e789..05fd9bac8d 100644 --- a/test/fuzztest/updatemissionsnapshot_fuzzer/BUILD.gn +++ b/test/fuzztest/updatemissionsnapshot_fuzzer/BUILD.gn @@ -52,7 +52,7 @@ ohos_fuzztest("UpdateMissionSnapShotFuzzTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "ipc:ipc_core", "relational_store:native_dataability", "relational_store:native_rdb", diff --git a/test/mock/services_abilitymgr_test/appmgr_test_service/BUILD.gn b/test/mock/services_abilitymgr_test/appmgr_test_service/BUILD.gn index 1dfd402843..2f8fb950a4 100644 --- a/test/mock/services_abilitymgr_test/appmgr_test_service/BUILD.gn +++ b/test/mock/services_abilitymgr_test/appmgr_test_service/BUILD.gn @@ -54,7 +54,7 @@ ohos_source_set("appmgr_test_service") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/mock/services_abilitymgr_test/libs/aakit/BUILD.gn b/test/mock/services_abilitymgr_test/libs/aakit/BUILD.gn index 20688ff9ec..bc5f138fc9 100644 --- a/test/mock/services_abilitymgr_test/libs/aakit/BUILD.gn +++ b/test/mock/services_abilitymgr_test/libs/aakit/BUILD.gn @@ -52,7 +52,7 @@ ohos_source_set("aakit_mock") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] 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 c2a39fa88e..e002971e4c 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 @@ -18,7 +18,6 @@ #include "hilog_wrapper.h" #include "ability_util.h" #include "ability_manager_errors.h" -#include "ability_record.h" #include "appmgr/app_mgr_constants.h" namespace OHOS { diff --git a/test/moduletest/ability_manager_service_dump_test/BUILD.gn b/test/moduletest/ability_manager_service_dump_test/BUILD.gn index 39d04c9d2d..ea187be132 100644 --- a/test/moduletest/ability_manager_service_dump_test/BUILD.gn +++ b/test/moduletest/ability_manager_service_dump_test/BUILD.gn @@ -61,7 +61,7 @@ ohos_moduletest("ability_manager_service_dump_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/moduletest/ability_record_test/BUILD.gn b/test/moduletest/ability_record_test/BUILD.gn index 3e503c95d0..532bf20d43 100644 --- a/test/moduletest/ability_record_test/BUILD.gn +++ b/test/moduletest/ability_record_test/BUILD.gn @@ -75,7 +75,7 @@ ohos_moduletest("AbilityRecordModuleTest") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/moduletest/ability_timeout_module_test/BUILD.gn b/test/moduletest/ability_timeout_module_test/BUILD.gn index 66cc484f5a..12c195c12e 100644 --- a/test/moduletest/ability_timeout_module_test/BUILD.gn +++ b/test/moduletest/ability_timeout_module_test/BUILD.gn @@ -28,6 +28,8 @@ ohos_moduletest("ability_timeout_module_test") { sources = [ "ability_timeout_module_test.cpp" ] sources += [ + "${ability_runtime_services_path}/abilitymgr/src/ability_bundle_event_callback.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_service.cpp", "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", @@ -54,6 +56,7 @@ ohos_moduletest("ability_timeout_module_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gmock_main", @@ -83,7 +86,7 @@ ohos_moduletest("ability_timeout_module_test") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", @@ -122,5 +125,7 @@ ohos_moduletest("ability_timeout_module_test") { group("moduletest") { testonly = true - deps = [ ":ability_timeout_module_test" ] + deps = [ + # ":ability_timeout_module_test" + ] } diff --git a/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp b/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp index 221c57389d..908c856088 100644 --- a/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp +++ b/test/moduletest/ability_timeout_module_test/ability_timeout_module_test.cpp @@ -49,10 +49,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -68,11 +68,11 @@ static void WaitUntilTaskFinishedByTimer() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; int sleepingTime = 5000; - if (handler->PostTask(f, "AbilityManagerServiceTest", sleepingTime)) { + if (handler->SubmitTask(f, "AbilityManagerServiceTest", sleepingTime)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -121,7 +121,6 @@ void AbilityTimeoutModuleTest::SetUp() void AbilityTimeoutModuleTest::TearDown() { WaitUntilTaskFinishedByTimer(); - abilityMs_->handler_->RemoveAllEvents(); abilityMs_->currentMissionListManager_->terminateAbilityList_.clear(); abilityMs_->currentMissionListManager_->launcherList_->missions_.clear(); abilityMs_->currentMissionListManager_->defaultStandardList_->missions_.clear(); @@ -140,10 +139,8 @@ void AbilityTimeoutModuleTest::MockOnStart() if (abilityMs_->state_ == ServiceRunningState::STATE_RUNNING) { return; } - abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - abilityMs_->handler_ = std::make_shared(abilityMs_->eventLoop_, abilityMs_); - EXPECT_TRUE(abilityMs_->handler_); - EXPECT_TRUE(abilityMs_->eventLoop_); + abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + EXPECT_TRUE(abilityMs_->taskHandler_); // init user controller. abilityMs_->userController_ = std::make_shared(); @@ -166,7 +163,6 @@ void AbilityTimeoutModuleTest::MockOnStart() abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; abilityMs_->iBundleManager_ = new BundleMgrService(); - abilityMs_->eventLoop_->Run(); WaitUntilTaskFinished(); } @@ -180,7 +176,6 @@ void AbilityTimeoutModuleTest::MockOnStop() return; } - abilityMs_->handler_->RemoveAllEvents(); abilityMs_->connectManagers_.clear(); abilityMs_->connectManager_.reset(); abilityMs_->iBundleManager_.clear(); diff --git a/test/moduletest/call_module_test/BUILD.gn b/test/moduletest/call_module_test/BUILD.gn index 3012aa24d2..76a743ad38 100644 --- a/test/moduletest/call_module_test/BUILD.gn +++ b/test/moduletest/call_module_test/BUILD.gn @@ -42,6 +42,7 @@ ohos_moduletest("call_ability_service_module_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -60,7 +61,7 @@ ohos_moduletest("call_ability_service_module_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/moduletest/call_module_test/call_ability_service_module_test.cpp b/test/moduletest/call_module_test/call_ability_service_module_test.cpp index afa5771bdb..85279146b3 100644 --- a/test/moduletest/call_module_test/call_ability_service_module_test.cpp +++ b/test/moduletest/call_module_test/call_ability_service_module_test.cpp @@ -51,10 +51,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -127,13 +127,11 @@ void AbilityManagerServiceTest::OnStartAms() abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; - abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - EXPECT_TRUE(abilityMs_->eventLoop_); - - abilityMs_->handler_ = std::make_shared(abilityMs_->eventLoop_, abilityMs_); + abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler("AbilityManagerServiceTest"); + abilityMs_->eventHandler_ = std::make_shared(abilityMs_->taskHandler_, abilityMs_); abilityMs_->connectManager_ = std::make_shared(0); abilityMs_->connectManagers_.emplace(0, abilityMs_->connectManager_); - EXPECT_TRUE(abilityMs_->handler_); + EXPECT_TRUE(abilityMs_->taskHandler_); EXPECT_TRUE(abilityMs_->connectManager_); abilityMs_->dataAbilityManager_ = std::make_shared(); @@ -147,7 +145,6 @@ void AbilityManagerServiceTest::OnStartAms() abilityMs_->currentMissionListManager_ = std::make_shared(0); abilityMs_->currentMissionListManager_->Init(); - abilityMs_->eventLoop_->Run(); return; } diff --git a/test/moduletest/common/ams/BUILD.gn b/test/moduletest/common/ams/BUILD.gn index 885cd63f12..13dc002575 100644 --- a/test/moduletest/common/ams/BUILD.gn +++ b/test/moduletest/common/ams/BUILD.gn @@ -43,7 +43,10 @@ ohos_source_set("appmgr_mst_source") { if (target_cpu == "arm") { cflags += [ "-DBINDER_IPC_32BIT" ] } - deps = [ "${ability_runtime_services_path}/appmgr:libappms" ] + deps = [ + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", + ] public_deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/app_manager:app_manager", @@ -68,7 +71,7 @@ ohos_source_set("appmgr_mst_source") { "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn index 3ce601fb82..796b5fbe68 100644 --- a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn +++ b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn @@ -29,6 +29,7 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") { external_deps = [ "bundle_framework:appexecfwk_base", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/moduletest/common/ams/app_life_cycle_test/BUILD.gn b/test/moduletest/common/ams/app_life_cycle_test/BUILD.gn index c035265f7d..582a14bb1b 100644 --- a/test/moduletest/common/ams/app_life_cycle_test/BUILD.gn +++ b/test/moduletest/common/ams/app_life_cycle_test/BUILD.gn @@ -32,6 +32,7 @@ ohos_moduletest("AmsAppLifeCycleModuleTest") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] @@ -40,6 +41,7 @@ ohos_moduletest("AmsAppLifeCycleModuleTest") { "access_token:libnativetoken", "access_token:libtoken_setproc", "bundle_framework:appexecfwk_base", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", @@ -52,5 +54,7 @@ ohos_moduletest("AmsAppLifeCycleModuleTest") { group("moduletest") { testonly = true - deps = [ ":AmsAppLifeCycleModuleTest" ] + deps = [ + # ":AmsAppLifeCycleModuleTest" + ] } diff --git a/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp b/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp index 455492422c..6754262fc8 100644 --- a/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp +++ b/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp @@ -136,8 +136,9 @@ void AmsAppLifeCycleModuleTest::SetUp() mockBundleMgr = new (std::nothrow) BundleMgrService(); serviceInner_->SetBundleManager(mockBundleMgr); - auto runner = EventRunner::Create("AmsAppLifeCycleModuleTest"); - handler_ = std::make_shared(runner, serviceInner_); + auto taskHandler = AAFwk::TaskHandlerWrap::CreateQueueHandler("AmsAppLifeCycleModuleTest"); + handler_ = std::make_shared(taskHandler, serviceInner_); + serviceInner_->SetTaskHandler(taskHandler); serviceInner_->SetEventHandler(handler_); } diff --git a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn index ae38b3ff80..07333fa082 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn +++ b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn @@ -41,6 +41,7 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { "access_token:libnativetoken", "access_token:libtoken_setproc", "bundle_framework:appexecfwk_base", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn index e2c0cbf6df..c5db6ccc0b 100644 --- a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn +++ b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn @@ -25,11 +25,13 @@ ohos_moduletest("AmsAppRecentListModuleTest") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] external_deps = [ "bundle_framework:appexecfwk_base", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn b/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn index 44f531cb91..20383ef411 100644 --- a/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn +++ b/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn @@ -36,6 +36,7 @@ ohos_moduletest("AppRunningProcessesInfoModuleTest") { "access_token:libnativetoken", "access_token:libtoken_setproc", "bundle_framework:appexecfwk_base", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "window_manager:libwm", diff --git a/test/moduletest/common/ams/app_running_record_test/BUILD.gn b/test/moduletest/common/ams/app_running_record_test/BUILD.gn index 750207017c..5a4433d4cb 100644 --- a/test/moduletest/common/ams/app_running_record_test/BUILD.gn +++ b/test/moduletest/common/ams/app_running_record_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_moduletest("AmsAppRunningRecordModuleTest") { ] external_deps = [ + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn index 76e91fa9b9..5e049a6263 100644 --- a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn +++ b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn @@ -27,11 +27,13 @@ ohos_moduletest("AmsAppServiceFlowModuleTest") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] external_deps = [ "bundle_framework:appexecfwk_base", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp b/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp index 4a0986558a..0bf4d13755 100644 --- a/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp +++ b/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp @@ -88,8 +88,9 @@ void AmsAppServiceFlowModuleTest::SetUp() serviceInner_.reset(new (std::nothrow) AppMgrServiceInner()); serviceInner_->Init(); - auto runner = EventRunner::Create("AmsAppServiceFlowModuleTest"); - handler_ = std::make_shared(runner, serviceInner_); + auto taskHandler = AAFwk::TaskHandlerWrap::CreateQueueHandler("AmsAppServiceFlowModuleTest"); + handler_ = std::make_shared(taskHandler, serviceInner_); + serviceInner_->SetTaskHandler(taskHandler); serviceInner_->SetEventHandler(handler_); mockBundleMgr_ = new (std::nothrow) BundleMgrService(); serviceInner_->SetBundleManager(mockBundleMgr_); diff --git a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn index af8e357bc8..cb90abad92 100644 --- a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn @@ -31,6 +31,7 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { deps = [ "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -39,7 +40,7 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { "access_token:libnativetoken", "access_token:libtoken_setproc", "bundle_framework:appexecfwk_base", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/moduletest/common/ams/ipc_ams_mgr_test/ams_ipc_ams_mgr_module_test.cpp b/test/moduletest/common/ams/ipc_ams_mgr_test/ams_ipc_ams_mgr_module_test.cpp index a8df0a1f31..923d4d4df6 100644 --- a/test/moduletest/common/ams/ipc_ams_mgr_test/ams_ipc_ams_mgr_module_test.cpp +++ b/test/moduletest/common/ams/ipc_ams_mgr_test/ams_ipc_ams_mgr_module_test.cpp @@ -61,7 +61,7 @@ public: } std::shared_ptr GetMockAppMgrServiceInner(); - std::shared_ptr GetAmsEventHandler(); + std::shared_ptr GetAmsTaskHandler(); protected: sptr mockToken_ = nullptr; @@ -69,7 +69,7 @@ protected: std::unique_ptr client_{ nullptr }; std::shared_ptr mockAppMgrServiceInner_{ nullptr }; - std::shared_ptr amsEventHandler_{ nullptr }; + std::shared_ptr amsTaskHandler_; }; class MockMockAppMgrService : public MockAppMgrService { @@ -95,7 +95,7 @@ void AmsIpcAmsmgrModuleTest::SetUp() void AmsIpcAmsmgrModuleTest::TearDown() { - amsEventHandler_.reset(); + amsTaskHandler_.reset(); mockAppMgrServiceInner_.reset(); } @@ -123,14 +123,12 @@ std::shared_ptr AmsIpcAmsmgrModuleTest::GetMockAppMgrSer return mockAppMgrServiceInner_; } -std::shared_ptr AmsIpcAmsmgrModuleTest::GetAmsEventHandler() +std::shared_ptr AmsIpcAmsmgrModuleTest::GetAmsTaskHandler() { - if (!amsEventHandler_) { - auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - amsEventHandler_ = - std::make_shared(EventRunner::Create("AmsMgrSchedulerTest"), mockAppMgrServiceInner); + if (!amsTaskHandler_) { + amsTaskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("AmsMgrSchedulerTest"); } - return amsEventHandler_; + return amsTaskHandler_; } /* @@ -144,9 +142,8 @@ std::shared_ptr AmsIpcAmsmgrModuleTest::GetAmsEventHandler() HWTEST_F(AmsIpcAmsmgrModuleTest, ExcuteAmsmgrIPCInterface_002, TestSize.Level3) { auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); sptr mockMockAppMgr(new MockMockAppMgrService()); sptr appMgrClient = iface_cast(mockMockAppMgr); @@ -184,9 +181,8 @@ HWTEST_F(AmsIpcAmsmgrModuleTest, ExcuteAmsmgrIPCInterface_002, TestSize.Level3) HWTEST_F(AmsIpcAmsmgrModuleTest, ExcuteAmsmgrIPCInterface_003, TestSize.Level3) { auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); sptr mockMockAppMgr(new MockMockAppMgrService()); sptr appMgrClient = iface_cast(mockMockAppMgr); @@ -226,9 +222,8 @@ HWTEST_F(AmsIpcAmsmgrModuleTest, ExcuteAmsmgrIPCInterface_003, TestSize.Level3) HWTEST_F(AmsIpcAmsmgrModuleTest, ExcuteAmsmgrIPCInterface_004, TestSize.Level3) { auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); sptr callback = new MockAppStateCallback(); sptr mockMockAppMgr(new MockMockAppMgrService()); @@ -270,9 +265,8 @@ HWTEST_F(AmsIpcAmsmgrModuleTest, ExcuteAmsmgrIPCInterface_005, TestSize.Level3) const int32_t connectionState = 1; auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); sptr mockMockAppMgr(new MockMockAppMgrService()); sptr appMgrClient = iface_cast(mockMockAppMgr); @@ -311,9 +305,8 @@ HWTEST_F(AmsIpcAmsmgrModuleTest, ExcuteAmsmgrIPCInterface_006, TestSize.Level3) { const std::string bundleName = "p1"; auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); sptr mockMockAppMgr(new MockMockAppMgrService()); sptr appMgrClient = iface_cast(mockMockAppMgr); @@ -350,9 +343,8 @@ HWTEST_F(AmsIpcAmsmgrModuleTest, ExcuteAmsmgrIPCInterface_006, TestSize.Level3) HWTEST_F(AmsIpcAmsmgrModuleTest, ExcuteAmsmgrIPCInterface_007, TestSize.Level3) { auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); sptr mockMockAppMgr(new MockMockAppMgrService()); sptr appMgrClient = iface_cast(mockMockAppMgr); diff --git a/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn b/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn index 287b07175e..24081c234e 100644 --- a/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn +++ b/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_moduletest("AmsServiceAppSpawnClientModuleTest") { external_deps = [ "bundle_framework:appexecfwk_base", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/moduletest/common/ams/service_event_drive_test/BUILD.gn b/test/moduletest/common/ams/service_event_drive_test/BUILD.gn index 624c9c6217..06aa47c4ac 100644 --- a/test/moduletest/common/ams/service_event_drive_test/BUILD.gn +++ b/test/moduletest/common/ams/service_event_drive_test/BUILD.gn @@ -42,6 +42,7 @@ ohos_moduletest("AmsServiceEventDriveModuleTest") { "access_token:libnativetoken", "access_token:libtoken_setproc", "bundle_framework:appexecfwk_base", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", @@ -56,5 +57,7 @@ ohos_moduletest("AmsServiceEventDriveModuleTest") { group("moduletest") { testonly = true - deps = [ ":AmsServiceEventDriveModuleTest" ] + deps = [ + # ":AmsServiceEventDriveModuleTest" + ] } diff --git a/test/moduletest/common/ams/service_start_process_test/BUILD.gn b/test/moduletest/common/ams/service_start_process_test/BUILD.gn index 02f065ee41..13afd4e34f 100644 --- a/test/moduletest/common/ams/service_start_process_test/BUILD.gn +++ b/test/moduletest/common/ams/service_start_process_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_moduletest("AmsServiceStartModuleTest") { external_deps = [ "bundle_framework:appexecfwk_base", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", diff --git a/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn b/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn index 3c31b255fb..58c395f65c 100644 --- a/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn +++ b/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn @@ -28,6 +28,8 @@ ohos_moduletest("specified_ability_service_test") { sources = [ "specified_ability_service_test.cpp" ] sources += [ + "${ability_runtime_services_path}/abilitymgr/src/ability_bundle_event_callback.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_service.cpp", "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", @@ -55,6 +57,7 @@ ohos_moduletest("specified_ability_service_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gmock_main", @@ -83,7 +86,7 @@ ohos_moduletest("specified_ability_service_test") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp b/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp index 25d4743043..582bb88d2c 100644 --- a/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp +++ b/test/moduletest/common/ams/specified_ability_service_test/specified_ability_service_test.cpp @@ -127,13 +127,13 @@ void SpecifiedAbilityServiceTest::WaitAMS() if (!abilityMgrServ_) { return; } - auto handler = abilityMgrServ_->GetEventHandler(); + auto handler = abilityMgrServ_->GetTaskHandler(); if (!handler) { return; } std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { diff --git a/test/moduletest/ipc_ability_mgr_test/BUILD.gn b/test/moduletest/ipc_ability_mgr_test/BUILD.gn index 84804b4afb..8c60de8dc4 100644 --- a/test/moduletest/ipc_ability_mgr_test/BUILD.gn +++ b/test/moduletest/ipc_ability_mgr_test/BUILD.gn @@ -45,6 +45,7 @@ ohos_moduletest("IpcAbilityMgrServiceModuleTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/moduletest/mission_dump_test/BUILD.gn b/test/moduletest/mission_dump_test/BUILD.gn index 322b79a9d8..b0c13b8399 100644 --- a/test/moduletest/mission_dump_test/BUILD.gn +++ b/test/moduletest/mission_dump_test/BUILD.gn @@ -58,7 +58,7 @@ ohos_moduletest("mission_dump_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/moduletest/on_new_want_module_test/BUILD.gn b/test/moduletest/on_new_want_module_test/BUILD.gn index 48de88c394..d65a0b6be0 100644 --- a/test/moduletest/on_new_want_module_test/BUILD.gn +++ b/test/moduletest/on_new_want_module_test/BUILD.gn @@ -28,6 +28,8 @@ ohos_moduletest("on_new_want_module_test") { sources = [ "on_new_want_module_test.cpp" ] sources += [ + "${ability_runtime_services_path}/abilitymgr/src/ability_bundle_event_callback.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_service.cpp", "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", @@ -52,6 +54,7 @@ ohos_moduletest("on_new_want_module_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gmock_main", @@ -80,7 +83,7 @@ ohos_moduletest("on_new_want_module_test") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/moduletest/panding_want_manager_test/BUILD.gn b/test/moduletest/panding_want_manager_test/BUILD.gn index 8cc3ba433d..819e55136e 100644 --- a/test/moduletest/panding_want_manager_test/BUILD.gn +++ b/test/moduletest/panding_want_manager_test/BUILD.gn @@ -68,7 +68,7 @@ ohos_moduletest("PandingWantMgrTest") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/moduletest/running_infos_module_test/BUILD.gn b/test/moduletest/running_infos_module_test/BUILD.gn index 8e92c55dd3..853262b613 100644 --- a/test/moduletest/running_infos_module_test/BUILD.gn +++ b/test/moduletest/running_infos_module_test/BUILD.gn @@ -29,6 +29,8 @@ ohos_moduletest("running_infos_module_test") { sources = [ "running_infos_module_test.cpp" ] sources += [ + "${ability_runtime_services_path}/abilitymgr/src/ability_bundle_event_callback.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_service.cpp", "${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp", @@ -56,6 +58,7 @@ ohos_moduletest("running_infos_module_test") { "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gmock_main", @@ -88,6 +91,7 @@ ohos_moduletest("running_infos_module_test") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", @@ -127,5 +131,7 @@ ohos_moduletest("running_infos_module_test") { group("moduletest") { testonly = true - deps = [ ":running_infos_module_test" ] + deps = [ + # ":running_infos_module_test" + ] } diff --git a/test/moduletest/running_infos_module_test/running_infos_module_test.cpp b/test/moduletest/running_infos_module_test/running_infos_module_test.cpp index 94e95efba3..8af9520c3b 100644 --- a/test/moduletest/running_infos_module_test/running_infos_module_test.cpp +++ b/test/moduletest/running_infos_module_test/running_infos_module_test.cpp @@ -64,10 +64,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -112,11 +112,8 @@ void RunningInfosModuleTest::OnStartAms() abilityMgrServ_->state_ = ServiceRunningState::STATE_RUNNING; - abilityMgrServ_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - EXPECT_TRUE(abilityMgrServ_->eventLoop_); - - abilityMgrServ_->handler_ = std::make_shared(abilityMgrServ_->eventLoop_, abilityMgrServ_); - EXPECT_TRUE(abilityMgrServ_->handler_); + abilityMgrServ_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + EXPECT_TRUE(abilityMgrServ_->taskHandler_); // init user controller. abilityMgrServ_->userController_ = std::make_shared(); @@ -136,8 +133,7 @@ void RunningInfosModuleTest::OnStartAms() EXPECT_TRUE(abilityMgrServ_->interceptorExecuter_); abilityMgrServ_->InitMissionListManager(userId, true); - abilityMgrServ_->connectManager_->SetEventHandler(abilityMgrServ_->handler_); - abilityMgrServ_->eventLoop_->Run(); + abilityMgrServ_->connectManager_->SetTaskHandler(abilityMgrServ_->taskHandler_); auto topAbility = abilityMgrServ_->GetListManagerByUserId(MOCK_MAIN_USER_ID)->GetCurrentTopAbilityLocked(); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); @@ -151,8 +147,7 @@ void RunningInfosModuleTest::OnStartAms() void RunningInfosModuleTest::OnStopAms() { - abilityMgrServ_->eventLoop_.reset(); - abilityMgrServ_->handler_.reset(); + abilityMgrServ_->taskHandler_.reset(); abilityMgrServ_->state_ = ServiceRunningState::STATE_NOT_START; } diff --git a/test/moduletest/start_ability_implicit_module_test/BUILD.gn b/test/moduletest/start_ability_implicit_module_test/BUILD.gn index e369c9247b..42ac1708ef 100644 --- a/test/moduletest/start_ability_implicit_module_test/BUILD.gn +++ b/test/moduletest/start_ability_implicit_module_test/BUILD.gn @@ -54,6 +54,7 @@ ohos_moduletest("start_ability_implicit_module_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gmock_main", @@ -82,6 +83,7 @@ ohos_moduletest("start_ability_implicit_module_test") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp b/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp index 6600d5bfc9..441385b28f 100644 --- a/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp +++ b/test/moduletest/start_ability_implicit_module_test/start_ability_implicit_module_test.cpp @@ -48,10 +48,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -85,9 +85,7 @@ void StartAbilityImplicitModuleTest::OnStartAms() const } abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; - abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - EXPECT_TRUE(abilityMs_->eventLoop_); - abilityMs_->handler_ = std::make_shared(abilityMs_->eventLoop_, abilityMs_); + abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler("StartAbilityImplicitModuleTest"); // init user controller. abilityMs_->userController_ = std::make_shared(); EXPECT_TRUE(abilityMs_->userController_); @@ -115,7 +113,6 @@ void StartAbilityImplicitModuleTest::OnStartAms() const abilityMs_->InitMissionListManager(userId, true); abilityMs_->SwitchManagers(0, false); abilityMs_->userController_->SetCurrentUserId(MOCK_MAIN_USER_ID); - abilityMs_->eventLoop_->Run(); return; } diff --git a/test/moduletest/start_option_display_id_test/BUILD.gn b/test/moduletest/start_option_display_id_test/BUILD.gn index 310941b837..9ab96d674f 100644 --- a/test/moduletest/start_option_display_id_test/BUILD.gn +++ b/test/moduletest/start_option_display_id_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_moduletest("start_option_module_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -55,7 +56,7 @@ ohos_moduletest("start_option_module_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/moduletest/start_option_display_id_test/start_option_display_id_test.cpp b/test/moduletest/start_option_display_id_test/start_option_display_id_test.cpp index ab8790f2f9..7c3e5222c7 100644 --- a/test/moduletest/start_option_display_id_test/start_option_display_id_test.cpp +++ b/test/moduletest/start_option_display_id_test/start_option_display_id_test.cpp @@ -46,10 +46,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -115,11 +115,8 @@ void StartOptionDisplayIdTest::OnStartAms() abilityMgrServ_->state_ = ServiceRunningState::STATE_RUNNING; - abilityMgrServ_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - EXPECT_TRUE(abilityMgrServ_->eventLoop_); - - abilityMgrServ_->handler_ = std::make_shared(abilityMgrServ_->eventLoop_, abilityMgrServ_); - EXPECT_TRUE(abilityMgrServ_->handler_); + abilityMgrServ_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + EXPECT_TRUE(abilityMgrServ_->taskHandler_); // init user controller. abilityMgrServ_->userController_ = std::make_shared(); @@ -136,8 +133,7 @@ void StartOptionDisplayIdTest::OnStartAms() AmsConfigurationParameter::GetInstance().Parse(); abilityMgrServ_->InitMissionListManager(userId, true); - abilityMgrServ_->connectManager_->SetEventHandler(abilityMgrServ_->handler_); - abilityMgrServ_->eventLoop_->Run(); + abilityMgrServ_->connectManager_->SetTaskHandler(abilityMgrServ_->taskHandler_); WaitUntilTaskFinished(); return; @@ -148,8 +144,7 @@ void StartOptionDisplayIdTest::OnStartAms() void StartOptionDisplayIdTest::OnStopAms() { - abilityMgrServ_->eventLoop_.reset(); - abilityMgrServ_->handler_.reset(); + abilityMgrServ_->taskHandler_.reset(); abilityMgrServ_->state_ = ServiceRunningState::STATE_NOT_START; } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index bdf03faacc..88104568de 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -102,9 +102,11 @@ config("test_exception_config") { ohos_source_set("abilityms_test_source") { sources = [ + "${ability_runtime_services_path}/abilitymgr/src/ability_bundle_event_callback.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_connect_callback_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_connect_manager.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_event_handler.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ability_event_util.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_interceptor.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_interceptor_executer.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_proxy.cpp", @@ -183,6 +185,7 @@ ohos_source_set("abilityms_test_source") { "${ability_runtime_innerkits_path}/connectionobs_manager:connection_obs_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/sa_mgr:sa_mgr_mock", ] @@ -198,7 +201,7 @@ ohos_source_set("abilityms_test_source") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/unittest/ability_connect_callback_proxy_test/BUILD.gn b/test/unittest/ability_connect_callback_proxy_test/BUILD.gn index 6081c767ad..c67918e7ab 100644 --- a/test/unittest/ability_connect_callback_proxy_test/BUILD.gn +++ b/test/unittest/ability_connect_callback_proxy_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("ability_connect_callback_proxy_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_connect_callback_stub_test/BUILD.gn b/test/unittest/ability_connect_callback_stub_test/BUILD.gn index a41f65a490..c4fb47b6fa 100644 --- a/test/unittest/ability_connect_callback_stub_test/BUILD.gn +++ b/test/unittest/ability_connect_callback_stub_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("ability_connect_callback_stub_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", @@ -108,7 +108,7 @@ ohos_unittest("ability_connect_callback_recipient_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_connect_manager_test/BUILD.gn b/test/unittest/ability_connect_manager_test/BUILD.gn index a5b1e66337..8187d4f42c 100644 --- a/test/unittest/ability_connect_manager_test/BUILD.gn +++ b/test/unittest/ability_connect_manager_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_unittest("ability_connect_manager_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -60,7 +61,7 @@ ohos_unittest("ability_connect_manager_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp b/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp index 9ef5ff1a59..dd1b8919ea 100644 --- a/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp +++ b/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp @@ -14,6 +14,7 @@ */ #include +#include #define private public #define protected public @@ -26,7 +27,6 @@ #include "ability_scheduler.h" #include "ability_util.h" #include "bundlemgr/mock_bundle_manager.h" -#include "event_handler.h" #include "mock_ability_connect_callback.h" #include "sa_mgr_client.h" #include "system_ability_definition.h" @@ -37,12 +37,13 @@ using namespace OHOS::AppExecFwk; namespace OHOS { namespace AAFwk { template -static void WaitUntilTaskCalled(const F& f, const std::shared_ptr& handler, std::atomic& taskCalled) +static void WaitUntilTaskCalled(const F& f, const std::shared_ptr& handler, + std::atomic& taskCalled) { const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; // if delay more than 1 second, break @@ -54,7 +55,7 @@ static void WaitUntilTaskCalled(const F& f, const std::shared_ptr& } } -static void WaitUntilTaskDone(const std::shared_ptr& handler) +static void WaitUntilTaskDone(const std::shared_ptr& handler) { std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; @@ -69,6 +70,8 @@ public: void TearDown(); AbilityConnectManager* ConnectManager() const; + std::shared_ptr TaskHandler() const; + std::shared_ptr EventHandler() const; AbilityRequest GenerateAbilityRequest(const std::string& deviceName, const std::string& abilityName, const std::string& appName, const std::string& bundleName, const std::string& moduleName); @@ -93,6 +96,8 @@ protected: private: std::shared_ptr connectManager_; + std::shared_ptr taskHandler_; + std::shared_ptr eventHandler_; }; AbilityRequest AbilityConnectManagerTest::GenerateAbilityRequest(const std::string& deviceName, @@ -152,6 +157,8 @@ void AbilityConnectManagerTest::TearDownTestCase(void) void AbilityConnectManagerTest::SetUp(void) { connectManager_ = std::make_unique(0); + taskHandler_ = TaskHandlerWrap::CreateQueueHandler("AbilityConnectManagerTest"); + eventHandler_ = std::make_shared(taskHandler_); // generate ability request std::string deviceName = "device"; std::string abilityName = "ServiceAbility"; @@ -197,6 +204,16 @@ AbilityConnectManager* AbilityConnectManagerTest::ConnectManager() const return connectManager_.get(); } +std::shared_ptr AbilityConnectManagerTest::TaskHandler() const +{ + return taskHandler_; +} + +std::shared_ptr AbilityConnectManagerTest::EventHandler() const +{ + return eventHandler_; +} + /* * Feature: AbilityConnectManager * Function: StartAbility @@ -207,12 +224,12 @@ AbilityConnectManager* AbilityConnectManagerTest::ConnectManager() const */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_001, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result = ConnectManager()->StartAbility(abilityRequest_); EXPECT_EQ(OHOS::ERR_OK, result); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto elementName = abilityRequest_.want.GetElement().GetURI(); auto service = ConnectManager()->GetServiceRecordByElementName(elementName); @@ -222,13 +239,13 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_001, TestSize.Level1) service->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE); auto result1 = ConnectManager()->StartAbility(abilityRequest_); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(OHOS::ERR_OK, result1); EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 1); service->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVATING); auto result2 = ConnectManager()->StartAbility(abilityRequest_); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(OHOS::ERR_OK, result2); EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 1); } @@ -245,12 +262,12 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_001, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_002, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result = ConnectManager()->StartAbility(abilityRequest_); EXPECT_EQ(OHOS::ERR_OK, result); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); OHOS::sptr nullToken = nullptr; auto result1 = ConnectManager()->TerminateAbility(nullToken); @@ -261,7 +278,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_002, TestSize.Level1) EXPECT_NE(service, nullptr); auto result2 = ConnectManager()->TerminateAbility(service->GetToken()); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(OHOS::ERR_OK, result2); EXPECT_EQ(service->GetAbilityState(), TERMINATING); } @@ -276,12 +293,12 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_002, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_003, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result = ConnectManager()->StartAbility(abilityRequest_); EXPECT_EQ(OHOS::ERR_OK, result); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto elementName = abilityRequest_.want.GetElement().GetURI(); auto service = ConnectManager()->GetServiceRecordByElementName(elementName); @@ -289,7 +306,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_003, TestSize.Level1) service->SetTerminatingState(); auto result1 = ConnectManager()->TerminateAbility(service->GetToken()); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(OHOS::ERR_OK, result1); EXPECT_NE(service->GetAbilityState(), TERMINATING); } @@ -304,12 +321,12 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_003, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_004, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result = ConnectManager()->StartAbility(abilityRequest_); EXPECT_EQ(OHOS::ERR_OK, result); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto result1 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr); EXPECT_EQ(0, result1); @@ -319,7 +336,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_004, TestSize.Level1) EXPECT_NE(service, nullptr); auto result2 = ConnectManager()->TerminateAbility(service->GetToken()); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(0, result2); EXPECT_EQ(service->GetAbilityState(), TERMINATING); } @@ -336,12 +353,12 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_004, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_005, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result = ConnectManager()->StartAbility(abilityRequest_); EXPECT_EQ(OHOS::ERR_OK, result); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto elementName = abilityRequest_.want.GetElement().GetURI(); auto service = ConnectManager()->GetServiceRecordByElementName(elementName); @@ -349,11 +366,11 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_005, TestSize.Level1) AbilityRequest otherRequest; auto result1 = ConnectManager()->StopServiceAbility(otherRequest); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(OHOS::ERR_INVALID_VALUE, result1); auto result2 = ConnectManager()->StopServiceAbility(abilityRequest_); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(OHOS::ERR_OK, result2); EXPECT_EQ(service->GetAbilityState(), TERMINATING); } @@ -368,12 +385,12 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_005, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_006, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result = ConnectManager()->StartAbility(abilityRequest_); EXPECT_EQ(OHOS::ERR_OK, result); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto elementName = abilityRequest_.want.GetElement().GetURI(); auto service = ConnectManager()->GetServiceRecordByElementName(elementName); @@ -381,7 +398,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_006, TestSize.Level1) service->SetTerminatingState(); auto result1 = ConnectManager()->StopServiceAbility(abilityRequest_); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(OHOS::ERR_OK, result1); EXPECT_NE(service->GetAbilityState(), TERMINATING); } @@ -396,12 +413,12 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_006, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_007, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result = ConnectManager()->StartAbility(abilityRequest_); EXPECT_EQ(OHOS::ERR_OK, result); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto result1 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr); EXPECT_EQ(0, result1); @@ -411,7 +428,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_007, TestSize.Level1) EXPECT_NE(service, nullptr); auto result2 = ConnectManager()->StopServiceAbility(abilityRequest_); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(0, result2); EXPECT_EQ(service->GetAbilityState(), TERMINATING); } @@ -451,14 +468,14 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_008, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_009, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); int result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr); EXPECT_EQ(0, result); auto connectMap = ConnectManager()->GetConnectMap(); EXPECT_EQ(1, static_cast(connectMap.size())); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); usleep(TEST_WAIT_TIME); connectMap = ConnectManager()->GetConnectMap(); @@ -506,8 +523,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_010, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_011, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); int result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr); auto elementName = abilityRequest_.want.GetElement(); @@ -523,7 +540,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_011, TestSize.Level1) ConnectManager()->AttachAbilityThreadLocked(scheduler, token->AsObject()); ConnectManager()->AbilityTransitionDone(token->AsObject(), OHOS::AAFwk::AbilityState::INACTIVE); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); usleep(TEST_WAIT_TIME); connectMap = ConnectManager()->GetConnectMap(); EXPECT_EQ(0, result); @@ -924,8 +941,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Connect_008, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Disconnect_001, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto callback = new AbilityConnectCallback(); auto result = ConnectManager()->DisconnectAbilityLocked(callback); @@ -958,8 +975,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Disconnect_001, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Disconnect_002, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr); EXPECT_EQ(0, result); @@ -988,7 +1005,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Kit_Disconnect_002, TestSize.Level1) } auto result5 = ConnectManager()->DisconnectAbilityLocked(callbackA_); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(result5, OHOS::ERR_OK); auto serviceMap = ConnectManager()->GetServiceMap(); EXPECT_EQ(static_cast(serviceMap.size()), 2); @@ -1042,8 +1059,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_019, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_020, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); OHOS::sptr nullToken = nullptr; auto result = ConnectManager()->ScheduleDisconnectAbilityDoneLocked(nullToken); @@ -1067,7 +1084,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_020, TestSize.Level1) } auto result2 = ConnectManager()->DisconnectAbilityLocked(callbackA_); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(result2, OHOS::ERR_OK); auto result3 = ConnectManager()->ScheduleDisconnectAbilityDoneLocked(token); @@ -1089,8 +1106,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_020, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_021, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); OHOS::sptr nullToken = nullptr; auto result = ConnectManager()->ScheduleCommandAbilityDoneLocked(nullToken); @@ -1151,8 +1168,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_022, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_024, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr); EXPECT_EQ(0, result); @@ -1187,7 +1204,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_024, TestSize.Level1) auto token = abilityRecord->GetToken(); ConnectManager()->OnAbilityDied(abilityRecord, 0); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto list = abilityRecord->GetConnectRecordList(); EXPECT_EQ(static_cast(list.size()), 0); @@ -1198,7 +1215,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_024, TestSize.Level1) auto token1 = abilityRecord1->GetToken(); ConnectManager()->OnAbilityDied(abilityRecord1, 0); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto list1 = abilityRecord1->GetConnectRecordList(); EXPECT_EQ(static_cast(list1.size()), 0); } @@ -1217,8 +1234,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_025, TestSize.Level1) auto result = ConnectManager()->DispatchInactive(ability, OHOS::AAFwk::AbilityState::INACTIVATING); EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result3 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr); EXPECT_EQ(0, result3); @@ -1253,8 +1270,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_026, TestSize.Level1) auto result = ConnectManager()->DispatchInactive(ability, OHOS::AAFwk::AbilityState::INACTIVATING); EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result3 = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr); EXPECT_EQ(0, result3); @@ -1285,8 +1302,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_026, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_027, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); ConnectManager()->AddConnectDeathRecipient(nullptr); EXPECT_TRUE(ConnectManager()->recipientMap_.empty()); @@ -1309,8 +1326,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_027, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_028, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); ConnectManager()->AddConnectDeathRecipient(callbackA_); EXPECT_EQ(static_cast(ConnectManager()->recipientMap_.size()), 1); @@ -1332,15 +1349,15 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_028, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_029, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto result = ConnectManager()->ConnectAbilityLocked(abilityRequest_, callbackA_, nullptr); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(0, result); ConnectManager()->OnCallBackDied(nullptr); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto connectMap = ConnectManager()->GetConnectMap(); auto connectRecordList = connectMap.at(callbackA_->AsObject()); EXPECT_EQ(1, static_cast(connectRecordList.size())); @@ -1349,7 +1366,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_Connect_Service_029, TestSize.Level1) } ConnectManager()->OnCallBackDied(callbackA_->AsObject()); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto cMap = ConnectManager()->GetConnectMap(); connectRecordList = connectMap.at(callbackA_->AsObject()); EXPECT_EQ(1, static_cast(connectMap.size())); @@ -1524,8 +1541,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_ConnectAbilityLocked_001, Te { std::shared_ptr connectManager = std::make_shared(0); ASSERT_NE(connectManager, nullptr); - auto handler = std::make_shared(EventRunner::Create()); - connectManager->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); std::shared_ptr abilityRecord = serviceRecord_; AbilityRequest abilityRequest; sptr callerToken = abilityRecord->GetToken(); @@ -1568,6 +1585,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_AttachAbilityThreadLocked_00 sptr token = abilityRecord->GetToken(); connectManager->serviceMap_.emplace("first", abilityRecord); connectManager->eventHandler_ = nullptr; + connectManager->taskHandler_ = nullptr; int res = connectManager->AttachAbilityThreadLocked(scheduler, token); EXPECT_EQ(res, ERR_OK); } @@ -1734,7 +1752,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_CompleteCommandAbility_001, { std::shared_ptr connectManager = std::make_shared(0); std::shared_ptr abilityRecord = serviceRecord_; - connectManager->eventHandler_ = nullptr; + connectManager->taskHandler_ = nullptr; connectManager->CompleteCommandAbility(abilityRecord); EXPECT_TRUE(abilityRecord->IsAbilityState(AbilityState::ACTIVE)); } @@ -1790,7 +1808,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_GetConnectRecordListByCallba sptr callback = new AbilityConnectCallback(); connectManager->connectMap_.clear(); auto res = connectManager->GetConnectRecordListByCallback(callback); - EXPECT_EQ(res.size(), 0); + EXPECT_EQ(res.size(), 0u); } /* @@ -1983,8 +2001,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_DispatchInactive_001, TestSi int state = 0; abilityRecord->SetAbilityState(AbilityState::INACTIVATING); abilityRecord->isCreateByConnect_ = false; - auto handler = std::make_shared(EventRunner::Create()); - connectManager->SetEventHandler(handler); + connectManager->SetTaskHandler(TaskHandler()); + connectManager->SetEventHandler(EventHandler()); int res = connectManager->DispatchInactive(abilityRecord, state); EXPECT_EQ(res, ERR_OK); } @@ -2001,8 +2019,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_DispatchTerminate_001, TestS { std::shared_ptr connectManager = std::make_shared(0); std::shared_ptr abilityRecord = serviceRecord_; - auto handler = std::make_shared(EventRunner::Create()); - connectManager->SetEventHandler(handler); + connectManager->SetTaskHandler(TaskHandler()); + connectManager->SetEventHandler(EventHandler()); int res = connectManager->DispatchTerminate(abilityRecord); EXPECT_EQ(res, ERR_OK); } @@ -2370,8 +2388,8 @@ HWTEST_F(AbilityConnectManagerTest, AAFwk_AbilityMS_StopAllExtensions_001, TestS */ HWTEST_F(AbilityConnectManagerTest, AAFWK_IsAbilityNeedKeepAlive_001, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); // mock bms return EXPECT_TRUE(ConnectManager()->IsAbilityNeedKeepAlive(serviceRecord2_)); @@ -2388,23 +2406,23 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_IsAbilityNeedKeepAlive_001, TestSize.L */ HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_001, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); int userId = 0; auto result = ConnectManager()->StartAbility(abilityRequest_); EXPECT_EQ(OHOS::ERR_OK, result); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto elementName = abilityRequest_.want.GetElement().GetURI(); std::shared_ptr service = ConnectManager()->GetServiceRecordByElementName(elementName); EXPECT_NE(service, nullptr); EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 1); - + // HandleTerminate ConnectManager()->OnAbilityDied(service, userId); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 0); } @@ -2419,20 +2437,20 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_001, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_002, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); int userId = 0; auto result = ConnectManager()->StartAbility(abilityRequest2_); EXPECT_EQ(OHOS::ERR_OK, result); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto elementName = abilityRequest2_.want.GetElement().GetURI(); auto service = ConnectManager()->GetServiceRecordByElementName(elementName); EXPECT_NE(service, nullptr); EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 1); - + // HandleTerminate ConnectManager()->HandleAbilityDiedTask(service, userId); EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 1); @@ -2449,15 +2467,15 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_002, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_003, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); int userId = 0; auto result = ConnectManager()->StartAbility(abilityRequest2_); EXPECT_EQ(OHOS::ERR_OK, result); - WaitUntilTaskDone(handler); - + WaitUntilTaskDone(TaskHandler()); + auto elementName = abilityRequest2_.want.GetElement().GetURI(); std::shared_ptr service = ConnectManager()->GetServiceRecordByElementName(elementName); EXPECT_NE(service, nullptr); @@ -2465,7 +2483,7 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_003, TestSize.Level1) // set the over interval time according the config; without init config, the interval time is 0. // ensure now - restartTime < intervalTime service->SetRestartTime(AbilityUtil::SystemTimeMillis() + 1000); - + // HandleTerminate ConnectManager()->HandleAbilityDiedTask(service, userId); EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 0); @@ -2482,11 +2500,11 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_RestartAbility_003, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AAFWK_PostRestartResidentTask_001, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); ConnectManager()->PostRestartResidentTask(abilityRequest2_); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 0); } @@ -2500,15 +2518,15 @@ HWTEST_F(AbilityConnectManagerTest, AAFWK_PostRestartResidentTask_001, TestSize. */ HWTEST_F(AbilityConnectManagerTest, AAFWK_Start_Service_With_SessionInfo_001, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto sessionInfo = MockSessionInfo(0); abilityRequest_.sessionInfo = sessionInfo; auto result = ConnectManager()->StartAbility(abilityRequest_); EXPECT_EQ(OHOS::ERR_OK, result); abilityRequest_.sessionInfo = nullptr; - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); auto service = ConnectManager()->GetUIExtensioBySessionInfo(sessionInfo); EXPECT_EQ(static_cast(ConnectManager()->GetServiceMap().size()), 1); @@ -2912,8 +2930,8 @@ HWTEST_F(AbilityConnectManagerTest, OnAbilityRequestDone_001, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, ScheduleCommandAbilityWindowDone_001, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); auto sessionInfo = MockSessionInfo(0); sptr nullToken = nullptr; @@ -2975,8 +2993,8 @@ HWTEST_F(AbilityConnectManagerTest, DispatchForeground_001, TestSize.Level1) result = connectManager->DispatchForeground(serviceRecord_); EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); - auto handler = std::make_shared(EventRunner::Create()); - connectManager->SetEventHandler(handler); + connectManager->SetTaskHandler(TaskHandler()); + connectManager->SetEventHandler(EventHandler()); result = connectManager->DispatchForeground(serviceRecord_); EXPECT_EQ(result, OHOS::ERR_OK); } @@ -3001,8 +3019,8 @@ HWTEST_F(AbilityConnectManagerTest, DispatchBackground_001, TestSize.Level1) result = connectManager->DispatchBackground(serviceRecord_); EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); - auto handler = std::make_shared(EventRunner::Create()); - connectManager->SetEventHandler(handler); + connectManager->SetTaskHandler(TaskHandler()); + connectManager->SetEventHandler(EventHandler()); result = connectManager->DispatchBackground(serviceRecord_); EXPECT_EQ(result, OHOS::ERR_OK); } @@ -3036,8 +3054,8 @@ HWTEST_F(AbilityConnectManagerTest, CommandAbilityWindow_001, TestSize.Level1) { std::shared_ptr connectManager = std::make_shared(0); ASSERT_NE(connectManager, nullptr); - auto handler = std::make_shared(EventRunner::Create()); - connectManager->SetEventHandler(handler); + connectManager->SetTaskHandler(TaskHandler()); + connectManager->SetEventHandler(EventHandler()); connectManager->CommandAbilityWindow(serviceRecord_, MockSessionInfo(0), WIN_CMD_FOREGROUND); } @@ -3076,8 +3094,8 @@ HWTEST_F(AbilityConnectManagerTest, CompleteForeground_001, TestSize.Level1) */ HWTEST_F(AbilityConnectManagerTest, AddUIExtWindowDeathRecipient_001, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); ConnectManager()->uiExtRecipientMap_.clear(); ConnectManager()->AddUIExtWindowDeathRecipient(nullptr); @@ -3103,8 +3121,8 @@ HWTEST_F(AbilityConnectManagerTest, AddUIExtWindowDeathRecipient_001, TestSize.L */ HWTEST_F(AbilityConnectManagerTest, RemoveUIExtWindowDeathRecipient_001, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); ConnectManager()->uiExtRecipientMap_.clear(); ConnectManager()->AddUIExtWindowDeathRecipient(callbackA_->AsObject()); @@ -3128,8 +3146,8 @@ HWTEST_F(AbilityConnectManagerTest, RemoveUIExtWindowDeathRecipient_001, TestSiz */ HWTEST_F(AbilityConnectManagerTest, OnUIExtWindowDied_001, TestSize.Level1) { - auto handler = std::make_shared(EventRunner::Create()); - ConnectManager()->SetEventHandler(handler); + ConnectManager()->SetTaskHandler(TaskHandler()); + ConnectManager()->SetEventHandler(EventHandler()); ConnectManager()->uiExtRecipientMap_.clear(); ConnectManager()->uiExtensionMap_.clear(); @@ -3137,12 +3155,12 @@ HWTEST_F(AbilityConnectManagerTest, OnUIExtWindowDied_001, TestSize.Level1) callbackA_->AsObject(), AbilityConnectManager::UIExtWindowMapValType(serviceRecord_, MockSessionInfo(0))); ConnectManager()->AddUIExtWindowDeathRecipient(callbackA_->AsObject()); ConnectManager()->OnUIExtWindowDied(nullptr); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_EQ(static_cast(ConnectManager()->uiExtRecipientMap_.size()), 1); EXPECT_EQ(static_cast(ConnectManager()->uiExtensionMap_.size()), 1); ConnectManager()->OnUIExtWindowDied(callbackA_->AsObject()); - WaitUntilTaskDone(handler); + WaitUntilTaskDone(TaskHandler()); EXPECT_TRUE(ConnectManager()->uiExtRecipientMap_.empty()); EXPECT_TRUE(ConnectManager()->uiExtensionMap_.empty()); } diff --git a/test/unittest/ability_event_handler_test/BUILD.gn b/test/unittest/ability_event_handler_test/BUILD.gn index e177eaf526..4e78457d4d 100644 --- a/test/unittest/ability_event_handler_test/BUILD.gn +++ b/test/unittest/ability_event_handler_test/BUILD.gn @@ -38,6 +38,7 @@ ohos_unittest("ability_event_handler_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -52,7 +53,7 @@ ohos_unittest("ability_event_handler_test") { "c_utils:utils", "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp b/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp index e174b67a87..2c20509fd5 100644 --- a/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp +++ b/test/unittest/ability_event_handler_test/ability_event_handler_test.cpp @@ -54,25 +54,25 @@ void AbilityEventHandlerTest::TearDown() */ HWTEST_F(AbilityEventHandlerTest, ability_event_handler_001, TestSize.Level1) { - std::shared_ptr runner; + std::shared_ptr runner; std::weak_ptr server; std::shared_ptr eventData = std::make_shared(); - auto event = AppExecFwk::InnerEvent::Get(UserEventHandler::EVENT_SYSTEM_USER_START, eventData); + auto event = EventWrap(UserEventHandler::EVENT_SYSTEM_USER_START, eventData); auto handler = std::make_shared(runner, server); SetParameter("libc.hook_mode", "startup:"); handler->ProcessEvent(event); SetParameter("libc.hook_mode", "test_parameter"); handler->ProcessEvent(event); - auto event2 = event->Get(AbilityManagerService::LOAD_TIMEOUT_MSG, event->GetParam()); - std::string str = std::to_string(event->GetInnerEventId()); + auto event2 = EventWrap(AbilityManagerService::LOAD_TIMEOUT_MSG, event.GetParam()); + std::string str = std::to_string(event.GetEventId()); handler->ProcessEvent(event2); - event2 = event->Get(AbilityManagerService::ACTIVE_TIMEOUT_MSG, event->GetParam()); + event2 = EventWrap(AbilityManagerService::ACTIVE_TIMEOUT_MSG, event.GetParam()); handler->ProcessEvent(event2); - event2 = event->Get(AbilityManagerService::INACTIVE_TIMEOUT_MSG, event->GetParam()); + event2 = EventWrap(AbilityManagerService::INACTIVE_TIMEOUT_MSG, event.GetParam()); handler->ProcessEvent(event2); - event2 = event->Get(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, event->GetParam()); + event2 = EventWrap(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, event.GetParam()); handler->ProcessEvent(event2); - event2 = event->Get(AbilityManagerService::BACKGROUND_TIMEOUT_MSG, event->GetParam()); + event2 = EventWrap(AbilityManagerService::BACKGROUND_TIMEOUT_MSG, event.GetParam()); handler->ProcessEvent(event2); } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/ability_interceptor_test/BUILD.gn b/test/unittest/ability_interceptor_test/BUILD.gn index d4845ca064..c7fe9cf78a 100644 --- a/test/unittest/ability_interceptor_test/BUILD.gn +++ b/test/unittest/ability_interceptor_test/BUILD.gn @@ -62,7 +62,7 @@ ohos_unittest("ability_interceptor_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/ability_manager_client_branch_test/BUILD.gn b/test/unittest/ability_manager_client_branch_test/BUILD.gn index 8fbd9228f4..98ede814e8 100644 --- a/test/unittest/ability_manager_client_branch_test/BUILD.gn +++ b/test/unittest/ability_manager_client_branch_test/BUILD.gn @@ -62,7 +62,7 @@ ohos_unittest("ability_manager_client_branch_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbeget_proxy", diff --git a/test/unittest/ability_manager_proxy_test/BUILD.gn b/test/unittest/ability_manager_proxy_test/BUILD.gn index 0330f845ff..dc732b7018 100644 --- a/test/unittest/ability_manager_proxy_test/BUILD.gn +++ b/test/unittest/ability_manager_proxy_test/BUILD.gn @@ -58,7 +58,7 @@ ohos_unittest("ability_manager_proxy_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_manager_service_account_test/BUILD.gn b/test/unittest/ability_manager_service_account_test/BUILD.gn index d5dff800be..5894960b53 100644 --- a/test/unittest/ability_manager_service_account_test/BUILD.gn +++ b/test/unittest/ability_manager_service_account_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_unittest("ability_manager_service_account_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -58,7 +59,7 @@ ohos_unittest("ability_manager_service_account_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp b/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp index 3559f1c288..36c42cc342 100644 --- a/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp +++ b/test/unittest/ability_manager_service_account_test/ability_manager_service_account_test.cpp @@ -44,10 +44,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { diff --git a/test/unittest/ability_manager_service_anr_test/BUILD.gn b/test/unittest/ability_manager_service_anr_test/BUILD.gn index 452864a20c..e2495fdcfd 100644 --- a/test/unittest/ability_manager_service_anr_test/BUILD.gn +++ b/test/unittest/ability_manager_service_anr_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_unittest("ability_manager_service_anr_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -63,6 +64,7 @@ ohos_unittest("ability_manager_service_anr_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "dsoftbus:softbus_client", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_manager_service_anr_test/ability_manager_service_anr_test.cpp b/test/unittest/ability_manager_service_anr_test/ability_manager_service_anr_test.cpp index 92e910bcab..fc899675a5 100644 --- a/test/unittest/ability_manager_service_anr_test/ability_manager_service_anr_test.cpp +++ b/test/unittest/ability_manager_service_anr_test/ability_manager_service_anr_test.cpp @@ -52,10 +52,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -89,10 +89,10 @@ void AbilityManagerServiceAnrTest::OnStartAms() abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; - abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - EXPECT_TRUE(abilityMs_->eventLoop_); + abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + EXPECT_TRUE(abilityMs_->taskHandler_); - abilityMs_->handler_ = std::make_shared(abilityMs_->eventLoop_, abilityMs_); + abilityMs_->eventHandler_ = std::make_shared(abilityMs_->taskHandler_, abilityMs_); abilityMs_->dataAbilityManager_ = std::make_shared(); abilityMs_->dataAbilityManagers_.emplace(0, abilityMs_->dataAbilityManager_); @@ -107,8 +107,6 @@ void AbilityManagerServiceAnrTest::OnStartAms() auto deviceType = AmsConfigurationParameter::GetInstance().GetDeviceType(); DelayedSingleton::GetInstance()->SetDeviceType(deviceType); #endif - - abilityMs_->eventLoop_->Run(); return; } diff --git a/test/unittest/ability_manager_service_dialog_test/BUILD.gn b/test/unittest/ability_manager_service_dialog_test/BUILD.gn index b694f91c8a..25c37d60a4 100644 --- a/test/unittest/ability_manager_service_dialog_test/BUILD.gn +++ b/test/unittest/ability_manager_service_dialog_test/BUILD.gn @@ -36,6 +36,7 @@ ohos_unittest("ability_manager_service_dialog_test") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "hilog:libhilog", ] } diff --git a/test/unittest/ability_manager_service_distributed_test/BUILD.gn b/test/unittest/ability_manager_service_distributed_test/BUILD.gn index 268cfa4a55..cae9de7052 100755 --- a/test/unittest/ability_manager_service_distributed_test/BUILD.gn +++ b/test/unittest/ability_manager_service_distributed_test/BUILD.gn @@ -42,7 +42,7 @@ ohos_unittest("ability_manager_service_distributed_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_manager_service_test/BUILD.gn b/test/unittest/ability_manager_service_test/BUILD.gn index bff73de31b..f065808d29 100755 --- a/test/unittest/ability_manager_service_test/BUILD.gn +++ b/test/unittest/ability_manager_service_test/BUILD.gn @@ -58,6 +58,7 @@ ohos_unittest("ability_manager_service_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/unittest:abilityms_test_source", @@ -76,7 +77,7 @@ ohos_unittest("ability_manager_service_test") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp b/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp index 248cd9fc27..b672e934cf 100755 --- a/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp +++ b/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp @@ -68,10 +68,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -1718,6 +1718,20 @@ HWTEST_F(AbilityManagerServiceTest, OnAppStateChanged_001, TestSize.Level1) HILOG_INFO("AbilityManagerServiceTest OnAppStateChanged_001 end"); } +/* + * Feature: AbilityManagerService + * Function: GetTaskHandler + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetTaskHandler + */ +HWTEST_F(AbilityManagerServiceTest, GetTaskHandler_001, TestSize.Level1) +{ + HILOG_INFO("AbilityManagerServiceTest GetTaskHandler_001 start"); + ASSERT_NE(abilityMs_, nullptr); + EXPECT_NE(abilityMs_->GetTaskHandler(), nullptr); + HILOG_INFO("AbilityManagerServiceTest GetTaskHandler_001 end"); +} + /* * Feature: AbilityManagerService * Function: GetEventHandler @@ -2922,11 +2936,11 @@ HWTEST_F(AbilityManagerServiceTest, VerifyAccountPermission_001, TestSize.Level1 HWTEST_F(AbilityManagerServiceTest, BlockAmsService_001, TestSize.Level1) { HILOG_INFO("AbilityManagerServiceTest BlockAmsService_001 start"); - auto temp = abilityMs_->handler_; - abilityMs_->handler_ = nullptr; + auto temp = abilityMs_->taskHandler_; + abilityMs_->taskHandler_ = nullptr; EXPECT_EQ(abilityMs_->BlockAmsService(), ERR_NO_INIT); - abilityMs_->handler_ = temp; + abilityMs_->taskHandler_ = temp; EXPECT_EQ(abilityMs_->BlockAmsService(), ERR_OK); HILOG_INFO("AbilityManagerServiceTest BlockAmsService_001 end"); } diff --git a/test/unittest/ability_manager_stub_test/BUILD.gn b/test/unittest/ability_manager_stub_test/BUILD.gn index 7bbfbf1c83..69d10dc7fd 100644 --- a/test/unittest/ability_manager_stub_test/BUILD.gn +++ b/test/unittest/ability_manager_stub_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_unittest("ability_manager_stub_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -56,7 +57,7 @@ ohos_unittest("ability_manager_stub_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_record_dump_test/BUILD.gn b/test/unittest/ability_record_dump_test/BUILD.gn index 11eb6f5bf8..32cbf2ce3e 100644 --- a/test/unittest/ability_record_dump_test/BUILD.gn +++ b/test/unittest/ability_record_dump_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_unittest("ability_record_dump_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_record_test/BUILD.gn b/test/unittest/ability_record_test/BUILD.gn index 3cf17845d9..4d701479ed 100644 --- a/test/unittest/ability_record_test/BUILD.gn +++ b/test/unittest/ability_record_test/BUILD.gn @@ -60,7 +60,7 @@ ohos_unittest("ability_record_test") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", @@ -114,7 +114,7 @@ ohos_unittest("ability_record_test_call") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/ability_record_test/ability_record_test.cpp b/test/unittest/ability_record_test/ability_record_test.cpp index c35ad204e6..2eb2d67d0d 100644 --- a/test/unittest/ability_record_test/ability_record_test.cpp +++ b/test/unittest/ability_record_test/ability_record_test.cpp @@ -61,7 +61,6 @@ public: std::shared_ptr abilityResult_{ nullptr }; std::shared_ptr abilityRequest_{ nullptr }; static constexpr unsigned int CHANGE_CONFIG_LOCALE = 0x00000001; - inline static std::shared_ptr handler_{ nullptr }; }; void AbilityRecordTest::SetUpTestCase(void) diff --git a/test/unittest/ability_scheduler_proxy_test/BUILD.gn b/test/unittest/ability_scheduler_proxy_test/BUILD.gn index f735b003dc..471ad940f5 100644 --- a/test/unittest/ability_scheduler_proxy_test/BUILD.gn +++ b/test/unittest/ability_scheduler_proxy_test/BUILD.gn @@ -57,7 +57,7 @@ ohos_unittest("ability_scheduler_proxy_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_scheduler_stub_test/BUILD.gn b/test/unittest/ability_scheduler_stub_test/BUILD.gn index 9cf28dd140..e79ebcaa13 100644 --- a/test/unittest/ability_scheduler_stub_test/BUILD.gn +++ b/test/unittest/ability_scheduler_stub_test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("ability_scheduler_stub_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_service_start_test/BUILD.gn b/test/unittest/ability_service_start_test/BUILD.gn index 880ea370c2..a00ccba877 100644 --- a/test/unittest/ability_service_start_test/BUILD.gn +++ b/test/unittest/ability_service_start_test/BUILD.gn @@ -56,7 +56,7 @@ ohos_unittest("ability_service_start_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_timeout_test/BUILD.gn b/test/unittest/ability_timeout_test/BUILD.gn index eba107748c..d885776ec5 100644 --- a/test/unittest/ability_timeout_test/BUILD.gn +++ b/test/unittest/ability_timeout_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_unittest("ability_timeout_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -59,7 +60,7 @@ ohos_unittest("ability_timeout_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_timeout_test/ability_timeout_test.cpp b/test/unittest/ability_timeout_test/ability_timeout_test.cpp index 403afff912..9445ccd916 100644 --- a/test/unittest/ability_timeout_test/ability_timeout_test.cpp +++ b/test/unittest/ability_timeout_test/ability_timeout_test.cpp @@ -49,10 +49,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -68,11 +68,11 @@ static void WaitUntilTaskFinishedByTimer() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; int sleepingTime = 5000; - if (handler->PostTask(f, "AbilityManagerServiceTest", sleepingTime)) { + if (handler->SubmitTask(f, "AbilityManagerServiceTest", sleepingTime)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -116,7 +116,6 @@ void AbilityTimeoutTest::SetUp() void AbilityTimeoutTest::TearDown() { WaitUntilTaskFinishedByTimer(); - abilityMs_->handler_->RemoveAllEvents(); abilityMs_->currentMissionListManager_->terminateAbilityList_.clear(); abilityMs_->currentMissionListManager_->launcherList_->missions_.clear(); abilityMs_->currentMissionListManager_->defaultStandardList_->missions_.clear(); @@ -135,10 +134,10 @@ void AbilityTimeoutTest::MockOnStart() if (abilityMs_->state_ == ServiceRunningState::STATE_RUNNING) { return; } - abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - abilityMs_->handler_ = std::make_shared(abilityMs_->eventLoop_, abilityMs_); - EXPECT_TRUE(abilityMs_->handler_); - EXPECT_TRUE(abilityMs_->eventLoop_); + abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + abilityMs_->eventHandler_ = std::make_shared(abilityMs_->taskHandler_, abilityMs_); + EXPECT_TRUE(abilityMs_->taskHandler_); + EXPECT_TRUE(abilityMs_->eventHandler_); // init user controller. abilityMs_->userController_ = std::make_shared(); @@ -159,7 +158,6 @@ void AbilityTimeoutTest::MockOnStart() abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; abilityMs_->iBundleManager_ = new BundleMgrService(); - abilityMs_->eventLoop_->Run(); WaitUntilTaskFinished(); } @@ -173,7 +171,6 @@ void AbilityTimeoutTest::MockOnStop() return; } - abilityMs_->handler_->RemoveAllEvents(); abilityMs_->connectManagers_.clear(); abilityMs_->connectManager_.reset(); abilityMs_->iBundleManager_.clear(); diff --git a/test/unittest/ability_token_proxy_test/BUILD.gn b/test/unittest/ability_token_proxy_test/BUILD.gn index 747946c6fa..e90e7f9e79 100644 --- a/test/unittest/ability_token_proxy_test/BUILD.gn +++ b/test/unittest/ability_token_proxy_test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("ability_token_proxy_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ability_token_stub_test/BUILD.gn b/test/unittest/ability_token_stub_test/BUILD.gn index b19f666491..bdca0e84fd 100644 --- a/test/unittest/ability_token_stub_test/BUILD.gn +++ b/test/unittest/ability_token_stub_test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("ability_token_stub_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index b7ae7f10f2..8c3b39e8d7 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -51,6 +51,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -59,7 +60,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/test/unittest/ams_ability_running_record_test/ams_ability_running_record_test.cpp b/test/unittest/ams_ability_running_record_test/ams_ability_running_record_test.cpp index d1c5a545d2..a4424828a8 100644 --- a/test/unittest/ams_ability_running_record_test/ams_ability_running_record_test.cpp +++ b/test/unittest/ams_ability_running_record_test/ams_ability_running_record_test.cpp @@ -58,8 +58,9 @@ protected: sptr client_; sptr mockedAppClient_; std::shared_ptr testAppRecord_; - std::shared_ptr serviceInner_ = nullptr; - std::shared_ptr handler_ = nullptr; + std::shared_ptr serviceInner_; + std::shared_ptr taskHandler_; + std::shared_ptr eventHandler_; }; void AmsAbilityRunningRecordTest::SetUpTestCase() @@ -71,9 +72,9 @@ void AmsAbilityRunningRecordTest::TearDownTestCase() void AmsAbilityRunningRecordTest::SetUp() { mockedAppClient_ = new MockApplication(); - auto runner = EventRunner::Create("AmsAppLifeCycleModuleTest"); - serviceInner_ = std::make_shared(); - handler_ = std::make_shared(runner, serviceInner_); + taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("AmsAbilityRunningRecordTest"); + serviceInner_ = std::make_shared(); + eventHandler_ = std::make_shared(taskHandler_, serviceInner_); } void AmsAbilityRunningRecordTest::TearDown() @@ -96,7 +97,8 @@ std::shared_ptr AmsAbilityRunningRecordTest::GetTestAppRunning appInfo->name = GetTestAppName(); testAppRecord_ = std::make_shared(appInfo, AppRecordId::Create(), GetProcessName()); testAppRecord_->SetApplicationClient(GetMockedAppSchedulerClient()); - testAppRecord_->SetEventHandler(handler_); + testAppRecord_->SetTaskHandler(taskHandler_); + testAppRecord_->SetEventHandler(eventHandler_); } return testAppRecord_; } diff --git a/test/unittest/ams_app_death_recipient_test/BUILD.gn b/test/unittest/ams_app_death_recipient_test/BUILD.gn index e3419c280b..09b398857d 100644 --- a/test/unittest/ams_app_death_recipient_test/BUILD.gn +++ b/test/unittest/ams_app_death_recipient_test/BUILD.gn @@ -38,6 +38,7 @@ ohos_unittest("AppDeathRecipientTest") { "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", @@ -52,7 +53,7 @@ ohos_unittest("AppDeathRecipientTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/test/unittest/ams_app_death_recipient_test/ams_app_death_recipient_test.cpp b/test/unittest/ams_app_death_recipient_test/ams_app_death_recipient_test.cpp index a20ef10f11..4bb5cd04a7 100644 --- a/test/unittest/ams_app_death_recipient_test/ams_app_death_recipient_test.cpp +++ b/test/unittest/ams_app_death_recipient_test/ams_app_death_recipient_test.cpp @@ -18,7 +18,6 @@ #include "app_mgr_service_inner.h" #undef private #include -#include "app_mgr_service_inner.h" #include "hilog_wrapper.h" #include "mock_ability_token.h" #include "mock_app_scheduler.h" @@ -48,14 +47,14 @@ public: sptr GetApp(int32_t pid, int size); public: - std::shared_ptr handler_; + std::shared_ptr handler_; std::shared_ptr appMgrServiceInner_; sptr appDeathRecipientObject_; OHOS::sptr mockToken_; OHOS::sptr mockBundleMgr; }; -static void WaitUntilTaskFinished(std::shared_ptr handler) +static void WaitUntilTaskFinished(std::shared_ptr handler) { if (!handler) { return; @@ -66,7 +65,7 @@ static void WaitUntilTaskFinished(std::shared_ptr handler) uint32_t count = 0; std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; // if delay more than 1 second, break @@ -87,11 +86,10 @@ void AppDeathRecipientTest::TearDownTestCase() void AppDeathRecipientTest::SetUp() { - auto runner = EventRunner::Create("AppDeathRecipientTest"); appMgrServiceInner_ = std::make_shared(); appMgrServiceInner_->Init(); - handler_ = std::make_shared(runner, appMgrServiceInner_); + handler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("AppDeathRecipientTest"); appDeathRecipientObject_ = new (std::nothrow) AppDeathRecipient(); @@ -158,7 +156,7 @@ sptr AppDeathRecipientTest::GetApp(int32_t pid, int size) /* * Feature: Ams - * Function: SetEventHandler ande SetAppMgrServiceInner. + * Function: SetTaskHandler ande SetAppMgrServiceInner. * SubFunction: AppDeathRecipient * FunctionPoints: initialization * EnvConditions: have to an application @@ -168,7 +166,7 @@ sptr AppDeathRecipientTest::GetApp(int32_t pid, int size) HWTEST_F(AppDeathRecipientTest, AppDeathRecipient_001, TestSize.Level1) { HILOG_INFO("AppDeathRecipient_001 start"); - appDeathRecipientObject_->SetEventHandler(handler_); + appDeathRecipientObject_->SetTaskHandler(handler_); EXPECT_TRUE(appDeathRecipientObject_->handler_.lock() != nullptr); appDeathRecipientObject_->SetAppMgrServiceInner(appMgrServiceInner_); @@ -192,7 +190,7 @@ HWTEST_F(AppDeathRecipientTest, AppDeathRecipient_002, TestSize.Level1) sptr appOne = GetApp(pid1, 1); sptr appTwo = GetApp(pid2, 2); - appDeathRecipientObject_->SetEventHandler(handler_); + appDeathRecipientObject_->SetTaskHandler(handler_); appDeathRecipientObject_->SetAppMgrServiceInner(appMgrServiceInner_); appDeathRecipientObject_->OnRemoteDied(appOne); diff --git a/test/unittest/ams_app_life_cycle_test/BUILD.gn b/test/unittest/ams_app_life_cycle_test/BUILD.gn index 0ffa2686fc..ddf7c93382 100644 --- a/test/unittest/ams_app_life_cycle_test/BUILD.gn +++ b/test/unittest/ams_app_life_cycle_test/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("AmsAppLifeCycleTest") { "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", ] @@ -64,7 +65,7 @@ ohos_unittest("AmsAppLifeCycleTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp b/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp index 68e1e8670e..56df2bd399 100644 --- a/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp +++ b/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp @@ -88,8 +88,8 @@ protected: std::shared_ptr serviceInner_; sptr mock_token_ = nullptr; sptr mockBundleMgr = nullptr; - std::shared_ptr runner_ = nullptr; - std::shared_ptr handler_ = nullptr; + std::shared_ptr taskHandler_; + std::shared_ptr eventHandler_; sptr mockAppStateCallbackStub_ = nullptr; }; @@ -106,16 +106,17 @@ void AmsAppLifeCycleTest::SetUp() mockBundleMgr = new (std::nothrow) BundleMgrService(); serviceInner_->SetBundleManager(mockBundleMgr); - runner_ = EventRunner::Create("AmsAppLifeCycleTest"); - handler_ = std::make_shared(runner_, serviceInner_); - serviceInner_->SetEventHandler(handler_); + taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("AmsAppLifeCycleTest"); + eventHandler_ = std::make_shared(taskHandler_, serviceInner_); + serviceInner_->SetTaskHandler(taskHandler_); + serviceInner_->SetEventHandler(eventHandler_); } void AmsAppLifeCycleTest::TearDown() { serviceInner_ = nullptr; - handler_ = nullptr; - runner_.reset(); + eventHandler_ = nullptr; + taskhandler_.reset(); } std::shared_ptr AmsAppLifeCycleTest::StartProcessAndLoadAbility(const sptr& token, @@ -195,7 +196,8 @@ TestApplicationPreRecord AmsAppLifeCycleTest::CreateTestApplicationRecord( std::shared_ptr appRecord = serviceInner_->CreateAppRunningRecord( token, nullptr, appInfo, abilityInfo, "com.ohos.test.helloworld", bundleInfo, hapModuleInfo, nullptr); - appRecord->SetEventHandler(handler_); + appRecord->SetTaskHandler(taskHandler_); + appRecord->SetEventHandler(eventHandler_); EXPECT_NE(appRecord, nullptr); auto abilityRecord = appRecord->GetAbilityRunningRecordByToken(GetMockToken()); EXPECT_NE(abilityRecord, nullptr); @@ -223,7 +225,8 @@ std::shared_ptr AmsAppLifeCycleTest::CreateTestApplicationAndS token, nullptr, appInfo, abilityInfo, "AmsAppLifeCycleTest", bundleInfo, hapModuleInfo, nullptr); EXPECT_NE(appRecord, nullptr); - appRecord->SetEventHandler(handler_); + appRecord->SetTaskHandler(taskHandler_); + appRecord->SetEventHandler(eventHandler_); appRecord->SetState(appState); return appRecord; } diff --git a/test/unittest/ams_app_mgr_client_test/BUILD.gn b/test/unittest/ams_app_mgr_client_test/BUILD.gn index 6eefaa893d..cb89ac4660 100644 --- a/test/unittest/ams_app_mgr_client_test/BUILD.gn +++ b/test/unittest/ams_app_mgr_client_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("AmsAppMgrClientTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "window_manager:libwm", diff --git a/test/unittest/ams_app_running_record_test/BUILD.gn b/test/unittest/ams_app_running_record_test/BUILD.gn index a8c931f926..e976322337 100644 --- a/test/unittest/ams_app_running_record_test/BUILD.gn +++ b/test/unittest/ams_app_running_record_test/BUILD.gn @@ -40,6 +40,7 @@ ohos_unittest("AmsAppRunningRecordTest") { deps = [ "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/googletest:gmock_main", ] @@ -49,7 +50,7 @@ ohos_unittest("AmsAppRunningRecordTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "window_manager:libwm", diff --git a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp index b284bf9656..52b5222ec1 100644 --- a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp +++ b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp @@ -2241,14 +2241,16 @@ HWTEST_F(AmsAppRunningRecordTest, AddAbilityStageBySpecifiedAbility_001, TestSiz record->AddAbilityStageBySpecifiedAbility(bundleName1); - auto runner = EventRunner::Create("AmsAppLifeCycleModuleTest"); + auto runner = AAFwk::TaskHandlerWrap::CreateQueueHandler("AmsAppRunningRecordTest"); std::shared_ptr serviceInner = std::make_shared(); std::shared_ptr handler = std::make_shared(runner, serviceInner); + record->taskHandler_ = runner; record->eventHandler_ = handler; record->AddAbilityStageBySpecifiedAbility(bundleName1); record->AddAbilityStageBySpecifiedAbility(bundleName); - record->eventHandler_->SendEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG, 1, 0); + record->eventHandler_->SendEvent( + AAFwk::EventWrap(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG, 1), 0); record->AddAbilityStageBySpecifiedAbility(bundleName); auto abilityInfo2 = std::make_shared(); @@ -2292,14 +2294,17 @@ HWTEST_F(AmsAppRunningRecordTest, AddAbilityStageDone_001, TestSize.Level1) EXPECT_TRUE(record != nullptr); record->AddAbilityStageDone(); - auto runner = EventRunner::Create("AmsAppLifeCycleModuleTest"); + auto runner = AAFwk::TaskHandlerWrap::CreateQueueHandler("AmsAppRunningRecordTest"); std::shared_ptr serviceInner = std::make_shared(); std::shared_ptr handler = std::make_shared(runner, serviceInner); + record->taskHandler_ = runner; record->eventHandler_ = handler; record->AddAbilityStageDone(); - record->eventHandler_->SendEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG, 1, 0); - record->eventHandler_->SendEvent(AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG, 1, 0); + record->eventHandler_->SendEvent( + AAFwk::EventWrap(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG, 1), 0); + record->eventHandler_->SendEvent( + AAFwk::EventWrap(AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG, 1), 0); record->AddAbilityStageDone(); record->isSpecifiedAbility_ = true; diff --git a/test/unittest/ams_app_workflow_test/BUILD.gn b/test/unittest/ams_app_workflow_test/BUILD.gn index b14bd3d7f2..05a74f615c 100644 --- a/test/unittest/ams_app_workflow_test/BUILD.gn +++ b/test/unittest/ams_app_workflow_test/BUILD.gn @@ -50,6 +50,7 @@ ohos_unittest("AmsWorkFlowTest") { "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", ] @@ -62,7 +63,7 @@ ohos_unittest("AmsWorkFlowTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp b/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp index 08599a5c3d..ee8e1c5fa1 100644 --- a/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp +++ b/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp @@ -80,8 +80,9 @@ void AmsWorkFlowTest::SetUp() { serviceInner_ = std::make_unique(); serviceInner_->Init(); - auto runner = EventRunner::Create("AmsWorkFlowTest"); - handler_ = std::make_shared(runner, serviceInner_); + auto taskhandler = AAFwk::TaskHandlerWrap::CreateQueueHandler("AmsWorkFlowTest"); + handler_ = std::make_shared(taskhandler, serviceInner_); + serviceInner_->SetTaskHandler(taskhandler); serviceInner_->SetEventHandler(handler_); } diff --git a/test/unittest/ams_mgr_kill_process_test/BUILD.gn b/test/unittest/ams_mgr_kill_process_test/BUILD.gn index 9070a1a886..87fdbae740 100644 --- a/test/unittest/ams_mgr_kill_process_test/BUILD.gn +++ b/test/unittest/ams_mgr_kill_process_test/BUILD.gn @@ -46,6 +46,7 @@ ohos_unittest("AmsMgrKillProcessTest") { "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -57,7 +58,7 @@ ohos_unittest("AmsMgrKillProcessTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/test/unittest/ams_mgr_proxy_test/BUILD.gn b/test/unittest/ams_mgr_proxy_test/BUILD.gn index 80c8a88cc6..b57221772e 100644 --- a/test/unittest/ams_mgr_proxy_test/BUILD.gn +++ b/test/unittest/ams_mgr_proxy_test/BUILD.gn @@ -29,6 +29,7 @@ ohos_unittest("AmsMgrProxyTest") { deps = [ "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -40,7 +41,7 @@ ohos_unittest("AmsMgrProxyTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", diff --git a/test/unittest/ams_mgr_scheduler_dump_test/BUILD.gn b/test/unittest/ams_mgr_scheduler_dump_test/BUILD.gn index 67ffe00363..fdd89ddb07 100644 --- a/test/unittest/ams_mgr_scheduler_dump_test/BUILD.gn +++ b/test/unittest/ams_mgr_scheduler_dump_test/BUILD.gn @@ -25,6 +25,7 @@ ohos_unittest("ams_mgr_scheduler_dump_test") { deps = [ "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -36,7 +37,7 @@ ohos_unittest("ams_mgr_scheduler_dump_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/test/unittest/ams_mgr_scheduler_test/BUILD.gn b/test/unittest/ams_mgr_scheduler_test/BUILD.gn index 9fe4970985..46011d8ce2 100644 --- a/test/unittest/ams_mgr_scheduler_test/BUILD.gn +++ b/test/unittest/ams_mgr_scheduler_test/BUILD.gn @@ -41,12 +41,13 @@ ohos_unittest("ams_mgr_scheduler_test") { "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] external_deps = [ "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] 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 7cafded0cc..112289a5b3 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 @@ -51,11 +51,11 @@ protected: } std::shared_ptr GetMockAppMgrServiceInner(); - std::shared_ptr GetAmsEventHandler(); + std::shared_ptr GetAmsTaskHandler(); private: std::shared_ptr mockAppMgrServiceInner_; - std::shared_ptr amsEventHandler_; + std::shared_ptr amsTaskHandler_; }; void AmsMgrSchedulerTest::SetUpTestCase() @@ -69,7 +69,7 @@ void AmsMgrSchedulerTest::SetUp() void AmsMgrSchedulerTest::TearDown() { - amsEventHandler_.reset(); + amsTaskHandler_.reset(); mockAppMgrServiceInner_.reset(); } @@ -81,14 +81,12 @@ std::shared_ptr AmsMgrSchedulerTest::GetMockAppMgrServic return mockAppMgrServiceInner_; } -std::shared_ptr AmsMgrSchedulerTest::GetAmsEventHandler() +std::shared_ptr AmsMgrSchedulerTest::GetAmsTaskHandler() { - if (!amsEventHandler_) { - auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - amsEventHandler_ = - std::make_shared(EventRunner::Create("AmsMgrSchedulerTest"), mockAppMgrServiceInner); + if (!amsTaskHandler_) { + amsTaskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("AmsMgrSchedulerTest"); } - return amsEventHandler_; + return amsTaskHandler_; } /* @@ -104,9 +102,8 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_001, TestSize.Level1) HILOG_DEBUG("AmsMgrScheduler_001 start."); auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); ASSERT_NE(amsMgrScheduler, nullptr); sptr token = new MockAbilityToken(); @@ -137,10 +134,9 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_002, TestSize.Level1) HILOG_DEBUG("AmsMgrScheduler_002 start."); auto mockAppMgrServiceInner = std::make_shared(); - auto eventRunner = EventRunner::Create("AmsMgrSchedulerTest"); - auto amsEventHandler = std::make_shared(eventRunner, mockAppMgrServiceInner); + auto taskHandler = AAFwk::TaskHandlerWrap::CreateQueueHandler("AmsMgrSchedulerTest"); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, taskHandler); ASSERT_NE(amsMgrScheduler, nullptr); sptr token = new MockAbilityToken(); @@ -174,9 +170,8 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_003, TestSize.Level1) HILOG_DEBUG("AmsMgrScheduler_003 start."); auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); ASSERT_NE(amsMgrScheduler, nullptr); sptr token = new MockAbilityToken(); @@ -203,9 +198,8 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_004, TestSize.Level1) HILOG_DEBUG("AmsMgrScheduler_004 start."); auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); ASSERT_NE(amsMgrScheduler, nullptr); sptr token = new MockAbilityToken(); bool clearMissionFlag = true; @@ -230,9 +224,8 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_005, TestSize.Level1) HILOG_DEBUG("AmsMgrScheduler_005 start."); auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); ASSERT_NE(amsMgrScheduler, nullptr); sptr appStateCallbackHost = new AppStateCallbackHost(); @@ -257,18 +250,18 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_007, TestSize.Level1) HILOG_DEBUG("AmsMgrScheduler_007 start."); auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); + auto amsTaskHandler = GetAmsTaskHandler(); // act normal std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, amsTaskHandler); EXPECT_EQ(true, amsMgrScheduler->IsReady()); // check params AppMgrServiceInner - std::unique_ptr amsMgrScheduler2 = std::make_unique(nullptr, amsEventHandler); + std::unique_ptr amsMgrScheduler2 = std::make_unique(nullptr, amsTaskHandler); EXPECT_EQ(false, amsMgrScheduler2->IsReady()); - // check params AMSEventHandler + // check params amsTaskHandler std::unique_ptr amsMgrScheduler3 = std::make_unique(mockAppMgrServiceInner, nullptr); EXPECT_EQ(false, amsMgrScheduler3->IsReady()); @@ -289,17 +282,17 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_008, TestSize.Level1) HILOG_DEBUG("AmsMgrScheduler_008 start."); auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); + auto amsTaskHandler = GetAmsTaskHandler(); EXPECT_CALL(*mockAppMgrServiceInner, KillApplication(_)).Times(1).WillOnce(Return(ERR_OK)); // check params AppMgrServiceInner - std::unique_ptr amsMgrScheduler2 = std::make_unique(nullptr, amsEventHandler); + std::unique_ptr amsMgrScheduler2 = std::make_unique(nullptr, amsTaskHandler); EXPECT_EQ(false, amsMgrScheduler2->IsReady()); EXPECT_EQ(ERR_INVALID_OPERATION, amsMgrScheduler2->KillApplication(GetTestAppName())); - // check params AMSEventHandler + // check params amsTaskHandler std::unique_ptr amsMgrScheduler3 = std::make_unique(mockAppMgrServiceInner, nullptr); EXPECT_EQ(false, amsMgrScheduler3->IsReady()); @@ -308,7 +301,7 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_008, TestSize.Level1) // act normal std::unique_ptr amsMgrScheduler4 = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, amsTaskHandler); EXPECT_EQ(true, amsMgrScheduler4->IsReady()); EXPECT_EQ(ERR_OK, amsMgrScheduler4->KillApplication(GetTestAppName())); @@ -329,9 +322,8 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_009, TestSize.Level1) HILOG_DEBUG("AmsMgrScheduler_009 start."); auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); EXPECT_EQ(true, amsMgrScheduler->IsReady()); EXPECT_CALL(*mockAppMgrServiceInner, AbilityBehaviorAnalysis(_, _, _, _, _)) @@ -349,7 +341,6 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_009, TestSize.Level1) mockAppMgrServiceInner->Wait(); mockAppMgrServiceInner.reset(); - amsEventHandler.reset(); HILOG_DEBUG("AmsMgrScheduler_009 end."); } @@ -495,9 +486,8 @@ HWTEST_F(AmsMgrSchedulerTest, LoadAbility_003, TestSize.Level0) HWTEST_F(AmsMgrSchedulerTest, LoadAbility_004, TestSize.Level0) { auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); - auto amsEventHandler = GetAmsEventHandler(); std::unique_ptr amsMgrScheduler = - std::make_unique(mockAppMgrServiceInner, amsEventHandler); + std::make_unique(mockAppMgrServiceInner, GetAmsTaskHandler()); ASSERT_NE(amsMgrScheduler, nullptr); sptr token = nullptr; sptr preToken = nullptr; @@ -523,7 +513,7 @@ HWTEST_F(AmsMgrSchedulerTest, UpdateAbilityState_001, TestSize.Level0) AbilityState state = AbilityState::ABILITY_STATE_READY; amsMgrScheduler->UpdateAbilityState(token, state); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->UpdateAbilityState(token, state); } @@ -543,7 +533,7 @@ HWTEST_F(AmsMgrSchedulerTest, UpdateExtensionState_001, TestSize.Level0) ExtensionState state = ExtensionState::EXTENSION_STATE_READY; amsMgrScheduler->UpdateExtensionState(token, state); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->UpdateExtensionState(token, state); } @@ -563,7 +553,7 @@ HWTEST_F(AmsMgrSchedulerTest, TerminateAbility_001, TestSize.Level0) bool clearMissionFlag = true; amsMgrScheduler->TerminateAbility(token, clearMissionFlag); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->TerminateAbility(token, clearMissionFlag); } @@ -582,7 +572,7 @@ HWTEST_F(AmsMgrSchedulerTest, RegisterAppStateCallback_001, TestSize.Level0) sptr callback = nullptr; amsMgrScheduler->RegisterAppStateCallback(callback); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->RegisterAppStateCallback(callback); } @@ -605,7 +595,7 @@ HWTEST_F(AmsMgrSchedulerTest, AbilityBehaviorAnalysis_001, TestSize.Level0) int32_t connectionState = 0; amsMgrScheduler->AbilityBehaviorAnalysis(token, preToken, visibility, perceptibility, connectionState); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->AbilityBehaviorAnalysis(token, preToken, visibility, perceptibility, connectionState); } @@ -642,7 +632,7 @@ HWTEST_F(AmsMgrSchedulerTest, KillProcessWithAccount_001, TestSize.Level0) int32_t res1 = amsMgrScheduler->KillProcessWithAccount(bundleName, accountId); EXPECT_EQ(res1, ERR_INVALID_OPERATION); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); int32_t res2 = amsMgrScheduler->KillProcessWithAccount(bundleName, accountId); EXPECT_NE(res2, ERR_INVALID_OPERATION); } @@ -662,7 +652,7 @@ HWTEST_F(AmsMgrSchedulerTest, AbilityAttachTimeOut_001, TestSize.Level0) sptr token = nullptr; amsMgrScheduler->AbilityAttachTimeOut(token); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->AbilityAttachTimeOut(token); } @@ -681,7 +671,7 @@ HWTEST_F(AmsMgrSchedulerTest, PrepareTerminate_001, TestSize.Level0) sptr token = nullptr; amsMgrScheduler->PrepareTerminate(token); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->PrepareTerminate(token); } @@ -700,7 +690,7 @@ HWTEST_F(AmsMgrSchedulerTest, KillApplication_001, TestSize.Level0) std::string bundleName = "bundleName"; amsMgrScheduler->KillApplication(bundleName); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->KillApplication(bundleName); } @@ -720,7 +710,7 @@ HWTEST_F(AmsMgrSchedulerTest, KillApplicationByUid_001, TestSize.Level0) int uid = 0; amsMgrScheduler->KillApplicationByUid(bundleName, uid); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->KillApplicationByUid(bundleName, uid); } @@ -738,7 +728,7 @@ HWTEST_F(AmsMgrSchedulerTest, KillApplicationSelf_001, TestSize.Level0) ASSERT_NE(amsMgrScheduler, nullptr); amsMgrScheduler->KillApplicationSelf(); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->KillApplicationSelf(); } @@ -758,7 +748,7 @@ HWTEST_F(AmsMgrSchedulerTest, GetRunningProcessInfoByToken_001, TestSize.Level0) RunningProcessInfo info; amsMgrScheduler->GetRunningProcessInfoByToken(token, info); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->GetRunningProcessInfoByToken(token, info); } @@ -778,7 +768,7 @@ HWTEST_F(AmsMgrSchedulerTest, GetRunningProcessInfoByPid_001, TestSize.Level0) RunningProcessInfo info; amsMgrScheduler->GetRunningProcessInfoByPid(pid, info); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->GetRunningProcessInfoByPid(pid, info); } @@ -803,7 +793,7 @@ HWTEST_F(AmsMgrSchedulerTest, StartSpecifiedAbility_001, TestSize.Level0) AbilityInfo abilityInfo; amsMgrScheduler->StartSpecifiedAbility(want, abilityInfo); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->StartSpecifiedAbility(want, abilityInfo); } @@ -822,7 +812,7 @@ HWTEST_F(AmsMgrSchedulerTest, RegisterStartSpecifiedAbilityResponse_001, TestSiz sptr response = nullptr; amsMgrScheduler->RegisterStartSpecifiedAbilityResponse(response); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); amsMgrScheduler->RegisterStartSpecifiedAbilityResponse(response); } @@ -843,7 +833,7 @@ HWTEST_F(AmsMgrSchedulerTest, GetApplicationInfoByProcessID_001, TestSize.Level0 int res1 = amsMgrScheduler->GetApplicationInfoByProcessID(pid, application, debug); EXPECT_EQ(res1, ERR_INVALID_OPERATION); amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); - amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); int res2 = amsMgrScheduler->GetApplicationInfoByProcessID(pid, application, debug); EXPECT_NE(res2, ERR_INVALID_OPERATION); } diff --git a/test/unittest/ams_mgr_stub_test/BUILD.gn b/test/unittest/ams_mgr_stub_test/BUILD.gn index b3b328c075..a8655fef2f 100644 --- a/test/unittest/ams_mgr_stub_test/BUILD.gn +++ b/test/unittest/ams_mgr_stub_test/BUILD.gn @@ -28,6 +28,7 @@ ohos_unittest("AmsMgrStubTest") { deps = [ "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -38,7 +39,7 @@ ohos_unittest("AmsMgrStubTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", diff --git a/test/unittest/ams_recent_app_list_test/BUILD.gn b/test/unittest/ams_recent_app_list_test/BUILD.gn index 98dcf60189..57267cb8a6 100644 --- a/test/unittest/ams_recent_app_list_test/BUILD.gn +++ b/test/unittest/ams_recent_app_list_test/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("AmsRecentAppListTest") { "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", ] @@ -64,7 +65,7 @@ ohos_unittest("AmsRecentAppListTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn index 61709853ea..68dee0a85d 100644 --- a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn +++ b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn @@ -54,6 +54,7 @@ ohos_unittest("AmsServiceAppSpawnClientTest") { "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", ] @@ -64,7 +65,7 @@ ohos_unittest("AmsServiceAppSpawnClientTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/unittest/ams_service_event_drive_test/BUILD.gn b/test/unittest/ams_service_event_drive_test/BUILD.gn index b98ffb04ff..5d98bc895e 100644 --- a/test/unittest/ams_service_event_drive_test/BUILD.gn +++ b/test/unittest/ams_service_event_drive_test/BUILD.gn @@ -56,6 +56,7 @@ ohos_unittest("AmsServiceEventDriveTest") { "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", ] @@ -69,7 +70,7 @@ ohos_unittest("AmsServiceEventDriveTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/test/unittest/ams_service_load_ability_process_test/BUILD.gn index 3ff9fa9580..ac3ed31a10 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", @@ -65,7 +66,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/test/unittest/ams_service_startup_test/BUILD.gn b/test/unittest/ams_service_startup_test/BUILD.gn index 17d88332f7..821192c270 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("AmsServiceStartupTest") { "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", ] @@ -64,7 +65,7 @@ ohos_unittest("AmsServiceStartupTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/unittest/app_mgr_client_test/BUILD.gn b/test/unittest/app_mgr_client_test/BUILD.gn index 57674200f3..7c6a76f344 100644 --- a/test/unittest/app_mgr_client_test/BUILD.gn +++ b/test/unittest/app_mgr_client_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("AppMgrClientTest") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/app_mgr_service_dump_test/BUILD.gn b/test/unittest/app_mgr_service_dump_test/BUILD.gn index cd826e4e04..7f348021bd 100644 --- a/test/unittest/app_mgr_service_dump_test/BUILD.gn +++ b/test/unittest/app_mgr_service_dump_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_unittest("app_mgr_service_dump_test") { deps = [ "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/googletest:gtest_main", ] @@ -41,7 +42,7 @@ ohos_unittest("app_mgr_service_dump_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/test/unittest/app_mgr_service_dump_test/app_mgr_service_dump_test.cpp b/test/unittest/app_mgr_service_dump_test/app_mgr_service_dump_test.cpp index 5720a9f137..b6a950d945 100644 --- a/test/unittest/app_mgr_service_dump_test/app_mgr_service_dump_test.cpp +++ b/test/unittest/app_mgr_service_dump_test/app_mgr_service_dump_test.cpp @@ -85,8 +85,9 @@ HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_GetProcessRunningInfosByUserId auto appMgrService = std::make_shared(); EXPECT_NE(appMgrService, nullptr); - appMgrService->handler_ = std::make_shared( - EventRunner::Create("AppMgrServiceDumpTest"), appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); std::vector info; auto result = appMgrService->GetProcessRunningInfosByUserId(info, USER_ID); @@ -106,9 +107,10 @@ HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0100, TestSize.Level1) auto appMgrService = std::make_shared(); EXPECT_NE(appMgrService, nullptr); - auto runner = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME); - EXPECT_NE(runner, nullptr); - appMgrService->handler_ = std::make_shared(runner, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); constexpr int fd(1); std::vector args; @@ -153,9 +155,10 @@ HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0300, TestSize.Level1) auto appMgrService = std::make_shared(); EXPECT_NE(appMgrService, nullptr); - auto runner = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME); - EXPECT_NE(runner, nullptr); - appMgrService->handler_ = std::make_shared(runner, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); constexpr int fd(1); std::vector args; @@ -176,9 +179,10 @@ HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0400, TestSize.Level1) auto appMgrService = std::make_shared(); EXPECT_NE(appMgrService, nullptr); - auto runner = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME); - EXPECT_NE(runner, nullptr); - appMgrService->handler_ = std::make_shared(runner, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + EXPECT_NE(appMgrService->taskHandler_, nullptr); + appMgrService->eventHandler_ = std::make_shared( + appMgrService->taskHandler_, appMgrService->appMgrServiceInner_); constexpr int fd(1); std::vector args; diff --git a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index d7057cbbe3..16e070e5dc 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -50,6 +50,7 @@ ohos_unittest("AMSEventHandlerTest") { "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", "${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", @@ -64,7 +65,7 @@ ohos_unittest("AMSEventHandlerTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/test/unittest/app_mgr_service_event_handler_test/app_mgr_service_event_handler_test.cpp b/test/unittest/app_mgr_service_event_handler_test/app_mgr_service_event_handler_test.cpp index 922f54f1aa..15d2d2b6ba 100644 --- a/test/unittest/app_mgr_service_event_handler_test/app_mgr_service_event_handler_test.cpp +++ b/test/unittest/app_mgr_service_event_handler_test/app_mgr_service_event_handler_test.cpp @@ -31,12 +31,13 @@ namespace AppExecFwk { static bool eventHandlerFlag_ = false; class MockAMSEventHandler : public AMSEventHandler { public: - MockAMSEventHandler(const std::shared_ptr& runner, const std::shared_ptr& ams); + MockAMSEventHandler(const std::shared_ptr& runner, + const std::shared_ptr& appMgrService); virtual ~MockAMSEventHandler(); - void ProcessEvent(const InnerEvent::Pointer& event) override + void ProcessEvent(const AAFwk::EventWrap& event) override { - if (event->GetInnerEventId() == 10) { + if (event.GetEventId() == 10) { eventHandlerFlag_ = true; } } @@ -52,10 +53,10 @@ public: public: std::shared_ptr testAms; std::shared_ptr eventHandler_; - std::shared_ptr runner_; + std::shared_ptr runner_; }; -static void WaitUntilTaskFinished(std::shared_ptr handler) +static void WaitUntilTaskFinished(std::shared_ptr handler) { if (!handler) { return; @@ -66,7 +67,7 @@ static void WaitUntilTaskFinished(std::shared_ptr handler) uint32_t count = 0; std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; // if delay more than 1 second, break @@ -87,7 +88,7 @@ void AMSEventHandlerTest::TearDownTestCase() void AMSEventHandlerTest::SetUp() { - runner_ = EventRunner::Create("AMSEventHandlerTest"); + runner_ = AAFwk::TaskHandlerWrap::CreateQueueHandler("AMSEventHandlerTest"); testAms = std::make_shared(); } @@ -95,8 +96,8 @@ void AMSEventHandlerTest::TearDown() {} MockAMSEventHandler::MockAMSEventHandler( - const std::shared_ptr& runner, const std::shared_ptr& ams) - : AMSEventHandler(runner, ams) + const std::shared_ptr& runner, const std::shared_ptr& appMgrService) + : AMSEventHandler(runner, appMgrService) {} MockAMSEventHandler::~MockAMSEventHandler() @@ -150,14 +151,14 @@ HWTEST_F(AMSEventHandlerTest, app_mgr_service_event_handler_test_002, TestSize.L eventHandler_->SendEvent(20); // waiting callback - WaitUntilTaskFinished(eventHandler_); + WaitUntilTaskFinished(runner_); EXPECT_FALSE(eventHandlerFlag_); // test num == 10 eventHandler_->SendEvent(10); // waiting callback - WaitUntilTaskFinished(eventHandler_); + WaitUntilTaskFinished(runner_); EXPECT_TRUE(eventHandlerFlag_); HILOG_INFO("app_mgr_service_event_handler_test end"); diff --git a/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn b/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn index ab955706b9..4ab595d82e 100644 --- a/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn @@ -36,6 +36,7 @@ ohos_unittest("app_mgr_service_inner_tdd_test") { deps = [ "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -49,7 +50,7 @@ ohos_unittest("app_mgr_service_inner_tdd_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "init:libbegetutil", diff --git a/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp b/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp index 39b8c19626..81579b9900 100644 --- a/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp +++ b/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp @@ -337,39 +337,6 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_008, TestSize.Level1) HILOG_INFO("SendProcessStartEvent_008 end"); } -/** - * @tc.name: SendProcessExitEventTask_001 - * @tc.desc: Verify that the SendProcessExitEventTask interface calls normally - * @tc.type: FUNC - */ -HWTEST_F(AppMgrServiceInnerTest, SendProcessExitEventTask_001, TestSize.Level1) -{ - HILOG_INFO("SendProcessExitEventTask_001 start"); - auto appMgrServiceInner = std::make_shared(); - EXPECT_NE(appMgrServiceInner, nullptr); - auto runner = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME); - appMgrServiceInner->eventHandler_ = std::make_shared(runner, appMgrServiceInner); - - pid_t pid = -1; - time_t exitTime = 0; - int32_t count = 2; - appMgrServiceInner->SendProcessExitEventTask(pid, exitTime, count); - - auto eventTask = [eventRunner = runner] () { - eventRunner->Run(); - }; - std::thread testThread(eventTask); - pid_t pid1 = IPCSkeleton::GetCallingPid(); - appMgrServiceInner->SendProcessExitEventTask(pid1, exitTime, count); - std::this_thread::sleep_for(std::chrono::seconds(1)); - auto stopEventTask = [eventRunner = runner] () { - eventRunner->Stop(); - }; - appMgrServiceInner->eventHandler_->PostTask(stopEventTask, "stopEventTask"); - testThread.join(); - HILOG_INFO("SendProcessExitEventTask_001 end"); -} - /** * @tc.name: SendProcessExitEvent_001 * @tc.desc: Verify that the SendProcessExitEvent interface calls normally diff --git a/test/unittest/app_mgr_service_inner_test/BUILD.gn b/test/unittest/app_mgr_service_inner_test/BUILD.gn index f0f3ee2f6d..78fe7b2626 100644 --- a/test/unittest/app_mgr_service_inner_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_test/BUILD.gn @@ -36,6 +36,7 @@ ohos_unittest("AppMgrServiceInnerTest") { deps = [ "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -49,7 +50,7 @@ ohos_unittest("AppMgrServiceInnerTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "init:libbegetutil", diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 2b338dee8a..a3f8ef5346 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -1733,7 +1733,7 @@ HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_001, TestSize.Level0) appRecord->SetKeepAliveAppState(true, true); appMgrServiceInner->ClearAppRunningData(appRecord, false); - appMgrServiceInner->eventHandler_ = nullptr; + appMgrServiceInner->taskHandler_ = nullptr; appMgrServiceInner->ClearAppRunningData(appRecord, false); appRecord->restartResidentProcCount_ = 0; @@ -1787,7 +1787,7 @@ HWTEST_F(AppMgrServiceInnerTest, HandleTimeOut_001, TestSize.Level0) auto appMgrServiceInner = std::make_shared(); EXPECT_NE(appMgrServiceInner, nullptr); - InnerEvent::Pointer innerEvent = InnerEvent::Pointer(nullptr, nullptr); + AAFwk::EventWrap innerEvent(0); appMgrServiceInner->HandleTimeOut(innerEvent); appMgrServiceInner->appRunningManager_ = nullptr; @@ -1865,7 +1865,7 @@ HWTEST_F(AppMgrServiceInnerTest, HandleTerminateApplicationTimeOut_001, TestSize appRecord->GetPriorityObject()->SetPid(pid); appMgrServiceInner->HandleTerminateApplicationTimeOut(0); - appMgrServiceInner->eventHandler_ = nullptr; + appMgrServiceInner->taskHandler_ = nullptr; appMgrServiceInner->HandleTerminateApplicationTimeOut(0); appMgrServiceInner->appRunningManager_ = nullptr; @@ -2657,7 +2657,7 @@ HWTEST_F(AppMgrServiceInnerTest, KillApplicationByRecord_001, TestSize.Level0) appMgrServiceInner->KillApplicationByRecord(appRecord); appMgrServiceInner->KillApplicationByRecord(appRecord1); - appMgrServiceInner->eventHandler_ = nullptr; + appMgrServiceInner->taskHandler_ = nullptr; appMgrServiceInner->KillApplicationByRecord(appRecord); appMgrServiceInner->KillApplicationByRecord(appRecord1); diff --git a/test/unittest/app_mgr_service_test/BUILD.gn b/test/unittest/app_mgr_service_test/BUILD.gn index 97f6db3407..b5ab7e8a79 100644 --- a/test/unittest/app_mgr_service_test/BUILD.gn +++ b/test/unittest/app_mgr_service_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_unittest("app_mgr_service_test") { deps = [ "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", "//third_party/googletest:gtest_main", ] @@ -42,7 +43,7 @@ ohos_unittest("app_mgr_service_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "init:libbegetutil", diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index eec1abf08e..831e956542 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -31,7 +31,7 @@ public: static void TearDownTestCase(); void SetUp() override; void TearDown() override; - std::shared_ptr runner_ {nullptr}; + std::shared_ptr taskHandler_; }; void AppMgrServiceTest::SetUpTestCase(void) @@ -42,7 +42,7 @@ void AppMgrServiceTest::TearDownTestCase(void) void AppMgrServiceTest::SetUp() { - runner_ = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME); + taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); } void AppMgrServiceTest::TearDown() @@ -128,7 +128,8 @@ HWTEST_F(AppMgrServiceTest, AttachApplication_002, TestSize.Level0) ASSERT_NE(appMgrService, nullptr); sptr app = nullptr; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); appMgrService->AttachApplication(app); } @@ -212,7 +213,7 @@ HWTEST_F(AppMgrServiceTest, AbilityCleaned_002, TestSize.Level0) auto appMgrService = std::make_shared(); ASSERT_NE(appMgrService, nullptr); appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); appMgrService->AbilityCleaned(nullptr); } @@ -247,7 +248,7 @@ HWTEST_F(AppMgrServiceTest, AddAppDeathRecipient_002, TestSize.Level0) ASSERT_NE(appMgrService, nullptr); pid_t pid = 1; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); appMgrService->AddAppDeathRecipient(pid); } @@ -282,7 +283,7 @@ HWTEST_F(AppMgrServiceTest, StartupResidentProcess_002, TestSize.Level0) ASSERT_NE(appMgrService, nullptr); std::vector bundleInfos; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); appMgrService->StartupResidentProcess(bundleInfos); } @@ -299,7 +300,7 @@ HWTEST_F(AppMgrServiceTest, ClearUpApplicationData_001, TestSize.Level0) auto appMgrService = std::make_shared(); std::string bundleName = "bundleName"; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->ClearUpApplicationData(bundleName); EXPECT_EQ(res, ERR_PERMISSION_DENIED); } @@ -334,7 +335,8 @@ HWTEST_F(AppMgrServiceTest, GetAllRunningProcesses_002, TestSize.Level0) auto appMgrService = std::make_shared(); std::vector info; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->GetAllRunningProcesses(info); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -387,7 +389,8 @@ HWTEST_F(AppMgrServiceTest, GetAllRenderProcesses_002, TestSize.Level0) auto appMgrService = std::make_shared(); std::vector info; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->GetAllRenderProcesses(info); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -422,7 +425,8 @@ HWTEST_F(AppMgrServiceTest, NotifyMemoryLevel_002, TestSize.Level0) auto appMgrService = std::make_shared(); int32_t level = 1; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->NotifyMemoryLevel(level); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -458,7 +462,8 @@ HWTEST_F(AppMgrServiceTest, AddAbilityStageDone_002, TestSize.Level0) ASSERT_NE(appMgrService, nullptr); int32_t recordId = 1; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); appMgrService->AddAbilityStageDone(recordId); } @@ -509,7 +514,8 @@ HWTEST_F(AppMgrServiceTest, GetForegroundApplications_002, TestSize.Level0) auto appMgrService = std::make_shared(); std::vector list; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->GetForegroundApplications(list); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -550,7 +556,8 @@ HWTEST_F(AppMgrServiceTest, StartUserTestProcess_002, TestSize.Level0) BundleInfo bundleInfo; int32_t userId = 1; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int res = appMgrService->StartUserTestProcess(want, observer, bundleInfo, userId); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -589,7 +596,8 @@ HWTEST_F(AppMgrServiceTest, FinishUserTest_002, TestSize.Level0) int64_t resultCode = 1; std::string bundleName = "bundleName"; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int res = appMgrService->FinishUserTest(msg, resultCode, bundleName); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -629,7 +637,8 @@ HWTEST_F(AppMgrServiceTest, ScheduleAcceptWantDone_002, TestSize.Level0) Want want; std::string flag = "flag"; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); appMgrService->ScheduleAcceptWantDone(recordId, want, flag); } @@ -665,7 +674,8 @@ HWTEST_F(AppMgrServiceTest, GetAbilityRecordsByProcessID_002, TestSize.Level0) int pid = 1; std::vector> tokens; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); OHOS::AppExecFwk::MockNativeToken::SetNativeToken(); int res = appMgrService->GetAbilityRecordsByProcessID(pid, tokens); EXPECT_NE(res, ERR_INVALID_OPERATION); @@ -681,7 +691,8 @@ HWTEST_F(AppMgrServiceTest, PreStartNWebSpawnProcess_001, TestSize.Level0) { auto appMgrService = std::make_shared(); appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int ret = appMgrService->PreStartNWebSpawnProcess(); EXPECT_NE(ret, ERR_INVALID_OPERATION); } @@ -739,7 +750,8 @@ HWTEST_F(AppMgrServiceTest, StartRenderProcess_002, TestSize.Level0) pid_t renderPid = 1; int32_t crashFd = 1; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->StartRenderProcess( renderParam, ipcFd, sharedFd, crashFd, renderPid); EXPECT_NE(res, ERR_INVALID_OPERATION); @@ -776,7 +788,8 @@ HWTEST_F(AppMgrServiceTest, AttachRenderProcess_002, TestSize.Level0) ASSERT_NE(appMgrService, nullptr); sptr scheduler = nullptr; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); appMgrService->AttachRenderProcess(scheduler); } @@ -812,7 +825,8 @@ HWTEST_F(AppMgrServiceTest, GetRenderProcessTerminationStatus_002, TestSize.Leve pid_t renderPid = 1; int status = 1; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->GetRenderProcessTerminationStatus(renderPid, status); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -847,7 +861,8 @@ HWTEST_F(AppMgrServiceTest, GetConfiguration_002, TestSize.Level0) auto appMgrService = std::make_shared(); Configuration config; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->GetConfiguration(config); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -882,7 +897,8 @@ HWTEST_F(AppMgrServiceTest, UpdateConfiguration_002, TestSize.Level0) auto appMgrService = std::make_shared(); Configuration config; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->UpdateConfiguration(config); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -917,7 +933,8 @@ HWTEST_F(AppMgrServiceTest, RegisterConfigurationObserver_002, TestSize.Level0) auto appMgrService = std::make_shared(); sptr observer = nullptr; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->RegisterConfigurationObserver(observer); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -952,7 +969,8 @@ HWTEST_F(AppMgrServiceTest, UnregisterConfigurationObserver_002, TestSize.Level0 auto appMgrService = std::make_shared(); sptr observer = nullptr; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->UnregisterConfigurationObserver(observer); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -986,7 +1004,8 @@ HWTEST_F(AppMgrServiceTest, BlockAppService_002, TestSize.Level0) { auto appMgrService = std::make_shared(); appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int res = appMgrService->BlockAppService(); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -1022,7 +1041,8 @@ HWTEST_F(AppMgrServiceTest, GetAppRunningStateByBundleName_002, TestSize.Level0) auto appMgrService = std::make_shared(); std::string bundleName = "bundleName"; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); bool res = appMgrService->GetAppRunningStateByBundleName(bundleName); EXPECT_FALSE(res); } @@ -1059,7 +1079,8 @@ HWTEST_F(AppMgrServiceTest, NotifyLoadRepairPatch_002, TestSize.Level0) std::string bundleName = "bundleName"; sptr callback = nullptr; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); OHOS::AppExecFwk::MockNativeToken::SetNativeToken(); int32_t res = appMgrService->NotifyLoadRepairPatch(bundleName, callback); EXPECT_NE(res, ERR_INVALID_OPERATION); @@ -1097,7 +1118,8 @@ HWTEST_F(AppMgrServiceTest, NotifyHotReloadPage_002, TestSize.Level0) std::string bundleName = "bundleName"; sptr callback = nullptr; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); OHOS::AppExecFwk::MockNativeToken::SetNativeToken(); int32_t res = appMgrService->NotifyHotReloadPage(bundleName, callback); EXPECT_NE(res, ERR_INVALID_OPERATION); @@ -1136,7 +1158,8 @@ HWTEST_F(AppMgrServiceTest, SetContinuousTaskProcess_002, TestSize.Level0) int32_t pid = 1; bool isContinuousTask = false; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t res = appMgrService->SetContinuousTaskProcess(pid, isContinuousTask); EXPECT_NE(res, ERR_INVALID_OPERATION); } @@ -1174,7 +1197,8 @@ HWTEST_F(AppMgrServiceTest, NotifyUnLoadRepairPatch_002, TestSize.Level0) std::string bundleName = "bundleName"; sptr callback = nullptr; appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); OHOS::AppExecFwk::MockNativeToken::SetNativeToken(); int32_t res = appMgrService->NotifyUnLoadRepairPatch(bundleName, callback); EXPECT_NE(res, ERR_INVALID_OPERATION); diff --git a/test/unittest/app_running_processes_info_test/BUILD.gn b/test/unittest/app_running_processes_info_test/BUILD.gn index 873d106283..6e6f291df3 100644 --- a/test/unittest/app_running_processes_info_test/BUILD.gn +++ b/test/unittest/app_running_processes_info_test/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("AppRunningProcessesInfoTest") { "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] @@ -62,7 +63,7 @@ ohos_unittest("AppRunningProcessesInfoTest") { "appspawn:appspawn_socket_client", "bundle_framework:appexecfwk_core", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/test/unittest/app_scheduler_test/BUILD.gn b/test/unittest/app_scheduler_test/BUILD.gn index e8e222779f..dda294fc55 100644 --- a/test/unittest/app_scheduler_test/BUILD.gn +++ b/test/unittest/app_scheduler_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("app_scheduler_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbeget_proxy", diff --git a/test/unittest/app_spawn_socket_test/BUILD.gn b/test/unittest/app_spawn_socket_test/BUILD.gn index 1bb3798c8d..264d9a1028 100755 --- a/test/unittest/app_spawn_socket_test/BUILD.gn +++ b/test/unittest/app_spawn_socket_test/BUILD.gn @@ -38,12 +38,13 @@ ohos_unittest("app_spawn_socket_test") { "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] external_deps = [ "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/app_state_observer_manager_test/BUILD.gn b/test/unittest/app_state_observer_manager_test/BUILD.gn index 2c9181d0dc..7553dccb61 100755 --- a/test/unittest/app_state_observer_manager_test/BUILD.gn +++ b/test/unittest/app_state_observer_manager_test/BUILD.gn @@ -40,13 +40,14 @@ ohos_unittest("app_state_observer_manager_test") { "${ability_runtime_path}/services/abilitymgr:abilityms_target", "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/unittest:appmgr_test_source", ] external_deps = [ "ability_runtime:ability_manager", "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/background_task_observer_test/BUILD.gn b/test/unittest/background_task_observer_test/BUILD.gn index 6d99d758c1..1bd49a56fc 100755 --- a/test/unittest/background_task_observer_test/BUILD.gn +++ b/test/unittest/background_task_observer_test/BUILD.gn @@ -53,7 +53,7 @@ ohos_unittest("background_task_observer_test") { "ability_base:zuri", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/call_container_test/BUILD.gn b/test/unittest/call_container_test/BUILD.gn index a627dd7a56..b3b321e0e5 100644 --- a/test/unittest/call_container_test/BUILD.gn +++ b/test/unittest/call_container_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("call_container_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/unittest:abilityms_test_source", @@ -52,7 +53,7 @@ ohos_unittest("call_container_test") { "ability_base:zuri", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/call_container_test/call_container_test.cpp b/test/unittest/call_container_test/call_container_test.cpp index 1a6c8e69c3..ea3ba09f7e 100644 --- a/test/unittest/call_container_test/call_container_test.cpp +++ b/test/unittest/call_container_test/call_container_test.cpp @@ -33,10 +33,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -97,11 +97,11 @@ void CallContainerTest::OnStartAms() abilityMgrServ_->state_ = ServiceRunningState::STATE_RUNNING; - abilityMgrServ_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - EXPECT_TRUE(abilityMgrServ_->eventLoop_); - - abilityMgrServ_->handler_ = std::make_shared(abilityMgrServ_->eventLoop_, abilityMgrServ_); - EXPECT_TRUE(abilityMgrServ_->handler_); + abilityMgrServ_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + EXPECT_TRUE(abilityMgrServ_->taskHandler_); + abilityMgrServ_->eventHandler_ = std::make_shared( + abilityMgrServ_->taskHandler_, abilityMgrServ_); + EXPECT_TRUE(abilityMgrServ_->eventHandler_); // init user controller. abilityMgrServ_->userController_ = std::make_shared(); @@ -118,8 +118,9 @@ void CallContainerTest::OnStartAms() AmsConfigurationParameter::GetInstance().Parse(); abilityMgrServ_->InitMissionListManager(userId, true); - abilityMgrServ_->connectManager_->SetEventHandler(abilityMgrServ_->handler_); - abilityMgrServ_->eventLoop_->Run(); + abilityMgrServ_->connectManager_->SetTaskHandler(abilityMgrServ_->taskHandler_); + abilityMgrServ_->connectManager_->SetEventHandler(abilityMgrServ_->eventHandler_); + auto topAbility = abilityMgrServ_->GetListManagerByUserId(MOCK_MAIN_USER_ID)->GetCurrentTopAbilityLocked(); if (topAbility) { topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND); diff --git a/test/unittest/call_record_test/BUILD.gn b/test/unittest/call_record_test/BUILD.gn index ea57ed7251..201817c09d 100644 --- a/test/unittest/call_record_test/BUILD.gn +++ b/test/unittest/call_record_test/BUILD.gn @@ -47,7 +47,10 @@ ohos_unittest("call_record_test") { "//third_party/googletest:gmock_main", ] - external_deps = [ "ability_base:want" ] + external_deps = [ + "ability_base:want", + "ffrt:libffrt", + ] if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] diff --git a/test/unittest/configuration_test/BUILD.gn b/test/unittest/configuration_test/BUILD.gn index 8a7142dfe2..d2c0145516 100644 --- a/test/unittest/configuration_test/BUILD.gn +++ b/test/unittest/configuration_test/BUILD.gn @@ -42,6 +42,7 @@ ohos_unittest("configuration_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -58,7 +59,7 @@ ohos_unittest("configuration_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "resource_management:global_resmgr", diff --git a/test/unittest/connection_observer_controller_test/BUILD.gn b/test/unittest/connection_observer_controller_test/BUILD.gn index 7eeef9c711..5b4aaac419 100755 --- a/test/unittest/connection_observer_controller_test/BUILD.gn +++ b/test/unittest/connection_observer_controller_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("connection_observer_controller_test") { "ability_runtime:ability_manager", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/connection_record_test/BUILD.gn b/test/unittest/connection_record_test/BUILD.gn index 76e7682bcd..7904c294af 100644 --- a/test/unittest/connection_record_test/BUILD.gn +++ b/test/unittest/connection_record_test/BUILD.gn @@ -56,7 +56,7 @@ ohos_unittest("connection_record_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/connection_state_item_test/BUILD.gn b/test/unittest/connection_state_item_test/BUILD.gn index 65b68725d0..fd6f2ea6c5 100755 --- a/test/unittest/connection_state_item_test/BUILD.gn +++ b/test/unittest/connection_state_item_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("connection_state_item_test") { "ability_base:zuri", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/connection_state_manager_test/BUILD.gn b/test/unittest/connection_state_manager_test/BUILD.gn index 323c88bd4c..3784a6354d 100755 --- a/test/unittest/connection_state_manager_test/BUILD.gn +++ b/test/unittest/connection_state_manager_test/BUILD.gn @@ -56,7 +56,7 @@ ohos_unittest("connection_state_manager_test") { "ability_runtime:ability_manager", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/data_ability_manager_test/BUILD.gn b/test/unittest/data_ability_manager_test/BUILD.gn index 836416609d..09cd63ba36 100644 --- a/test/unittest/data_ability_manager_test/BUILD.gn +++ b/test/unittest/data_ability_manager_test/BUILD.gn @@ -59,7 +59,7 @@ ohos_unittest("data_ability_manager_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbeget_proxy", diff --git a/test/unittest/data_ability_record_test/BUILD.gn b/test/unittest/data_ability_record_test/BUILD.gn index 9244b18d71..769387e933 100644 --- a/test/unittest/data_ability_record_test/BUILD.gn +++ b/test/unittest/data_ability_record_test/BUILD.gn @@ -60,7 +60,7 @@ ohos_unittest("data_ability_record_test") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/data_ability_record_test/data_ability_record_test.cpp b/test/unittest/data_ability_record_test/data_ability_record_test.cpp index 96025bfbce..765a2b99e1 100644 --- a/test/unittest/data_ability_record_test/data_ability_record_test.cpp +++ b/test/unittest/data_ability_record_test/data_ability_record_test.cpp @@ -155,7 +155,7 @@ HWTEST_F(DataAbilityRecordTest, AaFwk_DataAbilityRecord_WaitForLoaded_001, TestS HILOG_INFO("AaFwk_DataAbilityRecord_WaitForLoaded_001 start."); auto dataAbilityRecord = std::make_shared(abilityRequest_); - std::mutex mutex; + ffrt::mutex mutex; system_clock::duration timeout = 800ms; EXPECT_EQ(dataAbilityRecord->WaitForLoaded(mutex, timeout), ERR_INVALID_STATE); @@ -176,7 +176,7 @@ HWTEST_F(DataAbilityRecordTest, AaFwk_DataAbilityRecord_WaitForLoaded_002, TestS HILOG_INFO("AaFwk_DataAbilityRecord_WaitForLoaded_002 start."); auto dataAbilityRecord = std::make_shared(abilityRequest_); - std::mutex mutex; + ffrt::mutex mutex; system_clock::duration timeout = 800ms; EXPECT_EQ(dataAbilityRecord->StartLoading(), ERR_OK); @@ -198,7 +198,7 @@ HWTEST_F(DataAbilityRecordTest, AaFwk_DataAbilityRecord_WaitForLoaded_003, TestS HILOG_INFO("AaFwk_DataAbilityRecord_WaitForLoaded_003 start."); auto dataAbilityRecord = std::make_shared(abilityRequest_); - std::mutex mutex; + ffrt::mutex mutex; system_clock::duration timeout = 800ms; EXPECT_EQ(dataAbilityRecord->StartLoading(), ERR_OK); diff --git a/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn index e7b5874847..7e9a3f5b7f 100644 --- a/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_ext_test/BUILD.gn @@ -39,7 +39,7 @@ ohos_unittest("dataobs_mgr_inner_ext_test") { "ability_base:want", "ability_base:zuri", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/dataobs_mgr_inner_ext_test/mock.h b/test/unittest/dataobs_mgr_inner_ext_test/mock.h index 4906a91b3e..04106b282d 100644 --- a/test/unittest/dataobs_mgr_inner_ext_test/mock.h +++ b/test/unittest/dataobs_mgr_inner_ext_test/mock.h @@ -19,7 +19,6 @@ #include "gmock/gmock.h" #include "semaphore_ex.h" #include "data_ability_observer_stub.h" -#include "event_handler.h" #include "dataobs_mgr_inner_ext.h" namespace OHOS { diff --git a/test/unittest/dataobs_mgr_inner_test/BUILD.gn b/test/unittest/dataobs_mgr_inner_test/BUILD.gn index af5e84d9ab..0a76be3056 100644 --- a/test/unittest/dataobs_mgr_inner_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_inner_test/BUILD.gn @@ -39,7 +39,7 @@ ohos_unittest("dataobs_mgr_inner_test") { "ability_base:want", "ability_base:zuri", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn b/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn index baf3cd685e..a3e7e03f91 100755 --- a/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn @@ -31,6 +31,7 @@ ohos_unittest("dataobs_mgr_service_dump_test") { deps = [ "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_services_path}/dataobsmgr:dataobsms_static", "//third_party/googletest:gtest_main", ] @@ -43,7 +44,7 @@ ohos_unittest("dataobs_mgr_service_dump_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/test/unittest/dataobs_mgr_service_test/BUILD.gn b/test/unittest/dataobs_mgr_service_test/BUILD.gn index 7125fcf781..759a62fe90 100644 --- a/test/unittest/dataobs_mgr_service_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_service_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_unittest("dataobs_mgr_service_test") { } deps = [ "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_services_path}/dataobsmgr:dataobsms_static", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", @@ -39,7 +40,7 @@ ohos_unittest("dataobs_mgr_service_test") { "ability_base:want", "ability_base:zuri", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/dataobs_mgr_service_test/dataobs_mgr_service_test.cpp b/test/unittest/dataobs_mgr_service_test/dataobs_mgr_service_test.cpp index 76657afb8f..9ac0da86be 100644 --- a/test/unittest/dataobs_mgr_service_test/dataobs_mgr_service_test.cpp +++ b/test/unittest/dataobs_mgr_service_test/dataobs_mgr_service_test.cpp @@ -62,26 +62,6 @@ HWTEST_F(DataObsMgrServiceTest, AaFwk_DataObsMgrServiceTest_QueryServiceState_01 GTEST_LOG_(INFO) << "AaFwk_DataObsMgrServiceTest_QueryServiceState_0100 end"; } -/* - * Feature: DataObsMgrService - * Function: GetEventHandler - * SubFunction: NA - * FunctionPoints: DataObsMgrService GetEventHandler - * EnvConditions: NA - * CaseDescription: Verify that the DataObsMgrService could get eventHandler. - */ -HWTEST_F(DataObsMgrServiceTest, AaFwk_DataObsMgrServiceTest_GetEventHandler_0100, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AaFwk_DataObsMgrServiceTest_GetEventHandler_0100 start"; - auto dataObsMgrServer = DelayedSingleton::GetInstance(); - - const std::shared_ptr retVal = dataObsMgrServer->GetEventHandler(); - - EXPECT_EQ(nullptr, retVal.get()); - - GTEST_LOG_(INFO) << "AaFwk_DataObsMgrServiceTest_GetEventHandler_0100 end"; -} - /* * Feature: DataObsMgrService * Function: OnStart @@ -98,7 +78,6 @@ HWTEST_F(DataObsMgrServiceTest, AaFwk_DataObsMgrServiceTest_OnStart_0100, TestSi dataObsMgrServer->OnStart(); EXPECT_EQ(testValue, dataObsMgrServer->QueryServiceState()); - EXPECT_NE(nullptr, dataObsMgrServer->GetEventHandler().get()); GTEST_LOG_(INFO) << "AaFwk_DataObsMgrServiceTest_OnStart_0100 end"; } @@ -272,7 +251,6 @@ HWTEST_F(DataObsMgrServiceTest, AaFwk_DataObsMgrServiceTest_OnStop_0100, TestSiz dataObsMgrServer->OnStop(); EXPECT_EQ(testValue, dataObsMgrServer->QueryServiceState()); - EXPECT_EQ(nullptr, dataObsMgrServer->GetEventHandler().get()); GTEST_LOG_(INFO) << "AaFwk_DataObsMgrServiceTest_OnStop_0100 end"; } diff --git a/test/unittest/dlp_state_item_test/BUILD.gn b/test/unittest/dlp_state_item_test/BUILD.gn index 7b5db58ac7..c5ebacc7ba 100644 --- a/test/unittest/dlp_state_item_test/BUILD.gn +++ b/test/unittest/dlp_state_item_test/BUILD.gn @@ -57,7 +57,7 @@ ohos_unittest("dlp_state_item_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/dlp_utils_test/BUILD.gn b/test/unittest/dlp_utils_test/BUILD.gn index 34bf9385d0..9794a441c9 100644 --- a/test/unittest/dlp_utils_test/BUILD.gn +++ b/test/unittest/dlp_utils_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_unittest("dlp_utils_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "ffrt:libffrt", "ipc:ipc_core", ] } diff --git a/test/unittest/form_extension_context_test/BUILD.gn b/test/unittest/form_extension_context_test/BUILD.gn index a01767b358..e07fddda46 100644 --- a/test/unittest/form_extension_context_test/BUILD.gn +++ b/test/unittest/form_extension_context_test/BUILD.gn @@ -61,7 +61,7 @@ ohos_unittest("form_extension_context_test") { "ability_runtime:runtime", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbeget_proxy", diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index 55deb60a02..7cfa0dfca4 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -114,7 +114,7 @@ ohos_unittest("ability_test") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", @@ -405,6 +405,7 @@ ohos_unittest("data_ability_helper_test") { "data_share:datashare_common", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", @@ -461,6 +462,7 @@ ohos_unittest("data_ability_helper_impl_test") { "data_share:datashare_common", "data_share:datashare_consumer", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", diff --git a/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_impl_test.cpp index 34903b3bc9..78f0ecf04c 100644 --- a/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_impl_test.cpp @@ -206,7 +206,7 @@ HWTEST_F(DataAbilityHelperImplForObserverTest, AppExecFwk_DataAbilityHelperImpl_Creator_0700, Function | MediumTest | Level1) { GTEST_LOG_(INFO) << "AppExecFwk_DataAbilityHelperImpl_Creator_0700 start"; - std::shared_ptr context = + std::shared_ptr context = std::make_shared(); std::shared_ptr uri = nullptr; bool tryBind = false; @@ -224,7 +224,7 @@ HWTEST_F(DataAbilityHelperImplForObserverTest, AppExecFwk_DataAbilityHelperImpl_Creator_0800, Function | MediumTest | Level1) { GTEST_LOG_(INFO) << "AppExecFwk_DataAbilityHelperImpl_Creator_0800 start"; - std::shared_ptr context = + std::shared_ptr context = std::make_shared(); std::shared_ptr uri = std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); @@ -379,7 +379,7 @@ HWTEST_F(DataAbilityHelperImplForObserverTest, { GTEST_LOG_(INFO) << "AppExecFwk_DataAbilityHelperImpl_Creator_1600 start"; std::weak_ptr abilityRecord; - std::shared_ptr context = + std::shared_ptr context = std::make_shared(); std::shared_ptr uri = std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); diff --git a/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_test.cpp b/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_test.cpp index 8d55ce863b..88045273e6 100644 --- a/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_test.cpp @@ -816,7 +816,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Query_0400, F NativeRdb::DataAbilityPredicates predicates("predicatestest"); std::weak_ptr abilityRecord; sptr remote = new OHOS::AAFwk::Token(abilityRecord); - + dataAbilityHelper->dataShareHelper_ = DataShare::DataShareHelper::Creator(remote, DATA_SHARE_URI); // Test to AbilityThread interface auto returnQuery = diff --git a/test/unittest/free_install_manager_test/BUILD.gn b/test/unittest/free_install_manager_test/BUILD.gn index 182b203fb2..cd5a0ba251 100644 --- a/test/unittest/free_install_manager_test/BUILD.gn +++ b/test/unittest/free_install_manager_test/BUILD.gn @@ -44,6 +44,7 @@ ohos_unittest("free_install_manager_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -59,7 +60,7 @@ ohos_unittest("free_install_manager_test") { "background_task_mgr:bgtaskmgr_innerkits", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/free_install_manager_test/free_install_manager_test.cpp b/test/unittest/free_install_manager_test/free_install_manager_test.cpp index 54887931bc..28622f25fc 100644 --- a/test/unittest/free_install_manager_test/free_install_manager_test.cpp +++ b/test/unittest/free_install_manager_test/free_install_manager_test.cpp @@ -64,8 +64,8 @@ void FreeInstallTest::TearDownTestCase(void) void FreeInstallTest::SetUp(void) { freeInstallManager_ = std::make_shared(abilityMs_); - abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - abilityMs_->handler_ = std::make_shared(abilityMs_->eventLoop_, abilityMs_); + abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + abilityMs_->eventHandler_ = std::make_shared(abilityMs_->taskHandler_, abilityMs_); } void FreeInstallTest::TearDown(void) @@ -90,10 +90,10 @@ void FreeInstallTest::WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = abilityMs_->handler_; + auto handler = abilityMs_->taskHandler_; std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -123,7 +123,7 @@ HWTEST_F(FreeInstallTest, FreeInstall_StartFreeInstall_001, TestSize.Level1) auto task = [manager = freeInstallManager_, want, userId, requestCode, callerToken, &res]() { res = manager->StartFreeInstall(want, userId, requestCode, callerToken); }; - abilityMs_->handler_->PostTask(task); + abilityMs_->taskHandler_->SubmitTask(task); usleep(100000); // from freeInstallManager_->freeInstallList_ find startInstallTime @@ -179,7 +179,7 @@ HWTEST_F(FreeInstallTest, FreeInstall_StartFreeInstall_003, TestSize.Level1) auto task = [manager = freeInstallManager_, want, userId, requestCode, callerToken, &res]() { res = manager->StartFreeInstall(want, userId, requestCode, callerToken); }; - abilityMs_->handler_->PostTask(task); + abilityMs_->taskHandler_->SubmitTask(task); usleep(100000); // from freeInstallManager_->freeInstallList_ find startInstallTime diff --git a/test/unittest/image_info_test/BUILD.gn b/test/unittest/image_info_test/BUILD.gn index ebe03db324..aaa724867c 100755 --- a/test/unittest/image_info_test/BUILD.gn +++ b/test/unittest/image_info_test/BUILD.gn @@ -53,7 +53,7 @@ ohos_unittest("image_info_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/implicit_start_processor_test/BUILD.gn b/test/unittest/implicit_start_processor_test/BUILD.gn index 7a78b01e60..0a5653675f 100755 --- a/test/unittest/implicit_start_processor_test/BUILD.gn +++ b/test/unittest/implicit_start_processor_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("implicit_start_processor_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbeget_proxy", diff --git a/test/unittest/lifecycle_deal_test/BUILD.gn b/test/unittest/lifecycle_deal_test/BUILD.gn index 498b88298b..f34b3cb94c 100644 --- a/test/unittest/lifecycle_deal_test/BUILD.gn +++ b/test/unittest/lifecycle_deal_test/BUILD.gn @@ -58,7 +58,7 @@ ohos_unittest("lifecycle_deal_test") { "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_core", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/lifecycle_test/BUILD.gn b/test/unittest/lifecycle_test/BUILD.gn index 2f9c5ecde8..5dc9d9b88e 100644 --- a/test/unittest/lifecycle_test/BUILD.gn +++ b/test/unittest/lifecycle_test/BUILD.gn @@ -42,6 +42,7 @@ ohos_unittest("lifecycle_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -56,7 +57,7 @@ ohos_unittest("lifecycle_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/lifecycle_test/lifecycle_test.cpp b/test/unittest/lifecycle_test/lifecycle_test.cpp index 5138194aff..e6fd3f9a25 100644 --- a/test/unittest/lifecycle_test/lifecycle_test.cpp +++ b/test/unittest/lifecycle_test/lifecycle_test.cpp @@ -41,14 +41,14 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); if (handler == nullptr) { GTEST_LOG_(ERROR) << "handler is nullptr"; return; } std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -96,14 +96,14 @@ void LifecycleTest::OnStartabilityAms() } abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; - abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - EXPECT_TRUE(abilityMs_->eventLoop_); - abilityMs_->handler_ = std::make_shared(abilityMs_->eventLoop_, abilityMs_); + abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + abilityMs_->eventHandler_ = std::make_shared(abilityMs_->taskHandler_, abilityMs_); abilityMs_->connectManager_ = std::make_shared(0); abilityMs_->connectManagers_.emplace(0, abilityMs_->connectManager_); - EXPECT_TRUE(abilityMs_->handler_); + EXPECT_TRUE(abilityMs_->taskHandler_); EXPECT_TRUE(abilityMs_->connectManager_); - abilityMs_->connectManager_->SetEventHandler(abilityMs_->handler_); + abilityMs_->connectManager_->SetTaskHandler(abilityMs_->taskHandler_); + abilityMs_->connectManager_->SetEventHandler(abilityMs_->eventHandler_); abilityMs_->dataAbilityManager_ = std::make_shared(); abilityMs_->dataAbilityManagers_.emplace(0, abilityMs_->dataAbilityManager_); EXPECT_TRUE(abilityMs_->dataAbilityManager_); @@ -112,7 +112,6 @@ void LifecycleTest::OnStartabilityAms() abilityMs_->currentMissionListManager_->Init(); abilityMs_->pendingWantManager_ = std::make_shared(); EXPECT_TRUE(abilityMs_->pendingWantManager_); - abilityMs_->eventLoop_->Run(); return; } diff --git a/test/unittest/mission_data_storage_test/BUILD.gn b/test/unittest/mission_data_storage_test/BUILD.gn index 3b223492c0..1e5ec99246 100755 --- a/test/unittest/mission_data_storage_test/BUILD.gn +++ b/test/unittest/mission_data_storage_test/BUILD.gn @@ -41,6 +41,7 @@ ohos_unittest("mission_data_storage_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -53,7 +54,7 @@ ohos_unittest("mission_data_storage_test") { "ability_runtime:ability_manager", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/mission_data_storage_test/mission_data_storage_test.cpp b/test/unittest/mission_data_storage_test/mission_data_storage_test.cpp index dee5e379d7..80d7eefa86 100755 --- a/test/unittest/mission_data_storage_test/mission_data_storage_test.cpp +++ b/test/unittest/mission_data_storage_test/mission_data_storage_test.cpp @@ -42,22 +42,6 @@ void MissionDataStorageTest::SetUp(void) void MissionDataStorageTest::TearDown(void) {} -/* - * Feature: MissionDataStorage - * Function: SetEventHandler - * SubFunction: NA - * FunctionPoints: MissionDataStorage SetEventHandler - * EnvConditions: NA - * CaseDescription: Verify SetEventHandler - */ -HWTEST_F(MissionDataStorageTest, SetEventHandler_001, TestSize.Level1) -{ - auto missionDataStorage = std::make_shared(); - EXPECT_NE(missionDataStorage, nullptr); - auto handler = std::make_shared(EventRunner::Create()); - missionDataStorage->SetEventHandler(handler); -} - /* * Feature: MissionDataStorage * Function: SaveMissionInfo diff --git a/test/unittest/mission_info_mgr_test/BUILD.gn b/test/unittest/mission_info_mgr_test/BUILD.gn index f21be7bd7f..7c626e568c 100755 --- a/test/unittest/mission_info_mgr_test/BUILD.gn +++ b/test/unittest/mission_info_mgr_test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("mission_info_mgr_test") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/mission_info_test/BUILD.gn b/test/unittest/mission_info_test/BUILD.gn index f86ae67178..b100f9709f 100755 --- a/test/unittest/mission_info_test/BUILD.gn +++ b/test/unittest/mission_info_test/BUILD.gn @@ -53,7 +53,7 @@ ohos_unittest("mission_info_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/mission_list_dump_test/BUILD.gn b/test/unittest/mission_list_dump_test/BUILD.gn index 392ba86ae8..6dd615ff90 100644 --- a/test/unittest/mission_list_dump_test/BUILD.gn +++ b/test/unittest/mission_list_dump_test/BUILD.gn @@ -32,6 +32,7 @@ ohos_unittest("mission_list_dump_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/mission_list_manager_dump_test/BUILD.gn b/test/unittest/mission_list_manager_dump_test/BUILD.gn index 35fd0a38d4..732b0537b4 100644 --- a/test/unittest/mission_list_manager_dump_test/BUILD.gn +++ b/test/unittest/mission_list_manager_dump_test/BUILD.gn @@ -35,7 +35,7 @@ ohos_unittest("mission_list_manager_dump_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/mission_list_manager_test/BUILD.gn b/test/unittest/mission_list_manager_test/BUILD.gn index b0857a84f7..64676225da 100644 --- a/test/unittest/mission_list_manager_test/BUILD.gn +++ b/test/unittest/mission_list_manager_test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("mission_list_manager_test") { "ability_base:zuri", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/mission_list_manager_ut_test/BUILD.gn b/test/unittest/mission_list_manager_ut_test/BUILD.gn index b1b2fc2fc8..d178a2dbd4 100644 --- a/test/unittest/mission_list_manager_ut_test/BUILD.gn +++ b/test/unittest/mission_list_manager_ut_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("mission_list_manager_ut_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "relational_store:native_appdatafwk", diff --git a/test/unittest/mission_list_test/BUILD.gn b/test/unittest/mission_list_test/BUILD.gn index 1d65b82b84..ed14f17378 100644 --- a/test/unittest/mission_list_test/BUILD.gn +++ b/test/unittest/mission_list_test/BUILD.gn @@ -52,7 +52,7 @@ ohos_unittest("mission_list_test") { "ability_base:zuri", "access_token:libaccesstoken_sdk", "c_utils:utils", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] @@ -95,7 +95,7 @@ ohos_unittest("mission_list_test_call") { "bundle_framework:appexecfwk_base", "c_utils:utilsbase", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", ] diff --git a/test/unittest/mission_listener_proxy_test/BUILD.gn b/test/unittest/mission_listener_proxy_test/BUILD.gn index 3c8bf477cd..b5dc89c89d 100755 --- a/test/unittest/mission_listener_proxy_test/BUILD.gn +++ b/test/unittest/mission_listener_proxy_test/BUILD.gn @@ -53,7 +53,7 @@ ohos_unittest("mission_listener_proxy_test") { "ability_base:zuri", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/mission_listener_test/BUILD.gn b/test/unittest/mission_listener_test/BUILD.gn index 15706fdcbb..49b189d4d3 100644 --- a/test/unittest/mission_listener_test/BUILD.gn +++ b/test/unittest/mission_listener_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("mission_listener_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/mission_test/BUILD.gn b/test/unittest/mission_test/BUILD.gn index 436fc2db84..548f76c1c4 100644 --- a/test/unittest/mission_test/BUILD.gn +++ b/test/unittest/mission_test/BUILD.gn @@ -53,7 +53,7 @@ ohos_unittest("mission_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/pending_want_key_test/BUILD.gn b/test/unittest/pending_want_key_test/BUILD.gn index 03e241a175..0b852518b4 100644 --- a/test/unittest/pending_want_key_test/BUILD.gn +++ b/test/unittest/pending_want_key_test/BUILD.gn @@ -46,7 +46,7 @@ ohos_unittest("pending_want_key_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/pending_want_manager_dump_test/BUILD.gn b/test/unittest/pending_want_manager_dump_test/BUILD.gn index b11b2680bb..776be7a8f7 100644 --- a/test/unittest/pending_want_manager_dump_test/BUILD.gn +++ b/test/unittest/pending_want_manager_dump_test/BUILD.gn @@ -36,7 +36,7 @@ ohos_unittest("pending_want_manager_dump_test") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/pending_want_manager_test/BUILD.gn b/test/unittest/pending_want_manager_test/BUILD.gn index 3cf40a6f1b..62aefa0733 100644 --- a/test/unittest/pending_want_manager_test/BUILD.gn +++ b/test/unittest/pending_want_manager_test/BUILD.gn @@ -59,7 +59,7 @@ ohos_unittest("pending_want_manager_test") { "access_token:libtoken_setproc", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/pending_want_record_test/BUILD.gn b/test/unittest/pending_want_record_test/BUILD.gn index 3b6b500ac0..399e12ef03 100644 --- a/test/unittest/pending_want_record_test/BUILD.gn +++ b/test/unittest/pending_want_record_test/BUILD.gn @@ -57,7 +57,7 @@ ohos_unittest("pending_want_record_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/pending_want_test/BUILD.gn b/test/unittest/pending_want_test/BUILD.gn index 7698499172..d9897a88a7 100644 --- a/test/unittest/pending_want_test/BUILD.gn +++ b/test/unittest/pending_want_test/BUILD.gn @@ -57,7 +57,7 @@ ohos_unittest("pending_want_test") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", diff --git a/test/unittest/remote_mission_listener_proxy_test/BUILD.gn b/test/unittest/remote_mission_listener_proxy_test/BUILD.gn index 0e2f466b3c..31fbb815c9 100755 --- a/test/unittest/remote_mission_listener_proxy_test/BUILD.gn +++ b/test/unittest/remote_mission_listener_proxy_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("remote_mission_listener_proxy_test") { "ability_base:zuri", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/resident_process_manager_test/BUILD.gn b/test/unittest/resident_process_manager_test/BUILD.gn index fa1ab8ce80..0d3d637fec 100755 --- a/test/unittest/resident_process_manager_test/BUILD.gn +++ b/test/unittest/resident_process_manager_test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("resident_process_manager_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbeget_proxy", diff --git a/test/unittest/running_infos_test/BUILD.gn b/test/unittest/running_infos_test/BUILD.gn index 5f4896265b..9781c063dc 100644 --- a/test/unittest/running_infos_test/BUILD.gn +++ b/test/unittest/running_infos_test/BUILD.gn @@ -45,6 +45,7 @@ ohos_unittest("running_infos_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -61,7 +62,7 @@ ohos_unittest("running_infos_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/running_infos_test/running_infos_test.cpp b/test/unittest/running_infos_test/running_infos_test.cpp index f1d736b3a0..4e23e9c7f7 100644 --- a/test/unittest/running_infos_test/running_infos_test.cpp +++ b/test/unittest/running_infos_test/running_infos_test.cpp @@ -48,10 +48,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -84,11 +84,10 @@ void RunningInfosTest::OnStartAms() abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; - abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - EXPECT_TRUE(abilityMs_->eventLoop_); - - abilityMs_->handler_ = std::make_shared(abilityMs_->eventLoop_, abilityMs_); - EXPECT_TRUE(abilityMs_->handler_); + abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + EXPECT_TRUE(abilityMs_->taskHandler_); + abilityMs_->eventHandler_ = std::make_shared(abilityMs_->taskHandler_, abilityMs_); + EXPECT_TRUE(abilityMs_->eventHandler_); // init user controller. abilityMs_->userController_ = std::make_shared(); @@ -104,8 +103,8 @@ void RunningInfosTest::OnStartAms() AmsConfigurationParameter::GetInstance().Parse(); abilityMs_->InitMissionListManager(userId, true); - abilityMs_->connectManager_->SetEventHandler(abilityMs_->handler_); - abilityMs_->eventLoop_->Run(); + abilityMs_->connectManager_->SetTaskHandler(abilityMs_->taskHandler_); + abilityMs_->connectManager_->SetEventHandler(abilityMs_->eventHandler_); WaitUntilTaskFinished(); auto topAbility = abilityMs_->GetListManagerByUserId(MOCK_MAIN_USER_ID)->GetCurrentTopAbilityLocked(); if (topAbility) { @@ -119,8 +118,8 @@ void RunningInfosTest::OnStartAms() void RunningInfosTest::OnStopAms() { - abilityMs_->eventLoop_.reset(); - abilityMs_->handler_.reset(); + abilityMs_->eventHandler_.reset(); + abilityMs_->taskHandler_.reset(); abilityMs_->state_ = ServiceRunningState::STATE_NOT_START; } diff --git a/test/unittest/sender_info_test/BUILD.gn b/test/unittest/sender_info_test/BUILD.gn index 3ee739b765..4078bcca72 100644 --- a/test/unittest/sender_info_test/BUILD.gn +++ b/test/unittest/sender_info_test/BUILD.gn @@ -52,7 +52,7 @@ ohos_unittest("sender_info_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/service_extension_context_test/BUILD.gn b/test/unittest/service_extension_context_test/BUILD.gn index 948e5a79cb..f568253b01 100644 --- a/test/unittest/service_extension_context_test/BUILD.gn +++ b/test/unittest/service_extension_context_test/BUILD.gn @@ -62,7 +62,7 @@ ohos_unittest("service_extension_context_test") { "ability_runtime:runtime", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbeget_proxy", diff --git a/test/unittest/specified_mission_list_test/BUILD.gn b/test/unittest/specified_mission_list_test/BUILD.gn index c561bc533c..1c2b015466 100644 --- a/test/unittest/specified_mission_list_test/BUILD.gn +++ b/test/unittest/specified_mission_list_test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("specified_mission_list_test") { "ability_base:zuri", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/start_option_display_id_test/BUILD.gn b/test/unittest/start_option_display_id_test/BUILD.gn index 3484b95e3e..ab467dcf0b 100644 --- a/test/unittest/start_option_display_id_test/BUILD.gn +++ b/test/unittest/start_option_display_id_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_unittest("start_option_display_id_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -60,7 +61,7 @@ ohos_unittest("start_option_display_id_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/start_option_display_id_test/start_option_display_id_test.cpp b/test/unittest/start_option_display_id_test/start_option_display_id_test.cpp index d07c0215dc..3274969130 100644 --- a/test/unittest/start_option_display_id_test/start_option_display_id_test.cpp +++ b/test/unittest/start_option_display_id_test/start_option_display_id_test.cpp @@ -47,10 +47,10 @@ static void WaitUntilTaskFinished() const uint32_t maxRetryCount = 1000; const uint32_t sleepTime = 1000; uint32_t count = 0; - auto handler = OHOS::DelayedSingleton::GetInstance()->GetEventHandler(); + auto handler = OHOS::DelayedSingleton::GetInstance()->GetTaskHandler(); std::atomic taskCalled(false); auto f = [&taskCalled]() { taskCalled.store(true); }; - if (handler->PostTask(f)) { + if (handler->SubmitTask(f)) { while (!taskCalled.load()) { ++count; if (count >= maxRetryCount) { @@ -117,11 +117,10 @@ void StartOptionDisplayIdTest::OnStartAms() abilityMs_->state_ = ServiceRunningState::STATE_RUNNING; - abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE); - EXPECT_TRUE(abilityMs_->eventLoop_); - - abilityMs_->handler_ = std::make_shared(abilityMs_->eventLoop_, abilityMs_); - EXPECT_TRUE(abilityMs_->handler_); + abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE); + EXPECT_TRUE(abilityMs_->taskHandler_); + abilityMs_->eventHandler_ = std::make_shared(abilityMs_->taskHandler_, abilityMs_); + EXPECT_TRUE(abilityMs_->eventHandler_); // init user controller. abilityMs_->userController_ = std::make_shared(); @@ -138,8 +137,8 @@ void StartOptionDisplayIdTest::OnStartAms() AmsConfigurationParameter::GetInstance().Parse(); abilityMs_->InitMissionListManager(userId, true); - abilityMs_->connectManager_->SetEventHandler(abilityMs_->handler_); - abilityMs_->eventLoop_->Run(); + abilityMs_->connectManager_->SetTaskHandler(abilityMs_->taskHandler_); + abilityMs_->connectManager_->SetEventHandler(abilityMs_->eventHandler_); WaitUntilTaskFinished(); return; @@ -150,8 +149,8 @@ void StartOptionDisplayIdTest::OnStartAms() void StartOptionDisplayIdTest::OnStopAms() { - abilityMs_->eventLoop_.reset(); - abilityMs_->handler_.reset(); + abilityMs_->eventHandler_.reset(); + abilityMs_->taskHandler_.reset(); abilityMs_->state_ = ServiceRunningState::STATE_NOT_START; } diff --git a/test/unittest/stop_user_callback_proxy_test/BUILD.gn b/test/unittest/stop_user_callback_proxy_test/BUILD.gn index 5a3844bcc4..f3b49ca825 100755 --- a/test/unittest/stop_user_callback_proxy_test/BUILD.gn +++ b/test/unittest/stop_user_callback_proxy_test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("stop_user_callback_proxy_test") { "ability_runtime:ability_manager", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/stop_user_callback_stub_test/BUILD.gn b/test/unittest/stop_user_callback_stub_test/BUILD.gn index b469b12c45..67fac627f3 100644 --- a/test/unittest/stop_user_callback_stub_test/BUILD.gn +++ b/test/unittest/stop_user_callback_stub_test/BUILD.gn @@ -55,7 +55,7 @@ ohos_unittest("stop_user_callback_stub_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", diff --git a/test/unittest/task_data_persistence_mgr_test/BUILD.gn b/test/unittest/task_data_persistence_mgr_test/BUILD.gn index c1723d60e6..94204527f0 100755 --- a/test/unittest/task_data_persistence_mgr_test/BUILD.gn +++ b/test/unittest/task_data_persistence_mgr_test/BUILD.gn @@ -53,7 +53,7 @@ ohos_unittest("task_data_persistence_mgr_test") { "ability_runtime:ability_manager", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn index 22bc2ac2fd..7354947461 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_unittest("ui_ability_lifecycle_manager_test") { "bundle_framework:appexecfwk_core", "c_utils:utils", "dsoftbus:softbus_client", + "ffrt:libffrt", "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", diff --git a/test/unittest/user_controller_test/BUILD.gn b/test/unittest/user_controller_test/BUILD.gn index 73a7d98df6..bced1a9050 100644 --- a/test/unittest/user_controller_test/BUILD.gn +++ b/test/unittest/user_controller_test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("user_controller_test") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "window_manager:scene_session", diff --git a/test/unittest/user_event_handler_test/BUILD.gn b/test/unittest/user_event_handler_test/BUILD.gn index c7b5c20a7c..5fc52fa3f0 100755 --- a/test/unittest/user_event_handler_test/BUILD.gn +++ b/test/unittest/user_event_handler_test/BUILD.gn @@ -41,6 +41,7 @@ ohos_unittest("user_event_handler_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -52,7 +53,7 @@ ohos_unittest("user_event_handler_test") { "ability_base:zuri", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/user_event_handler_test/user_event_handler_test.cpp b/test/unittest/user_event_handler_test/user_event_handler_test.cpp index 0bc9c9db1b..54f5b894b4 100755 --- a/test/unittest/user_event_handler_test/user_event_handler_test.cpp +++ b/test/unittest/user_event_handler_test/user_event_handler_test.cpp @@ -19,7 +19,6 @@ #undef private using namespace testing::ext; -using namespace OHOS::AppExecFwk; namespace OHOS { namespace AAFwk { @@ -50,28 +49,10 @@ void UserEventHandlerTest::TearDown(void) */ HWTEST_F(UserEventHandlerTest, ProcessEvent_001, TestSize.Level1) { - std::shared_ptr runner; + std::shared_ptr runner; std::weak_ptr owner; std::shared_ptr handler = std::make_shared(runner, owner); - InnerEvent::Pointer event = InnerEvent::Get(); - event.reset(); - handler->ProcessEvent(event); -} - -/* - * Feature: UserEventHandler - * Function: ProcessEvent - * SubFunction: NA - * FunctionPoints: UserEventHandler ProcessEvent - * EnvConditions: NA - * CaseDescription: Verify ProcessEvent - */ -HWTEST_F(UserEventHandlerTest, ProcessEvent_002, TestSize.Level1) -{ - std::shared_ptr runner; - std::weak_ptr owner; - std::shared_ptr handler = std::make_shared(runner, owner); - InnerEvent::Pointer event = InnerEvent::Get(); + EventWrap event(0); handler->ProcessEvent(event); } } // namespace AAFwk diff --git a/test/unittest/want_agent_test/BUILD.gn b/test/unittest/want_agent_test/BUILD.gn index c98eb0ea63..e4f0949d7c 100644 --- a/test/unittest/want_agent_test/BUILD.gn +++ b/test/unittest/want_agent_test/BUILD.gn @@ -45,7 +45,7 @@ ohos_unittest("want_agent_test") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_core", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", diff --git a/test/unittest/want_receiver_proxy_test/BUILD.gn b/test/unittest/want_receiver_proxy_test/BUILD.gn index bb59c9c77b..1c6ab9d04f 100644 --- a/test/unittest/want_receiver_proxy_test/BUILD.gn +++ b/test/unittest/want_receiver_proxy_test/BUILD.gn @@ -53,7 +53,7 @@ ohos_unittest("want_receiver_proxy_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/want_receiver_stub_test/BUILD.gn b/test/unittest/want_receiver_stub_test/BUILD.gn index 6f294f4763..b98a770668 100644 --- a/test/unittest/want_receiver_stub_test/BUILD.gn +++ b/test/unittest/want_receiver_stub_test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("want_receiver_stub_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/want_sender_info_test/BUILD.gn b/test/unittest/want_sender_info_test/BUILD.gn index 5b31f11501..88967ab2a5 100644 --- a/test/unittest/want_sender_info_test/BUILD.gn +++ b/test/unittest/want_sender_info_test/BUILD.gn @@ -56,7 +56,7 @@ ohos_unittest("want_sender_info_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/want_sender_proxy_test/BUILD.gn b/test/unittest/want_sender_proxy_test/BUILD.gn index cae7791f70..e4bc83a2bc 100644 --- a/test/unittest/want_sender_proxy_test/BUILD.gn +++ b/test/unittest/want_sender_proxy_test/BUILD.gn @@ -53,7 +53,7 @@ ohos_unittest("want_sender_proxy_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/want_sender_stub_test/BUILD.gn b/test/unittest/want_sender_stub_test/BUILD.gn index 95d69e2178..82089a0df4 100644 --- a/test/unittest/want_sender_stub_test/BUILD.gn +++ b/test/unittest/want_sender_stub_test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("want_sender_stub_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] diff --git a/test/unittest/wants_info_test/BUILD.gn b/test/unittest/wants_info_test/BUILD.gn index c92405cc6a..2783bccbbe 100644 --- a/test/unittest/wants_info_test/BUILD.gn +++ b/test/unittest/wants_info_test/BUILD.gn @@ -52,7 +52,7 @@ ohos_unittest("wants_info_test") { "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", ] From d6bd2a094d9f32f45698eadf0738a1f81632488d Mon Sep 17 00:00:00 2001 From: shaoxianqiang <1018410944@qq.com> Date: Tue, 27 Jun 2023 23:34:51 +0800 Subject: [PATCH 27/52] =?UTF-8?q?codecheck=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shaoxianqiang <1018410944@qq.com> Change-Id: I64c2492fae04f311eb6d3055d14d5d01012e2ee5 --- .../app/js_app_manager/js_app_manager.cpp | 51 ++++++------------- services/appmgr/src/app_mgr_service.cpp | 4 +- services/appmgr/src/app_mgr_service_inner.cpp | 2 +- .../include/mock_app_mgr_service.h | 3 +- .../include/mock_app_mgr_service.h | 3 +- 5 files changed, 23 insertions(+), 40 deletions(-) diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index bee5bacc8f..f91a06a687 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -538,7 +538,7 @@ private: NativeValue* OnGetProcessMemoryByPid(NativeEngine& engine, const NativeCallbackInfo& info) { - HILOG_INFO("%{public}s is called", __FUNCTION__); + HILOG_DEBUG("is called"); if (info.argc < ARGC_ONE) { HILOG_ERROR("Params not match"); ThrowTooFewParametersError(engine); @@ -564,7 +564,7 @@ private: if (ret == 0) { task.ResolveWithNoError(engine, CreateJsValue(engine, memSize)); } else { - task.Reject(engine, CreateJsErrorByNativeErr(engine, ret, "Get Process Memory by pid failed.")); + task.Reject(engine, CreateJsErrorByNativeErr(engine, ret)); } }; @@ -577,7 +577,7 @@ private: NativeValue* OnGetRunningProcessInfoByBundleName(NativeEngine& engine, const NativeCallbackInfo& info) { - HILOG_INFO("%{public}s is called", __FUNCTION__); + HILOG_DEBUG("is called"); if (info.argc < ARGC_ONE) { HILOG_ERROR("Params number less then one"); ThrowTooFewParametersError(engine); @@ -587,38 +587,19 @@ private: std::string bundleName; int userId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE; bool isPromiseType = false; - bool argCheckPass = true; - do { - if (!ConvertFromJsValue(engine, info.argv[0], bundleName)) { - HILOG_ERROR("First parameter must be string"); - argCheckPass = false; - break; - } - if (info.argc == ARGC_ONE) { - isPromiseType = true; - } else if (info.argc == ARGC_TWO) { - if (ConvertFromJsValue(engine, info.argv[1], userId)) { - isPromiseType = true; - } else { - HILOG_INFO("Second parameter must be async callback"); - } - } else if (info.argc == ARGC_THREE) { - if (ConvertFromJsValue(engine, info.argv[1], userId)) { - HILOG_INFO("Third parameter must be async callback"); - } else { - HILOG_WARN("Must input userid and use callback when argc is three."); - argCheckPass = false; - break; - } - } else { - HILOG_WARN("Argc cannot be larger then 3."); - argCheckPass = false; - break; - } - } while (false); - - if (!argCheckPass) { + if (!ConvertFromJsValue(engine, info.argv[0], bundleName)) { + HILOG_ERROR("First parameter must be string"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + if (info.argc == ARGC_ONE) { + isPromiseType = true; + } else if (info.argc == ARGC_TWO && ConvertFromJsValue(engine, info.argv[1], userId)) { + isPromiseType = true; + } else if (info.argc == ARGC_THREE && ConvertFromJsValue(engine, info.argv[1], userId)) { + HILOG_INFO("Third parameter must be async callback"); + } else { HILOG_ERROR("Param not match"); ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return engine.CreateUndefined(); @@ -636,7 +617,7 @@ private: if (ret == 0) { task.ResolveWithNoError(engine, CreateJsRunningProcessInfoArray(engine, infos)); } else { - task.Reject(engine, CreateJsErrorByNativeErr(engine, ret, "Get RunningProcessInfo by bundleName failed.")); + task.Reject(engine, CreateJsErrorByNativeErr(engine, ret)); } }; diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 7ea78dc42d..a5bfc4aaca 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -769,8 +769,8 @@ int32_t AppMgrService::GetProcessMemoryByPid(const int32_t pid, int32_t &memoryS return appMgrServiceInner_->GetProcessMemoryByPid(pid, memorySize); } -int32_t AppMgrService::GetRunningProcessInformation( - const std::string &bundleName, int32_t userId, std::vector &info) +int32_t AppMgrService::GetRunningProcessInformation(const std::string &bundleName, int32_t userId, + std::vector &info) { if (!IsReady()) { HILOG_ERROR("AppMgrService is not ready."); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 5698341c06..298e68abf0 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -3914,7 +3914,7 @@ int32_t AppMgrServiceInner::GetRunningProcessInformation( auto appInfoList = appRecord->GetAppInfoList(); for (const auto &appInfo : appInfoList) { if (appInfo == nullptr) { - continue; + continue; } if (appInfo->bundleName == bundleName && appInfo->uid == uid) { GetRunningProcesses(appRecord, info); diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index 6758dd5c4e..7c8bdad9b7 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -71,7 +71,8 @@ public: MOCK_METHOD1(NotifyAppFault, int32_t(const FaultData &faultData)); MOCK_METHOD1(NotifyAppFaultBySA, int32_t(const AppFaultDataBySA &faultData)); MOCK_METHOD2(GetProcessMemoryByPid, int32_t(const int32_t pid, int32_t & memorySize)); - MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, std::vector &info)); + MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, + std::vector &info)); void AttachApplication(const sptr& app) { GTEST_LOG_(INFO) << "MockAppMgrService::AttachApplication called"; diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index 6a5ff43aae..4a0a9d4fcd 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -81,7 +81,8 @@ public: MOCK_METHOD1(NotifyAppFault, int32_t(const FaultData &faultData)); MOCK_METHOD1(NotifyAppFaultBySA, int32_t(const AppFaultDataBySA &faultData)); MOCK_METHOD2(GetProcessMemoryByPid, int32_t(const int32_t pid, int32_t & memorySize)); - MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, std::vector &info)); + MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, + std::vector &info)); virtual int StartUserTestProcess( const AAFwk::Want& want, const sptr& observer, const BundleInfo& bundleInfo, int32_t userId) { From 9721316b784f0eb655f606d347b5c17a9a135fe6 Mon Sep 17 00:00:00 2001 From: shaoxianqiang <1018410944@qq.com> Date: Wed, 28 Jun 2023 00:32:31 +0800 Subject: [PATCH 28/52] =?UTF-8?q?codecheck=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shaoxianqiang <1018410944@qq.com> Change-Id: I64c2492fae04f311eb6d3055d14d5d01012e2ee5 --- .../app/js_app_manager/js_app_manager.cpp | 55 +++++++------------ services/appmgr/src/app_mgr_service.cpp | 4 +- services/appmgr/src/app_mgr_service_inner.cpp | 2 +- .../include/mock_app_mgr_service.h | 3 +- .../include/mock_app_mgr_service.h | 3 +- 5 files changed, 28 insertions(+), 39 deletions(-) diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index bee5bacc8f..41ad189c61 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -538,7 +538,7 @@ private: NativeValue* OnGetProcessMemoryByPid(NativeEngine& engine, const NativeCallbackInfo& info) { - HILOG_INFO("%{public}s is called", __FUNCTION__); + HILOG_DEBUG("is called"); if (info.argc < ARGC_ONE) { HILOG_ERROR("Params not match"); ThrowTooFewParametersError(engine); @@ -564,7 +564,7 @@ private: if (ret == 0) { task.ResolveWithNoError(engine, CreateJsValue(engine, memSize)); } else { - task.Reject(engine, CreateJsErrorByNativeErr(engine, ret, "Get Process Memory by pid failed.")); + task.Reject(engine, CreateJsErrorByNativeErr(engine, ret)); } }; @@ -577,9 +577,9 @@ private: NativeValue* OnGetRunningProcessInfoByBundleName(NativeEngine& engine, const NativeCallbackInfo& info) { - HILOG_INFO("%{public}s is called", __FUNCTION__); + HILOG_DEBUG("is called"); if (info.argc < ARGC_ONE) { - HILOG_ERROR("Params number less then one"); + HILOG_ERROR("Params number less then one."); ThrowTooFewParametersError(engine); return engine.CreateUndefined(); } @@ -587,38 +587,25 @@ private: std::string bundleName; int userId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE; bool isPromiseType = false; - bool argCheckPass = true; - do { - if (!ConvertFromJsValue(engine, info.argv[0], bundleName)) { - HILOG_ERROR("First parameter must be string"); - argCheckPass = false; - break; - } - if (info.argc == ARGC_ONE) { + if (!ConvertFromJsValue(engine, info.argv[0], bundleName)) { + HILOG_ERROR("First parameter must be string"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + if (info.argc == ARGC_ONE) { + isPromiseType = true; + } else if (info.argc == ARGC_TWO) { + if (ConvertFromJsValue(engine, info.argv[1], userId)) { isPromiseType = true; - } else if (info.argc == ARGC_TWO) { - if (ConvertFromJsValue(engine, info.argv[1], userId)) { - isPromiseType = true; - } else { - HILOG_INFO("Second parameter must be async callback"); - } - } else if (info.argc == ARGC_THREE) { - if (ConvertFromJsValue(engine, info.argv[1], userId)) { - HILOG_INFO("Third parameter must be async callback"); - } else { - HILOG_WARN("Must input userid and use callback when argc is three."); - argCheckPass = false; - break; - } - } else { - HILOG_WARN("Argc cannot be larger then 3."); - argCheckPass = false; - break; } - } while (false); - - if (!argCheckPass) { + } else if (info.argc == ARGC_THREE) { + if (!ConvertFromJsValue(engine, info.argv[1], userId)) { + HILOG_WARN("Must input userid and use callback when argc is three."); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + } else { HILOG_ERROR("Param not match"); ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return engine.CreateUndefined(); @@ -636,7 +623,7 @@ private: if (ret == 0) { task.ResolveWithNoError(engine, CreateJsRunningProcessInfoArray(engine, infos)); } else { - task.Reject(engine, CreateJsErrorByNativeErr(engine, ret, "Get RunningProcessInfo by bundleName failed.")); + task.Reject(engine, CreateJsErrorByNativeErr(engine, ret)); } }; diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 7ea78dc42d..a5bfc4aaca 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -769,8 +769,8 @@ int32_t AppMgrService::GetProcessMemoryByPid(const int32_t pid, int32_t &memoryS return appMgrServiceInner_->GetProcessMemoryByPid(pid, memorySize); } -int32_t AppMgrService::GetRunningProcessInformation( - const std::string &bundleName, int32_t userId, std::vector &info) +int32_t AppMgrService::GetRunningProcessInformation(const std::string &bundleName, int32_t userId, + std::vector &info) { if (!IsReady()) { HILOG_ERROR("AppMgrService is not ready."); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 5698341c06..298e68abf0 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -3914,7 +3914,7 @@ int32_t AppMgrServiceInner::GetRunningProcessInformation( auto appInfoList = appRecord->GetAppInfoList(); for (const auto &appInfo : appInfoList) { if (appInfo == nullptr) { - continue; + continue; } if (appInfo->bundleName == bundleName && appInfo->uid == uid) { GetRunningProcesses(appRecord, info); diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index 6758dd5c4e..7c8bdad9b7 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -71,7 +71,8 @@ public: MOCK_METHOD1(NotifyAppFault, int32_t(const FaultData &faultData)); MOCK_METHOD1(NotifyAppFaultBySA, int32_t(const AppFaultDataBySA &faultData)); MOCK_METHOD2(GetProcessMemoryByPid, int32_t(const int32_t pid, int32_t & memorySize)); - MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, std::vector &info)); + MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, + std::vector &info)); void AttachApplication(const sptr& app) { GTEST_LOG_(INFO) << "MockAppMgrService::AttachApplication called"; diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index 6a5ff43aae..4a0a9d4fcd 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -81,7 +81,8 @@ public: MOCK_METHOD1(NotifyAppFault, int32_t(const FaultData &faultData)); MOCK_METHOD1(NotifyAppFaultBySA, int32_t(const AppFaultDataBySA &faultData)); MOCK_METHOD2(GetProcessMemoryByPid, int32_t(const int32_t pid, int32_t & memorySize)); - MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, std::vector &info)); + MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, + std::vector &info)); virtual int StartUserTestProcess( const AAFwk::Want& want, const sptr& observer, const BundleInfo& bundleInfo, int32_t userId) { From 8d31aa945e1b8c79aa74ff589f928dbfa9a813b2 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Wed, 28 Jun 2023 10:02:21 +0800 Subject: [PATCH 29/52] modify review Signed-off-by: xinking129 --- .../ability_manager_client_test.cpp | 8 ++------ test/unittest/BUILD.gn | 2 +- test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp | 4 ++-- .../app_mgr_service_test/app_mgr_service_test.cpp | 8 ++++---- test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp | 6 ++---- .../app_scheduler_host_test/app_scheduler_host_test.cpp | 1 - .../app_scheduler_proxy_test/app_scheduler_proxy_test.cpp | 2 +- test/unittest/app_scheduler_test/app_scheduler_test.cpp | 1 - test/unittest/fault_data/fault_data_test.cpp | 3 +-- 9 files changed, 13 insertions(+), 22 deletions(-) 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 0eeb6bead4..5e1fa69727 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 @@ -82,12 +82,10 @@ HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_DumpSysState_0100, TestS HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_ForceExitApp_0100, TestSize.Level1) { HILOG_INFO("AbilityManagerClient_ForceExitApp_0100 start"); - int32_t pid = 0; - Reason exitReason = REASON_JS_ERROR; + Reason exitReason = REASON_JS_ERROR; auto result = AbilityManagerClient::GetInstance()->ForceExitApp(pid, exitReason); EXPECT_EQ(result, ERR_OK); - HILOG_INFO("AbilityManagerClient_ForceExitApp_0100 end"); } @@ -99,11 +97,9 @@ HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_ForceExitApp_0100, TestS HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_RecordAppExitReason_0100, TestSize.Level1) { HILOG_INFO("AbilityManagerClient_RecordAppExitReason_0100 start"); - - Reason exitReason = REASON_JS_ERROR; + Reason exitReason = REASON_JS_ERROR; auto result = AbilityManagerClient::GetInstance()->RecordAppExitReason(exitReason); EXPECT_EQ(result, ERR_OK); - HILOG_INFO("AbilityManagerClient_RecordAppExitReason_0100 end"); } } // namespace AAFwk diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index a3801a7848..4872ff840b 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -315,6 +315,7 @@ group("unittest") { "ams_service_event_drive_test:unittest", "ams_service_load_ability_process_test:unittest", "ams_service_startup_test:unittest", + "app_lifecycle_deal_test:unittest", "app_mgr_client_test:unittest", "app_mgr_proxy_test:unittest", "app_mgr_service_dump_test:unittest", @@ -328,7 +329,6 @@ group("unittest") { "app_scheduler_host_test:unittest", "app_scheduler_proxy_test:unittest", "app_scheduler_test:unittest", - "app_lifecycle_deal_test:unittest", "app_spawn_client_test:unittest", "app_spawn_socket_test:unittest", "app_state_observer_manager_test:unittest", diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 13a60495f8..f20e98e16c 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -240,7 +240,7 @@ HWTEST_F(AppMgrProxyTest, PreStartNWebSpawnProcess_001, TestSize.Level0) * @tc.type: FUNC * @tc.require: issueI79RY8 */ -HWTEST_F(AppMgrProxyTest, NotifyAppFault_001, TestSize.Level0) +HWTEST_F(AppMgrProxyTest, NotifyAppFault_001, TestSize.Level1) { EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) .Times(1) @@ -256,7 +256,7 @@ HWTEST_F(AppMgrProxyTest, NotifyAppFault_001, TestSize.Level0) * @tc.type: FUNC * @tc.require: issueI79RY8 */ -HWTEST_F(AppMgrProxyTest, NotifyAppFaultBySA_001, TestSize.Level0) +HWTEST_F(AppMgrProxyTest, NotifyAppFaultBySA_001, TestSize.Level1) { EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) .Times(1) diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index 3f5ca73c9c..45499769aa 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -1187,7 +1187,7 @@ HWTEST_F(AppMgrServiceTest, NotifyUnLoadRepairPatch_002, TestSize.Level0) */ HWTEST_F(AppMgrServiceTest, NotifyAppFault_001, TestSize.Level1) { - sptr appMgrService = new (std::nothrow)AppMgrService(); + sptr appMgrService = new (std::nothrow) AppMgrService(); appMgrService->SetInnerService(nullptr); FaultData faultData; int32_t res = appMgrService->NotifyAppFault(faultData); @@ -1201,7 +1201,7 @@ HWTEST_F(AppMgrServiceTest, NotifyAppFault_001, TestSize.Level1) */ HWTEST_F(AppMgrServiceTest, NotifyAppFault_002, TestSize.Level1) { - sptr appMgrService = new (std::nothrow)AppMgrService(); + sptr appMgrService = new (std::nothrow) AppMgrService(); appMgrService->SetInnerService(nullptr); AppFaultDataBySA faultData; int32_t res = appMgrService->NotifyAppFaultBySA(faultData); @@ -1215,8 +1215,8 @@ HWTEST_F(AppMgrServiceTest, NotifyAppFault_002, TestSize.Level1) */ HWTEST_F(AppMgrServiceTest, NotifyAppFault_003, TestSize.Level1) { - sptr appMgrService = new (std::nothrow)AppMgrService(); - appMgrService->SetInnerService(std::make_shared()); + sptr appMgrService = new (std::nothrow) AppMgrService(); + appMgrService->SetInnerService(std::make_shared()); appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); AppFaultDataBySA faultData; int32_t res = appMgrService->NotifyAppFaultBySA(faultData); diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index a88912d930..57fdefd285 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -225,7 +225,7 @@ HWTEST_F(AppMgrStubTest, PreStartNWebSpawnProcess_001, TestSize.Level0) * @tc.type: FUNC * @tc.require: issueI79RY8 */ -HWTEST_F(AppMgrStubTest, HandleNotifyFault_001, TestSize.Level0) +HWTEST_F(AppMgrStubTest, HandleNotifyFault_001, TestSize.Level1) { MessageParcel data; MessageParcel reply; @@ -238,7 +238,6 @@ HWTEST_F(AppMgrStubTest, HandleNotifyFault_001, TestSize.Level0) faultData.faultType = FaultDataType::UNKNOWN; data.WriteParcelable(&faultData); EXPECT_CALL(*mockAppMgrService_, NotifyAppFault(_)).Times(1); - auto result = mockAppMgrService_->OnRemoteRequest( static_cast(IAppMgr::Message::NOTIFY_APP_FAULT), data, reply, option); EXPECT_EQ(result, NO_ERROR); @@ -250,7 +249,7 @@ HWTEST_F(AppMgrStubTest, HandleNotifyFault_001, TestSize.Level0) * @tc.type: FUNC * @tc.require: issueI79RY8 */ -HWTEST_F(AppMgrStubTest, HandleNotifyFaultBySA_001, TestSize.Level0) +HWTEST_F(AppMgrStubTest, HandleNotifyFaultBySA_001, TestSize.Level1) { MessageParcel data; MessageParcel reply; @@ -264,7 +263,6 @@ HWTEST_F(AppMgrStubTest, HandleNotifyFaultBySA_001, TestSize.Level0) faultData.pid = 24; data.WriteParcelable(&faultData); EXPECT_CALL(*mockAppMgrService_, NotifyAppFaultBySA(_)).Times(1); - auto result = mockAppMgrService_->OnRemoteRequest( static_cast(IAppMgr::Message::NOTIFY_APP_FAULT_BY_SA), data, reply, option); EXPECT_EQ(result, NO_ERROR); diff --git a/test/unittest/app_scheduler_host_test/app_scheduler_host_test.cpp b/test/unittest/app_scheduler_host_test/app_scheduler_host_test.cpp index f1249ee2ac..da3924d28b 100644 --- a/test/unittest/app_scheduler_host_test/app_scheduler_host_test.cpp +++ b/test/unittest/app_scheduler_host_test/app_scheduler_host_test.cpp @@ -79,7 +79,6 @@ HWTEST_F(AppSchedulerHostTest, HandleNotifyAppFault_001, TestSize.Level1) faultData.faultType = FaultDataType::UNKNOWN; data.WriteParcelable(&faultData); EXPECT_CALL(*mockAppScheduler_, ScheduleNotifyAppFault(_)).Times(1); - auto result = mockAppScheduler_->OnRemoteRequest( static_cast(IAppScheduler::Message::SCHEDULE_NOTIFY_FAULT), data, reply, option); EXPECT_EQ(result, NO_ERROR); diff --git a/test/unittest/app_scheduler_proxy_test/app_scheduler_proxy_test.cpp b/test/unittest/app_scheduler_proxy_test/app_scheduler_proxy_test.cpp index fa52c7ea4c..eda2a467a6 100644 --- a/test/unittest/app_scheduler_proxy_test/app_scheduler_proxy_test.cpp +++ b/test/unittest/app_scheduler_proxy_test/app_scheduler_proxy_test.cpp @@ -53,7 +53,7 @@ void AppSchedulerProxyTest::TearDown() HWTEST_F(AppSchedulerProxyTest, ScheduleNotifyAppFault_001, TestSize.Level1) { sptr impl; - sptr appSchedulerProxy = new (std::nothrow)AppSchedulerProxy(impl); + sptr appSchedulerProxy = new (std::nothrow) AppSchedulerProxy(impl); FaultData faultData; faultData.faultType = FaultDataType::APP_FREEZE; faultData.errorObject.message = "msgContent"; diff --git a/test/unittest/app_scheduler_test/app_scheduler_test.cpp b/test/unittest/app_scheduler_test/app_scheduler_test.cpp index 3e044bb985..145abcc266 100644 --- a/test/unittest/app_scheduler_test/app_scheduler_test.cpp +++ b/test/unittest/app_scheduler_test/app_scheduler_test.cpp @@ -1160,6 +1160,5 @@ HWTEST_F(AppSchedulerTest, AppScheduler_NotifyFault_001, TestSize.Level1) int res = DelayedSingleton::GetInstance()->NotifyFault(faultData); EXPECT_EQ(res, INNER_ERR); } - } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/fault_data/fault_data_test.cpp b/test/unittest/fault_data/fault_data_test.cpp index 14bc81f135..cf9dcbcf39 100644 --- a/test/unittest/fault_data/fault_data_test.cpp +++ b/test/unittest/fault_data/fault_data_test.cpp @@ -142,7 +142,6 @@ HWTEST_F(FaultDataTest, ReadFromParcel_002, TestSize.Level1) EXPECT_EQ(false, retSecond); MessageParcel messageThird; - messageThird.WriteString(helloWord); messageThird.WriteString(helloWord); bool retThird = appFaultDataBySA->ReadFromParcel(messageThird); @@ -193,7 +192,7 @@ HWTEST_F(FaultDataTest, Unmarshalling_002, TestSize.Level1) message.WriteInt32(34); message.WriteInt32(56); message.WriteString(helloWord); - auto retSecond = appFaultDataBySA->Unmarshalling(message); + auto retSecond = appFaultDataBySA->Unmarshalling(message); EXPECT_NE(nullptr, retSecond); } From e35bf5d26fe89667e2662d2f7f60e9bee0bee4d2 Mon Sep 17 00:00:00 2001 From: l30047846 Date: Thu, 29 Jun 2023 09:47:38 +0800 Subject: [PATCH 30/52] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l30047846 --- test/unittest/app_mgr_service_test/app_mgr_service_test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index 94e82c0e02..4a553b8fb7 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -1214,7 +1214,8 @@ HWTEST_F(AppMgrServiceTest, GetProcessMemoryByPid_002, TestSize.Level0) ASSERT_NE(appMgrService, nullptr); appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int32_t pid = 0; int32_t memorySize = 0; @@ -1257,7 +1258,8 @@ HWTEST_F(AppMgrServiceTest, GetRunningProcessInformation_002, TestSize.Level0) ASSERT_NE(appMgrService, nullptr); appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); std::string bundleName = "testBundleName"; int32_t userId = 100; From 7b10c28509608e0b63741128e00f58fc7fa72f1a Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 28 Jun 2023 11:45:53 +0800 Subject: [PATCH 31/52] add user Signed-off-by: unknown --- .../include/ability_manager_service.h | 6 ++-- .../src/ability_manager_service.cpp | 28 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index fea0678bea..10bd4e2780 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1330,7 +1330,7 @@ private: std::map dumpsysFuncMap_; int CheckStaticCfgPermission(AppExecFwk::AbilityInfo &abilityInfo, bool isStartAsCaller, - uint32_t callerTokenId); + uint32_t callerTokenId, bool isData = false, bool isSaCall = false); bool GetValidDataAbilityUri(const std::string &abilityInfoUri, std::string &adjustUri); @@ -1368,7 +1368,7 @@ private: * @param abilityRequest, abilityRequest. * @return Returns whether the caller is allowed to start DataAbility. */ - int CheckCallDataAbilityPermission(AbilityRequest &abilityRequest, bool isShell); + int CheckCallDataAbilityPermission(AbilityRequest &abilityRequest, bool isShell, bool IsSACall = false); /** * Check if Caller is allowed to start ServiceExtension(Stage) or DataShareExtension(Stage). @@ -1432,7 +1432,7 @@ private: void UpdateFocusState(std::vector &info); AAFwk::PermissionVerification::VerificationInfo CreateVerificationInfo( - const AbilityRequest &abilityRequest); + const AbilityRequest &abilityRequest, bool isData = false, bool isShell = false, bool isSA = false); int AddStartControlParam(Want &want, const sptr &callerToken); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 5c875e0b78..83bad7f71c 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -3287,7 +3287,7 @@ sptr AbilityManagerService::AcquireDataAbility( auto userId = GetValidUserId(INVALID_USER_ID); AbilityRequest abilityRequest; std::string dataAbilityUri = localUri.ToString(); - HILOG_INFO("%{public}s, called. userId %{public}d", __func__, userId); + HILOG_INFO("called. userId %{public}d", userId); bool queryResult = IN_PROCESS_CALL(bms->QueryAbilityInfoByUri(dataAbilityUri, userId, abilityRequest.abilityInfo)); if (!queryResult || abilityRequest.abilityInfo.name.empty() || abilityRequest.abilityInfo.bundleName.empty()) { HILOG_ERROR("Invalid ability info for data ability acquiring."); @@ -3297,7 +3297,7 @@ sptr AbilityManagerService::AcquireDataAbility( abilityRequest.callerToken = callerToken; auto isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (!isSaCall && CheckCallDataAbilityPermission(abilityRequest, isShellCall) != ERR_OK) { + if (!isSaCall && CheckCallDataAbilityPermission(abilityRequest, isShellCall, isSaCall) != ERR_OK) { HILOG_ERROR("Invalid ability request info for data ability acquiring."); return nullptr; } @@ -3306,7 +3306,8 @@ sptr AbilityManagerService::AcquireDataAbility( abilityRequest.appInfo.name.c_str(), abilityRequest.appInfo.bundleName.c_str(), abilityRequest.abilityInfo.name.c_str()); - if (CheckStaticCfgPermission(abilityRequest.abilityInfo, false, -1) != AppExecFwk::Constants::PERMISSION_GRANTED) { + if (CheckStaticCfgPermission(abilityRequest.abilityInfo, false, -1, true, isSaCall) != + AppExecFwk::Constants::PERMISSION_GRANTED) { if (!VerificationAllToken(callerToken)) { HILOG_INFO("VerificationAllToken fail"); return nullptr; @@ -6015,10 +6016,12 @@ int AbilityManagerService::ForceTimeoutForTest(const std::string &abilityName, c #endif int AbilityManagerService::CheckStaticCfgPermission(AppExecFwk::AbilityInfo &abilityInfo, bool isStartAsCaller, - uint32_t callerTokenId) + uint32_t callerTokenId, bool isData, bool isSaCall) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + if (!isData) { + isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + } if (isSaCall) { // do not need check static config permission when start ability by SA return AppExecFwk::Constants::PERMISSION_GRANTED; @@ -6618,7 +6621,7 @@ int AbilityManagerService::CheckCallServicePermission(const AbilityRequest &abil } } -int AbilityManagerService::CheckCallDataAbilityPermission(AbilityRequest &abilityRequest, bool isShell) +int AbilityManagerService::CheckCallDataAbilityPermission(AbilityRequest &abilityRequest, bool isShell, bool isSACall) { abilityRequest.appInfo = abilityRequest.abilityInfo.applicationInfo; abilityRequest.uid = abilityRequest.appInfo.uid; @@ -6631,7 +6634,8 @@ int AbilityManagerService::CheckCallDataAbilityPermission(AbilityRequest &abilit return ERR_WRONG_INTERFACE_CALL; } - AAFwk::PermissionVerification::VerificationInfo verificationInfo = CreateVerificationInfo(abilityRequest); + AAFwk::PermissionVerification::VerificationInfo verificationInfo = CreateVerificationInfo(abilityRequest, + true, isShell, isSACall); if (isShell) { verificationInfo.isBackgroundCall = true; } @@ -6649,7 +6653,7 @@ int AbilityManagerService::CheckCallDataAbilityPermission(AbilityRequest &abilit } AAFwk::PermissionVerification::VerificationInfo AbilityManagerService::CreateVerificationInfo( - const AbilityRequest &abilityRequest) + const AbilityRequest &abilityRequest, bool isData, bool isShell, bool isSA) { AAFwk::PermissionVerification::VerificationInfo verificationInfo; verificationInfo.accessTokenId = abilityRequest.appInfo.accessTokenId; @@ -6664,9 +6668,11 @@ AAFwk::PermissionVerification::VerificationInfo AbilityManagerService::CreateVer } else { verificationInfo.associatedWakeUp = abilityRequest.appInfo.associatedWakeUp; } - if (AAFwk::PermissionVerification::GetInstance()->IsSACall() || - AAFwk::PermissionVerification::GetInstance()->IsShellCall()) { - HILOG_INFO("Caller is not an application."); + if (!isData) { + isSA = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + isShell = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); + } + if (isSA || isShell) { return verificationInfo; } std::shared_ptr callerAbility = Token::GetAbilityRecordByToken(abilityRequest.callerToken); From a928e156a5e946210dea31388242bc31b5108c9f Mon Sep 17 00:00:00 2001 From: shaoxianqiang <1018410944@qq.com> Date: Wed, 28 Jun 2023 13:22:22 +0800 Subject: [PATCH 32/52] =?UTF-8?q?codecheck=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shaoxianqiang <1018410944@qq.com> Change-Id: I9a6b53fca2f4c24f5b3d26d13998d84075daae5a --- frameworks/js/napi/app/js_app_manager/js_app_manager.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index 41ad189c61..502ea823b1 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -577,9 +577,7 @@ private: NativeValue* OnGetRunningProcessInfoByBundleName(NativeEngine& engine, const NativeCallbackInfo& info) { - HILOG_DEBUG("is called"); if (info.argc < ARGC_ONE) { - HILOG_ERROR("Params number less then one."); ThrowTooFewParametersError(engine); return engine.CreateUndefined(); } @@ -587,7 +585,6 @@ private: std::string bundleName; int userId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE; bool isPromiseType = false; - if (!ConvertFromJsValue(engine, info.argv[0], bundleName)) { HILOG_ERROR("First parameter must be string"); ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); @@ -606,7 +603,6 @@ private: return engine.CreateUndefined(); } } else { - HILOG_ERROR("Param not match"); ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return engine.CreateUndefined(); } @@ -614,7 +610,6 @@ private: AsyncTask::CompleteCallback complete = [bundleName, userId, appManager = appManager_](NativeEngine &engine, AsyncTask &task, int32_t status) { if (appManager == nullptr) { - HILOG_WARN("appManager is nullptr"); task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INNER)); return; } @@ -626,7 +621,6 @@ private: task.Reject(engine, CreateJsErrorByNativeErr(engine, ret)); } }; - NativeValue* lastParam = isPromiseType ? nullptr : info.argv[info.argc - 1]; NativeValue* result = nullptr; AsyncTask::Schedule("JSAppManager::OnGetRunningProcessInfoByBundleName", From f53d1239ca2601d6c2c0ce47c4501627950d5f60 Mon Sep 17 00:00:00 2001 From: m30043719 Date: Mon, 26 Jun 2023 20:38:02 +0800 Subject: [PATCH 33/52] =?UTF-8?q?=E4=BF=AE=E5=A4=8DcontinueMission?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=BC=82=E5=B8=B8=E5=85=A5=E5=8F=82=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issue:https://gitee.com/openharmony/ability_ability_runtime/issues/I7F8US Signed-off-by: m30043719 --- .../distributed_mission_manager.cpp | 59 ++++++++++++------- .../distributed_mission_manager.h | 10 ++-- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp b/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp index c1c12b4c32..924f49e5ae 100644 --- a/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp +++ b/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp @@ -694,7 +694,7 @@ bool RegisterMissionWrapDeviceId(napi_env &env, napi_value &argc, std::to_string(VALUE_BUFFER_SIZE); return false; } - registerMissionCB->deviceId = deviceId; + registerMissionCB->deviceId = std::string(deviceId); return true; } @@ -1445,7 +1445,7 @@ bool GetUnRegisterMissionDeviceId(napi_env &env, const napi_value &value, std::to_string(VALUE_BUFFER_SIZE); return false; } - registerMissionCB->deviceId = deviceId; + registerMissionCB->deviceId = std::string(deviceId); HILOG_INFO("%{public}s called end.", __func__); return true; } @@ -1579,6 +1579,7 @@ void ContinueAbilityExecuteCB(napi_env env, void *data) } continueAbilityCB->result = -1; + continueAbilityCB->abilityContinuation->SetContinueAbilityHasBundleName(continueAbilityCB->hasArgsWithBundleName); if (continueAbilityCB->hasArgsWithBundleName) { continueAbilityCB->result = AAFwk::AbilityManagerClient::GetInstance()-> ContinueMission(continueAbilityCB->srcDeviceId, continueAbilityCB->dstDeviceId, @@ -1606,19 +1607,30 @@ void ContinueAbilityCallbackCompletedCB(napi_env env, napi_status status, void * int32_t errCode = ErrorCodeReturn(continueAbilityCB->result); result[0] = GenerateBusinessError(env, errCode, ErrorMessageReturn(errCode)); } - - if (continueAbilityCB->callbackRef == nullptr) { // promise - if (continueAbilityCB->result == 0) { - napi_resolve_deferred(env, continueAbilityCB->cbBase.deferred, result[1]); - } else { - napi_reject_deferred(env, continueAbilityCB->cbBase.deferred, result[0]); + if (!continueAbilityCB->hasArgsWithBundleName) { + if (continueAbilityCB->callbackRef == nullptr) { // promise + if (continueAbilityCB->result == 0) { + napi_resolve_deferred(env, continueAbilityCB->cbBase.deferred, result[1]); + } else { + napi_reject_deferred(env, continueAbilityCB->cbBase.deferred, result[0]); + } + } else { // AsyncCallback + napi_value callback = nullptr; + napi_get_reference_value(env, continueAbilityCB->callbackRef, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_TWO, &result[0], &callResult); + napi_delete_reference(env, continueAbilityCB->callbackRef); + } + } else { + if (continueAbilityCB->callbackRef == nullptr && continueAbilityCB->result != 0) { // promise + napi_reject_deferred(env, continueAbilityCB->cbBase.deferred, result[0]); + } else if (continueAbilityCB->callbackRef != nullptr && continueAbilityCB->result != 0) { // AsyncCallback + napi_value callback = nullptr; + napi_get_reference_value(env, continueAbilityCB->callbackRef, &callback); + napi_value callResult; + napi_call_function(env, nullptr, callback, ARGS_TWO, &result[0], &callResult); + napi_delete_reference(env, continueAbilityCB->callbackRef); } - } else { // AsyncCallback - napi_value callback = nullptr; - napi_get_reference_value(env, continueAbilityCB->callbackRef, &callback); - napi_value callResult; - napi_call_function(env, nullptr, callback, ARGS_TWO, &result[0], &callResult); - napi_delete_reference(env, continueAbilityCB->callbackRef); } napi_delete_async_work(env, continueAbilityCB->cbBase.asyncWork); delete continueAbilityCB; @@ -1997,13 +2009,12 @@ void UvWorkOnContinueDone(uv_work_t *work, int status) delete work; return; } - - napi_value result = nullptr; HILOG_INFO("UvWorkOnContinueDone, resultCode = %{public}d", continueAbilityCB->resultCode); - result = - WrapInt32(continueAbilityCB->cbBase.cbInfo.env, continueAbilityCB->resultCode, "resultCode"); - - if (continueAbilityCB->cbBase.cbInfo.callback != nullptr) { + napi_value result = WrapInt32(continueAbilityCB->cbBase.cbInfo.env, continueAbilityCB->resultCode, "resultCode"); + if (continueAbilityCB->hasArgsWithBundleName) { + result = WrapInt32(continueAbilityCB->cbBase.cbInfo.env, continueAbilityCB->resultCode, "code"); + } + if (continueAbilityCB->cbBase.deferred == nullptr) { napi_value callback = nullptr; napi_value undefined = nullptr; napi_get_undefined(continueAbilityCB->cbBase.cbInfo.env, &undefined); @@ -2025,7 +2036,6 @@ void UvWorkOnContinueDone(uv_work_t *work, int status) napi_reject_deferred(continueAbilityCB->cbBase.cbInfo.env, continueAbilityCB->cbBase.deferred, result[0]); } } - napi_close_handle_scope(continueAbilityCB->cbBase.cbInfo.env, scope); delete continueAbilityCB; continueAbilityCB = nullptr; @@ -2053,6 +2063,7 @@ void NAPIMissionContinue::OnContinueDone(int32_t result) return; } continueAbilityCB->cbBase.cbInfo.env = env_; + continueAbilityCB->hasArgsWithBundleName = onContinueDoneHasBundleName_; if (onContinueDoneRef_ != nullptr) { continueAbilityCB->cbBase.cbInfo.callback = onContinueDoneRef_; } else { @@ -2081,10 +2092,16 @@ void NAPIMissionContinue::SetContinueAbilityCBRef(const napi_ref &ref) onContinueDoneRef_ = ref; } +void NAPIMissionContinue::SetContinueAbilityHasBundleName(bool hasBundleName) +{ + onContinueDoneHasBundleName_ = hasBundleName; +} + void NAPIMissionContinue::SetContinueAbilityPromiseRef(const napi_deferred &promiseDeferred) { promiseDeferred_ = promiseDeferred; } + napi_value DistributedMissionManagerExport(napi_env env, napi_value exports) { HILOG_INFO("%{public}s,called", __func__); diff --git a/frameworks/js/napi/mission_manager/distributed_mission_manager.h b/frameworks/js/napi/mission_manager/distributed_mission_manager.h index 9a9190923e..de909a6bf1 100644 --- a/frameworks/js/napi/mission_manager/distributed_mission_manager.h +++ b/frameworks/js/napi/mission_manager/distributed_mission_manager.h @@ -47,12 +47,14 @@ public: void SetEnv(const napi_env &env); void SetContinueAbilityEnv(const napi_env &env); void SetContinueAbilityCBRef(const napi_ref &ref); + void SetContinueAbilityHasBundleName(bool hasBundleName); void SetContinueAbilityPromiseRef(const napi_deferred &promiseDeferred); private: + bool onContinueDoneHasBundleName_ = false; napi_env env_ = nullptr; napi_ref onContinueDoneRef_ = nullptr; - napi_deferred promiseDeferred_; + napi_deferred promiseDeferred_ = nullptr; }; class NAPIRemoteMissionListener : public AAFwk::RemoteMissionListenerStub { @@ -96,8 +98,8 @@ struct CallbackInfo { struct CBBase { CallbackInfo cbInfo; - napi_async_work asyncWork; - napi_deferred deferred; + napi_async_work asyncWork = nullptr; + napi_deferred deferred = nullptr; int errCode = 0; }; @@ -153,7 +155,7 @@ struct ContinueAbilityCB { int missionId = 0; std::string bundleName; bool hasArgsWithBundleName = false; - napi_ref callbackRef; + napi_ref callbackRef = nullptr; }; struct SyncRemoteMissionsContext { From dc94347cf8df2b85f92e815cac36c99433db61fd Mon Sep 17 00:00:00 2001 From: renhw Date: Wed, 28 Jun 2023 15:38:16 +0800 Subject: [PATCH 34/52] fix image source Signed-off-by: renhw --- .../abilitymgr/include/mission_data_storage.h | 1 + .../abilitymgr/src/mission_data_storage.cpp | 57 ++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/include/mission_data_storage.h b/services/abilitymgr/include/mission_data_storage.h index eb4a0dca93..aa30b0612e 100644 --- a/services/abilitymgr/include/mission_data_storage.h +++ b/services/abilitymgr/include/mission_data_storage.h @@ -102,6 +102,7 @@ public: std::shared_ptr GetSnapshot(int missionId, bool isLowResolution = false) const; std::unique_ptr GetPixelMap(int missionId, bool isLowResolution) const; + std::unique_ptr ReadFileToBuffer(const std::string &filePath, size_t &bufferSize) const; #endif private: diff --git a/services/abilitymgr/src/mission_data_storage.cpp b/services/abilitymgr/src/mission_data_storage.cpp index 93acc66640..d4c52d8b5e 100644 --- a/services/abilitymgr/src/mission_data_storage.cpp +++ b/services/abilitymgr/src/mission_data_storage.cpp @@ -14,7 +14,7 @@ */ #include "mission_data_storage.h" - +#include #include "directory_ex.h" #include "file_ex.h" #include "hilog_wrapper.h" @@ -363,6 +363,51 @@ std::shared_ptr MissionDataStorage::GetSnapshot(int missionId, return std::shared_ptr(pixelMapPtr.release()); } +std::unique_ptr MissionDataStorage::ReadFileToBuffer(const std::string &filePath, size_t &bufferSize) const +{ + struct stat statbuf; + int ret = stat(filePath.c_str(), &statbuf); + if (ret != 0) { + HILOG_ERROR("GetPixelMap: get the file size failed, ret:%{public}d.", ret); + return nullptr; + } + bufferSize = statbuf.st_size; + std::string realPath; + if (!OHOS::PathToRealPath(filePath, realPath)) { + HILOG_ERROR("ReadFileToBuffer:file path to real path failed, file path=%{public}s.", filePath.c_str()); + return nullptr; + } + + std::unique_ptr buffer = std::make_unique(bufferSize); + if (buffer == nullptr) { + HILOG_ERROR("ReadFileToBuffer:buffer is nullptr"); + return nullptr; + } + + FILE *fp = fopen(realPath.c_str(), "rb"); + if (fp == nullptr) { + HILOG_ERROR("ReadFileToBuffer:open file failed, real path=%{public}s.", realPath.c_str()); + return nullptr; + } + fseek(fp, 0, SEEK_END); + size_t fileSize = ftell(fp); + fseek(fp, 0, SEEK_SET); + if (bufferSize < fileSize) { + HILOG_ERROR("ReadFileToBuffer:buffer size:(%{public}zu) is smaller than file size:(%{public}zu).", bufferSize, + fileSize); + fclose(fp); + return nullptr; + } + size_t retSize = std::fread(buffer.get(), 1, fileSize, fp); + if (retSize != fileSize) { + HILOG_ERROR("ReadFileToBuffer:read file result size = %{public}zu, size = %{public}zu.", retSize, fileSize); + fclose(fp); + return nullptr; + } + fclose(fp); + return buffer; +} + std::unique_ptr MissionDataStorage::GetPixelMap(int missionId, bool isLowResolution) const { std::string filePath = GetMissionSnapshotPath(missionId, isLowResolution); @@ -371,8 +416,16 @@ std::unique_ptr MissionDataStorage::GetPixelMap(int missionId, return nullptr; } uint32_t errCode = 0; + + size_t bufferSize = 0; + const std::string fileName = filePath; + std::unique_ptr buffer = MissionDataStorage::ReadFileToBuffer(fileName, bufferSize); + if (buffer == nullptr) { + HILOG_ERROR("GetPixelMap: get buffer error buffer == nullptr"); + return nullptr; + } Media::SourceOptions sourceOptions; - auto imageSource = Media::ImageSource::CreateImageSource(filePath, sourceOptions, errCode); + auto imageSource = Media::ImageSource::CreateImageSource(buffer.get(), bufferSize, sourceOptions, errCode); if (errCode != OHOS::Media::SUCCESS) { HILOG_ERROR("snapshot: CreateImageSource failed, errCode = %{public}d", errCode); return nullptr; From 665b32bc92c577c99653da28f802be3061f003b7 Mon Sep 17 00:00:00 2001 From: shaoxianqiang <1018410944@qq.com> Date: Wed, 28 Jun 2023 16:05:12 +0800 Subject: [PATCH 35/52] =?UTF-8?q?=E5=86=B2=E7=AA=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shaoxianqiang <1018410944@qq.com> Change-Id: I25c66e7c992208806ae9761f42ada5162952c140 --- test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp | 3 +++ .../app_mgr_service_inner_test/app_mgr_service_inner_test.cpp | 3 +++ test/unittest/app_mgr_service_test/app_mgr_service_test.cpp | 2 ++ test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp | 3 +++ 4 files changed, 11 insertions(+) diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 3512f21fb5..2232ba7a4c 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -277,6 +277,9 @@ HWTEST_F(AppMgrProxyTest, GetRunningProcessInformation_001, TestSize.Level0) EXPECT_EQ(mockAppMgrService_->code_, static_cast(IAppMgr::Message::GET_PIDS_BY_BUNDLENAME)); HILOG_INFO("%{public}s end.", __func__); +} + +/** * @tc.name: NotifyAppFault_001 * @tc.desc: Notify app fault. * @tc.type: FUNC diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index ef757f1251..89b582d8cb 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -3308,6 +3308,9 @@ HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInformation_001, TestSize.Leve EXPECT_EQ(ret, ERR_NO_INIT); HILOG_INFO("GetRunningProcessInformation_001 end"); +} + +/** * @tc.name: GetBundleNameByPid_001 * @tc.desc: get bundle name by Pid. * @tc.type: FUNC diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index 42f927bba7..25f38922e5 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -1290,6 +1290,8 @@ HWTEST_F(AppMgrServiceTest, GetRunningProcessInformation_002, TestSize.Level0) std::vector info; int32_t res = appMgrService->GetRunningProcessInformation(bundleName, userId, info); EXPECT_EQ(res, ERR_OK); +} + /** * @tc.name: NotifyAppFault_001 * @tc.desc: Verify that the NotifyAppFault interface calls normally diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index 671c00e6c0..71be8ec404 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -271,6 +271,9 @@ HWTEST_F(AppMgrStubTest, GetRunningProcessInformation_001, TestSize.Level0) EXPECT_EQ(result, NO_ERROR); HILOG_INFO("%{public}s end.", __func__); +} + +/** * @tc.name: HandleNotifyFault_001 * @tc.desc: Handle notify fault. * @tc.type: FUNC From c1ddf50e98a88996331fa34394b75ccd7e5e5ffc Mon Sep 17 00:00:00 2001 From: jsjzju Date: Wed, 28 Jun 2023 16:13:17 +0800 Subject: [PATCH 36/52] =?UTF-8?q?=E8=A1=A5=E5=85=85tdd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jsjzju Change-Id: Ibe1a364cd461f392d7616782d6a67e8e0a7699cb --- .../ability_manager_client_branch_test.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp index 216f8eef4e..32028f00d3 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp @@ -542,6 +542,20 @@ HWTEST_F(AbilityManagerClientBranchTest, ScheduleCommandAbilityDone_0100, TestSi EXPECT_EQ(ERR_OK, result); } +/** + * @tc.name: AbilityManagerClient_ScheduleCommandAbilityWindowDone_0100 + * @tc.desc: ScheduleCommandAbilityWindowDone + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerClientBranchTest, ScheduleCommandAbilityWindowDone_0100, TestSize.Level1) +{ + sptr token = nullptr; + sptr sessionInfo(new SessionInfo()); + auto result = client_->ScheduleCommandAbilityWindowDone( + token, sessionInfo, WIN_CMD_FOREGROUND, ABILITY_CMD_FOREGROUND); + EXPECT_EQ(ERR_OK, result); +} + /** * @tc.name: AbilityManagerClient_CloseAbility_0100 * @tc.desc: CloseAbility From de05c8e208f28e7f15194d1832ea99ca83584bda Mon Sep 17 00:00:00 2001 From: xinking129 Date: Wed, 28 Jun 2023 17:30:40 +0800 Subject: [PATCH 37/52] seletor scroll change Signed-off-by: xinking129 --- .../src/main/ets/pages/selectorPcDialog.ets | 292 +++++++++--------- 1 file changed, 147 insertions(+), 145 deletions(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPcDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPcDialog.ets index 0165d8a174..3f8e7e2dae 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPcDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPcDialog.ets @@ -236,158 +236,160 @@ struct SelectorPcDialog { .margin({ left: 48 }) .width(394) .height(56) - List() { - ListItem() { - Text($r("app.string.message_recommendApps_selector")) - .fontSize(14) - .fontWeight(FontWeight.Medium) - .width(394) - .height(48) - .visibility(this.recommendAppsVisiable) - } - ForEach(globalThis.pcShowHapList, (item: any, current) => { + Scroll() { + List() { ListItem() { - Flex({ direction: FlexDirection.Row }) { - if (item.split("#")[3] != "") { - Image(item.split("#")[3]) - .height(48) - .width(48) - .alignSelf(ItemAlign.Center) - .margin({ left : 16 }) - .borderRadius(12) - } else { - Image($r("app.media.app_icon")) - .height(48) - .width(48) - .alignSelf(ItemAlign.Center) - .margin({ left : 16 }) - .borderRadius(12) + Text($r("app.string.message_recommendApps_selector")) + .fontSize(14) + .fontWeight(FontWeight.Medium) + .width(394) + .height(48) + .visibility(this.recommendAppsVisiable) + } + ForEach(globalThis.pcShowHapList, (item: any, current) => { + ListItem() { + Flex({ direction: FlexDirection.Row }) { + if (item.split("#")[3] != "") { + Image(item.split("#")[3]) + .height(48) + .width(48) + .alignSelf(ItemAlign.Center) + .margin({ left : 16 }) + .borderRadius(12) + } else { + Image($r("app.media.app_icon")) + .height(48) + .width(48) + .alignSelf(ItemAlign.Center) + .margin({ left : 16 }) + .borderRadius(12) + } + if (item.split("#")[2] != "") { + Text(item.split("#")[2]) + .fontSize(16) + .width("60%") + .height(64) + .alignSelf(ItemAlign.Center) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .margin({ left : 16 }) + } else { + Text(item.split("#")[0]) + .fontSize(16) + .width("60%") + .height(64) + .alignSelf(ItemAlign.Center) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .margin({ left : 16 }) + } + Image($r("app.media.selectedMark")) + .height(24) + .width(24) + .alignSelf(ItemAlign.Center) + .margin({ right : 16 }) + .visibility(this.hapListPngVisibility[current]) } - if (item.split("#")[2] != "") { - Text(item.split("#")[2]) - .fontSize(16) - .width("60%") - .height(64) - .alignSelf(ItemAlign.Center) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .margin({ left : 16 }) - } else { - Text(item.split("#")[0]) - .fontSize(16) - .width("60%") - .height(64) - .alignSelf(ItemAlign.Center) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .margin({ left : 16 }) - } - Image($r("app.media.selectedMark")) - .height(24) - .width(24) - .alignSelf(ItemAlign.Center) - .margin({ right : 16 }) - .visibility(this.hapListPngVisibility[current]) + .onClick(() => { + this.cleanFirstListColorAndVisibility(); + this.cleanSecondListColorAndVisibility(); + this.selectItem = item; + this.hapListBackGround[current] = 0x1A0A59F7; + this.hapListPngVisibility[current] = 0; + this.isCheck = true; + }) } - .onClick(() => { - this.cleanFirstListColorAndVisibility(); - this.cleanSecondListColorAndVisibility(); - this.selectItem = item; - this.hapListBackGround[current] = 0x1A0A59F7; - this.hapListPngVisibility[current] = 0; - this.isCheck = true; + .backgroundColor(this.hapListBackGround[current]) + .borderRadius(12) + .height(64) + .width(328) + }, item => item) + ListItem() { + Button($r("app.string.message_moreOpenMode_selector"),{ type: ButtonType.Capsule }) + .fontSize(16) + .backgroundColor('#ffffffff') + .fontWeight(FontWeight.Medium) + .width(128) + .height(40) + .fontColor('#0A59F7') + .margin({ right : 218 }) + .onClick(() => { + this.onClickMoreApp() + this.moreOpenModeVisiable = 2 + this.moreOpenModeAreaHigh = 0 + this.moreHapListVisibility = 0 + this.moreAppsVisiable = 0 + this.moreAppsAreaHigh = 48 }) } - .backgroundColor(this.hapListBackGround[current]) - .borderRadius(12) - .height(64) - .width(328) - }, item => item) - ListItem() { - Button($r("app.string.message_moreOpenMode_selector"),{ type: ButtonType.Capsule }) - .fontSize(16) - .backgroundColor('#ffffffff') - .fontWeight(FontWeight.Medium) - .width(128) - .height(40) - .fontColor('#0A59F7') - .margin({ right : 218 }) - .onClick(() => { - this.onClickMoreApp() - this.moreOpenModeVisiable = 2 - this.moreOpenModeAreaHigh = 0 - this.moreHapListVisibility = 0 - this.moreAppsVisiable = 0 - this.moreAppsAreaHigh = 48 - }) - } - .visibility(this.moreOpenModeVisiable) - .width(346) - .height(this.moreOpenModeAreaHigh) - ListItem() { - Text($r("app.string.message_moreApps_selector")) - .fontSize(14) - .fontWeight(FontWeight.Medium) - .visibility(this.moreAppsVisiable) - .margin({ right : 234 }) - } - .width(346) - .height(this.moreAppsAreaHigh) - ForEach(this.pcShowMoreHapList, (item: any, current) => { + .visibility(this.moreOpenModeVisiable) + .width(346) + .height(this.moreOpenModeAreaHigh) ListItem() { - Flex({ direction: FlexDirection.Row }) { - if (item.split("#")[3] != "") { - Image(item.split("#")[3]) - .height(48) - .width(48) - .alignSelf(ItemAlign.Center) - .margin({ left : 16 }) - .borderRadius(12) - } else { - Image($r("app.media.app_icon")) - .height(48) - .width(48) - .alignSelf(ItemAlign.Center) - .margin({ left : 16 }) - .borderRadius(12) - } - if (item.split("#")[2] != "") { - Text(item.split("#")[2]) - .fontSize(16) - .width("60%") - .height(64) - .alignSelf(ItemAlign.Center) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .margin({ left : 16 }) - } else { - Text(item.split("#")[0]) - .fontSize(16) - .width("60%") - .height(64) - .alignSelf(ItemAlign.Center) - .height(56) - .width(394) - } - Image($r("app.media.selectedMark")) - .height(24) - .width(24) - .alignSelf(ItemAlign.Center) - .margin({ right : 16 }) - .visibility(this.moreHapListPngVisibility[current]) - } - .onClick(() => { - this.cleanFirstListColorAndVisibility(); - this.cleanSecondListColorAndVisibility(); - this.selectItem = item; - this.moreHapListBackGround[current] = 0x1A0A59F7; - this.moreHapListPngVisibility[current] = 0; - this.isCheck = true; - }) + Text($r("app.string.message_moreApps_selector")) + .fontSize(14) + .fontWeight(FontWeight.Medium) + .visibility(this.moreAppsVisiable) + .margin({ right : 234 }) } - .backgroundColor(this.moreHapListBackGround[current]) - .borderRadius(12) - .height(64) - .width(328) - .visibility(this.moreHapListVisibility) - }, item => item) + .width(346) + .height(this.moreAppsAreaHigh) + ForEach(this.pcShowMoreHapList, (item: any, current) => { + ListItem() { + Flex({ direction: FlexDirection.Row }) { + if (item.split("#")[3] != "") { + Image(item.split("#")[3]) + .height(48) + .width(48) + .alignSelf(ItemAlign.Center) + .margin({ left : 16 }) + .borderRadius(12) + } else { + Image($r("app.media.app_icon")) + .height(48) + .width(48) + .alignSelf(ItemAlign.Center) + .margin({ left : 16 }) + .borderRadius(12) + } + if (item.split("#")[2] != "") { + Text(item.split("#")[2]) + .fontSize(16) + .width("60%") + .height(64) + .alignSelf(ItemAlign.Center) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .margin({ left : 16 }) + } else { + Text(item.split("#")[0]) + .fontSize(16) + .width("60%") + .height(64) + .alignSelf(ItemAlign.Center) + .height(56) + .width(394) + } + Image($r("app.media.selectedMark")) + .height(24) + .width(24) + .alignSelf(ItemAlign.Center) + .margin({ right : 16 }) + .visibility(this.moreHapListPngVisibility[current]) + } + .onClick(() => { + this.cleanFirstListColorAndVisibility(); + this.cleanSecondListColorAndVisibility(); + this.selectItem = item; + this.moreHapListBackGround[current] = 0x1A0A59F7; + this.moreHapListPngVisibility[current] = 0; + this.isCheck = true; + }) + } + .backgroundColor(this.moreHapListBackGround[current]) + .borderRadius(12) + .height(64) + .width(328) + .visibility(this.moreHapListVisibility) + }, item => item) + } } .edgeEffect(EdgeEffect.None) .height(this.pcSelectorlist.height) From 7adfed450db910efb20c52f7287347146186a017 Mon Sep 17 00:00:00 2001 From: jsjzju Date: Mon, 26 Jun 2023 18:51:43 +0800 Subject: [PATCH 38/52] =?UTF-8?q?UIExtension=E5=8F=8C=E5=90=91=E9=80=9A?= =?UTF-8?q?=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jsjzju Change-Id: I35d57a4baeafa090cac7e8355954c56e67ac44e6 --- .../js_ui_extension_content_session.cpp | 122 +++++++++++++++++- .../js_ui_extension_content_session.h | 8 +- 2 files changed, 123 insertions(+), 7 deletions(-) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp index b0bd626e0a..d48aa9af63 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp @@ -16,6 +16,7 @@ #include "js_ui_extension_content_session.h" #include "ability_manager_client.h" +#include "event_handler.h" #include "hilog_wrapper.h" #include "js_error_utils.h" #include "js_runtime_utils.h" @@ -33,8 +34,8 @@ constexpr size_t ARGC_ONE = 1; } // namespace JsUIExtensionContentSession::JsUIExtensionContentSession( - sptr sessionInfo, sptr uiWindow) - : sessionInfo_(sessionInfo), uiWindow_(uiWindow) {} + NativeEngine& engine, sptr sessionInfo, sptr uiWindow) + : engine_(engine), sessionInfo_(sessionInfo), uiWindow_(uiWindow) {} void JsUIExtensionContentSession::Finalizer(NativeEngine* engine, void* data, void* hint) { @@ -99,19 +100,105 @@ NativeValue *JsUIExtensionContentSession::OnTerminateSelf(NativeEngine& engine, NativeValue *JsUIExtensionContentSession::OnTerminateSelfWithResult(NativeEngine& engine, NativeCallbackInfo& info) { HILOG_DEBUG("called"); - return nullptr; + if (info.argc < ARGC_ONE) { + HILOG_ERROR("invalid param"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + int resultCode = 0; + AAFwk::Want want; + if (!UnWrapAbilityResult(engine, info.argv[INDEX_ZERO], resultCode, want)) { + HILOG_ERROR("OnTerminateSelfWithResult Failed to parse ability result!"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + AsyncTask::CompleteCallback complete = + [uiWindow = uiWindow_, sessionInfo = sessionInfo_, want, resultCode](NativeEngine& engine, + AsyncTask& task, int32_t status) { + if (uiWindow == nullptr) { + HILOG_WARN("uiWindow is nullptr"); + task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + auto ret = uiWindow->TransferAbilityResult(resultCode, want); + if (ret != Rosen::WMError::WM_OK) { + task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + auto errorCode = AAFwk::AbilityManagerClient::GetInstance()->TerminateUIExtensionAbility(sessionInfo); + if (errorCode == 0) { + task.ResolveWithNoError(engine, engine.CreateUndefined()); + } else { + task.Reject(engine, CreateJsErrorByNativeErr(engine, errorCode)); + } + }; + + NativeValue* lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr; + NativeValue* result = nullptr; + AsyncTask::Schedule("JsUIExtensionContentSession::OnTerminateSelfWithResult", + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; } NativeValue *JsUIExtensionContentSession::OnSendData(NativeEngine& engine, NativeCallbackInfo& info) { HILOG_DEBUG("called"); - return nullptr; + if (info.argc < ARGC_ONE) { + HILOG_ERROR("invalid param"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + AAFwk::WantParams params; + if (!AppExecFwk::UnwrapWantParams(reinterpret_cast(&engine), + reinterpret_cast(info.argv[INDEX_ZERO]), params)) { + HILOG_ERROR("OnSendData Failed to parse param!"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + if (uiWindow_ == nullptr) { + HILOG_ERROR("uiWindow_ is nullptr"); + return engine.CreateNumber(static_cast(AbilityErrorCode::ERROR_CODE_INNER)); + } + + Rosen::WMError ret = uiWindow_->TransferExtensionData(params); + if (ret == Rosen::WMError::WM_OK) { + return engine.CreateNumber(static_cast(AbilityErrorCode::ERROR_OK)); + } else { + return engine.CreateNumber(static_cast(AbilityErrorCode::ERROR_CODE_INNER)); + } } NativeValue *JsUIExtensionContentSession::OnSetReceiveDataCallback(NativeEngine& engine, NativeCallbackInfo& info) { HILOG_DEBUG("called"); - return nullptr; + if (info.argc < ARGC_ONE || info.argv[INDEX_ZERO]->TypeOf() != NATIVE_FUNCTION) { + HILOG_ERROR("invalid param"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } + + NativeValue* callback = info.argv[INDEX_ZERO]; + receiveDataCallback_.reset(engine.CreateReference(callback, 1)); + if (!isRegistered) { + if (uiWindow_ == nullptr) { + HILOG_ERROR("uiWindow_ is nullptr"); + return engine.CreateNumber(static_cast(AbilityErrorCode::ERROR_CODE_INNER)); + } + std::weak_ptr weakCallback(receiveDataCallback_); + auto handler = std::make_shared(AppExecFwk::EventRunner::GetMainEventRunner()); + uiWindow_->RegisterTransferComponentDataListener([&engine = engine_, handler, weakCallback]( + const AAFwk::WantParams& wantParams) { + if (handler) { + handler->PostTask([&engine, weakCallback, wantParams]() { + JsUIExtensionContentSession::CallReceiveDataCallBack(engine, weakCallback, wantParams); + }); + } + }); + isRegistered = true; + } + return engine.CreateNumber(static_cast(AbilityErrorCode::ERROR_OK)); } NativeValue *JsUIExtensionContentSession::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info) @@ -148,7 +235,7 @@ NativeValue *JsUIExtensionContentSession::CreateJsUIExtensionContentSession(Nati NativeObject* object = ConvertNativeValueTo(objValue); std::unique_ptr jsSession = - std::make_unique(sessionInfo, uiWindow); + std::make_unique(engine, sessionInfo, uiWindow); object->SetNativePointer(jsSession.release(), Finalizer, nullptr); const char *moduleName = "JsUIExtensionContentSession"; @@ -160,6 +247,29 @@ NativeValue *JsUIExtensionContentSession::CreateJsUIExtensionContentSession(Nati return objValue; } +void JsUIExtensionContentSession::CallReceiveDataCallBack(NativeEngine& engine, + std::weak_ptr weakCallback, const AAFwk::WantParams& wantParams) +{ + auto callback = weakCallback.lock(); + if (callback == nullptr) { + HILOG_WARN("callback is nullptr"); + return; + } + NativeValue* method = callback->Get(); + if (method == nullptr) { + HILOG_WARN("method is nullptr"); + return; + } + HandleScope handleScope(engine); + NativeValue* nativeWantParams = AppExecFwk::CreateJsWantParams(engine, wantParams); + if (nativeWantParams == nullptr) { + HILOG_ERROR("nativeWantParams is nullptr"); + return; + } + NativeValue* argv[] = {nativeWantParams}; + engine.CallFunction(engine.GetGlobal(), method, argv, ARGC_ONE); +} + bool JsUIExtensionContentSession::UnWrapAbilityResult(NativeEngine& engine, NativeValue* argv, int& resultCode, AAFwk::Want& want) { diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_content_session.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_content_session.h index f593ff7258..5b57aecae3 100644 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_content_session.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_content_session.h @@ -24,7 +24,8 @@ namespace OHOS { namespace AbilityRuntime { class JsUIExtensionContentSession { public: - JsUIExtensionContentSession(sptr sessionInfo, sptr uiWindow); + JsUIExtensionContentSession(NativeEngine& engine, sptr sessionInfo, + sptr uiWindow); virtual ~JsUIExtensionContentSession() = default; static void Finalizer(NativeEngine* engine, void* data, void* hint); static NativeValue* CreateJsUIExtensionContentSession(NativeEngine& engine, @@ -43,10 +44,15 @@ protected: NativeValue* OnSetReceiveDataCallback(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info); + static void CallReceiveDataCallBack(NativeEngine& engine, std::weak_ptr weakCallback, + const AAFwk::WantParams& wantParams); static bool UnWrapAbilityResult(NativeEngine& engine, NativeValue* argv, int& resultCode, AAFwk::Want& want); private: + NativeEngine& engine_; sptr sessionInfo_; sptr uiWindow_; + std::shared_ptr receiveDataCallback_; + bool isRegistered = false; }; } // namespace AbilityRuntime } // namespace OHOS From ff5c6067084c22d9f9091cf4e15f76c43189ad21 Mon Sep 17 00:00:00 2001 From: renhw001 Date: Wed, 28 Jun 2023 11:22:23 +0000 Subject: [PATCH 39/52] update services/abilitymgr/src/mission_data_storage.cpp. Signed-off-by: renhw001 --- services/abilitymgr/src/mission_data_storage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/mission_data_storage.cpp b/services/abilitymgr/src/mission_data_storage.cpp index d4c52d8b5e..10de6b8dfd 100644 --- a/services/abilitymgr/src/mission_data_storage.cpp +++ b/services/abilitymgr/src/mission_data_storage.cpp @@ -394,7 +394,7 @@ std::unique_ptr MissionDataStorage::ReadFileToBuffer(const std::strin fseek(fp, 0, SEEK_SET); if (bufferSize < fileSize) { HILOG_ERROR("ReadFileToBuffer:buffer size:(%{public}zu) is smaller than file size:(%{public}zu).", bufferSize, - fileSize); + fileSize); fclose(fp); return nullptr; } From 35d633463b1e08c73edc49ad7b9d21803f397e08 Mon Sep 17 00:00:00 2001 From: wuhaohao7 Date: Wed, 28 Jun 2023 19:46:10 +0800 Subject: [PATCH 40/52] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E9=83=A8=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuhaohao7 --- bundle.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bundle.json b/bundle.json index d1fd6e31b1..c4cf9dbee3 100644 --- a/bundle.json +++ b/bundle.json @@ -60,7 +60,6 @@ "hitrace", "hiview", "i18n", - "icu", "init", "input", "ipc", From 3c719dd3d6e92206159f0f39d5be02bc3f2fce53 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 28 Jun 2023 21:28:33 +0800 Subject: [PATCH 41/52] add user Signed-off-by: unknown --- services/abilitymgr/src/data_ability_record.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/services/abilitymgr/src/data_ability_record.cpp b/services/abilitymgr/src/data_ability_record.cpp index 58bfd9fcad..bc4069becc 100644 --- a/services/abilitymgr/src/data_ability_record.cpp +++ b/services/abilitymgr/src/data_ability_record.cpp @@ -226,16 +226,6 @@ int DataAbilityRecord::AddClient(const sptr &client, bool tryBind clientInfo.tryBind = tryBind; clientInfo.isNotHap = isNotHap; clientInfo.clientPid = IPCSkeleton::GetCallingPid(); - if (!isNotHap) { - auto clientAbilityRecord = Token::GetAbilityRecordByToken(client); - CHECK_POINTER_AND_RETURN(clientAbilityRecord, ERR_UNKNOWN_OBJECT); - appScheduler->AbilityBehaviorAnalysis(ability_->GetToken(), clientAbilityRecord->GetToken(), 0, 0, 1); - HILOG_INFO("Ability '%{public}s|%{public}s'.", clientAbilityRecord->GetApplicationInfo().bundleName.c_str(), - clientAbilityRecord->GetAbilityInfo().name.c_str()); - } - - HILOG_INFO("Data ability '%{public}s|%{public}s'.", ability_->GetApplicationInfo().bundleName.c_str(), - ability_->GetAbilityInfo().name.c_str()); return ERR_OK; } From 14e9e26625f2c385ed5c44efc16d9b47b1c22497 Mon Sep 17 00:00:00 2001 From: liuliu Date: Tue, 27 Jun 2023 21:09:11 +0800 Subject: [PATCH 42/52] fix back Signed-off-by: liuliu Change-Id: I3e2943c5048e9649e0b93754590bf66b5d05491a --- .../ability_manager/include/window_info.h | 2 ++ services/abilitymgr/include/ability_record.h | 7 ++++-- services/abilitymgr/src/ability_record.cpp | 25 ++++++++++++++++--- .../abilitymgr/src/mission_list_manager.cpp | 6 ++++- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/interfaces/inner_api/ability_manager/include/window_info.h b/interfaces/inner_api/ability_manager/include/window_info.h index 74e563546c..512582b575 100644 --- a/interfaces/inner_api/ability_manager/include/window_info.h +++ b/interfaces/inner_api/ability_manager/include/window_info.h @@ -34,6 +34,8 @@ enum class TransitionReason : uint32_t { CLOSE, ABILITY_TRANSITION, BACK_TRANSITION, + CLOSE_BUTTON, + BACKGROUND_TRANSITION, }; struct AbilityTransitionInfo : public Parcelable { diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index b27e1a3f33..4e84355ecd 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -469,8 +469,10 @@ public: std::shared_ptr &startOptions, const std::shared_ptr &callerAbility, uint32_t sceneFlag = 0); - void ProcessForegroundAbility(const std::shared_ptr &callerAbility, uint32_t sceneFlag = 0); + void ProcessForegroundAbility(const std::shared_ptr &callerAbility, bool needExit = true, + uint32_t sceneFlag = 0); void NotifyAnimationFromTerminatingAbility() const; + void NotifyAnimationFromMinimizeAbility() const; void SetCompleteFirstFrameDrawing(const bool flag); bool IsCompleteFirstFrameDrawing() const; @@ -928,7 +930,8 @@ private: const AbilityRequest &abilityRequest) const; void NotifyAnimationFromRecentTask(const std::shared_ptr &startOptions, const std::shared_ptr &want) const; - void NotifyAnimationFromTerminatingAbility(const std::shared_ptr &callerAbility, bool flag); + void NotifyAnimationFromTerminatingAbility(const std::shared_ptr &callerAbility, bool needExit, + bool flag); void StartingWindowTask(bool isRecent, bool isCold, const AbilityRequest &abilityRequest, std::shared_ptr &startOptions); diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index ed1d7ff684..2e61b4ba45 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -446,7 +446,8 @@ std::string AbilityRecord::GetLabel() } #ifdef SUPPORT_GRAPHICS -void AbilityRecord::ProcessForegroundAbility(const std::shared_ptr &callerAbility, uint32_t sceneFlag) +void AbilityRecord::ProcessForegroundAbility(const std::shared_ptr &callerAbility, bool needExit, + uint32_t sceneFlag) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); std::string element = GetWant().GetElement().GetURI(); @@ -454,7 +455,7 @@ void AbilityRecord::ProcessForegroundAbility(const std::shared_ptr& callerAbility, - bool flag) + bool needExit, bool flag) { auto windowHandler = GetWMSHandler(); if (!windowHandler) { @@ -484,8 +485,10 @@ void AbilityRecord::NotifyAnimationFromTerminatingAbility(const std::shared_ptr< fromInfo->abilityToken_ = callerAbility->GetToken(); } - if (flag) { + if (flag && needExit) { fromInfo->reason_ = TransitionReason::BACK_TRANSITION; + } else if (flag && !needExit) { + fromInfo->reason_ = TransitionReason::BACKGROUND_TRANSITION; } else { fromInfo->reason_ = TransitionReason::CLOSE; } @@ -510,6 +513,20 @@ void AbilityRecord::NotifyAnimationFromTerminatingAbility() const windowHandler->NotifyWindowTransition(fromInfo, nullptr); } +void AbilityRecord::NotifyAnimationFromMinimizeAbility() const +{ + auto windowHandler = GetWMSHandler(); + if (!windowHandler) { + HILOG_WARN("Get WMS handler failed."); + return; + } + + sptr fromInfo = new AbilityTransitionInfo(); + SetAbilityTransitionInfo(fromInfo); + fromInfo->reason_ = TransitionReason::MINIMIZE; + windowHandler->NotifyWindowTransition(fromInfo, nullptr); +} + void AbilityRecord::SetAbilityTransitionInfo(sptr& info) const { info->abilityToken_ = token_; diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index bf926ea467..b7836726c9 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -1359,8 +1359,12 @@ int MissionListManager::MoveAbilityToBackgroundLocked(const std::shared_ptrSetPreAbilityRecord(abilityRecord); #ifdef SUPPORT_GRAPHICS nextAbilityRecord->SetPendingState(AbilityState::FOREGROUND); - nextAbilityRecord->ProcessForegroundAbility(abilityRecord); + nextAbilityRecord->ProcessForegroundAbility(abilityRecord, false); } else { + if (!abilityRecord->IsClearMissionFlag()) { + abilityRecord->NotifyAnimationFromMinimizeAbility(); + return ERR_OK; + } #else nextAbilityRecord->ProcessForegroundAbility(); } else { From 73724fa7f25a8da743b575903b5c41407ddfd3ca Mon Sep 17 00:00:00 2001 From: songjindian Date: Thu, 29 Jun 2023 09:42:20 +0800 Subject: [PATCH 43/52] =?UTF-8?q?tdd=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songjindian --- test/unittest/app_mgr_service_test/app_mgr_service_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index 831e956542..c7ad209b85 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -599,7 +599,7 @@ HWTEST_F(AppMgrServiceTest, FinishUserTest_002, TestSize.Level0) appMgrService->taskHandler_ = taskHandler_; appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); int res = appMgrService->FinishUserTest(msg, resultCode, bundleName); - EXPECT_NE(res, ERR_INVALID_OPERATION); + EXPECT_EQ(res, ERR_INVALID_OPERATION); } /* From b6b1718379e274cff6db63ec7e53d35547f8fcae Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Thu, 29 Jun 2023 11:31:10 +0800 Subject: [PATCH 44/52] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- .../ability_manager_client_branch_test.cpp | 23 +++++ .../unittest/runtime_test/js_runtime_test.cpp | 91 +++++++++++++++++++ .../want_agent_test/want_agent_test.cpp | 40 ++++++++ 3 files changed, 154 insertions(+) diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp index b44894e008..7faf4cb3f8 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp @@ -1409,5 +1409,28 @@ HWTEST_F(AbilityManagerClientBranchTest, RequestDialogService_0100, TestSize.Lev auto result = client_->RequestDialogService(want, callerToken); EXPECT_EQ(result, ERR_OK); } + +/** + * @tc.name: AbilityManagerClient_SetSessionManagerService_0100 + * @tc.desc: SetSessionManagerService + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerClientBranchTest, AbilityManagerClient_SetSessionManagerService_0100, TestSize.Level1) +{ + sptr sessionManagerService = nullptr; + auto result = client_->SetSessionManagerService(sessionManagerService); + EXPECT_TRUE(result = ERR_WRONG_INTERFACE_CALL); +} + +/** + * @tc.name: AbilityManagerClient_GetSessionManagerService_0100 + * @tc.desc: GetSessionManagerService + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerClientBranchTest, AbilityManagerClient_GetSessionManagerService_0100, TestSize.Level1) +{ + auto result = client_->GetSessionManagerService(); + EXPECT_TRUE(result == nullptr); +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/runtime_test/js_runtime_test.cpp b/test/unittest/runtime_test/js_runtime_test.cpp index 9c21de76cd..973185ef6a 100755 --- a/test/unittest/runtime_test/js_runtime_test.cpp +++ b/test/unittest/runtime_test/js_runtime_test.cpp @@ -754,5 +754,96 @@ HWTEST_F(JsRuntimeTest, PostSyncTask_0100, TestSize.Level0) jsRuntime->PostSyncTask(task, taskName); EXPECT_EQ(taskExecuted, true); } + +/** + * @tc.name: PostTask_0100 + * @tc.desc: Js runtime post task. + * @tc.type: FUNC + * @tc.require: issueI7C87T + */ +HWTEST_F(JsRuntimeTest, PostTask_0100, TestSize.Level0) +{ + HILOG_INFO("PostTask_0100 start"); + auto jsRuntime = AbilityRuntime::JsRuntime::Create(options_); + ASSERT_NE(jsRuntime, nullptr); + + std::string taskName = "postTask001"; + bool taskExecuted = false; + auto task = [taskName, &taskExecuted]() { + HILOG_INFO("%{public}s called.", taskName.c_str()); + taskExecuted = true; + }; + int64_t delayTime = 10; + jsRuntime->PostTask(task, taskName, delayTime); + EXPECT_NE(taskExecuted, true); + HILOG_INFO("PostTask_0100 end"); +} + +/** + * @tc.name: RemoveTask_0100 + * @tc.desc: Js runtime remove task. + * @tc.type: FUNC + * @tc.require: issueI7C87T + */ +HWTEST_F(JsRuntimeTest, RemoveTask_0100, TestSize.Level0) +{ + HILOG_INFO("RemoveTask_0100 start"); + auto jsRuntime = AbilityRuntime::JsRuntime::Create(options_); + ASSERT_NE(jsRuntime, nullptr); + + std::string taskName = "removeTask001"; + bool taskExecuted = false; + auto task = [taskName, &taskExecuted]() { + HILOG_INFO("%{public}s called.", taskName.c_str()); + taskExecuted = true; + }; + int64_t delayTime = 10; + jsRuntime->PostTask(task, taskName, delayTime); + jsRuntime->RemoveTask(taskName); + EXPECT_NE(taskExecuted, true); + HILOG_INFO("RemoveTask_0100 end"); +} + +/** + * @tc.name: StartDebugger_0100 + * @tc.desc: JsRuntime test for StartDebugger. + * @tc.type: FUNC + */ +HWTEST_F(JsRuntimeTest, StartDebugger_0100, TestSize.Level0) +{ + HILOG_INFO("StartDebugger_0100 start"); + + AbilityRuntime::Runtime::Options options; + options.preload = true; + auto jsRuntime = AbilityRuntime::JsRuntime::Create(options); + + ASSERT_NE(jsRuntime, nullptr); + + bool needBreakPoint = false; + uint32_t instanceId = 1; + + auto result = jsRuntime->StartDebugger(needBreakPoint, instanceId); + EXPECT_NE(result, false); + HILOG_INFO("StartDebugger_0100 end"); +} + +/** + * @tc.name: DoCleanWorkAfterStageCleaned_0100 + * @tc.desc: JsRuntime test for DoCleanWorkAfterStageCleaned. + * @tc.type: FUNC + */ +HWTEST_F(JsRuntimeTest, DoCleanWorkAfterStageCleaned_0100, TestSize.Level0) +{ + HILOG_INFO("DoCleanWorkAfterStageCleaned_0100 start"); + + AbilityRuntime::Runtime::Options options; + options.preload = true; + auto jsRuntime = AbilityRuntime::JsRuntime::Create(options); + + ASSERT_NE(jsRuntime, nullptr); + + jsRuntime->DoCleanWorkAfterStageCleaned(); + HILOG_INFO("DoCleanWorkAfterStageCleaned_0100 end"); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/test/unittest/want_agent_test/want_agent_test.cpp b/test/unittest/want_agent_test/want_agent_test.cpp index 07ea83d240..5db6d2f414 100644 --- a/test/unittest/want_agent_test/want_agent_test.cpp +++ b/test/unittest/want_agent_test/want_agent_test.cpp @@ -91,4 +91,44 @@ HWTEST_F(WantAgentTest, WantAgent_0200, Function | MediumTest | Level1) std::shared_ptr wantAgent = std::make_shared(pendingWant); EXPECT_EQ(wantAgent->GetPendingWant(), pendingWant); } + +/* + * @tc.number : WantAgent_0300 + * @tc.name : WantAgentInfo Constructors + * @tc.desc : 1.Constructors and SetPendingWant + */ +HWTEST_F(WantAgentTest, WantAgent_0300, Function | MediumTest | Level1) +{ + sptr target(new (std::nothrow) PendingWantRecord()); + std::shared_ptr pendingWant = std::make_shared(target); + std::shared_ptr wantAgent = std::make_shared(pendingWant); + EXPECT_NE(wantAgent, nullptr); + wantAgent->SetPendingWant(pendingWant); +} + +/* + * @tc.number : WantAgent_0400 + * @tc.name : WantAgentInfo Constructors + * @tc.desc : 1.Constructors and Marshalling + */ +HWTEST_F(WantAgentTest, WantAgent_0400, Function | MediumTest | Level1) +{ + std::shared_ptr wantAgent = std::make_shared(nullptr); + Parcel parcel; + bool ret = wantAgent->Marshalling(parcel); + EXPECT_EQ(ret, true); +} + +/* + * @tc.number : WantAgent_0500 + * @tc.name : WantAgentInfo Constructors + * @tc.desc : 1.Constructors and Unmarshalling + */ +HWTEST_F(WantAgentTest, WantAgent_0500, Function | MediumTest | Level1) +{ + std::shared_ptr wantAgent = std::make_shared(nullptr); + Parcel parcel; + bool ret = wantAgent->Unmarshalling(parcel); + EXPECT_EQ(ret, true); +} } // namespace OHOS::AbilityRuntime::WantAgent From cd1af8998813859c530791ed08c08ba378f02ec2 Mon Sep 17 00:00:00 2001 From: liuliu Date: Thu, 29 Jun 2023 12:04:22 +0800 Subject: [PATCH 45/52] add animalEnabled Signed-off-by: liuliu Change-Id: I042206abd87d349967dcec980ccca89b2871e959 --- .../include/window_manager_service_handler.h | 3 ++- .../window_manager_service_handler_proxy.h | 2 +- .../window_manager_service_handler_proxy.cpp | 7 ++++++- .../window_manager_service_handler_stub.cpp | 4 +++- services/abilitymgr/include/ability_record.h | 2 +- services/abilitymgr/src/ability_record.cpp | 20 ++++++++++--------- .../abilitymgr/src/mission_list_manager.cpp | 7 +++++-- .../ability_record_test.cpp | 3 ++- .../mission_list_manager_test.cpp | 3 ++- 9 files changed, 33 insertions(+), 18 deletions(-) diff --git a/interfaces/inner_api/ability_manager/include/window_manager_service_handler.h b/interfaces/inner_api/ability_manager/include/window_manager_service_handler.h index 296b574e5c..14a8d3c350 100644 --- a/interfaces/inner_api/ability_manager/include/window_manager_service_handler.h +++ b/interfaces/inner_api/ability_manager/include/window_manager_service_handler.h @@ -31,7 +31,8 @@ class IWindowManagerServiceHandler : public OHOS::IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.WindowManagerServiceHandler"); - virtual void NotifyWindowTransition(sptr fromInfo, sptr toInfo) = 0; + virtual void NotifyWindowTransition(sptr fromInfo, sptr toInfo, + bool& animaEnabled) = 0; virtual int32_t GetFocusWindow(sptr& abilityToken) = 0; diff --git a/interfaces/inner_api/ability_manager/include/window_manager_service_handler_proxy.h b/interfaces/inner_api/ability_manager/include/window_manager_service_handler_proxy.h index 845abb3cb8..7b9cbef0d2 100644 --- a/interfaces/inner_api/ability_manager/include/window_manager_service_handler_proxy.h +++ b/interfaces/inner_api/ability_manager/include/window_manager_service_handler_proxy.h @@ -28,7 +28,7 @@ public: virtual ~WindowManagerServiceHandlerProxy() = default; virtual void NotifyWindowTransition(sptr fromInfo, - sptr toInfo) override; + sptr toInfo, bool& animaEnabled) override; virtual int32_t GetFocusWindow(sptr& abilityToken) override; diff --git a/interfaces/inner_api/ability_manager/src/window_manager_service_handler_proxy.cpp b/interfaces/inner_api/ability_manager/src/window_manager_service_handler_proxy.cpp index cce3ba4fa6..c1b4a56113 100644 --- a/interfaces/inner_api/ability_manager/src/window_manager_service_handler_proxy.cpp +++ b/interfaces/inner_api/ability_manager/src/window_manager_service_handler_proxy.cpp @@ -26,7 +26,7 @@ WindowManagerServiceHandlerProxy::WindowManagerServiceHandlerProxy(const sptr(impl) {} void WindowManagerServiceHandlerProxy::NotifyWindowTransition(sptr fromInfo, - sptr toInfo) + sptr toInfo, bool& animaEnabled) { HILOG_DEBUG("%{public}s is called.", __func__); MessageParcel data; @@ -42,12 +42,17 @@ void WindowManagerServiceHandlerProxy::NotifyWindowTransition(sptrSendRequest(WMSCmd::ON_NOTIFY_WINDOW_TRANSITION, data, reply, option); if (error != ERR_OK) { HILOG_ERROR("SendRequest fail, error: %{public}d", error); } + animaEnabled = reply.ReadBool(); } int32_t WindowManagerServiceHandlerProxy::GetFocusWindow(sptr& abilityToken) diff --git a/interfaces/inner_api/ability_manager/src/window_manager_service_handler_stub.cpp b/interfaces/inner_api/ability_manager/src/window_manager_service_handler_stub.cpp index 20b65aa77c..37a26a89f5 100644 --- a/interfaces/inner_api/ability_manager/src/window_manager_service_handler_stub.cpp +++ b/interfaces/inner_api/ability_manager/src/window_manager_service_handler_stub.cpp @@ -76,7 +76,9 @@ int WindowManagerServiceHandlerStub::NotifyWindowTransitionInner(MessageParcel & HILOG_ERROR("To read toInfo failed."); return ERR_AAFWK_PARCEL_FAIL; } - NotifyWindowTransition(fromInfo, toInfo); + bool animaEnabled = data.ReadBool(); + NotifyWindowTransition(fromInfo, toInfo, animaEnabled); + reply.WriteBool(animaEnabled); return ERR_OK; } diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 4e84355ecd..da476134d1 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -472,7 +472,7 @@ public: void ProcessForegroundAbility(const std::shared_ptr &callerAbility, bool needExit = true, uint32_t sceneFlag = 0); void NotifyAnimationFromTerminatingAbility() const; - void NotifyAnimationFromMinimizeAbility() const; + void NotifyAnimationFromMinimizeAbility(bool& animaEnabled); void SetCompleteFirstFrameDrawing(const bool flag); bool IsCompleteFirstFrameDrawing() const; diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 2e61b4ba45..0b19b6a268 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -495,8 +495,8 @@ void AbilityRecord::NotifyAnimationFromTerminatingAbility(const std::shared_ptr< auto toInfo = CreateAbilityTransitionInfo(); SetAbilityTransitionInfo(abilityInfo_, toInfo); - - windowHandler->NotifyWindowTransition(fromInfo, toInfo); + bool animaEnabled = false; + windowHandler->NotifyWindowTransition(fromInfo, toInfo, animaEnabled); } void AbilityRecord::NotifyAnimationFromTerminatingAbility() const @@ -510,21 +510,22 @@ void AbilityRecord::NotifyAnimationFromTerminatingAbility() const sptr fromInfo = new AbilityTransitionInfo(); SetAbilityTransitionInfo(fromInfo); fromInfo->reason_ = TransitionReason::CLOSE; - windowHandler->NotifyWindowTransition(fromInfo, nullptr); + bool animaEnabled = false; + windowHandler->NotifyWindowTransition(fromInfo, nullptr, animaEnabled); } -void AbilityRecord::NotifyAnimationFromMinimizeAbility() const +void AbilityRecord::NotifyAnimationFromMinimizeAbility(bool& animaEnabled) { auto windowHandler = GetWMSHandler(); if (!windowHandler) { HILOG_WARN("Get WMS handler failed."); return; } - + HILOG_INFO("Notify Animation From MinimizeAbility"); sptr fromInfo = new AbilityTransitionInfo(); SetAbilityTransitionInfo(fromInfo); fromInfo->reason_ = TransitionReason::MINIMIZE; - windowHandler->NotifyWindowTransition(fromInfo, nullptr); + windowHandler->NotifyWindowTransition(fromInfo, nullptr, animaEnabled); } void AbilityRecord::SetAbilityTransitionInfo(sptr& info) const @@ -681,7 +682,8 @@ void AbilityRecord::NotifyAnimationFromRecentTask(const std::shared_ptr fromInfo = new AbilityTransitionInfo(); fromInfo->isRecent_ = true; - windowHandler->NotifyWindowTransition(fromInfo, toInfo); + bool animaEnabled = false; + windowHandler->NotifyWindowTransition(fromInfo, toInfo, animaEnabled); } void AbilityRecord::NotifyAnimationFromStartingAbility(const std::shared_ptr &callerAbility, @@ -706,8 +708,8 @@ void AbilityRecord::NotifyAnimationFromStartingAbility(const std::shared_ptrabilityToken_ = token_; toInfo->missionId_ = missionId_; SetAbilityTransitionInfo(abilityInfo_, toInfo); - - windowHandler->NotifyWindowTransition(fromInfo, toInfo); + bool animaEnabled = false; + windowHandler->NotifyWindowTransition(fromInfo, toInfo, animaEnabled); } void AbilityRecord::StartingWindowTask(bool isRecent, bool isCold, const AbilityRequest &abilityRequest, diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index b7836726c9..392586ef36 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -1361,8 +1361,11 @@ int MissionListManager::MoveAbilityToBackgroundLocked(const std::shared_ptrSetPendingState(AbilityState::FOREGROUND); nextAbilityRecord->ProcessForegroundAbility(abilityRecord, false); } else { + bool animaEnabled = false; if (!abilityRecord->IsClearMissionFlag()) { - abilityRecord->NotifyAnimationFromMinimizeAbility(); + abilityRecord->NotifyAnimationFromMinimizeAbility(animaEnabled); + } + if (animaEnabled) { return ERR_OK; } #else @@ -1392,7 +1395,7 @@ void MissionListManager::RemoveBackgroundingAbility(const std::shared_ptrIsEmpty()) { - HILOG_DEBUG("Remove terminating ability, missionList is empty, remove."); + HILOG_DEBUG("Remove backgrounding ability, missionList is empty, remove."); RemoveMissionList(missionList); } diff --git a/test/unittest/ability_record_test/ability_record_test.cpp b/test/unittest/ability_record_test/ability_record_test.cpp index 2eb2d67d0d..b62fdd57b1 100644 --- a/test/unittest/ability_record_test/ability_record_test.cpp +++ b/test/unittest/ability_record_test/ability_record_test.cpp @@ -114,7 +114,8 @@ bool IsTestAbilityExist2(const std::string& data) class MockWMSHandler : public IWindowManagerServiceHandler { public: - virtual void NotifyWindowTransition(sptr fromInfo, sptr toInfo) + virtual void NotifyWindowTransition(sptr fromInfo, sptr toInfo, + bool& animaEnabled) {} virtual int32_t GetFocusWindow(sptr& abilityToken) diff --git a/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp b/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp index d942be77da..875ec1d415 100644 --- a/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp +++ b/test/unittest/mission_list_manager_test/mission_list_manager_test.cpp @@ -89,7 +89,8 @@ bool g_cancelStartingWindowCalled = false; class MockWMSHandler : public IWindowManagerServiceHandler { public: - virtual void NotifyWindowTransition(sptr fromInfo, sptr toInfo) + virtual void NotifyWindowTransition(sptr fromInfo, sptr toInfo, + bool& animaEnabled) { g_notifyWindowTransitionCalled = true; } From 8181f5f57f81e01074939431d586c765e7c92003 Mon Sep 17 00:00:00 2001 From: zhoushicheng Date: Wed, 28 Jun 2023 08:26:09 +0000 Subject: [PATCH 46/52] Issue:#I7GRPC Signed-off-by: zhoushicheng Change-Id: Ia83723c7733b4ff780964d1df04d924c8b6547d8 --- .../abilitymanager_fuzzer.cpp | 202 ++++++++++++++++-- 1 file changed, 181 insertions(+), 21 deletions(-) diff --git a/test/fuzztest/abilitymanager_fuzzer/abilitymanager_fuzzer.cpp b/test/fuzztest/abilitymanager_fuzzer/abilitymanager_fuzzer.cpp index 67ad37277a..cc1c129721 100644 --- a/test/fuzztest/abilitymanager_fuzzer/abilitymanager_fuzzer.cpp +++ b/test/fuzztest/abilitymanager_fuzzer/abilitymanager_fuzzer.cpp @@ -30,6 +30,7 @@ constexpr size_t FOO_MAX_LEN = 1024; constexpr size_t U32_AT_SIZE = 4; } const std::u16string ABILITYMGR_INTERFACE_TOKEN = u"ohos.aafwk.AbilityManager"; +std::map codeMap_; uint32_t GetU32Data(const char* ptr) { @@ -37,30 +38,189 @@ uint32_t GetU32Data(const char* ptr) return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]; } +void EmplaceCodeMap1() +{ + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::TERMINATE_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::ATTACH_ABILITY_THREAD)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::ABILITY_TRANSITION_DONE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CONNECT_ABILITY_DONE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::DISCONNECT_ABILITY_DONE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::ADD_WINDOW_INFO)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::TERMINATE_ABILITY_RESULT)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::LIST_STACK_INFO)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_RECENT_MISSION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REMOVE_MISSION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REMOVE_STACK)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::COMMAND_ABILITY_DONE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_MISSION_SNAPSHOT)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::ACQUIRE_DATA_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::RELEASE_DATA_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MOVE_MISSION_TO_TOP)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::KILL_PROCESS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::UNINSTALL_APP)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::TERMINATE_ABILITY_BY_CALLER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MOVE_MISSION_TO_FLOATING_STACK)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MOVE_MISSION_TO_SPLITSCREEN_STACK)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CHANGE_FOCUS_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MINIMIZE_MULTI_WINDOW)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MAXIMIZE_MULTI_WINDOW)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_FLOATING_MISSIONS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CLOSE_MULTI_WINDOW)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MOVE_MISSION_TO_END)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::COMPEL_VERIFY_PERMISSION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::POWER_OFF)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::POWER_ON)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::LUCK_MISSION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::UNLUCK_MISSION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SET_MISSION_INFO)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_MISSION_LOCK_MODE_STATE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MINIMIZE_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::LOCK_MISSION_FOR_CLEANUP)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::UNLOCK_MISSION_FOR_CLEANUP)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REGISTER_MISSION_LISTENER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::UNREGISTER_MISSION_LISTENER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_MISSION_INFOS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_MISSION_INFO_BY_ID)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CLEAN_MISSION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CLEAN_ALL_MISSIONS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MOVE_MISSION_TO_FRONT)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_MISSION_SNAPSHOT_BY_ID)); +} + +void EmplaceCodeMap2() +{ + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_USER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::STOP_USER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SET_ABILITY_CONTROLLER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::IS_USER_A_STABILITY_TEST)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SET_MISSION_LABEL)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::DO_ABILITY_FOREGROUND)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::DO_ABILITY_BACKGROUND)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MOVE_MISSION_TO_FRONT_BY_OPTIONS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_MISSION_ID_BY_ABILITY_TOKEN)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SET_MISSION_ICON)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::DUMP_ABILITY_INFO_DONE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_EXTENSION_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::STOP_EXTENSION_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SET_COMPONENT_INTERCEPTION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SEND_ABILITY_RESULT_BY_TOKEN)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SET_ROOT_SCENE_SESSION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::PREPARE_TERMINATE_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::COMMAND_ABILITY_WINDOW_DONE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CALL_ABILITY_BY_SCB)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MOVE_ABILITY_TO_BACKGROUND)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CONNECT_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::DISCONNECT_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::STOP_SERVICE_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_ABILITY_ADD_CALLER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_PENDING_WANT_SENDER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SEND_PENDING_WANT_SENDER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CANCEL_PENDING_WANT_SENDER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_PENDING_WANT_UID)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_PENDING_WANT_BUNDLENAME)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_PENDING_WANT_USERID)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_PENDING_WANT_TYPE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_PENDING_WANT_CODE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REGISTER_CANCEL_LISTENER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::UNREGISTER_CANCEL_LISTENER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_PENDING_REQUEST_WANT)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_PENDING_WANT_SENDER_INFO)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SET_SHOW_ON_LOCK_SCREEN)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SEND_APP_NOT_RESPONSE_PROCESS_ID)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_ABILITY_FOR_SETTINGS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_ABILITY_MISSION_SNAPSHOT)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_APP_MEMORY_SIZE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::IS_RAM_CONSTRAINED_DEVICE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_ABILITY_RUNNING_INFO)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_EXTENSION_RUNNING_INFO)); +} + +void EmplaceCodeMap3() +{ + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_PROCESS_RUNNING_INFO)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CLEAR_UP_APPLICATION_DATA)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_ABILITY_FOR_OPTIONS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::BLOCK_AMS_SERVICE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::BLOCK_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::BLOCK_APP_SERVICE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_CALL_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::RELEASE_CALL_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CONNECT_ABILITY_WITH_TYPE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_UI_EXTENSION_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CALL_REQUEST_DONE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_ABILITY_AS_CALLER_BY_TOKEN)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_ABILITY_AS_CALLER_FOR_OPTIONS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MINIMIZE_UI_EXTENSION_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::TERMINATE_UI_EXTENSION_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CONNECT_UI_EXTENSION_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_UI_ABILITY_BY_SCB)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MINIMIZE_UI_ABILITY_BY_SCB)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CLOSE_UI_ABILITY_BY_SCB)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REQUEST_DIALOG_SERVICE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_SPECIFIED_ABILITY_BY_SCB)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SET_SESSIONMANAGERSERVICE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_SESSIONMANAGERSERVICE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_CONTINUATION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::NOTIFY_CONTINUATION_RESULT)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::NOTIFY_COMPLETE_CONTINUATION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CONTINUE_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CONTINUE_MISSION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SEND_RESULT_TO_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REGISTER_REMOTE_ON_LISTENER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REGISTER_REMOTE_OFF_LISTENER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::CONTINUE_MISSION_OF_BUNDLENAME)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REGISTER_REMOTE_MISSION_LISTENER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::UNREGISTER_REMOTE_MISSION_LISTENER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_SYNC_MISSIONS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::STOP_SYNC_MISSIONS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REGISTER_SNAPSHOT_HANDLER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_MISSION_SNAPSHOT_INFO)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::UPDATE_MISSION_SNAPSHOT)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MOVE_MISSIONS_TO_FOREGROUND)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::MOVE_MISSIONS_TO_BACKGROUND)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::UPDATE_MISSION_SNAPSHOT_FROM_WMS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::START_USER_TEST)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::FINISH_USER_TEST)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::DELEGATOR_DO_ABILITY_FOREGROUND)); +} + +void EmplaceCodeMap4() +{ + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::DELEGATOR_DO_ABILITY_BACKGROUND)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_TOP_ABILITY_TOKEN)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::DUMP_STATE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::DUMPSYS_STATE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::FORCE_TIMEOUT)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REGISTER_WMS_HANDLER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::COMPLETEFIRSTFRAMEDRAWING)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::REGISTER_CONNECTION_OBSERVER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::UNREGISTER_CONNECTION_OBSERVER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_DLP_CONNECTION_INFOS)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_TOP_ABILITY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::FREE_INSTALL_ABILITY_FROM_REMOTE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::ADD_FREE_INSTALL_OBSERVER)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::ABILITY_RECOVERY)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::ABILITY_RECOVERY_ENABLE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::QUERY_MISSION_VAILD)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::VERIFY_PERMISSION)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::ACQUIRE_SHARE_DATA)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::SHARE_DATA_DONE)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::GET_ABILITY_TOKEN)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::FORCE_EXIT_APP)); + codeMap_.emplace(codeMap_.size(), static_cast(IAbilityManager::RECORD_APP_EXIT_REASON)); +} + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { - uint32_t code = GetU32Data(data) % (IAbilityManager::GET_ABILITY_TOKEN + IAbilityManager::SET_ROOT_SCENE_SESSION); - if (code >IAbilityManager::GET_ABILITY_TOKEN) { - code = IAbilityManager::GET_ABILITY_TOKEN; - } else if (code > IAbilityManager::SHARE_DATA_DONE && code != IAbilityManager::GET_ABILITY_TOKEN) { - code = IAbilityManager::ACQUIRE_SHARE_DATA + - (code % (IAbilityManager::SHARE_DATA_DONE - IAbilityManager::ACQUIRE_SHARE_DATA + 1)); - } else if (code > IAbilityManager::VERIFY_PERMISSION) { - code = IAbilityManager::GET_TOP_ABILITY + - (code % (IAbilityManager::VERIFY_PERMISSION - IAbilityManager::GET_TOP_ABILITY + 1)); - } else if (code > IAbilityManager::GET_DLP_CONNECTION_INFOS) { - code = IAbilityManager::REGISTER_WMS_HANDLER + - (code % (IAbilityManager::GET_DLP_CONNECTION_INFOS - IAbilityManager::REGISTER_WMS_HANDLER + 1)); - } else if (code > IAbilityManager::FORCE_TIMEOUT) { - code = IAbilityManager::DUMP_STATE + - (code % (IAbilityManager::FORCE_TIMEOUT - IAbilityManager::DUMP_STATE + 1)); - } else if (code > IAbilityManager::GET_TOP_ABILITY_TOKEN) { - code = IAbilityManager::START_ABILITY + - (code % (IAbilityManager::GET_TOP_ABILITY_TOKEN - IAbilityManager::START_ABILITY + 1)); - } else if (code > IAbilityManager::SET_ROOT_SCENE_SESSION) { - code = IAbilityManager::TERMINATE_ABILITY + - (code % (IAbilityManager::SET_ROOT_SCENE_SESSION - IAbilityManager::TERMINATE_ABILITY + 1)); + if (codeMap_.size() == 0) { + EmplaceCodeMap1(); + EmplaceCodeMap2(); + EmplaceCodeMap3(); + EmplaceCodeMap4(); } + uint32_t code = GetU32Data(data) % codeMap_.size(); + code = codeMap_[code]; MessageParcel parcel; parcel.WriteInterfaceToken(ABILITYMGR_INTERFACE_TOKEN); From 68877f587acfacc539dad9a2b0cb74e432b5a130 Mon Sep 17 00:00:00 2001 From: yuwenze Date: Thu, 29 Jun 2023 13:16:44 +0000 Subject: [PATCH 47/52] reconstructing upms Signed-off-by: yuwenze Change-Id: I4a4de8084f0ad0bda182dc74c41bf827044f3941 --- .../include/uri_permission_manager_client.h | 2 +- .../uri_permission_manager_interface.h | 2 +- .../include/uri_permission_manager_proxy.h | 2 +- .../src/uri_permission_manager_client.cpp | 4 +- .../src/uri_permission_manager_proxy.cpp | 6 +- .../src/uri_permission_manager_stub.cpp | 3 +- services/abilitymgr/src/ability_record.cpp | 2 +- .../include/uri_bundle_event_callback.h | 8 +- .../uri_permission_manager_stub_impl.h | 47 ++- .../src/uri_bundle_event_callback.cpp | 17 +- .../src/uri_permission_manager_service.cpp | 18 +- .../src/uri_permission_manager_stub_impl.cpp | 290 ++++++++---------- .../uripermissionmanager_fuzzer.cpp | 2 +- .../uri_permission_impl_test/BUILD.gn | 5 - .../include/mock_system_ability_manager.h | 9 + .../include/storage_manager_service_mock.h | 2 + .../include/system_ability_manager_client.h | 21 ++ .../mock/src/mock_system_ability_manager.cpp | 30 -- .../mock/src/storage_manager_service_mock.cpp | 22 -- .../src/system_ability_manager_client.cpp | 43 --- .../uri_permission_impl_test.cpp | 58 ++-- test/unittest/uri_permission_test/BUILD.gn | 2 + .../uri_permission_test.cpp | 57 +--- 23 files changed, 240 insertions(+), 412 deletions(-) delete mode 100755 test/unittest/uri_permission_impl_test/mock/src/mock_system_ability_manager.cpp delete mode 100755 test/unittest/uri_permission_impl_test/mock/src/storage_manager_service_mock.cpp delete mode 100755 test/unittest/uri_permission_impl_test/mock/src/system_ability_manager_client.cpp diff --git a/interfaces/inner_api/uri_permission/include/uri_permission_manager_client.h b/interfaces/inner_api/uri_permission/include/uri_permission_manager_client.h index 31bebb1070..572856117f 100644 --- a/interfaces/inner_api/uri_permission/include/uri_permission_manager_client.h +++ b/interfaces/inner_api/uri_permission/include/uri_permission_manager_client.h @@ -38,7 +38,7 @@ public: * @param autoremove the uri is temperarily or not */ int GrantUriPermission(const Uri &uri, unsigned int flag, - const std::string targetBundleName, int autoremove); + const std::string targetBundleName, int autoremove, int32_t appIndex = 0); /** * @brief Clear user's uri authorization record with auto remove flag. diff --git a/interfaces/inner_api/uri_permission/include/uri_permission_manager_interface.h b/interfaces/inner_api/uri_permission/include/uri_permission_manager_interface.h index 732ccf4123..6d195493a1 100644 --- a/interfaces/inner_api/uri_permission/include/uri_permission_manager_interface.h +++ b/interfaces/inner_api/uri_permission/include/uri_permission_manager_interface.h @@ -36,7 +36,7 @@ public: * @return Returns true if the authorization is successful, otherwise returns false. */ virtual int GrantUriPermission(const Uri &uri, unsigned int flag, - const std::string targetBundleName, int autoremove) = 0; + const std::string targetBundleName, int autoremove, int32_t appIndex = 0) = 0; /** * @brief Clear user's uri authorization record with autoremove flag. diff --git a/interfaces/inner_api/uri_permission/include/uri_permission_manager_proxy.h b/interfaces/inner_api/uri_permission/include/uri_permission_manager_proxy.h index 98914541be..7a4764bbbf 100644 --- a/interfaces/inner_api/uri_permission/include/uri_permission_manager_proxy.h +++ b/interfaces/inner_api/uri_permission/include/uri_permission_manager_proxy.h @@ -27,7 +27,7 @@ public: virtual ~UriPermissionManagerProxy() = default; virtual int GrantUriPermission(const Uri &uri, unsigned int flag, - const std::string targetBundleName, int autoremove) override; + const std::string targetBundleName, int autoremove, int32_t appIndex = 0) override; virtual void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) override; virtual int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override; diff --git a/interfaces/inner_api/uri_permission/src/uri_permission_manager_client.cpp b/interfaces/inner_api/uri_permission/src/uri_permission_manager_client.cpp index 759c8dbfe7..e1a2d811d1 100644 --- a/interfaces/inner_api/uri_permission/src/uri_permission_manager_client.cpp +++ b/interfaces/inner_api/uri_permission/src/uri_permission_manager_client.cpp @@ -34,12 +34,12 @@ UriPermissionManagerClient& UriPermissionManagerClient::GetInstance() } int UriPermissionManagerClient::GrantUriPermission(const Uri &uri, unsigned int flag, - const std::string targetBundleName, int autoremove) + const std::string targetBundleName, int autoremove, int32_t appIndex) { HILOG_DEBUG("targetBundleName :%{public}s", targetBundleName.c_str()); auto uriPermMgr = ConnectUriPermService(); if (uriPermMgr) { - return uriPermMgr->GrantUriPermission(uri, flag, targetBundleName, autoremove); + return uriPermMgr->GrantUriPermission(uri, flag, targetBundleName, autoremove, appIndex); } return INNER_ERR; } diff --git a/interfaces/inner_api/uri_permission/src/uri_permission_manager_proxy.cpp b/interfaces/inner_api/uri_permission/src/uri_permission_manager_proxy.cpp index bb7be569fa..dc5ddcd89d 100644 --- a/interfaces/inner_api/uri_permission/src/uri_permission_manager_proxy.cpp +++ b/interfaces/inner_api/uri_permission/src/uri_permission_manager_proxy.cpp @@ -25,7 +25,7 @@ UriPermissionManagerProxy::UriPermissionManagerProxy(const sptr & : IRemoteProxy(impl) {} int UriPermissionManagerProxy::GrantUriPermission(const Uri &uri, unsigned int flag, - const std::string targetBundleName, int autoremove) + const std::string targetBundleName, int autoremove, int32_t appIndex) { HILOG_DEBUG("UriPermissionManagerProxy::GrantUriPermission is called."); MessageParcel data; @@ -49,6 +49,10 @@ int UriPermissionManagerProxy::GrantUriPermission(const Uri &uri, unsigned int f HILOG_ERROR("Write autoremove failed."); return INNER_ERR; } + if (!data.WriteInt32(appIndex)) { + HILOG_ERROR("Write appIndex failed."); + return INNER_ERR; + } MessageParcel reply; MessageOption option; int error = Remote()->SendRequest(UriPermMgrCmd::ON_GRANT_URI_PERMISSION, data, reply, option); diff --git a/interfaces/inner_api/uri_permission/src/uri_permission_manager_stub.cpp b/interfaces/inner_api/uri_permission/src/uri_permission_manager_stub.cpp index 5f2e6327f3..6ce2a16916 100644 --- a/interfaces/inner_api/uri_permission/src/uri_permission_manager_stub.cpp +++ b/interfaces/inner_api/uri_permission/src/uri_permission_manager_stub.cpp @@ -38,7 +38,8 @@ int UriPermissionManagerStub::OnRemoteRequest( auto flag = data.ReadInt32(); auto targetBundleName = data.ReadString(); auto autoremove = data.ReadInt32(); - int result = GrantUriPermission(*uri, flag, targetBundleName, autoremove); + auto appIndex = data.ReadInt32(); + int result = GrantUriPermission(*uri, flag, targetBundleName, autoremove, appIndex); reply.WriteInt32(result); break; } diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 0b19b6a268..7b940559e4 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -2479,7 +2479,7 @@ void AbilityRecord::GrantUriPermission(Want &want, int32_t userId, std::string t int autoremove = 1; auto ret = IN_PROCESS_CALL( AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermission(uri, want.GetFlags(), - targetBundleName, autoremove)); + targetBundleName, autoremove, appIndex_)); if (ret == 0) { isGrantedUriPermission_ = true; } diff --git a/services/uripermmgr/include/uri_bundle_event_callback.h b/services/uripermmgr/include/uri_bundle_event_callback.h index 90debb9bda..4c0f8b5568 100644 --- a/services/uripermmgr/include/uri_bundle_event_callback.h +++ b/services/uripermmgr/include/uri_bundle_event_callback.h @@ -18,11 +18,12 @@ #include "bundle_event_callback_host.h" #include "common_event_support.h" -#include "hilog_wrapper.h" #include "uri_permission_manager_stub_impl.h" namespace OHOS { namespace AAFwk { +class UriPermissionManagerStubImpl; + /** * @brief This class is a callback class that will be registered to BundleManager. * This class will be called by BundleManager when install, uninstall, updates of haps happens, @@ -30,9 +31,8 @@ namespace AAFwk { */ class UriBundleEventCallback : public AppExecFwk::BundleEventCallbackHost { public: - UriBundleEventCallback() = default; - explicit UriBundleEventCallback(sptr impl); - ~UriBundleEventCallback() = default; + UriBundleEventCallback(sptr impl) : upms_(impl) {} + virtual ~UriBundleEventCallback() = default; /** * @brief The main callback function that will be called by BundleManager * when install, uninstall, updates of haps happens to notify UriPermissionManger. diff --git a/services/uripermmgr/include/uri_permission_manager_stub_impl.h b/services/uripermmgr/include/uri_permission_manager_stub_impl.h index 25f369594f..d8c5cc2d5c 100644 --- a/services/uripermmgr/include/uri_permission_manager_stub_impl.h +++ b/services/uripermmgr/include/uri_permission_manager_stub_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -21,19 +21,21 @@ #include "app_mgr_interface.h" #include "bundlemgr/bundle_mgr_interface.h" -#include "storage_manager_proxy.h" #include "istorage_manager.h" #include "uri.h" +#include "uri_bundle_event_callback.h" #include "uri_permission_manager_stub.h" -namespace OHOS { -namespace AAFwk { +namespace OHOS::AAFwk { +namespace { using ClearProxyCallback = std::function&)>; +using TokenId = Security::AccessToken::AccessTokenID; +} struct GrantInfo { unsigned int flag; - const unsigned int fromTokenId; - const unsigned int targetTokenId; + const uint32_t fromTokenId; + const uint32_t targetTokenId; int autoremove; }; class UriPermissionManagerStubImpl : public UriPermissionManagerStub, @@ -41,30 +43,27 @@ class UriPermissionManagerStubImpl : public UriPermissionManagerStub, public: UriPermissionManagerStubImpl() = default; virtual ~UriPermissionManagerStubImpl() = default; + void Init(); + void Stop() const; int GrantUriPermission(const Uri &uri, unsigned int flag, - const std::string targetBundleName, int autoremove) override; + const std::string targetBundleName, int autoremove, int32_t appIndex = 0) override; - void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) override; - void RevokeAllUriPermissions(int tokenId); + void RevokeUriPermission(const TokenId tokenId) override; + void RevokeAllUriPermissions(uint32_t tokenId); int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override; - sptr ConnectBundleManager(); private: - sptr ConnectAppMgr(); - sptr ConnectStorageManager(); - int GetCurrentAccountId(); - void ClearAppMgrProxy(); - void ClearBMSProxy(); - void ClearSMProxy(); + template + void ConnectManager(sptr &mgr, int32_t serviceId); + int32_t GetCurrentAccountId() const; int GrantUriPermissionImpl(const Uri &uri, unsigned int flag, - Security::AccessToken::AccessTokenID fromTokenId, - Security::AccessToken::AccessTokenID targetTokenId, int autoremove); - Security::AccessToken::AccessTokenID GetTokenIdByBundleName(const std::string bundleName); + TokenId fromTokenId, TokenId targetTokenId, int autoremove); + uint32_t GetTokenIdByBundleName(const std::string bundleName, int32_t appIndex); class ProxyDeathRecipient : public IRemoteObject::DeathRecipient { public: - explicit ProxyDeathRecipient(const ClearProxyCallback &proxy) : proxy_(proxy) {} + explicit ProxyDeathRecipient(ClearProxyCallback&& proxy) : proxy_(proxy) {} ~ProxyDeathRecipient() = default; virtual void OnRemoteDied([[maybe_unused]] const wptr& remote) override; @@ -75,13 +74,11 @@ private: private: std::map> uriMap_; std::mutex mutex_; - std::mutex appMgrMutex_; - std::mutex bmsMutex_; - std::mutex storageMutex_; + std::mutex mgrMutex_; sptr appMgr_ = nullptr; sptr bundleManager_ = nullptr; sptr storageManager_ = nullptr; + sptr uriBundleEventCallback_ = nullptr; }; -} // namespace AAFwk -} // namespace OHOS +} // namespace OHOS::AAFwk #endif // OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_STUB_IMPL_H diff --git a/services/uripermmgr/src/uri_bundle_event_callback.cpp b/services/uripermmgr/src/uri_bundle_event_callback.cpp index a47abf5cb9..65865c2bc8 100644 --- a/services/uripermmgr/src/uri_bundle_event_callback.cpp +++ b/services/uripermmgr/src/uri_bundle_event_callback.cpp @@ -12,21 +12,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "uri_bundle_event_callback.h" -namespace OHOS { -namespace AAFwk { + +#include "hilog_wrapper.h" + +namespace OHOS::AAFwk { +namespace { const std::string KEY_TOKEN = "accessTokenId"; -UriBundleEventCallback::UriBundleEventCallback(sptr impl) -{ - upms_ = impl; } + void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData eventData) { const Want& want = eventData.GetWant(); // action contains the change type of haps. std::string action = want.GetAction(); std::string bundleName = want.GetElement().GetBundleName(); - int token = want.GetIntParam(KEY_TOKEN, 0); + auto token = static_cast(want.GetIntParam(KEY_TOKEN, 0)); // verify data if (action.empty() || bundleName.empty()) { HILOG_ERROR("OnReceiveEvent failed, empty action/bundleName"); @@ -42,5 +44,4 @@ void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData even upms_->RevokeAllUriPermissions(token); } } -} // namespace AAFwk -} // namespace OHOS +} // namespace OHOS::AAFwk diff --git a/services/uripermmgr/src/uri_permission_manager_service.cpp b/services/uripermmgr/src/uri_permission_manager_service.cpp index 18242e1298..adc9084f33 100644 --- a/services/uripermmgr/src/uri_permission_manager_service.cpp +++ b/services/uripermmgr/src/uri_permission_manager_service.cpp @@ -20,7 +20,6 @@ #include "ipc_skeleton.h" #include "iservice_registry.h" #include "system_ability_definition.h" -#include "uri_bundle_event_callback.h" namespace OHOS { namespace AAFwk { @@ -75,19 +74,7 @@ bool UriPermissionManagerService::Init() if (impl_ == nullptr) { impl_ = new UriPermissionManagerStubImpl(); - } - // Register UriBundleEventCallback to receive hap updates - HILOG_INFO("Register UriBundleEventCallback to receive hap updates."); - auto bms = impl_->ConnectBundleManager(); - sptr uriBundleEventCallback = - new (std::nothrow) UriBundleEventCallback(impl_); - if (bms && uriBundleEventCallback) { - bool re = bms->RegisterBundleEventCallback(uriBundleEventCallback); - if (!re) { - HILOG_ERROR("RegisterBundleEventCallback failed!"); - } - } else { - HILOG_ERROR("Get BundleManager or uriBundleEventCallback failed!"); + impl_->Init(); } ready_ = true; return true; @@ -101,6 +88,9 @@ void UriPermissionManagerService::SelfClean() registerToService_ = false; } } + if (impl_ != nullptr) { + impl_->Stop(); + } } } // namespace AAFwk } // namespace OHOS diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index 8c5c229081..5b08307e01 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -25,29 +25,55 @@ #include "os_account_manager_wrapper.h" #include "permission_constants.h" #include "permission_verification.h" -#include "singleton.h" #include "system_ability_definition.h" #include "want.h" namespace OHOS { namespace AAFwk { -const int32_t DEFAULT_USER_ID = 0; -const int32_t ERR_OK = 0; -using TokenId = Security::AccessToken::AccessTokenID; +namespace { +constexpr int32_t DEFAULT_USER_ID = 0; +constexpr int32_t ERR_OK = 0; +} + +void UriPermissionManagerStubImpl::Init() +{ + // Register UriBundleEventCallback to receive hap updates + HILOG_INFO("Register UriBundleEventCallback to receive hap updates."); + ConnectManager(bundleManager_, BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (bundleManager_ == nullptr) { + HILOG_ERROR("Get BundleManager failed!"); + return; + } + uriBundleEventCallback_ = new UriBundleEventCallback(this); + auto ret = bundleManager_->RegisterBundleEventCallback(uriBundleEventCallback_); + if (!ret) { + HILOG_ERROR("RegisterBundleEventCallback failed!"); + } +} + +void UriPermissionManagerStubImpl::Stop() const +{ + if (uriBundleEventCallback_ != nullptr) { + auto ret = bundleManager_->UnregisterBundleEventCallback(uriBundleEventCallback_); + if (!ret) { + HILOG_ERROR("UnregisterBundleEventCallback failed!"); + } + } +} int UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned int flag, - const std::string targetBundleName, int autoremove) + const std::string targetBundleName, int autoremove, int32_t appIndex) { - HILOG_DEBUG("UriPermissionManagerStubImpl::GrantUriPermission is called."); + HILOG_DEBUG("CALL: appIndex is %{public}d.", appIndex); // reject sandbox to grant uri permission - auto appMgrProxy = ConnectAppMgr(); - if (appMgrProxy == nullptr) { - HILOG_ERROR("ConnectAppMgr failed"); + ConnectManager(appMgr_, APP_MGR_SERVICE_ID); + if (appMgr_ == nullptr) { + HILOG_ERROR("Get BundleManager failed!"); return INNER_ERR; } auto callerPid = IPCSkeleton::GetCallingPid(); bool isSandbox = false; - auto ret = appMgrProxy->JudgeSandboxByPid(callerPid, isSandbox); + auto ret = appMgr_->JudgeSandboxByPid(callerPid, isSandbox); if (ret != ERR_OK) { HILOG_ERROR("JudgeSandboxByPid failed."); return INNER_ERR; @@ -63,8 +89,8 @@ int UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned in } Uri uri_inner = uri; auto&& authority = uri_inner.GetAuthority(); - Security::AccessToken::AccessTokenID fromTokenId = GetTokenIdByBundleName(authority); - Security::AccessToken::AccessTokenID targetTokenId = GetTokenIdByBundleName(targetBundleName); + auto fromTokenId = GetTokenIdByBundleName(authority, 0); + auto targetTokenId = GetTokenIdByBundleName(targetBundleName, appIndex); auto callerTokenId = IPCSkeleton::GetCallingTokenID(); auto permission = PermissionVerification::GetInstance()->VerifyCallingPermission( AAFwk::PermissionConstants::PERMISSION_PROXY_AUTHORIZATION_URI); @@ -94,18 +120,17 @@ int UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned in } int UriPermissionManagerStubImpl::GrantUriPermissionImpl(const Uri &uri, unsigned int flag, - Security::AccessToken::AccessTokenID fromTokenId, - Security::AccessToken::AccessTokenID targetTokenId, int autoremove) + TokenId fromTokenId, TokenId targetTokenId, int autoremove) { - auto storageMgrProxy = ConnectStorageManager(); - if (storageMgrProxy == nullptr) { - HILOG_ERROR("ConnectStorageManager failed"); + ConnectManager(storageManager_, STORAGE_MANAGER_MANAGER_ID); + if (storageManager_ == nullptr) { + HILOG_ERROR("ConnectManager failed"); return INNER_ERR; } auto uriStr = uri.ToString(); - auto ret = storageMgrProxy->CreateShareFile(uriStr, targetTokenId, flag); + auto ret = storageManager_->CreateShareFile(uriStr, targetTokenId, flag); if (ret != 0 && ret != -EEXIST) { - HILOG_ERROR("storageMgrProxy failed to CreateShareFile."); + HILOG_ERROR("failed to CreateShareFile."); return INNER_ERR; } std::lock_guard guard(mutex_); @@ -163,18 +188,18 @@ void UriPermissionManagerStubImpl::RevokeUriPermission(const TokenId tokenId) } } - auto storageMgrProxy = ConnectStorageManager(); - if (storageMgrProxy == nullptr) { - HILOG_ERROR("ConnectStorageManager failed"); + ConnectManager(storageManager_, STORAGE_MANAGER_MANAGER_ID); + if (storageManager_ == nullptr) { + HILOG_ERROR("ConnectManager failed"); return; } if (!uriList.empty()) { - storageMgrProxy->DeleteShareFile(tokenId, uriList); + storageManager_->DeleteShareFile(tokenId, uriList); } } -void UriPermissionManagerStubImpl::RevokeAllUriPermissions(int tokenId) +void UriPermissionManagerStubImpl::RevokeAllUriPermissions(uint32_t tokenId) { HILOG_DEBUG("Start to remove all uri permission for uninstalled app."); std::map> uriLists; @@ -200,15 +225,15 @@ void UriPermissionManagerStubImpl::RevokeAllUriPermissions(int tokenId) } } - auto storageMgrProxy = ConnectStorageManager(); - if (storageMgrProxy == nullptr) { + ConnectManager(storageManager_, STORAGE_MANAGER_MANAGER_ID); + if (storageManager_ == nullptr) { HILOG_ERROR("ConnectStorageManager failed"); return; } if (!uriLists.empty()) { for (auto iter = uriLists.begin(); iter != uriLists.end(); iter++) { - storageMgrProxy->DeleteShareFile(iter->first, iter->second); + storageManager_->DeleteShareFile(iter->first, iter->second); } } } @@ -223,8 +248,8 @@ int UriPermissionManagerStubImpl::RevokeUriPermissionManually(const Uri &uri, co HILOG_WARN("only support file uri."); return ERR_CODE_INVALID_URI_TYPE; } - Security::AccessToken::AccessTokenID uriTokenId = GetTokenIdByBundleName(authority); - Security::AccessToken::AccessTokenID tokenId = GetTokenIdByBundleName(bundleName); + auto uriTokenId = GetTokenIdByBundleName(authority, 0); + auto tokenId = GetTokenIdByBundleName(bundleName, 0); auto callerTokenId = IPCSkeleton::GetCallingTokenID(); auto permission = PermissionVerification::GetInstance()->VerifyCallingPermission( AAFwk::PermissionConstants::PERMISSION_PROXY_AUTHORIZATION_URI); @@ -234,186 +259,117 @@ int UriPermissionManagerStubImpl::RevokeUriPermissionManually(const Uri &uri, co } std::vector uriList; - { - std::lock_guard guard(mutex_); + auto uriStr = uri.ToString(); + std::lock_guard guard(mutex_); - auto uriStr = uri.ToString(); - auto search = uriMap_.find(uriStr); - if (search == uriMap_.end()) { - HILOG_INFO("URI does not exist on uri map."); - return ERR_OK; - } - auto& list = search->second; - for (auto it = list.begin(); it != list.end(); it++) { - if (it->targetTokenId == tokenId) { - HILOG_INFO("Erase an info form list."); - auto storageMgrProxy = ConnectStorageManager(); - if (storageMgrProxy == nullptr) { - HILOG_ERROR("ConnectStorageManager failed"); - return INNER_ERR; - } - uriList.emplace_back(search->first); - if (storageMgrProxy->DeleteShareFile(tokenId, uriList) == ERR_OK) { - list.erase(it); - break; - } else { - HILOG_ERROR("DeleteShareFile failed"); - return INNER_ERR; - } + auto search = uriMap_.find(uriStr); + if (search == uriMap_.end()) { + HILOG_INFO("URI does not exist on uri map."); + return ERR_OK; + } + auto& list = search->second; + for (auto it = list.begin(); it != list.end(); it++) { + if (it->targetTokenId == tokenId) { + HILOG_INFO("Erase an info form list."); + ConnectManager(storageManager_, STORAGE_MANAGER_MANAGER_ID); + if (storageManager_ == nullptr) { + HILOG_ERROR("ConnectStorageManager failed"); + return INNER_ERR; + } + uriList.emplace_back(search->first); + if (storageManager_->DeleteShareFile(tokenId, uriList) == ERR_OK) { + list.erase(it); + break; + } else { + HILOG_ERROR("DeleteShareFile failed"); + return INNER_ERR; } } - if (list.size() == 0) { - uriMap_.erase(search); - } + } + if (list.size() == 0) { + uriMap_.erase(search); } return ERR_OK; } -sptr UriPermissionManagerStubImpl::ConnectAppMgr() +template +void UriPermissionManagerStubImpl::ConnectManager(sptr &mgr, int32_t serviceId) { - HILOG_DEBUG("%{public}s is called.", __func__); - std::lock_guard lock(appMgrMutex_); - if (appMgr_ == nullptr) { + HILOG_DEBUG("Call."); + std::lock_guard lock(mgrMutex_); + if (mgr == nullptr) { + HILOG_ERROR("mgr is nullptr."); auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!systemAbilityMgr) { + if (systemAbilityMgr == nullptr) { HILOG_ERROR("Failed to get SystemAbilityManager."); - return nullptr; + return; } - auto remoteObj = systemAbilityMgr->GetSystemAbility(APP_MGR_SERVICE_ID); - if (!remoteObj || (appMgr_ = iface_cast(remoteObj)) == nullptr) { - HILOG_ERROR("Failed to get AppMgrService."); - return nullptr; + auto remoteObj = systemAbilityMgr->GetSystemAbility(serviceId); + if (remoteObj == nullptr) { + HILOG_ERROR("Failed to get mgr."); + return; } + HILOG_ERROR("to cast."); + mgr = iface_cast(remoteObj); + if (mgr == nullptr) { + HILOG_ERROR("Failed to cast."); + return; + } + wptr manager = mgr; auto self = weak_from_this(); - const auto& onClearProxyCallback = [self](const wptr& remote) { + auto onClearProxyCallback = [manager, self](const auto& remote) { + auto mgrSptr = manager.promote(); auto impl = self.lock(); - if (impl && impl->appMgr_ == remote) { - impl->ClearAppMgrProxy(); + if (impl && mgrSptr && mgrSptr->AsObject() == remote.promote()) { + std::lock_guard lock(impl->mgrMutex_); + mgrSptr.clear(); } }; - sptr recipient(new ProxyDeathRecipient(onClearProxyCallback)); - if (!appMgr_->AsObject()->AddDeathRecipient(recipient)) { + sptr recipient(new ProxyDeathRecipient(std::move(onClearProxyCallback))); + if (!mgr->AsObject()->AddDeathRecipient(recipient)) { HILOG_ERROR("AddDeathRecipient failed."); } } - HILOG_DEBUG("%{public}s end.", __func__); - return appMgr_; } -sptr UriPermissionManagerStubImpl::ConnectBundleManager() +uint32_t UriPermissionManagerStubImpl::GetTokenIdByBundleName(const std::string bundleName, int32_t appIndex) { - HILOG_DEBUG("%{public}s is called.", __func__); - std::lock_guard lock(bmsMutex_); + ConnectManager(bundleManager_, BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); if (bundleManager_ == nullptr) { - auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!systemAbilityMgr) { - HILOG_ERROR("Failed to get SystemAbilityManager."); - return nullptr; - } - - auto remoteObj = systemAbilityMgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - if (!remoteObj || (bundleManager_ = iface_cast(remoteObj)) == nullptr) { - HILOG_ERROR("Failed to get bms."); - return nullptr; - } - auto self = weak_from_this(); - const auto& onClearProxyCallback = [self](const wptr& remote) { - auto impl = self.lock(); - if (impl && impl->bundleManager_ == remote) { - impl->ClearBMSProxy(); - } - }; - sptr recipient(new ProxyDeathRecipient(onClearProxyCallback)); - if (!bundleManager_->AsObject()->AddDeathRecipient(recipient)) { - HILOG_ERROR("AddDeathRecipient failed."); - } - } - HILOG_DEBUG("%{public}s end.", __func__); - return bundleManager_; -} - -Security::AccessToken::AccessTokenID UriPermissionManagerStubImpl::GetTokenIdByBundleName(const std::string bundleName) -{ - auto bms = ConnectBundleManager(); - if (bms == nullptr) { HILOG_WARN("Failed to get bms."); return GET_BUNDLE_MANAGER_SERVICE_FAILED; } auto bundleFlag = AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO; AppExecFwk::BundleInfo bundleInfo; - if (!IN_PROCESS_CALL(bms->GetBundleInfo(bundleName, bundleFlag, bundleInfo, GetCurrentAccountId()))) { - HILOG_WARN("To fail to get bundle info according to uri."); - return GET_BUNDLE_INFO_FAILED; + auto userId = GetCurrentAccountId(); + if (appIndex == 0) { + if (!IN_PROCESS_CALL(bundleManager_->GetBundleInfo(bundleName, bundleFlag, bundleInfo, userId))) { + HILOG_WARN("Failed to get bundle info according to uri."); + return GET_BUNDLE_INFO_FAILED; + } + } else { + if (IN_PROCESS_CALL(bundleManager_->GetSandboxBundleInfo(bundleName, appIndex, userId, bundleInfo) != ERR_OK)) { + HILOG_WARN("Failed to get bundle info according to appIndex."); + return GET_BUNDLE_INFO_FAILED; + } } return bundleInfo.applicationInfo.accessTokenId; } -sptr UriPermissionManagerStubImpl::ConnectStorageManager() -{ - std::lock_guard lock(storageMutex_); - if (storageManager_ == nullptr) { - auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!systemAbilityMgr) { - HILOG_ERROR("Failed to get SystemAbilityManager."); - return nullptr; - } - - auto remoteObj = systemAbilityMgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID); - if (!remoteObj || (storageManager_ = iface_cast(remoteObj)) == nullptr) { - HILOG_ERROR("Failed to get storage manager."); - return nullptr; - } - auto self = weak_from_this(); - const auto& onClearProxyCallback = [self](const wptr& remote) { - auto impl = self.lock(); - if (impl && impl->storageManager_ == remote) { - impl->ClearSMProxy(); - } - }; - sptr recipient(new ProxyDeathRecipient(onClearProxyCallback)); - if (!storageManager_->AsObject()->AddDeathRecipient(recipient)) { - HILOG_ERROR("AddDeathRecipient failed."); - } - } - HILOG_DEBUG("%{public}s end.", __func__); - return storageManager_; -} - -void UriPermissionManagerStubImpl::ClearAppMgrProxy() -{ - HILOG_DEBUG("%{public}s is called.", __func__); - std::lock_guard lock(appMgrMutex_); - appMgr_ = nullptr; -} - -void UriPermissionManagerStubImpl::ClearBMSProxy() -{ - HILOG_DEBUG("%{public}s is called.", __func__); - std::lock_guard lock(bmsMutex_); - bundleManager_ = nullptr; -} - -void UriPermissionManagerStubImpl::ClearSMProxy() -{ - HILOG_DEBUG("%{public}s is called.", __func__); - std::lock_guard lock(bmsMutex_); - storageManager_ = nullptr; -} - void UriPermissionManagerStubImpl::ProxyDeathRecipient::OnRemoteDied( [[maybe_unused]] const wptr& remote) { if (proxy_) { - HILOG_DEBUG("%{public}s, bms stub died.", __func__); + HILOG_DEBUG("mgr stub died."); proxy_(remote); } } -int UriPermissionManagerStubImpl::GetCurrentAccountId() +int32_t UriPermissionManagerStubImpl::GetCurrentAccountId() const { std::vector osActiveAccountIds; - ErrCode ret = DelayedSingleton::GetInstance()-> + auto ret = DelayedSingleton::GetInstance()-> QueryActiveOsAccountIds(osActiveAccountIds); if (ret != ERR_OK) { HILOG_ERROR("QueryActiveOsAccountIds failed."); diff --git a/test/fuzztest/uripermissionmanager_fuzzer/uripermissionmanager_fuzzer.cpp b/test/fuzztest/uripermissionmanager_fuzzer/uripermissionmanager_fuzzer.cpp index e24324698e..ed5d58b48a 100644 --- a/test/fuzztest/uripermissionmanager_fuzzer/uripermissionmanager_fuzzer.cpp +++ b/test/fuzztest/uripermissionmanager_fuzzer/uripermissionmanager_fuzzer.cpp @@ -38,7 +38,7 @@ public: virtual ~UriPermissionManagerStubFuzzTest() {} int GrantUriPermission(const Uri &uri, unsigned int flag, const std::string targetBundleName, - int autoremove) override + int autoremove, int32_t appIndex = 0) override { return 0; } diff --git a/test/unittest/uri_permission_impl_test/BUILD.gn b/test/unittest/uri_permission_impl_test/BUILD.gn index c6bc0cec22..5a97c6078f 100755 --- a/test/unittest/uri_permission_impl_test/BUILD.gn +++ b/test/unittest/uri_permission_impl_test/BUILD.gn @@ -26,9 +26,6 @@ ohos_unittest("uri_permission_impl_test") { sources = [ "${ability_runtime_test_path}/mock/common/src/mock_native_token.cpp", - "mock/src/mock_system_ability_manager.cpp", - "mock/src/storage_manager_service_mock.cpp", - "mock/src/system_ability_manager_client.cpp", "uri_permission_impl_test.cpp", ] @@ -52,8 +49,6 @@ ohos_unittest("uri_permission_impl_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - - # "hilog:libhilog", "storage_service:storage_manager_sa_proxy", ] } diff --git a/test/unittest/uri_permission_impl_test/mock/include/mock_system_ability_manager.h b/test/unittest/uri_permission_impl_test/mock/include/mock_system_ability_manager.h index 58f3a0570d..95edb31f38 100755 --- a/test/unittest/uri_permission_impl_test/mock/include/mock_system_ability_manager.h +++ b/test/unittest/uri_permission_impl_test/mock/include/mock_system_ability_manager.h @@ -30,6 +30,15 @@ public: sptr GetSystemAbility(int serviceId); }; + +bool MockSystemAbilityManager::isNullptr = false; +sptr MockSystemAbilityManager::GetSystemAbility(int serviceId) +{ + if (isNullptr) { + return nullptr; + } + return new StorageManager::StorageManagerServiceMock(); +} } // namespace AAFwk } // namespace OHOS #endif // MOCK_SYSTEM_ABILITY_MANAGER_H \ No newline at end of file diff --git a/test/unittest/uri_permission_impl_test/mock/include/storage_manager_service_mock.h b/test/unittest/uri_permission_impl_test/mock/include/storage_manager_service_mock.h index dbb82a0246..2843f345de 100755 --- a/test/unittest/uri_permission_impl_test/mock/include/storage_manager_service_mock.h +++ b/test/unittest/uri_permission_impl_test/mock/include/storage_manager_service_mock.h @@ -225,6 +225,8 @@ public: return E_OK; } }; + +bool StorageManagerServiceMock::isZero = true; } // namespace StorageManager } // namespace OHOS #endif // MOCK_STORAGE_MANAGER_SERVICE_H \ No newline at end of file diff --git a/test/unittest/uri_permission_impl_test/mock/include/system_ability_manager_client.h b/test/unittest/uri_permission_impl_test/mock/include/system_ability_manager_client.h index 7194dd54dd..bbf3a35b97 100755 --- a/test/unittest/uri_permission_impl_test/mock/include/system_ability_manager_client.h +++ b/test/unittest/uri_permission_impl_test/mock/include/system_ability_manager_client.h @@ -39,6 +39,27 @@ private: sptr systemAbilityManager_; std::mutex systemAbilityManagerLock_; }; + +bool SystemAbilityManagerClient::nullptrFlag = false; + +SystemAbilityManagerClient& SystemAbilityManagerClient::GetInstance() +{ + static auto instance = new SystemAbilityManagerClient(); + return *instance; +} + +sptr SystemAbilityManagerClient::GetSystemAbilityManager() +{ + std::lock_guard lock(systemAbilityManagerLock_); + if (nullptrFlag) { + return nullptr; + } + if (systemAbilityManager_ != nullptr) { + return systemAbilityManager_; + } + systemAbilityManager_ = new MockSystemAbilityManager(); + return systemAbilityManager_; +} } // namespace AAFwk } // namespace OHOS #endif // SERVICE_REGISTRY_INCLUDE_H \ No newline at end of file diff --git a/test/unittest/uri_permission_impl_test/mock/src/mock_system_ability_manager.cpp b/test/unittest/uri_permission_impl_test/mock/src/mock_system_ability_manager.cpp deleted file mode 100755 index 9844408a20..0000000000 --- a/test/unittest/uri_permission_impl_test/mock/src/mock_system_ability_manager.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2023 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_system_ability_manager.h" - -namespace OHOS { -namespace AAFwk { -bool MockSystemAbilityManager::isNullptr = true; -sptr MockSystemAbilityManager::GetSystemAbility(int serviceId) -{ - if (isNullptr) { - return nullptr; - } - return new StorageManager::StorageManagerServiceMock(); -} - -} // namespace AAFwk -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/uri_permission_impl_test/mock/src/storage_manager_service_mock.cpp b/test/unittest/uri_permission_impl_test/mock/src/storage_manager_service_mock.cpp deleted file mode 100755 index fa83e7c010..0000000000 --- a/test/unittest/uri_permission_impl_test/mock/src/storage_manager_service_mock.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2023 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 "storage_manager_service_mock.h" - -namespace OHOS { -namespace StorageManager { -bool StorageManagerServiceMock::isZero = true; -} // namespace AAFwk -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/uri_permission_impl_test/mock/src/system_ability_manager_client.cpp b/test/unittest/uri_permission_impl_test/mock/src/system_ability_manager_client.cpp deleted file mode 100755 index 8c6f130450..0000000000 --- a/test/unittest/uri_permission_impl_test/mock/src/system_ability_manager_client.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023 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 "system_ability_manager_client.h" - -#include "mock_system_ability_manager.h" - -namespace OHOS { -namespace AAFwk { -bool SystemAbilityManagerClient::nullptrFlag = false; - -SystemAbilityManagerClient& SystemAbilityManagerClient::GetInstance() -{ - static auto instance = new SystemAbilityManagerClient(); - return *instance; -} - -sptr SystemAbilityManagerClient::GetSystemAbilityManager() -{ - std::lock_guard lock(systemAbilityManagerLock_); - if (nullptrFlag) { - return nullptr; - } - if (systemAbilityManager_ != nullptr) { - return systemAbilityManager_; - } - systemAbilityManager_ = new MockSystemAbilityManager(); - return systemAbilityManager_; -} -} // namespace AAFwk -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp b/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp index 1979fa1e96..31d68fbb23 100755 --- a/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp +++ b/test/unittest/uri_permission_impl_test/uri_permission_impl_test.cpp @@ -15,12 +15,12 @@ #include +#include "mock_native_token.h" +#include "system_ability_definition.h" #include "system_ability_manager_client.h" - #define private public #include "uri_permission_manager_stub_impl.h" #undef private -#include "mock_native_token.h" using namespace testing; using namespace testing::ext; @@ -244,58 +244,36 @@ HWTEST_F(UriPermissionImplTest, Upms_RevokeUriPermission_002, TestSize.Level1) /* * Feature: URIPermissionManagerService - * Function: ConnectBundleManager + * Function: ConnectManager * SubFunction: NA - * FunctionPoints: URIPermissionManagerService ConnectBundleManager + * FunctionPoints: URIPermissionManagerService ConnectManager */ -HWTEST_F(UriPermissionImplTest, Upms_ConnectBundleManager_001, TestSize.Level1) +HWTEST_F(UriPermissionImplTest, Upms_ConnectManager_001, TestSize.Level1) { - auto upms = std::make_shared(); + auto upms = std::make_unique(); ASSERT_NE(upms, nullptr); SystemAbilityManagerClient::nullptrFlag = true; - (void)upms->ConnectBundleManager(); + sptr storageManager = nullptr; + upms->ConnectManager(storageManager, STORAGE_MANAGER_MANAGER_ID); SystemAbilityManagerClient::nullptrFlag = false; + ASSERT_EQ(storageManager, nullptr); } /* * Feature: URIPermissionManagerService - * Function: ConnectBundleManager + * Function: ConnectManager * SubFunction: NA - * FunctionPoints: URIPermissionManagerService ConnectBundleManager + * FunctionPoints: URIPermissionManagerService ConnectManager */ -HWTEST_F(UriPermissionImplTest, Upms_ConnectBundleManager_002, TestSize.Level1) +HWTEST_F(UriPermissionImplTest, Upms_ConnectManager_002, TestSize.Level1) { - auto upms = std::make_shared(); + auto upms = std::make_unique(); ASSERT_NE(upms, nullptr); - (void)upms->ConnectBundleManager(); -} - -/* - * Feature: URIPermissionManagerService - * Function: ConnectStorageManager - * SubFunction: NA - * FunctionPoints: URIPermissionManagerService ConnectStorageManager - */ -HWTEST_F(UriPermissionImplTest, Upms_ConnectStorageManager_001, TestSize.Level1) -{ - auto upms = std::make_shared(); - ASSERT_NE(upms, nullptr); - SystemAbilityManagerClient::nullptrFlag = true; - (void)upms->ConnectStorageManager(); - SystemAbilityManagerClient::nullptrFlag = false; -} - -/* - * Feature: URIPermissionManagerService - * Function: ConnectStorageManager - * SubFunction: NA - * FunctionPoints: URIPermissionManagerService ConnectStorageManager - */ -HWTEST_F(UriPermissionImplTest, Upms_ConnectStorageManager_002, TestSize.Level1) -{ - auto upms = std::make_shared(); - ASSERT_NE(upms, nullptr); - (void)upms->ConnectStorageManager(); + MockSystemAbilityManager::isNullptr = true; + sptr storageManager = nullptr; + upms->ConnectManager(storageManager, STORAGE_MANAGER_MANAGER_ID); + MockSystemAbilityManager::isNullptr = false; + ASSERT_EQ(storageManager, nullptr); } } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/uri_permission_test/BUILD.gn b/test/unittest/uri_permission_test/BUILD.gn index 6f38b598fc..37f4c4b8a3 100755 --- a/test/unittest/uri_permission_test/BUILD.gn +++ b/test/unittest/uri_permission_test/BUILD.gn @@ -36,6 +36,8 @@ ohos_unittest("uri_permission_test") { "ability_base:zuri", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", + + # "ipc:ipc_core", "storage_service:storage_manager_sa_proxy", ] } diff --git a/test/unittest/uri_permission_test/uri_permission_test.cpp b/test/unittest/uri_permission_test/uri_permission_test.cpp index bc5e8b4df8..62c0c6cb78 100755 --- a/test/unittest/uri_permission_test/uri_permission_test.cpp +++ b/test/unittest/uri_permission_test/uri_permission_test.cpp @@ -15,9 +15,13 @@ #include +#include "istorage_manager.h" +#include "storage_manager_proxy.h" +#include "system_ability_definition.h" #define private public #include "uri_permission_manager_stub_impl.h" #undef private + using namespace testing; using namespace testing::ext; @@ -59,28 +63,17 @@ HWTEST_F(UriPermissionTest, Upms_GrantUriPermission_001, TestSize.Level1) /* * Feature: URIPermissionManagerService - * Function: ConnectBundleManager + * Function: ConnectManager * SubFunction: NA - * FunctionPoints: URIPermissionManagerService ConnectBundleManager + * FunctionPoints: URIPermissionManagerService ConnectManager */ -HWTEST_F(UriPermissionTest, Upms_ConnectBundleManager_001, TestSize.Level1) +HWTEST_F(UriPermissionTest, Upms_ConnectManager_001, TestSize.Level1) { - auto upms = std::make_shared(); - EXPECT_NE(upms, nullptr); - (void)upms->ConnectBundleManager(); -} - -/* - * Feature: URIPermissionManagerService - * Function: ConnectStorageManager - * SubFunction: NA - * FunctionPoints: URIPermissionManagerService ConnectStorageManager - */ -HWTEST_F(UriPermissionTest, Upms_ConnectStorageManager_001, TestSize.Level1) -{ - auto upms = std::make_shared(); - EXPECT_NE(upms, nullptr); - (void)upms->ConnectStorageManager(); + auto upms = std::make_unique(); + ASSERT_NE(upms, nullptr); + sptr storageManager = nullptr; + upms->ConnectManager(storageManager, STORAGE_MANAGER_MANAGER_ID); + ASSERT_NE(storageManager, nullptr); } /* @@ -104,32 +97,6 @@ HWTEST_F(UriPermissionTest, Upms_RevokeUriPermission_001, TestSize.Level1) upms->RevokeUriPermission(targetTokenId); } -/* - * Feature: URIPermissionManagerService - * Function: ClearBMSProxy - * SubFunction: NA - * FunctionPoints: URIPermissionManagerService ClearBMSProxy - */ -HWTEST_F(UriPermissionTest, Upms_ClearBMSProxy_001, TestSize.Level1) -{ - auto upms = std::make_shared(); - EXPECT_NE(upms, nullptr); - upms->ClearBMSProxy(); -} - -/* - * Feature: URIPermissionManagerService - * Function: ClearSMProxy - * SubFunction: NA - * FunctionPoints: URIPermissionManagerService ClearSMProxy - */ -HWTEST_F(UriPermissionTest, Upms_ClearBMSProxy_002, TestSize.Level1) -{ - auto upms = std::make_shared(); - EXPECT_NE(upms, nullptr); - upms->ClearSMProxy(); -} - /* * Feature: URIPermissionManagerService * Function: OnRemoteDied From c7d01997afd5ad8d3a244c9d14b4e24c998618b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=87=AF?= Date: Thu, 29 Jun 2023 02:35:10 +0000 Subject: [PATCH 48/52] update services/appmgr/src/app_running_manager.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡凯 --- services/appmgr/include/app_running_record.h | 4 ++++ services/appmgr/src/app_mgr_service_inner.cpp | 4 ++-- services/appmgr/src/app_running_manager.cpp | 9 +++++---- services/appmgr/src/app_state_observer_manager.cpp | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 0f0d9c866f..2967d0b820 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -638,6 +638,10 @@ public: return extensionType_ == ExtensionAbilityType::UI; } + bool IsWindowExtension() const + { + return extensionType_ == ExtensionAbilityType::WINDOW; + } private: /** * SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilityStage data. diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index e94a7fc0cc..381396849a 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -503,8 +503,8 @@ void AppMgrServiceInner::ApplicationBackgrounded(const int32_t recordId) } if (appRecord->GetState() == ApplicationState::APP_STATE_FOREGROUND) { appRecord->SetState(ApplicationState::APP_STATE_BACKGROUND); - bool needNotifyApp = - !appRecord->IsUIExtension() && appRunningManager_->IsApplicationBackground(appRecord->GetBundleName()); + bool needNotifyApp = !appRecord->IsUIExtension() && !appRecord->IsWindowExtension() + && appRunningManager_->IsApplicationBackground(appRecord->GetBundleName()); OnAppStateChanged(appRecord, ApplicationState::APP_STATE_BACKGROUND, needNotifyApp); DelayedSingleton::GetInstance()->OnProcessStateChanged(appRecord); } else { diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 5b39214f24..84f18b2321 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -529,7 +529,8 @@ void AppRunningManager::GetForegroundApplications(std::vector &lis return; } auto state = appRecord->GetState(); - if (state == ApplicationState::APP_STATE_FOREGROUND && !appRecord->IsUIExtension()) { + if (state == ApplicationState::APP_STATE_FOREGROUND && !appRecord->IsUIExtension() + && !appRecord->IsWindowExtension()) { AppStateData appData; appData.bundleName = appRecord->GetBundleName(); appData.uid = appRecord->GetUid(); @@ -794,13 +795,13 @@ bool AppRunningManager::IsApplicationFirstForeground(const AppRunningRecord &for { HILOG_DEBUG("function called."); std::lock_guard guard(lock_); - if (foregroundingRecord.IsUIExtension()) { + if (foregroundingRecord.IsUIExtension() || foregroundingRecord.IsWindowExtension()) { return false; } for (const auto &item : appRunningRecordMap_) { const auto &appRecord = item.second; if (appRecord == nullptr || appRecord->GetBundleName() != foregroundingRecord.GetBundleName() - || appRecord->IsUIExtension()) { + || appRecord->IsUIExtension() || appRecord->IsWindowExtension()) { continue; } auto state = appRecord->GetState(); @@ -822,7 +823,7 @@ bool AppRunningManager::IsApplicationBackground(const std::string &bundleName) HILOG_ERROR("appRecord is nullptr"); return false; } - if (appRecord->IsUIExtension()) { + if (appRecord->IsUIExtension() || appRecord->IsWindowExtension()) { continue; } auto state = appRecord->GetState(); diff --git a/services/appmgr/src/app_state_observer_manager.cpp b/services/appmgr/src/app_state_observer_manager.cpp index 5b35b9474a..dc5a955918 100644 --- a/services/appmgr/src/app_state_observer_manager.cpp +++ b/services/appmgr/src/app_state_observer_manager.cpp @@ -332,7 +332,7 @@ void AppStateObserverManager::HandleAppStateChanged(const std::shared_ptrIsUIExtension()) { + && !appRecord->IsUIExtension() && !appRecord->IsWindowExtension()) { AppStateData data = WrapAppStateData(appRecord, state); HILOG_DEBUG("HandleAppStateChanged, name:%{public}s, uid:%{public}d, state:%{public}d, notify:%{public}d", data.bundleName.c_str(), data.uid, data.state, needNotifyApp); From 788d543544760b307b38f1fbfc464db6f2477636 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Thu, 29 Jun 2023 21:48:54 +0800 Subject: [PATCH 49/52] modify tdd test code Signed-off-by: xinking129 --- test/unittest/app_mgr_service_test/app_mgr_service_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index 45499769aa..9810772226 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -1217,7 +1217,8 @@ HWTEST_F(AppMgrServiceTest, NotifyAppFault_003, TestSize.Level1) { sptr appMgrService = new (std::nothrow) AppMgrService(); appMgrService->SetInnerService(std::make_shared()); - appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); AppFaultDataBySA faultData; int32_t res = appMgrService->NotifyAppFaultBySA(faultData); EXPECT_EQ(ERR_INVALID_VALUE, res); From 887e3c2f03522026313b60efcd287e6b535fd1c5 Mon Sep 17 00:00:00 2001 From: dy_study Date: Tue, 27 Jun 2023 09:44:54 +0000 Subject: [PATCH 50/52] Add UIExtension default background color. Signed-off-by: dy_study Change-Id: Ia5da0c01c058fe3ce7e19c1c54641643759ddd9c --- .../native/ui_extension_ability/js_ui_extension.cpp | 2 ++ services/abilitymgr/src/ability_manager_service.cpp | 8 -------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp index b9f0194a40..b017a62be7 100755 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp @@ -38,6 +38,7 @@ using namespace OHOS::AppExecFwk; namespace { constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; +constexpr static char DEFAULT_BACKGROUND_COLOR[] = "#40ffffff"; } NativeValue *AttachUIExtensionContext(NativeEngine *engine, void *value, void *) @@ -315,6 +316,7 @@ void JsUIExtension::ForegroundWindow(const AAFwk::Want &want, const sptrSetBackgroundColor(DEFAULT_BACKGROUND_COLOR); HandleScope handleScope(jsRuntime_); NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine(); napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast(nativeEngine), want); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 0d8d90b702..e52e87d3ef 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -1714,14 +1714,6 @@ int AbilityManagerService::StartUIExtensionAbility(const Want &want, const sptr< HILOG_DEBUG("userId is : %{public}d, singleton is : %{public}d", validUserId, static_cast(abilityInfo.applicationInfo.singleton)); - result = CheckOptExtensionAbility(want, abilityRequest, validUserId, extensionType); - if (result != ERR_OK) { - HILOG_ERROR("CheckOptExtensionAbility error."); - eventInfo.errCode = result; - EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); - return result; - } - result = JudgeAbilityVisibleControl(abilityInfo); if (result != ERR_OK) { HILOG_ERROR("JudgeAbilityVisibleControl error."); From c2003cc26afcff79e7cce85c99ef414220432d21 Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Thu, 29 Jun 2023 14:59:28 +0000 Subject: [PATCH 51/52] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!5?= =?UTF-8?q?653=20:=20=E4=BF=AE=E6=94=B9dnsproxyd=E6=9D=83=E9=99=90'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/appmgr/src/app_mgr_service_inner.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 73c3fbcf99..e94a7fc0cc 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -128,9 +128,7 @@ const std::string PROCESS_EXIT_EVENT_TASK = "Send Process Exit Event Task"; constexpr int32_t ROOT_UID = 0; constexpr int32_t FOUNDATION_UID = 5523; constexpr int32_t DEFAULT_USER_ID = 0; -#ifdef APP_MGR_SERVICE_APPMS -constexpr int32_t NETSYS_SOCKET_GROUPID = 1097; -#endif + int32_t GetUserIdByUid(int32_t uid) { return uid / BASE_USER_RANGE; @@ -1765,7 +1763,6 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str uint8_t setAllowInternet = 0; uint8_t allowInternet = 1; auto token = bundleInfo.applicationInfo.accessTokenId; - std::vector gids; { // Add TRACE HITRACE_METER_NAME(HITRACE_TAG_APP, "AccessTokenKit::VerifyAccessToken"); @@ -1779,7 +1776,6 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str } else { auto ret = SetInternetPermission(bundleInfo.uid, 1); HILOG_DEBUG("SetInternetPermission, ret = %{public}d", ret); - gids.push_back(NETSYS_SOCKET_GROUPID); #endif } @@ -1795,7 +1791,6 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str AppSpawnStartMsg startMsg; startMsg.uid = bundleInfo.uid; startMsg.gid = bundleInfo.gid; - startMsg.gids = gids; startMsg.accessTokenId = bundleInfo.applicationInfo.accessTokenId; startMsg.apl = bundleInfo.applicationInfo.appPrivilegeLevel; startMsg.bundleName = bundleName; From b5a3e06a7aebdef209b43d464719fcc4ffaca1b3 Mon Sep 17 00:00:00 2001 From: dy_study Date: Wed, 28 Jun 2023 09:54:58 +0000 Subject: [PATCH 52/52] Update StartUIExtension method. Signed-off-by: dy_study Change-Id: I660c462edd7869d4a35b8edd12b0f451823eb7da --- bundle.json | 9 ++++++++ frameworks/native/ability/native/BUILD.gn | 7 +++++- .../include/ability_manager_client.h | 8 ++----- .../include/ability_manager_interface.h | 8 ++----- .../include/service_router_mgr_interface.h | 8 +++---- .../include/service_router_mgr_proxy.h | 9 +++----- .../src/service_router_mgr_proxy.cpp | 11 +-------- .../srms/include/service_router_mgr_service.h | 9 +++----- .../srms/src/service_router_mgr_service.cpp | 6 ++--- .../srms/src/service_router_mgr_stub.cpp | 9 +------- .../include/ability_manager_proxy.h | 8 ++----- .../include/ability_manager_service.h | 8 ++----- .../abilitymgr/src/ability_manager_client.cpp | 8 +++---- .../abilitymgr/src/ability_manager_proxy.cpp | 11 +-------- .../src/ability_manager_service.cpp | 23 +++++++++++-------- .../abilitymgr/src/ability_manager_stub.cpp | 11 +-------- .../ability_manager_client_branch_test.cpp | 2 +- .../ability_manager_service_test.cpp | 5 ++-- 18 files changed, 58 insertions(+), 102 deletions(-) diff --git a/bundle.json b/bundle.json index e9fd9bd837..aa4cf2e9e0 100644 --- a/bundle.json +++ b/bundle.json @@ -329,6 +329,15 @@ ] }, "name": "//foundation/ability/ability_runtime/tools/aa:tools_aa_source_set" + }, + { + "header": { + "header_base": "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native/ui_extension_ability", + "header_files": [ + "ui_extension_context.h" + ] + }, + "name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:ui_extension" } ], "test": [ diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 456fdd3dbe..8783579d31 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -729,9 +729,12 @@ group("extension_module") { } } -ohos_shared_library("ui_extension") { +config("ui_extension_public_config") { + visibility = [ ":*" ] include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability" ] +} +ohos_shared_library("ui_extension") { sources = [ "${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension.cpp", "${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp", @@ -740,6 +743,8 @@ ohos_shared_library("ui_extension") { "${ability_runtime_native_path}/ability/native/ui_extension_ability/ui_extension_context.cpp", ] + public_configs = [ ":ui_extension_public_config" ] + deps = [ ":abilitykit_native", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", 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 f9faf8da5e..958a2d7bfe 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -198,19 +198,15 @@ public: AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED); /** - * Start ui extension ability with want, send want to ability manager service. + * Start ui extension ability with extension session info, send extension session info to ability manager service. * - * @param want, the want of the ability to start. * @param extensionSessionInfo the extension session info of the ability to start. * @param userId, Designation User ID. - * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. * @return Returns ERR_OK on success, others on failure. */ ErrCode StartUIExtensionAbility( - const Want &want, const sptr &extensionSessionInfo, - int32_t userId = DEFAULT_INVAL_VALUE, - AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED); + int32_t userId = DEFAULT_INVAL_VALUE); /** * Start ui ability with want, send want to ability manager service. 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 e0e8df58fb..3c5867d683 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -186,19 +186,15 @@ public: } /** - * Start ui extension ability with want, send want to ability manager service. + * Start ui extension ability with extension session info, send extension session info to ability manager service. * - * @param want, the want of the ability to start. * @param extensionSessionInfo the extension session info of the ability to start. * @param userId, Designation User ID. - * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. * @return Returns ERR_OK on success, others on failure. */ virtual int StartUIExtensionAbility( - const Want &want, const sptr &extensionSessionInfo, - int32_t userId = DEFAULT_INVAL_VALUE, - AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) + int32_t userId = DEFAULT_INVAL_VALUE) { return 0; } diff --git a/service_router_framework/interfaces/inner_api/include/service_router_mgr_interface.h b/service_router_framework/interfaces/inner_api/include/service_router_mgr_interface.h index 30e1bcf40b..81051f8dd3 100755 --- a/service_router_framework/interfaces/inner_api/include/service_router_mgr_interface.h +++ b/service_router_framework/interfaces/inner_api/include/service_router_mgr_interface.h @@ -61,16 +61,14 @@ public: std::vector &purposeInfos) = 0; /** - * Start ui extension ability with want, send want to ability manager service. + * Start ui extension ability with extension session info, send extension session info to ability manager service. * - * @param want, the want of the ability to start. * @param sessionInfo the extension session info of the ability to start. * @param userId, Designation User ID. - * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. * @return Returns ERR_OK on success, others on failure. */ - virtual int32_t StartUIExtensionAbility(const Want &want, const sptr &sessionInfo, - int32_t userId = DEFAULT_INVAL_VALUE, ExtensionAbilityType extensionType = ExtensionAbilityType::UNSPECIFIED) + virtual int32_t StartUIExtensionAbility(const sptr &sessionInfo, + int32_t userId = DEFAULT_INVAL_VALUE) { return 0; } diff --git a/service_router_framework/interfaces/inner_api/include/service_router_mgr_proxy.h b/service_router_framework/interfaces/inner_api/include/service_router_mgr_proxy.h index eb2d42218d..3c367e2072 100755 --- a/service_router_framework/interfaces/inner_api/include/service_router_mgr_proxy.h +++ b/service_router_framework/interfaces/inner_api/include/service_router_mgr_proxy.h @@ -51,17 +51,14 @@ public: std::vector &purposeInfos) override; /** - * Start ui extension ability with want, send want to ability manager service. + * Start ui extension ability with extension session info, send extension session info to ability manager service. * - * @param want, the want of the ability to start. * @param sessionInfo the extension session info of the ability to start. * @param userId, Designation User ID. - * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. * @return Returns ERR_OK on success, others on failure. */ - int32_t StartUIExtensionAbility(const Want &want, const sptr &sessionInfo, - int32_t userId = DEFAULT_INVAL_VALUE, - ExtensionAbilityType extensionType = ExtensionAbilityType::UNSPECIFIED) override; + int32_t StartUIExtensionAbility(const sptr &sessionInfo, + int32_t userId = DEFAULT_INVAL_VALUE) override; /** * Connect ui extension ability with want, connect session with service ability. diff --git a/service_router_framework/interfaces/inner_api/src/service_router_mgr_proxy.cpp b/service_router_framework/interfaces/inner_api/src/service_router_mgr_proxy.cpp index 4ff404c3af..2ec1aa11cf 100755 --- a/service_router_framework/interfaces/inner_api/src/service_router_mgr_proxy.cpp +++ b/service_router_framework/interfaces/inner_api/src/service_router_mgr_proxy.cpp @@ -79,8 +79,7 @@ int32_t ServiceRouterMgrProxy::QueryPurposeInfos(const Want &want, const std::st return res; } -int32_t ServiceRouterMgrProxy::StartUIExtensionAbility(const Want &want, const sptr &sessionInfo, - int32_t userId, ExtensionAbilityType extensionType) +int32_t ServiceRouterMgrProxy::StartUIExtensionAbility(const sptr &sessionInfo, int32_t userId) { MessageParcel data; MessageParcel reply; @@ -89,10 +88,6 @@ int32_t ServiceRouterMgrProxy::StartUIExtensionAbility(const Want &want, const s APP_LOGE("write interfaceToken failed"); return ERR_APPEXECFWK_PARCEL_ERROR; } - if (!data.WriteParcelable(&want)) { - APP_LOGE("want write failed."); - return ERR_APPEXECFWK_PARCEL_ERROR; - } if (sessionInfo) { if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) { @@ -110,10 +105,6 @@ int32_t ServiceRouterMgrProxy::StartUIExtensionAbility(const Want &want, const s APP_LOGE("StartExtensionAbility, userId write failed."); return ERR_APPEXECFWK_PARCEL_ERROR; } - if (!data.WriteInt32(static_cast(extensionType))) { - APP_LOGE("StartExtensionAbility, extensionType write failed."); - return ERR_APPEXECFWK_PARCEL_ERROR; - } if (!Remote()) { APP_LOGE("StartExtensionAbility, Remote error."); return ERR_APPEXECFWK_PARCEL_ERROR; diff --git a/service_router_framework/services/srms/include/service_router_mgr_service.h b/service_router_framework/services/srms/include/service_router_mgr_service.h index 640c419906..687c897d51 100755 --- a/service_router_framework/services/srms/include/service_router_mgr_service.h +++ b/service_router_framework/services/srms/include/service_router_mgr_service.h @@ -74,17 +74,14 @@ public: std::vector &purposeInfos) override; /** - * Start ui extension ability with want, send want to ability manager service. + * Start ui extension ability with extension session info, send extension session info to ability manager service. * - * @param want, the want of the ability to start. * @param sessionInfo the extension session info of the ability to start. * @param userId, Designation User ID. - * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. * @return Returns ERR_OK on success, others on failure. */ - virtual int32_t StartUIExtensionAbility(const Want &want, const sptr &sessionInfo, - int32_t userId = DEFAULT_INVAL_VALUE, - ExtensionAbilityType extensionType = ExtensionAbilityType::UNSPECIFIED) override; + virtual int32_t StartUIExtensionAbility(const sptr &sessionInfo, + int32_t userId = DEFAULT_INVAL_VALUE) override; /** * Connect ui extension ability with want, connect session with service ability. diff --git a/service_router_framework/services/srms/src/service_router_mgr_service.cpp b/service_router_framework/services/srms/src/service_router_mgr_service.cpp index 1b260f79cb..68baf9dca5 100755 --- a/service_router_framework/services/srms/src/service_router_mgr_service.cpp +++ b/service_router_framework/services/srms/src/service_router_mgr_service.cpp @@ -171,13 +171,11 @@ int32_t ServiceRouterMgrService::QueryPurposeInfos(const Want &want, const std:: return ServiceRouterDataMgr::GetInstance().QueryPurposeInfos(want, purposeName, purposeInfos); } -int32_t ServiceRouterMgrService::StartUIExtensionAbility(const Want &want, const sptr &sessionInfo, - int32_t userId, ExtensionAbilityType extensionType) +int32_t ServiceRouterMgrService::StartUIExtensionAbility(const sptr &sessionInfo, int32_t userId) { APP_LOGD("StartUIExtensionAbility start:"); DelayUnloadTask(); - return IN_PROCESS_CALL(AbilityManagerClient::GetInstance()-> - StartUIExtensionAbility(want, sessionInfo, userId, extensionType)); + return IN_PROCESS_CALL(AbilityManagerClient::GetInstance()->StartUIExtensionAbility(sessionInfo, userId)); } int32_t ServiceRouterMgrService::ConnectUIExtensionAbility(const Want &want, const sptr &connect, diff --git a/service_router_framework/services/srms/src/service_router_mgr_stub.cpp b/service_router_framework/services/srms/src/service_router_mgr_stub.cpp index 0e0da6ed4e..8bac2d3c92 100755 --- a/service_router_framework/services/srms/src/service_router_mgr_stub.cpp +++ b/service_router_framework/services/srms/src/service_router_mgr_stub.cpp @@ -126,23 +126,16 @@ int ServiceRouterMgrStub::HandleQueryPurposeInfos(MessageParcel &data, MessagePa int ServiceRouterMgrStub::HandleStartUIExtensionAbility(MessageParcel &data, MessageParcel &reply) { APP_LOGD("ServiceRouterMgrStub handle start ui extension ability"); - Want *want = data.ReadParcelable(); - if (want == nullptr) { - APP_LOGE("ReadParcelable failed"); - return ERR_APPEXECFWK_PARCEL_ERROR; - } sptr sessionInfo = nullptr; if (data.ReadBool()) { sessionInfo = data.ReadParcelable(); } int32_t userId = data.ReadInt32(); - ExtensionAbilityType type = static_cast(data.ReadInt32()); - int32_t result = StartUIExtensionAbility(*want, sessionInfo, userId, type); + int32_t result = StartUIExtensionAbility(sessionInfo, userId); if (!reply.WriteInt32(result)) { APP_LOGE("write result failed"); return ERR_APPEXECFWK_PARCEL_ERROR; } - delete want; return ERR_OK; } diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 66d4a31d2f..c63d259eba 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -143,19 +143,15 @@ public: AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override; /** - * Start ui extension ability with want, send want to ability manager service. + * Start ui extension ability with extension session info, send extension session info to ability manager service. * - * @param want, the want of the ability to start. * @param extensionSessionInfo the extension session info of the ability to start. * @param userId, Designation User ID. - * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. * @return Returns ERR_OK on success, others on failure. */ virtual int StartUIExtensionAbility( - const Want &want, const sptr &extensionSessionInfo, - int32_t userId = DEFAULT_INVAL_VALUE, - AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override; + int32_t userId = DEFAULT_INVAL_VALUE) override; /** * Start ui ability 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 bbc46c3682..f73d6feaf2 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -196,19 +196,15 @@ public: AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override; /** - * Start ui extension ability with want, send want to ability manager service. + * Start ui extension ability with extension session info, send extension session info to ability manager service. * - * @param want, the want of the ability to start. * @param extensionSessionInfo the extension session info of the ability to start. * @param userId, Designation User ID. - * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started. * @return Returns ERR_OK on success, others on failure. */ virtual int StartUIExtensionAbility( - const Want &want, const sptr &extensionSessionInfo, - int32_t userId = DEFAULT_INVAL_VALUE, - AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override; + int32_t userId = DEFAULT_INVAL_VALUE) override; /** * Start ui ability with want, send want to ability manager service. diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 8869dddcc2..b65bf912a2 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -197,14 +197,14 @@ ErrCode AbilityManagerClient::StartExtensionAbility(const Want &want, const sptr return abms->StartExtensionAbility(want, callerToken, userId, extensionType); } -ErrCode AbilityManagerClient::StartUIExtensionAbility(const Want &want, const sptr &extensionSessionInfo, - int32_t userId, AppExecFwk::ExtensionAbilityType extensionType) +ErrCode AbilityManagerClient::StartUIExtensionAbility(const sptr &extensionSessionInfo, int32_t userId) { auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); HILOG_INFO("name:%{public}s %{public}s, userId:%{public}d.", - want.GetElement().GetAbilityName().c_str(), want.GetElement().GetBundleName().c_str(), userId); - return abms->StartUIExtensionAbility(want, extensionSessionInfo, userId, extensionType); + extensionSessionInfo->want.GetElement().GetAbilityName().c_str(), + extensionSessionInfo->want.GetElement().GetBundleName().c_str(), userId); + return abms->StartUIExtensionAbility(extensionSessionInfo, userId); } ErrCode AbilityManagerClient::StartUIAbilityBySCB(sptr sessionInfo) diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index bd08239ac8..2cb5f6d197 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -395,8 +395,7 @@ int AbilityManagerProxy::StartExtensionAbility(const Want &want, const sptr &extensionSessionInfo, - int32_t userId, AppExecFwk::ExtensionAbilityType extensionType) +int AbilityManagerProxy::StartUIExtensionAbility(const sptr &extensionSessionInfo, int32_t userId) { int error; MessageParcel data; @@ -405,10 +404,6 @@ int AbilityManagerProxy::StartUIExtensionAbility(const Want &want, const sptr(extensionType))) { - HILOG_ERROR("StartExtensionAbility, extensionType write failed."); - return INNER_ERR; - } if (!Remote()) { HILOG_ERROR("StartExtensionAbility, Remote error."); return INNER_ERR; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index e52e87d3ef..b8597d02c0 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -112,6 +112,8 @@ const std::string BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard"; // Support prepare terminate constexpr int32_t PREPARE_TERMINATE_ENABLE_SIZE = 6; const char* PREPARE_TERMINATE_ENABLE_PARAMETER = "persist.sys.prepare_terminate"; +// UIExtension type +const std::string UIEXTENSION_TYPE_KEY = "ability.want.params.UIEXTENSIONTYPE"; const std::unordered_set WHITE_LIST_ASS_WAKEUP_SET = { BUNDLE_NAME_SETTINGSDATA }; @@ -1636,21 +1638,22 @@ int AbilityManagerService::StartExtensionAbility(const Want &want, const sptr &extensionSessionInfo, - int32_t userId, AppExecFwk::ExtensionAbilityType extensionType) +int AbilityManagerService::StartUIExtensionAbility(const sptr &extensionSessionInfo, int32_t userId) { HILOG_INFO("Start ui extension ability come, bundlename: %{public}s, ability is %{public}s, userId is %{pravite}d", - want.GetElement().GetBundleName().c_str(), want.GetElement().GetAbilityName().c_str(), userId); + extensionSessionInfo->want.GetElement().GetBundleName().c_str(), + extensionSessionInfo->want.GetElement().GetAbilityName().c_str(), userId); CHECK_POINTER_AND_RETURN(extensionSessionInfo, ERR_INVALID_VALUE); - EventInfo eventInfo = BuildEventInfo(want, userId); + AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UI; + EventInfo eventInfo = BuildEventInfo(extensionSessionInfo->want, userId); eventInfo.extensionType = static_cast(extensionType); EventReport::SendExtensionEvent(EventName::START_SERVICE, HiSysEventType::BEHAVIOR, eventInfo); sptr callerToken = extensionSessionInfo->callerToken; - if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) || + if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, extensionSessionInfo->want) || VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED || - !DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) { + !DlpUtils::DlpAccessOtherAppsCheck(callerToken, extensionSessionInfo->want)) { HILOG_ERROR("StartUIExtensionAbility: Permission verification failed."); eventInfo.errCode = CHECK_PERMISSION_FAILED; EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); @@ -1673,7 +1676,7 @@ int AbilityManagerService::StartUIExtensionAbility(const Want &want, const sptr< } auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : - interceptorExecuter_->DoProcess(want, 0, GetUserId(), false); + interceptorExecuter_->DoProcess(extensionSessionInfo->want, 0, GetUserId(), false); if (result != ERR_OK) { HILOG_ERROR("interceptorExecuter_ is nullptr or DoProcess return error."); eventInfo.errCode = result; @@ -1689,7 +1692,7 @@ int AbilityManagerService::StartUIExtensionAbility(const Want &want, const sptr< return ERR_INVALID_VALUE; } - if (ImplicitStartProcessor::IsImplicitStartAction(want)) { + if (ImplicitStartProcessor::IsImplicitStartAction(extensionSessionInfo->want)) { HILOG_ERROR("UI extension ability donot support implicit start."); eventInfo.errCode = ERR_INVALID_VALUE; EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); @@ -1697,11 +1700,11 @@ int AbilityManagerService::StartUIExtensionAbility(const Want &want, const sptr< } AbilityRequest abilityRequest; - abilityRequest.Voluation(want, DEFAULT_INVAL_VALUE, callerToken); + abilityRequest.Voluation(extensionSessionInfo->want, DEFAULT_INVAL_VALUE, callerToken); abilityRequest.callType = AbilityCallType::START_EXTENSION_TYPE; abilityRequest.extensionType = extensionType; abilityRequest.sessionInfo = extensionSessionInfo; - result = GenerateExtensionAbilityRequest(want, abilityRequest, callerToken, validUserId); + result = GenerateExtensionAbilityRequest(extensionSessionInfo->want, abilityRequest, callerToken, validUserId); if (result != ERR_OK) { HILOG_ERROR("Generate ability request local error."); eventInfo.errCode = result; diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 65ede1603a..16c4f64625 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -503,24 +503,15 @@ int AbilityManagerStub::StartExtensionAbilityInner(MessageParcel &data, MessageP int AbilityManagerStub::StartUIExtensionAbilityInner(MessageParcel &data, MessageParcel &reply) { - Want *want = data.ReadParcelable(); - if (want == nullptr) { - HILOG_ERROR("want is nullptr"); - return ERR_INVALID_VALUE; - } - sptr extensionSessionInfo = nullptr; if (data.ReadBool()) { extensionSessionInfo = data.ReadParcelable(); } int32_t userId = data.ReadInt32(); - int32_t extensionType = data.ReadInt32(); - int32_t result = StartUIExtensionAbility(*want, extensionSessionInfo, userId, - static_cast(extensionType)); + int32_t result = StartUIExtensionAbility(extensionSessionInfo, userId); reply.WriteInt32(result); - delete want; return NO_ERROR; } diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp index 7faf4cb3f8..76effca92a 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp @@ -1091,7 +1091,7 @@ HWTEST_F(AbilityManagerClientBranchTest, StartUIExtensionAbility_0100, TestSize. { GTEST_LOG_(INFO) << "StartUIExtensionAbility_0100 start"; Want want; - EXPECT_EQ(client_->StartUIExtensionAbility(want, nullptr, 100, AppExecFwk::ExtensionAbilityType::UI), + EXPECT_EQ(client_->StartUIExtensionAbility(nullptr, 100), ERR_OK); GTEST_LOG_(INFO) << "StartUIExtensionAbility_0100 end"; } diff --git a/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp b/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp index b672e934cf..644eb2f184 100755 --- a/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp +++ b/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp @@ -3198,7 +3198,7 @@ HWTEST_F(AbilityManagerServiceTest, IsValidMissionIds_002, TestSize.Level1) HWTEST_F(AbilityManagerServiceTest, StartUIExtensionAbility_001, TestSize.Level1) { Want want; - EXPECT_EQ(abilityMs_->StartUIExtensionAbility(want, nullptr, 100, AppExecFwk::ExtensionAbilityType::UI), + EXPECT_EQ(abilityMs_->StartUIExtensionAbility(nullptr, 100), ERR_INVALID_VALUE); } @@ -3211,8 +3211,7 @@ HWTEST_F(AbilityManagerServiceTest, StartUIExtensionAbility_001, TestSize.Level1 HWTEST_F(AbilityManagerServiceTest, StartUIExtensionAbility_002, TestSize.Level1) { Want want; - EXPECT_EQ(abilityMs_->StartUIExtensionAbility(want, MockSessionInfo(0), USER_ID_U100, - AppExecFwk::ExtensionAbilityType::UI), CHECK_PERMISSION_FAILED); + EXPECT_EQ(abilityMs_->StartUIExtensionAbility(MockSessionInfo(0), USER_ID_U100), CHECK_PERMISSION_FAILED); } /*