diff --git a/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp b/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp index a9b7ff527d5dfad08fa6e6f2205079abf360229f..4c0389860b254cac551fed6cecb5ae9f68a629f5 100644 --- a/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp @@ -35,45 +35,11 @@ public: /** * @tc.name: initHour_00100 - * @tc.desc: set hour < 0 should throw exception. - * @tc.type: FUNC - * @tc.require: SR000GGTRC AR000GH8E8 - */ -HWTEST_F(ReminderRequestAlarmTest, initHour_00100, Function | SmallTest | Level1) -{ - std::vector daysOfWeek; - try { - auto rrc = std::make_shared(-1, 1, daysOfWeek); - EXPECT_TRUE(false) << "hour < 0 should throw exception."; - } catch (const std::invalid_argument &e) { - ANSR_LOGI("hour < 0 throw exception."); - } -} - -/** - * @tc.name: initHour_00200 - * @tc.desc: set hour > 23 should throw exception. - * @tc.type: FUNC - * @tc.require: SR000GGTRC AR000GH8E8 - */ -HWTEST_F(ReminderRequestAlarmTest, initHour_00200, Function | SmallTest | Level1) -{ - std::vector daysOfWeek; - try { - auto rrc = std::make_shared(24, 1, daysOfWeek); - EXPECT_TRUE(false) << "hour > 23 should throw exception."; - } catch (const std::invalid_argument &e) { - ANSR_LOGI("hour > 23 throw exception."); - } -} - -/** - * @tc.name: initHour_00300 * @tc.desc: test set edge value of hour (0 and 23). * @tc.type: FUNC * @tc.require: SR000GGTRC AR000GH8E8 */ -HWTEST_F(ReminderRequestAlarmTest, initHour_00300, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestAlarmTest, initHour_00100, Function | SmallTest | Level1) { std::vector daysOfWeek; auto rrc = std::make_shared(0, 1, daysOfWeek); @@ -93,46 +59,12 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00300, Function | SmallTest | Level1 } /** - * @tc.name: initHour_00400 - * @tc.desc: set minute < 0 should throw exception. - * @tc.type: FUNC - * @tc.require: SR000GGTRC AR000GH8E8 - */ -HWTEST_F(ReminderRequestAlarmTest, initHour_00400, Function | SmallTest | Level1) -{ - std::vector daysOfWeek; - try { - auto rrc = std::make_shared(1, -1, daysOfWeek); - EXPECT_TRUE(false) << "minute < 0 should throw exception."; - } catch (const std::invalid_argument &e) { - ANSR_LOGI("minute < 0 throw exception."); - } -} - -/** - * @tc.name: initHour_00500 - * @tc.desc: set minute > 59 should throw exception. - * @tc.type: FUNC - * @tc.require: SR000GGTRC AR000GH8E8 - */ -HWTEST_F(ReminderRequestAlarmTest, initHour_00500, Function | SmallTest | Level1) -{ - std::vector daysOfWeek; - try { - auto rrc = std::make_shared(1, 60, daysOfWeek); - EXPECT_TRUE(false) << "minute > 59 should throw exception."; - } catch (const std::invalid_argument &e) { - ANSR_LOGI("minute > 59 throw exception."); - } -} - -/** - * @tc.name: initHour_00600 + * @tc.name: initHour_00200 * @tc.desc: test set edge value of minute (0 and 59). * @tc.type: FUNC * @tc.require: SR000GGTRC AR000GH8E8 */ -HWTEST_F(ReminderRequestAlarmTest, initHour_00600, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestAlarmTest, initHour_00200, Function | SmallTest | Level1) { std::vector daysOfWeek; auto rrc = std::make_shared(0, 0, daysOfWeek); @@ -187,29 +119,11 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00300, Function | SmallTest | /** * @tc.name: initDaysOfWeek_00400 - * @tc.desc: test set daysOfWeek exceeding maximum length. - * @tc.type: FUNC - * @tc.require: SR000GGTRC AR000GH8E8 - */ -HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00400, Function | SmallTest | Level1) -{ - uint8_t arr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); - try { - auto rrc = std::make_shared(0, 0, daysOfWeek); - EXPECT_TRUE(false) << "repeatDays exceeding maximum length should throw exception"; - } catch (const std::invalid_argument &e) { - EXPECT_TRUE(true); - } -} - -/** - * @tc.name: initDaysOfWeek_00500 * @tc.desc: test set daysOfWeek with null value. * @tc.type: FUNC * @tc.require: SR000GGTRC AR000GH8E8 */ -HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00500, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00400, Function | SmallTest | Level1) { uint8_t arr[] = {}; std::vector daysOfWeek (arr, arr + sizeof(arr) / sizeof(uint8_t)); diff --git a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp index d7e758578cdc535398490c1e7c1dcecdb502985a..461ce28fca46fb4fb2c077d9e7c0a9ffe99389b4 100644 --- a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp @@ -200,17 +200,6 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00500, Function | SmallTest | calendar = std::make_shared(nowTime, repeatMonths, repeatDays); actualRepeatMonths = calendar->GetRepeatMonths(); EXPECT_TRUE(actualRepeatMonths.size() == 0) << "Set repeat month with 13 error."; - - for (uint8_t i = 1; i <= 12; i++) { - repeatMonths.push_back(i); - } - repeatMonths.push_back(1); - try { - auto calendar = std::make_shared(nowTime, repeatMonths, repeatDays); - EXPECT_TRUE(false) << "length of repeat month > 12 should throw exception."; - } catch (const std::invalid_argument &e) { - ANSR_LOGI("length of repeat month > 12 throw exception."); - } } /** @@ -283,18 +272,6 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00700, Function | SmallTest | calendar = std::make_shared(nowTime, repeatMonths, repeatDays); actualRepeatDays = calendar->GetRepeatDays(); EXPECT_TRUE(actualRepeatDays.size() == 0) << "Set repeat day with 32 error."; - - repeatDays.clear(); - for (uint8_t i = 1; i <= 31; i++) { - repeatDays.push_back(i); - } - repeatDays.push_back(1); - try { - calendar = std::make_shared(nowTime, repeatMonths, repeatDays); - ANSR_LOGI("length of repeat month > 32 should throw exception."); - } catch (const std::invalid_argument &e) { - ANSR_LOGI("length of repeat month > 32 throw exception."); - } } /** diff --git a/frameworks/ans/test/unittest/reminder_request_timer_test.cpp b/frameworks/ans/test/unittest/reminder_request_timer_test.cpp index 36cc697b70e47f8e0a9d0a4fa7046bc4fb3f30e0..1a6e8c8a32a9ad424c5e7e5311e6ba69c700a55a 100644 --- a/frameworks/ans/test/unittest/reminder_request_timer_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_timer_test.cpp @@ -38,45 +38,11 @@ public: /** * @tc.name: initCountDownTime_00100 - * @tc.desc: set countDownTime = 0 should throw exception. - * @tc.type: FUNC - * @tc.require: SR000GGTRC AR000GH8E8 - */ -HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00100, Function | SmallTest | Level1) -{ - try { - uint64_t countDownTimeInSeconds = 0; - auto rrc = std::make_shared(countDownTimeInSeconds); - EXPECT_TRUE(false) << "countDownTime < 0 should throw exception."; - } catch (const std::invalid_argument &e) { - ANSR_LOGI("countDownTime < 0 throw exception."); - } -} - -/** - * @tc.name: initCountDownTime_00200 - * @tc.desc: set countDownTime > (UINT64_MAX / 1000) should throw exception. - * @tc.type: FUNC - * @tc.require: SR000GGTRC AR000GH8E8 - */ -HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00200, Function | SmallTest | Level1) -{ - try { - auto rrc = std::make_shared(UINT64_MAX / 1000); - EXPECT_TRUE(false) << "countDownTime >= (UINT64_MAX / 1000) should throw exception."; - } catch (const std::invalid_argument &e) { - ANSR_LOGI("countDownTime > (UINT64_MAX / 1000) throw exception."); - } -} - - -/** - * @tc.name: initCountDownTime_00300 * @tc.desc: set countDownTime with normal value. * @tc.type: FUNC * @tc.require: SR000GGTRC AR000GH8E8 */ -HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00300, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00100, Function | SmallTest | Level1) { uint64_t countDownTimeInSeconds = 1; auto rrc = std::make_shared(countDownTimeInSeconds); diff --git a/hisysevent.yaml b/hisysevent.yaml index 49e0f595494422bd77a6d0c55b3ce1fe7ef7360c..7e60568b609ba3e97f8f76c77e6251719dedb8f1 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -26,4 +26,10 @@ ANS_PUBLISH: ANS_SUBSCRIBE: __BASE: {type: FAULT, level: CRITICAL, tag: ANS, desc: ans subscribe} PID: {type: INT32, desc: pid} - UID: {type: INT32, desc: uid} \ No newline at end of file + UID: {type: INT32, desc: uid} + +ALARM_TRIGGER: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: alarm trigger} + PID: {type: INT32, desc: thread pid} + UID: {type: INT32, desc: package uid} + NAME: {type: STRING, desc: call package name} \ No newline at end of file diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index ce40019bc038ff5bd7a47f72f3597bba2294ea1e..c8d6651a73e60b226cd3b8d15d41761ebb23362e 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -81,6 +81,7 @@ ohos_shared_library("libans") { "access_token:libaccesstoken_sdk", "device_usage_statistics:usagestatsinner", "distributeddatamgr:distributeddata_inner", + "hisysevent_native:libhisysevent", "multimedia_image_standard:image_native", "multimedia_media_standard:media_client", "os_account:os_account_innerkits", diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index e28db03dc16d07aa11621554042b8eb4155d962c..d34b7fb4ddf8892c272116df1c2c01356ce967e4 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -223,9 +223,13 @@ private: * Create a information for timer, such as timer type, repeat policy, interval and want agent. * * @param type Indicates the timer type. + * @param reminderRequest Indicates the reminder request. * @return pointer of ReminderTimerInfo. */ - std::shared_ptr CreateTimerInfo(TimerType type) const; + std::shared_ptr CreateTimerInfo(TimerType type, + const sptr &reminderRequest) const; + void InitTimerInfo(std::shared_ptr &timerInfo, + const sptr &reminderRequest) const; void GetImmediatelyShowRemindersLocked(std::vector> &reminders) const; diff --git a/services/ans/include/reminder_timer_info.h b/services/ans/include/reminder_timer_info.h index ef4920a766c0573fbd54dd1571ab97beb96084ef..5ffc5b34a568c9801e28f40b4288b94e31e84230 100644 --- a/services/ans/include/reminder_timer_info.h +++ b/services/ans/include/reminder_timer_info.h @@ -36,6 +36,21 @@ public: action_ = action; } + inline void SetPid(const int32_t pid) + { + pid_ = pid; + } + + inline void SetUid(const int32_t uid) + { + uid_ = uid; + } + + inline void SetBundleName(const std::string &bundleName) + { + bundleName_ = bundleName; + } + /** * When timing is up, this function will execute as call back. */ @@ -63,6 +78,9 @@ public: private: std::string action_; + int32_t pid_ {-1}; + int32_t uid_ {-1}; + std::string bundleName_; }; } // namespace OHOS } // namespace Notification diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 946ece0ef7859739f5584a3655d8999689a65b4e..bb36b715b96379f66c9b24dfe16fdeb96290ca4d 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -293,13 +293,9 @@ void ReminderDataManager::OnProcessDiedLocked(const sptr ReminderDataManager::CreateTimerInfo(TimerType type) const +void ReminderDataManager::InitTimerInfo(std::shared_ptr &sharedTimerInfo, + const sptr &reminderRequest) 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); int32_t timerType = static_cast(timerTypeWakeup | timerTypeExact); @@ -307,6 +303,26 @@ std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerTyp sharedTimerInfo->SetRepeat(false); sharedTimerInfo->SetInterval(0); + auto mit = notificationBundleOptionMap_.find(reminderRequest->GetReminderId()); + if (mit == notificationBundleOptionMap_.end()) { + ANS_LOGE("Failed to get bundle information. reminderId=%{public}d", + reminderRequest->GetReminderId()); + return; + } + sharedTimerInfo->SetBundleName(mit->second->GetBundleName()); + sharedTimerInfo->SetUid(mit->second->GetUid()); +} + +std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerType type, + const sptr &reminderRequest) 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; + } + InitTimerInfo(sharedTimerInfo, reminderRequest); + int32_t requestCode = 10; std::vector flags; flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); @@ -315,6 +331,7 @@ std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerTyp switch (type) { case (TimerType::TRIGGER_TIMER): { want->SetAction(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); + sharedTimerInfo->SetAction(ReminderRequest::REMINDER_EVENT_ALARM_ALERT); want->SetParam(ReminderRequest::PARAM_REMINDER_ID, activeReminderId_); break; } @@ -324,6 +341,7 @@ std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerTyp return sharedTimerInfo; } want->SetAction(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); + sharedTimerInfo->SetAction(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); want->SetParam(ReminderRequest::PARAM_REMINDER_ID, alertingReminderId_); break; } @@ -1232,7 +1250,7 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques break; } SetActiveReminder(reminderRequest); - timerId_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type)); + timerId_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type, reminderRequest)); triggerTime = reminderRequest->GetTriggerTimeInMilli(); timer->StartTimer(timerId_, triggerTime); ANSR_LOGD("Start timing (next triggerTime), timerId=%{public}" PRIu64 "", timerId_); @@ -1245,7 +1263,7 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques } triggerTime = ReminderRequest::GetDurationSinceEpochInMilli(now) + static_cast(reminderRequest->GetRingDuration() * ReminderRequest::MILLI_SECONDS); - timerIdAlerting_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type)); + timerIdAlerting_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type, reminderRequest)); timer->StartTimer(timerIdAlerting_, triggerTime); ANSR_LOGD( "Start timing (alerting time out), timerId=%{public}" PRIu64 "", timerIdAlerting_); diff --git a/services/ans/src/reminder_timer_info.cpp b/services/ans/src/reminder_timer_info.cpp index fbfd1ab728810f03e7926456ad30124323c814f4..5a199358458e3548b07c78fd49ce710260ec4366 100644 --- a/services/ans/src/reminder_timer_info.cpp +++ b/services/ans/src/reminder_timer_info.cpp @@ -17,9 +17,11 @@ #include "ans_log_wrapper.h" #include "common_event_manager.h" +#include "hisysevent.h" #include "reminder_request.h" using namespace OHOS::EventFwk; +using namespace OHOS::HiviewDFX; namespace OHOS { namespace Notification { void ReminderTimerInfo::SetType(const int &_type) @@ -45,6 +47,11 @@ void ReminderTimerInfo::SetWantAgent(std::shared_ptr