diff --git a/OAT.xml b/OAT.xml
index aa01ceabe357535c840cb743727fb16106185a8e..78d6121297f7b5a729a2ab4ad3ee2a1e44b7aa81 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -1,5 +1,5 @@
-
+
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 928dc3b8b789e0fdcf0c8a6239d2dfde8a806ec1..202cc62bc070331ffd60566432dc5122f600cc6b 100644
--- a/frameworks/ans/dialog/dialog_ui/js/pages/index/index.js
+++ b/frameworks/ans/dialog/dialog_ui/js/pages/index/index.js
@@ -1,3 +1,18 @@
+/*
+ * 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 a0aa9d6ccf3c7a5039278afb806ca60395040791..7bdd6531526aa9ac6b1842b72f7da87992383378 100644
--- a/frameworks/ans/native/BUILD.gn
+++ b/frameworks/ans/native/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2021 Huawei Device Co., Ltd.
+# 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
@@ -85,11 +85,12 @@ 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 613c42646030dd35bc5e0fceaaac6a6e29f23e53..0773681bda983ca3e0bc266db9e911016c0a71be 100644
--- a/frameworks/ans/native/src/notification.cpp
+++ b/frameworks/ans/native/src/notification.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -246,7 +246,7 @@ bool Notification::MarshallingBool(Parcel &parcel) const
bool Notification::MarshallingString(Parcel &parcel) const
{
if (!parcel.WriteString(key_)) {
- ANS_LOGE("Can't wirte key");
+ ANS_LOGE("Can't write key");
return false;
}
@@ -258,7 +258,7 @@ bool Notification::MarshallingString(Parcel &parcel) const
}
if (!parcel.WriteString(deviceId_)) {
- ANS_LOGE("Can't wirte deviceId");
+ ANS_LOGE("Can't write deviceId");
return false;
}
diff --git a/frameworks/ans/native/src/notification_action_button.cpp b/frameworks/ans/native/src/notification_action_button.cpp
index cc3ba9f0c52089569b25aeb4d137b040fba6ded2..c638c0703bbd38caa4bf6b6aef10e697b9ac4e20 100644
--- a/frameworks/ans/native/src/notification_action_button.cpp
+++ b/frameworks/ans/native/src/notification_action_button.cpp
@@ -26,7 +26,7 @@ std::shared_ptr NotificationActionButton::Create(const
const std::string &title, const std::shared_ptr &wantAgent,
const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton,
bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs,
- const std::vector> &userInputs, bool isContextual)
+ const std::shared_ptr &userInput, bool isContextual)
{
if (isContextual && (!icon || !wantAgent)) {
ANS_LOGE("icon or wantAgent can not be null when isContextual is true");
@@ -42,18 +42,10 @@ std::shared_ptr NotificationActionButton::Create(const
}
}
+ std::shared_ptr textInput = userInput;
std::vector> onlyInputs = mimeTypeOnlyInputs;
- std::vector> textInputs {};
- for (auto &userInput : userInputs) {
- if (!userInput) {
- continue;
- }
-
- if (userInput->IsMimeTypeOnly()) {
- onlyInputs.push_back(userInput);
- } else {
- textInputs.push_back(userInput);
- }
+ if (userInput && (userInput->IsMimeTypeOnly())) {
+ onlyInputs.push_back(userInput);
}
auto pActionButton = new (std::nothrow) NotificationActionButton(icon,
@@ -63,7 +55,7 @@ std::shared_ptr NotificationActionButton::Create(const
semanticActionButton,
autoCreatedReplies,
onlyInputs,
- textInputs,
+ textInput,
isContextual);
if (pActionButton == nullptr) {
ANS_LOGE("create NotificationActionButton object failed");
@@ -88,7 +80,7 @@ std::shared_ptr NotificationActionButton::Create(
actionButton->GetSemanticActionButton(),
actionButton->IsAutoCreatedReplies(),
actionButton->GetMimeTypeOnlyUserInputs(),
- actionButton->GetUserInputs(),
+ actionButton->GetUserInput(),
actionButton->IsContextDependent());
}
@@ -96,7 +88,7 @@ NotificationActionButton::NotificationActionButton(const std::shared_ptr &wantAgent,
const std::shared_ptr &extras, NotificationConstant::SemanticActionButton semanticActionButton,
bool autoCreatedReplies, const std::vector> &mimeTypeOnlyInputs,
- const std::vector> &userInputs, bool isContextual)
+ const std::shared_ptr &userInput, bool isContextual)
: icon_(icon),
title_(title),
wantAgent_(wantAgent),
@@ -104,7 +96,7 @@ NotificationActionButton::NotificationActionButton(const std::shared_ptr> NotificationActionButton::Ge
void NotificationActionButton::AddNotificationUserInput(const std::shared_ptr &userInput)
{
- if (!userInput) {
- ANS_LOGE("The userInput is invalid.");
- return;
- }
-
- userInputs_.emplace_back(userInput);
+ userInput_ = userInput;
}
-std::vector> NotificationActionButton::GetUserInputs() const
+const std::shared_ptr NotificationActionButton::GetUserInput() const
{
- return userInputs_;
+ return userInput_;
}
void NotificationActionButton::SetAutoCreatedReplies(bool autoCreatedReplies)
@@ -212,14 +199,12 @@ std::string NotificationActionButton::Dump()
mimeTypeOnlyUserInputs += ", ";
}
- std::string userInputs = "";
- for (auto &item : userInputs_) {
- if (!item) {
- userInputs += "nullptr, ";
- continue;
- }
- userInputs += item->Dump();
- userInputs += ", ";
+ std::string userInput = "";
+ if (userInput_ == nullptr) {
+ userInput += "nullptr, ";
+ } else {
+ userInput += userInput_->Dump();
+ userInput += ", ";
}
return "NotificationActionButton{ "
@@ -228,7 +213,7 @@ std::string NotificationActionButton::Dump()
", autoCreatedReplies = " + (autoCreatedReplies_ ? "true" : "false") +
", isContextual = " + (isContextual_ ? "true" : "false") +
", mimeTypeOnlyUserInputs = [" + mimeTypeOnlyUserInputs + "]" +
- ", userInputs = [" + userInputs + "]" +
+ ", userInputs = [" + userInput + "]" +
" }";
}
@@ -350,24 +335,17 @@ bool NotificationActionButton::Marshalling(Parcel &parcel) const
}
}
- if (!parcel.WriteInt32(static_cast(userInputs_.size()))) {
- ANS_LOGE("Failed to write the size of userInputs");
+ valid = userInput_ ? true : false;
+ if (!parcel.WriteBool(valid)) {
+ ANS_LOGE("Failed to write the flag which indicate whether userInput is null");
return false;
}
- for (auto it = userInputs_.begin(); it != userInputs_.end(); ++it) {
- valid = (*it) ? true : false;
- if (!parcel.WriteBool(valid)) {
- ANS_LOGE("Failed to write the flag which indicate whether userInput is null");
+ if (valid) {
+ if (!parcel.WriteParcelable(userInput_.get())) {
+ ANS_LOGE("Failed to write userInput");
return false;
}
-
- if (valid) {
- if (!parcel.WriteParcelable(it->get())) {
- ANS_LOGE("Failed to write userInput");
- return false;
- }
- }
}
return true;
@@ -427,19 +405,13 @@ bool NotificationActionButton::ReadFromParcel(Parcel &parcel)
}
}
- auto vsize = parcel.ReadInt32();
- for (auto it = 0; it < vsize; ++it) {
- valid = parcel.ReadBool();
- NotificationUserInput *member {nullptr};
- if (valid) {
- member = parcel.ReadParcelable();
- if (member == nullptr) {
- ANS_LOGE("Failed to read userInput");
- return false;
- }
+ valid = parcel.ReadBool();
+ if (valid) {
+ userInput_ = std::shared_ptr(parcel.ReadParcelable());
+ if (!userInput_) {
+ ANS_LOGE("Failed to read userInput");
+ return false;
}
-
- userInputs_.emplace_back(member);
}
return true;
diff --git a/frameworks/ans/native/src/notification_sorting_map.cpp b/frameworks/ans/native/src/notification_sorting_map.cpp
index 2bd73d2f504f4b270616547b4da9d50490ba497a..9e87b4e635d4ff3cb3e0e85d582cb7772d5a3b5c 100644
--- a/frameworks/ans/native/src/notification_sorting_map.cpp
+++ b/frameworks/ans/native/src/notification_sorting_map.cpp
@@ -68,12 +68,19 @@ bool NotificationSortingMap::Marshalling(Parcel &parcel) const
ANS_LOGE("Can't write sorting size");
return false;
}
- for_each(sortings_.begin(), sortings_.end(), [&](std::pair sorting) {
+
+ int count = 0;
+ for (auto &sorting : sortings_) {
if (!parcel.WriteParcelable(&sorting.second)) {
ANS_LOGE("Can't write sorting");
ret = false;
}
- });
+ count++;
+
+ if (count == MAX_ACTIVE_NUM) {
+ break;
+ }
+ }
return ret;
}
@@ -84,6 +91,7 @@ NotificationSortingMap *NotificationSortingMap::Unmarshalling(Parcel &parcel)
// read sorting num
int32_t size = 0;
parcel.ReadInt32(size);
+ size = (size <= MAX_ACTIVE_NUM) ? size : MAX_ACTIVE_NUM;
for (int i = 0; i < size; i++) {
// read sorting
diff --git a/frameworks/ans/native/src/notification_subscriber.cpp b/frameworks/ans/native/src/notification_subscriber.cpp
index e3a9a3c334858baa5391f370ed84d6b87a2a8676..a0865fa929e0d5f474c1841d52efe204f2fe7852 100644
--- a/frameworks/ans/native/src/notification_subscriber.cpp
+++ b/frameworks/ans/native/src/notification_subscriber.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -99,9 +99,9 @@ void NotificationSubscriber::SubscriberImpl::OnEnabledNotificationChanged(
bool NotificationSubscriber::SubscriberImpl::GetAnsManagerProxy()
{
- if (nullptr == proxy_) {
+ if (proxy_ == nullptr) {
std::lock_guard lock(mutex_);
- if (nullptr == proxy_) {
+ if (proxy_ == nullptr) {
sptr systemAbilityManager =
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!systemAbilityManager) {
diff --git a/frameworks/ans/native/src/notification_user_input.cpp b/frameworks/ans/native/src/notification_user_input.cpp
index 337eeb50cdd3e8f5d4c2cf6057604474984a85ca..dfd11abb96cc01e8179612b7ef5cacdf12ae485a 100644
--- a/frameworks/ans/native/src/notification_user_input.cpp
+++ b/frameworks/ans/native/src/notification_user_input.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -248,7 +248,7 @@ bool NotificationUserInput::ToJson(nlohmann::json &jsonObject) const
NotificationUserInput *NotificationUserInput::FromJson(const nlohmann::json &jsonObject)
{
- if (jsonObject.is_null() or !jsonObject.is_object()) {
+ if (jsonObject.is_null() || !jsonObject.is_object()) {
ANS_LOGE("Invalid JSON object");
return nullptr;
}
diff --git a/frameworks/ans/native/src/reminder_helper.cpp b/frameworks/ans/native/src/reminder_helper.cpp
index 5e518b7714e744a67d37dcf9a3c7414c6dff13d8..524d479dcf6be3889181f0fa0cc5ca4f6842aa4f 100644
--- a/frameworks/ans/native/src/reminder_helper.cpp
+++ b/frameworks/ans/native/src/reminder_helper.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -13,13 +13,13 @@
* limitations under the License.
*/
+#include "reminder_helper.h"
+
#include "ans_log_wrapper.h"
#include "ans_notification.h"
#include "notification_helper.h"
#include "singleton.h"
-#include "reminder_helper.h"
-
namespace OHOS {
namespace Notification {
ErrCode ReminderHelper::PublishReminder(ReminderRequest &reminder)
diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp
index 8c71b7f82560abea9e70fe49f1820d167f11aa48..381d0bb5db61d5808adde21dbfa8374ef2aba3a9 100644
--- a/frameworks/ans/native/src/reminder_request.cpp
+++ b/frameworks/ans/native/src/reminder_request.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -13,18 +13,24 @@
* limitations under the License.
*/
+#include "reminder_request.h"
+
#include "ans_log_wrapper.h"
#include "bundle_mgr_interface.h"
#include "if_system_ability_manager.h"
+#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"
-#include "reminder_request.h"
-
namespace OHOS {
namespace Notification {
+namespace {
+const int BASE_YEAR = 1900;
+}
+
int32_t ReminderRequest::GLOBAL_ID = 0;
const uint64_t ReminderRequest::INVALID_LONG_LONG_VALUE = 0;
const uint16_t ReminderRequest::INVALID_U16_VALUE = 0;
@@ -45,13 +51,45 @@ const std::string ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT = "ohos.event.no
const std::string ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION =
"ohos.event.notification.reminder.REMOVE_NOTIFICATION";
const std::string ReminderRequest::PARAM_REMINDER_ID = "REMINDER_ID";
-const int ReminderRequest::BASE_YEAR = 1900;
+const std::string ReminderRequest::SEP_BUTTON_SINGLE = "";
+const std::string ReminderRequest::SEP_BUTTON_MULTI = "";
+const std::string ReminderRequest::SEP_WANT_AGENT = "";
+
+// 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()
{
- wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_;
- maxScreenWantAgentInfo_ =
- maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_;
+ InitServerObj();
}
ReminderRequest::ReminderRequest(const ReminderRequest &other)
@@ -79,12 +117,16 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other)
this->actionButtonMap_ = other.actionButtonMap_;
}
+ReminderRequest::ReminderRequest(int32_t reminderId)
+{
+ reminderId_ = reminderId;
+ InitServerObj();
+}
+
ReminderRequest::ReminderRequest(ReminderType reminderType)
{
reminderType_ = reminderType;
- wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_;
- maxScreenWantAgentInfo_ =
- maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_;
+ InitServerObj();
}
bool ReminderRequest::CanRemove() const
@@ -124,7 +166,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;
@@ -169,6 +211,11 @@ void ReminderRequest::InitUserId(const int &userId)
userId_ = userId;
}
+void ReminderRequest::InitUid(const int32_t &uid)
+{
+ uid_ = uid;
+}
+
bool ReminderRequest::IsExpired() const
{
return isExpired_;
@@ -372,6 +419,192 @@ 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)
{
@@ -412,7 +645,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 {
@@ -511,7 +744,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 {
@@ -560,6 +793,16 @@ uint64_t ReminderRequest::GetTriggerTimeInMilli() const
return triggerTimeInMilli_;
}
+int ReminderRequest::GetUserId() const
+{
+ return userId_;
+}
+
+int32_t ReminderRequest::GetUid() const
+{
+ return uid_;
+}
+
std::shared_ptr ReminderRequest::GetWantAgentInfo() const
{
return wantAgentInfo_;
@@ -606,6 +849,11 @@ void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std
SetMaxScreenWantAgent(maxScreenWantAgent);
break;
}
+ case UpdateNotificationType::BUNDLE_INFO: {
+ ANSR_LOGI("UpdateNotification hap information");
+ UpdateNotificationBundleInfo();
+ break;
+ }
case UpdateNotificationType::CONTENT: {
break;
}
@@ -710,12 +958,12 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const
ANSR_LOGE("Failed to write action button size");
return false;
}
- for (auto it = actionButtonMap_.begin(); it != actionButtonMap_.end(); ++it) {
- if (!parcel.WriteUint8(static_cast(it->first))) {
+ for (auto button : actionButtonMap_) {
+ if (!parcel.WriteUint8(static_cast(button.first))) {
ANSR_LOGE("Failed to write action button type");
return false;
}
- if (!parcel.WriteString(static_cast(it->second.title))) {
+ if (!parcel.WriteString(static_cast(button.second.title))) {
ANSR_LOGE("Failed to write action button title");
return false;
}
@@ -725,12 +973,15 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const
ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel)
{
- auto objptr = new ReminderRequest();
- if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) {
+ auto objptr = new (std::nothrow) ReminderRequest();
+ if (objptr == nullptr) {
+ ANSR_LOGE("Failed to create reminder due to no memory.");
+ return objptr;
+ }
+ if (!objptr->ReadFromParcel(parcel)) {
delete objptr;
objptr = nullptr;
}
-
return objptr;
}
@@ -782,7 +1033,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");
@@ -870,6 +1121,13 @@ 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;
@@ -892,6 +1150,21 @@ std::string ReminderRequest::GetDateTimeInfo(const time_t &timeInSecond) const
return GetTimeInfoInner(timeInSecond, TimeFormat::YMDHMS);
}
+std::string ReminderRequest::GetButtonInfo() const
+{
+ std::string info = "";
+ bool isFirst = true;
+ for (auto 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;
@@ -907,15 +1180,13 @@ std::string ReminderRequest::GetShowTime(const uint64_t showTime) const
{
if (reminderType_ == ReminderType::TIMER) {
return "";
- } else {
- const time_t showTimeInSecond = static_cast(showTime / MILLI_SECONDS);
- return GetTimeInfoInner(showTimeInSecond, TimeFormat::HM);
}
+ return GetTimeInfoInner(static_cast(showTime / MILLI_SECONDS), TimeFormat::HM);
}
std::string ReminderRequest::GetTimeInfoInner(const time_t &timeInSecond, const TimeFormat &format) const
{
- uint8_t dateTimeLen = 80;
+ const uint8_t dateTimeLen = 80;
char dateTimeBuffer[dateTimeLen];
struct tm timeInfo;
(void)localtime_r(&timeInSecond, &timeInfo);
@@ -978,9 +1249,9 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze)
int requestCode = 10;
std::vector flags;
flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG);
- for (auto it = actionButtonMap_.begin(); it != actionButtonMap_.end(); ++it) {
+ for (auto button : actionButtonMap_) {
auto want = std::make_shared();
- auto type = it->first;
+ auto type = button.first;
if (type == ActionButtonType::CLOSE) {
want->SetAction(REMINDER_EVENT_CLOSE_ALERT);
ANSR_LOGD("Add action button, type is close");
@@ -997,7 +1268,7 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze)
want->SetParam(PARAM_REMINDER_ID, reminderId_);
std::vector> wants;
wants.push_back(want);
- auto title = static_cast(it->second.title);
+ auto title = static_cast(button.second.title);
AbilityRuntime::WantAgent::WantAgentInfo buttonWantAgentInfo(
requestCode,
AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT,
@@ -1005,8 +1276,12 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze)
wants,
nullptr
);
+
+ std::string identity = IPCSkeleton::ResetCallingIdentity();
std::shared_ptr buttonWantAgent =
AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo, userId_);
+ IPCSkeleton::SetCallingIdentity(identity);
+
std::shared_ptr actionButton
= NotificationActionButton::Create(nullptr, title, buttonWantAgent);
notificationRequest_->AddActionButton(actionButton);
@@ -1030,8 +1305,12 @@ void ReminderRequest::AddRemovalWantAgent()
wants,
nullptr
);
+
+ std::string identity = IPCSkeleton::ResetCallingIdentity();
std::shared_ptr wantAgent =
AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_);
+ IPCSkeleton::SetCallingIdentity(identity);
+
notificationRequest_->SetRemovalWantAgent(wantAgent);
}
@@ -1052,7 +1331,10 @@ std::shared_ptr ReminderRequest::CreateWan
wants,
nullptr
);
- return AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_);
+ std::string identity = IPCSkeleton::ResetCallingIdentity();
+ auto wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_);
+ IPCSkeleton::SetCallingIdentity(identity);
+ return wantAgent;
}
void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element)
@@ -1073,7 +1355,7 @@ void ReminderRequest::SetState(bool deSet, const uint8_t newState, std::string f
if (deSet) {
state_ |= newState;
} else {
- state_ &= ~newState;
+ state_ &= static_cast(~newState);
}
ANSR_LOGI("Switch the reminder(reminderId=%{public}d) state, from %{public}s to %{public}s, called by %{public}s",
reminderId_, GetState(oldState).c_str(), GetState(state_).c_str(), function.c_str());
@@ -1121,7 +1403,7 @@ void ReminderRequest::UpdateNotificationCommon()
{
time_t now;
(void)time(&now); // unit is seconds.
- notificationRequest_->SetDeliveryTime(static_cast(now) * MILLI_SECONDS);
+ notificationRequest_->SetDeliveryTime(GetDurationSinceEpochInMilli(now));
notificationRequest_->SetLabel(NOTIFICATION_LABEL);
notificationRequest_->SetShowDeliveryTime(true);
notificationRequest_->SetTapDismissed(true);
@@ -1131,8 +1413,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();
@@ -1141,6 +1423,25 @@ 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) {
@@ -1153,6 +1454,7 @@ void ReminderRequest::UpdateNotificationContent(const bool &setSnooze)
// snooze the reminder by manual
extendContent = GetShowTime(triggerTimeInMilli_) +
snoozeContent_ == "" ? "" : (" (" + snoozeContent_ + ")");
+ notificationRequest_->SetTapDismissed(false);
} else {
// the reminder is expired now, when timeInterval is 0
extendContent = GetShowTime(reminderTimeInMilli_) +
@@ -1247,5 +1549,94 @@ 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 f5a549729d310340397863571d3a25fe0fd3fc29..1bb778ea66742414abee0324b6e0bff14a37fffb 100644
--- a/frameworks/ans/native/src/reminder_request_alarm.cpp
+++ b/frameworks/ans/native/src/reminder_request_alarm.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -13,10 +13,11 @@
* limitations under the License.
*/
-#include "ans_log_wrapper.h"
-
#include "reminder_request_alarm.h"
+#include "ans_log_wrapper.h"
+#include "reminder_store.h"
+
namespace OHOS {
namespace Notification {
const uint8_t ReminderRequestAlarm::DAYS_PER_WEEK = 7;
@@ -28,6 +29,11 @@ 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)
{
@@ -49,7 +55,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)");
}
@@ -269,7 +275,11 @@ ReminderRequestAlarm *ReminderRequestAlarm::Unmarshalling(Parcel &parcel)
{
ANSR_LOGD("New alarm");
auto objptr = new (std::nothrow) ReminderRequestAlarm();
- if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) {
+ if (objptr == nullptr) {
+ ANSR_LOGE("Failed to create reminder alarm due to no memory.");
+ return objptr;
+ }
+ if (!objptr->ReadFromParcel(parcel)) {
delete objptr;
objptr = nullptr;
}
@@ -296,5 +306,46 @@ 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 0809af1294726c2a50f9e02e688d28fdf0fc4970..b2490eb647b877e2b2aae4770c266a71babd8f66 100644
--- a/frameworks/ans/native/src/reminder_request_calendar.cpp
+++ b/frameworks/ans/native/src/reminder_request_calendar.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * 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
@@ -13,10 +13,10 @@
* limitations under the License.
*/
-#include "ans_log_wrapper.h"
-
#include "reminder_request_calendar.h"
+#include "ans_log_wrapper.h"
+
namespace OHOS {
namespace Notification {
const uint8_t ReminderRequestCalendar::MAX_MONTHS_OF_YEAR = 12;
@@ -25,13 +25,25 @@ 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)
{
- // 1. record the infomation which designated by user at first time.
- firstDesignateYear_ = GetActualTime(TimeTransferType::YEAR, dateTime.tm_year);
- firstDesignateMonth_ = GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon);
+ // 1. record the information which designated by user at first time.
+ firstDesignateYear_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime.tm_year));
+ firstDesignateMonth_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon));
firstDesignateDay_ = dateTime.tm_mday;
SetRepeatMonths(repeatMonths);
SetRepeatDaysOfMonth(repeatDays);
@@ -39,8 +51,8 @@ ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime,
// 2. get the latest valid trigger time.
InitDateTime(dateTime);
- hour_ = dateTime_.tm_hour;
- minute_ = dateTime_.tm_min;
+ hour_ = static_cast(dateTime_.tm_hour);
+ minute_ = static_cast(dateTime_.tm_min);
uint64_t nextTriggerTime = INVALID_LONG_LONG_VALUE;
if ((nextTriggerTime = GetNextTriggerTime()) != INVALID_LONG_LONG_VALUE) {
time_t target = static_cast(nextTriggerTime / MILLI_SECONDS);
@@ -51,9 +63,9 @@ ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime,
"Not exist next trigger time, please check the param of ReminderRequestCalendar constructor.");
}
- // 2. set the time infomation (used to transfer to proxy service) which is decided to trigger firstly.
- year_ = GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year);
- month_ = GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon);
+ // 2. set the time information (used to transfer to proxy service) which is decided to trigger firstly.
+ year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year));
+ month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon));
day_ = dateTime_.tm_mday;
second_ = 0;
SetTriggerTimeInMilli(nextTriggerTime);
@@ -86,7 +98,7 @@ uint8_t ReminderRequestCalendar::GetDaysOfMonth(const uint16_t &year, const uint
uint8_t leapParam1 = 4;
uint8_t leapParam2 = 100;
if (month == february) {
- days = ((((0 == year % leapParam1) && (0 != year % leapParam2)) || (0 == year % solarYear))
+ days = ((((year % leapParam1 == 0) && (year % leapParam2 != 0)) || (year % solarYear == 0))
? leapMonth : nonLeapMonth);
} else {
days = daysArray[month - 1];
@@ -191,7 +203,7 @@ uint64_t ReminderRequestCalendar::GetNextTriggerTimeAsRepeatReminder(const tm &n
}
if ((triggerTimeInMilli = GetTimeInstantMilli(setYear, setMonth, setDay, hour_, minute_, second_))
!= INVALID_LONG_LONG_VALUE) {
- ANSR_LOGD("Next calendar time:%{public}u/%{public}u/%{public}u %{public}u:%{public}u:%{public}u",
+ ANSR_LOGD("Next calendar time:%{public}hu/%{public}hhu/%{public}hhu %{public}hhu:%{public}hhu:%{public}hhu",
setYear, setMonth, setDay, hour_, minute_, second_);
}
return triggerTimeInMilli;
@@ -284,7 +296,7 @@ void ReminderRequestCalendar::SetMonth(const uint8_t &month, const bool &isSet)
void ReminderRequestCalendar::SetRepeatMonths(const std::vector &repeatMonths)
{
if (repeatMonths.size() > MAX_MONTHS_OF_YEAR) {
- ANSR_LOGW("The length of repeat months array should not larger than %{public}u", MAX_MONTHS_OF_YEAR);
+ ANSR_LOGW("The length of repeat months array should not larger than %{public}hhu", MAX_MONTHS_OF_YEAR);
throw std::invalid_argument(
"The length of repeat months array should not larger than " + std::to_string(MAX_MONTHS_OF_YEAR));
}
@@ -297,7 +309,7 @@ void ReminderRequestCalendar::SetRepeatMonths(const std::vector &repeat
void ReminderRequestCalendar::SetRepeatDaysOfMonth(const std::vector &repeateDays)
{
if (repeateDays.size() > MAX_DAYS_OF_MONTH) {
- ANSR_LOGW("The length of repeat days array should not larger than %{public}u", MAX_DAYS_OF_MONTH);
+ ANSR_LOGW("The length of repeat days array should not larger than %{public}hhu", MAX_DAYS_OF_MONTH);
throw std::invalid_argument(
"The length of repeat days array should not larger than " + std::to_string(MAX_DAYS_OF_MONTH));
}
@@ -439,7 +451,11 @@ ReminderRequestCalendar *ReminderRequestCalendar::Unmarshalling(Parcel &parcel)
{
ANSR_LOGD("New calendar");
auto objptr = new ReminderRequestCalendar();
- if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) {
+ if (objptr == nullptr) {
+ ANS_LOGE("Failed to create reminder calendar due to no memory.");
+ return objptr;
+ }
+ if (!objptr->ReadFromParcel(parcel)) {
delete objptr;
objptr = nullptr;
}
@@ -498,5 +514,96 @@ 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_request_timer.cpp b/frameworks/ans/native/src/reminder_request_timer.cpp
index d0fd4337b2432cc0974cfcb9d5103ad071705014..cac42261980e32d4966be8ff836c2370982fb2a8 100644
--- a/frameworks/ans/native/src/reminder_request_timer.cpp
+++ b/frameworks/ans/native/src/reminder_request_timer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -13,14 +13,14 @@
* limitations under the License.
*/
+#include "reminder_request_timer.h"
+
#include
#include
#include "ans_log_wrapper.h"
#include "time_service_client.h"
-#include "reminder_request_timer.h"
-
namespace OHOS {
namespace Notification {
ReminderRequestTimer::ReminderRequestTimer(uint64_t countDownTimeInSeconds)
@@ -33,7 +33,12 @@ ReminderRequestTimer::ReminderRequestTimer(uint64_t countDownTimeInSeconds)
ReminderRequest::SetTriggerTimeInMilli(
ReminderRequest::GetDurationSinceEpochInMilli(now) + countDownTimeInSeconds_ * ReminderRequest::MILLI_SECONDS);
sptr timer = MiscServices::TimeServiceClient::GetInstance();
- firstRealTimeInMilliSeconds_ = timer->GetBootTimeMs();
+ int64_t bootTimeMs = timer->GetBootTimeMs();
+ if (bootTimeMs >= 0) {
+ firstRealTimeInMilliSeconds_ = static_cast(bootTimeMs);
+ } else {
+ ANSR_LOGW("Get boot time error.");
+ }
}
ReminderRequestTimer::ReminderRequestTimer(const ReminderRequestTimer &other) : ReminderRequest(other)
@@ -113,8 +118,12 @@ bool ReminderRequestTimer::Marshalling(Parcel &parcel) const
ReminderRequestTimer *ReminderRequestTimer::Unmarshalling(Parcel &parcel)
{
- auto objptr = new ReminderRequestTimer();
- if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) {
+ auto objptr = new (std::nothrow) ReminderRequestTimer();
+ if (objptr == nullptr) {
+ ANSR_LOGE("Failed to create reminder timer due to no memory.");
+ return objptr;
+ }
+ if (!objptr->ReadFromParcel(parcel)) {
delete objptr;
objptr = nullptr;
}
diff --git a/frameworks/ans/native/src/reminder_store.cpp b/frameworks/ans/native/src/reminder_store.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1b51a5a9f33c1f9a3d7bbe31da8d9034d9929bb4
--- /dev/null
+++ b/frameworks/ans/native/src/reminder_store.cpp
@@ -0,0 +1,418 @@
+/*
+ * 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 6ff225e5b24ee98b492a4f648358cabc949577f3..5822ce2fce71617b3298d3636469fb89ed9ffcf1 100644
--- a/frameworks/ans/native/test/unittest/BUILD.gn
+++ b/frameworks/ans/native/test/unittest/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2021 Huawei Device Co., Ltd.
+# 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
@@ -47,17 +47,18 @@ 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/native/test/unittest/reminder_request_alarm_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp
index d658d162c17953ac065308dc2d28117d07eab81a..a9b7ff527d5dfad08fa6e6f2205079abf360229f 100644
--- a/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp
+++ b/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
diff --git a/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp
index f7bc5ed5cb3f750452100c1b20dfeaaddeff48a4..ff9b3415d359f66fbf11c33a7b28a9625ce4b0fa 100644
--- a/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp
+++ b/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
diff --git a/frameworks/ans/native/test/unittest/reminder_request_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_test.cpp
index 14f13c79bfc96216cac3edd1dcb9eb97519b546d..b92b95288588d8b9e42174490dd13c462f57acb5 100644
--- a/frameworks/ans/native/test/unittest/reminder_request_test.cpp
+++ b/frameworks/ans/native/test/unittest/reminder_request_test.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
diff --git a/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp
index 852fbb84eb3c575668039f834d654362a0f6c267..36cc697b70e47f8e0a9d0a4fa7046bc4fb3f30e0 100644
--- a/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp
+++ b/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn
index de3b5012a106ad6a78231fc4c9004bfa7f14438c..941b39a8468526b7b81b690731041dab8c4c5d96 100644
--- a/frameworks/ans/test/moduletest/BUILD.gn
+++ b/frameworks/ans/test/moduletest/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2021 Huawei Device Co., Ltd.
+# 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
@@ -53,7 +53,9 @@ ohos_moduletest("ans_fw_module_test") {
"ans_fw_module_test.cpp",
"mock/blob.cpp",
"mock/distributed_kv_data_manager.cpp",
+ "mock/mock_accesstoken_kit.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",
@@ -80,17 +82,18 @@ 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",
]
@@ -127,6 +130,7 @@ 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",
@@ -154,17 +158,18 @@ 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",
]
@@ -201,6 +206,7 @@ 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",
@@ -227,17 +233,18 @@ 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",
]
@@ -274,6 +281,7 @@ 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",
@@ -300,17 +308,18 @@ 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",
]
@@ -333,8 +342,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 8f759bb5aeaa397729cee4bc6144c64c3aa3802d..c3952cb152c551c671dd6b4c2a807645af431687 100644
--- a/frameworks/ans/test/moduletest/ReminderHelperTest.js
+++ b/frameworks/ans/test/moduletest/ReminderHelperTest.js
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -108,8 +108,7 @@ describe("ReminderHelperTest", function () {
*/
it("testReminderHelper003", 0, async function (done) {
function reminderCallback(err, data) {
- let i = 0;
- expect(0).assertEqual(i);
+ expect(true).assertEqual(true);
}
reminderAgent.addNotificationSlot(0, reminderCallback);
done();
@@ -245,14 +244,13 @@ 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(id).then(() => {
+ reminderAgent.cancelReminder(0).then(() => {
reminderAgent.getValidReminders().then((reminders) => {
cancellength = reminders.length
firstdiff = publishlength - cancellength;
@@ -319,10 +317,8 @@ describe("ReminderHelperTest", function () {
reminderAgent.getValidReminders((err, reminders) => {
cancellength = reminders.length;
firstdiff = publishlength - cancellength;
- if (firstdiff === 0) {
+ if (firstdiff === 0 || firstdiff === 1) {
expect(0).assertEqual(firstdiff);
- } else if (firstdiff === 1) {
- expect(1).assertEqual(firstdiff);
}
});
});
@@ -357,10 +353,8 @@ describe("ReminderHelperTest", function () {
reminderAgent.getValidReminders((err, reminders) => {
cancellength = reminders.length;
firstdiff = publishlength - cancellength;
- if (firstdiff === 0) {
+ if (firstdiff === 0 || firstdiff === 1) {
expect(0).assertEqual(firstdiff);
- } else if (firstdiff === 1) {
- expect(1).assertEqual(firstdiff);
}
});
});
@@ -846,7 +840,7 @@ describe("ReminderHelperTest", function () {
slotType:3
}
reminderAgent.publishReminder(calendar).then((reminderId) => {
- expect(typeof(reminderId)).assertEqual('number');
+ expect(typeof(reminderId) === 'number').assertEqual(true);
});
done();
})
diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp
index e7d017b0b70177dc3f4df348bf857d396e97a5e1..e6763424dbb05b7cc00bfb0d7faa15839f19b9b9 100644
--- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp
+++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -28,6 +28,7 @@
#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"
@@ -63,6 +64,7 @@ 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;
@@ -442,9 +444,11 @@ public:
DistributedKv::StoreId storeId = {.storeId = KVSTORE_SCREEN_STATUS_STORE_ID};
std::shared_ptr pointer =
DistributedKv::AnsTestSingleKvStore::GetMockKvStorePointer(appId, storeId);
- DistributedKv::Key key("" + DELIMITER + "screen_status");
- DistributedKv::Value value(isScreenOn ? "on" : "off");
- pointer->Put(key, value);
+ if (pointer) {
+ DistributedKv::Key key("" + DELIMITER + "screen_status");
+ DistributedKv::Value value(isScreenOn ? "on" : "off");
+ pointer->Put(key, value);
+ }
}
};
@@ -472,7 +476,9 @@ 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) {
@@ -670,7 +676,8 @@ 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 << UID << KEY_SPLITER << notificationLabel << KEY_SPLITER << notificationIdInt;
+ stream << KEY_SPLITER << USER_ID << 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);
@@ -726,7 +733,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 << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0;
+ stream << KEY_SPLITER << USER_ID << 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);
@@ -816,7 +823,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_RemoveNotificaitons_00100, Function | Medium
eventParser.Parse(events);
EXPECT_TRUE(eventParser.GetWaitOnConsumed());
SleepForFC();
- EXPECT_EQ(NotificationHelper::RemoveNotifications(), ERR_OK);
+ EXPECT_EQ(NotificationHelper::RemoveNotifications(USER_ID), ERR_OK);
std::vector> notifications;
EXPECT_EQ(NotificationHelper::GetAllActiveNotifications(notifications), ERR_OK);
EXPECT_EQ((int)notifications.size(), (int)0);
@@ -999,7 +1006,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 << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 1;
+ stream << KEY_SPLITER << USER_ID << 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);
@@ -1094,7 +1101,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 << UID << KEY_SPLITER << NOTIFICATION_LABEL_0 << KEY_SPLITER << 0;
+ stream0 << KEY_SPLITER << USER_ID << 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);
@@ -1106,7 +1113,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 << UID << KEY_SPLITER << NOTIFICATION_LABEL_1 << KEY_SPLITER << 1;
+ stream1 << KEY_SPLITER << USER_ID << 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);
@@ -1787,7 +1794,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), false);
+ ASSERT_EQ(GetRequestInDistributedEntryList(request, entries, outEntry), true);
AppExecFwk::MockSetDistributedNotificationEnabled(true);
SleepForFC();
}
@@ -1910,7 +1917,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(), ERR_OK);
+ ASSERT_EQ(NotificationHelper::RemoveNotifications(USER_ID), ERR_OK);
ASSERT_EQ(pointer->GetEntries(DistributedKv::Key(""), entries), DistributedKv::Status::SUCCESS);
ASSERT_EQ(entries.size(), std::size_t(0));
SleepForFC();
@@ -1979,7 +1986,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Subscribe_00100, Function | Me
EventParser parser1;
parser1.Parse(subscriber.GetEvents());
- auto notificationList = parser1.GetOnConsumedReq();
+ auto notificationList = parser1.GetOnConsumedWithSortingMapReq();
EXPECT_NE(notificationList.size(), std::size_t(0));
std::shared_ptr outNotification;
EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true);
@@ -1990,7 +1997,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Subscribe_00100, Function | Me
EventParser parser2;
parser2.Parse(subscriber.GetEvents());
- notificationList = parser2.GetOnConsumedReq();
+ notificationList = parser2.GetOnConsumedWithSortingMapReq();
EXPECT_NE(notificationList.size(), std::size_t(0));
EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true);
subscriber.ClearEvents();
@@ -2040,7 +2047,7 @@ HWTEST_F(AnsFWModuleTest, DistributedNotification_Subscribe_00200, Function | Me
EventParser parser1;
parser1.Parse(subscriber.GetEvents());
- auto notificationList = parser1.GetOnConsumedReq();
+ auto notificationList = parser1.GetOnConsumedWithSortingMapReq();
EXPECT_NE(notificationList.size(), std::size_t(0));
std::shared_ptr outNotification;
EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true);
@@ -2114,12 +2121,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.GetOnConsumedReq();
+ auto notificationList = parser.GetOnConsumedWithSortingMapReq();
std::shared_ptr outNotification;
EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true);
EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND);
@@ -2145,12 +2152,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.GetOnConsumedReq();
+ auto notificationList = parser.GetOnConsumedWithSortingMapReq();
std::shared_ptr outNotification;
EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true);
EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND);
@@ -2176,12 +2183,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.GetOnConsumedReq();
+ auto notificationList = parser.GetOnConsumedWithSortingMapReq();
std::shared_ptr outNotification;
EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true);
EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_IDLE_REMIND);
@@ -2207,12 +2214,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.GetOnConsumedReq();
+ auto notificationList = parser.GetOnConsumedWithSortingMapReq();
std::shared_ptr outNotification;
EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true);
EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_IDLE_DONOT_REMIND);
@@ -2241,21 +2248,23 @@ 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_SCREEN_STATUS_STORE_ID};
+ DistributedKv::StoreId storeId = {.storeId = KVSTORE_NOTIFICATION_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.GetOnConsumedReq();
+ auto notificationList = parser.GetOnConsumedWithSortingMapReq();
std::shared_ptr outNotification;
EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true);
EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_ACTIVE_REMIND);
@@ -2284,13 +2293,14 @@ 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_SCREEN_STATUS_STORE_ID};
+ DistributedKv::StoreId storeId = {.storeId = KVSTORE_NOTIFICATION_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);
@@ -2298,7 +2308,7 @@ HWTEST_F(AnsFWModuleTest, DefaultRemindPolicy_00600, Function | MediumTest | Lev
EventParser parser;
parser.Parse(subscriber.GetEvents());
- auto notificationList = parser.GetOnConsumedReq();
+ auto notificationList = parser.GetOnConsumedWithSortingMapReq();
std::shared_ptr outNotification;
EXPECT_EQ(GetRequestInNotificationList(request, notificationList, outNotification), true);
EXPECT_EQ(outNotification->GetRemindType(), NotificationConstant::RemindType::DEVICE_IDLE_DONOT_REMIND);
@@ -2314,7 +2324,11 @@ 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();
@@ -2349,7 +2363,11 @@ 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();
@@ -2386,7 +2404,11 @@ 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();
@@ -2419,7 +2441,10 @@ 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);
}
@@ -2466,7 +2491,10 @@ 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);
@@ -2492,7 +2520,11 @@ 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();
@@ -2530,7 +2562,11 @@ 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/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp
index 89aa95b853d0cd73f64fef98072b54390b4f12dc..80c11446e13354b9753c7eb9bee404396692b7e7 100644
--- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp
+++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp
@@ -216,25 +216,23 @@ private:
EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType());
std::vector> actionButtons = notificationRequest.GetActionButtons();
for (auto actionButton : actionButtons) {
- std::vector> userInputs = actionButton->GetUserInputs();
- for (auto userInput : userInputs) {
- EXPECT_EQ(NotificationConstant::FREE_FORM_INPUT, userInput->GetInputsSource(g_want));
- EXPECT_EQ(nullptr, userInput->GetInputsFromWant(g_want));
- std::map> map = userInput->GetMimeInputsFromWant(g_want, "");
- EXPECT_EQ(unsigned(0), map.size());
- EXPECT_EQ("inputKey", userInput->GetInputKey());
- EXPECT_NE(nullptr, userInput->GetAdditionalData());
- EXPECT_EQ(NotificationConstant::InputEditType::EDIT_DISABLED, userInput->GetEditType());
- for (auto option : userInput->GetOptions()) {
- EXPECT_EQ("", option);
- }
- for (auto type : userInput->GetPermitMimeTypes()) {
- EXPECT_EQ("mimeType", type);
- }
- EXPECT_EQ(false, userInput->IsMimeTypeOnly());
- EXPECT_EQ("tag", userInput->GetTag());
- EXPECT_EQ(false, userInput->IsPermitFreeFormInput());
+ std::shared_ptr userInput = actionButton->GetUserInput();
+ EXPECT_EQ(NotificationConstant::FREE_FORM_INPUT, userInput->GetInputsSource(g_want));
+ EXPECT_EQ(nullptr, userInput->GetInputsFromWant(g_want));
+ std::map> map = userInput->GetMimeInputsFromWant(g_want, "");
+ EXPECT_EQ(unsigned(0), map.size());
+ EXPECT_EQ("inputKey", userInput->GetInputKey());
+ EXPECT_NE(nullptr, userInput->GetAdditionalData());
+ EXPECT_EQ(NotificationConstant::InputEditType::EDIT_DISABLED, userInput->GetEditType());
+ for (auto option : userInput->GetOptions()) {
+ EXPECT_EQ("", option);
+ }
+ for (auto type : userInput->GetPermitMimeTypes()) {
+ EXPECT_EQ("mimeType", type);
}
+ EXPECT_EQ(false, userInput->IsMimeTypeOnly());
+ EXPECT_EQ("tag", userInput->GetTag());
+ EXPECT_EQ(false, userInput->IsPermitFreeFormInput());
}
}
@@ -1345,9 +1343,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_08000, Function
std::shared_ptr dummyIcon;
auto ab1 = NotificationActionButton::Create(dummyIcon, "ab1_title", wAgent2);
- auto spUserInput3 = NotificationUserInput::Create("uikey3");
auto spUserInput2 = NotificationUserInput::Create("uikey2");
- ab1->AddNotificationUserInput(spUserInput3);
ab1->AddNotificationUserInput(spUserInput2);
auto spOnlyUserInput1 = NotificationUserInput::Create("uionlykey1");
spOnlyUserInput1->SetPermitFreeFormInput(false);
diff --git a/frameworks/ans/test/moduletest/config.json b/frameworks/ans/test/moduletest/config.json
index 7d3bb1663873510fc00c1203273ad743dfbb2f43..46e2a9f391b523655bdfbb7b2a6d525dcd79dff1 100644
--- a/frameworks/ans/test/moduletest/config.json
+++ b/frameworks/ans/test/moduletest/config.json
@@ -13,6 +13,18 @@
},
"deviceConfig": {},
"module": {
+ "reqPermissions": [
+ {
+ "name": "ohos.permission.PUBLISH_AGENT_REMINDER",
+ "reason": "SYSTEM_GRANT",
+ "usedScene": {
+ "ability": [
+ ".FormAbility"
+ ],
+ "when": "inuse"
+ }
+ }
+ ],
"package": "com.example.myapplication",
"name": ".MyApplication",
"deviceType": [
@@ -58,4 +70,3 @@
]
}
}
-
\ No newline at end of file
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 ce1ef007f3d3239be5a04cfe8b1770fc8b760e9c..3f04edd54e985e20434f983247b3b69aa334c971 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 Huawei Device Co., Ltd.
+ * 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
@@ -178,7 +178,7 @@ public:
}
/**
* @brief Query the AbilityInfo by the given Want.
- * @param want Indicates the infomation of the ability.
+ * @param want Indicates the information 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 informations with specifc flags.
+ * @brief Dump the bundle information with specific 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 infomation result.
+ * @param result Indicates the dump information 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_accesstoken_kit.cpp b/frameworks/ans/test/moduletest/mock/mock_accesstoken_kit.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7d8f042d3907a75a702b0237d96dd384facad9ad
--- /dev/null
+++ b/frameworks/ans/test/moduletest/mock/mock_accesstoken_kit.cpp
@@ -0,0 +1,27 @@
+/*
+ * 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 "accesstoken_kit.h"
+
+namespace OHOS {
+namespace Security {
+namespace AccessToken {
+int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName)
+{
+ return PERMISSION_GRANTED;
+}
+} // namespace AccessToken
+} // namespace Security
+} // namespace OHOS
diff --git a/frameworks/ans/test/moduletest/mock/mock_bundle_manager_helper.cpp b/frameworks/ans/test/moduletest/mock/mock_bundle_manager_helper.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..fdeac6723e6820bb7a97931b9baff0972d3ce38b
--- /dev/null
+++ b/frameworks/ans/test/moduletest/mock/mock_bundle_manager_helper.cpp
@@ -0,0 +1,60 @@
+/*
+ * 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/notification_action_button.h b/interfaces/innerkits/ans/native/include/notification_action_button.h
index 48dfe2a238c4f6c3c49207c94fbd7d6fd1a42d62..d1a14a2a226143f3b085a58b415bf43cc2b01059 100644
--- a/interfaces/innerkits/ans/native/include/notification_action_button.h
+++ b/interfaces/innerkits/ans/native/include/notification_action_button.h
@@ -50,7 +50,7 @@ public:
NotificationConstant::SemanticActionButton::NONE_ACTION_BUTTON,
bool autoCreatedReplies = true,
const std::vector> &mimeTypeOnlyInputs = {},
- const std::vector> &userInputs = {}, bool isContextual = false);
+ const std::shared_ptr &userInput = {}, bool isContextual = false);
/**
* A static function used to create a NotificationActionButton instance by copying parameters from an existing
@@ -130,11 +130,11 @@ public:
void AddNotificationUserInput(const std::shared_ptr &userInput);
/**
- * Obtains the NotificationUserInput objects to be collected from the user when this NotificationActionButton
+ * Obtains the NotificationUserInput object to be collected from the user when this NotificationActionButton
* is sent.
- * @return the list of NotificationUserInput objects.
+ * @return the NotificationUserInput object.
*/
- std::vector> GetUserInputs() const;
+ const std::shared_ptr GetUserInput() const;
/**
* Sets whether to allow the platform to automatically generate possible replies and add them to
@@ -222,7 +222,7 @@ private:
const std::shared_ptr &extras,
NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies,
const std::vector> &mimeTypeOnlyInputs,
- const std::vector> &userInputs, bool isContextual);
+ const std::shared_ptr &userInput, bool isContextual);
/**
* Read a NotificationActionButton object from a Parcel.
@@ -240,7 +240,7 @@ private:
};
bool autoCreatedReplies_ {true};
std::vector> mimeTypeOnlyUserInputs_ {};
- std::vector> userInputs_ {};
+ std::shared_ptr userInput_ {};
bool isContextual_ {false};
};
} // namespace Notification
diff --git a/interfaces/innerkits/ans/native/include/notification_long_text_content.h b/interfaces/innerkits/ans/native/include/notification_long_text_content.h
index 85d50017f84f8e10d128657851d052742b5bbabd..13b6ebcaf03e721727c8f1a4f0652092707e6bdd 100644
--- a/interfaces/innerkits/ans/native/include/notification_long_text_content.h
+++ b/interfaces/innerkits/ans/native/include/notification_long_text_content.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -120,7 +120,7 @@ protected:
private:
/**
- * the maximum lenth of longtext is 1024 characters.
+ * the maximum length of longtext is 1024 characters.
*/
static const std::size_t MAX_LONGTEXT_LENGTH;
diff --git a/interfaces/innerkits/ans/native/include/reminder_helper.h b/interfaces/innerkits/ans/native/include/reminder_helper.h
index 0d7f34d8880c0a3ee6fec2c2810703f5256b6473..639b2be8ccd48ccbcc3ae9ed05e37c39776380dd 100644
--- a/interfaces/innerkits/ans/native/include/reminder_helper.h
+++ b/interfaces/innerkits/ans/native/include/reminder_helper.h
@@ -53,7 +53,7 @@ public:
/**
* Cancels a specified reminder.
*
- * @param reminderId Indicates the ID of the reminder instace to cancel.
+ * @param reminderId Indicates the ID of the reminder instance to cancel.
* @return Returns cancel reminder result.
*/
static ErrCode CancelReminder(const int32_t reminderId);
@@ -69,7 +69,7 @@ public:
* Obtains all valid reminder notifications set by the current application, namely, the reminders that will
* still be triggered later. If a reminder will never be triggered again, it is not considered a valid reminder.
*
- * @param[out] validReminders Indicates an initial vector to recieve the result.
+ * @param[out] validReminders Indicates an initial vector to receive the result.
* @return Returns an array list containing all valid reminder notifications set by the current application.
*/
static ErrCode GetValidReminders(std::vector> &validReminders);
diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h
index 14fb032d6ff2f0af0445dfee2cc70254c92418b0..798913b6a582a95a44c45f2c865a8cb2862a4563 100644
--- a/interfaces/innerkits/ans/native/include/reminder_request.h
+++ b/interfaces/innerkits/ans/native/include/reminder_request.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * 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
@@ -19,8 +19,11 @@
#include