diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index 8cf575c0b090f713afbe6861b4d41eca97c445c4..d115b2a96aad03807066503188cc03052397920c 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -97,6 +97,7 @@ ohos_shared_library("ans_core") { "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", + "os_account_standard:os_account_innerkits", "samgr_standard:samgr_proxy", "time_native:time_service", ] diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 3b27d3b01f52972a8298a678963e3e5a25f9e8d0..45f7a7d215e6f1b2288279cef1b29f295b5a4a92 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -14,6 +14,11 @@ */ #include "ans_log_wrapper.h" +#include "bundle_mgr_interface.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "os_account_manager.h" +#include "system_ability_definition.h" #include "want_agent_helper.h" #include "reminder_request.h" @@ -159,6 +164,11 @@ void ReminderRequest::InitReminderId() ANSR_LOGI("reminderId_=%{public}d", reminderId_); } +void ReminderRequest::InitUserId(const int &userId) +{ + userId_ = userId; +} + bool ReminderRequest::IsExpired() const { return isExpired_; @@ -869,7 +879,7 @@ uint64_t ReminderRequest::GetNowInstantMilli() const ANSR_LOGE("Get now time error"); return 0; } - return static_cast(now * MILLI_SECONDS); + return static_cast(now) * MILLI_SECONDS; } std::string ReminderRequest::GetShowTime(const uint64_t showTime) const @@ -978,7 +988,7 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze) nullptr ); std::shared_ptr buttonWantAgent = - WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo); + WantAgent::WantAgentHelper::GetWantAgent(buttonWantAgentInfo, userId_); std::shared_ptr actionButton = NotificationActionButton::Create(nullptr, title, buttonWantAgent); notificationRequest_->AddActionButton(actionButton); @@ -1002,7 +1012,8 @@ void ReminderRequest::AddRemovalWantAgent() wants, nullptr ); - std::shared_ptr wantAgent = WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); + std::shared_ptr wantAgent + = WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); notificationRequest_->SetRemovalWantAgent(wantAgent); } @@ -1022,7 +1033,7 @@ std::shared_ptr ReminderRequest::CreateWantAgent(AppExecFw wants, nullptr ); - return WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); + return WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); } void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element) @@ -1104,7 +1115,7 @@ void ReminderRequest::UpdateNotificationCommon() } time_t now; (void)time(&now); // unit is seconds. - notificationRequest_->SetDeliveryTime(static_cast(now * MILLI_SECONDS)); + notificationRequest_->SetDeliveryTime(static_cast(now) * MILLI_SECONDS); } void ReminderRequest::UpdateNotificationContent(const bool &setSnooze) @@ -1180,5 +1191,24 @@ int ReminderRequest::GetCTime(const TimeTransferType &type, int actualTime) return -1; } } + +int32_t ReminderRequest::GetUid(const int &userId, const std::string &bundleName) +{ + AppExecFwk::ApplicationInfo info; + sptr systemAbilityManager + = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + sptr bundleMgr = iface_cast(remoteObject); + bundleMgr->GetApplicationInfo(bundleName, AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, + static_cast(userId), info); + return static_cast(info.uid); +} + +int ReminderRequest::GetUserId(const int &uid) +{ + int userId = -1; + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); + return userId; +} } } 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 3e76090e706690195f1f7761f6000140930a34e9..d658d162c17953ac065308dc2d28117d07eab81a 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp @@ -34,9 +34,10 @@ public: }; /** - * @tc.number : initHour_00100 - * @tc.name : - * @tc.desc : set hour < 0 should throw exception. + * @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) { @@ -50,9 +51,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00100, Function | SmallTest | Level1 } /** - * @tc.number : initHour_00200 - * @tc.name : - * @tc.desc : set hour > 23 should 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) { @@ -66,9 +68,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00200, Function | SmallTest | Level1 } /** - * @tc.number : initHour_00300 - * @tc.name : - * @tc.desc : test set edge value of hour (0 and 23). + * @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) { @@ -90,9 +93,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00300, Function | SmallTest | Level1 } /** - * @tc.number : initHour_00400 - * @tc.name : - * @tc.desc : set minute < 0 should throw exception. + * @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) { @@ -106,9 +110,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00400, Function | SmallTest | Level1 } /** - * @tc.number : initHour_00500 - * @tc.name : - * @tc.desc : set minute > 59 should 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) { @@ -122,9 +127,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00500, Function | SmallTest | Level1 } /** - * @tc.number : initHour_00600 - * @tc.name : - * @tc.desc : test set edge value of minute (0 and 59). + * @tc.name: initHour_00600 + * @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) { @@ -137,9 +143,10 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00600, Function | SmallTest | Level1 } /** - * @tc.number : initDaysOfWeek_00100 - * @tc.name : - * @tc.desc : test set daysOfWeek with normal value. + * @tc.name: initDaysOfWeek_00100 + * @tc.desc: test set daysOfWeek with normal value. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00100, Function | SmallTest | Level1) { @@ -151,9 +158,10 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00100, Function | SmallTest | } /** - * @tc.number : initDaysOfWeek_00200 - * @tc.name : - * @tc.desc : test set daysOfWeek with edge value. + * @tc.name: initDaysOfWeek_00200 + * @tc.desc: test set daysOfWeek with edge value. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00200, Function | SmallTest | Level1) { @@ -164,9 +172,10 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00200, Function | SmallTest | } /** - * @tc.number : initDaysOfWeek_00300 - * @tc.name : - * @tc.desc : test set daysOfWeek with duplicate value. + * @tc.name: initDaysOfWeek_00300 + * @tc.desc: test set daysOfWeek with duplicate value. + * @tc.type: FUNC + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00300, Function | SmallTest | Level1) { @@ -177,9 +186,10 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00300, Function | SmallTest | } /** - * @tc.number : initDaysOfWeek_00400 - * @tc.name : - * @tc.desc : test set daysOfWeek exceeding maximum length. + * @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) { @@ -194,9 +204,10 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00400, Function | SmallTest | } /** - * @tc.number : initDaysOfWeek_00500 - * @tc.name : - * @tc.desc : test set daysOfWeek with null value. + * @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) { 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 77c61bb7ba59033d1aa27656536fb02033418a4e..f7bc5ed5cb3f750452100c1b20dfeaaddeff48a4 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp @@ -79,9 +79,10 @@ public: }; /** - * @tc.number : initDateTime_00100 - * @tc.name : - * @tc.desc : Check firstDesignateYear set successfully. + * @tc.name: initDateTime_00100 + * @tc.desc: Check firstDesignateYear set successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00100, Function | SmallTest | Level1) { @@ -95,9 +96,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00100, Function | SmallTest | } /** - * @tc.number : initDateTime_00200 - * @tc.name : - * @tc.desc : Check firstDesignateMonth set successfully. + * @tc.name: initDateTime_00200 + * @tc.desc: Check firstDesignateMonth set successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00200, Function | SmallTest | Level1) { @@ -111,9 +113,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00200, Function | SmallTest | } /** - * @tc.number : initDateTime_00300 - * @tc.name : - * @tc.desc : Check firstDesignateDay set successfully. + * @tc.name: initDateTime_00300 + * @tc.desc: Check firstDesignateDay set successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00300, Function | SmallTest | Level1) { @@ -127,9 +130,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00300, Function | SmallTest | } /** - * @tc.number : initDateTime_00400 - * @tc.name : - * @tc.desc : Check repeatMonth set with normal value successfully. + * @tc.name: initDateTime_00400 + * @tc.desc: Check repeatMonth set with normal value successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00400, Function | SmallTest | Level1) { @@ -168,9 +172,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00400, Function | SmallTest | } /** - * @tc.number : initDateTime_00500 - * @tc.name : - * @tc.desc : Check repeatMonth set with exception value successfully. + * @tc.name: initDateTime_00500 + * @tc.desc: Check repeatMonth set with exception value successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00500, Function | SmallTest | Level1) { @@ -209,9 +214,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00500, Function | SmallTest | } /** - * @tc.number : initDateTime_00600 - * @tc.name : - * @tc.desc : Check repeatDay set with nomal value successfully. + * @tc.name: initDateTime_00600 + * @tc.desc: Check repeatDay set with nomal value successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00600, Function | SmallTest | Level1) { @@ -249,9 +255,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00600, Function | SmallTest | } /** - * @tc.number : initDateTime_00700 - * @tc.name : - * @tc.desc : Check repeatDay set with exception value successfully. + * @tc.name: initDateTime_00700 + * @tc.desc: Check repeatDay set with exception value successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00700, Function | SmallTest | Level1) { @@ -291,9 +298,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00700, Function | SmallTest | } /** - * @tc.number : initDateTime_00800 - * @tc.name : - * @tc.desc : Check hour set successfully. + * @tc.name: initDateTime_00800 + * @tc.desc: Check hour set successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00800, Function | SmallTest | Level1) { @@ -306,9 +314,10 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00800, Function | SmallTest | } /** - * @tc.number : initDateTime_00900 - * @tc.name : - * @tc.desc : Check minut set successfully. + * @tc.name: initDateTime_00900 + * @tc.desc: Check minut set successfully. + * @tc.type: FUNC + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00900, Function | SmallTest | Level1) { diff --git a/frameworks/ans/native/test/unittest/reminder_request_test.cpp b/frameworks/ans/native/test/unittest/reminder_request_test.cpp index 1f189e9f55060ad7f53a7217e90b21a0d43b694d..7788b8fc78700801aa4bf6b9473e32b3811a655d 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_test.cpp @@ -38,9 +38,10 @@ public: const uint8_t ReminderRequestTest::REMINDER_STATUS_SHOWING = 4; /** - * @tc.number : CanRemove_00100 - * @tc.name : - * @tc.desc : When reminder init, CanRemove should return true. + * @tc.name: CanRemove_00100 + * @tc.desc: When reminder init, CanRemove should return true. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00100, Function | SmallTest | Level1) { @@ -49,9 +50,10 @@ HWTEST_F(ReminderRequestTest, CanRemove_00100, Function | SmallTest | Level1) } /** - * @tc.number : CanRemove_00200 - * @tc.name : - * @tc.desc : When reminder is shown, CanRemove should return false. + * @tc.name: CanRemove_00200 + * @tc.desc: When reminder is shown, CanRemove should return false. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00200, Function | SmallTest | Level1) { @@ -61,9 +63,10 @@ HWTEST_F(ReminderRequestTest, CanRemove_00200, Function | SmallTest | Level1) } /** - * @tc.number : CanRemove_00300 - * @tc.name : - * @tc.desc : When reminder close, CanRemove should return true. + * @tc.name: CanRemove_00300 + * @tc.desc: When reminder close, CanRemove should return true. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00300, Function | SmallTest | Level1) { @@ -74,9 +77,10 @@ HWTEST_F(ReminderRequestTest, CanRemove_00300, Function | SmallTest | Level1) } /** - * @tc.number : CanRemove_00400 - * @tc.name : - * @tc.desc : When reminder is covered as same notification id, CanRemove should return true. + * @tc.name: CanRemove_00400 + * @tc.desc: When reminder is covered as same notification id, CanRemove should return true. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, CanRemove_00400, Function | SmallTest | Level1) { @@ -88,9 +92,10 @@ HWTEST_F(ReminderRequestTest, CanRemove_00400, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00100 - * @tc.name : - * @tc.desc : When reminder init, state should be 0. + * @tc.name: StateCheck_00100 + * @tc.desc: When reminder init, state should be 0. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00100, Function | SmallTest | Level1) { @@ -99,9 +104,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00100, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00200 - * @tc.name : - * @tc.desc : When reminder close with param true, state REMINDER_STATUS_SHOWING should be unset. + * @tc.name: StateCheck_00200 + * @tc.desc: When reminder close with param true, state REMINDER_STATUS_SHOWING should be unset. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00200, Function | SmallTest | Level1) { @@ -111,9 +117,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00200, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00300 - * @tc.name : - * @tc.desc : When reminder close with param false, state REMINDER_STATUS_SHOWING should be unset. + * @tc.name: StateCheck_00300 + * @tc.desc: When reminder close with param false, state REMINDER_STATUS_SHOWING should be unset. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00300, Function | SmallTest | Level1) { @@ -123,9 +130,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00300, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00400 - * @tc.name : - * @tc.desc : When reminder is covered as same notification id, state REMINDER_STATUS_SHOWING should be unset. + * @tc.name: StateCheck_00400 + * @tc.desc: When reminder is covered as same notification id, state REMINDER_STATUS_SHOWING should be unset. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, StateCheck_00400, Function | SmallTest | Level1) { @@ -135,9 +143,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00400, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00500 - * @tc.name : - * @tc.desc : When reminder is shown with param true,true, state REMINDER_STATUS_SHOWING should be set. + * @tc.name: StateCheck_00500 + * @tc.desc: When reminder is shown with param true,true, state REMINDER_STATUS_SHOWING should be set. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00500, Function | SmallTest | Level1) { @@ -147,9 +156,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00500, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00600 - * @tc.name : - * @tc.desc : When reminder is shown with param false,true, state REMINDER_STATUS_SHOWING should be set. + * @tc.name: StateCheck_00600 + * @tc.desc: When reminder is shown with param false,true, state REMINDER_STATUS_SHOWING should be set. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00600, Function | SmallTest | Level1) { @@ -159,9 +169,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00600, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00700 - * @tc.name : - * @tc.desc : When reminder is shown with param true,false, state REMINDER_STATUS_SHOWING should not change. + * @tc.name: StateCheck_00700 + * @tc.desc: When reminder is shown with param true,false, state REMINDER_STATUS_SHOWING should not change. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00700, Function | SmallTest | Level1) { @@ -172,9 +183,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00700, Function | SmallTest | Level1) } /** - * @tc.number : StateCheck_00800 - * @tc.name : - * @tc.desc : When reminder is shown with param false,false, state REMINDER_STATUS_SHOWING should be unset. + * @tc.name: StateCheck_00800 + * @tc.desc: When reminder is shown with param false,false, state REMINDER_STATUS_SHOWING should be unset. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00800, Function | SmallTest | Level1) { @@ -185,9 +197,10 @@ HWTEST_F(ReminderRequestTest, StateCheck_00800, Function | SmallTest | Level1) } /** - * @tc.number : initReminderId_00100 - * @tc.name : - * @tc.desc : When reminder create successfully, system should assign unique id to reminder. + * @tc.name: initReminderId_00100 + * @tc.desc: When reminder create successfully, system should assign unique id to reminder. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, initReminderId_00100, Function | SmallTest | Level1) { @@ -200,9 +213,10 @@ HWTEST_F(ReminderRequestTest, initReminderId_00100, Function | SmallTest | Level } /** - * @tc.number : setContent_00100 - * @tc.name : - * @tc.desc : Test SetContent with normal parameters. + * @tc.name: setContent_00100 + * @tc.desc: Test SetContent with normal parameters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setContent_00100, Function | SmallTest | Level1) { @@ -213,9 +227,10 @@ HWTEST_F(ReminderRequestTest, setContent_00100, Function | SmallTest | Level1) } /** - * @tc.number : setContent_00200 - * @tc.name : - * @tc.desc : Test SetContent parameters with special characters. + * @tc.name: setContent_00200 + * @tc.desc: Test SetContent parameters with special characters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setContent_00200, Function | SmallTest | Level1) { @@ -226,9 +241,10 @@ HWTEST_F(ReminderRequestTest, setContent_00200, Function | SmallTest | Level1) } /** - * @tc.number : setExpiredContent_00100 - * @tc.name : - * @tc.desc : Test SetExpiredContent with normal parameters. + * @tc.name: setExpiredContent_00100 + * @tc.desc: Test SetExpiredContent with normal parameters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF AR000GNF1U */ HWTEST_F(ReminderRequestTest, setExpiredContent_00100, Function | SmallTest | Level1) { @@ -239,9 +255,10 @@ HWTEST_F(ReminderRequestTest, setExpiredContent_00100, Function | SmallTest | Le } /** - * @tc.number : setExpiredContent_00200 - * @tc.name : - * @tc.desc : Test SetExpiredContent with special characters. + * @tc.name: setExpiredContent_00200 + * @tc.desc: Test SetExpiredContent with special characters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF AR000GNF1U */ HWTEST_F(ReminderRequestTest, setExpiredContent_00200, Function | SmallTest | Level1) { @@ -252,9 +269,10 @@ HWTEST_F(ReminderRequestTest, setExpiredContent_00200, Function | SmallTest | Le } /** - * @tc.number : setTitle_00100 - * @tc.name : - * @tc.desc : Test SetTitle with normal parameters. + * @tc.name: setTitle_00100 + * @tc.desc: Test SetTitle with normal parameters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setTitle_00100, Function | SmallTest | Level1) { @@ -265,9 +283,10 @@ HWTEST_F(ReminderRequestTest, setTitle_00100, Function | SmallTest | Level1) } /** - * @tc.number : setTitle_00200 - * @tc.name : - * @tc.desc : Test SetTitle with special characters. + * @tc.name: setTitle_00200 + * @tc.desc: Test SetTitle with special characters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setTitle_00200, Function | SmallTest | Level1) { @@ -278,9 +297,10 @@ HWTEST_F(ReminderRequestTest, setTitle_00200, Function | SmallTest | Level1) } /** - * @tc.number : setNotificationId_00100 - * @tc.name : - * @tc.desc : Test SetNotificationId parameters. + * @tc.name: setNotificationId_00100 + * @tc.desc: Test SetNotificationId parameters. + * @tc.type: FUNC + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setNotificationId_00100, Function | SmallTest | Level1) { @@ -289,5 +309,44 @@ HWTEST_F(ReminderRequestTest, setNotificationId_00100, Function | SmallTest | Le rrc->SetNotificationId(notificationId); EXPECT_EQ(rrc->GetNotificationId(), notificationId); } + +/** + * @tc.name: setSnoozeTimes_00100 + * @tc.desc: Test SetSnoozeTimes parameters. + * @tc.type: FUNC + * @tc.require: AR000GNF1T + */ +HWTEST_F(ReminderRequestTest, setSnoozeTimes_00100, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + rrc->SetSnoozeTimes(1); + EXPECT_EQ(rrc->GetSnoozeTimes(), 1) << "Get snoozeTimes not 1"; + EXPECT_EQ(rrc->GetSnoozeTimesDynamic(), 1) << "Get snoozeTimesDynamic not 1"; +} + +/** + * @tc.name: setTimeInterval_00100 + * @tc.desc: Test SetTimeInterval parameters. + * @tc.type: FUNC + * @tc.require: AR000GNF1T + */ +HWTEST_F(ReminderRequestTest, setTimeInterval_00100, Function | SmallTest | Level1) +{ + uint32_t minTimeIntervalInSecond = 5 * 60; + auto rrc = std::make_shared(); + rrc->SetTimeInterval(-1); + EXPECT_EQ(rrc->GetTimeInterval(), 0) << "timeInterval should be 0 when set with value less than 0"; + rrc->SetTimeInterval(0); + EXPECT_EQ(rrc->GetTimeInterval(), 0) << "timeInterval should be 0 when set with value 0"; + rrc->SetTimeInterval(1); + EXPECT_EQ(rrc->GetTimeInterval(), minTimeIntervalInSecond) + << "0 < timeInterval < minTimeInterval should be set to minTimeInterval"; + uint32_t timeInterval = minTimeIntervalInSecond; + rrc->SetTimeInterval(timeInterval); + EXPECT_EQ(rrc->GetTimeInterval(), timeInterval) << "timeInterval set error"; + timeInterval = minTimeIntervalInSecond + 1; + rrc->SetTimeInterval(timeInterval); + EXPECT_EQ(rrc->GetTimeInterval(), timeInterval) << "timeInterval set error."; +} } } \ No newline at end of file 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 6b39c09bf034b89774c8e488712ecabe947a06e2..852fbb84eb3c575668039f834d654362a0f6c267 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp @@ -37,9 +37,10 @@ public: }; /** - * @tc.number : initCountDownTime_00100 - * @tc.name : - * @tc.desc : set countDownTime = 0 should throw exception. + * @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) { @@ -53,9 +54,10 @@ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00100, Function | SmallTest } /** - * @tc.number : initCountDownTime_00200 - * @tc.name : - * @tc.desc : set countDownTime > (UINT64_MAX / 1000) should 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) { @@ -69,9 +71,10 @@ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00200, Function | SmallTest /** - * @tc.number : initCountDownTime_00300 - * @tc.name : - * @tc.desc : set countDownTime with normal value. + * @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) { diff --git a/frameworks/ans/test/moduletest/ReminderHelperTest.js b/frameworks/ans/test/moduletest/ReminderHelperTest.js index c61a047ec7d76b6643b13bf07e59379476698fd2..1b29bd76e39df871077f7fcc0d7f35d75b809817 100644 --- a/frameworks/ans/test/moduletest/ReminderHelperTest.js +++ b/frameworks/ans/test/moduletest/ReminderHelperTest.js @@ -52,7 +52,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper001 * @tc.desc: test publishReminder can return correct reminder id. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper001", 0, async function (done) { let timer = { @@ -82,7 +82,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper002 * @tc.desc: test publishReminder can return correct reminder id. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper002", 0, async function (done) { let timer = { @@ -104,7 +104,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper003 * @tc.desc: test addNotificationSlot instance with null * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EC */ it("testReminderHelper003", 0, async function (done) { function reminderCallback(err, data) { @@ -119,7 +119,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper004 * @tc.desc: test addNotificationSlot instance with null * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EC */ it("testReminderHelper004", 0, async function (done) { let mySlot = null; @@ -141,7 +141,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper005 * @tc.desc: test addNotificationSlot with normal value * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EC */ it("testReminderHelper005", 0, async function (done) { let mySlot = { @@ -158,7 +158,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper006 * @tc.desc: test addNotificationSlot with normal value * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EC */ it("testReminderHelper006", 0, async function (done) { reminderAgent.addNotificationSlot(3, (err, data) => { @@ -172,7 +172,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper007 * @tc.desc: test cancelAllReminders can cancel all exist reminders * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper007", 0, async function (done) { let timer = { @@ -205,7 +205,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper008 * @tc.desc: test cancelAllReminders can cancel all exist reminders * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper008", 0, async function (done) { let timer = { @@ -238,7 +238,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper009 * @tc.desc: test cancelReminder with not exit reminder. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper009", 0, async function (done) { let timer = { @@ -268,7 +268,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper010 * @tc.desc: test cancelReminder with not exit reminder. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper010", 0, async function (done) { let timer = { @@ -297,7 +297,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper011 * @tc.desc: test cancelReminder with exist reminder. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper011", 0, async function (done) { let alarm = { @@ -335,7 +335,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper012 * @tc.desc: test cancelReminder with exist reminder. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EA */ it("testReminderHelper012", 0, async function (done) { let alarm = { @@ -373,7 +373,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper013 * @tc.desc: test getValidReminders, verify all the information is correct. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EB */ it("testReminderHelper013", 0, async function (done) { var alarm = { @@ -403,7 +403,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper014 * @tc.desc: test getValidReminders, verify all the information is correct. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EB */ it("testReminderHelper014", 0, async function (done) { var alarm = { @@ -433,7 +433,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper015 * @tc.desc: test removeNotificationSlot with not exist slot. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8ED */ it("testReminderHelper015", 0, function (done) { function reminderCallback(err, data){ @@ -448,7 +448,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper016 * @tc.desc: test removeNotificationSlot with not exist slot. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8ED */ it("testReminderHelper016", 0, function (done) { let promise = new Promise((resolve, reject) => { @@ -469,7 +469,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper017 * @tc.desc: test removeNotificationSlot with exist slot. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8ED */ it("testReminderHelper017", 0, async function (done) { var tarRemoveSlot = { @@ -487,7 +487,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper018 * @tc.desc: test removeNotificationSlot with exist slot. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8ED */ it("testReminderHelper018", 0, async function (done) { var tarRemoveSlot = { @@ -506,7 +506,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper019 * @tc.desc: test getValidReminders. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EB AR000GH8EG */ it("testReminderHelper019", 0, async function (done) { let timer = { @@ -526,7 +526,7 @@ describe("ReminderHelperTest", function () { * @tc.name:testReminderHelper020 * @tc.desc: test getValidReminders. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8EB AR000GH8EG */ it("testReminderHelper020", 0, async function (done) { let timer = { @@ -546,7 +546,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper021 * @tc.desc: test publishReminder a normal alarm. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper021", 0, async function (done) { let alarm = { @@ -567,7 +567,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper022 * @tc.desc: test publishReminder a normal alarm. * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper022", 0, async function (done) { let alarm = { @@ -589,7 +589,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper023 * @tc.desc: test publishReminder * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper023", 0, function (done) { let calendar = { @@ -670,7 +670,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper024 * @tc.desc: test publishReminder * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper024", 0, async function (done) { let calendar = { @@ -751,7 +751,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper025 * @tc.desc: test publishReminder * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper025", 0, async function (done) { let calendar = { @@ -803,7 +803,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper026 * @tc.desc: test publishReminder * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper026", 0, async function (done) { let calendar = { @@ -855,7 +855,7 @@ describe("ReminderHelperTest", function () { * @tc.name: testReminderHelper027 * @tc.desc: test publishReminder (max number limit of each application) * @tc.type: FUNC - * @tc.require: + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper027", 0, async function (done) { let timer = { diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index b671414152b079807abe67523dae330629a23d0b..3f6fa49e391acfd0677df835ce0f9a8ffaaaa184 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -269,6 +269,17 @@ public: */ void InitReminderId(); + /** + * @brief Inits reminder userId when publish reminder success. + * + * When package remove, user id is sended by wantAgent, but we cannot get the uid according user id as the + * package has been removed, and the bundleOption can not be create with correct uid. so we need to record + * the user id, and use it to judge which user the reminder belong to. + * + * @param userId Indicates the userId which the reminder belong to. + */ + void InitUserId(const int &userId); + /** * @brief Check the reminder is alerting or not. * @@ -549,6 +560,8 @@ public: static const std::string PARAM_REMINDER_ID; static int GetActualTime(const TimeTransferType &type, int cTime); static int GetCTime(const TimeTransferType &type, int actualTime); + static int32_t GetUid(const int &userId, const std::string &bundleName); + static int GetUserId(const int &uid); protected: ReminderRequest(); @@ -611,6 +624,7 @@ private: uint8_t state_ {0}; int32_t notificationId_ {0}; int32_t reminderId_ {-1}; + int userId_ {-1}; // Indicates the reminder has been shown in the past time. // When the reminder has been created but not showed, it is equals to 0. diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index c1167f1bae653e2bd515541d724a8a7a20534df0..e1a781c15de69858b0a8387ac1acfed5a7f5f8c7 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -36,8 +36,11 @@ public: /** * @brief Cancels all the reminders relative to the bundle option. + * + * @param bundleOption Indicates the bundle option. + * @param userId Indicates the user id which the bundle belong to. */ - void CancelAllReminders(const sptr &bundleOption); + void CancelAllReminders(const sptr &bundleOption, int userId); /** * @brief Cancels the target reminder relative to the reminder id and bundle option. diff --git a/services/ans/include/reminder_event_manager.h b/services/ans/include/reminder_event_manager.h index 09c908f496c74cf9c9047e326fea8acf31cca3a0..35f46ba0ec2d26137aba6d19eed2ae3078bdbd8e 100644 --- a/services/ans/include/reminder_event_manager.h +++ b/services/ans/include/reminder_event_manager.h @@ -43,7 +43,6 @@ private: sptr GetBundleOption(const OHOS::EventFwk::Want &want) const; void HandlePackageRemove(OHOS::EventFwk::Want &want) const; void HandleProcessDied(OHOS::EventFwk::Want &want) const; - int32_t GetUid(const int userId, const std::string bundleName) const; std::shared_ptr reminderDataManager_ = nullptr; }; }; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 494a045a00f3617d0eaf48d1408bab7f3b269cbd..42255c75606b5e0e20954c0061f7b6ae32e0571f 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1627,7 +1627,9 @@ ErrCode AdvancedNotificationService::CancelAllReminders() if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; } - ReminderDataManager::GetInstance()->CancelAllReminders(bundleOption); + int userId = -1; + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); + ReminderDataManager::GetInstance()->CancelAllReminders(bundleOption, userId); return ERR_OK; } diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 18f09d8b6cf6f212a9dbc8c946d9a5a72b52838c..bde765f127c0822a23138ddba5db2d7080e1432b 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -54,6 +54,7 @@ void ReminderDataManager::CancelReminder( } if (activeReminderId_ == reminderId) { ANSR_LOGD("Cancel active reminder, id=%{public}d", reminderId); + activeReminder_->OnStop(); StopTimerLocked(TimerType::TRIGGER_TIMER); } if (alertingReminderId_ == reminderId) { @@ -117,15 +118,15 @@ bool ReminderDataManager::CheckReminderLimitExceededLocked(const std::string &bu return false; } -void ReminderDataManager::CancelAllReminders(const sptr &bundleOption) +void ReminderDataManager::CancelAllReminders(const sptr &bundleOption, int userId) { MUTEX.lock(); auto it = notificationBundleOptionMap_.find(activeReminderId_); - if (it == notificationBundleOptionMap_.end()) { - ANSR_LOGW("Not get bundle option, reminderId=%{public}d", activeReminderId_); - } else { + if (it != notificationBundleOptionMap_.end()) { if (it->second->GetBundleName() == bundleOption->GetBundleName()) { + activeReminder_->OnStop(); StopTimer(TimerType::TRIGGER_TIMER); + ANSR_LOGD("Stop active reminder, reminderId=%{public}d", activeReminderId_); } } for (auto vit = reminderVector_.begin(); vit != reminderVector_.end();) { @@ -137,10 +138,12 @@ void ReminderDataManager::CancelAllReminders(const sptrsecond->GetBundleName() == bundleOption->GetBundleName()) { + ANSR_LOGD("currently, userId is not supported. userId=%{public}d", userId); if ((*vit)->IsAlerting()) { StopAlertingReminder(*vit); } CancelNotification(*vit); + RemoveFromShowedReminders(*vit); ANSR_LOGD("Containers(vector/map) remove. reminderId=%{public}d", reminderId); vit = reminderVector_.erase(vit); notificationBundleOptionMap_.erase(mit); @@ -196,7 +199,11 @@ void ReminderDataManager::OnProcessDiedLocked(const sptrGetReminderId(); auto mit = notificationBundleOptionMap_.find(reminderId); if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGE("Get bundle option occur error, reminderId=%{public}d", reminderId); + ANSR_LOGD( + "Not get bundle option, the reminder may has been cancelled, reminderId=%{public}d", reminderId); + CancelNotification(*it); + showedReminderVector_.erase(it); + --it; continue; } if (mit->second->GetBundleName() != bundleName || mit->second->GetUid() != uid) { @@ -321,6 +328,7 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b int32_t reminderId = reminder->GetReminderId(); if (activeReminderId_ == reminderId) { ANSR_LOGD("Stop active reminder due to CloseReminder"); + activeReminder_->OnStop(); StopTimerLocked(TimerType::TRIGGER_TIMER); } if (alertingReminderId_ == reminderId) { @@ -350,6 +358,7 @@ void ReminderDataManager::RefreshRemindersDueToSysTimeChange(uint8_t type) ANSR_LOGI("Refresh all reminders due to %{public}s changed by user", typeInfo.c_str()); if (activeReminderId_ != -1) { ANSR_LOGD("Stop active reminder due to date/time or timeZone change"); + activeReminder_->OnStop(); StopTimerLocked(TimerType::TRIGGER_TIMER); } std::vector> showImmediately = RefreshRemindersLocked(type); @@ -407,6 +416,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( { std::lock_guard lock(ReminderDataManager::MUTEX); reminder->InitReminderId(); + reminder->InitUserId(ReminderRequest::GetUserId(bundleOption->GetUid())); int32_t reminderId = reminder->GetReminderId(); ANSR_LOGD("Containers(map) add. reminderId=%{public}d", reminderId); auto ret = notificationBundleOptionMap_.insert( @@ -567,6 +577,7 @@ void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) int32_t reminderId = reminder->GetReminderId(); if (activeReminderId_ == reminderId) { ANSR_LOGD("Cancel active reminder, id=%{public}d", activeReminderId_); + activeReminder_->OnStop(); StopTimerLocked(TimerType::TRIGGER_TIMER); } @@ -605,8 +616,8 @@ void ReminderDataManager::StartRecentReminder() return; } if (activeReminderId_ != -1) { - StopTimerLocked(TimerType::TRIGGER_TIMER); activeReminder_->OnStop(); + StopTimerLocked(TimerType::TRIGGER_TIMER); } ANSR_LOGI("Start recent reminder"); StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); @@ -694,12 +705,11 @@ sptr ReminderDataManager::GetRecentReminderLocked() } int32_t reminderId = (*it)->GetReminderId(); ANSR_LOGD("Containers(vector) remove. reminderId=%{public}d", reminderId); - auto mit = notificationBundleOptionMap_.find((*it)->GetReminderId()); + auto mit = notificationBundleOptionMap_.find(reminderId); if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGE("Remove notificationBundleOption(reminderId=%{public}d) fail", - (*it)->GetReminderId()); + ANSR_LOGE("Remove notificationBundleOption(reminderId=%{public}d) fail", reminderId); } else { - ANSR_LOGD("Containers(vector/map) remove. reminderId=%{public}d", reminderId); + ANSR_LOGD("Containers(map) remove. reminderId=%{public}d", reminderId); notificationBundleOptionMap_.erase(mit); } it = reminderVector_.erase(it); @@ -753,14 +763,12 @@ sptr ReminderDataManager::HandleRefreshReminder(uint8_t &type, } if (!needShowImmediately) { uint64_t triggerTimeAfter = reminder->GetTriggerTimeInMilli(); - if (triggerTimeBefore != triggerTimeAfter - || reminder->GetReminderId() == alertingReminderId_) { + if (triggerTimeBefore != triggerTimeAfter || reminder->GetReminderId() == alertingReminderId_) { CloseReminder(reminder, true); } return nullptr; - } else { - return reminder; } + return reminder; } void ReminderDataManager::HandleSameNotificationIdShowing(const sptr reminder) @@ -938,6 +946,10 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques sptr timer = MiscServices::TimeServiceClient::GetInstance(); time_t now; (void)time(&now); // unit is seconds. + if (now < 0) { + ANSR_LOGE("Get now time error"); + return; + } uint64_t triggerTime = 0; switch (type) { case TimerType::TRIGGER_TIMER: { @@ -957,7 +969,7 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques ANSR_LOGE("Alerting time out timer has already started."); break; } - triggerTime = now * ReminderRequest::MILLI_SECONDS + triggerTime = static_cast(now) * ReminderRequest::MILLI_SECONDS + static_cast(reminderRequest->GetRingDuration() * ReminderRequest::MILLI_SECONDS); timerIdAlerting_ = timer->CreateTimer(REMINDER_DATA_MANAGER->CreateTimerInfo(type)); timer->StartTimer(timerIdAlerting_, triggerTime); @@ -973,8 +985,9 @@ void ReminderDataManager::StartTimer(const sptr &reminderReques if (triggerTime == 0) { ANSR_LOGW("Start timer fail"); } else { - ANSR_LOGD("Timing info: now:(%{public}lld), tar:(%{public}llu)", - (long long)(now * ReminderRequest::MILLI_SECONDS), (unsigned long long)(triggerTime)); + ANSR_LOGD("Timing info: now:(%{public}llu), tar:(%{public}llu)", + (unsigned long long)(static_cast(now) * ReminderRequest::MILLI_SECONDS), + (unsigned long long)(triggerTime)); } } diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index d085adff048081db48272588c9c02c2fa3b4621d..f4f75ad54477296cbb38a21b0301079da73f71d2 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -19,9 +19,6 @@ #include "common_event_manager.h" #include "common_event_support.h" #include "bundle_constants.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" #include "reminder_event_manager.h" @@ -110,8 +107,11 @@ void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFw void ReminderEventManager::ReminderEventSubscriber::HandlePackageRemove(OHOS::EventFwk::Want &want) const { - sptr bundleOption = GetBundleOption(want); - reminderDataManager_->CancelAllReminders(bundleOption); + OHOS::AppExecFwk::ElementName ele = want.GetElement(); + std::string bundleName = ele.GetBundleName(); + int userId = want.GetIntParam(OHOS::AppExecFwk::Constants::USER_ID, -1); + sptr bundleOption = new NotificationBundleOption(bundleName, -1); + reminderDataManager_->CancelAllReminders(bundleOption, userId); } void ReminderEventManager::ReminderEventSubscriber::HandleProcessDied(OHOS::EventFwk::Want &want) const @@ -126,24 +126,10 @@ sptr ReminderEventManager::ReminderEventSubscriber::Ge OHOS::AppExecFwk::ElementName ele = want.GetElement(); std::string bundleName = ele.GetBundleName(); int userId = want.GetIntParam(OHOS::AppExecFwk::Constants::USER_ID, -1); - int32_t uid = GetUid(userId, bundleName); - ANSR_LOGD("bundleName=%{public}s, uid=%{public}d", bundleName.c_str(), uid); + int32_t uid = ReminderRequest::GetUid(userId, bundleName); + ANSR_LOGD("bundleName=%{public}s, userId=%{public}d, uid=%{public}d", bundleName.c_str(), userId, uid); sptr bundleOption = new NotificationBundleOption(bundleName, uid); return bundleOption; } - -int32_t ReminderEventManager::ReminderEventSubscriber::GetUid(const int userId, const std::string bundleName) const -{ - AppExecFwk::ApplicationInfo info; - OHOS::sptr systemAbilityManager - = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - OHOS::sptr remoteObject - = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - OHOS::sptr bundleMgr - = OHOS::iface_cast(remoteObject); - bundleMgr->GetApplicationInfo(bundleName, AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, - static_cast(userId), info); - return static_cast(info.uid); -} } // namespace OHOS } // namespace Notification