diff --git a/bundle.json b/bundle.json index f87567a63fd810b6c9d8b1e2548012cb9ea08af0..e6e634878ed0af70bd3dcb2a1f856b9aaf24f5d2 100644 --- a/bundle.json +++ b/bundle.json @@ -106,7 +106,8 @@ "//base/notification/distributed_notification_service/frameworks/ans:ans_client", "//base/notification/distributed_notification_service/frameworks/js/napi:napi_notification", "//base/notification/distributed_notification_service/frameworks/js/napi:napi_reminder", - "//base/notification/distributed_notification_service/interfaces/ndk:ohnotification" + "//base/notification/distributed_notification_service/interfaces/ndk:ohnotification", + "//base/notification/distributed_notification_service/frameworks/reminder:reminder_client" ], "service_group": [ "//base/notification/distributed_notification_service/sa_profile:ans_sa_profile", diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 7fa6fe2af0c5e391f1235b473b11101cb3b382f9..0dd044b407923f058568cc6c638c1a426f149e03 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -111,11 +111,6 @@ ohos_shared_library("ans_innerkits") { "${frameworks_module_ans_path}/src/notification_user_input.cpp", "${frameworks_module_ans_path}/src/push_callback_stub.cpp", "${frameworks_module_ans_path}/src/push_promise_callback.cpp", - "${frameworks_module_ans_path}/src/reminder_helper.cpp", - "${frameworks_module_ans_path}/src/reminder_request.cpp", - "${frameworks_module_ans_path}/src/reminder_request_alarm.cpp", - "${frameworks_module_ans_path}/src/reminder_request_calendar.cpp", - "${frameworks_module_ans_path}/src/reminder_request_timer.cpp", ] public_configs = [ ":ans_innerkits_public_config" ] diff --git a/frameworks/ans/src/reminder_helper.cpp b/frameworks/ans/src/reminder_helper.cpp deleted file mode 100644 index 49298a0725ee03697fe820d84bb9069b4532534b..0000000000000000000000000000000000000000 --- a/frameworks/ans/src/reminder_helper.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "reminder_helper.h" - -#include "ans_log_wrapper.h" -#include "ans_notification.h" -#include "notification_helper.h" -#include "singleton.h" - -namespace OHOS { -namespace Notification { -ErrCode ReminderHelper::PublishReminder(ReminderRequest &reminder) -{ - ANSR_LOGI("PublishReminder start"); - NotificationHelper::AddSlotByType(reminder.GetSlotType()); - return DelayedSingleton::GetInstance()->PublishReminder(reminder); -} - -ErrCode ReminderHelper::CancelReminder(const int32_t reminderId) -{ - ANSR_LOGI("CancelReminder start"); - return DelayedSingleton::GetInstance()->CancelReminder(reminderId); -} - -ErrCode ReminderHelper::CancelAllReminders() -{ - ANSR_LOGI("CancelAllReminders start"); - return DelayedSingleton::GetInstance()->CancelAllReminders(); -} - -ErrCode ReminderHelper::GetValidReminders(std::vector> &validReminders) -{ - ANSR_LOGI("GetValidReminders start"); - return DelayedSingleton::GetInstance()->GetValidReminders(validReminders); -} - -ErrCode ReminderHelper::AddNotificationSlot(const NotificationSlot &slot) -{ - ANSR_LOGI("AddNotificationSlot start"); - return DelayedSingleton::GetInstance()->AddNotificationSlot(slot); -} - -ErrCode ReminderHelper::RemoveNotificationSlot(const NotificationConstant::SlotType &slotType) -{ - ANSR_LOGI("RemoveNotificationSlot start"); - return DelayedSingleton::GetInstance()->RemoveNotificationSlot(slotType); -} - -ErrCode ReminderHelper::AddExcludeDate(const int32_t reminderId, const uint64_t date) -{ - ANSR_LOGI("AddExcludeDate start"); - return DelayedSingleton::GetInstance()->AddExcludeDate(reminderId, date); -} - -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& dates) -{ - ANSR_LOGI("GetExcludeDates start"); - return DelayedSingleton::GetInstance()->GetExcludeDates(reminderId, dates); -} -} -} \ No newline at end of file diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp deleted file mode 100644 index 7603993b9ef299d49cd42e0951a1958fb6d39c4c..0000000000000000000000000000000000000000 --- a/frameworks/ans/src/reminder_request.cpp +++ /dev/null @@ -1,1925 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "reminder_request.h" - -#include "ans_const_define.h" -#include "ans_log_wrapper.h" -#include "bundle_mgr_interface.h" -#include "bundle_mgr_proxy.h" -#include "if_system_ability_manager.h" -#include "ipc_skeleton.h" -#include "iservice_registry.h" -#include "locale_config.h" -#include "system_ability_definition.h" -#include "want_agent_helper.h" -#include "nlohmann/json.hpp" -#include "want_params_wrapper.h" - -namespace OHOS { -namespace Notification { -namespace { -const int32_t BASE_YEAR = 1900; -const int32_t SINGLE_BUTTON_INVALID = 0; -const int32_t SINGLE_BUTTON_JSONSTRING = 0; -const int32_t SINGLE_BUTTON_ONLY_ONE = 1; -const int32_t SINGLE_BUTTON_MIN_LEN = 2; -const int32_t SINGLE_BUTTON_MAX_LEN = 4; -const int32_t BUTTON_TYPE_INDEX = 0; -const int32_t BUTTON_TITLE_INDEX = 1; -const int32_t BUTTON_PKG_INDEX = 2; -const int32_t BUTTON_ABILITY_INDEX = 3; -const int32_t WANT_AGENT_URI_INDEX = 2; -const int32_t INDENT = -1; - -const char* const PARAM_EXTRA_KEY = "NotificationRequest_extraInfo"; -} - -int32_t ReminderRequest::GLOBAL_ID = 0; -const uint64_t ReminderRequest::INVALID_LONG_LONG_VALUE = 0; -const uint16_t ReminderRequest::INVALID_U16_VALUE = 0; -const uint16_t ReminderRequest::MILLI_SECONDS = 1000; -const uint16_t ReminderRequest::SAME_TIME_DISTINGUISH_MILLISECONDS = 1000; -const uint32_t ReminderRequest::MIN_TIME_INTERVAL_IN_MILLI = 5 * 60 * 1000; -const uint8_t ReminderRequest::INVALID_U8_VALUE = 0; -const uint8_t ReminderRequest::REMINDER_STATUS_INACTIVE = 0; -const uint8_t ReminderRequest::REMINDER_STATUS_ACTIVE = 1; -const uint8_t ReminderRequest::REMINDER_STATUS_ALERTING = 2; -const uint8_t ReminderRequest::REMINDER_STATUS_SHOWING = 4; -const uint8_t ReminderRequest::REMINDER_STATUS_SNOOZE = 8; -const uint8_t ReminderRequest::TIME_HOUR_OFFSET = 12; -const std::string ReminderRequest::NOTIFICATION_LABEL = "REMINDER_AGENT"; -const std::string ReminderRequest::REMINDER_EVENT_ALARM_ALERT = "ohos.event.notification.reminder.ALARM_ALERT"; -const std::string ReminderRequest::REMINDER_EVENT_CLOSE_ALERT = "ohos.event.notification.reminder.CLOSE_ALERT"; -const std::string ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT = "ohos.event.notification.reminder.SNOOZE_ALERT"; -const std::string ReminderRequest::REMINDER_EVENT_CUSTOM_ALERT = "ohos.event.notification.reminder.COSTUM_ALERT"; -const std::string ReminderRequest::REMINDER_EVENT_CLICK_ALERT = "ohos.event.notification.reminder.CLICK_ALERT"; -const std::string ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT = "ohos.event.notification.reminder.ALERT_TIMEOUT"; -const std::string ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION = - "ohos.event.notification.reminder.REMOVE_NOTIFICATION"; -const std::string ReminderRequest::PARAM_REMINDER_ID = "REMINDER_ID"; -const std::string ReminderRequest::SEP_BUTTON_SINGLE = ""; -const std::string ReminderRequest::SEP_BUTTON_MULTI = ""; -const std::string ReminderRequest::SEP_WANT_AGENT = ""; -const std::string ReminderRequest::SEP_BUTTON_VALUE_TYPE = ""; -const std::string ReminderRequest::SEP_BUTTON_VALUE = ""; -const std::string ReminderRequest::SEP_BUTTON_VALUE_BLOB = ""; -const uint8_t ReminderRequest::DAYS_PER_WEEK = 7; -const uint8_t ReminderRequest::MONDAY = 1; -const uint8_t ReminderRequest::SUNDAY = 7; -const uint8_t ReminderRequest::HOURS_PER_DAY = 24; -const uint16_t ReminderRequest::SECONDS_PER_HOUR = 3600; - -template -void GetJsonValue(const nlohmann::json& root, const std::string& name, T& value) -{ - using ValueType = std::remove_cv_t>; - if constexpr (std::is_same_v) { - if (!root.contains(name) || !root[name].is_string()) { - value = T(); - return; - } - value = root[name].get(); - return; - } - value = T(); -} - -inline static bool IsVaildButtonType(const std::string& type) -{ - // check action button type range - if (type.size() != 1) { - return false; - } - if (type[0] >= '0' && type[0] <= '3') { - return true; - } - return false; -} - -ReminderRequest::ReminderRequest() -{ - InitServerObj(); -} - -ReminderRequest::ReminderRequest(const ReminderRequest &other) -{ - this->content_ = other.content_; - this->expiredContent_ = other.expiredContent_; - this->snoozeContent_ = other.snoozeContent_; - this->displayContent_ = other.displayContent_; - this->title_ = other.title_; - this->isExpired_ = other.isExpired_; - this->isSystemApp_ = other.isSystemApp_; - this->snoozeTimes_ = other.snoozeTimes_; - this->snoozeTimesDynamic_ = other.snoozeTimesDynamic_; - this->state_ = other.state_; - this->notificationId_ = other.notificationId_; - this->reminderId_ = other.reminderId_; - this->reminderTimeInMilli_ = other.reminderTimeInMilli_; - this->ringDurationInMilli_ = other.ringDurationInMilli_; - this->triggerTimeInMilli_ = other.triggerTimeInMilli_; - this->timeIntervalInMilli_ = other.timeIntervalInMilli_; - this->reminderType_ = other.reminderType_; - this->slotType_ = other.slotType_; - this->snoozeSlotType_ = other.snoozeSlotType_; - this->notificationRequest_ = other.notificationRequest_; - this->wantAgentInfo_ = other.wantAgentInfo_; - this->maxScreenWantAgentInfo_ = other.maxScreenWantAgentInfo_; - this->actionButtonMap_ = other.actionButtonMap_; - this->tapDismissed_= other.tapDismissed_; - this->autoDeletedTime_ = other.autoDeletedTime_; - this->customButtonUri_ = other.customButtonUri_; - this->groupId_ = other.groupId_; - this->customRingUri_ = other.customRingUri_; - this->creatorBundleName_ = other.creatorBundleName_; -} - -ReminderRequest::ReminderRequest(int32_t reminderId) -{ - reminderId_ = reminderId; - InitServerObj(); -} - -ReminderRequest::ReminderRequest(ReminderType reminderType) -{ - reminderType_ = reminderType; - InitServerObj(); -} - -bool ReminderRequest::CanRemove() const -{ - if ((state_ & (REMINDER_STATUS_SHOWING | REMINDER_STATUS_ALERTING | REMINDER_STATUS_ACTIVE)) == 0) { - return true; - } - return false; -} - -bool ReminderRequest::CanShow() const -{ - // when system time change by user manually, and the reminde is to show immediately, - // the show reminder just need to be triggered by ReminderDataManager#RefreshRemindersLocked(uint8_t). - // we need to make the REMINDER_EVENT_ALARM_ALERT do nothing. - uint64_t nowInstantMilli = GetNowInstantMilli(); - if (nowInstantMilli == 0) { - return false; - } - if (nowInstantMilli < (GetReminderTimeInMilli() + MIN_TIME_INTERVAL_IN_MILLI)) { - return false; - } - return true; -} - -std::string ReminderRequest::Dump() const -{ - const time_t nextTriggerTime = static_cast(triggerTimeInMilli_ / MILLI_SECONDS); - std::string dateTimeInfo = GetTimeInfoInner(nextTriggerTime, TimeFormat::YMDHMS, true); - return "Reminder[" - "reminderId=" + std::to_string(reminderId_) + - ", type=" + std::to_string(static_cast(reminderType_)) + - ", state=" + GetState(state_) + - ", nextTriggerTime=" + dateTimeInfo.c_str() + - "]"; -} - -ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type, - const std::string &resource, const std::shared_ptr &buttonWantAgent, - const std::shared_ptr &buttonDataShareUpdate) -{ - if ((type != ActionButtonType::CLOSE) && (type != ActionButtonType::SNOOZE) && (type != ActionButtonType::CUSTOM)) { - ANSR_LOGI("Button type is not support: %{public}d.", static_cast(type)); - return *this; - } - ActionButtonInfo actionButtonInfo; - actionButtonInfo.type = type; - actionButtonInfo.title = title; - actionButtonInfo.resource = resource; - actionButtonInfo.wantAgent = buttonWantAgent; - actionButtonInfo.dataShareUpdate = buttonDataShareUpdate; - - actionButtonMap_.insert(std::pair(type, actionButtonInfo)); - return *this; -} - -ReminderRequest& ReminderRequest::SetContent(const std::string &content) -{ - content_ = content; - return *this; -} - -ReminderRequest& ReminderRequest::SetExpiredContent(const std::string &expiredContent) -{ - expiredContent_ = expiredContent; - return *this; -} - -void ReminderRequest::SetExpired(bool isExpired) -{ - isExpired_ = isExpired; -} - -void ReminderRequest::InitCreatorBundleName(const std::string &creatorBundleName) -{ - creatorBundleName_ = creatorBundleName; -} - -void ReminderRequest::InitCreatorUid(const int32_t creatorUid) -{ - creatorUid_ = creatorUid; -} - -void ReminderRequest::InitReminderId() -{ - std::lock_guard lock(std::mutex); - if (GLOBAL_ID < 0) { - ANSR_LOGW("GLOBAL_ID overdule"); - GLOBAL_ID = 0; - } - reminderId_ = ++GLOBAL_ID; - ANSR_LOGI("reminderId_=%{public}d", reminderId_); -} - -void ReminderRequest::InitUserId(const int32_t &userId) -{ - userId_ = userId; -} - -void ReminderRequest::InitUid(const int32_t &uid) -{ - uid_ = uid; -} - -void ReminderRequest::InitBundleName(const std::string &bundleName) -{ - bundleName_ = bundleName; -} - -bool ReminderRequest::IsExpired() const -{ - return isExpired_; -} - -bool ReminderRequest::IsShowing() const -{ - if ((state_ & REMINDER_STATUS_SHOWING) != 0) { - return true; - } - return false; -} - -void ReminderRequest::OnClose(bool updateNext) -{ - if ((state_ & REMINDER_STATUS_SHOWING) == 0) { - ANSR_LOGE("onClose, the state of reminder is incorrect, state:%{public}s", GetState(state_).c_str()); - return; - } - SetState(false, REMINDER_STATUS_SHOWING | REMINDER_STATUS_SNOOZE, "onClose()"); - if ((state_ & REMINDER_STATUS_ALERTING) != 0) { - SetState(false, REMINDER_STATUS_ALERTING, "onClose"); - } - if (updateNext) { - uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false); - if (nextTriggerTime == INVALID_LONG_LONG_VALUE) { - isExpired_ = true; - } else { - SetTriggerTimeInMilli(nextTriggerTime); - snoozeTimesDynamic_ = snoozeTimes_; - } - } -} - -bool ReminderRequest::OnDateTimeChange() -{ - uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false); - return HandleSysTimeChange(triggerTimeInMilli_, nextTriggerTime); -} - -bool ReminderRequest::HandleSysTimeChange(uint64_t oriTriggerTime, uint64_t optTriggerTime) -{ - if (isExpired_) { - return false; - } - uint64_t now = GetNowInstantMilli(); - if (now == 0) { - ANSR_LOGE("get now time failed."); - return false; - } - if (oriTriggerTime == 0 && optTriggerTime < now) { - ANSR_LOGW("trigger time is less than now time."); - return false; - } - bool showImmediately = false; - if (optTriggerTime != INVALID_LONG_LONG_VALUE && (optTriggerTime <= oriTriggerTime || oriTriggerTime == 0)) { - // case1. switch to a previous time - SetTriggerTimeInMilli(optTriggerTime); - snoozeTimesDynamic_ = snoozeTimes_; - } else { - if (oriTriggerTime <= now) { - // case2. switch to a future time, trigger time is less than now time. - // when the reminder show immediately, trigger time will update in onShow function. - snoozeTimesDynamic_ = 0; - showImmediately = true; - } else { - // case3. switch to a future time, trigger time is larger than now time. - showImmediately = false; - } - } - return showImmediately; -} - -bool ReminderRequest::HandleTimeZoneChange( - uint64_t oldZoneTriggerTime, uint64_t newZoneTriggerTime, uint64_t optTriggerTime) -{ - if (isExpired_) { - return false; - } - ANSR_LOGD("Handle timezone change, old:%{public}" PRIu64 ", new:%{public}" PRIu64 "", - oldZoneTriggerTime, newZoneTriggerTime); - if (oldZoneTriggerTime == newZoneTriggerTime) { - return false; - } - bool showImmediately = false; - if (optTriggerTime != INVALID_LONG_LONG_VALUE && oldZoneTriggerTime < newZoneTriggerTime) { - // case1. timezone change to smaller - SetTriggerTimeInMilli(optTriggerTime); - snoozeTimesDynamic_ = snoozeTimes_; - } else { - // case2. timezone change to larger - time_t now; - (void)time(&now); // unit is seconds. - if (static_cast(now) < 0) { - ANSR_LOGE("Get now time error"); - return false; - } - if (newZoneTriggerTime <= GetDurationSinceEpochInMilli(now)) { - snoozeTimesDynamic_ = 0; - showImmediately = true; - } else { - SetTriggerTimeInMilli(newZoneTriggerTime); - showImmediately = false; - } - } - return showImmediately; -} - -void ReminderRequest::OnSameNotificationIdCovered() -{ - SetState(false, REMINDER_STATUS_ALERTING | REMINDER_STATUS_SHOWING | REMINDER_STATUS_SNOOZE, - "OnSameNotificationIdCovered"); -} - -void ReminderRequest::OnShow(bool isPlaySoundOrVibration, bool isSysTimeChanged, bool allowToNotify) -{ - if ((state_ & (REMINDER_STATUS_ACTIVE | REMINDER_STATUS_SNOOZE)) != 0) { - SetState(false, REMINDER_STATUS_ACTIVE | REMINDER_STATUS_SNOOZE, "onShow()"); - } - if (isSysTimeChanged) { - uint64_t nowInstantMilli = GetNowInstantMilli(); - if (nowInstantMilli == 0) { - ANSR_LOGW("Onshow, get now time error"); - } - reminderTimeInMilli_ = nowInstantMilli; - } else { - reminderTimeInMilli_ = triggerTimeInMilli_; - } - UpdateNextReminder(false); - if (allowToNotify) { - SetState(true, REMINDER_STATUS_SHOWING, "OnShow"); - if (isPlaySoundOrVibration) { - SetState(true, REMINDER_STATUS_ALERTING, "OnShow"); - } - UpdateNotificationStateForAlert(); - } -} - -void ReminderRequest::OnShowFail() -{ - SetState(false, REMINDER_STATUS_SHOWING, "OnShowFailed()"); -} - -bool ReminderRequest::OnSnooze() -{ - if ((state_ & REMINDER_STATUS_SNOOZE) != 0) { - ANSR_LOGW("onSnooze, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str()); - return false; - } - if ((state_ & REMINDER_STATUS_ALERTING) != 0) { - SetState(false, REMINDER_STATUS_ALERTING, "onSnooze()"); - } - SetSnoozeTimesDynamic(GetSnoozeTimes()); - if (!UpdateNextReminder(true)) { - return false; - } - UpdateNotificationStateForSnooze(); - if (timeIntervalInMilli_ > 0) { - SetState(true, REMINDER_STATUS_SNOOZE, "onSnooze()"); - } - return true; -} - -void ReminderRequest::OnStart() -{ - if ((state_ & REMINDER_STATUS_ACTIVE) != 0) { - ANSR_LOGE( - "start failed, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str()); - return; - } - if (isExpired_) { - ANSR_LOGE("start failed, the reminder is expired"); - return; - } - SetState(true, REMINDER_STATUS_ACTIVE, "OnStart()"); -} - -void ReminderRequest::OnStop() -{ - ANSR_LOGI("Stop the previous active reminder, %{public}s", this->Dump().c_str()); - if ((state_ & REMINDER_STATUS_ACTIVE) == 0) { - ANSR_LOGW("onStop, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str()); - return; - } - SetState(false, REMINDER_STATUS_ACTIVE, "OnStop"); -} - -bool ReminderRequest::OnTerminate() -{ - if ((state_ & REMINDER_STATUS_ALERTING) == 0) { - ANSR_LOGW("onTerminate, the state of reminder is %{public}s", (GetState(state_)).c_str()); - return false; - } - SetState(false, REMINDER_STATUS_ALERTING, "onTerminate"); - UpdateNotificationStateForAlert(); - return true; -} - -bool ReminderRequest::OnTimeZoneChange() -{ - time_t oldZoneTriggerTime = static_cast(triggerTimeInMilli_ / MILLI_SECONDS); - struct tm *localOriTime = localtime(&oldZoneTriggerTime); - if (localOriTime == nullptr) { - ANSR_LOGE("oldZoneTriggerTime is null"); - return false; - } - time_t newZoneTriggerTime = mktime(localOriTime); - uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false); - return HandleTimeZoneChange( - triggerTimeInMilli_, GetDurationSinceEpochInMilli(newZoneTriggerTime), nextTriggerTime); -} - -void ReminderRequest::RecoverActionButtonJsonMode(const std::string &jsonString) -{ - if (!nlohmann::json::accept(jsonString)) { - ANSR_LOGW("not a json string!"); - return; - } - nlohmann::json root = nlohmann::json::parse(jsonString, nullptr, false); - if (root.is_discarded()) { - ANSR_LOGW("parse json data failed!"); - return; - } - std::string type; - GetJsonValue(root, "type", type); - if (!IsVaildButtonType(type)) { - ANSR_LOGW("unkown button type!"); - return; - } - std::string title; - GetJsonValue(root, "title", title); - std::string resource; - GetJsonValue(root, "resource", resource); - auto buttonWantAgent = std::make_shared(); - if (root.contains("wantAgent") && !root["wantAgent"].empty()) { - nlohmann::json wantAgent = root["wantAgent"]; - GetJsonValue(wantAgent, "pkgName", buttonWantAgent->pkgName); - GetJsonValue(wantAgent, "abilityName", buttonWantAgent->abilityName); - } - auto buttonDataShareUpdate = std::make_shared(); - if (root.contains("dataShareUpdate") && !root["dataShareUpdate"].empty()) { - nlohmann::json dataShareUpdate = root["dataShareUpdate"]; - GetJsonValue(dataShareUpdate, "uri", buttonDataShareUpdate->uri); - GetJsonValue(dataShareUpdate, "equalTo", buttonDataShareUpdate->equalTo); - GetJsonValue(dataShareUpdate, "valuesBucket", buttonDataShareUpdate->valuesBucket); - } - SetActionButton(title, ActionButtonType(std::stoi(type, nullptr)), - resource, buttonWantAgent, buttonDataShareUpdate); -} - -void ReminderRequest::DeserializeButtonInfo(const std::string& buttonInfoStr) -{ - std::vector multiButton = StringSplit(buttonInfoStr, SEP_BUTTON_MULTI); - for (auto button : multiButton) { - std::vector singleButton = StringSplit(button, SEP_BUTTON_SINGLE); - if (singleButton.size() <= SINGLE_BUTTON_INVALID) { - ANSR_LOGW("RecoverButton fail"); - return; - } - if (singleButton.size() == SINGLE_BUTTON_ONLY_ONE) { - std::string jsonString = singleButton.at(SINGLE_BUTTON_JSONSTRING); - RecoverActionButtonJsonMode(jsonString); - continue; - } - // old method Soon to be deleted - if (singleButton.size() < SINGLE_BUTTON_MIN_LEN) { - ANSR_LOGW("RecoverButton fail"); - return; - } - auto buttonWantAgent = std::make_shared(); - if (singleButton.size() == SINGLE_BUTTON_MAX_LEN) { - buttonWantAgent->pkgName = singleButton.at(BUTTON_PKG_INDEX); - buttonWantAgent->abilityName = singleButton.at(BUTTON_ABILITY_INDEX); - } - std::string resource = ""; - auto buttonDataShareUpdate = std::make_shared(); - SetActionButton(singleButton.at(BUTTON_TITLE_INDEX), - ActionButtonType(std::atoi(singleButton.at(BUTTON_TYPE_INDEX).c_str())), - resource, buttonWantAgent, buttonDataShareUpdate); - ANSR_LOGI("RecoverButton title:%{public}s, pkgName:%{public}s, abilityName:%{public}s", - singleButton.at(BUTTON_TITLE_INDEX).c_str(), buttonWantAgent->pkgName.c_str(), - buttonWantAgent->abilityName.c_str()); - } -} - -std::vector ReminderRequest::StringSplit(std::string source, const std::string &split) -{ - std::vector result; - if (source.empty()) { - return result; - } - size_t pos = 0; - while ((pos = source.find(split)) != std::string::npos) { - std::string token = source.substr(0, pos); - if (!token.empty()) { - result.push_back(token); - } - source.erase(0, pos + split.length()); - } - if (!source.empty()) { - result.push_back(source); - } - return result; -} - -void ReminderRequest::RecoverWantAgentByJson(const std::string& wantAgentInfo, const uint8_t& type) -{ - nlohmann::json root = nlohmann::json::parse(wantAgentInfo, nullptr, false); - if (root.is_discarded()) { - ANSR_LOGW("parse json data failed"); - return; - } - if (!root.contains("pkgName") || !root["pkgName"].is_string() || - !root.contains("abilityName") || !root["abilityName"].is_string() || - !root.contains("uri") || !root["uri"].is_string() || - !root.contains("parameters") || !root["parameters"].is_string()) { - return; - } - - std::string pkgName = root.at("pkgName").get(); - std::string abilityName = root.at("abilityName").get(); - std::string uri = root.at("uri").get(); - std::string parameters = root.at("parameters").get(); - switch (type) { - case WANT_AGENT_FLAG: { - auto wai = std::make_shared(); - wai->pkgName = pkgName; - wai->abilityName = abilityName; - wai->uri = uri; - wai->parameters = AAFwk::WantParamWrapper::ParseWantParams(parameters); - SetWantAgentInfo(wai); - break; - } - case MAX_WANT_AGENT_FLAG: { - auto maxScreenWantAgentInfo = std::make_shared(); - maxScreenWantAgentInfo->pkgName = pkgName; - maxScreenWantAgentInfo->abilityName = abilityName; - SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); - break; - } - default: { - ANSR_LOGW("RecoverWantAgent type not support"); - break; - } - } -} - -void ReminderRequest::DeserializeWantAgent(const std::string &wantAgentInfo, const uint8_t type) -{ - if (nlohmann::json::accept(wantAgentInfo)) { - RecoverWantAgentByJson(wantAgentInfo, type); - return; - } - std::vector info = StringSplit(wantAgentInfo, ReminderRequest::SEP_WANT_AGENT); - uint8_t minLen = 2; - if (info.size() < minLen) { - ANSR_LOGW("RecoverWantAgent fail"); - return; - } - ANSR_LOGD("pkg=%{public}s, ability=%{public}s", info.at(0).c_str(), info.at(1).c_str()); - switch (type) { - case 0: { - auto wai = std::make_shared(); - wai->pkgName = info.at(0); - wai->abilityName = info.at(1); - if (info.size() > minLen) { - wai->uri = info.at(WANT_AGENT_URI_INDEX); - } - SetWantAgentInfo(wai); - break; - } - case 1: { - auto maxScreenWantAgentInfo = std::make_shared(); - maxScreenWantAgentInfo->pkgName = info.at(0); - maxScreenWantAgentInfo->abilityName = info.at(1); - SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); - break; - } - default: { - ANSR_LOGW("RecoverWantAgent type not support"); - break; - } - } -} - -ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo( - const std::shared_ptr &maxScreenWantAgentInfo) -{ - maxScreenWantAgentInfo_ = maxScreenWantAgentInfo; - return *this; -} - -ReminderRequest& ReminderRequest::SetNotificationId(int32_t notificationId) -{ - notificationId_ = notificationId; - return *this; -} - -ReminderRequest& ReminderRequest::SetGroupId(const std::string &groupId) -{ - groupId_ = groupId; - return *this; -} - -ReminderRequest& ReminderRequest::SetSlotType(const NotificationConstant::SlotType &slotType) -{ - slotType_ = slotType; - return *this; -} - -ReminderRequest& ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType) -{ - snoozeSlotType_ = snoozeSlotType; - return *this; -} - -ReminderRequest& ReminderRequest::SetSnoozeContent(const std::string &snoozeContent) -{ - snoozeContent_ = snoozeContent; - return *this; -} - -ReminderRequest& ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes) -{ - snoozeTimes_ = snoozeTimes; - SetSnoozeTimesDynamic(snoozeTimes); - return *this; -} - -ReminderRequest& ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes) -{ - snoozeTimesDynamic_ = snooziTimes; - return *this; -} - -ReminderRequest& ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds) -{ - if (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS)) { - ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range"); - timeIntervalInMilli_ = 0; - } else { - uint64_t timeIntervalInMilli = timeIntervalInSeconds * MILLI_SECONDS; - if (timeIntervalInMilli > 0 && timeIntervalInMilli < MIN_TIME_INTERVAL_IN_MILLI) { - ANSR_LOGW("SetTimeInterval, replace to set %{public}u, for the given is 0<%{public}" PRIu64 "<%{public}u", - MIN_TIME_INTERVAL_IN_MILLI / MILLI_SECONDS, timeIntervalInSeconds, - MIN_TIME_INTERVAL_IN_MILLI / MILLI_SECONDS); - timeIntervalInMilli_ = MIN_TIME_INTERVAL_IN_MILLI; - } else { - timeIntervalInMilli_ = timeIntervalInMilli; - } - } - return *this; -} - -ReminderRequest& ReminderRequest::SetTitle(const std::string &title) -{ - title_ = title; - return *this; -} - -void ReminderRequest::SetTriggerTimeInMilli(uint64_t triggerTimeInMilli) -{ - triggerTimeInMilli_ = triggerTimeInMilli; -} - -ReminderRequest& ReminderRequest::SetWantAgentInfo(const std::shared_ptr &wantAgentInfo) -{ - if (wantAgentInfo != nullptr) { - wantAgentInfo_ = wantAgentInfo; - } - return *this; -} - -bool ReminderRequest::ShouldShowImmediately() const -{ - uint64_t nowInstantMilli = GetNowInstantMilli(); - if (nowInstantMilli == 0) { - return false; - } - if (triggerTimeInMilli_ > nowInstantMilli) { - return false; - } - return true; -} - -std::map ReminderRequest::GetActionButtons( - ) const -{ - return actionButtonMap_; -} - -std::string ReminderRequest::GetCreatorBundleName() const -{ - return creatorBundleName_; -} - -int32_t ReminderRequest::GetCreatorUid() const -{ - return creatorUid_; -} - -std::string ReminderRequest::GetContent() const -{ - return content_; -} - -std::string ReminderRequest::GetExpiredContent() const -{ - return expiredContent_; -} - -std::shared_ptr ReminderRequest::GetMaxScreenWantAgentInfo() const -{ - return maxScreenWantAgentInfo_; -} - -int32_t ReminderRequest::GetNotificationId() const -{ - return notificationId_; -} - -std::string ReminderRequest::GetGroupId() const -{ - return groupId_; -} - -sptr ReminderRequest::GetNotificationRequest() const -{ - return notificationRequest_; -} - -int32_t ReminderRequest::GetReminderId() const -{ - return reminderId_; -} - -uint64_t ReminderRequest::GetReminderTimeInMilli() const -{ - return reminderTimeInMilli_; -} - -void ReminderRequest::SetReminderId(int32_t reminderId) -{ - reminderId_ = reminderId; -} - -void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli) -{ - reminderTimeInMilli_ = reminderTimeInMilli; -} - -ReminderRequest& ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds) -{ - uint64_t ringDuration = ringDurationInSeconds * MILLI_SECONDS; - ringDurationInMilli_ = std::min(ringDuration, MAX_RING_DURATION); - return *this; -} - -NotificationConstant::SlotType ReminderRequest::GetSlotType() const -{ - return slotType_; -} - -NotificationConstant::SlotType ReminderRequest::GetSnoozeSlotType() const -{ - return snoozeSlotType_; -} - -std::string ReminderRequest::GetSnoozeContent() const -{ - return snoozeContent_; -} - -uint8_t ReminderRequest::GetSnoozeTimes() const -{ - return snoozeTimes_; -} - -uint8_t ReminderRequest::GetSnoozeTimesDynamic() const -{ - return snoozeTimesDynamic_; -} - -uint8_t ReminderRequest::GetState() const -{ - return state_; -} - -uint64_t ReminderRequest::GetTimeInterval() const -{ - return timeIntervalInMilli_ / MILLI_SECONDS; -} - -std::string ReminderRequest::GetTitle() const -{ - return title_; -} - -uint64_t ReminderRequest::GetTriggerTimeInMilli() const -{ - return triggerTimeInMilli_; -} - -int32_t ReminderRequest::GetUserId() const -{ - return userId_; -} - -int32_t ReminderRequest::GetUid() const -{ - return uid_; -} - -std::string ReminderRequest::GetBundleName() const -{ - return bundleName_; -} - -void ReminderRequest::SetReminderType(const ReminderType type) -{ - reminderType_ = type; -} - -void ReminderRequest::SetState(const uint8_t state) -{ - state_ = state; -} - -void ReminderRequest::SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek) -{ - repeatDaysOfWeek_ = repeatDaysOfWeek; -} - -void ReminderRequest::SetSystemApp(bool isSystem) -{ - isSystemApp_ = isSystem; -} - -bool ReminderRequest::IsSystemApp() const -{ - return isSystemApp_; -} - -void ReminderRequest::SetTapDismissed(bool tapDismissed) -{ - tapDismissed_ = tapDismissed; -} - -bool ReminderRequest::IsTapDismissed() const -{ - return tapDismissed_; -} - -void ReminderRequest::SetAutoDeletedTime(int64_t autoDeletedTime) -{ - autoDeletedTime_ = autoDeletedTime; -} - -int64_t ReminderRequest::GetAutoDeletedTime() const -{ - return autoDeletedTime_; -} - -void ReminderRequest::SetCustomButtonUri(const std::string &uri) -{ - customButtonUri_ = uri; -} - -std::string ReminderRequest::GetCustomButtonUri() const -{ - return customButtonUri_; -} - -void ReminderRequest::SetCustomRingUri(const std::string &uri) -{ - customRingUri_ = uri; -} - -std::string ReminderRequest::GetCustomRingUri() const -{ - return customRingUri_; -} - -sptr ReminderRequest::GetNotificationBundleOption() const -{ - return notificationOption_; -} - -void ReminderRequest::SetNotificationBundleOption(const sptr& option) -{ - notificationOption_ = option; -} - -std::shared_ptr ReminderRequest::GetWantAgentInfo() const -{ - return wantAgentInfo_; -} - -ReminderRequest::ReminderType ReminderRequest::GetReminderType() const -{ - return reminderType_; -} - -uint16_t ReminderRequest::GetRingDuration() const -{ - return ringDurationInMilli_ / MILLI_SECONDS; -} - -bool ReminderRequest::UpdateNextReminder() -{ - return false; -} - -bool ReminderRequest::SetNextTriggerTime() -{ - return false; -} - -void ReminderRequest::SetWantAgentStr(const std::string& wantStr) -{ - wantAgentStr_ = wantStr; -} - -std::string ReminderRequest::GetWantAgentStr() -{ - return wantAgentStr_; -} - -void ReminderRequest::SetMaxWantAgentStr(const std::string& maxWantStr) -{ - maxWantAgentStr_ = maxWantStr; -} - -std::string ReminderRequest::GetMaxWantAgentStr() -{ - return maxWantAgentStr_; -} - -void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std::string extra) -{ - switch (type) { - case UpdateNotificationType::COMMON: { - ANSR_LOGI("UpdateNotification common information"); - if (extra == "snooze") { - UpdateNotificationCommon(true); - } else { - UpdateNotificationCommon(false); - } - break; - } - case UpdateNotificationType::REMOVAL_WANT_AGENT: { - ANSR_LOGI("UpdateNotification removal_want_agent"); - AddRemovalWantAgent(); - break; - } - case UpdateNotificationType::WANT_AGENT: { - ANSR_LOGI("UpdateNotification want_agent"); - AppExecFwk::ElementName wantAgent("", wantAgentInfo_->pkgName, wantAgentInfo_->abilityName); - SetWantAgent(wantAgent); - SetExtraInfo(wantAgentInfo_->parameters); - break; - } - case UpdateNotificationType::MAX_SCREEN_WANT_AGENT: { - ANSR_LOGI("UpdateNotification max_screen_want_agent"); - AppExecFwk::ElementName maxScreenWantAgent( - "", maxScreenWantAgentInfo_->pkgName, maxScreenWantAgentInfo_->abilityName); - SetMaxScreenWantAgent(maxScreenWantAgent); - break; - } - case UpdateNotificationType::BUNDLE_INFO: { - ANSR_LOGI("UpdateNotification hap information"); - UpdateNotificationBundleInfo(); - break; - } - case UpdateNotificationType::CONTENT: { - break; - } - default: - break; - } -} - -bool ReminderRequest::MarshallingActionButton(Parcel& parcel) const -{ - // write map - uint64_t actionButtonMapSize = static_cast(actionButtonMap_.size()); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, actionButtonMapSize, "actionButtonMapSize"); - for (auto button : actionButtonMap_) { - uint8_t buttonType = static_cast(button.first); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.title, "buttonTitle"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.resource, "buttonResource"); - - if (button.second.wantAgent == nullptr) { - ANSR_LOGE("button wantAgent is null"); - return false; - } - - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->pkgName, "wantAgent's pkgName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->abilityName, "wantAgent's abilityName"); - - if (button.second.dataShareUpdate == nullptr) { - ANSR_LOGE("button dataShareUpdate is null"); - return false; - } - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->uri, - "dataShareUpdate's uri"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->equalTo, - "dataShareUpdate's equalTo"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->valuesBucket, - "dataShareUpdate's valuesBucket"); - } - return true; -} - -bool ReminderRequest::MarshallingWantParameters(Parcel& parcel, const AAFwk::WantParams& params) const -{ - if (params.Size() == 0) { - if (!parcel.WriteInt32(VALUE_NULL)) { - return false; - } - } else { - if (!parcel.WriteInt32(VALUE_OBJECT)) { - return false; - } - if (!parcel.WriteParcelable(¶ms)) { - return false; - } - } - return true; -} - -bool ReminderRequest::Marshalling(Parcel &parcel) const -{ - // write string - WRITE_STRING_RETURN_FALSE_LOG(parcel, content_, "content"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, expiredContent_, "expiredContent"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, snoozeContent_, "snoozeContent"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, title_, "title"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->abilityName, "wantAgentInfo's abilityName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->pkgName, "wantAgentInfo's pkgName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->uri, "wantAgentInfo's uri"); - if (!MarshallingWantParameters(parcel, wantAgentInfo_->parameters)) { - ANSR_LOGE("Failed to write wantAgentInfo's parameters"); - return false; - } - WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->abilityName, "maxScreenWantAgentInfo's abilityName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->pkgName, "maxScreenWantAgentInfo's pkgName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, customButtonUri_, "customButtonUri"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, groupId_, "groupId"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, customRingUri_, "customRingUri"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, creatorBundleName_, "creatorBundleName"); - - // write bool - WRITE_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); - WRITE_BOOL_RETURN_FALSE_LOG(parcel, tapDismissed_, "tapDismissed"); - - // write int - WRITE_INT64_RETURN_FALSE_LOG(parcel, autoDeletedTime_, "autoDeletedTime"); - WRITE_INT32_RETURN_FALSE_LOG(parcel, reminderId_, "reminderId"); - WRITE_INT32_RETURN_FALSE_LOG(parcel, notificationId_, "notificationId"); - - WRITE_UINT64_RETURN_FALSE_LOG(parcel, triggerTimeInMilli_, "triggerTimeInMilli"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, timeIntervalInMilli_, "timeIntervalInMilli"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, ringDurationInMilli_, "ringDurationInMilli"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, reminderTimeInMilli_, "reminderTimeInMilli"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimes_, "snoozeTimes"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimesDynamic_, "snoozeTimesDynamic"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, state_, "state"); - - // write enum - uint8_t reminderType = static_cast(reminderType_); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); - - int32_t slotType = static_cast(slotType_); - WRITE_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); - - int32_t snoozeSlotType = static_cast(snoozeSlotType_); - WRITE_INT32_RETURN_FALSE_LOG(parcel, snoozeSlotType, "snoozeSlotType"); - - if (!MarshallingActionButton(parcel)) { - return false; - } - return true; -} - -ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel) -{ - auto objptr = new (std::nothrow) ReminderRequest(); - if (objptr == nullptr) { - ANSR_LOGE("Failed to create reminder due to no memory."); - return objptr; - } - if (!objptr->ReadFromParcel(parcel)) { - delete objptr; - objptr = nullptr; - } - return objptr; -} - -bool ReminderRequest::ReadActionButtonFromParcel(Parcel& parcel) -{ - uint64_t buttonMapSize = 0; - READ_UINT64_RETURN_FALSE_LOG(parcel, buttonMapSize, "actionButtonMapSize"); - buttonMapSize = (buttonMapSize < MAX_ACTION_BUTTON_NUM) ? buttonMapSize : MAX_ACTION_BUTTON_NUM; - for (uint64_t i = 0; i < buttonMapSize; i++) { - uint8_t buttonType = static_cast(ActionButtonType::INVALID); - READ_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); - ActionButtonType type = static_cast(buttonType); - std::string title = parcel.ReadString(); - std::string resource = parcel.ReadString(); - std::string pkgName = parcel.ReadString(); - std::string abilityName = parcel.ReadString(); - std::string uri = parcel.ReadString(); - std::string equalTo = parcel.ReadString(); - std::string valuesBucket = parcel.ReadString(); - ActionButtonInfo info; - info.type = type; - info.title = title; - info.resource = resource; - info.wantAgent = std::make_shared(); - if (info.wantAgent == nullptr) { - return false; - } - info.wantAgent->pkgName = pkgName; - info.wantAgent->abilityName = abilityName; - info.dataShareUpdate = std::make_shared(); - if (info.dataShareUpdate == nullptr) { - return false; - } - info.dataShareUpdate->uri = uri; - info.dataShareUpdate->equalTo = equalTo; - info.dataShareUpdate->valuesBucket = valuesBucket; - actionButtonMap_.insert(std::pair(type, info)); - } - return true; -} - -bool ReminderRequest::ReadWantParametersFromParcel(Parcel& parcel, AAFwk::WantParams& wantParams) -{ - int empty = VALUE_NULL; - if (!parcel.ReadInt32(empty)) { - return false; - } - if (empty == VALUE_OBJECT) { - auto params = parcel.ReadParcelable(); - if (params != nullptr) { - wantParams = *params; - delete params; - params = nullptr; - } else { - return false; - } - } - return true; -} - -bool ReminderRequest::ReadFromParcel(Parcel &parcel) -{ - READ_STRING_RETURN_FALSE_LOG(parcel, content_, "content"); - READ_STRING_RETURN_FALSE_LOG(parcel, expiredContent_, "expiredContent"); - READ_STRING_RETURN_FALSE_LOG(parcel, snoozeContent_, "snoozeContent"); - READ_STRING_RETURN_FALSE_LOG(parcel, title_, "title"); - READ_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->abilityName, "wantAgentInfo's abilityName"); - READ_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->pkgName, "wantAgentInfo's pkgName"); - READ_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->uri, "wantAgentInfo's uri"); - if (!ReadWantParametersFromParcel(parcel, wantAgentInfo_->parameters)) { - ANSR_LOGE("Failed to write wantAgentInfo's parameters"); - return false; - } - READ_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->abilityName, "maxScreenWantAgentInfo's abilityName"); - READ_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->pkgName, "maxScreenWantAgentInfo's pkgName"); - READ_STRING_RETURN_FALSE_LOG(parcel, customButtonUri_, "customButtonUri"); - READ_STRING_RETURN_FALSE_LOG(parcel, groupId_, "groupId"); - READ_STRING_RETURN_FALSE_LOG(parcel, customRingUri_, "customRingUri"); - READ_STRING_RETURN_FALSE_LOG(parcel, creatorBundleName_, "creatorBundleName"); - - READ_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); - READ_BOOL_RETURN_FALSE_LOG(parcel, tapDismissed_, "tapDismissed"); - - READ_INT64_RETURN_FALSE_LOG(parcel, autoDeletedTime_, "autoDeletedTime"); - - int32_t tempReminderId = -1; - READ_INT32_RETURN_FALSE_LOG(parcel, tempReminderId, "reminderId"); - reminderId_ = (tempReminderId == -1) ? reminderId_ : tempReminderId; - - READ_INT32_RETURN_FALSE_LOG(parcel, notificationId_, "notificationId"); - - READ_UINT64_RETURN_FALSE_LOG(parcel, triggerTimeInMilli_, "triggerTimeInMilli"); - READ_UINT64_RETURN_FALSE_LOG(parcel, timeIntervalInMilli_, "timeIntervalInMilli"); - READ_UINT64_RETURN_FALSE_LOG(parcel, ringDurationInMilli_, "ringDurationInMilli"); - READ_UINT64_RETURN_FALSE_LOG(parcel, reminderTimeInMilli_, "reminderTimeInMilli"); - - READ_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimes_, "snoozeTimes"); - READ_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimesDynamic_, "snoozeTimesDynamic"); - READ_UINT8_RETURN_FALSE_LOG(parcel, state_, "state"); - - uint8_t reminderType = static_cast(ReminderType::INVALID); - READ_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); - reminderType_ = static_cast(reminderType); - - int32_t slotType = static_cast(NotificationConstant::SlotType::OTHER); - READ_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); - slotType_ = static_cast(slotType); - - int32_t snoozeSlotType = static_cast(NotificationConstant::SlotType::OTHER); - READ_INT32_RETURN_FALSE_LOG(parcel, snoozeSlotType, "snoozeSlotType"); - snoozeSlotType_ = static_cast(snoozeSlotType); - - if (!ReadActionButtonFromParcel(parcel)) { - return false; - } - - if (!InitNotificationRequest()) { - return false; - } - return true; -} - -bool ReminderRequest::InitNotificationRequest() -{ - ANSR_LOGI("Init notification"); - notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); - if (notificationRequest_ == nullptr) { - ANSR_LOGE("Failed to create notification."); - return false; - } - displayContent_ = content_; - return true; -} - -void ReminderRequest::InitServerObj() -{ - wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; - maxScreenWantAgentInfo_ = - maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; -} - -bool ReminderRequest::IsAlerting() const -{ - return (state_ & REMINDER_STATUS_ALERTING) != 0; -} - -uint64_t ReminderRequest::GetDurationSinceEpochInMilli(const time_t target) -{ - auto tarEndTimePoint = std::chrono::system_clock::from_time_t(target); - auto tarDuration = std::chrono::duration_cast(tarEndTimePoint.time_since_epoch()); - int64_t tarDate = tarDuration.count(); - if (tarDate < 0) { - ANSR_LOGW("tarDuration is less than 0."); - return INVALID_LONG_LONG_VALUE; - } - return static_cast(tarDate); -} - -std::string ReminderRequest::GetDateTimeInfo(const time_t &timeInSecond) const -{ - return GetTimeInfoInner(timeInSecond, TimeFormat::YMDHMS, true); -} - -std::string ReminderRequest::SerializeButtonInfo() const -{ - std::string info = ""; - bool isFirst = true; - for (auto button : actionButtonMap_) { - if (!isFirst) { - info += SEP_BUTTON_MULTI; - } - ActionButtonInfo buttonInfo = button.second; - nlohmann::json root; - root["type"] = std::to_string(static_cast(button.first)); - root["title"] = buttonInfo.title; - root["resource"] = buttonInfo.resource; - if (buttonInfo.wantAgent != nullptr) { - nlohmann::json wantAgentfriends; - wantAgentfriends["pkgName"] = buttonInfo.wantAgent->pkgName; - wantAgentfriends["abilityName"] = buttonInfo.wantAgent->abilityName; - root["wantAgent"] = wantAgentfriends; - } - - if (buttonInfo.dataShareUpdate != nullptr) { - nlohmann::json dataShareUpdatefriends; - dataShareUpdatefriends["uri"] = buttonInfo.dataShareUpdate->uri; - dataShareUpdatefriends["equalTo"] = buttonInfo.dataShareUpdate->equalTo; - dataShareUpdatefriends["valuesBucket"] = buttonInfo.dataShareUpdate->valuesBucket; - root["dataShareUpdate"] = dataShareUpdatefriends; - } - std::string str = root.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace); - info += str; - isFirst = false; - } - return info; -} - -uint64_t ReminderRequest::GetNowInstantMilli() const -{ - time_t now; - (void)time(&now); // unit is seconds. - if (static_cast(now) < 0) { - ANSR_LOGE("Get now time error"); - return 0; - } - return GetDurationSinceEpochInMilli(now); -} - -std::string ReminderRequest::GetShowTime(const uint64_t showTime) const -{ - if (reminderType_ == ReminderType::TIMER) { - return ""; - } - return GetTimeInfoInner(static_cast(showTime / MILLI_SECONDS), TimeFormat::HM, false); -} - -std::string ReminderRequest::GetTimeInfoInner(const time_t &timeInSecond, const TimeFormat &format, - bool keep24Hour) const -{ - const uint8_t dateTimeLen = 80; - char dateTimeBuffer[dateTimeLen]; - struct tm timeInfo; - (void)localtime_r(&timeInSecond, &timeInfo); - bool is24HourClock = OHOS::Global::I18n::LocaleConfig::Is24HourClock(); - if (!is24HourClock && timeInfo.tm_hour > TIME_HOUR_OFFSET && !keep24Hour) { - timeInfo.tm_hour -= TIME_HOUR_OFFSET; - } - switch (format) { - case TimeFormat::YMDHMS: { - (void)strftime(dateTimeBuffer, dateTimeLen, "%Y-%m-%d %H:%M:%S", &timeInfo); - break; - } - case TimeFormat::HM: { - (void)strftime(dateTimeBuffer, dateTimeLen, "%H:%M", &timeInfo); - break; - } - default: { - ANSR_LOGW("Time format not support."); - break; - } - } - std::string dateTimeInfo(dateTimeBuffer); - return dateTimeInfo; -} - -std::string ReminderRequest::GetState(const uint8_t state) const -{ - std::string stateInfo = "'"; - if (state == REMINDER_STATUS_INACTIVE) { - stateInfo += "Inactive"; - } else { - bool hasSeparator = false; - if ((state & REMINDER_STATUS_ACTIVE) != 0) { - stateInfo += "Active"; - hasSeparator = true; - } - if ((state & REMINDER_STATUS_ALERTING) != 0) { - if (hasSeparator) { - stateInfo += ","; - } - stateInfo += "Alerting"; - hasSeparator = true; - } - if ((state & REMINDER_STATUS_SHOWING) != 0) { - if (hasSeparator) { - stateInfo += ","; - } - stateInfo += "Showing"; - hasSeparator = true; - } - if ((state & REMINDER_STATUS_SNOOZE) != 0) { - if (hasSeparator) { - stateInfo += ","; - } - stateInfo += "Snooze"; - } - } - stateInfo += "'"; - return stateInfo; -} - -void ReminderRequest::AddActionButtons(const bool includeSnooze) -{ - int32_t requestCode = 10; - std::vector flags; - flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); - for (auto button : actionButtonMap_) { - auto want = std::make_shared(); - auto type = button.first; - switch (type) { - case ActionButtonType::CLOSE: - want->SetAction(REMINDER_EVENT_CLOSE_ALERT); - break; - case ActionButtonType::SNOOZE: - if (includeSnooze) { - want->SetAction(REMINDER_EVENT_SNOOZE_ALERT); - } else { - ANSR_LOGD("Not add action button, type is snooze, as includeSnooze is false"); - continue; - } - break; - case ActionButtonType::CUSTOM: - want->SetAction(REMINDER_EVENT_CUSTOM_ALERT); - if (button.second.wantAgent == nullptr) { - return; - } - want->SetParam("PkgName", button.second.wantAgent->pkgName); - want->SetParam("AbilityName", button.second.wantAgent->abilityName); - break; - default: - break; - } - want->SetParam(PARAM_REMINDER_ID, reminderId_); - std::vector> wants; - wants.push_back(want); - auto title = static_cast(button.second.title); - AbilityRuntime::WantAgent::WantAgentInfo buttonWantAgentInfo( - requestCode, - AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, - flags, - wants, - nullptr - ); - - std::string identity = IPCSkeleton::ResetCallingIdentity(); - std::shared_ptr buttonWantAgent = - AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo, userId_); - IPCSkeleton::SetCallingIdentity(identity); - - std::shared_ptr actionButton - = NotificationActionButton::Create(nullptr, title, buttonWantAgent); - notificationRequest_->AddActionButton(actionButton); - } -} - -void ReminderRequest::AddRemovalWantAgent() -{ - int32_t requestCode = 10; - std::vector flags; - flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); - auto want = std::make_shared(); - want->SetAction(REMINDER_EVENT_REMOVE_NOTIFICATION); - want->SetParam(PARAM_REMINDER_ID, reminderId_); - std::vector> wants; - wants.push_back(want); - AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( - requestCode, - AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, - flags, - wants, - nullptr - ); - - std::string identity = IPCSkeleton::ResetCallingIdentity(); - std::shared_ptr wantAgent = - AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); - IPCSkeleton::SetCallingIdentity(identity); - - notificationRequest_->SetRemovalWantAgent(wantAgent); -} - -std::shared_ptr ReminderRequest::CreateWantAgent( - AppExecFwk::ElementName &element) const -{ - int32_t requestCode = 10; - std::vector wantFlags; - wantFlags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); - auto want = std::make_shared(); - want->SetAction(REMINDER_EVENT_CLICK_ALERT); - want->SetParam(PARAM_REMINDER_ID, reminderId_); - std::vector> wantes; - wantes.push_back(want); - AbilityRuntime::WantAgent::WantAgentInfo wantInfo( - requestCode, - AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, - wantFlags, - wantes, - nullptr - ); - std::string callingIdentity = IPCSkeleton::ResetCallingIdentity(); - auto wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantInfo, userId_); - IPCSkeleton::SetCallingIdentity(callingIdentity); - return wantAgent; -} - -std::shared_ptr ReminderRequest::CreateMaxWantAgent( - AppExecFwk::ElementName &element) const -{ - int32_t requestCode = 10; - std::vector flags; - flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); - auto want = std::make_shared(); - want->SetElement(element); - std::vector> wants; - wants.push_back(want); - AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( - requestCode, - AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITY, - flags, - wants, - nullptr - ); - std::string identity = IPCSkeleton::ResetCallingIdentity(); - auto wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); - IPCSkeleton::SetCallingIdentity(identity); - return wantAgent; -} - -void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element) -{ - std::shared_ptr wantAgent = CreateMaxWantAgent(element); - notificationRequest_->SetMaxScreenWantAgent(wantAgent); -} - -void ReminderRequest::SetWantAgent(AppExecFwk::ElementName &element) -{ - std::shared_ptr wantAgent = CreateWantAgent(element); - notificationRequest_->SetWantAgent(wantAgent); -} - -void ReminderRequest::SetExtraInfo(const AAFwk::WantParams& params) -{ - if (params.HasParam(PARAM_EXTRA_KEY)) { - std::shared_ptr extras = std::make_shared( - params.GetWantParams(PARAM_EXTRA_KEY)); - notificationRequest_->SetAdditionalData(extras); - } -} - -void ReminderRequest::SetState(bool deSet, const uint8_t newState, std::string function) -{ - uint8_t oldState = state_; - if (deSet) { - state_ |= newState; - } else { - state_ &= static_cast(~newState); - } - ANSR_LOGI("Switch the reminder(reminderId=%{public}d) state, from %{public}s to %{public}s, called by %{public}s", - reminderId_, GetState(oldState).c_str(), GetState(state_).c_str(), function.c_str()); -} - -void ReminderRequest::SetStateToInActive() -{ - SetState(false, (REMINDER_STATUS_SHOWING | REMINDER_STATUS_ALERTING | REMINDER_STATUS_ACTIVE), - "SetStateToInActive"); -} - -void ReminderRequest::UpdateActionButtons(const bool &setSnooze) -{ - if (notificationRequest_ == nullptr) { - ANSR_LOGE("updateActionButtons failed, the notificationRequest is null"); - return; - } - notificationRequest_->ClearActionButtons(); - if (setSnooze) { - AddActionButtons(false); - } else { - AddActionButtons(true); - } -} - -bool ReminderRequest::UpdateNextReminder(const bool &force) -{ - bool result = true; - if (force) { - uint64_t nowInstantMilli = GetNowInstantMilli(); - if (nowInstantMilli == 0) { - result = false; - } else { - if (timeIntervalInMilli_ != 0) { - triggerTimeInMilli_ = nowInstantMilli + timeIntervalInMilli_; - snoozeTimesDynamic_ = snoozeTimes_; - isExpired_ = false; - } - } - } else { - result = UpdateNextReminder(); - } - std::string info = result ? "success" : "no next"; - ANSR_LOGI("updateNextReminder(id=%{public}d, %{public}s): force=%{public}d, trigger time is: %{public}s", - reminderId_, info.c_str(), force, - GetDateTimeInfo(static_cast(triggerTimeInMilli_ / MILLI_SECONDS)).c_str()); - return result; -} - -void ReminderRequest::UpdateNotificationCommon(bool isSnooze) -{ - time_t now; - (void)time(&now); // unit is seconds. - notificationRequest_->SetDeliveryTime(GetDurationSinceEpochInMilli(now)); - notificationRequest_->SetLabel(NOTIFICATION_LABEL); - notificationRequest_->SetShowDeliveryTime(true); - if (isSnooze) { - if (snoozeSlotType_ == NotificationConstant::SlotType::OTHER) { - notificationRequest_->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); - } else { - notificationRequest_->SetSlotType(snoozeSlotType_); - } - } else { - notificationRequest_->SetSlotType(slotType_); - } - notificationRequest_->SetTapDismissed(tapDismissed_); - notificationRequest_->SetAutoDeletedTime(autoDeletedTime_); - auto notificationNormalContent = std::make_shared(); - notificationNormalContent->SetText(displayContent_); - notificationNormalContent->SetTitle(title_); - auto notificationContent = std::make_shared(notificationNormalContent); - notificationRequest_->SetContent(notificationContent); - if ((reminderType_ == ReminderRequest::ReminderType::TIMER) || - (reminderType_ == ReminderRequest::ReminderType::ALARM)) { - notificationRequest_->SetUnremovable(true); - } -} - -void ReminderRequest::UpdateNotificationBundleInfo() -{ - std::string ownerBundleName = notificationRequest_->GetOwnerBundleName(); - if (!(ownerBundleName.empty())) { - return; - } - ANSR_LOGD("ownerBundleName=%{public}s, bundleName_=%{public}s", - ownerBundleName.c_str(), bundleName_.c_str()); - notificationRequest_->SetOwnerBundleName(bundleName_); - notificationRequest_->SetCreatorBundleName(bundleName_); - notificationRequest_->SetCreatorUid(uid_); - notificationRequest_->SetCreatorUserId(userId_); -} - -void ReminderRequest::UpdateNotificationContent(const bool &setSnooze) -{ - if (notificationRequest_ == nullptr) { - ANSR_LOGE("updateNotificationContent failed, the notificationRequest is null"); - return; - } - std::string extendContent = ""; - if (setSnooze) { - if (timeIntervalInMilli_ != 0) { - // snooze the reminder by manual - extendContent = snoozeContent_; - notificationRequest_->SetTapDismissed(false); - } else { - // the reminder is expired now, when timeInterval is 0 - extendContent = expiredContent_; - } - } else if (IsAlerting()) { - // the reminder is alerting, or ring duration is 0 - extendContent = ""; - } else if (snoozeTimesDynamic_ != snoozeTimes_) { - // the reminder is snoozing by period artithmetic, when the ring duration is over. - extendContent = snoozeContent_; - notificationRequest_->SetTapDismissed(false); - } else { - // the reminder has already snoozed by period arithmetic, when the ring duration is over. - extendContent = expiredContent_; - } - if (extendContent == "") { - displayContent_ = content_; - } else { - displayContent_ = extendContent; - } - ANSR_LOGD("Display content=%{public}s", displayContent_.c_str()); -} - -void ReminderRequest::UpdateNotificationStateForAlert() -{ - ANSR_LOGD("UpdateNotification content and buttons"); - UpdateNotificationContent(false); - UpdateActionButtons(false); -} - -void ReminderRequest::UpdateNotificationStateForSnooze() -{ - ANSR_LOGD("UpdateNotification content and buttons"); - UpdateNotificationContent(true); - UpdateActionButtons(true); -} - -int32_t ReminderRequest::GetActualTime(const TimeTransferType &type, int32_t cTime) -{ - switch (type) { - case (TimeTransferType::YEAR): // year - return BASE_YEAR + cTime; - case (TimeTransferType::MONTH): // month - return 1 + cTime; - case (TimeTransferType::WEEK): { // week - return cTime == 0 ? SUNDAY : cTime; - } - default: - return -1; - } -} - -int32_t ReminderRequest::GetCTime(const TimeTransferType &type, int32_t actualTime) -{ - switch (type) { - case (TimeTransferType::YEAR): // year - return actualTime - BASE_YEAR; - case (TimeTransferType::MONTH): // month - return actualTime - 1; - case (TimeTransferType::WEEK): { // week - return actualTime == SUNDAY ? 0 : actualTime; - } - default: - return -1; - } -} - -void ReminderRequest::SerializeWantAgent(std::string& wantInfoStr, std::string& maxWantInfoStr) -{ - std::string pkgName; - std::string abilityName; - std::string uri; - std::string parameters; - if (wantAgentInfo_ != nullptr) { - pkgName = wantAgentInfo_->pkgName; - abilityName = wantAgentInfo_->abilityName; - uri = wantAgentInfo_->uri; - AAFwk::WantParamWrapper wrapper(wantAgentInfo_->parameters); - parameters = wrapper.ToString(); - } - nlohmann::json wantInfo; - wantInfo["pkgName"] = pkgName; - wantInfo["abilityName"] = abilityName; - wantInfo["uri"] = uri; - wantInfo["parameters"] = parameters; - wantInfoStr = wantInfo.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace); - - if (maxScreenWantAgentInfo_ != nullptr) { - pkgName = maxScreenWantAgentInfo_->pkgName; - abilityName = maxScreenWantAgentInfo_->abilityName; - uri = ""; - parameters = ""; - } - nlohmann::json maxWantInfo; - maxWantInfo["pkgName"] = pkgName; - maxWantInfo["abilityName"] = abilityName; - maxWantInfo["uri"] = uri; - maxWantInfo["parameters"] = parameters; - maxWantInfoStr = maxWantInfo.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace); -} - -int64_t ReminderRequest::GetNextDaysOfWeek(const time_t now, const time_t target) const -{ - struct tm nowTime; - (void)localtime_r(&now, &nowTime); - int32_t today = GetActualTime(TimeTransferType::WEEK, nowTime.tm_wday); - int32_t dayCount = now >= target ? 1 : 0; - for (; dayCount <= DAYS_PER_WEEK; dayCount++) { - int32_t day = (today + dayCount) % DAYS_PER_WEEK; - day = (day == 0) ? SUNDAY : day; - if (IsRepeatDaysOfWeek(day)) { - break; - } - } - ANSR_LOGI("NextDayInterval is %{public}d", dayCount); - time_t nextTriggerTime = target + dayCount * HOURS_PER_DAY * SECONDS_PER_HOUR; - return GetTriggerTime(now, nextTriggerTime); -} - -bool ReminderRequest::IsRepeatDaysOfWeek(int32_t day) const -{ - return (repeatDaysOfWeek_ & (1 << (day - 1))) > 0; -} - -time_t ReminderRequest::GetTriggerTimeWithDST(const time_t now, const time_t nextTriggerTime) const -{ - time_t triggerTime = nextTriggerTime; - struct tm nowLocal; - struct tm nextLocal; - (void)localtime_r(&now, &nowLocal); - (void)localtime_r(&nextTriggerTime, &nextLocal); - if (nowLocal.tm_isdst == 0 && nextLocal.tm_isdst > 0) { - triggerTime -= SECONDS_PER_HOUR; - } else if (nowLocal.tm_isdst > 0 && nextLocal.tm_isdst == 0) { - triggerTime += SECONDS_PER_HOUR; - } - return triggerTime; -} - -uint8_t ReminderRequest::GetRepeatDaysOfWeek() const -{ - return repeatDaysOfWeek_; -} - -void ReminderRequest::SetRepeatDaysOfWeek(bool set, const std::vector &daysOfWeek) -{ - if (daysOfWeek.size() == 0) { - return; - } - if (daysOfWeek.size() > DAYS_PER_WEEK) { - ANSR_LOGE("The length of daysOfWeek should not larger than 7"); - return; - } - for (auto it = daysOfWeek.begin(); it != daysOfWeek.end(); ++it) { - if (*it < MONDAY || *it > SUNDAY) { - continue; - } - if (set) { - repeatDaysOfWeek_ |= 1 << (*it - 1); - } else { - repeatDaysOfWeek_ &= ~(1 << (*it - 1)); - } - } -} - -std::vector ReminderRequest::GetDaysOfWeek() const -{ - std::vector repeatDays; - int32_t days[] = {1, 2, 3, 4, 5, 6, 7}; - int32_t len = sizeof(days) / sizeof(int32_t); - for (int32_t i = 0; i < len; i++) { - if (IsRepeatDaysOfWeek(days[i])) { - repeatDays.push_back(days[i]); - } - } - return repeatDays; -} - -uint64_t ReminderRequest::GetTriggerTime(const time_t now, const time_t nextTriggerTime) const -{ - time_t triggerTime = GetTriggerTimeWithDST(now, nextTriggerTime); - struct tm test; - (void)localtime_r(&triggerTime, &test); - ANSR_LOGI("NextTriggerTime: year=%{public}d, mon=%{public}d, day=%{public}d, hour=%{public}d, " - "min=%{public}d, sec=%{public}d, week=%{public}d, nextTriggerTime=%{public}lld", - GetActualTime(TimeTransferType::YEAR, test.tm_year), - GetActualTime(TimeTransferType::MONTH, test.tm_mon), - test.tm_mday, - test.tm_hour, - test.tm_min, - test.tm_sec, - GetActualTime(TimeTransferType::WEEK, test.tm_wday), - (long long)triggerTime); - - if (static_cast(triggerTime) <= 0) { - return 0; - } - return GetDurationSinceEpochInMilli(triggerTime); -} - -void ReminderRequest::OnLanguageChange(const std::shared_ptr &resMgr) -{ - if (resMgr == nullptr) { - return; - } - // update title - for (auto &button : actionButtonMap_) { - if (button.second.resource.empty()) { - continue; - } - std::string title; - resMgr->GetStringByName(button.second.resource.c_str(), title); - if (title.empty()) { - continue; - } - button.second.title = title; - } -} -} -} diff --git a/frameworks/ans/src/reminder_request_alarm.cpp b/frameworks/ans/src/reminder_request_alarm.cpp deleted file mode 100644 index 8fd928b2b89b5221952eb2cf9e365915d289218b..0000000000000000000000000000000000000000 --- a/frameworks/ans/src/reminder_request_alarm.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "reminder_request_alarm.h" - -#include "ans_log_wrapper.h" - -namespace OHOS { -namespace Notification { -const uint8_t ReminderRequestAlarm::MINUTES_PER_HOUR = 60; -const int8_t ReminderRequestAlarm::DEFAULT_SNOOZE_TIMES = 3; - -ReminderRequestAlarm::ReminderRequestAlarm(uint8_t hour, uint8_t minute, const std::vector daysOfWeek) - : ReminderRequest(ReminderRequest::ReminderType::ALARM) -{ - SetSnoozeTimes(DEFAULT_SNOOZE_TIMES); - hour_ = hour; - minute_ = minute; - CheckParamValid(); - SetRepeatDaysOfWeek(true, daysOfWeek); - SetTriggerTimeInMilli(GetNextTriggerTime(true)); -} - -ReminderRequestAlarm::ReminderRequestAlarm(const ReminderRequestAlarm &other) : ReminderRequest(other) -{ - hour_ = other.hour_; - minute_ = other.minute_; - repeatDaysOfWeek_ = other.repeatDaysOfWeek_; - ANSR_LOGD("hour_=%{public}d, minute_=%{public}d, repeatDaysOfWeek_=%{public}d", - hour_, minute_, other.repeatDaysOfWeek_); -} - -void ReminderRequestAlarm::CheckParamValid() const -{ - if (hour_ >= HOURS_PER_DAY) { - ANSR_LOGE("setted hour is not between [0, 24)"); - return; - } - if (minute_ >= MINUTES_PER_HOUR) { - ANSR_LOGE("setted minute is not between [0, 60)"); - return; - } -} - -bool ReminderRequestAlarm::IsRepeatReminder() const -{ - if ((repeatDaysOfWeek_ != 0) || ((GetTimeInterval() > 0) && (GetSnoozeTimes() > 0))) { - return true; - } else { - return false; - } -} - - -uint64_t ReminderRequestAlarm::PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) -{ - if (ignoreRepeat || (repeatDaysOfWeek_)) { - return GetNextTriggerTime(forceToGetNext); - } else { - return INVALID_LONG_LONG_VALUE; - } -} - -uint64_t ReminderRequestAlarm::GetNextTriggerTime(bool forceToGetNext) const -{ - time_t now; - (void)time(&now); // unit is seconds. - struct tm nowTime; - (void)localtime_r(&now, &nowTime); - ANSR_LOGD("Now: year=%{public}d, mon=%{public}d, day=%{public}d, hour=%{public}d, " - "min=%{public}d, sec=%{public}d, week=%{public}d, Target: tar_hour=%{public}d, tar_min=%{public}d", - GetActualTime(TimeTransferType::YEAR, nowTime.tm_year), - GetActualTime(TimeTransferType::MONTH, nowTime.tm_mon), - nowTime.tm_mday, nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec, - GetActualTime(TimeTransferType::WEEK, nowTime.tm_wday), hour_, minute_); - - struct tm tar; - tar.tm_year = nowTime.tm_year; - tar.tm_mon = nowTime.tm_mon; - tar.tm_mday = nowTime.tm_mday; - tar.tm_hour = hour_; - tar.tm_min = minute_; - tar.tm_sec = 0; - tar.tm_isdst = -1; - - const time_t target = mktime(&tar); - if (repeatDaysOfWeek_ > 0) { - return GetNextDaysOfWeek(now, target); - } - - time_t nextTriggerTime = 0; - if (now >= target) { - if (forceToGetNext) { - nextTriggerTime = target + 1 * HOURS_PER_DAY * SECONDS_PER_HOUR; - } - } else { - nextTriggerTime = target; - } - return GetTriggerTime(now, nextTriggerTime); -} - -void ReminderRequestAlarm::SetHour(const uint8_t hour) -{ - hour_ = hour; -} - -void ReminderRequestAlarm::SetMinute(const uint8_t minute) -{ - minute_ = minute; -} - -uint8_t ReminderRequestAlarm::GetHour() const -{ - return hour_; -} - -uint8_t ReminderRequestAlarm::GetMinute() const -{ - return minute_; -} - -bool ReminderRequestAlarm::UpdateNextReminder() -{ - ANSR_LOGD("UpdateNextReminder alarm time"); - if (IsRepeatReminder()) { - uint8_t letfSnoozeTimes = GetSnoozeTimesDynamic(); - if ((letfSnoozeTimes > 0) && (GetTimeInterval() > 0)) { - ANSR_LOGI("Left times: %{public}d, update next triggerTime", GetSnoozeTimesDynamic()); - SetTriggerTimeInMilli(GetTriggerTimeInMilli() + GetTimeInterval() * MILLI_SECONDS); - SetSnoozeTimesDynamic(--letfSnoozeTimes); - } else { - SetSnoozeTimesDynamic(GetSnoozeTimes()); - if (repeatDaysOfWeek_ == 0) { - ANSR_LOGI("No need to update next triggerTime"); - SetExpired(true); - return false; - } - uint64_t nextTriggerTime = GetNextTriggerTime(true); - if (nextTriggerTime != INVALID_LONG_LONG_VALUE) { - ANSR_LOGI("Set next trigger time successful, reset dynamic snoozeTimes"); - SetTriggerTimeInMilli(nextTriggerTime); - } else { - ANSR_LOGW("Set reminder to expired"); - SetExpired(true); - return false; - } - } - return true; - } else { - ANSR_LOGD("Single time reminder, not need to update next trigger time"); - SetSnoozeTimesDynamic(GetSnoozeTimes()); - SetExpired(true); - return false; - } -} - -bool ReminderRequestAlarm::Marshalling(Parcel &parcel) const -{ - if (ReminderRequest::Marshalling(parcel)) { - WRITE_UINT8_RETURN_FALSE_LOG(parcel, hour_, "hour"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, minute_, "minute"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, repeatDaysOfWeek_, "repeatDaysOfWeek"); - return true; - } - return false; -} - -ReminderRequestAlarm *ReminderRequestAlarm::Unmarshalling(Parcel &parcel) -{ - ANSR_LOGD("New alarm"); - auto objptr = new (std::nothrow) ReminderRequestAlarm(); - if (objptr == nullptr) { - ANSR_LOGE("Failed to create reminder alarm due to no memory."); - return objptr; - } - if (!objptr->ReadFromParcel(parcel)) { - delete objptr; - objptr = nullptr; - } - return objptr; -} - -bool ReminderRequestAlarm::ReadFromParcel(Parcel &parcel) -{ - if (ReminderRequest::ReadFromParcel(parcel)) { - READ_UINT8_RETURN_FALSE_LOG(parcel, hour_, "hour"); - READ_UINT8_RETURN_FALSE_LOG(parcel, minute_, "minute"); - READ_UINT8_RETURN_FALSE_LOG(parcel, repeatDaysOfWeek_, "repeatDaysOfWeek"); - - ANSR_LOGD("hour_=%{public}d, minute_=%{public}d", hour_, minute_); - return true; - } - return false; -} -} -} \ No newline at end of file diff --git a/frameworks/ans/src/reminder_request_calendar.cpp b/frameworks/ans/src/reminder_request_calendar.cpp deleted file mode 100644 index df26f548ccc0977ec839176fbbb85216b8152b4b..0000000000000000000000000000000000000000 --- a/frameworks/ans/src/reminder_request_calendar.cpp +++ /dev/null @@ -1,870 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "reminder_request_calendar.h" - -#include "ans_log_wrapper.h" -#include "nlohmann/json.hpp" - -namespace OHOS { -namespace Notification { -const uint8_t ReminderRequestCalendar::DEFAULT_SNOOZE_TIMES = 3; - -const uint8_t ReminderRequestCalendar::DAY_ARRAY[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - -ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, const std::vector &repeatMonths, - const std::vector &repeatDays, const std::vector &daysOfWeek) - : ReminderRequest(ReminderRequest::ReminderType::CALENDAR) -{ - // 1. record the information which designated by user at first time. - firstDesignateYear_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime.tm_year)); - firstDesignateMonth_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon)); - firstDesignateDay_ = dateTime.tm_mday; - SetRepeatMonths(repeatMonths); - SetRepeatDaysOfMonth(repeatDays); - SetRepeatDaysOfWeek(true, daysOfWeek); - SetSnoozeTimes(DEFAULT_SNOOZE_TIMES); - - // 2. should SetNextTriggerTime() after constructor - InitDateTime(dateTime); -} - -ReminderRequestCalendar::ReminderRequestCalendar(const ReminderRequestCalendar &other) : ReminderRequest(other) -{ - dateTime_ = other.dateTime_; - firstDesignateYear_ = other.firstDesignateYear_; - firstDesignateMonth_ = other.firstDesignateMonth_; - firstDesignateDay_ = other.firstDesignateDay_; - year_ = other.year_; - month_ = other.month_; - day_ = other.day_; - hour_ = other.hour_; - minute_ = other.minute_; - second_ = other.second_; - repeatMonth_ = other.repeatMonth_; - repeatDay_ = other.repeatDay_; - repeatDaysOfWeek_ = other.repeatDaysOfWeek_; - rruleWantAgentInfo_ = other.rruleWantAgentInfo_; - durationTime_ = other.durationTime_; - startDateTime_ = other.startDateTime_; - endDateTime_ = other.endDateTime_; - excludeDates_ = other.excludeDates_; - lastStartDateTime_ = other.lastStartDateTime_; -} - -void ReminderRequestCalendar::SetRRuleWantAgentInfo(const std::shared_ptr &wantAgentInfo) -{ - rruleWantAgentInfo_ = wantAgentInfo; -} - -void ReminderRequestCalendar::AddExcludeDate(const uint64_t date) -{ - time_t t = static_cast(date / MILLI_SECONDS); - struct tm dateTime; - (void)localtime_r(&t, &dateTime); - dateTime.tm_hour = 0; - dateTime.tm_min = 0; - dateTime.tm_sec = 0; - const time_t target = mktime(&dateTime); - if (target == -1) { - ANSR_LOGW("error exclude date"); - return; - } - excludeDates_.insert(ReminderRequest::GetDurationSinceEpochInMilli(target)); -} - -void ReminderRequestCalendar::DelExcludeDates() -{ - excludeDates_.clear(); -} - -std::vector ReminderRequestCalendar::GetExcludeDates() const -{ - std::vector excludeDates; - for (auto date : excludeDates_) { - excludeDates.push_back(date); - } - return excludeDates; -} - -bool ReminderRequestCalendar::IsInExcludeDate() const -{ - time_t t = static_cast(startDateTime_ / MILLI_SECONDS); - struct tm dateTime; - (void)localtime_r(&t, &dateTime); - dateTime.tm_hour = 0; - dateTime.tm_min = 0; - dateTime.tm_sec = 0; - const time_t target = mktime(&dateTime); - if (target == -1) { - ANSR_LOGW("error start date time"); - return false; - } - uint64_t notificationTime = ReminderRequest::GetDurationSinceEpochInMilli(target); - if (excludeDates_.find(notificationTime) != excludeDates_.end()) { - ANSR_LOGI("Reminder[%{public}d] trigger time is in exclude date", GetReminderId()); - return true; - } - return false; -} - -std::shared_ptr ReminderRequestCalendar::GetRRuleWantAgentInfo() -{ - return rruleWantAgentInfo_; -} - -void ReminderRequestCalendar::SetRepeatDay(const uint32_t repeatDay) -{ - repeatDay_ = repeatDay; -} - -void ReminderRequestCalendar::SetRepeatMonth(const uint16_t repeatMonth) -{ - repeatMonth_ = repeatMonth; -} - -void ReminderRequestCalendar::SetFirstDesignateYear(const uint16_t firstDesignateYear) -{ - firstDesignateYear_ = firstDesignateYear; -} - -void ReminderRequestCalendar::SetFirstDesignageMonth(const uint16_t firstDesignateMonth) -{ - firstDesignateMonth_ = firstDesignateMonth; -} - -void ReminderRequestCalendar::SetFirstDesignateDay(const uint16_t firstDesignateDay) -{ - firstDesignateDay_ = firstDesignateDay; -} - -void ReminderRequestCalendar::SetYear(const uint16_t year) -{ - year_ = year; -} - -void ReminderRequestCalendar::SetMonth(const uint8_t month) -{ - month_ = month; -} - -void ReminderRequestCalendar::SetDay(const uint8_t day) -{ - day_ = day; -} - -void ReminderRequestCalendar::SetHour(const uint8_t hour) -{ - hour_ = hour; -} - -void ReminderRequestCalendar::SetMinute(const uint8_t minute) -{ - minute_ = minute; -} - -bool ReminderRequestCalendar::InitTriggerTime() -{ - uint64_t nextTriggerTime = INVALID_LONG_LONG_VALUE; - uint64_t nowInMilli = GetNowInstantMilli(); - if ((startDateTime_ <= nowInMilli) && (nowInMilli <= endDateTime_)) { - nextTriggerTime = nowInMilli + DEFAULT_DELAY_TIME; - } else if (startDateTime_ > nowInMilli) { - nextTriggerTime = startDateTime_; - } else if (endDateTime_ < nowInMilli && IsRepeatReminder()) { - nextTriggerTime = GetNextTriggerTime(); - } else { - return false; - } - lastStartDateTime_ = startDateTime_; - SetTriggerTimeInMilli(nextTriggerTime); - return true; -} - -bool ReminderRequestCalendar::SetNextTriggerTime() -{ - hour_ = static_cast(dateTime_.tm_hour); - minute_ = static_cast(dateTime_.tm_min); - uint64_t nextTriggerTime = INVALID_LONG_LONG_VALUE; - if ((nextTriggerTime = GetNextTriggerTime()) != INVALID_LONG_LONG_VALUE) { - time_t target = static_cast(nextTriggerTime / MILLI_SECONDS); - (void)localtime_r(&target, &dateTime_); - } else { - ANSR_LOGW("Not exist next trigger time, please check the param of ReminderRequestCalendar constructor."); - return false; - } - - // set the time information (used to transfer to proxy service) which is decided to trigger firstly. - year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year)); - month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon)); - day_ = static_cast(dateTime_.tm_mday); - second_ = 0; - SetTriggerTimeInMilli(nextTriggerTime); - return true; -} - -uint8_t ReminderRequestCalendar::GetDaysOfMonth(const uint16_t &year, const uint8_t &month) -{ - uint8_t days; - if (month == FEBRUARY) { - days = ((((year % LEAP_PARAM_MIN == 0) && (year % LEAP_PARAM_MAX != 0)) || (year % SOLAR_YEAR == 0)) - ? LEAP_MONTH : NON_LEAP_MONTH); - } else { - days = DAY_ARRAY[month - 1]; - } - return days; -} - -uint8_t ReminderRequestCalendar::GetNextDay( - const uint16_t &settedYear, const uint8_t &settedMonth, const tm &now, const tm &target) const -{ - uint32_t repeatDayTmp = repeatDay_; - uint8_t daysOfSpecialMonth = GetDaysOfMonth(settedYear, settedMonth); - uint8_t setDayTmp = INVALID_U8_VALUE; - for (uint8_t i = 1; i <= daysOfSpecialMonth; i++) { - if ((repeatDayTmp & (1 << (i - 1))) > 0) { - struct tm setTime; - setTime.tm_year = GetCTime(TimeTransferType::YEAR, settedYear); - setTime.tm_mon = GetCTime(TimeTransferType::MONTH, settedMonth); - setTime.tm_mday = static_cast(i); - setTime.tm_hour = target.tm_hour; - setTime.tm_min = target.tm_min; - setTime.tm_sec = target.tm_sec; - setTime.tm_isdst = -1; - - struct tm nowTime; - nowTime.tm_year = now.tm_year; - nowTime.tm_mon = now.tm_mon; - nowTime.tm_mday = now.tm_mday; - nowTime.tm_hour = now.tm_hour; - nowTime.tm_min = now.tm_min; - nowTime.tm_sec = now.tm_sec; - nowTime.tm_isdst = -1; - - if (mktime(&nowTime) >= mktime(&setTime)) { - continue; - } else { - setDayTmp = i; - return setDayTmp; - } - } - } - return setDayTmp; -} - -bool ReminderRequestCalendar::CheckCalenderIsExpired(const uint64_t now) -{ - if (IsInExcludeDate()) { - return false; - } - if (now <= (lastStartDateTime_ + durationTime_) && now >= lastStartDateTime_) { - ANSR_LOGI("now: %{public}" PRIu64 ", start: %{public}" PRIu64 ", end: %{public}" PRIu64 "", - now, lastStartDateTime_, lastStartDateTime_ + durationTime_); - return true; - } - if (now <= endDateTime_ && now >= startDateTime_) { - ANSR_LOGI("now: %{public}" PRIu64 ", start: %{public}" PRIu64 ", end: %{public}" PRIu64 "", - now, startDateTime_, endDateTime_); - return true; - } - return false; -} - -bool ReminderRequestCalendar::OnDateTimeChange() -{ - if (IsExpired()) { - return false; - } - if (startDateTime_ == endDateTime_) { - return ReminderRequest::OnDateTimeChange(); - } - uint64_t now = GetNowInstantMilli(); - if (now == 0) { - ANSR_LOGE("get now time failed"); - return false; - } - if (CheckCalenderIsExpired(now)) { - return GetTriggerTimeInMilli() <= now; - } else { - uint64_t triggerTime = GetNextTriggerTime(true); - SetTriggerTimeInMilli(triggerTime); - return false; - } -} - -bool ReminderRequestCalendar::IsRepeat() const -{ - return (repeatMonth_ > 0 && repeatDay_ > 0) || (repeatDaysOfWeek_ > 0); -} - -bool ReminderRequestCalendar::CheckExcludeDate() -{ - if (!IsRepeat()) { - // not repeat reminder - return false; - } - - if (IsInExcludeDate()) { - // in exclude date - uint64_t triggerTime = GetNextTriggerTime(true); - SetTriggerTimeInMilli(triggerTime); - return true; - } - return false; -} - -bool ReminderRequestCalendar::IsPullUpService() -{ - if (rruleWantAgentInfo_ == nullptr) { - return false; - } - - uint64_t now = GetNowInstantMilli(); - if (now == 0) { - ANSR_LOGE("get now time failed"); - return false; - } - - if (now >= startDateTime_) { - return true; - } - return false; -} - -bool ReminderRequestCalendar::IsNeedNotification() -{ - uint64_t now = GetNowInstantMilli(); - if (now == 0) { - ANSR_LOGE("get now time failed"); - return false; - } - if ((now <= endDateTime_ && now >= startDateTime_) || - (startDateTime_ == endDateTime_)) { - return true; - } - uint64_t triggerTime = GetNextTriggerTime(true); - SetTriggerTimeInMilli(triggerTime); - return false; -} - -void ReminderRequestCalendar::CalcLastStartDateTime() -{ - time_t t; - (void)time(&t); - struct tm nowTime; - (void)localtime_r(&t, &nowTime); - - t = static_cast(startDateTime_/MILLI_SECONDS); - struct tm startTime; - (void)localtime_r(&t, &startTime); - - startTime.tm_year = nowTime.tm_year; - startTime.tm_mon = nowTime.tm_mon; - startTime.tm_mday = nowTime.tm_mday; - time_t target = mktime(&startTime); - if (target != -1) { - lastStartDateTime_ = ReminderRequest::GetDurationSinceEpochInMilli(target); - } -} - -uint64_t ReminderRequestCalendar::GetNextTriggerTime(const bool updateLast) -{ - uint64_t triggerTimeInMilli = INVALID_LONG_LONG_VALUE; - time_t now; - (void)time(&now); // unit is seconds. - struct tm nowTime; - (void)localtime_r(&now, &nowTime); - nowTime.tm_sec = 0; - struct tm tarTime; - tarTime.tm_year = GetCTime(TimeTransferType::YEAR, firstDesignateYear_); - tarTime.tm_mon = GetCTime(TimeTransferType::MONTH, firstDesignateMonth_); - tarTime.tm_mday = firstDesignateDay_; - tarTime.tm_hour = hour_; - tarTime.tm_min = minute_; - tarTime.tm_sec = 0; - tarTime.tm_isdst = -1; - const time_t target = mktime(&tarTime); - ANSR_LOGD("Now time is: %{public}s", GetDateTimeInfo(now).c_str()); - if (repeatMonth_ > 0 && repeatDay_ > 0) { - triggerTimeInMilli = GetNextTriggerTimeAsRepeatReminder(nowTime, tarTime); - startDateTime_ = triggerTimeInMilli; - endDateTime_ = triggerTimeInMilli + durationTime_; - } else if (repeatDaysOfWeek_ > 0 && (target <= now)) { - nowTime.tm_hour = tarTime.tm_hour; - nowTime.tm_min = tarTime.tm_min; - nowTime.tm_sec = tarTime.tm_sec; - nowTime.tm_isdst = tarTime.tm_isdst; - const time_t tar = mktime(&nowTime); - triggerTimeInMilli = GetNextDaysOfWeek(now, tar); - startDateTime_ = triggerTimeInMilli; - endDateTime_ = triggerTimeInMilli + durationTime_; - } else { - ANSR_LOGD("tarTime: %{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d", - tarTime.tm_year, tarTime.tm_mon, tarTime.tm_mday, tarTime.tm_hour, tarTime.tm_min, tarTime.tm_sec); - if (target == -1) { - ANSR_LOGW("mktime return error."); - } - if (now < target) { - triggerTimeInMilli = ReminderRequest::GetDurationSinceEpochInMilli(target); - ANSR_LOGD("Next calendar time:%{public}s", GetDateTimeInfo(target).c_str()); - } - } - if (updateLast) { - lastStartDateTime_ = startDateTime_; - } else { - CalcLastStartDateTime(); - } - return triggerTimeInMilli; -} - -uint64_t ReminderRequestCalendar::GetNextTriggerTimeAsRepeatReminder(const tm &nowTime, const tm &tarTime) const -{ - uint64_t triggerTimeInMilli = INVALID_LONG_LONG_VALUE; - uint16_t setYear = static_cast(GetActualTime(TimeTransferType::YEAR, nowTime.tm_year)); - uint8_t setMonth = INVALID_U8_VALUE; - uint8_t setDay = INVALID_U8_VALUE; - uint8_t beginMonth = static_cast(GetActualTime(TimeTransferType::MONTH, nowTime.tm_mon)); - uint8_t count = 1; - uint16_t repeatMonthTmp = repeatMonth_; - for (uint8_t i = beginMonth; i < (MAX_MONTHS_OF_YEAR + beginMonth + 1); i++) { - if ((repeatMonthTmp & (1 << ((i - 1) % MAX_MONTHS_OF_YEAR))) > 0) { - setMonth = (i % MAX_MONTHS_OF_YEAR); - setMonth = setMonth == 0 ? DECEMBER : setMonth; - if (count != 1) { - setYear = setMonth <= beginMonth ? setYear + 1 : setYear; - } - setDay = GetNextDay(setYear, setMonth, nowTime, tarTime); - } - if (setDay != INVALID_U8_VALUE) { - break; - } - count++; - } - if ((triggerTimeInMilli = GetTimeInstantMilli(setYear, setMonth, setDay, hour_, minute_, second_)) - != INVALID_LONG_LONG_VALUE) { - ANSR_LOGD("Next calendar time:%{public}hu/%{public}hhu/%{public}hhu %{public}hhu:%{public}hhu:%{public}hhu", - setYear, setMonth, setDay, hour_, minute_, second_); - } - return triggerTimeInMilli; -} - -uint64_t ReminderRequestCalendar::GetTimeInstantMilli( - uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) const -{ - struct tm tar; - tar.tm_year = GetCTime(TimeTransferType::YEAR, year); - tar.tm_mon = GetCTime(TimeTransferType::MONTH, month); - tar.tm_mday = static_cast(day); - tar.tm_hour = static_cast(hour); - tar.tm_min = static_cast(minute); - tar.tm_sec = static_cast(second); - tar.tm_isdst = -1; - - ANSR_LOGD("tar: %{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d", - tar.tm_year, tar.tm_mon, tar.tm_mday, tar.tm_hour, tar.tm_min, tar.tm_sec); - const time_t target = mktime(&tar); - if (target == -1) { - ANSR_LOGW("mktime return error."); - return INVALID_LONG_LONG_VALUE; - } - return ReminderRequest::GetDurationSinceEpochInMilli(target); -} - -void ReminderRequestCalendar::InitDateTime() -{ - dateTime_.tm_year = GetCTime(TimeTransferType::YEAR, year_); - dateTime_.tm_mon = GetCTime(TimeTransferType::MONTH, month_); - dateTime_.tm_mday = static_cast(day_); - dateTime_.tm_hour = static_cast(hour_); - dateTime_.tm_min = static_cast(minute_); - dateTime_.tm_sec = static_cast(second_); - dateTime_.tm_isdst = -1; -} - -void ReminderRequestCalendar::InitDateTime(const tm &dateTime) -{ - dateTime_.tm_year = dateTime.tm_year; - dateTime_.tm_mon = dateTime.tm_mon; - dateTime_.tm_mday = dateTime.tm_mday; - dateTime_.tm_hour = dateTime.tm_hour; - dateTime_.tm_min = dateTime.tm_min; - dateTime_.tm_sec = dateTime.tm_sec; - dateTime_.tm_isdst = -1; - - year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime.tm_year)); - month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon)); - day_ = static_cast(dateTime.tm_mday); - hour_ = static_cast(dateTime.tm_hour); - minute_ = static_cast(dateTime.tm_min); - second_ = static_cast(dateTime.tm_sec); - - time_t time = mktime(&dateTime_); - if (time == -1) { - startDateTime_ = 0; - } else { - startDateTime_ = ReminderRequest::GetDurationSinceEpochInMilli(time); - endDateTime_ = startDateTime_; - } -} - -bool ReminderRequestCalendar::IsRepeatReminder() const -{ - return (repeatMonth_ > 0 && repeatDay_ > 0) || (repeatDaysOfWeek_ > 0) - || (GetTimeInterval() > 0 && GetSnoozeTimes() > 0); -} - -bool ReminderRequestCalendar::IsRepeatMonth(uint8_t month) const -{ - if (month > MAX_MONTHS_OF_YEAR) { - return false; - } - return (repeatMonth_ & (1 << (month - 1))) > 0; -} - -bool ReminderRequestCalendar::IsRepeatDay(uint8_t day) const -{ - if (day > MAX_DAYS_OF_MONTH) { - return false; - } - return (repeatDay_ & (1 << (day - 1))) > 0; -} - -void ReminderRequestCalendar::SetDay(const uint8_t &day, const bool &isSet) -{ - if (day < 1 || day > MAX_DAYS_OF_MONTH) { - return; - } - if (isSet) { - repeatDay_ |= 1 << (day - 1); - } else { - repeatDay_ &= ~(1 << (day - 1)); - } -} - -void ReminderRequestCalendar::SetMonth(const uint8_t &month, const bool &isSet) -{ - if (month < JANUARY || month > DECEMBER) { - return; - } - if (isSet) { - repeatMonth_ |= 1 << (month - 1); - } else { - repeatMonth_ &= ~ (1 << (month - 1)); - } -} - -void ReminderRequestCalendar::SetRepeatMonths(const std::vector &repeatMonths) -{ - if (repeatMonths.size() > MAX_MONTHS_OF_YEAR) { - ANSR_LOGW("The length of repeat months array should not larger than %{public}hhu", MAX_MONTHS_OF_YEAR); - return; - } - repeatMonth_ = 0; - for (auto it = repeatMonths.begin(); it != repeatMonths.end(); ++it) { - SetMonth((*it), true); - } -} - -void ReminderRequestCalendar::SetRepeatDaysOfMonth(const std::vector &repeatDays) -{ - if (repeatDays.size() > MAX_DAYS_OF_MONTH) { - ANSR_LOGW("The length of repeat days array should not larger than %{public}hhu", MAX_DAYS_OF_MONTH); - return; - } - repeatDay_ = 0; - for (auto it = repeatDays.begin(); it != repeatDays.end(); ++it) { - SetDay((*it), true); - } -} - -std::vector ReminderRequestCalendar::GetRepeatMonths() const -{ - std::vector repeatMonths; - for (int32_t i = 0; i < MAX_MONTHS_OF_YEAR; i++) { - if (IsRepeatMonth(i + 1)) { - repeatMonths.push_back(i + 1); - } - } - return repeatMonths; -} - -std::vector ReminderRequestCalendar::GetRepeatDays() const -{ - std::vector repeatDays; - for (int32_t i = 0; i < MAX_DAYS_OF_MONTH; i++) { - if (IsRepeatDay(i + 1)) { - repeatDays.push_back(i + 1); - } - } - return repeatDays; -} - -bool ReminderRequestCalendar::UpdateNextReminder() -{ - ANSR_LOGD("UpdateNextReminder calendar time"); - if (!IsRepeatReminder()) { - ANSR_LOGI("No need to update next trigger time as it is an one-time reminder."); - SetSnoozeTimesDynamic(GetSnoozeTimes()); - SetTriggerTimeInMilli(INVALID_LONG_LONG_VALUE); - if (startDateTime_ == endDateTime_) { - SetExpired(true); - } - return false; - } - uint8_t leftSnoozeTimes = GetSnoozeTimesDynamic(); - if (leftSnoozeTimes > 0 && (GetTimeInterval() > 0)) { - ANSR_LOGI("Left snooze times: %{public}d, update next triggerTime", leftSnoozeTimes); - SetTriggerTimeInMilli(GetTriggerTimeInMilli() + GetTimeInterval() * MILLI_SECONDS); - SetSnoozeTimesDynamic(--leftSnoozeTimes); - } else { - SetSnoozeTimesDynamic(GetSnoozeTimes()); - if ((repeatMonth_ == 0 || repeatDay_ == 0) && (repeatDaysOfWeek_ == 0)) { - ANSR_LOGI("Not a day repeat reminder, no need to update to next trigger time."); - SetTriggerTimeInMilli(INVALID_LONG_LONG_VALUE); - if (startDateTime_ == endDateTime_) { - SetExpired(true); - } - return false; - } else { - uint64_t nextTriggerTime = GetNextTriggerTime(); - if (nextTriggerTime != INVALID_LONG_LONG_VALUE) { - ANSR_LOGI("Set next trigger time successful, reset dynamic snoozeTimes"); - SetTriggerTimeInMilli(nextTriggerTime); - } else { - ANSR_LOGW("Set next trigger time invalidate"); - SetExpired(true); - return false; - } - } - } - return true; -} - -uint64_t ReminderRequestCalendar::PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) -{ - if (ignoreRepeat || (repeatMonth_ > 0 && repeatDay_ > 0) || (repeatDaysOfWeek_ > 0)) { - return GetNextTriggerTime(true); - } else { - return INVALID_LONG_LONG_VALUE; - } -} - -bool ReminderRequestCalendar::Marshalling(Parcel &parcel) const -{ - if (ReminderRequest::Marshalling(parcel)) { - // write int - WRITE_UINT16_RETURN_FALSE_LOG(parcel, year_, "year"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, month_, "month"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, day_, "day"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, hour_, "hour"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, minute_, "minute"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, second_, "second"); - WRITE_UINT16_RETURN_FALSE_LOG(parcel, repeatMonth_, "repeatMonth"); - WRITE_UINT32_RETURN_FALSE_LOG(parcel, repeatDay_, "repeatDay"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, durationTime_, "durationTime"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, startDateTime_, "startDateTime"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, endDateTime_, "endDateTime"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, lastStartDateTime_, "lastStartDateTime"); - WRITE_UINT16_RETURN_FALSE_LOG(parcel, firstDesignateYear_, "firstDesignateYear"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateMonth_, "firstDesignateMonth"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateDay_, "firstDesignateDay"); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, repeatDaysOfWeek_, "repeatDaysOfWeek"); - - bool rruleFlag = rruleWantAgentInfo_ == nullptr ? 0 : 1; - WRITE_BOOL_RETURN_FALSE_LOG(parcel, rruleFlag, "rruleFlag"); - if (rruleWantAgentInfo_ != nullptr) { - WRITE_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->pkgName, "rruleWantAgentInfo's pkgName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->abilityName, "rruleWantAgentInfo's abilityName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->uri, "rruleWantAgentInfo's uri"); - } - return true; - } - return false; -} - -ReminderRequestCalendar *ReminderRequestCalendar::Unmarshalling(Parcel &parcel) -{ - ANSR_LOGD("New calendar"); - auto objptr = new (std::nothrow) ReminderRequestCalendar(); - if (objptr == nullptr) { - ANS_LOGE("Failed to create reminder calendar due to no memory."); - return objptr; - } - if (!objptr->ReadFromParcel(parcel)) { - delete objptr; - objptr = nullptr; - } - return objptr; -} - -bool ReminderRequestCalendar::ReadFromParcel(Parcel &parcel) -{ - if (ReminderRequest::ReadFromParcel(parcel)) { - // read int - READ_UINT16_RETURN_FALSE_LOG(parcel, year_, "year"); - READ_UINT8_RETURN_FALSE_LOG(parcel, month_, "month"); - READ_UINT8_RETURN_FALSE_LOG(parcel, day_, "day"); - READ_UINT8_RETURN_FALSE_LOG(parcel, hour_, "hour"); - READ_UINT8_RETURN_FALSE_LOG(parcel, minute_, "minute"); - READ_UINT8_RETURN_FALSE_LOG(parcel, second_, "second"); - READ_UINT16_RETURN_FALSE_LOG(parcel, repeatMonth_, "repeatMonth"); - READ_UINT32_RETURN_FALSE_LOG(parcel, repeatDay_, "repeatDay"); - READ_UINT64_RETURN_FALSE_LOG(parcel, durationTime_, "durationTime"); - READ_UINT64_RETURN_FALSE_LOG(parcel, startDateTime_, "startDateTime"); - READ_UINT64_RETURN_FALSE_LOG(parcel, endDateTime_, "endDateTime"); - READ_UINT64_RETURN_FALSE_LOG(parcel, lastStartDateTime_, "lastStartDateTime"); - - InitDateTime(); - - READ_UINT16_RETURN_FALSE_LOG(parcel, firstDesignateYear_, "firstDesignateYear"); - READ_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateMonth_, "firstDesignateMonth"); - READ_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateDay_, "firstDesignateDay"); - READ_UINT8_RETURN_FALSE_LOG(parcel, repeatDaysOfWeek_, "repeatDaysOfWeek"); - - bool rruleFlag = false; - READ_BOOL_RETURN_FALSE_LOG(parcel, rruleFlag, "rruleFlag"); - if (rruleFlag) { - rruleWantAgentInfo_ = std::make_shared(); - READ_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->pkgName, "rruleWantAgentInfo's pkgName"); - READ_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->abilityName, "rruleWantAgentInfo's abilityName"); - READ_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->uri, "rruleWantAgentInfo's uri"); - } - return true; - } - return false; -} - -void ReminderRequestCalendar::SetDateTime(const uint64_t time) -{ - time_t t = static_cast(time / MILLI_SECONDS); - struct tm dateTime; - (void)localtime_r(&t, &dateTime); - - year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime.tm_year)); - month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon)); - day_ = static_cast(dateTime.tm_mday); - hour_ = static_cast(dateTime.tm_hour); - minute_ = static_cast(dateTime.tm_min); - second_ = static_cast(dateTime.tm_sec); - startDateTime_ = time; -} - -bool ReminderRequestCalendar::SetEndDateTime(const uint64_t time) -{ - if (time < startDateTime_) { - return false; - } - endDateTime_ = time; - durationTime_ = endDateTime_ - startDateTime_; - return true; -} - -uint64_t ReminderRequestCalendar::GetDateTime() const -{ - return startDateTime_; -} - -uint64_t ReminderRequestCalendar::GetEndDateTime() const -{ - return endDateTime_; -} - -void ReminderRequestCalendar::SetLastStartDateTime(const uint64_t time) -{ - lastStartDateTime_ = time; -} - -uint64_t ReminderRequestCalendar::GetLastStartDateTime() const -{ - return lastStartDateTime_; -} - -std::string ReminderRequestCalendar::SerializationRRule() -{ - constexpr int32_t INDENT = -1; - if (rruleWantAgentInfo_ == nullptr) { - return ""; - } - nlohmann::json root; - root["pkgName"] = rruleWantAgentInfo_->pkgName; - root["abilityName"] = rruleWantAgentInfo_->abilityName; - root["uri"] = rruleWantAgentInfo_->uri; - std::string str = root.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace); - return str; -} - -std::string ReminderRequestCalendar::SerializationExcludeDates() -{ - constexpr int32_t INDENT = -1; - nlohmann::json root; - root["excludeDates"] = nlohmann::json::array(); - for (auto date : excludeDates_) { - root["excludeDates"].push_back(date); - } - std::string str = root.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace); - return str; -} - -void ReminderRequestCalendar::DeserializationRRule(const std::string& str) -{ - if (str.empty()) { - return; - } - if (!nlohmann::json::accept(str)) { - ANSR_LOGW("not a json string!"); - return; - } - nlohmann::json root = nlohmann::json::parse(str, nullptr, false); - if (root.is_discarded()) { - ANSR_LOGW("parse json data failed!"); - return; - } - if (!root.contains("pkgName") || !root["pkgName"].is_string() || - !root.contains("abilityName") || !root["abilityName"].is_string() || - !root.contains("uri") || !root["uri"].is_string()) { - return; - } - - rruleWantAgentInfo_ = std::make_shared(); - rruleWantAgentInfo_->pkgName = root["pkgName"].get(); - rruleWantAgentInfo_->abilityName = root["abilityName"].get(); - rruleWantAgentInfo_->uri = root["uri"].get(); -} - -void ReminderRequestCalendar::DeserializationExcludeDates(const std::string& str) -{ - if (str.empty()) { - return; - } - if (!nlohmann::json::accept(str)) { - return; - } - nlohmann::json root = nlohmann::json::parse(str, nullptr, false); - if (root.is_discarded()) { - return; - } - - if (!root.contains("excludeDates") || !root["excludeDates"].is_array()) { - return; - } - excludeDates_.clear(); - for (auto date : root["excludeDates"]) { - if (date.is_number()) { - excludeDates_.insert(date.get()); - } - } -} -} -} diff --git a/frameworks/ans/src/reminder_request_timer.cpp b/frameworks/ans/src/reminder_request_timer.cpp deleted file mode 100644 index 867f26ae9266e07d45dfbef647b9779336bb7d17..0000000000000000000000000000000000000000 --- a/frameworks/ans/src/reminder_request_timer.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "reminder_request_timer.h" - -#include -#include - -#include "ans_log_wrapper.h" -#include "time_service_client.h" - -namespace OHOS { -namespace Notification { -ReminderRequestTimer::ReminderRequestTimer(uint64_t countDownTimeInSeconds) - : ReminderRequest(ReminderRequest::ReminderType::TIMER) -{ - CheckParamsValid(countDownTimeInSeconds); - countDownTimeInSeconds_ = countDownTimeInSeconds; - time_t now; // unit is seconds. - (void)time(&now); - ReminderRequest::SetTriggerTimeInMilli( - ReminderRequest::GetDurationSinceEpochInMilli(now) + countDownTimeInSeconds_ * ReminderRequest::MILLI_SECONDS); - sptr timer = MiscServices::TimeServiceClient::GetInstance(); - if (timer == nullptr) { - ANSR_LOGW("Failed to get boot time due to TimeServiceClient is null."); - } else { - int64_t bootTimeMs = timer->GetBootTimeMs(); - if (bootTimeMs >= 0) { - firstRealTimeInMilliSeconds_ = static_cast(bootTimeMs); - } else { - ANSR_LOGW("Get boot time error."); - } - } -} - -ReminderRequestTimer::ReminderRequestTimer(const ReminderRequestTimer &other) : ReminderRequest(other) -{ - firstRealTimeInMilliSeconds_ = other.firstRealTimeInMilliSeconds_; - countDownTimeInSeconds_ = other.countDownTimeInSeconds_; -} - -uint64_t ReminderRequestTimer::GetInitInfo() const -{ - return countDownTimeInSeconds_; -} - -void ReminderRequestTimer::SetInitInfo(const uint64_t countDownTimeInSeconds) -{ - countDownTimeInSeconds_ = countDownTimeInSeconds; -} - -uint64_t ReminderRequestTimer::PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) -{ - ANSR_LOGD("countdown time not support PreGetNextTriggerTimeIgnoreSnooze"); - return ReminderRequest::INVALID_LONG_LONG_VALUE; -} - -bool ReminderRequestTimer::OnDateTimeChange() -{ - UpdateTimeInfo("onDateTimeChange"); - return false; -} - -bool ReminderRequestTimer::OnTimeZoneChange() -{ - UpdateTimeInfo("onTimeZoneChange"); - return false; -} - -bool ReminderRequestTimer::UpdateNextReminder() -{ - ANSR_LOGD("countdown time not support repeat reminder, no need to update next triggerTime"); - SetExpired(true); - return false; -} - -void ReminderRequestTimer::CheckParamsValid(const uint64_t countDownTimeInSeconds) const -{ - if (countDownTimeInSeconds == 0 || countDownTimeInSeconds >= (UINT64_MAX / ReminderRequest::MILLI_SECONDS)) { - ANSR_LOGE("Illegal count down time, please check the description of the constructor"); - return; - } -} - -void ReminderRequestTimer::UpdateTimeInfo(const std::string &description) -{ - if (IsExpired()) { - return; - } - - ANSR_LOGD("%{public}s, update countdown time trigger time", description.c_str()); - time_t now; - (void)time(&now); // unit is seconds. - whenToChangeSysTime_ = ReminderRequest::GetDurationSinceEpochInMilli(now); - sptr timer = MiscServices::TimeServiceClient::GetInstance(); - if (timer == nullptr) { - ANSR_LOGW("Failed to updateTime info due to TimeServiceClient is null."); - return; - } - int64_t bootTime = timer->GetBootTimeMs(); - if (bootTime < 0) { - ANSR_LOGW("BootTime is illegal"); - return; - } - SetTriggerTimeInMilli(whenToChangeSysTime_ + countDownTimeInSeconds_ * MILLI_SECONDS - - (static_cast(bootTime) - firstRealTimeInMilliSeconds_)); -} - -bool ReminderRequestTimer::Marshalling(Parcel &parcel) const -{ - if (ReminderRequest::Marshalling(parcel)) { - // write int - WRITE_UINT64_RETURN_FALSE_LOG(parcel, firstRealTimeInMilliSeconds_, "firstRealTimeInMilliSeconds"); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, countDownTimeInSeconds_, "countDownTimeInSeconds"); - return true; - } - return false; -} - -ReminderRequestTimer *ReminderRequestTimer::Unmarshalling(Parcel &parcel) -{ - auto objptr = new (std::nothrow) ReminderRequestTimer(); - if (objptr == nullptr) { - ANSR_LOGE("Failed to create reminder timer due to no memory."); - return objptr; - } - if (!objptr->ReadFromParcel(parcel)) { - delete objptr; - objptr = nullptr; - } - return objptr; -} - -bool ReminderRequestTimer::ReadFromParcel(Parcel &parcel) -{ - if (ReminderRequest::ReadFromParcel(parcel)) { - // read int - READ_UINT64_RETURN_FALSE_LOG(parcel, firstRealTimeInMilliSeconds_, "firstRealTimeInMilliSeconds"); - READ_UINT64_RETURN_FALSE_LOG(parcel, countDownTimeInSeconds_, "countDownTimeInSeconds"); - return true; - } - return false; -} -} -} diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 2a1ae28808c50228aeafd85157c86377867e80ca..e503d8d65cd8ac965a18e4d79518b7e59513977f 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -652,62 +652,62 @@ public: */ virtual ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) = 0; - /** - * @brief Publishes a reminder notification. - * - * @param reminder Identifies the reminder notification request that needs to be published. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode PublishReminder(sptr &reminder) = 0; - - /** - * @brief Cancel a reminder notifications. - * - * @param reminderId Identifies the reminders id that needs to be canceled. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelReminder(const int32_t reminderId) = 0; - - /** - * @brief Get all valid reminder notifications. - * - * @param reminders Identifies the list of all valid notifications. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetValidReminders(std::vector> &reminders) = 0; - - /** - * @brief Cancel all reminder notifications. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelAllReminders() = 0; - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) = 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 dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) = 0; + // /** + // * @brief Publishes a reminder notification. + // * + // * @param reminder Identifies the reminder notification request that needs to be published. + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode PublishReminder(sptr &reminder) = 0; + + // /** + // * @brief Cancel a reminder notifications. + // * + // * @param reminderId Identifies the reminders id that needs to be canceled. + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode CancelReminder(const int32_t reminderId) = 0; + + // /** + // * @brief Get all valid reminder notifications. + // * + // * @param reminders Identifies the list of all valid notifications. + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode GetValidReminders(std::vector> &reminders) = 0; + + // /** + // * @brief Cancel all reminder notifications. + // * + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode CancelAllReminders() = 0; + + // /** + // * @brief Add exclude date for reminder + // * + // * @param reminderId Identifies the reminders id. + // * @param date exclude date + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) = 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 dates exclude dates + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) = 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 2c6afcea9e3f93c59b5aa5639f2c40facd777ade..db8df7d94a07c0ad5575879f220282416a04f783 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -649,62 +649,62 @@ public: */ ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override; - /** - * @brief Publishes a reminder notification. - * - * @param reminder Identifies the reminder notification request that needs to be published. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode PublishReminder(sptr &reminder) override; - - /** - * @brief Cancel a reminder notifications. - * - * @param reminderId Identifies the reminders id that needs to be canceled. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode CancelReminder(const int32_t reminderId) override; - - /** - * @brief Get all valid reminder notifications. - * - * @param reminders Identifies the list of all valid notifications. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode GetValidReminders(std::vector> &reminders) override; - - /** - * @brief Cancel all reminder notifications. - * - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode CancelAllReminders() override; - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) 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 dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; + // /** + // * @brief Publishes a reminder notification. + // * + // * @param reminder Identifies the reminder notification request that needs to be published. + // * @return Returns ERR_OK on success, others on failure. + // */ + // ErrCode PublishReminder(sptr &reminder) override; + + // /** + // * @brief Cancel a reminder notifications. + // * + // * @param reminderId Identifies the reminders id that needs to be canceled. + // * @return Returns ERR_OK on success, others on failure. + // */ + // ErrCode CancelReminder(const int32_t reminderId) override; + + // /** + // * @brief Get all valid reminder notifications. + // * + // * @param reminders Identifies the list of all valid notifications. + // * @return Returns ERR_OK on success, others on failure. + // */ + // ErrCode GetValidReminders(std::vector> &reminders) override; + + // /** + // * @brief Cancel all reminder notifications. + // * + // * @return Returns ERR_OK on success, others on failure. + // */ + // ErrCode CancelAllReminders() override; + + // /** + // * @brief Add exclude date for reminder + // * + // * @param reminderId Identifies the reminders id. + // * @param date exclude date + // * @return Returns ERR_OK on success, others on failure. + // */ + // ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) 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 dates exclude dates + // * @return Returns ERR_OK on success, others on failure. + // */ + // ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) 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 bdd0e5bbd636a5c306082e55af91a91225e13e6f..51650a7769a3deb54b919db53bfc2ac7219591c9 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -642,62 +642,62 @@ public: */ virtual ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override; - /** - * @brief Publishes a reminder notification. - * - * @param reminder Identifies the reminder notification request that needs to be published. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode PublishReminder(sptr &reminder) override; - - /** - * @brief Cancel a reminder notifications. - * - * @param reminderId Identifies the reminders id that needs to be canceled. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelReminder(const int32_t reminderId) override; - - /** - * @brief Get all valid reminder notifications. - * - * @param reminders Identifies the list of all valid notifications. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetValidReminders(std::vector> &reminders) override; - - /** - * @brief Cancel all reminder notifications. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelAllReminders() override; - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) 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 dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; + // /** + // * @brief Publishes a reminder notification. + // * + // * @param reminder Identifies the reminder notification request that needs to be published. + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode PublishReminder(sptr &reminder) override; + + // /** + // * @brief Cancel a reminder notifications. + // * + // * @param reminderId Identifies the reminders id that needs to be canceled. + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode CancelReminder(const int32_t reminderId) override; + + // /** + // * @brief Get all valid reminder notifications. + // * + // * @param reminders Identifies the list of all valid notifications. + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode GetValidReminders(std::vector> &reminders) override; + + // /** + // * @brief Cancel all reminder notifications. + // * + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode CancelAllReminders() override; + + // /** + // * @brief Add exclude date for reminder + // * + // * @param reminderId Identifies the reminders id. + // * @param date exclude date + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) 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 dates exclude dates + // * @return Returns ERR_OK on success, others on failure. + // */ + // virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; /** * @brief Checks whether this device is support template. @@ -1012,13 +1012,13 @@ private: ErrCode HandleGetDeviceRemindType(MessageParcel &data, MessageParcel &reply); ErrCode HandlePublishContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); ErrCode HandleCancelContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); - ErrCode HandlePublishReminder(MessageParcel &data, MessageParcel &reply); - 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 HandlePublishReminder(MessageParcel &data, MessageParcel &reply); + // 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 20287108d1d82cffd472e37936f2c6c37ce96070..cb70a6da4699c5efb0d0a2ce47237f2152e5c3d6 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -876,64 +876,7 @@ public: * @brief try to reconnect ans SA when SA manager OnAddSystemAbility called. */ void Reconnect(); - - /** - * @brief Publishes a scheduled reminder. - * - * @param reminder Indicates a reminder. - * @return Returns publish result. - */ - ErrCode PublishReminder(ReminderRequest &reminder); - - /** - * @brief Cancels a specified reminder. - * - * @param reminderId Indicates reminder Id. - * @return Returns cancel result. - */ - ErrCode CancelReminder(const int32_t reminderId); - - /** - * @brief Cancels all reminders of current third part application. - * - * @return Returns cancel result. - */ - ErrCode CancelAllReminders(); - - /** - * @brief Obtains all valid reminder notifications set by the current application. - * - * @param[out] validReminders Indicates the vector to store the result. - * @return Returns get valid reminders result. - */ - ErrCode GetValidReminders(std::vector> &validReminders); - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date); - - /** - * @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 dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); - + /** * @brief Checks whether this application has permission to publish notifications under the user. * diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 00fb37e7ee692b7dbe23bc0f2b79fea1c01a131c..5a141e4311282d4e263282c714c1f9591916c758 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -24,9 +24,6 @@ #include "iservice_registry.h" #include "notification_button_option.h" #include "notification_local_live_view_subscriber.h" -#include "reminder_request_alarm.h" -#include "reminder_request_calendar.h" -#include "reminder_request_timer.h" #include "system_ability_definition.h" #include "unique_fd.h" @@ -1340,103 +1337,6 @@ void AnsNotification::Reconnect() } } -ErrCode AnsNotification::PublishReminder(ReminderRequest &reminder) -{ - sptr tarReminder = nullptr; - switch (reminder.GetReminderType()) { - case (ReminderRequest::ReminderType::TIMER): { - ANSR_LOGI("Publish timer"); - ReminderRequestTimer &timer = (ReminderRequestTimer &)reminder; - tarReminder = new (std::nothrow) ReminderRequestTimer(timer); - break; - } - case (ReminderRequest::ReminderType::ALARM): { - ANSR_LOGI("Publish alarm"); - ReminderRequestAlarm &alarm = (ReminderRequestAlarm &)reminder; - tarReminder = new (std::nothrow) ReminderRequestAlarm(alarm); - break; - } - case (ReminderRequest::ReminderType::CALENDAR): { - ANSR_LOGI("Publish calendar"); - ReminderRequestCalendar &calendar = (ReminderRequestCalendar &)reminder; - tarReminder = new (std::nothrow) ReminderRequestCalendar(calendar); - break; - } - default: { - ANSR_LOGW("PublishReminder fail."); - return ERR_ANS_INVALID_PARAM; - } - } - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - ErrCode code = proxy->PublishReminder(tarReminder); - reminder.SetReminderId(tarReminder->GetReminderId()); - return code; -} - -ErrCode AnsNotification::CancelReminder(const int32_t reminderId) -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->CancelReminder(reminderId); -} - -ErrCode AnsNotification::CancelAllReminders() -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->CancelAllReminders(); -} - -ErrCode AnsNotification::GetValidReminders(std::vector> &validReminders) -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->GetValidReminders(validReminders); -} - -ErrCode AnsNotification::AddExcludeDate(const int32_t reminderId, const uint64_t date) -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->AddExcludeDate(reminderId, date); -} - -ErrCode AnsNotification::DelExcludeDates(const int32_t reminderId) -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->DelExcludeDates(reminderId); -} - -ErrCode AnsNotification::GetExcludeDates(const int32_t reminderId, std::vector& dates) -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->GetExcludeDates(reminderId, dates); -} - sptr AnsNotification::GetAnsManagerProxy() { sptr systemAbilityManager = diff --git a/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp b/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp index f5256f48615ad1873ebdb8d6118d77ca10481ffd..e5b32313d15f2c483e5e090a2d98de881baf83ab 100644 --- a/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp @@ -30,266 +30,266 @@ namespace OHOS { namespace Notification { -ErrCode AnsManagerProxy::PublishReminder(sptr &reminder) -{ - ANSR_LOGI("PublishReminder"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[PublishReminder] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - if (reminder == nullptr) { - ANSR_LOGW("[PublishReminder] fail: reminder is null ptr."); - return ERR_ANS_INVALID_PARAM; - } - if (!data.WriteUint8(static_cast(reminder->GetReminderType()))) { - ANSR_LOGE("[PublishReminder] fail: write reminder type failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!data.WriteParcelable(reminder)) { - ANSR_LOGE("[Publish] fail: write reminder parcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } +// ErrCode AnsManagerProxy::PublishReminder(sptr &reminder) +// { +// ANSR_LOGI("PublishReminder"); +// MessageParcel data; +// if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { +// ANSR_LOGE("[PublishReminder] fail: write interface token failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// if (reminder == nullptr) { +// ANSR_LOGW("[PublishReminder] fail: reminder is null ptr."); +// return ERR_ANS_INVALID_PARAM; +// } +// if (!data.WriteUint8(static_cast(reminder->GetReminderType()))) { +// ANSR_LOGE("[PublishReminder] fail: write reminder type failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// if (!data.WriteParcelable(reminder)) { +// ANSR_LOGE("[Publish] fail: write reminder parcelable failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::PUBLISH_REMINDER, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[PublishReminder] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - int32_t reminderId = -1; - if (!reply.ReadInt32(reminderId)) { - ANSR_LOGE("[PublishReminder] fail: read reminder id failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - reminder->SetReminderId(reminderId); - ANSR_LOGD("ReminderId=%{public}d", reminder->GetReminderId()); - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[PublishReminder] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} +// MessageParcel reply; +// MessageOption option = {MessageOption::TF_SYNC}; +// ErrCode result = InnerTransact(NotificationInterfaceCode::PUBLISH_REMINDER, option, data, reply); +// if (result != ERR_OK) { +// ANSR_LOGE("[PublishReminder] fail: transact ErrCode=%{public}d", result); +// return ERR_ANS_TRANSACT_FAILED; +// } +// int32_t reminderId = -1; +// if (!reply.ReadInt32(reminderId)) { +// ANSR_LOGE("[PublishReminder] fail: read reminder id failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// reminder->SetReminderId(reminderId); +// ANSR_LOGD("ReminderId=%{public}d", reminder->GetReminderId()); +// if (!reply.ReadInt32(result)) { +// ANSR_LOGE("[PublishReminder] fail: read result failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// return result; +// } -ErrCode AnsManagerProxy::CancelReminder(const int32_t reminderId) -{ - ANSR_LOGI("[CancelReminder]"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[CancelReminder] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!data.WriteInt32(reminderId)) { - ANSR_LOGE("[CancelReminder] fail: write reminder id failed"); - return ERR_ANS_PARCELABLE_FAILED; - } +// ErrCode AnsManagerProxy::CancelReminder(const int32_t reminderId) +// { +// ANSR_LOGI("[CancelReminder]"); +// MessageParcel data; +// if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { +// ANSR_LOGE("[CancelReminder] fail: write interface token failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// if (!data.WriteInt32(reminderId)) { +// ANSR_LOGE("[CancelReminder] fail: write reminder id failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_REMINDER, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[CancelReminder] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[CancelReminder] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} +// MessageParcel reply; +// MessageOption option = {MessageOption::TF_SYNC}; +// ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_REMINDER, option, data, reply); +// if (result != ERR_OK) { +// ANSR_LOGE("[CancelReminder] fail: transact ErrCode=%{public}d", result); +// return ERR_ANS_TRANSACT_FAILED; +// } +// if (!reply.ReadInt32(result)) { +// ANSR_LOGE("[CancelReminder] fail: read result failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// return result; +// } -ErrCode AnsManagerProxy::CancelAllReminders() -{ - ANSR_LOGI("[CancelAllReminders]"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[CancelAllReminders] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } +// ErrCode AnsManagerProxy::CancelAllReminders() +// { +// ANSR_LOGI("[CancelAllReminders]"); +// MessageParcel data; +// if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { +// ANSR_LOGE("[CancelAllReminders] fail: write interface token failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_ALL_REMINDERS, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[CancelAllReminders] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[CancelAllReminders] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} +// MessageParcel reply; +// MessageOption option = {MessageOption::TF_SYNC}; +// ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_ALL_REMINDERS, option, data, reply); +// if (result != ERR_OK) { +// ANSR_LOGE("[CancelAllReminders] fail: transact ErrCode=%{public}d", result); +// return ERR_ANS_TRANSACT_FAILED; +// } +// if (!reply.ReadInt32(result)) { +// ANSR_LOGE("[CancelAllReminders] fail: read result failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// return result; +// } -ErrCode AnsManagerProxy::GetValidReminders(std::vector> &reminders) -{ - ANSR_LOGI("[GetValidReminders]"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[GetValidReminders] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } +// ErrCode AnsManagerProxy::GetValidReminders(std::vector> &reminders) +// { +// ANSR_LOGI("[GetValidReminders]"); +// MessageParcel data; +// if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { +// ANSR_LOGE("[GetValidReminders] fail: write interface token failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[GetValidReminders] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - uint8_t count = 0; - if (!reply.ReadUint8(count)) { - ANSR_LOGE("[GetValidReminders] fail: read reminder count failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - ANSR_LOGD("[GetValidReminders] count=%{public}hhu", count); - reminders.clear(); - result = ReadReminders(count, reply, reminders); - if (result != ERR_OK) { - ANSR_LOGE("[GetValidReminders] fail: ReadReminders ErrCode=%{public}d", result); - return result; - } else { - ANSR_LOGD("[GetValidReminders], size=%{public}zu", reminders.size()); - } - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[GetValidReminders] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} +// MessageParcel reply; +// MessageOption option = {MessageOption::TF_SYNC}; +// ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS, option, data, reply); +// if (result != ERR_OK) { +// ANSR_LOGE("[GetValidReminders] fail: transact ErrCode=%{public}d", result); +// return ERR_ANS_TRANSACT_FAILED; +// } +// uint8_t count = 0; +// if (!reply.ReadUint8(count)) { +// ANSR_LOGE("[GetValidReminders] fail: read reminder count failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// ANSR_LOGD("[GetValidReminders] count=%{public}hhu", count); +// reminders.clear(); +// result = ReadReminders(count, reply, reminders); +// if (result != ERR_OK) { +// ANSR_LOGE("[GetValidReminders] fail: ReadReminders ErrCode=%{public}d", result); +// return result; +// } else { +// ANSR_LOGD("[GetValidReminders], size=%{public}zu", reminders.size()); +// } +// if (!reply.ReadInt32(result)) { +// ANSR_LOGE("[GetValidReminders] fail: read result failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// return result; +// } -ErrCode AnsManagerProxy::AddExcludeDate(const int32_t reminderId, const uint64_t date) -{ - 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(date)) { - ANSR_LOGE("[AddExcludeDate] fail: write exclude date failed"); - return ERR_ANS_PARCELABLE_FAILED; - } +// ErrCode AnsManagerProxy::AddExcludeDate(const int32_t reminderId, const uint64_t date) +// { +// 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(date)) { +// ANSR_LOGE("[AddExcludeDate] fail: write exclude date 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; -} +// 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; - } +// 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; -} +// 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& dates) -{ - 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; - } +// ErrCode AnsManagerProxy::GetExcludeDates(const int32_t reminderId, std::vector& dates) +// { +// 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 date count failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - ANSR_LOGD("[GetExcludeDates] count=%{public}hhu", count); - dates.clear(); - for (uint8_t i = 0; i < count; i++) { - uint64_t date = 0; - if (!reply.ReadUint64(date)) { - ANSR_LOGE("[GetExcludeDates] fail: read exclude date"); - return ERR_ANS_PARCELABLE_FAILED; - } - dates.push_back(date); - } - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[GetExcludeDates] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} +// 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 date count failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// ANSR_LOGD("[GetExcludeDates] count=%{public}hhu", count); +// dates.clear(); +// for (uint8_t i = 0; i < count; i++) { +// uint64_t date = 0; +// if (!reply.ReadUint64(date)) { +// ANSR_LOGE("[GetExcludeDates] fail: read exclude date"); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// dates.push_back(date); +// } +// 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) -{ - for (uint8_t i = 0; i < count; i++) { - uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); - if (!reply.ReadUint8(typeInfo)) { - ANSR_LOGE("Failed to read reminder type"); - return ERR_ANS_PARCELABLE_FAILED; - } - auto reminderType = static_cast(typeInfo); - sptr reminder; - if (ReminderRequest::ReminderType::ALARM == reminderType) { - ANSR_LOGD("[GetValidReminders] alarm"); - reminder = reply.ReadParcelable(); - } else if (ReminderRequest::ReminderType::TIMER == reminderType) { - ANSR_LOGD("[GetValidReminders] timer"); - reminder = reply.ReadParcelable(); - } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { - ANSR_LOGD("[GetValidReminders] calendar"); - reminder = reply.ReadParcelable(); - } else { - ANSR_LOGW("[GetValidReminders] type=%{public}hhu", typeInfo); - return ERR_ANS_INVALID_PARAM; - } - if (!reminder) { - ANSR_LOGE("[GetValidReminders] fail: Reminder ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - reminders.push_back(reminder); - } - return ERR_OK; -} +// ErrCode AnsManagerProxy::ReadReminders( +// uint8_t &count, MessageParcel &reply, std::vector> &reminders) +// { +// for (uint8_t i = 0; i < count; i++) { +// uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); +// if (!reply.ReadUint8(typeInfo)) { +// ANSR_LOGE("Failed to read reminder type"); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// auto reminderType = static_cast(typeInfo); +// sptr reminder; +// if (ReminderRequest::ReminderType::ALARM == reminderType) { +// ANSR_LOGD("[GetValidReminders] alarm"); +// reminder = reply.ReadParcelable(); +// } else if (ReminderRequest::ReminderType::TIMER == reminderType) { +// ANSR_LOGD("[GetValidReminders] timer"); +// reminder = reply.ReadParcelable(); +// } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { +// ANSR_LOGD("[GetValidReminders] calendar"); +// reminder = reply.ReadParcelable(); +// } else { +// ANSR_LOGW("[GetValidReminders] type=%{public}hhu", typeInfo); +// return ERR_ANS_INVALID_PARAM; +// } +// if (!reminder) { +// ANSR_LOGE("[GetValidReminders] fail: Reminder ReadParcelable failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// reminders.push_back(reminder); +// } +// return ERR_OK; +// } } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/src/manager/ans_manager_stub.cpp b/frameworks/core/src/manager/ans_manager_stub.cpp index ded5e9a9201c49dac9a2b017124423d647bc39ae..bf78dbec7c9a01f6a29ca8e5d6e1f1908b27a9d4 100644 --- a/frameworks/core/src/manager/ans_manager_stub.cpp +++ b/frameworks/core/src/manager/ans_manager_stub.cpp @@ -287,22 +287,22 @@ int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess result = HandleCancelContinuousTaskNotification(data, reply); break; } - case static_cast(NotificationInterfaceCode::PUBLISH_REMINDER): { - result = HandlePublishReminder(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::CANCEL_REMINDER): { - result = HandleCancelReminder(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::CANCEL_ALL_REMINDERS): { - result = HandleCancelAllReminders(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS): { - result = HandleGetValidReminders(data, reply); - break; - } + // case static_cast(NotificationInterfaceCode::PUBLISH_REMINDER): { + // result = HandlePublishReminder(data, reply); + // break; + // } + // case static_cast(NotificationInterfaceCode::CANCEL_REMINDER): { + // result = HandleCancelReminder(data, reply); + // break; + // } + // case static_cast(NotificationInterfaceCode::CANCEL_ALL_REMINDERS): { + // result = HandleCancelAllReminders(data, reply); + // break; + // } + // case static_cast(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS): { + // result = HandleGetValidReminders(data, reply); + // break; + // } case static_cast(NotificationInterfaceCode::IS_SUPPORT_TEMPLATE): { result = HandleIsSupportTemplate(data, reply); break; @@ -433,18 +433,18 @@ int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess break; } #endif - case static_cast(NotificationInterfaceCode::ADD_EXCLUDE_DATE_REMINDER): { - result = HandleAddExcludeDate(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::DEL_EXCLUDE_DATES_REMINDER): { - result = HandleDelExcludeDates(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::GET_EXCLUDE_DATES_REMINDER): { - result = HandleGetExcludeDates(data, reply); - break; - } + // case static_cast(NotificationInterfaceCode::ADD_EXCLUDE_DATE_REMINDER): { + // result = HandleAddExcludeDate(data, reply); + // break; + // } + // case static_cast(NotificationInterfaceCode::DEL_EXCLUDE_DATES_REMINDER): { + // result = HandleDelExcludeDates(data, reply); + // break; + // } + // case static_cast(NotificationInterfaceCode::GET_EXCLUDE_DATES_REMINDER): { + // result = HandleGetExcludeDates(data, reply); + // break; + // } case static_cast(NotificationInterfaceCode::GET_DONOTDISTURB_PROFILE): { result = HandleGetDoNotDisturbProfile(data, reply); break; @@ -1857,174 +1857,174 @@ ErrCode AnsManagerStub::HandleShellDump(MessageParcel &data, MessageParcel &repl return ERR_OK; } -ErrCode AnsManagerStub::HandlePublishReminder(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandlePublishReminder"); - uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); - if (!data.ReadUint8(typeInfo)) { - ANSR_LOGE("Failed to read reminder type"); - return ERR_ANS_PARCELABLE_FAILED; - } - ReminderRequest::ReminderType reminderType = static_cast(typeInfo); - sptr reminder; - if (ReminderRequest::ReminderType::ALARM == reminderType) { - ANSR_LOGD("Publish alarm"); - reminder = data.ReadParcelable(); - } else if (ReminderRequest::ReminderType::TIMER == reminderType) { - ANSR_LOGD("Publish timer"); - reminder = data.ReadParcelable(); - } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { - ANSR_LOGD("Publish calendar"); - reminder = data.ReadParcelable(); - } else { - ANSR_LOGE("Reminder type invalid"); - return ERR_ANS_INVALID_PARAM; - } - if (!reminder) { - ANSR_LOGE("Reminder ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - ErrCode result = PublishReminder(reminder); - - if (!reply.WriteInt32(reminder->GetReminderId())) { - ANSR_LOGE("Write back reminderId 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::HandleCancelReminder(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandleCancelReminder"); - int32_t reminderId = -1; - if (!data.ReadInt32(reminderId)) { - ANSR_LOGE("Read reminder id failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - ErrCode result = CancelReminder(reminderId); - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerStub::HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply) -{ - ErrCode result = CancelAllReminders(); - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerStub::HandleGetValidReminders(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandleGetValidReminders"); - std::vector> validReminders; - ErrCode result = GetValidReminders(validReminders); - - ANSR_LOGD("Write back size=%{public}zu", validReminders.size()); - if (!reply.WriteUint8(static_cast(validReminders.size()))) { - ANSR_LOGE("Write back reminder count failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - for (auto it = validReminders.begin(); it != validReminders.end(); ++it) { - sptr reminder = (*it); - uint8_t reminderType = static_cast(reminder->GetReminderType()); - ANSR_LOGD("ReminderType=%{public}d", reminderType); - if (!reply.WriteUint8(reminderType)) { - ANSR_LOGW("Write reminder type failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!reply.WriteParcelable(reminder)) { - ANSR_LOGW("Write reminder parcelable 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::HandleAddExcludeDate(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandleAddExcludeDate"); - int32_t reminderId = -1; - if (!data.ReadInt32(reminderId)) { - ANSR_LOGE("Read reminder id failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - uint64_t date = 0; - if (!data.ReadUint64(date)) { - ANSR_LOGE("Read exclude date failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - ErrCode result = AddExcludeDate(reminderId, date); - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerStub::HandleDelExcludeDates(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandleDelExcludeDates"); - int32_t reminderId = -1; - if (!data.ReadInt32(reminderId)) { - ANSR_LOGE("Read reminder id failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - ErrCode result = DelExcludeDates(reminderId); - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerStub::HandleGetExcludeDates(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandleGetExcludeDates"); - int32_t reminderId = -1; - if (!data.ReadInt32(reminderId)) { - ANSR_LOGE("Read reminder id failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - std::vector dates; - ErrCode result = GetExcludeDates(reminderId, dates); - ANSR_LOGD("Write back size=%{public}zu", dates.size()); - if (!reply.WriteUint8(static_cast(dates.size()))) { - ANSR_LOGE("Write back exclude date count failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - for (const auto date : dates) { - if (!reply.WriteUint64(date)) { - ANSR_LOGW("Write exclude date 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::HandlePublishReminder(MessageParcel &data, MessageParcel &reply) +// { +// ANSR_LOGI("HandlePublishReminder"); +// uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); +// if (!data.ReadUint8(typeInfo)) { +// ANSR_LOGE("Failed to read reminder type"); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// ReminderRequest::ReminderType reminderType = static_cast(typeInfo); +// sptr reminder; +// if (ReminderRequest::ReminderType::ALARM == reminderType) { +// ANSR_LOGD("Publish alarm"); +// reminder = data.ReadParcelable(); +// } else if (ReminderRequest::ReminderType::TIMER == reminderType) { +// ANSR_LOGD("Publish timer"); +// reminder = data.ReadParcelable(); +// } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { +// ANSR_LOGD("Publish calendar"); +// reminder = data.ReadParcelable(); +// } else { +// ANSR_LOGE("Reminder type invalid"); +// return ERR_ANS_INVALID_PARAM; +// } +// if (!reminder) { +// ANSR_LOGE("Reminder ReadParcelable failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } + +// ErrCode result = PublishReminder(reminder); + +// if (!reply.WriteInt32(reminder->GetReminderId())) { +// ANSR_LOGE("Write back reminderId 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::HandleCancelReminder(MessageParcel &data, MessageParcel &reply) +// { +// ANSR_LOGI("HandleCancelReminder"); +// int32_t reminderId = -1; +// if (!data.ReadInt32(reminderId)) { +// ANSR_LOGE("Read reminder id failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } + +// ErrCode result = CancelReminder(reminderId); +// if (!reply.WriteInt32(result)) { +// ANSR_LOGE("Write back result failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// return result; +// } + +// ErrCode AnsManagerStub::HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply) +// { +// ErrCode result = CancelAllReminders(); +// if (!reply.WriteInt32(result)) { +// ANSR_LOGE("Write back result failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// return result; +// } + +// ErrCode AnsManagerStub::HandleGetValidReminders(MessageParcel &data, MessageParcel &reply) +// { +// ANSR_LOGI("HandleGetValidReminders"); +// std::vector> validReminders; +// ErrCode result = GetValidReminders(validReminders); + +// ANSR_LOGD("Write back size=%{public}zu", validReminders.size()); +// if (!reply.WriteUint8(static_cast(validReminders.size()))) { +// ANSR_LOGE("Write back reminder count failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } + +// for (auto it = validReminders.begin(); it != validReminders.end(); ++it) { +// sptr reminder = (*it); +// uint8_t reminderType = static_cast(reminder->GetReminderType()); +// ANSR_LOGD("ReminderType=%{public}d", reminderType); +// if (!reply.WriteUint8(reminderType)) { +// ANSR_LOGW("Write reminder type failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// if (!reply.WriteParcelable(reminder)) { +// ANSR_LOGW("Write reminder parcelable 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::HandleAddExcludeDate(MessageParcel &data, MessageParcel &reply) +// { +// ANSR_LOGI("HandleAddExcludeDate"); +// int32_t reminderId = -1; +// if (!data.ReadInt32(reminderId)) { +// ANSR_LOGE("Read reminder id failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// uint64_t date = 0; +// if (!data.ReadUint64(date)) { +// ANSR_LOGE("Read exclude date failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } + +// ErrCode result = AddExcludeDate(reminderId, date); +// if (!reply.WriteInt32(result)) { +// ANSR_LOGE("Write back result failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// return result; +// } + +// ErrCode AnsManagerStub::HandleDelExcludeDates(MessageParcel &data, MessageParcel &reply) +// { +// ANSR_LOGI("HandleDelExcludeDates"); +// int32_t reminderId = -1; +// if (!data.ReadInt32(reminderId)) { +// ANSR_LOGE("Read reminder id failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } + +// ErrCode result = DelExcludeDates(reminderId); +// if (!reply.WriteInt32(result)) { +// ANSR_LOGE("Write back result failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } +// return result; +// } + +// ErrCode AnsManagerStub::HandleGetExcludeDates(MessageParcel &data, MessageParcel &reply) +// { +// ANSR_LOGI("HandleGetExcludeDates"); +// int32_t reminderId = -1; +// if (!data.ReadInt32(reminderId)) { +// ANSR_LOGE("Read reminder id failed."); +// return ERR_ANS_PARCELABLE_FAILED; +// } + +// std::vector dates; +// ErrCode result = GetExcludeDates(reminderId, dates); +// ANSR_LOGD("Write back size=%{public}zu", dates.size()); +// if (!reply.WriteUint8(static_cast(dates.size()))) { +// ANSR_LOGE("Write back exclude date count failed"); +// return ERR_ANS_PARCELABLE_FAILED; +// } + +// for (const auto date : dates) { +// if (!reply.WriteUint64(date)) { +// ANSR_LOGW("Write exclude date 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) { diff --git a/frameworks/core/src/manager/ans_manager_stub_invalid.cpp b/frameworks/core/src/manager/ans_manager_stub_invalid.cpp index e447bad8afe68a2c54b960192c0e84c1cd7219ed..62d5cea3d01f50d1c10229cb533e255932893415 100644 --- a/frameworks/core/src/manager/ans_manager_stub_invalid.cpp +++ b/frameworks/core/src/manager/ans_manager_stub_invalid.cpp @@ -454,47 +454,47 @@ ErrCode AnsManagerStub::CancelContinuousTaskNotification(const std::string &labe return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::PublishReminder(sptr &reminder) -{ - ANS_LOGE("AnsManagerStub::PublishReminder called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::CancelReminder(const int32_t reminderId) -{ - ANS_LOGE("AnsManagerStub::CancelReminder called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::GetValidReminders(std::vector> &reminders) -{ - ANS_LOGE("AnsManagerStub::getValidReminders called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::CancelAllReminders() -{ - ANS_LOGE("AnsManagerStub::cancelAllReminders called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::AddExcludeDate(const int32_t reminderId, const uint64_t date) -{ - 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& dates) -{ - ANS_LOGE("AnsManagerStub::GetExcludeDates called!"); - return ERR_INVALID_OPERATION; -} +// ErrCode AnsManagerStub::PublishReminder(sptr &reminder) +// { +// ANS_LOGE("AnsManagerStub::PublishReminder called!"); +// return ERR_INVALID_OPERATION; +// } + +// ErrCode AnsManagerStub::CancelReminder(const int32_t reminderId) +// { +// ANS_LOGE("AnsManagerStub::CancelReminder called!"); +// return ERR_INVALID_OPERATION; +// } + +// ErrCode AnsManagerStub::GetValidReminders(std::vector> &reminders) +// { +// ANS_LOGE("AnsManagerStub::getValidReminders called!"); +// return ERR_INVALID_OPERATION; +// } + +// ErrCode AnsManagerStub::CancelAllReminders() +// { +// ANS_LOGE("AnsManagerStub::cancelAllReminders called!"); +// return ERR_INVALID_OPERATION; +// } + +// ErrCode AnsManagerStub::AddExcludeDate(const int32_t reminderId, const uint64_t date) +// { +// 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& dates) +// { +// ANS_LOGE("AnsManagerStub::GetExcludeDates called!"); +// return ERR_INVALID_OPERATION; +// } ErrCode AnsManagerStub::IsSupportTemplate(const std::string &templateName, bool &support) { diff --git a/frameworks/js/napi/src/reminder/BUILD.gn b/frameworks/js/napi/src/reminder/BUILD.gn index 3bdbdddb193f63ffa574053ba0904ce4300a19bb..434e883af0d4638add668472ae58aab6ea31ceba 100644 --- a/frameworks/js/napi/src/reminder/BUILD.gn +++ b/frameworks/js/napi/src/reminder/BUILD.gn @@ -58,7 +58,10 @@ ohos_shared_library("reminderagent") { "reminder_common.cpp", ] - deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", + ] external_deps = [ "ability_base:want", diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index f45edf5d2a872a1beed29b1f0e762a20601dbb7d..c0349f4b195f21772e848c4db5a83d4789b05dde 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -53,19 +53,19 @@ struct AsyncCallbackInfo { napi_ref callback = nullptr; napi_value result = nullptr; int32_t reminderId = -1; - uint64_t excludeDate = 0; + int64_t excludeDate = 0; bool isThrow = false; NotificationNapi::NotificationConstant::SlotType inType = NotificationNapi::NotificationConstant::SlotType::CONTENT_INFORMATION; std::shared_ptr reminder = nullptr; - std::vector> validReminders; - std::vector excludeDates; + std::vector validReminders; + std::vector excludeDates; CallbackPromiseInfo info; }; struct Parameters { int32_t reminderId = -1; - uint64_t excludeDate = 0; + int64_t excludeDate = 0; int32_t errCode = ERR_OK; NotificationNapi::NotificationConstant::SlotType inType = NotificationNapi::NotificationConstant::SlotType::CONTENT_INFORMATION; @@ -805,7 +805,7 @@ napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi return NotificationNapi::Common::NapiGetBoolean(env, true); } -void GetValidRemindersInner(napi_env env, const std::vector>& validReminders, napi_value& arr) +void GetValidRemindersInner(napi_env env, const std::vector& validReminders, napi_value& arr) { int32_t count = 0; napi_create_array(env, &arr); @@ -816,7 +816,7 @@ void GetValidRemindersInner(napi_env env, const std::vector>& validReminders, napi_value& arr) +void GetAllValidRemindersInner(napi_env env, const std::vector& validReminders, napi_value& arr) { int32_t count = 0; napi_create_array(env, &arr); @@ -840,12 +840,12 @@ void GetAllValidRemindersInner(napi_env env, const std::vectorGetReminderId(), &reminderId); + napi_create_int32(env, reminder.GetReminderId(), &reminderId); napi_set_named_property(env, result, REMINDER_INFO_REMINDER_ID, reminderId); napi_set_element(env, arr, count, result); count++; @@ -1187,7 +1187,7 @@ napi_value ParseAddExcludeDateParameter(const napi_env &env, const napi_callback ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); return nullptr; } - params.excludeDate = static_cast(date); + params.excludeDate = static_cast(date); return NotificationNapi::Common::NapiGetNull(env); } @@ -1335,7 +1335,7 @@ napi_value DelExcludeDates(napi_env env, napi_callback_info info) return isCallback ? NotificationNapi::Common::NapiGetNull(env) : promise; } -void GetExcludeDatesInner(napi_env env, const std::vector& dates, napi_value& arr) +void GetExcludeDatesInner(napi_env env, const std::vector& dates, napi_value& arr) { int32_t count = 0; napi_create_array(env, &arr); diff --git a/interfaces/inner_api/reminder_helper.h b/interfaces/inner_api/reminder_helper.h index 553dea0c9f1ab73ad62f82c212b59a9024ac70a3..0dbd9e7b8d75dadb575ad5c1a5c34fe489d54cb2 100644 --- a/interfaces/inner_api/reminder_helper.h +++ b/interfaces/inner_api/reminder_helper.h @@ -72,7 +72,7 @@ public: * @param[out] validReminders Indicates an initial vector to receive the result. * @return Returns an array list containing all valid reminder notifications set by the current application. */ - static ErrCode GetValidReminders(std::vector> &validReminders); + static ErrCode GetValidReminders(std::vector &validReminders); /** * Creates a NotificationSlot. @@ -104,7 +104,7 @@ public: * @param date exclude date * @return Returns ERR_OK on success, others on failure. */ - static ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date); + static ErrCode AddExcludeDate(const int32_t reminderId, const int64_t date); /** * @brief Clear exclude date for reminder @@ -121,7 +121,7 @@ public: * @param dates exclude dates * @return Returns ERR_OK on success, others on failure. */ - static ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); + static ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); private: static bool CheckPermission(); diff --git a/my.diff b/my.diff new file mode 100644 index 0000000000000000000000000000000000000000..0f6eec674d7070d2771aa15d9a51ff6e37707ed1 --- /dev/null +++ b/my.diff @@ -0,0 +1,5055 @@ +diff --git a/bundle.json b/bundle.json +index f87567a6..e6e63487 100644 +--- a/bundle.json ++++ b/bundle.json +@@ -106,7 +106,8 @@ + "//base/notification/distributed_notification_service/frameworks/ans:ans_client", + "//base/notification/distributed_notification_service/frameworks/js/napi:napi_notification", + "//base/notification/distributed_notification_service/frameworks/js/napi:napi_reminder", +- "//base/notification/distributed_notification_service/interfaces/ndk:ohnotification" ++ "//base/notification/distributed_notification_service/interfaces/ndk:ohnotification", ++ "//base/notification/distributed_notification_service/frameworks/reminder:reminder_client" + ], + "service_group": [ + "//base/notification/distributed_notification_service/sa_profile:ans_sa_profile", +diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn +index 7fa6fe2a..0dd044b4 100644 +--- a/frameworks/ans/BUILD.gn ++++ b/frameworks/ans/BUILD.gn +@@ -111,11 +111,6 @@ ohos_shared_library("ans_innerkits") { + "${frameworks_module_ans_path}/src/notification_user_input.cpp", + "${frameworks_module_ans_path}/src/push_callback_stub.cpp", + "${frameworks_module_ans_path}/src/push_promise_callback.cpp", +- "${frameworks_module_ans_path}/src/reminder_helper.cpp", +- "${frameworks_module_ans_path}/src/reminder_request.cpp", +- "${frameworks_module_ans_path}/src/reminder_request_alarm.cpp", +- "${frameworks_module_ans_path}/src/reminder_request_calendar.cpp", +- "${frameworks_module_ans_path}/src/reminder_request_timer.cpp", + ] + + public_configs = [ ":ans_innerkits_public_config" ] +diff --git a/frameworks/ans/src/reminder_helper.cpp b/frameworks/ans/src/reminder_helper.cpp +deleted file mode 100644 +index 49298a07..00000000 +--- a/frameworks/ans/src/reminder_helper.cpp ++++ /dev/null +@@ -1,80 +0,0 @@ +-/* +- * Copyright (c) 2021-2022 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 "reminder_helper.h" +- +-#include "ans_log_wrapper.h" +-#include "ans_notification.h" +-#include "notification_helper.h" +-#include "singleton.h" +- +-namespace OHOS { +-namespace Notification { +-ErrCode ReminderHelper::PublishReminder(ReminderRequest &reminder) +-{ +- ANSR_LOGI("PublishReminder start"); +- NotificationHelper::AddSlotByType(reminder.GetSlotType()); +- return DelayedSingleton::GetInstance()->PublishReminder(reminder); +-} +- +-ErrCode ReminderHelper::CancelReminder(const int32_t reminderId) +-{ +- ANSR_LOGI("CancelReminder start"); +- return DelayedSingleton::GetInstance()->CancelReminder(reminderId); +-} +- +-ErrCode ReminderHelper::CancelAllReminders() +-{ +- ANSR_LOGI("CancelAllReminders start"); +- return DelayedSingleton::GetInstance()->CancelAllReminders(); +-} +- +-ErrCode ReminderHelper::GetValidReminders(std::vector> &validReminders) +-{ +- ANSR_LOGI("GetValidReminders start"); +- return DelayedSingleton::GetInstance()->GetValidReminders(validReminders); +-} +- +-ErrCode ReminderHelper::AddNotificationSlot(const NotificationSlot &slot) +-{ +- ANSR_LOGI("AddNotificationSlot start"); +- return DelayedSingleton::GetInstance()->AddNotificationSlot(slot); +-} +- +-ErrCode ReminderHelper::RemoveNotificationSlot(const NotificationConstant::SlotType &slotType) +-{ +- ANSR_LOGI("RemoveNotificationSlot start"); +- return DelayedSingleton::GetInstance()->RemoveNotificationSlot(slotType); +-} +- +-ErrCode ReminderHelper::AddExcludeDate(const int32_t reminderId, const uint64_t date) +-{ +- ANSR_LOGI("AddExcludeDate start"); +- return DelayedSingleton::GetInstance()->AddExcludeDate(reminderId, date); +-} +- +-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& dates) +-{ +- ANSR_LOGI("GetExcludeDates start"); +- return DelayedSingleton::GetInstance()->GetExcludeDates(reminderId, dates); +-} +-} +-} +\ No newline at end of file +diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp +deleted file mode 100644 +index 7603993b..00000000 +--- a/frameworks/ans/src/reminder_request.cpp ++++ /dev/null +@@ -1,1925 +0,0 @@ +-/* +- * Copyright (c) 2021-2022 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 "reminder_request.h" +- +-#include "ans_const_define.h" +-#include "ans_log_wrapper.h" +-#include "bundle_mgr_interface.h" +-#include "bundle_mgr_proxy.h" +-#include "if_system_ability_manager.h" +-#include "ipc_skeleton.h" +-#include "iservice_registry.h" +-#include "locale_config.h" +-#include "system_ability_definition.h" +-#include "want_agent_helper.h" +-#include "nlohmann/json.hpp" +-#include "want_params_wrapper.h" +- +-namespace OHOS { +-namespace Notification { +-namespace { +-const int32_t BASE_YEAR = 1900; +-const int32_t SINGLE_BUTTON_INVALID = 0; +-const int32_t SINGLE_BUTTON_JSONSTRING = 0; +-const int32_t SINGLE_BUTTON_ONLY_ONE = 1; +-const int32_t SINGLE_BUTTON_MIN_LEN = 2; +-const int32_t SINGLE_BUTTON_MAX_LEN = 4; +-const int32_t BUTTON_TYPE_INDEX = 0; +-const int32_t BUTTON_TITLE_INDEX = 1; +-const int32_t BUTTON_PKG_INDEX = 2; +-const int32_t BUTTON_ABILITY_INDEX = 3; +-const int32_t WANT_AGENT_URI_INDEX = 2; +-const int32_t INDENT = -1; +- +-const char* const PARAM_EXTRA_KEY = "NotificationRequest_extraInfo"; +-} +- +-int32_t ReminderRequest::GLOBAL_ID = 0; +-const uint64_t ReminderRequest::INVALID_LONG_LONG_VALUE = 0; +-const uint16_t ReminderRequest::INVALID_U16_VALUE = 0; +-const uint16_t ReminderRequest::MILLI_SECONDS = 1000; +-const uint16_t ReminderRequest::SAME_TIME_DISTINGUISH_MILLISECONDS = 1000; +-const uint32_t ReminderRequest::MIN_TIME_INTERVAL_IN_MILLI = 5 * 60 * 1000; +-const uint8_t ReminderRequest::INVALID_U8_VALUE = 0; +-const uint8_t ReminderRequest::REMINDER_STATUS_INACTIVE = 0; +-const uint8_t ReminderRequest::REMINDER_STATUS_ACTIVE = 1; +-const uint8_t ReminderRequest::REMINDER_STATUS_ALERTING = 2; +-const uint8_t ReminderRequest::REMINDER_STATUS_SHOWING = 4; +-const uint8_t ReminderRequest::REMINDER_STATUS_SNOOZE = 8; +-const uint8_t ReminderRequest::TIME_HOUR_OFFSET = 12; +-const std::string ReminderRequest::NOTIFICATION_LABEL = "REMINDER_AGENT"; +-const std::string ReminderRequest::REMINDER_EVENT_ALARM_ALERT = "ohos.event.notification.reminder.ALARM_ALERT"; +-const std::string ReminderRequest::REMINDER_EVENT_CLOSE_ALERT = "ohos.event.notification.reminder.CLOSE_ALERT"; +-const std::string ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT = "ohos.event.notification.reminder.SNOOZE_ALERT"; +-const std::string ReminderRequest::REMINDER_EVENT_CUSTOM_ALERT = "ohos.event.notification.reminder.COSTUM_ALERT"; +-const std::string ReminderRequest::REMINDER_EVENT_CLICK_ALERT = "ohos.event.notification.reminder.CLICK_ALERT"; +-const std::string ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT = "ohos.event.notification.reminder.ALERT_TIMEOUT"; +-const std::string ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION = +- "ohos.event.notification.reminder.REMOVE_NOTIFICATION"; +-const std::string ReminderRequest::PARAM_REMINDER_ID = "REMINDER_ID"; +-const std::string ReminderRequest::SEP_BUTTON_SINGLE = ""; +-const std::string ReminderRequest::SEP_BUTTON_MULTI = ""; +-const std::string ReminderRequest::SEP_WANT_AGENT = ""; +-const std::string ReminderRequest::SEP_BUTTON_VALUE_TYPE = ""; +-const std::string ReminderRequest::SEP_BUTTON_VALUE = ""; +-const std::string ReminderRequest::SEP_BUTTON_VALUE_BLOB = ""; +-const uint8_t ReminderRequest::DAYS_PER_WEEK = 7; +-const uint8_t ReminderRequest::MONDAY = 1; +-const uint8_t ReminderRequest::SUNDAY = 7; +-const uint8_t ReminderRequest::HOURS_PER_DAY = 24; +-const uint16_t ReminderRequest::SECONDS_PER_HOUR = 3600; +- +-template +-void GetJsonValue(const nlohmann::json& root, const std::string& name, T& value) +-{ +- using ValueType = std::remove_cv_t>; +- if constexpr (std::is_same_v) { +- if (!root.contains(name) || !root[name].is_string()) { +- value = T(); +- return; +- } +- value = root[name].get(); +- return; +- } +- value = T(); +-} +- +-inline static bool IsVaildButtonType(const std::string& type) +-{ +- // check action button type range +- if (type.size() != 1) { +- return false; +- } +- if (type[0] >= '0' && type[0] <= '3') { +- return true; +- } +- return false; +-} +- +-ReminderRequest::ReminderRequest() +-{ +- InitServerObj(); +-} +- +-ReminderRequest::ReminderRequest(const ReminderRequest &other) +-{ +- this->content_ = other.content_; +- this->expiredContent_ = other.expiredContent_; +- this->snoozeContent_ = other.snoozeContent_; +- this->displayContent_ = other.displayContent_; +- this->title_ = other.title_; +- this->isExpired_ = other.isExpired_; +- this->isSystemApp_ = other.isSystemApp_; +- this->snoozeTimes_ = other.snoozeTimes_; +- this->snoozeTimesDynamic_ = other.snoozeTimesDynamic_; +- this->state_ = other.state_; +- this->notificationId_ = other.notificationId_; +- this->reminderId_ = other.reminderId_; +- this->reminderTimeInMilli_ = other.reminderTimeInMilli_; +- this->ringDurationInMilli_ = other.ringDurationInMilli_; +- this->triggerTimeInMilli_ = other.triggerTimeInMilli_; +- this->timeIntervalInMilli_ = other.timeIntervalInMilli_; +- this->reminderType_ = other.reminderType_; +- this->slotType_ = other.slotType_; +- this->snoozeSlotType_ = other.snoozeSlotType_; +- this->notificationRequest_ = other.notificationRequest_; +- this->wantAgentInfo_ = other.wantAgentInfo_; +- this->maxScreenWantAgentInfo_ = other.maxScreenWantAgentInfo_; +- this->actionButtonMap_ = other.actionButtonMap_; +- this->tapDismissed_= other.tapDismissed_; +- this->autoDeletedTime_ = other.autoDeletedTime_; +- this->customButtonUri_ = other.customButtonUri_; +- this->groupId_ = other.groupId_; +- this->customRingUri_ = other.customRingUri_; +- this->creatorBundleName_ = other.creatorBundleName_; +-} +- +-ReminderRequest::ReminderRequest(int32_t reminderId) +-{ +- reminderId_ = reminderId; +- InitServerObj(); +-} +- +-ReminderRequest::ReminderRequest(ReminderType reminderType) +-{ +- reminderType_ = reminderType; +- InitServerObj(); +-} +- +-bool ReminderRequest::CanRemove() const +-{ +- if ((state_ & (REMINDER_STATUS_SHOWING | REMINDER_STATUS_ALERTING | REMINDER_STATUS_ACTIVE)) == 0) { +- return true; +- } +- return false; +-} +- +-bool ReminderRequest::CanShow() const +-{ +- // when system time change by user manually, and the reminde is to show immediately, +- // the show reminder just need to be triggered by ReminderDataManager#RefreshRemindersLocked(uint8_t). +- // we need to make the REMINDER_EVENT_ALARM_ALERT do nothing. +- uint64_t nowInstantMilli = GetNowInstantMilli(); +- if (nowInstantMilli == 0) { +- return false; +- } +- if (nowInstantMilli < (GetReminderTimeInMilli() + MIN_TIME_INTERVAL_IN_MILLI)) { +- return false; +- } +- return true; +-} +- +-std::string ReminderRequest::Dump() const +-{ +- const time_t nextTriggerTime = static_cast(triggerTimeInMilli_ / MILLI_SECONDS); +- std::string dateTimeInfo = GetTimeInfoInner(nextTriggerTime, TimeFormat::YMDHMS, true); +- return "Reminder[" +- "reminderId=" + std::to_string(reminderId_) + +- ", type=" + std::to_string(static_cast(reminderType_)) + +- ", state=" + GetState(state_) + +- ", nextTriggerTime=" + dateTimeInfo.c_str() + +- "]"; +-} +- +-ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type, +- const std::string &resource, const std::shared_ptr &buttonWantAgent, +- const std::shared_ptr &buttonDataShareUpdate) +-{ +- if ((type != ActionButtonType::CLOSE) && (type != ActionButtonType::SNOOZE) && (type != ActionButtonType::CUSTOM)) { +- ANSR_LOGI("Button type is not support: %{public}d.", static_cast(type)); +- return *this; +- } +- ActionButtonInfo actionButtonInfo; +- actionButtonInfo.type = type; +- actionButtonInfo.title = title; +- actionButtonInfo.resource = resource; +- actionButtonInfo.wantAgent = buttonWantAgent; +- actionButtonInfo.dataShareUpdate = buttonDataShareUpdate; +- +- actionButtonMap_.insert(std::pair(type, actionButtonInfo)); +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetContent(const std::string &content) +-{ +- content_ = content; +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetExpiredContent(const std::string &expiredContent) +-{ +- expiredContent_ = expiredContent; +- return *this; +-} +- +-void ReminderRequest::SetExpired(bool isExpired) +-{ +- isExpired_ = isExpired; +-} +- +-void ReminderRequest::InitCreatorBundleName(const std::string &creatorBundleName) +-{ +- creatorBundleName_ = creatorBundleName; +-} +- +-void ReminderRequest::InitCreatorUid(const int32_t creatorUid) +-{ +- creatorUid_ = creatorUid; +-} +- +-void ReminderRequest::InitReminderId() +-{ +- std::lock_guard lock(std::mutex); +- if (GLOBAL_ID < 0) { +- ANSR_LOGW("GLOBAL_ID overdule"); +- GLOBAL_ID = 0; +- } +- reminderId_ = ++GLOBAL_ID; +- ANSR_LOGI("reminderId_=%{public}d", reminderId_); +-} +- +-void ReminderRequest::InitUserId(const int32_t &userId) +-{ +- userId_ = userId; +-} +- +-void ReminderRequest::InitUid(const int32_t &uid) +-{ +- uid_ = uid; +-} +- +-void ReminderRequest::InitBundleName(const std::string &bundleName) +-{ +- bundleName_ = bundleName; +-} +- +-bool ReminderRequest::IsExpired() const +-{ +- return isExpired_; +-} +- +-bool ReminderRequest::IsShowing() const +-{ +- if ((state_ & REMINDER_STATUS_SHOWING) != 0) { +- return true; +- } +- return false; +-} +- +-void ReminderRequest::OnClose(bool updateNext) +-{ +- if ((state_ & REMINDER_STATUS_SHOWING) == 0) { +- ANSR_LOGE("onClose, the state of reminder is incorrect, state:%{public}s", GetState(state_).c_str()); +- return; +- } +- SetState(false, REMINDER_STATUS_SHOWING | REMINDER_STATUS_SNOOZE, "onClose()"); +- if ((state_ & REMINDER_STATUS_ALERTING) != 0) { +- SetState(false, REMINDER_STATUS_ALERTING, "onClose"); +- } +- if (updateNext) { +- uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false); +- if (nextTriggerTime == INVALID_LONG_LONG_VALUE) { +- isExpired_ = true; +- } else { +- SetTriggerTimeInMilli(nextTriggerTime); +- snoozeTimesDynamic_ = snoozeTimes_; +- } +- } +-} +- +-bool ReminderRequest::OnDateTimeChange() +-{ +- uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false); +- return HandleSysTimeChange(triggerTimeInMilli_, nextTriggerTime); +-} +- +-bool ReminderRequest::HandleSysTimeChange(uint64_t oriTriggerTime, uint64_t optTriggerTime) +-{ +- if (isExpired_) { +- return false; +- } +- uint64_t now = GetNowInstantMilli(); +- if (now == 0) { +- ANSR_LOGE("get now time failed."); +- return false; +- } +- if (oriTriggerTime == 0 && optTriggerTime < now) { +- ANSR_LOGW("trigger time is less than now time."); +- return false; +- } +- bool showImmediately = false; +- if (optTriggerTime != INVALID_LONG_LONG_VALUE && (optTriggerTime <= oriTriggerTime || oriTriggerTime == 0)) { +- // case1. switch to a previous time +- SetTriggerTimeInMilli(optTriggerTime); +- snoozeTimesDynamic_ = snoozeTimes_; +- } else { +- if (oriTriggerTime <= now) { +- // case2. switch to a future time, trigger time is less than now time. +- // when the reminder show immediately, trigger time will update in onShow function. +- snoozeTimesDynamic_ = 0; +- showImmediately = true; +- } else { +- // case3. switch to a future time, trigger time is larger than now time. +- showImmediately = false; +- } +- } +- return showImmediately; +-} +- +-bool ReminderRequest::HandleTimeZoneChange( +- uint64_t oldZoneTriggerTime, uint64_t newZoneTriggerTime, uint64_t optTriggerTime) +-{ +- if (isExpired_) { +- return false; +- } +- ANSR_LOGD("Handle timezone change, old:%{public}" PRIu64 ", new:%{public}" PRIu64 "", +- oldZoneTriggerTime, newZoneTriggerTime); +- if (oldZoneTriggerTime == newZoneTriggerTime) { +- return false; +- } +- bool showImmediately = false; +- if (optTriggerTime != INVALID_LONG_LONG_VALUE && oldZoneTriggerTime < newZoneTriggerTime) { +- // case1. timezone change to smaller +- SetTriggerTimeInMilli(optTriggerTime); +- snoozeTimesDynamic_ = snoozeTimes_; +- } else { +- // case2. timezone change to larger +- time_t now; +- (void)time(&now); // unit is seconds. +- if (static_cast(now) < 0) { +- ANSR_LOGE("Get now time error"); +- return false; +- } +- if (newZoneTriggerTime <= GetDurationSinceEpochInMilli(now)) { +- snoozeTimesDynamic_ = 0; +- showImmediately = true; +- } else { +- SetTriggerTimeInMilli(newZoneTriggerTime); +- showImmediately = false; +- } +- } +- return showImmediately; +-} +- +-void ReminderRequest::OnSameNotificationIdCovered() +-{ +- SetState(false, REMINDER_STATUS_ALERTING | REMINDER_STATUS_SHOWING | REMINDER_STATUS_SNOOZE, +- "OnSameNotificationIdCovered"); +-} +- +-void ReminderRequest::OnShow(bool isPlaySoundOrVibration, bool isSysTimeChanged, bool allowToNotify) +-{ +- if ((state_ & (REMINDER_STATUS_ACTIVE | REMINDER_STATUS_SNOOZE)) != 0) { +- SetState(false, REMINDER_STATUS_ACTIVE | REMINDER_STATUS_SNOOZE, "onShow()"); +- } +- if (isSysTimeChanged) { +- uint64_t nowInstantMilli = GetNowInstantMilli(); +- if (nowInstantMilli == 0) { +- ANSR_LOGW("Onshow, get now time error"); +- } +- reminderTimeInMilli_ = nowInstantMilli; +- } else { +- reminderTimeInMilli_ = triggerTimeInMilli_; +- } +- UpdateNextReminder(false); +- if (allowToNotify) { +- SetState(true, REMINDER_STATUS_SHOWING, "OnShow"); +- if (isPlaySoundOrVibration) { +- SetState(true, REMINDER_STATUS_ALERTING, "OnShow"); +- } +- UpdateNotificationStateForAlert(); +- } +-} +- +-void ReminderRequest::OnShowFail() +-{ +- SetState(false, REMINDER_STATUS_SHOWING, "OnShowFailed()"); +-} +- +-bool ReminderRequest::OnSnooze() +-{ +- if ((state_ & REMINDER_STATUS_SNOOZE) != 0) { +- ANSR_LOGW("onSnooze, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str()); +- return false; +- } +- if ((state_ & REMINDER_STATUS_ALERTING) != 0) { +- SetState(false, REMINDER_STATUS_ALERTING, "onSnooze()"); +- } +- SetSnoozeTimesDynamic(GetSnoozeTimes()); +- if (!UpdateNextReminder(true)) { +- return false; +- } +- UpdateNotificationStateForSnooze(); +- if (timeIntervalInMilli_ > 0) { +- SetState(true, REMINDER_STATUS_SNOOZE, "onSnooze()"); +- } +- return true; +-} +- +-void ReminderRequest::OnStart() +-{ +- if ((state_ & REMINDER_STATUS_ACTIVE) != 0) { +- ANSR_LOGE( +- "start failed, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str()); +- return; +- } +- if (isExpired_) { +- ANSR_LOGE("start failed, the reminder is expired"); +- return; +- } +- SetState(true, REMINDER_STATUS_ACTIVE, "OnStart()"); +-} +- +-void ReminderRequest::OnStop() +-{ +- ANSR_LOGI("Stop the previous active reminder, %{public}s", this->Dump().c_str()); +- if ((state_ & REMINDER_STATUS_ACTIVE) == 0) { +- ANSR_LOGW("onStop, the state of reminder is incorrect, state: %{public}s", (GetState(state_)).c_str()); +- return; +- } +- SetState(false, REMINDER_STATUS_ACTIVE, "OnStop"); +-} +- +-bool ReminderRequest::OnTerminate() +-{ +- if ((state_ & REMINDER_STATUS_ALERTING) == 0) { +- ANSR_LOGW("onTerminate, the state of reminder is %{public}s", (GetState(state_)).c_str()); +- return false; +- } +- SetState(false, REMINDER_STATUS_ALERTING, "onTerminate"); +- UpdateNotificationStateForAlert(); +- return true; +-} +- +-bool ReminderRequest::OnTimeZoneChange() +-{ +- time_t oldZoneTriggerTime = static_cast(triggerTimeInMilli_ / MILLI_SECONDS); +- struct tm *localOriTime = localtime(&oldZoneTriggerTime); +- if (localOriTime == nullptr) { +- ANSR_LOGE("oldZoneTriggerTime is null"); +- return false; +- } +- time_t newZoneTriggerTime = mktime(localOriTime); +- uint64_t nextTriggerTime = PreGetNextTriggerTimeIgnoreSnooze(true, false); +- return HandleTimeZoneChange( +- triggerTimeInMilli_, GetDurationSinceEpochInMilli(newZoneTriggerTime), nextTriggerTime); +-} +- +-void ReminderRequest::RecoverActionButtonJsonMode(const std::string &jsonString) +-{ +- if (!nlohmann::json::accept(jsonString)) { +- ANSR_LOGW("not a json string!"); +- return; +- } +- nlohmann::json root = nlohmann::json::parse(jsonString, nullptr, false); +- if (root.is_discarded()) { +- ANSR_LOGW("parse json data failed!"); +- return; +- } +- std::string type; +- GetJsonValue(root, "type", type); +- if (!IsVaildButtonType(type)) { +- ANSR_LOGW("unkown button type!"); +- return; +- } +- std::string title; +- GetJsonValue(root, "title", title); +- std::string resource; +- GetJsonValue(root, "resource", resource); +- auto buttonWantAgent = std::make_shared(); +- if (root.contains("wantAgent") && !root["wantAgent"].empty()) { +- nlohmann::json wantAgent = root["wantAgent"]; +- GetJsonValue(wantAgent, "pkgName", buttonWantAgent->pkgName); +- GetJsonValue(wantAgent, "abilityName", buttonWantAgent->abilityName); +- } +- auto buttonDataShareUpdate = std::make_shared(); +- if (root.contains("dataShareUpdate") && !root["dataShareUpdate"].empty()) { +- nlohmann::json dataShareUpdate = root["dataShareUpdate"]; +- GetJsonValue(dataShareUpdate, "uri", buttonDataShareUpdate->uri); +- GetJsonValue(dataShareUpdate, "equalTo", buttonDataShareUpdate->equalTo); +- GetJsonValue(dataShareUpdate, "valuesBucket", buttonDataShareUpdate->valuesBucket); +- } +- SetActionButton(title, ActionButtonType(std::stoi(type, nullptr)), +- resource, buttonWantAgent, buttonDataShareUpdate); +-} +- +-void ReminderRequest::DeserializeButtonInfo(const std::string& buttonInfoStr) +-{ +- std::vector multiButton = StringSplit(buttonInfoStr, SEP_BUTTON_MULTI); +- for (auto button : multiButton) { +- std::vector singleButton = StringSplit(button, SEP_BUTTON_SINGLE); +- if (singleButton.size() <= SINGLE_BUTTON_INVALID) { +- ANSR_LOGW("RecoverButton fail"); +- return; +- } +- if (singleButton.size() == SINGLE_BUTTON_ONLY_ONE) { +- std::string jsonString = singleButton.at(SINGLE_BUTTON_JSONSTRING); +- RecoverActionButtonJsonMode(jsonString); +- continue; +- } +- // old method Soon to be deleted +- if (singleButton.size() < SINGLE_BUTTON_MIN_LEN) { +- ANSR_LOGW("RecoverButton fail"); +- return; +- } +- auto buttonWantAgent = std::make_shared(); +- if (singleButton.size() == SINGLE_BUTTON_MAX_LEN) { +- buttonWantAgent->pkgName = singleButton.at(BUTTON_PKG_INDEX); +- buttonWantAgent->abilityName = singleButton.at(BUTTON_ABILITY_INDEX); +- } +- std::string resource = ""; +- auto buttonDataShareUpdate = std::make_shared(); +- SetActionButton(singleButton.at(BUTTON_TITLE_INDEX), +- ActionButtonType(std::atoi(singleButton.at(BUTTON_TYPE_INDEX).c_str())), +- resource, buttonWantAgent, buttonDataShareUpdate); +- ANSR_LOGI("RecoverButton title:%{public}s, pkgName:%{public}s, abilityName:%{public}s", +- singleButton.at(BUTTON_TITLE_INDEX).c_str(), buttonWantAgent->pkgName.c_str(), +- buttonWantAgent->abilityName.c_str()); +- } +-} +- +-std::vector ReminderRequest::StringSplit(std::string source, const std::string &split) +-{ +- std::vector result; +- if (source.empty()) { +- return result; +- } +- size_t pos = 0; +- while ((pos = source.find(split)) != std::string::npos) { +- std::string token = source.substr(0, pos); +- if (!token.empty()) { +- result.push_back(token); +- } +- source.erase(0, pos + split.length()); +- } +- if (!source.empty()) { +- result.push_back(source); +- } +- return result; +-} +- +-void ReminderRequest::RecoverWantAgentByJson(const std::string& wantAgentInfo, const uint8_t& type) +-{ +- nlohmann::json root = nlohmann::json::parse(wantAgentInfo, nullptr, false); +- if (root.is_discarded()) { +- ANSR_LOGW("parse json data failed"); +- return; +- } +- if (!root.contains("pkgName") || !root["pkgName"].is_string() || +- !root.contains("abilityName") || !root["abilityName"].is_string() || +- !root.contains("uri") || !root["uri"].is_string() || +- !root.contains("parameters") || !root["parameters"].is_string()) { +- return; +- } +- +- std::string pkgName = root.at("pkgName").get(); +- std::string abilityName = root.at("abilityName").get(); +- std::string uri = root.at("uri").get(); +- std::string parameters = root.at("parameters").get(); +- switch (type) { +- case WANT_AGENT_FLAG: { +- auto wai = std::make_shared(); +- wai->pkgName = pkgName; +- wai->abilityName = abilityName; +- wai->uri = uri; +- wai->parameters = AAFwk::WantParamWrapper::ParseWantParams(parameters); +- SetWantAgentInfo(wai); +- break; +- } +- case MAX_WANT_AGENT_FLAG: { +- auto maxScreenWantAgentInfo = std::make_shared(); +- maxScreenWantAgentInfo->pkgName = pkgName; +- maxScreenWantAgentInfo->abilityName = abilityName; +- SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); +- break; +- } +- default: { +- ANSR_LOGW("RecoverWantAgent type not support"); +- break; +- } +- } +-} +- +-void ReminderRequest::DeserializeWantAgent(const std::string &wantAgentInfo, const uint8_t type) +-{ +- if (nlohmann::json::accept(wantAgentInfo)) { +- RecoverWantAgentByJson(wantAgentInfo, type); +- return; +- } +- std::vector info = StringSplit(wantAgentInfo, ReminderRequest::SEP_WANT_AGENT); +- uint8_t minLen = 2; +- if (info.size() < minLen) { +- ANSR_LOGW("RecoverWantAgent fail"); +- return; +- } +- ANSR_LOGD("pkg=%{public}s, ability=%{public}s", info.at(0).c_str(), info.at(1).c_str()); +- switch (type) { +- case 0: { +- auto wai = std::make_shared(); +- wai->pkgName = info.at(0); +- wai->abilityName = info.at(1); +- if (info.size() > minLen) { +- wai->uri = info.at(WANT_AGENT_URI_INDEX); +- } +- SetWantAgentInfo(wai); +- break; +- } +- case 1: { +- auto maxScreenWantAgentInfo = std::make_shared(); +- maxScreenWantAgentInfo->pkgName = info.at(0); +- maxScreenWantAgentInfo->abilityName = info.at(1); +- SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); +- break; +- } +- default: { +- ANSR_LOGW("RecoverWantAgent type not support"); +- break; +- } +- } +-} +- +-ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo( +- const std::shared_ptr &maxScreenWantAgentInfo) +-{ +- maxScreenWantAgentInfo_ = maxScreenWantAgentInfo; +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetNotificationId(int32_t notificationId) +-{ +- notificationId_ = notificationId; +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetGroupId(const std::string &groupId) +-{ +- groupId_ = groupId; +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetSlotType(const NotificationConstant::SlotType &slotType) +-{ +- slotType_ = slotType; +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType) +-{ +- snoozeSlotType_ = snoozeSlotType; +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetSnoozeContent(const std::string &snoozeContent) +-{ +- snoozeContent_ = snoozeContent; +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetSnoozeTimes(const uint8_t snoozeTimes) +-{ +- snoozeTimes_ = snoozeTimes; +- SetSnoozeTimesDynamic(snoozeTimes); +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTimes) +-{ +- snoozeTimesDynamic_ = snooziTimes; +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds) +-{ +- if (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS)) { +- ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range"); +- timeIntervalInMilli_ = 0; +- } else { +- uint64_t timeIntervalInMilli = timeIntervalInSeconds * MILLI_SECONDS; +- if (timeIntervalInMilli > 0 && timeIntervalInMilli < MIN_TIME_INTERVAL_IN_MILLI) { +- ANSR_LOGW("SetTimeInterval, replace to set %{public}u, for the given is 0<%{public}" PRIu64 "<%{public}u", +- MIN_TIME_INTERVAL_IN_MILLI / MILLI_SECONDS, timeIntervalInSeconds, +- MIN_TIME_INTERVAL_IN_MILLI / MILLI_SECONDS); +- timeIntervalInMilli_ = MIN_TIME_INTERVAL_IN_MILLI; +- } else { +- timeIntervalInMilli_ = timeIntervalInMilli; +- } +- } +- return *this; +-} +- +-ReminderRequest& ReminderRequest::SetTitle(const std::string &title) +-{ +- title_ = title; +- return *this; +-} +- +-void ReminderRequest::SetTriggerTimeInMilli(uint64_t triggerTimeInMilli) +-{ +- triggerTimeInMilli_ = triggerTimeInMilli; +-} +- +-ReminderRequest& ReminderRequest::SetWantAgentInfo(const std::shared_ptr &wantAgentInfo) +-{ +- if (wantAgentInfo != nullptr) { +- wantAgentInfo_ = wantAgentInfo; +- } +- return *this; +-} +- +-bool ReminderRequest::ShouldShowImmediately() const +-{ +- uint64_t nowInstantMilli = GetNowInstantMilli(); +- if (nowInstantMilli == 0) { +- return false; +- } +- if (triggerTimeInMilli_ > nowInstantMilli) { +- return false; +- } +- return true; +-} +- +-std::map ReminderRequest::GetActionButtons( +- ) const +-{ +- return actionButtonMap_; +-} +- +-std::string ReminderRequest::GetCreatorBundleName() const +-{ +- return creatorBundleName_; +-} +- +-int32_t ReminderRequest::GetCreatorUid() const +-{ +- return creatorUid_; +-} +- +-std::string ReminderRequest::GetContent() const +-{ +- return content_; +-} +- +-std::string ReminderRequest::GetExpiredContent() const +-{ +- return expiredContent_; +-} +- +-std::shared_ptr ReminderRequest::GetMaxScreenWantAgentInfo() const +-{ +- return maxScreenWantAgentInfo_; +-} +- +-int32_t ReminderRequest::GetNotificationId() const +-{ +- return notificationId_; +-} +- +-std::string ReminderRequest::GetGroupId() const +-{ +- return groupId_; +-} +- +-sptr ReminderRequest::GetNotificationRequest() const +-{ +- return notificationRequest_; +-} +- +-int32_t ReminderRequest::GetReminderId() const +-{ +- return reminderId_; +-} +- +-uint64_t ReminderRequest::GetReminderTimeInMilli() const +-{ +- return reminderTimeInMilli_; +-} +- +-void ReminderRequest::SetReminderId(int32_t reminderId) +-{ +- reminderId_ = reminderId; +-} +- +-void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli) +-{ +- reminderTimeInMilli_ = reminderTimeInMilli; +-} +- +-ReminderRequest& ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds) +-{ +- uint64_t ringDuration = ringDurationInSeconds * MILLI_SECONDS; +- ringDurationInMilli_ = std::min(ringDuration, MAX_RING_DURATION); +- return *this; +-} +- +-NotificationConstant::SlotType ReminderRequest::GetSlotType() const +-{ +- return slotType_; +-} +- +-NotificationConstant::SlotType ReminderRequest::GetSnoozeSlotType() const +-{ +- return snoozeSlotType_; +-} +- +-std::string ReminderRequest::GetSnoozeContent() const +-{ +- return snoozeContent_; +-} +- +-uint8_t ReminderRequest::GetSnoozeTimes() const +-{ +- return snoozeTimes_; +-} +- +-uint8_t ReminderRequest::GetSnoozeTimesDynamic() const +-{ +- return snoozeTimesDynamic_; +-} +- +-uint8_t ReminderRequest::GetState() const +-{ +- return state_; +-} +- +-uint64_t ReminderRequest::GetTimeInterval() const +-{ +- return timeIntervalInMilli_ / MILLI_SECONDS; +-} +- +-std::string ReminderRequest::GetTitle() const +-{ +- return title_; +-} +- +-uint64_t ReminderRequest::GetTriggerTimeInMilli() const +-{ +- return triggerTimeInMilli_; +-} +- +-int32_t ReminderRequest::GetUserId() const +-{ +- return userId_; +-} +- +-int32_t ReminderRequest::GetUid() const +-{ +- return uid_; +-} +- +-std::string ReminderRequest::GetBundleName() const +-{ +- return bundleName_; +-} +- +-void ReminderRequest::SetReminderType(const ReminderType type) +-{ +- reminderType_ = type; +-} +- +-void ReminderRequest::SetState(const uint8_t state) +-{ +- state_ = state; +-} +- +-void ReminderRequest::SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek) +-{ +- repeatDaysOfWeek_ = repeatDaysOfWeek; +-} +- +-void ReminderRequest::SetSystemApp(bool isSystem) +-{ +- isSystemApp_ = isSystem; +-} +- +-bool ReminderRequest::IsSystemApp() const +-{ +- return isSystemApp_; +-} +- +-void ReminderRequest::SetTapDismissed(bool tapDismissed) +-{ +- tapDismissed_ = tapDismissed; +-} +- +-bool ReminderRequest::IsTapDismissed() const +-{ +- return tapDismissed_; +-} +- +-void ReminderRequest::SetAutoDeletedTime(int64_t autoDeletedTime) +-{ +- autoDeletedTime_ = autoDeletedTime; +-} +- +-int64_t ReminderRequest::GetAutoDeletedTime() const +-{ +- return autoDeletedTime_; +-} +- +-void ReminderRequest::SetCustomButtonUri(const std::string &uri) +-{ +- customButtonUri_ = uri; +-} +- +-std::string ReminderRequest::GetCustomButtonUri() const +-{ +- return customButtonUri_; +-} +- +-void ReminderRequest::SetCustomRingUri(const std::string &uri) +-{ +- customRingUri_ = uri; +-} +- +-std::string ReminderRequest::GetCustomRingUri() const +-{ +- return customRingUri_; +-} +- +-sptr ReminderRequest::GetNotificationBundleOption() const +-{ +- return notificationOption_; +-} +- +-void ReminderRequest::SetNotificationBundleOption(const sptr& option) +-{ +- notificationOption_ = option; +-} +- +-std::shared_ptr ReminderRequest::GetWantAgentInfo() const +-{ +- return wantAgentInfo_; +-} +- +-ReminderRequest::ReminderType ReminderRequest::GetReminderType() const +-{ +- return reminderType_; +-} +- +-uint16_t ReminderRequest::GetRingDuration() const +-{ +- return ringDurationInMilli_ / MILLI_SECONDS; +-} +- +-bool ReminderRequest::UpdateNextReminder() +-{ +- return false; +-} +- +-bool ReminderRequest::SetNextTriggerTime() +-{ +- return false; +-} +- +-void ReminderRequest::SetWantAgentStr(const std::string& wantStr) +-{ +- wantAgentStr_ = wantStr; +-} +- +-std::string ReminderRequest::GetWantAgentStr() +-{ +- return wantAgentStr_; +-} +- +-void ReminderRequest::SetMaxWantAgentStr(const std::string& maxWantStr) +-{ +- maxWantAgentStr_ = maxWantStr; +-} +- +-std::string ReminderRequest::GetMaxWantAgentStr() +-{ +- return maxWantAgentStr_; +-} +- +-void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std::string extra) +-{ +- switch (type) { +- case UpdateNotificationType::COMMON: { +- ANSR_LOGI("UpdateNotification common information"); +- if (extra == "snooze") { +- UpdateNotificationCommon(true); +- } else { +- UpdateNotificationCommon(false); +- } +- break; +- } +- case UpdateNotificationType::REMOVAL_WANT_AGENT: { +- ANSR_LOGI("UpdateNotification removal_want_agent"); +- AddRemovalWantAgent(); +- break; +- } +- case UpdateNotificationType::WANT_AGENT: { +- ANSR_LOGI("UpdateNotification want_agent"); +- AppExecFwk::ElementName wantAgent("", wantAgentInfo_->pkgName, wantAgentInfo_->abilityName); +- SetWantAgent(wantAgent); +- SetExtraInfo(wantAgentInfo_->parameters); +- break; +- } +- case UpdateNotificationType::MAX_SCREEN_WANT_AGENT: { +- ANSR_LOGI("UpdateNotification max_screen_want_agent"); +- AppExecFwk::ElementName maxScreenWantAgent( +- "", maxScreenWantAgentInfo_->pkgName, maxScreenWantAgentInfo_->abilityName); +- SetMaxScreenWantAgent(maxScreenWantAgent); +- break; +- } +- case UpdateNotificationType::BUNDLE_INFO: { +- ANSR_LOGI("UpdateNotification hap information"); +- UpdateNotificationBundleInfo(); +- break; +- } +- case UpdateNotificationType::CONTENT: { +- break; +- } +- default: +- break; +- } +-} +- +-bool ReminderRequest::MarshallingActionButton(Parcel& parcel) const +-{ +- // write map +- uint64_t actionButtonMapSize = static_cast(actionButtonMap_.size()); +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, actionButtonMapSize, "actionButtonMapSize"); +- for (auto button : actionButtonMap_) { +- uint8_t buttonType = static_cast(button.first); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.title, "buttonTitle"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.resource, "buttonResource"); +- +- if (button.second.wantAgent == nullptr) { +- ANSR_LOGE("button wantAgent is null"); +- return false; +- } +- +- WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->pkgName, "wantAgent's pkgName"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->abilityName, "wantAgent's abilityName"); +- +- if (button.second.dataShareUpdate == nullptr) { +- ANSR_LOGE("button dataShareUpdate is null"); +- return false; +- } +- WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->uri, +- "dataShareUpdate's uri"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->equalTo, +- "dataShareUpdate's equalTo"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->valuesBucket, +- "dataShareUpdate's valuesBucket"); +- } +- return true; +-} +- +-bool ReminderRequest::MarshallingWantParameters(Parcel& parcel, const AAFwk::WantParams& params) const +-{ +- if (params.Size() == 0) { +- if (!parcel.WriteInt32(VALUE_NULL)) { +- return false; +- } +- } else { +- if (!parcel.WriteInt32(VALUE_OBJECT)) { +- return false; +- } +- if (!parcel.WriteParcelable(¶ms)) { +- return false; +- } +- } +- return true; +-} +- +-bool ReminderRequest::Marshalling(Parcel &parcel) const +-{ +- // write string +- WRITE_STRING_RETURN_FALSE_LOG(parcel, content_, "content"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, expiredContent_, "expiredContent"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, snoozeContent_, "snoozeContent"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, title_, "title"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->abilityName, "wantAgentInfo's abilityName"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->pkgName, "wantAgentInfo's pkgName"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->uri, "wantAgentInfo's uri"); +- if (!MarshallingWantParameters(parcel, wantAgentInfo_->parameters)) { +- ANSR_LOGE("Failed to write wantAgentInfo's parameters"); +- return false; +- } +- WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->abilityName, "maxScreenWantAgentInfo's abilityName"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->pkgName, "maxScreenWantAgentInfo's pkgName"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, customButtonUri_, "customButtonUri"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, groupId_, "groupId"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, customRingUri_, "customRingUri"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, creatorBundleName_, "creatorBundleName"); +- +- // write bool +- WRITE_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); +- WRITE_BOOL_RETURN_FALSE_LOG(parcel, tapDismissed_, "tapDismissed"); +- +- // write int +- WRITE_INT64_RETURN_FALSE_LOG(parcel, autoDeletedTime_, "autoDeletedTime"); +- WRITE_INT32_RETURN_FALSE_LOG(parcel, reminderId_, "reminderId"); +- WRITE_INT32_RETURN_FALSE_LOG(parcel, notificationId_, "notificationId"); +- +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, triggerTimeInMilli_, "triggerTimeInMilli"); +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, timeIntervalInMilli_, "timeIntervalInMilli"); +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, ringDurationInMilli_, "ringDurationInMilli"); +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, reminderTimeInMilli_, "reminderTimeInMilli"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimes_, "snoozeTimes"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimesDynamic_, "snoozeTimesDynamic"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, state_, "state"); +- +- // write enum +- uint8_t reminderType = static_cast(reminderType_); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); +- +- int32_t slotType = static_cast(slotType_); +- WRITE_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); +- +- int32_t snoozeSlotType = static_cast(snoozeSlotType_); +- WRITE_INT32_RETURN_FALSE_LOG(parcel, snoozeSlotType, "snoozeSlotType"); +- +- if (!MarshallingActionButton(parcel)) { +- return false; +- } +- return true; +-} +- +-ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel) +-{ +- auto objptr = new (std::nothrow) ReminderRequest(); +- if (objptr == nullptr) { +- ANSR_LOGE("Failed to create reminder due to no memory."); +- return objptr; +- } +- if (!objptr->ReadFromParcel(parcel)) { +- delete objptr; +- objptr = nullptr; +- } +- return objptr; +-} +- +-bool ReminderRequest::ReadActionButtonFromParcel(Parcel& parcel) +-{ +- uint64_t buttonMapSize = 0; +- READ_UINT64_RETURN_FALSE_LOG(parcel, buttonMapSize, "actionButtonMapSize"); +- buttonMapSize = (buttonMapSize < MAX_ACTION_BUTTON_NUM) ? buttonMapSize : MAX_ACTION_BUTTON_NUM; +- for (uint64_t i = 0; i < buttonMapSize; i++) { +- uint8_t buttonType = static_cast(ActionButtonType::INVALID); +- READ_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); +- ActionButtonType type = static_cast(buttonType); +- std::string title = parcel.ReadString(); +- std::string resource = parcel.ReadString(); +- std::string pkgName = parcel.ReadString(); +- std::string abilityName = parcel.ReadString(); +- std::string uri = parcel.ReadString(); +- std::string equalTo = parcel.ReadString(); +- std::string valuesBucket = parcel.ReadString(); +- ActionButtonInfo info; +- info.type = type; +- info.title = title; +- info.resource = resource; +- info.wantAgent = std::make_shared(); +- if (info.wantAgent == nullptr) { +- return false; +- } +- info.wantAgent->pkgName = pkgName; +- info.wantAgent->abilityName = abilityName; +- info.dataShareUpdate = std::make_shared(); +- if (info.dataShareUpdate == nullptr) { +- return false; +- } +- info.dataShareUpdate->uri = uri; +- info.dataShareUpdate->equalTo = equalTo; +- info.dataShareUpdate->valuesBucket = valuesBucket; +- actionButtonMap_.insert(std::pair(type, info)); +- } +- return true; +-} +- +-bool ReminderRequest::ReadWantParametersFromParcel(Parcel& parcel, AAFwk::WantParams& wantParams) +-{ +- int empty = VALUE_NULL; +- if (!parcel.ReadInt32(empty)) { +- return false; +- } +- if (empty == VALUE_OBJECT) { +- auto params = parcel.ReadParcelable(); +- if (params != nullptr) { +- wantParams = *params; +- delete params; +- params = nullptr; +- } else { +- return false; +- } +- } +- return true; +-} +- +-bool ReminderRequest::ReadFromParcel(Parcel &parcel) +-{ +- READ_STRING_RETURN_FALSE_LOG(parcel, content_, "content"); +- READ_STRING_RETURN_FALSE_LOG(parcel, expiredContent_, "expiredContent"); +- READ_STRING_RETURN_FALSE_LOG(parcel, snoozeContent_, "snoozeContent"); +- READ_STRING_RETURN_FALSE_LOG(parcel, title_, "title"); +- READ_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->abilityName, "wantAgentInfo's abilityName"); +- READ_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->pkgName, "wantAgentInfo's pkgName"); +- READ_STRING_RETURN_FALSE_LOG(parcel, wantAgentInfo_->uri, "wantAgentInfo's uri"); +- if (!ReadWantParametersFromParcel(parcel, wantAgentInfo_->parameters)) { +- ANSR_LOGE("Failed to write wantAgentInfo's parameters"); +- return false; +- } +- READ_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->abilityName, "maxScreenWantAgentInfo's abilityName"); +- READ_STRING_RETURN_FALSE_LOG(parcel, maxScreenWantAgentInfo_->pkgName, "maxScreenWantAgentInfo's pkgName"); +- READ_STRING_RETURN_FALSE_LOG(parcel, customButtonUri_, "customButtonUri"); +- READ_STRING_RETURN_FALSE_LOG(parcel, groupId_, "groupId"); +- READ_STRING_RETURN_FALSE_LOG(parcel, customRingUri_, "customRingUri"); +- READ_STRING_RETURN_FALSE_LOG(parcel, creatorBundleName_, "creatorBundleName"); +- +- READ_BOOL_RETURN_FALSE_LOG(parcel, isExpired_, "isExpired"); +- READ_BOOL_RETURN_FALSE_LOG(parcel, tapDismissed_, "tapDismissed"); +- +- READ_INT64_RETURN_FALSE_LOG(parcel, autoDeletedTime_, "autoDeletedTime"); +- +- int32_t tempReminderId = -1; +- READ_INT32_RETURN_FALSE_LOG(parcel, tempReminderId, "reminderId"); +- reminderId_ = (tempReminderId == -1) ? reminderId_ : tempReminderId; +- +- READ_INT32_RETURN_FALSE_LOG(parcel, notificationId_, "notificationId"); +- +- READ_UINT64_RETURN_FALSE_LOG(parcel, triggerTimeInMilli_, "triggerTimeInMilli"); +- READ_UINT64_RETURN_FALSE_LOG(parcel, timeIntervalInMilli_, "timeIntervalInMilli"); +- READ_UINT64_RETURN_FALSE_LOG(parcel, ringDurationInMilli_, "ringDurationInMilli"); +- READ_UINT64_RETURN_FALSE_LOG(parcel, reminderTimeInMilli_, "reminderTimeInMilli"); +- +- READ_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimes_, "snoozeTimes"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimesDynamic_, "snoozeTimesDynamic"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, state_, "state"); +- +- uint8_t reminderType = static_cast(ReminderType::INVALID); +- READ_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); +- reminderType_ = static_cast(reminderType); +- +- int32_t slotType = static_cast(NotificationConstant::SlotType::OTHER); +- READ_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); +- slotType_ = static_cast(slotType); +- +- int32_t snoozeSlotType = static_cast(NotificationConstant::SlotType::OTHER); +- READ_INT32_RETURN_FALSE_LOG(parcel, snoozeSlotType, "snoozeSlotType"); +- snoozeSlotType_ = static_cast(snoozeSlotType); +- +- if (!ReadActionButtonFromParcel(parcel)) { +- return false; +- } +- +- if (!InitNotificationRequest()) { +- return false; +- } +- return true; +-} +- +-bool ReminderRequest::InitNotificationRequest() +-{ +- ANSR_LOGI("Init notification"); +- notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); +- if (notificationRequest_ == nullptr) { +- ANSR_LOGE("Failed to create notification."); +- return false; +- } +- displayContent_ = content_; +- return true; +-} +- +-void ReminderRequest::InitServerObj() +-{ +- wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; +- maxScreenWantAgentInfo_ = +- maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; +-} +- +-bool ReminderRequest::IsAlerting() const +-{ +- return (state_ & REMINDER_STATUS_ALERTING) != 0; +-} +- +-uint64_t ReminderRequest::GetDurationSinceEpochInMilli(const time_t target) +-{ +- auto tarEndTimePoint = std::chrono::system_clock::from_time_t(target); +- auto tarDuration = std::chrono::duration_cast(tarEndTimePoint.time_since_epoch()); +- int64_t tarDate = tarDuration.count(); +- if (tarDate < 0) { +- ANSR_LOGW("tarDuration is less than 0."); +- return INVALID_LONG_LONG_VALUE; +- } +- return static_cast(tarDate); +-} +- +-std::string ReminderRequest::GetDateTimeInfo(const time_t &timeInSecond) const +-{ +- return GetTimeInfoInner(timeInSecond, TimeFormat::YMDHMS, true); +-} +- +-std::string ReminderRequest::SerializeButtonInfo() const +-{ +- std::string info = ""; +- bool isFirst = true; +- for (auto button : actionButtonMap_) { +- if (!isFirst) { +- info += SEP_BUTTON_MULTI; +- } +- ActionButtonInfo buttonInfo = button.second; +- nlohmann::json root; +- root["type"] = std::to_string(static_cast(button.first)); +- root["title"] = buttonInfo.title; +- root["resource"] = buttonInfo.resource; +- if (buttonInfo.wantAgent != nullptr) { +- nlohmann::json wantAgentfriends; +- wantAgentfriends["pkgName"] = buttonInfo.wantAgent->pkgName; +- wantAgentfriends["abilityName"] = buttonInfo.wantAgent->abilityName; +- root["wantAgent"] = wantAgentfriends; +- } +- +- if (buttonInfo.dataShareUpdate != nullptr) { +- nlohmann::json dataShareUpdatefriends; +- dataShareUpdatefriends["uri"] = buttonInfo.dataShareUpdate->uri; +- dataShareUpdatefriends["equalTo"] = buttonInfo.dataShareUpdate->equalTo; +- dataShareUpdatefriends["valuesBucket"] = buttonInfo.dataShareUpdate->valuesBucket; +- root["dataShareUpdate"] = dataShareUpdatefriends; +- } +- std::string str = root.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace); +- info += str; +- isFirst = false; +- } +- return info; +-} +- +-uint64_t ReminderRequest::GetNowInstantMilli() const +-{ +- time_t now; +- (void)time(&now); // unit is seconds. +- if (static_cast(now) < 0) { +- ANSR_LOGE("Get now time error"); +- return 0; +- } +- return GetDurationSinceEpochInMilli(now); +-} +- +-std::string ReminderRequest::GetShowTime(const uint64_t showTime) const +-{ +- if (reminderType_ == ReminderType::TIMER) { +- return ""; +- } +- return GetTimeInfoInner(static_cast(showTime / MILLI_SECONDS), TimeFormat::HM, false); +-} +- +-std::string ReminderRequest::GetTimeInfoInner(const time_t &timeInSecond, const TimeFormat &format, +- bool keep24Hour) const +-{ +- const uint8_t dateTimeLen = 80; +- char dateTimeBuffer[dateTimeLen]; +- struct tm timeInfo; +- (void)localtime_r(&timeInSecond, &timeInfo); +- bool is24HourClock = OHOS::Global::I18n::LocaleConfig::Is24HourClock(); +- if (!is24HourClock && timeInfo.tm_hour > TIME_HOUR_OFFSET && !keep24Hour) { +- timeInfo.tm_hour -= TIME_HOUR_OFFSET; +- } +- switch (format) { +- case TimeFormat::YMDHMS: { +- (void)strftime(dateTimeBuffer, dateTimeLen, "%Y-%m-%d %H:%M:%S", &timeInfo); +- break; +- } +- case TimeFormat::HM: { +- (void)strftime(dateTimeBuffer, dateTimeLen, "%H:%M", &timeInfo); +- break; +- } +- default: { +- ANSR_LOGW("Time format not support."); +- break; +- } +- } +- std::string dateTimeInfo(dateTimeBuffer); +- return dateTimeInfo; +-} +- +-std::string ReminderRequest::GetState(const uint8_t state) const +-{ +- std::string stateInfo = "'"; +- if (state == REMINDER_STATUS_INACTIVE) { +- stateInfo += "Inactive"; +- } else { +- bool hasSeparator = false; +- if ((state & REMINDER_STATUS_ACTIVE) != 0) { +- stateInfo += "Active"; +- hasSeparator = true; +- } +- if ((state & REMINDER_STATUS_ALERTING) != 0) { +- if (hasSeparator) { +- stateInfo += ","; +- } +- stateInfo += "Alerting"; +- hasSeparator = true; +- } +- if ((state & REMINDER_STATUS_SHOWING) != 0) { +- if (hasSeparator) { +- stateInfo += ","; +- } +- stateInfo += "Showing"; +- hasSeparator = true; +- } +- if ((state & REMINDER_STATUS_SNOOZE) != 0) { +- if (hasSeparator) { +- stateInfo += ","; +- } +- stateInfo += "Snooze"; +- } +- } +- stateInfo += "'"; +- return stateInfo; +-} +- +-void ReminderRequest::AddActionButtons(const bool includeSnooze) +-{ +- int32_t requestCode = 10; +- std::vector flags; +- flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); +- for (auto button : actionButtonMap_) { +- auto want = std::make_shared(); +- auto type = button.first; +- switch (type) { +- case ActionButtonType::CLOSE: +- want->SetAction(REMINDER_EVENT_CLOSE_ALERT); +- break; +- case ActionButtonType::SNOOZE: +- if (includeSnooze) { +- want->SetAction(REMINDER_EVENT_SNOOZE_ALERT); +- } else { +- ANSR_LOGD("Not add action button, type is snooze, as includeSnooze is false"); +- continue; +- } +- break; +- case ActionButtonType::CUSTOM: +- want->SetAction(REMINDER_EVENT_CUSTOM_ALERT); +- if (button.second.wantAgent == nullptr) { +- return; +- } +- want->SetParam("PkgName", button.second.wantAgent->pkgName); +- want->SetParam("AbilityName", button.second.wantAgent->abilityName); +- break; +- default: +- break; +- } +- want->SetParam(PARAM_REMINDER_ID, reminderId_); +- std::vector> wants; +- wants.push_back(want); +- auto title = static_cast(button.second.title); +- AbilityRuntime::WantAgent::WantAgentInfo buttonWantAgentInfo( +- requestCode, +- AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, +- flags, +- wants, +- nullptr +- ); +- +- std::string identity = IPCSkeleton::ResetCallingIdentity(); +- std::shared_ptr buttonWantAgent = +- AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo, userId_); +- IPCSkeleton::SetCallingIdentity(identity); +- +- std::shared_ptr actionButton +- = NotificationActionButton::Create(nullptr, title, buttonWantAgent); +- notificationRequest_->AddActionButton(actionButton); +- } +-} +- +-void ReminderRequest::AddRemovalWantAgent() +-{ +- int32_t requestCode = 10; +- std::vector flags; +- flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); +- auto want = std::make_shared(); +- want->SetAction(REMINDER_EVENT_REMOVE_NOTIFICATION); +- want->SetParam(PARAM_REMINDER_ID, reminderId_); +- std::vector> wants; +- wants.push_back(want); +- AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( +- requestCode, +- AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, +- flags, +- wants, +- nullptr +- ); +- +- std::string identity = IPCSkeleton::ResetCallingIdentity(); +- std::shared_ptr wantAgent = +- AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); +- IPCSkeleton::SetCallingIdentity(identity); +- +- notificationRequest_->SetRemovalWantAgent(wantAgent); +-} +- +-std::shared_ptr ReminderRequest::CreateWantAgent( +- AppExecFwk::ElementName &element) const +-{ +- int32_t requestCode = 10; +- std::vector wantFlags; +- wantFlags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); +- auto want = std::make_shared(); +- want->SetAction(REMINDER_EVENT_CLICK_ALERT); +- want->SetParam(PARAM_REMINDER_ID, reminderId_); +- std::vector> wantes; +- wantes.push_back(want); +- AbilityRuntime::WantAgent::WantAgentInfo wantInfo( +- requestCode, +- AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, +- wantFlags, +- wantes, +- nullptr +- ); +- std::string callingIdentity = IPCSkeleton::ResetCallingIdentity(); +- auto wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantInfo, userId_); +- IPCSkeleton::SetCallingIdentity(callingIdentity); +- return wantAgent; +-} +- +-std::shared_ptr ReminderRequest::CreateMaxWantAgent( +- AppExecFwk::ElementName &element) const +-{ +- int32_t requestCode = 10; +- std::vector flags; +- flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); +- auto want = std::make_shared(); +- want->SetElement(element); +- std::vector> wants; +- wants.push_back(want); +- AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( +- requestCode, +- AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITY, +- flags, +- wants, +- nullptr +- ); +- std::string identity = IPCSkeleton::ResetCallingIdentity(); +- auto wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); +- IPCSkeleton::SetCallingIdentity(identity); +- return wantAgent; +-} +- +-void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element) +-{ +- std::shared_ptr wantAgent = CreateMaxWantAgent(element); +- notificationRequest_->SetMaxScreenWantAgent(wantAgent); +-} +- +-void ReminderRequest::SetWantAgent(AppExecFwk::ElementName &element) +-{ +- std::shared_ptr wantAgent = CreateWantAgent(element); +- notificationRequest_->SetWantAgent(wantAgent); +-} +- +-void ReminderRequest::SetExtraInfo(const AAFwk::WantParams& params) +-{ +- if (params.HasParam(PARAM_EXTRA_KEY)) { +- std::shared_ptr extras = std::make_shared( +- params.GetWantParams(PARAM_EXTRA_KEY)); +- notificationRequest_->SetAdditionalData(extras); +- } +-} +- +-void ReminderRequest::SetState(bool deSet, const uint8_t newState, std::string function) +-{ +- uint8_t oldState = state_; +- if (deSet) { +- state_ |= newState; +- } else { +- state_ &= static_cast(~newState); +- } +- ANSR_LOGI("Switch the reminder(reminderId=%{public}d) state, from %{public}s to %{public}s, called by %{public}s", +- reminderId_, GetState(oldState).c_str(), GetState(state_).c_str(), function.c_str()); +-} +- +-void ReminderRequest::SetStateToInActive() +-{ +- SetState(false, (REMINDER_STATUS_SHOWING | REMINDER_STATUS_ALERTING | REMINDER_STATUS_ACTIVE), +- "SetStateToInActive"); +-} +- +-void ReminderRequest::UpdateActionButtons(const bool &setSnooze) +-{ +- if (notificationRequest_ == nullptr) { +- ANSR_LOGE("updateActionButtons failed, the notificationRequest is null"); +- return; +- } +- notificationRequest_->ClearActionButtons(); +- if (setSnooze) { +- AddActionButtons(false); +- } else { +- AddActionButtons(true); +- } +-} +- +-bool ReminderRequest::UpdateNextReminder(const bool &force) +-{ +- bool result = true; +- if (force) { +- uint64_t nowInstantMilli = GetNowInstantMilli(); +- if (nowInstantMilli == 0) { +- result = false; +- } else { +- if (timeIntervalInMilli_ != 0) { +- triggerTimeInMilli_ = nowInstantMilli + timeIntervalInMilli_; +- snoozeTimesDynamic_ = snoozeTimes_; +- isExpired_ = false; +- } +- } +- } else { +- result = UpdateNextReminder(); +- } +- std::string info = result ? "success" : "no next"; +- ANSR_LOGI("updateNextReminder(id=%{public}d, %{public}s): force=%{public}d, trigger time is: %{public}s", +- reminderId_, info.c_str(), force, +- GetDateTimeInfo(static_cast(triggerTimeInMilli_ / MILLI_SECONDS)).c_str()); +- return result; +-} +- +-void ReminderRequest::UpdateNotificationCommon(bool isSnooze) +-{ +- time_t now; +- (void)time(&now); // unit is seconds. +- notificationRequest_->SetDeliveryTime(GetDurationSinceEpochInMilli(now)); +- notificationRequest_->SetLabel(NOTIFICATION_LABEL); +- notificationRequest_->SetShowDeliveryTime(true); +- if (isSnooze) { +- if (snoozeSlotType_ == NotificationConstant::SlotType::OTHER) { +- notificationRequest_->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); +- } else { +- notificationRequest_->SetSlotType(snoozeSlotType_); +- } +- } else { +- notificationRequest_->SetSlotType(slotType_); +- } +- notificationRequest_->SetTapDismissed(tapDismissed_); +- notificationRequest_->SetAutoDeletedTime(autoDeletedTime_); +- auto notificationNormalContent = std::make_shared(); +- notificationNormalContent->SetText(displayContent_); +- notificationNormalContent->SetTitle(title_); +- auto notificationContent = std::make_shared(notificationNormalContent); +- notificationRequest_->SetContent(notificationContent); +- if ((reminderType_ == ReminderRequest::ReminderType::TIMER) || +- (reminderType_ == ReminderRequest::ReminderType::ALARM)) { +- notificationRequest_->SetUnremovable(true); +- } +-} +- +-void ReminderRequest::UpdateNotificationBundleInfo() +-{ +- std::string ownerBundleName = notificationRequest_->GetOwnerBundleName(); +- if (!(ownerBundleName.empty())) { +- return; +- } +- ANSR_LOGD("ownerBundleName=%{public}s, bundleName_=%{public}s", +- ownerBundleName.c_str(), bundleName_.c_str()); +- notificationRequest_->SetOwnerBundleName(bundleName_); +- notificationRequest_->SetCreatorBundleName(bundleName_); +- notificationRequest_->SetCreatorUid(uid_); +- notificationRequest_->SetCreatorUserId(userId_); +-} +- +-void ReminderRequest::UpdateNotificationContent(const bool &setSnooze) +-{ +- if (notificationRequest_ == nullptr) { +- ANSR_LOGE("updateNotificationContent failed, the notificationRequest is null"); +- return; +- } +- std::string extendContent = ""; +- if (setSnooze) { +- if (timeIntervalInMilli_ != 0) { +- // snooze the reminder by manual +- extendContent = snoozeContent_; +- notificationRequest_->SetTapDismissed(false); +- } else { +- // the reminder is expired now, when timeInterval is 0 +- extendContent = expiredContent_; +- } +- } else if (IsAlerting()) { +- // the reminder is alerting, or ring duration is 0 +- extendContent = ""; +- } else if (snoozeTimesDynamic_ != snoozeTimes_) { +- // the reminder is snoozing by period artithmetic, when the ring duration is over. +- extendContent = snoozeContent_; +- notificationRequest_->SetTapDismissed(false); +- } else { +- // the reminder has already snoozed by period arithmetic, when the ring duration is over. +- extendContent = expiredContent_; +- } +- if (extendContent == "") { +- displayContent_ = content_; +- } else { +- displayContent_ = extendContent; +- } +- ANSR_LOGD("Display content=%{public}s", displayContent_.c_str()); +-} +- +-void ReminderRequest::UpdateNotificationStateForAlert() +-{ +- ANSR_LOGD("UpdateNotification content and buttons"); +- UpdateNotificationContent(false); +- UpdateActionButtons(false); +-} +- +-void ReminderRequest::UpdateNotificationStateForSnooze() +-{ +- ANSR_LOGD("UpdateNotification content and buttons"); +- UpdateNotificationContent(true); +- UpdateActionButtons(true); +-} +- +-int32_t ReminderRequest::GetActualTime(const TimeTransferType &type, int32_t cTime) +-{ +- switch (type) { +- case (TimeTransferType::YEAR): // year +- return BASE_YEAR + cTime; +- case (TimeTransferType::MONTH): // month +- return 1 + cTime; +- case (TimeTransferType::WEEK): { // week +- return cTime == 0 ? SUNDAY : cTime; +- } +- default: +- return -1; +- } +-} +- +-int32_t ReminderRequest::GetCTime(const TimeTransferType &type, int32_t actualTime) +-{ +- switch (type) { +- case (TimeTransferType::YEAR): // year +- return actualTime - BASE_YEAR; +- case (TimeTransferType::MONTH): // month +- return actualTime - 1; +- case (TimeTransferType::WEEK): { // week +- return actualTime == SUNDAY ? 0 : actualTime; +- } +- default: +- return -1; +- } +-} +- +-void ReminderRequest::SerializeWantAgent(std::string& wantInfoStr, std::string& maxWantInfoStr) +-{ +- std::string pkgName; +- std::string abilityName; +- std::string uri; +- std::string parameters; +- if (wantAgentInfo_ != nullptr) { +- pkgName = wantAgentInfo_->pkgName; +- abilityName = wantAgentInfo_->abilityName; +- uri = wantAgentInfo_->uri; +- AAFwk::WantParamWrapper wrapper(wantAgentInfo_->parameters); +- parameters = wrapper.ToString(); +- } +- nlohmann::json wantInfo; +- wantInfo["pkgName"] = pkgName; +- wantInfo["abilityName"] = abilityName; +- wantInfo["uri"] = uri; +- wantInfo["parameters"] = parameters; +- wantInfoStr = wantInfo.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace); +- +- if (maxScreenWantAgentInfo_ != nullptr) { +- pkgName = maxScreenWantAgentInfo_->pkgName; +- abilityName = maxScreenWantAgentInfo_->abilityName; +- uri = ""; +- parameters = ""; +- } +- nlohmann::json maxWantInfo; +- maxWantInfo["pkgName"] = pkgName; +- maxWantInfo["abilityName"] = abilityName; +- maxWantInfo["uri"] = uri; +- maxWantInfo["parameters"] = parameters; +- maxWantInfoStr = maxWantInfo.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace); +-} +- +-int64_t ReminderRequest::GetNextDaysOfWeek(const time_t now, const time_t target) const +-{ +- struct tm nowTime; +- (void)localtime_r(&now, &nowTime); +- int32_t today = GetActualTime(TimeTransferType::WEEK, nowTime.tm_wday); +- int32_t dayCount = now >= target ? 1 : 0; +- for (; dayCount <= DAYS_PER_WEEK; dayCount++) { +- int32_t day = (today + dayCount) % DAYS_PER_WEEK; +- day = (day == 0) ? SUNDAY : day; +- if (IsRepeatDaysOfWeek(day)) { +- break; +- } +- } +- ANSR_LOGI("NextDayInterval is %{public}d", dayCount); +- time_t nextTriggerTime = target + dayCount * HOURS_PER_DAY * SECONDS_PER_HOUR; +- return GetTriggerTime(now, nextTriggerTime); +-} +- +-bool ReminderRequest::IsRepeatDaysOfWeek(int32_t day) const +-{ +- return (repeatDaysOfWeek_ & (1 << (day - 1))) > 0; +-} +- +-time_t ReminderRequest::GetTriggerTimeWithDST(const time_t now, const time_t nextTriggerTime) const +-{ +- time_t triggerTime = nextTriggerTime; +- struct tm nowLocal; +- struct tm nextLocal; +- (void)localtime_r(&now, &nowLocal); +- (void)localtime_r(&nextTriggerTime, &nextLocal); +- if (nowLocal.tm_isdst == 0 && nextLocal.tm_isdst > 0) { +- triggerTime -= SECONDS_PER_HOUR; +- } else if (nowLocal.tm_isdst > 0 && nextLocal.tm_isdst == 0) { +- triggerTime += SECONDS_PER_HOUR; +- } +- return triggerTime; +-} +- +-uint8_t ReminderRequest::GetRepeatDaysOfWeek() const +-{ +- return repeatDaysOfWeek_; +-} +- +-void ReminderRequest::SetRepeatDaysOfWeek(bool set, const std::vector &daysOfWeek) +-{ +- if (daysOfWeek.size() == 0) { +- return; +- } +- if (daysOfWeek.size() > DAYS_PER_WEEK) { +- ANSR_LOGE("The length of daysOfWeek should not larger than 7"); +- return; +- } +- for (auto it = daysOfWeek.begin(); it != daysOfWeek.end(); ++it) { +- if (*it < MONDAY || *it > SUNDAY) { +- continue; +- } +- if (set) { +- repeatDaysOfWeek_ |= 1 << (*it - 1); +- } else { +- repeatDaysOfWeek_ &= ~(1 << (*it - 1)); +- } +- } +-} +- +-std::vector ReminderRequest::GetDaysOfWeek() const +-{ +- std::vector repeatDays; +- int32_t days[] = {1, 2, 3, 4, 5, 6, 7}; +- int32_t len = sizeof(days) / sizeof(int32_t); +- for (int32_t i = 0; i < len; i++) { +- if (IsRepeatDaysOfWeek(days[i])) { +- repeatDays.push_back(days[i]); +- } +- } +- return repeatDays; +-} +- +-uint64_t ReminderRequest::GetTriggerTime(const time_t now, const time_t nextTriggerTime) const +-{ +- time_t triggerTime = GetTriggerTimeWithDST(now, nextTriggerTime); +- struct tm test; +- (void)localtime_r(&triggerTime, &test); +- ANSR_LOGI("NextTriggerTime: year=%{public}d, mon=%{public}d, day=%{public}d, hour=%{public}d, " +- "min=%{public}d, sec=%{public}d, week=%{public}d, nextTriggerTime=%{public}lld", +- GetActualTime(TimeTransferType::YEAR, test.tm_year), +- GetActualTime(TimeTransferType::MONTH, test.tm_mon), +- test.tm_mday, +- test.tm_hour, +- test.tm_min, +- test.tm_sec, +- GetActualTime(TimeTransferType::WEEK, test.tm_wday), +- (long long)triggerTime); +- +- if (static_cast(triggerTime) <= 0) { +- return 0; +- } +- return GetDurationSinceEpochInMilli(triggerTime); +-} +- +-void ReminderRequest::OnLanguageChange(const std::shared_ptr &resMgr) +-{ +- if (resMgr == nullptr) { +- return; +- } +- // update title +- for (auto &button : actionButtonMap_) { +- if (button.second.resource.empty()) { +- continue; +- } +- std::string title; +- resMgr->GetStringByName(button.second.resource.c_str(), title); +- if (title.empty()) { +- continue; +- } +- button.second.title = title; +- } +-} +-} +-} +diff --git a/frameworks/ans/src/reminder_request_alarm.cpp b/frameworks/ans/src/reminder_request_alarm.cpp +deleted file mode 100644 +index 8fd928b2..00000000 +--- a/frameworks/ans/src/reminder_request_alarm.cpp ++++ /dev/null +@@ -1,208 +0,0 @@ +-/* +- * Copyright (c) 2021-2022 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 "reminder_request_alarm.h" +- +-#include "ans_log_wrapper.h" +- +-namespace OHOS { +-namespace Notification { +-const uint8_t ReminderRequestAlarm::MINUTES_PER_HOUR = 60; +-const int8_t ReminderRequestAlarm::DEFAULT_SNOOZE_TIMES = 3; +- +-ReminderRequestAlarm::ReminderRequestAlarm(uint8_t hour, uint8_t minute, const std::vector daysOfWeek) +- : ReminderRequest(ReminderRequest::ReminderType::ALARM) +-{ +- SetSnoozeTimes(DEFAULT_SNOOZE_TIMES); +- hour_ = hour; +- minute_ = minute; +- CheckParamValid(); +- SetRepeatDaysOfWeek(true, daysOfWeek); +- SetTriggerTimeInMilli(GetNextTriggerTime(true)); +-} +- +-ReminderRequestAlarm::ReminderRequestAlarm(const ReminderRequestAlarm &other) : ReminderRequest(other) +-{ +- hour_ = other.hour_; +- minute_ = other.minute_; +- repeatDaysOfWeek_ = other.repeatDaysOfWeek_; +- ANSR_LOGD("hour_=%{public}d, minute_=%{public}d, repeatDaysOfWeek_=%{public}d", +- hour_, minute_, other.repeatDaysOfWeek_); +-} +- +-void ReminderRequestAlarm::CheckParamValid() const +-{ +- if (hour_ >= HOURS_PER_DAY) { +- ANSR_LOGE("setted hour is not between [0, 24)"); +- return; +- } +- if (minute_ >= MINUTES_PER_HOUR) { +- ANSR_LOGE("setted minute is not between [0, 60)"); +- return; +- } +-} +- +-bool ReminderRequestAlarm::IsRepeatReminder() const +-{ +- if ((repeatDaysOfWeek_ != 0) || ((GetTimeInterval() > 0) && (GetSnoozeTimes() > 0))) { +- return true; +- } else { +- return false; +- } +-} +- +- +-uint64_t ReminderRequestAlarm::PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) +-{ +- if (ignoreRepeat || (repeatDaysOfWeek_)) { +- return GetNextTriggerTime(forceToGetNext); +- } else { +- return INVALID_LONG_LONG_VALUE; +- } +-} +- +-uint64_t ReminderRequestAlarm::GetNextTriggerTime(bool forceToGetNext) const +-{ +- time_t now; +- (void)time(&now); // unit is seconds. +- struct tm nowTime; +- (void)localtime_r(&now, &nowTime); +- ANSR_LOGD("Now: year=%{public}d, mon=%{public}d, day=%{public}d, hour=%{public}d, " +- "min=%{public}d, sec=%{public}d, week=%{public}d, Target: tar_hour=%{public}d, tar_min=%{public}d", +- GetActualTime(TimeTransferType::YEAR, nowTime.tm_year), +- GetActualTime(TimeTransferType::MONTH, nowTime.tm_mon), +- nowTime.tm_mday, nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec, +- GetActualTime(TimeTransferType::WEEK, nowTime.tm_wday), hour_, minute_); +- +- struct tm tar; +- tar.tm_year = nowTime.tm_year; +- tar.tm_mon = nowTime.tm_mon; +- tar.tm_mday = nowTime.tm_mday; +- tar.tm_hour = hour_; +- tar.tm_min = minute_; +- tar.tm_sec = 0; +- tar.tm_isdst = -1; +- +- const time_t target = mktime(&tar); +- if (repeatDaysOfWeek_ > 0) { +- return GetNextDaysOfWeek(now, target); +- } +- +- time_t nextTriggerTime = 0; +- if (now >= target) { +- if (forceToGetNext) { +- nextTriggerTime = target + 1 * HOURS_PER_DAY * SECONDS_PER_HOUR; +- } +- } else { +- nextTriggerTime = target; +- } +- return GetTriggerTime(now, nextTriggerTime); +-} +- +-void ReminderRequestAlarm::SetHour(const uint8_t hour) +-{ +- hour_ = hour; +-} +- +-void ReminderRequestAlarm::SetMinute(const uint8_t minute) +-{ +- minute_ = minute; +-} +- +-uint8_t ReminderRequestAlarm::GetHour() const +-{ +- return hour_; +-} +- +-uint8_t ReminderRequestAlarm::GetMinute() const +-{ +- return minute_; +-} +- +-bool ReminderRequestAlarm::UpdateNextReminder() +-{ +- ANSR_LOGD("UpdateNextReminder alarm time"); +- if (IsRepeatReminder()) { +- uint8_t letfSnoozeTimes = GetSnoozeTimesDynamic(); +- if ((letfSnoozeTimes > 0) && (GetTimeInterval() > 0)) { +- ANSR_LOGI("Left times: %{public}d, update next triggerTime", GetSnoozeTimesDynamic()); +- SetTriggerTimeInMilli(GetTriggerTimeInMilli() + GetTimeInterval() * MILLI_SECONDS); +- SetSnoozeTimesDynamic(--letfSnoozeTimes); +- } else { +- SetSnoozeTimesDynamic(GetSnoozeTimes()); +- if (repeatDaysOfWeek_ == 0) { +- ANSR_LOGI("No need to update next triggerTime"); +- SetExpired(true); +- return false; +- } +- uint64_t nextTriggerTime = GetNextTriggerTime(true); +- if (nextTriggerTime != INVALID_LONG_LONG_VALUE) { +- ANSR_LOGI("Set next trigger time successful, reset dynamic snoozeTimes"); +- SetTriggerTimeInMilli(nextTriggerTime); +- } else { +- ANSR_LOGW("Set reminder to expired"); +- SetExpired(true); +- return false; +- } +- } +- return true; +- } else { +- ANSR_LOGD("Single time reminder, not need to update next trigger time"); +- SetSnoozeTimesDynamic(GetSnoozeTimes()); +- SetExpired(true); +- return false; +- } +-} +- +-bool ReminderRequestAlarm::Marshalling(Parcel &parcel) const +-{ +- if (ReminderRequest::Marshalling(parcel)) { +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, hour_, "hour"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, minute_, "minute"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, repeatDaysOfWeek_, "repeatDaysOfWeek"); +- return true; +- } +- return false; +-} +- +-ReminderRequestAlarm *ReminderRequestAlarm::Unmarshalling(Parcel &parcel) +-{ +- ANSR_LOGD("New alarm"); +- auto objptr = new (std::nothrow) ReminderRequestAlarm(); +- if (objptr == nullptr) { +- ANSR_LOGE("Failed to create reminder alarm due to no memory."); +- return objptr; +- } +- if (!objptr->ReadFromParcel(parcel)) { +- delete objptr; +- objptr = nullptr; +- } +- return objptr; +-} +- +-bool ReminderRequestAlarm::ReadFromParcel(Parcel &parcel) +-{ +- if (ReminderRequest::ReadFromParcel(parcel)) { +- READ_UINT8_RETURN_FALSE_LOG(parcel, hour_, "hour"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, minute_, "minute"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, repeatDaysOfWeek_, "repeatDaysOfWeek"); +- +- ANSR_LOGD("hour_=%{public}d, minute_=%{public}d", hour_, minute_); +- return true; +- } +- return false; +-} +-} +-} +\ No newline at end of file +diff --git a/frameworks/ans/src/reminder_request_calendar.cpp b/frameworks/ans/src/reminder_request_calendar.cpp +deleted file mode 100644 +index df26f548..00000000 +--- a/frameworks/ans/src/reminder_request_calendar.cpp ++++ /dev/null +@@ -1,870 +0,0 @@ +-/* +- * Copyright (c) 2021-2022 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 "reminder_request_calendar.h" +- +-#include "ans_log_wrapper.h" +-#include "nlohmann/json.hpp" +- +-namespace OHOS { +-namespace Notification { +-const uint8_t ReminderRequestCalendar::DEFAULT_SNOOZE_TIMES = 3; +- +-const uint8_t ReminderRequestCalendar::DAY_ARRAY[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +- +-ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, const std::vector &repeatMonths, +- const std::vector &repeatDays, const std::vector &daysOfWeek) +- : ReminderRequest(ReminderRequest::ReminderType::CALENDAR) +-{ +- // 1. record the information which designated by user at first time. +- firstDesignateYear_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime.tm_year)); +- firstDesignateMonth_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon)); +- firstDesignateDay_ = dateTime.tm_mday; +- SetRepeatMonths(repeatMonths); +- SetRepeatDaysOfMonth(repeatDays); +- SetRepeatDaysOfWeek(true, daysOfWeek); +- SetSnoozeTimes(DEFAULT_SNOOZE_TIMES); +- +- // 2. should SetNextTriggerTime() after constructor +- InitDateTime(dateTime); +-} +- +-ReminderRequestCalendar::ReminderRequestCalendar(const ReminderRequestCalendar &other) : ReminderRequest(other) +-{ +- dateTime_ = other.dateTime_; +- firstDesignateYear_ = other.firstDesignateYear_; +- firstDesignateMonth_ = other.firstDesignateMonth_; +- firstDesignateDay_ = other.firstDesignateDay_; +- year_ = other.year_; +- month_ = other.month_; +- day_ = other.day_; +- hour_ = other.hour_; +- minute_ = other.minute_; +- second_ = other.second_; +- repeatMonth_ = other.repeatMonth_; +- repeatDay_ = other.repeatDay_; +- repeatDaysOfWeek_ = other.repeatDaysOfWeek_; +- rruleWantAgentInfo_ = other.rruleWantAgentInfo_; +- durationTime_ = other.durationTime_; +- startDateTime_ = other.startDateTime_; +- endDateTime_ = other.endDateTime_; +- excludeDates_ = other.excludeDates_; +- lastStartDateTime_ = other.lastStartDateTime_; +-} +- +-void ReminderRequestCalendar::SetRRuleWantAgentInfo(const std::shared_ptr &wantAgentInfo) +-{ +- rruleWantAgentInfo_ = wantAgentInfo; +-} +- +-void ReminderRequestCalendar::AddExcludeDate(const uint64_t date) +-{ +- time_t t = static_cast(date / MILLI_SECONDS); +- struct tm dateTime; +- (void)localtime_r(&t, &dateTime); +- dateTime.tm_hour = 0; +- dateTime.tm_min = 0; +- dateTime.tm_sec = 0; +- const time_t target = mktime(&dateTime); +- if (target == -1) { +- ANSR_LOGW("error exclude date"); +- return; +- } +- excludeDates_.insert(ReminderRequest::GetDurationSinceEpochInMilli(target)); +-} +- +-void ReminderRequestCalendar::DelExcludeDates() +-{ +- excludeDates_.clear(); +-} +- +-std::vector ReminderRequestCalendar::GetExcludeDates() const +-{ +- std::vector excludeDates; +- for (auto date : excludeDates_) { +- excludeDates.push_back(date); +- } +- return excludeDates; +-} +- +-bool ReminderRequestCalendar::IsInExcludeDate() const +-{ +- time_t t = static_cast(startDateTime_ / MILLI_SECONDS); +- struct tm dateTime; +- (void)localtime_r(&t, &dateTime); +- dateTime.tm_hour = 0; +- dateTime.tm_min = 0; +- dateTime.tm_sec = 0; +- const time_t target = mktime(&dateTime); +- if (target == -1) { +- ANSR_LOGW("error start date time"); +- return false; +- } +- uint64_t notificationTime = ReminderRequest::GetDurationSinceEpochInMilli(target); +- if (excludeDates_.find(notificationTime) != excludeDates_.end()) { +- ANSR_LOGI("Reminder[%{public}d] trigger time is in exclude date", GetReminderId()); +- return true; +- } +- return false; +-} +- +-std::shared_ptr ReminderRequestCalendar::GetRRuleWantAgentInfo() +-{ +- return rruleWantAgentInfo_; +-} +- +-void ReminderRequestCalendar::SetRepeatDay(const uint32_t repeatDay) +-{ +- repeatDay_ = repeatDay; +-} +- +-void ReminderRequestCalendar::SetRepeatMonth(const uint16_t repeatMonth) +-{ +- repeatMonth_ = repeatMonth; +-} +- +-void ReminderRequestCalendar::SetFirstDesignateYear(const uint16_t firstDesignateYear) +-{ +- firstDesignateYear_ = firstDesignateYear; +-} +- +-void ReminderRequestCalendar::SetFirstDesignageMonth(const uint16_t firstDesignateMonth) +-{ +- firstDesignateMonth_ = firstDesignateMonth; +-} +- +-void ReminderRequestCalendar::SetFirstDesignateDay(const uint16_t firstDesignateDay) +-{ +- firstDesignateDay_ = firstDesignateDay; +-} +- +-void ReminderRequestCalendar::SetYear(const uint16_t year) +-{ +- year_ = year; +-} +- +-void ReminderRequestCalendar::SetMonth(const uint8_t month) +-{ +- month_ = month; +-} +- +-void ReminderRequestCalendar::SetDay(const uint8_t day) +-{ +- day_ = day; +-} +- +-void ReminderRequestCalendar::SetHour(const uint8_t hour) +-{ +- hour_ = hour; +-} +- +-void ReminderRequestCalendar::SetMinute(const uint8_t minute) +-{ +- minute_ = minute; +-} +- +-bool ReminderRequestCalendar::InitTriggerTime() +-{ +- uint64_t nextTriggerTime = INVALID_LONG_LONG_VALUE; +- uint64_t nowInMilli = GetNowInstantMilli(); +- if ((startDateTime_ <= nowInMilli) && (nowInMilli <= endDateTime_)) { +- nextTriggerTime = nowInMilli + DEFAULT_DELAY_TIME; +- } else if (startDateTime_ > nowInMilli) { +- nextTriggerTime = startDateTime_; +- } else if (endDateTime_ < nowInMilli && IsRepeatReminder()) { +- nextTriggerTime = GetNextTriggerTime(); +- } else { +- return false; +- } +- lastStartDateTime_ = startDateTime_; +- SetTriggerTimeInMilli(nextTriggerTime); +- return true; +-} +- +-bool ReminderRequestCalendar::SetNextTriggerTime() +-{ +- hour_ = static_cast(dateTime_.tm_hour); +- minute_ = static_cast(dateTime_.tm_min); +- uint64_t nextTriggerTime = INVALID_LONG_LONG_VALUE; +- if ((nextTriggerTime = GetNextTriggerTime()) != INVALID_LONG_LONG_VALUE) { +- time_t target = static_cast(nextTriggerTime / MILLI_SECONDS); +- (void)localtime_r(&target, &dateTime_); +- } else { +- ANSR_LOGW("Not exist next trigger time, please check the param of ReminderRequestCalendar constructor."); +- return false; +- } +- +- // set the time information (used to transfer to proxy service) which is decided to trigger firstly. +- year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year)); +- month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon)); +- day_ = static_cast(dateTime_.tm_mday); +- second_ = 0; +- SetTriggerTimeInMilli(nextTriggerTime); +- return true; +-} +- +-uint8_t ReminderRequestCalendar::GetDaysOfMonth(const uint16_t &year, const uint8_t &month) +-{ +- uint8_t days; +- if (month == FEBRUARY) { +- days = ((((year % LEAP_PARAM_MIN == 0) && (year % LEAP_PARAM_MAX != 0)) || (year % SOLAR_YEAR == 0)) +- ? LEAP_MONTH : NON_LEAP_MONTH); +- } else { +- days = DAY_ARRAY[month - 1]; +- } +- return days; +-} +- +-uint8_t ReminderRequestCalendar::GetNextDay( +- const uint16_t &settedYear, const uint8_t &settedMonth, const tm &now, const tm &target) const +-{ +- uint32_t repeatDayTmp = repeatDay_; +- uint8_t daysOfSpecialMonth = GetDaysOfMonth(settedYear, settedMonth); +- uint8_t setDayTmp = INVALID_U8_VALUE; +- for (uint8_t i = 1; i <= daysOfSpecialMonth; i++) { +- if ((repeatDayTmp & (1 << (i - 1))) > 0) { +- struct tm setTime; +- setTime.tm_year = GetCTime(TimeTransferType::YEAR, settedYear); +- setTime.tm_mon = GetCTime(TimeTransferType::MONTH, settedMonth); +- setTime.tm_mday = static_cast(i); +- setTime.tm_hour = target.tm_hour; +- setTime.tm_min = target.tm_min; +- setTime.tm_sec = target.tm_sec; +- setTime.tm_isdst = -1; +- +- struct tm nowTime; +- nowTime.tm_year = now.tm_year; +- nowTime.tm_mon = now.tm_mon; +- nowTime.tm_mday = now.tm_mday; +- nowTime.tm_hour = now.tm_hour; +- nowTime.tm_min = now.tm_min; +- nowTime.tm_sec = now.tm_sec; +- nowTime.tm_isdst = -1; +- +- if (mktime(&nowTime) >= mktime(&setTime)) { +- continue; +- } else { +- setDayTmp = i; +- return setDayTmp; +- } +- } +- } +- return setDayTmp; +-} +- +-bool ReminderRequestCalendar::CheckCalenderIsExpired(const uint64_t now) +-{ +- if (IsInExcludeDate()) { +- return false; +- } +- if (now <= (lastStartDateTime_ + durationTime_) && now >= lastStartDateTime_) { +- ANSR_LOGI("now: %{public}" PRIu64 ", start: %{public}" PRIu64 ", end: %{public}" PRIu64 "", +- now, lastStartDateTime_, lastStartDateTime_ + durationTime_); +- return true; +- } +- if (now <= endDateTime_ && now >= startDateTime_) { +- ANSR_LOGI("now: %{public}" PRIu64 ", start: %{public}" PRIu64 ", end: %{public}" PRIu64 "", +- now, startDateTime_, endDateTime_); +- return true; +- } +- return false; +-} +- +-bool ReminderRequestCalendar::OnDateTimeChange() +-{ +- if (IsExpired()) { +- return false; +- } +- if (startDateTime_ == endDateTime_) { +- return ReminderRequest::OnDateTimeChange(); +- } +- uint64_t now = GetNowInstantMilli(); +- if (now == 0) { +- ANSR_LOGE("get now time failed"); +- return false; +- } +- if (CheckCalenderIsExpired(now)) { +- return GetTriggerTimeInMilli() <= now; +- } else { +- uint64_t triggerTime = GetNextTriggerTime(true); +- SetTriggerTimeInMilli(triggerTime); +- return false; +- } +-} +- +-bool ReminderRequestCalendar::IsRepeat() const +-{ +- return (repeatMonth_ > 0 && repeatDay_ > 0) || (repeatDaysOfWeek_ > 0); +-} +- +-bool ReminderRequestCalendar::CheckExcludeDate() +-{ +- if (!IsRepeat()) { +- // not repeat reminder +- return false; +- } +- +- if (IsInExcludeDate()) { +- // in exclude date +- uint64_t triggerTime = GetNextTriggerTime(true); +- SetTriggerTimeInMilli(triggerTime); +- return true; +- } +- return false; +-} +- +-bool ReminderRequestCalendar::IsPullUpService() +-{ +- if (rruleWantAgentInfo_ == nullptr) { +- return false; +- } +- +- uint64_t now = GetNowInstantMilli(); +- if (now == 0) { +- ANSR_LOGE("get now time failed"); +- return false; +- } +- +- if (now >= startDateTime_) { +- return true; +- } +- return false; +-} +- +-bool ReminderRequestCalendar::IsNeedNotification() +-{ +- uint64_t now = GetNowInstantMilli(); +- if (now == 0) { +- ANSR_LOGE("get now time failed"); +- return false; +- } +- if ((now <= endDateTime_ && now >= startDateTime_) || +- (startDateTime_ == endDateTime_)) { +- return true; +- } +- uint64_t triggerTime = GetNextTriggerTime(true); +- SetTriggerTimeInMilli(triggerTime); +- return false; +-} +- +-void ReminderRequestCalendar::CalcLastStartDateTime() +-{ +- time_t t; +- (void)time(&t); +- struct tm nowTime; +- (void)localtime_r(&t, &nowTime); +- +- t = static_cast(startDateTime_/MILLI_SECONDS); +- struct tm startTime; +- (void)localtime_r(&t, &startTime); +- +- startTime.tm_year = nowTime.tm_year; +- startTime.tm_mon = nowTime.tm_mon; +- startTime.tm_mday = nowTime.tm_mday; +- time_t target = mktime(&startTime); +- if (target != -1) { +- lastStartDateTime_ = ReminderRequest::GetDurationSinceEpochInMilli(target); +- } +-} +- +-uint64_t ReminderRequestCalendar::GetNextTriggerTime(const bool updateLast) +-{ +- uint64_t triggerTimeInMilli = INVALID_LONG_LONG_VALUE; +- time_t now; +- (void)time(&now); // unit is seconds. +- struct tm nowTime; +- (void)localtime_r(&now, &nowTime); +- nowTime.tm_sec = 0; +- struct tm tarTime; +- tarTime.tm_year = GetCTime(TimeTransferType::YEAR, firstDesignateYear_); +- tarTime.tm_mon = GetCTime(TimeTransferType::MONTH, firstDesignateMonth_); +- tarTime.tm_mday = firstDesignateDay_; +- tarTime.tm_hour = hour_; +- tarTime.tm_min = minute_; +- tarTime.tm_sec = 0; +- tarTime.tm_isdst = -1; +- const time_t target = mktime(&tarTime); +- ANSR_LOGD("Now time is: %{public}s", GetDateTimeInfo(now).c_str()); +- if (repeatMonth_ > 0 && repeatDay_ > 0) { +- triggerTimeInMilli = GetNextTriggerTimeAsRepeatReminder(nowTime, tarTime); +- startDateTime_ = triggerTimeInMilli; +- endDateTime_ = triggerTimeInMilli + durationTime_; +- } else if (repeatDaysOfWeek_ > 0 && (target <= now)) { +- nowTime.tm_hour = tarTime.tm_hour; +- nowTime.tm_min = tarTime.tm_min; +- nowTime.tm_sec = tarTime.tm_sec; +- nowTime.tm_isdst = tarTime.tm_isdst; +- const time_t tar = mktime(&nowTime); +- triggerTimeInMilli = GetNextDaysOfWeek(now, tar); +- startDateTime_ = triggerTimeInMilli; +- endDateTime_ = triggerTimeInMilli + durationTime_; +- } else { +- ANSR_LOGD("tarTime: %{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d", +- tarTime.tm_year, tarTime.tm_mon, tarTime.tm_mday, tarTime.tm_hour, tarTime.tm_min, tarTime.tm_sec); +- if (target == -1) { +- ANSR_LOGW("mktime return error."); +- } +- if (now < target) { +- triggerTimeInMilli = ReminderRequest::GetDurationSinceEpochInMilli(target); +- ANSR_LOGD("Next calendar time:%{public}s", GetDateTimeInfo(target).c_str()); +- } +- } +- if (updateLast) { +- lastStartDateTime_ = startDateTime_; +- } else { +- CalcLastStartDateTime(); +- } +- return triggerTimeInMilli; +-} +- +-uint64_t ReminderRequestCalendar::GetNextTriggerTimeAsRepeatReminder(const tm &nowTime, const tm &tarTime) const +-{ +- uint64_t triggerTimeInMilli = INVALID_LONG_LONG_VALUE; +- uint16_t setYear = static_cast(GetActualTime(TimeTransferType::YEAR, nowTime.tm_year)); +- uint8_t setMonth = INVALID_U8_VALUE; +- uint8_t setDay = INVALID_U8_VALUE; +- uint8_t beginMonth = static_cast(GetActualTime(TimeTransferType::MONTH, nowTime.tm_mon)); +- uint8_t count = 1; +- uint16_t repeatMonthTmp = repeatMonth_; +- for (uint8_t i = beginMonth; i < (MAX_MONTHS_OF_YEAR + beginMonth + 1); i++) { +- if ((repeatMonthTmp & (1 << ((i - 1) % MAX_MONTHS_OF_YEAR))) > 0) { +- setMonth = (i % MAX_MONTHS_OF_YEAR); +- setMonth = setMonth == 0 ? DECEMBER : setMonth; +- if (count != 1) { +- setYear = setMonth <= beginMonth ? setYear + 1 : setYear; +- } +- setDay = GetNextDay(setYear, setMonth, nowTime, tarTime); +- } +- if (setDay != INVALID_U8_VALUE) { +- break; +- } +- count++; +- } +- if ((triggerTimeInMilli = GetTimeInstantMilli(setYear, setMonth, setDay, hour_, minute_, second_)) +- != INVALID_LONG_LONG_VALUE) { +- ANSR_LOGD("Next calendar time:%{public}hu/%{public}hhu/%{public}hhu %{public}hhu:%{public}hhu:%{public}hhu", +- setYear, setMonth, setDay, hour_, minute_, second_); +- } +- return triggerTimeInMilli; +-} +- +-uint64_t ReminderRequestCalendar::GetTimeInstantMilli( +- uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) const +-{ +- struct tm tar; +- tar.tm_year = GetCTime(TimeTransferType::YEAR, year); +- tar.tm_mon = GetCTime(TimeTransferType::MONTH, month); +- tar.tm_mday = static_cast(day); +- tar.tm_hour = static_cast(hour); +- tar.tm_min = static_cast(minute); +- tar.tm_sec = static_cast(second); +- tar.tm_isdst = -1; +- +- ANSR_LOGD("tar: %{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d", +- tar.tm_year, tar.tm_mon, tar.tm_mday, tar.tm_hour, tar.tm_min, tar.tm_sec); +- const time_t target = mktime(&tar); +- if (target == -1) { +- ANSR_LOGW("mktime return error."); +- return INVALID_LONG_LONG_VALUE; +- } +- return ReminderRequest::GetDurationSinceEpochInMilli(target); +-} +- +-void ReminderRequestCalendar::InitDateTime() +-{ +- dateTime_.tm_year = GetCTime(TimeTransferType::YEAR, year_); +- dateTime_.tm_mon = GetCTime(TimeTransferType::MONTH, month_); +- dateTime_.tm_mday = static_cast(day_); +- dateTime_.tm_hour = static_cast(hour_); +- dateTime_.tm_min = static_cast(minute_); +- dateTime_.tm_sec = static_cast(second_); +- dateTime_.tm_isdst = -1; +-} +- +-void ReminderRequestCalendar::InitDateTime(const tm &dateTime) +-{ +- dateTime_.tm_year = dateTime.tm_year; +- dateTime_.tm_mon = dateTime.tm_mon; +- dateTime_.tm_mday = dateTime.tm_mday; +- dateTime_.tm_hour = dateTime.tm_hour; +- dateTime_.tm_min = dateTime.tm_min; +- dateTime_.tm_sec = dateTime.tm_sec; +- dateTime_.tm_isdst = -1; +- +- year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime.tm_year)); +- month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon)); +- day_ = static_cast(dateTime.tm_mday); +- hour_ = static_cast(dateTime.tm_hour); +- minute_ = static_cast(dateTime.tm_min); +- second_ = static_cast(dateTime.tm_sec); +- +- time_t time = mktime(&dateTime_); +- if (time == -1) { +- startDateTime_ = 0; +- } else { +- startDateTime_ = ReminderRequest::GetDurationSinceEpochInMilli(time); +- endDateTime_ = startDateTime_; +- } +-} +- +-bool ReminderRequestCalendar::IsRepeatReminder() const +-{ +- return (repeatMonth_ > 0 && repeatDay_ > 0) || (repeatDaysOfWeek_ > 0) +- || (GetTimeInterval() > 0 && GetSnoozeTimes() > 0); +-} +- +-bool ReminderRequestCalendar::IsRepeatMonth(uint8_t month) const +-{ +- if (month > MAX_MONTHS_OF_YEAR) { +- return false; +- } +- return (repeatMonth_ & (1 << (month - 1))) > 0; +-} +- +-bool ReminderRequestCalendar::IsRepeatDay(uint8_t day) const +-{ +- if (day > MAX_DAYS_OF_MONTH) { +- return false; +- } +- return (repeatDay_ & (1 << (day - 1))) > 0; +-} +- +-void ReminderRequestCalendar::SetDay(const uint8_t &day, const bool &isSet) +-{ +- if (day < 1 || day > MAX_DAYS_OF_MONTH) { +- return; +- } +- if (isSet) { +- repeatDay_ |= 1 << (day - 1); +- } else { +- repeatDay_ &= ~(1 << (day - 1)); +- } +-} +- +-void ReminderRequestCalendar::SetMonth(const uint8_t &month, const bool &isSet) +-{ +- if (month < JANUARY || month > DECEMBER) { +- return; +- } +- if (isSet) { +- repeatMonth_ |= 1 << (month - 1); +- } else { +- repeatMonth_ &= ~ (1 << (month - 1)); +- } +-} +- +-void ReminderRequestCalendar::SetRepeatMonths(const std::vector &repeatMonths) +-{ +- if (repeatMonths.size() > MAX_MONTHS_OF_YEAR) { +- ANSR_LOGW("The length of repeat months array should not larger than %{public}hhu", MAX_MONTHS_OF_YEAR); +- return; +- } +- repeatMonth_ = 0; +- for (auto it = repeatMonths.begin(); it != repeatMonths.end(); ++it) { +- SetMonth((*it), true); +- } +-} +- +-void ReminderRequestCalendar::SetRepeatDaysOfMonth(const std::vector &repeatDays) +-{ +- if (repeatDays.size() > MAX_DAYS_OF_MONTH) { +- ANSR_LOGW("The length of repeat days array should not larger than %{public}hhu", MAX_DAYS_OF_MONTH); +- return; +- } +- repeatDay_ = 0; +- for (auto it = repeatDays.begin(); it != repeatDays.end(); ++it) { +- SetDay((*it), true); +- } +-} +- +-std::vector ReminderRequestCalendar::GetRepeatMonths() const +-{ +- std::vector repeatMonths; +- for (int32_t i = 0; i < MAX_MONTHS_OF_YEAR; i++) { +- if (IsRepeatMonth(i + 1)) { +- repeatMonths.push_back(i + 1); +- } +- } +- return repeatMonths; +-} +- +-std::vector ReminderRequestCalendar::GetRepeatDays() const +-{ +- std::vector repeatDays; +- for (int32_t i = 0; i < MAX_DAYS_OF_MONTH; i++) { +- if (IsRepeatDay(i + 1)) { +- repeatDays.push_back(i + 1); +- } +- } +- return repeatDays; +-} +- +-bool ReminderRequestCalendar::UpdateNextReminder() +-{ +- ANSR_LOGD("UpdateNextReminder calendar time"); +- if (!IsRepeatReminder()) { +- ANSR_LOGI("No need to update next trigger time as it is an one-time reminder."); +- SetSnoozeTimesDynamic(GetSnoozeTimes()); +- SetTriggerTimeInMilli(INVALID_LONG_LONG_VALUE); +- if (startDateTime_ == endDateTime_) { +- SetExpired(true); +- } +- return false; +- } +- uint8_t leftSnoozeTimes = GetSnoozeTimesDynamic(); +- if (leftSnoozeTimes > 0 && (GetTimeInterval() > 0)) { +- ANSR_LOGI("Left snooze times: %{public}d, update next triggerTime", leftSnoozeTimes); +- SetTriggerTimeInMilli(GetTriggerTimeInMilli() + GetTimeInterval() * MILLI_SECONDS); +- SetSnoozeTimesDynamic(--leftSnoozeTimes); +- } else { +- SetSnoozeTimesDynamic(GetSnoozeTimes()); +- if ((repeatMonth_ == 0 || repeatDay_ == 0) && (repeatDaysOfWeek_ == 0)) { +- ANSR_LOGI("Not a day repeat reminder, no need to update to next trigger time."); +- SetTriggerTimeInMilli(INVALID_LONG_LONG_VALUE); +- if (startDateTime_ == endDateTime_) { +- SetExpired(true); +- } +- return false; +- } else { +- uint64_t nextTriggerTime = GetNextTriggerTime(); +- if (nextTriggerTime != INVALID_LONG_LONG_VALUE) { +- ANSR_LOGI("Set next trigger time successful, reset dynamic snoozeTimes"); +- SetTriggerTimeInMilli(nextTriggerTime); +- } else { +- ANSR_LOGW("Set next trigger time invalidate"); +- SetExpired(true); +- return false; +- } +- } +- } +- return true; +-} +- +-uint64_t ReminderRequestCalendar::PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) +-{ +- if (ignoreRepeat || (repeatMonth_ > 0 && repeatDay_ > 0) || (repeatDaysOfWeek_ > 0)) { +- return GetNextTriggerTime(true); +- } else { +- return INVALID_LONG_LONG_VALUE; +- } +-} +- +-bool ReminderRequestCalendar::Marshalling(Parcel &parcel) const +-{ +- if (ReminderRequest::Marshalling(parcel)) { +- // write int +- WRITE_UINT16_RETURN_FALSE_LOG(parcel, year_, "year"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, month_, "month"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, day_, "day"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, hour_, "hour"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, minute_, "minute"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, second_, "second"); +- WRITE_UINT16_RETURN_FALSE_LOG(parcel, repeatMonth_, "repeatMonth"); +- WRITE_UINT32_RETURN_FALSE_LOG(parcel, repeatDay_, "repeatDay"); +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, durationTime_, "durationTime"); +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, startDateTime_, "startDateTime"); +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, endDateTime_, "endDateTime"); +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, lastStartDateTime_, "lastStartDateTime"); +- WRITE_UINT16_RETURN_FALSE_LOG(parcel, firstDesignateYear_, "firstDesignateYear"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateMonth_, "firstDesignateMonth"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateDay_, "firstDesignateDay"); +- WRITE_UINT8_RETURN_FALSE_LOG(parcel, repeatDaysOfWeek_, "repeatDaysOfWeek"); +- +- bool rruleFlag = rruleWantAgentInfo_ == nullptr ? 0 : 1; +- WRITE_BOOL_RETURN_FALSE_LOG(parcel, rruleFlag, "rruleFlag"); +- if (rruleWantAgentInfo_ != nullptr) { +- WRITE_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->pkgName, "rruleWantAgentInfo's pkgName"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->abilityName, "rruleWantAgentInfo's abilityName"); +- WRITE_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->uri, "rruleWantAgentInfo's uri"); +- } +- return true; +- } +- return false; +-} +- +-ReminderRequestCalendar *ReminderRequestCalendar::Unmarshalling(Parcel &parcel) +-{ +- ANSR_LOGD("New calendar"); +- auto objptr = new (std::nothrow) ReminderRequestCalendar(); +- if (objptr == nullptr) { +- ANS_LOGE("Failed to create reminder calendar due to no memory."); +- return objptr; +- } +- if (!objptr->ReadFromParcel(parcel)) { +- delete objptr; +- objptr = nullptr; +- } +- return objptr; +-} +- +-bool ReminderRequestCalendar::ReadFromParcel(Parcel &parcel) +-{ +- if (ReminderRequest::ReadFromParcel(parcel)) { +- // read int +- READ_UINT16_RETURN_FALSE_LOG(parcel, year_, "year"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, month_, "month"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, day_, "day"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, hour_, "hour"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, minute_, "minute"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, second_, "second"); +- READ_UINT16_RETURN_FALSE_LOG(parcel, repeatMonth_, "repeatMonth"); +- READ_UINT32_RETURN_FALSE_LOG(parcel, repeatDay_, "repeatDay"); +- READ_UINT64_RETURN_FALSE_LOG(parcel, durationTime_, "durationTime"); +- READ_UINT64_RETURN_FALSE_LOG(parcel, startDateTime_, "startDateTime"); +- READ_UINT64_RETURN_FALSE_LOG(parcel, endDateTime_, "endDateTime"); +- READ_UINT64_RETURN_FALSE_LOG(parcel, lastStartDateTime_, "lastStartDateTime"); +- +- InitDateTime(); +- +- READ_UINT16_RETURN_FALSE_LOG(parcel, firstDesignateYear_, "firstDesignateYear"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateMonth_, "firstDesignateMonth"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateDay_, "firstDesignateDay"); +- READ_UINT8_RETURN_FALSE_LOG(parcel, repeatDaysOfWeek_, "repeatDaysOfWeek"); +- +- bool rruleFlag = false; +- READ_BOOL_RETURN_FALSE_LOG(parcel, rruleFlag, "rruleFlag"); +- if (rruleFlag) { +- rruleWantAgentInfo_ = std::make_shared(); +- READ_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->pkgName, "rruleWantAgentInfo's pkgName"); +- READ_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->abilityName, "rruleWantAgentInfo's abilityName"); +- READ_STRING_RETURN_FALSE_LOG(parcel, rruleWantAgentInfo_->uri, "rruleWantAgentInfo's uri"); +- } +- return true; +- } +- return false; +-} +- +-void ReminderRequestCalendar::SetDateTime(const uint64_t time) +-{ +- time_t t = static_cast(time / MILLI_SECONDS); +- struct tm dateTime; +- (void)localtime_r(&t, &dateTime); +- +- year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime.tm_year)); +- month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon)); +- day_ = static_cast(dateTime.tm_mday); +- hour_ = static_cast(dateTime.tm_hour); +- minute_ = static_cast(dateTime.tm_min); +- second_ = static_cast(dateTime.tm_sec); +- startDateTime_ = time; +-} +- +-bool ReminderRequestCalendar::SetEndDateTime(const uint64_t time) +-{ +- if (time < startDateTime_) { +- return false; +- } +- endDateTime_ = time; +- durationTime_ = endDateTime_ - startDateTime_; +- return true; +-} +- +-uint64_t ReminderRequestCalendar::GetDateTime() const +-{ +- return startDateTime_; +-} +- +-uint64_t ReminderRequestCalendar::GetEndDateTime() const +-{ +- return endDateTime_; +-} +- +-void ReminderRequestCalendar::SetLastStartDateTime(const uint64_t time) +-{ +- lastStartDateTime_ = time; +-} +- +-uint64_t ReminderRequestCalendar::GetLastStartDateTime() const +-{ +- return lastStartDateTime_; +-} +- +-std::string ReminderRequestCalendar::SerializationRRule() +-{ +- constexpr int32_t INDENT = -1; +- if (rruleWantAgentInfo_ == nullptr) { +- return ""; +- } +- nlohmann::json root; +- root["pkgName"] = rruleWantAgentInfo_->pkgName; +- root["abilityName"] = rruleWantAgentInfo_->abilityName; +- root["uri"] = rruleWantAgentInfo_->uri; +- std::string str = root.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace); +- return str; +-} +- +-std::string ReminderRequestCalendar::SerializationExcludeDates() +-{ +- constexpr int32_t INDENT = -1; +- nlohmann::json root; +- root["excludeDates"] = nlohmann::json::array(); +- for (auto date : excludeDates_) { +- root["excludeDates"].push_back(date); +- } +- std::string str = root.dump(INDENT, ' ', false, nlohmann::json::error_handler_t::replace); +- return str; +-} +- +-void ReminderRequestCalendar::DeserializationRRule(const std::string& str) +-{ +- if (str.empty()) { +- return; +- } +- if (!nlohmann::json::accept(str)) { +- ANSR_LOGW("not a json string!"); +- return; +- } +- nlohmann::json root = nlohmann::json::parse(str, nullptr, false); +- if (root.is_discarded()) { +- ANSR_LOGW("parse json data failed!"); +- return; +- } +- if (!root.contains("pkgName") || !root["pkgName"].is_string() || +- !root.contains("abilityName") || !root["abilityName"].is_string() || +- !root.contains("uri") || !root["uri"].is_string()) { +- return; +- } +- +- rruleWantAgentInfo_ = std::make_shared(); +- rruleWantAgentInfo_->pkgName = root["pkgName"].get(); +- rruleWantAgentInfo_->abilityName = root["abilityName"].get(); +- rruleWantAgentInfo_->uri = root["uri"].get(); +-} +- +-void ReminderRequestCalendar::DeserializationExcludeDates(const std::string& str) +-{ +- if (str.empty()) { +- return; +- } +- if (!nlohmann::json::accept(str)) { +- return; +- } +- nlohmann::json root = nlohmann::json::parse(str, nullptr, false); +- if (root.is_discarded()) { +- return; +- } +- +- if (!root.contains("excludeDates") || !root["excludeDates"].is_array()) { +- return; +- } +- excludeDates_.clear(); +- for (auto date : root["excludeDates"]) { +- if (date.is_number()) { +- excludeDates_.insert(date.get()); +- } +- } +-} +-} +-} +diff --git a/frameworks/ans/src/reminder_request_timer.cpp b/frameworks/ans/src/reminder_request_timer.cpp +deleted file mode 100644 +index 867f26ae..00000000 +--- a/frameworks/ans/src/reminder_request_timer.cpp ++++ /dev/null +@@ -1,157 +0,0 @@ +-/* +- * Copyright (c) 2021-2022 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 "reminder_request_timer.h" +- +-#include +-#include +- +-#include "ans_log_wrapper.h" +-#include "time_service_client.h" +- +-namespace OHOS { +-namespace Notification { +-ReminderRequestTimer::ReminderRequestTimer(uint64_t countDownTimeInSeconds) +- : ReminderRequest(ReminderRequest::ReminderType::TIMER) +-{ +- CheckParamsValid(countDownTimeInSeconds); +- countDownTimeInSeconds_ = countDownTimeInSeconds; +- time_t now; // unit is seconds. +- (void)time(&now); +- ReminderRequest::SetTriggerTimeInMilli( +- ReminderRequest::GetDurationSinceEpochInMilli(now) + countDownTimeInSeconds_ * ReminderRequest::MILLI_SECONDS); +- sptr timer = MiscServices::TimeServiceClient::GetInstance(); +- if (timer == nullptr) { +- ANSR_LOGW("Failed to get boot time due to TimeServiceClient is null."); +- } else { +- int64_t bootTimeMs = timer->GetBootTimeMs(); +- if (bootTimeMs >= 0) { +- firstRealTimeInMilliSeconds_ = static_cast(bootTimeMs); +- } else { +- ANSR_LOGW("Get boot time error."); +- } +- } +-} +- +-ReminderRequestTimer::ReminderRequestTimer(const ReminderRequestTimer &other) : ReminderRequest(other) +-{ +- firstRealTimeInMilliSeconds_ = other.firstRealTimeInMilliSeconds_; +- countDownTimeInSeconds_ = other.countDownTimeInSeconds_; +-} +- +-uint64_t ReminderRequestTimer::GetInitInfo() const +-{ +- return countDownTimeInSeconds_; +-} +- +-void ReminderRequestTimer::SetInitInfo(const uint64_t countDownTimeInSeconds) +-{ +- countDownTimeInSeconds_ = countDownTimeInSeconds; +-} +- +-uint64_t ReminderRequestTimer::PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) +-{ +- ANSR_LOGD("countdown time not support PreGetNextTriggerTimeIgnoreSnooze"); +- return ReminderRequest::INVALID_LONG_LONG_VALUE; +-} +- +-bool ReminderRequestTimer::OnDateTimeChange() +-{ +- UpdateTimeInfo("onDateTimeChange"); +- return false; +-} +- +-bool ReminderRequestTimer::OnTimeZoneChange() +-{ +- UpdateTimeInfo("onTimeZoneChange"); +- return false; +-} +- +-bool ReminderRequestTimer::UpdateNextReminder() +-{ +- ANSR_LOGD("countdown time not support repeat reminder, no need to update next triggerTime"); +- SetExpired(true); +- return false; +-} +- +-void ReminderRequestTimer::CheckParamsValid(const uint64_t countDownTimeInSeconds) const +-{ +- if (countDownTimeInSeconds == 0 || countDownTimeInSeconds >= (UINT64_MAX / ReminderRequest::MILLI_SECONDS)) { +- ANSR_LOGE("Illegal count down time, please check the description of the constructor"); +- return; +- } +-} +- +-void ReminderRequestTimer::UpdateTimeInfo(const std::string &description) +-{ +- if (IsExpired()) { +- return; +- } +- +- ANSR_LOGD("%{public}s, update countdown time trigger time", description.c_str()); +- time_t now; +- (void)time(&now); // unit is seconds. +- whenToChangeSysTime_ = ReminderRequest::GetDurationSinceEpochInMilli(now); +- sptr timer = MiscServices::TimeServiceClient::GetInstance(); +- if (timer == nullptr) { +- ANSR_LOGW("Failed to updateTime info due to TimeServiceClient is null."); +- return; +- } +- int64_t bootTime = timer->GetBootTimeMs(); +- if (bootTime < 0) { +- ANSR_LOGW("BootTime is illegal"); +- return; +- } +- SetTriggerTimeInMilli(whenToChangeSysTime_ + countDownTimeInSeconds_ * MILLI_SECONDS - +- (static_cast(bootTime) - firstRealTimeInMilliSeconds_)); +-} +- +-bool ReminderRequestTimer::Marshalling(Parcel &parcel) const +-{ +- if (ReminderRequest::Marshalling(parcel)) { +- // write int +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, firstRealTimeInMilliSeconds_, "firstRealTimeInMilliSeconds"); +- WRITE_UINT64_RETURN_FALSE_LOG(parcel, countDownTimeInSeconds_, "countDownTimeInSeconds"); +- return true; +- } +- return false; +-} +- +-ReminderRequestTimer *ReminderRequestTimer::Unmarshalling(Parcel &parcel) +-{ +- auto objptr = new (std::nothrow) ReminderRequestTimer(); +- if (objptr == nullptr) { +- ANSR_LOGE("Failed to create reminder timer due to no memory."); +- return objptr; +- } +- if (!objptr->ReadFromParcel(parcel)) { +- delete objptr; +- objptr = nullptr; +- } +- return objptr; +-} +- +-bool ReminderRequestTimer::ReadFromParcel(Parcel &parcel) +-{ +- if (ReminderRequest::ReadFromParcel(parcel)) { +- // read int +- READ_UINT64_RETURN_FALSE_LOG(parcel, firstRealTimeInMilliSeconds_, "firstRealTimeInMilliSeconds"); +- READ_UINT64_RETURN_FALSE_LOG(parcel, countDownTimeInSeconds_, "countDownTimeInSeconds"); +- return true; +- } +- return false; +-} +-} +-} +diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h +index 2a1ae288..e503d8d6 100644 +--- a/frameworks/core/include/ans_manager_interface.h ++++ b/frameworks/core/include/ans_manager_interface.h +@@ -652,62 +652,62 @@ public: + */ + virtual ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) = 0; + +- /** +- * @brief Publishes a reminder notification. +- * +- * @param reminder Identifies the reminder notification request that needs to be published. +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode PublishReminder(sptr &reminder) = 0; +- +- /** +- * @brief Cancel a reminder notifications. +- * +- * @param reminderId Identifies the reminders id that needs to be canceled. +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode CancelReminder(const int32_t reminderId) = 0; +- +- /** +- * @brief Get all valid reminder notifications. +- * +- * @param reminders Identifies the list of all valid notifications. +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode GetValidReminders(std::vector> &reminders) = 0; +- +- /** +- * @brief Cancel all reminder notifications. +- * +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode CancelAllReminders() = 0; +- +- /** +- * @brief Add exclude date for reminder +- * +- * @param reminderId Identifies the reminders id. +- * @param date exclude date +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) = 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 dates exclude dates +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) = 0; ++ // /** ++ // * @brief Publishes a reminder notification. ++ // * ++ // * @param reminder Identifies the reminder notification request that needs to be published. ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode PublishReminder(sptr &reminder) = 0; ++ ++ // /** ++ // * @brief Cancel a reminder notifications. ++ // * ++ // * @param reminderId Identifies the reminders id that needs to be canceled. ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode CancelReminder(const int32_t reminderId) = 0; ++ ++ // /** ++ // * @brief Get all valid reminder notifications. ++ // * ++ // * @param reminders Identifies the list of all valid notifications. ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode GetValidReminders(std::vector> &reminders) = 0; ++ ++ // /** ++ // * @brief Cancel all reminder notifications. ++ // * ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode CancelAllReminders() = 0; ++ ++ // /** ++ // * @brief Add exclude date for reminder ++ // * ++ // * @param reminderId Identifies the reminders id. ++ // * @param date exclude date ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) = 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 dates exclude dates ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) = 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 2c6afcea..db8df7d9 100644 +--- a/frameworks/core/include/ans_manager_proxy.h ++++ b/frameworks/core/include/ans_manager_proxy.h +@@ -649,62 +649,62 @@ public: + */ + ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override; + +- /** +- * @brief Publishes a reminder notification. +- * +- * @param reminder Identifies the reminder notification request that needs to be published. +- * @return Returns ERR_OK on success, others on failure. +- */ +- ErrCode PublishReminder(sptr &reminder) override; +- +- /** +- * @brief Cancel a reminder notifications. +- * +- * @param reminderId Identifies the reminders id that needs to be canceled. +- * @return Returns ERR_OK on success, others on failure. +- */ +- ErrCode CancelReminder(const int32_t reminderId) override; +- +- /** +- * @brief Get all valid reminder notifications. +- * +- * @param reminders Identifies the list of all valid notifications. +- * @return Returns ERR_OK on success, others on failure. +- */ +- ErrCode GetValidReminders(std::vector> &reminders) override; +- +- /** +- * @brief Cancel all reminder notifications. +- * +- * @return Returns ERR_OK on success, others on failure. +- */ +- ErrCode CancelAllReminders() override; +- +- /** +- * @brief Add exclude date for reminder +- * +- * @param reminderId Identifies the reminders id. +- * @param date exclude date +- * @return Returns ERR_OK on success, others on failure. +- */ +- ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) 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 dates exclude dates +- * @return Returns ERR_OK on success, others on failure. +- */ +- ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; ++ // /** ++ // * @brief Publishes a reminder notification. ++ // * ++ // * @param reminder Identifies the reminder notification request that needs to be published. ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // ErrCode PublishReminder(sptr &reminder) override; ++ ++ // /** ++ // * @brief Cancel a reminder notifications. ++ // * ++ // * @param reminderId Identifies the reminders id that needs to be canceled. ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // ErrCode CancelReminder(const int32_t reminderId) override; ++ ++ // /** ++ // * @brief Get all valid reminder notifications. ++ // * ++ // * @param reminders Identifies the list of all valid notifications. ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // ErrCode GetValidReminders(std::vector> &reminders) override; ++ ++ // /** ++ // * @brief Cancel all reminder notifications. ++ // * ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // ErrCode CancelAllReminders() override; ++ ++ // /** ++ // * @brief Add exclude date for reminder ++ // * ++ // * @param reminderId Identifies the reminders id. ++ // * @param date exclude date ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) 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 dates exclude dates ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) 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 bdd0e5bb..51650a77 100644 +--- a/frameworks/core/include/ans_manager_stub.h ++++ b/frameworks/core/include/ans_manager_stub.h +@@ -642,62 +642,62 @@ public: + */ + virtual ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override; + +- /** +- * @brief Publishes a reminder notification. +- * +- * @param reminder Identifies the reminder notification request that needs to be published. +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode PublishReminder(sptr &reminder) override; +- +- /** +- * @brief Cancel a reminder notifications. +- * +- * @param reminderId Identifies the reminders id that needs to be canceled. +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode CancelReminder(const int32_t reminderId) override; +- +- /** +- * @brief Get all valid reminder notifications. +- * +- * @param reminders Identifies the list of all valid notifications. +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode GetValidReminders(std::vector> &reminders) override; +- +- /** +- * @brief Cancel all reminder notifications. +- * +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode CancelAllReminders() override; +- +- /** +- * @brief Add exclude date for reminder +- * +- * @param reminderId Identifies the reminders id. +- * @param date exclude date +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) 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 dates exclude dates +- * @return Returns ERR_OK on success, others on failure. +- */ +- virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; ++ // /** ++ // * @brief Publishes a reminder notification. ++ // * ++ // * @param reminder Identifies the reminder notification request that needs to be published. ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode PublishReminder(sptr &reminder) override; ++ ++ // /** ++ // * @brief Cancel a reminder notifications. ++ // * ++ // * @param reminderId Identifies the reminders id that needs to be canceled. ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode CancelReminder(const int32_t reminderId) override; ++ ++ // /** ++ // * @brief Get all valid reminder notifications. ++ // * ++ // * @param reminders Identifies the list of all valid notifications. ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode GetValidReminders(std::vector> &reminders) override; ++ ++ // /** ++ // * @brief Cancel all reminder notifications. ++ // * ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode CancelAllReminders() override; ++ ++ // /** ++ // * @brief Add exclude date for reminder ++ // * ++ // * @param reminderId Identifies the reminders id. ++ // * @param date exclude date ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) 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 dates exclude dates ++ // * @return Returns ERR_OK on success, others on failure. ++ // */ ++ // virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; + + /** + * @brief Checks whether this device is support template. +@@ -1012,13 +1012,13 @@ private: + ErrCode HandleGetDeviceRemindType(MessageParcel &data, MessageParcel &reply); + ErrCode HandlePublishContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); + ErrCode HandleCancelContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); +- ErrCode HandlePublishReminder(MessageParcel &data, MessageParcel &reply); +- 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 HandlePublishReminder(MessageParcel &data, MessageParcel &reply); ++ // 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 20287108..cb70a6da 100644 +--- a/frameworks/core/include/ans_notification.h ++++ b/frameworks/core/include/ans_notification.h +@@ -876,64 +876,7 @@ public: + * @brief try to reconnect ans SA when SA manager OnAddSystemAbility called. + */ + void Reconnect(); +- +- /** +- * @brief Publishes a scheduled reminder. +- * +- * @param reminder Indicates a reminder. +- * @return Returns publish result. +- */ +- ErrCode PublishReminder(ReminderRequest &reminder); +- +- /** +- * @brief Cancels a specified reminder. +- * +- * @param reminderId Indicates reminder Id. +- * @return Returns cancel result. +- */ +- ErrCode CancelReminder(const int32_t reminderId); +- +- /** +- * @brief Cancels all reminders of current third part application. +- * +- * @return Returns cancel result. +- */ +- ErrCode CancelAllReminders(); +- +- /** +- * @brief Obtains all valid reminder notifications set by the current application. +- * +- * @param[out] validReminders Indicates the vector to store the result. +- * @return Returns get valid reminders result. +- */ +- ErrCode GetValidReminders(std::vector> &validReminders); +- +- /** +- * @brief Add exclude date for reminder +- * +- * @param reminderId Identifies the reminders id. +- * @param date exclude date +- * @return Returns ERR_OK on success, others on failure. +- */ +- ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date); +- +- /** +- * @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 dates exclude dates +- * @return Returns ERR_OK on success, others on failure. +- */ +- ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); +- ++ + /** + * @brief Checks whether this application has permission to publish notifications under the user. + * +diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp +index 00fb37e7..5a141e43 100644 +--- a/frameworks/core/src/ans_notification.cpp ++++ b/frameworks/core/src/ans_notification.cpp +@@ -24,9 +24,6 @@ + #include "iservice_registry.h" + #include "notification_button_option.h" + #include "notification_local_live_view_subscriber.h" +-#include "reminder_request_alarm.h" +-#include "reminder_request_calendar.h" +-#include "reminder_request_timer.h" + #include "system_ability_definition.h" + #include "unique_fd.h" + +@@ -1340,103 +1337,6 @@ void AnsNotification::Reconnect() + } + } + +-ErrCode AnsNotification::PublishReminder(ReminderRequest &reminder) +-{ +- sptr tarReminder = nullptr; +- switch (reminder.GetReminderType()) { +- case (ReminderRequest::ReminderType::TIMER): { +- ANSR_LOGI("Publish timer"); +- ReminderRequestTimer &timer = (ReminderRequestTimer &)reminder; +- tarReminder = new (std::nothrow) ReminderRequestTimer(timer); +- break; +- } +- case (ReminderRequest::ReminderType::ALARM): { +- ANSR_LOGI("Publish alarm"); +- ReminderRequestAlarm &alarm = (ReminderRequestAlarm &)reminder; +- tarReminder = new (std::nothrow) ReminderRequestAlarm(alarm); +- break; +- } +- case (ReminderRequest::ReminderType::CALENDAR): { +- ANSR_LOGI("Publish calendar"); +- ReminderRequestCalendar &calendar = (ReminderRequestCalendar &)reminder; +- tarReminder = new (std::nothrow) ReminderRequestCalendar(calendar); +- break; +- } +- default: { +- ANSR_LOGW("PublishReminder fail."); +- return ERR_ANS_INVALID_PARAM; +- } +- } +- sptr proxy = GetAnsManagerProxy(); +- if (!proxy) { +- ANS_LOGE("GetAnsManagerProxy fail."); +- return ERR_ANS_SERVICE_NOT_CONNECTED; +- } +- ErrCode code = proxy->PublishReminder(tarReminder); +- reminder.SetReminderId(tarReminder->GetReminderId()); +- return code; +-} +- +-ErrCode AnsNotification::CancelReminder(const int32_t reminderId) +-{ +- sptr proxy = GetAnsManagerProxy(); +- if (!proxy) { +- ANS_LOGE("GetAnsManagerProxy fail."); +- return ERR_ANS_SERVICE_NOT_CONNECTED; +- } +- return proxy->CancelReminder(reminderId); +-} +- +-ErrCode AnsNotification::CancelAllReminders() +-{ +- sptr proxy = GetAnsManagerProxy(); +- if (!proxy) { +- ANS_LOGE("GetAnsManagerProxy fail."); +- return ERR_ANS_SERVICE_NOT_CONNECTED; +- } +- return proxy->CancelAllReminders(); +-} +- +-ErrCode AnsNotification::GetValidReminders(std::vector> &validReminders) +-{ +- sptr proxy = GetAnsManagerProxy(); +- if (!proxy) { +- ANS_LOGE("GetAnsManagerProxy fail."); +- return ERR_ANS_SERVICE_NOT_CONNECTED; +- } +- return proxy->GetValidReminders(validReminders); +-} +- +-ErrCode AnsNotification::AddExcludeDate(const int32_t reminderId, const uint64_t date) +-{ +- sptr proxy = GetAnsManagerProxy(); +- if (!proxy) { +- ANS_LOGE("GetAnsManagerProxy fail."); +- return ERR_ANS_SERVICE_NOT_CONNECTED; +- } +- return proxy->AddExcludeDate(reminderId, date); +-} +- +-ErrCode AnsNotification::DelExcludeDates(const int32_t reminderId) +-{ +- sptr proxy = GetAnsManagerProxy(); +- if (!proxy) { +- ANS_LOGE("GetAnsManagerProxy fail."); +- return ERR_ANS_SERVICE_NOT_CONNECTED; +- } +- return proxy->DelExcludeDates(reminderId); +-} +- +-ErrCode AnsNotification::GetExcludeDates(const int32_t reminderId, std::vector& dates) +-{ +- sptr proxy = GetAnsManagerProxy(); +- if (!proxy) { +- ANS_LOGE("GetAnsManagerProxy fail."); +- return ERR_ANS_SERVICE_NOT_CONNECTED; +- } +- return proxy->GetExcludeDates(reminderId, dates); +-} +- + sptr AnsNotification::GetAnsManagerProxy() + { + sptr systemAbilityManager = +diff --git a/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp b/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp +index f5256f48..e5b32313 100644 +--- a/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp ++++ b/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp +@@ -30,266 +30,266 @@ + + namespace OHOS { + namespace Notification { +-ErrCode AnsManagerProxy::PublishReminder(sptr &reminder) +-{ +- ANSR_LOGI("PublishReminder"); +- MessageParcel data; +- if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { +- ANSR_LOGE("[PublishReminder] fail: write interface token failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- if (reminder == nullptr) { +- ANSR_LOGW("[PublishReminder] fail: reminder is null ptr."); +- return ERR_ANS_INVALID_PARAM; +- } +- if (!data.WriteUint8(static_cast(reminder->GetReminderType()))) { +- ANSR_LOGE("[PublishReminder] fail: write reminder type failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- if (!data.WriteParcelable(reminder)) { +- ANSR_LOGE("[Publish] fail: write reminder parcelable failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } ++// ErrCode AnsManagerProxy::PublishReminder(sptr &reminder) ++// { ++// ANSR_LOGI("PublishReminder"); ++// MessageParcel data; ++// if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ++// ANSR_LOGE("[PublishReminder] fail: write interface token failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// if (reminder == nullptr) { ++// ANSR_LOGW("[PublishReminder] fail: reminder is null ptr."); ++// return ERR_ANS_INVALID_PARAM; ++// } ++// if (!data.WriteUint8(static_cast(reminder->GetReminderType()))) { ++// ANSR_LOGE("[PublishReminder] fail: write reminder type failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// if (!data.WriteParcelable(reminder)) { ++// ANSR_LOGE("[Publish] fail: write reminder parcelable failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } + +- MessageParcel reply; +- MessageOption option = {MessageOption::TF_SYNC}; +- ErrCode result = InnerTransact(NotificationInterfaceCode::PUBLISH_REMINDER, option, data, reply); +- if (result != ERR_OK) { +- ANSR_LOGE("[PublishReminder] fail: transact ErrCode=%{public}d", result); +- return ERR_ANS_TRANSACT_FAILED; +- } +- int32_t reminderId = -1; +- if (!reply.ReadInt32(reminderId)) { +- ANSR_LOGE("[PublishReminder] fail: read reminder id failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- reminder->SetReminderId(reminderId); +- ANSR_LOGD("ReminderId=%{public}d", reminder->GetReminderId()); +- if (!reply.ReadInt32(result)) { +- ANSR_LOGE("[PublishReminder] fail: read result failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- return result; +-} ++// MessageParcel reply; ++// MessageOption option = {MessageOption::TF_SYNC}; ++// ErrCode result = InnerTransact(NotificationInterfaceCode::PUBLISH_REMINDER, option, data, reply); ++// if (result != ERR_OK) { ++// ANSR_LOGE("[PublishReminder] fail: transact ErrCode=%{public}d", result); ++// return ERR_ANS_TRANSACT_FAILED; ++// } ++// int32_t reminderId = -1; ++// if (!reply.ReadInt32(reminderId)) { ++// ANSR_LOGE("[PublishReminder] fail: read reminder id failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// reminder->SetReminderId(reminderId); ++// ANSR_LOGD("ReminderId=%{public}d", reminder->GetReminderId()); ++// if (!reply.ReadInt32(result)) { ++// ANSR_LOGE("[PublishReminder] fail: read result failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// return result; ++// } + +-ErrCode AnsManagerProxy::CancelReminder(const int32_t reminderId) +-{ +- ANSR_LOGI("[CancelReminder]"); +- MessageParcel data; +- if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { +- ANSR_LOGE("[CancelReminder] fail: write interface token failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- if (!data.WriteInt32(reminderId)) { +- ANSR_LOGE("[CancelReminder] fail: write reminder id failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } ++// ErrCode AnsManagerProxy::CancelReminder(const int32_t reminderId) ++// { ++// ANSR_LOGI("[CancelReminder]"); ++// MessageParcel data; ++// if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ++// ANSR_LOGE("[CancelReminder] fail: write interface token failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// if (!data.WriteInt32(reminderId)) { ++// ANSR_LOGE("[CancelReminder] fail: write reminder id failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } + +- MessageParcel reply; +- MessageOption option = {MessageOption::TF_SYNC}; +- ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_REMINDER, option, data, reply); +- if (result != ERR_OK) { +- ANSR_LOGE("[CancelReminder] fail: transact ErrCode=%{public}d", result); +- return ERR_ANS_TRANSACT_FAILED; +- } +- if (!reply.ReadInt32(result)) { +- ANSR_LOGE("[CancelReminder] fail: read result failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- return result; +-} ++// MessageParcel reply; ++// MessageOption option = {MessageOption::TF_SYNC}; ++// ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_REMINDER, option, data, reply); ++// if (result != ERR_OK) { ++// ANSR_LOGE("[CancelReminder] fail: transact ErrCode=%{public}d", result); ++// return ERR_ANS_TRANSACT_FAILED; ++// } ++// if (!reply.ReadInt32(result)) { ++// ANSR_LOGE("[CancelReminder] fail: read result failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// return result; ++// } + +-ErrCode AnsManagerProxy::CancelAllReminders() +-{ +- ANSR_LOGI("[CancelAllReminders]"); +- MessageParcel data; +- if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { +- ANSR_LOGE("[CancelAllReminders] fail: write interface token failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } ++// ErrCode AnsManagerProxy::CancelAllReminders() ++// { ++// ANSR_LOGI("[CancelAllReminders]"); ++// MessageParcel data; ++// if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ++// ANSR_LOGE("[CancelAllReminders] fail: write interface token failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } + +- MessageParcel reply; +- MessageOption option = {MessageOption::TF_SYNC}; +- ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_ALL_REMINDERS, option, data, reply); +- if (result != ERR_OK) { +- ANSR_LOGE("[CancelAllReminders] fail: transact ErrCode=%{public}d", result); +- return ERR_ANS_TRANSACT_FAILED; +- } +- if (!reply.ReadInt32(result)) { +- ANSR_LOGE("[CancelAllReminders] fail: read result failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- return result; +-} ++// MessageParcel reply; ++// MessageOption option = {MessageOption::TF_SYNC}; ++// ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_ALL_REMINDERS, option, data, reply); ++// if (result != ERR_OK) { ++// ANSR_LOGE("[CancelAllReminders] fail: transact ErrCode=%{public}d", result); ++// return ERR_ANS_TRANSACT_FAILED; ++// } ++// if (!reply.ReadInt32(result)) { ++// ANSR_LOGE("[CancelAllReminders] fail: read result failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// return result; ++// } + +-ErrCode AnsManagerProxy::GetValidReminders(std::vector> &reminders) +-{ +- ANSR_LOGI("[GetValidReminders]"); +- MessageParcel data; +- if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { +- ANSR_LOGE("[GetValidReminders] fail: write interface token failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } ++// ErrCode AnsManagerProxy::GetValidReminders(std::vector> &reminders) ++// { ++// ANSR_LOGI("[GetValidReminders]"); ++// MessageParcel data; ++// if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ++// ANSR_LOGE("[GetValidReminders] fail: write interface token failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } + +- MessageParcel reply; +- MessageOption option = {MessageOption::TF_SYNC}; +- ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS, option, data, reply); +- if (result != ERR_OK) { +- ANSR_LOGE("[GetValidReminders] fail: transact ErrCode=%{public}d", result); +- return ERR_ANS_TRANSACT_FAILED; +- } +- uint8_t count = 0; +- if (!reply.ReadUint8(count)) { +- ANSR_LOGE("[GetValidReminders] fail: read reminder count failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- ANSR_LOGD("[GetValidReminders] count=%{public}hhu", count); +- reminders.clear(); +- result = ReadReminders(count, reply, reminders); +- if (result != ERR_OK) { +- ANSR_LOGE("[GetValidReminders] fail: ReadReminders ErrCode=%{public}d", result); +- return result; +- } else { +- ANSR_LOGD("[GetValidReminders], size=%{public}zu", reminders.size()); +- } +- if (!reply.ReadInt32(result)) { +- ANSR_LOGE("[GetValidReminders] fail: read result failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- return result; +-} ++// MessageParcel reply; ++// MessageOption option = {MessageOption::TF_SYNC}; ++// ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS, option, data, reply); ++// if (result != ERR_OK) { ++// ANSR_LOGE("[GetValidReminders] fail: transact ErrCode=%{public}d", result); ++// return ERR_ANS_TRANSACT_FAILED; ++// } ++// uint8_t count = 0; ++// if (!reply.ReadUint8(count)) { ++// ANSR_LOGE("[GetValidReminders] fail: read reminder count failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// ANSR_LOGD("[GetValidReminders] count=%{public}hhu", count); ++// reminders.clear(); ++// result = ReadReminders(count, reply, reminders); ++// if (result != ERR_OK) { ++// ANSR_LOGE("[GetValidReminders] fail: ReadReminders ErrCode=%{public}d", result); ++// return result; ++// } else { ++// ANSR_LOGD("[GetValidReminders], size=%{public}zu", reminders.size()); ++// } ++// if (!reply.ReadInt32(result)) { ++// ANSR_LOGE("[GetValidReminders] fail: read result failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// return result; ++// } + +-ErrCode AnsManagerProxy::AddExcludeDate(const int32_t reminderId, const uint64_t date) +-{ +- 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(date)) { +- ANSR_LOGE("[AddExcludeDate] fail: write exclude date failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } ++// ErrCode AnsManagerProxy::AddExcludeDate(const int32_t reminderId, const uint64_t date) ++// { ++// 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(date)) { ++// ANSR_LOGE("[AddExcludeDate] fail: write exclude date 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; +-} ++// 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; +- } ++// 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; +-} ++// 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& dates) +-{ +- 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; +- } ++// ErrCode AnsManagerProxy::GetExcludeDates(const int32_t reminderId, std::vector& dates) ++// { ++// 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 date count failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- ANSR_LOGD("[GetExcludeDates] count=%{public}hhu", count); +- dates.clear(); +- for (uint8_t i = 0; i < count; i++) { +- uint64_t date = 0; +- if (!reply.ReadUint64(date)) { +- ANSR_LOGE("[GetExcludeDates] fail: read exclude date"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- dates.push_back(date); +- } +- if (!reply.ReadInt32(result)) { +- ANSR_LOGE("[GetExcludeDates] fail: read result failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- return result; +-} ++// 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 date count failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// ANSR_LOGD("[GetExcludeDates] count=%{public}hhu", count); ++// dates.clear(); ++// for (uint8_t i = 0; i < count; i++) { ++// uint64_t date = 0; ++// if (!reply.ReadUint64(date)) { ++// ANSR_LOGE("[GetExcludeDates] fail: read exclude date"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// dates.push_back(date); ++// } ++// 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) +-{ +- for (uint8_t i = 0; i < count; i++) { +- uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); +- if (!reply.ReadUint8(typeInfo)) { +- ANSR_LOGE("Failed to read reminder type"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- auto reminderType = static_cast(typeInfo); +- sptr reminder; +- if (ReminderRequest::ReminderType::ALARM == reminderType) { +- ANSR_LOGD("[GetValidReminders] alarm"); +- reminder = reply.ReadParcelable(); +- } else if (ReminderRequest::ReminderType::TIMER == reminderType) { +- ANSR_LOGD("[GetValidReminders] timer"); +- reminder = reply.ReadParcelable(); +- } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { +- ANSR_LOGD("[GetValidReminders] calendar"); +- reminder = reply.ReadParcelable(); +- } else { +- ANSR_LOGW("[GetValidReminders] type=%{public}hhu", typeInfo); +- return ERR_ANS_INVALID_PARAM; +- } +- if (!reminder) { +- ANSR_LOGE("[GetValidReminders] fail: Reminder ReadParcelable failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- reminders.push_back(reminder); +- } +- return ERR_OK; +-} ++// ErrCode AnsManagerProxy::ReadReminders( ++// uint8_t &count, MessageParcel &reply, std::vector> &reminders) ++// { ++// for (uint8_t i = 0; i < count; i++) { ++// uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); ++// if (!reply.ReadUint8(typeInfo)) { ++// ANSR_LOGE("Failed to read reminder type"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// auto reminderType = static_cast(typeInfo); ++// sptr reminder; ++// if (ReminderRequest::ReminderType::ALARM == reminderType) { ++// ANSR_LOGD("[GetValidReminders] alarm"); ++// reminder = reply.ReadParcelable(); ++// } else if (ReminderRequest::ReminderType::TIMER == reminderType) { ++// ANSR_LOGD("[GetValidReminders] timer"); ++// reminder = reply.ReadParcelable(); ++// } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { ++// ANSR_LOGD("[GetValidReminders] calendar"); ++// reminder = reply.ReadParcelable(); ++// } else { ++// ANSR_LOGW("[GetValidReminders] type=%{public}hhu", typeInfo); ++// return ERR_ANS_INVALID_PARAM; ++// } ++// if (!reminder) { ++// ANSR_LOGE("[GetValidReminders] fail: Reminder ReadParcelable failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// reminders.push_back(reminder); ++// } ++// return ERR_OK; ++// } + } // namespace Notification + } // namespace OHOS +diff --git a/frameworks/core/src/manager/ans_manager_stub.cpp b/frameworks/core/src/manager/ans_manager_stub.cpp +index ded5e9a9..bf78dbec 100644 +--- a/frameworks/core/src/manager/ans_manager_stub.cpp ++++ b/frameworks/core/src/manager/ans_manager_stub.cpp +@@ -287,22 +287,22 @@ int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess + result = HandleCancelContinuousTaskNotification(data, reply); + break; + } +- case static_cast(NotificationInterfaceCode::PUBLISH_REMINDER): { +- result = HandlePublishReminder(data, reply); +- break; +- } +- case static_cast(NotificationInterfaceCode::CANCEL_REMINDER): { +- result = HandleCancelReminder(data, reply); +- break; +- } +- case static_cast(NotificationInterfaceCode::CANCEL_ALL_REMINDERS): { +- result = HandleCancelAllReminders(data, reply); +- break; +- } +- case static_cast(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS): { +- result = HandleGetValidReminders(data, reply); +- break; +- } ++ // case static_cast(NotificationInterfaceCode::PUBLISH_REMINDER): { ++ // result = HandlePublishReminder(data, reply); ++ // break; ++ // } ++ // case static_cast(NotificationInterfaceCode::CANCEL_REMINDER): { ++ // result = HandleCancelReminder(data, reply); ++ // break; ++ // } ++ // case static_cast(NotificationInterfaceCode::CANCEL_ALL_REMINDERS): { ++ // result = HandleCancelAllReminders(data, reply); ++ // break; ++ // } ++ // case static_cast(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS): { ++ // result = HandleGetValidReminders(data, reply); ++ // break; ++ // } + case static_cast(NotificationInterfaceCode::IS_SUPPORT_TEMPLATE): { + result = HandleIsSupportTemplate(data, reply); + break; +@@ -433,18 +433,18 @@ int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess + break; + } + #endif +- case static_cast(NotificationInterfaceCode::ADD_EXCLUDE_DATE_REMINDER): { +- result = HandleAddExcludeDate(data, reply); +- break; +- } +- case static_cast(NotificationInterfaceCode::DEL_EXCLUDE_DATES_REMINDER): { +- result = HandleDelExcludeDates(data, reply); +- break; +- } +- case static_cast(NotificationInterfaceCode::GET_EXCLUDE_DATES_REMINDER): { +- result = HandleGetExcludeDates(data, reply); +- break; +- } ++ // case static_cast(NotificationInterfaceCode::ADD_EXCLUDE_DATE_REMINDER): { ++ // result = HandleAddExcludeDate(data, reply); ++ // break; ++ // } ++ // case static_cast(NotificationInterfaceCode::DEL_EXCLUDE_DATES_REMINDER): { ++ // result = HandleDelExcludeDates(data, reply); ++ // break; ++ // } ++ // case static_cast(NotificationInterfaceCode::GET_EXCLUDE_DATES_REMINDER): { ++ // result = HandleGetExcludeDates(data, reply); ++ // break; ++ // } + case static_cast(NotificationInterfaceCode::GET_DONOTDISTURB_PROFILE): { + result = HandleGetDoNotDisturbProfile(data, reply); + break; +@@ -1857,174 +1857,174 @@ ErrCode AnsManagerStub::HandleShellDump(MessageParcel &data, MessageParcel &repl + return ERR_OK; + } + +-ErrCode AnsManagerStub::HandlePublishReminder(MessageParcel &data, MessageParcel &reply) +-{ +- ANSR_LOGI("HandlePublishReminder"); +- uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); +- if (!data.ReadUint8(typeInfo)) { +- ANSR_LOGE("Failed to read reminder type"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- ReminderRequest::ReminderType reminderType = static_cast(typeInfo); +- sptr reminder; +- if (ReminderRequest::ReminderType::ALARM == reminderType) { +- ANSR_LOGD("Publish alarm"); +- reminder = data.ReadParcelable(); +- } else if (ReminderRequest::ReminderType::TIMER == reminderType) { +- ANSR_LOGD("Publish timer"); +- reminder = data.ReadParcelable(); +- } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { +- ANSR_LOGD("Publish calendar"); +- reminder = data.ReadParcelable(); +- } else { +- ANSR_LOGE("Reminder type invalid"); +- return ERR_ANS_INVALID_PARAM; +- } +- if (!reminder) { +- ANSR_LOGE("Reminder ReadParcelable failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- +- ErrCode result = PublishReminder(reminder); +- +- if (!reply.WriteInt32(reminder->GetReminderId())) { +- ANSR_LOGE("Write back reminderId 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::HandleCancelReminder(MessageParcel &data, MessageParcel &reply) +-{ +- ANSR_LOGI("HandleCancelReminder"); +- int32_t reminderId = -1; +- if (!data.ReadInt32(reminderId)) { +- ANSR_LOGE("Read reminder id failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- +- ErrCode result = CancelReminder(reminderId); +- if (!reply.WriteInt32(result)) { +- ANSR_LOGE("Write back result failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- return result; +-} +- +-ErrCode AnsManagerStub::HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply) +-{ +- ErrCode result = CancelAllReminders(); +- if (!reply.WriteInt32(result)) { +- ANSR_LOGE("Write back result failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- return result; +-} +- +-ErrCode AnsManagerStub::HandleGetValidReminders(MessageParcel &data, MessageParcel &reply) +-{ +- ANSR_LOGI("HandleGetValidReminders"); +- std::vector> validReminders; +- ErrCode result = GetValidReminders(validReminders); +- +- ANSR_LOGD("Write back size=%{public}zu", validReminders.size()); +- if (!reply.WriteUint8(static_cast(validReminders.size()))) { +- ANSR_LOGE("Write back reminder count failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- +- for (auto it = validReminders.begin(); it != validReminders.end(); ++it) { +- sptr reminder = (*it); +- uint8_t reminderType = static_cast(reminder->GetReminderType()); +- ANSR_LOGD("ReminderType=%{public}d", reminderType); +- if (!reply.WriteUint8(reminderType)) { +- ANSR_LOGW("Write reminder type failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- if (!reply.WriteParcelable(reminder)) { +- ANSR_LOGW("Write reminder parcelable 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::HandleAddExcludeDate(MessageParcel &data, MessageParcel &reply) +-{ +- ANSR_LOGI("HandleAddExcludeDate"); +- int32_t reminderId = -1; +- if (!data.ReadInt32(reminderId)) { +- ANSR_LOGE("Read reminder id failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- uint64_t date = 0; +- if (!data.ReadUint64(date)) { +- ANSR_LOGE("Read exclude date failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- +- ErrCode result = AddExcludeDate(reminderId, date); +- if (!reply.WriteInt32(result)) { +- ANSR_LOGE("Write back result failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- return result; +-} +- +-ErrCode AnsManagerStub::HandleDelExcludeDates(MessageParcel &data, MessageParcel &reply) +-{ +- ANSR_LOGI("HandleDelExcludeDates"); +- int32_t reminderId = -1; +- if (!data.ReadInt32(reminderId)) { +- ANSR_LOGE("Read reminder id failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- +- ErrCode result = DelExcludeDates(reminderId); +- if (!reply.WriteInt32(result)) { +- ANSR_LOGE("Write back result failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- return result; +-} +- +-ErrCode AnsManagerStub::HandleGetExcludeDates(MessageParcel &data, MessageParcel &reply) +-{ +- ANSR_LOGI("HandleGetExcludeDates"); +- int32_t reminderId = -1; +- if (!data.ReadInt32(reminderId)) { +- ANSR_LOGE("Read reminder id failed."); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- +- std::vector dates; +- ErrCode result = GetExcludeDates(reminderId, dates); +- ANSR_LOGD("Write back size=%{public}zu", dates.size()); +- if (!reply.WriteUint8(static_cast(dates.size()))) { +- ANSR_LOGE("Write back exclude date count failed"); +- return ERR_ANS_PARCELABLE_FAILED; +- } +- +- for (const auto date : dates) { +- if (!reply.WriteUint64(date)) { +- ANSR_LOGW("Write exclude date 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::HandlePublishReminder(MessageParcel &data, MessageParcel &reply) ++// { ++// ANSR_LOGI("HandlePublishReminder"); ++// uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); ++// if (!data.ReadUint8(typeInfo)) { ++// ANSR_LOGE("Failed to read reminder type"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// ReminderRequest::ReminderType reminderType = static_cast(typeInfo); ++// sptr reminder; ++// if (ReminderRequest::ReminderType::ALARM == reminderType) { ++// ANSR_LOGD("Publish alarm"); ++// reminder = data.ReadParcelable(); ++// } else if (ReminderRequest::ReminderType::TIMER == reminderType) { ++// ANSR_LOGD("Publish timer"); ++// reminder = data.ReadParcelable(); ++// } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { ++// ANSR_LOGD("Publish calendar"); ++// reminder = data.ReadParcelable(); ++// } else { ++// ANSR_LOGE("Reminder type invalid"); ++// return ERR_ANS_INVALID_PARAM; ++// } ++// if (!reminder) { ++// ANSR_LOGE("Reminder ReadParcelable failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++ ++// ErrCode result = PublishReminder(reminder); ++ ++// if (!reply.WriteInt32(reminder->GetReminderId())) { ++// ANSR_LOGE("Write back reminderId 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::HandleCancelReminder(MessageParcel &data, MessageParcel &reply) ++// { ++// ANSR_LOGI("HandleCancelReminder"); ++// int32_t reminderId = -1; ++// if (!data.ReadInt32(reminderId)) { ++// ANSR_LOGE("Read reminder id failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++ ++// ErrCode result = CancelReminder(reminderId); ++// if (!reply.WriteInt32(result)) { ++// ANSR_LOGE("Write back result failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// return result; ++// } ++ ++// ErrCode AnsManagerStub::HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply) ++// { ++// ErrCode result = CancelAllReminders(); ++// if (!reply.WriteInt32(result)) { ++// ANSR_LOGE("Write back result failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// return result; ++// } ++ ++// ErrCode AnsManagerStub::HandleGetValidReminders(MessageParcel &data, MessageParcel &reply) ++// { ++// ANSR_LOGI("HandleGetValidReminders"); ++// std::vector> validReminders; ++// ErrCode result = GetValidReminders(validReminders); ++ ++// ANSR_LOGD("Write back size=%{public}zu", validReminders.size()); ++// if (!reply.WriteUint8(static_cast(validReminders.size()))) { ++// ANSR_LOGE("Write back reminder count failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++ ++// for (auto it = validReminders.begin(); it != validReminders.end(); ++it) { ++// sptr reminder = (*it); ++// uint8_t reminderType = static_cast(reminder->GetReminderType()); ++// ANSR_LOGD("ReminderType=%{public}d", reminderType); ++// if (!reply.WriteUint8(reminderType)) { ++// ANSR_LOGW("Write reminder type failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// if (!reply.WriteParcelable(reminder)) { ++// ANSR_LOGW("Write reminder parcelable 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::HandleAddExcludeDate(MessageParcel &data, MessageParcel &reply) ++// { ++// ANSR_LOGI("HandleAddExcludeDate"); ++// int32_t reminderId = -1; ++// if (!data.ReadInt32(reminderId)) { ++// ANSR_LOGE("Read reminder id failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// uint64_t date = 0; ++// if (!data.ReadUint64(date)) { ++// ANSR_LOGE("Read exclude date failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++ ++// ErrCode result = AddExcludeDate(reminderId, date); ++// if (!reply.WriteInt32(result)) { ++// ANSR_LOGE("Write back result failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// return result; ++// } ++ ++// ErrCode AnsManagerStub::HandleDelExcludeDates(MessageParcel &data, MessageParcel &reply) ++// { ++// ANSR_LOGI("HandleDelExcludeDates"); ++// int32_t reminderId = -1; ++// if (!data.ReadInt32(reminderId)) { ++// ANSR_LOGE("Read reminder id failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++ ++// ErrCode result = DelExcludeDates(reminderId); ++// if (!reply.WriteInt32(result)) { ++// ANSR_LOGE("Write back result failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++// return result; ++// } ++ ++// ErrCode AnsManagerStub::HandleGetExcludeDates(MessageParcel &data, MessageParcel &reply) ++// { ++// ANSR_LOGI("HandleGetExcludeDates"); ++// int32_t reminderId = -1; ++// if (!data.ReadInt32(reminderId)) { ++// ANSR_LOGE("Read reminder id failed."); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++ ++// std::vector dates; ++// ErrCode result = GetExcludeDates(reminderId, dates); ++// ANSR_LOGD("Write back size=%{public}zu", dates.size()); ++// if (!reply.WriteUint8(static_cast(dates.size()))) { ++// ANSR_LOGE("Write back exclude date count failed"); ++// return ERR_ANS_PARCELABLE_FAILED; ++// } ++ ++// for (const auto date : dates) { ++// if (!reply.WriteUint64(date)) { ++// ANSR_LOGW("Write exclude date 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) + { +diff --git a/frameworks/core/src/manager/ans_manager_stub_invalid.cpp b/frameworks/core/src/manager/ans_manager_stub_invalid.cpp +index e447bad8..62d5cea3 100644 +--- a/frameworks/core/src/manager/ans_manager_stub_invalid.cpp ++++ b/frameworks/core/src/manager/ans_manager_stub_invalid.cpp +@@ -454,47 +454,47 @@ ErrCode AnsManagerStub::CancelContinuousTaskNotification(const std::string &labe + return ERR_INVALID_OPERATION; + } + +-ErrCode AnsManagerStub::PublishReminder(sptr &reminder) +-{ +- ANS_LOGE("AnsManagerStub::PublishReminder called!"); +- return ERR_INVALID_OPERATION; +-} +- +-ErrCode AnsManagerStub::CancelReminder(const int32_t reminderId) +-{ +- ANS_LOGE("AnsManagerStub::CancelReminder called!"); +- return ERR_INVALID_OPERATION; +-} +- +-ErrCode AnsManagerStub::GetValidReminders(std::vector> &reminders) +-{ +- ANS_LOGE("AnsManagerStub::getValidReminders called!"); +- return ERR_INVALID_OPERATION; +-} +- +-ErrCode AnsManagerStub::CancelAllReminders() +-{ +- ANS_LOGE("AnsManagerStub::cancelAllReminders called!"); +- return ERR_INVALID_OPERATION; +-} +- +-ErrCode AnsManagerStub::AddExcludeDate(const int32_t reminderId, const uint64_t date) +-{ +- 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& dates) +-{ +- ANS_LOGE("AnsManagerStub::GetExcludeDates called!"); +- return ERR_INVALID_OPERATION; +-} ++// ErrCode AnsManagerStub::PublishReminder(sptr &reminder) ++// { ++// ANS_LOGE("AnsManagerStub::PublishReminder called!"); ++// return ERR_INVALID_OPERATION; ++// } ++ ++// ErrCode AnsManagerStub::CancelReminder(const int32_t reminderId) ++// { ++// ANS_LOGE("AnsManagerStub::CancelReminder called!"); ++// return ERR_INVALID_OPERATION; ++// } ++ ++// ErrCode AnsManagerStub::GetValidReminders(std::vector> &reminders) ++// { ++// ANS_LOGE("AnsManagerStub::getValidReminders called!"); ++// return ERR_INVALID_OPERATION; ++// } ++ ++// ErrCode AnsManagerStub::CancelAllReminders() ++// { ++// ANS_LOGE("AnsManagerStub::cancelAllReminders called!"); ++// return ERR_INVALID_OPERATION; ++// } ++ ++// ErrCode AnsManagerStub::AddExcludeDate(const int32_t reminderId, const uint64_t date) ++// { ++// 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& dates) ++// { ++// ANS_LOGE("AnsManagerStub::GetExcludeDates called!"); ++// return ERR_INVALID_OPERATION; ++// } + + ErrCode AnsManagerStub::IsSupportTemplate(const std::string &templateName, bool &support) + { +diff --git a/frameworks/js/napi/src/reminder/BUILD.gn b/frameworks/js/napi/src/reminder/BUILD.gn +index 3bdbdddb..434e883a 100644 +--- a/frameworks/js/napi/src/reminder/BUILD.gn ++++ b/frameworks/js/napi/src/reminder/BUILD.gn +@@ -58,7 +58,10 @@ ohos_shared_library("reminderagent") { + "reminder_common.cpp", + ] + +- deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] ++ deps = [ ++ "${frameworks_module_ans_path}:ans_innerkits", ++ "${frameworks_module_reminder_path}:reminder_innerkits", ++ ] + + external_deps = [ + "ability_base:want", +diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp +index f45edf5d..c0349f4b 100644 +--- a/frameworks/js/napi/src/reminder/publish.cpp ++++ b/frameworks/js/napi/src/reminder/publish.cpp +@@ -53,19 +53,19 @@ struct AsyncCallbackInfo { + napi_ref callback = nullptr; + napi_value result = nullptr; + int32_t reminderId = -1; +- uint64_t excludeDate = 0; ++ int64_t excludeDate = 0; + bool isThrow = false; + NotificationNapi::NotificationConstant::SlotType inType + = NotificationNapi::NotificationConstant::SlotType::CONTENT_INFORMATION; + std::shared_ptr reminder = nullptr; +- std::vector> validReminders; +- std::vector excludeDates; ++ std::vector validReminders; ++ std::vector excludeDates; + CallbackPromiseInfo info; + }; + + struct Parameters { + int32_t reminderId = -1; +- uint64_t excludeDate = 0; ++ int64_t excludeDate = 0; + int32_t errCode = ERR_OK; + NotificationNapi::NotificationConstant::SlotType inType + = NotificationNapi::NotificationConstant::SlotType::CONTENT_INFORMATION; +@@ -805,7 +805,7 @@ napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi + return NotificationNapi::Common::NapiGetBoolean(env, true); + } + +-void GetValidRemindersInner(napi_env env, const std::vector>& validReminders, napi_value& arr) ++void GetValidRemindersInner(napi_env env, const std::vector& validReminders, napi_value& arr) + { + int32_t count = 0; + napi_create_array(env, &arr); +@@ -816,7 +816,7 @@ void GetValidRemindersInner(napi_env env, const std::vector>& validReminders, napi_value& arr) ++void GetAllValidRemindersInner(napi_env env, const std::vector& validReminders, napi_value& arr) + { + int32_t count = 0; + napi_create_array(env, &arr); +@@ -840,12 +840,12 @@ void GetAllValidRemindersInner(napi_env env, const std::vectorGetReminderId(), &reminderId); ++ napi_create_int32(env, reminder.GetReminderId(), &reminderId); + napi_set_named_property(env, result, REMINDER_INFO_REMINDER_ID, reminderId); + napi_set_element(env, arr, count, result); + count++; +@@ -1187,7 +1187,7 @@ napi_value ParseAddExcludeDateParameter(const napi_env &env, const napi_callback + ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); + return nullptr; + } +- params.excludeDate = static_cast(date); ++ params.excludeDate = static_cast(date); + return NotificationNapi::Common::NapiGetNull(env); + } + +@@ -1335,7 +1335,7 @@ napi_value DelExcludeDates(napi_env env, napi_callback_info info) + return isCallback ? NotificationNapi::Common::NapiGetNull(env) : promise; + } + +-void GetExcludeDatesInner(napi_env env, const std::vector& dates, napi_value& arr) ++void GetExcludeDatesInner(napi_env env, const std::vector& dates, napi_value& arr) + { + int32_t count = 0; + napi_create_array(env, &arr); +diff --git a/interfaces/inner_api/reminder_helper.h b/interfaces/inner_api/reminder_helper.h +index 553dea0c..0dbd9e7b 100644 +--- a/interfaces/inner_api/reminder_helper.h ++++ b/interfaces/inner_api/reminder_helper.h +@@ -72,7 +72,7 @@ public: + * @param[out] validReminders Indicates an initial vector to receive the result. + * @return Returns an array list containing all valid reminder notifications set by the current application. + */ +- static ErrCode GetValidReminders(std::vector> &validReminders); ++ static ErrCode GetValidReminders(std::vector &validReminders); + + /** + * Creates a NotificationSlot. +@@ -104,7 +104,7 @@ public: + * @param date exclude date + * @return Returns ERR_OK on success, others on failure. + */ +- static ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date); ++ static ErrCode AddExcludeDate(const int32_t reminderId, const int64_t date); + + /** + * @brief Clear exclude date for reminder +@@ -121,7 +121,7 @@ public: + * @param dates exclude dates + * @return Returns ERR_OK on success, others on failure. + */ +- static ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); ++ static ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); + + private: + static bool CheckPermission(); +diff --git a/notification.gni b/notification.gni +index 77e6889a..d9317424 100644 +--- a/notification.gni ++++ b/notification.gni +@@ -25,6 +25,7 @@ commonlibrary_utils_path = "//commonlibrary/c_utils" + services_path = "${component_path}/services" + frameworks_path = "${component_path}/frameworks" + frameworks_module_ans_path = "${frameworks_path}/ans" ++frameworks_module_reminder_path = "${frameworks_path}/reminder" + interfaces_path = "${component_path}/interfaces" + inner_api_path = "${interfaces_path}/inner_api" + notification_ndk_path = "${interfaces_path}/ndk" diff --git a/notification.gni b/notification.gni index 77e6889af1527d2dc7f8db4070f8d18b36c2a8f4..d9317424c2811483816f1b406c016798cafeb16b 100644 --- a/notification.gni +++ b/notification.gni @@ -25,6 +25,7 @@ commonlibrary_utils_path = "//commonlibrary/c_utils" services_path = "${component_path}/services" frameworks_path = "${component_path}/frameworks" frameworks_module_ans_path = "${frameworks_path}/ans" +frameworks_module_reminder_path = "${frameworks_path}/reminder" interfaces_path = "${component_path}/interfaces" inner_api_path = "${interfaces_path}/inner_api" notification_ndk_path = "${interfaces_path}/ndk"