From 0b0cff6528de8f3f9f25ad9514f9bd611c1f067a Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Sat, 18 Dec 2021 11:24:51 +0000 Subject: [PATCH 1/2] Conversational Notification and code format Signed-off-by: zhaoyuan17 --- .../ans/core/include/ans_manager_interface.h | 2 +- .../ans/core/include/ans_notification.h | 6 - frameworks/ans/core/src/ans_notification.cpp | 2 - frameworks/ans/native/BUILD.gn | 0 frameworks/ans/native/src/message_user.cpp | 16 +- frameworks/ans/native/src/notification.cpp | 2 +- .../native/src/notification_action_button.cpp | 52 +++- .../native/src/notification_bundle_option.cpp | 5 +- .../ans/native/src/notification_content.cpp | 88 ++---- .../notification_conversational_content.cpp | 21 +- .../notification_conversational_message.cpp | 12 +- .../src/notification_do_not_disturb_date.cpp | 9 +- .../src/notification_long_text_content.cpp | 10 +- .../native/src/notification_media_content.cpp | 10 +- .../src/notification_multiline_content.cpp | 9 +- .../src/notification_normal_content.cpp | 4 +- .../src/notification_picture_content.cpp | 9 +- .../ans/native/src/notification_request.cpp | 84 +++--- .../ans/native/src/notification_slot.cpp | 31 +- .../native/src/notification_slot_group.cpp | 14 +- .../ans/native/src/notification_sorting.cpp | 24 +- .../native/src/notification_sorting_map.cpp | 22 +- .../src/notification_subscribe_info.cpp | 11 +- .../native/src/notification_user_input.cpp | 59 ++-- frameworks/ans/test/moduletest/BUILD.gn | 0 .../ans_innerkits_module_publish_test.cpp | 14 +- .../mock/include/mock_ipc_skeleton.h | 0 .../wantagent/src/want_agent_helper.cpp | 10 +- .../ans/native/include/notification.h | 3 - .../include/notification_action_button.h | 24 +- .../include/notification_bundle_option.h | 1 - .../native/include/notification_constant.h | 2 +- .../ans/native/include/notification_content.h | 10 +- .../notification_conversational_content.h | 3 - .../notification_conversational_message.h | 2 - .../ans/native/include/notification_helper.h | 2 +- .../include/notification_long_text_content.h | 2 - .../include/notification_media_content.h | 3 - .../include/notification_multiline_content.h | 2 - .../include/notification_normal_content.h | 1 - .../include/notification_picture_content.h | 4 +- .../ans/native/include/notification_request.h | 13 +- .../ans/native/include/notification_slot.h | 2 - .../native/include/notification_slot_group.h | 2 - .../ans/native/include/notification_sorting.h | 3 - .../native/include/notification_sorting_map.h | 4 - .../include/notification_subscribe_info.h | 4 - .../native/include/notification_subscriber.h | 2 - .../native/include/notification_user_input.h | 45 ++- interfaces/kits/napi/ans/BUILD.gn | 0 interfaces/kits/napi/ans/include/common.h | 19 +- interfaces/kits/napi/ans/include/constant.h | 5 +- interfaces/kits/napi/ans/include/publish.h | 1 - interfaces/kits/napi/ans/src/cancel.cpp | 22 +- interfaces/kits/napi/ans/src/common.cpp | 82 ++--- interfaces/kits/napi/ans/src/constant.cpp | 1 - .../kits/napi/ans/src/display_badge.cpp | 104 +++---- interfaces/kits/napi/ans/src/disturb_mode.cpp | 8 +- .../kits/napi/ans/src/enable_notification.cpp | 133 +++++---- interfaces/kits/napi/ans/src/publish.cpp | 11 +- interfaces/kits/napi/ans/src/remove.cpp | 103 +++---- interfaces/kits/napi/ans/src/slot.cpp | 282 +++++++++--------- interfaces/kits/napi/ans/src/subscribe.cpp | 18 +- interfaces/kits/napi/ans/src/unsubscribe.cpp | 10 +- sa_profile/3203.xml | 0 services/ans/test/unittest/mock/blob.cpp | 0 .../unittest/mock/include/mock_ipc_skeleton.h | 0 services/test/moduletest/mock/blob.cpp | 0 .../acts/actsnotificationfuzztest/BUILD.gn | 0 .../ansSlotGroupHap/AnsSTSlotGroupTest.hap | Bin 70 files changed, 726 insertions(+), 733 deletions(-) mode change 100755 => 100644 frameworks/ans/native/BUILD.gn mode change 100755 => 100644 frameworks/ans/test/moduletest/BUILD.gn mode change 100755 => 100644 frameworks/ans/test/moduletest/mock/include/mock_ipc_skeleton.h mode change 100755 => 100644 interfaces/kits/napi/ans/BUILD.gn mode change 100755 => 100644 sa_profile/3203.xml mode change 100755 => 100644 services/ans/test/unittest/mock/blob.cpp mode change 100755 => 100644 services/ans/test/unittest/mock/include/mock_ipc_skeleton.h mode change 100755 => 100644 services/test/moduletest/mock/blob.cpp mode change 100755 => 100644 test/common/acts/actsnotificationfuzztest/BUILD.gn mode change 100755 => 100644 test/resource/ansSlotGroupHap/AnsSTSlotGroupTest.hap diff --git a/frameworks/ans/core/include/ans_manager_interface.h b/frameworks/ans/core/include/ans_manager_interface.h index 8513f4fc5..be9a8b105 100644 --- a/frameworks/ans/core/include/ans_manager_interface.h +++ b/frameworks/ans/core/include/ans_manager_interface.h @@ -27,7 +27,6 @@ #include "notification_request.h" #include "notification_slot.h" #include "notification_slot_group.h" -#include "notification_sorting.h" #include "notification_subscribe_info.h" namespace OHOS { @@ -106,6 +105,7 @@ public: virtual ErrCode SetDoNotDisturbDate(const sptr &date) = 0; virtual ErrCode GetDoNotDisturbDate(sptr &date) = 0; virtual ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) = 0; + virtual ErrCode CancelGroup(const std::string &groupName) = 0; virtual ErrCode RemoveGroupByBundle( const sptr &bundleOption, const std::string &groupName) = 0; diff --git a/frameworks/ans/core/include/ans_notification.h b/frameworks/ans/core/include/ans_notification.h index f95a82d62..e030626c5 100644 --- a/frameworks/ans/core/include/ans_notification.h +++ b/frameworks/ans/core/include/ans_notification.h @@ -20,12 +20,6 @@ #include "ans_manager_death_recipient.h" #include "ans_manager_interface.h" -#include "notification_bundle_option.h" -#include "notification_do_not_disturb_date.h" -#include "notification_request.h" -#include "notification_slot.h" -#include "notification_slot_group.h" -#include "notification_sorting_map.h" #include "notification_subscriber.h" namespace OHOS { diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index 2e8b48018..f6d751e3e 100644 --- a/frameworks/ans/core/src/ans_notification.cpp +++ b/frameworks/ans/core/src/ans_notification.cpp @@ -18,8 +18,6 @@ #include "ans_inner_errors.h" #include "ans_log_wrapper.h" #include "iservice_registry.h" -#include "notification_request.h" -#include "notification_sorting.h" #include "system_ability_definition.h" namespace OHOS { diff --git a/frameworks/ans/native/BUILD.gn b/frameworks/ans/native/BUILD.gn old mode 100755 new mode 100644 diff --git a/frameworks/ans/native/src/message_user.cpp b/frameworks/ans/native/src/message_user.cpp index 4e1632abd..82a642514 100644 --- a/frameworks/ans/native/src/message_user.cpp +++ b/frameworks/ans/native/src/message_user.cpp @@ -88,12 +88,14 @@ bool MessageUser::IsUserImportant() const std::string MessageUser::Dump() const { - return "MessageUser[key = " + key_ + - ", name = " + name_ + - ", pixelMap = " + (pixelMap_ ? "not null" : "null") + - ", uri = " + uri_.ToString() + - ", isMachine = " + (isMachine_ ? "true" : "false") + - ", isUserImportant = " + (isUserImportant_ ? "true" : "false") + "]"; + return "MessageUser{ " + "key = " + key_ + + ", name = " + name_ + + ", pixelMap = " + (pixelMap_ ? "not null" : "null") + + ", uri = " + uri_.ToString() + + ", isMachine = " + (isMachine_ ? "true" : "false") + + ", isUserImportant = " + (isUserImportant_ ? "true" : "false") + + " }"; } bool MessageUser::Marshalling(Parcel &parcel) const @@ -181,7 +183,7 @@ bool MessageUser::ReadFromParcel(Parcel &parcel) MessageUser *MessageUser::Unmarshalling(Parcel &parcel) { - MessageUser *messageUser = new MessageUser(); + MessageUser *messageUser = new (std::nothrow) MessageUser(); if (messageUser && !messageUser->ReadFromParcel(parcel)) { delete messageUser; diff --git a/frameworks/ans/native/src/notification.cpp b/frameworks/ans/native/src/notification.cpp index 77b1f58b4..40636e8c9 100644 --- a/frameworks/ans/native/src/notification.cpp +++ b/frameworks/ans/native/src/notification.cpp @@ -309,7 +309,7 @@ void Notification::ReadFromParcelString(Parcel &parcel) { // Read key_ key_ = parcel.ReadString(); - + // Read sound_ if (enableSound_) { sound_ = std::make_shared(parcel.ReadString()); diff --git a/frameworks/ans/native/src/notification_action_button.cpp b/frameworks/ans/native/src/notification_action_button.cpp index 94cd2a724..b129a547a 100644 --- a/frameworks/ans/native/src/notification_action_button.cpp +++ b/frameworks/ans/native/src/notification_action_button.cpp @@ -21,7 +21,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::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, + const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, const std::vector> &userInputs, bool isContextual) { @@ -32,9 +32,9 @@ std::shared_ptr NotificationActionButton::Create(const auto realExtras = extras; if (!realExtras) { - realExtras = std::make_shared(); + realExtras = std::make_shared(); if (!realExtras) { - ANS_LOGE("create PacMap object failed"); + ANS_LOGE("create WantParams object failed"); return {}; } } @@ -86,7 +86,7 @@ std::shared_ptr NotificationActionButton::Create( NotificationActionButton::NotificationActionButton(const std::shared_ptr &icon, const std::string &title, const std::shared_ptr &wantAgent, - const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, + const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, const std::vector> &userInputs, bool isContextual) : icon_(icon), @@ -115,12 +115,14 @@ const std::shared_ptr NotificationActionButton::GetWantAge return wantAgent_; } -void NotificationActionButton::AddAdditionalData(AppExecFwk::PacMap &pacMap) +void NotificationActionButton::AddAdditionalData(AAFwk::WantParams &extras) { - extras_->PutAll(pacMap); + if (extras_) { + *extras_ = extras; + } } -const std::shared_ptr NotificationActionButton::GetAdditionalData() const +const std::shared_ptr NotificationActionButton::GetAdditionalData() const { return extras_; } @@ -192,10 +194,34 @@ bool NotificationActionButton::IsContextDependent() const std::string NotificationActionButton::Dump() { - return "NotificationActionButton[ title = " + title_ + - ", semanticActionButton = " + std::to_string(static_cast(semanticActionButton_)) + - ", autoCreatedReplies = " + (autoCreatedReplies_ ? "true" : "false") + - ", isContextual = " + (isContextual_ ? "true" : "false") + " ]"; + std::string mimeTypeOnlyUserInputs = ""; + for (auto &item : mimeTypeOnlyUserInputs_) { + if (!item) { + mimeTypeOnlyUserInputs += "nullptr, "; + continue; + } + mimeTypeOnlyUserInputs += item->Dump(); + mimeTypeOnlyUserInputs += ", "; + } + + std::string userInputs = ""; + for (auto &item : userInputs_) { + if (!item) { + userInputs += "nullptr, "; + continue; + } + userInputs += item->Dump(); + userInputs += ", "; + } + + return "NotificationActionButton{ " + "title = " + title_ + + ", semanticActionButton = " + std::to_string(static_cast(semanticActionButton_)) + + ", autoCreatedReplies = " + (autoCreatedReplies_ ? "true" : "false") + + ", isContextual = " + (isContextual_ ? "true" : "false") + + ", mimeTypeOnlyUserInputs = [" + mimeTypeOnlyUserInputs + "]" + + ", userInputs = [" + userInputs + "]" + + " }"; } bool NotificationActionButton::Marshalling(Parcel &parcel) const @@ -286,7 +312,7 @@ bool NotificationActionButton::Marshalling(Parcel &parcel) const NotificationActionButton *NotificationActionButton::Unmarshalling(Parcel &parcel) { - auto pButton = new NotificationActionButton(); + auto pButton = new (std::nothrow) NotificationActionButton(); if ((pButton != nullptr) && !pButton->ReadFromParcel(parcel)) { delete pButton; pButton = nullptr; @@ -330,7 +356,7 @@ bool NotificationActionButton::ReadFromParcel(Parcel &parcel) valid = parcel.ReadBool(); if (valid) { - extras_ = std::shared_ptr(parcel.ReadParcelable()); + extras_ = std::shared_ptr(parcel.ReadParcelable()); if (!extras_) { ANS_LOGE("Failed to read extras"); return false; diff --git a/frameworks/ans/native/src/notification_bundle_option.cpp b/frameworks/ans/native/src/notification_bundle_option.cpp index 4269aca2b..402d186d8 100644 --- a/frameworks/ans/native/src/notification_bundle_option.cpp +++ b/frameworks/ans/native/src/notification_bundle_option.cpp @@ -47,7 +47,10 @@ int32_t NotificationBundleOption::GetUid() const std::string NotificationBundleOption::Dump() { - return "NotificationBundleOption[ bundleName = " + bundleName_ + ", uid = " + std::to_string(uid_) + " ]"; + return "NotificationBundleOption{ " + "bundleName = " + bundleName_ + + ", uid = " + std::to_string(uid_) + + " }"; } bool NotificationBundleOption::Marshalling(Parcel &parcel) const diff --git a/frameworks/ans/native/src/notification_content.cpp b/frameworks/ans/native/src/notification_content.cpp index 5f302bb59..f76e41ef4 100644 --- a/frameworks/ans/native/src/notification_content.cpp +++ b/frameworks/ans/native/src/notification_content.cpp @@ -106,8 +106,10 @@ std::string NotificationContent::Dump() : (contentType_ == NotificationContent::Type::MULTILINE) ? "MULTILINE" : (contentType_ == NotificationContent::Type::PICTURE) ? "PICTURE" : "NONE"; - return "NotificationContent[ contentType = " + contentTypeStr + - ", content = " + (content_ ? "not null" : "null") + "]"; + return "NotificationContent{ " + "contentType = " + contentTypeStr + + ", content = " + (content_ ? content_->Dump() : "null") + + " }"; } bool NotificationContent::Marshalling(Parcel &parcel) const @@ -135,7 +137,7 @@ bool NotificationContent::Marshalling(Parcel &parcel) const NotificationContent *NotificationContent::Unmarshalling(Parcel &parcel) { - auto pContent = new NotificationContent(); + auto pContent = new (std::nothrow) NotificationContent(); if ((pContent != nullptr) && !pContent->ReadFromParcel(parcel)) { delete pContent; pContent = nullptr; @@ -154,68 +156,38 @@ bool NotificationContent::ReadFromParcel(Parcel &parcel) } switch (contentType_) { - case NotificationContent::Type::BASIC_TEXT: { - std::shared_ptr normalContent( - parcel.ReadParcelable()); - if (!normalContent) { - ANS_LOGE("Failed to read normal content"); - return false; - } - content_ = std::dynamic_pointer_cast(normalContent); + case NotificationContent::Type::BASIC_TEXT: + content_ = std::static_pointer_cast( + std::shared_ptr(parcel.ReadParcelable())); break; - } - case NotificationContent::Type::CONVERSATION: { - std::shared_ptr conversationalContent( - parcel.ReadParcelable()); - if (!conversationalContent) { - ANS_LOGE("Failed to read conversational content"); - return false; - } - content_ = std::dynamic_pointer_cast(conversationalContent); + case NotificationContent::Type::CONVERSATION: + content_ = + std::static_pointer_cast(std::shared_ptr( + parcel.ReadParcelable())); break; - } - case NotificationContent::Type::LONG_TEXT: { - std::shared_ptr longTextContent( - parcel.ReadParcelable()); - if (!longTextContent) { - ANS_LOGE("Failed to read long text content"); - return false; - } - content_ = std::dynamic_pointer_cast(longTextContent); + case NotificationContent::Type::LONG_TEXT: + content_ = std::static_pointer_cast( + std::shared_ptr(parcel.ReadParcelable())); break; - } - case NotificationContent::Type::MEDIA: { - std::shared_ptr mediaContent(parcel.ReadParcelable()); - if (!mediaContent) { - ANS_LOGE("Failed to read media content"); - return false; - } - content_ = std::dynamic_pointer_cast(mediaContent); + case NotificationContent::Type::MEDIA: + content_ = std::static_pointer_cast( + std::shared_ptr(parcel.ReadParcelable())); break; - } - case NotificationContent::Type::MULTILINE: { - std::shared_ptr multiLineContent( - parcel.ReadParcelable()); - if (!multiLineContent) { - ANS_LOGE("Failed to read multiLine content"); - return false; - } - content_ = std::dynamic_pointer_cast(multiLineContent); + case NotificationContent::Type::MULTILINE: + content_ = std::static_pointer_cast( + std::shared_ptr(parcel.ReadParcelable())); break; - } - case NotificationContent::Type::PICTURE: { - std::shared_ptr pictureContent( - parcel.ReadParcelable()); - if (!pictureContent) { - ANS_LOGE("Failed to read picture content"); - return false; - } - content_ = std::dynamic_pointer_cast(pictureContent); + case NotificationContent::Type::PICTURE: + content_ = std::static_pointer_cast( + std::shared_ptr(parcel.ReadParcelable())); break; - } - default: { + default: + ANS_LOGE("Invalid contentType"); return false; - } + } + if (!content_) { + ANS_LOGE("Failed to read content"); + return false; } return true; diff --git a/frameworks/ans/native/src/notification_conversational_content.cpp b/frameworks/ans/native/src/notification_conversational_content.cpp index 102a98424..137851332 100644 --- a/frameworks/ans/native/src/notification_conversational_content.cpp +++ b/frameworks/ans/native/src/notification_conversational_content.cpp @@ -76,10 +76,21 @@ NotificationConversationalContent::MessageVector NotificationConversationalConte std::string NotificationConversationalContent::Dump() { - return "NotificationConversationalContent[ " + NotificationBasicContent::Dump() + - ", conversationTitle = " + conversationTitle_ + ", isGroup = " + (isGroup_ ? "true" : "false") + - ", messageUser = " + messageUser_.Dump() + - ", messages = " + (!messages_.empty() ? "not empty" : "empty") + " ]"; + std::string messages = ""; + for (auto &message : messages_) { + if (!message) { + messages += "nullptr, "; + continue; + } + messages += message->Dump(); + messages += ", "; + } + return "NotificationConversationalContent{ " + NotificationBasicContent::Dump() + + ", conversationTitle = " + conversationTitle_ + + ", isGroup = " + (isGroup_ ? "true" : "false") + + ", messageUser = " + messageUser_.Dump() + + ", messages = " + messages + + " }"; } bool NotificationConversationalContent::Marshalling(Parcel &parcel) const @@ -132,7 +143,7 @@ bool NotificationConversationalContent::Marshalling(Parcel &parcel) const NotificationConversationalContent *NotificationConversationalContent::Unmarshalling(Parcel &parcel) { - auto pContent = new NotificationConversationalContent(); + auto pContent = new (std::nothrow) NotificationConversationalContent(); if ((pContent != nullptr) && !pContent->ReadFromParcel(parcel)) { delete pContent; pContent = nullptr; diff --git a/frameworks/ans/native/src/notification_conversational_message.cpp b/frameworks/ans/native/src/notification_conversational_message.cpp index 139826a7c..1f385c03b 100644 --- a/frameworks/ans/native/src/notification_conversational_message.cpp +++ b/frameworks/ans/native/src/notification_conversational_message.cpp @@ -56,9 +56,13 @@ const std::shared_ptr NotificationConversationalMessage::GetUri() const std::string NotificationConversationalMessage::Dump() { - return "NotificationConversationalMessage[ text = " + text_ + ", arrivedTime = " + std::to_string(arrivedTime_) + - ", mimeType = " + mimeType_ + ", uri = " + (uri_ ? uri_->ToString() : "null") + - ", sender = " + sender_.Dump() + " ]"; + return "NotificationConversationalMessage{ " + "text = " + text_ + + ", arrivedTime = " + std::to_string(arrivedTime_) + + ", mimeType = " + mimeType_ + + ", uri = " + (uri_ ? uri_->ToString() : "null") + + ", sender = " + sender_.Dump() + + " }"; } bool NotificationConversationalMessage::Marshalling(Parcel &parcel) const @@ -101,7 +105,7 @@ bool NotificationConversationalMessage::Marshalling(Parcel &parcel) const NotificationConversationalMessage *NotificationConversationalMessage::Unmarshalling(Parcel &parcel) { - auto pMessage = new NotificationConversationalMessage(); + auto pMessage = new (std::nothrow) NotificationConversationalMessage(); if ((pMessage != nullptr) && !pMessage->ReadFromParcel(parcel)) { delete pMessage; pMessage = nullptr; diff --git a/frameworks/ans/native/src/notification_do_not_disturb_date.cpp b/frameworks/ans/native/src/notification_do_not_disturb_date.cpp index 4492263fe..188018fd5 100644 --- a/frameworks/ans/native/src/notification_do_not_disturb_date.cpp +++ b/frameworks/ans/native/src/notification_do_not_disturb_date.cpp @@ -55,10 +55,11 @@ int64_t NotificationDoNotDisturbDate::GetEndDate() const std::string NotificationDoNotDisturbDate::Dump() { - return "NotificationDoNotDisturbDate[ "\ - "doNotDisturbType = " + std::to_string(static_cast(doNotDisturbType_)) + - ", beginDate = " + std::to_string(beginDate_) + - ", endDate = " + std::to_string(endDate_) + " ]"; + return "NotificationDoNotDisturbDate{ " + "doNotDisturbType = " + std::to_string(static_cast(doNotDisturbType_)) + + ", beginDate = " + std::to_string(beginDate_) + + ", endDate = " + std::to_string(endDate_) + + " }"; } bool NotificationDoNotDisturbDate::Marshalling(Parcel &parcel) const diff --git a/frameworks/ans/native/src/notification_long_text_content.cpp b/frameworks/ans/native/src/notification_long_text_content.cpp index 1ce547bbd..fb305300d 100644 --- a/frameworks/ans/native/src/notification_long_text_content.cpp +++ b/frameworks/ans/native/src/notification_long_text_content.cpp @@ -63,9 +63,11 @@ std::string NotificationLongTextContent::GetLongText() const std::string NotificationLongTextContent::Dump() { - return "NotificationLongTextContent[ " + NotificationBasicContent::Dump() + - " longText = " + longText_ + " briefText = " + briefText_ + - " expandedTitle = " + expandedTitle_ + " ]"; + return "NotificationLongTextContent{ " + NotificationBasicContent::Dump() + + ", longText = " + longText_ + + ", briefText = " + briefText_ + + ", expandedTitle = " + expandedTitle_ + + " }"; } bool NotificationLongTextContent::Marshalling(Parcel &parcel) const @@ -95,7 +97,7 @@ bool NotificationLongTextContent::Marshalling(Parcel &parcel) const NotificationLongTextContent *NotificationLongTextContent::Unmarshalling(Parcel &parcel) { - auto pContent = new NotificationLongTextContent(); + auto pContent = new (std::nothrow) NotificationLongTextContent(); if ((pContent != nullptr) && !pContent->ReadFromParcel(parcel)) { delete pContent; pContent = nullptr; diff --git a/frameworks/ans/native/src/notification_media_content.cpp b/frameworks/ans/native/src/notification_media_content.cpp index 252240bc4..e1c303d89 100644 --- a/frameworks/ans/native/src/notification_media_content.cpp +++ b/frameworks/ans/native/src/notification_media_content.cpp @@ -42,11 +42,13 @@ std::string NotificationMediaContent::Dump() { std::string numbers {}; std::for_each(sequenceNumbers_.begin(), sequenceNumbers_.end(), [&numbers](int32_t num) { - numbers += std::to_string(num) + " "; + numbers += std::to_string(num) + ", "; }); - return "NotificationMediaContent[ " + NotificationBasicContent::Dump() + - ", avToken = " + (avToken_ ? "not null" : "null") + ", sequenceNumbers = " + numbers + " ]"; + return "NotificationMediaContent{ " + NotificationBasicContent::Dump() + + ", avToken = " + (avToken_ ? "not null" : "null") + + ", sequenceNumbers = " + numbers + + " }"; } bool NotificationMediaContent::Marshalling(Parcel &parcel) const @@ -66,7 +68,7 @@ bool NotificationMediaContent::Marshalling(Parcel &parcel) const NotificationMediaContent *NotificationMediaContent::Unmarshalling(Parcel &parcel) { - auto pContent = new NotificationMediaContent(); + auto pContent = new (std::nothrow) NotificationMediaContent(); if ((pContent != nullptr) && !pContent->ReadFromParcel(parcel)) { delete pContent; pContent = nullptr; diff --git a/frameworks/ans/native/src/notification_multiline_content.cpp b/frameworks/ans/native/src/notification_multiline_content.cpp index d20acf486..320c23bd5 100644 --- a/frameworks/ans/native/src/notification_multiline_content.cpp +++ b/frameworks/ans/native/src/notification_multiline_content.cpp @@ -63,8 +63,11 @@ std::string NotificationMultiLineContent::Dump() allLines_.begin(), allLines_.end(), [&lines](const std::string &line) { lines += " " + line + ","; }); lines.pop_back(); - return "NotificationMultiLineContent[ " + NotificationBasicContent::Dump() + ", briefText = " + briefText_ + - ", expandedTitle = " + expandedTitle_ + ", allLines = [" + lines + " ] ]"; + return "NotificationMultiLineContent{ " + NotificationBasicContent::Dump() + + ", briefText = " + briefText_ + + ", expandedTitle = " + expandedTitle_ + + ", allLines = [" + lines + "]" + + " }"; } bool NotificationMultiLineContent::Marshalling(Parcel &parcel) const @@ -94,7 +97,7 @@ bool NotificationMultiLineContent::Marshalling(Parcel &parcel) const NotificationMultiLineContent *NotificationMultiLineContent::Unmarshalling(Parcel &parcel) { - auto pContent = new NotificationMultiLineContent(); + auto pContent = new (std::nothrow) NotificationMultiLineContent(); if ((pContent != nullptr) && !pContent->ReadFromParcel(parcel)) { delete pContent; pContent = nullptr; diff --git a/frameworks/ans/native/src/notification_normal_content.cpp b/frameworks/ans/native/src/notification_normal_content.cpp index 481c1aa9c..d6743d14f 100644 --- a/frameworks/ans/native/src/notification_normal_content.cpp +++ b/frameworks/ans/native/src/notification_normal_content.cpp @@ -19,7 +19,7 @@ namespace OHOS { namespace Notification { std::string NotificationNormalContent::Dump() { - return "NotificationNormalContent[ " + NotificationBasicContent::Dump() + " ]"; + return "NotificationNormalContent{ " + NotificationBasicContent::Dump() + " }"; } bool NotificationNormalContent::Marshalling(Parcel &parcel) const @@ -29,7 +29,7 @@ bool NotificationNormalContent::Marshalling(Parcel &parcel) const NotificationNormalContent *NotificationNormalContent::Unmarshalling(Parcel &parcel) { - auto pContent = new NotificationNormalContent(); + auto pContent = new (std::nothrow) NotificationNormalContent(); if ((pContent != nullptr) && !pContent->ReadFromParcel(parcel)) { delete pContent; pContent = nullptr; diff --git a/frameworks/ans/native/src/notification_picture_content.cpp b/frameworks/ans/native/src/notification_picture_content.cpp index b2aa8af66..d7e65d4b0 100644 --- a/frameworks/ans/native/src/notification_picture_content.cpp +++ b/frameworks/ans/native/src/notification_picture_content.cpp @@ -50,8 +50,11 @@ const std::shared_ptr NotificationPictureContent::GetBigPicture std::string NotificationPictureContent::Dump() { - return "NotificationPictureContent[ " + NotificationBasicContent::Dump() + ", briefText = " + briefText_ + - ", expandedTitle = " + expandedTitle_ + ", bigPicture = " + (bigPicture_ ? "not null" : "null") + " ]"; + return "NotificationPictureContent{ " + NotificationBasicContent::Dump() + + ", briefText = " + briefText_ + + ", expandedTitle = " + expandedTitle_ + + ", bigPicture = " + (bigPicture_ ? "not null" : "null") + + " }"; } bool NotificationPictureContent::Marshalling(Parcel &parcel) const @@ -89,7 +92,7 @@ bool NotificationPictureContent::Marshalling(Parcel &parcel) const NotificationPictureContent *NotificationPictureContent::Unmarshalling(Parcel &parcel) { - auto pContent = new NotificationPictureContent(); + auto pContent = new (std::nothrow) NotificationPictureContent(); if ((pContent != nullptr) && !pContent->ReadFromParcel(parcel)) { delete pContent; pContent = nullptr; diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index c7a41c8c5..bbf4e1303 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -716,46 +716,48 @@ std::string NotificationRequest::GetLabel() const std::string NotificationRequest::Dump() { - return "NotificationRequest[ notificationId = " + std::to_string(notificationId_) + - ", slotType = " + std::to_string(static_cast(slotType_)) + - ", createTime = " + std::to_string(createTime_) + ", deliveryTime = " + std::to_string(deliveryTime_) + - ", autoDeletedTime = " + std::to_string(autoDeletedTime_) + ", settingsText = " + settingsText_ + - ", creatorBundleName = " + creatorBundleName_ + - ", creatorPid = " + std::to_string(static_cast(creatorPid_)) + - ", creatorUid = " + std::to_string(static_cast(creatorUid_)) + - ", ownerBundleName = " + ownerBundleName_ + ", groupName = " + groupName_ + - ", statusBarText = " + statusBarText_ + ", label = " + label_ + ", shortcutId = " + shortcutId_ + - ", sortingKey = " + sortingKey_ + - ", groupAlertType = " + std::to_string(static_cast(groupAlertType_)) + - ", color = " + std::to_string(color_) + ", badgeNumber = " + std::to_string(badgeNumber_) + - ", visiblenessType = " + std::to_string(static_cast(visiblenessType_)) + - ", progressValue = " + std::to_string(progressValue_) + ", progressMax = " + std::to_string(progressMax_) + - ", badgeStyle = " + std::to_string(static_cast(badgeStyle_)) + - ", classification = " + classification_ + - ", notificationContentType = " + std::to_string(static_cast(notificationContentType_)) + - ", showDeliveryTime = " + (showDeliveryTime_ ? "true" : "false") + - ", tapDismissed = " + (tapDismissed_ ? "true" : "false") + - ", colorEnabled = " + (colorEnabled_ ? "true" : "false") + - ", alertOneTime = " + (alertOneTime_ ? "true" : "false") + - ", showStopwatch = " + (showStopwatch_ ? "true" : "false") + - ", isCountdown = " + (isCountdown_ ? "true" : "false") + - ", inProgress = " + (inProgress_ ? "true" : "false") + - ", groupOverview = " + (groupOverview_ ? "true" : "false") + - ", progressIndeterminate = " + (progressIndeterminate_ ? "true" : "false") + - ", unremovable = " + (unremovable_ ? "true" : "false") + - ", floatingIcon = " + (floatingIcon_ ? "true" : "false") + - ", onlyLocal = " + (onlyLocal_ ? "true" : "false") + ", permitted = " + (permitted_ ? "true" : "false") + - ", context = " + (context_ ? "not null" : "null") + ", wantAgent = " + (wantAgent_ ? "not null" : "null") + - ", removalWantAgent = " + (removalWantAgent_ ? "not null" : "null") + - ", maxScreenWantAgent = " + (maxScreenWantAgent_ ? "not null" : "null") + - ", additionalParams = " + (additionalParams_ ? "not null" : "null") + - ", littleIcon = " + (littleIcon_ ? "not null" : "null") + - ", bigIcon = " + (bigIcon_ ? "not null" : "null") + - ", notificationContent = " + (notificationContent_ ? "not null" : "null") + - ", publicNotification = " + (publicNotification_ ? "not null" : "null") + - ", actionButtons = " + (!actionButtons_.empty() ? "not empty" : "empty") + - ", messageUsers = " + (!messageUsers_.empty() ? "not empty" : "empty") + - ", userInputHistory = " + (!userInputHistory_.empty() ? "not empty" : "empty") + " ]"; + return "NotificationRequest{ " + "notificationId = " + std::to_string(notificationId_) + + ", slotType = " + std::to_string(static_cast(slotType_)) + + ", createTime = " + std::to_string(createTime_) + ", deliveryTime = " + std::to_string(deliveryTime_) + + ", autoDeletedTime = " + std::to_string(autoDeletedTime_) + ", settingsText = " + settingsText_ + + ", creatorBundleName = " + creatorBundleName_ + + ", creatorPid = " + std::to_string(static_cast(creatorPid_)) + + ", creatorUid = " + std::to_string(static_cast(creatorUid_)) + + ", ownerBundleName = " + ownerBundleName_ + ", groupName = " + groupName_ + + ", statusBarText = " + statusBarText_ + ", label = " + label_ + ", shortcutId = " + shortcutId_ + + ", sortingKey = " + sortingKey_ + + ", groupAlertType = " + std::to_string(static_cast(groupAlertType_)) + + ", color = " + std::to_string(color_) + ", badgeNumber = " + std::to_string(badgeNumber_) + + ", visiblenessType = " + std::to_string(static_cast(visiblenessType_)) + + ", progressValue = " + std::to_string(progressValue_) + ", progressMax = " + std::to_string(progressMax_) + + ", badgeStyle = " + std::to_string(static_cast(badgeStyle_)) + + ", classification = " + classification_ + + ", notificationContentType = " + std::to_string(static_cast(notificationContentType_)) + + ", showDeliveryTime = " + (showDeliveryTime_ ? "true" : "false") + + ", tapDismissed = " + (tapDismissed_ ? "true" : "false") + + ", colorEnabled = " + (colorEnabled_ ? "true" : "false") + + ", alertOneTime = " + (alertOneTime_ ? "true" : "false") + + ", showStopwatch = " + (showStopwatch_ ? "true" : "false") + + ", isCountdown = " + (isCountdown_ ? "true" : "false") + + ", inProgress = " + (inProgress_ ? "true" : "false") + + ", groupOverview = " + (groupOverview_ ? "true" : "false") + + ", progressIndeterminate = " + (progressIndeterminate_ ? "true" : "false") + + ", unremovable = " + (unremovable_ ? "true" : "false") + + ", floatingIcon = " + (floatingIcon_ ? "true" : "false") + + ", onlyLocal = " + (onlyLocal_ ? "true" : "false") + ", permitted = " + (permitted_ ? "true" : "false") + + ", context = " + (context_ ? "not null" : "null") + ", wantAgent = " + (wantAgent_ ? "not null" : "null") + + ", removalWantAgent = " + (removalWantAgent_ ? "not null" : "null") + + ", maxScreenWantAgent = " + (maxScreenWantAgent_ ? "not null" : "null") + + ", additionalParams = " + (additionalParams_ ? "not null" : "null") + + ", littleIcon = " + (littleIcon_ ? "not null" : "null") + + ", bigIcon = " + (bigIcon_ ? "not null" : "null") + + ", notificationContent = " + (notificationContent_ ? notificationContent_->Dump() : "null") + + ", publicNotification = " + (publicNotification_ ? "not null" : "null") + + ", actionButtons = " + (!actionButtons_.empty() ? actionButtons_.at(0)->Dump() : "empty") + + ", messageUsers = " + (!messageUsers_.empty() ? messageUsers_.at(0)->Dump() : "empty") + + ", userInputHistory = " + (!userInputHistory_.empty() ? userInputHistory_.at(0) : "empty") + + " }"; } bool NotificationRequest::Marshalling(Parcel &parcel) const @@ -1092,7 +1094,7 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const NotificationRequest *NotificationRequest::Unmarshalling(Parcel &parcel) { - auto objptr = new NotificationRequest(); + auto objptr = new (std::nothrow) NotificationRequest(); if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) { delete objptr; objptr = nullptr; diff --git a/frameworks/ans/native/src/notification_slot.cpp b/frameworks/ans/native/src/notification_slot.cpp index 00f7a5b7c..04f4c9c5a 100644 --- a/frameworks/ans/native/src/notification_slot.cpp +++ b/frameworks/ans/native/src/notification_slot.cpp @@ -202,19 +202,22 @@ void NotificationSlot::EnableBadge(bool isShowBadge) std::string NotificationSlot::Dump() const { - return "NotificationSlot[ id = " + id_ + - ", name = " + name_ + - ", description = " + description_ + - ", type = " + std::to_string(static_cast(type_)) + - ", level = " + std::to_string(static_cast(level_)) + - ", isBypassDnd = " + (isBypassDnd_ ? "true" : "false") + - ", visibleness = " + std::to_string(static_cast(lockScreenVisibleness_)) + - ", sound = " + sound_.ToString() + - ", isLightEnabled = " + (isLightEnabled_ ? "true" : "false") + - ", lightColor = " + std::to_string(lightColor_) + - ", isVibrate = " + (isVibrationEnabled_ ? "true" : "false") + - ", vibration = " + MergeVectorToString(vibrationValues_) + - ", isShowBadge = " + (isShowBadge_ ? "true" : "false") + ", groupId = " + groupId_ + "]"; + return "NotificationSlot{ " + "id = " + id_ + + ", name = " + name_ + + ", description = " + description_ + + ", type = " + std::to_string(static_cast(type_)) + + ", level = " + std::to_string(static_cast(level_)) + + ", isBypassDnd = " + (isBypassDnd_ ? "true" : "false") + + ", visibleness = " + std::to_string(static_cast(lockScreenVisibleness_)) + + ", sound = " + sound_.ToString() + + ", isLightEnabled = " + (isLightEnabled_ ? "true" : "false") + + ", lightColor = " + std::to_string(lightColor_) + + ", isVibrate = " + (isVibrationEnabled_ ? "true" : "false") + + ", vibration = " + MergeVectorToString(vibrationValues_) + + ", isShowBadge = " + (isShowBadge_ ? "true" : "false") + + ", groupId = " + groupId_ + + " }"; } bool NotificationSlot::Marshalling(Parcel &parcel) const @@ -334,7 +337,7 @@ bool NotificationSlot::ReadFromParcel(Parcel &parcel) NotificationSlot *NotificationSlot::Unmarshalling(Parcel &parcel) { - NotificationSlot *notificationSlot = new NotificationSlot(NotificationConstant::SlotType::CUSTOM); + NotificationSlot *notificationSlot = new (std::nothrow) NotificationSlot(NotificationConstant::SlotType::CUSTOM); if (notificationSlot && !notificationSlot->ReadFromParcel(parcel)) { delete notificationSlot; diff --git a/frameworks/ans/native/src/notification_slot_group.cpp b/frameworks/ans/native/src/notification_slot_group.cpp index 89720f812..c870357e0 100644 --- a/frameworks/ans/native/src/notification_slot_group.cpp +++ b/frameworks/ans/native/src/notification_slot_group.cpp @@ -78,11 +78,13 @@ std::string NotificationSlotGroup::Dump() const contents += ","; } } - return "NotificationSlotGroup[id = " + id_ + - ", name = " + name_ + - ", description = " + description_ + - ", slots = " + contents + - ", isDisabled = " + (isDisabled_ ? "true" : "false") + "]"; + return "NotificationSlotGroup{ " + "id = " + id_ + + ", name = " + name_ + + ", description = " + description_ + + ", slots = " + contents + + ", isDisabled = " + (isDisabled_ ? "true" : "false") + + " }"; } bool NotificationSlotGroup::Marshalling(Parcel &parcel) const @@ -150,7 +152,7 @@ bool NotificationSlotGroup::ReadFromParcel(Parcel &parcel) NotificationSlotGroup *NotificationSlotGroup::Unmarshalling(Parcel &parcel) { - NotificationSlotGroup *notificationSlotGroup = new NotificationSlotGroup(); + NotificationSlotGroup *notificationSlotGroup = new (std::nothrow) NotificationSlotGroup(); if (notificationSlotGroup && !notificationSlotGroup->ReadFromParcel(parcel)) { delete notificationSlotGroup; diff --git a/frameworks/ans/native/src/notification_sorting.cpp b/frameworks/ans/native/src/notification_sorting.cpp index fc390cfc0..4e0c41015 100644 --- a/frameworks/ans/native/src/notification_sorting.cpp +++ b/frameworks/ans/native/src/notification_sorting.cpp @@ -53,18 +53,16 @@ void NotificationSorting::SetGroupKeyOverride(const std::string &groupKeyOverrid std::string NotificationSorting::Dump() const { - std::string contents {""}; - if (slot_ != nullptr) { - contents = slot_->Dump(); - } else { - contents = "nullptr"; - } - return "NotificationSorting[key =" + key_ + ", ranking =" + std::to_string(ranking_) + - ", importance =" + std::to_string(importance_) + - ", visiblenessOverride =" + std::to_string(visiblenessOverride_) + - ", isDisplayBadge =" + (isDisplayBadge_ ? "true" : "false") + - ", isHiddenNotification =" + (isHiddenNotification_ ? "true" : "false") + - ", groupKeyOverride =" + groupKeyOverride_ + ", slot_ =" + contents + "]"; + return "NotificationSorting{ " + "key = " + key_ + + ", ranking = " + std::to_string(ranking_) + + ", importance = " + std::to_string(importance_) + + ", visiblenessOverride = " + std::to_string(visiblenessOverride_) + + ", isDisplayBadge = " + (isDisplayBadge_ ? "true" : "false") + + ", isHiddenNotification = " + (isHiddenNotification_ ? "true" : "false") + + ", groupKeyOverride = " + groupKeyOverride_ + + ", slot = " + (slot_ != nullptr ? slot_->Dump() : "nullptr") + + " }"; } bool NotificationSorting::Marshalling(Parcel &parcel) const @@ -143,7 +141,7 @@ bool NotificationSorting::ReadFromParcel(Parcel &parcel) NotificationSorting *NotificationSorting::Unmarshalling(Parcel &parcel) { - NotificationSorting *sorting = new NotificationSorting(); + NotificationSorting *sorting = new (std::nothrow) NotificationSorting(); if (sorting && !sorting->ReadFromParcel(parcel)) { delete sorting; sorting = nullptr; diff --git a/frameworks/ans/native/src/notification_sorting_map.cpp b/frameworks/ans/native/src/notification_sorting_map.cpp index 8e32c8bfe..2bd73d2f5 100644 --- a/frameworks/ans/native/src/notification_sorting_map.cpp +++ b/frameworks/ans/native/src/notification_sorting_map.cpp @@ -93,24 +93,20 @@ NotificationSortingMap *NotificationSortingMap::Unmarshalling(Parcel &parcel) } } - NotificationSortingMap *sortingMap = new NotificationSortingMap(sortings); + NotificationSortingMap *sortingMap = new (std::nothrow) NotificationSortingMap(sortings); return sortingMap; } + std::string NotificationSortingMap::Dump() const { - int keyNum = 0; - std::string separator; - std::string keys = " sortedkey = "; - for (auto item : sortedKey_) { - if (keyNum == 0) { - separator = ""; - } else { - separator = ", "; - } - keys = keys + separator + item; - keyNum++; + std::string keys = ""; + for (auto key : sortedKey_) { + keys += key; + keys += ", "; } - return "NotificationSortingMap[" + keys + "]"; + return "NotificationSortingMap{ " + "sortedkey = [" + keys + "]" + " }"; } } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/native/src/notification_subscribe_info.cpp b/frameworks/ans/native/src/notification_subscribe_info.cpp index 7f4239874..0f70d047c 100644 --- a/frameworks/ans/native/src/notification_subscribe_info.cpp +++ b/frameworks/ans/native/src/notification_subscribe_info.cpp @@ -57,7 +57,7 @@ bool NotificationSubscribeInfo::Marshalling(Parcel &parcel) const NotificationSubscribeInfo *NotificationSubscribeInfo::Unmarshalling(Parcel &parcel) { - NotificationSubscribeInfo *info = new NotificationSubscribeInfo(); + NotificationSubscribeInfo *info = new (std::nothrow) NotificationSubscribeInfo(); if (info && !info->ReadFromParcel(parcel)) { delete info; info = nullptr; @@ -74,7 +74,14 @@ bool NotificationSubscribeInfo::ReadFromParcel(Parcel &parcel) std::string NotificationSubscribeInfo::Dump() { - return "Dump"; + std::string appNames = ""; + for (auto name : appNames_) { + appNames += name; + appNames += ", "; + } + return "NotificationSubscribeInfo{ " + "appNames = [" + appNames + "]" + + " }"; } } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/native/src/notification_user_input.cpp b/frameworks/ans/native/src/notification_user_input.cpp index e8ed66a0f..eb0387fd6 100644 --- a/frameworks/ans/native/src/notification_user_input.cpp +++ b/frameworks/ans/native/src/notification_user_input.cpp @@ -32,10 +32,10 @@ NotificationConstant::InputsSource NotificationUserInput::GetInputsSource(const } void NotificationUserInput::AddInputsToWant(const std::vector> &userInputs, - AAFwk::Want &want, const AppExecFwk::PacMap &pacMap) + AAFwk::Want &want, const AAFwk::WantParams &additional) {} -std::shared_ptr NotificationUserInput::GetInputsFromWant(const AAFwk::Want &want) +std::shared_ptr NotificationUserInput::GetInputsFromWant(const AAFwk::Want &want) { return {}; } @@ -68,7 +68,7 @@ std::shared_ptr NotificationUserInput::Create(const std:: std::shared_ptr NotificationUserInput::Create(const std::string &inputKey, const std::string &tag, const std::vector &options, bool permitFreeFormInput, - const std::set &permitMimeTypes, const std::shared_ptr &pacMap, + const std::set &permitMimeTypes, const std::shared_ptr &additional, NotificationConstant::InputEditType editType) { if (inputKey.empty()) { @@ -88,13 +88,13 @@ std::shared_ptr NotificationUserInput::Create(const std:: } } - auto realPacMap = pacMap; - if (!realPacMap) { - realPacMap = std::make_shared(); + auto realAdditional = additional; + if (!realAdditional) { + realAdditional = std::make_shared(); } auto pUserInput = new (std::nothrow) - NotificationUserInput(inputKey, tag, options, permitFreeFormInput, permitMimeTypes, realPacMap, editType); + NotificationUserInput(inputKey, tag, options, permitFreeFormInput, permitMimeTypes, realAdditional, editType); if (pUserInput == nullptr) { ANS_LOGE("create NotificationUserInput object failed"); return {}; @@ -104,18 +104,18 @@ std::shared_ptr NotificationUserInput::Create(const std:: } NotificationUserInput::NotificationUserInput(const std::string &inputKey) - : inputKey_(inputKey), pacMap_(std::make_shared()) + : inputKey_(inputKey), additionalData_(std::make_shared()) {} NotificationUserInput::NotificationUserInput(const std::string &inputKey, const std::string &tag, const std::vector &options, bool permitFreeFormInput, const std::set &permitMimeTypes, - const std::shared_ptr &pacMap, NotificationConstant::InputEditType editType) + const std::shared_ptr &additional, NotificationConstant::InputEditType editType) : inputKey_(inputKey), tag_(tag), options_(options), permitFreeFormInput_(permitFreeFormInput), permitMimeTypes_(permitMimeTypes), - pacMap_(pacMap), + additionalData_(additional), editType_(editType) {} @@ -124,14 +124,16 @@ std::string NotificationUserInput::GetInputKey() const return inputKey_; } -void NotificationUserInput::AddAdditionalData(AppExecFwk::PacMap &pacMap) +void NotificationUserInput::AddAdditionalData(AAFwk::WantParams &additional) { - pacMap_->PutAll(pacMap); + if (additionalData_) { + *additionalData_ = additional; + } } -const std::shared_ptr NotificationUserInput::GetAdditionalData() const +const std::shared_ptr NotificationUserInput::GetAdditionalData() const { - return pacMap_; + return additionalData_; } void NotificationUserInput::SetEditType(NotificationConstant::InputEditType inputEditType) @@ -215,11 +217,14 @@ std::string NotificationUserInput::Dump() permitMimeTypes.pop_back(); permitMimeTypes.pop_back(); - return "NotificationUserInput[ inputKey = " + inputKey_ + " tag = " + tag_ + - "options = [ " + options + " ]" + - " permitFreeFormInput = " + (permitFreeFormInput_ ? "true" : "false") + - " permitMimeTypes = [ " + permitMimeTypes + " ]" + - " editType = " + std::to_string(static_cast(editType_)) + " ]"; + return "NotificationUserInput{ " + "inputKey = " + inputKey_ + + ", tag = " + tag_ + + ", options = [" + options + "]" + + ", permitFreeFormInput = " + (permitFreeFormInput_ ? "true" : "false") + + ", permitMimeTypes = [" + permitMimeTypes + "]" + + ", editType = " + std::to_string(static_cast(editType_)) + + " }"; } bool NotificationUserInput::Marshalling(Parcel &parcel) const @@ -244,15 +249,15 @@ bool NotificationUserInput::Marshalling(Parcel &parcel) const return false; } - auto valid = pacMap_ ? true : false; + auto valid = additionalData_ ? true : false; if (!parcel.WriteBool(valid)) { - ANS_LOGE("Failed to write the flag which indicate whether pacMap is null"); + ANS_LOGE("Failed to write the flag which indicate whether additionalData is null"); return false; } if (valid) { - if (!parcel.WriteParcelable(pacMap_.get())) { - ANS_LOGE("Failed to write pacMap"); + if (!parcel.WriteParcelable(additionalData_.get())) { + ANS_LOGE("Failed to write additionalData"); return false; } } @@ -279,7 +284,7 @@ bool NotificationUserInput::Marshalling(Parcel &parcel) const NotificationUserInput *NotificationUserInput::Unmarshalling(Parcel &parcel) { - auto pUserInput = new NotificationUserInput(); + auto pUserInput = new (std::nothrow) NotificationUserInput(); if ((pUserInput != nullptr) && !pUserInput->ReadFromParcel(parcel)) { delete pUserInput; pUserInput = nullptr; @@ -306,9 +311,9 @@ bool NotificationUserInput::ReadFromParcel(Parcel &parcel) auto valid = parcel.ReadBool(); if (valid) { - pacMap_ = std::shared_ptr(parcel.ReadParcelable()); - if (!pacMap_) { - ANS_LOGE("Failed to read pacMap"); + additionalData_ = std::shared_ptr(parcel.ReadParcelable()); + if (!additionalData_) { + ANS_LOGE("Failed to read additionalData"); return false; } } diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn old mode 100755 new mode 100644 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 65a4ab2e7..2c14f23f9 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -561,17 +561,17 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00200, Function NotificationActionButton::Create(nullptr, "title", wantAgent); std::shared_ptr userInput = NotificationUserInput::Create("inputKey"); std::vector> userInputs; - AppExecFwk::PacMap pacMap; + AAFwk::WantParams additional; std::map> results; std::vector options; std::set permitMimeTypes; - std::shared_ptr pacMapPtr; + std::shared_ptr additionalPtr; userInput->SetInputsSource(g_want, NotificationConstant::FREE_FORM_INPUT); - userInput->AddInputsToWant(userInputs, g_want, pacMap); + userInput->AddInputsToWant(userInputs, g_want, additional); std::shared_ptr userInputMine = NotificationUserInput::Create( - "Key", "tag", options, false, permitMimeTypes, pacMapPtr, NotificationConstant::EDIT_AUTO); + "Key", "tag", options, false, permitMimeTypes, additionalPtr, NotificationConstant::EDIT_AUTO); userInput->AddMimeInputToWant(*userInputMine, g_want, results); - userInput->AddAdditionalData(pacMap); + userInput->AddAdditionalData(additional); userInput->SetEditType(NotificationConstant::EDIT_DISABLED); userInput->SetOptions(options); userInput->SetPermitMimeTypes("mimeType", false); @@ -622,8 +622,8 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00300, Function std::shared_ptr actionButton = NotificationActionButton::Create(nullptr, "title", wantAgent); std::shared_ptr onlyUserInput = NotificationUserInput::Create("onlyUserInputKey"); - AppExecFwk::PacMap pacMap; - actionButton->AddAdditionalData(pacMap); + AAFwk::WantParams additional; + actionButton->AddAdditionalData(additional); actionButton->SetSemanticActionButton(NotificationConstant::NONE_ACTION_BUTTON); actionButton->SetAutoCreatedReplies(true); actionButton->AddMimeTypeOnlyUserInput(onlyUserInput); diff --git a/frameworks/ans/test/moduletest/mock/include/mock_ipc_skeleton.h b/frameworks/ans/test/moduletest/mock/include/mock_ipc_skeleton.h old mode 100755 new mode 100644 diff --git a/frameworks/wantagent/src/want_agent_helper.cpp b/frameworks/wantagent/src/want_agent_helper.cpp index fcb6d2757..33135ef63 100644 --- a/frameworks/wantagent/src/want_agent_helper.cpp +++ b/frameworks/wantagent/src/want_agent_helper.cpp @@ -152,7 +152,7 @@ std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo &pa wantSenderInfo.allWants.push_back(wantsInfo); wantSenderInfo.bundleName = want->GetOperation().GetBundleName(); wantSenderInfo.flags = FlagsTransformer(paramsInfo.GetFlags()); - wantSenderInfo.type = (int32_t)paramsInfo.GetOperationType(); + wantSenderInfo.type = (int32_t)paramsInfo.GetOperationType(); sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); if (target == nullptr) { @@ -308,13 +308,13 @@ void WantAgentHelper::RegisterCancelListener( const std::shared_ptr &cancelListener, const std::shared_ptr &agent) { if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetWant WantAgent invalid input param."); + WANT_AGENT_LOGE("WantAgentHelper::RegisterCancelListener WantAgent invalid input param."); return; } std::shared_ptr pendingWant = agent->GetPendingWant(); if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetWant PendingWant invalid input param."); + WANT_AGENT_LOGE("WantAgentHelper::RegisterCancelListener PendingWant invalid input param."); return; } @@ -325,13 +325,13 @@ void WantAgentHelper::UnregisterCancelListener( const std::shared_ptr &cancelListener, const std::shared_ptr &agent) { if (agent == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetWant WantAgent invalid input param."); + WANT_AGENT_LOGE("WantAgentHelper::UnregisterCancelListener WantAgent invalid input param."); return; } std::shared_ptr pendingWant = agent->GetPendingWant(); if (pendingWant == nullptr) { - WANT_AGENT_LOGE("WantAgentHelper::GetWant PendingWant invalid input param."); + WANT_AGENT_LOGE("WantAgentHelper::UnregisterCancelListener PendingWant invalid input param."); return; } diff --git a/interfaces/innerkits/ans/native/include/notification.h b/interfaces/innerkits/ans/native/include/notification.h index 7503e15b1..e2e71ea27 100644 --- a/interfaces/innerkits/ans/native/include/notification.h +++ b/interfaces/innerkits/ans/native/include/notification.h @@ -16,9 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_H -#include -#include - #include "notification_request.h" #include "parcel.h" #include "uri.h" diff --git a/interfaces/innerkits/ans/native/include/notification_action_button.h b/interfaces/innerkits/ans/native/include/notification_action_button.h index 8cb3e3958..a1a0f9a7b 100644 --- a/interfaces/innerkits/ans/native/include/notification_action_button.h +++ b/interfaces/innerkits/ans/native/include/notification_action_button.h @@ -16,15 +16,11 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_ACTION_BUTTON_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_ACTION_BUTTON_H -#include -#include -#include #include "notification_constant.h" #include "notification_user_input.h" -#include "want_agent.h" -#include "pac_map.h" -#include "pixel_map.h" #include "parcel.h" +#include "pixel_map.h" +#include "want_agent.h" namespace OHOS { namespace Notification { @@ -35,7 +31,7 @@ public: * @param icon Indicates the icon to represent this NotificationActionButton. * @param title Indicates the title of this NotificationActionButton. * @param wantAgent Indicates the wantAgent to be triggered when this NotificationActionButton is triggered. - * @param extras Indicates the PacMap object containing the additional data. + * @param extras Indicates the AAFwk::WantParams object containing the additional data. * @param semanticActionButton Indicates the semantic action to add. * @param autoCreatedReplies Indicates whether to allow the platform to automatically generate possible replies. * @param mimeTypeOnlyInputs Indicates the NotificationUserInput object to add which allows only values of @@ -48,7 +44,7 @@ public: */ static std::shared_ptr Create(const std::shared_ptr &icon, const std::string &title, const std::shared_ptr &wantAgent, - const std::shared_ptr &extras = {}, + const std::shared_ptr &extras = {}, NotificationConstant::SemanticActionButton semanticActionButton = NotificationConstant::SemanticActionButton::NONE_ACTION_BUTTON, bool autoCreatedReplies = true, @@ -89,15 +85,15 @@ public: /** * Adds additional data to this NotificationActionButton. - * @param pacMap Indicates the PacMap object containing the additional data. + * @param extras Indicates the AAFwk::WantParams object containing the additional data. */ - void AddAdditionalData(AppExecFwk::PacMap &pacMap); + void AddAdditionalData(AAFwk::WantParams &extras); /** * Obtains the additional data included in this NotificationActionButton. * @return the additional data included in this NotificationActionButton. */ - const std::shared_ptr GetAdditionalData() const; + const std::shared_ptr GetAdditionalData() const; /** * Sets a semantic action for this NotificationActionButton. @@ -199,7 +195,7 @@ private: * @param icon Indicates the icon to represent this NotificationActionButton. * @param title Indicates the title of this NotificationActionButton. * @param wantAgent Indicates the WantAgent to be triggered when this NotificationActionButton is triggered. - * @param extras Indicates the PacMap object containing the additional data. + * @param extras Indicates the AAFwk::WantParams object containing the additional data. * @param semanticActionButton Indicates the semantic action to add. * @param autoCreatedReplies Indicates whether to allow the platform to automatically generate possible replies. * @param mimeTypeOnlyInputs Indicates the NotificationUserInput object to add which allows only values of @@ -208,7 +204,7 @@ 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); @@ -223,7 +219,7 @@ private: std::shared_ptr icon_ {}; std::string title_ {}; std::shared_ptr wantAgent_ {}; - std::shared_ptr extras_ {}; + std::shared_ptr extras_ {}; NotificationConstant::SemanticActionButton semanticActionButton_ { NotificationConstant::SemanticActionButton::NONE_ACTION_BUTTON }; diff --git a/interfaces/innerkits/ans/native/include/notification_bundle_option.h b/interfaces/innerkits/ans/native/include/notification_bundle_option.h index 4ea4fb03c..992bfff9e 100644 --- a/interfaces/innerkits/ans/native/include/notification_bundle_option.h +++ b/interfaces/innerkits/ans/native/include/notification_bundle_option.h @@ -16,7 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_BUNDLE_OPTION_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_BUNDLE_OPTION_H -#include #include "parcel.h" namespace OHOS { diff --git a/interfaces/innerkits/ans/native/include/notification_constant.h b/interfaces/innerkits/ans/native/include/notification_constant.h index 1f710ef02..f3dd82cf1 100644 --- a/interfaces/innerkits/ans/native/include/notification_constant.h +++ b/interfaces/innerkits/ans/native/include/notification_constant.h @@ -105,7 +105,7 @@ public: */ TYPE_TIMER = 0x00000002 }; - + /** * Indicates that a notification is deleted because it is clicked. */ diff --git a/interfaces/innerkits/ans/native/include/notification_content.h b/interfaces/innerkits/ans/native/include/notification_content.h index ea5abb8cb..9d5ebdabb 100644 --- a/interfaces/innerkits/ans/native/include/notification_content.h +++ b/interfaces/innerkits/ans/native/include/notification_content.h @@ -16,15 +16,13 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONTENT_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONTENT_H -#include -#include #include "notification_basic_content.h" -#include "notification_normal_content.h" -#include "notification_long_text_content.h" -#include "notification_picture_content.h" #include "notification_conversational_content.h" -#include "notification_multiline_content.h" +#include "notification_long_text_content.h" #include "notification_media_content.h" +#include "notification_multiline_content.h" +#include "notification_normal_content.h" +#include "notification_picture_content.h" #include "parcel.h" namespace OHOS { diff --git a/interfaces/innerkits/ans/native/include/notification_conversational_content.h b/interfaces/innerkits/ans/native/include/notification_conversational_content.h index 7ff86bac9..e35265131 100644 --- a/interfaces/innerkits/ans/native/include/notification_conversational_content.h +++ b/interfaces/innerkits/ans/native/include/notification_conversational_content.h @@ -16,9 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONVERSATIONAL_CONTENT_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONVERSATIONAL_CONTENT_H -#include -#include -#include #include "message_user.h" #include "notification_basic_content.h" #include "notification_conversational_message.h" diff --git a/interfaces/innerkits/ans/native/include/notification_conversational_message.h b/interfaces/innerkits/ans/native/include/notification_conversational_message.h index 06eb0b350..d46aacca2 100644 --- a/interfaces/innerkits/ans/native/include/notification_conversational_message.h +++ b/interfaces/innerkits/ans/native/include/notification_conversational_message.h @@ -16,8 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONVERSATIONAL_MESSAGE_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONVERSATIONAL_MESSAGE_H -#include -#include #include "message_user.h" #include "parcel.h" #include "uri.h" diff --git a/interfaces/innerkits/ans/native/include/notification_helper.h b/interfaces/innerkits/ans/native/include/notification_helper.h index 0395b638c..a5d94f43e 100644 --- a/interfaces/innerkits/ans/native/include/notification_helper.h +++ b/interfaces/innerkits/ans/native/include/notification_helper.h @@ -524,7 +524,7 @@ public: * only be null or an empty string, indicating the current device. * @param enabled Specifies whether to allow the current application to publish notifications. The value * true indicates that notifications are allowed, and the value false indicates that - * notifications are not allowed.\ + * notifications are not allowed. * @return Returns set notifications enabled for default bundle result. */ static ErrCode SetNotificationsEnabledForDefaultBundle(const std::string &deviceId, bool enabled); diff --git a/interfaces/innerkits/ans/native/include/notification_long_text_content.h b/interfaces/innerkits/ans/native/include/notification_long_text_content.h index b64685f5d..c6ffcb670 100644 --- a/interfaces/innerkits/ans/native/include/notification_long_text_content.h +++ b/interfaces/innerkits/ans/native/include/notification_long_text_content.h @@ -16,8 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_LONG_TEXT_CONTENT_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_LONG_TEXT_CONTENT_H -#include -#include #include "notification_basic_content.h" #include "parcel.h" diff --git a/interfaces/innerkits/ans/native/include/notification_media_content.h b/interfaces/innerkits/ans/native/include/notification_media_content.h index c725db2ae..54d90d2c9 100644 --- a/interfaces/innerkits/ans/native/include/notification_media_content.h +++ b/interfaces/innerkits/ans/native/include/notification_media_content.h @@ -16,9 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MEDIA_CONTENT_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MEDIA_CONTENT_H -#include -#include -#include #include "notification_basic_content.h" #include "parcel.h" diff --git a/interfaces/innerkits/ans/native/include/notification_multiline_content.h b/interfaces/innerkits/ans/native/include/notification_multiline_content.h index 485f6c1fa..a3d216fbe 100644 --- a/interfaces/innerkits/ans/native/include/notification_multiline_content.h +++ b/interfaces/innerkits/ans/native/include/notification_multiline_content.h @@ -16,8 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MULTILINE_CONTENT_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MULTILINE_CONTENT_H -#include -#include #include "notification_basic_content.h" #include "parcel.h" diff --git a/interfaces/innerkits/ans/native/include/notification_normal_content.h b/interfaces/innerkits/ans/native/include/notification_normal_content.h index 4bb177e95..cae7525ec 100644 --- a/interfaces/innerkits/ans/native/include/notification_normal_content.h +++ b/interfaces/innerkits/ans/native/include/notification_normal_content.h @@ -16,7 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_NORMAL_CONTENT_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_NORMAL_CONTENT_H -#include #include "notification_basic_content.h" #include "parcel.h" diff --git a/interfaces/innerkits/ans/native/include/notification_picture_content.h b/interfaces/innerkits/ans/native/include/notification_picture_content.h index 91a3dd806..df45286fe 100644 --- a/interfaces/innerkits/ans/native/include/notification_picture_content.h +++ b/interfaces/innerkits/ans/native/include/notification_picture_content.h @@ -16,11 +16,9 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_PICTURE_CONTENT_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_PICTURE_CONTENT_H -#include -#include #include "notification_basic_content.h" -#include "pixel_map.h" #include "parcel.h" +#include "pixel_map.h" namespace OHOS { namespace Notification { diff --git a/interfaces/innerkits/ans/native/include/notification_request.h b/interfaces/innerkits/ans/native/include/notification_request.h index a18b7d668..1e8a22b52 100644 --- a/interfaces/innerkits/ans/native/include/notification_request.h +++ b/interfaces/innerkits/ans/native/include/notification_request.h @@ -16,17 +16,14 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_REQUEST_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_REQUEST_H -#include -#include -#include +#include "context.h" #include "message_user.h" #include "notification_action_button.h" #include "notification_content.h" -#include "want_agent.h" -#include "context.h" #include "ohos/aafwk/content/want_params.h" -#include "pixel_map.h" #include "parcel.h" +#include "pixel_map.h" +#include "want_agent.h" namespace OHOS { namespace Notification { @@ -859,7 +856,7 @@ public: /** * Unmarshal object from a Parcel. - * @return the NotificationRequest + * @return the NotificationRequest. */ static NotificationRequest *Unmarshalling(Parcel &parcel); @@ -878,7 +875,7 @@ private: * the maximum number of action buttons is 3. */ static const std::size_t MAX_ACTION_BUTTONS; - + private: /** * Read a NotificationRequest object from a Parcel. diff --git a/interfaces/innerkits/ans/native/include/notification_slot.h b/interfaces/innerkits/ans/native/include/notification_slot.h index b8adaaf72..6b5343032 100644 --- a/interfaces/innerkits/ans/native/include/notification_slot.h +++ b/interfaces/innerkits/ans/native/include/notification_slot.h @@ -16,8 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SLOT_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SLOT_H -#include - #include "notification_content.h" #include "notification_request.h" #include "parcel.h" diff --git a/interfaces/innerkits/ans/native/include/notification_slot_group.h b/interfaces/innerkits/ans/native/include/notification_slot_group.h index bcba43946..7becacaae 100644 --- a/interfaces/innerkits/ans/native/include/notification_slot_group.h +++ b/interfaces/innerkits/ans/native/include/notification_slot_group.h @@ -16,8 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SLOT_GROUP_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SLOT_GROUP_H -#include - #include "notification_slot.h" namespace OHOS { diff --git a/interfaces/innerkits/ans/native/include/notification_sorting.h b/interfaces/innerkits/ans/native/include/notification_sorting.h index da7810b6f..cc02e7447 100644 --- a/interfaces/innerkits/ans/native/include/notification_sorting.h +++ b/interfaces/innerkits/ans/native/include/notification_sorting.h @@ -16,9 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SORTING_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SORTING_H -#include -#include - #include "ans_log_wrapper.h" #include "notification_slot.h" #include "parcel.h" diff --git a/interfaces/innerkits/ans/native/include/notification_sorting_map.h b/interfaces/innerkits/ans/native/include/notification_sorting_map.h index 0fe5e4b83..cd7d83a12 100644 --- a/interfaces/innerkits/ans/native/include/notification_sorting_map.h +++ b/interfaces/innerkits/ans/native/include/notification_sorting_map.h @@ -16,10 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SORTING_MAP_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SORTING_MAP_H -#include -#include -#include - #include "notification_sorting.h" #include "parcel.h" diff --git a/interfaces/innerkits/ans/native/include/notification_subscribe_info.h b/interfaces/innerkits/ans/native/include/notification_subscribe_info.h index bb5ede504..7043ae687 100644 --- a/interfaces/innerkits/ans/native/include/notification_subscribe_info.h +++ b/interfaces/innerkits/ans/native/include/notification_subscribe_info.h @@ -16,10 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATIN_SUBSCRIBER_INFO_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATIN_SUBSCRIBER_INFO_H -#include -#include -#include - #include "parcel.h" namespace OHOS { diff --git a/interfaces/innerkits/ans/native/include/notification_subscriber.h b/interfaces/innerkits/ans/native/include/notification_subscriber.h index 688959d02..aefa50b6a 100644 --- a/interfaces/innerkits/ans/native/include/notification_subscriber.h +++ b/interfaces/innerkits/ans/native/include/notification_subscriber.h @@ -16,8 +16,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SUBSCRIBER_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SUBSCRIBER_H -#include - #include "ans_manager_interface.h" #include "ans_subscriber_stub.h" #include "notification_request.h" diff --git a/interfaces/innerkits/ans/native/include/notification_user_input.h b/interfaces/innerkits/ans/native/include/notification_user_input.h index 1327bca96..74420e956 100644 --- a/interfaces/innerkits/ans/native/include/notification_user_input.h +++ b/interfaces/innerkits/ans/native/include/notification_user_input.h @@ -16,15 +16,10 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_USER_INPUT_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_USER_INPUT_H -#include -#include -#include -#include #include "notification_constant.h" -#include "pac_map.h" -#include "want.h" #include "parcel.h" #include "uri.h" +#include "want.h" namespace OHOS { namespace Notification { @@ -50,22 +45,22 @@ public: * collection services when sending input results to an WantAgent. * @param userInputs Indicates the list of NotificationUserInput objects for which the input results are provided. * @param want Indicates the Want to which the input results are to be added. - * @param pacMap Indicates the PacMap object holding the input results. - * The PacMap key must match the keys contained in the objects specified in userInputs. + * @param additional Indicates the AAFwk::WantParams object holding the input results. + * The AAFwk::WantParams key must match the keys contained in the objects specified in userInputs. */ static void AddInputsToWant(const std::vector> &userInputs, - AAFwk::Want &want, const AppExecFwk::PacMap &pacMap); + AAFwk::Want &want, const AAFwk::WantParams &additional); /** * Obtains the input text results from a specified Want. * @param want Indicates the Want object containing one or more user input results. - * @return the PacMap object containing the input text results. + * @return the AAFwk::WantParams object containing the input text results. */ - static std::shared_ptr GetInputsFromWant(const AAFwk::Want &want); + static std::shared_ptr GetInputsFromWant(const AAFwk::Want &want); /** * Adds the given NotificationUserInput object of a specified MIME type to an Want. This method is similar to - * addInputsToWant(NotificationUserInput, Want, PacMap) except that the MIME type must be specified. + * addInputsToWant(NotificationUserInput, Want, AAFwk::WantParams) except that the MIME type must be specified. * @param userInput Indicates the NotificationUserInput object for which the input results are provided. * @param want Indicates the Want to which the input results are to be added. * @param results Indicates a map containing the MIME type and its URI result. @@ -86,7 +81,7 @@ public: public: /** * A static function used to create a NotificationUserInput instance with the input parameters passed. - * @param inputKey Indicates the PacMap key used to identify this input when the input is collected from the user. + * @param inputKey Indicates the AAFwk::WantParams key used to identify this input when the input is collected from the user. * @return the shared_ptr object owns the created NotificationUserInput object otherwise return empty object if * inputKey is empty. */ @@ -94,14 +89,14 @@ public: /** * A static function used to create a NotificationUserInput instance with the input parameters passed. - * @param inputKey Indicates the PacMap key used to identify this input when the input is collected from the user. + * @param inputKey Indicates the AAFwk::WantParams key used to identify this input when the input is collected from the user. * @param tag Indicates the tag to be displayed. * @param options Indicates the list of predefined options to be provided for user input. * @param permitFreeFormInput Specifies whether to allow arbitrary text values. The default value is true, * indicating that arbitrary text values are allowed. If this parameter is set to false, you must pass a non-empty * std::vector of options or a non-empty std::set of permitMimeTypes. Otherwise, return empty object. * @param permitMimeTypes Indicates the MIME type allowed. - * @param pacMap Indicates the PacMap object containing the additional data. + * @param additional Indicates the AAFwk::WantParams object containing the additional data. * @param editType Indicates the edit type to set. For details about available values, see * NotificationConstant::InputEditType. * @return the shared_ptr object owns the created NotificationUserInput object otherwise return empty object if @@ -109,7 +104,7 @@ public: */ static std::shared_ptr Create(const std::string &inputKey, const std::string &tag, const std::vector &options, bool permitFreeFormInput, const std::set &permitMimeTypes, - const std::shared_ptr &pacMap, NotificationConstant::InputEditType editType); + const std::shared_ptr &additional, NotificationConstant::InputEditType editType); /** * Default deconstructor used to deconstruct. @@ -124,16 +119,16 @@ public: /** * Adds additional data to this Builder. - * The value of pacMap will replace the existing extras value in this Builder. - * @param pacMap Indicates the PacMap object containing the additional data. + * The value of AAFwk::WantParams will replace the existing extras value in this Builder. + * @param additional Indicates the AAFwk::WantParams object containing the additional data. */ - void AddAdditionalData(AppExecFwk::PacMap &pacMap); + void AddAdditionalData(AAFwk::WantParams &additional); /** * Obtains the additional data included in this NotificationUserInput object. * @return the additional data in this NotificationUserInput object. */ - const std::shared_ptr GetAdditionalData() const; + const std::shared_ptr GetAdditionalData() const; /** * Sets the edit type of the options provided by this NotificationUserInput object. @@ -236,13 +231,13 @@ private: /** * A constructor used to create a NotificationUserInput instance with the input parameters passed. - * @param inputKey Indicates the PacMap key used to identify this input when the input is collected from the user. + * @param inputKey Indicates the AAFwk::WantParams key used to identify this input when the input is collected from the user. */ explicit NotificationUserInput(const std::string &inputKey); /** * A constructor used to create a NotificationUserInput instance with the input parameters passed. - * @param inputKey Indicates the PacMap key used to identify this input when the input is collected from the user. + * @param inputKey Indicates the AAFwk::WantParams key used to identify this input when the input is collected from the user. * @param tag Indicates the tag to be displayed. * @param options Indicates the list of predefined options to be provided for user input. * @param permitFreeFormInput Specifies whether to allow arbitrary text values. The default value is true, @@ -250,13 +245,13 @@ private: * setOptions(const std::vector &) to set a non-empty list or call * setPermitMimeTypes(std::string, bool) to allow a MIME type. * @param permitMimeTypes Indicates the MIME type allowed. - * @param pacMap Indicates the PacMap object containing the additional data. + * @param additional Indicates the AAFwk::WantParams object containing the additional data. * @param editType Indicates the edit type to set. For details about available values, see * NotificationConstant::InputEditType. */ NotificationUserInput(const std::string &inputKey, const std::string &tag, const std::vector &options, bool permitFreeFormInput, const std::set &permitMimeTypes, - const std::shared_ptr &pacMap, NotificationConstant::InputEditType editType); + const std::shared_ptr &additional, NotificationConstant::InputEditType editType); /** * Read a NotificationUserInput object from a Parcel. @@ -270,7 +265,7 @@ private: std::vector options_ {}; bool permitFreeFormInput_ {true}; std::set permitMimeTypes_ {}; - std::shared_ptr pacMap_ {}; + std::shared_ptr additionalData_ {}; NotificationConstant::InputEditType editType_ {NotificationConstant::InputEditType::EDIT_AUTO}; }; } // namespace Notification diff --git a/interfaces/kits/napi/ans/BUILD.gn b/interfaces/kits/napi/ans/BUILD.gn old mode 100755 new mode 100644 diff --git a/interfaces/kits/napi/ans/include/common.h b/interfaces/kits/napi/ans/include/common.h index 0f2075e72..ca2751f8f 100644 --- a/interfaces/kits/napi/ans/include/common.h +++ b/interfaces/kits/napi/ans/include/common.h @@ -28,6 +28,9 @@ const std::int32_t STR_MAX_SIZE = 64; const std::int32_t LONG_STR_MAX_SIZE = 1024; const int NO_ERROR = 0; const int ERROR = -1; +const int PARAM0 = 0; +const int PARAM1 = 1; +const int PARAM2 = 2; enum class ContentType { NOTIFICATION_CONTENT_BASIC_TEXT, @@ -284,10 +287,14 @@ public: static napi_value GetNotificationWantAgent( const napi_env &env, const napi_value &value, NotificationRequest &request); - static napi_value GetNotificationSlot(const napi_env &env, const napi_value &value, NotificationSlot &slot); - static napi_value GetNotificationSlotByString(const napi_env &env, const napi_value &value, NotificationSlot &slot); - static napi_value GetNotificationSlotByBool(const napi_env &env, const napi_value &value, NotificationSlot &slot); - static napi_value GetNotificationSlotByNumber(const napi_env &env, const napi_value &value, NotificationSlot &slot); + static napi_value GetNotificationSlot( + const napi_env &env, const napi_value &value, NotificationSlot &slot); + static napi_value GetNotificationSlotByString( + const napi_env &env, const napi_value &value, NotificationSlot &slot); + static napi_value GetNotificationSlotByBool( + const napi_env &env, const napi_value &value, NotificationSlot &slot); + static napi_value GetNotificationSlotByNumber( + const napi_env &env, const napi_value &value, NotificationSlot &slot); static napi_value GetNotificationSlotByVibration( const napi_env &env, const napi_value &value, NotificationSlot &slot); @@ -371,7 +378,7 @@ public: static napi_value GetNotificationMultiLineContentLines(const napi_env &env, const napi_value &result, std::shared_ptr &multiLineContent); - static napi_value GetBundleOption(const napi_env &env, const napi_value &value, BundleOption &option); + static napi_value GetBundleOption(const napi_env &env, const napi_value &value, NotificationBundleOption &option); static napi_value GetNotificationKey(const napi_env &env, const napi_value &value, NotificationKey &key); @@ -400,8 +407,6 @@ public: private: static const int ARGS_ONE = 1; static const int ARGS_TWO = 2; - static const int PARAM0 = 0; - static const int PARAM1 = 1; static const int ONLY_CALLBACK_MAX_PARA = 1; static const int ONLY_CALLBACK_MIN_PARA = 0; static std::set> wantAgent_; diff --git a/interfaces/kits/napi/ans/include/constant.h b/interfaces/kits/napi/ans/include/constant.h index 5eb46c17f..323a4fd0f 100644 --- a/interfaces/kits/napi/ans/include/constant.h +++ b/interfaces/kits/napi/ans/include/constant.h @@ -15,10 +15,7 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CONSTANT_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CONSTANT_H -#include "ans_log_wrapper.h" -#include "napi/native_api.h" -#include "napi/native_node_api.h" -#include "notification_helper.h" +#include "common.h" namespace OHOS { namespace NotificationNapi { diff --git a/interfaces/kits/napi/ans/include/publish.h b/interfaces/kits/napi/ans/include/publish.h index 2f64e25b9..6d8405209 100644 --- a/interfaces/kits/napi/ans/include/publish.h +++ b/interfaces/kits/napi/ans/include/publish.h @@ -15,7 +15,6 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_PUBLISH_H #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_PUBLISH_H -#include #include "common.h" namespace OHOS { diff --git a/interfaces/kits/napi/ans/src/cancel.cpp b/interfaces/kits/napi/ans/src/cancel.cpp index 1632d1fc2..799bc5cd8 100644 --- a/interfaces/kits/napi/ans/src/cancel.cpp +++ b/interfaces/kits/napi/ans/src/cancel.cpp @@ -59,31 +59,31 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_valuetype valuetype = napi_undefined; // argv[0]: id: number - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); - NAPI_CALL(env, napi_get_value_int32(env, argv[0], ¶s.id)); + NAPI_CALL(env, napi_get_value_int32(env, argv[PARAM0], ¶s.id)); // argv[1]: label: string / callback if (argc >= CANCEL_MAX_PARA - 1) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, (valuetype == napi_string || valuetype == napi_function), "Wrong argument type. String or function expected."); if (valuetype == napi_string) { char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; - NAPI_CALL(env, napi_get_value_string_utf8(env, argv[1], str, STR_MAX_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, argv[PARAM1], str, STR_MAX_SIZE - 1, &strLen)); paras.label = str; } else { - napi_create_reference(env, argv[1], 1, ¶s.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶s.callback); } } // argv[2]: callback if (argc >= CANCEL_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[CANCEL_MAX_PARA - 1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[CANCEL_MAX_PARA - 1], 1, ¶s.callback); + napi_create_reference(env, argv[PARAM2], 1, ¶s.callback); } return Common::NapiGetNull(env); @@ -101,18 +101,18 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_valuetype valuetype = napi_undefined; // argv[0]: groupName: string - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; - NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], str, STR_MAX_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, argv[PARAM0], str, STR_MAX_SIZE - 1, &strLen)); paras.groupName = str; // argv[1]: callback if (argc >= CANCEL_GROUP_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[CANCEL_GROUP_MIN_PARA], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[CANCEL_GROUP_MIN_PARA], 1, ¶s.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶s.callback); } return Common::NapiGetNull(env); diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 3e67eac60..c995c0e62 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -14,14 +14,8 @@ */ #include "common.h" -#include #include "napi_common.h" -#include "notification_long_text_content.h" -#include "notification_multiline_content.h" -#include "notification_slot.h" #include "pixel_map_napi.h" -#include "publish.h" -#include "want_agent.h" namespace OHOS { namespace NotificationNapi { @@ -160,9 +154,9 @@ napi_value Common::ParseParaOnlyCallback(const napi_env &env, const napi_callbac // argv[0]:callback napi_valuetype valuetype = napi_undefined; if (argc >= ONLY_CALLBACK_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[ONLY_CALLBACK_MIN_PARA], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[ONLY_CALLBACK_MIN_PARA], 1, &callback); + napi_create_reference(env, argv[PARAM0], 1, &callback); } return Common::NapiGetNull(env); @@ -1133,9 +1127,12 @@ napi_value Common::SetNotificationActionButtonByExtras( const napi_env &env, const std::shared_ptr &actionButton, napi_value &result) { ANS_LOGI("enter"); - + if (!actionButton) { + ANS_LOGE("actionButton is null"); + return NapiGetBoolean(env, false); + } // extras?: {[key: string]: any} - std::shared_ptr extras = nullptr; + auto extras = actionButton->GetAdditionalData(); if (extras) { napi_value nExtras = nullptr; nExtras = OHOS::AppExecFwk::WrapWantParams(env, *extras); @@ -1197,8 +1194,8 @@ napi_value Common::SetNotificationActionButtonByUserInput( napi_create_int64(env, userInput->GetEditType(), &value); napi_set_named_property(env, result, "editType", value); - // additionalData?: {[key: string]: any} - std::shared_ptr additionalData = nullptr; + // additionalData?: {[key: string]: Object} + auto additionalData = userInput->GetAdditionalData(); if (additionalData) { napi_value nAdditionalData = nullptr; nAdditionalData = OHOS::AppExecFwk::WrapWantParams(env, *additionalData); @@ -2131,6 +2128,7 @@ napi_value Common::GetNotificationActionButtonsDetailedByExtras( if (!OHOS::AppExecFwk::UnwrapWantParams(env, result, wantParams)) { return nullptr; } + pActionButton->AddAdditionalData(wantParams); } return NapiGetNull(env); } @@ -2223,14 +2221,13 @@ napi_value Common::GetNotificationUserInputByTag( // tag: string NAPI_CALL(env, napi_has_named_property(env, userInputResult, "tag", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, userInputResult, "tag", &value); - NAPI_CALL(env, napi_typeof(env, value, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); - userInput->SetTag(str); - ANS_LOGI("NotificationUserInput::tag = %{public}s", str); - } + NAPI_ASSERT(env, hasProperty, "Property tag expected."); + napi_get_named_property(env, userInputResult, "tag", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); + userInput->SetTag(str); + ANS_LOGI("NotificationUserInput::tag = %{public}s", str); return NapiGetNull(env); } @@ -2254,24 +2251,24 @@ napi_value Common::GetNotificationUserInputByOptions( // options: Array NAPI_CALL(env, napi_has_named_property(env, userInputResult, "options", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, userInputResult, "options", &value); - napi_is_array(env, value, &isArray); - NAPI_ASSERT(env, isArray, "Property options is expected to be an array."); - napi_get_array_length(env, value, &length); - NAPI_ASSERT(env, length > 0, "The array is empty."); - std::vector options; - for (uint32_t i = 0; i < length; ++i) { - napi_value option = nullptr; - char str[STR_MAX_SIZE] = {0}; - napi_get_element(env, value, i, &option); - NAPI_CALL(env, napi_typeof(env, option, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, option, str, STR_MAX_SIZE - 1, &strLen)); - options.emplace_back(str); - } - userInput->SetOptions(options); + NAPI_ASSERT(env, hasProperty, "Property options expected."); + napi_get_named_property(env, userInputResult, "options", &value); + napi_is_array(env, value, &isArray); + NAPI_ASSERT(env, isArray, "Property options is expected to be an array."); + napi_get_array_length(env, value, &length); + NAPI_ASSERT(env, length > 0, "The array is empty."); + std::vector options; + for (uint32_t i = 0; i < length; ++i) { + napi_value option = nullptr; + char str[STR_MAX_SIZE] = {0}; + napi_get_element(env, value, i, &option); + NAPI_CALL(env, napi_typeof(env, option, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, option, str, STR_MAX_SIZE - 1, &strLen)); + options.emplace_back(str); } + userInput->SetOptions(options); + return NapiGetNull(env); } @@ -2382,7 +2379,7 @@ napi_value Common::GetNotificationUserInputByAdditionalData( return nullptr; } - // additionalData?: {[key: string]: any} + // additionalData?: {[key: string]: Object} NAPI_CALL(env, napi_has_named_property(env, userInputResult, "additionalData", &hasProperty)); if (hasProperty) { napi_get_named_property(env, userInputResult, "additionalData", &result); @@ -2392,6 +2389,7 @@ napi_value Common::GetNotificationUserInputByAdditionalData( if (!OHOS::AppExecFwk::UnwrapWantParams(env, result, wantParams)) { return nullptr; } + userInput->AddAdditionalData(wantParams); } return NapiGetNull(env); @@ -3396,7 +3394,7 @@ napi_value Common::GetNotificationSlotByVibration(const napi_env &env, const nap return NapiGetNull(env); } -napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, BundleOption &option) +napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, NotificationBundleOption &option) { ANS_LOGI("enter"); @@ -3413,15 +3411,17 @@ napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, NAPI_CALL(env, napi_typeof(env, result, &valuetype)); NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); - option.bundle = str; + option.SetBundleName(str); // uid?: number NAPI_CALL(env, napi_has_named_property(env, value, "uid", &hasProperty)); if (hasProperty) { + int32_t uid = 0; napi_get_named_property(env, value, "uid", &result); NAPI_CALL(env, napi_typeof(env, result, &valuetype)); NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); - napi_get_value_int32(env, result, &option.uid); + napi_get_value_int32(env, result, &uid); + option.SetUid(uid); } return NapiGetNull(env); diff --git a/interfaces/kits/napi/ans/src/constant.cpp b/interfaces/kits/napi/ans/src/constant.cpp index 96e3e4219..29fefc600 100644 --- a/interfaces/kits/napi/ans/src/constant.cpp +++ b/interfaces/kits/napi/ans/src/constant.cpp @@ -14,7 +14,6 @@ */ #include "constant.h" -#include "common.h" namespace OHOS { namespace NotificationNapi { diff --git a/interfaces/kits/napi/ans/src/display_badge.cpp b/interfaces/kits/napi/ans/src/display_badge.cpp index 214b87bb6..737e6403c 100644 --- a/interfaces/kits/napi/ans/src/display_badge.cpp +++ b/interfaces/kits/napi/ans/src/display_badge.cpp @@ -22,7 +22,7 @@ const int ENABLE_BADGE_DISPLAYED_MIN_PARA = 2; const int IS_DISPLAY_BADGE_MAX_PARA = 2; struct EnableBadgeParams { - BundleOption option; + NotificationBundleOption option; bool enable = false; napi_ref callback = nullptr; }; @@ -35,7 +35,7 @@ struct AsyncCallbackInfoEnableBadge { }; struct IsDisplayBadgeParams { - BundleOption option; + NotificationBundleOption option; napi_ref callback = nullptr; bool hasBundleOption = false; }; @@ -60,24 +60,24 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[0]: bundle napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type.Object expected."); - auto retValue = Common::GetBundleOption(env, argv[0], params.option); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); return nullptr; } // argv[1]: enable - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); - napi_get_value_bool(env, argv[1], ¶ms.enable); + napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); // argv[2]:callback if (argc >= ENABLE_BADGE_DISPLAYED_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[ENABLE_BADGE_DISPLAYED_MAX_PARA - 1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[ENABLE_BADGE_DISPLAYED_MAX_PARA - 1], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); } return Common::NapiGetNull(env); @@ -98,26 +98,26 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[0]: bundle / callback napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, (valuetype == napi_function) || (valuetype == napi_object), "Wrong argument type. Function or object expected."); if (valuetype == napi_object) { - auto retValue = Common::GetBundleOption(env, argv[0], params.option); + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); return nullptr; } params.hasBundleOption = true; } else { - napi_create_reference(env, argv[0], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM0], 1, ¶ms.callback); } // argv[1]:callback if (argc >= IS_DISPLAY_BADGE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } return Common::NapiGetNull(env); @@ -149,15 +149,12 @@ napi_value DisplayBadge(napi_env env, napi_callback_info info) [](napi_env env, void *data) { ANS_LOGI("DisplayBadge napi_create_async_work start"); AsyncCallbackInfoEnableBadge *asynccallbackinfo = (AsyncCallbackInfoEnableBadge *)data; - NotificationBundleOption bundleOption; - bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); - bundleOption.SetUid(asynccallbackinfo->params.option.uid); - ANS_LOGI("asynccallbackinfo->params.option.bundle = %{public}s", - asynccallbackinfo->params.option.bundle.c_str()); - ANS_LOGI("asynccallbackinfo->params.option.uid = %{public}d", asynccallbackinfo->params.option.uid); - ANS_LOGI("asynccallbackinfo->params.enable = %{public}d", asynccallbackinfo->params.enable); - asynccallbackinfo->info.errorCode = - NotificationHelper::SetShowBadgeEnabledForBundle(bundleOption, asynccallbackinfo->params.enable); + ANS_LOGI("option.bundle = %{public}s option.uid = %{public}d enable = %{public}d", + asynccallbackinfo->params.option.GetBundleName().c_str(), + asynccallbackinfo->params.option.GetUid(), + asynccallbackinfo->params.enable); + asynccallbackinfo->info.errorCode = NotificationHelper::SetShowBadgeEnabledForBundle( + asynccallbackinfo->params.option, asynccallbackinfo->params.enable); ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d", asynccallbackinfo->info.errorCode); }, [](napi_env env, napi_status status, void *data) { @@ -188,6 +185,30 @@ napi_value DisplayBadge(napi_env env, napi_callback_info info) } } +void AsyncCompleteCallbackIsBadgeDisplayed(napi_env env, napi_status status, void *data) +{ + ANS_LOGI("enter"); + if (!data) { + ANS_LOGE("Invalid async callback data"); + return; + } + AsyncCallbackInfoIsDisplayBadge *asynccallbackinfo = (AsyncCallbackInfoIsDisplayBadge *)data; + + napi_value result = nullptr; + napi_get_boolean(env, asynccallbackinfo->enabled, &result); + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + if (asynccallbackinfo) { + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } +} + napi_value IsBadgeDisplayed(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); @@ -215,40 +236,19 @@ napi_value IsBadgeDisplayed(napi_env env, napi_callback_info info) ANS_LOGI("IsBadgeDisplayed napi_create_async_work start"); AsyncCallbackInfoIsDisplayBadge *asynccallbackinfo = (AsyncCallbackInfoIsDisplayBadge *)data; - NotificationBundleOption bundleOption; - bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); - bundleOption.SetUid(asynccallbackinfo->params.option.uid); if (asynccallbackinfo->params.hasBundleOption) { - ANS_LOGI("asynccallbackinfo->params.option.bundle = %{public}s", - asynccallbackinfo->params.option.bundle.c_str()); - ANS_LOGI("asynccallbackinfo->params.option.uid = %{public}d", asynccallbackinfo->params.option.uid); - ANS_LOGI("asynccallbackinfo->enabled = %{public}d", asynccallbackinfo->enabled); - asynccallbackinfo->info.errorCode = - NotificationHelper::GetShowBadgeEnabledForBundle(bundleOption, asynccallbackinfo->enabled); + ANS_LOGI("option.bundle = %{public}s option.uid = %{public}d", + asynccallbackinfo->params.option.GetBundleName().c_str(), + asynccallbackinfo->params.option.GetUid()); + asynccallbackinfo->info.errorCode = NotificationHelper::GetShowBadgeEnabledForBundle( + asynccallbackinfo->params.option, asynccallbackinfo->enabled); } else { - ANS_LOGI("asynccallbackinfo->enabled = %{public}d", asynccallbackinfo->enabled); asynccallbackinfo->info.errorCode = NotificationHelper::GetShowBadgeEnabled(asynccallbackinfo->enabled); } - ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d", asynccallbackinfo->info.errorCode); - }, - [](napi_env env, napi_status status, void *data) { - ANS_LOGI("IsBadgeDisplayed napi_create_async_work end"); - AsyncCallbackInfoIsDisplayBadge *asynccallbackinfo = (AsyncCallbackInfoIsDisplayBadge *)data; - - napi_value result = nullptr; - napi_get_boolean(env, asynccallbackinfo->enabled, &result); - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - if (asynccallbackinfo) { - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } + ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d, enabled = %{public}d", + asynccallbackinfo->info.errorCode, asynccallbackinfo->enabled); }, + AsyncCompleteCallbackIsBadgeDisplayed, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); diff --git a/interfaces/kits/napi/ans/src/disturb_mode.cpp b/interfaces/kits/napi/ans/src/disturb_mode.cpp index d9b056f86..a27ba1940 100644 --- a/interfaces/kits/napi/ans/src/disturb_mode.cpp +++ b/interfaces/kits/napi/ans/src/disturb_mode.cpp @@ -112,17 +112,17 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[0]: date napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - if (GetDoNotDisturbDate(env, argv[0], params) == nullptr) { + if (GetDoNotDisturbDate(env, argv[PARAM0], params) == nullptr) { return nullptr; } // argv[1]:callback if (argc >= SET_DISTURB_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[SET_DISTURB_MIN_PARA], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[SET_DISTURB_MIN_PARA], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } return Common::NapiGetNull(env); diff --git a/interfaces/kits/napi/ans/src/enable_notification.cpp b/interfaces/kits/napi/ans/src/enable_notification.cpp index f0d943a43..7850a4f8d 100644 --- a/interfaces/kits/napi/ans/src/enable_notification.cpp +++ b/interfaces/kits/napi/ans/src/enable_notification.cpp @@ -22,7 +22,7 @@ const int ENABLE_NOTIFICATION_MIN_PARA = 2; const int IS_NOTIFICATION_ENABLE_MAX_PARA = 2; struct EnableParams { - BundleOption option; + NotificationBundleOption option; bool enable = false; napi_ref callback = nullptr; }; @@ -35,7 +35,7 @@ struct AsyncCallbackInfoEnable { }; struct IsEnableParams { - BundleOption option; + NotificationBundleOption option; napi_ref callback = nullptr; bool hasBundleOption = false; }; @@ -60,24 +60,24 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[0]: bundle napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type.Object expected."); - auto retValue = Common::GetBundleOption(env, argv[0], params.option); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); return nullptr; } // argv[1]: enable - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); - napi_get_value_bool(env, argv[1], ¶ms.enable); + napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); // argv[2]:callback if (argc >= ENABLE_NOTIFICATION_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[ENABLE_NOTIFICATION_MAX_PARA - 1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[ENABLE_NOTIFICATION_MAX_PARA - 1], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); } return Common::NapiGetNull(env); @@ -98,31 +98,53 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[0]: bundle / callback napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, (valuetype == napi_function) || (valuetype == napi_object), "Wrong argument type. Function or object expected."); if (valuetype == napi_object) { - auto retValue = Common::GetBundleOption(env, argv[0], params.option); + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); return nullptr; } params.hasBundleOption = true; } else { - napi_create_reference(env, argv[0], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM0], 1, ¶ms.callback); } // argv[1]:callback if (argc >= IS_NOTIFICATION_ENABLE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } return Common::NapiGetNull(env); } +void AsyncCompleteCallbackEnableNotification(napi_env env, napi_status status, void *data) +{ + ANS_LOGI("enter"); + if (!data) { + ANS_LOGE("Invalid async callback data"); + return; + } + AsyncCallbackInfoEnable *asynccallbackinfo = (AsyncCallbackInfoEnable *)data; + + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + if (asynccallbackinfo) { + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } +} + napi_value EnableNotification(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); @@ -149,30 +171,12 @@ napi_value EnableNotification(napi_env env, napi_callback_info info) [](napi_env env, void *data) { ANS_LOGI("EnableNotification napi_create_async_work start"); AsyncCallbackInfoEnable *asynccallbackinfo = (AsyncCallbackInfoEnable *)data; - NotificationBundleOption bundleOption; - bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); - bundleOption.SetUid(asynccallbackinfo->params.option.uid); - std::string deviceId; + std::string deviceId {""}; asynccallbackinfo->info.errorCode = NotificationHelper::SetNotificationsEnabledForSpecifiedBundle( - bundleOption, deviceId, asynccallbackinfo->params.enable); + asynccallbackinfo->params.option, deviceId, asynccallbackinfo->params.enable); ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d", asynccallbackinfo->info.errorCode); }, - [](napi_env env, napi_status status, void *data) { - ANS_LOGI("EnableNotification napi_create_async_work end"); - AsyncCallbackInfoEnable *asynccallbackinfo = (AsyncCallbackInfoEnable *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - if (asynccallbackinfo) { - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } - }, + AsyncCompleteCallbackEnableNotification, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); @@ -185,6 +189,30 @@ napi_value EnableNotification(napi_env env, napi_callback_info info) } } +void AsyncCompleteCallbackIsNotificationEnabled(napi_env env, napi_status status, void *data) +{ + ANS_LOGI("enter"); + if (!data) { + ANS_LOGE("Invalid async callback data"); + return; + } + AsyncCallbackInfoIsEnable *asynccallbackinfo = (AsyncCallbackInfoIsEnable *)data; + + napi_value result = nullptr; + napi_get_boolean(env, asynccallbackinfo->allowed, &result); + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + if (asynccallbackinfo) { + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } +} + napi_value IsNotificationEnabled(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); @@ -213,39 +241,18 @@ napi_value IsNotificationEnabled(napi_env env, napi_callback_info info) AsyncCallbackInfoIsEnable *asynccallbackinfo = (AsyncCallbackInfoIsEnable *)data; if (asynccallbackinfo->params.hasBundleOption) { - NotificationBundleOption bundleOption; - bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); - bundleOption.SetUid(asynccallbackinfo->params.option.uid); - ANS_LOGI("asynccallbackinfo->params.option.bundle = %{public}s", - asynccallbackinfo->params.option.bundle.c_str()); - ANS_LOGI("asynccallbackinfo->params.option.uid = %{public}d", asynccallbackinfo->params.option.uid); - ANS_LOGI("asynccallbackinfo->allowed = %{public}d", asynccallbackinfo->allowed); + ANS_LOGI("option.bundle = %{public}s option.uid = %{public}d", + asynccallbackinfo->params.option.GetBundleName().c_str(), + asynccallbackinfo->params.option.GetUid()); asynccallbackinfo->info.errorCode = - NotificationHelper::IsAllowedNotify(bundleOption, asynccallbackinfo->allowed); + NotificationHelper::IsAllowedNotify(asynccallbackinfo->params.option, asynccallbackinfo->allowed); } else { - ANS_LOGI("asynccallbackinfo->allowed = %{public}d", asynccallbackinfo->allowed); asynccallbackinfo->info.errorCode = NotificationHelper::IsAllowedNotify(asynccallbackinfo->allowed); } - ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d", asynccallbackinfo->info.errorCode); - }, - [](napi_env env, napi_status status, void *data) { - ANS_LOGI("IsNotificationEnabled napi_create_async_work end"); - AsyncCallbackInfoIsEnable *asynccallbackinfo = (AsyncCallbackInfoIsEnable *)data; - - napi_value result = nullptr; - napi_get_boolean(env, asynccallbackinfo->allowed, &result); - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - if (asynccallbackinfo) { - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } + ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d, allowed = %{public}d", + asynccallbackinfo->info.errorCode, asynccallbackinfo->allowed); }, + AsyncCompleteCallbackIsNotificationEnabled, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); diff --git a/interfaces/kits/napi/ans/src/publish.cpp b/interfaces/kits/napi/ans/src/publish.cpp index d94182cef..b544ea7d8 100644 --- a/interfaces/kits/napi/ans/src/publish.cpp +++ b/interfaces/kits/napi/ans/src/publish.cpp @@ -12,11 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "publish.h" -#include "notification_basic_content.h" -#include "notification_constant.h" -#include "notification_content.h" -#include "notification_normal_content.h" namespace OHOS { namespace NotificationNapi { @@ -56,17 +53,17 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments"); napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); // argv[0] : NotificationRequest - if (Common::GetNotificationRequest(env, argv[0], params.request) == nullptr) { + if (Common::GetNotificationRequest(env, argv[PARAM0], params.request) == nullptr) { return nullptr; } // argv[1] : callback if (argc >= PUBLISH_NOTIFICATION_MAX) { - if (GetCallback(env, argv[1], params) == nullptr) { + if (GetCallback(env, argv[PARAM1], params) == nullptr) { return nullptr; } } diff --git a/interfaces/kits/napi/ans/src/remove.cpp b/interfaces/kits/napi/ans/src/remove.cpp index cd9faf5a4..be24eca7f 100644 --- a/interfaces/kits/napi/ans/src/remove.cpp +++ b/interfaces/kits/napi/ans/src/remove.cpp @@ -13,10 +13,8 @@ * limitations under the License. */ -#include "remove.h" #include -#include "common.h" -#include "notification_bundle_option.h" +#include "remove.h" namespace OHOS { namespace NotificationNapi { @@ -33,7 +31,7 @@ const int REMOVE_GROUP_BY_BUNDLE_MIN_PARA = 2; const int REMOVE_GROUP_BY_BUNDLE_MAX_PARA = 3; struct BundleAndKeyInfo { - BundleOption option; + NotificationBundleOption option; NotificationKey key; }; @@ -51,7 +49,7 @@ struct AsyncCallbackInfoRemove { }; struct RemoveParamsGroupByBundle { - BundleOption option; + NotificationBundleOption option; std::string groupName = ""; napi_ref callback = nullptr; }; @@ -74,7 +72,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_ASSERT(env, argc >= REMOVE_MIN_PARA, "Wrong number of arguments"); napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, (valuetype == napi_string) || (valuetype == napi_object), "Wrong argument type. String or object expected."); @@ -82,28 +80,28 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[0]: hashCode size_t strLen = 0; char str[STR_MAX_SIZE] = {0}; - NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], str, STR_MAX_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, argv[PARAM0], str, STR_MAX_SIZE - 1, &strLen)); params.hashcode = str; // argv[1]:callback if (argc >= REMOVE_OR_BUNDLE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } } else { NAPI_ASSERT(env, argc >= REMOVE_BY_BUNDLE_AND_KEY_MIN_PARA, "Wrong number of arguments"); BundleAndKeyInfo info {}; // argv[0]: BundleOption - auto retValue = Common::GetBundleOption(env, argv[0], info.option); + auto retValue = Common::GetBundleOption(env, argv[PARAM0], info.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); return nullptr; } // argv[1]: NotificationKey - retValue = Common::GetNotificationKey(env, argv[1], info.key); + retValue = Common::GetNotificationKey(env, argv[PARAM1], info.key); if (retValue == nullptr) { ANS_LOGE("GetNotificationKey failed."); return nullptr; @@ -113,9 +111,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[2]:callback if (argc >= REMOVE_BY_BUNDLE_AND_KEY_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[REMOVE_BY_BUNDLE_AND_KEY_MAX_PARA - 1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[REMOVE_BY_BUNDLE_AND_KEY_MAX_PARA - 1], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); } } @@ -136,25 +134,25 @@ napi_value ParseParametersByRemoveAll(const napi_env &env, const napi_callback_i } napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, (valuetype == napi_function) || (valuetype == napi_object), "Wrong argument type. Function or object expected."); if (valuetype == napi_function) { // argv[0]: callback - napi_create_reference(env, argv[0], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM0], 1, ¶ms.callback); } else { BundleAndKeyInfo info {}; // argv[0]: BundleOption - auto retValue = Common::GetBundleOption(env, argv[0], info.option); + auto retValue = Common::GetBundleOption(env, argv[PARAM0], info.option); NAPI_ASSERT(env, retValue != nullptr, "GetBundleOption failed."); params.bundleAndKeyInfo = info; // argv[1]:callback if (argc >= REMOVE_ALL_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } } @@ -174,27 +172,27 @@ napi_value ParseParameters( NAPI_ASSERT(env, argc >= REMOVE_GROUP_BY_BUNDLE_MIN_PARA, "Wrong number of arguments"); // argv[0]: bundle - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type.Object expected."); - auto retValue = Common::GetBundleOption(env, argv[0], params.option); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); return nullptr; } // argv[1]: groupName: string - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; - NAPI_CALL(env, napi_get_value_string_utf8(env, argv[1], str, STR_MAX_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, argv[PARAM1], str, STR_MAX_SIZE - 1, &strLen)); params.groupName = str; // argv[2]:callback if (argc >= REMOVE_GROUP_BY_BUNDLE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[REMOVE_GROUP_BY_BUNDLE_MIN_PARA], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[REMOVE_GROUP_BY_BUNDLE_MIN_PARA], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); } return Common::NapiGetNull(env); @@ -233,9 +231,8 @@ napi_value Remove(napi_env env, napi_callback_info info) } else if (asynccallbackinfo->params.bundleAndKeyInfo.has_value()) { auto &infos = asynccallbackinfo->params.bundleAndKeyInfo.value(); - NotificationBundleOption bundleOption(infos.option.bundle, infos.option.uid); asynccallbackinfo->info.errorCode = - NotificationHelper::RemoveNotification(bundleOption, infos.key.id, infos.key.label); + NotificationHelper::RemoveNotification(infos.option, infos.key.id, infos.key.label); } }, [](napi_env env, napi_status status, void *data) { @@ -296,8 +293,7 @@ napi_value RemoveAll(napi_env env, napi_callback_info info) if (asynccallbackinfo->params.bundleAndKeyInfo.has_value()) { auto &infos = asynccallbackinfo->params.bundleAndKeyInfo.value(); - NotificationBundleOption bundleOption(infos.option.bundle, infos.option.uid); - asynccallbackinfo->info.errorCode = NotificationHelper::RemoveAllNotifications(bundleOption); + asynccallbackinfo->info.errorCode = NotificationHelper::RemoveAllNotifications(infos.option); } else { asynccallbackinfo->info.errorCode = NotificationHelper::RemoveNotifications(); } @@ -330,6 +326,28 @@ napi_value RemoveAll(napi_env env, napi_callback_info info) } } +void AsyncCompleteCallbackRemoveGroupByBundle(napi_env env, napi_status status, void *data) +{ + ANS_LOGI("enter"); + if (!data) { + ANS_LOGE("Invalid async callback data"); + return; + } + AsyncCallbackInfoRemoveGroupByBundle *asynccallbackinfo = (AsyncCallbackInfoRemoveGroupByBundle *)data; + + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + if (asynccallbackinfo) { + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } +} + napi_value RemoveGroupByBundle(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); @@ -356,31 +374,14 @@ napi_value RemoveGroupByBundle(napi_env env, napi_callback_info info) [](napi_env env, void *data) { ANS_LOGI("RemoveGroupByBundle napi_create_async_work start"); AsyncCallbackInfoRemoveGroupByBundle *asynccallbackinfo = (AsyncCallbackInfoRemoveGroupByBundle *)data; - NotificationBundleOption bundleOption( - asynccallbackinfo->params.option.bundle, asynccallbackinfo->params.option.uid); ANS_LOGI("option.bundle = %{public}s, option.uid = %{public}d, groupName = %{public}s", - asynccallbackinfo->params.option.bundle.c_str(), - asynccallbackinfo->params.option.uid, + asynccallbackinfo->params.option.GetBundleName().c_str(), + asynccallbackinfo->params.option.GetUid(), asynccallbackinfo->params.groupName.c_str()); - asynccallbackinfo->info.errorCode = - NotificationHelper::RemoveGroupByBundle(bundleOption, asynccallbackinfo->params.groupName); - }, - [](napi_env env, napi_status status, void *data) { - ANS_LOGI("RemoveGroupByBundle napi_create_async_work end"); - AsyncCallbackInfoRemoveGroupByBundle *asynccallbackinfo = (AsyncCallbackInfoRemoveGroupByBundle *)data; - - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - if (asynccallbackinfo) { - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } + asynccallbackinfo->info.errorCode = NotificationHelper::RemoveGroupByBundle( + asynccallbackinfo->params.option, asynccallbackinfo->params.groupName); }, + AsyncCompleteCallbackRemoveGroupByBundle, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); diff --git a/interfaces/kits/napi/ans/src/slot.cpp b/interfaces/kits/napi/ans/src/slot.cpp index 15d0156b5..7eab91e85 100644 --- a/interfaces/kits/napi/ans/src/slot.cpp +++ b/interfaces/kits/napi/ans/src/slot.cpp @@ -54,7 +54,7 @@ struct AsyncCallbackInfoAddSlots { }; struct ParametersInfoSetSlotByBundle { - BundleOption option; + NotificationBundleOption option; std::vector> slots; napi_ref callback = nullptr; }; @@ -80,7 +80,7 @@ struct AsyncCallbackInfoGetSlot { }; struct ParametersInfoGetSlotNumByBundle { - BundleOption option; + NotificationBundleOption option; napi_ref callback = nullptr; }; @@ -100,7 +100,7 @@ struct AsyncCallbackInfoGetSlots { }; struct ParametersInfoGetSlotsByBundle { - BundleOption option; + NotificationBundleOption option; napi_ref callback = nullptr; }; @@ -141,28 +141,28 @@ napi_value ParseParametersByAddSlot(const napi_env &env, const napi_callback_inf napi_valuetype valuetype = napi_undefined; // argv[0]: NotificationSlot - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT( env, (valuetype == napi_object || valuetype == napi_number), "Wrong argument type. Object or number expected."); if (valuetype == napi_number) { paras.isAddSlotByType = true; int slotType = 0; - napi_get_value_int32(env, argv[0], &slotType); + napi_get_value_int32(env, argv[PARAM0], &slotType); if (!Common::SlotTypeJSToC(SlotType(slotType), paras.inType)) { return nullptr; } } else { paras.isAddSlotByType = false; - if (!Common::GetNotificationSlot(env, argv[0], paras.slot)) { + if (!Common::GetNotificationSlot(env, argv[PARAM0], paras.slot)) { return nullptr; } } // argv[1]:callback if (argc >= ADD_SLOT_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶s.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶s.callback); } return Common::NapiGetNull(env); } @@ -179,14 +179,14 @@ napi_value ParseParametersByAddSlots(const napi_env &env, const napi_callback_in napi_valuetype valuetype = napi_undefined; // argv[0]: Array bool isArray = false; - napi_is_array(env, argv[0], &isArray); + napi_is_array(env, argv[PARAM0], &isArray); NAPI_ASSERT(env, isArray, "Wrong argument type. Array expected."); uint32_t length = 0; - napi_get_array_length(env, argv[0], &length); + napi_get_array_length(env, argv[PARAM0], &length); NAPI_ASSERT(env, length > 0, "The array is empty."); for (size_t i = 0; i < length; i++) { napi_value nSlot = nullptr; - napi_get_element(env, argv[0], i, &nSlot); + napi_get_element(env, argv[PARAM0], i, &nSlot); NAPI_CALL(env, napi_typeof(env, nSlot, &valuetype)); NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); NotificationSlot slot; @@ -198,9 +198,9 @@ napi_value ParseParametersByAddSlots(const napi_env &env, const napi_callback_in // argv[1]:callback if (argc >= ADD_SLOTS_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶s.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶s.callback); } return Common::NapiGetNull(env); } @@ -218,19 +218,19 @@ napi_value ParseParametersSetSlotByBundle( NAPI_ASSERT(env, argc >= SET_SLOT_AS_BUNDLE_MAX_PARA - 1, "Wrong number of arguments"); // argv[0]: bundle - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type.Object expected."); - auto retValue = Common::GetBundleOption(env, argv[0], params.option); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); return nullptr; } // argv[1]: slot - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type.Object expected."); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); NotificationSlot slot; - if (!Common::GetNotificationSlot(env, argv[1], slot)) { + if (!Common::GetNotificationSlot(env, argv[PARAM1], slot)) { return nullptr; } std::vector slots; @@ -247,9 +247,9 @@ napi_value ParseParametersSetSlotByBundle( // argv[2]:callback if (argc >= SET_SLOT_AS_BUNDLE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[SET_SLOT_AS_BUNDLE_MAX_PARA - 1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[SET_SLOT_AS_BUNDLE_MAX_PARA - 1], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); } return Common::NapiGetNull(env); @@ -266,19 +266,19 @@ napi_value ParseParametersByGetSlot(const napi_env &env, const napi_callback_inf napi_valuetype valuetype = napi_undefined; // argv[0]: SlotType - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); int slotType = 0; - napi_get_value_int32(env, argv[0], &slotType); + napi_get_value_int32(env, argv[PARAM0], &slotType); if (!Common::SlotTypeJSToC(SlotType(slotType), paras.outType)) { return nullptr; } // argv[1]:callback if (argc >= GET_SLOT_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶s.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶s.callback); } return Common::NapiGetNull(env); } @@ -296,9 +296,9 @@ napi_value ParseParametersGetSlotNumByBundle( NAPI_ASSERT(env, argc >= GET_SLOT_NUM_AS_BUNDLE_MAX_PARA - 1, "Wrong number of arguments"); // argv[0]: bundle - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type.Object expected."); - auto retValue = Common::GetBundleOption(env, argv[0], params.option); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); return nullptr; @@ -306,9 +306,9 @@ napi_value ParseParametersGetSlotNumByBundle( // argv[1]:callback if (argc >= GET_SLOT_NUM_AS_BUNDLE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } return Common::NapiGetNull(env); @@ -327,9 +327,9 @@ napi_value ParseParametersGetSlotsByBundle( NAPI_ASSERT(env, argc >= GET_SLOTS_AS_BUNDLE_MAX_PARA - 1, "Wrong number of arguments"); // argv[0]: bundle - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type.Object expected."); - auto retValue = Common::GetBundleOption(env, argv[0], params.option); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); return nullptr; @@ -337,9 +337,9 @@ napi_value ParseParametersGetSlotsByBundle( // argv[1]:callback if (argc >= GET_SLOTS_AS_BUNDLE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶ms.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } return Common::NapiGetNull(env); @@ -357,19 +357,19 @@ napi_value ParseParametersByRemoveSlot( napi_valuetype valuetype = napi_undefined; // argv[0]: SlotType - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); int slotType = 0; - napi_get_value_int32(env, argv[0], &slotType); + napi_get_value_int32(env, argv[PARAM0], &slotType); if (!Common::SlotTypeJSToC(SlotType(slotType), paras.outType)) { return nullptr; } // argv[1]:callback if (argc >= REMOVE_SLOT_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶s.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶s.callback); } return Common::NapiGetNull(env); } @@ -522,11 +522,8 @@ napi_value SetSlotByBundle(napi_env env, napi_callback_info info) ANS_LOGI("SetSlotByBundle napi_create_async_work start"); auto asynccallbackinfo = (AsyncCallbackInfoSetSlotByBundle *)data; - NotificationBundleOption bundleOption; - bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); - bundleOption.SetUid(asynccallbackinfo->params.option.uid); - asynccallbackinfo->info.errorCode = - NotificationHelper::UpdateNotificationSlots(bundleOption, asynccallbackinfo->params.slots); + asynccallbackinfo->info.errorCode = NotificationHelper::UpdateNotificationSlots( + asynccallbackinfo->params.option, asynccallbackinfo->params.slots); }, [](napi_env env, napi_status status, void *data) { ANS_LOGI("SetSlotByBundle napi_create_async_work end"); @@ -662,11 +659,8 @@ napi_value GetSlotNumByBundle(napi_env env, napi_callback_info info) ANS_LOGI("GetSlotNumByBundle napi_create_async_work start"); auto asynccallbackinfo = (AsyncCallbackInfoGetSlotNumByBundle *)data; - NotificationBundleOption bundleOption; - bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); - bundleOption.SetUid(asynccallbackinfo->params.option.uid); - asynccallbackinfo->info.errorCode = - NotificationHelper::GetNotificationSlotNumAsBundle(bundleOption, asynccallbackinfo->num); + asynccallbackinfo->info.errorCode = NotificationHelper::GetNotificationSlotNumAsBundle( + asynccallbackinfo->params.option, asynccallbackinfo->num); }, [](napi_env env, napi_status status, void *data) { ANS_LOGI("GetSlotNumByBundle napi_create_async_work end"); @@ -697,6 +691,54 @@ napi_value GetSlotNumByBundle(napi_env env, napi_callback_info info) } } +void AsyncCompleteCallbackGetSlots(napi_env env, napi_status status, void *data) +{ + ANS_LOGI("enter"); + if (!data) { + ANS_LOGE("Invalid async callback data"); + return; + } + napi_value result = nullptr; + auto asynccallbackinfo = (AsyncCallbackInfoGetSlots *)data; + if (asynccallbackinfo->info.errorCode != ERR_OK) { + result = Common::NapiGetNull(env); + } else { + napi_value arr = nullptr; + napi_create_array(env, &arr); + size_t count = 0; + for (auto vec : asynccallbackinfo->slots) { + if (!vec) { + ANS_LOGW("Invalid NotificationSlot object ptr"); + continue; + } + napi_value nSlot = nullptr; + napi_create_object(env, &nSlot); + if (!Common::SetNotificationSlot(env, *vec, nSlot)) { + continue; + } + napi_set_element(env, arr, count, nSlot); + count++; + } + ANS_LOGI("getSlots count = %{public}zu", count); + result = arr; + if ((count == 0) && (asynccallbackinfo->slots.size() > 0)) { + asynccallbackinfo->info.errorCode = ERROR; + result = Common::NapiGetNull(env); + } + } + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + if (asynccallbackinfo) { + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } +} + napi_value GetSlots(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); @@ -725,48 +767,7 @@ napi_value GetSlots(napi_env env, napi_callback_info info) auto asynccallbackinfo = (AsyncCallbackInfoGetSlots *)data; asynccallbackinfo->info.errorCode = NotificationHelper::GetNotificationSlots(asynccallbackinfo->slots); }, - [](napi_env env, napi_status status, void *data) { - ANS_LOGI("GetSlots napi_create_async_work end"); - auto asynccallbackinfo = (AsyncCallbackInfoGetSlots *)data; - napi_value result = nullptr; - if (asynccallbackinfo->info.errorCode != ERR_OK) { - result = Common::NapiGetNull(env); - } else { - napi_value arr = nullptr; - napi_create_array(env, &arr); - size_t count = 0; - for (auto vec : asynccallbackinfo->slots) { - if (!vec) { - ANS_LOGW("Invalid NotificationSlot object ptr"); - continue; - } - napi_value nSlot = nullptr; - napi_create_object(env, &nSlot); - if (!Common::SetNotificationSlot(env, *vec, nSlot)) { - continue; - } - napi_set_element(env, arr, count, nSlot); - count++; - } - ANS_LOGI("getSlots count = %{public}zu", count); - result = arr; - if ((count == 0) && (asynccallbackinfo->slots.size() > 0)) { - asynccallbackinfo->info.errorCode = ERROR; - result = Common::NapiGetNull(env); - } - } - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - if (asynccallbackinfo) { - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } - }, + AsyncCompleteCallbackGetSlots, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); @@ -779,6 +780,54 @@ napi_value GetSlots(napi_env env, napi_callback_info info) } } +void AsyncCompleteCallbackGetSlotsByBundle(napi_env env, napi_status status, void *data) +{ + ANS_LOGI("enter"); + if (!data) { + ANS_LOGE("Invalid async callback data"); + return; + } + napi_value result = nullptr; + auto asynccallbackinfo = (AsyncCallbackInfoGetSlotsByBundle *)data; + if (asynccallbackinfo->info.errorCode != ERR_OK) { + result = Common::NapiGetNull(env); + } else { + napi_value arr = nullptr; + napi_create_array(env, &arr); + size_t count = 0; + for (auto vec : asynccallbackinfo->slots) { + if (!vec) { + ANS_LOGW("Invalid NotificationSlot object ptr"); + continue; + } + napi_value nSlot = nullptr; + napi_create_object(env, &nSlot); + if (!Common::SetNotificationSlot(env, *vec, nSlot)) { + continue; + } + napi_set_element(env, arr, count, nSlot); + count++; + } + ANS_LOGI("getSlots count = %{public}zu", count); + result = arr; + if ((count == 0) && (asynccallbackinfo->slots.size() > 0)) { + asynccallbackinfo->info.errorCode = ERROR; + result = Common::NapiGetNull(env); + } + } + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + if (asynccallbackinfo) { + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } +} + napi_value GetSlotsByBundle(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); @@ -806,55 +855,10 @@ napi_value GetSlotsByBundle(napi_env env, napi_callback_info info) ANS_LOGI("GetSlotsByBundle napi_create_async_work start"); auto asynccallbackinfo = (AsyncCallbackInfoGetSlotsByBundle *)data; - NotificationBundleOption bundleOption; - bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); - bundleOption.SetUid(asynccallbackinfo->params.option.uid); - asynccallbackinfo->info.errorCode = - NotificationHelper::GetNotificationSlotsForBundle(bundleOption, asynccallbackinfo->slots); - }, - [](napi_env env, napi_status status, void *data) { - ANS_LOGI("GetSlotsByBundle napi_create_async_work end"); - auto asynccallbackinfo = (AsyncCallbackInfoGetSlotsByBundle *)data; - - napi_value result = nullptr; - if (asynccallbackinfo->info.errorCode != ERR_OK) { - result = Common::NapiGetNull(env); - } else { - napi_value arr = nullptr; - napi_create_array(env, &arr); - size_t count = 0; - for (auto vec : asynccallbackinfo->slots) { - if (!vec) { - ANS_LOGW("Invalid NotificationSlot object ptr"); - continue; - } - napi_value nSlot = nullptr; - napi_create_object(env, &nSlot); - if (!Common::SetNotificationSlot(env, *vec, nSlot)) { - continue; - } - napi_set_element(env, arr, count, nSlot); - count++; - } - ANS_LOGI("getSlots count = %{public}zu", count); - result = arr; - if ((count == 0) && (asynccallbackinfo->slots.size() > 0)) { - asynccallbackinfo->info.errorCode = ERROR; - result = Common::NapiGetNull(env); - } - } - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); - - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - if (asynccallbackinfo) { - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } + asynccallbackinfo->info.errorCode = NotificationHelper::GetNotificationSlotsForBundle( + asynccallbackinfo->params.option, asynccallbackinfo->slots); }, + AsyncCompleteCallbackGetSlotsByBundle, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); diff --git a/interfaces/kits/napi/ans/src/subscribe.cpp b/interfaces/kits/napi/ans/src/subscribe.cpp index d35db6290..8573dcb04 100644 --- a/interfaces/kits/napi/ans/src/subscribe.cpp +++ b/interfaces/kits/napi/ans/src/subscribe.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include #include +#include #include "subscribe.h" namespace OHOS { @@ -957,12 +957,12 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_valuetype valuetype = napi_undefined; // argv[0]:subscriber - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type for arg0. NotificationSubscriber object expected."); SubscriberInstancesInfo subscriberInstancesInfo; - if (!HasNotificationSubscriber(env, argv[0], subscriberInstancesInfo)) { - if (GetNotificationSubscriber(env, argv[0], subscriberInstancesInfo) == nullptr) { + if (!HasNotificationSubscriber(env, argv[PARAM0], subscriberInstancesInfo)) { + if (GetNotificationSubscriber(env, argv[PARAM0], subscriberInstancesInfo) == nullptr) { ANS_LOGE("NotificationSubscriber parse failed"); if (subscriberInstancesInfo.subscriber) { delete subscriberInstancesInfo.subscriber; @@ -983,14 +983,14 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[1]:callback or NotificationSubscribeInfo if (argc >= SUBSRIBE_MAX_PARA - 1) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, (valuetype == napi_function) || (valuetype == napi_object), "Wrong argument type for arg1. Function or NotificationSubscribeInfo object expected."); if (valuetype == napi_function) { - napi_create_reference(env, argv[1], 1, &callback); + napi_create_reference(env, argv[PARAM1], 1, &callback); } else { - if (Common::GetNotificationSubscriberInfo(env, argv[1], subscriberInfo) == nullptr) { + if (Common::GetNotificationSubscriberInfo(env, argv[PARAM1], subscriberInfo) == nullptr) { ANS_LOGE("NotificationSubscribeInfo parse failed"); return nullptr; } @@ -999,9 +999,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[2]:callback if (argc >= SUBSRIBE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[SUBSRIBE_MAX_PARA - 1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[SUBSRIBE_MAX_PARA - 1], 1, &callback); + napi_create_reference(env, argv[PARAM2], 1, &callback); } return Common::NapiGetNull(env); diff --git a/interfaces/kits/napi/ans/src/unsubscribe.cpp b/interfaces/kits/napi/ans/src/unsubscribe.cpp index bd500e332..7ffc15278 100644 --- a/interfaces/kits/napi/ans/src/unsubscribe.cpp +++ b/interfaces/kits/napi/ans/src/unsubscribe.cpp @@ -45,11 +45,11 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_valuetype valuetype = napi_undefined; // argv[0]:subscriber - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type for arg0. Subscribe object expected."); SubscriberInstancesInfo subscriberInstancesInfo; - if (!HasNotificationSubscriber(env, argv[0], subscriberInstancesInfo)) { + if (!HasNotificationSubscriber(env, argv[PARAM0], subscriberInstancesInfo)) { ANS_LOGW("Subscriber not found"); } @@ -58,9 +58,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[1]:callback if (argc >= UNSUBSCRIBE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶s.callback); + napi_create_reference(env, argv[PARAM1], 1, ¶s.callback); } return Common::NapiGetNull(env); @@ -84,7 +84,7 @@ napi_value Unsubscribe(napi_env env, napi_callback_info info) Common::PaddingCallbackPromiseInfo(env, paras.callback, asynccallbackinfo->info, promise); napi_value resourceName = nullptr; - napi_create_string_latin1(env, "Unsubscribe", NAPI_AUTO_LENGTH, &resourceName); + napi_create_string_latin1(env, "unsubscribe", NAPI_AUTO_LENGTH, &resourceName); // Asynchronous function call napi_create_async_work(env, diff --git a/sa_profile/3203.xml b/sa_profile/3203.xml old mode 100755 new mode 100644 diff --git a/services/ans/test/unittest/mock/blob.cpp b/services/ans/test/unittest/mock/blob.cpp old mode 100755 new mode 100644 diff --git a/services/ans/test/unittest/mock/include/mock_ipc_skeleton.h b/services/ans/test/unittest/mock/include/mock_ipc_skeleton.h old mode 100755 new mode 100644 diff --git a/services/test/moduletest/mock/blob.cpp b/services/test/moduletest/mock/blob.cpp old mode 100755 new mode 100644 diff --git a/test/common/acts/actsnotificationfuzztest/BUILD.gn b/test/common/acts/actsnotificationfuzztest/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/resource/ansSlotGroupHap/AnsSTSlotGroupTest.hap b/test/resource/ansSlotGroupHap/AnsSTSlotGroupTest.hap old mode 100755 new mode 100644 -- Gitee From c872cb4e41639d1fab80c86d220e0b2d05512adc Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Sat, 18 Dec 2021 11:53:58 +0000 Subject: [PATCH 2/2] Fix codex Signed-off-by: zhaoyuan17 --- .../ans/native/include/notification_user_input.h | 12 ++++++++---- interfaces/kits/napi/ans/src/remove.cpp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/interfaces/innerkits/ans/native/include/notification_user_input.h b/interfaces/innerkits/ans/native/include/notification_user_input.h index 74420e956..e432cd2e0 100644 --- a/interfaces/innerkits/ans/native/include/notification_user_input.h +++ b/interfaces/innerkits/ans/native/include/notification_user_input.h @@ -81,7 +81,8 @@ public: public: /** * A static function used to create a NotificationUserInput instance with the input parameters passed. - * @param inputKey Indicates the AAFwk::WantParams key used to identify this input when the input is collected from the user. + * @param inputKey Indicates the AAFwk::WantParams key used to identify this input + * when the input is collected from the user. * @return the shared_ptr object owns the created NotificationUserInput object otherwise return empty object if * inputKey is empty. */ @@ -89,7 +90,8 @@ public: /** * A static function used to create a NotificationUserInput instance with the input parameters passed. - * @param inputKey Indicates the AAFwk::WantParams key used to identify this input when the input is collected from the user. + * @param inputKey Indicates the AAFwk::WantParams key used to identify this input + * when the input is collected from the user. * @param tag Indicates the tag to be displayed. * @param options Indicates the list of predefined options to be provided for user input. * @param permitFreeFormInput Specifies whether to allow arbitrary text values. The default value is true, @@ -231,13 +233,15 @@ private: /** * A constructor used to create a NotificationUserInput instance with the input parameters passed. - * @param inputKey Indicates the AAFwk::WantParams key used to identify this input when the input is collected from the user. + * @param inputKey Indicates the AAFwk::WantParams key used to identify this input + * when the input is collected from the user. */ explicit NotificationUserInput(const std::string &inputKey); /** * A constructor used to create a NotificationUserInput instance with the input parameters passed. - * @param inputKey Indicates the AAFwk::WantParams key used to identify this input when the input is collected from the user. + * @param inputKey Indicates the AAFwk::WantParams key used to identify this input + * when the input is collected from the user. * @param tag Indicates the tag to be displayed. * @param options Indicates the list of predefined options to be provided for user input. * @param permitFreeFormInput Specifies whether to allow arbitrary text values. The default value is true, diff --git a/interfaces/kits/napi/ans/src/remove.cpp b/interfaces/kits/napi/ans/src/remove.cpp index be24eca7f..0757bbea3 100644 --- a/interfaces/kits/napi/ans/src/remove.cpp +++ b/interfaces/kits/napi/ans/src/remove.cpp @@ -379,7 +379,7 @@ napi_value RemoveGroupByBundle(napi_env env, napi_callback_info info) asynccallbackinfo->params.option.GetUid(), asynccallbackinfo->params.groupName.c_str()); asynccallbackinfo->info.errorCode = NotificationHelper::RemoveGroupByBundle( - asynccallbackinfo->params.option, asynccallbackinfo->params.groupName); + asynccallbackinfo->params.option, asynccallbackinfo->params.groupName); }, AsyncCompleteCallbackRemoveGroupByBundle, (void *)asynccallbackinfo, -- Gitee