From 78335476f78afb96075aa740fadfe209f668f0a4 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Thu, 16 Nov 2023 17:36:52 +0800 Subject: [PATCH 01/56] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=96=B0API=E6=8E=A5=E5=8F=A3=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/include/ans_manager_interface.h | 21 +++ frameworks/core/include/ans_manager_proxy.h | 20 +++ frameworks/core/include/ans_manager_stub.h | 2 +- ..._notification_service_ipc_interface_code.h | 2 + frameworks/core/src/ans_manager_proxy.cpp | 12 ++ frameworks/core/src/ans_manager_stub.cpp | 69 ++++++++ .../js/napi/include/manager/napi_slot.h | 34 ++++ .../js/napi/src/manager/init_module.cpp | 2 + frameworks/js/napi/src/manager/napi_slot.cpp | 149 ++++++++++++++++++ frameworks/js/napi/src/slot.cpp | 17 ++ 10 files changed, 327 insertions(+), 1 deletion(-) diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index a58d2237f..0d62c771e 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -684,6 +684,27 @@ 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, const sptr&slot, uint64_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(sptr&slot, 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 5c91814e3..29810595e 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, sptr&slot, uint64_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(sptr&slot, 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 4da073244..43503d2f6 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -780,7 +780,7 @@ 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); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result) { 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 78f24ac5d..2489f4e16 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 50666b0c8..fa2fea219 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2695,6 +2695,18 @@ ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber) return result; } +ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(sptr&slot, uint32_t& slotFlags) +{ + + +} + +ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(sptr&slot, uint32_t slotFlags) +{ + + +} + 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 47254fb7c..56c366a20 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; + } + + + sptr slot = data.ReadStrongParcelable(); + if (slot == 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, slot, 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; + } + + sptr slot = data.ReadStrongParcelable(); + if (slot == nullptr) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t slotFlags = 0; + ErrCode result = GetSlotFlagsAsBundle(bundleOption, slot, slotFlags); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteUint64(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; diff --git a/frameworks/js/napi/include/manager/napi_slot.h b/frameworks/js/napi/include/manager/napi_slot.h index 0d63119ae..99c1a509a 100644 --- a/frameworks/js/napi/include/manager/napi_slot.h +++ b/frameworks/js/napi/include/manager/napi_slot.h @@ -154,6 +154,34 @@ struct AsyncCallbackInfoInfoIsEnableSlot { CallbackPromiseInfo info; }; +struct ParametersInfoSetSlotFlagsByBundle { + NotificationBundleOption option; + sptr slot; + uint32_t slotFlags; + napi_ref callback = nullptr; +}; + +struct ParametersInfoGetSlotFlagsByBundle { + NotificationBundleOption option; + sptr slot; + napi_ref callback = nullptr; +}; + +struct AsyncCallbackInfoSetSlotFlagsByBundle { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + ParametersInfoSetSlotByBundle 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 +193,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 +212,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, ParametersInfoGetSlotNumByBundle ¶ms); } // namespace NotificationNapi } // namespace OHOS diff --git a/frameworks/js/napi/src/manager/init_module.cpp b/frameworks/js/napi/src/manager/init_module.cpp index 3e82d3a48..4770767eb 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 dc889b843..2cb79bcb0 100644 --- a/frameworks/js/napi/src/manager/napi_slot.cpp +++ b/frameworks/js/napi/src/manager/napi_slot.cpp @@ -910,5 +910,154 @@ 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"); + ParametersInfoSetSlotByBundle params {}; + if (ParseParametersSetSlotByBundle(env, info, params) == nullptr) { + Common::NapiThrow(env, ERROR_PARAM_INVALID); + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoSetSlotByBundle *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoSetSlotByBundle {.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, "setSlotByBundle", NAPI_AUTO_LENGTH, &resourceName); + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("NapiSetSlotByBundle work excute."); + auto asynccallbackinfo = static_cast(data); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = NotificationHelper::UpdateNotificationSlots( + asynccallbackinfo->params.option, asynccallbackinfo->params.slots); + } + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("NapiSetSlotByBundle 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 napiSetSlotByBundle callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + ANS_LOGD("NapiSetSlotByBundle 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 napiSetSlotByBundle 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 napiSetSlotByBundle callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + + if (isCallback) { + ANS_LOGD("napiSetSlotByBundle callback is nullptr."); + return Common::NapiGetNull(env); + } else { + return promise; + } + + +} + +napi_value NapiGetSlotFlagsByBundle(napi_env env, napi_callback_info info) +{ + ANS_LOGI("enter"); + ParametersInfoGetSlotNumByBundle params {}; + if (ParseParametersGetSlotNumByBundle(env, info, params) == nullptr) { + Common::NapiThrow(env, ERROR_PARAM_INVALID); + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoGetSlotNumByBundle *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoGetSlotNumByBundle {.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, "getSlotNumByBundle", NAPI_AUTO_LENGTH, &resourceName); + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("NapiGetSlotNumByBundle work excute."); + auto asynccallbackinfo = reinterpret_cast(data); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = NotificationHelper::GetNotificationSlotNumAsBundle( + asynccallbackinfo->params.option, asynccallbackinfo->num); + } + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("NapiGetSlotNumByBundle work complete."); + auto asynccallbackinfo = static_cast(data); + if (asynccallbackinfo) { + napi_value result = nullptr; + napi_create_uint32(env, asynccallbackinfo->num, &result); + Common::CreateReturnValue(env, asynccallbackinfo->info, result); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete napiGetSlotNumByBundle callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + ANS_LOGD("NapiGetSlotNumByBundle 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 napiGetSlotNumByBundle 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 napiGetSlotNumByBundle callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + + if (isCallback) { + ANS_LOGD("napiGetSlotNumByBundle 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 1005a040c..fcec0a68b 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -397,6 +397,23 @@ napi_value ParseParametersGetSlotNumByBundle( return Common::NapiGetNull(env); } + +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, ParametersInfoGetSlotNumByBundle ¶ms) + { + + + + + } + napi_value ParseParametersGetSlotsByBundle( const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotsByBundle ¶ms) { -- Gitee From deda075d17812dddbb9ad502b52b968f40cb2035 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Fri, 17 Nov 2023 13:51:09 +0800 Subject: [PATCH 02/56] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/core/src/ans_manager_stub.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 56c366a20..e277aa1ba 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -514,7 +514,6 @@ ErrCode AnsManagerStub::HandleSetSlotFlagsAsBundle(MessageParcel &data, MessageP } return ERR_OK; - } ErrCode AnsManagerStub::HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply) @@ -544,7 +543,6 @@ ErrCode AnsManagerStub::HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageP } return ERR_OK; - } -- Gitee From f5f5f7c47f29651a1d9647bd77d81fa7f6761c13 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Fri, 17 Nov 2023 14:01:37 +0800 Subject: [PATCH 03/56] Add SetSlotFlags/GetSlotFlags to NotificationSlot class --- frameworks/ans/src/notification_slot.cpp | 10 ++++++++++ interfaces/inner_api/notification_slot.h | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index 3bef9e5d4..729f1b19b 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -84,6 +84,16 @@ void NotificationSlot::SetLevel(NotificationLevel level) level_ = level; } +uint32_t NotificationSlot::GetSlotFlags() const +{ + return slotFlags_; +} + +void NotificationSlot::SetSlotFlags(uint32_t slotFlags) +{ + slotFlags_ = slotFlags; +} + NotificationConstant::SlotType NotificationSlot::GetType() const { return type_; diff --git a/interfaces/inner_api/notification_slot.h b/interfaces/inner_api/notification_slot.h index 354938d85..838345f43 100644 --- a/interfaces/inner_api/notification_slot.h +++ b/interfaces/inner_api/notification_slot.h @@ -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 level of the NotificationSlot object. + */ + uint32_t GetSlotFlags() const; + + /** + * @brief Sets the level of a NotificationSlot object. + * @note SetLevel must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) method is called. + * Otherwise, the settings will not take effect. + * + * @param level Specifies the level 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). * @@ -345,6 +363,7 @@ private: bool isShowBadge_ {true}; bool isBypassDnd_ {false}; std::string description_ {}; + uint32_t slotFlags_{0}; int32_t lightColor_ {0}; NotificationLevel level_ {LEVEL_DEFAULT}; NotificationConstant::SlotType type_ {}; -- Gitee From a5ec83650399ee3ae779f91286222f5e367ca31c Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Fri, 17 Nov 2023 14:07:50 +0800 Subject: [PATCH 04/56] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/js/napi/include/slot.h | 2 ++ frameworks/js/napi/src/slot.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/frameworks/js/napi/include/slot.h b/frameworks/js/napi/include/slot.h index 72017d1cc..df15c58e7 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/slot.cpp b/frameworks/js/napi/src/slot.cpp index fcec0a68b..0baaf077d 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -1479,5 +1479,18 @@ napi_value IsEnableNotificationSlot(napi_env env, napi_callback_info info) return promise; } } + + +napi_value GetSlotFlagsByBundle(napi_env env, napi_callback_info info) +{ + +} + + +napi_value SetSlotFlagsByBundle(napi_env env, napi_callback_info info) +{ + +} + } // namespace NotificationNapi } // namespace OHOS \ No newline at end of file -- Gitee From 901622d113fef798e9a9357fd34aface9778bf39 Mon Sep 17 00:00:00 2001 From: zhushuaiyu Date: Fri, 17 Nov 2023 17:12:01 +0800 Subject: [PATCH 05/56] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20AnsManagerProxy::Set?= =?UTF-8?q?SlotFlagsAsBundle=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/core/src/ans_manager_proxy.cpp | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index fa2fea219..8e54955a5 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2703,8 +2703,53 @@ ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(sptr&slot, uint ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(sptr&slot, uint32_t slotFlags) { + if (bundleOption == nullptr) { + ANS_LOGE("[SetSlotFlagsAsBundle] fail: bundleOption is empty."); + return ERR_ANS_INVALID_PARAM; + } + + if (slot == nullptr) { + ANS_LOGE("[SetSlotFlagsAsBundle] fail: slots is empty."); + return ERR_ANS_INVALID_PARAM; + } + + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[UpdateSlots] 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; + } + if (!data.WriteParcelable(slot)) { + ANS_LOGE("[SetSlotFlagsAsBundle] fail: write slots failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + + if (!data.WriteInt32(slotFlags)) { + 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) -- Gitee From e5e06236a39538b2bc87ab56ecfd01b0679ae259 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 09:26:15 +0800 Subject: [PATCH 06/56] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ReminderModeFlag?= =?UTF-8?q?=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/js/napi/include/common.h | 8 ++++++++ frameworks/js/napi/src/manager/napi_slot.cpp | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 141a01747..f44ae40e4 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -64,6 +64,14 @@ enum class SlotLevel { LEVEL_HIGH = 4, }; +enum ReminderModeFlag: unsigned int{ + kRMFRing = 0x01, //振铃 + kRMFLockScreen = 0x02, //锁屏 + kRMFHangUp = 0x04,//横幅通知 + kRMFLight = 0x08,//亮屏 + kRMFVibration = 0x10,//振动 +}ReminderModeFlag; + enum class RemoveReason { CLICK_REASON_REMOVE = 1, CANCEL_REASON_REMOVE = 2, diff --git a/frameworks/js/napi/src/manager/napi_slot.cpp b/frameworks/js/napi/src/manager/napi_slot.cpp index 2cb79bcb0..a15467074 100644 --- a/frameworks/js/napi/src/manager/napi_slot.cpp +++ b/frameworks/js/napi/src/manager/napi_slot.cpp @@ -913,7 +913,7 @@ napi_value NapiIsEnableNotificationSlot(napi_env env, napi_callback_info info) napi_value NapiSetSlotFlagsByBundle(napi_env env, napi_callback_info info) { - ANS_LOGI("enter"); + /*ANS_LOGI("enter"); ParametersInfoSetSlotByBundle params {}; if (ParseParametersSetSlotByBundle(env, info, params) == nullptr) { Common::NapiThrow(env, ERROR_PARAM_INVALID); @@ -981,13 +981,13 @@ napi_value NapiSetSlotFlagsByBundle(napi_env env, napi_callback_info info) } else { return promise; } - - +*/ } napi_value NapiGetSlotFlagsByBundle(napi_env env, napi_callback_info info) { - ANS_LOGI("enter"); + /* + ANS_LOGI("enter"); ParametersInfoGetSlotNumByBundle params {}; if (ParseParametersGetSlotNumByBundle(env, info, params) == nullptr) { Common::NapiThrow(env, ERROR_PARAM_INVALID); @@ -1057,6 +1057,7 @@ napi_value NapiGetSlotFlagsByBundle(napi_env env, napi_callback_info info) } else { return promise; } + */ } } // namespace NotificationNapi -- Gitee From ed970019ba387f760ee7f83a9cebf5562665876e Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 09:41:51 +0800 Subject: [PATCH 07/56] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=B0=91=E5=8F=82=E6=95=B0=E9=94=99=E8=AF=AF=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/core/include/ans_manager_proxy.h | 2 +- frameworks/core/src/ans_manager_proxy.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 29810595e..3488307e2 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -689,7 +689,7 @@ public: * @param slotFlags Indicates the slogFlags of slot to set. * @return Returns ERR_OK on success, others on failure. */ - ErrCode SetSlotFlagsAsBundle(sptr&slot, uint32_t slotFlags) override; + ErrCode SetSlotFlagsAsBundle(const sptr &bundleOption, sptr&slot, uint32_t slotFlags) override; /** * @brief Register Push Callback. diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 8e54955a5..4577846a0 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2695,13 +2695,13 @@ ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber) return result; } -ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(sptr&slot, uint32_t& slotFlags) +ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr &bundleOption, sptr&slot, uint32_t& slotFlags) { } -ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(sptr&slot, uint32_t slotFlags) +ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(const sptr &bundleOption, sptr&slot, uint32_t slotFlags) { if (bundleOption == nullptr) { ANS_LOGE("[SetSlotFlagsAsBundle] fail: bundleOption is empty."); -- Gitee From dbc8ca868d89aa8acabb3e84d32651bd8b46d917 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 09:47:52 +0800 Subject: [PATCH 08/56] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/core/include/ans_manager_proxy.h | 2 +- frameworks/core/src/ans_manager_proxy.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 3488307e2..ec315b5e8 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -679,7 +679,7 @@ public: * @param slotFlags Indicates the slogFlags of slot to get. * @return Returns ERR_OK on success, others on failure. */ - ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, sptr&slot, uint64_t &slotFlags) override; + ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr&slot, uint64_t &slotFlags) override; /** * @brief Set the slotFlags of slot. diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 4577846a0..2322886d5 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2695,7 +2695,7 @@ ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber) return result; } -ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr &bundleOption, sptr&slot, uint32_t& slotFlags) +ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr&slot, uint32_t& slotFlags) { -- Gitee From 4d58c3355a30a3a4c8c53923a7d3e5a776f43db8 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 10:09:32 +0800 Subject: [PATCH 09/56] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/core/include/ans_manager_interface.h | 4 ++-- frameworks/core/include/ans_manager_stub.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 0d62c771e..1697789b8 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -692,7 +692,7 @@ public: * @param slotFlags Indicates the slogFlags of slot. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr&slot, uint64_t &slotFlags) = 0; + virtual ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, const sptr&slot, uint64_t &slotFlags) = 0; /** * @brief Set the slotFlags of slot. @@ -702,7 +702,7 @@ public: * @param slotFlags Indicates the slogFlags of slot to set. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode SetSlotFlagsAsBundle(sptr&slot, uint32_t slotFlags) = 0; + virtual ErrCode SetSlotFlagsAsBundle(const sptr& bundleOption, sptr&slot, uint32_t slotFlags) = 0; /** diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 43503d2f6..8ea8f98b8 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -781,6 +781,7 @@ private: 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) { -- Gitee From 846a601ebc28e3be74986bd6e0951ca0b7ab4b32 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 10:40:16 +0800 Subject: [PATCH 10/56] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/js/napi/include/common.h | 4 ++-- interfaces/inner_api/notification_constant.h | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index f44ae40e4..3b32f7d66 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -64,13 +64,13 @@ enum class SlotLevel { LEVEL_HIGH = 4, }; -enum ReminderModeFlag: unsigned int{ +enum ReminderModeFlag: unsigned int { kRMFRing = 0x01, //振铃 kRMFLockScreen = 0x02, //锁屏 kRMFHangUp = 0x04,//横幅通知 kRMFLight = 0x08,//亮屏 kRMFVibration = 0x10,//振动 -}ReminderModeFlag; +}; enum class RemoveReason { CLICK_REASON_REMOVE = 1, diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 564e87bb3..d0caec11e 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 + UNKOWN_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 =OXFFFF, }; enum class VisiblenessType { -- Gitee From 7ae54c5f00f87f4dbb7010554e728ee34c38c839 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 11:02:40 +0800 Subject: [PATCH 11/56] Fixed compiler errors --- frameworks/core/src/ans_manager_stub.cpp | 2 +- interfaces/inner_api/notification_constant.h | 2 +- interfaces/inner_api/notification_request.h | 2 +- interfaces/inner_api/notification_slot.h | 10 +++++----- interfaces/inner_api/notification_sorting.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index e277aa1ba..05b22aad7 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -530,7 +530,7 @@ ErrCode AnsManagerStub::HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageP return ERR_ANS_PARCELABLE_FAILED; } - int32_t slotFlags = 0; + uint32_t slotFlags = 0; ErrCode result = GetSlotFlagsAsBundle(bundleOption, slot, slotFlags); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write result failed, ErrCode=%{public}d", result); diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index d0caec11e..33ff17e49 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -63,7 +63,7 @@ public: 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 =OXFFFF, + OTHER_TYPES =0xFFFF, }; enum class VisiblenessType { diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index d080a7d91..29111da75 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 838345f43..2e07e7438 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(); @@ -150,16 +150,16 @@ public: /** * @brief Obtains the slotflags of a NotificationSlot object, which is set by SetSlotFlags(uint32_t slotFlags). * - * @return Returns the level of the NotificationSlot object. + * @return Returns the slotflags of the NotificationSlot object. */ uint32_t GetSlotFlags() const; /** - * @brief Sets the level of a NotificationSlot object. - * @note SetLevel must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) method is called. + * @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 level of the NotificationSlot object, which determines the notification display + * @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); diff --git a/interfaces/inner_api/notification_sorting.h b/interfaces/inner_api/notification_sorting.h index 324101613..37e8adaee 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; }; -- Gitee From 294371eff7fb50badeba7ba14d9b5b9b82a892c4 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 11:10:51 +0800 Subject: [PATCH 12/56] Fixed compile error --- frameworks/core/include/ans_manager_proxy.h | 2 +- frameworks/core/src/ans_manager_proxy.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index ec315b5e8..fee8619be 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -679,7 +679,7 @@ public: * @param slotFlags Indicates the slogFlags of slot to get. * @return Returns ERR_OK on success, others on failure. */ - ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr&slot, uint64_t &slotFlags) override; + ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr&slot, uint32_t &slotFlags) override; /** * @brief Set the slotFlags of slot. diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 2322886d5..b0ad2ed12 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2698,7 +2698,7 @@ ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber) ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr&slot, uint32_t& slotFlags) { - + rerun ERR_ANS_PARCELABLE_FAILED; } ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(const sptr &bundleOption, sptr&slot, uint32_t slotFlags) -- Gitee From 48353051a2b6c4750303f9dfefc59e3abfa9551e Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 13:15:01 +0800 Subject: [PATCH 13/56] fixed errors --- frameworks/ans/src/notification_slot.cpp | 2 +- frameworks/ans/src/notification_sorting.cpp | 2 +- frameworks/ans/src/reminder_request.cpp | 6 +- .../unittest/notification_helper_test.cpp | 2 +- .../test/unittest/reminder_request_test.cpp | 2 +- .../core/include/ans_manager_interface.h | 2 +- frameworks/core/src/ans_manager_proxy.cpp | 2 +- frameworks/core/src/ans_manager_stub.cpp | 2 +- .../js/napi/include/manager/napi_slot.h | 16 +-- frameworks/js/napi/src/common.cpp | 14 +-- frameworks/js/napi/src/slot.cpp | 16 +-- interfaces/inner_api/notification_constant.h | 2 +- .../advanced_notification_service_test.cpp | 98 +++++++++---------- .../notification_preferences_test.cpp | 52 +++++----- ...ication_subscriber_manager_branch_test.cpp | 12 +-- services/test/moduletest/ans_module_test.cpp | 42 ++++---- .../notification_service_test.cpp | 4 +- 17 files changed, 138 insertions(+), 138 deletions(-) diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index 729f1b19b..12282588f 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -126,7 +126,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); diff --git a/frameworks/ans/src/notification_sorting.cpp b/frameworks/ans/src/notification_sorting.cpp index 78699b112..0eb450b25 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 773c451a2..364a266cd 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 0edf9670f..dc49fc381 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 957e21c21..88d8b0047 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 1697789b8..1fc5cad6d 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -692,7 +692,7 @@ public: * @param slotFlags Indicates the slogFlags of slot. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, const sptr&slot, uint64_t &slotFlags) = 0; + virtual ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, const sptr&slot, uint32_t &slotFlags) = 0; /** * @brief Set the slotFlags of slot. diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index b0ad2ed12..cac6c9e20 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2698,7 +2698,7 @@ ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber) ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr&slot, uint32_t& slotFlags) { - rerun ERR_ANS_PARCELABLE_FAILED; + return ERR_ANS_PARCELABLE_FAILED; } ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(const sptr &bundleOption, sptr&slot, uint32_t slotFlags) diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 05b22aad7..bf9bc3790 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -537,7 +537,7 @@ ErrCode AnsManagerStub::HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageP return ERR_ANS_PARCELABLE_FAILED; } - if (!reply.WriteUint64(slotFlags)) { + if (!reply.WriteUint32(slotFlags)) { ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: write enabled failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; } diff --git a/frameworks/js/napi/include/manager/napi_slot.h b/frameworks/js/napi/include/manager/napi_slot.h index 99c1a509a..b5f73e1d4 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; }; diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index f0e7d9160..04d3c5ae5 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::UNKNOW: 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/slot.cpp b/frameworks/js/napi/src/slot.cpp index 0baaf077d..a89bf59aa 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; }; diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 33ff17e49..89d21e3e1 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -57,7 +57,7 @@ public: }; enum SlotType { - UNKOWN_TYPE =0, + 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 diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 9619465de..7be1740e8 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 06d1d93f7..ed0bfdfe7 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 9b18d001e..1afb93f63 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 438ec9882..abf4c0b6f 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 f3d25bf3e..62a016aef 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"; -- Gitee From eca09d78d0f35c776eb1133ecb18895526e94b65 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 14:55:35 +0800 Subject: [PATCH 14/56] Fixed errors --- frameworks/ans/src/notification_slot.cpp | 2 +- .../js/napi/include/manager/napi_slot.h | 6 +- frameworks/js/napi/src/common.cpp | 2 +- frameworks/js/napi/src/manager/napi_slot.cpp | 2 + .../js/napi/src/reminder/reminder_common.cpp | 4 +- frameworks/js/napi/src/slot.cpp | 65 +++++++++++++------ interfaces/inner_api/notification_constant.h | 2 +- 7 files changed, 56 insertions(+), 27 deletions(-) diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index 12282588f..f8e0f8248 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -101,7 +101,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"; diff --git a/frameworks/js/napi/include/manager/napi_slot.h b/frameworks/js/napi/include/manager/napi_slot.h index b5f73e1d4..9624a75e2 100644 --- a/frameworks/js/napi/include/manager/napi_slot.h +++ b/frameworks/js/napi/include/manager/napi_slot.h @@ -170,7 +170,7 @@ struct ParametersInfoGetSlotFlagsByBundle { struct AsyncCallbackInfoSetSlotFlagsByBundle { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - ParametersInfoSetSlotByBundle params; + ParametersInfoSetSlotFlagsByBundle params; CallbackPromiseInfo info; }; @@ -193,7 +193,7 @@ 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 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); @@ -215,7 +215,7 @@ napi_value ParseParametersIsEnableSlot( 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, ParametersInfoGetSlotNumByBundle ¶ms); + const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotFlagsByBundle ¶ms); } // namespace NotificationNapi } // namespace OHOS diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index 04d3c5ae5..15dead808 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -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::UNKNOW: + case NotificationConstant::SlotType::UNKNOWN_TYPE: outType = SlotType::UNKNOWN_TYPE; break; case NotificationConstant::SlotType::SOCIAL_COMMUNICATION: diff --git a/frameworks/js/napi/src/manager/napi_slot.cpp b/frameworks/js/napi/src/manager/napi_slot.cpp index a15467074..46936368d 100644 --- a/frameworks/js/napi/src/manager/napi_slot.cpp +++ b/frameworks/js/napi/src/manager/napi_slot.cpp @@ -982,6 +982,7 @@ napi_value NapiSetSlotFlagsByBundle(napi_env env, napi_callback_info info) return promise; } */ + return Common::NapiGetUndefined(env); } napi_value NapiGetSlotFlagsByBundle(napi_env env, napi_callback_info info) @@ -1058,6 +1059,7 @@ napi_value NapiGetSlotFlagsByBundle(napi_env env, napi_callback_info info) return promise; } */ + return Common::NapiGetUndefined(env); } } // namespace NotificationNapi diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index fa2ce9813..f14a3d6dd 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 a89bf59aa..9f6a2fd90 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -81,19 +81,6 @@ struct AsyncCallbackInfoGetSlot { sptr slot = nullptr; }; -struct ParametersInfoGetSlotNumByBundle { - NotificationBundleOption option; - napi_ref callback = nullptr; -}; - -struct AsyncCallbackInfoGetSlotNumByBundle { - napi_env env = nullptr; - napi_async_work asyncWork = nullptr; - ParametersInfoGetSlotNumByBundle params; - CallbackPromiseInfo info; - uint64_t num = 0; -}; - struct AsyncCallbackInfoGetSlots { napi_env env = nullptr; napi_async_work asyncWork = nullptr; @@ -114,6 +101,19 @@ struct AsyncCallbackInfoGetSlotsByBundle { std::vector> slots; }; +struct ParametersInfoGetSlotNumByBundle { + NotificationBundleOption option; + napi_ref callback = nullptr; +}; + +struct AsyncCallbackInfoGetSlotNumByBundle { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + ParametersInfoGetSlotNumByBundle params; + CallbackPromiseInfo info; + uint64_t num = 0; +}; + struct ParametersInfoRemoveSlot { NotificationConstant::SlotType outType = NotificationConstant::SlotType::OTHER_TYPES; napi_ref callback = nullptr; @@ -160,6 +160,34 @@ struct AsyncCallbackInfoInfoIsEnableSlot { CallbackPromiseInfo info; }; +struct ParametersInfoSetSlotFlagsByBundle { + NotificationBundleOption option; + sptr slot; + uint32_t slotFlags; + napi_ref callback = nullptr; +}; + +struct ParametersInfoGetSlotFlagsByBundle { + NotificationBundleOption option; + sptr slot; + 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"); @@ -401,16 +429,16 @@ napi_value ParseParametersGetSlotNumByBundle( napi_value ParseParametersSetSlotFlagsByBundle( const napi_env &env, const napi_callback_info &info, ParametersInfoSetSlotFlagsByBundle ¶ms) { - + return nullptr; } napi_value ParseParametersGetSlotFlagsByBundle( - const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotNumByBundle ¶ms) + const napi_env &env, const napi_callback_info &info, ParametersInfoGetSlotFlagsByBundle ¶ms) { - + return nullptr; } @@ -1483,13 +1511,12 @@ napi_value IsEnableNotificationSlot(napi_env env, napi_callback_info info) napi_value GetSlotFlagsByBundle(napi_env env, napi_callback_info info) { - + return Common::NapiGetUndefined(env); } - napi_value SetSlotFlagsByBundle(napi_env env, napi_callback_info info) { - + return Common::NapiGetUndefined(env); } } // namespace NotificationNapi diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 89d21e3e1..c60b5180d 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -57,7 +57,7 @@ public: }; enum SlotType { - UNKNOWN_TYPE =0, + 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 -- Gitee From a3c14d810a7faca4b846be5d2ec637c1f1132f87 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 15:18:16 +0800 Subject: [PATCH 15/56] Fixed error --- services/ans/src/advanced_notification_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 93309924a..31c7c81cf 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; } -- Gitee From ef9a3187794b572052e7315c22935f530390dad8 Mon Sep 17 00:00:00 2001 From: leikanglong Date: Sat, 18 Nov 2023 15:29:30 +0800 Subject: [PATCH 16/56] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E6=95=B0=E6=8D=AE=E5=BA=93=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: leikanglong --- .../include/notification_preferences_info.h | 15 ++++ services/ans/include/preferences_constant.h | 6 ++ .../src/notification_preferences_database.cpp | 84 +++++++++++++++++++ .../ans/src/notification_preferences_info.cpp | 31 +++++++ 4 files changed, 136 insertions(+) diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 6e1272d6e..217642dfb 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -61,6 +61,20 @@ public: */ int32_t GetImportance() const; + /** + * @brief Set bundle slotFlags. + * + * @param name Indicates the bundle slotFlags. + */ + void SetSlotFlags(const sptr& slot, const int32_t &slotFlags); + + /** + * @brief Get bundle slotFlags. + * + * @return Return slotFlags. + */ + int32_t GetSlotFlags(const sptr& slot) const; + /** * @brief Set bundle Whether to show badge. * @@ -192,6 +206,7 @@ public: bool isEnabledNotification_ = BUNDLE_ENABLE_NOTIFICATION; bool hasPoppedDialog_ = BUNDLE_POPPED_DIALOG; std::map> slots_; + std::map slotFlagsMap; }; /* diff --git a/services/ans/include/preferences_constant.h b/services/ans/include/preferences_constant.h index 7e3de52ce..f1fcf2f66 100644 --- a/services/ans/include/preferences_constant.h +++ b/services/ans/include/preferences_constant.h @@ -60,6 +60,12 @@ enum class BundleType { BUNDLE_ENABLE_NOTIFICATION_TYPE, BUNDLE_ENABLE_NOTIFICATION_USER_OPTION, BUNDLE_POPPED_DIALOG_TYPE, + BUNDLE_SLOTFLGS_SOCIAL_COMMUNICATION_TYPE, //社交通信 + BUNDLE_SLOTFLGS_SERVICE_REMINDER_TYPE, //服务提醒 + BUNDLE_SLOTFLGS_CONTENT_INFORMATION_TYPE, //内容资讯 + BUNDLE_SLOTFLGS_OTHER_TYPE, //其他类型 + BUNDLE_SLOTFLGS_CUSTOM_TYPE, //自定义类型 + BUNDLE_SLOTFLGS_LIVE_VIEW_TYPE, //实况窗类型(仅对系统应用开放) }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index fc77905c6..85ae30452 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -168,6 +168,41 @@ const static std::string KEY_SLOT_ENABLE_BYPASS_DND = "enableBypassDnd"; */ const static std::string KEY_SLOT_ENABLED = "enabled"; +/** + * Indicates whether the type of slot is flags. + */ +const static std::string KEY_SLOT_FLAGS = "flags"; + +/** + * Indicates that disturbe key which slot flgs social communication + */ +const static std::string KEY_BUNDLE_SLOTFLGS_SOCIAL_COMMUNICATION_TYPE = "bundleslotflgssocialcommunication"; + +/** + * Indicates that disturbe key which slot flgs servicer eminder type + */ +const static std::string KEY_BUNDLE_SLOTFLGS_SERVICE_REMINDER_TYPE = "bundleslotflgsserviceremindertype"; + +/** + * Indicates that disturbe key which slot flgs content information type + */ +const static std::string KEY_BUNDLE_SLOTFLGS_CONTENT_INFORMATION_TYPE = "bundleslotflgscontentinformationtype"; + +/** + * Indicates that disturbe key which slot flgs other type + */ +const static std::string KEY_BUNDLE_SLOTFLGS_OTHER_TYPE = "bundleslotflgsothertype"; + +/** + * Indicates that disturbe key which slot flgs custom type + */ +const static std::string KEY_BUNDLE_SLOTFLGS_CUSTOM_TYPE = "bundleslotflgscustomtype"; + +/** + * Indicates that disturbe key which slot flgs live view type + */ +const static std::string KEY_BUNDLE_SLOTFLGS_LIVE_VIEW_TYPE = "bundleslotflgsliveviewtype"; + const std::map &, std::string &)>> @@ -227,6 +262,11 @@ const std::map& slot, const int32_t &slotFlags) +{ + if (!CheckRdbStore()) { + ANS_LOGE("RdbStore is nullptr."); + return false; + } + + std::string typeKey = + std::string().append(std::to_string(bundleInfo)).append(KEY_UNDER_LINE).append(KEY_SLOT_FLAGS); + std::string flagsValue = std::to_string(slotFlags); + int32_t result = rdbDataManager_->InsertData(typeKey, flagsValue); + if (result != NativeRdb::E_OK) { + ANS_LOGE("Store flags notification failed. %{public}d", result); + return false; + } + return true; +} + bool NotificationPreferencesDatabase::PutHasPoppedDialog( const NotificationPreferencesInfo::BundleInfo &bundleInfo, const bool &hasPopped) { @@ -747,6 +806,24 @@ int32_t NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( case BundleType::BUNDLE_POPPED_DIALOG_TYPE: keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_POPPED_DIALOG); break; + case BundleType::BUNDLE_SLOTFLGS_SOCIAL_COMMUNICATION_TYPE: + keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_SOCIAL_COMMUNICATION_TYPE); + break; + case BundleType::BUNDLE_SLOTFLGS_SERVICE_REMINDER_TYPE: + keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_SERVICE_REMINDER_TYPE); + break; + case BundleType::BUNDLE_SLOTFLGS_CONTENT_INFORMATION_TYPE: + keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_CONTENT_INFORMATION_TYPE); + break; + case BundleType::BUNDLE_SLOTFLGS_OTHER_TYPE: + keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_OTHER_TYPE); + break; + case BundleType::BUNDLE_SLOTFLGS_CUSTOM_TYPE: + keyStr = GenerateBundleKey(bundleKey, KEYBUNDLE_SLOTFLGS_CUSTOM_TYPE); + break; + case BundleType::BUNDLE_SLOTFLGS_LIVE_VIEW_TYPE: + keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_LIVE_VIEW_TYPE); + break; default: break; } @@ -1142,6 +1219,13 @@ 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::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 bc28ad929..d686c5174 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -98,6 +98,37 @@ bool NotificationPreferencesInfo::BundleInfo::GetSlot( return false; } +void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(const sptr &slot, const int32_t &slotFlags) +{ + if (slotFlagsMap.find(slot->GetType()) == slotFlagsMap.end()) + { + slotFlagsMap.insert_or_assign(slot->GetType(), slotFlags) + } + else + { + for (auto it = slotFlagsMap.begin(); it != slotFlagsMap.end(); ++it) + { + if (it->first.compare(slot->GetType()) == 0) && it->second != slotFlags) + { + it->second = slotflag; + } + } + } +} + +int32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags(const sptr &slot) const +{ + auto it = slotFlagsMap.find(slot->GetType()) + if(it != slotFlagsMap.end()) + { + return it->second; + } + else + { + return 0; + } +} + bool NotificationPreferencesInfo::BundleInfo::GetAllSlots(std::vector> &slots) { slots.clear(); -- Gitee From b00dc3a7a79e2e7f914356deec8dceecf0a86612 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 16:10:04 +0800 Subject: [PATCH 17/56] =?UTF-8?q?=E7=BB=99Service=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/advanced_notification_service.h | 21 +++++++++++++++++++ .../ans/src/advanced_notification_service.cpp | 11 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index eb54f4259..2149dbeb9 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -689,6 +689,27 @@ 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, const sptr&slot, 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, sptr&slot, uint32_t slotFlags) override; + #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED /** * @brief Obtains the event of turn on screen. diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 31c7c81cf..ea2fd5b9f 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -4859,6 +4859,17 @@ void AdvancedNotificationService::ResetPushCallbackProxy() pushCallBack_ = nullptr; } +ErrCode AdvancedNotificationService::GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr &slot, uint32_t &slotFlags) +{ + return ERR_ANS_NO_MEMORY; +} + +ErrCode AdvancedNotificationService::SetSlotFlagsAsBundle(const sptr &bundleOption, sptr &slot, uint32_t slotFlags) +{ + + return ERR_ANS_NO_MEMORY; +} + ErrCode AdvancedNotificationService::RegisterPushCallback(const sptr &pushCallback) { if (!AccessTokenHelper::IsSystemApp()) { -- Gitee From 3fa3cc189d953138f7dc794d4c97b9c166b6f7b8 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 18 Nov 2023 17:08:13 +0800 Subject: [PATCH 18/56] Update fixed error --- frameworks/ans/src/notification_slot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index f8e0f8248..94f8cd9df 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -347,7 +347,7 @@ bool NotificationSlot::ReadFromParcel(Parcel &parcel) 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; -- Gitee From 885c632886a3ab69ea430ca171b4d3ceaedb6008 Mon Sep 17 00:00:00 2001 From: zhushuaiyu Date: Sat, 18 Nov 2023 17:16:09 +0800 Subject: [PATCH 19/56] add function implementation --- frameworks/core/src/ans_manager_proxy.cpp | 52 ++++++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index cac6c9e20..e771f622d 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2697,8 +2697,56 @@ ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber) ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr&slot, uint32_t& slotFlags) { + if (bundleOption == nullptr) { + ANS_LOGE("[GetSlotFlagsAsBundle] fail: bundle is empty."); + return ERR_ANS_INVALID_PARAM; + } - return ERR_ANS_PARCELABLE_FAILED; + if (slot == nullptr) { + ANS_LOGE("[GetSlotFlagsAsBundle] fail: slots 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.WriteParcelable(slot)) { + ANS_LOGE("[GetSlotFlagsAsBundle] fail: write slots 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, sptr&slot, uint32_t slotFlags) @@ -2716,7 +2764,7 @@ ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(const sptr Date: Mon, 20 Nov 2023 18:39:15 +0800 Subject: [PATCH 20/56] added code and fixed code --- frameworks/ans/src/notification_helper.cpp | 6 + frameworks/core/include/ans_notification.h | 10 + frameworks/core/src/ans_notification.cpp | 17 ++ frameworks/js/napi/src/manager/napi_slot.cpp | 139 +---------- frameworks/js/napi/src/slot.cpp | 229 ++++++++++++++++++- interfaces/inner_api/notification_helper.h | 10 + 6 files changed, 267 insertions(+), 144 deletions(-) diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 2e1c71735..8c1e1a6fa 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -60,6 +60,12 @@ ErrCode NotificationHelper::GetNotificationSlotNumAsBundle(const NotificationBun return DelayedSingleton::GetInstance()->GetNotificationSlotNumAsBundle(bundleOption, num); } + +ErrCode NotificationHelper::GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slogFlags) +{ + return DelayedSingleton::GetInstance()->GetNotificationSlotFlagsAsBundle(bundleOption, num); +} + ErrCode NotificationHelper::PublishNotification(const NotificationRequest &request) { return DelayedSingleton::GetInstance()->PublishNotification(request); diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index fff7608ec..3c16669de 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -102,6 +102,16 @@ 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 slot number by bundle result. + */ + ErrCode GetNotificationSlotFlagsAsBundle(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/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 383756662..0ec8be894 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -121,6 +121,23 @@ 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::PublishNotification(const NotificationRequest &request) { ANS_LOGI("enter"); diff --git a/frameworks/js/napi/src/manager/napi_slot.cpp b/frameworks/js/napi/src/manager/napi_slot.cpp index 46936368d..495c84711 100644 --- a/frameworks/js/napi/src/manager/napi_slot.cpp +++ b/frameworks/js/napi/src/manager/napi_slot.cpp @@ -913,151 +913,16 @@ napi_value NapiIsEnableNotificationSlot(napi_env env, napi_callback_info info) napi_value NapiSetSlotFlagsByBundle(napi_env env, napi_callback_info info) { - /*ANS_LOGI("enter"); - ParametersInfoSetSlotByBundle params {}; - if (ParseParametersSetSlotByBundle(env, info, params) == nullptr) { - Common::NapiThrow(env, ERROR_PARAM_INVALID); - return Common::NapiGetUndefined(env); - } - - AsyncCallbackInfoSetSlotByBundle *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoSetSlotByBundle {.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, "setSlotByBundle", NAPI_AUTO_LENGTH, &resourceName); - // Asynchronous function call - napi_create_async_work(env, - nullptr, - resourceName, - [](napi_env env, void *data) { - ANS_LOGI("NapiSetSlotByBundle work excute."); - auto asynccallbackinfo = static_cast(data); - if (asynccallbackinfo) { - asynccallbackinfo->info.errorCode = NotificationHelper::UpdateNotificationSlots( - asynccallbackinfo->params.option, asynccallbackinfo->params.slots); - } - }, - [](napi_env env, napi_status status, void *data) { - ANS_LOGI("NapiSetSlotByBundle 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 napiSetSlotByBundle callback reference."); - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } - ANS_LOGD("NapiSetSlotByBundle 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 napiSetSlotByBundle 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 napiSetSlotByBundle callback reference."); - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } + /* - if (isCallback) { - ANS_LOGD("napiSetSlotByBundle callback is nullptr."); - return Common::NapiGetNull(env); - } else { - return promise; - } -*/ + */ return Common::NapiGetUndefined(env); } napi_value NapiGetSlotFlagsByBundle(napi_env env, napi_callback_info info) { /* - ANS_LOGI("enter"); - ParametersInfoGetSlotNumByBundle params {}; - if (ParseParametersGetSlotNumByBundle(env, info, params) == nullptr) { - Common::NapiThrow(env, ERROR_PARAM_INVALID); - return Common::NapiGetUndefined(env); - } - AsyncCallbackInfoGetSlotNumByBundle *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoGetSlotNumByBundle {.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, "getSlotNumByBundle", NAPI_AUTO_LENGTH, &resourceName); - // Asynchronous function call - napi_create_async_work(env, - nullptr, - resourceName, - [](napi_env env, void *data) { - ANS_LOGI("NapiGetSlotNumByBundle work excute."); - auto asynccallbackinfo = reinterpret_cast(data); - if (asynccallbackinfo) { - asynccallbackinfo->info.errorCode = NotificationHelper::GetNotificationSlotNumAsBundle( - asynccallbackinfo->params.option, asynccallbackinfo->num); - } - }, - [](napi_env env, napi_status status, void *data) { - ANS_LOGI("NapiGetSlotNumByBundle work complete."); - auto asynccallbackinfo = static_cast(data); - if (asynccallbackinfo) { - napi_value result = nullptr; - napi_create_uint32(env, asynccallbackinfo->num, &result); - Common::CreateReturnValue(env, asynccallbackinfo->info, result); - if (asynccallbackinfo->info.callback != nullptr) { - ANS_LOGD("Delete napiGetSlotNumByBundle callback reference."); - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } - ANS_LOGD("NapiGetSlotNumByBundle 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 napiGetSlotNumByBundle 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 napiGetSlotNumByBundle callback reference."); - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - napi_delete_async_work(env, asynccallbackinfo->asyncWork); - delete asynccallbackinfo; - asynccallbackinfo = nullptr; - } - - if (isCallback) { - ANS_LOGD("napiGetSlotNumByBundle callback is nullptr."); - return Common::NapiGetNull(env); - } else { - return promise; - } */ return Common::NapiGetUndefined(env); } diff --git a/frameworks/js/napi/src/slot.cpp b/frameworks/js/napi/src/slot.cpp index 9f6a2fd90..afe9bdf67 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -162,14 +162,12 @@ struct AsyncCallbackInfoInfoIsEnableSlot { struct ParametersInfoSetSlotFlagsByBundle { NotificationBundleOption option; - sptr slot; uint32_t slotFlags; napi_ref callback = nullptr; }; struct ParametersInfoGetSlotFlagsByBundle { NotificationBundleOption option; - sptr slot; napi_ref callback = nullptr; }; @@ -429,16 +427,93 @@ napi_value ParseParametersGetSlotNumByBundle( napi_value ParseParametersSetSlotFlagsByBundle( const napi_env &env, const napi_callback_info &info, ParametersInfoSetSlotFlagsByBundle ¶ms) { - return nullptr; + ANS_LOGI("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; + + } + int32_t slotFlags = 0; + napi_get_value_int32(env, argv[PARAM1], &slotFlags); + paras.slotFlags = slotFlags; + + // 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); + } + napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); + } + + 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 nullptr; + return Common::NapiGetNull(env); } @@ -1508,15 +1583,155 @@ napi_value IsEnableNotificationSlot(napi_env env, napi_callback_info info) } } - napi_value GetSlotFlagsByBundle(napi_env env, napi_callback_info info) { - return Common::NapiGetUndefined(env); + 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); + + 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) { - return Common::NapiGetUndefined(env); + ANS_LOGI("enter"); + + ParametersInfoSetSlotFlagsByBundle params {}; + if (ParseParametersSetSlotFlagsByBundle(env, info, params) == 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::UpdateNotificationSlots( + asynccallbackinfo->params.option, asynccallbackinfo->params.slots); + } + }, + [](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; + } + } } // namespace NotificationNapi diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index e07cd0d17..2e47c4439 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -104,6 +104,16 @@ 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 Publishes a notification. * @note If a notification with the same ID has been published by the current application and has not been deleted, -- Gitee From b8ca64fcd08939caf69ac9f48b066a0ebce3ba2d Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Tue, 21 Nov 2023 09:25:24 +0800 Subject: [PATCH 21/56] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/core/include/ans_manager_proxy.h | 4 ++-- frameworks/core/src/ans_manager_proxy.cpp | 15 ++------------- frameworks/core/src/ans_manager_stub.cpp | 17 ++--------------- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index fee8619be..28582a964 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -679,7 +679,7 @@ public: * @param slotFlags Indicates the slogFlags of slot to get. * @return Returns ERR_OK on success, others on failure. */ - ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr&slot, uint32_t &slotFlags) override; + ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t &slotFlags) override; /** * @brief Set the slotFlags of slot. @@ -689,7 +689,7 @@ public: * @param slotFlags Indicates the slogFlags of slot to set. * @return Returns ERR_OK on success, others on failure. */ - ErrCode SetSlotFlagsAsBundle(const sptr &bundleOption, sptr&slot, uint32_t slotFlags) override; + ErrCode SetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) override; /** * @brief Register Push Callback. diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index e771f622d..c26f65086 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2695,7 +2695,7 @@ ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber) return result; } -ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr&slot, uint32_t& slotFlags) +ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t& slotFlags) { if (bundleOption == nullptr) { ANS_LOGE("[GetSlotFlagsAsBundle] fail: bundle is empty."); @@ -2718,11 +2718,6 @@ ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr &bundleOption, sptr&slot, uint32_t slotFlags) +ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) { if (bundleOption == nullptr) { ANS_LOGE("[SetSlotFlagsAsBundle] fail: bundleOption is empty."); @@ -2772,12 +2767,6 @@ ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(const sptr slot = data.ReadStrongParcelable(); - if (slot == 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, slot, slotFlags); + 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; @@ -524,14 +517,8 @@ ErrCode AnsManagerStub::HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageP return ERR_ANS_PARCELABLE_FAILED; } - sptr slot = data.ReadStrongParcelable(); - if (slot == nullptr) { - ANS_LOGE("[HandleGetSlotFlagsAsBundle] fail: read bundle failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - uint32_t slotFlags = 0; - ErrCode result = GetSlotFlagsAsBundle(bundleOption, slot, slotFlags); + 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; -- Gitee From ae2bb9c770604e1a10782ec5dd70ae1c39ad95b4 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Tue, 21 Nov 2023 09:30:16 +0800 Subject: [PATCH 22/56] =?UTF-8?q?API=E6=8E=A5=E5=8F=A3=E5=8F=98=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/core/include/ans_manager_proxy.h | 2 +- services/ans/include/advanced_notification_service.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 28582a964..12b568bba 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -679,7 +679,7 @@ public: * @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; + ErrCode NapiGetSlotsByBundle(const sptr &bundleOption, uint32_t &slotFlags) override; /** * @brief Set the slotFlags of slot. diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 2149dbeb9..70771440e 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -698,7 +698,7 @@ public: * @param slotFlags Indicates the slogFlags of slot. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, const sptr&slot, uint32_t &slotFlags) override; + virtual ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t &slotFlags) override; /** * @brief Set the slotFlags of slot. @@ -708,7 +708,7 @@ public: * @param slotFlags Indicates the slogFlags of slot to set. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode SetSlotFlagsAsBundle(const sptr& bundleOption, sptr&slot, uint32_t slotFlags) override; + virtual ErrCode SetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t slotFlags) override; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED /** -- Gitee From 17492026fd71823062f48971186fea242725596e Mon Sep 17 00:00:00 2001 From: zhushuaiyu Date: Tue, 21 Nov 2023 11:12:21 +0800 Subject: [PATCH 23/56] Fixed errors --- frameworks/ans/src/notification_helper.cpp | 9 +- frameworks/core/include/ans_notification.h | 13 +- frameworks/core/src/ans_notification.cpp | 18 +++ frameworks/js/napi/src/manager/napi_slot.cpp | 142 ++++++++++++++++++- frameworks/js/napi/src/slot.cpp | 18 +-- interfaces/inner_api/notification_helper.h | 9 ++ 6 files changed, 191 insertions(+), 18 deletions(-) diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 8c1e1a6fa..c3f31c349 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -61,9 +61,14 @@ ErrCode NotificationHelper::GetNotificationSlotNumAsBundle(const NotificationBun } -ErrCode NotificationHelper::GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slogFlags) +ErrCode NotificationHelper::GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slotFlags) { - return DelayedSingleton::GetInstance()->GetNotificationSlotFlagsAsBundle(bundleOption, num); + return DelayedSingleton::GetInstance()->GetNotificationSlotFlagsAsBundle(bundleOption, slotFlags); +} + +ErrCode SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags) +{ + return DelayedSingleton::GetInstance()->SetNotificationSlotFlagsAsBundle(bundleOption, slotFlags); } ErrCode NotificationHelper::PublishNotification(const NotificationRequest &request) diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 3c16669de..c8d1608e0 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -108,10 +108,21 @@ public: * * @param bundleOption Indicates the bundle name and uid of the application. * @param slotFlags Indicates slotFlags of bundle. - * @return Returns get slot number by bundle result. + * @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/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 0ec8be894..100280288 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -138,6 +138,24 @@ ErrCode AnsNotification::GetNotificationSlotFlagsAsBundle(const NotificationBund } + +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/src/manager/napi_slot.cpp b/frameworks/js/napi/src/manager/napi_slot.cpp index 495c84711..cbce9e430 100644 --- a/frameworks/js/napi/src/manager/napi_slot.cpp +++ b/frameworks/js/napi/src/manager/napi_slot.cpp @@ -913,18 +913,148 @@ napi_value NapiIsEnableNotificationSlot(napi_env env, napi_callback_info info) 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); + } - */ - 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::SetSlotFlagsByBundle( + 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); + } - */ - 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 diff --git a/frameworks/js/napi/src/slot.cpp b/frameworks/js/napi/src/slot.cpp index afe9bdf67..162f0e68d 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -451,13 +451,13 @@ napi_value ParseParametersSetSlotFlagsByBundle( 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; - - } + // //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; + // } + int32_t slotFlags = 0; napi_get_value_int32(env, argv[PARAM1], &slotFlags); paras.slotFlags = slotFlags; @@ -1691,8 +1691,8 @@ napi_value SetSlotFlagsByBundle(napi_env env, napi_callback_info info) ANS_LOGI("SetSlotFlagsByBundle napi_create_async_work start"); auto asynccallbackinfo = static_cast(data); if (asynccallbackinfo) { - asynccallbackinfo->info.errorCode = NotificationHelper::UpdateNotificationSlots( - asynccallbackinfo->params.option, asynccallbackinfo->params.slots); + asynccallbackinfo->info.errorCode = NotificationHelper::SetNotificationSlotFlagsByBundle( + asynccallbackinfo->params.option, asynccallbackinfo->params.slotFlags); } }, [](napi_env env, napi_status status, void *data) { diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index 2e47c4439..ddebc3e1b 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -114,6 +114,15 @@ public: */ 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, -- Gitee From aa8d0c874f8def230f5f40ac97404677b3c6d021 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Tue, 21 Nov 2023 16:56:01 +0800 Subject: [PATCH 24/56] Fixed error --- frameworks/core/include/ans_manager_proxy.h | 2 +- frameworks/core/src/ans_notification.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 12b568bba..28582a964 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -679,7 +679,7 @@ public: * @param slotFlags Indicates the slogFlags of slot to get. * @return Returns ERR_OK on success, others on failure. */ - ErrCode NapiGetSlotsByBundle(const sptr &bundleOption, uint32_t &slotFlags) override; + ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t &slotFlags) override; /** * @brief Set the slotFlags of slot. diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 100280288..d6f713f99 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -135,7 +135,6 @@ ErrCode AnsNotification::GetNotificationSlotFlagsAsBundle(const NotificationBund sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->GetSlotFlagsAsBundle(bo, slotFlags); - } @@ -153,7 +152,6 @@ ErrCode AnsNotification::SetNotificationSlotFlagsAsBundle(const NotificationBund sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); return ansManagerProxy_->SetSlotFlagsAsBundle(bo, slotFlags); - } ErrCode AnsNotification::PublishNotification(const NotificationRequest &request) -- Gitee From 08ff32c3443c181911276272ac42db808a50de39 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Tue, 21 Nov 2023 17:04:52 +0800 Subject: [PATCH 25/56] Fixed API parameter number --- frameworks/core/include/ans_manager_interface.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 1fc5cad6d..b749ac832 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -692,7 +692,7 @@ public: * @param slotFlags Indicates the slogFlags of slot. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, const sptr&slot, uint32_t &slotFlags) = 0; + virtual ErrCode GetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t &slotFlags) = 0; /** * @brief Set the slotFlags of slot. @@ -702,7 +702,7 @@ public: * @param slotFlags Indicates the slogFlags of slot to set. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode SetSlotFlagsAsBundle(const sptr& bundleOption, sptr&slot, uint32_t slotFlags) = 0; + virtual ErrCode SetSlotFlagsAsBundle(const sptr& bundleOption, uint32_t slotFlags) = 0; /** -- Gitee From d97de50aa559bf2eca1eb3ba80d3bafa72e71505 Mon Sep 17 00:00:00 2001 From: zhushuaiyu Date: Tue, 21 Nov 2023 17:56:28 +0800 Subject: [PATCH 26/56] Add essential functions implementation --- .../ans/include/notification_preferences.h | 19 +++++ .../include/notification_preferences_info.h | 15 ++++ .../ans/src/advanced_notification_service.cpp | 73 ++++++++++++++++++- services/ans/src/notification_preferences.cpp | 34 +++++++++ .../ans/src/notification_preferences_info.cpp | 11 +++ 5 files changed, 148 insertions(+), 4 deletions(-) diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 2f2d9a2d3..31d9ad47c 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -173,6 +173,25 @@ 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 soltFlags Indicates to setsoltFlags. + * @return Return ERR_OK on success, others on failure. + */ + ErrCode GetNotificationSlotFlagsForBundle(const sptr &bundleOption, uint32_t &soltFlags); + + /** + * @brief Get slotFlags in the of bunlde from DB. + * + * @param bundleOption Indicates bunlde info label. + * @param soltFlags Indicates to get soltFlags. + * @return Return ERR_OK on success, others on failure. + */ + ErrCode SetNotificationSlotFlagsForBundle(const sptr &bundleOption, uint32_t soltFlags); + /** * @brief Get private notification enable in the of bunlde from DB. * diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 6e1272d6e..aea111aa3 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -137,6 +137,20 @@ public: */ uint32_t GetAllSlotsSize(); + /** + * @brief Get slotflags from bundle. + * + * @return Return slotFlags of bundle. + */ + uint32_t GetSlotFlags(); + + /** + * @brief Get slotflags from bundle. + * + * @param slotFlags Indicates slotFlags of bundle. + */ + void SetSlotFlags(uint32_t slotFlags); + /** * @brief Get all slot from group in bundle. * @@ -186,6 +200,7 @@ 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; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index ea2fd5b9f..f77197a58 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -4859,15 +4859,80 @@ void AdvancedNotificationService::ResetPushCallbackProxy() pushCallBack_ = nullptr; } -ErrCode AdvancedNotificationService::GetSlotFlagsAsBundle(const sptr &bundleOption, const sptr &slot, uint32_t &slotFlags) +ErrCode AdvancedNotificationService::GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t &slotFlags) { - return ERR_ANS_NO_MEMORY; + 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; + num = 0; + } + })); + notificationSvrQueue_->wait(handler); + + return result; } -ErrCode AdvancedNotificationService::SetSlotFlagsAsBundle(const sptr &bundleOption, sptr &slot, uint32_t slotFlags) +ErrCode AdvancedNotificationService::SetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) { + if (bundleOption == nullptr) { + ANS_LOGE("[SetSlotFlagsAsBundle] fail: bundle 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.WriteStrongParcelable(bundleOption)) { + ANS_LOGE("[SetSlotFlagsAsBundle] fail:: write bundle failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(slotFlags)) { + 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("fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } - return ERR_ANS_NO_MEMORY; + if (!reply.ReadInt32(result)) { + ANS_LOGE("fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; } ErrCode AdvancedNotificationService::RegisterPushCallback(const sptr &pushCallback) diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index e9b3fad21..85b9fff69 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -255,6 +255,40 @@ ErrCode NotificationPreferences::GetNotificationSlotsNumForBundle( return result; } +ErrCode NotificationPreferences::GetNotificationSlotFlagsForBundle( + const sptr &bundleOption, uint32_t &soltFlags) +{ + if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode result = ERR_OK; + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::lock_guard lock(preferenceMutex_); + if (preferencesInfo_.GetBundleInfo(bundleOption, bundleInfo)) { + soltFlags = static_cast(bundleInfo.GetSlotFlags()); + } else { + result = ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST; + } + return result; +} + + +ErrCode NotificationPreferences::SetNotificationSlotFlagsForBundle( + const sptr &bundleOption, uint32_t soltFlags) +{ + 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_SLOT_FLAGS, soltFlags); + if (result == ERR_OK) { + preferencesInfo_ = preferencesInfo; + } + return result; +} + ErrCode NotificationPreferences::IsShowBadge(const sptr &bundleOption, bool &enable) { if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index bc28ad929..233b231db 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -130,6 +130,17 @@ bool NotificationPreferencesInfo::BundleInfo::RemoveSlot(const NotificationConst return false; } +uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() +{ + return slotFlags_; +} + +void SetSlotFlags(uint32_t slotFlags) +{ + + slotFlags_ = slotFlags; +} + void NotificationPreferencesInfo::BundleInfo::RemoveAllSlots() { slots_.clear(); -- Gitee From 2b22021e1a4e6ecff3961b51aa4291482059540a Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Tue, 21 Nov 2023 18:13:58 +0800 Subject: [PATCH 27/56] Fixed compiler errors --- frameworks/core/src/ans_manager_proxy.cpp | 11 ----------- frameworks/js/napi/src/manager/napi_slot.cpp | 2 +- frameworks/js/napi/src/slot.cpp | 7 ++----- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index c26f65086..d70a4b05f 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2702,11 +2702,6 @@ ErrCode AnsManagerProxy::GetSlotFlagsAsBundle(const sptr(data); if (asynccallbackinfo) { - asynccallbackinfo->info.errorCode = NotificationHelper::SetSlotFlagsByBundle( + asynccallbackinfo->info.errorCode = NotificationHelper::SetNotificationSlotFlagsAsBundle( asynccallbackinfo->params.option, asynccallbackinfo->params.slotFlags); } }, diff --git a/frameworks/js/napi/src/slot.cpp b/frameworks/js/napi/src/slot.cpp index 162f0e68d..ecd239e00 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -460,7 +460,7 @@ napi_value ParseParametersSetSlotFlagsByBundle( int32_t slotFlags = 0; napi_get_value_int32(env, argv[PARAM1], &slotFlags); - paras.slotFlags = slotFlags; + params.slotFlags = slotFlags; // argv[2]:callback if (argc >= SET_SLOT_AS_BUNDLE_MAX_PARA) { @@ -1605,9 +1605,6 @@ napi_value GetSlotFlagsByBundle(napi_env env, napi_callback_info info) napi_value resourceName = nullptr; napi_create_string_latin1(env, "getSlotFlagsByBundle", NAPI_AUTO_LENGTH, &resourceName); - 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, @@ -1691,7 +1688,7 @@ napi_value SetSlotFlagsByBundle(napi_env env, napi_callback_info info) ANS_LOGI("SetSlotFlagsByBundle napi_create_async_work start"); auto asynccallbackinfo = static_cast(data); if (asynccallbackinfo) { - asynccallbackinfo->info.errorCode = NotificationHelper::SetNotificationSlotFlagsByBundle( + asynccallbackinfo->info.errorCode = NotificationHelper::SetNotificationSlotFlagsAsBundle( asynccallbackinfo->params.option, asynccallbackinfo->params.slotFlags); } }, -- Gitee From ba48cf46e3d9c3a083ffbd23123fd7e45d3007e9 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Tue, 21 Nov 2023 18:46:55 +0800 Subject: [PATCH 28/56] Fixed errors --- .../ans/src/advanced_notification_service.cpp | 50 +++++++------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index f77197a58..dfd2491c5 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -4888,7 +4888,7 @@ ErrCode AdvancedNotificationService::GetSlotFlagsAsBundle(const sptrwait(handler); @@ -4898,43 +4898,29 @@ ErrCode AdvancedNotificationService::GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) { - if (bundleOption == nullptr) { - ANS_LOGE("[SetSlotFlagsAsBundle] fail: bundle 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; - } + ANS_LOGD("%{public}s", __FUNCTION__); - if (!data.WriteStrongParcelable(bundleOption)) { - ANS_LOGE("[SetSlotFlagsAsBundle] fail:: write bundle failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - if (!data.WriteInt32(slotFlags)) { - 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("fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; + sptr bundleOption = GenerateBundleOption(); + if (bundleOption == nullptr) { + ANS_LOGD("BundleOption is null."); + return ERR_ANS_INVALID_BUNDLE; } - if (!reply.ReadInt32(result)) { - ANS_LOGE("fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; + if (notificationSvrQueue_ == nullptr) { + ANS_LOGE("Serial queue is invalidity."); + return ERR_ANS_INVALID_PARAM; } - - return result; + ErrCode result = ERR_OK; + ffrt::task_handle handler = notificationSvrQueue_->submit_h( + std::bind([&]() { + ANS_LOGD("ffrt enter!"); + result = NotificationPreferences::GetInstance().SetNotificationSlotFlagsForBundle(bundleOption, slotFlags); + })); + notificationSvrQueue_->wait(handler); + return result; } + ErrCode AdvancedNotificationService::RegisterPushCallback(const sptr &pushCallback) { if (!AccessTokenHelper::IsSystemApp()) { -- Gitee From b01a386af54a16dbb0d27bbc49a490e25bca898c Mon Sep 17 00:00:00 2001 From: leikanglong Date: Tue, 21 Nov 2023 19:12:56 +0800 Subject: [PATCH 29/56] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E6=95=B0=E6=8D=AE=E5=BA=93=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification_preferences_database.h | 2 + .../include/notification_preferences_info.h | 6 +- services/ans/include/preferences_constant.h | 7 +- services/ans/src/notification_preferences.cpp | 7 ++ .../src/notification_preferences_database.cpp | 65 +++---------------- .../ans/src/notification_preferences_info.cpp | 34 ++++------ 6 files changed, 36 insertions(+), 85 deletions(-) diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index afc046043..6fb4819fa 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(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const int32_t &slotFlags) bool PutHasPoppedDialog(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const bool &hasPopped); /** @@ -214,6 +215,7 @@ private: void ParseSlotDescription(sptr &slot, const std::string &value) const; void ParseSlotLevel(sptr &slot, const std::string &value) const; void ParseSlotShowBadge(sptr &slot, const std::string &value) const; + void ParseSlotFlags(sptr &slot, const std::string &value) const; void ParseSlotEnableLight(sptr &slot, const std::string &value) const; void ParseSlotEnableVrbration(sptr &slot, const std::string &value) const; void ParseSlotLedLightColor(sptr &slot, const std::string &value) const; diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 217642dfb..f3c05f6c8 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -66,14 +66,14 @@ public: * * @param name Indicates the bundle slotFlags. */ - void SetSlotFlags(const sptr& slot, const int32_t &slotFlags); + void SetSlotFlags(const int32_t &slotFlags); /** * @brief Get bundle slotFlags. * * @return Return slotFlags. */ - int32_t GetSlotFlags(const sptr& slot) const; + int32_t GetSlotFlags() const; /** * @brief Set bundle Whether to show badge. @@ -206,7 +206,7 @@ public: bool isEnabledNotification_ = BUNDLE_ENABLE_NOTIFICATION; bool hasPoppedDialog_ = BUNDLE_POPPED_DIALOG; std::map> slots_; - std::map slotFlagsMap; + std::map slotFlagsMap; }; /* diff --git a/services/ans/include/preferences_constant.h b/services/ans/include/preferences_constant.h index f1fcf2f66..fd6f3d13c 100644 --- a/services/ans/include/preferences_constant.h +++ b/services/ans/include/preferences_constant.h @@ -60,12 +60,7 @@ enum class BundleType { BUNDLE_ENABLE_NOTIFICATION_TYPE, BUNDLE_ENABLE_NOTIFICATION_USER_OPTION, BUNDLE_POPPED_DIALOG_TYPE, - BUNDLE_SLOTFLGS_SOCIAL_COMMUNICATION_TYPE, //社交通信 - BUNDLE_SLOTFLGS_SERVICE_REMINDER_TYPE, //服务提醒 - BUNDLE_SLOTFLGS_CONTENT_INFORMATION_TYPE, //内容资讯 - BUNDLE_SLOTFLGS_OTHER_TYPE, //其他类型 - BUNDLE_SLOTFLGS_CUSTOM_TYPE, //自定义类型 - BUNDLE_SLOTFLGS_LIVE_VIEW_TYPE, //实况窗类型(仅对系统应用开放) + BUNDLE_SLOTFLGS_TYPE, }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index e9b3fad21..ce6121ce7 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -572,6 +572,10 @@ ErrCode NotificationPreferences::SaveBundleProperty(NotificationPreferencesInfo: bundleInfo.SetHasPoppedDialog(value); storeDBResult = preferncesDB_->PutHasPoppedDialog(bundleInfo, value); break; + case BundleType::BUNDLE_SLOTFLGS_TYPE: + bundleInfo.SetSlotFlags(value); + storeDBResult = preferncesDB_->PutSlotFlags(bundleInfo, value); + break; default: break; } @@ -602,6 +606,9 @@ ErrCode NotificationPreferences::GetBundleProperty( case BundleType::BUNDLE_POPPED_DIALOG_TYPE: value = bundleInfo.GetHasPoppedDialog(); break; + case BundleType::BUNDLE_SLOTFLGS_TYPE: + value = bundleInfo.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 85ae30452..36d30528b 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -171,37 +171,7 @@ const static std::string KEY_SLOT_ENABLED = "enabled"; /** * Indicates whether the type of slot is flags. */ -const static std::string KEY_SLOT_FLAGS = "flags"; - -/** - * Indicates that disturbe key which slot flgs social communication - */ -const static std::string KEY_BUNDLE_SLOTFLGS_SOCIAL_COMMUNICATION_TYPE = "bundleslotflgssocialcommunication"; - -/** - * Indicates that disturbe key which slot flgs servicer eminder type - */ -const static std::string KEY_BUNDLE_SLOTFLGS_SERVICE_REMINDER_TYPE = "bundleslotflgsserviceremindertype"; - -/** - * Indicates that disturbe key which slot flgs content information type - */ -const static std::string KEY_BUNDLE_SLOTFLGS_CONTENT_INFORMATION_TYPE = "bundleslotflgscontentinformationtype"; - -/** - * Indicates that disturbe key which slot flgs other type - */ -const static std::string KEY_BUNDLE_SLOTFLGS_OTHER_TYPE = "bundleslotflgsothertype"; - -/** - * Indicates that disturbe key which slot flgs custom type - */ -const static std::string KEY_BUNDLE_SLOTFLGS_CUSTOM_TYPE = "bundleslotflgscustomtype"; - -/** - * Indicates that disturbe key which slot flgs live view type - */ -const static std::string KEY_BUNDLE_SLOTFLGS_LIVE_VIEW_TYPE = "bundleslotflgsliveviewtype"; +const static std::string KEY_BUNDLE_SLOTFLGS_TYPE = "slotflagstype"; const std::map& slot, const int32_t &slotFlags) +bool NotificationPreferencesDatabase::PutSlotFlags(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const int32_t &slotFlags) { if (!CheckRdbStore()) { ANS_LOGE("RdbStore is nullptr."); return false; } - std::string typeKey = - std::string().append(std::to_string(bundleInfo)).append(KEY_UNDER_LINE).append(KEY_SLOT_FLAGS); - std::string flagsValue = std::to_string(slotFlags); - int32_t result = rdbDataManager_->InsertData(typeKey, flagsValue); + std::string bundleKey = GenerateBundleLablel(bundleInfo); + std::string key= bundleInfo.GetBundleName() + std::to_string(bundleInfo.GetBundleUid()); + int32_t result = rdbDataManager_->InsertData(key, std::to_string(slotFlags)); if (result != NativeRdb::E_OK) { ANS_LOGE("Store flags notification failed. %{public}d", result); return false; @@ -806,23 +774,8 @@ int32_t NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( case BundleType::BUNDLE_POPPED_DIALOG_TYPE: keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_POPPED_DIALOG); break; - case BundleType::BUNDLE_SLOTFLGS_SOCIAL_COMMUNICATION_TYPE: - keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_SOCIAL_COMMUNICATION_TYPE); - break; - case BundleType::BUNDLE_SLOTFLGS_SERVICE_REMINDER_TYPE: - keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_SERVICE_REMINDER_TYPE); - break; - case BundleType::BUNDLE_SLOTFLGS_CONTENT_INFORMATION_TYPE: - keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_CONTENT_INFORMATION_TYPE); - break; - case BundleType::BUNDLE_SLOTFLGS_OTHER_TYPE: - keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_OTHER_TYPE); - break; - case BundleType::BUNDLE_SLOTFLGS_CUSTOM_TYPE: - keyStr = GenerateBundleKey(bundleKey, KEYBUNDLE_SLOTFLGS_CUSTOM_TYPE); - break; - case BundleType::BUNDLE_SLOTFLGS_LIVE_VIEW_TYPE: - keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_LIVE_VIEW_TYPE); + case BundleType::BUNDLE_SLOTFLGS_TYPE: + keyStr = GenerateBundleKey(bundleKey, KEY_BUNDLE_SLOTFLGS_TYPE); break; default: break; @@ -1223,7 +1176,7 @@ void NotificationPreferencesDatabase::ParseSlotFlags(sptr &slo { ANS_LOGD("ParseSlotFlags slot show flags is %{public}s.", value.c_str()); uint32_t slotFlags = static_cast(StringToInt(value)); - slot->setSlotFlags(slotFlags); + //slot->SetSlotFlags(slotFlags); } void NotificationPreferencesDatabase::ParseSlotEnableLight(sptr &slot, const std::string &value) const diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index d686c5174..aca5d87c1 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -98,33 +98,27 @@ bool NotificationPreferencesInfo::BundleInfo::GetSlot( return false; } -void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(const sptr &slot, const int32_t &slotFlags) -{ - if (slotFlagsMap.find(slot->GetType()) == slotFlagsMap.end()) - { - slotFlagsMap.insert_or_assign(slot->GetType(), slotFlags) - } - else - { - for (auto it = slotFlagsMap.begin(); it != slotFlagsMap.end(); ++it) - { - if (it->first.compare(slot->GetType()) == 0) && it->second != slotFlags) - { - it->second = slotflag; +void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(const int32_t &slotFlags) +{ + std::string key= this->GetBundleName() + std::to_string(this->GetBundleUid()); + if (slotFlagsMap.find(key) == slotFlagsMap.end()){ + slotFlagsMap.insert_or_assign(key, slotFlags); + }else{ + for (auto it = slotFlagsMap.begin(); it != slotFlagsMap.end(); ++it){ + if (it->first.compare(key) == 0 && it->second != slotFlags){ + it->second = slotFlags; } } } } -int32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags(const sptr &slot) const +int32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() const { - auto it = slotFlagsMap.find(slot->GetType()) - if(it != slotFlagsMap.end()) - { + std::string key= this->GetBundleName() + std::to_string(this->GetBundleUid()); + auto it = slotFlagsMap.find(key); + if(it != slotFlagsMap.end()){ return it->second; - } - else - { + }else{ return 0; } } -- Gitee From dda04fb917c77bdba11effe1e5bd5a92e925f21b Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Tue, 21 Nov 2023 19:16:41 +0800 Subject: [PATCH 30/56] Fixed compile errors --- services/ans/include/notification_preferences_info.h | 2 +- services/ans/include/preferences_constant.h | 1 + services/ans/src/advanced_notification_service.cpp | 2 -- services/ans/src/notification_preferences_info.cpp | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index aea111aa3..87991da36 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -145,7 +145,7 @@ public: uint32_t GetSlotFlags(); /** - * @brief Get slotflags from bundle. + * @brief Set slotflags from bundle. * * @param slotFlags Indicates slotFlags of bundle. */ diff --git a/services/ans/include/preferences_constant.h b/services/ans/include/preferences_constant.h index 7e3de52ce..0566632dd 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_SLOT_FLAGS, }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index dfd2491c5..dab4510aa 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -4899,8 +4899,6 @@ ErrCode AdvancedNotificationService::GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t slotFlags) { ANS_LOGD("%{public}s", __FUNCTION__); - - sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { ANS_LOGD("BundleOption is null."); return ERR_ANS_INVALID_BUNDLE; diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 233b231db..d721e0c5b 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -135,7 +135,7 @@ uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() return slotFlags_; } -void SetSlotFlags(uint32_t slotFlags) +void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(uint32_t slotFlags) { slotFlags_ = slotFlags; -- Gitee From 089a8edaf51aa50e2d878fee35a8a87f4c98a042 Mon Sep 17 00:00:00 2001 From: leikanglong Date: Tue, 21 Nov 2023 20:08:13 +0800 Subject: [PATCH 31/56] 11 --- services/ans/src/notification_preferences_database.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 36d30528b..2fd629904 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -1175,7 +1175,7 @@ void NotificationPreferencesDatabase::ParseSlotShowBadge(sptr 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)); + uint32_t slotFlags = static_cast(StringToInt(value)); //slot->SetSlotFlags(slotFlags); } -- Gitee From 77904e75c0c8ee3d5b39aec9bcbde6c3606c20ae Mon Sep 17 00:00:00 2001 From: leikanglong Date: Wed, 22 Nov 2023 09:48:00 +0800 Subject: [PATCH 32/56] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E6=95=B0=E6=8D=AE=E5=BA=93=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/ans/include/notification_preferences_database.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index 6fb4819fa..f630d0d59 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -95,7 +95,7 @@ public: * @return Return true on success, false on failure. */ bool PutNotificationsEnabled(const int32_t &userId, const bool &enabled); - bool PutSlotFlags(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const int32_t &slotFlags) + bool PutSlotFlags(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const int32_t &slotFlags); bool PutHasPoppedDialog(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const bool &hasPopped); /** -- Gitee From 13c7fd818a8c2378a456d5f10484cd49638a5130 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Thu, 23 Nov 2023 14:16:53 +0800 Subject: [PATCH 33/56] Fixed errors --- frameworks/ans/src/notification_helper.cpp | 2 +- services/ans/src/notification_preferences_database.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index c3f31c349..41be6e7e2 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -66,7 +66,7 @@ ErrCode NotificationHelper::GetNotificationSlotFlagsAsBundle(const NotificationB return DelayedSingleton::GetInstance()->GetNotificationSlotFlagsAsBundle(bundleOption, slotFlags); } -ErrCode SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags) +ErrCode NotificationHelper::SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags) { return DelayedSingleton::GetInstance()->SetNotificationSlotFlagsAsBundle(bundleOption, slotFlags); } diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 36d30528b..baf8abca9 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -1175,8 +1175,8 @@ void NotificationPreferencesDatabase::ParseSlotShowBadge(sptr 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); + uint32_t slotFlags = static_cast(StringToInt(value)); + slot->SetSlotFlags(slotFlags); } void NotificationPreferencesDatabase::ParseSlotEnableLight(sptr &slot, const std::string &value) const -- Gitee From 48acb27bd6ec45c601c2835e0658b94e1cc5a2ab Mon Sep 17 00:00:00 2001 From: zhushuaiyu Date: Fri, 24 Nov 2023 10:44:43 +0800 Subject: [PATCH 34/56] Fixed Parcel read/write issue --- frameworks/ans/src/notification_slot.cpp | 6 ++++++ interfaces/inner_api/notification_slot.h | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index 94f8cd9df..d61d1b8c6 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -313,6 +313,11 @@ bool NotificationSlot::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteInt32(slotFlags_)) { + ANS_LOGE("Failed to write slotFlags"); + return false; + } + return true; } @@ -342,6 +347,7 @@ bool NotificationSlot::ReadFromParcel(Parcel &parcel) parcel.ReadInt64Vector(&vibrationValues_); enabled_ = parcel.ReadBool(); + slotFlags_ = parcel.ReadInt32(); return true; } diff --git a/interfaces/inner_api/notification_slot.h b/interfaces/inner_api/notification_slot.h index 2e07e7438..d30089ce7 100644 --- a/interfaces/inner_api/notification_slot.h +++ b/interfaces/inner_api/notification_slot.h @@ -363,7 +363,6 @@ private: bool isShowBadge_ {true}; bool isBypassDnd_ {false}; std::string description_ {}; - uint32_t slotFlags_{0}; int32_t lightColor_ {0}; NotificationLevel level_ {LEVEL_DEFAULT}; NotificationConstant::SlotType type_ {}; @@ -371,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 -- Gitee From 543e573842d8d3310539f06e6dab902a9a48e1d1 Mon Sep 17 00:00:00 2001 From: zhushuaiyu Date: Fri, 24 Nov 2023 10:51:58 +0800 Subject: [PATCH 35/56] added missing codes --- frameworks/ans/src/notification_slot.cpp | 11 +++++++++++ interfaces/inner_api/notification_slot.h | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index d61d1b8c6..4139098dd 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -210,6 +210,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{ " @@ -227,6 +237,7 @@ std::string NotificationSlot::Dump() const ", vibration = " + MergeVectorToString(vibrationValues_) + ", isShowBadge = " + (isShowBadge_ ? "true" : "false") + ", enabled = " + (enabled_ ? "true" : "false") + + ", slotFlags = " + std::to_string(static_cast(slotFlags_)) + " }"; } diff --git a/interfaces/inner_api/notification_slot.h b/interfaces/inner_api/notification_slot.h index d30089ce7..6046d2763 100644 --- a/interfaces/inner_api/notification_slot.h +++ b/interfaces/inner_api/notification_slot.h @@ -296,6 +296,22 @@ public: */ bool GetEnable() const; + + /** + * @brief Set slotFlags of slot. + * @note Set slotFlags of slot. + * + * @param slotFlags slotFlags of slot. + */ + void SetSlotFlags(uint32_t slotFlags); + + /** + * @brief Obtains slotFlags of slot. + * + * @return Returns slotFlags of slot. + */ + uint32_t GetSlotFlags() const; + /** * @brief Dumps a string representation of the object. * -- Gitee From 1a2ff651021211c9cb57d57f42a427cc4e431280 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Fri, 24 Nov 2023 11:41:52 +0800 Subject: [PATCH 36/56] Fixed duplicated declare functions --- frameworks/ans/src/notification_slot.cpp | 10 ---------- interfaces/inner_api/notification_slot.h | 16 ---------------- 2 files changed, 26 deletions(-) diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index 4139098dd..202fdcd57 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -84,16 +84,6 @@ void NotificationSlot::SetLevel(NotificationLevel level) level_ = level; } -uint32_t NotificationSlot::GetSlotFlags() const -{ - return slotFlags_; -} - -void NotificationSlot::SetSlotFlags(uint32_t slotFlags) -{ - slotFlags_ = slotFlags; -} - NotificationConstant::SlotType NotificationSlot::GetType() const { return type_; diff --git a/interfaces/inner_api/notification_slot.h b/interfaces/inner_api/notification_slot.h index 6046d2763..d30089ce7 100644 --- a/interfaces/inner_api/notification_slot.h +++ b/interfaces/inner_api/notification_slot.h @@ -296,22 +296,6 @@ public: */ bool GetEnable() const; - - /** - * @brief Set slotFlags of slot. - * @note Set slotFlags of slot. - * - * @param slotFlags slotFlags of slot. - */ - void SetSlotFlags(uint32_t slotFlags); - - /** - * @brief Obtains slotFlags of slot. - * - * @return Returns slotFlags of slot. - */ - uint32_t GetSlotFlags() const; - /** * @brief Dumps a string representation of the object. * -- Gitee From 8b71ee955be4aca3af4f9f233b7f3480beedcc69 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Fri, 24 Nov 2023 16:26:40 +0800 Subject: [PATCH 37/56] Fixed code error --- .../js/napi/include/manager/napi_slot.h | 2 -- frameworks/js/napi/src/slot.cpp | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/frameworks/js/napi/include/manager/napi_slot.h b/frameworks/js/napi/include/manager/napi_slot.h index 9624a75e2..e688dc305 100644 --- a/frameworks/js/napi/include/manager/napi_slot.h +++ b/frameworks/js/napi/include/manager/napi_slot.h @@ -156,14 +156,12 @@ struct AsyncCallbackInfoInfoIsEnableSlot { struct ParametersInfoSetSlotFlagsByBundle { NotificationBundleOption option; - sptr slot; uint32_t slotFlags; napi_ref callback = nullptr; }; struct ParametersInfoGetSlotFlagsByBundle { NotificationBundleOption option; - sptr slot; napi_ref callback = nullptr; }; diff --git a/frameworks/js/napi/src/slot.cpp b/frameworks/js/napi/src/slot.cpp index ecd239e00..8c376fdc1 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -188,7 +188,7 @@ struct AsyncCallbackInfoGetSlotFlagsByBundle { 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; @@ -228,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; @@ -281,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}; @@ -427,7 +430,7 @@ napi_value ParseParametersGetSlotNumByBundle( napi_value ParseParametersSetSlotFlagsByBundle( const napi_env &env, const napi_callback_info &info, ParametersInfoSetSlotFlagsByBundle ¶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}; @@ -457,11 +460,11 @@ napi_value ParseParametersSetSlotFlagsByBundle( // 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)); @@ -469,11 +472,12 @@ napi_value ParseParametersSetSlotFlagsByBundle( 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( @@ -1660,10 +1664,11 @@ napi_value GetSlotFlagsByBundle(napi_env env, napi_callback_info info) napi_value SetSlotFlagsByBundle(napi_env env, napi_callback_info info) { - ANS_LOGI("enter"); + ANS_LOGI("SetSlotFlagsByBundle enter"); ParametersInfoSetSlotFlagsByBundle params {}; if (ParseParametersSetSlotFlagsByBundle(env, info, params) == nullptr) { + ANS_LOGI("Call ParseParametersSetSlotFlagsByBundle return nullptr"); return Common::NapiGetUndefined(env); } @@ -1728,7 +1733,7 @@ napi_value SetSlotFlagsByBundle(napi_env env, napi_callback_info info) } else { return promise; } - + ANS_LOGI("SetSlotFlagsByBundle out"); } } // namespace NotificationNapi -- Gitee From c50c935e52e1a89974fbfd3325ad17a26cfc83df Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Fri, 24 Nov 2023 19:54:02 +0800 Subject: [PATCH 38/56] add missing codes --- frameworks/core/include/ans_manager_stub.h | 9 +++++++++ frameworks/core/src/ans_manager_stub.cpp | 6 ++++++ services/ans/src/notification_preferences.cpp | 2 ++ 3 files changed, 17 insertions(+) diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 8ea8f98b8..1c3cb3ddd 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -686,6 +686,14 @@ public: */ virtual ErrCode SetBadgeNumber(int32_t badgeNumber) override; + /** + * @brief Get slotFlags. + * + * @param badgeNumber The slotFlags. + * @return Returns set slotFlags result. + */ + virtual ErrCode GetSlotFlagsAsBundle(const sptr &bundleOption, uint32_t &slotFlags) override; + /** * @brief Register Push Callback. * @@ -694,6 +702,7 @@ public: */ ErrCode RegisterPushCallback(const sptr& pushCallback) override; + /** * @brief Unregister Push Callback. * diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index fa32221db..f202034ec 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -2006,6 +2006,12 @@ 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::HasNotificationPolicyAccessPermission(bool &granted) { ANS_LOGE("AnsManagerStub::HasNotificationPolicyAccessPermission called!"); diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 086b9901f..50cc44a39 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -280,6 +280,8 @@ ErrCode NotificationPreferences::SetNotificationSlotFlagsForBundle( if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } + + ANS_LOGD("ffrt: SetNotificationSlotFlagsForBundle call SetBundleProperty"); std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_SLOT_FLAGS, soltFlags); -- Gitee From 4fdab62b8b3e0068649975bb990c5717bcb941f3 Mon Sep 17 00:00:00 2001 From: leikanglong Date: Fri, 24 Nov 2023 20:17:56 +0800 Subject: [PATCH 39/56] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/ans/src/notification_preferences.cpp | 11 +++++++++-- .../ans/src/notification_preferences_database.cpp | 7 +++++++ services/ans/src/notification_preferences_info.cpp | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 086b9901f..9640bcca1 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -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("preferencesInfo_: %{public}s", preferencesInfo_.c_str()); } 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 sptrPutNotificationsEnabledForBundle(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; @@ -638,9 +643,11 @@ 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: + ANS_LOGD("Into BUNDLE_SLOTFLGS_TYPE:GetSlotFlags."); value = bundleInfo.GetSlotFlags(); break; default: diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index baf8abca9..d0b0f76ce 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -234,6 +234,7 @@ const std::mapInsertData(key, std::to_string(slotFlags)); + ANS_LOGD("PutSlotFlags:result:. %{public}d", result); if (result != NativeRdb::E_OK) { ANS_LOGE("Store flags notification failed. %{public}d", result); return false; } + ANS_LOGD("PutSlotFlags-3.") return true; } @@ -772,9 +777,11 @@ 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: diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 665adf031..0a042f8de 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -100,6 +100,7 @@ bool NotificationPreferencesInfo::BundleInfo::GetSlot( void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(const int32_t &slotFlags) { + ANS_LOGD("into BundleInfo::SetSlotFlags.") std::string key= this->GetBundleName() + std::to_string(this->GetBundleUid()); if (slotFlagsMap.find(key) == slotFlagsMap.end()){ slotFlagsMap.insert_or_assign(key, slotFlags); @@ -110,10 +111,12 @@ void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(const int32_t &slotFl } } } + ANS_LOGD("out BundleInfo::SetSlotFlags.") } int32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() const { + ANS_LOGD("into BundleInfo::GetSlotFlags.") std::string key= this->GetBundleName() + std::to_string(this->GetBundleUid()); auto it = slotFlagsMap.find(key); if(it != slotFlagsMap.end()){ @@ -121,6 +124,7 @@ int32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() const }else{ return 0; } + ANS_LOGD("out BundleInfo::GetSlotFlags.") } bool NotificationPreferencesInfo::BundleInfo::GetAllSlots(std::vector> &slots) -- Gitee From 647be2ff1f737625973af300a3fa39ce2edf5f2e Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 25 Nov 2023 13:51:49 +0800 Subject: [PATCH 40/56] Fixed bugs --- frameworks/ans/src/notification_helper.cpp | 4 ++-- frameworks/core/src/ans_manager_stub.cpp | 6 +++--- services/ans/src/advanced_notification_service.cpp | 9 +++++++++ services/ans/src/notification_preferences.cpp | 7 ++++--- services/ans/src/notification_preferences_database.cpp | 3 +++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 41be6e7e2..c857d5089 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -63,12 +63,12 @@ ErrCode NotificationHelper::GetNotificationSlotNumAsBundle(const NotificationBun ErrCode NotificationHelper::GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slotFlags) { - return DelayedSingleton::GetInstance()->GetNotificationSlotFlagsAsBundle(bundleOption, slotFlags); + return DelayedSingleton::GetInstance()->GetSlotFlagsAsBundle(bundleOption, slotFlags); } ErrCode NotificationHelper::SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags) { - return DelayedSingleton::GetInstance()->SetNotificationSlotFlagsAsBundle(bundleOption, slotFlags); + return DelayedSingleton::GetInstance()->SetSlotFlagsAsBundle(bundleOption, slotFlags); } ErrCode NotificationHelper::PublishNotification(const NotificationRequest &request) diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index f202034ec..5163c347f 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -259,12 +259,12 @@ const std::map 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; @@ -4904,6 +4906,13 @@ ErrCode AdvancedNotificationService::SetSlotFlagsAsBundle(const 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; diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 50cc44a39..4063b9156 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -281,10 +281,10 @@ ErrCode NotificationPreferences::SetNotificationSlotFlagsForBundle( return ERR_ANS_INVALID_PARAM; } - ANS_LOGD("ffrt: SetNotificationSlotFlagsForBundle call SetBundleProperty"); + ANS_LOGD("NotificationPreferences: SetNotificationSlotFlagsForBundle call SetBundleProperty"); std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; - ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_SLOT_FLAGS, soltFlags); + ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_SLOTFLGS_TYPE, soltFlags); if (result == ERR_OK) { preferencesInfo_ = preferencesInfo; } @@ -575,7 +575,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); @@ -610,6 +610,7 @@ ErrCode NotificationPreferences::SaveBundleProperty(NotificationPreferencesInfo: break; case BundleType::BUNDLE_SLOTFLGS_TYPE: bundleInfo.SetSlotFlags(value); + ANS_LOGD("NotificationPreferences: call PutSlotFlags():"); storeDBResult = preferncesDB_->PutSlotFlags(bundleInfo, value); break; default: diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index baf8abca9..75a82b08a 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -465,11 +465,14 @@ bool NotificationPreferencesDatabase::PutSlotFlags(const NotificationPreferences std::string bundleKey = GenerateBundleLablel(bundleInfo); std::string key= bundleInfo.GetBundleName() + std::to_string(bundleInfo.GetBundleUid()); + ANS_LOGD("NotificationPreferencesDatabase::PutSlotFlags entered, bundleKey=%{public}d, key=%{public}d, slotFlags=%{public}d", bundleKey..c_str(), key.c_str(), slotFlags); int32_t result = rdbDataManager_->InsertData(key, std::to_string(slotFlags)); if (result != NativeRdb::E_OK) { ANS_LOGE("Store flags notification failed. %{public}d", result); return false; } + + ANS_LOGD("NotificationPreferencesDatabase::PutSlotFlags return true out"); return true; } -- Gitee From fd58f9ff7b382273c7d7c2fe27b05654d886641b Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 25 Nov 2023 14:31:53 +0800 Subject: [PATCH 41/56] Fixed bugs --- services/ans/src/advanced_notification_service.cpp | 2 +- services/ans/src/notification_preferences_database.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 410d5179f..830319398 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -4921,7 +4921,7 @@ ErrCode AdvancedNotificationService::SetSlotFlagsAsBundle(const sptrsubmit_h( std::bind([&]() { ANS_LOGD("ffrt enter!"); - result = NotificationPreferences::GetInstance().SetNotificationSlotFlagsForBundle(bundleOption, slotFlags); + result = NotificationPreferences::GetInstance().SetNotificationSlotFlagsForBundle(bundle, slotFlags); })); notificationSvrQueue_->wait(handler); return result; diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 924aee38a..b80bccf00 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -458,16 +458,16 @@ bool NotificationPreferencesDatabase::PutNotificationsEnabled(const int32_t &use bool NotificationPreferencesDatabase::PutSlotFlags(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const int32_t &slotFlags) { - ANS_LOGD("PutSlotFlags-1.") + ANS_LOGD("PutSlotFlags-1."); if (!CheckRdbStore()) { ANS_LOGE("RdbStore is nullptr."); return false; } - ANS_LOGD("PutSlotFlags-2.") + ANS_LOGD("PutSlotFlags-2."); std::string bundleKey = GenerateBundleLablel(bundleInfo); std::string key= bundleInfo.GetBundleName() + std::to_string(bundleInfo.GetBundleUid()); - ANS_LOGD("NotificationPreferencesDatabase::PutSlotFlags entered, bundleKey=%{public}d, key=%{public}d, slotFlags=%{public}d", bundleKey.c_str(), key.c_str(), slotFlags); + ANS_LOGD("NotificationPreferencesDatabase::PutSlotFlags entered, bundleKey=%{public}s, key=%{public}s, slotFlags=%{public}d", bundleKey.c_str(), key.c_str(), slotFlags); int32_t result = rdbDataManager_->InsertData(key, std::to_string(slotFlags)); ANS_LOGD("PutSlotFlags:result:. %{public}d", result); if (result != NativeRdb::E_OK) { -- Gitee From 0f435f7ed63add1ff290fa06b5427673aa963be4 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 25 Nov 2023 16:46:50 +0800 Subject: [PATCH 42/56] Fixed bugs --- .../ans/src/advanced_notification_service.cpp | 14 ++++++++++++- .../src/notification_preferences_database.cpp | 20 +++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 830319398..0521b6a23 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -4906,6 +4906,18 @@ ErrCode AdvancedNotificationService::SetSlotFlagsAsBundle(const sptr bundle = GenerateValidBundleOption(bundleOption); if (bundle == nullptr) { @@ -4920,7 +4932,7 @@ ErrCode AdvancedNotificationService::SetSlotFlagsAsBundle(const sptrsubmit_h( std::bind([&]() { - ANS_LOGD("ffrt enter!"); + ANS_LOGD("SetSlotFlagsAsBundle ffrt enter!"); result = NotificationPreferences::GetInstance().SetNotificationSlotFlagsForBundle(bundle, slotFlags); })); notificationSvrQueue_->wait(handler); diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index b80bccf00..70c25497a 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -168,10 +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 = "BundleSlotflagstype"; + /** * Indicates whether the type of slot is flags. */ -const static std::string KEY_BUNDLE_SLOTFLGS_TYPE = "slotflagstype"; +const static std::string KEY_SLOT_SLOTFLGS_TYPE = "slotflagstype"; const std::map &slo slot->SetSlotFlags(slotFlags); } +void NotificationPreferencesDatabase::ParseBundleSlotFlags(const 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()); -- Gitee From c6a24ea5cdefa2da078f0370a433ad4774efa6fa Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 25 Nov 2023 18:15:37 +0800 Subject: [PATCH 43/56] Fixed bugs --- services/ans/src/notification_preferences.cpp | 8 ++++---- services/ans/src/notification_preferences_database.cpp | 4 ++-- services/ans/src/notification_preferences_info.cpp | 8 ++++---- services/ans/src/notification_rdb_data_mgr.cpp | 1 + 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 5d68600b3..598e80d14 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -62,13 +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.") + ANS_LOGD("add slot to db judge."); return ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; } if (result == ERR_OK) { preferencesInfo_ = preferencesInfo; - ANS_LOGD("preferencesInfo_: %{public}s", preferencesInfo_.c_str()); + ANS_LOGD("AddNotificationSlots return Ok!"); } return result; } @@ -78,7 +78,7 @@ ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptrGetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; } - ANS_LOGD("add slot to db judge.") + ANS_LOGD("add slot to db judge."); std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; NotificationPreferencesInfo::BundleInfo bundleInfo; @@ -89,7 +89,7 @@ ErrCode NotificationPreferences::AddNotificationBundleProperty(const sptr &slo slot->SetSlotFlags(slotFlags); } -void NotificationPreferencesDatabase::ParseBundleSlotFlags(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &value) const +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)); diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 0a042f8de..26faa9df7 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -100,7 +100,7 @@ bool NotificationPreferencesInfo::BundleInfo::GetSlot( void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(const int32_t &slotFlags) { - ANS_LOGD("into BundleInfo::SetSlotFlags.") + ANS_LOGD("into BundleInfo::SetSlotFlags."); std::string key= this->GetBundleName() + std::to_string(this->GetBundleUid()); if (slotFlagsMap.find(key) == slotFlagsMap.end()){ slotFlagsMap.insert_or_assign(key, slotFlags); @@ -111,12 +111,12 @@ void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(const int32_t &slotFl } } } - ANS_LOGD("out BundleInfo::SetSlotFlags.") + ANS_LOGD("out BundleInfo::SetSlotFlags."); } int32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() const { - ANS_LOGD("into BundleInfo::GetSlotFlags.") + ANS_LOGD("into BundleInfo::GetSlotFlags."); std::string key= this->GetBundleName() + std::to_string(this->GetBundleUid()); auto it = slotFlagsMap.find(key); if(it != slotFlagsMap.end()){ @@ -124,7 +124,7 @@ int32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() const }else{ return 0; } - ANS_LOGD("out BundleInfo::GetSlotFlags.") + ANS_LOGD("out BundleInfo::GetSlotFlags."); } bool NotificationPreferencesInfo::BundleInfo::GetAllSlots(std::vector> &slots) diff --git a/services/ans/src/notification_rdb_data_mgr.cpp b/services/ans/src/notification_rdb_data_mgr.cpp index 145b35760..8918add06 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); -- Gitee From 0ec4eae2bc0019db1077c9cdc69ac63e4c076102 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Sat, 25 Nov 2023 18:29:32 +0800 Subject: [PATCH 44/56] Fixed DB write failed --- .../src/notification_preferences_database.cpp | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 6064bc0bc..35f7eb1a0 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -458,6 +458,7 @@ bool NotificationPreferencesDatabase::PutNotificationsEnabled(const int32_t &use std::string typeKey = std::string().append(KEY_ENABLE_ALL_NOTIFICATION).append(KEY_UNDER_LINE).append(std::to_string(userId)); std::string enableValue = std::to_string(enabled); + int32_t result = rdbDataManager_->InsertData(typeKey, enableValue); if (result != NativeRdb::E_OK) { ANS_LOGE("Store enable notification failed. %{public}d", result); @@ -478,15 +479,19 @@ bool NotificationPreferencesDatabase::PutSlotFlags(NotificationPreferencesInfo:: std::string bundleKey = GenerateBundleLablel(bundleInfo); std::string key= bundleInfo.GetBundleName() + std::to_string(bundleInfo.GetBundleUid()); ANS_LOGD("NotificationPreferencesDatabase::PutSlotFlags entered, bundleKey=%{public}s, key=%{public}s, slotFlags=%{public}d", bundleKey.c_str(), key.c_str(), slotFlags); - int32_t result = rdbDataManager_->InsertData(key, std::to_string(slotFlags)); - ANS_LOGD("PutSlotFlags:result:. %{public}d", result); - if (result != NativeRdb::E_OK) { - ANS_LOGE("Store flags notification failed. %{public}d", result); - return false; - } - - ANS_LOGD("NotificationPreferencesDatabase::PutSlotFlags return true out"); - return true; + std::string bundleKey = GenerateBundleLablel(bundleInfo); + int32_t result = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); + return (result == NativeRdb::E_OK); + + // int32_t result = rdbDataManager_->InsertData(key, std::to_string(slotFlags)); + // ANS_LOGD("PutSlotFlags:result:. %{public}d", result); + // if (result != NativeRdb::E_OK) { + // ANS_LOGE("Store flags notification failed. %{public}d", result); + // return false; + // } + + // ANS_LOGD("NotificationPreferencesDatabase::PutSlotFlags return true out"); + // return true; } bool NotificationPreferencesDatabase::PutHasPoppedDialog( -- Gitee From eb182e90fa5605d1a1abdc5666d4b892b3924b3d Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Mon, 27 Nov 2023 10:13:53 +0800 Subject: [PATCH 45/56] Add notification_config_parse and fixed bugs --- .../test/moduletest/ans_fw_module_test.cpp | 6 +- interfaces/inner_api/reminder_request.h | 2 +- services/ans/BUILD.gn | 2 + .../notification_preferences_database.h | 5 +- .../ans/src/notification_config_parse.cpp | 228 ++++++++++++++++++ services/ans/src/notification_config_parse.h | 48 ++++ .../src/notification_preferences_database.cpp | 14 +- 7 files changed, 286 insertions(+), 19 deletions(-) create mode 100644 services/ans/src/notification_config_parse.cpp create mode 100644 services/ans/src/notification_config_parse.h diff --git a/frameworks/test/moduletest/ans_fw_module_test.cpp b/frameworks/test/moduletest/ans_fw_module_test.cpp index c1dd06bbe..799b81eab 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/reminder_request.h b/interfaces/inner_api/reminder_request.h index b96f031e7..464bc8d4a 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 a1a5c4fb5..536609f61 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/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index f630d0d59..85d9dea4b 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -95,7 +95,7 @@ public: * @return Return true on success, false on failure. */ bool PutNotificationsEnabled(const int32_t &userId, const bool &enabled); - bool PutSlotFlags(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const int32_t &slotFlags); + bool PutSlotFlags(NotificationPreferencesInfo::BundleInfo &bundleInfo, const int32_t &slotFlags); bool PutHasPoppedDialog(const NotificationPreferencesInfo::BundleInfo &bundleInfo, const bool &hasPopped); /** @@ -203,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( @@ -215,7 +216,6 @@ private: void ParseSlotDescription(sptr &slot, const std::string &value) const; void ParseSlotLevel(sptr &slot, const std::string &value) const; void ParseSlotShowBadge(sptr &slot, const std::string &value) const; - void ParseSlotFlags(sptr &slot, const std::string &value) const; void ParseSlotEnableLight(sptr &slot, const std::string &value) const; void ParseSlotEnableVrbration(sptr &slot, const std::string &value) const; void ParseSlotLedLightColor(sptr &slot, const std::string &value) const; @@ -224,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/src/notification_config_parse.cpp b/services/ans/src/notification_config_parse.cpp new file mode 100644 index 000000000..e1421c8c6 --- /dev/null +++ b/services/ans/src/notification_config_parse.cpp @@ -0,0 +1,228 @@ +/* + * 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 "ans_log_wrapper.h" +#include "notification_config_parse.h" + +const char* ReminderModeNames[] = {"Ring\0","LockScreen\0", "HangUp\0", "Light\0", "Vibration\0"}; + +const char* SlotTypeNames[] = {"Social_communication\0", "Service_reminder\0", "Content_information\0", "Live_view\0", "Custom_service\0", "Other\0"}; + +const char* SlotTypeCcmNames[] = {"Social_communication", "Service_reminder", "Content_information", "Live_view", "Custom_service", "Other"}; + + +//std::map NotificationConfigFile::slotFlagsMap = {}; +//std::map NotificationConfigFile::slotFlagsCcmMap = {}; + +NotificationConfigFile::NotificationConfigFile() +{ + + +} + + +NotificationConfigFile::NotificationConfigFile(const std::string& filePath) +{ + + +} + +NotificationConfigFile::~NotificationConfigFile() +{ + +} + + + +size_t NotificationConfigFile::get_file_size(const char *filepath) +{ + /*check input para*/ + if(nullptr == filepath) + return 0; + struct stat filestat; + memset(&filestat,0,sizeof(struct stat)); + /*get file information*/ + if(0 == stat(filepath,&filestat)) + return filestat.st_size; + else + return 0; +} + +char * NotificationConfigFile::ReadFileBuffer(const char *filepath) +{ + /*check input para*/ + if(nullptr == filepath) + { + ANS_LOGE("filePath is NULL\n"); + return nullptr; + } + /*get file size*/ + size_t size = get_file_size(filepath); + if(0 == size) + { + return nullptr; + } + + /*malloc memory*/ + char *buf = (char*)malloc(size+1); + if(nullptr == buf) + { + return nullptr; + } + + memset(buf,0,size+1); + + /*read string from file*/ + FILE *fp = fopen(filepath,"r"); + size_t readSize = fread(buf,1,size,fp); + if(readSize != size) + { + /*read error*/ + free(buf); + buf = nullptr; + } + + buf[size] = 0; + return buf; +} + + + +cJSON *NotificationConfigFile::PreParseJsonFile(const char *filePath) +{ + /*check input para*/ + if(nullptr == filePath) + { + ANS_LOGE("input filePath is nullptr\n"); + return nullptr; + } + /*read file content to buffer*/ + char *buf = ReadFileBuffer(filePath); + if(nullptr == buf) + { + ANS_LOGE("read file to buf failed\n"); + return nullptr; + } + /*parse JSON*/ + cJSON *pTemp = cJSON_Parse(buf); + free(buf); + buf = nullptr; + return pTemp; +} + + +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; +} + + +bool NotificationConfigFile::parseNotificationConfigJsonFile(std::string& filePath, std::map& slotFlagsMap) +{ + cJSON *pJson = nullptr; + cJSON *pTemp = nullptr; + cJSON *pVal = nullptr; + int reminderModeValue = 0; + /*Creating cJSON objects*/ + pJson = PreParseJsonFile(filePath.c_str()); + if(nullptr == pJson) + { + ANS_LOGE("parse json failed\n"); + return -1; + } + /*Obtain the number of cJSON arrays*/ + + int num = cJSON_GetArraySize(pJson); + + for(int j=0 ; j < num;j++) + { + uint32_t slotFlags = 0; + pTemp = cJSON_GetObjectItem(pJson,SlotTypeNames[j]); + for(int i =0; i < 5; i++) + { + pVal = cJSON_GetObjectItem(pTemp, ReminderModeNames[i]); + reminderModeValue = pVal->valueint; + if(strcasecmp(ReminderModeNames[i], "Ring\0") == 0 && reminderModeValue == 1) + slotFlags |= ReminderModeFlag::kRMFRing; + else if(strcasecmp(ReminderModeNames[i], "LockScreen\0") == 0 && reminderModeValue == 1) + slotFlags |= ReminderModeFlag::kRMFLockScreen; + else if(strcasecmp(ReminderModeNames[i], "HangUp\0") == 0 && reminderModeValue == 1) + slotFlags |= ReminderModeFlag::kRMFHangUp; + else if(strcasecmp(ReminderModeNames[i], "Light\0") == 0 && reminderModeValue == 1) + slotFlags |= ReminderModeFlag::kRMFLight; + else if(strcasecmp(ReminderModeNames[i], "Vibration\0") == 0 && reminderModeValue == 1) + slotFlags |= ReminderModeFlag::kRMFVibration; + } + ANS_LOGD("Json Got insertMap item slotType = %{public}s, slotFlags = %{public}d\n", SlotTypeNames[j], slotFlags); + slotFlagsMap.insert(std::make_pair(SlotTypeNames[j], slotFlags)); + } + return (slotFlagsMap.size() > 0) ? true : false; +} + +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(), 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; +} diff --git a/services/ans/src/notification_config_parse.h b/services/ans/src/notification_config_parse.h new file mode 100644 index 000000000..6bda23210 --- /dev/null +++ b/services/ans/src/notification_config_parse.h @@ -0,0 +1,48 @@ +/* + * 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 "cJSON.h" +#include +#include +#include "globals.h" +#include "xmlstring.h" + +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 char * ReadFileBuffer(const char *filepath); +static size_t get_file_size(const char *filepath); +static cJSON *PreParseJsonFile(const char *filePath); +static int binaryToDecimal(const char *binaryString); +public: +static bool parseNotificationConfigJsonFile(std::string& filePath, std::map &slotFlagsMap); +static bool parseNotificationConfigCcmFile(std::string& filePath, std::map &slotFlagsMap); +}; + +#endif diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 35f7eb1a0..460908a31 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -477,21 +477,9 @@ bool NotificationPreferencesDatabase::PutSlotFlags(NotificationPreferencesInfo:: ANS_LOGD("PutSlotFlags-2."); std::string bundleKey = GenerateBundleLablel(bundleInfo); - std::string key= bundleInfo.GetBundleName() + std::to_string(bundleInfo.GetBundleUid()); - ANS_LOGD("NotificationPreferencesDatabase::PutSlotFlags entered, bundleKey=%{public}s, key=%{public}s, slotFlags=%{public}d", bundleKey.c_str(), key.c_str(), slotFlags); - 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); - - // int32_t result = rdbDataManager_->InsertData(key, std::to_string(slotFlags)); - // ANS_LOGD("PutSlotFlags:result:. %{public}d", result); - // if (result != NativeRdb::E_OK) { - // ANS_LOGE("Store flags notification failed. %{public}d", result); - // return false; - // } - - // ANS_LOGD("NotificationPreferencesDatabase::PutSlotFlags return true out"); - // return true; } bool NotificationPreferencesDatabase::PutHasPoppedDialog( -- Gitee From 2f7e055ca50751643cd49b38f0fe09fa2d283615 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Mon, 27 Nov 2023 11:31:52 +0800 Subject: [PATCH 46/56] clean code --- bundle.json | 1 + services/ans/BUILD.gn | 2 +- .../notification_config_parse.h | 51 ++-- .../ans/src/notification_config_parse.cpp | 266 ++++++------------ 4 files changed, 110 insertions(+), 210 deletions(-) rename services/ans/{src => include}/notification_config_parse.h (43%) diff --git a/bundle.json b/bundle.json index 9f17e004b..4483576c4 100644 --- a/bundle.json +++ b/bundle.json @@ -84,6 +84,7 @@ ], "third_party": [ "libuv", + "libxml2", "icu" ] }, diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 536609f61..82b8a2ac8 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -44,7 +44,7 @@ ohos_shared_library("libans") { ] sources = [ - "src/notification_config_parse.cpp" + "src/notification_config_parse.cpp", "src/access_token_helper.cpp", "src/advanced_notification_service.cpp", "src/advanced_notification_service_ability.cpp", diff --git a/services/ans/src/notification_config_parse.h b/services/ans/include/notification_config_parse.h similarity index 43% rename from services/ans/src/notification_config_parse.h rename to services/ans/include/notification_config_parse.h index 6bda23210..a9efb6e35 100644 --- a/services/ans/src/notification_config_parse.h +++ b/services/ans/include/notification_config_parse.h @@ -15,34 +15,35 @@ #ifndef NOTIFICATION_CONFIG_FILE_H #define NOTIFICATION_CONFIG_FILE_H -#include "cJSON.h" #include #include -#include "globals.h" -#include "xmlstring.h" -static enum ReminderModeFlag: unsigned int{ - kRMFRing = 0x01, //Ring - kRMFLockScreen = 0x02, //LockScreen - kRMFHangUp = 0x04, //HangUp - kRMFLight = 0x08, //Light - kRMFVibration = 0x10, //Vibration -}ReminderModeFlag; - -class NotificationConfigFile +namespace OHOS { -public: - NotificationConfigFile(); - NotificationConfigFile(const std::string& filePath); - ~NotificationConfigFile(); -private: -static char * ReadFileBuffer(const char *filepath); -static size_t get_file_size(const char *filepath); -static cJSON *PreParseJsonFile(const char *filePath); -static int binaryToDecimal(const char *binaryString); -public: -static bool parseNotificationConfigJsonFile(std::string& filePath, std::map &slotFlagsMap); -static bool parseNotificationConfigCcmFile(std::string& filePath, std::map &slotFlagsMap); -}; + 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 bool getNotificationSlotFlagConfig(std::map &slotFlagsMap) : static bool parseNotificationConfigCcmFile(std::string & filePath, std::map & slotFlagsMap); + }; + } // namespace Notification +} // namespace OHOS #endif diff --git a/services/ans/src/notification_config_parse.cpp b/services/ans/src/notification_config_parse.cpp index e1421c8c6..8634a7cd6 100644 --- a/services/ans/src/notification_config_parse.cpp +++ b/services/ans/src/notification_config_parse.cpp @@ -18,211 +18,109 @@ #include #include #include +#include +#include #include "ans_log_wrapper.h" #include "notification_config_parse.h" -const char* ReminderModeNames[] = {"Ring\0","LockScreen\0", "HangUp\0", "Light\0", "Vibration\0"}; - -const char* SlotTypeNames[] = {"Social_communication\0", "Service_reminder\0", "Content_information\0", "Live_view\0", "Custom_service\0", "Other\0"}; - -const char* SlotTypeCcmNames[] = {"Social_communication", "Service_reminder", "Content_information", "Live_view", "Custom_service", "Other"}; - - -//std::map NotificationConfigFile::slotFlagsMap = {}; -//std::map NotificationConfigFile::slotFlagsCcmMap = {}; - -NotificationConfigFile::NotificationConfigFile() -{ - - -} - - -NotificationConfigFile::NotificationConfigFile(const std::string& filePath) +namespace OHOS { - - -} - -NotificationConfigFile::~NotificationConfigFile() -{ - -} - - - -size_t NotificationConfigFile::get_file_size(const char *filepath) -{ - /*check input para*/ - if(nullptr == filepath) - return 0; - struct stat filestat; - memset(&filestat,0,sizeof(struct stat)); - /*get file information*/ - if(0 == stat(filepath,&filestat)) - return filestat.st_size; - else - return 0; -} - -char * NotificationConfigFile::ReadFileBuffer(const char *filepath) -{ - /*check input para*/ - if(nullptr == filepath) - { - ANS_LOGE("filePath is NULL\n"); - return nullptr; - } - /*get file size*/ - size_t size = get_file_size(filepath); - if(0 == size) - { - return nullptr; - } - - /*malloc memory*/ - char *buf = (char*)malloc(size+1); - if(nullptr == buf) - { - return nullptr; - } - - memset(buf,0,size+1); - - /*read string from file*/ - FILE *fp = fopen(filepath,"r"); - size_t readSize = fread(buf,1,size,fp); - if(readSize != size) - { - /*read error*/ - free(buf); - buf = nullptr; - } - - buf[size] = 0; - return buf; -} - - - -cJSON *NotificationConfigFile::PreParseJsonFile(const char *filePath) -{ - /*check input para*/ - if(nullptr == filePath) - { - ANS_LOGE("input filePath is nullptr\n"); - return nullptr; - } - /*read file content to buffer*/ - char *buf = ReadFileBuffer(filePath); - if(nullptr == buf) + namespace Notification { - ANS_LOGE("read file to buf failed\n"); - return nullptr; - } - /*parse JSON*/ - cJSON *pTemp = cJSON_Parse(buf); - free(buf); - buf = nullptr; - return pTemp; -} + const char *SlotTypeCcmNames[] = {"Social_communication", "Service_reminder", "Content_information", "Live_view", "Custom_service", "Other"}; -int NotificationConfigFile::binaryToDecimal(const char *binaryString) -{ - int lenth = strlen(binaryString); - int decimal = 0; - int weight = 1; + NotificationConfigFile::NotificationConfigFile() + { + } - for(int i = lenth-1; i >= 0; i--) - { - if(binaryString[i] == '1') + NotificationConfigFile::NotificationConfigFile(const std::string &filePath) { - decimal += weight; } - weight *= 2; - } - return decimal; -} + NotificationConfigFile::~NotificationConfigFile() + { + } -bool NotificationConfigFile::parseNotificationConfigJsonFile(std::string& filePath, std::map& slotFlagsMap) -{ - cJSON *pJson = nullptr; - cJSON *pTemp = nullptr; - cJSON *pVal = nullptr; - int reminderModeValue = 0; - /*Creating cJSON objects*/ - pJson = PreParseJsonFile(filePath.c_str()); - if(nullptr == pJson) - { - ANS_LOGE("parse json failed\n"); - return -1; - } - /*Obtain the number of cJSON arrays*/ + int NotificationConfigFile::binaryToDecimal(const char *binaryString) + { + int lenth = strlen(binaryString); + int decimal = 0; + int weight = 1; - int num = cJSON_GetArraySize(pJson); + for (int i = lenth - 1; i >= 0; i--) + { + if (binaryString[i] == '1') + { + decimal += weight; + } + weight *= 2; + } + return decimal; + } - for(int j=0 ; j < num;j++) - { - uint32_t slotFlags = 0; - pTemp = cJSON_GetObjectItem(pJson,SlotTypeNames[j]); - for(int i =0; i < 5; i++) + void NotificationConfigFile::getDefaultSlotFlagsMap(std::map &slotFlagsMap) { - pVal = cJSON_GetObjectItem(pTemp, ReminderModeNames[i]); - reminderModeValue = pVal->valueint; - if(strcasecmp(ReminderModeNames[i], "Ring\0") == 0 && reminderModeValue == 1) - slotFlags |= ReminderModeFlag::kRMFRing; - else if(strcasecmp(ReminderModeNames[i], "LockScreen\0") == 0 && reminderModeValue == 1) - slotFlags |= ReminderModeFlag::kRMFLockScreen; - else if(strcasecmp(ReminderModeNames[i], "HangUp\0") == 0 && reminderModeValue == 1) - slotFlags |= ReminderModeFlag::kRMFHangUp; - else if(strcasecmp(ReminderModeNames[i], "Light\0") == 0 && reminderModeValue == 1) - slotFlags |= ReminderModeFlag::kRMFLight; - else if(strcasecmp(ReminderModeNames[i], "Vibration\0") == 0 && reminderModeValue == 1) - slotFlags |= ReminderModeFlag::kRMFVibration; + slotFlagsMap.insert(std::make_pair(SlotTypeNames[0], 0b11011)); + slotFlagsMap.insert(std::make_pair(SlotTypeNames[1], 0b11111)); + slotFlagsMap.insert(std::make_pair(SlotTypeNames[2], 0b00000)); + slotFlagsMap.insert(std::make_pair(SlotTypeNames[3], 0b10111)); + slotFlagsMap.insert(std::make_pair(SlotTypeNames[4], 0b00000)); + slotFlagsMap.insert(std::make_pair(SlotTypeNames[4], 0b00000)); + ANS_LOGD("Default Got insertMap item slotType = %{public}s, slotFlags = %{public}d\n", SlotTypeNames[j], slotFlags); } - ANS_LOGD("Json Got insertMap item slotType = %{public}s, slotFlags = %{public}d\n", SlotTypeNames[j], slotFlags); - slotFlagsMap.insert(std::make_pair(SlotTypeNames[j], slotFlags)); - } - return (slotFlagsMap.size() > 0) ? true : false; -} -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; - } + 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 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) { - 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++) + std::string subName = reinterpret_cast(curNodePtr->name); + if (strcasecmp(subName.c_str(), "slotType") == 0) { - if(strcasecmp(subNodeName.c_str(), SlotTypeCcmNames[i]) == 0 && strcasecmp(reminderFlagsName.c_str(), "reminderFlags") == 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++) { - 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)); + if (strcasecmp(subNodeName.c_str(), 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; -} + 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); + rturn true; + } + else + { + return parseNotificationConfigCcmFile(filePath, slotFlagsMap); + } + } + } // namespace Notification +} // namespace OHOS -- Gitee From 0c48c8210f14a7826fc0f45165f03a0d5cb81371 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Mon, 27 Nov 2023 12:04:40 +0800 Subject: [PATCH 47/56] Fixed compile errors --- .../ans/include/notification_config_parse.h | 4 +++- .../ans/src/notification_config_parse.cpp | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/services/ans/include/notification_config_parse.h b/services/ans/include/notification_config_parse.h index a9efb6e35..bd428a85f 100644 --- a/services/ans/include/notification_config_parse.h +++ b/services/ans/include/notification_config_parse.h @@ -41,7 +41,9 @@ namespace OHOS static int binaryToDecimal(const char *binaryString); public: - static bool getNotificationSlotFlagConfig(std::map &slotFlagsMap) : static bool parseNotificationConfigCcmFile(std::string & filePath, std::map & slotFlagsMap); + 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 diff --git a/services/ans/src/notification_config_parse.cpp b/services/ans/src/notification_config_parse.cpp index 8634a7cd6..fa22e7e8d 100644 --- a/services/ans/src/notification_config_parse.cpp +++ b/services/ans/src/notification_config_parse.cpp @@ -61,13 +61,16 @@ namespace OHOS void NotificationConfigFile::getDefaultSlotFlagsMap(std::map &slotFlagsMap) { - slotFlagsMap.insert(std::make_pair(SlotTypeNames[0], 0b11011)); - slotFlagsMap.insert(std::make_pair(SlotTypeNames[1], 0b11111)); - slotFlagsMap.insert(std::make_pair(SlotTypeNames[2], 0b00000)); - slotFlagsMap.insert(std::make_pair(SlotTypeNames[3], 0b10111)); - slotFlagsMap.insert(std::make_pair(SlotTypeNames[4], 0b00000)); - slotFlagsMap.insert(std::make_pair(SlotTypeNames[4], 0b00000)); - ANS_LOGD("Default Got insertMap item slotType = %{public}s, slotFlags = %{public}d\n", SlotTypeNames[j], slotFlags); + slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[0], 0b11011)); + slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[1], 0b11111)); + slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[2], 0b00000)); + slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[3], 0b10111)); + slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[4], 0b00000)); + slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[5], 0b00000)); + for (int i = 0; i < 6; i++) + { + ANS_LOGD("Default Got slotFlagsMap item slotType = %{public}s, slotFlags = %{public}d\n", slotFlagsMap[i].first, slotFlagsMap[i].second); + } } bool NotificationConfigFile::parseNotificationConfigCcmFile(std::string &filePath, std::map &slotFlagsMap) @@ -115,7 +118,7 @@ namespace OHOS if (stat(filePath.c_str(), &buffer) != 0) // config file not exist { getDefaultSlotFlagsMap(slotFlagsMap); - rturn true; + return true; } else { -- Gitee From a518438c8cd536f18467a9ce75c2b618a95e3db2 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Mon, 27 Nov 2023 14:30:15 +0800 Subject: [PATCH 48/56] Fixed compiler error --- services/ans/src/notification_config_parse.cpp | 4 ++-- services/ans/src/notification_preferences_database.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/ans/src/notification_config_parse.cpp b/services/ans/src/notification_config_parse.cpp index fa22e7e8d..fc901e80c 100644 --- a/services/ans/src/notification_config_parse.cpp +++ b/services/ans/src/notification_config_parse.cpp @@ -67,9 +67,9 @@ namespace OHOS slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[3], 0b10111)); slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[4], 0b00000)); slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[5], 0b00000)); - for (int i = 0; i < 6; i++) + for (auto &iter : slotFlagsMap) { - ANS_LOGD("Default Got slotFlagsMap item slotType = %{public}s, slotFlags = %{public}d\n", slotFlagsMap[i].first, slotFlagsMap[i].second); + ANS_LOGD("Default Got slotFlagsMap item slotType = %{public}s, slotFlags = %{public}d\n", iter.first.c_str(), iter.second); } } diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 460908a31..4f4037d94 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -171,7 +171,7 @@ const static std::string KEY_SLOT_ENABLED = "enabled"; /** * Indicates whether the type of bungle is flags. */ -const static std::string KEY_BUNDLE_SLOTFLGS_TYPE = "BundleSlotflagstype"; +const static std::string KEY_BUNDLE_SLOTFLGS_TYPE = "bundleSlotflagstype"; /** * Indicates whether the type of slot is flags. -- Gitee From c5900153cee5d0d16a27602433571e5a452e631a Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Mon, 27 Nov 2023 16:31:18 +0800 Subject: [PATCH 49/56] fixed codes --- interfaces/inner_api/notification_constant.h | 2 + .../include/notification_preferences_info.h | 40 ++++++++----- .../ans/src/notification_config_parse.cpp | 18 +++--- .../ans/src/notification_preferences_info.cpp | 59 ++++++++++++++----- 4 files changed, 79 insertions(+), 40 deletions(-) diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index c60b5180d..29eb21227 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/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index ce03e5798..dad6cf5c8 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -61,20 +61,6 @@ public: */ int32_t GetImportance() const; - /** - * @brief Set bundle slotFlags. - * - * @param name Indicates the bundle slotFlags. - */ - void SetSlotFlags(const int32_t &slotFlags); - - /** - * @brief Get bundle slotFlags. - * - * @return Return slotFlags. - */ - int32_t GetSlotFlags() const; - /** * @brief Set bundle Whether to show badge. * @@ -159,12 +145,33 @@ public: uint32_t GetSlotFlags(); /** - * @brief Set slotflags from bundle. + * @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. * @@ -221,7 +228,8 @@ public: bool isEnabledNotification_ = BUNDLE_ENABLE_NOTIFICATION; bool hasPoppedDialog_ = BUNDLE_POPPED_DIALOG; std::map> slots_; - std::map slotFlagsMap; + std::map slotFlagsMap_; + std::map slotFlagsDefaultMap_; }; /* diff --git a/services/ans/src/notification_config_parse.cpp b/services/ans/src/notification_config_parse.cpp index fc901e80c..ccccb0326 100644 --- a/services/ans/src/notification_config_parse.cpp +++ b/services/ans/src/notification_config_parse.cpp @@ -21,15 +21,13 @@ #include #include #include "ans_log_wrapper.h" +#include "notification_constant.h" #include "notification_config_parse.h" namespace OHOS { namespace Notification { - - const char *SlotTypeCcmNames[] = {"Social_communication", "Service_reminder", "Content_information", "Live_view", "Custom_service", "Other"}; - NotificationConfigFile::NotificationConfigFile() { } @@ -61,12 +59,12 @@ namespace OHOS void NotificationConfigFile::getDefaultSlotFlagsMap(std::map &slotFlagsMap) { - slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[0], 0b11011)); - slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[1], 0b11111)); - slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[2], 0b00000)); - slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[3], 0b10111)); - slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[4], 0b00000)); - slotFlagsMap.insert(std::make_pair(SlotTypeCcmNames[5], 0b00000)); + 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); @@ -100,7 +98,7 @@ namespace OHOS std::string reminderFlagsName = reinterpret_cast(subNodePtr->next->name); for (int i = 0; i < 6; i++) { - if (strcasecmp(subNodeName.c_str(), SlotTypeCcmNames[i]) == 0 && strcasecmp(reminderFlagsName.c_str(), "reminderFlags") == 0) + 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); diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 26faa9df7..56ef86273 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ #include "notification_preferences_info.h" +#include "notification_constant.h" +#include "notification_config_parse.h" namespace OHOS { namespace Notification { @@ -98,28 +100,57 @@ bool NotificationPreferencesInfo::BundleInfo::GetSlot( return false; } -void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(const int32_t &slotFlags) +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."); - std::string key= this->GetBundleName() + std::to_string(this->GetBundleUid()); - if (slotFlagsMap.find(key) == slotFlagsMap.end()){ - slotFlagsMap.insert_or_assign(key, 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 != slotFlags){ - it->second = slotFlags; + 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."); + ANS_LOGD("out BundleInfo::SetSlotFlags for specified slot."); } -int32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() const +uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlagsForSlot(const NotificationConstant::SlotType &type) const { ANS_LOGD("into BundleInfo::GetSlotFlags."); - std::string key= this->GetBundleName() + std::to_string(this->GetBundleUid()); - auto it = slotFlagsMap.find(key); - if(it != slotFlagsMap.end()){ + std::string key = GetSlotFlagsKeyFromType(type); + auto it = slotFlagsMap_.find(key); + if(it != slotFlagsMap_.end()){ return it->second; }else{ return 0; @@ -166,7 +197,6 @@ uint32_t NotificationPreferencesInfo::BundleInfo::GetSlotFlags() void NotificationPreferencesInfo::BundleInfo::SetSlotFlags(uint32_t slotFlags) { - slotFlags_ = slotFlags; } @@ -216,6 +246,7 @@ bool NotificationPreferencesInfo::RemoveBundleInfo(const sptr &bundleOption) const { + NotificationConfigFile::getNotificationSlotFlagConfig(NotificationConstant::NOTIFICATION_SLOTFLAG_CONFIG_PATH, slotFlagsDefaultMap_); std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid()); auto iter = infos_.find(bundleKey); if (iter != infos_.end()) { -- Gitee From 3a72979fe5dd8f3e99c227a8f918ebadac43f5a1 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Mon, 27 Nov 2023 17:11:32 +0800 Subject: [PATCH 50/56] Fixed errors --- frameworks/core/src/ans_manager_proxy.cpp | 3 ++- services/ans/include/notification_preferences_info.h | 1 - services/ans/src/notification_preferences_info.cpp | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index d70a4b05f..3bc0a11ec 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -2757,7 +2757,8 @@ ErrCode AnsManagerProxy::SetSlotFlagsAsBundle(const sptr isEnabledAllNotification_; std::map> doNotDisturbDate_; diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 56ef86273..765e0969f 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -19,9 +19,14 @@ 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) { @@ -246,7 +251,6 @@ bool NotificationPreferencesInfo::RemoveBundleInfo(const sptr &bundleOption) const { - NotificationConfigFile::getNotificationSlotFlagConfig(NotificationConstant::NOTIFICATION_SLOTFLAG_CONFIG_PATH, slotFlagsDefaultMap_); std::string bundleKey = bundleOption->GetBundleName() + std::to_string(bundleOption->GetUid()); auto iter = infos_.find(bundleKey); if (iter != infos_.end()) { -- Gitee From 69ef06da8b646ae9e241ce5890b7370b7898c4b6 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Mon, 27 Nov 2023 17:36:57 +0800 Subject: [PATCH 51/56] Fixed bug --- services/ans/src/notification_preferences.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 598e80d14..bc7e7540c 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -264,15 +264,7 @@ ErrCode NotificationPreferences::GetNotificationSlotFlagsForBundle( return ERR_ANS_INVALID_PARAM; } - ErrCode result = ERR_OK; - NotificationPreferencesInfo::BundleInfo bundleInfo; - std::lock_guard lock(preferenceMutex_); - if (preferencesInfo_.GetBundleInfo(bundleOption, bundleInfo)) { - soltFlags = static_cast(bundleInfo.GetSlotFlags()); - } else { - result = ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST; - } - return result; + return GetBundleProperty(bundleOption, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); } @@ -324,6 +316,7 @@ ErrCode NotificationPreferences::GetImportance(const sptr &bundleOption, const int32_t &importance) { -- Gitee From e476ca9d56fd1faede994b00f95b733f55369041 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Mon, 27 Nov 2023 18:20:38 +0800 Subject: [PATCH 52/56] Fixed bugs --- services/ans/include/notification_preferences.h | 8 ++++---- services/ans/src/notification_preferences.cpp | 2 +- services/ans/src/notification_preferences_database.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 31d9ad47c..dec7da69b 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -178,19 +178,19 @@ public: * @brief Get slotFlags in the of bunlde from DB. * * @param bundleOption Indicates bunlde info label. - * @param soltFlags Indicates to setsoltFlags. + * @param slotFlags Indicates to set soltFlags. * @return Return ERR_OK on success, others on failure. */ - ErrCode GetNotificationSlotFlagsForBundle(const sptr &bundleOption, uint32_t &soltFlags); + ErrCode GetNotificationSlotFlagsForBundle(const sptr &bundleOption, uint32_t &slotFlags); /** * @brief Get slotFlags in the of bunlde from DB. * * @param bundleOption Indicates bunlde info label. - * @param soltFlags Indicates to get soltFlags. + * @param slotFlags Indicates to get slotFlags. * @return Return ERR_OK on success, others on failure. */ - ErrCode SetNotificationSlotFlagsForBundle(const sptr &bundleOption, uint32_t soltFlags); + ErrCode SetNotificationSlotFlagsForBundle(const sptr &bundleOption, uint32_t slotFlags); /** * @brief Get private notification enable in the of bunlde from DB. diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index bc7e7540c..025d91f8d 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -258,7 +258,7 @@ ErrCode NotificationPreferences::GetNotificationSlotsNumForBundle( } ErrCode NotificationPreferences::GetNotificationSlotFlagsForBundle( - const sptr &bundleOption, uint32_t &soltFlags) + const sptr &bundleOption, uint32_t &slotFlags) { if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 4f4037d94..485e950e7 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -171,12 +171,12 @@ const static std::string KEY_SLOT_ENABLED = "enabled"; /** * Indicates whether the type of bungle is flags. */ -const static std::string KEY_BUNDLE_SLOTFLGS_TYPE = "bundleSlotflagstype"; +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 = "slotflagstype"; +const static std::string KEY_SLOT_SLOTFLGS_TYPE = "reminderflagstype"; const std::map Date: Tue, 28 Nov 2023 18:54:04 +0800 Subject: [PATCH 53/56] Fixed TDD compiler error --- frameworks/core/include/ans_manager_stub.h | 10 +++++++++- frameworks/core/src/ans_manager_stub.cpp | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 1c3cb3ddd..f61c41bc1 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -690,10 +690,18 @@ public: * @brief Get slotFlags. * * @param badgeNumber The slotFlags. - * @return Returns set slotFlags result. + * @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. * diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 5163c347f..574238f61 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -2012,6 +2012,12 @@ ErrCode AnsManagerStub::GetSlotFlagsAsBundle(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!"); -- Gitee From 07c6fc512fc5b60eb11a6d3ee6cd8d0df6233498 Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Wed, 29 Nov 2023 10:50:44 +0800 Subject: [PATCH 54/56] Clean source code --- .../core/include/ans_manager_interface.h | 5 ++-- frameworks/core/include/ans_manager_proxy.h | 2 +- frameworks/core/include/ans_manager_stub.h | 1 - frameworks/core/include/ans_notification.h | 3 -- frameworks/core/src/ans_manager_stub.cpp | 2 -- frameworks/core/src/ans_notification.cpp | 1 - frameworks/js/napi/include/common.h | 10 +++---- frameworks/js/napi/src/slot.cpp | 26 ++++++++--------- interfaces/inner_api/notification_helper.h | 1 - interfaces/inner_api/notification_slot.h | 2 +- .../include/advanced_notification_service.h | 5 ++-- .../ans/include/notification_config_parse.h | 8 ------ .../ans/include/notification_preferences.h | 1 - .../ans/src/advanced_notification_service.cpp | 1 - .../ans/src/notification_config_parse.cpp | 1 + services/ans/src/notification_preferences.cpp | 12 ++++---- .../src/notification_preferences_database.cpp | 11 ++++---- .../ans/src/notification_preferences_info.cpp | 28 +++++++++---------- 18 files changed, 51 insertions(+), 69 deletions(-) diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index b749ac832..ad5ff9a8f 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -684,7 +684,7 @@ 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. @@ -694,7 +694,7 @@ public: */ 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. @@ -704,7 +704,6 @@ public: */ 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 28582a964..c69143a49 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -671,7 +671,7 @@ public: */ ErrCode SetBadgeNumber(int32_t badgeNumber) override; - /** + /** * @brief Get the slotFlags of slot. * * @param bundleOption Indicates the bundle name and uid of the application. diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index f61c41bc1..b0d8ee5a4 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -710,7 +710,6 @@ public: */ ErrCode RegisterPushCallback(const sptr& pushCallback) override; - /** * @brief Unregister Push Callback. * diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index c8d1608e0..be49c8a6e 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -102,7 +102,6 @@ public: */ ErrCode GetNotificationSlotNumAsBundle(const NotificationBundleOption &bundleOption, uint64_t &num); - /** * @brief Obtains slotFlags of bundle. * @@ -112,8 +111,6 @@ public: */ ErrCode GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slotFlags); - - /** * @brief Set slotFlags of bundle. * diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 574238f61..d90ff8308 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -485,7 +485,6 @@ ErrCode AnsManagerStub::HandleGetSlotNumAsBundle(MessageParcel &data, MessagePar return ERR_OK; } - ErrCode AnsManagerStub::HandleSetSlotFlagsAsBundle(MessageParcel &data, MessageParcel &reply) { sptr bundleOption = data.ReadStrongParcelable(); @@ -532,7 +531,6 @@ ErrCode AnsManagerStub::HandleGetSlotFlagsAsBundle(MessageParcel &data, MessageP return ERR_OK; } - ErrCode AnsManagerStub::HandleGetActiveNotifications(MessageParcel &data, MessageParcel &reply) { std::vector> notifications; diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index d6f713f99..e93fae9fb 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -137,7 +137,6 @@ ErrCode AnsNotification::GetNotificationSlotFlagsAsBundle(const NotificationBund return ansManagerProxy_->GetSlotFlagsAsBundle(bo, slotFlags); } - ErrCode AnsNotification::SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags) { if (bundleOption.GetBundleName().empty()) { diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 3b32f7d66..69013ad96 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -65,11 +65,11 @@ enum class SlotLevel { }; enum ReminderModeFlag: unsigned int { - kRMFRing = 0x01, //振铃 - kRMFLockScreen = 0x02, //锁屏 - kRMFHangUp = 0x04,//横幅通知 - kRMFLight = 0x08,//亮屏 - kRMFVibration = 0x10,//振动 + kRMFRing = 0x01, //Ring + kRMFLockScreen = 0x02, //LockScreen + kRMFHangUp = 0x04, //HangUp + kRMFLight = 0x08, //Light + kRMFVibration = 0x10, //Vibration }; enum class RemoveReason { diff --git a/frameworks/js/napi/src/slot.cpp b/frameworks/js/napi/src/slot.cpp index 8c376fdc1..ac90ef227 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -81,37 +81,37 @@ struct AsyncCallbackInfoGetSlot { sptr slot = nullptr; }; -struct AsyncCallbackInfoGetSlots { +struct ParametersInfoGetSlotNumByBundle { + NotificationBundleOption option; + napi_ref callback = nullptr; +}; + +struct AsyncCallbackInfoGetSlotNumByBundle { napi_env env = nullptr; napi_async_work asyncWork = nullptr; + ParametersInfoGetSlotNumByBundle params; CallbackPromiseInfo info; - std::vector> slots; -}; - -struct ParametersInfoGetSlotsByBundle { - NotificationBundleOption option; - napi_ref callback = nullptr; + uint64_t num = 0; }; -struct AsyncCallbackInfoGetSlotsByBundle { +struct AsyncCallbackInfoGetSlots { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - ParametersInfoGetSlotsByBundle params; CallbackPromiseInfo info; std::vector> slots; }; -struct ParametersInfoGetSlotNumByBundle { +struct ParametersInfoGetSlotsByBundle { NotificationBundleOption option; napi_ref callback = nullptr; }; -struct AsyncCallbackInfoGetSlotNumByBundle { +struct AsyncCallbackInfoGetSlotsByBundle { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - ParametersInfoGetSlotNumByBundle params; + ParametersInfoGetSlotsByBundle params; CallbackPromiseInfo info; - uint64_t num = 0; + std::vector> slots; }; struct ParametersInfoRemoveSlot { diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index ddebc3e1b..281e51673 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -104,7 +104,6 @@ public: */ static ErrCode GetNotificationSlotNumAsBundle(const NotificationBundleOption &bundleOption, uint64_t &num); - /** * @brief Obtains slotflags of bundle. * diff --git a/interfaces/inner_api/notification_slot.h b/interfaces/inner_api/notification_slot.h index d30089ce7..706b61ae7 100644 --- a/interfaces/inner_api/notification_slot.h +++ b/interfaces/inner_api/notification_slot.h @@ -147,7 +147,7 @@ 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. diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 70771440e..050f85709 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -689,8 +689,7 @@ 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. @@ -700,7 +699,7 @@ public: */ 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. diff --git a/services/ans/include/notification_config_parse.h b/services/ans/include/notification_config_parse.h index bd428a85f..89b380908 100644 --- a/services/ans/include/notification_config_parse.h +++ b/services/ans/include/notification_config_parse.h @@ -22,14 +22,6 @@ 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: diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index dec7da69b..b8b3a7d3c 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -173,7 +173,6 @@ public: */ ErrCode SetTotalBadgeNums(const sptr &bundleOption, const int32_t num); - /** * @brief Get slotFlags in the of bunlde from DB. * diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 0521b6a23..1c4663fce 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -4939,7 +4939,6 @@ ErrCode AdvancedNotificationService::SetSlotFlagsAsBundle(const sptr &pushCallback) { if (!AccessTokenHelper::IsSystemApp()) { diff --git a/services/ans/src/notification_config_parse.cpp b/services/ans/src/notification_config_parse.cpp index ccccb0326..9e676fa7e 100644 --- a/services/ans/src/notification_config_parse.cpp +++ b/services/ans/src/notification_config_parse.cpp @@ -20,6 +20,7 @@ #include #include #include +#include "common.h" #include "ans_log_wrapper.h" #include "notification_constant.h" #include "notification_config_parse.h" diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 025d91f8d..4d317a0bf 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" @@ -264,12 +264,14 @@ ErrCode NotificationPreferences::GetNotificationSlotFlagsForBundle( return ERR_ANS_INVALID_PARAM; } - return GetBundleProperty(bundleOption, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); + 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 soltFlags) + const sptr &bundleOption, uint32_t slotFlags) { if (bundleOption == nullptr || bundleOption->GetBundleName().empty()) { return ERR_ANS_INVALID_PARAM; @@ -278,7 +280,7 @@ ErrCode NotificationPreferences::SetNotificationSlotFlagsForBundle( ANS_LOGD("NotificationPreferences: SetNotificationSlotFlagsForBundle call SetBundleProperty"); std::lock_guard lock(preferenceMutex_); NotificationPreferencesInfo preferencesInfo = preferencesInfo_; - ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_SLOTFLGS_TYPE, soltFlags); + ErrCode result = SetBundleProperty(preferencesInfo, bundleOption, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); if (result == ERR_OK) { preferencesInfo_ = preferencesInfo; } @@ -643,8 +645,8 @@ ErrCode NotificationPreferences::GetBundleProperty( value = bundleInfo.GetHasPoppedDialog(); break; case BundleType::BUNDLE_SLOTFLGS_TYPE: - ANS_LOGD("Into BUNDLE_SLOTFLGS_TYPE:GetSlotFlags."); value = bundleInfo.GetSlotFlags(); + ANS_LOGD("Into BUNDLE_SLOTFLGS_TYPE:GetSlotFlags."); break; default: result = ERR_ANS_INVALID_PARAM; diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 485e950e7..ebb468092 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -178,7 +178,6 @@ const static std::string KEY_BUNDLE_SLOTFLGS_TYPE = "bundleReminderflagstype"; */ const static std::string KEY_SLOT_SLOTFLGS_TYPE = "reminderflagstype"; - const std::map &, std::string &)>> NotificationPreferencesDatabase::slotMap_ = { @@ -237,11 +236,11 @@ const std::map Date: Wed, 29 Nov 2023 11:12:59 +0800 Subject: [PATCH 55/56] format code --- .../ans/src/notification_config_parse.cpp | 180 +++++++++--------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/services/ans/src/notification_config_parse.cpp b/services/ans/src/notification_config_parse.cpp index 9e676fa7e..d494526c3 100644 --- a/services/ans/src/notification_config_parse.cpp +++ b/services/ans/src/notification_config_parse.cpp @@ -27,102 +27,102 @@ namespace OHOS { - namespace Notification - { - NotificationConfigFile::NotificationConfigFile() - { - } + namespace Notification + { + NotificationConfigFile::NotificationConfigFile() + { + } - NotificationConfigFile::NotificationConfigFile(const std::string &filePath) - { - } + NotificationConfigFile::NotificationConfigFile(const std::string &filePath) + { + } - NotificationConfigFile::~NotificationConfigFile() - { - } + NotificationConfigFile::~NotificationConfigFile() + { + } - int NotificationConfigFile::binaryToDecimal(const char *binaryString) - { - int lenth = strlen(binaryString); - int decimal = 0; - int weight = 1; + 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; - } + 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); - } - } + 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; - } + 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; - } + 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 + 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 -- Gitee From d0f1528fb692e5222b4129bf2b69103687aa39cb Mon Sep 17 00:00:00 2001 From: hupeixi1 Date: Wed, 29 Nov 2023 11:33:18 +0800 Subject: [PATCH 56/56] remove duplicate define --- frameworks/js/napi/include/common.h | 8 -------- services/ans/include/notification_config_parse.h | 8 ++++++++ services/ans/src/notification_config_parse.cpp | 1 - 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 69013ad96..141a01747 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -64,14 +64,6 @@ enum class SlotLevel { LEVEL_HIGH = 4, }; -enum ReminderModeFlag: unsigned int { - kRMFRing = 0x01, //Ring - kRMFLockScreen = 0x02, //LockScreen - kRMFHangUp = 0x04, //HangUp - kRMFLight = 0x08, //Light - kRMFVibration = 0x10, //Vibration -}; - enum class RemoveReason { CLICK_REASON_REMOVE = 1, CANCEL_REASON_REMOVE = 2, diff --git a/services/ans/include/notification_config_parse.h b/services/ans/include/notification_config_parse.h index 89b380908..bd428a85f 100644 --- a/services/ans/include/notification_config_parse.h +++ b/services/ans/include/notification_config_parse.h @@ -22,6 +22,14 @@ 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: diff --git a/services/ans/src/notification_config_parse.cpp b/services/ans/src/notification_config_parse.cpp index d494526c3..f7a3aae9f 100644 --- a/services/ans/src/notification_config_parse.cpp +++ b/services/ans/src/notification_config_parse.cpp @@ -20,7 +20,6 @@ #include #include #include -#include "common.h" #include "ans_log_wrapper.h" #include "notification_constant.h" #include "notification_config_parse.h" -- Gitee