From 30d51888fab8379342f93bd865128fb103a25883 Mon Sep 17 00:00:00 2001 From: wanchengzhen Date: Wed, 16 Feb 2022 10:01:07 +0000 Subject: [PATCH] Check codeCheck Signed-off-by: wanchengzhen --- bundle.json | 1 + .../AMS/mock_serviceability_manager_service.h | 3 +- frameworks/kits/ability/native/BUILD.gn | 7 +- .../kits/ability/native/include/ability.h | 31 -- .../ability/native/include/ability_impl.h | 2 +- .../include/ability_runtime/js_ability.h | 2 + .../ability/native/include/ability_thread.h | 4 +- .../distributed_client.h | 9 +- .../native/include/iability_callback.h | 3 - .../kits/ability/native/src/ability.cpp | 82 +---- .../kits/ability/native/src/ability_impl.cpp | 2 +- .../native/src/ability_runtime/js_ability.cpp | 64 +++- .../ability/native/src/ability_thread.cpp | 18 +- .../distributed/continuation_manager.cpp | 4 - .../distributed_client.cpp | 11 +- .../include/mock_ability_manager_client.h | 6 +- .../include/mock_ability_manager_service.h | 3 +- .../mock_ability_scheduler_for_observer.h | 6 +- frameworks/kits/appkit/BUILD.gn | 73 +++- .../include/ability_delegator.h | 58 +--- .../include/ability_delegator_infos.h | 33 ++ .../include/iability_monitor.h | 13 +- .../src/ability_delegator.cpp | 229 +++++------- .../src/iability_monitor.cpp | 30 +- .../form_extension_context.cpp | 6 +- .../appkit/native/app/include/main_thread.h | 16 +- .../appkit/native/app/src/main_thread.cpp | 42 +-- .../test/unittest/context_container_test.cpp | 20 +- .../Mock/include/mock_ability_mgr_service.h | 2 +- .../cpp/src/ohos/aafwk/content/want.cpp | 1 - .../mock/AMS/mock_ability_manager_service.h | 3 +- .../AMS/mock_serviceability_manager_service.h | 3 +- .../include/ability_manager_client.h | 15 +- .../include/ability_manager_interface.h | 11 +- .../include/ability_scheduler_interface.h | 4 +- .../ability_manager/include/start_options.h | 8 +- .../want/include/ohos/aafwk/content/want.h | 1 - .../js/@ohos.ability.particleAbility.d.ts | 26 -- .../aafwk/ability_context/ability_context.js | 8 +- .../napi/aafwk/app/ability_delegator/BUILD.gn | 2 +- .../app/ability_delegator/ability_monitor.cpp | 16 +- .../app/ability_delegator/ability_monitor.h | 17 +- .../js_ability_delegator.cpp | 69 ++-- .../ability_delegator/js_ability_delegator.h | 2 + .../js_ability_delegator_registry.cpp | 15 +- .../js_ability_delegator_utils.cpp | 27 +- .../napi/aafwk/app/test_runner/test_runner.js | 4 +- .../napi/aafwk/inner/napi_common/BUILD.gn | 1 - .../napi_common/feature_ability_common.h | 1 - .../inner/napi_common/napi_common_ability.cpp | 328 ------------------ .../inner/napi_common/napi_common_ability.h | 22 +- .../inner/napi_common/napi_common_want.cpp | 14 +- .../inner/napi_common/napi_common_want.h | 1 - .../aafwk/mission_manager/mission_manager.cpp | 21 +- .../particleAbility/particle_ability.cpp | 30 -- .../include/ability_manager_proxy.h | 8 +- .../include/ability_manager_service.h | 6 +- .../abilitymgr/include/ability_manager_stub.h | 3 +- services/abilitymgr/include/ability_record.h | 4 +- .../include/ability_scheduler_proxy.h | 4 +- services/abilitymgr/include/lifecycle_deal.h | 2 +- services/abilitymgr/include/mission_list.h | 4 +- .../abilitymgr/include/mission_list_manager.h | 16 +- .../abilitymgr/src/ability_manager_client.cpp | 17 - .../abilitymgr/src/ability_manager_proxy.cpp | 28 +- .../src/ability_manager_service.cpp | 119 +++---- .../abilitymgr/src/ability_manager_stub.cpp | 21 +- services/abilitymgr/src/ability_record.cpp | 13 +- .../src/ability_scheduler_proxy.cpp | 7 +- .../abilitymgr/src/ability_scheduler_stub.cpp | 9 +- services/abilitymgr/src/lifecycle_deal.cpp | 2 +- services/abilitymgr/src/mission_list.cpp | 8 +- .../abilitymgr/src/mission_list_manager.cpp | 49 +-- .../abilitymgr/src/pending_want_manager.cpp | 3 +- services/abilitymgr/src/start_options.cpp | 14 +- .../libs/aakit/include/ability_scheduler.h | 4 +- .../ability_scheduler_mock.h | 6 +- .../ability_dump_test/ability_dump_test.cpp | 7 +- .../ability_manager_stub_mock.h | 3 +- .../ability_manager_service_test.cpp | 9 +- .../ability_manager_stub_impl_mock.h | 6 +- .../ability_manager_stub_mock.h | 2 +- .../ability_record_test.cpp | 1 + .../ability_schedule_stub_mock.h | 6 +- .../ability_service_start_test.cpp | 2 + .../ability_stack_manager_test.cpp | 1 + .../ability_with_applications_test.cpp | 1 + .../abilityms_appms_test.cpp | 24 +- .../kernal_system_app_manager_test.cpp | 3 + .../phone/lifecycle_test/lifecycle_test.cpp | 10 +- .../pending_want_manager_test.cpp | 1 + .../terminate_ability_test.cpp | 7 +- services/appmgr/src/app_mgr_service_inner.cpp | 18 +- .../test/mock/src/mock_bundle_manager.cpp | 4 + .../ams_app_life_cycle_test.cpp | 100 +++++- .../ams_service_event_drive_test.cpp | 20 +- services/formmgr/bundle.json | 4 +- services/formmgr/src/form_mgr_service.cpp | 6 +- .../test/mock/include/mock_ability_manager.h | 13 +- .../fms_form_host_record_test.cpp | 16 +- .../fms_form_mgr_add_form_test.cpp | 22 +- .../fms_form_mgr_cast_temp_form_test.cpp | 16 +- .../fms_form_mgr_death_callback_test.cpp | 18 +- .../fms_form_mgr_delete_form_test.cpp | 16 +- .../fms_form_mgr_lifecycle_update_test.cpp | 11 +- .../fms_form_mgr_message_event_test.cpp | 16 +- ...s_form_mgr_notify_invisible_forms_test.cpp | 24 +- ...fms_form_mgr_notify_visible_forms_test.cpp | 13 +- .../fms_form_mgr_release_form_test.cpp | 8 +- .../fms_form_mgr_request_form_test.cpp | 14 +- .../fms_form_mgr_update_form_test.cpp | 17 +- .../fms_form_provider_mgr_test.cpp | 18 +- .../fms_form_set_next_refresh_test.cpp | 21 +- .../fms_form_sys_event_receiver_test.cpp | 18 +- .../fms_form_timer_mgr_test.cpp | 3 + .../include/appmgr/mock_ability_mgr_host.h | 6 +- .../mock/include/mock_ability_mgr_service.h | 3 +- .../mock/include/mock_ability_scheduler.h | 4 +- .../include/mock_ability_scheduler_stub.h | 4 +- .../ability_mgr_module_test.cpp | 7 +- .../ability_stack_module_test.cpp | 4 +- .../dump_module_test/dump_module_test.cpp | 1 + .../panding_want_manager_test.cpp | 2 +- tools/aa/src/ability_command.cpp | 37 +- tools/test/mock/mock_ability_manager_stub.h | 3 +- 125 files changed, 921 insertions(+), 1426 deletions(-) create mode 100644 frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_infos.h diff --git a/bundle.json b/bundle.json index a1087adc372..ae71005c594 100644 --- a/bundle.json +++ b/bundle.json @@ -24,6 +24,7 @@ "appspawn", "bytrace_standard", "ces_standard", + "ces_standard", "device_manager_base", "distributeddatamgr_appdatamgr", "distributedschedule_dms_fwk", diff --git a/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h index 64a58e4af28..fb6a3059f83 100644 --- a/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h @@ -117,7 +117,7 @@ public: MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id)); MOCK_METHOD1(GetSystemMemoryAttr, void(AppExecFwk::SystemMemoryAttr &memoryInfo)); MOCK_METHOD3(StartContinuation, int(const Want &want, const sptr &abilityToken, int32_t status)); - MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, const int32_t result)); MOCK_METHOD1(LockMissionForCleanup, int(int32_t missionId)); MOCK_METHOD1(UnlockMissionForCleanup, int(int32_t missionId)); @@ -134,7 +134,6 @@ public: MOCK_METHOD1(CleanMission, int(int32_t missionId)); MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); - MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); MOCK_METHOD2(GetWantSenderInfo, int(const sptr &target, std::shared_ptr &info)); diff --git a/frameworks/kits/ability/native/BUILD.gn b/frameworks/kits/ability/native/BUILD.gn index 3bfc269332c..4290788f2d0 100644 --- a/frameworks/kits/ability/native/BUILD.gn +++ b/frameworks/kits/ability/native/BUILD.gn @@ -76,7 +76,6 @@ config("ability_public_config") { "//third_party/libuv/include", "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context", "//foundation/aafwk/standard/interfaces/innerkits/base/include/ohos/aafwk/base", - "//foundation/aafwk/standard/frameworks/kits/ability/native/include", "//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/remote_register_service", "//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/distributed", "//foundation/aafwk/standard/frameworks/kits/ability/native/include/distributed_ability_runtime", @@ -125,7 +124,6 @@ ohos_shared_library("abilitykit_native") { "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_dataability/include", "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_resultset/include", - "//foundation/distributeddatamgr/objectstore/interfaces/innerkits/", "//base/global/i18n_standard/frameworks/intl/include", ] @@ -234,7 +232,6 @@ ohos_shared_library("abilitykit_native") { configs = [ ":ability_config" ] public_configs = [ ":ability_public_config", - "//base/notification/ans_standard/frameworks/wantagent:wantagent_innerkits_public_config", "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_public_config", ] @@ -242,11 +239,11 @@ ohos_shared_library("abilitykit_native") { ":static_subscriber_ipc", "${INNERKITS_PATH}/base:base", "${INNERKITS_PATH}/want:want", - "//base/notification/ans_standard/frameworks/wantagent:wantagent_innerkits", "//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard", "//foundation/aafwk/standard/common/task_dispatcher:task_dispatcher", "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_native", "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", + "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_delegator", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager", "//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager:dataobs_manager", @@ -257,7 +254,6 @@ ohos_shared_library("abilitykit_native") { "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", - "//foundation/resourceschedule/background_task_mgr/interfaces/innerkits:bgtaskmgr_innerkits", "//third_party/icu/icu4c:shared_icuuc", ] @@ -269,7 +265,6 @@ ohos_shared_library("abilitykit_native") { "access_token:libaccesstoken_sdk", "bytrace_standard:bytrace_core", "ces_standard:cesfwk_innerkits", - "distributeddataobject:distributeddataobject_impl", "form_runtime:fmskit_native", "form_runtime:form_manager", "ipc:ipc_core", diff --git a/frameworks/kits/ability/native/include/ability.h b/frameworks/kits/ability/native/include/ability.h index b43960bd9f4..55b6f88512d 100755 --- a/frameworks/kits/ability/native/include/ability.h +++ b/frameworks/kits/ability/native/include/ability.h @@ -44,7 +44,6 @@ #include "iremote_object.h" #include "pac_map.h" #include "want.h" -#include "want_agent.h" #include "window_option.h" #include "window_scene.h" #include "wm_common.h" @@ -672,14 +671,6 @@ public: */ virtual void Dump(const std::string &extra); - /** - * @brief dump ability info - * - * @param params dump params that indicate different dump targets - * @param info dump ability info - */ - virtual void Dump(const std::vector ¶ms, std::vector &info); - /** * @brief Keeps this Service ability in the background and displays a notification bar. * To use this method, you need to request the ohos.permission.KEEP_BACKGROUND_RUNNING permission from the system. @@ -1015,21 +1006,6 @@ public: */ bool DeleteForm(const int64_t formId); - /** - * @brief Keep this Service ability in the background and displays a notification bar. - * - * @param wantAgent Indicates which ability to start when user click the notification bar. - * @return the method result code, 0 means succeed - */ - virtual int StartBackgroundRunning(const Notification::WantAgent::WantAgent &wantAgent) final; - - /** - * @brief Cancel background running of this ability to free up system memory. - * - * @return the method result code, 0 means succeed - */ - virtual int StopBackgroundRunning() final; - /** * @brief The form callback. */ @@ -1461,13 +1437,6 @@ protected: */ bool IsRestoredInContinuation() const; - /** - * @brief wait for distributed object to complete sync - * - * @param want the want param. - */ - void WaitingDistributedObjectSyncComplete(const Want& want); - /** * @brief Notify continuation * diff --git a/frameworks/kits/ability/native/include/ability_impl.h b/frameworks/kits/ability/native/include/ability_impl.h index c5ee7da1607..cf2afeb8a7b 100755 --- a/frameworks/kits/ability/native/include/ability_impl.h +++ b/frameworks/kits/ability/native/include/ability_impl.h @@ -349,7 +349,7 @@ public: * * @return */ - virtual void NotifyContinuationResult(int32_t result); + virtual void NotifyContinuationResult(const int32_t result); bool IsStageBasedModel() const; diff --git a/frameworks/kits/ability/native/include/ability_runtime/js_ability.h b/frameworks/kits/ability/native/include/ability_runtime/js_ability.h index 59db1588763..851d6fa9f21 100755 --- a/frameworks/kits/ability/native/include/ability_runtime/js_ability.h +++ b/frameworks/kits/ability/native/include/ability_runtime/js_ability.h @@ -17,6 +17,7 @@ #define ABILITY_RUNTIME_JS_ABILITY_H #include "ability.h" +#include "ability_delegator_infos.h" class NativeReference; class NativeValue; @@ -69,6 +70,7 @@ private: void CallObjectMethod(const char *name, NativeValue *const *argv = nullptr, size_t argc = 0); std::unique_ptr CreateAppWindowStage(); void GetPageStackFromWant(const Want &want, std::string &pageStack); + std::shared_ptr CreateADelegatorAbilityProperty(); JsRuntime &jsRuntime_; std::shared_ptr shellContextRef_; diff --git a/frameworks/kits/ability/native/include/ability_thread.h b/frameworks/kits/ability/native/include/ability_thread.h index 6ad054d18b4..2b870321f20 100644 --- a/frameworks/kits/ability/native/include/ability_thread.h +++ b/frameworks/kits/ability/native/include/ability_thread.h @@ -313,7 +313,7 @@ public: * * @param result: Continuation result */ - void NotifyContinuationResult(int32_t result); + void NotifyContinuationResult(const int32_t result); /** * @brief Converts the given uri that refer to the Data ability into a normalized URI. A normalized URI can be used @@ -400,7 +400,7 @@ public: * * @param runnerInfo ability runner info. */ - void DumpAbilityInfo(const std::vector ¶ms, std::vector &info); + void DumpAbilityInfo(std::vector &info); sptr CallRequest(); diff --git a/frameworks/kits/ability/native/include/distributed_ability_runtime/distributed_client.h b/frameworks/kits/ability/native/include/distributed_ability_runtime/distributed_client.h index f931e17ee99..a8a75b9274d 100644 --- a/frameworks/kits/ability/native/include/distributed_ability_runtime/distributed_client.h +++ b/frameworks/kits/ability/native/include/distributed_ability_runtime/distributed_client.h @@ -31,15 +31,14 @@ class DistributedClient { public: DistributedClient() = default; virtual ~DistributedClient() = default; - int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, - uint32_t accessToken); + int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode); int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams); int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid, - int32_t status, uint32_t accessToken); + int32_t status); int32_t NotifyCompleteContinuation(const std::u16string &devId, int32_t sessionId, bool isSuccess); - int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken); + int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, + const sptr& connect, int32_t callerUid, int32_t callerPid); int32_t DisconnectRemoteAbility(const sptr& connect); int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag); int32_t StopSyncRemoteMissions(const std::string& devId); diff --git a/frameworks/kits/ability/native/include/iability_callback.h b/frameworks/kits/ability/native/include/iability_callback.h index 7a4f8195fb7..a62753795d5 100644 --- a/frameworks/kits/ability/native/include/iability_callback.h +++ b/frameworks/kits/ability/native/include/iability_callback.h @@ -20,9 +20,6 @@ namespace OHOS { namespace AppExecFwk { class IAbilityCallback { public: - IAbilityCallback() = default; - virtual ~IAbilityCallback() = default; - /** * @brief Called back at ability context. */ diff --git a/frameworks/kits/ability/native/src/ability.cpp b/frameworks/kits/ability/native/src/ability.cpp index 61772871a83..54ce04dd202 100755 --- a/frameworks/kits/ability/native/src/ability.cpp +++ b/frameworks/kits/ability/native/src/ability.cpp @@ -24,20 +24,17 @@ #include "ability_runtime/js_ability.h" #include "abs_shared_result_set.h" #include "app_log_wrapper.h" -#include "background_task_mgr_helper.h" #include "bytrace.h" #include "connection_manager.h" #include "context_impl.h" #include "continuation_manager.h" #include "continuation_register_manager.h" #include "continuation_register_manager_proxy.h" -#include "continuous_task_param.h" #include "data_ability_operation.h" #include "data_ability_predicates.h" #include "data_ability_result.h" #include "data_uri_utils.h" #include "display_type.h" -#include "distributed_objectstore.h" #include "form_host_client.h" #include "form_mgr.h" #include "form_provider_client.h" @@ -81,7 +78,6 @@ static std::mutex formLock; constexpr int64_t SEC_TO_MILLISEC = 1000; constexpr int64_t MILLISEC_TO_NANOSEC = 1000000; -constexpr int32_t DISTRIBUTED_OBJECT_TIMEOUT = 3000; Ability* Ability::Create(const std::unique_ptr& runtime) { @@ -206,7 +202,7 @@ void Ability::OnStart(const Want &want) } int defualtDisplayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; - int displayId = want.GetIntParam(Want::PARAM_RESV_DISPLAY_ID, defualtDisplayId); + int displayId = want.GetIntParam(StartOptions::STRING_DISPLAY_ID, defualtDisplayId); APP_LOGI("Ability::OnStart bundleName:%{public}s, abilityName:%{public}s, windowType:%{public}d, " "displayId:%{public}d", abilityInfo_->bundleName.c_str(), @@ -279,7 +275,6 @@ void Ability::Destroy() APP_LOGI("%{public}s begin.", __func__); // Release the scene. if (scene_ != nullptr) { - scene_->GoDestroy(); scene_ = nullptr; onSceneDestroyed(); } @@ -418,43 +413,8 @@ bool Ability::IsRestoredInContinuation() const return false; } -void Ability::WaitingDistributedObjectSyncComplete(const Want& want) -{ - int sessionId = want.GetIntParam(DMS_SESSION_ID, DEFAULT_DMS_SESSION_ID); - std::string originDeviceId = want.GetStringParam(DMS_ORIGIN_DEVICE_ID); - - APP_LOGI("continuation WaitingDistributedObjectSyncComplete begin"); - auto timeout = [self = shared_from_this(), sessionId, originDeviceId]() { - APP_LOGI("DistributedObject sync timeout"); - self->continuationManager_->NotifyCompleteContinuation( - originDeviceId, sessionId, false, nullptr); - }; - - // std::shared_ptr handler = handler_; - auto callback = [self = shared_from_this(), sessionId, originDeviceId]() { - APP_LOGI("DistributedObject sync complete"); - if (self->handler_ != nullptr) { - self->handler_->RemoveTask("Waiting_Sync_Timeout"); - } - self->continuationManager_->NotifyCompleteContinuation( - originDeviceId, sessionId, true, nullptr); - }; - - std::string &bundleName = abilityInfo_->bundleName; - APP_LOGI("continuation TriggerRestore begin"); - ObjectStore::DistributedObjectStore::GetInstance(bundleName)->TriggerRestore(callback); - APP_LOGI("continuation TriggerRestore end"); - - if (handler_ != nullptr) { - APP_LOGI("continuation set timeout begin"); - handler_->PostTask(timeout, "Waiting_Sync_Timeout", DISTRIBUTED_OBJECT_TIMEOUT); - APP_LOGI("continuation set timeout end"); - } -} - void Ability::NotityContinuationResult(const Want& want, bool success) { - APP_LOGI("NotityContinuationResult begin"); std::weak_ptr ReplicaHandler = continuationHandler_; reverseContinuationSchedulerReplica_ = sptr( new (std::nothrow) ReverseContinuationSchedulerReplica(handler_, ReplicaHandler)); @@ -1262,15 +1222,6 @@ void Ability::Dump(const std::string &extra) } } -/** - * @brief dump ability info - * - * @param params dump params that indicate different dump targets - * @param info dump ability info -*/ -void Ability::Dump(const std::vector ¶ms, std::vector &info) -{} - /** * @brief Keeps this Service ability in the background and displays a notification bar. * To use this method, you need to request the ohos.permission.KEEP_BACKGROUND_RUNNING permission from the system. @@ -1994,30 +1945,6 @@ bool Ability::DeleteForm(const int64_t formId) return DeleteForm(formId, DELETE_FORM); } -/** - * @brief Keep this Service ability in the background and displays a notification bar. - * - * @param wantAgent Indicates which ability to start when user click the notification bar. - * @return the method result code, 0 means succeed - */ -int Ability::StartBackgroundRunning(const Notification::WantAgent::WantAgent &wantAgent) -{ - uint32_t defaultBgMode = 0; - BackgroundTaskMgr::ContinuousTaskParam taskParam = BackgroundTaskMgr::ContinuousTaskParam(false, defaultBgMode, - std::make_shared(wantAgent), abilityInfo_->name, GetToken()); - return BackgroundTaskMgr::BackgroundTaskMgrHelper::RequestStartBackgroundRunning(taskParam); -} - -/** - * @brief Cancel background running of this ability to free up system memory. - * - * @return the method result code, 0 means succeed - */ -int Ability::StopBackgroundRunning() -{ - return BackgroundTaskMgr::BackgroundTaskMgrHelper::RequestStopBackgroundRunning(abilityInfo_->name, GetToken()); -} - /** * @brief Cast temp form with formId. * @@ -3345,13 +3272,6 @@ void Ability::DoOnForeground(const Want& want) if (abilityWindow_ != nullptr) { APP_LOGI("%{public}s begin abilityWindow_->OnPostAbilityForeground, sceneFlag:%{public}d.", __func__, sceneFlag_); - auto window = abilityWindow_->GetWindow(); - if (window != nullptr && want.HasParameter(Want::PARAM_RESV_WINDOW_MODE)) { - auto windowMode = want.GetIntParam(Want::PARAM_RESV_WINDOW_MODE, - AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED); - window->SetWindowMode(static_cast(windowMode)); - APP_LOGI("set window mode = %{public}d.", windowMode); - } abilityWindow_->OnPostAbilityForeground(sceneFlag_); APP_LOGI("%{public}s end abilityWindow_->OnPostAbilityForeground.", __func__); } else { diff --git a/frameworks/kits/ability/native/src/ability_impl.cpp b/frameworks/kits/ability/native/src/ability_impl.cpp index e4aed208c0b..a57bfb9b105 100755 --- a/frameworks/kits/ability/native/src/ability_impl.cpp +++ b/frameworks/kits/ability/native/src/ability_impl.cpp @@ -918,7 +918,7 @@ void AbilityImpl::ContinueAbility(const std::string& deviceId) ability_->ContinueAbilityWithStack(deviceId); } -void AbilityImpl::NotifyContinuationResult(int32_t result) +void AbilityImpl::NotifyContinuationResult(const int32_t result) { if (ability_ == nullptr) { APP_LOGE("AbilityImpl::NotifyContinuationResult ability_ is nullptr"); diff --git a/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp b/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp index 46ad247b289..10b5e2d71c1 100755 --- a/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp +++ b/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp @@ -15,6 +15,7 @@ #include #include "system_ability_definition.h" #include "if_system_ability_manager.h" +#include "ability_delegator_registry.h" #include "ability_runtime/js_ability.h" #include "ability_runtime/js_ability_context.h" @@ -144,6 +145,12 @@ void JsAbility::OnStart(const Want &want) CreateJsLaunchParam(nativeEngine, GetLaunchParam()), }; CallObjectMethod("onCreate", argv, ArraySize(argv)); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_INFO("Call AbilityDelegator::PostPerformStart"); + delegator->PostPerformStart(CreateADelegatorAbilityProperty()); + } } void JsAbility::OnStop() @@ -151,6 +158,13 @@ void JsAbility::OnStop() Ability::OnStop(); CallObjectMethod("onDestroy"); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_INFO("Call AbilityDelegator::PostPerformStop"); + delegator->PostPerformStop(CreateADelegatorAbilityProperty()); + } + bool ret = ConnectionManager::GetInstance().DisconnectCaller(AbilityContext::token_); if (ret) { HILOG_INFO("The service connection is not disconnected."); @@ -168,6 +182,12 @@ void JsAbility::OnSceneCreated() } NativeValue *argv[] = {jsAppWindowStage->Get()}; CallObjectMethod("onWindowStageCreate", argv, ArraySize(argv)); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_INFO("Call AbilityDelegator::PostPerformScenceCreated"); + delegator->PostPerformScenceCreated(CreateADelegatorAbilityProperty()); + } } void JsAbility::OnSceneRestored() @@ -181,6 +201,12 @@ void JsAbility::OnSceneRestored() } NativeValue *argv[] = {jsAppWindowStage->Get()}; CallObjectMethod("onWindowStageRestore", argv, ArraySize(argv)); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_INFO("Call AbilityDelegator::PostPerformScenceRestored"); + delegator->PostPerformScenceRestored(CreateADelegatorAbilityProperty()); + } } void JsAbility::onSceneDestroyed() @@ -188,6 +214,12 @@ void JsAbility::onSceneDestroyed() Ability::onSceneDestroyed(); CallObjectMethod("onWindowStageDestroy"); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_INFO("Call AbilityDelegator::PostPerformScenceDestroyed"); + delegator->PostPerformScenceDestroyed(CreateADelegatorAbilityProperty()); + } } void JsAbility::OnForeground(const Want &want) @@ -210,6 +242,12 @@ void JsAbility::OnForeground(const Want &want) obj->SetProperty("lastRequestWant", jsWant); CallObjectMethod("onForeground", &jsWant, 1); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_INFO("Call AbilityDelegator::PostPerformForeground"); + delegator->PostPerformForeground(CreateADelegatorAbilityProperty()); + } } void JsAbility::OnBackground() @@ -217,6 +255,12 @@ void JsAbility::OnBackground() Ability::OnBackground(); CallObjectMethod("onBackground"); + + auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + HILOG_INFO("Call AbilityDelegator::PostPerformBackground"); + delegator->PostPerformBackground(CreateADelegatorAbilityProperty()); + } } bool JsAbility::OnContinue(WantParams &wantParams) @@ -455,22 +499,24 @@ void JsAbility::DoOnForeground(const Want &want) HILOG_ERROR("restore: content storage is nullptr"); } OnSceneRestored(); - WaitingDistributedObjectSyncComplete(want); + NotityContinuationResult(want, true); } else { OnSceneCreated(); } - } else { - auto window = scene_->GetMainWindow(); - if (window != nullptr && want.HasParameter(Want::PARAM_RESV_WINDOW_MODE)) { - auto windowMode = want.GetIntParam(Want::PARAM_RESV_WINDOW_MODE, - AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED); - window->SetWindowMode(static_cast(windowMode)); - HILOG_INFO("set window mode = %{public}d.", windowMode); - } } HILOG_INFO("%{public}s begin scene_->GoForeground, sceneFlag_:%{public}d.", __func__, Ability::sceneFlag_); scene_->GoForeground(Ability::sceneFlag_); HILOG_INFO("%{public}s end scene_->GoForeground.", __func__); } + +std::shared_ptr JsAbility::CreateADelegatorAbilityProperty() +{ + auto property = std::make_shared(); + property->token_ = GetAbilityContext()->GetToken(); + property->name_ = GetAbilityName(); + property->lifecycleState_ = GetState(); + + return property; +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/kits/ability/native/src/ability_thread.cpp b/frameworks/kits/ability/native/src/ability_thread.cpp index 9b980402d57..ef238eaad0a 100644 --- a/frameworks/kits/ability/native/src/ability_thread.cpp +++ b/frameworks/kits/ability/native/src/ability_thread.cpp @@ -1212,7 +1212,7 @@ void AbilityThread::ContinueAbility(const std::string& deviceId) abilityImpl_->ContinueAbility(deviceId); } -void AbilityThread::NotifyContinuationResult(int32_t result) +void AbilityThread::NotifyContinuationResult(const int32_t result) { APP_LOGI("NotifyContinuationResult, result:%{public}d", result); if (abilityImpl_ == nullptr) { @@ -1559,23 +1559,9 @@ std::shared_ptr AbilityThread::BuildAbilityConte return abilityContextImpl; } -void AbilityThread::DumpAbilityInfo(const std::vector ¶ms, std::vector &info) +void AbilityThread::DumpAbilityInfo(std::vector &info) { APP_LOGI("%{public}s begin.", __func__); - if (!params.empty()) { - if (abilityImpl_->IsStageBasedModel()) { - auto window = currentAbility_->GetWindow(); - if (window == nullptr) { - APP_LOGE("DumpAbilityInfo window == nullptr"); - return; - } - window->DumpInfo(params, info); - } else { - currentAbility_->Dump(params, info); - } - - return; - } std::string dumpInfo = " event:"; info.push_back(dumpInfo); diff --git a/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp b/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp index 92d95f336f5..cb26a3056fa 100644 --- a/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp +++ b/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp @@ -21,7 +21,6 @@ #include "app_log_wrapper.h" #include "continuation_handler.h" #include "distributed_client.h" -#include "distributed_objectstore.h" #include "operation_builder.h" #include "string_ex.h" #include "string_wrapper.h" @@ -163,9 +162,6 @@ int32_t ContinuationManager::OnContinueAndGetContent(WantParams &wantParams) APP_LOGE("OnContinue failed."); return CONTINUE_ON_CONTINUE_FAILED; } - auto abilityInfo = abilityInfo_.lock(); - std::string &bundleName = abilityInfo->bundleName; - ObjectStore::DistributedObjectStore::GetInstance(bundleName)->TriggerSync(); status = GetContentInfo(wantParams); if (!status) { diff --git a/frameworks/kits/ability/native/src/distributed_ability_runtime/distributed_client.cpp b/frameworks/kits/ability/native/src/distributed_ability_runtime/distributed_client.cpp index 9255c711399..b7ef1ed1473 100644 --- a/frameworks/kits/ability/native/src/distributed_ability_runtime/distributed_client.cpp +++ b/frameworks/kits/ability/native/src/distributed_ability_runtime/distributed_client.cpp @@ -37,7 +37,7 @@ sptr DistributedClient::GetDmsProxy() } int32_t DistributedClient::StartRemoteAbility(const OHOS::AAFwk::Want& want, - int32_t callerUid, int32_t requestCode, uint32_t accessToken) + int32_t callerUid, int32_t requestCode) { HILOG_INFO("called"); sptr remote = GetDmsProxy(); @@ -51,13 +51,12 @@ int32_t DistributedClient::StartRemoteAbility(const OHOS::AAFwk::Want& want, PARCEL_WRITE_HELPER(data, Parcelable, &want); PARCEL_WRITE_HELPER(data, Int32, callerUid); PARCEL_WRITE_HELPER(data, Int32, requestCode); - PARCEL_WRITE_HELPER(data, Uint32, accessToken); MessageParcel reply; PARCEL_TRANSACT_SYNC_RET_INT(remote, START_REMOTE_ABILITY, data, reply); } -int32_t DistributedClient::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken) +int32_t DistributedClient::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, + const sptr& connect, int32_t callerUid, int32_t callerPid) { HILOG_INFO("called"); if (connect == nullptr) { @@ -78,7 +77,6 @@ int32_t DistributedClient::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, c PARCEL_WRITE_HELPER(data, RemoteObject, connect); PARCEL_WRITE_HELPER(data, Int32, callerUid); PARCEL_WRITE_HELPER(data, Int32, callerPid); - PARCEL_WRITE_HELPER(data, Uint32, accessToken); MessageParcel reply; PARCEL_TRANSACT_SYNC_RET_INT(remote, CONNECT_REMOTE_ABILITY, data, reply); } @@ -132,7 +130,7 @@ int32_t DistributedClient::ContinueMission(const std::string& srcDeviceId, const } int32_t DistributedClient::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid, - int32_t status, uint32_t accessToken) + int32_t status) { HILOG_INFO("called"); sptr remote = GetDmsProxy(); @@ -148,7 +146,6 @@ int32_t DistributedClient::StartContinuation(const OHOS::AAFwk::Want& want, int3 PARCEL_WRITE_HELPER(data, Int32, missionId); PARCEL_WRITE_HELPER(data, Int32, callerUid); PARCEL_WRITE_HELPER(data, Int32, status); - PARCEL_WRITE_HELPER(data, Uint32, accessToken); MessageParcel reply; PARCEL_TRANSACT_SYNC_RET_INT(remote, START_CONTINUATION, data, reply); } diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_client.h b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_client.h index c5d85822a23..3c1fda6d1d2 100755 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_client.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_client.h @@ -125,9 +125,9 @@ public: { return std::vector>(); }; - virtual void NotifyContinuationResult(int32_t result) {}; + virtual void NotifyContinuationResult(const int32_t result) {}; virtual void ContinueAbility(const std::string& deviceId) {}; - virtual void DumpAbilityInfo(const std::vector ¶ms, std::vector &info) {}; + virtual void DumpAbilityInfo(std::vector &info) {}; virtual sptr CallRequest() { return sptr(nullptr); @@ -135,4 +135,4 @@ public: }; } // namespace AppExecFwk } // namespace OHOS -#endif // FOUNDATION_APPEXECFWK_OHOS_ABILITY_NATIVE_MOCK_ABILITY_MANAGER_CLIENT_H +#endif // FOUNDATION_APPEXECFWK_OHOS_ABILITY_NATIVE_MOCK_ABILITY_MANAGER_CLIENT_H \ No newline at end of file diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h index 5b099201890..f828cef1da6 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h @@ -137,7 +137,7 @@ public: MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id)); MOCK_METHOD1(GetSystemMemoryAttr, void(AppExecFwk::SystemMemoryAttr &memoryInfo)); MOCK_METHOD3(StartContinuation, int(const Want &want, const sptr &abilityToken, int32_t status)); - MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, const int32_t result)); MOCK_METHOD5(ContinueMission, int(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams)); MOCK_METHOD2(ContinueAbility, int(const std::string &deviceId, int32_t missionId)); @@ -154,7 +154,6 @@ public: MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD2(SetMissionLabel, int(const sptr &token, const std::string &label)); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); - MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector &info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector &info)); diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_scheduler_for_observer.h b/frameworks/kits/ability/native/test/mock/include/mock_ability_scheduler_for_observer.h index b5c7d3e35c2..a638facadc4 100755 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_scheduler_for_observer.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_scheduler_for_observer.h @@ -58,9 +58,9 @@ public: MOCK_METHOD2(ScheduleUnregisterObserver, bool(const Uri &uri, const sptr &dataObserver)); MOCK_METHOD1(ScheduleNotifyChange, bool(const Uri &uri)); MOCK_METHOD1(ExecuteBatch, std::vector>(const std::vector> &operation)); - MOCK_METHOD1(NotifyContinuationResult, void(int32_t result)); + MOCK_METHOD1(NotifyContinuationResult, void(const int32_t result)); MOCK_METHOD1(ContinueAbility, void(const std::string& deviceId)); - MOCK_METHOD2(DumpAbilityInfo, void(const std::vector ¶ms, std::vector &info)); + MOCK_METHOD1(DumpAbilityInfo, void(std::vector &info)); virtual sptr CallRequest() { @@ -71,4 +71,4 @@ public: } // namespace AppExecFwk } // namespace OHOS -#endif /* OHOS_APPEXECFWK_MOCK_ABILITY_SCHEDULER_FOR_OBESERVER_H */ +#endif /* OHOS_APPEXECFWK_MOCK_ABILITY_SCHEDULER_FOR_OBESERVER_H */ \ No newline at end of file diff --git a/frameworks/kits/appkit/BUILD.gn b/frameworks/kits/appkit/BUILD.gn index 372c6a06c46..e3992e2f4cd 100644 --- a/frameworks/kits/appkit/BUILD.gn +++ b/frameworks/kits/appkit/BUILD.gn @@ -95,7 +95,6 @@ ohos_shared_library("appkit_native") { "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/context", "${aafwk_path}/frameworks/kits/appkit/native", "${aafwk_path}/frameworks/kits/ability/native/include", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/include", "${aafwk_path}/interfaces/innerkits/ability_manager/include", "${aafwk_path}/services/abilitymgr/include", "//utils/native/base/include", @@ -125,15 +124,6 @@ ohos_shared_library("appkit_native") { "${aafwk_path}/frameworks/kits/appkit/native/app/src/application_impl.cpp", "${aafwk_path}/frameworks/kits/appkit/native/app/src/context_container.cpp", - #"${aafwk_path}/frameworks/kits/appkit/native/app/main.cpp", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_registry.cpp", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/delegator_thread.cpp", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/runner_runtime/js_test_runner.cpp", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/shell_cmd_result.cpp", - "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/test_runner.cpp", "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/app/ability_stage.cpp", "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/app/js_ability_stage.cpp", "${aafwk_path}/frameworks/kits/appkit/native/app/src/context_deal.cpp", @@ -149,6 +139,7 @@ ohos_shared_library("appkit_native") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + ":appkit_delegator", "${aafwk_path}/common/task_dispatcher:task_dispatcher", "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", "${aafwk_path}/frameworks/kits/appkit:app_context", @@ -246,3 +237,65 @@ ohos_shared_library("app_context") { part_name = "ability_runtime" } + +# build so +ohos_shared_library("appkit_delegator") { + include_dirs = [ + "${appexecfwk_path}/common/log/include", + "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/app", + "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/context", + "${aafwk_path}/frameworks/kits/appkit/native", + "${aafwk_path}/frameworks/kits/ability/native/include", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/include", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "//utils/native/base/include", + ] + + configs = [ ":appkit_config" ] + + public_configs = [ ":appkit_public_config" ] + + sources = [ + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_args.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator_registry.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/delegator_thread.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/runner_runtime/js_test_runner.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/shell_cmd_result.cpp", + "${aafwk_path}/frameworks/kits/appkit/native/ability_delegator/src/test_runner.cpp", + "//foundation/aafwk/standard/tools/aa/src/shell_command_result.cpp", + "//foundation/aafwk/standard/tools/aa/src/test_observer_proxy.cpp", + ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${aafwk_path}/frameworks/kits/appkit:app_context", + "${aafwk_path}/interfaces/innerkits/ability_manager:ability_manager", + "${aafwk_path}/interfaces/innerkits/app_manager:app_manager", + "${aafwk_path}/interfaces/innerkits/want:want", + "${appexecfwk_path}/common:libappexecfwk_common", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler:libeventhandler", + "//third_party/icu/icu4c:shared_icuuc", + "//utils/native/base:utils", + ] + + external_deps = [ + "ability_runtime:runtime", + "bytrace_standard:bytrace_core", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + public_deps = [ + "//foundation/ace/napi:ace_napi", + ] + + part_name = "ability_runtime" +} diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h index d970c48d466..0a0a1f084a9 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h @@ -19,24 +19,21 @@ #include #include #include -#include #include -#include #include +#include "ability_delegator_infos.h" #include "iability_monitor.h" #include "delegator_thread.h" #include "shell_cmd_result.h" #include "test_runner.h" -#include "ability_lifecycle_callbacks.h" #include "ability_lifecycle_executor.h" #include "ability_runtime/context/context.h" -#include "main_thread.h" namespace OHOS { namespace AppExecFwk { -class AbilityDelegator : public AbilityLifecycleCallbacks, public std::enable_shared_from_this { +class AbilityDelegator : public std::enable_shared_from_this { public: enum class AbilityState : uint8_t { UNINITIALIZED = 0, @@ -46,24 +43,11 @@ public: STOPED }; - using ability_property = std::tuple, std::shared_ptr, AbilityDelegator::AbilityState>; - using list_ability_property = std::list; - public: - AbilityDelegator(const sptr &mainThread, std::unique_ptr runner, + AbilityDelegator(const std::shared_ptr &context, std::unique_ptr runner, const sptr &observer); ~AbilityDelegator(); - void Init(); - - void OnAbilityStart(const std::shared_ptr &ability) override; - void OnAbilityInactive(const std::shared_ptr &ability) override; - void OnAbilityBackground(const std::shared_ptr &ability) override; - void OnAbilityForeground(const std::shared_ptr &ability) override; - void OnAbilityActive(const std::shared_ptr &ability) override; - void OnAbilityStop(const std::shared_ptr &ability) override; - void OnAbilitySaveState(const PacMap &outState) override; - void AddAbilityMonitor(const std::shared_ptr &monitor); void RemoveAbilityMonitor(const std::shared_ptr &monitor); void ClearAllMonitors(); @@ -88,35 +72,29 @@ public: void Print(const std::string &msg); - void PrePerformStart(const std::shared_ptr &ability); - void PostPerformStart(const std::shared_ptr &ability); - void PrePerformScenceCreated(const std::shared_ptr &ability); - void PrePerformScenceRestored(const std::shared_ptr &ability); - void PrePerformScenceDestroyed(const std::shared_ptr &ability); - void PrePerformForeground(const std::shared_ptr &ability); - void PrePerformBackground(const std::shared_ptr &ability); - void PrePerformStop(const std::shared_ptr &ability); + void PostPerformStart(const std::shared_ptr &ability); + void PostPerformScenceCreated(const std::shared_ptr &ability); + void PostPerformScenceRestored(const std::shared_ptr &ability); + void PostPerformScenceDestroyed(const std::shared_ptr &ability); + void PostPerformForeground(const std::shared_ptr &ability); + void PostPerformBackground(const std::shared_ptr &ability); + void PostPerformStop(const std::shared_ptr &ability); -private: - AbilityDelegator::AbilityState ConvertAbilityState(const AbilityLifecycleExecutor::LifecycleState lifecycleState); - void ProcessAbilityProperties(const std::shared_ptr &ability); - sptr GetAbilityToken(const std::shared_ptr &ability); - std::optional DoesPropertyExist(const sptr &token); - void FinishUserTest(const int32_t resultCode); + void FinishUserTest(const std::string &msg, const int32_t resultCode); private: - static constexpr size_t FIRST_PROPERTY {0}; - static constexpr size_t SECOND_PROPERTY {1}; - static constexpr size_t THIRD_PROPERTY {2}; + AbilityDelegator::AbilityState ConvertAbilityState(const AbilityLifecycleExecutor::LifecycleState lifecycleState); + void ProcessAbilityProperties(const std::shared_ptr &ability); + std::shared_ptr DoesPropertyExist(const sptr &token); private: - sptr mainThread_; + std::shared_ptr appContext_; std::unique_ptr testRunner_; + sptr observer_; + std::unique_ptr delegatorThread_; - list_ability_property abilityProperties_; + std::list> abilityProperties_; std::vector> abilityMonitors_; - std::shared_ptr appContext_; - sptr observer_; std::mutex mutexMonitor_; std::mutex mutexAbilityProperties_; diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_infos.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_infos.h new file mode 100644 index 00000000000..f7f69cc39f5 --- /dev/null +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_infos.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 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 FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_INFOS_H +#define FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_INFOS_H + +#include +#include "ability_lifecycle_executor.h" +#include "iremote_object.h" + +namespace OHOS { +namespace AppExecFwk { +struct ADelegatorAbilityProperty { + sptr token_; + std::string name_; + AbilityLifecycleExecutor::LifecycleState lifecycleState_ {AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED}; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_INFOS_H diff --git a/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h b/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h index 00a01e0dea9..337ab360567 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h @@ -17,14 +17,11 @@ #define FOUNDATION_APPEXECFWK_OHOS_IABILITY_MONITORE_H #include -#include #include #include #include -#include -#include "ability.h" -#include "want.h" +#include "ability_delegator_infos.h" namespace OHOS { namespace AppExecFwk { @@ -36,10 +33,10 @@ public: explicit IAbilityMonitor(const std::string &abilityName); virtual ~IAbilityMonitor() = default; - virtual bool Match(const std::shared_ptr &ability, const Want &want); + virtual bool Match(const std::shared_ptr &ability, bool isNotify = false); - virtual std::shared_ptr waitForAbility(); - virtual std::shared_ptr waitForAbility(const int64_t timeoutMs); + virtual std::shared_ptr waitForAbility(); + virtual std::shared_ptr waitForAbility(const int64_t timeoutMs); virtual void OnAbilityStart(); virtual void OnAbilityForeground(); @@ -52,7 +49,7 @@ public: private: std::string abilityName_; - std::shared_ptr matchedAbility_; + std::shared_ptr matchedAbility_; std::condition_variable cvMatch_; std::mutex mMatch_; diff --git a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp index 471cda75eba..81bd3b47ed2 100644 --- a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp +++ b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp @@ -23,67 +23,12 @@ namespace OHOS { namespace AppExecFwk { -AbilityDelegator::AbilityDelegator(const sptr &mainThread, std::unique_ptr runner, - const sptr &observer) - : mainThread_(mainThread), testRunner_(std::move(runner)), observer_(observer) +AbilityDelegator::AbilityDelegator(const std::shared_ptr &context, + std::unique_ptr runner, const sptr &observer) + : appContext_(context), testRunner_(std::move(runner)), observer_(observer) {} AbilityDelegator::~AbilityDelegator() -{ - if (mainThread_) { - auto app = mainThread_->GetApplication(); - if (app) { - app->UnregisterAbilityLifecycleCallbacks(shared_from_this()); - } - } -} - -void AbilityDelegator::Init() -{ - APP_LOGI("Enter"); - - if (!mainThread_) { - APP_LOGE("Invalid mainThread"); - return; - } - - auto app = mainThread_->GetApplication(); - if (!app) { - APP_LOGE("Invalid application"); - return; - } - - appContext_ = app->GetAppContext(); - app->RegisterAbilityLifecycleCallbacks(shared_from_this()); -} - -void AbilityDelegator::OnAbilityStart(const std::shared_ptr &ability) -{ - ProcessAbilityProperties(ability); -} - -void AbilityDelegator::OnAbilityInactive(const std::shared_ptr &ability) -{} - -void AbilityDelegator::OnAbilityBackground(const std::shared_ptr &ability) -{ - ProcessAbilityProperties(ability); -} - -void AbilityDelegator::OnAbilityForeground(const std::shared_ptr &ability) -{ - ProcessAbilityProperties(ability); -} - -void AbilityDelegator::OnAbilityActive(const std::shared_ptr &ability) -{} - -void AbilityDelegator::OnAbilityStop(const std::shared_ptr &ability) -{ - ProcessAbilityProperties(ability); -} - -void AbilityDelegator::OnAbilitySaveState(const PacMap &outState) {} void AbilityDelegator::AddAbilityMonitor(const std::shared_ptr &monitor) @@ -144,7 +89,7 @@ sptr AbilityDelegator::WaitAbilityMonitor(const std::shared_ptrtoken_; } sptr AbilityDelegator::WaitAbilityMonitor( @@ -163,7 +108,7 @@ sptr AbilityDelegator::WaitAbilityMonitor( return {}; } - return GetAbilityToken(obtainedAbility); + return obtainedAbility->token_; } std::shared_ptr AbilityDelegator::GetAppContext() const @@ -185,7 +130,7 @@ AbilityDelegator::AbilityState AbilityDelegator::GetAbilityState(const sptr(existedProperty.value()); + return ConvertAbilityState(existedProperty->lifecycleState_); } sptr AbilityDelegator::GetCurrentTopAbility() @@ -249,8 +194,9 @@ bool AbilityDelegator::DoAbilityForeground(const sptr &token) return false; } - if (AAFwk::AbilityManagerClient::GetInstance()->DelegatorDoAbilityForeground(token)) { - APP_LOGE("Failed to call DelegatorDoAbilityForeground"); + auto ret = AAFwk::AbilityManagerClient::GetInstance()->DelegatorDoAbilityForeground(token); + if (ret) { + APP_LOGE("Failed to call DelegatorDoAbilityForeground, reson : %{public}d", ret); return false; } @@ -264,8 +210,9 @@ bool AbilityDelegator::DoAbilityBackground(const sptr &token) return false; } - if (AAFwk::AbilityManagerClient::GetInstance()->DelegatorDoAbilityBackground(token)) { - APP_LOGE("Failed to call DelegatorDoAbilityBackground"); + auto ret = AAFwk::AbilityManagerClient::GetInstance()->DelegatorDoAbilityBackground(token); + if (ret) { + APP_LOGE("Failed to call DelegatorDoAbilityBackground, reson : %{public}d", ret); return false; } @@ -293,6 +240,7 @@ std::unique_ptr AbilityDelegator::ExecuteShellCommand(const std: void AbilityDelegator::Print(const std::string &msg) { + APP_LOGI("message to print : %{public}s", msg.data()); auto testObserver = iface_cast(observer_); if (!testObserver) { APP_LOGW("Invalid testObserver"); @@ -302,35 +250,14 @@ void AbilityDelegator::Print(const std::string &msg) testObserver->TestStatus(msg, 0); } -void AbilityDelegator::PrePerformStart(const std::shared_ptr &ability) +void AbilityDelegator::PostPerformStart(const std::shared_ptr &ability) { if (!ability) { APP_LOGW("Invalid input parameter"); return; } - std::unique_lock lck(mutexMonitor_); - if (abilityMonitors_.empty()) { - APP_LOGW("Empty abilityMonitors"); - return; - } - - for (auto &monitor : abilityMonitors_) { - if (!monitor) { - continue; - } - - monitor->Match(ability, {}); - monitor->OnAbilityStart(); - } -} - -void AbilityDelegator::PostPerformStart(const std::shared_ptr &ability) -{ - if (!ability) { - APP_LOGW("Invalid input parameter"); - return; - } + ProcessAbilityProperties(ability); std::unique_lock lck(mutexMonitor_); if (abilityMonitors_.empty()) { @@ -343,17 +270,21 @@ void AbilityDelegator::PostPerformStart(const std::shared_ptr &ability) continue; } - monitor->Match(ability, {}); + if (monitor->Match(ability, true)) { + monitor->OnAbilityStart(); + } } } -void AbilityDelegator::PrePerformScenceCreated(const std::shared_ptr &ability) +void AbilityDelegator::PostPerformScenceCreated(const std::shared_ptr &ability) { if (!ability) { APP_LOGW("Invalid input parameter"); return; } + ProcessAbilityProperties(ability); + std::unique_lock lck(mutexMonitor_); if (abilityMonitors_.empty()) { APP_LOGW("Empty abilityMonitors"); @@ -365,18 +296,21 @@ void AbilityDelegator::PrePerformScenceCreated(const std::shared_ptr &a continue; } - monitor->Match(ability, {}); - monitor->OnWindowStageCreate(); + if (monitor->Match(ability)) { + monitor->OnWindowStageCreate(); + } } } -void AbilityDelegator::PrePerformScenceRestored(const std::shared_ptr &ability) +void AbilityDelegator::PostPerformScenceRestored(const std::shared_ptr &ability) { if (!ability) { APP_LOGW("Invalid input parameter"); return; } + ProcessAbilityProperties(ability); + std::unique_lock lck(mutexMonitor_); if (abilityMonitors_.empty()) { APP_LOGW("Empty abilityMonitors"); @@ -388,18 +322,21 @@ void AbilityDelegator::PrePerformScenceRestored(const std::shared_ptr & continue; } - monitor->Match(ability, {}); - monitor->OnWindowStageRestore(); + if (monitor->Match(ability)) { + monitor->OnWindowStageRestore(); + } } } -void AbilityDelegator::PrePerformScenceDestroyed(const std::shared_ptr &ability) +void AbilityDelegator::PostPerformScenceDestroyed(const std::shared_ptr &ability) { if (!ability) { APP_LOGW("Invalid input parameter"); return; } + ProcessAbilityProperties(ability); + std::unique_lock lck(mutexMonitor_); if (abilityMonitors_.empty()) { APP_LOGW("Empty abilityMonitors"); @@ -411,18 +348,21 @@ void AbilityDelegator::PrePerformScenceDestroyed(const std::shared_ptr continue; } - monitor->Match(ability, {}); - monitor->OnWindowStageDestroy(); + if (monitor->Match(ability)) { + monitor->OnWindowStageDestroy(); + } } } -void AbilityDelegator::PrePerformForeground(const std::shared_ptr &ability) +void AbilityDelegator::PostPerformForeground(const std::shared_ptr &ability) { if (!ability) { APP_LOGW("Invalid input parameter"); return; } + ProcessAbilityProperties(ability); + std::unique_lock lck(mutexMonitor_); if (abilityMonitors_.empty()) { APP_LOGW("Empty abilityMonitors"); @@ -434,18 +374,21 @@ void AbilityDelegator::PrePerformForeground(const std::shared_ptr &abil continue; } - monitor->Match(ability, {}); - monitor->OnAbilityForeground(); + if (monitor->Match(ability)) { + monitor->OnAbilityForeground(); + } } } -void AbilityDelegator::PrePerformBackground(const std::shared_ptr &ability) +void AbilityDelegator::PostPerformBackground(const std::shared_ptr &ability) { if (!ability) { APP_LOGW("Invalid input parameter"); return; } + ProcessAbilityProperties(ability); + std::unique_lock lck(mutexMonitor_); if (abilityMonitors_.empty()) { APP_LOGW("Empty abilityMonitors"); @@ -457,18 +400,21 @@ void AbilityDelegator::PrePerformBackground(const std::shared_ptr &abil continue; } - monitor->Match(ability, {}); - monitor->OnAbilityBackground(); + if (monitor->Match(ability)) { + monitor->OnAbilityBackground(); + } } } -void AbilityDelegator::PrePerformStop(const std::shared_ptr &ability) +void AbilityDelegator::PostPerformStop(const std::shared_ptr &ability) { if (!ability) { APP_LOGW("Invalid input parameter"); return; } + ProcessAbilityProperties(ability); + std::unique_lock lck(mutexMonitor_); if (abilityMonitors_.empty()) { APP_LOGW("Empty abilityMonitors"); @@ -480,8 +426,9 @@ void AbilityDelegator::PrePerformStop(const std::shared_ptr &ability) continue; } - monitor->Match(ability, {}); - monitor->OnAbilityStop(); + if (monitor->Match(ability)) { + monitor->OnAbilityStop(); + } } } @@ -510,75 +457,53 @@ AbilityDelegator::AbilityState AbilityDelegator::ConvertAbilityState( return abilityState; } -void AbilityDelegator::ProcessAbilityProperties(const std::shared_ptr &ability) +void AbilityDelegator::ProcessAbilityProperties(const std::shared_ptr &ability) { if (!ability) { - APP_LOGW("Invalid ability"); + APP_LOGW("Invalid ability property"); return; } - auto abilityToken = GetAbilityToken(ability); - if (!abilityToken) { - APP_LOGE("Invalid ability token"); - return; - } + APP_LOGW("ability property : name : %{public}s, state : %{public}d", + ability->name_.data(), ability->lifecycleState_); std::unique_lock lck(mutexAbilityProperties_); - auto existedProperty = DoesPropertyExist(abilityToken); + auto existedProperty = DoesPropertyExist(ability->token_); if (existedProperty) { - abilityProperties_.remove(existedProperty.value()); - } - - auto abilityState = ConvertAbilityState(ability->GetState()); - if (abilityState == AbilityDelegator::AbilityState::FOREGROUND) { - abilityProperties_.emplace_front(abilityToken, ability, abilityState); - } else { - abilityProperties_.emplace_back(abilityToken, ability, abilityState); - } -} - -sptr AbilityDelegator::GetAbilityToken(const std::shared_ptr &ability) -{ - if (!ability) { - APP_LOGW("Invalid ability"); - return {}; - } - - auto abilityContext = ability->GetAbilityContext(); - if (!abilityContext) { - APP_LOGE("Invalid ability context"); - return {}; + // update + existedProperty->lifecycleState_ = ability->lifecycleState_; + return; } - return abilityContext->GetToken(); + abilityProperties_.emplace_back(ability); } -std::optional AbilityDelegator::DoesPropertyExist(const sptr &token) +std::shared_ptr AbilityDelegator::DoesPropertyExist(const sptr &token) { if (!token) { APP_LOGW("Invalid input parameter"); - return std::nullopt; + return {}; } for (auto &it : abilityProperties_) { - auto tmpToken = std::get(it); - if (token == tmpToken) { + if (!it) { + APP_LOGW("Invalid ability property"); + continue; + } + + if (token == it->token_) { + APP_LOGI("Porperty exists"); return it; } } - return std::nullopt; + return {}; } -void AbilityDelegator::FinishUserTest(const int32_t resultCode) +void AbilityDelegator::FinishUserTest(const std::string &msg, const int32_t resultCode) { APP_LOGI("Enter"); - if (!mainThread_) { - APP_LOGE("Invalid mainThread"); - return; - } - if (!observer_) { APP_LOGE("Invalid observer"); return; @@ -591,8 +516,10 @@ void AbilityDelegator::FinishUserTest(const int32_t resultCode) } const auto &bundleName = delegatorArgs->GetTestBundleName(); - - mainThread_->FinishUserTest("UserTest finished", resultCode, bundleName, observer_); + auto err = AAFwk::AbilityManagerClient::GetInstance()->FinishUserTest(msg, resultCode, bundleName, observer_); + if (err) { + APP_LOGE("MainThread::FinishUserTest is failed %{public}d", err); + } } } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp b/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp index c592bcd1e6a..1e52a05eb80 100644 --- a/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp +++ b/frameworks/kits/appkit/native/ability_delegator/src/iability_monitor.cpp @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include "iability_monitor.h" +#include #include "app_log_wrapper.h" +#include "iability_monitor.h" using namespace std::chrono_literals; @@ -23,15 +23,15 @@ namespace AppExecFwk { IAbilityMonitor::IAbilityMonitor(const std::string &abilityName) : abilityName_(abilityName) {} -bool IAbilityMonitor::Match(const std::shared_ptr &ability, const Want &want) +bool IAbilityMonitor::Match(const std::shared_ptr &ability, bool isNotify) { - std::string aName; - if (ability) { - aName = ability->GetAbilityName(); - } else { - aName = want.GetElement().GetAbilityName(); + if (!ability) { + APP_LOGW("Invalid ability property"); + return false; } + const auto &aName = ability->name_; + if (abilityName_.empty() || aName.empty()) { APP_LOGW("Invalid name"); return false; @@ -42,25 +42,27 @@ bool IAbilityMonitor::Match(const std::shared_ptr &ability, const Want return false; } - if (ability) { + APP_LOGI("Matched : ability name : %{public}s, isNotify : %{public}s", + abilityName_.data(), (isNotify ? "true" : "false")); + + if (isNotify) { + APP_LOGI("Matched : notify ability matched"); { std::lock_guard matchLock(mMatch_); matchedAbility_ = ability; } cvMatch_.notify_one(); - - return true; } - return false; + return true; } -std::shared_ptr IAbilityMonitor::waitForAbility() +std::shared_ptr IAbilityMonitor::waitForAbility() { return waitForAbility(MAX_TIME_OUT); } -std::shared_ptr IAbilityMonitor::waitForAbility(const int64_t timeoutMs) +std::shared_ptr IAbilityMonitor::waitForAbility(const int64_t timeoutMs) { auto realTime = timeoutMs; if (timeoutMs <= 0) { diff --git a/frameworks/kits/appkit/native/ability_runtime/form_extension_context.cpp b/frameworks/kits/appkit/native/ability_runtime/form_extension_context.cpp index 7e8e1ae7a34..c6f080e518b 100644 --- a/frameworks/kits/appkit/native/ability_runtime/form_extension_context.cpp +++ b/frameworks/kits/appkit/native/ability_runtime/form_extension_context.cpp @@ -55,7 +55,7 @@ ErrCode FormExtensionContext::StartAbility(const AAFwk::Want &want) const ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, -1); HILOG_DEBUG("%{public}s. End calling StartAbility. ret=%{public}d", __func__, err); if (err != ERR_OK) { - HILOG_ERROR("FormExtensionContext::StartAbility is failed %{public}d", err); + HILOG_ERROR("ServiceContext::StartAbility is failed %{public}d", err); } return err; } @@ -66,7 +66,7 @@ ErrCode FormExtensionContext::StartAbility(const AAFwk::Want &want, const AAFwk: ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, startOptions, token_, -1); HILOG_DEBUG("%{public}s. End calling StartAbility. ret=%{public}d", __func__, err); if (err != ERR_OK) { - HILOG_ERROR("FormExtensionContext::StartAbility is failed %{public}d", err); + HILOG_ERROR("ServiceContext::StartAbility is failed %{public}d", err); } return err; } @@ -75,7 +75,7 @@ AppExecFwk::AbilityType FormExtensionContext::GetAbilityInfoType() const { std::shared_ptr info = GetAbilityInfo(); if (info == nullptr) { - HILOG_ERROR("FormExtensionContext::GetAbilityInfoType info == nullptr"); + HILOG_ERROR("ServiceContext::GetAbilityInfoType info == nullptr"); return AppExecFwk::AbilityType::UNKNOWN; } diff --git a/frameworks/kits/appkit/native/app/include/main_thread.h b/frameworks/kits/appkit/native/app/include/main_thread.h index 28e6e32b652..771d7c7aafd 100644 --- a/frameworks/kits/appkit/native/app/include/main_thread.h +++ b/frameworks/kits/appkit/native/app/include/main_thread.h @@ -217,18 +217,6 @@ public: void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override; - /** - * @brief Finish user test. - * @param msg user test message. - * @param resultCode user test result Code. - * @param bundleName user test bundleName. - * @param observer test observer callback. - * - * @return Returns ERR_OK on success, others on failure. - */ - int FinishUserTest(const std::string &msg, const int &resultCode, - const std::string &bundleName, const sptr &observer); - private: /** * @@ -392,10 +380,8 @@ private: * * @brief Task in event handler timeout detected. * - * @param runner the runner belong to the mainthread. - * */ - void TaskTimeoutDetected(const std::shared_ptr& runner); + void TaskTimeoutDetected(); /** * diff --git a/frameworks/kits/appkit/native/app/src/main_thread.cpp b/frameworks/kits/appkit/native/app/src/main_thread.cpp index 9e9c7569465..7db6e964a8c 100644 --- a/frameworks/kits/appkit/native/app/src/main_thread.cpp +++ b/frameworks/kits/appkit/native/app/src/main_thread.cpp @@ -834,6 +834,13 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con return; } + // create contextImpl + std::shared_ptr contextImpl = std::make_shared(); + contextImpl->SetResourceManager(resourceManager); + contextImpl->SetApplicationInfo(std::make_shared(appInfo)); + contextImpl->InitAppContext(); + application_->SetApplicationContext(contextImpl); + bool moduelJson = false; bool isStageBased = false; if (!bundleInfo.hapModuleInfos.empty()) { @@ -883,13 +890,6 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con application_->SetAbilityRecordMgr(abilityRecordMgr_); application_->SetConfiguration(config); - // create contextImpl - std::shared_ptr contextImpl = std::make_shared(); - contextImpl->SetResourceManager(resourceManager); - contextImpl->SetApplicationInfo(std::make_shared(appInfo)); - contextImpl->InitAppContext(); - application_->SetApplicationContext(contextImpl); - applicationImpl_->SetRecordId(appLaunchData.GetRecordId()); applicationImpl_->SetApplication(application_); mainThreadState_ = MainThreadState::READY; @@ -962,30 +962,18 @@ bool MainThread::AbilityDelegatorPrepare(const UserTestRecord &record) return false; } - auto delegator = std::make_shared(this, std::move(testRunner), record.observer); + auto delegator = std::make_shared( + application_->GetAppContext(), std::move(testRunner), record.observer); if (!delegator) { APP_LOGE("delegator is null"); return false; } - delegator->Init(); AbilityDelegatorRegistry::RegisterInstance(delegator, args); delegator->Prepare(); return true; } -int MainThread::FinishUserTest(const std::string &msg, const int &resultCode, - const std::string &bundleName, const sptr &observer) -{ - APP_LOGI("MainThread::FinishUserTest"); - ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->FinishUserTest( - msg, resultCode, bundleName, observer); - if (err != ERR_OK) { - APP_LOGE("MainThread::FinishUserTest is failed %{public}d", err); - } - return ERR_OK; -} - /** * * @brief launch the ability. @@ -1294,7 +1282,7 @@ void MainThread::HandleConfigurationUpdated(const Configuration &config) APP_LOGI("MainThread::HandleConfigurationUpdated called end."); } -void MainThread::TaskTimeoutDetected(const std::shared_ptr &runner) +void MainThread::TaskTimeoutDetected() { BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); APP_LOGI("MainThread::TaskTimeoutDetected called start."); @@ -1303,14 +1291,14 @@ void MainThread::TaskTimeoutDetected(const std::shared_ptr &runner) APP_LOGI("MainThread::TaskTimeoutDetected delivery timeout"); }; auto distributeTimeoutCallback = []() { - APP_LOGI("MainThread::TaskTimeoutDetected distribute timeout"); + APP_LOGI("MainThread::TaskTimeoutDetected delivery timeout"); }; - if (runner !=nullptr && mainHandler_ != nullptr) { - runner->SetDeliveryTimeout(DELIVERY_TIME); + if (mainHandler_ != nullptr) { + mainHandler_->SetDeliveryTimeout(DELIVERY_TIME); mainHandler_->SetDeliveryTimeoutCallback(deliveryTimeoutCallback); - runner->SetDistributeTimeout(DISTRIBUTE_TIME); + mainHandler_->SetDistributeTimeout(DISTRIBUTE_TIME); mainHandler_->SetDistributeTimeoutCallback(distributeTimeoutCallback); } APP_LOGI("MainThread::TaskTimeoutDetected called end."); @@ -1341,7 +1329,7 @@ void MainThread::Init(const std::shared_ptr &runner, const std::sha if (!watchDogHandler_->PostTask(taskWatchDog)) { APP_LOGE("MainThread::Init WatchDog postTask task failed"); } - TaskTimeoutDetected(runner); + TaskTimeoutDetected(); /* watchDogHandler_->Init(mainHandler_, watchDogHandler_); APP_LOGI("MainThread:Init before CreateRunner."); diff --git a/frameworks/kits/appkit/native/test/unittest/context_container_test.cpp b/frameworks/kits/appkit/native/test/unittest/context_container_test.cpp index fa9e66f1355..c9a1cda312b 100644 --- a/frameworks/kits/appkit/native/test/unittest/context_container_test.cpp +++ b/frameworks/kits/appkit/native/test/unittest/context_container_test.cpp @@ -45,27 +45,25 @@ public: }; void ContextContainerTest::SetUpTestCase(void) -{ - OHOS::DelayedSingleton::GetInstance()->RegisterSystemAbility( - OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService()); -} +{} void ContextContainerTest::TearDownTestCase(void) -{ - OHOS::DelayedSingleton::DestroyInstance(); -} +{} void ContextContainerTest::SetUp(void) { + OHOS::sptr bundleObject = new (std::nothrow) BundleMgrService(); + + OHOS::DelayedSingleton::GetInstance()->RegisterSystemAbility( + OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject); + OHOS::DelayedSingleton::GetInstance()->RegisterSystemAbility( + OHOS::ABILITY_MGR_SERVICE_ID, bundleObject); context_ = std::make_shared(); contextDeal_ = std::make_shared(); } void ContextContainerTest::TearDown(void) -{ - context_ = nullptr; - contextDeal_ = nullptr; -} +{} /** * @tc.number: AppExecFwk_ContextContainer_GetBundleName_0100 diff --git a/frameworks/kits/appkit/test/Mock/include/mock_ability_mgr_service.h b/frameworks/kits/appkit/test/Mock/include/mock_ability_mgr_service.h index c776ffb53d1..f53ce738e03 100644 --- a/frameworks/kits/appkit/test/Mock/include/mock_ability_mgr_service.h +++ b/frameworks/kits/appkit/test/Mock/include/mock_ability_mgr_service.h @@ -73,7 +73,6 @@ public: MOCK_METHOD1(CleanMission, int(int32_t missionId)); MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); - MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector &info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector &info)); @@ -109,6 +108,7 @@ private: bool DumpStateCalled_ = false; Semaphore sem_; }; + } // namespace AAFwk } // namespace OHOS #endif // FOUNDATION_APPEXECFWK_KITS_APPKIT_TEST_MOCK_ABILITY_MGR_SERVICE_H \ No newline at end of file diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp index 2453de0f445..8b0488a35eb 100644 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp @@ -67,7 +67,6 @@ const std::string Want::MIME_TYPE("mime-type"); const std::string Want::WANT_HEADER("#Intent;"); const std::string Want::PARAM_RESV_WINDOW_MODE("ohos.aafwk.param.windowMode"); -const std::string Want::PARAM_RESV_DISPLAY_ID("ohos.aafwk.param.displayId"); const std::string Want::PARAM_RESV_CALLER_TOKEN("ohos.aafwk.param.callerToken"); const std::string Want::PARAM_RESV_CALLER_UID("ohos.aafwk.param.callerUid"); const std::string Want::PARAM_RESV_CALLER_PID("ohos.aafwk.param.callerPid"); diff --git a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h index d44cbd503d6..08e6ee1ace6 100644 --- a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h @@ -114,7 +114,7 @@ public: MOCK_METHOD1(SetMissionStackSetting, int(const StackSetting &stackSetting)); MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id)); MOCK_METHOD3(StartContinuation, int(const Want &want, const sptr &abilityToken, int32_t status)); - MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, const int32_t result)); MOCK_METHOD5(ContinueMission, int(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams)); MOCK_METHOD2(ContinueAbility, int(const std::string &deviceId, int32_t missionId)); @@ -130,7 +130,6 @@ public: MOCK_METHOD1(CleanMission, int(int32_t missionId)); MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); - MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); MOCK_METHOD2(SetMissionLabel, int(const sptr &token, const std::string &label)); MOCK_METHOD2(GetWantSenderInfo, int(const sptr &target, std::shared_ptr &info)); diff --git a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h index 32f421dde29..cca6d5b4c93 100644 --- a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h @@ -113,7 +113,7 @@ public: MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id)); MOCK_METHOD1(GetSystemMemoryAttr, void(AppExecFwk::SystemMemoryAttr &memoryInfo)); MOCK_METHOD3(StartContinuation, int(const Want &want, const sptr &abilityToken, int32_t status)); - MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, const int32_t result)); MOCK_METHOD5(ContinueMission, int(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams)); MOCK_METHOD2(ContinueAbility, int(const std::string &deviceId, int32_t missionId)); @@ -129,7 +129,6 @@ public: MOCK_METHOD1(CleanMission, int(int32_t missionId)); MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); - MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); MOCK_METHOD2(SetMissionLabel, int(const sptr &token, const std::string &label)); MOCK_METHOD2(GetWantSenderInfo, int(const sptr &target, std::shared_ptr &info)); diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_client.h b/interfaces/innerkits/ability_manager/include/ability_manager_client.h index a1276abb217..2fb59725614 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_client.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_client.h @@ -609,13 +609,11 @@ public: /** * @brief Move a mission to front. * @param missionId Id of target mission. - * @param startOptions Special startOptions for target mission. * * @return Returns ERR_OK on success, others on failure. */ ErrCode MoveMissionToFront(int32_t missionId); - ErrCode MoveMissionToFront(int32_t missionId, const StartOptions &startOptions); - + /** * Start Ability, connect session with common ability. * @@ -751,16 +749,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ ErrCode DoAbilityBackground(const sptr &token, uint32_t flag); - - /** - * Set ability controller. - * - * @param abilityController, The ability controller. - * @return Returns ERR_OK on success, others on failure. - */ - virtual int SetAbilityController(const sptr &abilityController, - bool imAStabilityTest); - + private: static std::mutex mutex_; static std::shared_ptr instance_; diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h index f38d68f96f9..b741244ada4 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h @@ -544,7 +544,7 @@ public: virtual void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess) = 0; - virtual int NotifyContinuationResult(int32_t missionId, int32_t result) = 0; + virtual int NotifyContinuationResult(int32_t missionId, const int32_t result) = 0; virtual int LockMissionForCleanup(int32_t missionId) = 0; @@ -566,9 +566,7 @@ public: virtual int CleanAllMissions() = 0; virtual int MoveMissionToFront(int32_t missionId) = 0; - - virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) = 0; - + /** * Start Ability, connect session with common ability. * @@ -671,7 +669,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int DelegatorDoAbilityBackground(const sptr &token) = 0; - + /** * Calls this interface to move the ability to the foreground. * @@ -863,9 +861,6 @@ public: // ipc id for ability background (55) DO_ABILITY_BACKGROUND, - // ipc id for move mission to front by options (56) - MOVE_MISSION_TO_FRONT_BY_OPTIONS, - // ipc id 1001-2000 for DMS // ipc id for starting ability (1001) START_ABILITY = 1001, diff --git a/interfaces/innerkits/ability_manager/include/ability_scheduler_interface.h b/interfaces/innerkits/ability_manager/include/ability_scheduler_interface.h index c56581a4cf5..42db89b9854 100644 --- a/interfaces/innerkits/ability_manager/include/ability_scheduler_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_scheduler_interface.h @@ -273,9 +273,9 @@ public: virtual std::vector> ExecuteBatch( const std::vector> &operations) = 0; virtual void ContinueAbility(const std::string& deviceId) = 0; - virtual void NotifyContinuationResult(int32_t result) = 0; + virtual void NotifyContinuationResult(const int32_t result) = 0; - virtual void DumpAbilityInfo(const std::vector ¶ms, std::vector &info) = 0; + virtual void DumpAbilityInfo(std::vector& info) = 0; virtual sptr CallRequest() = 0; diff --git a/interfaces/innerkits/ability_manager/include/start_options.h b/interfaces/innerkits/ability_manager/include/start_options.h index df20f768bc0..82fe7cd47f7 100644 --- a/interfaces/innerkits/ability_manager/include/start_options.h +++ b/interfaces/innerkits/ability_manager/include/start_options.h @@ -22,15 +22,11 @@ #include "parcel.h" namespace OHOS { namespace AAFwk { -class StartOptions final : public Parcelable, public std::enable_shared_from_this { +class StartOptions : public Parcelable { public: + static const std::string STRING_DISPLAY_ID; const int32_t DEFAULT_DISPLAY_ID {0}; - StartOptions() = default; - ~StartOptions() = default; - StartOptions(const StartOptions &other); - StartOptions &operator=(const StartOptions &other); - bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; static StartOptions *Unmarshalling(Parcel &parcel); diff --git a/interfaces/innerkits/want/include/ohos/aafwk/content/want.h b/interfaces/innerkits/want/include/ohos/aafwk/content/want.h index 8cbea1e7b33..1c571636cbb 100644 --- a/interfaces/innerkits/want/include/ohos/aafwk/content/want.h +++ b/interfaces/innerkits/want/include/ohos/aafwk/content/want.h @@ -789,7 +789,6 @@ public: // reserved param definition static const std::string PARAM_RESV_WINDOW_MODE; - static const std::string PARAM_RESV_DISPLAY_ID; static const std::string PARAM_RESV_CALLER_TOKEN; static const std::string PARAM_RESV_CALLER_UID; static const std::string PARAM_RESV_CALLER_PID; diff --git a/interfaces/kits/js/@ohos.ability.particleAbility.d.ts b/interfaces/kits/js/@ohos.ability.particleAbility.d.ts index a6db3d53a1c..44e794c32b5 100644 --- a/interfaces/kits/js/@ohos.ability.particleAbility.d.ts +++ b/interfaces/kits/js/@ohos.ability.particleAbility.d.ts @@ -16,7 +16,6 @@ import { AsyncCallback } from './basic'; import { StartAbilityParameter } from './ability/startAbilityParameter'; import { Want } from './ability/want'; import { ConnectOptions } from './ability/connectOptions'; -import { NotificationRequest } from './notification/notificationRequest'; /** * A Particle Ability represents an ability with service. @@ -61,30 +60,5 @@ declare namespace particleAbility { */ function disconnectAbility(connection: number, callback:AsyncCallback): void; function disconnectAbility(connection: number): Promise; - - /** - * Keep this Service ability in the background and display a notification bar. - * - * @since 7 - * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask - * @permission ohos.permission.KEEP_BACKGROUND_RUNNING - * @param id Identifies the notification bar information. - * @param request Indicates the notificationRequest instance containing information for displaying a notification bar. - * @FAModelOnly - * @deprecated - */ - function startBackgroundRunning(id: number, request: NotificationRequest, callback: AsyncCallback): void; - function startBackgroundRunning(id: number, request: NotificationRequest): Promise; - - /** - * Cancel background running of this ability to free up system memory. - * - * @since 7 - * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask - * @FAModelOnly - * @deprecated - */ - function cancelBackgroundRunning(callback: AsyncCallback): void; - function cancelBackgroundRunning(): Promise; } export default particleAbility; \ No newline at end of file diff --git a/interfaces/kits/napi/aafwk/ability_context/ability_context.js b/interfaces/kits/napi/aafwk/ability_context/ability_context.js index 0be12bee92f..c053519cd7c 100755 --- a/interfaces/kits/napi/aafwk/ability_context/ability_context.js +++ b/interfaces/kits/napi/aafwk/ability_context/ability_context.js @@ -52,12 +52,12 @@ class AbilityContext extends Context { } } - startAbilityForResult(want, options, callback) { - return this.__context_impl__.startAbilityForResult(want, options, callback) + startAbilityForResult(want, callback) { + return this.__context_impl__.startAbilityForResult(want, callback) } - startAbilityForResultWithAccount(want, accountId, options, callback) { - return this.__context_impl__.startAbilityForResultWithAccount(want, accountId, options, callback) + startAbilityForResultWithAccount(want, accountId, callback) { + return this.__context_impl__.startAbilityForResultWithAccount(want, accountId, callback) } connectAbility(want, options) { diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/BUILD.gn b/interfaces/kits/napi/aafwk/app/ability_delegator/BUILD.gn index da7a4cbcaaf..06853c2562b 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/BUILD.gn +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/BUILD.gn @@ -36,7 +36,7 @@ ohos_shared_library("abilitydelegatorregistry") { deps = [ "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", - "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", + "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_delegator", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/base:base", ] diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.cpp b/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.cpp index 600f104ba57..bc8f2cdb097 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.cpp +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.cpp @@ -22,11 +22,11 @@ namespace OHOS { namespace AbilityDelegatorJs { using namespace OHOS::AbilityRuntime; -AbilityMonitor::AbilityMonitor(const std::string &name, JSAbilityMonitor *jsAbilityMonitor) +AbilityMonitor::AbilityMonitor(const std::string &name, const std::shared_ptr &jsAbilityMonitor) : IAbilityMonitor(name), jsMonitor_(jsAbilityMonitor) {} -void AbilityMonitor::onAbilityStart() +void AbilityMonitor::OnAbilityStart() { HILOG_INFO("onAbilityCreate is called"); @@ -39,7 +39,7 @@ void AbilityMonitor::onAbilityStart() HILOG_INFO("onAbilityCreate is called end"); } -void AbilityMonitor::onAbilityForeground() +void AbilityMonitor::OnAbilityForeground() { HILOG_INFO("onAbilityForeground is called"); @@ -52,7 +52,7 @@ void AbilityMonitor::onAbilityForeground() HILOG_INFO("onAbilityForeground is called end"); } -void AbilityMonitor::onAbilityBackground() +void AbilityMonitor::OnAbilityBackground() { HILOG_INFO("onAbilityBackground is called"); @@ -65,7 +65,7 @@ void AbilityMonitor::onAbilityBackground() HILOG_INFO("onAbilityBackground is called end"); } -void AbilityMonitor::onAbilityStop() +void AbilityMonitor::OnAbilityStop() { HILOG_INFO("onAbilityDestroy is called"); @@ -78,7 +78,7 @@ void AbilityMonitor::onAbilityStop() HILOG_INFO("onAbilityDestroy is called end"); } -void AbilityMonitor::onWindowStageCreate() +void AbilityMonitor::OnWindowStageCreate() { HILOG_INFO("onWindowStageCreate is called"); @@ -91,7 +91,7 @@ void AbilityMonitor::onWindowStageCreate() HILOG_INFO("onWindowStageCreate is called end"); } -void AbilityMonitor::onWindowStageRestore() +void AbilityMonitor::OnWindowStageRestore() { HILOG_INFO("onWindowStageRestore is called"); @@ -104,7 +104,7 @@ void AbilityMonitor::onWindowStageRestore() HILOG_INFO("onWindowStageRestore is called end"); } -void AbilityMonitor::onWindowStageDestroy() +void AbilityMonitor::OnWindowStageDestroy() { HILOG_INFO("onWindowStageDestroy is called"); diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.h b/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.h index 1f00888d0e3..dd89eb0340d 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.h +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.h @@ -27,19 +27,18 @@ class NativeValue; namespace OHOS { namespace AbilityDelegatorJs { using namespace OHOS::AppExecFwk; -using Function = void(*)(); class AbilityMonitor : public IAbilityMonitor { public: - AbilityMonitor(const std::string &name, JSAbilityMonitor *jsAbilityMonitor); + AbilityMonitor(const std::string &name, const std::shared_ptr &jsAbilityMonitor); ~AbilityMonitor() = default; - void onAbilityStart(); - void onAbilityForeground(); - void onAbilityBackground(); - void onAbilityStop(); - void onWindowStageCreate(); - void onWindowStageRestore(); - void onWindowStageDestroy(); + void OnAbilityStart() override; + void OnAbilityForeground() override; + void OnAbilityBackground() override; + void OnAbilityStop() override; + void OnWindowStageCreate() override; + void OnWindowStageRestore() override; + void OnWindowStageDestroy() override; private: std::shared_ptr jsMonitor_; diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp index f7da618ea3c..9fbe7702c9a 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp @@ -29,7 +29,6 @@ namespace AbilityDelegatorJs { constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; constexpr size_t ARGC_THREE = 3; -constexpr size_t ARGC_FOUR = 4; constexpr size_t INDEX_ZERO = 0; constexpr size_t INDEX_ONE = 1; constexpr size_t INDEX_TWO = 2; @@ -104,11 +103,17 @@ NativeValue *JSAbilityDelegator::ExecuteShellCommand(NativeEngine *engine, Nativ return (me != nullptr) ? me->OnExecuteShellCommand(*engine, *info) : nullptr; } +NativeValue *JSAbilityDelegator::FinishTest(NativeEngine *engine, NativeCallbackInfo *info) +{ + JSAbilityDelegator *me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnFinishTest(*engine, *info) : nullptr; +} + NativeValue *JSAbilityDelegator::OnAddAbilityMonitor(NativeEngine &engine, NativeCallbackInfo &info) { HILOG_INFO("OnAddAbilityMonitor is called, argc = %{public}d", static_cast(info.argc)); - if (info.argc < ARGC_ONE || info.argc > ARGC_TWO) { + if (info.argc < ARGC_ONE) { HILOG_ERROR("Incorrect number of parameters"); return engine.CreateUndefined(); } @@ -134,7 +139,7 @@ NativeValue *JSAbilityDelegator::OnRemoveAbilityMonitor(NativeEngine &engine, Na { HILOG_INFO("OnRemoveAbilityMonitor is called, argc = %{public}d", static_cast(info.argc)); - if (info.argc < ARGC_ONE || info.argc > ARGC_TWO) { + if (info.argc < ARGC_ONE) { HILOG_ERROR("Incorrect number of parameters"); return engine.CreateUndefined(); } @@ -170,7 +175,7 @@ NativeValue *JSAbilityDelegator::OnWaitAbilityMonitor(NativeEngine &engine, Nati { HILOG_INFO("OnWaitAbilityMonitor is called, argc = %{public}d", static_cast(info.argc)); - if (info.argc < ARGC_ONE || info.argc > ARGC_THREE) { + if (info.argc < ARGC_ONE) { HILOG_ERROR("Incorrect number of parameters"); return engine.CreateUndefined(); } @@ -221,7 +226,7 @@ NativeValue *JSAbilityDelegator::OnPrint(NativeEngine &engine, NativeCallbackInf { HILOG_INFO("OnPrint is called, argc = %{public}d", static_cast(info.argc)); - if (info.argc < ARGC_ONE || info.argc > ARGC_TWO) { + if (info.argc < ARGC_ONE) { HILOG_ERROR("Incorrect number of parameters"); return engine.CreateUndefined(); } @@ -248,7 +253,7 @@ NativeValue *JSAbilityDelegator::OnExecuteShellCommand(NativeEngine &engine, Nat { HILOG_INFO("OnExecuteShellCommand is called, argc = %{public}d", static_cast(info.argc)); - if (info.argc < ARGC_ONE || info.argc > ARGC_FOUR) { + if (info.argc < ARGC_ONE) { HILOG_ERROR("Incorrect number of parameters"); return engine.CreateUndefined(); } @@ -285,11 +290,6 @@ NativeValue *JSAbilityDelegator::OnGetAppContext(NativeEngine &engine, NativeCal { HILOG_INFO("OnGetAppContext is called, argc = %{public}d", static_cast(info.argc)); - if (info.argc > ARGC_ONE) { - HILOG_ERROR("Incorrect number of parameters"); - return engine.CreateUndefined(); - } - AsyncTask::CompleteCallback complete = [](NativeEngine &engine, AsyncTask &task, int32_t status) { HILOG_INFO("OnGetAppContext AsyncTask is called"); std::shared_ptr context = @@ -307,7 +307,7 @@ NativeValue *JSAbilityDelegator::OnGetAbilityState(NativeEngine &engine, NativeC { HILOG_INFO("OnGetAbilityState is called, argc = %{public}d", static_cast(info.argc)); - if (info.argc < ARGC_ONE || info.argc > ARGC_TWO) { + if (info.argc < ARGC_ONE) { HILOG_ERROR("Incorrect number of parameters"); return engine.CreateUndefined(); } @@ -334,11 +334,6 @@ NativeValue *JSAbilityDelegator::OnGetCurrentTopAbility(NativeEngine &engine, Na { HILOG_INFO("OnGetCurrentTopAbility is called, argc = %{public}d", static_cast(info.argc)); - if (info.argc > ARGC_ONE) { - HILOG_ERROR("Incorrect number of parameters"); - return engine.CreateUndefined(); - } - AsyncTask::CompleteCallback complete = [this](NativeEngine &engine, AsyncTask &task, int32_t status) { HILOG_INFO("OnGetCurrentTopAbility AsyncTask is called"); sptr remoteObject = @@ -356,7 +351,7 @@ NativeValue *JSAbilityDelegator::OnDoAbilityForeground(NativeEngine &engine, Nat { HILOG_INFO("OnDoAbilityForeground is called, argc = %{public}d", static_cast(info.argc)); - if (info.argc < ARGC_ONE || info.argc > ARGC_TWO) { + if (info.argc < ARGC_ONE) { HILOG_ERROR("Incorrect number of parameters"); return engine.CreateUndefined(); } @@ -382,7 +377,7 @@ NativeValue *JSAbilityDelegator::OnDoAbilityBackground(NativeEngine &engine, Nat { HILOG_INFO("OnDoAbilityBackground is called, argc = %{public}d", static_cast(info.argc)); - if (info.argc < ARGC_ONE || info.argc > ARGC_TWO) { + if (info.argc < ARGC_ONE) { HILOG_ERROR("Incorrect number of parameters"); return engine.CreateUndefined(); } @@ -404,6 +399,38 @@ NativeValue *JSAbilityDelegator::OnDoAbilityBackground(NativeEngine &engine, Nat return result; } +NativeValue *JSAbilityDelegator::OnFinishTest(NativeEngine &engine, NativeCallbackInfo &info) +{ + HILOG_INFO("OnFinishTest is called, argc = %{public}d", static_cast(info.argc)); + + if (info.argc < ARGC_TWO) { + HILOG_ERROR("Incorrect number of parameters"); + return engine.CreateUndefined(); + } + + std::string msg; + int64_t code = 0; + if (!ConvertFromJsValue(engine, info.argv[INDEX_ZERO], msg)) { + HILOG_ERROR("Parse para failed"); + return engine.CreateUndefined(); + } + + if (!ConvertFromJsValue(engine, info.argv[INDEX_ONE], code)) { + HILOG_ERROR("Parse para argv[1] failed"); + return engine.CreateUndefined(); + } + + AsyncTask::CompleteCallback complete = [msg, code](NativeEngine &engine, AsyncTask &task, int32_t status) { + HILOG_INFO("OnFinishTest AsyncTask is called"); + AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator()->FinishUserTest(msg, code); + task.Resolve(engine, engine.CreateUndefined()); + }; + NativeValue *lastParam = (info.argc == ARGC_THREE) ? info.argv[INDEX_TWO] : nullptr; + NativeValue *result = nullptr; + AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + NativeValue *JSAbilityDelegator::ParseJSMonitorPara( NativeEngine &engine, NativeValue *value, std::shared_ptr &monitor) { @@ -436,7 +463,7 @@ NativeValue *JSAbilityDelegator::ParseJSMonitorPara( abilityMonitor->SetJsAbilityMonitorEnv(&engine); abilityMonitor->SetJsAbilityMonitor(value); - monitor = std::make_shared(abilityName, abilityMonitor.get()); + monitor = std::make_shared(abilityName, abilityMonitor); if (!monitor) { HILOG_INFO("Failed to create monitor"); return nullptr; @@ -444,7 +471,7 @@ NativeValue *JSAbilityDelegator::ParseJSMonitorPara( std::shared_ptr refence = nullptr; refence.reset(engine.CreateReference(value, 1)); - monitorRecord[refence] = monitor; + monitorRecord.emplace(refence, monitor); return engine.CreateNull(); } diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h index 4ad09f07960..06342d72ec8 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h @@ -39,6 +39,7 @@ public: static NativeValue *GetCurrentTopAbility(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue *DoAbilityForeground(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue *DoAbilityBackground(NativeEngine *engine, NativeCallbackInfo *info); + static NativeValue *FinishTest(NativeEngine *engine, NativeCallbackInfo *info); private: NativeValue *OnAddAbilityMonitor(NativeEngine &engine, NativeCallbackInfo &info); @@ -51,6 +52,7 @@ private: NativeValue *OnGetCurrentTopAbility(NativeEngine &engine, NativeCallbackInfo &info); NativeValue *OnDoAbilityForeground(NativeEngine &engine, NativeCallbackInfo &info); NativeValue *OnDoAbilityBackground(NativeEngine &engine, NativeCallbackInfo &info); + NativeValue *OnFinishTest(NativeEngine &engine, NativeCallbackInfo &info); private: NativeValue *CreateJsAbilityObject(NativeEngine &engine, const sptr &remoteObject); diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.cpp b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.cpp index 9dfcbef1e0a..41b4d16025b 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.cpp +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.cpp @@ -28,7 +28,6 @@ using namespace OHOS::AppExecFwk; using namespace OHOS::AbilityRuntime; namespace { constexpr int32_t ARGC_ONE = 1; - class JsAbilityDelegatorRegistry { public: JsAbilityDelegatorRegistry() = default; @@ -55,16 +54,12 @@ public: private: NativeValue *OnGetAbilityDelegator(NativeEngine &engine, NativeCallbackInfo &info) { - HILOG_INFO("%{public}s is called", __FUNCTION__); - if (info.argc > ARGC_ONE) { - HILOG_ERROR("Params not match"); - return engine.CreateUndefined(); - } + HILOG_INFO("OnGetAbilityDelegator is called, argc = %{public}d", static_cast(info.argc)); AsyncTask::CompleteCallback complete = [](NativeEngine &engine, AsyncTask &task, int32_t status) { + HILOG_INFO("OnGetAbilityDelegator AsyncTask::CompleteCallback"); task.Resolve(engine, CreateJsAbilityDelegator(engine)); }; - NativeValue *lastParam = (info.argc == ARGC_ONE) ? info.argv[0] : nullptr; NativeValue *result = nullptr; AsyncTask::Schedule( @@ -74,11 +69,7 @@ private: NativeValue *OnGetArguments(NativeEngine &engine, NativeCallbackInfo &info) { - HILOG_INFO("%{public}s is called", __FUNCTION__); - if (info.argc > ARGC_ONE) { - HILOG_ERROR("Params not match"); - return engine.CreateUndefined(); - } + HILOG_INFO("OnGetArguments is called, argc = %{public}d", static_cast(info.argc)); AsyncTask::CompleteCallback complete = [](NativeEngine &engine, AsyncTask &task, int32_t status) { std::shared_ptr abilityDelegatorArgs = diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_utils.cpp b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_utils.cpp index 9af710d8deb..9407cbf5759 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_utils.cpp +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_utils.cpp @@ -48,29 +48,25 @@ NativeValue *CreateJsAbilityDelegator(NativeEngine &engine) BindNativeFunction(engine, *object, "doAbilityBackground", JSAbilityDelegator::DoAbilityBackground); BindNativeFunction(engine, *object, "print", JSAbilityDelegator::Print); BindNativeFunction(engine, *object, "executeShellCommand", JSAbilityDelegator::ExecuteShellCommand); + BindNativeFunction(engine, *object, "finishTest", JSAbilityDelegator::FinishTest); return objValue; } -napi_value WrapStringToJS(napi_env env, const std::string &value) -{ - napi_value result = nullptr; - NAPI_CALL(env, napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result)); - return result; -} - -void SetAbilityDelegatorArgumentsPara(napi_env env, const std::map ¶s) +NativeValue *SetAbilityDelegatorArgumentsPara(NativeEngine &engine, const std::map ¶s) { HILOG_INFO("SetAbilityDelegatorArgumentsPara is called"); - napi_value parameter = nullptr; - napi_value result = nullptr; + NativeValue *objValue = engine.CreateObject(); + NativeObject *object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + HILOG_ERROR("Failed to get object"); + return nullptr; + } auto iter = paras.begin(); for (; iter != paras.end(); ++iter) { - NAPI_CALL_RETURN_VOID( - env, napi_set_named_property(env, parameter, iter->first.c_str(), WrapStringToJS(env, iter->second))); + object->SetProperty(iter->first.c_str(), CreateJsValue(engine, iter->second)); } - napi_set_named_property(env, result, "parameters", parameter); - return; + return objValue; } NativeValue *CreateJsAbilityDelegatorArguments( @@ -86,7 +82,8 @@ NativeValue *CreateJsAbilityDelegatorArguments( } object->SetProperty("bundleName", CreateJsValue(engine, abilityDelegatorArgs->GetTestBundleName())); - SetAbilityDelegatorArgumentsPara(reinterpret_cast(&engine), abilityDelegatorArgs->GetTestParam()); + object->SetProperty("parameters", + SetAbilityDelegatorArgumentsPara(engine, abilityDelegatorArgs->GetTestParam())); object->SetProperty("testCaseNames", CreateJsValue(engine, abilityDelegatorArgs->GetTestCaseName())); object->SetProperty("testRunnerClassName", CreateJsValue(engine, abilityDelegatorArgs->GetTestRunnerClassName())); diff --git a/interfaces/kits/napi/aafwk/app/test_runner/test_runner.js b/interfaces/kits/napi/aafwk/app/test_runner/test_runner.js index 4bd372f4769..7e517c5b51b 100755 --- a/interfaces/kits/napi/aafwk/app/test_runner/test_runner.js +++ b/interfaces/kits/napi/aafwk/app/test_runner/test_runner.js @@ -15,8 +15,8 @@ class TestRunner { constructor() {} - onPrepare​() {} - onRun​() {} + onPrepare() {} + onRun() {} } export default TestRunner diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn b/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn index e3904f5ff16..aff79d10f1b 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn +++ b/interfaces/kits/napi/aafwk/inner/napi_common/BUILD.gn @@ -30,7 +30,6 @@ ohos_shared_library("napi_common") { ] deps = [ - "//base/notification/ans_standard/frameworks/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", "//foundation/aafwk/standard/interfaces/innerkits/base:base", diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h b/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h index 6738cc3a15c..5441466206d 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h +++ b/interfaces/kits/napi/aafwk/inner/napi_common/feature_ability_common.h @@ -58,7 +58,6 @@ struct AsyncCallbackInfo { napi_async_work asyncWork = nullptr; napi_deferred deferred = nullptr; Ability *ability = nullptr; - Notification::WantAgent::WantAgent *wantAgent = nullptr; CallAbilityParam param; CallbackInfo aceCallback; bool native_result; diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp index a5b9eda80d3..71d51480c38 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp @@ -3501,333 +3501,5 @@ napi_value AcquireDataAbilityHelperWrap(napi_env env, napi_callback_info info, D HILOG_INFO("%{public}s,end", __func__); return result; } - -napi_value UnwrapParamForWantAgent(napi_env &env, napi_value &args, Notification::WantAgent::WantAgent *&wantAgent) -{ - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - napi_value wantAgentParam = nullptr; - napi_value result = nullptr; - - bool hasProperty = false; - NAPI_CALL(env, napi_has_named_property(env, args, "wantAgent", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, args, "wantAgent", &wantAgentParam); - NAPI_CALL(env, napi_typeof(env, wantAgentParam, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - napi_unwrap(env, wantAgentParam, (void **)&wantAgent); - } - - napi_get_null(env, &result); - return result; -} - -void StartBackgroundRunningExecuteCB(napi_env env, void *data) -{ - HILOG_INFO("%{public}s called.", __func__); - AsyncCallbackInfo *asyncCallbackInfo = (AsyncCallbackInfo *)data; - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("%{public}s asyncCallbackInfo == nullptr", __func__); - return; - } - if (asyncCallbackInfo->errCode == NAPI_ERR_PARAM_INVALID) { - HILOG_ERROR("parse input param failed"); - return; - } - if (asyncCallbackInfo->ability == nullptr) { - asyncCallbackInfo->errCode = NAPI_ERR_ACE_ABILITY; - HILOG_ERROR("%{public}s ability == nullptr", __func__); - return; - } - const std::shared_ptr info = asyncCallbackInfo->ability->GetAbilityInfo(); - if (info == nullptr) { - HILOG_ERROR("abilityinfo is null"); - asyncCallbackInfo->errCode = NAPI_ERR_ACE_ABILITY; - return; - } - - asyncCallbackInfo->errCode = asyncCallbackInfo->ability->StartBackgroundRunning(*asyncCallbackInfo->wantAgent); - - HILOG_INFO("%{public}s end.", __func__); -} - -void BackgroundRunningCallbackCompletedCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("%{public}s called.", __func__); - AsyncCallbackInfo *asyncCallbackInfo = static_cast(data); - napi_value callback = 0; - napi_value undefined = 0; - napi_value result[ARGS_TWO] = {0}; - napi_value callResult = 0; - napi_get_undefined(env, &undefined); - if (asyncCallbackInfo->errCode == NAPI_ERR_NO_ERROR) { - result[0] = WrapUndefinedToJS(env); - napi_create_int32(env, 0, &result[1]); - } else { - result[1] = WrapUndefinedToJS(env); - result[0] = GetCallbackErrorValue(env, asyncCallbackInfo->errCode); - } - - napi_get_reference_value(env, asyncCallbackInfo->cbInfo.callback, &callback); - napi_call_function(env, undefined, callback, ARGS_TWO, result, &callResult); - - if (asyncCallbackInfo->cbInfo.callback != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->cbInfo.callback); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - HILOG_INFO("%{public}s end.", __func__); -} - -void BackgroundRunningPromiseCompletedCB(napi_env env, napi_status status, void *data) -{ - HILOG_INFO("%{public}s called.", __func__); - AsyncCallbackInfo *asyncCallbackInfo = static_cast(data); - napi_value result = 0; - if (asyncCallbackInfo->errCode == NAPI_ERR_NO_ERROR) { - napi_create_int32(env, 0, &result); - napi_resolve_deferred(env, asyncCallbackInfo->deferred, result); - } else { - result = GetCallbackErrorValue(env, asyncCallbackInfo->errCode); - napi_reject_deferred(env, asyncCallbackInfo->deferred, result); - } - - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - HILOG_INFO("%{public}s, end.", __func__); - delete asyncCallbackInfo; -} - -napi_value StartBackgroundRunningAsync( - napi_env env, napi_value *args, const size_t argCallback, AsyncCallbackInfo *asyncCallbackInfo) -{ - HILOG_INFO("%{public}s asyncCallback.", __func__); - if (args == nullptr || asyncCallbackInfo == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = 0; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); - if (valuetype == napi_function) { - NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &asyncCallbackInfo->cbInfo.callback)); - } - - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - StartBackgroundRunningExecuteCB, - BackgroundRunningCallbackCompletedCB, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - - HILOG_INFO("%{public}s asyncCallback end.", __func__); - return WrapVoidToJS(env); -} - -napi_value StartBackgroundRunningPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo) -{ - HILOG_INFO("%{public}s, promise.", __func__); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName; - NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); - napi_deferred deferred; - napi_value promise = 0; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo->deferred = deferred; - - NAPI_CALL(env, - napi_create_async_work(env, - nullptr, - resourceName, - StartBackgroundRunningExecuteCB, - BackgroundRunningPromiseCompletedCB, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - HILOG_INFO("%{public}s, end.", __func__); - return promise; -} - -napi_value StartBackgroundRunningWrap(napi_env &env, napi_callback_info &info, AsyncCallbackInfo *asyncCallbackInfo) -{ - HILOG_INFO("%{public}s called.", __func__); - size_t paramNums = 3; - const size_t minParamNums = 2; - const size_t maxParamNums = 3; - napi_value args[maxParamNums] = {nullptr}; - napi_value ret = 0; - - NAPI_CALL(env, napi_get_cb_info(env, info, ¶mNums, args, NULL, NULL)); - - if (paramNums < minParamNums || paramNums > maxParamNums) { - HILOG_ERROR("%{public}s, Wrong argument count.", __func__); - return nullptr; - } - - if (UnwrapParamForWantAgent(env, args[1], asyncCallbackInfo->wantAgent) == nullptr) { - asyncCallbackInfo->errCode = NAPI_ERR_PARAM_INVALID; - } - - if (paramNums == maxParamNums) { - ret = StartBackgroundRunningAsync(env, args, maxParamNums - 1, asyncCallbackInfo); - } else { - ret = StartBackgroundRunningPromise(env, asyncCallbackInfo); - } - - HILOG_INFO("%{public}s end.", __func__); - return ret; -} - -napi_value NAPI_StartBackgroundRunningCommon(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - AsyncCallbackInfo *asyncCallbackInfo = CreateAsyncCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("%{public}s asyncCallbackInfo == nullpter", __func__); - return WrapVoidToJS(env); - } - - asyncCallbackInfo->errCode = NAPI_ERR_NO_ERROR; - napi_value ret = StartBackgroundRunningWrap(env, info, asyncCallbackInfo); - if (ret == nullptr) { - HILOG_ERROR("%{public}s ret == nullpter", __func__); - if (asyncCallbackInfo != nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s end.", __func__); - return ret; -} - -void CancelBackgroundRunningExecuteCB(napi_env env, void *data) -{ - HILOG_INFO("NAPI_PACancelBackgroundRunning, worker pool thread execute."); - AsyncCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo->ability != nullptr) { - asyncCallbackInfo->ability->StopBackgroundRunning(); - } else { - HILOG_ERROR("NAPI_PACancelBackgroundRunning, ability == nullptr"); - } - HILOG_INFO("NAPI_PACancelBackgroundRunning, worker pool thread execute end."); -} - -napi_value CancelBackgroundRunningAsync( - napi_env env, napi_value *args, const size_t argCallback, AsyncCallbackInfo *asyncCallbackInfo) -{ - HILOG_INFO("%{public}s, asyncCallback.", __func__); - if (args == nullptr || asyncCallbackInfo == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = 0; - napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); - - napi_valuetype valuetype = napi_undefined; - napi_typeof(env, args[argCallback], &valuetype); - if (valuetype == napi_function) { - napi_create_reference(env, args[argCallback], 1, &asyncCallbackInfo->cbInfo.callback); - } - - napi_create_async_work( - env, - nullptr, - resourceName, - CancelBackgroundRunningExecuteCB, - BackgroundRunningCallbackCompletedCB, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - napi_queue_async_work(env, asyncCallbackInfo->asyncWork); - napi_value result = 0; - napi_get_null(env, &result); - HILOG_INFO("%{public}s, asyncCallback end", __func__); - return result; -} - -napi_value CancelBackgroundRunningPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo) -{ - HILOG_INFO("%{public}s, promise.", __func__); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("%{public}s, param == nullptr.", __func__); - return nullptr; - } - napi_value resourceName = 0; - napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName); - napi_deferred deferred; - napi_value promise = 0; - napi_create_promise(env, &deferred, &promise); - - asyncCallbackInfo->deferred = deferred; - - napi_create_async_work( - env, - nullptr, - resourceName, - CancelBackgroundRunningExecuteCB, - BackgroundRunningPromiseCompletedCB, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - napi_queue_async_work(env, asyncCallbackInfo->asyncWork); - HILOG_INFO("%{public}s, promise end", __func__); - return promise; -} - -napi_value CancelBackgroundRunningWrap(napi_env &env, napi_callback_info &info, AsyncCallbackInfo *asyncCallbackInfo) -{ - HILOG_INFO("%{public}s called.", __func__); - size_t argcAsync = 1; - const size_t argcPromise = 0; - const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; - napi_value args[ARGS_MAX_COUNT] = {nullptr}; - napi_value ret = 0; - - NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, NULL, NULL)); - if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { - HILOG_ERROR("%{public}s, Wrong argument count.", __func__); - return nullptr; - } - - if (argcAsync > argcPromise) { - ret = CancelBackgroundRunningAsync(env, args, 0, asyncCallbackInfo); - } else { - ret = CancelBackgroundRunningPromise(env, asyncCallbackInfo); - } - - HILOG_INFO("%{public}s end.", __func__); - return ret; -} - -napi_value NAPI_CancelBackgroundRunningCommon(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s called.", __func__); - AsyncCallbackInfo *asyncCallbackInfo = CreateAsyncCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("%{public}s asyncCallbackInfo == nullpter", __func__); - return WrapVoidToJS(env); - } - - asyncCallbackInfo->errCode = NAPI_ERR_NO_ERROR; - napi_value ret = CancelBackgroundRunningWrap(env, info, asyncCallbackInfo); - if (ret == nullptr) { - HILOG_ERROR("%{public}s ret == nullpter", __func__); - if (asyncCallbackInfo != nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - ret = WrapVoidToJS(env); - } - HILOG_INFO("%{public}s end.", __func__); - return ret; -} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.h b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.h index c15bb499a33..293bf202414 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.h +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.h @@ -26,7 +26,7 @@ const std::int32_t STR_MAX_SIZE = 128; napi_value *GetGlobalClassContext(void); -napi_status SaveGlobalDataAbilityHelper(napi_env env, napi_value constructor); +napi_status SaveGlobalDataAbilityHelper(napi_env env, napi_value constructor); napi_value GetGlobalDataAbilityHelper(napi_env env); bool& GetDataAbilityHelperStatus(); @@ -227,26 +227,6 @@ napi_value NAPI_AcquireDataAbilityHelperCommon(napi_env env, napi_callback_info napi_value ConvertAbilityInfo(napi_env env, const AbilityInfo &abilityInfo); -/** - * @brief start background running. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_StartBackgroundRunningCommon(napi_env env, napi_callback_info info); - -/** - * @brief cancel background running. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_CancelBackgroundRunningCommon(napi_env env, napi_callback_info info); - bool CheckAbilityType(const CBBase *cbBase); struct ConnecttionKey { diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp index 4b3f081efc4..9dff21cbd37 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp @@ -686,17 +686,6 @@ bool InnerUnwrapWantParams(napi_env env, const std::string &key, napi_value para return false; } -bool BlackListFilter(const std::string &strProName) -{ - if (strProName == Want::PARAM_RESV_WINDOW_MODE) { - return true; - } - if (strProName == Want::PARAM_RESV_DISPLAY_ID) { - return true; - } - return false; -} - bool UnwrapWantParams(napi_env env, napi_value param, AAFwk::WantParams &wantParams) { HILOG_INFO("%{public}s called.", __func__); @@ -720,8 +709,7 @@ bool UnwrapWantParams(napi_env env, napi_value param, AAFwk::WantParams &wantPar std::string strProName = UnwrapStringFromJS(env, jsProName); /* skip reserved param */ - if (BlackListFilter(strProName)) { - HILOG_INFO("%{public}s is filtered.", strProName.c_str()); + if (strProName == Want::PARAM_RESV_WINDOW_MODE) { continue; } HILOG_INFO("%{public}s called. Property name=%{public}s.", __func__, strProName.c_str()); diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.h b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.h index 8cc4bcade3f..03130b2beb4 100644 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.h +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.h @@ -33,7 +33,6 @@ bool UnwrapElementName(napi_env env, napi_value param, ElementName &elementName) napi_value WrapWantParams(napi_env env, const AAFwk::WantParams &wantParams); bool UnwrapWantParams(napi_env env, napi_value param, AAFwk::WantParams &wantParams); -bool BlackListFilter(const std::string &strProName); napi_value WrapWant(napi_env env, const Want &want); bool UnwrapWant(napi_env env, napi_value param, Want &want); diff --git a/interfaces/kits/napi/aafwk/mission_manager/mission_manager.cpp b/interfaces/kits/napi/aafwk/mission_manager/mission_manager.cpp index d7e9f78a1d5..da1fb0fdefd 100644 --- a/interfaces/kits/napi/aafwk/mission_manager/mission_manager.cpp +++ b/interfaces/kits/napi/aafwk/mission_manager/mission_manager.cpp @@ -23,15 +23,12 @@ #include "js_mission_listener.h" #include "js_runtime_utils.h" #include "mission_snapshot.h" -#include "napi_common_start_options.h" #include "pixel_map_napi.h" -#include "start_options.h" #include namespace OHOS { namespace AbilityRuntime { -constexpr size_t ARGC_ONE = 1; using namespace OHOS::AppExecFwk; using AbilityManagerClient = AAFwk::AbilityManagerClient; namespace { @@ -455,23 +452,14 @@ private: HILOG_ERROR("Parse missionId failed"); errCode = ERR_NOT_OK; } - decltype(info.argc) unwrapArgc = 1; - - AAFwk::StartOptions startOptions; - if (info.argc > ARGC_ONE && info.argv[1]->TypeOf() == NATIVE_OBJECT) { - HILOG_INFO("OnMoveMissionToFront start options is used."); - AppExecFwk::UnwrapStartOptions(reinterpret_cast(&engine), - reinterpret_cast(info.argv[1]), startOptions); - unwrapArgc++; - } + AsyncTask::CompleteCallback complete = - [missionId, errCode, startOptions, unwrapArgc](NativeEngine &engine, AsyncTask &task, int32_t status) { + [missionId, errCode](NativeEngine &engine, AsyncTask &task, int32_t status) { if (errCode != 0) { task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params.")); return; } - auto ret = (unwrapArgc == 1) ? AbilityManagerClient::GetInstance()->MoveMissionToFront(missionId) : - AbilityManagerClient::GetInstance()->MoveMissionToFront(missionId, startOptions); + auto ret = AbilityManagerClient::GetInstance()->MoveMissionToFront(missionId); if (ret == 0) { task.Resolve(engine, engine.CreateUndefined()); } else { @@ -479,7 +467,7 @@ private: } }; - NativeValue* lastParam = (info.argc <= unwrapArgc) ? nullptr : info.argv[unwrapArgc]; + NativeValue* lastParam = (info.argc <= 1) ? nullptr : info.argv[1]; NativeValue* result = nullptr; AsyncTask::Schedule( engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); @@ -517,6 +505,7 @@ NativeValue* JsMissionManagerInit(NativeEngine* engine, NativeValue* exportObj) BindNativeFunction(*engine, *object, "clearMission", JsMissionManager::ClearMission); BindNativeFunction(*engine, *object, "clearAllMissions", JsMissionManager::ClearAllMissions); BindNativeFunction(*engine, *object, "moveMissionToFront", JsMissionManager::MoveMissionToFront); + BindNativeFunction(*engine, *object, "moveMissionToFront", JsMissionManager::MoveMissionToFront); return engine->CreateUndefined(); } } // namespace AbilityRuntime diff --git a/interfaces/kits/napi/aafwk/particleAbility/particle_ability.cpp b/interfaces/kits/napi/aafwk/particleAbility/particle_ability.cpp index aa4f8065c8d..c5dd1ae82d3 100644 --- a/interfaces/kits/napi/aafwk/particleAbility/particle_ability.cpp +++ b/interfaces/kits/napi/aafwk/particleAbility/particle_ability.cpp @@ -182,34 +182,6 @@ napi_value NAPI_PAAcquireDataAbilityHelper(napi_env env, napi_callback_info info return NAPI_AcquireDataAbilityHelperCommon(env, info, AbilityType::UNKNOWN); } -/** - * @brief ParticleAbility NAPI method : startBackgroundRunning. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_PAStartBackgroundRunning(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s,called", __func__); - return NAPI_StartBackgroundRunningCommon(env, info); -} - -/** - * @brief ParticleAbility NAPI method : cancelBackgroundRunning. - * - * @param env The environment that the Node-API call is invoked under. - * @param info The callback info passed into the callback function. - * - * @return The return value from NAPI C++ to JS for the module. - */ -napi_value NAPI_PACancelBackgroundRunning(napi_env env, napi_callback_info info) -{ - HILOG_INFO("%{public}s,called", __func__); - return NAPI_CancelBackgroundRunningCommon(env, info); -} - /** * @brief ParticleAbility NAPI module registration. * @@ -233,8 +205,6 @@ napi_value ParticleAbilityInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("connectAbility", NAPI_PAConnectAbility), DECLARE_NAPI_FUNCTION("disconnectAbility", NAPI_PADisConnectAbility), DECLARE_NAPI_FUNCTION("acquireDataAbilityHelper", NAPI_PAAcquireDataAbilityHelper), - DECLARE_NAPI_FUNCTION("startBackgroundRunning", NAPI_PAStartBackgroundRunning), - DECLARE_NAPI_FUNCTION("cancelBackgroundRunning", NAPI_PACancelBackgroundRunning), }; napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties); diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 79f078b1c1e..18ad4c0f89a 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -519,7 +519,7 @@ public: virtual void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess) override; - virtual int NotifyContinuationResult(int32_t missionId, int32_t result) override; + virtual int NotifyContinuationResult(int32_t missionId, const int32_t result) override; virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; @@ -544,9 +544,7 @@ public: virtual int CleanAllMissions() override; virtual int MoveMissionToFront(int32_t missionId) override; - - virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override; - + /** * Start Ability, connect session with common ability. * @@ -657,7 +655,7 @@ public: * @param pid The not response process ID. */ virtual bool SendANRProcessID(int pid) override; - + private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 212db26fad7..925610fa4e9 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -215,7 +215,7 @@ public: * @param result, continuation result. * @return Returns ERR_OK on success, others on failure. */ - virtual int NotifyContinuationResult(int32_t missionId, int32_t result) override; + virtual int NotifyContinuationResult(int32_t missionId, const int32_t result) override; /** * RegisterMissionListener, register remote device mission listener. @@ -659,8 +659,6 @@ public: virtual int MoveMissionToFront(int32_t missionId) override; - virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override; - virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; virtual int StopSyncRemoteMissions(const std::string& devId) override; @@ -1109,8 +1107,6 @@ private: int DelegatorMoveMissionToFront(int32_t missionId); - void StartupResidentProcess(); - using DumpFuncType = void (AbilityManagerService::*)(const std::string &args, std::vector &info); std::map dumpFuncMap_; diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 448a262cf09..08bacb824ca 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -142,7 +142,7 @@ private: int CleanMissionInner(MessageParcel &data, MessageParcel &reply); int CleanAllMissionsInner(MessageParcel &data, MessageParcel &reply); int MoveMissionToFrontInner(MessageParcel &data, MessageParcel &reply); - + // for new version ability (call ability) int StartAbilityByCallInner(MessageParcel &data, MessageParcel &reply); int ReleaseInner(MessageParcel &data, MessageParcel &reply); @@ -170,7 +170,6 @@ private: int DoAbilityBackgroundInner(MessageParcel &data, MessageParcel &reply); int IsRunningInStabilityTestInner(MessageParcel &data, MessageParcel &reply); - int MoveMissionToFrontByOptionsInner(MessageParcel &data, MessageParcel &reply); using RequestFuncType = int (AbilityManagerStub::*)(MessageParcel &data, MessageParcel &reply); std::map requestFuncMap_; diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 78633a38fd5..1753d77f382 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -670,7 +670,7 @@ public: * dump ability state info. * */ - void DumpAbilityState(std::vector &info, bool isClient, const std::vector ¶ms); + void DumpAbilityState(std::vector &info, bool isClient); void SetStartTime(); @@ -755,7 +755,7 @@ public: void SetLaunchReason(const LaunchReason &reason); void SetLastExitReason(const LastExitReason &reason); void ContinueAbility(const std::string& deviceId); - void NotifyContinuationResult(int32_t result); + void NotifyContinuationResult(const int32_t result); std::shared_ptr GetOwnedMissionList() const; void SetUseNewMission(); diff --git a/services/abilitymgr/include/ability_scheduler_proxy.h b/services/abilitymgr/include/ability_scheduler_proxy.h index 26e93b3e80d..7b505783d67 100644 --- a/services/abilitymgr/include/ability_scheduler_proxy.h +++ b/services/abilitymgr/include/ability_scheduler_proxy.h @@ -297,7 +297,7 @@ public: * @param The continuation result. * @return */ - void NotifyContinuationResult(int32_t result) override; + void NotifyContinuationResult(const int32_t result) override; /** * Dump Ability Runner info. @@ -305,7 +305,7 @@ public: * @param * @return Ability Runner info. */ - void DumpAbilityInfo(const std::vector ¶ms, std::vector &info) override; + void DumpAbilityInfo(std::vector &info) override; sptr CallRequest() override; private: diff --git a/services/abilitymgr/include/lifecycle_deal.h b/services/abilitymgr/include/lifecycle_deal.h index 2d894433ff1..dfca7756eda 100644 --- a/services/abilitymgr/include/lifecycle_deal.h +++ b/services/abilitymgr/include/lifecycle_deal.h @@ -58,7 +58,7 @@ public: void ForegroundNew(const Want &want, LifeCycleStateInfo &stateInfo); void BackgroundNew(const Want &want, LifeCycleStateInfo &stateInfo); void ContinueAbility(const std::string& deviceId); - void NotifyContinuationResult(int32_t result); + void NotifyContinuationResult(const int32_t result); private: sptr GetScheduler(); diff --git a/services/abilitymgr/include/mission_list.h b/services/abilitymgr/include/mission_list.h index 30b4140bdcc..ca093f4dca8 100644 --- a/services/abilitymgr/include/mission_list.h +++ b/services/abilitymgr/include/mission_list.h @@ -174,9 +174,7 @@ public: * @param info dump result. */ void DumpList(std::vector &info, bool isClient); - - void DumpStateByRecordId( - std::vector &info, bool isClient, int32_t abilityRecordId, const std::vector ¶ms); + void DumpStateByRecordId(std::vector &info, bool isClient, int32_t abilityRecordId); std::shared_ptr GetMissionBySpecifiedFlag(const std::string &flag) const; private: diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index 191b986b813..650085f7f87 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -27,7 +27,6 @@ #include "mission_info.h" #include "mission_snapshot.h" #include "snapshot.h" -#include "start_options.h" #include "want.h" namespace OHOS { @@ -68,10 +67,9 @@ public: int GetMissionInfo(int32_t missionId, MissionInfo &missionInfo); - int MoveMissionToFront(int32_t missionId, std::shared_ptr startOptions = nullptr); + int MoveMissionToFront(int32_t missionId); - int MoveMissionToFront(int32_t missionId, bool isCallerFromLauncher, - std::shared_ptr startOptions = nullptr); + int MoveMissionToFront(int32_t missionId, bool isCallerFromLauncher); /** * OnAbilityRequestDone, app manager service call this interface after ability request done. @@ -264,14 +262,7 @@ public: */ void DumpMissionList(std::vector &info, bool isClient, const std::string &args = ""); - /** - * @brief dump mission list by id with params - * - * @param info dump result. - * @param params dump params. - */ - void DumpMissionListByRecordId( - std::vector& info, bool isClient, int32_t abilityRecordId, const std::vector& params); + void DumpMissionListByRecordId(std::vector &info, bool isClient, int32_t abilityRecordId); /** * @brief dump mission by id @@ -303,6 +294,7 @@ public: * @param element, target ability name. */ int ReleaseLocked(const sptr &connect, const AppExecFwk::ElementName &element); + /** * @brief register snapshotHandler * @param handler the snapshotHandler diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index bf217771d14..ec19bb5290a 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -772,14 +772,6 @@ ErrCode AbilityManagerClient::MoveMissionToFront(int32_t missionId) return abms->MoveMissionToFront(missionId); } -ErrCode AbilityManagerClient::MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) -{ - CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); - - sptr abms = iface_cast(remoteObject_); - return abms->MoveMissionToFront(missionId, startOptions); -} - ErrCode AbilityManagerClient::StartAbilityByCall( const Want &want, const sptr &connect, const sptr &callToken) { @@ -932,14 +924,5 @@ ErrCode AbilityManagerClient::DoAbilityBackground(const sptr &tok sptr abms = iface_cast(remoteObject_); return abms->DoAbilityBackground(token, flag); } - -ErrCode AbilityManagerClient::SetAbilityController(const sptr &abilityController, - bool imAStabilityTest) -{ - CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); - - sptr abms = iface_cast(remoteObject_); - return abms->SetAbilityController(abilityController, imAStabilityTest); -} } // namespace AAFwk } // namespace AAFwk diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 14980e30031..86db7a562d3 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -1721,7 +1721,7 @@ void AbilityManagerProxy::NotifyCompleteContinuation(const std::string &deviceId } } -int AbilityManagerProxy::NotifyContinuationResult(int32_t missionId, int32_t result) +int AbilityManagerProxy::NotifyContinuationResult(int32_t missionId, const int32_t result) { MessageParcel data; MessageParcel reply; @@ -1996,32 +1996,6 @@ int AbilityManagerProxy::MoveMissionToFront(int32_t missionId) return reply.ReadInt32(); } -int AbilityManagerProxy::MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) -{ - int error; - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!WriteInterfaceToken(data)) { - return INNER_ERR; - } - if (!data.WriteInt32(missionId)) { - HILOG_ERROR("move mission to front , WriteInt32 fail."); - return ERR_INVALID_VALUE; - } - if (!data.WriteParcelable(&startOptions)) { - HILOG_ERROR("startOptions write failed."); - return INNER_ERR; - } - error = Remote()->SendRequest(IAbilityManager::MOVE_MISSION_TO_FRONT_BY_OPTIONS, data, reply, option); - if (error != NO_ERROR) { - HILOG_ERROR("move mission to front, SendRequest error: %d", error); - return error; - } - return reply.ReadInt32(); -} - int AbilityManagerProxy::StartUser(int userId) { int error; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 900d0ba43fc..abe4afc04dc 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -288,6 +288,10 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrStartAbility(abilityRequest); } } - abilityRequest.want.SetParam(Want::PARAM_RESV_DISPLAY_ID, startOptions.GetDisplayID()); + abilityRequest.want.SetParam(StartOptions::STRING_DISPLAY_ID, startOptions.GetDisplayID()); abilityRequest.want.SetParam(Want::PARAM_RESV_WINDOW_MODE, startOptions.GetWindowMode()); if (useNewMission_) { userIdValid = abilityInfo.applicationInfo.singleUser ? DEFAULT_USER_ID : userIdValid; @@ -583,11 +595,9 @@ int AbilityManagerService::StartRemoteAbility(const Want &want, int requestCode) HILOG_INFO("%{public}s", __func__); want.DumpInfo(0); int32_t callerUid = IPCSkeleton::GetCallingUid(); - uint32_t accessToken = IPCSkeleton::GetCallingTokenID(); DistributedClient dmsClient; HILOG_INFO("AbilityManagerService::Try to StartRemoteAbility, callerUid = %{public}d", callerUid); - HILOG_INFO("AbilityManagerService::Try to StartRemoteAbility, AccessTokenID = %{public}d", accessToken); - int result = dmsClient.StartRemoteAbility(want, callerUid, requestCode, accessToken); + int result = dmsClient.StartRemoteAbility(want, callerUid, requestCode); if (result != ERR_NONE) { HILOG_ERROR("AbilityManagerService::StartRemoteAbility failed, result = %{public}d", result); } @@ -928,6 +938,10 @@ int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t u return result; } auto abilityInfo = abilityRequest.abilityInfo; + result = CheckStaticCfgPermission(abilityInfo); + if (result != ERR_OK) { + return result; + } result = AbilityUtil::JudgeAbilityVisibleControl(abilityInfo); if (result != ERR_OK) { HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__); @@ -959,10 +973,8 @@ int AbilityManagerService::ConnectRemoteAbility(const Want &want, const sptr &connect) @@ -1011,15 +1023,13 @@ int AbilityManagerService::StartContinuation(const Want &want, const sptrMoveMissionToFront(missionId); } -int AbilityManagerService::MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) -{ - HILOG_INFO("request MoveMissionToFront, missionId:%{public}d", missionId); - CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); - CHECK_POINTER_AND_RETURN(iBundleManager_, ERR_NO_INIT); - - if (!CheckCallerIsSystemAppByIpc()) { - HILOG_ERROR("caller is not system app"); - return CALLER_ISNOT_SYSTEMAPP; - } - - auto options = std::make_shared(startOptions); - return currentMissionListManager_->MoveMissionToFront(missionId, options); -} - std::shared_ptr AbilityManagerService::GetServiceRecordByElementName(const std::string &element) { return connectManager_->GetServiceRecordByElementName(element); @@ -1506,6 +1501,10 @@ sptr AbilityManagerService::AcquireDataAbility( abilityRequest.appInfo.bundleName.c_str(), abilityRequest.abilityInfo.name.c_str()); + if (CheckStaticCfgPermission(abilityRequest.abilityInfo) != ERR_OK) { + return nullptr; + } + CHECK_POINTER_AND_RETURN(dataAbilityManager_, nullptr); return dataAbilityManager_->Acquire(abilityRequest, tryBind, callerToken, isSystem); } @@ -1700,10 +1699,9 @@ void AbilityManagerService::DumpSysAbilityInner( if (argList.empty()) { return; } - if (argList.size() >= MIN_DUMP_ARGUMENT_NUM) { + if (argList.size() == MIN_DUMP_ARGUMENT_NUM) { HILOG_INFO("argList = %{public}s", argList[1].c_str()); - std::vector params(argList.begin() + MIN_DUMP_ARGUMENT_NUM, argList.end()); - targetManager->DumpMissionListByRecordId(info, isClient, std::stoi(argList[1]), params); + targetManager->DumpMissionListByRecordId(info, isClient, std::stoi(argList[1])); } else { info.emplace_back("error: invalid argument, please see 'ability dumpsys -h'."); } @@ -3216,7 +3214,8 @@ void AbilityManagerService::StartSystemApplication() StartingSystemUiAbility(); - StartupResidentProcess(); + // Location may change + DelayedSingleton::GetInstance()->StartupResidentProcess(); } void AbilityManagerService::StartingSystemUiAbility() @@ -4096,6 +4095,13 @@ int AbilityManagerService::GetCurrentTopAbility(sptr &token) } token = abilityRecord->GetToken(); + if (!token) { + HILOG_ERROR("Failed to get token"); + return ERR_INVALID_VALUE; + } + + HILOG_INFO("bundleName : %{public}s, abilityName : %{public}s", + bundleName.data(), abilityRecord->GetAbilityInfo().name.data()); return ERR_OK; } @@ -4105,6 +4111,11 @@ int AbilityManagerService::DelegatorDoAbilityForeground(const sptr bundleInfos; - (void)iBundleManager_->QueryKeepAliveBundleInfos(bundleInfos); - for (auto bundleInfo : bundleInfos) { - for (auto hapModuleInfo : bundleInfo.hapModuleInfos) { - if (!hapModuleInfo.mainElementName.empty()) { - AppExecFwk::AbilityInfo abilityInfo; - Want want; - want.SetElementName(hapModuleInfo.bundleName, hapModuleInfo.mainElementName); - (void)StartAbility(want, USER_ID_NO_HEAD, DEFAULT_INVAL_VALUE); // user 0 - } - } - } - - DelayedSingleton::GetInstance()->StartupResidentProcess(); -} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 6d679b09bd3..d9088839c36 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -125,7 +125,6 @@ void AbilityManagerStub::SecondStepInit() requestFuncMap_[CLEAN_MISSION] = &AbilityManagerStub::CleanMissionInner; requestFuncMap_[CLEAN_ALL_MISSIONS] = &AbilityManagerStub::CleanAllMissionsInner; requestFuncMap_[MOVE_MISSION_TO_FRONT] = &AbilityManagerStub::MoveMissionToFrontInner; - requestFuncMap_[MOVE_MISSION_TO_FRONT_BY_OPTIONS] = &AbilityManagerStub::MoveMissionToFrontByOptionsInner; requestFuncMap_[START_CALL_ABILITY] = &AbilityManagerStub::StartAbilityByCallInner; requestFuncMap_[RELEASE_CALL_ABILITY] = &AbilityManagerStub::ReleaseInner; requestFuncMap_[SET_MISSION_LABEL] = &AbilityManagerStub::SetMissionLabelInner; @@ -1149,25 +1148,9 @@ int AbilityManagerStub::MoveMissionToFrontInner(MessageParcel &data, MessageParc return NO_ERROR; } -int AbilityManagerStub::MoveMissionToFrontByOptionsInner(MessageParcel &data, MessageParcel &reply) -{ - int32_t missionId = data.ReadInt32(); - StartOptions *startOptions = data.ReadParcelable(); - if (startOptions == nullptr) { - HILOG_ERROR("startOptions is nullptr"); - return ERR_INVALID_VALUE; - } - int result = MoveMissionToFront(missionId, *startOptions); - if (!reply.WriteInt32(result)) { - HILOG_ERROR("MoveMissionToFront failed."); - return ERR_INVALID_VALUE; - } - return NO_ERROR; -} - int AbilityManagerStub::StartAbilityByCallInner(MessageParcel &data, MessageParcel &reply) { - + HILOG_DEBUG("AbilityManagerStub::StartAbilityByCallInner begin."); Want *want = data.ReadParcelable(); if (want == nullptr) { @@ -1183,7 +1166,7 @@ int AbilityManagerStub::StartAbilityByCallInner(MessageParcel &data, MessageParc reply.WriteInt32(result); delete want; - + HILOG_DEBUG("AbilityManagerStub::StartAbilityByCallInner end."); return NO_ERROR; diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 1c398aea0b9..90c73efb5bd 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -922,8 +922,7 @@ void AbilityRecord::Dump(std::vector &info) } } -void AbilityRecord::DumpAbilityState( - std::vector &info, bool isClient, const std::vector ¶ms) +void AbilityRecord::DumpAbilityState(std::vector &info, bool isClient) { HILOG_INFO("%{public}s begin.", __func__); std::string dumpInfo = " AbilityRecord ID #" + std::to_string(recordId_); @@ -955,10 +954,7 @@ void AbilityRecord::DumpAbilityState( // add dump client info if (isClient && scheduler_ && isReady_) { - scheduler_->DumpAbilityInfo(params, info); - if (!params.empty()) { - return; - } + scheduler_->DumpAbilityInfo(info); AppExecFwk::Configuration config; if (DelayedSingleton::GetInstance()->GetConfiguration(config) == ERR_OK) { info.emplace_back(" configuration: " + config.GetName()); @@ -996,8 +992,7 @@ void AbilityRecord::DumpService(std::vector &info, bool isClient) c } // add dump client info if (isClient && scheduler_ && isReady_) { - std::vector params; - scheduler_->DumpAbilityInfo(params, info); + scheduler_->DumpAbilityInfo(info); AppExecFwk::Configuration config; if (DelayedSingleton::GetInstance()->GetConfiguration(config) == ERR_OK) { info.emplace_back(" configuration: " + config.GetName()); @@ -1297,7 +1292,7 @@ void AbilityRecord::SetLastExitReason(const LastExitReason &reason) lifeCycleStateInfo_.launchParam.lastExitReason = reason; } -void AbilityRecord::NotifyContinuationResult(int32_t result) +void AbilityRecord::NotifyContinuationResult(const int32_t result) { HILOG_INFO("NotifyContinuationResult."); CHECK_POINTER(lifecycleDeal_); diff --git a/services/abilitymgr/src/ability_scheduler_proxy.cpp b/services/abilitymgr/src/ability_scheduler_proxy.cpp index bdf34a06b6f..c95d108a3ee 100755 --- a/services/abilitymgr/src/ability_scheduler_proxy.cpp +++ b/services/abilitymgr/src/ability_scheduler_proxy.cpp @@ -981,7 +981,7 @@ void AbilitySchedulerProxy::NotifyContinuationResult(int32_t result) } } -void AbilitySchedulerProxy::DumpAbilityInfo(const std::vector ¶ms, std::vector &info) +void AbilitySchedulerProxy::DumpAbilityInfo(std::vector &info) { MessageParcel data; MessageParcel reply; @@ -991,11 +991,6 @@ void AbilitySchedulerProxy::DumpAbilityInfo(const std::vector ¶ return; } - if (!data.WriteStringVector(params)) { - HILOG_ERROR("DumpAbilityRunner fail to write params"); - return; - } - int32_t err = Remote()->SendRequest(IAbilityScheduler::DUMP_ABILITY_RUNNER_INNER, data, reply, option); if (err != NO_ERROR) { HILOG_ERROR("DumpAbilityRunner fail to SendRequest. err: %d", err); diff --git a/services/abilitymgr/src/ability_scheduler_stub.cpp b/services/abilitymgr/src/ability_scheduler_stub.cpp index 89e19940414..e72008a219a 100644 --- a/services/abilitymgr/src/ability_scheduler_stub.cpp +++ b/services/abilitymgr/src/ability_scheduler_stub.cpp @@ -580,13 +580,10 @@ int AbilitySchedulerStub::NotifyContinuationResultInner(MessageParcel &data, Mes int AbilitySchedulerStub::DumpAbilityInfoInner(MessageParcel &data, MessageParcel &reply) { + std::vector infos; - std::vector params; - if (!data.ReadStringVector(¶ms)) { - HILOG_INFO("DumpAbilityInfoInner read params error"); - return NO_ERROR; - } - DumpAbilityInfo(params, infos); + + DumpAbilityInfo(infos); for (const auto & infostep:infos) { HILOG_INFO("DumpAbilityInfoInner infos = %{public}s", infostep.c_str()); diff --git a/services/abilitymgr/src/lifecycle_deal.cpp b/services/abilitymgr/src/lifecycle_deal.cpp index 2ab80063fdc..3e5160e9f9a 100755 --- a/services/abilitymgr/src/lifecycle_deal.cpp +++ b/services/abilitymgr/src/lifecycle_deal.cpp @@ -160,7 +160,7 @@ void LifecycleDeal::ContinueAbility(const std::string& deviceId) abilityScheduler_->ContinueAbility(deviceId); } -void LifecycleDeal::NotifyContinuationResult(int32_t result) +void LifecycleDeal::NotifyContinuationResult(const int32_t result) { HILOG_INFO("NotifyContinuationResult."); auto abilityScheduler = GetScheduler(); diff --git a/services/abilitymgr/src/mission_list.cpp b/services/abilitymgr/src/mission_list.cpp index 24e621a6808..439df45cef9 100644 --- a/services/abilitymgr/src/mission_list.cpp +++ b/services/abilitymgr/src/mission_list.cpp @@ -264,8 +264,7 @@ void MissionList::Dump(std::vector& info) } } -void MissionList::DumpStateByRecordId( - std::vector &info, bool isClient, int32_t abilityRecordId, const std::vector ¶ms) +void MissionList::DumpStateByRecordId(std::vector &info, bool isClient, int32_t abilityRecordId) { for (const auto& mission : missions_) { if (mission) { @@ -273,7 +272,7 @@ void MissionList::DumpStateByRecordId( if (abilityRecord) { if (abilityRecord->GetRecordId() == abilityRecordId) { HILOG_INFO("record begain to call DumpAbilityState %{public}s", __func__); - abilityRecord->DumpAbilityState(info, isClient, params); + abilityRecord->DumpAbilityState(info, isClient); return; } } @@ -295,8 +294,7 @@ void MissionList::DumpList(std::vector &info, bool isClient) auto abilityRecord = mission->GetAbilityRecord(); if (abilityRecord) { HILOG_INFO("record begain to call DumpAbilityState %{public}s", __func__); - std::vector params; - abilityRecord->DumpAbilityState(info, isClient, params); + abilityRecord->DumpAbilityState(info, isClient); } } } diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 198261ccc02..d657ed586ff 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -145,14 +145,13 @@ int MissionListManager::GetMissionInfo(int32_t missionId, MissionInfo &missionIn return DelayedSingleton::GetInstance()->GetMissionInfoById(missionId, missionInfo); } -int MissionListManager::MoveMissionToFront(int32_t missionId, std::shared_ptr startOptions) +int MissionListManager::MoveMissionToFront(int32_t missionId) { std::lock_guard guard(managerLock_); - return MoveMissionToFront(missionId, true, startOptions); + return MoveMissionToFront(missionId, true); } -int MissionListManager::MoveMissionToFront(int32_t missionId, bool isCallerFromLauncher, - std::shared_ptr startOptions) +int MissionListManager::MoveMissionToFront(int32_t missionId, bool isCallerFromLauncher) { HILOG_INFO("move mission to front:%{public}d.", missionId); std::lock_guard guard(managerLock_); @@ -178,11 +177,7 @@ int MissionListManager::MoveMissionToFront(int32_t missionId, bool isCallerFromL HILOG_ERROR("get target ability record failed, missionId: %{public}d", missionId); return MOVE_MISSION_FAILED; } - if (startOptions != nullptr) { - Want want(targetAbilityRecord->GetWant()); - want.SetParam(Want::PARAM_RESV_WINDOW_MODE, startOptions->GetWindowMode()); - targetAbilityRecord->SetWant(want); - } + // schedule target ability to foreground. targetAbilityRecord->ProcessForegroundAbility(); HILOG_DEBUG("SetMovingState, missionId: %{public}d", missionId); @@ -1579,7 +1574,7 @@ void MissionListManager::Dump(std::vector &info) } void MissionListManager::DumpMissionListByRecordId( - std::vector &info, bool isClient, int32_t abilityRecordId, const std::vector ¶ms) + std::vector &info, bool isClient, int32_t abilityRecordId) { std::lock_guard guard(managerLock_); std::string dumpInfo = "User ID #" + std::to_string(userId_); @@ -1587,23 +1582,23 @@ void MissionListManager::DumpMissionListByRecordId( for (const auto& missionList : currentMissionLists_) { if (missionList && missionList != launcherList_) { HILOG_INFO("missionList begain to call DumpMissionListByRecordId %{public}s", __func__); - missionList->DumpStateByRecordId(info, isClient, abilityRecordId, params); + missionList->DumpStateByRecordId(info, isClient, abilityRecordId); } } if (defaultStandardList_) { HILOG_INFO("defaultStandardList begain to call DumpMissionListByRecordId %{public}s", __func__); - defaultStandardList_->DumpStateByRecordId(info, isClient, abilityRecordId, params); + defaultStandardList_->DumpStateByRecordId(info, isClient, abilityRecordId); } if (defaultSingleList_) { HILOG_INFO("defaultSingleList begain to call DumpMissionListByRecordId %{public}s", __func__); - defaultSingleList_->DumpStateByRecordId(info, isClient, abilityRecordId, params); + defaultSingleList_->DumpStateByRecordId(info, isClient, abilityRecordId); } if (launcherList_) { HILOG_INFO("launcherList begain to call DumpMissionListByRecordId %{public}s", __func__); - launcherList_->DumpStateByRecordId(info, isClient, abilityRecordId, params); + launcherList_->DumpStateByRecordId(info, isClient, abilityRecordId); } } void MissionListManager::DumpMissionList(std::vector &info, bool isClient, const std::string &args) @@ -1962,21 +1957,31 @@ void MissionListManager::GetAbilityRunningInfos(std::vector std::shared_ptr MissionListManager::GetCurrentTopAbility(const std::string &bundleName) { + std::lock_guard guard(managerLock_); + for (auto &missionList : currentMissionLists_) { if (!missionList) { HILOG_WARN("Invalid missionList."); continue; } - auto abilityRecord = missionList->GetLauncherRoot(); - if (!abilityRecord) { - HILOG_ERROR("Invalid ability record."); - return {}; - } + auto missions = missionList->GetAllMissions(); + for (auto &mission : missions) { + if (!mission) { + HILOG_WARN("Invalid mission."); + continue; + } - auto appInfo = abilityRecord->GetApplicationInfo(); - if (bundleName.compare(appInfo.bundleName)) { - return abilityRecord; + auto abilityRecord = mission->GetAbilityRecord(); + if (!abilityRecord) { + HILOG_WARN("Invalid ability record."); + continue; + } + + auto appInfo = abilityRecord->GetApplicationInfo(); + if (bundleName.compare(appInfo.bundleName) == 0) { + return abilityRecord; + } } } diff --git a/services/abilitymgr/src/pending_want_manager.cpp b/services/abilitymgr/src/pending_want_manager.cpp index 22f19601b8c..f7461d333c9 100644 --- a/services/abilitymgr/src/pending_want_manager.cpp +++ b/services/abilitymgr/src/pending_want_manager.cpp @@ -235,8 +235,7 @@ int32_t PendingWantManager::DeviceIdDetermine( return result; } DistributedClient dmsClient; - uint32_t accessToken = IPCSkeleton::GetCallingTokenID(); - result = dmsClient.StartRemoteAbility(want, callerUid, requestCode, accessToken); + result = dmsClient.StartRemoteAbility(want, callerUid, requestCode); if (result != ERR_OK) { HILOG_ERROR("%{public}s: StartRemoteAbility Error! result = %{public}d", __func__, result); } diff --git a/services/abilitymgr/src/start_options.cpp b/services/abilitymgr/src/start_options.cpp index e7bc58c9596..20eb4bfd33a 100644 --- a/services/abilitymgr/src/start_options.cpp +++ b/services/abilitymgr/src/start_options.cpp @@ -17,20 +17,8 @@ namespace OHOS { namespace AAFwk { -StartOptions::StartOptions(const StartOptions &other) -{ - windowMode_ = other.windowMode_; - displayId_ = other.displayId_; -} -StartOptions &StartOptions::operator=(const StartOptions &other) -{ - if (this != &other) { - windowMode_ = other.windowMode_; - displayId_ = other.displayId_; - } - return *this; -} +const std::string StartOptions::STRING_DISPLAY_ID = "ohos.aafwk.displayId"; bool StartOptions::ReadFromParcel(Parcel &parcel) { diff --git a/services/abilitymgr/test/mock/libs/aakit/include/ability_scheduler.h b/services/abilitymgr/test/mock/libs/aakit/include/ability_scheduler.h index bc9551997f3..03bb8e5c183 100755 --- a/services/abilitymgr/test/mock/libs/aakit/include/ability_scheduler.h +++ b/services/abilitymgr/test/mock/libs/aakit/include/ability_scheduler.h @@ -97,11 +97,11 @@ public: { return std::vector>(); }; - virtual void NotifyContinuationResult(int32_t result) override + virtual void NotifyContinuationResult(const int32_t result) override {}; virtual void ContinueAbility(const std::string& deviceId) override {}; - virtual void DumpAbilityInfo(const std::vector ¶ms, std::vector &info) override + virtual void DumpAbilityInfo(std::vector &info) override {}; virtual sptr CallRequest() override { diff --git a/services/abilitymgr/test/mock/libs/ability_scheduler_mock/ability_scheduler_mock.h b/services/abilitymgr/test/mock/libs/ability_scheduler_mock/ability_scheduler_mock.h index ec5ea8943c5..34bcf6228f5 100755 --- a/services/abilitymgr/test/mock/libs/ability_scheduler_mock/ability_scheduler_mock.h +++ b/services/abilitymgr/test/mock/libs/ability_scheduler_mock/ability_scheduler_mock.h @@ -41,9 +41,9 @@ public: MOCK_METHOD3(ScheduleCommandAbility, void(const Want &, bool, int)); MOCK_METHOD1(NotifyTopActiveAbilityChanged, void(bool flag)); MOCK_METHOD2(NotifyMultiWinModeChanged, void(int32_t winModeKey, bool flag)); - MOCK_METHOD1(NotifyContinuationResult, void(int32_t result)); + MOCK_METHOD1(NotifyContinuationResult, void(const int32_t result)); MOCK_METHOD1(ContinueAbility, void(const std::string& deviceId)); - MOCK_METHOD2(DumpAbilityInfo, void(const std::vector ¶ms, std::vector &info)); + MOCK_METHOD1(DumpAbilityInfo, void(std::vector &info)); int InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { @@ -150,4 +150,4 @@ public: int code_ = 0; }; } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp b/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp index cc363a08756..8957753503d 100644 --- a/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp @@ -186,7 +186,12 @@ void AbilityDumpTest::SetUp() void AbilityDumpTest::TearDown() { - g_abilityMs->OnStop(); + g_abilityMs->eventLoop_->Stop(); + g_abilityMs->eventLoop_.reset(); + g_abilityMs->handler_.reset(); + g_abilityMs->state_ = ServiceRunningState::STATE_NOT_START; + OHOS::DelayedSingleton::DestroyInstance(); + g_abilityMs = nullptr; } void AbilityDumpTest::StartAbilityes() diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h index d06f56e6423..bf6c9c53302 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -393,7 +393,7 @@ public: MOCK_METHOD2(GetPendingRequestWant, int(const sptr &target, std::shared_ptr &want)); MOCK_METHOD1(GetSystemMemoryAttr, void(AppExecFwk::SystemMemoryAttr &memoryInfo)); MOCK_METHOD3(StartContinuation, int(const Want &want, const sptr &abilityToken, int32_t status)); - MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, const int32_t result)); MOCK_METHOD5(ContinueMission, int(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams)); MOCK_METHOD2(ContinueAbility, int(const std::string &deviceId, int32_t missionId)); @@ -409,7 +409,6 @@ public: MOCK_METHOD1(CleanMission, int(int32_t missionId)); MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); - MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); MOCK_METHOD2(SetMissionLabel, int(const sptr &token, const std::string &label)); MOCK_METHOD2(GetWantSenderInfo, int(const sptr &target, std::shared_ptr &info)); MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector &info)); diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp index 827759c8945..9afa0aa2423 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp @@ -98,8 +98,8 @@ public: public: AbilityRequest abilityRequest_; + std::shared_ptr abilityMs_ {nullptr}; std::shared_ptr abilityRecord_ {nullptr}; - std::shared_ptr abilityMs_ = DelayedSingleton::GetInstance(); }; int AbilityManagerServiceTest::StartAbility(const Want &want) @@ -161,7 +161,9 @@ void AbilityManagerServiceTest::OnStartAms() void AbilityManagerServiceTest::OnStopAms() { - abilityMs_->OnStop(); + abilityMs_->eventLoop_.reset(); + abilityMs_->handler_.reset(); + abilityMs_->state_ = ServiceRunningState::STATE_NOT_START; } void AbilityManagerServiceTest::SetUpTestCase() @@ -177,6 +179,7 @@ void AbilityManagerServiceTest::TearDownTestCase() void AbilityManagerServiceTest::SetUp() { + abilityMs_ = OHOS::DelayedSingleton::GetInstance(); OnStartAms(); WaitUntilTaskFinished(); if (abilityRecord_ == nullptr) { @@ -185,11 +188,13 @@ void AbilityManagerServiceTest::SetUp() abilityRequest_.abilityInfo.type = AbilityType::DATA; abilityRecord_ = AbilityRecord::CreateAbilityRecord(abilityRequest_); } + } void AbilityManagerServiceTest::TearDown() { OnStopAms(); + OHOS::DelayedSingleton::DestroyInstance(); } /* diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h index ea21028ca66..344172f5499 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -49,7 +49,7 @@ public: MOCK_METHOD2(GetWantSenderInfo, int(const sptr &target, std::shared_ptr &info)); MOCK_METHOD2(SetMissionLabel, int(const sptr &token, const std::string &label)); MOCK_METHOD3(StartContinuation, int(const Want &want, const sptr &abilityToken, int32_t status)); - MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, const int32_t result)); MOCK_METHOD5(ContinueMission, int(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams)); MOCK_METHOD2(ContinueAbility, int(const std::string &deviceId, int32_t missionId)); @@ -357,10 +357,6 @@ public: { return 0; } - virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override - { - return 0; - } virtual int GetMissionInfos(const std::string& deviceId, int32_t numMax, std::vector &missionInfos) override { diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h index 2b6a3166749..c7af16c3182 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h @@ -124,7 +124,7 @@ public: return 0; } MOCK_METHOD3(StartContinuation, int(const Want &want, const sptr &abilityToken, int32_t status)); - MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, const int32_t result)); MOCK_METHOD5(ContinueMission, int(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams)); MOCK_METHOD2(ContinueAbility, int(const std::string &deviceId, int32_t missionId)); diff --git a/services/abilitymgr/test/unittest/phone/ability_record_test/ability_record_test.cpp b/services/abilitymgr/test/unittest/phone/ability_record_test/ability_record_test.cpp index 547699defa8..71202da4478 100644 --- a/services/abilitymgr/test/unittest/phone/ability_record_test/ability_record_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_record_test/ability_record_test.cpp @@ -53,6 +53,7 @@ void AbilityRecordTest::SetUpTestCase(void) void AbilityRecordTest::TearDownTestCase(void) { OHOS::DelayedSingleton::GetInstance()->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); } void AbilityRecordTest::SetUp(void) diff --git a/services/abilitymgr/test/unittest/phone/ability_scheduler_stub_test/ability_schedule_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_scheduler_stub_test/ability_schedule_stub_mock.h index ce061009455..a1a4ef18a98 100755 --- a/services/abilitymgr/test/unittest/phone/ability_scheduler_stub_test/ability_schedule_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_scheduler_stub_test/ability_schedule_stub_mock.h @@ -129,11 +129,11 @@ public: { return std::vector>(); } - virtual void NotifyContinuationResult(int32_t result) override + virtual void NotifyContinuationResult(const int32_t result) override {} virtual void ContinueAbility(const std::string& deviceId) override {} - virtual void DumpAbilityInfo(const std::vector ¶ms, std::vector &info) override + virtual void DumpAbilityInfo(std::vector &info) override {} virtual sptr CallRequest() override { @@ -143,4 +143,4 @@ public: } // namespace AAFwk } // namespace OHOS -#endif +#endif \ No newline at end of file diff --git a/services/abilitymgr/test/unittest/phone/ability_service_start_test/ability_service_start_test.cpp b/services/abilitymgr/test/unittest/phone/ability_service_start_test/ability_service_start_test.cpp index 5164dce77f5..5d50f189567 100644 --- a/services/abilitymgr/test/unittest/phone/ability_service_start_test/ability_service_start_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_service_start_test/ability_service_start_test.cpp @@ -57,6 +57,8 @@ void AbilityServiceStartTest::SetUp() void AbilityServiceStartTest::TearDown() { aams_->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); + aams_ = nullptr; } /* diff --git a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp index d4a48a6cb73..e22a8cce45b 100644 --- a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp @@ -137,6 +137,7 @@ void AbilityStackManagerTest::TearDown() { stackManager_.reset(); abilityMs_->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); } void AbilityStackManagerTest::init() diff --git a/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp b/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp index a4d33b77bca..b33478719cb 100644 --- a/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp @@ -78,6 +78,7 @@ void AbilityWithApplicationsTest::SetUp() void AbilityWithApplicationsTest::TearDown() { abilityMs_->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); } void AbilityWithApplicationsTest::OnStartabilityAms() diff --git a/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp b/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp index a529e853178..2ea8b76aa7a 100644 --- a/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp +++ b/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp @@ -86,7 +86,8 @@ public: public: std::shared_ptr abilityRecord_ {nullptr}; - std::shared_ptr abilityMs_ = DelayedSingleton::GetInstance(); + std::shared_ptr callback_ {nullptr}; + std::shared_ptr abilityMs_ {nullptr}; }; void AbilityMsAppmsTest::OnStartabilityAms() @@ -134,20 +135,18 @@ void AbilityMsAppmsTest::OnStartabilityAms() } void AbilityMsAppmsTest::SetUpTestCase(void) -{ - DelayedSingleton::GetInstance()->RegisterSystemAbility( - OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService()); - DelayedSingleton::GetInstance()->Init(std::make_shared()); -} - +{} void AbilityMsAppmsTest::TearDownTestCase(void) -{ - OHOS::DelayedSingleton::DestroyInstance(); - DelayedSingleton::DestroyInstance(); -} +{} void AbilityMsAppmsTest::SetUp(void) { + DelayedSingleton::GetInstance()->RegisterSystemAbility( + OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService()); + DelayedSingleton::GetInstance(); + callback_ = std::make_shared(); + DelayedSingleton::GetInstance()->Init(callback_); + abilityMs_ = DelayedSingleton::GetInstance(); OnStartabilityAms(); StartAbility(); GTEST_LOG_(INFO) << "SetUp"; @@ -155,7 +154,8 @@ void AbilityMsAppmsTest::SetUp(void) void AbilityMsAppmsTest::TearDown(void) { - abilityMs_->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); + DelayedSingleton::DestroyInstance(); GTEST_LOG_(INFO) << "TearDown"; } diff --git a/services/abilitymgr/test/unittest/phone/kernal_system_app_manager_test/kernal_system_app_manager_test.cpp b/services/abilitymgr/test/unittest/phone/kernal_system_app_manager_test/kernal_system_app_manager_test.cpp index 73f7fdbb841..8d5191d5e1d 100644 --- a/services/abilitymgr/test/unittest/phone/kernal_system_app_manager_test/kernal_system_app_manager_test.cpp +++ b/services/abilitymgr/test/unittest/phone/kernal_system_app_manager_test/kernal_system_app_manager_test.cpp @@ -74,12 +74,15 @@ void KernalSystemAppManagerTest::SetUpTestCase() int systemAbilityId = 401; OHOS::DelayedSingleton::GetInstance()->RegisterSystemAbility( systemAbilityId, new (std::nothrow) AppExecFwk::BundleMgrService()); + DelayedSingleton::GetInstance(); DelayedSingleton::GetInstance()->OnStart(); } void KernalSystemAppManagerTest::TearDownTestCase() { OHOS::DelayedSingleton::GetInstance()->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); + OHOS::DelayedSingleton::DestroyInstance(); } diff --git a/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp b/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp index 26defef799b..4870fe569ab 100644 --- a/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp +++ b/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp @@ -80,7 +80,7 @@ public: public: int startLancherFlag_ = false; - std::shared_ptr abilityMs_ = OHOS::DelayedSingleton::GetInstance(); + std::shared_ptr abilityMs_ {nullptr}; std::shared_ptr launcherAbilityRecord_ {nullptr}; // launcher ability OHOS::sptr launcherToken_ {nullptr}; // token of launcher ability std::shared_ptr nextAbilityRecord_ {nullptr}; // ability being launched @@ -143,6 +143,7 @@ void LifecycleTest::TearDownTestCase(void) void LifecycleTest::SetUp(void) { + abilityMs_ = OHOS::DelayedSingleton::GetInstance(); OnStartabilityAms(); WaitUntilTaskFinished(); StartLauncherAbility(); @@ -151,7 +152,11 @@ void LifecycleTest::SetUp(void) void LifecycleTest::TearDown(void) { - abilityMs_->OnStop(); + abilityMs_->eventLoop_->Stop(); + abilityMs_->eventLoop_.reset(); + abilityMs_->handler_.reset(); + abilityMs_->state_ = ServiceRunningState::STATE_NOT_START; + OHOS::DelayedSingleton::DestroyInstance(); launcherAbilityRecord_.reset(); launcherToken_ = nullptr; nextAbilityRecord_.reset(); @@ -159,6 +164,7 @@ void LifecycleTest::TearDown(void) launcherScheduler_ = nullptr; nextScheduler_ = nullptr; command_.reset(); + abilityMs_ = nullptr; startLancherFlag_ = false; } diff --git a/services/abilitymgr/test/unittest/phone/pending_want_manager_test/pending_want_manager_test.cpp b/services/abilitymgr/test/unittest/phone/pending_want_manager_test/pending_want_manager_test.cpp index db35827b343..95e043170d1 100644 --- a/services/abilitymgr/test/unittest/phone/pending_want_manager_test/pending_want_manager_test.cpp +++ b/services/abilitymgr/test/unittest/phone/pending_want_manager_test/pending_want_manager_test.cpp @@ -132,6 +132,7 @@ void PendingWantManagerTest::SetUp() void PendingWantManagerTest::TearDown() { abilityMs_->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); } WantSenderInfo PendingWantManagerTest::MakeWantSenderInfo(Want &want, int32_t flags, int32_t userId, int32_t type) diff --git a/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp b/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp index b010a495b5e..078735a877c 100644 --- a/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp +++ b/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp @@ -193,7 +193,12 @@ void TerminateAbilityTest::SetUp(void) void TerminateAbilityTest::TearDown(void) { - g_aams->OnStop(); + g_aams->eventLoop_->Stop(); + g_aams->eventLoop_.reset(); + g_aams->handler_.reset(); + g_aams->state_ = ServiceRunningState::STATE_NOT_START; + OHOS::DelayedSingleton::DestroyInstance(); + g_aams = nullptr; } bool TerminateAbilityTest::StartAbility( diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 659ac291268..53fdabdc245 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -1721,23 +1721,9 @@ void AppMgrServiceInner::StartResidentProcess(const std::vector &inf } for (auto &bundle : infos) { - auto processName = bundle.applicationInfo.process.empty() ? - bundle.applicationInfo.bundleName : bundle.applicationInfo.process; + auto processName = + bundle.applicationInfo.process.empty() ? bundle.applicationInfo.bundleName : bundle.applicationInfo.process; APP_LOGI("processName = [%{public}s]", processName.c_str()); - - bool allElementNameEmpty = true; - for (auto hapModuleInfo : bundle.hapModuleInfos) { - if (!hapModuleInfo.mainElementName.empty()) { - // already start main element and process, no need start process again - allElementNameEmpty = false; - break; - } - } - if (!allElementNameEmpty) { - APP_LOGW("processName [%{public}s] Already exists ", processName.c_str()); - continue; - } - // Inspection records auto appRecord = appRunningManager_->CheckAppRunningRecordIsExist( bundle.applicationInfo.name, processName, bundle.applicationInfo.uid, bundle); diff --git a/services/appmgr/test/mock/src/mock_bundle_manager.cpp b/services/appmgr/test/mock/src/mock_bundle_manager.cpp index ca3ec28c311..562ad2b5c03 100644 --- a/services/appmgr/test/mock/src/mock_bundle_manager.cpp +++ b/services/appmgr/test/mock/src/mock_bundle_manager.cpp @@ -52,6 +52,7 @@ bool BundleMgrProxy::GetApplicationInfo( std::string BundleMgrProxy::GetAppType(const std::string &bundleName) { + GTEST_LOG_(INFO) << " BundleMgrProxy::GetAppTyp"; return "system"; } @@ -104,17 +105,20 @@ bool BundleMgrService::GetApplicationInfo( std::string BundleMgrService::GetAppType(const std::string &bundleName) { + GTEST_LOG_(INFO) << " BundleMgrService::GetAppType"; return "system"; } bool BundleMgrService::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) { + GTEST_LOG_(INFO) << " BundleMgrService::GetHapModuleInfo"; hapModuleInfo.name = "Captain"; return true; } bool BundleMgrProxy::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) { + GTEST_LOG_(INFO) << " BundleMgrService::GetHapModuleInfo"; hapModuleInfo.name = "Captain"; return true; } diff --git a/services/appmgr/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp b/services/appmgr/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp index 1a1d2e20a58..2b4ebe05821 100644 --- a/services/appmgr/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp +++ b/services/appmgr/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp @@ -86,7 +86,6 @@ protected: std::shared_ptr serviceInner_; sptr mock_token_ = nullptr; sptr mockBundleMgr = nullptr; - std::shared_ptr runner_ = nullptr; std::shared_ptr handler_ = nullptr; sptr mockAppStateCallbackStub_ = nullptr; }; @@ -104,17 +103,13 @@ void AmsAppLifeCycleTest::SetUp() mockBundleMgr = new (std::nothrow) BundleMgrService(); serviceInner_->SetBundleManager(mockBundleMgr); - runner_ = EventRunner::Create("AmsAppLifeCycleTest"); - handler_ = std::make_shared(runner_, serviceInner_); + auto runner = EventRunner::Create("AmsAppLifeCycleTest"); + handler_ = std::make_shared(runner, serviceInner_); serviceInner_->SetEventHandler(handler_); } void AmsAppLifeCycleTest::TearDown() -{ - serviceInner_ = nullptr; - handler_ = nullptr; - runner_.reset(); -} +{} std::shared_ptr AmsAppLifeCycleTest::StartProcessAndLoadAbility(const sptr &token, const sptr &preToken, const std::shared_ptr &abilityInfo, @@ -1481,6 +1476,68 @@ HWTEST_F(AmsAppLifeCycleTest, KillApplication_001, TestSize.Level1) EXPECT_EQ(ERR_OK, result); } +/* + * Feature: AMS + * Function: AppLifeCycle + * SubFunction: Schedule + * FunctionPoints: Kill application + * CaseDescription: Verify if AppMgrService Kill by appname successfully. + */ +HWTEST_F(AmsAppLifeCycleTest, KillApplication_002, TestSize.Level1) +{ + const pid_t NEW_PID = 123; + auto abilityInfo = GetAbilityInfoByIndex("0"); + auto appInfo = GetApplication(); + sptr token = GetMockToken(); + + std::shared_ptr mockClientPtr = std::make_shared(); + EXPECT_CALL(*mockClientPtr, StartProcess(_, _)).Times(1).WillOnce(DoAll(SetArgReferee<1>(NEW_PID), Return(ERR_OK))); + + serviceInner_->SetAppSpawnClient(mockClientPtr); + + serviceInner_->LoadAbility(token, nullptr, abilityInfo, appInfo); + BundleInfo bundleInfo; + bundleInfo.appId = "com.ohos.test.helloworld_code123"; + auto appRecord = serviceInner_->appRunningManager_->CheckAppRunningRecordIsExist( + appInfo->name, appInfo->name, appInfo->uid, bundleInfo); + EXPECT_EQ(appRecord->GetPriorityObject()->GetPid(), NEW_PID); + + pid_t pid = fork(); + if (pid > 0) { + appRecord->GetPriorityObject()->SetPid(pid); + } + + sptr mockAppScheduler = new MockAppScheduler(); + sptr client = iface_cast(mockAppScheduler.GetRefPtr()); + appRecord->SetApplicationClient(client); + EXPECT_CALL(*mockAppScheduler, ScheduleProcessSecurityExit()).Times(1); + + int ret = serviceInner_->KillApplication(abilityInfo->applicationName); + EXPECT_EQ(ERR_OK, ret); +} + +/* + * Feature: AMS + * Function: AppLifeCycle + * SubFunction: Schedule + * FunctionPoints: Kill application + * CaseDescription: Verify if AppMgrService Kill by pid successfully. + */ +HWTEST_F(AmsAppLifeCycleTest, KillProcessByPid001, TestSize.Level1) +{ + pid_t pid = fork(); + + if (pid > 0) { + int32_t ret = serviceInner_->KillProcessByPid(pid); + EXPECT_EQ(ERR_OK, ret); + } + + if (pid == 0) { + int32_t ret = serviceInner_->KillProcessByPid(pid); + EXPECT_EQ(-1, ret); + } +} + /* * Feature: AMS * Function: AppLifeCycle @@ -1837,6 +1894,33 @@ HWTEST_F(AmsAppLifeCycleTest, ClearUpApplicationData_001, TestSize.Level1) serviceInner_->ClearUpApplicationData(appRecord->GetBundleName(), appRecord->GetUid(), NEW_PID); } +/* + * Feature: AMS + * Function: AppLifeCycle + * SubFunction: ClearUpApplicationData + * FunctionPoints: UnsuspendApplication + * CaseDescription: test application state is APP_STATE_BACKGROUND(apprecord is nullptr) + */ +HWTEST_F(AmsAppLifeCycleTest, ClearUpApplicationData_002, TestSize.Level1) +{ + auto abilityInfo = GetAbilityInfoByIndex("110"); + auto appInfo = GetApplication(); + sptr token = GetMockToken(); + + int32_t pid = fork(); + + if (pid > 0) { + auto appRecord = StartProcessAndLoadAbility(token, nullptr, abilityInfo, appInfo, pid); + + EXPECT_CALL(*mockBundleMgr, CleanBundleDataFiles(_, _)).Times(1).WillOnce(Return(101)); + appRecord->SetUid(101); + sptr mockAppScheduler = new MockAppScheduler(); + sptr client = iface_cast(mockAppScheduler.GetRefPtr()); + appRecord->SetApplicationClient(client); + serviceInner_->ClearUpApplicationData(appRecord->GetBundleName(), appRecord->GetUid(), pid); + } +} + /* * Feature: AMS * Function: AppLifeCycle::IsBackgroundRunningRestricted diff --git a/services/appmgr/test/unittest/ams_service_event_drive_test/ams_service_event_drive_test.cpp b/services/appmgr/test/unittest/ams_service_event_drive_test/ams_service_event_drive_test.cpp index f17bbdbe689..093b1e7ccb9 100644 --- a/services/appmgr/test/unittest/ams_service_event_drive_test/ams_service_event_drive_test.cpp +++ b/services/appmgr/test/unittest/ams_service_event_drive_test/ams_service_event_drive_test.cpp @@ -47,7 +47,7 @@ public: std::shared_ptr GetAmsEventHandler(); protected: - std::shared_ptr appMgrService_ = std::make_shared(); + std::shared_ptr appMgrService_; }; void AmsServiceEventDriveTest::SetUpTestCase() @@ -58,13 +58,11 @@ void AmsServiceEventDriveTest::TearDownTestCase() void AmsServiceEventDriveTest::SetUp() { - appMgrService_->OnStart(); + appMgrService_ = std::make_shared(); } void AmsServiceEventDriveTest::TearDown() -{ - appMgrService_->OnStop(); -} +{} /* * Feature: AppMgrService @@ -286,7 +284,6 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_009, TestSize.Level1) { APP_LOGI("ams_service_event_drive_test_009 start"); - appMgrService_->OnStop(); std::shared_ptr innerService = std::make_shared(); appMgrService_->SetInnerService(innerService); @@ -310,7 +307,6 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_010, TestSize.Level1) { APP_LOGI("ams_service_event_drive_test_010 start"); - appMgrService_->OnStop(); std::shared_ptr innerService = std::make_shared(); appMgrService_->SetInnerService(innerService); @@ -334,7 +330,6 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_011, TestSize.Level1) { APP_LOGI("ams_service_event_drive_test_011 start"); - appMgrService_->OnStop(); std::shared_ptr innerService = std::make_shared(); appMgrService_->SetInnerService(innerService); @@ -358,7 +353,6 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_012, TestSize.Level1) { APP_LOGI("ams_service_event_drive_test_012 start"); - appMgrService_->OnStop(); std::shared_ptr innerService = std::make_shared(); appMgrService_->SetInnerService(innerService); @@ -382,7 +376,6 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_013, TestSize.Level1) { APP_LOGI("ams_service_event_drive_test_013 start"); - appMgrService_->OnStop(); std::shared_ptr innerService = std::make_shared(); appMgrService_->SetInnerService(innerService); @@ -406,7 +399,6 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_014, TestSize.Level1) { APP_LOGI("ams_service_event_drive_test_014 start"); - appMgrService_->OnStop(); std::shared_ptr innerService = std::make_shared(); appMgrService_->SetInnerService(innerService); @@ -430,7 +422,6 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_015, TestSize.Level1) { APP_LOGI("ams_service_event_drive_test_015 start"); - appMgrService_->OnStop(); std::shared_ptr innerService = std::make_shared(); appMgrService_->SetInnerService(innerService); @@ -452,7 +443,6 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_016, TestSize.Level1) { APP_LOGI("ams_service_event_drive_test_016 start"); - appMgrService_->OnStop(); std::shared_ptr innerService = std::make_shared(); appMgrService_->SetInnerService(innerService); @@ -866,7 +856,6 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_035, TestSize.Level1) { APP_LOGI("ams_service_event_drive_test_035 start"); - appMgrService_->OnStop(); std::shared_ptr innerService = std::make_shared(); appMgrService_->SetInnerService(innerService); @@ -939,7 +928,6 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_038, TestSize.Level1) { APP_LOGI("ams_service_event_drive_test_038 start"); - appMgrService_->OnStop(); std::shared_ptr innerService = std::make_shared(); appMgrService_->SetInnerService(innerService); @@ -982,6 +970,7 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_039, TestSize.Level1) * EnvConditions: Mobile that can run ohos test framework * CaseDescription: Verify if QueryServiceState act normal after AppMgrService stopped */ +/* HWTEST_F(AmsServiceEventDriveTest, EventDrive_040, TestSize.Level1) { APP_LOGI("AppMgrService::EventDrive_040 start 1"); @@ -1001,6 +990,7 @@ HWTEST_F(AmsServiceEventDriveTest, EventDrive_040, TestSize.Level1) APP_LOGI("AppMgrService::EventDrive_040 end"); } +*/ /* * Feature: AppMgrService diff --git a/services/formmgr/bundle.json b/services/formmgr/bundle.json index fb7f7e2d693..801f14db7b9 100644 --- a/services/formmgr/bundle.json +++ b/services/formmgr/bundle.json @@ -23,13 +23,13 @@ "components": [ "ability_runtime", "ans_standard", - "bundle_framework", + "appexecfwk_standard", "ces_standard", "hiviewdfx_hilog_native", "ipc", "napi", "native_appdatamgr", - "time_native", + "miscservices_time", "os_account_standard", "permission_standard", "power_manager_native", diff --git a/services/formmgr/src/form_mgr_service.cpp b/services/formmgr/src/form_mgr_service.cpp index e61d0f15ae9..7eff4a62a66 100644 --- a/services/formmgr/src/form_mgr_service.cpp +++ b/services/formmgr/src/form_mgr_service.cpp @@ -61,10 +61,8 @@ FormMgrService::FormMgrService() FormMgrService::~FormMgrService() { - if (formSysEventReceiver_ != nullptr) { - EventFwk::CommonEventManager::UnSubscribeCommonEvent(formSysEventReceiver_); - formSysEventReceiver_ = nullptr; - } + EventFwk::CommonEventManager::UnSubscribeCommonEvent(formSysEventReceiver_); + formSysEventReceiver_ = nullptr; } bool FormMgrService::IsReady() const diff --git a/services/formmgr/test/mock/include/mock_ability_manager.h b/services/formmgr/test/mock/include/mock_ability_manager.h index 80b69f608f2..1471e067860 100644 --- a/services/formmgr/test/mock/include/mock_ability_manager.h +++ b/services/formmgr/test/mock/include/mock_ability_manager.h @@ -268,7 +268,7 @@ public: { return 0; } - int NotifyContinuationResult(int32_t missionId, int32_t result) override + int NotifyContinuationResult(int32_t missionId, const int32_t result) override { return 0; } @@ -329,10 +329,7 @@ public: { return 0; } - virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override - { - return 0; - } + virtual int SetMissionLabel(const sptr &token, const std::string &lable) override { @@ -712,7 +709,7 @@ public: { return 0; } - int NotifyContinuationResult(int32_t missionId, int32_t result) override + int NotifyContinuationResult(int32_t missionId, const int32_t result) override { return 0; } @@ -801,10 +798,6 @@ public: { return 0; } - virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override - { - return 0; - } virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override { return 0; diff --git a/services/formmgr/test/unittest/fms_form_host_record_test/fms_form_host_record_test.cpp b/services/formmgr/test/unittest/fms_form_host_record_test/fms_form_host_record_test.cpp index 2388329a8ad..2b29e51a9f8 100644 --- a/services/formmgr/test/unittest/fms_form_host_record_test/fms_form_host_record_test.cpp +++ b/services/formmgr/test/unittest/fms_form_host_record_test/fms_form_host_record_test.cpp @@ -67,13 +67,13 @@ public: protected: sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); + + sptr mockBundleMgr_; + sptr mockAbilityMgrServ_; }; void FmsFormHostRecordTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); - FormAmsHelper::GetInstance().SetAbilityManager(new MockAbilityMgrService()); -} +{} void FmsFormHostRecordTest::TearDownTestCase() {} @@ -81,6 +81,14 @@ void FmsFormHostRecordTest::TearDownTestCase() void FmsFormHostRecordTest::SetUp() { formyMgrServ_->OnStart(); + + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + EXPECT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + + mockAbilityMgrServ_ = new (std::nothrow) MockAbilityMgrService(); + FormAmsHelper::GetInstance().SetAbilityManager(mockAbilityMgrServ_); + token_ = new (std::nothrow) MockFormHostClient(); // Permission install diff --git a/services/formmgr/test/unittest/fms_form_mgr_add_form_test/fms_form_mgr_add_form_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_add_form_test/fms_form_mgr_add_form_test.cpp index f651a81d5c3..e6cad4e0edc 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_add_form_test/fms_form_mgr_add_form_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_add_form_test/fms_form_mgr_add_form_test.cpp @@ -71,20 +71,30 @@ public: protected: sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); + + sptr mockBundleMgr_; + sptr mockAbilityMgrServ_; }; void FmsFormMgrAddFormTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); - FormAmsHelper::GetInstance().SetAbilityManager(new MockAbilityMgrService()); -} +{} void FmsFormMgrAddFormTest::TearDownTestCase() {} void FmsFormMgrAddFormTest::SetUp() { + // APP_LOGI("fms_form_mgr_client_test_001 setup"); formyMgrServ_->OnStart(); + + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + EXPECT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + + mockAbilityMgrServ_ = new (std::nothrow) MockAbilityMgrService(); + FormAmsHelper::GetInstance().SetAbilityManager(mockAbilityMgrServ_); + + // APP_LOGI("fms_form_mgr_client_test_001 FormMgrService started"); token_ = new (std::nothrow) MockFormHostClient(); // Permission install @@ -106,9 +116,7 @@ void FmsFormMgrAddFormTest::SetUp() } void FmsFormMgrAddFormTest::TearDown() -{ - formyMgrServ_->OnStop(); -} +{} /* * Feature: FormMgrService diff --git a/services/formmgr/test/unittest/fms_form_mgr_cast_temp_form_test/fms_form_mgr_cast_temp_form_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_cast_temp_form_test/fms_form_mgr_cast_temp_form_test.cpp index cd116a163b8..9dd4306f69d 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_cast_temp_form_test/fms_form_mgr_cast_temp_form_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_cast_temp_form_test/fms_form_mgr_cast_temp_form_test.cpp @@ -70,13 +70,13 @@ public: protected: sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); + + sptr mockBundleMgr_; + sptr mockAbilityMgrServ_; }; void FmsFormMgrCastTempFormTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); - FormAmsHelper::GetInstance().SetAbilityManager(new MockAbilityMgrService()); -} +{} void FmsFormMgrCastTempFormTest::TearDownTestCase() {} @@ -84,6 +84,14 @@ void FmsFormMgrCastTempFormTest::TearDownTestCase() void FmsFormMgrCastTempFormTest::SetUp() { formyMgrServ_->OnStart(); + + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + ASSERT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + + mockAbilityMgrServ_ = new (std::nothrow) MockAbilityMgrService(); + FormAmsHelper::GetInstance().SetAbilityManager(mockAbilityMgrServ_); + token_ = new (std::nothrow) MockFormHostClient(); // Permission install diff --git a/services/formmgr/test/unittest/fms_form_mgr_death_callback_test/fms_form_mgr_death_callback_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_death_callback_test/fms_form_mgr_death_callback_test.cpp index a28dee10fdd..f9b45712fd4 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_death_callback_test/fms_form_mgr_death_callback_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_death_callback_test/fms_form_mgr_death_callback_test.cpp @@ -72,20 +72,30 @@ public: protected: sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); + + sptr mockBundleMgr_; + sptr mockAbilityMgrServ_; }; void FmsFormMgrDeathCallbackTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); - FormAmsHelper::GetInstance().SetAbilityManager(new MockAbilityMgrService()); -} +{} void FmsFormMgrDeathCallbackTest::TearDownTestCase() {} void FmsFormMgrDeathCallbackTest::SetUp() { + // APP_LOGI("fms_form_mgr_client_test_001 setup"); formyMgrServ_->OnStart(); + + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + EXPECT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + + mockAbilityMgrServ_ = new (std::nothrow) MockAbilityMgrService(); + FormAmsHelper::GetInstance().SetAbilityManager(mockAbilityMgrServ_); + + // APP_LOGI("fms_form_mgr_client_test_001 FormMgrService started"); token_ = new (std::nothrow) MockFormHostClient(); // Permission install diff --git a/services/formmgr/test/unittest/fms_form_mgr_delete_form_test/fms_form_mgr_delete_form_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_delete_form_test/fms_form_mgr_delete_form_test.cpp index 0f35979671f..d0ec63205f1 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_delete_form_test/fms_form_mgr_delete_form_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_delete_form_test/fms_form_mgr_delete_form_test.cpp @@ -67,13 +67,13 @@ public: protected: sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); + + sptr mockBundleMgr_; + sptr mockAbilityMgrServ_; }; void FmsFormMgrDeleteFormTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); - FormAmsHelper::GetInstance().SetAbilityManager(new MockAbilityMgrService()); -} +{} void FmsFormMgrDeleteFormTest::TearDownTestCase() {} @@ -81,6 +81,14 @@ void FmsFormMgrDeleteFormTest::TearDownTestCase() void FmsFormMgrDeleteFormTest::SetUp() { formyMgrServ_->OnStart(); + + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + EXPECT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + + mockAbilityMgrServ_ = new (std::nothrow) MockAbilityMgrService(); + FormAmsHelper::GetInstance().SetAbilityManager(mockAbilityMgrServ_); + token_ = new (std::nothrow) MockFormHostClient(); // Permission install diff --git a/services/formmgr/test/unittest/fms_form_mgr_lifecycle_update_test/fms_form_mgr_lifecycle_update_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_lifecycle_update_test/fms_form_mgr_lifecycle_update_test.cpp index 1718061927e..045433d88f0 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_lifecycle_update_test/fms_form_mgr_lifecycle_update_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_lifecycle_update_test/fms_form_mgr_lifecycle_update_test.cpp @@ -56,22 +56,27 @@ public: void InitFormItemInfo(int64_t formId, FormItemInfo &formItemInfo) const; protected: + sptr mockBundleMgr_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); sptr token_; }; void FmsFormMgrLifecycleUpdateTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); -} +{} void FmsFormMgrLifecycleUpdateTest::TearDownTestCase() {} void FmsFormMgrLifecycleUpdateTest::SetUp() { + // APP_LOGI("fms_form_mgr_enable_update_test_001 setup"); formyMgrServ_->OnStart(); + // mock BundleMgr + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + ASSERT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + // token token_ = new (std::nothrow) MockFormHostClient(); diff --git a/services/formmgr/test/unittest/fms_form_mgr_message_event_test/fms_form_mgr_message_event_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_message_event_test/fms_form_mgr_message_event_test.cpp index cc7870b1dcf..efa7bc17664 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_message_event_test/fms_form_mgr_message_event_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_message_event_test/fms_form_mgr_message_event_test.cpp @@ -69,13 +69,13 @@ public: protected: sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); + + sptr mockBundleMgr_; + sptr mockAbilityMgrServ_; }; void FmsFormMgrMessageEventTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); - FormAmsHelper::GetInstance().SetAbilityManager(new MockAbilityMgrService()); -} +{} void FmsFormMgrMessageEventTest::TearDownTestCase() {} @@ -83,6 +83,14 @@ void FmsFormMgrMessageEventTest::TearDownTestCase() void FmsFormMgrMessageEventTest::SetUp() { formyMgrServ_->OnStart(); + + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + EXPECT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + + mockAbilityMgrServ_ = new (std::nothrow) MockAbilityMgrService(); + FormAmsHelper::GetInstance().SetAbilityManager(mockAbilityMgrServ_); + token_ = new (std::nothrow) MockFormHostClient(); // Permission install diff --git a/services/formmgr/test/unittest/fms_form_mgr_notify_invisible_forms_test/fms_form_mgr_notify_invisible_forms_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_notify_invisible_forms_test/fms_form_mgr_notify_invisible_forms_test.cpp index bb38d6a70fd..4f5adb32364 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_notify_invisible_forms_test/fms_form_mgr_notify_invisible_forms_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_notify_invisible_forms_test/fms_form_mgr_notify_invisible_forms_test.cpp @@ -45,27 +45,36 @@ const std::string DEF_LABEL1 = "PermissionFormRequireGrant"; class FmsFormMgrNotifyInvisibleFormsTest : public testing::Test { public: + FmsFormMgrNotifyInvisibleFormsTest() : formMgrService_(nullptr) + {} + ~FmsFormMgrNotifyInvisibleFormsTest() + {} static void SetUpTestCase(void); static void TearDownTestCase(void); void SetUp(); void TearDown(); protected: sptr token_; - std::shared_ptr formMgrService_; + sptr mockBundleMgr_; + std::shared_ptr formMgrService_ = DelayedSingleton::GetInstance(); }; void FmsFormMgrNotifyInvisibleFormsTest::SetUpTestCase(void) -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); -} +{} void FmsFormMgrNotifyInvisibleFormsTest::TearDownTestCase(void) {} void FmsFormMgrNotifyInvisibleFormsTest::SetUp(void) { - formMgrService_ = DelayedSingleton::GetInstance(); + formMgrService_ = std::make_shared(); + formMgrService_->OnStart(); + // mock BundleMgr + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + ASSERT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + // token token_ = new (std::nothrow) OHOS::AppExecFwk::MockFormHostClient(); @@ -91,10 +100,7 @@ void FmsFormMgrNotifyInvisibleFormsTest::SetUp(void) } void FmsFormMgrNotifyInvisibleFormsTest::TearDown(void) -{ - formMgrService_->OnStop(); - token_ = nullptr; -} +{} /** * @tc.number: FmsFormMgrNotifyInvisibleFormsTest_NotifyInvisibleForms_002 diff --git a/services/formmgr/test/unittest/fms_form_mgr_notify_visible_forms_test/fms_form_mgr_notify_visible_forms_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_notify_visible_forms_test/fms_form_mgr_notify_visible_forms_test.cpp index a5d4d7f233e..843686dbc7c 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_notify_visible_forms_test/fms_form_mgr_notify_visible_forms_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_notify_visible_forms_test/fms_form_mgr_notify_visible_forms_test.cpp @@ -56,20 +56,23 @@ public: void TearDown(); protected: sptr token_; - std::shared_ptr formMgrService_; + sptr mockBundleMgr_; + std::shared_ptr formMgrService_ = DelayedSingleton::GetInstance(); }; void FmsFormMgrNotifyVisibleFormsTest::SetUpTestCase(void) -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); -} +{} void FmsFormMgrNotifyVisibleFormsTest::TearDownTestCase(void) {} void FmsFormMgrNotifyVisibleFormsTest::SetUp(void) { - formMgrService_ = DelayedSingleton::GetInstance(); + formMgrService_ = std::make_shared(); formMgrService_->OnStart(); + + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + ASSERT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); token_ = new (std::nothrow) MockFormHostClient(); // Permission install diff --git a/services/formmgr/test/unittest/fms_form_mgr_release_form_test/fms_form_mgr_release_form_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_release_form_test/fms_form_mgr_release_form_test.cpp index d8122862fcb..ca8bdd6c2a4 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_release_form_test/fms_form_mgr_release_form_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_release_form_test/fms_form_mgr_release_form_test.cpp @@ -62,12 +62,11 @@ public: protected: sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); + sptr mockBundleMgr_; }; void FmsFormMgrReleaseFormTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); -} +{} void FmsFormMgrReleaseFormTest::TearDownTestCase() {} @@ -75,6 +74,9 @@ void FmsFormMgrReleaseFormTest::TearDownTestCase() void FmsFormMgrReleaseFormTest::SetUp() { formyMgrServ_->OnStart(); + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + ASSERT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); token_ = new (std::nothrow) MockFormHostClient(); // Permission install diff --git a/services/formmgr/test/unittest/fms_form_mgr_request_form_test/fms_form_mgr_request_form_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_request_form_test/fms_form_mgr_request_form_test.cpp index 08af6003557..feaecd16054 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_request_form_test/fms_form_mgr_request_form_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_request_form_test/fms_form_mgr_request_form_test.cpp @@ -57,15 +57,14 @@ public: void TearDown(); protected: + sptr mockAbilityMgrServ_; + sptr mockBundleMgr_; sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); }; void FmsFormMgrRequestFormTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); - FormAmsHelper::GetInstance().SetAbilityManager(new MockAbilityMgrService()); -} +{} void FmsFormMgrRequestFormTest::TearDownTestCase() {} @@ -73,8 +72,15 @@ void FmsFormMgrRequestFormTest::TearDownTestCase() void FmsFormMgrRequestFormTest::SetUp() { formyMgrServ_->OnStart(); + token_ = new (std::nothrow) MockFormHostClient(); + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + ASSERT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + + mockAbilityMgrServ_ = new (std::nothrow) MockAbilityMgrService(); + FormAmsHelper::GetInstance().SetAbilityManager(mockAbilityMgrServ_); // Permission install std::vector permList; Permission::PermissionDef permDef; diff --git a/services/formmgr/test/unittest/fms_form_mgr_update_form_test/fms_form_mgr_update_form_test.cpp b/services/formmgr/test/unittest/fms_form_mgr_update_form_test/fms_form_mgr_update_form_test.cpp index 311ee272f6f..559958c4f72 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_update_form_test/fms_form_mgr_update_form_test.cpp +++ b/services/formmgr/test/unittest/fms_form_mgr_update_form_test/fms_form_mgr_update_form_test.cpp @@ -63,13 +63,13 @@ public: protected: sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); + + sptr mockBundleMgr_; + sptr mockAbilityMgrServ_; }; void FmsFormMgrUpdateFormTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); - FormAmsHelper::GetInstance().SetAbilityManager(new MockAbilityMgrService()); -} +{} void FmsFormMgrUpdateFormTest::TearDownTestCase() {} @@ -77,7 +77,16 @@ void FmsFormMgrUpdateFormTest::TearDownTestCase() void FmsFormMgrUpdateFormTest::SetUp() { APP_LOGI("fms_form_mgr_client_updateForm_test_001 setup"); + formyMgrServ_->OnStart(); + + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + ASSERT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + + mockAbilityMgrServ_ = new (std::nothrow) MockAbilityMgrService(); + FormAmsHelper::GetInstance().SetAbilityManager(mockAbilityMgrServ_); + token_ = new (std::nothrow) MockFormHostClient(); // Permission install diff --git a/services/formmgr/test/unittest/fms_form_provider_mgr_test/fms_form_provider_mgr_test.cpp b/services/formmgr/test/unittest/fms_form_provider_mgr_test/fms_form_provider_mgr_test.cpp index a7ccb2ab73e..cec93e35f57 100644 --- a/services/formmgr/test/unittest/fms_form_provider_mgr_test/fms_form_provider_mgr_test.cpp +++ b/services/formmgr/test/unittest/fms_form_provider_mgr_test/fms_form_provider_mgr_test.cpp @@ -68,20 +68,30 @@ public: protected: sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); + + sptr mockBundleMgr_; + sptr mockAbilityMgrServ_; }; void FmsFormProviderMgrTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); - FormAmsHelper::GetInstance().SetAbilityManager(new MockAbilityMgrService()); -} +{} void FmsFormProviderMgrTest::TearDownTestCase() {} void FmsFormProviderMgrTest::SetUp() { + // APP_LOGI("fms_form_mgr_client_test_001 setup"); formyMgrServ_->OnStart(); + + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + EXPECT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + + mockAbilityMgrServ_ = new (std::nothrow) MockAbilityMgrService(); + FormAmsHelper::GetInstance().SetAbilityManager(mockAbilityMgrServ_); + + // APP_LOGI("fms_form_mgr_client_test_001 FormMgrService started"); token_ = new (std::nothrow) MockFormHostClient(); // Permission install diff --git a/services/formmgr/test/unittest/fms_form_set_next_refresh_test/fms_form_set_next_refresh_test.cpp b/services/formmgr/test/unittest/fms_form_set_next_refresh_test/fms_form_set_next_refresh_test.cpp index 7d18793db1e..c363f16e3a2 100644 --- a/services/formmgr/test/unittest/fms_form_set_next_refresh_test/fms_form_set_next_refresh_test.cpp +++ b/services/formmgr/test/unittest/fms_form_set_next_refresh_test/fms_form_set_next_refresh_test.cpp @@ -49,32 +49,35 @@ public: {} ~FmsFormSetNextRefreshTest() {} + std::shared_ptr formSetNextRefresh_ = DelayedSingleton::GetInstance(); static void SetUpTestCase(void); static void TearDownTestCase(void); void SetUp(); void TearDown(); protected: - std::shared_ptr formSetNextRefresh_; + sptr mockBundleMgr_; }; - void FmsFormSetNextRefreshTest::SetUpTestCase(void) -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); -} +{} void FmsFormSetNextRefreshTest::TearDownTestCase(void) {} void FmsFormSetNextRefreshTest::SetUp(void) { - formSetNextRefresh_ = DelayedSingleton::GetInstance(); + formSetNextRefresh_ = std::make_shared(); + formSetNextRefresh_->OnStart(); + + // mock BundleMgr + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + ASSERT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); } void FmsFormSetNextRefreshTest::TearDown(void) -{ - formSetNextRefresh_->OnStop(); -} +{} + /** * @tc.number: FmsFormSetNextRefreshTest_SetNextRefreshTime_001 diff --git a/services/formmgr/test/unittest/fms_form_sys_event_receiver_test/fms_form_sys_event_receiver_test.cpp b/services/formmgr/test/unittest/fms_form_sys_event_receiver_test/fms_form_sys_event_receiver_test.cpp index 15ec5785933..ada590a92a1 100644 --- a/services/formmgr/test/unittest/fms_form_sys_event_receiver_test/fms_form_sys_event_receiver_test.cpp +++ b/services/formmgr/test/unittest/fms_form_sys_event_receiver_test/fms_form_sys_event_receiver_test.cpp @@ -82,20 +82,30 @@ public: protected: sptr token_; std::shared_ptr formyMgrServ_ = DelayedSingleton::GetInstance(); + + sptr mockBundleMgr_; + sptr mockAbilityMgrServ_; }; void FmsFormSysEventReceiverTest::SetUpTestCase() -{ - FormBmsHelper::GetInstance().SetBundleManager(new BundleMgrService()); - FormAmsHelper::GetInstance().SetAbilityManager(new MockAbilityMgrService()); -} +{} void FmsFormSysEventReceiverTest::TearDownTestCase() {} void FmsFormSysEventReceiverTest::SetUp() { + // APP_LOGI("fms_form_mgr_client_test_001 setup"); formyMgrServ_->OnStart(); + + mockBundleMgr_ = new (std::nothrow) BundleMgrService(); + EXPECT_TRUE(mockBundleMgr_ != nullptr); + FormBmsHelper::GetInstance().SetBundleManager(mockBundleMgr_); + + mockAbilityMgrServ_ = new (std::nothrow) MockAbilityMgrService(); + FormAmsHelper::GetInstance().SetAbilityManager(mockAbilityMgrServ_); + + // APP_LOGI("fms_form_mgr_client_test_001 FormMgrService started"); token_ = new (std::nothrow) MockFormHostClient(); // Permission install diff --git a/services/formmgr/test/unittest/fms_form_timer_mgr_test/fms_form_timer_mgr_test.cpp b/services/formmgr/test/unittest/fms_form_timer_mgr_test/fms_form_timer_mgr_test.cpp index 0e1a0d43edc..e41de5bc00a 100644 --- a/services/formmgr/test/unittest/fms_form_timer_mgr_test/fms_form_timer_mgr_test.cpp +++ b/services/formmgr/test/unittest/fms_form_timer_mgr_test/fms_form_timer_mgr_test.cpp @@ -539,6 +539,9 @@ HWTEST_F(FmsFormTimerMgrTest, Fms_FormTimerMgr_0027, Function | MediumTest | Lev GTEST_LOG_(INFO) << "Fms_FormTimerMgr_0027 start"; bool isAddOk4 = FormTimerMgr::GetInstance().AddFormTimer(PARAM_FORM_ID_VALUE_6, 10, 30, 0); EXPECT_EQ(isAddOk4, true); + + std::this_thread::sleep_for(std::chrono::milliseconds(Constants::MIN_PERIOD)); + GTEST_LOG_(INFO) << "Fms_FormTimerMgr_0027 end"; } } diff --git a/services/test/mock/include/appmgr/mock_ability_mgr_host.h b/services/test/mock/include/appmgr/mock_ability_mgr_host.h index 171319d34d7..3707f0dd010 100644 --- a/services/test/mock/include/appmgr/mock_ability_mgr_host.h +++ b/services/test/mock/include/appmgr/mock_ability_mgr_host.h @@ -313,7 +313,7 @@ public: { return 0; } - int NotifyContinuationResult(int32_t missionId, int32_t result) override + int NotifyContinuationResult(int32_t missionId, const int32_t result) override { return 0; } @@ -375,10 +375,6 @@ public: { return 0; } - virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override - { - return 0; - } virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override { return 0; diff --git a/services/test/mock/include/mock_ability_mgr_service.h b/services/test/mock/include/mock_ability_mgr_service.h index 385f2b969d4..83fe2e1c4b3 100644 --- a/services/test/mock/include/mock_ability_mgr_service.h +++ b/services/test/mock/include/mock_ability_mgr_service.h @@ -96,7 +96,7 @@ public: MOCK_METHOD1(SetShowOnLockScreen, int(bool isAllow)); MOCK_METHOD1(GetSystemMemoryAttr, void(AppExecFwk::SystemMemoryAttr &memoryInfo)); MOCK_METHOD3(StartContinuation, int(const Want &want, const sptr &abilityToken, int32_t status)); - MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, const int32_t result)); MOCK_METHOD5(ContinueMission, int(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams)); MOCK_METHOD2(ContinueAbility, int(const std::string &deviceId, int32_t missionId)); @@ -112,7 +112,6 @@ public: MOCK_METHOD1(CleanMission, int(int32_t missionId)); MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); - MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); MOCK_METHOD2(SetMissionLabel, int(const sptr &token, const std::string &label)); MOCK_METHOD1(ClearUpApplicationData, int(const std::string &)); diff --git a/services/test/mock/include/mock_ability_scheduler.h b/services/test/mock/include/mock_ability_scheduler.h index a5ab5274fef..b4afe3f78cc 100755 --- a/services/test/mock/include/mock_ability_scheduler.h +++ b/services/test/mock/include/mock_ability_scheduler.h @@ -42,9 +42,9 @@ public: ScheduleUnregisterObserver, bool(const Uri &uri, const sptr &dataObserver)); MOCK_METHOD1(ScheduleNotifyChange, bool(const Uri &uri)); MOCK_METHOD1(ExecuteBatch, std::vector>(const std::vector> &operations)); - MOCK_METHOD1(NotifyContinuationResult, void(int32_t result)); + MOCK_METHOD1(NotifyContinuationResult, void(const int32_t result)); MOCK_METHOD1(ContinueAbility, void(const std::string& deviceId)); - MOCK_METHOD2(DumpAbilityInfo, void(const std::vector ¶ms, std::vector &info)); + MOCK_METHOD1(DumpAbilityInfo, void(std::vector &info)); std::vector GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter) { std::vector types; diff --git a/services/test/mock/include/mock_ability_scheduler_stub.h b/services/test/mock/include/mock_ability_scheduler_stub.h index 5e36df317ad..1913d5afb08 100755 --- a/services/test/mock/include/mock_ability_scheduler_stub.h +++ b/services/test/mock/include/mock_ability_scheduler_stub.h @@ -51,9 +51,9 @@ public: MOCK_METHOD1(ScheduleNotifyChange, bool(const Uri &uri)); MOCK_METHOD1(ExecuteBatch, std::vector>( const std::vector> &operations)); - MOCK_METHOD1(NotifyContinuationResult, void(int32_t result)); + MOCK_METHOD1(NotifyContinuationResult, void(const int32_t result)); MOCK_METHOD1(ContinueAbility, void(const std::string& deviceId)); - MOCK_METHOD2(DumpAbilityInfo, void(const std::vector ¶ms, std::vector &info)); + MOCK_METHOD1(DumpAbilityInfo, void(std::vector &info)); virtual sptr CallRequest() { diff --git a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp index 707fce1de92..1c49229fb3f 100644 --- a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp +++ b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp @@ -201,19 +201,22 @@ static void OnStartAms() void AbilityMgrModuleTest::SetUpTestCase(void) { + OHOS::DelayedSingleton::DestroyInstance(); OHOS::DelayedSingleton::GetInstance()->RegisterSystemAbility( OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new (std::nothrow) BundleMgrService()); + abilityMgrServ_ = OHOS::DelayedSingleton::GetInstance(); mockAppMgrClient_ = std::make_shared(); + OnStartAms(); } void AbilityMgrModuleTest::TearDownTestCase(void) { - abilityMgrServ_->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); + abilityMgrServ_.reset(); mockAppMgrClient_.reset(); } - void AbilityMgrModuleTest::SetUp(void) { scheduler_ = new MockAbilityScheduler(); diff --git a/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp b/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp index 9879881ccdc..e1edffa368e 100644 --- a/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp +++ b/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp @@ -149,7 +149,9 @@ void AbilityStackModuleTest::SetUp(void) void AbilityStackModuleTest::TearDown(void) { GTEST_LOG_(INFO) << "TearDown"; - DelayedSingleton::GetInstance()->OnStop(); + auto ams = DelayedSingleton::GetInstance(); + OHOS::DelayedSingleton::DestroyInstance(); + if (mockScheduler_ != nullptr) { mockScheduler_.clear(); } diff --git a/services/test/moduletest/dump_module_test/dump_module_test.cpp b/services/test/moduletest/dump_module_test/dump_module_test.cpp index 454b85e303e..68943019cac 100644 --- a/services/test/moduletest/dump_module_test/dump_module_test.cpp +++ b/services/test/moduletest/dump_module_test/dump_module_test.cpp @@ -183,6 +183,7 @@ void DumpModuleTest::SetUp() void DumpModuleTest::TearDown() { g_abilityMs->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); GTEST_LOG_(INFO) << "TearDown OK"; } diff --git a/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp b/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp index bdcf2640585..2b20747fefc 100644 --- a/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp +++ b/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp @@ -98,7 +98,7 @@ void PandingWantManagerTest::SetUpTestCase(void) void PandingWantManagerTest::TearDownTestCase(void) { - abilityManager->OnStop(); + OHOS::DelayedSingleton::DestroyInstance(); if (appClient) { delete appClient; appClient = nullptr; diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index c95050bd1d0..b08e0b38bef 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -629,13 +629,9 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() if (isfirstCommand == false) { isfirstCommand = true; } else { - // 'aa dumpsys -i 10 -element -lastpage' - // 'aa dumpsys -i 10 -render -lastpage' - if (strcmp(optarg, "astpage")) { - result = OHOS::ERR_INVALID_VALUE; - resultReceiver_.append(HELP_MSG_DUMPSYS); - return result; - } + result = OHOS::ERR_INVALID_VALUE; + resultReceiver_.append(HELP_MSG_DUMPSYS); + return result; } // 'aa dumpsys -l' // 'aa dumpsys --mission-list' @@ -652,12 +648,9 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() return result; } } else { - // 'aa dumpsys -i 10 -inspector' - if (strcmp(optarg, "nspector")) { - result = OHOS::ERR_INVALID_VALUE; - resultReceiver_.append(HELP_MSG_DUMPSYS); - return result; - } + result = OHOS::ERR_INVALID_VALUE; + resultReceiver_.append(HELP_MSG_DUMPSYS); + return result; } // 'aa dumpsys -i' // 'aa dumpsys --ability' @@ -667,12 +660,9 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() if (isfirstCommand == false) { isfirstCommand = true; } else { - // 'aa dumpsys -i 10 -element' - if (strcmp(optarg, "lement")) { - result = OHOS::ERR_INVALID_VALUE; - resultReceiver_.append(HELP_MSG_DUMPSYS); - return result; - } + result = OHOS::ERR_INVALID_VALUE; + resultReceiver_.append(HELP_MSG_DUMPSYS); + return result; } // 'aa dumpsys -e' // 'aa dumpsys --extension' @@ -694,12 +684,9 @@ ErrCode AbilityManagerShellCommand::RunAsDumpsysCommand() if (isfirstCommand == false) { isfirstCommand = true; } else { - // 'aa dumpsys -i 10 -render' - if (strcmp(optarg, "ender")) { - result = OHOS::ERR_INVALID_VALUE; - resultReceiver_.append(HELP_MSG_DUMPSYS); - return result; - } + result = OHOS::ERR_INVALID_VALUE; + resultReceiver_.append(HELP_MSG_DUMPSYS); + return result; } // 'aa dumpsys -r' // 'aa dumpsys --process' diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 990e06c9547..15e4358bf46 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -119,7 +119,7 @@ public: MOCK_METHOD1(SetShowOnLockScreen, int(bool isAllow)); MOCK_METHOD1(GetSystemMemoryAttr, void(AppExecFwk::SystemMemoryAttr &memoryInfo)); MOCK_METHOD3(StartContinuation, int(const Want &want, const sptr &abilityToken, int32_t status)); - MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, const int32_t result)); MOCK_METHOD5(ContinueMission, int(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId, const sptr &callBack, AAFwk::WantParams &wantParams)); MOCK_METHOD2(ContinueAbility, int(const std::string &deviceId, int32_t missionId)); @@ -135,7 +135,6 @@ public: MOCK_METHOD1(CleanMission, int(int32_t missionId)); MOCK_METHOD0(CleanAllMissions, int()); MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); - MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions &startOptions)); MOCK_METHOD2(SetMissionLabel, int(const sptr &token, const std::string &label)); MOCK_METHOD1(ClearUpApplicationData, int(const std::string &)); -- Gitee