diff --git a/bundle.json b/bundle.json index 9f17e004b70ae041c1079fcd2adbeaab65a2a61c..4483576c442eb4ed2bac95c90c643c0fded319c0 100644 --- a/bundle.json +++ b/bundle.json @@ -84,6 +84,7 @@ ], "third_party": [ "libuv", + "libxml2", "icu" ] }, diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 2e1c717357798a52938bfc4501fc79548c48e418..c857d508903892697be73cc3df83080465730727 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -60,6 +60,17 @@ ErrCode NotificationHelper::GetNotificationSlotNumAsBundle(const NotificationBun return DelayedSingleton::GetInstance()->GetNotificationSlotNumAsBundle(bundleOption, num); } + +ErrCode NotificationHelper::GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slotFlags) +{ + return DelayedSingleton::GetInstance()->GetSlotFlagsAsBundle(bundleOption, slotFlags); +} + +ErrCode NotificationHelper::SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags) +{ + return DelayedSingleton::GetInstance()->SetSlotFlagsAsBundle(bundleOption, slotFlags); +} + ErrCode NotificationHelper::PublishNotification(const NotificationRequest &request) { return DelayedSingleton::GetInstance()->PublishNotification(request); diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index 3bef9e5d45d10402ec0eaeccae3b69e32ff98f0d..202fdcd57967398d88355234e03187fbbedcaf80 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -91,7 +91,7 @@ NotificationConstant::SlotType NotificationSlot::GetType() const void NotificationSlot::SetType(NotificationConstant::SlotType type) { - type_ = NotificationConstant::SlotType::CUSTOM; + type_ = NotificationConstant::SlotType::CUSTOMER_SERVICE; switch (type) { case NotificationConstant::SlotType::SOCIAL_COMMUNICATION: id_ = "SOCIAL_COMMUNICATION"; @@ -116,7 +116,7 @@ void NotificationSlot::SetType(NotificationConstant::SlotType type) SetEnableVibration(false); SetLevel(LEVEL_LOW); break; - case NotificationConstant::SlotType::OTHER: + case NotificationConstant::SlotType::OTHER_TYPES: id_ = "OTHER"; SetName("OTHER"); SetLockscreenVisibleness(NotificationConstant::VisiblenessType::SECRET); @@ -200,6 +200,16 @@ bool NotificationSlot::GetEnable() const return enabled_; } +void NotificationSlot::SetSlotFlags(uint32_t slotFlags) +{ + slotFlags_ = slotFlags; +} + +uint32_t NotificationSlot::GetSlotFlags() const +{ + return slotFlags_; +} + std::string NotificationSlot::Dump() const { return "NotificationSlot{ " @@ -217,6 +227,7 @@ std::string NotificationSlot::Dump() const ", vibration = " + MergeVectorToString(vibrationValues_) + ", isShowBadge = " + (isShowBadge_ ? "true" : "false") + ", enabled = " + (enabled_ ? "true" : "false") + + ", slotFlags = " + std::to_string(static_cast(slotFlags_)) + " }"; } @@ -303,6 +314,11 @@ bool NotificationSlot::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteInt32(slotFlags_)) { + ANS_LOGE("Failed to write slotFlags"); + return false; + } + return true; } @@ -332,12 +348,13 @@ bool NotificationSlot::ReadFromParcel(Parcel &parcel) parcel.ReadInt64Vector(&vibrationValues_); enabled_ = parcel.ReadBool(); + slotFlags_ = parcel.ReadInt32(); return true; } NotificationSlot *NotificationSlot::Unmarshalling(Parcel &parcel) { - NotificationSlot *notificationSlot = new (std::nothrow) NotificationSlot(NotificationConstant::SlotType::CUSTOM); + NotificationSlot *notificationSlot = new (std::nothrow) NotificationSlot(NotificationConstant::SlotType::CUSTOMER_SERVICE); if (notificationSlot && !notificationSlot->ReadFromParcel(parcel)) { delete notificationSlot; diff --git a/frameworks/ans/src/notification_sorting.cpp b/frameworks/ans/src/notification_sorting.cpp index 78699b112ca9c87693d2e2f91cccbc54013cd354..0eb450b2584e6422e7855639cb2b82efb14a1bbf 100644 --- a/frameworks/ans/src/notification_sorting.cpp +++ b/frameworks/ans/src/notification_sorting.cpp @@ -40,7 +40,7 @@ NotificationSorting::NotificationSorting(const NotificationSorting &sorting) void NotificationSorting::SetSlot(const sptr &slot) { if (slot == nullptr) { - slot_ = new (std::nothrow) NotificationSlot(NotificationConstant::SlotType::OTHER); + slot_ = new (std::nothrow) NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); return; } slot_ = slot; diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 773c451a259ff88ec9b0de860907f8a81d9391a2..364a266cd8f16debb200d10f6c4195a887706758 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -1218,11 +1218,11 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) READ_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); reminderType_ = static_cast(reminderType); - int32_t slotType = static_cast(NotificationConstant::SlotType::OTHER); + int32_t slotType = static_cast(NotificationConstant::SlotType::OTHER_TYPES); READ_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); slotType_ = static_cast(slotType); - int32_t snoozeSlotType = static_cast(NotificationConstant::SlotType::OTHER); + int32_t snoozeSlotType = static_cast(NotificationConstant::SlotType::OTHER_TYPES); READ_INT32_RETURN_FALSE_LOG(parcel, snoozeSlotType, "snoozeSlotType"); snoozeSlotType_ = static_cast(snoozeSlotType); @@ -1578,7 +1578,7 @@ void ReminderRequest::UpdateNotificationCommon(bool isSnooze) notificationRequest_->SetLabel(NOTIFICATION_LABEL); notificationRequest_->SetShowDeliveryTime(true); if (isSnooze) { - if (snoozeSlotType_ == NotificationConstant::SlotType::OTHER) { + if (snoozeSlotType_ == NotificationConstant::SlotType::OTHER_TYPES) { notificationRequest_->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); } else { notificationRequest_->SetSlotType(snoozeSlotType_); diff --git a/frameworks/ans/test/unittest/notification_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp index 0edf9670f9e8cd38a6492144faba92c44565ad4d..dc49fc3816f968d49eea4c4c77548caa59eabb35 100644 --- a/frameworks/ans/test/unittest/notification_helper_test.cpp +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -1053,7 +1053,7 @@ HWTEST_F(NotificationHelperTest, SetType_00001, Function | SmallTest | Level1) auto slot3 = std::make_shared(slotType); EXPECT_NE(slot3, nullptr); - slotType = NotificationConstant::SlotType::OTHER; + slotType = NotificationConstant::SlotType::OTHER_TYPES; auto slot4 = std::make_shared(slotType); EXPECT_NE(slot4, nullptr); } diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 957e21c213b3f0d3b445a9fc8ec6f1db039be05c..88d8b0047c2bd35988df83c21ef29f976f6e6fae 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1851,7 +1851,7 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00100, Function | SmallTe auto rrc = std::make_shared(); EXPECT_EQ(rrc->InitNotificationRequest(), true); sptr ret = rrc->GetNotificationRequest(); - rrc->snoozeSlotType_ = NotificationConstant::SlotType::OTHER; + rrc->snoozeSlotType_ = NotificationConstant::SlotType::OTHER_TYPES; bool isSnooze = true; // when diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index a58d2237f8bbb84b45dd35349a13d56067bf56e1..ad5ff9a8f718f1433d66f775fc4d1effce5aa5fb 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -684,6 +684,26 @@ public: */ virtual ErrCode SetBadgeNumber(int32_t badgeNumber) = 0; + /** + * @brief Obtains the number of slotFlags. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slot Indicates the specified slot object + * @param slotFlags Indicates the slogFlags of slot. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t &slotFlags) = 0; + + /** + * @brief Set the slotFlags of slot. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slot Indicates the specified slot object + * @param slotFlags Indicates the slogFlags of slot to set. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode SetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t slotFlags) = 0; + /** * @brief Register Push Callback. * diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 5c91814e3cc2cd707ba793f54c8e7ce474c7636d..c69143a499638c1d37388ac71d1475a6bf5a78c1 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -671,6 +671,26 @@ public: */ ErrCode SetBadgeNumber(int32_t badgeNumber) override; + /** + * @brief Get the slotFlags of slot. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slot Indicates the specified slot object + * @param slotFlags Indicates the slogFlags of slot to get. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t &slotFlags) override; + + /** + * @brief Set the slotFlags of slot. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slot Indicates the specified slot object + * @param slotFlags Indicates the slogFlags of slot to set. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode SetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) override; + /** * @brief Register Push Callback. * diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 4da073244fcfaea5436246f5c71edbe07c0d0d58..b0d8ee5a4fb805c62cf148a76748a961515ea608 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -686,6 +686,22 @@ public: */ virtual ErrCode SetBadgeNumber(int32_t badgeNumber) override; + /** + * @brief Get slotFlags. + * + * @param badgeNumber The slotFlags. + * @return Returns get slotFlags result. + */ + virtual ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t &slotFlags) override; + + /** + * @brief Set slotFlags. + * + * @param badgeNumber The slotFlags. + * @return Returns set slotFlags result. + */ + virtual ErrCode SetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) override; + /** * @brief Register Push Callback. * @@ -780,7 +796,8 @@ private: ErrCode HandleUnregisterPushCallback(MessageParcel &data, MessageParcel &reply); ErrCode HandleSubscribeLocalLiveView(MessageParcel &data, MessageParcel &reply); ErrCode HandleTriggerLocalLiveView(MessageParcel &data, MessageParcel &reply); - + ErrCode HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply); + ErrCode HandleSetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result) { diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index fff7608eca9991a3447f356ef56653ef19be30b4..be49c8a6eb0a0a58336110618f78c301806da530 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -102,6 +102,24 @@ public: */ ErrCode GetNotificationSlotNumAsBundle(const NotificationBundleOption &bundleOption, uint64_t &num); + /** + * @brief Obtains slotFlags of bundle. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slotFlags Indicates slotFlags of bundle. + * @return Returns get slotflags by bundle result. + */ + ErrCode GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slotFlags); + + /** + * @brief Set slotFlags of bundle. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slotFlags Indicates slotFlags of bundle. + * @return Returns set slotflags by bundle result. + */ + ErrCode SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags); + /** * @brief Publishes a notification. * @note If a notification with the same ID has been published by the current application and has not been deleted, diff --git a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h index 78f24ac5deb76ac191d1ecb0961967d5584d4087..2489f4e1669f4b5977181ac391e9d72616e9cdf4 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -120,6 +120,8 @@ namespace Notification { ON_RESPONSE, SUBSCRIBE_LOCAL_LIVE_VIEW_NOTIFICATION, TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION, + SET_SLOTFLAGS_BY_BUNDLE, + GET_SLOTFLAGS_BY_BUNDLE, }; } } diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 50666b0c84d02e88da7ef09dbc0d4cbc29c0380a..3bc0a11ec60871299bcd203963371e56fb175e6e 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2695,6 +2695,90 @@ ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber) return result; } +ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t& slotFlags) +{ + if (bundleOption == nullptr) { + ANS_LOGE("[GetSlotFlagsAsBundle] fail: bundle is empty."); + return ERR_ANS_INVALID_PARAM; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[GetSlotFlagsAsBundle] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteStrongParcelable(bundleOption)) { + ANS_LOGE("[GetSlotFlagsAsBundle] fail:: write bundle failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(slotFlags)) { + ANS_LOGE("[GetSlotFlagsAsBundle] fail: write slots failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::GET_SLOTFLAGS_BY_BUNDLE, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.ReadUint32(slotFlags)) { + ANS_LOGE("[GetSlotFlagsAsBundle] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + +ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) +{ + if (bundleOption == nullptr) { + ANS_LOGE("[SetSlotFlagsAsBundle] fail: bundleOption is empty."); + return ERR_ANS_INVALID_PARAM; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[SetSlotFlagsAsBundle] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteParcelable(bundleOption)) { + ANS_LOGE("[SetSlotFlagsAsBundle] fail:: write bundleoption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + uint32_t validSlotFlag = 0x001f&slotFlags;// got the LSB 5 bits as slotflags; + if (!data.WriteInt32(validSlotFlag)) { + ANS_LOGE("[SetSlotFlagsAsBundle] fail: write slots failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = { MessageOption::TF_SYNC }; + ErrCode result = InnerTransact(NotificationInterfaceCode::SET_SLOTFLAGS_BY_BUNDLE, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + ErrCode AnsManagerProxy::RegisterPushCallback(const sptr &pushCallback) { MessageParcel data; diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 47254fb7ca9a9af59bc8ad0f699761ceac6369e9..d90ff8308c9a524c2590758c9c88742822c512ca 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -259,6 +259,12 @@ const std::map bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t slotFlags = 0; + if (!data.ReadInt32(slotFlags)) { + ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: read notification failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetSlotFlagsAsBundle(bundleOption, slotFlags); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSetSlotFlagsAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply) +{ + sptr bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + uint32_t slotFlags = 0; + ErrCode result = GetSlotFlagsAsBundle(bundleOption, slotFlags); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteUint32(slotFlags)) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + ErrCode AnsManagerStub::HandleGetActiveNotifications(MessageParcel &data, MessageParcel &reply) { std::vector> notifications; @@ -1952,6 +2004,18 @@ ErrCode AnsManagerStub::GetBundleImportance(int &importance) return ERR_INVALID_OPERATION; } +ErrCode AnsManagerStub::GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t &slotFlags) +{ + ANS_LOGE("AnsManagerStub::GetSlotFlagsAsBundle called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::SetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) +{ + ANS_LOGE("AnsManagerStub::SetSlotFlagsAsBundle called!"); + return ERR_INVALID_OPERATION; +} + ErrCode AnsManagerStub::HasNotificationPolicyAccessPermission(bool &granted) { ANS_LOGE("AnsManagerStub::HasNotificationPolicyAccessPermission called!"); diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 38375666213aa5138a5efc1d572848635e78976d..e93fae9fbd66def1c67c131da2e3511890faa338 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -121,6 +121,38 @@ ErrCode AnsNotification::GetNotificationSlotNumAsBundle(const NotificationBundle return ansManagerProxy_->GetSlotNumAsBundle(bo, num); } +ErrCode AnsNotification::GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slotFlags) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + if (!GetAnsManagerProxy()) { + ANS_LOGE("Fail to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return ansManagerProxy_->GetSlotFlagsAsBundle(bo, slotFlags); +} + +ErrCode AnsNotification::SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags) +{ + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + if (!GetAnsManagerProxy()) { + ANS_LOGE("Fail to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + return ansManagerProxy_->SetSlotFlagsAsBundle(bo, slotFlags); +} + ErrCode AnsNotification::PublishNotification(const NotificationRequest &request) { ANS_LOGI("enter"); diff --git a/frameworks/js/napi/include/manager/napi_slot.h b/frameworks/js/napi/include/manager/napi_slot.h index 0d63119ae4e505560d11bb964c87e3546616cf1e..e688dc305582af770525dda7eca2bc1af52cca31 100644 --- a/frameworks/js/napi/include/manager/napi_slot.h +++ b/frameworks/js/napi/include/manager/napi_slot.h @@ -23,7 +23,7 @@ using namespace OHOS::Notification; struct ParametersInfoAddSlot { NotificationSlot slot; - NotificationConstant::SlotType inType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType inType = NotificationConstant::SlotType::OTHER_TYPES; bool isAddSlotByType = false; napi_ref callback = nullptr; }; @@ -32,7 +32,7 @@ struct AsyncCallbackInfoAddSlot { napi_env env = nullptr; napi_async_work asyncWork = nullptr; NotificationSlot slot; - NotificationConstant::SlotType inType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType inType = NotificationConstant::SlotType::OTHER_TYPES; bool isAddSlotByType = false; CallbackPromiseInfo info; }; @@ -63,14 +63,14 @@ struct AsyncCallbackInfoSetSlotByBundle { }; struct ParametersInfoGetSlot { - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; napi_ref callback = nullptr; }; struct AsyncCallbackInfoGetSlot { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; CallbackPromiseInfo info; sptr slot = nullptr; }; @@ -109,14 +109,14 @@ struct AsyncCallbackInfoGetSlotsByBundle { }; struct ParametersInfoRemoveSlot { - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; napi_ref callback = nullptr; }; struct AsyncCallbackInfoRemoveSlot { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; CallbackPromiseInfo info; }; @@ -128,7 +128,7 @@ struct AsyncCallbackInfoRemoveAllSlots { struct ParametersInfoEnableSlot { NotificationBundleOption option; - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; bool enable = false; napi_ref callback = nullptr; }; @@ -142,7 +142,7 @@ struct AsyncCallbackInfoInfoEnableSlot { struct ParametersInfoIsEnableSlot { NotificationBundleOption option; - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; napi_ref callback = nullptr; }; @@ -154,6 +154,32 @@ struct AsyncCallbackInfoInfoIsEnableSlot { CallbackPromiseInfo info; }; +struct ParametersInfoSetSlotFlagsByBundle { + NotificationBundleOption option; + uint32_t slotFlags; + napi_ref callback = nullptr; +}; + +struct ParametersInfoGetSlotFlagsByBundle { + NotificationBundleOption option; + napi_ref callback = nullptr; +}; + +struct AsyncCallbackInfoSetSlotFlagsByBundle { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + ParametersInfoSetSlotFlagsByBundle params; + CallbackPromiseInfo info; +}; + +struct AsyncCallbackInfoGetSlotFlagsByBundle { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + ParametersInfoGetSlotFlagsByBundle params; + CallbackPromiseInfo info; + uint32_t slotFlags = 0; +}; + napi_value NapiAddSlot(napi_env env, napi_callback_info info); napi_value NapiAddSlots(napi_env env, napi_callback_info info); napi_value NapiSetSlotByBundle(napi_env env, napi_callback_info info); @@ -165,6 +191,8 @@ napi_value NapiRemoveSlot(napi_env env, napi_callback_info info); napi_value NapiRemoveAllSlots(napi_env env, napi_callback_info info); napi_value NapiEnableNotificationSlot(napi_env env, napi_callback_info info); napi_value NapiIsEnableNotificationSlot(napi_env env, napi_callback_info info); +napi_value NapiSetSlotFlagsByBundle(napi_env env, napi_callback_info info); +napi_value NapiGetSlotFlagsByBundle(napi_env env, napi_callback_info info); napi_value ParseParametersByAddSlot(const napi_env &env, const napi_callback_info &info, ParametersInfoAddSlot ¶s); napi_value ParseParametersByAddSlots( @@ -182,6 +210,10 @@ napi_value ParseParametersEnableSlot( const napi_env &env, const napi_callback_info &info, ParametersInfoEnableSlot ¶ms); napi_value ParseParametersIsEnableSlot( const napi_env &env, const napi_callback_info &info, ParametersInfoIsEnableSlot ¶ms); +napi_value ParseParametersSetSlotFlagsByBundle( + const napi_env &env, const napi_callback_info &info, ParametersInfoSetSlotFlagsByBundle ¶ms); +napi_value ParseParametersGetSlotFlagsByBundle( + const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotFlagsByBundle ¶ms); } // namespace NotificationNapi } // namespace OHOS diff --git a/frameworks/js/napi/include/slot.h b/frameworks/js/napi/include/slot.h index 72017d1cc4e3637cfe43638492121e0006130e13..df15c58e73fd84280c447b6ad16b62dc766579df 100644 --- a/frameworks/js/napi/include/slot.h +++ b/frameworks/js/napi/include/slot.h @@ -32,6 +32,8 @@ napi_value RemoveSlot(napi_env env, napi_callback_info info); napi_value RemoveAllSlots(napi_env env, napi_callback_info info); napi_value EnableNotificationSlot(napi_env env, napi_callback_info info); napi_value IsEnableNotificationSlot(napi_env env, napi_callback_info info); +napi_value GetSlotFlagsByBundle(napi_env env, napi_callback_info info); +napi_value SetSlotFlagsByBundle(napi_env env, napi_callback_info info); } // namespace NotificationNapi } // namespace OHOS diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index f0e7d9160b9201d3cf315260bf6bd82bd54e7058..15dead8086b3803ce10e06c368b7ae25791e853c 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -1932,7 +1932,7 @@ napi_value Common::GetNotificationSlotType(const napi_env &env, const napi_value } napi_get_value_int32(env, result, &slotType); - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; if (!SlotTypeJSToC(SlotType(slotType), outType)) { return nullptr; } @@ -1951,7 +1951,7 @@ napi_value Common::GetNotificationSlotType(const napi_env &env, const napi_value } napi_get_value_int32(env, result, &slotType); - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; if (!SlotTypeJSToC(SlotType(slotType), outType)) { return nullptr; } @@ -1959,7 +1959,7 @@ napi_value Common::GetNotificationSlotType(const napi_env &env, const napi_value ANS_LOGI("slotType = %{public}d", slotType); } else { ANS_LOGI("default slotType = OTHER"); - request.SetSlotType(NotificationConstant::OTHER); + request.SetSlotType(NotificationConstant::OTHER_TYPES); } return NapiGetNull(env); @@ -4653,7 +4653,7 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va napi_get_value_int32(env, nobj, &slotType); } - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; if (!Common::SlotTypeJSToC(SlotType(slotType), outType)) { return nullptr; } @@ -5106,7 +5106,7 @@ bool Common::SlotTypeJSToC(const SlotType &inType, NotificationConstant::SlotTyp break; case SlotType::UNKNOWN_TYPE: case SlotType::OTHER_TYPES: - outType = NotificationConstant::SlotType::OTHER; + outType = NotificationConstant::SlotType::OTHER_TYPES; break; default: ANS_LOGE("SlotType %{public}d is an invalid value", inType); @@ -5118,7 +5118,7 @@ bool Common::SlotTypeJSToC(const SlotType &inType, NotificationConstant::SlotTyp bool Common::SlotTypeCToJS(const NotificationConstant::SlotType &inType, SlotType &outType) { switch (inType) { - case NotificationConstant::SlotType::CUSTOM: + case NotificationConstant::SlotType::UNKNOWN_TYPE: outType = SlotType::UNKNOWN_TYPE; break; case NotificationConstant::SlotType::SOCIAL_COMMUNICATION: @@ -5136,7 +5136,7 @@ bool Common::SlotTypeCToJS(const NotificationConstant::SlotType &inType, SlotTyp case NotificationConstant::SlotType::CUSTOMER_SERVICE: outType = SlotType::CUSTOMER_SERVICE; break; - case NotificationConstant::SlotType::OTHER: + case NotificationConstant::SlotType::OTHER_TYPES: outType = SlotType::OTHER_TYPES; break; default: diff --git a/frameworks/js/napi/src/manager/init_module.cpp b/frameworks/js/napi/src/manager/init_module.cpp index 3e82d3a482369e4488b2b979a4821b745e30dde1..4770767eb6eaa48d01fee0bbb38f9d373ec48f75 100644 --- a/frameworks/js/napi/src/manager/init_module.cpp +++ b/frameworks/js/napi/src/manager/init_module.cpp @@ -104,6 +104,8 @@ napi_value NotificationManagerInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getSyncNotificationEnabledWithoutApp", NapiGetSyncNotificationEnabledWithoutApp), DECLARE_NAPI_FUNCTION("subscribeSystemLiveView", NapiSubscriteLocalAcitvity), DECLARE_NAPI_FUNCTION("triggerSystemLiveView", NapiTriggerLocalLiveView), + DECLARE_NAPI_FUNCTION("setSlotFlagsByBundle", NapiSetSlotFlagsByBundle), + DECLARE_NAPI_FUNCTION("getSlotFlagsByBundle", NapiGetSlotFlagsByBundle), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); diff --git a/frameworks/js/napi/src/manager/napi_slot.cpp b/frameworks/js/napi/src/manager/napi_slot.cpp index dc889b8435d0a8c2c5272b1375989c658eb293bb..a637f642b15004abf3c847d9ac57a80ad6b3e2fa 100644 --- a/frameworks/js/napi/src/manager/napi_slot.cpp +++ b/frameworks/js/napi/src/manager/napi_slot.cpp @@ -910,5 +910,152 @@ napi_value NapiIsEnableNotificationSlot(napi_env env, napi_callback_info info) return promise; } } + +napi_value NapiSetSlotFlagsByBundle(napi_env env, napi_callback_info info) +{ + ANS_LOGI("enter"); + ParametersInfoSetSlotFlagsByBundle params {}; + if (ParseParametersSetSlotFlagsByBundle(env, info, params) == nullptr) { + Common::NapiThrow(env, ERROR_PARAM_INVALID); + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoSetSlotFlagsByBundle *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoSetSlotFlagsByBundle {.env = env, .asyncWork = nullptr, .params = params}; + if (!asynccallbackinfo) { + return Common::JSParaError(env, params.callback); + } + napi_value promise = nullptr; + Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); + + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "setSlotFlagsByBundle", NAPI_AUTO_LENGTH, &resourceName); + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("NapiSetSlotFlagsByBundle work excute."); + auto asynccallbackinfo = static_cast(data); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = NotificationHelper::SetNotificationSlotFlagsAsBundle( + asynccallbackinfo->params.option, asynccallbackinfo->params.slotFlags); + } + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("NapiSetSlotFlagsByBundle work complete."); + auto asynccallbackinfo = static_cast(data); + if (asynccallbackinfo) { + Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete napiSetSlotFlagsByBundle callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + ANS_LOGD("NapiSetSlotFlagsByBundle work complete end."); + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + + bool isCallback = asynccallbackinfo->info.isCallback; + napi_status status = napi_queue_async_work_with_qos(env, asynccallbackinfo->asyncWork, napi_qos_user_initiated); + if (status != napi_ok) { + ANS_LOGE("Queue napiSetSlotFlagsByBundle work failed return: %{public}d", status); + asynccallbackinfo->info.errorCode = ERROR_INTERNAL_ERROR; + Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete napiSetSlotFlagsByBundle callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + + if (isCallback) { + ANS_LOGD("napiSetSlotFlagsByBundle callback is nullptr."); + return Common::NapiGetNull(env); + } else { + return promise; + } +} + +napi_value NapiGetSlotFlagsByBundle(napi_env env, napi_callback_info info) +{ + ANS_LOGI("enter"); + ParametersInfoGetSlotFlagsByBundle params {}; + if (ParseParametersGetSlotFlagsByBundle(env, info, params) == nullptr) { + Common::NapiThrow(env, ERROR_PARAM_INVALID); + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoGetSlotFlagsByBundle *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoGetSlotFlagsByBundle {.env = env, .asyncWork = nullptr, .params = params}; + if (!asynccallbackinfo) { + return Common::JSParaError(env, params.callback); + } + napi_value promise = nullptr; + Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); + + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "getSlotFlagsByBundle", NAPI_AUTO_LENGTH, &resourceName); + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("NapiGetSlotFlagsByBundle work excute."); + auto asynccallbackinfo = reinterpret_cast(data); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = NotificationHelper::GetNotificationSlotFlagsAsBundle( + asynccallbackinfo->params.option, asynccallbackinfo->slotFlags); + } + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("NapiGetSlotFlagsByBundle work complete."); + auto asynccallbackinfo = static_cast(data); + if (asynccallbackinfo) { + napi_value result = nullptr; + napi_create_uint32(env, asynccallbackinfo->slotFlags, &result); + Common::CreateReturnValue(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete napiGetSlotFlagsByBundle callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + ANS_LOGD("NapiGetSlotFlagsByBundle work complete end."); + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + + bool isCallback = asynccallbackinfo->info.isCallback; + napi_status status = napi_queue_async_work_with_qos(env, asynccallbackinfo->asyncWork, napi_qos_user_initiated); + if (status != napi_ok) { + ANS_LOGE("Queue napiGetSlotFlagsByBundle work failed return: %{public}d", status); + asynccallbackinfo->info.errorCode = ERROR_INTERNAL_ERROR; + Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete napiGetSlotFlagsByBundle callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + + if (isCallback) { + ANS_LOGD("napiGetSlotFlagsByBundle callback is nullptr."); + return Common::NapiGetNull(env); + } else { + return promise; + } +} + } // namespace NotificationNapi } // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index fa2ce981388c9807aa119bdeb10969e29ecd7325..f14a3d6dd1d9cc2ac8e6ea803dc233dac651cb80 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -495,7 +495,7 @@ napi_value ReminderCommon::GenReminder( // slotType int32_t slotType = 0; if (GetInt32(env, value, ReminderAgentNapi::SLOT_TYPE, slotType, false)) { - enum NotificationConstant::SlotType actureType = NotificationConstant::SlotType::OTHER; + enum NotificationConstant::SlotType actureType = NotificationConstant::SlotType::OTHER_TYPES; if (!NotificationNapi::Common::SlotTypeJSToC(NotificationNapi::SlotType(slotType), actureType)) { ANSR_LOGW("slot type not support."); return nullptr; @@ -506,7 +506,7 @@ napi_value ReminderCommon::GenReminder( // snoozeSlotType int32_t snoozeSlotType = 0; if (GetInt32(env, value, ReminderAgentNapi::SNOOZE_SLOT_TYPE, snoozeSlotType, false)) { - enum NotificationConstant::SlotType actureSnoozeType = NotificationConstant::SlotType::OTHER; + enum NotificationConstant::SlotType actureSnoozeType = NotificationConstant::SlotType::OTHER_TYPES; if (!NotificationNapi::Common::SlotTypeJSToC(NotificationNapi::SlotType(snoozeSlotType), actureSnoozeType)) { ANSR_LOGW("snooze slot type not support."); return nullptr; diff --git a/frameworks/js/napi/src/slot.cpp b/frameworks/js/napi/src/slot.cpp index 1005a040c3a6ad76013f5636fbccf7f3aaa2ae35..ac90ef227dacd2d617e4f453113f68451ccc4924 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -29,7 +29,7 @@ const int32_t SET_ENABLE_SLOT_MAX_PARA = 4; struct ParametersInfoAddSlot { NotificationSlot slot; - NotificationConstant::SlotType inType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType inType = NotificationConstant::SlotType::OTHER_TYPES; bool isAddSlotByType = false; napi_ref callback = nullptr; }; @@ -38,7 +38,7 @@ struct AsyncCallbackInfoAddSlot { napi_env env = nullptr; napi_async_work asyncWork = nullptr; NotificationSlot slot; - NotificationConstant::SlotType inType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType inType = NotificationConstant::SlotType::OTHER_TYPES; bool isAddSlotByType = false; CallbackPromiseInfo info; }; @@ -69,14 +69,14 @@ struct AsyncCallbackInfoSetSlotByBundle { }; struct ParametersInfoGetSlot { - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; napi_ref callback = nullptr; }; struct AsyncCallbackInfoGetSlot { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; CallbackPromiseInfo info; sptr slot = nullptr; }; @@ -115,14 +115,14 @@ struct AsyncCallbackInfoGetSlotsByBundle { }; struct ParametersInfoRemoveSlot { - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; napi_ref callback = nullptr; }; struct AsyncCallbackInfoRemoveSlot { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; CallbackPromiseInfo info; }; @@ -134,7 +134,7 @@ struct AsyncCallbackInfoRemoveAllSlots { struct ParametersInfoEnableSlot { NotificationBundleOption option; - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; bool enable = false; napi_ref callback = nullptr; }; @@ -148,7 +148,7 @@ struct AsyncCallbackInfoInfoEnableSlot { struct ParametersInfoIsEnableSlot { NotificationBundleOption option; - NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; napi_ref callback = nullptr; }; @@ -160,9 +160,35 @@ struct AsyncCallbackInfoInfoIsEnableSlot { CallbackPromiseInfo info; }; +struct ParametersInfoSetSlotFlagsByBundle { + NotificationBundleOption option; + uint32_t slotFlags; + napi_ref callback = nullptr; +}; + +struct ParametersInfoGetSlotFlagsByBundle { + NotificationBundleOption option; + napi_ref callback = nullptr; +}; + +struct AsyncCallbackInfoSetSlotFlagsByBundle { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + ParametersInfoSetSlotFlagsByBundle params; + CallbackPromiseInfo info; +}; + +struct AsyncCallbackInfoGetSlotFlagsByBundle { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + ParametersInfoGetSlotFlagsByBundle params; + CallbackPromiseInfo info; + uint32_t slotFlags = 0; +}; + napi_value ParseParametersByAddSlot(const napi_env &env, const napi_callback_info &info, ParametersInfoAddSlot ¶s) { - ANS_LOGI("enter"); + ANS_LOGI("ParseParametersByAddSlot enter"); size_t argc = ADD_SLOT_MAX_PARA; napi_value argv[ADD_SLOT_MAX_PARA] = {nullptr}; napi_value thisVar = nullptr; @@ -202,12 +228,14 @@ napi_value ParseParametersByAddSlot(const napi_env &env, const napi_callback_inf } napi_create_reference(env, argv[PARAM1], 1, ¶s.callback); } + + ANS_LOGI("ParseParametersByAddSlot OUT"); return Common::NapiGetNull(env); } napi_value ParseParametersByAddSlots(const napi_env &env, const napi_callback_info &info, ParametersInfoAddSlots ¶s) { - ANS_LOGI("enter"); + ANS_LOGI("ParseParametersByAddSlots enter"); size_t argc = ADD_SLOTS_MAX_PARA; napi_value argv[ADD_SLOTS_MAX_PARA] = {nullptr}; napi_value thisVar = nullptr; @@ -255,13 +283,14 @@ napi_value ParseParametersByAddSlots(const napi_env &env, const napi_callback_in } napi_create_reference(env, argv[PARAM1], 1, ¶s.callback); } + ANS_LOGI("ParseParametersByAddSlots out"); return Common::NapiGetNull(env); } napi_value ParseParametersSetSlotByBundle( const napi_env &env, const napi_callback_info &info, ParametersInfoSetSlotByBundle ¶ms) { - ANS_LOGI("enter"); + ANS_LOGI("ParseParametersSetSlotByBundle enter"); size_t argc = SET_SLOT_AS_BUNDLE_MAX_PARA; napi_value argv[SET_SLOT_AS_BUNDLE_MAX_PARA] = {nullptr}; @@ -397,6 +426,101 @@ napi_value ParseParametersGetSlotNumByBundle( return Common::NapiGetNull(env); } + +napi_value ParseParametersSetSlotFlagsByBundle( + const napi_env &env, const napi_callback_info &info, ParametersInfoSetSlotFlagsByBundle ¶ms) + { + ANS_LOGI("ParseParametersSetSlotByBundle enter"); + + size_t argc = SET_SLOT_AS_BUNDLE_MAX_PARA; + napi_value argv[SET_SLOT_AS_BUNDLE_MAX_PARA] = {nullptr}; + napi_value thisVar = nullptr; + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); + if (argc < SET_SLOT_AS_BUNDLE_MAX_PARA - 1) { + ANS_LOGE("Wrong number of arguments."); + return nullptr; + } + + // argv[0]: bundle + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); + if (valuetype != napi_object) { + ANS_LOGE("Argument type error. Object expected."); + return nullptr; + } + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); + if (retValue == nullptr) { + ANS_LOGE("GetBundleOption failed."); + return nullptr; + } + + // //argv[1]:slotFlags + // NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); + // if (valuetype != napi_number) { + // ANS_LOGE("Error argument type. Number expected."); + // return nullptr; + // } + ANS_LOGI("ParseParametersSetSlotByBundle enter1"); + int32_t slotFlags = 0; + napi_get_value_int32(env, argv[PARAM1], &slotFlags); + params.slotFlags = slotFlags; + ANS_LOGI("enter2"); + // argv[2]:callback + if (argc >= SET_SLOT_AS_BUNDLE_MAX_PARA) { + NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); + if (valuetype != napi_function) { + ANS_LOGE("Callback is not function excute promise."); + return Common::NapiGetNull(env); + } + ANS_LOGI("ParseParametersSetSlotByBundle enter3"); + napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); + } + + ANS_LOGI("ParseParametersSetSlotByBundle out!"); + return Common::NapiGetNull(env); + } + +napi_value ParseParametersGetSlotFlagsByBundle( + const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotFlagsByBundle ¶ms) + { + ANS_LOGI("enter"); + + size_t argc = GET_SLOTS_AS_BUNDLE_MAX_PARA; + napi_value argv[GET_SLOTS_AS_BUNDLE_MAX_PARA] = {nullptr}; + napi_value thisVar = nullptr; + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); + if (argc < GET_SLOTS_AS_BUNDLE_MAX_PARA - 1) { + ANS_LOGE("Wrong number of arguments"); + return nullptr; + } + + // argv[0]: bundle + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); + if (valuetype != napi_object) { + ANS_LOGE("Wrong argument type. Object expected."); + return nullptr; + } + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); + if (retValue == nullptr) { + ANS_LOGE("GetBundleOption failed."); + return nullptr; + } + + // argv[1]:callback + if (argc >= GET_SLOTS_AS_BUNDLE_MAX_PARA) { + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); + if (valuetype != napi_function) { + ANS_LOGE("Callback is not function excute promise."); + return Common::NapiGetNull(env); + } + napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); + } + + return Common::NapiGetNull(env); + + } + napi_value ParseParametersGetSlotsByBundle( const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotsByBundle ¶ms) { @@ -1462,5 +1586,155 @@ napi_value IsEnableNotificationSlot(napi_env env, napi_callback_info info) return promise; } } + +napi_value GetSlotFlagsByBundle(napi_env env, napi_callback_info info) +{ + ANS_LOGI("enter"); + + ParametersInfoGetSlotFlagsByBundle params {}; + if (ParseParametersGetSlotFlagsByBundle(env, info, params) == nullptr) { + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoGetSlotFlagsByBundle *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoGetSlotFlagsByBundle {.env = env, .asyncWork = nullptr, .params = params}; + if (!asynccallbackinfo) { + ANS_LOGD("Asynccallbackinfo is nullptr."); + return Common::JSParaError(env, params.callback); + } + napi_value promise = nullptr; + Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); + + ANS_LOGD("create getSlotFlagsByBundle string."); + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "getSlotFlagsByBundle", NAPI_AUTO_LENGTH, &resourceName); + + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("GetSlotFlagsByBundle napi_create_async_work start"); + auto asynccallbackinfo = reinterpret_cast(data); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = NotificationHelper::GetNotificationSlotFlagsAsBundle( + asynccallbackinfo->params.option, asynccallbackinfo->slotFlags); + } + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("GetSlotFlagsByBundle napi_create_async_work end"); + auto asynccallbackinfo = static_cast(data); + if (asynccallbackinfo) { + napi_value result = nullptr; + napi_create_uint32(env, asynccallbackinfo->slotFlags, &result); + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete getSlotFlagsByBundle callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + ANS_LOGD("GetSlotFlagsByBundle work complete end."); + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + + napi_status status = napi_queue_async_work_with_qos(env, asynccallbackinfo->asyncWork, napi_qos_user_initiated); + if (status != napi_ok) { + ANS_LOGE("Queue getSlotFlagsByBundle work failed return: %{public}d", status); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + return Common::JSParaError(env, params.callback); + } + + if (asynccallbackinfo->info.isCallback) { + ANS_LOGD("getSlotFlagsByBundle callback is nullptr."); + return Common::NapiGetNull(env); + } else { + return promise; + } + //return Common::NapiGetUndefined(env); +} + +napi_value SetSlotFlagsByBundle(napi_env env, napi_callback_info info) +{ + ANS_LOGI("SetSlotFlagsByBundle enter"); + + ParametersInfoSetSlotFlagsByBundle params {}; + if (ParseParametersSetSlotFlagsByBundle(env, info, params) == nullptr) { + ANS_LOGI("Call ParseParametersSetSlotFlagsByBundle return nullptr"); + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoSetSlotFlagsByBundle *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoSetSlotFlagsByBundle {.env = env, .asyncWork = nullptr, .params = params}; + if (!asynccallbackinfo) { + ANS_LOGD("Asynccallbackinfo is nullptr."); + return Common::JSParaError(env, params.callback); + } + napi_value promise = nullptr; + Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); + + ANS_LOGD("Create setSlotFlagsByBundle string."); + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "setSlotFlagsByBundle", NAPI_AUTO_LENGTH, &resourceName); + + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("SetSlotFlagsByBundle napi_create_async_work start"); + auto asynccallbackinfo = static_cast(data); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = NotificationHelper::SetNotificationSlotFlagsAsBundle( + asynccallbackinfo->params.option, asynccallbackinfo->params.slotFlags); + } + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("SetSlotFlagsByBundle napi_create_async_work end"); + auto asynccallbackinfo = static_cast(data); + if (asynccallbackinfo) { + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete setSlotFlagsByBundle callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + ANS_LOGD("SetSlotFlagsByBundle work complete end."); + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + + napi_status status = napi_queue_async_work_with_qos(env, asynccallbackinfo->asyncWork, napi_qos_user_initiated); + if (status != napi_ok) { + ANS_LOGE("Queue setSlotFlagsByBundle work failed return: %{public}d", status); + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + return Common::JSParaError(env, params.callback); + } + + if (asynccallbackinfo->info.isCallback) { + ANS_LOGD("setSlotFlagsByBundle callback is nullptr."); + return Common::NapiGetNull(env); + } else { + return promise; + } + ANS_LOGI("SetSlotFlagsByBundle out"); +} + } // namespace NotificationNapi } // namespace OHOS \ No newline at end of file diff --git a/frameworks/test/moduletest/ans_fw_module_test.cpp b/frameworks/test/moduletest/ans_fw_module_test.cpp index c1dd06bbe84b7449fb492f186f4d4ac542633f77..799b81eab6e54b21b756e54cb05371b36ff0157e 100644 --- a/frameworks/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/test/moduletest/ans_fw_module_test.cpp @@ -1235,7 +1235,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishNotificationWithPixelMap_00100, Funct const int ICON_SIZE = 36; NotificationRequest req; - req.SetSlotType(NotificationConstant::SlotType::OTHER); + req.SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req.SetLabel("label"); std::shared_ptr pictureContent = std::make_shared(); EXPECT_NE(pictureContent, nullptr); @@ -1267,7 +1267,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishNotificationWithPixelMap_00200, Funct const int ICON_SIZE = 36; NotificationRequest req; - req.SetSlotType(NotificationConstant::SlotType::OTHER); + req.SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req.SetLabel("label"); std::shared_ptr pictureContent = std::make_shared(); EXPECT_NE(pictureContent, nullptr); @@ -1299,7 +1299,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishNotificationWithPixelMap_00300, Funct const int ICON_SIZE = 256; NotificationRequest req; - req.SetSlotType(NotificationConstant::SlotType::OTHER); + req.SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req.SetLabel("label"); std::shared_ptr pictureContent = std::make_shared(); EXPECT_NE(pictureContent, nullptr); diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 564e87bb3a7f55f11a9245fda9d2fc764a04f34b..29eb212279cb8fceeb59606d7d9cf675f9a64a53 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -57,13 +57,13 @@ public: }; enum SlotType { - SOCIAL_COMMUNICATION, // the notification type is social communication - SERVICE_REMINDER, // the notification type is service reminder - CONTENT_INFORMATION, // the notificatin type is content information - OTHER, // the notificatin type is other - CUSTOM, // the notification type is custom - LIVE_VIEW, // the notification type is live view - CUSTOMER_SERVICE, // the notification type is customer service + UNKNOWN_TYPE =0, + SOCIAL_COMMUNICATION =1, // the notification type is social communication + SERVICE_REMINDER =2, // the notification type is service reminder + CONTENT_INFORMATION =3, // the notificatin type is content information + LIVE_VIEW =4, // the notification type is live view + CUSTOMER_SERVICE =5, // the notification type is customer service + OTHER_TYPES =0xFFFF, }; enum class VisiblenessType { @@ -190,6 +190,8 @@ public: constexpr static const char* NOTIFICATION_JOURNAL_MODE = "WAL"; constexpr static const char* NOTIFICATION_SYNC_MODE = "FULL"; constexpr static int32_t NOTIFICATION_RDB_VERSION = 1; + constexpr static const char* NOTIFICATION_SLOTFLAG_CONFIG_PATH = "/etc/notification_reminder_config.ccm"; + constexpr static const char * SLOTTYPECCMNAMES[] = {"Social_communication", "Service_reminder", "Content_information", "Live_view", "Custom_service", "Other"}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index e07cd0d174034d34960000b97dd465f4d5a622ef..281e51673b7285635b1a565a8e6504af68c04511 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -104,6 +104,24 @@ public: */ static ErrCode GetNotificationSlotNumAsBundle(const NotificationBundleOption &bundleOption, uint64_t &num); + /** + * @brief Obtains slotflags of bundle. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slotFlags Indicates slotFlags of bundle. + * @return Returns get slotFlags by bundle result. + */ + static ErrCode GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slotFlags); + + /** + * @brief set slotflags of bundle. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slotFlags Indicates slotFlags of bundle. + * @return Returns get slotFlags by bundle result. + */ + static ErrCode SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags); + /** * @brief Publishes a notification. * @note If a notification with the same ID has been published by the current application and has not been deleted, diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index d080a7d91e29bac4403b4845183bb376ba0b8162..29111da75a0a7666c94c0f05ce1d3a7287abfc83 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -1153,7 +1153,7 @@ private: std::string sortingKey_ {}; std::string classification_ {}; - NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::OTHER}; + NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::OTHER_TYPES}; NotificationRequest::GroupAlertType groupAlertType_ {NotificationRequest::GroupAlertType::ALL}; NotificationConstant::VisiblenessType visiblenessType_ {NotificationConstant::VisiblenessType::NO_OVERRIDE}; NotificationRequest::BadgeStyle badgeStyle_ {NotificationRequest::BadgeStyle::NONE}; diff --git a/interfaces/inner_api/notification_slot.h b/interfaces/inner_api/notification_slot.h index 354938d857cdbf762fda984813b256a04a0a9409..706b61ae7192ed1544ddec2e95022df2e7cc04d7 100644 --- a/interfaces/inner_api/notification_slot.h +++ b/interfaces/inner_api/notification_slot.h @@ -43,7 +43,7 @@ public: * * @param type Specifies the type of the NotificationSlot object, */ - NotificationSlot(NotificationConstant::SlotType type = NotificationConstant::SlotType::CUSTOM); + NotificationSlot(NotificationConstant::SlotType type = NotificationConstant::SlotType::CUSTOMER_SERVICE); ~NotificationSlot(); @@ -146,6 +146,24 @@ public: */ void SetLevel(NotificationLevel level); + + /** + * @brief Obtains the slotflags of a NotificationSlot object, which is set by SetSlotFlags(uint32_t slotFlags). + * + * @return Returns the slotflags of the NotificationSlot object. + */ + uint32_t GetSlotFlags() const; + + /** + * @brief Sets the slotflags of a NotificationSlot object. + * @note SetSlotFlags must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) method is called. + * Otherwise, the settings will not take effect. + * + * @param level Specifies the slotflags of the NotificationSlot object, which determines the notification display + * effect. The value can be LEVEL_NONE, LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, or LEVEL_HIGH. + */ + void SetSlotFlags(uint32_t slotFlags); + /** * @brief Obtains the type of a NotificationSlot object, which is set by SetType(SlotType). * @@ -352,7 +370,7 @@ private: Uri sound_; std::vector vibrationValues_ {}; bool enabled_ {true}; - + uint32_t slotFlags_{0}; // no object in parcel static constexpr int32_t VALUE_NULL = -1; // object exist in parcel diff --git a/interfaces/inner_api/notification_sorting.h b/interfaces/inner_api/notification_sorting.h index 32410161396fafd50bc7a8b5bcbfb837fa820b7d..37e8adaeee6f5f8a89ccd176498288ea78aad005 100644 --- a/interfaces/inner_api/notification_sorting.h +++ b/interfaces/inner_api/notification_sorting.h @@ -163,7 +163,7 @@ private: bool isHiddenNotification_ {}; std::string groupKeyOverride_ {}; int32_t visiblenessOverride_ {}; - sptr slot_ = new (std::nothrow) NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot_ = new (std::nothrow) NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); friend class AdvancedNotificationService; }; diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index b96f031e71a032ad6ce808e7b1a4423d4fd68529..464bc8d4a2494069a640e59256b498022b981ad6 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -1031,7 +1031,7 @@ private: uint64_t timeIntervalInMilli_ {0}; ReminderType reminderType_ {ReminderType::INVALID}; NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::SOCIAL_COMMUNICATION}; - NotificationConstant::SlotType snoozeSlotType_ {NotificationConstant::SlotType::OTHER}; + NotificationConstant::SlotType snoozeSlotType_ {NotificationConstant::SlotType::OTHER_TYPES}; sptr notificationRequest_ = nullptr; std::shared_ptr wantAgentInfo_ = nullptr; std::shared_ptr maxScreenWantAgentInfo_ = nullptr; diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index a1a5c4fb5e24f1d2e6c499dd2745d92d367e7c01..82b8a2ac83e72754945021b8d281a93bf50180b6 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -44,6 +44,7 @@ ohos_shared_library("libans") { ] sources = [ + "src/notification_config_parse.cpp", "src/access_token_helper.cpp", "src/advanced_notification_service.cpp", "src/advanced_notification_service_ability.cpp", @@ -75,6 +76,7 @@ ohos_shared_library("libans") { deps = [ "${frameworks_module_ans_path}:ans_innerkits", "//third_party/icu/icu4c:shared_icuuc", + "//third_party/libxml2:libxml2", ] if (is_double_framework) { diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index eb54f425914f30976bf9120e1e349e4387d9d6ae..050f85709f58e18450b72201b4a21167c5ba8ab1 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -689,6 +689,26 @@ public: */ ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) override; + /** + * @brief Obtains the number of slotFlags. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slot Indicates the specified slot object + * @param slotFlags Indicates the slogFlags of slot. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t &slotFlags) override; + + /** + * @brief Set the slotFlags of slot. + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param slot Indicates the specified slot object + * @param slotFlags Indicates the slogFlags of slot to set. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode SetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t slotFlags) override; + #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED /** * @brief Obtains the event of turn on screen. diff --git a/services/ans/include/notification_config_parse.h b/services/ans/include/notification_config_parse.h new file mode 100644 index 0000000000000000000000000000000000000000..bd428a85f79d642069632df8650842a1d412aaf9 --- /dev/null +++ b/services/ans/include/notification_config_parse.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef NOTIFICATION_CONFIG_FILE_H +#define NOTIFICATION_CONFIG_FILE_H + +#include +#include + +namespace OHOS +{ + namespace Notification + { + static enum ReminderModeFlag : unsigned int { + kRMFRing = 0x01, // Ring + kRMFLockScreen = 0x02, // LockScreen + kRMFHangUp = 0x04, // HangUp + kRMFLight = 0x08, // Light + kRMFVibration = 0x10, // Vibration + } ReminderModeFlag; + + class NotificationConfigFile + { + public: + NotificationConfigFile(); + NotificationConfigFile(const std::string &filePath); + ~NotificationConfigFile(); + + private: + static int binaryToDecimal(const char *binaryString); + + public: + static void getDefaultSlotFlagsMap(std::map &slotFlagsMap); + static bool getNotificationSlotFlagConfig(std::string & filePath, std::map &slotFlagsMap); + static bool parseNotificationConfigCcmFile(std::string & filePath, std::map & slotFlagsMap); + }; + } // namespace Notification +} // namespace OHOS + +#endif diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 2f2d9a2d3ff867f2b9442436ed84322954be7936..b8b3a7d3c90ca6848aa3d32a483af18dd0a1913d 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -173,6 +173,24 @@ public: */ ErrCode SetTotalBadgeNums(const sptr &bundleOption, const int32_t num); + /** + * @brief Get slotFlags in the of bunlde from DB. + * + * @param bundleOption Indicates bunlde info label. + * @param slotFlags Indicates to set soltFlags. + * @return Return ERR_OK on success, others on failure. + */ + ErrCode GetNotificationSlotFlagsForBundle(const sptr &bundleOption, uint32_t &slotFlags); + + /** + * @brief Get slotFlags in the of bunlde from DB. + * + * @param bundleOption Indicates bunlde info label. + * @param slotFlags Indicates to get slotFlags. + * @return Return ERR_OK on success, others on failure. + */ + ErrCode SetNotificationSlotFlagsForBundle(const sptr &bundleOption, uint32_t slotFlags); + /** * @brief Get private notification enable in the of bunlde from DB. * diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index afc0460436e63677a5a33c2c40dd7b21ad1ffb4a..85d9dea4bc88b22cfe1626b56d33f49214455a83 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -95,6 +95,7 @@ public: * @return Return true on success, false on failure. */ bool PutNotificationsEnabled(const int32_t &userId, const bool &enabled); + bool PutSlotFlags(NotificationPreferencesInfo::BundleInfo &bundleInfo, const int32_t &slotFlags); bool PutHasPoppedDialog(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const bool &hasPopped); /** @@ -202,6 +203,7 @@ private: void ParseEnableAllNotification(NotificationPreferencesInfo &info); void ParseBundleName(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleImportance(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; + void ParseBundleSlotFlags(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleShowBadge(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleBadgeNum(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const; void ParseBundleEnableNotification( @@ -222,6 +224,7 @@ private: void ParseSlotVibrationSytle(sptr &slot, const std::string &value) const; void ParseSlotEnableBypassDnd(sptr &slot, const std::string &value) const; void ParseSlotEnabled(sptr &slot, const std::string &value) const; + void ParseSlotFlags(sptr &slot, const std::string &value) const; std::string GenerateBundleLablel(const NotificationPreferencesInfo::BundleInfo &bundleInfo) const; void GetDoNotDisturbType(NotificationPreferencesInfo &info, int32_t userId); diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 6e1272d6e0e3723d1a82425d549ece48312cef73..afcc5daa67debeb4ff79874eaf849213c8bcbbcc 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -137,6 +137,41 @@ public: */ uint32_t GetAllSlotsSize(); + /** + * @brief Get slotflags from bundle. + * + * @return Return slotFlags of bundle. + */ + uint32_t GetSlotFlags(); + + /** + * @brief Set slotflags to bundle. + * + * @param slotFlags Indicates slotFlags of bundle. + */ + void SetSlotFlags(uint32_t slotFlags); + + /** + * get slot type name string from slottype enum type. + * @param type slot type enum value. + * @return slot type name string. + */ + const char *GetSlotFlagsKeyFromType(const NotificationConstant::SlotType &type) const; + + /** + * set for specified slottype slotfalgs. + * @param type Indicates slot type. + * @param slotFlags Indicates slotFlags of slot. + */ + void SetSlotFlagsForSlot(const NotificationConstant::SlotType &type, uint32_t slotFlags); + + /** + * get for specified slottype slotfalgs. + * @param type Indicates slot type. + * @return specified slottype's slotfalgs. + */ + uint32_t GetSlotFlagsForSlot(const NotificationConstant::SlotType &type) const; + /** * @brief Get all slot from group in bundle. * @@ -186,12 +221,15 @@ public: private: std::string bundleName_; int32_t uid_ = 0; + uint32_t slotFlags_ = 0; int32_t importance_ = BUNDLE_IMPORTANCE; bool isShowBadge_ = BUNDLE_SHOW_BADGE; int32_t badgeTotalNum_ = BUNDLE_BADGE_TOTAL_NUM; bool isEnabledNotification_ = BUNDLE_ENABLE_NOTIFICATION; bool hasPoppedDialog_ = BUNDLE_POPPED_DIALOG; std::map> slots_; + std::map slotFlagsMap_; + std::map slotFlagsDefaultMap_; }; /* @@ -273,7 +311,6 @@ public: void RemoveNotificationEnable(const int32_t userId); void RemoveDoNotDisturbDate(const int32_t userId); void SetBundleInfoFromDb(const BundleInfo &info, std::string bundleKey); - private: std::map isEnabledAllNotification_; std::map> doNotDisturbDate_; diff --git a/services/ans/include/preferences_constant.h b/services/ans/include/preferences_constant.h index 7e3de52ce071376783ae58c68aff6fa6fc66990f..fd6f3d13c866e66df4893ef774e2d791414a8571 100644 --- a/services/ans/include/preferences_constant.h +++ b/services/ans/include/preferences_constant.h @@ -60,6 +60,7 @@ enum class BundleType { BUNDLE_ENABLE_NOTIFICATION_TYPE, BUNDLE_ENABLE_NOTIFICATION_USER_OPTION, BUNDLE_POPPED_DIALOG_TYPE, + BUNDLE_SLOTFLGS_TYPE, }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 93309924af32a2f55ac63baff42540e6db4c5897..1c4663fce9a0d6ef03a2c6ab2886f231705e3e55 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -428,6 +428,7 @@ sptr AdvancedNotificationService::GenerateValidBundleO ANS_LOGE("Failed to get active user id!"); return validBundleOption; } + ANS_LOGD("Ans Called GenerateValidBundleOption Enter:"); int32_t uid = bundleManager->GetDefaultUidByBundleName(bundleOption->GetBundleName(), activeUserId); if (uid > 0) { validBundleOption = new (std::nothrow) NotificationBundleOption(bundleOption->GetBundleName(), uid); @@ -436,6 +437,7 @@ sptr AdvancedNotificationService::GenerateValidBundleO return nullptr; } } + ANS_LOGD("Ans Called GenerateValidBundleOption: validBundleOption buildname =%{public}s, uid = %{public}d", validBundleOption->GetBundleName().c_str(), validBundleOption->GetUid()); } } else { validBundleOption = bundleOption; @@ -503,7 +505,7 @@ ErrCode AdvancedNotificationService::PrepareNotificationInfo( return ERR_ANS_INVALID_PARAM; } bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); - if ((request->GetSlotType() == NotificationConstant::SlotType::CUSTOM) && + if ((request->GetSlotType() == NotificationConstant::SlotType::CUSTOMER_SERVICE) && !AccessTokenHelper::IsSystemApp() && !isSubsystem) { return ERR_ANS_NON_SYSTEM_APP; } @@ -4859,6 +4861,84 @@ void AdvancedNotificationService::ResetPushCallbackProxy() pushCallBack_ = nullptr; } +ErrCode AdvancedNotificationService::GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t &slotFlags) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + + bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { + return ERR_ANS_NON_SYSTEM_APP; + } + + if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { + return ERR_ANS_PERMISSION_DENIED; + } + + sptr bundle = GenerateValidBundleOption(bundleOption); + if (bundle == nullptr) { + ANS_LOGD("Bundle is null."); + return ERR_ANS_INVALID_BUNDLE; + } + + if (notificationSvrQueue_ == nullptr) { + ANS_LOGE("Serial queue is invalid."); + return ERR_ANS_INVALID_PARAM; + } + ErrCode result = ERR_OK; + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGD("ffrt enter!"); + result = NotificationPreferences::GetInstance().GetNotificationSlotFlagsForBundle(bundle, slotFlags); + if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) { + result = ERR_OK; + slotFlags = 0; + } + })); + notificationSvrQueue_->wait(handler); + + return result; +} + +ErrCode AdvancedNotificationService::SetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + if (bundleOption == nullptr) { + ANS_LOGD("BundleOption is null."); + return ERR_ANS_INVALID_BUNDLE; + } + + bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) + { + ANS_LOGD("IsSystemApp is false."); + return ERR_ANS_NON_SYSTEM_APP; + } + + if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) + { + return ERR_ANS_PERMISSION_DENIED; + } + + sptr bundle = GenerateValidBundleOption(bundleOption); + if (bundle == nullptr) + { + ANS_LOGD("Bundle is null."); + return ERR_ANS_INVALID_BUNDLE; + } + + if (notificationSvrQueue_ == nullptr) { + ANS_LOGE("Serial queue is invalidity."); + return ERR_ANS_INVALID_PARAM; + } + ErrCode result = ERR_OK; + ffrt::task_handle handler = notificationSvrQueue_->submit_h( + std::bind([&]() { + ANS_LOGD("SetSlotFlagsAsBundle ffrt enter!"); + result = NotificationPreferences::GetInstance().SetNotificationSlotFlagsForBundle(bundle, slotFlags); + })); + notificationSvrQueue_->wait(handler); + return result; +} + ErrCode AdvancedNotificationService::RegisterPushCallback(const sptr &pushCallback) { if (!AccessTokenHelper::IsSystemApp()) { diff --git a/services/ans/src/notification_config_parse.cpp b/services/ans/src/notification_config_parse.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f7a3aae9f71c54b3ffb6cc4c5ae2b4d1fb9d7c7f --- /dev/null +++ b/services/ans/src/notification_config_parse.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "ans_log_wrapper.h" +#include "notification_constant.h" +#include "notification_config_parse.h" + +namespace OHOS +{ + namespace Notification + { + NotificationConfigFile::NotificationConfigFile() + { + } + + NotificationConfigFile::NotificationConfigFile(const std::string &filePath) + { + } + + NotificationConfigFile::~NotificationConfigFile() + { + } + + int NotificationConfigFile::binaryToDecimal(const char *binaryString) + { + int lenth = strlen(binaryString); + int decimal = 0; + int weight = 1; + + for (int i = lenth - 1; i >= 0; i--) + { + if (binaryString[i] == '1') + { + decimal += weight; + } + weight *= 2; + } + return decimal; + } + + void NotificationConfigFile::getDefaultSlotFlagsMap(std::map &slotFlagsMap) + { + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[0], 0b11011)); + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[1], 0b11111)); + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[2], 0b00000)); + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[3], 0b10111)); + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[4], 0b00000)); + slotFlagsMap.insert(std::make_pair(NotificationConstant::SLOTTYPECCMNAMES[5], 0b00000)); + for (auto &iter : slotFlagsMap) + { + ANS_LOGD("Default Got slotFlagsMap item slotType = %{public}s, slotFlags = %{public}d\n", iter.first.c_str(), iter.second); + } + } + + bool NotificationConfigFile::parseNotificationConfigCcmFile(std::string &filePath, std::map &slotFlagsMap) + { + xmlDocPtr docPtr = xmlReadFile(filePath.c_str(), nullptr, XML_PARSE_NOBLANKS); + if (docPtr == nullptr) + { + ANS_LOGE("xmlReadFile return nullptr!"); + return false; + } + + xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr); + if (rootPtr == nullptr || rootPtr->name == nullptr || + xmlStrcmp(rootPtr->name, reinterpret_cast("slotTypeConfig")) != 0) + { + ANS_LOGE("got RootElement return nullptr!"); + xmlFreeDoc(docPtr); + return false; + } + for (xmlNodePtr curNodePtr = rootPtr->children; curNodePtr != nullptr; curNodePtr = curNodePtr->next) + { + std::string subName = reinterpret_cast(curNodePtr->name); + if (strcasecmp(subName.c_str(), "slotType") == 0) + { + xmlNodePtr subNodePtr = curNodePtr->children; + std::string subNodeName = reinterpret_cast(subNodePtr->children->content); + std::string reminderFlagsName = reinterpret_cast(subNodePtr->next->name); + for (int i = 0; i < 6; i++) + { + if (strcasecmp(subNodeName.c_str(), NotificationConstant::SLOTTYPECCMNAMES[i]) == 0 && strcasecmp(reminderFlagsName.c_str(), "reminderFlags") == 0) + { + uint32_t flagsDecimal = binaryToDecimal(reinterpret_cast(subNodePtr->next->children->content)); + ANS_LOGD("Ccm Got insertMap item slotType =%{public}s, slotFlags = %{public}d\n", subNodeName.c_str(), flagsDecimal); + slotFlagsMap.insert(std::make_pair(subNodeName, flagsDecimal)); + } + } + } + } + return (slotFlagsMap.size() > 0) ? true : false; + } + + bool NotificationConfigFile::getNotificationSlotFlagConfig(std::string &filePath, std::map &slotFlagsMap) + { + struct stat buffer; + if (stat(filePath.c_str(), &buffer) != 0) // config file not exist + { + getDefaultSlotFlagsMap(slotFlagsMap); + return true; + } + else + { + return parseNotificationConfigCcmFile(filePath, slotFlagsMap); + } + } + } // namespace Notification +} // namespace OHOS diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index e9b3fad21bea9acb6ed0331b96be8d04e11a5c32..4d317a0bf999657eba269a0341c79e7850804873 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -21,7 +21,7 @@ #include "ans_inner_errors.h" #include "ans_log_wrapper.h" #include "bundle_manager_helper.h" -#include "hitrace_meter_adapter.h" +`#include "hitrace_meter_adapter.h" #include "nlohmann/json.hpp" #include "os_account_manager.h" @@ -62,11 +62,13 @@ ErrCode NotificationPreferences::AddNotificationSlots( ANS_LOGE("ffrt: add slot to db!"); if (result == ERR_OK && (!preferncesDB_->PutSlotsToDisturbeDB(bundleOption->GetBundleName(), bundleOption->GetUid(), slots))) { + ANS_LOGD("add slot to db judge."); return ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; } if (result == ERR_OK) { preferencesInfo_ = preferencesInfo; + ANS_LOGD("AddNotificationSlots return Ok!"); } return result; } @@ -76,7 +78,7 @@ ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptrGetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } - + ANS_LOGD("add slot to db judge."); std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; NotificationPreferencesInfo::BundleInfo bundleInfo; @@ -87,7 +89,7 @@ ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptr &bundleOption, uint32_t &slotFlags) +{ + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode err = GetBundleProperty(bundleOption, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); + ANS_LOGD("GetNotificationSlotFlagsForBundle getslotFlags=%{public}d.", slotFlags); + return err; +} + + +ErrCode NotificationPreferences::SetNotificationSlotFlagsForBundle( + const sptr &bundleOption, uint32_t slotFlags) +{ + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { + return ERR_ANS_INVALID_PARAM; + } + + ANS_LOGD("NotificationPreferences: SetNotificationSlotFlagsForBundle call SetBundleProperty"); + std::lock_guard lock(preferenceMutex_); + NotificationPreferencesInfo preferencesInfo = preferencesInfo_; + ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); + if (result == ERR_OK) { + preferencesInfo_ = preferencesInfo; + } + return result; +} + ErrCode NotificationPreferences::IsShowBadge(const sptr &bundleOption, bool &enable) { if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { @@ -286,6 +318,7 @@ ErrCode NotificationPreferences::GetImportance(const sptr &bundleOption, const int32_t &importance) { @@ -539,7 +572,7 @@ ErrCode NotificationPreferences::SetBundleProperty(NotificationPreferencesInfo & bundleInfo.SetBundleUid(bundleOption->GetUid()); bundleInfo.SetEnableNotification(CheckApiCompatibility(bundleOption)); } - + ANS_LOGD("NotificationPreferences: SetBundleProperty enter:"); result = SaveBundleProperty(bundleInfo, bundleOption, type, value); preferencesInfo.SetBundleInfo(bundleInfo); @@ -569,8 +602,16 @@ ErrCode NotificationPreferences::SaveBundleProperty(NotificationPreferencesInfo: storeDBResult = preferncesDB_->PutNotificationsEnabledForBundle(bundleInfo, value); break; case BundleType::BUNDLE_POPPED_DIALOG_TYPE: + ANS_LOGD("Into BUNDLE_POPPED_DIALOG_TYPE:SetHasPoppedDialog."); bundleInfo.SetHasPoppedDialog(value); storeDBResult = preferncesDB_->PutHasPoppedDialog(bundleInfo, value); + break; + case BundleType::BUNDLE_SLOTFLGS_TYPE: + ANS_LOGD("Into BUNDLE_SLOTFLGS_TYPE:SetSlotFlags."); + bundleInfo.SetSlotFlags(value); + ANS_LOGD("NotificationPreferences: call PutSlotFlags():"); + storeDBResult = preferncesDB_->PutSlotFlags(bundleInfo, value); + break; default: break; @@ -600,8 +641,13 @@ ErrCode NotificationPreferences::GetBundleProperty( value = bundleInfo.GetEnableNotification(); break; case BundleType::BUNDLE_POPPED_DIALOG_TYPE: + ANS_LOGD("Into BUNDLE_POPPED_DIALOG_TYPE:GetHasPoppedDialog."); value = bundleInfo.GetHasPoppedDialog(); break; + case BundleType::BUNDLE_SLOTFLGS_TYPE: + value = bundleInfo.GetSlotFlags(); + ANS_LOGD("Into BUNDLE_SLOTFLGS_TYPE:GetSlotFlags."); + break; default: result = ERR_ANS_INVALID_PARAM; break; diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index fc77905c6fd060ad80cf319a6063a9aa0c9286c3..ebb4680927feacb8de2ba2da4f832c04b800f6ea 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -168,6 +168,15 @@ const static std::string KEY_SLOT_ENABLE_BYPASS_DND = "enableBypassDnd"; */ const static std::string KEY_SLOT_ENABLED = "enabled"; +/** + * Indicates whether the type of bungle is flags. + */ +const static std::string KEY_BUNDLE_SLOTFLGS_TYPE = "bundleReminderflagstype"; + +/** + * Indicates whether the type of slot is flags. + */ +const static std::string KEY_SLOT_SLOTFLGS_TYPE = "reminderflagstype"; const std::map &, std::string &)>> @@ -227,6 +236,11 @@ const std::mapInsertData(typeKey, enableValue); if (result != NativeRdb::E_OK) { ANS_LOGE("Store enable notification failed. %{public}d", result); @@ -446,6 +466,21 @@ bool NotificationPreferencesDatabase::PutNotificationsEnabled(const int32_t &use return true; } +bool NotificationPreferencesDatabase::PutSlotFlags(NotificationPreferencesInfo::BundleInfo &bundleInfo, const int32_t &slotFlags) +{ + ANS_LOGD("PutSlotFlags-1."); + if (!CheckRdbStore()) { + ANS_LOGE("RdbStore is nullptr."); + return false; + } + + ANS_LOGD("PutSlotFlags-2."); + std::string bundleKey = GenerateBundleLablel(bundleInfo); + ANS_LOGD("NotificationPreferencesDatabase::PutSlotFlags entered, bundleKey=%{public}s, slotFlags=%{public}d", bundleKey.c_str(), slotFlags); + int32_t result = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); + return (result == NativeRdb::E_OK); +} + bool NotificationPreferencesDatabase::PutHasPoppedDialog( const NotificationPreferencesInfo::BundleInfo &bundleInfo, const bool &hasPopped) { @@ -745,8 +780,13 @@ int32_t NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_ENABLE_NOTIFICATION); break; case BundleType::BUNDLE_POPPED_DIALOG_TYPE: + ANS_LOGD("Into BUNDLE_POPPED_DIALOG_TYPE:GenerateBundleKey."); keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_POPPED_DIALOG); break; + case BundleType::BUNDLE_SLOTFLGS_TYPE: + ANS_LOGD("Into BUNDLE_SLOTFLGS_TYPE:GenerateBundleKey."); + keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_TYPE); + break; default: break; } @@ -1142,6 +1182,19 @@ void NotificationPreferencesDatabase::ParseSlotShowBadge(sptr slot->EnableBadge(showBadge); } +void NotificationPreferencesDatabase::ParseSlotFlags(sptr &slot, const std::string &value) const +{ + ANS_LOGD("ParseSlotFlags slot show flags is %{public}s.", value.c_str()); + uint32_t slotFlags = static_cast(StringToInt(value)); + slot->SetSlotFlags(slotFlags); +} + +void NotificationPreferencesDatabase::ParseBundleSlotFlags(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const +{ + ANS_LOGD("ParseBundleSlotFlags slot show flags is %{public}s.", value.c_str()); + bundleInfo.SetSlotFlags(StringToInt(value)); +} + void NotificationPreferencesDatabase::ParseSlotEnableLight(sptr &slot, const std::string &value) const { ANS_LOGD("ParseSlotEnableLight slot enable light is %{public}s.", value.c_str()); diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index bc28ad929e9840154f31a9df07b308e26f8fc8ec..777d1688a71b0157b0f7eeb176e62871759f4d08 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -13,13 +13,20 @@ * limitations under the License. */ #include "notification_preferences_info.h" +#include "notification_constant.h" +#include "notification_config_parse.h" namespace OHOS { namespace Notification { NotificationPreferencesInfo::BundleInfo::BundleInfo() -{} +{ + std::string configPath(NotificationConstant::NOTIFICATION_SLOTFLAG_CONFIG_PATH); + NotificationConfigFile::getNotificationSlotFlagConfig(configPath, slotFlagsDefaultMap_); +} NotificationPreferencesInfo::BundleInfo::~BundleInfo() -{} +{ + slotFlagsDefaultMap_.clear(); +} void NotificationPreferencesInfo::BundleInfo::SetBundleName(const std::string &name) { @@ -98,6 +105,64 @@ bool NotificationPreferencesInfo::BundleInfo::GetSlot( return false; } +const char* NotificationPreferencesInfo::BundleInfo::GetSlotFlagsKeyFromType(const NotificationConstant::SlotType &type) const +{ + switch (type) + { + case NotificationConstant::SlotType::SOCIAL_COMMUNICATION: + return NotificationConstant::SLOTTYPECCMNAMES[0]; + break; + case NotificationConstant::SlotType::SERVICE_REMINDER: + return NotificationConstant::SLOTTYPECCMNAMES[1]; + break; + case NotificationConstant::SlotType::CONTENT_INFORMATION: + return NotificationConstant::SLOTTYPECCMNAMES[2]; + break; + case NotificationConstant::SlotType::LIVE_VIEW: + return NotificationConstant::SLOTTYPECCMNAMES[3]; + break; + case NotificationConstant::SlotType::CUSTOMER_SERVICE: + return NotificationConstant::SLOTTYPECCMNAMES[4]; + break; + case NotificationConstant::SlotType::OTHER_TYPES: + return NotificationConstant::SLOTTYPECCMNAMES[5]; + break; + default: + return nullptr; + } +} + +void NotificationPreferencesInfo::BundleInfo::SetSlotFlagsForSlot(const NotificationConstant::SlotType &type, uint32_t slotFlags) +{ + ANS_LOGD("into BundleInfo::SetSlotFlags for specified slot."); + uint32_t bundleSlotFlags = GetSlotFlags(); + std::string key = GetSlotFlagsKeyFromType(type); + uint32_t finalSlotFlags = bundleSlotFlags&slotFlagsDefaultMap_[key]; + if (slotFlagsMap_.find(key) == slotFlagsMap_.end()){ + slotFlagsMap_.insert_or_assign(key, finalSlotFlags); + }else{ + for (auto it = slotFlagsMap_.begin(); it != slotFlagsMap_.end(); ++it){ + if (it->first.compare(key) == 0 && it->second != finalSlotFlags){ + it->second = finalSlotFlags; + } + } + } + ANS_LOGD("out BundleInfo::SetSlotFlags for specified slot."); +} + +uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlagsForSlot(const NotificationConstant::SlotType &type) const +{ + ANS_LOGD("into BundleInfo::GetSlotFlags."); + std::string key = GetSlotFlagsKeyFromType(type); + auto it = slotFlagsMap_.find(key); + if(it != slotFlagsMap_.end()){ + return it->second; + }else{ + return 0; + } + ANS_LOGD("out BundleInfo::GetSlotFlags."); +} + bool NotificationPreferencesInfo::BundleInfo::GetAllSlots(std::vector> &slots) { slots.clear(); @@ -130,6 +195,16 @@ bool NotificationPreferencesInfo::BundleInfo::RemoveSlot(const NotificationConst return false; } +uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() +{ + return slotFlags_; +} + +void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(uint32_t slotFlags) +{ + slotFlags_ = slotFlags; +} + void NotificationPreferencesInfo::BundleInfo::RemoveAllSlots() { slots_.clear(); diff --git a/services/ans/src/notification_rdb_data_mgr.cpp b/services/ans/src/notification_rdb_data_mgr.cpp index 145b3576051398bf9be542f2cffe8a7fec47eefc..8918add06e70e08947ba7ba470ff1eeed26bee42 100644 --- a/services/ans/src/notification_rdb_data_mgr.cpp +++ b/services/ans/src/notification_rdb_data_mgr.cpp @@ -155,6 +155,7 @@ int32_t NotificationDataMgr::InsertData(const std::string &key, const std::strin NativeRdb::ValuesBucket valuesBucket; valuesBucket.PutString(NOTIFICATION_KEY, key); valuesBucket.PutString(NOTIFICATION_VALUE, value); + ANS_LOGD("Call InsertWithConflictResolution key=%{public}s, value=%{public}s", key.c_str(), value.c_str()); int32_t ret = rdbStore_->InsertWithConflictResolution( rowId, notificationRdbConfig_.tableName, valuesBucket, NativeRdb::ConflictResolution::ON_CONFLICT_REPLACE); diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 9619465dece5782bfa765cadb59bc48d6c4c1a67..7be1740e80efd43ec21b255b21b3f524988a655f 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -139,11 +139,11 @@ void AdvancedNotificationServiceTest::TestAddSlot(NotificationConstant::SlotType */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00100, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); std::string label = "publish's label"; std::shared_ptr normalContent = std::make_shared(); @@ -164,11 +164,11 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00100, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00200, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); std::string label = "publish's label"; std::shared_ptr normalContent = std::make_shared(); @@ -393,11 +393,11 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01000, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01100, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); std::string label = "publish's label"; std::shared_ptr normalContent = std::make_shared(); @@ -492,7 +492,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01600, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01800, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); EXPECT_EQ((int)advancedNotificationService_->SetNotificationBadgeNum(2), (int)ERR_OK); } @@ -503,7 +503,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01800, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01900, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); int importance; EXPECT_EQ((int)advancedNotificationService_->GetBundleImportance(importance), (int)ERR_OK); } @@ -531,7 +531,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02200, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02300, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; sptr slot0 = new NotificationSlot(NotificationConstant::OTHER); slots.push_back(slot0); @@ -621,7 +621,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03900, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04000, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; EXPECT_EQ(advancedNotificationService_->GetSlotsByBundle( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), slots), @@ -677,7 +677,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04600, { sptr req = new NotificationRequest(1); req->SetSlotType(NotificationConstant::OTHER); - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle( std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), false), (int)ERR_OK); @@ -692,7 +692,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04600, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04700, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); std::string label = "testLabel"; { @@ -729,7 +729,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04800, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04900, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); sptr req = new NotificationRequest(1); req->SetSlotType(NotificationConstant::OTHER); EXPECT_EQ(advancedNotificationService_->CancelAll(), (int)ERR_OK); @@ -742,7 +742,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04900, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05000, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); int32_t notificationId = 2; std::string label = "testLabel"; @@ -776,7 +776,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05100, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05200, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); EXPECT_EQ(advancedNotificationService_->RemoveSlotByType(NotificationConstant::OTHER), ERR_OK); } @@ -787,7 +787,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05200, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05300, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); EXPECT_EQ((int)advancedNotificationService_->RemoveSlotByType(NotificationConstant::CUSTOM), 0); } @@ -816,7 +816,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05600, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05900, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); EXPECT_EQ((int)advancedNotificationService_->SetNotificationBadgeNum(2), (int)ERR_OK); } @@ -827,7 +827,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05900, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06000, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); int importance = 0; EXPECT_EQ((int)advancedNotificationService_->GetBundleImportance(importance), (int)ERR_OK); } @@ -856,7 +856,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06300, HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06400, Function | SmallTest | Level1) { std::vector> slots; - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); sptr slot0 = new NotificationSlot(NotificationConstant::OTHER); slots.push_back(slot0); EXPECT_EQ((int)advancedNotificationService_->UpdateSlots( @@ -959,7 +959,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08300, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08600, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); EXPECT_EQ((int)advancedNotificationService_->SetShowBadgeEnabledForBundle( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), true), (int)ERR_OK); @@ -977,10 +977,10 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08600, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08700, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); sptr slot; EXPECT_EQ((int)advancedNotificationService_->GetSlotByType(NotificationConstant::OTHER, slot), (int)ERR_OK); - EXPECT_EQ(slot->GetType(), NotificationConstant::SlotType::OTHER); + EXPECT_EQ(slot->GetType(), NotificationConstant::SlotType::OTHER_TYPES); } /** @@ -1012,7 +1012,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09200, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09300, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> notifications; EXPECT_EQ((int)advancedNotificationService_->SetNotificationsEnabledForSpecialBundle( std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID), true), @@ -1056,7 +1056,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09700, { EXPECT_EQ( (int)advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true), (int)ERR_OK); - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); bool allowed = true; EXPECT_EQ((int)advancedNotificationService_->IsSpecialBundleAllowedNotify( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), allowed), @@ -1128,7 +1128,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10000, IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("label"); std::shared_ptr pictureContent = std::make_shared(); EXPECT_NE(pictureContent, nullptr); @@ -1161,7 +1161,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10100, IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("label"); std::shared_ptr pictureContent = std::make_shared(); EXPECT_NE(pictureContent, nullptr); @@ -1194,7 +1194,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10200, IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("label"); std::shared_ptr pictureContent = std::make_shared(); EXPECT_NE(pictureContent, nullptr); @@ -1223,7 +1223,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10300, IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(1); ASSERT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("label"); std::shared_ptr normalContent = std::make_shared(); ASSERT_NE(normalContent, nullptr); @@ -1249,7 +1249,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10400, IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(1); ASSERT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("label"); std::shared_ptr normalContent = std::make_shared(); ASSERT_NE(normalContent, nullptr); @@ -1422,7 +1422,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11000, IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); EXPECT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_OK); SleepForFC(); @@ -1438,7 +1438,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11100, IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); EXPECT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_ANS_NOT_SYSTEM_SERVICE); SleepForFC(); @@ -1559,7 +1559,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12100, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12200, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); int32_t notificationId = 1; std::string label = "testRemove"; sptr req = new NotificationRequest(notificationId); @@ -1615,7 +1615,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12400, IPCSkeleton::SetCallingTokenID(DLP_NATIVE_TOKEN); sptr req = new (std::nothrow) NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); std::string label = "publish's label"; std::shared_ptr normalContent = std::make_shared(); @@ -1643,7 +1643,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12500, IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new (std::nothrow) NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); std::string label = "publish's label"; std::shared_ptr normalContent = std::make_shared(); @@ -1678,7 +1678,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12500, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12600, Function | SmallTest | Level1) { - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); int32_t notificationId = 1; std::string representativeBundle = "RepresentativeBundle"; int32_t userId = 1; @@ -2019,7 +2019,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15500, IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new (std::nothrow) NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); std::string label = "publish's label"; std::shared_ptr normalContent = std::make_shared(); @@ -2057,7 +2057,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15600, IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new (std::nothrow) NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); std::string label = "publish's label"; std::shared_ptr normalContent = std::make_shared(); @@ -2098,7 +2098,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15700, sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); std::string label = "publish's label"; std::shared_ptr normalContent = std::make_shared(); @@ -2160,7 +2160,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16100, sptr req = new (std::nothrow) NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); std::string label = "publish's label"; std::shared_ptr normalContent = std::make_shared(); @@ -2189,7 +2189,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16200, { GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0200 test start"; - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); int32_t notificationId = 1; std::string representativeBundle = "RepresentativeBundle"; @@ -2210,7 +2210,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16300, { GTEST_LOG_(INFO) << "ANS_CancelAsBundle_0300 test start"; - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); int32_t notificationId = 1; std::string representativeBundle = "RepresentativeBundle"; int32_t userId = 0; @@ -2232,7 +2232,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16400, IPCSkeleton::SetCallingUid(NON_SYSTEM_APP_UID); std::vector> slots; - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(slot); EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_OK); @@ -2251,7 +2251,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16600, IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); std::vector> slots; - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(slot); EXPECT_EQ(advancedNotificationService_->AddSlots(slots), ERR_ANS_INVALID_BUNDLE); @@ -2286,7 +2286,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16800, IPCSkeleton::SetCallingUid(NON_BUNDLE_NAME_UID); std::vector> slots; - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(slot); EXPECT_EQ(advancedNotificationService_->GetSlots(slots), ERR_ANS_INVALID_BUNDLE); @@ -2336,7 +2336,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16900, EXPECT_EQ(advancedNotificationService_->RemoveAllSlots(), ERR_ANS_INVALID_BUNDLE); - EXPECT_EQ(advancedNotificationService_->AddSlotByType(NotificationConstant::SlotType::OTHER), + EXPECT_EQ(advancedNotificationService_->AddSlotByType(NotificationConstant::SlotType::OTHER_TYPES), ERR_ANS_INVALID_BUNDLE); std::string groupName = "name"; @@ -2443,10 +2443,10 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17100, EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_OK); EXPECT_EQ(advancedNotificationService_->SetEnabledForBundleSlot(bundleOption, - NotificationConstant::SlotType::OTHER, enable), ERR_OK); + NotificationConstant::SlotType::OTHER_TYPES, enable), ERR_OK); EXPECT_EQ(advancedNotificationService_->GetEnabledForBundleSlot(bundleOption, - NotificationConstant::SlotType::OTHER, enable), ERR_OK); + NotificationConstant::SlotType::OTHER_TYPES, enable), ERR_OK); EXPECT_EQ(advancedNotificationService_->SetSyncNotificationEnabledWithoutApp(userId, enable), ERR_OK); @@ -2465,11 +2465,11 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17200, { GTEST_LOG_(INFO) << "ANS_GetActiveNotifications_0100 test start"; - TestAddSlot(NotificationConstant::SlotType::OTHER); + TestAddSlot(NotificationConstant::SlotType::OTHER_TYPES); IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); std::string label = "publish's label"; std::shared_ptr normalContent = std::make_shared(); diff --git a/services/ans/test/unittest/notification_preferences_test.cpp b/services/ans/test/unittest/notification_preferences_test.cpp index 06d1d93f76bdc81e6861e82ab6306826d75fc279..ed0bfdfe75dc4f25ddd5a106fd32fc3ffb3531ab 100644 --- a/services/ans/test/unittest/notification_preferences_test.cpp +++ b/services/ans/test/unittest/notification_preferences_test.cpp @@ -67,7 +67,7 @@ void NotificationPreferencesTest::TearDown() void NotificationPreferencesTest::TestAddNotificationSlot() { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; slots.push_back(slot); NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots); @@ -75,7 +75,7 @@ void NotificationPreferencesTest::TestAddNotificationSlot() void NotificationPreferencesTest::TestAddNotificationSlot(NotificationPreferencesInfo &info) { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, slot, info); } @@ -86,7 +86,7 @@ void NotificationPreferencesTest::TestAddNotificationSlot(NotificationPreference */ HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00100, Function | SmallTest | Level1) { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; slots.push_back(slot); EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots), (int)ERR_OK); @@ -99,7 +99,7 @@ HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00100, Function | Sma */ HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00200, Function | SmallTest | Level1) { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; slots.push_back(slot); EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleEmptyOption_, slots), @@ -157,7 +157,7 @@ HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00500, Function | Sma */ HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00600, Function | SmallTest | Level1) { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; slots.push_back(slot); EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(nullptr, slots), @@ -175,7 +175,7 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00100, Function | S { TestAddNotificationSlot(); EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot( - bundleOption_, NotificationConstant::SlotType::OTHER), + bundleOption_, NotificationConstant::SlotType::OTHER_TYPES), (int)ERR_OK); } @@ -187,7 +187,7 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00100, Function | S HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00200, Function | SmallTest | Level1) { EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot( - bundleEmptyOption_, NotificationConstant::SlotType::OTHER), + bundleEmptyOption_, NotificationConstant::SlotType::OTHER_TYPES), (int)ERR_ANS_INVALID_PARAM); } @@ -201,7 +201,7 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00300, Function | S { TestAddNotificationSlot(); EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot( - noExsitbundleOption_, NotificationConstant::SlotType::OTHER), + noExsitbundleOption_, NotificationConstant::SlotType::OTHER_TYPES), (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } @@ -228,7 +228,7 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00500, Function | S { TestAddNotificationSlot(); EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot( - nullptr, NotificationConstant::SlotType::OTHER), + nullptr, NotificationConstant::SlotType::OTHER_TYPES), (int)ERR_ANS_INVALID_PARAM); } @@ -287,7 +287,7 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00400, Functio */ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00100, Function | SmallTest | Level1) { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; slots.push_back(slot); EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots), (int)ERR_OK); @@ -305,7 +305,7 @@ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00100, Function | */ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00200, Function | SmallTest | Level1) { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; slots.push_back(slot); EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(bundleEmptyOption_, slots), @@ -332,7 +332,7 @@ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00300, Function | */ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00400, Function | SmallTest | Level1) { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; slots.push_back(slot); EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(noExsitbundleOption_, slots), @@ -347,7 +347,7 @@ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00400, Function | */ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00500, Function | SmallTest | Level1) { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; slots.push_back(slot); EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(noExsitbundleOption_, slots), @@ -361,7 +361,7 @@ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00500, Function | */ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00600, Function | SmallTest | Level1) { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); std::vector> slots; slots.push_back(slot); EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(nullptr, slots), @@ -378,7 +378,7 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00100, Function | Smal TestAddNotificationSlot(); sptr slot; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot( - bundleOption_, NotificationConstant::SlotType::OTHER, slot), + bundleOption_, NotificationConstant::SlotType::OTHER_TYPES, slot), (int)ERR_OK); } @@ -392,7 +392,7 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00200, Function | Smal { sptr slot; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot( - bundleEmptyOption_, NotificationConstant::SlotType::OTHER, slot), + bundleEmptyOption_, NotificationConstant::SlotType::OTHER_TYPES, slot), (int)ERR_ANS_INVALID_PARAM); } @@ -422,7 +422,7 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00400, Function | Smal TestAddNotificationSlot(); sptr slot; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot( - noExsitbundleOption_, NotificationConstant::SlotType::OTHER, slot), + noExsitbundleOption_, NotificationConstant::SlotType::OTHER_TYPES, slot), (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } @@ -436,7 +436,7 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00500, Function | Smal { sptr slot; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot( - nullptr, NotificationConstant::SlotType::OTHER, slot), + nullptr, NotificationConstant::SlotType::OTHER_TYPES, slot), (int)ERR_ANS_INVALID_PARAM); } @@ -463,7 +463,7 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00100, Function | */ HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00200, Function | SmallTest | Level1) { - sptr slot1 = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot1 = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); sptr slot2 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION); std::vector> slots; slots.push_back(slot1); @@ -1139,7 +1139,7 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00300, Fu HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00100, Function | SmallTest | Level1) { NotificationPreferencesInfo info; - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, nullptr, info), (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST); } @@ -1153,7 +1153,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00100, Function | S HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00200, Function | SmallTest | Level1) { NotificationPreferencesInfo info; - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, slot, info), (int)ERR_OK); } @@ -1170,7 +1170,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00100, Function | S NotificationPreferencesInfo info; TestAddNotificationSlot(info); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( - bundleOption_, NotificationConstant::SlotType::OTHER, info), (int)ERR_OK); + bundleOption_, NotificationConstant::SlotType::OTHER_TYPES, info), (int)ERR_OK); } /** @@ -1183,7 +1183,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00200, Function | S { NotificationPreferencesInfo info; EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( - bundleOption_, NotificationConstant::SlotType::OTHER, info), + bundleOption_, NotificationConstant::SlotType::OTHER_TYPES, info), (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } @@ -1210,7 +1210,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00300, Function | S */ HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00100, Function | SmallTest | Level1) { - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); NotificationPreferencesInfo info; EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, nullptr, info), (int)ERR_ANS_INVALID_PARAM); @@ -1226,7 +1226,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00100, Function | S HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00200, Function | SmallTest | Level1) { NotificationPreferencesInfo info; - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } @@ -1257,7 +1257,7 @@ HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00400, Function | S { NotificationPreferencesInfo info; TestAddNotificationSlot(info); - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), (int)ERR_OK); } diff --git a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp index 9b18d001e5316d826b0d2f3e7b716b13b9a4fe46..1afb93f637c18ddb1278fa111fbbbbcdb6a7d6d7 100755 --- a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp @@ -1241,7 +1241,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_05 HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_05900, Function | SmallTest | Level1) { sptr bundleOption = nullptr; - NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER_TYPES; bool enabled = true; IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); @@ -1261,7 +1261,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_05 HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06000, Function | SmallTest | Level1) { sptr bundleOption = new NotificationBundleOption(); - NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER_TYPES; bool enabled = true; IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); @@ -1282,7 +1282,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06 HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06100, Function | SmallTest | Level1) { sptr bundleOption = nullptr; - NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER_TYPES; bool enabled = true; IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); @@ -1302,7 +1302,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06 HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06200, Function | SmallTest | Level1) { sptr bundleOption = new NotificationBundleOption(); - NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER_TYPES; bool enabled = true; IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); @@ -1323,7 +1323,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06 HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06300, Function | SmallTest | Level1) { sptr bundleOption = new NotificationBundleOption(); - NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER_TYPES; bool enabled = true; IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); @@ -1345,7 +1345,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06 HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06400, Function | SmallTest | Level1) { sptr bundleOption = new NotificationBundleOption(); - NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER; + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::OTHER_TYPES; bool enabled = true; IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); diff --git a/services/test/moduletest/ans_module_test.cpp b/services/test/moduletest/ans_module_test.cpp index 438ec98827ce4f7d3ac397a5c98be72231fbc536..abf4c0b6fd45170c5877a1f4666b1a988ba3ac46 100644 --- a/services/test/moduletest/ans_module_test.cpp +++ b/services/test/moduletest/ans_module_test.cpp @@ -338,7 +338,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_007, Function | SmallTest | Level1) // add slot std::vector> slots; - sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(slot0); g_advancedNotificationService->AddSlots(slots); @@ -1027,7 +1027,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0042, Function | SmallTest | Level1) // add slot std::vector> slots; - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slot->SetEnableVibration(true); slots.push_back(slot); g_advancedNotificationService->AddSlots(slots); @@ -1101,7 +1101,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0049, Function | SmallTest | Level1) 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 otherSlot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(socialSlot); slots.push_back(reminderSlot); slots.push_back(contentSlot); @@ -1174,7 +1174,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0054, Function | SmallTest | Level1) 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 otherSlot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(socialSlot); slots.push_back(reminderSlot); @@ -1536,7 +1536,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0100, Function | SmallTest | Level1) // add slot std::vector> slots; - sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(slot0); g_advancedNotificationService->AddSlots(slots); @@ -1669,7 +1669,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0105, Function | SmallTest | Level1) 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 otherSlot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); sptr customSlot = new NotificationSlot(NotificationConstant::SlotType::CUSTOM); slots.push_back(socialSlot); @@ -1736,7 +1736,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0107, Function | SmallTest | Level1) // add slot std::vector> slots; - sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(slot0); g_advancedNotificationService->AddSlots(slots); @@ -1784,7 +1784,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0108, Function | SmallTest | Level1) // add slot std::vector> slots; - sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(slot0); g_advancedNotificationService->AddSlots(slots); @@ -1941,7 +1941,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0113, Function | SmallTest | Level1) // add slot std::vector> slots; - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slot->SetSound(Uri(".")); slot->SetEnableLight(true); slot->SetEnableVibration(true); @@ -1962,8 +1962,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0113, Function | SmallTest | Level1) std::shared_ptr content = std::make_shared(contentImpl); req->SetContent(content); req1->SetContent(content); - req->SetSlotType(NotificationConstant::SlotType::OTHER); - req1->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); + req1->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); // publish request g_advancedNotificationService->Publish(label, req); @@ -2204,7 +2204,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0121, Function | SmallTest | Level1) 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 otherSlot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); sptr customSlot = new NotificationSlot(NotificationConstant::SlotType::CUSTOM); slots.push_back(socialSlot); @@ -2217,7 +2217,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0121, Function | SmallTest | Level1) EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION), 0); EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SERVICE_REMINDER), 0); EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::CONTENT_INFORMATION), 0); - EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::OTHER), 0); + EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::OTHER_TYPES), 0); EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::CUSTOM), 0); } @@ -2253,7 +2253,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0122, Function | SmallTest | Level1) req->SetLabel(label); req1->SetLabel(label); req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - req1->SetSlotType(NotificationConstant::SlotType::OTHER); + req1->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); // publish request @@ -2262,7 +2262,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0122, Function | SmallTest | Level1) // add slot std::vector> otherSlots; - slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); otherSlots.push_back(slot); EXPECT_EQ(0, g_advancedNotificationService->AddSlots(otherSlots)); @@ -2290,7 +2290,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0123, Function | SmallTest | Level1) 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::OTHER_TYPES)); slots.push_back(new NotificationSlot(NotificationConstant::SlotType::CUSTOM)); EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), 0); sptr req = new NotificationRequest(0); @@ -2307,7 +2307,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0123, Function | SmallTest | Level1) req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); req1->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER); req2->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); - req3->SetSlotType(NotificationConstant::SlotType::OTHER); + req3->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req4->SetSlotType(NotificationConstant::SlotType::CUSTOM); g_advancedNotificationService->Publish("testLabel", req); @@ -2514,7 +2514,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0128, Function | SmallTest | Level1) // add slot std::vector> slots; sptr slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION); - sptr slot1 = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot1 = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(slot); slots.push_back(slot1); g_advancedNotificationService->AddSlots(slots); @@ -2539,7 +2539,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0128, Function | SmallTest | Level1) req1->SetLabel(label); req1->SetContent(longTextContent); req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); - req1->SetSlotType(NotificationConstant::SlotType::OTHER); + req1->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); // publish EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); @@ -2566,7 +2566,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0130, Function | SmallTest | Level1) // add slot std::vector> slots; - sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER_TYPES); slots.push_back(slot); slot->SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC); slot->SetEnableVibration(true); @@ -2574,7 +2574,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0130, Function | SmallTest | Level1) // create request std::string label = "testLabel"; sptr req = new NotificationRequest(0); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel(label); // publish EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); diff --git a/test/bechmarktest/notification_services_test/notification_service_test.cpp b/test/bechmarktest/notification_services_test/notification_service_test.cpp index f3d25bf3ed69a7aea1b2e5c8452f9a53242802a3..62a016aef2c8ab8b4c613d38f66be518d5930c3c 100644 --- a/test/bechmarktest/notification_services_test/notification_service_test.cpp +++ b/test/bechmarktest/notification_services_test/notification_service_test.cpp @@ -189,7 +189,7 @@ BENCHMARK_F(BenchmarkNotificationService, PublishNotificationTestCase001)(benchm IPCSkeleton::SetCallingTokenID(0); sptr req = new (std::nothrow) NotificationRequest(1); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); req->SetCreatorUid(100); std::string label = "publish's label"; @@ -220,7 +220,7 @@ BENCHMARK_F(BenchmarkNotificationService, CancelNotificationTestCase001)(benchma IPCSkeleton::SetCallingTokenID(0); sptr req = new (std::nothrow) NotificationRequest(0); EXPECT_NE(req, nullptr); - req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetSlotType(NotificationConstant::SlotType::OTHER_TYPES); req->SetLabel("req's label"); req->SetCreatorUid(100); std::string label = "publish's label";