From d1d3e437212c3e114599238f69504aecd1a7ab02 Mon Sep 17 00:00:00 2001 From: liqiang Date: Thu, 10 Feb 2022 14:09:55 +0800 Subject: [PATCH] IssueNo:https://gitee.com/openharmony/notification_ans_standard/issues/I4T3TK Description:migrate wantagent module to aafwk repo Sig: SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: liqiang Change-Id: I266b82b1615667974e964d2c8c8343a60cb266ac --- bundle.json | 1 - frameworks/BUILD.gn | 1 - frameworks/ans/core/BUILD.gn | 4 +- frameworks/ans/native/BUILD.gn | 4 +- .../native/src/notification_action_button.cpp | 13 +- .../ans/native/src/notification_request.cpp | 25 +- .../ans/native/src/reminder_request.cpp | 41 +- frameworks/ans/native/test/unittest/BUILD.gn | 2 +- frameworks/ans/test/moduletest/BUILD.gn | 16 +- .../ans_innerkits_module_publish_test.cpp | 18 +- frameworks/wantagent/BUILD.gn | 83 - .../wantagent/src/completed_dispatcher.cpp | 45 - frameworks/wantagent/src/pending_want.cpp | 422 ------ frameworks/wantagent/src/trigger_info.cpp | 114 -- frameworks/wantagent/src/want_agent.cpp | 57 - .../wantagent/src/want_agent_helper.cpp | 439 ------ frameworks/wantagent/src/want_agent_info.cpp | 107 -- .../wantagent/src/want_agent_log_wrapper.cpp | 43 - frameworks/wantagent/test/BUILD.gn | 25 - .../completed_dispatcher_test/BUILD.gn | 60 - .../completed_dispatcher_test.cpp | 209 --- .../test/unittest/pending_want_test/BUILD.gn | 68 - .../pending_want_test/pending_want_test.cpp | 700 --------- .../test/unittest/trigger_Info_test/BUILD.gn | 60 - .../trigger_Info_test/trigger_Info_test.cpp | 225 --- .../unittest/want_agent_helper_test/BUILD.gn | 65 - .../want_agent_helper_test.cpp | 711 --------- .../unittest/want_agent_info_test/BUILD.gn | 60 - .../want_agent_info_test.cpp | 322 ---- .../test/unittest/want_agent_test/BUILD.gn | 60 - .../want_agent_test/want_agent_test.cpp | 100 -- interfaces/BUILD.gn | 1 - .../include/notification_action_button.h | 9 +- .../ans/native/include/notification_request.h | 18 +- .../ans/native/include/reminder_request.h | 2 +- .../wantagent/include/cancel_listener.h | 31 - .../wantagent/include/completed_callback.h | 40 - .../wantagent/include/completed_dispatcher.h | 52 - .../wantagent/include/pending_want.h | 281 ---- .../wantagent/include/trigger_info.h | 173 --- .../innerkits/wantagent/include/want_agent.h | 72 - .../wantagent/include/want_agent_constant.h | 133 -- .../wantagent/include/want_agent_helper.h | 199 --- .../wantagent/include/want_agent_info.h | 124 -- .../include/want_agent_log_wrapper.h | 68 - interfaces/kits/js/@ohos.wantAgent.d.ts | 204 --- interfaces/kits/js/wantAgent/triggerInfo.d.ts | 53 - .../kits/js/wantAgent/wantAgentInfo.d.ts | 53 - interfaces/kits/napi/ans/BUILD.gn | 2 +- interfaces/kits/napi/ans/include/common.h | 5 +- interfaces/kits/napi/ans/src/common.cpp | 36 +- .../kits/napi/ans/src/reminder/BUILD.gn | 2 +- interfaces/kits/napi/wantagent/BUILD.gn | 60 - .../kits/napi/wantagent/napi_want_agent.cpp | 1340 ----------------- .../kits/napi/wantagent/napi_want_agent.h | 198 --- .../kits/napi/wantagent/native_module.cpp | 64 - services/ans/BUILD.gn | 2 +- services/ans/include/reminder_timer_info.h | 2 +- .../ans/src/advanced_notification_service.cpp | 6 +- services/ans/src/reminder_data_manager.cpp | 11 +- services/ans/src/reminder_timer_info.cpp | 2 +- services/ans/test/unittest/BUILD.gn | 2 +- services/test/moduletest/BUILD.gn | 3 +- services/test/moduletest/ans_module_test.cpp | 15 +- test/resource/ansSTSlotGroupTest/BUILD.gn | 2 +- .../include/notificationgetparam.h | 22 +- .../src/notificationfuzztestmanager.cpp | 63 +- .../src/notificationgetparam.cpp | 78 +- test/systemtest/acts/ansDump/BUILD.gn | 2 +- tools/dump/BUILD.gn | 2 +- 70 files changed, 212 insertions(+), 7320 deletions(-) delete mode 100644 frameworks/wantagent/BUILD.gn delete mode 100644 frameworks/wantagent/src/completed_dispatcher.cpp delete mode 100644 frameworks/wantagent/src/pending_want.cpp delete mode 100644 frameworks/wantagent/src/trigger_info.cpp delete mode 100644 frameworks/wantagent/src/want_agent.cpp delete mode 100644 frameworks/wantagent/src/want_agent_helper.cpp delete mode 100644 frameworks/wantagent/src/want_agent_info.cpp delete mode 100644 frameworks/wantagent/src/want_agent_log_wrapper.cpp delete mode 100644 frameworks/wantagent/test/BUILD.gn delete mode 100644 frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn delete mode 100644 frameworks/wantagent/test/unittest/completed_dispatcher_test/completed_dispatcher_test.cpp delete mode 100644 frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn delete mode 100644 frameworks/wantagent/test/unittest/pending_want_test/pending_want_test.cpp delete mode 100644 frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn delete mode 100644 frameworks/wantagent/test/unittest/trigger_Info_test/trigger_Info_test.cpp delete mode 100644 frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn delete mode 100644 frameworks/wantagent/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp delete mode 100644 frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn delete mode 100644 frameworks/wantagent/test/unittest/want_agent_info_test/want_agent_info_test.cpp delete mode 100644 frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn delete mode 100644 frameworks/wantagent/test/unittest/want_agent_test/want_agent_test.cpp delete mode 100644 interfaces/innerkits/wantagent/include/cancel_listener.h delete mode 100644 interfaces/innerkits/wantagent/include/completed_callback.h delete mode 100644 interfaces/innerkits/wantagent/include/completed_dispatcher.h delete mode 100644 interfaces/innerkits/wantagent/include/pending_want.h delete mode 100644 interfaces/innerkits/wantagent/include/trigger_info.h delete mode 100644 interfaces/innerkits/wantagent/include/want_agent.h delete mode 100644 interfaces/innerkits/wantagent/include/want_agent_constant.h delete mode 100644 interfaces/innerkits/wantagent/include/want_agent_helper.h delete mode 100644 interfaces/innerkits/wantagent/include/want_agent_info.h delete mode 100644 interfaces/innerkits/wantagent/include/want_agent_log_wrapper.h delete mode 100644 interfaces/kits/js/@ohos.wantAgent.d.ts delete mode 100644 interfaces/kits/js/wantAgent/triggerInfo.d.ts delete mode 100644 interfaces/kits/js/wantAgent/wantAgentInfo.d.ts delete mode 100644 interfaces/kits/napi/wantagent/BUILD.gn delete mode 100644 interfaces/kits/napi/wantagent/napi_want_agent.cpp delete mode 100644 interfaces/kits/napi/wantagent/napi_want_agent.h delete mode 100644 interfaces/kits/napi/wantagent/native_module.cpp diff --git a/bundle.json b/bundle.json index f90a9ac8c..25811965b 100644 --- a/bundle.json +++ b/bundle.json @@ -86,7 +86,6 @@ "//base/notification/ans_standard/services/test/moduletest:ans_module_test", "//base/notification/ans_standard/frameworks/ans/test/moduletest:moduletest", "//base/notification/ans_standard/frameworks/ans/native/test/unittest:ans_reminder_unit_test", - "//base/notification/ans_standard/frameworks/wantagent/test/:unittest", "//base/notification/ans_standard/test:systemtest" ] } diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn index e4053fa5c..a923cf469 100644 --- a/frameworks/BUILD.gn +++ b/frameworks/BUILD.gn @@ -15,6 +15,5 @@ group("frameworks_target") { deps = [ "ans/core:ans_core_target", "ans/native:native_targets", - "wantagent:native_wantagent", ] } diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index 9aaee019c..fdca50b6d 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -26,7 +26,7 @@ config("public_ans_core_config") { "${core_path}/common/include", "${core_path}/include", "${interfaces_path}/innerkits/ans/native/include", - "${interfaces_path}/innerkits/wantAgent/include", + "//utils/native/base/include", "//third_party/json/single_include", "//third_party/jsoncpp/include", @@ -85,7 +85,6 @@ ohos_shared_library("ans_core") { public_configs = [ ":public_ans_core_config" ] deps = [ - "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", @@ -93,6 +92,7 @@ ohos_shared_library("ans_core") { external_deps = [ "ability_base:want", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", diff --git a/frameworks/ans/native/BUILD.gn b/frameworks/ans/native/BUILD.gn index 475b8a611..a0aa9d6cc 100644 --- a/frameworks/ans/native/BUILD.gn +++ b/frameworks/ans/native/BUILD.gn @@ -29,7 +29,7 @@ config("ans_innerkits_public_config") { "//third_party/jsoncpp/include", "//utils/system/safwk/native/include", ] - configs = [ "${frameworks_path}/wantagent:wantagent_innerkits_public_config" ] + configs = [ "//foundation/aafwk/standard/frameworks/kits/wantagent:wantagent_innerkits_public_config" ] } ohos_shared_library("ans_innerkits") { @@ -79,13 +79,13 @@ ohos_shared_library("ans_innerkits") { deps = [ "${frameworks_path}/ans/core:ans_core", - "${frameworks_path}/wantagent:wantagent_innerkits", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", ] external_deps = [ "ability_base:want", + "ability_runtime:wantagent_innerkits", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/frameworks/ans/native/src/notification_action_button.cpp b/frameworks/ans/native/src/notification_action_button.cpp index b61dbf836..cc3ba9f0c 100644 --- a/frameworks/ans/native/src/notification_action_button.cpp +++ b/frameworks/ans/native/src/notification_action_button.cpp @@ -23,7 +23,7 @@ namespace OHOS { namespace Notification { std::shared_ptr NotificationActionButton::Create(const std::shared_ptr &icon, - const std::string &title, const std::shared_ptr &wantAgent, + const std::string &title, const std::shared_ptr &wantAgent, const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, const std::vector> &userInputs, bool isContextual) @@ -93,7 +93,7 @@ std::shared_ptr NotificationActionButton::Create( } NotificationActionButton::NotificationActionButton(const std::shared_ptr &icon, - const std::string &title, const std::shared_ptr &wantAgent, + const std::string &title, const std::shared_ptr &wantAgent, const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, const std::vector> &userInputs, bool isContextual) @@ -118,7 +118,7 @@ std::string NotificationActionButton::GetTitle() const return title_; } -const std::shared_ptr NotificationActionButton::GetWantAgent() const +const std::shared_ptr NotificationActionButton::GetWantAgent() const { return wantAgent_; } @@ -236,7 +236,7 @@ bool NotificationActionButton::ToJson(nlohmann::json &jsonObject) const { jsonObject["icon"] = AnsImageUtil::PackImage(icon_); jsonObject["title"] = title_; - jsonObject["wantAgent"] = wantAgent_ ? WantAgent::WantAgentHelper::ToString(wantAgent_) : ""; + jsonObject["wantAgent"] = wantAgent_ ? AbilityRuntime::WantAgent::WantAgentHelper::ToString(wantAgent_) : ""; std::string extrasStr; if (extras_) { @@ -273,7 +273,7 @@ NotificationActionButton *NotificationActionButton::FromJson(const nlohmann::jso if (jsonObject.find("wantAgent") != jsonEnd) { auto wantAgentValue = jsonObject.at("wantAgent").get(); - pButton->wantAgent_ = WantAgent::WantAgentHelper::FromString(wantAgentValue); + pButton->wantAgent_ = AbilityRuntime::WantAgent::WantAgentHelper::FromString(wantAgentValue); } if (jsonObject.find("extras") != jsonEnd) { @@ -410,7 +410,8 @@ bool NotificationActionButton::ReadFromParcel(Parcel &parcel) valid = parcel.ReadBool(); if (valid) { - wantAgent_ = std::shared_ptr(parcel.ReadParcelable()); + wantAgent_ = std::shared_ptr( + parcel.ReadParcelable()); if (!wantAgent_) { ANS_LOGE("Failed to read wantAgent"); return false; diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index 52c4d5d6e..f48ccfb59 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -108,32 +108,32 @@ int32_t NotificationRequest::GetNotificationId() const return notificationId_; } -void NotificationRequest::SetWantAgent(const std::shared_ptr &wantAgent) +void NotificationRequest::SetWantAgent(const std::shared_ptr &wantAgent) { wantAgent_ = wantAgent; } -const std::shared_ptr NotificationRequest::GetWantAgent() const +const std::shared_ptr NotificationRequest::GetWantAgent() const { return wantAgent_; } -void NotificationRequest::SetRemovalWantAgent(const std::shared_ptr &wantAgent) +void NotificationRequest::SetRemovalWantAgent(const std::shared_ptr &wantAgent) { removalWantAgent_ = wantAgent; } -const std::shared_ptr NotificationRequest::GetRemovalWantAgent() const +const std::shared_ptr NotificationRequest::GetRemovalWantAgent() const { return removalWantAgent_; } -void NotificationRequest::SetMaxScreenWantAgent(const std::shared_ptr &wantAgent) +void NotificationRequest::SetMaxScreenWantAgent(const std::shared_ptr &wantAgent) { maxScreenWantAgent_ = wantAgent; } -const std::shared_ptr NotificationRequest::GetMaxScreenWantAgent() const +const std::shared_ptr NotificationRequest::GetMaxScreenWantAgent() const { return maxScreenWantAgent_; } @@ -755,7 +755,7 @@ NotificationRequest *NotificationRequest::FromJson(const nlohmann::json &jsonObj if (jsonObject.find("wantAgent") != jsonEnd) { auto wantAgentValue = jsonObject.at("wantAgent").get(); - pRequest->wantAgent_ = WantAgent::WantAgentHelper::FromString(wantAgentValue); + pRequest->wantAgent_ = AbilityRuntime::WantAgent::WantAgentHelper::FromString(wantAgentValue); } if (!ConvertJsonToNotificationContent(pRequest, jsonObject)) { @@ -1264,7 +1264,8 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) valid = parcel.ReadBool(); if (valid) { - wantAgent_ = std::shared_ptr(parcel.ReadParcelable()); + wantAgent_ = std::shared_ptr( + parcel.ReadParcelable()); if (!wantAgent_) { ANS_LOGE("Failed to read wantAgent"); return false; @@ -1273,7 +1274,8 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) valid = parcel.ReadBool(); if (valid) { - removalWantAgent_ = std::shared_ptr(parcel.ReadParcelable()); + removalWantAgent_ = std::shared_ptr( + parcel.ReadParcelable()); if (!removalWantAgent_) { ANS_LOGE("Failed to read removalWantAgent"); return false; @@ -1282,7 +1284,8 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) valid = parcel.ReadBool(); if (valid) { - maxScreenWantAgent_ = std::shared_ptr(parcel.ReadParcelable()); + maxScreenWantAgent_ = std::shared_ptr( + parcel.ReadParcelable()); if (!maxScreenWantAgent_) { ANS_LOGE("Failed to read maxScreenWantAgent"); return false; @@ -1498,7 +1501,7 @@ void NotificationRequest::CopyOther(const NotificationRequest &other) bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const { - jsonObject["wantAgent"] = wantAgent_ ? WantAgent::WantAgentHelper::ToString(wantAgent_) : ""; + jsonObject["wantAgent"] = wantAgent_ ? AbilityRuntime::WantAgent::WantAgentHelper::ToString(wantAgent_) : ""; nlohmann::json contentObj; if (notificationContent_) { diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 45f7a7d21..f768f60e0 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -958,8 +958,8 @@ std::string ReminderRequest::GetState(const uint8_t state) const void ReminderRequest::AddActionButtons(const bool includeSnooze) { int requestCode = 10; - std::vector flags; - flags.push_back(WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); + std::vector flags; + flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); for (auto it = actionButtonMap_.begin(); it != actionButtonMap_.end(); ++it) { auto want = std::make_shared(); auto type = it->first; @@ -980,15 +980,15 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze) std::vector> wants; wants.push_back(want); auto title = static_cast(it->second.title); - WantAgent::WantAgentInfo buttonWantAgentInfo( + AbilityRuntime::WantAgent::WantAgentInfo buttonWantAgentInfo( requestCode, - WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, + AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, flags, wants, nullptr ); - std::shared_ptr buttonWantAgent = - WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo, userId_); + std::shared_ptr buttonWantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo, userId_); std::shared_ptr actionButton = NotificationActionButton::Create(nullptr, title, buttonWantAgent); notificationRequest_->AddActionButton(actionButton); @@ -998,53 +998,54 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze) void ReminderRequest::AddRemovalWantAgent() { int requestCode = 10; - std::vector flags; - flags.push_back(WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); + std::vector flags; + flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); auto want = std::make_shared(); want->SetAction(REMINDER_EVENT_REMOVE_NOTIFICATION); want->SetParam(PARAM_REMINDER_ID, reminderId_); std::vector> wants; wants.push_back(want); - WantAgent::WantAgentInfo wantAgentInfo( + AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( requestCode, - WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, + AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, flags, wants, nullptr ); - std::shared_ptr wantAgent - = WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); notificationRequest_->SetRemovalWantAgent(wantAgent); } -std::shared_ptr ReminderRequest::CreateWantAgent(AppExecFwk::ElementName &element) const +std::shared_ptr ReminderRequest::CreateWantAgent( + AppExecFwk::ElementName &element) const { int requestCode = 10; - std::vector flags; - flags.push_back(WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); + std::vector flags; + flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); auto want = std::make_shared(); want->SetElement(element); std::vector> wants; wants.push_back(want); - WantAgent::WantAgentInfo wantAgentInfo( + AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( requestCode, - WantAgent::WantAgentConstant::OperationType::START_ABILITY, + AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITY, flags, wants, nullptr ); - return WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); + return AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); } void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element) { - std::shared_ptr wantAgent = CreateWantAgent(element); + std::shared_ptr wantAgent = CreateWantAgent(element); notificationRequest_->SetMaxScreenWantAgent(wantAgent); } void ReminderRequest::SetWantAgent(AppExecFwk::ElementName &element) { - std::shared_ptr wantAgent = CreateWantAgent(element); + std::shared_ptr wantAgent = CreateWantAgent(element); notificationRequest_->SetWantAgent(wantAgent); } diff --git a/frameworks/ans/native/test/unittest/BUILD.gn b/frameworks/ans/native/test/unittest/BUILD.gn index a9d25195d..bd274f32d 100644 --- a/frameworks/ans/native/test/unittest/BUILD.gn +++ b/frameworks/ans/native/test/unittest/BUILD.gn @@ -41,13 +41,13 @@ ohos_unittest("ans_reminder_unit_test") { deps = [ "${core_path}:ans_core", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] external_deps = [ "ability_base:want", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "bytrace_standard:bytrace_core", diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index 3d079b884..fd56828c2 100644 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -41,11 +41,9 @@ ohos_moduletest("ans_fw_module_test") { "//base/notification/ans_standard/interfaces/innerkits/ans/native/test/moduletest/mock/include", "//base/notification/ces_standard/interfaces/innerkits/native/include", "//base/notification/ans_standard/interfaces/innerkits/ans/native/include", - "//base/notification/ans_standard/interfaces/innerkits/wantagent/include", "${core_path}/common/include", "${core_path}/include", "${interfaces_path}/innerkits/ans/native/include", - "${interfaces_path}/innerkits/wantAgent/include", "//utils/native/base/include", "//third_party/jsoncpp/include", "//base/notification/ans_standard/frameworks/ans/test/moduletest/mock/include", @@ -69,7 +67,6 @@ ohos_moduletest("ans_fw_module_test") { deps = [ "${frameworks_path}/ans/core:ans_core", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "${services_path}/ans:libans", "//third_party/googletest:gtest_main", "//utils/native/base:utils", @@ -83,6 +80,7 @@ ohos_moduletest("ans_fw_module_test") { external_deps = [ "ability_base:want", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", @@ -115,11 +113,9 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "//base/notification/ans_standard/interfaces/innerkits/ans/native/test/moduletest/mock/include", "//base/notification/ces_standard/interfaces/innerkits/native/include", "//base/notification/ans_standard/interfaces/innerkits/ans/native/include", - "//base/notification/ans_standard/interfaces/innerkits/wantagent/include", "${core_path}/common/include", "${core_path}/include", "${interfaces_path}/innerkits/ans/native/include", - "${interfaces_path}/innerkits/wantAgent/include", "//utils/native/base/include", "//third_party/jsoncpp/include", "//base/notification/ans_standard/frameworks/ans/test/moduletest/mock/include", @@ -145,7 +141,6 @@ ohos_moduletest("ans_innerkits_module_publish_test") { deps = [ "${frameworks_path}/ans/core:ans_core", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "${services_path}/ans:libans", "//third_party/googletest:gtest_main", "//utils/native/base:utils", @@ -160,6 +155,7 @@ ohos_moduletest("ans_innerkits_module_publish_test") { external_deps = [ "ability_base:base", "ability_base:want", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", @@ -192,11 +188,9 @@ ohos_moduletest("ans_innerkits_module_slot_test") { "//base/notification/ans_standard/interfaces/innerkits/ans/native/test/moduletest/mock/include", "//base/notification/ces_standard/interfaces/innerkits/native/include", "//base/notification/ans_standard/interfaces/innerkits/ans/native/include", - "//base/notification/ans_standard/interfaces/innerkits/wantagent/include", "${core_path}/common/include", "${core_path}/include", "${interfaces_path}/innerkits/ans/native/include", - "${interfaces_path}/innerkits/wantAgent/include", "//utils/native/base/include", "//third_party/jsoncpp/include", "//base/notification/ans_standard/frameworks/ans/test/moduletest/mock/include", @@ -220,7 +214,6 @@ ohos_moduletest("ans_innerkits_module_slot_test") { deps = [ "${frameworks_path}/ans/core:ans_core", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "${services_path}/ans:libans", "//third_party/googletest:gtest_main", "//utils/native/base:utils", @@ -234,6 +227,7 @@ ohos_moduletest("ans_innerkits_module_slot_test") { external_deps = [ "ability_base:want", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", @@ -266,11 +260,9 @@ ohos_moduletest("ans_innerkits_module_setting_test") { "//base/notification/ans_standard/interfaces/innerkits/ans/native/test/moduletest/mock/include", "//base/notification/ces_standard/interfaces/innerkits/native/include", "//base/notification/ans_standard/interfaces/innerkits/ans/native/include", - "//base/notification/ans_standard/interfaces/innerkits/wantagent/include", "${core_path}/common/include", "${core_path}/include", "${interfaces_path}/innerkits/ans/native/include", - "${interfaces_path}/innerkits/wantAgent/include", "//utils/native/base/include", "//third_party/jsoncpp/include", "//base/notification/ans_standard/frameworks/ans/test/moduletest/mock/include", @@ -294,7 +286,6 @@ ohos_moduletest("ans_innerkits_module_setting_test") { deps = [ "${frameworks_path}/ans/core:ans_core", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "${services_path}/ans:libans", "//third_party/googletest:gtest_main", "//utils/native/base:utils", @@ -308,6 +299,7 @@ ohos_moduletest("ans_innerkits_module_setting_test") { external_deps = [ "ability_base:want", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp index 5df346c42..41ae2f718 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -399,7 +399,7 @@ private: } }; -class CompletedCallbackTest : public WantAgent::CompletedCallback { +class CompletedCallbackTest : public AbilityRuntime::WantAgent::CompletedCallback { void OnSendFinished( const AAFwk::Want &want, int resultCode, const std::string &resultData, const AAFwk::WantParams &resultExtras) { @@ -637,8 +637,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00200, Function EXPECT_NE(mediaContent, nullptr); std::shared_ptr content = std::make_shared(mediaContent); EXPECT_NE(content, nullptr); - WantAgent::WantAgentInfo paramsInfo; - std::shared_ptr wantAgent = WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); + AbilityRuntime::WantAgent::WantAgentInfo paramsInfo; + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); std::shared_ptr actionButton = NotificationActionButton::Create(nullptr, "title", wantAgent); std::shared_ptr userInput = NotificationUserInput::Create("inputKey"); @@ -696,8 +697,9 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00300, Function EXPECT_NE(mediaContent, nullptr); std::shared_ptr content = std::make_shared(mediaContent); EXPECT_NE(content, nullptr); - WantAgent::WantAgentInfo paramsInfo; - std::shared_ptr wantAgent = WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); + AbilityRuntime::WantAgent::WantAgentInfo paramsInfo; + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); if (nullptr == wantAgent) { GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00300::wantAgent is nullptr"; } @@ -1314,10 +1316,10 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_08000, Function req.SetLabel("label"); req.SetOwnerBundleName("owner"); - auto wAgent1 = std::make_shared(); + auto wAgent1 = std::make_shared(); req.SetWantAgent(wAgent1); - auto wAgent2 = std::make_shared(); + auto wAgent2 = std::make_shared(); std::shared_ptr dummyIcon; auto ab1 = NotificationActionButton::Create(dummyIcon, "ab1_title", wAgent2); @@ -1335,7 +1337,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_08000, Function ab1->AddMimeTypeOnlyUserInput(spOnlyUserInput1); ab1->AddMimeTypeOnlyUserInput(spOnlyUserInput4); - std::shared_ptr dummyWantAgent; + std::shared_ptr dummyWantAgent; auto ab2 = NotificationActionButton::Create(dummyIcon, "ab2_title", dummyWantAgent); req.AddActionButton(ab1); diff --git a/frameworks/wantagent/BUILD.gn b/frameworks/wantagent/BUILD.gn deleted file mode 100644 index 99a52a5c1..000000000 --- a/frameworks/wantagent/BUILD.gn +++ /dev/null @@ -1,83 +0,0 @@ -# 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. - -import("//base/notification/ans_standard/notification.gni") -import("//build/ohos.gni") - -group("native_wantagent") { - deps = [ ":wantagent_innerkits" ] -} - -config("wantagent_innerkits_public_config") { - visibility = [ ":*" ] - - include_dirs = [ - "${interfaces_path}/innerkits/wantagent/include", - "//base/global/resmgr_standard/interfaces/innerkits/include", - "//foundation/aafwk/standard/frameworks/kits/ability/native/include", - "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", - "//foundation/aafwk/standard/services/abilitymgr/include", - "//foundation/aafwk/standard/interfaces/innerkits/app_manager/include/appmgr", - "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", - "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", - "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", - "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime", - "//third_party/icu/icu4c/source/common", - ] -} - -ohos_shared_library("wantagent_innerkits") { - include_dirs = [ - "//utils/native/base/include", - "//foundation/aafwk/standard/services/common/include", - "//foundation/distributedschedule/safwk/services/safwk/include", - ] - - sources = [ - "src/completed_dispatcher.cpp", - "src/pending_want.cpp", - "src/trigger_info.cpp", - "src/want_agent.cpp", - "src/want_agent_helper.cpp", - "src/want_agent_info.cpp", - "src/want_agent_log_wrapper.cpp", - ] - - configs = [ "//utils/native/base:utils_config" ] - - public_configs = [ ":wantagent_innerkits_public_config" ] - - deps = [ - "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", - "//utils/native/base:utils", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:ability_manager", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "ces_standard:cesfwk_core", - "eventhandler:libeventhandler", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "samgr_standard:samgr_proxy", - ] - - if (is_double_framework) { - cflags = [ "-DCONFIG_DUAL_FRAMEWORK" ] - } - - subsystem_name = "notification" - part_name = "ans_standard" -} diff --git a/frameworks/wantagent/src/completed_dispatcher.cpp b/frameworks/wantagent/src/completed_dispatcher.cpp deleted file mode 100644 index 44ceed2db..000000000 --- a/frameworks/wantagent/src/completed_dispatcher.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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. - */ - -#include "completed_dispatcher.h" - -namespace OHOS::Notification::WantAgent { -CompletedDispatcher::CompletedDispatcher(const std::shared_ptr &pendingWant, - const std::shared_ptr &callback, const std::shared_ptr &handler) - : pendingWant_(pendingWant), callback_(callback), handler_(handler) -{} - -void CompletedDispatcher::Send(const int32_t resultCode) -{} - -void CompletedDispatcher::PerformReceive(const AAFwk::Want &want, int resultCode, const std::string &data, - const AAFwk::WantParams &extras, bool serialized, bool sticky, int sendingUser) -{ - want_ = want; - resultCode_ = resultCode; - resultData_ = data; - resultExtras_ = extras; - if (handler_ == nullptr) { - Run(); - } -} - -void CompletedDispatcher::Run() -{ - if (callback_ != nullptr) { - callback_->OnSendFinished(want_, resultCode_, resultData_, resultExtras_); - } -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/frameworks/wantagent/src/pending_want.cpp b/frameworks/wantagent/src/pending_want.cpp deleted file mode 100644 index a544e1814..000000000 --- a/frameworks/wantagent/src/pending_want.cpp +++ /dev/null @@ -1,422 +0,0 @@ -/* - * 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. - */ - -#include "pending_want.h" -#include "ability_manager_client.h" -#include "hilog_wrapper.h" -#include "pending_want_record.h" -#include "want_agent_log_wrapper.h" -#include "want_sender_info.h" - -using namespace OHOS::AppExecFwk; -using namespace OHOS::AAFwk; - -namespace OHOS::Notification::WantAgent { -PendingWant::PendingWant(const sptr &target) - : target_(target), cancelReceiver_(nullptr), whitelistToken_(nullptr) -{} - -PendingWant::PendingWant(const sptr &target, const sptr whitelistToken) - : target_(target), cancelReceiver_(nullptr), whitelistToken_(whitelistToken) -{} - -WantAgentConstant::OperationType PendingWant::GetType(const sptr &target) -{ - int32_t operationType = 0; - AbilityManagerClient::GetInstance()->GetPendingWantType(target, operationType); - return (WantAgentConstant::OperationType)operationType; -} - -std::shared_ptr PendingWant::GetAbility( - const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, unsigned int flags) -{ - return GetAbility(context, requestCode, want, flags, nullptr); -} - -std::shared_ptr PendingWant::GetAbility( - const std::shared_ptr &context, int requestCode, - const std::shared_ptr &want, unsigned int flags, const std::shared_ptr &options) -{ - WANT_AGENT_LOGI("PendingWant::GetAbility begin."); - if (context == nullptr) { - WANT_AGENT_LOGE("PendingWant::GetAbility invalid input param."); - return nullptr; - } - - WantsInfo wantsInfo; - wantsInfo.want = *want; - wantsInfo.resolvedTypes = want != nullptr ? want->GetType() : ""; - if (options != nullptr) { - wantsInfo.want.SetParams(*options); - } - - WantSenderInfo wantSenderInfo; - wantSenderInfo.type = (int32_t)WantAgentConstant::OperationType::START_ABILITY; - wantSenderInfo.allWants.push_back(wantsInfo); - wantSenderInfo.bundleName = context->GetBundleName(); - wantSenderInfo.flags = flags; - wantSenderInfo.userId = -1; - wantSenderInfo.requestCode = requestCode; - sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); - WANT_AGENT_LOGI("PendingWant::GetAbility end."); - - return std::make_shared(target); -} - -std::shared_ptr PendingWant::GetAbilities(const std::shared_ptr &context, - int requestCode, std::vector> &wants, unsigned int flags) -{ - return GetAbilities(context, requestCode, wants, flags, nullptr); -} - -std::shared_ptr PendingWant::GetAbilities(const std::shared_ptr &context, - int requestCode, std::vector> &wants, - unsigned int flags, const std::shared_ptr &options) -{ - if (context == nullptr) { - WANT_AGENT_LOGE("PendingWant::GetAbilities invalid input param."); - return nullptr; - } - - WantSenderInfo wantSenderInfo; - wantSenderInfo.type = (int32_t)WantAgentConstant::OperationType::START_ABILITIES; - wantSenderInfo.bundleName = context->GetBundleName(); - wantSenderInfo.flags = flags; - wantSenderInfo.userId = -1; - wantSenderInfo.requestCode = requestCode; - for (auto want : wants) { - WantsInfo wantsInfo; - if (want != nullptr) { - wantsInfo.want = *want; - } - wantsInfo.resolvedTypes = want != nullptr ? want->GetType() : ""; - if (options != nullptr) { - wantsInfo.want.SetParams(*options); - } - wantSenderInfo.allWants.push_back(wantsInfo); - } - sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); - - return std::make_shared(target); -} - -std::shared_ptr PendingWant::GetCommonEvent( - const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, unsigned int flags) -{ - return GetCommonEventAsUser(context, requestCode, want, flags, 0); -} - -std::shared_ptr PendingWant::GetCommonEventAsUser( - const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, unsigned int flags, int uid) -{ - if (context == nullptr) { - WANT_AGENT_LOGE("PendingWant::GetCommonEventAsUser invalid input param."); - return nullptr; - } - - WantsInfo wantsInfo; - if (want != nullptr) { - wantsInfo.want = *want; - } - wantsInfo.resolvedTypes = want != nullptr ? want->GetType() : ""; - - WantSenderInfo wantSenderInfo; - wantSenderInfo.type = (int32_t)WantAgentConstant::OperationType::SEND_COMMON_EVENT; - wantSenderInfo.allWants.push_back(wantsInfo); - wantSenderInfo.bundleName = context->GetBundleName(); - wantSenderInfo.flags = flags; - wantSenderInfo.userId = -1; - wantSenderInfo.requestCode = requestCode; - sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); - - return std::make_shared(target); -} - -std::shared_ptr PendingWant::GetService( - const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, unsigned int flags) -{ - return BuildServicePendingWant(context, requestCode, want, flags, - WantAgentConstant::OperationType::START_SERVICE); -} - -std::shared_ptr PendingWant::GetForegroundService( - const std::shared_ptr &context, int requestCode, - const std::shared_ptr &want, unsigned int flags) -{ - return BuildServicePendingWant( - context, requestCode, want, flags, WantAgentConstant::OperationType::START_FOREGROUND_SERVICE); -} - -std::shared_ptr PendingWant::BuildServicePendingWant( - const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, - unsigned int flags, WantAgentConstant::OperationType serviceKind) -{ - if (context == nullptr) { - WANT_AGENT_LOGE("PendingWant::BuildServicePendingWant invalid input param."); - return nullptr; - } - - WantsInfo wantsInfo; - if (want != nullptr) { - wantsInfo.want = *want; - } - wantsInfo.resolvedTypes = want != nullptr ? want->GetType() : ""; - - WantSenderInfo wantSenderInfo; - wantSenderInfo.type = (int32_t)serviceKind; - wantSenderInfo.allWants.push_back(wantsInfo); - wantSenderInfo.bundleName = context->GetBundleName(); - wantSenderInfo.flags = flags; - wantSenderInfo.userId = -1; - wantSenderInfo.requestCode = requestCode; - sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); - - return std::make_shared(target); -} - -void PendingWant::Cancel(const sptr &target) -{ - AbilityManagerClient::GetInstance()->CancelWantSender(target); -} - -void PendingWant::Send(const sptr &target) -{ - Send(0, nullptr, nullptr, "", nullptr, target); -} - -void PendingWant::Send(int resultCode, const sptr &target) -{ - Send(resultCode, nullptr, nullptr, "", nullptr, target); -} - -void PendingWant::Send(int resultCode, const std::shared_ptr &want, - const sptr &target) -{ - Send(resultCode, want, nullptr, "", nullptr, target); -} - -void PendingWant::Send( - int resultCode, const sptr &onCompleted, const sptr &target) -{ - Send(resultCode, nullptr, onCompleted, "", nullptr, target); -} - -void PendingWant::Send(int resultCode, const std::shared_ptr &want, - const sptr &onCompleted, const sptr &target) -{ - Send(resultCode, want, onCompleted, "", nullptr, target); -} - -void PendingWant::Send(int resultCode, const std::shared_ptr &want, - const sptr &onCompleted, const std::string &requiredPermission, - const sptr &target) -{ - Send(resultCode, want, onCompleted, requiredPermission, nullptr, target); -} - -void PendingWant::Send(int resultCode, const std::shared_ptr &want, - const sptr &onCompleted, const std::string &requiredPermission, - const std::shared_ptr &options, const sptr &target) -{ - HILOG_INFO("%{public}s:begin.", __func__); - if (SendAndReturnResult(resultCode, want, onCompleted, requiredPermission, options, target) != 0) { - WANT_AGENT_LOGE("PendingWant::SendAndReturnResult failed."); - } -} - -int PendingWant::SendAndReturnResult(int resultCode, const std::shared_ptr &want, - const sptr &onCompleted, const std::string &requiredPermission, - const std::shared_ptr &options, const sptr &target) -{ - HILOG_INFO("%{public}s:begin.", __func__); - - SenderInfo senderInfo; - senderInfo.resolvedType = want != nullptr ? want->GetType() : ""; - if (want != nullptr) { - senderInfo.want = *want; - } - if (options != nullptr) { - senderInfo.want.SetParams(*options); - } - senderInfo.requiredPermission = requiredPermission; - senderInfo.code = resultCode; - senderInfo.finishedReceiver = onCompleted; - - return AbilityManagerClient::GetInstance()->SendWantSender(target, senderInfo); -} - -bool PendingWant::Equals( - const std::shared_ptr &targetPendingWant, const std::shared_ptr &otherPendingWant) -{ - if (targetPendingWant == nullptr && otherPendingWant == nullptr) { - return true; - } - if (targetPendingWant == nullptr || otherPendingWant == nullptr) { - return false; - } - return targetPendingWant->GetHashCode(targetPendingWant->GetTarget()) == - targetPendingWant->GetHashCode(otherPendingWant->GetTarget()); -} - -sptr PendingWant::GetTarget() -{ - return target_; -} - -void PendingWant::SetTarget(const sptr &target) -{ - target_ = target; -} - -PendingWant::CancelReceiver::CancelReceiver(const std::weak_ptr &outerInstance) - : outerInstance_(outerInstance) -{} - -void PendingWant::CancelReceiver::PerformReceive(const AAFwk::Want &want, int resultCode, const std::string &data, - const AAFwk::WantParams &extras, bool serialized, bool sticky, int sendingUser) -{} - -void PendingWant::CancelReceiver::Send(const int32_t resultCode) -{ - HILOG_INFO("%{public}s:begin.", __func__); - - if (outerInstance_.lock() != nullptr) { - outerInstance_.lock()->NotifyCancelListeners(resultCode); - } -} - -void PendingWant::RegisterCancelListener( - const std::shared_ptr &cancelListener, const sptr &target) -{ - HILOG_INFO("%{public}s:begin.", __func__); - - if (cancelListener == nullptr) { - WANT_AGENT_LOGE("PendingWant::RegisterCancelListener invalid input param."); - return; - } - std::scoped_lock lock(lock_object); - if (cancelReceiver_ == nullptr) { - cancelReceiver_ = new (std::nothrow) CancelReceiver(weak_from_this()); - } - bool isEmpty = cancelListeners_.empty(); - cancelListeners_.push_back(cancelListener); - if (isEmpty) { - AbilityManagerClient::GetInstance()->RegisterCancelListener(target, cancelReceiver_); - } -} - -void PendingWant::NotifyCancelListeners(int32_t resultCode) -{ - HILOG_INFO("%{public}s:begin.", __func__); - - std::vector> cancelListeners; - { - std::scoped_lock lock(lock_object); - cancelListeners = std::vector>(cancelListeners_); - } - for (auto cancelListener : cancelListeners) { - if (cancelListener != nullptr) { - cancelListener->OnCancelled(resultCode); - } - } -} - -void PendingWant::UnregisterCancelListener( - const std::shared_ptr &cancelListener, const sptr &target) -{ - HILOG_INFO("%{public}s:begin.", __func__); - - if (cancelListener == nullptr) { - WANT_AGENT_LOGE("PendingWant::UnregisterCancelListener invalid input param."); - return; - } - - std::scoped_lock lock(lock_object); - bool isEmpty = cancelListeners_.empty(); - cancelListeners_.erase(remove_if(cancelListeners_.begin(), - cancelListeners_.end(), - [cancelListener](std::shared_ptr x) { return x == cancelListener; }), - cancelListeners_.end()); - if (cancelListeners_.empty() && !isEmpty) { - AbilityManagerClient::GetInstance()->UnregisterCancelListener(target, cancelReceiver_); - } -} - -int PendingWant::GetHashCode(const sptr &target) -{ - int32_t code = -1; - AbilityManagerClient::GetInstance()->GetPendingWantCode(target, code); - return code; -} - -int PendingWant::GetUid(const sptr &target) -{ - int32_t uid = -1; - AbilityManagerClient::GetInstance()->GetPendingWantUid(target, uid); - return uid; -} - -std::string PendingWant::GetBundleName(const sptr &target) -{ - std::string bundleName = ""; - AbilityManagerClient::GetInstance()->GetPendingWantBundleName(target, bundleName); - return bundleName; -} - -std::shared_ptr PendingWant::GetWant(const sptr &target) -{ - std::shared_ptr want = std::make_shared(); - int ret = AbilityManagerClient::GetInstance()->GetPendingRequestWant(target, want); - return ret ? nullptr : want; -} - -bool PendingWant::Marshalling(Parcel &parcel) const -{ - if (!parcel.WriteParcelable(target_->AsObject())) { - WANT_AGENT_LOGE("parcel WriteString failed"); - return false; - } - - return true; -} - -PendingWant *PendingWant::Unmarshalling(Parcel &parcel) -{ - PendingWant *pendingWant = new (std::nothrow) PendingWant(); - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("read from parcel failed"); - return nullptr; - } - sptr target = iface_cast(parcel.ReadParcelable()); - if (target == nullptr) { - return nullptr; - } - pendingWant->SetTarget(target); - - return pendingWant; -} - -std::shared_ptr PendingWant::GetWantSenderInfo(const sptr &target) -{ - std::shared_ptr info = std::make_shared(); - int ret = AbilityManagerClient::GetInstance()->GetWantSenderInfo(target, info); - return ret ? nullptr : info; -} -} // namespace OHOS::Notification::WantAgent diff --git a/frameworks/wantagent/src/trigger_info.cpp b/frameworks/wantagent/src/trigger_info.cpp deleted file mode 100644 index aec2c92a9..000000000 --- a/frameworks/wantagent/src/trigger_info.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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. - */ - -#include "trigger_info.h" - -using namespace OHOS::AAFwk; - -namespace OHOS::Notification::WantAgent { -TriggerInfo::TriggerInfo() : permission_(""), extraInfo_(nullptr), want_(nullptr), resultCode_(0) -{} - -TriggerInfo::TriggerInfo(const std::string &permission, const std::shared_ptr &extraInfo, - const std::shared_ptr &want, int resultCode) -{ - permission_ = permission; - if (extraInfo != nullptr) { - extraInfo_ = std::make_shared(*extraInfo); - } - if (want != nullptr) { - want_ = std::make_shared(*want); - } - resultCode_ = resultCode; -} - -TriggerInfo::TriggerInfo(const TriggerInfo ¶mInfo) -{ - permission_ = paramInfo.GetPermission(); - if (paramInfo.GetExtraInfo() != nullptr) { - extraInfo_ = std::make_shared(*paramInfo.GetExtraInfo()); - } - if (paramInfo.GetWant() != nullptr) { - want_ = std::make_shared(*paramInfo.GetWant()); - } - resultCode_ = paramInfo.GetResultCode(); -} - -const TriggerInfo &TriggerInfo::operator=(const TriggerInfo ¶mInfo) -{ - permission_ = paramInfo.GetPermission(); - if (paramInfo.GetExtraInfo() != nullptr) { - extraInfo_ = std::make_shared(*paramInfo.GetExtraInfo()); - } - if (paramInfo.GetWant() != nullptr) { - want_ = std::make_shared(*paramInfo.GetWant()); - } - resultCode_ = paramInfo.GetResultCode(); - - return *this; -} - -std::string TriggerInfo::GetPermission() const -{ - return permission_; -} - -std::shared_ptr TriggerInfo::GetExtraInfo() const -{ - return extraInfo_; -} - -std::shared_ptr TriggerInfo::GetWant() const -{ - return want_; -} - -int TriggerInfo::GetResultCode() const -{ - return resultCode_; -} - -TriggerInfo::Builder::Builder() -{} - -std::shared_ptr TriggerInfo::Builder::SetPermission(const std::string &permission) -{ - permission_ = permission; - return shared_from_this(); -} - -std::shared_ptr TriggerInfo::Builder::SetWantParams(const std::shared_ptr ¶ms) -{ - params_ = params; - return shared_from_this(); -} - -std::shared_ptr TriggerInfo::Builder::SetWant(const std::shared_ptr &want) -{ - want_ = want; - return shared_from_this(); -} - -std::shared_ptr TriggerInfo::Builder::SetResultCode(int resultCode) -{ - resultCode_ = resultCode; - return shared_from_this(); -} - -std::shared_ptr TriggerInfo::Builder::Build() -{ - return std::make_shared(permission_, params_, want_, resultCode_); -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/frameworks/wantagent/src/want_agent.cpp b/frameworks/wantagent/src/want_agent.cpp deleted file mode 100644 index d0d529d45..000000000 --- a/frameworks/wantagent/src/want_agent.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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. - */ - -#include "want_agent.h" -#include "want_agent_log_wrapper.h" - -namespace OHOS::Notification::WantAgent { -WantAgent::WantAgent(const std::shared_ptr &pendingWant) -{ - pendingWant_ = pendingWant; -} - -std::shared_ptr WantAgent::GetPendingWant() -{ - return pendingWant_; -} - -void WantAgent::SetPendingWant(const std::shared_ptr &pendingWant) -{ - pendingWant_ = pendingWant; -} - -bool WantAgent::Marshalling(Parcel &parcel) const -{ - if (!parcel.WriteParcelable(pendingWant_.get())) { - WANT_AGENT_LOGE("parcel WriteString failed"); - return false; - } - - return true; -} - -WantAgent *WantAgent::Unmarshalling(Parcel &parcel) -{ - WantAgent *agent = new (std::nothrow) WantAgent(); - if (agent == nullptr) { - WANT_AGENT_LOGE("read from parcel failed"); - return nullptr; - } - std::shared_ptr pendingWant(parcel.ReadParcelable()); - agent->SetPendingWant(pendingWant); - - return agent; -} -} // namespace OHOS::Notification::WantAgent diff --git a/frameworks/wantagent/src/want_agent_helper.cpp b/frameworks/wantagent/src/want_agent_helper.cpp deleted file mode 100644 index a37de29fe..000000000 --- a/frameworks/wantagent/src/want_agent_helper.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/* - * 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. - */ - -#include "want_agent_helper.h" - -#include "ability_manager_client.h" -#include "hilog_wrapper.h" -#include "ohos/aafwk/content/want_params_wrapper.h" -#include "pending_want.h" -#include "want_agent_log_wrapper.h" -#include "want_sender_info.h" -#include "want_sender_interface.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS::Notification::WantAgent { -WantAgentHelper::WantAgentHelper() -{} - -unsigned int WantAgentHelper::FlagsTransformer(const std::vector &flags) -{ - unsigned int wantFlags = 0; - if (flags.empty()) { - wantFlags |= FLAG_UPDATE_CURRENT; - return wantFlags; - } - - for (auto flag : flags) { - switch (flag) { - case WantAgentConstant::Flags::ONE_TIME_FLAG: - wantFlags |= FLAG_ONE_SHOT; - break; - case WantAgentConstant::Flags::NO_BUILD_FLAG: - wantFlags |= FLAG_NO_CREATE; - break; - case WantAgentConstant::Flags::CANCEL_PRESENT_FLAG: - wantFlags |= FLAG_CANCEL_CURRENT; - break; - case WantAgentConstant::Flags::UPDATE_PRESENT_FLAG: - wantFlags |= FLAG_UPDATE_CURRENT; - break; - case WantAgentConstant::Flags::CONSTANT_FLAG: - wantFlags |= FLAG_IMMUTABLE; - break; - default: - WANT_AGENT_LOGE("WantAgentHelper::flags is error."); - break; - } - } - return wantFlags; -} - -std::shared_ptr WantAgentHelper::GetWantAgent( - const std::shared_ptr &context, const WantAgentInfo ¶msInfo) -{ - WANT_AGENT_LOGI("WantAgentHelper::GetWantAgent begin."); - if (context == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent invalid input param."); - return nullptr; - } - - std::vector> wants = paramsInfo.GetWants(); - if (wants.empty()) { - WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent invalid input param."); - return nullptr; - } - - HILOG_INFO("%{public}s:bundle name = %{public}s; ability name = %{public}s", - __func__, - wants[0]->GetElement().GetBundleName().c_str(), - wants[0]->GetElement().GetAbilityName().c_str()); - - unsigned int flags = FlagsTransformer(paramsInfo.GetFlags()); - if (flags == 0) { - WANT_AGENT_LOGE("WantAgentHelper::flags invalid."); - return nullptr; - } - - std::shared_ptr extraInfo = paramsInfo.GetExtraInfo(); - std::shared_ptr pendingWant = nullptr; - int requestCode = paramsInfo.GetRequestCode(); - WantAgentConstant::OperationType operationType = paramsInfo.GetOperationType(); - switch (operationType) { - case WantAgentConstant::OperationType::START_ABILITY: - pendingWant = PendingWant::GetAbility(context, requestCode, wants[0], flags, extraInfo); - break; - case WantAgentConstant::OperationType::START_ABILITIES: - pendingWant = PendingWant::GetAbilities(context, requestCode, wants, flags, extraInfo); - break; - case WantAgentConstant::OperationType::START_SERVICE: - pendingWant = PendingWant::GetService(context, requestCode, wants[0], flags); - break; - case WantAgentConstant::OperationType::START_FOREGROUND_SERVICE: - pendingWant = PendingWant::GetForegroundService(context, requestCode, wants[0], flags); - break; - case WantAgentConstant::OperationType::SEND_COMMON_EVENT: - pendingWant = PendingWant::GetCommonEvent(context, requestCode, wants[0], flags); - break; - default: - WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent operation type is error."); - break; - } - - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent the wants does not meet the requirements."); - return nullptr; - } - - std::shared_ptr agent = std::make_shared(pendingWant); - WANT_AGENT_LOGI("WantAgentHelper::GetWantAgent end."); - return agent; -} - -std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo ¶msInfo, int32_t userId) -{ - std::vector> wants = paramsInfo.GetWants(); - if (wants.empty()) { - WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent invalid input param."); - return nullptr; - } - - std::shared_ptr want = wants[0]; - if (want == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent invalid input param."); - return nullptr; - } - - WantsInfo wantsInfo; - wantsInfo.want = *want; - wantsInfo.resolvedTypes = want->GetType(); - if (paramsInfo.GetExtraInfo() != nullptr) { - wantsInfo.want.SetParams(*paramsInfo.GetExtraInfo()); - } - - HILOG_INFO("%{public}s:bundle name = %{public}s; ability name = %{public}s", - __func__, - wantsInfo.want.GetElement().GetBundleName().c_str(), - wantsInfo.want.GetElement().GetAbilityName().c_str()); - - WantSenderInfo wantSenderInfo; - wantSenderInfo.allWants.push_back(wantsInfo); - wantSenderInfo.bundleName = want->GetOperation().GetBundleName(); - wantSenderInfo.flags = FlagsTransformer(paramsInfo.GetFlags()); - wantSenderInfo.type = (int32_t)paramsInfo.GetOperationType(); - wantSenderInfo.userId = userId; - - sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); - if (target == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent target is nullptr."); - return nullptr; - } - std::shared_ptr agent = std::make_shared(std::make_shared(target)); - - return agent; -} - -WantAgentConstant::OperationType WantAgentHelper::GetType(const std::shared_ptr &agent) -{ - if (agent == nullptr || agent->GetPendingWant() == nullptr) { - return WantAgentConstant::OperationType::UNKNOWN_TYPE; - } - - return agent->GetPendingWant()->GetType(agent->GetPendingWant()->GetTarget()); -} - -void WantAgentHelper::TriggerWantAgent(const std::shared_ptr &agent, - const std::shared_ptr &callback, const TriggerInfo ¶msInfo) -{ - HILOG_INFO("%{public}s:begin.", __func__); - if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::TriggerWantAgent invalid input param."); - return; - } - - std::shared_ptr pendingWant = agent->GetPendingWant(); - WantAgentConstant::OperationType type = GetType(agent); - sptr dispatcher = nullptr; - if (callback != nullptr) { - dispatcher = new (std::nothrow) CompletedDispatcher(pendingWant, callback, nullptr); - } - - Send(pendingWant, type, dispatcher, paramsInfo); -} - -void WantAgentHelper::Send(const std::shared_ptr &pendingWant, - WantAgentConstant::OperationType type, const sptr &callBack, const TriggerInfo ¶msInfo) -{ - HILOG_INFO("%{public}s:begin.", __func__); - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::Send invalid input param."); - return; - } - - pendingWant->Send(paramsInfo.GetResultCode(), - paramsInfo.GetWant(), - callBack, - paramsInfo.GetPermission(), - paramsInfo.GetExtraInfo(), - pendingWant->GetTarget()); -} - -void WantAgentHelper::Cancel(const std::shared_ptr &agent) -{ - if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::Cancel WantAgent invalid input param."); - return; - } - - std::shared_ptr pendingWant = agent->GetPendingWant(); - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::Cancel PendingWant invalid input param."); - return; - } - - pendingWant->Cancel(pendingWant->GetTarget()); -} - -bool WantAgentHelper::JudgeEquality( - const std::shared_ptr &agent, const std::shared_ptr &otherAgent) -{ - if ((agent == nullptr) && (otherAgent == nullptr)) { - return true; - } - - if ((agent == nullptr) || (otherAgent == nullptr)) { - return false; - } - - return PendingWant::Equals(agent->GetPendingWant(), otherAgent->GetPendingWant()); -} - -int WantAgentHelper::GetHashCode(const std::shared_ptr &agent) -{ - if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetHashCode WantAgent invalid input param."); - return 0; - } - - std::shared_ptr pendingWant = agent->GetPendingWant(); - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetHashCode PendingWant invalid input param."); - return 0; - } - - return pendingWant->GetHashCode(pendingWant->GetTarget()); -} - -std::string WantAgentHelper::GetBundleName(const std::shared_ptr &agent) -{ - if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetBundleName WantAgent invalid input param."); - return ""; - } - - std::shared_ptr pendingWant = agent->GetPendingWant(); - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetBundleName PendingWant invalid input param."); - return ""; - } - - return pendingWant->GetBundleName(pendingWant->GetTarget()); -} - -int WantAgentHelper::GetUid(const std::shared_ptr &agent) -{ - if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetUid WantAgent invalid input param."); - return -1; - } - - std::shared_ptr pendingWant = agent->GetPendingWant(); - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetUid PendingWant invalid input param."); - return -1; - } - - return pendingWant->GetUid(pendingWant->GetTarget()); -} - -std::shared_ptr WantAgentHelper::GetWant(const std::shared_ptr &agent) -{ - if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetWant WantAgent invalid input param."); - return nullptr; - } - - std::shared_ptr pendingWant = agent->GetPendingWant(); - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetWant PendingWant invalid input param."); - return nullptr; - } - - return pendingWant->GetWant(pendingWant->GetTarget()); -} - -void WantAgentHelper::RegisterCancelListener( - const std::shared_ptr &cancelListener, const std::shared_ptr &agent) -{ - if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::RegisterCancelListener WantAgent invalid input param."); - return; - } - - std::shared_ptr pendingWant = agent->GetPendingWant(); - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::RegisterCancelListener PendingWant invalid input param."); - return; - } - - pendingWant->RegisterCancelListener(cancelListener, pendingWant->GetTarget()); -} - -void WantAgentHelper::UnregisterCancelListener( - const std::shared_ptr &cancelListener, const std::shared_ptr &agent) -{ - if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::UnregisterCancelListener WantAgent invalid input param."); - return; - } - - std::shared_ptr pendingWant = agent->GetPendingWant(); - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::UnregisterCancelListener PendingWant invalid input param."); - return; - } - - pendingWant->UnregisterCancelListener(cancelListener, pendingWant->GetTarget()); -} - -std::string WantAgentHelper::ToString(const std::shared_ptr &agent) -{ - if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::ToString WantAgent invalid input param."); - return ""; - } - - std::shared_ptr pendingWant = agent->GetPendingWant(); - if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::ToString PendingWant invalid input param."); - return ""; - } - - std::shared_ptr info = pendingWant->GetWantSenderInfo(pendingWant->GetTarget()); - if (info == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::ToString WantSenderInfo invalid input param."); - return ""; - } - nlohmann::json jsonObject; - jsonObject["requestCode"] = (*info.get()).requestCode; - jsonObject["operationType"] = (*info.get()).type; - jsonObject["flags"] = (*info.get()).flags; - - nlohmann::json wants = nlohmann::json::array(); - for (auto &wantInfo : (*info.get()).allWants) { - wants.emplace_back(wantInfo.want.ToString()); - } - jsonObject["wants"] = wants; - - if ((*info.get()).allWants.size() > 0) { - nlohmann::json paramsObj; - AAFwk::WantParamWrapper wWrapper((*info.get()).allWants[0].want.GetParams()); - paramsObj["extraInfoValue"] = wWrapper.ToString(); - jsonObject["extraInfo"] = paramsObj; - } - - return jsonObject.dump(); -} - -std::shared_ptr WantAgentHelper::FromString(const std::string &jsonString) -{ - if (jsonString.empty()) { - return nullptr; - } - nlohmann::json jsonObject = nlohmann::json::parse(jsonString); - - int requestCode = -1; - if (jsonObject.contains("requestCode")) { - requestCode = jsonObject.at("requestCode").get(); - } - - WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::UNKNOWN_TYPE; - if (jsonObject.contains("operationType")) { - operationType = static_cast(jsonObject.at("operationType").get()); - } - - int flags = -1; - std::vector flagsVec = {}; - if (jsonObject.contains("flags")) { - flags = jsonObject.at("flags").get(); - } - if (flags | FLAG_ONE_SHOT) { - flagsVec.emplace_back(WantAgentConstant::Flags::ONE_TIME_FLAG); - } else if (flags | FLAG_NO_CREATE) { - flagsVec.emplace_back(WantAgentConstant::Flags::NO_BUILD_FLAG); - } else if (flags | FLAG_CANCEL_CURRENT) { - flagsVec.emplace_back(WantAgentConstant::Flags::CANCEL_PRESENT_FLAG); - } else if (flags | FLAG_UPDATE_CURRENT) { - flagsVec.emplace_back(WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); - } else if (flags | FLAG_IMMUTABLE) { - flagsVec.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - } - - std::vector> wants = {}; - if (jsonObject.contains("wants")) { - for (auto &wantObj : jsonObject.at("wants")) { - auto wantString = wantObj.get(); - wants.emplace_back(std::make_shared(*Want::FromString(wantString))); - } - } - - std::shared_ptr extraInfo = nullptr; - if (jsonObject.contains("extraInfo")) { - auto extraInfoObj = jsonObject.at("extraInfo"); - if (extraInfoObj.contains("extraInfoValue")) { - auto pwWrapper = AAFwk::WantParamWrapper::Parse(extraInfoObj.at("extraInfoValue").get()); - AAFwk::WantParams params; - if (pwWrapper->GetValue(params) == ERR_OK) { - extraInfo = std::make_shared(params); - } - } - } - WantAgentInfo info(requestCode, operationType, flagsVec, wants, extraInfo); - - return GetWantAgent(info); -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/frameworks/wantagent/src/want_agent_info.cpp b/frameworks/wantagent/src/want_agent_info.cpp deleted file mode 100644 index a3a69fb23..000000000 --- a/frameworks/wantagent/src/want_agent_info.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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. - */ - -#include "want_agent_info.h" -#include "want.h" -#include "want_params.h" - -using namespace OHOS::AAFwk; - -namespace OHOS::Notification::WantAgent { -WantAgentInfo::WantAgentInfo() : WantAgentInfo(nullptr) -{} - -WantAgentInfo::WantAgentInfo(int requestCode, const WantAgentConstant::OperationType &operationType, - WantAgentConstant::Flags flag, std::vector> &wants, - const std::shared_ptr &extraInfo) -{ - requestCode_ = requestCode; - operationType_ = operationType; - flags_.push_back(flag); - if (!wants.empty()) { - for (auto want : wants) { - if (want != nullptr) { - wants_.push_back(std::make_shared(*want)); - } - } - } - if (extraInfo != nullptr) { - extraInfo_ = std::make_shared(*extraInfo); - } -} - -WantAgentInfo::WantAgentInfo(int requestCode, const WantAgentConstant::OperationType &operationType, - const std::vector &flags, std::vector> &wants, - const std::shared_ptr &extraInfo) -{ - requestCode_ = requestCode; - operationType_ = operationType; - if (!flags.empty()) { - flags_.insert(flags_.end(), flags.begin(), flags.end()); - } - if (!wants.empty()) { - for (auto want : wants) { - if (want != nullptr) { - wants_.push_back(std::make_shared(*want)); - } - } - } - if (extraInfo != nullptr) { - extraInfo_ = std::make_shared(*extraInfo); - } -} - -WantAgentInfo::WantAgentInfo(const std::shared_ptr ¶mInfo) -{ - if (paramInfo != nullptr) { - requestCode_ = paramInfo->GetRequestCode(); - operationType_ = paramInfo->GetOperationType(); - flags_.insert(flags_.end(), paramInfo->GetFlags().begin(), paramInfo->GetFlags().end()); - if (!paramInfo->GetWants().empty()) { - for (auto want : paramInfo->GetWants()) { - wants_.push_back(std::make_shared(*want)); - } - } - if (paramInfo->GetExtraInfo() != nullptr) { - extraInfo_ = std::make_shared(*paramInfo->GetExtraInfo()); - } - } -} - -int WantAgentInfo::GetRequestCode() const -{ - return requestCode_; -} - -WantAgentConstant::OperationType WantAgentInfo::GetOperationType() const -{ - return operationType_; -} - -std::vector WantAgentInfo::GetFlags() const -{ - return flags_; -} - -std::vector> WantAgentInfo::GetWants() const -{ - return wants_; -} - -std::shared_ptr WantAgentInfo::GetExtraInfo() const -{ - return extraInfo_; -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/frameworks/wantagent/src/want_agent_log_wrapper.cpp b/frameworks/wantagent/src/want_agent_log_wrapper.cpp deleted file mode 100644 index e379cef23..000000000 --- a/frameworks/wantagent/src/want_agent_log_wrapper.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - */ - -#include "want_agent_log_wrapper.h" - -namespace OHOS::Notification::WantAgent { -// initial static member object -WantAgentLogLevel WantAgentLogWrapper::level_ = WantAgentLogLevel::DEBUG; - -bool WantAgentLogWrapper::JudgeLevel(const WantAgentLogLevel &level) -{ - const WantAgentLogLevel &curLevel = WantAgentLogWrapper::GetLogLevel(); - if (level < curLevel) { - return false; - } - return true; -} - -std::string WantAgentLogWrapper::GetBriefFileName(const char *str) -{ - if (!str) { - return std::string(); - } - std::string fullPath(str); - size_t pos = fullPath.find_last_of("/"); - if (pos == std::string::npos) { - return std::string(); - } - return fullPath.substr(pos + 1); -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/frameworks/wantagent/test/BUILD.gn b/frameworks/wantagent/test/BUILD.gn deleted file mode 100644 index 9c2a2b1cc..000000000 --- a/frameworks/wantagent/test/BUILD.gn +++ /dev/null @@ -1,25 +0,0 @@ -# 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. - -group("unittest") { - testonly = true - - deps = [ - "unittest/completed_dispatcher_test:unittest", - "unittest/pending_want_test:unittest", - "unittest/trigger_Info_test:unittest", - "unittest/want_agent_helper_test:unittest", - "unittest/want_agent_info_test:unittest", - "unittest/want_agent_test:unittest", - ] -} diff --git a/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn b/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn deleted file mode 100644 index 7bf5f49ef..000000000 --- a/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn +++ /dev/null @@ -1,60 +0,0 @@ -# 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. - -import("//base/notification/ans_standard/notification.gni") -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = "ans_standard/wantagent" - -ohos_unittest("completed_dispatcher_test") { - module_out_path = module_output_path - include_dirs = [ "//foundation/aafwk/standard/services/abilitymgr/include" ] - - sources = [ "completed_dispatcher_test.cpp" ] - - configs = [ "//utils/native/base:utils_config" ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - deps = [ - "${core_path}:ans_core", - "${frameworks_path}/wantagent:wantagent_innerkits", - "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", - "//foundation/aafwk/standard/services/abilitymgr:abilityms", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "ces_standard:cesfwk_core", - "dmsfwk_standard:zuri", - "eventhandler:libeventhandler", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "samgr_standard:samgr_proxy", - ] -} - -group("unittest") { - testonly = true - deps = [ ":completed_dispatcher_test" ] -} diff --git a/frameworks/wantagent/test/unittest/completed_dispatcher_test/completed_dispatcher_test.cpp b/frameworks/wantagent/test/unittest/completed_dispatcher_test/completed_dispatcher_test.cpp deleted file mode 100644 index 3c6c28bba..000000000 --- a/frameworks/wantagent/test/unittest/completed_dispatcher_test/completed_dispatcher_test.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* - * 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. - */ - -#include -#include "completed_callback.h" -#define private public -#define protected public -#include "completed_dispatcher.h" -#undef private -#undef protected -#include "element_name.h" -#include "event_handler.h" -#include "pending_want.h" -#include "ohos/aafwk/base/base_types.h" -#include "want.h" -#include "want_params.h" -#include "want_receiver_stub.h" -#include "ohos/aafwk/base/bool_wrapper.h" - -using namespace testing::ext; -using namespace OHOS::AAFwk; -using namespace OHOS; -using OHOS::AppExecFwk::ElementName; -using namespace OHOS::AppExecFwk; -using vector_str = std::vector; - -namespace OHOS::Notification::WantAgent { -class CompletedDispatcherTest : public testing::Test { -public: - CompletedDispatcherTest() - {} - ~CompletedDispatcherTest() - {} - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Want MakeWant(std::string deviceId, std::string abilityName, std::string bundleName); - - class CompletedCallbackSon : public CompletedCallback { - /** - * Called when a Send operation as completed. - * - * @param want The original Want that was sent. - * @param resultCode The final result code determined by the Send. - * @param resultData The final data collected by a broadcast. - * @param resultExtras The final extras collected by a broadcast. - */ - public: - void OnSendFinished(const AAFwk::Want &want, int resultCode, const std::string &resultData, - const AAFwk::WantParams &resultExtras) override; - static int code; - }; -}; - -int CompletedDispatcherTest::CompletedCallbackSon::code = 0; - -void CompletedDispatcherTest::CompletedCallbackSon::OnSendFinished( - const AAFwk::Want &want, int resultCode, const std::string &resultData, const AAFwk::WantParams &resultExtras) -{ - code = 100; -} - -Want CompletedDispatcherTest::MakeWant(std::string deviceId, std::string abilityName, std::string bundleName) -{ - ElementName element(deviceId, bundleName, abilityName); - Want want; - want.SetElement(element); - return want; -} - -void CompletedDispatcherTest::SetUpTestCase(void) -{} - -void CompletedDispatcherTest::TearDownTestCase(void) -{} - -void CompletedDispatcherTest::SetUp(void) -{} - -void CompletedDispatcherTest::TearDown(void) -{} - -/* - * @tc.number : CompletedDispatcher_0100 - * @tc.name : CompletedDispatcher Constructors - * @tc.desc : 1.The parameter is nullptr - */ -HWTEST_F(CompletedDispatcherTest, CompletedDispatcher_0100, Function | MediumTest | Level1) -{ - CompletedDispatcher completedDispatcher(nullptr, nullptr, nullptr); - EXPECT_EQ(completedDispatcher.pendingWant_, nullptr); - EXPECT_EQ(completedDispatcher.callback_, nullptr); - EXPECT_EQ(completedDispatcher.handler_, nullptr); -} - -/* - * @tc.number : CompletedDispatcher_0200 - * @tc.name : CompletedDispatcher Constructors - * @tc.desc : 1.The parameter is not nullptr - */ -HWTEST_F(CompletedDispatcherTest, CompletedDispatcher_0200, Function | MediumTest | Level1) -{ - std::shared_ptr callBack = - std::make_shared(); - CompletedDispatcher completedDispatcher(nullptr, callBack, nullptr); - EXPECT_EQ(completedDispatcher.pendingWant_, nullptr); - EXPECT_EQ(completedDispatcher.callback_, callBack); - EXPECT_EQ(completedDispatcher.handler_, nullptr); -} - -/* - * @tc.number : CompletedDispatcher_0300 - * @tc.name : CompletedDispatcher PerformReceive - * @tc.desc : 1.The parameter is not nullptr - */ -HWTEST_F(CompletedDispatcherTest, CompletedDispatcher_0300, Function | MediumTest | Level1) -{ - std::shared_ptr callBack = - std::make_shared(); - CompletedDispatcher completedDispatcher(nullptr, callBack, nullptr); - - Want want = MakeWant("device", "ability", "bundleName"); - std::string key = "key"; - bool value = true; - WantParams wParams; - wParams.SetParam(key, Boolean::Box(value)); - completedDispatcher.PerformReceive(want, 10, "test", wParams, 0, 0, 1); - EXPECT_EQ(completedDispatcher.want_.GetElement().GetBundleName(), "bundleName"); - EXPECT_EQ(completedDispatcher.want_.GetElement().GetAbilityName(), "ability"); - EXPECT_EQ(completedDispatcher.resultCode_, 10); - EXPECT_EQ(completedDispatcher.resultData_, "test"); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(completedDispatcher.resultExtras_.GetParam(key))), value); - EXPECT_EQ(CompletedCallbackSon::code, 100); - CompletedCallbackSon::code = 0; -} - -/* - * @tc.number : CompletedDispatcher_0400 - * @tc.name : CompletedDispatcher PerformReceive - * @tc.desc : 1.The parameter is not nullptr - * 2.called callBack - */ -HWTEST_F(CompletedDispatcherTest, CompletedDispatcher_0400, Function | MediumTest | Level1) -{ - std::shared_ptr callBack = - std::make_shared(); - std::shared_ptr handler = std::make_shared(); - CompletedDispatcher completedDispatcher(nullptr, callBack, handler); - - Want want = MakeWant("device", "ability", "bundleName"); - std::string key = "key"; - bool value = false; - WantParams wParams; - wParams.SetParam(key, Boolean::Box(value)); - completedDispatcher.PerformReceive(want, 10, "test", wParams, 0, 0, 1); - EXPECT_EQ(completedDispatcher.want_.GetElement().GetBundleName(), "bundleName"); - EXPECT_EQ(completedDispatcher.want_.GetElement().GetAbilityName(), "ability"); - EXPECT_EQ(completedDispatcher.resultCode_, 10); - EXPECT_EQ(completedDispatcher.resultData_, "test"); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(completedDispatcher.resultExtras_.GetParam(key))), value); - EXPECT_EQ(CompletedCallbackSon::code, 0); - CompletedCallbackSon::code = 0; -} - -/* - * @tc.number : CompletedDispatcher_0500 - * @tc.name : CompletedDispatcher Run - * @tc.desc : 1.The parameter is not nullptr - * 2.called callBack - */ -HWTEST_F(CompletedDispatcherTest, CompletedDispatcher_0500, Function | MediumTest | Level1) -{ - std::shared_ptr callBack = - std::make_shared(); - CompletedDispatcher completedDispatcher(nullptr, callBack, nullptr); - EXPECT_EQ(completedDispatcher.callback_, callBack); - completedDispatcher.Run(); - EXPECT_EQ(CompletedCallbackSon::code, 100); - CompletedCallbackSon::code = 0; -} - -/* - * @tc.number : CompletedDispatcher_0600 - * @tc.name : CompletedDispatcher Run - * @tc.desc : 1.The parameter is nullptr - * 2.no called callBack - */ -HWTEST_F(CompletedDispatcherTest, CompletedDispatcher_0600, Function | MediumTest | Level1) -{ - CompletedDispatcher completedDispatcher(nullptr, nullptr, nullptr); - EXPECT_EQ(completedDispatcher.callback_, nullptr); - completedDispatcher.Run(); - EXPECT_EQ(CompletedCallbackSon::code, 0); - CompletedCallbackSon::code = 0; -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn deleted file mode 100644 index 80252d5fd..000000000 --- a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn +++ /dev/null @@ -1,68 +0,0 @@ -# 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. - -import("//base/notification/ans_standard/notification.gni") -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = "ans_standard/wantagent" - -ohos_unittest("pending_want_test") { - module_out_path = module_output_path - include_dirs = [ - "//aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/", - "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime", - "//foundation/aafwk/standard/services/abilitymgr/include", - "//foundation/distributedschedule/samgr/adapter/interfaces/innerkits/include/", - "//utils/system/safwk/native/include", - "//utils/native/base/include", - ] - - sources = [ "pending_want_test.cpp" ] - - configs = [ "//utils/native/base:utils_config" ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - deps = [ - "${core_path}:ans_core", - "${frameworks_path}/wantagent:wantagent_innerkits", - "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", - "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", - "//foundation/aafwk/standard/services/abilitymgr:abilityms", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "ces_standard:cesfwk_core", - "dmsfwk_standard:zuri", - "eventhandler:libeventhandler", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "samgr_standard:samgr_proxy", - ] -} - -group("unittest") { - testonly = true - deps = [ ":pending_want_test" ] -} diff --git a/frameworks/wantagent/test/unittest/pending_want_test/pending_want_test.cpp b/frameworks/wantagent/test/unittest/pending_want_test/pending_want_test.cpp deleted file mode 100644 index ee49efd40..000000000 --- a/frameworks/wantagent/test/unittest/pending_want_test/pending_want_test.cpp +++ /dev/null @@ -1,700 +0,0 @@ -/* - * 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. - */ - -#include -#include "ability_manager_client.h" -#include "cancel_listener.h" -#include "completed_callback.h" -#include "completed_dispatcher.h" -#include "context/context.h" -#include "context_container.h" -#include "context_impl.h" -#include "element_name.h" -#include "event_handler.h" -#include "iservice_registry.h" -#include "ohos/aafwk/base/base_types.h" -#define private public -#define protected public -#include "pending_want.h" -#undef private -#undef protected -#include "sa_mgr_client.h" -#include "system_ability_definition.h" -#include "want.h" -#include "wants_info.h" -#include "want_params.h" -#include "want_receiver_stub.h" -#include "want_agent_helper.h" -#include "want_sender_info.h" -#include "want_sender_stub.h" -#include "ohos/aafwk/base/array_wrapper.h" -#include "ohos/aafwk/base/bool_wrapper.h" -#include "ohos/aafwk/base/zchar_wrapper.h" -#include "ohos/aafwk/base/byte_wrapper.h" -#include "ohos/aafwk/base/double_wrapper.h" -#include "ohos/aafwk/base/float_wrapper.h" -#include "ohos/aafwk/base/int_wrapper.h" -#include "ohos/aafwk/base/long_wrapper.h" -#include "ohos/aafwk/base/short_wrapper.h" -#include "ohos/aafwk/base/string_wrapper.h" - -using namespace testing::ext; -using namespace OHOS::AAFwk; -using namespace OHOS; -using OHOS::AppExecFwk::ElementName; -using namespace OHOS::AppExecFwk; -using vector_str = std::vector; - -namespace OHOS::Notification::WantAgent { -class PendingWantTest : public testing::Test { -public: - PendingWantTest() - {} - ~PendingWantTest() - {} - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - static Want MakeWant(std::string deviceId, std::string abilityName, std::string bundleName); - - static int callBackCancelListenerConnt; - - class WantSender : public AAFwk::WantSenderStub { - public: - void Send(SenderInfo &senderInfo) override; - }; - - class CancelListenerSon : public CancelListener { - public: - void OnCancelled(int resultCode) override; - }; -}; - -int PendingWantTest::callBackCancelListenerConnt = 0; - -void PendingWantTest::WantSender::Send(SenderInfo &senderInfo) -{} - -void PendingWantTest::CancelListenerSon::OnCancelled(int resultCode) -{ - callBackCancelListenerConnt++; -} - -Want PendingWantTest::MakeWant(std::string deviceId, std::string abilityName, std::string bundleName) -{ - ElementName element(deviceId, bundleName, abilityName); - Want want; - want.SetElement(element); - return want; -} - -std::shared_ptr GetAppContext() -{ - std::shared_ptr context = std::make_shared(); - return context; -} - -void PendingWantTest::SetUpTestCase(void) -{} - -void PendingWantTest::TearDownTestCase(void) -{} - -void PendingWantTest::SetUp(void) -{} - -void PendingWantTest::TearDown(void) -{} - -/* - * @tc.number : PendingWant_0100 - * @tc.name : PendingWant Constructors - * @tc.desc : 1.The parameter is nullptr - */ -HWTEST_F(PendingWantTest, PendingWant_0100, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - EXPECT_EQ(pendingWant.target_, nullptr); - EXPECT_EQ(pendingWant.cancelReceiver_, nullptr); - EXPECT_EQ(pendingWant.whitelistToken_, nullptr); -} - -/* - * @tc.number : PendingWant_0200 - * @tc.name : PendingWant Constructors - * @tc.desc : 1.The parameter target is not nullptr - */ -HWTEST_F(PendingWantTest, PendingWant_0200, Function | MediumTest | Level1) -{ - sptr target(new (std::nothrow) WantSender()); - PendingWant pendingWant(target); - EXPECT_EQ(pendingWant.target_, target); - EXPECT_EQ(pendingWant.cancelReceiver_, nullptr); - EXPECT_EQ(pendingWant.whitelistToken_, nullptr); -} - -/* - * @tc.number : PendingWant_0300 - * @tc.name : PendingWant GetType - * @tc.desc : 1.Get PendingWant Type (UNKNOWN_TYPE) - */ -HWTEST_F(PendingWantTest, PendingWant_0300, Function | MediumTest | Level1) -{ - sptr target = nullptr; - PendingWant pendingWant(target); - EXPECT_EQ(pendingWant.target_, target); - EXPECT_EQ(pendingWant.GetType(target), WantAgentConstant::OperationType::UNKNOWN_TYPE); -} - -/* - * @tc.number : PendingWant_0400 - * @tc.name : PendingWant GetAbility - * @tc.desc : 1.Get pendingWant (context is nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_0400, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetAbility(nullptr, requestCode, want, flags); - EXPECT_EQ(pendingWant, nullptr); -} - - -/* - * @tc.number : PendingWant_0600 - * @tc.name : PendingWant GetAbility - * @tc.desc : 1.Get pendingWant (options is not nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_0600, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - bool value = true; - std::string key = "key"; - std::shared_ptr wParams = std::make_shared(); - wParams->SetParam(key, Boolean::Box(value)); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetAbility( - GetAppContext(), requestCode, want, flags, wParams); - EXPECT_NE(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_0700 - * @tc.name : PendingWant GetAbilities - * @tc.desc : 1.Get pendingWant (context is nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_0700, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - std::shared_ptr want2 = std::make_shared(); - ElementName element2("device", "bundleName", "abilityName"); - want2->SetElement(element2); - std::vector> wants; - wants.emplace_back(want); - wants.emplace_back(want2); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetAbilities( - nullptr, requestCode, wants, flags); - EXPECT_EQ(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_0800 - * @tc.name : PendingWant GetAbilities - * @tc.desc : 1.Get pendingWant (context is not nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_0800, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - std::shared_ptr want2 = std::make_shared(); - ElementName element2("device", "bundleName", "abilityName"); - want2->SetElement(element2); - std::vector> wants; - wants.emplace_back(want); - wants.emplace_back(want2); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetAbilities( - GetAppContext(), requestCode, wants, flags); - EXPECT_NE(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_0900 - * @tc.name : PendingWant GetAbilities - * @tc.desc : 1.Get pendingWant (options is not nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_0900, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - std::shared_ptr want2 = std::make_shared(); - ElementName element2("device", "bundleName", "abilityName"); - want2->SetElement(element2); - std::vector> wants; - wants.emplace_back(want); - wants.emplace_back(want2); - bool value = true; - std::string key = "key"; - std::shared_ptr wParams = std::make_shared(); - wParams->SetParam(key, Boolean::Box(value)); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetAbilities( - GetAppContext(), requestCode, wants, flags, wParams); - EXPECT_NE(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_1000 - * @tc.name : PendingWant GetCommonEventAsUser - * @tc.desc : 1.Get pendingWant (context is nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_1000, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetCommonEventAsUser( - nullptr, requestCode, want, flags, 0); - EXPECT_EQ(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_1100 - * @tc.name : PendingWant GetCommonEventAsUser - * @tc.desc : 1.Get pendingWant (context is not nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_1100, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetCommonEventAsUser( - GetAppContext(), requestCode, want, flags, 0); - EXPECT_NE(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_1200 - * @tc.name : PendingWant GetCommonEventAsUser - * @tc.desc : 1.Get pendingWant (want is nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_1200, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want; - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetCommonEventAsUser( - GetAppContext(), requestCode, want, flags, 0); - EXPECT_NE(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_1300 - * @tc.name : PendingWant GetService - * @tc.desc : 1.Get pendingWant (want is nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_1300, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want; - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetService( - GetAppContext(), requestCode, want, flags); - EXPECT_NE(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_1400 - * @tc.name : PendingWant GetService - * @tc.desc : 1.Get pendingWant (context is nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_1400, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetService(nullptr, requestCode, want, flags); - EXPECT_EQ(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_1500 - * @tc.name : PendingWant GetForegroundService - * @tc.desc : 1.Get pendingWant (want is nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_1500, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want; - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetForegroundService( - GetAppContext(), requestCode, want, flags); - EXPECT_NE(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_1600 - * @tc.name : PendingWant GetForegroundService - * @tc.desc : 1.Get pendingWant (context is nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_1600, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - std::shared_ptr pendingWant = PendingWant::GetForegroundService(nullptr, requestCode, want, flags); - EXPECT_EQ(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_1700 - * @tc.name : PendingWant GetForegroundService - * @tc.desc : 1.Get pendingWant (want is nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_1700, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want; - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - WantAgentConstant::OperationType type = WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; - std::shared_ptr pendingWant = - PendingWant::BuildServicePendingWant(GetAppContext(), requestCode, want, flags, type); - EXPECT_NE(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_1800 - * @tc.name : PendingWant GetForegroundService - * @tc.desc : 1.Get pendingWant (context is nullptr) - */ -HWTEST_F(PendingWantTest, PendingWant_1800, Function | MediumTest | Level1) -{ - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - WantAgentConstant::OperationType type = WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; - std::shared_ptr pendingWant = - PendingWant::BuildServicePendingWant(nullptr, requestCode, want, flags, type); - EXPECT_EQ(pendingWant, nullptr); -} - -/* - * @tc.number : PendingWant_1900 - * @tc.name : PendingWant Equals - * @tc.desc : 1.Equals - */ -HWTEST_F(PendingWantTest, PendingWant_1900, Function | MediumTest | Level1) -{ - sptr target(new (std::nothrow) WantSender()); - std::shared_ptr pendingWant = std::make_shared(target); - sptr target2(nullptr); - std::shared_ptr pendingWant2 = std::make_shared(target2); - EXPECT_EQ(pendingWant->Equals(pendingWant, pendingWant2), false); -} - -/* - * @tc.number : PendingWant_2000 - * @tc.name : PendingWant Equals - * @tc.desc : 1.Equals - */ -HWTEST_F(PendingWantTest, PendingWant_2000, Function | MediumTest | Level1) -{ - sptr target(new (std::nothrow) WantSender()); - std::shared_ptr pendingWant = std::make_shared(target); - std::shared_ptr pendingWant2(nullptr); - EXPECT_EQ(pendingWant->Equals(pendingWant, pendingWant2), false); -} - -/* - * @tc.number : PendingWant_2100 - * @tc.name : PendingWant SendAndReturnResult - * @tc.desc : SendAndReturnResult - */ -HWTEST_F(PendingWantTest, PendingWant_2100, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - bool value = true; - std::shared_ptr wParams = std::make_shared(); - std::string key = "key"; - wParams->SetParam(key, Boolean::Box(value)); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - AbilityManagerClient::GetInstance()->Connect(); - EXPECT_EQ(INNER_ERR, - pendingWant.SendAndReturnResult(requestCode, want, nullptr, "Permission", nullptr, nullptr)); -} - -/* - * @tc.number : PendingWant_2200 - * @tc.name : PendingWant SendAndReturnResult - * @tc.desc : SendAndReturnResult - */ -HWTEST_F(PendingWantTest, PendingWant_2200, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - int requestCode = 10; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - bool value = true; - std::shared_ptr wParams = std::make_shared(); - std::string key = "key"; - wParams->SetParam(key, Boolean::Box(value)); - unsigned int flags = 1; - flags |= FLAG_NO_CREATE; - AbilityManagerClient::GetInstance()->Connect(); - EXPECT_EQ(1, pendingWant.SendAndReturnResult(requestCode, want, nullptr, "Permission", nullptr, nullptr)); -} - -/* - * @tc.number : PendingWant_2300 - * @tc.name : PendingWant Equals - * @tc.desc : Equals - */ -HWTEST_F(PendingWantTest, PendingWant_2300, Function | MediumTest | Level1) -{ - sptr target(new (std::nothrow) WantSender()); - std::shared_ptr pendingWant = std::make_shared(target); - std::shared_ptr pendingWant2 = std::make_shared(target); - EXPECT_EQ(pendingWant->Equals(pendingWant, pendingWant2), true); -} - -/* - * @tc.number : PendingWant_2400 - * @tc.name : PendingWant GetTarget - * @tc.desc : 1.GetTarget - */ -HWTEST_F(PendingWantTest, PendingWant_2400, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - auto target = pendingWant.GetTarget(); - EXPECT_EQ(target, nullptr); -} - -/* - * @tc.number : PendingWant_2500 - * @tc.name : PendingWant GetTarget - * @tc.desc : 1.GetTarget - */ -HWTEST_F(PendingWantTest, PendingWant_2500, Function | MediumTest | Level1) -{ - sptr target(new (std::nothrow) WantSender()); - PendingWant pendingWant(target); - auto target1 = pendingWant.GetTarget(); - EXPECT_EQ(target1, target); -} - -/* - * @tc.number : PendingWant_2600 - * @tc.name : PendingWant RegisterCancelListener - * @tc.desc : 1.RegisterCancelListener - */ -HWTEST_F(PendingWantTest, PendingWant_2600, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - std::shared_ptr cancelListener1 = std::make_shared(); - std::shared_ptr cancelListener2 = std::make_shared(); - pendingWant.RegisterCancelListener(cancelListener1, nullptr); - pendingWant.RegisterCancelListener(cancelListener2, nullptr); - EXPECT_EQ(static_cast(pendingWant.cancelListeners_.size()), 2); -} - -/* - * @tc.number : PendingWant_2700 - * @tc.name : PendingWant RegisterCancelListener - * @tc.desc : 1.RegisterCancelListener - */ -HWTEST_F(PendingWantTest, PendingWant_2700, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - std::shared_ptr cancelListener2 = std::make_shared(); - pendingWant.RegisterCancelListener(nullptr, nullptr); - pendingWant.RegisterCancelListener(cancelListener2, nullptr); - EXPECT_EQ(static_cast(pendingWant.cancelListeners_.size()), 1); -} - -/* - * @tc.number : PendingWant_2800 - * @tc.name : PendingWant RegisterCancelListener - * @tc.desc : 1.RegisterCancelListener - */ -HWTEST_F(PendingWantTest, PendingWant_2800, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - pendingWant.RegisterCancelListener(nullptr, nullptr); - pendingWant.RegisterCancelListener(nullptr, nullptr); - EXPECT_EQ(static_cast(pendingWant.cancelListeners_.size()), 0); -} - -/* - * @tc.number : PendingWant_2900 - * @tc.name : PendingWant NotifyCancelListeners - * @tc.desc : 1.NotifyCancelListeners - */ -HWTEST_F(PendingWantTest, PendingWant_2900, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - std::shared_ptr cancelListener1 = std::make_shared(); - std::shared_ptr cancelListener2 = std::make_shared(); - pendingWant.RegisterCancelListener(cancelListener1, nullptr); - pendingWant.RegisterCancelListener(cancelListener2, nullptr); - pendingWant.NotifyCancelListeners(0); - EXPECT_EQ(callBackCancelListenerConnt, 2); - callBackCancelListenerConnt = 0; -} - -/* - * @tc.number : PendingWant_3000 - * @tc.name : PendingWant NotifyCancelListeners - * @tc.desc : 1.NotifyCancelListeners - */ -HWTEST_F(PendingWantTest, PendingWant_3000, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - std::shared_ptr cancelListener2 = std::make_shared(); - pendingWant.RegisterCancelListener(nullptr, nullptr); - pendingWant.RegisterCancelListener(cancelListener2, nullptr); - pendingWant.NotifyCancelListeners(0); - EXPECT_EQ(callBackCancelListenerConnt, 1); - callBackCancelListenerConnt = 0; -} - -/* - * @tc.number : PendingWant_3100 - * @tc.name : PendingWant NotifyCancelListeners - * @tc.desc : 1.NotifyCancelListeners - */ -HWTEST_F(PendingWantTest, PendingWant_3100, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - pendingWant.RegisterCancelListener(nullptr, nullptr); - pendingWant.RegisterCancelListener(nullptr, nullptr); - pendingWant.NotifyCancelListeners(0); - EXPECT_EQ(callBackCancelListenerConnt, 0); - callBackCancelListenerConnt = 0; -} - -/* - * @tc.number : PendingWant_3200 - * @tc.name : PendingWant UnregisterCancelListener - * @tc.desc : 1.UnregisterCancelListener - */ -HWTEST_F(PendingWantTest, PendingWant_3200, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - std::shared_ptr cancelListener1 = std::make_shared(); - std::shared_ptr cancelListener2 = std::make_shared(); - pendingWant.RegisterCancelListener(cancelListener1, nullptr); - pendingWant.RegisterCancelListener(cancelListener2, nullptr); - EXPECT_EQ(static_cast(pendingWant.cancelListeners_.size()), 2); - pendingWant.UnregisterCancelListener(cancelListener1, nullptr); - EXPECT_EQ(static_cast(pendingWant.cancelListeners_.size()), 1); -} - -/* - * @tc.number : PendingWant_3300 - * @tc.name : PendingWant UnregisterCancelListener - * @tc.desc : 1.UnregisterCancelListener - */ -HWTEST_F(PendingWantTest, PendingWant_3300, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - std::shared_ptr cancelListener2 = std::make_shared(); - pendingWant.RegisterCancelListener(nullptr, nullptr); - pendingWant.RegisterCancelListener(cancelListener2, nullptr); - EXPECT_EQ(static_cast(pendingWant.cancelListeners_.size()), 1); - pendingWant.UnregisterCancelListener(cancelListener2, nullptr); - EXPECT_EQ(static_cast(pendingWant.cancelListeners_.size()), 0); -} - -/* - * @tc.number : PendingWant_3400 - * @tc.name : PendingWant UnregisterCancelListener - * @tc.desc : 1.UnregisterCancelListener - */ -HWTEST_F(PendingWantTest, PendingWant_3400, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - pendingWant.UnregisterCancelListener(nullptr, nullptr); - EXPECT_EQ(static_cast(pendingWant.cancelListeners_.size()), 0); -} - -/* - * @tc.number : PendingWant_3500 - * @tc.name : PendingWant GetWant - * @tc.desc : 1.GetWant - */ -HWTEST_F(PendingWantTest, PendingWant_3500, Function | MediumTest | Level1) -{ - PendingWant pendingWant(nullptr); - auto want = pendingWant.GetWant(nullptr); - EXPECT_EQ(want, nullptr); -} - -/* - * @tc.number : PendingWant_3600 - * @tc.name : PendingWant Equals - * @tc.desc : Equals - */ -HWTEST_F(PendingWantTest, PendingWant_3700, Function | MediumTest | Level1) -{ - std::shared_ptr pendingWant(nullptr); - std::shared_ptr pendingWant2(nullptr); - EXPECT_EQ(pendingWant->Equals(pendingWant, pendingWant2), true); -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn b/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn deleted file mode 100644 index 2c7ffd04c..000000000 --- a/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn +++ /dev/null @@ -1,60 +0,0 @@ -# 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. - -import("//base/notification/ans_standard/notification.gni") -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = "ans_standard/wantagent" - -ohos_unittest("trigger_Info_test") { - module_out_path = module_output_path - include_dirs = [ "//foundation/aafwk/standard/services/abilitymgr/include" ] - - sources = [ "trigger_Info_test.cpp" ] - - configs = [ "//utils/native/base:utils_config" ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - deps = [ - "${core_path}:ans_core", - "${frameworks_path}/wantagent:wantagent_innerkits", - "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", - "//foundation/aafwk/standard/services/abilitymgr:abilityms", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "ces_standard:cesfwk_core", - "dmsfwk_standard:zuri", - "eventhandler:libeventhandler", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "samgr_standard:samgr_proxy", - ] -} - -group("unittest") { - testonly = true - deps = [ ":trigger_Info_test" ] -} diff --git a/frameworks/wantagent/test/unittest/trigger_Info_test/trigger_Info_test.cpp b/frameworks/wantagent/test/unittest/trigger_Info_test/trigger_Info_test.cpp deleted file mode 100644 index 08c195f16..000000000 --- a/frameworks/wantagent/test/unittest/trigger_Info_test/trigger_Info_test.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * 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. - */ - -#include - -#include "completed_callback.h" -#include "event_handler.h" -#include "element_name.h" -#include "ohos/aafwk/base/base_types.h" -#include "pending_want.h" -#define private public -#define protected public -#include "trigger_info.h" -#undef private -#undef protected -#include "want.h" -#include "want_params.h" -#include "want_receiver_stub.h" -#include "ohos/aafwk/base/bool_wrapper.h" - -using namespace testing::ext; -using namespace OHOS::AAFwk; -using namespace OHOS; -using OHOS::AppExecFwk::ElementName; -using namespace OHOS::AppExecFwk; -using vector_str = std::vector; - -namespace OHOS::Notification::WantAgent { -class TriggerInfoTest : public testing::Test { -public: - TriggerInfoTest() - {} - ~TriggerInfoTest() - {} - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void TriggerInfoTest::SetUpTestCase(void) -{} - -void TriggerInfoTest::TearDownTestCase(void) -{} - -void TriggerInfoTest::SetUp(void) -{} - -void TriggerInfoTest::TearDown(void) -{} - -/* - * @tc.number : TriggerInfo_0100 - * @tc.name : TriggerInfo Constructors - * @tc.desc : 1.def Constructors - */ -HWTEST_F(TriggerInfoTest, TriggerInfo_0100, Function | MediumTest | Level1) -{ - TriggerInfo triggerInfo; - EXPECT_EQ(triggerInfo.permission_, ""); - EXPECT_EQ(triggerInfo.extraInfo_, nullptr); - EXPECT_EQ(triggerInfo.want_, nullptr); - EXPECT_EQ(triggerInfo.resultCode_, 0); -} - -/* - * @tc.number : TriggerInfo_0200 - * @tc.name : TriggerInfo Constructors - * @tc.desc : 1.def Constructors - */ -HWTEST_F(TriggerInfoTest, TriggerInfo_0200, Function | MediumTest | Level1) -{ - std::string permission = "nihao"; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - bool value = true; - std::string key = "key"; - std::shared_ptr wParams = std::make_shared(); - wParams->SetParam(key, Boolean::Box(value)); - int resultCode = 10; - TriggerInfo triggerInfo(permission, wParams, want, resultCode); - EXPECT_EQ(triggerInfo.permission_, permission); - EXPECT_NE(triggerInfo.extraInfo_, wParams); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(triggerInfo.extraInfo_->GetParam(key))), value); - EXPECT_NE(triggerInfo.want_, want); - EXPECT_EQ(triggerInfo.want_->GetElement().GetBundleName(), "bundleName"); - EXPECT_EQ(triggerInfo.want_->GetElement().GetAbilityName(), "abilityName"); - EXPECT_EQ(triggerInfo.resultCode_, resultCode); -} - -/* - * @tc.number : TriggerInfo_0300 - * @tc.name : TriggerInfo Constructors - * @tc.desc : 1.copy Constructors - */ -HWTEST_F(TriggerInfoTest, TriggerInfo_0300, Function | MediumTest | Level1) -{ - std::string permission = "nihao"; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - bool value = true; - std::string key = "key"; - std::shared_ptr wParams = std::make_shared(); - wParams->SetParam(key, Boolean::Box(value)); - int resultCode = 10; - TriggerInfo triggerInfo(permission, wParams, want, resultCode); - EXPECT_EQ(triggerInfo.permission_, permission); - EXPECT_NE(triggerInfo.extraInfo_, wParams); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(triggerInfo.extraInfo_->GetParam(key))), value); - EXPECT_NE(triggerInfo.want_, want); - EXPECT_EQ(triggerInfo.want_->GetElement().GetBundleName(), "bundleName"); - EXPECT_EQ(triggerInfo.want_->GetElement().GetAbilityName(), "abilityName"); - EXPECT_EQ(triggerInfo.resultCode_, resultCode); - TriggerInfo triggerInfo1(triggerInfo); - EXPECT_EQ(triggerInfo1.permission_, triggerInfo.permission_); - EXPECT_NE(triggerInfo1.extraInfo_, triggerInfo.extraInfo_); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(triggerInfo1.extraInfo_->GetParam(key))), value); - EXPECT_NE(triggerInfo1.want_, triggerInfo.want_); - EXPECT_EQ(triggerInfo1.want_->GetElement().GetBundleName(), "bundleName"); - EXPECT_EQ(triggerInfo1.want_->GetElement().GetAbilityName(), "abilityName"); - EXPECT_EQ(triggerInfo1.resultCode_, triggerInfo.resultCode_); -} - -/* - * @tc.number : TriggerInfo_0400 - * @tc.name : TriggerInfo::Builder SetPermission - * @tc.desc : 1.SetPermission - */ -HWTEST_F(TriggerInfoTest, TriggerInfo_0400, Function | MediumTest | Level1) -{ - std::shared_ptr builder = std::make_shared(); - builder->SetPermission("nihao"); - EXPECT_EQ(builder->permission_, "nihao"); -} - -/* - * @tc.number : TriggerInfo_0500 - * @tc.name : TriggerInfo::Builder SetWantParams - * @tc.desc : 1.SetWantParams - */ -HWTEST_F(TriggerInfoTest, TriggerInfo_0500, Function | MediumTest | Level1) -{ - std::shared_ptr builder = std::make_shared(); - bool value = true; - std::string key = "key"; - std::shared_ptr wParams = std::make_shared(); - wParams->SetParam(key, Boolean::Box(value)); - builder->SetWantParams(wParams); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(builder->params_->GetParam(key))), value); -} - -/* - * @tc.number : TriggerInfo_0600 - * @tc.name : TriggerInfo::Builder SetWant - * @tc.desc : 1.SetWant - */ -HWTEST_F(TriggerInfoTest, TriggerInfo_0600, Function | MediumTest | Level1) -{ - std::shared_ptr builder = std::make_shared(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - builder->SetWant(want); - EXPECT_EQ(builder->want_->GetElement().GetBundleName(), "bundleName"); - EXPECT_EQ(builder->want_->GetElement().GetAbilityName(), "abilityName"); -} - -/* - * @tc.number : TriggerInfo_0700 - * @tc.name : TriggerInfo::Builder SetResultCode - * @tc.desc : 1.SetResultCode - */ -HWTEST_F(TriggerInfoTest, TriggerInfo_0700, Function | MediumTest | Level1) -{ - std::shared_ptr builder = std::make_shared(); - int resultCode = 100; - builder->SetResultCode(resultCode); - EXPECT_EQ(builder->resultCode_, resultCode); -} - -/* - * @tc.number : TriggerInfo_0800 - * @tc.name : TriggerInfo::Builder Build - * @tc.desc : 1.Build,Great TriggerInfo object - */ -HWTEST_F(TriggerInfoTest, TriggerInfo_0800, Function | MediumTest | Level1) -{ - std::shared_ptr builder = std::make_shared(); - builder->SetPermission("nihao"); - bool value = true; - std::string key = "key"; - std::shared_ptr wParams = std::make_shared(); - wParams->SetParam(key, Boolean::Box(value)); - builder->SetWantParams(wParams); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - builder->SetWant(want); - int resultCode = 100; - builder->SetResultCode(resultCode); - - auto info = builder->Build(); - EXPECT_NE(info, nullptr); - EXPECT_EQ(info->permission_, "nihao"); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(info->extraInfo_->GetParam(key))), value); - EXPECT_EQ(info->want_->GetElement().GetBundleName(), "bundleName"); - EXPECT_EQ(info->want_->GetElement().GetAbilityName(), "abilityName"); - EXPECT_EQ(info->resultCode_, resultCode); -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn deleted file mode 100644 index 926b3dcf1..000000000 --- a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn +++ /dev/null @@ -1,65 +0,0 @@ -# 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. - -import("//base/notification/ans_standard/notification.gni") -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = "ans_standard/wantagent" - -ohos_unittest("want_agent_helper_test") { - module_out_path = module_output_path - include_dirs = [ - "//aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/", - "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime", - "//foundation/aafwk/standard/services/abilitymgr/include", - ] - - sources = [ "want_agent_helper_test.cpp" ] - - configs = [ "//utils/native/base:utils_config" ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - deps = [ - "${core_path}:ans_core", - "${frameworks_path}/wantagent:wantagent_innerkits", - "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", - "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", - "//foundation/aafwk/standard/services/abilitymgr:abilityms", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "ces_standard:cesfwk_core", - "dmsfwk_standard:zuri", - "eventhandler:libeventhandler", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "samgr_standard:samgr_proxy", - ] -} - -group("unittest") { - testonly = true - deps = [ ":want_agent_helper_test" ] -} diff --git a/frameworks/wantagent/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp b/frameworks/wantagent/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp deleted file mode 100644 index 622c8c8b4..000000000 --- a/frameworks/wantagent/test/unittest/want_agent_helper_test/want_agent_helper_test.cpp +++ /dev/null @@ -1,711 +0,0 @@ -/* - * 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. - */ - -#include -#include "ability_context.h" -#include "completed_callback.h" -#include "context_container.h" -#include "context_impl.h" -#include "context/context.h" -#include "element_name.h" -#include "event_handler.h" -#include "ohos/aafwk/base/base_types.h" -#include "pending_want.h" -#include "want.h" -#include "want_agent.h" -#include "want_agent_constant.h" -#define private public -#define protected public -#include "want_agent_helper.h" -#include "want_agent_info.h" -#undef private -#undef protected -#include "want_params.h" -#include "want_receiver_stub.h" -#include "want_sender_stub.h" -#include "ohos/aafwk/base/bool_wrapper.h" - -using namespace testing::ext; -using namespace OHOS::AAFwk; -using namespace OHOS; -using OHOS::AppExecFwk::ElementName; -using namespace OHOS::AppExecFwk; -using vector_str = std::vector; - -namespace OHOS::Notification::WantAgent { -class WantAgentHelperTest : public testing::Test { -public: - WantAgentHelperTest() - {} - ~WantAgentHelperTest() - {} - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - class WantSender : public AAFwk::WantSenderStub { - public: - void Send(SenderInfo &senderInfo) override; - }; -}; - -void WantAgentHelperTest::WantSender::Send(SenderInfo &senderInfo) -{} - -void WantAgentHelperTest::SetUpTestCase(void) -{} - -void WantAgentHelperTest::TearDownTestCase(void) -{} - -void WantAgentHelperTest::SetUp(void) -{} - -void WantAgentHelperTest::TearDown(void) -{} - -/* - * @tc.number : WantAgentHelper_0100 - * @tc.name : WantAgentHelper Constructors - * @tc.desc : 1.WantAgentConstant::Flags::ONE_TIME_FLAG - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_0100, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::vector flags; - flags.emplace_back(WantAgentConstant::Flags::ONE_TIME_FLAG); - EXPECT_EQ(wantAgentHelper->FlagsTransformer(flags), static_cast(0x40000000)); -} - -/* - * @tc.number : WantAgentHelper_0200 - * @tc.name : WantAgentHelper Constructors - * @tc.desc : 1.WantAgentConstant::Flags::NO_BUILD_FLAG - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_0200, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::vector flags; - flags.emplace_back(WantAgentConstant::Flags::NO_BUILD_FLAG); - EXPECT_EQ(wantAgentHelper->FlagsTransformer(flags), static_cast(0x20000000)); -} - -/* - * @tc.number : WantAgentHelper_0300 - * @tc.name : WantAgentHelper Constructors - * @tc.desc : 1.WantAgentConstant::Flags::CANCEL_PRESENT_FLAG - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_0300, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::vector flags; - flags.emplace_back(WantAgentConstant::Flags::CANCEL_PRESENT_FLAG); - EXPECT_EQ(wantAgentHelper->FlagsTransformer(flags), static_cast(0x10000000)); -} - -/* - * @tc.number : WantAgentHelper_0400 - * @tc.name : WantAgentHelper Constructors - * @tc.desc : 1.WantAgentConstant::Flags::UPDATE_PRESENT_FLAG - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_0400, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::vector flags; - flags.emplace_back(WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); - EXPECT_EQ(wantAgentHelper->FlagsTransformer(flags), static_cast(0x8000000)); -} - -/* - * @tc.number : WantAgentHelper_0500 - * @tc.name : WantAgentHelper Constructors - * @tc.desc : 1.WantAgentConstant::Flags::CONSTANT_FLAG - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_0500, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::vector flags; - flags.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - EXPECT_EQ(wantAgentHelper->FlagsTransformer(flags), static_cast(0x4000000)); -} - -/* - * @tc.number : WantAgentHelper_0600 - * @tc.name : WantAgentHelper Constructors - * @tc.desc : 1.WantAgentConstant::Flags::REPLACE_BUNDLE - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_0600, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::vector flags; - flags.emplace_back(WantAgentConstant::Flags::REPLACE_BUNDLE); - EXPECT_EQ( - wantAgentHelper->FlagsTransformer(flags), static_cast(WantAgentConstant::Flags::ONE_TIME_FLAG)); -} - -/* - * @tc.number : WantAgentHelper_0700 - * @tc.name : WantAgentHelper Constructors - * @tc.desc : 1.WantAgentConstant::Flags::CONSTANT_FLAG | UPDATE_PRESENT_FLAG | REPLACE_BUNDLE - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_0700, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::vector flags; - flags.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - flags.emplace_back(WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); - flags.emplace_back(WantAgentConstant::Flags::REPLACE_BUNDLE); - EXPECT_EQ(wantAgentHelper->FlagsTransformer(flags), static_cast(0xc000000)); -} - -/* - * @tc.number : WantAgentHelper_0800 - * @tc.name : WantAgentHelper GetWantAgent - * @tc.desc : 1.GetWantAgent context is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_0800, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - WantAgentInfo wantAgentInfo; - auto wantAgent = wantAgentHelper->GetWantAgent(nullptr, wantAgentInfo); - EXPECT_EQ(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_0900 - * @tc.name : WantAgentHelper GetWantAgent - * @tc.desc : 1.GetWantAgent context is not nullptr - * ` 2.wantAgentInfo.wants_ empty - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_0900, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.clear(); - auto wantAgent = wantAgentHelper->GetWantAgent(nullptr, wantAgentInfo); - EXPECT_EQ(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_1000 - * @tc.name : WantAgentHelper GetWantAgent - * @tc.desc : 1.GetWantAgent context is not nullptr - * 2.wantAgentInfo.wants_.siez() != wantAgentInfo.flags_.siez() - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_1000, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = OHOS::AbilityRuntime::Context::GetApplicationContext(); - WantAgentInfo wantAgentInfo; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.clear(); - auto wantAgent = wantAgentHelper->GetWantAgent(context, wantAgentInfo); - EXPECT_EQ(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_1100 - * @tc.name : WantAgentHelper GetWantAgent - * @tc.desc : 1.GetWantAgent context is not nullptr - * 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez() - * 3.FlagsTransformer return 0 - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_1100, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = OHOS::AbilityRuntime::Context::GetApplicationContext(); - WantAgentInfo wantAgentInfo; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::REPLACE_BUNDLE); - auto wantAgent = wantAgentHelper->GetWantAgent(context, wantAgentInfo); - EXPECT_EQ(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_1200 - * @tc.name : WantAgentHelper GetWantAgent - * @tc.desc : 1.GetWantAgent context is not nullptr - * 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez() - * 3.FlagsTransformer return ok - * 4.Type is WantAgentConstant::OperationType::START_ABILITY - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_1200, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = std::make_shared(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.operationType_ = WantAgentConstant::OperationType::START_ABILITY; - wantAgentInfo.requestCode_ = 10; - auto wantAgent = wantAgentHelper->GetWantAgent(context, wantAgentInfo); - EXPECT_NE(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_1300 - * @tc.name : WantAgentHelper GetWantAgent - * @tc.desc : 1.GetWantAgent context is not nullptr - * 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez() - * 3.FlagsTransformer return ok - * 4.Type is WantAgentConstant::OperationType::START_ABILITIES - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_1300, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = std::make_shared(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.operationType_ = WantAgentConstant::OperationType::START_ABILITIES; - wantAgentInfo.requestCode_ = 10; - auto wantAgent = wantAgentHelper->GetWantAgent(context, wantAgentInfo); - EXPECT_NE(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_1400 - * @tc.name : WantAgentHelper GetWantAgent - * @tc.desc : 1.GetWantAgent context is not nullptr - * 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez() - * 3.FlagsTransformer return ok - * 4.Type is WantAgentConstant::OperationType::START_SERVICE - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_1400, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = std::make_shared(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.operationType_ = WantAgentConstant::OperationType::START_SERVICE; - wantAgentInfo.requestCode_ = 10; - auto wantAgent = wantAgentHelper->GetWantAgent(context, wantAgentInfo); - EXPECT_NE(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_1500 - * @tc.name : WantAgentHelper GetWantAgent - * @tc.desc : 1.GetWantAgent context is not nullptr - * 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez() - * 3.FlagsTransformer return ok - * 4.Type is WantAgentConstant::OperationType::START_FOREGROUND_SERVICE - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_1500, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = std::make_shared(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.operationType_ = WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; - wantAgentInfo.requestCode_ = 10; - auto wantAgent = wantAgentHelper->GetWantAgent(context, wantAgentInfo); - EXPECT_NE(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_1600 - * @tc.name : WantAgentHelper GetWantAgent - * @tc.desc : 1.GetWantAgent context is not nullptr - * 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez() - * 3.FlagsTransformer return ok - * 4.Type is WantAgentConstant::OperationType::START_FOREGROUND_SERVICE - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_1600, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = std::make_shared(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.operationType_ = WantAgentConstant::OperationType::SEND_COMMON_EVENT; - wantAgentInfo.requestCode_ = 10; - auto wantAgent = wantAgentHelper->GetWantAgent(context, wantAgentInfo); - EXPECT_NE(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_1700 - * @tc.name : WantAgentHelper GetWantAgent - * @tc.desc : 1.GetWantAgent context is not nullptr - * 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez() - * 3.FlagsTransformer return ok - * 4.Type is 100 - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_1700, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr context = OHOS::AbilityRuntime::Context::GetApplicationContext(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.operationType_ = static_cast(100); - wantAgentInfo.requestCode_ = 10; - auto wantAgent = wantAgentHelper->GetWantAgent(context, wantAgentInfo); - EXPECT_EQ(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_1800 - * @tc.name : WantAgentHelper GetWantAgent(const WantAgentInfo ¶msInfo) - * @tc.desc : 1.wantAgentInfo.wants_.siez() == 0 - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_1800, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.clear(); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.operationType_ = static_cast(100); - wantAgentInfo.requestCode_ = 10; - auto wantAgent = wantAgentHelper->GetWantAgent(wantAgentInfo); - EXPECT_EQ(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_1900 - * @tc.name : WantAgentHelper GetWantAgent(const WantAgentInfo ¶msInfo) - * @tc.desc : 1.wantAgentInfo.wants_ not empty - * 2.wantAgentInfo.wants_.siez() != wantAgentInfo.flags_.siez() - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_1900, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.clear(); - wantAgentInfo.operationType_ = static_cast(100); - wantAgentInfo.requestCode_ = 10; - auto wantAgent = wantAgentHelper->GetWantAgent(wantAgentInfo); - EXPECT_EQ(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_2000 - * @tc.name : WantAgentHelper GetWantAgent(const WantAgentInfo ¶msInfo) - * @tc.desc : 1.wantAgentInfo.wants_ not empty - * 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez() - * 3.wantAgentInfo.wants_[0] is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_2000, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.emplace_back(nullptr); - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.operationType_ = static_cast(100); - wantAgentInfo.requestCode_ = 10; - auto wantAgent = wantAgentHelper->GetWantAgent(wantAgentInfo); - EXPECT_EQ(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_2100 - * @tc.name : WantAgentHelper GetWantAgent(const WantAgentInfo ¶msInfo) - * @tc.desc : 1.wantAgentInfo.wants_ not empty - * 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez() - * 3.wantAgentInfo.wants_[0] is not nullptr - * 4.wantAgentInfo.extraInfo_ is not nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_2100, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.operationType_ = static_cast(100); - wantAgentInfo.requestCode_ = 10; - bool value = true; - std::string key = "key"; - std::shared_ptr wParams = std::make_shared(); - wParams->SetParam(key, Boolean::Box(value)); - wantAgentInfo.extraInfo_ = wParams; - auto wantAgent = wantAgentHelper->GetWantAgent(wantAgentInfo); - EXPECT_EQ(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_2200 - * @tc.name : WantAgentHelper GetWantAgent(const WantAgentInfo ¶msInfo) - * @tc.desc : 1.wantAgentInfo.wants_ not empty - * 2.wantAgentInfo.wants_.siez() == wantAgentInfo.flags_.siez() - * 3.wantAgentInfo.wants_[0] is not nullptr - * 4.wantAgentInfo.extraInfo_ is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_2200, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - WantAgentInfo wantAgentInfo; - wantAgentInfo.wants_.emplace_back(want); - wantAgentInfo.flags_.emplace_back(WantAgentConstant::Flags::CONSTANT_FLAG); - wantAgentInfo.operationType_ = static_cast(100); - wantAgentInfo.requestCode_ = 10; - wantAgentInfo.extraInfo_ = nullptr; - auto wantAgent = wantAgentHelper->GetWantAgent(wantAgentInfo); - EXPECT_EQ(wantAgent, nullptr); -} - -/* - * @tc.number : WantAgentHelper_2300 - * @tc.name : WantAgentHelper GetType - * @tc.desc : 1.agent is not nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_2300, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - WantAgentInfo wantAgentInfo; - auto wantAgent = wantAgentHelper->GetWantAgent(nullptr, wantAgentInfo); - auto type = wantAgentHelper->GetType(wantAgent); - EXPECT_EQ(type, WantAgentConstant::OperationType::UNKNOWN_TYPE); -} - -/* - * @tc.number : WantAgentHelper_2400 - * @tc.name : WantAgentHelper GetType - * @tc.desc : 1.agent is not nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_2400, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr wantAgent(nullptr); - auto type = wantAgentHelper->GetType(wantAgent); - EXPECT_EQ(type, WantAgentConstant::OperationType::UNKNOWN_TYPE); -} - -/* - * @tc.number : WantAgentHelper_2500 - * @tc.name : WantAgentHelper GetType - * @tc.desc : 1.agent is not nullptr,PendingWant is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_2500, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr pendingWant(nullptr); - std::shared_ptr wantAgent = std::make_shared(pendingWant); - auto type = wantAgentHelper->GetType(wantAgent); - EXPECT_EQ(type, WantAgentConstant::OperationType::UNKNOWN_TYPE); -} - -/* - * @tc.number : WantAgentHelper_2600 - * @tc.name : WantAgentHelper JudgeEquality - * @tc.desc : 1.JudgeEquality - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_2600, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr wantAgent(nullptr); - std::shared_ptr wantAgent2(nullptr); - auto isEqual = wantAgentHelper->JudgeEquality(wantAgent, wantAgent2); - EXPECT_EQ(isEqual, true); -} - -/* - * @tc.number : WantAgentHelper_2700 - * @tc.name : WantAgentHelper JudgeEquality - * @tc.desc : 1.JudgeEquality,Judge whether it is equal or not - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_2700, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - sptr target(new (std::nothrow) WantSender()); - std::shared_ptr pendingWant = std::make_shared(target); - std::shared_ptr wantAgent = std::make_shared(pendingWant); - std::shared_ptr wantAgent2(nullptr); - auto isEqual = wantAgentHelper->JudgeEquality(wantAgent, wantAgent2); - EXPECT_EQ(isEqual, false); -} - -/* - * @tc.number : WantAgentHelper_2800 - * @tc.name : WantAgentHelper JudgeEquality - * @tc.desc : 1.JudgeEquality,Judge whether it is equal or not - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_2800, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - sptr target(new (std::nothrow) WantSender()); - std::shared_ptr pendingWant = std::make_shared(target); - std::shared_ptr wantAgent = std::make_shared(pendingWant); - std::shared_ptr wantAgent2 = std::make_shared(pendingWant); - auto isEqual = wantAgentHelper->JudgeEquality(wantAgent, wantAgent2); - EXPECT_EQ(isEqual, true); -} - -/* - * @tc.number : WantAgentHelper_2900 - * @tc.name : WantAgentHelper JudgeEquality - * @tc.desc : 1.JudgeEquality,Judge whether it is equal or not - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_2900, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - sptr target(new (std::nothrow) WantSender()); - std::shared_ptr pendingWant = std::make_shared(target); - std::shared_ptr pendingWant2(nullptr); - std::shared_ptr wantAgent = std::make_shared(pendingWant); - std::shared_ptr wantAgent2 = std::make_shared(pendingWant2); - auto isEqual = wantAgentHelper->JudgeEquality(wantAgent, wantAgent2); - EXPECT_EQ(isEqual, false); -} - -/* - * @tc.number : WantAgentHelper_3000 - * @tc.name : WantAgentHelper GetHashCode - * @tc.desc : 1.GetHashCode WantAgent is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_3000, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr wantAgent(nullptr); - auto hashCode = wantAgentHelper->GetHashCode(wantAgent); - EXPECT_EQ(hashCode, 0); -} - -/* - * @tc.number : WantAgentHelper_3100 - * @tc.name : WantAgentHelper GetHashCode - * @tc.desc : 1.GetHashCode WantAgent.PendingWant.target is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_3100, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr pendingWant(nullptr); - std::shared_ptr wantAgent = std::make_shared(pendingWant); - auto hashCode = wantAgentHelper->GetHashCode(wantAgent); - EXPECT_EQ(hashCode, 0); -} - -/* - * @tc.number : WantAgentHelper_3200 - * @tc.name : WantAgentHelper GetBundleName - * @tc.desc : 1.GetBundleName WantAgent is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_3200, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr wantAgent(nullptr); - auto bundleName = wantAgentHelper->GetBundleName(wantAgent); - EXPECT_EQ(bundleName, ""); -} - -/* - * @tc.number : WantAgentHelper_3300 - * @tc.name : WantAgentHelper GetBundleName - * @tc.desc : 1.GetBundleName WantAgent.PendingWant.target is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_3300, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr pendingWant(nullptr); - std::shared_ptr wantAgent = std::make_shared(pendingWant); - auto bundleName = wantAgentHelper->GetBundleName(wantAgent); - EXPECT_EQ(bundleName, ""); -} - -/* - * @tc.number : WantAgentHelper_3400 - * @tc.name : WantAgentHelper GetUid - * @tc.desc : 1.GetUid WantAgent is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_3400, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr wantAgent(nullptr); - auto uid = wantAgentHelper->GetUid(wantAgent); - EXPECT_EQ(uid, -1); -} - -/* - * @tc.number : WantAgentHelper_3500 - * @tc.name : WantAgentHelper GetUid - * @tc.desc : 1.GetUid WantAgent.PendingWant.target is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_3500, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr pendingWant(nullptr); - std::shared_ptr wantAgent = std::make_shared(pendingWant); - auto uid = wantAgentHelper->GetUid(wantAgent); - EXPECT_EQ(uid, -1); -} - -/* - * @tc.number : WantAgentHelper_3600 - * @tc.name : WantAgentHelper GetWant - * @tc.desc : 1.GetWant WantAgent is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_3600, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr wantAgent(nullptr); - auto want = wantAgentHelper->GetWant(wantAgent); - EXPECT_EQ(want, nullptr); -} - -/* - * @tc.number : WantAgentHelper_3700 - * @tc.name : WantAgentHelper GetWant - * @tc.desc : 1.GetWant WantAgent.PendingWant.target is nullptr - */ -HWTEST_F(WantAgentHelperTest, WantAgentHelper_3700, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgentHelper = std::make_shared(); - std::shared_ptr pendingWant(nullptr); - std::shared_ptr wantAgent = std::make_shared(pendingWant); - auto want = wantAgentHelper->GetWant(wantAgent); - EXPECT_EQ(want, nullptr); -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn deleted file mode 100644 index eb5f2d7fa..000000000 --- a/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn +++ /dev/null @@ -1,60 +0,0 @@ -# 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. - -import("//base/notification/ans_standard/notification.gni") -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = "ans_standard/wantagent" - -ohos_unittest("want_agent_info_test") { - module_out_path = module_output_path - include_dirs = [ "//foundation/aafwk/standard/services/abilitymgr/include" ] - - sources = [ "want_agent_info_test.cpp" ] - - configs = [ "//utils/native/base:utils_config" ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - deps = [ - "${core_path}:ans_core", - "${frameworks_path}/wantagent:wantagent_innerkits", - "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", - "//foundation/aafwk/standard/services/abilitymgr:abilityms", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "ces_standard:cesfwk_core", - "dmsfwk_standard:zuri", - "eventhandler:libeventhandler", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "samgr_standard:samgr_proxy", - ] -} - -group("unittest") { - testonly = true - deps = [ ":want_agent_info_test" ] -} diff --git a/frameworks/wantagent/test/unittest/want_agent_info_test/want_agent_info_test.cpp b/frameworks/wantagent/test/unittest/want_agent_info_test/want_agent_info_test.cpp deleted file mode 100644 index f72436766..000000000 --- a/frameworks/wantagent/test/unittest/want_agent_info_test/want_agent_info_test.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/* - * 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. - */ - -#include -#include "ability_context.h" -#include "completed_callback.h" -#include "context_container.h" -#include "element_name.h" -#include "event_handler.h" -#include "ohos/aafwk/base/base_types.h" -#include "pending_want.h" -#include "want.h" -#include "want_agent.h" -#include "want_agent_constant.h" -#include "want_agent_helper.h" -#define private public -#define protected public -#include "want_agent_info.h" -#undef private -#undef protected -#include "want_params.h" -#include "want_receiver_stub.h" -#include "want_sender_stub.h" -#include "ohos/aafwk/base/bool_wrapper.h" - -using namespace testing::ext; -using namespace OHOS::AAFwk; -using namespace OHOS; -using OHOS::AppExecFwk::ElementName; -using namespace OHOS::AppExecFwk; -using vector_str = std::vector; - -namespace OHOS::Notification::WantAgent { -class WantAgentInfoTest : public testing::Test { -public: - WantAgentInfoTest() - {} - ~WantAgentInfoTest() - {} - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - class WantSender : public AAFwk::WantSenderStub { - public: - void Send(SenderInfo &senderInfo) override; - }; -}; - -void WantAgentInfoTest::WantSender::Send(SenderInfo &senderInfo) -{} - -void WantAgentInfoTest::SetUpTestCase(void) -{} - -void WantAgentInfoTest::TearDownTestCase(void) -{} - -void WantAgentInfoTest::SetUp(void) -{} - -void WantAgentInfoTest::TearDown(void) -{} - -/* - * @tc.number : WantAgentInfo_0100 - * @tc.name : WantAgentInfo Constructors - * @tc.desc : 1.Constructors - */ -HWTEST_F(WantAgentInfoTest, WantAgentInfo_0100, Function | MediumTest | Level1) -{ - int requestCode = 10; - WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::START_ABILITY; - WantAgentConstant::Flags flag = WantAgentConstant::Flags::CONSTANT_FLAG; - std::vector> wants; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - wants.emplace_back(want); - std::shared_ptr extraInfo = std::make_shared(); - bool value = true; - std::string key = "key"; - extraInfo->SetParam(key, Boolean::Box(value)); - std::shared_ptr wantAgentInfo = - std::make_shared(requestCode, operationType, flag, wants, extraInfo); - EXPECT_EQ(wantAgentInfo->GetRequestCode(), requestCode); - EXPECT_EQ(wantAgentInfo->GetOperationType(), operationType); - EXPECT_EQ(wantAgentInfo->GetFlags().at(0), flag); - EXPECT_NE(wantAgentInfo->GetWants().at(0), want); - EXPECT_EQ(wantAgentInfo->GetWants().at(0)->GetElement().GetBundleName(), want->GetElement().GetBundleName()); - EXPECT_EQ(wantAgentInfo->GetWants().at(0)->GetElement().GetAbilityName(), want->GetElement().GetAbilityName()); - EXPECT_NE(wantAgentInfo->GetExtraInfo(), extraInfo); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(wantAgentInfo->GetExtraInfo()->GetParam(key))), - Boolean::Unbox(IBoolean::Query(extraInfo->GetParam(key)))); -} - -/* - * @tc.number : WantAgentInfo_0200 - * @tc.name : WantAgentInfo Constructors - * @tc.desc : 1.Constructors - */ -HWTEST_F(WantAgentInfoTest, WantAgentInfo_0200, Function | MediumTest | Level1) -{ - int requestCode = 10; - WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::START_ABILITY; - std::vector flags; - WantAgentConstant::Flags flag = WantAgentConstant::Flags::CONSTANT_FLAG; - flags.emplace_back(flag); - std::vector> wants; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - wants.emplace_back(want); - std::shared_ptr extraInfo = std::make_shared(); - bool value = true; - std::string key = "key"; - extraInfo->SetParam(key, Boolean::Box(value)); - std::shared_ptr wantAgentInfo = - std::make_shared(requestCode, operationType, flags, wants, extraInfo); - EXPECT_EQ(wantAgentInfo->GetRequestCode(), requestCode); - EXPECT_EQ(wantAgentInfo->GetOperationType(), operationType); - EXPECT_EQ(wantAgentInfo->GetFlags().at(0), flag); - EXPECT_NE(wantAgentInfo->GetWants().at(0), want); - EXPECT_EQ(wantAgentInfo->GetWants().at(0)->GetElement().GetBundleName(), want->GetElement().GetBundleName()); - EXPECT_EQ(wantAgentInfo->GetWants().at(0)->GetElement().GetAbilityName(), want->GetElement().GetAbilityName()); - EXPECT_NE(wantAgentInfo->GetExtraInfo(), extraInfo); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(wantAgentInfo->GetExtraInfo()->GetParam(key))), - Boolean::Unbox(IBoolean::Query(extraInfo->GetParam(key)))); -} - -/* - * @tc.number : WantAgentInfo_0300 - * @tc.name : WantAgentInfo Constructors - * @tc.desc : 1.Copy Constructors - */ -HWTEST_F(WantAgentInfoTest, WantAgentInfo_0300, Function | MediumTest | Level1) -{ - int requestCode = 10; - WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::START_ABILITY; - std::vector flags; - WantAgentConstant::Flags flag = WantAgentConstant::Flags::CONSTANT_FLAG; - flags.emplace_back(flag); - std::vector> wants; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - wants.emplace_back(want); - std::shared_ptr extraInfo = std::make_shared(); - bool value = true; - std::string key = "key"; - extraInfo->SetParam(key, Boolean::Box(value)); - std::shared_ptr wantAgentInfo = - std::make_shared(requestCode, operationType, flags, wants, extraInfo); - EXPECT_EQ(wantAgentInfo->GetRequestCode(), requestCode); - EXPECT_EQ(wantAgentInfo->GetOperationType(), operationType); - EXPECT_EQ(wantAgentInfo->GetFlags().at(0), flag); - EXPECT_NE(wantAgentInfo->GetWants().at(0), want); - EXPECT_EQ(wantAgentInfo->GetWants().at(0)->GetElement().GetBundleName(), want->GetElement().GetBundleName()); - EXPECT_EQ(wantAgentInfo->GetWants().at(0)->GetElement().GetAbilityName(), want->GetElement().GetAbilityName()); - EXPECT_NE(wantAgentInfo->GetExtraInfo(), extraInfo); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(wantAgentInfo->GetExtraInfo()->GetParam(key))), - Boolean::Unbox(IBoolean::Query(extraInfo->GetParam(key)))); - - WantAgentInfo wantAgentInfo1(wantAgentInfo); - EXPECT_EQ(wantAgentInfo->GetRequestCode(), wantAgentInfo1.GetRequestCode()); - EXPECT_EQ(wantAgentInfo->GetOperationType(), wantAgentInfo1.GetOperationType()); - EXPECT_EQ(wantAgentInfo->GetFlags().at(0), wantAgentInfo1.GetFlags().at(0)); - EXPECT_NE(wantAgentInfo->GetWants().at(0), wantAgentInfo1.GetWants().at(0)); - EXPECT_EQ(wantAgentInfo->GetWants().at(0)->GetElement().GetBundleName(), - wantAgentInfo1.GetWants().at(0)->GetElement().GetBundleName()); - EXPECT_EQ(wantAgentInfo->GetWants().at(0)->GetElement().GetAbilityName(), - wantAgentInfo1.GetWants().at(0)->GetElement().GetAbilityName()); - EXPECT_NE(wantAgentInfo->GetExtraInfo(), wantAgentInfo1.GetExtraInfo()); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(wantAgentInfo->GetExtraInfo()->GetParam(key))), - Boolean::Unbox(IBoolean::Query(wantAgentInfo1.GetExtraInfo()->GetParam(key)))); -} - -/* - * @tc.number : WantAgentInfo_0400 - * @tc.name : WantAgentInfo GetRequestCode - * @tc.desc : 1.GetRequestCode - */ -HWTEST_F(WantAgentInfoTest, WantAgentInfo_0400, Function | MediumTest | Level1) -{ - int requestCode = 10; - WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::START_ABILITY; - std::vector flags; - WantAgentConstant::Flags flag = WantAgentConstant::Flags::CONSTANT_FLAG; - flags.emplace_back(flag); - std::vector> wants; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - wants.emplace_back(want); - std::shared_ptr extraInfo = std::make_shared(); - bool value = true; - std::string key = "key"; - extraInfo->SetParam(key, Boolean::Box(value)); - std::shared_ptr wantAgentInfo = - std::make_shared(requestCode, operationType, flags, wants, extraInfo); - EXPECT_EQ(wantAgentInfo->GetRequestCode(), requestCode); -} - -/* - * @tc.number : WantAgentInfo_0500 - * @tc.name : WantAgentInfo GetOperationType - * @tc.desc : 1.GetOperationType - */ -HWTEST_F(WantAgentInfoTest, WantAgentInfo_0500, Function | MediumTest | Level1) -{ - int requestCode = 10; - WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::START_ABILITY; - std::vector flags; - WantAgentConstant::Flags flag = WantAgentConstant::Flags::CONSTANT_FLAG; - flags.emplace_back(flag); - std::vector> wants; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - wants.emplace_back(want); - std::shared_ptr extraInfo = std::make_shared(); - bool value = true; - std::string key = "key"; - extraInfo->SetParam(key, Boolean::Box(value)); - std::shared_ptr wantAgentInfo = - std::make_shared(requestCode, operationType, flags, wants, extraInfo); - EXPECT_EQ(wantAgentInfo->GetOperationType(), operationType); -} - -/* - * @tc.number : WantAgentInfo_0600 - * @tc.name : WantAgentInfo GetFlags - * @tc.desc : 1.GetFlags - */ -HWTEST_F(WantAgentInfoTest, WantAgentInfo_0600, Function | MediumTest | Level1) -{ - int requestCode = 10; - WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::START_ABILITY; - std::vector flags; - WantAgentConstant::Flags flag = WantAgentConstant::Flags::CONSTANT_FLAG; - flags.emplace_back(flag); - std::vector> wants; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - wants.emplace_back(want); - std::shared_ptr extraInfo = std::make_shared(); - bool value = true; - std::string key = "key"; - extraInfo->SetParam(key, Boolean::Box(value)); - std::shared_ptr wantAgentInfo = - std::make_shared(requestCode, operationType, flags, wants, extraInfo); - EXPECT_EQ(wantAgentInfo->GetFlags().at(0), flag); -} - -/* - * @tc.number : WantAgentInfo_0700 - * @tc.name : WantAgentInfo GetWants - * @tc.desc : 1.GetWants - */ -HWTEST_F(WantAgentInfoTest, WantAgentInfo_0700, Function | MediumTest | Level1) -{ - int requestCode = 10; - WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::START_ABILITY; - std::vector flags; - WantAgentConstant::Flags flag = WantAgentConstant::Flags::CONSTANT_FLAG; - flags.emplace_back(flag); - std::vector> wants; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - wants.emplace_back(want); - std::shared_ptr extraInfo = std::make_shared(); - bool value = true; - std::string key = "key"; - extraInfo->SetParam(key, Boolean::Box(value)); - std::shared_ptr wantAgentInfo = - std::make_shared(requestCode, operationType, flags, wants, extraInfo); - EXPECT_EQ(wantAgentInfo->GetWants().at(0)->GetElement().GetBundleName(), want->GetElement().GetBundleName()); - EXPECT_EQ(wantAgentInfo->GetWants().at(0)->GetElement().GetAbilityName(), want->GetElement().GetAbilityName()); -} - -/* - * @tc.number : WantAgentInfo_0800 - * @tc.name : WantAgentInfo GetWants - * @tc.desc : 1.GetWants - */ -HWTEST_F(WantAgentInfoTest, WantAgentInfo_0800, Function | MediumTest | Level1) -{ - int requestCode = 10; - WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::START_ABILITY; - std::vector flags; - WantAgentConstant::Flags flag = WantAgentConstant::Flags::CONSTANT_FLAG; - flags.emplace_back(flag); - std::vector> wants; - std::shared_ptr want = std::make_shared(); - ElementName element("device", "bundleName", "abilityName"); - want->SetElement(element); - wants.emplace_back(want); - std::shared_ptr extraInfo = std::make_shared(); - bool value = true; - std::string key = "key"; - extraInfo->SetParam(key, Boolean::Box(value)); - std::shared_ptr wantAgentInfo = - std::make_shared(requestCode, operationType, flags, wants, extraInfo); - EXPECT_NE(wantAgentInfo->GetExtraInfo(), extraInfo); - EXPECT_EQ(Boolean::Unbox(IBoolean::Query(wantAgentInfo->GetExtraInfo()->GetParam(key))), - Boolean::Unbox(IBoolean::Query(extraInfo->GetParam(key)))); -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn deleted file mode 100644 index df5b130f1..000000000 --- a/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn +++ /dev/null @@ -1,60 +0,0 @@ -# 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. - -import("//base/notification/ans_standard/notification.gni") -import("//build/ohos.gni") -import("//build/test.gni") - -module_output_path = "ans_standard/wantagent" - -ohos_unittest("want_agent_test") { - module_out_path = module_output_path - include_dirs = [ "//foundation/aafwk/standard/services/abilitymgr/include" ] - - sources = [ "want_agent_test.cpp" ] - - configs = [ "//utils/native/base:utils_config" ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - deps = [ - "${core_path}:ans_core", - "${frameworks_path}/wantagent:wantagent_innerkits", - "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", - "//foundation/aafwk/standard/services/abilitymgr:abilityms", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "ces_standard:cesfwk_core", - "dmsfwk_standard:zuri", - "eventhandler:libeventhandler", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "samgr_standard:samgr_proxy", - ] -} - -group("unittest") { - testonly = true - deps = [ ":want_agent_test" ] -} diff --git a/frameworks/wantagent/test/unittest/want_agent_test/want_agent_test.cpp b/frameworks/wantagent/test/unittest/want_agent_test/want_agent_test.cpp deleted file mode 100644 index f8694df0e..000000000 --- a/frameworks/wantagent/test/unittest/want_agent_test/want_agent_test.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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. - */ - -#include -#include "ability_context.h" -#include "completed_callback.h" -#include "context_container.h" -#include "element_name.h" -#include "event_handler.h" -#include "ohos/aafwk/base/base_types.h" -#include "pending_want.h" -#include "want.h" -#define private public -#define protected public -#include "want_agent.h" -#undef private -#undef protected -#include "want_agent_constant.h" -#include "want_agent_helper.h" -#include "want_agent_info.h" -#include "want_params.h" -#include "want_receiver_stub.h" -#include "want_sender_stub.h" - -using namespace testing::ext; -using namespace OHOS::AAFwk; -using namespace OHOS; -using OHOS::AppExecFwk::ElementName; -using namespace OHOS::AppExecFwk; -using namespace OHOS::Notification::WantAgent; -using vector_str = std::vector; - -namespace OHOS::Notification::WantAgent { -class WantAgentTest : public testing::Test { -public: - WantAgentTest() - {} - ~WantAgentTest() - {} - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - class WantSender : public AAFwk::WantSenderStub { - public: - void Send(SenderInfo &senderInfo) override; - }; -}; - -void WantAgentTest::WantSender::Send(SenderInfo &senderInfo) -{} - -void WantAgentTest::SetUpTestCase(void) -{} - -void WantAgentTest::TearDownTestCase(void) -{} - -void WantAgentTest::SetUp(void) -{} - -void WantAgentTest::TearDown(void) -{} - -/* - * @tc.number : WantAgent_0100 - * @tc.name : WantAgentInfo Constructors - * @tc.desc : 1.Constructors and GetPendingWant - */ -HWTEST_F(WantAgentTest, WantAgent_0100, Function | MediumTest | Level1) -{ - std::shared_ptr wantAgent = std::make_shared(nullptr); - EXPECT_EQ(wantAgent->GetPendingWant(), nullptr); -} - -/* - * @tc.number : WantAgent_0200 - * @tc.name : WantAgentInfo Constructors - * @tc.desc : 1.Constructors and GetPendingWant - */ -HWTEST_F(WantAgentTest, WantAgent_0200, Function | MediumTest | Level1) -{ - sptr target(new (std::nothrow) WantSender()); - std::shared_ptr pendingWant = std::make_shared(target); - std::shared_ptr wantAgent = std::make_shared(pendingWant); - EXPECT_EQ(wantAgent->GetPendingWant(), pendingWant); -} -} // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/interfaces/BUILD.gn b/interfaces/BUILD.gn index d5d17329a..3fb13765a 100644 --- a/interfaces/BUILD.gn +++ b/interfaces/BUILD.gn @@ -15,6 +15,5 @@ group("interfaces_target") { deps = [ "kits/napi/ans:notification", "kits/napi/ans/src/reminder:reminderagent", - "kits/napi/wantagent:wantagent", ] } diff --git a/interfaces/innerkits/ans/native/include/notification_action_button.h b/interfaces/innerkits/ans/native/include/notification_action_button.h index 197922395..48dfe2a23 100644 --- a/interfaces/innerkits/ans/native/include/notification_action_button.h +++ b/interfaces/innerkits/ans/native/include/notification_action_button.h @@ -44,7 +44,7 @@ public: * isContextual is true but icon or wantAgent is empty. */ static std::shared_ptr Create(const std::shared_ptr &icon, - const std::string &title, const std::shared_ptr &wantAgent, + const std::string &title, const std::shared_ptr &wantAgent, const std::shared_ptr &extras = {}, NotificationConstant::SemanticActionButton semanticActionButton = NotificationConstant::SemanticActionButton::NONE_ACTION_BUTTON, @@ -82,7 +82,7 @@ public: * Obtains the WantAgent of this NotificationActionButton. * @return the WantAgent of this NotificationActionButton. */ - const std::shared_ptr GetWantAgent() const; + const std::shared_ptr GetWantAgent() const; /** * Adds additional data to this NotificationActionButton. @@ -218,7 +218,8 @@ private: * @param isContextual Indicates whether this NotificationActionButton is a contextual action. */ NotificationActionButton(const std::shared_ptr &icon, const std::string &title, - const std::shared_ptr &wantAgent, const std::shared_ptr &extras, + const std::shared_ptr &wantAgent, + const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, const std::vector> &userInputs, bool isContextual); @@ -232,7 +233,7 @@ private: private: std::shared_ptr icon_ {}; std::string title_ {}; - std::shared_ptr wantAgent_ {}; + std::shared_ptr wantAgent_ {}; std::shared_ptr extras_ {}; NotificationConstant::SemanticActionButton semanticActionButton_ { NotificationConstant::SemanticActionButton::NONE_ACTION_BUTTON diff --git a/interfaces/innerkits/ans/native/include/notification_request.h b/interfaces/innerkits/ans/native/include/notification_request.h index 117d918cb..85de466d8 100644 --- a/interfaces/innerkits/ans/native/include/notification_request.h +++ b/interfaces/innerkits/ans/native/include/notification_request.h @@ -226,25 +226,25 @@ public: * @param wantAgent Indicates the operation triggered by tapping the notification, which can be set by * WantAgent. */ - void SetWantAgent(const std::shared_ptr &wantAgent); + void SetWantAgent(const std::shared_ptr &wantAgent); /** * Obtains the WantAgent contained in this notification. * @return the WantAgent contained in this notification. */ - const std::shared_ptr GetWantAgent() const; + const std::shared_ptr GetWantAgent() const; /** * Sets an WantAgent object that is triggered when the user explicitly removes this notification. * @param wantAgent Indicates the WantAgent object to be triggered. */ - void SetRemovalWantAgent(const std::shared_ptr &wantAgent); + void SetRemovalWantAgent(const std::shared_ptr &wantAgent); /** * Obtains the WantAgent object that is triggered when the user explicitly removes this notification. * @return the WantAgent object to be triggered. */ - const std::shared_ptr GetRemovalWantAgent() const; + const std::shared_ptr GetRemovalWantAgent() const; /** * Sets the WantAgent to start when the device is not in use, @@ -255,13 +255,13 @@ public: * @param wantAgent Indicates the WantAgent object containing information about the to-be-started ability that * uses the Page template. */ - void SetMaxScreenWantAgent(const std::shared_ptr &wantAgent); + void SetMaxScreenWantAgent(const std::shared_ptr &wantAgent); /** * Obtains the full-screen WantAgent set by calling setMaxScreenWantAgent(WantAgent). * @return the full-screen WantAgent. */ - const std::shared_ptr GetMaxScreenWantAgent() const; + const std::shared_ptr GetMaxScreenWantAgent() const; /** * Sets extra parameters that are stored as key-value pairs for the notification. @@ -1031,9 +1031,9 @@ private: bool onlyLocal_ {false}; bool permitted_ {true}; - std::shared_ptr wantAgent_ {}; - std::shared_ptr removalWantAgent_ {}; - std::shared_ptr maxScreenWantAgent_ {}; + std::shared_ptr wantAgent_ {}; + std::shared_ptr removalWantAgent_ {}; + std::shared_ptr maxScreenWantAgent_ {}; std::shared_ptr additionalParams_ {}; std::shared_ptr littleIcon_ {}; std::shared_ptr bigIcon_ {}; diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index 3f6fa49e3..8e320cda6 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -576,7 +576,7 @@ protected: private: void AddActionButtons(const bool includeSnooze); void AddRemovalWantAgent(); - std::shared_ptr CreateWantAgent(AppExecFwk::ElementName &element) const; + std::shared_ptr CreateWantAgent(AppExecFwk::ElementName &element) const; uint64_t GetNowInstantMilli() const; std::string GetShowTime(const uint64_t showTime) const; std::string GetTimeInfoInner(const time_t &timeInSecond, const TimeFormat &format) const; diff --git a/interfaces/innerkits/wantagent/include/cancel_listener.h b/interfaces/innerkits/wantagent/include/cancel_listener.h deleted file mode 100644 index cb3a24495..000000000 --- a/interfaces/innerkits/wantagent/include/cancel_listener.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_CANCEL_LISTENER_H -#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_CANCEL_LISTENER_H - -namespace OHOS::Notification::WantAgent { -class CancelListener { -public: - /** - * Called when a Cancel operation as completed. - * - * @param resultCode The final result code determined by the Send. - */ - virtual void OnCancelled(int resultCode) = 0; - virtual ~CancelListener() = default; -}; -} // namespace OHOS::Notification::WantAgent -#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_CANCEL_LISTENER_H \ No newline at end of file diff --git a/interfaces/innerkits/wantagent/include/completed_callback.h b/interfaces/innerkits/wantagent/include/completed_callback.h deleted file mode 100644 index 5657c86b4..000000000 --- a/interfaces/innerkits/wantagent/include/completed_callback.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_CALLBACK_H -#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_CALLBACK_H - -#include -#include -#include "want.h" -#include "want_params.h" - -namespace OHOS::Notification::WantAgent { -class CompletedCallback { -public: - virtual ~CompletedCallback() = default; - /** - * Called when a Send operation as completed. - * - * @param want The original Want that was sent. - * @param resultCode The final result code determined by the Send. - * @param resultData The final data collected by a broadcast. - * @param resultExtras The final extras collected by a broadcast. - */ - virtual void OnSendFinished(const AAFwk::Want &want, int resultCode, const std::string &resultData, - const AAFwk::WantParams &resultExtras) = 0; -}; -} // namespace OHOS::Notification::WantAgent -#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_CALLBACK_H \ No newline at end of file diff --git a/interfaces/innerkits/wantagent/include/completed_dispatcher.h b/interfaces/innerkits/wantagent/include/completed_dispatcher.h deleted file mode 100644 index 3b987c8fd..000000000 --- a/interfaces/innerkits/wantagent/include/completed_dispatcher.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_DISPATCHER_H -#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_DISPATCHER_H - -#include -#include -#include "completed_callback.h" -#include "event_handler.h" -#include "want.h" -#include "want_params.h" -#include "want_receiver_stub.h" - -namespace OHOS::Notification::WantAgent { -class PendingWant; -class CompletedDispatcher : public AAFwk::WantReceiverStub { -public: - CompletedDispatcher(const std::shared_ptr &pendingWant, - const std::shared_ptr &callback, const std::shared_ptr &handler); - virtual ~CompletedDispatcher() = default; - - void Send(const int32_t resultCode) override; - - void PerformReceive(const AAFwk::Want &want, int resultCode, const std::string &data, - const AAFwk::WantParams &extras, bool serialized, bool sticky, int sendingUser) override; - - void Run(); - -private: - const std::shared_ptr pendingWant_; - const std::shared_ptr callback_; - const std::shared_ptr handler_; - AAFwk::Want want_; - int resultCode_ = 0; - std::string resultData_; - AAFwk::WantParams resultExtras_; -}; -} // namespace OHOS::Notification::WantAgent -#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_DISPATCHER_H \ No newline at end of file diff --git a/interfaces/innerkits/wantagent/include/pending_want.h b/interfaces/innerkits/wantagent/include/pending_want.h deleted file mode 100644 index ece50a14e..000000000 --- a/interfaces/innerkits/wantagent/include/pending_want.h +++ /dev/null @@ -1,281 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_PENDING_WANT_H -#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_PENDING_WANT_H - -#include -#include -#include -#include -#include "cancel_listener.h" -#include "context/context.h" -#include "completed_dispatcher.h" -#include "event_handler.h" -#include "want.h" -#include "want_agent_constant.h" -#include "want_params.h" -#include "want_receiver_stub.h" -#include "want_sender_info.h" -#include "want_sender_stub.h" - -namespace OHOS::Notification::WantAgent { -class PendingWant final : public std::enable_shared_from_this, public Parcelable { -public: - PendingWant() {}; - PendingWant(const sptr &target); - PendingWant(const sptr &target, const sptr whitelistToken); - virtual ~PendingWant() = default; - - WantAgentConstant::OperationType GetType(const sptr &target); - - /** - * Retrieve a PendingWant that will start a new ability. - * - * @param context The Context in which this PendingWant should start - * the ability. - * @param requestCode Private request code for the sender - * @param want Want of the ability to be launched. - * @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE}, - * FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT. - * - * @return Returns an existing or new PendingWant matching the given - * parameters. May return null only if FLAG_NO_CREATE has been - * supplied. - */ - static std::shared_ptr GetAbility(const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, unsigned int flags); - - /** - * Retrieve a PendingWant that will start a new ability - * - * @param context The Context in which this PendingWant should start - * the ability. - * @param requestCode Private request code for the sender - * @param want Want of the ability to be launched. - * @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, - * FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT. - * @param options Additional options for how the ability should be started. - * May be null if there are no options. - * - * @return Returns an existing or new PendingWant matching the given - * parameters. May return null only if FLAG_NO_CREATE has been - * supplied. - */ - static std::shared_ptr GetAbility(const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, - unsigned int flags, const std::shared_ptr &options); - - /** - * Like GetAbility(Context, int, Want, int)}, but allows an - * array of Wants to be supplied. The last Want in the array is - * taken as the primary key for the PendingWant, like the single Want - * given to GetAbility(Context, int, Want, int). - * - * @param context The Context in which this PendingWant should start - * the ability. - * @param requestCode Private request code for the sender - * @param wants Array of Wants of the abilities to be launched. - * @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, - * FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT. - * - * @return Returns an existing or new PendingWant matching the given - * parameters. May return null only if FLAG_NO_CREATE has been - * supplied. - */ - static std::shared_ptr GetAbilities(const std::shared_ptr &context, - int requestCode, std::vector> &wants, unsigned int flags); - - /** - * Like GetAbility(Context, int, Want, int)}, but allows an - * array of Wants to be supplied. The last Want in the array is - * taken as the primary key for the PendingWant, like the single Want - * given to GetAbility(Context, int, Want, int). - * - * @param context The Context in which this PendingWant should start - * the ability. - * @param requestCode Private request code for the sender - * @param wants Array of Wants of the abilities to be launched. - * @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, - * FLAG_CANCEL_CURRENT} link #FLAG_UPDATE_CURRENT, - * FLAG_IMMUTABLE. - * - * @return Returns an existing or new PendingWant matching the given - * parameters. May return null only if FLAG_NO_CREATE has been - * supplied. - */ - static std::shared_ptr GetAbilities(const std::shared_ptr &context, - int requestCode, std::vector> &wants, unsigned int flags, - const std::shared_ptr &options); - - /** - * Retrieve a PendingWant that will perform a common event. - * - * @param context The Context in which this PendingWant should perform - * the common event. - * @param requestCode Private request code for the sender - * @param want The Want to be common event. - * @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, - * FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, - * FLAG_IMMUTABLE. - * - * @return Returns an existing or new PendingWant matching the given - * parameters. May return null only if FLAG_NO_CREATE has been - * supplied. - */ - static std::shared_ptr GetCommonEvent(const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, unsigned int flags); - - /** - * Note that current user will be interpreted at the time the - * common event is sent, not when the pending want is created. - */ - static std::shared_ptr GetCommonEventAsUser( - const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, unsigned int flags, int uid); - - /** - * Retrieve a PendingWant that will start a service. - * - * @param context The Context in which this PendingWant should start - * the service. - * @param requestCode Private request code for the sender - * @param want An Want describing the service to be started. - * @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, - * FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, - * FLAG_IMMUTABLE. - * - * @return Returns an existing or new PendingWant matching the given - * parameters. May return null only if FLAG_NO_CREATE has been - * supplied. - */ - static std::shared_ptr GetService( - const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, unsigned int flags); - - /** - * Retrieve a PendingWant that will start a foreground service. - * - * @param context The Context in which this PendingWant should start - * the service. - * @param requestCode Private request code for the sender - * @param want An Want describing the service to be started. - * @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, - * FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, - * FLAG_IMMUTABLE . - * - * @return Returns an existing or new PendingWant matching the given - * parameters. May return null only if FLAG_NO_CREATE has been - * supplied. - */ - static std::shared_ptr GetForegroundService( - const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, unsigned int flags); - - /** - * @description: Marshals a Want into a Parcel. - * Fields in the Want are marshalled separately. If any field fails to be marshalled, false is returned. - * @param parcel Indicates the Parcel object for marshalling. - * @return Returns true if the marshalling is successful; returns false otherwise. - */ - virtual bool Marshalling(Parcel &parcel) const; - - /** - * @description: Unmarshals a Want from a Parcel. - * Fields in the Want are unmarshalled separately. If any field fails to be unmarshalled, false is returned. - * @param parcel Indicates the Parcel object for unmarshalling. - * @return Returns true if the unmarshalling is successful; returns false otherwise. - */ - static PendingWant *Unmarshalling(Parcel &parcel); - - static bool Equals( - const std::shared_ptr &targetPendingWant, const std::shared_ptr &otherPendingWant); - - void Cancel(const sptr &target); - - void Send(const sptr &target); - - void Send(int resultCode, const sptr &target); - - void Send(int resultCode, - const std::shared_ptr &want, const sptr &target); - - void Send(int resultCode, const sptr &onCompleted, const sptr &target); - - void Send(int resultCode, - const std::shared_ptr &want, const sptr &onCompleted, - const sptr &target); - - void Send(int resultCode, - const std::shared_ptr &want, const sptr &onCompleted, - const std::string &requiredPermission, const sptr &target); - - void Send(int resultCode, const std::shared_ptr &want, - const sptr &onCompleted, const std::string &requiredPermission, - const std::shared_ptr &options, const sptr &target); - - int SendAndReturnResult(int resultCode, const std::shared_ptr &want, - const sptr &onCompleted, const std::string &requiredPermission, - const std::shared_ptr &options, const sptr &target); - - std::string GetBundleName(const sptr &target); - - int GetUid(const sptr &target); - - sptr GetTarget(); - - void SetTarget(const sptr &target); - - void RegisterCancelListener( - const std::shared_ptr &cancelListener, const sptr &target); - - void NotifyCancelListeners(int32_t resultCode); - - void UnregisterCancelListener( - const std::shared_ptr &cancelListener, const sptr &target); - - int GetHashCode(const sptr &target); - - std::shared_ptr GetWant(const sptr &target); - - std::shared_ptr GetWantSenderInfo(const sptr &target); - -private: - std::mutex lock_object; - sptr target_; - sptr cancelReceiver_; - sptr whitelistToken_; - std::vector> cancelListeners_; - - class CancelReceiver : public AAFwk::WantReceiverStub { - public: - explicit CancelReceiver(const std::weak_ptr &outerInstance); - virtual ~CancelReceiver() = default; - - void Send(const int32_t resultCode) override; - void PerformReceive(const AAFwk::Want &want, int resultCode, const std::string &data, - const AAFwk::WantParams &extras, bool serialized, bool sticky, int sendingUser) override; - - private: - std::weak_ptr outerInstance_; - }; - - static std::shared_ptr BuildServicePendingWant( - const std::shared_ptr &context, - int requestCode, const std::shared_ptr &want, unsigned int flags, - WantAgentConstant::OperationType serviceKind); -}; -} // namespace OHOS::Notification::WantAgent -#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_PENDING_WANT_H \ No newline at end of file diff --git a/interfaces/innerkits/wantagent/include/trigger_info.h b/interfaces/innerkits/wantagent/include/trigger_info.h deleted file mode 100644 index a41ba98ec..000000000 --- a/interfaces/innerkits/wantagent/include/trigger_info.h +++ /dev/null @@ -1,173 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_TRIGGER_INFO_H -#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_TRIGGER_INFO_H - -#include -#include -#include "want.h" -#include "want_params.h" - -namespace OHOS::Notification::WantAgent { -class TriggerInfo final : public std::enable_shared_from_this { -public: - /** - * Default constructor used to create a {@code TriggerInfo} instance. - * - */ - TriggerInfo(); - virtual ~TriggerInfo() = default; - - /** - * A constructor used to create a {@code TriggerInfo} instance based on the input parameters. - * - * @param permission Indicates the permission required for an {@link WantAgent} recipient. - * This parameter is valid only when the {@link WantAgent} is triggered to send common events. - * @param extraInfo Indicates the custom extra data you want to add for triggering an {@link WantAgent}. - * @param want Indicates the extra {@link ohos.aafwk.content.Want}. - * If {@code flags} in {@link WantAgentInfo} contains {@link WantAgentConstant.Flags#CONSTANT_FLAG}, - * this parameter is invalid. If flags contains {@link WantAgentConstant.Flags#REPLACE_ELEMENT}, - * {@link WantAgentConstant.Flags#REPLACE_ACTION}, {@link WantAgentConstant.Flags#REPLACE_URI}, - * {@link WantAgentConstant.Flags#REPLACE_ENTITIES}, and {@link WantAgentConstant.Flags#REPLACE_BUNDLE}, - * the {@code element}, {@code action}, {@code uri}, {@code entities}, and {@code bundleName} attributes of the - * {@link ohos.aafwk.content.Want} specified in this parameter will be used to replace the - * corresponding attributes in the original {@link ohos.aafwk.content.Want}, respectively. - * If this parameter is null, the original {@link ohos.aafwk.content.Want} remains unchanged. - * @param code Indicates the result code provided for the target of the {@link WantAgent}. - */ - TriggerInfo(const std::string &permission, const std::shared_ptr &extraInfo, - const std::shared_ptr &want, int resultCode); - - /** - * A constructor used to create a {@code TriggerInfo} instance by copying parameters from an existing one. - * - * @param paramInfo Indicates the existing {@code TriggerInfo} object. - */ - explicit TriggerInfo(const TriggerInfo ¶mInfo); - - /** - * A copy assignment operator used to create a {@code TriggerInfo} instance by copying parameters from an existing - * one. - * - * @param paramInfo Indicates the existing {@code TriggerInfo} object. - */ - const TriggerInfo &operator=(const TriggerInfo ¶mInfo); - - /** - * Obtains the permission from the current {@code TriggerInfo} object. - * - * @return Returns the permission name. - */ - std::string GetPermission() const; - - /** - * Obtains the extra data from the {@code TriggerInfo} object. - * - * @return Returns the extra data. - */ - std::shared_ptr GetExtraInfo() const; - - /** - * Obtains the {@link ohos.aafwk.content.Want} used for triggering an {@link WantAgent}. - * - * @return Returns an {@link ohos.aafwk.content.Want} object. - */ - std::shared_ptr GetWant() const; - - /** - * Obtains the result code provided for the target of the {@link WantAgent}. - * - * @return Returns the result code provided for the target of the {@link WantAgent}. - */ - int GetResultCode() const; - - /** - * A builder class for {@link TriggerInfo} objects. - * - */ -public: - class Builder final : public std::enable_shared_from_this { - public: - /** - * Default constructor used to create a {@code Builder} instance. - * - */ - Builder(); - virtual ~Builder() = default; - - /** - * Sets the permission that the {@link WantAgent} recipient must have. - * - * @param permission Indicates the permission to set. This parameter is valid only when the {@link WantAgent} - * to trigger is intended to send a common event. - * @return Returns this {@code Builder} object with the specified permission. - */ - std::shared_ptr SetPermission(const std::string &permission); - - /** - * Sets custom data. - * - * @param params Indicates the custom data to set. - * @return Returns this {@code Builder} object with the custom data. - */ - std::shared_ptr SetWantParams(const std::shared_ptr ¶ms); - - /** - * Sets a custom {@link ohos.aafwk.content.Want}. - * - * @param want Indicates the custom {@code Want} to set. If the member variable {@code flags} of the - * {@link WantAgentInfo} contains {@link WantAgentConstant.Flags#CONSTANT_FLAG}, this parameter does not - * take effect. If {@code flags} contains {@link WantAgentConstant.Flags#REPLACE_ELEMENT}, - * {@link WantAgentConstant.Flags#REPLACE_ACTION}, {@link WantAgentConstant.Flags#REPLACE_URI}, - * {@link WantAgentConstant.Flags#REPLACE_ENTITIES}, and {@link WantAgentConstant.Flags#REPLACE_BUNDLE}, - * the {@code element}, {@code action}, {@code uri}, {@code entities}, and {@code bundleName} attributes of the - * {@link ohos.aafwk.content.Want} specified in this parameter will be used to replace the corresponding - * attributes in the original {@link ohos.aafwk.content.Want}, respectively. If this parameter is null, the - * original {@link ohos.aafwk.content.Want} remains unchanged. - * @return Returns this {@code Builder} object with the custom {@code Want}. - */ - std::shared_ptr SetWant(const std::shared_ptr &want); - - /** - * Sets the result code provided for the target of the {@link WantAgent}. - * - * @param code Indicates the result code provided for the target of the {@link WantAgent}. - * @return Returns this {@code Builder} object with the specified result code. - */ - std::shared_ptr SetResultCode(int resultCode); - - /** - * Creates a {@link TriggerInfo} object using all of the settings. - * - * @return Returns the created {@code TriggerInfo} object. - */ - std::shared_ptr Build(); - - private: - std::string permission_; - std::shared_ptr params_; - std::shared_ptr want_; - int resultCode_ = 0; - }; - -private: - std::string permission_; - std::shared_ptr extraInfo_; - std::shared_ptr want_; - int resultCode_ = 0; -}; -} // namespace OHOS::Notification::WantAgent -#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_TRIGGER_INFO_H \ No newline at end of file diff --git a/interfaces/innerkits/wantagent/include/want_agent.h b/interfaces/innerkits/wantagent/include/want_agent.h deleted file mode 100644 index 3af5ac876..000000000 --- a/interfaces/innerkits/wantagent/include/want_agent.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_H -#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_H - -#include -#include -#include "parcel.h" -#include "pending_want.h" -#include "want.h" -#include "want_params.h" - -namespace OHOS::Notification::WantAgent { -class WantAgent final : public std::enable_shared_from_this, public Parcelable { -public: - WantAgent() {}; - virtual ~WantAgent() = default; - /** - * Constructor. - * - * @param obj The proxy object. - */ - explicit WantAgent(const std::shared_ptr &pendingWant); - - /** - * Gets proxy obj. - * - * @return Return obj. - */ - std::shared_ptr GetPendingWant(); - - /** - * Sets proxy obj. - * - * @param obj The proxy object. - */ - void SetPendingWant(const std::shared_ptr &pendingWant); - - /** - * @description: Marshals a Want into a Parcel. - * Fields in the Want are marshalled separately. If any field fails to be marshalled, false is returned. - * @param parcel Indicates the Parcel object for marshalling. - * @return Returns true if the marshalling is successful; returns false otherwise. - */ - virtual bool Marshalling(Parcel &parcel) const; - - /** - * @description: Unmarshals a Want from a Parcel. - * Fields in the Want are unmarshalled separately. If any field fails to be unmarshalled, false is returned. - * @param parcel Indicates the Parcel object for unmarshalling. - * @return Returns true if the unmarshalling is successful; returns false otherwise. - */ - static WantAgent *Unmarshalling(Parcel &parcel); - -private: - std::shared_ptr pendingWant_; -}; -} // namespace OHOS::Notification::WantAgent -#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_H \ No newline at end of file diff --git a/interfaces/innerkits/wantagent/include/want_agent_constant.h b/interfaces/innerkits/wantagent/include/want_agent_constant.h deleted file mode 100644 index 4f611ffa5..000000000 --- a/interfaces/innerkits/wantagent/include/want_agent_constant.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_CONSTANT_H -#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_CONSTANT_H - -namespace OHOS::Notification::WantAgent { -/// -/// Provides enumerated constants that are used for setting object attributes in the methods provided by -/// . -/// -/// -class WantAgentConstant final { - /// - /// Enumerates flags for using an . - /// - /// -public: - enum class Flags { - /// - /// Indicates that the can be used only once. - /// - ONE_TIME_FLAG, - - /// - /// Indicates that {@code null} is returned if the does not exist. - /// - NO_BUILD_FLAG, - - /// - /// Indicates that the existing should be canceled before the new object is - /// generated. - /// - CANCEL_PRESENT_FLAG, - - /// - /// Indicates that the system only replaces the extra data of the existing - /// with that of the new object. - /// - UPDATE_PRESENT_FLAG, - - /// - /// Indicates that the created should be immutable. - /// - CONSTANT_FLAG, - - /// - /// Indicates that the current value of {@code element} can be replaced - /// when the is triggered. - /// - REPLACE_ELEMENT, - - /// - /// Indicates that the current value of {@code action} can be replaced - /// when the is triggered. - /// - REPLACE_ACTION, - - /// - /// Indicates that the current value of {@code uri} can be replaced when the is - /// triggered. - /// - REPLACE_URI, - - /// - /// Indicates that the current value of {@code entities} can be replaced - /// when the is triggered. - /// - REPLACE_ENTITIES, - - /// - /// Indicates that the current value of {@code bundleName} can be replaced - /// when the is triggered. - /// - REPLACE_BUNDLE - }; - - /// - /// Identifies the operation for using an , such as starting an ability or sending a - /// common event. - /// - /// -public: - enum class OperationType { - /// - /// Unknown operation. - /// - UNKNOWN_TYPE, - - /// - /// Starts an ability with a UI. - /// - START_ABILITY, - - /// - /// Starts multiple abilities. - /// - START_ABILITIES, - - /// - /// Starts an ability without a UI. - /// - START_SERVICE, - - /// - /// Sends a common event. - /// - SEND_COMMON_EVENT, - - /// - /// Starts a foreground ability without a UI. - /// - START_FOREGROUND_SERVICE - }; - -private: - WantAgentConstant() {}; - virtual ~WantAgentConstant() = default; -}; -} // namespace OHOS::Notification::WantAgent -#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_CONSTANT_H diff --git a/interfaces/innerkits/wantagent/include/want_agent_helper.h b/interfaces/innerkits/wantagent/include/want_agent_helper.h deleted file mode 100644 index a059e60b8..000000000 --- a/interfaces/innerkits/wantagent/include/want_agent_helper.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_HELPER_H -#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_HELPER_H - -#include -#include -#include "context/context.h" -#include "completed_callback.h" -#include "completed_dispatcher.h" -#include "event_handler.h" -#include "nlohmann/json.hpp" -#include "trigger_info.h" -#include "want.h" -#include "want_agent.h" -#include "want_agent_info.h" -#include "want_params.h" - -namespace OHOS::Notification::WantAgent { -/** - * A helper class used to obtain, trigger, cancel, and compare WantAgent objects and to obtain - * the bundle name, UID, and hash code value of an WantAgent object. - * - */ - -static const int FLAG_ONE_SHOT = 1 << 30; -static const int FLAG_NO_CREATE = 1 << 29; -static const int FLAG_CANCEL_CURRENT = 1 << 28; -static const int FLAG_UPDATE_CURRENT = 1 << 27; -static const int FLAG_IMMUTABLE = 1 << 26; -static const int INVLID_WANT_AGENT_USER_ID = -1; - -class WantAgentHelper final : public std::enable_shared_from_this { -public: - /** - * Obtains an WantAgent object. - * The WantAgent class does not have any constructor, and you can only use this method to create an - * WantAgent object. - * - * @param context Indicates the context of the caller. This parameter cannot be null. - * @param paramsInfo Indicates the WantAgentInfo object that contains parameters of the - * WantAgent object to create. - * @return Returns the created WantAgent object. - */ - static std::shared_ptr GetWantAgent( - const std::shared_ptr &context, const WantAgentInfo ¶msInfo); - - /** - * Obtains an WantAgent object. - * - * The WantAgent class does not have any constructor, and you can only use this method to create an - * WantAgent object. - * - * @param paramsInfo Indicates the WantAgentInfo object that contains parameters of the - * WantAgent object to create. - * @param userId Indicates the user id for this wantagent info, default is INVLID_WANT_AGENT_USER_ID(-1). - * @return Returns the created WantAgent object. - */ - static std::shared_ptr GetWantAgent(const WantAgentInfo ¶msInfo, - int32_t userId = INVLID_WANT_AGENT_USER_ID); - - /** - * Obtains an WantAgent object operation type. - * - * @param agent Indicates the WantAgent to trigger. - * @return Returns the created WantAgent object. - */ - static WantAgentConstant::OperationType GetType(const std::shared_ptr &agent); - - /** - * Triggers an WantAgent. - * - * After this method is called, events associated with the specified WantAgent will be executed, - * such as starting an ability or sending a common event. - * - * @param context Indicates the context of the caller. This parameter cannot be null. - * @param agent Indicates the WantAgent to trigger. - * @param onCompleted Indicates the callback method to be called after the WantAgent is triggered. - * This parameter can be null. - * @param handler Indicates the thread for executing the callback indicated by OnCompleted. - * If this parameter is null, the callback method will be executed in a thread in the thread pool of - * the current process. - * @param paramsInfo Indicates the TriggerInfo object that contains triggering parameters. - */ - static void TriggerWantAgent(const std::shared_ptr &agent, - const std::shared_ptr &callback, - const TriggerInfo ¶msInfo); - - /** - * Cancels an WantAgent. - * - * Only the application that creates the WantAgent can cancel it. - * - * @param agent Indicates the WantAgent to cancel. - */ - static void Cancel(const std::shared_ptr &agent); - - /** - * Checks whether two WantAgent objects are the same. - * - * @param agent Indicates one of the WantAgent object to compare. - * @param otherAgent Indicates the other WantAgent object to compare. - * @return Returns true If the two objects are the same; returns false otherwise. - */ - static bool JudgeEquality(const std::shared_ptr &agent, const std::shared_ptr &otherAgent); - - /** - * Obtains the hash code value of an WantAgent. - * - * @param agent Indicates the antAgent whose hash code value is to be obtained. - * @return Returns the hash code value of the WantAgent. - */ - static int GetHashCode(const std::shared_ptr &agent); - - /** - * Obtains the bundle name of an WantAgent. - * - * @param agent Indicates the WantAgent whose bundle name is to be obtained. - * @return Returns the bundle name of the WantAgent if any; returns {@code null} otherwise. - */ - static std::string GetBundleName(const std::shared_ptr &agent); - - /** - * Obtains the user ID (UID) of an WantAgent. - * - * @param agent Indicates the WantAgent whose UID is to be obtained. - * @return Returns the UID of the WantAgent if any; returns -1} otherwise. - */ - static int GetUid(const std::shared_ptr &agent); - - /** - * Obtains the Want WantAgent. - * - * @param agent Indicates the WantAgent whose Want is to be obtained. - * @return Returns the Want of the WantAgent. - */ - static std::shared_ptr GetWant(const std::shared_ptr &agent); - - /** - * Register Cancel function Listener. - * - * @param cancelListener Register listener object. - * @param agent Indicates the WantAgent whose bundle name is to be obtained. - */ - static void RegisterCancelListener( - const std::shared_ptr &cancelListener, const std::shared_ptr &agent); - - /** - * Unregister Cancel function Listener. - * - * @param cancelListener Register listener object. - * @param agent Indicates the WantAgent whose bundle name is to be obtained. - */ - static void UnregisterCancelListener( - const std::shared_ptr &cancelListener, const std::shared_ptr &agent); - - /** - * Convert WantAgentInfo object to json string. - * - * @param jsonObject Json object. - * @return WantAgentInfo object's json string. - */ - static std::string ToString(const std::shared_ptr &agent); - - /** - * Convert json string to WantAgentInfo object. - * - * @param jsonString Json string. - * @return WantAgentInfo object. - */ - static std::shared_ptr FromString(const std::string &jsonString); - -private: - WantAgentHelper(); - virtual ~WantAgentHelper() = default; - -private: - static void Send(const std::shared_ptr &pendingWant, - WantAgentConstant::OperationType type, - const sptr &callBack, - const TriggerInfo ¶msInfo); - - static unsigned int FlagsTransformer(const std::vector &flags); -}; -} // namespace OHOS::Notification::WantAgent -#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_HELPER_H \ No newline at end of file diff --git a/interfaces/innerkits/wantagent/include/want_agent_info.h b/interfaces/innerkits/wantagent/include/want_agent_info.h deleted file mode 100644 index 70315d122..000000000 --- a/interfaces/innerkits/wantagent/include/want_agent_info.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_INFO_H -#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_INFO_H - -#include -#include -#include "want.h" -#include "want_agent_constant.h" -#include "want_params.h" - -namespace OHOS::Notification::WantAgent { -/** - * A parametric class that contains the parameters required by WantAgentHelper GetWantAgent. - * - * This class is used to encapsulate parameters requestCode, operationType, - * flag, Wants, and extraInfo. It is used as the input parameter for - * the WantAgentHelper GetWantAgent method. - * - */ -class WantAgentInfo final : public std::enable_shared_from_this { -public: - /** - * Default constructor used to create an empty WantAgentInfo instance. - * - */ - WantAgentInfo(); - virtual ~WantAgentInfo() = default; - - /** - * A constructor used to create an WantAgentInfo instance based on the input parameters. - * - * @param requestCode Indicates the request code to set. It is a private value defined by the user. - * @param operationType Indicates the type of the operation to be performed by the WantAgent object. - * For details about the value range, see WantAgentConstant.OperationType. - * @param flag Indicates the flag for handling the WantAgent. - * For details about the value range, see WantAgentConstant.Flags. - * @param Wants Indicates the collection of Want objects to be used for creating the WantAgent - * object. The number of Wants in the collection is determined by WantAgentConstant.OperationType. - * @param extraInfo Indicates the extra information to be used for creating the WantAgent object. - */ - WantAgentInfo(int requestCode, const WantAgentConstant::OperationType &operationType, WantAgentConstant::Flags flag, - std::vector> &Wants, const std::shared_ptr &extraInfo); - - /** - * A constructor used to create an WantAgentInfo instance based on the input parameters. - * - * @param requestCode Indicates the request code to set. It is a private value defined by the user. - * @param operationType Indicates the type of the operation to be performed by the WantAgent object. - * For details about the value range, see WantAgentConstant.OperationType. - * @param flags Indicates the flags for handling the WantAgent. - * For details about the value range, see WantAgentConstant.Flags. - * @param Wants Indicates the collection of Want objects to be used for creating the WantAgent - * object. The number of Wants in the collection is determined by WantAgentConstant.OperationType. - * @param extraInfo Indicates the extra information to be used for creating the WantAgent object. - */ - WantAgentInfo(int requestCode, const WantAgentConstant::OperationType &operationType, - const std::vector &flags, std::vector> &Wants, - const std::shared_ptr &extraInfo); - - /** - * A constructor used to create an WantAgentInfo instance by copying parameters from an existing one. - * - * @param paramInfo Indicates the existing WantAgentInfo object. - */ - explicit WantAgentInfo(const std::shared_ptr ¶mInfo); - - /** - * Obtains the requestCode of the WantAgent object. - * - * @return Returns the requestCode of the WantAgent object. - */ - int GetRequestCode() const; - - /** - * Obtains the operationType of the WantAgent object. - * - * @return Returns the operationType of the WantAgent object. - */ - WantAgentConstant::OperationType GetOperationType() const; - - /** - * Obtains the flag of the WantAgent object. - * - * @return Returns the flag of the WantAgent object. - */ - std::vector GetFlags() const; - - /** - * Obtains the collection of all Wants of the WantAgent object. - * - * @return Returns the collection of all Wants of the WantAgent object. - */ - std::vector> GetWants() const; - - /** - * Obtains the extra information of the WantAgent object. - * - * @return Returns the extra information of the WantAgent object. - */ - std::shared_ptr GetExtraInfo() const; - -private: - int requestCode_ = 0; - WantAgentConstant::OperationType operationType_ = WantAgentConstant::OperationType::UNKNOWN_TYPE; - std::vector flags_ = std::vector(); - std::vector> wants_ = std::vector>(); - std::shared_ptr extraInfo_; -}; -} // namespace OHOS::Notification::WantAgent -#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_INFO_H \ No newline at end of file diff --git a/interfaces/innerkits/wantagent/include/want_agent_log_wrapper.h b/interfaces/innerkits/wantagent/include/want_agent_log_wrapper.h deleted file mode 100644 index 8c9c141a3..000000000 --- a/interfaces/innerkits/wantagent/include/want_agent_log_wrapper.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_LOG_WRAPPER_H -#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_LOG_WRAPPER_H - -#include -#include "hilog/log.h" - -namespace OHOS::Notification::WantAgent { -#ifndef WANT_AGENT_LOG_DOMAIN -#define WANT_AGENT_LOG_DOMAIN 0xD001000 -#endif -#ifndef WANT_AGENT_LOG_TAG -#define WANT_AGENT_LOG_TAG "WantAgent" -#endif - -enum class WantAgentLogLevel { DEBUG = 0, INFO, WARN, ERROR, FATAL }; - -static constexpr OHOS::HiviewDFX::HiLogLabel Want_Agent_LABEL = {LOG_CORE, WANT_AGENT_LOG_DOMAIN, WANT_AGENT_LOG_TAG}; - -class WantAgentLogWrapper { -public: - static bool JudgeLevel(const WantAgentLogLevel &level); - - static void SetLogLevel(const WantAgentLogLevel &level) - { - level_ = level; - } - - static const WantAgentLogLevel &GetLogLevel() - { - return level_; - } - - static std::string GetBriefFileName(const char *str); - -private: - static WantAgentLogLevel level_; -}; - -#define PRINT_LOG(LEVEL, Level, fmt, ...) \ - if (WantAgentLogWrapper::JudgeLevel(WantAgentLogLevel::LEVEL)) \ - OHOS::HiviewDFX::HiLog::Level(Want_Agent_LABEL, \ - "[%{public}s(%{public}s)] " fmt, \ - WantAgentLogWrapper::GetBriefFileName(__FILE__).c_str(), \ - __FUNCTION__, \ - ##__VA_ARGS__) - -#define WANT_AGENT_LOGD(fmt, ...) PRINT_LOG(DEBUG, Debug, fmt, ##__VA_ARGS__) -#define WANT_AGENT_LOGI(fmt, ...) PRINT_LOG(INFO, Info, fmt, ##__VA_ARGS__) -#define WANT_AGENT_LOGW(fmt, ...) PRINT_LOG(WARN, Warn, fmt, ##__VA_ARGS__) -#define WANT_AGENT_LOGE(fmt, ...) PRINT_LOG(ERROR, Error, fmt, ##__VA_ARGS__) -#define WANT_AGENT_LOGF(fmt, ...) PRINT_LOG(FATAL, Fatal, fmt, ##__VA_ARGS__) -} // namespace OHOS::Notification::WantAgent -#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_WANT_AGENT_LOG_WRAPPER_H diff --git a/interfaces/kits/js/@ohos.wantAgent.d.ts b/interfaces/kits/js/@ohos.wantAgent.d.ts deleted file mode 100644 index e5de044ce..000000000 --- a/interfaces/kits/js/@ohos.wantAgent.d.ts +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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. - */ - -import { AsyncCallback , Callback} from './basic'; -import { Want } from './ability/want'; -import { WantAgentInfo } from './wantAgent/wantAgentInfo'; -import { TriggerInfo } from './wantAgent/triggerInfo'; - -/** - * Provide the method obtain trigger, cancel, and compare and to obtain - * the bundle name, UID of an {@link WantAgent} object. - * - * @name wantAgent - * @since 7 - * @devices phone, tablet, tv, wearable, car - * @import import wantAgent from '@ohos.wantAgent'; - * @permission N/A - */ -declare namespace wantAgent { - /** - * Obtains the bundle name of a WantAgent. - * - * @param WantAgent whose bundle name to obtain. - * @return Returns the bundle name of the {@link WantAgent} if any. - */ - function getBundleName(agent: WantAgent, callback: AsyncCallback): void; - function getBundleName(agent: WantAgent): Promise; - - /** - * Obtains the UID of a WantAgent. - * - * @param WantAgent whose UID to obtain. - * @return Returns the UID of the {@link WantAgent} if any; returns {@code -1} otherwise. - */ - function getUid(agent: WantAgent, callback: AsyncCallback): void; - function getUid(agent: WantAgent): Promise; - - /** - * Obtains the {@link Want} of an {@link WantAgent}. - * - * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. - * @return Returns the {@link Want} of the {@link WantAgent}. - * @systemapi Hide this for inner system use. - */ - function getWant(agent: WantAgent, callback: AsyncCallback): void; - - /** - * Obtains the {@link Want} of an {@link WantAgent}. - * - * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. - * @return Returns the {@link Want} of the {@link WantAgent}. - * @systemapi Hide this for inner system use. - */ - function getWant(agent: WantAgent): Promise; - - /** - * Cancels a WantAgent. Only the application that creates the WantAgent can cancel it. - * - * @param WantAgent to cancel. - */ - function cancel(agent: WantAgent, callback: AsyncCallback): void; - function cancel(agent: WantAgent): Promise; - - /** - * Triggers a WantAgent. - * - * @param WantAgent to trigger. - * @param Trigger parameters. - * @param callback Indicates the callback method to be called after the {@link WantAgent} is triggered. - */ - function trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback): void; - - /** - * Checks whether two WantAgent objects are equal. - * - * @param WantAgent to compare. - * @param WantAgent to compare. - * @return Returns {@code true} If the two objects are the same; returns {@code false} otherwise. - */ - function equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback): void; - function equal(agent: WantAgent, otherAgent: WantAgent): Promise; - - /** - * Obtains a WantAgent object. - * - * @param Information about the WantAgent object to obtain. - * @return Returns the created {@link WantAgent} object. - */ - function getWantAgent(info: WantAgentInfo, callback: AsyncCallback): void; - function getWantAgent(info: WantAgentInfo): Promise; - - /** - * Enumerates flags for using a WantAgent. - */ - export enum WantAgentFlags { - /** - * Indicates that the WantAgent can be used only once. - * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. - */ - ONE_TIME_FLAG = 0, - - /** - * Indicates that null is returned if the WantAgent does not exist. - * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. - */ - NO_BUILD_FLAG, - - /** - * Indicates that the existing WantAgent should be canceled before a new object is generated. - * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. - */ - CANCEL_PRESENT_FLAG, - - /** - * Indicates that the system only replaces the extra data of the existing WantAgent with that of the new object. - * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. - */ - UPDATE_PRESENT_FLAG, - - /** - * Indicates that the created WantAgent should be immutable. - */ - CONSTANT_FLAG - } - - /** - * Identifies the operation for using a WantAgent, such as starting an ability or sending a common event. - */ - export enum OperationType { - /** - * Unknown operation. - */ - UNKNOWN_TYPE = 0, - - /** - * Starts an ability with a UI. - */ - START_ABILITY, - - /** - * Starts multiple abilities with a UI. - */ - START_ABILITIES, - - /** - * Starts an ability without a UI. - */ - START_SERVICE, - - /** - * Sends a common event. - */ - SEND_COMMON_EVENT - } - - /** - * Describes the data returned by after wantAgent.trigger is called. - */ - export interface CompleteData { - /** - * Triggered WantAgent. - */ - info: WantAgent; - - /** - * Existing Want that is triggered. - */ - want: Want; - - /** - * Request code used to trigger the WantAgent. - */ - finalCode: number; - - /** - * Final data collected by the common event. - */ - finalData: string; - - /** - * Extra data collected by the common event. - */ - extraInfo?: {[key: string]: any}; - } -} - -/** - * WantAgent object. - */ -export type WantAgent = object; - -export default wantAgent; \ No newline at end of file diff --git a/interfaces/kits/js/wantAgent/triggerInfo.d.ts b/interfaces/kits/js/wantAgent/triggerInfo.d.ts deleted file mode 100644 index 8cd951dce..000000000 --- a/interfaces/kits/js/wantAgent/triggerInfo.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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. - */ - -import { Want } from '../ability/want'; - -/** - * Provides the information required for triggering a WantAgent. - * - * @name TriggerInfo - * @since 7 - * @devices phone, tablet, tv, wearable, car - * @permission N/A - */ -export interface TriggerInfo { - /** - * Result code. - */ - code: number; - - /** - * Extra Want. - * If flags in WantAgentInfo contain CONSTANT_FLAG, this parameter is invalid. - * If flags contain REPLACE_ELEMENT, REPLACE_ACTION, REPLACE_URI, REPLACE_ENTITIES, and REPLACE_BUNDLE, - * the element, action, uri, entities, and bundleName attributes of the Want specified in this parameter - * will be used to replace the corresponding attributes in the original Want, respectively. - * If this parameter is null, the original Want remains unchanged. - */ - want?: Want; - - /** - * Permission required for a WantAgent recipient. - * This parameter is valid only when the WantAgent is triggered to send common events. - * If permission is null, no permission is required on the recipient. - */ - permission?: string; - - /** - * Custom extra data you want to add for triggering a WantAgent. - */ - extraInfo?: {[key: string]: any}; -} \ No newline at end of file diff --git a/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts b/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts deleted file mode 100644 index f33531d32..000000000 --- a/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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. - */ - -import { Want } from '../ability/want'; -import wantAgent from '../@ohos.wantAgent' - -/** - * Provides the information required for triggering a WantAgent. - * - * @name WantAgentInfo - * @since 7 - * @devices phone, tablet, tv, wearable, car - * @permission N/A - */ -export interface WantAgentInfo { - /** - * An array of all Wants for starting abilities or sending common events. Only Wants can be displayed. - */ - wants: Array; - - /** - * Type of the action specified in a Want. - */ - operationType: wantAgent.OperationType; - - /** - * Request code defined by the user. - */ - requestCode: number; - - /** - * An array of flags for using the WantAgent. - */ - wantAgentFlags?: Array; - - /** - * Extra information about how the Want starts an ability. - * If there is no extra information to set, this constant can be left empty. - */ - extraInfo?: {[key: string]: any}; -} \ No newline at end of file diff --git a/interfaces/kits/napi/ans/BUILD.gn b/interfaces/kits/napi/ans/BUILD.gn index b1bb7d055..74ee9b535 100644 --- a/interfaces/kits/napi/ans/BUILD.gn +++ b/interfaces/kits/napi/ans/BUILD.gn @@ -66,7 +66,6 @@ ohos_shared_library("notification") { deps = [ "${frameworks_path}/ans/core:ans_core", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", "//foundation/multimedia/image_standard/interfaces/innerkits:image", "//third_party/jsoncpp:jsoncpp", @@ -78,6 +77,7 @@ ohos_shared_library("notification") { "ability_base:base", "ability_base:want", "ability_runtime:abilitykit_native", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", diff --git a/interfaces/kits/napi/ans/include/common.h b/interfaces/kits/napi/ans/include/common.h index 8abe7e812..297cd4132 100644 --- a/interfaces/kits/napi/ans/include/common.h +++ b/interfaces/kits/napi/ans/include/common.h @@ -427,7 +427,8 @@ public: static bool SourceTypeCToJS(const NotificationConstant::SourceType &inType, SourceType &outType); - static napi_value CreateWantAgentByJS(const napi_env &env, const std::shared_ptr &agent); + static napi_value CreateWantAgentByJS(const napi_env &env, + const std::shared_ptr &agent); static napi_value GetNotificationTemplate( const napi_env &env, const napi_value &value, NotificationRequest &request); @@ -446,7 +447,7 @@ private: static const int ARGS_TWO = 2; static const int ONLY_CALLBACK_MAX_PARA = 1; static const int ONLY_CALLBACK_MIN_PARA = 0; - static std::set> wantAgent_; + static std::set> wantAgent_; }; } // namespace NotificationNapi } // namespace OHOS diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 541933a8d..3590331e9 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -19,7 +19,7 @@ namespace OHOS { namespace NotificationNapi { -std::set> Common::wantAgent_; +std::set> Common::wantAgent_; Common::Common() {} @@ -428,7 +428,7 @@ napi_value Common::SetNotificationRequestByWantAgent( return NapiGetBoolean(env, false); } // wantAgent?: WantAgent - std::shared_ptr agent = request->GetWantAgent(); + std::shared_ptr agent = request->GetWantAgent(); if (agent) { napi_value wantAgent = nullptr; wantAgent = CreateWantAgentByJS(env, agent); @@ -438,7 +438,7 @@ napi_value Common::SetNotificationRequestByWantAgent( } // removalWantAgent?: WantAgent - std::shared_ptr removalAgent = request->GetRemovalWantAgent(); + std::shared_ptr removalAgent = request->GetRemovalWantAgent(); if (removalAgent) { napi_value wantAgent = nullptr; wantAgent = CreateWantAgentByJS(env, removalAgent); @@ -448,7 +448,7 @@ napi_value Common::SetNotificationRequestByWantAgent( } // maxScreenWantAgent?: WantAgent - std::shared_ptr maxScreenAgent = request->GetMaxScreenWantAgent(); + std::shared_ptr maxScreenAgent = request->GetMaxScreenWantAgent(); if (maxScreenAgent) { napi_value wantAgent = nullptr; wantAgent = CreateWantAgentByJS(env, maxScreenAgent); @@ -1175,7 +1175,7 @@ napi_value Common::SetNotificationActionButton( napi_set_named_property(env, result, "title", value); // wantAgent: WantAgent - std::shared_ptr agent = actionButton->GetWantAgent(); + std::shared_ptr agent = actionButton->GetWantAgent(); if (agent == nullptr) { ANS_LOGI("wantAgent is null"); napi_set_named_property(env, result, "wantAgent", NapiGetNull(env)); @@ -1755,7 +1755,7 @@ napi_value Common::GetNotificationWantAgent(const napi_env &env, const napi_valu ANS_LOGI("enter"); bool hasProperty = false; - WantAgent::WantAgent *wantAgent = nullptr; + AbilityRuntime::WantAgent::WantAgent *wantAgent = nullptr; napi_value result = nullptr; napi_valuetype valuetype = napi_undefined; @@ -1769,7 +1769,8 @@ napi_value Common::GetNotificationWantAgent(const napi_env &env, const napi_valu ANS_LOGE("Invalid object wantAgent"); return nullptr; } - std::shared_ptr sWantAgent = std::make_shared(*wantAgent); + std::shared_ptr sWantAgent = + std::make_shared(*wantAgent); request.SetWantAgent(sWantAgent); } @@ -1829,7 +1830,7 @@ napi_value Common::GetNotificationRemovalWantAgent( ANS_LOGI("enter"); bool hasProperty = false; - WantAgent::WantAgent *wantAgent = nullptr; + AbilityRuntime::WantAgent::WantAgent *wantAgent = nullptr; napi_value result = nullptr; napi_valuetype valuetype = napi_undefined; @@ -1843,7 +1844,8 @@ napi_value Common::GetNotificationRemovalWantAgent( ANS_LOGE("Invalid object removalWantAgent"); return nullptr; } - std::shared_ptr removeWantAgent = std::make_shared(*wantAgent); + std::shared_ptr removeWantAgent = + std::make_shared(*wantAgent); request.SetRemovalWantAgent(removeWantAgent); } @@ -1856,7 +1858,7 @@ napi_value Common::GetNotificationMaxScreenWantAgent( ANS_LOGI("enter"); bool hasProperty = false; - WantAgent::WantAgent *wantAgent = nullptr; + AbilityRuntime::WantAgent::WantAgent *wantAgent = nullptr; napi_value result = nullptr; napi_valuetype valuetype = napi_undefined; @@ -1870,7 +1872,8 @@ napi_value Common::GetNotificationMaxScreenWantAgent( ANS_LOGE("Invalid object maxScreenWantAgent"); return nullptr; } - std::shared_ptr maxScreenWantAgent = std::make_shared(*wantAgent); + std::shared_ptr maxScreenWantAgent = + std::make_shared(*wantAgent); request.SetMaxScreenWantAgent(maxScreenWantAgent); } @@ -2185,9 +2188,9 @@ napi_value Common::GetNotificationActionButtonsDetailedBasicInfo( size_t strLen = 0; napi_value value = nullptr; std::string title; - WantAgent::WantAgent *wantAgentPtr = nullptr; + AbilityRuntime::WantAgent::WantAgent *wantAgentPtr = nullptr; std::shared_ptr pixelMap = nullptr; - std::shared_ptr wantAgent; + std::shared_ptr wantAgent; // title: string NAPI_CALL(env, napi_has_named_property(env, actionButton, "title", &hasProperty)); @@ -2209,7 +2212,7 @@ napi_value Common::GetNotificationActionButtonsDetailedBasicInfo( ANS_LOGE("Invalid object wantAgent"); return nullptr; } - wantAgent = std::make_shared(*wantAgentPtr); + wantAgent = std::make_shared(*wantAgentPtr); // icon?: image.PixelMap NAPI_CALL(env, napi_has_named_property(env, actionButton, "icon", &hasProperty)); @@ -3991,7 +3994,8 @@ bool Common::SourceTypeCToJS(const NotificationConstant::SourceType &inType, Sou return true; } -napi_value Common::CreateWantAgentByJS(const napi_env &env, const std::shared_ptr &agent) +napi_value Common::CreateWantAgentByJS(const napi_env &env, + const std::shared_ptr &agent) { if (agent == nullptr) { ANS_LOGI("agent is nullptr"); @@ -4018,7 +4022,7 @@ napi_value Common::CreateWantAgentByJS(const napi_env &env, const std::shared_pt wantAgent, (void *)agent.get(), [](napi_env env, void *data, void *hint) { - WantAgent::WantAgent *objectInfo = (WantAgent::WantAgent *)data; + AbilityRuntime::WantAgent::WantAgent *objectInfo = (AbilityRuntime::WantAgent::WantAgent *)data; ANS_LOGI("CreateWantAgentByJS this = %{public}p", objectInfo); if (objectInfo) { diff --git a/interfaces/kits/napi/ans/src/reminder/BUILD.gn b/interfaces/kits/napi/ans/src/reminder/BUILD.gn index ece4efa20..0cabca867 100644 --- a/interfaces/kits/napi/ans/src/reminder/BUILD.gn +++ b/interfaces/kits/napi/ans/src/reminder/BUILD.gn @@ -55,7 +55,6 @@ ohos_shared_library("reminderagent") { deps = [ "${frameworks_path}/ans/core:ans_core", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", "//foundation/multimedia/image_standard/interfaces/innerkits:image", "//third_party/jsoncpp:jsoncpp", @@ -66,6 +65,7 @@ ohos_shared_library("reminderagent") { external_deps = [ "ability_base:want", "ability_runtime:abilitykit_native", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", diff --git a/interfaces/kits/napi/wantagent/BUILD.gn b/interfaces/kits/napi/wantagent/BUILD.gn deleted file mode 100644 index 326b2365b..000000000 --- a/interfaces/kits/napi/wantagent/BUILD.gn +++ /dev/null @@ -1,60 +0,0 @@ -# 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. - -import("//base/notification/ans_standard/notification.gni") -import("//build/ohos.gni") - -ohos_shared_library("wantagent") { - include_dirs = [ - "//third_party/node/src", - "//foundation/aafwk/standard/services/common/include", - "//utils/system/safwk/native/include", - "//third_party/libuv/include", - "//foundation/aafwk/standard/frameworks/kits/ability/native/include", - "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime", - "//foundation/aafwk/standard/services/abilitymgr/include", - "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common", - "//foundation/aafwk/standard/services/common/include", - "./", - ] - - sources = [ - "napi_want_agent.cpp", - "native_module.cpp", - ] - - deps = [ - "${frameworks_path}/wantagent:wantagent_innerkits", - "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", - "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", - "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", - "//utils/native/base:utils", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:abilitykit_native", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "eventhandler:libeventhandler", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "napi:ace_napi", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] - - relative_install_dir = "module" - subsystem_name = "notification" - part_name = "ans_standard" -} diff --git a/interfaces/kits/napi/wantagent/napi_want_agent.cpp b/interfaces/kits/napi/wantagent/napi_want_agent.cpp deleted file mode 100644 index c530972e4..000000000 --- a/interfaces/kits/napi/wantagent/napi_want_agent.cpp +++ /dev/null @@ -1,1340 +0,0 @@ -/* - * 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. - */ - -#include "napi_want_agent.h" - -#include -#include -#include -#include - -#include "hilog_wrapper.h" -#include "napi_common.h" -#include "want_agent_helper.h" - -namespace OHOS { -#define NAPI_ASSERT_RETURN_NULL(env, assertion, message) \ -do { \ - if (!(assertion)) { \ - HILOG_INFO(message); \ - return nullptr; \ - } \ -} while (0) -constexpr int32_t BUSINESS_ERROR_CODE_OK = 0; - -TriggerCompleteCallBack::TriggerCompleteCallBack() -{} - -TriggerCompleteCallBack::~TriggerCompleteCallBack() -{} - -void TriggerCompleteCallBack::SetCallbackInfo(const napi_env &env, const napi_ref &ref) -{ - triggerCompleteInfo_.env = env; - triggerCompleteInfo_.ref = ref; -} - -void TriggerCompleteCallBack::SetWantAgentInstance(const std::shared_ptr &wantAgent) -{ - triggerCompleteInfo_.wantAgent = wantAgent; -} - -auto OnSendFinishedUvAfterWorkCallback = [](uv_work_t *work, int status) { - HILOG_INFO("TriggerCompleteCallBack::OnSendFinishedUvAfterWorkCallback:status = %{public}d", status); - - TriggerReceiveDataWorker *dataWorkerData = static_cast(work->data); - if (dataWorkerData == nullptr) { - HILOG_INFO("TriggerReceiveDataWorker instance(uv_work_t) is nullptr"); - delete work; - return; - } - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - - result[0] = GetCallbackErrorResult(dataWorkerData->env, BUSINESS_ERROR_CODE_OK); - napi_create_object(dataWorkerData->env, &result[1]); - // wrap wantAgent - napi_value wantAgentClass = nullptr; - auto constructorcb = [](napi_env env, napi_callback_info info) -> napi_value { - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); - return thisVar; - }; - napi_define_class( - dataWorkerData->env, "WantAgentClass", NAPI_AUTO_LENGTH, constructorcb, nullptr, 0, nullptr, &wantAgentClass); - napi_value jsWantAgent = nullptr; - napi_new_instance(dataWorkerData->env, wantAgentClass, 0, nullptr, &jsWantAgent); - auto finalizecb = [](napi_env env, void *data, void *hint) {}; - napi_wrap(dataWorkerData->env, jsWantAgent, (void *)dataWorkerData->wantAgent.get(), finalizecb, nullptr, nullptr); - napi_set_named_property(dataWorkerData->env, result[1], "wantAgent", jsWantAgent); - // wrap want - napi_value jsWant = WrapWant(dataWorkerData->env, dataWorkerData->want); - napi_set_named_property(dataWorkerData->env, result[1], "want", jsWant); - // wrap finalCode - napi_value jsFinalCode = nullptr; - napi_create_int32(dataWorkerData->env, dataWorkerData->resultCode, &jsFinalCode); - napi_set_named_property(dataWorkerData->env, result[1], "finalCode", jsFinalCode); - // wrap finalData - napi_value jsFinalData = nullptr; - napi_create_string_utf8(dataWorkerData->env, dataWorkerData->resultData.c_str(), NAPI_AUTO_LENGTH, &jsFinalData); - napi_set_named_property(dataWorkerData->env, result[1], "finalData", jsFinalData); - // wrap extraInfo - napi_value jsExtraInfo = WrapWantParams(dataWorkerData->env, dataWorkerData->resultExtras); - napi_set_named_property(dataWorkerData->env, result[1], "extraInfo", jsExtraInfo); - - napi_value callResult = nullptr; - napi_value undefined = nullptr; - napi_value callback = nullptr; - napi_get_undefined(dataWorkerData->env, &undefined); - napi_get_reference_value(dataWorkerData->env, dataWorkerData->ref, &callback); - napi_call_function(dataWorkerData->env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - delete dataWorkerData; - dataWorkerData = nullptr; - delete work; -}; - -void TriggerCompleteCallBack::OnSendFinished( - const AAFwk::Want &want, int resultCode, const std::string &resultData, const AAFwk::WantParams &resultExtras) -{ - HILOG_INFO("TriggerCompleteCallBack::OnSendFinished start"); - if (triggerCompleteInfo_.ref == nullptr) { - HILOG_INFO("triggerCompleteInfo_ CallBack is nullptr"); - return; - } - uv_loop_s *loop = nullptr; -#if NAPI_VERSION >= NUMBER_OF_PARAMETERS_TWO - napi_get_uv_event_loop(triggerCompleteInfo_.env, &loop); -#endif // NAPI_VERSION >= 2 - if (loop == nullptr) { - HILOG_INFO("loop instance is nullptr"); - return; - } - - uv_work_t *work = new (std::nothrow) uv_work_t; - if (work == nullptr) { - HILOG_INFO("uv_work_t instance is nullptr"); - return; - } - TriggerReceiveDataWorker *dataWorker = new (std::nothrow) TriggerReceiveDataWorker(); - if (dataWorker == nullptr) { - HILOG_INFO("TriggerReceiveDataWorker instance is nullptr"); - delete work; - work = nullptr; - return; - } - dataWorker->want = want; - dataWorker->resultCode = resultCode; - dataWorker->resultData = resultData; - dataWorker->resultExtras = resultExtras; - dataWorker->env = triggerCompleteInfo_.env; - dataWorker->ref = triggerCompleteInfo_.ref; - dataWorker->wantAgent = triggerCompleteInfo_.wantAgent; - work->data = (void *)dataWorker; - int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, OnSendFinishedUvAfterWorkCallback); - if (ret != 0) { - delete dataWorker; - dataWorker = nullptr; - delete work; - work = nullptr; - } - - HILOG_INFO("TriggerCompleteCallBack::OnSendFinished end"); -} -napi_value WantAgentInit(napi_env env, napi_value exports) -{ - HILOG_INFO("napi_moudule Init start..."); - napi_property_descriptor desc[] = { - DECLARE_NAPI_FUNCTION("getBundleName", NAPI_GetBundleName), - DECLARE_NAPI_FUNCTION("getUid", NAPI_GetUid), - DECLARE_NAPI_FUNCTION("cancel", NAPI_Cancel), - DECLARE_NAPI_FUNCTION("trigger", NAPI_Trigger), - DECLARE_NAPI_FUNCTION("equal", NAPI_Equal), - DECLARE_NAPI_FUNCTION("getWant", NAPI_GetWant), - DECLARE_NAPI_FUNCTION("getWantAgent", NAPI_GetWantAgent), - }; - - NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); - HILOG_INFO("napi_moudule Init end..."); - return exports; -} - -void SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const std::string &propName) -{ - napi_value prop = nullptr; - if (napi_create_int32(env, objName, &prop) == napi_ok) { - napi_set_named_property(env, dstObj, propName.c_str(), prop); - } -} - -napi_value WantAgentFlagsInit(napi_env env, napi_value exports) -{ - HILOG_INFO("%{public}s, called", __func__); - - napi_value obj = nullptr; - napi_create_object(env, &obj); - - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_ZERO, "ONE_TIME_FLAG"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_ONE, "NO_BUILD_FLAG"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_TWO, "CANCEL_PRESENT_FLAG"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_THREE, "UPDATE_PRESENT_FLAG"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_FOUR, "CONSTANT_FLAG"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_FIVE, "REPLACE_ELEMENT"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_SIX, "REPLACE_ACTION"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_SEVEN, "REPLACE_URI"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_EIGHT, "REPLACE_ENTITIES"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_NINE, "REPLACE_BUNDLE"); - - napi_property_descriptor exportFuncs[] = { - DECLARE_NAPI_PROPERTY("WantAgentFlags", obj), - }; - - napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); - return exports; -} - -napi_value WantAgentOperationTypeInit(napi_env env, napi_value exports) -{ - HILOG_INFO("%{public}s, called", __func__); - - napi_value obj = nullptr; - napi_create_object(env, &obj); - - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_ZERO, "UNKNOWN_TYPE"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_ONE, "START_ABILITY"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_TWO, "START_ABILITIES"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_THREE, "START_SERVICE"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_FOUR, "SEND_COMMON_EVENT"); - SetNamedPropertyByInteger(env, obj, NUMBER_OF_PARAMETERS_FIVE, "START_FOREGROUND_SERVICE"); - - napi_property_descriptor exportFuncs[] = { - DECLARE_NAPI_PROPERTY("OperationType", obj), - }; - - napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); - return exports; -} - -auto NAPI_GetBundleNameExecuteCallBack = [](napi_env env, void *data) { - HILOG_INFO("GetBundleName called(CallBack Mode)..."); - AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = static_cast(data); - asyncCallbackInfo->bundleName = WantAgentHelper::GetBundleName(asyncCallbackInfo->wantAgent); -}; - -auto NAPI_GetBundleNameCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetBundleName compeleted(CallBack Mode)..."); - AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("asyncCallbackInfo is nullptr."); - return; - } - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value callResult = nullptr; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - napi_create_string_utf8(env, asyncCallbackInfo->bundleName.c_str(), NAPI_AUTO_LENGTH, &result[1]); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -auto NAPI_GetBundleNamePromiseCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetBundleName compeleted(Promise Mode)..."); - AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("asyncCallbackInfo is nullptr."); - return; - } - napi_value result = nullptr; - napi_create_string_utf8(env, asyncCallbackInfo->bundleName.c_str(), NAPI_AUTO_LENGTH, &result); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -napi_value NAPI_GetBundleNameWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncGetBundleNameCallbackInfo &asyncCallbackInfo) -{ - HILOG_INFO("NAPI_GetBundleNameWrap called..."); - if (callBackMode) { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_GetBundleNameCallBack", NAPI_AUTO_LENGTH, &resourceName); - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_GetBundleNameExecuteCallBack, - NAPI_GetBundleNameCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); - // create reutrn - napi_value ret = nullptr; - NAPI_CALL(env, napi_create_int32(env, 0, &ret)); - return ret; - } else { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_GetBundleNamePromise", NAPI_AUTO_LENGTH, &resourceName); - - napi_deferred deferred = nullptr; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo.deferred = deferred; - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_GetBundleNameExecuteCallBack, - NAPI_GetBundleNamePromiseCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - napi_queue_async_work(env, asyncCallbackInfo.asyncWork); - return promise; - } -} - -napi_value NAPI_GetBundleName(napi_env env, napi_callback_info info) -{ - size_t argc = NUMBER_OF_PARAMETERS_TWO; - napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - HILOG_INFO("argc = [%{public}zu]", argc); - - napi_valuetype wantAgentType = napi_valuetype::napi_null; - napi_typeof(env, argv[0], &wantAgentType); - NAPI_ASSERT_RETURN_NULL(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); - - Notification::WantAgent::WantAgent *pWantAgent = nullptr; - napi_unwrap(env, argv[0], (void **)&(pWantAgent)); - if (pWantAgent == nullptr) { - HILOG_INFO("Notification::WantAgent::WantAgent napi_unwrap error"); - return NapiGetNull(env); - } - - bool callBackMode = false; - if (argc >= NUMBER_OF_PARAMETERS_TWO) { - napi_valuetype valuetype = napi_valuetype::napi_null; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - NAPI_ASSERT_RETURN_NULL(env, valuetype == napi_function, "Wrong argument type. Function expected."); - callBackMode = true; - } - AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncGetBundleNameCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - }; - if (asyncCallbackInfo == nullptr) { - return NapiGetNull(env); - } - asyncCallbackInfo->wantAgent = std::make_shared(*pWantAgent); - - if (callBackMode) { - napi_create_reference(env, argv[1], 1, &asyncCallbackInfo->callback[0]); - } - napi_value ret = NAPI_GetBundleNameWrap(env, info, callBackMode, *asyncCallbackInfo); - if (ret == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - return ((callBackMode) ? (NapiGetNull(env)) : (ret)); -} - -auto NAPI_GetUidWrapExecuteCallBack = [](napi_env env, void *data) { - HILOG_INFO("GetUid called(CallBack Mode)..."); - AsyncGetUidCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("asyncCallbackInfo is nullptr."); - return; - } - asyncCallbackInfo->uid = WantAgentHelper::GetUid(asyncCallbackInfo->wantAgent); -}; - -auto NAPI_GetUidWrapCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetUid compeleted(CallBack Mode)..."); - AsyncGetUidCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("asyncCallbackInfo is nullptr."); - return; - } - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value callResult = nullptr; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - napi_create_int32(env, asyncCallbackInfo->uid, &result[1]); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -auto NAPI_GetUidWrapPromiseCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetUid compeleted(Promise Mode)..."); - AsyncGetUidCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("asyncCallbackInfo is nullptr."); - return; - } - napi_value result = nullptr; - napi_create_int32(env, asyncCallbackInfo->uid, &result); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -napi_value NAPI_GetUidWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncGetUidCallbackInfo &asyncCallbackInfo) -{ - HILOG_INFO("NAPI_GetUidWrap called..."); - if (callBackMode) { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_GetUidCallBack", NAPI_AUTO_LENGTH, &resourceName); - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_GetUidWrapExecuteCallBack, - NAPI_GetUidWrapCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); - // create reutrn - napi_value ret = nullptr; - NAPI_CALL(env, napi_create_int32(env, 0, &ret)); - return ret; - } else { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_GetUidPromise", NAPI_AUTO_LENGTH, &resourceName); - - napi_deferred deferred = nullptr; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo.deferred = deferred; - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_GetUidWrapExecuteCallBack, - NAPI_GetUidWrapPromiseCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - napi_queue_async_work(env, asyncCallbackInfo.asyncWork); - return promise; - } -} - -napi_value NAPI_GetUid(napi_env env, napi_callback_info info) -{ - size_t argc = NUMBER_OF_PARAMETERS_TWO; - napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - HILOG_INFO("argc = [%{public}zu]", argc); - - napi_valuetype wantAgentType = napi_valuetype::napi_null; - napi_typeof(env, argv[0], &wantAgentType); - NAPI_ASSERT_RETURN_NULL(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); - - Notification::WantAgent::WantAgent *pWantAgent = nullptr; - napi_unwrap(env, argv[0], (void **)&(pWantAgent)); - if (pWantAgent == nullptr) { - return NapiGetNull(env); - } - - bool callBackMode = false; - if (argc >= NUMBER_OF_PARAMETERS_TWO) { - napi_valuetype valuetype = napi_valuetype::napi_null; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - NAPI_ASSERT_RETURN_NULL(env, valuetype == napi_function, "Wrong argument type. Function expected."); - callBackMode = true; - } - AsyncGetUidCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncGetUidCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - }; - if (asyncCallbackInfo == nullptr) { - return NapiGetNull(env); - } - asyncCallbackInfo->wantAgent = std::make_shared(*pWantAgent); - - if (callBackMode) { - napi_create_reference(env, argv[1], 1, &asyncCallbackInfo->callback[0]); - } - napi_value ret = NAPI_GetUidWrap(env, info, callBackMode, *asyncCallbackInfo); - if (ret == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - return ((callBackMode) ? (NapiGetNull(env)) : (ret)); -} - -auto NAPI_GetWantWrapExecuteCallBack = [](napi_env env, void *data) { - HILOG_INFO("GetWant called(CallBack Mode)..."); - AsyncGetWantCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("asyncCallbackInfo is nullptr."); - return; - } - asyncCallbackInfo->want = WantAgentHelper::GetWant(asyncCallbackInfo->wantAgent); -}; - -auto NAPI_GetWantWrapCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetWant compeleted(CallBack Mode)..."); - AsyncGetWantCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr || asyncCallbackInfo->want == nullptr) { - HILOG_ERROR("asyncCallbackInfo or want is nullptr."); - return; - } - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {}; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value callResult = nullptr; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - result[1] = WrapWant(env, *(asyncCallbackInfo->want)); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -auto NAPI_GetWantWrapPromiseCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetWant compeleted(Promise Mode)..."); - AsyncGetWantCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr || asyncCallbackInfo->want == nullptr) { - HILOG_ERROR("asyncCallbackInfo or want is nullptr."); - return; - } - napi_value result = WrapWant(env, *(asyncCallbackInfo->want)); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -napi_value NAPI_GetWantWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncGetWantCallbackInfo &asyncCallbackInfo) -{ - HILOG_INFO("NAPI_GetWantWrap called..."); - if (callBackMode) { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_GetWantCallBack", NAPI_AUTO_LENGTH, &resourceName); - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_GetWantWrapExecuteCallBack, - NAPI_GetWantWrapCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); - // create reutrn - napi_value ret = nullptr; - NAPI_CALL(env, napi_create_int32(env, 0, &ret)); - return ret; - } else { - napi_value resourceName; - napi_create_string_latin1(env, "NAPI_GetWantPromise", NAPI_AUTO_LENGTH, &resourceName); - - napi_deferred deferred = nullptr; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo.deferred = deferred; - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_GetWantWrapExecuteCallBack, - NAPI_GetWantWrapPromiseCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - napi_queue_async_work(env, asyncCallbackInfo.asyncWork); - return promise; - } -} - -napi_value NAPI_GetWant(napi_env env, napi_callback_info info) -{ - size_t argc = NUMBER_OF_PARAMETERS_TWO; - napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - HILOG_INFO("argc = [%{public}zu]", argc); - - napi_valuetype wantAgentType = napi_valuetype::napi_null; - napi_typeof(env, argv[0], &wantAgentType); - NAPI_ASSERT_RETURN_NULL(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); - - Notification::WantAgent::WantAgent *pWantAgent = nullptr; - napi_unwrap(env, argv[0], (void **)&(pWantAgent)); - if (pWantAgent == nullptr) { - return NapiGetNull(env); - } - - bool callBackMode = false; - if (argc >= NUMBER_OF_PARAMETERS_TWO) { - napi_valuetype valuetype = napi_valuetype::napi_null; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - NAPI_ASSERT_RETURN_NULL(env, valuetype == napi_function, "Wrong argument type. Function expected."); - callBackMode = true; - } - AsyncGetWantCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncGetWantCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - }; - if (asyncCallbackInfo == nullptr) { - return NapiGetNull(env); - } - asyncCallbackInfo->wantAgent = std::make_shared(*pWantAgent); - - if (callBackMode) { - napi_create_reference(env, argv[1], 1, &asyncCallbackInfo->callback[0]); - } - napi_value ret = NAPI_GetWantWrap(env, info, callBackMode, *asyncCallbackInfo); - if (ret == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - return ((callBackMode) ? (NapiGetNull(env)) : (ret)); -} - -void DeleteRecordByCode(const int32_t code) -{ - std::lock_guard guard(g_mutex); - for (const auto &item : *g_WantAgentMap) { - auto code_ = item.second; - auto record = item.first; - if (code_ == code) { - g_WantAgentMap->erase(record); - if (record != nullptr) { - delete record; - record = nullptr; - } - } - } -} - -auto NAPI_CancelWrapExecuteCallBack = [](napi_env env, void *data) { - HILOG_INFO("Cancel called(CallBack Mode)..."); - AsyncCancelCallbackInfo *asyncCallbackInfo = static_cast(data); - WantAgentHelper::Cancel(asyncCallbackInfo->wantAgent); -}; - -auto NAPI_CancelWrapCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Cancel compeleted(CallBack Mode)..."); - AsyncCancelCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("asyncCallbackInfo is nullptr."); - return; - } - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {nullptr}; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value callResult = nullptr; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - napi_get_null(env, &result[1]); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -auto NAPI_CancelWrapPromiseCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Cancel compeleted(Promise Mode)..."); - AsyncCancelCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("asyncCallbackInfo is nullptr."); - return; - } - napi_value result = nullptr; - napi_get_null(env, &result); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -napi_value NAPI_CancelWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncCancelCallbackInfo &asyncCallbackInfo) -{ - HILOG_INFO("NAPI_CancelWrap called..."); - if (callBackMode) { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_CancelCallBack", NAPI_AUTO_LENGTH, &resourceName); - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_CancelWrapExecuteCallBack, - NAPI_CancelWrapCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); - // create reutrn - napi_value ret = nullptr; - NAPI_CALL(env, napi_create_int32(env, 0, &ret)); - return ret; - } else { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_CancelPromise", NAPI_AUTO_LENGTH, &resourceName); - - napi_deferred deferred = nullptr; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo.deferred = deferred; - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_CancelWrapExecuteCallBack, - NAPI_CancelWrapPromiseCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - napi_queue_async_work(env, asyncCallbackInfo.asyncWork); - return promise; - } -} - -napi_value NAPI_Cancel(napi_env env, napi_callback_info info) -{ - size_t argc = NUMBER_OF_PARAMETERS_TWO; - napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - HILOG_INFO("argc = [%{public}zu]", argc); - - napi_valuetype wantAgentType = napi_valuetype::napi_null; - napi_typeof(env, argv[0], &wantAgentType); - NAPI_ASSERT_RETURN_NULL(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); - - Notification::WantAgent::WantAgent *pWantAgent = nullptr; - napi_unwrap(env, argv[0], (void **)&(pWantAgent)); - if (pWantAgent == nullptr) { - return NapiGetNull(env); - } - - bool callBackMode = false; - if (argc >= NUMBER_OF_PARAMETERS_TWO) { - napi_valuetype valuetype = napi_valuetype::napi_null; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - NAPI_ASSERT_RETURN_NULL(env, valuetype == napi_function, "Wrong argument type. Function expected."); - callBackMode = true; - } - AsyncCancelCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncCancelCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - }; - if (asyncCallbackInfo == nullptr) { - return NapiGetNull(env); - } - asyncCallbackInfo->wantAgent = std::make_shared(*pWantAgent); - - if (callBackMode) { - napi_create_reference(env, argv[1], 1, &asyncCallbackInfo->callback[0]); - } - napi_value ret = NAPI_CancelWrap(env, info, callBackMode, *asyncCallbackInfo); - if (ret == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - return ((callBackMode) ? (NapiGetNull(env)) : (ret)); -} - -auto NAPI_TriggerWrapExecuteCallBack = [](napi_env env, void *data) { - HILOG_INFO("Trigger called ..."); - AsyncTriggerCallbackInfo *asyncCallbackInfo = static_cast(data); - asyncCallbackInfo->triggerObj->SetCallbackInfo(env, asyncCallbackInfo->callback[0]); - asyncCallbackInfo->triggerObj->SetWantAgentInstance(asyncCallbackInfo->wantAgent); - WantAgentHelper::TriggerWantAgent(asyncCallbackInfo->wantAgent, - asyncCallbackInfo->triggerObj, - asyncCallbackInfo->triggerInfo); -}; - -auto NAPI_TriggerWrapCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Trigger compeleted ..."); - AsyncTriggerCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("asyncCallbackInfo is nullptr."); - return; - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -napi_value NAPI_TriggerWrap(napi_env env, napi_callback_info info, AsyncTriggerCallbackInfo &asyncCallbackInfo) -{ - HILOG_INFO("NAPI_TriggerWrap called..."); - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_TriggerWrap", NAPI_AUTO_LENGTH, &resourceName); - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_TriggerWrapExecuteCallBack, - NAPI_TriggerWrapCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); - // create reutrn - napi_value ret = nullptr; - NAPI_CALL(env, napi_create_int32(env, 0, &ret)); - return ret; -} - -napi_value NAPI_GetTriggerInfo(napi_value argv[NUMBER_OF_PARAMETERS_THREE], uint8_t argvLen, napi_env env, - napi_callback_info info, Notification::WantAgent::TriggerInfo &triggerInfo) -{ - if (argvLen < 1) { - return nullptr; - } - // Get triggerInfo - napi_value jsTriggerInfo = argv[1]; - napi_valuetype valueType = napi_valuetype::napi_null; - NAPI_CALL(env, napi_typeof(env, jsTriggerInfo, &valueType)); - NAPI_ASSERT_RETURN_NULL(env, valueType == napi_object, "param type mismatch!"); - - // Get triggerInfo code - int32_t code = -1; - if (!UnwrapInt32ByPropertyName(env, jsTriggerInfo, "code", code)) { - return NapiGetNull(env); - } - // Get triggerInfo want - napi_value jsWant = nullptr; - jsWant = GetPropertyValueByPropertyName(env, jsTriggerInfo, "want", napi_object); - std::shared_ptr want = nullptr; - if (jsWant != nullptr) { - want = std::make_shared(); - if (!UnwrapWant(env, jsWant, *want)) { - return NapiGetNull(env); - } - } - // Get triggerInfo permission - std::string permission = {}; - UnwrapStringByPropertyName(env, jsTriggerInfo, "permission", permission); - // Get triggerInfo extraInfo - napi_value jsExtraInfo = nullptr; - jsExtraInfo = GetPropertyValueByPropertyName(env, jsTriggerInfo, "extraInfo", napi_object); - std::shared_ptr extraInfo = nullptr; - if (jsExtraInfo != nullptr) { - extraInfo = std::make_shared(); - if (!UnwrapWantParams(env, jsExtraInfo, *extraInfo)) { - return NapiGetNull(env); - } - } - - Notification::WantAgent::TriggerInfo triggerInfoData(permission, extraInfo, want, code); - triggerInfo = triggerInfoData; - return NapiGetNull(env); -} - -napi_value NAPI_Trigger(napi_env env, napi_callback_info info) -{ - size_t argc = NUMBER_OF_PARAMETERS_THREE; - napi_value argv[NUMBER_OF_PARAMETERS_THREE] = {}; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - HILOG_INFO("argc = [%{public}zu]", argc); - - napi_valuetype wantAgentType = napi_valuetype::napi_null; - napi_typeof(env, argv[0], &wantAgentType); - NAPI_ASSERT_RETURN_NULL(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); - - Notification::WantAgent::WantAgent *pWantAgent = nullptr; - napi_unwrap(env, argv[0], (void **)&(pWantAgent)); - if (pWantAgent == nullptr) { - return NapiGetNull(env); - } - - bool callBackMode = false; - if (argc >= NUMBER_OF_PARAMETERS_THREE) { - napi_valuetype valuetype; - NAPI_CALL(env, napi_typeof(env, argv[NUMBER_OF_PARAMETERS_TWO], &valuetype)); - NAPI_ASSERT_RETURN_NULL(env, valuetype == napi_function, "Wrong argument type. Function expected."); - callBackMode = true; - } - - Notification::WantAgent::TriggerInfo triggerInfo; - napi_value ret = NAPI_GetTriggerInfo(argv, NUMBER_OF_PARAMETERS_THREE, env, info, triggerInfo); - if (ret == nullptr) { - return NapiGetNull(env); - } - - AsyncTriggerCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncTriggerCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - }; - if (asyncCallbackInfo == nullptr) { - return NapiGetNull(env); - } - asyncCallbackInfo->wantAgent = std::make_shared(*pWantAgent); - asyncCallbackInfo->triggerInfo = triggerInfo; - asyncCallbackInfo->triggerObj = nullptr; - if (callBackMode) { - asyncCallbackInfo->callBackMode = callBackMode; - asyncCallbackInfo->triggerObj = std::make_shared(); - napi_create_reference(env, argv[NUMBER_OF_PARAMETERS_TWO], 1, &asyncCallbackInfo->callback[0]); - } - - ret = NAPI_TriggerWrap(env, info, *asyncCallbackInfo); - if (ret == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - return NapiGetNull(env); -} - -auto NAPI_EqualWrapExecuteCallBack = [](napi_env env, void *data) { - HILOG_INFO("Equal called(CallBack Mode)..."); - AsyncEqualCallbackInfo *asyncCallbackInfo = static_cast(data); - asyncCallbackInfo->result = - WantAgentHelper::JudgeEquality(asyncCallbackInfo->wantAgentFirst, asyncCallbackInfo->wantAgentSecond); -}; - -auto NAPI_EqualWrapCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Equal compeleted(CallBack Mode)..."); - AsyncEqualCallbackInfo *asyncCallbackInfo = static_cast(data); - if (asyncCallbackInfo == nullptr) { - HILOG_ERROR("asyncCallbackInfo is nullptr."); - return; - } - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {}; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value callResult = nullptr; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - napi_get_boolean(env, asyncCallbackInfo->result, &result[1]); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -auto NAPI_EqualWrapPromiseCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Equal compeleted(Promise Mode)..."); - AsyncEqualCallbackInfo *asyncCallbackInfo = static_cast(data); - napi_value result = nullptr; - napi_get_boolean(env, asyncCallbackInfo->result, &result); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; -}; - -napi_value NAPI_EqualWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncEqualCallbackInfo &asyncCallbackInfo) -{ - HILOG_INFO("NAPI_EqualWrap called..."); - if (callBackMode) { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_EqualWrapCallBack", NAPI_AUTO_LENGTH, &resourceName); - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_EqualWrapExecuteCallBack, - NAPI_EqualWrapCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); - // create reutrn - napi_value ret = nullptr; - NAPI_CALL(env, napi_create_int32(env, 0, &ret)); - return ret; - } else { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_EqualPromise", NAPI_AUTO_LENGTH, &resourceName); - - napi_deferred deferred = nullptr; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo.deferred = deferred; - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_EqualWrapExecuteCallBack, - NAPI_EqualWrapPromiseCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - napi_queue_async_work(env, asyncCallbackInfo.asyncWork); - return promise; - } -} - -napi_value NAPI_Equal(napi_env env, napi_callback_info info) -{ - size_t argc = NUMBER_OF_PARAMETERS_THREE; - napi_value argv[NUMBER_OF_PARAMETERS_THREE] = {}; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - HILOG_INFO("argc = [%{public}zu]", argc); - - napi_valuetype wantAgentFirstType = napi_valuetype::napi_null; - napi_typeof(env, argv[0], &wantAgentFirstType); - NAPI_ASSERT_RETURN_NULL(env, wantAgentFirstType == napi_object, "Wrong argument type. Object expected."); - - Notification::WantAgent::WantAgent *pWantAgentFirst = nullptr; - napi_unwrap(env, argv[0], (void **)&(pWantAgentFirst)); - if (pWantAgentFirst == nullptr) { - return NapiGetNull(env); - } - - napi_valuetype wantAgentSecondType = napi_valuetype::napi_null; - napi_typeof(env, argv[1], &wantAgentSecondType); - NAPI_ASSERT_RETURN_NULL(env, wantAgentSecondType == napi_object, "Wrong argument type. Object expected."); - - Notification::WantAgent::WantAgent *pWantAgentSecond = nullptr; - napi_unwrap(env, argv[1], (void **)&(pWantAgentSecond)); - if (pWantAgentSecond == nullptr) { - return NapiGetNull(env); - } - - bool callBackMode = false; - if (argc >= NUMBER_OF_PARAMETERS_THREE) { - napi_valuetype valuetype = napi_valuetype::napi_null; - NAPI_CALL(env, napi_typeof(env, argv[NUMBER_OF_PARAMETERS_TWO], &valuetype)); - NAPI_ASSERT_RETURN_NULL(env, valuetype == napi_function, "Wrong argument type. Function expected."); - callBackMode = true; - } - AsyncEqualCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncEqualCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - }; - if (asyncCallbackInfo == nullptr) { - return NapiGetNull(env); - } - asyncCallbackInfo->wantAgentFirst = std::make_shared(*pWantAgentFirst); - asyncCallbackInfo->wantAgentSecond = std::make_shared(*pWantAgentSecond); - - if (callBackMode) { - napi_create_reference(env, argv[NUMBER_OF_PARAMETERS_TWO], 1, &asyncCallbackInfo->callback[0]); - } - napi_value ret = NAPI_EqualWrap(env, info, callBackMode, *asyncCallbackInfo); - if (ret == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - return ((callBackMode) ? (NapiGetNull(env)) : (ret)); -} - -auto NAPI_GetWantAgentWrapExecuteCallBack = [](napi_env env, void *data) { - HILOG_INFO("GetWantAgent called(CallBack Mode)..."); - AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = static_cast(data); - Notification::WantAgent::WantAgentInfo wantAgentInfo(asyncCallbackInfo->requestCode, - asyncCallbackInfo->operationType, - asyncCallbackInfo->wantAgentFlags, - asyncCallbackInfo->wants, - asyncCallbackInfo->extraInfo); - asyncCallbackInfo->wantAgent = - Notification::WantAgent::WantAgentHelper::GetWantAgent(asyncCallbackInfo->context, wantAgentInfo); - if (asyncCallbackInfo->wantAgent == nullptr) { - HILOG_INFO("GetWantAgent instance is nullptr..."); - } - int32_t code = Notification::WantAgent::WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); - std::lock_guard guard(g_mutex); - g_WantAgentMap->emplace(asyncCallbackInfo, code); -}; - -auto NAPI_GetWantAgentWrapCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetWantAgent compeleted(CallBack Mode)..."); - AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = static_cast(data); - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_value callResult = nullptr; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - - napi_value wantAgentClass = nullptr; - napi_define_class(env, - "WantAgentClass", - NAPI_AUTO_LENGTH, - [](napi_env env, napi_callback_info info) -> napi_value { - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); - return thisVar; - }, - nullptr, - 0, - nullptr, - &wantAgentClass); - napi_new_instance(env, wantAgentClass, 0, nullptr, &result[1]); - napi_wrap(env, - result[1], - (void *)asyncCallbackInfo->wantAgent.get(), - [](napi_env env, void *data, void *hint) {}, - nullptr, - nullptr); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); -}; - -auto NAPI_GetWantAgentWrapPromiseCompleteCallBack = [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetWantAgent compeleted(Promise Mode)..."); - AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = static_cast(data); - napi_value wantAgentClass = nullptr; - napi_define_class(env, - "WantAgentClass", - NAPI_AUTO_LENGTH, - [](napi_env env, napi_callback_info info) -> napi_value { - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); - return thisVar; - }, - nullptr, - 0, - nullptr, - &wantAgentClass); - napi_value result = nullptr; - napi_new_instance(env, wantAgentClass, 0, nullptr, &result); - napi_wrap(env, - result, - (void *)asyncCallbackInfo->wantAgent.get(), - [](napi_env env, void *data, void *hint) {}, - nullptr, - nullptr); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); -}; - -napi_value NAPI_GetWantAgentWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncGetWantAgentCallbackInfo &asyncCallbackInfo) -{ - HILOG_INFO("NAPI_GetWantAgentWrap called..."); - if (callBackMode) { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_GetWantAgentCallBack", NAPI_AUTO_LENGTH, &resourceName); - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_GetWantAgentWrapExecuteCallBack, - NAPI_GetWantAgentWrapCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); - // create reutrn - napi_value ret = nullptr; - NAPI_CALL(env, napi_create_int32(env, 0, &ret)); - return ret; - } else { - napi_value resourceName = nullptr; - napi_create_string_latin1(env, "NAPI_GetWantAgentPromise", NAPI_AUTO_LENGTH, &resourceName); - - napi_deferred deferred = nullptr; - napi_value promise = nullptr; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo.deferred = deferred; - - napi_create_async_work(env, - nullptr, - resourceName, - NAPI_GetWantAgentWrapExecuteCallBack, - NAPI_GetWantAgentWrapPromiseCompleteCallBack, - (void *)&asyncCallbackInfo, - &asyncCallbackInfo.asyncWork); - napi_queue_async_work(env, asyncCallbackInfo.asyncWork); - return promise; - } -} - -napi_value NAPI_GetWantAgentWants(napi_env env, napi_value jsWantAgentInfo, const WantAgentWantsParas ¶s) -{ - napi_valuetype jsWantAgentInfoType = napi_valuetype::napi_null; - NAPI_CALL(env, napi_typeof(env, jsWantAgentInfo, &jsWantAgentInfoType)); - NAPI_ASSERT_RETURN_NULL(env, jsWantAgentInfoType == napi_object, "param type mismatch!"); - - napi_value jsWants = GetPropertyValueByPropertyName(env, jsWantAgentInfo, "wants", napi_object); - bool isArray = false; - if (jsWants == nullptr || napi_is_array(env, jsWants, &isArray) != napi_ok || !isArray) { - return NapiGetNull(env); - } - - uint32_t wantsLen = 0; - napi_get_array_length(env, jsWants, &wantsLen); - for (uint32_t i = 0; i < wantsLen; i++) { - std::shared_ptr want = std::make_shared(); - napi_value jsWant = nullptr; - napi_get_element(env, jsWants, i, &jsWant); - if (!UnwrapWant(env, jsWant, *want)) { - return NapiGetNull(env); - } - paras.wants.emplace_back(want); - } - - // Get operationType - if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "operationType", paras.operationType)) { - return NapiGetNull(env); - } - // Get requestCode - if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "requestCode", paras.requestCode)) { - return NapiGetNull(env); - } - // Get wantAgentFlags - napi_value JsWantAgentFlags = GetPropertyValueByPropertyName(env, jsWantAgentInfo, "wantAgentFlags", napi_object); - if (JsWantAgentFlags != nullptr) { - uint32_t arrayLength = 0; - NAPI_CALL(env, napi_get_array_length(env, JsWantAgentFlags, &arrayLength)); - HILOG_INFO("property is array, length=%{public}d", arrayLength); - for (uint32_t i = 0; i < arrayLength; i++) { - napi_value napiWantAgentFlags = nullptr; - napi_get_element(env, JsWantAgentFlags, i, &napiWantAgentFlags); - napi_valuetype valuetype0 = napi_valuetype::napi_null; - NAPI_CALL(env, napi_typeof(env, napiWantAgentFlags, &valuetype0)); - NAPI_ASSERT_RETURN_NULL(env, valuetype0 == napi_number, "Wrong argument type. Numbers expected."); - int32_t value0 = 0; - NAPI_CALL(env, napi_get_value_int32(env, napiWantAgentFlags, &value0)); - paras.wantAgentFlags.emplace_back(static_cast(value0)); - } - } - // Get extraInfo - napi_value JsExtraInfo = GetPropertyValueByPropertyName(env, jsWantAgentInfo, "extraInfo", napi_object); - if (JsExtraInfo != nullptr) { - if (!UnwrapWantParams(env, JsExtraInfo, paras.extraInfo)) { - return NapiGetNull(env); - } - } - return NapiGetNull(env); -} - -napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info) -{ - size_t argc = NUMBER_OF_PARAMETERS_TWO; - napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - HILOG_INFO("argc = [%{public}zu]", argc); - napi_value jsWantAgentInfo = argv[0]; - - // Get wants - std::vector> wants = {}; - int32_t operationType = -1; - int32_t requestCode = -1; - std::vector wantAgentFlags = {}; - AAFwk::WantParams extraInfo = {}; - WantAgentWantsParas paras = { - .wants = wants, - .operationType = operationType, - .requestCode = requestCode, - .wantAgentFlags = wantAgentFlags, - .extraInfo = extraInfo, - }; - napi_value ret = NAPI_GetWantAgentWants(env, jsWantAgentInfo, paras); - if (ret == nullptr) { - return NapiGetNull(env); - } - - bool callBackMode = false; - if (argc >= NUMBER_OF_PARAMETERS_TWO) { - napi_valuetype valuetype; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - NAPI_ASSERT_RETURN_NULL(env, valuetype == napi_function, "Wrong argument type. Function expected."); - callBackMode = true; - } - - AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncGetWantAgentCallbackInfo { - .env = env, - .asyncWork = nullptr, - .deferred = nullptr, - }; - if (asyncCallbackInfo == nullptr) { - return NapiGetNull(env); - } - asyncCallbackInfo->wants = wants; - asyncCallbackInfo->operationType = - static_cast(operationType); - asyncCallbackInfo->requestCode = requestCode; - asyncCallbackInfo->wantAgentFlags = wantAgentFlags; - asyncCallbackInfo->extraInfo.reset(new (std::nothrow) AAFwk::WantParams(extraInfo)); - asyncCallbackInfo->context = OHOS::AbilityRuntime::Context::GetApplicationContext(); - - if (callBackMode) { - napi_create_reference(env, argv[1], 1, &asyncCallbackInfo->callback[0]); - } - ret = NAPI_GetWantAgentWrap(env, info, callBackMode, *asyncCallbackInfo); - if (ret == nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - - return ((callBackMode) ? (NapiGetNull(env)) : (ret)); -} - -napi_value GetCallbackErrorResult(napi_env env, int errCode) -{ - napi_value result = nullptr; - napi_value eCode = nullptr; - NAPI_CALL(env, napi_create_int32(env, errCode, &eCode)); - NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_CALL(env, napi_set_named_property(env, result, "code", eCode)); - return result; -} - -napi_value NapiGetNull(napi_env env) -{ - napi_value result = nullptr; - napi_get_null(env, &result); - return result; -} -} // namespace OHOS diff --git a/interfaces/kits/napi/wantagent/napi_want_agent.h b/interfaces/kits/napi/wantagent/napi_want_agent.h deleted file mode 100644 index b6312c585..000000000 --- a/interfaces/kits/napi/wantagent/napi_want_agent.h +++ /dev/null @@ -1,198 +0,0 @@ -/* - * 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 NAPI_WANT_AGENT_H -#define NAPI_WANT_AGENT_H - -#include -#include -#include -#include - -#include "ability.h" -#include "completed_callback.h" -#include "context/context.h" -#include "napi/native_api.h" -#include "napi/native_common.h" -#include "napi/native_node_api.h" -#include "trigger_info.h" -#include "want.h" -#include "want_agent.h" -#include "want_agent_constant.h" -#include "want_params.h" - -namespace OHOS { -using namespace OHOS::AppExecFwk; -using namespace OHOS::Notification; -using namespace OHOS::Notification::WantAgent; - -const uint8_t NUMBER_OF_PARAMETERS_ZERO = 0; -const uint8_t NUMBER_OF_PARAMETERS_ONE = 1; -const uint8_t NUMBER_OF_PARAMETERS_TWO = 2; -const uint8_t NUMBER_OF_PARAMETERS_THREE = 3; -const uint8_t NUMBER_OF_PARAMETERS_FOUR = 4; -const uint8_t NUMBER_OF_PARAMETERS_FIVE = 5; -const uint8_t NUMBER_OF_PARAMETERS_SIX = 6; -const uint8_t NUMBER_OF_PARAMETERS_SEVEN = 7; -const uint8_t NUMBER_OF_PARAMETERS_EIGHT = 8; -const uint8_t NUMBER_OF_PARAMETERS_NINE = 9; - -class TriggerCompleteCallBack; - -struct AsyncGetWantAgentCallbackInfo { - napi_env env; - napi_async_work asyncWork; - napi_deferred deferred; - napi_ref callback[2] = {0}; - std::vector> wants; - Notification::WantAgent::WantAgentConstant::OperationType operationType; - int32_t requestCode = -1; - std::vector wantAgentFlags; - std::shared_ptr extraInfo; - std::shared_ptr context; - std::shared_ptr wantAgent; -}; - -struct AsyncGetBundleNameCallbackInfo { - napi_env env; - napi_async_work asyncWork; - napi_deferred deferred; - napi_ref callback[2] = {0}; - std::shared_ptr wantAgent; - std::string bundleName; -}; - -struct AsyncGetUidCallbackInfo { - napi_env env; - napi_async_work asyncWork; - napi_deferred deferred; - napi_ref callback[2] = {0}; - std::shared_ptr wantAgent; - int32_t uid; -}; - -struct AsyncGetWantCallbackInfo { - napi_env env; - napi_async_work asyncWork; - napi_deferred deferred; - napi_ref callback[2] = {0}; - std::shared_ptr wantAgent; - std::shared_ptr want; -}; - -struct AsyncEqualCallbackInfo { - napi_env env; - napi_async_work asyncWork; - napi_deferred deferred; - napi_ref callback[2] = {0}; - std::shared_ptr wantAgentFirst; - std::shared_ptr wantAgentSecond; - bool result; -}; - -struct AsyncCancelCallbackInfo { - napi_env env; - napi_async_work asyncWork; - napi_deferred deferred; - napi_ref callback[2] = {0}; - std::shared_ptr wantAgent; -}; - -struct AsyncTriggerCallbackInfo { - napi_env env; - napi_async_work asyncWork; - napi_deferred deferred; - napi_ref callback[2] = {0}; - bool callBackMode = false; - std::shared_ptr triggerObj; - std::shared_ptr wantAgent; - Notification::WantAgent::TriggerInfo triggerInfo; -}; - -struct CallbackInfo { - std::shared_ptr wantAgent; - napi_env env; - napi_ref ref; -}; - -struct TriggerReceiveDataWorker { - napi_env env; - napi_ref ref = 0; - std::shared_ptr wantAgent; - AAFwk::Want want; - int resultCode; - std::string resultData; - AAFwk::WantParams resultExtras; -}; - -struct WantAgentWantsParas { - std::vector> &wants; - int32_t &operationType; - int32_t &requestCode; - std::vector &wantAgentFlags; - AAFwk::WantParams &extraInfo; -}; - -class TriggerCompleteCallBack : public CompletedCallback { -public: - TriggerCompleteCallBack(); - virtual ~TriggerCompleteCallBack(); - -public: - virtual void OnSendFinished(const AAFwk::Want &want, int resultCode, const std::string &resultData, - const AAFwk::WantParams &resultExtras) override; - void SetCallbackInfo(const napi_env &env, const napi_ref &ref); - void SetWantAgentInstance(const std::shared_ptr &wantAgent); - -private: - CallbackInfo triggerCompleteInfo_; -}; - -napi_value WantAgentInit(napi_env env, napi_value exports); - -void SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const std::string &propName); -napi_value WantAgentFlagsInit(napi_env env, napi_value exports); -napi_value WantAgentOperationTypeInit(napi_env env, napi_value exports); - -napi_value NAPI_GetBundleName(napi_env env, napi_callback_info info); -napi_value NAPI_GetUid(napi_env env, napi_callback_info info); -napi_value NAPI_GetWant(napi_env env, napi_callback_info info); -napi_value NAPI_Cancel(napi_env env, napi_callback_info info); -napi_value NAPI_Trigger(napi_env env, napi_callback_info info); -napi_value NAPI_Equal(napi_env env, napi_callback_info info); -napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info); - -napi_value GetCallbackErrorResult(napi_env env, int errCode); -napi_value NapiGetNull(napi_env env); - -void DeleteRecordByCode(const int32_t code); -static std::unique_ptr, - std::function *)>> - g_WantAgentMap(new std::map, - [](std::map *map) { - if (map == nullptr) { - return; - } - for (auto &item : *map) { - if (item.first != nullptr) { - delete item.first; - } - } - map->clear(); - delete map; - }); -static std::recursive_mutex g_mutex; -} // namespace OHOS -#endif // NAPI_WANT_AGENT_H diff --git a/interfaces/kits/napi/wantagent/native_module.cpp b/interfaces/kits/napi/wantagent/native_module.cpp deleted file mode 100644 index f4474a384..000000000 --- a/interfaces/kits/napi/wantagent/native_module.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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. - */ - -#include -#include -#include -#include - -#include "napi_want_agent.h" -#include "napi/native_api.h" -#include "napi/native_node_api.h" - -#include "hilog_wrapper.h" - -using namespace OHOS::Notification; -using namespace OHOS::Notification::WantAgent; - -namespace OHOS { -EXTERN_C_START -/* - * function for module exports - */ -static napi_value Init(napi_env env, napi_value exports) -{ - WantAgentInit(env, exports); - WantAgentFlagsInit(env, exports); - WantAgentOperationTypeInit(env, exports); - return exports; -} -EXTERN_C_END - -/* - * Module define - */ -static napi_module _module = { - .nm_version = 1, - .nm_flags = 0, - .nm_filename = nullptr, - .nm_register_func = Init, - .nm_modname = "wantagent", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -/* - * Module register function - */ -extern "C" __attribute__((constructor)) void RegisterModule(void) -{ - napi_module_register(&_module); -} -} // namespace OHOS \ No newline at end of file diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 25ec1ffc3..6f04904e5 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -56,7 +56,6 @@ ohos_shared_library("libans") { "${core_path}:ans_core", "${frameworks_path}/ans/dialog/dialog_ui/js:dialog_js_files_etc", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr", "//utils/native/base:utils", ] @@ -74,6 +73,7 @@ ohos_shared_library("libans") { external_deps = [ "ability_runtime:abilitykit_native", "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", "distributeddatamgr:distributeddata_inner", "multimedia_image_standard:image_native", "multimedia_media_standard:media_client", diff --git a/services/ans/include/reminder_timer_info.h b/services/ans/include/reminder_timer_info.h index 0d8ddeb33..b3e66b42d 100644 --- a/services/ans/include/reminder_timer_info.h +++ b/services/ans/include/reminder_timer_info.h @@ -59,7 +59,7 @@ public: /** * Indicates the want agent information. */ - void SetWantAgent(std::shared_ptr wantAgent) override; + void SetWantAgent(std::shared_ptr wantAgent) override; private: std::string action_; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 08a0c83a5..9985085a5 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2931,9 +2931,9 @@ void AdvancedNotificationService::TriggerRemoveWantAgent(const sptrGetRemovalWantAgent() == nullptr) { return; } - OHOS::Notification::WantAgent::TriggerInfo triggerInfo; - std::shared_ptr agent = request->GetRemovalWantAgent(); - WantAgent::WantAgentHelper::TriggerWantAgent(agent, nullptr, triggerInfo); + OHOS::AbilityRuntime::WantAgent::TriggerInfo triggerInfo; + std::shared_ptr agent = request->GetRemovalWantAgent(); + AbilityRuntime::WantAgent::WantAgentHelper::TriggerWantAgent(agent, nullptr, triggerInfo); } ErrCode AdvancedNotificationService::IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 9fff8c9f6..50d19fc97 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -229,8 +229,8 @@ std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerTyp sharedTimerInfo->SetInterval(0); int requestCode = 10; - std::vector flags; - flags.push_back(WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); + std::vector flags; + flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); auto want = std::make_shared(); switch (type) { @@ -253,14 +253,15 @@ std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerTyp } std::vector> wants; wants.push_back(want); - WantAgent::WantAgentInfo wantAgentInfo( + AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( requestCode, - WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, + AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, flags, wants, nullptr ); - std::shared_ptr wantAgent = WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); sharedTimerInfo->SetWantAgent(wantAgent); return sharedTimerInfo; } diff --git a/services/ans/src/reminder_timer_info.cpp b/services/ans/src/reminder_timer_info.cpp index 486ae1d00..939bb0685 100644 --- a/services/ans/src/reminder_timer_info.cpp +++ b/services/ans/src/reminder_timer_info.cpp @@ -37,7 +37,7 @@ void ReminderTimerInfo::SetInterval(const uint64_t &_interval) interval = _interval; } -void ReminderTimerInfo::SetWantAgent(std::shared_ptr _wantAgent) +void ReminderTimerInfo::SetWantAgent(std::shared_ptr _wantAgent) { wantAgent = _wantAgent; } diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 433c15344..d8e19a2e7 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -63,7 +63,6 @@ ohos_unittest("ans_unit_test") { deps = [ "${core_path}:ans_core", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr", "//third_party/googletest:gtest_main", "//utils/native/base:utils", @@ -79,6 +78,7 @@ ohos_unittest("ans_unit_test") { "ability_base:want", "ability_runtime:abilitykit_native", "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 225f65d35..5eb0e9d07 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -56,9 +56,7 @@ ohos_moduletest("ans_module_test") { deps = [ "${core_path}:ans_core", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr", - "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] @@ -66,6 +64,7 @@ ohos_moduletest("ans_module_test") { "ability_base:want", "ability_runtime:abilitykit_native", "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", diff --git a/services/test/moduletest/ans_module_test.cpp b/services/test/moduletest/ans_module_test.cpp index 5bc3a973b..854b88975 100644 --- a/services/test/moduletest/ans_module_test.cpp +++ b/services/test/moduletest/ans_module_test.cpp @@ -1488,7 +1488,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0066, Function | SmallTest | Level1) HWTEST_F(AnsModuleTest, AnsModuleTest_0100, Function | SmallTest | Level1) { // create wantagent - std::shared_ptr agent = std::make_shared(); + std::shared_ptr agent = + std::make_shared(); // subscriber auto subscriber = new TestAnsSubscriber(); @@ -1531,7 +1532,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0100, Function | SmallTest | Level1) HWTEST_F(AnsModuleTest, AnsModuleTest_0101, Function | SmallTest | Level1) { // create wantagent - std::shared_ptr agent = std::make_shared(); + std::shared_ptr agent = + std::make_shared(); // subscriber auto subscriber = new TestAnsSubscriber(); @@ -1562,7 +1564,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0101, Function | SmallTest | Level1) HWTEST_F(AnsModuleTest, AnsModuleTest_0102, Function | SmallTest | Level1) { // create wantagent - std::shared_ptr agent = std::make_shared(); + std::shared_ptr agent = + std::make_shared(); // subscriber auto subscriber = new TestAnsSubscriber(); @@ -1593,7 +1596,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0102, Function | SmallTest | Level1) HWTEST_F(AnsModuleTest, AnsModuleTest_0103, Function | SmallTest | Level1) { // create wantagent - std::shared_ptr agent = std::make_shared(); + std::shared_ptr agent = + std::make_shared(); // subscriber auto subscriber = new TestAnsSubscriber(); @@ -1648,7 +1652,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0105, Function | SmallTest | Level1) HWTEST_F(AnsModuleTest, AnsModuleTest_0106, Function | SmallTest | Level1) { // create wantagent - std::shared_ptr agent = std::make_shared(); + std::shared_ptr agent = + std::make_shared(); // subscriber auto subscriber = new TestAnsSubscriber(); diff --git a/test/resource/ansSTSlotGroupTest/BUILD.gn b/test/resource/ansSTSlotGroupTest/BUILD.gn index 4747485ba..df98efbd1 100644 --- a/test/resource/ansSTSlotGroupTest/BUILD.gn +++ b/test/resource/ansSTSlotGroupTest/BUILD.gn @@ -48,7 +48,6 @@ ohos_shared_library("libraryAnsSTSlotGroupTest") { deps = [ "${core_path}:ans_core", "${frameworks_path}/ans/native:ans_innerkits", - "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native", "//foundation/appexecfwk/standard/common:libappexecfwk_common", "//foundation/appexecfwk/standard/services/bundlemgr:libbms", @@ -58,6 +57,7 @@ ohos_shared_library("libraryAnsSTSlotGroupTest") { external_deps = [ "ability_base:want", "ability_runtime:abilitykit_native", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "hiviewdfx_hilog_native:libhilog", diff --git a/test/resource/notificationfuzztest/include/notificationgetparam.h b/test/resource/notificationfuzztest/include/notificationgetparam.h index 1b7a14b7d..73b884065 100644 --- a/test/resource/notificationfuzztest/include/notificationgetparam.h +++ b/test/resource/notificationfuzztest/include/notificationgetparam.h @@ -111,19 +111,19 @@ OHOS::Notification::NotificationSlot::NotificationLevel GetParamNotificationLeve std::shared_ptr GetParamNotificationSubscriber(); std::shared_ptr GetParamNotificationSubscribeInfo(); -std::shared_ptr GetParamWantAgentInfo(); -OHOS::Notification::WantAgent::WantAgentConstant::OperationType GetParamOperationType(); -OHOS::Notification::WantAgent::WantAgentConstant::Flags GetParamFlags(); -std::vector GetParamFlagsVector(); +std::shared_ptr GetParamWantAgentInfo(); +OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType GetParamOperationType(); +OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags GetParamFlags(); +std::vector GetParamFlagsVector(); std::shared_ptr GetParamNotification(); sptr GetParamNotificationSptr(); std::vector> GetParamNotificationSptrVector(); -std::shared_ptr GetParamPendingWant(); -std::shared_ptr GetParamWantAgent(); -std::shared_ptr GetParamCompletedCallback(); -std::shared_ptr GetParamTriggerInfo(); -std::shared_ptr GetParamCancelListener(); +std::shared_ptr GetParamPendingWant(); +std::shared_ptr GetParamWantAgent(); +std::shared_ptr GetParamCompletedCallback(); +std::shared_ptr GetParamTriggerInfo(); +std::shared_ptr GetParamCancelListener(); std::shared_ptr GetParamLauncherService(); std::vector GetParamLauncherAbilityInfoVector(); @@ -251,13 +251,13 @@ public: static std::mutex mutex; }; -class TestCompletedCallback : public OHOS::Notification::WantAgent::CompletedCallback { +class TestCompletedCallback : public OHOS::AbilityRuntime::WantAgent::CompletedCallback { void OnSendFinished(const AAFwk::Want &want, int resultCode, const std::string &resultData, const AAFwk::WantParams &resultExtras) override {} }; -class TestCancelListener : public OHOS::Notification::WantAgent::CancelListener { +class TestCancelListener : public OHOS::AbilityRuntime::WantAgent::CancelListener { public: void OnCancelled(int resultCode) override {} diff --git a/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp b/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp index 01bdfbd97..bb4702414 100644 --- a/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp +++ b/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp @@ -511,67 +511,72 @@ void NotificationFuzzTestManager::RegisterWantAgentHelper() { callFunctionMap_.emplace("WantAgentHelperGetWantAgentAppExecFwkparamsInfo", []() { std::shared_ptr context = OHOS::AbilityRuntime::Context::GetApplicationContext(); - const OHOS::Notification::WantAgent::WantAgentInfo paramsInfo = *GetParamWantAgentInfo(); - OHOS::Notification::WantAgent::WantAgentHelper::GetWantAgent(context, paramsInfo); + const OHOS::AbilityRuntime::WantAgent::WantAgentInfo paramsInfo = *GetParamWantAgentInfo(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(context, paramsInfo); }); callFunctionMap_.emplace("WantAgentHelperGetWantAgentparamsInfo", []() { - const OHOS::Notification::WantAgent::WantAgentInfo paramsInfo = *GetParamWantAgentInfo(); - OHOS::Notification::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); + const OHOS::AbilityRuntime::WantAgent::WantAgentInfo paramsInfo = *GetParamWantAgentInfo(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo); }); callFunctionMap_.emplace("WantAgentHelperGetType", []() { - const std::shared_ptr agent = GetParamWantAgent(); - OHOS::Notification::WantAgent::WantAgentHelper::GetType(agent); + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper::GetType(agent); }); callFunctionMap_.emplace("WantAgentHelperTriggerWantAgent", []() { - const std::shared_ptr agent = GetParamWantAgent(); - const std::shared_ptr callback = GetParamCompletedCallback(); - OHOS::Notification::WantAgent::TriggerInfo paramsInfo(*GetParamTriggerInfo()); - OHOS::Notification::WantAgent::WantAgentHelper::TriggerWantAgent(agent, callback, paramsInfo); + const std::shared_ptr agent = GetParamWantAgent(); + const std::shared_ptr callback = + GetParamCompletedCallback(); + OHOS::AbilityRuntime::WantAgent::TriggerInfo paramsInfo(*GetParamTriggerInfo()); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper::TriggerWantAgent(agent, callback, paramsInfo); }); callFunctionMap_.emplace("WantAgentHelperCancel", []() { - const std::shared_ptr agent = GetParamWantAgent(); - OHOS::Notification::WantAgent::WantAgentHelper::Cancel(agent); + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper::Cancel(agent); }); callFunctionMap_.emplace("WantAgentHelperJudgeEquality", []() { - const std::shared_ptr agent = GetParamWantAgent(); - const std::shared_ptr otherAgent = GetParamWantAgent(); - OHOS::Notification::WantAgent::WantAgentHelper::JudgeEquality(agent, otherAgent); + const std::shared_ptr agent = GetParamWantAgent(); + const std::shared_ptr otherAgent + = GetParamWantAgent(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper::JudgeEquality(agent, otherAgent); }); callFunctionMap_.emplace("WantAgentHelperGetHashCode", []() { - const std::shared_ptr agent = GetParamWantAgent(); - OHOS::Notification::WantAgent::WantAgentHelper::GetHashCode(agent); + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper::GetHashCode(agent); }); callFunctionMap_.emplace("WantAgentHelperGetBundleName", []() { - const std::shared_ptr agent = GetParamWantAgent(); - OHOS::Notification::WantAgent::WantAgentHelper::GetBundleName(agent); + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper::GetBundleName(agent); }); callFunctionMap_.emplace("WantAgentHelperGetUid", []() { - const std::shared_ptr agent = GetParamWantAgent(); - OHOS::Notification::WantAgent::WantAgentHelper::GetUid(agent); + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper::GetUid(agent); }); callFunctionMap_.emplace("WantAgentHelperGetWant", []() { - const std::shared_ptr agent = GetParamWantAgent(); - OHOS::Notification::WantAgent::WantAgentHelper::GetWant(agent); + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper::GetWant(agent); }); callFunctionMap_.emplace("WantAgentHelperRegisterCancelListener", []() { - const std::shared_ptr cancelListener; - const std::shared_ptr agent = GetParamWantAgent(); - OHOS::Notification::WantAgent::WantAgentHelper::RegisterCancelListener(cancelListener, agent); + const std::shared_ptr cancelListener; + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper:: + RegisterCancelListener(cancelListener, agent); }); callFunctionMap_.emplace("WantAgentHelperUnregisterCancelListener", []() { - const std::shared_ptr cancelListener = GetParamCancelListener(); - const std::shared_ptr agent = GetParamWantAgent(); - OHOS::Notification::WantAgent::WantAgentHelper::UnregisterCancelListener(cancelListener, agent); + const std::shared_ptr cancelListener + = GetParamCancelListener(); + const std::shared_ptr agent = GetParamWantAgent(); + OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgentHelper:: + UnregisterCancelListener(cancelListener, agent); }); } diff --git a/test/resource/notificationfuzztest/src/notificationgetparam.cpp b/test/resource/notificationfuzztest/src/notificationgetparam.cpp index a1c6578aa..99c54eae6 100644 --- a/test/resource/notificationfuzztest/src/notificationgetparam.cpp +++ b/test/resource/notificationfuzztest/src/notificationgetparam.cpp @@ -693,98 +693,98 @@ std::shared_ptr GetParamNotificat return std::make_shared(); } -std::shared_ptr GetParamWantAgentInfo() +std::shared_ptr GetParamWantAgentInfo() { switch (GetIntParam() % INDEX_THREE) { case INDEX_ZERO: - return std::make_shared(); + return std::make_shared(); break; case INDEX_ONE: { std::vector> param = GetParamWantVector(); - return std::make_shared( + return std::make_shared( GetIntParam(), GetParamOperationType(), GetParamFlags(), param, GetParamWantParams()); } break; case INDEX_TWO: { std::vector> param = GetParamWantVector(); - return std::make_shared( + return std::make_shared( GetIntParam(), GetParamOperationType(), GetParamFlagsVector(), param, GetParamWantParams()); } break; default: - return std::make_shared(); + return std::make_shared(); break; } } -OHOS::Notification::WantAgent::WantAgentConstant::OperationType GetParamOperationType() +OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType GetParamOperationType() { switch (GetIntParam() % INDEX_SIX) { case INDEX_ZERO: - return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE; break; case INDEX_ONE: - return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_ABILITY; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITY; break; case INDEX_TWO: - return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_ABILITIES; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITIES; break; case INDEX_THREE: - return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_SERVICE; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_SERVICE; break; case INDEX_FOUR: - return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT; break; case INDEX_FIVE: - return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; break; default: - return OHOS::Notification::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType::UNKNOWN_TYPE; break; } } -OHOS::Notification::WantAgent::WantAgentConstant::Flags GetParamFlags() +OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags GetParamFlags() { switch (GetIntParam() % INDEX_TEN) { case INDEX_ZERO: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG; break; case INDEX_ONE: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::NO_BUILD_FLAG; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::NO_BUILD_FLAG; break; case INDEX_TWO: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::CANCEL_PRESENT_FLAG; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::CANCEL_PRESENT_FLAG; break; case INDEX_THREE: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG; break; case INDEX_FOUR: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::CONSTANT_FLAG; break; case INDEX_FIVE: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_ELEMENT; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_ELEMENT; break; case INDEX_SIX: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_ACTION; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_ACTION; break; case INDEX_SEVEN: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_URI; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_URI; break; case INDEX_EIGHT: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_ENTITIES; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_ENTITIES; break; case INDEX_NINE: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::REPLACE_BUNDLE; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::REPLACE_BUNDLE; break; default: - return OHOS::Notification::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG; + return OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags::ONE_TIME_FLAG; break; } } -std::vector GetParamFlagsVector() +std::vector GetParamFlagsVector() { - vector param; + vector param; size_t len = GenRandom(0, MAX_LENGTH); while (len--) { - OHOS::Notification::WantAgent::WantAgentConstant::Flags t = GetParamFlags(); + OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags t = GetParamFlags(); param.push_back(t); } return param; @@ -813,38 +813,38 @@ std::vector> GetParamNotificationSptrVect } return param; } -std::shared_ptr GetParamPendingWant() +std::shared_ptr GetParamPendingWant() { sptr target = new WantSender(); sptr whitelistToken = GetParamSptrRemote(); if (GetBoolParam()) { - return std::make_shared(target); + return std::make_shared(target); } else { - return std::make_shared(target, whitelistToken); + return std::make_shared(target, whitelistToken); } } -std::shared_ptr GetParamWantAgent() +std::shared_ptr GetParamWantAgent() { if (GetBoolParam()) { - return std::make_shared(); + return std::make_shared(); } else { - return std::make_shared(GetParamPendingWant()); + return std::make_shared(GetParamPendingWant()); } } -std::shared_ptr GetParamCompletedCallback() +std::shared_ptr GetParamCompletedCallback() { return std::make_shared(); } -std::shared_ptr GetParamTriggerInfo() +std::shared_ptr GetParamTriggerInfo() { if (GetBoolParam()) { - return std::make_shared(); + return std::make_shared(); } else { - return std::make_shared( + return std::make_shared( GetStringParam(), GetParamWantParams(), GetParamWant(), GetIntParam()); } } -std::shared_ptr GetParamCancelListener() +std::shared_ptr GetParamCancelListener() { return std::make_shared(); } diff --git a/test/systemtest/acts/ansDump/BUILD.gn b/test/systemtest/acts/ansDump/BUILD.gn index b1a3dde29..34a487248 100644 --- a/test/systemtest/acts/ansDump/BUILD.gn +++ b/test/systemtest/acts/ansDump/BUILD.gn @@ -34,13 +34,13 @@ ohos_systemtest("AnsDumpTest") { deps = [ "${frameworks_path}/ans/core:ans_core", - "${frameworks_path}/wantagent:wantagent_innerkits", "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] external_deps = [ "ability_base:want", + "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_core", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/tools/dump/BUILD.gn b/tools/dump/BUILD.gn index 45d2a10bb..e89422237 100644 --- a/tools/dump/BUILD.gn +++ b/tools/dump/BUILD.gn @@ -39,7 +39,7 @@ ohos_executable("anm") { configs = [ "${core_path}:public_ans_core_config", - "${frameworks_path}/wantagent:wantagent_innerkits_public_config", + "//foundation/aafwk/standard/frameworks/kits/wantagent:wantagent_innerkits_public_config", ] defines = [] -- Gitee