From 77194ff4733b3602255480b2e5d38b85126716ac Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Wed, 1 Dec 2021 10:25:56 +0000 Subject: [PATCH] Text codex Signed-off-by: zhaoyuan17 --- .../core/common/include/ans_const_define.h | 1 + .../core/common/include/ans_inner_errors.h | 1 + .../ans/core/include/ans_manager_interface.h | 10 +- .../ans/core/include/ans_manager_proxy.h | 2 + .../ans/core/include/ans_manager_stub.h | 4 + .../ans/core/include/ans_notification.h | 17 + frameworks/ans/core/src/ans_manager_proxy.cpp | 67 + frameworks/ans/core/src/ans_manager_stub.cpp | 57 + frameworks/ans/core/src/ans_notification.cpp | 27 + frameworks/ans/native/src/notification.cpp | 40 + .../ans/native/src/notification_helper.cpp | 10 + .../ans/native/src/notification_request.cpp | 2 +- .../test/moduletest/ans_fw_module_test.cpp | 179 ++ .../ans/native/include/notification.h | 16 + .../native/include/notification_constant.h | 15 + .../ans/native/include/notification_helper.h | 17 + .../ans/native/include/notification_request.h | 2 +- interfaces/kits/napi/ans/include/common.h | 185 +- interfaces/kits/napi/ans/src/common.cpp | 2810 ++++++++++------- interfaces/kits/napi/ans/src/constant.cpp | 21 +- interfaces/kits/napi/ans/src/subscribe.cpp | 12 +- .../include/advanced_notification_service.h | 5 +- .../ans/src/advanced_notification_service.cpp | 106 +- .../advanced_notification_service_test.cpp | 68 + services/ans/test/unittest/ans_ut_constant.h | 1 + 25 files changed, 2520 insertions(+), 1155 deletions(-) diff --git a/frameworks/ans/core/common/include/ans_const_define.h b/frameworks/ans/core/common/include/ans_const_define.h index 60a2cc4f8..8e1cb00b4 100644 --- a/frameworks/ans/core/common/include/ans_const_define.h +++ b/frameworks/ans/core/common/include/ans_const_define.h @@ -32,6 +32,7 @@ constexpr uint32_t MAX_SLOT_GROUP_NUM = 4; constexpr uint32_t MAX_ICON_SIZE = 50 * 1024; constexpr uint32_t MAX_PICTURE_SIZE = 2 * 1024 * 1024; constexpr bool SUPPORT_DO_NOT_DISTRUB = true; +constexpr uint32_t SYSTEM_SERVICE_UID = 1000; // Default sound for notification const static Uri DEFAULT_NOTIFICATION_SOUND("file://system/etc/Light.ogg"); diff --git a/frameworks/ans/core/common/include/ans_inner_errors.h b/frameworks/ans/core/common/include/ans_inner_errors.h index a671871f3..8e59ee723 100644 --- a/frameworks/ans/core/common/include/ans_inner_errors.h +++ b/frameworks/ans/core/common/include/ans_inner_errors.h @@ -46,6 +46,7 @@ enum ErrorCode : uint32_t { ERR_ANS_SERVICE_NOT_CONNECTED, ERR_ANS_INVALID_PARAM, ERR_ANS_INVALID_UID, + ERR_ANS_NOT_SYSTEM_SERVICE, ERR_ANS_INVALID_PID, ERR_ANS_INVALID_BUNDLE, ERR_ANS_NOT_ALLOWED, diff --git a/frameworks/ans/core/include/ans_manager_interface.h b/frameworks/ans/core/include/ans_manager_interface.h index 70caf0f64..ab5de9115 100644 --- a/frameworks/ans/core/include/ans_manager_interface.h +++ b/frameworks/ans/core/include/ans_manager_interface.h @@ -22,8 +22,8 @@ #include "ans_subscriber_interface.h" #include "iremote_broker.h" #include "notification_bundle_option.h" -#include "notification_do_not_disturb_date.h" #include "notification_constant.h" +#include "notification_do_not_disturb_date.h" #include "notification_request.h" #include "notification_slot.h" #include "notification_slot_group.h" @@ -103,14 +103,16 @@ public: virtual ErrCode IsAllowedNotify(bool &allowed) = 0; virtual ErrCode IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) = 0; - virtual ErrCode SetDoNotDisturbDate(const sptr & date) = 0; - virtual ErrCode GetDoNotDisturbDate(sptr & date) = 0; + virtual ErrCode SetDoNotDisturbDate(const sptr &date) = 0; + virtual ErrCode GetDoNotDisturbDate(sptr &date) = 0; virtual ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) = 0; virtual ErrCode CancelGroup(const std::string &groupName) = 0; virtual ErrCode RemoveGroupByBundle( const sptr &bundleOption, const std::string &groupName) = 0; virtual ErrCode ShellDump(const std::string &dumpOption, std::vector &dumpInfo) = 0; + virtual ErrCode PublishLongTaskNotification(const sptr &request) = 0; + virtual ErrCode CancelLongTaskNotification(const std::string &label, int32_t notificationId) = 0; protected: enum TransactId : uint32_t { @@ -168,6 +170,8 @@ protected: CANCEL_GROUP, REMOVE_GROUP_BY_BUNDLE, SHELL_DUMP, + PUBLISH_LONG_TASK_NOTIFICATION, + CANCEL_LONG_TASK_NOTIFICATION, }; }; } // namespace Notification diff --git a/frameworks/ans/core/include/ans_manager_proxy.h b/frameworks/ans/core/include/ans_manager_proxy.h index b780d0d0b..af36f3989 100644 --- a/frameworks/ans/core/include/ans_manager_proxy.h +++ b/frameworks/ans/core/include/ans_manager_proxy.h @@ -99,6 +99,8 @@ public: const sptr &bundleOption, const std::string &groupName) override; ErrCode ShellDump(const std::string &dumpOption, std::vector &dumpInfo) override; + ErrCode PublishLongTaskNotification(const sptr &request) override; + ErrCode CancelLongTaskNotification(const std::string &label, int32_t notificationId) override; private: ErrCode InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/ans/core/include/ans_manager_stub.h b/frameworks/ans/core/include/ans_manager_stub.h index 04338d636..70ef9746b 100644 --- a/frameworks/ans/core/include/ans_manager_stub.h +++ b/frameworks/ans/core/include/ans_manager_stub.h @@ -104,6 +104,8 @@ public: const sptr &bundleOption, const std::string &groupName) override; virtual ErrCode ShellDump(const std::string &dumpOption, std::vector &dumpInfo) override; + virtual ErrCode PublishLongTaskNotification(const sptr &request) override; + virtual ErrCode CancelLongTaskNotification(const std::string &label, int32_t notificationId) override; private: static const std::map> @@ -163,6 +165,8 @@ private: ErrCode HandleSetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply); ErrCode HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply); + ErrCode HandlePublishLongTaskNotification(MessageParcel &data, MessageParcel &reply); + ErrCode HandleCancelLongTaskNotification(MessageParcel &data, MessageParcel &reply); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result); diff --git a/frameworks/ans/core/include/ans_notification.h b/frameworks/ans/core/include/ans_notification.h index 4c2661323..7aa642624 100644 --- a/frameworks/ans/core/include/ans_notification.h +++ b/frameworks/ans/core/include/ans_notification.h @@ -618,6 +618,23 @@ public: */ ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport); + /** + * Publishes a long task notification. + * @param request Indicates the NotificationRequest object for setting the notification content. + * This parameter must be specified. + * @return Returns publish long task notification result. + */ + ErrCode PublishLongTaskNotification(const NotificationRequest &request); + + /** + * Cancels a published long task notification matching the specified label and notificationId. + * + * @param label Indicates the label of the long task notification to cancel. + * @param notificationId Indicates the ID of the long task notification to cancel. + * @return Returns cancel long task notification result. + */ + ErrCode CancelLongTaskNotification(const std::string &label, int32_t notificationId); + /** * Reset ans manager proxy when OnRemoteDied called. */ diff --git a/frameworks/ans/core/src/ans_manager_proxy.cpp b/frameworks/ans/core/src/ans_manager_proxy.cpp index 69c1809ad..5a402bc88 100644 --- a/frameworks/ans/core/src/ans_manager_proxy.cpp +++ b/frameworks/ans/core/src/ans_manager_proxy.cpp @@ -1876,6 +1876,73 @@ ErrCode AnsManagerProxy::ShellDump(const std::string &dumpOption, std::vector &request) +{ + if (request == nullptr) { + ANS_LOGW("[PublishLongTaskNotification] fail: notification request is null ptr."); + return ERR_ANS_INVALID_PARAM; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGW("[PublishLongTaskNotification] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteParcelable(request)) { + ANS_LOGW("[PublishLongTaskNotification] fail: write request failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(PUBLISH_LONG_TASK_NOTIFICATION, option, data, reply); + if (result != ERR_OK) { + ANS_LOGW("[PublishLongTaskNotification] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGW("[PublishLongTaskNotification] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + +ErrCode AnsManagerProxy::CancelLongTaskNotification(const std::string &label, int32_t notificationId) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGW("[CancelLongTaskNotification] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteString(label)) { + ANS_LOGW("[CancelLongTaskNotification] fail: write label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(notificationId)) { + ANS_LOGW("[CancelLongTaskNotification] fail: write notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(CANCEL_LONG_TASK_NOTIFICATION, option, data, reply); + if (result != ERR_OK) { + ANS_LOGW("[CancelLongTaskNotification] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGW("[CancelLongTaskNotification] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + ErrCode AnsManagerProxy::InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply) { auto remote = Remote(); diff --git a/frameworks/ans/core/src/ans_manager_stub.cpp b/frameworks/ans/core/src/ans_manager_stub.cpp index 2e8da5eac..9db9b1bbe 100644 --- a/frameworks/ans/core/src/ans_manager_stub.cpp +++ b/frameworks/ans/core/src/ans_manager_stub.cpp @@ -188,6 +188,12 @@ const std::map request = data.ReadParcelable(); + if (!request) { + ANS_LOGW("[HandlePublishLongTaskNotification] fail: notification ReadParcelable failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = PublishLongTaskNotification(request); + + if (!reply.WriteInt32(result)) { + ANS_LOGW("[HandlePublishLongTaskNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelLongTaskNotification(MessageParcel &data, MessageParcel &reply) +{ + std::string label; + if (!data.ReadString(label)) { + ANS_LOGW("[HandleCancelLongTaskNotification] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGW("[HandleCancelLongTaskNotification] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelLongTaskNotification(label, notificationId); + + if (!reply.WriteInt32(result)) { + ANS_LOGW("[HandleCancelLongTaskNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + ErrCode AnsManagerStub::HandleIsNotificationPolicyAccessGranted(MessageParcel &data, MessageParcel &reply) { bool granted = false; @@ -1616,5 +1662,16 @@ ErrCode AnsManagerStub::ShellDump(const std::string &dumpOption, std::vector &request) +{ + ANS_LOGW("AnsManagerStub::PublishLongTaskNotification called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelLongTaskNotification(const std::string &label, int32_t notificationId) +{ + ANS_LOGW("AnsManagerStub::CancelLongTaskNotification called!"); + return ERR_INVALID_OPERATION; +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index fb2a0e253..59d3adb3a 100644 --- a/frameworks/ans/core/src/ans_notification.cpp +++ b/frameworks/ans/core/src/ans_notification.cpp @@ -819,6 +819,33 @@ ErrCode AnsNotification::DoesSupportDoNotDisturbMode(bool &doesSupport) return ansManagerProxy_->DoesSupportDoNotDisturbMode(doesSupport); } +ErrCode AnsNotification::PublishLongTaskNotification(const NotificationRequest &request) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + auto pReq = new (std::nothrow) NotificationRequest(request); + if (pReq == nullptr) { + ANS_LOGE("create NotificationRequest failed."); + return ERR_ANS_NO_MEMORY; + } + + sptr sptrReq(pReq); + return ansManagerProxy_->PublishLongTaskNotification(sptrReq); +} + +ErrCode AnsNotification::CancelLongTaskNotification(const std::string &label, int32_t notificationId) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return ansManagerProxy_->CancelLongTaskNotification(label, notificationId); +} + void AnsNotification::ResetAnsManagerProxy() { ANS_LOGI("enter"); diff --git a/frameworks/ans/native/src/notification.cpp b/frameworks/ans/native/src/notification.cpp index 9e829789e..36a2b9466 100644 --- a/frameworks/ans/native/src/notification.cpp +++ b/frameworks/ans/native/src/notification.cpp @@ -41,6 +41,8 @@ Notification::Notification(const Notification &other) postTime_ = other.postTime_; sound_ = other.sound_; vibrationStyle_ = other.vibrationStyle_; + isRemoveAllowed_ = other.isRemoveAllowed_; + sourceType_ = other.sourceType_; } Notification::~Notification() @@ -171,6 +173,16 @@ bool Notification::IsFloatingIcon() const return request_->IsFloatingIcon(); } +bool Notification::IsRemoveAllowed() const +{ + return isRemoveAllowed_; +} + +NotificationConstant::SourceType Notification::GetSourceType() const +{ + return sourceType_; +} + bool Notification::Marshalling(Parcel &parcel) const { if (!parcel.WriteBool(enableLight_)) { @@ -188,6 +200,11 @@ bool Notification::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteBool(isRemoveAllowed_)) { + ANS_LOGE("Can't write isRemoveAllowed"); + return false; + } + if (!parcel.WriteString(key_)) { ANS_LOGE("Can't wirte key"); return false; @@ -202,6 +219,11 @@ bool Notification::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteInt32(static_cast(sourceType_))) { + ANS_LOGE("Can't write sourceType"); + return false; + } + if (!parcel.WriteStrongParcelable(request_)) { ANS_LOGE("Can't write request"); return false; @@ -238,6 +260,9 @@ bool Notification::ReadFromParcel(Parcel &parcel) // Read enableViration_ enableViration_ = parcel.ReadBool(); + // Read isRemoveAllowed_ + isRemoveAllowed_ = parcel.ReadBool(); + // Read key_ key_ = parcel.ReadString(); @@ -247,6 +272,9 @@ bool Notification::ReadFromParcel(Parcel &parcel) // Read lockscreenVisibleness_ lockscreenVisibleness_ = static_cast(parcel.ReadInt32()); + // Read sourceType_ + sourceType_ = static_cast(parcel.ReadInt32()); + // Read request_ request_ = parcel.ReadStrongParcelable(); @@ -325,10 +353,22 @@ std::string Notification::GenerateNotificationKey(int32_t uid, const std::string return stream.str(); } +void Notification::SetRemoveAllowed(bool removeAllowed) +{ + isRemoveAllowed_ = removeAllowed; +} + +void Notification::SetSourceType(NotificationConstant::SourceType sourceType) +{ + sourceType_ = sourceType; +} + std::string Notification::Dump() const { std::string dump = "Notification{ key = " + key_ + ", ledLightColor = " + std::to_string(ledLightColor_) + ", lockscreenVisbleness = " + std::to_string(static_cast(lockscreenVisibleness_)) + + ", isRemoveAllowed = " + (isRemoveAllowed_ ? "true" : "false") + + ", sourceType = " + std::to_string(static_cast(sourceType_)) + ",request = "; if (request_ == nullptr) { dump += "nullptr"; diff --git a/frameworks/ans/native/src/notification_helper.cpp b/frameworks/ans/native/src/notification_helper.cpp index 020fe4a0b..e314165d7 100644 --- a/frameworks/ans/native/src/notification_helper.cpp +++ b/frameworks/ans/native/src/notification_helper.cpp @@ -321,5 +321,15 @@ ErrCode NotificationHelper::DoesSupportDoNotDisturbMode(bool &doesSupport) { return DelayedSingleton::GetInstance()->DoesSupportDoNotDisturbMode(doesSupport); } + +ErrCode NotificationHelper::PublishLongTaskNotification(const NotificationRequest &request) +{ + return DelayedSingleton::GetInstance()->PublishLongTaskNotification(request); +} + +ErrCode NotificationHelper::CancelLongTaskNotification(const std::string &label, int32_t notificationId) +{ + return DelayedSingleton::GetInstance()->CancelLongTaskNotification(label, notificationId); +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index 801fb1eb0..1ea18d3c0 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -387,7 +387,7 @@ uint32_t NotificationRequest::GetColor() const return color_; } -bool NotificationRequest::IsColorEnabled() +bool NotificationRequest::IsColorEnabled() const { if (!colorEnabled_) { 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 9b2b77064..12885a5a5 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -28,6 +28,7 @@ #include "ans_manager_proxy.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" +#include "mock_ipc_skeleton.h" #include "notification_content.h" #include "notification_helper.h" #include "notification_long_text_content.h" @@ -1547,5 +1548,183 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_DoNotDisturb_07000, Function | Medium EXPECT_EQ(srcDate.GetDoNotDisturbType(), disDate.GetDoNotDisturbType()); } + +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishLongTask_07100, Function | MediumTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + NotificationRequest req(0); + req.SetLabel(NOTIFICATION_LABEL_0); + EXPECT_EQ(NotificationHelper::PublishLongTaskNotification(req), ERR_OK); + SleepForFC(); + EventParser eventParser; + std::list> events = subscriber.GetEvents(); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + eventParser.SetWaitOnConsumed(false); + + std::vector> notifications; + EXPECT_EQ(NotificationHelper::GetAllActiveNotifications(notifications), ERR_OK); + EXPECT_NE((int)notifications.size(), (int)0); + int32_t id = notifications[0]->GetId(); + IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + EXPECT_EQ(NotificationHelper::CancelLongTaskNotification(NOTIFICATION_LABEL_0, id), ERR_OK); + EXPECT_EQ(NotificationHelper::GetAllActiveNotifications(notifications), ERR_OK); + EXPECT_EQ((int)notifications.size(), (int)0); + SleepForFC(); + + EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber), ERR_OK); + events = subscriber.GetEvents(); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + EXPECT_TRUE(eventParser.GetWaitOnCanceledWithSortingMapAndDeleteReason()); + subscriber.ClearEvents(); + SleepForFC(); + IPCSkeleton::SetCallingUid(1); +} + +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishLongTask_07200, Function | MediumTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + NotificationRequest req(0); + req.SetLabel(NOTIFICATION_LABEL_0); + EXPECT_EQ(NotificationHelper::PublishLongTaskNotification(req), ERR_OK); + SleepForFC(); + EventParser eventParser; + std::list> events = subscriber.GetEvents(); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + eventParser.SetWaitOnConsumed(false); + + std::vector> notifications; + EXPECT_EQ(NotificationHelper::GetAllActiveNotifications(notifications), ERR_OK); + EXPECT_NE((int)notifications.size(), (int)0); + std::string key = notifications[0]->GetKey().c_str(); + EXPECT_EQ(NotificationHelper::RemoveNotification(key), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); + int32_t id = notifications[0]->GetId(); + IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + EXPECT_EQ(NotificationHelper::CancelLongTaskNotification(NOTIFICATION_LABEL_0, id), ERR_OK); + EXPECT_EQ(NotificationHelper::GetAllActiveNotifications(notifications), ERR_OK); + EXPECT_EQ((int)notifications.size(), (int)0); + SleepForFC(); + + EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber), ERR_OK); + events = subscriber.GetEvents(); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + EXPECT_TRUE(eventParser.GetWaitOnCanceledWithSortingMapAndDeleteReason()); + subscriber.ClearEvents(); + SleepForFC(); + IPCSkeleton::SetCallingUid(1); +} + +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishLongTask_07300, Function | MediumTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + NotificationRequest req(0); + req.SetLabel(NOTIFICATION_LABEL_0); + EXPECT_EQ(NotificationHelper::PublishLongTaskNotification(req), ERR_OK); + SleepForFC(); + EventParser eventParser; + std::list> events = subscriber.GetEvents(); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + eventParser.SetWaitOnConsumed(false); + + std::vector> notifications; + EXPECT_EQ(NotificationHelper::GetAllActiveNotifications(notifications), ERR_OK); + EXPECT_NE((int)notifications.size(), (int)0); + int32_t id = notifications[0]->GetId(); + EXPECT_EQ(NotificationHelper::CancelNotification(id), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); + IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + EXPECT_EQ(NotificationHelper::CancelLongTaskNotification(NOTIFICATION_LABEL_0, id), ERR_OK); + EXPECT_EQ(NotificationHelper::GetAllActiveNotifications(notifications), ERR_OK); + EXPECT_EQ((int)notifications.size(), (int)0); + SleepForFC(); + + EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber), ERR_OK); + events = subscriber.GetEvents(); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + EXPECT_TRUE(eventParser.GetWaitOnCanceledWithSortingMapAndDeleteReason()); + subscriber.ClearEvents(); + SleepForFC(); + IPCSkeleton::SetCallingUid(1); +} + +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishLongTask_07400, Function | MediumTest | Level1) +{ + NotificationRequest req(0); + req.SetLabel(NOTIFICATION_LABEL_0); + EXPECT_EQ(NotificationHelper::PublishLongTaskNotification(req), (int)ERR_ANS_NOT_SYSTEM_SERVICE); +} + +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishLongTask_07500, Function | MediumTest | Level1) +{ + TestAnsSubscriber subscriber; + NotificationSubscribeInfo info; + info.AddAppName("bundleName"); + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber, info), ERR_OK); + + std::shared_ptr implContent = std::make_shared(); + std::shared_ptr content = std::make_shared(implContent); + NotificationRequest req0(0); + req0.SetLabel(NOTIFICATION_LABEL_0); + req0.SetContent(content); + EXPECT_EQ(NotificationHelper::PublishNotification(req0), ERR_OK); + + NotificationRequest req1(1); + req1.SetLabel(NOTIFICATION_LABEL_1); + req1.SetContent(content); + EXPECT_EQ(NotificationHelper::PublishNotification(req1), ERR_OK); + EXPECT_EQ( + NotificationHelper::CancelLongTaskNotification(NOTIFICATION_LABEL_1, 1), (int)ERR_ANS_NOT_SYSTEM_SERVICE); + EXPECT_EQ(NotificationHelper::CancelAllNotifications(), ERR_OK); + SleepForFC(); + EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber, info), ERR_OK); + SleepForFC(); + std::list> events = subscriber.GetEvents(); + + EventParser eventParser; + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + EXPECT_TRUE(eventParser.GetWaitOnConsumedWithSortingMap()); + EXPECT_TRUE(eventParser.GetWaitOnCanceled()); + EXPECT_TRUE(eventParser.GetWaitOnCanceledWithSortingMapAndDeleteReason()); + subscriber.ClearEvents(); + SleepForFC(); +} + +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishLongTask_07600, Function | MediumTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + + NotificationRequest req(0); + req.SetLabel(NOTIFICATION_LABEL_0); + EXPECT_EQ(NotificationHelper::PublishLongTaskNotification(req), ERR_OK); + + SleepForFC(); + EventParser eventParser; + std::list> events = subscriber.GetEvents(); + eventParser.Parse(events); + EXPECT_TRUE(eventParser.GetWaitOnConsumed()); + + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 0); + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->IsRemoveAllowed(), false); + EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetSourceType(), NotificationConstant::SourceType::TYPE_LONGTASK); + + EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber), ERR_OK); + SleepForFC(); + subscriber.ClearEvents(); + IPCSkeleton::SetCallingUid(1); +} } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification.h b/interfaces/innerkits/ans/native/include/notification.h index e515d617a..5b063f9a8 100644 --- a/interfaces/innerkits/ans/native/include/notification.h +++ b/interfaces/innerkits/ans/native/include/notification.h @@ -181,6 +181,18 @@ public: */ bool IsFloatingIcon() const; + /** + * Whether to support remove allowed. + * @return Current remove allowed status. + */ + bool IsRemoveAllowed() const; + + /** + * Gets the notification source. + * @return the notification slot type. + */ + NotificationConstant::SourceType GetSourceType() const; + /** * @brief Dumps a string representation of the object. * @@ -216,6 +228,8 @@ private: void SetPostTime(const int64_t &time); void SetSound(const Uri &sound); void SetVibrationStyle(const std::vector &style); + void SetRemoveAllowed(bool removeAllowed); + void SetSourceType(NotificationConstant::SourceType sourceType); bool ReadFromParcel(Parcel &parcel); std::string GenerateNotificationKey(int32_t uid, const std::string &label, int32_t id); @@ -223,9 +237,11 @@ private: bool enableSound_ {false}; bool enableLight_ {false}; bool enableViration_ {false}; + bool isRemoveAllowed_ {true}; std::string key_ {""}; int32_t ledLightColor_ {0}; NotificationConstant::VisiblenessType lockscreenVisibleness_ {NotificationConstant::VisiblenessType::NO_OVERRIDE}; + NotificationConstant::SourceType sourceType_ {NotificationConstant::SourceType::TYPE_NORMAL}; sptr request_ {nullptr}; int64_t postTime_ {0}; std::shared_ptr sound_ {nullptr}; diff --git a/interfaces/innerkits/ans/native/include/notification_constant.h b/interfaces/innerkits/ans/native/include/notification_constant.h index dcf4fe973..8cafaf56b 100644 --- a/interfaces/innerkits/ans/native/include/notification_constant.h +++ b/interfaces/innerkits/ans/native/include/notification_constant.h @@ -91,6 +91,21 @@ public: CLEARLY = 3, // time period }; + enum class SourceType { + /** + * general notification. + */ + TYPE_NORMAL = 0x00000000, + /** + * long-term task notification. + */ + TYPE_LONGTASK = 0x00000001, + /** + * timed notification. + */ + TYPE_TIMER = 0x00000002 + }; + /** * Indicates that a notification is deleted because it is clicked. */ diff --git a/interfaces/innerkits/ans/native/include/notification_helper.h b/interfaces/innerkits/ans/native/include/notification_helper.h index 73bd56b50..6299f78c3 100644 --- a/interfaces/innerkits/ans/native/include/notification_helper.h +++ b/interfaces/innerkits/ans/native/include/notification_helper.h @@ -612,6 +612,23 @@ public: * @return Returns check result. */ static ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport); + + /** + * Publishes a long task notification. + * @param request Indicates the NotificationRequest object for setting the notification content. + * This parameter must be specified. + * @return Returns publish long task notification result. + */ + static ErrCode PublishLongTaskNotification(const NotificationRequest &request); + + /** + * Cancels a published long task notification matching the specified label and notificationId. + * + * @param label Indicates the label of the long task notification to cancel. + * @param notificationId Indicates the ID of the long task notification to cancel. + * @return Returns cancel long task notification result. + */ + static ErrCode CancelLongTaskNotification(const std::string &label, int32_t notificationId); }; } // 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 d5f6c81df..ad1b0789f 100644 --- a/interfaces/innerkits/ans/native/include/notification_request.h +++ b/interfaces/innerkits/ans/native/include/notification_request.h @@ -454,7 +454,7 @@ public: * Checks whether background color is enabled for this notification. * @return true if background color is enabled; returns false otherwise. */ - bool IsColorEnabled(); + bool IsColorEnabled() const; /** * Sets whether to enable background color for this notification. diff --git a/interfaces/kits/napi/ans/include/common.h b/interfaces/kits/napi/ans/include/common.h index c95b1a1fd..a0d88a235 100644 --- a/interfaces/kits/napi/ans/include/common.h +++ b/interfaces/kits/napi/ans/include/common.h @@ -34,8 +34,7 @@ enum ContentType { NOTIFICATION_CONTENT_LONG_TEXT, NOTIFICATION_CONTENT_PICTURE, NOTIFICATION_CONTENT_CONVERSATION, - NOTIFICATION_CONTENT_MULTILINE, - NOTIFICATION_CONTENT_MEDIA + NOTIFICATION_CONTENT_MULTILINE }; enum SlotType { @@ -89,6 +88,12 @@ enum InputEditType { EDIT_AUTO, EDIT_DISABLED, EDIT_ENABLED }; enum DoNotDisturbType { TYPE_NONE, TYPE_ONCE, TYPE_DAILY, TYPE_CLEARLY }; +enum SourceType { + TYPE_NORMAL = 0x00000000, + TYPE_LONGTASK = 0x00000001, + TYPE_TIMER = 0x00000002 +}; + struct NotificationSubscribeInfo { std::vector bundleNames; int userId = 0; @@ -118,7 +123,7 @@ class Common { ~Common(); public: - static napi_value NapiGetboolean(napi_env env, const bool &isValue); + static napi_value NapiGetBoolean(napi_env env, const bool &isValue); static napi_value NapiGetNull(napi_env env); @@ -145,10 +150,22 @@ public: static napi_value ParseParaOnlyCallback(const napi_env &env, const napi_callback_info &info, napi_ref &callback); static napi_value SetNotification( - const napi_env &env, OHOS::Notification::Notification *notification, napi_value &result); + const napi_env &env, const OHOS::Notification::Notification *notification, napi_value &result); static napi_value SetNotificationRequest( - const napi_env &env, OHOS::Notification::NotificationRequest *request, napi_value &result); + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result); + static napi_value SetNotificationRequestByString( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result); + static napi_value SetNotificationRequestByNumber( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result); + static napi_value SetNotificationRequestByBool( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result); + static napi_value SetNotificationRequestByWantAgent( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result); + static napi_value SetNotificationRequestByPixelMap( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result); + static napi_value SetNotificationRequestByCustom( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result); static napi_value SetNotificationSortingMap( const napi_env &env, const std::shared_ptr &sortingMap, napi_value &result); @@ -160,29 +177,33 @@ public: static napi_value SetNotificationContent( const napi_env &env, const std::shared_ptr &content, napi_value &result); - + static napi_value SetNotificationContentDetailed(const napi_env &env, const enum ContentType &type, + const std::shared_ptr &content, napi_value &result); static napi_value SetNotificationBasicContent( - const napi_env &env, NotificationBasicContent *basicContent, napi_value &result); - + const napi_env &env, const NotificationBasicContent *basicContent, napi_value &result); static napi_value SetNotificationLongTextContent( - const napi_env &env, OHOS::Notification::NotificationLongTextContent *longTextContent, napi_value &result); - + const napi_env &env, NotificationBasicContent *basicContent, napi_value &result); static napi_value SetNotificationPictureContent( - const napi_env &env, OHOS::Notification::NotificationPictureContent *pictureContent, napi_value &result); - + const napi_env &env, NotificationBasicContent *basicContent, napi_value &result); static napi_value SetNotificationConversationalContent(const napi_env &env, - OHOS::Notification::NotificationConversationalContent *conversationalContent, napi_value &result); - + NotificationBasicContent *basicContent, napi_value &result); static napi_value SetNotificationMultiLineContent( - const napi_env &env, OHOS::Notification::NotificationMultiLineContent *multiLineContent, napi_value &result); + const napi_env &env, NotificationBasicContent *basicContent, napi_value &result); static napi_value SetMessageUser(const napi_env &env, const MessageUser &messageUser, napi_value &result); + static napi_value SetConversationalMessages(const napi_env &env, + const OHOS::Notification::NotificationConversationalContent *conversationalContent, napi_value &arr); + static napi_value SetConversationalMessage(const napi_env &env, const std::shared_ptr &conversationalMessage, napi_value &result); static napi_value SetNotificationActionButton( const napi_env &env, const std::shared_ptr &actionButton, napi_value &result); + static napi_value SetNotificationActionButtonByExtras( + const napi_env &env, const std::shared_ptr &actionButton, napi_value &result); + static napi_value SetNotificationActionButtonByUserInput( + const napi_env &env, const std::shared_ptr &userInput, napi_value &result); static napi_value SetDoNotDisturbDate( const napi_env &env, const NotificationDoNotDisturbDate &date, napi_value &result); @@ -192,6 +213,54 @@ public: static napi_value GetNotificationRequest( const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationRequestByNumber( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationRequestByString( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationRequestByBool( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationRequestByCustom( + const napi_env &env, const napi_value &value, NotificationRequest &request); + + static napi_value GetNotificationId(const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationSlotType( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationIsOngoing( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationIsUnremovable( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationDeliveryTime( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationtapDismissed( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationExtraInfo( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationGroupName( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationRemovalWantAgent( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationMaxScreenWantAgent( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationAutoDeletedTime( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationClassification( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationColor(const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationColorEnabled( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationIsAlertOnce( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationIsStopwatch( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationIsCountDown( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationStatusBarText( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationLabel(const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationBadgeIconStyle( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationShowDeliveryTime( + const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationContent( const napi_env &env, const napi_value &value, NotificationRequest &request); @@ -200,6 +269,90 @@ public: const napi_env &env, const napi_value &value, NotificationRequest &request); static napi_value GetNotificationSlot(const napi_env &env, const napi_value &value, NotificationSlot &slot); + static napi_value GetNotificationSlotByString(const napi_env &env, const napi_value &value, NotificationSlot &slot); + static napi_value GetNotificationSlotByBool(const napi_env &env, const napi_value &value, NotificationSlot &slot); + static napi_value GetNotificationSlotByNumber(const napi_env &env, const napi_value &value, NotificationSlot &slot); + static napi_value GetNotificationSlotByCustom(const napi_env &env, const napi_value &value, NotificationSlot &slot); + + static napi_value GetNotificationActionButtons( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationActionButtonsDetailed( + const napi_env &env, const napi_value &actionButton, std::shared_ptr &pActionButton); + static napi_value GetNotificationActionButtonsDetailedBasicInfo( + const napi_env &env, const napi_value &actionButton, std::shared_ptr &pActionButton); + static napi_value GetNotificationActionButtonsDetailedByExtras( + const napi_env &env, const napi_value &actionButton, std::shared_ptr &pActionButton); + static napi_value GetNotificationUserInput( + const napi_env &env, const napi_value &actionButton, std::shared_ptr &pActionButton); + static napi_value GetNotificationUserInputByInputKey( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput); + static napi_value GetNotificationUserInputByTag( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput); + static napi_value GetNotificationUserInputByOptions( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput); + static napi_value GetNotificationUserInputByPermitMimeTypes( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput); + static napi_value GetNotificationUserInputByPermitFreeFormInput( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput); + static napi_value GetNotificationUserInputByEditType( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput); + static napi_value GetNotificationUserInputByAdditionalData( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput); + + static napi_value GetNotificationSmallIcon( + const napi_env &env, const napi_value &value, NotificationRequest &request); + static napi_value GetNotificationLargeIcon( + const napi_env &env, const napi_value &value, NotificationRequest &request); + + static napi_value GetNotificationContentType(const napi_env &env, const napi_value &result, int32_t &type); + static napi_value GetNotificationBasicContent( + const napi_env &env, const napi_value &result, NotificationRequest &request); + static napi_value GetNotificationBasicContentDetailed( + const napi_env &env, const napi_value &contentResult, std::shared_ptr basicContent); + + static napi_value GetNotificationLongTextContent( + const napi_env &env, const napi_value &result, NotificationRequest &request); + static napi_value GetNotificationLongTextContentDetailed( + const napi_env &env, const napi_value &contentResult, + std::shared_ptr &longContent); + + static napi_value GetNotificationPictureContent( + const napi_env &env, const napi_value &result, NotificationRequest &request); + static napi_value GetNotificationPictureContentDetailed( + const napi_env &env, const napi_value &contentResult, + std::shared_ptr &pictureContent); + + static napi_value GetNotificationConversationalContent( + const napi_env &env, const napi_value &result, NotificationRequest &request); + static napi_value GetNotificationConversationalContentByUser( + const napi_env &env, const napi_value &contentResult, MessageUser &user); + static napi_value GetNotificationConversationalContentTitle( + const napi_env &env, const napi_value &contentResult, + std::shared_ptr &conversationalContent); + static napi_value GetNotificationConversationalContentGroup( + const napi_env &env, const napi_value &contentResult, + std::shared_ptr &conversationalContent); + static napi_value GetNotificationConversationalContentMessages( + const napi_env &env, const napi_value &contentResult, + std::shared_ptr &conversationalContent); + static napi_value GetConversationalMessage( + const napi_env &env, const napi_value &conversationalMessage, + std::shared_ptr &message); + static napi_value GetConversationalMessageBasicInfo( + const napi_env &env, const napi_value &conversationalMessage, + std::shared_ptr &message); + static napi_value GetConversationalMessageOtherInfo( + const napi_env &env, const napi_value &conversationalMessage, + std::shared_ptr &message); + static napi_value GetMessageUser(const napi_env &env, const napi_value &result, MessageUser &messageUser); + static napi_value GetMessageUserByString(const napi_env &env, const napi_value &result, MessageUser &messageUser); + static napi_value GetMessageUserByBool(const napi_env &env, const napi_value &result, MessageUser &messageUser); + static napi_value GetMessageUserByCustom(const napi_env &env, const napi_value &result, MessageUser &messageUser); + + static napi_value GetNotificationMultiLineContent( + const napi_env &env, const napi_value &result, NotificationRequest &request); + static napi_value GetNotificationMultiLineContentLines(const napi_env &env, const napi_value &result, + std::shared_ptr &multiLineContent); static napi_value GetBundleOption(const napi_env &env, const napi_value &value, BundleOption &option); @@ -223,6 +376,8 @@ public: static bool DoNotDisturbTypeCToJS(const NotificationConstant::DoNotDisturbType &inType, DoNotDisturbType &outType); + static bool SourceTypeCToJS(const NotificationConstant::SourceType &inType, SourceType &outType); + static napi_value CreateWantAgentByJS(const napi_env &env, const std::shared_ptr &agent); private: diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 0db4a1946..e53d25129 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -26,66 +26,14 @@ namespace OHOS { namespace NotificationNapi { std::set> Common::wantAgent_; -static napi_value GetIdByPublish(const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetSlotType(const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationIsOngoing(const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationIsUnremovable( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationDeliveryTime( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationtapDismissed( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationRemovalWantAgent( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationMaxScreenWantAgent( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationAutoDeletedTime( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationClassification( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationColor(const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationColorEnabled( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationIsAlertOnce( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationIsStopwatch( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationIsCountDown( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationStatusBarText( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationLabel(const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationBadgeIconStyle( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationShowDeliveryTime( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationNotificationActionButtons( - const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationSmallIcon(const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationLargeIcon(const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationContentType(const napi_env &env, const napi_value &result, int32_t &type); -static napi_value GetNotificationBasicContent( - const napi_env &env, const napi_value &result, NotificationRequest &request); -static napi_value GetNotificationLongTextContent( - const napi_env &env, const napi_value &result, NotificationRequest &request); -static napi_value GetNotificationPictureContent( - const napi_env &env, const napi_value &result, NotificationRequest &request); -static napi_value GetNotificationConversationalContent( - const napi_env &env, const napi_value &result, NotificationRequest &request); -static napi_value GetNotificationMultiLineContent( - const napi_env &env, const napi_value &result, NotificationRequest &request); -static napi_value GetNotificationMultiLineContentLines(const napi_env &env, const napi_value &result, - std::shared_ptr &multiLineContent); -static napi_value GetNotificationExtraInfo(const napi_env &env, const napi_value &value, NotificationRequest &request); -static napi_value GetNotificationGroupName( - const napi_env &env, const napi_value &value, NotificationRequest &request); + Common::Common() {} Common::~Common() {} -napi_value Common::NapiGetboolean(napi_env env, const bool &isValue) +napi_value Common::NapiGetBoolean(napi_env env, const bool &isValue) { napi_value result = nullptr; napi_get_boolean(env, isValue, &result); @@ -134,14 +82,13 @@ void Common::PaddingCallbackPromiseInfo( void Common::ReturnCallbackPromise(const napi_env &env, const CallbackPromiseInfo &info, const napi_value &result) { - ANS_LOGI("enter"); - + ANS_LOGI("enter errorCode=%{public}d", info.errorCode); if (info.isCallback) { SetCallback(env, info.callback, info.errorCode, result); } else { SetPromise(env, info.deferred, info.errorCode, result); } - ANS_LOGI("ReturnCallbackPromise end"); + ANS_LOGI("end"); } void Common::SetCallback( @@ -222,18 +169,18 @@ napi_value Common::ParseParaOnlyCallback(const napi_env &env, const napi_callbac } napi_value Common::SetNotification( - const napi_env &env, OHOS::Notification::Notification *notification, napi_value &result) + const napi_env &env, const OHOS::Notification::Notification *notification, napi_value &result) { ANS_LOGI("enter"); if (notification == nullptr) { ANS_LOGE("notification is nullptr"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } napi_value value = nullptr; NotificationRequest request = notification->GetNotificationRequest(); if (!SetNotificationRequest(env, &request, result)) { - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } // hashCode?: string @@ -256,34 +203,66 @@ napi_value Common::SetNotification( napi_create_int32(env, notification->GetPid(), &value); napi_set_named_property(env, result, "creatorPid", value); - return NapiGetboolean(env, true); + // readonly isRemoveAllowed?: boolean; + napi_get_boolean(env, notification->IsRemoveAllowed(), &value); + napi_set_named_property(env, result, "isRemoveAllowed", value); + + // readonly source?: number; + enum SourceType sourceType = SourceType::TYPE_NORMAL; + if (!SourceTypeCToJS(notification->GetSourceType(), sourceType)) { + return NapiGetBoolean(env, false); + } + napi_create_int32(env, sourceType, &value); + napi_set_named_property(env, result, "source", value); + + return NapiGetBoolean(env, true); } -napi_value Common::SetNotificationRequest( - const napi_env &env, OHOS::Notification::NotificationRequest *request, napi_value &result) +napi_value Common::SetNotificationRequestByString( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result) { - ANS_LOGI("SetNotificationRequest start"); + ANS_LOGI("enter"); napi_value value = nullptr; if (request == nullptr) { ANS_LOGE("request is nullptr"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } - // content: NotificationContent - std::shared_ptr content = request->GetContent(); - if (content) { - napi_value contentResult = nullptr; - napi_create_object(env, &contentResult); - if (!SetNotificationContent(env, content, contentResult)) { - ANS_LOGE("SetNotificationContent call failed"); - return NapiGetboolean(env, false); - } - napi_set_named_property(env, result, "content", contentResult); - } else { - ANS_LOGE("content is nullptr"); - return NapiGetboolean(env, false); + // classification?: string + napi_create_string_utf8(env, request->GetClassification().c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, "classification", value); + + // statusBarText?: string + napi_create_string_utf8(env, request->GetStatusBarText().c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, "statusBarText", value); + + // label?: string + napi_create_string_utf8(env, request->GetLabel().c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, "label", value); + + // groupName?: string + napi_create_string_utf8(env, request->GetGroupName().c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, "groupName", value); + + // readonly creatorBundleName?: string + napi_create_string_utf8(env, request->GetCreatorBundleName().c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, "creatorBundleName", value); + + return NapiGetBoolean(env, true); +} + +napi_value Common::SetNotificationRequestByNumber( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result) +{ + ANS_LOGI("enter"); + + napi_value value = nullptr; + + if (request == nullptr) { + ANS_LOGE("request is nullptr"); + return NapiGetBoolean(env, false); } // id?: number @@ -293,11 +272,50 @@ napi_value Common::SetNotificationRequest( // slotType?: SlotType enum SlotType outType = SlotType::UNKNOWN_TYPE; if (!SlotTypeCToJS(request->GetSlotType(), outType)) { - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } napi_create_int32(env, outType, &value); napi_set_named_property(env, result, "slotType", value); + // deliveryTime?: number + napi_create_int64(env, request->GetDeliveryTime(), &value); + napi_set_named_property(env, result, "deliveryTime", value); + + // autoDeletedTime?: number + napi_create_int64(env, request->GetAutoDeletedTime(), &value); + napi_set_named_property(env, result, "autoDeletedTime", value); + + // color ?: number + napi_create_uint32(env, request->GetColor(), &value); + napi_set_named_property(env, result, "color", value); + + // badgeIconStyle ?: number + int badgeIconStyle = (int)request->GetBadgeIconStyle(); + napi_create_int32(env, badgeIconStyle, &value); + napi_set_named_property(env, result, "badgeIconStyle", value); + + // readonly creatorUid?: number + napi_create_int32(env, request->GetCreatorUid(), &value); + napi_set_named_property(env, result, "creatorUid", value); + + // readonly creatorPid?: number + napi_create_int32(env, request->GetCreatorPid(), &value); + napi_set_named_property(env, result, "creatorPid", value); + + return NapiGetBoolean(env, true); +} + +napi_value Common::SetNotificationRequestByBool( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result) +{ + ANS_LOGI("enter"); + + napi_value value = nullptr; + + if (request == nullptr) { + ANS_LOGE("request is nullptr"); + return NapiGetBoolean(env, false); + } // isOngoing?: boolean napi_get_boolean(env, request->IsInProgress(), &value); napi_set_named_property(env, result, "isOngoing", value); @@ -306,18 +324,45 @@ napi_value Common::SetNotificationRequest( napi_get_boolean(env, request->IsUnremovable(), &value); napi_set_named_property(env, result, "isUnremovable", value); - // deliveryTime?: number - napi_create_int64(env, request->GetDeliveryTime(), &value); - napi_set_named_property(env, result, "deliveryTime", value); - // tapDismissed?: boolean napi_get_boolean(env, request->IsTapDismissed(), &value); napi_set_named_property(env, result, "tapDismissed", value); - // autoDeletedTime?: number - napi_create_int64(env, request->GetAutoDeletedTime(), &value); - napi_set_named_property(env, result, "autoDeletedTime", value); + // colorEnabled?: boolean + napi_get_boolean(env, request->IsColorEnabled(), &value); + napi_set_named_property(env, result, "colorEnabled", value); + + // isAlertOnce?: boolean + napi_get_boolean(env, request->IsAlertOneTime(), &value); + napi_set_named_property(env, result, "isAlertOnce", value); + + // isStopwatch?: boolean + napi_get_boolean(env, request->IsShowStopwatch(), &value); + napi_set_named_property(env, result, "isStopwatch", value); + + // isCountDown?: boolean + napi_get_boolean(env, request->IsCountdownTimer(), &value); + napi_set_named_property(env, result, "isCountDown", value); + + // isFloatingIcon?: boolean + napi_get_boolean(env, request->IsFloatingIcon(), &value); + napi_set_named_property(env, result, "isFloatingIcon", value); + + // showDeliveryTime?: boolean + napi_get_boolean(env, request->IsShowDeliveryTime(), &value); + napi_set_named_property(env, result, "showDeliveryTime", value); + + return NapiGetBoolean(env, true); +} +napi_value Common::SetNotificationRequestByWantAgent( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result) +{ + ANS_LOGI("enter"); + if (request == nullptr) { + ANS_LOGE("request is nullptr"); + return NapiGetBoolean(env, false); + } // wantAgent?: WantAgent std::shared_ptr agent = request->GetWantAgent(); if (agent) { @@ -328,15 +373,7 @@ napi_value Common::SetNotificationRequest( napi_set_named_property(env, result, "wantAgent", NapiGetNull(env)); } - // extraInfo ?: {[key:string] : any} - std::shared_ptr additionalData = request->GetAdditionalData(); - if (additionalData) { - napi_value extraInfo = nullptr; - extraInfo = OHOS::AppExecFwk::WrapWantParams(env, *additionalData); - napi_set_named_property(env, result, "extraInfo", extraInfo); - } - - // removalWantAgent ?: WantAgent + // removalWantAgent?: WantAgent std::shared_ptr removalAgent = request->GetRemovalWantAgent(); if (removalAgent) { napi_value wantAgent = nullptr; @@ -346,7 +383,7 @@ napi_value Common::SetNotificationRequest( napi_set_named_property(env, result, "removalWantAgent", NapiGetNull(env)); } - // maxScreenWantAgent ? WantAgent + // maxScreenWantAgent?: WantAgent std::shared_ptr maxScreenAgent = request->GetMaxScreenWantAgent(); if (maxScreenAgent) { napi_value wantAgent = nullptr; @@ -356,68 +393,20 @@ napi_value Common::SetNotificationRequest( napi_set_named_property(env, result, "maxScreenWantAgent", NapiGetNull(env)); } - // classification ?: string - napi_create_string_utf8(env, request->GetClassification().c_str(), NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, result, "classification", value); - - // color ?: number - napi_create_uint32(env, request->GetColor(), &value); - napi_set_named_property(env, result, "color", value); - - // colorEnabled ?: boolean - napi_get_boolean(env, request->IsColorEnabled(), &value); - napi_set_named_property(env, result, "colorEnabled", value); - - // isAlertOnce ?: boolean - napi_get_boolean(env, request->IsAlertOneTime(), &value); - napi_set_named_property(env, result, "isAlertOnce", value); - - // isStopwatch ?: boolean - napi_get_boolean(env, request->IsShowStopwatch(), &value); - napi_set_named_property(env, result, "isStopwatch", value); - - // isCountDown ?: boolean - napi_get_boolean(env, request->IsCountdownTimer(), &value); - napi_set_named_property(env, result, "isCountDown", value); - - // statusBarText ?: string - napi_create_string_utf8(env, request->GetStatusBarText().c_str(), NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, result, "statusBarText", value); - - // isFloatingIcon ?: boolean - napi_get_boolean(env, request->IsFloatingIcon(), &value); - napi_set_named_property(env, result, "isFloatingIcon", value); - - // label ?: string - napi_create_string_utf8(env, request->GetLabel().c_str(), NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, result, "label", value); - - // badgeIconStyle ?: number - int badgeIconStyle = (int)request->GetBadgeIconStyle(); - napi_create_int32(env, badgeIconStyle, &value); - napi_set_named_property(env, result, "badgeIconStyle", value); + return NapiGetBoolean(env, true); +} - // showDeliveryTime ?: boolean - napi_get_boolean(env, request->IsShowDeliveryTime(), &value); - napi_set_named_property(env, result, "showDeliveryTime", value); +napi_value Common::SetNotificationRequestByPixelMap( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result) +{ + ANS_LOGI("enter"); - // actionButtons?: Array - napi_value arr = nullptr; - int count = 0; - napi_create_array(env, &arr); - for (auto vec : request->GetActionButtons()) { - if (vec) { - napi_value actionButtonResult = nullptr; - napi_create_object(env, &actionButtonResult); - if (SetNotificationActionButton(env, vec, actionButtonResult)) { - napi_set_element(env, arr, count, actionButtonResult); - count++; - } - } + if (request == nullptr) { + ANS_LOGE("request is nullptr"); + return NapiGetBoolean(env, false); } - napi_set_named_property(env, result, "actionButtons", arr); - // smallIcon ?: image.PixelMap + // smallIcon?: image.PixelMap std::shared_ptr littleIcon = request->GetLittleIcon(); if (littleIcon) { napi_value smallIconResult = nullptr; @@ -432,7 +421,7 @@ napi_value Common::SetNotificationRequest( } } - // largeIcon ?: image.PixelMap + // largeIcon?: image.PixelMap std::shared_ptr largeIcon = request->GetBigIcon(); if (largeIcon) { napi_value largeIconResult = nullptr; @@ -447,36 +436,104 @@ napi_value Common::SetNotificationRequest( } } - // groupName?: string - napi_create_string_utf8(env, request->GetGroupName().c_str(), NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, result, "groupName", value); + return NapiGetBoolean(env, true); +} - // readonly creatorBundleName?: string - napi_create_string_utf8(env, request->GetCreatorBundleName().c_str(), NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, result, "creatorBundleName", value); +napi_value Common::SetNotificationRequestByCustom( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result) +{ + ANS_LOGI("enter"); - // readonly creatorUid?: number - napi_create_int32(env, request->GetCreatorUid(), &value); - napi_set_named_property(env, result, "creatorUid", value); + if (request == nullptr) { + ANS_LOGE("request is nullptr"); + return NapiGetBoolean(env, false); + } - // readonly creatorPid?: number - napi_create_int32(env, request->GetCreatorPid(), &value); - napi_set_named_property(env, result, "creatorPid", value); + // content: NotificationContent + std::shared_ptr content = request->GetContent(); + if (content) { + napi_value contentResult = nullptr; + napi_create_object(env, &contentResult); + if (!SetNotificationContent(env, content, contentResult)) { + ANS_LOGE("SetNotificationContent call failed"); + return NapiGetBoolean(env, false); + } + napi_set_named_property(env, result, "content", contentResult); + } else { + ANS_LOGE("content is nullptr"); + return NapiGetBoolean(env, false); + } + + // extraInfo?: {[key:string] : any} + std::shared_ptr additionalData = request->GetAdditionalData(); + if (additionalData) { + napi_value extraInfo = nullptr; + extraInfo = OHOS::AppExecFwk::WrapWantParams(env, *additionalData); + napi_set_named_property(env, result, "extraInfo", extraInfo); + } + + // actionButtons?: Array + napi_value arr = nullptr; + int count = 0; + napi_create_array(env, &arr); + for (auto vec : request->GetActionButtons()) { + if (vec) { + napi_value actionButtonResult = nullptr; + napi_create_object(env, &actionButtonResult); + if (SetNotificationActionButton(env, vec, actionButtonResult)) { + napi_set_element(env, arr, count, actionButtonResult); + count++; + } + } + } + napi_set_named_property(env, result, "actionButtons", arr); + + return NapiGetBoolean(env, true); +} + +napi_value Common::SetNotificationRequest( + const napi_env &env, const OHOS::Notification::NotificationRequest *request, napi_value &result) +{ + ANS_LOGI("enter"); + + if (request == nullptr) { + ANS_LOGE("request is nullptr"); + return NapiGetBoolean(env, false); + } + + if (!SetNotificationRequestByString(env, request, result)) { + return NapiGetBoolean(env, false); + } + if (!SetNotificationRequestByNumber(env, request, result)) { + return NapiGetBoolean(env, false); + } + if (!SetNotificationRequestByBool(env, request, result)) { + return NapiGetBoolean(env, false); + } + if (!SetNotificationRequestByWantAgent(env, request, result)) { + return NapiGetBoolean(env, false); + } + if (!SetNotificationRequestByPixelMap(env, request, result)) { + return NapiGetBoolean(env, false); + } + if (!SetNotificationRequestByCustom(env, request, result)) { + return NapiGetBoolean(env, false); + } - return NapiGetboolean(env, true); + return NapiGetBoolean(env, true); } napi_value Common::SetNotificationSortingMap( const napi_env &env, const std::shared_ptr &sortingMap, napi_value &result) { - ANS_LOGI("SetNotificationSortingMap start"); + ANS_LOGI("enter"); if (sortingMap == nullptr) { ANS_LOGE("sortingMap is null"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } if (sortingMap->GetKey().size() == 0) { ANS_LOGE("sortingMap GetKey().size is empty"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } size_t count = 0; @@ -498,7 +555,7 @@ napi_value Common::SetNotificationSortingMap( napi_create_object(env, &sortingResult); if (!SetNotificationSorting(env, sorting, sortingResult)) { ANS_LOGE("SetNotificationSorting call failed"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } napi_set_named_property(env, sortingsResult, key.c_str(), sortingResult); count++; @@ -509,12 +566,12 @@ napi_value Common::SetNotificationSortingMap( napi_set_named_property(env, result, "sortedHashCode", arrSortedHashCode); napi_set_named_property(env, result, "sortings", sortingsResult); - return NapiGetboolean(env, true); + return NapiGetBoolean(env, true); } napi_value Common::SetNotificationSorting(const napi_env &env, const NotificationSorting &sorting, napi_value &result) { - ANS_LOGI("SetNotificationSorting start"); + ANS_LOGI("enter"); // slot: NotificationSlot napi_value slotResult = nullptr; @@ -522,7 +579,7 @@ napi_value Common::SetNotificationSorting(const napi_env &env, const Notificatio napi_create_object(env, &slotResult); if (!SetNotificationSlot(env, sorting.GetSlot(), slotResult)) { ANS_LOGE("SetNotificationSlot call failed"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } napi_set_named_property(env, result, "slot", slotResult); @@ -554,7 +611,7 @@ napi_value Common::SetNotificationSorting(const napi_env &env, const Notificatio napi_create_int32(env, sorting.GetVisiblenessOverride(), &value); napi_set_named_property(env, result, "visiblenessOverride", value); - return NapiGetboolean(env, true); + return NapiGetBoolean(env, true); } napi_value Common::SetNotificationSlot(const napi_env &env, const NotificationSlot &slot, napi_value &result) @@ -565,7 +622,7 @@ napi_value Common::SetNotificationSlot(const napi_env &env, const NotificationSl // type: SlotType enum SlotType outType = SlotType::UNKNOWN_TYPE; if (!SlotTypeCToJS(slot.GetType(), outType)) { - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } napi_create_int32(env, outType, &value); napi_set_named_property(env, result, "type", value); @@ -573,7 +630,7 @@ napi_value Common::SetNotificationSlot(const napi_env &env, const NotificationSl // level?: number enum SlotLevel outLevel { SlotLevel::LEVEL_NONE }; if (!SlotLevelCToJS(slot.GetLevel(), outLevel)) { - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } napi_create_int32(env, outLevel, &value); napi_set_named_property(env, result, "level", value); @@ -622,107 +679,99 @@ napi_value Common::SetNotificationSlot(const napi_env &env, const NotificationSl } napi_set_named_property(env, result, "vibrationValues", arr); - return NapiGetboolean(env, true); + return NapiGetBoolean(env, true); } -napi_value Common::SetNotificationContent( - const napi_env &env, const std::shared_ptr &content, napi_value &result) +napi_value Common::SetNotificationContentDetailed(const napi_env &env, const enum ContentType &type, + const std::shared_ptr &content, napi_value &result) { - ANS_LOGI("SetNotificationContent start"); - if (content == nullptr) { + ANS_LOGI("enter"); + napi_value ret = NapiGetBoolean(env, false); + if (!content) { ANS_LOGE("content is null"); - return NapiGetboolean(env, false); - } - - napi_value value = nullptr; - // contentType: ContentType - NotificationContent::Type type = content->GetContentType(); - ContentType outType = ContentType::NOTIFICATION_CONTENT_BASIC_TEXT; - if (!ContentTypeCToJS(type, outType)) { - return NapiGetboolean(env, false); + return ret; } - napi_create_int32(env, (int32_t)outType, &value); - napi_set_named_property(env, result, "contentType", value); - std::shared_ptr basicContent = content->GetNotificationContent(); if (basicContent == nullptr) { - ANS_LOGI("content is null"); - return NapiGetboolean(env, false); + ANS_LOGE("content is null"); + return ret; } - if (outType == ContentType::NOTIFICATION_CONTENT_BASIC_TEXT) { + + napi_value contentResult = nullptr; + napi_create_object(env, &contentResult); + if (type == ContentType::NOTIFICATION_CONTENT_BASIC_TEXT) { // normal?: NotificationBasicContent - napi_value basicContentResult = nullptr; - napi_create_object(env, &basicContentResult); - if (SetNotificationBasicContent(env, basicContent.get(), basicContentResult)) { - napi_set_named_property(env, result, "normal", basicContentResult); - } else { - return NapiGetboolean(env, false); + ret = SetNotificationBasicContent(env, basicContent.get(), contentResult); + if (ret) { + napi_set_named_property(env, result, "normal", contentResult); } - - } else if (outType == ContentType::NOTIFICATION_CONTENT_LONG_TEXT) { + } else if (type == ContentType::NOTIFICATION_CONTENT_LONG_TEXT) { // longText?: NotificationLongTextContent - OHOS::Notification::NotificationLongTextContent *longTextContent = - static_cast(basicContent.get()); - napi_value longTextContentResult = nullptr; - napi_create_object(env, &longTextContentResult); - if (SetNotificationLongTextContent(env, longTextContent, longTextContentResult)) { - napi_set_named_property(env, result, "longText", longTextContentResult); - } else { - return NapiGetboolean(env, false); + ret = SetNotificationLongTextContent(env, basicContent.get(), contentResult); + if (ret) { + napi_set_named_property(env, result, "longText", contentResult); } - - } else if (outType == ContentType::NOTIFICATION_CONTENT_PICTURE) { + } else if (type == ContentType::NOTIFICATION_CONTENT_PICTURE) { // picture?: NotificationPictureContent - OHOS::Notification::NotificationPictureContent *pictureContent = - static_cast(basicContent.get()); - napi_value pictureContentResult = nullptr; - napi_create_object(env, &pictureContentResult); - if (SetNotificationPictureContent(env, pictureContent, pictureContentResult)) { - napi_set_named_property(env, result, "picture", pictureContentResult); - } else { - return NapiGetboolean(env, false); + ret = SetNotificationPictureContent(env, basicContent.get(), contentResult); + if (ret) { + napi_set_named_property(env, result, "picture", contentResult); } - } else if (outType == ContentType::NOTIFICATION_CONTENT_CONVERSATION) { - // conversational?: NotificationConversationalContent - OHOS::Notification::NotificationConversationalContent *conversationalContent = - static_cast(basicContent.get()); - napi_value conversationalContentResult = nullptr; - napi_create_object(env, &conversationalContentResult); - if (SetNotificationConversationalContent(env, conversationalContent, conversationalContentResult)) { - napi_set_named_property(env, result, "conversational", conversationalContentResult); - } else { - return NapiGetboolean(env, false); + } else if (type == ContentType::NOTIFICATION_CONTENT_CONVERSATION) { + // conversation?: NotificationConversationalContent + ret = SetNotificationConversationalContent(env, basicContent.get(), contentResult); + if (ret) { + napi_set_named_property(env, result, "conversation", contentResult); } - } else if (outType == ContentType::NOTIFICATION_CONTENT_MULTILINE) { + } else if (type == ContentType::NOTIFICATION_CONTENT_MULTILINE) { // multiLine?: NotificationMultiLineContent - OHOS::Notification::NotificationMultiLineContent *multiLineContent = - static_cast(basicContent.get()); - napi_value multiLineContentResult = nullptr; - napi_create_object(env, &multiLineContentResult); - if (SetNotificationMultiLineContent(env, multiLineContent, multiLineContentResult)) { - napi_set_named_property(env, result, "multiLine", multiLineContentResult); - } else { - return NapiGetboolean(env, false); + ret = SetNotificationMultiLineContent(env, basicContent.get(), contentResult); + if (ret) { + napi_set_named_property(env, result, "multiLine", contentResult); } } else { ANS_LOGE("ContentType is does not exist"); - return NapiGetboolean(env, false); } - return NapiGetboolean(env, true); + return ret; +} + +napi_value Common::SetNotificationContent( + const napi_env &env, const std::shared_ptr &content, napi_value &result) +{ + ANS_LOGI("enter"); + napi_value value = nullptr; + if (content == nullptr) { + ANS_LOGE("content is null"); + return NapiGetBoolean(env, false); + } + + // contentType: ContentType + NotificationContent::Type type = content->GetContentType(); + ContentType outType = ContentType::NOTIFICATION_CONTENT_BASIC_TEXT; + if (!ContentTypeCToJS(type, outType)) { + return NapiGetBoolean(env, false); + } + napi_create_int32(env, (int32_t)outType, &value); + napi_set_named_property(env, result, "contentType", value); + + if (!SetNotificationContentDetailed(env, outType, content, result)) { + return NapiGetBoolean(env, false); + } + + return NapiGetBoolean(env, true); } napi_value Common::SetNotificationBasicContent( - const napi_env &env, NotificationBasicContent *basicContent, napi_value &result) + const napi_env &env, const NotificationBasicContent *basicContent, napi_value &result) { - ANS_LOGI("SetNotificationBasicContent start"); + ANS_LOGI("enter"); + napi_value value = nullptr; if (basicContent == nullptr) { ANS_LOGE("basicContent is null"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } - napi_value value = nullptr; - // title: string napi_create_string_utf8(env, basicContent->GetTitle().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "title", value); @@ -735,25 +784,31 @@ napi_value Common::SetNotificationBasicContent( napi_create_string_utf8(env, basicContent->GetAdditionalText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "additionalText", value); - return NapiGetboolean(env, true); + return NapiGetBoolean(env, true); } napi_value Common::SetNotificationLongTextContent( - const napi_env &env, OHOS::Notification::NotificationLongTextContent *longTextContent, napi_value &result) + const napi_env &env, NotificationBasicContent *basicContent, napi_value &result) { - ANS_LOGI("SetNotificationLongTextContent start"); + ANS_LOGI("enter"); + napi_value value = nullptr; + if (basicContent == nullptr) { + ANS_LOGE("basicContent is null"); + return NapiGetBoolean(env, false); + } + + OHOS::Notification::NotificationLongTextContent *longTextContent = + static_cast(basicContent); if (longTextContent == nullptr) { ANS_LOGE("longTextContent is null"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } if (!SetNotificationBasicContent(env, longTextContent, result)) { ANS_LOGE("SetNotificationBasicContent call failed"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } - napi_value value = nullptr; - // longText: string napi_create_string_utf8(env, longTextContent->GetLongText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "longText", value); @@ -766,25 +821,30 @@ napi_value Common::SetNotificationLongTextContent( napi_create_string_utf8(env, longTextContent->GetExpandedTitle().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "expandedTitle", value); - return NapiGetboolean(env, true); + return NapiGetBoolean(env, true); } napi_value Common::SetNotificationPictureContent( - const napi_env &env, OHOS::Notification::NotificationPictureContent *pictureContent, napi_value &result) + const napi_env &env, NotificationBasicContent *basicContent, napi_value &result) { - ANS_LOGI("SetNotificationPictureContent start"); + ANS_LOGI("enter"); + napi_value value = nullptr; + if (basicContent == nullptr) { + ANS_LOGE("basicContent is null"); + return NapiGetBoolean(env, false); + } + OHOS::Notification::NotificationPictureContent *pictureContent = + static_cast(basicContent); if (pictureContent == nullptr) { ANS_LOGE("pictureContent is null"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } if (!SetNotificationBasicContent(env, pictureContent, result)) { ANS_LOGE("SetNotificationBasicContent call failed"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } - napi_value value = nullptr; - // briefText: string napi_create_string_utf8(env, pictureContent->GetBriefText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "briefText", value); @@ -801,30 +861,36 @@ napi_value Common::SetNotificationPictureContent( pictureResult = Media::PixelMapNapi::CreatePixelMap(env, picture); NAPI_CALL(env, napi_typeof(env, pictureResult, &valuetype)); if (valuetype == napi_undefined) { - ANS_LOGI("pictureResult is undefined"); + ANS_LOGW("pictureResult is undefined"); napi_set_named_property(env, result, "picture", NapiGetNull(env)); } else { napi_set_named_property(env, result, "picture", pictureResult); } } - return NapiGetboolean(env, true); + return NapiGetBoolean(env, true); } napi_value Common::SetNotificationConversationalContent(const napi_env &env, - OHOS::Notification::NotificationConversationalContent *conversationalContent, napi_value &result) + NotificationBasicContent *basicContent, napi_value &result) { - ANS_LOGI("SetNotificationConversationalContent start"); + ANS_LOGI("enter"); + napi_value value = nullptr; + if (basicContent == nullptr) { + ANS_LOGE("basicContent is null"); + return NapiGetBoolean(env, false); + } + OHOS::Notification::NotificationConversationalContent *conversationalContent = + static_cast(basicContent); if (conversationalContent == nullptr) { ANS_LOGE("conversationalContent is null"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } if (!SetNotificationBasicContent(env, conversationalContent, result)) { ANS_LOGE("SetNotificationBasicContent call failed"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } - napi_value value = nullptr; // conversationTitle: string napi_create_string_utf8(env, conversationalContent->GetConversationTitle().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "conversationTitle", value); @@ -835,20 +901,9 @@ napi_value Common::SetNotificationConversationalContent(const napi_env &env, // messages: Array napi_value arr = nullptr; - int count = 0; - napi_create_array(env, &arr); - std::vector> messages = - conversationalContent->GetAllConversationalMessages(); - for (auto vec : messages) { - if (!vec) { - continue; - } - napi_value conversationalMessageResult = nullptr; - napi_create_object(env, &conversationalMessageResult); - if (SetConversationalMessage(env, vec, conversationalMessageResult)) { - napi_set_element(env, arr, count, conversationalMessageResult); - count++; - } + if (!SetConversationalMessages(env, conversationalContent, arr)) { + ANS_LOGE("SetConversationalMessages call failed"); + return NapiGetBoolean(env, false); } napi_set_named_property(env, result, "messages", arr); @@ -856,28 +911,35 @@ napi_value Common::SetNotificationConversationalContent(const napi_env &env, napi_value messageUserResult = nullptr; napi_create_object(env, &messageUserResult); if (!SetMessageUser(env, conversationalContent->GetMessageUser(), messageUserResult)) { - messageUserResult = NapiGetNull(env); + ANS_LOGE("SetMessageUser call failed"); + return NapiGetBoolean(env, false); } napi_set_named_property(env, result, "user", messageUserResult); - return NapiGetboolean(env, true); + return NapiGetBoolean(env, true); } napi_value Common::SetNotificationMultiLineContent( - const napi_env &env, OHOS::Notification::NotificationMultiLineContent *multiLineContent, napi_value &result) + const napi_env &env, NotificationBasicContent *basicContent, napi_value &result) { - ANS_LOGI("SetNotificationMultiLineContent start"); + ANS_LOGI("enter"); + napi_value value = nullptr; + if (basicContent == nullptr) { + ANS_LOGE("basicContent is null"); + return NapiGetBoolean(env, false); + } + OHOS::Notification::NotificationMultiLineContent *multiLineContent = + static_cast(basicContent); if (multiLineContent == nullptr) { ANS_LOGE("multiLineContent is null"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } if (!SetNotificationBasicContent(env, multiLineContent, result)) { ANS_LOGE("SetNotificationBasicContent call failed"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } - napi_value value = nullptr; // briefText: string napi_create_string_utf8(env, multiLineContent->GetBriefText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "briefText", value); @@ -897,47 +959,90 @@ napi_value Common::SetNotificationMultiLineContent( } napi_set_named_property(env, result, "lines", arr); - return NapiGetboolean(env, true); + return NapiGetBoolean(env, true); } napi_value Common::SetMessageUser(const napi_env &env, const MessageUser &messageUser, napi_value &result) { - ANS_LOGI("SetMessageUser start"); + ANS_LOGI("enter"); napi_value value = nullptr; // name: string napi_create_string_utf8(env, messageUser.GetName().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "name", value); + // key: string + napi_create_string_utf8(env, messageUser.GetKey().c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, "key", value); + // uri: string napi_create_string_utf8(env, messageUser.GetUri().ToString().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "uri", value); - // important: boolean + // isMachine: boolean + napi_get_boolean(env, messageUser.IsMachine(), &value); + napi_set_named_property(env, result, "isMachine", value); + + // isUserImportant: boolean napi_get_boolean(env, messageUser.IsUserImportant(), &value); - napi_set_named_property(env, result, "important", value); + napi_set_named_property(env, result, "isUserImportant", value); - // machine: boolean - napi_get_boolean(env, messageUser.IsMachine(), &value); - napi_set_named_property(env, result, "machine", value); + // icon?: image.PixelMap + std::shared_ptr icon = messageUser.GetPixelMap(); + if (icon) { + napi_value iconResult = nullptr; + napi_valuetype valuetype = napi_undefined; + iconResult = Media::PixelMapNapi::CreatePixelMap(env, icon); + NAPI_CALL(env, napi_typeof(env, iconResult, &valuetype)); + if (valuetype == napi_undefined) { + ANS_LOGW("iconResult is undefined"); + napi_set_named_property(env, result, "icon", NapiGetNull(env)); + } else { + napi_set_named_property(env, result, "icon", iconResult); + } + } + return NapiGetBoolean(env, true); +} - // key: string - napi_create_string_utf8(env, messageUser.GetKey().c_str(), NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, result, "key", value); +napi_value Common::SetConversationalMessages(const napi_env &env, + const OHOS::Notification::NotificationConversationalContent *conversationalContent, napi_value &arr) +{ + ANS_LOGI("enter"); + if (!conversationalContent) { + ANS_LOGE("conversationalContent is null"); + return NapiGetBoolean(env, false); + } - return NapiGetboolean(env, true); + int count = 0; + napi_create_array(env, &arr); + std::vector> messages = + conversationalContent->GetAllConversationalMessages(); + for (auto vec : messages) { + if (!vec) { + continue; + } + napi_value conversationalMessageResult = nullptr; + napi_create_object(env, &conversationalMessageResult); + if (!SetConversationalMessage(env, vec, conversationalMessageResult)) { + ANS_LOGE("SetConversationalMessage call failed"); + return NapiGetBoolean(env, false); + } + napi_set_element(env, arr, count, conversationalMessageResult); + count++; + } + return NapiGetBoolean(env, true); } napi_value Common::SetConversationalMessage(const napi_env &env, const std::shared_ptr &conversationalMessage, napi_value &result) { - ANS_LOGI("SetConversationalMessage start"); + ANS_LOGI("enter"); + napi_value value = nullptr; if (conversationalMessage == nullptr) { - ANS_LOGE("SetConversationalMessage is null"); - return NapiGetboolean(env, false); + ANS_LOGE("conversationalMessage is null"); + return NapiGetBoolean(env, false); } - napi_value value = nullptr; // text: string napi_create_string_utf8(env, conversationalMessage->GetText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "text", value); @@ -946,6 +1051,15 @@ napi_value Common::SetConversationalMessage(const napi_env &env, napi_create_int64(env, conversationalMessage->GetArrivedTime(), &value); napi_set_named_property(env, result, "timestamp", value); + // sender: MessageUser + napi_value messageUserResult = nullptr; + napi_create_object(env, &messageUserResult); + if (!SetMessageUser(env, conversationalMessage->GetSender(), messageUserResult)) { + ANS_LOGE("SetMessageUser call failed"); + return NapiGetBoolean(env, false); + } + napi_set_named_property(env, result, "sender", messageUserResult); + // mimeType: string napi_create_string_utf8(env, conversationalMessage->GetMimeType().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "mimeType", value); @@ -954,24 +1068,16 @@ napi_value Common::SetConversationalMessage(const napi_env &env, napi_create_string_utf8(env, conversationalMessage->GetUri()->ToString().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "uri", value); - // sender: MessageUser - napi_value messageUserResult = nullptr; - napi_create_object(env, &messageUserResult); - if (SetMessageUser(env, conversationalMessage->GetSender(), messageUserResult)) { - messageUserResult = NapiGetNull(env); - } - napi_set_named_property(env, result, "sender", messageUserResult); - - return NapiGetboolean(env, true); + return NapiGetBoolean(env, true); } napi_value Common::SetNotificationActionButton( const napi_env &env, const std::shared_ptr &actionButton, napi_value &result) { - ANS_LOGI("SetNotificationActionButton start"); + ANS_LOGI("enter"); if (actionButton == nullptr) { ANS_LOGE("actionButton is null"); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } napi_value value = nullptr; @@ -985,7 +1091,7 @@ napi_value Common::SetNotificationActionButton( if (agent == nullptr) { ANS_LOGI("wantAgent is null"); napi_set_named_property(env, result, "wantAgent", NapiGetNull(env)); - return NapiGetboolean(env, false); + return NapiGetBoolean(env, false); } napi_value wantAgent = nullptr; wantAgent = CreateWantAgentByJS(env, agent); @@ -999,13 +1105,107 @@ napi_value Common::SetNotificationActionButton( iconResult = Media::PixelMapNapi::CreatePixelMap(env, icon); NAPI_CALL(env, napi_typeof(env, iconResult, &valuetype)); if (valuetype == napi_undefined) { - ANS_LOGI("iconResult is undefined"); + ANS_LOGW("iconResult is undefined"); napi_set_named_property(env, result, "icon", NapiGetNull(env)); } else { napi_set_named_property(env, result, "icon", iconResult); } } - return NapiGetboolean(env, true); + + if (!SetNotificationActionButtonByExtras(env, actionButton, result)) { + return NapiGetBoolean(env, false); + } + + //userInput?:NotificationUserInput; + if (actionButton->GetUserInputs().size() > 0) { + napi_value userInputResult = nullptr; + napi_create_object(env, &userInputResult); + if (!SetNotificationActionButtonByUserInput(env, actionButton->GetUserInputs().front(), userInputResult)) { + return NapiGetBoolean(env, false); + } + napi_set_named_property(env, result, "userInput", userInputResult); + } + + return NapiGetBoolean(env, true); +} + +napi_value Common::SetNotificationActionButtonByExtras( + const napi_env &env, const std::shared_ptr &actionButton, napi_value &result) +{ + ANS_LOGI("enter"); + + // extras?: {[key: string]: any} + std::shared_ptr extras = nullptr; + if (extras) { + napi_value nExtras = nullptr; + nExtras = OHOS::AppExecFwk::WrapWantParams(env, *extras); + napi_set_named_property(env, result, "extras", nExtras); + } + return NapiGetBoolean(env, true); +} + +napi_value Common::SetNotificationActionButtonByUserInput( + const napi_env &env, const std::shared_ptr &userInput, napi_value &result) +{ + ANS_LOGI("enter"); + + if (!userInput) { + ANS_LOGE("userInput is null"); + return NapiGetBoolean(env, false); + } + + napi_value value = nullptr; + napi_value arr = nullptr; + int count = 0; + + // inputKey: string + napi_create_string_utf8(env, userInput->GetInputKey().c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, "inputKey", value); + + // tag: string + napi_create_string_utf8(env, userInput->GetTag().c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, result, "tag", value); + + // options: Array + napi_create_array(env, &arr); + for (auto vec : userInput->GetOptions()) { + napi_create_string_utf8(env, vec.c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_element(env, arr, count, value); + count++; + } + if (count > 0) { + napi_set_named_property(env, result, "options", arr); + } + + // permitFreeFormInput?: boolean + napi_get_boolean(env, userInput->IsPermitFreeFormInput(), &value); + napi_set_named_property(env, result, "permitFreeFormInput", value); + + // permitMimeTypes?: Array + count = 0; + napi_create_array(env, &arr); + for (auto vec : userInput->GetPermitMimeTypes()) { + napi_create_string_utf8(env, vec.c_str(), NAPI_AUTO_LENGTH, &value); + napi_set_element(env, arr, count, value); + count++; + } + if (count > 0) { + napi_set_named_property(env, result, "permitMimeTypes", arr); + } + + // editType?: number + napi_create_int64(env, userInput->GetEditType(), &value); + napi_set_named_property(env, result, "editType", value); + + // additionalData?: {[key: string]: any} + std::shared_ptr additionalData = nullptr; + if (additionalData) { + napi_value nAdditionalData = nullptr; + nAdditionalData = OHOS::AppExecFwk::WrapWantParams(env, *additionalData); + napi_set_named_property(env, result, "additionalData", nAdditionalData); + } + + return NapiGetBoolean(env, true); } napi_value Common::SetDoNotDisturbDate( @@ -1013,32 +1213,34 @@ napi_value Common::SetDoNotDisturbDate( { ANS_LOGI("enter"); enum DoNotDisturbType outType = DoNotDisturbType::TYPE_NONE; - if (DoNotDisturbTypeCToJS(date.GetDoNotDisturbType(), outType)) { - // type:DoNotDisturbType - napi_value typeNapi = nullptr; - napi_create_int32(env, outType, &typeNapi); - napi_set_named_property(env, result, "type", typeNapi); - - // begin:Date - double begind = double(date.GetBeginDate()); - napi_value beginNapi = nullptr; - napi_create_date(env, begind, &beginNapi); - napi_set_named_property(env, result, "begin", beginNapi); - - // end:Date - double endd = double(date.GetEndDate()); - napi_value endNapi = nullptr; - napi_create_date(env, endd, &endNapi); - napi_set_named_property(env, result, "end", endNapi); - } else { - return NapiGetboolean(env, false); + if (!DoNotDisturbTypeCToJS(date.GetDoNotDisturbType(), outType)) { + return NapiGetBoolean(env, false); } - return NapiGetboolean(env, true); + + // type:DoNotDisturbType + napi_value typeNapi = nullptr; + napi_create_int32(env, outType, &typeNapi); + napi_set_named_property(env, result, "type", typeNapi); + + // begin:Date + double begind = double(date.GetBeginDate()); + napi_value beginNapi = nullptr; + napi_create_date(env, begind, &beginNapi); + napi_set_named_property(env, result, "begin", beginNapi); + + // end:Date + double endd = double(date.GetEndDate()); + napi_value endNapi = nullptr; + napi_create_date(env, endd, &endNapi); + napi_set_named_property(env, result, "end", endNapi); + + return NapiGetBoolean(env, true); } napi_value Common::GetNotificationSubscriberInfo( const napi_env &env, const napi_value &value, NotificationSubscribeInfo &subscriberInfo) { + ANS_LOGI("enter"); uint32_t length = 0; size_t strLen = 0; bool hasProperty = false; @@ -1080,144 +1282,157 @@ napi_value Common::GetNotificationSubscriberInfo( return NapiGetNull(env); } -napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationRequestByNumber( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); - - // content: NotificationContent - if (GetNotificationContent(env, value, request) == nullptr) { - return nullptr; - } - // id?: number - if (GetIdByPublish(env, value, request) == nullptr) { + if (GetNotificationId(env, value, request) == nullptr) { return nullptr; } - - // slotType?: notification.SlotType - if (GetSlotType(env, value, request) == nullptr) { + // deliveryTime?: number + if (GetNotificationDeliveryTime(env, value, request) == nullptr) { return nullptr; } - - // isOngoing?: boolean - if (GetNotificationIsOngoing(env, value, request) == nullptr) { + // autoDeletedTime?: number + if (GetNotificationAutoDeletedTime(env, value, request) == nullptr) { return nullptr; } - - // isUnremovable?: boolean - if (GetNotificationIsUnremovable(env, value, request) == nullptr) { + // color?: number + if (GetNotificationColor(env, value, request) == nullptr) { return nullptr; } - - // deliveryTime?: number - if (GetNotificationDeliveryTime(env, value, request) == nullptr) { + // badgeIconStyle?: number + if (GetNotificationBadgeIconStyle(env, value, request) == nullptr) { return nullptr; } + return NapiGetNull(env); +} - // tapDismissed?: boolean - if (GetNotificationtapDismissed(env, value, request) == nullptr) { +napi_value Common::GetNotificationRequestByString( + const napi_env &env, const napi_value &value, NotificationRequest &request) +{ + ANS_LOGI("enter"); + // classification?: string + if (GetNotificationClassification(env, value, request) == nullptr) { return nullptr; } - - // wantAgent?: WantAgent - if (GetNotificationWantAgent(env, value, request) == nullptr) { + // statusBarText?: string + if (GetNotificationStatusBarText(env, value, request) == nullptr) { return nullptr; } - - // extraInfo?: {[key: string]: any} - if (GetNotificationExtraInfo(env, value, request) == nullptr) { + // label?: string + if (GetNotificationLabel(env, value, request) == nullptr) { return nullptr; } - - // removalWantAgent?: WantAgent - if (GetNotificationRemovalWantAgent(env, value, request) == nullptr) { + // groupName?: string + if (GetNotificationGroupName(env, value, request) == nullptr) { return nullptr; } + return NapiGetNull(env); +} - // maxScreenWantAgent?: WantAgent - if (GetNotificationMaxScreenWantAgent(env, value, request) == nullptr) { - return nullptr; - } - - // autoDeletedTime?: number - if (GetNotificationAutoDeletedTime(env, value, request) == nullptr) { +napi_value Common::GetNotificationRequestByBool( + const napi_env &env, const napi_value &value, NotificationRequest &request) +{ + ANS_LOGI("enter"); + // isOngoing?: boolean + if (GetNotificationIsOngoing(env, value, request) == nullptr) { return nullptr; } - - // classification?: string - if (GetNotificationClassification(env, value, request) == nullptr) { + // isUnremovable?: boolean + if (GetNotificationIsUnremovable(env, value, request) == nullptr) { return nullptr; } - - // color?: number - if (GetNotificationColor(env, value, request) == nullptr) { + // tapDismissed?: boolean + if (GetNotificationtapDismissed(env, value, request) == nullptr) { return nullptr; } - // colorEnabled?: boolean if (GetNotificationColorEnabled(env, value, request) == nullptr) { return nullptr; } - // isAlertOnce?: boolean if (GetNotificationIsAlertOnce(env, value, request) == nullptr) { return nullptr; } - // isStopwatch?: boolean if (GetNotificationIsStopwatch(env, value, request) == nullptr) { return nullptr; } - // isCountDown?: boolean if (GetNotificationIsCountDown(env, value, request) == nullptr) { return nullptr; } - - // statusBarText?: string - if (GetNotificationStatusBarText(env, value, request) == nullptr) { + // showDeliveryTime?: boolean + if (GetNotificationShowDeliveryTime(env, value, request) == nullptr) { return nullptr; } + return NapiGetNull(env); +} - // label?: string - if (GetNotificationLabel(env, value, request) == nullptr) { +napi_value Common::GetNotificationRequestByCustom( + const napi_env &env, const napi_value &value, NotificationRequest &request) +{ + ANS_LOGI("enter"); + // content: NotificationContent + if (GetNotificationContent(env, value, request) == nullptr) { return nullptr; } - - // badgeIconStyle?: number - if (GetNotificationBadgeIconStyle(env, value, request) == nullptr) { + // slotType?: notification.SlotType + if (GetNotificationSlotType(env, value, request) == nullptr) { return nullptr; } - - // showDeliveryTime?: boolean - if (GetNotificationShowDeliveryTime(env, value, request) == nullptr) { + // wantAgent?: WantAgent + if (GetNotificationWantAgent(env, value, request) == nullptr) { + return nullptr; + } + // extraInfo?: {[key: string]: any} + if (GetNotificationExtraInfo(env, value, request) == nullptr) { + return nullptr; + } + // removalWantAgent?: WantAgent + if (GetNotificationRemovalWantAgent(env, value, request) == nullptr) { + return nullptr; + } + // maxScreenWantAgent?: WantAgent + if (GetNotificationMaxScreenWantAgent(env, value, request) == nullptr) { return nullptr; } - // actionButtons?: Array - if (GetNotificationNotificationActionButtons(env, value, request) == nullptr) { + if (GetNotificationActionButtons(env, value, request) == nullptr) { return nullptr; } - // smallIcon?: image.PixelMap if (GetNotificationSmallIcon(env, value, request) == nullptr) { return nullptr; } - // largeIcon?: image.PixelMap if (GetNotificationLargeIcon(env, value, request) == nullptr) { return nullptr; } + return NapiGetNull(env); +} - // groupName?: string - if (GetNotificationGroupName(env, value, request) == nullptr) { +napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value &value, NotificationRequest &request) +{ + ANS_LOGI("enter"); + if (!GetNotificationRequestByNumber(env, value, request)) { return nullptr; } - - return Common::NapiGetNull(env); + if (!GetNotificationRequestByString(env, value, request)) { + return nullptr; + } + if (!GetNotificationRequestByBool(env, value, request)) { + return nullptr; + } + if (!GetNotificationRequestByCustom(env, value, request)) { + return nullptr; + } + return NapiGetNull(env); } -napi_value GetIdByPublish(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationId(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1233,16 +1448,16 @@ napi_value GetIdByPublish(const napi_env &env, const napi_value &value, Notifica NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); napi_get_value_int32(env, result, ¬ificationId); request.SetNotificationId(notificationId); - ANS_LOGI("============GetIdByPublish notificationId = %{public}d", notificationId); + ANS_LOGI("notificationId = %{public}d", notificationId); } else { + ANS_LOGI("default notificationId = 0"); request.SetNotificationId(0); } - ANS_LOGI("end"); - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetSlotType(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationSlotType(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1259,16 +1474,17 @@ napi_value GetSlotType(const napi_env &env, const napi_value &value, Notificatio napi_get_value_int32(env, result, &slotType); enum NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; - if (!Common::SlotTypeJSToC(SlotType(slotType), outType)) { + if (!SlotTypeJSToC(SlotType(slotType), outType)) { return nullptr; } request.SetSlotType(outType); - ANS_LOGI("============GetSlotType slotType = %{public}d", slotType); + ANS_LOGI("slotType = %{public}d", slotType); } else { + ANS_LOGI("default slotType = OTHER"); request.SetSlotType(NotificationConstant::OTHER); } - ANS_LOGI("end"); - return Common::NapiGetNull(env); + + return NapiGetNull(env); } napi_value Common::GetNotificationContent(const napi_env &env, const napi_value &value, NotificationRequest &request) @@ -1281,10 +1497,7 @@ napi_value Common::GetNotificationContent(const napi_env &env, const napi_value int32_t type = 0; NAPI_CALL(env, napi_has_named_property(env, value, "content", &hasProperty)); - if (!hasProperty) { - ANS_LOGE("Property content expected."); - return nullptr; - } + NAPI_ASSERT(env, hasProperty, "Property content expected."); napi_get_named_property(env, value, "content", &result); NAPI_CALL(env, napi_typeof(env, result, &valuetype)); @@ -1322,18 +1535,14 @@ napi_value Common::GetNotificationContent(const napi_env &env, const napi_value return nullptr; } break; - case NotificationContent::Type::MEDIA: - break; default: return nullptr; - break; } - ANS_LOGI("end"); - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationIsOngoing(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationIsOngoing(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1351,10 +1560,11 @@ napi_value GetNotificationIsOngoing(const napi_env &env, const napi_value &value request.SetInProgress(isOngoing); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationIsUnremovable(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationIsUnremovable( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1372,10 +1582,11 @@ napi_value GetNotificationIsUnremovable(const napi_env &env, const napi_value &v request.SetUnremovable(isUnremovable); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationDeliveryTime(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationDeliveryTime( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1393,10 +1604,11 @@ napi_value GetNotificationDeliveryTime(const napi_env &env, const napi_value &va request.SetDeliveryTime(deliveryTime); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationtapDismissed(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationtapDismissed( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1414,7 +1626,7 @@ napi_value GetNotificationtapDismissed(const napi_env &env, const napi_value &va request.SetTapDismissed(tapDismissed); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } napi_value Common::GetNotificationWantAgent(const napi_env &env, const napi_value &value, NotificationRequest &request) @@ -1440,10 +1652,10 @@ napi_value Common::GetNotificationWantAgent(const napi_env &env, const napi_valu request.SetWantAgent(sWantAgent); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationExtraInfo(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationExtraInfo(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1465,10 +1677,10 @@ napi_value GetNotificationExtraInfo(const napi_env &env, const napi_value &value request.SetAdditionalData(extras); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationGroupName(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationGroupName(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1487,10 +1699,11 @@ napi_value GetNotificationGroupName(const napi_env &env, const napi_value &value request.SetGroupName(str); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationRemovalWantAgent(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationRemovalWantAgent( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1513,10 +1726,11 @@ napi_value GetNotificationRemovalWantAgent(const napi_env &env, const napi_value request.SetRemovalWantAgent(removeWantAgent); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationMaxScreenWantAgent(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationMaxScreenWantAgent( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1539,10 +1753,11 @@ napi_value GetNotificationMaxScreenWantAgent(const napi_env &env, const napi_val request.SetMaxScreenWantAgent(maxScreenWantAgent); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationAutoDeletedTime(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationAutoDeletedTime( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1560,10 +1775,11 @@ napi_value GetNotificationAutoDeletedTime(const napi_env &env, const napi_value request.SetAutoDeletedTime(autoDeletedTime); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationClassification(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationClassification( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1582,10 +1798,10 @@ napi_value GetNotificationClassification(const napi_env &env, const napi_value & request.SetClassification(str); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationColor(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationColor(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1604,10 +1820,11 @@ napi_value GetNotificationColor(const napi_env &env, const napi_value &value, No request.SetColor(color); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationColorEnabled(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationColorEnabled( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1625,10 +1842,11 @@ napi_value GetNotificationColorEnabled(const napi_env &env, const napi_value &va request.SetColorEnabled(colorEnabled); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationIsAlertOnce(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationIsAlertOnce( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1646,10 +1864,11 @@ napi_value GetNotificationIsAlertOnce(const napi_env &env, const napi_value &val request.SetAlertOneTime(isAlertOnce); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationIsStopwatch(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationIsStopwatch( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1667,10 +1886,11 @@ napi_value GetNotificationIsStopwatch(const napi_env &env, const napi_value &val request.SetShowStopwatch(isStopwatch); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationIsCountDown(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationIsCountDown( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1688,10 +1908,11 @@ napi_value GetNotificationIsCountDown(const napi_env &env, const napi_value &val request.SetCountdownTimer(isCountDown); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationStatusBarText(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationStatusBarText( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1710,10 +1931,10 @@ napi_value GetNotificationStatusBarText(const napi_env &env, const napi_value &v request.SetStatusBarText(str); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationLabel(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationLabel(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1732,10 +1953,11 @@ napi_value GetNotificationLabel(const napi_env &env, const napi_value &value, No request.SetLabel(str); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationBadgeIconStyle(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationBadgeIconStyle( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1753,10 +1975,11 @@ napi_value GetNotificationBadgeIconStyle(const napi_env &env, const napi_value & request.SetBadgeIconStyle(static_cast(badgeIconStyle)); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationShowDeliveryTime(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationShowDeliveryTime( + const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1774,10 +1997,10 @@ napi_value GetNotificationShowDeliveryTime(const napi_env &env, const napi_value request.SetShowDeliveryTime(showDeliveryTime); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationNotificationActionButtons( +napi_value Common::GetNotificationActionButtons( const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1785,17 +2008,8 @@ napi_value GetNotificationNotificationActionButtons( bool isArray = false; napi_valuetype valuetype = napi_undefined; napi_value actionButtons = nullptr; - char str[STR_MAX_SIZE] = {0}; - size_t strLen = 0; uint32_t length = 0; bool hasProperty = false; - napi_value titelActionButton = nullptr; - napi_value wantAgentActionButton = nullptr; - napi_value iconActionButton = nullptr; - std::string title; - WantAgent::WantAgent *wantAgentPtr = nullptr; - std::shared_ptr pixelMap = nullptr; - std::shared_ptr wantAgent; napi_has_named_property(env, value, "actionButtons", &hasProperty); if (!hasProperty) { @@ -1813,82 +2027,88 @@ napi_value GetNotificationNotificationActionButtons( NAPI_CALL(env, napi_typeof(env, actionButton, &valuetype)); NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - // title: string - NAPI_CALL(env, napi_has_named_property(env, actionButton, "title", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, actionButton, "title", &titelActionButton); - NAPI_CALL(env, napi_typeof(env, titelActionButton, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, titelActionButton, str, STR_MAX_SIZE - 1, &strLen)); - title = str; - } else { - ANS_LOGE("Property title expected."); - return nullptr; - } - - // wantAgent: WantAgent - NAPI_CALL(env, napi_has_named_property(env, actionButton, "wantAgent", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, actionButton, "wantAgent", &wantAgentActionButton); - NAPI_CALL(env, napi_typeof(env, wantAgentActionButton, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - napi_unwrap(env, wantAgentActionButton, (void **)&wantAgentPtr); - if (wantAgentPtr == nullptr) { - ANS_LOGE("Invalid object wantAgent"); - return nullptr; - } - wantAgent = std::make_shared(*wantAgentPtr); - } else { - ANS_LOGE("Property wantAgent expected."); + std::shared_ptr pActionButton = nullptr; + if (GetNotificationActionButtonsDetailed(env, actionButton, pActionButton) == nullptr) { return nullptr; } - - // icon?: image.PixelMap - NAPI_CALL(env, napi_has_named_property(env, actionButton, "icon", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, actionButton, "icon", &iconActionButton); - NAPI_CALL(env, napi_typeof(env, iconActionButton, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - pixelMap = Media::PixelMapNapi::GetPixelMap(env, iconActionButton); - if (pixelMap == nullptr) { - ANS_LOGE("Invalid object pixelMap"); - return nullptr; - } - } - - auto pActionButton = NotificationActionButton::Create(pixelMap, title, wantAgent); request.AddActionButton(pActionButton); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationSmallIcon(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationActionButtonsDetailed( + const napi_env &env, const napi_value &actionButton, std::shared_ptr &pActionButton) { ANS_LOGI("enter"); + if (!GetNotificationActionButtonsDetailedBasicInfo(env, actionButton, pActionButton)) { + return nullptr; + } + if (!GetNotificationActionButtonsDetailedByExtras(env, actionButton, pActionButton)) { + return nullptr; + } + if (!GetNotificationUserInput(env, actionButton, pActionButton)) { + return nullptr; + } + return NapiGetNull(env); +} + +napi_value Common::GetNotificationActionButtonsDetailedBasicInfo( + const napi_env &env, const napi_value &actionButton, std::shared_ptr &pActionButton) +{ + ANS_LOGI("enter"); napi_valuetype valuetype = napi_undefined; - napi_value result = nullptr; bool hasProperty = false; + char str[STR_MAX_SIZE] = {0}; + size_t strLen = 0; + napi_value value = nullptr; + std::string title; + WantAgent::WantAgent *wantAgentPtr = nullptr; + std::shared_ptr pixelMap = nullptr; + std::shared_ptr wantAgent; - NAPI_CALL(env, napi_has_named_property(env, value, "smallIcon", &hasProperty)); + // title: string + NAPI_CALL(env, napi_has_named_property(env, actionButton, "title", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property title expected."); + napi_get_named_property(env, actionButton, "title", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); + title = str; + + // wantAgent: WantAgent + NAPI_CALL(env, napi_has_named_property(env, actionButton, "wantAgent", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property wantAgent expected."); + napi_get_named_property(env, actionButton, "wantAgent", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + napi_unwrap(env, value, (void **)&wantAgentPtr); + if (wantAgentPtr == nullptr) { + ANS_LOGE("Invalid object wantAgent"); + return nullptr; + } + wantAgent = std::make_shared(*wantAgentPtr); + + // icon?: image.PixelMap + NAPI_CALL(env, napi_has_named_property(env, actionButton, "icon", &hasProperty)); if (hasProperty) { - napi_get_named_property(env, value, "smallIcon", &result); - NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + napi_get_named_property(env, actionButton, "icon", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - std::shared_ptr pixelMap = nullptr; - pixelMap = Media::PixelMapNapi::GetPixelMap(env, result); + pixelMap = Media::PixelMapNapi::GetPixelMap(env, value); if (pixelMap == nullptr) { ANS_LOGE("Invalid object pixelMap"); return nullptr; } - request.SetLittleIcon(pixelMap); } + pActionButton = NotificationActionButton::Create(pixelMap, title, wantAgent); - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationLargeIcon(const napi_env &env, const napi_value &value, NotificationRequest &request) +napi_value Common::GetNotificationActionButtonsDetailedByExtras( + const napi_env &env, const napi_value &actionButton, std::shared_ptr &pActionButton) { ANS_LOGI("enter"); @@ -1896,124 +2116,438 @@ napi_value GetNotificationLargeIcon(const napi_env &env, const napi_value &value napi_value result = nullptr; bool hasProperty = false; - NAPI_CALL(env, napi_has_named_property(env, value, "largeIcon", &hasProperty)); + if (!pActionButton) { + ANS_LOGE("pActionButton is nullptr"); + return nullptr; + } + + //extras?: {[key: string]: any} + NAPI_CALL(env, napi_has_named_property(env, actionButton, "extras", &hasProperty)); if (hasProperty) { - napi_get_named_property(env, value, "largeIcon", &result); + napi_get_named_property(env, actionButton, "extras", &result); NAPI_CALL(env, napi_typeof(env, result, &valuetype)); NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - std::shared_ptr pixelMap = nullptr; - pixelMap = Media::PixelMapNapi::GetPixelMap(env, result); - if (pixelMap == nullptr) { - ANS_LOGE("Invalid object pixelMap"); + AAFwk::WantParams wantParams; + if (!OHOS::AppExecFwk::UnwrapWantParams(env, result, wantParams)) { return nullptr; } - request.SetBigIcon(pixelMap); } - - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationContentType(const napi_env &env, const napi_value &result, int32_t &type) +napi_value Common::GetNotificationUserInput( + const napi_env &env, const napi_value &actionButton, std::shared_ptr &pActionButton) { ANS_LOGI("enter"); - - napi_value contentResult = nullptr; napi_valuetype valuetype = napi_undefined; + napi_value userInputResult = nullptr; bool hasProperty = false; - NAPI_CALL(env, napi_has_named_property(env, result, "contentType", &hasProperty)); - if (!hasProperty) { - ANS_LOGE("Property contentType expected."); - return nullptr; - } + //userInput?: NotificationUserInput + NAPI_CALL(env, napi_has_named_property(env, actionButton, "userInput", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, actionButton, "userInput", &userInputResult); + NAPI_CALL(env, napi_typeof(env, userInputResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + std::shared_ptr userInput = nullptr; - napi_get_named_property(env, result, "contentType", &contentResult); - NAPI_CALL(env, napi_typeof(env, contentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); - napi_get_value_int32(env, contentResult, &type); + if (!GetNotificationUserInputByInputKey(env, userInputResult, userInput)) { + return nullptr; + } + if (!GetNotificationUserInputByTag(env, userInputResult, userInput)) { + return nullptr; + } + if (!GetNotificationUserInputByOptions(env, userInputResult, userInput)) { + return nullptr; + } + if (!GetNotificationUserInputByPermitFreeFormInput(env, userInputResult, userInput)) { + return nullptr; + } + if (!GetNotificationUserInputByPermitMimeTypes(env, userInputResult, userInput)) { + return nullptr; + } + if (!GetNotificationUserInputByEditType(env, userInputResult, userInput)) { + return nullptr; + } + if (!GetNotificationUserInputByAdditionalData(env, userInputResult, userInput)) { + return nullptr; + } + pActionButton->AddNotificationUserInput(userInput); + } - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationBasicContent(const napi_env &env, const napi_value &result, NotificationRequest &request) +napi_value Common::GetNotificationUserInputByInputKey( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput) { ANS_LOGI("enter"); - napi_valuetype valuetype = napi_undefined; - napi_value contentResult = nullptr; - napi_value basicContentResult = nullptr; + napi_value value = nullptr; bool hasProperty = false; char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; - NAPI_CALL(env, napi_has_named_property(env, result, "normal", &hasProperty)); - NAPI_ASSERT(env, hasProperty, "Property normal expected."); - napi_get_named_property(env, result, "normal", &contentResult); - NAPI_CALL(env, napi_typeof(env, contentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - - std::shared_ptr normalContent = std::make_shared(); - if (normalContent == nullptr) { - ANS_LOGE("normalContent is null"); + // inputKey: string + NAPI_CALL(env, napi_has_named_property(env, userInputResult, "inputKey", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property inputKey expected."); + napi_get_named_property(env, userInputResult, "inputKey", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); + ANS_LOGI("NotificationUserInput::inputKey = %{public}s", str); + userInput = NotificationUserInput::Create(str); + if (!userInput) { + ANS_LOGI("Failed to create NotificationUserInput by inputKey=%{public}s", str); return nullptr; } - // title: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); + return NapiGetNull(env); +} + +napi_value Common::GetNotificationUserInputByTag( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value value = nullptr; + bool hasProperty = false; + char str[STR_MAX_SIZE] = {0}; + size_t strLen = 0; + + if (!userInput) { + ANS_LOGE("userInput is nullptr"); + return nullptr; + } + + // tag: string + NAPI_CALL(env, napi_has_named_property(env, userInputResult, "tag", &hasProperty)); if (hasProperty) { - napi_get_named_property(env, contentResult, "title", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); + napi_get_named_property(env, userInputResult, "tag", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - normalContent->SetTitle(str); - ANS_LOGI("normal::title = %{public}s", str); - } else { - ANS_LOGE("Property title expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); + userInput->SetTag(str); + ANS_LOGI("NotificationUserInput::tag = %{public}s", str); + } + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationUserInputByOptions( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value value = nullptr; + bool hasProperty = false; + size_t strLen = 0; + uint32_t length = 0; + bool isArray = false; + + if (!userInput) { + ANS_LOGE("userInput is nullptr"); return nullptr; } - // text: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); + // options: Array + NAPI_CALL(env, napi_has_named_property(env, userInputResult, "options", &hasProperty)); if (hasProperty) { - napi_get_named_property(env, contentResult, "text", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - normalContent->SetText(str); - ANS_LOGI("normal::text = %{public}s", str); - } else { - ANS_LOGE("Property text expected."); + napi_get_named_property(env, userInputResult, "options", &value); + napi_is_array(env, value, &isArray); + NAPI_ASSERT(env, isArray, "Property options is expected to be an array."); + napi_get_array_length(env, value, &length); + NAPI_ASSERT(env, length > 0, "The array is empty."); + std::vector options; + for (uint32_t i = 0; i < length; ++i) { + napi_value option = nullptr; + char str[STR_MAX_SIZE] = {0}; + napi_get_element(env, value, i, &option); + NAPI_CALL(env, napi_typeof(env, option, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, option, str, STR_MAX_SIZE - 1, &strLen)); + options.emplace_back(str); + } + userInput->SetOptions(options); + } + return NapiGetNull(env); +} + +napi_value Common::GetNotificationUserInputByPermitMimeTypes( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value value = nullptr; + bool hasProperty = false; + size_t strLen = 0; + uint32_t length = 0; + bool isArray = false; + + if (!userInput) { + ANS_LOGE("userInput is nullptr"); + return nullptr; + } + + // permitMimeTypes?: Array + NAPI_CALL(env, napi_has_named_property(env, userInputResult, "permitMimeTypes", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, userInputResult, "permitMimeTypes", &value); + napi_is_array(env, value, &isArray); + NAPI_ASSERT(env, isArray, "Property options is expected to be an array."); + napi_get_array_length(env, value, &length); + NAPI_ASSERT(env, length > 0, "The array is empty."); + for (uint32_t i = 0; i < length; ++i) { + napi_value permitMimeType = nullptr; + char str[STR_MAX_SIZE] = {0}; + napi_get_element(env, value, i, &permitMimeType); + NAPI_CALL(env, napi_typeof(env, permitMimeType, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, permitMimeType, str, STR_MAX_SIZE - 1, &strLen)); + userInput->SetPermitMimeTypes(str, true); + } + } + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationUserInputByPermitFreeFormInput( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput) +{ + ANS_LOGI("enter"); + napi_value value = nullptr; + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + + if (!userInput) { + ANS_LOGE("userInput is nullptr"); + return nullptr; + } + + // permitFreeFormInput?: boolean + NAPI_CALL(env, napi_has_named_property(env, userInputResult, "permitFreeFormInput", &hasProperty)); + if (hasProperty) { + bool permitFreeFormInput = false; + napi_get_named_property(env, userInputResult, "permitFreeFormInput", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); + napi_get_value_bool(env, value, &permitFreeFormInput); + ANS_LOGI("permitFreeFormInput is: %{public}d", permitFreeFormInput); + userInput->SetPermitFreeFormInput(permitFreeFormInput); + } + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationUserInputByEditType( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput) +{ + ANS_LOGI("enter"); + napi_value value = nullptr; + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + int32_t editType = 0; + + if (!userInput) { + ANS_LOGE("userInput is nullptr"); + return nullptr; + } + + //editType?: number + NAPI_CALL(env, napi_has_named_property(env, userInputResult, "editType", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, userInputResult, "editType", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + napi_get_value_int32(env, value, &editType); + userInput->SetEditType(NotificationConstant::InputEditType(editType)); + } + return NapiGetNull(env); +} + +napi_value Common::GetNotificationUserInputByAdditionalData( + const napi_env &env, const napi_value &userInputResult, std::shared_ptr &userInput) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value result = nullptr; + bool hasProperty = false; + + if (!userInput) { + ANS_LOGE("userInput is nullptr"); + return nullptr; + } + + //additionalData?: {[key: string]: any} + NAPI_CALL(env, napi_has_named_property(env, userInputResult, "additionalData", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, userInputResult, "additionalData", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + AAFwk::WantParams wantParams; + if (!OHOS::AppExecFwk::UnwrapWantParams(env, result, wantParams)) { + return nullptr; + } + } + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationSmallIcon(const napi_env &env, const napi_value &value, NotificationRequest &request) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value result = nullptr; + bool hasProperty = false; + + NAPI_CALL(env, napi_has_named_property(env, value, "smallIcon", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "smallIcon", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + std::shared_ptr pixelMap = nullptr; + pixelMap = Media::PixelMapNapi::GetPixelMap(env, result); + if (pixelMap == nullptr) { + ANS_LOGE("Invalid object pixelMap"); + return nullptr; + } + request.SetLittleIcon(pixelMap); + } + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationLargeIcon(const napi_env &env, const napi_value &value, NotificationRequest &request) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value result = nullptr; + bool hasProperty = false; + + NAPI_CALL(env, napi_has_named_property(env, value, "largeIcon", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "largeIcon", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + std::shared_ptr pixelMap = nullptr; + pixelMap = Media::PixelMapNapi::GetPixelMap(env, result); + if (pixelMap == nullptr) { + ANS_LOGE("Invalid object pixelMap"); + return nullptr; + } + request.SetBigIcon(pixelMap); + } + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationContentType(const napi_env &env, const napi_value &result, int32_t &type) +{ + ANS_LOGI("enter"); + + napi_value contentResult = nullptr; + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + + NAPI_CALL(env, napi_has_named_property(env, result, "contentType", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property contentType expected."); + + napi_get_named_property(env, result, "contentType", &contentResult); + NAPI_CALL(env, napi_typeof(env, contentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + napi_get_value_int32(env, contentResult, &type); + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationBasicContent( + const napi_env &env, const napi_value &result, NotificationRequest &request) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value contentResult = nullptr; + bool hasProperty = false; + NAPI_CALL(env, napi_has_named_property(env, result, "normal", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property normal expected."); + napi_get_named_property(env, result, "normal", &contentResult); + NAPI_CALL(env, napi_typeof(env, contentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + + std::shared_ptr normalContent = std::make_shared(); + if (normalContent == nullptr) { + ANS_LOGE("normalContent is null"); + return nullptr; + } + + if (GetNotificationBasicContentDetailed(env, contentResult, normalContent) == nullptr) { return nullptr; } + request.SetContent(std::make_shared(normalContent)); + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationBasicContentDetailed( + const napi_env &env, const napi_value &contentResult, std::shared_ptr basicContent) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value value = nullptr; + bool hasProperty = false; + char str[STR_MAX_SIZE] = {0}; + size_t strLen = 0; + + // title: string + NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property title expected."); + napi_get_named_property(env, contentResult, "title", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); + basicContent->SetTitle(str); + ANS_LOGI("normal::title = %{public}s", str); + + // text: string + NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property text expected."); + napi_get_named_property(env, contentResult, "text", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); + basicContent->SetText(str); + ANS_LOGI("normal::text = %{public}s", str); + // additionalText?: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); if (hasProperty) { - napi_get_named_property(env, contentResult, "additionalText", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); + napi_get_named_property(env, contentResult, "additionalText", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - normalContent->SetAdditionalText(str); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); + basicContent->SetAdditionalText(str); ANS_LOGI("normal::additionalText = %{public}s", str); } - request.SetContent(std::make_shared(normalContent)); - - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationLongTextContent(const napi_env &env, const napi_value &result, NotificationRequest &request) +napi_value Common::GetNotificationLongTextContent( + const napi_env &env, const napi_value &result, NotificationRequest &request) { ANS_LOGI("enter"); napi_valuetype valuetype = napi_undefined; napi_value contentResult = nullptr; - napi_value longContentResult = nullptr; - napi_value basicContentResult = nullptr; bool hasProperty = false; - char str[STR_MAX_SIZE] = {0}; - char long_str[LONG_STR_MAX_SIZE + 1] = {0}; - size_t strLen = 0; NAPI_CALL(env, napi_has_named_property(env, result, "longText", &hasProperty)); NAPI_ASSERT(env, hasProperty, "Property longText expected."); @@ -2029,103 +2563,73 @@ napi_value GetNotificationLongTextContent(const napi_env &env, const napi_value return nullptr; } - // title: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "title", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - longContent->SetTitle(str); - ANS_LOGI("longText::title = %{public}s", str); - } else { - ANS_LOGE("Property title expected."); + if (GetNotificationLongTextContentDetailed(env, contentResult, longContent) == nullptr) { return nullptr; } - // text: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "text", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - longContent->SetText(str); - ANS_LOGI("longText::text = %{public}s", str); - } else { - ANS_LOGE("Property text expected."); - return nullptr; - } + request.SetContent(std::make_shared(longContent)); - // additionalText?: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "additionalText", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - longContent->SetAdditionalText(str); - ANS_LOGI("longText::additionalText = %{public}s", str); + return NapiGetNull(env); +} + +napi_value Common::GetNotificationLongTextContentDetailed( + const napi_env &env, const napi_value &contentResult, + std::shared_ptr &longContent) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value longContentResult = nullptr; + bool hasProperty = false; + char str[STR_MAX_SIZE] = {0}; + char long_str[LONG_STR_MAX_SIZE + 1] = {0}; + size_t strLen = 0; + + if (GetNotificationBasicContentDetailed(env, contentResult, longContent) == nullptr) { + return nullptr; } // longText: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "longText", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "longText", &longContentResult); - NAPI_CALL(env, napi_typeof(env, longContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, long_str, LONG_STR_MAX_SIZE, &strLen)); - longContent->SetLongText(long_str); - ANS_LOGI("longText::longText = %{public}s", long_str); - } else { - ANS_LOGE("Property longText expected."); - return nullptr; - } + NAPI_ASSERT(env, hasProperty, "Property longText expected."); + napi_get_named_property(env, contentResult, "longText", &longContentResult); + NAPI_CALL(env, napi_typeof(env, longContentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, long_str, LONG_STR_MAX_SIZE, &strLen)); + longContent->SetLongText(long_str); + ANS_LOGI("longText::longText = %{public}s", long_str); // briefText: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "briefText", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "briefText", &longContentResult); - NAPI_CALL(env, napi_typeof(env, longContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, str, STR_MAX_SIZE - 1, &strLen)); - longContent->SetBriefText(str); - ANS_LOGI("longText::briefText = %{public}s", str); - } else { - ANS_LOGE("Property briefText expected."); - return nullptr; - } + NAPI_ASSERT(env, hasProperty, "Property briefText expected."); + napi_get_named_property(env, contentResult, "briefText", &longContentResult); + NAPI_CALL(env, napi_typeof(env, longContentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, str, STR_MAX_SIZE - 1, &strLen)); + longContent->SetBriefText(str); + ANS_LOGI("longText::briefText = %{public}s", str); // expandedTitle: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "expandedTitle", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "expandedTitle", &longContentResult); - NAPI_CALL(env, napi_typeof(env, longContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, str, STR_MAX_SIZE - 1, &strLen)); - longContent->SetExpandedTitle(str); - ANS_LOGI("longText::expandedTitle = %{public}s", str); - } else { - ANS_LOGE("Property expandedTitle expected."); - return nullptr; - } - - request.SetContent(std::make_shared(longContent)); + NAPI_ASSERT(env, hasProperty, "Property expandedTitle expected."); + napi_get_named_property(env, contentResult, "expandedTitle", &longContentResult); + NAPI_CALL(env, napi_typeof(env, longContentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, longContentResult, str, STR_MAX_SIZE - 1, &strLen)); + longContent->SetExpandedTitle(str); + ANS_LOGI("longText::expandedTitle = %{public}s", str); - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationPictureContent(const napi_env &env, const napi_value &result, NotificationRequest &request) +napi_value Common::GetNotificationPictureContent( + const napi_env &env, const napi_value &result, NotificationRequest &request) { ANS_LOGI("enter"); napi_valuetype valuetype = napi_undefined; napi_value contentResult = nullptr; - napi_value pictureContentResult = nullptr; - napi_value basicContentResult = nullptr; bool hasProperty = false; - char str[STR_MAX_SIZE] = {0}; - size_t strLen = 0; NAPI_CALL(env, napi_has_named_property(env, result, "picture", &hasProperty)); NAPI_ASSERT(env, hasProperty, "Property picture expected."); @@ -2139,241 +2643,305 @@ napi_value GetNotificationPictureContent(const napi_env &env, const napi_value & ANS_LOGE("pictureContent is null"); return nullptr; } + if (GetNotificationPictureContentDetailed(env, contentResult, pictureContent) == nullptr) { + return nullptr; + } - // title: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "title", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - pictureContent->SetTitle(str); - ANS_LOGI("pictureText::title = %{public}s", str); - } else { - ANS_LOGE("Property title expected."); + request.SetContent(std::make_shared(pictureContent)); + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationPictureContentDetailed(const napi_env &env, + const napi_value &contentResult, std::shared_ptr &pictureContent) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value pictureContentResult = nullptr; + bool hasProperty = false; + char str[STR_MAX_SIZE] = {0}; + size_t strLen = 0; + + if (GetNotificationBasicContentDetailed(env, contentResult, pictureContent) == nullptr) { return nullptr; } - // text: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "text", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - pictureContent->SetText(str); - ANS_LOGI("pictureText::text = %{public}s", str); - } else { - ANS_LOGE("Property text expected."); + // briefText: string + NAPI_CALL(env, napi_has_named_property(env, contentResult, "briefText", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property briefText expected."); + napi_get_named_property(env, contentResult, "briefText", &pictureContentResult); + NAPI_CALL(env, napi_typeof(env, pictureContentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, pictureContentResult, str, STR_MAX_SIZE - 1, &strLen)); + pictureContent->SetBriefText(str); + + // expandedTitle: string + NAPI_CALL(env, napi_has_named_property(env, contentResult, "expandedTitle", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property briefText expected."); + napi_get_named_property(env, contentResult, "expandedTitle", &pictureContentResult); + NAPI_CALL(env, napi_typeof(env, pictureContentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, pictureContentResult, str, STR_MAX_SIZE - 1, &strLen)); + pictureContent->SetExpandedTitle(str); + + // picture: image.PixelMap + NAPI_CALL(env, napi_has_named_property(env, contentResult, "picture", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property picture expected."); + napi_get_named_property(env, contentResult, "picture", &pictureContentResult); + NAPI_CALL(env, napi_typeof(env, pictureContentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + std::shared_ptr pixelMap = nullptr; + pixelMap = Media::PixelMapNapi::GetPixelMap(env, pictureContentResult); + if (pixelMap == nullptr) { + ANS_LOGE("Invalid object pixelMap"); + return nullptr; + } + pictureContent->SetBigPicture(pixelMap); + + return Common::NapiGetNull(env); +} + +napi_value Common::GetNotificationConversationalContent( + const napi_env &env, const napi_value &result, NotificationRequest &request) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value contentResult = nullptr; + bool hasProperty = false; + MessageUser user; + + NAPI_CALL(env, napi_has_named_property(env, result, "conversation", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property conversation expected."); + napi_get_named_property(env, result, "conversation", &contentResult); + NAPI_CALL(env, napi_typeof(env, contentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + + if (GetNotificationConversationalContentByUser(env, contentResult, user) == nullptr) { + return nullptr; + } + + std::shared_ptr conversationalContent = + std::make_shared(user); + if (conversationalContent == nullptr) { + ANS_LOGE("conversationalContent is null"); return nullptr; } - // additionalText?: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "additionalText", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - pictureContent->SetAdditionalText(str); - ANS_LOGI("pictureText::additionalText = %{public}s", str); + if (GetNotificationBasicContentDetailed(env, contentResult, conversationalContent) == nullptr) { + return nullptr; } - - // briefText: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "briefText", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "briefText", &pictureContentResult); - NAPI_CALL(env, napi_typeof(env, pictureContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, pictureContentResult, str, STR_MAX_SIZE - 1, &strLen)); - pictureContent->SetBriefText(str); - ANS_LOGI("pictureText::briefText = %{public}s", str); - } else { - ANS_LOGE("Property briefText expected."); + if (GetNotificationConversationalContentTitle(env, contentResult, conversationalContent) == nullptr) { return nullptr; } - - // expandedTitle: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "expandedTitle", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "expandedTitle", &pictureContentResult); - NAPI_CALL(env, napi_typeof(env, pictureContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, pictureContentResult, str, STR_MAX_SIZE - 1, &strLen)); - pictureContent->SetExpandedTitle(str); - ANS_LOGI("pictureText::expandedTitle = %{public}s", str); - } else { - ANS_LOGE("Property expandedTitle expected."); + if (GetNotificationConversationalContentGroup(env, contentResult, conversationalContent) == nullptr) { + return nullptr; + } + if (GetNotificationConversationalContentMessages(env, contentResult, conversationalContent) == nullptr) { return nullptr; } - // picture: image.PixelMap - NAPI_CALL(env, napi_has_named_property(env, contentResult, "picture", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "picture", &pictureContentResult); - NAPI_CALL(env, napi_typeof(env, pictureContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - std::shared_ptr pixelMap = nullptr; - pixelMap = Media::PixelMapNapi::GetPixelMap(env, pictureContentResult); - if (pixelMap == nullptr) { - ANS_LOGE("Invalid object pixelMap"); - return nullptr; - } - pictureContent->SetBigPicture(pixelMap); - } else { - ANS_LOGE("Property picture expected."); + request.SetContent(std::make_shared(conversationalContent)); + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationConversationalContentByUser( + const napi_env &env, const napi_value &contentResult, MessageUser &user) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + + // user: MessageUser + NAPI_CALL(env, napi_has_named_property(env, contentResult, "user", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property user expected."); + napi_value userResult = nullptr; + napi_get_named_property(env, contentResult, "user", &userResult); + NAPI_CALL(env, napi_typeof(env, userResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + if (!GetMessageUser(env, userResult, user)) { return nullptr; } - request.SetContent(std::make_shared(pictureContent)); - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetMessageUser(const napi_env &env, const napi_value &result, MessageUser &messageUser) +napi_value Common::GetNotificationConversationalContentTitle( + const napi_env &env, const napi_value &contentResult, + std::shared_ptr &conversationalContent) { ANS_LOGI("enter"); napi_valuetype valuetype = napi_undefined; + napi_value conversationalContentResult = nullptr; bool hasProperty = false; char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; - // name: string - NAPI_CALL(env, napi_has_named_property(env, result, "name", &hasProperty)); - if (hasProperty) { - napi_value nameResult = nullptr; - napi_get_named_property(env, result, "name", &nameResult); - NAPI_CALL(env, napi_typeof(env, nameResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, nameResult, str, STR_MAX_SIZE - 1, &strLen)); - messageUser.SetName(str); - ANS_LOGI("MessageUser::name = %{public}s", str); - } else { - ANS_LOGE("Property name expected."); - return nullptr; - } + // conversationTitle: string + NAPI_CALL(env, napi_has_named_property(env, contentResult, "conversationTitle", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property conversationTitle expected."); + napi_get_named_property(env, contentResult, "conversationTitle", &conversationalContentResult); + NAPI_CALL(env, napi_typeof(env, conversationalContentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, conversationalContentResult, str, STR_MAX_SIZE - 1, &strLen)); + conversationalContent->SetConversationTitle(str); + ANS_LOGI("conversationTitle = %{public}s", str); - // uri: string - NAPI_CALL(env, napi_has_named_property(env, result, "uri", &hasProperty)); - if (hasProperty) { - napi_value uriResult = nullptr; - napi_get_named_property(env, result, "uri", &uriResult); - NAPI_CALL(env, napi_typeof(env, uriResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, uriResult, str, STR_MAX_SIZE - 1, &strLen)); - Uri uri(str); - messageUser.SetUri(uri); - ANS_LOGI("MessageUser::uri = %{public}s", str); - } else { - ANS_LOGE("Property uri expected."); - return nullptr; - } + return NapiGetNull(env); +} - // important: boolean - NAPI_CALL(env, napi_has_named_property(env, result, "important", &hasProperty)); - if (hasProperty) { - napi_value importantResult = nullptr; - napi_get_named_property(env, result, "important", &importantResult); - NAPI_CALL(env, napi_typeof(env, importantResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); - bool important = false; - napi_get_value_bool(env, importantResult, &important); - messageUser.SetUserAsImportant(important); - ANS_LOGI("MessageUser::important = %{public}d", important); - } else { - ANS_LOGE("Property important expected."); - return nullptr; +napi_value Common::GetNotificationConversationalContentGroup( + const napi_env &env, const napi_value &contentResult, + std::shared_ptr &conversationalContent) +{ + ANS_LOGI("enter"); + napi_valuetype valuetype = napi_undefined;; + napi_value conversationalContentResult = nullptr; + bool hasProperty = false; + + // conversationGroup: boolean + NAPI_CALL(env, napi_has_named_property(env, contentResult, "conversationGroup", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property conversationGroup expected."); + napi_get_named_property(env, contentResult, "conversationGroup", &conversationalContentResult); + NAPI_CALL(env, napi_typeof(env, conversationalContentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); + bool conversationGroup = false; + napi_get_value_bool(env, conversationalContentResult, &conversationGroup); + conversationalContent->SetConversationGroup(conversationGroup); + ANS_LOGI("conversationalText::conversationGroup = %{public}d", conversationGroup); + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationConversationalContentMessages( + const napi_env &env, const napi_value &contentResult, + std::shared_ptr &conversationalContent) +{ + ANS_LOGI("enter"); + napi_valuetype valuetype = napi_undefined; + napi_value conversationalContentResult = nullptr; + bool hasProperty = false; + + // messages: Array + NAPI_CALL(env, napi_has_named_property(env, contentResult, "messages", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property messages expected."); + napi_get_named_property(env, contentResult, "messages", &conversationalContentResult); + bool isArray = false; + napi_is_array(env, conversationalContentResult, &isArray); + NAPI_ASSERT(env, isArray, "Property messages is expected to be an array."); + uint32_t length = 0; + napi_get_array_length(env, conversationalContentResult, &length); + NAPI_ASSERT(env, length > 0, "The array is empty."); + for (size_t i = 0; i < length; i++) { + napi_value conversationalMessage = nullptr; + napi_get_element(env, conversationalContentResult, i, &conversationalMessage); + NAPI_CALL(env, napi_typeof(env, conversationalMessage, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + std::shared_ptr message = nullptr; + if (!GetConversationalMessage(env, conversationalMessage, message)) { + return nullptr; + } + conversationalContent->AddConversationalMessage(message); } - // machine: boolean - NAPI_CALL(env, napi_has_named_property(env, result, "machine", &hasProperty)); - if (hasProperty) { - napi_value machineResult = nullptr; - napi_get_named_property(env, result, "machine", &machineResult); - NAPI_CALL(env, napi_typeof(env, machineResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); - bool machine = false; - napi_get_value_bool(env, machineResult, &machine); - messageUser.SetMachine(machine); - ANS_LOGI("MessageUser::machine = %{public}d", machine); - } else { - ANS_LOGE("Property machine expected."); + return NapiGetNull(env); +} + +napi_value Common::GetConversationalMessage(const napi_env &env, const napi_value &conversationalMessage, + std::shared_ptr &message) +{ + ANS_LOGI("enter"); + + if (GetConversationalMessageBasicInfo(env, conversationalMessage, message) == nullptr) { return nullptr; } - - // key: string - NAPI_CALL(env, napi_has_named_property(env, result, "key", &hasProperty)); - if (hasProperty) { - napi_value keyResult = nullptr; - napi_get_named_property(env, result, "key", &keyResult); - NAPI_CALL(env, napi_typeof(env, keyResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, keyResult, str, STR_MAX_SIZE - 1, &strLen)); - messageUser.SetKey(str); - ANS_LOGI("MessageUser::key = %{public}s", str); - } else { - ANS_LOGE("Property key expected."); + if (GetConversationalMessageOtherInfo(env, conversationalMessage, message) == nullptr) { return nullptr; } - - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetConversationalMessage(const napi_env &env, const napi_value &conversationalMessage, +napi_value Common::GetConversationalMessageBasicInfo(const napi_env &env, const napi_value &conversationalMessage, std::shared_ptr &message) { ANS_LOGI("enter"); + napi_valuetype valuetype = napi_undefined; bool hasProperty = false; char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; std::string text; int64_t timestamp = 0; - std::string mimeType; - std::string uri; MessageUser sender; // text: string NAPI_CALL(env, napi_has_named_property(env, conversationalMessage, "text", &hasProperty)); - if (hasProperty) { - napi_value textResult = nullptr; - napi_get_named_property(env, conversationalMessage, "text", &textResult); - NAPI_CALL(env, napi_typeof(env, textResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, textResult, str, STR_MAX_SIZE - 1, &strLen)); - text = str; - ANS_LOGI("conversationalMessage::text = %{public}s", str); - } else { - ANS_LOGE("Property text expected."); - } + NAPI_ASSERT(env, hasProperty, "Property text expected."); + napi_value textResult = nullptr; + napi_get_named_property(env, conversationalMessage, "text", &textResult); + NAPI_CALL(env, napi_typeof(env, textResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, textResult, str, STR_MAX_SIZE - 1, &strLen)); + text = str; + ANS_LOGI("conversationalMessage::text = %{public}s", str); // timestamp: number NAPI_CALL(env, napi_has_named_property(env, conversationalMessage, "timestamp", &hasProperty)); - if (hasProperty) { - napi_value timestampResult = nullptr; - napi_get_named_property(env, conversationalMessage, "timestamp", ×tampResult); - NAPI_CALL(env, napi_typeof(env, timestampResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); - napi_get_value_int64(env, timestampResult, ×tamp); - ANS_LOGI("conversationalMessage::timestamp = %{public}" PRId64, timestamp); - } else { - ANS_LOGE("Property timestamp expected."); + NAPI_ASSERT(env, hasProperty, "Property timestamp expected."); + napi_value timestampResult = nullptr; + napi_get_named_property(env, conversationalMessage, "timestamp", ×tampResult); + NAPI_CALL(env, napi_typeof(env, timestampResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + napi_get_value_int64(env, timestampResult, ×tamp); + ANS_LOGI("conversationalMessage::timestamp = %{public}" PRId64, timestamp); + + // sender: MessageUser + NAPI_CALL(env, napi_has_named_property(env, conversationalMessage, "sender", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property sender expected."); + napi_value senderResult = nullptr; + napi_get_named_property(env, conversationalMessage, "sender", &senderResult); + NAPI_CALL(env, napi_typeof(env, senderResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + if (!GetMessageUser(env, senderResult, sender)) { + return nullptr; + } + + message = std::make_shared(text, timestamp, sender); + if (!message) { + ANS_LOGE("Failed to create NotificationConversationalMessage object"); + return nullptr; } + return NapiGetNull(env); +} + +napi_value Common::GetConversationalMessageOtherInfo(const napi_env &env, const napi_value &conversationalMessage, + std::shared_ptr &message) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + char str[STR_MAX_SIZE] = {0}; + size_t strLen = 0; + std::string mimeType; + std::string uri; + // mimeType: string NAPI_CALL(env, napi_has_named_property(env, conversationalMessage, "mimeType", &hasProperty)); - if (hasProperty) { - napi_value mimeTypeResult = nullptr; - napi_get_named_property(env, conversationalMessage, "mimeType", &mimeTypeResult); - NAPI_CALL(env, napi_typeof(env, mimeTypeResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, mimeTypeResult, str, STR_MAX_SIZE - 1, &strLen)); - mimeType = str; - ANS_LOGI("conversationalMessage::mimeType = %{public}s", str); - } else { - ANS_LOGE("Property mimeType expected."); - } + NAPI_ASSERT(env, hasProperty, "Property mimeType expected."); + napi_value mimeTypeResult = nullptr; + napi_get_named_property(env, conversationalMessage, "mimeType", &mimeTypeResult); + NAPI_CALL(env, napi_typeof(env, mimeTypeResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, mimeTypeResult, str, STR_MAX_SIZE - 1, &strLen)); + mimeType = str; + ANS_LOGI("conversationalMessage::mimeType = %{public}s", str); - // uri: string + // uri?: string NAPI_CALL(env, napi_has_named_property(env, conversationalMessage, "uri", &hasProperty)); if (hasProperty) { napi_value uriResult = nullptr; @@ -2383,184 +2951,147 @@ napi_value GetConversationalMessage(const napi_env &env, const napi_value &conve NAPI_CALL(env, napi_get_value_string_utf8(env, uriResult, str, STR_MAX_SIZE - 1, &strLen)); uri = str; ANS_LOGI("conversationalMessage::uri = %{public}s", str); - } else { - ANS_LOGE("Property uri expected."); } - // sender: MessageUser - NAPI_CALL(env, napi_has_named_property(env, conversationalMessage, "sender", &hasProperty)); - if (hasProperty) { - napi_value senderResult = nullptr; - napi_get_named_property(env, conversationalMessage, "sender", &senderResult); - NAPI_CALL(env, napi_typeof(env, senderResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - if (!GetMessageUser(env, senderResult, sender)) { - return nullptr; - } - } else { - ANS_LOGE("Property sender expected."); + std::shared_ptr uriPtr = std::make_shared(uri); + message->SetData(mimeType, uriPtr); + + return NapiGetNull(env); +} + +napi_value Common::GetMessageUser(const napi_env &env, const napi_value &result, MessageUser &messageUser) +{ + ANS_LOGI("enter"); + + if (GetMessageUserByString(env, result, messageUser) == nullptr) { + return nullptr; } - message = std::make_shared(text, timestamp, sender); - if (message == nullptr) { - ANS_LOGE("Failed to create NotificationConversationalMessage object."); + if (GetMessageUserByBool(env, result, messageUser) == nullptr) { return nullptr; } - std::shared_ptr uriPtr = std::make_shared(uri); - message->SetData(mimeType, uriPtr); - return Common::NapiGetNull(env); + if (GetMessageUserByCustom(env, result, messageUser) == nullptr) { + return nullptr; + } + + return NapiGetNull(env); } -napi_value GetNotificationConversationalContent( - const napi_env &env, const napi_value &result, NotificationRequest &request) +napi_value Common::GetMessageUserByString(const napi_env &env, const napi_value &result, MessageUser &messageUser) { ANS_LOGI("enter"); napi_valuetype valuetype = napi_undefined; - napi_value contentResult = nullptr; - napi_value conversationalContentResult = nullptr; - napi_value basicContentResult = nullptr; bool hasProperty = false; char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; - MessageUser user; - NAPI_CALL(env, napi_has_named_property(env, result, "conversational", &hasProperty)); - NAPI_ASSERT(env, hasProperty, "Property conversational expected."); - napi_get_named_property(env, result, "conversational", &contentResult); - NAPI_CALL(env, napi_typeof(env, contentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + // name: string + NAPI_CALL(env, napi_has_named_property(env, result, "name", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property name expected."); + napi_value nameResult = nullptr; + napi_get_named_property(env, result, "name", &nameResult); + NAPI_CALL(env, napi_typeof(env, nameResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, nameResult, str, STR_MAX_SIZE - 1, &strLen)); + messageUser.SetName(str); + ANS_LOGI("MessageUser::name = %{public}s", str); - // user: MessageUser - NAPI_CALL(env, napi_has_named_property(env, contentResult, "user", &hasProperty)); - if (hasProperty) { - napi_value userResult = nullptr; - napi_get_named_property(env, contentResult, "user", &userResult); - NAPI_CALL(env, napi_typeof(env, userResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - if (!GetMessageUser(env, userResult, user)) { - return nullptr; - } - } else { - ANS_LOGE("Property user expected."); - return nullptr; - } + // key: string + NAPI_CALL(env, napi_has_named_property(env, result, "key", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property key expected."); + napi_value keyResult = nullptr; + napi_get_named_property(env, result, "key", &keyResult); + NAPI_CALL(env, napi_typeof(env, keyResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, keyResult, str, STR_MAX_SIZE - 1, &strLen)); + messageUser.SetKey(str); + ANS_LOGI("MessageUser::key = %{public}s", str); - std::shared_ptr conversationalContent = - std::make_shared(user); - if (conversationalContent == nullptr) { - ANS_LOGE("conversationalContent is null"); - return nullptr; - } + // uri: string + NAPI_CALL(env, napi_has_named_property(env, result, "uri", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property uri expected."); + napi_value uriResult = nullptr; + napi_get_named_property(env, result, "uri", &uriResult); + NAPI_CALL(env, napi_typeof(env, uriResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, uriResult, str, STR_MAX_SIZE - 1, &strLen)); + Uri uri(str); + messageUser.SetUri(uri); + ANS_LOGI("MessageUser::uri = %{public}s", str); - // title: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "title", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - conversationalContent->SetTitle(str); - ANS_LOGI("conversationalText::title = %{public}s", str); - } else { - ANS_LOGE("Property title expected."); - return nullptr; - } + return NapiGetNull(env); +} - // text: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "text", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - conversationalContent->SetText(str); - ANS_LOGI("conversationalText::text = %{public}s", str); - } else { - ANS_LOGE("Property text expected."); - return nullptr; - } +napi_value Common::GetMessageUserByBool(const napi_env &env, const napi_value &result, MessageUser &messageUser) +{ + ANS_LOGI("enter"); - // additionalText?: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "additionalText", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - conversationalContent->SetAdditionalText(str); - ANS_LOGI("conversationalText::additionalText = %{public}s", str); - } + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; - // conversationTitle: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "conversationTitle", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "conversationTitle", &conversationalContentResult); - NAPI_CALL(env, napi_typeof(env, conversationalContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, conversationalContentResult, str, STR_MAX_SIZE - 1, &strLen)); - conversationalContent->SetConversationTitle(str); - ANS_LOGI("conversationalText::conversationTitle = %{public}s", str); - } else { - ANS_LOGE("Property conversationTitle expected."); - return nullptr; - } + // isMachine: boolean + NAPI_CALL(env, napi_has_named_property(env, result, "isMachine", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property isMachine expected."); + napi_value machineResult = nullptr; + napi_get_named_property(env, result, "isMachine", &machineResult); + NAPI_CALL(env, napi_typeof(env, machineResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); + bool machine = false; + napi_get_value_bool(env, machineResult, &machine); + messageUser.SetMachine(machine); + ANS_LOGI("MessageUser::isMachine = %{public}d", machine); + + // isUserImportant: boolean + NAPI_CALL(env, napi_has_named_property(env, result, "isUserImportant", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property isUserImportant expected."); + napi_value importantResult = nullptr; + napi_get_named_property(env, result, "isUserImportant", &importantResult); + NAPI_CALL(env, napi_typeof(env, importantResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); + bool important = false; + napi_get_value_bool(env, importantResult, &important); + messageUser.SetUserAsImportant(important); + ANS_LOGI("MessageUser::isUserImportant = %{public}d", important); - // conversationGroup: boolean - NAPI_CALL(env, napi_has_named_property(env, contentResult, "conversationGroup", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "conversationGroup", &conversationalContentResult); - NAPI_CALL(env, napi_typeof(env, conversationalContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); - bool conversationGroup = false; - napi_get_value_bool(env, conversationalContentResult, &conversationGroup); - conversationalContent->SetConversationGroup(conversationGroup); - ANS_LOGI("conversationalText::conversationGroup = %{public}d", conversationGroup); - } else { - ANS_LOGE("Property conversationGroup expected."); - return nullptr; - } + return NapiGetNull(env); +} - // messages: Array - NAPI_CALL(env, napi_has_named_property(env, contentResult, "messages", &hasProperty)); +napi_value Common::GetMessageUserByCustom(const napi_env &env, const napi_value &result, MessageUser &messageUser) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + + // icon?: image.PixelMap + NAPI_CALL(env, napi_has_named_property(env, result, "icon", &hasProperty)); if (hasProperty) { - napi_get_named_property(env, contentResult, "messages", &conversationalContentResult); - bool isArray = false; - napi_is_array(env, conversationalContentResult, &isArray); - NAPI_ASSERT(env, isArray, "Property messages is expected to be an array."); - uint32_t length = 0; - napi_get_array_length(env, conversationalContentResult, &length); - NAPI_ASSERT(env, length > 0, "The array is empty."); - for (size_t i = 0; i < length; i++) { - napi_value conversationalMessage = nullptr; - napi_get_element(env, conversationalContentResult, i, &conversationalMessage); - NAPI_CALL(env, napi_typeof(env, conversationalMessage, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - std::shared_ptr message = nullptr; - if (!GetConversationalMessage(env, conversationalMessage, message)) { - return nullptr; - } - conversationalContent->AddConversationalMessage(message); + napi_value iconResult = nullptr; + napi_get_named_property(env, result, "icon", &iconResult); + NAPI_CALL(env, napi_typeof(env, iconResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + std::shared_ptr pixelMap = nullptr; + pixelMap = Media::PixelMapNapi::GetPixelMap(env, iconResult); + if (pixelMap == nullptr) { + ANS_LOGE("Invalid object pixelMap"); + return nullptr; } - } else { - ANS_LOGE("Property messages expected."); - return nullptr; + messageUser.SetPixelMap(pixelMap); } - request.SetContent(std::make_shared(conversationalContent)); - - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationMultiLineContent(const napi_env &env, const napi_value &result, NotificationRequest &request) +napi_value Common::GetNotificationMultiLineContent( + const napi_env &env, const napi_value &result, NotificationRequest &request) { ANS_LOGI("enter"); napi_valuetype valuetype = napi_undefined; napi_value contentResult = nullptr; napi_value multiLineContentResult = nullptr; - napi_value basicContentResult = nullptr; bool hasProperty = false; char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; @@ -2578,90 +3109,43 @@ napi_value GetNotificationMultiLineContent(const napi_env &env, const napi_value return nullptr; } - // title: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "title", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - multiLineContent->SetTitle(str); - ANS_LOGI("multiLine::title = %{public}s", str); - } else { - ANS_LOGE("Property title expected."); - return nullptr; - } - - // text: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "text", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - multiLineContent->SetText(str); - ANS_LOGI("multiLine::text = %{public}s", str); - } else { - ANS_LOGE("Property text expected."); + if (GetNotificationBasicContentDetailed(env, contentResult, multiLineContent) == nullptr) { return nullptr; } - // additionalText?: string - NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "additionalText", &basicContentResult); - NAPI_CALL(env, napi_typeof(env, basicContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, basicContentResult, str, STR_MAX_SIZE - 1, &strLen)); - multiLineContent->SetAdditionalText(str); - ANS_LOGI("multiLine::additionalText = %{public}s", str); - } - // briefText: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "briefText", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "briefText", &multiLineContentResult); - NAPI_CALL(env, napi_typeof(env, multiLineContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, str, STR_MAX_SIZE - 1, &strLen)); - multiLineContent->SetBriefText(str); - ANS_LOGI("multiLine: briefText = %{public}s", str); - } else { - ANS_LOGE("Property briefText expected."); - return nullptr; - } + NAPI_ASSERT(env, hasProperty, "Property briefText expected."); + napi_get_named_property(env, contentResult, "briefText", &multiLineContentResult); + NAPI_CALL(env, napi_typeof(env, multiLineContentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, str, STR_MAX_SIZE - 1, &strLen)); + multiLineContent->SetBriefText(str); + ANS_LOGI("multiLine: briefText = %{public}s", str); // longTitle: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "longTitle", &hasProperty)); - if (hasProperty) { - napi_get_named_property(env, contentResult, "longTitle", &multiLineContentResult); - NAPI_CALL(env, napi_typeof(env, multiLineContentResult, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, str, STR_MAX_SIZE - 1, &strLen)); - multiLineContent->SetExpandedTitle(str); - ANS_LOGI("multiLine: longTitle = %{public}s", str); - } else { - ANS_LOGE("Property longTitle expected."); - return nullptr; - } + NAPI_ASSERT(env, hasProperty, "Property longTitle expected."); + napi_get_named_property(env, contentResult, "longTitle", &multiLineContentResult); + NAPI_CALL(env, napi_typeof(env, multiLineContentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, multiLineContentResult, str, STR_MAX_SIZE - 1, &strLen)); + multiLineContent->SetExpandedTitle(str); + ANS_LOGI("multiLine: longTitle = %{public}s", str); // lines: Array NAPI_CALL(env, napi_has_named_property(env, contentResult, "lines", &hasProperty)); - if (hasProperty) { - if (GetNotificationMultiLineContentLines(env, contentResult, multiLineContent) == nullptr) { - return nullptr; - } - } else { - ANS_LOGE("Property lines expected."); + NAPI_ASSERT(env, hasProperty, "Property lines expected."); + if (GetNotificationMultiLineContentLines(env, contentResult, multiLineContent) == nullptr) { return nullptr; } request.SetContent(std::make_shared(multiLineContent)); - return Common::NapiGetNull(env); + return NapiGetNull(env); } -napi_value GetNotificationMultiLineContentLines(const napi_env &env, const napi_value &result, +napi_value Common::GetNotificationMultiLineContentLines(const napi_env &env, const napi_value &result, std::shared_ptr &multiLineContent) { ANS_LOGI("enter"); @@ -2689,48 +3173,36 @@ napi_value GetNotificationMultiLineContentLines(const napi_env &env, const napi_ ANS_LOGI("multiLine: lines : addSingleLine = %{public}s", str); } - return Common::NapiGetNull(env); + return NapiGetNull(env); } napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &value, NotificationSlot &slot) { ANS_LOGI("enter"); - napi_value nobj = nullptr; - napi_valuetype valuetype = napi_undefined; - bool hasProperty = false; - size_t strLen = 0; - uint32_t length = 0; - // type: notification.SlotType - int slotType = 0; - NAPI_CALL(env, napi_has_named_property(env, value, "type", &hasProperty)); - NAPI_ASSERT(env, hasProperty, "Property type expected."); - napi_get_named_property(env, value, "type", &nobj); - NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); - napi_get_value_int32(env, nobj, &slotType); - enum NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; - if (!SlotTypeJSToC(SlotType(slotType), outType)) { + if (GetNotificationSlotByString(env, value, slot) == nullptr) { return nullptr; } - slot.SetType(outType); + if (GetNotificationSlotByNumber(env, value, slot) == nullptr) { + return nullptr; + } + if (GetNotificationSlotByCustom(env, value, slot) == nullptr) { + return nullptr; + } + if (GetNotificationSlotByBool(env, value, slot) == nullptr) { + return nullptr; + } + return NapiGetNull(env); +} - // level?: number - NAPI_CALL(env, napi_has_named_property(env, value, "level", &hasProperty)); - if (hasProperty) { - int inLevel = 0; - napi_get_named_property(env, value, "level", &nobj); - NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); - napi_get_value_int32(env, nobj, &inLevel); - ANS_LOGI("level is: %{public}d", inLevel); +napi_value Common::GetNotificationSlotByString(const napi_env &env, const napi_value &value, NotificationSlot &slot) +{ + ANS_LOGI("enter"); - NotificationSlot::NotificationLevel outLevel {NotificationSlot::NotificationLevel::LEVEL_NONE}; - if (!SlotLevelJSToC(SlotLevel(inLevel), outLevel)) { - return nullptr; - } - slot.SetLevel(outLevel); - } + napi_value nobj = nullptr; + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + size_t strLen = 0; // desc?: string NAPI_CALL(env, napi_has_named_property(env, value, "desc", &hasProperty)); @@ -2746,6 +3218,30 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va slot.SetDescription(desc); } + // sound?: string + NAPI_CALL(env, napi_has_named_property(env, value, "sound", &hasProperty)); + if (hasProperty) { + std::string sound; + char str[STR_MAX_SIZE] = {0}; + napi_get_named_property(env, value, "sound", &nobj); + NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, nobj, str, STR_MAX_SIZE - 1, &strLen)); + sound = str; + ANS_LOGI("sound is: %{public}s", sound.c_str()); + slot.SetSound(Uri(sound)); + } + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationSlotByBool(const napi_env &env, const napi_value &value, NotificationSlot &slot) +{ + ANS_LOGI("enter"); + napi_value nobj = nullptr; + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + // badgeFlag?: boolean NAPI_CALL(env, napi_has_named_property(env, value, "badgeFlag", &hasProperty)); if (hasProperty) { @@ -2770,32 +3266,6 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va slot.EnableBypassDnd(bypassDnd); } - // lockscreenVisibility?: number - NAPI_CALL(env, napi_has_named_property(env, value, "lockscreenVisibility", &hasProperty)); - if (hasProperty) { - int lockscreenVisibility = 0; - napi_get_named_property(env, value, "lockscreenVisibility", &nobj); - NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); - napi_get_value_int32(env, nobj, &lockscreenVisibility); - ANS_LOGI("lockscreenVisibility is: %{public}d", lockscreenVisibility); - slot.SetLockscreenVisibleness(NotificationConstant::VisiblenessType(lockscreenVisibility)); - } - - // sound?: string - NAPI_CALL(env, napi_has_named_property(env, value, "sound", &hasProperty)); - if (hasProperty) { - std::string sound; - char str[STR_MAX_SIZE] = {0}; - napi_get_named_property(env, value, "sound", &nobj); - NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, nobj, str, STR_MAX_SIZE - 1, &strLen)); - sound = str; - ANS_LOGI("sound is: %{public}s", sound.c_str()); - slot.SetSound(Uri(sound)); - } - // lightEnabled?: boolean NAPI_CALL(env, napi_has_named_property(env, value, "lightEnabled", &hasProperty)); if (hasProperty) { @@ -2808,6 +3278,57 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va slot.SetEnableLight(lightEnabled); } + // vibrationEnabled?: boolean + NAPI_CALL(env, napi_has_named_property(env, value, "vibrationEnabled", &hasProperty)); + if (hasProperty) { + bool vibrationEnabled = false; + napi_get_named_property(env, value, "vibrationEnabled", &nobj); + NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); + napi_get_value_bool(env, nobj, &vibrationEnabled); + ANS_LOGI("vibrationEnabled is: %{public}d", vibrationEnabled); + slot.SetEnableVibration(vibrationEnabled); + } + return NapiGetNull(env); +} + +napi_value Common::GetNotificationSlotByNumber(const napi_env &env, const napi_value &value, NotificationSlot &slot) +{ + ANS_LOGI("enter"); + + napi_value nobj = nullptr; + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + + // level?: number + NAPI_CALL(env, napi_has_named_property(env, value, "level", &hasProperty)); + if (hasProperty) { + int inLevel = 0; + napi_get_named_property(env, value, "level", &nobj); + NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + napi_get_value_int32(env, nobj, &inLevel); + ANS_LOGI("level is: %{public}d", inLevel); + + NotificationSlot::NotificationLevel outLevel {NotificationSlot::NotificationLevel::LEVEL_NONE}; + if (!Common::SlotLevelJSToC(SlotLevel(inLevel), outLevel)) { + return nullptr; + } + slot.SetLevel(outLevel); + } + + // lockscreenVisibility?: number + NAPI_CALL(env, napi_has_named_property(env, value, "lockscreenVisibility", &hasProperty)); + if (hasProperty) { + int lockscreenVisibility = 0; + napi_get_named_property(env, value, "lockscreenVisibility", &nobj); + NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + napi_get_value_int32(env, nobj, &lockscreenVisibility); + ANS_LOGI("lockscreenVisibility is: %{public}d", lockscreenVisibility); + slot.SetLockscreenVisibleness(NotificationConstant::VisiblenessType(lockscreenVisibility)); + } + // lightColor?: number NAPI_CALL(env, napi_has_named_property(env, value, "lightColor", &hasProperty)); if (hasProperty) { @@ -2819,6 +3340,30 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va ANS_LOGI("lightColor is: %{public}d", lightColor); slot.SetLedLightColor(lightColor); } + return NapiGetNull(env); +} + +napi_value Common::GetNotificationSlotByCustom(const napi_env &env, const napi_value &value, NotificationSlot &slot) +{ + ANS_LOGI("enter"); + napi_value nobj = nullptr; + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + uint32_t length = 0; + + // type: notification.SlotType + int slotType = 0; + NAPI_CALL(env, napi_has_named_property(env, value, "type", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property type expected."); + napi_get_named_property(env, value, "type", &nobj); + NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + napi_get_value_int32(env, nobj, &slotType); + enum NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + if (!Common::SlotTypeJSToC(SlotType(slotType), outType)) { + return nullptr; + } + slot.SetType(outType); // vibrationValues?: Array NAPI_CALL(env, napi_has_named_property(env, value, "vibrationValues", &hasProperty)); @@ -2843,18 +3388,6 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va slot.SetVibrationStyle(vibrationValues); } - // vibrationEnabled?: boolean - NAPI_CALL(env, napi_has_named_property(env, value, "vibrationEnabled", &hasProperty)); - if (hasProperty) { - bool vibrationEnabled = false; - napi_get_named_property(env, value, "vibrationEnabled", &nobj); - NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); - napi_get_value_bool(env, nobj, &vibrationEnabled); - ANS_LOGI("vibrationEnabled is: %{public}d", vibrationEnabled); - slot.SetEnableVibration(vibrationEnabled); - } - return NapiGetNull(env); } @@ -2935,6 +3468,9 @@ bool Common::ContentTypeJSToC(const enum ContentType &inType, enum NotificationC case ContentType::NOTIFICATION_CONTENT_PICTURE: outType = NotificationContent::Type::PICTURE; break; + case ContentType::NOTIFICATION_CONTENT_CONVERSATION: + outType = NotificationContent::Type::CONVERSATION; + break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); return false; @@ -2957,6 +3493,9 @@ bool Common::ContentTypeCToJS(const enum NotificationContent::Type &inType, enum case NotificationContent::Type::PICTURE: outType = ContentType::NOTIFICATION_CONTENT_PICTURE; break; + case NotificationContent::Type::CONVERSATION: + outType = ContentType::NOTIFICATION_CONTENT_CONVERSATION; + break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); return false; @@ -3144,6 +3683,25 @@ bool Common::DoNotDisturbTypeCToJS(const NotificationConstant::DoNotDisturbType return true; } +bool Common::SourceTypeCToJS(const NotificationConstant::SourceType &inType, SourceType &outType) +{ + switch (inType) { + case NotificationConstant::SourceType::TYPE_NORMAL: + outType = SourceType::TYPE_NORMAL; + break; + case NotificationConstant::SourceType::TYPE_LONGTASK: + outType = SourceType::TYPE_LONGTASK; + break; + case NotificationConstant::SourceType::TYPE_TIMER: + outType = SourceType::TYPE_TIMER; + break; + default: + ANS_LOGE("SourceType %{public}d is an invalid value", inType); + return false; + } + return true; +} + napi_value Common::CreateWantAgentByJS(const napi_env &env, const std::shared_ptr &agent) { if (agent == nullptr) { @@ -3189,4 +3747,4 @@ napi_value Common::CreateWantAgentByJS(const napi_env &env, const std::shared_pt return wantAgent; } } // namespace NotificationNapi -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/ans/src/constant.cpp b/interfaces/kits/napi/ans/src/constant.cpp index e3946a976..9d6654b3f 100644 --- a/interfaces/kits/napi/ans/src/constant.cpp +++ b/interfaces/kits/napi/ans/src/constant.cpp @@ -198,7 +198,6 @@ napi_value ContentTypeInit(napi_env env, napi_value exports) SetNamedPropertyByInteger( env, obj, ContentType::NOTIFICATION_CONTENT_CONVERSATION, "NOTIFICATION_CONTENT_CONVERSATION"); SetNamedPropertyByInteger(env, obj, ContentType::NOTIFICATION_CONTENT_MULTILINE, "NOTIFICATION_CONTENT_MULTILINE"); - SetNamedPropertyByInteger(env, obj, ContentType::NOTIFICATION_CONTENT_MEDIA, "NOTIFICATION_CONTENT_MEDIA"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("ContentType", obj), @@ -228,6 +227,25 @@ napi_value DoNotDisturbTypeInit(napi_env env, napi_value exports) return exports; } +napi_value SourceTypeInit(napi_env env, napi_value exports) +{ + ANS_LOGI("%{public}s, called", __func__); + + napi_value obj = nullptr; + napi_create_object(env, &obj); + + SetNamedPropertyByInteger(env, obj, SourceType::TYPE_NORMAL, "TYPE_NORMAL"); + SetNamedPropertyByInteger(env, obj, SourceType::TYPE_LONGTASK, "TYPE_LONGTASK"); + SetNamedPropertyByInteger(env, obj, SourceType::TYPE_TIMER, "TYPE_TIMER"); + + napi_property_descriptor exportFuncs[] = { + DECLARE_NAPI_PROPERTY("SourceType", obj), + }; + + napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); + return exports; +} + napi_value ConstantInit(napi_env env, napi_value exports) { NotificationReasonInit(env, exports); @@ -238,6 +256,7 @@ napi_value ConstantInit(napi_env env, napi_value exports) DoNotDisturbMode(env, exports); InputEditTypeInit(env, exports); ContentTypeInit(env, exports); + SourceTypeInit(env, exports); DoNotDisturbTypeInit(env, exports); return exports; } diff --git a/interfaces/kits/napi/ans/src/subscribe.cpp b/interfaces/kits/napi/ans/src/subscribe.cpp index ee5de8347..4056542cf 100644 --- a/interfaces/kits/napi/ans/src/subscribe.cpp +++ b/interfaces/kits/napi/ans/src/subscribe.cpp @@ -49,12 +49,12 @@ napi_value SetSubscribeCallbackData(const napi_env &env, ANS_LOGI("enter"); if (request == nullptr) { ANS_LOGE("request is null"); - return Common::NapiGetboolean(env, false); + return Common::NapiGetBoolean(env, false); } if (sortingMap == nullptr) { ANS_LOGE("sortingMap is null"); - return Common::NapiGetboolean(env, false); + return Common::NapiGetBoolean(env, false); } // request: NotificationRequest @@ -62,7 +62,7 @@ napi_value SetSubscribeCallbackData(const napi_env &env, napi_create_object(env, &requestResult); if (!Common::SetNotification(env, request.get(), requestResult)) { ANS_LOGE("SetNotification call failed"); - return Common::NapiGetboolean(env, false); + return Common::NapiGetBoolean(env, false); } napi_set_named_property(env, result, "request", requestResult); @@ -71,7 +71,7 @@ napi_value SetSubscribeCallbackData(const napi_env &env, napi_create_object(env, &sortingMapResult); if (!Common::SetNotificationSortingMap(env, sortingMap, sortingMapResult)) { ANS_LOGE("SetNotificationSortingMap call failed"); - return Common::NapiGetboolean(env, false); + return Common::NapiGetBoolean(env, false); } napi_set_named_property(env, result, "sortingMap", sortingMapResult); @@ -80,7 +80,7 @@ napi_value SetSubscribeCallbackData(const napi_env &env, napi_value value = nullptr; int outReason = 0; if (!Common::ReasonCToJS(deleteReason, outReason)) { - return Common::NapiGetboolean(env, false); + return Common::NapiGetBoolean(env, false); } napi_create_int32(env, outReason, &value); napi_set_named_property(env, result, "reason", value); @@ -109,7 +109,7 @@ napi_value SetSubscribeCallbackData(const napi_env &env, } napi_set_named_property(env, result, "vibrationValues", arr); - return Common::NapiGetboolean(env, true); + return Common::NapiGetBoolean(env, true); } SubscriberInstance::SubscriberInstance() diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index a476c597b..4cb4da125 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -107,6 +107,8 @@ public: const sptr &bundleOption, const std::string &groupName) override; ErrCode ShellDump(const std::string &dumpOption, std::vector &dumpInfo) override; + ErrCode PublishLongTaskNotification(const sptr &request) override; + ErrCode CancelLongTaskNotification(const std::string &label, int32_t notificationId) override; // SystemEvent void OnBundleRemoved(const sptr &bundleOption); @@ -146,9 +148,10 @@ private: void UpdateRecentNotification(sptr ¬ification, bool isDelete, int reason); void AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate); + bool CheckPermission(const std::string &bundleName); + ErrCode PrepereLongTaskNotificationRequest(const sptr &request, const int &uid); private: - bool CheckPermission(const std::string &bundleName); static sptr instance_; static std::mutex instanceMutex_; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 538f26bfa..1832260ed 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -379,7 +379,6 @@ void AdvancedNotificationService::StopFilters() ErrCode AdvancedNotificationService::Cancel(int notificationId, const std::string &label) { ANS_LOGD("%{public}s", __FUNCTION__); - sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -972,6 +971,9 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList(const sptr ¬ification, bool isCancel) { for (auto record : notificationList_) { + if (!record->notification->IsRemoveAllowed()) { + continue; + } if (((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && (record->bundleOption->GetUid() == bundleOption->GetUid())) && (record->notification->GetLabel() == label) && (record->notification->GetId() == notificationId)) { @@ -991,6 +993,9 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList( const std::string &key, sptr ¬ification, bool isCancel) { for (auto record : notificationList_) { + if (!record->notification->IsRemoveAllowed()) { + continue; + } if (record->notification->GetKey() == key) { if (!isCancel && record->request->IsUnremovable()) { return ERR_ANS_NOTIFICATION_IS_UNREMOVABLE; @@ -1273,6 +1278,85 @@ ErrCode AdvancedNotificationService::ShellDump(const std::string &dumpOption, st return result; } +ErrCode AdvancedNotificationService::PublishLongTaskNotification(const sptr &request) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + + int uid = IPCSkeleton::GetCallingUid(); + if (uid != SYSTEM_SERVICE_UID) { + return ERR_ANS_NOT_SYSTEM_SERVICE; + } + + sptr bundleOption = nullptr; + bundleOption = new NotificationBundleOption(std::string(), uid); + if (bundleOption == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + + ErrCode result = PrepereLongTaskNotificationRequest(request, uid); + if (result != ERR_OK) { + return result; + } + + std::shared_ptr record = std::make_shared(); + record->request = request; + record->bundleOption = bundleOption; + record->notification = new Notification(request); + if (record->notification != nullptr) { + record->notification->SetSourceType(NotificationConstant::SourceType::TYPE_LONGTASK); + record->notification->SetRemoveAllowed(false); + } + + handler_->PostSyncTask(std::bind([&]() { + if (!IsNotificationExists(record->notification->GetKey())) { + AddToNotificationList(record); + } else { + if (record->request->IsAlertOneTime()) { + record->notification->SetEnableLight(false); + record->notification->SetEnableSound(false); + record->notification->SetEnableViration(false); + } + UpdateInNotificationList(record); + } + + UpdateRecentNotification(record->notification, false, 0); + sptr sortingMap = GenerateSortingMap(); + NotificationSubscriberManager::GetInstance()->NotifyConsumed(record->notification, sortingMap); + })); + + return result; +} + +ErrCode AdvancedNotificationService::CancelLongTaskNotification(const std::string &label, int32_t notificationId) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + int uid = IPCSkeleton::GetCallingUid(); + if (uid != SYSTEM_SERVICE_UID) { + return ERR_ANS_NOT_SYSTEM_SERVICE; + } + + ErrCode result = ERR_OK; + handler_->PostSyncTask(std::bind([&]() { + sptr notification = nullptr; + for (auto record : notificationList_) { + if ((record->bundleOption->GetBundleName().empty()) && (record->bundleOption->GetUid() == uid) && + (record->notification->GetId() == notificationId) && (record->notification->GetLabel() == label)) { + notification = record->notification; + notificationList_.remove(record); + result = ERR_OK; + break; + } + } + if (notification != nullptr) { + int reason = NotificationConstant::CANCEL_REASON_DELETE; + UpdateRecentNotification(notification, true, reason); + sptr sortingMap = GenerateSortingMap(); + NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); + } + })); + return result; +} + ErrCode AdvancedNotificationService::ActiveNotificationDump(std::vector &dumpInfo) { ANS_LOGD("%{public}s", __FUNCTION__); @@ -1550,6 +1634,10 @@ ErrCode AdvancedNotificationService::RemoveNotification( sptr notification = nullptr; for (auto record : notificationList_) { + if (!record->notification->IsRemoveAllowed()) { + ANS_LOGD("Current Notification is not remove allowed"); + continue; + } if ((record->bundleOption->GetBundleName() == bundle->GetBundleName()) && (record->bundleOption->GetUid() == bundleOption->GetUid()) && (record->notification->GetId() == notificationId) && (record->notification->GetLabel() == label)) { @@ -1595,6 +1683,11 @@ ErrCode AdvancedNotificationService::RemoveAllNotifications(const sptrPostSyncTask(std::bind([&]() { std::vector> removeList; for (auto record : notificationList_) { + if (!record->notification->IsRemoveAllowed()) { + ANS_LOGD("Current Notification is not remove allowed"); + continue; + } + if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && (record->bundleOption->GetUid() == bundleOption->GetUid()) && !record->request->IsUnremovable()) { removeList.push_back(record); @@ -1903,5 +1996,16 @@ bool AdvancedNotificationService::CheckPermission(const std::string &bundleName) // Add permission check in future return true; } + +ErrCode AdvancedNotificationService::PrepereLongTaskNotificationRequest( + const sptr &request, const int &uid) +{ + int pid = IPCSkeleton::GetCallingPid(); + request->SetCreatorUid(uid); + request->SetCreatorPid(pid); + + ErrCode result = CheckPictureSize(request); + return result; +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 1d6b79c69..af0863774 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1557,5 +1557,73 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10900, EXPECT_EQ(result->GetBeginDate(), beginDate); EXPECT_EQ(result->GetEndDate(), endDate); } + +/** + * @tc.number : ANS_Publish_01500 + * @tc.name : ANSPublish01500 + * @tc.desc : publish a long task notification + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11000, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + sptr req = new NotificationRequest(); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + EXPECT_EQ(advancedNotificationService_->PublishLongTaskNotification(req), (int)ERR_OK); + SleepForFC(); +} + +/** + * @tc.number : ANS_Publish_01600 + * @tc.name : ANSPublish01600 + * @tc.desc : publish a long task notification + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11100, Function | SmallTest | Level1) +{ + sptr req = new NotificationRequest(); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + EXPECT_EQ(advancedNotificationService_->PublishLongTaskNotification(req), (int)ERR_ANS_NOT_SYSTEM_SERVICE); + SleepForFC(); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_11200 + * @tc.name : ANS_Cancel_0300 + * @tc.desc : public two notification to cancel one of them + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11200, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + std::string label = "testLabel"; + { + sptr req = new NotificationRequest(1); + req->SetSlotType(NotificationConstant::OTHER); + req->SetLabel(label); + EXPECT_EQ(advancedNotificationService_->PublishLongTaskNotification(req), (int)ERR_OK); + } + EXPECT_EQ(advancedNotificationService_->CancelLongTaskNotification(label, 1), (int)ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_11300 + * @tc.name : ANS_Cancel_0400 + * @tc.desc : public two notification to cancel one of them + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11300, Function | SmallTest | Level1) +{ + IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); + std::string label = "testLabel"; + { + sptr req = new NotificationRequest(1); + req->SetSlotType(NotificationConstant::OTHER); + req->SetLabel(label); + EXPECT_EQ(advancedNotificationService_->PublishLongTaskNotification(req), (int)ERR_OK); + } + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + EXPECT_EQ(advancedNotificationService_->CancelLongTaskNotification(label, 1), (int)ERR_ANS_NOT_SYSTEM_SERVICE); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/ans_ut_constant.h b/services/ans/test/unittest/ans_ut_constant.h index 886634b71..80a623729 100644 --- a/services/ans/test/unittest/ans_ut_constant.h +++ b/services/ans/test/unittest/ans_ut_constant.h @@ -23,6 +23,7 @@ namespace Notification { constexpr int SYSTEM_APP_UID = 100; constexpr int NON_SYSTEM_APP_UID = 1000; constexpr int NON_BUNDLE_NAME_UID = 2000; +constexpr int SYSTEM_SERVICE_UID = 1000; const std::string TEST_DEFUALT_BUNDLE = "bundleName"; } // namespace Notification } // namespace OHOS -- Gitee