diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index efa426b5d36696102c7f269d449fcdd55f04d701..5adbeee6ce012ad980c68c0de62d65253e8be3f1 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -18,7 +18,6 @@ #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" @@ -27,10 +26,6 @@ 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; @@ -43,6 +38,7 @@ const uint8_t ReminderRequest::REMINDER_STATUS_ACTIVE = 1; const uint8_t ReminderRequest::REMINDER_STATUS_ALERTING = 2; const uint8_t ReminderRequest::REMINDER_STATUS_SHOWING = 4; const uint8_t ReminderRequest::REMINDER_STATUS_SNOOZE = 8; +const int ReminderRequest::BASE_YEAR = 1900; const std::string ReminderRequest::NOTIFICATION_LABEL = "REMINDER_AGENT"; const std::string ReminderRequest::REMINDER_EVENT_ALARM_ALERT = "ohos.event.notification.reminder.ALARM_ALERT"; const std::string ReminderRequest::REMINDER_EVENT_CLOSE_ALERT = "ohos.event.notification.reminder.CLOSE_ALERT"; @@ -55,38 +51,6 @@ const std::string ReminderRequest::SEP_BUTTON_SINGLE = ""; const std::string ReminderRequest::SEP_BUTTON_MULTI = ""; const std::string ReminderRequest::SEP_WANT_AGENT = ""; -// For database recovery. -const std::string ReminderRequest::REMINDER_ID = "reminder_id"; -const std::string ReminderRequest::PKG_NAME = "package_name"; -const std::string ReminderRequest::USER_ID = "user_id"; -const std::string ReminderRequest::UID = "uid"; -const std::string ReminderRequest::APP_LABEL = "app_label"; -const std::string ReminderRequest::REMINDER_TYPE = "reminder_type"; -const std::string ReminderRequest::REMINDER_TIME = "reminder_time"; -const std::string ReminderRequest::TRIGGER_TIME = "trigger_time"; -const std::string ReminderRequest::RTC_TRIGGER_TIME = "rtc_trigger_time"; -const std::string ReminderRequest::TIME_INTERVAL = "time_interval"; -const std::string ReminderRequest::SNOOZE_TIMES = "snooze_times"; -const std::string ReminderRequest::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; -const std::string ReminderRequest::RING_DURATION = "ring_duration"; -const std::string ReminderRequest::IS_EXPIRED = "is_expired"; -const std::string ReminderRequest::IS_ACTIVE = "is_active"; -const std::string ReminderRequest::STATE = "state"; -const std::string ReminderRequest::ZONE_ID = "zone_id"; -const std::string ReminderRequest::HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; -const std::string ReminderRequest::ACTION_BUTTON_INFO = "button_info"; -const std::string ReminderRequest::SLOT_ID = "slot_id"; -const std::string ReminderRequest::NOTIFICATION_ID = "notification_id"; -const std::string ReminderRequest::TITLE = "title"; -const std::string ReminderRequest::CONTENT = "content"; -const std::string ReminderRequest::SNOOZE_CONTENT = "snooze_content"; -const std::string ReminderRequest::EXPIRED_CONTENT = "expired_content"; -const std::string ReminderRequest::AGENT = "agent"; -const std::string ReminderRequest::MAX_SCREEN_AGENT = "maxScreen_agent"; - -std::string ReminderRequest::sqlOfAddColumns = ""; -std::vector ReminderRequest::columns; - ReminderRequest::ReminderRequest() { InitServerObj(); @@ -973,15 +937,12 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel) { - auto objptr = new (std::nothrow) ReminderRequest(); - if (objptr == nullptr) { - ANSR_LOGE("Failed to create reminder due to no memory."); - return objptr; - } - if (!objptr->ReadFromParcel(parcel)) { + auto objptr = new ReminderRequest(); + if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) { delete objptr; objptr = nullptr; } + return objptr; } @@ -1278,12 +1239,8 @@ 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); @@ -1307,12 +1264,8 @@ 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); } @@ -1333,10 +1286,7 @@ std::shared_ptr ReminderRequest::CreateWan wants, nullptr ); - std::string identity = IPCSkeleton::ResetCallingIdentity(); - auto wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); - IPCSkeleton::SetCallingIdentity(identity); - return wantAgent; + return AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); } void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element) @@ -1357,7 +1307,7 @@ void ReminderRequest::SetState(bool deSet, const uint8_t newState, std::string f if (deSet) { state_ |= newState; } else { - state_ &= static_cast(~newState); + state_ &= ~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()); @@ -1436,7 +1386,7 @@ void ReminderRequest::UpdateNotificationBundleInfo() notificationRequest_->SetOwnerBundleName(bundleName_); notificationRequest_->SetCreatorBundleName(bundleName_); notificationRequest_->SetCreatorUid(uid_); - ErrCode errCode = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid_, userId_); + ErrCode errCode = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid_, userId_); if (errCode != ERR_OK) { ANSR_LOGE("GetOsAccountLocalIdFromUid fail."); return; @@ -1599,7 +1549,38 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, } } -void ReminderRequest::InitDbColumns() +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; + +void ReminderRequest::Init() { AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", false); AddColumn(PKG_NAME, "TEXT NOT NULL", false); @@ -1641,4 +1622,4 @@ void ReminderRequest::AddColumn( } } } -} +} \ No newline at end of file diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index 35a459af72db423e3620cdb782bc394ab786980e..532202d0c16ec1303648c7cb19319e21a6164c5a 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -29,11 +29,6 @@ const uint8_t ReminderRequestAlarm::MINUTES_PER_HOUR = 60; const int8_t ReminderRequestAlarm::INVALID_INT_VALUE = -1; const int8_t ReminderRequestAlarm::DEFAULT_SNOOZE_TIMES = 3; -// For database recovery. -const std::string ReminderRequestAlarm::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; -const std::string ReminderRequestAlarm::ALARM_HOUR = "alarm_hour"; -const std::string ReminderRequestAlarm::ALARM_MINUTE = "alarm_minute"; - ReminderRequestAlarm::ReminderRequestAlarm(uint8_t hour, uint8_t minute, const std::vector daysOfWeek) : ReminderRequest(ReminderRequest::ReminderType::ALARM) { @@ -275,11 +270,7 @@ ReminderRequestAlarm *ReminderRequestAlarm::Unmarshalling(Parcel &parcel) { ANSR_LOGD("New alarm"); auto objptr = new (std::nothrow) ReminderRequestAlarm(); - if (objptr == nullptr) { - ANSR_LOGE("Failed to create reminder alarm due to no memory."); - return objptr; - } - if (!objptr->ReadFromParcel(parcel)) { + if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) { delete objptr; objptr = nullptr; } @@ -341,7 +332,11 @@ void ReminderRequestAlarm::AppendValuesBucket(const sptr &remin values.PutInt(ALARM_MINUTE, minute); } -void ReminderRequestAlarm::InitDbColumns() +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"; + +void ReminderRequestAlarm::Init() { ReminderRequest::AddColumn(REPEAT_DAYS_OF_WEEK, "INT", false); ReminderRequest::AddColumn(ALARM_HOUR, "INT", false); diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index 07b741a0aa897a249637ffd04e24e5e338c8b8bf..746c2adcd41a1106367610d0f0c7d2e6a010a9f3 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -25,25 +25,13 @@ 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 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)); + firstDesignateYear_ = GetActualTime(TimeTransferType::YEAR, dateTime.tm_year); + firstDesignateMonth_ = GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon); firstDesignateDay_ = dateTime.tm_mday; SetRepeatMonths(repeatMonths); SetRepeatDaysOfMonth(repeatDays); @@ -51,8 +39,8 @@ ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, // 2. get the latest valid trigger time. InitDateTime(dateTime); - hour_ = static_cast(dateTime_.tm_hour); - minute_ = static_cast(dateTime_.tm_min); + hour_ = dateTime_.tm_hour; + minute_ = 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); @@ -64,8 +52,8 @@ ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, } // 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)); + year_ = GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year); + month_ = GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon); day_ = dateTime_.tm_mday; second_ = 0; SetTriggerTimeInMilli(nextTriggerTime); @@ -451,11 +439,7 @@ ReminderRequestCalendar *ReminderRequestCalendar::Unmarshalling(Parcel &parcel) { ANSR_LOGD("New calendar"); auto objptr = new ReminderRequestCalendar(); - if (objptr == nullptr) { - ANS_LOGE("Failed to create reminder calendar due to no memory."); - return objptr; - } - if (!objptr->ReadFromParcel(parcel)) { + if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) { delete objptr; objptr = nullptr; } @@ -592,7 +576,18 @@ void ReminderRequestCalendar::AppendValuesBucket(const sptr &re values.PutInt(CALENDAR_MINUTE, minute); } -void ReminderRequestCalendar::InitDbColumns() +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"; + +void ReminderRequestCalendar::Init() { ReminderRequest::AddColumn(REPEAT_DAYS, "INT", false); ReminderRequest::AddColumn(REPEAT_MONTHS, "INT", false); diff --git a/frameworks/ans/native/src/reminder_request_timer.cpp b/frameworks/ans/native/src/reminder_request_timer.cpp index cac42261980e32d4966be8ff836c2370982fb2a8..66b8794cf9a1bac79f19b02881685ea97b0fd8c8 100644 --- a/frameworks/ans/native/src/reminder_request_timer.cpp +++ b/frameworks/ans/native/src/reminder_request_timer.cpp @@ -33,12 +33,7 @@ ReminderRequestTimer::ReminderRequestTimer(uint64_t countDownTimeInSeconds) ReminderRequest::SetTriggerTimeInMilli( ReminderRequest::GetDurationSinceEpochInMilli(now) + countDownTimeInSeconds_ * ReminderRequest::MILLI_SECONDS); sptr timer = MiscServices::TimeServiceClient::GetInstance(); - int64_t bootTimeMs = timer->GetBootTimeMs(); - if (bootTimeMs >= 0) { - firstRealTimeInMilliSeconds_ = static_cast(bootTimeMs); - } else { - ANSR_LOGW("Get boot time error."); - } + firstRealTimeInMilliSeconds_ = timer->GetBootTimeMs(); } ReminderRequestTimer::ReminderRequestTimer(const ReminderRequestTimer &other) : ReminderRequest(other) @@ -118,12 +113,8 @@ bool ReminderRequestTimer::Marshalling(Parcel &parcel) const ReminderRequestTimer *ReminderRequestTimer::Unmarshalling(Parcel &parcel) { - auto objptr = new (std::nothrow) ReminderRequestTimer(); - if (objptr == nullptr) { - ANSR_LOGE("Failed to create reminder timer due to no memory."); - return objptr; - } - if (!objptr->ReadFromParcel(parcel)) { + auto objptr = new ReminderRequestTimer(); + if ((objptr != nullptr) && !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 index 1b51a5a9f33c1f9a3d7bbe31da8d9034d9929bb4..b63bcaea32a1504d5901cd6107a3aea6d5fa9925 100644 --- a/frameworks/ans/native/src/reminder_store.cpp +++ b/frameworks/ans/native/src/reminder_store.cpp @@ -28,16 +28,15 @@ 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 std::string ReminderStore::REMINDER_DB_DIR = "/data/system_ce/ans_standard/"; +const std::string ReminderStore::REMINDER_DB_NAME = "reminder.db"; +const std::string ReminderStore::REMINDER_DB_TABLE = "reminder"; +const uint32_t ReminderStore::REMINDER_RDB_VERSION = 1; +const int32_t ReminderStore::STATE_FAIL = -1; const int32_t ReminderStore::STATE_OK = 0; +const uint16_t ReminderStore::TIME_INTERVAL_FOR_DELETE = 1800; +const uint16_t ReminderStore::MILLI_SECONDS = 1000; +std::vector ReminderStore::columns; int32_t ReminderStore::ReminderStoreDataCallBack::OnCreate(NativeRdb::RdbStore &store) { @@ -67,13 +66,13 @@ int32_t ReminderStore::Init() } } - ReminderRequest::InitDbColumns(); - ReminderRequestCalendar::InitDbColumns(); - ReminderRequestAlarm::InitDbColumns(); - columns.insert(columns.begin(), + ReminderRequest::Init(); + ReminderRequestCalendar::Init(); + ReminderRequestAlarm::Init(); + ReminderStore::columns.insert(ReminderStore::columns.begin(), ReminderRequest::columns.begin(), ReminderRequest::columns.end()); - std::string dbConfig = REMINDER_DB_DIR + REMINDER_DB_NAME; + std::string dbConfig = ReminderStore::REMINDER_DB_DIR + ReminderStore::REMINDER_DB_NAME; NativeRdb::RdbStoreConfig config_(dbConfig); ReminderStoreDataCallBack rdbDataCallBack_; rdbStore_ = NativeRdb::RdbHelper::GetRdbStore(config_, REMINDER_RDB_VERSION, rdbDataCallBack_, errCode); @@ -125,7 +124,7 @@ int32_t ReminderStore::InitData() ANSR_LOGE("Init data failed."); return STATE_FAIL; } - return ReminderStore::STATE_OK; + return STATE_OK; } int32_t ReminderStore::Delete(int32_t reminderId) @@ -260,7 +259,7 @@ std::shared_ptr ReminderStore::Query(const std::s uint8_t ReminderStore::GetColumnIndex(const std::string& name) { uint8_t index = 0; - for (auto it = columns.begin(); it != columns.end(); ++it) { + for (auto it = ReminderStore::columns.begin(); it != ReminderStore::columns.end(); ++it) { if (name == (*it)) { break; } @@ -415,4 +414,4 @@ void ReminderStore::GenerateData(const sptr &reminder, ReminderRequestAlarm::AppendValuesBucket(reminder, bundleOption, values); } } // namespace Notification -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/test/moduletest/ReminderHelperTest.js b/frameworks/ans/test/moduletest/ReminderHelperTest.js index c3952cb152c551c671dd6b4c2a807645af431687..93aaa459fceab374a059e96a48adf59ffb7ffa94 100644 --- a/frameworks/ans/test/moduletest/ReminderHelperTest.js +++ b/frameworks/ans/test/moduletest/ReminderHelperTest.js @@ -108,7 +108,8 @@ describe("ReminderHelperTest", function () { */ it("testReminderHelper003", 0, async function (done) { function reminderCallback(err, data) { - expect(true).assertEqual(true); + let i = 0; + expect(0).assertEqual(i); } reminderAgent.addNotificationSlot(0, reminderCallback); done(); @@ -244,13 +245,14 @@ describe("ReminderHelperTest", function () { reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, triggerTimeInSeconds: 3 } + let id = 1; let publishlength = -1; let cancellength = -1; let firstdiff = -1; reminderAgent.publishReminder(timer).then(() => { reminderAgent.getValidReminders().then((reminders) => { publishlength=reminders.length - reminderAgent.cancelReminder(0).then(() => { + reminderAgent.cancelReminder(id).then(() => { reminderAgent.getValidReminders().then((reminders) => { cancellength = reminders.length firstdiff = publishlength - cancellength; @@ -317,8 +319,10 @@ describe("ReminderHelperTest", function () { reminderAgent.getValidReminders((err, reminders) => { cancellength = reminders.length; firstdiff = publishlength - cancellength; - if (firstdiff === 0 || firstdiff === 1) { + if (firstdiff === 0) { expect(0).assertEqual(firstdiff); + } else if (firstdiff === 1) { + expect(1).assertEqual(firstdiff); } }); }); @@ -353,8 +357,10 @@ describe("ReminderHelperTest", function () { reminderAgent.getValidReminders((err, reminders) => { cancellength = reminders.length; firstdiff = publishlength - cancellength; - if (firstdiff === 0 || firstdiff === 1) { + if (firstdiff === 0) { expect(0).assertEqual(firstdiff); + } else if (firstdiff === 1) { + expect(1).assertEqual(firstdiff); } }); }); @@ -840,7 +846,7 @@ describe("ReminderHelperTest", function () { slotType:3 } reminderAgent.publishReminder(calendar).then((reminderId) => { - expect(typeof(reminderId) === 'number').assertEqual(true); + expect(typeof(reminderId)).assertEqual('number'); }); done(); }) diff --git a/frameworks/ans/test/moduletest/config.json b/frameworks/ans/test/moduletest/config.json index 46e2a9f391b523655bdfbb7b2a6d525dcd79dff1..7d3bb1663873510fc00c1203273ad743dfbb2f43 100644 --- a/frameworks/ans/test/moduletest/config.json +++ b/frameworks/ans/test/moduletest/config.json @@ -13,18 +13,6 @@ }, "deviceConfig": {}, "module": { - "reqPermissions": [ - { - "name": "ohos.permission.PUBLISH_AGENT_REMINDER", - "reason": "SYSTEM_GRANT", - "usedScene": { - "ability": [ - ".FormAbility" - ], - "when": "inuse" - } - } - ], "package": "com.example.myapplication", "name": ".MyApplication", "deviceType": [ @@ -70,3 +58,4 @@ ] } } + \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index 798913b6a582a95a44c45f2c865a8cb2862a4563..f4585d1deb5efb3c9e2cf5341fcdecf86afcf70d 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -607,7 +607,7 @@ public: static const uint8_t REMINDER_STATUS_SNOOZE; // For database recovery. - static void InitDbColumns(); + static void Init(); static const std::string REMINDER_ID; static const std::string PKG_NAME; static const std::string USER_ID; @@ -664,6 +664,8 @@ protected: */ static void AddColumn(const std::string &name, const std::string &type, const bool &isEnd); + static const int BASE_YEAR; + private: void AddActionButtons(const bool includeSnooze); void AddRemovalWantAgent(); diff --git a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h index 705dbf0a03945b6e2c1cbb4773573dcfb991881e..b0f562507939de534ab7055b15a1a1dfc2011101 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h @@ -109,7 +109,7 @@ public: const sptr &bundleOption, NativeRdb::ValuesBucket &values); // For database recovery. - static void InitDbColumns(); + static void Init(); protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; diff --git a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h index 1023f233267ecb5a5f0d71525d4fa5edd5ff1e61..9d022dc7d002633612488e780b8b6382654d71d6 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h @@ -147,7 +147,7 @@ public: static uint8_t GetDaysOfMonth(const uint16_t &year, const uint8_t &month); // For database recovery. - static void InitDbColumns(); + static void Init(); protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; @@ -186,17 +186,7 @@ private: static const uint8_t DECEMBER; static const uint8_t DEFAULT_SNOOZE_TIMES; - tm dateTime_ = { - .tm_sec = 0, - .tm_min = 0, - .tm_hour = 0, - .tm_mday = 1, - .tm_mon = 0, - .tm_year = 0, - .tm_wday = 0, - .tm_yday = 0, - .tm_isdst = -1 - }; + tm dateTime_; uint16_t firstDesignateYear_ {1}; uint8_t firstDesignateMonth_ {1}; uint8_t firstDesignateDay_ {1}; diff --git a/interfaces/innerkits/ans/native/include/reminder_request_timer.h b/interfaces/innerkits/ans/native/include/reminder_request_timer.h index 673bf2885e2e76b7c7f9e4514d1c5a784ce34b48..8b9aae9867ec07fd27347c3790af4a21c5545804 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_timer.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_timer.h @@ -77,8 +77,8 @@ private: void CheckParamsValid(const uint64_t countDownTimeInSeconds) const; void UpdateTimeInfo(const std::string description); uint64_t countDownTimeInSeconds_ {0}; - uint64_t firstRealTimeInMilliSeconds_ {0}; - uint64_t whenToChangeSysTime_ {0}; + uint64_t firstRealTimeInMilliSeconds_ {-1}; + uint64_t whenToChangeSysTime_ {-1}; }; } // namespace Reminder } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/reminder_store.h b/interfaces/innerkits/ans/native/include/reminder_store.h index cea23b096fecfb5139dbfac9d72a145b5e0152be..8e49fded8d3f0590461b5a6504fe5026ef14c9af 100644 --- a/interfaces/innerkits/ans/native/include/reminder_store.h +++ b/interfaces/innerkits/ans/native/include/reminder_store.h @@ -41,6 +41,8 @@ public: int64_t UpdateOrInsert(const sptr &reminder, const sptr &bundleOption); static uint8_t GetColumnIndex(const std::string& name); + static std::vector columns; + static const int32_t STATE_FAIL; static const int32_t STATE_OK; private: @@ -69,6 +71,13 @@ private: std::shared_ptr Query(const std::string &queryCondition) const; int64_t Update(const sptr &reminder, const sptr &bundleOption); + static const std::string REMINDER_DB_DIR; + static const std::string REMINDER_DB_NAME; + static const std::string REMINDER_DB_TABLE; + static const uint32_t REMINDER_RDB_VERSION; + static const uint16_t TIME_INTERVAL_FOR_DELETE; + static const uint16_t MILLI_SECONDS; + class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback { public: int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; diff --git a/interfaces/kits/js/@ohos.reminderAgent.d.ts b/interfaces/kits/js/@ohos.reminderAgent.d.ts index f227a9b7388d2f75b9bda8d83005824e7911433d..581d5fe418f08232e658c464084aa7faa2fd988a 100644 --- a/interfaces/kits/js/@ohos.reminderAgent.d.ts +++ b/interfaces/kits/js/@ohos.reminderAgent.d.ts @@ -408,13 +408,6 @@ declare namespace reminderAgent { * @syscap SystemCapability.Notification.ReminderAgent. */ minute: number; - - /** - * value of minute. - * @since 7 - * @syscap SystemCapability.Notification.ReminderAgent. - */ - second: number; } } export default reminderAgent; \ No newline at end of file diff --git a/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp index 27f82b503edbf4c5270a00583223e097deeb97a5..8ebcb860969cb471f44a1374c80839d28a30a6bf 100644 --- a/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp +++ b/interfaces/kits/napi/ans/src/reminder/reminder_common.cpp @@ -222,7 +222,7 @@ napi_value ReminderCommon::GenReminder( if (propertyVal < 0) { reminder->SetSnoozeTimes(0); } else { - uint8_t snoozeTimes = propertyVal > UINT8_MAX ? UINT8_MAX : static_cast(propertyVal); + uint8_t snoozeTimes = propertyVal > UINT8_MAX ? UINT8_MAX : propertyVal; reminder->SetSnoozeTimes(static_cast(snoozeTimes)); } } diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 538c554a5e4fa8c89e46557c871cb75ef9b4d69a..238814284f593e3d838d853d006dd665a343625f 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -18,7 +18,6 @@ #include "ans_log_wrapper.h" #include "ans_const_define.h" #include "common_event_support.h" -#include "ipc_skeleton.h" #include "notification_slot.h" #include "reminder_event_manager.h" #include "time_service_client.h" @@ -237,22 +236,15 @@ void ReminderDataManager::OnProcessDiedLocked(const sptr ReminderDataManager::CreateTimerInfo(TimerType type) const { auto sharedTimerInfo = std::make_shared(); - if (sharedTimerInfo->TIMER_TYPE_WAKEUP > UINT8_MAX || sharedTimerInfo->TIMER_TYPE_EXACT > UINT8_MAX) { - ANSR_LOGE("Failed to set timer type."); - return nullptr; - } - uint8_t timerTypeWakeup = static_cast(sharedTimerInfo->TIMER_TYPE_WAKEUP); - uint8_t timerTypeExact = static_cast(sharedTimerInfo->TIMER_TYPE_EXACT); - int timerType = static_cast(timerTypeWakeup | timerTypeExact); - sharedTimerInfo->SetType(timerType); + sharedTimerInfo->SetType(sharedTimerInfo->TIMER_TYPE_WAKEUP|sharedTimerInfo->TIMER_TYPE_EXACT); sharedTimerInfo->SetRepeat(false); sharedTimerInfo->SetInterval(0); int requestCode = 10; std::vector flags; flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); - auto want = std::make_shared(); + switch (type) { case (TimerType::TRIGGER_TIMER): { want->SetAction(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); @@ -280,12 +272,8 @@ std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerTyp wants, nullptr ); - - std::string identity = IPCSkeleton::ResetCallingIdentity(); std::shared_ptr wantAgent = AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, 0); - IPCSkeleton::SetCallingIdentity(identity); - sharedTimerInfo->SetWantAgent(wantAgent); return sharedTimerInfo; } @@ -665,6 +653,7 @@ void ReminderDataManager::StartRecentReminder() StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); reminder->OnStart(); store_->UpdateOrInsert(reminder, FindNotificationBundleOption(reminder->GetReminderId())); + SetActiveReminder(reminder); } void ReminderDataManager::StopAlertingReminder(const sptr &reminder) @@ -1147,13 +1136,13 @@ void ReminderDataManager::ResetStates(TimerType type) { switch (type) { case TimerType::TRIGGER_TIMER: { - ANSR_LOGD("ResetStates(activeReminderId, timerId(next triggerTime))"); + ANSR_LOGD("ResetStates(activeReminder)"); timerId_ = 0; activeReminderId_ = -1; break; } case TimerType::ALERTING_TIMER: { - ANSR_LOGD("ResetStates(alertingReminderId, timeId(alerting time out))"); + ANSR_LOGD("ResetStates(alertingReminder)"); timerIdAlerting_ = 0; alertingReminderId_ = -1; break;