diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index fd203213c202c492ecdb789650e26e762fd990a8..da55aed922b6b05cde374cecffb495014c3ce17e 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 b0c004d71acf98861ccac1a48fb0dbd8c376a337..4c114748e9b228046097642cf7370bd35c27e103 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 acdfc939c52ab417da2cb34933ab6d92073e72e3..b5adae94ec9affbf19a620b61aafe74774d14544 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 744dc11f61a87dbcb02f6a481c664448e55bdf99..43f23d63c8a35e2e66e8127514e0c116ae88c98f 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 86ea093d9aa8230df5744fd492f6bd0099e5b391..87d459c55ee5651eacefdcb4f55d24fb702e5a41 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 f17afa07b8ac74e9d010ee6fca666b60ed651d24..c806df2ef08e8d4b0b8f9ce4d178a063e6a6fa55 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 f6d3e65b3290b46ccbb925cf94dce901b1832517..d66b8bc7afe9bfa8e7a3fd5a76941fcfcdf234b5 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 4d0df649db1c693bfd780287d79d1ef067b85d24..abd88be57d106dc3bfc618f0535c91dc021ed089 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 02c7e1e4cf0defffcc243703cbf49de3cadcd2c5..b346882bd29d7610a742ace62a989255f200dec2 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 6315d338d4bdff27b44464daa88b386415a13b79..0ff27d780b079bb00ea7cfa9404d36a7b35d8109 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 e14dd2f75e9062072b6b8a30926a80a6bc4f2641..0115c3ba4c5d7adc8128dc664ed24807d1fa498c 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 ba6edb7ff6f139ca9e853ab90a92fa5b018331d0..5d97a1a1a316651d0af4e03ee9a916c04fcb5a59 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 85404dd1ba96fcdb2650f370bc1efcc8cb55085b..ec2898f5b865c827a00cdc2731099254016a1dda 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 d5d86db34149ebe610de1c79b72029a9fab72c7c..926dbfc2d994fd94b0d7a287994321a1dfd31628 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 b0fe01159843af11f910fdc83143b09d2cab2497..a3a69fb230f51308438005d20f2525e41abb3288 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 9a338eaea51762a53cdf5e694c9a8e2ef1d86359..e515d617a8815d1caa940dcbd4ddf3c7ecbd807b 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 843b87753b2ee636efd0efd0d740ec5e40ff6a38..8cb3e395888b9720dc344278ecb2dce5fdcb7edb 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 f96de434bf797d8905fa7f7df4f74c0cd2a73b6f..c1431546697e83a004948cab225b29ec5abb6d33 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 6a3733897f50d4be034d5a580ca44a5e92ed83ce..ea5abb8cb46c1cc96be69c90dd52ddde594e7183 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 9e274ed77f1a6acea617825b68d42509850cd7dc..5b91d30e264ee6ad7793eb963362bf62a4d7f76c 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 acd2c31ec0f2e11fe7462a9f44bb4ca1f60a912f..06eb0b35099019017ec21cc517f66279f31be73a 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 f0a7ffb1552e4949309dbd3e842cb20516450741..b64685f5d696c5718b4f4a1d2cb8d1ab29ba07df 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 cfc7b3be27de4b8ed8fad3679f33421afcf8c9fd..c725db2ae3a58fb83a66b68f7e3870db281aa686 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 1bbfe05ea420b78fbfe6826a53a9693f427f34e6..485f6c1fa0495f9809af61cfdac29cde6494a20f 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 c4abb2f4573e6b477dec75aa262ce151067b6a4f..91a3dd8062ddbc1416321d7185543ce9832f0502 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 a879f32d8032da13254fc6d49dde313d5a1fb487..f3c236fe22628b691af798f95c9ea3bf295ef4e5 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 5a82654defffab83ad155a8ed2acff14ad635951..f9594c65ed63fcb13ac8283ed93f92e63d6abebd 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 4b273f93862e9799d4d321f9bb9a9f3c4e0aa59f..4be3ba5b49bffb0943175e61a489ee84780aacfd 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 32a8163cb800fe8f7a0d2b853b095882ef2b4383..54fb3f37a083a13d8310287230204f13db90946d 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 49dc6fc294dcd96ead39070705bccae9f1d97602..1eb370e590ea1e33718589e546d77e48caab852b 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 ebe13aac993630a354e40f1d81bedf72bbd554a6..6cbdecc3e3d64e0801dd1ca3f028fd451a4bca61 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 f84d26830231b3b4e61694326d1f04140a589c1d..1327bca968d9fd37054852492c00e3fe9c0c05c4 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 b86b1a3cb5699f47b659ed5940cb2feffe6ff6a9..7ab84bd4ee814dd9eb1cfcb9e67b3c4e4933d8c1 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 92a08e74b15d9c1caebd8576d3a117c880cd786b..17bcd58326fdd0cfbb049482de22e1e8df942926 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 1690462d791838a58b4ff63c9c0d03a17b004b98..fabae8a06626e8624dda17b9c8fe957cca20971a 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 5264e984fa929a82ca024c7ee836410d3b5f048c..7bc7871ffd069955e3264be9a8e70767b247e7d7 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 a2543c73c8737c78b19d8c58cd9780afcd07922f..e57a617a8ca39f8196e0abe0572a578159626af8 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 129355a8fccb3091b7b8b08f7e7ce26332a20898..ea42c40b0ceabdd8351341aee1defa767656dcd5 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 34040e313a80d2d5f6f898b63b143ffff6dd03ed..d2b88c530288ae23d1cb4f59247c58ccdfc90f13 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 ae680b46bde0c98d239659d9d4addf0450ebf38f..aa8c2cdcd2350b067d49f544a3f67203c64b414b 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 d763bd05899dcec401dafd17fe1ad18e4724619c..0d6ba8c4222b07703359bb523051a6e7e096650d 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 8dd5e880c3ce4188a59a97f4db6e765bd6d027d2..3c860cab93386e6461945300a1dadb939456d6a0 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 8cae75ede33dee9c3d921e827e6f6f80676db105..59b9a3dae34736a55b4e0f660549ae5170ede2d6 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 3b493f2c67bd29da0b3573cc61136132c0576f66..3764f5380b0a30d434eef2789dac27f79c1ff48f 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 f2bcb906e99d503b77ad48a0f115c0c51968c256..724acd30cf781db619f73859b346e4887151de7d 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 659c9e59dd459c776990fbf5e5b5dcddbc2489d9..7e2b9bc384a268e090fd9b8930accd1db5dc4766 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 0f347104567df4e611070f034de13430afd674d2..9876c492188dc7aad2d81e343345d1750cd3c12a 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,70 @@ 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 +145,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 +234,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 +319,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 +336,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 +354,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 +362,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 +447,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 +463,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 +481,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 +489,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 +572,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 +588,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 +606,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 +630,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 +717,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 +733,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 +751,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 +759,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], 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 +825,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 +837,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 +876,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, 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 +901,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 +909,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 +995,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 +1009,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 +1021,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 +1040,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,227 +1048,222 @@ 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, const WantAgentWantsParas ¶s) { - 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); + paras.wants.emplace_back(want); } + // Get operationType - int32_t operationType = -1; - if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "operationType", operationType)) { + if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "operationType", paras.operationType)) { return NapiGetNull(env); } // Get requestCode - int32_t requestCode = -1; - if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "requestCode", requestCode)) { + if (!UnwrapInt32ByPropertyName(env, jsWantAgentInfo, "requestCode", paras.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; 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 = 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)) { + if (!UnwrapWantParams(env, JsExtraInfo, paras.extraInfo)) { return NapiGetNull(env); } } + return NapiGetNull(env); +} + +napi_value NAPI_GetWantAgent(napi_env env, napi_callback_info info) +{ + size_t argc = NUMBER_OF_PARAMETERS_TWO; + napi_value argv[NUMBER_OF_PARAMETERS_TWO] = {}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); + HILOG_INFO("argc = [%{public}zu]", argc); + napi_value jsWantAgentInfo = argv[0]; + + // Get wants + std::vector> wants = {}; + int32_t operationType = -1; + int32_t requestCode = -1; + std::vector wantAgentFlags = {}; + AAFwk::WantParams extraInfo = {}; + WantAgentWantsParas paras = { + .wants = wants, + .operationType = operationType, + .requestCode = requestCode, + .wantAgentFlags = wantAgentFlags, + .extraInfo = extraInfo, + }; + napi_value ret = NAPI_GetWantAgentWants(env, jsWantAgentInfo, paras); + if (ret == nullptr) { + return NapiGetNull(env); + } + // Get context napi_value global = 0; NAPI_CALL(env, napi_get_global(env, &global)); @@ -1208,8 +1271,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 +1281,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 +1300,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 +1321,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 e5bf33c25f0fca3a67a4c56a935a904371d2d320..f8c3f84646f19c6a887f1b814610db9aa61de72a 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; @@ -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(); @@ -151,11 +159,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 +183,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 11981d2a2d2dae611c5c3ecfdb5a9d8fcaf8cc20..0177c32c6cfb67d60cce620ccc660bd8da784a02 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 f46776fb702e180c2027b57a8c5a7c28fcd20a27..f8fb3183094504668cc0c098cba8a3b57cf9c68b 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 510034cfa2efa726b2df99dfa80dc76ba088f6e5..f2121538389d08dec54c8bb30f75ccbf7caf4f39 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); }