diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index cc8e50066cefdb0a65e26b6ec60f8bf7df113faf..5529bcc2083326ca12f0bb689737ff83035a4095 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -56,6 +56,7 @@ ohos_shared_library("ans_core") { "${frameworks_path}/ans/native/src/notification_conversational_message.cpp", "${frameworks_path}/ans/native/src/notification_distributed_options.cpp", "${frameworks_path}/ans/native/src/notification_do_not_disturb_date.cpp", + "${frameworks_path}/ans/native/src/notification_flags.cpp", "${frameworks_path}/ans/native/src/notification_helper.cpp", "${frameworks_path}/ans/native/src/notification_long_text_content.cpp", "${frameworks_path}/ans/native/src/notification_media_content.cpp", @@ -76,6 +77,7 @@ ohos_shared_library("ans_core") { "${frameworks_path}/ans/native/src/reminder_request_alarm.cpp", "${frameworks_path}/ans/native/src/reminder_request_calendar.cpp", "${frameworks_path}/ans/native/src/reminder_request_timer.cpp", + "${frameworks_path}/ans/native/src/reminder_store.cpp", ] configs = [ ":private_config" ] @@ -90,12 +92,15 @@ ohos_shared_library("ans_core") { ] external_deps = [ + "ability_runtime:abilitykit_native", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", + "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + "os_account_standard:os_account_innerkits", "samgr_standard:samgr_proxy", "time_native:time_service", ] diff --git a/frameworks/ans/native/BUILD.gn b/frameworks/ans/native/BUILD.gn index df025a7a409c8c2c9ac4e1798881f5f121b7f864..d3d53f7919562aef044746a00483ec9e2db97196 100644 --- a/frameworks/ans/native/BUILD.gn +++ b/frameworks/ans/native/BUILD.gn @@ -51,6 +51,7 @@ ohos_shared_library("ans_innerkits") { "src/notification_conversational_message.cpp", "src/notification_distributed_options.cpp", "src/notification_do_not_disturb_date.cpp", + "src/notification_flags.cpp", "src/notification_helper.cpp", "src/notification_long_text_content.cpp", "src/notification_media_content.cpp", @@ -83,11 +84,13 @@ ohos_shared_library("ans_innerkits") { ] external_deps = [ + "ability_runtime:abilitykit_native", "ability_runtime:want", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", "samgr_standard:samgr_proxy", ] diff --git a/frameworks/ans/native/src/notification_flags.cpp b/frameworks/ans/native/src/notification_flags.cpp new file mode 100644 index 0000000000000000000000000000000000000000..901964bc74583c1d4390df4a91d6559e63b37856 --- /dev/null +++ b/frameworks/ans/native/src/notification_flags.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 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 "notification_flags.h" +#include "ans_log_wrapper.h" + +namespace OHOS { +namespace Notification { +void NotificationFlags::SetSoundEnabled(bool soundEnabled) +{ + soundEnabled_ = soundEnabled; +} + +bool NotificationFlags::IsSoundEnabled() const +{ + return soundEnabled_; +} + +void NotificationFlags::SetVibrationEnabled(bool vibrationEnabled) +{ + vibrationEnabled_ = vibrationEnabled; +} + +bool NotificationFlags::IsVibrationEnabled() const +{ + return vibrationEnabled_; +} + +std::string NotificationFlags::Dump() +{ + return "soundEnabled = " + std::string(soundEnabled_ ? "true" : "false") + + ", vibrationEnabled = " + std::string(vibrationEnabled_ ? "true" : "false"); +} + +bool NotificationFlags::ToJson(nlohmann::json &jsonObject) const +{ + jsonObject["soundEnabled"] = soundEnabled_; + jsonObject["vibrationEnabled"] = vibrationEnabled_; + + return true; +} + +NotificationFlags *NotificationFlags::FromJson(const nlohmann::json &jsonObject) +{ + if (jsonObject.is_null() or !jsonObject.is_object()) { + ANS_LOGE("Invalid JSON object"); + return nullptr; + } + + auto pFlags = new (std::nothrow) NotificationFlags(); + if (pFlags == nullptr) { + ANS_LOGE("Failed to create notificationFlags instance"); + return nullptr; + } + + const auto &jsonEnd = jsonObject.cend(); + if (jsonObject.find("soundEnabled") != jsonEnd) { + pFlags->soundEnabled_ = jsonObject.at("soundEnabled").get(); + } + + if (jsonObject.find("vibrationEnabled") != jsonEnd) { + pFlags->vibrationEnabled_ = jsonObject.at("vibrationEnabled").get(); + } + + return pFlags; +} + +bool NotificationFlags::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteBool(soundEnabled_)) { + ANS_LOGE("Failed to write flag sound enable for the notification"); + return false; + } + + if (!parcel.WriteBool(vibrationEnabled_)) { + ANS_LOGE("Failed to write flag vibration enable for the notification"); + return false; + } + + return true; +} + +NotificationFlags *NotificationFlags::Unmarshalling(Parcel &parcel) +{ + auto templ = new NotificationFlags(); + if ((templ != nullptr) && !templ->ReadFromParcel(parcel)) { + delete templ; + templ = nullptr; + } + + return templ; +} + +bool NotificationFlags::ReadFromParcel(Parcel &parcel) +{ + soundEnabled_ = parcel.ReadBool(); + vibrationEnabled_ = parcel.ReadBool(); + + return true; +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index 98900bcb18c0f688ddde2f85c6594693c9d8eea4..9807dace34bda86b9a1f1c13286baa33428126a2 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -679,6 +679,7 @@ std::string NotificationRequest::Dump() ", messageUsers = " + (!messageUsers_.empty() ? messageUsers_.at(0)->Dump() : "empty") + ", userInputHistory = " + (!userInputHistory_.empty() ? userInputHistory_.at(0) : "empty") + ", distributedOptions = " + distributedOptions_.Dump() + + ", notificationFlags = " + (notificationFlags_ ? "not null" : "null") + " }"; } @@ -777,6 +778,12 @@ NotificationRequest *NotificationRequest::FromJson(const nlohmann::json &jsonObj return nullptr; } + if (!ConvertJsonToNotificationFlags(pRequest, jsonObject)) { + delete pRequest; + pRequest = nullptr; + return nullptr; + } + return pRequest; } @@ -1127,6 +1134,19 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const } } + valid = notificationFlags_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write flags for the notification"); + return false; + } + + if (valid) { + if (!parcel.WriteParcelable(notificationFlags_.get())) { + ANS_LOGE("Failed to write notification flags"); + return false; + } + } + return true; } @@ -1337,6 +1357,15 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) } } + valid = parcel.ReadBool(); + if (valid) { + notificationFlags_ = std::shared_ptr(parcel.ReadParcelable()); + if (!notificationFlags_) { + ANS_LOGE("Failed to read notificationFlags"); + return false; + } + } + return true; } @@ -1359,6 +1388,16 @@ std::shared_ptr NotificationRequest::GetTemplate() const return notificationTemplate_; } +void NotificationRequest::SetFlags(const std::shared_ptr &flags) +{ + notificationFlags_ = flags; +} + +std::shared_ptr NotificationRequest::GetFlags() const +{ + return notificationFlags_; +} + void NotificationRequest::CopyBase(const NotificationRequest &other) { this->notificationId_ = other.notificationId_; @@ -1422,6 +1461,7 @@ void NotificationRequest::CopyOther(const NotificationRequest &other) this->distributedOptions_ = other.distributedOptions_; this->notificationTemplate_ = other.notificationTemplate_; + this->notificationFlags_ = other.notificationFlags_; } bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const @@ -1470,6 +1510,13 @@ bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const } jsonObject["distributedOptions"] = optObj; + nlohmann::json flagsObj; + if (!NotificationJsonConverter::ConvertToJosn(notificationFlags_.get(), flagsObj)) { + ANS_LOGE("Cannot convert notificationFlags to JSON"); + return false; + } + jsonObject["notificationFlags"] = flagsObj; + return true; } @@ -1692,5 +1739,31 @@ bool NotificationRequest::ConvertJsonToNotificationDistributedOptions( return true; } + +bool NotificationRequest::ConvertJsonToNotificationFlags( + NotificationRequest *target, const nlohmann::json &jsonObject) +{ + if (target == nullptr) { + ANS_LOGE("Invalid input parameter"); + return false; + } + + const auto &jsonEnd = jsonObject.cend(); + + if (jsonObject.find("notificationFlags") != jsonEnd) { + auto flagsObj = jsonObject.at("notificationFlags"); + if (!flagsObj.is_null()) { + auto pFlags = NotificationJsonConverter::ConvertFromJosn(flagsObj); + if (pFlags == nullptr) { + ANS_LOGE("Failed to parse notificationFlags!"); + return false; + } + + target->notificationFlags_ = std::shared_ptr(pFlags); + } + } + + return true; +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/native/src/reminder_helper.cpp b/frameworks/ans/native/src/reminder_helper.cpp index 3197916aec4e4f7c1608785cb4759518bdf28f8e..4291b022ef403f7bce52cd722f65b29e02c687f1 100644 --- a/frameworks/ans/native/src/reminder_helper.cpp +++ b/frameworks/ans/native/src/reminder_helper.cpp @@ -29,7 +29,12 @@ namespace Notification { ErrCode ReminderHelper::PublishReminder(ReminderRequest &reminder) { ANSR_LOGI("PublishReminder start"); - + + // wait bundle manager to implement permission check. + // if (!CheckPermission()) { + // return ERR_PERMISSION_DENIED; + // } + NotificationSlot slot(reminder.GetSlotType()); NotificationHelper::AddNotificationSlot(slot); return DelayedSingleton::GetInstance()->PublishReminder(reminder); diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 3b27d3b01f52972a8298a678963e3e5a25f9e8d0..5692fe1e94d3fcc7f36485abce4f10cb52d5dd18 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -14,9 +14,15 @@ */ #include "ans_log_wrapper.h" +#include "bundle_mgr_interface.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "os_account_manager.h" +#include "system_ability_definition.h" #include "want_agent_helper.h" #include "reminder_request.h" +#include "reminder_store.h" namespace OHOS { namespace Notification { @@ -32,6 +38,7 @@ 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 int ReminderRequest::BASE_YEAR = 1900; 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"; @@ -40,13 +47,13 @@ const std::string ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT = "ohos.event.no const std::string ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION = "ohos.event.notification.reminder.REMOVE_NOTIFICATION"; const std::string ReminderRequest::PARAM_REMINDER_ID = "REMINDER_ID"; -const int ReminderRequest::BASE_YEAR = 1900; +const std::string ReminderRequest::SEP_BUTTON_SINGLE = ""; +const std::string ReminderRequest::SEP_BUTTON_MULTI = ""; +const std::string ReminderRequest::SEP_WANT_AGENT = ""; ReminderRequest::ReminderRequest() { - wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; - maxScreenWantAgentInfo_ = - maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; + InitServerObj(); } ReminderRequest::ReminderRequest(const ReminderRequest &other) @@ -74,12 +81,16 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) this->actionButtonMap_ = other.actionButtonMap_; } +ReminderRequest::ReminderRequest(int32_t reminderId) +{ + reminderId_ = reminderId; + InitServerObj(); +} + ReminderRequest::ReminderRequest(ReminderType reminderType) { reminderType_ = reminderType; - wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; - maxScreenWantAgentInfo_ = - maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; + InitServerObj(); } bool ReminderRequest::CanRemove() const @@ -117,6 +128,23 @@ std::string ReminderRequest::Dump() const "]"; } +// std::string ReminderRequest::DumpAll() const +// { +// const time_t nextTriggerTime = static_cast(triggerTimeInMilli_ / MILLI_SECONDS); +// std::string dateTimeInfo = GetTimeInfoInner(nextTriggerTime, TimeFormat::YMDHMS); +// return "Reminder[" +// "reminderId=" + std::to_string(reminderId_) + +// ", type=" + std::to_string(static_cast(reminderType_)) + +// ", state=" + GetState(state_) + +// ", nextTriggerTime=" + dateTimeInfo.c_str() + +// ", content=" + content_ + +// ", expiredContent=" + expiredContent_ + +// ", snoozeContent=" + snoozeContent_ + +// ", title=" + title_ + +// ", isExpired" +// "]"; +// } + ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type) { if (type != ActionButtonType::CLOSE && type != ActionButtonType::SNOOZE) { @@ -159,6 +187,16 @@ void ReminderRequest::InitReminderId() ANSR_LOGI("reminderId_=%{public}d", reminderId_); } +void ReminderRequest::InitUserId(const int &userId) +{ + userId_ = userId; +} + +void ReminderRequest::InitUid(const int32_t &uid) +{ + uid_ = uid; +} + bool ReminderRequest::IsExpired() const { return isExpired_; @@ -360,6 +398,191 @@ bool ReminderRequest::OnTimeZoneChange() return HandleTimeZoneChange(oldZoneTriggerTime, newZoneTriggerTime, nextTriggerTime); } +int64_t ReminderRequest::RecoveryInt64FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType) +{ + if (columnType == DbRecoveryType::INT) { + int value; + resultSet->GetInt(ReminderStore::GetColumnIndex(columnName), value); + return static_cast(value); + } + if (columnType == DbRecoveryType::LONG) { + int64_t value; + resultSet->GetLong(ReminderStore::GetColumnIndex(columnName), value); + return value; + } + ANSR_LOGE("Recovery data error"); + return 0; +} + +void ReminderRequest::RecoveryUint64FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint64_t &attribute) +{ + if (columnType == DbRecoveryType::INT) { + int value; + resultSet->GetInt(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else if (columnType == DbRecoveryType::LONG) { + int64_t value; + resultSet->GetLong(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else { + ANSR_LOGE("Recovery data error"); + } +} + +void ReminderRequest::RecoveryUint32FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint32_t &attribute) +{ + if (columnType == DbRecoveryType::INT) { + int value; + resultSet->GetInt(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else if (columnType == DbRecoveryType::LONG) { + int64_t value; + resultSet->GetLong(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else { + ANSR_LOGE("Recovery data error"); + } +} + +void ReminderRequest::RecoveryUint8FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint8_t &attribute) +{ + if (columnType == DbRecoveryType::INT) { + int value; + resultSet->GetInt(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else if (columnType == DbRecoveryType::LONG) { + int64_t value; + resultSet->GetLong(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else { + ANSR_LOGE("Recovery data error"); + } +} + +void ReminderRequest::RecoveryFromDb(const std::shared_ptr &resultSet) +{ + // reminderId + resultSet->GetInt(ReminderStore::GetColumnIndex(Instance::REMINDER_ID), reminderId_); + + // userId + resultSet->GetInt(ReminderStore::GetColumnIndex(Instance::USER_ID), userId_); + + // uid + resultSet->GetInt(ReminderStore::GetColumnIndex(Instance::UID), uid_); + + // reminderType + int reminderType; + resultSet->GetInt(ReminderStore::GetColumnIndex(Instance::REMINDER_TYPE), reminderType); + reminderType_ = ReminderType(reminderType); // todo check + + // reminderTime + // RecoveryUint64FromDb(resultSet, Instance::REMINDER_TIME, DbRecoveryType::INT, reminderTimeInMilli_); + reminderTimeInMilli_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::REMINDER_TIME, DbRecoveryType::LONG)); + + // triggerTime + // RecoveryUint64FromDb(resultSet, Instance::TRIGGER_TIME, DbRecoveryType::INT, triggerTimeInMilli_); + triggerTimeInMilli_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::TRIGGER_TIME, DbRecoveryType::LONG)); + ANSR_LOGD("~~~~triggerTimeInMilli_=%{public}llu", triggerTimeInMilli_); + + // timeInterval + uint64_t timeIntervalInSecond = + static_cast(RecoveryInt64FromDb(resultSet, Instance::TIME_INTERVAL, DbRecoveryType::LONG)); + // RecoveryUint64FromDb(resultSet, Instance::TIME_INTERVAL, DbRecoveryType::INT, timeIntervalInSecond); + SetTimeInterval(timeIntervalInSecond); + + // snoozeTimes + // RecoveryUint8FromDb(resultSet, Instance::SNOOZE_TIMES, DbRecoveryType::INT, snoozeTimes_); + snoozeTimes_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::SNOOZE_TIMES, DbRecoveryType::INT)); + + // dynamicSnoozeTimes + // RecoveryUint8FromDb(resultSet, Instance::DYNAMIC_SNOOZE_TIMES, DbRecoveryType::INT, snoozeTimesDynamic_); + snoozeTimesDynamic_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::DYNAMIC_SNOOZE_TIMES, DbRecoveryType::INT)); + + // ringDuration + uint64_t ringDurationInSecond = + static_cast(RecoveryInt64FromDb(resultSet, Instance::RING_DURATION, DbRecoveryType::LONG)); + // RecoveryUint64FromDb(resultSet, Instance::RING_DURATION, DbRecoveryType::LONG, ringDurationInSecond); + SetRingDuration(ringDurationInSecond); + + // isExpired + std::string isExpired; + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::IS_EXPIRED), isExpired); + isExpired_ = isExpired == "true" ? true : false; + + // state + // RecoveryUint8FromDb(resultSet, Instance::STATE, DbRecoveryType::INT, state_); + state_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::STATE, DbRecoveryType::INT)); + + // action buttons + RecoveryActionButton(resultSet); + + // slotType + // values.PutInt(Instance::SLOT_ID, reminder->GetSlotType()); + + // notification id + resultSet->GetInt(ReminderStore::GetColumnIndex(Instance::NOTIFICATION_ID), notificationId_); + + // title + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::TITLE), title_); + + // content + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::CONTENT), content_); + + // snoozeContent + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::SNOOZE_CONTENT), snoozeContent_); + + // expiredContent + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::EXPIRED_CONTENT), expiredContent_); + + // wantAgent + + // maxWantAgent + + // auto wantAgentInfo = reminder->GetWantAgentInfo(); + // if (wantAgentInfo == nullptr) { + // std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; + // values.PutString(Instance::AGENT, info); + // } else { + // values.PutString(Instance::AGENT, wantAgentInfo->pkgName + // + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->abilityName); + // } + // auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo(); + // if (maxScreenWantAgentInfo == nullptr) { + // std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; + // values.PutString(Instance::MAX_SCREEN_AGENT, info); + // } else { + // values.PutString(Instance::MAX_SCREEN_AGENT, maxScreenWantAgentInfo->pkgName + // + ReminderRequest::SEP_WANT_AGENT + maxScreenWantAgentInfo->abilityName); + // } + + InitNotificationRequest(); +} + +void ReminderRequest::RecoveryActionButton(const std::shared_ptr &resultSet) +{ + std::string actionButtonInfo; + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::ACTION_BUTTON_INFO), actionButtonInfo); + + // std::string info = ""; + // bool isFirst = true; + // for (auto it = actionButtonMap_.begin(); it != actionButtonMap_.end(); ++it) { + // if (!isFirst) { + // info += SEP_BUTTON_MULTI; + // } + // ActionButtonInfo buttonInfo = it->second; + // info += std::to_string(static_cast(it->first)) + SEP_BUTTON_SINGLE + buttonInfo.title; + // isFirst = false; + // } + // return info; +} + ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo( const std::shared_ptr &maxScreenWantAgentInfo) { @@ -446,6 +669,11 @@ bool ReminderRequest::ShouldShowImmediately() const return true; } +uint8_t ReminderRequest::GetConstStateInactive() +{ + return REMINDER_STATUS_INACTIVE; +} + std::map ReminderRequest::GetActionButtons( ) const { @@ -548,6 +776,16 @@ uint64_t ReminderRequest::GetTriggerTimeInMilli() const return triggerTimeInMilli_; } +int ReminderRequest::GetUserId() const +{ + return userId_; +} + +int32_t ReminderRequest::GetUid() const +{ + return uid_; +} + std::shared_ptr ReminderRequest::GetWantAgentInfo() const { return wantAgentInfo_; @@ -848,7 +1086,13 @@ void ReminderRequest::InitNotificationRequest() ANSR_LOGI("Init notification"); notificationRequest_ = new NotificationRequest(notificationId_); displayContent_ = content_; - AddActionButtons(true); +} + +void ReminderRequest::InitServerObj() +{ + wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; + maxScreenWantAgentInfo_ = + maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; } bool ReminderRequest::IsAlerting() const @@ -861,6 +1105,21 @@ std::string ReminderRequest::GetDateTimeInfo(const time_t &timeInSecond) const return GetTimeInfoInner(timeInSecond, TimeFormat::YMDHMS); } +std::string ReminderRequest::GetButtonInfo() const +{ + std::string info = ""; + bool isFirst = true; + for (auto it = actionButtonMap_.begin(); it != actionButtonMap_.end(); ++it) { + if (!isFirst) { + info += SEP_BUTTON_MULTI; + } + ActionButtonInfo buttonInfo = it->second; + info += std::to_string(static_cast(it->first)) + SEP_BUTTON_SINGLE + buttonInfo.title; + isFirst = false; + } + return info; +} + uint64_t ReminderRequest::GetNowInstantMilli() const { time_t now; @@ -869,7 +1128,7 @@ uint64_t ReminderRequest::GetNowInstantMilli() const ANSR_LOGE("Get now time error"); return 0; } - return static_cast(now * MILLI_SECONDS); + return static_cast(now) * MILLI_SECONDS; } std::string ReminderRequest::GetShowTime(const uint64_t showTime) const @@ -877,6 +1136,8 @@ std::string ReminderRequest::GetShowTime(const uint64_t showTime) const if (reminderType_ == ReminderType::TIMER) { return ""; } else { + // bool isTime24 = false; // todo + const time_t showTimeInSecond = static_cast(showTime / MILLI_SECONDS); return GetTimeInfoInner(showTimeInSecond, TimeFormat::HM); } @@ -978,7 +1239,7 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze) nullptr ); std::shared_ptr buttonWantAgent = - WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo); + WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo, userId_); std::shared_ptr actionButton = NotificationActionButton::Create(nullptr, title, buttonWantAgent); notificationRequest_->AddActionButton(actionButton); @@ -1002,7 +1263,8 @@ void ReminderRequest::AddRemovalWantAgent() wants, nullptr ); - std::shared_ptr wantAgent = WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); + std::shared_ptr wantAgent + = WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); notificationRequest_->SetRemovalWantAgent(wantAgent); } @@ -1022,7 +1284,7 @@ std::shared_ptr ReminderRequest::CreateWantAgent(AppExecFw wants, nullptr ); - return WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); + return WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); } void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element) @@ -1104,7 +1366,7 @@ void ReminderRequest::UpdateNotificationCommon() } time_t now; (void)time(&now); // unit is seconds. - notificationRequest_->SetDeliveryTime(static_cast(now * MILLI_SECONDS)); + notificationRequest_->SetDeliveryTime(static_cast(now) * MILLI_SECONDS); } void ReminderRequest::UpdateNotificationContent(const bool &setSnooze) @@ -1180,5 +1442,147 @@ int ReminderRequest::GetCTime(const TimeTransferType &type, int actualTime) return -1; } } + +int32_t ReminderRequest::GetUid(const int &userId, const std::string &bundleName) +{ + AppExecFwk::ApplicationInfo info; + OHOS::sptr systemAbilityManager + = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + OHOS::sptr remoteObject + = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + OHOS::sptr bundleMgr + = OHOS::iface_cast(remoteObject); + bundleMgr->GetApplicationInfo(bundleName, AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, + static_cast(userId), info); + return static_cast(info.uid); +} + +int ReminderRequest::GetUserId(const int &uid) +{ + int userId = -1; + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); + return userId; +} + +void ReminderRequest::AppendValuesBucket(const sptr &reminder, + const sptr &bundleOption, NativeRdb::ValuesBucket &values) +{ + values.PutInt(Instance::REMINDER_ID, reminder->GetReminderId()); + values.PutString(Instance::PKG_NAME, bundleOption->GetBundleName()); + values.PutInt(Instance::USER_ID, reminder->GetUserId()); + values.PutInt(Instance::UID, reminder->GetUid()); + values.PutString(Instance::APP_LABEL, ""); // no use + values.PutInt(Instance::REMINDER_TYPE, static_cast(reminder->GetReminderType())); + values.PutLong(Instance::REMINDER_TIME, reminder->GetReminderTimeInMilli()); + values.PutLong(Instance::TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); + values.PutLong(Instance::RTC_TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); // no use + values.PutLong(Instance::TIME_INTERVAL, reminder->GetTimeInterval()); + values.PutInt(Instance::SNOOZE_TIMES, reminder->GetSnoozeTimes()); + values.PutInt(Instance::DYNAMIC_SNOOZE_TIMES, reminder->GetSnoozeTimesDynamic()); + values.PutLong(Instance::RING_DURATION, reminder->GetRingDuration()); + values.PutString(Instance::IS_EXPIRED, reminder->IsExpired() ? "true" : "false"); + values.PutString(Instance::IS_ACTIVE, ""); // no use + values.PutInt(Instance::STATE, reminder->GetState()); + values.PutString(Instance::ZONE_ID, ""); // no use + values.PutString(Instance::HAS_SCHEDULED_TIMEOUT, ""); // no use + values.PutString(Instance::ACTION_BUTTON_INFO, reminder->GetButtonInfo()); + values.PutInt(Instance::SLOT_ID, reminder->GetSlotType()); + values.PutInt(Instance::NOTIFICATION_ID, reminder->GetNotificationId()); + values.PutString(Instance::TITLE, reminder->GetTitle()); + values.PutString(Instance::CONTENT, reminder->GetContent()); + values.PutString(Instance::SNOOZE_CONTENT, reminder->GetSnoozeContent()); + values.PutString(Instance::EXPIRED_CONTENT, reminder->GetExpiredContent()); + auto wantAgentInfo = reminder->GetWantAgentInfo(); + if (wantAgentInfo == nullptr) { + std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; + values.PutString(Instance::AGENT, info); + } else { + values.PutString(Instance::AGENT, wantAgentInfo->pkgName + + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->abilityName); + } + auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo(); + if (maxScreenWantAgentInfo == nullptr) { + std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; + values.PutString(Instance::MAX_SCREEN_AGENT, info); + } else { + values.PutString(Instance::MAX_SCREEN_AGENT, maxScreenWantAgentInfo->pkgName + + ReminderRequest::SEP_WANT_AGENT + maxScreenWantAgentInfo->abilityName); + } +} + + + +const std::string ReminderRequest::Instance::REMINDER_ID = "reminder_id"; +const std::string ReminderRequest::Instance::PKG_NAME = "package_name"; +const std::string ReminderRequest::Instance::USER_ID = "user_id"; +const std::string ReminderRequest::Instance::UID = "uid"; +const std::string ReminderRequest::Instance::APP_LABEL = "app_label"; +const std::string ReminderRequest::Instance::REMINDER_TYPE = "reminder_type"; +const std::string ReminderRequest::Instance::REMINDER_TIME = "reminder_time"; +const std::string ReminderRequest::Instance::TRIGGER_TIME = "trigger_time"; +const std::string ReminderRequest::Instance::RTC_TRIGGER_TIME = "rtc_trigger_time"; +const std::string ReminderRequest::Instance::TIME_INTERVAL = "time_interval"; +const std::string ReminderRequest::Instance::SNOOZE_TIMES = "snooze_times"; +const std::string ReminderRequest::Instance::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; +const std::string ReminderRequest::Instance::RING_DURATION = "ring_duration"; +const std::string ReminderRequest::Instance::IS_EXPIRED = "is_expired"; +const std::string ReminderRequest::Instance::IS_ACTIVE = "is_active"; +const std::string ReminderRequest::Instance::STATE = "state"; +const std::string ReminderRequest::Instance::ZONE_ID = "zone_id"; +const std::string ReminderRequest::Instance::HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; +const std::string ReminderRequest::Instance::ACTION_BUTTON_INFO = "button_info"; +const std::string ReminderRequest::Instance::SLOT_ID = "slot_id"; +const std::string ReminderRequest::Instance::NOTIFICATION_ID = "notification_id"; +const std::string ReminderRequest::Instance::TITLE = "title"; +const std::string ReminderRequest::Instance::CONTENT = "content"; +const std::string ReminderRequest::Instance::SNOOZE_CONTENT = "snooze_content"; +const std::string ReminderRequest::Instance::EXPIRED_CONTENT = "expired_content"; +const std::string ReminderRequest::Instance::AGENT = "agent"; +const std::string ReminderRequest::Instance::MAX_SCREEN_AGENT = "maxScreen_agent"; + +std::string ReminderRequest::Instance::SQL_ADD_COLUMNS = ""; +std::vector ReminderRequest::Instance::COLUMNS; + +void ReminderRequest::Instance::Init() +{ + AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", false); + AddColumn(PKG_NAME, "TEXT NOT NULL", false); + AddColumn(USER_ID, "INT NOT NULL", false); + AddColumn(UID, "INT NOT NULL", false); + AddColumn(APP_LABEL, "TEXT", false); + AddColumn(REMINDER_TYPE, "INT NOT NULL", false); + AddColumn(REMINDER_TIME, "BIGINT NOT NULL", false); + AddColumn(TRIGGER_TIME, "BIGINT NOT NULL", false); + AddColumn(RTC_TRIGGER_TIME, "BIGINT NOT NULL", false); + AddColumn(TIME_INTERVAL, "BIGINT NOT NULL", false); + AddColumn(SNOOZE_TIMES, "INT NOT NULL", false); + AddColumn(DYNAMIC_SNOOZE_TIMES, "INT NOT NULL", false); + AddColumn(RING_DURATION, "BIGINT NOT NULL", false); + AddColumn(IS_EXPIRED, "TEXT NOT NULL", false); + AddColumn(IS_ACTIVE, "TEXT NOT NULL", false); + AddColumn(STATE, "INT NOT NULL", false); + AddColumn(ZONE_ID, "TEXT", false); + AddColumn(HAS_SCHEDULED_TIMEOUT, "TEXT", false); + AddColumn(ACTION_BUTTON_INFO, "TEXT", false); + AddColumn(SLOT_ID, "INT", false); + AddColumn(NOTIFICATION_ID, "INT NOT NULL", false); + AddColumn(TITLE, "TEXT", false); + AddColumn(CONTENT, "TEXT", false); + AddColumn(SNOOZE_CONTENT, "TEXT", false); + AddColumn(EXPIRED_CONTENT, "TEXT", false); + AddColumn(AGENT, "TEXT", false); + AddColumn(MAX_SCREEN_AGENT, "TEXT", false); +} + +void ReminderRequest::Instance::AddColumn( + const std::string &name, const std::string &type, const bool &isEnd) +{ + COLUMNS.push_back(name); + if (!isEnd) { + SQL_ADD_COLUMNS += name + " " + type + ", "; + } else { + SQL_ADD_COLUMNS += name + " " + type; + } } } +} \ No newline at end of file diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index f1334689b7764f1a85879601012eeeebdb22834f..cf9a8bf838b31db19077d5c80cc628f4cb41a91a 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -16,6 +16,7 @@ #include "ans_log_wrapper.h" #include "reminder_request_alarm.h" +#include "reminder_store.h" namespace OHOS { namespace Notification { @@ -301,5 +302,67 @@ bool ReminderRequestAlarm::ReadFromParcel(Parcel &parcel) ANSR_LOGD("hour_=%{public}d, minute_=%{public}d, repeatDays_=%{public}d", hour_, minute_, repeatDays_); return true; } + +void ReminderRequestAlarm::RecoveryFromDb(const std::shared_ptr &resultSet) +{ + ReminderRequest::RecoveryFromDb(resultSet); + + // repeatDays + // RecoveryUint8FromDb(resultSet, Instance::REPEAT_DAYS_OF_WEEK, ReminderRequest::DbRecoveryType::INT, repeatDays_); + repeatDays_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::REPEAT_DAYS_OF_WEEK, DbRecoveryType::INT)); + + // hour + // RecoveryUint8FromDb(resultSet, Instance::ALARM_HOUR, ReminderRequest::DbRecoveryType::INT, hour_); + hour_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::ALARM_HOUR, DbRecoveryType::INT)); + + // minute + // RecoveryUint8FromDb(resultSet, Instance::ALARM_MINUTE, ReminderRequest::DbRecoveryType::INT, minute_); + minute_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::ALARM_MINUTE, DbRecoveryType::INT)); +} + +void ReminderRequestAlarm::AppendValuesBucket(const sptr &reminder, + const sptr &bundleOption, NativeRdb::ValuesBucket &values) +{ + uint8_t repeatDays = 0; + uint8_t hour = 0; + uint8_t minute = 0; + if (reminder->GetReminderType() == ReminderRequest::ReminderType::ALARM) { + ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr()); + repeatDays = alarm->GetRepeatDay(); + hour = alarm->GetHour(); + minute = alarm->GetMinute(); + } + values.PutInt(Instance::REPEAT_DAYS_OF_WEEK, repeatDays); + values.PutInt(Instance::ALARM_HOUR, hour); + values.PutInt(Instance::ALARM_MINUTE, minute); +} + +const std::string ReminderRequestAlarm::Instance::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; +const std::string ReminderRequestAlarm::Instance::ALARM_HOUR = "alarm_hour"; +const std::string ReminderRequestAlarm::Instance::ALARM_MINUTE = "alarm_minute"; + +std::string ReminderRequestAlarm::Instance::SQL_ADD_COLUMNS = ""; +std::vector ReminderRequestAlarm::Instance::COLUMNS; + +void ReminderRequestAlarm::Instance::Init() +{ + AddColumn(REPEAT_DAYS_OF_WEEK, "INT", false); + AddColumn(ALARM_HOUR, "INT", false); + AddColumn(ALARM_MINUTE, "INT", true); +} + +void ReminderRequestAlarm::Instance::AddColumn( + const std::string &name, const std::string &type, const bool &isEnd) +{ + COLUMNS.push_back(name); + if (!isEnd) { + SQL_ADD_COLUMNS += name + " " + type + ", "; + } else { + SQL_ADD_COLUMNS += name + " " + type; + } +} } } \ No newline at end of file diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index 115c6fa0d804e308d375bc6f978b7fef2141cfd3..1a6b578ec9717fe0846c45e3cdddf86b2fde0fc4 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -491,5 +491,121 @@ bool ReminderRequestCalendar::ReadFromParcel(Parcel &parcel) } return true; } + +void ReminderRequestCalendar::RecoveryFromDb(const std::shared_ptr &resultSet) +{ + ReminderRequest::RecoveryFromDb(resultSet); + + // repeatDay + repeatDay_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::REPEAT_DAYS, DbRecoveryType::INT)); + + // repeatMonth + repeatMonth_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::REPEAT_MONTHS, DbRecoveryType::INT)); + + // firstDesignateYear + firstDesignateYear_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::FIRST_DESIGNATE_YEAR, DbRecoveryType::INT)); + + // firstDesignateMonth + firstDesignateMonth_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::FIRST_DESIGNATE_MONTH, DbRecoveryType::INT)); + + // firstDesignateDay + firstDesignateDay_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::FIRST_DESIGNATE_DAY, DbRecoveryType::INT)); + + // year + year_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::CALENDAR_YEAR, DbRecoveryType::INT)); + + // month + month_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::CALENDAR_MONTH, DbRecoveryType::INT)); + + // day + day_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::CALENDAR_DAY, DbRecoveryType::INT)); + + // hour + hour_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::CALENDAR_HOUR, DbRecoveryType::INT)); + + // minute + minute_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::CALENDAR_MINUTE, DbRecoveryType::INT)); +} + +void ReminderRequestCalendar::AppendValuesBucket(const sptr &reminder, + const sptr &bundleOption, NativeRdb::ValuesBucket &values) +{ + uint32_t repeatDay = 0; + uint16_t repeatMonth = 0; + uint16_t firstDesignateYear = 0; + uint8_t firstDesignateMonth = 0; + uint8_t firstDesignateDay = 0; + uint16_t year = 0; + uint8_t month = 0; + uint8_t day = 0; + uint8_t hour = 0; + uint8_t minute = 0; + if (reminder->GetReminderType() == ReminderRequest::ReminderType::CALENDAR) { + ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); + repeatDay = calendar->GetRepeatDay(); + repeatMonth = calendar->GetRepeatMonth(); + firstDesignateYear = calendar->GetFirstDesignateYear(); + firstDesignateMonth = calendar->GetFirstDesignageMonth(); + firstDesignateDay = calendar->GetFirstDesignateDay(); + year = calendar->GetYear(); + month = calendar->GetMonth(); + day = calendar->GetDay(); + hour = calendar->GetHour(); + minute = calendar->GetMinute(); + } + values.PutInt(Instance::REPEAT_DAYS, repeatDay); + values.PutInt(Instance::REPEAT_MONTHS, repeatMonth); + values.PutInt(Instance::FIRST_DESIGNATE_YEAR, firstDesignateYear); + values.PutInt(Instance::FIRST_DESIGNATE_MONTH, firstDesignateMonth); + values.PutInt(Instance::FIRST_DESIGNATE_DAY, firstDesignateDay); + values.PutInt(Instance::CALENDAR_YEAR, year); + values.PutInt(Instance::CALENDAR_MONTH, month); + values.PutInt(Instance::CALENDAR_DAY, day); + values.PutInt(Instance::CALENDAR_HOUR, hour); + values.PutInt(Instance::CALENDAR_MINUTE, minute); +} + +const std::string ReminderRequestCalendar::Instance::REPEAT_DAYS = "repeat_days"; +const std::string ReminderRequestCalendar::Instance::REPEAT_MONTHS = "repeat_months"; +const std::string ReminderRequestCalendar::Instance::FIRST_DESIGNATE_YEAR = "first_designate_year"; +const std::string ReminderRequestCalendar::Instance::FIRST_DESIGNATE_MONTH = "first_designate_month"; +const std::string ReminderRequestCalendar::Instance::FIRST_DESIGNATE_DAY = "first_designate_day"; +const std::string ReminderRequestCalendar::Instance::CALENDAR_YEAR = "calendar_year"; +const std::string ReminderRequestCalendar::Instance::CALENDAR_MONTH = "calendar_month"; +const std::string ReminderRequestCalendar::Instance::CALENDAR_DAY = "calendar_day"; +const std::string ReminderRequestCalendar::Instance::CALENDAR_HOUR = "calendar_hour"; +const std::string ReminderRequestCalendar::Instance::CALENDAR_MINUTE = "calendar_minute"; + +std::string ReminderRequestCalendar::Instance::SQL_ADD_COLUMNS = ""; +std::vector ReminderRequestCalendar::Instance::COLUMNS; + +void ReminderRequestCalendar::Instance::Init() +{ + AddColumn(REPEAT_DAYS, "INT", false); + AddColumn(REPEAT_MONTHS, "INT", false); + AddColumn(FIRST_DESIGNATE_YEAR, "INT", false); + AddColumn(FIRST_DESIGNATE_MONTH, "INT", false); + AddColumn(FIRST_DESIGNATE_DAY, "INT", false); + AddColumn(CALENDAR_YEAR, "INT", false); + AddColumn(CALENDAR_MONTH, "INT", false); + AddColumn(CALENDAR_DAY, "INT", false); + AddColumn(CALENDAR_HOUR, "INT", false); + AddColumn(CALENDAR_MINUTE, "INT", false); +} + +void ReminderRequestCalendar::Instance::AddColumn( + const std::string &name, const std::string &type, const bool &isEnd) +{ + COLUMNS.push_back(name); + if (!isEnd) { + SQL_ADD_COLUMNS += name + " " + type + ", "; + } else { + SQL_ADD_COLUMNS += name + " " + type; + } +} } } \ No newline at end of file diff --git a/frameworks/ans/native/src/reminder_store.cpp b/frameworks/ans/native/src/reminder_store.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e6fd403817c72600cd7354e0622750e22a30fe9b --- /dev/null +++ b/frameworks/ans/native/src/reminder_store.cpp @@ -0,0 +1,657 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "ans_log_wrapper.h" +#include "reminder_const.h" +#include "reminder_request_alarm.h" +#include "reminder_request_calendar.h" +#include "reminder_request_timer.h" + +#include "reminder_store.h" + +using namespace OHOS::Notification::ReminderAgent; + +namespace OHOS { +namespace Notification { +const std::string ReminderStore::REMINDER_DB_DIR = "/data/user/0/reminder/"; // todo replace path +const std::string ReminderStore::REMINDER_DB_NAME = "reminder.db"; +const uint32_t ReminderStore::REMINDER_RDB_VERSION = 1; +std::vector ReminderStore::COLUMNS; + +int32_t ReminderStore::ReminderStoreDataCallBack::OnCreate(NativeRdb::RdbStore &store) +{ + ANSR_LOGD("Create table."); + std::string CREATE_REMINDER_TABLE = "CREATE TABLE IF NOT EXISTS " + REMINDER_DB_TABLE + " (" + + ReminderRequest::Instance::SQL_ADD_COLUMNS + + ReminderRequestCalendar::Instance::SQL_ADD_COLUMNS + + ReminderRequestAlarm::Instance::SQL_ADD_COLUMNS + ")"; + ANSR_LOGD("~~~createTable:%{public}s", CREATE_REMINDER_TABLE.c_str()); + return store.ExecuteSql(CREATE_REMINDER_TABLE); +} + +int32_t ReminderStore::ReminderStoreDataCallBack::OnUpgrade(NativeRdb::RdbStore &store, int32_t oldVersion, int32_t newVersion) +{ + return NativeRdb::E_OK; +} + +int32_t ReminderStore::Init() +{ + ANSR_LOGD("Reminder store init."); + + /* std::filesystem::path databaseDir(REMINDER_DB_DIR); + ANSR_LOGD("ReminderStore::%{public}s databaseDir.", __func__); + if (!std::filesystem::exists(databaseDir)) { + bool createDir = std::filesystem::create_directories(REMINDER_DB_DIR); + ANSR_LOGD("ReminderStore::%{public}s createDir.", __func__); + if (!createDir) { + ANSR_LOGE("ReminderStore::%{public}s failed to create directory %{public}s", __func__, REMINDER_DB_DIR.c_str()); + } + } */ + + ReminderRequest::Instance::Init(); + ReminderRequestCalendar::Instance::Init(); + ReminderRequestAlarm::Instance::Init(); + ReminderStore::COLUMNS.insert(ReminderStore::COLUMNS.begin() + , ReminderRequestAlarm::Instance::COLUMNS.begin(), ReminderRequestAlarm::Instance::COLUMNS.end()); + ReminderStore::COLUMNS.insert(ReminderStore::COLUMNS.begin() + , ReminderRequestCalendar::Instance::COLUMNS.begin(), ReminderRequestCalendar::Instance::COLUMNS.end()); + ReminderStore::COLUMNS.insert(ReminderStore::COLUMNS.begin() + , ReminderRequest::Instance::COLUMNS.begin(), ReminderRequest::Instance::COLUMNS.end()); + + int32_t errCode(STATE_FAIL); + std::string dbConfig = ReminderStore::REMINDER_DB_DIR + ReminderStore::REMINDER_DB_NAME; + NativeRdb::RdbStoreConfig config_(dbConfig); + ReminderStoreDataCallBack rdbDataCallBack_; + rdbStore_ = NativeRdb::RdbHelper::GetRdbStore(config_, REMINDER_RDB_VERSION, rdbDataCallBack_, errCode); + if (rdbStore_ == nullptr) { + ANSR_LOGE("ReminderStore init fail, errCode %{public}d.", errCode); + return errCode; + } + return ReminderStore::InitData(); +} + +int32_t ReminderStore::InitData() +{ + ANSR_LOGD("Reminder data init."); + + struct timeb now; + ftime(&now); + time_t nowTime = now.time; + int64_t overDueRtcTime = (static_cast(nowTime) - TIME_INTERVAL_FOR_DELETE) * MILLI_SECONDS; + ANSR_LOGD("OverDueRtcTime: %{public}lld.", overDueRtcTime); + ReminderStore::DeleteRtcTime(overDueRtcTime); // todo check(cannot delete if it is a repeat reminder) + + std::string deleteCondition = ReminderRequest::Instance::IS_EXPIRED + " is true"; + ReminderStore::Delete(deleteCondition); + + int32_t statusChangedRows = STATE_FAIL; + NativeRdb::ValuesBucket statusValues; + statusValues.PutInt(ReminderRequest::Instance::STATE, ReminderRequest::GetConstStateInactive()); + int32_t statusResult = rdbStore_->Update(statusChangedRows, REMINDER_DB_TABLE, statusValues); + ANSR_LOGD("Change status to inactive, changed rows: %{public}d.", statusChangedRows); + + int32_t activeChangedRows = STATE_FAIL; + NativeRdb::ValuesBucket activeValues; + activeValues.PutString(ReminderRequest::Instance::IS_ACTIVE, "false"); + std::string activeUpdateCondition = ReminderRequest::Instance::IS_ACTIVE + " is true"; + std::vector activeWhereArgs; + int32_t activeResult = rdbStore_->Update( + activeChangedRows, REMINDER_DB_TABLE, activeValues, activeUpdateCondition, activeWhereArgs); + ANSR_LOGD("Change status isActive to false, changed rows: %{public}d.", activeChangedRows); + + int32_t scheduledChangedRows = STATE_FAIL; + NativeRdb::ValuesBucket scheduledValues; + scheduledValues.PutString(ReminderRequest::Instance::HAS_SCHEDULED_TIMEOUT, "false"); + std::string scheduledUpdateCondition = ReminderRequest::Instance::HAS_SCHEDULED_TIMEOUT + " is true"; + std::vector scheduledWhereArgs; + int32_t scheduledResult = rdbStore_->Update( + scheduledChangedRows, REMINDER_DB_TABLE, scheduledValues, scheduledUpdateCondition, scheduledWhereArgs); + ANSR_LOGD("Change status has_ScheduledTimeout to false, changed rows: %{public}d.", scheduledChangedRows); + + if (statusResult != NativeRdb::E_OK || activeResult != NativeRdb::E_OK + || scheduledResult != NativeRdb::E_OK) { + ANSR_LOGE("Init data failed."); + return STATE_FAIL; + } + return STATE_OK; +} + +int32_t ReminderStore::Delete(int32_t reminderId) +{ + std::string deleteCondition = ReminderRequest::Instance::REMINDER_ID + + " = " + std::to_string(reminderId); + return ReminderStore::Delete(deleteCondition); +} + +int32_t ReminderStore::DeleteUser(int32_t userId) +{ + std::string deleteCondition = ReminderRequest::Instance::USER_ID + " = " + std::to_string(userId); + return ReminderStore::Delete(deleteCondition); +} + +int32_t ReminderStore::Delete(const std::string &pkg, int32_t userId) +{ + std::string deleteCondition = ReminderRequest::Instance::PKG_NAME + " = " + pkg + " and " + + ReminderRequest::Instance::USER_ID + " = " + std::to_string(userId); + return ReminderStore::Delete(deleteCondition); +} + +int32_t ReminderStore::DeleteRtcTime(int64_t rtcTime) +{ + std::string deleteCondition = ReminderRequest::Instance::RTC_TRIGGER_TIME + + " < " + std::to_string(rtcTime); + return ReminderStore::Delete(deleteCondition); +} + +int32_t ReminderStore::Delete(const std::string &deleteCondition) +{ + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return STATE_FAIL; + } + int32_t deletedRows = STATE_FAIL; + std::vector whereArgs; + int32_t result = rdbStore_->Delete(deletedRows, REMINDER_DB_TABLE, deleteCondition, whereArgs); + if (result != NativeRdb::E_OK) { + ANSR_LOGE("Delete operation failed, deleteConditon: %{public}s," \ + "result: %{public}d.", deleteCondition.c_str(), result); + } + ANSR_LOGD("Delete operation done, deleteConditon: %{public}s," \ + "deleted rows: %{public}d.", deleteCondition.c_str(), deletedRows); + return deletedRows; +} + +int64_t ReminderStore::UpdateOrInsert( + const sptr &reminder, const sptr &bundleOption) +{ + if (reminder->GetReminderType() == ReminderRequest::ReminderType::TIMER) { + ANSR_LOGI("Countdown not support persist."); + return STATE_FAIL; + } + int64_t isSuccess = STATE_FAIL; + if (IsReminderExist(reminder)) { + isSuccess = ReminderStore::Update(reminder, bundleOption); + } else { + isSuccess = ReminderStore::Insert(reminder, bundleOption); + } + return isSuccess; +} + +int64_t ReminderStore::Insert( + const sptr &reminder, const sptr &bundleOption) +{ + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return STATE_FAIL; + } + int64_t rowId = STATE_FAIL; + NativeRdb::ValuesBucket values; + ReminderStore::GenerateData(reminder, bundleOption, values); + int32_t result = rdbStore_->Insert(rowId, REMINDER_DB_TABLE, values); + if (result != NativeRdb::E_OK) { + ANSR_LOGE("Insert operation failed, result: %{public}d, reminderId=%{public}d." + , result, reminder->GetReminderId()); + return result; + } + ANSR_LOGD("Insert successfully, reminderId=%{public}d.", reminder->GetReminderId()); + return result; +} + +int64_t ReminderStore::Update( + const sptr &reminder, const sptr &bundleOption) +{ + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return STATE_FAIL; + } + int32_t changedRows = STATE_FAIL; + NativeRdb::ValuesBucket values; + ReminderStore::GenerateData(reminder, bundleOption, values); + std::string updateCondition = ReminderRequest::Instance::REMINDER_ID + + " = " + std::to_string(reminder->GetReminderId()); + std::vector whereArgs; + int32_t result = rdbStore_->Update(changedRows, REMINDER_DB_TABLE, values, updateCondition, whereArgs); + if ((result != NativeRdb::E_OK) || (changedRows <= 0)) { + ANSR_LOGE("Update operation failed, result: %{public}d, updated rows: %{public}d, reminderId=%{public}d." + , result, changedRows, reminder->GetReminderId()); + return result; + } + ANSR_LOGD("Update successfully, updated rows: %{public}d, reminderId=%{public}d." + , changedRows, reminder->GetReminderId()); + return result; +} + +bool ReminderStore::IsReminderExist(const sptr &reminder) +{ + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return false; + } + std::string queryCondition = "select * from " + REMINDER_DB_TABLE + " where " + + ReminderRequest::Instance::REMINDER_ID + " = " + + std::to_string(reminder->GetReminderId()); + std::vector whereArgs; + std::unique_ptr queryResultSet = rdbStore_->QuerySql(queryCondition, whereArgs); + if (queryResultSet == nullptr) { + ANSR_LOGE("QueryResultSet is null."); + return false; + } + int32_t resultNum; + queryResultSet->GetRowCount(resultNum); + if (resultNum == 0) { + return false; + } + return true; +} + +std::shared_ptr ReminderStore::Query(const std::string &queryCondition) const +{ + std::unique_ptr queryResultSet; + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return queryResultSet; + } + std::vector whereArgs; + queryResultSet = rdbStore_->QuerySql(queryCondition, whereArgs); + return queryResultSet; +} + +std::vector ReminderStore::GetRepeatInfo(int64_t repeatData, int32_t maxRepeatVal) +{ + std::vector repeatInfo; + for (int i = 1; i <= maxRepeatVal; i++) { + if ((repeatData & (1 << (i - 1))) > 0) { + repeatInfo.push_back(i); + } + } + return repeatInfo; +} + +uint8_t ReminderStore::GetColumnIndex(const std::string& name) +{ + uint8_t index = 0; + for (auto it = ReminderStore::COLUMNS.begin(); it != ReminderStore::COLUMNS.end(); ++it) { + if (name == (*it)) { + break; + } + index++; + } + return index; +} + +int32_t ReminderStore::GetMaxId() +{ + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return STATE_FAIL; + } + std::string queryCondition = "select * from " + REMINDER_DB_TABLE + " order by " + + ReminderRequest::Instance::REMINDER_ID + " desc"; // todo * + std::shared_ptr queryResultSet = ReminderStore::Query(queryCondition); + if (queryResultSet == nullptr) { + ANSR_LOGE("QueryResultSet is null."); + return STATE_FAIL; + } + int32_t resultNum; + queryResultSet->GetRowCount(resultNum); + if (resultNum == 0) { + ANSR_LOGI("QueryResultSet is zero."); + return STATE_FAIL; + } + queryResultSet->GoToNextRow(); + int32_t maxId = STATE_FAIL; + int32_t result = queryResultSet->GetInt(0, maxId); + if (result != NativeRdb::E_OK) { + ANSR_LOGE("Query operation failed, result %{public}d.", result); + } + ANSR_LOGD("MaxId: %{public}d.", maxId); + return maxId; +} + +std::vector> ReminderStore::GetAllValidReminders() +{ + std::string queryCondition = "select * from " + REMINDER_DB_TABLE + " where " + + ReminderRequest::Instance::IS_EXPIRED + " is false order by " + + ReminderRequest::Instance::TRIGGER_TIME + " asc"; + return GetReminders(queryCondition); +} + +std::vector> ReminderStore::GetReminders(const std::string &queryCondition) +{ + std::vector> reminders; + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return reminders; + } + std::shared_ptr queryResultSet = Query(queryCondition); + if (queryResultSet == nullptr) { + return reminders; + } + bool isAtLastRow = false; + queryResultSet->IsAtLastRow(isAtLastRow); + while(!isAtLastRow) { + queryResultSet->GoToNextRow(); + sptr reminder; + reminder = BuildReminder(queryResultSet); + reminders.push_back(reminder); + queryResultSet->IsAtLastRow(isAtLastRow); + } + ANSR_LOGD("~~~~size=%{public}d", reminders.size()); + return reminders; +} + +sptr ReminderStore::BuildReminder(const std::shared_ptr &resultSet) +{ + int32_t reminderType; + int32_t reminderId; + resultSet->GetInt(ReminderStore::GetColumnIndex(ReminderRequest::Instance::REMINDER_TYPE), reminderType); + resultSet->GetInt(ReminderStore::GetColumnIndex(ReminderRequest::Instance::REMINDER_ID), reminderId); + + sptr reminder = nullptr; + switch (reminderType) { + case (static_cast(ReminderRequest::ReminderType::TIMER)): { + reminder = new ReminderRequestTimer(reminderId); + break; + } + case (static_cast(ReminderRequest::ReminderType::CALENDAR)): { + reminder = new ReminderRequestCalendar(reminderId); + break; + } + case (static_cast(ReminderRequest::ReminderType::ALARM)): { + reminder = new ReminderRequestAlarm(reminderId); + break; + } + default: { + ANSR_LOGE("ReminderType from database is error, reminderType %{public}d.", reminderType); + } + } + if (reminder != nullptr) { + reminder->RecoveryFromDb(resultSet); + ANSR_LOGI("BuildReminder success."); + } else { + ANSR_LOGW("BuildReminder fail."); + } + return reminder; +} + +bool ReminderStore::GetBundleOption(const int32_t &reminderId, sptr &bundleOption) const +{ + std::string queryCondition = "select " + ReminderRequest::Instance::PKG_NAME + ", " + + ReminderRequest::Instance::UID + " from " + REMINDER_DB_TABLE + " where " + + ReminderRequest::Instance::REMINDER_ID + "=" + std::to_string(reminderId); + std::shared_ptr queryResultSet = Query(queryCondition); + if (queryResultSet == nullptr) { + return false; + } + bool isAtLastRow = false; + queryResultSet->IsAtLastRow(isAtLastRow); + if (isAtLastRow) { + return false; + } + ANSR_LOGD("~~~~1"); + queryResultSet->GoToNextRow(); + std::string pkgName; + GetStringVal(queryResultSet, ReminderRequest::Instance::PKG_NAME, pkgName); + int32_t uid; + GetInt32Val(queryResultSet, ReminderRequest::Instance::UID, uid); + bundleOption->SetBundleName(pkgName); + bundleOption->SetUid(uid); + return true; +} + +void ReminderStore::GetInt32Val(std::shared_ptr &resultSet + , const std::string &name, int32_t &value) const +{ + int32_t columnIndex; + resultSet->GetColumnIndex(name, columnIndex); + resultSet->GetInt(columnIndex, value); // todo check outOf size +} + +void ReminderStore::GetStringVal(std::shared_ptr &resultSet + , const std::string &name, std::string &value) const +{ + int32_t columnIndex; + resultSet->GetColumnIndex(name, columnIndex); + resultSet->GetString(columnIndex, value); +} + +void ReminderStore::GenerateData(const sptr &reminder, + const sptr &bundleOption, NativeRdb::ValuesBucket &values) const +{ + ReminderRequest::AppendValuesBucket(reminder, bundleOption, values); + ReminderRequestCalendar::AppendValuesBucket(reminder, bundleOption, values); + ReminderRequestAlarm::AppendValuesBucket(reminder, bundleOption, values); +} + +/* std::string ReminderStore::ConvertIconToString(std::shared_ptr &icon) +{ + Media::ImageInfo imageInfo; + icon->GetImageInfo(imageInfo); + uint64_t bufferSize = imageInfo.size.width * imageInfo.size.height; + Media::Rect region = {0, 0, imageInfo.size.width, imageInfo.size.height}; + uint8_t dst[bufferSize]; + icon->ReadPixels(bufferSize, 0, imageInfo.size.width, region, dst); + std::string base64Icon = iconhandler_.EncodeToBase64(dst, bufferSize); + std::string compressedIcon; + iconhandler_.CompressString(base64Icon, compressedIcon); + return compressedIcon + SEP_POUND_ICON + std::to_string(imageInfo.size.width) + SEP_POUND_ICON + std::to_string(imageInfo.size.height); +} + +std::shared_ptr ReminderStore::ConvertStringToIcon(const std::string &icon) +{ + std::vector info = iconhandler_.StringSplit(icon, SEP_POUND_ICON); + int32_t width = atoi(info[1].c_str()); + int32_t height = atoi(info[2].c_str()); + Media::InitializationOptions initializationOptions; + initializationOptions.size = {width, height}; + initializationOptions.pixelFormat = Media::PixelFormat::ARGB_8888; + std::string unCompressedIcon; + iconhandler_.DecompressString(info[0], unCompressedIcon); + uint32_t colorLength = initializationOptions.size.height * initializationOptions.size.width; + uint32_t colors[colorLength]; + iconhandler_.DecodeBase64(unCompressedIcon, colorLength, colors); + std::shared_ptr pixelMap = Media::PixelMap::Create(colors, colorLength, initializationOptions); + return pixelMap; +} + +std::string ReminderStore::IconHandler::EncodeToBase64(const uint8_t *dst, const uint64_t &bufferSize) +{ + if (dst == nullptr) { + ANSR_LOGE("ReminderStore::%{public}s buffer input dst address is null.", __func__); + return ""; + } + uint64_t curSize = bufferSize; + std::string ret; + int32_t i = 0; + int32_t j = 0; + uint8_t charArrayThree[3]; + uint8_t charArrayFour[4]; + while (curSize--) { + charArrayThree[i++] = *(dst++); + if (i == 3) { + charArrayFour[0] = (charArrayThree[0] & 0xfc) >> 2; + charArrayFour[1] = ((charArrayThree[0] & 0x03) << 4) + ((charArrayThree[1] & 0xf0) >> 4); + charArrayFour[2] = ((charArrayThree[1] & 0x0f) << 2) + ((charArrayThree[2] & 0xc0) >> 6); + charArrayFour[3] = charArrayThree[2] & 0x3f; + for (i = 0; i < 4; i++) { + ret += BASE64_CHARS[charArrayFour[i]]; + } + i = 0; + } + } + if(i) { + for (j = i; j < 3; j++) { + charArrayThree[j] = '\0'; + } + charArrayFour[0] = (charArrayThree[0] & 0xfc) >> 2; + charArrayFour[1] = ((charArrayThree[0] & 0x03) << 4) + ((charArrayThree[1] & 0xf0) >> 4); + charArrayFour[2] = ((charArrayThree[1] & 0x0f) << 2) + ((charArrayThree[2] & 0xc0) >> 6); + charArrayFour[3] = charArrayThree[2] & 0x3f; + for (j = 0; j < i + 1; j++) { + ret += BASE64_CHARS[charArrayFour[j]]; + } + while (i++ < 3) { + ret += '='; + } + } + return ret; +} + +uint8_t ReminderStore::IconHandler::DecodeBase64(const std::string &base64, const uint32_t colorLength, uint32_t *dst) +{ + int32_t length = base64.size(); + int32_t i = 0; + int32_t j = 0; + int index = 0; + int colorIndex = 0; + uint8_t charArrayThree[3]; + uint8_t charArrayFour[4]; + while (length-- && (base64[index] != '=') && ReminderStore::IconHandler::IsBase64(base64[index])) { + charArrayFour[i++] = base64[index]; + index++; + if (i == 4) { + for (i = 0; i < 4; i++) { + charArrayFour[i] = BASE64_CHARS.find(charArrayFour[i]); + } + charArrayThree[0] = (charArrayFour[0] << 2) + ((charArrayFour[1] & 0x30) >> 4); + charArrayThree[1] = ((charArrayFour[1] & 0xf) << 4) + ((charArrayFour[2] & 0x3c) >> 2); + charArrayThree[2] = ((charArrayFour[2] & 0x3) << 6) + charArrayFour[3]; + for (i = 0; i < 3; i++) { + dst[colorIndex++] = charArrayThree[i]; + } + i = 0; + } + } + if (i) { + for (j = i; j < 4; j++) { + charArrayFour[j] = 0; + } + for (j = 0; j < 4; j++) { + charArrayFour[j] = BASE64_CHARS.find(charArrayFour[j]); + } + charArrayThree[0] = (charArrayFour[0] << 2) + ((charArrayFour[1] & 0x30) >> 4); + charArrayThree[1] = ((charArrayFour[1] & 0xf) << 4) + ((charArrayFour[2] & 0x3c) >> 2); + charArrayThree[2] = ((charArrayFour[2] & 0x3) << 6) + charArrayFour[3]; + for (j = 0; j < i - 1; j++) { + dst[colorIndex++] = charArrayThree[j]; + } + } + return STATE_OK; +} + +inline bool ReminderStore::IconHandler::IsBase64(const char character) { + return (isalnum(character) || (character == '+') || (character == '/')); +} + +std::vector ReminderStore::IconHandler::IntToByte(int32_t num) +{ + std::vector bytes(4); + bytes[0] = (int8_t) ((num >> 24) & 0xff); + bytes[1] = (int8_t) ((num >> 16) & 0xff); + bytes[2] = (int8_t) ((num >> 8) & 0xff); + bytes[3] = (int8_t) (num & 0xff); + return bytes; +} + +int32_t ReminderStore::IconHandler::ByteToInt(const std::vector &bytes) +{ + return (bytes[0] & 0xff) << 24 | (bytes[1] & 0xff) << 16 | (bytes[2] & 0xff) << 8 | (bytes[3] & 0xff); +} + +int32_t ReminderStore::IconHandler::CompressString(const std::string &inputStr, std::string &outputStr) +{ + z_stream zs; + memset_s(&zs, sizeof zs, 0, sizeof zs); + if (deflateInit(&zs, Z_BEST_COMPRESSION) != Z_OK) { + ANSR_LOGE("ReminderStore::%{public}s deflateInit failed while compressing.", __func__); + return STATE_FAIL; + } + zs.next_in = const_cast(reinterpret_cast(inputStr.data())); + zs.avail_in = inputStr.size(); + + int ret; + char outBuffer[BUFFER_SIZE]; + std::string compressedStr; + do { + zs.next_out = reinterpret_cast(outBuffer); + zs.avail_out = sizeof(outBuffer); + ret = deflate(&zs, Z_FINISH); + if (compressedStr.size() < zs.total_out) { + compressedStr.append(outBuffer, zs.total_out - compressedStr.size()); + } + } while (ret == Z_OK); + + deflateEnd(&zs); + if (ret != Z_STREAM_END) { + ANSR_LOGE("ReminderStore::%{public}s: Exception during zlib compression! ret: %{public}d, message: %{public}s.", __func__, ret, zs.msg); + return STATE_FAIL; + } + outputStr = compressedStr; + return STATE_OK; +} + +int32_t ReminderStore::IconHandler::DecompressString(const std::string &inputStr, std::string &outputStr) +{ + z_stream zs; + memset_s(&zs, sizeof zs, 0, sizeof zs); + if (inflateInit(&zs) != Z_OK) { + ANSR_LOGE("ReminderStore::%{public}s deflateInit failed while compressing.", __func__); + return STATE_FAIL; + } + zs.next_in = const_cast(reinterpret_cast(inputStr.data())); + zs.avail_in = inputStr.size(); + + int ret; + char outBuffer[BUFFER_SIZE]; + std::string decompressedStr; + do { + zs.next_out = reinterpret_cast(outBuffer); + zs.avail_out = sizeof(outBuffer); + ret = inflate(&zs, 0); + if (decompressedStr.size() < zs.total_out) { + decompressedStr.append(outBuffer, zs.total_out - decompressedStr.size()); + } + } while (ret == Z_OK); + + inflateEnd(&zs); + if (ret != Z_STREAM_END) { + ANSR_LOGE("ReminderStore::%{public}s: Exception during zlib decompression! ret: %{public}d, message: %{public}s.", __func__, ret, zs.msg); + return STATE_FAIL; + } + outputStr = decompressedStr; + return STATE_OK; +} + +std::vector ReminderStore::IconHandler::StringSplit(std::string source, std::string split) +{ + size_t pos = 0; + std::vector result; + 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; +} */ +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/native/test/unittest/BUILD.gn b/frameworks/ans/native/test/unittest/BUILD.gn index fca3be04e78fec93dc55f6cb7d629c1a05728bbc..873cdd3b8427931b4f1795b800be1414b8613744 100644 --- a/frameworks/ans/native/test/unittest/BUILD.gn +++ b/frameworks/ans/native/test/unittest/BUILD.gn @@ -49,16 +49,17 @@ ohos_unittest("ans_reminder_unit_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "bytrace_standard:bytrace_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp index 3e76090e706690195f1f7761f6000140930a34e9..d658d162c17953ac065308dc2d28117d07eab81a 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp @@ -34,9 +34,10 @@ public: }; /** - * @tc.number : initHour_00100 - * @tc.name : - * @tc.desc : set hour < 0 should throw exception. + * @tc.name: initHour_00100 + * @tc.desc: set hour < 0 should throw exception. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00100, Function | SmallTest | Level1) { @@ -50,9 +51,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00100, Function | SmallTest | Level1 } /** - * @tc.number : initHour_00200 - * @tc.name : - * @tc.desc : set hour > 23 should throw exception. + * @tc.name: initHour_00200 + * @tc.desc: set hour > 23 should throw exception. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00200, Function | SmallTest | Level1) { @@ -66,9 +68,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00200, Function | SmallTest | Level1 } /** - * @tc.number : initHour_00300 - * @tc.name : - * @tc.desc : test set edge value of hour (0 and 23). + * @tc.name: initHour_00300 + * @tc.desc: test set edge value of hour (0 and 23). + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00300, Function | SmallTest | Level1) { @@ -90,9 +93,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00300, Function | SmallTest | Level1 } /** - * @tc.number : initHour_00400 - * @tc.name : - * @tc.desc : set minute < 0 should throw exception. + * @tc.name: initHour_00400 + * @tc.desc: set minute < 0 should throw exception. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00400, Function | SmallTest | Level1) { @@ -106,9 +110,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00400, Function | SmallTest | Level1 } /** - * @tc.number : initHour_00500 - * @tc.name : - * @tc.desc : set minute > 59 should throw exception. + * @tc.name: initHour_00500 + * @tc.desc: set minute > 59 should throw exception. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00500, Function | SmallTest | Level1) { @@ -122,9 +127,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00500, Function | SmallTest | Level1 } /** - * @tc.number : initHour_00600 - * @tc.name : - * @tc.desc : test set edge value of minute (0 and 59). + * @tc.name: initHour_00600 + * @tc.desc: test set edge value of minute (0 and 59). + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00600, Function | SmallTest | Level1) { @@ -137,9 +143,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00600, Function | SmallTest | Level1 } /** - * @tc.number : initDaysOfWeek_00100 - * @tc.name : - * @tc.desc : test set daysOfWeek with normal value. + * @tc.name: initDaysOfWeek_00100 + * @tc.desc: test set daysOfWeek with normal value. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00100, Function | SmallTest | Level1) { @@ -151,9 +158,10 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00100, Function | SmallTest | } /** - * @tc.number : initDaysOfWeek_00200 - * @tc.name : - * @tc.desc : test set daysOfWeek with edge value. + * @tc.name: initDaysOfWeek_00200 + * @tc.desc: test set daysOfWeek with edge value. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00200, Function | SmallTest | Level1) { @@ -164,9 +172,10 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00200, Function | SmallTest | } /** - * @tc.number : initDaysOfWeek_00300 - * @tc.name : - * @tc.desc : test set daysOfWeek with duplicate value. + * @tc.name: initDaysOfWeek_00300 + * @tc.desc: test set daysOfWeek with duplicate value. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00300, Function | SmallTest | Level1) { @@ -177,9 +186,10 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00300, Function | SmallTest | } /** - * @tc.number : initDaysOfWeek_00400 - * @tc.name : - * @tc.desc : test set daysOfWeek exceeding maximum length. + * @tc.name: initDaysOfWeek_00400 + * @tc.desc: test set daysOfWeek exceeding maximum length. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00400, Function | SmallTest | Level1) { @@ -194,9 +204,10 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00400, Function | SmallTest | } /** - * @tc.number : initDaysOfWeek_00500 - * @tc.name : - * @tc.desc : test set daysOfWeek with null value. + * @tc.name: initDaysOfWeek_00500 + * @tc.desc: test set daysOfWeek with null value. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00500, Function | SmallTest | Level1) { diff --git a/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp index 77c61bb7ba59033d1aa27656536fb02033418a4e..f7bc5ed5cb3f750452100c1b20dfeaaddeff48a4 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp @@ -79,9 +79,10 @@ public: }; /** - * @tc.number : initDateTime_00100 - * @tc.name : - * @tc.desc : Check firstDesignateYear set successfully. + * @tc.name: initDateTime_00100 + * @tc.desc: Check firstDesignateYear set successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00100, Function | SmallTest | Level1) { @@ -95,9 +96,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00100, Function | SmallTest | } /** - * @tc.number : initDateTime_00200 - * @tc.name : - * @tc.desc : Check firstDesignateMonth set successfully. + * @tc.name: initDateTime_00200 + * @tc.desc: Check firstDesignateMonth set successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00200, Function | SmallTest | Level1) { @@ -111,9 +113,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00200, Function | SmallTest | } /** - * @tc.number : initDateTime_00300 - * @tc.name : - * @tc.desc : Check firstDesignateDay set successfully. + * @tc.name: initDateTime_00300 + * @tc.desc: Check firstDesignateDay set successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00300, Function | SmallTest | Level1) { @@ -127,9 +130,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00300, Function | SmallTest | } /** - * @tc.number : initDateTime_00400 - * @tc.name : - * @tc.desc : Check repeatMonth set with normal value successfully. + * @tc.name: initDateTime_00400 + * @tc.desc: Check repeatMonth set with normal value successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00400, Function | SmallTest | Level1) { @@ -168,9 +172,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00400, Function | SmallTest | } /** - * @tc.number : initDateTime_00500 - * @tc.name : - * @tc.desc : Check repeatMonth set with exception value successfully. + * @tc.name: initDateTime_00500 + * @tc.desc: Check repeatMonth set with exception value successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00500, Function | SmallTest | Level1) { @@ -209,9 +214,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00500, Function | SmallTest | } /** - * @tc.number : initDateTime_00600 - * @tc.name : - * @tc.desc : Check repeatDay set with nomal value successfully. + * @tc.name: initDateTime_00600 + * @tc.desc: Check repeatDay set with nomal value successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00600, Function | SmallTest | Level1) { @@ -249,9 +255,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00600, Function | SmallTest | } /** - * @tc.number : initDateTime_00700 - * @tc.name : - * @tc.desc : Check repeatDay set with exception value successfully. + * @tc.name: initDateTime_00700 + * @tc.desc: Check repeatDay set with exception value successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00700, Function | SmallTest | Level1) { @@ -291,9 +298,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00700, Function | SmallTest | } /** - * @tc.number : initDateTime_00800 - * @tc.name : - * @tc.desc : Check hour set successfully. + * @tc.name: initDateTime_00800 + * @tc.desc: Check hour set successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00800, Function | SmallTest | Level1) { @@ -306,9 +314,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00800, Function | SmallTest | } /** - * @tc.number : initDateTime_00900 - * @tc.name : - * @tc.desc : Check minut set successfully. + * @tc.name: initDateTime_00900 + * @tc.desc: Check minut set successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00900, Function | SmallTest | Level1) { diff --git a/frameworks/ans/native/test/unittest/reminder_request_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_test.cpp index 1f189e9f55060ad7f53a7217e90b21a0d43b694d..7788b8fc78700801aa4bf6b9473e32b3811a655d 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_test.cpp @@ -38,9 +38,10 @@ public: const uint8_t ReminderRequestTest::REMINDER_STATUS_SHOWING = 4; /** - * @tc.number : CanRemove_00100 - * @tc.name : - * @tc.desc : When reminder init, CanRemove should return true. + * @tc.name: CanRemove_00100 + * @tc.desc: When reminder init, CanRemove should return true. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00100, Function | SmallTest | Level1) { @@ -49,9 +50,10 @@ HWTEST_F(ReminderRequestTest, CanRemove_00100, Function | SmallTest | Level1) } /** - * @tc.number : CanRemove_00200 - * @tc.name : - * @tc.desc : When reminder is shown, CanRemove should return false. + * @tc.name: CanRemove_00200 + * @tc.desc: When reminder is shown, CanRemove should return false. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00200, Function | SmallTest | Level1) { @@ -61,9 +63,10 @@ HWTEST_F(ReminderRequestTest, CanRemove_00200, Function | SmallTest | Level1) } /** - * @tc.number : CanRemove_00300 - * @tc.name : - * @tc.desc : When reminder close, CanRemove should return true. + * @tc.name: CanRemove_00300 + * @tc.desc: When reminder close, CanRemove should return true. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00300, Function | SmallTest | Level1) { @@ -74,9 +77,10 @@ HWTEST_F(ReminderRequestTest, CanRemove_00300, Function | SmallTest | Level1) } /** - * @tc.number : CanRemove_00400 - * @tc.name : - * @tc.desc : When reminder is covered as same notification id, CanRemove should return true. + * @tc.name: CanRemove_00400 + * @tc.desc: When reminder is covered as same notification id, CanRemove should return true. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, CanRemove_00400, Function | SmallTest | Level1) { @@ -88,9 +92,10 @@ HWTEST_F(ReminderRequestTest, CanRemove_00400, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00100 - * @tc.name : - * @tc.desc : When reminder init, state should be 0. + * @tc.name: StateCheck_00100 + * @tc.desc: When reminder init, state should be 0. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00100, Function | SmallTest | Level1) { @@ -99,9 +104,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00100, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00200 - * @tc.name : - * @tc.desc : When reminder close with param true, state REMINDER_STATUS_SHOWING should be unset. + * @tc.name: StateCheck_00200 + * @tc.desc: When reminder close with param true, state REMINDER_STATUS_SHOWING should be unset. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00200, Function | SmallTest | Level1) { @@ -111,9 +117,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00200, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00300 - * @tc.name : - * @tc.desc : When reminder close with param false, state REMINDER_STATUS_SHOWING should be unset. + * @tc.name: StateCheck_00300 + * @tc.desc: When reminder close with param false, state REMINDER_STATUS_SHOWING should be unset. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00300, Function | SmallTest | Level1) { @@ -123,9 +130,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00300, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00400 - * @tc.name : - * @tc.desc : When reminder is covered as same notification id, state REMINDER_STATUS_SHOWING should be unset. + * @tc.name: StateCheck_00400 + * @tc.desc: When reminder is covered as same notification id, state REMINDER_STATUS_SHOWING should be unset. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, StateCheck_00400, Function | SmallTest | Level1) { @@ -135,9 +143,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00400, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00500 - * @tc.name : - * @tc.desc : When reminder is shown with param true,true, state REMINDER_STATUS_SHOWING should be set. + * @tc.name: StateCheck_00500 + * @tc.desc: When reminder is shown with param true,true, state REMINDER_STATUS_SHOWING should be set. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00500, Function | SmallTest | Level1) { @@ -147,9 +156,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00500, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00600 - * @tc.name : - * @tc.desc : When reminder is shown with param false,true, state REMINDER_STATUS_SHOWING should be set. + * @tc.name: StateCheck_00600 + * @tc.desc: When reminder is shown with param false,true, state REMINDER_STATUS_SHOWING should be set. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00600, Function | SmallTest | Level1) { @@ -159,9 +169,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00600, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00700 - * @tc.name : - * @tc.desc : When reminder is shown with param true,false, state REMINDER_STATUS_SHOWING should not change. + * @tc.name: StateCheck_00700 + * @tc.desc: When reminder is shown with param true,false, state REMINDER_STATUS_SHOWING should not change. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00700, Function | SmallTest | Level1) { @@ -172,9 +183,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00700, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00800 - * @tc.name : - * @tc.desc : When reminder is shown with param false,false, state REMINDER_STATUS_SHOWING should be unset. + * @tc.name: StateCheck_00800 + * @tc.desc: When reminder is shown with param false,false, state REMINDER_STATUS_SHOWING should be unset. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00800, Function | SmallTest | Level1) { @@ -185,9 +197,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00800, Function | SmallTest | Level1) } /** - * @tc.number : initReminderId_00100 - * @tc.name : - * @tc.desc : When reminder create successfully, system should assign unique id to reminder. + * @tc.name: initReminderId_00100 + * @tc.desc: When reminder create successfully, system should assign unique id to reminder. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, initReminderId_00100, Function | SmallTest | Level1) { @@ -200,9 +213,10 @@ HWTEST_F(ReminderRequestTest, initReminderId_00100, Function | SmallTest | Level } /** - * @tc.number : setContent_00100 - * @tc.name : - * @tc.desc : Test SetContent with normal parameters. + * @tc.name: setContent_00100 + * @tc.desc: Test SetContent with normal parameters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setContent_00100, Function | SmallTest | Level1) { @@ -213,9 +227,10 @@ HWTEST_F(ReminderRequestTest, setContent_00100, Function | SmallTest | Level1) } /** - * @tc.number : setContent_00200 - * @tc.name : - * @tc.desc : Test SetContent parameters with special characters. + * @tc.name: setContent_00200 + * @tc.desc: Test SetContent parameters with special characters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setContent_00200, Function | SmallTest | Level1) { @@ -226,9 +241,10 @@ HWTEST_F(ReminderRequestTest, setContent_00200, Function | SmallTest | Level1) } /** - * @tc.number : setExpiredContent_00100 - * @tc.name : - * @tc.desc : Test SetExpiredContent with normal parameters. + * @tc.name: setExpiredContent_00100 + * @tc.desc: Test SetExpiredContent with normal parameters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF AR000GNF1U */ HWTEST_F(ReminderRequestTest, setExpiredContent_00100, Function | SmallTest | Level1) { @@ -239,9 +255,10 @@ HWTEST_F(ReminderRequestTest, setExpiredContent_00100, Function | SmallTest | Le } /** - * @tc.number : setExpiredContent_00200 - * @tc.name : - * @tc.desc : Test SetExpiredContent with special characters. + * @tc.name: setExpiredContent_00200 + * @tc.desc: Test SetExpiredContent with special characters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF AR000GNF1U */ HWTEST_F(ReminderRequestTest, setExpiredContent_00200, Function | SmallTest | Level1) { @@ -252,9 +269,10 @@ HWTEST_F(ReminderRequestTest, setExpiredContent_00200, Function | SmallTest | Le } /** - * @tc.number : setTitle_00100 - * @tc.name : - * @tc.desc : Test SetTitle with normal parameters. + * @tc.name: setTitle_00100 + * @tc.desc: Test SetTitle with normal parameters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setTitle_00100, Function | SmallTest | Level1) { @@ -265,9 +283,10 @@ HWTEST_F(ReminderRequestTest, setTitle_00100, Function | SmallTest | Level1) } /** - * @tc.number : setTitle_00200 - * @tc.name : - * @tc.desc : Test SetTitle with special characters. + * @tc.name: setTitle_00200 + * @tc.desc: Test SetTitle with special characters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setTitle_00200, Function | SmallTest | Level1) { @@ -278,9 +297,10 @@ HWTEST_F(ReminderRequestTest, setTitle_00200, Function | SmallTest | Level1) } /** - * @tc.number : setNotificationId_00100 - * @tc.name : - * @tc.desc : Test SetNotificationId parameters. + * @tc.name: setNotificationId_00100 + * @tc.desc: Test SetNotificationId parameters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setNotificationId_00100, Function | SmallTest | Level1) { @@ -289,5 +309,44 @@ HWTEST_F(ReminderRequestTest, setNotificationId_00100, Function | SmallTest | Le rrc->SetNotificationId(notificationId); EXPECT_EQ(rrc->GetNotificationId(), notificationId); } + +/** + * @tc.name: setSnoozeTimes_00100 + * @tc.desc: Test SetSnoozeTimes parameters. + * @tc.type: FUNC + * @tc.require: AR000GNF1T + */ +HWTEST_F(ReminderRequestTest, setSnoozeTimes_00100, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + rrc->SetSnoozeTimes(1); + EXPECT_EQ(rrc->GetSnoozeTimes(), 1) << "Get snoozeTimes not 1"; + EXPECT_EQ(rrc->GetSnoozeTimesDynamic(), 1) << "Get snoozeTimesDynamic not 1"; +} + +/** + * @tc.name: setTimeInterval_00100 + * @tc.desc: Test SetTimeInterval parameters. + * @tc.type: FUNC + * @tc.require: AR000GNF1T + */ +HWTEST_F(ReminderRequestTest, setTimeInterval_00100, Function | SmallTest | Level1) +{ + uint32_t minTimeIntervalInSecond = 5 * 60; + auto rrc = std::make_shared(); + rrc->SetTimeInterval(-1); + EXPECT_EQ(rrc->GetTimeInterval(), 0) << "timeInterval should be 0 when set with value less than 0"; + rrc->SetTimeInterval(0); + EXPECT_EQ(rrc->GetTimeInterval(), 0) << "timeInterval should be 0 when set with value 0"; + rrc->SetTimeInterval(1); + EXPECT_EQ(rrc->GetTimeInterval(), minTimeIntervalInSecond) + << "0 < timeInterval < minTimeInterval should be set to minTimeInterval"; + uint32_t timeInterval = minTimeIntervalInSecond; + rrc->SetTimeInterval(timeInterval); + EXPECT_EQ(rrc->GetTimeInterval(), timeInterval) << "timeInterval set error"; + timeInterval = minTimeIntervalInSecond + 1; + rrc->SetTimeInterval(timeInterval); + EXPECT_EQ(rrc->GetTimeInterval(), timeInterval) << "timeInterval set error."; +} } } \ No newline at end of file diff --git a/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp index 6b39c09bf034b89774c8e488712ecabe947a06e2..852fbb84eb3c575668039f834d654362a0f6c267 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp @@ -37,9 +37,10 @@ public: }; /** - * @tc.number : initCountDownTime_00100 - * @tc.name : - * @tc.desc : set countDownTime = 0 should throw exception. + * @tc.name: initCountDownTime_00100 + * @tc.desc: set countDownTime = 0 should throw exception. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00100, Function | SmallTest | Level1) { @@ -53,9 +54,10 @@ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00100, Function | SmallTest } /** - * @tc.number : initCountDownTime_00200 - * @tc.name : - * @tc.desc : set countDownTime > (UINT64_MAX / 1000) should throw exception. + * @tc.name: initCountDownTime_00200 + * @tc.desc: set countDownTime > (UINT64_MAX / 1000) should throw exception. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00200, Function | SmallTest | Level1) { @@ -69,9 +71,10 @@ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00200, Function | SmallTest /** - * @tc.number : initCountDownTime_00300 - * @tc.name : - * @tc.desc : set countDownTime with normal value. + * @tc.name: initCountDownTime_00300 + * @tc.desc: set countDownTime with normal value. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00300, Function | SmallTest | Level1) { diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index 1015a68459c0d9fb2eb253ef532bd1f1b68cb0b4..c8c3a48de71cd7facbd8e40994ef2f22b324c4c7 100644 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -84,12 +84,12 @@ ohos_moduletest("ans_fw_module_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", @@ -162,12 +162,12 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", @@ -237,12 +237,12 @@ ohos_moduletest("ans_innerkits_module_slot_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", @@ -312,12 +312,12 @@ ohos_moduletest("ans_innerkits_module_setting_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", diff --git a/frameworks/ans/test/moduletest/ReminderHelperTest.js b/frameworks/ans/test/moduletest/ReminderHelperTest.js index c61a047ec7d76b6643b13bf07e59379476698fd2..1b29bd76e39df871077f7fcc0d7f35d75b809817 100644 --- a/frameworks/ans/test/moduletest/ReminderHelperTest.js +++ b/frameworks/ans/test/moduletest/ReminderHelperTest.js @@ -52,7 +52,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper001 * @tc.desc: test publishReminder can return correct reminder id. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper001", 0, async function (done) { let timer = { @@ -82,7 +82,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper002 * @tc.desc: test publishReminder can return correct reminder id. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper002", 0, async function (done) { let timer = { @@ -104,7 +104,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper003 * @tc.desc: test addNotificationSlot instance with null * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EC */ it("testReminderHelper003", 0, async function (done) { function reminderCallback(err, data) { @@ -119,7 +119,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper004 * @tc.desc: test addNotificationSlot instance with null * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EC */ it("testReminderHelper004", 0, async function (done) { let mySlot = null; @@ -141,7 +141,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper005 * @tc.desc: test addNotificationSlot with normal value * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EC */ it("testReminderHelper005", 0, async function (done) { let mySlot = { @@ -158,7 +158,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper006 * @tc.desc: test addNotificationSlot with normal value * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EC */ it("testReminderHelper006", 0, async function (done) { reminderAgent.addNotificationSlot(3, (err, data) => { @@ -172,7 +172,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper007 * @tc.desc: test cancelAllReminders can cancel all exist reminders * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper007", 0, async function (done) { let timer = { @@ -205,7 +205,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper008 * @tc.desc: test cancelAllReminders can cancel all exist reminders * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper008", 0, async function (done) { let timer = { @@ -238,7 +238,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper009 * @tc.desc: test cancelReminder with not exit reminder. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper009", 0, async function (done) { let timer = { @@ -268,7 +268,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper010 * @tc.desc: test cancelReminder with not exit reminder. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper010", 0, async function (done) { let timer = { @@ -297,7 +297,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper011 * @tc.desc: test cancelReminder with exist reminder. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper011", 0, async function (done) { let alarm = { @@ -335,7 +335,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper012 * @tc.desc: test cancelReminder with exist reminder. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper012", 0, async function (done) { let alarm = { @@ -373,7 +373,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper013 * @tc.desc: test getValidReminders, verify all the information is correct. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EB */ it("testReminderHelper013", 0, async function (done) { var alarm = { @@ -403,7 +403,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper014 * @tc.desc: test getValidReminders, verify all the information is correct. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EB */ it("testReminderHelper014", 0, async function (done) { var alarm = { @@ -433,7 +433,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper015 * @tc.desc: test removeNotificationSlot with not exist slot. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8ED */ it("testReminderHelper015", 0, function (done) { function reminderCallback(err, data){ @@ -448,7 +448,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper016 * @tc.desc: test removeNotificationSlot with not exist slot. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8ED */ it("testReminderHelper016", 0, function (done) { let promise = new Promise((resolve, reject) => { @@ -469,7 +469,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper017 * @tc.desc: test removeNotificationSlot with exist slot. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8ED */ it("testReminderHelper017", 0, async function (done) { var tarRemoveSlot = { @@ -487,7 +487,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper018 * @tc.desc: test removeNotificationSlot with exist slot. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8ED */ it("testReminderHelper018", 0, async function (done) { var tarRemoveSlot = { @@ -506,7 +506,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper019 * @tc.desc: test getValidReminders. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EB AR000GH8EG */ it("testReminderHelper019", 0, async function (done) { let timer = { @@ -526,7 +526,7 @@ describe("ReminderHelperTest", function () { * @tc.name:testReminderHelper020 * @tc.desc: test getValidReminders. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EB AR000GH8EG */ it("testReminderHelper020", 0, async function (done) { let timer = { @@ -546,7 +546,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper021 * @tc.desc: test publishReminder a normal alarm. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper021", 0, async function (done) { let alarm = { @@ -567,7 +567,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper022 * @tc.desc: test publishReminder a normal alarm. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper022", 0, async function (done) { let alarm = { @@ -589,7 +589,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper023 * @tc.desc: test publishReminder * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper023", 0, function (done) { let calendar = { @@ -670,7 +670,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper024 * @tc.desc: test publishReminder * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper024", 0, async function (done) { let calendar = { @@ -751,7 +751,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper025 * @tc.desc: test publishReminder * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper025", 0, async function (done) { let calendar = { @@ -803,7 +803,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper026 * @tc.desc: test publishReminder * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper026", 0, async function (done) { let calendar = { @@ -855,7 +855,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper027 * @tc.desc: test publishReminder (max number limit of each application) * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper027", 0, async function (done) { let timer = { diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp index b9115de5681a661087cc68d8cdab314c0d8eccd8..a8ac9f30751ead3851743819d44022d910b2073a 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -55,6 +55,7 @@ const int32_t CASE_ELEVEN = 11; const int32_t CASE_TWELVE = 12; const int32_t CASE_THIRTEEN = 13; const int32_t CASE_FOURTEEN = 14; +const int32_t CASE_FIFTEEN = 15; const int32_t CALLING_UID = 9999; const int32_t PIXEL_MAP_TEST_WIDTH = 32; @@ -136,6 +137,8 @@ public: EXPECT_EQ(true, notificationRequest.IsGroupOverview()); } else if (CASE_FOURTEEN == notificationRequest.GetNotificationId()) { CheckCaseFourteenResult(notificationRequest); + } else if (CASE_FIFTEEN == notificationRequest.GetNotificationId()) { + CheckCaseFifteenResult(notificationRequest); } else { GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish::OnConsumed do nothing!!!!!"; } @@ -369,6 +372,15 @@ private: } EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType()); } + + void CheckCaseFifteenResult(NotificationRequest notificationRequest) + { + std::shared_ptr notiFlags = notificationRequest.GetFlags(); + if (notiFlags != nullptr) { + EXPECT_EQ(false, notiFlags->IsSoundEnabled()); + EXPECT_EQ(true, notiFlags->IsVibrationEnabled()); + } + } }; class CompletedCallbackTest : public WantAgent::CompletedCallback { @@ -1327,5 +1339,44 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_08000, Function CheckJsonConverter(&req); } + +/** + * @tc.number : ANS_Interface_MT_Publish_05000 + * @tc.name : Publish_05000 + * @tc.desc : Add notification slot(type is OTHER), make a subscriber and publish a flags notification. + * @tc.expected : Add notification slot success, make a subscriber and publish a flags notification success. + */ +HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_05000, Function | MediumTest | Level1) +{ + NotificationSlot slot(NotificationConstant::OTHER); + EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot)); + auto subscriber = TestAnsSubscriber(); + NotificationSubscribeInfo info = NotificationSubscribeInfo(); + info.AddAppName("bundleName"); + g_subscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); + WaitOnSubscribeResult(); + + std::shared_ptr notiFlags = std::make_shared(); + EXPECT_NE(notiFlags, nullptr); + notiFlags->SetSoundEnabled(false); + notiFlags->SetVibrationEnabled(true); + GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_04000::flags::" << notiFlags->Dump(); + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + NotificationRequest req; + req.SetContent(content); + req.SetFlags(notiFlags); + req.SetSlotType(NotificationConstant::OTHER); + req.SetNotificationId(CASE_FIFTEEN); + g_consumed_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); + WaitOnConsumed(); + g_unsubscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(subscriber, info)); + WaitOnUnsubscribeResult(); +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/frameworks/wantagent/BUILD.gn b/frameworks/wantagent/BUILD.gn index ee4c79b1b82baa8a4e0fed6a646e62194b3934ad..4c3a05b2a193f853b87ea053ac9c7ac4d0eb5c4f 100644 --- a/frameworks/wantagent/BUILD.gn +++ b/frameworks/wantagent/BUILD.gn @@ -69,10 +69,10 @@ ohos_shared_library("wantagent_innerkits") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/src/want_agent_helper.cpp b/frameworks/wantagent/src/want_agent_helper.cpp index 58f13b14279588886a168ce0f95c26096d925734..acd15cff886e52e58c60e9d6ef21814070ab62c2 100644 --- a/frameworks/wantagent/src/want_agent_helper.cpp +++ b/frameworks/wantagent/src/want_agent_helper.cpp @@ -124,7 +124,49 @@ std::shared_ptr WantAgentHelper::GetWantAgent( return agent; } -std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo ¶msInfo) +// std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo ¶msInfo) +// { +// std::vector> wants = paramsInfo.GetWants(); +// if (wants.empty()) { +// WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent invalid input param."); +// return nullptr; +// } + +// std::shared_ptr want = wants[0]; +// if (want == nullptr) { +// WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent invalid input param."); +// return nullptr; +// } + +// WantsInfo wantsInfo; +// wantsInfo.want = *want; +// wantsInfo.resolvedTypes = want->GetType(); +// if (paramsInfo.GetExtraInfo() != nullptr) { +// wantsInfo.want.SetParams(*paramsInfo.GetExtraInfo()); +// } + +// HILOG_INFO("%{public}s:bundle name = %{public}s; ability name = %{public}s", +// __func__, +// wantsInfo.want.GetElement().GetBundleName().c_str(), +// wantsInfo.want.GetElement().GetAbilityName().c_str()); + +// WantSenderInfo wantSenderInfo; +// wantSenderInfo.allWants.push_back(wantsInfo); +// wantSenderInfo.bundleName = want->GetOperation().GetBundleName(); +// wantSenderInfo.flags = FlagsTransformer(paramsInfo.GetFlags()); +// wantSenderInfo.type = (int32_t)paramsInfo.GetOperationType(); + +// sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); +// if (target == nullptr) { +// WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent target is nullptr."); +// return nullptr; +// } +// std::shared_ptr agent = std::make_shared(std::make_shared(target)); + +// return agent; +// } + +std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo ¶msInfo, int32_t userId) { std::vector> wants = paramsInfo.GetWants(); if (wants.empty()) { @@ -155,6 +197,7 @@ std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo &pa wantSenderInfo.bundleName = want->GetOperation().GetBundleName(); wantSenderInfo.flags = FlagsTransformer(paramsInfo.GetFlags()); wantSenderInfo.type = (int32_t)paramsInfo.GetOperationType(); + wantSenderInfo.userId = userId; sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); if (target == nullptr) { @@ -186,6 +229,9 @@ void WantAgentHelper::TriggerWantAgent(const std::shared_ptr &agent, std::shared_ptr pendingWant = agent->GetPendingWant(); WantAgentConstant::OperationType type = GetType(agent); + + HILOG_INFO("~~~~%{public}d", type); + sptr dispatcher = nullptr; if (callback != nullptr) { dispatcher = new (std::nothrow) CompletedDispatcher(pendingWant, callback, nullptr); diff --git a/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn b/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn index 83587c2b946bef190d67e415add4280dcf324743..c2fdd1b29a5e7044a61e6c445390046dde6f8cfb 100644 --- a/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn @@ -44,11 +44,11 @@ ohos_unittest("completed_dispatcher_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn index 6e3099ab13d0e869cbecbda96c107ac660593d3f..8c0f2efd5d6a4dc3ff6dbd2bcacdc5259955dec7 100644 --- a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn @@ -51,11 +51,11 @@ ohos_unittest("pending_want_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn b/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn index c1f05358a3ced3c2d6cd169750fd0dde70ddfec9..936039c909cdf3f6d8c443da3e6ae26c37785c1c 100644 --- a/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn @@ -44,11 +44,11 @@ ohos_unittest("trigger_Info_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn index 42ebaf1f42cb62c222d769c4543911cc8a0ba732..e33afabc488db5ebf8dad66dd43c3e32338f7221 100644 --- a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn @@ -48,11 +48,11 @@ ohos_unittest("want_agent_helper_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn index 7d29fdf0e854536e5791312a76e35a7b2924f619..0d7bc82738ce8124e73003a4c3b027382a5a0f5b 100644 --- a/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn @@ -44,11 +44,11 @@ ohos_unittest("want_agent_info_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn index c08997e88576526a865df0cc7f04cc0f17c0bd7c..2d8437643ef9fd6378e50186ff88733df0bd4fd7 100644 --- a/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn @@ -44,11 +44,11 @@ ohos_unittest("want_agent_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/interfaces/innerkits/ans/native/include/notification_flags.h b/interfaces/innerkits/ans/native/include/notification_flags.h new file mode 100644 index 0000000000000000000000000000000000000000..09664ed4d1575837df2a3b965cab60b567e080ce --- /dev/null +++ b/interfaces/innerkits/ans/native/include/notification_flags.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 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. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_FLAGS_H +#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_FLAGS_H + +#include +#include "parcel.h" +#include "notification_json_convert.h" + +namespace OHOS { +namespace Notification { +class NotificationFlags : public Parcelable, public NotificationJsonConvertionBase { +public: + /** + * Default constructor used to create an empty NotificationFlags instance. + */ + NotificationFlags() = default; + + /** + * Default deconstructor used to deconstruct. + */ + ~NotificationFlags() = default; + + /** + * Sets the notification whether enable sound. + * @param soundEnabled whether enable sound. + */ + void SetSoundEnabled(bool soundEnabled); + + /** + * Checks whether enable sound. + * @return sound enable. + */ + bool IsSoundEnabled() const; + + /** + * Sets the notification whether enable vibration. + * @param vibrationEnabled whether enable vibration. + */ + void SetVibrationEnabled(bool vibrationEnabled); + + /** + * Checks whether enable vibration. + * @return vibration enable. + */ + bool IsVibrationEnabled() const; + + /** + * Returns a string representation of the object. + * @return a string representation of the object. + */ + std::string Dump(); + + /** + * Converts a NotificationFlags object into a Json. + * @param jsonObject Indicates the Json object. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * Creates a NotificationFlags object from a Json. + * @param jsonObject Indicates the Json object. + * @return the NotificationFlags. + */ + static NotificationFlags *FromJson(const nlohmann::json &jsonObject); + + /** + * Marshal a object into a Parcel. + * @param parcel the object into the parcel + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * Unmarshal object from a Parcel. + * @return the NotificationFlags + */ + static NotificationFlags *Unmarshalling(Parcel &parcel); + +private: + /** + * Read a NotificationFlags object from a Parcel. + * @param parcel the parcel + */ + bool ReadFromParcel(Parcel &parcel); + +private: + bool soundEnabled_ {true}; + bool vibrationEnabled_ {false}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_FLAGS_H + diff --git a/interfaces/innerkits/ans/native/include/notification_request.h b/interfaces/innerkits/ans/native/include/notification_request.h index 93b5f2d9a8f233e70d17ddac8b1c7ac0df83b2c6..e2f6190f8ec06c8b690ba0f72a2355336bd9ce9c 100644 --- a/interfaces/innerkits/ans/native/include/notification_request.h +++ b/interfaces/innerkits/ans/native/include/notification_request.h @@ -20,6 +20,7 @@ #include "notification_action_button.h" #include "notification_content.h" #include "notification_distributed_options.h" +#include "notification_flags.h" #include "notification_json_convert.h" #include "notification_template.h" #include "ohos/aafwk/content/want_params.h" @@ -915,6 +916,18 @@ public: */ std::shared_ptr GetTemplate() const; + /** + * Sets the flags of this notification. + * @param flags the flags of this notification. + */ + void SetFlags(const std::shared_ptr &flags); + + /** + * Obtains the flags of the notification. + * @return the flags of the notification. + */ + std::shared_ptr GetFlags() const; + private: /** * Indicates the color mask, used for calculation with the ARGB value set by setColor(int32_t). @@ -958,6 +971,7 @@ private: static bool ConvertJsonToNotificationActionButton(NotificationRequest *target, const nlohmann::json &jsonObject); static bool ConvertJsonToNotificationDistributedOptions( NotificationRequest *target, const nlohmann::json &jsonObject); + static bool ConvertJsonToNotificationFlags(NotificationRequest *target, const nlohmann::json &jsonObject); private: int32_t notificationId_ {0}; @@ -1019,6 +1033,7 @@ private: NotificationDistributedOptions distributedOptions_; std::shared_ptr notificationTemplate_ {}; + std::shared_ptr notificationFlags_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/reminder_const.h b/interfaces/innerkits/ans/native/include/reminder_const.h new file mode 100644 index 0000000000000000000000000000000000000000..88c3379d641922230afbcb673bfbf7b457fffda9 --- /dev/null +++ b/interfaces/innerkits/ans/native/include/reminder_const.h @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_CONST_H +#define BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_CONST_H + +#include +#include + +namespace OHOS { +namespace Notification { +namespace ReminderAgent { +const int32_t STATE_FAIL = -1; +const int32_t STATE_OK = 0; + +/* const int32_t BUFFER_SIZE = 8192; */ +const uint16_t TIME_INTERVAL_FOR_DELETE = 1800; +const uint16_t MILLI_SECONDS = 1000; + +const std::string REMINDER_DB_TABLE = "reminder"; +/* const std::string SEP_POUND_ICON = "#"; +const std::string BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; */ + +// ReminderRequest column name +// const std::string ACTION_BUTTON_INFO = "button_info"; +// const std::string AGENT = "agent"; +// const std::string APP_LABEL = "app_label"; +// const std::string CONTENT = "content"; +// const std::string DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; +// const std::string EXPIRED_CONTENT = "expired_content"; +// const std::string HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; +// const std::string IS_ACTIVE = "is_active"; +// const std::string IS_EXPIRED = "is_expired"; +// const std::string MAX_SCREEN_AGENT = "maxScreen_agent"; +// const std::string NOTIFICATION_ID = "notification_id"; +// const std::string PKG_NAME = "package_name"; +// const std::string REMINDER_ID = "reminder_id"; +// const std::string REMINDER_TIME = "reminder_time"; +// const std::string REMINDER_TYPE = "reminder_type"; +// const std::string RING_DURATION = "ring_duration"; +// const std::string RTC_TRIGGER_TIME = "rtc_trigger_time"; +// const std::string SLOT_ID = "slot_id"; +// const std::string SNOOZE_CONTENT = "snooze_content"; +// const std::string SNOOZE_TIMES = "snooze_times"; +// const std::string STATE = "state"; +// const std::string TIME_INTERVAL = "time_interval"; +// const std::string TITLE = "title"; +// const std::string TRIGGER_TIME = "trigger_time"; +// const std::string USER_ID = "user_id"; +// const std::string ZONE_ID = "zone_id"; +// /* const std::string REMINDER_DATA_ICON = "icon"; */ + +// // ReminderRequestCalendar column name +// const std::string CALENDAR_YEAR = "calendar_year"; +// const std::string CALENDAR_MONTH = "calendar_month"; +// const std::string CALENDAR_DAY = "calendar_day"; +// const std::string CALENDAR_HOUR = "calendar_hour"; +// const std::string CALENDAR_MINUTE = "calendar_minute"; +// const std::string FIRST_DESIGNATE_YEAR = "first_designate_year"; +// const std::string FIRST_DESIGNATE_MONTH = "first_designate_month"; +// const std::string FIRST_DESIGNATE_DAY = "first_designate_day"; +// const std::string REPEAT_DAYS = "repeat_days"; +// const std::string REPEAT_MONTHS = "repeat_months"; + +// // ReminderRequestAlarm column name +// const std::string ALARM_HOUR = "alarm_hour"; +// const std::string ALARM_MINUTE = "alarm_minute"; +// const std::string REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; + +// // create reminder table +// const std::string CREATE_REMINDER_TABLE = "CREATE TABLE IF NOT EXISTS " + REMINDER_DB_TABLE + " (" +// + REMINDER_ID + " INTEGER PRIMARY KEY, " +// + PKG_NAME + " TEXT NOT NULL, " +// + USER_ID + " INT NOT NULL, " +// + APP_LABEL + " TEXT, " +// + REMINDER_TYPE + " INT NOT NULL, " +// + REMINDER_TIME + " BIGINT NOT NULL, " +// + TRIGGER_TIME + " BIGINT NOT NULL, " +// + RTC_TRIGGER_TIME + " BIGINT NOT NULL, " +// + TIME_INTERVAL + " BIGINT NOT NULL, " +// + SNOOZE_TIMES + " INT NOT NULL, " +// + DYNAMIC_SNOOZE_TIMES + " INT NOT NULL, " +// + RING_DURATION + " BIGINT NOT NULL, " +// + IS_EXPIRED + " TEXT NOT NULL, " +// + IS_ACTIVE + " TEXT NOT NULL, " +// + STATE + " TEXT NOT NULL, " +// + ZONE_ID + " TEXT, " +// + HAS_SCHEDULED_TIMEOUT + " TEXT, " +// + ACTION_BUTTON_INFO + " TEXT, " +// + SLOT_ID + " INT, " +// + NOTIFICATION_ID + " INT NOT NULL, " +// + TITLE + " TEXT, " +// + CONTENT + " TEXT, " +// + SNOOZE_CONTENT + " TEXT, " +// + EXPIRED_CONTENT + " TEXT, " +// /* + REMINDER_DATA_ICON + " TEXT, " */ +// + AGENT + " TEXT, " +// + MAX_SCREEN_AGENT + " TEXT, " + +// + REPEAT_DAYS + " INT, " +// + REPEAT_MONTHS + " INT, " +// + FIRST_DESIGNATE_YEAR + " INT, " +// + FIRST_DESIGNATE_MONTH + " INT, " +// + FIRST_DESIGNATE_DAY + " INT, " +// + CALENDAR_YEAR + " INT, " +// + CALENDAR_MONTH + " INT, " +// + CALENDAR_DAY + " INT, " +// + CALENDAR_HOUR + " INT, " +// + CALENDAR_MINUTE + " INT, " + +// + REPEAT_DAYS_OF_WEEK + " INT, " +// + ALARM_HOUR + " INT, " +// + ALARM_MINUTE + " INT)"; +} // namespace ReminderAgent +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_CONST_H \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index b671414152b079807abe67523dae330629a23d0b..88271321956844f2949d1f74c065e6c1de223ea8 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -19,8 +19,11 @@ #include #include +#include "abs_shared_result_set.h" +#include "notification_bundle_option.h" #include "notification_constant.h" #include "notification_request.h" +#include "values_bucket.h" namespace OHOS { namespace Notification { @@ -129,6 +132,14 @@ public: * @param Indicates the exist reminder. */ explicit ReminderRequest(const ReminderRequest &other); + + /** + * @brief This constructor should only be used in background proxy service process + * when reminder instance recovery from database. + * + * @param reminderId Indicates reminder id. + */ + explicit ReminderRequest(int32_t reminderId); ReminderRequest& operator = (const ReminderRequest &other); virtual ~ReminderRequest() override {}; @@ -162,6 +173,7 @@ public: * @return Information of the reminder. */ std::string Dump() const; + // std::string DumpAll() const; /** * @brief Obtains the configured action buttons. @@ -256,6 +268,9 @@ public: */ uint64_t GetTriggerTimeInMilli() const; + int GetUserId() const; + int32_t GetUid() const; + /** * @brief Obtains want agent information. * @@ -269,6 +284,27 @@ public: */ void InitReminderId(); + /** + * @brief Inits reminder userId when publish reminder success. + * + * When package remove, user id is sended by wantAgent, but we cannot get the uid according user id as the + * package has been removed, and the bundleOption can not be create with correct uid. so we need to record + * the user id, and use it to judge which user the reminder belong to. + * + * @param userId Indicates the userId which the reminder belong to. + */ + void InitUserId(const int &userId); + + /** + * @brief Inites reminder uid when publish reminder success. + * + * When system reboot and recovery from database, we cannot get the uid according user id as BMS has not be + * ready. So we need to record the uid in order to create correct bundleOption. + * + * @param uid Indicates the uid which the reminder belong to. + */ + void InitUid(const int32_t &uid); + /** * @brief Check the reminder is alerting or not. * @@ -367,6 +403,14 @@ public: */ virtual bool OnTimeZoneChange(); + /** + * @brief Recovery reminder instance from database record. + * + * @param resultSet Indicates the resultSet with pointer to the row of record data. + */ + virtual void RecoveryFromDb(const std::shared_ptr &resultSet); + void RecoveryActionButton(const std::shared_ptr &resultSet); + /** * @brief Sets action button. * @@ -514,6 +558,8 @@ public: */ void UpdateNotificationRequest(UpdateNotificationType type, std::string extra); + static uint8_t GetConstStateInactive(); + static int32_t GLOBAL_ID; static const uint64_t INVALID_LONG_LONG_VALUE; static const uint16_t INVALID_U16_VALUE; @@ -549,8 +595,54 @@ public: static const std::string PARAM_REMINDER_ID; static int GetActualTime(const TimeTransferType &type, int cTime); static int GetCTime(const TimeTransferType &type, int actualTime); + static int32_t GetUid(const int &userId, const std::string &bundleName); + static int GetUserId(const int &uid); + static void AppendValuesBucket(const sptr &reminder, + const sptr &bundleOption, NativeRdb::ValuesBucket &values); + +class Instance { +public: + const static std::string REMINDER_ID; + const static std::string PKG_NAME; + const static std::string USER_ID; + const static std::string UID; + const static std::string APP_LABEL; + const static std::string REMINDER_TYPE; + const static std::string REMINDER_TIME; + const static std::string TRIGGER_TIME; + const static std::string RTC_TRIGGER_TIME; + const static std::string TIME_INTERVAL; + const static std::string SNOOZE_TIMES; + const static std::string DYNAMIC_SNOOZE_TIMES; + const static std::string RING_DURATION; + const static std::string IS_EXPIRED; + const static std::string IS_ACTIVE; + const static std::string STATE; + const static std::string ZONE_ID; + const static std::string HAS_SCHEDULED_TIMEOUT; + const static std::string ACTION_BUTTON_INFO; + const static std::string SLOT_ID; + const static std::string NOTIFICATION_ID; + const static std::string TITLE; + const static std::string CONTENT; + const static std::string SNOOZE_CONTENT; + const static std::string EXPIRED_CONTENT; + const static std::string AGENT; + const static std::string MAX_SCREEN_AGENT; + + static std::string SQL_ADD_COLUMNS; + static std::vector COLUMNS; + static void Init(); + +private: + static void AddColumn(const std::string &name, const std::string &type, const bool &isEnd); +}; protected: + enum class DbRecoveryType : uint8_t { + INT, + LONG + }; ReminderRequest(); explicit ReminderRequest(ReminderType reminderType); std::string GetDateTimeInfo(const time_t &timeInSecond) const; @@ -558,12 +650,21 @@ protected: { return INVALID_LONG_LONG_VALUE; } + int64_t RecoveryInt64FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType); + void RecoveryUint64FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint64_t &attribute); + void RecoveryUint32FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint32_t &attribute); + void RecoveryUint8FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint8_t &attribute); static const int BASE_YEAR; private: void AddActionButtons(const bool includeSnooze); void AddRemovalWantAgent(); std::shared_ptr CreateWantAgent(AppExecFwk::ElementName &element) const; + std::string GetButtonInfo() const; uint64_t GetNowInstantMilli() const; std::string GetShowTime(const uint64_t showTime) const; std::string GetTimeInfoInner(const time_t &timeInSecond, const TimeFormat &format) const; @@ -571,6 +672,7 @@ private: bool HandleSysTimeChange(uint64_t oriTriggerTime, uint64_t optTriggerTime); bool HandleTimeZoneChange(uint64_t oldZoneTriggerTime, uint64_t newZoneTriggerTime, uint64_t optTriggerTime); void InitNotificationRequest(); + void InitServerObj(); void SetMaxScreenWantAgent(AppExecFwk::ElementName &element); void SetState(bool deSet, const uint8_t newState, std::string function); void SetWantAgent(AppExecFwk::ElementName &element); @@ -599,6 +701,9 @@ private: static const uint8_t REMINDER_STATUS_SHOWING; static const uint8_t REMINDER_STATUS_SNOOZE; static const uint32_t MIN_TIME_INTERVAL_IN_MILLI; + static const std::string SEP_BUTTON_SINGLE; + static const std::string SEP_BUTTON_MULTI; + static const std::string SEP_WANT_AGENT; std::string content_ {}; std::string expiredContent_ {}; @@ -611,6 +716,8 @@ private: uint8_t state_ {0}; int32_t notificationId_ {0}; int32_t reminderId_ {-1}; + int userId_ {-1}; + int32_t uid_ {-1}; // Indicates the reminder has been shown in the past time. // When the reminder has been created but not showed, it is equals to 0. diff --git a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h index 07239f1ea3b9cb57afcee7db461a6fc0d04969cf..d0fd6f4dfe2e7288b37bee92bfa9750876b32aeb 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h @@ -40,6 +40,14 @@ public: */ ReminderRequestAlarm(uint8_t hour, uint8_t minute, std::vector daysOfWeek); + /** + * @brief This constructor should only be used in background proxy service process + * when reminder instance recovery from database. + * + * @param reminderId Indicates reminder id. + */ + ReminderRequestAlarm(int32_t reminderId) : ReminderRequest(reminderId) {}; + /** * @brief Copy construct from an exist reminder. * @@ -96,6 +104,23 @@ public: * @return true if read parcel success. */ bool ReadFromParcel(Parcel &parcel) override; + virtual void RecoveryFromDb(const std::shared_ptr &resultSet) override; + static void AppendValuesBucket(const sptr &reminder, + const sptr &bundleOption, NativeRdb::ValuesBucket &values); + +class Instance { +public: + const static std::string REPEAT_DAYS_OF_WEEK; + const static std::string ALARM_HOUR; + const static std::string ALARM_MINUTE; + + static std::string SQL_ADD_COLUMNS; + static std::vector COLUMNS; + static void Init(); + +private: + static void AddColumn(const std::string &name, const std::string &type, const bool &isEnd); +}; protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; diff --git a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h index 8c6868e98c0537ee2d2ac89ba2f591c153f84f63..5b90719a088c9cc9edf30a9fb21568467271c588 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h @@ -52,6 +52,14 @@ public: ReminderRequestCalendar(const tm &dateTime, const std::vector &repeatMonths, const std::vector &repeatDays); + /** + * @brief This constructor should only be used in background proxy service process + * when reminder instance recovery from database. + * + * @param reminderId Indicates reminder id. + */ + ReminderRequestCalendar(int32_t reminderId) : ReminderRequest(reminderId) {}; + explicit ReminderRequestCalendar(const ReminderRequestCalendar &other); ReminderRequestCalendar& operator = (const ReminderRequestCalendar &other); ~ReminderRequestCalendar() override {} @@ -133,6 +141,30 @@ public: static const uint8_t MAX_MONTHS_OF_YEAR; static const uint8_t MAX_DAYS_OF_MONTH; + virtual void RecoveryFromDb(const std::shared_ptr &resultSet) override; + static void AppendValuesBucket(const sptr &reminder, + const sptr &bundleOption, NativeRdb::ValuesBucket &values); + +class Instance { +public: + const static std::string REPEAT_DAYS; + const static std::string REPEAT_MONTHS; + const static std::string FIRST_DESIGNATE_YEAR; + const static std::string FIRST_DESIGNATE_MONTH; + const static std::string FIRST_DESIGNATE_DAY; + const static std::string CALENDAR_YEAR; + const static std::string CALENDAR_MONTH; + const static std::string CALENDAR_DAY; + const static std::string CALENDAR_HOUR; + const static std::string CALENDAR_MINUTE; + + static std::string SQL_ADD_COLUMNS; + static std::vector COLUMNS; + static void Init(); + +private: + static void AddColumn(const std::string &name, const std::string &type, const bool &isEnd); +}; protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; @@ -144,6 +176,12 @@ private: uint8_t GetNextDay(const uint16_t &settedYear, const uint8_t &settedMonth, const tm &now, const tm &target) const; uint64_t GetNextTriggerTime() const; uint64_t GetNextTriggerTimeAsRepeatReminder(const tm &nowTime, const tm &tarTime) const; + uint32_t GetRepeatDay() const { + return repeatDay_; + } + uint16_t GetRepeatMonth() const { + return repeatMonth_; + } uint64_t GetTimeInstantMilli( uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) const; diff --git a/interfaces/innerkits/ans/native/include/reminder_request_timer.h b/interfaces/innerkits/ans/native/include/reminder_request_timer.h index 9fc2362f2effe12f4758313624e55562c48318cd..46bf1a28cf4d895ef5c9a24c5a3efd8e46cba12c 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_timer.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_timer.h @@ -33,6 +33,14 @@ public: */ ReminderRequestTimer(uint64_t countDownTimeInSeconds); + /** + * @brief This constructor should only be used in background proxy service process + * when reminder instance recovery from database. + * + * @param reminderId Indicates reminder id. + */ + ReminderRequestTimer(int32_t reminderId) : ReminderRequest(reminderId) {}; + /** * @brief Copy construct from an exist reminder. * diff --git a/interfaces/innerkits/ans/native/include/reminder_store.h b/interfaces/innerkits/ans/native/include/reminder_store.h new file mode 100644 index 0000000000000000000000000000000000000000..72d7027816c0b48af65f8f2f516c20aa2884b278 --- /dev/null +++ b/interfaces/innerkits/ans/native/include/reminder_store.h @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_STORE_H +#define BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_STORE_H + +#include + +#include "notification_bundle_option.h" +#include "pixel_map.h" +#include "reminder_request.h" +#include "rdb_errno.h" +#include "rdb_helper.h" +#include "rdb_open_callback.h" +#include "rdb_store_config.h" + +namespace OHOS { +namespace Notification { +class ReminderStore { +public: + ReminderStore() {}; + virtual ~ReminderStore() {}; + int32_t Init(); + int32_t Delete(int32_t reminderId); + int32_t Delete(const std::string &pkg, int32_t userId); + int32_t DeleteUser(int32_t userId); + std::vector> GetAllValidReminders(); + bool GetBundleOption(const int32_t &reminderId, sptr &bundleOption) const; + int32_t GetMaxId(); + int64_t UpdateOrInsert(const sptr &reminder, const sptr &bundleOption); + /* std::string ConvertIconToString(std::shared_ptr &icon); + std::shared_ptr ConvertStringToIcon(const std::string &icon); */ + static std::vector GetRepeatInfo(int64_t repeatData, int32_t maxRepeatVal); + static uint8_t GetColumnIndex(const std::string& name); + static std::vector COLUMNS; + +private: + /** + * @brief Inits the data in database when system boot on or proxy process reboot on. + * + * 1. Deletes all the reminders which TRIGGER_TIME is less than now-30min. + * 2. Deletes all the reminders which IS_EXPIRED is true. + * 3. Sets all the value of STATE to ReminderRequest::REMINDER_STATUS_INACTIVE + * 4. Sets all the value of IS_ACTIVE to false. + * 5. Sets all the value of HAS_SCHEDULED_TIMEOUT to false. + * + * @return int32_t + */ + int32_t InitData(); + sptr BuildReminder(const std::shared_ptr &resultSet); + int32_t Delete(const std::string &deleteCondition); + int32_t DeleteRtcTime(int64_t rtcTime); + void GetInt32Val(std::shared_ptr &resultSet + , const std::string &name, int32_t &value) const; + void GetStringVal(std::shared_ptr &resultSet + , const std::string &name, std::string &value) const; + std::vector> GetReminders(const std::string &queryCondition); + void GenerateData(const sptr &remindert, + const sptr &bundleOption, NativeRdb::ValuesBucket &values) const; + bool IsReminderExist(const sptr &reminder); + int64_t Insert(const sptr &reminder, const sptr &bundleOption); + std::shared_ptr Query(const std::string &queryCondition) const; + int64_t Update(const sptr &reminder, const sptr &bundleOption); + +private: + static const std::string REMINDER_DB_DIR; + static const std::string REMINDER_DB_NAME; + static const uint32_t REMINDER_RDB_VERSION; + +private: + /* class IconHandler { + public: + std::string EncodeToBase64(const uint8_t *dst, const uint64_t &bufferSize); + uint8_t DecodeBase64(const std::string &base64, const uint32_t colorLength, uint32_t *dst); + std::vector IntToByte(int32_t num); + int32_t ByteToInt(const std::vector &bytes); + int32_t CompressString(const std::string &inputStr, std::string &outputStr); + int32_t DecompressString(const std::string &inputStr, std::string &outputStr); + inline bool IsBase64(const char character); + std::vector StringSplit(std::string source, std::string split = ","); + }; */ + +class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback { +public: + int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; + int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override; +}; + +private: + std::shared_ptr rdbStore_; + /* ReminderStore::IconHandler iconhandler_; */ +}; + +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_STORE_H \ No newline at end of file diff --git a/interfaces/innerkits/wantagent/include/want_agent_helper.h b/interfaces/innerkits/wantagent/include/want_agent_helper.h index 52ea8d9834df9aa417a20d5880035047c69f349c..2ead216db7ad9467e39c235500f7a54d0eab0eb7 100644 --- a/interfaces/innerkits/wantagent/include/want_agent_helper.h +++ b/interfaces/innerkits/wantagent/include/want_agent_helper.h @@ -67,7 +67,8 @@ public: * WantAgent object to create. * @return Returns the created WantAgent object. */ - static std::shared_ptr GetWantAgent(const WantAgentInfo ¶msInfo); + // static std::shared_ptr GetWantAgent(const WantAgentInfo ¶msInfo); + static std::shared_ptr GetWantAgent(const WantAgentInfo ¶msInfo, int32_t userId = -1); /** * Obtains an WantAgent object operation type. diff --git a/interfaces/kits/js/notification/notificationFlags.ts b/interfaces/kits/js/notification/notificationFlags.ts new file mode 100644 index 0000000000000000000000000000000000000000..58c4a68314afc35be19aed5e06956446a8bd9c8e --- /dev/null +++ b/interfaces/kits/js/notification/notificationFlags.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 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. + */ + +/** + * Describes a NotificationFlags instance. + * + * @name NotificationFlags + * @since 8 + * @devices phone, tablet, tv, wearable, car + * @permission N/A + * @sysCap SystemCapability.Notification.ANS + */ + export interface NotificationFlags { + /** + * Whether to enable sound reminder. + */ + readonly soundEnabled?: boolean; + + /** + * Whether to enable vibration reminder. + */ + readonly vibrationEnabled?: boolean; +} diff --git a/interfaces/kits/js/notification/notificationRequest.d.ts b/interfaces/kits/js/notification/notificationRequest.d.ts index 6525bf19ea3640ac643504b838db1111e35a4218..971ecb0c744167e6b9bd77deb0acd6b178627c7b 100644 --- a/interfaces/kits/js/notification/notificationRequest.d.ts +++ b/interfaces/kits/js/notification/notificationRequest.d.ts @@ -19,6 +19,7 @@ import { WantAgent } from '../@ohos.wantAgent'; import { NotificationContent } from './notificationContent'; import { NotificationActionButton } from './notificationActionButton'; import { NotificationTemplate } from './notificationTemplate'; +import { NotificationFlags } from './notificationFlags'; /** * Defines a NotificationRequest instance. @@ -197,4 +198,11 @@ export interface NotificationRequest { * @since 8 */ template?: NotificationTemplate; + + /** + * Obtains the set of identifiers for the notification. + * + * @since 8 + */ + readonly notificationFlags?: NotificationFlags; } diff --git a/interfaces/kits/napi/ans/BUILD.gn b/interfaces/kits/napi/ans/BUILD.gn index 97c13373e4d945684cc5b863222e593674f4bc1c..9fca9676a282daa1ca1737c915de888c78263669 100644 --- a/interfaces/kits/napi/ans/BUILD.gn +++ b/interfaces/kits/napi/ans/BUILD.gn @@ -78,11 +78,12 @@ ohos_shared_library("notification") { "ability_runtime:abilitykit_native", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", + "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "napi:ace_napi", + "native_appdatamgr:native_rdb", ] relative_install_dir = "module" diff --git a/interfaces/kits/napi/ans/include/common.h b/interfaces/kits/napi/ans/include/common.h index f77e712a0739059ea6506b38e9943992c1cba99e..ba4cd1aadaee35e5170f873578c06b42e05a6729 100644 --- a/interfaces/kits/napi/ans/include/common.h +++ b/interfaces/kits/napi/ans/include/common.h @@ -429,6 +429,9 @@ public: static napi_value SetNotificationTemplateInfo( const napi_env &env, const std::shared_ptr &templ, napi_value &result); + static napi_value SetNotificationFlags( + const napi_env &env, const std::shared_ptr &flags, napi_value &result); + private: static const int ARGS_ONE = 1; static const int ARGS_TWO = 2; diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 2097b51d3ebeb6bc36fa9c5dca059ba1179810c9..d8d8a57c1d1a8d72acd31f6dde6eca60df13a5bb 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -548,7 +548,7 @@ napi_value Common::SetNotificationRequestByCustom( } napi_set_named_property(env, result, "actionButtons", arr); - // template?: NotificationTemplate; + // template?: NotificationTemplate std::shared_ptr templ = request->GetTemplate(); if (templ) { napi_value templateResult = nullptr; @@ -560,6 +560,18 @@ napi_value Common::SetNotificationRequestByCustom( napi_set_named_property(env, result, "template", templateResult); } + // readonly notificationFlags?: NotificationFlags + std::shared_ptr flags = request->GetFlags(); + if (flags) { + napi_value flagsResult = nullptr; + napi_create_object(env, &flagsResult); + if (!SetNotificationFlags(env, flags, flagsResult)) { + ANS_LOGE("SetNotificationFlags call failed"); + return NapiGetBoolean(env, false); + } + napi_set_named_property(env, result, "notificationFlags", flagsResult); + } + return NapiGetBoolean(env, true); } @@ -2593,29 +2605,33 @@ napi_value Common::GetNotificationSupportDisplayDevices( ANS_LOGI("enter"); bool isArray = false; + bool hasProperty = false; napi_valuetype valuetype = napi_undefined; napi_value supportDisplayDevices = nullptr; char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; uint32_t length = 0; - napi_get_named_property(env, value, "supportDisplayDevices", &supportDisplayDevices); - napi_is_array(env, supportDisplayDevices, &isArray); - NAPI_ASSERT(env, isArray, "Property supportDisplayDevices is expected to be an array."); + NAPI_CALL(env, napi_has_named_property(env, value, "supportDisplayDevices", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "supportDisplayDevices", &supportDisplayDevices); + napi_is_array(env, supportDisplayDevices, &isArray); + NAPI_ASSERT(env, isArray, "Property supportDisplayDevices is expected to be an array."); - napi_get_array_length(env, supportDisplayDevices, &length); - NAPI_ASSERT(env, length > 0, "The array is empty."); - std::vector devices; - for (size_t i = 0; i < length; i++) { - napi_value line = nullptr; - napi_get_element(env, supportDisplayDevices, i, &line); - NAPI_CALL(env, napi_typeof(env, line, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, line, str, STR_MAX_SIZE - 1, &strLen)); - devices.emplace_back(str); - ANS_LOGI("supportDisplayDevices = %{public}s", str); + napi_get_array_length(env, supportDisplayDevices, &length); + NAPI_ASSERT(env, length > 0, "The array is empty."); + std::vector devices; + for (size_t i = 0; i < length; i++) { + napi_value line = nullptr; + napi_get_element(env, supportDisplayDevices, i, &line); + NAPI_CALL(env, napi_typeof(env, line, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, line, str, STR_MAX_SIZE - 1, &strLen)); + devices.emplace_back(str); + ANS_LOGI("supportDisplayDevices = %{public}s", str); + } + request.SetDevicesSupportDisplay(devices); } - request.SetDevicesSupportDisplay(devices); return NapiGetNull(env); } @@ -2625,29 +2641,33 @@ napi_value Common::GetNotificationSupportOperateDevices( ANS_LOGI("enter"); bool isArray = false; + bool hasProperty = false; napi_valuetype valuetype = napi_undefined; napi_value supportOperateDevices = nullptr; char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; uint32_t length = 0; - napi_get_named_property(env, value, "supportOperateDevices", &supportOperateDevices); - napi_is_array(env, supportOperateDevices, &isArray); - NAPI_ASSERT(env, isArray, "Property supportOperateDevices is expected to be an array."); + NAPI_CALL(env, napi_has_named_property(env, value, "supportOperateDevices", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "supportOperateDevices", &supportOperateDevices); + napi_is_array(env, supportOperateDevices, &isArray); + NAPI_ASSERT(env, isArray, "Property supportOperateDevices is expected to be an array."); - napi_get_array_length(env, supportOperateDevices, &length); - NAPI_ASSERT(env, length > 0, "The array is empty."); - std::vector devices; - for (size_t i = 0; i < length; i++) { - napi_value line = nullptr; - napi_get_element(env, supportOperateDevices, i, &line); - NAPI_CALL(env, napi_typeof(env, line, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, line, str, STR_MAX_SIZE - 1, &strLen)); - devices.emplace_back(str); - ANS_LOGI("supportOperateDevices = %{public}s", str); + napi_get_array_length(env, supportOperateDevices, &length); + NAPI_ASSERT(env, length > 0, "The array is empty."); + std::vector devices; + for (size_t i = 0; i < length; i++) { + napi_value line = nullptr; + napi_get_element(env, supportOperateDevices, i, &line); + NAPI_CALL(env, napi_typeof(env, line, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, line, str, STR_MAX_SIZE - 1, &strLen)); + devices.emplace_back(str); + ANS_LOGI("supportOperateDevices = %{public}s", str); + } + request.SetDevicesSupportOperate(devices); } - request.SetDevicesSupportOperate(devices); return NapiGetNull(env); } @@ -3613,10 +3633,16 @@ napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, size_t strLen = 0; // bundle: string NAPI_CALL(env, napi_has_named_property(env, value, "bundle", &hasProperty)); - NAPI_ASSERT(env, hasProperty, "Property bundle expected."); + if (!hasProperty) { + ANS_LOGE("Property bundle expected."); + return nullptr; + } napi_get_named_property(env, value, "bundle", &result); NAPI_CALL(env, napi_typeof(env, result, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + if (valuetype != napi_string) { + ANS_LOGE("Wrong argument type. String expected."); + return nullptr; + } NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); option.SetBundleName(str); @@ -3626,7 +3652,10 @@ napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, int32_t uid = 0; napi_get_named_property(env, value, "uid", &result); NAPI_CALL(env, napi_typeof(env, result, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } napi_get_value_int32(env, result, &uid); option.SetUid(uid); } @@ -4074,5 +4103,28 @@ napi_value Common::SetNotificationTemplateInfo( return NapiGetBoolean(env, true); } + +napi_value Common::SetNotificationFlags( + const napi_env &env, const std::shared_ptr &flags, napi_value &result) +{ + ANS_LOGI("enter"); + + if (flags == nullptr) { + ANS_LOGE("flags is null"); + return NapiGetBoolean(env, false); + } + + napi_value value = nullptr; + + // readonly soundEnabled?: boolean + napi_get_boolean(env, flags->IsSoundEnabled(), &value); + napi_set_named_property(env, result, "soundEnabled", value); + + // readonly vibrationEnabled?: boolean + napi_get_boolean(env, flags->IsVibrationEnabled(), &value); + napi_set_named_property(env, result, "vibrationEnabled", value); + + return NapiGetBoolean(env, true); +} } // namespace NotificationNapi -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/napi/ans/src/display_badge.cpp b/interfaces/kits/napi/ans/src/display_badge.cpp index 3484b24e96db82e73b3525b078b89f5719060ca0..71da17f3c3aad294f2411dd205a199a68d9c3a08 100644 --- a/interfaces/kits/napi/ans/src/display_badge.cpp +++ b/interfaces/kits/napi/ans/src/display_badge.cpp @@ -57,12 +57,19 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_value argv[ENABLE_BADGE_DISPLAYED_MAX_PARA] = {nullptr}; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - NAPI_ASSERT(env, argc >= ENABLE_BADGE_DISPLAYED_MIN_PARA, "Wrong number of arguments"); + if (argc < ENABLE_BADGE_DISPLAYED_MIN_PARA) { + ANS_LOGW("Wrong number of arguments."); + return nullptr; + } // argv[0]: bundle napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + if (valuetype != napi_object) { + ANS_LOGW("Wrong argument type. Object expected."); + return nullptr; + } + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); @@ -71,13 +78,19 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[1]: enable NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); + if (valuetype != napi_boolean) { + ANS_LOGW("Wrong argument type. Bool expected."); + return nullptr; + } napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); // argv[2]:callback if (argc >= ENABLE_BADGE_DISPLAYED_MAX_PARA) { NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + if (valuetype != napi_function) { + ANS_LOGW("Wrong argument type. Function expected."); + return nullptr; + } napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); } @@ -92,14 +105,21 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_value argv[IS_DISPLAY_BADGE_MAX_PARA] = {nullptr}; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - NAPI_ASSERT(env, argc >= IS_DISPLAY_BADGE_MIN_PARA, "Wrong number of arguments"); + + if (argc < IS_DISPLAY_BADGE_MIN_PARA) { + ANS_LOGW("Wrong number of arguments."); + return nullptr; + } // argv[0]: bundle / callback napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); - NAPI_ASSERT(env, - (valuetype == napi_function) || (valuetype == napi_object), - "Wrong argument type. Function or object expected."); + + if ((valuetype != napi_function) && (valuetype != napi_object)) { + ANS_LOGW("Wrong argument type. Function or object expected, %{public}d", valuetype); + return nullptr; + } + if (valuetype == napi_object) { auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { @@ -114,7 +134,10 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[1]:callback if (argc >= IS_DISPLAY_BADGE_MAX_PARA) { NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + if (valuetype != napi_function) { + ANS_LOGW("Wrong argument type. Function expected."); + return nullptr; + } napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } @@ -213,6 +236,7 @@ napi_value IsBadgeDisplayed(napi_env env, napi_callback_info info) IsDisplayBadgeParams params {}; if (ParseParameters(env, info, params) == nullptr) { + ANS_LOGE("Failed to parse params!"); return Common::NapiGetUndefined(env); } diff --git a/interfaces/kits/napi/ans/src/enable_notification.cpp b/interfaces/kits/napi/ans/src/enable_notification.cpp index 7850a4f8dcad6ef12d04fbc0422c7d6e35be7ea1..c9b896d17d66f963641ff3bc41cc5b15e799f64d 100644 --- a/interfaces/kits/napi/ans/src/enable_notification.cpp +++ b/interfaces/kits/napi/ans/src/enable_notification.cpp @@ -56,12 +56,18 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_value argv[ENABLE_NOTIFICATION_MAX_PARA] = {nullptr}; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - NAPI_ASSERT(env, argc >= ENABLE_NOTIFICATION_MIN_PARA, "Wrong number of arguments"); + if (argc < ENABLE_NOTIFICATION_MIN_PARA) { + ANS_LOGW("Wrong number of arguments."); + return nullptr; + } // argv[0]: bundle napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + if (valuetype != napi_object) { + ANS_LOGW("Wrong argument type. Object expected."); + return nullptr; + } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); @@ -70,13 +76,19 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[1]: enable NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); + if (valuetype != napi_boolean) { + ANS_LOGW("Wrong argument type. Bool expected."); + return nullptr; + } napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); // argv[2]:callback if (argc >= ENABLE_NOTIFICATION_MAX_PARA) { NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + if (valuetype != napi_function) { + ANS_LOGW("Wrong argument type. Function expected."); + return nullptr; + } napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); } @@ -99,9 +111,10 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[0]: bundle / callback napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); - NAPI_ASSERT(env, - (valuetype == napi_function) || (valuetype == napi_object), - "Wrong argument type. Function or object expected."); + if ((valuetype != napi_function) && (valuetype != napi_object)) { + ANS_LOGW("Wrong argument type. Function or object expected."); + return nullptr; + } if (valuetype == napi_object) { auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { @@ -116,7 +129,10 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[1]:callback if (argc >= IS_NOTIFICATION_ENABLE_MAX_PARA) { NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + if (valuetype != napi_function) { + ANS_LOGW("Wrong argument type. Function expected."); + return nullptr; + } napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } diff --git a/interfaces/kits/napi/ans/src/reminder/BUILD.gn b/interfaces/kits/napi/ans/src/reminder/BUILD.gn index b51f48bb29a0fde0e51d5de62b62364121ebe8fe..33b24f00216def0690952997374891964fd648ad 100644 --- a/interfaces/kits/napi/ans/src/reminder/BUILD.gn +++ b/interfaces/kits/napi/ans/src/reminder/BUILD.gn @@ -66,11 +66,12 @@ ohos_shared_library("reminderagent") { external_deps = [ "ability_runtime:abilitykit_native", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", + "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "napi:ace_napi", + "native_appdatamgr:native_rdb", ] relative_install_dir = "module" diff --git a/interfaces/kits/napi/wantagent/BUILD.gn b/interfaces/kits/napi/wantagent/BUILD.gn index c8671f52df2fba25ffa1c01f517e49830fb01c79..666c747cafc29d82aa40cd1d8e6b349902f49414 100644 --- a/interfaces/kits/napi/wantagent/BUILD.gn +++ b/interfaces/kits/napi/wantagent/BUILD.gn @@ -45,9 +45,9 @@ ohos_shared_library("wantagent") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "napi:ace_napi", diff --git a/notification.gni b/notification.gni index 9901863fe7194cc18511bc1ca2bd24a3ee50d9e9..d51ab2aa0d7d5dca4d51455b18b35d4768d078ca 100644 --- a/notification.gni +++ b/notification.gni @@ -32,13 +32,14 @@ aafwk_path = "//foundation/aafwk/standard" ans_standard_external_deps = [ "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "native_appdatamgr:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/services/ans/include/advanced_notification_service_ability.h b/services/ans/include/advanced_notification_service_ability.h index ec5c866d8169672394e40ff6507a2da72a8a1df4..5ebdf2f02de0a95013f0b56de48c57cdef236a2c 100644 --- a/services/ans/include/advanced_notification_service_ability.h +++ b/services/ans/include/advanced_notification_service_ability.h @@ -20,6 +20,7 @@ #include "advanced_notification_service.h" #include "system_ability_definition.h" +#include "reminder_data_manager.h" namespace OHOS { namespace Notification { @@ -36,6 +37,7 @@ private: private: sptr service_; + std::shared_ptr reminderAgent_; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index c1167f1bae653e2bd515541d724a8a7a20534df0..619c63d30c73657636aed086491ae203739faa9a 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -21,7 +21,9 @@ #include "advanced_notification_service.h" #include "player.h" +#include "reminder_const.h" #include "reminder_request.h" +#include "reminder_store.h" #include "reminder_timer_info.h" namespace OHOS { @@ -36,8 +38,11 @@ public: /** * @brief Cancels all the reminders relative to the bundle option. + * + * @param bundleOption Indicates the bundle option. + * @param userId Indicates the user id which the bundle belong to. */ - void CancelAllReminders(const sptr &bundleOption); + void CancelAllReminders(const sptr &bundleOption, int userId); /** * @brief Cancels the target reminder relative to the reminder id and bundle option. @@ -79,6 +84,13 @@ public: void GetValidReminders( const sptr bundleOption, std::vector> &reminders); + /** + * @brief Inits and recovery data from database. + * + * @param isFromBootComplete Indicates the init is called when boot completed. + */ + void Init(bool isFromBootComplete); + /** * @brief Triggered when third party application died. * @@ -251,6 +263,8 @@ private: bool HandleSysTimeChange(const sptr reminder) const; + bool IsReminderAgentReady() const; + /** * Judge the two reminders is belong to the same application or not. * @@ -262,6 +276,8 @@ private: bool IsBelongToSameApp( const sptr reminder, const std::string otherPkgName, const int otherUserId); + void LoadReminderFromDb(); + void PlaySoundAndVibrationLocked(const sptr &reminder); void PlaySoundAndVibration(const sptr &reminder); void StopSoundAndVibrationLocked(const sptr &reminder); @@ -399,6 +415,8 @@ private: */ static const int16_t MAX_NUM_REMINDER_LIMIT_APP; + bool isReminderAgentReady_ = false; + /** * Vector used to record all the reminders in system. */ @@ -441,8 +459,9 @@ private: /** * Indicates the total count of reminders in system. */ - int16_t totalCount_ {0}; + int16_t totalCount_ {0}; // todo recovery from db AdvancedNotificationService *advancedNotificationService_; + std::shared_ptr store_ = nullptr; }; } // namespace OHOS } // namespace Nofitifcation diff --git a/services/ans/include/reminder_event_manager.h b/services/ans/include/reminder_event_manager.h index 09c908f496c74cf9c9047e326fea8acf31cca3a0..35f46ba0ec2d26137aba6d19eed2ae3078bdbd8e 100644 --- a/services/ans/include/reminder_event_manager.h +++ b/services/ans/include/reminder_event_manager.h @@ -43,7 +43,6 @@ private: sptr GetBundleOption(const OHOS::EventFwk::Want &want) const; void HandlePackageRemove(OHOS::EventFwk::Want &want) const; void HandleProcessDied(OHOS::EventFwk::Want &want) const; - int32_t GetUid(const int userId, const std::string bundleName) const; std::shared_ptr reminderDataManager_ = nullptr; }; }; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 61f7b0daa006893c0b7c5d08006d13f96593d62c..ace0c7587719823b389b9d93fa23b75799ea6531 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -46,17 +46,18 @@ namespace OHOS { namespace Notification { namespace { -static const std::string ACTIVE_NOTIFICATION_OPTION = "active"; -static const std::string RECENT_NOTIFICATION_OPTION = "recent"; +constexpr char ACTIVE_NOTIFICATION_OPTION[] = "active"; +constexpr char RECENT_NOTIFICATION_OPTION[] = "recent"; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED -static const std::string DISTRIBUTED_NOTIFICATION_OPTION = "distributed"; +constexpr char DISTRIBUTED_NOTIFICATION_OPTION[] = "distributed"; #endif -static const std::string SET_RECENT_COUNT_OPTION = "setRecentCount"; +constexpr char SET_RECENT_COUNT_OPTION[] = "setRecentCount"; +constexpr char FOUNDATION_BUNDLE_NAME[] = "ohos.global.systemres"; -static const int32_t NOTIFICATION_MIN_COUNT = 0; -static const int32_t NOTIFICATION_MAX_COUNT = 1024; +constexpr int32_t NOTIFICATION_MIN_COUNT = 0; +constexpr int32_t NOTIFICATION_MAX_COUNT = 1024; -static const int32_t DEFAULT_RECENT_COUNT = 16; +constexpr int32_t DEFAULT_RECENT_COUNT = 16; constexpr int HOURS_IN_ONE_DAY = 24; @@ -100,6 +101,9 @@ inline bool IsSystemApp() bool isSystemApp = false; int callingUid = IPCSkeleton::GetCallingUid(); + ANSR_LOGD("~~~~callingUid=%{public}d", callingUid); + std::string bundleName = GetClientBundleName(); + ANSR_LOGD("~~~~bundleName=%{public}s", bundleName.c_str()); std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); if (bundleManager != nullptr) { @@ -170,7 +174,7 @@ ErrCode PrepereNotificationRequest(const sptr &request) int pid = IPCSkeleton::GetCallingPid(); request->SetCreatorUid(uid); request->SetCreatorPid(pid); - + int userId = SUBSCRIBE_USER_INIT; OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); if (userId >= SUBSCRIBE_USER_SYSTEM_BEGIN && userId <= SUBSCRIBE_USER_SYSTEM_END) { @@ -296,17 +300,22 @@ ErrCode AdvancedNotificationService::CancelPreparedNotification( int notificationId, const std::string &label, const sptr &bundleOption) { if (bundleOption == nullptr) { + ANSR_LOGD("~~~~1"); return ERR_ANS_INVALID_BUNDLE; } + ANSR_LOGD("~~~~2"); ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { sptr notification = nullptr; result = RemoveFromNotificationList(bundleOption, label, notificationId, notification, true); if (result != ERR_OK) { + ANSR_LOGD("~~~~3"); return; } + ANSR_LOGD("~~~~4"); if (notification != nullptr) { + ANSR_LOGD("~~~~5"); int reason = NotificationConstant::APP_CANCEL_REASON_DELETE; UpdateRecentNotification(notification, true, reason); sptr sortingMap = GenerateSortingMap(); @@ -417,6 +426,7 @@ ErrCode AdvancedNotificationService::Filter(const std::shared_ptr &record) { + ANSR_LOGD("~~~~push_back, notificationId=%{public}d", record->notification->GetId()); notificationList_.push_back(record); SortNotificationList(); } @@ -1106,10 +1116,15 @@ ErrCode AdvancedNotificationService::GetShowBadgeEnabled(bool &enabled) ErrCode AdvancedNotificationService::RemoveFromNotificationList(const sptr &bundleOption, const std::string &label, int notificationId, sptr ¬ification, bool isCancel) { + ANSR_LOGD("~~~~%{public}s, %{public}d, %{public}s, %{public}d" + , bundleOption->GetBundleName().c_str(), bundleOption->GetUid(), label.c_str(), notificationId); + for (auto record : notificationList_) { if (!record->notification->IsRemoveAllowed()) { + ANSR_LOGD("~~~~3.1"); continue; } + ANSR_LOGD("~~~~3.11"); if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && (record->bundleOption->GetUid() == bundleOption->GetUid()) && (record->notification->GetLabel() == label) && @@ -1118,19 +1133,24 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList(const sptrdeviceId.empty() #endif ) { + ANSR_LOGD("~~~~3.2"); if (!isCancel && record->request->IsUnremovable()) { + ANSR_LOGD("~~~~3.3"); return ERR_ANS_NOTIFICATION_IS_UNREMOVABLE; } notification = record->notification; // delete or delete all, call the function if (!isCancel) { + ANSR_LOGD("~~~~3.4"); TriggerRemoveWantAgent(record->request); } + ANSR_LOGD("~~~~3.5"); notificationList_.remove(record); return ERR_OK; } } + ANSR_LOGD("~~~~3.6"); return ERR_ANS_NOTIFICATION_NOT_EXISTS; } @@ -1146,6 +1166,10 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList( return ERR_ANS_NOTIFICATION_IS_UNREMOVABLE; } notification = record->notification; + // delete or delete all, call the function + if (!isCancel) { + TriggerRemoveWantAgent(record->request); + } notificationList_.remove(record); return ERR_OK; } @@ -1486,6 +1510,14 @@ ErrCode AdvancedNotificationService::PublishContinuousTaskNotification(const spt return ERR_ANS_NOT_SYSTEM_SERVICE; } + if (request->GetCreatorBundleName().empty()) { + request->SetCreatorBundleName(FOUNDATION_BUNDLE_NAME); + } + + if (request->GetOwnerBundleName().empty()) { + request->SetOwnerBundleName(FOUNDATION_BUNDLE_NAME); + } + sptr bundleOption = nullptr; bundleOption = new NotificationBundleOption(std::string(), uid); if (bundleOption == nullptr) { @@ -1559,7 +1591,6 @@ ErrCode AdvancedNotificationService::CancelContinuousTaskNotification(const std: ErrCode AdvancedNotificationService::PublishReminder(sptr &reminder) { ANSR_LOGI("Publish reminder"); - ReminderDataManager::GetInstance()->SetService(this); sptr notificationRequest = reminder->GetNotificationRequest(); sptr bundleOption = nullptr; ErrCode result = PrepareNotificationInfo(notificationRequest, bundleOption); @@ -1574,7 +1605,6 @@ ErrCode AdvancedNotificationService::PublishReminder(sptr &remi ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) { ANSR_LOGI("Cancel Reminder"); - ReminderDataManager::GetInstance()->SetService(this); sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -1586,19 +1616,19 @@ ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) ErrCode AdvancedNotificationService::CancelAllReminders() { ANSR_LOGI("Cancel all reminders"); - ReminderDataManager::GetInstance()->SetService(this); sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; } - ReminderDataManager::GetInstance()->CancelAllReminders(bundleOption); + int userId = -1; + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); + ReminderDataManager::GetInstance()->CancelAllReminders(bundleOption, userId); return ERR_OK; } ErrCode AdvancedNotificationService::GetValidReminders(std::vector> &reminders) { ANSR_LOGI("GetValidReminders"); - ReminderDataManager::GetInstance()->SetService(this); reminders.clear(); sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { @@ -2294,7 +2324,7 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDate(const sptrPostSyncTask(std::bind([&]() { result = NotificationPreferences::GetInstance().SetDoNotDisturbDate(bundleOption, newConfig); if (result == ERR_OK) { @@ -2367,6 +2397,9 @@ ErrCode AdvancedNotificationService::DoesSupportDoNotDisturbMode(bool &doesSuppo bool AdvancedNotificationService::CheckPermission(const std::string &bundleName) { ANS_LOGD("%{public}s", __FUNCTION__); + if (IPCSkeleton::GetCallingUid() == SYSTEM_SERVICE_UID) { + return true; + } if (bundleName.empty()) { ANS_LOGE("Bundle name is empty."); return false; diff --git a/services/ans/src/advanced_notification_service_ability.cpp b/services/ans/src/advanced_notification_service_ability.cpp index 56f052fb8b4cf0c10e32d58b47c6ebed42223f8d..379fc8bf348bddfdd1fb1c584a294a295ef088e7 100644 --- a/services/ans/src/advanced_notification_service_ability.cpp +++ b/services/ans/src/advanced_notification_service_ability.cpp @@ -30,6 +30,7 @@ AdvancedNotificationServiceAbility::~AdvancedNotificationServiceAbility() void AdvancedNotificationServiceAbility::OnStart() { + ANSR_LOGD("~~~~Service init"); if (service_ != nullptr) { return; } @@ -38,11 +39,15 @@ void AdvancedNotificationServiceAbility::OnStart() if (!Publish(service_)) { return; } + ANSR_LOGD("~~~~Service init 1"); + reminderAgent_ = ReminderDataManager::GetInstance(); + reminderAgent_->SetService(static_cast(service_.GetRefPtr())); } void AdvancedNotificationServiceAbility::OnStop() { service_ = nullptr; + reminderAgent_ = nullptr; } } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 18f09d8b6cf6f212a9dbc8c946d9a5a72b52838c..8dd3880e4c1ae7894d3e26d5b3ddba30d93a2ccf 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -54,6 +54,7 @@ void ReminderDataManager::CancelReminder( } if (activeReminderId_ == reminderId) { ANSR_LOGD("Cancel active reminder, id=%{public}d", reminderId); + activeReminder_->OnStop(); StopTimerLocked(TimerType::TRIGGER_TIMER); } if (alertingReminderId_ == reminderId) { @@ -87,6 +88,9 @@ void ReminderDataManager::CancelNotification(const sptr &remind notification->GetNotificationId(), ReminderRequest::NOTIFICATION_LABEL, bundleOption); } +// todo CancelReminder(const sptr &bundleOption, int userId) +// todo CancelReminder(int userId) + bool ReminderDataManager::CheckReminderLimitExceededLocked(const std::string &bundleName) const { std::lock_guard lock(ReminderDataManager::MUTEX); @@ -117,15 +121,15 @@ bool ReminderDataManager::CheckReminderLimitExceededLocked(const std::string &bu return false; } -void ReminderDataManager::CancelAllReminders(const sptr &bundleOption) +void ReminderDataManager::CancelAllReminders(const sptr &bundleOption, int userId) { MUTEX.lock(); auto it = notificationBundleOptionMap_.find(activeReminderId_); - if (it == notificationBundleOptionMap_.end()) { - ANSR_LOGW("Not get bundle option, reminderId=%{public}d", activeReminderId_); - } else { + if (it != notificationBundleOptionMap_.end()) { if (it->second->GetBundleName() == bundleOption->GetBundleName()) { + activeReminder_->OnStop(); StopTimer(TimerType::TRIGGER_TIMER); + ANSR_LOGD("Stop active reminder, reminderId=%{public}d", activeReminderId_); } } for (auto vit = reminderVector_.begin(); vit != reminderVector_.end();) { @@ -137,10 +141,12 @@ void ReminderDataManager::CancelAllReminders(const sptrsecond->GetBundleName() == bundleOption->GetBundleName()) { + ANSR_LOGD("currently, userId is not supported. userId=%{public}d", userId); if ((*vit)->IsAlerting()) { StopAlertingReminder(*vit); } CancelNotification(*vit); + RemoveFromShowedReminders(*vit); ANSR_LOGD("Containers(vector/map) remove. reminderId=%{public}d", reminderId); vit = reminderVector_.erase(vit); notificationBundleOptionMap_.erase(mit); @@ -196,7 +202,11 @@ void ReminderDataManager::OnProcessDiedLocked(const sptrGetReminderId(); auto mit = notificationBundleOptionMap_.find(reminderId); if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGE("Get bundle option occur error, reminderId=%{public}d", reminderId); + ANSR_LOGD( + "Not get bundle option, the reminder may has been cancelled, reminderId=%{public}d", reminderId); + CancelNotification(*it); + showedReminderVector_.erase(it); + --it; continue; } if (mit->second->GetBundleName() != bundleName || mit->second->GetUid() != uid) { @@ -211,6 +221,7 @@ void ReminderDataManager::OnProcessDiedLocked(const sptrUpdateOrInsert } } @@ -237,7 +248,7 @@ std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerTyp return sharedTimerInfo; } want->SetAction(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); - want->SetParam(ReminderRequest::PARAM_REMINDER_ID, alertingReminderId_); + want->SetParam(ReminderRequest::PARAM_REMINDER_ID, alertingReminderId_); // todo no need break; } default: @@ -321,6 +332,7 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b int32_t reminderId = reminder->GetReminderId(); if (activeReminderId_ == reminderId) { ANSR_LOGD("Stop active reminder due to CloseReminder"); + activeReminder_->OnStop(); StopTimerLocked(TimerType::TRIGGER_TIMER); } if (alertingReminderId_ == reminderId) { @@ -329,17 +341,24 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b } reminder->OnClose(true); RemoveFromShowedReminders(reminder); + // todo store_->UpdateOrInsert if (cancelNotification) { CancelNotification(reminder); } StartRecentReminder(); } +// todo OnSwitchUser() +// todo OnRemoveUser() +// todo OnInterruptChange() + std::shared_ptr ReminderDataManager::GetInstance() { if (REMINDER_DATA_MANAGER == nullptr) { + ANSR_LOGD("~~~~GetInstance init"); REMINDER_DATA_MANAGER = std::make_shared(); ReminderEventManager reminderEventManager(REMINDER_DATA_MANAGER); + REMINDER_DATA_MANAGER->Init(false); } return REMINDER_DATA_MANAGER; } @@ -350,6 +369,7 @@ void ReminderDataManager::RefreshRemindersDueToSysTimeChange(uint8_t type) ANSR_LOGI("Refresh all reminders due to %{public}s changed by user", typeInfo.c_str()); if (activeReminderId_ != -1) { ANSR_LOGD("Stop active reminder due to date/time or timeZone change"); + activeReminder_->OnStop(); StopTimerLocked(TimerType::TRIGGER_TIMER); } std::vector> showImmediately = RefreshRemindersLocked(type); @@ -399,7 +419,10 @@ void ReminderDataManager::TerminateAlerting(const sptr &reminde } ANSR_LOGD("publish(update) notification.(reminderId=%{public}d)", reminder->GetReminderId()); UpdateNotification(reminder); + ANSR_LOGD("~~~~~~~~~~~~~~~~content=%{public}s" + , notificationRequest->GetContent()->GetNotificationContent()->GetText().c_str()); advancedNotificationService_->PublishPreparedNotification(notificationRequest, bundleOption); + // todo store_->UpdateOrInsert } void ReminderDataManager::UpdateAndSaveReminderLocked( @@ -407,6 +430,8 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( { std::lock_guard lock(ReminderDataManager::MUTEX); reminder->InitReminderId(); + reminder->InitUserId(ReminderRequest::GetUserId(bundleOption->GetUid())); + reminder->InitUid(bundleOption->GetUid()); int32_t reminderId = reminder->GetReminderId(); ANSR_LOGD("Containers(map) add. reminderId=%{public}d", reminderId); auto ret = notificationBundleOptionMap_.insert( @@ -418,6 +443,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( ANSR_LOGD("Containers(vector) add. reminderId=%{public}d", reminderId); reminderVector_.push_back(reminder); totalCount_++; + store_->UpdateOrInsert(reminder, bundleOption); } void ReminderDataManager::SetService(AdvancedNotificationService *advancedNotificationService) @@ -486,7 +512,7 @@ void ReminderDataManager::ShowActiveReminderExtendLocked(sptr & if ((*it)->GetTriggerTimeInMilli() - triggerTime > ReminderRequest::SAME_TIME_DISTINGUISH_MILLISECONDS) { continue; } - if (!isAlerting) { + if (!isAlerting) { // todo isSoundOrVibratorDefined playSoundReminder = (*it); isAlerting = true; } else { @@ -503,6 +529,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co { ANSR_LOGD("Show the reminder(Play sound: %{public}d), %{public}s", static_cast(isNeedToPlaySound), reminder->Dump().c_str()); + // todo if (IsNotificationEnable(rem)) int32_t reminderId = reminder->GetReminderId(); sptr bundleOption = FindNotificationBundleOption(reminderId); sptr notificationRequest = reminder->GetNotificationRequest(); @@ -537,6 +564,8 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co } else { HandleSameNotificationIdShowing(reminder); } + // todo store_->UpdateOrInsert + if (isNeedToStartNext) { StartRecentReminder(); } @@ -567,6 +596,7 @@ void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) int32_t reminderId = reminder->GetReminderId(); if (activeReminderId_ == reminderId) { ANSR_LOGD("Cancel active reminder, id=%{public}d", activeReminderId_); + activeReminder_->OnStop(); StopTimerLocked(TimerType::TRIGGER_TIMER); } @@ -576,6 +606,7 @@ void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) StopSoundAndVibrationLocked(reminder); } reminder->OnSnooze(); + // todo store_->UpdateOrInsert // 2) Show the notification dialog in the systemUI sptr bundleOption = FindNotificationBundleOption(reminderId); @@ -605,13 +636,23 @@ void ReminderDataManager::StartRecentReminder() return; } if (activeReminderId_ != -1) { - StopTimerLocked(TimerType::TRIGGER_TIMER); activeReminder_->OnStop(); - } - ANSR_LOGI("Start recent reminder"); - StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); - reminder->OnStart(); - SetActiveReminder(reminder); + StopTimerLocked(TimerType::TRIGGER_TIMER); + // todo store_->UpdateOrInsert() + } + // if (reminder->ShouldShowImmediately()) { // todo + // if (IsSoundOrVibratorDefined(reminder)) { + // ShowReminder(reminder, true, true, false, false); + // } else { + // ShowReminder(reminder, false, true, false, false); + // } + // } else { + ANSR_LOGI("Start recent reminder"); + StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); + reminder->OnStart(); + // todo store_->UpdateOrInsert() + SetActiveReminder(reminder); + // } } void ReminderDataManager::StopAlertingReminder(const sptr &reminder) @@ -694,16 +735,16 @@ sptr ReminderDataManager::GetRecentReminderLocked() } int32_t reminderId = (*it)->GetReminderId(); ANSR_LOGD("Containers(vector) remove. reminderId=%{public}d", reminderId); - auto mit = notificationBundleOptionMap_.find((*it)->GetReminderId()); + auto mit = notificationBundleOptionMap_.find(reminderId); if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGE("Remove notificationBundleOption(reminderId=%{public}d) fail", - (*it)->GetReminderId()); + ANSR_LOGE("Remove notificationBundleOption(reminderId=%{public}d) fail", reminderId); } else { - ANSR_LOGD("Containers(vector/map) remove. reminderId=%{public}d", reminderId); + ANSR_LOGD("Containers(map) remove. reminderId=%{public}d", reminderId); notificationBundleOptionMap_.erase(mit); } it = reminderVector_.erase(it); totalCount_--; + // todo store_->Delete(reminderId); } return nullptr; } @@ -731,7 +772,7 @@ void ReminderDataManager::HandleImmediatelyShow( { bool isAlerting = false; for (auto it = showImmediately.begin(); it != showImmediately.end(); ++it) { - if (!isAlerting) { + if (!isAlerting) { // todo isSoundOrVibratorDefined ShowReminder((*it), true, false, isSysTimeChanged, false); isAlerting = true; } else { @@ -753,14 +794,14 @@ sptr ReminderDataManager::HandleRefreshReminder(uint8_t &type, } if (!needShowImmediately) { uint64_t triggerTimeAfter = reminder->GetTriggerTimeInMilli(); - if (triggerTimeBefore != triggerTimeAfter - || reminder->GetReminderId() == alertingReminderId_) { + if (triggerTimeBefore != triggerTimeAfter || reminder->GetReminderId() == alertingReminderId_) { CloseReminder(reminder, true); } + // todo store_->UpdateOrInsert return nullptr; - } else { - return reminder; } + // todo store_->UpdateOrInsert + return reminder; } void ReminderDataManager::HandleSameNotificationIdShowing(const sptr reminder) @@ -789,10 +830,39 @@ void ReminderDataManager::HandleSameNotificationIdShowing(const sptrOnSameNotificationIdCovered(); RemoveFromShowedReminders(*it); + // todo store_->UpdateOrInsert } } } +void ReminderDataManager::Init(bool isFromBootComplete) +{ + ANSR_LOGD("ReminderDataManager Init, isFromBootComplete:%{public}d", isFromBootComplete); + if (IsReminderAgentReady()) { + return; + } + if (store_ == nullptr) { + store_ = std::make_shared(); + } + if (store_->Init() != ReminderAgent::STATE_OK) { + ANSR_LOGW("Db init fail."); + return; + } + LoadReminderFromDb(); + ANSR_LOGD("~~~~dump:%{public}s", Dump().c_str()); + if (isFromBootComplete) { + // todo + } + StartRecentReminder(); // todo + isReminderAgentReady_ = true; + ANSR_LOGD("ReminderAgent is ready."); +} + +bool ReminderDataManager::IsReminderAgentReady() const +{ + return isReminderAgentReady_; +} + bool ReminderDataManager::IsBelongToSameApp( const sptr reminder, const std::string otherPkgName, const int otherUserId) { @@ -809,6 +879,31 @@ bool ReminderDataManager::IsBelongToSameApp( return false; } +// todo IsBelongToSameUser + +void ReminderDataManager::LoadReminderFromDb() +{ + std::lock_guard lock(ReminderDataManager::MUTEX); + std::vector> existReminders = store_->GetAllValidReminders(); + reminderVector_ = existReminders; + ANSR_LOGD("LoadReminderFromDb, reminder size=%{public}d", reminderVector_.size()); + for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { + sptr bundleOption = new NotificationBundleOption(); + int32_t reminderId = (*it)->GetReminderId(); + if (!(store_->GetBundleOption(reminderId, bundleOption))) { + ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); + continue; + } + auto ret = notificationBundleOptionMap_.insert( + std::pair>(reminderId, bundleOption)); + if (!ret.second) { + ANSR_LOGE("Containers add to map error"); + continue; + } + } + ReminderRequest::GLOBAL_ID = store_->GetMaxId() + 1; +} + void ReminderDataManager::PlaySoundAndVibrationLocked(const sptr &reminder) { std::lock_guard lock(ReminderDataManager::ALERT_MUTEX); // todo check died lock @@ -880,6 +975,9 @@ void ReminderDataManager::StopSoundAndVibration(const sptr &rem SetAlertingReminder(nullReminder); } +// todo AddDefaultSlotIfNeeded +// todo IsNotificationEnable + void ReminderDataManager::RemoveFromShowedReminders(const sptr &reminder) { std::lock_guard lock(ReminderDataManager::SHOW_MUTEX); @@ -913,6 +1011,7 @@ void ReminderDataManager::RemoveReminderLocked(const int32_t &reminderId) ANSR_LOGD("Containers(vector) remove. reminderId=%{public}d", reminderId); it = reminderVector_.erase(it); totalCount_--; + // todo store_->Delete(reminderId); break; } else { ++it; @@ -938,6 +1037,10 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques sptr timer = MiscServices::TimeServiceClient::GetInstance(); time_t now; (void)time(&now); // unit is seconds. + if (now < 0) { + ANSR_LOGE("Get now time error"); + return; + } uint64_t triggerTime = 0; switch (type) { case TimerType::TRIGGER_TIMER: { @@ -957,7 +1060,7 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques ANSR_LOGE("Alerting time out timer has already started."); break; } - triggerTime = now * ReminderRequest::MILLI_SECONDS + triggerTime = static_cast(now) * ReminderRequest::MILLI_SECONDS + static_cast(reminderRequest->GetRingDuration() * ReminderRequest::MILLI_SECONDS); timerIdAlerting_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type)); timer->StartTimer(timerIdAlerting_, triggerTime); @@ -973,8 +1076,9 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques if (triggerTime == 0) { ANSR_LOGW("Start timer fail"); } else { - ANSR_LOGD("Timing info: now:(%{public}lld), tar:(%{public}llu)", - (long long)(now * ReminderRequest::MILLI_SECONDS), (unsigned long long)(triggerTime)); + ANSR_LOGD("Timing info: now:(%{public}llu), tar:(%{public}llu)", + (unsigned long long)(static_cast(now) * ReminderRequest::MILLI_SECONDS), + (unsigned long long)(triggerTime)); } } diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index d085adff048081db48272588c9c02c2fa3b4621d..13e06d7e0a6a39cace843e0cc3b5d77b681a4b8e 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -19,9 +19,6 @@ #include "common_event_manager.h" #include "common_event_support.h" #include "bundle_constants.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" #include "reminder_event_manager.h" @@ -40,6 +37,7 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); @@ -86,6 +84,11 @@ void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFw reminderDataManager_->CloseReminder(want, false); return; } + if (action == CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED) { + // todo judge major user + reminderDataManager_->Init(true); + return; + } if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { HandlePackageRemove(want); return; @@ -110,8 +113,11 @@ void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFw void ReminderEventManager::ReminderEventSubscriber::HandlePackageRemove(OHOS::EventFwk::Want &want) const { - sptr bundleOption = GetBundleOption(want); - reminderDataManager_->CancelAllReminders(bundleOption); + OHOS::AppExecFwk::ElementName ele = want.GetElement(); + std::string bundleName = ele.GetBundleName(); + int userId = want.GetIntParam(OHOS::AppExecFwk::Constants::USER_ID, -1); + sptr bundleOption = new NotificationBundleOption(bundleName, -1); + reminderDataManager_->CancelAllReminders(bundleOption, userId); } void ReminderEventManager::ReminderEventSubscriber::HandleProcessDied(OHOS::EventFwk::Want &want) const @@ -126,24 +132,10 @@ sptr ReminderEventManager::ReminderEventSubscriber::Ge OHOS::AppExecFwk::ElementName ele = want.GetElement(); std::string bundleName = ele.GetBundleName(); int userId = want.GetIntParam(OHOS::AppExecFwk::Constants::USER_ID, -1); - int32_t uid = GetUid(userId, bundleName); - ANSR_LOGD("bundleName=%{public}s, uid=%{public}d", bundleName.c_str(), uid); + int32_t uid = ReminderRequest::GetUid(userId, bundleName); + ANSR_LOGD("bundleName=%{public}s, userId=%{public}d, uid=%{public}d", bundleName.c_str(), userId, uid); sptr bundleOption = new NotificationBundleOption(bundleName, uid); return bundleOption; } - -int32_t ReminderEventManager::ReminderEventSubscriber::GetUid(const int userId, const std::string bundleName) const -{ - AppExecFwk::ApplicationInfo info; - OHOS::sptr systemAbilityManager - = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - OHOS::sptr remoteObject - = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - OHOS::sptr bundleMgr - = OHOS::iface_cast(remoteObject); - bundleMgr->GetApplicationInfo(bundleName, AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, - static_cast(userId), info); - return static_cast(info.uid); -} } // namespace OHOS } // namespace Notification diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index d5c0aabd1ca1b343384401dc5327240b4e61a754..3e976bf56a1f295330d56fc59548900f35c51736 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -78,12 +78,12 @@ ohos_unittest("ans_unit_test") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index 43dd48487e5c716ce5fda69b2076bbfcadb97c12..22c67f691853cbde82f7a4662f034882ef9b87ad 100644 --- a/services/distributed/BUILD.gn +++ b/services/distributed/BUILD.gn @@ -46,9 +46,9 @@ ohos_shared_library("libans_distributed") { external_deps = [ "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index 347c7abeb7d63af35d55f8784d54c9ab24c2d46d..934c13331449282f544f764a2e1657e705f5dbd2 100644 --- a/services/distributed/test/unittest/BUILD.gn +++ b/services/distributed/test/unittest/BUILD.gn @@ -69,7 +69,7 @@ ohos_unittest("ans_distributed_unit_test") { external_deps = [ "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", + "bundle_framework:appexecfwk_base", "distributeddatamgr:distributeddata_inner", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 6a56dad4ba7166d3aeb73a26e27b4c52f1b62a03..f4bcd539cf25fd6a9d822913fb6a03708da3c078 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -65,12 +65,12 @@ ohos_moduletest("ans_module_test") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/test/common/acts/actsnotificationfuzztest/BUILD.gn b/test/common/acts/actsnotificationfuzztest/BUILD.gn index 218219a346d41e2245374c81f7cbfb028ca5a0d5..cdc3f2039f76bdf03ab3f911e97127a72d3115de 100644 --- a/test/common/acts/actsnotificationfuzztest/BUILD.gn +++ b/test/common/acts/actsnotificationfuzztest/BUILD.gn @@ -79,10 +79,10 @@ ohos_systemtest("ActsNotificationFuzzTest") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "appexecfwk_standard:libeventhandler", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", diff --git a/test/resource/ansSTSlotGroupTest/BUILD.gn b/test/resource/ansSTSlotGroupTest/BUILD.gn index 2090014d3e97fd55db954365148924541238ab9c..ca4688dd19f7a2d61c1577f7b8b3bda626d1a154 100644 --- a/test/resource/ansSTSlotGroupTest/BUILD.gn +++ b/test/resource/ansSTSlotGroupTest/BUILD.gn @@ -59,8 +59,8 @@ ohos_shared_library("libraryAnsSTSlotGroupTest") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] diff --git a/test/systemtest/acts/ansDump/BUILD.gn b/test/systemtest/acts/ansDump/BUILD.gn index 1a039aab3d7b7ba53fc9ea55a9fe7b4a6fd65fbf..52a13ac519655291947c7f1a0433c266e129bbaf 100644 --- a/test/systemtest/acts/ansDump/BUILD.gn +++ b/test/systemtest/acts/ansDump/BUILD.gn @@ -42,7 +42,7 @@ ohos_systemtest("AnsDumpTest") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_core", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/tools/dump/include/notification_shell_command.h b/tools/dump/include/notification_shell_command.h index bede4da7ee61efdac00fbf299d542b7302d0a93d..26fc5199e25195ffb6f9dacbaedf1ce9eb993a78 100644 --- a/tools/dump/include/notification_shell_command.h +++ b/tools/dump/include/notification_shell_command.h @@ -34,12 +34,11 @@ private: ErrCode RunAsDumpCommand(); ErrCode RunHelp(); - ErrCode RunActive(); - ErrCode RunRecent(); + ErrCode RunActive(std::vector &infos); + ErrCode RunRecent(std::vector &infos); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - ErrCode RunDistributed(); + ErrCode RunDistributed(std::vector &infos); #endif - ErrCode RunSetRecentCount(); private: std::shared_ptr ans_; diff --git a/tools/dump/src/notification_shell_command.cpp b/tools/dump/src/notification_shell_command.cpp index 2d44785e738cfe1b70b1917ed4da86c899dded5c..97de8dd95d8b5da05f66b0ac7be1481c1e99cda2 100644 --- a/tools/dump/src/notification_shell_command.cpp +++ b/tools/dump/src/notification_shell_command.cpp @@ -99,10 +99,9 @@ ErrCode NotificationShellCommand::RunHelp() return ERR_OK; } -ErrCode NotificationShellCommand::RunActive() +ErrCode NotificationShellCommand::RunActive(std::vector &infos) { ErrCode ret = ERR_OK; - std::vector infos; if (ans_ != nullptr) { ret = ans_->ShellDump("active", infos); resultReceiver_.append("Total:" + std::to_string(infos.size()) + "\n"); @@ -112,10 +111,9 @@ ErrCode NotificationShellCommand::RunActive() return ret; } -ErrCode NotificationShellCommand::RunRecent() +ErrCode NotificationShellCommand::RunRecent(std::vector &infos) { ErrCode ret = ERR_OK; - std::vector infos; if (ans_ != nullptr) { ret = ans_->ShellDump("recent", infos); resultReceiver_.append("Total:" + std::to_string(infos.size()) + "\n"); @@ -126,10 +124,9 @@ ErrCode NotificationShellCommand::RunRecent() } #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED -ErrCode NotificationShellCommand::RunDistributed() +ErrCode NotificationShellCommand::RunDistributed(std::vector &infos) { ErrCode ret = ERR_OK; - std::vector infos; if (ans_ != nullptr) { ret = ans_->ShellDump("distributed", infos); resultReceiver_.append("Total:" + std::to_string(infos.size()) + "\n"); @@ -157,14 +154,14 @@ ErrCode NotificationShellCommand::RunAsDumpCommand() ret = RunHelp(); break; case 'A': - ret = RunActive(); + ret = RunActive(infos); break; case 'R': - ret = RunRecent(); + ret = RunRecent(infos); break; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED case 'D': - ret = RunDistributed(); + ret = RunDistributed(infos); break; #endif case 0: