From e6d35095e9b010dbfcee9ede2b2cf7c6ddd7e156 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Tue, 9 Apr 2024 10:31:59 +0800 Subject: [PATCH] add reminder exclude date Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_helper.cpp | 17 ++ .../core/include/ans_manager_interface.h | 26 ++ frameworks/core/include/ans_manager_proxy.h | 26 ++ frameworks/core/include/ans_manager_stub.h | 29 ++ frameworks/core/include/ans_notification.h | 26 ++ ..._notification_service_ipc_interface_code.h | 3 + .../core/src/ans_manager_proxy_reminder.cpp | 100 +++++++ frameworks/core/src/ans_manager_stub.cpp | 78 ++++++ .../core/src/ans_manager_stub_invalid.cpp | 18 ++ frameworks/core/src/ans_notification.cpp | 27 ++ frameworks/js/napi/include/reminder/publish.h | 27 ++ .../napi/include/reminder/reminder_common.h | 3 + .../src/reminder/native_module_manager.cpp | 3 + frameworks/js/napi/src/reminder/publish.cpp | 258 ++++++++++++++++++ .../js/napi/src/reminder/reminder_common.cpp | 20 ++ interfaces/inner_api/reminder_helper.h | 26 ++ .../include/advanced_notification_service.h | 26 ++ services/ans/include/reminder_data_manager.h | 28 ++ ...advanced_notification_reminder_service.cpp | 57 ++++ services/ans/src/reminder_data_manager.cpp | 18 ++ 20 files changed, 816 insertions(+) diff --git a/frameworks/ans/src/reminder_helper.cpp b/frameworks/ans/src/reminder_helper.cpp index 6b09c8a31..9d83fbd3c 100644 --- a/frameworks/ans/src/reminder_helper.cpp +++ b/frameworks/ans/src/reminder_helper.cpp @@ -59,5 +59,22 @@ ErrCode ReminderHelper::RemoveNotificationSlot(const NotificationConstant::SlotT return DelayedSingleton::GetInstance()->RemoveNotificationSlot(slotType); } +ErrCode ReminderHelper::AddExcludeDate(const int32_t reminderId, const uint64_t time) +{ + ANSR_LOGI("AddExcludeDate start"); + return DelayedSingleton::GetInstance()->AddExcludeDate(reminderId, time); +} + +ErrCode ReminderHelper::DelExcludeDates(const int32_t reminderId) +{ + ANSR_LOGI("DelExcludeDates start"); + return DelayedSingleton::GetInstance()->DelExcludeDates(reminderId); +} + +ErrCode ReminderHelper::GetExcludeDates(const int32_t reminderId, std::vector& times) +{ + ANSR_LOGI("GetExcludeDates start"); + return DelayedSingleton::GetInstance()->GetExcludeDates(reminderId, times); +} } } \ No newline at end of file diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index d2bbabfc1..e04275da7 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -634,6 +634,32 @@ public: */ virtual ErrCode CancelAllReminders() = 0; + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param time exclude date + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t time) = 0; + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode DelExcludeDates(const int32_t reminderId) = 0; + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param times exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& times) = 0; + /** * @brief Checks whether this device is support template. * diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index d5a4586c3..5cefab27d 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -633,6 +633,32 @@ public: */ ErrCode CancelAllReminders() override; + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param time exclude date + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t time) override; + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode DelExcludeDates(const int32_t reminderId) override; + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param times exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetExcludeDates(const int32_t reminderId, std::vector& times) override; + /** * @brief Checks Whether the specified users is allowed to publish notifications. * diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 63edc7881..3e265105c 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -626,6 +626,32 @@ public: */ virtual ErrCode CancelAllReminders() override; + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param time exclude date + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t time) override; + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode DelExcludeDates(const int32_t reminderId) override; + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param times exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& times) override; + /** * @brief Checks whether this device is support template. * @@ -905,6 +931,9 @@ private: ErrCode HandleCancelReminder(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetValidReminders(MessageParcel &data, MessageParcel &reply); ErrCode HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply); + ErrCode HandleAddExcludeDate(MessageParcel &data, MessageParcel &reply); + ErrCode HandleDelExcludeDates(MessageParcel &data, MessageParcel &reply); + ErrCode HandleGetExcludeDates(MessageParcel &data, MessageParcel &reply); ErrCode HandleIsSupportTemplate(MessageParcel &data, MessageParcel &reply); ErrCode HandleIsSpecialUserAllowedNotifyByUser(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetNotificationsEnabledByUser(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 79ea9f112..27648a8b7 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -770,6 +770,32 @@ public: */ ErrCode GetValidReminders(std::vector> &validReminders); + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param time exclude date + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t time); + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode DelExcludeDates(const int32_t reminderId); + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param times exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetExcludeDates(const int32_t reminderId, std::vector& times); + /** * @brief Checks whether this application has permission to publish notifications under the user. * 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 4d7ff350c..980ce7923 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -136,6 +136,9 @@ namespace Notification { GET_DISTRIBUTED_ENABLED_BY_BUNDLE, SET_SMART_REMINDER_ENABLED, GET_SMART_REMINDER_ENABLED, + ADD_EXCLUDE_DATE_REMINDER, + DEL_EXCLUDE_DATES_REMINDER, + GET_EXCLUDE_DATES_REMINDER, }; } } diff --git a/frameworks/core/src/ans_manager_proxy_reminder.cpp b/frameworks/core/src/ans_manager_proxy_reminder.cpp index 5c135d2eb..218a9bc74 100644 --- a/frameworks/core/src/ans_manager_proxy_reminder.cpp +++ b/frameworks/core/src/ans_manager_proxy_reminder.cpp @@ -159,6 +159,106 @@ ErrCode AnsManagerProxy::GetValidReminders(std::vector> &r return result; } +ErrCode AnsManagerProxy::AddExcludeDate(const int32_t reminderId, const uint64_t time) +{ + ANSR_LOGI("[AddExcludeDate]"); + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANSR_LOGE("[AddExcludeDate] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + if (!data.WriteInt32(reminderId)) { + ANSR_LOGE("[AddExcludeDate] fail: write reminder id failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + if (!data.WriteUint64(time)) { + ANSR_LOGE("[AddExcludeDate] fail: write time failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::ADD_EXCLUDE_DATE_REMINDER, option, data, reply); + if (result != ERR_OK) { + ANSR_LOGE("[AddExcludeDate] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + if (!reply.ReadInt32(result)) { + ANSR_LOGE("[AddExcludeDate] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerProxy::DelExcludeDates(const int32_t reminderId) +{ + ANSR_LOGI("[DelExcludeDates]"); + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANSR_LOGE("[DelExcludeDates] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + if (!data.WriteInt32(reminderId)) { + ANSR_LOGE("[DelExcludeDates] fail: write reminder id failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::DEL_EXCLUDE_DATES_REMINDER, option, data, reply); + if (result != ERR_OK) { + ANSR_LOGE("[DelExcludeDates] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + if (!reply.ReadInt32(result)) { + ANSR_LOGE("[DelExcludeDates] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + +ErrCode AnsManagerProxy::GetExcludeDates(const int32_t reminderId, std::vector& times) +{ + ANSR_LOGI("[GetExcludeDates]"); + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANSR_LOGE("[GetExcludeDates] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + if (!data.WriteInt32(reminderId)) { + ANSR_LOGE("[GetExcludeDates] fail: write reminder id failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::GET_EXCLUDE_DATES_REMINDER, option, data, reply); + if (result != ERR_OK) { + ANSR_LOGE("[GetExcludeDates] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + uint8_t count = 0; + if (!reply.ReadUint8(count)) { + ANSR_LOGE("[GetExcludeDates] fail: read exclude time count failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + ANSR_LOGD("[GetExcludeDates] count=%{public}hhu", count); + times.clear(); + for (uint8_t i = 0; i < count; i++) { + uint64_t time = 0; + if (!reply.ReadUint64(time)) { + ANSR_LOGE("Failed to read exclude time"); + return ERR_ANS_PARCELABLE_FAILED; + } + times.push_back(time); + } + if (!reply.ReadInt32(result)) { + ANSR_LOGE("[GetExcludeDates] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + ErrCode AnsManagerProxy::ReadReminders( uint8_t &count, MessageParcel &reply, std::vector> &reminders) { diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index dac790cd6..7251cdc11 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -304,6 +304,15 @@ const std::map times; + ErrCode result = GetExcludeDates(reminderId, times); + ANSR_LOGD("Write back size=%{public}zu", times.size()); + if (!reply.WriteUint8(static_cast(times.size()))) { + ANSR_LOGE("Write back exclude count failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + for (const auto time : times) { + if (!reply.WriteUint64(time)) { + ANSR_LOGW("Write exclude time failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + if (!reply.WriteInt32(result)) { + ANSR_LOGE("Write back result failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + ErrCode AnsManagerStub::HandleIsSupportTemplate(MessageParcel &data, MessageParcel &reply) { std::string templateName; diff --git a/frameworks/core/src/ans_manager_stub_invalid.cpp b/frameworks/core/src/ans_manager_stub_invalid.cpp index 6e3192f01..b4144420d 100644 --- a/frameworks/core/src/ans_manager_stub_invalid.cpp +++ b/frameworks/core/src/ans_manager_stub_invalid.cpp @@ -445,6 +445,24 @@ ErrCode AnsManagerStub::CancelAllReminders() return ERR_INVALID_OPERATION; } +ErrCode AnsManagerStub::AddExcludeDate(const int32_t reminderId, const uint64_t time) +{ + ANS_LOGE("AnsManagerStub::AddExcludeDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DelExcludeDates(const int32_t reminderId) +{ + ANS_LOGE("AnsManagerStub::DelExcludeDates called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetExcludeDates(const int32_t reminderId, std::vector& times) +{ + ANS_LOGE("AnsManagerStub::GetExcludeDates called!"); + return ERR_INVALID_OPERATION; +} + ErrCode AnsManagerStub::IsSupportTemplate(const std::string &templateName, bool &support) { ANS_LOGE("AnsManagerStub::IsSupportTemplate called!"); diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 59a29c8a1..264eb6470 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -1097,6 +1097,33 @@ ErrCode AnsNotification::GetValidReminders(std::vector> &v return ansManagerProxy_->GetValidReminders(validReminders); } +ErrCode AnsNotification::AddExcludeDate(const int32_t reminderId, const uint64_t time) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return ansManagerProxy_->AddExcludeDate(reminderId, time); +} + +ErrCode AnsNotification::DelExcludeDates(const int32_t reminderId) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return ansManagerProxy_->DelExcludeDates(reminderId); +} + +ErrCode AnsNotification::GetExcludeDates(const int32_t reminderId, std::vector& times) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return ansManagerProxy_->GetExcludeDates(reminderId, times); +} + bool AnsNotification::GetAnsManagerProxy() { if (!ansManagerProxy_) { diff --git a/frameworks/js/napi/include/reminder/publish.h b/frameworks/js/napi/include/reminder/publish.h index d8f711229..a875364cd 100644 --- a/frameworks/js/napi/include/reminder/publish.h +++ b/frameworks/js/napi/include/reminder/publish.h @@ -126,6 +126,33 @@ napi_value PublishReminderMgr(napi_env env, napi_callback_info info); * @return opaque pointer that is used to represent a JavaScript value. */ napi_value AddSlotMgr(napi_env env, napi_callback_info info); + +/** + * @brief Add exclude date. + * + * @param env Indicates the context. + * @param info Indicates the opaque datatype about the context. + * @return opaque pointer that is used to represent a JavaScript value. + */ +napi_value AddExcludeDate(napi_env env, napi_callback_info info); + +/** + * @brief Del exclude dates. + * + * @param env Indicates the context. + * @param info Indicates the opaque datatype about the context. + * @return opaque pointer that is used to represent a JavaScript value. + */ +napi_value DelExcludeDates(napi_env env, napi_callback_info info); + +/** + * @brief Get exclude dates. + * + * @param env Indicates the context. + * @param info Indicates the opaque datatype about the context. + * @return opaque pointer that is used to represent a JavaScript value. + */ +napi_value GetExcludeDates(napi_env env, napi_callback_info info); } // namespace ReminderAgentNapi } // namespace OHOS diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index 606dc6c35..0774c1818 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -116,6 +116,9 @@ public: static bool GetObject(const napi_env &env, const napi_value &value, const char* propertyName, napi_value& propertyVal); + static bool GetDate(const napi_env& env, const napi_value& value, + const char* propertyName, double& date); + static void HandleErrCode(const napi_env &env, int32_t errCode); static void ReturnCallbackPromise(const napi_env &env, const CallbackPromiseInfo &info, diff --git a/frameworks/js/napi/src/reminder/native_module_manager.cpp b/frameworks/js/napi/src/reminder/native_module_manager.cpp index 0fc385dbc..876712ba3 100644 --- a/frameworks/js/napi/src/reminder/native_module_manager.cpp +++ b/frameworks/js/napi/src/reminder/native_module_manager.cpp @@ -34,6 +34,9 @@ napi_value ReminderAgentManagerInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("publishReminder", PublishReminderMgr), DECLARE_NAPI_FUNCTION("addNotificationSlot", AddSlotMgr), DECLARE_NAPI_FUNCTION("removeNotificationSlot", NotificationNapi::NapiRemoveSlot), + DECLARE_NAPI_FUNCTION("addExcludeDate", AddExcludeDate), + DECLARE_NAPI_FUNCTION("delExcludeDates", DelExcludeDates), + DECLARE_NAPI_FUNCTION("getExcludeDates", GetExcludeDates), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); return exports; diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 327f9d50b..60bb92800 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -31,6 +31,9 @@ static const int32_t CANCEL_PARAM_LEN = 2; static const int32_t CANCEL_ALL_PARAM_LEN = 1; static const int32_t GET_VALID_PARAM_LEN = 1; static const int32_t ADD_SLOT_PARAM_LEN = 2; +static constexpr int32_t ADD_EXCLUDE_DATE_PARAM_LEN = 2; +static constexpr int32_t DEL_EXCLUDE_DATE_PARAM_LEN = 1; +static constexpr int32_t GET_EXCLUDE_DATE_PARAM_LEN = 1; struct AsyncCallbackInfo { explicit AsyncCallbackInfo(napi_env napiEnv) : env(napiEnv) {} @@ -51,16 +54,19 @@ struct AsyncCallbackInfo { napi_ref callback = nullptr; napi_value result = nullptr; int32_t reminderId = -1; + uint64_t excludeTime = 0; bool isThrow = false; NotificationNapi::NotificationConstant::SlotType inType = NotificationNapi::NotificationConstant::SlotType::CONTENT_INFORMATION; std::shared_ptr reminder = nullptr; std::vector> validReminders; + std::vector excludeTimes; CallbackPromiseInfo info; }; struct Parameters { int32_t reminderId = -1; + uint64_t excludeTime = 0; int32_t errCode = ERR_OK; NotificationNapi::NotificationConstant::SlotType inType = NotificationNapi::NotificationConstant::SlotType::CONTENT_INFORMATION; @@ -1139,5 +1145,257 @@ napi_value AddSlot(napi_env env, napi_callback_info info) { return AddSlotInner(env, info, false); } + +napi_value ParseAddExcludeDateParameter(const napi_env &env, const napi_callback_info &info, Parameters ¶ms, + AsyncCallbackInfo &asyncCallbackInfo) +{ + ANSR_LOGI("ParseAddExcludeDateParameter"); + size_t argc = ADD_EXCLUDE_DATE_PARAM_LEN; + napi_value argv[ADD_EXCLUDE_DATE_PARAM_LEN] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc < ADD_EXCLUDE_DATE_PARAM_LEN) { + ANSR_LOGW("Wrong number of arguments"); + ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); + return nullptr; + } + + // argv[0]: reminder id + int32_t reminderId = -1; + if (!ReminderCommon::GetInt32(env, argv[0], nullptr, reminderId, true)) { + ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); + return nullptr; + } + if (reminderId < 0) { + ANSR_LOGW("Param id of cancels Reminder is illegal."); + ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); + return nullptr; + } + params.reminderId = reminderId; + + // argv[1]: exclude date + double date = 0.0; + if (!ReminderCommon::GetDate(env, argv[0], nullptr, date)) { + ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); + return nullptr; + } + if (date < 0) { + ANSR_LOGW("Param id of cancels Reminder is illegal."); + ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); + return nullptr; + } + params.excludeTime = static_cast(date); + return NotificationNapi::Common::NapiGetNull(env); +} + +napi_value AddExcludeDate(napi_env env, napi_callback_info info) +{ + ANSR_LOGD("Call AddExcludeDate"); + + AsyncCallbackInfo *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfo(env); + if (!asynccallbackinfo) { + ANSR_LOGE("Low memory."); + return NotificationNapi::Common::NapiGetNull(env); + } + std::unique_ptr callbackPtr { asynccallbackinfo }; + + // param + Parameters params; + if (ParseAddExcludeDateParameter(env, info, params, *asynccallbackinfo) == nullptr) { + return DealErrorReturn(env, asynccallbackinfo->callback, NotificationNapi::Common::NapiGetNull(env), isThrow); + } + + // promise + napi_value promise = nullptr; + SetAsynccallbackinfo(env, *asynccallbackinfo, promise); + asynccallbackinfo->reminderId = params.reminderId; + asynccallbackinfo->excludeTime = params.excludeTime; + asynccallbackinfo->isThrow = true; + + // resource name + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "addExcludeDate", NAPI_AUTO_LENGTH, &resourceName); + + // create and queue async work + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANSR_LOGI("Cancel napi_create_async_work start"); + auto asynccallbackinfo = reinterpret_cast(data); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = ReminderHelper::AddExcludeDate(asynccallbackinfo->reminderId, + asynccallbackinfo->excludeTime); + } + }, + [](napi_env env, napi_status status, void *data) { + ANSR_LOGI("Cancel napi_create_async_work complete start"); + auto asynccallbackinfo = reinterpret_cast(data); + std::unique_ptr callbackPtr { asynccallbackinfo }; + + ReminderCommon::ReturnCallbackPromise( + env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env), asynccallbackinfo->isThrow); + ANSR_LOGI("Cancel napi_create_async_work complete end"); + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork)); + callbackPtr.release(); + + if (asynccallbackinfo->info.isCallback) { + return NotificationNapi::Common::NapiGetNull(env); + } else { + return promise; + } + return napi_value(); +} + +napi_value ParseReminderIdParameter(const napi_env &env, const napi_callback_info &info, Parameters ¶ms, + AsyncCallbackInfo &asyncCallbackInfo) +{ + ANSR_LOGI("ParseAddExcludeDateParameter"); + size_t argc = DEL_EXCLUDE_DATE_PARAM_LEN; + napi_value argv[DEL_EXCLUDE_DATE_PARAM_LEN] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + if (argc < DEL_EXCLUDE_DATE_PARAM_LEN) { + ANSR_LOGW("Wrong number of arguments"); + ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); + return nullptr; + } + + // argv[0]: reminder id + int32_t reminderId = -1; + if (!ReminderCommon::GetInt32(env, argv[0], nullptr, reminderId, true)) { + ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); + return nullptr; + } + if (reminderId < 0) { + ANSR_LOGW("Param id of cancels Reminder is illegal."); + ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); + return nullptr; + } + params.reminderId = reminderId; + return NotificationNapi::Common::NapiGetNull(env); +} + +napi_value DelExcludeDates(napi_env env, napi_callback_info info) +{ + ANSR_LOGD("Call DelExcludeDates"); + + AsyncCallbackInfo *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfo(env); + if (!asynccallbackinfo) { + ANSR_LOGE("Low memory."); + return NotificationNapi::Common::NapiGetNull(env); + } + std::unique_ptr callbackPtr { asynccallbackinfo }; + + // param + Parameters params; + if (ParseReminderIdParameter(env, info, params, *asynccallbackinfo) == nullptr) { + return DealErrorReturn(env, asynccallbackinfo->callback, NotificationNapi::Common::NapiGetNull(env), isThrow); + } + + // promise + napi_value promise = nullptr; + SetAsynccallbackinfo(env, *asynccallbackinfo, promise); + asynccallbackinfo->reminderId = params.reminderId; + asynccallbackinfo->isThrow = true; + + // resource name + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "delExcludeDates", NAPI_AUTO_LENGTH, &resourceName); + + // create and queue async work + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANSR_LOGI("Cancel napi_create_async_work start"); + auto asynccallbackinfo = reinterpret_cast(data); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = ReminderHelper::DelExcludeDates(asynccallbackinfo->reminderId); + } + }, + [](napi_env env, napi_status status, void *data) { + ANSR_LOGI("Cancel napi_create_async_work complete start"); + auto asynccallbackinfo = reinterpret_cast(data); + std::unique_ptr callbackPtr { asynccallbackinfo }; + + ReminderCommon::ReturnCallbackPromise( + env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env), asynccallbackinfo->isThrow); + ANSR_LOGI("Cancel napi_create_async_work complete end"); + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork)); + callbackPtr.release(); + + if (asynccallbackinfo->info.isCallback) { + return NotificationNapi::Common::NapiGetNull(env); + } else { + return promise; + } + return napi_value(); +} + +napi_value GetExcludeDates(napi_env env, napi_callback_info info) +{ + ANSR_LOGD("Call AddExcludeDate"); + + AsyncCallbackInfo *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfo(env); + if (!asynccallbackinfo) { + ANSR_LOGE("Low memory."); + return NotificationNapi::Common::NapiGetNull(env); + } + std::unique_ptr callbackPtr { asynccallbackinfo }; + + // param + Parameters params; + if (ParseReminderIdParameter(env, info, params, *asynccallbackinfo) == nullptr) { + return DealErrorReturn(env, asynccallbackinfo->callback, NotificationNapi::Common::NapiGetNull(env), isThrow); + } + + // promise + napi_value promise = nullptr; + SetAsynccallbackinfo(env, *asynccallbackinfo, promise); + asynccallbackinfo->reminderId = params.reminderId; + asynccallbackinfo->isThrow = true; + + // resource name + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "addExcludeDate", NAPI_AUTO_LENGTH, &resourceName); + + // create and queue async work + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANSR_LOGI("Cancel napi_create_async_work start"); + auto asynccallbackinfo = reinterpret_cast(data); + if (asynccallbackinfo) { + asynccallbackinfo->info.errorCode = ReminderHelper::AddExcludeDate(asynccallbackinfo->reminderId, + asynccallbackinfo->excludeTime); + } + }, + [](napi_env env, napi_status status, void *data) { + ANSR_LOGI("Cancel napi_create_async_work complete start"); + auto asynccallbackinfo = reinterpret_cast(data); + std::unique_ptr callbackPtr { asynccallbackinfo }; + + ReminderCommon::ReturnCallbackPromise( + env, asynccallbackinfo->info, NotificationNapi::Common::NapiGetNull(env), asynccallbackinfo->isThrow); + ANSR_LOGI("Cancel napi_create_async_work complete end"); + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork)); + callbackPtr.release(); + + if (asynccallbackinfo->info.isCallback) { + return NotificationNapi::Common::NapiGetNull(env); + } else { + return promise; + } + return napi_value(); +} } } diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 53769e22b..9180dfaba 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -721,6 +721,26 @@ bool ReminderCommon::GetObject(const napi_env &env, const napi_value &value, return true; } +bool ReminderCommon::GetDate(const napi_env& env, const napi_value& value, + const char* propertyName, double& date) +{ + bool hasProperty = false; + NAPI_CALL_BASE(env, napi_has_named_property(env, value, propertyName, &hasProperty), false); + if (!hasProperty) { + return false; + } + napi_value value = nullptr; + napi_get_named_property(env, argv, propertyName, &value); + bool isDate = false; + napi_is_date(env, value, &isDate); + if (!isDate) { + ANS_LOGE("Wrong argument type. Date expected."); + return false; + } + napi_get_date_value(env, value, &date); + return true; +} + napi_value ReminderCommon::CreateReminderTimer( const napi_env &env, const napi_value &value, std::shared_ptr& reminder) { diff --git a/interfaces/inner_api/reminder_helper.h b/interfaces/inner_api/reminder_helper.h index f35bffbaf..8dfccea54 100644 --- a/interfaces/inner_api/reminder_helper.h +++ b/interfaces/inner_api/reminder_helper.h @@ -97,6 +97,32 @@ public: */ static ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType); + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param time exclude date + * @return Returns ERR_OK on success, others on failure. + */ + static ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t time); + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + static ErrCode DelExcludeDates(const int32_t reminderId); + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param times exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + static ErrCode GetExcludeDates(const int32_t reminderId, std::vector& times); + private: static bool CheckPermission(); }; diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 8ba7147fb..e15306671 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -672,6 +672,32 @@ public: */ ErrCode CancelAllReminders() override; + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param time exclude date + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t time) override; + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode DelExcludeDates(const int32_t reminderId) override; + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param times exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetExcludeDates(const int32_t reminderId, std::vector& times) override; + /** * @brief Checks whether this device is support template. * diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index efe301bb5..2309601fb 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -66,6 +66,34 @@ public: */ ErrCode CancelReminder(const int32_t &reminderId, const sptr &bundleOption); + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param time exclude date + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t time, + const sptr &bundleOption); + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode DelExcludeDates(const int32_t reminderId, const sptr &bundleOption); + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param times exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetExcludeDates(const int32_t reminderId, const sptr &bundleOption, + std::vector& times); + /** * @brief Close the target reminder which is showing on panel. * This is manul operation by user: 1.Click close button of the reminder, 2.remove reminder notification. diff --git a/services/ans/src/advanced_notification_reminder_service.cpp b/services/ans/src/advanced_notification_reminder_service.cpp index 7ef5fdcb8..9707718dc 100644 --- a/services/ans/src/advanced_notification_reminder_service.cpp +++ b/services/ans/src/advanced_notification_reminder_service.cpp @@ -166,6 +166,63 @@ ErrCode AdvancedNotificationService::GetValidReminders(std::vector bundleOption = GenerateBundleOption(); + if (bundleOption == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + return rdm->AddExcludeDate(reminderId, time, bundleOption); +} + +ErrCode AdvancedNotificationService::DelExcludeDates(const int32_t reminderId) +{ + ANSR_LOGI("Cancel Reminder"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); + return ERR_REMINDER_PERMISSION_DENIED; + } + + sptr bundleOption = GenerateBundleOption(); + if (bundleOption == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + return rdm->DelExcludeDates(reminderId, bundleOption); +} + +ErrCode AdvancedNotificationService::GetExcludeDates(const int32_t reminderId, std::vector& times) +{ + ANSR_LOGI("Cancel Reminder"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); + return ERR_REMINDER_PERMISSION_DENIED; + } + + sptr bundleOption = GenerateBundleOption(); + if (bundleOption == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + return rdm->GetExcludeDates(reminderId, bundleOption, times); +} + #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED NotificationConstant::RemindType AdvancedNotificationService::GetRemindType() { diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 35b59cb35..1202a3d0c 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -126,6 +126,24 @@ ErrCode ReminderDataManager::CancelAllReminders(const std::string &packageName, return ERR_OK; } +ErrCode ReminderDataManager::AddExcludeDate(const int32_t reminderId, const uint64_t time, + const sptr &bundleOption) +{ + return ERR_OK; +} + +ErrCode ReminderDataManager::DelExcludeDates(const int32_t reminderId, + const sptr &bundleOption) +{ + return ERR_OK; +} + +ErrCode ReminderDataManager::GetExcludeDates(const int32_t reminderId, + const sptr &bundleOption, std::vector& times) +{ + return ERR_OK; +} + void ReminderDataManager::GetValidReminders( const sptr &bundleOption, std::vector> &reminders) { -- Gitee