From dc7b64b1c83ff1b6cda7ac48e146bea21204e494 Mon Sep 17 00:00:00 2001 From: zhongjianfei Date: Fri, 11 Mar 2022 00:53:24 +0800 Subject: [PATCH] Revert "fix ans bugs." This reverts commit c8c3b927cf5be60d8f9c026fec4fb7eba35fe51b. Signed-off-by: zhongjianfei Change-Id: I235867a78ede01f7015df607763db3c2e141386b --- bundle.json | 3 +- frameworks/ans/core/BUILD.gn | 4 +- frameworks/ans/core/src/ans_notification.cpp | 8 +- .../dialog/dialog_ui/js/pages/index/index.css | 15 - .../dialog/dialog_ui/js/pages/index/index.hml | 15 - .../dialog/dialog_ui/js/pages/index/index.js | 15 - frameworks/ans/native/BUILD.gn | 3 +- frameworks/ans/native/src/notification.cpp | 6 +- .../native/src/notification_subscriber.cpp | 6 +- .../ans/native/src/reminder_request.cpp | 402 +---------------- .../ans/native/src/reminder_request_alarm.cpp | 49 +- .../native/src/reminder_request_calendar.cpp | 105 +---- frameworks/ans/native/src/reminder_store.cpp | 418 ------------------ frameworks/ans/native/test/unittest/BUILD.gn | 5 +- frameworks/ans/test/moduletest/BUILD.gn | 22 +- .../ans/test/moduletest/ReminderHelperTest.js | 18 +- .../test/moduletest/ans_fw_module_test.cpp | 88 ++-- .../mock/include/mock_bundle_manager.h | 8 +- .../mock/mock_bundle_manager_helper.cpp | 60 --- .../ans/native/include/reminder_request.h | 119 +---- .../native/include/reminder_request_alarm.h | 19 - .../include/reminder_request_calendar.h | 34 -- .../native/include/reminder_request_timer.h | 8 - .../ans/native/include/reminder_store.h | 83 ---- interfaces/kits/js/@ohos.reminderAgent.d.ts | 9 +- interfaces/kits/napi/ans/BUILD.gn | 5 +- interfaces/kits/napi/ans/include/publish.h | 3 +- interfaces/kits/napi/ans/src/disturb_mode.cpp | 6 +- interfaces/kits/napi/ans/src/init.cpp | 3 +- interfaces/kits/napi/ans/src/publish.cpp | 21 +- .../kits/napi/ans/src/reminder/BUILD.gn | 3 +- .../kits/napi/ans/src/reminder/publish.cpp | 4 +- .../napi/ans/src/reminder/reminder_common.cpp | 23 +- notification.gni | 2 +- .../advanced_notification_service_ability.h | 2 - services/ans/include/reminder_data_manager.h | 28 +- services/ans/include/reminder_event_manager.h | 11 - .../ans/src/advanced_notification_service.cpp | 17 +- .../advanced_notification_service_ability.cpp | 2 - services/ans/src/notification_preferences.cpp | 1 - .../src/notification_preferences_database.cpp | 22 +- .../ans/src/notification_preferences_info.cpp | 2 +- .../src/notification_subscriber_manager.cpp | 11 +- services/ans/src/reminder_data_manager.cpp | 97 +--- services/ans/src/reminder_event_manager.cpp | 40 +- services/ans/test/unittest/BUILD.gn | 2 +- services/distributed/BUILD.gn | 2 +- services/distributed/test/unittest/BUILD.gn | 2 +- .../unittest/distributed_database_test.cpp | 2 +- .../distributed_notification_manager_test.cpp | 2 +- services/test/moduletest/BUILD.gn | 4 +- services/test/moduletest/ans_module_test.cpp | 8 +- .../mock/include/mock_single_kv_store.h | 2 +- .../mock/mock_bundle_manager_helper.cpp | 11 - test/common/acts/BUILD.gn | 1 + .../acts/actsnotificationfuzztest/BUILD.gn | 1 + test/resource/ansSTSlotGroupTest/BUILD.gn | 1 + tools/dump/BUILD.gn | 3 +- 58 files changed, 170 insertions(+), 1696 deletions(-) delete mode 100644 frameworks/ans/native/src/reminder_store.cpp delete mode 100644 frameworks/ans/test/moduletest/mock/mock_bundle_manager_helper.cpp delete mode 100644 interfaces/innerkits/ans/native/include/reminder_store.h diff --git a/bundle.json b/bundle.json index 02459d490..620c6674f 100644 --- a/bundle.json +++ b/bundle.json @@ -38,8 +38,7 @@ "name": "ans_standard", "subsystem": "notification", "syscap": [ - "SystemCapability.Notification.Notification", - "SystemCapability.Notification.ReminderAgent" + "SystemCapability.DistributedNotificationService" ], "features": [], "adapted_system_type": [ diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index 63e45c809..8c1172118 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -78,7 +78,6 @@ ohos_shared_library("ans_core") { "${frameworks_path}/ans/native/src/reminder_request_alarm.cpp", "${frameworks_path}/ans/native/src/reminder_request_calendar.cpp", "${frameworks_path}/ans/native/src/reminder_request_timer.cpp", - "${frameworks_path}/ans/native/src/reminder_store.cpp", ] configs = [ ":private_config" ] @@ -93,13 +92,12 @@ ohos_shared_library("ans_core") { external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", + "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", - "native_appdatamgr:native_rdb", "os_account_standard:os_account_innerkits", "samgr_standard:samgr_proxy", "time_native:time_service", diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index 02f3ff0d3..fb2439edb 100644 --- a/frameworks/ans/core/src/ans_notification.cpp +++ b/frameworks/ans/core/src/ans_notification.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1238,7 +1238,11 @@ ErrCode AnsNotification::IsSupportTemplate(const std::string &templateName, bool bool AnsNotification::IsNonDistributedNotificationType(const NotificationContent::Type &type) { - return ((type == NotificationContent::Type::CONVERSATION) || (type == NotificationContent::Type::PICTURE)); + if ((type == NotificationContent::Type::CONVERSATION) || + (type == NotificationContent::Type::PICTURE)) { + return true; + } + return false; } ErrCode AnsNotification::IsAllowedNotify(const int32_t &userId, bool &allowed) diff --git a/frameworks/ans/dialog/dialog_ui/js/pages/index/index.css b/frameworks/ans/dialog/dialog_ui/js/pages/index/index.css index 7afe50dcd..cf6a1e51c 100644 --- a/frameworks/ans/dialog/dialog_ui/js/pages/index/index.css +++ b/frameworks/ans/dialog/dialog_ui/js/pages/index/index.css @@ -1,18 +1,3 @@ -/* - * 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. - */ - .container { display: flex; flex-direction: column; diff --git a/frameworks/ans/dialog/dialog_ui/js/pages/index/index.hml b/frameworks/ans/dialog/dialog_ui/js/pages/index/index.hml index 73e8c517a..98272a4d6 100644 --- a/frameworks/ans/dialog/dialog_ui/js/pages/index/index.hml +++ b/frameworks/ans/dialog/dialog_ui/js/pages/index/index.hml @@ -1,18 +1,3 @@ - -
diff --git a/frameworks/ans/dialog/dialog_ui/js/pages/index/index.js b/frameworks/ans/dialog/dialog_ui/js/pages/index/index.js index 202cc62bc..928dc3b8b 100644 --- a/frameworks/ans/dialog/dialog_ui/js/pages/index/index.js +++ b/frameworks/ans/dialog/dialog_ui/js/pages/index/index.js @@ -1,18 +1,3 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - import router from '@ohos.router' export default { diff --git a/frameworks/ans/native/BUILD.gn b/frameworks/ans/native/BUILD.gn index 7bdd65315..059c83526 100644 --- a/frameworks/ans/native/BUILD.gn +++ b/frameworks/ans/native/BUILD.gn @@ -85,12 +85,11 @@ ohos_shared_library("ans_innerkits") { external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:wantagent_innerkits", + "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", - "native_appdatamgr:native_rdb", "samgr_standard:samgr_proxy", ] diff --git a/frameworks/ans/native/src/notification.cpp b/frameworks/ans/native/src/notification.cpp index 0773681bd..613c42646 100644 --- a/frameworks/ans/native/src/notification.cpp +++ b/frameworks/ans/native/src/notification.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -246,7 +246,7 @@ bool Notification::MarshallingBool(Parcel &parcel) const bool Notification::MarshallingString(Parcel &parcel) const { if (!parcel.WriteString(key_)) { - ANS_LOGE("Can't write key"); + ANS_LOGE("Can't wirte key"); return false; } @@ -258,7 +258,7 @@ bool Notification::MarshallingString(Parcel &parcel) const } if (!parcel.WriteString(deviceId_)) { - ANS_LOGE("Can't write deviceId"); + ANS_LOGE("Can't wirte deviceId"); return false; } diff --git a/frameworks/ans/native/src/notification_subscriber.cpp b/frameworks/ans/native/src/notification_subscriber.cpp index a0865fa92..e3a9a3c33 100644 --- a/frameworks/ans/native/src/notification_subscriber.cpp +++ b/frameworks/ans/native/src/notification_subscriber.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -99,9 +99,9 @@ void NotificationSubscriber::SubscriberImpl::OnEnabledNotificationChanged( bool NotificationSubscriber::SubscriberImpl::GetAnsManagerProxy() { - if (proxy_ == nullptr) { + if (nullptr == proxy_) { std::lock_guard lock(mutex_); - if (proxy_ == nullptr) { + if (nullptr == proxy_) { sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!systemAbilityManager) { diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 381d0bb5d..fec50a742 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,7 +21,6 @@ #include "ipc_skeleton.h" #include "iservice_registry.h" #include "os_account_manager.h" -#include "reminder_store.h" #include "system_ability_definition.h" #include "want_agent_helper.h" @@ -51,45 +50,12 @@ const std::string ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT = "ohos.event.no const std::string ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION = "ohos.event.notification.reminder.REMOVE_NOTIFICATION"; const std::string ReminderRequest::PARAM_REMINDER_ID = "REMINDER_ID"; -const std::string ReminderRequest::SEP_BUTTON_SINGLE = ""; -const std::string ReminderRequest::SEP_BUTTON_MULTI = ""; -const std::string ReminderRequest::SEP_WANT_AGENT = ""; - -// 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::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::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"; - -std::string ReminderRequest::sqlOfAddColumns = ""; -std::vector ReminderRequest::columns; ReminderRequest::ReminderRequest() { - InitServerObj(); + wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; + maxScreenWantAgentInfo_ = + maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; } ReminderRequest::ReminderRequest(const ReminderRequest &other) @@ -117,16 +83,12 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) this->actionButtonMap_ = other.actionButtonMap_; } -ReminderRequest::ReminderRequest(int32_t reminderId) -{ - reminderId_ = reminderId; - InitServerObj(); -} - ReminderRequest::ReminderRequest(ReminderType reminderType) { reminderType_ = reminderType; - InitServerObj(); + wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; + maxScreenWantAgentInfo_ = + maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; } bool ReminderRequest::CanRemove() const @@ -166,7 +128,7 @@ std::string ReminderRequest::Dump() const ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type) { - if ((type != ActionButtonType::CLOSE) && (type != ActionButtonType::SNOOZE)) { + if (type != ActionButtonType::CLOSE && type != ActionButtonType::SNOOZE) { ANSR_LOGI("Button type only support: %{public}d or %{public}d", static_cast(ActionButtonType::CLOSE), static_cast(ActionButtonType::SNOOZE)); return *this; @@ -211,11 +173,6 @@ void ReminderRequest::InitUserId(const int &userId) userId_ = userId; } -void ReminderRequest::InitUid(const int32_t &uid) -{ - uid_ = uid; -} - bool ReminderRequest::IsExpired() const { return isExpired_; @@ -419,192 +376,6 @@ bool ReminderRequest::OnTimeZoneChange() triggerTimeInMilli_, GetDurationSinceEpochInMilli(newZoneTriggerTime), nextTriggerTime); } -int64_t ReminderRequest::RecoverInt64FromDb(const std::shared_ptr &resultSet, - const std::string &columnName, const DbRecoveryType &columnType) -{ - if (resultSet == nullptr) { - ANSR_LOGE("ResultSet is null"); - return 0; - } - switch (columnType) { - case (DbRecoveryType::INT): { - int value; - resultSet->GetInt(ReminderStore::GetColumnIndex(columnName), value); - return static_cast(value); - } - case (DbRecoveryType::LONG): { - int64_t value; - resultSet->GetLong(ReminderStore::GetColumnIndex(columnName), value); - return value; - } - default: { - ANSR_LOGD("ColumnType not support."); - break; - } - } - ANSR_LOGE("Recover data error"); - return 0; -} - -void ReminderRequest::RecoverFromDb(const std::shared_ptr &resultSet) -{ - if (resultSet == nullptr) { - ANSR_LOGE("ResultSet is null"); - return; - } - - // reminderId - resultSet->GetInt(ReminderStore::GetColumnIndex(REMINDER_ID), reminderId_); - - // userId - resultSet->GetInt(ReminderStore::GetColumnIndex(USER_ID), userId_); - - // bundleName - resultSet->GetString(ReminderStore::GetColumnIndex(PKG_NAME), bundleName_); - - // uid - resultSet->GetInt(ReminderStore::GetColumnIndex(UID), uid_); - - // reminderType - int reminderType; - resultSet->GetInt(ReminderStore::GetColumnIndex(REMINDER_TYPE), reminderType); - reminderType_ = ReminderType(reminderType); - - // reminderTime - reminderTimeInMilli_ = - static_cast(RecoverInt64FromDb(resultSet, REMINDER_TIME, DbRecoveryType::LONG)); - - // triggerTime - triggerTimeInMilli_ = - static_cast(RecoverInt64FromDb(resultSet, TRIGGER_TIME, DbRecoveryType::LONG)); - - // timeInterval - uint64_t timeIntervalInSecond = - static_cast(RecoverInt64FromDb(resultSet, TIME_INTERVAL, DbRecoveryType::LONG)); - SetTimeInterval(timeIntervalInSecond); - - // snoozeTimes - snoozeTimes_ = static_cast(RecoverInt64FromDb(resultSet, SNOOZE_TIMES, DbRecoveryType::INT)); - - // dynamicSnoozeTimes - snoozeTimesDynamic_ = - static_cast(RecoverInt64FromDb(resultSet, DYNAMIC_SNOOZE_TIMES, DbRecoveryType::INT)); - - // ringDuration - uint64_t ringDurationInSecond = - static_cast(RecoverInt64FromDb(resultSet, RING_DURATION, DbRecoveryType::LONG)); - SetRingDuration(ringDurationInSecond); - - // isExpired - std::string isExpired; - resultSet->GetString(ReminderStore::GetColumnIndex(IS_EXPIRED), isExpired); - isExpired_ = isExpired == "true" ? true : false; - - // state - state_ = static_cast(RecoverInt64FromDb(resultSet, STATE, DbRecoveryType::INT)); - - // action buttons - RecoverActionButton(resultSet); - - // slotType - int slotType; - resultSet->GetInt(ReminderStore::GetColumnIndex(SLOT_ID), slotType); - slotType_ = NotificationConstant::SlotType(slotType); - - // notification id - resultSet->GetInt(ReminderStore::GetColumnIndex(NOTIFICATION_ID), notificationId_); - - // title - resultSet->GetString(ReminderStore::GetColumnIndex(TITLE), title_); - - // content - resultSet->GetString(ReminderStore::GetColumnIndex(CONTENT), content_); - - // snoozeContent - resultSet->GetString(ReminderStore::GetColumnIndex(SNOOZE_CONTENT), snoozeContent_); - - // expiredContent - resultSet->GetString(ReminderStore::GetColumnIndex(EXPIRED_CONTENT), expiredContent_); - - InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent - - // wantAgent - std::string wantAgent; - resultSet->GetString(ReminderStore::GetColumnIndex(AGENT), wantAgent); - RecoverWantAgent(wantAgent, 0); - - // maxScreenWantAgent - std::string maxScreenWantAgent; - resultSet->GetString(ReminderStore::GetColumnIndex(MAX_SCREEN_AGENT), maxScreenWantAgent); - RecoverWantAgent(wantAgent, 1); -} - -void ReminderRequest::RecoverActionButton(const std::shared_ptr &resultSet) -{ - if (resultSet == nullptr) { - ANSR_LOGE("ResultSet is null"); - return; - } - std::string actionButtonInfo; - resultSet->GetString(ReminderStore::GetColumnIndex(ACTION_BUTTON_INFO), actionButtonInfo); - std::vector multiButton = StringSplit(actionButtonInfo, SEP_BUTTON_MULTI); - for (auto button : multiButton) { - std::vector singleButton = StringSplit(button, SEP_BUTTON_SINGLE); - SetActionButton(singleButton.at(1), ActionButtonType(std::stoi(singleButton.at(0), nullptr))); - } -} - -std::vector ReminderRequest::StringSplit(std::string source, const std::string &split) const -{ - std::vector result; - if (source.empty()) { - return result; - } - size_t pos = 0; - while ((pos = source.find(split)) != std::string::npos) { - std::string token = source.substr(0, pos); - if (!token.empty()) { - result.push_back(token); - } - source.erase(0, pos + split.length()); - } - if (!source.empty()) { - result.push_back(source); - } - return result; -} - -void ReminderRequest::RecoverWantAgent(std::string wantAgentInfo, const uint8_t &type) -{ - std::vector info = StringSplit(wantAgentInfo, ReminderRequest::SEP_WANT_AGENT); - uint8_t minLen = 2; - if (info.size() < minLen) { - ANSR_LOGW("RecoverWantAgent fail"); - return; - } - ANSR_LOGD("pkg=%{public}s, ability=%{public}s", info.at(0).c_str(), info.at(1).c_str()); - switch (type) { - case 0: { - auto wantAgentInfo = std::make_shared(); - wantAgentInfo->pkgName = info.at(0); - wantAgentInfo->abilityName = info.at(1); - SetWantAgentInfo(wantAgentInfo); - break; - } - case 1: { - auto maxScreenWantAgentInfo = std::make_shared(); - maxScreenWantAgentInfo->pkgName = info.at(0); - maxScreenWantAgentInfo->abilityName = info.at(1); - SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); - break; - } - default: { - ANSR_LOGW("RecoverWantAgent type not support"); - break; - } - } -} - ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo( const std::shared_ptr &maxScreenWantAgentInfo) { @@ -645,7 +416,7 @@ ReminderRequest& ReminderRequest::SetSnoozeTimesDynamic(const uint8_t snooziTime ReminderRequest& ReminderRequest::SetTimeInterval(const uint64_t timeIntervalInSeconds) { - if ((timeIntervalInSeconds < 0) || (timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS))) { + if (timeIntervalInSeconds < 0 || timeIntervalInSeconds > (UINT64_MAX / MILLI_SECONDS)) { ANSR_LOGW("SetTimeInterval, replace to set (0s), for the given is out of legal range"); timeIntervalInMilli_ = 0; } else { @@ -744,7 +515,7 @@ void ReminderRequest::SetReminderTimeInMilli(const uint64_t reminderTimeInMilli) ReminderRequest& ReminderRequest::SetRingDuration(const uint64_t ringDurationInSeconds) { - if ((ringDurationInSeconds <= 0) || (ringDurationInSeconds > (UINT64_MAX / MILLI_SECONDS))) { + if (ringDurationInSeconds <= 0 || ringDurationInSeconds > (UINT64_MAX / MILLI_SECONDS)) { ANSR_LOGW("setRingDuration, replace to set (1s), for the given is out of legal range"); ringDurationInMilli_ = MILLI_SECONDS; } else { @@ -793,16 +564,6 @@ uint64_t ReminderRequest::GetTriggerTimeInMilli() const return triggerTimeInMilli_; } -int ReminderRequest::GetUserId() const -{ - return userId_; -} - -int32_t ReminderRequest::GetUid() const -{ - return uid_; -} - std::shared_ptr ReminderRequest::GetWantAgentInfo() const { return wantAgentInfo_; @@ -849,11 +610,6 @@ void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std SetMaxScreenWantAgent(maxScreenWantAgent); break; } - case UpdateNotificationType::BUNDLE_INFO: { - ANSR_LOGI("UpdateNotification hap information"); - UpdateNotificationBundleInfo(); - break; - } case UpdateNotificationType::CONTENT: { break; } @@ -1033,7 +789,7 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) ANSR_LOGE("Failed to read tempReminderId"); return false; } - reminderId_ = (tempReminderId == -1) ? reminderId_ : tempReminderId; + reminderId_ = tempReminderId == -1 ? reminderId_ : tempReminderId; if (!parcel.ReadInt32(notificationId_)) { ANSR_LOGE("Failed to read notificationId"); @@ -1121,13 +877,6 @@ bool ReminderRequest::InitNotificationRequest() return true; } -void ReminderRequest::InitServerObj() -{ - wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; - maxScreenWantAgentInfo_ = - maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; -} - bool ReminderRequest::IsAlerting() const { return (state_ & REMINDER_STATUS_ALERTING) != 0; @@ -1150,21 +899,6 @@ std::string ReminderRequest::GetDateTimeInfo(const time_t &timeInSecond) const return GetTimeInfoInner(timeInSecond, TimeFormat::YMDHMS); } -std::string ReminderRequest::GetButtonInfo() const -{ - std::string info = ""; - bool isFirst = true; - for (auto button : actionButtonMap_) { - if (!isFirst) { - info += SEP_BUTTON_MULTI; - } - ActionButtonInfo buttonInfo = button.second; - info += std::to_string(static_cast(button.first)) + SEP_BUTTON_SINGLE + buttonInfo.title; - isFirst = false; - } - return info; -} - uint64_t ReminderRequest::GetNowInstantMilli() const { time_t now; @@ -1186,7 +920,7 @@ std::string ReminderRequest::GetShowTime(const uint64_t showTime) const std::string ReminderRequest::GetTimeInfoInner(const time_t &timeInSecond, const TimeFormat &format) const { - const uint8_t dateTimeLen = 80; + uint8_t dateTimeLen = 80; char dateTimeBuffer[dateTimeLen]; struct tm timeInfo; (void)localtime_r(&timeInSecond, &timeInfo); @@ -1413,8 +1147,8 @@ void ReminderRequest::UpdateNotificationCommon() notificationNormalContent->SetTitle(title_); auto notificationContent = std::make_shared(notificationNormalContent); notificationRequest_->SetContent(notificationContent); - if ((reminderType_ == ReminderRequest::ReminderType::TIMER) || - (reminderType_ == ReminderRequest::ReminderType::ALARM)) { + if (reminderType_ == ReminderRequest::ReminderType::TIMER + || reminderType_ == ReminderRequest::ReminderType::ALARM) { notificationRequest_->SetUnremovable(true); } auto flags = std::make_shared(); @@ -1423,25 +1157,6 @@ void ReminderRequest::UpdateNotificationCommon() notificationRequest_->SetFlags(flags); } -void ReminderRequest::UpdateNotificationBundleInfo() -{ - std::string ownerBundleName = notificationRequest_->GetOwnerBundleName(); - if (!(ownerBundleName.empty())) { - return; - } - ANSR_LOGD("ownerBundleName=%{public}s, bundleName_=%{public}s", - ownerBundleName.c_str(), bundleName_.c_str()); - notificationRequest_->SetOwnerBundleName(bundleName_); - notificationRequest_->SetCreatorBundleName(bundleName_); - notificationRequest_->SetCreatorUid(uid_); - ErrCode errCode = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid_, userId_); - if (errCode != ERR_OK) { - ANSR_LOGE("GetOsAccountLocalIdFromUid fail."); - return; - } - notificationRequest_->SetCreatorUserId(userId_); -} - void ReminderRequest::UpdateNotificationContent(const bool &setSnooze) { if (notificationRequest_ == nullptr) { @@ -1549,94 +1264,5 @@ int ReminderRequest::GetUserId(const int &uid) AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); return userId; } - -void ReminderRequest::AppendValuesBucket(const sptr &reminder, - const sptr &bundleOption, 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(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.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()); - auto wantAgentInfo = reminder->GetWantAgentInfo(); - if (wantAgentInfo == nullptr) { - std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; - values.PutString(AGENT, info); - } else { - values.PutString(AGENT, wantAgentInfo->pkgName - + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->abilityName); - } - auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo(); - if (maxScreenWantAgentInfo == nullptr) { - std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; - values.PutString(MAX_SCREEN_AGENT, info); - } else { - values.PutString(MAX_SCREEN_AGENT, maxScreenWantAgentInfo->pkgName - + ReminderRequest::SEP_WANT_AGENT + maxScreenWantAgentInfo->abilityName); - } -} - -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(APP_LABEL, "TEXT", false); - AddColumn(REMINDER_TYPE, "INT NOT NULL", false); - AddColumn(REMINDER_TIME, "BIGINT NOT NULL", false); - AddColumn(TRIGGER_TIME, "BIGINT NOT NULL", false); - AddColumn(RTC_TRIGGER_TIME, "BIGINT NOT NULL", false); - AddColumn(TIME_INTERVAL, "BIGINT NOT NULL", false); - AddColumn(SNOOZE_TIMES, "INT NOT NULL", false); - AddColumn(DYNAMIC_SNOOZE_TIMES, "INT NOT NULL", false); - AddColumn(RING_DURATION, "BIGINT NOT NULL", false); - AddColumn(IS_EXPIRED, "TEXT NOT NULL", false); - AddColumn(IS_ACTIVE, "TEXT NOT NULL", false); - AddColumn(STATE, "INT NOT NULL", false); - AddColumn(ZONE_ID, "TEXT", false); - AddColumn(HAS_SCHEDULED_TIMEOUT, "TEXT", false); - AddColumn(ACTION_BUTTON_INFO, "TEXT", false); - AddColumn(SLOT_ID, "INT", false); - AddColumn(NOTIFICATION_ID, "INT NOT NULL", false); - AddColumn(TITLE, "TEXT", false); - AddColumn(CONTENT, "TEXT", false); - AddColumn(SNOOZE_CONTENT, "TEXT", false); - AddColumn(EXPIRED_CONTENT, "TEXT", false); - AddColumn(AGENT, "TEXT", false); - AddColumn(MAX_SCREEN_AGENT, "TEXT", false); -} - -void ReminderRequest::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; - } -} } } diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index 1bb778ea6..8d9963226 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -16,7 +16,6 @@ #include "reminder_request_alarm.h" #include "ans_log_wrapper.h" -#include "reminder_store.h" namespace OHOS { namespace Notification { @@ -29,11 +28,6 @@ const uint8_t ReminderRequestAlarm::MINUTES_PER_HOUR = 60; const int8_t ReminderRequestAlarm::INVALID_INT_VALUE = -1; const int8_t ReminderRequestAlarm::DEFAULT_SNOOZE_TIMES = 3; -// For database recovery. -const std::string ReminderRequestAlarm::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; -const std::string ReminderRequestAlarm::ALARM_HOUR = "alarm_hour"; -const std::string ReminderRequestAlarm::ALARM_MINUTE = "alarm_minute"; - ReminderRequestAlarm::ReminderRequestAlarm(uint8_t hour, uint8_t minute, const std::vector daysOfWeek) : ReminderRequest(ReminderRequest::ReminderType::ALARM) { @@ -55,7 +49,7 @@ ReminderRequestAlarm::ReminderRequestAlarm(const ReminderRequestAlarm &other) : void ReminderRequestAlarm::CheckParamValid() const { - if ((hour_ >= HOURS_PER_DAY) || (hour_ < 0)) { + if (hour_ >= HOURS_PER_DAY || hour_ < 0) { ANSR_LOGE("setted hour is not between [0, 24)"); throw std::invalid_argument("setted hour is not between [0, 24)"); } @@ -306,46 +300,5 @@ bool ReminderRequestAlarm::ReadFromParcel(Parcel &parcel) ANSR_LOGD("hour_=%{public}d, minute_=%{public}d, repeatDays_=%{public}d", hour_, minute_, repeatDays_); return true; } - -void ReminderRequestAlarm::RecoverFromDb(const std::shared_ptr &resultSet) -{ - ReminderRequest::RecoverFromDb(resultSet); - - // repeatDays - repeatDays_ = - static_cast(RecoverInt64FromDb(resultSet, REPEAT_DAYS_OF_WEEK, DbRecoveryType::INT)); - - // hour - hour_ = - static_cast(RecoverInt64FromDb(resultSet, ALARM_HOUR, DbRecoveryType::INT)); - - // minute - minute_ = - static_cast(RecoverInt64FromDb(resultSet, ALARM_MINUTE, DbRecoveryType::INT)); -} - -void ReminderRequestAlarm::AppendValuesBucket(const sptr &reminder, - const sptr &bundleOption, NativeRdb::ValuesBucket &values) -{ - uint8_t repeatDays = 0; - uint8_t hour = 0; - uint8_t minute = 0; - if (reminder->GetReminderType() == ReminderRequest::ReminderType::ALARM) { - ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr()); - repeatDays = alarm->GetRepeatDay(); - hour = alarm->GetHour(); - minute = alarm->GetMinute(); - } - values.PutInt(REPEAT_DAYS_OF_WEEK, repeatDays); - values.PutInt(ALARM_HOUR, hour); - values.PutInt(ALARM_MINUTE, minute); -} - -void ReminderRequestAlarm::InitDbColumns() -{ - ReminderRequest::AddColumn(REPEAT_DAYS_OF_WEEK, "INT", false); - ReminderRequest::AddColumn(ALARM_HOUR, "INT", false); - ReminderRequest::AddColumn(ALARM_MINUTE, "INT", true); -} } } \ No newline at end of file diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index b2490eb64..58c260f5e 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -25,18 +25,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"; - ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, const std::vector &repeatMonths, const std::vector &repeatDays) : ReminderRequest(ReminderRequest::ReminderType::CALENDAR) @@ -98,7 +86,7 @@ uint8_t ReminderRequestCalendar::GetDaysOfMonth(const uint16_t &year, const uint uint8_t leapParam1 = 4; uint8_t leapParam2 = 100; if (month == february) { - days = ((((year % leapParam1 == 0) && (year % leapParam2 != 0)) || (year % solarYear == 0)) + days = ((((0 == year % leapParam1) && (0 != year % leapParam2)) || (0 == year % solarYear)) ? leapMonth : nonLeapMonth); } else { days = daysArray[month - 1]; @@ -514,96 +502,5 @@ bool ReminderRequestCalendar::ReadFromParcel(Parcel &parcel) } return true; } - -void ReminderRequestCalendar::RecoverFromDb(const std::shared_ptr &resultSet) -{ - ReminderRequest::RecoverFromDb(resultSet); - - // repeatDay - repeatDay_ = static_cast(RecoverInt64FromDb(resultSet, REPEAT_DAYS, DbRecoveryType::INT)); - - // repeatMonth - repeatMonth_ = - static_cast(RecoverInt64FromDb(resultSet, REPEAT_MONTHS, DbRecoveryType::INT)); - - // firstDesignateYear - firstDesignateYear_ = - static_cast(RecoverInt64FromDb(resultSet, FIRST_DESIGNATE_YEAR, DbRecoveryType::INT)); - - // firstDesignateMonth - firstDesignateMonth_ = - static_cast(RecoverInt64FromDb(resultSet, FIRST_DESIGNATE_MONTH, DbRecoveryType::INT)); - - // firstDesignateDay - firstDesignateDay_ = - static_cast(RecoverInt64FromDb(resultSet, FIRST_DESIGNATE_DAY, DbRecoveryType::INT)); - - // year - year_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_YEAR, DbRecoveryType::INT)); - - // month - month_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_MONTH, DbRecoveryType::INT)); - - // day - day_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_DAY, DbRecoveryType::INT)); - - // hour - hour_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_HOUR, DbRecoveryType::INT)); - - // minute - minute_ = static_cast(RecoverInt64FromDb(resultSet, CALENDAR_MINUTE, DbRecoveryType::INT)); -} - -void ReminderRequestCalendar::AppendValuesBucket(const sptr &reminder, - const sptr &bundleOption, NativeRdb::ValuesBucket &values) -{ - uint32_t repeatDay = 0; - uint16_t repeatMonth = 0; - uint16_t firstDesignateYear = 0; - uint8_t firstDesignateMonth = 0; - uint8_t firstDesignateDay = 0; - uint16_t year = 0; - uint8_t month = 0; - uint8_t day = 0; - uint8_t hour = 0; - uint8_t minute = 0; - if (reminder->GetReminderType() == ReminderRequest::ReminderType::CALENDAR) { - ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); - repeatDay = calendar->GetRepeatDay(); - repeatMonth = calendar->GetRepeatMonth(); - firstDesignateYear = calendar->GetFirstDesignateYear(); - firstDesignateMonth = calendar->GetFirstDesignageMonth(); - firstDesignateDay = calendar->GetFirstDesignateDay(); - year = calendar->GetYear(); - month = calendar->GetMonth(); - day = calendar->GetDay(); - hour = calendar->GetHour(); - minute = calendar->GetMinute(); - } - values.PutInt(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); -} - -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); -} } } \ No newline at end of file diff --git a/frameworks/ans/native/src/reminder_store.cpp b/frameworks/ans/native/src/reminder_store.cpp deleted file mode 100644 index 1b51a5a9f..000000000 --- a/frameworks/ans/native/src/reminder_store.cpp +++ /dev/null @@ -1,418 +0,0 @@ -/* - * 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 "reminder_store.h" - -#include -#include -#include -#include - -#include "ability_context.h" -#include "ans_log_wrapper.h" -#include "reminder_request_alarm.h" -#include "reminder_request_calendar.h" -#include "reminder_request_timer.h" - -namespace OHOS { -namespace Notification { -namespace { -const std::string REMINDER_DB_DIR = "/data/system_ce/ans_standard/"; -const std::string REMINDER_DB_NAME = "reminder.db"; -const std::string REMINDER_DB_TABLE = "reminder"; -const uint32_t REMINDER_RDB_VERSION = 1; -const int32_t STATE_FAIL = -1; -std::vector columns; -} - -const int32_t ReminderStore::STATE_OK = 0; - -int32_t ReminderStore::ReminderStoreDataCallBack::OnCreate(NativeRdb::RdbStore &store) -{ - ANSR_LOGD("Create table."); - std::string CREATE_REMINDER_TABLE = "CREATE TABLE IF NOT EXISTS " + REMINDER_DB_TABLE + " (" - + ReminderRequest::sqlOfAddColumns + ")"; - ANSR_LOGD("CreateTable:%{public}s", CREATE_REMINDER_TABLE.c_str()); - return store.ExecuteSql(CREATE_REMINDER_TABLE); -} - -int32_t ReminderStore::ReminderStoreDataCallBack::OnUpgrade( - NativeRdb::RdbStore &store, int32_t oldVersion, int32_t newVersion) -{ - return NativeRdb::E_OK; -} - -int32_t ReminderStore::Init() -{ - ANSR_LOGD("Reminder store init."); - int32_t errCode(STATE_FAIL); - - if (access(REMINDER_DB_DIR.c_str(), F_OK) != 0) { - int createDir = mkdir(REMINDER_DB_DIR.c_str(), S_IRWXU); - if (createDir != 0) { - ANSR_LOGE("Failed to create directory %{public}s", REMINDER_DB_DIR.c_str()); - return errCode; - } - } - - ReminderRequest::InitDbColumns(); - ReminderRequestCalendar::InitDbColumns(); - ReminderRequestAlarm::InitDbColumns(); - columns.insert(columns.begin(), - ReminderRequest::columns.begin(), ReminderRequest::columns.end()); - - std::string dbConfig = REMINDER_DB_DIR + REMINDER_DB_NAME; - NativeRdb::RdbStoreConfig config_(dbConfig); - ReminderStoreDataCallBack rdbDataCallBack_; - rdbStore_ = NativeRdb::RdbHelper::GetRdbStore(config_, REMINDER_RDB_VERSION, rdbDataCallBack_, errCode); - if (rdbStore_ == nullptr) { - ANSR_LOGE("ReminderStore init fail, errCode %{public}d.", errCode); - return errCode; - } - return ReminderStore::InitData(); -} - -int32_t ReminderStore::InitData() -{ - ANSR_LOGD("Reminder data init."); - std::string deleteCondition = ReminderRequest::IS_EXPIRED + " is true"; - ReminderStore::Delete(deleteCondition); - - int32_t statusChangedRows = STATE_FAIL; - NativeRdb::ValuesBucket statusValues; - statusValues.PutInt(ReminderRequest::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) { - ANSR_LOGE("Init data failed."); - return STATE_FAIL; - } - - int32_t activeChangedRows = STATE_FAIL; - NativeRdb::ValuesBucket activeValues; - activeValues.PutString(ReminderRequest::IS_ACTIVE, "false"); - std::string activeUpdateCondition = ReminderRequest::IS_ACTIVE + " is true"; - std::vector activeWhereArgs; - int32_t activeResult = rdbStore_->Update( - activeChangedRows, REMINDER_DB_TABLE, activeValues, activeUpdateCondition, activeWhereArgs); - ANSR_LOGD("Change status isActive to false, changed rows: %{public}d.", activeChangedRows); - if (activeResult != NativeRdb::E_OK) { - ANSR_LOGE("Init data failed."); - return STATE_FAIL; - } - - int32_t scheduledChangedRows = STATE_FAIL; - NativeRdb::ValuesBucket scheduledValues; - scheduledValues.PutString(ReminderRequest::HAS_SCHEDULED_TIMEOUT, "false"); - std::string scheduledUpdateCondition = ReminderRequest::HAS_SCHEDULED_TIMEOUT + " is true"; - std::vector scheduledWhereArgs; - int32_t scheduledResult = rdbStore_->Update( - scheduledChangedRows, REMINDER_DB_TABLE, scheduledValues, scheduledUpdateCondition, scheduledWhereArgs); - ANSR_LOGD("Change status has_ScheduledTimeout to false, changed rows: %{public}d.", scheduledChangedRows); - if (scheduledResult != NativeRdb::E_OK) { - ANSR_LOGE("Init data failed."); - return STATE_FAIL; - } - return ReminderStore::STATE_OK; -} - -int32_t ReminderStore::Delete(int32_t reminderId) -{ - std::string deleteCondition = ReminderRequest::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); - 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); - return ReminderStore::Delete(deleteCondition); -} - -int32_t ReminderStore::Delete(const std::string &deleteCondition) -{ - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return STATE_FAIL; - } - int32_t deletedRows = STATE_FAIL; - std::vector whereArgs; - int32_t result = rdbStore_->Delete(deletedRows, REMINDER_DB_TABLE, deleteCondition, whereArgs); - if (result != NativeRdb::E_OK) { - ANSR_LOGE("Delete operation failed, deleteConditon: %{public}s," \ - "result: %{public}d.", deleteCondition.c_str(), result); - } - ANSR_LOGD("Delete operation done, deleteConditon: %{public}s," \ - "deleted rows: %{public}d.", deleteCondition.c_str(), deletedRows); - return deletedRows; -} - -int64_t ReminderStore::UpdateOrInsert( - const sptr &reminder, const sptr &bundleOption) -{ - if (reminder->GetReminderType() == ReminderRequest::ReminderType::TIMER) { - ANSR_LOGI("Countdown not support persist."); - return STATE_FAIL; - } - int64_t isSuccess = STATE_FAIL; - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return isSuccess; - } - if (bundleOption == nullptr) { - ANSR_LOGE("BundleOption is null."); - return isSuccess; - } - if (IsReminderExist(reminder)) { - isSuccess = Update(reminder, bundleOption); - } else { - isSuccess = Insert(reminder, bundleOption); - } - return isSuccess; -} - -int64_t ReminderStore::Insert( - const sptr &reminder, const sptr &bundleOption) -{ - int64_t rowId = STATE_FAIL; - NativeRdb::ValuesBucket values; - ReminderStore::GenerateData(reminder, bundleOption, values); - int32_t result = rdbStore_->Insert(rowId, REMINDER_DB_TABLE, values); - if (result != NativeRdb::E_OK) { - ANSR_LOGE("Insert operation failed, result: %{public}d, reminderId=%{public}d.", - result, reminder->GetReminderId()); - return result; - } - ANSR_LOGD("Insert successfully, reminderId=%{public}d.", reminder->GetReminderId()); - return result; -} - -int64_t ReminderStore::Update( - const sptr &reminder, const sptr &bundleOption) -{ - int32_t changedRows = STATE_FAIL; - NativeRdb::ValuesBucket values; - ReminderStore::GenerateData(reminder, bundleOption, values); - std::string updateCondition = ReminderRequest::REMINDER_ID - + " = " + std::to_string(reminder->GetReminderId()); - std::vector whereArgs; - int32_t result = rdbStore_->Update(changedRows, REMINDER_DB_TABLE, values, updateCondition, whereArgs); - if ((result != NativeRdb::E_OK) || (changedRows <= 0)) { - ANSR_LOGE("Update operation failed, result: %{public}d, updated rows: %{public}d, reminderId=%{public}d.", - result, changedRows, reminder->GetReminderId()); - return result; - } - ANSR_LOGD("Update successfully, updated rows: %{public}d, reminderId=%{public}d.", - changedRows, reminder->GetReminderId()); - return result; -} - -bool ReminderStore::IsReminderExist(const sptr &reminder) -{ - std::string queryCondition = "select " + ReminderRequest::REMINDER_ID - + " from " + REMINDER_DB_TABLE + " where " - + ReminderRequest::REMINDER_ID + " = " + std::to_string(reminder->GetReminderId()); - std::vector whereArgs; - std::unique_ptr queryResultSet = rdbStore_->QuerySql(queryCondition, whereArgs); - if (queryResultSet == nullptr) { - ANSR_LOGE("QueryResultSet is null."); - return false; - } - int32_t resultNum; - queryResultSet->GetRowCount(resultNum); - if (resultNum == 0) { - return false; - } - return true; -} - -std::shared_ptr ReminderStore::Query(const std::string &queryCondition) const -{ - std::unique_ptr queryResultSet; - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return queryResultSet; - } - std::vector whereArgs; - queryResultSet = rdbStore_->QuerySql(queryCondition, whereArgs); - return queryResultSet; -} - -uint8_t ReminderStore::GetColumnIndex(const std::string& name) -{ - uint8_t index = 0; - for (auto it = columns.begin(); it != columns.end(); ++it) { - if (name == (*it)) { - break; - } - index++; - } - return index; -} - -int32_t ReminderStore::GetMaxId() -{ - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return STATE_FAIL; - } - std::string queryCondition = "select " + ReminderRequest::REMINDER_ID - + " from " + REMINDER_DB_TABLE + " order by " - + ReminderRequest::REMINDER_ID + " desc"; - std::shared_ptr queryResultSet = ReminderStore::Query(queryCondition); - if (queryResultSet == nullptr) { - ANSR_LOGE("QueryResultSet is null."); - return STATE_FAIL; - } - int32_t resultNum; - queryResultSet->GetRowCount(resultNum); - if (resultNum == 0) { - ANSR_LOGI("QueryResultSet is zero."); - return STATE_FAIL; - } - queryResultSet->GoToNextRow(); - int32_t maxId = STATE_FAIL; - int32_t result = queryResultSet->GetInt(0, maxId); - if (result != NativeRdb::E_OK) { - ANSR_LOGE("Query operation failed, result %{public}d.", result); - } - ANSR_LOGD("MaxId: %{public}d.", maxId); - return maxId; -} - -std::vector> ReminderStore::GetAllValidReminders() -{ - std::string queryCondition = "select * from " + REMINDER_DB_TABLE + " where " - + ReminderRequest::IS_EXPIRED + " is false order by " - + ReminderRequest::TRIGGER_TIME + " asc"; - ANSR_LOGD("Get all reminders"); - return GetReminders(queryCondition); -} - -std::vector> ReminderStore::GetReminders(const std::string &queryCondition) -{ - std::vector> reminders; - if (rdbStore_ == nullptr) { - ANSR_LOGE("Rdb store is not initialized."); - return reminders; - } - std::shared_ptr queryResultSet = Query(queryCondition); - if (queryResultSet == nullptr) { - return reminders; - } - bool isAtLastRow = false; - queryResultSet->IsAtLastRow(isAtLastRow); - while (!isAtLastRow) { - queryResultSet->GoToNextRow(); - sptr reminder; - reminder = BuildReminder(queryResultSet); - reminders.push_back(reminder); - queryResultSet->IsAtLastRow(isAtLastRow); - } - ANSR_LOGD("Size=%{public}d", reminders.size()); - return reminders; -} - -sptr ReminderStore::BuildReminder(const std::shared_ptr &resultSet) -{ - int32_t reminderType; - int32_t reminderId; - resultSet->GetInt(ReminderStore::GetColumnIndex(ReminderRequest::REMINDER_TYPE), reminderType); - resultSet->GetInt(ReminderStore::GetColumnIndex(ReminderRequest::REMINDER_ID), reminderId); - - sptr reminder = nullptr; - switch (reminderType) { - case (static_cast(ReminderRequest::ReminderType::TIMER)): { - reminder = new ReminderRequestTimer(reminderId); - break; - } - case (static_cast(ReminderRequest::ReminderType::CALENDAR)): { - reminder = new ReminderRequestCalendar(reminderId); - break; - } - case (static_cast(ReminderRequest::ReminderType::ALARM)): { - reminder = new ReminderRequestAlarm(reminderId); - break; - } - default: { - ANSR_LOGE("ReminderType from database is error, reminderType %{public}d.", reminderType); - break; - } - } - if (reminder != nullptr) { - reminder->RecoverFromDb(resultSet); - ANSR_LOGI("BuildReminder success."); - } else { - ANSR_LOGW("BuildReminder fail."); - } - return reminder; -} - -bool ReminderStore::GetBundleOption(const int32_t &reminderId, sptr &bundleOption) const -{ - std::string queryCondition = "select " + ReminderRequest::PKG_NAME + ", " - + ReminderRequest::UID + " from " + REMINDER_DB_TABLE + " where " - + ReminderRequest::REMINDER_ID + "=" + std::to_string(reminderId); - std::shared_ptr queryResultSet = Query(queryCondition); - if (queryResultSet == nullptr) { - return false; - } - bool isAtLastRow = false; - queryResultSet->IsAtLastRow(isAtLastRow); - if (isAtLastRow) { - return false; - } - queryResultSet->GoToNextRow(); - std::string pkgName; - GetStringVal(queryResultSet, ReminderRequest::PKG_NAME, pkgName); - int32_t uid; - GetInt32Val(queryResultSet, ReminderRequest::UID, uid); - bundleOption->SetBundleName(pkgName); - bundleOption->SetUid(uid); - return true; -} - -void ReminderStore::GetInt32Val(std::shared_ptr &resultSet, - const std::string &name, int32_t &value) const -{ - int32_t columnIndex; - resultSet->GetColumnIndex(name, columnIndex); - resultSet->GetInt(columnIndex, value); -} - -void ReminderStore::GetStringVal(std::shared_ptr &resultSet, - const std::string &name, std::string &value) const -{ - int32_t columnIndex; - resultSet->GetColumnIndex(name, columnIndex); - resultSet->GetString(columnIndex, value); -} - -void ReminderStore::GenerateData(const sptr &reminder, - const sptr &bundleOption, NativeRdb::ValuesBucket &values) const -{ - ReminderRequest::AppendValuesBucket(reminder, bundleOption, values); - ReminderRequestCalendar::AppendValuesBucket(reminder, bundleOption, values); - ReminderRequestAlarm::AppendValuesBucket(reminder, bundleOption, values); -} -} // namespace Notification -} // namespace OHOS diff --git a/frameworks/ans/native/test/unittest/BUILD.gn b/frameworks/ans/native/test/unittest/BUILD.gn index 5822ce2fc..6ff225e5b 100644 --- a/frameworks/ans/native/test/unittest/BUILD.gn +++ b/frameworks/ans/native/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -47,18 +47,17 @@ ohos_unittest("ans_reminder_unit_test") { external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "bytrace_standard:bytrace_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", + "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", - "native_appdatamgr:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index ff4682817..de3b5012a 100644 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -54,7 +54,6 @@ ohos_moduletest("ans_fw_module_test") { "mock/blob.cpp", "mock/distributed_kv_data_manager.cpp", "mock/mock_bundle_manager.cpp", - "mock/mock_bundle_manager_helper.cpp", "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_change_notification.cpp", "mock/mock_common_event_data.cpp", @@ -81,18 +80,17 @@ ohos_moduletest("ans_fw_module_test") { external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", + "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", - "native_appdatamgr:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] @@ -129,7 +127,6 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "mock/blob.cpp", "mock/distributed_kv_data_manager.cpp", "mock/mock_bundle_manager.cpp", - "mock/mock_bundle_manager_helper.cpp", "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_change_notification.cpp", "mock/mock_common_event_data.cpp", @@ -157,18 +154,17 @@ ohos_moduletest("ans_innerkits_module_publish_test") { external_deps = [ "ability_base:base", "ability_base:want", - "ability_base:zuri", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", + "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", - "native_appdatamgr:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] @@ -205,7 +201,6 @@ ohos_moduletest("ans_innerkits_module_slot_test") { "mock/blob.cpp", "mock/distributed_kv_data_manager.cpp", "mock/mock_bundle_manager.cpp", - "mock/mock_bundle_manager_helper.cpp", "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_change_notification.cpp", "mock/mock_common_event_data.cpp", @@ -232,18 +227,17 @@ ohos_moduletest("ans_innerkits_module_slot_test") { external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", + "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", - "native_appdatamgr:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] @@ -280,7 +274,6 @@ ohos_moduletest("ans_innerkits_module_setting_test") { "mock/blob.cpp", "mock/distributed_kv_data_manager.cpp", "mock/mock_bundle_manager.cpp", - "mock/mock_bundle_manager_helper.cpp", "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_change_notification.cpp", "mock/mock_common_event_data.cpp", @@ -307,18 +300,17 @@ ohos_moduletest("ans_innerkits_module_setting_test") { external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", + "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", - "native_appdatamgr:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] @@ -341,8 +333,8 @@ group("moduletest") { deps += [ # ":ReminderAgentJsTest", # ":ans_fw_module_test", - # ":ans_innerkits_module_publish_test", - # ":ans_innerkits_module_setting_test", - # ":ans_innerkits_module_slot_test", + ":ans_innerkits_module_publish_test", + ":ans_innerkits_module_setting_test", + ":ans_innerkits_module_slot_test", ] } diff --git a/frameworks/ans/test/moduletest/ReminderHelperTest.js b/frameworks/ans/test/moduletest/ReminderHelperTest.js index c3952cb15..8f759bb5a 100644 --- a/frameworks/ans/test/moduletest/ReminderHelperTest.js +++ b/frameworks/ans/test/moduletest/ReminderHelperTest.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -108,7 +108,8 @@ describe("ReminderHelperTest", function () { */ it("testReminderHelper003", 0, async function (done) { function reminderCallback(err, data) { - expect(true).assertEqual(true); + let i = 0; + expect(0).assertEqual(i); } reminderAgent.addNotificationSlot(0, reminderCallback); done(); @@ -244,13 +245,14 @@ describe("ReminderHelperTest", function () { reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, triggerTimeInSeconds: 3 } + let id = 1; let publishlength = -1; let cancellength = -1; let firstdiff = -1; reminderAgent.publishReminder(timer).then(() => { reminderAgent.getValidReminders().then((reminders) => { publishlength=reminders.length - reminderAgent.cancelReminder(0).then(() => { + reminderAgent.cancelReminder(id).then(() => { reminderAgent.getValidReminders().then((reminders) => { cancellength = reminders.length firstdiff = publishlength - cancellength; @@ -317,8 +319,10 @@ describe("ReminderHelperTest", function () { reminderAgent.getValidReminders((err, reminders) => { cancellength = reminders.length; firstdiff = publishlength - cancellength; - if (firstdiff === 0 || firstdiff === 1) { + if (firstdiff === 0) { expect(0).assertEqual(firstdiff); + } else if (firstdiff === 1) { + expect(1).assertEqual(firstdiff); } }); }); @@ -353,8 +357,10 @@ describe("ReminderHelperTest", function () { reminderAgent.getValidReminders((err, reminders) => { cancellength = reminders.length; firstdiff = publishlength - cancellength; - if (firstdiff === 0 || firstdiff === 1) { + if (firstdiff === 0) { expect(0).assertEqual(firstdiff); + } else if (firstdiff === 1) { + expect(1).assertEqual(firstdiff); } }); }); @@ -840,7 +846,7 @@ describe("ReminderHelperTest", function () { slotType:3 } reminderAgent.publishReminder(calendar).then((reminderId) => { - expect(typeof(reminderId) === 'number').assertEqual(true); + expect(typeof(reminderId)).assertEqual('number'); }); done(); }) diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index e5fec4ec0..e7d017b0b 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -28,7 +28,6 @@ #include "ans_manager_proxy.h" #include "common_event_manager.h" #include "common_event_support.h" -#include "datetime_ex.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "mock_ipc_skeleton.h" @@ -64,7 +63,6 @@ const std::string KVSTORE_PREFERENCES_STORE_ID = "distributed_preferences"; const std::string KVSTORE_SCREEN_STATUS_STORE_ID = "distributed_screen_status"; constexpr int UID = 1; -constexpr int USER_ID = 0; constexpr int CANCEL_REASON_DELETE = 2; constexpr int APP_CANCEL_REASON_DELETE = 8; constexpr int APP_CANCEL_ALL_REASON_DELETE = 9; @@ -474,9 +472,7 @@ public: void Parse(std::list> events) { - GTEST_LOG_(INFO) << "TestAnsSubscriber::Parse event size=" << events.size(); for (auto event : events) { - GTEST_LOG_(INFO) << "TestAnsSubscriber::Parse event type=" << static_cast(event->GetType()); if (event->GetType() == SubscriberEventType::ON_SUBSCRIBERESULT) { waitOnSubscriber_ = true; } else if (event->GetType() == SubscriberEventType::ON_CONSUMED) { @@ -674,8 +670,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_FlowControl_00100, Function | MediumTest | L int32_t notificationIdInt = i; if (i < MAX_ACTIVE_NUM_PERSECOND) { std::stringstream stream; - stream << KEY_SPLITER << USER_ID << KEY_SPLITER << UID << KEY_SPLITER - << notificationLabel << KEY_SPLITER << notificationIdInt; + stream << KEY_SPLITER << UID << KEY_SPLITER << notificationLabel << KEY_SPLITER << notificationIdInt; std::string notificationKey = stream.str(); NotificationSorting sorting; EXPECT_EQ(eventParser.GetOnConsumedReq()[i]->GetLabel().c_str(), notificationLabel); @@ -731,7 +726,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitonsByKey_00100, Function | M EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 0); std::stringstream stream; - stream << KEY_SPLITER << USER_ID << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0; + stream << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0; std::string notificationKey = stream.str(); NotificationSorting sorting; EXPECT_EQ(eventParser.GetOnCanceledReq()[0]->GetKey(), notificationKey); @@ -821,7 +816,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitons_00100, Function | Medium eventParser.Parse(events); EXPECT_TRUE(eventParser.GetWaitOnConsumed()); SleepForFC(); - EXPECT_EQ(NotificationHelper::RemoveNotifications(USER_ID), ERR_OK); + EXPECT_EQ(NotificationHelper::RemoveNotifications(), ERR_OK); std::vector> notifications; EXPECT_EQ(NotificationHelper::GetAllActiveNotifications(notifications), ERR_OK); EXPECT_EQ((int)notifications.size(), (int)0); @@ -1004,7 +999,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_CancelNotificationById_00100, Function | Med EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 1); std::stringstream stream; - stream << KEY_SPLITER << USER_ID << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 1; + stream << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 1; std::string notificationKey = stream.str(); NotificationSorting sorting; EXPECT_EQ(eventParser.GetOnCanceledReq()[0]->GetKey(), notificationKey); @@ -1099,7 +1094,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_CancelAllNotifications_00100, Function | Med EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetLabel().c_str(), NOTIFICATION_LABEL_0); EXPECT_EQ(eventParser.GetOnConsumedReq()[0]->GetId(), 0); std::stringstream stream0; - stream0 << KEY_SPLITER << USER_ID << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0; + stream0 << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0; std::string notificationKey0 = stream0.str(); NotificationSorting sorting0; EXPECT_EQ(eventParser.GetOnCanceledReq()[0]->GetKey(), notificationKey0); @@ -1111,7 +1106,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_CancelAllNotifications_00100, Function | Med EXPECT_EQ(eventParser.GetOnConsumedReq()[1]->GetLabel().c_str(), NOTIFICATION_LABEL_1); EXPECT_EQ(eventParser.GetOnConsumedReq()[1]->GetId(), 1); std::stringstream stream1; - stream1 << KEY_SPLITER << USER_ID << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_1 << KEY_SPLITER << 1; + stream1 << KEY_SPLITER << UID << KEY_SPLITER << NOTIFICATION_LABEL_1 << KEY_SPLITER << 1; std::string notificationKey1 = stream1.str(); NotificationSorting sorting1; EXPECT_EQ(eventParser.GetOnCanceledReq()[1]->GetKey(), notificationKey1); @@ -1792,7 +1787,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Publish_00300, Function | Medi ASSERT_EQ(NotificationHelper::PublishNotification(request), ERR_OK); ASSERT_EQ(pointer->GetEntries(DistributedKv::Key(""), entries), DistributedKv::Status::SUCCESS); DistributedKv::Entry outEntry; - ASSERT_EQ(GetRequestInDistributedEntryList(request, entries, outEntry), true); + ASSERT_EQ(GetRequestInDistributedEntryList(request, entries, outEntry), false); AppExecFwk::MockSetDistributedNotificationEnabled(true); SleepForFC(); } @@ -1915,7 +1910,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Remove_00200, Function | Mediu ASSERT_EQ(pointer->GetEntries(DistributedKv::Key(""), entries), DistributedKv::Status::SUCCESS); ASSERT_EQ(GetRequestInDistributedEntryList(request, entries, outEntry), true); - ASSERT_EQ(NotificationHelper::RemoveNotifications(USER_ID), ERR_OK); + ASSERT_EQ(NotificationHelper::RemoveNotifications(), ERR_OK); ASSERT_EQ(pointer->GetEntries(DistributedKv::Key(""), entries), DistributedKv::Status::SUCCESS); ASSERT_EQ(entries.size(), std::size_t(0)); SleepForFC(); @@ -1984,7 +1979,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Subscribe_00100, Function | Me EventParser parser1; parser1.Parse(subscriber.GetEvents()); - auto notificationList = parser1.GetOnConsumedWithSortingMapReq(); + auto notificationList = parser1.GetOnConsumedReq(); EXPECT_NE(notificationList.size(), std::size_t(0)); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); @@ -1995,7 +1990,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Subscribe_00100, Function | Me EventParser parser2; parser2.Parse(subscriber.GetEvents()); - notificationList = parser2.GetOnConsumedWithSortingMapReq(); + notificationList = parser2.GetOnConsumedReq(); EXPECT_NE(notificationList.size(), std::size_t(0)); EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); subscriber.ClearEvents(); @@ -2045,7 +2040,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Subscribe_00200, Function | Me EventParser parser1; parser1.Parse(subscriber.GetEvents()); - auto notificationList = parser1.GetOnConsumedWithSortingMapReq(); + auto notificationList = parser1.GetOnConsumedReq(); EXPECT_NE(notificationList.size(), std::size_t(0)); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); @@ -2119,12 +2114,12 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00100, Function | MediumTest | Lev TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + EXPECT_EQ(NotificationHelper::PublishNotification(request), ERR_OK); - SleepForFC(); EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedWithSortingMapReq(); + auto notificationList = parser.GetOnConsumedReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND); @@ -2150,12 +2145,12 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00200, Function | MediumTest | Lev TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + EXPECT_EQ(NotificationHelper::PublishNotification(request), ERR_OK); - SleepForFC(); EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedWithSortingMapReq(); + auto notificationList = parser.GetOnConsumedReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND); @@ -2181,12 +2176,12 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00300, Function | MediumTest | Lev TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + EXPECT_EQ(NotificationHelper::PublishNotification(request), ERR_OK); - SleepForFC(); EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedWithSortingMapReq(); + auto notificationList = parser.GetOnConsumedReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_IDLE_REMIND); @@ -2212,12 +2207,12 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00400, Function | MediumTest | Lev TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + EXPECT_EQ(NotificationHelper::PublishNotification(request), ERR_OK); - SleepForFC(); EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedWithSortingMapReq(); + auto notificationList = parser.GetOnConsumedReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_IDLE_DONOT_REMIND); @@ -2246,23 +2241,21 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00500, Function | MediumTest | Lev PublishCommonEventScreenStatus(true); + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); DistributedKv::AppId appId = {.appId = KVSTORE_APP_ID}; - DistributedKv::StoreId storeId = {.storeId = KVSTORE_NOTIFICATION_STORE_ID}; + DistributedKv::StoreId storeId = {.storeId = KVSTORE_SCREEN_STATUS_STORE_ID}; std::shared_ptr pointer = DistributedKv::AnsTestSingleKvStore::GetMockKvStorePointer(appId, storeId); - TestAnsSubscriber subscriber; - EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - DistributedKv::Key key(GenerateDistributedKey(request, REMOTE_DEVICE_ID)); DistributedKv::Value value(jsonString); pointer->InsertDataToDoCallback(key, value); SleepForFC(); - SleepForFC(); EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedWithSortingMapReq(); + auto notificationList = parser.GetOnConsumedReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND); @@ -2291,14 +2284,13 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00600, Function | MediumTest | Lev PublishCommonEventScreenStatus(false); + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); DistributedKv::AppId appId = {.appId = KVSTORE_APP_ID}; - DistributedKv::StoreId storeId = {.storeId = KVSTORE_NOTIFICATION_STORE_ID}; + DistributedKv::StoreId storeId = {.storeId = KVSTORE_SCREEN_STATUS_STORE_ID}; std::shared_ptr pointer = DistributedKv::AnsTestSingleKvStore::GetMockKvStorePointer(appId, storeId); - TestAnsSubscriber subscriber; - EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - DistributedKv::Key key(GenerateDistributedKey(request, REMOTE_DEVICE_ID)); DistributedKv::Value value(jsonString); pointer->InsertDataToDoCallback(key, value); @@ -2306,7 +2298,7 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00600, Function | MediumTest | Lev EventParser parser; parser.Parse(subscriber.GetEvents()); - auto notificationList = parser.GetOnConsumedWithSortingMapReq(); + auto notificationList = parser.GetOnConsumedReq(); std::shared_ptr outNotification; EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true); EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_IDLE_DONOT_REMIND); @@ -2322,11 +2314,7 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07100, Function IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - - std::shared_ptr implContent = std::make_shared(); - std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); - req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); SleepForFC(); @@ -2361,11 +2349,7 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07200, Function IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - - std::shared_ptr implContent = std::make_shared(); - std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); - req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); SleepForFC(); @@ -2402,11 +2386,7 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07300, Function IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - - std::shared_ptr implContent = std::make_shared(); - std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); - req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); SleepForFC(); @@ -2439,10 +2419,7 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07300, Function HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07400, Function | MediumTest | Level1) { - std::shared_ptr implContent = std::make_shared(); - std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); - req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), (int)ERR_ANS_NOT_SYSTEM_SERVICE); } @@ -2489,10 +2466,7 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07600, Function TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - std::shared_ptr implContent = std::make_shared(); - std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); - req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); @@ -2518,11 +2492,7 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07700, Function IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - - std::shared_ptr implContent = std::make_shared(); - std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); - req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); SleepForFC(); @@ -2560,11 +2530,7 @@ HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_PulbishContinuousTask_07800, Function IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); TestAnsSubscriber subscriber; EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); - - std::shared_ptr implContent = std::make_shared(); - std::shared_ptr content = std::make_shared(implContent); NotificationRequest req(0); - req.SetContent(content); req.SetLabel(NOTIFICATION_LABEL_0); EXPECT_EQ(NotificationHelper::PublishContinuousTaskNotification(req), ERR_OK); SleepForFC(); diff --git a/frameworks/ans/test/moduletest/mock/include/mock_bundle_manager.h b/frameworks/ans/test/moduletest/mock/include/mock_bundle_manager.h index 3f04edd54..ce1ef007f 100644 --- a/frameworks/ans/test/moduletest/mock/include/mock_bundle_manager.h +++ b/frameworks/ans/test/moduletest/mock/include/mock_bundle_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -178,7 +178,7 @@ public: } /** * @brief Query the AbilityInfo by the given Want. - * @param want Indicates the information of the ability. + * @param want Indicates the infomation of the ability. * @param abilityInfo Indicates the obtained AbilityInfo object. * @return Returns true if the AbilityInfo is successfully obtained; returns false otherwise. */ @@ -449,11 +449,11 @@ public: return true; } /** - * @brief Dump the bundle information with specific flags. + * @brief Dump the bundle informations with specifc flags. * @param flag Indicates the information contained in the dump result. * @param bundleName Indicates the bundle name if needed. * @param userId Indicates the user ID. - * @param result Indicates the dump information result. + * @param result Indicates the dump infomation result. * @return Returns true if the dump result is successfully obtained; returns false otherwise. */ virtual bool DumpInfos( diff --git a/frameworks/ans/test/moduletest/mock/mock_bundle_manager_helper.cpp b/frameworks/ans/test/moduletest/mock/mock_bundle_manager_helper.cpp deleted file mode 100644 index fdeac6723..000000000 --- a/frameworks/ans/test/moduletest/mock/mock_bundle_manager_helper.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "bundle_manager_helper.h" - -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - -namespace OHOS { -namespace Notification { -BundleManagerHelper::BundleManagerHelper() -{} - -BundleManagerHelper::~BundleManagerHelper() -{} - -void BundleManagerHelper::OnRemoteDied(const wptr &object) -{} - -std::string BundleManagerHelper::GetBundleNameByUid(int uid) -{ - return "bundleName"; -} - -bool BundleManagerHelper::IsSystemApp(int uid) -{ - return true; -} - -int BundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId) -{ - return 1000; -} - -bool BundleManagerHelper::GetBundleInfoByBundleName( - const std::string bundle, const int32_t userId, AppExecFwk::BundleInfo &bundleInfo) -{ - return true; -} - -void BundleManagerHelper::Connect() -{} - -void BundleManagerHelper::Disconnect() -{} -} // namespace Notification -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index 798913b6a..36c16a871 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -19,11 +19,9 @@ #include #include -#include "abs_shared_result_set.h" #include "notification_bundle_option.h" #include "notification_constant.h" #include "notification_request.h" -#include "values_bucket.h" namespace OHOS { namespace Notification { @@ -78,7 +76,6 @@ public: REMOVAL_WANT_AGENT, WANT_AGENT, MAX_SCREEN_WANT_AGENT, - BUNDLE_INFO, CONTENT }; @@ -133,14 +130,6 @@ public: * @param Indicates the exist reminder. */ explicit ReminderRequest(const ReminderRequest &other); - - /** - * @brief This constructor should only be used in background proxy service process - * when reminder instance recovery from database. - * - * @param reminderId Indicates reminder id. - */ - explicit ReminderRequest(int32_t reminderId); ReminderRequest& operator = (const ReminderRequest &other); virtual ~ReminderRequest() override {}; @@ -268,9 +257,6 @@ public: */ uint64_t GetTriggerTimeInMilli() const; - int GetUserId() const; - int32_t GetUid() const; - /** * @brief Obtains want agent information. * @@ -295,16 +281,6 @@ public: */ void InitUserId(const int &userId); - /** - * @brief Inites reminder uid when publish reminder success. - * - * When system reboot and recovery from database, we cannot get the uid according user id as BMS has not be - * ready. So we need to record the uid in order to create correct bundleOption. - * - * @param uid Indicates the uid which the reminder belong to. - */ - void InitUid(const int32_t &uid); - /** * @brief Check the reminder is alerting or not. * @@ -403,15 +379,6 @@ public: */ virtual bool OnTimeZoneChange(); - /** - * @brief Recovery reminder instance from database record. - * - * @param resultSet Indicates the resultSet with pointer to the row of record data. - */ - virtual void RecoverFromDb(const std::shared_ptr &resultSet); - void RecoverActionButton(const std::shared_ptr &resultSet); - void RecoverWantAgent(std::string wantAgentInfo, const uint8_t &type); - /** * @brief Sets action button. * @@ -559,14 +526,6 @@ public: */ void UpdateNotificationRequest(UpdateNotificationType type, std::string extra); - static int GetActualTime(const TimeTransferType &type, int cTime); - static int GetCTime(const TimeTransferType &type, int actualTime); - static uint64_t GetDurationSinceEpochInMilli(const time_t target); - static int32_t GetUid(const int &userId, const std::string &bundleName); - static int GetUserId(const int &uid); - static void AppendValuesBucket(const sptr &reminder, - const sptr &bundleOption, NativeRdb::ValuesBucket &values); - static int32_t GLOBAL_ID; static const uint64_t INVALID_LONG_LONG_VALUE; static const uint16_t INVALID_U16_VALUE; @@ -600,49 +559,13 @@ public: */ static const std::string REMINDER_EVENT_REMOVE_NOTIFICATION; static const std::string PARAM_REMINDER_ID; - static const uint8_t REMINDER_STATUS_INACTIVE; - static const uint8_t REMINDER_STATUS_ACTIVE; - static const uint8_t REMINDER_STATUS_ALERTING; - static const uint8_t REMINDER_STATUS_SHOWING; - static const uint8_t REMINDER_STATUS_SNOOZE; - - // For database recovery. - static void InitDbColumns(); - static const std::string REMINDER_ID; - static const std::string PKG_NAME; - static const std::string USER_ID; - static const std::string UID; - static const std::string APP_LABEL; - static const std::string REMINDER_TYPE; - static const std::string REMINDER_TIME; - static const std::string TRIGGER_TIME; - static const std::string RTC_TRIGGER_TIME; - static const std::string TIME_INTERVAL; - static const std::string SNOOZE_TIMES; - static const std::string DYNAMIC_SNOOZE_TIMES; - static const std::string RING_DURATION; - static const std::string IS_EXPIRED; - static const std::string IS_ACTIVE; - static const std::string STATE; - static const std::string ZONE_ID; - static const std::string HAS_SCHEDULED_TIMEOUT; - static const std::string ACTION_BUTTON_INFO; - static const std::string SLOT_ID; - static const std::string NOTIFICATION_ID; - static const std::string TITLE; - static const std::string CONTENT; - static const std::string SNOOZE_CONTENT; - static const std::string EXPIRED_CONTENT; - static const std::string AGENT; - static const std::string MAX_SCREEN_AGENT; - static std::string sqlOfAddColumns; - static std::vector columns; + static int GetActualTime(const TimeTransferType &type, int cTime); + static int GetCTime(const TimeTransferType &type, int actualTime); + static uint64_t GetDurationSinceEpochInMilli(const time_t target); + static int32_t GetUid(const int &userId, const std::string &bundleName); + static int GetUserId(const int &uid); protected: - enum class DbRecoveryType : uint8_t { - INT, - LONG - }; ReminderRequest(); explicit ReminderRequest(ReminderType reminderType); std::string GetDateTimeInfo(const time_t &timeInSecond) const; @@ -650,25 +573,12 @@ protected: { return INVALID_LONG_LONG_VALUE; } - int64_t RecoverInt64FromDb(const std::shared_ptr &resultSet, - const std::string &columnName, const DbRecoveryType &columnType); - /** - * @brief For database recovery. - * - * Add column to create table of database. - * - * @param name Indicates the column name. - * @param type Indicates the type of the column. - * @param isEnd Indicates whether it is the last column. - */ - static void AddColumn(const std::string &name, const std::string &type, const bool &isEnd); private: void AddActionButtons(const bool includeSnooze); void AddRemovalWantAgent(); std::shared_ptr CreateWantAgent(AppExecFwk::ElementName &element) const; - std::string GetButtonInfo() const; uint64_t GetNowInstantMilli() const; std::string GetShowTime(const uint64_t showTime) const; std::string GetTimeInfoInner(const time_t &timeInSecond, const TimeFormat &format) const; @@ -676,23 +586,14 @@ private: bool HandleSysTimeChange(uint64_t oriTriggerTime, uint64_t optTriggerTime); bool HandleTimeZoneChange(uint64_t oldZoneTriggerTime, uint64_t newZoneTriggerTime, uint64_t optTriggerTime); bool InitNotificationRequest(); - void InitServerObj(); void SetMaxScreenWantAgent(AppExecFwk::ElementName &element); void SetState(bool deSet, const uint8_t newState, std::string function); void SetWantAgent(AppExecFwk::ElementName &element); - std::vector StringSplit(std::string source, const std::string &split) const; void UpdateActionButtons(const bool &setSnooze); bool UpdateNextReminder(const bool &force); void UpdateNotificationContent(const bool &setSnooze); void UpdateNotificationCommon(); - /** - * @brief Used for reminder recovery from database. - * - * @param bundleName Indicates the third part bundle name. - */ - void UpdateNotificationBundleInfo(); - /** * @brief Update the notification, which will be shown for the "Alerting" reminder. * 1. Update the notification label/content. @@ -707,17 +608,18 @@ private: */ void UpdateNotificationStateForSnooze(); + static const uint8_t REMINDER_STATUS_INACTIVE; + static const uint8_t REMINDER_STATUS_ACTIVE; + static const uint8_t REMINDER_STATUS_ALERTING; + static const uint8_t REMINDER_STATUS_SHOWING; + static const uint8_t REMINDER_STATUS_SNOOZE; static const uint32_t MIN_TIME_INTERVAL_IN_MILLI; - static const std::string SEP_BUTTON_SINGLE; - static const std::string SEP_BUTTON_MULTI; - static const std::string SEP_WANT_AGENT; std::string content_ {}; std::string expiredContent_ {}; std::string snoozeContent_ {}; std::string displayContent_ {}; std::string title_ {}; - std::string bundleName_ {}; bool isExpired_ {false}; uint8_t snoozeTimes_ {0}; uint8_t snoozeTimesDynamic_ {0}; @@ -725,7 +627,6 @@ private: int32_t notificationId_ {0}; int32_t reminderId_ {-1}; int userId_ {-1}; - int32_t uid_ {-1}; // Indicates the reminder has been shown in the past time. // When the reminder has been created but not showed, it is equals to 0. diff --git a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h index 705dbf0a0..6c943699e 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h @@ -40,14 +40,6 @@ public: */ ReminderRequestAlarm(uint8_t hour, uint8_t minute, std::vector daysOfWeek); - /** - * @brief This constructor should only be used in background proxy service process - * when reminder instance recovery from database. - * - * @param reminderId Indicates reminder id. - */ - explicit ReminderRequestAlarm(int32_t reminderId) : ReminderRequest(reminderId) {}; - /** * @brief Copy construct from an exist reminder. * @@ -104,12 +96,6 @@ public: * @return true if read parcel success. */ bool ReadFromParcel(Parcel &parcel) override; - virtual void RecoverFromDb(const std::shared_ptr &resultSet) override; - static void AppendValuesBucket(const sptr &reminder, - const sptr &bundleOption, NativeRdb::ValuesBucket &values); - - // For database recovery. - static void InitDbColumns(); protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; @@ -162,11 +148,6 @@ private: uint8_t hour_ = {0}; uint8_t minute_ = {0}; uint8_t repeatDays_ = {0}; - - // For database recovery. - static const std::string REPEAT_DAYS_OF_WEEK; - static const std::string ALARM_HOUR; - static const std::string ALARM_MINUTE; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h index 1023f2332..638b881aa 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h @@ -52,14 +52,6 @@ public: ReminderRequestCalendar(const tm &dateTime, const std::vector &repeatMonths, const std::vector &repeatDays); - /** - * @brief This constructor should only be used in background proxy service process - * when reminder instance recovery from database. - * - * @param reminderId Indicates reminder id. - */ - explicit ReminderRequestCalendar(int32_t reminderId) : ReminderRequest(reminderId) {}; - explicit ReminderRequestCalendar(const ReminderRequestCalendar &other); ReminderRequestCalendar& operator = (const ReminderRequestCalendar &other); ~ReminderRequestCalendar() override {} @@ -141,14 +133,8 @@ public: static const uint8_t MAX_MONTHS_OF_YEAR; static const uint8_t MAX_DAYS_OF_MONTH; - virtual void RecoverFromDb(const std::shared_ptr &resultSet) override; - static void AppendValuesBucket(const sptr &reminder, - const sptr &bundleOption, NativeRdb::ValuesBucket &values); static uint8_t GetDaysOfMonth(const uint16_t &year, const uint8_t &month); - // For database recovery. - static void InitDbColumns(); - protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; @@ -158,14 +144,6 @@ private: uint8_t GetNextDay(const uint16_t &settedYear, const uint8_t &settedMonth, const tm &now, const tm &target) const; uint64_t GetNextTriggerTime() const; uint64_t GetNextTriggerTimeAsRepeatReminder(const tm &nowTime, const tm &tarTime) const; - uint32_t GetRepeatDay() const - { - return repeatDay_; - } - uint16_t GetRepeatMonth() const - { - return repeatMonth_; - } uint64_t GetTimeInstantMilli( uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) const; @@ -208,18 +186,6 @@ private: uint8_t second_ {0}; 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; }; } } diff --git a/interfaces/innerkits/ans/native/include/reminder_request_timer.h b/interfaces/innerkits/ans/native/include/reminder_request_timer.h index 673bf2885..19c279d33 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_timer.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_timer.h @@ -33,14 +33,6 @@ public: */ explicit ReminderRequestTimer(uint64_t countDownTimeInSeconds); - /** - * @brief This constructor should only be used in background proxy service process - * when reminder instance recovery from database. - * - * @param reminderId Indicates reminder id. - */ - explicit ReminderRequestTimer(int32_t reminderId) : ReminderRequest(reminderId) {}; - /** * @brief Copy construct from an exist reminder. * diff --git a/interfaces/innerkits/ans/native/include/reminder_store.h b/interfaces/innerkits/ans/native/include/reminder_store.h deleted file mode 100644 index cea23b096..000000000 --- a/interfaces/innerkits/ans/native/include/reminder_store.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_STORE_H -#define BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_STORE_H - -#include - -#include "notification_bundle_option.h" -#include "reminder_request.h" -#include "rdb_errno.h" -#include "rdb_helper.h" -#include "rdb_open_callback.h" -#include "rdb_store_config.h" - -namespace OHOS { -namespace Notification { -class ReminderStore { -public: - ReminderStore() {}; - virtual ~ReminderStore() {}; - int32_t Init(); - int32_t Delete(int32_t reminderId); - int32_t Delete(const std::string &pkg, int32_t userId); - int32_t DeleteUser(int32_t userId); - std::vector> GetAllValidReminders(); - bool GetBundleOption(const int32_t &reminderId, sptr &bundleOption) const; - int32_t GetMaxId(); - int64_t UpdateOrInsert(const sptr &reminder, const sptr &bundleOption); - static uint8_t GetColumnIndex(const std::string& name); - - static const int32_t STATE_OK; - -private: - /** - * @brief Inits the data in database when system boot on or proxy process reboot on. - * - * 1. Deletes all the reminders which IS_EXPIRED is true. - * 2. Sets all the value of STATE to ReminderRequest::REMINDER_STATUS_INACTIVE - * 3. Sets all the value of IS_ACTIVE to false. - * 4. Sets all the value of HAS_SCHEDULED_TIMEOUT to false. - * - * @return int32_t result code. - */ - int32_t InitData(); - sptr BuildReminder(const std::shared_ptr &resultSet); - int32_t Delete(const std::string &deleteCondition); - void GetInt32Val(std::shared_ptr &resultSet, - const std::string &name, int32_t &value) const; - void GetStringVal(std::shared_ptr &resultSet, - const std::string &name, std::string &value) const; - std::vector> GetReminders(const std::string &queryCondition); - void GenerateData(const sptr &remindert, - const sptr &bundleOption, NativeRdb::ValuesBucket &values) const; - bool IsReminderExist(const sptr &reminder); - int64_t Insert(const sptr &reminder, const sptr &bundleOption); - std::shared_ptr Query(const std::string &queryCondition) const; - int64_t Update(const sptr &reminder, const sptr &bundleOption); - -class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback { -public: - int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; - int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override; -}; - -private: - std::shared_ptr rdbStore_ = nullptr; -}; -} // namespace Notification -} // namespace OHOS -#endif // BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_STORE_H \ No newline at end of file diff --git a/interfaces/kits/js/@ohos.reminderAgent.d.ts b/interfaces/kits/js/@ohos.reminderAgent.d.ts index f227a9b73..4fb85da2d 100644 --- a/interfaces/kits/js/@ohos.reminderAgent.d.ts +++ b/interfaces/kits/js/@ohos.reminderAgent.d.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"), * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -408,13 +408,6 @@ declare namespace reminderAgent { * @syscap SystemCapability.Notification.ReminderAgent. */ minute: number; - - /** - * value of minute. - * @since 7 - * @syscap SystemCapability.Notification.ReminderAgent. - */ - second: number; } } export default reminderAgent; \ No newline at end of file diff --git a/interfaces/kits/napi/ans/BUILD.gn b/interfaces/kits/napi/ans/BUILD.gn index cc31ec338..74ee9b535 100644 --- a/interfaces/kits/napi/ans/BUILD.gn +++ b/interfaces/kits/napi/ans/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -76,14 +76,13 @@ ohos_shared_library("notification") { external_deps = [ "ability_base:base", "ability_base:want", - "ability_base:zuri", "ability_runtime:abilitykit_native", "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", + "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "napi:ace_napi", - "native_appdatamgr:native_rdb", ] relative_install_dir = "module" diff --git a/interfaces/kits/napi/ans/include/publish.h b/interfaces/kits/napi/ans/include/publish.h index 684921abd..6d8405209 100644 --- a/interfaces/kits/napi/ans/include/publish.h +++ b/interfaces/kits/napi/ans/include/publish.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,7 +21,6 @@ namespace OHOS { namespace NotificationNapi { using namespace OHOS::Notification; napi_value Publish(napi_env env, napi_callback_info info); -napi_value ShowNotification(napi_env env, napi_callback_info info); } // namespace NotificationNapi } // namespace OHOS #endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_PUBLISH_H \ No newline at end of file diff --git a/interfaces/kits/napi/ans/src/disturb_mode.cpp b/interfaces/kits/napi/ans/src/disturb_mode.cpp index dd0291acd..0bf8a47fb 100644 --- a/interfaces/kits/napi/ans/src/disturb_mode.cpp +++ b/interfaces/kits/napi/ans/src/disturb_mode.cpp @@ -308,13 +308,13 @@ napi_value GetDoNotDisturbDate(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - GetDoNotDisturbDateParams params {}; + SetDoNotDisturbDateParams params {}; if (ParseParameters(env, info, params) == nullptr) { return Common::NapiGetUndefined(env); } - AsyncCallbackInfoGetDoNotDisturb *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoGetDoNotDisturb {.env = env, .asyncWork = nullptr, .params = params}; + AsyncCallbackInfoSetDoNotDisturb *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoSetDoNotDisturb {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } diff --git a/interfaces/kits/napi/ans/src/init.cpp b/interfaces/kits/napi/ans/src/init.cpp index 6361a6a97..2a26b7ce3 100644 --- a/interfaces/kits/napi/ans/src/init.cpp +++ b/interfaces/kits/napi/ans/src/init.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -76,7 +76,6 @@ napi_value NotificationInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("enableDistributedSelf", EnableDistributedSelf), DECLARE_NAPI_FUNCTION("isDistributedEnableByBundle", IsDistributedEnableByBundle), DECLARE_NAPI_FUNCTION("getDeviceRemindType", GetDeviceRemindType), - DECLARE_NAPI_FUNCTION("show", ShowNotification), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); diff --git a/interfaces/kits/napi/ans/src/publish.cpp b/interfaces/kits/napi/ans/src/publish.cpp index 2c4b96095..d099d5211 100644 --- a/interfaces/kits/napi/ans/src/publish.cpp +++ b/interfaces/kits/napi/ans/src/publish.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -137,12 +137,15 @@ napi_value Publish(napi_env env, napi_callback_info info) [](napi_env env, napi_status status, void *data) { ANS_LOGI("Publish napi_create_async_work complete start"); AsyncCallbackInfoPublish *asynccallbackinfo = (AsyncCallbackInfoPublish *)data; + + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); if (asynccallbackinfo) { - Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); - if (asynccallbackinfo->info.callback != nullptr) { - napi_delete_reference(env, asynccallbackinfo->info.callback); - } - napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } @@ -159,11 +162,5 @@ napi_value Publish(napi_env env, napi_callback_info info) return promise; } } - -napi_value ShowNotification(napi_env env, napi_callback_info info) -{ - ANS_LOGI("ShowNotification enter"); - return Common::NapiGetNull(env); -} } // namespace NotificationNapi } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/ans/src/reminder/BUILD.gn b/interfaces/kits/napi/ans/src/reminder/BUILD.gn index 481065433..0cabca867 100644 --- a/interfaces/kits/napi/ans/src/reminder/BUILD.gn +++ b/interfaces/kits/napi/ans/src/reminder/BUILD.gn @@ -64,14 +64,13 @@ ohos_shared_library("reminderagent") { external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:abilitykit_native", "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", + "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "napi:ace_napi", - "native_appdatamgr:native_rdb", ] relative_install_dir = "module" diff --git a/interfaces/kits/napi/ans/src/reminder/publish.cpp b/interfaces/kits/napi/ans/src/reminder/publish.cpp index 911791e66..242a7d66c 100644 --- a/interfaces/kits/napi/ans/src/reminder/publish.cpp +++ b/interfaces/kits/napi/ans/src/reminder/publish.cpp @@ -73,7 +73,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, size_t argc = PUBLISH_PARAM_LEN; napi_value argv[PUBLISH_PARAM_LEN] = {nullptr}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - if ((argc < 1) || (argc > PUBLISH_PARAM_LEN)) { + if (argc < 1 || argc > PUBLISH_PARAM_LEN) { ANSR_LOGW("Wrong number of arguments"); return nullptr; } @@ -100,7 +100,7 @@ napi_value ParseCanCelParameter(const napi_env &env, const napi_callback_info &i size_t argc = CANCEL_PARAM_LEN; napi_value argv[CANCEL_PARAM_LEN] = {nullptr}; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); - if ((argc < 1) || (argc > CANCEL_PARAM_LEN)) { + if (argc < 1 || argc > CANCEL_PARAM_LEN) { ANSR_LOGW("Wrong number of arguments"); return nullptr; } diff --git a/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp index a874223f9..27f82b503 100644 --- a/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp +++ b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp @@ -366,24 +366,21 @@ napi_value ReminderCommon::CreateReminderAlarm( { // hour int32_t propertyHourVal = 0; - const int32_t maxHour = 23; if (!GetInt32(env, value, ReminderAgentNapi::ALARM_HOUR, propertyHourVal, true)) { return nullptr; } // minute int32_t propertyMinuteVal = 0; - const int32_t maxMinute = 59; if (!GetInt32(env, value, ReminderAgentNapi::ALARM_MINUTE, propertyMinuteVal, true)) { return nullptr; } - - if ((propertyHourVal < 0) || (propertyHourVal > maxHour)) { + if (propertyHourVal < 0 || propertyHourVal > 23) { ANSR_LOGW("Create alarm reminder fail: designated %{public}s must between [0, 23].", ReminderAgentNapi::ALARM_HOUR); return nullptr; } - if ((propertyMinuteVal < 0) || (propertyMinuteVal > maxMinute)) { + if (propertyMinuteVal < 0 || propertyMinuteVal > 59) { ANSR_LOGW("Create alarm reminder fail: designated %{public}s must between [0, 59].", ReminderAgentNapi::ALARM_MINUTE); return nullptr; @@ -415,11 +412,11 @@ napi_value ReminderCommon::CreateReminderCalendar( int32_t propertyDayVal = 0; int32_t propertyHourVal = 0; int32_t propertyMinteVal = 0; - if (!GetInt32(env, dateTimeObj, ReminderAgentNapi::CALENDAR_YEAR, propertyYearVal, true) || - !GetInt32(env, dateTimeObj, ReminderAgentNapi::CALENDAR_MONTH, propertyMonthVal, true) || - !GetInt32(env, dateTimeObj, ReminderAgentNapi::CALENDAR_DAY, propertyDayVal, true) || - !GetInt32(env, dateTimeObj, ReminderAgentNapi::CALENDAR_HOUR, propertyHourVal, true) || - !GetInt32(env, dateTimeObj, ReminderAgentNapi::CALENDAR_MINUTE, propertyMinteVal, true)) { + if (!GetInt32(env, dateTimeObj, ReminderAgentNapi::CALENDAR_YEAR, propertyYearVal, true) + || !GetInt32(env, dateTimeObj, ReminderAgentNapi::CALENDAR_MONTH, propertyMonthVal, true) + || !GetInt32(env, dateTimeObj, ReminderAgentNapi::CALENDAR_DAY, propertyDayVal, true) + || !GetInt32(env, dateTimeObj, ReminderAgentNapi::CALENDAR_HOUR, propertyHourVal, true) + || !GetInt32(env, dateTimeObj, ReminderAgentNapi::CALENDAR_MINUTE, propertyMinteVal, true)) { return nullptr; } if (!CheckCalendarParams(propertyYearVal, propertyMonthVal, propertyDayVal, @@ -456,18 +453,18 @@ napi_value ReminderCommon::CreateReminderCalendar( bool ReminderCommon::CheckCalendarParams(const int32_t &year, const int32_t &month, const int32_t &day, const int32_t &hour, const int32_t &min) { - if ((year < 0) || (year > UINT16_MAX)) { + if (year < 0 || year > UINT16_MAX) { ANSR_LOGW("Create calendar reminder fail: designated %{public}s must between [0, %{public}d]", ReminderAgentNapi::CALENDAR_YEAR, UINT16_MAX); return false; } - if ((month < 1 || month) > (ReminderRequestCalendar::MAX_MONTHS_OF_YEAR)) { + if (month < 1 || month > ReminderRequestCalendar::MAX_MONTHS_OF_YEAR) { ANSR_LOGW("Create calendar reminder fail: designated %{public}s must between [1, %{public}hhu]", ReminderAgentNapi::CALENDAR_MONTH, ReminderRequestCalendar::MAX_MONTHS_OF_YEAR); return false; } uint8_t maxDaysOfMonth = ReminderRequestCalendar::GetDaysOfMonth(static_cast(year), month); - if ((day < 1) || (day > maxDaysOfMonth)) { + if (day < 1 || day > maxDaysOfMonth) { ANSR_LOGW("Create calendar reminder fail: designated %{public}s must between [1, %{public}hhu]", ReminderAgentNapi::CALENDAR_DAY, maxDaysOfMonth); return false; diff --git a/notification.gni b/notification.gni index ed68c454f..d379ebca6 100644 --- a/notification.gni +++ b/notification.gni @@ -32,10 +32,10 @@ aafwk_path = "//foundation/aafwk/standard" ans_standard_external_deps = [ "ability_base:base", "ability_base:want", - "ability_base:zuri", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", + "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/ans/include/advanced_notification_service_ability.h b/services/ans/include/advanced_notification_service_ability.h index 236cdeb0e..ec5c866d8 100644 --- a/services/ans/include/advanced_notification_service_ability.h +++ b/services/ans/include/advanced_notification_service_ability.h @@ -19,7 +19,6 @@ #include "system_ability.h" #include "advanced_notification_service.h" -#include "reminder_data_manager.h" #include "system_ability_definition.h" namespace OHOS { @@ -37,7 +36,6 @@ private: private: sptr service_; - std::shared_ptr reminderAgent_; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 168891ff2..9805bb07c 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -22,17 +22,13 @@ #include "advanced_notification_service.h" #include "player.h" #include "reminder_request.h" -#include "reminder_store.h" #include "reminder_timer_info.h" namespace OHOS { namespace Notification { class ReminderDataManager final { public: - ReminderDataManager() - { - Init(false); - }; + ReminderDataManager() {}; ~ReminderDataManager() {}; ReminderDataManager(ReminderDataManager &other) = delete; @@ -76,8 +72,6 @@ public: * @return Single instance of ReminderDataManager. */ static std::shared_ptr GetInstance(); - static std::shared_ptr InitInstance( - sptr &advancedNotificationService); /** * Obtains all the valid reminders (which are not expired) relative to the bundle option. @@ -88,15 +82,6 @@ public: void GetValidReminders( const sptr bundleOption, std::vector> &reminders); - /** - * @brief Inits and recovery data from database. - * - * @param isFromBootComplete Indicates the init is called when boot completed. - */ - void Init(bool isFromBootComplete); - - void OnServiceStart(); - /** * @brief Triggered when third party application died. * @@ -209,8 +194,6 @@ private: */ std::shared_ptr CreateTimerInfo(TimerType type) const; - void GetImmediatelyShowRemindersLocked(std::vector> &reminders) const; - std::string GetSoundUri(const sptr &reminder); /** @@ -277,8 +260,6 @@ private: bool HandleSysTimeChange(const sptr reminder) const; - bool IsReminderAgentReady() const; - /** * Judge the two reminders is belong to the same application or not. * @@ -290,8 +271,6 @@ private: bool IsBelongToSameApp( const sptr reminder, const std::string otherPkgName, const int otherUserId); - void LoadReminderFromDb(); - void PlaySoundAndVibrationLocked(const sptr &reminder); void PlaySoundAndVibration(const sptr &reminder); void StopSoundAndVibrationLocked(const sptr &reminder); @@ -425,8 +404,6 @@ private: */ static const int16_t MAX_NUM_REMINDER_LIMIT_APP; - bool isReminderAgentReady_ = false; - /** * Vector used to record all the reminders in system. */ @@ -470,8 +447,7 @@ private: * Indicates the total count of reminders in system. */ int16_t totalCount_ {0}; - sptr advancedNotificationService_ = nullptr; - std::shared_ptr store_ = nullptr; + AdvancedNotificationService *advancedNotificationService_ = nullptr; }; } // namespace OHOS } // namespace Nofitifcation diff --git a/services/ans/include/reminder_event_manager.h b/services/ans/include/reminder_event_manager.h index 50aacfd84..0fb8b6556 100644 --- a/services/ans/include/reminder_event_manager.h +++ b/services/ans/include/reminder_event_manager.h @@ -18,7 +18,6 @@ #include "common_event_subscriber.h" #include "reminder_data_manager.h" -#include "system_ability_status_change_stub.h" #include @@ -46,16 +45,6 @@ private: void HandleProcessDied(OHOS::EventFwk::Want &want) const; std::shared_ptr reminderDataManager_ = nullptr; }; - -class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { -public: - explicit SystemAbilityStatusChangeListener(std::shared_ptr &reminderDataManager); - ~SystemAbilityStatusChangeListener() {}; - virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; - virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; -private: - std::shared_ptr reminderDataManager_ = nullptr; -}; }; } // namespace OHOS } // namespace Notification diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 38ff35137..8725821be 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1629,10 +1629,6 @@ ErrCode AdvancedNotificationService::PublishContinuousTaskNotification(const spt if (uid != SYSTEM_SERVICE_UID) { return ERR_ANS_NOT_SYSTEM_SERVICE; } - int userId = SUBSCRIBE_USER_INIT; - OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); - request->SetCreatorUserId(userId); - ANS_LOGD("%{public}s, uid=%{public}d userId=%{public}d", __FUNCTION__, uid, userId); if (request->GetCreatorBundleName().empty()) { request->SetCreatorBundleName(FOUNDATION_BUNDLE_NAME); @@ -1722,6 +1718,7 @@ ErrCode AdvancedNotificationService::PublishReminder(sptr &remi return result; } + ReminderDataManager::GetInstance()->SetService(this); sptr notificationRequest = reminder->GetNotificationRequest(); sptr bundleOption = nullptr; result = PrepareNotificationInfo(notificationRequest, bundleOption); @@ -1740,6 +1737,7 @@ ErrCode AdvancedNotificationService::PublishReminder(sptr &remi ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) { ANSR_LOGI("Cancel Reminder"); + ReminderDataManager::GetInstance()->SetService(this); sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -1755,6 +1753,7 @@ ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) ErrCode AdvancedNotificationService::CancelAllReminders() { ANSR_LOGI("Cancel all reminders"); + ReminderDataManager::GetInstance()->SetService(this); sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -1772,6 +1771,7 @@ ErrCode AdvancedNotificationService::CancelAllReminders() ErrCode AdvancedNotificationService::GetValidReminders(std::vector> &reminders) { ANSR_LOGI("GetValidReminders"); + ReminderDataManager::GetInstance()->SetService(this); reminders.clear(); sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { @@ -2407,18 +2407,15 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDate(const sptr &date) { - ANS_LOGD("%{public}s enter, userId = %{public}d", __FUNCTION__, userId); if (date == nullptr) { - ANS_LOGE("Invalid date param"); return ERR_ANS_INVALID_PARAM; } @@ -3132,6 +3127,7 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDateByUser(const int32_t &us int64_t beginDate = ResetSeconds(date->GetBeginDate()); int64_t endDate = ResetSeconds(date->GetEndDate()); + switch (date->GetDoNotDisturbType()) { case NotificationConstant::DoNotDisturbType::NONE: beginDate = 0; @@ -3148,7 +3144,7 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDateByUser(const int32_t &us default: break; } - ANS_LOGD("Before set SetDoNotDisturbDate beginDate = %{public}lld, endDate = %{public}lld", beginDate, endDate); + const sptr newConfig = new NotificationDoNotDisturbDate( date->GetDoNotDisturbType(), beginDate, @@ -3157,7 +3153,6 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDateByUser(const int32_t &us sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { - ANS_LOGE("Generate invalid bundle option!"); return ERR_ANS_INVALID_BUNDLE; } diff --git a/services/ans/src/advanced_notification_service_ability.cpp b/services/ans/src/advanced_notification_service_ability.cpp index 2fb8f0911..56f052fb8 100644 --- a/services/ans/src/advanced_notification_service_ability.cpp +++ b/services/ans/src/advanced_notification_service_ability.cpp @@ -38,13 +38,11 @@ void AdvancedNotificationServiceAbility::OnStart() if (!Publish(service_)) { return; } - reminderAgent_ = ReminderDataManager::InitInstance(service_); } void AdvancedNotificationServiceAbility::OnStop() { service_ = nullptr; - reminderAgent_ = nullptr; } } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index a0613efa3..fa62778b2 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -567,7 +567,6 @@ ErrCode NotificationPreferences::GetDoNotDisturbDate(const int32_t &userId, ErrCode NotificationPreferences::SetDoNotDisturbDate(const int32_t &userId, const sptr date) { - ANS_LOGE("enter."); if (userId <= SUBSCRIBE_USER_INIT) { return ERR_ANS_INVALID_PARAM; } diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index dd8493b03..85c9643aa 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -442,7 +442,7 @@ bool NotificationPreferencesDatabase::PutDoNotDisturbDate( } void NotificationPreferencesDatabase::GetValueFromDisturbeDB( - const std::string &key, std::function callback) + const std::string &key, std::function funcion) { if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); @@ -454,19 +454,19 @@ void NotificationPreferencesDatabase::GetValueFromDisturbeDB( DistributedKv::Key getKey(key); status = kvStorePtr_->Get(getKey, value); if (status != DistributedKv::Status::SUCCESS) { - ANS_LOGE("Get value failed, use default value. error code is %{public}d", status); + ANS_LOGE("Get value failed, use defalut value. error code is %{public}d", status); return; } if (value.Empty()) { - ANS_LOGE("Get value is empty, use default value. error code is %{public}d", value.Empty()); + ANS_LOGE("Get value is empty, use defalut value. error code is %{public}d", value.Empty()); return; } - callback(value); + funcion(value); } void NotificationPreferencesDatabase::GetValueFromDisturbeDB( - const std::string &key, std::function callback) + const std::string &key, std::function funcion) { if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); @@ -477,7 +477,7 @@ void NotificationPreferencesDatabase::GetValueFromDisturbeDB( DistributedKv::Value value; DistributedKv::Key getKey(key); status = kvStorePtr_->Get(getKey, value); - callback(status, value); + funcion(status, value); } bool NotificationPreferencesDatabase::CheckBundle(const std::string &bundleName, const int &bundleUid) @@ -1362,7 +1362,7 @@ void NotificationPreferencesDatabase::GetDoNotDisturbType(NotificationPreference } } } else { - ANS_LOGW("Parse disturbe mode failed, use default value."); + ANS_LOGW("Parse disturbe mode failed, use defalut value."); } info.SetDoNotDisturbDate(userId, disturbDate); }); @@ -1386,7 +1386,7 @@ void NotificationPreferencesDatabase::GetDoNotDisturbBeginDate(NotificationPrefe } } } else { - ANS_LOGW("Parse disturbe start time failed, use default value."); + ANS_LOGW("Parse disturbe start time failed, use defalut value."); } info.SetDoNotDisturbDate(userId, disturbDate); }); @@ -1410,7 +1410,7 @@ void NotificationPreferencesDatabase::GetDoNotDisturbEndDate(NotificationPrefere } } } else { - ANS_LOGW("Parse disturbe end time failed, use default value."); + ANS_LOGW("Parse disturbe end time failed, use defalut value."); } info.SetDoNotDisturbDate(userId, disturbDate); }); @@ -1434,7 +1434,7 @@ void NotificationPreferencesDatabase::GetEnableAllNotification(NotificationPrefe info.SetEnabledAllNotification(userId, static_cast(StringToInt(value.ToString()))); } } else { - ANS_LOGW("Parse enable all notification failed, use default value."); + ANS_LOGW("Parse enable all notification failed, use defalut value."); } }); } diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 6d8e53d3b..2ef4b6746 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 95fed2d13..80a7bc7d5 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -306,9 +306,8 @@ void NotificationSubscriberManager::NotifyConsumedInner( int32_t recvUserId = notification->GetNotificationRequest().GetReceiverUserId(); int32_t sendUserId = notification->GetUserId(); for (auto record : subscriberRecordList_) { + ANS_LOGD("%{public}s record->userId = <%{public}d>", __FUNCTION__, record->userId); auto BundleNames = notification->GetBundleName(); - ANS_LOGD("%{public}s record->userId = <%{public}d> BundleName = <%{public}s", - __FUNCTION__, record->userId, BundleNames.c_str()); auto iter = std::find(record->bundleList_.begin(), record->bundleList_.end(), BundleNames); if (!record->subscribedAll == (iter != record->bundleList_.end()) && ((record->userId == sendUserId) || @@ -360,7 +359,11 @@ void NotificationSubscriberManager::NotifyDoNotDisturbDateChangedInner(const spt bool NotificationSubscriberManager::IsSystemUser(int32_t userId) { - return ((userId >= SUBSCRIBE_USER_SYSTEM_BEGIN) && (userId <= SUBSCRIBE_USER_SYSTEM_END)); + if (userId >= SUBSCRIBE_USER_SYSTEM_BEGIN && userId <= SUBSCRIBE_USER_SYSTEM_END) { + return true; + } + + return false; } void NotificationSubscriberManager::NotifyEnabledNotificationChangedInner( diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 0b3f2ee69..cb3428bad 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -150,7 +150,6 @@ void ReminderDataManager::CancelAllReminders(const sptrDelete(reminderId); continue; } ++vit; @@ -192,15 +191,6 @@ void ReminderDataManager::AddToShowedReminders(const sptr &remi showedReminderVector_.push_back(reminder); } -void ReminderDataManager::OnServiceStart() -{ - std::vector> immediatelyShowReminders; - GetImmediatelyShowRemindersLocked(immediatelyShowReminders); - ANSR_LOGD("immediatelyShowReminders size=%{public}d", immediatelyShowReminders.size()); - HandleImmediatelyShow(immediatelyShowReminders, false); - StartRecentReminder(); -} - void ReminderDataManager::OnProcessDiedLocked(const sptr bundleOption) { std::string bundleName = bundleOption->GetBundleName(); @@ -230,7 +220,6 @@ void ReminderDataManager::OnProcessDiedLocked(const sptrUpdateOrInsert((*it), bundleOption); } } @@ -364,23 +353,15 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b } reminder->OnClose(true); RemoveFromShowedReminders(reminder); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); if (cancelNotification) { CancelNotification(reminder); } } std::shared_ptr ReminderDataManager::GetInstance() -{ - return REMINDER_DATA_MANAGER; -} - -std::shared_ptr ReminderDataManager::InitInstance( - sptr &advancedNotificationService) { if (REMINDER_DATA_MANAGER == nullptr) { REMINDER_DATA_MANAGER = std::make_shared(); - REMINDER_DATA_MANAGER->advancedNotificationService_ = advancedNotificationService; ReminderEventManager reminderEventManager(REMINDER_DATA_MANAGER); } return REMINDER_DATA_MANAGER; @@ -443,7 +424,6 @@ void ReminderDataManager::TerminateAlerting(const sptr &reminde ANSR_LOGD("publish(update) notification.(reminderId=%{public}d)", reminder->GetReminderId()); UpdateNotification(reminder); advancedNotificationService_->PublishPreparedNotification(notificationRequest, bundleOption); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); } void ReminderDataManager::UpdateAndSaveReminderLocked( @@ -452,7 +432,6 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( std::lock_guard lock(ReminderDataManager::MUTEX); reminder->InitReminderId(); reminder->InitUserId(ReminderRequest::GetUserId(bundleOption->GetUid())); - reminder->InitUid(bundleOption->GetUid()); int32_t reminderId = reminder->GetReminderId(); ANSR_LOGD("Containers(map) add. reminderId=%{public}d", reminderId); auto ret = notificationBundleOptionMap_.insert( @@ -464,7 +443,6 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( ANSR_LOGD("Containers(vector) add. reminderId=%{public}d", reminderId); reminderVector_.push_back(reminder); totalCount_++; - store_->UpdateOrInsert(reminder, bundleOption); } void ReminderDataManager::SetService(AdvancedNotificationService *advancedNotificationService) @@ -588,8 +566,6 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co } HandleSameNotificationIdShowing(reminder); } - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); - if (isNeedToStartNext) { StartRecentReminder(); } @@ -601,7 +577,6 @@ void ReminderDataManager::UpdateNotification(const sptr &remind reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::REMOVAL_WANT_AGENT, ""); reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::WANT_AGENT, ""); reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::MAX_SCREEN_WANT_AGENT, ""); - reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::BUNDLE_INFO, ""); } void ReminderDataManager::SnoozeReminder(const OHOS::EventFwk::Want &want) @@ -631,7 +606,6 @@ void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) StopTimerLocked(TimerType::ALERTING_TIMER); } reminder->OnSnooze(); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); // 2) Show the notification dialog in the systemUI sptr bundleOption = FindNotificationBundleOption(reminderId); @@ -662,13 +636,12 @@ void ReminderDataManager::StartRecentReminder() } if (activeReminderId_ != -1) { activeReminder_->OnStop(); - store_->UpdateOrInsert(activeReminder_, FindNotificationBundleOption(activeReminderId_)); StopTimerLocked(TimerType::TRIGGER_TIMER); } ANSR_LOGI("Start recent reminder"); StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); reminder->OnStart(); - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + SetActiveReminder(reminder); } void ReminderDataManager::StopAlertingReminder(const sptr &reminder) @@ -768,7 +741,6 @@ sptr ReminderDataManager::GetRecentReminderLocked() } it = reminderVector_.erase(it); totalCount_--; - store_->Delete(reminderId); } return nullptr; } @@ -821,10 +793,8 @@ sptr ReminderDataManager::HandleRefreshReminder(uint8_t &type, if (triggerTimeBefore != triggerTimeAfter || reminder->GetReminderId() == alertingReminderId_) { CloseReminder(reminder, true); } - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); return nullptr; } - store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); return reminder; } @@ -854,48 +824,10 @@ void ReminderDataManager::HandleSameNotificationIdShowing(const sptrOnSameNotificationIdCovered(); RemoveFromShowedReminders(*it); - store_->UpdateOrInsert((*it), FindNotificationBundleOption((*it)->GetReminderId())); - } - } -} - -void ReminderDataManager::Init(bool isFromBootComplete) -{ - ANSR_LOGD("ReminderDataManager Init, isFromBootComplete:%{public}d", isFromBootComplete); - if (IsReminderAgentReady()) { - return; - } - if (store_ == nullptr) { - store_ = std::make_shared(); - } - if (store_->Init() != ReminderStore::STATE_OK) { - ANSR_LOGW("Db init fail."); - return; - } - LoadReminderFromDb(); - isReminderAgentReady_ = true; - ANSR_LOGD("ReminderAgent is ready."); -} - -void ReminderDataManager::GetImmediatelyShowRemindersLocked(std::vector> &reminders) const -{ - std::lock_guard lock(ReminderDataManager::MUTEX); - for (auto reminderSptr : reminderVector_) { - if (!(reminderSptr->ShouldShowImmediately())) { - break; - } - if (reminderSptr->GetReminderType() != ReminderRequest::ReminderType::TIMER) { - reminderSptr->SetSnoozeTimesDynamic(0); } - reminders.push_back(reminderSptr); } } -bool ReminderDataManager::IsReminderAgentReady() const -{ - return isReminderAgentReady_; -} - bool ReminderDataManager::IsBelongToSameApp( const sptr reminder, const std::string otherPkgName, const int otherUserId) { @@ -912,33 +844,9 @@ bool ReminderDataManager::IsBelongToSameApp( return false; } -void ReminderDataManager::LoadReminderFromDb() -{ - std::lock_guard lock(ReminderDataManager::MUTEX); - std::vector> existReminders = store_->GetAllValidReminders(); - reminderVector_ = existReminders; - ANSR_LOGD("LoadReminderFromDb, reminder size=%{public}d", reminderVector_.size()); - for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { - sptr bundleOption = new NotificationBundleOption(); - int32_t reminderId = (*it)->GetReminderId(); - if (!(store_->GetBundleOption(reminderId, bundleOption))) { - ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); - continue; - } - auto ret = notificationBundleOptionMap_.insert( - std::pair>(reminderId, bundleOption)); - if (!ret.second) { - ANSR_LOGE("Containers add to map error"); - continue; - } - } - totalCount_ = reminderVector_.size(); - ReminderRequest::GLOBAL_ID = store_->GetMaxId() + 1; -} - void ReminderDataManager::PlaySoundAndVibrationLocked(const sptr &reminder) { - std::lock_guard lock(ReminderDataManager::ALERT_MUTEX); + std::lock_guard lock(ReminderDataManager::ALERT_MUTEX); // todo check died lock PlaySoundAndVibration(reminder); } @@ -1041,7 +949,6 @@ void ReminderDataManager::RemoveReminderLocked(const int32_t &reminderId) ANSR_LOGD("Containers(vector) remove. reminderId=%{public}d", reminderId); it = reminderVector_.erase(it); totalCount_--; - store_->Delete(reminderId); break; } else { ++it; diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index 759099394..c4270e932 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -21,10 +21,8 @@ #include "bundle_mgr_interface.h" #include "common_event_manager.h" #include "common_event_support.h" -#include "if_system_ability_manager.h" #include "ipc_skeleton.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" + using namespace OHOS::EventFwk; namespace OHOS { @@ -41,7 +39,6 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT); - matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); @@ -57,18 +54,6 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa ANSR_LOGD("SubscribeCommonEvent fail"); } IPCSkeleton::SetCallingIdentity(identity); - - sptr statusChangeListener - = new SystemAbilityStatusChangeListener(reminderDataManager); - sptr samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgrProxy == nullptr) { - ANSR_LOGD("samgrProxy is null"); - return; - } - int32_t ret = samgrProxy->SubscribeSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, statusChangeListener); - if (ret != ERR_OK) { - ANSR_LOGE("subscribe system ability id: %{public}d failed", BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - } } ReminderEventManager::ReminderEventSubscriber::ReminderEventSubscriber( @@ -103,10 +88,6 @@ void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFw reminderDataManager_->CloseReminder(want, false); return; } - if (action == CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED) { - reminderDataManager_->Init(true); - return; - } if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { HandlePackageRemove(want); return; @@ -166,24 +147,5 @@ sptr ReminderEventManager::ReminderEventSubscriber::Ge } return bundleOption; } - -ReminderEventManager::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener( - std::shared_ptr &reminderDataManager) -{ - reminderDataManager_ = reminderDataManager; -} - -void ReminderEventManager::SystemAbilityStatusChangeListener::OnAddSystemAbility( - int32_t systemAbilityId, const std::string& deviceId) -{ - ANSR_LOGD("OnAddSystemAbilityInner"); - reminderDataManager_->OnServiceStart(); -} - -void ReminderEventManager::SystemAbilityStatusChangeListener::OnRemoveSystemAbility( - int32_t systemAbilityId, const std::string& deviceId) -{ - ANSR_LOGD("OnRemoveSystemAbilityInner"); -} } // namespace OHOS } // namespace Notification diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 9be0e2f5f..86cb09652 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -76,7 +76,6 @@ ohos_unittest("ans_unit_test") { external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:wantagent_innerkits", @@ -85,6 +84,7 @@ ohos_unittest("ans_unit_test") { "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", + "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index 86107793a..337764a8b 100644 --- a/services/distributed/BUILD.gn +++ b/services/distributed/BUILD.gn @@ -46,8 +46,8 @@ ohos_shared_library("libans_distributed") { external_deps = [ "ability_base:want", - "ability_base:zuri", "distributeddatamgr:distributeddata_inner", + "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index 0f1d53cc6..df3f579e2 100644 --- a/services/distributed/test/unittest/BUILD.gn +++ b/services/distributed/test/unittest/BUILD.gn @@ -69,9 +69,9 @@ ohos_unittest("ans_distributed_unit_test") { external_deps = [ "ability_base:base", "ability_base:want", - "ability_base:zuri", "bundle_framework:appexecfwk_base", "distributeddatamgr:distributeddata_inner", + "dmsfwk_standard:zuri", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/distributed/test/unittest/distributed_database_test.cpp b/services/distributed/test/unittest/distributed_database_test.cpp index 329297a73..0e2a4ac80 100644 --- a/services/distributed/test/unittest/distributed_database_test.cpp +++ b/services/distributed/test/unittest/distributed_database_test.cpp @@ -169,7 +169,7 @@ HWTEST_F(DistributedDatabaseTest, GetLocalDeviceId_00100, Function | SmallTest | /** * @tc.name : DistributedDatabase_GetLocalDeviceInfo_00100 * @tc.number : GetLocalDeviceInfo_00100 - * @tc.desc : Get local device information. + * @tc.desc : Get local device infomation. */ HWTEST_F(DistributedDatabaseTest, GetLocalDeviceInfo_00100, Function | SmallTest | Level1) { diff --git a/services/distributed/test/unittest/distributed_notification_manager_test.cpp b/services/distributed/test/unittest/distributed_notification_manager_test.cpp index e4ab49cf0..c6cac5a4c 100644 --- a/services/distributed/test/unittest/distributed_notification_manager_test.cpp +++ b/services/distributed/test/unittest/distributed_notification_manager_test.cpp @@ -173,7 +173,7 @@ HWTEST_F(DistributedNotificationManagerTest, Distributed_Get_Current_Notificatio /** * @tc.name : Distributed_Get_Local_DeviceInfo_00100 * @tc.number : Distributed_Get_Local_DeviceInfo_00100 - * @tc.desc : Get local distributed device information. + * @tc.desc : Get local distributed device infomation. */ HWTEST_F(DistributedNotificationManagerTest, Distributed_Get_Local_DeviceInfo_00100, Function | SmallTest | Level1) { diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 653df974a..a6b03d311 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -30,6 +30,7 @@ ohos_moduletest("ans_module_test") { sources = [ "${services_path}/ans/src/advanced_notification_service.cpp", "${services_path}/ans/src/advanced_notification_service_ability.cpp", + "${services_path}/ans/src/bundle_manager_helper.cpp", "${services_path}/ans/src/notification_preferences.cpp", "${services_path}/ans/src/notification_preferences_database.cpp", "${services_path}/ans/src/notification_preferences_info.cpp", @@ -44,7 +45,6 @@ ohos_moduletest("ans_module_test") { "mock/blob.cpp", "mock/distributed_kv_data_manager.cpp", "mock/mock_bundle_manager.cpp", - "mock/mock_bundle_manager_helper.cpp", "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_event_handler.cpp", "mock/mock_ipc.cpp", @@ -62,7 +62,6 @@ ohos_moduletest("ans_module_test") { external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:wantagent_innerkits", @@ -71,6 +70,7 @@ ohos_moduletest("ans_module_test") { "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", + "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", diff --git a/services/test/moduletest/ans_module_test.cpp b/services/test/moduletest/ans_module_test.cpp index ddd6a066c..9ca7b24f5 100644 --- a/services/test/moduletest/ans_module_test.cpp +++ b/services/test/moduletest/ans_module_test.cpp @@ -2620,7 +2620,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0132, Function | SmallTest | Level1) sptr date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); - EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(date), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK); @@ -2662,7 +2662,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0133, Function | SmallTest | Level1) int64_t endDate = endDuration.count(); sptr date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); - EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(date), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK); @@ -2704,7 +2704,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0134, Function | SmallTest | Level1) int64_t endDate = endDuration.count(); sptr date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate); - EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(date), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK); @@ -2746,7 +2746,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0135, Function | SmallTest | Level1) int64_t endDate = endDuration.count(); sptr date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate); - EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(date), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK); diff --git a/services/test/moduletest/mock/include/mock_single_kv_store.h b/services/test/moduletest/mock/include/mock_single_kv_store.h index bea39c9cf..b682e4315 100644 --- a/services/test/moduletest/mock/include/mock_single_kv_store.h +++ b/services/test/moduletest/mock/include/mock_single_kv_store.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/test/moduletest/mock/mock_bundle_manager_helper.cpp b/services/test/moduletest/mock/mock_bundle_manager_helper.cpp index fdeac6723..70406de1d 100644 --- a/services/test/moduletest/mock/mock_bundle_manager_helper.cpp +++ b/services/test/moduletest/mock/mock_bundle_manager_helper.cpp @@ -40,17 +40,6 @@ bool BundleManagerHelper::IsSystemApp(int uid) return true; } -int BundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId) -{ - return 1000; -} - -bool BundleManagerHelper::GetBundleInfoByBundleName( - const std::string bundle, const int32_t userId, AppExecFwk::BundleInfo &bundleInfo) -{ - return true; -} - void BundleManagerHelper::Connect() {} diff --git a/test/common/acts/BUILD.gn b/test/common/acts/BUILD.gn index efd738228..190963cd3 100644 --- a/test/common/acts/BUILD.gn +++ b/test/common/acts/BUILD.gn @@ -23,6 +23,7 @@ config("ansfwk_kits_test_config") { "//foundation/appexecfwk/standard/services/bundlemgr/include", "//utils/system/safwk/native/include", "${services_path}/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "//foundation/distributedschedule/safwk/services/safwk/include", ] } diff --git a/test/common/acts/actsnotificationfuzztest/BUILD.gn b/test/common/acts/actsnotificationfuzztest/BUILD.gn index 7fd68617a..02432ad5b 100644 --- a/test/common/acts/actsnotificationfuzztest/BUILD.gn +++ b/test/common/acts/actsnotificationfuzztest/BUILD.gn @@ -80,6 +80,7 @@ ohos_systemtest("ActsNotificationFuzzTest") { "ability_runtime:abilitykit_native", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", + "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/test/resource/ansSTSlotGroupTest/BUILD.gn b/test/resource/ansSTSlotGroupTest/BUILD.gn index 677bcea62..df98efbd1 100644 --- a/test/resource/ansSTSlotGroupTest/BUILD.gn +++ b/test/resource/ansSTSlotGroupTest/BUILD.gn @@ -30,6 +30,7 @@ config("ansSTSlotGroupTestConfig") { "//foundation/appexecfwk/standard/services/bundlemgr/include", "//foundation/aafwk/standard/services/abilitymgr/include", "//foundation/appexecfwk/standard/common/log/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "${interfaces_path}/innerkits/ans/native/include", ] diff --git a/tools/dump/BUILD.gn b/tools/dump/BUILD.gn index 0d583b0bd..e89422237 100644 --- a/tools/dump/BUILD.gn +++ b/tools/dump/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -50,7 +50,6 @@ ohos_executable("anm") { external_deps = [ "hiviewdfx_hilog_native:libhilog", "multimedia_image_standard:image_native", - "native_appdatamgr:native_rdb", ] external_deps += ans_standard_external_deps -- Gitee