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..41be6e7e2433b8a5d610e52e55bc512d6131ec1f 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()->GetNotificationSlotFlagsAsBundle(bundleOption, slotFlags); +} + +ErrCode NotificationHelper::SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags) +{ + return DelayedSingleton::GetInstance()->SetNotificationSlotFlagsAsBundle(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..a3f61c50188a4968bc8caec82e6b256569503d3c 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"; @@ -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/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..e5374487448be6898b8336b8eb005ce01ced2834 100644 --- a/frameworks/js/napi/include/manager/napi_slot.h +++ b/frameworks/js/napi/include/manager/napi_slot.h @@ -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/src/constant.cpp b/frameworks/js/napi/src/constant.cpp index c5d6fcd7b05c2516fbfe9401d92a37ad8aa0745c..a2c5745ee62f8badcd7170344d2a96df9426bbaf 100644 --- a/frameworks/js/napi/src/constant.cpp +++ b/frameworks/js/napi/src/constant.cpp @@ -58,7 +58,7 @@ napi_value SlotTypeInit(napi_env env, napi_value exports) SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::CONTENT_INFORMATION, "CONTENT_INFORMATION"); SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::LIVE_VIEW, "LIVE_VIEW"); SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::CUSTOMER_SERVICE, "CUSTOMER_SERVICE"); - SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::OTHER_TYPES, "OTHER_TYPES"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::OTHER_TYPES, "OTHER"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("SlotType", obj), 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/slot.cpp b/frameworks/js/napi/src/slot.cpp index 1005a040c3a6ad76013f5636fbccf7f3aaa2ae35..8cd96795a521292fffe97713d1abd2d53edb6728 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -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/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 564e87bb3a7f55f11a9245fda9d2fc764a04f34b..0eaee4d5c25f7fa46dd30b959afc22bbf9a11643 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -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_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/reminder_request.h b/interfaces/inner_api/reminder_request.h index d2a58f544a374124eb04ac3ece53e147bcb6c496..b96f031e71a032ad6ce808e7b1a4423d4fd68529 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -378,6 +378,13 @@ public: */ NotificationConstant::SlotType GetSlotType() const; + /** + * @brief Obtains snoozeSlot type. + * + * @return snoozeSlot type. + */ + NotificationConstant::SlotType GetSnoozeSlotType() const; + std::string GetSnoozeContent() const; uint8_t GetSnoozeTimes() const; uint8_t GetSnoozeTimesDynamic() const; @@ -655,7 +662,7 @@ public: * @return Current reminder self. */ ReminderRequest& SetSlotType(const NotificationConstant::SlotType &slotType); - + ReminderRequest& SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType); ReminderRequest& SetSnoozeContent(const std::string &snoozeContent); /** @@ -873,6 +880,7 @@ public: static const std::string ACTION_BUTTON_INFO; static const std::string CUSTOM_BUTTON_URI; static const std::string SLOT_ID; + static const std::string SNOOZE_SLOT_ID; static const std::string NOTIFICATION_ID; static const std::string TITLE; static const std::string CONTENT; @@ -949,7 +957,7 @@ private: void UpdateActionButtons(const bool &setSnooze); bool UpdateNextReminder(const bool &force); void UpdateNotificationContent(const bool &setSnooze); - void UpdateNotificationCommon(); + void UpdateNotificationCommon(bool isSnooze); /** * @brief Determine whether it is repeated every week. @@ -1023,6 +1031,7 @@ private: uint64_t timeIntervalInMilli_ {0}; ReminderType reminderType_ {ReminderType::INVALID}; NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::SOCIAL_COMMUNICATION}; + NotificationConstant::SlotType snoozeSlotType_ {NotificationConstant::SlotType::OTHER}; sptr notificationRequest_ = nullptr; std::shared_ptr wantAgentInfo_ = nullptr; std::shared_ptr maxScreenWantAgentInfo_ = nullptr; diff --git a/interfaces/inner_api/reminder_store.h b/interfaces/inner_api/reminder_store.h index 58be32314d79848436df6ff8bdb37063ac6bb84b..f3bb4384f31404d566629cf90a7744add16b2df2 100644 --- a/interfaces/inner_api/reminder_store.h +++ b/interfaces/inner_api/reminder_store.h @@ -73,7 +73,6 @@ private: int64_t Insert(const sptr &reminder, const sptr &bundleOption); std::shared_ptr Query(const std::string &queryCondition) const; int64_t Update(const sptr &reminder, const sptr &bundleOption); - class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback { public: int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index a1a5c4fb5e24f1d2e6c499dd2745d92d367e7c01..55dd382b57396da41b9fd091e35f9bba8dd2ad29 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -49,6 +49,7 @@ ohos_shared_library("libans") { "src/advanced_notification_service_ability.cpp", "src/bundle_manager_helper.cpp", "src/event_report.cpp", + "src/notification_config_parse.cpp", "src/notification_dialog.cpp", "src/notification_dialog_manager.cpp", "src/notification_local_live_view_subscriber_manager.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..7f69bb24ca17f2ede2ccddf1e91400658e8ce1d9 --- /dev/null +++ b/services/ans/include/notification_config_parse.h @@ -0,0 +1,52 @@ +/* +* 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..f829e8b10cc74f8f63cca6811f4e4e06600ec97d 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -503,7 +503,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 +4859,83 @@ 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([&]() { + 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..75b5bf6e01de452d7fe8993fbd068c0072852f72 --- /dev/null +++ b/services/ans/src/notification_config_parse.cpp @@ -0,0 +1,114 @@ +/* +* 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) { + 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..2328ee7f6466c45d5185974b4305572e25689045 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -76,7 +76,6 @@ ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptrGetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } - std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; NotificationPreferencesInfo::BundleInfo bundleInfo; @@ -87,7 +86,7 @@ ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptr &bundleOption, uint32_t &slotFlags) +{ + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { + return ERR_ANS_INVALID_PARAM; + } + + return GetBundleProperty(bundleOption, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); +} + + +ErrCode NotificationPreferences::SetNotificationSlotFlagsForBundle( + const sptr &bundleOption, uint32_t slotFlags) +{ + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { + return ERR_ANS_INVALID_PARAM; + } + + 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 +312,7 @@ ErrCode NotificationPreferences::GetImportance(const sptr &bundleOption, const int32_t &importance) { @@ -539,7 +566,6 @@ ErrCode NotificationPreferences::SetBundleProperty(NotificationPreferencesInfo & bundleInfo.SetBundleUid(bundleOption->GetUid()); bundleInfo.SetEnableNotification(CheckApiCompatibility(bundleOption)); } - result = SaveBundleProperty(bundleInfo, bundleOption, type, value); preferencesInfo.SetBundleInfo(bundleInfo); @@ -569,9 +595,15 @@ 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); + storeDBResult = preferncesDB_->PutSlotFlags(bundleInfo, value); + break; default: break; } @@ -600,8 +632,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..85cf2369b4023d5cf831e5b0449d6fd548e8a973 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::map 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..f80e78a74baf48c7bc668956494193bd1133c260 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -13,13 +13,21 @@ * 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 +106,61 @@ 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: + return NotificationConstant::SLOTTYPECCMNAMES[5]; + break; + default: + return nullptr; + } +} + +void NotificationPreferencesInfo::BundleInfo::SetSlotFlagsForSlot(const NotificationConstant::SlotType &type, uint32_t slotFlags) +{ + 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; + } + } + } +} + +uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlagsForSlot(const NotificationConstant::SlotType &type) const +{ + std::string key = GetSlotFlagsKeyFromType(type); + auto it = slotFlagsMap_.find(key); + if(it != slotFlagsMap_.end()){ + return it->second; + }else{ + return 0; + } +} + bool NotificationPreferencesInfo::BundleInfo::GetAllSlots(std::vector> &slots) { slots.clear(); @@ -130,6 +193,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();