From 5b12a8ecb9087c389a2aed7b1d90bb169b73f34c Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Sat, 18 Sep 2021 19:47:13 +0800 Subject: [PATCH 1/2] fix codex Signed-off-by: zhaoyuan17 --- frameworks/ans/core/src/ans_notification.cpp | 4 +- .../native/src/notification_action_button.cpp | 8 +- .../native/src/notification_bundle_option.cpp | 2 +- .../ans/native/src/notification_constant.cpp | 2 +- .../ans/native/src/notification_helper.cpp | 2 +- .../src/notification_long_text_content.cpp | 2 +- .../native/src/notification_media_content.cpp | 24 +- .../src/notification_multiline_content.cpp | 4 +- .../ans/native/src/notification_request.cpp | 50 +- .../ans/native/src/notification_sorting.cpp | 2 +- .../native/src/notification_user_input.cpp | 2 +- .../test/moduletest/ans_fw_module_test.cpp | 32 +- .../ans_innerkits_module_publish_test.cpp | 5 +- frameworks/wantagent/src/pending_want.cpp | 4 +- frameworks/wantagent/src/want_agent_info.cpp | 1 - .../ans/native/include/notification.h | 20 +- .../include/notification_action_button.h | 21 +- .../include/notification_basic_content.h | 6 +- .../ans/native/include/notification_content.h | 4 +- .../notification_conversational_content.h | 8 +- .../notification_conversational_message.h | 10 +- .../include/notification_long_text_content.h | 6 +- .../include/notification_media_content.h | 4 +- .../include/notification_multiline_content.h | 6 +- .../include/notification_picture_content.h | 6 +- .../ans/native/include/notification_request.h | 110 +- .../ans/native/include/notification_slot.h | 22 +- .../ans/native/include/notification_sorting.h | 16 +- .../native/include/notification_sorting_map.h | 4 +- .../include/notification_subscribe_info.h | 2 +- .../native/include/notification_subscriber.h | 6 +- .../native/include/notification_user_input.h | 14 +- .../wantagent/include/pending_want.h | 2 +- interfaces/kits/napi/ans/include/common.h | 1 - interfaces/kits/napi/ans/include/init.h | 2 +- interfaces/kits/napi/ans/src/cancel.cpp | 4 +- interfaces/kits/napi/ans/src/common.cpp | 6 +- .../kits/napi/ans/src/display_badge.cpp | 8 +- interfaces/kits/napi/ans/src/disturb_mode.cpp | 4 +- .../kits/napi/ans/src/enable_notification.cpp | 8 +- interfaces/kits/napi/ans/src/get_active.cpp | 6 +- interfaces/kits/napi/ans/src/publish.cpp | 2 +- interfaces/kits/napi/ans/src/remove.cpp | 18 +- interfaces/kits/napi/ans/src/slot.cpp | 28 +- interfaces/kits/napi/ans/src/subscribe.cpp | 21 +- interfaces/kits/napi/ans/src/unsubscribe.cpp | 2 +- .../kits/napi/wantagent/napi_want_agent.cpp | 1215 +++++++++-------- .../kits/napi/wantagent/napi_want_agent.h | 7 +- .../kits/napi/wantagent/native_module.cpp | 6 +- .../src/notification_preferences_database.cpp | 4 +- .../notification_preferences_test.cpp | 6 +- 51 files changed, 917 insertions(+), 842 deletions(-) diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index fd203213c..da55aed92 100644 --- a/frameworks/ans/core/src/ans_notification.cpp +++ b/frameworks/ans/core/src/ans_notification.cpp @@ -512,7 +512,7 @@ ErrCode AnsNotification::RemoveNotification(const std::string &key) } ErrCode AnsNotification::RemoveNotification( - const NotificationBundleOption &bundleOption, const int32_t notificationId, const std::string &label) + const NotificationBundleOption &bundleOption, const int32_t notificationId, const std::string &label) { if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); @@ -572,7 +572,7 @@ ErrCode AnsNotification::GetNotificationSlotsForBundle( } ErrCode AnsNotification::UpdateNotificationSlots( - const NotificationBundleOption &bundleOption, const std::vector> &slots) + const NotificationBundleOption &bundleOption, const std::vector> &slots) { if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); diff --git a/frameworks/ans/native/src/notification_action_button.cpp b/frameworks/ans/native/src/notification_action_button.cpp index b0c004d71..4c114748e 100644 --- a/frameworks/ans/native/src/notification_action_button.cpp +++ b/frameworks/ans/native/src/notification_action_button.cpp @@ -42,7 +42,7 @@ std::shared_ptr NotificationActionButton::Create(const } std::vector> onlyInputs = mimeTypeOnlyInputs; - std::vector> textInputs{}; + std::vector> textInputs {}; for (auto &userInput : userInputs) { if (!userInput) { continue; @@ -222,7 +222,7 @@ bool NotificationActionButton::Marshalling(Parcel &parcel) const return false; } - bool valid{false}; + bool valid {false}; valid = icon_ ? true : false; if (!parcel.WriteBool(valid)) { @@ -310,7 +310,7 @@ bool NotificationActionButton::ReadFromParcel(Parcel &parcel) semanticActionButton_ = static_cast(parcel.ReadInt32()); - bool valid{false}; + bool valid {false}; valid = parcel.ReadBool(); if (valid) { @@ -342,7 +342,7 @@ bool NotificationActionButton::ReadFromParcel(Parcel &parcel) auto vsize = parcel.ReadInt32(); for (auto it = 0; it < vsize; ++it) { valid = parcel.ReadBool(); - NotificationUserInput *member{nullptr}; + NotificationUserInput *member {nullptr}; if (valid) { member = parcel.ReadParcelable(); if (nullptr == member) { diff --git a/frameworks/ans/native/src/notification_bundle_option.cpp b/frameworks/ans/native/src/notification_bundle_option.cpp index acdfc939c..b5adae94e 100644 --- a/frameworks/ans/native/src/notification_bundle_option.cpp +++ b/frameworks/ans/native/src/notification_bundle_option.cpp @@ -46,7 +46,7 @@ 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_constant.cpp b/frameworks/ans/native/src/notification_constant.cpp index 744dc11f6..43f23d63c 100644 --- a/frameworks/ans/native/src/notification_constant.cpp +++ b/frameworks/ans/native/src/notification_constant.cpp @@ -17,7 +17,7 @@ namespace OHOS { namespace Notification { -const std::string NotificationConstant::EXTRA_INPUTS_SOURCE{"notification_user_input_source"}; +const std::string NotificationConstant::EXTRA_INPUTS_SOURCE {"notification_user_input_source"}; } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/native/src/notification_helper.cpp b/frameworks/ans/native/src/notification_helper.cpp index 86ea093d9..87d459c55 100644 --- a/frameworks/ans/native/src/notification_helper.cpp +++ b/frameworks/ans/native/src/notification_helper.cpp @@ -210,7 +210,7 @@ ErrCode NotificationHelper::RemoveNotification(const std::string &key) } ErrCode NotificationHelper::RemoveNotification( - const NotificationBundleOption &bundleOption, const int32_t notificationId, const std::string &label) + const NotificationBundleOption &bundleOption, const int32_t notificationId, const std::string &label) { return DelayedSingleton::GetInstance()->RemoveNotification(bundleOption, notificationId, label); } diff --git a/frameworks/ans/native/src/notification_long_text_content.cpp b/frameworks/ans/native/src/notification_long_text_content.cpp index f17afa07b..c806df2ef 100644 --- a/frameworks/ans/native/src/notification_long_text_content.cpp +++ b/frameworks/ans/native/src/notification_long_text_content.cpp @@ -19,7 +19,7 @@ namespace OHOS { namespace Notification { -const std::size_t NotificationLongTextContent::MAX_LONGTEXT_LENGTH{1024}; +const std::size_t NotificationLongTextContent::MAX_LONGTEXT_LENGTH {1024}; NotificationLongTextContent::NotificationLongTextContent(const std::string &longText) { diff --git a/frameworks/ans/native/src/notification_media_content.cpp b/frameworks/ans/native/src/notification_media_content.cpp index f6d3e65b3..d66b8bc7a 100644 --- a/frameworks/ans/native/src/notification_media_content.cpp +++ b/frameworks/ans/native/src/notification_media_content.cpp @@ -41,7 +41,7 @@ std::vector NotificationMediaContent::GetShownActions() const std::string NotificationMediaContent::Dump() { - std::string numbers{}; + std::string numbers {}; std::for_each(sequenceNumbers_.begin(), sequenceNumbers_.end(), [&numbers](int32_t num) { numbers += std::to_string(num) + " "; }); @@ -57,19 +57,6 @@ bool NotificationMediaContent::Marshalling(Parcel &parcel) const return false; } - // auto valid = avToken_ ? true : false; - // if (!parcel.WriteBool(valid)) { - // ANS_LOGE("Failed to write the flag which indicate whether avToken is null"); - // return false; - // } - - // if (valid) { - // if (!parcel.WriteParcelable(avToken_.get())) { - // ANS_LOGE("Failed to write avToken"); - // return false; - // } - // } - if (!parcel.WriteUInt32Vector(sequenceNumbers_)) { ANS_LOGE("Failed to write sequence numbers"); return false; @@ -96,15 +83,6 @@ bool NotificationMediaContent::ReadFromParcel(Parcel &parcel) return false; } - // auto valid = parcel.ReadBool(); - // if (valid) { - // avToken_ = std::shared_ptr(parcel.ReadParcelable()); - // if (!avToken_) { - // ANS_LOGE("Failed to read avToken"); - // return false; - // } - // } - if (!parcel.ReadUInt32Vector(&sequenceNumbers_)) { ANS_LOGE("Failed to read sequence numbers"); return false; diff --git a/frameworks/ans/native/src/notification_multiline_content.cpp b/frameworks/ans/native/src/notification_multiline_content.cpp index 4d0df649d..abd88be57 100644 --- a/frameworks/ans/native/src/notification_multiline_content.cpp +++ b/frameworks/ans/native/src/notification_multiline_content.cpp @@ -19,7 +19,7 @@ namespace OHOS { namespace Notification { -const std::vector::size_type NotificationMultiLineContent::MAX_LINES{7}; +const std::vector::size_type NotificationMultiLineContent::MAX_LINES {7}; void NotificationMultiLineContent::SetExpandedTitle(const std::string &exTitle) { @@ -58,7 +58,7 @@ std::vector NotificationMultiLineContent::GetAllLines() const std::string NotificationMultiLineContent::Dump() { - std::string lines{}; + std::string lines {}; std::for_each( allLines_.begin(), allLines_.end(), [&lines](const std::string &line) { lines += " " + line + ","; }); lines.pop_back(); diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index 02c7e1e4c..b346882bd 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -20,28 +20,28 @@ namespace OHOS { namespace Notification { -const std::string NotificationRequest::CLASSIFICATION_ALARM{"alarm"}; -const std::string NotificationRequest::CLASSIFICATION_CALL{"call"}; -const std::string NotificationRequest::CLASSIFICATION_EMAIL{"email"}; -const std::string NotificationRequest::CLASSIFICATION_ERROR{"err"}; -const std::string NotificationRequest::CLASSIFICATION_EVENT{"event"}; -const std::string NotificationRequest::CLASSIFICATION_MESSAGE{"msg"}; -const std::string NotificationRequest::CLASSIFICATION_NAVIGATION{"navigation"}; -const std::string NotificationRequest::CLASSIFICATION_PROGRESS{"progress"}; -const std::string NotificationRequest::CLASSIFICATION_PROMO{"promo"}; -const std::string NotificationRequest::CLASSIFICATION_RECOMMENDATION{"recommendation"}; -const std::string NotificationRequest::CLASSIFICATION_REMINDER{"reminder"}; -const std::string NotificationRequest::CLASSIFICATION_SERVICE{"service"}; -const std::string NotificationRequest::CLASSIFICATION_SOCIAL{"social"}; -const std::string NotificationRequest::CLASSIFICATION_STATUS{"status"}; -const std::string NotificationRequest::CLASSIFICATION_SYSTEM{"sys"}; -const std::string NotificationRequest::CLASSIFICATION_TRANSPORT{"transport"}; - -const uint32_t NotificationRequest::COLOR_DEFAULT{0}; - -const uint32_t NotificationRequest::COLOR_MASK{0xFF000000}; -const std::size_t NotificationRequest::MAX_USER_INPUT_HISTORY{5}; -const std::size_t NotificationRequest::MAX_ACTION_BUTTONS{3}; +const std::string NotificationRequest::CLASSIFICATION_ALARM {"alarm"}; +const std::string NotificationRequest::CLASSIFICATION_CALL {"call"}; +const std::string NotificationRequest::CLASSIFICATION_EMAIL {"email"}; +const std::string NotificationRequest::CLASSIFICATION_ERROR {"err"}; +const std::string NotificationRequest::CLASSIFICATION_EVENT {"event"}; +const std::string NotificationRequest::CLASSIFICATION_MESSAGE {"msg"}; +const std::string NotificationRequest::CLASSIFICATION_NAVIGATION {"navigation"}; +const std::string NotificationRequest::CLASSIFICATION_PROGRESS {"progress"}; +const std::string NotificationRequest::CLASSIFICATION_PROMO {"promo"}; +const std::string NotificationRequest::CLASSIFICATION_RECOMMENDATION {"recommendation"}; +const std::string NotificationRequest::CLASSIFICATION_REMINDER {"reminder"}; +const std::string NotificationRequest::CLASSIFICATION_SERVICE {"service"}; +const std::string NotificationRequest::CLASSIFICATION_SOCIAL {"social"}; +const std::string NotificationRequest::CLASSIFICATION_STATUS {"status"}; +const std::string NotificationRequest::CLASSIFICATION_SYSTEM {"sys"}; +const std::string NotificationRequest::CLASSIFICATION_TRANSPORT {"transport"}; + +const uint32_t NotificationRequest::COLOR_DEFAULT {0}; + +const uint32_t NotificationRequest::COLOR_MASK {0xFF000000}; +const std::size_t NotificationRequest::MAX_USER_INPUT_HISTORY {5}; +const std::size_t NotificationRequest::MAX_ACTION_BUTTONS {3}; NotificationRequest::NotificationRequest(int32_t notificationId) : notificationId_(notificationId) { @@ -943,12 +943,12 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const if (!parcel.WriteBool(permitted_)) { ANS_LOGE("Failed to write flag indicating whether to allow the platform to \ - generate contextual NotificationActionButton objects"); + generate contextual NotificationActionButton objects"); return false; } // write objects which managed by std::shared_ptr - bool valid{false}; + bool valid {false}; valid = wantAgent_ ? true : false; if (!parcel.WriteBool(valid)) { @@ -1177,7 +1177,7 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) onlyLocal_ = parcel.ReadBool(); permitted_ = parcel.ReadBool(); - bool valid{false}; + bool valid {false}; valid = parcel.ReadBool(); if (valid) { diff --git a/frameworks/ans/native/src/notification_sorting.cpp b/frameworks/ans/native/src/notification_sorting.cpp index 6315d338d..0ff27d780 100644 --- a/frameworks/ans/native/src/notification_sorting.cpp +++ b/frameworks/ans/native/src/notification_sorting.cpp @@ -49,7 +49,7 @@ void NotificationSorting::SetGroupKeyOverride(const std::string &groupKeyOverrid std::string NotificationSorting::Dump() const { - std::string contents{""}; + std::string contents {""}; if (slot_ != nullptr) { contents = slot_->Dump(); } else { diff --git a/frameworks/ans/native/src/notification_user_input.cpp b/frameworks/ans/native/src/notification_user_input.cpp index e14dd2f75..0115c3ba4 100644 --- a/frameworks/ans/native/src/notification_user_input.cpp +++ b/frameworks/ans/native/src/notification_user_input.cpp @@ -321,7 +321,7 @@ bool NotificationUserInput::ReadFromParcel(Parcel &parcel) auto ssize = parcel.ReadInt32(); for (auto it = 0; it < ssize; ++it) { - std::string member{}; + std::string member {}; if (!parcel.ReadString(member)) { ANS_LOGE("Failed to read permitMimeTypes"); return false; diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index ba6edb7ff..5d97a1a1a 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -91,6 +91,10 @@ public: OnUnSubscribeResultEvent(NotificationConstant::SubscribeResult result) : SubscriberEvent(SubscriberEventType::ON_UNSUBSCRIBERESULT), unSubscribeResult_(result) {} + + ~OnUnSubscribeResultEvent() override + {} + NotificationConstant::SubscribeResult GetUnSubscribeResult() { return unSubscribeResult_; @@ -104,6 +108,9 @@ class OnDiedEvent : public SubscriberEvent { public: OnDiedEvent() : SubscriberEvent(SubscriberEventType::ON_DIED) {} + + ~OnDiedEvent() override + {} }; class OnUpdatedEvent : public SubscriberEvent { @@ -112,6 +119,9 @@ public: : SubscriberEvent(SubscriberEventType::ON_UPDATE), sortingMap_(sortingMap) {} + ~OnUpdatedEvent() override + {} + std::shared_ptr GetNotificationSortingMap() { return sortingMap_; @@ -127,6 +137,9 @@ public: : SubscriberEvent(SubscriberEventType::ON_DISTURBMODECHANGED), disturbMode_(disturbMode) {} + ~OnDisturbModeChangedEvent() override + {} + int GetDisturbModeChanged() { return disturbMode_; @@ -142,6 +155,9 @@ public: : SubscriberEvent(SubscriberEventType::ON_CANCELED), request_(request) {} + ~OnOnCanceledEvent() override + {} + std::shared_ptr GetRequest() { return request_; @@ -161,6 +177,9 @@ public: deleteReason_(deleteReason) {} + ~OnOnCanceledWithSortingMapAndDeleteReasonEvent() override + {} + std::shared_ptr GetRequest() { return request_; @@ -186,6 +205,9 @@ public: : SubscriberEvent(SubscriberEventType::ON_CONSUMED), request_(request) {} + ~OnConsumedEvent() override + {} + std::shared_ptr GetRequest() { return request_; @@ -204,6 +226,9 @@ public: type_ = SubscriberEventType::ON_CONSUMED_WITH_SORTINGMAP; } + ~OnConsumedWithSortingMapEvent() override + {} + std::shared_ptr GetRequest() { return request_; @@ -325,6 +350,9 @@ public: waitOnCanceledWithSortingMapAndDeleteReason_ = false; } + ~EventParser() + {} + void parse(std::list> events) { for (auto event : events) { @@ -1079,8 +1107,10 @@ inline std::shared_ptr MakePixelMap(int32_t width, int32_t height) int32_t rowDataSize = width * PIXEL_BYTES; uint32_t bufferSize = rowDataSize * height; void *buffer = malloc(bufferSize); + if (buffer != nullptr) { + pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr); + } EXPECT_NE(buffer, nullptr); - pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr); return pixelMap; } 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 85404dd1b..ec2898f5b 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -514,7 +514,10 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00100, Function int32_t rowDataSize = (PIXEL_MAP_TEST_WIDTH + 3) / 4 * 4; uint32_t bufferSize = rowDataSize * PIXEL_MAP_TEST_HEIGHT; void *buffer = malloc(bufferSize); - pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, Media::AllocatorType::HEAP_ALLOC, nullptr); + if (buffer != nullptr) { + pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, Media::AllocatorType::HEAP_ALLOC, nullptr); + } + EXPECT_NE(buffer, nullptr); req.SetBigIcon(pixelMap); req.SetLittleIcon(pixelMap); diff --git a/frameworks/wantagent/src/pending_want.cpp b/frameworks/wantagent/src/pending_want.cpp index d5d86db34..926dbfc2d 100644 --- a/frameworks/wantagent/src/pending_want.cpp +++ b/frameworks/wantagent/src/pending_want.cpp @@ -347,8 +347,8 @@ void PendingWant::UnregisterCancelListener( std::scoped_lock lock(lock_object); bool isEmpty = cancelListeners_.empty(); cancelListeners_.erase(remove_if(cancelListeners_.begin(), - cancelListeners_.end(), - [cancelListener](std::shared_ptr x) { return x == cancelListener; }), + cancelListeners_.end(), + [cancelListener](std::shared_ptr x) { return x == cancelListener; }), cancelListeners_.end()); if (cancelListeners_.empty() && !isEmpty) { AbilityManagerClient::GetInstance()->UnregisterCancelListener(target, cancelReceiver_); diff --git a/frameworks/wantagent/src/want_agent_info.cpp b/frameworks/wantagent/src/want_agent_info.cpp index b0fe01159..a3a69fb23 100644 --- a/frameworks/wantagent/src/want_agent_info.cpp +++ b/frameworks/wantagent/src/want_agent_info.cpp @@ -104,5 +104,4 @@ std::shared_ptr WantAgentInfo::GetExtraInfo() const { return extraInfo_; } - } // namespace OHOS::Notification::WantAgent \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/notification.h b/interfaces/innerkits/ans/native/include/notification.h index 9a338eaea..e515d617a 100644 --- a/interfaces/innerkits/ans/native/include/notification.h +++ b/interfaces/innerkits/ans/native/include/notification.h @@ -220,16 +220,16 @@ private: std::string GenerateNotificationKey(int32_t uid, const std::string &label, int32_t id); private: - bool enableSound_{false}; - bool enableLight_{false}; - bool enableViration_{false}; - std::string key_{""}; - int32_t ledLightColor_{0}; - NotificationConstant::VisiblenessType lockscreenVisibleness_{NotificationConstant::VisiblenessType::NO_OVERRIDE}; - sptr request_{nullptr}; - int64_t postTime_{0}; - std::shared_ptr sound_{nullptr}; - std::vector vibrationStyle_{}; + bool enableSound_ {false}; + bool enableLight_ {false}; + bool enableViration_ {false}; + std::string key_ {""}; + int32_t ledLightColor_ {0}; + NotificationConstant::VisiblenessType lockscreenVisibleness_ {NotificationConstant::VisiblenessType::NO_OVERRIDE}; + sptr request_ {nullptr}; + int64_t postTime_ {0}; + std::shared_ptr sound_ {nullptr}; + std::vector vibrationStyle_ {}; friend class AdvancedNotificationService; friend class NotificationSlotFilter; diff --git a/interfaces/innerkits/ans/native/include/notification_action_button.h b/interfaces/innerkits/ans/native/include/notification_action_button.h index 843b87753..8cb3e3958 100644 --- a/interfaces/innerkits/ans/native/include/notification_action_button.h +++ b/interfaces/innerkits/ans/native/include/notification_action_button.h @@ -220,16 +220,17 @@ private: bool ReadFromParcel(Parcel &parcel); private: - std::shared_ptr icon_{}; - std::string title_{}; - std::shared_ptr wantAgent_{}; - std::shared_ptr extras_{}; - NotificationConstant::SemanticActionButton semanticActionButton_{ - NotificationConstant::SemanticActionButton::NONE_ACTION_BUTTON}; - bool autoCreatedReplies_{true}; - std::vector> mimeTypeOnlyUserInputs_{}; - std::vector> userInputs_{}; - bool isContextual_{false}; + std::shared_ptr icon_ {}; + std::string title_ {}; + std::shared_ptr wantAgent_ {}; + std::shared_ptr extras_ {}; + NotificationConstant::SemanticActionButton semanticActionButton_ { + NotificationConstant::SemanticActionButton::NONE_ACTION_BUTTON + }; + bool autoCreatedReplies_ {true}; + std::vector> mimeTypeOnlyUserInputs_ {}; + std::vector> userInputs_ {}; + bool isContextual_ {false}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_basic_content.h b/interfaces/innerkits/ans/native/include/notification_basic_content.h index f96de434b..c14315466 100644 --- a/interfaces/innerkits/ans/native/include/notification_basic_content.h +++ b/interfaces/innerkits/ans/native/include/notification_basic_content.h @@ -92,9 +92,9 @@ protected: virtual bool ReadFromParcel(Parcel &parcel); protected: - std::string text_{}; - std::string title_{}; - std::string additionalText_{}; + std::string text_ {}; + std::string title_ {}; + std::string additionalText_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_content.h b/interfaces/innerkits/ans/native/include/notification_content.h index 6a3733897..ea5abb8cb 100644 --- a/interfaces/innerkits/ans/native/include/notification_content.h +++ b/interfaces/innerkits/ans/native/include/notification_content.h @@ -173,8 +173,8 @@ private: bool ReadFromParcel(Parcel &parcel); private: - NotificationContent::Type contentType_{NotificationContent::Type::NONE}; - std::shared_ptr content_{}; + NotificationContent::Type contentType_ {NotificationContent::Type::NONE}; + std::shared_ptr content_ {}; }; } // namespace Notification } // 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 9e274ed77..5b91d30e2 100644 --- a/interfaces/innerkits/ans/native/include/notification_conversational_content.h +++ b/interfaces/innerkits/ans/native/include/notification_conversational_content.h @@ -133,10 +133,10 @@ private: NotificationConversationalContent() = default; private: - MessageUser messageUser_{}; - std::string conversationTitle_{}; - bool isGroup_{false}; - MessageVector messages_{}; + MessageUser messageUser_ {}; + std::string conversationTitle_ {}; + bool isGroup_ {false}; + MessageVector messages_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_conversational_message.h b/interfaces/innerkits/ans/native/include/notification_conversational_message.h index acd2c31ec..06eb0b350 100644 --- a/interfaces/innerkits/ans/native/include/notification_conversational_message.h +++ b/interfaces/innerkits/ans/native/include/notification_conversational_message.h @@ -108,11 +108,11 @@ private: bool ReadFromParcel(Parcel &parcel); private: - int64_t arrivedTime_{0}; - std::string text_{}; - MessageUser sender_{}; - std::shared_ptr uri_{}; - std::string mimeType_{}; + int64_t arrivedTime_ {0}; + std::string text_ {}; + MessageUser sender_ {}; + std::shared_ptr uri_ {}; + std::string mimeType_ {}; }; } // namespace Notification } // namespace OHOS 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 f0a7ffb15..b64685f5d 100644 --- a/interfaces/innerkits/ans/native/include/notification_long_text_content.h +++ b/interfaces/innerkits/ans/native/include/notification_long_text_content.h @@ -114,9 +114,9 @@ private: static const std::size_t MAX_LONGTEXT_LENGTH; private: - std::string longText_{}; - std::string expandedTitle_{}; - std::string briefText_{}; + std::string longText_ {}; + std::string expandedTitle_ {}; + std::string briefText_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_media_content.h b/interfaces/innerkits/ans/native/include/notification_media_content.h index cfc7b3be2..c725db2ae 100644 --- a/interfaces/innerkits/ans/native/include/notification_media_content.h +++ b/interfaces/innerkits/ans/native/include/notification_media_content.h @@ -99,8 +99,8 @@ protected: bool ReadFromParcel(Parcel &parcel) override; private: - std::shared_ptr avToken_{}; - std::vector sequenceNumbers_{}; + std::shared_ptr avToken_ {}; + std::vector sequenceNumbers_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_multiline_content.h b/interfaces/innerkits/ans/native/include/notification_multiline_content.h index 1bbfe05ea..485f6c1fa 100644 --- a/interfaces/innerkits/ans/native/include/notification_multiline_content.h +++ b/interfaces/innerkits/ans/native/include/notification_multiline_content.h @@ -111,9 +111,9 @@ private: static const std::vector::size_type MAX_LINES; private: - std::string expandedTitle_{}; - std::string briefText_{}; - std::vector allLines_{}; + std::string expandedTitle_ {}; + std::string briefText_ {}; + std::vector allLines_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_picture_content.h b/interfaces/innerkits/ans/native/include/notification_picture_content.h index c4abb2f45..91a3dd806 100644 --- a/interfaces/innerkits/ans/native/include/notification_picture_content.h +++ b/interfaces/innerkits/ans/native/include/notification_picture_content.h @@ -104,9 +104,9 @@ protected: bool ReadFromParcel(Parcel &parcel) override; private: - std::string expandedTitle_{}; - std::string briefText_{}; - std::shared_ptr bigPicture_{}; + std::string expandedTitle_ {}; + std::string briefText_ {}; + std::shared_ptr bigPicture_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_request.h b/interfaces/innerkits/ans/native/include/notification_request.h index a879f32d8..f3c236fe2 100644 --- a/interfaces/innerkits/ans/native/include/notification_request.h +++ b/interfaces/innerkits/ans/native/include/notification_request.h @@ -888,61 +888,61 @@ private: int64_t GetNowSysTime(); private: - int32_t notificationId_{0}; - uint32_t color_{NotificationRequest::COLOR_DEFAULT}; - int32_t badgeNumber_{0}; - int32_t progressValue_{0}; - int32_t progressMax_{0}; - int64_t createTime_{0}; - int64_t deliveryTime_{0}; - int64_t autoDeletedTime_{0}; - - pid_t creatorPid_{0}; - pid_t creatorUid_{0}; - - std::string settingsText_{}; - std::string creatorBundleName_{}; - std::string ownerBundleName_{}; - std::string groupValue_{}; - std::string statusBarText_{}; - std::string label_{}; - std::string shortcutId_{}; - std::string sortingKey_{}; - std::string classification_{}; - - NotificationConstant::SlotType slotType_{NotificationConstant::SlotType::OTHER}; - NotificationRequest::GroupAlertType groupAlertType_{NotificationRequest::GroupAlertType::ALL}; - NotificationConstant::VisiblenessType visiblenessType_{NotificationConstant::VisiblenessType::NO_OVERRIDE}; - NotificationRequest::BadgeStyle badgeStyle_{NotificationRequest::BadgeStyle::NONE}; - NotificationContent::Type notificationContentType_{NotificationContent::Type::NONE}; - - bool showDeliveryTime_{false}; - bool tapDismissed_{false}; - bool colorEnabled_{false}; - bool alertOneTime_{false}; - bool showStopwatch_{false}; - bool isCountdown_{false}; - bool inProgress_{false}; - bool groupOverview_{false}; - bool progressIndeterminate_{false}; - bool unremovable_{false}; - bool floatingIcon_{false}; - bool onlyLocal_{false}; - bool permitted_{true}; - - std::shared_ptr context_{}; - std::shared_ptr wantAgent_{}; - std::shared_ptr removalWantAgent_{}; - std::shared_ptr maxScreenWantAgent_{}; - std::shared_ptr additionalParams_{}; - std::shared_ptr littleIcon_{}; - std::shared_ptr bigIcon_{}; - std::shared_ptr notificationContent_{}; - std::shared_ptr publicNotification_{}; - - std::vector> actionButtons_{}; - std::vector> messageUsers_{}; - std::vector userInputHistory_{}; + int32_t notificationId_ {0}; + uint32_t color_ {NotificationRequest::COLOR_DEFAULT}; + int32_t badgeNumber_ {0}; + int32_t progressValue_ {0}; + int32_t progressMax_ {0}; + int64_t createTime_ {0}; + int64_t deliveryTime_ {0}; + int64_t autoDeletedTime_ {0}; + + pid_t creatorPid_ {0}; + pid_t creatorUid_ {0}; + + std::string settingsText_ {}; + std::string creatorBundleName_ {}; + std::string ownerBundleName_ {}; + std::string groupValue_ {}; + std::string statusBarText_ {}; + std::string label_ {}; + std::string shortcutId_ {}; + std::string sortingKey_ {}; + std::string classification_ {}; + + NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::OTHER}; + NotificationRequest::GroupAlertType groupAlertType_ {NotificationRequest::GroupAlertType::ALL}; + NotificationConstant::VisiblenessType visiblenessType_ {NotificationConstant::VisiblenessType::NO_OVERRIDE}; + NotificationRequest::BadgeStyle badgeStyle_ {NotificationRequest::BadgeStyle::NONE}; + NotificationContent::Type notificationContentType_ {NotificationContent::Type::NONE}; + + bool showDeliveryTime_ {false}; + bool tapDismissed_ {false}; + bool colorEnabled_ {false}; + bool alertOneTime_ {false}; + bool showStopwatch_ {false}; + bool isCountdown_ {false}; + bool inProgress_ {false}; + bool groupOverview_ {false}; + bool progressIndeterminate_ {false}; + bool unremovable_ {false}; + bool floatingIcon_ {false}; + bool onlyLocal_ {false}; + bool permitted_ {true}; + + std::shared_ptr context_ {}; + std::shared_ptr wantAgent_ {}; + std::shared_ptr removalWantAgent_ {}; + std::shared_ptr maxScreenWantAgent_ {}; + std::shared_ptr additionalParams_ {}; + std::shared_ptr littleIcon_ {}; + std::shared_ptr bigIcon_ {}; + std::shared_ptr notificationContent_ {}; + std::shared_ptr publicNotification_ {}; + + std::vector> actionButtons_ {}; + std::vector> messageUsers_ {}; + std::vector userInputHistory_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_slot.h b/interfaces/innerkits/ans/native/include/notification_slot.h index 5a82654de..f9594c65e 100644 --- a/interfaces/innerkits/ans/native/include/notification_slot.h +++ b/interfaces/innerkits/ans/native/include/notification_slot.h @@ -33,7 +33,7 @@ public: // with no banner or prompt tone LEVEL_LOW, // the notifications are displayed on the notification panel, // with no banner or prompt tone - LEVEL_DEFAULT, // the notification function is enabled and notifications are displayed + LEVEL_DEFAULT, // the notification function is enabled and notifications are displayed, // on the notification panel, with a banner and a prompt tone. LEVEL_HIGH, // the notifications are displayed on the notification panel, // with a banner and a prompt tone @@ -346,20 +346,20 @@ private: void SetName(const std::string &name); private: - std::string id_{}; - std::string name_{}; + std::string id_ {}; + std::string name_ {}; bool isLightEnabled_ {false}; bool isVibrationEnabled_ {false}; - bool isShowBadge_{true}; - bool isBypassDnd_{false}; - std::string description_{}; + bool isShowBadge_ {true}; + bool isBypassDnd_ {false}; + std::string description_ {}; int32_t lightColor_ {0}; - NotificationLevel level_{LEVEL_DEFAULT}; - NotificationConstant::SlotType type_{}; - NotificationConstant::VisiblenessType lockScreenVisibleness_{NotificationConstant::VisiblenessType::NO_OVERRIDE}; - std::string groupId_{}; + NotificationLevel level_ {LEVEL_DEFAULT}; + NotificationConstant::SlotType type_ {}; + NotificationConstant::VisiblenessType lockScreenVisibleness_ {NotificationConstant::VisiblenessType::NO_OVERRIDE}; + std::string groupId_ {}; Uri sound_; - std::vector vibrationValues_{}; + std::vector vibrationValues_ {}; // no object in parcel static constexpr int VALUE_NULL = -1; diff --git a/interfaces/innerkits/ans/native/include/notification_sorting.h b/interfaces/innerkits/ans/native/include/notification_sorting.h index 4b273f938..4be3ba5b4 100644 --- a/interfaces/innerkits/ans/native/include/notification_sorting.h +++ b/interfaces/innerkits/ans/native/include/notification_sorting.h @@ -168,14 +168,14 @@ private: bool ReadFromParcel(Parcel &parcel); private: - std::string key_{}; - int32_t ranking_{-1}; - int32_t importance_{-1}; - bool isDisplayBadge_{true}; - bool isHiddenNotification_{}; - std::string groupKeyOverride_{}; - int32_t visiblenessOverride_{}; - sptr slot_{nullptr}; + std::string key_ {}; + int32_t ranking_ {-1}; + int32_t importance_ {-1}; + bool isDisplayBadge_ {true}; + bool isHiddenNotification_ {}; + std::string groupKeyOverride_ {}; + int32_t visiblenessOverride_ {}; + sptr slot_ {nullptr}; friend class AdvancedNotificationService; }; diff --git a/interfaces/innerkits/ans/native/include/notification_sorting_map.h b/interfaces/innerkits/ans/native/include/notification_sorting_map.h index 32a8163cb..54fb3f37a 100644 --- a/interfaces/innerkits/ans/native/include/notification_sorting_map.h +++ b/interfaces/innerkits/ans/native/include/notification_sorting_map.h @@ -93,8 +93,8 @@ private: void SetNotificationSorting(const std::vector &sortingList); private: - std::vector sortedKey_{}; - std::map sortings_{}; + std::vector sortedKey_ {}; + std::map sortings_ {}; }; } // namespace Notification diff --git a/interfaces/innerkits/ans/native/include/notification_subscribe_info.h b/interfaces/innerkits/ans/native/include/notification_subscribe_info.h index 49dc6fc29..1eb370e59 100644 --- a/interfaces/innerkits/ans/native/include/notification_subscribe_info.h +++ b/interfaces/innerkits/ans/native/include/notification_subscribe_info.h @@ -94,7 +94,7 @@ private: bool ReadFromParcel(Parcel &parcel); private: - std::vector appNames_{}; + std::vector appNames_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_subscriber.h b/interfaces/innerkits/ans/native/include/notification_subscriber.h index ebe13aac9..6cbdecc3e 100644 --- a/interfaces/innerkits/ans/native/include/notification_subscriber.h +++ b/interfaces/innerkits/ans/native/include/notification_subscriber.h @@ -149,9 +149,9 @@ private: public: NotificationSubscriber &subscriber_; - sptr recipient_{nullptr}; - sptr proxy_{nullptr}; - std::mutex mutex_{}; + sptr recipient_ {nullptr}; + sptr proxy_ {nullptr}; + std::mutex mutex_ {}; }; private: diff --git a/interfaces/innerkits/ans/native/include/notification_user_input.h b/interfaces/innerkits/ans/native/include/notification_user_input.h index f84d26830..1327bca96 100644 --- a/interfaces/innerkits/ans/native/include/notification_user_input.h +++ b/interfaces/innerkits/ans/native/include/notification_user_input.h @@ -265,13 +265,13 @@ private: bool ReadFromParcel(Parcel &parcel); private: - std::string inputKey_{}; - std::string tag_{}; - std::vector options_{}; - bool permitFreeFormInput_{true}; - std::set permitMimeTypes_{}; - std::shared_ptr pacMap_{}; - NotificationConstant::InputEditType editType_{NotificationConstant::InputEditType::EDIT_AUTO}; + std::string inputKey_ {}; + std::string tag_ {}; + std::vector options_ {}; + bool permitFreeFormInput_ {true}; + std::set permitMimeTypes_ {}; + std::shared_ptr pacMap_ {}; + NotificationConstant::InputEditType editType_ {NotificationConstant::InputEditType::EDIT_AUTO}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/wantagent/include/pending_want.h b/interfaces/innerkits/wantagent/include/pending_want.h index b86b1a3cb..7ab84bd4e 100644 --- a/interfaces/innerkits/wantagent/include/pending_want.h +++ b/interfaces/innerkits/wantagent/include/pending_want.h @@ -152,7 +152,7 @@ public: * @param want An Want describing the service to be started. * @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, * FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, - *FLAG_IMMUTABLE. + * FLAG_IMMUTABLE. * * @return Returns an existing or new PendingWant matching the given * parameters. May return null only if FLAG_NO_CREATE has been diff --git a/interfaces/kits/napi/ans/include/common.h b/interfaces/kits/napi/ans/include/common.h index 92a08e74b..17bcd5832 100644 --- a/interfaces/kits/napi/ans/include/common.h +++ b/interfaces/kits/napi/ans/include/common.h @@ -89,7 +89,6 @@ enum InputEditType { EDIT_AUTO, EDIT_DISABLED, EDIT_ENABLED }; struct NotificationSubscribeInfo { std::vector bundleNames; - // std::vector deviceIds; int userId = 0; bool hasSubscribeInfo = false; }; diff --git a/interfaces/kits/napi/ans/include/init.h b/interfaces/kits/napi/ans/include/init.h index 1690462d7..fabae8a06 100644 --- a/interfaces/kits/napi/ans/include/init.h +++ b/interfaces/kits/napi/ans/include/init.h @@ -41,7 +41,7 @@ napi_module _module = { .nm_flags = 0, .nm_filename = nullptr, .nm_register_func = Init, - .nm_modname = "notificationnapi", + .nm_modname = "notification", .nm_priv = ((void *)0), .reserved = {0} diff --git a/interfaces/kits/napi/ans/src/cancel.cpp b/interfaces/kits/napi/ans/src/cancel.cpp index 5264e984f..7bc7871ff 100644 --- a/interfaces/kits/napi/ans/src/cancel.cpp +++ b/interfaces/kits/napi/ans/src/cancel.cpp @@ -106,7 +106,7 @@ napi_value Cancel(napi_env env, napi_callback_info info) } AsyncCallbackInfoCancel *asynccallbackinfo = new (std::nothrow) - AsyncCallbackInfoCancel{.env = env, .asyncWork = nullptr, .id = paras.id, .label = paras.label}; + AsyncCallbackInfoCancel {.env = env, .asyncWork = nullptr, .id = paras.id, .label = paras.label}; if (!asynccallbackinfo) { return Common::JSParaError(env, paras.callback); } @@ -164,7 +164,7 @@ napi_value CancelAll(napi_env env, napi_callback_info info) } AsyncCallbackInfoCancel *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoCancel{.env = env, .asyncWork = nullptr}; + new (std::nothrow) AsyncCallbackInfoCancel {.env = env, .asyncWork = nullptr}; if (!asynccallbackinfo) { return Common::JSParaError(env, callback); } diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index a2543c73c..e57a617a8 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -2617,7 +2617,7 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va napi_get_value_int32(env, nobj, &inLevel); ANS_LOGI("level is: %{public}d", inLevel); - NotificationSlot::NotificationLevel outLevel{NotificationSlot::NotificationLevel::LEVEL_NONE}; + NotificationSlot::NotificationLevel outLevel {NotificationSlot::NotificationLevel::LEVEL_NONE}; if (!SlotLevelJSToC(SlotLevel(inLevel), outLevel)) { return nullptr; } @@ -2753,7 +2753,7 @@ napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, { ANS_LOGI("enter"); - bool hasProperty{false}; + bool hasProperty {false}; napi_valuetype valuetype = napi_undefined; napi_value result = nullptr; @@ -2784,7 +2784,7 @@ napi_value Common::GetNotificationKey(const napi_env &env, const napi_value &val { ANS_LOGI("enter"); - bool hasProperty{false}; + bool hasProperty {false}; napi_valuetype valuetype = napi_undefined; napi_value result = nullptr; diff --git a/interfaces/kits/napi/ans/src/display_badge.cpp b/interfaces/kits/napi/ans/src/display_badge.cpp index 129355a8f..ea42c40b0 100644 --- a/interfaces/kits/napi/ans/src/display_badge.cpp +++ b/interfaces/kits/napi/ans/src/display_badge.cpp @@ -127,13 +127,13 @@ napi_value DisplayBadge(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - EnableBadgeParams params{}; + EnableBadgeParams params {}; if (ParseParameters(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } AsyncCallbackInfoEnableBadge *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoEnableBadge{.env = env, .asyncWork = nullptr, .params = params}; + new (std::nothrow) AsyncCallbackInfoEnableBadge {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -192,13 +192,13 @@ napi_value IsBadgeDisplayed(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - IsDisplayBadgeParams params{}; + IsDisplayBadgeParams params {}; if (ParseParameters(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } AsyncCallbackInfoIsDisplayBadge *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoIsDisplayBadge{.env = env, .asyncWork = nullptr, .params = params}; + new (std::nothrow) AsyncCallbackInfoIsDisplayBadge {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } diff --git a/interfaces/kits/napi/ans/src/disturb_mode.cpp b/interfaces/kits/napi/ans/src/disturb_mode.cpp index 34040e313..d2b88c530 100644 --- a/interfaces/kits/napi/ans/src/disturb_mode.cpp +++ b/interfaces/kits/napi/ans/src/disturb_mode.cpp @@ -68,13 +68,13 @@ napi_value SetDoNotDisturbMode(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - DisturbModeParams params{}; + DisturbModeParams params {}; if (ParseParameters(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } AsyncCallbackInfoDisturbMode *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoDisturbMode{.env = env, .asyncWork = nullptr, .params = params}; + new (std::nothrow) AsyncCallbackInfoDisturbMode {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } diff --git a/interfaces/kits/napi/ans/src/enable_notification.cpp b/interfaces/kits/napi/ans/src/enable_notification.cpp index ae680b46b..aa8c2cdcd 100644 --- a/interfaces/kits/napi/ans/src/enable_notification.cpp +++ b/interfaces/kits/napi/ans/src/enable_notification.cpp @@ -127,13 +127,13 @@ napi_value EnableNotification(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - EnableParams params{}; + EnableParams params {}; if (ParseParameters(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } AsyncCallbackInfoEnable *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoEnable{.env = env, .asyncWork = nullptr, .params = params}; + new (std::nothrow) AsyncCallbackInfoEnable {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -189,13 +189,13 @@ napi_value IsNotificationEnabled(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - IsEnableParams params{}; + IsEnableParams params {}; if (ParseParameters(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } AsyncCallbackInfoIsEnable *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoIsEnable{.env = env, .asyncWork = nullptr, .params = params}; + new (std::nothrow) AsyncCallbackInfoIsEnable {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } diff --git a/interfaces/kits/napi/ans/src/get_active.cpp b/interfaces/kits/napi/ans/src/get_active.cpp index d763bd058..0d6ba8c42 100644 --- a/interfaces/kits/napi/ans/src/get_active.cpp +++ b/interfaces/kits/napi/ans/src/get_active.cpp @@ -77,7 +77,7 @@ napi_value GetAllActiveNotifications(napi_env env, napi_callback_info info) } AsyncCallbackInfoActive *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoActive{.env = env, .asyncWork = nullptr}; + new (std::nothrow) AsyncCallbackInfoActive {.env = env, .asyncWork = nullptr}; if (!asynccallbackinfo) { return Common::JSParaError(env, callback); } @@ -163,7 +163,7 @@ napi_value GetActiveNotifications(napi_env env, napi_callback_info info) } AsyncCallbackInfoActive *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoActive{.env = env, .asyncWork = nullptr}; + new (std::nothrow) AsyncCallbackInfoActive {.env = env, .asyncWork = nullptr}; if (!asynccallbackinfo) { return Common::JSParaError(env, callback); } @@ -249,7 +249,7 @@ napi_value GetActiveNotificationCount(napi_env env, napi_callback_info info) } AsyncCallbackInfoActive *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoActive{.env = env, .asyncWork = nullptr}; + new (std::nothrow) AsyncCallbackInfoActive {.env = env, .asyncWork = nullptr}; if (!asynccallbackinfo) { return Common::JSParaError(env, callback); } diff --git a/interfaces/kits/napi/ans/src/publish.cpp b/interfaces/kits/napi/ans/src/publish.cpp index 8dd5e880c..3c860cab9 100644 --- a/interfaces/kits/napi/ans/src/publish.cpp +++ b/interfaces/kits/napi/ans/src/publish.cpp @@ -88,7 +88,7 @@ napi_value Publish(napi_env env, napi_callback_info info) napi_value promise = nullptr; AsyncCallbackInfoPublish *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoPublish{.env = env, .asyncWork = nullptr}; + new (std::nothrow) AsyncCallbackInfoPublish {.env = env, .asyncWork = nullptr}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } diff --git a/interfaces/kits/napi/ans/src/remove.cpp b/interfaces/kits/napi/ans/src/remove.cpp index 8cae75ede..59b9a3dae 100644 --- a/interfaces/kits/napi/ans/src/remove.cpp +++ b/interfaces/kits/napi/ans/src/remove.cpp @@ -35,15 +35,15 @@ struct BundleAndKeyInfo { }; struct RemoveParams { - std::optional hashcode{}; - std::optional bundleAndKeyInfo{}; + std::optional hashcode {}; + std::optional bundleAndKeyInfo {}; napi_ref callback = nullptr; }; struct AsyncCallbackInfoRemove { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - RemoveParams params{}; + RemoveParams params {}; CallbackPromiseInfo info; }; @@ -78,7 +78,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, } else { NAPI_ASSERT(env, argc >= REMOVE_BY_BUNDLE_AND_KEY_MIN_PARA, "Wrong number of arguments"); - BundleAndKeyInfo info{}; + BundleAndKeyInfo info {}; // argv[0]: BundleOption auto retValue = Common::GetBundleOption(env, argv[0], info.option); if (retValue == nullptr) { @@ -128,7 +128,7 @@ napi_value ParseParametersByRemoveAll(const napi_env &env, const napi_callback_i // argv[0]: callback napi_create_reference(env, argv[0], 1, ¶ms.callback); } else { - BundleAndKeyInfo info{}; + BundleAndKeyInfo info {}; // argv[0]: BundleOption auto retValue = Common::GetBundleOption(env, argv[0], info.option); NAPI_ASSERT(env, retValue != nullptr, "GetBundleOption failed."); @@ -149,13 +149,13 @@ napi_value Remove(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - RemoveParams params{}; + RemoveParams params {}; if (ParseParameters(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } AsyncCallbackInfoRemove *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoRemove{.env = env, .asyncWork = nullptr, .params = params}; + new (std::nothrow) AsyncCallbackInfoRemove {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -215,13 +215,13 @@ napi_value RemoveAll(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - RemoveParams params{}; + RemoveParams params {}; if (ParseParametersByRemoveAll(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } AsyncCallbackInfoRemove *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoRemove{.env = env, .asyncWork = nullptr, .params = params}; + new (std::nothrow) AsyncCallbackInfoRemove {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } diff --git a/interfaces/kits/napi/ans/src/slot.cpp b/interfaces/kits/napi/ans/src/slot.cpp index 3b493f2c6..3764f5380 100644 --- a/interfaces/kits/napi/ans/src/slot.cpp +++ b/interfaces/kits/napi/ans/src/slot.cpp @@ -421,11 +421,13 @@ napi_value AddSlot(napi_env env, napi_callback_info info) return Common::JSParaError(env, paras.callback); } - AsyncCallbackInfoAddSlot *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoAddSlot{.env = env, + AsyncCallbackInfoAddSlot *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoAddSlot { + .env = env, .asyncWork = nullptr, .slot = paras.slot, .inType = paras.inType, - .isAddSlotByType = paras.isAddSlotByType}; + .isAddSlotByType = paras.isAddSlotByType + }; if (!asynccallbackinfo) { return Common::JSParaError(env, paras.callback); } @@ -485,7 +487,7 @@ napi_value AddSlots(napi_env env, napi_callback_info info) } AsyncCallbackInfoAddSlots *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoAddSlots{.env = env, .asyncWork = nullptr, .slots = paras.slots}; + new (std::nothrow) AsyncCallbackInfoAddSlots {.env = env, .asyncWork = nullptr, .slots = paras.slots}; if (!asynccallbackinfo) { return Common::JSParaError(env, paras.callback); } @@ -535,13 +537,13 @@ napi_value SetSlotByBundle(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - ParametersInfoSetSlotByBundle params{}; + ParametersInfoSetSlotByBundle params {}; if (ParseParametersSetSlotByBundle(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } AsyncCallbackInfoSetSlotByBundle *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoSetSlotByBundle{.env = env, .asyncWork = nullptr, .params = params}; + new (std::nothrow) AsyncCallbackInfoSetSlotByBundle {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -602,7 +604,7 @@ napi_value GetSlot(napi_env env, napi_callback_info info) } AsyncCallbackInfoGetSlot *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoGetSlot{.env = env, .asyncWork = nullptr, .outType = paras.outType}; + new (std::nothrow) AsyncCallbackInfoGetSlot {.env = env, .asyncWork = nullptr, .outType = paras.outType}; if (!asynccallbackinfo) { return Common::JSParaError(env, paras.callback); } @@ -668,13 +670,13 @@ napi_value GetSlotNumByBundle(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - ParametersInfoGetSlotNumByBundle params{}; + ParametersInfoGetSlotNumByBundle params {}; if (ParseParametersGetSlotNumByBundle(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } AsyncCallbackInfoGetSlotNumByBundle *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoGetSlotNumByBundle{.env = env, .asyncWork = nullptr, .params = params}; + new (std::nothrow) AsyncCallbackInfoGetSlotNumByBundle {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -736,7 +738,7 @@ napi_value GetSlots(napi_env env, napi_callback_info info) } AsyncCallbackInfoGetSlots *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoGetSlots{.env = env, .asyncWork = nullptr}; + new (std::nothrow) AsyncCallbackInfoGetSlots {.env = env, .asyncWork = nullptr}; if (!asynccallbackinfo) { return Common::JSParaError(env, callback); } @@ -815,13 +817,13 @@ napi_value GetSlotsByBundle(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - ParametersInfoGetSlotsByBundle params{}; + ParametersInfoGetSlotsByBundle params {}; if (ParseParametersGetSlotsByBundle(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } AsyncCallbackInfoGetSlotsByBundle *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoGetSlotsByBundle{.env = env, .asyncWork = nullptr, .params = params}; + new (std::nothrow) AsyncCallbackInfoGetSlotsByBundle {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -910,7 +912,7 @@ napi_value RemoveSlot(napi_env env, napi_callback_info info) } AsyncCallbackInfoRemoveSlot *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoRemoveSlot{.env = env, .asyncWork = nullptr, .outType = paras.outType}; + new (std::nothrow) AsyncCallbackInfoRemoveSlot {.env = env, .asyncWork = nullptr, .outType = paras.outType}; if (!asynccallbackinfo) { return Common::JSParaError(env, paras.callback); } @@ -966,7 +968,7 @@ napi_value RemoveAllSlots(napi_env env, napi_callback_info info) } AsyncCallbackInfoRemoveAllSlots *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoRemoveAllSlots{.env = env, .asyncWork = nullptr}; + new (std::nothrow) AsyncCallbackInfoRemoveAllSlots {.env = env, .asyncWork = nullptr}; if (!asynccallbackinfo) { return Common::JSParaError(env, callback); } diff --git a/interfaces/kits/napi/ans/src/subscribe.cpp b/interfaces/kits/napi/ans/src/subscribe.cpp index f2bcb906e..724acd30c 100644 --- a/interfaces/kits/napi/ans/src/subscribe.cpp +++ b/interfaces/kits/napi/ans/src/subscribe.cpp @@ -209,10 +209,10 @@ void SubscriberInstance::OnCanceled(const std::shared_ptrenv, &result); int error = 0; if (!SetSubscribeCallbackData(dataWorkerData->env, - dataWorkerData->request, - dataWorkerData->sortingMap, - dataWorkerData->deleteReason, - result)) { + dataWorkerData->request, + dataWorkerData->sortingMap, + dataWorkerData->deleteReason, + result)) { result = Common::NapiGetNull(dataWorkerData->env); error = ERROR; } else { @@ -296,10 +296,10 @@ void SubscriberInstance::OnConsumed(const std::shared_ptrenv, &result); int error = 0; if (!SetSubscribeCallbackData(dataWorkerData->env, - dataWorkerData->request, - dataWorkerData->sortingMap, - NO_DELETE_REASON, - result)) { + dataWorkerData->request, + dataWorkerData->sortingMap, + NO_DELETE_REASON, + result)) { result = Common::NapiGetNull(dataWorkerData->env); error = ERROR; } else { @@ -917,8 +917,9 @@ napi_value Subscribe(napi_env env, napi_callback_info info) } ANS_LOGI("Subscribe objectInfo = %{public}p", objectInfo); - AsyncCallbackInfoSubscribe *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoSubscribe{ - .env = env, .asyncWork = nullptr, .objectInfo = objectInfo, .subscriberInfo = subscriberInfo}; + AsyncCallbackInfoSubscribe *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoSubscribe { + .env = env, .asyncWork = nullptr, .objectInfo = objectInfo, .subscriberInfo = subscriberInfo + }; if (!asynccallbackinfo) { return Common::JSParaError(env, callback); } diff --git a/interfaces/kits/napi/ans/src/unsubscribe.cpp b/interfaces/kits/napi/ans/src/unsubscribe.cpp index 659c9e59d..7e2b9bc38 100644 --- a/interfaces/kits/napi/ans/src/unsubscribe.cpp +++ b/interfaces/kits/napi/ans/src/unsubscribe.cpp @@ -73,7 +73,7 @@ napi_value Unsubscribe(napi_env env, napi_callback_info info) } AsyncCallbackInfoUnsubscribe *asynccallbackinfo = new (std::nothrow) - AsyncCallbackInfoUnsubscribe{.env = env, .asyncWork = nullptr, .objectInfo = paras.objectInfo}; + AsyncCallbackInfoUnsubscribe {.env = env, .asyncWork = nullptr, .objectInfo = paras.objectInfo}; if (!asynccallbackinfo) { return Common::JSParaError(env, paras.callback); } diff --git a/interfaces/kits/napi/wantagent/napi_want_agent.cpp b/interfaces/kits/napi/wantagent/napi_want_agent.cpp index 0f3471045..f5b4759c8 100644 --- a/interfaces/kits/napi/wantagent/napi_want_agent.cpp +++ b/interfaces/kits/napi/wantagent/napi_want_agent.cpp @@ -19,14 +19,12 @@ #include #include #include -#include #include "hilog_wrapper.h" #include "napi_common.h" #include "want_agent_helper.h" namespace OHOS { - constexpr int32_t BUSINESS_ERROR_CODE_OK = 0; TriggerCompleteCallBack::TriggerCompleteCallBack() @@ -46,6 +44,69 @@ void TriggerCompleteCallBack::SetWantAgentInstance(const std::shared_ptrdata; + if (dataWorkerData == nullptr) { + HILOG_INFO("TriggerReceiveDataWorker instance(uv_work_t) is nullptr"); + return; + } + napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value callResult = nullptr; + + result[0] = GetCallbackErrorResult(dataWorkerData->env, BUSINESS_ERROR_CODE_OK); + napi_create_object(dataWorkerData->env, &result[1]); + // wrap wantAgent + napi_value wantAgentClass = nullptr; + napi_define_class(dataWorkerData->env, + "WantAgentClass", + NAPI_AUTO_LENGTH, + [](napi_env env, napi_callback_info info) -> napi_value { + napi_value thisVar = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); + return thisVar; + }, + nullptr, + 0, + nullptr, + &wantAgentClass); + napi_value jsWantAgent = nullptr; + napi_new_instance(dataWorkerData->env, wantAgentClass, 0, nullptr, &jsWantAgent); + napi_wrap(dataWorkerData->env, + jsWantAgent, + (void *)dataWorkerData->wantAgent.get(), + [](napi_env env, void *data, void *hint) {}, + nullptr, + nullptr); + napi_set_named_property(dataWorkerData->env, result[1], "wantAgent", jsWantAgent); + // wrap want + napi_value jsWant = nullptr; + jsWant = WrapWant(dataWorkerData->env, dataWorkerData->want); + napi_set_named_property(dataWorkerData->env, result[1], "want", jsWant); + // wrap finalCode + napi_value jsFinalCode = nullptr; + napi_create_int32(dataWorkerData->env, dataWorkerData->resultCode, &jsFinalCode); + napi_set_named_property(dataWorkerData->env, result[1], "finalCode", jsFinalCode); + // wrap finalData + napi_value jsFinalData = nullptr; + napi_create_string_utf8(dataWorkerData->env, dataWorkerData->resultData.c_str(), NAPI_AUTO_LENGTH, &jsFinalData); + napi_set_named_property(dataWorkerData->env, result[1], "finalData", jsFinalCode); + // wrap extraInfo + napi_value jsExtraInfo = WrapWantParams(dataWorkerData->env, dataWorkerData->resultExtras); + napi_set_named_property(dataWorkerData->env, result[1], "extraInfo", jsExtraInfo); + + napi_get_undefined(dataWorkerData->env, &undefined); + napi_get_reference_value(dataWorkerData->env, dataWorkerData->ref, &callback); + napi_call_function(dataWorkerData->env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); + + delete dataWorkerData; + dataWorkerData = nullptr; + delete work; + work = nullptr; +} + void TriggerCompleteCallBack::OnSendFinished( const AAFwk::Want &want, int resultCode, const std::string &resultData, const AAFwk::WantParams &resultExtras) { @@ -83,97 +144,44 @@ void TriggerCompleteCallBack::OnSendFinished( dataWorker->ref = triggerCompleteInfo_.ref; dataWorker->wantAgent = triggerCompleteInfo_.wantAgent; work->data = (void *)dataWorker; - uv_queue_work(loop, - work, - [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - TriggerReceiveDataWorker *dataWorkerData = (TriggerReceiveDataWorker *)work->data; - if (dataWorkerData == nullptr) { - HILOG_INFO("TriggerReceiveDataWorker instance(uv_work_t) is nullptr"); - return; - } - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - napi_value callback; - napi_value undefined; - napi_value callResult = 0; - - result[0] = GetCallbackErrorResult(dataWorkerData->env, BUSINESS_ERROR_CODE_OK); - napi_create_object(dataWorkerData->env, &result[1]); - // wrap wantAgent - napi_value wantAgentClass = nullptr; - napi_define_class(dataWorkerData->env, - "WantAgentClass", - NAPI_AUTO_LENGTH, - [](napi_env env, napi_callback_info info) -> napi_value { - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); - return thisVar; - }, - nullptr, - 0, - nullptr, - &wantAgentClass); - napi_value jsWantAgent = nullptr; - napi_new_instance(dataWorkerData->env, wantAgentClass, 0, nullptr, &jsWantAgent); - napi_wrap(dataWorkerData->env, - jsWantAgent, - (void *)dataWorkerData->wantAgent.get(), - [](napi_env env, void *data, void *hint) {}, - nullptr, - nullptr); - napi_set_named_property(dataWorkerData->env, result[1], "wantAgent", jsWantAgent); - // wrap want - napi_value jsWant; - jsWant = WrapWant(dataWorkerData->env, dataWorkerData->want); - napi_set_named_property(dataWorkerData->env, result[1], "want", jsWant); - // wrap finalCode - napi_value jsFinalCode; - napi_create_int32(dataWorkerData->env, dataWorkerData->resultCode, &jsFinalCode); - napi_set_named_property(dataWorkerData->env, result[1], "finalCode", jsFinalCode); - // wrap finalData - napi_value jsFinalData; - napi_create_string_utf8( - dataWorkerData->env, dataWorkerData->resultData.c_str(), NAPI_AUTO_LENGTH, &jsFinalData); - napi_set_named_property(dataWorkerData->env, result[1], "finalData", jsFinalCode); - // wrap extraInfo - napi_value jsExtraInfo; - jsExtraInfo = WrapWantParams(dataWorkerData->env, dataWorkerData->resultExtras); - napi_set_named_property(dataWorkerData->env, result[1], "extraInfo", jsExtraInfo); - - napi_get_undefined(dataWorkerData->env, &undefined); - napi_get_reference_value(dataWorkerData->env, dataWorkerData->ref, &callback); - napi_call_function( - dataWorkerData->env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - delete dataWorkerData; - dataWorkerData = nullptr; + int ret = + uv_queue_work(loop, work, [](uv_work_t *work) {}, TriggerCompleteCallBack::OnSendFinishedUvAfterWorkCallback); + if (ret != 0) { + if (dataWorker != nullptr) { + delete dataWorker; + dataWorker = nullptr; + } + if (work != nullptr) { delete work; work = nullptr; - }); + } + } HILOG_INFO("TriggerCompleteCallBack::OnSendFinished end"); } napi_value WantAgentInit(napi_env env, napi_value exports) { HILOG_INFO("napi_moudule Init start..."); - napi_property_descriptor desc[] = {DECLARE_NAPI_FUNCTION("getBundleName", NAPI_GetBundleName), + napi_property_descriptor desc[] = { + DECLARE_NAPI_FUNCTION("getBundleName", NAPI_GetBundleName), DECLARE_NAPI_FUNCTION("getUid", NAPI_GetUid), DECLARE_NAPI_FUNCTION("cancel", NAPI_Cancel), DECLARE_NAPI_FUNCTION("trigger", NAPI_Trigger), DECLARE_NAPI_FUNCTION("equal", NAPI_Equal), DECLARE_NAPI_FUNCTION("getWant", NAPI_GetWant), - DECLARE_NAPI_FUNCTION("getWantAgent", NAPI_GetWantAgent)}; + DECLARE_NAPI_FUNCTION("getWantAgent", NAPI_GetWantAgent), + }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); HILOG_INFO("napi_moudule Init end..."); return exports; } -void SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const char *propName) +void SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const std::string &propName) { napi_value prop = nullptr; if (napi_create_int32(env, objName, &prop) == napi_ok) { - napi_set_named_property(env, dstObj, propName, prop); + napi_set_named_property(env, dstObj, propName.c_str(), prop); } } @@ -225,79 +233,84 @@ napi_value WantAgentOperationTypeInit(napi_env env, napi_value exports) return exports; } +void NAPI_GetBundleNameExecuteCallBack(napi_env env, void *data) +{ + HILOG_INFO("GetBundleName called(CallBack Mode)..."); + AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = (AsyncGetBundleNameCallbackInfo *)data; + asyncCallbackInfo->bundleName = WantAgentHelper::GetBundleName(asyncCallbackInfo->wantAgent); +} + +void NAPI_GetBundleNameCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("GetBundleName compeleted(CallBack Mode)..."); + AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = (AsyncGetBundleNameCallbackInfo *)data; + napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value callResult = nullptr; + + result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); + napi_create_string_utf8(env, asyncCallbackInfo->bundleName.c_str(), NAPI_AUTO_LENGTH, &result[1]); + napi_get_undefined(env, &undefined); + napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); + napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); + + if (asyncCallbackInfo->callback[0] != nullptr) { + napi_delete_reference(env, asyncCallbackInfo->callback[0]); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + +void NAPI_GetBundleNamePromiseCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("GetBundleName compeleted(Promise Mode)..."); + AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = (AsyncGetBundleNameCallbackInfo *)data; + napi_value result = nullptr; + napi_create_string_utf8(env, asyncCallbackInfo->bundleName.c_str(), NAPI_AUTO_LENGTH, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + napi_value NAPI_GetBundleNameWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncGetBundleNameCallbackInfo *asyncCallbackInfo) + napi_env env, napi_callback_info info, bool callBackMode, AsyncGetBundleNameCallbackInfo &asyncCallbackInfo) { HILOG_INFO("NAPI_GetBundleNameWrap called..."); if (callBackMode) { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_GetBundleNameCallBack", NAPI_AUTO_LENGTH, &resourceName); napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("GetBundleName called(CallBack Mode)..."); - AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = (AsyncGetBundleNameCallbackInfo *)data; - asyncCallbackInfo->bundleName = WantAgentHelper::GetBundleName(asyncCallbackInfo->wantAgent); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetBundleName compeleted(CallBack Mode)..."); - AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = (AsyncGetBundleNameCallbackInfo *)data; - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - napi_value callback; - napi_value undefined; - napi_value callResult = 0; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - napi_create_string_utf8(env, asyncCallbackInfo->bundleName.c_str(), NAPI_AUTO_LENGTH, &result[1]); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + NAPI_GetBundleNameExecuteCallBack, + NAPI_GetBundleNameCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); // create reutrn - napi_value ret = 0; + napi_value ret = nullptr; NAPI_CALL(env, napi_create_int32(env, 0, &ret)); return ret; } else { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_GetBundleNamePromise", NAPI_AUTO_LENGTH, &resourceName); - napi_deferred deferred; - napi_value promise; + napi_deferred deferred = nullptr; + napi_value promise = nullptr; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo->deferred = deferred; + asyncCallbackInfo.deferred = deferred; napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("GetBundleName called(Promise Mode)..."); - AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = (AsyncGetBundleNameCallbackInfo *)data; - asyncCallbackInfo->bundleName = WantAgentHelper::GetBundleName(asyncCallbackInfo->wantAgent); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetBundleName compeleted(Promise Mode)..."); - AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = (AsyncGetBundleNameCallbackInfo *)data; - napi_value result; - napi_create_string_utf8(env, asyncCallbackInfo->bundleName.c_str(), NAPI_AUTO_LENGTH, &result); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + NAPI_GetBundleNameExecuteCallBack, + NAPI_GetBundleNamePromiseCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + napi_queue_async_work(env, asyncCallbackInfo.asyncWork); return promise; } } @@ -305,11 +318,11 @@ napi_value NAPI_GetBundleNameWrap( napi_value NAPI_GetBundleName(napi_env env, napi_callback_info info) { size_t argc = NUMBER_OF_PARAMETERS_TWO; - napi_value argv[argc]; + napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); HILOG_INFO("argc = [%{public}zu]", argc); - napi_valuetype wantAgentType; + napi_valuetype wantAgentType = napi_valuetype::napi_null; napi_typeof(env, argv[0], &wantAgentType); NAPI_ASSERT(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); @@ -322,13 +335,16 @@ napi_value NAPI_GetBundleName(napi_env env, napi_callback_info info) bool callBackMode = false; if (argc >= NUMBER_OF_PARAMETERS_TWO) { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_valuetype::napi_null; NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); callBackMode = true; } - AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = - new (std::nothrow) AsyncGetBundleNameCallbackInfo{.env = env, .asyncWork = nullptr, .deferred = nullptr}; + AsyncGetBundleNameCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncGetBundleNameCallbackInfo{ + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + }; if (asyncCallbackInfo == nullptr) { return NapiGetNull(env); } @@ -337,7 +353,7 @@ napi_value NAPI_GetBundleName(napi_env env, napi_callback_info info) if (callBackMode) { napi_create_reference(env, argv[1], 1, &asyncCallbackInfo->callback[0]); } - napi_value ret = NAPI_GetBundleNameWrap(env, info, callBackMode, asyncCallbackInfo); + napi_value ret = NAPI_GetBundleNameWrap(env, info, callBackMode, *asyncCallbackInfo); if (ret == nullptr) { delete asyncCallbackInfo; asyncCallbackInfo = nullptr; @@ -345,79 +361,84 @@ napi_value NAPI_GetBundleName(napi_env env, napi_callback_info info) return ((callBackMode) ? (NapiGetNull(env)) : (ret)); } +void NAPI_GetUidWrapExecuteCallBack(napi_env env, void *data) +{ + HILOG_INFO("GetUid called(CallBack Mode)..."); + AsyncGetUidCallbackInfo *asyncCallbackInfo = (AsyncGetUidCallbackInfo *)data; + asyncCallbackInfo->uid = WantAgentHelper::GetUid(asyncCallbackInfo->wantAgent); +} + +void NAPI_GetUidWrapCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("GetUid compeleted(CallBack Mode)..."); + AsyncGetUidCallbackInfo *asyncCallbackInfo = (AsyncGetUidCallbackInfo *)data; + napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value callResult = nullptr; + + result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); + napi_create_int32(env, asyncCallbackInfo->uid, &result[1]); + napi_get_undefined(env, &undefined); + napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); + napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); + + if (asyncCallbackInfo->callback[0] != nullptr) { + napi_delete_reference(env, asyncCallbackInfo->callback[0]); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + +void NAPI_GetUidWrapPromiseCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("GetUid compeleted(Promise Mode)..."); + AsyncGetUidCallbackInfo *asyncCallbackInfo = (AsyncGetUidCallbackInfo *)data; + napi_value result = nullptr; + napi_create_int32(env, asyncCallbackInfo->uid, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + napi_value NAPI_GetUidWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncGetUidCallbackInfo *asyncCallbackInfo) + napi_env env, napi_callback_info info, bool callBackMode, AsyncGetUidCallbackInfo &asyncCallbackInfo) { HILOG_INFO("NAPI_GetUidWrap called..."); if (callBackMode) { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_GetUidCallBack", NAPI_AUTO_LENGTH, &resourceName); napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("GetUid called(CallBack Mode)..."); - AsyncGetUidCallbackInfo *asyncCallbackInfo = (AsyncGetUidCallbackInfo *)data; - asyncCallbackInfo->uid = WantAgentHelper::GetUid(asyncCallbackInfo->wantAgent); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetUid compeleted(CallBack Mode)..."); - AsyncGetUidCallbackInfo *asyncCallbackInfo = (AsyncGetUidCallbackInfo *)data; - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - napi_value callback; - napi_value undefined; - napi_value callResult = 0; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - napi_create_int32(env, asyncCallbackInfo->uid, &result[1]); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + NAPI_GetUidWrapExecuteCallBack, + NAPI_GetUidWrapCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); // create reutrn - napi_value ret = 0; + napi_value ret = nullptr; NAPI_CALL(env, napi_create_int32(env, 0, &ret)); return ret; } else { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_GetUidPromise", NAPI_AUTO_LENGTH, &resourceName); - napi_deferred deferred; - napi_value promise; + napi_deferred deferred = nullptr; + napi_value promise = nullptr; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo->deferred = deferred; + asyncCallbackInfo.deferred = deferred; napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("GetUid called(Promise Mode)..."); - AsyncGetUidCallbackInfo *asyncCallbackInfo = (AsyncGetUidCallbackInfo *)data; - asyncCallbackInfo->uid = WantAgentHelper::GetUid(asyncCallbackInfo->wantAgent); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetUid compeleted(Promise Mode)..."); - AsyncGetUidCallbackInfo *asyncCallbackInfo = (AsyncGetUidCallbackInfo *)data; - napi_value result; - napi_create_int32(env, asyncCallbackInfo->uid, &result); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + NAPI_GetUidWrapExecuteCallBack, + NAPI_GetUidWrapPromiseCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + napi_queue_async_work(env, asyncCallbackInfo.asyncWork); return promise; } } @@ -425,11 +446,11 @@ napi_value NAPI_GetUidWrap( napi_value NAPI_GetUid(napi_env env, napi_callback_info info) { size_t argc = NUMBER_OF_PARAMETERS_TWO; - napi_value argv[argc]; + napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); HILOG_INFO("argc = [%{public}zu]", argc); - napi_valuetype wantAgentType; + napi_valuetype wantAgentType = napi_valuetype::napi_null; napi_typeof(env, argv[0], &wantAgentType); NAPI_ASSERT(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); @@ -441,13 +462,16 @@ napi_value NAPI_GetUid(napi_env env, napi_callback_info info) bool callBackMode = false; if (argc >= NUMBER_OF_PARAMETERS_TWO) { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_valuetype::napi_null; NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); callBackMode = true; } - AsyncGetUidCallbackInfo *asyncCallbackInfo = - new (std::nothrow) AsyncGetUidCallbackInfo{.env = env, .asyncWork = nullptr, .deferred = nullptr}; + AsyncGetUidCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncGetUidCallbackInfo{ + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + }; if (asyncCallbackInfo == nullptr) { return NapiGetNull(env); } @@ -456,7 +480,7 @@ napi_value NAPI_GetUid(napi_env env, napi_callback_info info) if (callBackMode) { napi_create_reference(env, argv[1], 1, &asyncCallbackInfo->callback[0]); } - napi_value ret = NAPI_GetUidWrap(env, info, callBackMode, asyncCallbackInfo); + napi_value ret = NAPI_GetUidWrap(env, info, callBackMode, *asyncCallbackInfo); if (ret == nullptr) { delete asyncCallbackInfo; asyncCallbackInfo = nullptr; @@ -464,78 +488,82 @@ napi_value NAPI_GetUid(napi_env env, napi_callback_info info) return ((callBackMode) ? (NapiGetNull(env)) : (ret)); } +void NAPI_GetWantWrapExecuteCallBack(napi_env env, void *data) +{ + HILOG_INFO("GetWant called(CallBack Mode)..."); + AsyncGetWantCallbackInfo *asyncCallbackInfo = (AsyncGetWantCallbackInfo *)data; + asyncCallbackInfo->want = WantAgentHelper::GetWant(asyncCallbackInfo->wantAgent); +} + +void NAPI_GetWantWrapCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("GetWant compeleted(CallBack Mode)..."); + AsyncGetWantCallbackInfo *asyncCallbackInfo = (AsyncGetWantCallbackInfo *)data; + napi_value result[NUMBER_OF_PARAMETERS_TWO] = {}; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value callResult = nullptr; + + result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); + result[1] = WrapWant(env, *(asyncCallbackInfo->want)); + napi_get_undefined(env, &undefined); + napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); + napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); + if (asyncCallbackInfo->callback[0] != nullptr) { + napi_delete_reference(env, asyncCallbackInfo->callback[0]); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + +void NAPI_GetWantWrapPromiseCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("GetWant compeleted(Promise Mode)..."); + AsyncGetWantCallbackInfo *asyncCallbackInfo = (AsyncGetWantCallbackInfo *)data; + napi_value result = WrapWant(env, *(asyncCallbackInfo->want)); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + napi_value NAPI_GetWantWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncGetWantCallbackInfo *asyncCallbackInfo) + napi_env env, napi_callback_info info, bool callBackMode, AsyncGetWantCallbackInfo &asyncCallbackInfo) { HILOG_INFO("NAPI_GetWantWrap called..."); if (callBackMode) { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_GetWantCallBack", NAPI_AUTO_LENGTH, &resourceName); napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("GetWant called(CallBack Mode)..."); - AsyncGetWantCallbackInfo *asyncCallbackInfo = (AsyncGetWantCallbackInfo *)data; - asyncCallbackInfo->want = WantAgentHelper::GetWant(asyncCallbackInfo->wantAgent); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetWant compeleted(CallBack Mode)..."); - AsyncGetWantCallbackInfo *asyncCallbackInfo = (AsyncGetWantCallbackInfo *)data; - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - napi_value callback; - napi_value undefined; - napi_value callResult = 0; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - result[1] = WrapWant(env, *(asyncCallbackInfo->want)); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + NAPI_GetWantWrapExecuteCallBack, + NAPI_GetWantWrapCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); // create reutrn - napi_value ret = 0; + napi_value ret = nullptr; NAPI_CALL(env, napi_create_int32(env, 0, &ret)); return ret; } else { napi_value resourceName; napi_create_string_latin1(env, "NAPI_GetWantPromise", NAPI_AUTO_LENGTH, &resourceName); - napi_deferred deferred; - napi_value promise; + napi_deferred deferred = nullptr; + napi_value promise = nullptr; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo->deferred = deferred; + asyncCallbackInfo.deferred = deferred; napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("GetWant called(Promise Mode)..."); - AsyncGetWantCallbackInfo *asyncCallbackInfo = (AsyncGetWantCallbackInfo *)data; - asyncCallbackInfo->want = WantAgentHelper::GetWant(asyncCallbackInfo->wantAgent); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetWant compeleted(Promise Mode)..."); - AsyncGetWantCallbackInfo *asyncCallbackInfo = (AsyncGetWantCallbackInfo *)data; - napi_value result; - result = WrapWant(env, *(asyncCallbackInfo->want)); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + NAPI_GetWantWrapExecuteCallBack, + NAPI_GetWantWrapPromiseCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + napi_queue_async_work(env, asyncCallbackInfo.asyncWork); return promise; } } @@ -543,11 +571,11 @@ napi_value NAPI_GetWantWrap( napi_value NAPI_GetWant(napi_env env, napi_callback_info info) { size_t argc = NUMBER_OF_PARAMETERS_TWO; - napi_value argv[argc]; + napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); HILOG_INFO("argc = [%{public}zu]", argc); - napi_valuetype wantAgentType; + napi_valuetype wantAgentType = napi_valuetype::napi_null; napi_typeof(env, argv[0], &wantAgentType); NAPI_ASSERT(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); @@ -559,13 +587,16 @@ napi_value NAPI_GetWant(napi_env env, napi_callback_info info) bool callBackMode = false; if (argc >= NUMBER_OF_PARAMETERS_TWO) { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_valuetype::napi_null; NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); callBackMode = true; } - AsyncGetWantCallbackInfo *asyncCallbackInfo = - new (std::nothrow) AsyncGetWantCallbackInfo{.env = env, .asyncWork = nullptr, .deferred = nullptr}; + AsyncGetWantCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncGetWantCallbackInfo{ + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + }; if (asyncCallbackInfo == nullptr) { return NapiGetNull(env); } @@ -574,7 +605,7 @@ napi_value NAPI_GetWant(napi_env env, napi_callback_info info) if (callBackMode) { napi_create_reference(env, argv[1], 1, &asyncCallbackInfo->callback[0]); } - napi_value ret = NAPI_GetWantWrap(env, info, callBackMode, asyncCallbackInfo); + napi_value ret = NAPI_GetWantWrap(env, info, callBackMode, *asyncCallbackInfo); if (ret == nullptr) { delete asyncCallbackInfo; asyncCallbackInfo = nullptr; @@ -598,83 +629,86 @@ void DeleteRecordByCode(const int32_t code) } } +void NAPI_CancelWrapExecuteCallBack(napi_env env, void *data) +{ + HILOG_INFO("Cancel called(CallBack Mode)..."); + AsyncCancelCallbackInfo *asyncCallbackInfo = (AsyncCancelCallbackInfo *)data; + int32_t code = WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); + WantAgentHelper::Cancel(asyncCallbackInfo->wantAgent); + DeleteRecordByCode(code); +} + +void NAPI_CancelWrapCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("Cancel compeleted(CallBack Mode)..."); + AsyncCancelCallbackInfo *asyncCallbackInfo = (AsyncCancelCallbackInfo *)data; + napi_value result[NUMBER_OF_PARAMETERS_TWO] = {nullptr}; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value callResult = nullptr; + + result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); + napi_get_null(env, &result[1]); + napi_get_undefined(env, &undefined); + napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); + napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); + + if (asyncCallbackInfo->callback[0] != nullptr) { + napi_delete_reference(env, asyncCallbackInfo->callback[0]); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + +void NAPI_CancelWrapPromiseCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("Cancel compeleted(Promise Mode)..."); + AsyncCancelCallbackInfo *asyncCallbackInfo = (AsyncCancelCallbackInfo *)data; + napi_value result = nullptr; + napi_get_null(env, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + napi_value NAPI_CancelWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncCancelCallbackInfo *asyncCallbackInfo) + napi_env env, napi_callback_info info, bool callBackMode, AsyncCancelCallbackInfo &asyncCallbackInfo) { HILOG_INFO("NAPI_CancelWrap called..."); if (callBackMode) { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_CancelCallBack", NAPI_AUTO_LENGTH, &resourceName); napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("Cancel called(CallBack Mode)..."); - AsyncCancelCallbackInfo *asyncCallbackInfo = (AsyncCancelCallbackInfo *)data; - int32_t code = WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); - WantAgentHelper::Cancel(asyncCallbackInfo->wantAgent); - DeleteRecordByCode(code); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Cancel compeleted(CallBack Mode)..."); - AsyncCancelCallbackInfo *asyncCallbackInfo = (AsyncCancelCallbackInfo *)data; - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - napi_value callback; - napi_value undefined; - napi_value callResult = 0; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - napi_get_null(env, &result[1]); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + NAPI_CancelWrapExecuteCallBack, + NAPI_CancelWrapCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); // create reutrn - napi_value ret = 0; + napi_value ret = nullptr; NAPI_CALL(env, napi_create_int32(env, 0, &ret)); return ret; } else { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_CancelPromise", NAPI_AUTO_LENGTH, &resourceName); - napi_deferred deferred; - napi_value promise; + napi_deferred deferred = nullptr; + napi_value promise = nullptr; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo->deferred = deferred; + asyncCallbackInfo.deferred = deferred; napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("Cancel called(Promise Mode)..."); - AsyncCancelCallbackInfo *asyncCallbackInfo = (AsyncCancelCallbackInfo *)data; - int32_t code = WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); - WantAgentHelper::Cancel(asyncCallbackInfo->wantAgent); - DeleteRecordByCode(code); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Cancel compeleted(Promise Mode)..."); - AsyncCancelCallbackInfo *asyncCallbackInfo = (AsyncCancelCallbackInfo *)data; - napi_value result; - napi_get_null(env, &result); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + NAPI_CancelWrapExecuteCallBack, + NAPI_CancelWrapPromiseCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + napi_queue_async_work(env, asyncCallbackInfo.asyncWork); return promise; } } @@ -682,11 +716,11 @@ napi_value NAPI_CancelWrap( napi_value NAPI_Cancel(napi_env env, napi_callback_info info) { size_t argc = NUMBER_OF_PARAMETERS_TWO; - napi_value argv[argc]; + napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); HILOG_INFO("argc = [%{public}zu]", argc); - napi_valuetype wantAgentType; + napi_valuetype wantAgentType = napi_valuetype::napi_null; napi_typeof(env, argv[0], &wantAgentType); NAPI_ASSERT(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); @@ -698,13 +732,16 @@ napi_value NAPI_Cancel(napi_env env, napi_callback_info info) bool callBackMode = false; if (argc >= NUMBER_OF_PARAMETERS_TWO) { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_valuetype::napi_null; NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); callBackMode = true; } - AsyncCancelCallbackInfo *asyncCallbackInfo = - new (std::nothrow) AsyncCancelCallbackInfo{.env = env, .asyncWork = nullptr, .deferred = nullptr}; + AsyncCancelCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncCancelCallbackInfo{ + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + }; if (asyncCallbackInfo == nullptr) { return NapiGetNull(env); } @@ -713,7 +750,7 @@ napi_value NAPI_Cancel(napi_env env, napi_callback_info info) if (callBackMode) { napi_create_reference(env, argv[1], 1, &asyncCallbackInfo->callback[0]); } - napi_value ret = NAPI_CancelWrap(env, info, callBackMode, asyncCallbackInfo); + napi_value ret = NAPI_CancelWrap(env, info, callBackMode, *asyncCallbackInfo); if (ret == nullptr) { delete asyncCallbackInfo; asyncCallbackInfo = nullptr; @@ -721,61 +758,53 @@ napi_value NAPI_Cancel(napi_env env, napi_callback_info info) return ((callBackMode) ? (NapiGetNull(env)) : (ret)); } -napi_value NAPI_TriggerWrap(napi_env env, napi_callback_info info, AsyncTriggerCallbackInfo *asyncCallbackInfo) +void NAPI_TriggerWrapExecuteCallBack(napi_env env, void *data) +{ + HILOG_INFO("Trigger called ..."); + AsyncTriggerCallbackInfo *asyncCallbackInfo = (AsyncTriggerCallbackInfo *)data; + asyncCallbackInfo->triggerObj->SetCallbackInfo(env, asyncCallbackInfo->callback[0]); + asyncCallbackInfo->triggerObj->SetWantAgentInstance(asyncCallbackInfo->wantAgent); + WantAgentHelper::TriggerWantAgent(asyncCallbackInfo->context, + asyncCallbackInfo->wantAgent, + asyncCallbackInfo->triggerObj, + asyncCallbackInfo->triggerInfo); +} + +void NAPI_TriggerWrapCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("Trigger compeleted ..."); + AsyncTriggerCallbackInfo *asyncCallbackInfo = (AsyncTriggerCallbackInfo *)data; + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + +napi_value NAPI_TriggerWrap(napi_env env, napi_callback_info info, AsyncTriggerCallbackInfo &asyncCallbackInfo) { HILOG_INFO("NAPI_TriggerWrap called..."); - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_TriggerWrap", NAPI_AUTO_LENGTH, &resourceName); napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("Trigger called ..."); - AsyncTriggerCallbackInfo *asyncCallbackInfo = (AsyncTriggerCallbackInfo *)data; - asyncCallbackInfo->triggerObj->SetCallbackInfo(env, asyncCallbackInfo->callback[0]); - asyncCallbackInfo->triggerObj->SetWantAgentInstance(asyncCallbackInfo->wantAgent); - WantAgentHelper::TriggerWantAgent(asyncCallbackInfo->context, - asyncCallbackInfo->wantAgent, - asyncCallbackInfo->triggerObj, - asyncCallbackInfo->triggerInfo); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Trigger compeleted ..."); - AsyncTriggerCallbackInfo *asyncCallbackInfo = (AsyncTriggerCallbackInfo *)data; - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); + NAPI_TriggerWrapExecuteCallBack, + NAPI_TriggerWrapCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); // create reutrn - napi_value ret = 0; + napi_value ret = nullptr; NAPI_CALL(env, napi_create_int32(env, 0, &ret)); return ret; } -napi_value NAPI_Trigger(napi_env env, napi_callback_info info) +napi_value NAPI_GetTriggerInfo(napi_value argv[NUMBER_OF_PARAMETERS_THREE], size_t argc, napi_env env, + napi_callback_info info, Notification::WantAgent::TriggerInfo &triggerInfo) { - size_t argc = NUMBER_OF_PARAMETERS_THREE; - napi_value argv[argc]; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - HILOG_INFO("argc = [%{public}zu]", argc); - - napi_valuetype wantAgentType; - napi_typeof(env, argv[0], &wantAgentType); - NAPI_ASSERT(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); - - Notification::WantAgent::WantAgent *pWantAgent = nullptr; - napi_unwrap(env, argv[0], (void **)&(pWantAgent)); - if (pWantAgent == nullptr) { - return NapiGetNull(env); - } - // Get triggerInfo napi_value jsTriggerInfo = argv[1]; - napi_valuetype valueType; + napi_valuetype valueType = napi_valuetype::napi_null; NAPI_CALL(env, napi_typeof(env, jsTriggerInfo, &valueType)); NAPI_ASSERT(env, valueType == napi_object, "param type mismatch!"); @@ -795,7 +824,7 @@ napi_value NAPI_Trigger(napi_env env, napi_callback_info info) } } // Get triggerInfo permission - std::string permission; + std::string permission = {}; UnwrapStringByPropertyName(env, jsTriggerInfo, "permission", permission); // Get triggerInfo extraInfo napi_value jsExtraInfo = nullptr; @@ -807,15 +836,37 @@ napi_value NAPI_Trigger(napi_env env, napi_callback_info info) return NapiGetNull(env); } } + + Notification::WantAgent::TriggerInfo triggerInfoData(permission, extraInfo, want, code); + triggerInfo = triggerInfoData; + return NapiGetNull(env); +} + +napi_value NAPI_Trigger(napi_env env, napi_callback_info info) +{ + size_t argc = NUMBER_OF_PARAMETERS_THREE; + napi_value argv[NUMBER_OF_PARAMETERS_THREE] = {}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); + HILOG_INFO("argc = [%{public}zu]", argc); + + napi_valuetype wantAgentType = napi_valuetype::napi_null; + napi_typeof(env, argv[0], &wantAgentType); + NAPI_ASSERT(env, wantAgentType == napi_object, "Wrong argument type. Object expected."); + + Notification::WantAgent::WantAgent *pWantAgent = nullptr; + napi_unwrap(env, argv[0], (void **)&(pWantAgent)); + if (pWantAgent == nullptr) { + return NapiGetNull(env); + } + // Get context - napi_value global = 0; + napi_value global = nullptr; NAPI_CALL(env, napi_get_global(env, &global)); - napi_value abilityObj = 0; + napi_value abilityObj = nullptr; NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); Ability *ability = nullptr; NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); - std::shared_ptr context = nullptr; - context = ability->GetContext(); + std::shared_ptr context = ability->GetContext(); bool callBackMode = false; if (argc >= NUMBER_OF_PARAMETERS_THREE) { @@ -824,14 +875,23 @@ napi_value NAPI_Trigger(napi_env env, napi_callback_info info) NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); callBackMode = true; } - AsyncTriggerCallbackInfo *asyncCallbackInfo = - new (std::nothrow) AsyncTriggerCallbackInfo{.env = env, .asyncWork = nullptr, .deferred = nullptr}; + + Notification::WantAgent::TriggerInfo triggerInfo; + napi_value ret = NAPI_GetTriggerInfo(argv, argc, env, info, triggerInfo); + if (ret == nullptr) { + return NapiGetNull(env); + } + + AsyncTriggerCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncTriggerCallbackInfo{ + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + }; if (asyncCallbackInfo == nullptr) { return NapiGetNull(env); } asyncCallbackInfo->wantAgent = std::make_shared(*pWantAgent); asyncCallbackInfo->context = context; - Notification::WantAgent::TriggerInfo triggerInfo(permission, extraInfo, want, code); asyncCallbackInfo->triggerInfo = triggerInfo; asyncCallbackInfo->triggerObj = nullptr; if (callBackMode) { @@ -840,7 +900,7 @@ napi_value NAPI_Trigger(napi_env env, napi_callback_info info) napi_create_reference(env, argv[NUMBER_OF_PARAMETERS_TWO], 1, &asyncCallbackInfo->callback[0]); } - napi_value ret = NAPI_TriggerWrap(env, info, asyncCallbackInfo); + ret = NAPI_TriggerWrap(env, info, *asyncCallbackInfo); if (ret == nullptr) { delete asyncCallbackInfo; asyncCallbackInfo = nullptr; @@ -848,81 +908,85 @@ napi_value NAPI_Trigger(napi_env env, napi_callback_info info) return NapiGetNull(env); } +void NAPI_EqualWrapExecuteCallBack(napi_env env, void *data) +{ + HILOG_INFO("Equal called(CallBack Mode)..."); + AsyncEqualCallbackInfo *asyncCallbackInfo = (AsyncEqualCallbackInfo *)data; + asyncCallbackInfo->result = + WantAgentHelper::JudgeEquality(asyncCallbackInfo->wantAgentFirst, asyncCallbackInfo->wantAgentSecond); +} + +void NAPI_EqualWrapCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("Equal compeleted(CallBack Mode)..."); + AsyncEqualCallbackInfo *asyncCallbackInfo = (AsyncEqualCallbackInfo *)data; + napi_value result[NUMBER_OF_PARAMETERS_TWO] = {}; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value callResult = nullptr; + + result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); + napi_get_boolean(env, asyncCallbackInfo->result, &result[1]); + napi_get_undefined(env, &undefined); + napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); + napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); + + if (asyncCallbackInfo->callback[0] != nullptr) { + napi_delete_reference(env, asyncCallbackInfo->callback[0]); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + +void NAPI_EqualWrapPromiseCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("Equal compeleted(Promise Mode)..."); + AsyncEqualCallbackInfo *asyncCallbackInfo = (AsyncEqualCallbackInfo *)data; + napi_value result = nullptr; + napi_get_boolean(env, asyncCallbackInfo->result, &result); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; +} + napi_value NAPI_EqualWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncEqualCallbackInfo *asyncCallbackInfo) + napi_env env, napi_callback_info info, bool callBackMode, AsyncEqualCallbackInfo &asyncCallbackInfo) { HILOG_INFO("NAPI_EqualWrap called..."); if (callBackMode) { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_EqualWrapCallBack", NAPI_AUTO_LENGTH, &resourceName); napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("Equal called(CallBack Mode)..."); - AsyncEqualCallbackInfo *asyncCallbackInfo = (AsyncEqualCallbackInfo *)data; - asyncCallbackInfo->result = WantAgentHelper::JudgeEquality( - asyncCallbackInfo->wantAgentFirst, asyncCallbackInfo->wantAgentSecond); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Equal compeleted(CallBack Mode)..."); - AsyncEqualCallbackInfo *asyncCallbackInfo = (AsyncEqualCallbackInfo *)data; - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - napi_value callback; - napi_value undefined; - napi_value callResult = 0; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - napi_get_boolean(env, asyncCallbackInfo->result, &result[1]); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + NAPI_EqualWrapExecuteCallBack, + NAPI_EqualWrapCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); // create reutrn - napi_value ret = 0; + napi_value ret = nullptr; NAPI_CALL(env, napi_create_int32(env, 0, &ret)); return ret; } else { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_EqualPromise", NAPI_AUTO_LENGTH, &resourceName); - napi_deferred deferred; - napi_value promise; + napi_deferred deferred = nullptr; + napi_value promise = nullptr; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo->deferred = deferred; + asyncCallbackInfo.deferred = deferred; napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("Equal called(Promise Mode)..."); - AsyncEqualCallbackInfo *asyncCallbackInfo = (AsyncEqualCallbackInfo *)data; - asyncCallbackInfo->result = WantAgentHelper::JudgeEquality( - asyncCallbackInfo->wantAgentFirst, asyncCallbackInfo->wantAgentSecond); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("Equal compeleted(Promise Mode)..."); - AsyncEqualCallbackInfo *asyncCallbackInfo = (AsyncEqualCallbackInfo *)data; - napi_value result; - napi_get_boolean(env, asyncCallbackInfo->result, &result); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - delete asyncCallbackInfo; - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + NAPI_EqualWrapExecuteCallBack, + NAPI_EqualWrapPromiseCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + napi_queue_async_work(env, asyncCallbackInfo.asyncWork); return promise; } } @@ -930,11 +994,11 @@ napi_value NAPI_EqualWrap( napi_value NAPI_Equal(napi_env env, napi_callback_info info) { size_t argc = NUMBER_OF_PARAMETERS_THREE; - napi_value argv[argc]; + napi_value argv[NUMBER_OF_PARAMETERS_THREE] = {}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); HILOG_INFO("argc = [%{public}zu]", argc); - napi_valuetype wantAgentFirstType; + napi_valuetype wantAgentFirstType = napi_valuetype::napi_null; napi_typeof(env, argv[0], &wantAgentFirstType); NAPI_ASSERT(env, wantAgentFirstType == napi_object, "Wrong argument type. Object expected."); @@ -944,7 +1008,7 @@ napi_value NAPI_Equal(napi_env env, napi_callback_info info) return NapiGetNull(env); } - napi_valuetype wantAgentSecondType; + napi_valuetype wantAgentSecondType = napi_valuetype::napi_null; napi_typeof(env, argv[1], &wantAgentSecondType); NAPI_ASSERT(env, wantAgentSecondType == napi_object, "Wrong argument type. Object expected."); @@ -956,13 +1020,16 @@ napi_value NAPI_Equal(napi_env env, napi_callback_info info) bool callBackMode = false; if (argc >= NUMBER_OF_PARAMETERS_THREE) { - napi_valuetype valuetype; + napi_valuetype valuetype = napi_valuetype::napi_null; NAPI_CALL(env, napi_typeof(env, argv[NUMBER_OF_PARAMETERS_TWO], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); callBackMode = true; } - AsyncEqualCallbackInfo *asyncCallbackInfo = - new (std::nothrow) AsyncEqualCallbackInfo{.env = env, .asyncWork = nullptr, .deferred = nullptr}; + AsyncEqualCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncEqualCallbackInfo{ + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + }; if (asyncCallbackInfo == nullptr) { return NapiGetNull(env); } @@ -972,7 +1039,7 @@ napi_value NAPI_Equal(napi_env env, napi_callback_info info) if (callBackMode) { napi_create_reference(env, argv[NUMBER_OF_PARAMETERS_TWO], 1, &asyncCallbackInfo->callback[0]); } - napi_value ret = NAPI_EqualWrap(env, info, callBackMode, asyncCallbackInfo); + napi_value ret = NAPI_EqualWrap(env, info, callBackMode, *asyncCallbackInfo); if (ret == nullptr) { delete asyncCallbackInfo; asyncCallbackInfo = nullptr; @@ -980,211 +1047,181 @@ napi_value NAPI_Equal(napi_env env, napi_callback_info info) return ((callBackMode) ? (NapiGetNull(env)) : (ret)); } +void NAPI_GetWantAgentWrapExecuteCallBack(napi_env env, void *data) +{ + HILOG_INFO("GetWantAgent called(CallBack Mode)..."); + AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = (AsyncGetWantAgentCallbackInfo *)data; + Notification::WantAgent::WantAgentInfo wantAgentInfo(asyncCallbackInfo->requestCode, + asyncCallbackInfo->operationType, + asyncCallbackInfo->wantAgentFlags, + asyncCallbackInfo->wants, + asyncCallbackInfo->extraInfo); + asyncCallbackInfo->wantAgent = + Notification::WantAgent::WantAgentHelper::GetWantAgent(asyncCallbackInfo->context, wantAgentInfo); + if (asyncCallbackInfo->wantAgent == nullptr) { + HILOG_INFO("GetWantAgent instance is nullptr..."); + } + int32_t code = Notification::WantAgent::WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); + std::lock_guard guard(g_mutex); + g_WantAgentMap.emplace(asyncCallbackInfo, code); +} + +void NAPI_GetWantAgentWrapCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("GetWantAgent compeleted(CallBack Mode)..."); + AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = (AsyncGetWantAgentCallbackInfo *)data; + napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value callResult = nullptr; + + result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); + + napi_value wantAgentClass = nullptr; + napi_define_class(env, + "WantAgentClass", + NAPI_AUTO_LENGTH, + [](napi_env env, napi_callback_info info) -> napi_value { + napi_value thisVar = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); + return thisVar; + }, + nullptr, + 0, + nullptr, + &wantAgentClass); + napi_new_instance(env, wantAgentClass, 0, nullptr, &result[1]); + napi_wrap(env, + result[1], + (void *)asyncCallbackInfo->wantAgent.get(), + [](napi_env env, void *data, void *hint) {}, + nullptr, + nullptr); + napi_get_undefined(env, &undefined); + napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); + napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); + + if (asyncCallbackInfo->callback[0] != nullptr) { + napi_delete_reference(env, asyncCallbackInfo->callback[0]); + } + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); +} + +void NAPI_GetWantAgentWrapPromiseCompleteCallBack(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("GetWantAgent compeleted(Promise Mode)..."); + AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = (AsyncGetWantAgentCallbackInfo *)data; + napi_value wantAgentClass = nullptr; + napi_define_class(env, + "WantAgentClass", + NAPI_AUTO_LENGTH, + [](napi_env env, napi_callback_info info) -> napi_value { + napi_value thisVar = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); + return thisVar; + }, + nullptr, + 0, + nullptr, + &wantAgentClass); + napi_value result = nullptr; + napi_new_instance(env, wantAgentClass, 0, nullptr, &result); + napi_wrap(env, + result, + (void *)asyncCallbackInfo->wantAgent.get(), + [](napi_env env, void *data, void *hint) {}, + nullptr, + nullptr); + napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); +} + napi_value NAPI_GetWantAgentWrap( - napi_env env, napi_callback_info info, bool callBackMode, AsyncGetWantAgentCallbackInfo *asyncCallbackInfo) + napi_env env, napi_callback_info info, bool callBackMode, AsyncGetWantAgentCallbackInfo &asyncCallbackInfo) { HILOG_INFO("NAPI_GetWantAgentWrap called..."); if (callBackMode) { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_GetWantAgentCallBack", NAPI_AUTO_LENGTH, &resourceName); napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("GetWantAgent called(CallBack Mode)..."); - AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = (AsyncGetWantAgentCallbackInfo *)data; - Notification::WantAgent::WantAgentInfo wantAgentInfo(asyncCallbackInfo->requestCode, - asyncCallbackInfo->operationType, - asyncCallbackInfo->wantAgentFlags, - asyncCallbackInfo->wants, - asyncCallbackInfo->extraInfo); - asyncCallbackInfo->wantAgent = - Notification::WantAgent::WantAgentHelper::GetWantAgent(asyncCallbackInfo->context, wantAgentInfo); - if (asyncCallbackInfo->wantAgent == nullptr) { - HILOG_INFO("GetWantAgent instance is nullptr..."); - } - int32_t code = Notification::WantAgent::WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); - std::lock_guard guard(g_mutex); - g_WantAgentMap.emplace(asyncCallbackInfo, code); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetWantAgent compeleted(CallBack Mode)..."); - AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = (AsyncGetWantAgentCallbackInfo *)data; - napi_value result[NUMBER_OF_PARAMETERS_TWO] = {0}; - napi_value callback; - napi_value undefined; - napi_value callResult = 0; - - result[0] = GetCallbackErrorResult(asyncCallbackInfo->env, BUSINESS_ERROR_CODE_OK); - - napi_value wantAgentClass = nullptr; - napi_define_class(env, - "WantAgentClass", - NAPI_AUTO_LENGTH, - [](napi_env env, napi_callback_info info) -> napi_value { - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); - return thisVar; - }, - nullptr, - 0, - nullptr, - &wantAgentClass); - napi_new_instance(env, wantAgentClass, 0, nullptr, &result[1]); - napi_wrap(env, - result[1], - (void *)asyncCallbackInfo->wantAgent.get(), - [](napi_env env, void *data, void *hint) {}, - nullptr, - nullptr); - napi_get_undefined(env, &undefined); - napi_get_reference_value(env, asyncCallbackInfo->callback[0], &callback); - napi_call_function(env, undefined, callback, NUMBER_OF_PARAMETERS_TWO, &result[0], &callResult); - - if (asyncCallbackInfo->callback[0] != nullptr) { - napi_delete_reference(env, asyncCallbackInfo->callback[0]); - } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + NAPI_GetWantAgentWrapExecuteCallBack, + NAPI_GetWantAgentWrapCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo.asyncWork)); // create reutrn - napi_value ret = 0; + napi_value ret = nullptr; NAPI_CALL(env, napi_create_int32(env, 0, &ret)); return ret; } else { - napi_value resourceName; + napi_value resourceName = nullptr; napi_create_string_latin1(env, "NAPI_GetWantAgentPromise", NAPI_AUTO_LENGTH, &resourceName); - napi_deferred deferred; - napi_value promise; + napi_deferred deferred = nullptr; + napi_value promise = nullptr; NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo->deferred = deferred; + asyncCallbackInfo.deferred = deferred; napi_create_async_work(env, nullptr, resourceName, - [](napi_env env, void *data) { - HILOG_INFO("GetWantAgent called(Promise Mode)..."); - AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = (AsyncGetWantAgentCallbackInfo *)data; - HILOG_INFO("GetWantAgent wants.size = [%{public}zu], wantAgentFlags.size = [%{public}zu]", - asyncCallbackInfo->wants.size(), - asyncCallbackInfo->wantAgentFlags.size()); - - Notification::WantAgent::WantAgentInfo wantAgentInfo(asyncCallbackInfo->requestCode, - asyncCallbackInfo->operationType, - asyncCallbackInfo->wantAgentFlags, - asyncCallbackInfo->wants, - asyncCallbackInfo->extraInfo); - asyncCallbackInfo->wantAgent = - Notification::WantAgent::WantAgentHelper::GetWantAgent(asyncCallbackInfo->context, wantAgentInfo); - if (asyncCallbackInfo->wantAgent == nullptr) { - HILOG_INFO("GetWantAgent instance is nullptr..."); - } - int32_t code = Notification::WantAgent::WantAgentHelper::GetHashCode(asyncCallbackInfo->wantAgent); - std::lock_guard guard(g_mutex); - g_WantAgentMap.emplace(asyncCallbackInfo, code); - }, - [](napi_env env, napi_status status, void *data) { - HILOG_INFO("GetWantAgent compeleted(Promise Mode)..."); - AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = (AsyncGetWantAgentCallbackInfo *)data; - napi_value wantAgentClass = nullptr; - napi_define_class(env, - "WantAgentClass", - NAPI_AUTO_LENGTH, - [](napi_env env, napi_callback_info info) -> napi_value { - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); - return thisVar; - }, - nullptr, - 0, - nullptr, - &wantAgentClass); - napi_value result = nullptr; - napi_new_instance(env, wantAgentClass, 0, nullptr, &result); - napi_wrap(env, - result, - (void *)asyncCallbackInfo->wantAgent.get(), - [](napi_env env, void *data, void *hint) {}, - nullptr, - nullptr); - napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, result); - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork); - napi_queue_async_work(env, asyncCallbackInfo->asyncWork); + NAPI_GetWantAgentWrapExecuteCallBack, + NAPI_GetWantAgentWrapPromiseCompleteCallBack, + (void *)&asyncCallbackInfo, + &asyncCallbackInfo.asyncWork); + napi_queue_async_work(env, asyncCallbackInfo.asyncWork); return promise; } } -napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info) +napi_value NAPI_GetWantAgentWants(napi_env env, napi_value jsWantAgentInfo, + std::vector> &wants, int32_t &operationType, int32_t &requestCode, + std::vector &wantAgentFlags, AAFwk::WantParams &extraInfo) { - size_t argc = NUMBER_OF_PARAMETERS_TWO; - napi_value argv[argc]; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - HILOG_INFO("argc = [%{public}zu]", argc); - - napi_valuetype jsWantAgentInfoType; - napi_value jsWantAgentInfo = argv[0]; + napi_valuetype jsWantAgentInfoType = napi_valuetype::napi_null; NAPI_CALL(env, napi_typeof(env, jsWantAgentInfo, &jsWantAgentInfoType)); NAPI_ASSERT(env, jsWantAgentInfoType == napi_object, "param type mismatch!"); - napi_value jsWants = nullptr; - jsWants = GetPropertyValueByPropertyName(env, jsWantAgentInfo, "wants", napi_object); - if (jsWants == nullptr) { - return NapiGetNull(env); - } + napi_value jsWants = GetPropertyValueByPropertyName(env, jsWantAgentInfo, "wants", napi_object); bool isArray = false; - if (napi_is_array(env, jsWants, &isArray) != napi_ok) { - return NapiGetNull(env); - } - if (isArray == false) { + if (jsWants == nullptr || napi_is_array(env, jsWants, &isArray) != napi_ok || !isArray) { return NapiGetNull(env); } + uint32_t wantsLen = 0; napi_get_array_length(env, jsWants, &wantsLen); - if (wantsLen < 0) { - return NapiGetNull(env); - } - std::vector> wants; for (uint32_t i = 0; i < wantsLen; i++) { std::shared_ptr want = std::make_shared(); - napi_value jsWant; + napi_value jsWant = nullptr; napi_get_element(env, jsWants, i, &jsWant); if (!UnwrapWant(env, jsWant, *want)) { return NapiGetNull(env); } - HILOG_INFO("want type is [%{public}s]", want->GetType().c_str()); wants.emplace_back(want); } + // Get operationType - int32_t operationType = -1; if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "operationType", operationType)) { return NapiGetNull(env); } // Get requestCode - int32_t requestCode = -1; if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "requestCode", requestCode)) { return NapiGetNull(env); } // Get wantAgentFlags - napi_value JsWantAgentFlags = nullptr; - std::vector wantAgentFlags; - JsWantAgentFlags = GetPropertyValueByPropertyName(env, jsWantAgentInfo, "wantAgentFlags", napi_object); - HILOG_INFO("NAPI_GetWantAgent8"); + napi_value JsWantAgentFlags = GetPropertyValueByPropertyName(env, jsWantAgentInfo, "wantAgentFlags", napi_object); if (JsWantAgentFlags != nullptr) { uint32_t arrayLength = 0; NAPI_CALL(env, napi_get_array_length(env, JsWantAgentFlags, &arrayLength)); HILOG_INFO("property is array, length=%{public}d", arrayLength); for (uint32_t i = 0; i < arrayLength; i++) { - napi_value napiWantAgentFlags; + napi_value napiWantAgentFlags = nullptr; napi_get_element(env, JsWantAgentFlags, i, &napiWantAgentFlags); - napi_valuetype valuetype0; + napi_valuetype valuetype0 = napi_valuetype::napi_null; NAPI_CALL(env, napi_typeof(env, napiWantAgentFlags, &valuetype0)); NAPI_ASSERT(env, valuetype0 == napi_number, "Wrong argument type. Numbers expected."); int32_t value0 = 0; @@ -1193,14 +1230,35 @@ napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info) } } // Get extraInfo - napi_value JsExtraInfo = nullptr; - JsExtraInfo = GetPropertyValueByPropertyName(env, jsWantAgentInfo, "extraInfo", napi_object); - AAFwk::WantParams extraInfo; + napi_value JsExtraInfo = GetPropertyValueByPropertyName(env, jsWantAgentInfo, "extraInfo", napi_object); if (JsExtraInfo != nullptr) { if (!UnwrapWantParams(env, JsExtraInfo, extraInfo)) { return NapiGetNull(env); } } + return NapiGetNull(env); +} + +napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info) +{ + size_t argc = NUMBER_OF_PARAMETERS_TWO; + napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); + HILOG_INFO("argc = [%{public}zu]", argc); + napi_value jsWantAgentInfo = argv[0]; + + // Get wants + std::vector> wants = {}; + int32_t operationType = -1; + int32_t requestCode = -1; + std::vector wantAgentFlags = {}; + AAFwk::WantParams extraInfo = {}; + napi_value ret = + NAPI_GetWantAgentWants(env, jsWantAgentInfo, wants, operationType, requestCode, wantAgentFlags, extraInfo); + if (ret == nullptr) { + return NapiGetNull(env); + } + // Get context napi_value global = 0; NAPI_CALL(env, napi_get_global(env, &global)); @@ -1208,8 +1266,7 @@ napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info) NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); Ability *ability = nullptr; NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); - std::shared_ptr context = nullptr; - context = ability->GetContext(); + std::shared_ptr context = ability->GetContext(); bool callBackMode = false; if (argc >= NUMBER_OF_PARAMETERS_TWO) { @@ -1219,8 +1276,11 @@ napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info) callBackMode = true; } - AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = - new (std::nothrow) AsyncGetWantAgentCallbackInfo{.env = env, .asyncWork = nullptr, .deferred = nullptr}; + AsyncGetWantAgentCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncGetWantAgentCallbackInfo{ + .env = env, + .asyncWork = nullptr, + .deferred = nullptr, + }; if (asyncCallbackInfo == nullptr) { return NapiGetNull(env); } @@ -1235,7 +1295,7 @@ napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info) if (callBackMode) { napi_create_reference(env, argv[1], 1, &asyncCallbackInfo->callback[0]); } - napi_value ret = NAPI_GetWantAgentWrap(env, info, callBackMode, asyncCallbackInfo); + ret = NAPI_GetWantAgentWrap(env, info, callBackMode, *asyncCallbackInfo); if (ret == nullptr) { delete asyncCallbackInfo; asyncCallbackInfo = nullptr; @@ -1256,9 +1316,8 @@ napi_value GetCallbackErrorResult(napi_env env, int errCode) napi_value NapiGetNull(napi_env env) { - napi_value result = 0; + napi_value result = nullptr; napi_get_null(env, &result); return result; } - } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/wantagent/napi_want_agent.h b/interfaces/kits/napi/wantagent/napi_want_agent.h index e5bf33c25..cd3989835 100644 --- a/interfaces/kits/napi/wantagent/napi_want_agent.h +++ b/interfaces/kits/napi/wantagent/napi_want_agent.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "napi/native_common.h" #include "napi/native_node_api.h" @@ -33,7 +34,6 @@ #include "trigger_info.h" namespace OHOS { - using namespace OHOS::AppExecFwk; using namespace OHOS::Notification; using namespace OHOS::Notification::WantAgent; @@ -151,11 +151,13 @@ public: private: CallbackInfo triggerCompleteInfo_; + + static void OnSendFinishedUvAfterWorkCallback(uv_work_t *work, int status); }; napi_value WantAgentInit(napi_env env, napi_value exports); -void SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const char *propName); +void SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const std::string &propName); napi_value WantAgentFlagsInit(napi_env env, napi_value exports); napi_value WantAgentOperationTypeInit(napi_env env, napi_value exports); @@ -173,6 +175,5 @@ napi_value NapiGetNull(napi_env env); void DeleteRecordByCode(const int32_t code); static std::map g_WantAgentMap; static std::recursive_mutex g_mutex; - } // namespace OHOS #endif // NAPI_WANT_AGENT_H diff --git a/interfaces/kits/napi/wantagent/native_module.cpp b/interfaces/kits/napi/wantagent/native_module.cpp index 11981d2a2..0177c32c6 100644 --- a/interfaces/kits/napi/wantagent/native_module.cpp +++ b/interfaces/kits/napi/wantagent/native_module.cpp @@ -44,13 +44,15 @@ EXTERN_C_END /* * Module define */ -static napi_module _module = {.nm_version = 1, +static napi_module _module = { + .nm_version = 1, .nm_flags = 0, .nm_filename = nullptr, .nm_register_func = Init, .nm_modname = "wantagent", .nm_priv = ((void *)0), - .reserved = {0}}; + .reserved = {0}, +}; /* * Module register function diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index f46776fb7..f8fb31830 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -674,7 +674,7 @@ bool NotificationPreferencesDatabase::StoreDeathRecipient() return true; } -template +template OHOS::DistributedKv::Status NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( const std::string &bundleKey, const BundleType &type, const T &t) { @@ -1234,4 +1234,4 @@ void NotificationPreferencesDatabase::ParseSlotEnableBypassDnd( slot->EnableBypassDnd(enable); } } // namespace Notification -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/notification_preferences_test.cpp b/services/ans/test/unittest/notification_preferences_test.cpp index 510034cfa..f21215383 100644 --- a/services/ans/test/unittest/notification_preferences_test.cpp +++ b/services/ans/test/unittest/notification_preferences_test.cpp @@ -843,7 +843,7 @@ HWTEST_F(NotificationPreferencesTest, GetImportance_00100, Function | SmallTest { int importance = 1; EXPECT_EQ((int)NotificationPreferences::GetInstance().SetImportance(bundleOption_, importance), (int)ERR_OK); - int getImportance = 0;; + int getImportance = 0; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetImportance(bundleOption_, getImportance), (int)ERR_OK); EXPECT_EQ(getImportance, 1); @@ -856,7 +856,7 @@ HWTEST_F(NotificationPreferencesTest, GetImportance_00100, Function | SmallTest */ HWTEST_F(NotificationPreferencesTest, GetImportance_00200, Function | SmallTest | Level1) { - int getImportance = 0;; + int getImportance = 0; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetImportance(bundleEmptyOption_, getImportance), (int)ERR_ANS_INVALID_PARAM); } @@ -893,7 +893,7 @@ HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00100, Function | SmallT { int num = 1; NotificationPreferences::GetInstance().SetTotalBadgeNums(bundleOption_, num); - int totalBadgeNum; + int totalBadgeNum = 0; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetTotalBadgeNums(bundleOption_, totalBadgeNum), (int)ERR_OK); EXPECT_EQ(totalBadgeNum, num); } -- Gitee From 9f1921bdb2414169e0842356db6dcf5cd62e4771 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Sat, 18 Sep 2021 21:45:17 +0800 Subject: [PATCH 2/2] fix codex Signed-off-by: zhaoyuan17 --- .../kits/napi/wantagent/napi_want_agent.cpp | 31 +++++++++++-------- .../kits/napi/wantagent/napi_want_agent.h | 8 +++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/interfaces/kits/napi/wantagent/napi_want_agent.cpp b/interfaces/kits/napi/wantagent/napi_want_agent.cpp index f5b4759c8..9876c4921 100644 --- a/interfaces/kits/napi/wantagent/napi_want_agent.cpp +++ b/interfaces/kits/napi/wantagent/napi_want_agent.cpp @@ -46,6 +46,7 @@ void TriggerCompleteCallBack::SetWantAgentInstance(const std::shared_ptrdata; if (dataWorkerData == nullptr) { HILOG_INFO("TriggerReceiveDataWorker instance(uv_work_t) is nullptr"); @@ -799,8 +800,8 @@ napi_value NAPI_TriggerWrap(napi_env env, napi_callback_info info, AsyncTriggerC return ret; } -napi_value NAPI_GetTriggerInfo(napi_value argv[NUMBER_OF_PARAMETERS_THREE], size_t argc, napi_env env, - napi_callback_info info, Notification::WantAgent::TriggerInfo &triggerInfo) +napi_value NAPI_GetTriggerInfo(napi_value argv[NUMBER_OF_PARAMETERS_THREE], napi_env env, napi_callback_info info, + Notification::WantAgent::TriggerInfo &triggerInfo) { // Get triggerInfo napi_value jsTriggerInfo = argv[1]; @@ -877,7 +878,7 @@ napi_value NAPI_Trigger(napi_env env, napi_callback_info info) } Notification::WantAgent::TriggerInfo triggerInfo; - napi_value ret = NAPI_GetTriggerInfo(argv, argc, env, info, triggerInfo); + napi_value ret = NAPI_GetTriggerInfo(argv, env, info, triggerInfo); if (ret == nullptr) { return NapiGetNull(env); } @@ -1178,9 +1179,7 @@ napi_value NAPI_GetWantAgentWrap( } } -napi_value NAPI_GetWantAgentWants(napi_env env, napi_value jsWantAgentInfo, - std::vector> &wants, int32_t &operationType, int32_t &requestCode, - std::vector &wantAgentFlags, AAFwk::WantParams &extraInfo) +napi_value NAPI_GetWantAgentWants(napi_env env, napi_value jsWantAgentInfo, const WantAgentWantsParas ¶s) { napi_valuetype jsWantAgentInfoType = napi_valuetype::napi_null; NAPI_CALL(env, napi_typeof(env, jsWantAgentInfo, &jsWantAgentInfoType)); @@ -1201,15 +1200,15 @@ napi_value NAPI_GetWantAgentWants(napi_env env, napi_value jsWantAgentInfo, if (!UnwrapWant(env, jsWant, *want)) { return NapiGetNull(env); } - wants.emplace_back(want); + paras.wants.emplace_back(want); } // Get operationType - if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "operationType", operationType)) { + if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "operationType", paras.operationType)) { return NapiGetNull(env); } // Get requestCode - if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "requestCode", requestCode)) { + if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "requestCode", paras.requestCode)) { return NapiGetNull(env); } // Get wantAgentFlags @@ -1226,13 +1225,13 @@ napi_value NAPI_GetWantAgentWants(napi_env env, napi_value jsWantAgentInfo, NAPI_ASSERT(env, valuetype0 == napi_number, "Wrong argument type. Numbers expected."); int32_t value0 = 0; NAPI_CALL(env, napi_get_value_int32(env, napiWantAgentFlags, &value0)); - wantAgentFlags.emplace_back(static_cast(value0)); + paras.wantAgentFlags.emplace_back(static_cast(value0)); } } // Get extraInfo napi_value JsExtraInfo = GetPropertyValueByPropertyName(env, jsWantAgentInfo, "extraInfo", napi_object); if (JsExtraInfo != nullptr) { - if (!UnwrapWantParams(env, JsExtraInfo, extraInfo)) { + if (!UnwrapWantParams(env, JsExtraInfo, paras.extraInfo)) { return NapiGetNull(env); } } @@ -1253,8 +1252,14 @@ napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info) int32_t requestCode = -1; std::vector wantAgentFlags = {}; AAFwk::WantParams extraInfo = {}; - napi_value ret = - NAPI_GetWantAgentWants(env, jsWantAgentInfo, wants, operationType, requestCode, wantAgentFlags, extraInfo); + WantAgentWantsParas paras = { + .wants = wants, + .operationType = operationType, + .requestCode = requestCode, + .wantAgentFlags = wantAgentFlags, + .extraInfo = extraInfo, + }; + napi_value ret = NAPI_GetWantAgentWants(env, jsWantAgentInfo, paras); if (ret == nullptr) { return NapiGetNull(env); } diff --git a/interfaces/kits/napi/wantagent/napi_want_agent.h b/interfaces/kits/napi/wantagent/napi_want_agent.h index cd3989835..f8c3f8464 100644 --- a/interfaces/kits/napi/wantagent/napi_want_agent.h +++ b/interfaces/kits/napi/wantagent/napi_want_agent.h @@ -138,6 +138,14 @@ struct TriggerReceiveDataWorker { AAFwk::WantParams resultExtras; }; +struct WantAgentWantsParas { + std::vector> &wants; + int32_t &operationType; + int32_t &requestCode; + std::vector &wantAgentFlags; + AAFwk::WantParams &extraInfo; +}; + class TriggerCompleteCallBack : public CompletedCallback { public: TriggerCompleteCallBack(); -- Gitee