From d4afc6d304e4e6345f0b85871abfd40423832597 Mon Sep 17 00:00:00 2001 From: 15151839515 Date: Fri, 17 Nov 2023 11:54:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E5=86=B5=E7=AA=97framework=E5=B1=82?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 15151839515 --- frameworks/ans/BUILD.gn | 9 +- frameworks/ans/src/notification.cpp | 67 +++ .../ans/src/notification_bundle_option.cpp | 32 ++ frameworks/ans/src/notification_helper.cpp | 24 +- ...otification_local_live_view_subscriber.cpp | 2 +- frameworks/ans/src/notification_request.cpp | 300 ++++++++++- frameworks/ans/src/notification_slot.cpp | 19 + .../ans/src/notification_subscriber.cpp | 12 +- frameworks/ans/src/reminder_helper.cpp | 1 + frameworks/ans/src/reminder_request.cpp | 464 +++++++++--------- frameworks/ans/src/reminder_request_alarm.cpp | 20 +- .../ans/src/reminder_request_calendar.cpp | 76 ++- frameworks/ans/src/reminder_request_timer.cpp | 2 + frameworks/ans/src/reminder_store.cpp | 92 ++-- frameworks/ans/src/reminder_table.cpp | 152 ++++++ frameworks/ans/test/unittest/BUILD.gn | 2 + .../notification_bundle_option_test.cpp | 20 +- .../unittest/notification_helper_test.cpp | 3 +- ...tification_local_live_view_button_test.cpp | 142 ++++++ ...ification_local_live_view_content_test.cpp | 123 +++++ .../ans/test/unittest/notification_test.cpp | 38 +- .../reminder_request_branch_test.cpp | 6 +- .../test/unittest/reminder_request_test.cpp | 91 +++- .../core/common/include/ans_const_define.h | 1 + .../core/include/ans_manager_interface.h | 20 +- frameworks/core/include/ans_manager_proxy.h | 23 +- frameworks/core/include/ans_manager_stub.h | 13 +- frameworks/core/include/ans_notification.h | 55 ++- .../core/include/ans_subscriber_interface.h | 3 + .../core/include/ans_subscriber_proxy.h | 3 + frameworks/core/include/ans_subscriber_stub.h | 4 + ..._notification_service_ipc_interface_code.h | 3 + .../core/include/hitrace_meter_adapter.h | 24 + frameworks/core/src/ans_manager_proxy.cpp | 125 ++++- frameworks/core/src/ans_manager_stub.cpp | 106 +++- frameworks/core/src/ans_notification.cpp | 146 +++--- frameworks/core/src/ans_subscriber_proxy.cpp | 53 ++ frameworks/core/src/ans_subscriber_stub.cpp | 35 ++ .../ans_manager_proxy_unit_test.cpp | 15 +- .../ans_manager_stub_test.cpp | 5 +- .../ans_notification_annex_test.cpp | 4 +- .../ans_notification_branch_test.cpp | 23 +- .../ans_notification_unit_test.cpp | 3 +- .../ans_subscriber_proxy_unit_test.cpp | 123 ++++- .../ans_subscriber_stub_test/BUILD.gn | 11 +- .../ans_subscriber_stub_unit_test.cpp | 99 ++++ frameworks/js/napi/include/common.h | 1 + .../napi/include/reminder/reminder_common.h | 1 + frameworks/js/napi/src/common.cpp | 7 + frameworks/js/napi/src/constant.cpp | 1 + .../js/napi/src/manager/napi_get_active.cpp | 2 + frameworks/js/napi/src/manager/napi_push.cpp | 2 +- frameworks/js/napi/src/manager/napi_slot.cpp | 3 +- frameworks/js/napi/src/reminder/publish.cpp | 6 + .../js/napi/src/reminder/reminder_common.cpp | 11 + frameworks/js/napi/src/slot.cpp | 3 +- .../ans_innerkits_module_publish_test.cpp | 155 +++++- .../ans_innerkits_module_slot_test.cpp | 11 +- interfaces/inner_api/notification.h | 47 ++ .../inner_api/notification_bundle_option.h | 19 +- interfaces/inner_api/notification_constant.h | 19 +- interfaces/inner_api/notification_helper.h | 29 +- interfaces/inner_api/notification_request.h | 116 ++++- .../inner_api/notification_subscriber.h | 3 + interfaces/inner_api/reminder_request.h | 27 +- interfaces/inner_api/reminder_request_alarm.h | 4 - .../inner_api/reminder_request_calendar.h | 12 - interfaces/inner_api/reminder_store.h | 3 +- interfaces/inner_api/reminder_table.h | 227 +++++++++ notification.gni | 7 + services/ans/BUILD.gn | 6 +- .../include/advanced_notification_service.h | 5 +- services/ans/include/reminder_data_manager.h | 2 +- .../ans/src/advanced_notification_service.cpp | 51 +- ...ion_local_live_view_subscriber_manager.cpp | 2 +- services/ans/src/notification_preferences.cpp | 2 +- .../src/notification_preferences_database.cpp | 2 +- .../src/notification_subscriber_manager.cpp | 2 +- services/ans/src/reminder_data_manager.cpp | 14 +- ...anced_notification_service_branch_test.cpp | 2 +- .../advanced_notification_service_test.cpp | 4 +- ...ication_subscriber_manager_branch_test.cpp | 4 +- services/distributed/BUILD.gn | 8 +- .../src/distributed_notification_manager.cpp | 2 +- .../advancednotificationservice_fuzzer.cpp | 2 +- .../ansmanagerstub_fuzzer.cpp | 2 +- .../setdonotdisturbdate_fuzzer.cpp | 2 +- tools/dump/BUILD.gn | 4 + tools/dump/src/notification_shell_command.cpp | 4 + 89 files changed, 2860 insertions(+), 570 deletions(-) create mode 100644 frameworks/ans/src/reminder_table.cpp create mode 100644 frameworks/ans/test/unittest/notification_local_live_view_button_test.cpp create mode 100644 frameworks/ans/test/unittest/notification_local_live_view_content_test.cpp create mode 100644 frameworks/core/include/hitrace_meter_adapter.h create mode 100644 interfaces/inner_api/reminder_table.h diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 52ea17249..66cad5c3c 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -108,10 +108,13 @@ ohos_shared_library("ans_innerkits") { "${frameworks_module_ans_path}/src/reminder_request_calendar.cpp", "${frameworks_module_ans_path}/src/reminder_request_timer.cpp", "${frameworks_module_ans_path}/src/reminder_store.cpp", + "${frameworks_module_ans_path}/src/reminder_table.cpp", ] public_configs = [ ":ans_innerkits_public_config" ] + defines = [] + external_deps = [ "ability_base:want", "ability_base:zuri", @@ -122,7 +125,6 @@ ohos_shared_library("ans_innerkits") { "eventhandler:libeventhandler", "hicollie:libhicollie", "hilog:libhilog", - "hitrace:hitrace_meter", "i18n:intl_util", "image_framework:image_native", "ipc:ipc_core", @@ -136,6 +138,11 @@ ohos_shared_library("ans_innerkits") { cflags = [ "-DCONFIG_DUAL_FRAMEWORK" ] } + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + defines += [ "HITRACE_METER_ENABLE" ] + } + subsystem_name = "${subsystem_name}" part_name = "${component_name}" } diff --git a/frameworks/ans/src/notification.cpp b/frameworks/ans/src/notification.cpp index 75b98c85e..4331dea48 100644 --- a/frameworks/ans/src/notification.cpp +++ b/frameworks/ans/src/notification.cpp @@ -55,6 +55,9 @@ Notification::Notification(const Notification &other) isRemoveAllowed_ = other.isRemoveAllowed_; sourceType_ = other.sourceType_; deviceId_ = other.deviceId_; + updateTimerId_ = other.updateTimerId_; + finishTimerId_ = other.finishTimerId_; + archiveTimerId_ = other.archiveTimerId_; } Notification::~Notification() @@ -308,6 +311,26 @@ bool Notification::MarshallingInt64(Parcel &parcel) const return true; } +bool Notification::MarshallingUint64(Parcel &parcel) const +{ + if (!parcel.WriteUint64(updateTimerId_)) { + ANS_LOGE("Can't write update timer id."); + return false; + } + + if (!parcel.WriteUint64(finishTimerId_)) { + ANS_LOGE("Can't write finish timer id."); + return false; + } + + if (!parcel.WriteUint64(archiveTimerId_)) { + ANS_LOGE("Can't write archive timer id."); + return false; + } + + return true; +} + bool Notification::MarshallingParcelable(Parcel &parcel) const { if (!parcel.WriteStrongParcelable(request_)) { @@ -332,6 +355,9 @@ bool Notification::Marshalling(Parcel &parcel) const if (!MarshallingInt64(parcel)) { return false; } + if (!MarshallingUint64(parcel)) { + return false; + } if (!MarshallingParcelable(parcel)) { return false; } @@ -392,6 +418,13 @@ void Notification::ReadFromParcelInt64(Parcel &parcel) parcel.ReadInt64Vector(&vibrationStyle_); } +void Notification::ReadFromParcelUint64(Parcel &parcel) +{ + updateTimerId_ = parcel.ReadUint64(); + finishTimerId_ = parcel.ReadUint64(); + archiveTimerId_ = parcel.ReadUint64(); +} + void Notification::ReadFromParcelParcelable(Parcel &parcel) { // Read request_ @@ -404,6 +437,7 @@ bool Notification::ReadFromParcel(Parcel &parcel) ReadFromParcelString(parcel); ReadFromParcelInt32(parcel); ReadFromParcelInt64(parcel); + ReadFromParcelUint64(parcel); ReadFromParcelParcelable(parcel); return true; @@ -505,7 +539,40 @@ std::string Notification::Dump() const ", postTime = " + std::to_string(postTime_) + ", sound = " + (sound_ == nullptr ? "nullptr" : sound_->ToString()) + ", vibrationStyle = [" + vibrationStyle + "]" + + ", updateTimer = " + std::to_string(updateTimerId_) + + ", finishTimer = " + std::to_string(finishTimerId_) + + ", archiveTimer = " + std::to_string(archiveTimerId_) + " }"; } + +uint64_t Notification::GetUpdateTimer() const +{ + return updateTimerId_; +} + +void Notification::SetUpdateTimer(uint64_t updateTimerId) +{ + updateTimerId_ = updateTimerId; +} + +uint64_t Notification::GetFinishTimer() const +{ + return finishTimerId_; +} + +void Notification::SetFinishTimer(uint64_t finishTimerId) +{ + finishTimerId_ = finishTimerId; +} + +void Notification::SetArchiveTimer(uint64_t archiveTimerId) +{ + archiveTimerId_ = archiveTimerId; +} + +uint64_t Notification::GetArchiveTimer() const +{ + return archiveTimerId_; +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/src/notification_bundle_option.cpp b/frameworks/ans/src/notification_bundle_option.cpp index bf9770077..b5047f466 100644 --- a/frameworks/ans/src/notification_bundle_option.cpp +++ b/frameworks/ans/src/notification_bundle_option.cpp @@ -94,5 +94,37 @@ bool NotificationBundleOption::ReadFromParcel(Parcel &parcel) return true; } + +bool NotificationBundleOption::ToJson(nlohmann::json &jsonObject) const +{ + jsonObject["uid"] = uid_; + jsonObject["bundleName"] = bundleName_; + return true; +} + +NotificationBundleOption *NotificationBundleOption::FromJson(const nlohmann::json &jsonObject) +{ + if (jsonObject.is_null() or !jsonObject.is_object()) { + ANS_LOGE("Invalid JSON object"); + return nullptr; + } + + auto *pBundle = new (std::nothrow) NotificationBundleOption(); + if (pBundle == nullptr) { + ANS_LOGE("Failed to create bundle option instance"); + return nullptr; + } + + const auto &jsonEnd = jsonObject.cend(); + if (jsonObject.find("uid") != jsonEnd && jsonObject.at("uid").is_number_integer()) { + pBundle->uid_ = jsonObject.at("uid").get(); + } + + if (jsonObject.find("bundleName") != jsonEnd && jsonObject.at("bundleName").is_string()) { + pBundle->bundleName_ = jsonObject.at("bundleName").get(); + } + + return pBundle; +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 2e1c71735..bd450bedf 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -251,6 +251,12 @@ ErrCode NotificationHelper::GetAllActiveNotifications( return DelayedSingleton::GetInstance()->GetAllActiveNotifications(key, notification); } +ErrCode NotificationHelper::GetActiveNotificationByFilter( + const LiveViewFilter &filter, sptr &request) +{ + return DelayedSingleton::GetInstance()->GetActiveNotificationByFilter(filter, request); +} + ErrCode NotificationHelper::IsAllowedNotify(const NotificationBundleOption &bundleOption, bool &allowed) { return DelayedSingleton::GetInstance()->IsAllowedNotify(bundleOption, allowed); @@ -386,10 +392,11 @@ ErrCode NotificationHelper::GetDoNotDisturbDate(const int32_t &userId, Notificat return DelayedSingleton::GetInstance()->GetDoNotDisturbDate(userId, doNotDisturbDate); } -ErrCode NotificationHelper::SetEnabledForBundleSlot( - const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled) +ErrCode NotificationHelper::SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) { - return DelayedSingleton::GetInstance()->SetEnabledForBundleSlot(bundleOption, slotType, enabled); + return DelayedSingleton::GetInstance()->SetEnabledForBundleSlot(bundleOption, + slotType, enabled, isForceControl); } ErrCode NotificationHelper::GetEnabledForBundleSlot( @@ -398,6 +405,11 @@ ErrCode NotificationHelper::GetEnabledForBundleSlot( return DelayedSingleton::GetInstance()->GetEnabledForBundleSlot(bundleOption, slotType, enabled); } +ErrCode NotificationHelper::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + return DelayedSingleton::GetInstance()->GetEnabledForBundleSlotSelf(slotType, enabled); +} + ErrCode NotificationHelper::SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) { return DelayedSingleton::GetInstance()->SetSyncNotificationEnabledWithoutApp( @@ -415,9 +427,11 @@ ErrCode NotificationHelper::SetBadgeNumber(int32_t badgeNumber) return DelayedSingleton::GetInstance()->SetBadgeNumber(badgeNumber); } -ErrCode NotificationHelper::RegisterPushCallback(const sptr &pushCallback) +ErrCode NotificationHelper::RegisterPushCallback(const sptr &pushCallback, + const sptr ¬ificationCheckRequest) { - return DelayedSingleton::GetInstance()->RegisterPushCallback(pushCallback); + return DelayedSingleton::GetInstance()->RegisterPushCallback(pushCallback, + notificationCheckRequest); } ErrCode NotificationHelper::UnregisterPushCallback() diff --git a/frameworks/ans/src/notification_local_live_view_subscriber.cpp b/frameworks/ans/src/notification_local_live_view_subscriber.cpp index 545c5f200..2dd138134 100644 --- a/frameworks/ans/src/notification_local_live_view_subscriber.cpp +++ b/frameworks/ans/src/notification_local_live_view_subscriber.cpp @@ -15,7 +15,7 @@ #include "notification_local_live_view_subscriber.h" -#include "hitrace_meter.h" +#include "hitrace_meter_adapter.h" #include "iservice_registry.h" #include "system_ability_definition.h" diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 78da16866..edb0173f4 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -15,10 +15,15 @@ #include "notification_request.h" +#include "ans_inner_errors.h" #include "ans_image_util.h" #include "ans_log_wrapper.h" +#include "errors.h" +#include "notification_live_view_content.h" +#include "refbase.h" #include "want_agent_helper.h" #include "want_params_wrapper.h" +#include namespace OHOS { namespace Notification { @@ -45,6 +50,7 @@ const uint32_t NotificationRequest::COLOR_MASK {0xFF000000}; const std::size_t NotificationRequest::MAX_USER_INPUT_HISTORY {5}; const std::size_t NotificationRequest::MAX_ACTION_BUTTONS {3}; const std::size_t NotificationRequest::MAX_MESSAGE_USERS {1000}; +const std::string NotificationRequest::KEY_PREFIX {"ans_live_view"}; NotificationRequest::NotificationRequest(int32_t notificationId) : notificationId_(notificationId) { @@ -249,6 +255,36 @@ int64_t NotificationRequest::GetAutoDeletedTime() const return autoDeletedTime_; } +void NotificationRequest::SetMaxUpdateTime(int64_t maxUpdateTime) +{ + maxUpdateTime_ = maxUpdateTime; +} + +int64_t NotificationRequest::GetMaxUpdateTime() const +{ + return maxUpdateTime_; +} + +void NotificationRequest::SetMaxFinishTime(int64_t maxFinishTime) +{ + maxFinishTime_ = maxFinishTime; +} + +int64_t NotificationRequest::GetMaxFinishTime() const +{ + return maxFinishTime_; +} + +void NotificationRequest::SetMaxArchiveTime(int64_t maxArchiveTime) +{ + maxArchiveTime_ = maxArchiveTime; +} + +int64_t NotificationRequest::GetMaxArchiveTime() const +{ + return maxArchiveTime_; +} + void NotificationRequest::SetLittleIcon(const std::shared_ptr &littleIcon) { littleIcon_ = littleIcon; @@ -678,9 +714,8 @@ std::string NotificationRequest::Dump() ", creatorUid = " + std::to_string(static_cast(creatorUid_)) + ", ownerBundleName = " + ownerBundleName_ + ", ownerUid = " + std::to_string(static_cast(ownerUid_)) + - ", groupName = " + groupName_ + - ", statusBarText = " + statusBarText_ + ", label = " + label_ + ", shortcutId = " + shortcutId_ + - ", sortingKey = " + sortingKey_ + + ", groupName = " + groupName_ + ", statusBarText = " + statusBarText_ + ", label = " + label_ + + ", shortcutId = " + shortcutId_ + ", sortingKey = " + sortingKey_ + ", groupAlertType = " + std::to_string(static_cast(groupAlertType_)) + ", color = " + std::to_string(color_) + ", badgeNumber = " + std::to_string(badgeNumber_) + ", visiblenessType = " + std::to_string(static_cast(visiblenessType_)) + @@ -714,9 +749,10 @@ std::string NotificationRequest::Dump() ", userInputHistory = " + (!userInputHistory_.empty() ? userInputHistory_.at(0) : "empty") + ", distributedOptions = " + distributedOptions_.Dump() + ", notificationFlags = " + (notificationFlags_ ? "not null" : "null") + - ", creatorUserId = " + std::to_string(creatorUserId_) + - ", ownerUserId = " + std::to_string(ownerUserId_) + + ", creatorUserId = " + std::to_string(creatorUserId_) + ", ownerUserId = " + std::to_string(ownerUserId_) + ", receiverUserId = " + std::to_string(receiverUserId_) + + ", maxUpdateTime = " + std::to_string(maxUpdateTime_) + + ", maxFinishTime = " + std::to_string(maxFinishTime_) + " }"; } @@ -1544,7 +1580,6 @@ void NotificationRequest::CopyOther(const NotificationRequest &other) this->additionalParams_ = other.additionalParams_; this->littleIcon_ = other.littleIcon_; this->bigIcon_ = other.bigIcon_; - this->overlayIcon_ = other.overlayIcon_; this->notificationContent_ = other.notificationContent_; this->actionButtons_ = other.actionButtons_; @@ -1615,6 +1650,20 @@ bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const return true; } +void NotificationRequest::ConvertJsonToNumExt( + NotificationRequest *target, const nlohmann::json &jsonObject) +{ + const auto &jsonEnd = jsonObject.cend(); + + if (jsonObject.find("maxUpdateTime") != jsonEnd && jsonObject.at("maxUpdateTime").is_number_integer()) { + target->maxUpdateTime_ = jsonObject.at("maxUpdateTime").get(); + } + + if (jsonObject.find("maxFinishTime") != jsonEnd && jsonObject.at("maxFinishTime").is_number_integer()) { + target->maxFinishTime_ = jsonObject.at("maxFinishTime").get(); + } +} + void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nlohmann::json &jsonObject) { if (target == nullptr) { @@ -1659,6 +1708,9 @@ void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nl if (jsonObject.find("badgeNumber") != jsonEnd && jsonObject.at("badgeNumber").is_number_integer()) { target->badgeNumber_ = jsonObject.at("badgeNumber").get(); } + + ConvertJsonToNumExt(target, jsonObject); + } } void NotificationRequest::ConvertJsonToString(NotificationRequest *target, const nlohmann::json &jsonObject) @@ -1884,5 +1936,241 @@ bool NotificationRequest::ConvertJsonToNotificationFlags( return true; } + +bool NotificationRequest::IsCommonLiveView() const +{ + return (slotType_ == NotificationConstant::SlotType::LIVE_VIEW) && + (notificationContentType_ == NotificationContent::Type::LIVE_VIEW); +} + +ErrCode NotificationRequest::CheckVersion(const sptr &oldRequest) const +{ + auto content = notificationContent_->GetNotificationContent(); + auto liveView = std::static_pointer_cast(content); + auto oldContent = oldRequest->GetContent()->GetNotificationContent(); + auto oldLiveView = std::static_pointer_cast(oldContent); + + if (oldLiveView->GetVersion() == NotificationLiveViewContent::MAX_VERSION) { + return ERR_OK; + } + if (liveView->GetVersion() == NotificationLiveViewContent::MAX_VERSION) { + ANS_LOGE("Invalid version, creator bundle name %{public}s, id %{public}d, " + "old version %{public}u, new version %{public}u.", GetCreatorBundleName().c_str(), + GetNotificationId(), oldLiveView->GetVersion(), liveView->GetVersion()); + return ERR_ANS_EXPIRED_NOTIFICATION; + } + if (oldLiveView->GetVersion() >= liveView->GetVersion()) { + ANS_LOGE("Live view has finished, creator bundle name %{public}s, id %{public}d, " + "old version %{public}u, new version %{public}u.", GetCreatorBundleName().c_str(), + GetNotificationId(), oldLiveView->GetVersion(), liveView->GetVersion()); + return ERR_ANS_EXPIRED_NOTIFICATION; + } + return ERR_OK; +} + +ErrCode NotificationRequest::CheckNotificationRequest(const sptr &oldRequest) const +{ + if (!IsCommonLiveView()) { + return ERR_OK; + } + + using StatusType = NotificationLiveViewContent::LiveViewStatus; + auto content = notificationContent_->GetNotificationContent(); + auto liveView = std::static_pointer_cast(content); + auto status = liveView->GetLiveViewStatus(); + if (oldRequest == nullptr) { + if (status != StatusType::LIVE_VIEW_CREATE) { + ANS_LOGE("Doesn't exist live view, bundle name %{public}s, id %{public}d.", + GetCreatorBundleName().c_str(), GetNotificationId()); + return ERR_ANS_NOTIFICATION_NOT_EXISTS; + } + return ERR_OK; + } + + if (!oldRequest->IsCommonLiveView()) { + ANS_LOGE("Invalid old request param, slot type %{public}d, content type %{public}d.", + oldRequest->GetSlotType(), oldRequest->GetNotificationType()); + return ERR_ANS_INVALID_PARAM; + } + + if (status == StatusType::LIVE_VIEW_CREATE) { + ANS_LOGW("Repeat create live view, bundle name %{public}s, id %{public}d.", + GetCreatorBundleName().c_str(), GetNotificationId()); + return ERR_ANS_REPEAT_CREATE; + } + + auto oldContent = oldRequest->GetContent()->GetNotificationContent(); + auto oldLiveView = std::static_pointer_cast(oldContent); + auto oldStatus = oldLiveView->GetLiveViewStatus(); + if (oldStatus == StatusType::LIVE_VIEW_END) { + ANS_LOGW("Live view has finished, bundle name %{public}s, id %{public}d.", + GetCreatorBundleName().c_str(), GetNotificationId()); + return ERR_ANS_END_NOTIFICATION; + } + + return CheckVersion(oldRequest); +} + +void NotificationRequest::FillMissingParameters(const sptr &oldRequest) +{ + if (!IsCommonLiveView() || (oldRequest == nullptr)) { + return; + } + + maxUpdateTime_ = oldRequest->maxUpdateTime_; + maxFinishTime_ = oldRequest->maxFinishTime_; + if (autoDeletedTime_ == NotificationConstant::INVALID_AUTO_DELETE_TIME) { + autoDeletedTime_ = oldRequest->autoDeletedTime_; + } + if (wantAgent_ == nullptr) { + wantAgent_ = oldRequest->wantAgent_; + } + + auto content = notificationContent_->GetNotificationContent(); + auto newLiveViewContent = std::static_pointer_cast(content); + if (newLiveViewContent->GetLiveViewStatus() == + NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_FULL_UPDATE) { + return; + } + auto newExtraInfo = newLiveViewContent->GetExtraInfo(); + auto oldContent = oldRequest->GetContent()->GetNotificationContent(); + auto oldLiveViewContent = std::static_pointer_cast(oldContent); + auto oldExtraInfo = oldLiveViewContent->GetExtraInfo(); + if (newExtraInfo == nullptr) { + newLiveViewContent->SetExtraInfo(oldExtraInfo); + } else { + auto oldKeySet = oldExtraInfo->KeySet(); + for (const auto &key : oldKeySet) { + if (!newExtraInfo->HasParam(key)) { + newExtraInfo->SetParam(key, oldExtraInfo->GetParam(key)); + } + } + } + + auto newPicture = newLiveViewContent->GetPicture(); + auto oldPicture = oldLiveViewContent->GetPicture(); + for (const auto &pictureRecord : oldPicture) { + if (newPicture.find(pictureRecord.first) != newPicture.end()) { + continue; + } + newPicture[pictureRecord.first] = pictureRecord.second; + } +} + +std::string NotificationRequest::GenerateNotificationRequestKey( + int32_t creatorUserId, int32_t creatorUid, const std::string &label, int32_t notificationId) +{ + const char *keySpliter = "_"; + + std::stringstream stream; + stream << KEY_PREFIX << keySpliter << creatorUserId << keySpliter << + creatorUid << keySpliter<< label << keySpliter << notificationId; + return stream.str(); +} + +std::string NotificationRequest::GetKey() +{ + const char *keySpliter = "_"; + + std::stringstream stream; + stream << KEY_PREFIX << keySpliter << creatorUserId_ << keySpliter << + creatorUid_ << keySpliter << label_ << keySpliter << notificationId_; + return stream.str(); +} + +bool NotificationRequest::CheckImageOverSizeForPixelMap( + const std::shared_ptr &pixelMap, uint32_t maxSize) +{ + if (pixelMap == nullptr) { + return false; + } + + auto size = static_cast(pixelMap->GetByteCount()); + return size > maxSize; +} + +ErrCode NotificationRequest::CheckImageSizeForConverSation(std::shared_ptr &content) +{ + auto conversationalContent = std::static_pointer_cast(content); + auto picture = conversationalContent->GetMessageUser().GetPixelMap(); + if (CheckImageOverSizeForPixelMap(picture, MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in ConversationalContent's message user exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto messages = conversationalContent->GetAllConversationalMessages(); + for (auto &msg : messages) { + if (!msg) { + continue; + } + auto img = msg->GetSender().GetPixelMap(); + if (CheckImageOverSizeForPixelMap(img, MAX_ICON_SIZE)) { + ANS_LOGE("The size of picture in ConversationalContent's message exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + } + return ERR_OK; +} + +ErrCode NotificationRequest::CheckImageSizeForPicture(std::shared_ptr &content) +{ + auto pictureContent = std::static_pointer_cast(content); + auto bigPicture = pictureContent->GetBigPicture(); + if (CheckImageOverSizeForPixelMap(bigPicture, MAX_PICTURE_SIZE)) { + ANS_LOGE("The size of big picture in PictureContent exceeds limit"); + return ERR_ANS_PICTURE_OVER_SIZE; + } + return ERR_OK; +} + +ErrCode NotificationRequest::CheckImageSizeForLiveView(std::shared_ptr &content) +{ + auto liveViewContent = std::static_pointer_cast(content); + auto pictureMap = liveViewContent->GetPicture(); + for (const auto &pixelMapRecord : pictureMap) { + if (pixelMapRecord.second.empty()) { + ANS_LOGE("Picture key exist, but picture content is empty."); + return ERR_ANS_INVALID_PARAM; + } + if (pixelMapRecord.second.size() > MAX_LIVE_VIEW_ICON_NUM) { + ANS_LOGE("Picture key exist, but picture content is empty."); + return ERR_ANS_INVALID_PARAM; + } + for (const auto &pixelMap : pixelMapRecord.second) { + if (CheckImageOverSizeForPixelMap(pixelMap, MAX_ICON_SIZE)) { + ANS_LOGE("The size of big picture in PictureContent exceeds limit."); + return ERR_ANS_ICON_OVER_SIZE; + } + } + } + return ERR_OK; +} + +ErrCode NotificationRequest::CheckImageSizeForContent() const +{ + auto content = GetContent(); + if (content == nullptr) { + ANS_LOGE("Invalid content in NotificationRequest"); + return ERR_OK; + } + + auto basicContent = GetContent()->GetNotificationContent(); + if (basicContent == nullptr) { + ANS_LOGE("Invalid content in NotificationRequest"); + return ERR_OK; + } + + auto contentType = GetNotificationType(); + switch (contentType) { + case NotificationContent::Type::CONVERSATION: + return CheckImageSizeForConverSation(basicContent); + case NotificationContent::Type::PICTURE: + return CheckImageSizeForPicture(basicContent); + case NotificationContent::Type::LIVE_VIEW: + return CheckImageSizeForLiveView(basicContent); + default: + return ERR_OK; + } +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/src/notification_slot.cpp b/frameworks/ans/src/notification_slot.cpp index 3bef9e5d4..a7fea9248 100644 --- a/frameworks/ans/src/notification_slot.cpp +++ b/frameworks/ans/src/notification_slot.cpp @@ -116,6 +116,15 @@ void NotificationSlot::SetType(NotificationConstant::SlotType type) SetEnableVibration(false); SetLevel(LEVEL_LOW); break; + case NotificationConstant::SlotType::LIVE_VIEW: + id_ = "LIVE_VIEW"; + SetName("LIVE_VIEW"); + SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC); + SetSound(DEFAULT_NOTIFICATION_SOUND); + SetVibrationStyle(DEFAULT_NOTIFICATION_VIBRATION); + SetLevel(LEVEL_DEFAULT); + SetForceControl(true); + break; case NotificationConstant::SlotType::OTHER: id_ = "OTHER"; SetName("OTHER"); @@ -200,6 +209,16 @@ bool NotificationSlot::GetEnable() const return enabled_; } +void NotificationSlot::SetForceControl(bool isForceControl) +{ + isForceControl_ = isForceControl; +} + +bool NotificationSlot::GetForceControl() const +{ + return isForceControl_; +} + std::string NotificationSlot::Dump() const { return "NotificationSlot{ " diff --git a/frameworks/ans/src/notification_subscriber.cpp b/frameworks/ans/src/notification_subscriber.cpp index 8ec317e47..533ead3ae 100644 --- a/frameworks/ans/src/notification_subscriber.cpp +++ b/frameworks/ans/src/notification_subscriber.cpp @@ -15,7 +15,7 @@ #include "notification_subscriber.h" -#include "hitrace_meter.h" +#include "hitrace_meter_adapter.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -67,6 +67,15 @@ void NotificationSubscriber::SubscriberImpl::OnConsumed( std::make_shared(*notification), std::make_shared(*notificationMap)); } +void NotificationSubscriber::SubscriberImpl::OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + for (auto notification : notifications) { + OnConsumed(notification, notificationMap); + } +} + void NotificationSubscriber::SubscriberImpl::OnCanceled( const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) { @@ -80,7 +89,6 @@ void NotificationSubscriber::SubscriberImpl::OnCanceled( } } - void NotificationSubscriber::SubscriberImpl::OnCanceledList(const std::vector> ¬ifications, const sptr ¬ificationMap, int32_t deleteReason) { diff --git a/frameworks/ans/src/reminder_helper.cpp b/frameworks/ans/src/reminder_helper.cpp index 33c84c1a1..6b09c8a31 100644 --- a/frameworks/ans/src/reminder_helper.cpp +++ b/frameworks/ans/src/reminder_helper.cpp @@ -58,5 +58,6 @@ ErrCode ReminderHelper::RemoveNotificationSlot(const NotificationConstant::SlotT ANSR_LOGI("RemoveNotificationSlot start"); return DelayedSingleton::GetInstance()->RemoveNotificationSlot(slotType); } + } } \ No newline at end of file diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 8904f2caa..773c451a2 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -15,6 +15,7 @@ #include "reminder_request.h" +#include "reminder_table.h" #include "ans_const_define.h" #include "ans_log_wrapper.h" #include "bundle_mgr_interface.h" @@ -76,41 +77,6 @@ const uint8_t ReminderRequest::SUNDAY = 7; const uint8_t ReminderRequest::HOURS_PER_DAY = 24; const uint16_t ReminderRequest::SECONDS_PER_HOUR = 3600; -// For database recovery. -const std::string ReminderRequest::REMINDER_ID = "reminder_id"; -const std::string ReminderRequest::PKG_NAME = "package_name"; -const std::string ReminderRequest::USER_ID = "user_id"; -const std::string ReminderRequest::UID = "uid"; -const std::string ReminderRequest::SYS_APP = "system_app"; -const std::string ReminderRequest::APP_LABEL = "app_label"; -const std::string ReminderRequest::REMINDER_TYPE = "reminder_type"; -const std::string ReminderRequest::REMINDER_TIME = "reminder_time"; -const std::string ReminderRequest::TRIGGER_TIME = "trigger_time"; -const std::string ReminderRequest::RTC_TRIGGER_TIME = "rtc_trigger_time"; -const std::string ReminderRequest::TIME_INTERVAL = "time_interval"; -const std::string ReminderRequest::SNOOZE_TIMES = "snooze_times"; -const std::string ReminderRequest::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; -const std::string ReminderRequest::RING_DURATION = "ring_duration"; -const std::string ReminderRequest::IS_EXPIRED = "is_expired"; -const std::string ReminderRequest::IS_ACTIVE = "is_active"; -const std::string ReminderRequest::STATE = "state"; -const std::string ReminderRequest::ZONE_ID = "zone_id"; -const std::string ReminderRequest::HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; -const std::string ReminderRequest::ACTION_BUTTON_INFO = "button_info"; -const std::string ReminderRequest::CUSTOM_BUTTON_URI = "custom_button_uri"; -const std::string ReminderRequest::SLOT_ID = "slot_id"; -const std::string ReminderRequest::NOTIFICATION_ID = "notification_id"; -const std::string ReminderRequest::TITLE = "title"; -const std::string ReminderRequest::CONTENT = "content"; -const std::string ReminderRequest::SNOOZE_CONTENT = "snooze_content"; -const std::string ReminderRequest::EXPIRED_CONTENT = "expired_content"; -const std::string ReminderRequest::AGENT = "agent"; -const std::string ReminderRequest::MAX_SCREEN_AGENT = "maxScreen_agent"; -const std::string ReminderRequest::TAP_DISMISSED = "tapDismissed"; -const std::string ReminderRequest::AUTO_DELETED_TIME = "autoDeletedTime"; -const std::string ReminderRequest::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; -const std::string ReminderRequest::GROUP_ID = "groupId"; - std::string ReminderRequest::sqlOfAddColumns = ""; std::vector ReminderRequest::columns; @@ -139,6 +105,7 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) this->timeIntervalInMilli_ = other.timeIntervalInMilli_; this->reminderType_ = other.reminderType_; this->slotType_ = other.slotType_; + this->snoozeSlotType_ = other.snoozeSlotType_; this->notificationRequest_ = other.notificationRequest_; this->wantAgentInfo_ = other.wantAgentInfo_; this->maxScreenWantAgentInfo_ = other.maxScreenWantAgentInfo_; @@ -338,8 +305,8 @@ bool ReminderRequest::HandleTimeZoneChange( if (isExpired_) { return false; } - ANSR_LOGD("Handle timezone change, oldZoneTriggerTime:%{public}" PRIu64 "\ - , newZoneTriggerTime:%{public}" PRIu64 "", oldZoneTriggerTime, newZoneTriggerTime); + ANSR_LOGD("Handle timezone change, old:%{public}" PRIu64 ", new:%{public}" PRIu64 "", + oldZoneTriggerTime, newZoneTriggerTime); if (oldZoneTriggerTime == newZoneTriggerTime) { return false; } @@ -495,119 +462,163 @@ int64_t ReminderRequest::RecoverInt64FromDb(const std::shared_ptr &resultSet) +void ReminderRequest::RecoverBasicFromDb(const std::shared_ptr& resultSet) { - if (resultSet == nullptr) { - ANSR_LOGE("ResultSet is null"); - return; - } - // reminderId - ReminderStore::GetInt32Val(resultSet, REMINDER_ID, reminderId_); + ReminderStore::GetInt32Val(resultSet, ReminderTable::REMINDER_ID, reminderId_); // userId - ReminderStore::GetInt32Val(resultSet, USER_ID, userId_); + ReminderStore::GetInt32Val(resultSet, ReminderTable::USER_ID, userId_); // bundleName - ReminderStore::GetStringVal(resultSet, PKG_NAME, bundleName_); + ReminderStore::GetStringVal(resultSet, ReminderTable::PKG_NAME, bundleName_); // uid - ReminderStore::GetInt32Val(resultSet, UID, uid_); + ReminderStore::GetInt32Val(resultSet, ReminderTable::UID, uid_); // isSystemApp std::string isSysApp; - ReminderStore::GetStringVal(resultSet, SYS_APP, isSysApp); + ReminderStore::GetStringVal(resultSet, ReminderTable::SYS_APP, isSysApp); isSystemApp_ = isSysApp == "true" ? true : false; // reminderType int32_t reminderType; - ReminderStore::GetInt32Val(resultSet, REMINDER_TYPE, reminderType); + ReminderStore::GetInt32Val(resultSet, ReminderTable::REMINDER_TYPE, reminderType); reminderType_ = ReminderType(reminderType); // reminderTime reminderTimeInMilli_ = - static_cast(RecoverInt64FromDb(resultSet, REMINDER_TIME, DbRecoveryType::LONG)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::REMINDER_TIME, + DbRecoveryType::LONG)); // triggerTime triggerTimeInMilli_ = - static_cast(RecoverInt64FromDb(resultSet, TRIGGER_TIME, DbRecoveryType::LONG)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::TRIGGER_TIME, + DbRecoveryType::LONG)); // timeInterval uint64_t timeIntervalInSecond = - static_cast(RecoverInt64FromDb(resultSet, TIME_INTERVAL, DbRecoveryType::LONG)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::TIME_INTERVAL, + DbRecoveryType::LONG)); SetTimeInterval(timeIntervalInSecond); // snoozeTimes - snoozeTimes_ = static_cast(RecoverInt64FromDb(resultSet, SNOOZE_TIMES, DbRecoveryType::INT)); + snoozeTimes_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::SNOOZE_TIMES, + DbRecoveryType::INT)); // dynamicSnoozeTimes snoozeTimesDynamic_ = - static_cast(RecoverInt64FromDb(resultSet, DYNAMIC_SNOOZE_TIMES, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::DYNAMIC_SNOOZE_TIMES, + DbRecoveryType::INT)); // ringDuration uint64_t ringDurationInSecond = - static_cast(RecoverInt64FromDb(resultSet, RING_DURATION, DbRecoveryType::LONG)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::RING_DURATION, + DbRecoveryType::LONG)); SetRingDuration(ringDurationInSecond); // isExpired std::string isExpired; - ReminderStore::GetStringVal(resultSet, IS_EXPIRED, isExpired); + ReminderStore::GetStringVal(resultSet, ReminderTable::IS_EXPIRED, + isExpired); isExpired_ = isExpired == "true" ? true : false; // state - state_ = static_cast(RecoverInt64FromDb(resultSet, STATE, DbRecoveryType::INT)); + state_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::STATE, + DbRecoveryType::INT)); // repeatDaysOfWeek_ - repeatDaysOfWeek_ = static_cast(RecoverInt64FromDb(resultSet, REPEAT_DAYS_OF_WEEK, DbRecoveryType::INT)); - + repeatDaysOfWeek_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::REPEAT_DAYS_OF_WEEK, + DbRecoveryType::INT)); + // action buttons RecoverActionButton(resultSet); // slotType int32_t slotType; - ReminderStore::GetInt32Val(resultSet, SLOT_ID, slotType); + ReminderStore::GetInt32Val(resultSet, ReminderTable::SLOT_ID, slotType); slotType_ = NotificationConstant::SlotType(slotType); + // snoozeSlotType + int32_t snoozeSlotType; + ReminderStore::GetInt32Val(resultSet, ReminderTable::SNOOZE_SLOT_ID, snoozeSlotType); + snoozeSlotType_ = NotificationConstant::SlotType(snoozeSlotType); + // notification id - ReminderStore::GetInt32Val(resultSet, NOTIFICATION_ID, notificationId_); + ReminderStore::GetInt32Val(resultSet, ReminderTable::NOTIFICATION_ID, notificationId_); + // title - ReminderStore::GetStringVal(resultSet, TITLE, title_); + ReminderStore::GetStringVal(resultSet, ReminderTable::TITLE, title_); // content - ReminderStore::GetStringVal(resultSet, CONTENT, content_); + ReminderStore::GetStringVal(resultSet, ReminderTable::CONTENT, content_); // snoozeContent - ReminderStore::GetStringVal(resultSet, SNOOZE_CONTENT, snoozeContent_); + ReminderStore::GetStringVal(resultSet, ReminderTable::SNOOZE_CONTENT, snoozeContent_); // expiredContent - ReminderStore::GetStringVal(resultSet, EXPIRED_CONTENT, expiredContent_); + ReminderStore::GetStringVal(resultSet, ReminderTable::EXPIRED_CONTENT, expiredContent_); InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent +} + +void ReminderRequest::RecoverFromDb(const std::shared_ptr &resultSet) +{ + if (resultSet == nullptr) { + ANSR_LOGE("ResultSet is null"); + return; + } + + RecoverBasicFromDb(resultSet); // wantAgent std::string wantAgent; - ReminderStore::GetStringVal(resultSet, AGENT, wantAgent); + ReminderStore::GetStringVal(resultSet, ReminderTable::AGENT, wantAgent); RecoverWantAgent(wantAgent, 0); // maxScreenWantAgent std::string maxScreenWantAgent; - ReminderStore::GetStringVal(resultSet, MAX_SCREEN_AGENT, maxScreenWantAgent); + ReminderStore::GetStringVal(resultSet, ReminderTable::MAX_SCREEN_AGENT, maxScreenWantAgent); RecoverWantAgent(maxScreenWantAgent, 1); // tapDismissed std::string tapDismissed; - ReminderStore::GetStringVal(resultSet, TAP_DISMISSED, tapDismissed); + ReminderStore::GetStringVal(resultSet, ReminderTable::TAP_DISMISSED, tapDismissed); tapDismissed_ = tapDismissed == "true" ? true : false; // autoDeletedTime autoDeletedTime_ = - static_cast(RecoverInt64FromDb(resultSet, AUTO_DELETED_TIME, DbRecoveryType::LONG)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::AUTO_DELETED_TIME, + DbRecoveryType::LONG)); // customButtonUri - ReminderStore::GetStringVal(resultSet, CUSTOM_BUTTON_URI, customButtonUri_); + ReminderStore::GetStringVal(resultSet, ReminderTable::CUSTOM_BUTTON_URI, customButtonUri_); // groupId - ReminderStore::GetStringVal(resultSet, GROUP_ID, groupId_); + ReminderStore::GetStringVal(resultSet, ReminderTable::GROUP_ID, groupId_); +} + +void ReminderRequest::RecoverActionButtonJsonMode(const std::string &jsonString) +{ + nlohmann::json root = nlohmann::json::parse(jsonString); + std::string type = root.at("type").get(); + std::string title = root.at("title").get(); + std::string resource = root.at("resource").get(); + auto buttonWantAgent = std::make_shared(); + if (!root["wantAgent"].empty()) { + nlohmann::json wantAgent = root["wantAgent"]; + buttonWantAgent->pkgName = wantAgent.at("pkgName").get(); + buttonWantAgent->abilityName = wantAgent.at("abilityName").get(); + } + auto buttonDataShareUpdate = std::make_shared(); + if (!root["dataShareUpdate"].empty()) { + nlohmann::json dataShareUpdate = root["dataShareUpdate"]; + buttonDataShareUpdate->uri = dataShareUpdate.at("uri").get(); + buttonDataShareUpdate->equalTo = dataShareUpdate.at("equalTo").get(); + buttonDataShareUpdate->valuesBucket = dataShareUpdate.at("valuesBucket").get(); + } + SetActionButton(title, ActionButtonType(std::stoi(type, nullptr)), + resource, buttonWantAgent, buttonDataShareUpdate); } void ReminderRequest::RecoverActionButton(const std::shared_ptr &resultSet) @@ -617,7 +628,7 @@ void ReminderRequest::RecoverActionButton(const std::shared_ptr multiButton = StringSplit(actionButtonInfo, SEP_BUTTON_MULTI); for (auto button : multiButton) { std::vector singleButton = StringSplit(button, SEP_BUTTON_SINGLE); @@ -627,25 +638,7 @@ void ReminderRequest::RecoverActionButton(const std::shared_ptr(); - std::string title = root.at("title").get(); - std::string resource = root.at("resource").get(); - auto buttonWantAgent = std::make_shared(); - if (!root["wantAgent"].empty()) { - nlohmann::json wantAgent = root["wantAgent"]; - buttonWantAgent->pkgName = wantAgent.at("pkgName").get(); - buttonWantAgent->abilityName = wantAgent.at("abilityName").get(); - } - auto buttonDataShareUpdate = std::make_shared(); - if (!root["dataShareUpdate"].empty()) { - nlohmann::json dataShareUpdate = root["dataShareUpdate"]; - buttonDataShareUpdate->uri = dataShareUpdate.at("uri").get(); - buttonDataShareUpdate->equalTo = dataShareUpdate.at("equalTo").get(); - buttonDataShareUpdate->valuesBucket = dataShareUpdate.at("valuesBucket").get(); - } - SetActionButton(title, ActionButtonType(std::stoi(type, nullptr)), - resource, buttonWantAgent, buttonDataShareUpdate); + RecoverActionButtonJsonMode(jsonString); continue; } // old method Soon to be deleted @@ -748,6 +741,12 @@ ReminderRequest& ReminderRequest::SetSlotType(const NotificationConstant::SlotTy return *this; } +ReminderRequest& ReminderRequest::SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType) +{ + snoozeSlotType_ = snoozeSlotType; + return *this; +} + ReminderRequest& ReminderRequest::SetSnoozeContent(const std::string &snoozeContent) { snoozeContent_ = snoozeContent; @@ -887,6 +886,11 @@ NotificationConstant::SlotType ReminderRequest::GetSlotType() const return slotType_; } +NotificationConstant::SlotType ReminderRequest::GetSnoozeSlotType() const +{ + return snoozeSlotType_; +} + std::string ReminderRequest::GetSnoozeContent() const { return snoozeContent_; @@ -1007,7 +1011,11 @@ void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std switch (type) { case UpdateNotificationType::COMMON: { ANSR_LOGI("UpdateNotification common information"); - UpdateNotificationCommon(); + if (extra == "snooze") { + UpdateNotificationCommon(true); + } else { + UpdateNotificationCommon(false); + } break; } case UpdateNotificationType::REMOVAL_WANT_AGENT: { @@ -1041,6 +1049,39 @@ void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std } } +bool ReminderRequest::MarshallingActionButton(Parcel& parcel) const +{ + // write map + uint64_t actionButtonMapSize = static_cast(actionButtonMap_.size()); + WRITE_UINT64_RETURN_FALSE_LOG(parcel, actionButtonMapSize, "actionButtonMapSize"); + for (auto button : actionButtonMap_) { + uint8_t buttonType = static_cast(button.first); + WRITE_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.title, "buttonTitle"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.resource, "buttonResource"); + + if (button.second.wantAgent == nullptr) { + ANSR_LOGE("button wantAgent is null"); + return false; + } + + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->pkgName, "wantAgent's pkgName"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->abilityName, "wantAgent's abilityName"); + + if (button.second.dataShareUpdate == nullptr) { + ANSR_LOGE("button dataShareUpdate is null"); + return false; + } + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->uri, + "dataShareUpdate's uri"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->equalTo, + "dataShareUpdate's equalTo"); + WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->valuesBucket, + "dataShareUpdate's valuesBucket"); + } + return true; +} + bool ReminderRequest::Marshalling(Parcel &parcel) const { // write string @@ -1082,30 +1123,11 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const int32_t slotType = static_cast(slotType_); WRITE_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); - // write map - uint64_t actionButtonMapSize = static_cast(actionButtonMap_.size()); - WRITE_UINT64_RETURN_FALSE_LOG(parcel, actionButtonMapSize, "actionButtonMapSize"); - for (auto button : actionButtonMap_) { - uint8_t buttonType = static_cast(button.first); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.title, "buttonTitle"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.resource, "buttonResource"); + int32_t snoozeSlotType = static_cast(snoozeSlotType_); + WRITE_INT32_RETURN_FALSE_LOG(parcel, snoozeSlotType, "snoozeSlotType"); - if (button.second.wantAgent == nullptr) { - ANSR_LOGE("button wantAgent is null"); - return false; - } - - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->pkgName, "wantAgent's pkgName"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.wantAgent->abilityName, "wantAgent's abilityName"); - - if (button.second.dataShareUpdate == nullptr) { - ANSR_LOGE("button dataShareUpdate is null"); - return false; - } - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->uri, "dataShareUpdate's uri"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->equalTo, "dataShareUpdate's equalTo"); - WRITE_STRING_RETURN_FALSE_LOG(parcel, button.second.dataShareUpdate->valuesBucket, "dataShareUpdate's valuesBucket"); + if (!MarshallingActionButton(parcel)) { + return false; } return true; } @@ -1124,6 +1146,38 @@ ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel) return objptr; } +bool ReminderRequest::ReadActionButtonFromParcel(Parcel& parcel) +{ + uint64_t buttonMapSize = 0; + READ_UINT64_RETURN_FALSE_LOG(parcel, buttonMapSize, "actionButtonMapSize"); + buttonMapSize = (buttonMapSize < MAX_ACTION_BUTTON_NUM) ? buttonMapSize : MAX_ACTION_BUTTON_NUM; + for (uint64_t i = 0; i < buttonMapSize; i++) { + uint8_t buttonType = static_cast(ActionButtonType::INVALID); + READ_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); + ActionButtonType type = static_cast(buttonType); + std::string title = parcel.ReadString(); + std::string resource = parcel.ReadString(); + std::string pkgName = parcel.ReadString(); + std::string abilityName = parcel.ReadString(); + std::string uri = parcel.ReadString(); + std::string equalTo = parcel.ReadString(); + std::string valuesBucket = parcel.ReadString(); + ActionButtonInfo info; + info.type = type; + info.title = title; + info.resource = resource; + info.wantAgent = std::make_shared(); + info.wantAgent->pkgName = pkgName; + info.wantAgent->abilityName = abilityName; + info.dataShareUpdate = std::make_shared(); + info.dataShareUpdate->uri = uri; + info.dataShareUpdate->equalTo = equalTo; + info.dataShareUpdate->valuesBucket = valuesBucket; + actionButtonMap_.insert(std::pair(type, info)); + } + return true; +} + bool ReminderRequest::ReadFromParcel(Parcel &parcel) { READ_STRING_RETURN_FALSE_LOG(parcel, content_, "content"); @@ -1168,33 +1222,14 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) READ_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); slotType_ = static_cast(slotType); - uint64_t buttonMapSize = 0; - READ_UINT64_RETURN_FALSE_LOG(parcel, buttonMapSize, "actionButtonMapSize"); - buttonMapSize = (buttonMapSize < MAX_ACTION_BUTTON_NUM) ? buttonMapSize : MAX_ACTION_BUTTON_NUM; - for (uint64_t i = 0; i < buttonMapSize; i++) { - uint8_t buttonType = static_cast(ActionButtonType::INVALID); - READ_UINT8_RETURN_FALSE_LOG(parcel, buttonType, "buttonType"); - ActionButtonType type = static_cast(buttonType); - std::string title = parcel.ReadString(); - std::string resource = parcel.ReadString(); - std::string pkgName = parcel.ReadString(); - std::string abilityName = parcel.ReadString(); - std::string uri = parcel.ReadString(); - std::string equalTo = parcel.ReadString(); - std::string valuesBucket = parcel.ReadString(); - ActionButtonInfo info; - info.type = type; - info.title = title; - info.resource = resource; - info.wantAgent = std::make_shared(); - info.wantAgent->pkgName = pkgName; - info.wantAgent->abilityName = abilityName; - info.dataShareUpdate = std::make_shared(); - info.dataShareUpdate->uri = uri; - info.dataShareUpdate->equalTo = equalTo; - info.dataShareUpdate->valuesBucket = valuesBucket; - actionButtonMap_.insert(std::pair(type, info)); + int32_t snoozeSlotType = static_cast(NotificationConstant::SlotType::OTHER); + READ_INT32_RETURN_FALSE_LOG(parcel, snoozeSlotType, "snoozeSlotType"); + snoozeSlotType_ = static_cast(snoozeSlotType); + + if (!ReadActionButtonFromParcel(parcel)) { + return false; } + if (!InitNotificationRequest()) { return false; } @@ -1535,14 +1570,22 @@ bool ReminderRequest::UpdateNextReminder(const bool &force) return result; } -void ReminderRequest::UpdateNotificationCommon() +void ReminderRequest::UpdateNotificationCommon(bool isSnooze) { time_t now; (void)time(&now); // unit is seconds. notificationRequest_->SetDeliveryTime(GetDurationSinceEpochInMilli(now)); notificationRequest_->SetLabel(NOTIFICATION_LABEL); notificationRequest_->SetShowDeliveryTime(true); - notificationRequest_->SetSlotType(slotType_); + if (isSnooze) { + if (snoozeSlotType_ == NotificationConstant::SlotType::OTHER) { + notificationRequest_->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); + } else { + notificationRequest_->SetSlotType(snoozeSlotType_); + } + } else { + notificationRequest_->SetSlotType(slotType_); + } notificationRequest_->SetTapDismissed(tapDismissed_); notificationRequest_->SetAutoDeletedTime(autoDeletedTime_); auto notificationNormalContent = std::make_shared(); @@ -1690,106 +1733,68 @@ int32_t ReminderRequest::GetUserId(const int32_t &uid) return userId; } -void ReminderRequest::AppendValuesBucket(const sptr &reminder, - const sptr &bundleOption, NativeRdb::ValuesBucket &values) +void ReminderRequest::AppendWantAgentValuesBucket(const sptr& reminder, + NativeRdb::ValuesBucket& values) { - values.PutInt(REMINDER_ID, reminder->GetReminderId()); - values.PutString(PKG_NAME, bundleOption->GetBundleName()); - values.PutInt(USER_ID, reminder->GetUserId()); - values.PutInt(UID, reminder->GetUid()); - values.PutString(SYS_APP, reminder->IsSystemApp() ? "true" : "false"); - values.PutString(APP_LABEL, ""); // no use, compatible with old version. - values.PutInt(REMINDER_TYPE, static_cast(reminder->GetReminderType())); - values.PutLong(REMINDER_TIME, reminder->GetReminderTimeInMilli()); - values.PutLong(TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); - values.PutLong( - RTC_TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); // no use, compatible with old version. - values.PutLong(TIME_INTERVAL, reminder->GetTimeInterval()); - values.PutInt(SNOOZE_TIMES, reminder->GetSnoozeTimes()); - values.PutInt(DYNAMIC_SNOOZE_TIMES, reminder->GetSnoozeTimesDynamic()); - values.PutLong(RING_DURATION, reminder->GetRingDuration()); - values.PutString(IS_EXPIRED, reminder->IsExpired() ? "true" : "false"); - values.PutString(IS_ACTIVE, ""); // no use, compatible with old version. - values.PutInt(STATE, reminder->GetState()); - values.PutString(ZONE_ID, ""); // no use, compatible with old version. - values.PutString(HAS_SCHEDULED_TIMEOUT, ""); // no use, compatible with old version. - values.PutString(ACTION_BUTTON_INFO, reminder->GetButtonInfo()); - values.PutString(CUSTOM_BUTTON_URI, reminder->GetCustomButtonUri()); - values.PutInt(SLOT_ID, reminder->GetSlotType()); - values.PutInt(NOTIFICATION_ID, reminder->GetNotificationId()); - values.PutString(TITLE, reminder->GetTitle()); - values.PutString(CONTENT, reminder->GetContent()); - values.PutString(SNOOZE_CONTENT, reminder->GetSnoozeContent()); - values.PutString(EXPIRED_CONTENT, reminder->GetExpiredContent()); - values.PutInt(REPEAT_DAYS_OF_WEEK, reminder->GetRepeatDaysOfWeek()); - values.PutString(GROUP_ID, reminder->GetGroupId()); auto wantAgentInfo = reminder->GetWantAgentInfo(); if (wantAgentInfo == nullptr) { std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null" + ReminderRequest::SEP_WANT_AGENT + "null"; - values.PutString(AGENT, info); + values.PutString(ReminderTable::AGENT, info); } else { std::string info = wantAgentInfo->pkgName + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->abilityName + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->uri; - values.PutString(AGENT, info); + values.PutString(ReminderTable::AGENT, info); } + auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo(); if (maxScreenWantAgentInfo == nullptr) { std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; - values.PutString(MAX_SCREEN_AGENT, info); + values.PutString(ReminderTable::MAX_SCREEN_AGENT, info); } else { - values.PutString(MAX_SCREEN_AGENT, maxScreenWantAgentInfo->pkgName + values.PutString(ReminderTable::MAX_SCREEN_AGENT, maxScreenWantAgentInfo->pkgName + ReminderRequest::SEP_WANT_AGENT + maxScreenWantAgentInfo->abilityName); } - values.PutString(TAP_DISMISSED, reminder->IsTapDismissed() ? "true" : "false"); - values.PutLong(AUTO_DELETED_TIME, reminder->GetAutoDeletedTime()); -} - -void ReminderRequest::InitDbColumns() -{ - 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(SYS_APP, "TEXT 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(CUSTOM_BUTTON_URI, "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); - AddColumn(TAP_DISMISSED, "TEXT", false); - AddColumn(AUTO_DELETED_TIME, "BIGINT", false); - AddColumn(REPEAT_DAYS_OF_WEEK, "INT", false); - AddColumn(GROUP_ID, "TEXT", false); -} - -void ReminderRequest::AddColumn( - const std::string &name, const std::string &type, const bool &isEnd) -{ - columns.push_back(name); - if (!isEnd) { - sqlOfAddColumns += name + " " + type + ", "; - } else { - sqlOfAddColumns += name + " " + type; - } +} + +void ReminderRequest::AppendValuesBucket(const sptr &reminder, + const sptr &bundleOption, NativeRdb::ValuesBucket &values) +{ + values.PutInt(ReminderTable::REMINDER_ID, reminder->GetReminderId()); + values.PutString(ReminderTable::PKG_NAME, bundleOption->GetBundleName()); + values.PutInt(ReminderTable::USER_ID, reminder->GetUserId()); + values.PutInt(ReminderTable::UID, reminder->GetUid()); + values.PutString(ReminderTable::SYS_APP, reminder->IsSystemApp() ? "true" : "false"); + values.PutString(ReminderTable::APP_LABEL, ""); // no use, compatible with old version. + values.PutInt(ReminderTable::REMINDER_TYPE, static_cast(reminder->GetReminderType())); + values.PutLong(ReminderTable::REMINDER_TIME, reminder->GetReminderTimeInMilli()); + values.PutLong(ReminderTable::TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); + values.PutLong( + ReminderTable::RTC_TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); // no use, compatible with old version. + values.PutLong(ReminderTable::TIME_INTERVAL, reminder->GetTimeInterval()); + values.PutInt(ReminderTable::SNOOZE_TIMES, reminder->GetSnoozeTimes()); + values.PutInt(ReminderTable::DYNAMIC_SNOOZE_TIMES, reminder->GetSnoozeTimesDynamic()); + values.PutLong(ReminderTable::RING_DURATION, reminder->GetRingDuration()); + values.PutString(ReminderTable::IS_EXPIRED, reminder->IsExpired() ? "true" : "false"); + values.PutString(ReminderTable::IS_ACTIVE, ""); // no use, compatible with old version. + values.PutInt(ReminderTable::STATE, reminder->GetState()); + values.PutString(ReminderTable::ZONE_ID, ""); // no use, compatible with old version. + values.PutString(ReminderTable::HAS_SCHEDULED_TIMEOUT, ""); // no use, compatible with old version. + values.PutString(ReminderTable::ACTION_BUTTON_INFO, reminder->GetButtonInfo()); + values.PutString(ReminderTable::CUSTOM_BUTTON_URI, reminder->GetCustomButtonUri()); + values.PutInt(ReminderTable::SLOT_ID, reminder->GetSlotType()); + values.PutInt(ReminderTable::SNOOZE_SLOT_ID, reminder->GetSnoozeSlotType()); + values.PutInt(ReminderTable::NOTIFICATION_ID, reminder->GetNotificationId()); + values.PutString(ReminderTable::TITLE, reminder->GetTitle()); + values.PutString(ReminderTable::CONTENT, reminder->GetContent()); + values.PutString(ReminderTable::SNOOZE_CONTENT, reminder->GetSnoozeContent()); + values.PutString(ReminderTable::EXPIRED_CONTENT, reminder->GetExpiredContent()); + values.PutInt(ReminderTable::REPEAT_DAYS_OF_WEEK, reminder->GetRepeatDaysOfWeek()); + values.PutString(ReminderTable::GROUP_ID, reminder->GetGroupId()); + + AppendWantAgentValuesBucket(reminder, values); + + values.PutString(ReminderTable::TAP_DISMISSED, reminder->IsTapDismissed() ? "true" : "false"); + values.PutLong(ReminderTable::AUTO_DELETED_TIME, reminder->GetAutoDeletedTime()); } int64_t ReminderRequest::GetNextDaysOfWeek(const time_t now, const time_t target) const @@ -1904,5 +1909,6 @@ void ReminderRequest::OnLanguageChange(const std::shared_ptr daysOfWeek) : ReminderRequest(ReminderRequest::ReminderType::ALARM) { @@ -203,11 +200,13 @@ void ReminderRequestAlarm::RecoverFromDb(const std::shared_ptr(RecoverInt64FromDb(resultSet, ALARM_HOUR, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::ALARM_HOUR, + DbRecoveryType::INT)); // minute minute_ = - static_cast(RecoverInt64FromDb(resultSet, ALARM_MINUTE, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::ALARM_MINUTE, + DbRecoveryType::INT)); } void ReminderRequestAlarm::AppendValuesBucket(const sptr &reminder, @@ -220,14 +219,9 @@ void ReminderRequestAlarm::AppendValuesBucket(const sptr &remin hour = alarm->GetHour(); minute = alarm->GetMinute(); } - values.PutInt(ALARM_HOUR, hour); - values.PutInt(ALARM_MINUTE, minute); + values.PutInt(ReminderTable::ALARM_HOUR, hour); + values.PutInt(ReminderTable::ALARM_MINUTE, minute); } -void ReminderRequestAlarm::InitDbColumns() -{ - ReminderRequest::AddColumn(ALARM_HOUR, "INT", false); - ReminderRequest::AddColumn(ALARM_MINUTE, "INT", true); -} } } \ No newline at end of file diff --git a/frameworks/ans/src/reminder_request_calendar.cpp b/frameworks/ans/src/reminder_request_calendar.cpp index 4f6a3bbba..6aedbd1cb 100644 --- a/frameworks/ans/src/reminder_request_calendar.cpp +++ b/frameworks/ans/src/reminder_request_calendar.cpp @@ -15,6 +15,7 @@ #include "reminder_request_calendar.h" +#include "reminder_table.h" #include "ans_log_wrapper.h" namespace OHOS { @@ -25,18 +26,6 @@ const uint8_t ReminderRequestCalendar::JANUARY = 1; const uint8_t ReminderRequestCalendar::DECEMBER = 12; const uint8_t ReminderRequestCalendar::DEFAULT_SNOOZE_TIMES = 3; -// For database recovery. -const std::string ReminderRequestCalendar::REPEAT_DAYS = "repeat_days"; -const std::string ReminderRequestCalendar::REPEAT_MONTHS = "repeat_months"; -const std::string ReminderRequestCalendar::FIRST_DESIGNATE_YEAR = "first_designate_year"; -const std::string ReminderRequestCalendar::FIRST_DESIGNATE_MONTH = "first_designate_month"; -const std::string ReminderRequestCalendar::FIRST_DESIGNATE_DAY = "first_designate_day"; -const std::string ReminderRequestCalendar::CALENDAR_YEAR = "calendar_year"; -const std::string ReminderRequestCalendar::CALENDAR_MONTH = "calendar_month"; -const std::string ReminderRequestCalendar::CALENDAR_DAY = "calendar_day"; -const std::string ReminderRequestCalendar::CALENDAR_HOUR = "calendar_hour"; -const std::string ReminderRequestCalendar::CALENDAR_MINUTE = "calendar_minute"; - const uint8_t ReminderRequestCalendar::DAY_ARRAY[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const uint8_t ReminderRequestCalendar::FEBRUARY = 2; const uint8_t ReminderRequestCalendar::LEAP_MONTH = 29; @@ -466,38 +455,48 @@ void ReminderRequestCalendar::RecoverFromDb(const std::shared_ptr(RecoverInt64FromDb(resultSet, REPEAT_DAYS, DbRecoveryType::INT)); + repeatDay_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::REPEAT_DAYS, + DbRecoveryType::INT)); // repeatMonth repeatMonth_ = - static_cast(RecoverInt64FromDb(resultSet, REPEAT_MONTHS, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::REPEAT_MONTHS, + DbRecoveryType::INT)); // firstDesignateYear firstDesignateYear_ = - static_cast(RecoverInt64FromDb(resultSet, FIRST_DESIGNATE_YEAR, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_YEAR, + DbRecoveryType::INT)); // firstDesignateMonth firstDesignateMonth_ = - static_cast(RecoverInt64FromDb(resultSet, FIRST_DESIGNATE_MONTH, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_MONTH, + DbRecoveryType::INT)); // firstDesignateDay firstDesignateDay_ = - static_cast(RecoverInt64FromDb(resultSet, FIRST_DESIGNATE_DAY, DbRecoveryType::INT)); + static_cast(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_DAY, + DbRecoveryType::INT)); // year - year_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_YEAR, DbRecoveryType::INT)); + year_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_YEAR, + DbRecoveryType::INT)); // month - month_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_MONTH, DbRecoveryType::INT)); + month_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_MONTH, + DbRecoveryType::INT)); // day - day_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_DAY, DbRecoveryType::INT)); + day_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_DAY, + DbRecoveryType::INT)); // hour - hour_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_HOUR, DbRecoveryType::INT)); + hour_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_HOUR, + DbRecoveryType::INT)); // minute - minute_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_MINUTE, DbRecoveryType::INT)); + minute_ = static_cast(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_MINUTE, + DbRecoveryType::INT)); } void ReminderRequestCalendar::AppendValuesBucket(const sptr &reminder, @@ -528,30 +527,17 @@ void ReminderRequestCalendar::AppendValuesBucket(const sptr &re minute = calendar->GetMinute(); } } - values.PutInt(REPEAT_DAYS, repeatDay); - values.PutInt(REPEAT_MONTHS, repeatMonth); - values.PutInt(FIRST_DESIGNATE_YEAR, firstDesignateYear); - values.PutInt(FIRST_DESIGNATE_MONTH, firstDesignateMonth); - values.PutInt(FIRST_DESIGNATE_DAY, firstDesignateDay); - values.PutInt(CALENDAR_YEAR, year); - values.PutInt(CALENDAR_MONTH, month); - values.PutInt(CALENDAR_DAY, day); - values.PutInt(CALENDAR_HOUR, hour); - values.PutInt(CALENDAR_MINUTE, minute); + values.PutInt(ReminderTable::REPEAT_DAYS, repeatDay); + values.PutInt(ReminderTable::REPEAT_MONTHS, repeatMonth); + values.PutInt(ReminderTable::FIRST_DESIGNATE_YEAR, firstDesignateYear); + values.PutInt(ReminderTable::FIRST_DESIGNATE_MONTH, firstDesignateMonth); + values.PutInt(ReminderTable::FIRST_DESIGNATE_DAY, firstDesignateDay); + values.PutInt(ReminderTable::CALENDAR_YEAR, year); + values.PutInt(ReminderTable::CALENDAR_MONTH, month); + values.PutInt(ReminderTable::CALENDAR_DAY, day); + values.PutInt(ReminderTable::CALENDAR_HOUR, hour); + values.PutInt(ReminderTable::CALENDAR_MINUTE, minute); } -void ReminderRequestCalendar::InitDbColumns() -{ - ReminderRequest::AddColumn(REPEAT_DAYS, "INT", false); - ReminderRequest::AddColumn(REPEAT_MONTHS, "INT", false); - ReminderRequest::AddColumn(FIRST_DESIGNATE_YEAR, "INT", false); - ReminderRequest::AddColumn(FIRST_DESIGNATE_MONTH, "INT", false); - ReminderRequest::AddColumn(FIRST_DESIGNATE_DAY, "INT", false); - ReminderRequest::AddColumn(CALENDAR_YEAR, "INT", false); - ReminderRequest::AddColumn(CALENDAR_MONTH, "INT", false); - ReminderRequest::AddColumn(CALENDAR_DAY, "INT", false); - ReminderRequest::AddColumn(CALENDAR_HOUR, "INT", false); - ReminderRequest::AddColumn(CALENDAR_MINUTE, "INT", false); -} } } diff --git a/frameworks/ans/src/reminder_request_timer.cpp b/frameworks/ans/src/reminder_request_timer.cpp index e8827184a..67bbe1362 100644 --- a/frameworks/ans/src/reminder_request_timer.cpp +++ b/frameworks/ans/src/reminder_request_timer.cpp @@ -94,6 +94,7 @@ void ReminderRequestTimer::UpdateTimeInfo(const std::string &description) if (IsExpired()) { return; } + ANSR_LOGD("%{public}s, update countdown time trigger time", description.c_str()); time_t now; (void)time(&now); // unit is seconds. @@ -147,5 +148,6 @@ bool ReminderRequestTimer::ReadFromParcel(Parcel &parcel) } return false; } + } } diff --git a/frameworks/ans/src/reminder_store.cpp b/frameworks/ans/src/reminder_store.cpp index 93b0486a5..3716609d7 100644 --- a/frameworks/ans/src/reminder_store.cpp +++ b/frameworks/ans/src/reminder_store.cpp @@ -22,6 +22,7 @@ #include "ability_context.h" #include "ans_log_wrapper.h" +#include "reminder_table.h" #include "reminder_request_alarm.h" #include "reminder_request_calendar.h" #include "reminder_request_timer.h" @@ -29,9 +30,10 @@ namespace OHOS { namespace Notification { namespace { -const uint32_t REMINDER_RDB_VERSION = 2; +const int32_t REMINDER_RDB_VERSION_V1 = 1; +const int32_t REMINDER_RDB_VERSION_V2 = 2; +const uint32_t REMINDER_RDB_VERSION = 3; const int32_t STATE_FAIL = -1; -std::vector columns; std::string g_sqlColumns; } @@ -44,7 +46,7 @@ int32_t ReminderStore::ReminderStoreDataCallBack::OnCreate(NativeRdb::RdbStore & { ANSR_LOGD("Create table."); std::string CREATE_REMINDER_TABLE = "CREATE TABLE IF NOT EXISTS " + REMINDER_DB_TABLE + " (" - + ReminderRequest::sqlOfAddColumns + ")"; + + ReminderTable::sqlOfAddColumns + ")"; ANSR_LOGD("CreateTable:%{public}s", CREATE_REMINDER_TABLE.c_str()); return store.ExecuteSql(CREATE_REMINDER_TABLE); } @@ -54,7 +56,14 @@ int32_t ReminderStore::ReminderStoreDataCallBack::OnUpgrade( { ANSR_LOGI("OnUpgrade oldVersion is %{public}d, newVersion is %{public}d", oldVersion, newVersion); if (oldVersion < newVersion && newVersion == REMINDER_RDB_VERSION) { - store.ExecuteSql("ALTER TABLE " + REMINDER_DB_TABLE + " ADD groupId TEXT DEFAULT '';"); + if (oldVersion == REMINDER_RDB_VERSION_V1) { + AddRdbColum(store, "groupId", "TEXT"); + AddRdbColum(store, "custom_ring_uri", "TEXT"); + AddRdbColum(store, "snooze_slot_id", "INT"); + } else if (oldVersion == REMINDER_RDB_VERSION_V2) { + AddRdbColum(store, "custom_ring_uri", "TEXT"); + AddRdbColum(store, "snooze_slot_id", "INT"); + } } store.SetVersion(newVersion); return NativeRdb::E_OK; @@ -73,12 +82,10 @@ int32_t ReminderStore::Init() } } - ReminderRequest::InitDbColumns(); - ReminderRequestCalendar::InitDbColumns(); - ReminderRequestAlarm::InitDbColumns(); - columns.insert(columns.begin(), - ReminderRequest::columns.begin(), ReminderRequest::columns.end()); - for (std::vector::const_iterator it = columns.begin(); it != columns.end(); ++it) { + ReminderTable::InitDbColumns(); + for (std::vector::const_iterator it = ReminderTable::columns.begin(); + it != ReminderTable::columns.end(); + ++it) { g_sqlColumns += *it + ","; } g_sqlColumns = g_sqlColumns.substr(0, g_sqlColumns.size() - 1); @@ -103,12 +110,12 @@ int32_t ReminderStore::InitData() ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } - std::string deleteCondition = ReminderRequest::IS_EXPIRED + " is true"; + std::string deleteCondition = ReminderTable::IS_EXPIRED + " is true"; ReminderStore::Delete(deleteCondition); int32_t statusChangedRows = STATE_FAIL; NativeRdb::ValuesBucket statusValues; - statusValues.PutInt(ReminderRequest::STATE, ReminderRequest::REMINDER_STATUS_INACTIVE); + statusValues.PutInt(ReminderTable::STATE, ReminderRequest::REMINDER_STATUS_INACTIVE); int32_t statusResult = rdbStore_->Update(statusChangedRows, REMINDER_DB_TABLE, statusValues); ANSR_LOGD("Change status to inactive, changed rows: %{public}d.", statusChangedRows); if (statusResult != NativeRdb::E_OK) { @@ -118,8 +125,8 @@ int32_t ReminderStore::InitData() int32_t activeChangedRows = STATE_FAIL; NativeRdb::ValuesBucket activeValues; - activeValues.PutString(ReminderRequest::IS_ACTIVE, "false"); - std::string activeUpdateCondition = ReminderRequest::IS_ACTIVE + " is true"; + activeValues.PutString(ReminderTable::IS_ACTIVE, "false"); + std::string activeUpdateCondition = ReminderTable::IS_ACTIVE + " is true"; std::vector activeWhereArgs; int32_t activeResult = rdbStore_->Update( activeChangedRows, REMINDER_DB_TABLE, activeValues, activeUpdateCondition, activeWhereArgs); @@ -131,8 +138,8 @@ int32_t ReminderStore::InitData() int32_t scheduledChangedRows = STATE_FAIL; NativeRdb::ValuesBucket scheduledValues; - scheduledValues.PutString(ReminderRequest::HAS_SCHEDULED_TIMEOUT, "false"); - std::string scheduledUpdateCondition = ReminderRequest::HAS_SCHEDULED_TIMEOUT + " is true"; + scheduledValues.PutString(ReminderTable::HAS_SCHEDULED_TIMEOUT, "false"); + std::string scheduledUpdateCondition = ReminderTable::HAS_SCHEDULED_TIMEOUT + " is true"; std::vector scheduledWhereArgs; int32_t scheduledResult = rdbStore_->Update( scheduledChangedRows, REMINDER_DB_TABLE, scheduledValues, scheduledUpdateCondition, scheduledWhereArgs); @@ -146,21 +153,21 @@ int32_t ReminderStore::InitData() int32_t ReminderStore::Delete(int32_t reminderId) { - std::string deleteCondition = ReminderRequest::REMINDER_ID + std::string deleteCondition = ReminderTable ::REMINDER_ID + " = " + std::to_string(reminderId); return ReminderStore::Delete(deleteCondition); } int32_t ReminderStore::DeleteUser(int32_t userId) { - std::string deleteCondition = ReminderRequest::USER_ID + " = " + std::to_string(userId); + std::string deleteCondition = ReminderTable::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::PKG_NAME + " = \"" + pkg + "\" and " - + ReminderRequest::USER_ID + " = " + std::to_string(userId); + std::string deleteCondition = ReminderTable::PKG_NAME + " = \"" + pkg + "\" and " + + ReminderTable::USER_ID + " = " + std::to_string(userId); return ReminderStore::Delete(deleteCondition); } @@ -236,7 +243,7 @@ int64_t ReminderStore::Update( int32_t changedRows = STATE_FAIL; NativeRdb::ValuesBucket values; ReminderStore::GenerateData(reminder, bundleOption, values); - std::string updateCondition = ReminderRequest::REMINDER_ID + std::string updateCondition = ReminderTable::REMINDER_ID + " = " + std::to_string(reminder->GetReminderId()); std::vector whereArgs; int32_t result = rdbStore_->Update(changedRows, REMINDER_DB_TABLE, values, updateCondition, whereArgs); @@ -253,7 +260,7 @@ int64_t ReminderStore::Update( bool ReminderStore::IsReminderExist(const sptr &reminder) { NativeRdb::AbsRdbPredicates absRdbPredicates(REMINDER_DB_TABLE); - absRdbPredicates.EqualTo(ReminderRequest::REMINDER_ID, std::to_string(reminder->GetReminderId())); + absRdbPredicates.EqualTo(ReminderTable::REMINDER_ID, std::to_string(reminder->GetReminderId())); auto queryResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (queryResultSet == nullptr) { ANSR_LOGE("QueryResultSet is null."); @@ -284,9 +291,9 @@ int32_t ReminderStore::GetMaxId() ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } - std::string queryCondition = "select " + ReminderRequest::REMINDER_ID + std::string queryCondition = "select " + ReminderTable::REMINDER_ID + " from " + REMINDER_DB_TABLE + " order by " - + ReminderRequest::REMINDER_ID + " desc"; + + ReminderTable::REMINDER_ID + " desc"; auto queryResultSet = ReminderStore::Query(queryCondition); if (queryResultSet == nullptr) { ANSR_LOGE("QueryResultSet is null."); @@ -310,12 +317,11 @@ int32_t ReminderStore::GetMaxId() std::vector> ReminderStore::GetAllValidReminders() { - std::string queryCondition = "select " + g_sqlColumns + " from " + REMINDER_DB_TABLE + " where " - + ReminderRequest::IS_EXPIRED + " is false order by " - + ReminderRequest::TRIGGER_TIME + " asc"; - ANSR_LOGD("Get all reminders"); - ANSR_LOGD("ReminderStore GetAllValidReminders queryCondition =%{public}s", queryCondition.c_str()); - return GetReminders(queryCondition); + std::string sql = "select " + g_sqlColumns + " from " + REMINDER_DB_TABLE + " where " + + ReminderTable::IS_EXPIRED + " = 'false' order by " + + ReminderTable::TRIGGER_TIME + " asc"; + ANSR_LOGD("GetAllValidReminders sql =%{public}s", sql.c_str()); + return GetReminders(sql); } std::vector> ReminderStore::GetReminders(const std::string &queryCondition) @@ -347,8 +353,8 @@ sptr ReminderStore::BuildReminder(const std::shared_ptr reminder = nullptr; switch (reminderType) { @@ -385,7 +391,7 @@ bool ReminderStore::GetBundleOption(const int32_t &reminderId, sptr queryResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (queryResultSet == nullptr) { @@ -398,9 +404,9 @@ bool ReminderStore::GetBundleOption(const int32_t &reminderId, sptrGoToNextRow(); std::string pkgName; - GetStringVal(queryResultSet, ReminderRequest::PKG_NAME, pkgName); + GetStringVal(queryResultSet, ReminderTable ::PKG_NAME, pkgName); int32_t uid; - GetInt32Val(queryResultSet, ReminderRequest::UID, uid); + GetInt32Val(queryResultSet, ReminderTable::UID, uid); bundleOption->SetBundleName(pkgName); bundleOption->SetUid(uid); return true; @@ -449,5 +455,21 @@ void ReminderStore::GenerateData(const sptr &reminder, ReminderRequestCalendar::AppendValuesBucket(reminder, bundleOption, values); ReminderRequestAlarm::AppendValuesBucket(reminder, bundleOption, values); } + +void ReminderStore::AddRdbColum(NativeRdb::RdbStore &store, const std::string &columName, const std::string &type) +{ + std::string sqlStr = ""; + if (type == "TEXT") { + sqlStr = "ALTER TABLE " + REMINDER_DB_TABLE + " ADD " + columName + " " + type + " DEFAULT '';"; + } else if (type == "INT") { + //3 is meaning others + sqlStr = "ALTER TABLE " + REMINDER_DB_TABLE + " ADD " + columName + " " + type + " DEFAULT 3;"; + } + ANSR_LOGD("AddRdbColum sqlStr = %{public}s", sqlStr.c_str()); + int errorCode = store.ExecuteSql(sqlStr); + if (errorCode != NativeRdb::E_OK) { + ANSR_LOGE("AddRdbColum error,errorCode is = %{public}d", errorCode); + }; +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/src/reminder_table.cpp b/frameworks/ans/src/reminder_table.cpp new file mode 100644 index 000000000..1a42c2789 --- /dev/null +++ b/frameworks/ans/src/reminder_table.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "reminder_table.h" + +namespace OHOS { +namespace Notification { +// Reminder Table Basic Columns. +const std::string ReminderTable::REMINDER_ID = "reminder_id"; +const std::string ReminderTable::PKG_NAME = "package_name"; +const std::string ReminderTable::USER_ID = "user_id"; +const std::string ReminderTable::UID = "uid"; +const std::string ReminderTable::SYS_APP = "system_app"; +const std::string ReminderTable::APP_LABEL = "app_label"; +const std::string ReminderTable::REMINDER_TYPE = "reminder_type"; +const std::string ReminderTable::REMINDER_TIME = "reminder_time"; +const std::string ReminderTable::TRIGGER_TIME = "trigger_time"; +const std::string ReminderTable::RTC_TRIGGER_TIME = "rtc_trigger_time"; +const std::string ReminderTable::TIME_INTERVAL = "time_interval"; +const std::string ReminderTable::SNOOZE_TIMES = "snooze_times"; +const std::string ReminderTable::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; +const std::string ReminderTable::RING_DURATION = "ring_duration"; +const std::string ReminderTable::IS_EXPIRED = "is_expired"; +const std::string ReminderTable::IS_ACTIVE = "is_active"; +const std::string ReminderTable::STATE = "state"; +const std::string ReminderTable::ZONE_ID = "zone_id"; +const std::string ReminderTable::HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; +const std::string ReminderTable::ACTION_BUTTON_INFO = "button_info"; +const std::string ReminderTable::CUSTOM_BUTTON_URI = "custom_button_uri"; +const std::string ReminderTable::SLOT_ID = "slot_id"; +const std::string ReminderTable::SNOOZE_SLOT_ID = "snooze_slot_id"; +const std::string ReminderTable::NOTIFICATION_ID = "notification_id"; +const std::string ReminderTable::TITLE = "title"; +const std::string ReminderTable::CONTENT = "content"; +const std::string ReminderTable::SNOOZE_CONTENT = "snooze_content"; +const std::string ReminderTable::EXPIRED_CONTENT = "expired_content"; +const std::string ReminderTable::AGENT = "agent"; +const std::string ReminderTable::MAX_SCREEN_AGENT = "maxScreen_agent"; +const std::string ReminderTable::TAP_DISMISSED = "tapDismissed"; +const std::string ReminderTable::AUTO_DELETED_TIME = "autoDeletedTime"; +const std::string ReminderTable::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; +const std::string ReminderTable::GROUP_ID = "groupId"; + +// Reminder Table Calendar Columns. +const std::string ReminderTable::REPEAT_DAYS = "repeat_days"; +const std::string ReminderTable::REPEAT_MONTHS = "repeat_months"; +const std::string ReminderTable::FIRST_DESIGNATE_YEAR = "first_designate_year"; +const std::string ReminderTable::FIRST_DESIGNATE_MONTH = "first_designate_month"; +const std::string ReminderTable::FIRST_DESIGNATE_DAY = "first_designate_day"; +const std::string ReminderTable::CALENDAR_YEAR = "calendar_year"; +const std::string ReminderTable::CALENDAR_MONTH = "calendar_month"; +const std::string ReminderTable::CALENDAR_DAY = "calendar_day"; +const std::string ReminderTable::CALENDAR_HOUR = "calendar_hour"; +const std::string ReminderTable::CALENDAR_MINUTE = "calendar_minute"; + +// Reminder Table Alarm Columns. +const std::string ReminderTable::ALARM_HOUR = "alarm_hour"; +const std::string ReminderTable::ALARM_MINUTE = "alarm_minute"; + +std::string ReminderTable::sqlOfAddColumns = ""; +std::vector ReminderTable::columns; + +void ReminderTable::InitDbColumns() +{ + InitBasicColumns(); + InitCalendarColumns(); + InitAlarmColumns(); +} + +void ReminderTable::InitBasicColumns() +{ + AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY"); + AddColumn(PKG_NAME, "TEXT NOT NULL"); + AddColumn(USER_ID, "INT NOT NULL"); + AddColumn(UID, "INT NOT NULL"); + AddColumn(SYS_APP, "TEXT NOT NULL"); + AddColumn(APP_LABEL, "TEXT"); + AddColumn(REMINDER_TYPE, "INT NOT NULL"); + AddColumn(REMINDER_TIME, "BIGINT NOT NULL"); + AddColumn(TRIGGER_TIME, "BIGINT NOT NULL"); + AddColumn(RTC_TRIGGER_TIME, "BIGINT NOT NULL"); + AddColumn(TIME_INTERVAL, "BIGINT NOT NULL"); + AddColumn(SNOOZE_TIMES, "INT NOT NULL"); + AddColumn(DYNAMIC_SNOOZE_TIMES, "INT NOT NULL"); + AddColumn(RING_DURATION, "BIGINT NOT NULL"); + AddColumn(IS_EXPIRED, "TEXT NOT NULL"); + AddColumn(IS_ACTIVE, "TEXT NOT NULL"); + AddColumn(STATE, "INT NOT NULL"); + AddColumn(ZONE_ID, "TEXT"); + AddColumn(HAS_SCHEDULED_TIMEOUT, "TEXT"); + AddColumn(ACTION_BUTTON_INFO, "TEXT"); + AddColumn(CUSTOM_BUTTON_URI, "TEXT"); + AddColumn(SLOT_ID, "INT"); + AddColumn(SNOOZE_SLOT_ID, "INT"); + AddColumn(NOTIFICATION_ID, "INT NOT NULL"); + AddColumn(TITLE, "TEXT"); + AddColumn(CONTENT, "TEXT"); + AddColumn(SNOOZE_CONTENT, "TEXT"); + AddColumn(EXPIRED_CONTENT, "TEXT"); + AddColumn(AGENT, "TEXT"); + AddColumn(MAX_SCREEN_AGENT, "TEXT"); + AddColumn(TAP_DISMISSED, "TEXT"); + AddColumn(AUTO_DELETED_TIME, "BIGINT"); + AddColumn(REPEAT_DAYS_OF_WEEK, "INT"); + AddColumn(GROUP_ID, "TEXT"); +} + +void ReminderTable::InitCalendarColumns() +{ + AddColumn(REPEAT_DAYS, "INT"); + AddColumn(REPEAT_MONTHS, "INT"); + AddColumn(FIRST_DESIGNATE_YEAR, "INT"); + AddColumn(FIRST_DESIGNATE_MONTH, "INT"); + AddColumn(FIRST_DESIGNATE_DAY, "INT"); + AddColumn(CALENDAR_YEAR, "INT"); + AddColumn(CALENDAR_MONTH, "INT"); + AddColumn(CALENDAR_DAY, "INT"); + AddColumn(CALENDAR_HOUR, "INT"); + AddColumn(CALENDAR_MINUTE, "INT"); +} + +void ReminderTable::InitAlarmColumns() +{ + AddColumn(ALARM_HOUR, "INT"); + AddColumn(ALARM_MINUTE, "INT", true); +} + +void ReminderTable ::AddColumn( + const std::string& name, const std::string& type, bool isEnd) +{ + columns.push_back(name); + if (!isEnd) { + sqlOfAddColumns += name + " " + type + ", "; + } else { + sqlOfAddColumns += name + " " + type; + } +} + +} +} \ No newline at end of file diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index 80f902f98..240088a8a 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -39,6 +39,8 @@ ohos_unittest("ans_reminder_unit_test") { "${frameworks_module_ans_path}/test/unittest/notification_do_not_disturb_date_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_flags_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_helper_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_local_live_view_button_test.cpp", + "${frameworks_module_ans_path}/test/unittest/notification_local_live_view_content_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_long_text_content_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_media_content_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_multiline_content_test.cpp", diff --git a/frameworks/ans/test/unittest/notification_bundle_option_test.cpp b/frameworks/ans/test/unittest/notification_bundle_option_test.cpp index 7139936f3..5adbb7e27 100644 --- a/frameworks/ans/test/unittest/notification_bundle_option_test.cpp +++ b/frameworks/ans/test/unittest/notification_bundle_option_test.cpp @@ -131,5 +131,23 @@ HWTEST_F(NotificationBundleOptionTest, ReadFromParcel_00001, Function | SmallTes auto rrc = std::make_shared(bundleName, uid); EXPECT_EQ(rrc->ReadFromParcel(parcel), false); } + +/** + * @tc.name: JsonConvert_00001 + * @tc.desc: Test json convert + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationBundleOptionTest, JsonConvert_00001, Function | SmallTest | Level1) +{ + std::string bundleName = "BundleName"; + int32_t uid = 10; + auto rrc = std::make_shared(bundleName, uid); + nlohmann::json jsonObject; + EXPECT_TRUE(rrc->ToJson(jsonObject)); + auto *rrcNew = rrc->FromJson(jsonObject); + EXPECT_EQ(rrcNew->GetBundleName(), rrc->GetBundleName()); + EXPECT_EQ(rrcNew->GetUid(), rrc->GetUid()); } -} \ No newline at end of file +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/test/unittest/notification_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp index 0edf9670f..4075e9123 100644 --- a/frameworks/ans/test/unittest/notification_helper_test.cpp +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -982,8 +982,9 @@ HWTEST_F(NotificationHelperTest, SetEnabledForBundleSlot_00001, Function | Small NotificationBundleOption bundleOption; NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; bool enabled = true; + bool isForceControl = false; NotificationHelper notificationHelper; - ErrCode ret = notificationHelper.SetEnabledForBundleSlot(bundleOption, slotType, enabled); + ErrCode ret = notificationHelper.SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); } diff --git a/frameworks/ans/test/unittest/notification_local_live_view_button_test.cpp b/frameworks/ans/test/unittest/notification_local_live_view_button_test.cpp new file mode 100644 index 000000000..78c7433d6 --- /dev/null +++ b/frameworks/ans/test/unittest/notification_local_live_view_button_test.cpp @@ -0,0 +1,142 @@ +/* + * 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 +#include +#include +#include "notification_local_live_view_button.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationLocalLiveViewButtonTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: AddSingleButtonName_00001 + * @tc.desc: Test buttonNames_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, AddSingleButtonName_00001, Function | SmallTest | Level1) +{ + std::string buttonName = "testOneButton"; + auto rrc = std::make_shared(); + rrc->addSingleButtonName(buttonName); + EXPECT_EQ(rrc->GetAllButtonNames()[0], buttonName); +} + +/** + * @tc.name: AddSingleButtonName_00002 + * @tc.desc: Test buttonNames_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, AddSingleButtonName_00002, Function | SmallTest | Level1) +{ + std::string buttonName = "testOneButton"; + auto rrc = std::make_shared(); + rrc->addSingleButtonName(buttonName); + EXPECT_EQ(rrc->GetAllButtonNames().size(), 1); +} + +/** + * @tc.name: AddSingleButtonName_00003 + * @tc.desc: Test buttonNames_ parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, AddSingleButtonName_00003, Function | SmallTest | Level1) +{ + std::string buttonNameOne = "testOneButton"; + std::string buttonNameTwo = "testTwoButton"; + std::string buttonNameThree = "testThreeButton"; + std::string buttonNameFour = "testFourButton"; + auto rrc = std::make_shared(); + rrc->addSingleButtonName(buttonNameOne); + rrc->addSingleButtonName(buttonNameTwo); + rrc->addSingleButtonName(buttonNameThree); + rrc->addSingleButtonName(buttonNameFour); + EXPECT_EQ(rrc->GetAllButtonNames().size(), 3); +} + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: FromJson_00001 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, FromJson_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + nlohmann::json jsonObject = nlohmann::json{"test"}; + EXPECT_EQ(jsonObject.is_object(), false); + EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewButtonTest, Unmarshalling_00001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + std::shared_ptr result = + std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, true); +} +} +} diff --git a/frameworks/ans/test/unittest/notification_local_live_view_content_test.cpp b/frameworks/ans/test/unittest/notification_local_live_view_content_test.cpp new file mode 100644 index 000000000..06771268e --- /dev/null +++ b/frameworks/ans/test/unittest/notification_local_live_view_content_test.cpp @@ -0,0 +1,123 @@ +/* + * 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 +#include "notification_local_live_view_content.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationLocalLiveViewContentTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() {} + void TearDown() {} +}; + +/** + * @tc.name: SetTypeCode_00001 + * @tc.desc: Test SetTypeCode parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, SetTypeCode_00001, Function | SmallTest | Level1) +{ + int32_t typeCode = 1; + auto rrc = std::make_shared(); + rrc->SetType(typeCode); + EXPECT_EQ(rrc->GetType(), typeCode); +} + + +/** + * @tc.name: ToJson_00001 + * @tc.desc: Test ToJson parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewContentTest, ToJson_00001, Function | SmallTest | Level1) +{ + nlohmann::json jsonObject; + auto rrc = std::make_shared(); + rrc->FromJson(jsonObject); + EXPECT_EQ(rrc->ToJson(jsonObject), true); +} + +/** + * @tc.name: FromJson_00001 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + nlohmann::json jsonObject = nlohmann::json{"typeCode", "capsule", "button", "progress", "time"}; + rrc->FromJson(jsonObject); + EXPECT_EQ(jsonObject.is_object(), false); + EXPECT_EQ(rrc->FromJson(jsonObject), NULL); +} + +/** + * @tc.name: Marshalling_00001 + * @tc.desc: Test Marshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewContentTest, Marshalling_00001, Function | SmallTest | Level1) +{ + Parcel parcel; + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->Marshalling(parcel), true); +} + +/** + * @tc.name: Unmarshalling_00001 + * @tc.desc: Test Unmarshalling parameters. + * @tc.type: FUNC + * @tc.require: issueI5WBBH + */ +HWTEST_F(NotificationLocalLiveViewContentTest, Unmarshalling_00001, Function | SmallTest | Level1) +{ + bool unmarshalling = true; + Parcel parcel; + auto result = std::make_shared(); + + if (nullptr != result) { + if (nullptr == result->Unmarshalling(parcel)) { + unmarshalling = false; + } + } + EXPECT_EQ(unmarshalling, false); +} + +/** + * @tc.name: FromJson_00002 + * @tc.desc: Test FromJson parameters. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationLocalLiveViewContentTest, FromJson_00002, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + nlohmann::json jsonObject = nlohmann::json{ + {"longText", "test"}, + {"expandedTitle", "test"}, + {"briefText", "test"}}; + EXPECT_NE(rrc->FromJson(jsonObject), nullptr); +} +} +} diff --git a/frameworks/ans/test/unittest/notification_test.cpp b/frameworks/ans/test/unittest/notification_test.cpp index 72362ed60..dd5424be9 100644 --- a/frameworks/ans/test/unittest/notification_test.cpp +++ b/frameworks/ans/test/unittest/notification_test.cpp @@ -270,12 +270,13 @@ HWTEST_F(NotificationTest, Dump_00001, Function | SmallTest | Level1) "inProgress = false, groupOverview = false, isRemoveAllowed = true, progressIndeterminate = false, " "unremovable = false, floatingIcon = false, onlyLocal = false, permitted = true, " "isAgent = false, removalWantAgent = null, maxScreenWantAgent = null, additionalParams = null, " - "littleIcon = null, bigIcon = null, notificationContent = null, " + "littleIcon = null, bigIcon = null, overlayIcon = null, notificationContent = null, " "notificationTemplate = null, actionButtons = empty, messageUsers = empty, " "userInputHistory = empty, distributedOptions = NotificationDistributedOptions" "{ isDistributed = true, devicesSupportDisplay = [], devicesSupportOperate = [] }, " - "notificationFlags = null, creatorUserId = -1, ownerUserId = -1, receiverUserId = -1 }, " - "postTime = 0, sound = nullptr, vibrationStyle = [] }"; + "notificationFlags = null, creatorUserId = -1, ownerUserId = -1, receiverUserId = -1, " + "maxUpdateTime = 0, maxFinishTime = 0 }, postTime = 0, sound = nullptr, vibrationStyle = [], " + "updateTimer = 0, finishTimer = 0, archiveTimer = 0 }"; EXPECT_EQ(rrc->Dump(), ret); } @@ -518,5 +519,34 @@ HWTEST_F(NotificationTest, Marshalling_00003, Function | SmallTest | Level1) EXPECT_EQ(rrc->Marshalling(parcel), true); } + + +/** + * @tc.name: GetUpdateTimer_00001 + * @tc.desc: Test get update timer. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetUpdateTimer_00001, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + auto rrc = std::make_shared(request); + rrc->SetUpdateTimer(1); + EXPECT_EQ(rrc->GetUpdateTimer(), 1); +} + +/** + * @tc.name: GetFinishTimer_00001 + * @tc.desc: Test get finish timer. + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(NotificationTest, GetFinishTimer_00001, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + auto rrc = std::make_shared(request); + rrc->SetFinishTimer(1); + EXPECT_EQ(rrc->GetFinishTimer(), 1); } -} \ No newline at end of file +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp b/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp index af05dd80e..9bfa63aac 100644 --- a/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp @@ -498,7 +498,7 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationCommon_00100, Function | S int32_t notificationId_ = 0; reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); reminderRequest->reminderType_ = ReminderRequest::ReminderType::TIMER; - reminderRequest->UpdateNotificationCommon(); + reminderRequest->UpdateNotificationCommon(false); } /** @@ -515,7 +515,7 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationCommon_00200, Function | S int32_t notificationId_ = 0; reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); reminderRequest->reminderType_ = ReminderRequest::ReminderType::ALARM; - reminderRequest->UpdateNotificationCommon(); + reminderRequest->UpdateNotificationCommon(false); } /** @@ -532,7 +532,7 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationCommon_00300, Function | S int32_t notificationId_ = 0; reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); reminderRequest->reminderType_ = ReminderRequest::ReminderType::INVALID; - reminderRequest->UpdateNotificationCommon(); + reminderRequest->UpdateNotificationCommon(false); } /** diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 4458d9bf5..c7b5427c5 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -18,6 +18,7 @@ #define private public #define protected public #include "reminder_request.h" +#include "reminder_table.h" #undef private #undef protected @@ -1329,14 +1330,11 @@ HWTEST_F(ReminderRequestTest, CreateWantAgent_00002, Function | SmallTest | Leve */ HWTEST_F(ReminderRequestTest, AddColumn_00002, Function | SmallTest | Level1) { - auto rrc = std::make_shared(); - rrc->InitDbColumns(); std::string name = "this is name"; std::string type = "this is type"; - rrc->AddColumn(name, type, true); - rrc->AddColumn(name, type, false); - int32_t result = rrc->GetReminderId(); - EXPECT_EQ(result, -1); + ReminderTable::AddColumn(name, type, true); + ReminderTable::AddColumn(name, type, false); + EXPECT_EQ(ReminderTable::columns.size(), 2); } /** @@ -1799,6 +1797,20 @@ HWTEST_F(ReminderRequestTest, SetCustomButtonUri_00001, Function | SmallTest | L EXPECT_EQ(result, ret); } +/** + * @tc.name: SetGroupId_00001 + * @tc.desc: Test SetGroupId parameters. + * @tc.type: FUNC + * @tc.require: issueI8CDH3 + */ +HWTEST_F(ReminderRequestTest, SetGroupId_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + std::string groupId = "123"; + rrc->SetGroupId(groupId); + EXPECT_EQ(rrc->GetGroupId(), groupId); +} + /** * @tc.name: InitBundleName_00001 * @tc.desc: Test InitBundleName with normal parameters. @@ -1828,17 +1840,70 @@ HWTEST_F(ReminderRequestTest, InitBundleName_00002, Function | SmallTest | Level } /** - * @tc.name: SetGroupId_00001 - * @tc.desc: Test SetGroupId parameters. + * @tc.name: UpdateNotificationCommon_00100 + * @tc.desc: Test UpdateNotificationCommon when snooze is true. * @tc.type: FUNC - * @tc.require: issueI8CDH3 + * @tc.require: issueII8F9EZ */ -HWTEST_F(ReminderRequestTest, SetGroupId_00001, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00100, Function | SmallTest | Level1) { + // given auto rrc = std::make_shared(); - std::string groupId = "123"; - rrc->SetGroupId(groupId); - EXPECT_EQ(rrc->GetGroupId(), groupId); + EXPECT_EQ(rrc->InitNotificationRequest(), true); + sptr ret = rrc->GetNotificationRequest(); + rrc->snoozeSlotType_ = NotificationConstant::SlotType::OTHER; + bool isSnooze = true; + + // when + rrc->UpdateNotificationCommon(isSnooze); + + // then + EXPECT_EQ(ret->GetSlotType(), NotificationConstant::SlotType::CONTENT_INFORMATION); +} + +/** + * @tc.name: UpdateNotificationCommon_00200 + * @tc.desc: Test UpdateNotificationCommon when snooze is true. + * @tc.type: FUNC + * @tc.require: issueII8F9EZ + */ +HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00200, Function | SmallTest | Level1) +{ + // given + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->InitNotificationRequest(), true); + sptr ret = rrc->GetNotificationRequest(); + rrc->snoozeSlotType_ = NotificationConstant::SlotType::SERVICE_REMINDER; + bool isSnooze = true; + + // when + rrc->UpdateNotificationCommon(isSnooze); + + // then + EXPECT_EQ(ret->GetSlotType(), NotificationConstant::SlotType::SERVICE_REMINDER); +} + +/** + * @tc.name: UpdateNotificationCommon_00300 + * @tc.desc: Test UpdateNotificationCommon when snooze is false. + * @tc.type: FUNC + * @tc.require: issueII8F9EZ + */ +HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00300, Function | SmallTest | Level1) +{ + // given + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->InitNotificationRequest(), true); + sptr ret = rrc->GetNotificationRequest(); + rrc->snoozeSlotType_ = NotificationConstant::SlotType::SERVICE_REMINDER; + rrc->slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; + bool isSnooze = false; + + // when + rrc->UpdateNotificationCommon(isSnooze); + + // then + EXPECT_EQ(ret->GetSlotType(), NotificationConstant::SlotType::SOCIAL_COMMUNICATION); } } } diff --git a/frameworks/core/common/include/ans_const_define.h b/frameworks/core/common/include/ans_const_define.h index 82c4900ac..435f1d1d2 100644 --- a/frameworks/core/common/include/ans_const_define.h +++ b/frameworks/core/common/include/ans_const_define.h @@ -31,6 +31,7 @@ constexpr uint32_t MAX_ACTIVE_NUM_PERSECOND = 10; constexpr size_t MAX_SLOT_NUM = 5; constexpr uint32_t MAX_ICON_SIZE = 50 * 1024; constexpr uint32_t MAX_PICTURE_SIZE = 2 * 1024 * 1024; +constexpr uint32_t MAX_LIVE_VIEW_ICON_NUM = 5; constexpr bool SUPPORT_DO_NOT_DISTRUB = true; constexpr uint32_t SYSTEM_SERVICE_UID = 1000; constexpr uint32_t MAX_CONVERSATIONAL_NUM = 10000; diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index a58d2237f..b8301d2d6 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -179,6 +179,20 @@ public: virtual ErrCode GetSpecialActiveNotifications( const std::vector &key, std::vector> ¬ifications) = 0; + /** + * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method + * to obtain particular live view notification extra info, you must have received the + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param notificationId Indicates the id of the notification to get the extra info by extra info keys. + * @param extraInfoKeys + * @param extraInfo + * @return + */ + virtual ErrCode GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + std::vector extraInfoKeys, sptr &request) = 0; + /** * @brief Allows another application to act as an agent to publish notifications in the name of your application * bundle. @@ -642,9 +656,10 @@ public: */ virtual ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) = 0; virtual ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled) = 0; + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) = 0; virtual ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) = 0; + virtual ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) = 0; /** * @brief Obtains specific datas via specified dump option. @@ -690,7 +705,8 @@ public: * @param pushCallback PushCallBack. * @return Returns register PushCallback result. */ - virtual ErrCode RegisterPushCallback(const sptr &pushCallback) = 0; + virtual ErrCode RegisterPushCallback( + const sptr &pushCallback, const sptr ¬ificationCheckRequest) = 0; /** * @brief Unregister Push Callback. diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 5c91814e3..c45c224c2 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -19,6 +19,7 @@ #include "ans_manager_interface.h" #include "distributed_notification_service_ipc_interface_code.h" #include "iremote_proxy.h" +#include "want_params.h" namespace OHOS { namespace Notification { @@ -166,6 +167,21 @@ public: ErrCode GetSpecialActiveNotifications( const std::vector &key, std::vector> ¬ifications) override; + /** + * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method + * to obtain particular live view notification extra info, you must have received the + * + * @param bundleOption Indicates the bundle name and uid of the application. + * @param notificationId Indicates the id of the notification to get the extra info by extra info keys. + * @param label + * @param extraInfoKeys + * @param extraInfo + * @return + */ + ErrCode GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + const std::vector extraInfoKeys, sptr &request) override; + /** * @brief Allows another application to act as an agent to publish notifications in the name of your application * bundle. @@ -629,9 +645,10 @@ public: */ ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) override; ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled) override; + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override; ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) override; + ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override; /** * @brief Obtains specific datas via specified dump option. @@ -675,9 +692,11 @@ public: * @brief Register Push Callback. * * @param pushCallback PushCallBack. + * @param notificationCheckRequest Filter conditions for push check * @return Returns register PushCallback result. */ - ErrCode RegisterPushCallback(const sptr &pushCallback) override; + ErrCode RegisterPushCallback(const sptr &pushCallback, + const sptr ¬ificationCheckRequest) override; /** * @brief Unregister Push Callback. diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 4da073244..98545d6c4 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -182,6 +182,10 @@ public: virtual ErrCode GetSpecialActiveNotifications( const std::vector &key, std::vector> ¬ifications) override; + virtual ErrCode GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + std::vector extraInfoKeys, sptr &request) override; + /** * @brief Allows another application to act as an agent to publish notifications in the name of your application * bundle. @@ -644,9 +648,10 @@ public: */ virtual ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) override; virtual ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled) override; + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override; virtual ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) override; + virtual ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override; /** * @brief Obtains specific datas via specified dump option. @@ -690,9 +695,11 @@ public: * @brief Register Push Callback. * * @param pushCallback PushCallBack. + * @param notificationCheckRequest Filter conditions for push check * @return Returns register PushCallback result. */ - ErrCode RegisterPushCallback(const sptr& pushCallback) override; + ErrCode RegisterPushCallback(const sptr& pushCallback, + const sptr& notificationCheckRequest) override; /** * @brief Unregister Push Callback. @@ -720,6 +727,7 @@ private: ErrCode HandleGetActiveNotificationNums(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetAllActiveNotifications(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetSpecialActiveNotifications(MessageParcel &data, MessageParcel &reply); + ErrCode HandleGetActiveNotificationByFilter(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetNotificationAgent(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetNotificationAgent(MessageParcel &data, MessageParcel &reply); ErrCode HandleCanPublishAsBundle(MessageParcel &data, MessageParcel &reply); @@ -773,6 +781,7 @@ private: ErrCode HandleGetDoNotDisturbDateByUser(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetEnabledForBundleSlot(MessageParcel &data, MessageParcel &reply); + ErrCode HandleGetEnabledForBundleSlotSelf(MessageParcel &data, MessageParcel &reply); ErrCode HandleDistributedSetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply); ErrCode HandleDistributedGetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetBadgeNumber(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index fff7608ec..fcad82aee 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -23,6 +23,7 @@ #include "ans_manager_interface.h" #include "notification_subscriber.h" #include "notification_local_live_view_subscriber.h" +#include "want_params.h" namespace OHOS { namespace Notification { @@ -468,6 +469,16 @@ public: ErrCode GetAllActiveNotifications( const std::vector key, std::vector> ¬ification); + /** + * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method + * to obtain particular live view notification extra info, you must have received the + * @param filter + * @param extraInfo + * @return + */ + ErrCode GetActiveNotificationByFilter( + const LiveViewFilter &filter, sptr &request); + /** * @brief Checks whether a specified application has the permission to publish notifications. If bundle specifies * the current application, no permission is required for calling this method. If bundle specifies another @@ -766,10 +777,11 @@ public: * @param bundleOption Indicates the bundle name and uid of the application. * @param slotType Indicates type of slot. * @param enable the type of slot enabled. + * @param isForceControl Indicates whether the slot is affected by the notification switch. * @return Returns get slot number by bundle result. */ - ErrCode SetEnabledForBundleSlot( - const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled); + ErrCode SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); /** * Obtains whether the application slot is enabled. @@ -782,6 +794,15 @@ public: ErrCode GetEnabledForBundleSlot( const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled); + /** + * Obtains whether the current application slot is enabled. + * + * @param slotType Indicates type of slot. + * @param enable the type of slot enabled to get. + * @return Returns get enabled result. + */ + ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled); + /** * @brief Obtains specific datas via specified dump option. * @@ -824,9 +845,11 @@ public: * @brief Register Push Callback. * * @param pushCallback PushCallBack. + * @param notificationCheckRequest Filter conditions for push check * @return Returns register PushCallback result. */ - ErrCode RegisterPushCallback(const sptr &pushCallback); + ErrCode RegisterPushCallback( + const sptr &pushCallback, const sptr ¬ificationCheckRequest); /** * @brief Unregister Push Callback. @@ -851,24 +874,6 @@ private: */ bool CanPublishMediaContent(const NotificationRequest &request) const; - /** - * @brief Checks whether the picture size exceeds the limit in PixelMap. - * - * @param pixelMap Indicates the specified image. - * @param maxSize Indicates the limit size. - * @return Returns true if the limit size is exceeded; returns false otherwise. - */ - bool CheckImageOverSizeForPixelMap( - const std::shared_ptr &pixelMap, uint32_t maxSize); - - /** - * @brief Checks whether the picture size exceeds the limit in NotificationRequest's content. - * - * @param request Indicates the specified request. - * @return Returns the ErrCode. - */ - ErrCode CheckImageSizeForContent(const NotificationRequest &request); - /** * @brief Checks whether the picture size exceeds the limit. * @@ -885,6 +890,14 @@ private: */ bool IsNonDistributedNotificationType(const NotificationContent::Type &type); + /** + * @brief Checks if the LiveViewContent can be published. + * + * @param request Indicates the specified request. + * @return Returns true if the MediaContent can be published; returns false otherwise. + */ + bool CanPublishLiveViewContent(const NotificationRequest &request) const; + private: std::mutex mutex_; sptr ansManagerProxy_; diff --git a/frameworks/core/include/ans_subscriber_interface.h b/frameworks/core/include/ans_subscriber_interface.h index 91e868f79..5ee72c940 100644 --- a/frameworks/core/include/ans_subscriber_interface.h +++ b/frameworks/core/include/ans_subscriber_interface.h @@ -56,6 +56,9 @@ public: virtual void OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) = 0; + virtual void OnConsumedList( + const std::vector> ¬ifications, const sptr ¬ificationMap) = 0; + /** * @brief The callback function on a notification canceled. * diff --git a/frameworks/core/include/ans_subscriber_proxy.h b/frameworks/core/include/ans_subscriber_proxy.h index 7fa46b9f2..881c4bdb1 100644 --- a/frameworks/core/include/ans_subscriber_proxy.h +++ b/frameworks/core/include/ans_subscriber_proxy.h @@ -48,6 +48,9 @@ public: void OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) override; + void OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) override; + /** * @brief The callback function on a notification canceled. * diff --git a/frameworks/core/include/ans_subscriber_stub.h b/frameworks/core/include/ans_subscriber_stub.h index 5e03e1e10..b84b5e7a9 100644 --- a/frameworks/core/include/ans_subscriber_stub.h +++ b/frameworks/core/include/ans_subscriber_stub.h @@ -58,6 +58,9 @@ public: void OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) override; + void OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) override; + /** * @brief The callback function on a notification canceled. * @@ -105,6 +108,7 @@ private: ErrCode HandleOnConnected(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnDisconnected(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnConsumedMap(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnConsumedListMap(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnCanceledListMap(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnUpdated(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h index 78f24ac5d..c0a5696bb 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -43,6 +43,7 @@ namespace Notification { GET_ACTIVE_NOTIFICATION_NUMS, GET_ALL_ACTIVE_NOTIFICATIONS, GET_SPECIAL_ACTIVE_NOTIFICATIONS, + GET_ACTIVE_NOTIFICATION_BY_FILTER, SET_NOTIFICATION_AGENT, GET_NOTIFICATION_AGENT, CAN_PUBLISH_AS_BUNDLE, @@ -99,6 +100,7 @@ namespace Notification { GET_DO_NOT_DISTURB_DATE_BY_USER, SET_ENABLED_FOR_BUNDLE_SLOT, GET_ENABLED_FOR_BUNDLE_SLOT, + GET_ENABLED_FOR_BUNDLE_SLOT_SELF, SET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP, GET_SYNC_NOTIFICATION_ENABLED_WITHOUT_APP, SET_BADGE_NUMBER, @@ -109,6 +111,7 @@ namespace Notification { ON_DISCONNECTED, ON_CONSUMED, // Obsolete ON_CONSUMED_MAP, + ON_CONSUMED_LIST_MAP, ON_CANCELED_MAP, ON_CANCELED_LIST_MAP, ON_UPDATED, diff --git a/frameworks/core/include/hitrace_meter_adapter.h b/frameworks/core/include/hitrace_meter_adapter.h new file mode 100644 index 000000000..ae6cd0ccd --- /dev/null +++ b/frameworks/core/include/hitrace_meter_adapter.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_HITRACE_METER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_HITRACE_METER_H + +#ifdef HITRACE_METER_ENABLE +#include "hitrace_meter.h" +#else +#define HITRACE_METER_NAME(TAG, str) ((void)0) +#endif + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_HITRACE_METER_H diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 50666b0c8..478dd0b01 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -44,6 +44,11 @@ ErrCode AnsManagerProxy::Publish(const std::string &label, const sptrIsCommonLiveView()) { + if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + return ERR_ANS_PARCELABLE_FAILED; + } + } if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ANS_LOGE("[Publish] fail: write interface token failed."); return ERR_ANS_PARCELABLE_FAILED; @@ -506,6 +511,67 @@ ErrCode AnsManagerProxy::GetSpecialActiveNotifications( return result; } +ErrCode AnsManagerProxy::GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + const std::vector extraInfoKeys, sptr &request) +{ + if (bundleOption == nullptr) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: bundle is empty."); + return ERR_ANS_INVALID_PARAM; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteParcelable(bundleOption)) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: write bundleOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(notificationId)) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: write notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteString(label)) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: write label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteStringVector(extraInfoKeys)) { + ANS_LOGE("[GetActiveNotificationByFilter] fail:: write extraInfoKeys failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + if (!reply.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ACTIVE_NOTIFICATION_BY_FILTER, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: transact ErrCode=%{public}d", result); + return result; + } + + request = reply.ReadParcelable(); + if (request == nullptr) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: read request is nullptr."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("[GetActiveNotificationByFilter] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + ErrCode AnsManagerProxy::SetNotificationAgent(const std::string &agent) { if (agent.empty()) { @@ -622,6 +688,11 @@ ErrCode AnsManagerProxy::PublishAsBundle( } MessageParcel data; + if (notification->IsCommonLiveView()) { + if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + return ERR_ANS_PARCELABLE_FAILED; + } + } if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { ANS_LOGE("[PublishAsBundle] fail: write interface token failed."); return ERR_ANS_PARCELABLE_FAILED; @@ -1198,7 +1269,8 @@ ErrCode AnsManagerProxy::SetNotificationsEnabledForAllBundles(const std::string MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE, option, data, reply); + ErrCode result = InnerTransact(NotificationInterfaceCode::SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE, + option, data, reply); if (result != ERR_OK) { ANS_LOGE("[SetNotificationsEnabledForAllBundles] fail: transact ErrCode=%{public}d", result); return ERR_ANS_TRANSACT_FAILED; @@ -2468,8 +2540,8 @@ ErrCode AnsManagerProxy::GetDoNotDisturbDate(const int32_t &userId, sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled) +ErrCode AnsManagerProxy::SetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) { if (bundleOption == nullptr) { ANS_LOGE("[SetEnabledForBundleSlot] fail: bundle is empty."); @@ -2497,6 +2569,11 @@ ErrCode AnsManagerProxy::SetEnabledForBundleSlot( return ERR_ANS_PARCELABLE_FAILED; } + if (!data.WriteBool(isForceControl)) { + ANS_LOGE("[SetEnabledForBundleSlot] fail: write isForceControl failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; ErrCode result = InnerTransact(NotificationInterfaceCode::SET_ENABLED_FOR_BUNDLE_SLOT, option, data, reply); @@ -2558,6 +2635,40 @@ ErrCode AnsManagerProxy::GetEnabledForBundleSlot( return result; } +ErrCode AnsManagerProxy::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(slotType)) { + ANS_LOGE("[GetEnabledForBundleSlotSelf] fail:: write slotType failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ENABLED_FOR_BUNDLE_SLOT_SELF, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.ReadBool(enabled)) { + ANS_LOGE("[GetEnabledForBundleSlotSelf] fail: read enable failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + ErrCode AnsManagerProxy::SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) { MessageParcel data; @@ -2695,7 +2806,8 @@ ErrCode AnsManagerProxy::SetBadgeNumber(int32_t badgeNumber) return result; } -ErrCode AnsManagerProxy::RegisterPushCallback(const sptr &pushCallback) +ErrCode AnsManagerProxy::RegisterPushCallback( + const sptr &pushCallback, const sptr ¬ificationCheckRequest) { MessageParcel data; if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { @@ -2708,6 +2820,11 @@ ErrCode AnsManagerProxy::RegisterPushCallback(const sptr &pushCal return ERR_ANS_PARCELABLE_FAILED; } + if (!data.WriteParcelable(notificationCheckRequest)) { + ANS_LOGE("write notificationCheckRequest failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + MessageParcel reply; MessageOption option = { MessageOption::TF_SYNC }; ErrCode result = InnerTransact(NotificationInterfaceCode::REGISTER_PUSH_CALLBACK, option, data, reply); diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index 47254fb7c..b412ab0df 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -75,6 +75,9 @@ const std::map bundleOption = data.ReadParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read bundleOption failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::string label; + if (!data.ReadString(label)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + std::vector extraInfoKeys; + if (!data.ReadStringVector(&extraInfoKeys)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: read extraInfoKeys failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr request; + ErrCode result = GetActiveNotificationByFilter(bundleOption, notificationId, label, extraInfoKeys, request); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteParcelable(request)) { + ANS_LOGE("[HandleGetActiveNotificationByFilter] fail: get extra info by filter failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + return result; +} + ErrCode AnsManagerStub::HandleSetNotificationAgent(MessageParcel &data, MessageParcel &reply) { std::string agent; @@ -1694,7 +1740,13 @@ ErrCode AnsManagerStub::HandleSetEnabledForBundleSlot(MessageParcel &data, Messa return ERR_ANS_PARCELABLE_FAILED; } - ErrCode result = SetEnabledForBundleSlot(bundleOption, slotType, enabled); + bool isForceControl = false; + if (!data.ReadBool(isForceControl)) { + ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: read isForceControl failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleSetEnabledForBundleSlot] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; @@ -1733,6 +1785,30 @@ ErrCode AnsManagerStub::HandleGetEnabledForBundleSlot(MessageParcel &data, Messa return ERR_OK; } +ErrCode AnsManagerStub::HandleGetEnabledForBundleSlotSelf(MessageParcel &data, MessageParcel &reply) +{ + int32_t type = 0; + if (!data.ReadInt32(type)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: read slot type failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + NotificationConstant::SlotType slotType = static_cast(type); + + bool enabled = false; + ErrCode result = GetEnabledForBundleSlotSelf(slotType, enabled); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(enabled)) { + ANS_LOGE("[HandleGetEnabledForBundleSlotSelf] fail: write enabled failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + return ERR_OK; +} + ErrCode AnsManagerStub::HandleDistributedSetEnabledWithoutApp(MessageParcel &data, MessageParcel &reply) { int32_t userId = SUBSCRIBE_USER_INIT; @@ -1806,7 +1882,13 @@ ErrCode AnsManagerStub::HandleRegisterPushCallback(MessageParcel &data, MessageP return ERR_ANS_PARCELABLE_FAILED; } - ErrCode result = RegisterPushCallback(pushCallBack); + sptr notificationCheckRequest = data.ReadParcelable(); + if (notificationCheckRequest == nullptr) { + ANS_LOGE("fail: read notificationCheckRequest failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = RegisterPushCallback(pushCallBack, notificationCheckRequest); if (!reply.WriteInt32(result)) { ANS_LOGE("fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; @@ -1915,6 +1997,14 @@ ErrCode AnsManagerStub::GetSpecialActiveNotifications( return ERR_INVALID_OPERATION; } +ErrCode AnsManagerStub::GetActiveNotificationByFilter( + const sptr &bundleOption, const int32_t notificationId, const std::string &label, + std::vector extraInfoKeys, sptr &request) +{ + ANS_LOGE("AnsManagerStub::GetActiveNotificationByFilter called!"); + return ERR_INVALID_OPERATION; +} + ErrCode AnsManagerStub::SetNotificationAgent(const std::string &agent) { ANS_LOGE("AnsManagerStub::SetNotificationAgent called!"); @@ -2239,8 +2329,8 @@ ErrCode AnsManagerStub::GetDoNotDisturbDate(const int32_t &userId, sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled) +ErrCode AnsManagerStub::SetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) { ANS_LOGE("AnsManagerStub::SetEnabledForBundleSlot called!"); return ERR_INVALID_OPERATION; @@ -2253,6 +2343,11 @@ ErrCode AnsManagerStub::GetEnabledForBundleSlot( return ERR_INVALID_OPERATION; } +ErrCode AnsManagerStub::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + ANS_LOGE("AnsManagerStub::GetEnabledForBundleSlotSelf called!"); + return ERR_INVALID_OPERATION; +} ErrCode AnsManagerStub::ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, std::vector &dumpInfo) @@ -2279,7 +2374,8 @@ ErrCode AnsManagerStub::SetBadgeNumber(int32_t badgeNumber) return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::RegisterPushCallback(const sptr& pushCallback) +ErrCode AnsManagerStub::RegisterPushCallback( + const sptr& pushCallback, const sptr ¬ificationCheckRequest) { ANS_LOGE("RegisterPushCallback called!"); return ERR_INVALID_OPERATION; diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 464345b55..44b3f3f6e 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -17,7 +17,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" -#include "hitrace_meter.h" +#include "hitrace_meter_adapter.h" #include "iservice_registry.h" #include "notification_button_option.h" #include "notification_local_live_view_subscriber.h" @@ -143,6 +143,11 @@ ErrCode AnsNotification::PublishNotification(const std::string &label, const Not return ERR_ANS_INVALID_PARAM; } + if (!CanPublishLiveViewContent(request)) { + ANS_LOGE("Refuse to publish the notification without valid live view content."); + return ERR_ANS_INVALID_PARAM; + } + ErrCode checkErr = CheckImageSize(request); if (checkErr != ERR_OK) { ANS_LOGE("The size of one picture exceeds the limit"); @@ -625,6 +630,28 @@ ErrCode AnsNotification::GetAllActiveNotifications( return ansManagerProxy_->GetSpecialActiveNotifications(key, notification); } +ErrCode AnsNotification::GetActiveNotificationByFilter(const LiveViewFilter &filter, + sptr &request) +{ + if (filter.bundle.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + ANS_LOGD("Bundle name %{public}s, uid %{public}d, notification id %{public}d, label %{public}s.", + filter.bundle.GetBundleName().c_str(), filter.bundle.GetUid(), filter.notificationKey.id, + filter.notificationKey.label.c_str()); + + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(filter.bundle)); + return ansManagerProxy_->GetActiveNotificationByFilter(bo, filter.notificationKey.id, filter.notificationKey.label, + filter.extraInfoKeys, request); +} + ErrCode AnsNotification::IsAllowedNotify(const NotificationBundleOption &bundleOption, bool &allowed) { if (bundleOption.GetBundleName().empty()) { @@ -1050,90 +1077,60 @@ bool AnsNotification::CanPublishMediaContent(const NotificationRequest &request) return true; } -bool AnsNotification::CheckImageOverSizeForPixelMap(const std::shared_ptr &pixelMap, uint32_t maxSize) +bool AnsNotification::CanPublishLiveViewContent(const NotificationRequest &request) const { - if (!pixelMap) { - return false; - } - - uint32_t size = static_cast(pixelMap->GetByteCount()); - if (size > maxSize) { + if (!request.IsCommonLiveView()) { return true; } - return false; -} -ErrCode AnsNotification::CheckImageSizeForContent(const NotificationRequest &request) -{ - auto content = request.GetContent(); - if (!content) { - ANS_LOGW("Invalid content in NotificationRequest"); - return ERR_OK; + if (request.GetContent() == nullptr) { + ANS_LOGE("Failed to publish notification with null content."); + return false; } - auto basicContent = request.GetContent()->GetNotificationContent(); - if (!basicContent) { - ANS_LOGW("Invalid content in NotificationRequest"); - return ERR_OK; + auto content = request.GetContent()->GetNotificationContent(); + auto liveView = std::static_pointer_cast(content); + if (liveView == nullptr) { + ANS_LOGE("Failed to get live view content."); + return false; } - auto contentType = request.GetNotificationType(); - switch (contentType) { - case NotificationContent::Type::CONVERSATION: { - auto conversationalContent = std::static_pointer_cast(basicContent); - - auto picture = conversationalContent->GetMessageUser().GetPixelMap(); - if (CheckImageOverSizeForPixelMap(picture, MAX_ICON_SIZE)) { - ANS_LOGE("The size of picture in ConversationalContent's message user exceeds limit"); - return ERR_ANS_ICON_OVER_SIZE; - } - - auto messages = conversationalContent->GetAllConversationalMessages(); - for (auto &msg : messages) { - if (!msg) { - continue; - } - - auto img = msg->GetSender().GetPixelMap(); - if (CheckImageOverSizeForPixelMap(img, MAX_ICON_SIZE)) { - ANS_LOGE("The size of picture in ConversationalContent's message exceeds limit"); - return ERR_ANS_ICON_OVER_SIZE; - } - } - break; - } - case NotificationContent::Type::PICTURE: { - auto pictureContent = std::static_pointer_cast(basicContent); + auto status = liveView->GetLiveViewStatus(); + if (status >= NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_BUTT) { + ANS_LOGE("Invalid status %{public}u.", status); + return false; + } - auto bigPicture = pictureContent->GetBigPicture(); - if (CheckImageOverSizeForPixelMap(bigPicture, MAX_PICTURE_SIZE)) { - ANS_LOGE("The size of big picture in PictureContent exceeds limit"); - return ERR_ANS_PICTURE_OVER_SIZE; - } - break; - } - default: - break; + auto extraInfo = liveView->GetExtraInfo(); + if ((extraInfo == nullptr) && (status != NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_END)) { + ANS_LOGE("Extrainfo is empty."); + return false; } - return ERR_OK; + return true; } ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) { auto littleIcon = request.GetLittleIcon(); - if (CheckImageOverSizeForPixelMap(littleIcon, MAX_ICON_SIZE)) { + if (NotificationRequest::CheckImageOverSizeForPixelMap(littleIcon, MAX_ICON_SIZE)) { ANS_LOGE("The size of little icon exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } auto bigIcon = request.GetBigIcon(); - if (CheckImageOverSizeForPixelMap(bigIcon, MAX_ICON_SIZE)) { + if (NotificationRequest::CheckImageOverSizeForPixelMap(bigIcon, MAX_ICON_SIZE)) { + ANS_LOGE("The size of big icon exceeds limit"); + return ERR_ANS_ICON_OVER_SIZE; + } + + auto overlayIcon = request.GetOverlayIcon(); + if (overlayIcon && NotificationRequest::CheckImageOverSizeForPixelMap(bigIcon, MAX_ICON_SIZE)) { ANS_LOGE("The size of big icon exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } - ErrCode err = CheckImageSizeForContent(request); + ErrCode err = request.CheckImageSizeForContent(); if (err != ERR_OK) { return err; } @@ -1144,7 +1141,7 @@ ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) continue; } auto icon = btn->GetIcon(); - if (CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { + if (NotificationRequest::CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { ANS_LOGE("The size of icon in ActionButton exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } @@ -1156,7 +1153,7 @@ ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) continue; } auto icon = user->GetPixelMap(); - if (CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { + if (NotificationRequest::CheckImageOverSizeForPixelMap(icon, MAX_ICON_SIZE)) { ANS_LOGE("The size of picture in MessageUser exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } @@ -1177,7 +1174,9 @@ ErrCode AnsNotification::IsSupportTemplate(const std::string &templateName, bool bool AnsNotification::IsNonDistributedNotificationType(const NotificationContent::Type &type) { - return ((type == NotificationContent::Type::CONVERSATION) || (type == NotificationContent::Type::PICTURE)); + return ((type == NotificationContent::Type::CONVERSATION) || + (type == NotificationContent::Type::PICTURE) || + (type == NotificationContent::Type::LIVE_VIEW)); } ErrCode AnsNotification::IsAllowedNotify(const int32_t &userId, bool &allowed) @@ -1275,8 +1274,8 @@ ErrCode AnsNotification::GetDoNotDisturbDate(const int32_t &userId, Notification return ret; } -ErrCode AnsNotification::SetEnabledForBundleSlot( - const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled) +ErrCode AnsNotification::SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (bundleOption.GetBundleName().empty()) { @@ -1290,7 +1289,7 @@ ErrCode AnsNotification::SetEnabledForBundleSlot( } sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); - return ansManagerProxy_->SetEnabledForBundleSlot(bo, slotType, enabled); + return ansManagerProxy_->SetEnabledForBundleSlot(bo, slotType, enabled, isForceControl); } ErrCode AnsNotification::GetEnabledForBundleSlot( @@ -1310,6 +1309,16 @@ ErrCode AnsNotification::GetEnabledForBundleSlot( return ansManagerProxy_->GetEnabledForBundleSlot(bo, slotType, enabled); } +ErrCode AnsNotification::GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetEnabledForBundleSlotSelf fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return ansManagerProxy_->GetEnabledForBundleSlotSelf(slotType, enabled); +} + ErrCode AnsNotification::ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, std::vector &dumpInfo) { @@ -1361,14 +1370,15 @@ ErrCode AnsNotification::SetBadgeNumber(int32_t badgeNumber) return ansManagerProxy_->SetBadgeNumber(badgeNumber); } -ErrCode AnsNotification::RegisterPushCallback(const sptr& pushCallback) +ErrCode AnsNotification::RegisterPushCallback( + const sptr& pushCallback, const sptr ¬ificationCheckRequest) { if (!GetAnsManagerProxy()) { ANS_LOGE("RegisterPushCallback fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; } - return ansManagerProxy_->RegisterPushCallback(pushCallback); + return ansManagerProxy_->RegisterPushCallback(pushCallback, notificationCheckRequest); } ErrCode AnsNotification::UnregisterPushCallback() diff --git a/frameworks/core/src/ans_subscriber_proxy.cpp b/frameworks/core/src/ans_subscriber_proxy.cpp index 8a7a1e003..9073bcb99 100644 --- a/frameworks/core/src/ans_subscriber_proxy.cpp +++ b/frameworks/core/src/ans_subscriber_proxy.cpp @@ -96,6 +96,12 @@ void AnsSubscriberProxy::OnConsumed( } MessageParcel data; + if (notification->GetNotificationRequest().IsCommonLiveView()) { + if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + ANS_LOGE("[OnConsumed] fail: set max capacity failed."); + return; + } + } if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { ANS_LOGE("[OnConsumed] fail: write interface token failed."); return; @@ -127,6 +133,47 @@ void AnsSubscriberProxy::OnConsumed( } } +void AnsSubscriberProxy::OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) +{ + ANS_LOGI("Start consumed list in proxy."); + if (notifications.empty() || notificationMap == nullptr) { + ANS_LOGE("Invalid notification to consumed."); + return; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { + ANS_LOGE("Write interface token failed."); + return; + } + + if (!WriteParcelableVector(notifications, data)) { + ANS_LOGE("Write notifications failed"); + return; + } + + if (!data.WriteBool(notificationMap != nullptr)) { + ANS_LOGE("Write existMap failed"); + return; + } + + if (notificationMap != nullptr) { + if (!data.WriteParcelable(notificationMap)) { + ANS_LOGE("Write notificationMap failed"); + return; + } + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_ASYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::ON_CONSUMED_LIST_MAP, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("Transact ErrCode=ERR_ANS_TRANSACT_FAILED"); + return; + } +} + void AnsSubscriberProxy::OnCanceled( const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) { @@ -136,6 +183,12 @@ void AnsSubscriberProxy::OnCanceled( } MessageParcel data; + if (notification->GetNotificationRequest().IsCommonLiveView()) { + if (!data.SetMaxCapacity(NotificationConstant::NOTIFICATION_MAX_LIVE_VIEW_SIZE)) { + ANS_LOGE("[OnCanceled] fail: set max capacity failed."); + return; + } + } if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { ANS_LOGE("[OnCanceled] fail: write interface token failed."); return; diff --git a/frameworks/core/src/ans_subscriber_stub.cpp b/frameworks/core/src/ans_subscriber_stub.cpp index 4648d80cc..9ea73e10f 100644 --- a/frameworks/core/src/ans_subscriber_stub.cpp +++ b/frameworks/core/src/ans_subscriber_stub.cpp @@ -32,6 +32,8 @@ AnsSubscriberStub::AnsSubscriberStub() std::bind(&AnsSubscriberStub::HandleOnDisconnected, this, std::placeholders::_1, std::placeholders::_2)); interfaces_.emplace(NotificationInterfaceCode::ON_CONSUMED_MAP, std::bind(&AnsSubscriberStub::HandleOnConsumedMap, this, std::placeholders::_1, std::placeholders::_2)); + interfaces_.emplace(NotificationInterfaceCode::ON_CONSUMED_LIST_MAP, + std::bind(&AnsSubscriberStub::HandleOnConsumedListMap, this, std::placeholders::_1, std::placeholders::_2)); interfaces_.emplace(NotificationInterfaceCode::ON_CANCELED_MAP, std::bind(&AnsSubscriberStub::HandleOnCanceledMap, this, std::placeholders::_1, std::placeholders::_2)); interfaces_.emplace(NotificationInterfaceCode::ON_CANCELED_LIST_MAP, @@ -116,6 +118,35 @@ ErrCode AnsSubscriberStub::HandleOnConsumedMap(MessageParcel &data, MessageParce return ERR_OK; } +ErrCode AnsSubscriberStub::HandleOnConsumedListMap(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGI("Start handle notifications in consumed list."); + + std::vector> notifications; + if (!ReadParcelableVector(notifications, data)) { + ANS_LOGE("read notifications failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool existMap = false; + if (!data.ReadBool(existMap)) { + ANS_LOGE("read existMap failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr notificationMap = nullptr; + if (existMap) { + notificationMap = data.ReadParcelable(); + if (notificationMap == nullptr) { + ANS_LOGE("read NotificationSortingMap failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + OnConsumedList(notifications, notificationMap); + return ERR_OK; +} + ErrCode AnsSubscriberStub::HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply) { sptr notification = data.ReadParcelable(); @@ -262,6 +293,10 @@ void AnsSubscriberStub::OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) {} +void AnsSubscriberStub::OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) +{} + void AnsSubscriberStub::OnCanceled( const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) {} diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp index c85c8cf90..86958bc8d 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -6561,7 +6561,8 @@ HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0100, Function | M std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -6581,7 +6582,8 @@ HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0200, Function | M std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = nullptr; - int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); EXPECT_EQ(ERR_ANS_INVALID_PARAM, result); } @@ -6603,7 +6605,8 @@ HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0300, Function | M std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false); EXPECT_EQ(ERR_OK, result); } @@ -6624,7 +6627,8 @@ HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0400, Function | M std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true); + int32_t result = proxy->SetEnabledForBundleSlot( + bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true, false);; EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } @@ -6646,7 +6650,8 @@ HWTEST_F(AnsManagerProxyUnitTest, SetEnabledForBundleSlotTest_0500, Function | M std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, NotificationConstant::SOCIAL_COMMUNICATION, true); + int32_t result = proxy->SetEnabledForBundleSlot(bundleOption, + NotificationConstant::SOCIAL_COMMUNICATION, true, false); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp index d10275d0f..f03a9102f 100644 --- a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp @@ -3158,11 +3158,13 @@ HWTEST_F(AnsManagerStubTest, HandleSetEnabledForBundleSlot01, Function | SmallTe sptr bundleOption = new NotificationBundleOption(); int32_t type = 4; bool enabled = true; + bool isForceControl = false; data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); data.WriteStrongParcelable(bundleOption); data.WriteInt32(type); data.WriteBool(enabled); + data.WriteBool(isForceControl); ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); EXPECT_EQ(ret, (int)ERR_OK); @@ -4098,8 +4100,9 @@ HWTEST_F(AnsManagerStubTest, SetEnabledForBundleSlot01, Function | SmallTest | L sptr bundleOption = new NotificationBundleOption(); NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SERVICE_REMINDER; bool enabled = true; + bool isForceControl = false; - ErrCode result = ansManagerStub_->SetEnabledForBundleSlot(bundleOption, slotType, enabled); + ErrCode result = ansManagerStub_->SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); } diff --git a/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp b/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp index 9aaf4e2e2..cf9e8fe2c 100644 --- a/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp @@ -318,8 +318,8 @@ HWTEST_F(AnsNotificationUnitAnnexTest, CheckImageSizeForContent_0100, Function | { NotificationRequest request; request.SetContent(nullptr); - - ErrCode ret = ans_->CheckImageSizeForContent(request); + + ErrCode ret = request.CheckImageSizeForContent(); EXPECT_EQ(ret, ERR_OK); } } // namespace Notification diff --git a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp index df43fc5f2..7b493ad7f 100755 --- a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp @@ -393,7 +393,7 @@ public: } ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled) override + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override { return ERR_ANS_INVALID_PARAM; } @@ -404,6 +404,11 @@ public: return ERR_ANS_INVALID_PARAM; } + ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override + { + return ERR_ANS_INVALID_PARAM; + } + ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, std::vector &dumpInfo) override { @@ -425,7 +430,8 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode RegisterPushCallback(const sptr &pushCallback) override + ErrCode RegisterPushCallback(const sptr &pushCallback, + const sptr ¬ificationCheckRequest) override { return ERR_ANS_INVALID_PARAM; } @@ -435,6 +441,13 @@ public: return ERR_ANS_INVALID_PARAM; } + ErrCode GetActiveNotificationByFilter(const sptr &bundleOption, + const int32_t notificationId, const std::string &label, std::vector extraInfoKeys, + const sptr &request) override + { + return ERR_ANS_INVALID_PARAM; + } + ErrCode TriggerLocalLiveView(const sptr &bundleOption, const int32_t notificationId, const sptr &buttonOption) override { @@ -530,7 +543,8 @@ HWTEST_F(AnsNotificationBranchTest, RegisterPushCallback_0100, Function | Medium EXPECT_NE(ansNotification, nullptr); sptr pushCallback = nullptr; MockGetAnsManagerProxy(false); - ErrCode ret = ansNotification->RegisterPushCallback(pushCallback); + sptr checkRequest = new (std::nothrow) NotificationCheckRequest(); + ErrCode ret = ansNotification->RegisterPushCallback(pushCallback, checkRequest); EXPECT_EQ(ret, ERR_ANS_SERVICE_NOT_CONNECTED); } @@ -548,7 +562,8 @@ HWTEST_F(AnsNotificationBranchTest, RegisterPushCallback_0200, Function | Medium sptr pushCallback = nullptr; MockGetAnsManagerProxy(true); ansNotification->ansManagerProxy_ = new (std::nothrow) MockAnsManagerInterface(); - ansNotification->RegisterPushCallback(pushCallback); + sptr checkRequest = new (std::nothrow) NotificationCheckRequest(); + ansNotification->RegisterPushCallback(pushCallback, checkRequest); } /* diff --git a/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp b/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp index c3e07352b..6a8486d29 100644 --- a/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp @@ -689,7 +689,8 @@ HWTEST_F(AnsNotificationUnitTest, SetEnabledForBundleSlot_0100, Function | Mediu bundleOption.SetBundleName(bundleName); NotificationConstant::SlotType slotType = NotificationConstant::SlotType::CUSTOM; bool enabled = true; - ErrCode ret1 = ans_->SetEnabledForBundleSlot(bundleOption, slotType, enabled); + bool isForceControl = false; + ErrCode ret1 = ans_->SetEnabledForBundleSlot(bundleOption, slotType, enabled, isForceControl); EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); ErrCode ret2 = ans_->GetEnabledForBundleSlot(bundleOption, slotType, enabled); EXPECT_EQ(ret2, ERR_ANS_SERVICE_NOT_CONNECTED); diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp index 3952ea93f..ea83edc89 100644 --- a/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_test/ans_subscriber_proxy_unit_test.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "notification_request.h" #include #define private public @@ -154,10 +155,15 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0400, Function | MediumTest | Le << "AnsSubscriberProxyUnitTest, OnConsumed_0400, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = + new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = + new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); sptr notificationMap = new (std::nothrow) NotificationSortingMap(); ASSERT_NE(nullptr, notificationMap); @@ -176,10 +182,15 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0500, Function | MediumTest | Le << "AnsSubscriberProxyUnitTest, OnConsumed_0500, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = + new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = + new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); sptr notificationMap = new (std::nothrow) NotificationSortingMap(); ASSERT_NE(nullptr, notificationMap); @@ -218,14 +229,102 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumed_0700, Function | MediumTest | Le << "AnsSubscriberProxyUnitTest, OnConsumed_0700, TestSize.Level1"; sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); ASSERT_NE(nullptr, iremoteObject); - EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)) + .Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = + new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = + new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); proxy->OnConsumed(notification, nullptr); } +/* + * @tc.name: OnConsumedList_0100 + * @tc.desc: Test OnConsumedList function and notifications is empty + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnConsumedList_0100, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + proxy->OnConsumedList(notifications, nullptr); +} + +/* + * @tc.name: OnConsumedList_0200 + * @tc.desc: Test OnConsumedList function and notifications is empty + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnConsumedList_0200, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); + std::vector> notifications; + notifications.emplace_back(notification); + proxy->OnConsumedList(notifications, nullptr); +} + +/* + * @tc.name: OnConsumedList_0300 + * @tc.desc: Test OnConsumedList function and notifications is empty + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnConsumedList_0300, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(0); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + std::vector> notifications; + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + proxy->OnConsumedList(notifications, notificationMap); +} + +/* + * @tc.name: OnConsumedList_0400 + * @tc.desc: 1.Test OnConsumedList function and notifications is not empty + * 2.notificationMap is not nullptr + * @tc.type: FUNC + */ +HWTEST_F(AnsSubscriberProxyUnitTest, OnConsumedList_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) + << "AnsSubscriberProxyBranchTest, OnConsumedList_0400, TestSize.Level1"; + sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, iremoteObject); + EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1); + std::shared_ptr proxy = std::make_shared(iremoteObject); + ASSERT_NE(nullptr, proxy); + sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); + std::vector> notifications; + notifications.emplace_back(notification); + sptr notificationMap = new (std::nothrow) NotificationSortingMap(); + proxy->OnConsumedList(notifications, notificationMap); +} + /* * @tc.name: OnCanceled_0400 * @tc.desc: test AnsSubscriberProxy's OnCanceled function @@ -241,7 +340,9 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0400, Function | MediumTest | Le EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); sptr notificationMap = new (std::nothrow) NotificationSortingMap(); ASSERT_NE(nullptr, notificationMap); @@ -264,7 +365,9 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0500, Function | MediumTest | Le EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); sptr notificationMap = new (std::nothrow) NotificationSortingMap(); ASSERT_NE(nullptr, notificationMap); @@ -308,7 +411,9 @@ HWTEST_F(AnsSubscriberProxyUnitTest, OnCanceled_0700, Function | MediumTest | Le EXPECT_CALL(*iremoteObject, SendRequest(_, _, _, _)).Times(1).WillRepeatedly(DoAll(Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - sptr notification = new (std::nothrow) OHOS::Notification::Notification(); + sptr request = new (std::nothrow) OHOS::Notification::NotificationRequest(); + ASSERT_NE(nullptr, request); + sptr notification = new (std::nothrow) OHOS::Notification::Notification(request); ASSERT_NE(nullptr, notification); int32_t deleteReason = 0; proxy->OnCanceled(notification, nullptr, deleteReason); diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn index 79476454f..fc967ba2c 100644 --- a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn +++ b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn @@ -19,11 +19,18 @@ module_output_path = "${component_name}/unittest" ohos_unittest("ans_subscriber_stub_test") { module_out_path = module_output_path - include_dirs = [ "${core_path}/include" ] + include_dirs = [ + "${core_path}/include", + "../mock/", + ] sources = [ "ans_subscriber_stub_unit_test.cpp" ] - deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] external_deps = [ "ability_base:want", diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp index 05692edf5..03b548d10 100644 --- a/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_subscriber_stub_test/ans_subscriber_stub_unit_test.cpp @@ -18,6 +18,7 @@ #define private public #define protected public #include "ans_subscriber_stub.h" +#include "ans_subscriber_proxy.h" #include "ans_inner_errors.h" #include "ans_notification.h" #undef private @@ -26,6 +27,7 @@ #include "message_option.h" #include "message_parcel.h" #include "parcel.h" +#include "mock_i_remote_object.h" using namespace testing; using namespace testing::ext; @@ -239,6 +241,103 @@ HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedMap04, Function | SmallTest EXPECT_EQ(res, ERR_OK); } +/** +* @tc.name: HandleOnConsumedListMap01 +* @tc.desc: test notification failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap01, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + ErrCode res = stub_->HandleOnConsumedListMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedListMap02 +* @tc.desc: test read existMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap02, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + std::vector> notifications; + notifications.emplace_back(notification); + + sptr remoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, remoteObject); + std::shared_ptr proxy = std::make_shared(remoteObject); + ASSERT_NE(nullptr, proxy); + bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); + EXPECT_EQ(isWriteNotificationsSucc, true); + + ErrCode res = stub_->HandleOnConsumedListMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedListMap03 +* @tc.desc: test read NotificationSortingMap failed +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap03, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + std::vector> notifications; + notifications.emplace_back(notification); + + sptr remoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, remoteObject); + std::shared_ptr proxy = std::make_shared(remoteObject); + ASSERT_NE(nullptr, proxy); + bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); + EXPECT_EQ(isWriteNotificationsSucc, true); + + bool existMap = true; + data.WriteBool(existMap); + + ErrCode res = stub_->HandleOnConsumedListMap(data, reply); + EXPECT_EQ(res, ERR_ANS_PARCELABLE_FAILED); +} + +/** +* @tc.name: HandleOnConsumedListMap04 +* @tc.desc: test HandleOnConsumedListMap success +* @tc.type: Fun +*/ +HWTEST_F(AnsSubscriberStubUnitTest, HandleOnConsumedListMap04, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + + sptr notification = new Notification(); + std::vector> notifications; + notifications.emplace_back(notification); + + sptr remoteObject = new (std::nothrow) MockIRemoteObject(); + ASSERT_NE(nullptr, remoteObject); + std::shared_ptr proxy = std::make_shared(remoteObject); + ASSERT_NE(nullptr, proxy); + bool isWriteNotificationsSucc = proxy->WriteParcelableVector(notifications, data); + EXPECT_EQ(isWriteNotificationsSucc, true); + + bool existMap = true; + data.WriteBool(existMap); + sptr notificationSortingMap = new NotificationSortingMap(); + data.WriteParcelable(notificationSortingMap); + + ErrCode res = stub_->HandleOnConsumedListMap(data, reply); + EXPECT_EQ(res, ERR_OK); +} + /** * @tc.name: HandleOnCanceledMap01 * @tc.desc: test notification failed diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 608996dff..7573f49f8 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -54,6 +54,7 @@ enum class SlotType { SERVICE_INFORMATION = 2, CONTENT_INFORMATION = 3, LIVE_VIEW = 4, + CUSTOMER_SERVICE = 5, OTHER_TYPES = 0xFFFF, }; diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index ccfc39a21..c0c9ef6a5 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -72,6 +72,7 @@ const char* BUTTON_DATA_SHARE_UPDATE_VALUE = "value"; const char* TAPDISMISSED = "tapDismissed"; const char* AUTODELETEDTIME = "autoDeletedTime"; const char* GROUP_ID = "groupId"; +const char* SNOOZE_SLOT_TYPE = "snoozeSlotType"; const int INDEX_KEY = 0; const int INDEX_TYPE = 1; const int INDEX_VALUE = 2; diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index 0232c68e6..5557e9029 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -22,6 +22,7 @@ #include "napi_common_util.h" #include "notification_action_button.h" #include "notification_capsule.h" +#include "notification_constant.h" #include "notification_progress.h" #include "notification_time.h" #include "pixel_map_napi.h" @@ -5395,6 +5396,9 @@ bool Common::SlotTypeJSToC(const SlotType &inType, NotificationConstant::SlotTyp case SlotType::LIVE_VIEW: outType = NotificationConstant::SlotType::LIVE_VIEW; break; + case SlotType::CUSTOMER_SERVICE: + outType = NotificationConstant::SlotType::CUSTOMER_SERVICE; + break; case SlotType::UNKNOWN_TYPE: case SlotType::OTHER_TYPES: outType = NotificationConstant::SlotType::OTHER; @@ -5424,6 +5428,9 @@ bool Common::SlotTypeCToJS(const NotificationConstant::SlotType &inType, SlotTyp case NotificationConstant::SlotType::LIVE_VIEW: outType = SlotType::LIVE_VIEW; break; + case NotificationConstant::SlotType::CUSTOMER_SERVICE: + outType = SlotType::CUSTOMER_SERVICE; + break; case NotificationConstant::SlotType::OTHER: outType = SlotType::OTHER_TYPES; break; diff --git a/frameworks/js/napi/src/constant.cpp b/frameworks/js/napi/src/constant.cpp index fa6711cec..c5d6fcd7b 100644 --- a/frameworks/js/napi/src/constant.cpp +++ b/frameworks/js/napi/src/constant.cpp @@ -57,6 +57,7 @@ napi_value SlotTypeInit(napi_env env, napi_value exports) SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::SERVICE_INFORMATION, "SERVICE_INFORMATION"); SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::CONTENT_INFORMATION, "CONTENT_INFORMATION"); SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::LIVE_VIEW, "LIVE_VIEW"); + SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::CUSTOMER_SERVICE, "CUSTOMER_SERVICE"); SetNamedPropertyByInteger(env, obj, (int32_t)SlotType::OTHER_TYPES, "OTHER_TYPES"); napi_property_descriptor exportFuncs[] = { diff --git a/frameworks/js/napi/src/manager/napi_get_active.cpp b/frameworks/js/napi/src/manager/napi_get_active.cpp index 9efd72f25..9df4b7d88 100644 --- a/frameworks/js/napi/src/manager/napi_get_active.cpp +++ b/frameworks/js/napi/src/manager/napi_get_active.cpp @@ -410,6 +410,8 @@ void AsyncGetLiveViewExecute(napi_env env, void *data) auto asyncLiveViewCallBackInfo = static_cast(data); if (asyncLiveViewCallBackInfo) { + asyncLiveViewCallBackInfo->info.errorCode = NotificationHelper::GetActiveNotificationByFilter( + asyncLiveViewCallBackInfo->filter, asyncLiveViewCallBackInfo->notificationRequest); } } diff --git a/frameworks/js/napi/src/manager/napi_push.cpp b/frameworks/js/napi/src/manager/napi_push.cpp index c32981123..d841af5a6 100644 --- a/frameworks/js/napi/src/manager/napi_push.cpp +++ b/frameworks/js/napi/src/manager/napi_push.cpp @@ -106,7 +106,7 @@ napi_value NapiPush::OnRegisterPushCallback(napi_env env, const napi_callback_in } jsPushCallBack_->SetJsPushCallBackObject(argv[INDEX_TWO]); - NotificationHelper::RegisterPushCallback(jsPushCallBack_->AsObject()); + NotificationHelper::RegisterPushCallback(jsPushCallBack_->AsObject(), checkRequest); return undefined; } diff --git a/frameworks/js/napi/src/manager/napi_slot.cpp b/frameworks/js/napi/src/manager/napi_slot.cpp index dc889b843..ac30b4abf 100644 --- a/frameworks/js/napi/src/manager/napi_slot.cpp +++ b/frameworks/js/napi/src/manager/napi_slot.cpp @@ -793,7 +793,8 @@ napi_value NapiEnableNotificationSlot(napi_env env, napi_callback_info info) asynccallbackinfo->info.errorCode = NotificationHelper::SetEnabledForBundleSlot( asynccallbackinfo->params.option, asynccallbackinfo->params.outType, - asynccallbackinfo->params.enable); + asynccallbackinfo->params.enable, + asynccallbackinfo->params.isForceControl); } }, [](napi_env env, napi_status status, void *data) { diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index c8b977c1c..86d2d4d72 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -762,6 +762,12 @@ napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi napi_create_int32(env, static_cast(jsSlotType), &value); napi_set_named_property(env, result, SLOT_TYPE, value); + // snoozeSlotType + NotificationNapi::SlotType jsSnoozeSlotType; + NotificationNapi::Common::SlotTypeCToJS(reminder.GetSnoozeSlotType(), jsSnoozeSlotType); + napi_create_int32(env, static_cast(jsSnoozeSlotType), &value); + napi_set_named_property(env, result, SNOOZE_SLOT_TYPE, value); + // group id napi_create_string_utf8(env, reminder.GetGroupId().c_str(), NAPI_AUTO_LENGTH, &value); napi_set_named_property(env, result, GROUP_ID, value); diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 0351e0c74..fa2ce9813 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -503,6 +503,17 @@ napi_value ReminderCommon::GenReminder( reminder->SetSlotType(actureType); } + // snoozeSlotType + int32_t snoozeSlotType = 0; + if (GetInt32(env, value, ReminderAgentNapi::SNOOZE_SLOT_TYPE, snoozeSlotType, false)) { + enum NotificationConstant::SlotType actureSnoozeType = NotificationConstant::SlotType::OTHER; + if (!NotificationNapi::Common::SlotTypeJSToC(NotificationNapi::SlotType(snoozeSlotType), actureSnoozeType)) { + ANSR_LOGW("snooze slot type not support."); + return nullptr; + } + reminder->SetSnoozeSlotType(actureSnoozeType); + } + // tapDismissed bool tapDismissed = false; if (GetBool(env, value, ReminderAgentNapi::TAPDISMISSED, tapDismissed)) { diff --git a/frameworks/js/napi/src/slot.cpp b/frameworks/js/napi/src/slot.cpp index 15276b56a..f6995b077 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -1324,7 +1324,8 @@ napi_value EnableNotificationSlot(napi_env env, napi_callback_info info) asynccallbackinfo->info.errorCode = NotificationHelper::SetEnabledForBundleSlot( asynccallbackinfo->params.option, asynccallbackinfo->params.outType, - asynccallbackinfo->params.enable); + asynccallbackinfo->params.enable, + asynccallbackinfo->params.isForceControl); } }, [](napi_env env, napi_status status, void *data) { diff --git a/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp index 51640904f..8441ecd0d 100644 --- a/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -17,6 +17,8 @@ #include "ans_inner_errors.h" #include "ans_manager_proxy.h" +#include "notification_local_live_view_content.h" +#include "notification_local_live_view_subscriber.h" #define private public #include "advanced_notification_service.h" #undef private @@ -60,6 +62,8 @@ const int32_t CASE_FOURTEEN = 14; const int32_t CASE_FIFTEEN = 15; const int32_t CASE_SIXTEEN = 16; const int32_t CASE_SEVENTEEN = 17; +const int32_t CASE_EIGHTEEN = 18; +const int32_t CASE_NINETEEN = 19; const int32_t PIXEL_MAP_TEST_WIDTH = 32; const int32_t PIXEL_MAP_TEST_HEIGHT = 32; @@ -73,9 +77,33 @@ std::mutex g_unsubscribe_mtx; std::mutex g_send_finished_mtx; AAFwk::Want g_want; +std::mutex g_system_live_view_subscribe_mtx; +std::mutex g_system_live_view_subscribe_response_mtx; +std::string g_onResponseReceivedButtonName {"testButton"}; +int32_t g_onResponseReceivedId = -1; + const time_t TIME_OUT_SECONDS_LIMIT = 5; const std::string CLASSIFICATION_ALARM {"alarm"}; +class TestLocalLiveViewSubscriber : public NotificationLocalLiveViewSubscriber { + void OnConnected() + {} + + void OnDisconnected() + {} + + void OnResponse(int32_t notificationId, sptr buttonOption) + { + GTEST_LOG_(INFO) << "OnResponse notificationId : " << notificationId; + g_onResponseReceivedId = notificationId; + g_onResponseReceivedButtonName = buttonOption->GetButtonName(); + g_system_live_view_subscribe_response_mtx.unlock(); + } + + void OnDied() + {} +}; + class TestAnsSubscriber : public NotificationSubscriber { public: void OnConnected() override @@ -198,7 +226,7 @@ private: EXPECT_NE(nullptr, notificationRequest.GetBigIcon()); EXPECT_NE(nullptr, notificationRequest.GetLittleIcon()); - EXPECT_NE(nullptr, notificationRequest.GetLittleIcon()); + EXPECT_NE(nullptr, notificationRequest.GetOverlayIcon()); std::vector> messageUser = notificationRequest.GetMessageUsers(); for (auto user : messageUser) { if (user != nullptr) { @@ -430,6 +458,7 @@ public: void WaitOnSubscribeResult(); void WaitOnConsumed(); void WaitOnUnsubscribeResult(); + void WaitOnResponse(int32_t notificationId, std::string buttonName); void CheckJsonConverter(const NotificationRequest *request); static sptr service_; @@ -514,6 +543,25 @@ void AnsInnerKitsModulePublishTest::WaitOnUnsubscribeResult() } } +void AnsInnerKitsModulePublishTest::WaitOnResponse(int32_t notificationId, std::string buttonName) +{ + struct tm publishTime = {0}; + EXPECT_EQ(OHOS::GetSystemCurrentTime(&publishTime), true); + struct tm publishDoingTime = {0}; + EXPECT_EQ(OHOS::GetSystemCurrentTime(&publishDoingTime), true); + int64_t publishSeconds = 0; + while (!g_system_live_view_subscribe_response_mtx.try_lock()) { + EXPECT_EQ(OHOS::GetSystemCurrentTime(&publishDoingTime), true); + publishSeconds = OHOS::GetSecondsBetween(publishTime, publishDoingTime); + if (publishSeconds >= TIME_OUT_SECONDS_LIMIT) { + GTEST_LOG_(INFO) << "g_system_live_view_subscribe_response_mtx.try_lock overtime"; + break; + } + } + EXPECT_EQ(g_onResponseReceivedButtonName, buttonName); + EXPECT_EQ(g_onResponseReceivedId, notificationId); +} + void AnsInnerKitsModulePublishTest::CheckJsonConverter(const NotificationRequest *request) { nlohmann::json jsonObject; @@ -1488,14 +1536,17 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Slot_Enalbe_00100, Func EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); bool enable = false; + bool isForceControl = false; NotificationBundleOption bo("bundleName", 1); - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::CONTENT_INFORMATION, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot( + bo, NotificationConstant::CONTENT_INFORMATION, enable, isForceControl)); sleep(SLEEP_TIME); EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::CONTENT_INFORMATION, enable)); GTEST_LOG_(INFO) << "ANS_Interface_MT_Slot_Enalbe_00100::end:" << enable; EXPECT_EQ(enable, false); EXPECT_EQ(ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, NotificationHelper::PublishNotification(req)); - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::CONTENT_INFORMATION, true)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot( + bo, NotificationConstant::CONTENT_INFORMATION, true, isForceControl)); } /** @@ -1522,16 +1573,19 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Slot_Enalbe_00200, Func EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); bool enable = false; + bool isForceControl = false; NotificationBundleOption bo("bundleName", 1); GTEST_LOG_(INFO) << "ANS_Interface_MT_Slot_Enalbe_00200::end:" << enable; - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, + NotificationConstant::SERVICE_REMINDER, enable, isForceControl)); sleep(SLEEP_TIME); EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); EXPECT_EQ(enable, false); EXPECT_EQ((uint32_t)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, NotificationHelper::PublishNotification(req)); enable = true; - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, + NotificationConstant::SERVICE_REMINDER, enable, isForceControl)); sleep(SLEEP_TIME); EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); EXPECT_EQ(enable, true); @@ -1594,6 +1648,97 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_09000, Function WaitOnUnsubscribeResult(); } +/** + * @tc.number : ANS_Interface_MT_Publish_10001 + * @tc.name : Publish_10001 + * @tc.desc : Add notification slot(type is LIVE_VIEW), make a subscriber, a system live view subscriber + * and publish a system live view notification. Then trigger a button. + * @tc.expected : Add notification slot success, make a subscriber, publish a notification + * and trigger a buuton success. + */ +HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_10001, Function | MediumTest | Level1) +{ + NotificationSlot slot(NotificationConstant::LIVE_VIEW); + EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot)); + auto subscriber = TestAnsSubscriber(); + g_subscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber)); + WaitOnSubscribeResult(); + + MessageUser messageUser; + std::shared_ptr liveContent = + std::make_shared(); + EXPECT_NE(liveContent, nullptr); + std::shared_ptr content = std::make_shared(liveContent); + EXPECT_NE(content, nullptr); + + NotificationRequest req; + int32_t notificationId = CASE_EIGHTEEN; + req.SetContent(content); + req.SetSlotType(NotificationConstant::LIVE_VIEW); + req.SetNotificationId(notificationId); + + g_consumed_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); + WaitOnConsumed(); + + g_unsubscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(subscriber)); + WaitOnUnsubscribeResult(); +} + +/** + * @tc.number : ANS_Interface_MT_Publish_10002 + * @tc.name : Publish_10002 + * @tc.desc : Add notification slot(type is LIVE_VIEW), make a subscriber, a system live view subscriber + * and publish a system live view notification. Then trigger a button. + * @tc.expected : Add notification slot success, make a subscriber, publish a notification + * and trigger a buuton success. + */ +HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_10002, Function | MediumTest | Level1) +{ + NotificationSlot slot(NotificationConstant::LIVE_VIEW); + EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot)); + auto subscriber = TestAnsSubscriber(); + g_subscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber)); + WaitOnSubscribeResult(); + + auto systemLiveViewSubscriber = TestLocalLiveViewSubscriber(); + EXPECT_EQ(0, NotificationHelper::SubscribeLocalLiveViewNotification(systemLiveViewSubscriber)); + + MessageUser messageUser; + std::shared_ptr liveContent = + std::make_shared(); + EXPECT_NE(liveContent, nullptr); + std::shared_ptr content = std::make_shared(liveContent); + EXPECT_NE(content, nullptr); + + NotificationRequest req; + int32_t notificationId = CASE_NINETEEN; + req.SetContent(content); + req.SetSlotType(NotificationConstant::LIVE_VIEW); + req.SetNotificationId(notificationId); + + g_consumed_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); + WaitOnConsumed(); + + std::string buttonName = "testButton"; + NotificationBundleOption bundleOption; + bundleOption.SetBundleName("bundleName"); + bundleOption.SetUid(1); + NotificationButtonOption buttonOption; + buttonOption.SetButtonName(buttonName); + g_system_live_view_subscribe_response_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::TriggerLocalLiveView(bundleOption, notificationId, buttonOption)); + WaitOnResponse(CASE_NINETEEN, buttonName); + + g_unsubscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(subscriber)); + WaitOnUnsubscribeResult(); +} + /** * @tc.name: ANS_Interface_MT_SetBadgeNumber_00100 * @tc.desc: check SetBadgeNumber interface return value. diff --git a/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp b/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp index e293563b1..6e6741da2 100644 --- a/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp +++ b/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp @@ -396,8 +396,10 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00 EXPECT_EQ(spSlot->GetEnable(), true); bool enable = false; + bool isForceControl = false; NotificationBundleOption bo("bundlename", 1); - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot( + bo, NotificationConstant::SOCIAL_COMMUNICATION, enable, isForceControl)); sleep(SLEEP_TIME); EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable)); EXPECT_EQ(enable, false); @@ -413,7 +415,8 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00 { bool enable = true; NotificationBundleOption bo("bundleName", 1); - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot( + bo, NotificationConstant::SOCIAL_COMMUNICATION, enable, false)); sleep(SLEEP_TIME); enable = false; EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SOCIAL_COMMUNICATION, enable)); @@ -434,8 +437,10 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00 HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_SetEnabledForBundleSlot_00300, Function | MediumTest | Level1) { bool enable = false; + bool isForceControl = false; NotificationBundleOption bo("bundleName", 1); - EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); + EXPECT_EQ(0, NotificationHelper::SetEnabledForBundleSlot( + bo, NotificationConstant::SERVICE_REMINDER, enable, isForceControl)); sleep(SLEEP_TIME); enable = true; EXPECT_EQ(0, NotificationHelper::GetEnabledForBundleSlot(bo, NotificationConstant::SERVICE_REMINDER, enable)); diff --git a/interfaces/inner_api/notification.h b/interfaces/inner_api/notification.h index 4f5908622..672782401 100644 --- a/interfaces/inner_api/notification.h +++ b/interfaces/inner_api/notification.h @@ -244,6 +244,48 @@ public: */ static Notification *Unmarshalling(Parcel &parcel); + /** + * @brief Obtains the update timer id. + * + * @return Returns the id of the notification update timer. + */ + uint64_t GetUpdateTimer() const; + + /** + * @brief Obtains the update timer id. + * + * @param updateTimerId the id of the notification update timer. + */ + void SetUpdateTimer(uint64_t updateTimerId); + + /** + * @brief Obtains the finish timer id of notification. + * + * @return Returns the id of the notification finish timer. + */ + uint64_t GetFinishTimer() const; + + /** + * @brief Obtains the finish timer id. + * + * @param finishTimerId the id of the notification finish timer. + */ + void SetFinishTimer(uint64_t finishTimerId); + + /** + * @brief Obtains the archive timer id of notification. + * + * @return Returns the id of the notification archive timer. + */ + uint64_t GetArchiveTimer() const; + + /** + * @brief Obtains the archive timer id. + * + * @param archiveTimerId the id of the notification archive timer. + */ + void SetArchiveTimer(uint64_t archiveTimerId); + private: Notification(); void SetEnableSound(const bool &enable); @@ -264,11 +306,13 @@ private: void ReadFromParcelString(Parcel &parcel); void ReadFromParcelInt32(Parcel &parcel); void ReadFromParcelInt64(Parcel &parcel); + void ReadFromParcelUint64(Parcel &parcel); void ReadFromParcelParcelable(Parcel &parcel); bool MarshallingBool(Parcel &parcel) const; bool MarshallingString(Parcel &parcel) const; bool MarshallingInt32(Parcel &parcel) const; bool MarshallingInt64(Parcel &parcel) const; + bool MarshallingUint64(Parcel &parcel) const; bool MarshallingParcelable(Parcel &parcel) const; private: @@ -284,6 +328,9 @@ private: NotificationConstant::SourceType sourceType_ {NotificationConstant::SourceType::TYPE_NORMAL}; sptr request_ {nullptr}; int64_t postTime_ {0}; + uint64_t updateTimerId_ {0}; + uint64_t finishTimerId_ {0}; + uint64_t archiveTimerId_ {0}; std::shared_ptr sound_ {nullptr}; std::vector vibrationStyle_ {}; diff --git a/interfaces/inner_api/notification_bundle_option.h b/interfaces/inner_api/notification_bundle_option.h index 60467a4d3..edc288710 100644 --- a/interfaces/inner_api/notification_bundle_option.h +++ b/interfaces/inner_api/notification_bundle_option.h @@ -16,11 +16,12 @@ #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUNDLE_OPTION_H #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUNDLE_OPTION_H +#include "notification_json_convert.h" #include "parcel.h" namespace OHOS { namespace Notification { -class NotificationBundleOption : public Parcelable { +class NotificationBundleOption : public Parcelable, public NotificationJsonConvertionBase { public: NotificationBundleOption() = default; @@ -85,6 +86,22 @@ public: */ static NotificationBundleOption *Unmarshalling(Parcel &parcel); + /** + * @brief Converts a notification bundle option object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a bundle option object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationBundleOption. + */ + static NotificationBundleOption *FromJson(const nlohmann::json &jsonObject); + private: /** * @brief Read data from a Parcel. diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index 3413024da..875c4600f 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -63,6 +63,7 @@ public: OTHER, // the notificatin type is other CUSTOM, // the notification type is custom LIVE_VIEW, // the notification type is live view + CUSTOMER_SERVICE, // the notification type is customer service }; enum class VisiblenessType { @@ -182,6 +183,22 @@ public: */ static const std::string EXTRA_INPUTS_SOURCE; + static const int64_t HOUR_TO_MS = 3600000; + + static const int64_t SECOND_TO_MS = 1000; + + static const int64_t MAX_FINISH_TIME = 8 * HOUR_TO_MS; + + static const int64_t MAX_UPDATE_TIME = 4 * HOUR_TO_MS; + + static const int64_t INVALID_AUTO_DELETE_TIME = -1; + + /* one hour */ + static const int64_t DEFAULT_AUTO_DELETE_TIME = 3600; + + static constexpr uint64_t INVALID_TIMER_ID = 0ULL; + + static constexpr uint64_t NOTIFICATION_MAX_LIVE_VIEW_SIZE = 520ULL * 1024ULL; // rdb constexpr static const char* NOTIFICATION_RDB_NAME = "/notificationdb.db"; constexpr static const char* NOTIFICATION_RDB_TABLE_NAME = "notification_table"; @@ -193,4 +210,4 @@ public: } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_CONSTANT_H \ No newline at end of file +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_CONSTANT_H diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index e07cd0d17..2b2a932a0 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -26,6 +26,7 @@ #include "notification_sorting_map.h" #include "notification_subscriber.h" #include "notification_local_live_view_subscriber.h" +#include "want_params.h" namespace OHOS { namespace Notification { @@ -471,6 +472,16 @@ public: static ErrCode GetAllActiveNotifications( const std::vector key, std::vector> ¬ification); + /** + * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method + * to obtain particular live view notification extra info by filter, you must + * @param filter + * @param extraInfo + * @return + */ + static ErrCode GetActiveNotificationByFilter( + const LiveViewFilter &filter, sptr &request); + /** * @brief Checks whether a specified application has the permission to publish notifications. If bundle specifies * the current application, no permission is required for calling this method. If bundle specifies another @@ -732,10 +743,11 @@ public: * @param bundleOption Indicates the bundle name and uid of the application. * @param slotType Indicates type of slot. * @param enabled the type of slot enabled. + * @param isForceControl Indicates whether the slot is affected by the notification switch. * @return Returns get slot number by bundle result. */ - static ErrCode SetEnabledForBundleSlot( - const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled); + static ErrCode SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl); /** * Obtains whether the application slot is enabled. @@ -748,6 +760,15 @@ public: static ErrCode GetEnabledForBundleSlot( const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled); + /** + * Obtains whether the current application slot is enabled. + * + * @param slotType Indicates type of slot. + * @param enabled the type of slot enabled to get. + * @return Returns get enabled result. + */ + static ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled); + /** * @brief Set whether to sync notifications to devices that do not have the app installed. * @@ -778,9 +799,11 @@ public: * @brief Register Push Callback. * * @param pushCallback push appliction's Callback. + * @param notificationCheckRequest Filter conditions for push check. * @return Returns register push callback result. */ - static ErrCode RegisterPushCallback(const sptr& pushCallback); + static ErrCode RegisterPushCallback( + const sptr& pushCallback, const sptr ¬ificationCheckRequest); /** * @brief Unregister Push Callback. diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index baa5a7b46..c813cd619 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -19,6 +19,7 @@ #include "ans_const_define.h" #include "message_user.h" #include "notification_action_button.h" +#include "notification_constant.h" #include "notification_content.h" #include "notification_distributed_options.h" #include "notification_flags.h" @@ -425,6 +426,54 @@ public: */ int64_t GetAutoDeletedTime() const; + /** + * @brief Sets the update deadline time before deleting a notification. + * + * @param maxUpdateTime Indicates the time in milliseconds. + * The default value is 0, indicating that the notification will not be automatically deleted. + * To enable the notification to be automatically deleted, set this parameter to an integer greater than 0. + */ + void SetMaxUpdateTime(int64_t maxUpdateTime); + + /** + * @brief Obtains the time point which a notification must be updated. + * + * @return Returns the time point in milliseconds. + */ + int64_t GetMaxUpdateTime() const; + + /** + * @brief Sets the finish deadline time before deleting a notification. + * + * @param maxFinishTime Indicates the time in milliseconds. + * The default value is 0, indicating that the notification will not be automatically deleted. + * To enable the notification to be automatically deleted, set this parameter to an integer greater than 0. + */ + void SetMaxFinishTime(int64_t maxUpdateTime); + + /** + * @brief Obtains the time point which a notification must be finished. + * + * @return Returns the time point in milliseconds. + */ + int64_t GetMaxFinishTime() const; + + /** + * @brief Sets the finish deadline time before deleting a notification. + * + * @param maxFinishTime Indicates the time in milliseconds. + * The default value is 0, indicating that the notification will not be automatically deleted. + * To enable the notification to be automatically deleted, set this parameter to an integer greater than 0. + */ + void SetMaxArchiveTime(int64_t maxArchiveTime); + + /** + * @brief Obtains the time point which a notification must be finished. + * + * @return Returns the time point in milliseconds. + */ + int64_t GetMaxArchiveTime() const; + /** * @brief Sets the little icon of the notification. * @@ -1101,6 +1150,62 @@ public: void SetRemoveAllowed(bool isRemoveAllowed); + bool IsCommonLiveView() const; + + /** + * @brief Checks whether the image size exceeds the limit in content. + * + * @param pixelMap Indicates the image smart pointer. + * @param maxSize The max size of image. + * @return Returns the ErrCode. + */ + static bool CheckImageOverSizeForPixelMap(const std::shared_ptr &pixelMap, uint32_t maxSize); + + /** + * @brief Checks whether the picture size exceeds the limit in content. + * + * @param request Indicates the specified request. + * @return Returns the ErrCode. + */ + ErrCode CheckNotificationRequest(const sptr &oldRequest) const; + + /** + * @brief Fill missing parameters of the current notification request. + * + * @param oldRequest Indicates the old request. + */ + void FillMissingParameters(const sptr &oldRequest); + + /** + * @brief Generate notification request key. + * + * @param creatorUserId Indicates the user id of creator. + * @param creatorUid Indicates the uid of creator. + * @param label Indicates the label of notification request. + * @param notificationId Indicates the ID of notification request, different apps may have same value. + * @return Return the unique key of notification request. + */ + static std::string GenerateNotificationRequestKey(int32_t creatorUserId, + int32_t creatorUid, const std::string &label, int32_t notificationId); + + /** + * @brief Get notification request key. + * + * @return Return the unique key of notification request. + */ + std::string GetKey(); + + /** + * @brief Check the image size in content. + * + * @return Return the check result, ERR_OK: check pass, others: not pass. + */ + ErrCode CheckImageSizeForContent() const; + /** + * Key prefix of notification request + */ + static const std::string KEY_PREFIX; + private: /** * Indicates the color mask, used for calculation with the ARGB value set by setColor(int32_t). @@ -1142,8 +1247,10 @@ private: void CopyOther(const NotificationRequest &other); bool ConvertObjectsToJson(nlohmann::json &jsonObject) const; + ErrCode CheckVersion(const sptr &oldRequest) const; static void ConvertJsonToNum(NotificationRequest *target, const nlohmann::json &jsonObject); + static void ConvertJsonToNumExt(NotificationRequest *target, const nlohmann::json &jsonObject); static void ConvertJsonToString(NotificationRequest *target, const nlohmann::json &jsonObject); static void ConvertJsonToEnum(NotificationRequest *target, const nlohmann::json &jsonObject); static void ConvertJsonToBool(NotificationRequest *target, const nlohmann::json &jsonObject); @@ -1153,6 +1260,9 @@ private: static bool ConvertJsonToNotificationDistributedOptions( NotificationRequest *target, const nlohmann::json &jsonObject); static bool ConvertJsonToNotificationFlags(NotificationRequest *target, const nlohmann::json &jsonObject); + static ErrCode CheckImageSizeForConverSation(std::shared_ptr &content); + static ErrCode CheckImageSizeForPicture(std::shared_ptr &content); + static ErrCode CheckImageSizeForLiveView(std::shared_ptr &content); private: int32_t notificationId_ {0}; @@ -1162,8 +1272,10 @@ private: int32_t progressMax_ {0}; int64_t createTime_ {0}; int64_t deliveryTime_ {0}; - int64_t autoDeletedTime_ {0}; - + int64_t autoDeletedTime_ {NotificationConstant::INVALID_AUTO_DELETE_TIME}; + int64_t maxUpdateTime_ {0}; + int64_t maxFinishTime_ {0}; + int64_t maxArchiveTime_ {0}; pid_t creatorPid_ {0}; int32_t creatorUid_ {0}; int32_t ownerUid_ {0}; diff --git a/interfaces/inner_api/notification_subscriber.h b/interfaces/inner_api/notification_subscriber.h index eec196e3c..0f2ad926f 100644 --- a/interfaces/inner_api/notification_subscriber.h +++ b/interfaces/inner_api/notification_subscriber.h @@ -120,6 +120,9 @@ private: void OnConsumed( const sptr ¬ification, const sptr ¬ificationMap) override; + void OnConsumedList(const std::vector> ¬ifications, + const sptr ¬ificationMap) override; + void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, int32_t deleteReason) override; diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index a174bfa93..b96f031e7 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -378,6 +378,13 @@ public: */ NotificationConstant::SlotType GetSlotType() const; + /** + * @brief Obtains snoozeSlot type. + * + * @return snoozeSlot type. + */ + NotificationConstant::SlotType GetSnoozeSlotType() const; + std::string GetSnoozeContent() const; uint8_t GetSnoozeTimes() const; uint8_t GetSnoozeTimesDynamic() const; @@ -577,8 +584,6 @@ public: * @param resultSet Indicates the resultSet with pointer to the row of record data. */ virtual void RecoverFromDb(const std::shared_ptr &resultSet); - void RecoverActionButton(const std::shared_ptr &resultSet); - void RecoverWantAgent(const std::string &wantAgentInfo, const uint8_t &type); /** * @brief Sets action button. @@ -657,7 +662,7 @@ public: * @return Current reminder self. */ ReminderRequest& SetSlotType(const NotificationConstant::SlotType &slotType); - + ReminderRequest& SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType); ReminderRequest& SetSnoozeContent(const std::string &snoozeContent); /** @@ -875,6 +880,7 @@ public: static const std::string ACTION_BUTTON_INFO; static const std::string CUSTOM_BUTTON_URI; static const std::string SLOT_ID; + static const std::string SNOOZE_SLOT_ID; static const std::string NOTIFICATION_ID; static const std::string TITLE; static const std::string CONTENT; @@ -901,6 +907,7 @@ protected: { return INVALID_LONG_LONG_VALUE; } + int64_t RecoverInt64FromDb(const std::shared_ptr &resultSet, const std::string &columnName, const DbRecoveryType &columnType); @@ -950,7 +957,7 @@ private: void UpdateActionButtons(const bool &setSnooze); bool UpdateNextReminder(const bool &force); void UpdateNotificationContent(const bool &setSnooze); - void UpdateNotificationCommon(); + void UpdateNotificationCommon(bool isSnooze); /** * @brief Determine whether it is repeated every week. @@ -980,6 +987,17 @@ private: */ void UpdateNotificationStateForSnooze(); + static void AppendWantAgentValuesBucket(const sptr& reminder, + NativeRdb::ValuesBucket& values); + + bool MarshallingActionButton(Parcel& parcel) const; + bool ReadActionButtonFromParcel(Parcel& parcel); + + void RecoverBasicFromDb(const std::shared_ptr& resultSet); + void RecoverActionButtonJsonMode(const std::string& jsonString); + void RecoverActionButton(const std::shared_ptr& resultSet); + void RecoverWantAgent(const std::string& wantAgentInfo, const uint8_t& type); + static const uint32_t MIN_TIME_INTERVAL_IN_MILLI; static const std::string SEP_BUTTON_SINGLE; static const std::string SEP_BUTTON_MULTI; @@ -1013,6 +1031,7 @@ private: uint64_t timeIntervalInMilli_ {0}; ReminderType reminderType_ {ReminderType::INVALID}; NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::SOCIAL_COMMUNICATION}; + NotificationConstant::SlotType snoozeSlotType_ {NotificationConstant::SlotType::OTHER}; sptr notificationRequest_ = nullptr; std::shared_ptr wantAgentInfo_ = nullptr; std::shared_ptr maxScreenWantAgentInfo_ = nullptr; diff --git a/interfaces/inner_api/reminder_request_alarm.h b/interfaces/inner_api/reminder_request_alarm.h index a70a57a96..1eea3c0f6 100644 --- a/interfaces/inner_api/reminder_request_alarm.h +++ b/interfaces/inner_api/reminder_request_alarm.h @@ -128,10 +128,6 @@ private: uint8_t hour_ = {0}; uint8_t minute_ = {0}; - - // For database recovery. - static const std::string ALARM_HOUR; - static const std::string ALARM_MINUTE; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/reminder_request_calendar.h b/interfaces/inner_api/reminder_request_calendar.h index 72b2cb620..88e5c4108 100644 --- a/interfaces/inner_api/reminder_request_calendar.h +++ b/interfaces/inner_api/reminder_request_calendar.h @@ -208,18 +208,6 @@ private: uint16_t repeatMonth_ {0}; uint32_t repeatDay_ {0}; - // For database recovery. - static const std::string REPEAT_DAYS; - static const std::string REPEAT_MONTHS; - static const std::string FIRST_DESIGNATE_YEAR; - static const std::string FIRST_DESIGNATE_MONTH; - static const std::string FIRST_DESIGNATE_DAY; - static const std::string CALENDAR_YEAR; - static const std::string CALENDAR_MONTH; - static const std::string CALENDAR_DAY; - static const std::string CALENDAR_HOUR; - static const std::string CALENDAR_MINUTE; - static const uint8_t DAY_ARRAY[12]; static const uint8_t FEBRUARY; static const uint8_t LEAP_MONTH; diff --git a/interfaces/inner_api/reminder_store.h b/interfaces/inner_api/reminder_store.h index 58be32314..4cea9b68b 100644 --- a/interfaces/inner_api/reminder_store.h +++ b/interfaces/inner_api/reminder_store.h @@ -73,7 +73,8 @@ private: 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); - + static void AddRdbColum(NativeRdb::RdbStore &rdbStore, const std::string &columName, + const std::string &type); class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback { public: int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; diff --git a/interfaces/inner_api/reminder_table.h b/interfaces/inner_api/reminder_table.h new file mode 100644 index 000000000..8ac8c7b91 --- /dev/null +++ b/interfaces/inner_api/reminder_table.h @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_H + +#include +#include + +namespace OHOS { +namespace Notification { +class ReminderTable { +public: + static void InitDbColumns(); + + // Reminder Table Basic Columns. + + /* + * reminder id + */ + static const std::string REMINDER_ID; + + /* + * package name + */ + static const std::string PKG_NAME; + + /* + * user id + */ + static const std::string USER_ID; + + /* + * uid + */ + static const std::string UID; + + /* + * systerm app flag + */ + static const std::string SYS_APP; + + /* + * app label + */ + static const std::string APP_LABEL; + + /* + * reminder type: Timer/Calendar/Alarm + */ + static const std::string REMINDER_TYPE; + + /* + * reminder time + */ + static const std::string REMINDER_TIME; + + /* + * trigger time + */ + static const std::string TRIGGER_TIME; + + /* + * RTC trigger time + */ + static const std::string RTC_TRIGGER_TIME; + + /* + * time interval + */ + static const std::string TIME_INTERVAL; + + /* + * snooze times + */ + static const std::string SNOOZE_TIMES; + + /* + * dynamic snooze times + */ + static const std::string DYNAMIC_SNOOZE_TIMES; + + /* + * ring duration + */ + static const std::string RING_DURATION; + + /* + * expired flag + */ + static const std::string IS_EXPIRED; + + /* + * active flag + */ + static const std::string IS_ACTIVE; + + /* + * reminder state + */ + static const std::string STATE; + + /* + * zone id + */ + static const std::string ZONE_ID; + + /* + * scheduled timeout flag + */ + static const std::string HAS_SCHEDULED_TIMEOUT; + + /* + * action button information + */ + static const std::string ACTION_BUTTON_INFO; + + /* + * custom button uri + */ + static const std::string CUSTOM_BUTTON_URI; + + /* + * slot type + */ + static const std::string SLOT_ID; + + /* + * snoozeslot type + */ + static const std::string SNOOZE_SLOT_ID; + + /* + * notification id + */ + static const std::string NOTIFICATION_ID; + + /* + * notification title + */ + static const std::string TITLE; + + /* + * notification content + */ + static const std::string CONTENT; + + /* + * notification snooze content + */ + static const std::string SNOOZE_CONTENT; + + /* + * notification expired content + */ + static const std::string EXPIRED_CONTENT; + + /* + * agent information + */ + static const std::string AGENT; + + /* + * max screen agent information + */ + static const std::string MAX_SCREEN_AGENT; + + /* + * tap dismissed flag + */ + static const std::string TAP_DISMISSED; + + /* + * auto deleted time + */ + static const std::string AUTO_DELETED_TIME; + + /* + * repeat days of week + */ + static const std::string REPEAT_DAYS_OF_WEEK; + + /* + * reminder group id + */ + static const std::string GROUP_ID; + + // Reminder Table Calendar Columns. + static const std::string REPEAT_DAYS; + static const std::string REPEAT_MONTHS; + static const std::string FIRST_DESIGNATE_YEAR; + static const std::string FIRST_DESIGNATE_MONTH; + static const std::string FIRST_DESIGNATE_DAY; + static const std::string CALENDAR_YEAR; + static const std::string CALENDAR_MONTH; + static const std::string CALENDAR_DAY; + static const std::string CALENDAR_HOUR; + static const std::string CALENDAR_MINUTE; + + // Reminder Table Alarm Columns. + static const std::string ALARM_HOUR; + static const std::string ALARM_MINUTE; + + static std::string sqlOfAddColumns; + static std::vector columns; + +private: + static void InitBasicColumns(); + static void InitCalendarColumns(); + static void InitAlarmColumns(); + static void AddColumn(const std::string& name, const std::string& type, bool isEnd = false); +}; +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_H \ No newline at end of file diff --git a/notification.gni b/notification.gni index 2050243d6..f6991faa6 100644 --- a/notification.gni +++ b/notification.gni @@ -53,6 +53,7 @@ declare_args() { hisysevent_usage = true standby_enable = true player_framework = true + ans_hitrace_usage = true if (defined(global_parts_info) && !defined(global_parts_info.resourceschedule_device_usage_statistics)) { @@ -74,5 +75,11 @@ declare_args() { player_framework = false } + if (defined(global_parts_info) && + !defined(global_parts_info.hiviewdfx_hitrace)) { + ans_hitrace_usage = false + } + print("hisysevent_usage = " + "$hisysevent_usage") + print("ans_hitrace_usage = " + "$ans_hitrace_usage") } diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index b52fcd3a2..a1a5c4fb5 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -101,7 +101,6 @@ ohos_shared_library("libans") { "data_share:datashare_consumer", "device_manager:devicemanagersdk", "ffrt:libffrt", - "hitrace:hitrace_meter", "i18n:intl_util", "image_framework:image_native", "kv_store:distributeddata_inner", @@ -132,6 +131,11 @@ ohos_shared_library("libans") { defines += [ "PLAYER_FRAMEWORK_ENABLE" ] } + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + defines += [ "HITRACE_METER_ENABLE" ] + } + subsystem_name = "${subsystem_name}" part_name = "${component_name}" } diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index eb54f4259..6fb39418f 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -658,7 +658,7 @@ public: */ ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr &date) override; ErrCode SetEnabledForBundleSlot(const sptr &bundleOption, - const NotificationConstant::SlotType &slotType, bool enabled) override; + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override; ErrCode GetEnabledForBundleSlot(const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled) override; @@ -762,7 +762,8 @@ public: * @param pushCallback PushCallBack. * @return Returns register push Callback result. */ - ErrCode RegisterPushCallback(const sptr& pushCallback) override; + ErrCode RegisterPushCallback(const sptr& pushCallback, + const sptr ¬ificationCheckRequest) override; /** * @brief Unregister Push Callback. diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 0c08c0462..0c57a3242 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -524,7 +524,7 @@ private: void UpdateAndSaveReminderLocked( const sptr &reminder, const sptr &bundleOption); - void UpdateNotification(const sptr &reminder); + void UpdateNotification(const sptr &reminder, bool isSnooze); static bool cmp(sptr &reminderRequest, sptr &other); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 185a853fe..bf4aae974 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -35,7 +35,7 @@ #include "common_event_manager.h" #include "common_event_support.h" #include "event_report.h" -#include "hitrace_meter.h" +#include "hitrace_meter_adapter.h" #include "ipc_skeleton.h" #include "nlohmann/json.hpp" #include "notification_constant.h" @@ -368,6 +368,7 @@ void AdvancedNotificationService::SelfClean() NotificationSubscriberManager::GetInstance()->ResetFfrtQueue(); DistributedNotificationManager::GetInstance()->ResetFfrtQueue(); + NotificationLocalLiveViewSubscriberManager::GetInstance()->ResetFfrtQueue(); } ErrCode AdvancedNotificationService::SetDefaultNotificationEnabled( @@ -1550,11 +1551,6 @@ ErrCode AdvancedNotificationService::SubscribeLocalLiveView( break; } - if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { - errCode = ERR_ANS_PERMISSION_DENIED; - break; - } - errCode = NotificationLocalLiveViewSubscriberManager::GetInstance()->AddLocalLiveViewSubscriber( subscriber, info); if (errCode != ERR_OK) { @@ -4337,8 +4333,8 @@ void AdvancedNotificationService::OnBundleDataCleared(const sptrwait(handler); } -ErrCode AdvancedNotificationService::SetEnabledForBundleSlot( - const sptr &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled) +ErrCode AdvancedNotificationService::SetEnabledForBundleSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("slotType: %{public}d, enabled: %{public}d", slotType, enabled); @@ -4772,11 +4768,20 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptrGetBundleNameByUid(uid); - if (request->GetCreatorBundleName().empty()) { - request->SetCreatorBundleName(bundle); - } - if (request->GetOwnerBundleName().empty()) { - request->SetOwnerBundleName(bundle); + if (!bundle.empty()) { + if (request->GetCreatorBundleName().empty()) { + request->SetCreatorBundleName(bundle); + } + if (request->GetOwnerBundleName().empty()) { + request->SetOwnerBundleName(bundle); + } + } else { + if (!request->GetCreatorBundleName().empty()) { + bundle = request->GetCreatorBundleName(); + } + if (!request->GetOwnerBundleName().empty()) { + bundle = request->GetOwnerBundleName(); + } } request->SetCreatorPid(IPCSkeleton::GetCallingPid()); @@ -4794,17 +4799,14 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptr bundleOption = new (std::nothrow) NotificationBundleOption(bundle, uid); - if (bundleOption == nullptr) { + std::shared_ptr record = std::make_shared(); + record->request = request; + record->bundleOption = new (std::nothrow) NotificationBundleOption(bundle, uid); + if (record->bundleOption == nullptr) { ANS_LOGE("Failed to create bundleOption"); return ERR_ANS_NO_MEMORY; } - - std::shared_ptr record = std::make_shared(); - record->request = request; - record->bundleOption = bundleOption; record->notification = new (std::nothrow) Notification(request); - if (record->notification == nullptr) { ANS_LOGE("Failed to create notification"); return ERR_ANS_NO_MEMORY; @@ -4815,6 +4817,12 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptrsubmit_h([this, &record]() { + if (!record->bundleOption->GetBundleName().empty()) { + ErrCode ret = AssignValidNotificationSlot(record); + if (ret != ERR_OK) { + ANS_LOGE("Can not assign valid slot!"); + } + } if (AssignToNotificationList(record) != ERR_OK) { ANS_LOGE("Failed to assign notification list"); return; @@ -4864,7 +4872,8 @@ void AdvancedNotificationService::ResetPushCallbackProxy() pushCallBack_ = nullptr; } -ErrCode AdvancedNotificationService::RegisterPushCallback(const sptr &pushCallback) +ErrCode AdvancedNotificationService::RegisterPushCallback( + const sptr &pushCallback, const sptr ¬ificationCheckRequest) { if (!AccessTokenHelper::IsSystemApp()) { ANS_LOGW("Not system app!"); diff --git a/services/ans/src/notification_local_live_view_subscriber_manager.cpp b/services/ans/src/notification_local_live_view_subscriber_manager.cpp index 13e5cb00a..820c20041 100644 --- a/services/ans/src/notification_local_live_view_subscriber_manager.cpp +++ b/services/ans/src/notification_local_live_view_subscriber_manager.cpp @@ -23,7 +23,7 @@ #include "ans_inner_errors.h" #include "ans_log_wrapper.h" #include "ans_watchdog.h" -#include "hitrace_meter.h" +#include "hitrace_meter_adapter.h" #include "ipc_skeleton.h" #include "notification_bundle_option.h" #include "notification_button_option.h" diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 60662adc6..e9b3fad21 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -21,7 +21,7 @@ #include "ans_inner_errors.h" #include "ans_log_wrapper.h" #include "bundle_manager_helper.h" -#include "hitrace_meter.h" +#include "hitrace_meter_adapter.h" #include "nlohmann/json.hpp" #include "os_account_manager.h" diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index 40dc39b95..fc77905c6 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -17,7 +17,7 @@ #include "ans_const_define.h" #include "ans_log_wrapper.h" -#include "hitrace_meter.h" +#include "hitrace_meter_adapter.h" #include "os_account_manager.h" #include "uri.h" diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 389e787b4..01e2078ba 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -23,7 +23,7 @@ #include "ans_inner_errors.h" #include "ans_log_wrapper.h" #include "ans_watchdog.h" -#include "hitrace_meter.h" +#include "hitrace_meter_adapter.h" #include "ipc_skeleton.h" #include "os_account_manager.h" #include "remote_death_recipient.h" diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index b91ea9b2d..7ba849531 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -780,7 +780,7 @@ void ReminderDataManager::TerminateAlerting(const sptr &reminde return; } ANSR_LOGD("publish(update) notification.(reminderId=%{public}d)", reminder->GetReminderId()); - UpdateNotification(reminder); + UpdateNotification(reminder, false); if (advancedNotificationService_ == nullptr) { ANSR_LOGE("Ans instance is null."); return; @@ -982,7 +982,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co bool toPlaySound = isNeedToPlaySound && ShouldAlert(reminder) ? true : false; reminder->OnShow(toPlaySound, isSysTimeChanged, true); AddToShowedReminders(reminder); - UpdateNotification(reminder); // this should be called after OnShow + UpdateNotification(reminder, false); // this should be called after OnShow if (alertingReminderId_ != -1) { TerminateAlerting(alertingReminder_, "PlaySoundAndVibration"); @@ -1010,7 +1010,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co } } -void ReminderDataManager::UpdateNotification(const sptr &reminder) +void ReminderDataManager::UpdateNotification(const sptr &reminder, bool isSnooze) { int32_t reminderId = reminder->GetReminderId(); sptr bundleOption = FindNotificationBundleOption(reminderId); @@ -1018,7 +1018,11 @@ void ReminderDataManager::UpdateNotification(const sptr &remind ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); return; } - reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::COMMON, ""); + if (isSnooze) { + reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::COMMON, "snooze"); + } else { + reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::COMMON, ""); + } reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::REMOVAL_WANT_AGENT, ""); reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::WANT_AGENT, ""); reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::MAX_SCREEN_WANT_AGENT, ""); @@ -1064,7 +1068,7 @@ void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) return; } ANSR_LOGD("publish(update) notification.(reminderId=%{public}d)", reminder->GetReminderId()); - UpdateNotification(reminder); + UpdateNotification(reminder, true); if (advancedNotificationService_ == nullptr) { ANSR_LOGE("Ans instance is null"); return; diff --git a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp index 8e4daa5bf..3741615eb 100644 --- a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp @@ -996,7 +996,7 @@ HWTEST_F(AnsBranchTest, AnsBranchTest_270000, Function | SmallTest | Level1) bool enabled = false; auto result = advancedNotificationService_->SetEnabledForBundleSlot( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), - NotificationConstant::SlotType::SOCIAL_COMMUNICATION, enabled); + NotificationConstant::SlotType::SOCIAL_COMMUNICATION, enabled, false); EXPECT_EQ(result, ERR_ANS_PERMISSION_DENIED); auto result1 = advancedNotificationService_->GetEnabledForBundleSlot( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 9619465de..7eb1e22b4 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1543,7 +1543,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12100, auto result = advancedNotificationService_->SetEnabledForBundleSlot( new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), NotificationConstant::SlotType::SOCIAL_COMMUNICATION, - false); + false, false); EXPECT_EQ(result, (int)ERR_OK); IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); @@ -2443,7 +2443,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17100, EXPECT_EQ(advancedNotificationService_->GetDoNotDisturbDate(userId, date), ERR_OK); EXPECT_EQ(advancedNotificationService_->SetEnabledForBundleSlot(bundleOption, - NotificationConstant::SlotType::OTHER, enable), ERR_OK); + NotificationConstant::SlotType::OTHER, enable, false), ERR_OK); EXPECT_EQ(advancedNotificationService_->GetEnabledForBundleSlot(bundleOption, NotificationConstant::SlotType::OTHER, enable), ERR_OK); diff --git a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp index 9b18d001e..459bc8e0e 100755 --- a/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_branch_test/notification_subscriber_manager_branch_test.cpp @@ -1249,7 +1249,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_05 MockVerifyNativeToken(false); MockVerifyCallerPermission(false); AdvancedNotificationService advancedNotificationService; - EXPECT_EQ(advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled), + EXPECT_EQ(advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled, false, false), ERR_ANS_NON_SYSTEM_APP); } @@ -1270,7 +1270,7 @@ HWTEST_F(NotificationSubscriberManagerBranchTest, AdvancedNotificationService_06 int32_t notificationId = 0; bundleOption->SetUid(notificationId); AdvancedNotificationService advancedNotificationService; - EXPECT_EQ(advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled), + EXPECT_EQ(advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled, false), ERR_ANS_INVALID_BUNDLE); } diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index 35a5002c4..07554f3a3 100644 --- a/services/distributed/BUILD.gn +++ b/services/distributed/BUILD.gn @@ -46,6 +46,8 @@ ohos_shared_library("libans_distributed") { include_dirs = [ "include" ] + defines = [] + configs = [ ":ans_distributed_config", "${frameworks_module_ans_path}:ans_innerkits_public_config", @@ -61,10 +63,14 @@ ohos_shared_library("libans_distributed") { "eventhandler:libeventhandler", "ffrt:libffrt", "hilog:libhilog", - "hitrace:hitrace_meter", "kv_store:distributeddata_inner", ] + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + defines += [ "HITRACE_METER_ENABLE" ] + } + subsystem_name = "${subsystem_name}" part_name = "${component_name}" } diff --git a/services/distributed/src/distributed_notification_manager.cpp b/services/distributed/src/distributed_notification_manager.cpp index 0bfc91fa8..7e179d565 100644 --- a/services/distributed/src/distributed_notification_manager.cpp +++ b/services/distributed/src/distributed_notification_manager.cpp @@ -20,7 +20,7 @@ #include "ans_inner_errors.h" #include "ans_log_wrapper.h" #include "ans_watchdog.h" -#include "hitrace_meter.h" +#include "hitrace_meter_adapter.h" namespace OHOS { namespace Notification { diff --git a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp index 14960ef70..919bdbd48 100644 --- a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp @@ -123,7 +123,7 @@ namespace OHOS { advancedNotificationService.DeleteAllByUser(userId); advancedNotificationService.SetDoNotDisturbDate(date); advancedNotificationService.GetDoNotDisturbDate(date); - advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled); + advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled, false); advancedNotificationService.GetEnabledForBundleSlot(bundleOption, slotType, enabled); std::vector dumpInfo; advancedNotificationService.ShellDump(stringData, stringData, userId, dumpInfo); diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index db837e18f..4a0c554a6 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -191,7 +191,7 @@ namespace OHOS { ansManagerStub.DeleteAllByUser(userId); ansManagerStub.SetDoNotDisturbDate(date); ansManagerStub.GetDoNotDisturbDate(date); - ansManagerStub.SetEnabledForBundleSlot(bundleOption, slotType, enabled); + ansManagerStub.SetEnabledForBundleSlot(bundleOption, slotType, enabled, false); ansManagerStub.GetEnabledForBundleSlot(bundleOption, slotType, enabled); std::vector dumpInfo; ansManagerStub.ShellDump(stringData, stringData, userId, dumpInfo); diff --git a/test/fuzztest/setdonotdisturbdate_fuzzer/setdonotdisturbdate_fuzzer.cpp b/test/fuzztest/setdonotdisturbdate_fuzzer/setdonotdisturbdate_fuzzer.cpp index a71c82721..3a18c1714 100644 --- a/test/fuzztest/setdonotdisturbdate_fuzzer/setdonotdisturbdate_fuzzer.cpp +++ b/test/fuzztest/setdonotdisturbdate_fuzzer/setdonotdisturbdate_fuzzer.cpp @@ -41,7 +41,7 @@ namespace OHOS { uint8_t types = *data % SLOT_TYPE_NUM; Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(types); bool enabled = *data % ENABLE; - Notification::NotificationHelper::SetEnabledForBundleSlot(bundleOption, slotType, enabled); + Notification::NotificationHelper::SetEnabledForBundleSlot(bundleOption, slotType, enabled, false); // test GetEnabledForBundleSlot function Notification::NotificationHelper::GetEnabledForBundleSlot(bundleOption, slotType, enabled); // test SetSyncNotificationEnabledWithoutApp function diff --git a/tools/dump/BUILD.gn b/tools/dump/BUILD.gn index bb30ed04f..f4b04fed2 100644 --- a/tools/dump/BUILD.gn +++ b/tools/dump/BUILD.gn @@ -58,6 +58,10 @@ ohos_executable("anm") { defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] } + if (build_variant == "user") { + defines += [ "ANM_BUILD_VARIANT_USER" ] + } + external_deps = [ "access_token:libnativetoken", "access_token:libtoken_setproc", diff --git a/tools/dump/src/notification_shell_command.cpp b/tools/dump/src/notification_shell_command.cpp index 3ca804a45..df6c1e0de 100644 --- a/tools/dump/src/notification_shell_command.cpp +++ b/tools/dump/src/notification_shell_command.cpp @@ -248,6 +248,10 @@ void NotificationShellCommand::CheckDumpOpt() ErrCode NotificationShellCommand::RunAsSettingCommand() { +#ifdef ANM_BUILD_VARIANT_USER + resultReceiver_.append("error: user version cannot use setting.\n"); + return ERR_INVALID_VALUE; +#endif int option = getopt_long(argc_, argv_, SETTING_SHORT_OPTIONS, SETTING_LONG_OPTIONS, nullptr); if (option == '?') { if (optopt == 'c') { -- Gitee