diff --git a/frameworks/ans/core/common/include/ans_const_define.h b/frameworks/ans/core/common/include/ans_const_define.h index 60a2cc4f86ca4c91d066b576045da246dd860bfc..8e1cb00b4de8e36793045b61a5948fbb453b899d 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 a671871f3cc651eba8b73d7638c9dee05d5cd4f4..8e59ee723c4d6cca6045bf428220ab38428e78e3 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 70caf0f6418f6b363ed7dec4e644507782bb6016..fae8fdf3e9c6d99d2df678ad998a5ca68ffd723c 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 PublishContinuousTaskNotification(const sptr &request) = 0; + virtual ErrCode CancelContinuousTaskNotification(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 b780d0d0b43cd54aec342df07244a49f77d3c8ba..77cd702690e590184bc3569e04273c8d8c7a94fe 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 PublishContinuousTaskNotification(const sptr &request) override; + ErrCode CancelContinuousTaskNotification(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 04338d636117f58a898f3c98756d3a4370ba03c2..7947df74faa8ccb744a9e4d2f1ead237c7c55ea2 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 PublishContinuousTaskNotification(const sptr &request) override; + virtual ErrCode CancelContinuousTaskNotification(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 HandlePublishContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); + ErrCode HandleCancelContinuousTaskNotification(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 4c26613237fa36f63228aae1cd45f0d0b81af2f3..0f879f05f11cb20acd38116c68d82bc04b691d24 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 PublishContinuousTaskNotification(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 CancelContinuousTaskNotification(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 69c1809adef353b1903f968843d7c5ccda2d703e..7729d7a7b43fe48cc2c2984128c3575cc18a334c 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("[PublishContinuousTaskNotification] fail: notification request is null ptr."); + return ERR_ANS_INVALID_PARAM; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGW("[PublishContinuousTaskNotification] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteParcelable(request)) { + ANS_LOGW("[PublishContinuousTaskNotification] 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("[PublishContinuousTaskNotification] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGW("[PublishContinuousTaskNotification] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + +ErrCode AnsManagerProxy::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGW("[CancelContinuousTaskNotification] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteString(label)) { + ANS_LOGW("[CancelContinuousTaskNotification] fail: write label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(notificationId)) { + ANS_LOGW("[CancelContinuousTaskNotification] 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("[CancelContinuousTaskNotification] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGW("[CancelContinuousTaskNotification] 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 2e8da5eac30e0865b5b7bd64e8c34c0865b48073..20a8c87d0c62c2714ddd3b6c639c87768463480e 100644 --- a/frameworks/ans/core/src/ans_manager_stub.cpp +++ b/frameworks/ans/core/src/ans_manager_stub.cpp @@ -188,6 +188,14 @@ const std::map request = data.ReadParcelable(); + if (!request) { + ANS_LOGW("[HandlePublishContinuousTaskNotification] fail: notification ReadParcelable failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = PublishContinuousTaskNotification(request); + + if (!reply.WriteInt32(result)) { + ANS_LOGW("[HandlePublishContinuousTaskNotification] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleCancelContinuousTaskNotification(MessageParcel &data, MessageParcel &reply) +{ + std::string label; + if (!data.ReadString(label)) { + ANS_LOGW("[HandleCancelContinuousTaskNotification] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + int notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGW("[HandleCancelContinuousTaskNotification] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelContinuousTaskNotification(label, notificationId); + + if (!reply.WriteInt32(result)) { + ANS_LOGW("[HandleCancelContinuousTaskNotification] 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 +1664,16 @@ ErrCode AnsManagerStub::ShellDump(const std::string &dumpOption, std::vector &request) +{ + ANS_LOGW("AnsManagerStub::PublishContinuousTaskNotification called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) +{ + ANS_LOGW("AnsManagerStub::CancelContinuousTaskNotification 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 fb2a0e253bbfcd42a6dae8844c9fe18d857e1cae..7171c3879954453c41b818d610451b453d87c006 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::PublishContinuousTaskNotification(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_->PublishContinuousTaskNotification(sptrReq); +} + +ErrCode AnsNotification::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return ansManagerProxy_->CancelContinuousTaskNotification(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 9e829789e0316cd5dad20c9fe05768310230d890..100e122204397d86a1dec2169d0304f3f5b876ad 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,7 +173,17 @@ bool Notification::IsFloatingIcon() const return request_->IsFloatingIcon(); } -bool Notification::Marshalling(Parcel &parcel) const +bool Notification::IsRemoveAllowed() const +{ + return isRemoveAllowed_; +} + +NotificationConstant::SourceType Notification::GetSourceType() const +{ + return sourceType_; +} + +bool Notification::MarshallingBool(Parcel &parcel) const { if (!parcel.WriteBool(enableLight_)) { ANS_LOGE("Can't write enableLight_"); @@ -188,10 +200,33 @@ bool Notification::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteBool(isRemoveAllowed_)) { + ANS_LOGE("Can't write isRemoveAllowed"); + return false; + } + + return true; +} + +bool Notification::MarshallingString(Parcel &parcel) const +{ if (!parcel.WriteString(key_)) { ANS_LOGE("Can't wirte key"); return false; } + + if (enableSound_ && sound_ != nullptr) { + if (!parcel.WriteString(sound_->ToString())) { + ANS_LOGE("Can't write sound"); + return false; + } + } + + return true; +} + +bool Notification::MarshallingInt32(Parcel &parcel) const +{ if (!parcel.WriteInt32(ledLightColor_)) { ANS_LOGE("Can't write ledLigthColor"); return false; @@ -202,23 +237,21 @@ bool Notification::Marshalling(Parcel &parcel) const return false; } - if (!parcel.WriteStrongParcelable(request_)) { - ANS_LOGE("Can't write request"); + if (!parcel.WriteInt32(static_cast(sourceType_))) { + ANS_LOGE("Can't write sourceType"); return false; } + return true; +} + +bool Notification::MarshallingInt64(Parcel &parcel) const +{ if (!parcel.WriteInt64(postTime_)) { ANS_LOGE("Can't write postTime"); return false; } - if (enableSound_ && sound_ != nullptr) { - if (!parcel.WriteString(sound_->ToString())) { - ANS_LOGE("Can't write sound"); - return false; - } - } - if (!parcel.WriteInt64Vector(vibrationStyle_)) { ANS_LOGE("Can't write vibrationStyle"); return false; @@ -227,7 +260,38 @@ bool Notification::Marshalling(Parcel &parcel) const return true; } -bool Notification::ReadFromParcel(Parcel &parcel) +bool Notification::MarshallingParcelable(Parcel &parcel) const +{ + if (!parcel.WriteStrongParcelable(request_)) { + ANS_LOGE("Can't write request"); + return false; + } + + return true; +} + +bool Notification::Marshalling(Parcel &parcel) const +{ + if (!MarshallingBool(parcel)) { + return false; + } + if (!MarshallingString(parcel)) { + return false; + } + if (!MarshallingInt32(parcel)) { + return false; + } + if (!MarshallingInt64(parcel)) { + return false; + } + if (!MarshallingParcelable(parcel)) { + return false; + } + + return true; +} + +void Notification::ReadFromParcelBool(Parcel &parcel) { // Read enableLight_ enableLight_ = parcel.ReadBool(); @@ -238,28 +302,55 @@ bool Notification::ReadFromParcel(Parcel &parcel) // Read enableViration_ enableViration_ = parcel.ReadBool(); + // Read isRemoveAllowed_ + isRemoveAllowed_ = parcel.ReadBool(); +} + +void Notification::ReadFromParcelString(Parcel &parcel) +{ // Read key_ key_ = parcel.ReadString(); + + // Read sound_ + if (enableSound_) { + sound_ = std::make_shared(parcel.ReadString()); + } +} +void Notification::ReadFromParcelInt32(Parcel &parcel) +{ // Read ledLightColor_ ledLightColor_ = parcel.ReadInt32(); // Read lockscreenVisibleness_ lockscreenVisibleness_ = static_cast(parcel.ReadInt32()); - // Read request_ - request_ = parcel.ReadStrongParcelable(); + // Read sourceType_ + sourceType_ = static_cast(parcel.ReadInt32()); +} +void Notification::ReadFromParcelInt64(Parcel &parcel) +{ // Read postTime_ postTime_ = parcel.ReadInt64(); - // Read sound_ - if (enableSound_) { - sound_ = std::make_shared(parcel.ReadString()); - } - // Read vibrationStyle_ parcel.ReadInt64Vector(&vibrationStyle_); +} + +void Notification::ReadFromParcelParcelable(Parcel &parcel) +{ + // Read request_ + request_ = parcel.ReadStrongParcelable(); +} + +bool Notification::ReadFromParcel(Parcel &parcel) +{ + ReadFromParcelBool(parcel); + ReadFromParcelString(parcel); + ReadFromParcelInt32(parcel); + ReadFromParcelInt64(parcel); + ReadFromParcelParcelable(parcel); return true; } @@ -325,10 +416,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 020fe4a0bc7768479c6361ea237d0a164dfdd879..038e5f916b8e23c7bff463c203988100cebe05ae 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::PublishContinuousTaskNotification(const NotificationRequest &request) +{ + return DelayedSingleton::GetInstance()->PublishContinuousTaskNotification(request); +} + +ErrCode NotificationHelper::CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) +{ + return DelayedSingleton::GetInstance()->CancelContinuousTaskNotification(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 801fb1eb0901cf53e62aa00df8b83cf4d1c5b5b1..1ea18d3c048611432ab3754a65a6b5e917d182fc 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 9b2b77064a9fdd8b002e193cd2ed56fc6b9cf057..ef727d9dafdb2faeba7fbd12f35c7ad91822196e 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::PublishContinuousTaskNotification(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::CancelContinuousTaskNotification(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::PublishContinuousTaskNotification(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::CancelContinuousTaskNotification(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::PublishContinuousTaskNotification(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::CancelContinuousTaskNotification(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::PublishContinuousTaskNotification(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::CancelContinuousTaskNotification(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::PublishContinuousTaskNotification(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_CONTINUOUS); + + 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 e515d617a8815d1caa940dcbd4ddf3c7ecbd807b..1b125e4fefa7ea54b2f04bc293ad3b2e869b0dc4 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,16 +228,30 @@ private: void SetPostTime(const int64_t &time); void SetSound(const Uri &sound); void SetVibrationStyle(const std::vector &style); - bool ReadFromParcel(Parcel &parcel); + void SetRemoveAllowed(bool removeAllowed); + void SetSourceType(NotificationConstant::SourceType sourceType); std::string GenerateNotificationKey(int32_t uid, const std::string &label, int32_t id); + bool ReadFromParcel(Parcel &parcel); + void ReadFromParcelBool(Parcel &parcel); + void ReadFromParcelString(Parcel &parcel); + void ReadFromParcelInt32(Parcel &parcel); + void ReadFromParcelInt64(Parcel &parcel); + void ReadFromParcelParcelable(Parcel &parcel); + bool MarshallingBool(Parcel &parcel) const; + bool MarshallingString(Parcel &parcel) const; + bool MarshallingInt32(Parcel &parcel) const; + bool MarshallingInt64(Parcel &parcel) const; + bool MarshallingParcelable(Parcel &parcel) const; 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 dcf4fe9735b96076b268fa764a02e949f6abbceb..fb8f4aae84e2ee34cdbf7f77c592a882e79721ce 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_CONTINUOUS = 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 73bd56b50ac346498d097303739620e5f387f248..cbc3d46c1f2b183bef20b299cdd7584b7438355a 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 PublishContinuousTaskNotification(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 CancelContinuousTaskNotification(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 d5f6c81df4469e890aebaf2238f594b2383b4016..ad1b0789fc2c2e9b0aa620e63e80ff085f07279a 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/js/@ohos.notification.d.ts b/interfaces/kits/js/@ohos.notification.d.ts index 869beba60ae1571b8d17f51e908d61aef11a6863..b1eb7f274a8d21dba6fa73a769434051c9060be2 100644 --- a/interfaces/kits/js/@ohos.notification.d.ts +++ b/interfaces/kits/js/@ohos.notification.d.ts @@ -34,6 +34,7 @@ import { NotificationRequest } from './notification/notificationRequest'; * @since 7 * @sysCap SystemCapability.Notification.ANS * @devices phone, tablet, tv, wearable, car + * @import import notification from '@ohos.notification'; * @permission N/A */ declare namespace notification { @@ -43,39 +44,29 @@ declare namespace notification { *

If a notification with the same ID has been published by the current application and has not been deleted, * this method will update the notification. * - * @param request Indicates the {@link NotificationRequest} object for setting the notification content. - * This parameter must be specified. - * - * @since 7 + * @param Publishes a notification. */ function publish(request: NotificationRequest, callback: AsyncCallback): void; function publish(request: NotificationRequest): Promise; /** - * Cancels a published notification. + * Cancels a notification with the specified ID. * - * @param id Indicates the unique notification ID in the application. The value must be the ID - * of a published notification. Otherwise, this method does not take effect. - * - * @since 7 + * @param ID of the notification to cancel, which must be unique in the application. */ function cancel(id: number, callback: AsyncCallback): void; /** - * Cancels a published notification matching the specified {@code label} and {@code notificationId}. - * - * @param label Indicates the label of the notification to cancel. - * @param id Indicates the ID of the notification to cancel. + * Cancels a notification with the specified label and ID. * - * @since 7 + * @param ID of the notification to cancel, which must be unique in the application. + * @param Label of the notification to cancel. */ function cancel(id: number, label: string, callback: AsyncCallback): void; function cancel(id: number, label?: string): Promise; /** - * Cancels all the published notifications. - * - * @since 7 + * Cancels all notifications of the current application. */ function cancelAll(callback: AsyncCallback): void; function cancelAll(): Promise; @@ -87,18 +78,23 @@ declare namespace notification { * This parameter must be specified. * * @systemapi Hide this for inner system use. - * @since 7 */ function addSlot(slot: NotificationSlot, callback: AsyncCallback): void; - function addSlot(slot: NotificationSlot): Promise; /** * Creates a notification slot. * - * @param slot Indicates the notification slot to be created, which is set by {@link SlotType}. + * @param slot Indicates the notification slot to be created, which is set by {@link NotificationSlot}. * This parameter must be specified. * - * @since 7 + * @systemapi Hide this for inner system use. + */ + function addSlot(slot: NotificationSlot): Promise; + + /** + * Adds a slot type. + * + * @param Slot type to add. */ function addSlot(type: SlotType, callback: AsyncCallback): void; function addSlot(type: SlotType): Promise; @@ -110,66 +106,83 @@ declare namespace notification { * This parameter must be specified. * * @systemapi Hide this for inner system use. - * @since 7 */ function addSlots(slots: Array, callback: AsyncCallback): void; + + /** + * Creates a notification slot. + * + * @param slots Indicates the notification slots to be created, which is set by {@link NotificationSlot}. + * This parameter must be specified. + * + * @systemapi Hide this for inner system use. + */ function addSlots(slots: Array): Promise; /** - * Queries a created notification slot. + * Obtains a notification slot of the specified slot type. * - * @param slotType Indicates the type of the slot, which is created by + * @param Type of the notification slot to obtain. * * @return Returns the created {@link NotificationSlot}. - * - * @since 7 */ function getSlot(slotType: SlotType, callback: AsyncCallback): void; function getSlot(slotType: SlotType): Promise; /** - * Obtains all notification slots of this application. + * Obtains all NotificationSlot objects created by the current application. * * @return Returns all notification slots of this application. - * - * @since 7 */ function getSlots(callback: AsyncCallback>): void; function getSlots(): Promise>; /** - * Deletes a created notification slot based on the slot type. + * Removes a NotificationSlot of the specified SlotType created by the current application. * - * @param slotType Indicates the type of the slot. - * - * @since 7 + * @param Type of the NotificationSlot to remove. */ function removeSlot(slotType: SlotType, callback: AsyncCallback): void; function removeSlot(slotType: SlotType): Promise; /** - * Deletes all notification slots. - * - * @since 7 + * Removes all NotificationSlot objects created by the current application. */ function removeAllSlots(callback: AsyncCallback): void; function removeAllSlots(): Promise; /** - * Indicates the type of the slot - * - * @since 7 + * Describes NotificationSlot types. */ export enum SlotType { + /** + * NotificationSlot of an unknown type. + */ UNKNOWN_TYPE = 0, + + /** + * NotificationSlot for social communication. + */ SOCIAL_COMMUNICATION = 1, + + /** + * NotificationSlot for service information. + */ SERVICE_INFORMATION = 2, + + /** + * NotificationSlot for service information. + */ CONTENT_INFORMATION = 3, + + /** + * NotificationSlot for other purposes. + */ OTHER_TYPES = 0xFFFF, } /** - * Indicates the type of the content + * Describes notification content types. * * @name ContentType * @since 7 @@ -178,23 +191,63 @@ declare namespace notification { * @permission N/A */ export enum ContentType { + /** + * Normal text notification. + */ NOTIFICATION_CONTENT_BASIC_TEXT, + + /** + * Long text notification. + */ NOTIFICATION_CONTENT_LONG_TEXT, + + /** + * Picture-attached notification. + */ NOTIFICATION_CONTENT_PICTURE, + + /** + * Conversation notification. + */ NOTIFICATION_CONTENT_CONVERSATION, + + /** + * Multi-line text notification. + */ NOTIFICATION_CONTENT_MULTILINE, } /** * Indicates the level of the slot - * - * @since 7 */ export enum SlotLevel { + /** + * Indicates that the notification function is disabled. + */ LEVEL_NONE = 0, + + /** + * Indicates that the notification function is enabled but notification + * icons are not displayed in the status bar, with no banner or prompt tone. + */ LEVEL_MIN = 1, + + /** + * Indicates that the notification function is enabled and notification + * icons are displayed in the status bar, with no banner or prompt tone. + */ LEVEL_LOW = 2, + + /** + * Indicates that the notification function is enabled and notification + * icons are displayed in the status bar, with no banner but with a prompt tone. + */ LEVEL_DEFAULT = 3, + + /** + * Indicates that the notification function is enabled and notification + * icons are displayed in the status bar, with a banner and a prompt tone. + */ LEVEL_HIGH = 4, } @@ -202,119 +255,214 @@ declare namespace notification { * subscribe * * @systemapi Hide this for inner system use. - * @since 7 + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback): void; + + /** + * subscribe + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ function subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback): void; + + /** + * subscribe + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ function subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise; /** * unsubscribe * * @systemapi Hide this for inner system use. - * @since 7 + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback): void; + + /** + * unsubscribe + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ function unsubscribe(subscriber: NotificationSubscriber): Promise; /** * enableNotification * * @systemapi Hide this for inner system use. - * @since 7 + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void; + + /** + * enableNotification + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ function enableNotification(bundle: BundleOption, enable: boolean): Promise; /** * isNotificationEnabled * * @systemapi Hide this for inner system use. - * @since 7 */ function isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback): void; + + /** + * isNotificationEnabled + * + * @systemapi Hide this for inner system use. + */ function isNotificationEnabled(bundle: BundleOption): Promise; /** * isNotificationEnabled * * @systemapi Hide this for inner system use. - * @since 7 */ function isNotificationEnabled(callback: AsyncCallback): void; + + /** + * isNotificationEnabled + * + * @systemapi Hide this for inner system use. + */ function isNotificationEnabled(): Promise; /** * displayBadge * * @systemapi Hide this for inner system use. - * @since 7 */ function displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void; + + /** + * displayBadge + * + * @systemapi Hide this for inner system use. + */ function displayBadge(bundle: BundleOption, enable: boolean): Promise; /** * isBadgeDisplayed * * @systemapi Hide this for inner system use. - * @since 7 */ function isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback): void; + + /** + * isBadgeDisplayed + * + * @systemapi Hide this for inner system use. + */ function isBadgeDisplayed(bundle: BundleOption): Promise; /** * setSlotByBundle * * @systemapi Hide this for inner system use. - * @since 7 + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback): void; + + /** + * setSlotByBundle + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ function setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise; /** * getSlotsByBundle * * @systemapi Hide this for inner system use. - * @since 7 + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>): void; + + /** + * getSlotsByBundle + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ function getSlotsByBundle(bundle: BundleOption): Promise>; /** * getSlotNumByBundle * * @systemapi Hide this for inner system use. - * @since 7 */ function getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback): void; + + /** + * getSlotNumByBundle + * + * @systemapi Hide this for inner system use. + */ function getSlotNumByBundle(bundle: BundleOption): Promise; /** * remove * * @systemapi Hide this for inner system use. - * @since 7 + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback): void; + + /** + * remove + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ function remove(bundle: BundleOption, notificationKey: NotificationKey): Promise; /** * remove * * @systemapi Hide this for inner system use. - * @since 7 + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function remove(hashCode: string, callback: AsyncCallback): void; + + /** + * remove + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ function remove(hashCode: string): Promise; /** * removeAll * * @systemapi Hide this for inner system use. - * @since 7 + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function removeAll(bundle: BundleOption, callback: AsyncCallback): void; + + /** + * removeAll + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ function removeAll(callback: AsyncCallback): void; + + /** + * removeAll + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ function removeAll(bundle?: BundleOption): Promise; /** @@ -322,31 +470,33 @@ declare namespace notification { * call this method. * * @systemapi Hide this for inner system use. - * @since 7 + * @permission ohos.permission.NOTIFICATION_CONTROLLER */ function getAllActiveNotifications(callback: AsyncCallback>): void; - function getAllActiveNotifications(): Promise>; /** - * Obtains the number of active notifications of the current application in the system. + * Obtains all active notifications in the current system. The caller must have system permissions to + * call this method. * - * @since 7 + * @systemapi Hide this for inner system use. + * @permission ohos.permission.NOTIFICATION_CONTROLLER + */ + function getAllActiveNotifications(): Promise>; + + /** + * Obtains the number of all active notifications. */ function getActiveNotificationCount(callback: AsyncCallback): void; function getActiveNotificationCount(): Promise; /** - * Obtains active notifications of the current application in the system. - * - * @since 7 + * Obtains an array of active notifications. */ function getActiveNotifications(callback: AsyncCallback>): void; function getActiveNotifications(): Promise>; /** - * BundleOption - * - * @since 7 + * Describes a BundleOption. */ export interface BundleOption { bundle: string; @@ -354,9 +504,7 @@ declare namespace notification { } /** - * NotificationKey - * - * @since 7 + * Describes a NotificationKey, which can be used to identify a notification. */ export interface NotificationKey { id: number; @@ -367,7 +515,6 @@ declare namespace notification { * DisturbMode * * @systemapi Hide this for inner system use. - * @since 7 */ export enum DoNotDisturbMode { ALLOW_UNKNOWN, diff --git a/interfaces/kits/js/@ohos.wantAgent.d.ts b/interfaces/kits/js/@ohos.wantAgent.d.ts index f7eab8a04f132e0681e147a410e316dde067d16f..17dd1c8aa2d855ada9d3e36a8b994b45eb4ca9e5 100644 --- a/interfaces/kits/js/@ohos.wantAgent.d.ts +++ b/interfaces/kits/js/@ohos.wantAgent.d.ts @@ -25,26 +25,24 @@ import { TriggerInfo } from './wantAgent/triggerInfo'; * @name wantAgent * @since 7 * @devices phone, tablet, tv, wearable, car - * @import wantAgent from '@ohos.wantAgent'; + * @import import wantAgent from '@ohos.wantAgent'; * @permission N/A */ declare namespace wantAgent { /** - * Obtains the bundle name of an {@link WantAgent}. + * Obtains the bundle name of a WantAgent. * - * @param agent Indicates the {@link WantAgent} whose bundle name is to be obtained. + * @param WantAgent whose bundle name to obtain. * @return Returns the bundle name of the {@link WantAgent} if any. - * @since 7 */ function getBundleName(agent: WantAgent, callback: AsyncCallback): void; function getBundleName(agent: WantAgent): Promise; /** - * Obtains the bundle name of an {@link WantAgent}. + * Obtains the UID of a WantAgent. * - * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. + * @param WantAgent whose UID to obtain. * @return Returns the UID of the {@link WantAgent} if any; returns {@code -1} otherwise. - * @since 7 */ function getUid(agent: WantAgent, callback: AsyncCallback): void; function getUid(agent: WantAgent): Promise; @@ -55,98 +53,177 @@ declare namespace wantAgent { * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. * @return Returns the {@link Want} of the {@link WantAgent}. * @systemapi Hide this for inner system use. - * @since 7 */ function getWant(agent: WantAgent, callback: AsyncCallback): void; + + /** + * Obtains the {@link Want} of an {@link WantAgent}. + * + * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. + * @return Returns the {@link Want} of the {@link WantAgent}. + * @systemapi Hide this for inner system use. + */ function getWant(agent: WantAgent): Promise; /** - * Cancels an {@link WantAgent}. Only the application that creates the {@link IntentAgent} can cancel it. + * Cancels a WantAgent. Only the application that creates the WantAgent can cancel it. * - * @param agent Indicates the {@link WantAgent} to cancel. - * @since 7 + * @param WantAgent to cancel. */ function cancel(agent: WantAgent, callback: AsyncCallback): void; function cancel(agent: WantAgent): Promise; /** - * Obtains the bundle name of an {@link WantAgent}. + * Triggers a WantAgent. * - * @param agent Indicates the {@link WantAgent} whose bundle name is to be obtained. - * @param triggerInfo Indicates the {@link TriggerInfo} object that contains triggering parameters. + * @param WantAgent to trigger. + * @param Trigger parameters. * @param callback Indicates the callback method to be called after the {@link WantAgent} is triggered. - * @since 7 */ function trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback): void; /** - * Checks whether two {@link WantAgent} objects are the same. + * Checks whether two WantAgent objects are equal. * - * @param agent Indicates one of the {@link WantAgent} object to compare. - * @param otherAgent Indicates the other {@link WantAgent} object to compare. + * @param WantAgent to compare. + * @param WantAgent to compare. * @return Returns {@code true} If the two objects are the same; returns {@code false} otherwise. - * @since 7 */ function equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback): void; function equal(agent: WantAgent, otherAgent: WantAgent): Promise; /** - * Obtains an {@link WantAgent} object. + * Obtains a WantAgent object. * - * @param info Indicates the {@link WantAgentInfo} object that contains parameters of the - * {@link WantAgent} object to create. + * @param Information about the WantAgent object to obtain. * @return Returns the created {@link WantAgent} object. - * @since 7 */ function getWantAgent(info: WantAgentInfo, callback: AsyncCallback): void; function getWantAgent(info: WantAgentInfo): Promise; /** - * Enumerates flags for using an {@link WantAgent}. - * - * @since 7 + * Enumerates flags for using a WantAgent. */ export enum WantAgentFlags { + /** + * Indicates that the WantAgent can be used only once. + * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. + */ ONE_TIME_FLAG = 0, + + /** + * Indicates that null is returned if the WantAgent does not exist. + * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. + */ NO_BUILD_FLAG, + + /** + * Indicates that the existing WantAgent should be canceled before a new object is generated. + * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. + */ CANCEL_PRESENT_FLAG, + + /** + * Indicates that the system only replaces the extra data of the existing WantAgent with that of the new object. + * This flag is valid only when OperationType is set to START_ABILITY, START_SERVICE, or SEND_COMMON_EVENT. + */ UPDATE_PRESENT_FLAG, + + /** + * Indicates that the created WantAgent should be immutable. + */ CONSTANT_FLAG, + + /** + * Indicates that the current value of element can be replaced when the WantAgent is triggered. + */ REPLACE_ELEMENT, + + /** + * Indicates that the current value of action can be replaced when the WantAgent is triggered. + */ REPLACE_ACTION, + + /** + * Indicates that the current value of uri can be replaced when the WantAgent is triggered. + */ REPLACE_URI, + + /** + * Indicates that the current value of entities can be replaced when the WantAgent is triggered. + */ REPLACE_ENTITIES, + + /** + * Indicates that the current value of packageName can be replaced when the WantAgent is triggered. + */ REPLACE_BUNDLE } /** - * Identifies the operation for using an {@link WantAgent}, such as starting an ability or sending a common event. - * - * @since 7 + * Identifies the operation for using a WantAgent, such as starting an ability or sending a common event. */ export enum OperationType { + /** + * Unknown operation. + */ UNKNOWN_TYPE = 0, + + /** + * Starts an ability with a UI. + */ START_ABILITY, + + /** + * Starts multiple abilities with a UI. + */ START_ABILITIES, + + /** + * Starts an ability without a UI. + */ START_SERVICE, + + /** + * Sends a common event. + */ SEND_COMMON_EVENT } /** - * A callback for the {@link trigger()} method. After the method execution is complete, - * the callback process will start. - * - * @since 7 + * Describes the data returned by after wantAgent.trigger is called. */ export interface CompleteData { + /** + * Triggered WantAgent. + */ info: WantAgent; + + /** + * Existing Want that is triggered. + */ want: Want; + + /** + * Request code used to trigger the WantAgent. + */ finalCode: number; + + /** + * Final data collected by the common event. + */ finalData: string; + + /** + * Extra data collected by the common event. + */ extraInfo?: {[key: string]: any}; } } +/** + * WantAgent object. + */ export type WantAgent = object; export default wantAgent; \ No newline at end of file diff --git a/interfaces/kits/js/notification/notificationActionButton.ts b/interfaces/kits/js/notification/notificationActionButton.d.ts similarity index 83% rename from interfaces/kits/js/notification/notificationActionButton.ts rename to interfaces/kits/js/notification/notificationActionButton.d.ts index 140215050e83fcd221ae81a436d28b747f233353..39cc3db49ea37fe7a708c51f36b0854e14ce90a9 100644 --- a/interfaces/kits/js/notification/notificationActionButton.ts +++ b/interfaces/kits/js/notification/notificationActionButton.d.ts @@ -16,15 +16,26 @@ import { WantAgent } from '../@ohos.wantAgent'; /** - * The action button of notification + * Describes an action button displayed in a notification. * @name NotificationActionButton * @since 7 - * @sysCap SystemCapability.Notification.ANS * @devices phone, tablet, tv, wearable, car * @permission N/A + * @sysCap SystemCapability.Notification.ANS */ export interface NotificationActionButton { + /** + * Button title. + */ title: string; + + /** + * WantAgent of the button. + */ wantAgent: WantAgent; + + /** + * Extra information of the button. + */ extras?: {[key: string]: any}; } diff --git a/interfaces/kits/js/notification/notificationContent.d.ts b/interfaces/kits/js/notification/notificationContent.d.ts index 7624cd304a6e7b08d1852f62296c449a32597e3e..d2cc36ebdc6e98670dfc6dc78c3071da0564e4f5 100644 --- a/interfaces/kits/js/notification/notificationContent.d.ts +++ b/interfaces/kits/js/notification/notificationContent.d.ts @@ -15,9 +15,8 @@ import notification from '../@ohos.notification'; import image from './@ohos.multimedia.image'; - /** - * Constructs basic notifications. + * Describes a normal text notification. * * @name NotificationBasicContent * @since 7 @@ -26,13 +25,24 @@ import image from './@ohos.multimedia.image'; * @permission N/A */ export interface NotificationBasicContent { + /** + * Title of the normal text notification. + */ title: string; + + /** + * Content of the normal text notification. + */ text: string; + + /** + * Additional information of the normal text notification. + */ additionalText?: string; } /** - * Constructs notifications that include long text. The long text contains a maximum of 1024 characters. + * Describes a long text notification. * * @name NotificationLongTextContent * @since 7 @@ -41,13 +51,24 @@ export interface NotificationBasicContent { * @permission N/A */ export interface NotificationLongTextContent extends NotificationBasicContent { + /** + * Long text content of the notification. + */ longText: string; + + /** + * Brief text of the long text notification. + */ briefText: string; + + /** + * Title that will be displayed for the long text notification when it is expanded. + */ expandedTitle: string; } /** - * Constructs a notification that includes multiple lines of text. + * Describes a multi-line text notification. * * @name NotificationMultiLineContent * @since 7 @@ -56,13 +77,24 @@ export interface NotificationLongTextContent extends NotificationBasicContent { * @permission N/A */ export interface NotificationMultiLineContent extends NotificationBasicContent { + /** + * Brief text of the multi-line text notification. + */ briefText: string; + + /** + * Brief text of the multi-line text notification. + */ longTitle: string; + + /** + * Multi-line content of the multi-line text notification. + */ lines: Array; } /** - * Constructs a notification that includes a picture. + * Describes a picture-attached notification. * * @name NotificationPictureContent * @since 7 @@ -71,13 +103,24 @@ export interface NotificationMultiLineContent extends NotificationBasicContent { * @permission N/A */ export interface NotificationPictureContent extends NotificationBasicContent { + /** + * Multi-line content of the multi-line text notification. + */ briefText: string; + + /** + * Title that will be displayed for the picture-attached notification when it is expanded. + */ expandedTitle: string; + + /** + * Picture to be included in a notification. + */ picture: image.PixelMap; } /** - * Constructs a notification. + * Describes notification types. * * @name NotificationContent * @since 7 @@ -86,9 +129,28 @@ export interface NotificationPictureContent extends NotificationBasicContent { * @permission N/A */ export interface NotificationContent { + /** + * Notification content type. + */ contentType: notification.ContentType; + + /** + * Normal text notification. + */ normal?: NotificationBasicContent; + + /** + * Long text notification. + */ longText?: NotificationLongTextContent; + + /** + * Multi-line text notification. + */ multiLine?: NotificationMultiLineContent; + + /** + * Picture-attached notification. + */ picture?: NotificationPictureContent; } diff --git a/interfaces/kits/js/notification/notificationRequest.d.ts b/interfaces/kits/js/notification/notificationRequest.d.ts index f3e2657fe0b4ed4e0a8d7162e568f16c6b2c0c46..b7e6575057d9b8eaf3e11c0bf7ab21d13628bf5f 100644 --- a/interfaces/kits/js/notification/notificationRequest.d.ts +++ b/interfaces/kits/js/notification/notificationRequest.d.ts @@ -20,7 +20,7 @@ import { NotificationContent } from './notificationContent'; import { NotificationActionButton } from './notificationActionButton'; /** - * Carries notifications. + * Defines a NotificationRequest instance. * * @name NotificationRequest * @since 7 @@ -29,44 +29,140 @@ import { NotificationActionButton } from './notificationActionButton'; * @permission N/A */ export interface NotificationRequest { + /** + * Notification content. + */ content: NotificationContent; + + /** + * Notification ID. + */ id?: number; + + /** + * Notification slot type. + */ slotType?: notification.SlotType; + + /** + * Whether the notification is an ongoing notification. + */ isOngoing?: boolean; + + /** + * Whether the notification can be removed. + */ isUnremovable?: boolean; + + /** + * Time when the notification is sent. + */ deliveryTime?: number; + + /** + * Whether the notification is automatically cleared. + */ tapDismissed?: boolean; + + /** + * Time when the notification is automatically cleared. + */ autoDeletedTime?: number; + + /** + * WantAgent instance to which the notification will be redirected after being clicked. + */ wantAgent?: WantAgent; + + /** + * Extended parameter. + */ extraInfo?: {[key: string]: any}; + + /** + * Background color of the notification. + */ color?: number; + + /** + * Whether the notification background color can be enabled. + */ colorEnabled?: boolean; + + /** + * Whether the notification triggers an alert only once. + */ isAlertOnce?: boolean; + + /** + * Whether to display the stopwatch. + */ isStopwatch?: boolean; + + /** + * Whether to display the countdown time. + */ isCountDown?: boolean; + + /** + * Whether the notification is displayed as a floating icon. + */ isFloatingIcon?: boolean; + + /** + * Notification label. + */ label?: string; + + /** + * Notification badge type. + */ badgeIconStyle?: number; + + /** + * Whether to display the time when the notification is delivered. + */ showDeliveryTime?: boolean; + + /** + * Buttons in the notification. Up to two buttons are allowed. + */ actionButtons?: Array; + + /** + * Small notification icon. + */ smallIcon?: image.PixelMap; + + /** + * Large notification icon. + */ largeIcon?: image.PixelMap; + + /** + * Read-only name of the package for which a notification is created. + */ readonly creatorBundleName?: string; + + /** + * Read-only UID of the notification creator. + */ readonly creatorUid?: number; + + /** + * Read-only PID of the notification creator. + */ readonly creatorPid?: number; /** * Obtains the classification of this notification. * * @systemapi Hide this for inner system use. - * @since 7 */ classification?: string; /** * Obtains the unique hash code of a notification in the current application. - * - * @since 7 */ readonly hashCode?: string; } diff --git a/interfaces/kits/js/notification/notificationSlot.d.ts b/interfaces/kits/js/notification/notificationSlot.d.ts index 56f987e69eecab5a125c9ba077f6c5d27153ba18..82ff360f74f57ce33f6749c346ba2e29f15019eb 100644 --- a/interfaces/kits/js/notification/notificationSlot.d.ts +++ b/interfaces/kits/js/notification/notificationSlot.d.ts @@ -16,89 +16,67 @@ import notification from '../@ohos.notification'; /** - * A constructor used to initialize the type, desc, and level of a {@code NotificationSlot} object. + * Describes a NotificationSlot instance. * * @name NotificationSlot * @since 7 - * @sysCap SystemCapability.Notification.ANS * @devices phone, tablet, tv, wearable, car * @permission N/A + * @sysCap SystemCapability.Notification.ANS */ export interface NotificationSlot { /** * Obtains the type of a notification slot. - * - * @since 7 */ type: notification.SlotType; /** * Obtains the level of a notification slot - * - * @since 7 */ level?: notification.SlotLevel; /** * Obtains the description of a notification slot. - * - * @since 7 */ desc?: string; /** * Obtains the application icon badge status of a notification slot. - * - * @since 7 */ badgeFlag?: boolean; /** * Obtains whether DND mode is bypassed for a notification slot. - * - * @since 7 */ bypassDnd?: boolean; /** * Whether and how to display notifications on the lock screen. - * - * @since 7 */ lockscreenVisibility?: number; /** * Obtains the vibration status of the notification slot. - * - * @since 7 */ vibrationEnabled?: boolean; /** * Obtains the prompt tone of the notification slot. - * - * @since 7 */ sound?: string; /** * Obtains whether the notification light is enabled in a notification slot. - * - * @since 7 */ lightEnabled?: boolean; /** * Obtains the color of the notification light in a notification slot. - * - * @since 7 */ lightColor?: number; /** * Obtains the vibration style of notifications in this notification slot. - * - * @since 7 */ vibrationValues?: Array; } diff --git a/interfaces/kits/js/notification/notificationSubscribeInfo.ts b/interfaces/kits/js/notification/notificationSubscribeInfo.d.ts similarity index 100% rename from interfaces/kits/js/notification/notificationSubscribeInfo.ts rename to interfaces/kits/js/notification/notificationSubscribeInfo.d.ts diff --git a/interfaces/kits/js/wantAgent/triggerInfo.d.ts b/interfaces/kits/js/wantAgent/triggerInfo.d.ts index 20dfdeab1fc8bd7d13e886209198ea49f4e91f14..8cd951dce9dd5e01050781527b93b30a26b1c32f 100644 --- a/interfaces/kits/js/wantAgent/triggerInfo.d.ts +++ b/interfaces/kits/js/wantAgent/triggerInfo.d.ts @@ -16,7 +16,7 @@ import { Want } from '../ability/want'; /** - * the info when object of WantAgent trigger + * Provides the information required for triggering a WantAgent. * * @name TriggerInfo * @since 7 @@ -24,8 +24,30 @@ import { Want } from '../ability/want'; * @permission N/A */ export interface TriggerInfo { + /** + * Result code. + */ code: number; + + /** + * Extra Want. + * If flags in WantAgentInfo contain CONSTANT_FLAG, this parameter is invalid. + * If flags contain REPLACE_ELEMENT, REPLACE_ACTION, REPLACE_URI, REPLACE_ENTITIES, and REPLACE_BUNDLE, + * the element, action, uri, entities, and bundleName attributes of the Want specified in this parameter + * will be used to replace the corresponding attributes in the original Want, respectively. + * If this parameter is null, the original Want remains unchanged. + */ want?: Want; + + /** + * Permission required for a WantAgent recipient. + * This parameter is valid only when the WantAgent is triggered to send common events. + * If permission is null, no permission is required on the recipient. + */ permission?: string; + + /** + * Custom extra data you want to add for triggering a WantAgent. + */ extraInfo?: {[key: string]: any}; } \ No newline at end of file diff --git a/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts b/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts index d4d1c8705268dabffb6e72240f02633426371da3..f33531d327fef0445af7e2609cd3fb924ded1971 100644 --- a/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts +++ b/interfaces/kits/js/wantAgent/wantAgentInfo.d.ts @@ -17,7 +17,7 @@ import { Want } from '../ability/want'; import wantAgent from '../@ohos.wantAgent' /** - * the info of WantAgent + * Provides the information required for triggering a WantAgent. * * @name WantAgentInfo * @since 7 @@ -25,9 +25,29 @@ import wantAgent from '../@ohos.wantAgent' * @permission N/A */ export interface WantAgentInfo { + /** + * An array of all Wants for starting abilities or sending common events. Only Wants can be displayed. + */ wants: Array; + + /** + * Type of the action specified in a Want. + */ operationType: wantAgent.OperationType; + + /** + * Request code defined by the user. + */ requestCode: number; + + /** + * An array of flags for using the WantAgent. + */ wantAgentFlags?: Array; + + /** + * Extra information about how the Want starts an ability. + * If there is no extra information to set, this constant can be left empty. + */ extraInfo?: {[key: string]: any}; } \ No newline at end of file diff --git a/interfaces/kits/napi/ans/include/common.h b/interfaces/kits/napi/ans/include/common.h index c95b1a1fd6bca235521eda6a00a4cf9db5b24837..94f053a3e5607345c648da912fcc155c467a22b2 100644 --- a/interfaces/kits/napi/ans/include/common.h +++ b/interfaces/kits/napi/ans/include/common.h @@ -29,16 +29,15 @@ const std::int32_t LONG_STR_MAX_SIZE = 1024; const int NO_ERROR = 0; const int ERROR = -1; -enum ContentType { +enum class ContentType { NOTIFICATION_CONTENT_BASIC_TEXT, NOTIFICATION_CONTENT_LONG_TEXT, NOTIFICATION_CONTENT_PICTURE, NOTIFICATION_CONTENT_CONVERSATION, - NOTIFICATION_CONTENT_MULTILINE, - NOTIFICATION_CONTENT_MEDIA + NOTIFICATION_CONTENT_MULTILINE }; -enum SlotType { +enum class SlotType { UNKNOWN_TYPE = 0, SOCIAL_COMMUNICATION = 1, SERVICE_INFORMATION = 2, @@ -46,7 +45,7 @@ enum SlotType { OTHER_TYPES = 0xFFFF, }; -enum SlotLevel { +enum class SlotLevel { LEVEL_NONE = 0, LEVEL_MIN = 1, LEVEL_LOW = 2, @@ -54,7 +53,7 @@ enum SlotLevel { LEVEL_HIGH = 4, }; -enum NotificationReason { +enum class NotificationReason { CLICK_REASON_DELETE, CANCEL_REASON_DELETE, CANCEL_ALL_REASON_DELETE, @@ -67,7 +66,7 @@ enum NotificationReason { APP_CANCEL_REASON_OTHER }; -enum SemanticActionButton { +enum class SemanticActionButton { NONE_ACTION_BUTTON, REPLY_ACTION_BUTTON, READ_ACTION_BUTTON, @@ -81,13 +80,35 @@ enum SemanticActionButton { CALL_ACTION_BUTTON }; -enum InputsSource { FREE_FORM_INPUT, OPTION }; +enum class InputsSource { + FREE_FORM_INPUT, + OPTION +}; + +enum class DisturbMode { + ALLOW_UNKNOWN, + ALLOW_ALL, + ALLOW_PRIORITY, + ALLOW_NONE, + ALLOW_ALARMS +}; -enum DisturbMode { ALLOW_UNKNOWN, ALLOW_ALL, ALLOW_PRIORITY, ALLOW_NONE, ALLOW_ALARMS }; +enum class InputEditType { + EDIT_AUTO, + EDIT_DISABLED, + EDIT_ENABLED +}; -enum InputEditType { EDIT_AUTO, EDIT_DISABLED, EDIT_ENABLED }; +enum class DoNotDisturbType { + TYPE_NONE, TYPE_ONCE, + TYPE_DAILY, TYPE_CLEARLY +}; -enum DoNotDisturbType { TYPE_NONE, TYPE_ONCE, TYPE_DAILY, TYPE_CLEARLY }; +enum class SourceType { + TYPE_NORMAL = 0x00000000, + TYPE_CONTINUOUS = 0x00000001, + TYPE_TIMER = 0x00000002 +}; struct NotificationSubscribeInfo { std::vector bundleNames; @@ -96,13 +117,13 @@ struct NotificationSubscribeInfo { }; struct BundleOption { - std::string bundle{}; - int uid{}; + std::string bundle {}; + int uid {}; }; struct NotificationKey { - int id{}; - std::string label{}; + int id {}; + std::string label {}; }; struct CallbackPromiseInfo { @@ -118,7 +139,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 +166,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 +193,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 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 +229,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,18 +285,103 @@ 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 GetNotificationSlotByVibration( + 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); static napi_value GetNotificationKey(const napi_env &env, const napi_value &value, NotificationKey &key); - static bool ContentTypeJSToC(const enum ContentType &inType, enum NotificationContent::Type &outType); + static bool ContentTypeJSToC(const ContentType &inType, NotificationContent::Type &outType); - static bool ContentTypeCToJS(const enum NotificationContent::Type &inType, enum ContentType &outType); + static bool ContentTypeCToJS(const NotificationContent::Type &inType, ContentType &outType); - static bool SlotTypeJSToC(const enum SlotType &inType, enum NotificationConstant::SlotType &outType); + static bool SlotTypeJSToC(const SlotType &inType, NotificationConstant::SlotType &outType); - static bool SlotTypeCToJS(const enum NotificationConstant::SlotType &inType, enum SlotType &outType); + static bool SlotTypeCToJS(const NotificationConstant::SlotType &inType, SlotType &outType); static bool SlotLevelJSToC(const SlotLevel &inLevel, NotificationSlot::NotificationLevel &outLevel); @@ -223,6 +393,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 0db4a1946b8e9ed04e5478835fa4df96c219ce03..3e67eac60b6fafeeffa7abf9111fa1eabf69f6fc 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 + SourceType sourceType = SourceType::TYPE_NORMAL; + if (!SourceTypeCToJS(notification->GetSourceType(), sourceType)) { + return NapiGetBoolean(env, false); + } + napi_create_int32(env, (int32_t)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 @@ -291,13 +270,52 @@ napi_value Common::SetNotificationRequest( napi_set_named_property(env, result, "id", value); // slotType?: SlotType - enum SlotType outType = SlotType::UNKNOWN_TYPE; + 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_create_int32(env, (int32_t)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); +} - 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); } 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) @@ -563,19 +620,19 @@ napi_value Common::SetNotificationSlot(const napi_env &env, const NotificationSl napi_value value = nullptr; // type: SlotType - enum SlotType outType = SlotType::UNKNOWN_TYPE; + 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_create_int32(env, (int32_t)outType, &value); napi_set_named_property(env, result, "type", value); // level?: number - enum SlotLevel outLevel { SlotLevel::LEVEL_NONE }; + 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_create_int32(env, (int32_t)outLevel, &value); napi_set_named_property(env, result, "level", value); // desc?: string @@ -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 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,46 +1105,142 @@ 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( const napi_env &env, const NotificationDoNotDisturbDate &date, napi_value &result) { 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); + DoNotDisturbType outType = DoNotDisturbType::TYPE_NONE; + if (!DoNotDisturbTypeCToJS(date.GetDoNotDisturbType(), outType)) { + return NapiGetBoolean(env, false); } - return NapiGetboolean(env, true); + + // type:DoNotDisturbType + napi_value typeNapi = nullptr; + napi_create_int32(env, (int32_t)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"); @@ -1258,17 +1473,18 @@ napi_value GetSlotType(const napi_env &env, const napi_value &value, Notificatio NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); napi_get_value_int32(env, result, &slotType); - enum NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; - if (!Common::SlotTypeJSToC(SlotType(slotType), outType)) { + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + 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,60 +2116,368 @@ 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)); + // 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; + } + + 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, userInputResult, "tag", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); + userInput->SetTag(str); + ANS_LOGI("NotificationUserInput::tag = %{public}s", str); + } + + return NapiGetNull(env); +} + +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; + } + + // options: Array + NAPI_CALL(env, napi_has_named_property(env, userInputResult, "options", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, userInputResult, "options", &value); + napi_is_array(env, value, &isArray); + NAPI_ASSERT(env, isArray, "Property options is expected to be an array."); + napi_get_array_length(env, value, &length); + NAPI_ASSERT(env, length > 0, "The array is empty."); + std::vector options; + for (uint32_t i = 0; i < length; ++i) { + napi_value option = nullptr; + char str[STR_MAX_SIZE] = {0}; + napi_get_element(env, value, i, &option); + NAPI_CALL(env, napi_typeof(env, option, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, option, str, STR_MAX_SIZE - 1, &strLen)); + options.emplace_back(str); + } + userInput->SetOptions(options); + } + 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(); @@ -1958,62 +2486,68 @@ napi_value GetNotificationBasicContent(const napi_env &env, const napi_value &re 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)); - normalContent->SetTitle(str); - ANS_LOGI("normal::title = %{public}s", str); - } else { - ANS_LOGE("Property title expected."); + 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)); - 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."); - return nullptr; - } + 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,351 +2563,385 @@ 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."); + 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)); + 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)); + 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 NapiGetNull(env); +} + +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; + bool hasProperty = false; + + NAPI_CALL(env, napi_has_named_property(env, result, "picture", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property picture expected."); + napi_get_named_property(env, result, "picture", &contentResult); + NAPI_CALL(env, napi_typeof(env, contentResult, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + + std::shared_ptr pictureContent = + std::make_shared(); + if (pictureContent == nullptr) { + ANS_LOGE("pictureContent is null"); + return nullptr; + } + if (GetNotificationPictureContentDetailed(env, contentResult, pictureContent) == nullptr) { + return nullptr; + } + + 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; } // 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", &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)); - 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."); + 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; } - - request.SetContent(std::make_shared(longContent)); + pictureContent->SetBigPicture(pixelMap); return Common::NapiGetNull(env); } -napi_value GetNotificationPictureContent(const napi_env &env, const napi_value &result, NotificationRequest &request) +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; - napi_value pictureContentResult = 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, "picture", &hasProperty)); - NAPI_ASSERT(env, hasProperty, "Property picture expected."); - napi_get_named_property(env, result, "picture", &contentResult); + 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."); - std::shared_ptr pictureContent = - std::make_shared(); - if (pictureContent == nullptr) { - ANS_LOGE("pictureContent is null"); + if (GetNotificationConversationalContentByUser(env, contentResult, user) == 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."); + std::shared_ptr conversationalContent = + std::make_shared(user); + if (conversationalContent == nullptr) { + ANS_LOGE("conversationalContent is null"); 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."); + if (GetNotificationBasicContentDetailed(env, contentResult, conversationalContent) == 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)); - pictureContent->SetAdditionalText(str); - ANS_LOGI("pictureText::additionalText = %{public}s", str); + if (GetNotificationConversationalContentTitle(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 (GetNotificationConversationalContentGroup(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 (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); + + // 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); + + return NapiGetNull(env); +} - std::shared_ptr conversationalContent = - std::make_shared(user); - if (conversationalContent == nullptr) { - ANS_LOGE("conversationalContent is null"); - return nullptr; - } +napi_value Common::GetMessageUserByBool(const napi_env &env, const napi_value &result, MessageUser &messageUser) +{ + ANS_LOGI("enter"); - // 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; - } + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; - // 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; - } + // 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); - // 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); - } + return NapiGetNull(env); +} - // 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; - } +napi_value Common::GetMessageUserByCustom(const napi_env &env, const napi_value &result, MessageUser &messageUser) +{ + ANS_LOGI("enter"); - // 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; - } + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; - // messages: Array - NAPI_CALL(env, napi_has_named_property(env, contentResult, "messages", &hasProperty)); + // 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,17 +3173,16 @@ 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; @@ -2709,28 +3192,35 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va 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)) { + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + if (!Common::SlotTypeJSToC(SlotType(slotType), outType)) { return nullptr; } slot.SetType(outType); - // 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 (!SlotLevelJSToC(SlotLevel(inLevel), outLevel)) { - return nullptr; - } - slot.SetLevel(outLevel); + if (GetNotificationSlotByString(env, value, slot) == nullptr) { + return nullptr; + } + if (GetNotificationSlotByNumber(env, value, slot) == nullptr) { + return nullptr; + } + if (GetNotificationSlotByVibration(env, value, slot) == nullptr) { + return nullptr; + } + if (GetNotificationSlotByBool(env, value, slot) == nullptr) { + return nullptr; } + return NapiGetNull(env); +} + +napi_value Common::GetNotificationSlotByString(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; // desc?: string NAPI_CALL(env, napi_has_named_property(env, value, "desc", &hasProperty)); @@ -2746,6 +3236,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 +3284,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 +3296,46 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va slot.SetEnableLight(lightEnabled); } + 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 +3347,16 @@ 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::GetNotificationSlotByVibration(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; // vibrationValues?: Array NAPI_CALL(env, napi_has_named_property(env, value, "vibrationValues", &hasProperty)); @@ -2920,7 +3458,7 @@ napi_value Common::GetNotificationKey(const napi_env &env, const napi_value &val return NapiGetNull(env); } -bool Common::ContentTypeJSToC(const enum ContentType &inType, enum NotificationContent::Type &outType) +bool Common::ContentTypeJSToC(const ContentType &inType, NotificationContent::Type &outType) { switch (inType) { case ContentType::NOTIFICATION_CONTENT_BASIC_TEXT: @@ -2935,6 +3473,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; @@ -2942,7 +3483,7 @@ bool Common::ContentTypeJSToC(const enum ContentType &inType, enum NotificationC return true; } -bool Common::ContentTypeCToJS(const enum NotificationContent::Type &inType, enum ContentType &outType) +bool Common::ContentTypeCToJS(const NotificationContent::Type &inType, ContentType &outType) { switch (inType) { case NotificationContent::Type::BASIC_TEXT: @@ -2957,6 +3498,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; @@ -2964,7 +3508,7 @@ bool Common::ContentTypeCToJS(const enum NotificationContent::Type &inType, enum return true; } -bool Common::SlotTypeJSToC(const enum SlotType &inType, enum NotificationConstant::SlotType &outType) +bool Common::SlotTypeJSToC(const SlotType &inType, NotificationConstant::SlotType &outType) { switch (inType) { case SlotType::SOCIAL_COMMUNICATION: @@ -2987,7 +3531,7 @@ bool Common::SlotTypeJSToC(const enum SlotType &inType, enum NotificationConstan return true; } -bool Common::SlotTypeCToJS(const enum NotificationConstant::SlotType &inType, enum SlotType &outType) +bool Common::SlotTypeCToJS(const NotificationConstant::SlotType &inType, SlotType &outType) { switch (inType) { case NotificationConstant::SlotType::CUSTOM: @@ -3067,31 +3611,31 @@ bool Common::ReasonCToJS(const int &inType, int &outType) { switch (inType) { case NotificationConstant::CLICK_REASON_DELETE: - outType = NotificationReason::CLICK_REASON_DELETE; + outType = (int)NotificationReason::CLICK_REASON_DELETE; break; case NotificationConstant::CANCEL_REASON_DELETE: - outType = NotificationReason::CANCEL_REASON_DELETE; + outType = (int)NotificationReason::CANCEL_REASON_DELETE; break; case NotificationConstant::CANCEL_ALL_REASON_DELETE: - outType = NotificationReason::CANCEL_ALL_REASON_DELETE; + outType = (int)NotificationReason::CANCEL_ALL_REASON_DELETE; break; case NotificationConstant::ERROR_REASON_DELETE: - outType = NotificationReason::ERROR_REASON_DELETE; + outType = (int)NotificationReason::ERROR_REASON_DELETE; break; case NotificationConstant::PACKAGE_CHANGED_REASON_DELETE: - outType = NotificationReason::PACKAGE_CHANGED_REASON_DELETE; + outType = (int)NotificationReason::PACKAGE_CHANGED_REASON_DELETE; break; case NotificationConstant::USER_STOPPED_REASON_DELETE: - outType = NotificationReason::USER_STOPPED_REASON_DELETE; + outType = (int)NotificationReason::USER_STOPPED_REASON_DELETE; break; case NotificationConstant::APP_CANCEL_REASON_DELETE: - outType = NotificationReason::APP_CANCEL_REASON_DELETE; + outType = (int)NotificationReason::APP_CANCEL_REASON_DELETE; break; case NotificationConstant::APP_CANCEL_ALL_REASON_DELETE: - outType = NotificationReason::APP_CANCEL_ALL_REASON_DELETE; + outType = (int)NotificationReason::APP_CANCEL_ALL_REASON_DELETE; break; case NotificationConstant::APP_CANCEL_REASON_OTHER: - outType = NotificationReason::APP_CANCEL_REASON_OTHER; + outType = (int)NotificationReason::APP_CANCEL_REASON_OTHER; break; default: ANS_LOGE("Reason %{public}d is an invalid value", inType); @@ -3144,6 +3688,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_CONTINUOUS: + outType = SourceType::TYPE_CONTINUOUS; + 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 +3752,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 e3946a9768bf9e92c747034df8497a0c37bc6e4c..96e3e4219c91e44422b9dafd44cc1354fb038404 100644 --- a/interfaces/kits/napi/ans/src/constant.cpp +++ b/interfaces/kits/napi/ans/src/constant.cpp @@ -35,19 +35,23 @@ napi_value NotificationReasonInit(napi_env env, napi_value exports) napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, NotificationReason::CLICK_REASON_DELETE, "CLICK_REASON_DELETE"); - SetNamedPropertyByInteger(env, obj, NotificationReason::CANCEL_REASON_DELETE, "CANCEL_REASON_DELETE"); - SetNamedPropertyByInteger(env, obj, NotificationReason::CANCEL_ALL_REASON_DELETE, "CANCEL_ALL_REASON_DELETE"); - SetNamedPropertyByInteger(env, obj, NotificationReason::ERROR_REASON_DELETE, "ERROR_REASON_DELETE"); + SetNamedPropertyByInteger(env, obj, (int32_t)NotificationReason::CLICK_REASON_DELETE, "CLICK_REASON_DELETE"); + SetNamedPropertyByInteger(env, obj, (int32_t)NotificationReason::CANCEL_REASON_DELETE, "CANCEL_REASON_DELETE"); SetNamedPropertyByInteger( - env, obj, NotificationReason::PACKAGE_CHANGED_REASON_DELETE, "PACKAGE_CHANGED_REASON_DELETE"); - SetNamedPropertyByInteger(env, obj, NotificationReason::USER_STOPPED_REASON_DELETE, "USER_STOPPED_REASON_DELETE"); + env, obj, (int32_t)NotificationReason::CANCEL_ALL_REASON_DELETE, "CANCEL_ALL_REASON_DELETE"); + SetNamedPropertyByInteger(env, obj, (int32_t)NotificationReason::ERROR_REASON_DELETE, "ERROR_REASON_DELETE"); SetNamedPropertyByInteger( - env, obj, NotificationReason::PACKAGE_BANNED_REASON_DELETE, "PACKAGE_BANNED_REASON_DELETE"); - SetNamedPropertyByInteger(env, obj, NotificationReason::APP_CANCEL_REASON_DELETE, "APP_CANCEL_REASON_DELETE"); + env, obj, (int32_t)NotificationReason::PACKAGE_CHANGED_REASON_DELETE, "PACKAGE_CHANGED_REASON_DELETE"); SetNamedPropertyByInteger( - env, obj, NotificationReason::APP_CANCEL_ALL_REASON_DELETE, "APP_CANCEL_ALL_REASON_DELETE"); - SetNamedPropertyByInteger(env, obj, NotificationReason::APP_CANCEL_REASON_OTHER, "APP_CANCEL_REASON_OTHER"); + env, obj, (int32_t)NotificationReason::USER_STOPPED_REASON_DELETE, "USER_STOPPED_REASON_DELETE"); + SetNamedPropertyByInteger( + env, obj, (int32_t)NotificationReason::PACKAGE_BANNED_REASON_DELETE, "PACKAGE_BANNED_REASON_DELETE"); + SetNamedPropertyByInteger( + env, obj, (int32_t)NotificationReason::APP_CANCEL_REASON_DELETE, "APP_CANCEL_REASON_DELETE"); + SetNamedPropertyByInteger( + env, obj, (int32_t)NotificationReason::APP_CANCEL_ALL_REASON_DELETE, "APP_CANCEL_ALL_REASON_DELETE"); + SetNamedPropertyByInteger( + env, obj, (int32_t)NotificationReason::APP_CANCEL_REASON_OTHER, "APP_CANCEL_REASON_OTHER"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("NotificationReason", obj), @@ -64,11 +68,11 @@ napi_value SlotTypeInit(napi_env env, napi_value exports) napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, SlotType::UNKNOWN_TYPE, "UNKNOWN_TYPE"); - SetNamedPropertyByInteger(env, obj, SlotType::SOCIAL_COMMUNICATION, "SOCIAL_COMMUNICATION"); - SetNamedPropertyByInteger(env, obj, SlotType::SERVICE_INFORMATION, "SERVICE_INFORMATION"); - SetNamedPropertyByInteger(env, obj, SlotType::CONTENT_INFORMATION, "CONTENT_INFORMATION"); - SetNamedPropertyByInteger(env, obj, SlotType::OTHER_TYPES, "OTHER_TYPES"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::UNKNOWN_TYPE, "UNKNOWN_TYPE"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::SOCIAL_COMMUNICATION, "SOCIAL_COMMUNICATION"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::SERVICE_INFORMATION, "SERVICE_INFORMATION"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::CONTENT_INFORMATION, "CONTENT_INFORMATION"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::OTHER_TYPES, "OTHER_TYPES"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("SlotType", obj), @@ -85,11 +89,11 @@ napi_value SlotLevelInit(napi_env env, napi_value exports) napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, SlotLevel::LEVEL_NONE, "LEVEL_NONE"); - SetNamedPropertyByInteger(env, obj, SlotLevel::LEVEL_MIN, "LEVEL_MIN"); - SetNamedPropertyByInteger(env, obj, SlotLevel::LEVEL_LOW, "LEVEL_LOW"); - SetNamedPropertyByInteger(env, obj, SlotLevel::LEVEL_DEFAULT, "LEVEL_DEFAULT"); - SetNamedPropertyByInteger(env, obj, SlotLevel::LEVEL_HIGH, "LEVEL_HIGH"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_NONE, "LEVEL_NONE"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_MIN, "LEVEL_MIN"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_LOW, "LEVEL_LOW"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_DEFAULT, "LEVEL_DEFAULT"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotLevel::LEVEL_HIGH, "LEVEL_HIGH"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("SlotLevel", obj), @@ -106,17 +110,24 @@ napi_value SemanticActionButtonInit(napi_env env, napi_value exports) napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::NONE_ACTION_BUTTON, "NONE_ACTION_BUTTON"); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::REPLY_ACTION_BUTTON, "REPLY_ACTION_BUTTON"); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::READ_ACTION_BUTTON, "READ_ACTION_BUTTON"); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::UNREAD_ACTION_BUTTON, "UNREAD_ACTION_BUTTON"); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::DELETE_ACTION_BUTTON, "DELETE_ACTION_BUTTON"); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::ARCHIVE_ACTION_BUTTON, "ARCHIVE_ACTION_BUTTON"); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::MUTE_ACTION_BUTTON, "MUTE_ACTION_BUTTON"); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::UNMUTE_ACTION_BUTTON, "UNMUTE_ACTION_BUTTON"); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::THUMBS_UP_ACTION_BUTTON, "THUMBS_UP_ACTION_BUTTON"); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::THUMBS_DOWN_ACTION_BUTTON, "THUMBS_DOWN_ACTION_BUTTON"); - SetNamedPropertyByInteger(env, obj, SemanticActionButton::CALL_ACTION_BUTTON, "CALL_ACTION_BUTTON"); + SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::NONE_ACTION_BUTTON, "NONE_ACTION_BUTTON"); + SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::REPLY_ACTION_BUTTON, "REPLY_ACTION_BUTTON"); + SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::READ_ACTION_BUTTON, "READ_ACTION_BUTTON"); + SetNamedPropertyByInteger( + env, obj, (int32_t)SemanticActionButton::UNREAD_ACTION_BUTTON, "UNREAD_ACTION_BUTTON"); + SetNamedPropertyByInteger( + env, obj, (int32_t)SemanticActionButton::DELETE_ACTION_BUTTON, "DELETE_ACTION_BUTTON"); + SetNamedPropertyByInteger( + env, obj, (int32_t)SemanticActionButton::ARCHIVE_ACTION_BUTTON, "ARCHIVE_ACTION_BUTTON"); + SetNamedPropertyByInteger( + env, obj, (int32_t)SemanticActionButton::MUTE_ACTION_BUTTON, "MUTE_ACTION_BUTTON"); + SetNamedPropertyByInteger( + env, obj, (int32_t)SemanticActionButton::UNMUTE_ACTION_BUTTON, "UNMUTE_ACTION_BUTTON"); + SetNamedPropertyByInteger( + env, obj, (int32_t)SemanticActionButton::THUMBS_UP_ACTION_BUTTON, "THUMBS_UP_ACTION_BUTTON"); + SetNamedPropertyByInteger( + env, obj, (int32_t)SemanticActionButton::THUMBS_DOWN_ACTION_BUTTON, "THUMBS_DOWN_ACTION_BUTTON"); + SetNamedPropertyByInteger(env, obj, (int32_t)SemanticActionButton::CALL_ACTION_BUTTON, "CALL_ACTION_BUTTON"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("SemanticActionButton", obj), @@ -133,8 +144,8 @@ napi_value InputsSourceInit(napi_env env, napi_value exports) napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, InputsSource::FREE_FORM_INPUT, "FREE_FORM_INPUT"); - SetNamedPropertyByInteger(env, obj, InputsSource::OPTION, "OPTION"); + SetNamedPropertyByInteger(env, obj, (int32_t)InputsSource::FREE_FORM_INPUT, "FREE_FORM_INPUT"); + SetNamedPropertyByInteger(env, obj, (int32_t)InputsSource::OPTION, "OPTION"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("InputsSource", obj), @@ -151,11 +162,11 @@ napi_value DoNotDisturbMode(napi_env env, napi_value exports) napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, DisturbMode::ALLOW_UNKNOWN, "ALLOW_UNKNOWN"); - SetNamedPropertyByInteger(env, obj, DisturbMode::ALLOW_ALL, "ALLOW_ALL"); - SetNamedPropertyByInteger(env, obj, DisturbMode::ALLOW_PRIORITY, "ALLOW_PRIORITY"); - SetNamedPropertyByInteger(env, obj, DisturbMode::ALLOW_NONE, "ALLOW_NONE"); - SetNamedPropertyByInteger(env, obj, DisturbMode::ALLOW_ALARMS, "ALLOW_ALARMS"); + SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_UNKNOWN, "ALLOW_UNKNOWN"); + SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_ALL, "ALLOW_ALL"); + SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_PRIORITY, "ALLOW_PRIORITY"); + SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_NONE, "ALLOW_NONE"); + SetNamedPropertyByInteger(env, obj, (int32_t)DisturbMode::ALLOW_ALARMS, "ALLOW_ALARMS"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("DoNotDisturbMode", obj), @@ -172,9 +183,9 @@ napi_value InputEditTypeInit(napi_env env, napi_value exports) napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, InputEditType::EDIT_AUTO, "EDIT_AUTO"); - SetNamedPropertyByInteger(env, obj, InputEditType::EDIT_DISABLED, "EDIT_DISABLED"); - SetNamedPropertyByInteger(env, obj, InputEditType::EDIT_ENABLED, "EDIT_ENABLED"); + SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_AUTO, "EDIT_AUTO"); + SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_DISABLED, "EDIT_DISABLED"); + SetNamedPropertyByInteger(env, obj, (int32_t)InputEditType::EDIT_ENABLED, "EDIT_ENABLED"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("InputEditType", obj), @@ -192,13 +203,15 @@ napi_value ContentTypeInit(napi_env env, napi_value exports) napi_create_object(env, &obj); SetNamedPropertyByInteger( - env, obj, ContentType::NOTIFICATION_CONTENT_BASIC_TEXT, "NOTIFICATION_CONTENT_BASIC_TEXT"); - SetNamedPropertyByInteger(env, obj, ContentType::NOTIFICATION_CONTENT_LONG_TEXT, "NOTIFICATION_CONTENT_LONG_TEXT"); - SetNamedPropertyByInteger(env, obj, ContentType::NOTIFICATION_CONTENT_PICTURE, "NOTIFICATION_CONTENT_PICTURE"); + env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_BASIC_TEXT, "NOTIFICATION_CONTENT_BASIC_TEXT"); + SetNamedPropertyByInteger( + env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_LONG_TEXT, "NOTIFICATION_CONTENT_LONG_TEXT"); 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"); + env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_PICTURE, "NOTIFICATION_CONTENT_PICTURE"); + SetNamedPropertyByInteger( + env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_CONVERSATION, "NOTIFICATION_CONTENT_CONVERSATION"); + SetNamedPropertyByInteger( + env, obj, (int32_t)ContentType::NOTIFICATION_CONTENT_MULTILINE, "NOTIFICATION_CONTENT_MULTILINE"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("ContentType", obj), @@ -215,10 +228,10 @@ napi_value DoNotDisturbTypeInit(napi_env env, napi_value exports) napi_value obj = nullptr; napi_create_object(env, &obj); - SetNamedPropertyByInteger(env, obj, DoNotDisturbType::TYPE_NONE, "TYPE_NONE"); - SetNamedPropertyByInteger(env, obj, DoNotDisturbType::TYPE_ONCE, "TYPE_ONCE"); - SetNamedPropertyByInteger(env, obj, DoNotDisturbType::TYPE_DAILY, "TYPE_DAILY"); - SetNamedPropertyByInteger(env, obj, DoNotDisturbType::TYPE_CLEARLY, "TYPE_CLEARLY"); + SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_NONE, "TYPE_NONE"); + SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_ONCE, "TYPE_ONCE"); + SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_DAILY, "TYPE_DAILY"); + SetNamedPropertyByInteger(env, obj, (int32_t)DoNotDisturbType::TYPE_CLEARLY, "TYPE_CLEARLY"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("DoNotDisturbType", obj), @@ -228,6 +241,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, (int32_t)SourceType::TYPE_NORMAL, "TYPE_NORMAL"); + SetNamedPropertyByInteger(env, obj, (int32_t)SourceType::TYPE_CONTINUOUS, "TYPE_CONTINUOUS"); + SetNamedPropertyByInteger(env, obj, (int32_t)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,9 +270,9 @@ 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; } - } // namespace NotificationNapi } // namespace OHOS diff --git a/interfaces/kits/napi/ans/src/subscribe.cpp b/interfaces/kits/napi/ans/src/subscribe.cpp index ee5de8347849bd7932c8ec1155958bf041f56b31..4056542cf186df85f83f758ed58e1e10722ee6b7 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 a476c597b4c3f20b64493933be812933c7b0fc16..921ad9d9ec47dcd05a3d31a9816513c7e36ec052 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 PublishContinuousTaskNotification(const sptr &request) override; + ErrCode CancelContinuousTaskNotification(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 538f26bfa44f8b6954e7bc8cd30969598dd639b2..7cc52336980741f600fd755d238f6d0e121b73bf 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::PublishContinuousTaskNotification(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_CONTINUOUS); + 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::CancelContinuousTaskNotification(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,9 @@ ErrCode AdvancedNotificationService::RemoveNotification( sptr notification = nullptr; for (auto record : notificationList_) { + if (!record->notification->IsRemoveAllowed()) { + continue; + } if ((record->bundleOption->GetBundleName() == bundle->GetBundleName()) && (record->bundleOption->GetUid() == bundleOption->GetUid()) && (record->notification->GetId() == notificationId) && (record->notification->GetLabel() == label)) { @@ -1595,6 +1682,10 @@ ErrCode AdvancedNotificationService::RemoveAllNotifications(const sptrPostSyncTask(std::bind([&]() { std::vector> removeList; for (auto record : notificationList_) { + if (!record->notification->IsRemoveAllowed()) { + continue; + } + if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && (record->bundleOption->GetUid() == bundleOption->GetUid()) && !record->request->IsUnremovable()) { removeList.push_back(record); @@ -1903,5 +1994,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 1d6b79c69be5f98e8574123cde6e13bb8d322f9b..1b51ab08ddc62075d3a0c752815ff85f20f2fa32 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -22,6 +22,7 @@ #define private public #include "advanced_notification_service.h" +#include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" #include "ans_ut_constant.h" @@ -1557,5 +1558,74 @@ 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_->PublishContinuousTaskNotification(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_->PublishContinuousTaskNotification(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_->PublishContinuousTaskNotification(req), (int)ERR_OK); + } + EXPECT_EQ(advancedNotificationService_->CancelContinuousTaskNotification(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_->PublishContinuousTaskNotification(req), (int)ERR_OK); + } + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + EXPECT_EQ( + advancedNotificationService_->CancelContinuousTaskNotification(label, 1), (int)ERR_ANS_NOT_SYSTEM_SERVICE); +} } // namespace Notification -} // namespace OHOS +} // namespace OHOS \ No newline at end of file