From 96fe4bb5d6daa0042720b4460339c3e0d24363b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=A4=A9=E6=80=A1?= Date: Sat, 8 Jul 2023 06:19:15 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BE=85=E6=9C=BAtimer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 朱天怡 --- bundle.json | 3 +- notification.gni | 6 ++++ services/ans/BUILD.gn | 5 +++ services/ans/src/reminder_data_manager.cpp | 41 ++++++++++++++++++++-- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/bundle.json b/bundle.json index 35ac7d426..1be53f3e2 100644 --- a/bundle.json +++ b/bundle.json @@ -79,7 +79,8 @@ "i18n", "device_manager", "kv_store", - "ffrt" + "ffrt", + "device_standby" ], "third_party": [ "libuv" diff --git a/notification.gni b/notification.gni index f2dafaa35..f2bf06c59 100644 --- a/notification.gni +++ b/notification.gni @@ -60,5 +60,11 @@ declare_args() { hisysevent_usage = false } + standby_enable = true + if (defined(global_parts_info) && + !defined(global_parts_info.resourceschedule_device_standby)) { + standby_enable = false + } + print("hisysevent_usage = " + "$hisysevent_usage") } diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index cf63b401a..1bd212c46 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -101,6 +101,11 @@ ohos_shared_library("libans") { cflags += [ "-DHAS_HISYSEVENT_PART" ] external_deps += [ "hisysevent:libhisysevent" ] } + + if (standby_enable) { + external_deps += ["device_standby:standby_innerkits"] + defines += ["DEVICE_STANDBY_ENABLE"] + } innerapi_tags = [ "platformsdk" ] subsystem_name = "${subsystem_name}" part_name = "${component_name}" diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 9fb3baaac..2afb0ca49 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -16,9 +16,14 @@ #include "reminder_data_manager.h" #include "ability_manager_client.h" +#include "access_token_helper.h" #include "ans_log_wrapper.h" #include "ans_const_define.h" #include "common_event_support.h" +#ifdef DEVICE_STANDBY_ENABLE +#include "standby_service_client.h" +#include "allow_type.h" +#endif #include "ipc_skeleton.h" #include "notification_slot.h" #include "os_account_manager.h" @@ -310,8 +315,6 @@ void ReminderDataManager::InitTimerInfo(std::shared_ptr &shar { uint8_t timerTypeWakeup = static_cast(sharedTimerInfo->TIMER_TYPE_WAKEUP); uint8_t timerTypeExact = static_cast(sharedTimerInfo->TIMER_TYPE_EXACT); - int32_t timerType = static_cast(timerTypeWakeup | timerTypeExact); - sharedTimerInfo->SetType(timerType); sharedTimerInfo->SetRepeat(false); sharedTimerInfo->SetInterval(0); @@ -323,6 +326,40 @@ void ReminderDataManager::InitTimerInfo(std::shared_ptr &shar } sharedTimerInfo->SetBundleName(mit->second->GetBundleName()); sharedTimerInfo->SetUid(mit->second->GetUid()); + + // The systemtimer type will be set TIMER_TYPE_INEXACT_REMINDER&&EXACT if reminder type is CALENDAR or TIMER, + // and set WAKEUP&&EXACT if ALARM. + int32_t timerType; + if (reminderRequest->GetReminderType() == ReminderRequest::ReminderType::CALENDAR || + reminderRequest->GetReminderType() == ReminderRequest::ReminderType::TIMER) { +#ifdef DEVICE_STANDBY_ENABLE + // Get allow list. + std::string name = mit->second->GetBundleName(); + std::vector allowInfoList; + DevStandbyMgr::StandbyServiceClient::GetInstance().GetAllowList(DevStandbyMgr::AllowType::TIMER, allowInfoList, 0); + auto it = std::find_if(allowInfoList.begin(), + allowInfoList.end(), + [name](const DevStandbyMgr::AllowInfo &allowInfo) { + return allowInfo.GetName() == name; + }); + if (AccessTokenHelper::IsSystemApp() || it != allowInfoList.end()) { + timerType = static_cast(timerTypeWakeup | timerTypeExact); + } else { + uint8_t timerTypeAns = static_cast(sharedTimerInfo->TIMER_TYPE_INEXACT_REMINDER); + timerType = static_cast(timerTypeAns | timerTypeExact); + } +#else + if (AccessTokenHelper::IsSystemApp()) { + timerType = static_cast(timerTypeWakeup | timerTypeExact); + } else { + uint8_t timerTypeAns = static_cast(sharedTimerInfo->TIMER_TYPE_INEXACT_REMINDER); + timerType = static_cast(timerTypeAns | timerTypeExact); + } +#endif + } else { + timerType = static_cast(timerTypeWakeup | timerTypeExact); + } + sharedTimerInfo->SetType(timerType); } std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerType type, -- Gitee From bc7cbfda0a7863a23208afd856f94f0dd1d77ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=A4=A9=E6=80=A1?= Date: Sun, 9 Jul 2023 08:49:36 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BE=85=E6=9C=BAtimer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 朱天怡 --- notification.gni | 4 ++-- services/ans/BUILD.gn | 4 ++-- services/ans/src/reminder_data_manager.cpp | 21 ++++++++++----------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/notification.gni b/notification.gni index f2bf06c59..d14421ff5 100644 --- a/notification.gni +++ b/notification.gni @@ -49,6 +49,7 @@ component_external_deps = [ declare_args() { device_usage = true hisysevent_usage = true + standby_enable = true if (defined(global_parts_info) && !defined(global_parts_info.resourceschedule_device_usage_statistics)) { @@ -60,10 +61,9 @@ declare_args() { hisysevent_usage = false } - standby_enable = true if (defined(global_parts_info) && !defined(global_parts_info.resourceschedule_device_standby)) { - standby_enable = false + standby_enable = false } print("hisysevent_usage = " + "$hisysevent_usage") diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 1bd212c46..32d3a272f 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -103,8 +103,8 @@ ohos_shared_library("libans") { } if (standby_enable) { - external_deps += ["device_standby:standby_innerkits"] - defines += ["DEVICE_STANDBY_ENABLE"] + external_deps += [ "device_standby:standby_innerkits" ] + defines += [ "DEVICE_STANDBY_ENABLE" ] } innerapi_tags = [ "platformsdk" ] subsystem_name = "${subsystem_name}" diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 2afb0ca49..37ee2418e 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -36,6 +36,9 @@ namespace Notification { namespace { const std::string ALL_PACKAGES = "allPackages"; const int32_t MAIN_USER_ID = 100; +#ifdef DEVICE_STANDBY_ENABLE +const int REASON_APP_API = 1; +#endif } /** @@ -336,12 +339,13 @@ void ReminderDataManager::InitTimerInfo(std::shared_ptr &shar // Get allow list. std::string name = mit->second->GetBundleName(); std::vector allowInfoList; - DevStandbyMgr::StandbyServiceClient::GetInstance().GetAllowList(DevStandbyMgr::AllowType::TIMER, allowInfoList, 0); + DevStandbyMgr::StandbyServiceClient::GetInstance().GetAllowList(DevStandbyMgr::AllowType::TIMER, + allowInfoList, REASON_APP_API); auto it = std::find_if(allowInfoList.begin(), - allowInfoList.end(), - [name](const DevStandbyMgr::AllowInfo &allowInfo) { - return allowInfo.GetName() == name; - }); + allowInfoList.end(), + [&name](const DevStandbyMgr::AllowInfo &allowInfo) { + return allowInfo.GetName() == name; + }); if (AccessTokenHelper::IsSystemApp() || it != allowInfoList.end()) { timerType = static_cast(timerTypeWakeup | timerTypeExact); } else { @@ -349,12 +353,7 @@ void ReminderDataManager::InitTimerInfo(std::shared_ptr &shar timerType = static_cast(timerTypeAns | timerTypeExact); } #else - if (AccessTokenHelper::IsSystemApp()) { - timerType = static_cast(timerTypeWakeup | timerTypeExact); - } else { - uint8_t timerTypeAns = static_cast(sharedTimerInfo->TIMER_TYPE_INEXACT_REMINDER); - timerType = static_cast(timerTypeAns | timerTypeExact); - } + timerType = static_cast(timerTypeWakeup | timerTypeExact); #endif } else { timerType = static_cast(timerTypeWakeup | timerTypeExact); -- Gitee