diff --git a/frameworks/ans/src/reminder_helper.cpp b/frameworks/ans/src/reminder_helper.cpp index 6b09c8a314e7af59c004c30ace41d1492637779e..9d83fbd3c08d82fbe57150dbad5ca4e0d8e20ae9 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 bae81cc15c5d66218e6a1fb753a11953fe650caf..990f90fae1b1753b6aebf41baebfa09a11650921 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -661,6 +661,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 4240d3b9f2af488331320726851fd9d15bb2b405..6227e4de7c20ad7013b33c915acf23e5e16e531f 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -659,6 +659,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 d72bbe8e199408e1a81ecec60629521c835c0e2d..19c9a932af464a440ea86b5f140270c0db14e10b 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -652,6 +652,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. * @@ -951,6 +977,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 4721e3846abdb7cb1147452d36ca0ee7a1533b8e..5ff4a307f62655dfd14cecc219a7cf3f099184f5 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -798,6 +798,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 20c69383788f97b2de1202c82c61b2f11a45b0b4..6ae4f5316c575e1d8ff03110f22a0b9beeeea8dd 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -141,6 +141,9 @@ namespace Notification { ADD_DO_NOTDISTURB_PROFILES, REMOVE_DO_NOT_DISTURB_PROFILES, SET_TARGET_DEVICE_STATUS, + 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 5c135d2ebbcf361dcc05b9b2f047dc2db0fbba57..218a9bc746facddf676359828065763085c45125 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 fc0b674e6a983b38cbec560d6b53cb2ddd02b4d6..7e01e320cde973232cdc4f2a88b73e7d28aeca77 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -319,6 +319,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 d7d030a764d2ae668c054721d918e5381a289438..ba2f693a78aac39c80f5bb43c53c4adc46bffce3 100644 --- a/frameworks/core/src/ans_manager_stub_invalid.cpp +++ b/frameworks/core/src/ans_manager_stub_invalid.cpp @@ -464,6 +464,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 1c61ca55a46417b260fd9e85731cfdde4570a1e6..c1cc43c4deec3c9ee71da6873908aeecf5e24a43 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -1143,6 +1143,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 d8f7112291fd9b9878a5e6f6ed8f2ab777875ee7..a875364cd1655e45b8e7c3223c90b42587f9e932 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 5dd03c5eb46ce565662d6904c89c19d7748053c7..09ba9b97fcb7c550409f727ca411268fb67ea042 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -117,6 +117,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 0fc385dbc636a63ce06bec8e4979c6837ecf60d2..876712ba301de031d5270efb81bae22708ae7344 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 327f9d50b92246b071f8cd4e9e32735003a8e1fd..60bb92800e6edfafa8407501a7dce1d038c7145b 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 bf597dbaf5410142f6f09df9a2375f8cb503efd5..05f519b0064a181e602075bd3dceaef488dd91a5 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 f35bffbafc80776c81418964c152745c6cc26446..8dfccea54064fbdd8b629d7223fa3e2592d1035e 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 e40114266acbe4631ac985f1da51db7096dd523c..a9ae22114d7b3a519a20872288c9a3d81b5cfdf9 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -702,6 +702,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 25ebcd8e80e30bf743165ed9c0755a4bae35f387..acbab52bc51ca19366dad631aa236c68b9fecceb 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 f715edd5e0ea7b52063af9fb046d551ef70766de..67b074f13bf73b4c60c820e7bce54aa19bcfea08 100644 --- a/services/ans/src/advanced_notification_reminder_service.cpp +++ b/services/ans/src/advanced_notification_reminder_service.cpp @@ -168,6 +168,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 8c1561f07903a82dc87724be25e1bf4bf8b44a9d..2eeb09d43f1f940a78864ad32fb27978f0d014c3 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) {