From 181100c7d6d160fdf046d70e17ee08328c9ae855 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 6 Nov 2023 09:54:23 +0800 Subject: [PATCH 01/11] New Requirements: Tap the button to notify the app Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 26 ++++++ .../test/unittest/reminder_request_test.cpp | 31 +++++++ .../napi/include/reminder/reminder_common.h | 1 + .../js/napi/src/reminder/reminder_common.cpp | 6 ++ interfaces/inner_api/reminder_request.h | 14 +++ services/ans/include/reminder_data_manager.h | 18 ++++ services/ans/src/reminder_data_manager.cpp | 85 +++++++++++++++++-- 7 files changed, 175 insertions(+), 6 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 6d8bc24a3..601189951 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -110,6 +110,7 @@ const std::string ReminderRequest::TAP_DISMISSED = "tapDismissed"; const std::string ReminderRequest::AUTO_DELETED_TIME = "autoDeletedTime"; const std::string ReminderRequest::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; const std::string ReminderRequest::GROUP_ID = "groupId"; +const std::string ReminderRequest::IS_NOTIFY_STATUS_CHANGED = "is_notify_status_changed"; std::string ReminderRequest::sqlOfAddColumns = ""; std::vector ReminderRequest::columns; @@ -259,6 +260,16 @@ void ReminderRequest::InitBundleName(const std::string &bundleName) bundleName_ = bundleName; } +void ReminderRequest::SetNotifyStatusChanged(const bool isNotifyStatusChanged) +{ + isNotifyStatusChanged_ = isNotifyStatusChanged; +} + +bool ReminderRequest::IsNotifyStatusChanged() +{ + return isNotifyStatusChanged_; +} + bool ReminderRequest::IsExpired() const { return isExpired_; @@ -606,6 +617,11 @@ void ReminderRequest::RecoverFromDb(const std::shared_ptr // customButtonUri resultSet->GetString(ReminderStore::GetColumnIndex(CUSTOM_BUTTON_URI), customButtonUri_); + + // isNotifyStatusChanged + std::string isNotifyStatusChanged; + resultSet->GetString(ReminderStore::GetColumnIndex(IS_NOTIFY_STATUS_CHANGED), isNotifyStatusChanged); + isNotifyStatusChanged_ = isNotifyStatusChanged == "true"; } void ReminderRequest::RecoverActionButton(const std::shared_ptr &resultSet) @@ -1096,6 +1112,10 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write tapDismissed"); return false; } + if (!parcel.WriteBool(isNotifyStatusChanged_)) { + ANSR_LOGE("Failed to write isNotifyStatusChanged"); + return false; + } // write int if (!parcel.WriteInt64(autoDeletedTime_)) { @@ -1278,6 +1298,10 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) ANSR_LOGE("Failed to read tapDismissed"); return false; } + if (!parcel.ReadBool(isNotifyStatusChanged_)) { + ANSR_LOGE("Failed to read isNotifyStatusChanged"); + return false; + } // read int if (!parcel.ReadInt64(autoDeletedTime_)) { @@ -1910,6 +1934,7 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, values.PutString(EXPIRED_CONTENT, reminder->GetExpiredContent()); values.PutInt(REPEAT_DAYS_OF_WEEK, reminder->GetRepeatDaysOfWeek()); values.PutString(GROUP_ID, reminder->GetGroupId()); + values.PutString(IS_NOTIFY_STATUS_CHANGED, reminder->IsNotifyStatusChanged() ? "true", "false"); auto wantAgentInfo = reminder->GetWantAgentInfo(); if (wantAgentInfo == nullptr) { std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null" + ReminderRequest::SEP_WANT_AGENT + "null"; @@ -1966,6 +1991,7 @@ void ReminderRequest::InitDbColumns() AddColumn(AUTO_DELETED_TIME, "BIGINT", false); AddColumn(REPEAT_DAYS_OF_WEEK, "INT", false); AddColumn(GROUP_ID, "TEXT", false); + AddColumn(IS_NOTIFY_STATUS_CHANGED, "TEXT", false); } void ReminderRequest::AddColumn( diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 4458d9bf5..8273d2f55 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1840,5 +1840,36 @@ HWTEST_F(ReminderRequestTest, SetGroupId_00001, Function | SmallTest | Level1) rrc->SetGroupId(groupId); EXPECT_EQ(rrc->GetGroupId(), groupId); } + +/** + * @tc.name: SetNotifyStatusChanged_00001 + * @tc.desc: Test SetNotifyStatusChanged + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ReminderRequestTest, SetNotifyStatusChanged_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + rrc->SetNotifyStatusChanged(false); + EXPECT_EQ(rrc->isNotifyStatusChanged_, false); + rrc->SetNotifyStatusChanged(true); + EXPECT_EQ(rrc->isNotifyStatusChanged_, true); +} + +/** + * @tc.name: IsNotifyStatusChanged_00001 + * @tc.desc: Test IsNotifyStatusChanged + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ReminderRequestTest, IsNotifyStatusChanged_00001, Function | SmallTest | Level1) +{ + auto rrc = std::make_shared(); + EXPECT_EQ(rrc->IsNotifyStatusChanged(), false); + rrc->SetNotifyStatusChanged(true); + EXPECT_EQ(rrc->IsNotifyStatusChanged(), true); + rrc->SetNotifyStatusChanged(false); + EXPECT_EQ(rrc->IsNotifyStatusChanged(), false); +} } } diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index ccfc39a21..c39f13cd4 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -72,6 +72,7 @@ const char* BUTTON_DATA_SHARE_UPDATE_VALUE = "value"; const char* TAPDISMISSED = "tapDismissed"; const char* AUTODELETEDTIME = "autoDeletedTime"; const char* GROUP_ID = "groupId"; +const char* IS_NOTIFY_STATUS = "notifyStatus"; const int INDEX_KEY = 0; const int INDEX_TYPE = 1; const int INDEX_VALUE = 2; diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 0351e0c74..1d76f0947 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -535,6 +535,12 @@ napi_value ReminderCommon::GenReminder( reminder->SetGroupId(std::string(str)); } + // isNotifyStatusChanged + bool isNotifyStatusChanged = false; + if (GetBool(env, value, ReminderAgentNapi::IS_NOTIFY_STATUS, isNotifyStatusChanged)) { + reminder->SetNotifyStatusChanged(isNotifyStatusChanged); + } + return NotificationNapi::Common::NapiGetNull(env); } diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 3d6e6c8af..ff44f6472 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -370,6 +370,16 @@ public: */ void InitBundleName(const std::string &bundleName); + /** + * + */ + void SetNotifyStatusChanged(const bool isNotifyStatusChanged); + + /** + * + */ + bool IsNotifyStatusChanged(); + /** * @brief Check the reminder is alerting or not. * @@ -788,6 +798,7 @@ public: static const std::string AUTO_DELETED_TIME; static const std::string REPEAT_DAYS_OF_WEEK; static const std::string GROUP_ID; + static const std::string IS_NOTIFY_STATUS_CHANGED; static std::string sqlOfAddColumns; static std::vector columns; @@ -919,6 +930,9 @@ private: std::shared_ptr wantAgentInfo_ = nullptr; std::shared_ptr maxScreenWantAgentInfo_ = nullptr; std::map actionButtonMap_ {}; + + // When the reminder action button is clicked, whether to notify the foreground app + bool isNotifyStatusChanged_ = false; }; } // namespace Reminder } // namespace OHOS diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 5fae70f7c..55d67f2cb 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -31,6 +31,7 @@ #include "reminder_config_change_observer.h" #include "datashare_predicates.h" #include "datashare_values_bucket.h" +#include "app_mgr_interface.h" namespace OHOS { namespace Notification { @@ -522,6 +523,17 @@ private: static bool cmp(sptr &reminderRequest, sptr &other); + /** + * + */ + bool ConnectAppMgr(); + + /** + * + */ + void CheckNeedNotifyStatus(const sptr &reminder, + const ReminderRequest::ActionButtonType buttonType); + /** * Single instance. */ @@ -603,6 +615,12 @@ private: * Indicates config change observer for language */ sptr configChangeObserver_ = nullptr; + + /** + * Indicates + */ + std::mutex appMgrMutex_; + sptr appMgrProxy_ = nullptr; }; } // namespace OHOS } // namespace Notification diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index e2c25de69..7b399f7b3 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -36,6 +36,9 @@ #include "datashare_value_object.h" #include "datashare_helper.h" #include "datashare_template.h" +#include "system_ability_definition.h" +#include "app_mgr_constants.h" +#include "iservice_registry.h" namespace OHOS { namespace Notification { @@ -501,19 +504,18 @@ void ReminderDataManager::CloseReminder(const OHOS::EventFwk::Want &want, bool c ANSR_LOGW("notificationRequest is not find, this reminder can`t close by groupId"); CloseReminder(reminder, cancelNotification); StartRecentReminder(); + CheckNeedNotifyStatus(reminder, ReminderRequest::ActionButtonType::CLOSE); return; } std::string bundleName = notificationRequest->GetCreatorBundleName(); std::string groupId = reminder->GetGroupId(); - if (groupId.empty()) { - ANSR_LOGD("default close reminder, the group id is not set."); - CloseReminder(reminder, cancelNotification); - StartRecentReminder(); - return; + if (!groupId.empty()) { + ANSR_LOGD("close reminder, the group id is set."); + CloseRemindersByGroupId(reminderId, bundleName, groupId); } - CloseRemindersByGroupId(reminderId, bundleName, groupId); CloseReminder(reminder, cancelNotification); StartRecentReminder(); + CheckNeedNotifyStatus(reminder, ReminderRequest::ActionButtonType::CLOSE); } void ReminderDataManager::CloseRemindersByGroupId(const int32_t &oldReminderId, const std::string &packageName, @@ -1031,6 +1033,7 @@ void ReminderDataManager::SnoozeReminder(const OHOS::EventFwk::Want &want) return; } SnoozeReminderImpl(reminder); + CheckNeedNotifyStatus(reminder, ReminderRequest::ActionButtonType::SNOOZE); } void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) @@ -1741,5 +1744,75 @@ void ReminderDataManager::OnConfigurationChanged(const AppExecFwk::Configuration UpdateReminderLanguage(*it); } } + +bool ReminderDataManager::ConnectAppMgr() +{ + if (appMgrProxy_ != nullptr) { + return true; + } + + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + ANSR_LOGE("get SystemAbilityManager failed"); + return false; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(APP_MGR_SERVICE_ID); + if (remoteObject == nullptr) { + ANSR_LOGE("get app manager service failed"); + return false; + } + + appMgrProxy_ = iface_cast(remoteObject); + if (!appMgrProxy_ || !appMgrProxy_->AsObject()) { + ANSR_LOGE("get app mgr proxy failed!"); + return false; + } + return true; +} + +void ReminderDataManager::CheckNeedNotifyStatus(const sptr &reminder, + const ReminderRequest::ActionButtonType buttonType) +{ + const std::string bundleName = reminder->GetBundleName(); + if (!reminder->IsNotifyStatusChanged() || bundleName.empty()) { + return; + } + // get foreground application + std::vector apps; + { + std::lock_guard lock(appMgrMutex_); + if (!ConnectAppMgr()) { + return; + } + if (appMgrProxy_->GetForegroundApplications(apps) != ERR_OK) { + ANS_LOGW("get foreground application failed"); + return; + } + } + // notify application + for (auto &eachApp : apps) { + if (eachApp.bundleName != bundleName) { + continue; + } + + EventFwk::Want want; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_REMINDER_STATUS_CHANGE); + EventFwk::CommonEventData eventData(want); + + std::string data; + data.append(std::to_string(static_cast(buttonType))).append(","); + data.append(std::to_string(reminder->GetReminderId())); + eventData.SetData(data); + + EventFwk::CommonEventPublishInfo info; + info.SetBundleName(bundleName); + if (EventFwk::CommonEventManager::PublishCommonEvent(eventData, info)) { + ANSR_LOGI("notify reminder status change %{public}s", bundleName.c_str()); + } + break; + } +} } } -- Gitee From 460631c7c0cca06f273cde6b811ad7fcf422cb8e Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 6 Nov 2023 15:04:14 +0800 Subject: [PATCH 02/11] update database and fix build bug Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 3 ++- frameworks/ans/src/reminder_store.cpp | 11 +++++++++-- .../ans/include/reminder_config_change_observer.h | 2 +- services/ans/src/reminder_config_change_observer.cpp | 2 +- services/ans/src/reminder_data_manager.cpp | 5 ++++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 601189951..57a0c25b4 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -149,6 +149,7 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) this->customButtonUri_ = other.customButtonUri_; this->repeatDaysOfWeek_ = other.repeatDaysOfWeek_; this->groupId_ = other.groupId_; + this->isNotifyStatusChanged_ = other.isNotifyStatusChanged_; } ReminderRequest::ReminderRequest(int32_t reminderId) @@ -1934,7 +1935,7 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, values.PutString(EXPIRED_CONTENT, reminder->GetExpiredContent()); values.PutInt(REPEAT_DAYS_OF_WEEK, reminder->GetRepeatDaysOfWeek()); values.PutString(GROUP_ID, reminder->GetGroupId()); - values.PutString(IS_NOTIFY_STATUS_CHANGED, reminder->IsNotifyStatusChanged() ? "true", "false"); + values.PutString(IS_NOTIFY_STATUS_CHANGED, reminder->IsNotifyStatusChanged() ? "true" : "false"); auto wantAgentInfo = reminder->GetWantAgentInfo(); if (wantAgentInfo == nullptr) { std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null" + ReminderRequest::SEP_WANT_AGENT + "null"; diff --git a/frameworks/ans/src/reminder_store.cpp b/frameworks/ans/src/reminder_store.cpp index ca636cebe..e02de41cc 100644 --- a/frameworks/ans/src/reminder_store.cpp +++ b/frameworks/ans/src/reminder_store.cpp @@ -32,7 +32,7 @@ namespace { const std::string REMINDER_DB_DIR = "/data/service/el1/public/notification/"; const std::string REMINDER_DB_NAME = "notification.db"; const std::string REMINDER_DB_TABLE = "reminder"; -const uint32_t REMINDER_RDB_VERSION = 2; +const uint32_t REMINDER_RDB_VERSION = 3; const int32_t STATE_FAIL = -1; std::vector columns; std::string g_sqlColumns; @@ -53,8 +53,15 @@ int32_t ReminderStore::ReminderStoreDataCallBack::OnUpgrade( NativeRdb::RdbStore &store, int32_t oldVersion, int32_t newVersion) { ANSR_LOGI("OnUpgrade oldVersion is %{public}d, newVersion is %{public}d", oldVersion, newVersion); - if (oldVersion < newVersion && newVersion == REMINDER_RDB_VERSION) { + constexpr int32_t reminderVersion1 = 1; + constexpr int32_t reminderVersion2 = 2; + if (oldVersion == reminderVersion1) { + // version 1 store.ExecuteSql("ALTER TABLE " + REMINDER_DB_TABLE + " ADD groupId TEXT DEFAULT '';"); + store.ExecuteSql("ALTER TABLE " + REMINDER_DB_TABLE + " ADD is_notify_status_changed TEXT DEFAULT '';"); + } else if (oldVersion == reminderVersion2) { + // version 2 + store.ExecuteSql("ALTER TABLE " + REMINDER_DB_TABLE + " ADD is_notify_status_changed TEXT DEFAULT '';"); } store.SetVersion(newVersion); return NativeRdb::E_OK; diff --git a/services/ans/include/reminder_config_change_observer.h b/services/ans/include/reminder_config_change_observer.h index 0495cf430..c0ba72285 100644 --- a/services/ans/include/reminder_config_change_observer.h +++ b/services/ans/include/reminder_config_change_observer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/ans/src/reminder_config_change_observer.cpp b/services/ans/src/reminder_config_change_observer.cpp index 5b68423c8..9208761bd 100644 --- a/services/ans/src/reminder_config_change_observer.cpp +++ b/services/ans/src/reminder_config_change_observer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 7b399f7b3..9baf573e8 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -20,6 +20,7 @@ #include "ans_log_wrapper.h" #include "ans_const_define.h" #include "common_event_support.h" +#include "common_event_manager.h" #ifdef DEVICE_STANDBY_ENABLE #include "standby_service_client.h" #include "allow_type.h" @@ -1798,7 +1799,9 @@ void ReminderDataManager::CheckNeedNotifyStatus(const sptr &rem } EventFwk::Want want; - want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_REMINDER_STATUS_CHANGE); + // common event not add COMMON_EVENT_REMINDER_STATUS_CHANGE, Temporary use of string + // want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_REMINDER_STATUS_CHANGE); + want.SetAction("usual.event.REMINDER_STATUS_CHANGE"); EventFwk::CommonEventData eventData(want); std::string data; -- Gitee From feb59745c07fc023f327069f2d945b6f241c1dc6 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 6 Nov 2023 15:45:45 +0800 Subject: [PATCH 03/11] update comments Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 2 +- frameworks/ans/test/unittest/reminder_request_test.cpp | 4 ++-- interfaces/inner_api/reminder_request.h | 6 ++++-- services/ans/include/reminder_data_manager.h | 7 ++++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index 57a0c25b4..d866e3bf5 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -266,7 +266,7 @@ void ReminderRequest::SetNotifyStatusChanged(const bool isNotifyStatusChanged) isNotifyStatusChanged_ = isNotifyStatusChanged; } -bool ReminderRequest::IsNotifyStatusChanged() +bool ReminderRequest::IsNotifyStatusChanged() const { return isNotifyStatusChanged_; } diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index 8273d2f55..f4d214902 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1845,7 +1845,7 @@ HWTEST_F(ReminderRequestTest, SetGroupId_00001, Function | SmallTest | Level1) * @tc.name: SetNotifyStatusChanged_00001 * @tc.desc: Test SetNotifyStatusChanged * @tc.type: FUNC - * @tc.require: + * @tc.require: issueI8E64Q */ HWTEST_F(ReminderRequestTest, SetNotifyStatusChanged_00001, Function | SmallTest | Level1) { @@ -1860,7 +1860,7 @@ HWTEST_F(ReminderRequestTest, SetNotifyStatusChanged_00001, Function | SmallTest * @tc.name: IsNotifyStatusChanged_00001 * @tc.desc: Test IsNotifyStatusChanged * @tc.type: FUNC - * @tc.require: + * @tc.require: issueI8E64Q */ HWTEST_F(ReminderRequestTest, IsNotifyStatusChanged_00001, Function | SmallTest | Level1) { diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index ff44f6472..d669a6c9b 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -371,14 +371,16 @@ public: void InitBundleName(const std::string &bundleName); /** - * + * @brief Set the notify status Flag. */ void SetNotifyStatusChanged(const bool isNotifyStatusChanged); /** + * @brief Check the reminder need to notify the application * + * @return true is the reminder need notify status. */ - bool IsNotifyStatusChanged(); + bool IsNotifyStatusChanged() const; /** * @brief Check the reminder is alerting or not. diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 55d67f2cb..5e99bf2a1 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -524,12 +524,17 @@ private: static bool cmp(sptr &reminderRequest, sptr &other); /** - * + * @brief Connect App Manager to get the current foreground application. */ bool ConnectAppMgr(); /** + * @brief Check need to notify the application, if the current foreground application + * is the creator of the reminder, notify the application of the reminder status + * change; otherwise, do not noitfy. * + * @param reminder Indicates a reminder. + * @param buttonType The type of button clicked by the user. */ void CheckNeedNotifyStatus(const sptr &reminder, const ReminderRequest::ActionButtonType buttonType); -- Gitee From 528f606630139f08f381cee7538a86d596c60370 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 6 Nov 2023 16:01:33 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20copyright=EF=BC=8C?= =?UTF-8?q?=E8=93=9D=E9=BB=84=E5=8C=BA=E6=A0=87=E5=87=86=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E6=A0=B7...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaojiaqi --- services/ans/include/reminder_config_change_observer.h | 2 +- services/ans/src/reminder_config_change_observer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/ans/include/reminder_config_change_observer.h b/services/ans/include/reminder_config_change_observer.h index c0ba72285..0495cf430 100644 --- a/services/ans/include/reminder_config_change_observer.h +++ b/services/ans/include/reminder_config_change_observer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/ans/src/reminder_config_change_observer.cpp b/services/ans/src/reminder_config_change_observer.cpp index 9208761bd..5b68423c8 100644 --- a/services/ans/src/reminder_config_change_observer.cpp +++ b/services/ans/src/reminder_config_change_observer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. + * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From b530eca8c461624e0b91d6b184d471618d8cd8cd Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 6 Nov 2023 19:55:39 +0800 Subject: [PATCH 05/11] update codecheck Signed-off-by: gaojiaqi --- frameworks/js/napi/include/reminder/reminder_common.h | 2 +- frameworks/js/napi/src/reminder/reminder_common.cpp | 2 +- services/ans/src/reminder_data_manager.cpp | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index c39f13cd4..6f634f96e 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -72,7 +72,7 @@ const char* BUTTON_DATA_SHARE_UPDATE_VALUE = "value"; const char* TAPDISMISSED = "tapDismissed"; const char* AUTODELETEDTIME = "autoDeletedTime"; const char* GROUP_ID = "groupId"; -const char* IS_NOTIFY_STATUS = "notifyStatus"; +const char* NEED_BROADCAST = "needBroadcast"; const int INDEX_KEY = 0; const int INDEX_TYPE = 1; const int INDEX_VALUE = 2; diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 1d76f0947..c2e9dbe83 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -537,7 +537,7 @@ napi_value ReminderCommon::GenReminder( // isNotifyStatusChanged bool isNotifyStatusChanged = false; - if (GetBool(env, value, ReminderAgentNapi::IS_NOTIFY_STATUS, isNotifyStatusChanged)) { + if (GetBool(env, value, ReminderAgentNapi::NEED_BROADCAST, isNotifyStatusChanged)) { reminder->SetNotifyStatusChanged(isNotifyStatusChanged); } diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 9baf573e8..adbe858ad 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1800,7 +1800,6 @@ void ReminderDataManager::CheckNeedNotifyStatus(const sptr &rem EventFwk::Want want; // common event not add COMMON_EVENT_REMINDER_STATUS_CHANGE, Temporary use of string - // want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_REMINDER_STATUS_CHANGE); want.SetAction("usual.event.REMINDER_STATUS_CHANGE"); EventFwk::CommonEventData eventData(want); -- Gitee From e78b08f4ea13ebcb2db23d1bea47888870f09f3c Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Mon, 6 Nov 2023 21:05:27 +0800 Subject: [PATCH 06/11] update publish.cpp Signed-off-by: gaojiaqi --- frameworks/js/napi/src/reminder/publish.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index d2fb6ea6d..82e12a45a 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -641,6 +641,8 @@ void ParseActionButtons(const napi_env &env, ReminderRequest &reminder, napi_val napi_set_named_property(env, actionButton, ACTION_BUTTON_TYPE, buttonInfo); napi_create_string_utf8(env, (it->second.title).c_str(), NAPI_AUTO_LENGTH, &buttonInfo); napi_set_named_property(env, actionButton, ACTION_BUTTON_TITLE, buttonInfo); + napi_create_string_utf8(env, (it->second.resource).c_str(), NAPI_AUTO_LENGTH, &buttonInfo); + napi_set_named_property(env, actionButton, ACTION_BUTTON_RESOURCE, buttonInfo); // create obj napi_value wantAgentInfo = nullptr; @@ -760,6 +762,10 @@ napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi napi_create_int32(env, static_cast(jsSlotType), &value); napi_set_named_property(env, result, SLOT_TYPE, value); + // needBroadcast + napi_get_boolean(env, reminder.IsNotifyStatusChanged(), &value); + napi_set_named_property(env, result, NEED_BROADCAST, value); + // wantAgent ParseWantAgent(env, reminder, result); -- Gitee From 3c3e66e9eaed6b13bb7245cab7e82ce82b045bb8 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Tue, 7 Nov 2023 17:21:10 +0800 Subject: [PATCH 07/11] remove isNotifyStatusChanged_ Signed-off-by: gaojiaqi --- frameworks/ans/src/reminder_request.cpp | 27 ---------------- frameworks/ans/src/reminder_store.cpp | 11 ++----- .../test/unittest/reminder_request_test.cpp | 31 ------------------- .../napi/include/reminder/reminder_common.h | 1 - frameworks/js/napi/src/reminder/publish.cpp | 4 --- .../js/napi/src/reminder/reminder_common.cpp | 6 ---- interfaces/inner_api/reminder_request.h | 16 ---------- services/ans/src/reminder_data_manager.cpp | 3 +- 8 files changed, 4 insertions(+), 95 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index d866e3bf5..6d8bc24a3 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -110,7 +110,6 @@ const std::string ReminderRequest::TAP_DISMISSED = "tapDismissed"; const std::string ReminderRequest::AUTO_DELETED_TIME = "autoDeletedTime"; const std::string ReminderRequest::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; const std::string ReminderRequest::GROUP_ID = "groupId"; -const std::string ReminderRequest::IS_NOTIFY_STATUS_CHANGED = "is_notify_status_changed"; std::string ReminderRequest::sqlOfAddColumns = ""; std::vector ReminderRequest::columns; @@ -149,7 +148,6 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) this->customButtonUri_ = other.customButtonUri_; this->repeatDaysOfWeek_ = other.repeatDaysOfWeek_; this->groupId_ = other.groupId_; - this->isNotifyStatusChanged_ = other.isNotifyStatusChanged_; } ReminderRequest::ReminderRequest(int32_t reminderId) @@ -261,16 +259,6 @@ void ReminderRequest::InitBundleName(const std::string &bundleName) bundleName_ = bundleName; } -void ReminderRequest::SetNotifyStatusChanged(const bool isNotifyStatusChanged) -{ - isNotifyStatusChanged_ = isNotifyStatusChanged; -} - -bool ReminderRequest::IsNotifyStatusChanged() const -{ - return isNotifyStatusChanged_; -} - bool ReminderRequest::IsExpired() const { return isExpired_; @@ -618,11 +606,6 @@ void ReminderRequest::RecoverFromDb(const std::shared_ptr // customButtonUri resultSet->GetString(ReminderStore::GetColumnIndex(CUSTOM_BUTTON_URI), customButtonUri_); - - // isNotifyStatusChanged - std::string isNotifyStatusChanged; - resultSet->GetString(ReminderStore::GetColumnIndex(IS_NOTIFY_STATUS_CHANGED), isNotifyStatusChanged); - isNotifyStatusChanged_ = isNotifyStatusChanged == "true"; } void ReminderRequest::RecoverActionButton(const std::shared_ptr &resultSet) @@ -1113,10 +1096,6 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const ANSR_LOGE("Failed to write tapDismissed"); return false; } - if (!parcel.WriteBool(isNotifyStatusChanged_)) { - ANSR_LOGE("Failed to write isNotifyStatusChanged"); - return false; - } // write int if (!parcel.WriteInt64(autoDeletedTime_)) { @@ -1299,10 +1278,6 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) ANSR_LOGE("Failed to read tapDismissed"); return false; } - if (!parcel.ReadBool(isNotifyStatusChanged_)) { - ANSR_LOGE("Failed to read isNotifyStatusChanged"); - return false; - } // read int if (!parcel.ReadInt64(autoDeletedTime_)) { @@ -1935,7 +1910,6 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, values.PutString(EXPIRED_CONTENT, reminder->GetExpiredContent()); values.PutInt(REPEAT_DAYS_OF_WEEK, reminder->GetRepeatDaysOfWeek()); values.PutString(GROUP_ID, reminder->GetGroupId()); - values.PutString(IS_NOTIFY_STATUS_CHANGED, reminder->IsNotifyStatusChanged() ? "true" : "false"); auto wantAgentInfo = reminder->GetWantAgentInfo(); if (wantAgentInfo == nullptr) { std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null" + ReminderRequest::SEP_WANT_AGENT + "null"; @@ -1992,7 +1966,6 @@ void ReminderRequest::InitDbColumns() AddColumn(AUTO_DELETED_TIME, "BIGINT", false); AddColumn(REPEAT_DAYS_OF_WEEK, "INT", false); AddColumn(GROUP_ID, "TEXT", false); - AddColumn(IS_NOTIFY_STATUS_CHANGED, "TEXT", false); } void ReminderRequest::AddColumn( diff --git a/frameworks/ans/src/reminder_store.cpp b/frameworks/ans/src/reminder_store.cpp index e02de41cc..ca636cebe 100644 --- a/frameworks/ans/src/reminder_store.cpp +++ b/frameworks/ans/src/reminder_store.cpp @@ -32,7 +32,7 @@ namespace { const std::string REMINDER_DB_DIR = "/data/service/el1/public/notification/"; const std::string REMINDER_DB_NAME = "notification.db"; const std::string REMINDER_DB_TABLE = "reminder"; -const uint32_t REMINDER_RDB_VERSION = 3; +const uint32_t REMINDER_RDB_VERSION = 2; const int32_t STATE_FAIL = -1; std::vector columns; std::string g_sqlColumns; @@ -53,15 +53,8 @@ int32_t ReminderStore::ReminderStoreDataCallBack::OnUpgrade( NativeRdb::RdbStore &store, int32_t oldVersion, int32_t newVersion) { ANSR_LOGI("OnUpgrade oldVersion is %{public}d, newVersion is %{public}d", oldVersion, newVersion); - constexpr int32_t reminderVersion1 = 1; - constexpr int32_t reminderVersion2 = 2; - if (oldVersion == reminderVersion1) { - // version 1 + if (oldVersion < newVersion && newVersion == REMINDER_RDB_VERSION) { store.ExecuteSql("ALTER TABLE " + REMINDER_DB_TABLE + " ADD groupId TEXT DEFAULT '';"); - store.ExecuteSql("ALTER TABLE " + REMINDER_DB_TABLE + " ADD is_notify_status_changed TEXT DEFAULT '';"); - } else if (oldVersion == reminderVersion2) { - // version 2 - store.ExecuteSql("ALTER TABLE " + REMINDER_DB_TABLE + " ADD is_notify_status_changed TEXT DEFAULT '';"); } store.SetVersion(newVersion); return NativeRdb::E_OK; diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/ans/test/unittest/reminder_request_test.cpp index f4d214902..4458d9bf5 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_test.cpp @@ -1840,36 +1840,5 @@ HWTEST_F(ReminderRequestTest, SetGroupId_00001, Function | SmallTest | Level1) rrc->SetGroupId(groupId); EXPECT_EQ(rrc->GetGroupId(), groupId); } - -/** - * @tc.name: SetNotifyStatusChanged_00001 - * @tc.desc: Test SetNotifyStatusChanged - * @tc.type: FUNC - * @tc.require: issueI8E64Q - */ -HWTEST_F(ReminderRequestTest, SetNotifyStatusChanged_00001, Function | SmallTest | Level1) -{ - auto rrc = std::make_shared(); - rrc->SetNotifyStatusChanged(false); - EXPECT_EQ(rrc->isNotifyStatusChanged_, false); - rrc->SetNotifyStatusChanged(true); - EXPECT_EQ(rrc->isNotifyStatusChanged_, true); -} - -/** - * @tc.name: IsNotifyStatusChanged_00001 - * @tc.desc: Test IsNotifyStatusChanged - * @tc.type: FUNC - * @tc.require: issueI8E64Q - */ -HWTEST_F(ReminderRequestTest, IsNotifyStatusChanged_00001, Function | SmallTest | Level1) -{ - auto rrc = std::make_shared(); - EXPECT_EQ(rrc->IsNotifyStatusChanged(), false); - rrc->SetNotifyStatusChanged(true); - EXPECT_EQ(rrc->IsNotifyStatusChanged(), true); - rrc->SetNotifyStatusChanged(false); - EXPECT_EQ(rrc->IsNotifyStatusChanged(), false); -} } } diff --git a/frameworks/js/napi/include/reminder/reminder_common.h b/frameworks/js/napi/include/reminder/reminder_common.h index 6f634f96e..ccfc39a21 100644 --- a/frameworks/js/napi/include/reminder/reminder_common.h +++ b/frameworks/js/napi/include/reminder/reminder_common.h @@ -72,7 +72,6 @@ const char* BUTTON_DATA_SHARE_UPDATE_VALUE = "value"; const char* TAPDISMISSED = "tapDismissed"; const char* AUTODELETEDTIME = "autoDeletedTime"; const char* GROUP_ID = "groupId"; -const char* NEED_BROADCAST = "needBroadcast"; const int INDEX_KEY = 0; const int INDEX_TYPE = 1; const int INDEX_VALUE = 2; diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index 82e12a45a..a6e847a29 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -762,10 +762,6 @@ napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi napi_create_int32(env, static_cast(jsSlotType), &value); napi_set_named_property(env, result, SLOT_TYPE, value); - // needBroadcast - napi_get_boolean(env, reminder.IsNotifyStatusChanged(), &value); - napi_set_named_property(env, result, NEED_BROADCAST, value); - // wantAgent ParseWantAgent(env, reminder, result); diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index c2e9dbe83..0351e0c74 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -535,12 +535,6 @@ napi_value ReminderCommon::GenReminder( reminder->SetGroupId(std::string(str)); } - // isNotifyStatusChanged - bool isNotifyStatusChanged = false; - if (GetBool(env, value, ReminderAgentNapi::NEED_BROADCAST, isNotifyStatusChanged)) { - reminder->SetNotifyStatusChanged(isNotifyStatusChanged); - } - return NotificationNapi::Common::NapiGetNull(env); } diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index d669a6c9b..3d6e6c8af 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -370,18 +370,6 @@ public: */ void InitBundleName(const std::string &bundleName); - /** - * @brief Set the notify status Flag. - */ - void SetNotifyStatusChanged(const bool isNotifyStatusChanged); - - /** - * @brief Check the reminder need to notify the application - * - * @return true is the reminder need notify status. - */ - bool IsNotifyStatusChanged() const; - /** * @brief Check the reminder is alerting or not. * @@ -800,7 +788,6 @@ public: static const std::string AUTO_DELETED_TIME; static const std::string REPEAT_DAYS_OF_WEEK; static const std::string GROUP_ID; - static const std::string IS_NOTIFY_STATUS_CHANGED; static std::string sqlOfAddColumns; static std::vector columns; @@ -932,9 +919,6 @@ private: std::shared_ptr wantAgentInfo_ = nullptr; std::shared_ptr maxScreenWantAgentInfo_ = nullptr; std::map actionButtonMap_ {}; - - // When the reminder action button is clicked, whether to notify the foreground app - bool isNotifyStatusChanged_ = false; }; } // namespace Reminder } // namespace OHOS diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index adbe858ad..e058d93f5 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1777,7 +1777,8 @@ void ReminderDataManager::CheckNeedNotifyStatus(const sptr &rem const ReminderRequest::ActionButtonType buttonType) { const std::string bundleName = reminder->GetBundleName(); - if (!reminder->IsNotifyStatusChanged() || bundleName.empty()) { + ANS_LOGI("notify bundleName is: %{public}s", bundleName.c_str()); + if (bundleName.empty()) { return; } // get foreground application -- Gitee From f87cd68d9c512f028db59fb60f57df1a7c86e586 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Tue, 7 Nov 2023 17:25:14 +0800 Subject: [PATCH 08/11] update comments Signed-off-by: gaojiaqi --- services/ans/include/reminder_data_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 5e99bf2a1..0e3d1b915 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -622,7 +622,7 @@ private: sptr configChangeObserver_ = nullptr; /** - * Indicates + * Indicates app mananger for get foreground application */ std::mutex appMgrMutex_; sptr appMgrProxy_ = nullptr; -- Gitee From bb1f769bc957c303ccd6d8ce4b14e1ef15f39531 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Wed, 8 Nov 2023 14:43:24 +0800 Subject: [PATCH 09/11] update log Signed-off-by: gaojiaqi --- services/ans/src/reminder_data_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index e058d93f5..410b5dc37 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1777,10 +1777,10 @@ void ReminderDataManager::CheckNeedNotifyStatus(const sptr &rem const ReminderRequest::ActionButtonType buttonType) { const std::string bundleName = reminder->GetBundleName(); - ANS_LOGI("notify bundleName is: %{public}s", bundleName.c_str()); if (bundleName.empty()) { return; } + ANS_LOGI("notify bundleName is: %{public}s", bundleName.c_str()); // get foreground application std::vector apps; { -- Gitee From 789def60eba1742a0b432335a23e07520b6855b7 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Fri, 10 Nov 2023 09:56:07 +0800 Subject: [PATCH 10/11] update event Signed-off-by: gaojiaqi --- services/ans/include/reminder_data_manager.h | 5 +++ services/ans/src/reminder_data_manager.cpp | 6 ++++ services/ans/src/reminder_event_manager.cpp | 35 +++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 0e3d1b915..0c08c0462 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -210,6 +210,11 @@ public: */ void OnConfigurationChanged(const AppExecFwk::Configuration &configuration); + /** + * @brief When OnRemoveSystemAbility occurs. + */ + void OnRemoveAppMgr(); + static const uint8_t TIME_ZONE_CHANGE; static const uint8_t DATE_TIME_CHANGE; diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 410b5dc37..b91ea9b2d 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -1746,6 +1746,12 @@ void ReminderDataManager::OnConfigurationChanged(const AppExecFwk::Configuration } } +void ReminderDataManager::OnRemoveAppMgr() +{ + std::lock_guard lock(appMgrMutex_); + appMgrProxy_ = nullptr; +} + bool ReminderDataManager::ConnectAppMgr() { if (appMgrProxy_ != nullptr) { diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index 8a8e6ebd0..aaa9f55eb 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -75,6 +75,14 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa ANSR_LOGE("Failed to create statusChangeListener due to no memory."); return; } + // app mgr + sptr appMgrStatusChangeListener + = new (std::nothrow) SystemAbilityStatusChangeListener(reminderDataManager); + if (appMgrStatusChangeListener == nullptr) { + ANSR_LOGE("Failed to create appMgrStatusChangeListener due to no memory."); + return; + } + sptr samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgrProxy == nullptr) { ANSR_LOGD("samgrProxy is null"); @@ -84,6 +92,10 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa if (ret != ERR_OK) { ANSR_LOGE("subscribe system ability id: %{public}d failed", BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); } + ret = samgrProxy->SubscribeSystemAbility(APP_MGR_SERVICE_ID, appMgrStatusChangeListener); + if (ret != ERR_OK) { + ANSR_LOGE("subscribe system ability id: %{public}d failed", APP_MGR_SERVICE_ID); + } } ReminderEventManager::ReminderEventSubscriber::ReminderEventSubscriber( @@ -213,13 +225,34 @@ void ReminderEventManager::SystemAbilityStatusChangeListener::OnAddSystemAbility int32_t systemAbilityId, const std::string& deviceId) { ANSR_LOGD("OnAddSystemAbilityInner"); - reminderDataManager_->OnServiceStart(); + switch(systemAbilityId) { + case BUNDLE_MGR_SERVICE_SYS_ABILITY_ID: + ANSR_LOGD("OnAddSystemAbilityInner: BUNDLE_MGR_SERVICE_SYS_ABILITY"); + reminderDataManager_->OnServiceStart(); + break; + case APP_MGR_SERVICE_ID: + ANSR_LOGD("OnAddSystemAbilityInner: APP_MGR_SERVICE"); + break; + default: + break; + } } void ReminderEventManager::SystemAbilityStatusChangeListener::OnRemoveSystemAbility( int32_t systemAbilityId, const std::string& deviceId) { ANSR_LOGD("OnRemoveSystemAbilityInner"); + switch(systemAbilityId) { + case BUNDLE_MGR_SERVICE_SYS_ABILITY_ID: + ANSR_LOGD("OnRemoveSystemAbilityInner: BUNDLE_MGR_SERVICE_SYS_ABILITY"); + break; + case APP_MGR_SERVICE_ID: + ANSR_LOGD("OnRemoveSystemAbilityInner: APP_MGR_SERVICE"); + reminderDataManager_->OnRemoveAppMgr(); + break; + default: + break; + } } } // namespace OHOS } // namespace Notification -- Gitee From 6ef9e0f45a7903935d0eeb9b446043abd218b3bf Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Fri, 10 Nov 2023 14:10:50 +0800 Subject: [PATCH 11/11] clean code Signed-off-by: gaojiaqi --- services/ans/src/reminder_event_manager.cpp | 40 ++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index aaa9f55eb..05988601a 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -225,16 +225,16 @@ void ReminderEventManager::SystemAbilityStatusChangeListener::OnAddSystemAbility int32_t systemAbilityId, const std::string& deviceId) { ANSR_LOGD("OnAddSystemAbilityInner"); - switch(systemAbilityId) { - case BUNDLE_MGR_SERVICE_SYS_ABILITY_ID: - ANSR_LOGD("OnAddSystemAbilityInner: BUNDLE_MGR_SERVICE_SYS_ABILITY"); - reminderDataManager_->OnServiceStart(); - break; - case APP_MGR_SERVICE_ID: - ANSR_LOGD("OnAddSystemAbilityInner: APP_MGR_SERVICE"); - break; - default: - break; + switch (systemAbilityId) { + case BUNDLE_MGR_SERVICE_SYS_ABILITY_ID: + ANSR_LOGD("OnAddSystemAbilityInner: BUNDLE_MGR_SERVICE_SYS_ABILITY"); + reminderDataManager_->OnServiceStart(); + break; + case APP_MGR_SERVICE_ID: + ANSR_LOGD("OnAddSystemAbilityInner: APP_MGR_SERVICE"); + break; + default: + break; } } @@ -242,16 +242,16 @@ void ReminderEventManager::SystemAbilityStatusChangeListener::OnRemoveSystemAbil int32_t systemAbilityId, const std::string& deviceId) { ANSR_LOGD("OnRemoveSystemAbilityInner"); - switch(systemAbilityId) { - case BUNDLE_MGR_SERVICE_SYS_ABILITY_ID: - ANSR_LOGD("OnRemoveSystemAbilityInner: BUNDLE_MGR_SERVICE_SYS_ABILITY"); - break; - case APP_MGR_SERVICE_ID: - ANSR_LOGD("OnRemoveSystemAbilityInner: APP_MGR_SERVICE"); - reminderDataManager_->OnRemoveAppMgr(); - break; - default: - break; + switch (systemAbilityId) { + case BUNDLE_MGR_SERVICE_SYS_ABILITY_ID: + ANSR_LOGD("OnRemoveSystemAbilityInner: BUNDLE_MGR_SERVICE_SYS_ABILITY"); + break; + case APP_MGR_SERVICE_ID: + ANSR_LOGD("OnRemoveSystemAbilityInner: APP_MGR_SERVICE"); + reminderDataManager_->OnRemoveAppMgr(); + break; + default: + break; } } } // namespace OHOS -- Gitee