From fc9012d68cfadca9f9606c09ed17b117a04a2c10 Mon Sep 17 00:00:00 2001 From: zhaoyuan Date: Wed, 15 Sep 2021 21:47:49 +0000 Subject: [PATCH] update pixelmap and test code Signed-off-by: zhaoyuan --- frameworks/ans/core/BUILD.gn | 2 + .../core/common/include/ans_const_define.h | 2 + .../core/common/include/ans_inner_errors.h | 3 +- .../ans/core/include/ans_manager_proxy.h | 4 +- .../ans/core/include/ans_manager_stub.h | 4 +- .../ans/core/include/ans_notification.h | 7 + frameworks/ans/core/src/ans_manager_proxy.cpp | 4 +- frameworks/ans/core/src/ans_manager_stub.cpp | 4 +- frameworks/ans/core/src/ans_notification.cpp | 106 +++ frameworks/ans/native/BUILD.gn | 2 + frameworks/ans/native/src/message_user.cpp | 35 +- .../native/src/notification_action_button.cpp | 61 +- .../src/notification_picture_content.cpp | 42 +- .../ans/native/src/notification_request.cpp | 92 +-- frameworks/ans/test/moduletest/BUILD.gn | 3 + .../test/moduletest/ans_fw_module_test.cpp | 120 +++- .../ans_innerkits_module_publish_test.cpp | 60 +- .../ans_innerkits_module_slot_test.cpp | 1 - .../moduletest/mock/mock_bundle_manager.cpp | 7 +- .../moduletest/mock/mock_event_handler.cpp | 194 +++-- .../ans/native/include/message_user.h | 9 +- .../include/notification_action_button.h | 11 +- .../include/notification_picture_content.h | 9 +- .../ans/native/include/notification_request.h | 15 +- .../native/include/notification_user_input.h | 2 - interfaces/kits/js/@ohos.notification.d.ts | 82 +-- interfaces/kits/js/@ohos.wantAgent.d.ts | 80 +-- .../notification/notificationActionButton.ts | 7 +- .../js/notification/notificationContent.d.ts | 18 +- .../js/notification/notificationRequest.d.ts | 11 +- .../js/notification/notificationSlot.d.ts | 4 +- .../js/notification/notificationSorting.d.ts | 4 +- .../notification/notificationSortingMap.d.ts | 4 +- .../notification/notificationSubscribeInfo.ts | 4 +- .../notification/notificationSubscriber.d.ts | 24 +- interfaces/kits/napi/ans/BUILD.gn | 2 + interfaces/kits/napi/ans/include/get_active.h | 2 +- interfaces/kits/napi/ans/include/slot.h | 6 +- interfaces/kits/napi/ans/src/common.cpp | 667 ++++++------------ .../kits/napi/ans/src/display_badge.cpp | 4 +- .../kits/napi/ans/src/enable_notification.cpp | 4 +- interfaces/kits/napi/ans/src/get_active.cpp | 10 +- interfaces/kits/napi/ans/src/init.cpp | 8 +- interfaces/kits/napi/ans/src/remove.cpp | 4 +- interfaces/kits/napi/ans/src/slot.cpp | 102 +-- interfaces/kits/napi/ans/src/subscribe.cpp | 54 +- services/ans/BUILD.gn | 1 + .../ans/include/notification_preferences.h | 6 +- .../notification_preferences_database.h | 2 +- .../include/notification_preferences_info.h | 10 +- .../ans/src/advanced_notification_service.cpp | 57 +- services/ans/src/notification_preferences.cpp | 17 +- .../src/notification_preferences_database.cpp | 130 ++-- services/ans/test/unittest/BUILD.gn | 1 + .../advanced_notification_service_test.cpp | 134 +++- .../mock/include/mock_single_kv_store.h | 178 +---- services/ans/test/unittest/mock/mock_ipc.cpp | 2 +- .../unittest/mock/mock_single_kv_store.cpp | 132 +--- services/test/moduletest/BUILD.gn | 1 + services/test/moduletest/ans_module_test.cpp | 60 +- .../mock/distributed_kv_data_manager.cpp | 1 - .../mock/include/mock_single_kv_store.h | 178 +---- .../moduletest/mock/mock_bundle_manager.cpp | 5 +- .../moduletest/mock/mock_bundle_mgr_proxy.cpp | 4 +- .../moduletest/mock/mock_event_handler.cpp | 194 +++-- .../moduletest/mock/mock_single_kv_store.cpp | 165 +---- .../include/ans_slotgroup_test.h | 2 +- .../src/ans_slotgroup_test.cpp | 45 +- tools/dump/src/notification_shell_command.cpp | 23 +- 69 files changed, 1381 insertions(+), 1867 deletions(-) diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index f630d47e4..492968520 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -27,6 +27,7 @@ config("public_ans_core_config") { "${core_path}/include", "${interfaces_path}/innerkits/ans/native/include", "${interfaces_path}/innerkits/wantAgent/include", + "//foundation/multimedia/image_standard/interfaces/innerkits/include", "//utils/native/base/include", "//third_party/jsoncpp/include", ] @@ -74,6 +75,7 @@ ohos_shared_library("ans_core") { "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", ] diff --git a/frameworks/ans/core/common/include/ans_const_define.h b/frameworks/ans/core/common/include/ans_const_define.h index 61e08768b..353899e52 100644 --- a/frameworks/ans/core/common/include/ans_const_define.h +++ b/frameworks/ans/core/common/include/ans_const_define.h @@ -25,6 +25,8 @@ constexpr uint32_t MAX_ACTIVE_NUM_PERAPP = 100; constexpr uint32_t MAX_ACTIVE_NUM_PERSECOND = 10; constexpr uint32_t MAX_SLOT_NUM = 5; 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; } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/core/common/include/ans_inner_errors.h b/frameworks/ans/core/common/include/ans_inner_errors.h index 1c59b864a..3552497d1 100644 --- a/frameworks/ans/core/common/include/ans_inner_errors.h +++ b/frameworks/ans/core/common/include/ans_inner_errors.h @@ -58,7 +58,8 @@ enum ErrorCode : uint32_t { ERR_ANS_NOTIFICATION_NOT_EXISTS, ERR_ANS_NOTIFICATION_IS_UNREMOVABLE, ERR_ANS_OVER_MAX_ACITVE_PERSECOND, - + ERR_ANS_ICON_OVER_SIZE, + ERR_ANS_PICTURE_OVER_SIZE, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED, ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST, ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST, diff --git a/frameworks/ans/core/include/ans_manager_proxy.h b/frameworks/ans/core/include/ans_manager_proxy.h index b90bc8e95..c09e7b818 100644 --- a/frameworks/ans/core/include/ans_manager_proxy.h +++ b/frameworks/ans/core/include/ans_manager_proxy.h @@ -98,10 +98,10 @@ public: private: ErrCode InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); - template + template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data); - template + template bool ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &reply, ErrCode &result); static inline BrokerDelegator delegator_; }; diff --git a/frameworks/ans/core/include/ans_manager_stub.h b/frameworks/ans/core/include/ans_manager_stub.h index 4bf53b386..45006dc32 100644 --- a/frameworks/ans/core/include/ans_manager_stub.h +++ b/frameworks/ans/core/include/ans_manager_stub.h @@ -155,10 +155,10 @@ private: ErrCode HandleIsSpecialBundleAllowedNotify(MessageParcel &data, MessageParcel &reply); ErrCode HandleShellDump(MessageParcel &data, MessageParcel &reply); - template + template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result); - template + template bool ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data); }; } // namespace Notification diff --git a/frameworks/ans/core/include/ans_notification.h b/frameworks/ans/core/include/ans_notification.h index c21ec347b..100bb3894 100644 --- a/frameworks/ans/core/include/ans_notification.h +++ b/frameworks/ans/core/include/ans_notification.h @@ -618,6 +618,13 @@ private: */ bool CanPublishMediaContent(const NotificationRequest &request) const; + /** + * Check whether the picture size exceeds the limit + * + * @return the ErrCode. + */ + ErrCode CheckImageSize(const NotificationRequest &request); + private: std::mutex mutex_; sptr ansManagerProxy_; diff --git a/frameworks/ans/core/src/ans_manager_proxy.cpp b/frameworks/ans/core/src/ans_manager_proxy.cpp index bbfa3b448..c4e3742a9 100644 --- a/frameworks/ans/core/src/ans_manager_proxy.cpp +++ b/frameworks/ans/core/src/ans_manager_proxy.cpp @@ -1797,7 +1797,7 @@ ErrCode AnsManagerProxy::InnerTransact(uint32_t code, MessageOption &flags, Mess } } -template +template bool AnsManagerProxy::WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) { if (!data.WriteInt32(parcelableVector.size())) { @@ -1814,7 +1814,7 @@ bool AnsManagerProxy::WriteParcelableVector(const std::vector> &parcelab return true; } -template +template bool AnsManagerProxy::ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &reply, ErrCode &result) { if (!reply.ReadInt32(result)) { diff --git a/frameworks/ans/core/src/ans_manager_stub.cpp b/frameworks/ans/core/src/ans_manager_stub.cpp index 1185b647f..7f97ff1db 100644 --- a/frameworks/ans/core/src/ans_manager_stub.cpp +++ b/frameworks/ans/core/src/ans_manager_stub.cpp @@ -1160,7 +1160,7 @@ ErrCode AnsManagerStub::HandleShellDump(MessageParcel &data, MessageParcel &repl return ERR_OK; } -template +template bool AnsManagerStub::WriteParcelableVector( const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result) { @@ -1183,7 +1183,7 @@ bool AnsManagerStub::WriteParcelableVector( return true; } -template +template bool AnsManagerStub::ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) { int32_t infoSize = 0; diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index 5bf4a26c3..fd203213c 100644 --- a/frameworks/ans/core/src/ans_notification.cpp +++ b/frameworks/ans/core/src/ans_notification.cpp @@ -14,6 +14,8 @@ */ #include "ans_notification.h" +#include +#include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" #include "iservice_registry.h" @@ -188,6 +190,12 @@ ErrCode AnsNotification::PublishNotification(const std::string &label, const Not return ERR_ANS_INVALID_PARAM; } + ErrCode checkErr = CheckImageSize(request); + if (checkErr != ERR_OK) { + ANS_LOGE("The size of one picture exceeds the limit"); + return checkErr; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -214,6 +222,12 @@ ErrCode AnsNotification::PublishNotification(const NotificationRequest &request, return ERR_ANS_INVALID_PARAM; } + ErrCode checkErr = CheckImageSize(request); + if (checkErr != ERR_OK) { + ANS_LOGE("The size of one picture exceeds the limit"); + return checkErr; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -328,6 +342,12 @@ ErrCode AnsNotification::PublishNotificationAsBundle( return ERR_ANS_INVALID_PARAM; } + ErrCode checkErr = CheckImageSize(request); + if (checkErr != ERR_OK) { + ANS_LOGE("The size of one picture exceeds the limit"); + return checkErr; + } + if (!GetAnsManagerProxy()) { ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; @@ -777,5 +797,91 @@ bool AnsNotification::CanPublishMediaContent(const NotificationRequest &request) return true; } + +ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) +{ + auto littleIcon = request.GetLittleIcon(); + if (littleIcon && (static_cast(littleIcon->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of little icon exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto bigIcon = request.GetBigIcon(); + if (bigIcon && (static_cast(bigIcon->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of big icon exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto content = request.GetContent(); + if (content) { + auto basicContent = request.GetContent()->GetNotificationContent(); + if (basicContent) { + auto contentType = request.GetNotificationType(); + switch (contentType) { + case NotificationContent::Type::CONVERSATION: { + auto conversationalContent = std::static_pointer_cast(basicContent); + + auto picture = conversationalContent->GetMessageUser().GetPixelMap(); + if (picture && (static_cast(picture->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in conversationalContent exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto messages = conversationalContent->GetAllConversationalMessages(); + for (auto &msg : messages) { + if (!msg) { + continue; + } + + auto img = msg->GetSender().GetPixelMap(); + if (img && (static_cast(img->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in conversationalMessage exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + } + } break; + case NotificationContent::Type::PICTURE: { + auto pictureContent = std::static_pointer_cast(basicContent); + + auto bigPicture = pictureContent->GetBigPicture(); + if (bigPicture && (static_cast(bigPicture->GetByteCount()) > MAX_PICTURE_SIZE)) { + ANS_LOGE("The size of big picture exceeds limit"); + return ERR_ANS_PICTURE_OVER_SIZE; + } + } break; + default: + break; + } + } + } + + auto buttons = request.GetActionButtons(); + for (auto &btn : buttons) { + if (!btn) { + continue; + } + + auto icon = btn->GetIcon(); + if (icon && (static_cast(icon->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of icon in actionButton exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + } + + auto users = request.GetMessageUsers(); + for (auto &user : users) { + if (!user) { + continue; + } + + auto icon = user->GetPixelMap(); + if (icon && (static_cast(icon->GetByteCount()) > MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in messageUser exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + } + + return ERR_OK; +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/native/BUILD.gn b/frameworks/ans/native/BUILD.gn index e8c5dae33..502edd929 100755 --- a/frameworks/ans/native/BUILD.gn +++ b/frameworks/ans/native/BUILD.gn @@ -33,6 +33,7 @@ ohos_shared_library("ans_innerkits") { include_dirs = [ "${interfaces_path}/ans/native/include", "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/multimedia/image_standard/interfaces/innerkits/include", "//utils/system/safwk/native/include", "//third_party/jsoncpp/include", ] @@ -75,6 +76,7 @@ ohos_shared_library("ans_innerkits") { "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", ] diff --git a/frameworks/ans/native/src/message_user.cpp b/frameworks/ans/native/src/message_user.cpp index 161d72387..4e1632abd 100644 --- a/frameworks/ans/native/src/message_user.cpp +++ b/frameworks/ans/native/src/message_user.cpp @@ -14,6 +14,7 @@ */ #include "message_user.h" +#include "ans_log_wrapper.h" namespace OHOS { namespace Notification { @@ -45,12 +46,12 @@ std::string MessageUser::GetName() const return name_; } -void MessageUser::SetPixelMap(const std::shared_ptr &pixelMap) +void MessageUser::SetPixelMap(const std::shared_ptr &pixelMap) { pixelMap_ = pixelMap; } -const std::shared_ptr MessageUser::GetPixelMap() const +const std::shared_ptr MessageUser::GetPixelMap() const { return pixelMap_; } @@ -98,30 +99,50 @@ std::string MessageUser::Dump() const bool MessageUser::Marshalling(Parcel &parcel) const { if (!parcel.WriteString(key_)) { + ANS_LOGE("Failed to write key"); return false; } if (!parcel.WriteString(name_)) { + ANS_LOGE("Failed to write name"); return false; } if (!parcel.WriteBool(isMachine_)) { + ANS_LOGE("Failed to write isMachine"); return false; } if (!parcel.WriteBool(isUserImportant_)) { + ANS_LOGE("Failed to write isUserImportant"); return false; } if (uri_.ToString().empty()) { if (!parcel.WriteInt32(VALUE_NULL)) { + ANS_LOGE("Failed to write VALUE_NULL"); return false; } } else { if (!parcel.WriteInt32(VALUE_OBJECT)) { + ANS_LOGE("Failed to write VALUE_OBJECT"); return false; } if (!parcel.WriteString((uri_.ToString()))) { + ANS_LOGE("Failed to write uri"); + return false; + } + } + + bool valid = pixelMap_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether pixelMap is null"); + return false; + } + + if (valid) { + if (!parcel.WriteParcelable(pixelMap_.get())) { + ANS_LOGE("Failed to write pixelMap"); return false; } } @@ -138,6 +159,7 @@ bool MessageUser::ReadFromParcel(Parcel &parcel) int empty = VALUE_NULL; if (!parcel.ReadInt32(empty)) { + ANS_LOGE("Failed to read VALUE"); return false; } @@ -145,6 +167,15 @@ bool MessageUser::ReadFromParcel(Parcel &parcel) uri_ = Uri((parcel.ReadString())); } + bool valid = parcel.ReadBool(); + if (valid) { + pixelMap_ = std::shared_ptr(parcel.ReadParcelable()); + if (!pixelMap_) { + ANS_LOGE("Failed to read pixelMap"); + return false; + } + } + return true; } diff --git a/frameworks/ans/native/src/notification_action_button.cpp b/frameworks/ans/native/src/notification_action_button.cpp index 62cf80e18..b0c004d71 100644 --- a/frameworks/ans/native/src/notification_action_button.cpp +++ b/frameworks/ans/native/src/notification_action_button.cpp @@ -20,7 +20,7 @@ namespace OHOS { namespace Notification { -std::shared_ptr NotificationActionButton::Create(const std::shared_ptr &icon, +std::shared_ptr NotificationActionButton::Create(const std::shared_ptr &icon, const std::string &title, const std::shared_ptr &wantAgent, const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, @@ -55,8 +55,15 @@ std::shared_ptr NotificationActionButton::Create(const } } - auto pActionButton = new (std::nothrow) NotificationActionButton( - icon, title, wantAgent, realExtras, semanticActionButton, autoCreatedReplies, onlyInputs, textInputs, isContextual); + auto pActionButton = new (std::nothrow) NotificationActionButton(icon, + title, + wantAgent, + realExtras, + semanticActionButton, + autoCreatedReplies, + onlyInputs, + textInputs, + isContextual); if (pActionButton == nullptr) { ANS_LOGE("create NotificationActionButton object failed"); return {}; @@ -79,10 +86,10 @@ std::shared_ptr NotificationActionButton::Create( actionButton->IsContextDependent()); } -NotificationActionButton::NotificationActionButton(const std::shared_ptr &icon, const std::string &title, - const std::shared_ptr &wantAgent, const std::shared_ptr &extras, - NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, - const std::vector> &mimeTypeOnlyInputs, +NotificationActionButton::NotificationActionButton(const std::shared_ptr &icon, + const std::string &title, const std::shared_ptr &wantAgent, + const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, + bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, const std::vector> &userInputs, bool isContextual) : icon_(icon), title_(title), @@ -95,7 +102,7 @@ NotificationActionButton::NotificationActionButton(const std::shared_ptr NotificationActionButton::GetIcon() const +const std::shared_ptr NotificationActionButton::GetIcon() const { return icon_; } @@ -217,18 +224,18 @@ bool NotificationActionButton::Marshalling(Parcel &parcel) const bool valid{false}; - // valid = icon_ ? true : false; - // if (!parcel.WriteBool(valid)) { - // ANS_LOGE("Failed to write the flag which indicate whether icon is null"); - // return false; - // } + valid = icon_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether icon is null"); + return false; + } - // if (valid) { - // if (!parcel.WriteParcelable(icon_.get())) { - // ANS_LOGE("Failed to write icon"); - // return false; - // } - // } + if (valid) { + if (!parcel.WriteParcelable(icon_.get())) { + ANS_LOGE("Failed to write icon"); + return false; + } + } valid = wantAgent_ ? true : false; if (!parcel.WriteBool(valid)) { @@ -305,14 +312,14 @@ bool NotificationActionButton::ReadFromParcel(Parcel &parcel) bool valid{false}; - // valid = parcel.ReadBool(); - // if (valid) { - // icon_ = std::shared_ptr(parcel.ReadParcelable()); - // if (!icon_) { - // ANS_LOGE("Failed to read icon"); - // return false; - // } - // } + valid = parcel.ReadBool(); + if (valid) { + icon_ = std::shared_ptr(parcel.ReadParcelable()); + if (!icon_) { + ANS_LOGE("Failed to read icon"); + return false; + } + } valid = parcel.ReadBool(); if (valid) { diff --git a/frameworks/ans/native/src/notification_picture_content.cpp b/frameworks/ans/native/src/notification_picture_content.cpp index 385e3c467..9138938cb 100644 --- a/frameworks/ans/native/src/notification_picture_content.cpp +++ b/frameworks/ans/native/src/notification_picture_content.cpp @@ -38,12 +38,12 @@ std::string NotificationPictureContent::GetBriefText() const return briefText_; } -void NotificationPictureContent::SetBigPicture(const std::shared_ptr &bigPicture) +void NotificationPictureContent::SetBigPicture(const std::shared_ptr &bigPicture) { bigPicture_ = bigPicture; } -const std::shared_ptr NotificationPictureContent::GetBigPicture() const +const std::shared_ptr NotificationPictureContent::GetBigPicture() const { return bigPicture_; } @@ -71,18 +71,18 @@ bool NotificationPictureContent::Marshalling(Parcel &parcel) const return false; } - // auto valid = bigPicture_ ? true : false; - // if (!parcel.WriteBool(valid)) { - // ANS_LOGE("Failed to write the flag which indicate whether bigPicture is null"); - // return false; - // } + auto valid = bigPicture_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether bigPicture is null"); + return false; + } - // if (valid) { - // if (!parcel.WriteParcelable(bigPicture_.get())) { - // ANS_LOGE("Failed to write bigPicture"); - // return false; - // } - // } + if (valid) { + if (!parcel.WriteParcelable(bigPicture_.get())) { + ANS_LOGE("Failed to write bigPicture"); + return false; + } + } return true; } @@ -115,14 +115,14 @@ bool NotificationPictureContent::ReadFromParcel(Parcel &parcel) return false; } - // auto valid = parcel.ReadBool(); - // if (valid) { - // bigPicture_ = std::shared_ptr(parcel.ReadParcelable()); - // if (!bigPicture_) { - // ANS_LOGE("Failed to read bigPicture"); - // return false; - // } - // } + auto valid = parcel.ReadBool(); + if (valid) { + bigPicture_ = std::shared_ptr(parcel.ReadParcelable()); + if (!bigPicture_) { + ANS_LOGE("Failed to read bigPicture"); + return false; + } + } return true; } diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index 809de5494..02c7e1e4c 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -344,22 +344,22 @@ int64_t NotificationRequest::GetAutoDeletedTime() const return autoDeletedTime_; } -void NotificationRequest::SetLittleIcon(const std::shared_ptr &littleIcon) +void NotificationRequest::SetLittleIcon(const std::shared_ptr &littleIcon) { littleIcon_ = littleIcon; } -const std::shared_ptr NotificationRequest::GetLittleIcon() const +const std::shared_ptr NotificationRequest::GetLittleIcon() const { return littleIcon_; } -void NotificationRequest::SetBigIcon(const std::shared_ptr &bigIcon) +void NotificationRequest::SetBigIcon(const std::shared_ptr &bigIcon) { bigIcon_ = bigIcon; } -const std::shared_ptr NotificationRequest::GetBigIcon() const +const std::shared_ptr NotificationRequest::GetBigIcon() const { return bigIcon_; } @@ -1002,31 +1002,31 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const } } - // valid = littleIcon_ ? true : false; - // if (!parcel.WriteBool(valid)) { - // ANS_LOGE("Failed to write the flag which indicate whether littleIcon is null"); - // return false; - // } - - // if (valid) { - // if (!parcel.WriteParcelable(littleIcon_.get())) { - // ANS_LOGE("Failed to write littleIcon"); - // return false; - // } - // } - - // valid = bigIcon_ ? true : false; - // if (!parcel.WriteBool(valid)) { - // ANS_LOGE("Failed to write the flag which indicate whether bigIcon is null"); - // return false; - // } - - // if (valid) { - // if (!parcel.WriteParcelable(bigIcon_.get())) { - // ANS_LOGE("Failed to write bigIcon"); - // return false; - // } - // } + valid = littleIcon_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether littleIcon is null"); + return false; + } + + if (valid) { + if (!parcel.WriteParcelable(littleIcon_.get())) { + ANS_LOGE("Failed to write littleIcon"); + return false; + } + } + + valid = bigIcon_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether bigIcon is null"); + return false; + } + + if (valid) { + if (!parcel.WriteParcelable(bigIcon_.get())) { + ANS_LOGE("Failed to write bigIcon"); + return false; + } + } valid = notificationContent_ ? true : false; if (!parcel.WriteBool(valid)) { @@ -1215,23 +1215,23 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) } } - // valid = parcel.ReadBool(); - // if (valid) { - // littleIcon_ = std::shared_ptr(parcel.ReadParcelable()); - // if (!littleIcon_) { - // ANS_LOGE("Failed to read littleIcon"); - // return false; - // } - // } - - // valid = parcel.ReadBool(); - // if (valid) { - // bigIcon_ = std::shared_ptr(parcel.ReadParcelable()); - // if (!bigIcon_) { - // ANS_LOGE("Failed to read bigIcon"); - // return false; - // } - // } + valid = parcel.ReadBool(); + if (valid) { + littleIcon_ = std::shared_ptr(parcel.ReadParcelable()); + if (!littleIcon_) { + ANS_LOGE("Failed to read littleIcon"); + return false; + } + } + + valid = parcel.ReadBool(); + if (valid) { + bigIcon_ = std::shared_ptr(parcel.ReadParcelable()); + if (!bigIcon_) { + ANS_LOGE("Failed to read bigIcon"); + return false; + } + } valid = parcel.ReadBool(); if (valid) { diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index db73e3179..8046c8d17 100755 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -102,6 +102,7 @@ ohos_moduletest("ans_fw_module_test") { "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//third_party/googletest:gtest_main", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utils", @@ -154,6 +155,7 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata/include", "//foundation/distributeddatamgr/distributeddatamgr/frameworks/innerkitsimpl/distributeddatafwk/src", "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/adapter/include/dfx", + "//foundation/multimedia/image_standard/interfaces/innerkits/include", "//developtools/bytrace_standard/interfaces/innerkits/native/include", ] @@ -182,6 +184,7 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index 7a35c46c2..ba6edb7ff 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -36,6 +36,8 @@ #include "system_ability_definition.h" using namespace testing::ext; +using namespace OHOS::Media; + namespace OHOS { namespace Notification { @@ -54,7 +56,7 @@ enum class SubscriberEventType { class SubscriberEvent { public: - ~SubscriberEvent() + virtual ~SubscriberEvent() {} SubscriberEventType GetType() { @@ -70,7 +72,7 @@ protected: class OnSubscribeResultEvent : public SubscriberEvent { public: - ~OnSubscribeResultEvent() + ~OnSubscribeResultEvent() override {} OnSubscribeResultEvent(NotificationConstant::SubscribeResult result) : SubscriberEvent(SubscriberEventType::ON_SUBSCRIBERESULT), subscribeResult_(result) @@ -1064,5 +1066,119 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishVibrationNotification_00100, Function SleepForFC(); } +inline std::shared_ptr MakePixelMap(int32_t width, int32_t height) +{ + const int32_t PIXEL_BYTES = 4; + std::shared_ptr pixelMap = std::make_shared(); + ImageInfo info; + info.size.width = width; + info.size.height = height; + info.pixelFormat = PixelFormat::ARGB_8888; + info.colorSpace = ColorSpace::SRGB; + pixelMap->SetImageInfo(info); + int32_t rowDataSize = width * PIXEL_BYTES; + uint32_t bufferSize = rowDataSize * height; + void *buffer = malloc(bufferSize); + EXPECT_NE(buffer, nullptr); + pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr); + return pixelMap; +} + +/** + * + * @tc.number : ANS_FW_MT_PublishNotificationWithPixelMap_00100 + * @tc.name : + * @tc.desc : Publish a notification with pixelMap. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishNotificationWithPixelMap_00100, Function | MediumTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 400; + const int BIG_PICTURE_HEIGHT = 300; + const int ICON_SIZE = 36; + + NotificationRequest req; + req.SetSlotType(NotificationConstant::SlotType::OTHER); + req.SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req.SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetBigIcon(bigIcon); + EXPECT_EQ(NotificationHelper::PublishNotification(req), ERR_OK); +} + +/** + * + * @tc.number : ANS_FW_MT_PublishNotificationWithPixelMap_00200 + * @tc.name : + * @tc.desc : Publish a notification with oversize pixelMap. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishNotificationWithPixelMap_00200, Function | MediumTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 1024; + const int BIG_PICTURE_HEIGHT = 1024; + const int ICON_SIZE = 36; + + NotificationRequest req; + req.SetSlotType(NotificationConstant::SlotType::OTHER); + req.SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req.SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetBigIcon(bigIcon); + EXPECT_EQ(NotificationHelper::PublishNotification(req), (int)ERR_ANS_PICTURE_OVER_SIZE); +} + +/** + * + * @tc.number : ANS_FW_MT_PublishNotificationWithPixelMap_00300 + * @tc.name : + * @tc.desc : Publish a notification with oversize pixelMap. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishNotificationWithPixelMap_00300, Function | MediumTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 400; + const int BIG_PICTURE_HEIGHT = 300; + const int ICON_SIZE = 256; + + NotificationRequest req; + req.SetSlotType(NotificationConstant::SlotType::OTHER); + req.SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req.SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req.SetBigIcon(bigIcon); + EXPECT_EQ(NotificationHelper::PublishNotification(req), (int)ERR_ANS_ICON_OVER_SIZE); +} + } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp index fbf6f3116..85404dd1b 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -57,6 +57,10 @@ const int32_t CASE_FOURTEEN = 14; const int32_t CASE_FIFTEEN = 15; const int32_t CASE_SIXTEEN = 16; const int32_t CALLING_UID = 9999; + +const int32_t PIXEL_MAP_TEST_WIDTH = 1024; +const int32_t PIXEL_MAP_TEST_HEIGHT = 1024; + std::mutex g_subscribe_mtx; std::mutex g_consumed_mtx; std::mutex g_unsubscribe_mtx; @@ -163,8 +167,8 @@ private: } } EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType()); - for (auto it : notificationRequest.GetNotificationUserInputHistory()) { - EXPECT_EQ("style", it); + for (auto str : notificationRequest.GetNotificationUserInputHistory()) { + EXPECT_EQ("style", str); } EXPECT_EQ("bundleName", notificationRequest.GetOwnerBundleName()); EXPECT_EQ("bundleName", notificationRequest.GetCreatorBundleName()); @@ -173,18 +177,31 @@ private: if (NotificationRequestPtr != nullptr) { EXPECT_EQ("ANS_Interface_MT_Publish_00100_REQUEST", NotificationRequestPtr->GetLabel()); } + + // pixelmap + auto littleIcon = notificationRequest.GetLittleIcon(); + Media::ImageInfo outImageInfo; + littleIcon->GetImageInfo(outImageInfo); + GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100 :: littleIcon :: width : " << outImageInfo.size.width; + GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_00100 :: littleIcon :: height : " << outImageInfo.size.height; + + EXPECT_EQ(outImageInfo.size.width, PIXEL_MAP_TEST_WIDTH); + EXPECT_EQ(outImageInfo.size.height, PIXEL_MAP_TEST_HEIGHT); + EXPECT_EQ(outImageInfo.pixelFormat, Media::PixelFormat::ALPHA_8); + EXPECT_EQ(outImageInfo.colorSpace, Media::ColorSpace::SRGB); + EXPECT_EQ(nullptr, notificationRequest.GetBigIcon()); EXPECT_EQ(nullptr, notificationRequest.GetLittleIcon()); EXPECT_EQ(nullptr, notificationRequest.GetLittleIcon()); std::vector> messageUser = notificationRequest.GetMessageUsers(); - for (auto it : messageUser) { - if (it != nullptr) { - EXPECT_EQ("ANS_Interface_MT_Publish_00100_Message_User", it->GetName()); - EXPECT_EQ("key", it->GetKey()); - EXPECT_EQ(nullptr, it->GetPixelMap()); - EXPECT_EQ(Uri("."), it->GetUri()); - EXPECT_EQ(false, it->IsMachine()); - EXPECT_EQ(false, it->IsUserImportant()); + for (auto user : messageUser) { + if (user != nullptr) { + EXPECT_EQ("ANS_Interface_MT_Publish_00100_Message_User", user->GetName()); + EXPECT_EQ("key", user->GetKey()); + EXPECT_EQ(nullptr, user->GetPixelMap()); + EXPECT_EQ(Uri("."), user->GetUri()); + EXPECT_EQ(false, user->IsMachine()); + EXPECT_EQ(false, user->IsUserImportant()); } } } @@ -352,6 +369,11 @@ class CompletedCallbackTest : public WantAgent::CompletedCallback { void OnSendFinished( const AAFwk::Want &want, int resultCode, const std::string &resultData, const AAFwk::WantParams &resultExtras) { + (void)want; + (void)resultCode; + (void)resultData; + (void)resultExtras; + g_send_finished_mtx.unlock(); OnWantReceived = true; } @@ -480,8 +502,22 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_00100, Function std::shared_ptr requestPtr = std::make_shared(); requestPtr->SetLabel("ANS_Interface_MT_Publish_00100_REQUEST"); req.SetPublicNotification(requestPtr); - req.SetBigIcon(nullptr); - req.SetLittleIcon(nullptr); + + // pixelmap + auto pixelMap = std::make_shared(); + Media::ImageInfo imageInfo; + imageInfo.size.width = PIXEL_MAP_TEST_WIDTH; + imageInfo.size.height = PIXEL_MAP_TEST_HEIGHT; + imageInfo.pixelFormat = Media::PixelFormat::ALPHA_8; + imageInfo.colorSpace = Media::ColorSpace::SRGB; + pixelMap->SetImageInfo(imageInfo); + int32_t rowDataSize = (PIXEL_MAP_TEST_WIDTH + 3) / 4 * 4; + uint32_t bufferSize = rowDataSize * PIXEL_MAP_TEST_HEIGHT; + void *buffer = malloc(bufferSize); + pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, Media::AllocatorType::HEAP_ALLOC, nullptr); + + req.SetBigIcon(pixelMap); + req.SetLittleIcon(pixelMap); std::shared_ptr messageUserPtr = std::make_shared(); messageUserPtr->SetName("ANS_Interface_MT_Publish_00100_Message_User"); messageUserPtr->SetKey("key"); diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp index 0433b2967..e7ced9336 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp @@ -118,7 +118,6 @@ HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_NotificationSlot_00100, Fu */ HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_NotificationSlot_00200, Function | MediumTest | Level1) { - // bundleObject->MockSetIsSystemApp(false); NotificationSlot slot(NotificationConstant::SERVICE_REMINDER); slot.SetEnableLight(true); slot.SetDescription("description"); diff --git a/frameworks/ans/test/moduletest/mock/mock_bundle_manager.cpp b/frameworks/ans/test/moduletest/mock/mock_bundle_manager.cpp index 340c592c3..98fd912f3 100644 --- a/frameworks/ans/test/moduletest/mock/mock_bundle_manager.cpp +++ b/frameworks/ans/test/moduletest/mock/mock_bundle_manager.cpp @@ -13,12 +13,15 @@ * limitations under the License. */ +#include "mock_bundle_manager.h" #include "ability_info.h" #include "application_info.h" -#include "mock_bundle_manager.h" namespace OHOS { namespace AppExecFwk { + +constexpr int SYSTEM_APP_UUID = 1000; + void MockBundleMgrService::MockSetIsSystemApp(bool isSystemApp) { isSystemAppMock_ = true; @@ -30,7 +33,7 @@ bool MockBundleMgrService::CheckIsSystemAppByUid(const int uid) if (isSystemAppMock_) { return isSystemApp_; } - return (uid < 1000) ? false : true; + return (uid < SYSTEM_APP_UUID) ? false : true; } int MockBundleMgrService::CheckPermission(const std::string &bundleName, const std::string &permission) diff --git a/frameworks/ans/test/moduletest/mock/mock_event_handler.cpp b/frameworks/ans/test/moduletest/mock/mock_event_handler.cpp index 4fcdd4a2c..12a7f65b9 100644 --- a/frameworks/ans/test/moduletest/mock/mock_event_handler.cpp +++ b/frameworks/ans/test/moduletest/mock/mock_event_handler.cpp @@ -17,108 +17,94 @@ #include "event_handler_utils.h" #include -namespace OHOS +namespace OHOS { +namespace AppExecFwk { + +std::shared_ptr EventHandler::Current() +{ + const std::weak_ptr &wp = std::make_shared(EventRunner::Create(true)); + return wp.lock(); +} + +EventHandler::EventHandler(const std::shared_ptr &runner) : eventRunner_(runner) +{} + +EventHandler::~EventHandler() +{} + +bool EventHandler::SendEvent(InnerEvent::Pointer &event, int64_t delayTime, Priority priority) +{ + std::function callback = event->GetTaskCallback(); + callback(); + return true; +} + +bool EventHandler::SendTimingEvent(InnerEvent::Pointer &event, int64_t taskTime, Priority priority) +{ + return true; +} + +bool EventHandler::SendSyncEvent(InnerEvent::Pointer &event, Priority priority) +{ + std::function callback = event->GetTaskCallback(); + callback(); + return true; +} + +void EventHandler::RemoveAllEvents() +{} + +void EventHandler::RemoveEvent(uint32_t innerEventId) +{} + +void EventHandler::RemoveEvent(uint32_t innerEventId, int64_t param) +{} + +void EventHandler::RemoveTask(const std::string &name) +{} + +ErrCode EventHandler::AddFileDescriptorListener( + int32_t fileDescriptor, uint32_t events, const std::shared_ptr &listener) { - namespace AppExecFwk - { - - std::shared_ptr EventHandler::Current() - { - const std::weak_ptr &wp = std::make_shared(EventRunner::Create(true)); - return wp.lock(); - } - - EventHandler::EventHandler(const std::shared_ptr &runner) : eventRunner_(runner) - { - } - - EventHandler::~EventHandler() - { - } - - bool EventHandler::SendEvent(InnerEvent::Pointer &event, int64_t delayTime, Priority priority) - { - std::function callback = event->GetTaskCallback(); - callback(); - return true; - } - - bool EventHandler::SendTimingEvent(InnerEvent::Pointer &event, int64_t taskTime, Priority priority) - { - return true; - } - - bool EventHandler::SendSyncEvent(InnerEvent::Pointer &event, Priority priority) - { - std::function callback = event->GetTaskCallback(); - callback(); - return true; - } - - void EventHandler::RemoveAllEvents() - { - } - - void EventHandler::RemoveEvent(uint32_t innerEventId) - { - } - - void EventHandler::RemoveEvent(uint32_t innerEventId, int64_t param) - { - } - - void EventHandler::RemoveTask(const std::string &name) - { - } - - ErrCode EventHandler::AddFileDescriptorListener( - int32_t fileDescriptor, uint32_t events, const std::shared_ptr &listener) - { - return EVENT_HANDLER_ERR_INVALID_PARAM; - } - - void EventHandler::RemoveAllFileDescriptorListeners() - { - } - - void EventHandler::RemoveFileDescriptorListener(int32_t fileDescriptor) - { - } - - void EventHandler::SetEventRunner(const std::shared_ptr &runner) - { - } - - void EventHandler::DistributeEvent(const InnerEvent::Pointer &event) - { - } - - void EventHandler::Dump(Dumper &dumper) - { - } - - bool EventHandler::HasInnerEvent(uint32_t innerEventId) - { - return true; - } - - bool EventHandler::HasInnerEvent(int64_t param) - { - return true; - } - - std::string EventHandler::GetEventName(const InnerEvent::Pointer &event) - { - return "132123"; - } - - bool EventHandler::IsIdle() - { - return true; - } - - void EventHandler::ProcessEvent(const InnerEvent::Pointer &) - { - } - } // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file + return EVENT_HANDLER_ERR_INVALID_PARAM; +} + +void EventHandler::RemoveAllFileDescriptorListeners() +{} + +void EventHandler::RemoveFileDescriptorListener(int32_t fileDescriptor) +{} + +void EventHandler::SetEventRunner(const std::shared_ptr &runner) +{} + +void EventHandler::DistributeEvent(const InnerEvent::Pointer &event) +{} + +void EventHandler::Dump(Dumper &dumper) +{} + +bool EventHandler::HasInnerEvent(uint32_t innerEventId) +{ + return true; +} + +bool EventHandler::HasInnerEvent(int64_t param) +{ + return true; +} + +std::string EventHandler::GetEventName(const InnerEvent::Pointer &event) +{ + return "132123"; +} + +bool EventHandler::IsIdle() +{ + return true; +} + +void EventHandler::ProcessEvent(const InnerEvent::Pointer &) +{} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/message_user.h b/interfaces/innerkits/ans/native/include/message_user.h index 0ceb44f49..0e7717dda 100644 --- a/interfaces/innerkits/ans/native/include/message_user.h +++ b/interfaces/innerkits/ans/native/include/message_user.h @@ -16,13 +16,12 @@ #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_MESSAGE_USER_H #include - +#include "pixel_map.h" #include "parcel.h" #include "uri.h" namespace OHOS { namespace Notification { -class PixelMap; class MessageUser final : public Parcelable { public: /** @@ -67,14 +66,14 @@ public: * Sets the pixel map of this MessageUser. * @param pixelMap Indicates the pixel map to set. */ - void SetPixelMap(const std::shared_ptr &pixelMap); + void SetPixelMap(const std::shared_ptr &pixelMap); /** * Obtains the pixel map of this MessageUser. * * @return Returns the pixel map of this MessageUser. */ - const std::shared_ptr GetPixelMap() const; + const std::shared_ptr GetPixelMap() const; /** * Sets the URI of this MessageUser. @@ -153,7 +152,7 @@ private: private: std::string key_{}; std::string name_{}; - std::shared_ptr pixelMap_{nullptr}; + std::shared_ptr pixelMap_{nullptr}; Uri uri_; bool isMachine_{false}; bool isUserImportant_{false}; diff --git a/interfaces/innerkits/ans/native/include/notification_action_button.h b/interfaces/innerkits/ans/native/include/notification_action_button.h index 42f8af582..843b87753 100644 --- a/interfaces/innerkits/ans/native/include/notification_action_button.h +++ b/interfaces/innerkits/ans/native/include/notification_action_button.h @@ -23,12 +23,11 @@ #include "notification_user_input.h" #include "want_agent.h" #include "pac_map.h" +#include "pixel_map.h" #include "parcel.h" namespace OHOS { namespace Notification { -class PixelMap; - class NotificationActionButton : public Parcelable { public: /** @@ -47,7 +46,7 @@ public: * @return the shared_ptr object owns the created NotificationActionButton object otherwise return empty object if * isContextual is true but icon or wantAgent is empty. */ - static std::shared_ptr Create(const std::shared_ptr &icon, + static std::shared_ptr Create(const std::shared_ptr &icon, const std::string &title, const std::shared_ptr &wantAgent, const std::shared_ptr &extras = {}, NotificationConstant::SemanticActionButton semanticActionButton = @@ -74,7 +73,7 @@ public: * Obtains the icon of this NotificationActionButton. * @return the icon of this NotificationActionButton. */ - const std::shared_ptr GetIcon() const; + const std::shared_ptr GetIcon() const; /** * Obtains the title of this NotificationActionButton. @@ -208,7 +207,7 @@ private: * @param userInputs Indicates the NotificationUserInput object to add. * @param isContextual Indicates whether this NotificationActionButton is a contextual action. */ - NotificationActionButton(const std::shared_ptr &icon, const std::string &title, + NotificationActionButton(const std::shared_ptr &icon, const std::string &title, const std::shared_ptr &wantAgent, const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs, @@ -221,7 +220,7 @@ private: bool ReadFromParcel(Parcel &parcel); private: - std::shared_ptr icon_{}; + std::shared_ptr icon_{}; std::string title_{}; std::shared_ptr wantAgent_{}; std::shared_ptr extras_{}; diff --git a/interfaces/innerkits/ans/native/include/notification_picture_content.h b/interfaces/innerkits/ans/native/include/notification_picture_content.h index 1fdd92f7e..c4abb2f45 100644 --- a/interfaces/innerkits/ans/native/include/notification_picture_content.h +++ b/interfaces/innerkits/ans/native/include/notification_picture_content.h @@ -19,12 +19,11 @@ #include #include #include "notification_basic_content.h" +#include "pixel_map.h" #include "parcel.h" namespace OHOS { namespace Notification { -class PixelMap; - class NotificationPictureContent : public NotificationBasicContent { public: /** @@ -71,13 +70,13 @@ public: * Sets the picture to be included in a notification. * @param bigPicture Indicates the PixelMap of the picture to be included. */ - void SetBigPicture(const std::shared_ptr &bigPicture); + void SetBigPicture(const std::shared_ptr &bigPicture); /** * Obtains the PixelMap of the picture specified by calling the setBigPicture(PixelMap) method. * @return the PixelMap of the picture included in the notification. */ - const std::shared_ptr GetBigPicture() const; + const std::shared_ptr GetBigPicture() const; /** * Returns a string representation of the object. @@ -107,7 +106,7 @@ protected: private: std::string expandedTitle_{}; std::string briefText_{}; - std::shared_ptr bigPicture_{}; + std::shared_ptr bigPicture_{}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_request.h b/interfaces/innerkits/ans/native/include/notification_request.h index 0f52f5bf6..a879f32d8 100644 --- a/interfaces/innerkits/ans/native/include/notification_request.h +++ b/interfaces/innerkits/ans/native/include/notification_request.h @@ -25,12 +25,11 @@ #include "want_agent.h" #include "context.h" #include "ohos/aafwk/content/want_params.h" +#include "pixel_map.h" #include "parcel.h" namespace OHOS { namespace Notification { -class PixelMap; - class NotificationRequest : public Parcelable { public: enum class BadgeStyle { @@ -402,25 +401,25 @@ public: * Sets the little icon of the notification. * @param littleIcon Indicates the icon of the notification. */ - void SetLittleIcon(const std::shared_ptr &littleIcon); + void SetLittleIcon(const std::shared_ptr &littleIcon); /** * Obtains the icon of the notification. * @return the notification icon. */ - const std::shared_ptr GetLittleIcon() const; + const std::shared_ptr GetLittleIcon() const; /** * Sets the large icon of this notification, which is usually displayed on the right of the notification. * @param bigIcon Indicates the large icon to set. It must be a PixelMap object. */ - void SetBigIcon(const std::shared_ptr &bigIcon); + void SetBigIcon(const std::shared_ptr &bigIcon); /** * Obtains the large icon of this notification. * @return the large icon of this notification. */ - const std::shared_ptr GetBigIcon() const; + const std::shared_ptr GetBigIcon() const; /** * Sets the classification of this notification, which describes the purpose of this notification. @@ -936,8 +935,8 @@ private: std::shared_ptr removalWantAgent_{}; std::shared_ptr maxScreenWantAgent_{}; std::shared_ptr additionalParams_{}; - std::shared_ptr littleIcon_{}; - std::shared_ptr bigIcon_{}; + std::shared_ptr littleIcon_{}; + std::shared_ptr bigIcon_{}; std::shared_ptr notificationContent_{}; std::shared_ptr publicNotification_{}; diff --git a/interfaces/innerkits/ans/native/include/notification_user_input.h b/interfaces/innerkits/ans/native/include/notification_user_input.h index 41b548076..f84d26830 100644 --- a/interfaces/innerkits/ans/native/include/notification_user_input.h +++ b/interfaces/innerkits/ans/native/include/notification_user_input.h @@ -28,8 +28,6 @@ namespace OHOS { namespace Notification { -class PixelMap; - class NotificationUserInput : public Parcelable { public: /** diff --git a/interfaces/kits/js/@ohos.notification.d.ts b/interfaces/kits/js/@ohos.notification.d.ts index f8c7dc59d..ef467ad88 100644 --- a/interfaces/kits/js/@ohos.notification.d.ts +++ b/interfaces/kits/js/@ohos.notification.d.ts @@ -32,8 +32,8 @@ import { NotificationRequest } from './notification/notificationRequest'; * * @name notification * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ declare namespace notification { @@ -86,7 +86,7 @@ declare namespace notification { * @param slot Indicates the notification slot to be created, which is set by {@link NotificationSlot}. * This parameter must be specified. * - * @SystemApi + * @systemapi Hide this for inner system use. * @since 7 */ function addSlot(slot: NotificationSlot, callback: AsyncCallback): void; @@ -109,7 +109,7 @@ declare namespace notification { * @param slots Indicates the notification slots to be created, which is set by {@link NotificationSlot}. * This parameter must be specified. * - * @SystemApi + * @systemapi Hide this for inner system use. * @since 7 */ function addSlots(slots: Array, callback: AsyncCallback): void; @@ -173,17 +173,15 @@ declare namespace notification { * * @name ContentType * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export enum ContentType { NOTIFICATION_CONTENT_BASIC_TEXT, NOTIFICATION_CONTENT_LONG_TEXT, NOTIFICATION_CONTENT_PICTURE, - NOTIFICATION_CONTENT_CONVERSATION, NOTIFICATION_CONTENT_MULTILINE, - NOTIFICATION_CONTENT_MEDIA } /** @@ -202,7 +200,7 @@ declare namespace notification { /** * subscribe * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ function subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback): void; @@ -212,7 +210,7 @@ declare namespace notification { /** * unsubscribe * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ function unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback): void; @@ -221,86 +219,79 @@ declare namespace notification { /** * enableNotification * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ function enableNotification(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void; function enableNotification(bundle: BundleOption, enable: boolean): Promise; /** - * canNotify + * isNotificationEnabled * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ function isNotificationEnabled(bundle: BundleOption, callback: AsyncCallback): void; function isNotificationEnabled(bundle: BundleOption): Promise; /** - * canNotify + * isNotificationEnabled * + * @systemapi Hide this for inner system use. * @since 7 */ function isNotificationEnabled(callback: AsyncCallback): void; function isNotificationEnabled(): Promise; /** - * isBadgeDisplayed + * displayBadge * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ function displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void; function displayBadge(bundle: BundleOption, enable: boolean): Promise; /** - * canDisplayBadge + * isBadgeDisplayed * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ function isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback): void; function isBadgeDisplayed(bundle: BundleOption): Promise; /** - * isShowBadge - * - * @since 7 - */ - function isBadgeDisplayed(callback: AsyncCallback): void; - function isBadgeDisplayed(): Promise; - - /** - * setSlotAsBundle + * setSlotByBundle * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ - function setSlotAsBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback): void; - function setSlotAsBundle(bundle: BundleOption, slot: NotificationSlot): Promise; + function setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback): void; + function setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise; /** - * getSlotsAsBundle + * getSlotsByBundle * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ - function getSlotsAsBundle(bundle: BundleOption, callback: AsyncCallback>): void; - function getSlotsAsBundle(bundle: BundleOption): Promise>; + function getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>): void; + function getSlotsByBundle(bundle: BundleOption): Promise>; /** - * getSlotNumAsBundle + * getSlotNumByBundle * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ - function getSlotNumAsBundle(bundle: BundleOption, callback: AsyncCallback): void; - function getSlotNumAsBundle(bundle: BundleOption): Promise; + function getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback): void; + function getSlotNumByBundle(bundle: BundleOption): Promise; /** * remove * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ function remove(bundle: BundleOption, notificationKey: NotificationKey, callback: AsyncCallback): void; @@ -309,7 +300,7 @@ declare namespace notification { /** * remove * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ function remove(hashCode: string, callback: AsyncCallback): void; @@ -318,7 +309,7 @@ declare namespace notification { /** * removeAll * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ function removeAll(bundle: BundleOption, callback: AsyncCallback): void; @@ -329,7 +320,7 @@ declare namespace notification { * Obtains all active notifications in the current system. The caller must have system permissions to * call this method. * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ function getAllActiveNotifications(callback: AsyncCallback>): void; @@ -340,8 +331,8 @@ declare namespace notification { * * @since 7 */ - function getActiveNotificationNums(callback: AsyncCallback): void; - function getActiveNotificationNums(): Promise; + function getActiveNotificationCount(callback: AsyncCallback): void; + function getActiveNotificationCount(): Promise; /** * Obtains active notifications of the current application in the system. @@ -368,12 +359,13 @@ declare namespace notification { */ export interface NotificationKey { id: number; - lable?: string; + label?: string; } /** * DisturbMode * + * @systemapi Hide this for inner system use. * @since 7 */ export enum DoNotDisturbMode { diff --git a/interfaces/kits/js/@ohos.wantAgent.d.ts b/interfaces/kits/js/@ohos.wantAgent.d.ts index 23f8c861f..2bdd0a1f0 100644 --- a/interfaces/kits/js/@ohos.wantAgent.d.ts +++ b/interfaces/kits/js/@ohos.wantAgent.d.ts @@ -16,7 +16,6 @@ import { AsyncCallback , Callback} from './basic'; import { Want } from './ability/want'; import { WantAgentInfo } from './wantAgent/wantAgentInfo'; -import { TriggerInfo } from './wantAgent/triggerInfo'; /** * Provide the method obtain trigger, cancel, and compare and to obtain @@ -28,68 +27,6 @@ import { TriggerInfo } from './wantAgent/triggerInfo'; * @permission N/A */ declare namespace wantAgent { - /** - * Obtains the bundle name of an {@link WantAgent}. - * - * @param agent Indicates the {@link WantAgent} whose bundle name is to be obtained. - * - * @since 7 - */ - function getBundleName(agent: WantAgent, callback: AsyncCallback): void; - function getBundleName(agent: WantAgent): Promise; - - /** - * Obtains the bundle name of an {@link WantAgent}. - * - * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. - * - * @since 7 - */ - function getUid(agent: WantAgent, callback: AsyncCallback): void; - function getUid(agent: WantAgent): Promise; - - /** - * Obtains the {@link Want} of an {@link WantAgent}. - * - * @param agent Indicates the {@link WantAgent} whose UID is to be obtained. - * - * @systemApi - * @since 7 - */ - function getWant(agent: WantAgent, callback: AsyncCallback): void; - function getWant(agent: WantAgent): Promise; - - /** - * Cancels an {@link WantAgent}. Only the application that creates the {@link IntentAgent} can cancel it. - * - * @param agent Indicates the {@link WantAgent} to cancel. - * - * @since 7 - */ - function cancel(agent: WantAgent, callback: AsyncCallback): void; - function cancel(agent: WantAgent): Promise; - - /** - * Obtains the bundle name of an {@link WantAgent}. - * - * @param agent Indicates the {@link WantAgent} whose bundle name is to be obtained. - * - * @since 7 - */ - function trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback): void; - - /** - * Checks whether two {@link WantAgent} objects are the same. - * - * @param agent Indicates one of the {@link WantAgent} object to compare. - * @param otherAgent Indicates the other {@link WantAgent} object 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. * @@ -130,22 +67,7 @@ declare namespace wantAgent { START_ABILITY, START_ABILITIES, START_SERVICE, - SEND_COMMON_EVENT, - START_FOREGROUND_SERVICE - } - - /** - * A callback for the {@link trigger()} method. After the method execution is complete, - * the callback process will start. - * - * @since 7 - */ - export interface CompleteData { - info: WantAgent; - want: Want; - finalCode: number; - finalData: string; - extraInfo?: {[key: string]: any}; + SEND_COMMON_EVENT } } diff --git a/interfaces/kits/js/notification/notificationActionButton.ts b/interfaces/kits/js/notification/notificationActionButton.ts index 21690e602..140215050 100644 --- a/interfaces/kits/js/notification/notificationActionButton.ts +++ b/interfaces/kits/js/notification/notificationActionButton.ts @@ -13,19 +13,18 @@ * limitations under the License. */ -import { AsyncCallback } from './../basic'; import { WantAgent } from '../@ohos.wantAgent'; -import image from '../@ohos.multimedia.image'; /** * The action button of notification * @name NotificationActionButton * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface NotificationActionButton { title: string; wantAgent: WantAgent; + extras?: {[key: string]: any}; } diff --git a/interfaces/kits/js/notification/notificationContent.d.ts b/interfaces/kits/js/notification/notificationContent.d.ts index f89526b33..134218f5e 100644 --- a/interfaces/kits/js/notification/notificationContent.d.ts +++ b/interfaces/kits/js/notification/notificationContent.d.ts @@ -20,8 +20,8 @@ import notification from '../@ohos.notification'; * * @name NotificationBasicContent * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface NotificationBasicContent { @@ -35,8 +35,8 @@ export interface NotificationBasicContent { * * @name NotificationLongTextContent * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface NotificationLongTextContent extends NotificationBasicContent { @@ -50,14 +50,14 @@ export interface NotificationLongTextContent extends NotificationBasicContent { * * @name NotificationMultiLineContent * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface NotificationMultiLineContent extends NotificationBasicContent { briefText: string; longTitle: string; - lines: Array; + lines: Array; } /** @@ -65,8 +65,8 @@ export interface NotificationMultiLineContent extends NotificationBasicContent { * * @name NotificationMultiLineContent * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface NotificationContent { diff --git a/interfaces/kits/js/notification/notificationRequest.d.ts b/interfaces/kits/js/notification/notificationRequest.d.ts index 5fd0fc9e6..0914b648d 100644 --- a/interfaces/kits/js/notification/notificationRequest.d.ts +++ b/interfaces/kits/js/notification/notificationRequest.d.ts @@ -13,9 +13,7 @@ * limitations under the License. */ -import { AsyncCallback } from './../basic'; import notification from '../@ohos.notification'; -import image from '../@ohos.multimedia.image'; import { WantAgent } from '../@ohos.wantAgent'; import { NotificationContent } from './notificationContent'; import { NotificationActionButton } from './notificationActionButton'; @@ -25,8 +23,8 @@ import { NotificationActionButton } from './notificationActionButton'; * * @name NotificationRequest * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface NotificationRequest { @@ -40,14 +38,11 @@ export interface NotificationRequest { autoDeletedTime?: number; wantAgent?: WantAgent; extraInfo?: {[key: string]: any}; - removalWantAgent?: WantAgent; - maxScreenWantAgent?: WantAgent; color?: number; colorEnabled?: boolean; isAlertOnce?: boolean; isStopwatch?: boolean; isCountDown?: boolean; - statusBarText?: string; isFloatingIcon?: boolean; label?: string; badgeIconStyle?: number; @@ -60,7 +55,7 @@ export interface NotificationRequest { /** * Obtains the classification of this notification. * - * @systemapi + * @systemapi Hide this for inner system use. * @since 7 */ classification?: string; diff --git a/interfaces/kits/js/notification/notificationSlot.d.ts b/interfaces/kits/js/notification/notificationSlot.d.ts index e91e8c0eb..56f987e69 100644 --- a/interfaces/kits/js/notification/notificationSlot.d.ts +++ b/interfaces/kits/js/notification/notificationSlot.d.ts @@ -20,8 +20,8 @@ import notification from '../@ohos.notification'; * * @name NotificationSlot * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface NotificationSlot { diff --git a/interfaces/kits/js/notification/notificationSorting.d.ts b/interfaces/kits/js/notification/notificationSorting.d.ts index 73fbae19b..1a34e32fa 100644 --- a/interfaces/kits/js/notification/notificationSorting.d.ts +++ b/interfaces/kits/js/notification/notificationSorting.d.ts @@ -19,8 +19,8 @@ import { NotificationSlot } from './notificationSlot'; * Provides sorting information about an active notification. * * @name NotificationSorting - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A * @since 7 */ diff --git a/interfaces/kits/js/notification/notificationSortingMap.d.ts b/interfaces/kits/js/notification/notificationSortingMap.d.ts index f632189de..829ddaf15 100644 --- a/interfaces/kits/js/notification/notificationSortingMap.d.ts +++ b/interfaces/kits/js/notification/notificationSortingMap.d.ts @@ -20,8 +20,8 @@ import { NotificationSorting } from './notificationSorting'; * * @name NotificationSortingMap * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ interface NotificationSortingMap { diff --git a/interfaces/kits/js/notification/notificationSubscribeInfo.ts b/interfaces/kits/js/notification/notificationSubscribeInfo.ts index 4d9afb649..ea1f69fc2 100644 --- a/interfaces/kits/js/notification/notificationSubscribeInfo.ts +++ b/interfaces/kits/js/notification/notificationSubscribeInfo.ts @@ -18,8 +18,8 @@ * * @name NotificationSubscribeInfo * @since 7 - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A */ export interface NotificationSubscribeInfo { diff --git a/interfaces/kits/js/notification/notificationSubscriber.d.ts b/interfaces/kits/js/notification/notificationSubscriber.d.ts index 309c15bb3..a659a9d0f 100644 --- a/interfaces/kits/js/notification/notificationSubscriber.d.ts +++ b/interfaces/kits/js/notification/notificationSubscriber.d.ts @@ -22,20 +22,20 @@ import notification from '../@ohos.notification'; * a notification is canceled. * * @name NotificationSubscriber - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A - * @systemApi + * @systemapi Hide this for inner system use. * @since 7 */ export interface NotificationSubscriber { - onConsumed?:(data: SubscribeCallbackData) => void; - onCanceled?:(data: SubscribeCallbackData) => void; + onConsume?:(data: SubscribeCallbackData) => void; + onCancel?:(data: SubscribeCallbackData) => void; onUpdate?:(data: NotificationSortingMap) => void; - onConnected?:() => void; - onDisConnect?:() => void; - onDied?:() => void; - onDisturbModeChanged?:(mode: notification.DoNotDisturbMode) => void; + onConnect?:() => void; + onDisconnect?:() => void; + onDestroy?:() => void; + onDisturbModeChange?:(mode: notification.DoNotDisturbMode) => void; } /** @@ -43,10 +43,10 @@ export interface NotificationSubscriber { * a notification is canceled. * * @name SubscribeCallbackData - * @sysCap ans - * @devices phone, tablet + * @sysCap SystemCapability.Notification.ANS + * @devices phone, tablet, tv, wearable, car * @permission N/A - * @systemApi + * @systemapi Hide this for inner system use. * @since 7 */ export interface SubscribeCallbackData { diff --git a/interfaces/kits/napi/ans/BUILD.gn b/interfaces/kits/napi/ans/BUILD.gn index d7d886beb..7592885e3 100755 --- a/interfaces/kits/napi/ans/BUILD.gn +++ b/interfaces/kits/napi/ans/BUILD.gn @@ -36,6 +36,7 @@ ohos_shared_library("notification") { "//foundation/aafwk/standard/frameworks/kits/ability/native/include", "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common", "//foundation/ace/napi/interfaces/kits/napi", + "//foundation/multimedia/image_standard/interfaces/kits/js/common/include/", "include", "//third_party/node/src", "//third_party/libuv/include", @@ -70,6 +71,7 @@ ohos_shared_library("notification") { "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", "//foundation/ace/napi:ace_napi", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//third_party/jsoncpp:jsoncpp", "//third_party/libuv:uv_static", "//utils/native/base:utils", diff --git a/interfaces/kits/napi/ans/include/get_active.h b/interfaces/kits/napi/ans/include/get_active.h index 011c3eb40..867eef8b0 100644 --- a/interfaces/kits/napi/ans/include/get_active.h +++ b/interfaces/kits/napi/ans/include/get_active.h @@ -24,7 +24,7 @@ using namespace OHOS::Notification; napi_value GetAllActiveNotifications(napi_env env, napi_callback_info info); napi_value GetActiveNotifications(napi_env env, napi_callback_info info); -napi_value GetActiveNotificationNums(napi_env env, napi_callback_info info); +napi_value GetActiveNotificationCount(napi_env env, napi_callback_info info); } // namespace NotificationNapi } // namespace OHOS diff --git a/interfaces/kits/napi/ans/include/slot.h b/interfaces/kits/napi/ans/include/slot.h index 789bc5376..e4e03749a 100644 --- a/interfaces/kits/napi/ans/include/slot.h +++ b/interfaces/kits/napi/ans/include/slot.h @@ -23,11 +23,11 @@ using namespace OHOS::Notification; napi_value AddSlot(napi_env env, napi_callback_info info); napi_value AddSlots(napi_env env, napi_callback_info info); -napi_value SetSlotAsBundle(napi_env env, napi_callback_info info); +napi_value SetSlotByBundle(napi_env env, napi_callback_info info); napi_value GetSlot(napi_env env, napi_callback_info info); -napi_value GetSlotNumAsBundle(napi_env env, napi_callback_info info); +napi_value GetSlotNumByBundle(napi_env env, napi_callback_info info); napi_value GetSlots(napi_env env, napi_callback_info info); -napi_value GetSlotsAsBundle(napi_env env, napi_callback_info info); +napi_value GetSlotsByBundle(napi_env env, napi_callback_info info); napi_value RemoveSlot(napi_env env, napi_callback_info info); napi_value RemoveAllSlots(napi_env env, napi_callback_info info); diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 09531dac6..a2543c73c 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -19,6 +19,7 @@ #include "notification_long_text_content.h" #include "notification_multiline_content.h" #include "notification_slot.h" +#include "pixel_map_napi.h" #include "publish.h" #include "want_agent.h" @@ -40,14 +41,6 @@ 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 GetNotificationSettingsText( -// const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationGroupValue( -// const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationGroupAlertType( -// const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationGroupOverview( -// 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); @@ -59,25 +52,17 @@ 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 GetNotificationVisibleness( -// const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationProgressBar( -// 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 GetNotificationOnlyLocal( -// const napi_env &env, const napi_value &value, NotificationRequest &request); -// static napi_value GetNotificationSortingKey(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 GetNotificationShortcutId( -// 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); @@ -207,11 +192,7 @@ napi_value Common::SetNotification( napi_create_string_utf8(env, notification->GetKey().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "hashCode", value); - // // ownerBundleName ?: string - // napi_create_string_utf8(env, notification->GetBundleName().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "ownerBundleName", value); - - // isFloatingIcon ?: boolean; + // isFloatingIcon ?: boolean napi_get_boolean(env, notification->IsFloatingIcon(), &value); napi_set_named_property(env, result, "isFloatingIcon", value); @@ -277,10 +258,6 @@ napi_value Common::SetNotificationRequest( napi_get_boolean(env, request->IsUnremovable(), &value); napi_set_named_property(env, result, "isUnremovable", value); - // // createTime?: number - // napi_create_int64(env, request->GetCreateTime(), &value); - // napi_set_named_property(env, result, "createTime", value); - // deliveryTime?: number napi_create_int64(env, request->GetDeliveryTime(), &value); napi_set_named_property(env, result, "deliveryTime", value); @@ -311,27 +288,6 @@ napi_value Common::SetNotificationRequest( napi_set_named_property(env, result, "extraInfo", extraInfo); } - // // settingsText ?: string - // napi_create_string_utf8(env, request->GetSettingsText().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "settingsText", value); - - // // ownerBundleName ?: string - // napi_create_string_utf8(env, notification->GetBundleName().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "ownerBundleName", value); - - // // groupValue ?: string - // napi_create_string_utf8(env, request->GetGroupValue().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "groupValue", value); - - // // groupAlertType ?: number - // int groupAlertType = (int)request->GetGroupAlertType(); - // napi_create_int32(env, groupAlertType, &value); - // napi_set_named_property(env, result, "groupAlertType", value); - - // // groupOverview ?: boolean - // napi_get_boolean(env, request->IsGroupOverview(), &value); - // napi_set_named_property(env, result, "groupOverview", value); - // removalWantAgent ?: WantAgent std::shared_ptr removalAgent = request->GetRemovalWantAgent(); if (removalAgent) { @@ -376,55 +332,14 @@ napi_value Common::SetNotificationRequest( napi_get_boolean(env, request->IsCountdownTimer(), &value); napi_set_named_property(env, result, "isCountDown", value); - // // visibleness ?: number - // int visibleness = (int)request->GetVisibleness(); - // napi_create_int32(env, visibleness, &value); - // napi_set_named_property(env, result, "visibleness", value); - - // // progressValue ?: number - // napi_create_int32(env, request->GetProgressValue(), &value); - // napi_set_named_property(env, result, "progressValue", value); - - // // progressMaxValue ?: number - // napi_create_int32(env, request->GetProgressMax(), &value); - // napi_set_named_property(env, result, "progressMaxValue", value); - - // // isIndeterminate ?: boolean - // napi_get_boolean(env, request->IsProgressIndeterminate(), &value); - // napi_set_named_property(env, result, "isIndeterminate", 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; do notification + // isFloatingIcon ?: boolean napi_get_boolean(env, request->IsFloatingIcon(), &value); napi_set_named_property(env, result, "isFloatingIcon", value); - // // onlyLocal ?: boolean - // napi_get_boolean(env, request->IsOnlyLocal(), &value); - // napi_set_named_property(env, result, "onlyLocal", value); - - // // sortingKey ?: string - // napi_create_string_utf8(env, request->GetSortingKey().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "sortingKey", value); - - // // messageUsers ?: Array - // napi_value arr; - // int count = 0; - // napi_create_array(env, &arr); - // for (auto vec : request->GetMessageUsers()) {notification - // if (vec) { - // napi_value messageUserResult; - // napi_create_object(env, &messageUserResult); - // if (SetMessageUser(env, vec, messageUserResult)) { - // napi_set_element(env, arr, count, messageUserResult); - // count++; - // } - // } - // } - // napi_set_named_property(env, result, "messageUsers", arr); - // label ?: string napi_create_string_utf8(env, request->GetLabel().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "label", value); @@ -434,10 +349,6 @@ napi_value Common::SetNotificationRequest( napi_create_int32(env, badgeIconStyle, &value); napi_set_named_property(env, result, "badgeIconStyle", value); - // // shortcutId ?: string - // napi_create_string_utf8(env, request->GetShortcutId().c_str(), NAPI_AUTO_LENGTH, &value); - // napi_set_named_property(env, result, "shortcutId", value); - // showDeliveryTime ?: boolean napi_get_boolean(env, request->IsShowDeliveryTime(), &value); napi_set_named_property(env, result, "showDeliveryTime", value); @@ -458,8 +369,35 @@ napi_value Common::SetNotificationRequest( } napi_set_named_property(env, result, "actionButtons", arr); - // smallIcon ?: image.PixelMap; do - // largeIcon ?: image.PixelMap; do + // smallIcon ?: image.PixelMap + std::shared_ptr littleIcon = request->GetLittleIcon(); + if (littleIcon) { + napi_value smallIconResult = nullptr; + napi_valuetype valuetype = napi_undefined; + smallIconResult = Media::PixelMapNapi::CreatePixelMap(env, littleIcon); + NAPI_CALL(env, napi_typeof(env, smallIconResult, &valuetype)); + if (valuetype == napi_undefined) { + ANS_LOGI("smallIconResult is undefined"); + napi_set_named_property(env, result, "smallIcon", NapiGetNull(env)); + } else { + napi_set_named_property(env, result, "smallIcon", smallIconResult); + } + } + + // largeIcon ?: image.PixelMap + std::shared_ptr largeIcon = request->GetBigIcon(); + if (largeIcon) { + napi_value largeIconResult = nullptr; + napi_valuetype valuetype = napi_undefined; + largeIconResult = Media::PixelMapNapi::CreatePixelMap(env, largeIcon); + NAPI_CALL(env, napi_typeof(env, largeIconResult, &valuetype)); + if (valuetype == napi_undefined) { + ANS_LOGI("largeIconResult is undefined"); + napi_set_named_property(env, result, "largeIcon", NapiGetNull(env)); + } else { + napi_set_named_property(env, result, "largeIcon", largeIconResult); + } + } // readonly creatorBundleName?: string napi_create_string_utf8(env, request->GetCreatorBundleName().c_str(), NAPI_AUTO_LENGTH, &value); @@ -552,10 +490,6 @@ napi_value Common::SetNotificationSorting(const napi_env &env, const Notificatio napi_get_boolean(env, sorting.IsHiddenNotification(), &value); napi_set_named_property(env, result, "isHiddenNotification", value); - // isSuitInterruptionFilter?: boolean ??????? do - // napi_get_boolean(env, sorting->isOrdered, &value); - // napi_set_named_property(env, result, "isSuitInterruptionFilter", value); - // importance?: number napi_create_int32(env, sorting.GetImportance(), &value); napi_set_named_property(env, result, "importance", value); @@ -576,7 +510,7 @@ napi_value Common::SetNotificationSlot(const napi_env &env, const NotificationSl ANS_LOGI("enter"); napi_value value = nullptr; - // type: SlotType; + // type: SlotType enum SlotType outType = SlotType::UNKNOWN_TYPE; if (!SlotTypeCToJS(slot.GetType(), outType)) { return NapiGetboolean(env, false); @@ -649,7 +583,7 @@ napi_value Common::SetNotificationContent( } napi_value value = nullptr; - // contentType: ContentType; + // contentType: ContentType NotificationContent::Type type = content->GetContentType(); ContentType outType = ContentType::NOTIFICATION_CONTENT_BASIC_TEXT; if (!ContentTypeCToJS(type, outType)) { @@ -737,15 +671,15 @@ napi_value Common::SetNotificationBasicContent( napi_value value = nullptr; - // title: string; + // title: string napi_create_string_utf8(env, basicContent->GetTitle().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "title", value); - // text: string; + // text: string napi_create_string_utf8(env, basicContent->GetText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "text", value); - // additionalText?: string; + // additionalText?: string napi_create_string_utf8(env, basicContent->GetAdditionalText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "additionalText", value); @@ -799,8 +733,6 @@ napi_value Common::SetNotificationPictureContent( napi_value value = nullptr; - // pictureId: number //c++ no do - // briefText: string napi_create_string_utf8(env, pictureContent->GetBriefText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "briefText", value); @@ -809,8 +741,20 @@ napi_value Common::SetNotificationPictureContent( napi_create_string_utf8(env, pictureContent->GetExpandedTitle().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "expandedTitle", value); - // bigPicture: image.PixelMap //do - + // picture: image.PixelMap + std::shared_ptr picture = pictureContent->GetBigPicture(); + if (picture) { + napi_value pictureResult = nullptr; + napi_valuetype valuetype = napi_undefined; + pictureResult = Media::PixelMapNapi::CreatePixelMap(env, picture); + NAPI_CALL(env, napi_typeof(env, pictureResult, &valuetype)); + if (valuetype == napi_undefined) { + ANS_LOGI("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); } @@ -913,8 +857,6 @@ napi_value Common::SetMessageUser(const napi_env &env, const MessageUser &messag napi_create_string_utf8(env, messageUser.GetName().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "name", value); - // pixelMap: image.PixelMap //do - // uri: string napi_create_string_utf8(env, messageUser.GetUri().ToString().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "uri", value); @@ -948,19 +890,19 @@ napi_value Common::SetConversationalMessage(const napi_env &env, napi_create_string_utf8(env, conversationalMessage->GetText().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "text", value); - // timestamp: number; + // timestamp: number napi_create_int64(env, conversationalMessage->GetArrivedTime(), &value); napi_set_named_property(env, result, "timestamp", value); - // mimeType: string; + // mimeType: string napi_create_string_utf8(env, conversationalMessage->GetMimeType().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "mimeType", value); - // uri: string; + // uri: string napi_create_string_utf8(env, conversationalMessage->GetUri()->ToString().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, "uri", value); - // sender: MessageUser; + // sender: MessageUser napi_value messageUserResult = nullptr; napi_create_object(env, &messageUserResult); if (SetMessageUser(env, conversationalMessage->GetSender(), messageUserResult)) { @@ -988,17 +930,29 @@ napi_value Common::SetNotificationActionButton( // wantAgent: WantAgent std::shared_ptr agent = actionButton->GetWantAgent(); - if (!agent) { + if (agent == nullptr) { ANS_LOGI("wantAgent is null"); napi_set_named_property(env, result, "wantAgent", NapiGetNull(env)); - return NapiGetboolean(env, true); + return NapiGetboolean(env, false); } napi_value wantAgent = nullptr; wantAgent = CreateWantAgentByJS(env, agent); napi_set_named_property(env, result, "wantAgent", wantAgent); - // extras?: {[key: string]: any} //do - // icon?: image.PixelMap //do + // icon?: image.PixelMap + std::shared_ptr icon = actionButton->GetIcon(); + 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_LOGI("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); } @@ -1011,7 +965,7 @@ napi_value Common::GetNotificationSubscriberInfo( bool isArray = false; napi_valuetype valuetype = napi_undefined; - // bundleNames?: Array; + // bundleNames?: Array NAPI_CALL(env, napi_has_named_property(env, value, "bundleNames", &hasProperty)); if (hasProperty) { napi_value nBundleNames = nullptr; @@ -1032,28 +986,7 @@ napi_value Common::GetNotificationSubscriberInfo( } } - // // deviceIds?: Array; - // NAPI_CALL(env, napi_has_named_property(env, value, "deviceIds", &hasProperty)); - // if (hasProperty) { - // napi_value nDeviceIds = nullptr; - // napi_get_named_property(env, value, "deviceIds", &nDeviceIds); - // napi_is_array(env, nDeviceIds, &isArray); - // NAPI_ASSERT(env, isArray, "Property bundleNames 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 nDeviceId = nullptr; - // char str[STR_MAX_SIZE] = {0}; - // napi_get_element(env, nDeviceIds, i, &nDeviceId); - // NAPI_CALL(env, napi_typeof(env, nDeviceId, &valuetype)); - // NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - // NAPI_CALL(env, napi_get_value_string_utf8(env, nDeviceId, str, STR_MAX_SIZE - 1, &strLen)); - // subscriberInfo.deviceIds.emplace_back(str); - // subscriberInfo.hasSubscribeInfo = true; - // } - // } - - // userId?: number; + // userId?: number NAPI_CALL(env, napi_has_named_property(env, value, "userId", &hasProperty)); if (hasProperty) { napi_value nUserId = nullptr; @@ -1131,26 +1064,6 @@ napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value return nullptr; } - // // settingsText?: string - // if (GetNotificationSettingsText(env, value, request) == nullptr) { - // return nullptr; - // } - - // // groupValue?: string - // if (GetNotificationGroupValue(env, value, request) == nullptr) { - // return nullptr; - // } - - // // groupAlertType?: number - // if (GetNotificationGroupAlertType(env, value, request) == nullptr) { - // return nullptr; - // } - - // // groupOverview?: boolean - // if (GetNotificationGroupOverview(env, value, request) == nullptr) { - // return nullptr; - // } - // classification?: string if (GetNotificationClassification(env, value, request) == nullptr) { return nullptr; @@ -1181,33 +1094,11 @@ napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value return nullptr; } - // // visibleness?: number - // if (GetNotificationVisibleness(env, value, request) == nullptr) { - // return nullptr; - // } - - // // progressValue?: number - // // progressMaxValue?: number - // // isIndeterminate?: boolean - // if (GetNotificationProgressBar(env, value, request) == nullptr) { - // return nullptr; - // } - // statusBarText?: string if (GetNotificationStatusBarText(env, value, request) == nullptr) { return nullptr; } - // // onlyLocal?: boolean - // if (GetNotificationOnlyLocal(env, value, request) == nullptr) { - // return nullptr; - // } - - // // sortingKey?: string - // if (GetNotificationSortingKey(env, value, request) == nullptr) { - // return nullptr; - // } - // label?: string if (GetNotificationLabel(env, value, request) == nullptr) { return nullptr; @@ -1218,11 +1109,6 @@ napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value return nullptr; } - // // shortcutId?: string - // if (GetNotificationShortcutId(env, value, request) == nullptr) { - // return nullptr; - // } - // showDeliveryTime?: boolean if (GetNotificationShowDeliveryTime(env, value, request) == nullptr) { return nullptr; @@ -1233,6 +1119,16 @@ napi_value Common::GetNotificationRequest(const napi_env &env, const napi_value 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 Common::NapiGetNull(env); } @@ -1560,98 +1456,6 @@ napi_value GetNotificationAutoDeletedTime(const napi_env &env, const napi_value return Common::NapiGetNull(env); } -// napi_value GetNotificationSettingsText( -// 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; -// char str[STR_MAX_SIZE] = {0}; -// size_t strLen = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "settingsText", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "settingsText", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); -// NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); -// request.SetSettingsText(str); -// } - -// ANS_LOGI("===============GetNotificationSettingsText====settingsText = %{public}s end", str); -// return Common::NapiGetNull(env); -// } - -// napi_value GetNotificationGroupValue( -// 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; -// char str[STR_MAX_SIZE] = {0}; -// size_t strLen = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "groupValue", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "groupValue", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); -// NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); -// request.SetGroupValue(str); -// } - -// ANS_LOGI("===============GetNotificationGroupValue====groupValue = %{public}s end", str); -// return Common::NapiGetNull(env); -// } - -// napi_value GetNotificationGroupAlertType( -// 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; -// int32_t groupAlertType = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "groupAlertType", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "groupAlertType", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); -// napi_get_value_int32(env, result, &groupAlertType); -// request.SetGroupAlertType(static_cast(groupAlertType)); -// } - -// return Common::NapiGetNull(env); -// } - -// napi_value GetNotificationGroupOverview( -// 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; -// bool groupOverview = false; - -// NAPI_CALL(env, napi_has_named_property(env, value, "groupOverview", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "groupOverview", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); -// napi_get_value_bool(env, result, &groupOverview); -// request.SetGroupOverview(groupOverview); -// } - -// return Common::NapiGetNull(env); -// } - napi_value GetNotificationClassification(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1780,68 +1584,6 @@ napi_value GetNotificationIsCountDown(const napi_env &env, const napi_value &val return Common::NapiGetNull(env); } -// napi_value GetNotificationVisibleness( -// 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; -// int32_t visibleness = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "visibleness", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "visibleness", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); -// napi_get_value_int32(env, result, &visibleness); -// request.SetVisibleness(static_cast(visibleness)); -// } - -// return Common::NapiGetNull(env); -// } - -// napi_value GetNotificationProgressBar(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; -// int32_t progressValue = 0; -// int32_t progressMaxValue = 0; -// bool isIndeterminate = false; - -// NAPI_CALL(env, napi_has_named_property(env, value, "progressValue", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "progressValue", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); -// napi_get_value_int32(env, result, &progressValue); -// } - -// NAPI_CALL(env, napi_has_named_property(env, value, "progressMaxValue", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "progressMaxValue", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); -// napi_get_value_int32(env, result, &progressMaxValue); -// } - -// NAPI_CALL(env, napi_has_named_property(env, value, "isIndeterminate", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "isIndeterminate", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); -// napi_get_value_bool(env, result, &isIndeterminate); -// } - -// request.SetProgressBar(progressValue, progressMaxValue, isIndeterminate); - -// return Common::NapiGetNull(env); -// } - napi_value GetNotificationStatusBarText(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1864,50 +1606,6 @@ napi_value GetNotificationStatusBarText(const napi_env &env, const napi_value &v return Common::NapiGetNull(env); } -// napi_value GetNotificationOnlyLocal(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; -// bool onlyLocal = false; - -// NAPI_CALL(env, napi_has_named_property(env, value, "onlyLocal", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "onlyLocal", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. bool expected."); -// napi_get_value_bool(env, result, &onlyLocal); -// request.SetOnlyLocal(onlyLocal); -// } - -// return Common::NapiGetNull(env); -// } - -// napi_value GetNotificationSortingKey(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; -// char str[STR_MAX_SIZE] = {0}; -// size_t strLen = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "sortingKey", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "sortingKey", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); -// NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); -// request.SetSortingKey(str); -// } - -// return Common::NapiGetNull(env); -// } - napi_value GetNotificationLabel(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -1951,30 +1649,6 @@ napi_value GetNotificationBadgeIconStyle(const napi_env &env, const napi_value & return Common::NapiGetNull(env); } -// napi_value GetNotificationShortcutId( -// 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; -// char str[STR_MAX_SIZE] = {0}; -// size_t strLen = 0; - -// NAPI_CALL(env, napi_has_named_property(env, value, "shortcutId", &hasProperty)); -// if (hasProperty) { -// napi_get_named_property(env, value, "shortcutId", &result); -// NAPI_CALL(env, napi_typeof(env, result, &valuetype)); -// NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); -// NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); -// request.SetShortcutId(str); -// } - -// ANS_LOGI("===============GetNotificationShortcutId====shortcutId = %{public}s end", str); -// return Common::NapiGetNull(env); -// } - napi_value GetNotificationShowDeliveryTime(const napi_env &env, const napi_value &value, NotificationRequest &request) { ANS_LOGI("enter"); @@ -2010,8 +1684,10 @@ napi_value GetNotificationNotificationActionButtons( 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); @@ -2030,7 +1706,7 @@ napi_value GetNotificationNotificationActionButtons( NAPI_CALL(env, napi_typeof(env, actionButton, &valuetype)); NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); - // title: string; + // title: string NAPI_CALL(env, napi_has_named_property(env, actionButton, "title", &hasProperty)); if (hasProperty) { napi_get_named_property(env, actionButton, "title", &titelActionButton); @@ -2043,7 +1719,7 @@ napi_value GetNotificationNotificationActionButtons( return nullptr; } - // wantAgent: WantAgent; + // wantAgent: WantAgent NAPI_CALL(env, napi_has_named_property(env, actionButton, "wantAgent", &hasProperty)); if (hasProperty) { napi_get_named_property(env, actionButton, "wantAgent", &wantAgentActionButton); @@ -2060,16 +1736,76 @@ napi_value GetNotificationNotificationActionButtons( return nullptr; } - // extras?: {[key: string]: any}; + // 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; + } + } - std::vector> vec; - auto pActionButton = NotificationActionButton::Create(nullptr, title, wantAgent); + auto pActionButton = NotificationActionButton::Create(pixelMap, title, wantAgent); request.AddActionButton(pActionButton); } return Common::NapiGetNull(env); } +napi_value 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 Common::NapiGetNull(env); +} + +napi_value 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 Common::NapiGetNull(env); +} + napi_value GetNotificationContentType(const napi_env &env, const napi_value &result, int32_t &type) { ANS_LOGI("enter"); @@ -2115,7 +1851,7 @@ napi_value GetNotificationBasicContent(const napi_env &env, const napi_value &re return nullptr; } - // title: string; + // title: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "title", &basicContentResult); @@ -2129,7 +1865,7 @@ napi_value GetNotificationBasicContent(const napi_env &env, const napi_value &re return nullptr; } - // text: string; + // text: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "text", &basicContentResult); @@ -2143,7 +1879,7 @@ napi_value GetNotificationBasicContent(const napi_env &env, const napi_value &re return nullptr; } - // additionalText?: string; + // additionalText?: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "additionalText", &basicContentResult); @@ -2185,7 +1921,7 @@ napi_value GetNotificationLongTextContent(const napi_env &env, const napi_value return nullptr; } - // title: string; + // title: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "title", &basicContentResult); @@ -2199,7 +1935,7 @@ napi_value GetNotificationLongTextContent(const napi_env &env, const napi_value return nullptr; } - // text: string; + // text: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "text", &basicContentResult); @@ -2213,7 +1949,7 @@ napi_value GetNotificationLongTextContent(const napi_env &env, const napi_value return nullptr; } - // additionalText?: string; + // additionalText?: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "additionalText", &basicContentResult); @@ -2224,7 +1960,7 @@ napi_value GetNotificationLongTextContent(const napi_env &env, const napi_value ANS_LOGI("longText::additionalText = %{public}s", str); } - // longText: string; + // longText: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "longText", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "longText", &longContentResult); @@ -2238,7 +1974,7 @@ napi_value GetNotificationLongTextContent(const napi_env &env, const napi_value return nullptr; } - // briefText: string; + // briefText: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "briefText", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "briefText", &longContentResult); @@ -2252,7 +1988,7 @@ napi_value GetNotificationLongTextContent(const napi_env &env, const napi_value return nullptr; } - // expandedTitle: string; + // expandedTitle: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "expandedTitle", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "expandedTitle", &longContentResult); @@ -2296,7 +2032,7 @@ napi_value GetNotificationPictureContent(const napi_env &env, const napi_value & return nullptr; } - // title: string; + // title: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "title", &basicContentResult); @@ -2310,7 +2046,7 @@ napi_value GetNotificationPictureContent(const napi_env &env, const napi_value & return nullptr; } - // text: string; + // text: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "text", &basicContentResult); @@ -2324,7 +2060,7 @@ napi_value GetNotificationPictureContent(const napi_env &env, const napi_value & return nullptr; } - // additionalText?: string; + // additionalText?: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "additionalText", &basicContentResult); @@ -2335,7 +2071,7 @@ napi_value GetNotificationPictureContent(const napi_env &env, const napi_value & ANS_LOGI("pictureText::additionalText = %{public}s", str); } - // briefText: string; + // briefText: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "briefText", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "briefText", &pictureContentResult); @@ -2349,7 +2085,7 @@ napi_value GetNotificationPictureContent(const napi_env &env, const napi_value & return nullptr; } - // expandedTitle: string; + // expandedTitle: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "expandedTitle", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "expandedTitle", &pictureContentResult); @@ -2363,8 +2099,23 @@ napi_value GetNotificationPictureContent(const napi_env &env, const napi_value & return nullptr; } - // bigPicture: image.PixelMap do - + // 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."); + return nullptr; + } request.SetContent(std::make_shared(pictureContent)); return Common::NapiGetNull(env); @@ -2393,8 +2144,6 @@ napi_value GetMessageUser(const napi_env &env, const napi_value &result, Message return nullptr; } - // pixelMap: image.PixelMap do - // uri: string NAPI_CALL(env, napi_has_named_property(env, result, "uri", &hasProperty)); if (hasProperty) { @@ -2597,7 +2346,7 @@ napi_value GetNotificationConversationalContent( return nullptr; } - // title: string; + // title: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "title", &basicContentResult); @@ -2611,7 +2360,7 @@ napi_value GetNotificationConversationalContent( return nullptr; } - // text: string; + // text: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "text", &basicContentResult); @@ -2625,7 +2374,7 @@ napi_value GetNotificationConversationalContent( return nullptr; } - // additionalText?: string; + // additionalText?: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "additionalText", &basicContentResult); @@ -2636,7 +2385,7 @@ napi_value GetNotificationConversationalContent( ANS_LOGI("conversationalText::additionalText = %{public}s", str); } - // conversationTitle: string; + // conversationTitle: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "conversationTitle", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "conversationTitle", &conversationalContentResult); @@ -2650,7 +2399,7 @@ napi_value GetNotificationConversationalContent( return nullptr; } - // conversationGroup: boolean; + // conversationGroup: boolean NAPI_CALL(env, napi_has_named_property(env, contentResult, "conversationGroup", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "conversationGroup", &conversationalContentResult); @@ -2665,7 +2414,7 @@ napi_value GetNotificationConversationalContent( return nullptr; } - // messages: Array; + // messages: Array NAPI_CALL(env, napi_has_named_property(env, contentResult, "messages", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "messages", &conversationalContentResult); @@ -2721,7 +2470,7 @@ napi_value GetNotificationMultiLineContent(const napi_env &env, const napi_value return nullptr; } - // title: string; + // title: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "title", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "title", &basicContentResult); @@ -2735,7 +2484,7 @@ napi_value GetNotificationMultiLineContent(const napi_env &env, const napi_value return nullptr; } - // text: string; + // text: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "text", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "text", &basicContentResult); @@ -2749,7 +2498,7 @@ napi_value GetNotificationMultiLineContent(const napi_env &env, const napi_value return nullptr; } - // additionalText?: string; + // additionalText?: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "additionalText", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "additionalText", &basicContentResult); @@ -2760,7 +2509,7 @@ napi_value GetNotificationMultiLineContent(const napi_env &env, const napi_value ANS_LOGI("multiLine::additionalText = %{public}s", str); } - // briefText: string; + // briefText: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "briefText", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "briefText", &multiLineContentResult); @@ -2774,7 +2523,7 @@ napi_value GetNotificationMultiLineContent(const napi_env &env, const napi_value return nullptr; } - // longTitle: string; + // longTitle: string NAPI_CALL(env, napi_has_named_property(env, contentResult, "longTitle", &hasProperty)); if (hasProperty) { napi_get_named_property(env, contentResult, "longTitle", &multiLineContentResult); @@ -2788,7 +2537,7 @@ napi_value GetNotificationMultiLineContent(const napi_env &env, const napi_value return nullptr; } - // lines: Array; + // lines: Array NAPI_CALL(env, napi_has_named_property(env, contentResult, "lines", &hasProperty)); if (hasProperty) { if (GetNotificationMultiLineContentLines(env, contentResult, multiLineContent) == nullptr) { @@ -3010,7 +2759,7 @@ napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; - // bundle: string; + // bundle: string NAPI_CALL(env, napi_has_named_property(env, value, "bundle", &hasProperty)); NAPI_ASSERT(env, hasProperty, "Property bundle expected."); napi_get_named_property(env, value, "bundle", &result); @@ -3019,7 +2768,7 @@ napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); option.bundle = str; - // uid?: number; + // uid?: number NAPI_CALL(env, napi_has_named_property(env, value, "uid", &hasProperty)); if (hasProperty) { napi_get_named_property(env, value, "uid", &result); @@ -3039,7 +2788,7 @@ napi_value Common::GetNotificationKey(const napi_env &env, const napi_value &val napi_valuetype valuetype = napi_undefined; napi_value result = nullptr; - // id: number; + // id: number NAPI_CALL(env, napi_has_named_property(env, value, "id", &hasProperty)); NAPI_ASSERT(env, hasProperty, "Property id expected."); napi_get_named_property(env, value, "id", &result); @@ -3047,7 +2796,7 @@ napi_value Common::GetNotificationKey(const napi_env &env, const napi_value &val NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); napi_get_value_int32(env, result, &key.id); - // lable?: string; + // label?: string NAPI_CALL(env, napi_has_named_property(env, value, "label", &hasProperty)); if (hasProperty) { char str[STR_MAX_SIZE] = {0}; @@ -3071,18 +2820,9 @@ bool Common::ContentTypeJSToC(const enum ContentType &inType, enum NotificationC case ContentType::NOTIFICATION_CONTENT_LONG_TEXT: outType = NotificationContent::Type::LONG_TEXT; break; - // case ContentType::NOTIFICATION_CONTENT_PICTURE: - // outType = NotificationContent::Type::PICTURE; - // break; - // case ContentType::NOTIFICATION_CONTENT_CONVERSATION: - // outType = NotificationContent::Type::CONVERSATION; - // break; case ContentType::NOTIFICATION_CONTENT_MULTILINE: outType = NotificationContent::Type::MULTILINE; break; - // case ContentType::NOTIFICATION_CONTENT_MEDIA: - // outType = NotificationContent::Type::MEDIA; - // break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); return false; @@ -3099,18 +2839,9 @@ bool Common::ContentTypeCToJS(const enum NotificationContent::Type &inType, enum case NotificationContent::Type::LONG_TEXT: outType = ContentType::NOTIFICATION_CONTENT_LONG_TEXT; break; - // case NotificationContent::Type::PICTURE: - // outType = ContentType::NOTIFICATION_CONTENT_PICTURE; - // break; - // case NotificationContent::Type::CONVERSATION: - // outType = ContentType::NOTIFICATION_CONTENT_CONVERSATION; - // break; case NotificationContent::Type::MULTILINE: outType = ContentType::NOTIFICATION_CONTENT_MULTILINE; break; - // case NotificationContent::Type::MEDIA: - // outType = ContentType::NOTIFICATION_CONTENT_MEDIA; - // break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); return false; diff --git a/interfaces/kits/napi/ans/src/display_badge.cpp b/interfaces/kits/napi/ans/src/display_badge.cpp index 52d895636..129355a8f 100644 --- a/interfaces/kits/napi/ans/src/display_badge.cpp +++ b/interfaces/kits/napi/ans/src/display_badge.cpp @@ -75,9 +75,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[2]:callback if (argc >= ENABLE_BADGE_DISPLAYED_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[ENABLE_BADGE_DISPLAYED_MAX_PARA - 1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[2], 1, ¶ms.callback); + napi_create_reference(env, argv[ENABLE_BADGE_DISPLAYED_MAX_PARA - 1], 1, ¶ms.callback); } return Common::NapiGetNull(env); diff --git a/interfaces/kits/napi/ans/src/enable_notification.cpp b/interfaces/kits/napi/ans/src/enable_notification.cpp index 014c6c3e6..ae680b46b 100644 --- a/interfaces/kits/napi/ans/src/enable_notification.cpp +++ b/interfaces/kits/napi/ans/src/enable_notification.cpp @@ -75,9 +75,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[2]:callback if (argc >= ENABLE_NOTIFICATION_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[ENABLE_NOTIFICATION_MAX_PARA - 1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[2], 1, ¶ms.callback); + napi_create_reference(env, argv[ENABLE_NOTIFICATION_MAX_PARA - 1], 1, ¶ms.callback); } return Common::NapiGetNull(env); diff --git a/interfaces/kits/napi/ans/src/get_active.cpp b/interfaces/kits/napi/ans/src/get_active.cpp index cf9bab8a6..d763bd058 100644 --- a/interfaces/kits/napi/ans/src/get_active.cpp +++ b/interfaces/kits/napi/ans/src/get_active.cpp @@ -239,7 +239,7 @@ napi_value GetActiveNotifications(napi_env env, napi_callback_info info) } } -napi_value GetActiveNotificationNums(napi_env env, napi_callback_info info) +napi_value GetActiveNotificationCount(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); @@ -257,19 +257,19 @@ napi_value GetActiveNotificationNums(napi_env env, napi_callback_info info) Common::PaddingCallbackPromiseInfo(env, callback, asynccallbackinfo->info, promise); napi_value resourceName = nullptr; - napi_create_string_latin1(env, "getActiveNotificationNums", NAPI_AUTO_LENGTH, &resourceName); + napi_create_string_latin1(env, "getActiveNotificationCount", NAPI_AUTO_LENGTH, &resourceName); // Asynchronous function call napi_create_async_work( env, nullptr, resourceName, [](napi_env env, void *data) { - ANS_LOGI("GetActiveNotificationNums napi_create_async_work start"); + ANS_LOGI("GetActiveNotificationCount napi_create_async_work start"); AsyncCallbackInfoActive *asynccallbackinfo = (AsyncCallbackInfoActive *)data; int32_t num = 0; asynccallbackinfo->info.errorCode = NotificationHelper::GetActiveNotificationNums(num); - ANS_LOGI("GetActiveNotificationNums nums = %{public}d", num); + ANS_LOGI("GetActiveNotificationCount count = %{public}d", num); if (asynccallbackinfo->info.errorCode != ERR_OK) { asynccallbackinfo->result = Common::NapiGetNull(env); return; @@ -277,7 +277,7 @@ napi_value GetActiveNotificationNums(napi_env env, napi_callback_info info) napi_create_int32(env, num, &asynccallbackinfo->result); }, [](napi_env env, napi_status status, void *data) { - ANS_LOGI("GetActiveNotificationNums napi_create_async_work end"); + ANS_LOGI("GetActiveNotificationCount napi_create_async_work end"); AsyncCallbackInfoActive *asynccallbackinfo = (AsyncCallbackInfoActive *)data; Common::ReturnCallbackPromise(env, asynccallbackinfo->info, asynccallbackinfo->result); diff --git a/interfaces/kits/napi/ans/src/init.cpp b/interfaces/kits/napi/ans/src/init.cpp index 64869c224..864e4a775 100644 --- a/interfaces/kits/napi/ans/src/init.cpp +++ b/interfaces/kits/napi/ans/src/init.cpp @@ -44,16 +44,16 @@ napi_value NotificationInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("removeAll", RemoveAll), DECLARE_NAPI_FUNCTION("getAllActiveNotifications", GetAllActiveNotifications), DECLARE_NAPI_FUNCTION("getActiveNotifications", GetActiveNotifications), - DECLARE_NAPI_FUNCTION("getActiveNotificationNums", GetActiveNotificationNums), + DECLARE_NAPI_FUNCTION("getActiveNotificationCount", GetActiveNotificationCount), DECLARE_NAPI_FUNCTION("cancel", Cancel), DECLARE_NAPI_FUNCTION("cancelAll", CancelAll), DECLARE_NAPI_FUNCTION("addSlot", AddSlot), DECLARE_NAPI_FUNCTION("addSlots", AddSlots), - DECLARE_NAPI_FUNCTION("setSlotAsBundle", SetSlotAsBundle), + DECLARE_NAPI_FUNCTION("setSlotByBundle", SetSlotByBundle), DECLARE_NAPI_FUNCTION("getSlot", GetSlot), - DECLARE_NAPI_FUNCTION("getSlotNumAsBundle", GetSlotNumAsBundle), + DECLARE_NAPI_FUNCTION("getSlotNumByBundle", GetSlotNumByBundle), DECLARE_NAPI_FUNCTION("getSlots", GetSlots), - DECLARE_NAPI_FUNCTION("getSlotsAsBundle", GetSlotsAsBundle), + DECLARE_NAPI_FUNCTION("getSlotsByBundle", GetSlotsByBundle), DECLARE_NAPI_FUNCTION("removeSlot", RemoveSlot), DECLARE_NAPI_FUNCTION("removeAllSlots", RemoveAllSlots), DECLARE_NAPI_FUNCTION("enableNotification", EnableNotification), diff --git a/interfaces/kits/napi/ans/src/remove.cpp b/interfaces/kits/napi/ans/src/remove.cpp index a2c4f62ba..8cae75ede 100644 --- a/interfaces/kits/napi/ans/src/remove.cpp +++ b/interfaces/kits/napi/ans/src/remove.cpp @@ -97,9 +97,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[2]:callback if (argc >= REMOVE_BY_BUNDLE_AND_KEY_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[REMOVE_BY_BUNDLE_AND_KEY_MAX_PARA - 1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[2], 1, ¶ms.callback); + napi_create_reference(env, argv[REMOVE_BY_BUNDLE_AND_KEY_MAX_PARA - 1], 1, ¶ms.callback); } } diff --git a/interfaces/kits/napi/ans/src/slot.cpp b/interfaces/kits/napi/ans/src/slot.cpp index 19350c716..3b493f2c6 100644 --- a/interfaces/kits/napi/ans/src/slot.cpp +++ b/interfaces/kits/napi/ans/src/slot.cpp @@ -25,7 +25,7 @@ const int GET_SLOT_NUM_AS_BUNDLE_MAX_PARA = 2; const int GET_SLOTS_MAX_PARA = 1; const int GET_SLOTS_AS_BUNDLE_MAX_PARA = 2; const int REMOVE_SLOT_MAX_PARA = 2; -const int REMOVE_ALL_MAX_PARA = 1; +const int REMOVE_ALL_SLOTS_MAX_PARA = 1; struct ParametersInfoAddSlot { NotificationSlot slot; @@ -55,16 +55,16 @@ struct AsyncCallbackInfoAddSlots { CallbackPromiseInfo info; }; -struct ParametersInfoSetSlotAsBundle { +struct ParametersInfoSetSlotByBundle { BundleOption option; std::vector> slots; napi_ref callback = nullptr; }; -struct AsyncCallbackInfoSetSlotAsBundle { +struct AsyncCallbackInfoSetSlotByBundle { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - ParametersInfoSetSlotAsBundle params; + ParametersInfoSetSlotByBundle params; CallbackPromiseInfo info; }; @@ -81,16 +81,16 @@ struct AsyncCallbackInfoGetSlot { CallbackPromiseInfo info; }; -struct ParametersInfoGetSlotNumAsBundle { +struct ParametersInfoGetSlotNumByBundle { BundleOption option; napi_ref callback = nullptr; }; -struct AsyncCallbackInfoGetSlotNumAsBundle { +struct AsyncCallbackInfoGetSlotNumByBundle { napi_env env = nullptr; napi_async_work asyncWork = nullptr; napi_value result = nullptr; - ParametersInfoGetSlotNumAsBundle params; + ParametersInfoGetSlotNumByBundle params; CallbackPromiseInfo info; }; @@ -101,16 +101,16 @@ struct AsyncCallbackInfoGetSlots { CallbackPromiseInfo info; }; -struct ParametersInfoGetSlotsAsBundle { +struct ParametersInfoGetSlotsByBundle { BundleOption option; napi_ref callback = nullptr; }; -struct AsyncCallbackInfoGetSlotsAsBundle { +struct AsyncCallbackInfoGetSlotsByBundle { napi_env env = nullptr; napi_async_work asyncWork = nullptr; napi_value result = nullptr; - ParametersInfoGetSlotsAsBundle params; + ParametersInfoGetSlotsByBundle params; CallbackPromiseInfo info; }; @@ -207,8 +207,8 @@ napi_value ParseParametersByAddSlots(const napi_env &env, const napi_callback_in return Common::NapiGetNull(env); } -napi_value ParseParametersSetSlotAsBundle( - const napi_env &env, const napi_callback_info &info, ParametersInfoSetSlotAsBundle ¶ms) +napi_value ParseParametersSetSlotByBundle( + const napi_env &env, const napi_callback_info &info, ParametersInfoSetSlotByBundle ¶ms) { ANS_LOGI("enter"); @@ -249,9 +249,9 @@ napi_value ParseParametersSetSlotAsBundle( // argv[2]:callback if (argc >= SET_SLOT_AS_BUNDLE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[SET_SLOT_AS_BUNDLE_MAX_PARA - 1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[2], 1, ¶ms.callback); + napi_create_reference(env, argv[SET_SLOT_AS_BUNDLE_MAX_PARA - 1], 1, ¶ms.callback); } return Common::NapiGetNull(env); @@ -285,8 +285,8 @@ napi_value ParseParametersByGetSlot(const napi_env &env, const napi_callback_inf return Common::NapiGetNull(env); } -napi_value ParseParametersGetSlotNumAsBundle( - const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotNumAsBundle ¶ms) +napi_value ParseParametersGetSlotNumByBundle( + const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotNumByBundle ¶ms) { ANS_LOGI("enter"); @@ -334,8 +334,8 @@ napi_value ParseParametersByGetSlots(const napi_env &env, const napi_callback_in return Common::NapiGetNull(env); } -napi_value ParseParametersGetSlotsAsBundle( - const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotsAsBundle ¶ms) +napi_value ParseParametersGetSlotsByBundle( + const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotsByBundle ¶ms) { ANS_LOGI("enter"); @@ -397,12 +397,12 @@ napi_value ParseParametersByRemoveSlot( napi_value ParseParametersByRemoveAllSlots(const napi_env &env, const napi_callback_info &info, napi_ref &callback) { ANS_LOGI("enter"); - size_t argc = REMOVE_ALL_MAX_PARA; - napi_value argv[REMOVE_ALL_MAX_PARA] = {nullptr}; + size_t argc = REMOVE_ALL_SLOTS_MAX_PARA; + napi_value argv[REMOVE_ALL_SLOTS_MAX_PARA] = {nullptr}; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - if (argc >= REMOVE_ALL_MAX_PARA) { + if (argc >= REMOVE_ALL_SLOTS_MAX_PARA) { napi_valuetype valuetype = napi_undefined; // argv[0]:callback NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); @@ -531,17 +531,17 @@ napi_value AddSlots(napi_env env, napi_callback_info info) } } -napi_value SetSlotAsBundle(napi_env env, napi_callback_info info) +napi_value SetSlotByBundle(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - ParametersInfoSetSlotAsBundle params{}; - if (ParseParametersSetSlotAsBundle(env, info, params) == nullptr) { + ParametersInfoSetSlotByBundle params{}; + if (ParseParametersSetSlotByBundle(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } - AsyncCallbackInfoSetSlotAsBundle *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoSetSlotAsBundle{.env = env, .asyncWork = nullptr, .params = params}; + AsyncCallbackInfoSetSlotByBundle *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoSetSlotByBundle{.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -549,14 +549,14 @@ napi_value SetSlotAsBundle(napi_env env, napi_callback_info info) Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); napi_value resourceName = nullptr; - napi_create_string_latin1(env, "setSlotAsBundle", NAPI_AUTO_LENGTH, &resourceName); + napi_create_string_latin1(env, "setSlotByBundle", NAPI_AUTO_LENGTH, &resourceName); // Asynchronous function call napi_create_async_work(env, nullptr, resourceName, [](napi_env env, void *data) { - ANS_LOGI("SetSlotAsBundle napi_create_async_work start"); - AsyncCallbackInfoSetSlotAsBundle *asynccallbackinfo = (AsyncCallbackInfoSetSlotAsBundle *)data; + ANS_LOGI("SetSlotByBundle napi_create_async_work start"); + AsyncCallbackInfoSetSlotByBundle *asynccallbackinfo = (AsyncCallbackInfoSetSlotByBundle *)data; NotificationBundleOption bundleOption; bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); @@ -565,8 +565,8 @@ napi_value SetSlotAsBundle(napi_env env, napi_callback_info info) NotificationHelper::UpdateNotificationSlots(bundleOption, asynccallbackinfo->params.slots); }, [](napi_env env, napi_status status, void *data) { - ANS_LOGI("SetSlotAsBundle napi_create_async_work end"); - AsyncCallbackInfoSetSlotAsBundle *asynccallbackinfo = (AsyncCallbackInfoSetSlotAsBundle *)data; + ANS_LOGI("SetSlotByBundle napi_create_async_work end"); + AsyncCallbackInfoSetSlotByBundle *asynccallbackinfo = (AsyncCallbackInfoSetSlotByBundle *)data; Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); @@ -664,17 +664,17 @@ napi_value GetSlot(napi_env env, napi_callback_info info) } } -napi_value GetSlotNumAsBundle(napi_env env, napi_callback_info info) +napi_value GetSlotNumByBundle(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - ParametersInfoGetSlotNumAsBundle params{}; - if (ParseParametersGetSlotNumAsBundle(env, info, params) == nullptr) { + ParametersInfoGetSlotNumByBundle params{}; + if (ParseParametersGetSlotNumByBundle(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } - AsyncCallbackInfoGetSlotNumAsBundle *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoGetSlotNumAsBundle{.env = env, .asyncWork = nullptr, .params = params}; + AsyncCallbackInfoGetSlotNumByBundle *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoGetSlotNumByBundle{.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -682,14 +682,14 @@ napi_value GetSlotNumAsBundle(napi_env env, napi_callback_info info) Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); napi_value resourceName = nullptr; - napi_create_string_latin1(env, "getSlotNumAsBundle", NAPI_AUTO_LENGTH, &resourceName); + napi_create_string_latin1(env, "getSlotNumByBundle", NAPI_AUTO_LENGTH, &resourceName); // Asynchronous function call napi_create_async_work(env, nullptr, resourceName, [](napi_env env, void *data) { - ANS_LOGI("GetSlotNumAsBundle napi_create_async_work start"); - AsyncCallbackInfoGetSlotNumAsBundle *asynccallbackinfo = (AsyncCallbackInfoGetSlotNumAsBundle *)data; + ANS_LOGI("GetSlotNumByBundle napi_create_async_work start"); + AsyncCallbackInfoGetSlotNumByBundle *asynccallbackinfo = (AsyncCallbackInfoGetSlotNumByBundle *)data; NotificationBundleOption bundleOption; bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); @@ -699,8 +699,8 @@ napi_value GetSlotNumAsBundle(napi_env env, napi_callback_info info) napi_create_int32(env, num, &asynccallbackinfo->result); }, [](napi_env env, napi_status status, void *data) { - ANS_LOGI("GetSlotNumAsBundle napi_create_async_work end"); - AsyncCallbackInfoGetSlotNumAsBundle *asynccallbackinfo = (AsyncCallbackInfoGetSlotNumAsBundle *)data; + ANS_LOGI("GetSlotNumByBundle napi_create_async_work end"); + AsyncCallbackInfoGetSlotNumByBundle *asynccallbackinfo = (AsyncCallbackInfoGetSlotNumByBundle *)data; Common::ReturnCallbackPromise(env, asynccallbackinfo->info, asynccallbackinfo->result); @@ -811,17 +811,17 @@ napi_value GetSlots(napi_env env, napi_callback_info info) } } -napi_value GetSlotsAsBundle(napi_env env, napi_callback_info info) +napi_value GetSlotsByBundle(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - ParametersInfoGetSlotsAsBundle params{}; - if (ParseParametersGetSlotsAsBundle(env, info, params) == nullptr) { + ParametersInfoGetSlotsByBundle params{}; + if (ParseParametersGetSlotsByBundle(env, info, params) == nullptr) { return Common::JSParaError(env, params.callback); } - AsyncCallbackInfoGetSlotsAsBundle *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoGetSlotsAsBundle{.env = env, .asyncWork = nullptr, .params = params}; + AsyncCallbackInfoGetSlotsByBundle *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoGetSlotsByBundle{.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -829,14 +829,14 @@ napi_value GetSlotsAsBundle(napi_env env, napi_callback_info info) Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); napi_value resourceName = nullptr; - napi_create_string_latin1(env, "getSlotsAsBundle", NAPI_AUTO_LENGTH, &resourceName); + napi_create_string_latin1(env, "getSlotsByBundle", NAPI_AUTO_LENGTH, &resourceName); // Asynchronous function call napi_create_async_work(env, nullptr, resourceName, [](napi_env env, void *data) { - ANS_LOGI("GetSlotsAsBundle napi_create_async_work start"); - AsyncCallbackInfoGetSlotsAsBundle *asynccallbackinfo = (AsyncCallbackInfoGetSlotsAsBundle *)data; + ANS_LOGI("GetSlotsByBundle napi_create_async_work start"); + AsyncCallbackInfoGetSlotsByBundle *asynccallbackinfo = (AsyncCallbackInfoGetSlotsByBundle *)data; NotificationBundleOption bundleOption; bundleOption.SetBundleName(asynccallbackinfo->params.option.bundle); @@ -873,8 +873,8 @@ napi_value GetSlotsAsBundle(napi_env env, napi_callback_info info) } }, [](napi_env env, napi_status status, void *data) { - ANS_LOGI("GetSlotsAsBundle napi_create_async_work end"); - AsyncCallbackInfoGetSlotsAsBundle *asynccallbackinfo = (AsyncCallbackInfoGetSlotsAsBundle *)data; + ANS_LOGI("GetSlotsByBundle napi_create_async_work end"); + AsyncCallbackInfoGetSlotsByBundle *asynccallbackinfo = (AsyncCallbackInfoGetSlotsByBundle *)data; Common::ReturnCallbackPromise(env, asynccallbackinfo->info, asynccallbackinfo->result); diff --git a/interfaces/kits/napi/ans/src/subscribe.cpp b/interfaces/kits/napi/ans/src/subscribe.cpp index f4787d927..f2bcb906e 100644 --- a/interfaces/kits/napi/ans/src/subscribe.cpp +++ b/interfaces/kits/napi/ans/src/subscribe.cpp @@ -21,13 +21,13 @@ namespace OHOS { namespace NotificationNapi { const int SUBSRIBE_MAX_PARA = 3; const int NO_DELETE_REASON = -1; -const std::string CONSUME = "onConsumed"; -const std::string CANCEL = "onCanceled"; +const std::string CONSUME = "onConsume"; +const std::string CANCEL = "onCancel"; const std::string UPDATE = "onUpdate"; -const std::string CONNECTED = "onConnected"; -const std::string DIS_CONNECTED = "onDisConnect"; -const std::string DIE = "onDied"; -const std::string DISTURB_MODE_CHANGE = "onDisturbModeChanged"; +const std::string CONNECTED = "onConnect"; +const std::string DIS_CONNECTED = "onDisconnect"; +const std::string DIE = "onDestroy"; +const std::string DISTURB_MODE_CHANGE = "onDisturbModeChange"; struct NotificationReceiveDataWorker { napi_env env = nullptr; @@ -736,27 +736,27 @@ napi_value GetNotificationSubscriber( napi_create_reference(env, value, 1, &subscriberInfo.ref); - // onConsumed?:(data: SubscribeCallbackData) => void; - NAPI_CALL(env, napi_has_named_property(env, value, "onConsumed", &hasProperty)); + // onConsume?:(data: SubscribeCallbackData) => void + NAPI_CALL(env, napi_has_named_property(env, value, "onConsume", &hasProperty)); if (hasProperty) { napi_value nOnConsumed = nullptr; - napi_get_named_property(env, value, "onConsumed", &nOnConsumed); + napi_get_named_property(env, value, "onConsume", &nOnConsumed); NAPI_CALL(env, napi_typeof(env, nOnConsumed, &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); napi_create_reference(env, nOnConsumed, 1, &result); subscriberInfo.subscriber->SetCallbackInfo(env, CONSUME, result); } - // onCanceled?:(data: SubscribeCallbackData) => void; - NAPI_CALL(env, napi_has_named_property(env, value, "onCanceled", &hasProperty)); + // onCancel?:(data: SubscribeCallbackData) => void + NAPI_CALL(env, napi_has_named_property(env, value, "onCancel", &hasProperty)); if (hasProperty) { napi_value nOnCanceled = nullptr; - napi_get_named_property(env, value, "onCanceled", &nOnCanceled); + napi_get_named_property(env, value, "onCancel", &nOnCanceled); NAPI_CALL(env, napi_typeof(env, nOnCanceled, &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); napi_create_reference(env, nOnCanceled, 1, &result); subscriberInfo.subscriber->SetCallbackInfo(env, CANCEL, result); } - // onUpdate?:(data: NotificationSortingMap) => void; + // onUpdate?:(data: NotificationSortingMap) => void NAPI_CALL(env, napi_has_named_property(env, value, "onUpdate", &hasProperty)); if (hasProperty) { napi_value nOnUpdate = nullptr; @@ -766,41 +766,41 @@ napi_value GetNotificationSubscriber( napi_create_reference(env, nOnUpdate, 1, &result); subscriberInfo.subscriber->SetCallbackInfo(env, UPDATE, result); } - // onConnected?:() => void; - NAPI_CALL(env, napi_has_named_property(env, value, "onConnected", &hasProperty)); + // onConnect?:() => void + NAPI_CALL(env, napi_has_named_property(env, value, "onConnect", &hasProperty)); if (hasProperty) { napi_value nOnConnected = nullptr; - napi_get_named_property(env, value, "onConnected", &nOnConnected); + napi_get_named_property(env, value, "onConnect", &nOnConnected); NAPI_CALL(env, napi_typeof(env, nOnConnected, &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); napi_create_reference(env, nOnConnected, 1, &result); subscriberInfo.subscriber->SetCallbackInfo(env, CONNECTED, result); } - // onDisConnect?:() => void; - NAPI_CALL(env, napi_has_named_property(env, value, "onDisConnect", &hasProperty)); + // onDisconnect?:() => void + NAPI_CALL(env, napi_has_named_property(env, value, "onDisconnect", &hasProperty)); if (hasProperty) { napi_value nOnDisConnect = nullptr; - napi_get_named_property(env, value, "onDisConnect", &nOnDisConnect); + napi_get_named_property(env, value, "onDisconnect", &nOnDisConnect); NAPI_CALL(env, napi_typeof(env, nOnDisConnect, &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); napi_create_reference(env, nOnDisConnect, 1, &result); subscriberInfo.subscriber->SetCallbackInfo(env, DIS_CONNECTED, result); } - // onDied?:() => void; - NAPI_CALL(env, napi_has_named_property(env, value, "onDied", &hasProperty)); + // onDestroy?:() => void + NAPI_CALL(env, napi_has_named_property(env, value, "onDestroy", &hasProperty)); if (hasProperty) { napi_value nOnDied = nullptr; - napi_get_named_property(env, value, "onDied", &nOnDied); + napi_get_named_property(env, value, "onDestroy", &nOnDied); NAPI_CALL(env, napi_typeof(env, nOnDied, &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); napi_create_reference(env, nOnDied, 1, &result); subscriberInfo.subscriber->SetCallbackInfo(env, DIE, result); } - // onDisturbModeChanged?:(mode: notification.DoNotDisturbMode) => void; - NAPI_CALL(env, napi_has_named_property(env, value, "onDisturbModeChanged", &hasProperty)); + // onDisturbModeChange?:(mode: notification.DoNotDisturbMode) => void + NAPI_CALL(env, napi_has_named_property(env, value, "onDisturbModeChange", &hasProperty)); if (hasProperty) { napi_value nOnDisturbModeChanged = nullptr; - napi_get_named_property(env, value, "onDisturbModeChanged", &nOnDisturbModeChanged); + napi_get_named_property(env, value, "onDisturbModeChange", &nOnDisturbModeChanged); NAPI_CALL(env, napi_typeof(env, nOnDisturbModeChanged, &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); napi_create_reference(env, nOnDisturbModeChanged, 1, &result); @@ -897,9 +897,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[2]:callback if (argc >= SUBSRIBE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype)); + NAPI_CALL(env, napi_typeof(env, argv[SUBSRIBE_MAX_PARA - 1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[2], 1, &callback); + napi_create_reference(env, argv[SUBSRIBE_MAX_PARA - 1], 1, &callback); } return Common::NapiGetNull(env); diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index a062596c3..629d4414e 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -67,6 +67,7 @@ ohos_shared_library("libans") { "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/aafwk/standard/services/abilitymgr:abilityms", "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//utils/native/base:utils", ] diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index bfd654130..103c4c10d 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -80,13 +80,13 @@ private: NotificationPreferencesInfo &preferencesInfo) const; ErrCode CheckGroupForUpdateSlotGroup(const sptr &bundleOption, const sptr &group, NotificationPreferencesInfo &preferencesInfo) const; - template + template ErrCode SetBundleProperty(NotificationPreferencesInfo &preferencesInfo, const sptr &bundleOption, const BundleType &type, const T &value); - template + template ErrCode SaveBundleProperty(NotificationPreferencesInfo::BundleInfo &bundleInfo, const sptr &bundleOption, const BundleType &type, const T &value); - template + template ErrCode GetBundleProperty(const sptr &bundleOption, const BundleType &type, T &value) const; std::string GenerateBundleKey(const sptr &bundleOption) const; diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index 2425af407..ef1f360a7 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -59,7 +59,7 @@ private: bool CheckBundle(const std::string &bundleKey); bool PutBundlePropertyValueToDisturbeDB(const NotificationPreferencesInfo::BundleInfo &bundleInfo); - template + template OHOS::DistributedKv::Status PutBundlePropertyToDisturbeDB( const std::string &bundleKey, const BundleType &type, const T &t); bool PutBundleToDisturbeDB( diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 55ef82b58..4e7845325 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -64,15 +64,15 @@ public: int GetBundleUid() const; private: - std::string bundleName_ {}; - int uid_ {}; + std::string bundleName_; + int uid_ = 0; int importance_ = BUNDLE_IMPORTANCE; bool isShowBadge_ = BUNDLE_SHOW_BADGE; int badgeTotalNum_ = BUNDLE_BADGE_TOTAL_NUM; bool isPrivateAllowed_ = BUNDLE_PRIVATE_ALLOWED; bool isEnabledNotification_ = BUNDLE_ENABLE_NOTIFICATION; - std::map> slots_ {}; - std::map> groups_ {}; + std::map> slots_; + std::map> groups_; }; NotificationPreferencesInfo() @@ -92,7 +92,7 @@ public: private: bool isEnabledAllNotification_ = true; NotificationConstant::DisturbMode disturbMode_ = NotificationConstant::DisturbMode::ALLOW_ALL; - std::map infos_ {}; + std::map infos_; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 810e07534..9305c21b5 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -47,16 +47,16 @@ static const int32_t NOTIFICATION_MAX_COUNT = 1024; static const int32_t DEFAULT_RECENT_COUNT = 16; struct RecentNotification { - sptr notification{nullptr}; - bool isActive{false}; - int deleteReason{0}; - int64_t deleteTime{0}; + sptr notification = nullptr; + bool isActive = false; + int deleteReason = 0; + int64_t deleteTime = 0; }; } // namespace struct AdvancedNotificationService::RecentInfo { - std::list> list{}; - size_t recentCount{DEFAULT_RECENT_COUNT}; + std::list> list; + size_t recentCount = DEFAULT_RECENT_COUNT; }; sptr AdvancedNotificationService::instance_; @@ -122,6 +122,35 @@ inline ErrCode AssignValidNotificationSlot(const std::shared_ptr &request) +{ + ErrCode result = ERR_OK; + + auto content = request->GetContent(); + if (content != nullptr && content->GetContentType() == NotificationContent::Type::PICTURE) { + std::shared_ptr pictureContent = + std::static_pointer_cast(content->GetNotificationContent()); + if (pictureContent != nullptr) { + auto picture = pictureContent->GetBigPicture(); + if (picture != nullptr && (uint32_t)picture->GetByteCount() > MAX_PICTURE_SIZE) { + result = ERR_ANS_PICTURE_OVER_SIZE; + } + } + } + + auto littleIcon = request->GetLittleIcon(); + if (littleIcon != nullptr && (uint32_t)littleIcon->GetByteCount() > MAX_ICON_SIZE) { + result = ERR_ANS_ICON_OVER_SIZE; + } + + auto bigIcon = request->GetBigIcon(); + if (bigIcon != nullptr && (uint32_t)bigIcon->GetByteCount() > MAX_ICON_SIZE) { + result = ERR_ANS_ICON_OVER_SIZE; + } + + return result; +} + inline ErrCode PrepereNotificationRequest(const sptr &request) { std::string bundle = GetClientBundleName(); @@ -137,7 +166,9 @@ inline ErrCode PrepereNotificationRequest(const sptr &reque request->SetCreatorUid(uid); request->SetCreatorPid(pid); - return ERR_OK; + ErrCode result = CheckPictureSize(request); + + return result; } sptr AdvancedNotificationService::GetInstance() @@ -151,7 +182,9 @@ sptr AdvancedNotificationService::GetInstance() } AdvancedNotificationService::AdvancedNotificationService() - : systemEventObserver_({std::bind(&AdvancedNotificationService::OnBundleRemoved, this, std::placeholders::_1)}) + : systemEventObserver_({ + std::bind(&AdvancedNotificationService::OnBundleRemoved, this, std::placeholders::_1), + }) { runner_ = OHOS::AppExecFwk::EventRunner::Create(); handler_ = std::make_shared(runner_); @@ -1126,18 +1159,14 @@ ErrCode AdvancedNotificationService::IsAllowedNotify(bool &allowed) { ANS_LOGD("%{public}s", __FUNCTION__); - sptr bundleOption = GenerateBundleOption(); - if (bundleOption == nullptr) { - return ERR_ANS_INVALID_BUNDLE; + if (!IsSystemApp()) { + return ERR_ANS_NON_SYSTEM_APP; } ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { allowed = false; result = NotificationPreferences::GetInstance().GetNotificationsEnabled(allowed); - if (result == ERR_OK && allowed) { - result = NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(bundleOption, allowed); - } })); return result; } diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 94175a711..a937d9018 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -141,6 +141,7 @@ ErrCode NotificationPreferences::RemoveNotificationAllSlots(const sptrRemoveAllSlotsFromDisturbeDB(GenerateBundleKey(bundleOption))) { result = ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; } @@ -389,8 +390,7 @@ ErrCode NotificationPreferences::SetShowBadge(const sptr &, std::string &)>> NotificationPreferencesDatabase::slotMap_ = { - {KEY_SLOT_GROUPID, + { + KEY_SLOT_GROUPID, std::bind(&NotificationPreferencesDatabase::ParseSlotGroupId, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3)}, - {KEY_SLOT_DESCRIPTION, + std::placeholders::_3), + }, + { + KEY_SLOT_DESCRIPTION, std::bind(&NotificationPreferencesDatabase::ParseSlotDescription, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_SLOT_LEVEL, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_SLOT_LEVEL, std::bind(&NotificationPreferencesDatabase::ParseSlotLevel, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3)}, - {KEY_SLOT_SHOW_BADGE, + std::placeholders::_3), + }, + { + KEY_SLOT_SHOW_BADGE, std::bind(&NotificationPreferencesDatabase::ParseSlotShowBadge, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_SLOT_ENABLE_LIGHT, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_SLOT_ENABLE_LIGHT, std::bind(&NotificationPreferencesDatabase::ParseSlotEnableLight, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_SLOT_ENABLE_VRBRATION, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_SLOT_ENABLE_VRBRATION, std::bind(&NotificationPreferencesDatabase::ParseSlotEnableVrbration, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_SLOT_LED_LIGHT_COLOR, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_SLOT_LED_LIGHT_COLOR, std::bind(&NotificationPreferencesDatabase::ParseSlotLedLightColor, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_SLOT_LOCKSCREEN_VISIBLENESS, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_SLOT_LOCKSCREEN_VISIBLENESS, std::bind(&NotificationPreferencesDatabase::ParseSlotLockscreenVisibleness, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_SLOT_SOUND, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_SLOT_SOUND, std::bind(&NotificationPreferencesDatabase::ParseSlotSound, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3)}, - {KEY_SLOT_VIBRATION_STYLE, + std::placeholders::_3), + }, + { + KEY_SLOT_VIBRATION_STYLE, std::bind(&NotificationPreferencesDatabase::ParseSlotVibrationSytle, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_SLOT_VIBRATION_STYLE, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_SLOT_VIBRATION_STYLE, std::bind(&NotificationPreferencesDatabase::ParseSlotEnableBypassDnd, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}}; + std::placeholders::_2, std::placeholders::_3), + }}; const std::map> NotificationPreferencesDatabase::bundleMap_ = { - {KEY_BUNDLE_NAME, + { + KEY_BUNDLE_NAME, std::bind(&NotificationPreferencesDatabase::ParseBundleName, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3)}, - {KEY_BUNDLE_IMPORTANCE, + std::placeholders::_3), + }, + { + KEY_BUNDLE_IMPORTANCE, std::bind(&NotificationPreferencesDatabase::ParseBundleImportance, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_BUNDLE_SHOW_BADGE, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_BUNDLE_SHOW_BADGE, std::bind(&NotificationPreferencesDatabase::ParseBundleShowBadge, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_BUNDLE_BADGE_TOTAL_NUM, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_BUNDLE_BADGE_TOTAL_NUM, std::bind(&NotificationPreferencesDatabase::ParseBundleBadgeNum, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_BUNDLE_PRIVATE_ALLOWED, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_BUNDLE_PRIVATE_ALLOWED, std::bind(&NotificationPreferencesDatabase::ParseBundlePrivateAllowed, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}, - {KEY_BUNDLE_ENABLE_NOTIFICATION, + std::placeholders::_2, std::placeholders::_3), + }, + { + KEY_BUNDLE_ENABLE_NOTIFICATION, std::bind(&NotificationPreferencesDatabase::ParseBundleEnableNotification, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}}; + std::placeholders::_2, std::placeholders::_3), + }}; NotificationPreferencesDatabase::NotificationPreferencesDatabase() { @@ -105,10 +139,12 @@ void NotificationPreferencesDatabase::TryTwice(const std::function entries; - status = kvStorePtr_->GetEntries({KEY_BUNDLE_LABEL}, entries); + status = kvStorePtr_->GetEntries(DistributedKv::Key(KEY_BUNDLE_LABEL), entries); if (status != OHOS::DistributedKv::Status::SUCCESS) { ANS_LOGE("Get Bundle Info failed."); return false; @@ -486,7 +522,8 @@ bool NotificationPreferencesDatabase::RemoveBundleFromDisturbeDB(const std::stri OHOS::DistributedKv::Status status; std::vector entries; - status = kvStorePtr_->GetEntries({KEY_ANS_BUNDLE + KEY_UNDER_LINE + bundleKey + KEY_UNDER_LINE}, entries); + status = kvStorePtr_->GetEntries( + DistributedKv::Key(KEY_ANS_BUNDLE + KEY_UNDER_LINE + bundleKey + KEY_UNDER_LINE), entries); if (status != OHOS::DistributedKv::Status::SUCCESS) { ANS_LOGE("Get Bundle Info failed."); @@ -498,7 +535,7 @@ bool NotificationPreferencesDatabase::RemoveBundleFromDisturbeDB(const std::stri keys.push_back(iter.key); } - OHOS::DistributedKv::Key bundleDBKey({KEY_BUNDLE_LABEL + KEY_BUNDLE_NAME + KEY_UNDER_LINE + bundleKey}); + OHOS::DistributedKv::Key bundleDBKey(KEY_BUNDLE_LABEL + KEY_BUNDLE_NAME + KEY_UNDER_LINE + bundleKey); keys.push_back(bundleDBKey); status = kvStorePtr_->DeleteBatch(keys); if (status != OHOS::DistributedKv::Status::SUCCESS) { @@ -525,7 +562,8 @@ bool NotificationPreferencesDatabase::RemoveSlotFromDisturbeDB( OHOS::DistributedKv::Status status; std::vector slotentries; std::string slotType = std::to_string(type); - status = kvStorePtr_->GetEntries({GenerateSlotKey(bundleKey, slotType) + KEY_UNDER_LINE}, slotentries); + status = + kvStorePtr_->GetEntries(DistributedKv::Key(GenerateSlotKey(bundleKey, slotType) + KEY_UNDER_LINE), slotentries); if (status != DistributedKv::Status::SUCCESS) { return false; } @@ -559,7 +597,7 @@ bool NotificationPreferencesDatabase::RemoveAllSlotsFromDisturbeDB(const std::st OHOS::DistributedKv::Status status; std::vector slotsEntries; - status = kvStorePtr_->GetEntries({GenerateSlotKey(bundleKey) + KEY_UNDER_LINE}, slotsEntries); + status = kvStorePtr_->GetEntries(DistributedKv::Key(GenerateSlotKey(bundleKey) + KEY_UNDER_LINE), slotsEntries); if (status != DistributedKv::Status::SUCCESS) { return false; } @@ -616,7 +654,7 @@ bool NotificationPreferencesDatabase::GetRemoveGroupKeysFromDisturbeDB( OHOS::DistributedKv::Status status; std::vector groupentries; std::string slotKeyStr = GenerateGroupKey(bundleKey, groupId); - status = kvStorePtr_->GetEntries({slotKeyStr + KEY_UNDER_LINE}, groupentries); + status = kvStorePtr_->GetEntries(DistributedKv::Key(slotKeyStr + KEY_UNDER_LINE), groupentries); if (status != DistributedKv::Status::SUCCESS) { return false; } @@ -791,7 +829,7 @@ void NotificationPreferencesDatabase::ParseBundleFromDistureDB( std::string bundleKey = item.value.ToString(); ANS_LOGD("Bundle name is %{public}s.", bundleKey.c_str()); std::vector bundleEntries; - kvStorePtr_->GetEntries({GenerateBundleKey(bundleKey)}, bundleEntries); + kvStorePtr_->GetEntries(DistributedKv::Key(GenerateBundleKey(bundleKey)), bundleEntries); ANS_LOGD("Bundle key is %{public}s.", GenerateBundleKey(bundleKey).c_str()); NotificationPreferencesInfo::BundleInfo bunldeInfo; for (auto bundleEntry : bundleEntries) { @@ -927,7 +965,7 @@ int NotificationPreferencesDatabase::StringToInt(const std::string &str) const std::string NotificationPreferencesDatabase::GenerateSlotKey( const std::string &bundleKey, const std::string &type, const std::string &subType) const { - /*slot key + /* slot key * * KEY_ANS_BUNDLE_bundlename_slot_type_0_id * KEY_ANS_BUNDLE_bundlename_slot_type_0_des @@ -949,7 +987,7 @@ std::string NotificationPreferencesDatabase::GenerateSlotKey( std::string NotificationPreferencesDatabase::GenerateGroupKey( const std::string &bundleKey, const std::string &type) const { - /*group key + /* group key * * KEY_ANS_BUNDLE_bundlename_group_id_id0_id: * KEY_ANS_BUNDLE_bundlename_group_id_id0_name: @@ -967,7 +1005,7 @@ std::string NotificationPreferencesDatabase::GenerateGroupKey( std::string NotificationPreferencesDatabase::GenerateBundleKey( const std::string &bundleKey, const std::string &type) const { - /*bundle key + /* bundle key * * label_KEY_ANS_KEY_BUNDLE_NAME = "" * KEY_ANS_BUNDLE_bundlename_ diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 8da3be02e..3179f766d 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -81,6 +81,7 @@ ohos_unittest("ans_unit_test") { "${frameworks_path}/ans/native:ans_innerkits", "${frameworks_path}/wantagent:wantagent_innerkits", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 90d0cbc84..8d7d215f3 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -30,6 +30,7 @@ #include "notification_subscriber.h" using namespace testing::ext; +using namespace OHOS::Media; namespace OHOS { namespace Notification { @@ -116,6 +117,7 @@ void AdvancedNotificationServiceTest::TestAddSlotGroup() groups.push_back(group); advancedNotificationService_->AddSlotGroups(groups); } + /** * @tc.number : AMS_ANS_Publish_00100 * @tc.name : ANSPublish00100 @@ -412,7 +414,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01200, /** * @tc.number : AMS_ANS_Publish_01300 * @tc.name : ANSPublish01300 - * @tc.desc : When a bundle is not allowed to publish a notification, the notification publishing interface returns + * @tc.desc : When a bundle is not allowed to publish a notification, the notification publishing interface + returns * ERR_ANS_NOT_ALLOWED */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01300, Function | SmallTest | Level1) @@ -1209,18 +1212,6 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09300, (int)ERR_OK); } -/** - * @tc.number : AdvancedNotificationServiceTest_09500 - * @tc.name : AMS_ANS_IsAllowedNotify_0100 - * @tc.desc : Test IsAllowedNotify function - */ -HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09500, Function | SmallTest | Level1) -{ - bool allowed = false; - EXPECT_EQ((int)advancedNotificationService_->IsAllowedNotify(allowed), - (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); -} - /** * @tc.number : AdvancedNotificationServiceTest_09600 * @tc.name : AMS_ANS_IsAllowedNotify_0200 @@ -1228,9 +1219,10 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09500, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09600, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + EXPECT_EQ((int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK); bool allowed = false; EXPECT_EQ((int)advancedNotificationService_->IsAllowedNotify(allowed), (int)ERR_OK); + EXPECT_TRUE(allowed); } /** @@ -1274,5 +1266,119 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09900, (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +inline std::shared_ptr MakePixelMap(int32_t width, int32_t height) +{ + const int32_t PIXEL_BYTES = 4; + std::shared_ptr pixelMap = std::make_shared(); + ImageInfo info; + info.size.width = width; + info.size.height = height; + info.pixelFormat = PixelFormat::ARGB_8888; + info.colorSpace = ColorSpace::SRGB; + pixelMap->SetImageInfo(info); + int32_t rowDataSize = width * PIXEL_BYTES; + uint32_t bufferSize = rowDataSize * height; + void *buffer = malloc(bufferSize); + EXPECT_NE(buffer, nullptr); + pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr); + return pixelMap; +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10000 + * @tc.name : AMS_ANS_Publish_With_PixelMap + * @tc.desc : Publish a notification with pixelMap. + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10000, Function | SmallTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 400; + const int BIG_PICTURE_HEIGHT = 300; + const int ICON_SIZE = 36; + + sptr req = new NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetBigIcon(bigIcon); + EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10100 + * @tc.name : AMS_ANS_Publish_With_PixelMap_Oversize_00100 + * @tc.desc : Publish a notification with oversize pixelMap. + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10100, Function | SmallTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 1024; + const int BIG_PICTURE_HEIGHT = 1024; + const int ICON_SIZE = 36; + + sptr req = new NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetBigIcon(bigIcon); + EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_ANS_PICTURE_OVER_SIZE); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10200 + * @tc.name : AMS_ANS_Publish_With_PixelMap_Oversize_00200 + * @tc.desc : Publish a notification with oversize pixelMap. + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10200, Function | SmallTest | Level1) +{ + const int BIG_PICTURE_WIDTH = 400; + const int BIG_PICTURE_HEIGHT = 300; + const int ICON_SIZE = 256; + + sptr req = new NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("label"); + std::shared_ptr pictureContent = std::make_shared(); + EXPECT_NE(pictureContent, nullptr); + pictureContent->SetText("notification text"); + pictureContent->SetTitle("notification title"); + std::shared_ptr bigPicture = MakePixelMap(BIG_PICTURE_WIDTH, BIG_PICTURE_HEIGHT); + EXPECT_NE(bigPicture, nullptr); + pictureContent->SetBigPicture(bigPicture); + std::shared_ptr content = std::make_shared(pictureContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + std::shared_ptr littleIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetLittleIcon(littleIcon); + std::shared_ptr bigIcon = MakePixelMap(ICON_SIZE, ICON_SIZE); + req->SetBigIcon(bigIcon); + EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_ANS_ICON_OVER_SIZE); +} + } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/mock/include/mock_single_kv_store.h b/services/ans/test/unittest/mock/include/mock_single_kv_store.h index 8a777ea02..f32d46b6d 100644 --- a/services/ans/test/unittest/mock/include/mock_single_kv_store.h +++ b/services/ans/test/unittest/mock/include/mock_single_kv_store.h @@ -19,13 +19,13 @@ #include #include +#include "data_query.h" #include "kvstore.h" #include "kvstore_observer.h" #include "kvstore_result_set.h" #include "kvstore_sync_callback.h" -#include "types.h" -#include "data_query.h" #include "single_kvstore.h" +#include "types.h" namespace OHOS { namespace DistributedKv { @@ -33,218 +33,72 @@ namespace DistributedKv { // This class provides put, delete, search, sync and subscribe functions of a key-value store. class AnsTestSingleKvStore : public SingleKvStore { public: - - // Get all entries in this store which key start with prefixKey. - // Parameters: - // perfixkey: the prefix to be searched. - // entries: entries will be returned in this parameter. - // Return: - // Status of this GetEntries operation. virtual Status GetEntries(const Key &prefixKey, std::vector &entries) const override; - // Get all entries in this store by query. - // Parameters: - // query: the query string. - // entries: entries will be returned in this parameter. - // Return: - // Status of this GetEntries operation. virtual Status GetEntriesWithQuery(const std::string &query, std::vector &entries) const override; - // Get all entries in this store by query. - // Parameters: - // query: the query object. - // entries: entries will be returned in this parameter. - // Return: - // Status of this GetEntries operation. virtual Status GetEntriesWithQuery(const DataQuery &query, std::vector &entries) const override; - // Get ResultSet in this store which key start with prefixKey. - // Parameters: - // perfixkey: the prefix to be searched. - // resultSet: resultSet will be returned in this parameter. - // Return: - // Status of this GetResultSet operation. - virtual void GetResultSet(const Key &prefixKey, - std::function)> callback) const override; - - // Get ResultSet in this store by Query. - // Parameters: - // query: the query string. - // resultSet: resultSet will be returned in this parameter. - // Return: - // Status of this GetResultSet operation. + virtual void GetResultSet( + const Key &prefixKey, std::function)> callback) const override; + virtual void GetResultSetWithQuery(const std::string &query, - std::function)> callback) const override; - - // Get ResultSet in this store by Query. - // Parameters: - // query: the query object. - // resultSet: resultSet will be returned in this parameter. - // Return: - // Status of this GetResultSet operation. - virtual void GetResultSetWithQuery(const DataQuery &query, - std::function)> callback) const override; - - // Close the ResultSet returned by GetResultSet. - // Parameters: - // resultSet: resultSet will be returned in this parameter. - // Return: - // Status of this CloseResultSet operation. + std::function)> callback) const override; + + virtual void GetResultSetWithQuery( + const DataQuery &query, std::function)> callback) const override; + virtual Status CloseResultSet(std::unique_ptr resultSet) override; - // Get the number of result by query. - // Parameters: - // query: the query string. - // result: result will be returned in this parameter. - // Return: - // Status of this CloseResultSet operation. virtual Status GetCountWithQuery(const std::string &query, int &result) const override; - // Get the number of result by query. - // Parameters: - // query: the query object. - // result: result will be returned in this parameter. - // Return: - // Status of this CloseResultSet operation. virtual Status GetCountWithQuery(const DataQuery &query, int &result) const override; - // Sync store with other devices. This is an asynchronous method, - // sync will fail if there is a syncing operation in progress. - // Parameters: - // deviceIdList: device list to sync. - // mode: mode can be set to SyncMode::PUSH, SyncMode::PULL and SyncMode::PUTH_PULL. PUSH_PULL will firstly - // push all not-local store to listed devices, then pull these stores back. - // allowedDelayMs: allowed delay milli-second to sync. default value is 0 for compatibility. - // Return: - // Status of this Sync operation. - virtual Status Sync(const std::vector &deviceIdList, const SyncMode &mode, - uint32_t allowedDelayMs = 0) override; - - // Remove the device data synced from remote. - // Parameters: - // device: device id. - // Return: - // Status of this remove operation. + virtual Status Sync( + const std::vector &deviceIdList, const SyncMode &mode, uint32_t allowedDelayMs = 0) override; + virtual Status RemoveDeviceData(const std::string &device) override; - // Get id of this SingleKvStore. virtual StoreId GetStoreId() const override; - // Delete an entry by its key. - // Parameters: - // key: key of the entry to be deleted. - // Return: - // Status of this delete operation. virtual Status Delete(const Key &key) override; - // Write a pair of key and value to this store. - // Parameters: - // key: key of this entry. Should be less than 1024 bytes. key will be trimmed before store. - // value: value of this entry. Should be less than (4 * 1024 * 1024) bytes. - // Return: - // Status of this put operation. virtual Status Put(const Key &key, const Value &value) override; - // Get value from AppKvStore by its key. - // Parameters: - // key: key of this entry. - // value: value will be returned in this parameter. - // Return: - // Status of this get operation. virtual Status Get(const Key &key, Value &value) override; - // subscribe change of this kvstore to a client-defined observer. observer->OnChange method will be called when store - // changes. - // Parameters: - // subscribeType: SUBSCRIBE_TYPE_LOCAL means local changes of syncable kv store, - // : SUBSCRIBE_TYPE_REMOTE means synced data changes from remote devices, - // : SUBSCRIBE_TYPE_ALL means both local changes and synced data changes. - // observer: observer to subscribe changes. - // Return: - // Status of this subscribe operation. virtual Status SubscribeKvStore(SubscribeType subscribeType, std::shared_ptr observer) override; - // un-subscribe change of this kvstore to a client-defined observer. - // Parameters: - // subscribeType: SUBSCRIBE_TYPE_LOCAL means local changes of syncable kv store, - // : SUBSCRIBE_TYPE_REMOTE means synced data changes from remote devices, - // : SUBSCRIBE_TYPE_ALL means both local changes and synced data changes. - // observer: observer to subscribe changes. - // Return: - // Status of this subscribe operation. virtual Status UnSubscribeKvStore(SubscribeType subscribeType, std::shared_ptr observer) override; - // register message for sync operation. - // Parameters: - // callback: callback to register. - // Return: - // Status of this register operation. virtual Status RegisterSyncCallback(std::shared_ptr callback) override; - // un-register message for sync operation. - // Parameters: - // callback: callback to register. - // Return: - // Status of this register operation. virtual Status UnRegisterSyncCallback() override; - // see Put, PutBatch put a list of entries to kvstore, - // all entries will be put in a transaction, - // if entries contains invalid entry, PutBatch will all fail. - // entries's size should be less than 128 and memory size must be less than IPC transport limit. virtual Status PutBatch(const std::vector &entries) override; - // delete a list of entries in the kvstore, - // delete key not exist still return success, - // key length should not be greater than 256, and can not be empty. - // if keys contains invalid key, all delete will fail. - // keys memory size should not be greater than IPC transport limit, and can not be empty. virtual Status DeleteBatch(const std::vector &keys) override; - // start transaction. - // all changes to this kvstore will be in a same transaction and will not change the store until Commit() or - // Rollback() is called. - // before this transaction is committed or rollbacked, all attemption to close this store will fail. virtual Status StartTransaction() override; - // commit current transaction. all changes to this store will be done after calling this method. - // any calling of this method outside a transaction will fail. virtual Status Commit() override; - // rollback current transaction. - // all changes to this store during this transaction will be rollback after calling this method. - // any calling of this method outside a transaction will fail. virtual Status Rollback() override; - // set synchronization parameters of this store. - // Parameters: - // syncParam: sync policy parameter. - // Return: - // Status of this operation. virtual Status SetSyncParam(const KvSyncParam &syncParam) override; - // get synchronization parameters of this store. - // Parameters: - // syncParam: sync policy parameter. - // Return: - // Status of this operation. virtual Status GetSyncParam(KvSyncParam &syncParam) override; virtual Status SetCapabilityEnabled(bool enabled) const override; virtual Status SetCapabilityRange(const std::vector &localLabels, - const std::vector &remoteSupportLabels) const override; + const std::vector &remoteSupportLabels) const override; virtual Status GetSecurityLevel(SecurityLevel &securityLevel) const override; + protected: - // control this store. - // Parameters: - // inputParam: input parameter. - // output: output data, nullptr if no data is returned. - // Return: - // Status of this control operation. KVSTORE_API virtual Status Control(KvControlCmd cmd, const KvParam &inputParam, sptr &output) override; }; -} // namespace AppDistributedKv +} // namespace DistributedKv } // namespace OHOS #endif // SINGLE_KV_STORE_H diff --git a/services/ans/test/unittest/mock/mock_ipc.cpp b/services/ans/test/unittest/mock/mock_ipc.cpp index 42687ac92..6f08e07f8 100644 --- a/services/ans/test/unittest/mock/mock_ipc.cpp +++ b/services/ans/test/unittest/mock/mock_ipc.cpp @@ -34,6 +34,6 @@ pid_t IPCSkeleton::GetCallingPid() void IPCSkeleton::SetCallingUid(pid_t uid) { - uid_ = uid; + uid_ = uid; } } // namespace OHOS diff --git a/services/ans/test/unittest/mock/mock_single_kv_store.cpp b/services/ans/test/unittest/mock/mock_single_kv_store.cpp index 4f9c78aa8..85aed3fef 100644 --- a/services/ans/test/unittest/mock/mock_single_kv_store.cpp +++ b/services/ans/test/unittest/mock/mock_single_kv_store.cpp @@ -18,127 +18,60 @@ namespace OHOS { namespace DistributedKv { -// Get all entries in this store which key start with prefixKey. -// Parameters: -// perfixkey: the prefix to be searched. -// entries: entries will be returned in this parameter. -// Return: -// Status of this GetEntries operation. + Status AnsTestSingleKvStore::GetEntries(const Key &prefixKey, std::vector &entries) const { return Status::SUCCESS; } -// Get all entries in this store by query. -// Parameters: -// query: the query string. -// entries: entries will be returned in this parameter. -// Return: -// Status of this GetEntries operation. Status AnsTestSingleKvStore::GetEntriesWithQuery(const std::string &query, std::vector &entries) const { return Status::SUCCESS; } -// Get all entries in this store by query. -// Parameters: -// query: the query object. -// entries: entries will be returned in this parameter. -// Return: -// Status of this GetEntries operation. Status AnsTestSingleKvStore::GetEntriesWithQuery(const DataQuery &query, std::vector &entries) const { return Status::SUCCESS; } -// Get ResultSet in this store which key start with prefixKey. -// Parameters: -// perfixkey: the prefix to be searched. -// resultSet: resultSet will be returned in this parameter. -// Return: -// Status of this GetResultSet operation. void AnsTestSingleKvStore::GetResultSet( const Key &prefixKey, std::function)> callback) const {} -// Get ResultSet in this store by Query. -// Parameters: -// query: the query string. -// resultSet: resultSet will be returned in this parameter. -// Return: -// Status of this GetResultSet operation. void AnsTestSingleKvStore::GetResultSetWithQuery( const std::string &query, std::function)> callback) const {} -// Get ResultSet in this store by Query. -// Parameters: -// query: the query object. -// resultSet: resultSet will be returned in this parameter. -// Return: -// Status of this GetResultSet operation. void AnsTestSingleKvStore::GetResultSetWithQuery( const DataQuery &query, std::function)> callback) const {} -// Close the ResultSet returned by GetResultSet. -// Parameters: -// resultSet: resultSet will be returned in this parameter. -// Return: -// Status of this CloseResultSet operation. Status AnsTestSingleKvStore::CloseResultSet(std::unique_ptr resultSet) { return Status::SUCCESS; } -// Get the number of result by query. -// Parameters: -// query: the query string. -// result: result will be returned in this parameter. -// Return: -// Status of this CloseResultSet operation. Status AnsTestSingleKvStore::GetCountWithQuery(const std::string &query, int &result) const { return Status::SUCCESS; } -// Get the number of result by query. -// Parameters: -// query: the query object. -// result: result will be returned in this parameter. -// Return: -// Status of this CloseResultSet operation. Status AnsTestSingleKvStore::GetCountWithQuery(const DataQuery &query, int &result) const { return Status::SUCCESS; } -// Sync store with other devices. This is an asynchronous method, -// sync will fail if there is a syncing operation in progress. -// Parameters: -// deviceIdList: device list to sync. -// mode: mode can be set to SyncMode::PUSH, SyncMode::PULL and SyncMode::PUTH_PULL. PUSH_PULL will firstly -// push all not-local store to listed devices, then pull these stores back. -// allowedDelayMs: allowed delay milli-second to sync. default value is 0 for compatibility. -// Return: -// Status of this Sync operation. Status AnsTestSingleKvStore::Sync( const std::vector &deviceIdList, const SyncMode &mode, uint32_t allowedDelayMs) { return Status::SUCCESS; } -// Remove the device data synced from remote. -// Parameters: -// device: device id. -// Return: -// Status of this remove operation. Status AnsTestSingleKvStore::RemoveDeviceData(const std::string &device) { return Status::SUCCESS; } -// Get id of this SingleKvStore. StoreId AnsTestSingleKvStore::GetStoreId() const { StoreId storeId; @@ -146,70 +79,31 @@ StoreId AnsTestSingleKvStore::GetStoreId() const return storeId; } -// Delete an entry by its key. -// Parameters: -// key: key of the entry to be deleted. -// Return: -// Status of this delete operation. Status AnsTestSingleKvStore::Delete(const Key &key) { return Status::SUCCESS; } -// Write a pair of key and value to this store. -// Parameters: -// key: key of this entry. Should be less than 1024 bytes. key will be trimmed before store. -// value: value of this entry. Should be less than (4 * 1024 * 1024) bytes. -// Return: -// Status of this put operation. Status AnsTestSingleKvStore::Put(const Key &key, const Value &value) { return Status::SUCCESS; } -// Get value from AppKvStore by its key. -// Parameters: -// key: key of this entry. -// value: value will be returned in this parameter. -// Return: -// Status of this get operation. Status AnsTestSingleKvStore::Get(const Key &key, Value &value) { return Status::SUCCESS; } -// subscribe change of this kvstore to a client-defined observer. observer->OnChange method will be called when store -// changes. -// Parameters: -// subscribeType: SUBSCRIBE_TYPE_LOCAL means local changes of syncable kv store, -// : SUBSCRIBE_TYPE_REMOTE means synced data changes from remote devices, -// : SUBSCRIBE_TYPE_ALL means both local changes and synced data changes. -// observer: observer to subscribe changes. -// Return: -// Status of this subscribe operation. Status AnsTestSingleKvStore::SubscribeKvStore(SubscribeType subscribeType, std::shared_ptr observer) { return Status::SUCCESS; } -// un-subscribe change of this kvstore to a client-defined observer. -// Parameters: -// subscribeType: SUBSCRIBE_TYPE_LOCAL means local changes of syncable kv store, -// : SUBSCRIBE_TYPE_REMOTE means synced data changes from remote devices, -// : SUBSCRIBE_TYPE_ALL means both local changes and synced data changes. -// observer: observer to subscribe changes. -// Return: -// Status of this subscribe operation. Status AnsTestSingleKvStore::UnSubscribeKvStore(SubscribeType subscribeType, std::shared_ptr observer) { return Status::SUCCESS; } -// register message for sync operation. -// Parameters: -// callback: callback to register. -// Return: -// Status of this register operation. Status AnsTestSingleKvStore::RegisterSyncCallback(std::shared_ptr callback) { return Status::SUCCESS; @@ -225,55 +119,31 @@ Status AnsTestSingleKvStore::PutBatch(const std::vector &entries) return Status::SUCCESS; } -// delete a list of entries in the kvstore, -// delete key not exist still return success, -// key length should not be greater than 256, and can not be empty. -// if keys contains invalid key, all delete will fail. -// keys memory size should not be greater than IPC transport limit, and can not be empty. Status AnsTestSingleKvStore::DeleteBatch(const std::vector &keys) { return Status::SUCCESS; } -// start transaction. -// all changes to this kvstore will be in a same transaction and will not change the store until Commit() or -// Rollback() is called. -// before this transaction is committed or rollbacked, all attemption to close this store will fail. Status AnsTestSingleKvStore::StartTransaction() { return Status::SUCCESS; } -// commit current transaction. all changes to this store will be done after calling this method. -// any calling of this method outside a transaction will fail. Status AnsTestSingleKvStore::Commit() { return Status::SUCCESS; } -// rollback current transaction. -// all changes to this store during this transaction will be rollback after calling this method. -// any calling of this method outside a transaction will fail. Status AnsTestSingleKvStore::Rollback() { return Status::SUCCESS; } -// set synchronization parameters of this store. -// Parameters: -// syncParam: sync policy parameter. -// Return: -// Status of this operation. Status AnsTestSingleKvStore::SetSyncParam(const KvSyncParam &syncParam) { return Status::SUCCESS; } -// get synchronization parameters of this store. -// Parameters: -// syncParam: sync policy parameter. -// Return: -// Status of this operation. Status AnsTestSingleKvStore::GetSyncParam(KvSyncParam &syncParam) { return Status::SUCCESS; diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 740e3b895..7711118f9 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -80,6 +80,7 @@ ohos_moduletest("ans_module_test") { "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//third_party/googletest:gtest_main", "//utils/native/base:utils", ] diff --git a/services/test/moduletest/ans_module_test.cpp b/services/test/moduletest/ans_module_test.cpp index b9a2f3535..fa3d4c130 100644 --- a/services/test/moduletest/ans_module_test.cpp +++ b/services/test/moduletest/ans_module_test.cpp @@ -72,10 +72,10 @@ public: } } - ConsumedFunc consumedCb_{nullptr}; - CanceledFunc canceledCb_{nullptr}; - std::function unSubscriberCb_{nullptr}; - std::function subscriberCb_{nullptr}; + ConsumedFunc consumedCb_ = nullptr; + CanceledFunc canceledCb_ = nullptr; + std::function unSubscriberCb_ = nullptr; + std::function subscriberCb_ = nullptr; }; class AnsModuleTest : public testing::Test { @@ -2324,46 +2324,31 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0122, Function | SmallTest | Level1) HWTEST_F(AnsModuleTest, AnsModuleTest_0123, Function | SmallTest | Level1) { int ret = 0; - - // subscriber auto subscriber = new TestAnsSubscriber(); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr); subscriber->consumedCb_ = [&ret](const std::shared_ptr notification, const std::shared_ptr sortingMap) { ret++; }; - subscriber->canceledCb_ = [](const std::shared_ptr &request, const std::shared_ptr &sortingMap, int deleteReason) { passed = true; }; - - // add slot std::vector> slots; - sptr socialSlot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - sptr reminderSlot = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER); - sptr contentSlot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION); - sptr otherSlot = new NotificationSlot(NotificationConstant::SlotType::OTHER); - sptr customSlot = new NotificationSlot(NotificationConstant::SlotType::CUSTOM); - - slots.push_back(socialSlot); - slots.push_back(reminderSlot); - slots.push_back(contentSlot); - slots.push_back(otherSlot); - slots.push_back(customSlot); - + slots.push_back(new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION)); + slots.push_back(new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER)); + slots.push_back(new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION)); + slots.push_back(new NotificationSlot(NotificationConstant::SlotType::OTHER)); + slots.push_back(new NotificationSlot(NotificationConstant::SlotType::CUSTOM)); EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), 0); - - // create request - std::string label = "testLabel"; sptr req = new NotificationRequest(0); sptr req1 = new NotificationRequest(1); sptr req2 = new NotificationRequest(2); sptr req3 = new NotificationRequest(3); sptr req4 = new NotificationRequest(4); - req->SetLabel(label); - req1->SetLabel(label); - req2->SetLabel(label); - req3->SetLabel(label); - req4->SetLabel(label); + req->SetLabel("testLabel"); + req1->SetLabel("testLabel"); + req2->SetLabel("testLabel"); + req3->SetLabel("testLabel"); + req4->SetLabel("testLabel"); req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); req1->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER); @@ -2371,17 +2356,16 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0123, Function | SmallTest | Level1) req3->SetSlotType(NotificationConstant::SlotType::OTHER); req4->SetSlotType(NotificationConstant::SlotType::CUSTOM); - g_advancedNotificationService->Publish(label, req); + g_advancedNotificationService->Publish("testLabel", req); EXPECT_EQ(ret, 0); - g_advancedNotificationService->Publish(label, req1); + g_advancedNotificationService->Publish("testLabel", req1); EXPECT_EQ(ret, 0); - g_advancedNotificationService->Publish(label, req2); + g_advancedNotificationService->Publish("testLabel", req2); EXPECT_EQ(ret, 0); - g_advancedNotificationService->Publish(label, req3); + g_advancedNotificationService->Publish("testLabel", req3); EXPECT_EQ(ret, 0); - g_advancedNotificationService->Publish(label, req4); + g_advancedNotificationService->Publish("testLabel", req4); EXPECT_EQ(ret, 0); - g_advancedNotificationService->DeleteAll(); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); EXPECT_FALSE(passed); @@ -2620,10 +2604,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0130, Function | SmallTest | Level1) // subscriber auto subscriber = new TestAnsSubscriber(); g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr); - subscriber->consumedCb_ = []( - const std::shared_ptr notification, - const std::shared_ptr sortingMap) - { + subscriber->consumedCb_ = + [](const std::shared_ptr notification, const std::shared_ptr sortingMap) { EXPECT_EQ(false, notification->EnableVibrate()); EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, notification->GetLockscreenVisibleness()); }; diff --git a/services/test/moduletest/mock/distributed_kv_data_manager.cpp b/services/test/moduletest/mock/distributed_kv_data_manager.cpp index 656932c20..d755b0151 100644 --- a/services/test/moduletest/mock/distributed_kv_data_manager.cpp +++ b/services/test/moduletest/mock/distributed_kv_data_manager.cpp @@ -17,7 +17,6 @@ #include "distributed_kv_data_manager.h" #include "constant.h" -//#include "ikvstore.h" #include "mock_single_kv_store.h" #include "types.h" diff --git a/services/test/moduletest/mock/include/mock_single_kv_store.h b/services/test/moduletest/mock/include/mock_single_kv_store.h index 8a777ea02..f32d46b6d 100644 --- a/services/test/moduletest/mock/include/mock_single_kv_store.h +++ b/services/test/moduletest/mock/include/mock_single_kv_store.h @@ -19,13 +19,13 @@ #include #include +#include "data_query.h" #include "kvstore.h" #include "kvstore_observer.h" #include "kvstore_result_set.h" #include "kvstore_sync_callback.h" -#include "types.h" -#include "data_query.h" #include "single_kvstore.h" +#include "types.h" namespace OHOS { namespace DistributedKv { @@ -33,218 +33,72 @@ namespace DistributedKv { // This class provides put, delete, search, sync and subscribe functions of a key-value store. class AnsTestSingleKvStore : public SingleKvStore { public: - - // Get all entries in this store which key start with prefixKey. - // Parameters: - // perfixkey: the prefix to be searched. - // entries: entries will be returned in this parameter. - // Return: - // Status of this GetEntries operation. virtual Status GetEntries(const Key &prefixKey, std::vector &entries) const override; - // Get all entries in this store by query. - // Parameters: - // query: the query string. - // entries: entries will be returned in this parameter. - // Return: - // Status of this GetEntries operation. virtual Status GetEntriesWithQuery(const std::string &query, std::vector &entries) const override; - // Get all entries in this store by query. - // Parameters: - // query: the query object. - // entries: entries will be returned in this parameter. - // Return: - // Status of this GetEntries operation. virtual Status GetEntriesWithQuery(const DataQuery &query, std::vector &entries) const override; - // Get ResultSet in this store which key start with prefixKey. - // Parameters: - // perfixkey: the prefix to be searched. - // resultSet: resultSet will be returned in this parameter. - // Return: - // Status of this GetResultSet operation. - virtual void GetResultSet(const Key &prefixKey, - std::function)> callback) const override; - - // Get ResultSet in this store by Query. - // Parameters: - // query: the query string. - // resultSet: resultSet will be returned in this parameter. - // Return: - // Status of this GetResultSet operation. + virtual void GetResultSet( + const Key &prefixKey, std::function)> callback) const override; + virtual void GetResultSetWithQuery(const std::string &query, - std::function)> callback) const override; - - // Get ResultSet in this store by Query. - // Parameters: - // query: the query object. - // resultSet: resultSet will be returned in this parameter. - // Return: - // Status of this GetResultSet operation. - virtual void GetResultSetWithQuery(const DataQuery &query, - std::function)> callback) const override; - - // Close the ResultSet returned by GetResultSet. - // Parameters: - // resultSet: resultSet will be returned in this parameter. - // Return: - // Status of this CloseResultSet operation. + std::function)> callback) const override; + + virtual void GetResultSetWithQuery( + const DataQuery &query, std::function)> callback) const override; + virtual Status CloseResultSet(std::unique_ptr resultSet) override; - // Get the number of result by query. - // Parameters: - // query: the query string. - // result: result will be returned in this parameter. - // Return: - // Status of this CloseResultSet operation. virtual Status GetCountWithQuery(const std::string &query, int &result) const override; - // Get the number of result by query. - // Parameters: - // query: the query object. - // result: result will be returned in this parameter. - // Return: - // Status of this CloseResultSet operation. virtual Status GetCountWithQuery(const DataQuery &query, int &result) const override; - // Sync store with other devices. This is an asynchronous method, - // sync will fail if there is a syncing operation in progress. - // Parameters: - // deviceIdList: device list to sync. - // mode: mode can be set to SyncMode::PUSH, SyncMode::PULL and SyncMode::PUTH_PULL. PUSH_PULL will firstly - // push all not-local store to listed devices, then pull these stores back. - // allowedDelayMs: allowed delay milli-second to sync. default value is 0 for compatibility. - // Return: - // Status of this Sync operation. - virtual Status Sync(const std::vector &deviceIdList, const SyncMode &mode, - uint32_t allowedDelayMs = 0) override; - - // Remove the device data synced from remote. - // Parameters: - // device: device id. - // Return: - // Status of this remove operation. + virtual Status Sync( + const std::vector &deviceIdList, const SyncMode &mode, uint32_t allowedDelayMs = 0) override; + virtual Status RemoveDeviceData(const std::string &device) override; - // Get id of this SingleKvStore. virtual StoreId GetStoreId() const override; - // Delete an entry by its key. - // Parameters: - // key: key of the entry to be deleted. - // Return: - // Status of this delete operation. virtual Status Delete(const Key &key) override; - // Write a pair of key and value to this store. - // Parameters: - // key: key of this entry. Should be less than 1024 bytes. key will be trimmed before store. - // value: value of this entry. Should be less than (4 * 1024 * 1024) bytes. - // Return: - // Status of this put operation. virtual Status Put(const Key &key, const Value &value) override; - // Get value from AppKvStore by its key. - // Parameters: - // key: key of this entry. - // value: value will be returned in this parameter. - // Return: - // Status of this get operation. virtual Status Get(const Key &key, Value &value) override; - // subscribe change of this kvstore to a client-defined observer. observer->OnChange method will be called when store - // changes. - // Parameters: - // subscribeType: SUBSCRIBE_TYPE_LOCAL means local changes of syncable kv store, - // : SUBSCRIBE_TYPE_REMOTE means synced data changes from remote devices, - // : SUBSCRIBE_TYPE_ALL means both local changes and synced data changes. - // observer: observer to subscribe changes. - // Return: - // Status of this subscribe operation. virtual Status SubscribeKvStore(SubscribeType subscribeType, std::shared_ptr observer) override; - // un-subscribe change of this kvstore to a client-defined observer. - // Parameters: - // subscribeType: SUBSCRIBE_TYPE_LOCAL means local changes of syncable kv store, - // : SUBSCRIBE_TYPE_REMOTE means synced data changes from remote devices, - // : SUBSCRIBE_TYPE_ALL means both local changes and synced data changes. - // observer: observer to subscribe changes. - // Return: - // Status of this subscribe operation. virtual Status UnSubscribeKvStore(SubscribeType subscribeType, std::shared_ptr observer) override; - // register message for sync operation. - // Parameters: - // callback: callback to register. - // Return: - // Status of this register operation. virtual Status RegisterSyncCallback(std::shared_ptr callback) override; - // un-register message for sync operation. - // Parameters: - // callback: callback to register. - // Return: - // Status of this register operation. virtual Status UnRegisterSyncCallback() override; - // see Put, PutBatch put a list of entries to kvstore, - // all entries will be put in a transaction, - // if entries contains invalid entry, PutBatch will all fail. - // entries's size should be less than 128 and memory size must be less than IPC transport limit. virtual Status PutBatch(const std::vector &entries) override; - // delete a list of entries in the kvstore, - // delete key not exist still return success, - // key length should not be greater than 256, and can not be empty. - // if keys contains invalid key, all delete will fail. - // keys memory size should not be greater than IPC transport limit, and can not be empty. virtual Status DeleteBatch(const std::vector &keys) override; - // start transaction. - // all changes to this kvstore will be in a same transaction and will not change the store until Commit() or - // Rollback() is called. - // before this transaction is committed or rollbacked, all attemption to close this store will fail. virtual Status StartTransaction() override; - // commit current transaction. all changes to this store will be done after calling this method. - // any calling of this method outside a transaction will fail. virtual Status Commit() override; - // rollback current transaction. - // all changes to this store during this transaction will be rollback after calling this method. - // any calling of this method outside a transaction will fail. virtual Status Rollback() override; - // set synchronization parameters of this store. - // Parameters: - // syncParam: sync policy parameter. - // Return: - // Status of this operation. virtual Status SetSyncParam(const KvSyncParam &syncParam) override; - // get synchronization parameters of this store. - // Parameters: - // syncParam: sync policy parameter. - // Return: - // Status of this operation. virtual Status GetSyncParam(KvSyncParam &syncParam) override; virtual Status SetCapabilityEnabled(bool enabled) const override; virtual Status SetCapabilityRange(const std::vector &localLabels, - const std::vector &remoteSupportLabels) const override; + const std::vector &remoteSupportLabels) const override; virtual Status GetSecurityLevel(SecurityLevel &securityLevel) const override; + protected: - // control this store. - // Parameters: - // inputParam: input parameter. - // output: output data, nullptr if no data is returned. - // Return: - // Status of this control operation. KVSTORE_API virtual Status Control(KvControlCmd cmd, const KvParam &inputParam, sptr &output) override; }; -} // namespace AppDistributedKv +} // namespace DistributedKv } // namespace OHOS #endif // SINGLE_KV_STORE_H diff --git a/services/test/moduletest/mock/mock_bundle_manager.cpp b/services/test/moduletest/mock/mock_bundle_manager.cpp index 340c592c3..98d2bcac2 100644 --- a/services/test/moduletest/mock/mock_bundle_manager.cpp +++ b/services/test/moduletest/mock/mock_bundle_manager.cpp @@ -19,6 +19,9 @@ namespace OHOS { namespace AppExecFwk { + +constexpr int SYSTEMAPP_UUID = 1000; + void MockBundleMgrService::MockSetIsSystemApp(bool isSystemApp) { isSystemAppMock_ = true; @@ -30,7 +33,7 @@ bool MockBundleMgrService::CheckIsSystemAppByUid(const int uid) if (isSystemAppMock_) { return isSystemApp_; } - return (uid < 1000) ? false : true; + return (uid < SYSTEMAPP_UUID) ? false : true; } int MockBundleMgrService::CheckPermission(const std::string &bundleName, const std::string &permission) diff --git a/services/test/moduletest/mock/mock_bundle_mgr_proxy.cpp b/services/test/moduletest/mock/mock_bundle_mgr_proxy.cpp index 7654e493f..5738fc881 100644 --- a/services/test/moduletest/mock/mock_bundle_mgr_proxy.cpp +++ b/services/test/moduletest/mock/mock_bundle_mgr_proxy.cpp @@ -258,13 +258,13 @@ bool BundleMgrProxy::UnregisterPermissionsChanged(const sptr +template bool BundleMgrProxy::GetParcelableInfo(IBundleMgr::Message code, MessageParcel &data, T &parcelableInfo) { return true; } -template +template bool BundleMgrProxy::GetParcelableInfos(IBundleMgr::Message code, MessageParcel &data, std::vector &parcelableInfos) { return true; diff --git a/services/test/moduletest/mock/mock_event_handler.cpp b/services/test/moduletest/mock/mock_event_handler.cpp index 4fcdd4a2c..12a7f65b9 100644 --- a/services/test/moduletest/mock/mock_event_handler.cpp +++ b/services/test/moduletest/mock/mock_event_handler.cpp @@ -17,108 +17,94 @@ #include "event_handler_utils.h" #include -namespace OHOS +namespace OHOS { +namespace AppExecFwk { + +std::shared_ptr EventHandler::Current() +{ + const std::weak_ptr &wp = std::make_shared(EventRunner::Create(true)); + return wp.lock(); +} + +EventHandler::EventHandler(const std::shared_ptr &runner) : eventRunner_(runner) +{} + +EventHandler::~EventHandler() +{} + +bool EventHandler::SendEvent(InnerEvent::Pointer &event, int64_t delayTime, Priority priority) +{ + std::function callback = event->GetTaskCallback(); + callback(); + return true; +} + +bool EventHandler::SendTimingEvent(InnerEvent::Pointer &event, int64_t taskTime, Priority priority) +{ + return true; +} + +bool EventHandler::SendSyncEvent(InnerEvent::Pointer &event, Priority priority) +{ + std::function callback = event->GetTaskCallback(); + callback(); + return true; +} + +void EventHandler::RemoveAllEvents() +{} + +void EventHandler::RemoveEvent(uint32_t innerEventId) +{} + +void EventHandler::RemoveEvent(uint32_t innerEventId, int64_t param) +{} + +void EventHandler::RemoveTask(const std::string &name) +{} + +ErrCode EventHandler::AddFileDescriptorListener( + int32_t fileDescriptor, uint32_t events, const std::shared_ptr &listener) { - namespace AppExecFwk - { - - std::shared_ptr EventHandler::Current() - { - const std::weak_ptr &wp = std::make_shared(EventRunner::Create(true)); - return wp.lock(); - } - - EventHandler::EventHandler(const std::shared_ptr &runner) : eventRunner_(runner) - { - } - - EventHandler::~EventHandler() - { - } - - bool EventHandler::SendEvent(InnerEvent::Pointer &event, int64_t delayTime, Priority priority) - { - std::function callback = event->GetTaskCallback(); - callback(); - return true; - } - - bool EventHandler::SendTimingEvent(InnerEvent::Pointer &event, int64_t taskTime, Priority priority) - { - return true; - } - - bool EventHandler::SendSyncEvent(InnerEvent::Pointer &event, Priority priority) - { - std::function callback = event->GetTaskCallback(); - callback(); - return true; - } - - void EventHandler::RemoveAllEvents() - { - } - - void EventHandler::RemoveEvent(uint32_t innerEventId) - { - } - - void EventHandler::RemoveEvent(uint32_t innerEventId, int64_t param) - { - } - - void EventHandler::RemoveTask(const std::string &name) - { - } - - ErrCode EventHandler::AddFileDescriptorListener( - int32_t fileDescriptor, uint32_t events, const std::shared_ptr &listener) - { - return EVENT_HANDLER_ERR_INVALID_PARAM; - } - - void EventHandler::RemoveAllFileDescriptorListeners() - { - } - - void EventHandler::RemoveFileDescriptorListener(int32_t fileDescriptor) - { - } - - void EventHandler::SetEventRunner(const std::shared_ptr &runner) - { - } - - void EventHandler::DistributeEvent(const InnerEvent::Pointer &event) - { - } - - void EventHandler::Dump(Dumper &dumper) - { - } - - bool EventHandler::HasInnerEvent(uint32_t innerEventId) - { - return true; - } - - bool EventHandler::HasInnerEvent(int64_t param) - { - return true; - } - - std::string EventHandler::GetEventName(const InnerEvent::Pointer &event) - { - return "132123"; - } - - bool EventHandler::IsIdle() - { - return true; - } - - void EventHandler::ProcessEvent(const InnerEvent::Pointer &) - { - } - } // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file + return EVENT_HANDLER_ERR_INVALID_PARAM; +} + +void EventHandler::RemoveAllFileDescriptorListeners() +{} + +void EventHandler::RemoveFileDescriptorListener(int32_t fileDescriptor) +{} + +void EventHandler::SetEventRunner(const std::shared_ptr &runner) +{} + +void EventHandler::DistributeEvent(const InnerEvent::Pointer &event) +{} + +void EventHandler::Dump(Dumper &dumper) +{} + +bool EventHandler::HasInnerEvent(uint32_t innerEventId) +{ + return true; +} + +bool EventHandler::HasInnerEvent(int64_t param) +{ + return true; +} + +std::string EventHandler::GetEventName(const InnerEvent::Pointer &event) +{ + return "132123"; +} + +bool EventHandler::IsIdle() +{ + return true; +} + +void EventHandler::ProcessEvent(const InnerEvent::Pointer &) +{} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/test/moduletest/mock/mock_single_kv_store.cpp b/services/test/moduletest/mock/mock_single_kv_store.cpp index 4b580d297..85aed3fef 100644 --- a/services/test/moduletest/mock/mock_single_kv_store.cpp +++ b/services/test/moduletest/mock/mock_single_kv_store.cpp @@ -18,132 +18,60 @@ namespace OHOS { namespace DistributedKv { -// Get all entries in this store which key start with prefixKey. -// Parameters: -// perfixkey: the prefix to be searched. -// entries: entries will be returned in this parameter. -// Return: -// Status of this GetEntries operation. + Status AnsTestSingleKvStore::GetEntries(const Key &prefixKey, std::vector &entries) const { return Status::SUCCESS; } -// Get all entries in this store by query. -// Parameters: -// query: the query string. -// entries: entries will be returned in this parameter. -// Return: -// Status of this GetEntries operation. Status AnsTestSingleKvStore::GetEntriesWithQuery(const std::string &query, std::vector &entries) const { return Status::SUCCESS; } -// Get all entries in this store by query. -// Parameters: -// query: the query object. -// entries: entries will be returned in this parameter. -// Return: -// Status of this GetEntries operation. Status AnsTestSingleKvStore::GetEntriesWithQuery(const DataQuery &query, std::vector &entries) const { return Status::SUCCESS; } -// Get ResultSet in this store which key start with prefixKey. -// Parameters: -// perfixkey: the prefix to be searched. -// resultSet: resultSet will be returned in this parameter. -// Return: -// Status of this GetResultSet operation. -void AnsTestSingleKvStore::GetResultSet(const Key &prefixKey, - std::function)> callback) const -{ - -} - -// Get ResultSet in this store by Query. -// Parameters: -// query: the query string. -// resultSet: resultSet will be returned in this parameter. -// Return: -// Status of this GetResultSet operation. -void AnsTestSingleKvStore::GetResultSetWithQuery(const std::string &query, - std::function)> callback) const -{ - -} +void AnsTestSingleKvStore::GetResultSet( + const Key &prefixKey, std::function)> callback) const +{} -// Get ResultSet in this store by Query. -// Parameters: -// query: the query object. -// resultSet: resultSet will be returned in this parameter. -// Return: -// Status of this GetResultSet operation. -void AnsTestSingleKvStore::GetResultSetWithQuery(const DataQuery &query, - std::function)> callback) const -{ +void AnsTestSingleKvStore::GetResultSetWithQuery( + const std::string &query, std::function)> callback) const +{} -} +void AnsTestSingleKvStore::GetResultSetWithQuery( + const DataQuery &query, std::function)> callback) const +{} -// Close the ResultSet returned by GetResultSet. -// Parameters: -// resultSet: resultSet will be returned in this parameter. -// Return: -// Status of this CloseResultSet operation. Status AnsTestSingleKvStore::CloseResultSet(std::unique_ptr resultSet) { return Status::SUCCESS; } -// Get the number of result by query. -// Parameters: -// query: the query string. -// result: result will be returned in this parameter. -// Return: -// Status of this CloseResultSet operation. Status AnsTestSingleKvStore::GetCountWithQuery(const std::string &query, int &result) const { return Status::SUCCESS; } -// Get the number of result by query. -// Parameters: -// query: the query object. -// result: result will be returned in this parameter. -// Return: -// Status of this CloseResultSet operation. Status AnsTestSingleKvStore::GetCountWithQuery(const DataQuery &query, int &result) const { return Status::SUCCESS; } -// Sync store with other devices. This is an asynchronous method, -// sync will fail if there is a syncing operation in progress. -// Parameters: -// deviceIdList: device list to sync. -// mode: mode can be set to SyncMode::PUSH, SyncMode::PULL and SyncMode::PUTH_PULL. PUSH_PULL will firstly -// push all not-local store to listed devices, then pull these stores back. -// allowedDelayMs: allowed delay milli-second to sync. default value is 0 for compatibility. -// Return: -// Status of this Sync operation. -Status AnsTestSingleKvStore::Sync(const std::vector &deviceIdList, const SyncMode &mode, uint32_t allowedDelayMs) +Status AnsTestSingleKvStore::Sync( + const std::vector &deviceIdList, const SyncMode &mode, uint32_t allowedDelayMs) { return Status::SUCCESS; } -// Remove the device data synced from remote. -// Parameters: -// device: device id. -// Return: -// Status of this remove operation. Status AnsTestSingleKvStore::RemoveDeviceData(const std::string &device) { return Status::SUCCESS; } -// Get id of this SingleKvStore. StoreId AnsTestSingleKvStore::GetStoreId() const { StoreId storeId; @@ -151,70 +79,31 @@ StoreId AnsTestSingleKvStore::GetStoreId() const return storeId; } -// Delete an entry by its key. -// Parameters: -// key: key of the entry to be deleted. -// Return: -// Status of this delete operation. Status AnsTestSingleKvStore::Delete(const Key &key) { return Status::SUCCESS; } -// Write a pair of key and value to this store. -// Parameters: -// key: key of this entry. Should be less than 1024 bytes. key will be trimmed before store. -// value: value of this entry. Should be less than (4 * 1024 * 1024) bytes. -// Return: -// Status of this put operation. Status AnsTestSingleKvStore::Put(const Key &key, const Value &value) { return Status::SUCCESS; } -// Get value from AppKvStore by its key. -// Parameters: -// key: key of this entry. -// value: value will be returned in this parameter. -// Return: -// Status of this get operation. Status AnsTestSingleKvStore::Get(const Key &key, Value &value) { return Status::SUCCESS; } -// subscribe change of this kvstore to a client-defined observer. observer->OnChange method will be called when store -// changes. -// Parameters: -// subscribeType: SUBSCRIBE_TYPE_LOCAL means local changes of syncable kv store, -// : SUBSCRIBE_TYPE_REMOTE means synced data changes from remote devices, -// : SUBSCRIBE_TYPE_ALL means both local changes and synced data changes. -// observer: observer to subscribe changes. -// Return: -// Status of this subscribe operation. Status AnsTestSingleKvStore::SubscribeKvStore(SubscribeType subscribeType, std::shared_ptr observer) { return Status::SUCCESS; } -// un-subscribe change of this kvstore to a client-defined observer. -// Parameters: -// subscribeType: SUBSCRIBE_TYPE_LOCAL means local changes of syncable kv store, -// : SUBSCRIBE_TYPE_REMOTE means synced data changes from remote devices, -// : SUBSCRIBE_TYPE_ALL means both local changes and synced data changes. -// observer: observer to subscribe changes. -// Return: -// Status of this subscribe operation. Status AnsTestSingleKvStore::UnSubscribeKvStore(SubscribeType subscribeType, std::shared_ptr observer) { return Status::SUCCESS; } -// register message for sync operation. -// Parameters: -// callback: callback to register. -// Return: -// Status of this register operation. Status AnsTestSingleKvStore::RegisterSyncCallback(std::shared_ptr callback) { return Status::SUCCESS; @@ -230,56 +119,31 @@ Status AnsTestSingleKvStore::PutBatch(const std::vector &entries) return Status::SUCCESS; } - -// delete a list of entries in the kvstore, -// delete key not exist still return success, -// key length should not be greater than 256, and can not be empty. -// if keys contains invalid key, all delete will fail. -// keys memory size should not be greater than IPC transport limit, and can not be empty. Status AnsTestSingleKvStore::DeleteBatch(const std::vector &keys) { return Status::SUCCESS; } -// start transaction. -// all changes to this kvstore will be in a same transaction and will not change the store until Commit() or -// Rollback() is called. -// before this transaction is committed or rollbacked, all attemption to close this store will fail. Status AnsTestSingleKvStore::StartTransaction() { return Status::SUCCESS; } -// commit current transaction. all changes to this store will be done after calling this method. -// any calling of this method outside a transaction will fail. Status AnsTestSingleKvStore::Commit() { return Status::SUCCESS; } -// rollback current transaction. -// all changes to this store during this transaction will be rollback after calling this method. -// any calling of this method outside a transaction will fail. Status AnsTestSingleKvStore::Rollback() { return Status::SUCCESS; } -// set synchronization parameters of this store. -// Parameters: -// syncParam: sync policy parameter. -// Return: -// Status of this operation. Status AnsTestSingleKvStore::SetSyncParam(const KvSyncParam &syncParam) { return Status::SUCCESS; } -// get synchronization parameters of this store. -// Parameters: -// syncParam: sync policy parameter. -// Return: -// Status of this operation. Status AnsTestSingleKvStore::GetSyncParam(KvSyncParam &syncParam) { return Status::SUCCESS; @@ -290,8 +154,8 @@ Status AnsTestSingleKvStore::SetCapabilityEnabled(bool enabled) const return Status::SUCCESS; } -Status AnsTestSingleKvStore::SetCapabilityRange(const std::vector &localLabels, - const std::vector &remoteSupportLabels) const +Status AnsTestSingleKvStore::SetCapabilityRange( + const std::vector &localLabels, const std::vector &remoteSupportLabels) const { return Status::SUCCESS; } @@ -306,6 +170,5 @@ Status AnsTestSingleKvStore::Control(KvControlCmd cmd, const KvParam &inputParam return Status::SUCCESS; } - } // namespace DistributedKv } // namespace OHOS \ No newline at end of file diff --git a/test/resource/ansSTSlotGroupTest/include/ans_slotgroup_test.h b/test/resource/ansSTSlotGroupTest/include/ans_slotgroup_test.h index d745fbf31..cdab5c143 100644 --- a/test/resource/ansSTSlotGroupTest/include/ans_slotgroup_test.h +++ b/test/resource/ansSTSlotGroupTest/include/ans_slotgroup_test.h @@ -18,7 +18,7 @@ #include #include "ability_loader.h" -#include +#include "notification_helper.h" #ifdef PRINT_LOG #undef PRINT_LOG #endif diff --git a/test/resource/ansSTSlotGroupTest/src/ans_slotgroup_test.cpp b/test/resource/ansSTSlotGroupTest/src/ans_slotgroup_test.cpp index 8f798c041..a1efa3a98 100644 --- a/test/resource/ansSTSlotGroupTest/src/ans_slotgroup_test.cpp +++ b/test/resource/ansSTSlotGroupTest/src/ans_slotgroup_test.cpp @@ -14,22 +14,23 @@ */ #include "ans_slotgroup_test.h" -#include +#include "notification_slot_group.h" namespace OHOS { namespace AppExecFwk { void AnsSlotGroupSystemTest::OnStart(const Want &want) { - APP_LOGI("====> ans SlotGroup test start:====>"); + APP_LOGI("====> ans SlotGroup test start====>"); Notification::NotificationSlotGroup notificationSlotGroupTest("id_test", "name_test"); + if (notificationSlotGroupTest.GetId().empty()) { ANS_LOGI("====> Notification slot group id is invalid====>"); } else { ANS_LOGI("====> Notification slot group id is====> %{public}s", notificationSlotGroupTest.GetId().c_str()); } + ErrCode errcodeAdd = Notification::NotificationHelper::AddNotificationSlotGroup(notificationSlotGroupTest); - printf("====> ErrCode Add:====> %d\n", errcodeAdd); - APP_LOGI("====> ansSlotGroupTest add add add add add add:====> %{public}d", errcodeAdd); + APP_LOGI("====> ansSlotGroupTest add:====> %{public}d", errcodeAdd); Notification::NotificationSlot notificationSlotFirst( Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION); @@ -42,34 +43,26 @@ void AnsSlotGroupSystemTest::OnStart(const Want &want) ErrCode errcodeAddSlotFirst = Notification::NotificationHelper::AddNotificationSlot(notificationSlotFirst); ErrCode errcodeAddSlotSecond = Notification::NotificationHelper::AddNotificationSlot(notificationSlotSecond); - APP_LOGI("====> ansSlotGroupTest:: errcodeAddSlotFirst :" - "====> %{public}d", - errcodeAddSlotFirst); - APP_LOGI("====> ansSlotGroupTest:: errcodeAddSlotSecond :" - "====> %{public}d", - errcodeAddSlotSecond); + APP_LOGI("====> ansSlotGroupTest errcodeAddSlotFirst:====> %{public}d", errcodeAddSlotFirst); + APP_LOGI("====> ansSlotGroupTest errcodeAddSlotSecond:====> %{public}d", errcodeAddSlotSecond); + sptr group; ErrCode errcodeGet = Notification::NotificationHelper::GetNotificationSlotGroup("id_test", group); - APP_LOGI("====> ansSlotGroupTest:: get get get get get get :" - "====> %{public}d", - errcodeGet); - std::string dumpGroupStr = group->Dump(); - APP_LOGI("====> ansSlotGroupTest:: dump dump dump dump dump :" - "====> %{public}s", - dumpGroupStr.c_str()); - APP_LOGI("====> ansSlotGroupTest:: the size of slots :" - "====> %{public}zu", - group->GetSlots().size()); + APP_LOGI("====> ansSlotGroupTest get:====> %{public}d", errcodeGet); + + if (group != nullptr) { + std::string dumpGroupStr = group->Dump(); + APP_LOGI("====> ansSlotGroupTest dump:====> %{public}s", dumpGroupStr.c_str()); + APP_LOGI("====> ansSlotGroupTest the size of slots:====> %{public}zu", group->GetSlots().size()); + } else { + APP_LOGI("====>group is null====>"); + } ErrCode errcodeRem = Notification::NotificationHelper::RemoveNotificationSlotGroup("id_test"); - APP_LOGI("====> ansSlotGroupTest:: remove remove remove remove :" - "====> %{public}d", - errcodeRem); + APP_LOGI("====> ansSlotGroupTest remove:====> %{public}d", errcodeRem); sptr groupTwo; ErrCode errcodeGetTwo = Notification::NotificationHelper::GetNotificationSlotGroup("id_test", groupTwo); - APP_LOGI("====> ansSlotGroupTest:: get get get get get get :" - "====> %{public}d", - errcodeGetTwo); + APP_LOGI("====> ansSlotGroupTest get:====> %{public}d", errcodeGetTwo); Ability::OnStart(want); } diff --git a/tools/dump/src/notification_shell_command.cpp b/tools/dump/src/notification_shell_command.cpp index a4c105699..8a2969d54 100644 --- a/tools/dump/src/notification_shell_command.cpp +++ b/tools/dump/src/notification_shell_command.cpp @@ -26,6 +26,15 @@ namespace OHOS { namespace Notification { namespace { + +static const struct option OPTIONS[] = { + {"help", no_argument, nullptr, 'h'}, + {"active", no_argument, nullptr, 'A'}, + {"recent", no_argument, nullptr, 'R'}, + {"setRecentCount", required_argument, nullptr, 0}, + {0, 0, 0, 0}, +}; + static const std::string HELP_MSG = "usage: anm []\n" "These are common commands list:\n" " help list available commands\n" @@ -82,19 +91,11 @@ ErrCode NotificationShellCommand::RunAsHelpCommand() ErrCode NotificationShellCommand::RunAsDumpCommand() { - struct option options[] = { - {"help", no_argument, nullptr, 'h'}, - {"active", no_argument, nullptr, 'A'}, - {"recent", no_argument, nullptr, 'R'}, - {"setRecentCount", required_argument, nullptr, 0}, - {0, 0, 0, 0}, - }; - int ind = 0; - int option = getopt_long(argc_, argv_, "hAR", options, &ind); + int option = getopt_long(argc_, argv_, "hAR", OPTIONS, &ind); ErrCode ret = ERR_OK; - std::vector infos{}; + std::vector infos; switch (option) { case 'h': @@ -118,7 +119,7 @@ ErrCode NotificationShellCommand::RunAsDumpCommand() break; case 0: if (ans_ != nullptr) { - ret = ans_->ShellDump(std::string(options[ind].name) + " " + std::string(optarg), infos); + ret = ans_->ShellDump(std::string(OPTIONS[ind].name) + " " + std::string(optarg), infos); } else { ret = ERR_ANS_SERVICE_NOT_CONNECTED; } -- Gitee