From 4dbca7c695a8595cd9e541529cd70e7ca59552d1 Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Mon, 24 Jan 2022 10:32:31 +0800 Subject: [PATCH 01/18] trigger remove wantagent Signed-off-by: fangJinliang1 Change-Id: Ia638f3095e2811657c4b7c8d79c90f1bdbe26a30 --- services/ans/src/advanced_notification_service.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 484f975bc..eb2b4d0c7 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1141,6 +1141,10 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList( return ERR_ANS_NOTIFICATION_IS_UNREMOVABLE; } notification = record->notification; + // delete or delete all, call the function + if (!isCancel) { + TriggerRemoveWantAgent(record->request); + } notificationList_.remove(record); return ERR_OK; } -- Gitee From 9480da980e540c74cda7e2fdb594ea0b53d22585 Mon Sep 17 00:00:00 2001 From: 17764556280 Date: Mon, 24 Jan 2022 14:43:03 +0800 Subject: [PATCH 02/18] modify bms part name Signed-off-by: 17764556280 --- frameworks/ans/core/BUILD.gn | 2 +- frameworks/ans/native/test/unittest/BUILD.gn | 4 ++-- frameworks/ans/test/moduletest/BUILD.gn | 16 ++++++++-------- frameworks/wantagent/BUILD.gn | 4 ++-- .../unittest/completed_dispatcher_test/BUILD.gn | 4 ++-- .../test/unittest/pending_want_test/BUILD.gn | 4 ++-- .../test/unittest/trigger_Info_test/BUILD.gn | 4 ++-- .../unittest/want_agent_helper_test/BUILD.gn | 4 ++-- .../test/unittest/want_agent_info_test/BUILD.gn | 4 ++-- .../test/unittest/want_agent_test/BUILD.gn | 4 ++-- interfaces/kits/napi/ans/BUILD.gn | 2 +- interfaces/kits/napi/ans/src/reminder/BUILD.gn | 2 +- interfaces/kits/napi/wantagent/BUILD.gn | 4 ++-- services/ans/test/unittest/BUILD.gn | 4 ++-- services/distributed/test/unittest/BUILD.gn | 2 +- services/test/moduletest/BUILD.gn | 4 ++-- .../acts/actsnotificationfuzztest/BUILD.gn | 4 ++-- test/resource/ansSTSlotGroupTest/BUILD.gn | 4 ++-- test/systemtest/acts/ansDump/BUILD.gn | 2 +- 19 files changed, 39 insertions(+), 39 deletions(-) diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index 8bd4d57f7..c54d626ee 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -90,7 +90,7 @@ ohos_shared_library("ans_core") { external_deps = [ "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", + "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/frameworks/ans/native/test/unittest/BUILD.gn b/frameworks/ans/native/test/unittest/BUILD.gn index 4662527a8..3e6607f7f 100644 --- a/frameworks/ans/native/test/unittest/BUILD.gn +++ b/frameworks/ans/native/test/unittest/BUILD.gn @@ -48,8 +48,8 @@ ohos_unittest("ans_reminder_unit_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "bytrace_standard:bytrace_core", "ces_standard:cesfwk_innerkits", diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index 9c8579d91..c63aded83 100644 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -84,8 +84,8 @@ ohos_moduletest("ans_fw_module_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", @@ -162,8 +162,8 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", @@ -237,8 +237,8 @@ ohos_moduletest("ans_innerkits_module_slot_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", @@ -312,8 +312,8 @@ ohos_moduletest("ans_innerkits_module_setting_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", diff --git a/frameworks/wantagent/BUILD.gn b/frameworks/wantagent/BUILD.gn index ee4c79b1b..77fce1486 100644 --- a/frameworks/wantagent/BUILD.gn +++ b/frameworks/wantagent/BUILD.gn @@ -69,8 +69,8 @@ ohos_shared_library("wantagent_innerkits") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "hiviewdfx_hilog_native:libhilog", diff --git a/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn b/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn index 83587c2b9..99461bf49 100644 --- a/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn @@ -44,8 +44,8 @@ ohos_unittest("completed_dispatcher_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", diff --git a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn index 6e3099ab1..00ab12f1c 100644 --- a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn @@ -51,8 +51,8 @@ ohos_unittest("pending_want_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", diff --git a/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn b/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn index c1f05358a..9eae21754 100644 --- a/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn @@ -44,8 +44,8 @@ ohos_unittest("trigger_Info_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", diff --git a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn index 42ebaf1f4..2504a997e 100644 --- a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn @@ -48,8 +48,8 @@ ohos_unittest("want_agent_helper_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", diff --git a/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn index 7d29fdf0e..220eb405a 100644 --- a/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn @@ -44,8 +44,8 @@ ohos_unittest("want_agent_info_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", diff --git a/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn index c08997e88..ee966bd19 100644 --- a/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn @@ -44,8 +44,8 @@ ohos_unittest("want_agent_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", diff --git a/interfaces/kits/napi/ans/BUILD.gn b/interfaces/kits/napi/ans/BUILD.gn index 97c13373e..d13d88323 100644 --- a/interfaces/kits/napi/ans/BUILD.gn +++ b/interfaces/kits/napi/ans/BUILD.gn @@ -78,7 +78,7 @@ ohos_shared_library("notification") { "ability_runtime:abilitykit_native", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", + "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/interfaces/kits/napi/ans/src/reminder/BUILD.gn b/interfaces/kits/napi/ans/src/reminder/BUILD.gn index b51f48bb2..23107e158 100644 --- a/interfaces/kits/napi/ans/src/reminder/BUILD.gn +++ b/interfaces/kits/napi/ans/src/reminder/BUILD.gn @@ -66,7 +66,7 @@ ohos_shared_library("reminderagent") { external_deps = [ "ability_runtime:abilitykit_native", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", + "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/interfaces/kits/napi/wantagent/BUILD.gn b/interfaces/kits/napi/wantagent/BUILD.gn index c8671f52d..acbb9f039 100644 --- a/interfaces/kits/napi/wantagent/BUILD.gn +++ b/interfaces/kits/napi/wantagent/BUILD.gn @@ -45,8 +45,8 @@ ohos_shared_library("wantagent") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 46202d3d4..1eb54058a 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -78,8 +78,8 @@ ohos_unittest("ans_unit_test") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index 347c7abeb..934c13331 100644 --- a/services/distributed/test/unittest/BUILD.gn +++ b/services/distributed/test/unittest/BUILD.gn @@ -69,7 +69,7 @@ ohos_unittest("ans_distributed_unit_test") { external_deps = [ "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", + "bundle_framework:appexecfwk_base", "distributeddatamgr:distributeddata_inner", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index a3567518a..97c3b2f9f 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -65,8 +65,8 @@ ohos_moduletest("ans_module_test") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", diff --git a/test/common/acts/actsnotificationfuzztest/BUILD.gn b/test/common/acts/actsnotificationfuzztest/BUILD.gn index 218219a34..8ccce80c6 100644 --- a/test/common/acts/actsnotificationfuzztest/BUILD.gn +++ b/test/common/acts/actsnotificationfuzztest/BUILD.gn @@ -79,8 +79,8 @@ ohos_systemtest("ActsNotificationFuzzTest") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", diff --git a/test/resource/ansSTSlotGroupTest/BUILD.gn b/test/resource/ansSTSlotGroupTest/BUILD.gn index 2090014d3..ca4688dd1 100644 --- a/test/resource/ansSTSlotGroupTest/BUILD.gn +++ b/test/resource/ansSTSlotGroupTest/BUILD.gn @@ -59,8 +59,8 @@ ohos_shared_library("libraryAnsSTSlotGroupTest") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] diff --git a/test/systemtest/acts/ansDump/BUILD.gn b/test/systemtest/acts/ansDump/BUILD.gn index 1a039aab3..52a13ac51 100644 --- a/test/systemtest/acts/ansDump/BUILD.gn +++ b/test/systemtest/acts/ansDump/BUILD.gn @@ -42,7 +42,7 @@ ohos_systemtest("AnsDumpTest") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_core", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", -- Gitee From 935025287d2bf0babf03cf68db580e9efabd7c7d Mon Sep 17 00:00:00 2001 From: 17764556280 Date: Mon, 24 Jan 2022 15:06:18 +0800 Subject: [PATCH 03/18] modify bms part name Signed-off-by: 17764556280 --- notification.gni | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notification.gni b/notification.gni index 9901863fe..19196f346 100644 --- a/notification.gni +++ b/notification.gni @@ -32,8 +32,8 @@ aafwk_path = "//foundation/aafwk/standard" ans_standard_external_deps = [ "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "dmsfwk_standard:zuri", -- Gitee From 0875ef3851e4c3ad7fd8ae2685dd688bf7bb9c6c Mon Sep 17 00:00:00 2001 From: 17764556280 Date: Mon, 24 Jan 2022 15:15:46 +0800 Subject: [PATCH 04/18] modify bms part name Signed-off-by: 17764556280 --- frameworks/ans/native/test/unittest/BUILD.gn | 2 +- frameworks/ans/test/moduletest/BUILD.gn | 8 ++++---- frameworks/wantagent/BUILD.gn | 2 +- .../test/unittest/completed_dispatcher_test/BUILD.gn | 2 +- .../wantagent/test/unittest/pending_want_test/BUILD.gn | 2 +- .../wantagent/test/unittest/trigger_Info_test/BUILD.gn | 2 +- .../test/unittest/want_agent_helper_test/BUILD.gn | 2 +- .../wantagent/test/unittest/want_agent_info_test/BUILD.gn | 2 +- .../wantagent/test/unittest/want_agent_test/BUILD.gn | 2 +- interfaces/kits/napi/wantagent/BUILD.gn | 2 +- services/ans/test/unittest/BUILD.gn | 2 +- services/test/moduletest/BUILD.gn | 2 +- test/common/acts/actsnotificationfuzztest/BUILD.gn | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/frameworks/ans/native/test/unittest/BUILD.gn b/frameworks/ans/native/test/unittest/BUILD.gn index 3e6607f7f..2512cfdbf 100644 --- a/frameworks/ans/native/test/unittest/BUILD.gn +++ b/frameworks/ans/native/test/unittest/BUILD.gn @@ -48,9 +48,9 @@ ohos_unittest("ans_reminder_unit_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "bytrace_standard:bytrace_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index c63aded83..f4478b3e4 100644 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -84,9 +84,9 @@ ohos_moduletest("ans_fw_module_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", @@ -162,9 +162,9 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", @@ -237,9 +237,9 @@ ohos_moduletest("ans_innerkits_module_slot_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", @@ -312,9 +312,9 @@ ohos_moduletest("ans_innerkits_module_setting_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", diff --git a/frameworks/wantagent/BUILD.gn b/frameworks/wantagent/BUILD.gn index 77fce1486..3079a9f19 100644 --- a/frameworks/wantagent/BUILD.gn +++ b/frameworks/wantagent/BUILD.gn @@ -69,9 +69,9 @@ ohos_shared_library("wantagent_innerkits") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn b/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn index 99461bf49..0e7c0b43d 100644 --- a/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn @@ -44,9 +44,9 @@ ohos_unittest("completed_dispatcher_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", diff --git a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn index 00ab12f1c..e2e2cd633 100644 --- a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn @@ -51,9 +51,9 @@ ohos_unittest("pending_want_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", diff --git a/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn b/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn index 9eae21754..70859531d 100644 --- a/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn @@ -44,9 +44,9 @@ ohos_unittest("trigger_Info_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", diff --git a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn index 2504a997e..a709539cf 100644 --- a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn @@ -48,9 +48,9 @@ ohos_unittest("want_agent_helper_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", diff --git a/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn index 220eb405a..f5dfa5537 100644 --- a/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn @@ -44,9 +44,9 @@ ohos_unittest("want_agent_info_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", diff --git a/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn index ee966bd19..f09422c21 100644 --- a/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn @@ -44,9 +44,9 @@ ohos_unittest("want_agent_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", diff --git a/interfaces/kits/napi/wantagent/BUILD.gn b/interfaces/kits/napi/wantagent/BUILD.gn index acbb9f039..305da38f9 100644 --- a/interfaces/kits/napi/wantagent/BUILD.gn +++ b/interfaces/kits/napi/wantagent/BUILD.gn @@ -45,9 +45,9 @@ ohos_shared_library("wantagent") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "napi:ace_napi", diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 1eb54058a..de0decb93 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -78,9 +78,9 @@ ohos_unittest("ans_unit_test") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 97c3b2f9f..194d497bf 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -65,9 +65,9 @@ ohos_moduletest("ans_module_test") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", diff --git a/test/common/acts/actsnotificationfuzztest/BUILD.gn b/test/common/acts/actsnotificationfuzztest/BUILD.gn index 8ccce80c6..c033414c8 100644 --- a/test/common/acts/actsnotificationfuzztest/BUILD.gn +++ b/test/common/acts/actsnotificationfuzztest/BUILD.gn @@ -79,9 +79,9 @@ ohos_systemtest("ActsNotificationFuzzTest") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", -- Gitee From ca4c077f77176931332b13acbc80827c324b7ab3 Mon Sep 17 00:00:00 2001 From: 17764556280 Date: Mon, 24 Jan 2022 15:19:03 +0800 Subject: [PATCH 05/18] modify bms part name Signed-off-by: 17764556280 --- notification.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notification.gni b/notification.gni index 19196f346..c35ab1cb1 100644 --- a/notification.gni +++ b/notification.gni @@ -32,9 +32,9 @@ aafwk_path = "//foundation/aafwk/standard" ans_standard_external_deps = [ "ability_runtime:base", "ability_runtime:want", + "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "appexecfwk_standard:libeventhandler", "ces_standard:cesfwk_innerkits", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", -- Gitee From decc8cd84a733a425552553d8fe54a82c3599be7 Mon Sep 17 00:00:00 2001 From: njupthan Date: Mon, 24 Jan 2022 16:00:07 +0800 Subject: [PATCH 06/18] Modify non mandatory properties of distributed options Signed-off-by: njupthan --- interfaces/kits/napi/ans/src/common.cpp | 68 ++++++++++++++----------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 2097b51d3..a86f7c8a2 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -2593,29 +2593,33 @@ napi_value Common::GetNotificationSupportDisplayDevices( ANS_LOGI("enter"); bool isArray = false; + bool hasProperty = false; napi_valuetype valuetype = napi_undefined; napi_value supportDisplayDevices = nullptr; char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; uint32_t length = 0; - napi_get_named_property(env, value, "supportDisplayDevices", &supportDisplayDevices); - napi_is_array(env, supportDisplayDevices, &isArray); - NAPI_ASSERT(env, isArray, "Property supportDisplayDevices is expected to be an array."); + NAPI_CALL(env, napi_has_named_property(env, value, "supportDisplayDevices", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "supportDisplayDevices", &supportDisplayDevices); + napi_is_array(env, supportDisplayDevices, &isArray); + NAPI_ASSERT(env, isArray, "Property supportDisplayDevices is expected to be an array."); - napi_get_array_length(env, supportDisplayDevices, &length); - NAPI_ASSERT(env, length > 0, "The array is empty."); - std::vector devices; - for (size_t i = 0; i < length; i++) { - napi_value line = nullptr; - napi_get_element(env, supportDisplayDevices, i, &line); - NAPI_CALL(env, napi_typeof(env, line, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, line, str, STR_MAX_SIZE - 1, &strLen)); - devices.emplace_back(str); - ANS_LOGI("supportDisplayDevices = %{public}s", str); + napi_get_array_length(env, supportDisplayDevices, &length); + NAPI_ASSERT(env, length > 0, "The array is empty."); + std::vector devices; + for (size_t i = 0; i < length; i++) { + napi_value line = nullptr; + napi_get_element(env, supportDisplayDevices, i, &line); + NAPI_CALL(env, napi_typeof(env, line, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, line, str, STR_MAX_SIZE - 1, &strLen)); + devices.emplace_back(str); + ANS_LOGI("supportDisplayDevices = %{public}s", str); + } + request.SetDevicesSupportDisplay(devices); } - request.SetDevicesSupportDisplay(devices); return NapiGetNull(env); } @@ -2625,29 +2629,33 @@ napi_value Common::GetNotificationSupportOperateDevices( ANS_LOGI("enter"); bool isArray = false; + bool hasProperty = false; napi_valuetype valuetype = napi_undefined; napi_value supportOperateDevices = nullptr; char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; uint32_t length = 0; - napi_get_named_property(env, value, "supportOperateDevices", &supportOperateDevices); - napi_is_array(env, supportOperateDevices, &isArray); - NAPI_ASSERT(env, isArray, "Property supportOperateDevices is expected to be an array."); + NAPI_CALL(env, napi_has_named_property(env, value, "supportOperateDevices", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, value, "supportOperateDevices", &supportOperateDevices); + napi_is_array(env, supportOperateDevices, &isArray); + NAPI_ASSERT(env, isArray, "Property supportOperateDevices is expected to be an array."); - napi_get_array_length(env, supportOperateDevices, &length); - NAPI_ASSERT(env, length > 0, "The array is empty."); - std::vector devices; - for (size_t i = 0; i < length; i++) { - napi_value line = nullptr; - napi_get_element(env, supportOperateDevices, i, &line); - NAPI_CALL(env, napi_typeof(env, line, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); - NAPI_CALL(env, napi_get_value_string_utf8(env, line, str, STR_MAX_SIZE - 1, &strLen)); - devices.emplace_back(str); - ANS_LOGI("supportOperateDevices = %{public}s", str); + napi_get_array_length(env, supportOperateDevices, &length); + NAPI_ASSERT(env, length > 0, "The array is empty."); + std::vector devices; + for (size_t i = 0; i < length; i++) { + napi_value line = nullptr; + napi_get_element(env, supportOperateDevices, i, &line); + NAPI_CALL(env, napi_typeof(env, line, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + NAPI_CALL(env, napi_get_value_string_utf8(env, line, str, STR_MAX_SIZE - 1, &strLen)); + devices.emplace_back(str); + ANS_LOGI("supportOperateDevices = %{public}s", str); + } + request.SetDevicesSupportOperate(devices); } - request.SetDevicesSupportOperate(devices); return NapiGetNull(env); } -- Gitee From bcc85f289e4b128694226b2c6f3c7f78a3da89e2 Mon Sep 17 00:00:00 2001 From: zero-cyc Date: Tue, 25 Jan 2022 15:01:33 +0800 Subject: [PATCH 07/18] chenlien@huawei.com Signed-off-by: zero-cyc Change-Id: Ib0fa36ef1ea9811351616591fe1c16c35da8e79a --- frameworks/ans/native/test/unittest/BUILD.gn | 2 +- frameworks/ans/test/moduletest/BUILD.gn | 8 ++++---- frameworks/wantagent/BUILD.gn | 2 +- .../test/unittest/completed_dispatcher_test/BUILD.gn | 2 +- .../wantagent/test/unittest/pending_want_test/BUILD.gn | 2 +- .../wantagent/test/unittest/trigger_Info_test/BUILD.gn | 2 +- .../test/unittest/want_agent_helper_test/BUILD.gn | 2 +- .../wantagent/test/unittest/want_agent_info_test/BUILD.gn | 2 +- .../wantagent/test/unittest/want_agent_test/BUILD.gn | 2 +- interfaces/kits/napi/wantagent/BUILD.gn | 2 +- notification.gni | 2 +- services/ans/test/unittest/BUILD.gn | 2 +- services/distributed/BUILD.gn | 2 +- services/test/moduletest/BUILD.gn | 2 +- test/common/acts/actsnotificationfuzztest/BUILD.gn | 2 +- 15 files changed, 18 insertions(+), 18 deletions(-) diff --git a/frameworks/ans/native/test/unittest/BUILD.gn b/frameworks/ans/native/test/unittest/BUILD.gn index 2512cfdbf..2d50fe276 100644 --- a/frameworks/ans/native/test/unittest/BUILD.gn +++ b/frameworks/ans/native/test/unittest/BUILD.gn @@ -48,13 +48,13 @@ ohos_unittest("ans_reminder_unit_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "bytrace_standard:bytrace_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index f4478b3e4..4d374f23b 100644 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -84,12 +84,12 @@ ohos_moduletest("ans_fw_module_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", @@ -162,12 +162,12 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", @@ -237,12 +237,12 @@ ohos_moduletest("ans_innerkits_module_slot_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", @@ -312,12 +312,12 @@ ohos_moduletest("ans_innerkits_module_setting_test") { external_deps = [ "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", diff --git a/frameworks/wantagent/BUILD.gn b/frameworks/wantagent/BUILD.gn index 3079a9f19..4c3a05b2a 100644 --- a/frameworks/wantagent/BUILD.gn +++ b/frameworks/wantagent/BUILD.gn @@ -69,10 +69,10 @@ ohos_shared_library("wantagent_innerkits") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn b/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn index 0e7c0b43d..c2fdd1b29 100644 --- a/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/completed_dispatcher_test/BUILD.gn @@ -44,11 +44,11 @@ ohos_unittest("completed_dispatcher_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn index e2e2cd633..8c0f2efd5 100644 --- a/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/pending_want_test/BUILD.gn @@ -51,11 +51,11 @@ ohos_unittest("pending_want_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn b/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn index 70859531d..936039c90 100644 --- a/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/trigger_Info_test/BUILD.gn @@ -44,11 +44,11 @@ ohos_unittest("trigger_Info_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn index a709539cf..e33afabc4 100644 --- a/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_helper_test/BUILD.gn @@ -48,11 +48,11 @@ ohos_unittest("want_agent_helper_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn index f5dfa5537..0d7bc8273 100644 --- a/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_info_test/BUILD.gn @@ -44,11 +44,11 @@ ohos_unittest("want_agent_info_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn b/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn index f09422c21..2d8437643 100644 --- a/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn +++ b/frameworks/wantagent/test/unittest/want_agent_test/BUILD.gn @@ -44,11 +44,11 @@ ohos_unittest("want_agent_test") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", diff --git a/interfaces/kits/napi/wantagent/BUILD.gn b/interfaces/kits/napi/wantagent/BUILD.gn index 305da38f9..666c747ca 100644 --- a/interfaces/kits/napi/wantagent/BUILD.gn +++ b/interfaces/kits/napi/wantagent/BUILD.gn @@ -45,9 +45,9 @@ ohos_shared_library("wantagent") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "napi:ace_napi", diff --git a/notification.gni b/notification.gni index c35ab1cb1..8a5ca46ca 100644 --- a/notification.gni +++ b/notification.gni @@ -32,11 +32,11 @@ aafwk_path = "//foundation/aafwk/standard" ans_standard_external_deps = [ "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index de0decb93..13cc23fff 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -78,12 +78,12 @@ ohos_unittest("ans_unit_test") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index 43dd48487..22c67f691 100644 --- a/services/distributed/BUILD.gn +++ b/services/distributed/BUILD.gn @@ -46,9 +46,9 @@ ohos_shared_library("libans_distributed") { external_deps = [ "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 194d497bf..43e087b66 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -65,12 +65,12 @@ ohos_moduletest("ans_module_test") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/test/common/acts/actsnotificationfuzztest/BUILD.gn b/test/common/acts/actsnotificationfuzztest/BUILD.gn index c033414c8..cdc3f2039 100644 --- a/test/common/acts/actsnotificationfuzztest/BUILD.gn +++ b/test/common/acts/actsnotificationfuzztest/BUILD.gn @@ -79,10 +79,10 @@ ohos_systemtest("ActsNotificationFuzzTest") { "ability_runtime:app_manager", "ability_runtime:base", "ability_runtime:want", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "dmsfwk_standard:zuri", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", -- Gitee From bb5568e1ceeff9e79ba79de48457950a4f1c80df Mon Sep 17 00:00:00 2001 From: liqiang Date: Tue, 25 Jan 2022 20:49:23 +0800 Subject: [PATCH 08/18] IsueNo:#I4S78C Description:fix displaybadge xts timeout fail bug Sig: SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: liqiang Change-Id: I5403b1841b8b054a8b39b2b043bf76707ab8110d --- interfaces/kits/napi/ans/src/common.cpp | 15 +++++-- .../kits/napi/ans/src/display_badge.cpp | 42 +++++++++++++++---- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index a86f7c8a2..f2ee37a75 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -3621,10 +3621,16 @@ napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, size_t strLen = 0; // bundle: string NAPI_CALL(env, napi_has_named_property(env, value, "bundle", &hasProperty)); - NAPI_ASSERT(env, hasProperty, "Property bundle expected."); + if (!hasProperty) { + ANS_LOGE("Property bundle expected."); + return nullptr; + } napi_get_named_property(env, value, "bundle", &result); NAPI_CALL(env, napi_typeof(env, result, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + if (valuetype != napi_string) { + ANS_LOGE("Wrong argument type. String expected."); + return nullptr; + } NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); option.SetBundleName(str); @@ -3634,7 +3640,10 @@ napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, int32_t uid = 0; napi_get_named_property(env, value, "uid", &result); NAPI_CALL(env, napi_typeof(env, result, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } napi_get_value_int32(env, result, &uid); option.SetUid(uid); } diff --git a/interfaces/kits/napi/ans/src/display_badge.cpp b/interfaces/kits/napi/ans/src/display_badge.cpp index 3484b24e9..71da17f3c 100644 --- a/interfaces/kits/napi/ans/src/display_badge.cpp +++ b/interfaces/kits/napi/ans/src/display_badge.cpp @@ -57,12 +57,19 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_value argv[ENABLE_BADGE_DISPLAYED_MAX_PARA] = {nullptr}; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - NAPI_ASSERT(env, argc >= ENABLE_BADGE_DISPLAYED_MIN_PARA, "Wrong number of arguments"); + if (argc < ENABLE_BADGE_DISPLAYED_MIN_PARA) { + ANS_LOGW("Wrong number of arguments."); + return nullptr; + } // argv[0]: bundle napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + if (valuetype != napi_object) { + ANS_LOGW("Wrong argument type. Object expected."); + return nullptr; + } + auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); @@ -71,13 +78,19 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[1]: enable NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); + if (valuetype != napi_boolean) { + ANS_LOGW("Wrong argument type. Bool expected."); + return nullptr; + } napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); // argv[2]:callback if (argc >= ENABLE_BADGE_DISPLAYED_MAX_PARA) { NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + if (valuetype != napi_function) { + ANS_LOGW("Wrong argument type. Function expected."); + return nullptr; + } napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); } @@ -92,14 +105,21 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_value argv[IS_DISPLAY_BADGE_MAX_PARA] = {nullptr}; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - NAPI_ASSERT(env, argc >= IS_DISPLAY_BADGE_MIN_PARA, "Wrong number of arguments"); + + if (argc < IS_DISPLAY_BADGE_MIN_PARA) { + ANS_LOGW("Wrong number of arguments."); + return nullptr; + } // argv[0]: bundle / callback napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); - NAPI_ASSERT(env, - (valuetype == napi_function) || (valuetype == napi_object), - "Wrong argument type. Function or object expected."); + + if ((valuetype != napi_function) && (valuetype != napi_object)) { + ANS_LOGW("Wrong argument type. Function or object expected, %{public}d", valuetype); + return nullptr; + } + if (valuetype == napi_object) { auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { @@ -114,7 +134,10 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[1]:callback if (argc >= IS_DISPLAY_BADGE_MAX_PARA) { NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + if (valuetype != napi_function) { + ANS_LOGW("Wrong argument type. Function expected."); + return nullptr; + } napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } @@ -213,6 +236,7 @@ napi_value IsBadgeDisplayed(napi_env env, napi_callback_info info) IsDisplayBadgeParams params {}; if (ParseParameters(env, info, params) == nullptr) { + ANS_LOGE("Failed to parse params!"); return Common::NapiGetUndefined(env); } -- Gitee From a5c3fcaffa46fd8b91d94a4996c0753a4741a5d9 Mon Sep 17 00:00:00 2001 From: liqiang Date: Wed, 26 Jan 2022 10:32:45 +0800 Subject: [PATCH 09/18] IssueNo:https://gitee.com/openharmony/notification_ans_standard/issues/I4S87I?from=project-issue Description:fix ActsAnsEnableNotificationTest xts timeout bug Sig: SIG_ApplicationFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: liqiang Change-Id: I989ca4a832f02fffc98fd55cb8d2ad5188740105 --- .../kits/napi/ans/src/enable_notification.cpp | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/interfaces/kits/napi/ans/src/enable_notification.cpp b/interfaces/kits/napi/ans/src/enable_notification.cpp index 7850a4f8d..c9b896d17 100644 --- a/interfaces/kits/napi/ans/src/enable_notification.cpp +++ b/interfaces/kits/napi/ans/src/enable_notification.cpp @@ -56,12 +56,18 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_value argv[ENABLE_NOTIFICATION_MAX_PARA] = {nullptr}; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - NAPI_ASSERT(env, argc >= ENABLE_NOTIFICATION_MIN_PARA, "Wrong number of arguments"); + if (argc < ENABLE_NOTIFICATION_MIN_PARA) { + ANS_LOGW("Wrong number of arguments."); + return nullptr; + } // argv[0]: bundle napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + if (valuetype != napi_object) { + ANS_LOGW("Wrong argument type. Object expected."); + return nullptr; + } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); @@ -70,13 +76,19 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[1]: enable NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); + if (valuetype != napi_boolean) { + ANS_LOGW("Wrong argument type. Bool expected."); + return nullptr; + } napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); // argv[2]:callback if (argc >= ENABLE_NOTIFICATION_MAX_PARA) { NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + if (valuetype != napi_function) { + ANS_LOGW("Wrong argument type. Function expected."); + return nullptr; + } napi_create_reference(env, argv[PARAM2], 1, ¶ms.callback); } @@ -99,9 +111,10 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[0]: bundle / callback napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); - NAPI_ASSERT(env, - (valuetype == napi_function) || (valuetype == napi_object), - "Wrong argument type. Function or object expected."); + if ((valuetype != napi_function) && (valuetype != napi_object)) { + ANS_LOGW("Wrong argument type. Function or object expected."); + return nullptr; + } if (valuetype == napi_object) { auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { @@ -116,7 +129,10 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[1]:callback if (argc >= IS_NOTIFICATION_ENABLE_MAX_PARA) { NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + if (valuetype != napi_function) { + ANS_LOGW("Wrong argument type. Function expected."); + return nullptr; + } napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } -- Gitee From 92c2d1f48640e2b915a9a883fa79bc087c546621 Mon Sep 17 00:00:00 2001 From: zengsiyu Date: Wed, 26 Jan 2022 11:27:21 +0800 Subject: [PATCH 10/18] fix: fix constants Signed-off-by: zengsiyu Change-Id: Ia9d99caf83e1cb3158d3ea24d2d0a524459df506 --- .../ans/src/advanced_notification_service.cpp | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index eb2b4d0c7..795c9ca54 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -46,17 +46,18 @@ namespace OHOS { namespace Notification { namespace { -static const std::string ACTIVE_NOTIFICATION_OPTION = "active"; -static const std::string RECENT_NOTIFICATION_OPTION = "recent"; +constexpr char ACTIVE_NOTIFICATION_OPTION[] = "active"; +constexpr char RECENT_NOTIFICATION_OPTION[] = "recent"; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED -static const std::string DISTRIBUTED_NOTIFICATION_OPTION = "distributed"; +constexpr char DISTRIBUTED_NOTIFICATION_OPTION[] = "distributed"; #endif -static const std::string SET_RECENT_COUNT_OPTION = "setRecentCount"; +constexpr char SET_RECENT_COUNT_OPTION[] = "setRecentCount"; +constexpr char FOUNDATION_BUNDLE_NAME[] = "ohos.global.systemres"; -static const int32_t NOTIFICATION_MIN_COUNT = 0; -static const int32_t NOTIFICATION_MAX_COUNT = 1024; +constexpr int32_t NOTIFICATION_MIN_COUNT = 0; +constexpr int32_t NOTIFICATION_MAX_COUNT = 1024; -static const int32_t DEFAULT_RECENT_COUNT = 16; +constexpr int32_t DEFAULT_RECENT_COUNT = 16; constexpr int HOURS_IN_ONE_DAY = 24; @@ -170,7 +171,7 @@ ErrCode PrepereNotificationRequest(const sptr &request) int pid = IPCSkeleton::GetCallingPid(); request->SetCreatorUid(uid); request->SetCreatorPid(pid); - + int userId = SUBSCRIBE_USER_INIT; OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); if (userId >= SUBSCRIBE_USER_SYSTEM_BEGIN && userId <= SUBSCRIBE_USER_SYSTEM_END) { @@ -1485,6 +1486,14 @@ ErrCode AdvancedNotificationService::PublishContinuousTaskNotification(const spt return ERR_ANS_NOT_SYSTEM_SERVICE; } + if (request->GetCreatorBundleName().empty()) { + request->SetCreatorBundleName(FOUNDATION_BUNDLE_NAME); + } + + if (request->GetOwnerBundleName().empty()) { + request->SetOwnerBundleName(FOUNDATION_BUNDLE_NAME); + } + sptr bundleOption = nullptr; bundleOption = new NotificationBundleOption(std::string(), uid); if (bundleOption == nullptr) { @@ -2293,7 +2302,7 @@ ErrCode AdvancedNotificationService::SetDoNotDisturbDate(const sptrPostSyncTask(std::bind([&]() { result = NotificationPreferences::GetInstance().SetDoNotDisturbDate(bundleOption, newConfig); if (result == ERR_OK) { @@ -2366,6 +2375,9 @@ ErrCode AdvancedNotificationService::DoesSupportDoNotDisturbMode(bool &doesSuppo bool AdvancedNotificationService::CheckPermission(const std::string &bundleName) { ANS_LOGD("%{public}s", __FUNCTION__); + if (IPCSkeleton::GetCallingUid() == SYSTEM_SERVICE_UID) { + return true; + } if (bundleName.empty()) { ANS_LOGE("Bundle name is empty."); return false; -- Gitee From 0ad69adcfac28e898201a955dab60f24de8ae46c Mon Sep 17 00:00:00 2001 From: fangJinliang1 Date: Tue, 25 Jan 2022 19:17:18 +0800 Subject: [PATCH 11/18] add notification flags Signed-off-by: fangJinliang1 Change-Id: If5f7e6385128544df49e4dcbd33877d4132efad3 Signed-off-by: fangJinliang1 --- frameworks/ans/core/BUILD.gn | 1 + frameworks/ans/native/BUILD.gn | 1 + .../ans/native/src/notification_flags.cpp | 114 ++++++++++++++++++ .../ans/native/src/notification_request.cpp | 73 +++++++++++ .../ans_innerkits_module_publish_test.cpp | 51 ++++++++ .../ans/native/include/notification_flags.h | 107 ++++++++++++++++ .../ans/native/include/notification_request.h | 15 +++ .../kits/js/notification/notificationFlags.ts | 35 ++++++ .../js/notification/notificationRequest.d.ts | 8 ++ interfaces/kits/napi/ans/include/common.h | 3 + interfaces/kits/napi/ans/src/common.cpp | 39 +++++- 11 files changed, 445 insertions(+), 2 deletions(-) create mode 100644 frameworks/ans/native/src/notification_flags.cpp create mode 100644 interfaces/innerkits/ans/native/include/notification_flags.h create mode 100644 interfaces/kits/js/notification/notificationFlags.ts diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index 346ddd631..6aff569c6 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -59,6 +59,7 @@ ohos_shared_library("ans_core") { "${frameworks_path}/ans/native/src/notification_conversational_message.cpp", "${frameworks_path}/ans/native/src/notification_distributed_options.cpp", "${frameworks_path}/ans/native/src/notification_do_not_disturb_date.cpp", + "${frameworks_path}/ans/native/src/notification_flags.cpp", "${frameworks_path}/ans/native/src/notification_helper.cpp", "${frameworks_path}/ans/native/src/notification_long_text_content.cpp", "${frameworks_path}/ans/native/src/notification_media_content.cpp", diff --git a/frameworks/ans/native/BUILD.gn b/frameworks/ans/native/BUILD.gn index 831a1d1f9..ae41de7dc 100644 --- a/frameworks/ans/native/BUILD.gn +++ b/frameworks/ans/native/BUILD.gn @@ -56,6 +56,7 @@ ohos_shared_library("ans_innerkits") { "src/notification_conversational_message.cpp", "src/notification_distributed_options.cpp", "src/notification_do_not_disturb_date.cpp", + "src/notification_flags.cpp", "src/notification_helper.cpp", "src/notification_long_text_content.cpp", "src/notification_media_content.cpp", diff --git a/frameworks/ans/native/src/notification_flags.cpp b/frameworks/ans/native/src/notification_flags.cpp new file mode 100644 index 000000000..901964bc7 --- /dev/null +++ b/frameworks/ans/native/src/notification_flags.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_flags.h" +#include "ans_log_wrapper.h" + +namespace OHOS { +namespace Notification { +void NotificationFlags::SetSoundEnabled(bool soundEnabled) +{ + soundEnabled_ = soundEnabled; +} + +bool NotificationFlags::IsSoundEnabled() const +{ + return soundEnabled_; +} + +void NotificationFlags::SetVibrationEnabled(bool vibrationEnabled) +{ + vibrationEnabled_ = vibrationEnabled; +} + +bool NotificationFlags::IsVibrationEnabled() const +{ + return vibrationEnabled_; +} + +std::string NotificationFlags::Dump() +{ + return "soundEnabled = " + std::string(soundEnabled_ ? "true" : "false") + + ", vibrationEnabled = " + std::string(vibrationEnabled_ ? "true" : "false"); +} + +bool NotificationFlags::ToJson(nlohmann::json &jsonObject) const +{ + jsonObject["soundEnabled"] = soundEnabled_; + jsonObject["vibrationEnabled"] = vibrationEnabled_; + + return true; +} + +NotificationFlags *NotificationFlags::FromJson(const nlohmann::json &jsonObject) +{ + if (jsonObject.is_null() or !jsonObject.is_object()) { + ANS_LOGE("Invalid JSON object"); + return nullptr; + } + + auto pFlags = new (std::nothrow) NotificationFlags(); + if (pFlags == nullptr) { + ANS_LOGE("Failed to create notificationFlags instance"); + return nullptr; + } + + const auto &jsonEnd = jsonObject.cend(); + if (jsonObject.find("soundEnabled") != jsonEnd) { + pFlags->soundEnabled_ = jsonObject.at("soundEnabled").get(); + } + + if (jsonObject.find("vibrationEnabled") != jsonEnd) { + pFlags->vibrationEnabled_ = jsonObject.at("vibrationEnabled").get(); + } + + return pFlags; +} + +bool NotificationFlags::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteBool(soundEnabled_)) { + ANS_LOGE("Failed to write flag sound enable for the notification"); + return false; + } + + if (!parcel.WriteBool(vibrationEnabled_)) { + ANS_LOGE("Failed to write flag vibration enable for the notification"); + return false; + } + + return true; +} + +NotificationFlags *NotificationFlags::Unmarshalling(Parcel &parcel) +{ + auto templ = new NotificationFlags(); + if ((templ != nullptr) && !templ->ReadFromParcel(parcel)) { + delete templ; + templ = nullptr; + } + + return templ; +} + +bool NotificationFlags::ReadFromParcel(Parcel &parcel) +{ + soundEnabled_ = parcel.ReadBool(); + vibrationEnabled_ = parcel.ReadBool(); + + return true; +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index 463ffe7df..a486bb337 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -679,6 +679,7 @@ std::string NotificationRequest::Dump() ", messageUsers = " + (!messageUsers_.empty() ? messageUsers_.at(0)->Dump() : "empty") + ", userInputHistory = " + (!userInputHistory_.empty() ? userInputHistory_.at(0) : "empty") + ", distributedOptions = " + distributedOptions_.Dump() + + ", notificationFlags = " + (notificationFlags_ ? "not null" : "null") + " }"; } @@ -777,6 +778,12 @@ NotificationRequest *NotificationRequest::FromJson(const nlohmann::json &jsonObj return nullptr; } + if (!ConvertJsonToNotificationFlags(pRequest, jsonObject)) { + delete pRequest; + pRequest = nullptr; + return nullptr; + } + return pRequest; } @@ -1127,6 +1134,19 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const } } + valid = notificationFlags_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write flags for the notification"); + return false; + } + + if (valid) { + if (!parcel.WriteParcelable(notificationFlags_.get())) { + ANS_LOGE("Failed to write notification flags"); + return false; + } + } + return true; } @@ -1337,6 +1357,15 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) } } + valid = parcel.ReadBool(); + if (valid) { + notificationFlags_ = std::shared_ptr(parcel.ReadParcelable()); + if (!notificationFlags_) { + ANS_LOGE("Failed to read notificationFlags"); + return false; + } + } + return true; } @@ -1359,6 +1388,16 @@ std::shared_ptr NotificationRequest::GetTemplate() const return notificationTemplate_; } +void NotificationRequest::SetFlags(const std::shared_ptr &flags) +{ + notificationFlags_ = flags; +} + +std::shared_ptr NotificationRequest::GetFlags() const +{ + return notificationFlags_; +} + void NotificationRequest::CopyBase(const NotificationRequest &other) { this->notificationId_ = other.notificationId_; @@ -1422,6 +1461,7 @@ void NotificationRequest::CopyOther(const NotificationRequest &other) this->distributedOptions_ = other.distributedOptions_; this->notificationTemplate_ = other.notificationTemplate_; + this->notificationFlags_ = other.notificationFlags_; } bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const @@ -1470,6 +1510,13 @@ bool NotificationRequest::ConvertObjectsToJson(nlohmann::json &jsonObject) const } jsonObject["distributedOptions"] = optObj; + nlohmann::json flagsObj; + if (!NotificationJsonConverter::ConvertToJosn(notificationFlags_.get(), flagsObj)) { + ANS_LOGE("Cannot convert notificationFlags to JSON"); + return false; + } + jsonObject["notificationFlags"] = flagsObj; + return true; } @@ -1692,5 +1739,31 @@ bool NotificationRequest::ConvertJsonToNotificationDistributedOptions( return true; } + +bool NotificationRequest::ConvertJsonToNotificationFlags( + NotificationRequest *target, const nlohmann::json &jsonObject) +{ + if (target == nullptr) { + ANS_LOGE("Invalid input parameter"); + return false; + } + + const auto &jsonEnd = jsonObject.cend(); + + if (jsonObject.find("notificationFlags") != jsonEnd) { + auto flagsObj = jsonObject.at("notificationFlags"); + if (!flagsObj.is_null()) { + auto pFlags = NotificationJsonConverter::ConvertFromJosn(flagsObj); + if (pFlags == nullptr) { + ANS_LOGE("Failed to parse notificationFlags!"); + return false; + } + + target->notificationFlags_ = std::shared_ptr(pFlags); + } + } + + return true; +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp index b9115de56..a8ac9f307 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -55,6 +55,7 @@ const int32_t CASE_ELEVEN = 11; const int32_t CASE_TWELVE = 12; const int32_t CASE_THIRTEEN = 13; const int32_t CASE_FOURTEEN = 14; +const int32_t CASE_FIFTEEN = 15; const int32_t CALLING_UID = 9999; const int32_t PIXEL_MAP_TEST_WIDTH = 32; @@ -136,6 +137,8 @@ public: EXPECT_EQ(true, notificationRequest.IsGroupOverview()); } else if (CASE_FOURTEEN == notificationRequest.GetNotificationId()) { CheckCaseFourteenResult(notificationRequest); + } else if (CASE_FIFTEEN == notificationRequest.GetNotificationId()) { + CheckCaseFifteenResult(notificationRequest); } else { GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish::OnConsumed do nothing!!!!!"; } @@ -369,6 +372,15 @@ private: } EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType()); } + + void CheckCaseFifteenResult(NotificationRequest notificationRequest) + { + std::shared_ptr notiFlags = notificationRequest.GetFlags(); + if (notiFlags != nullptr) { + EXPECT_EQ(false, notiFlags->IsSoundEnabled()); + EXPECT_EQ(true, notiFlags->IsVibrationEnabled()); + } + } }; class CompletedCallbackTest : public WantAgent::CompletedCallback { @@ -1327,5 +1339,44 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_08000, Function CheckJsonConverter(&req); } + +/** + * @tc.number : ANS_Interface_MT_Publish_05000 + * @tc.name : Publish_05000 + * @tc.desc : Add notification slot(type is OTHER), make a subscriber and publish a flags notification. + * @tc.expected : Add notification slot success, make a subscriber and publish a flags notification success. + */ +HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_05000, Function | MediumTest | Level1) +{ + NotificationSlot slot(NotificationConstant::OTHER); + EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot)); + auto subscriber = TestAnsSubscriber(); + NotificationSubscribeInfo info = NotificationSubscribeInfo(); + info.AddAppName("bundleName"); + g_subscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); + WaitOnSubscribeResult(); + + std::shared_ptr notiFlags = std::make_shared(); + EXPECT_NE(notiFlags, nullptr); + notiFlags->SetSoundEnabled(false); + notiFlags->SetVibrationEnabled(true); + GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_04000::flags::" << notiFlags->Dump(); + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + NotificationRequest req; + req.SetContent(content); + req.SetFlags(notiFlags); + req.SetSlotType(NotificationConstant::OTHER); + req.SetNotificationId(CASE_FIFTEEN); + g_consumed_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); + WaitOnConsumed(); + g_unsubscribe_mtx.lock(); + EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(subscriber, info)); + WaitOnUnsubscribeResult(); +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/notification_flags.h b/interfaces/innerkits/ans/native/include/notification_flags.h new file mode 100644 index 000000000..09664ed4d --- /dev/null +++ b/interfaces/innerkits/ans/native/include/notification_flags.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_FLAGS_H +#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_FLAGS_H + +#include +#include "parcel.h" +#include "notification_json_convert.h" + +namespace OHOS { +namespace Notification { +class NotificationFlags : public Parcelable, public NotificationJsonConvertionBase { +public: + /** + * Default constructor used to create an empty NotificationFlags instance. + */ + NotificationFlags() = default; + + /** + * Default deconstructor used to deconstruct. + */ + ~NotificationFlags() = default; + + /** + * Sets the notification whether enable sound. + * @param soundEnabled whether enable sound. + */ + void SetSoundEnabled(bool soundEnabled); + + /** + * Checks whether enable sound. + * @return sound enable. + */ + bool IsSoundEnabled() const; + + /** + * Sets the notification whether enable vibration. + * @param vibrationEnabled whether enable vibration. + */ + void SetVibrationEnabled(bool vibrationEnabled); + + /** + * Checks whether enable vibration. + * @return vibration enable. + */ + bool IsVibrationEnabled() const; + + /** + * Returns a string representation of the object. + * @return a string representation of the object. + */ + std::string Dump(); + + /** + * Converts a NotificationFlags object into a Json. + * @param jsonObject Indicates the Json object. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * Creates a NotificationFlags object from a Json. + * @param jsonObject Indicates the Json object. + * @return the NotificationFlags. + */ + static NotificationFlags *FromJson(const nlohmann::json &jsonObject); + + /** + * Marshal a object into a Parcel. + * @param parcel the object into the parcel + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * Unmarshal object from a Parcel. + * @return the NotificationFlags + */ + static NotificationFlags *Unmarshalling(Parcel &parcel); + +private: + /** + * Read a NotificationFlags object from a Parcel. + * @param parcel the parcel + */ + bool ReadFromParcel(Parcel &parcel); + +private: + bool soundEnabled_ {true}; + bool vibrationEnabled_ {false}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_FLAGS_H + diff --git a/interfaces/innerkits/ans/native/include/notification_request.h b/interfaces/innerkits/ans/native/include/notification_request.h index 93b5f2d9a..e2f6190f8 100644 --- a/interfaces/innerkits/ans/native/include/notification_request.h +++ b/interfaces/innerkits/ans/native/include/notification_request.h @@ -20,6 +20,7 @@ #include "notification_action_button.h" #include "notification_content.h" #include "notification_distributed_options.h" +#include "notification_flags.h" #include "notification_json_convert.h" #include "notification_template.h" #include "ohos/aafwk/content/want_params.h" @@ -915,6 +916,18 @@ public: */ std::shared_ptr GetTemplate() const; + /** + * Sets the flags of this notification. + * @param flags the flags of this notification. + */ + void SetFlags(const std::shared_ptr &flags); + + /** + * Obtains the flags of the notification. + * @return the flags of the notification. + */ + std::shared_ptr GetFlags() const; + private: /** * Indicates the color mask, used for calculation with the ARGB value set by setColor(int32_t). @@ -958,6 +971,7 @@ private: static bool ConvertJsonToNotificationActionButton(NotificationRequest *target, const nlohmann::json &jsonObject); static bool ConvertJsonToNotificationDistributedOptions( NotificationRequest *target, const nlohmann::json &jsonObject); + static bool ConvertJsonToNotificationFlags(NotificationRequest *target, const nlohmann::json &jsonObject); private: int32_t notificationId_ {0}; @@ -1019,6 +1033,7 @@ private: NotificationDistributedOptions distributedOptions_; std::shared_ptr notificationTemplate_ {}; + std::shared_ptr notificationFlags_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/kits/js/notification/notificationFlags.ts b/interfaces/kits/js/notification/notificationFlags.ts new file mode 100644 index 000000000..58c4a6831 --- /dev/null +++ b/interfaces/kits/js/notification/notificationFlags.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Describes a NotificationFlags instance. + * + * @name NotificationFlags + * @since 8 + * @devices phone, tablet, tv, wearable, car + * @permission N/A + * @sysCap SystemCapability.Notification.ANS + */ + export interface NotificationFlags { + /** + * Whether to enable sound reminder. + */ + readonly soundEnabled?: boolean; + + /** + * Whether to enable vibration reminder. + */ + readonly vibrationEnabled?: boolean; +} diff --git a/interfaces/kits/js/notification/notificationRequest.d.ts b/interfaces/kits/js/notification/notificationRequest.d.ts index 6525bf19e..971ecb0c7 100644 --- a/interfaces/kits/js/notification/notificationRequest.d.ts +++ b/interfaces/kits/js/notification/notificationRequest.d.ts @@ -19,6 +19,7 @@ import { WantAgent } from '../@ohos.wantAgent'; import { NotificationContent } from './notificationContent'; import { NotificationActionButton } from './notificationActionButton'; import { NotificationTemplate } from './notificationTemplate'; +import { NotificationFlags } from './notificationFlags'; /** * Defines a NotificationRequest instance. @@ -197,4 +198,11 @@ export interface NotificationRequest { * @since 8 */ template?: NotificationTemplate; + + /** + * Obtains the set of identifiers for the notification. + * + * @since 8 + */ + readonly notificationFlags?: NotificationFlags; } diff --git a/interfaces/kits/napi/ans/include/common.h b/interfaces/kits/napi/ans/include/common.h index f77e712a0..ba4cd1aad 100644 --- a/interfaces/kits/napi/ans/include/common.h +++ b/interfaces/kits/napi/ans/include/common.h @@ -429,6 +429,9 @@ public: static napi_value SetNotificationTemplateInfo( const napi_env &env, const std::shared_ptr &templ, napi_value &result); + static napi_value SetNotificationFlags( + const napi_env &env, const std::shared_ptr &flags, napi_value &result); + private: static const int ARGS_ONE = 1; static const int ARGS_TWO = 2; diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 2097b51d3..b7edb7ce7 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -548,7 +548,7 @@ napi_value Common::SetNotificationRequestByCustom( } napi_set_named_property(env, result, "actionButtons", arr); - // template?: NotificationTemplate; + // template?: NotificationTemplate std::shared_ptr templ = request->GetTemplate(); if (templ) { napi_value templateResult = nullptr; @@ -560,6 +560,18 @@ napi_value Common::SetNotificationRequestByCustom( napi_set_named_property(env, result, "template", templateResult); } + // readonly notificationFlags?: NotificationFlags + std::shared_ptr flags = request->GetFlags(); + if (flags) { + napi_value flagsResult = nullptr; + napi_create_object(env, &flagsResult); + if (!SetNotificationFlags(env, flags, flagsResult)) { + ANS_LOGE("SetNotificationFlags call failed"); + return NapiGetBoolean(env, false); + } + napi_set_named_property(env, result, "notificationFlags", flagsResult); + } + return NapiGetBoolean(env, true); } @@ -4074,5 +4086,28 @@ napi_value Common::SetNotificationTemplateInfo( return NapiGetBoolean(env, true); } + +napi_value Common::SetNotificationFlags( + const napi_env &env, const std::shared_ptr &flags, napi_value &result) +{ + ANS_LOGI("enter"); + + if (flags == nullptr) { + ANS_LOGE("flags is null"); + return NapiGetBoolean(env, false); + } + + napi_value value = nullptr; + + // readonly soundEnabled?: boolean + napi_get_boolean(env, flags->IsSoundEnabled(), &value); + napi_set_named_property(env, result, "soundEnabled", value); + + // readonly vibrationEnabled?: boolean + napi_get_boolean(env, flags->IsVibrationEnabled(), &value); + napi_set_named_property(env, result, "vibrationEnabled", value); + + return NapiGetBoolean(env, true); +} } // namespace NotificationNapi -} // namespace OHOS \ No newline at end of file +} // namespace OHOS -- Gitee From 172f46b87f972658279e2f017f567b9d6480ef2c Mon Sep 17 00:00:00 2001 From: njupthan Date: Thu, 27 Jan 2022 17:12:46 +0000 Subject: [PATCH 12/18] Modify the problem of incomplete dump output Signed-off-by: njupthan --- tools/dump/include/notification_shell_command.h | 7 +++---- tools/dump/src/notification_shell_command.cpp | 15 ++++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/tools/dump/include/notification_shell_command.h b/tools/dump/include/notification_shell_command.h index bede4da7e..26fc5199e 100644 --- a/tools/dump/include/notification_shell_command.h +++ b/tools/dump/include/notification_shell_command.h @@ -34,12 +34,11 @@ private: ErrCode RunAsDumpCommand(); ErrCode RunHelp(); - ErrCode RunActive(); - ErrCode RunRecent(); + ErrCode RunActive(std::vector &infos); + ErrCode RunRecent(std::vector &infos); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - ErrCode RunDistributed(); + ErrCode RunDistributed(std::vector &infos); #endif - ErrCode RunSetRecentCount(); private: std::shared_ptr ans_; diff --git a/tools/dump/src/notification_shell_command.cpp b/tools/dump/src/notification_shell_command.cpp index 2d44785e7..97de8dd95 100644 --- a/tools/dump/src/notification_shell_command.cpp +++ b/tools/dump/src/notification_shell_command.cpp @@ -99,10 +99,9 @@ ErrCode NotificationShellCommand::RunHelp() return ERR_OK; } -ErrCode NotificationShellCommand::RunActive() +ErrCode NotificationShellCommand::RunActive(std::vector &infos) { ErrCode ret = ERR_OK; - std::vector infos; if (ans_ != nullptr) { ret = ans_->ShellDump("active", infos); resultReceiver_.append("Total:" + std::to_string(infos.size()) + "\n"); @@ -112,10 +111,9 @@ ErrCode NotificationShellCommand::RunActive() return ret; } -ErrCode NotificationShellCommand::RunRecent() +ErrCode NotificationShellCommand::RunRecent(std::vector &infos) { ErrCode ret = ERR_OK; - std::vector infos; if (ans_ != nullptr) { ret = ans_->ShellDump("recent", infos); resultReceiver_.append("Total:" + std::to_string(infos.size()) + "\n"); @@ -126,10 +124,9 @@ ErrCode NotificationShellCommand::RunRecent() } #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED -ErrCode NotificationShellCommand::RunDistributed() +ErrCode NotificationShellCommand::RunDistributed(std::vector &infos) { ErrCode ret = ERR_OK; - std::vector infos; if (ans_ != nullptr) { ret = ans_->ShellDump("distributed", infos); resultReceiver_.append("Total:" + std::to_string(infos.size()) + "\n"); @@ -157,14 +154,14 @@ ErrCode NotificationShellCommand::RunAsDumpCommand() ret = RunHelp(); break; case 'A': - ret = RunActive(); + ret = RunActive(infos); break; case 'R': - ret = RunRecent(); + ret = RunRecent(infos); break; #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED case 'D': - ret = RunDistributed(); + ret = RunDistributed(infos); break; #endif case 0: -- Gitee From 45fcd022bcc9707d3af72ac68f8b1551180dfbf0 Mon Sep 17 00:00:00 2001 From: derek Date: Sun, 30 Jan 2022 14:23:29 +0800 Subject: [PATCH 13/18] add database Signed-off-by: derek Change-Id: I6e690acf1f167835f0d422004205d23eec6f1b41 --- frameworks/ans/core/BUILD.gn | 4 + frameworks/ans/native/BUILD.gn | 2 + frameworks/ans/native/src/reminder_helper.cpp | 7 +- .../ans/native/src/reminder_request.cpp | 169 ++++- .../ans/native/src/reminder_request_alarm.cpp | 42 ++ .../native/src/reminder_request_calendar.cpp | 77 +++ frameworks/ans/native/src/reminder_store.cpp | 647 ++++++++++++++++++ .../ans/native/include/reminder_const.h | 129 ++++ .../ans/native/include/reminder_request.h | 59 ++ .../native/include/reminder_request_alarm.h | 25 + .../include/reminder_request_calendar.h | 37 + .../native/include/reminder_request_timer.h | 8 + .../ans/native/include/reminder_store.h | 105 +++ notification.gni | 1 + services/ans/include/reminder_data_manager.h | 20 +- services/ans/include/reminder_event_manager.h | 1 - services/ans/src/reminder_data_manager.cpp | 88 ++- services/ans/src/reminder_event_manager.cpp | 25 +- 18 files changed, 1417 insertions(+), 29 deletions(-) create mode 100644 frameworks/ans/native/src/reminder_store.cpp create mode 100644 interfaces/innerkits/ans/native/include/reminder_const.h create mode 100644 interfaces/innerkits/ans/native/include/reminder_store.h diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index 8cf575c0b..5529bcc20 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -77,6 +77,7 @@ ohos_shared_library("ans_core") { "${frameworks_path}/ans/native/src/reminder_request_alarm.cpp", "${frameworks_path}/ans/native/src/reminder_request_calendar.cpp", "${frameworks_path}/ans/native/src/reminder_request_timer.cpp", + "${frameworks_path}/ans/native/src/reminder_store.cpp", ] configs = [ ":private_config" ] @@ -91,12 +92,15 @@ ohos_shared_library("ans_core") { ] external_deps = [ + "ability_runtime:abilitykit_native", "ability_runtime:want", "bundle_framework:appexecfwk_base", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", + "os_account_standard:os_account_innerkits", "samgr_standard:samgr_proxy", "time_native:time_service", ] diff --git a/frameworks/ans/native/BUILD.gn b/frameworks/ans/native/BUILD.gn index a27b1b04e..d3d53f791 100644 --- a/frameworks/ans/native/BUILD.gn +++ b/frameworks/ans/native/BUILD.gn @@ -84,11 +84,13 @@ ohos_shared_library("ans_innerkits") { ] external_deps = [ + "ability_runtime:abilitykit_native", "ability_runtime:want", "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", "samgr_standard:samgr_proxy", ] diff --git a/frameworks/ans/native/src/reminder_helper.cpp b/frameworks/ans/native/src/reminder_helper.cpp index 3197916ae..4291b022e 100644 --- a/frameworks/ans/native/src/reminder_helper.cpp +++ b/frameworks/ans/native/src/reminder_helper.cpp @@ -29,7 +29,12 @@ namespace Notification { ErrCode ReminderHelper::PublishReminder(ReminderRequest &reminder) { ANSR_LOGI("PublishReminder start"); - + + // wait bundle manager to implement permission check. + // if (!CheckPermission()) { + // return ERR_PERMISSION_DENIED; + // } + NotificationSlot slot(reminder.GetSlotType()); NotificationHelper::AddNotificationSlot(slot); return DelayedSingleton::GetInstance()->PublishReminder(reminder); diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 3b27d3b01..ebcb776b9 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" @@ -32,6 +37,7 @@ const uint8_t ReminderRequest::REMINDER_STATUS_ACTIVE = 1; const uint8_t ReminderRequest::REMINDER_STATUS_ALERTING = 2; const uint8_t ReminderRequest::REMINDER_STATUS_SHOWING = 4; const uint8_t ReminderRequest::REMINDER_STATUS_SNOOZE = 8; +const int ReminderRequest::BASE_YEAR = 1900; const std::string ReminderRequest::NOTIFICATION_LABEL = "REMINDER_AGENT"; const std::string ReminderRequest::REMINDER_EVENT_ALARM_ALERT = "ohos.event.notification.reminder.ALARM_ALERT"; const std::string ReminderRequest::REMINDER_EVENT_CLOSE_ALERT = "ohos.event.notification.reminder.CLOSE_ALERT"; @@ -40,7 +46,9 @@ const std::string ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT = "ohos.event.no const std::string ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION = "ohos.event.notification.reminder.REMOVE_NOTIFICATION"; const std::string ReminderRequest::PARAM_REMINDER_ID = "REMINDER_ID"; -const int ReminderRequest::BASE_YEAR = 1900; +const std::string ReminderRequest::SEP_BUTTON_SINGLE = ""; +const std::string ReminderRequest::SEP_BUTTON_MULTI = ""; +const std::string ReminderRequest::SEP_WANT_AGENT = ""; ReminderRequest::ReminderRequest() { @@ -446,6 +454,11 @@ bool ReminderRequest::ShouldShowImmediately() const return true; } +uint8_t ReminderRequest::GetConstStateInactive() +{ + return REMINDER_STATUS_INACTIVE; +} + std::map ReminderRequest::GetActionButtons( ) const { @@ -861,6 +874,21 @@ std::string ReminderRequest::GetDateTimeInfo(const time_t &timeInSecond) const return GetTimeInfoInner(timeInSecond, TimeFormat::YMDHMS); } +std::string ReminderRequest::GetButtonInfo() const +{ + std::string info = ""; + bool isFirst = true; + for (auto it = actionButtonMap_.begin(); it != actionButtonMap_.end(); ++it) { + if (!isFirst) { + info += SEP_BUTTON_MULTI; + } + ActionButtonInfo buttonInfo = it->second; + info += std::to_string(static_cast(it->first)) + SEP_BUTTON_SINGLE + buttonInfo.title; + isFirst = false; + } + return info; +} + uint64_t ReminderRequest::GetNowInstantMilli() const { time_t now; @@ -877,6 +905,8 @@ std::string ReminderRequest::GetShowTime(const uint64_t showTime) const if (reminderType_ == ReminderType::TIMER) { return ""; } else { + // bool isTime24 = false; // todo + const time_t showTimeInSecond = static_cast(showTime / MILLI_SECONDS); return GetTimeInfoInner(showTimeInSecond, TimeFormat::HM); } @@ -1180,5 +1210,142 @@ int ReminderRequest::GetCTime(const TimeTransferType &type, int actualTime) return -1; } } + +int32_t ReminderRequest::GetUid(const int &userId, const std::string &bundleName) +{ + 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); +} + +int ReminderRequest::GetUserId(const int &uid) +{ + int userId = -1; + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); + return userId; +} + +void ReminderRequest::AppendValuesBucket(const sptr &reminder, + sptr &bundleOption, NativeRdb::ValuesBucket &values) +{ + values.PutInt(Instance::REMINDER_ID, reminder->GetReminderId()); + values.PutString(Instance::PKG_NAME, bundleOption->GetBundleName()); + values.PutInt(Instance::USER_ID, GetUserId(bundleOption->GetUid())); + values.PutString(Instance::APP_LABEL, ""); // no use + values.PutInt(Instance::REMINDER_TYPE, static_cast(reminder->GetReminderType())); + values.PutLong(Instance::REMINDER_TIME, reminder->GetReminderTimeInMilli()); + values.PutLong(Instance::TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); + values.PutLong(Instance::RTC_TRIGGER_TIME, reminder->GetTriggerTimeInMilli()); // no use + values.PutLong(Instance::TIME_INTERVAL, reminder->GetTimeInterval()); + values.PutInt(Instance::SNOOZE_TIMES, reminder->GetSnoozeTimes()); + values.PutInt(Instance::DYNAMIC_SNOOZE_TIMES, reminder->GetSnoozeTimesDynamic()); + values.PutLong(Instance::RING_DURATION, reminder->GetRingDuration()); + values.PutString(Instance::IS_EXPIRED, reminder->IsExpired() ? "true" : "false"); + values.PutString(Instance::IS_ACTIVE, ""); // no use + values.PutInt(Instance::STATE, reminder->GetState()); + values.PutString(Instance::ZONE_ID, ""); // no use + values.PutString(Instance::HAS_SCHEDULED_TIMEOUT, ""); // no use + values.PutString(Instance::ACTION_BUTTON_INFO, reminder->GetButtonInfo()); + values.PutInt(Instance::SLOT_ID, reminder->GetSlotType()); + values.PutInt(Instance::NOTIFICATION_ID, reminder->GetNotificationId()); + values.PutString(Instance::TITLE, reminder->GetTitle()); + values.PutString(Instance::CONTENT, reminder->GetContent()); + values.PutString(Instance::SNOOZE_CONTENT, reminder->GetSnoozeContent()); + values.PutString(Instance::EXPIRED_CONTENT, reminder->GetExpiredContent()); + auto wantAgentInfo = reminder->GetWantAgentInfo(); + if (wantAgentInfo == nullptr) { + std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; + values.PutString(Instance::AGENT, info); + } else { + values.PutString(Instance::AGENT, wantAgentInfo->pkgName + + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->abilityName); + } + auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo(); + if (maxScreenWantAgentInfo == nullptr) { + std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; + values.PutString(Instance::MAX_SCREEN_AGENT, info); + } else { + values.PutString(Instance::MAX_SCREEN_AGENT, maxScreenWantAgentInfo->pkgName + + ReminderRequest::SEP_WANT_AGENT + maxScreenWantAgentInfo->abilityName); + } +} + +const std::string ReminderRequest::Instance::REMINDER_ID = "reminder_id"; +const std::string ReminderRequest::Instance::PKG_NAME = "package_name"; +const std::string ReminderRequest::Instance::USER_ID = "user_id"; +const std::string ReminderRequest::Instance::APP_LABEL = "app_label"; +const std::string ReminderRequest::Instance::REMINDER_TYPE = "reminder_type"; +const std::string ReminderRequest::Instance::REMINDER_TIME = "reminder_time"; +const std::string ReminderRequest::Instance::TRIGGER_TIME = "trigger_time"; +const std::string ReminderRequest::Instance::RTC_TRIGGER_TIME = "rtc_trigger_time"; +const std::string ReminderRequest::Instance::TIME_INTERVAL = "time_interval"; +const std::string ReminderRequest::Instance::SNOOZE_TIMES = "snooze_times"; +const std::string ReminderRequest::Instance::DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; +const std::string ReminderRequest::Instance::RING_DURATION = "ring_duration"; +const std::string ReminderRequest::Instance::IS_EXPIRED = "is_expired"; +const std::string ReminderRequest::Instance::IS_ACTIVE = "is_active"; +const std::string ReminderRequest::Instance::STATE = "state"; +const std::string ReminderRequest::Instance::ZONE_ID = "zone_id"; +const std::string ReminderRequest::Instance::HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; +const std::string ReminderRequest::Instance::ACTION_BUTTON_INFO = "button_info"; +const std::string ReminderRequest::Instance::SLOT_ID = "slot_id"; +const std::string ReminderRequest::Instance::NOTIFICATION_ID = "notification_id"; +const std::string ReminderRequest::Instance::TITLE = "title"; +const std::string ReminderRequest::Instance::CONTENT = "content"; +const std::string ReminderRequest::Instance::SNOOZE_CONTENT = "snooze_content"; +const std::string ReminderRequest::Instance::EXPIRED_CONTENT = "expired_content"; +const std::string ReminderRequest::Instance::AGENT = "agent"; +const std::string ReminderRequest::Instance::MAX_SCREEN_AGENT = "maxScreen_agent"; + +std::string ReminderRequest::Instance::SQL_ADD_COLUMNS = ""; +std::vector ReminderRequest::Instance::COLUMNS; + +void ReminderRequest::Instance::Init() +{ + AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", false); + AddColumn(PKG_NAME, "TEXT NOT NULL", false); + AddColumn(USER_ID, "INT NOT NULL", false); + AddColumn(APP_LABEL, "TEXT", false); + AddColumn(REMINDER_TYPE, "INT NOT NULL", false); + AddColumn(REMINDER_TIME, "BIGINT NOT NULL", false); + AddColumn(TRIGGER_TIME, "BIGINT NOT NULL", false); + AddColumn(RTC_TRIGGER_TIME, "BIGINT NOT NULL", false); + AddColumn(TIME_INTERVAL, "BIGINT NOT NULL", false); + AddColumn(SNOOZE_TIMES, "INT NOT NULL", false); + AddColumn(DYNAMIC_SNOOZE_TIMES, "INT NOT NULL", false); + AddColumn(RING_DURATION, "BIGINT NOT NULL", false); + AddColumn(IS_EXPIRED, "TEXT NOT NULL", false); + AddColumn(IS_ACTIVE, "TEXT NOT NULL", false); + AddColumn(STATE, "INT NOT NULL", false); + AddColumn(ZONE_ID, "TEXT", false); + AddColumn(HAS_SCHEDULED_TIMEOUT, "TEXT", false); + AddColumn(ACTION_BUTTON_INFO, "TEXT", false); + AddColumn(SLOT_ID, "INT", false); + AddColumn(NOTIFICATION_ID, "INT NOT NULL", false); + AddColumn(TITLE, "TEXT", false); + AddColumn(CONTENT, "TEXT", false); + AddColumn(SNOOZE_CONTENT, "TEXT", false); + AddColumn(EXPIRED_CONTENT, "TEXT", false); + AddColumn(AGENT, "TEXT", false); + AddColumn(MAX_SCREEN_AGENT, "TEXT", false); +} + +void ReminderRequest::Instance::AddColumn( + const std::string &name, const std::string &type, const bool &isEnd) +{ + COLUMNS.push_back(name); + if (!isEnd) { + SQL_ADD_COLUMNS += name + " " + type + ", "; + } else { + SQL_ADD_COLUMNS += name + " " + type; + } } } +} \ No newline at end of file diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index f1334689b..cccbfb10a 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -301,5 +301,47 @@ bool ReminderRequestAlarm::ReadFromParcel(Parcel &parcel) ANSR_LOGD("hour_=%{public}d, minute_=%{public}d, repeatDays_=%{public}d", hour_, minute_, repeatDays_); return true; } + +void ReminderRequestAlarm::AppendValuesBucket(const sptr &reminder, + sptr &bundleOption, NativeRdb::ValuesBucket &values) +{ + uint8_t repeatDays = 0; + uint8_t hour = 0; + uint8_t minute = 0; + if (reminder->GetReminderType() == ReminderRequest::ReminderType::ALARM) { + ReminderRequestAlarm* alarm = static_cast(reminder.GetRefPtr()); + repeatDays = alarm->GetRepeatDay(); + hour = alarm->GetHour(); + minute = alarm->GetMinute(); + } + values.PutInt(Instance::REPEAT_DAYS_OF_WEEK, repeatDays); + values.PutInt(Instance::ALARM_HOUR, hour); + values.PutInt(Instance::ALARM_MINUTE, minute); +} + +const std::string ReminderRequestAlarm::Instance::REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; +const std::string ReminderRequestAlarm::Instance::ALARM_HOUR = "alarm_hour"; +const std::string ReminderRequestAlarm::Instance::ALARM_MINUTE = "alarm_minute"; + +std::string ReminderRequestAlarm::Instance::SQL_ADD_COLUMNS = ""; +std::vector ReminderRequestAlarm::Instance::COLUMNS; + +void ReminderRequestAlarm::Instance::Init() +{ + AddColumn(REPEAT_DAYS_OF_WEEK, "INT", false); + AddColumn(ALARM_HOUR, "INT", false); + AddColumn(ALARM_MINUTE, "INT", true); +} + +void ReminderRequestAlarm::Instance::AddColumn( + const std::string &name, const std::string &type, const bool &isEnd) +{ + COLUMNS.push_back(name); + if (!isEnd) { + SQL_ADD_COLUMNS += name + " " + type + ", "; + } else { + SQL_ADD_COLUMNS += name + " " + type; + } +} } } \ No newline at end of file diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index 115c6fa0d..77665e3ec 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -491,5 +491,82 @@ bool ReminderRequestCalendar::ReadFromParcel(Parcel &parcel) } return true; } + +void ReminderRequestCalendar::AppendValuesBucket(const sptr &reminder, + sptr &bundleOption, NativeRdb::ValuesBucket &values) +{ + uint32_t repeatDay = 0; + uint16_t repeatMonth = 0; + uint16_t firstDesignateYear = 0; + uint8_t firstDesignateMonth = 0; + uint8_t firstDesignateDay = 0; + uint16_t year = 0; + uint8_t month = 0; + uint8_t day = 0; + uint8_t hour = 0; + uint8_t minute = 0; + if (reminder->GetReminderType() == ReminderRequest::ReminderType::CALENDAR) { + ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); + repeatDay = calendar->GetRepeatDay(); + repeatMonth = calendar->GetRepeatMonth(); + firstDesignateYear = calendar->GetFirstDesignateYear(); + firstDesignateMonth = calendar->GetFirstDesignageMonth(); + firstDesignateDay = calendar->GetFirstDesignateDay(); + year = calendar->GetYear(); + month = calendar->GetMonth(); + day = calendar->GetDay(); + hour = calendar->GetHour(); + minute = calendar->GetMinute(); + } + values.PutInt(Instance::REPEAT_DAYS, repeatDay); + values.PutInt(Instance::REPEAT_MONTHS, repeatMonth); + values.PutInt(Instance::FIRST_DESIGNATE_YEAR, firstDesignateYear); + values.PutInt(Instance::FIRST_DESIGNATE_MONTH, firstDesignateMonth); + values.PutInt(Instance::FIRST_DESIGNATE_DAY, firstDesignateDay); + values.PutInt(Instance::CALENDAR_YEAR, year); + values.PutInt(Instance::CALENDAR_MONTH, month); + values.PutInt(Instance::CALENDAR_DAY, day); + values.PutInt(Instance::CALENDAR_HOUR, hour); + values.PutInt(Instance::CALENDAR_MINUTE, minute); +} + +const std::string ReminderRequestCalendar::Instance::REPEAT_DAYS = "repeat_days"; +const std::string ReminderRequestCalendar::Instance::REPEAT_MONTHS = "repeat_months"; +const std::string ReminderRequestCalendar::Instance::FIRST_DESIGNATE_YEAR = "first_designate_year"; +const std::string ReminderRequestCalendar::Instance::FIRST_DESIGNATE_MONTH = "first_designate_month"; +const std::string ReminderRequestCalendar::Instance::FIRST_DESIGNATE_DAY = "first_designate_day"; +const std::string ReminderRequestCalendar::Instance::CALENDAR_YEAR = "calendar_year"; +const std::string ReminderRequestCalendar::Instance::CALENDAR_MONTH = "calendar_month"; +const std::string ReminderRequestCalendar::Instance::CALENDAR_DAY = "calendar_day"; +const std::string ReminderRequestCalendar::Instance::CALENDAR_HOUR = "calendar_hour"; +const std::string ReminderRequestCalendar::Instance::CALENDAR_MINUTE = "calendar_minute"; + +std::string ReminderRequestCalendar::Instance::SQL_ADD_COLUMNS = ""; +std::vector ReminderRequestCalendar::Instance::COLUMNS; + +void ReminderRequestCalendar::Instance::Init() +{ + AddColumn(REPEAT_DAYS, "INT", false); + AddColumn(REPEAT_MONTHS, "INT", false); + AddColumn(FIRST_DESIGNATE_YEAR, "INT", false); + AddColumn(FIRST_DESIGNATE_MONTH, "INT", false); + AddColumn(FIRST_DESIGNATE_DAY, "INT", false); + AddColumn(CALENDAR_YEAR, "INT", false); + AddColumn(CALENDAR_MONTH, "INT", false); + AddColumn(CALENDAR_DAY, "INT", false); + AddColumn(CALENDAR_HOUR, "INT", false); + AddColumn(CALENDAR_MINUTE, "INT", false); +} + +void ReminderRequestCalendar::Instance::AddColumn( + const std::string &name, const std::string &type, const bool &isEnd) +{ + COLUMNS.push_back(name); + if (!isEnd) { + SQL_ADD_COLUMNS += name + " " + type + ", "; + } else { + SQL_ADD_COLUMNS += name + " " + type; + } +} } } \ No newline at end of file diff --git a/frameworks/ans/native/src/reminder_store.cpp b/frameworks/ans/native/src/reminder_store.cpp new file mode 100644 index 000000000..58a618b93 --- /dev/null +++ b/frameworks/ans/native/src/reminder_store.cpp @@ -0,0 +1,647 @@ +/* + * Copyright (c) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "ans_log_wrapper.h" +#include "reminder_const.h" +#include "reminder_request_alarm.h" +#include "reminder_request_calendar.h" +#include "reminder_request_timer.h" + +#include "reminder_store.h" + +using namespace OHOS::Notification::ReminderAgent; + +namespace OHOS { +namespace Notification { +const std::string ReminderStore::REMINDER_DB_DIR = "/data/user/0/reminder/"; // todo replace path +const std::string ReminderStore::REMINDER_DB_NAME = "reminder.db"; +const uint32_t ReminderStore::REMINDER_RDB_VERSION = 1; + +int32_t ReminderStore::ReminderStoreDataCallBack::OnCreate(NativeRdb::RdbStore &store) +{ + ANSR_LOGD("Create table."); + ReminderRequest::Instance::Init(); + ReminderRequestCalendar::Instance::Init(); + ReminderRequestAlarm::Instance::Init(); + std::string CREATE_REMINDER_TABLE = "CREATE TABLE IF NOT EXISTS " + REMINDER_DB_TABLE + " (" + + ReminderRequest::Instance::SQL_ADD_COLUMNS + + ReminderRequestCalendar::Instance::SQL_ADD_COLUMNS + + ReminderRequestAlarm::Instance::SQL_ADD_COLUMNS + ")"; + return store.ExecuteSql(CREATE_REMINDER_TABLE); +} + +int32_t ReminderStore::ReminderStoreDataCallBack::OnUpgrade(NativeRdb::RdbStore &store, int32_t oldVersion, int32_t newVersion) +{ + return NativeRdb::E_OK; +} + +int32_t ReminderStore::Init() +{ + ANSR_LOGD("Reminder store init."); + + /* std::filesystem::path databaseDir(REMINDER_DB_DIR); + ANSR_LOGD("ReminderStore::%{public}s databaseDir.", __func__); + if (!std::filesystem::exists(databaseDir)) { + bool createDir = std::filesystem::create_directories(REMINDER_DB_DIR); + ANSR_LOGD("ReminderStore::%{public}s createDir.", __func__); + if (!createDir) { + ANSR_LOGE("ReminderStore::%{public}s failed to create directory %{public}s", __func__, REMINDER_DB_DIR.c_str()); + } + } */ + + int32_t errCode(STATE_FAIL); + std::string dbConfig = ReminderStore::REMINDER_DB_DIR + ReminderStore::REMINDER_DB_NAME; + NativeRdb::RdbStoreConfig config_(dbConfig); + ReminderStoreDataCallBack rdbDataCallBack_; + rdbStore_ = NativeRdb::RdbHelper::GetRdbStore(config_, REMINDER_RDB_VERSION, rdbDataCallBack_, errCode); + if (rdbStore_ == nullptr) { + ANSR_LOGE("ReminderStore init fail, errCode %{public}d.", errCode); + return errCode; + } + return ReminderStore::InitData(); +} + +int32_t ReminderStore::InitData() +{ + ANSR_LOGD("Reminder data init."); + + struct timeb now; + ftime(&now); + time_t nowTime = now.time; + nowTime -= TIME_INTERVAL_FOR_DELETE; + int64_t overDueRtcTime = nowTime * MILLI_SECONDS + now.millitm; + ANSR_LOGD("OverDueRtcTime: %{public}lld.", overDueRtcTime); + ReminderStore::DeleteRtcTime(overDueRtcTime); + + std::string deleteCondition = ReminderRequest::Instance::IS_EXPIRED + " = true"; + ReminderStore::Delete(deleteCondition); + + int32_t statusChangedRows = STATE_FAIL; + NativeRdb::ValuesBucket statusValues; + statusValues.PutInt(ReminderRequest::Instance::STATE, ReminderRequest::GetConstStateInactive()); + int32_t statusResult = rdbStore_->Update(statusChangedRows, REMINDER_DB_TABLE, statusValues); + ANSR_LOGD("Status changed rows: %{public}d.", statusChangedRows); + + int32_t activeChangedRows = STATE_FAIL; + NativeRdb::ValuesBucket activeValues; + activeValues.PutString(ReminderRequest::Instance::IS_ACTIVE, "false"); + std::string activeUpdateCondition = ReminderRequest::Instance::IS_ACTIVE + " = true"; + std::vector activeWhereArgs; + int32_t activeResult = rdbStore_->Update( + activeChangedRows, REMINDER_DB_TABLE, activeValues, activeUpdateCondition, activeWhereArgs); + ANSR_LOGD("Active changed rows: %{public}d.", activeChangedRows); + + int32_t scheduledChangedRows = STATE_FAIL; + NativeRdb::ValuesBucket scheduledValues; + scheduledValues.PutString(ReminderRequest::Instance::HAS_SCHEDULED_TIMEOUT, "false"); + std::string scheduledUpdateCondition = ReminderRequest::Instance::HAS_SCHEDULED_TIMEOUT + " = true"; + std::vector scheduledWhereArgs; + int32_t scheduledResult = rdbStore_->Update( + scheduledChangedRows, REMINDER_DB_TABLE, scheduledValues, scheduledUpdateCondition, scheduledWhereArgs); + ANSR_LOGD("Scheduled changed rows: %{public}d.", scheduledChangedRows); + + if (statusResult != NativeRdb::E_OK || activeResult != NativeRdb::E_OK + || scheduledResult != NativeRdb::E_OK) { + ANSR_LOGE("Init data failed."); + return STATE_FAIL; + } + return STATE_OK; +} + +int32_t ReminderStore::Delete(int32_t reminderId) +{ + std::string deleteCondition = ReminderRequest::Instance::REMINDER_ID + + " = " + std::to_string(reminderId); + return ReminderStore::Delete(deleteCondition); +} + +int32_t ReminderStore::DeleteUser(int32_t userId) +{ + std::string deleteCondition = ReminderRequest::Instance::USER_ID + " = " + std::to_string(userId); + return ReminderStore::Delete(deleteCondition); +} + +int32_t ReminderStore::Delete(const std::string &pkg, int32_t userId) +{ + std::string deleteCondition = ReminderRequest::Instance::PKG_NAME + " = " + pkg + " and " + + ReminderRequest::Instance::USER_ID + " = " + std::to_string(userId); + return ReminderStore::Delete(deleteCondition); +} + +int32_t ReminderStore::DeleteRtcTime(int64_t rtcTime) +{ + std::string deleteCondition = ReminderRequest::Instance::RTC_TRIGGER_TIME + + " < " + std::to_string(rtcTime); + return ReminderStore::Delete(deleteCondition); +} + +int32_t ReminderStore::Delete(const std::string &deleteCondition) +{ + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return STATE_FAIL; + } + int32_t deletedRows = STATE_FAIL; + std::vector whereArgs; + int32_t result = rdbStore_->Delete(deletedRows, REMINDER_DB_TABLE, deleteCondition, whereArgs); + if (result != NativeRdb::E_OK) { + ANSR_LOGE("Delete operation failed, deleteConditon: %{public}s," \ + "result: %{public}d.", deleteCondition.c_str(), result); + } + ANSR_LOGD("Delete operation done, deleteConditon: %{public}s," \ + "deleted rows: %{public}d.", deleteCondition.c_str(), deletedRows); + return deletedRows; +} + +int64_t ReminderStore::UpdateOrInsert(const sptr &reminder) +{ + if (reminder->GetReminderType() == ReminderRequest::ReminderType::TIMER) { + ANSR_LOGI("Countdown not support persist."); + return STATE_FAIL; + } + int64_t isSuccess = STATE_FAIL; + if (IsReminderExist(reminder)) { + isSuccess = ReminderStore::Update(reminder); + } else { + isSuccess = ReminderStore::Insert(reminder); + } + return isSuccess; +} + +int64_t ReminderStore::Insert(const sptr &reminder) +{ + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return STATE_FAIL; + } + int64_t rowId = STATE_FAIL; + NativeRdb::ValuesBucket values; + ReminderStore::GenerateData(reminder, values); + int32_t result = rdbStore_->Insert(rowId, REMINDER_DB_TABLE, values); + if (result != NativeRdb::E_OK) { + ANSR_LOGE("Insert operation failed, result: %{public}d, row id: %{public}lld.", result, rowId); + } + ANSR_LOGD("Insert successfully, row id: %{public}lld.", rowId); + return result; +} + +int64_t ReminderStore::Update(const sptr &reminder) +{ + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return STATE_FAIL; + } + int32_t changedRows = STATE_FAIL; + NativeRdb::ValuesBucket values; + ReminderStore::GenerateData(reminder, values); + std::string updateCondition = ReminderRequest::Instance::REMINDER_ID + + " = " + std::to_string(reminder->GetReminderId()); + std::vector whereArgs; + int32_t result = rdbStore_->Update(changedRows, REMINDER_DB_TABLE, values, updateCondition, whereArgs); + if ((result != NativeRdb::E_OK) || (changedRows <= 0)) { + ANSR_LOGE("Update operation failed, result: %{public}d, updated rows: %{public}d.", result, changedRows); + } + ANSR_LOGD("Update successfully, updated rows: %{public}d.", changedRows); + return result; +} + +bool ReminderStore::IsReminderExist(const sptr &reminder) +{ + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return false; + } + std::string queryCondition = "select * from " + REMINDER_DB_TABLE + " where " + + ReminderRequest::Instance::REMINDER_ID + " = " + + std::to_string(reminder->GetReminderId()); + std::vector whereArgs; + std::unique_ptr queryResultSet = rdbStore_->QuerySql(queryCondition, whereArgs); + if (queryResultSet == nullptr) { + ANSR_LOGE("QueryResultSet is null."); + return false; + } + int32_t resultNum; + queryResultSet->GetRowCount(resultNum); + if (resultNum == 0) { + return false; + } + return true; +} + +std::shared_ptr ReminderStore::Query(const std::string &queryCondition) const +{ + std::unique_ptr queryResultSet; + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return queryResultSet; + } + std::vector whereArgs; + queryResultSet = rdbStore_->QuerySql(queryCondition, whereArgs); + return queryResultSet; +} + +std::vector ReminderStore::GetRepeatInfo(int64_t repeatData, int32_t maxRepeatVal) +{ + std::vector repeatInfo; + for (int i = 1; i <= maxRepeatVal; i++) { + if ((repeatData & (1 << (i - 1))) > 0) { + repeatInfo.push_back(i); + } + } + return repeatInfo; +} + +int32_t ReminderStore::GetMaxId() +{ + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return STATE_FAIL; + } + std::string queryCondition = "select * from " + REMINDER_DB_TABLE + " order by " + + ReminderRequest::Instance::REMINDER_ID + " desc"; // todo * + std::shared_ptr queryResultSet = ReminderStore::Query(queryCondition); + if (queryResultSet == nullptr) { + ANSR_LOGE("QueryResultSet is null."); + return STATE_FAIL; + } + int32_t resultNum; + queryResultSet->GetRowCount(resultNum); + if (resultNum == 0) { + ANSR_LOGI("QueryResultSet is zero."); + return STATE_FAIL; + } + queryResultSet->GoToNextRow(); + int32_t maxId = STATE_FAIL; + int32_t result = queryResultSet->GetInt(0, maxId); + if (result != NativeRdb::E_OK) { + ANSR_LOGE("Query operation failed, result %{public}d.", result); + } + ANSR_LOGD("MaxId: %{public}d.", maxId); + return maxId; +} + +std::vector> ReminderStore::GetAllValidReminders() +{ + std::string queryCondition = "select * from " + REMINDER_DB_TABLE + " where " + + ReminderRequest::Instance::IS_EXPIRED + " = false order by " + + ReminderRequest::Instance::TRIGGER_TIME + " asc"; + return GetReminders(queryCondition); +} + +std::vector> ReminderStore::GetReminders(const std::string &queryCondition) +{ + std::vector> reminders; + if (rdbStore_ == nullptr) { + ANSR_LOGE("Rdb store is not initialized."); + return reminders; + } + std::shared_ptr queryResultSet = Query(queryCondition); + if (queryResultSet == nullptr) { + return reminders; + } + bool isAtLastRow = false; + queryResultSet->IsAtLastRow(isAtLastRow); + while(!isAtLastRow) { + queryResultSet->GoToNextRow(); + sptr reminder; + reminder = BuildReminder(queryResultSet); + reminders.push_back(reminder); + queryResultSet->IsAtLastRow(isAtLastRow); + } + ANSR_LOGD("~~~~size=%{public}d", reminders.size()); + return reminders; +} + +sptr ReminderStore::BuildReminder(const std::shared_ptr &resultSet) +{ + int32_t typeIndex; + int32_t idIndex; + resultSet->GetColumnIndex(ReminderRequest::Instance::REMINDER_TYPE, typeIndex); + resultSet->GetColumnIndex(ReminderRequest::Instance::USER_ID, idIndex); + int32_t reminderType; + int32_t reminderId; + resultSet->GetInt(typeIndex, reminderType); + resultSet->GetInt(idIndex, reminderId); + sptr reminder = nullptr; + switch (reminderType) { + case (static_cast(ReminderRequest::ReminderType::TIMER)): { + reminder = new ReminderRequestTimer(reminderId); + break; + } + case (static_cast(ReminderRequest::ReminderType::CALENDAR)): { + reminder = new ReminderRequestCalendar(reminderId); + break; + } + case (static_cast(ReminderRequest::ReminderType::ALARM)): { + reminder = new ReminderRequestAlarm(reminderId); + break; + } + default: { + ANSR_LOGE("ReminderType from database is error, reminderType %{public}d.", reminderType); + } + } + if (reminder != nullptr) { + // reminder->RecoveryFromDb(resultSet); // todo + ANSR_LOGI("BuildReminder success."); + } else { + ANSR_LOGW("BuildReminder fail."); + } + return reminder; +} + +bool ReminderStore::GetBundleOption(const int32_t &reminderId, sptr &bundleOption) const +{ + std::string queryCondition = "select " + ReminderRequest::Instance::PKG_NAME + ", " + + ReminderRequest::Instance::USER_ID + " from " + REMINDER_DB_TABLE + " where " + + ReminderRequest::Instance::REMINDER_ID + "=" + std::to_string(reminderId); + std::shared_ptr queryResultSet = Query(queryCondition); + if (queryResultSet == nullptr) { + return false; + } + bool isAtLastRow = false; + queryResultSet->IsAtLastRow(isAtLastRow); + if (isAtLastRow) { + return false; + } + queryResultSet->GoToNextRow(); + std::string pkgName; + GetStringVal(queryResultSet, ReminderRequest::Instance::PKG_NAME, pkgName); + int userId; + GetInt32Val(queryResultSet, ReminderRequest::Instance::USER_ID, userId); + int32_t uid = ReminderRequest::GetUid(userId, pkgName); + bundleOption->SetBundleName(pkgName); + bundleOption->SetUid(uid); + return true; +} + +void ReminderStore::GetInt32Val(std::shared_ptr &resultSet + , const std::string &name, int32_t &value) const +{ + int32_t columnIndex; + resultSet->GetColumnIndex(name, columnIndex); + resultSet->GetInt(columnIndex, value); // todo check outOf size +} + +void ReminderStore::GetStringVal(std::shared_ptr &resultSet + , const std::string &name, std::string &value) const +{ + int32_t columnIndex; + resultSet->GetColumnIndex(name, columnIndex); + resultSet->GetString(columnIndex, value); +} + +void ReminderStore::GenerateData(const sptr &reminder, NativeRdb::ValuesBucket &values) const +{ + // values.PutString(ReminderRequest::Instance::PKG_NAME, "aaa"); + // values.PutInt(ReminderRequest::Instance::USER_ID, 1); + // values.PutString(ReminderRequest::Instance::APP_LABEL, "bbb"); + // values.PutInt(ReminderRequest::Instance::REMINDER_TYPE, 1); + // values.PutLong(ReminderRequest::Instance::REMINDER_TIME, 1); + // values.PutLong(ReminderRequest::Instance::TRIGGER_TIME, 1); + // values.PutLong(ReminderRequest::Instance::RTC_TRIGGER_TIME, 1602068651948); + // values.PutLong(ReminderRequest::Instance::TIME_INTERVAL, 1); + // values.PutInt(ReminderRequest::Instance::SNOOZE_TIMES, 1); + // values.PutInt(ReminderRequest::Instance::DYNAMIC_SNOOZE_TIMES, 1); + // values.PutLong(ReminderRequest::Instance::RING_DURATION, 1); + // values.PutString(ReminderRequest::Instance::IS_EXPIRED, "true"); + // values.PutString(ReminderRequest::Instance::IS_ACTIVE, "true"); + // values.PutInt(ReminderRequest::Instance::STATE, 1); + // values.PutInt(ReminderRequest::Instance::NOTIFICATION_ID, 1); + ReminderRequest::AppendValuesBucket(reminder, values); + ReminderRequestCalendar::AppendValuesBucket(reminder, values); + ReminderRequestAlarm::AppendValuesBucket(reminder, values); + return values; +} + +/* std::string ReminderStore::ConvertIconToString(std::shared_ptr &icon) +{ + Media::ImageInfo imageInfo; + icon->GetImageInfo(imageInfo); + uint64_t bufferSize = imageInfo.size.width * imageInfo.size.height; + Media::Rect region = {0, 0, imageInfo.size.width, imageInfo.size.height}; + uint8_t dst[bufferSize]; + icon->ReadPixels(bufferSize, 0, imageInfo.size.width, region, dst); + std::string base64Icon = iconhandler_.EncodeToBase64(dst, bufferSize); + std::string compressedIcon; + iconhandler_.CompressString(base64Icon, compressedIcon); + return compressedIcon + SEP_POUND_ICON + std::to_string(imageInfo.size.width) + SEP_POUND_ICON + std::to_string(imageInfo.size.height); +} + +std::shared_ptr ReminderStore::ConvertStringToIcon(const std::string &icon) +{ + std::vector info = iconhandler_.StringSplit(icon, SEP_POUND_ICON); + int32_t width = atoi(info[1].c_str()); + int32_t height = atoi(info[2].c_str()); + Media::InitializationOptions initializationOptions; + initializationOptions.size = {width, height}; + initializationOptions.pixelFormat = Media::PixelFormat::ARGB_8888; + std::string unCompressedIcon; + iconhandler_.DecompressString(info[0], unCompressedIcon); + uint32_t colorLength = initializationOptions.size.height * initializationOptions.size.width; + uint32_t colors[colorLength]; + iconhandler_.DecodeBase64(unCompressedIcon, colorLength, colors); + std::shared_ptr pixelMap = Media::PixelMap::Create(colors, colorLength, initializationOptions); + return pixelMap; +} + +std::string ReminderStore::IconHandler::EncodeToBase64(const uint8_t *dst, const uint64_t &bufferSize) +{ + if (dst == nullptr) { + ANSR_LOGE("ReminderStore::%{public}s buffer input dst address is null.", __func__); + return ""; + } + uint64_t curSize = bufferSize; + std::string ret; + int32_t i = 0; + int32_t j = 0; + uint8_t charArrayThree[3]; + uint8_t charArrayFour[4]; + while (curSize--) { + charArrayThree[i++] = *(dst++); + if (i == 3) { + charArrayFour[0] = (charArrayThree[0] & 0xfc) >> 2; + charArrayFour[1] = ((charArrayThree[0] & 0x03) << 4) + ((charArrayThree[1] & 0xf0) >> 4); + charArrayFour[2] = ((charArrayThree[1] & 0x0f) << 2) + ((charArrayThree[2] & 0xc0) >> 6); + charArrayFour[3] = charArrayThree[2] & 0x3f; + for (i = 0; i < 4; i++) { + ret += BASE64_CHARS[charArrayFour[i]]; + } + i = 0; + } + } + if(i) { + for (j = i; j < 3; j++) { + charArrayThree[j] = '\0'; + } + charArrayFour[0] = (charArrayThree[0] & 0xfc) >> 2; + charArrayFour[1] = ((charArrayThree[0] & 0x03) << 4) + ((charArrayThree[1] & 0xf0) >> 4); + charArrayFour[2] = ((charArrayThree[1] & 0x0f) << 2) + ((charArrayThree[2] & 0xc0) >> 6); + charArrayFour[3] = charArrayThree[2] & 0x3f; + for (j = 0; j < i + 1; j++) { + ret += BASE64_CHARS[charArrayFour[j]]; + } + while (i++ < 3) { + ret += '='; + } + } + return ret; +} + +uint8_t ReminderStore::IconHandler::DecodeBase64(const std::string &base64, const uint32_t colorLength, uint32_t *dst) +{ + int32_t length = base64.size(); + int32_t i = 0; + int32_t j = 0; + int index = 0; + int colorIndex = 0; + uint8_t charArrayThree[3]; + uint8_t charArrayFour[4]; + while (length-- && (base64[index] != '=') && ReminderStore::IconHandler::IsBase64(base64[index])) { + charArrayFour[i++] = base64[index]; + index++; + if (i == 4) { + for (i = 0; i < 4; i++) { + charArrayFour[i] = BASE64_CHARS.find(charArrayFour[i]); + } + charArrayThree[0] = (charArrayFour[0] << 2) + ((charArrayFour[1] & 0x30) >> 4); + charArrayThree[1] = ((charArrayFour[1] & 0xf) << 4) + ((charArrayFour[2] & 0x3c) >> 2); + charArrayThree[2] = ((charArrayFour[2] & 0x3) << 6) + charArrayFour[3]; + for (i = 0; i < 3; i++) { + dst[colorIndex++] = charArrayThree[i]; + } + i = 0; + } + } + if (i) { + for (j = i; j < 4; j++) { + charArrayFour[j] = 0; + } + for (j = 0; j < 4; j++) { + charArrayFour[j] = BASE64_CHARS.find(charArrayFour[j]); + } + charArrayThree[0] = (charArrayFour[0] << 2) + ((charArrayFour[1] & 0x30) >> 4); + charArrayThree[1] = ((charArrayFour[1] & 0xf) << 4) + ((charArrayFour[2] & 0x3c) >> 2); + charArrayThree[2] = ((charArrayFour[2] & 0x3) << 6) + charArrayFour[3]; + for (j = 0; j < i - 1; j++) { + dst[colorIndex++] = charArrayThree[j]; + } + } + return STATE_OK; +} + +inline bool ReminderStore::IconHandler::IsBase64(const char character) { + return (isalnum(character) || (character == '+') || (character == '/')); +} + +std::vector ReminderStore::IconHandler::IntToByte(int32_t num) +{ + std::vector bytes(4); + bytes[0] = (int8_t) ((num >> 24) & 0xff); + bytes[1] = (int8_t) ((num >> 16) & 0xff); + bytes[2] = (int8_t) ((num >> 8) & 0xff); + bytes[3] = (int8_t) (num & 0xff); + return bytes; +} + +int32_t ReminderStore::IconHandler::ByteToInt(const std::vector &bytes) +{ + return (bytes[0] & 0xff) << 24 | (bytes[1] & 0xff) << 16 | (bytes[2] & 0xff) << 8 | (bytes[3] & 0xff); +} + +int32_t ReminderStore::IconHandler::CompressString(const std::string &inputStr, std::string &outputStr) +{ + z_stream zs; + memset_s(&zs, sizeof zs, 0, sizeof zs); + if (deflateInit(&zs, Z_BEST_COMPRESSION) != Z_OK) { + ANSR_LOGE("ReminderStore::%{public}s deflateInit failed while compressing.", __func__); + return STATE_FAIL; + } + zs.next_in = const_cast(reinterpret_cast(inputStr.data())); + zs.avail_in = inputStr.size(); + + int ret; + char outBuffer[BUFFER_SIZE]; + std::string compressedStr; + do { + zs.next_out = reinterpret_cast(outBuffer); + zs.avail_out = sizeof(outBuffer); + ret = deflate(&zs, Z_FINISH); + if (compressedStr.size() < zs.total_out) { + compressedStr.append(outBuffer, zs.total_out - compressedStr.size()); + } + } while (ret == Z_OK); + + deflateEnd(&zs); + if (ret != Z_STREAM_END) { + ANSR_LOGE("ReminderStore::%{public}s: Exception during zlib compression! ret: %{public}d, message: %{public}s.", __func__, ret, zs.msg); + return STATE_FAIL; + } + outputStr = compressedStr; + return STATE_OK; +} + +int32_t ReminderStore::IconHandler::DecompressString(const std::string &inputStr, std::string &outputStr) +{ + z_stream zs; + memset_s(&zs, sizeof zs, 0, sizeof zs); + if (inflateInit(&zs) != Z_OK) { + ANSR_LOGE("ReminderStore::%{public}s deflateInit failed while compressing.", __func__); + return STATE_FAIL; + } + zs.next_in = const_cast(reinterpret_cast(inputStr.data())); + zs.avail_in = inputStr.size(); + + int ret; + char outBuffer[BUFFER_SIZE]; + std::string decompressedStr; + do { + zs.next_out = reinterpret_cast(outBuffer); + zs.avail_out = sizeof(outBuffer); + ret = inflate(&zs, 0); + if (decompressedStr.size() < zs.total_out) { + decompressedStr.append(outBuffer, zs.total_out - decompressedStr.size()); + } + } while (ret == Z_OK); + + inflateEnd(&zs); + if (ret != Z_STREAM_END) { + ANSR_LOGE("ReminderStore::%{public}s: Exception during zlib decompression! ret: %{public}d, message: %{public}s.", __func__, ret, zs.msg); + return STATE_FAIL; + } + outputStr = decompressedStr; + return STATE_OK; +} + +std::vector ReminderStore::IconHandler::StringSplit(std::string source, std::string split) +{ + size_t pos = 0; + std::vector result; + while ((pos = source.find(split)) != std::string::npos) { + std::string token = source.substr(0, pos); + if (!token.empty()) { + result.push_back(token); + } + source.erase(0, pos + split.length()); + } + if (!source.empty()) { + result.push_back(source); + } + return result; +} */ +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/reminder_const.h b/interfaces/innerkits/ans/native/include/reminder_const.h new file mode 100644 index 000000000..88c3379d6 --- /dev/null +++ b/interfaces/innerkits/ans/native/include/reminder_const.h @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_CONST_H +#define BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_CONST_H + +#include +#include + +namespace OHOS { +namespace Notification { +namespace ReminderAgent { +const int32_t STATE_FAIL = -1; +const int32_t STATE_OK = 0; + +/* const int32_t BUFFER_SIZE = 8192; */ +const uint16_t TIME_INTERVAL_FOR_DELETE = 1800; +const uint16_t MILLI_SECONDS = 1000; + +const std::string REMINDER_DB_TABLE = "reminder"; +/* const std::string SEP_POUND_ICON = "#"; +const std::string BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; */ + +// ReminderRequest column name +// const std::string ACTION_BUTTON_INFO = "button_info"; +// const std::string AGENT = "agent"; +// const std::string APP_LABEL = "app_label"; +// const std::string CONTENT = "content"; +// const std::string DYNAMIC_SNOOZE_TIMES = "dynamic_snooze_times"; +// const std::string EXPIRED_CONTENT = "expired_content"; +// const std::string HAS_SCHEDULED_TIMEOUT = "has_ScheduledTimeout"; +// const std::string IS_ACTIVE = "is_active"; +// const std::string IS_EXPIRED = "is_expired"; +// const std::string MAX_SCREEN_AGENT = "maxScreen_agent"; +// const std::string NOTIFICATION_ID = "notification_id"; +// const std::string PKG_NAME = "package_name"; +// const std::string REMINDER_ID = "reminder_id"; +// const std::string REMINDER_TIME = "reminder_time"; +// const std::string REMINDER_TYPE = "reminder_type"; +// const std::string RING_DURATION = "ring_duration"; +// const std::string RTC_TRIGGER_TIME = "rtc_trigger_time"; +// const std::string SLOT_ID = "slot_id"; +// const std::string SNOOZE_CONTENT = "snooze_content"; +// const std::string SNOOZE_TIMES = "snooze_times"; +// const std::string STATE = "state"; +// const std::string TIME_INTERVAL = "time_interval"; +// const std::string TITLE = "title"; +// const std::string TRIGGER_TIME = "trigger_time"; +// const std::string USER_ID = "user_id"; +// const std::string ZONE_ID = "zone_id"; +// /* const std::string REMINDER_DATA_ICON = "icon"; */ + +// // ReminderRequestCalendar column name +// const std::string CALENDAR_YEAR = "calendar_year"; +// const std::string CALENDAR_MONTH = "calendar_month"; +// const std::string CALENDAR_DAY = "calendar_day"; +// const std::string CALENDAR_HOUR = "calendar_hour"; +// const std::string CALENDAR_MINUTE = "calendar_minute"; +// const std::string FIRST_DESIGNATE_YEAR = "first_designate_year"; +// const std::string FIRST_DESIGNATE_MONTH = "first_designate_month"; +// const std::string FIRST_DESIGNATE_DAY = "first_designate_day"; +// const std::string REPEAT_DAYS = "repeat_days"; +// const std::string REPEAT_MONTHS = "repeat_months"; + +// // ReminderRequestAlarm column name +// const std::string ALARM_HOUR = "alarm_hour"; +// const std::string ALARM_MINUTE = "alarm_minute"; +// const std::string REPEAT_DAYS_OF_WEEK = "repeat_days_of_week"; + +// // create reminder table +// const std::string CREATE_REMINDER_TABLE = "CREATE TABLE IF NOT EXISTS " + REMINDER_DB_TABLE + " (" +// + REMINDER_ID + " INTEGER PRIMARY KEY, " +// + PKG_NAME + " TEXT NOT NULL, " +// + USER_ID + " INT NOT NULL, " +// + APP_LABEL + " TEXT, " +// + REMINDER_TYPE + " INT NOT NULL, " +// + REMINDER_TIME + " BIGINT NOT NULL, " +// + TRIGGER_TIME + " BIGINT NOT NULL, " +// + RTC_TRIGGER_TIME + " BIGINT NOT NULL, " +// + TIME_INTERVAL + " BIGINT NOT NULL, " +// + SNOOZE_TIMES + " INT NOT NULL, " +// + DYNAMIC_SNOOZE_TIMES + " INT NOT NULL, " +// + RING_DURATION + " BIGINT NOT NULL, " +// + IS_EXPIRED + " TEXT NOT NULL, " +// + IS_ACTIVE + " TEXT NOT NULL, " +// + STATE + " TEXT NOT NULL, " +// + ZONE_ID + " TEXT, " +// + HAS_SCHEDULED_TIMEOUT + " TEXT, " +// + ACTION_BUTTON_INFO + " TEXT, " +// + SLOT_ID + " INT, " +// + NOTIFICATION_ID + " INT NOT NULL, " +// + TITLE + " TEXT, " +// + CONTENT + " TEXT, " +// + SNOOZE_CONTENT + " TEXT, " +// + EXPIRED_CONTENT + " TEXT, " +// /* + REMINDER_DATA_ICON + " TEXT, " */ +// + AGENT + " TEXT, " +// + MAX_SCREEN_AGENT + " TEXT, " + +// + REPEAT_DAYS + " INT, " +// + REPEAT_MONTHS + " INT, " +// + FIRST_DESIGNATE_YEAR + " INT, " +// + FIRST_DESIGNATE_MONTH + " INT, " +// + FIRST_DESIGNATE_DAY + " INT, " +// + CALENDAR_YEAR + " INT, " +// + CALENDAR_MONTH + " INT, " +// + CALENDAR_DAY + " INT, " +// + CALENDAR_HOUR + " INT, " +// + CALENDAR_MINUTE + " INT, " + +// + REPEAT_DAYS_OF_WEEK + " INT, " +// + ALARM_HOUR + " INT, " +// + ALARM_MINUTE + " INT)"; +} // namespace ReminderAgent +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_CONST_H \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index b67141415..d344805f9 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -19,8 +19,10 @@ #include #include +#include "notification_bundle_option.h" #include "notification_constant.h" #include "notification_request.h" +#include "values_bucket.h" namespace OHOS { namespace Notification { @@ -129,6 +131,16 @@ public: * @param Indicates the exist reminder. */ explicit ReminderRequest(const ReminderRequest &other); + + /** + * @brief This constructor should only be used in background proxy service process + * when reminder instance recovery from database. + * + * @param reminderId Indicates reminder id. + */ + explicit ReminderRequest(int32_t reminderId) { + reminderId_ = reminderId; + } ReminderRequest& operator = (const ReminderRequest &other); virtual ~ReminderRequest() override {}; @@ -514,6 +526,8 @@ public: */ void UpdateNotificationRequest(UpdateNotificationType type, std::string extra); + static uint8_t GetConstStateInactive(); + static int32_t GLOBAL_ID; static const uint64_t INVALID_LONG_LONG_VALUE; static const uint16_t INVALID_U16_VALUE; @@ -549,6 +563,47 @@ 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); + static void AppendValuesBucket(const sptr &reminder, + sptr &bundleOption, NativeRdb::ValuesBucket &values); + +class Instance { +public: + const static std::string REMINDER_ID; + const static std::string PKG_NAME; + const static std::string USER_ID; + const static std::string APP_LABEL; + const static std::string REMINDER_TYPE; + const static std::string REMINDER_TIME; + const static std::string TRIGGER_TIME; + const static std::string RTC_TRIGGER_TIME; + const static std::string TIME_INTERVAL; + const static std::string SNOOZE_TIMES; + const static std::string DYNAMIC_SNOOZE_TIMES; + const static std::string RING_DURATION; + const static std::string IS_EXPIRED; + const static std::string IS_ACTIVE; + const static std::string STATE; + const static std::string ZONE_ID; + const static std::string HAS_SCHEDULED_TIMEOUT; + const static std::string ACTION_BUTTON_INFO; + const static std::string SLOT_ID; + const static std::string NOTIFICATION_ID; + const static std::string TITLE; + const static std::string CONTENT; + const static std::string SNOOZE_CONTENT; + const static std::string EXPIRED_CONTENT; + const static std::string AGENT; + const static std::string MAX_SCREEN_AGENT; + + static std::string SQL_ADD_COLUMNS; + static std::vector COLUMNS; + static void Init(); + +private: + static void AddColumn(const std::string &name, const std::string &type, const bool &isEnd); +}; protected: ReminderRequest(); @@ -564,6 +619,7 @@ private: void AddActionButtons(const bool includeSnooze); void AddRemovalWantAgent(); std::shared_ptr CreateWantAgent(AppExecFwk::ElementName &element) const; + std::string GetButtonInfo() const; uint64_t GetNowInstantMilli() const; std::string GetShowTime(const uint64_t showTime) const; std::string GetTimeInfoInner(const time_t &timeInSecond, const TimeFormat &format) const; @@ -599,6 +655,9 @@ private: static const uint8_t REMINDER_STATUS_SHOWING; static const uint8_t REMINDER_STATUS_SNOOZE; static const uint32_t MIN_TIME_INTERVAL_IN_MILLI; + static const std::string SEP_BUTTON_SINGLE; + static const std::string SEP_BUTTON_MULTI; + static const std::string SEP_WANT_AGENT; std::string content_ {}; std::string expiredContent_ {}; diff --git a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h index 07239f1ea..bcde481fa 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h @@ -40,6 +40,14 @@ public: */ ReminderRequestAlarm(uint8_t hour, uint8_t minute, std::vector daysOfWeek); + /** + * @brief This constructor should only be used in background proxy service process + * when reminder instance recovery from database. + * + * @param reminderId Indicates reminder id. + */ + ReminderRequestAlarm(int32_t reminderId) : ReminderRequest(reminderId) {}; + /** * @brief Copy construct from an exist reminder. * @@ -97,6 +105,23 @@ public: */ bool ReadFromParcel(Parcel &parcel) override; + static void AppendValuesBucket(const sptr &reminder, + sptr &bundleOption, NativeRdb::ValuesBucket &values); + +class Instance { +public: + const static std::string REPEAT_DAYS_OF_WEEK; + const static std::string ALARM_HOUR; + const static std::string ALARM_MINUTE; + + static std::string SQL_ADD_COLUMNS; + static std::vector COLUMNS; + static void Init(); + +private: + static void AddColumn(const std::string &name, const std::string &type, const bool &isEnd); +}; + protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; diff --git a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h index 8c6868e98..9cbb2fe78 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h @@ -52,6 +52,14 @@ public: ReminderRequestCalendar(const tm &dateTime, const std::vector &repeatMonths, const std::vector &repeatDays); + /** + * @brief This constructor should only be used in background proxy service process + * when reminder instance recovery from database. + * + * @param reminderId Indicates reminder id. + */ + ReminderRequestCalendar(int32_t reminderId) : ReminderRequest(reminderId) {}; + explicit ReminderRequestCalendar(const ReminderRequestCalendar &other); ReminderRequestCalendar& operator = (const ReminderRequestCalendar &other); ~ReminderRequestCalendar() override {} @@ -133,6 +141,29 @@ public: static const uint8_t MAX_MONTHS_OF_YEAR; static const uint8_t MAX_DAYS_OF_MONTH; + static void AppendValuesBucket(const sptr &reminder, + sptr &bundleOption, NativeRdb::ValuesBucket &values); + +class Instance { +public: + const static std::string REPEAT_DAYS; + const static std::string REPEAT_MONTHS; + const static std::string FIRST_DESIGNATE_YEAR; + const static std::string FIRST_DESIGNATE_MONTH; + const static std::string FIRST_DESIGNATE_DAY; + const static std::string CALENDAR_YEAR; + const static std::string CALENDAR_MONTH; + const static std::string CALENDAR_DAY; + const static std::string CALENDAR_HOUR; + const static std::string CALENDAR_MINUTE; + + static std::string SQL_ADD_COLUMNS; + static std::vector COLUMNS; + static void Init(); + +private: + static void AddColumn(const std::string &name, const std::string &type, const bool &isEnd); +}; protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; @@ -144,6 +175,12 @@ private: uint8_t GetNextDay(const uint16_t &settedYear, const uint8_t &settedMonth, const tm &now, const tm &target) const; uint64_t GetNextTriggerTime() const; uint64_t GetNextTriggerTimeAsRepeatReminder(const tm &nowTime, const tm &tarTime) const; + uint32_t GetRepeatDay() const { + return repeatDay_; + } + uint16_t GetRepeatMonth() const { + return repeatMonth_; + } uint64_t GetTimeInstantMilli( uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) const; diff --git a/interfaces/innerkits/ans/native/include/reminder_request_timer.h b/interfaces/innerkits/ans/native/include/reminder_request_timer.h index 9fc2362f2..46bf1a28c 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_timer.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_timer.h @@ -33,6 +33,14 @@ public: */ ReminderRequestTimer(uint64_t countDownTimeInSeconds); + /** + * @brief This constructor should only be used in background proxy service process + * when reminder instance recovery from database. + * + * @param reminderId Indicates reminder id. + */ + ReminderRequestTimer(int32_t reminderId) : ReminderRequest(reminderId) {}; + /** * @brief Copy construct from an exist reminder. * diff --git a/interfaces/innerkits/ans/native/include/reminder_store.h b/interfaces/innerkits/ans/native/include/reminder_store.h new file mode 100644 index 000000000..f6e9b4e8f --- /dev/null +++ b/interfaces/innerkits/ans/native/include/reminder_store.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_STORE_H +#define BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_STORE_H + +#include + +#include "notification_bundle_option.h" +#include "pixel_map.h" +#include "reminder_request.h" +#include "rdb_errno.h" +#include "rdb_helper.h" +#include "rdb_open_callback.h" +#include "rdb_store_config.h" + +namespace OHOS { +namespace Notification { +class ReminderStore { +public: + ReminderStore() {}; + virtual ~ReminderStore() {}; + int32_t Init(); + int32_t Delete(int32_t reminderId); + int32_t Delete(const std::string &pkg, int32_t userId); + int32_t DeleteUser(int32_t userId); + std::vector> GetAllValidReminders(); + bool GetBundleOption(const int32_t &reminderId, sptr &bundleOption) const; + int32_t GetMaxId(); + int64_t UpdateOrInsert(const sptr &reminder); + /* std::string ConvertIconToString(std::shared_ptr &icon); + std::shared_ptr ConvertStringToIcon(const std::string &icon); */ + static std::vector GetRepeatInfo(int64_t repeatData, int32_t maxRepeatVal); + +private: + /** + * @brief Inits the data in database when system boot on or proxy process reboot on. + * + * 1. Deletes all the reminders which TRIGGER_TIME is less than now-30min. + * 2. Deletes all the reminders which IS_EXPIRED is true. + * 3. Sets all the value of STATE to ReminderRequest::REMINDER_STATUS_INACTIVE + * 4. Sets all the value of IS_ACTIVE to false. + * 5. Sets all the value of HAS_SCHEDULED_TIMEOUT to false. + * + * @return int32_t + */ + int32_t InitData(); + sptr BuildReminder(const std::shared_ptr &resultSet); + int32_t Delete(const std::string &deleteCondition); + int32_t DeleteRtcTime(int64_t rtcTime); + void GetInt32Val(std::shared_ptr &resultSet + , const std::string &name, int32_t &value) const; + void GetStringVal(std::shared_ptr &resultSet + , const std::string &name, std::string &value) const; + std::vector> GetReminders(const std::string &queryCondition); + void GenerateData(const sptr &remindert, NativeRdb::ValuesBucket &values) const; + bool IsReminderExist(const sptr &reminder); + int64_t Insert(const sptr &reminder); + std::shared_ptr Query(const std::string &queryCondition) const; + int64_t Update(const sptr &reminder); + +private: + static const std::string REMINDER_DB_DIR; + static const std::string REMINDER_DB_NAME; + static const uint32_t REMINDER_RDB_VERSION; + +private: + /* class IconHandler { + public: + std::string EncodeToBase64(const uint8_t *dst, const uint64_t &bufferSize); + uint8_t DecodeBase64(const std::string &base64, const uint32_t colorLength, uint32_t *dst); + std::vector IntToByte(int32_t num); + int32_t ByteToInt(const std::vector &bytes); + int32_t CompressString(const std::string &inputStr, std::string &outputStr); + int32_t DecompressString(const std::string &inputStr, std::string &outputStr); + inline bool IsBase64(const char character); + std::vector StringSplit(std::string source, std::string split = ","); + }; */ + +class ReminderStoreDataCallBack : public NativeRdb::RdbOpenCallback { +public: + int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; + int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override; +}; + +private: + std::shared_ptr rdbStore_; + /* ReminderStore::IconHandler iconhandler_; */ +}; + +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_ANS_STANDARD_INTERFACES_INNERKITS_ANS_NATIVE_INCLUDE_REMINDER_STORE_H \ No newline at end of file diff --git a/notification.gni b/notification.gni index 8a5ca46ca..d51ab2aa0 100644 --- a/notification.gni +++ b/notification.gni @@ -39,6 +39,7 @@ ans_standard_external_deps = [ "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "native_appdatamgr:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index c1167f1ba..6b8c24676 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -21,14 +21,18 @@ #include "advanced_notification_service.h" #include "player.h" +#include "reminder_const.h" #include "reminder_request.h" +#include "reminder_store.h" #include "reminder_timer_info.h" namespace OHOS { namespace Notification { class ReminderDataManager final { public: - ReminderDataManager() {}; + ReminderDataManager() { + Init(false); + }; ~ReminderDataManager() {}; ReminderDataManager(ReminderDataManager &other) = delete; @@ -79,6 +83,13 @@ public: void GetValidReminders( const sptr bundleOption, std::vector> &reminders); + /** + * @brief Inits and recovery data from database. + * + * @param isFromBootComplete Indicates the init is called when boot completed. + */ + void Init(bool isFromBootComplete); + /** * @brief Triggered when third party application died. * @@ -251,6 +262,8 @@ private: bool HandleSysTimeChange(const sptr reminder) const; + bool IsReminderAgentReady() const; + /** * Judge the two reminders is belong to the same application or not. * @@ -262,6 +275,8 @@ private: bool IsBelongToSameApp( const sptr reminder, const std::string otherPkgName, const int otherUserId); + void LoadReminderFromDb(); + void PlaySoundAndVibrationLocked(const sptr &reminder); void PlaySoundAndVibration(const sptr &reminder); void StopSoundAndVibrationLocked(const sptr &reminder); @@ -399,6 +414,8 @@ private: */ static const int16_t MAX_NUM_REMINDER_LIMIT_APP; + bool isReminderAgentReady_ = false; + /** * Vector used to record all the reminders in system. */ @@ -443,6 +460,7 @@ private: */ int16_t totalCount_ {0}; AdvancedNotificationService *advancedNotificationService_; + std::shared_ptr store_ = nullptr; }; } // namespace OHOS } // namespace Nofitifcation diff --git a/services/ans/include/reminder_event_manager.h b/services/ans/include/reminder_event_manager.h index 09c908f49..35f46ba0e 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/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 18f09d8b6..c66cdcc20 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -87,6 +87,9 @@ void ReminderDataManager::CancelNotification(const sptr &remind notification->GetNotificationId(), ReminderRequest::NOTIFICATION_LABEL, bundleOption); } +// todo CancelReminder(const sptr &bundleOption, int userId) +// todo CancelReminder(int userId) + bool ReminderDataManager::CheckReminderLimitExceededLocked(const std::string &bundleName) const { std::lock_guard lock(ReminderDataManager::MUTEX); @@ -237,7 +240,7 @@ std::shared_ptr ReminderDataManager::CreateTimerInfo(TimerTyp return sharedTimerInfo; } want->SetAction(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); - want->SetParam(ReminderRequest::PARAM_REMINDER_ID, alertingReminderId_); + want->SetParam(ReminderRequest::PARAM_REMINDER_ID, alertingReminderId_); // todo no need break; } default: @@ -335,6 +338,10 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b StartRecentReminder(); } +// todo OnSwitchUser() +// todo OnRemoveUser() +// todo OnInterruptChange() + std::shared_ptr ReminderDataManager::GetInstance() { if (REMINDER_DATA_MANAGER == nullptr) { @@ -399,6 +406,8 @@ void ReminderDataManager::TerminateAlerting(const sptr &reminde } ANSR_LOGD("publish(update) notification.(reminderId=%{public}d)", reminder->GetReminderId()); UpdateNotification(reminder); + ANSR_LOGD("~~~~~~~~~~~~~~~~content=%{public}s" + , notificationRequest->GetContent()->GetNotificationContent()->GetText().c_str()); advancedNotificationService_->PublishPreparedNotification(notificationRequest, bundleOption); } @@ -418,6 +427,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( ANSR_LOGD("Containers(vector) add. reminderId=%{public}d", reminderId); reminderVector_.push_back(reminder); totalCount_++; + store_->UpdateOrInsert(reminder); } void ReminderDataManager::SetService(AdvancedNotificationService *advancedNotificationService) @@ -486,7 +496,7 @@ void ReminderDataManager::ShowActiveReminderExtendLocked(sptr & if ((*it)->GetTriggerTimeInMilli() - triggerTime > ReminderRequest::SAME_TIME_DISTINGUISH_MILLISECONDS) { continue; } - if (!isAlerting) { + if (!isAlerting) { // todo isSoundOrVibratorDefined playSoundReminder = (*it); isAlerting = true; } else { @@ -503,6 +513,7 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co { ANSR_LOGD("Show the reminder(Play sound: %{public}d), %{public}s", static_cast(isNeedToPlaySound), reminder->Dump().c_str()); + // todo if (IsNotificationEnable(rem)) int32_t reminderId = reminder->GetReminderId(); sptr bundleOption = FindNotificationBundleOption(reminderId); sptr notificationRequest = reminder->GetNotificationRequest(); @@ -608,10 +619,18 @@ void ReminderDataManager::StartRecentReminder() StopTimerLocked(TimerType::TRIGGER_TIMER); activeReminder_->OnStop(); } - ANSR_LOGI("Start recent reminder"); - StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); - reminder->OnStart(); - SetActiveReminder(reminder); + // if (reminder->ShouldShowImmediately()) { // todo + // if (IsSoundOrVibratorDefined(reminder)) { + // ShowReminder(reminder, true, true, false, false); + // } else { + // ShowReminder(reminder, false, true, false, false); + // } + // } else { + ANSR_LOGI("Start recent reminder"); + StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); + reminder->OnStart(); + SetActiveReminder(reminder); + // } } void ReminderDataManager::StopAlertingReminder(const sptr &reminder) @@ -731,7 +750,7 @@ void ReminderDataManager::HandleImmediatelyShow( { bool isAlerting = false; for (auto it = showImmediately.begin(); it != showImmediately.end(); ++it) { - if (!isAlerting) { + if (!isAlerting) { // todo isSoundOrVibratorDefined ShowReminder((*it), true, false, isSysTimeChanged, false); isAlerting = true; } else { @@ -793,6 +812,33 @@ void ReminderDataManager::HandleSameNotificationIdShowing(const sptr(); + } + if (store_->Init() != ReminderAgent::STATE_OK) { + ANSR_LOGW("Db init fail."); + return; + } + LoadReminderFromDb(); + if (isFromBootComplete) { + // todo + } + StartRecentReminder(); + isReminderAgentReady_ = true; + ANSR_LOGD("ReminderAgent is ready."); +} + +bool ReminderDataManager::IsReminderAgentReady() const +{ + return isReminderAgentReady_; +} + bool ReminderDataManager::IsBelongToSameApp( const sptr reminder, const std::string otherPkgName, const int otherUserId) { @@ -809,6 +855,31 @@ bool ReminderDataManager::IsBelongToSameApp( return false; } +// todo IsBelongToSameUser + +void ReminderDataManager::LoadReminderFromDb() +{ + std::lock_guard lock(ReminderDataManager::MUTEX); + std::vector> existReminders = store_->GetAllValidReminders(); + reminderVector_ = existReminders; + ANSR_LOGD("LoadReminderFromDb, reminder size=%{public}d", reminderVector_.size()); + for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { + sptr bundleOption = new NotificationBundleOption(); + int32_t reminderId = (*it)->GetReminderId(); + if (!(store_->GetBundleOption(reminderId, bundleOption))) { + ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); + continue; + } + auto ret = notificationBundleOptionMap_.insert( + std::pair>(reminderId, bundleOption)); + if (!ret.second) { + ANSR_LOGE("Containers add to map error"); + continue; + } + } + ReminderRequest::GLOBAL_ID = store_->GetMaxId() + 1; +} + void ReminderDataManager::PlaySoundAndVibrationLocked(const sptr &reminder) { std::lock_guard lock(ReminderDataManager::ALERT_MUTEX); // todo check died lock @@ -880,6 +951,9 @@ void ReminderDataManager::StopSoundAndVibration(const sptr &rem SetAlertingReminder(nullReminder); } +// todo AddDefaultSlotIfNeeded +// todo IsNotificationEnable + void ReminderDataManager::RemoveFromShowedReminders(const sptr &reminder) { std::lock_guard lock(ReminderDataManager::SHOW_MUTEX); diff --git a/services/ans/src/reminder_event_manager.cpp b/services/ans/src/reminder_event_manager.cpp index d085adff0..e8ad9ec46 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" @@ -40,6 +37,7 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT); matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_CLOSE_ALERT); matchingSkills.AddEvent(ReminderRequest::REMINDER_EVENT_SNOOZE_ALERT); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); @@ -86,6 +84,11 @@ void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFw reminderDataManager_->CloseReminder(want, false); return; } + if (action == CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED) { + // todo judge major user + reminderDataManager_->Init(true); + return; + } if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { HandlePackageRemove(want); return; @@ -126,24 +129,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); + int32_t uid = ReminderRequest::GetUid(userId, bundleName); ANSR_LOGD("bundleName=%{public}s, uid=%{public}d", bundleName.c_str(), 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 -- Gitee From abc9c862d4a8bc20e1aa098213dbe133d9d63c3c Mon Sep 17 00:00:00 2001 From: derek Date: Sun, 30 Jan 2022 15:04:54 +0800 Subject: [PATCH 14/18] update Signed-off-by: derek Change-Id: I1e7cdf260692bb3849c4445611b852fd8b85bf4f --- .../ans/native/src/reminder_request.cpp | 2 +- .../ans/native/src/reminder_request_alarm.cpp | 2 +- .../native/src/reminder_request_calendar.cpp | 2 +- frameworks/ans/native/src/reminder_store.cpp | 27 ++++++++++--------- .../ans/native/include/reminder_request.h | 2 +- .../native/include/reminder_request_alarm.h | 2 +- .../include/reminder_request_calendar.h | 2 +- .../ans/native/include/reminder_store.h | 9 ++++--- services/ans/src/reminder_data_manager.cpp | 26 ++++++++++++------ 9 files changed, 44 insertions(+), 30 deletions(-) diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index ebcb776b9..e28bb0ceb 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -1233,7 +1233,7 @@ int ReminderRequest::GetUserId(const int &uid) } void ReminderRequest::AppendValuesBucket(const sptr &reminder, - sptr &bundleOption, NativeRdb::ValuesBucket &values) + const sptr &bundleOption, NativeRdb::ValuesBucket &values) { values.PutInt(Instance::REMINDER_ID, reminder->GetReminderId()); values.PutString(Instance::PKG_NAME, bundleOption->GetBundleName()); diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index cccbfb10a..c61258a80 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -303,7 +303,7 @@ bool ReminderRequestAlarm::ReadFromParcel(Parcel &parcel) } void ReminderRequestAlarm::AppendValuesBucket(const sptr &reminder, - sptr &bundleOption, NativeRdb::ValuesBucket &values) + const sptr &bundleOption, NativeRdb::ValuesBucket &values) { uint8_t repeatDays = 0; uint8_t hour = 0; diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index 77665e3ec..2b1b77117 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -493,7 +493,7 @@ bool ReminderRequestCalendar::ReadFromParcel(Parcel &parcel) } void ReminderRequestCalendar::AppendValuesBucket(const sptr &reminder, - sptr &bundleOption, NativeRdb::ValuesBucket &values) + const sptr &bundleOption, NativeRdb::ValuesBucket &values) { uint32_t repeatDay = 0; uint16_t repeatMonth = 0; diff --git a/frameworks/ans/native/src/reminder_store.cpp b/frameworks/ans/native/src/reminder_store.cpp index 58a618b93..490edd1e0 100644 --- a/frameworks/ans/native/src/reminder_store.cpp +++ b/frameworks/ans/native/src/reminder_store.cpp @@ -168,7 +168,8 @@ int32_t ReminderStore::Delete(const std::string &deleteCondition) return deletedRows; } -int64_t ReminderStore::UpdateOrInsert(const sptr &reminder) +int64_t ReminderStore::UpdateOrInsert( + const sptr &reminder, const sptr &bundleOption) { if (reminder->GetReminderType() == ReminderRequest::ReminderType::TIMER) { ANSR_LOGI("Countdown not support persist."); @@ -176,14 +177,15 @@ int64_t ReminderStore::UpdateOrInsert(const sptr &reminder) } int64_t isSuccess = STATE_FAIL; if (IsReminderExist(reminder)) { - isSuccess = ReminderStore::Update(reminder); + isSuccess = ReminderStore::Update(reminder, bundleOption); } else { - isSuccess = ReminderStore::Insert(reminder); + isSuccess = ReminderStore::Insert(reminder, bundleOption); } return isSuccess; } -int64_t ReminderStore::Insert(const sptr &reminder) +int64_t ReminderStore::Insert( + const sptr &reminder, const sptr &bundleOption) { if (rdbStore_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); @@ -191,7 +193,7 @@ int64_t ReminderStore::Insert(const sptr &reminder) } int64_t rowId = STATE_FAIL; NativeRdb::ValuesBucket values; - ReminderStore::GenerateData(reminder, values); + ReminderStore::GenerateData(reminder, bundleOption, values); int32_t result = rdbStore_->Insert(rowId, REMINDER_DB_TABLE, values); if (result != NativeRdb::E_OK) { ANSR_LOGE("Insert operation failed, result: %{public}d, row id: %{public}lld.", result, rowId); @@ -200,7 +202,8 @@ int64_t ReminderStore::Insert(const sptr &reminder) return result; } -int64_t ReminderStore::Update(const sptr &reminder) +int64_t ReminderStore::Update( + const sptr &reminder, const sptr &bundleOption) { if (rdbStore_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); @@ -208,7 +211,7 @@ int64_t ReminderStore::Update(const sptr &reminder) } int32_t changedRows = STATE_FAIL; NativeRdb::ValuesBucket values; - ReminderStore::GenerateData(reminder, values); + ReminderStore::GenerateData(reminder, bundleOption, values); std::string updateCondition = ReminderRequest::Instance::REMINDER_ID + " = " + std::to_string(reminder->GetReminderId()); std::vector whereArgs; @@ -405,7 +408,8 @@ void ReminderStore::GetStringVal(std::shared_ptr resultSet->GetString(columnIndex, value); } -void ReminderStore::GenerateData(const sptr &reminder, NativeRdb::ValuesBucket &values) const +void ReminderStore::GenerateData(const sptr &reminder, + const sptr &bundleOption, NativeRdb::ValuesBucket &values) const { // values.PutString(ReminderRequest::Instance::PKG_NAME, "aaa"); // values.PutInt(ReminderRequest::Instance::USER_ID, 1); @@ -422,10 +426,9 @@ void ReminderStore::GenerateData(const sptr &reminder, NativeRd // values.PutString(ReminderRequest::Instance::IS_ACTIVE, "true"); // values.PutInt(ReminderRequest::Instance::STATE, 1); // values.PutInt(ReminderRequest::Instance::NOTIFICATION_ID, 1); - ReminderRequest::AppendValuesBucket(reminder, values); - ReminderRequestCalendar::AppendValuesBucket(reminder, values); - ReminderRequestAlarm::AppendValuesBucket(reminder, values); - return values; + ReminderRequest::AppendValuesBucket(reminder, bundleOption, values); + ReminderRequestCalendar::AppendValuesBucket(reminder, bundleOption, values); + ReminderRequestAlarm::AppendValuesBucket(reminder, bundleOption, values); } /* std::string ReminderStore::ConvertIconToString(std::shared_ptr &icon) diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index d344805f9..bde9414d9 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -566,7 +566,7 @@ public: static int32_t GetUid(const int &userId, const std::string &bundleName); static int GetUserId(const int &uid); static void AppendValuesBucket(const sptr &reminder, - sptr &bundleOption, NativeRdb::ValuesBucket &values); + const sptr &bundleOption, NativeRdb::ValuesBucket &values); class Instance { public: diff --git a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h index bcde481fa..18ddd2898 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h @@ -106,7 +106,7 @@ public: bool ReadFromParcel(Parcel &parcel) override; static void AppendValuesBucket(const sptr &reminder, - sptr &bundleOption, NativeRdb::ValuesBucket &values); + const sptr &bundleOption, NativeRdb::ValuesBucket &values); class Instance { public: diff --git a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h index 9cbb2fe78..d85d224c6 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h @@ -142,7 +142,7 @@ public: static const uint8_t MAX_MONTHS_OF_YEAR; static const uint8_t MAX_DAYS_OF_MONTH; static void AppendValuesBucket(const sptr &reminder, - sptr &bundleOption, NativeRdb::ValuesBucket &values); + const sptr &bundleOption, NativeRdb::ValuesBucket &values); class Instance { public: diff --git a/interfaces/innerkits/ans/native/include/reminder_store.h b/interfaces/innerkits/ans/native/include/reminder_store.h index f6e9b4e8f..d698dc250 100644 --- a/interfaces/innerkits/ans/native/include/reminder_store.h +++ b/interfaces/innerkits/ans/native/include/reminder_store.h @@ -39,7 +39,7 @@ public: std::vector> GetAllValidReminders(); bool GetBundleOption(const int32_t &reminderId, sptr &bundleOption) const; int32_t GetMaxId(); - int64_t UpdateOrInsert(const sptr &reminder); + int64_t UpdateOrInsert(const sptr &reminder, const sptr &bundleOption); /* std::string ConvertIconToString(std::shared_ptr &icon); std::shared_ptr ConvertStringToIcon(const std::string &icon); */ static std::vector GetRepeatInfo(int64_t repeatData, int32_t maxRepeatVal); @@ -65,11 +65,12 @@ private: void GetStringVal(std::shared_ptr &resultSet , const std::string &name, std::string &value) const; std::vector> GetReminders(const std::string &queryCondition); - void GenerateData(const sptr &remindert, NativeRdb::ValuesBucket &values) const; + void GenerateData(const sptr &remindert, + const sptr &bundleOption, NativeRdb::ValuesBucket &values) const; bool IsReminderExist(const sptr &reminder); - int64_t Insert(const sptr &reminder); + int64_t Insert(const sptr &reminder, const sptr &bundleOption); std::shared_ptr Query(const std::string &queryCondition) const; - int64_t Update(const sptr &reminder); + int64_t Update(const sptr &reminder, const sptr &bundleOption); private: static const std::string REMINDER_DB_DIR; diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index c66cdcc20..f7bbb0843 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -214,6 +214,7 @@ void ReminderDataManager::OnProcessDiedLocked(const sptrUpdateOrInsert } } @@ -332,6 +333,7 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b } reminder->OnClose(true); RemoveFromShowedReminders(reminder); + // todo store_->UpdateOrInsert if (cancelNotification) { CancelNotification(reminder); } @@ -409,6 +411,7 @@ void ReminderDataManager::TerminateAlerting(const sptr &reminde ANSR_LOGD("~~~~~~~~~~~~~~~~content=%{public}s" , notificationRequest->GetContent()->GetNotificationContent()->GetText().c_str()); advancedNotificationService_->PublishPreparedNotification(notificationRequest, bundleOption); + // todo store_->UpdateOrInsert } void ReminderDataManager::UpdateAndSaveReminderLocked( @@ -427,7 +430,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( ANSR_LOGD("Containers(vector) add. reminderId=%{public}d", reminderId); reminderVector_.push_back(reminder); totalCount_++; - store_->UpdateOrInsert(reminder); + store_->UpdateOrInsert(reminder, bundleOption); } void ReminderDataManager::SetService(AdvancedNotificationService *advancedNotificationService) @@ -548,6 +551,8 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co } else { HandleSameNotificationIdShowing(reminder); } + // todo store_->UpdateOrInsert + if (isNeedToStartNext) { StartRecentReminder(); } @@ -587,6 +592,7 @@ void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) StopSoundAndVibrationLocked(reminder); } reminder->OnSnooze(); + // todo store_->UpdateOrInsert // 2) Show the notification dialog in the systemUI sptr bundleOption = FindNotificationBundleOption(reminderId); @@ -618,6 +624,7 @@ void ReminderDataManager::StartRecentReminder() if (activeReminderId_ != -1) { StopTimerLocked(TimerType::TRIGGER_TIMER); activeReminder_->OnStop(); + // todo store_->UpdateOrInsert() } // if (reminder->ShouldShowImmediately()) { // todo // if (IsSoundOrVibratorDefined(reminder)) { @@ -629,6 +636,7 @@ void ReminderDataManager::StartRecentReminder() ANSR_LOGI("Start recent reminder"); StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); reminder->OnStart(); + // todo store_->UpdateOrInsert() SetActiveReminder(reminder); // } } @@ -713,16 +721,16 @@ 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); notificationBundleOptionMap_.erase(mit); } it = reminderVector_.erase(it); totalCount_--; + // todo store_->Delete(reminderId); } return nullptr; } @@ -772,14 +780,14 @@ 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); } + // todo store_->UpdateOrInsert return nullptr; - } else { - return reminder; } + // todo store_->UpdateOrInsert + return reminder; } void ReminderDataManager::HandleSameNotificationIdShowing(const sptr reminder) @@ -808,6 +816,7 @@ void ReminderDataManager::HandleSameNotificationIdShowing(const sptrOnSameNotificationIdCovered(); RemoveFromShowedReminders(*it); + // todo store_->UpdateOrInsert } } } @@ -987,6 +996,7 @@ void ReminderDataManager::RemoveReminderLocked(const int32_t &reminderId) ANSR_LOGD("Containers(vector) remove. reminderId=%{public}d", reminderId); it = reminderVector_.erase(it); totalCount_--; + // todo store_->Delete(reminderId); break; } else { ++it; -- Gitee From 51c9fd608178488a7e89f32bcded0b1b0f934ffb Mon Sep 17 00:00:00 2001 From: derek Date: Mon, 7 Feb 2022 10:10:04 +0800 Subject: [PATCH 15/18] fix build error Signed-off-by: derek Change-Id: I86e1e1c464f2633f2e23ba26c0ae1478c3710938 --- interfaces/kits/napi/ans/BUILD.gn | 1 + interfaces/kits/napi/ans/src/reminder/BUILD.gn | 1 + 2 files changed, 2 insertions(+) diff --git a/interfaces/kits/napi/ans/BUILD.gn b/interfaces/kits/napi/ans/BUILD.gn index d13d88323..9fca9676a 100644 --- a/interfaces/kits/napi/ans/BUILD.gn +++ b/interfaces/kits/napi/ans/BUILD.gn @@ -83,6 +83,7 @@ ohos_shared_library("notification") { "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "napi:ace_napi", + "native_appdatamgr:native_rdb", ] relative_install_dir = "module" diff --git a/interfaces/kits/napi/ans/src/reminder/BUILD.gn b/interfaces/kits/napi/ans/src/reminder/BUILD.gn index 23107e158..33b24f002 100644 --- a/interfaces/kits/napi/ans/src/reminder/BUILD.gn +++ b/interfaces/kits/napi/ans/src/reminder/BUILD.gn @@ -71,6 +71,7 @@ ohos_shared_library("reminderagent") { "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "napi:ace_napi", + "native_appdatamgr:native_rdb", ] relative_install_dir = "module" -- Gitee From 4b4cb26811d161bfe3134251e0a539e8554ad570 Mon Sep 17 00:00:00 2001 From: derek Date: Mon, 7 Feb 2022 21:51:25 +0800 Subject: [PATCH 16/18] add reminderAgent init, add userId to reminderRequest and so on Signed-off-by: derek Change-Id: I983df9df7ec44f6067583375ee4917e0a3f1959f --- frameworks/ans/native/src/reminder_request.cpp | 9 +++++++-- .../innerkits/ans/native/include/reminder_request.h | 6 ++++++ .../include/advanced_notification_service_ability.h | 2 ++ services/ans/src/advanced_notification_service.cpp | 4 ---- .../ans/src/advanced_notification_service_ability.cpp | 3 +++ services/ans/src/reminder_data_manager.cpp | 10 ++++++++-- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index e28bb0ceb..91fe2a46e 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -167,6 +167,11 @@ void ReminderRequest::InitReminderId() ANSR_LOGI("reminderId_=%{public}d", reminderId_); } +void ReminderRequest::InitUserId(const int& userId) +{ + userId_ = userId; +} + bool ReminderRequest::IsExpired() const { return isExpired_; @@ -861,7 +866,6 @@ void ReminderRequest::InitNotificationRequest() ANSR_LOGI("Init notification"); notificationRequest_ = new NotificationRequest(notificationId_); displayContent_ = content_; - AddActionButtons(true); } bool ReminderRequest::IsAlerting() const @@ -1032,7 +1036,8 @@ void ReminderRequest::AddRemovalWantAgent() wants, nullptr ); - std::shared_ptr wantAgent = WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); + std::shared_ptr wantAgent + = WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); notificationRequest_->SetRemovalWantAgent(wantAgent); } diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index bde9414d9..4b5f1517f 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -281,6 +281,11 @@ public: */ void InitReminderId(); + /** + * @brief Inits reminder userId when publish reminder success. + */ + void InitUserId(const int& userId); + /** * @brief Check the reminder is alerting or not. * @@ -670,6 +675,7 @@ private: uint8_t state_ {0}; int32_t notificationId_ {0}; int32_t reminderId_ {-1}; + int userId_ {0}; // 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/advanced_notification_service_ability.h b/services/ans/include/advanced_notification_service_ability.h index ec5c866d8..5ebdf2f02 100644 --- a/services/ans/include/advanced_notification_service_ability.h +++ b/services/ans/include/advanced_notification_service_ability.h @@ -20,6 +20,7 @@ #include "advanced_notification_service.h" #include "system_ability_definition.h" +#include "reminder_data_manager.h" namespace OHOS { namespace Notification { @@ -36,6 +37,7 @@ private: private: sptr service_; + std::shared_ptr reminderAgent_; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index facee75ca..cb88bde20 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1572,7 +1572,6 @@ ErrCode AdvancedNotificationService::CancelContinuousTaskNotification(const std: ErrCode AdvancedNotificationService::PublishReminder(sptr &reminder) { ANSR_LOGI("Publish reminder"); - ReminderDataManager::GetInstance()->SetService(this); sptr notificationRequest = reminder->GetNotificationRequest(); sptr bundleOption = nullptr; ErrCode result = PrepareNotificationInfo(notificationRequest, bundleOption); @@ -1587,7 +1586,6 @@ ErrCode AdvancedNotificationService::PublishReminder(sptr &remi ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) { ANSR_LOGI("Cancel Reminder"); - ReminderDataManager::GetInstance()->SetService(this); sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -1599,7 +1597,6 @@ ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) ErrCode AdvancedNotificationService::CancelAllReminders() { ANSR_LOGI("Cancel all reminders"); - ReminderDataManager::GetInstance()->SetService(this); sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; @@ -1611,7 +1608,6 @@ ErrCode AdvancedNotificationService::CancelAllReminders() ErrCode AdvancedNotificationService::GetValidReminders(std::vector> &reminders) { ANSR_LOGI("GetValidReminders"); - ReminderDataManager::GetInstance()->SetService(this); reminders.clear(); sptr bundleOption = GenerateBundleOption(); if (bundleOption == nullptr) { diff --git a/services/ans/src/advanced_notification_service_ability.cpp b/services/ans/src/advanced_notification_service_ability.cpp index 56f052fb8..c96691618 100644 --- a/services/ans/src/advanced_notification_service_ability.cpp +++ b/services/ans/src/advanced_notification_service_ability.cpp @@ -38,11 +38,14 @@ void AdvancedNotificationServiceAbility::OnStart() if (!Publish(service_)) { return; } + reminderAgent_ = ReminderDataManager::GetInstance(); + reminderAgent_->SetService(static_cast(service_.GetRefPtr())); } void AdvancedNotificationServiceAbility::OnStop() { service_ = nullptr; + reminderAgent_ = nullptr; } } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index f7bbb0843..bccd5eb59 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -144,6 +144,7 @@ void ReminderDataManager::CancelAllReminders(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) { @@ -419,6 +424,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( @@ -725,7 +731,7 @@ sptr ReminderDataManager::GetRecentReminderLocked() if (mit == notificationBundleOptionMap_.end()) { 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); -- Gitee From 08c74ab36b2e5cdd55957c8dac863e0346883673 Mon Sep 17 00:00:00 2001 From: derek Date: Thu, 10 Feb 2022 22:54:50 +0800 Subject: [PATCH 17/18] update store Signed-off-by: derek Change-Id: Idecbc70e783e7c23ffdd699c878380771a1646f9 --- .../ans/native/src/reminder_request.cpp | 255 +++++++++++++++++- .../ans/native/src/reminder_request_alarm.cpp | 21 ++ .../native/src/reminder_request_calendar.cpp | 29 ++ frameworks/ans/native/src/reminder_store.cpp | 93 ++++--- frameworks/ans/native/test/unittest/BUILD.gn | 1 + .../unittest/reminder_request_alarm_test.cpp | 77 +++--- .../reminder_request_calendar_test.cpp | 63 +++-- .../test/unittest/reminder_request_test.cpp | 179 +++++++----- .../unittest/reminder_request_timer_test.cpp | 21 +- .../ans/test/moduletest/ReminderHelperTest.js | 54 ++-- .../wantagent/src/want_agent_helper.cpp | 48 +++- .../ans/native/include/reminder_request.h | 52 +++- .../native/include/reminder_request_alarm.h | 2 +- .../include/reminder_request_calendar.h | 1 + .../ans/native/include/reminder_store.h | 2 + .../wantagent/include/want_agent_helper.h | 3 +- services/ans/include/reminder_data_manager.h | 11 +- .../ans/src/advanced_notification_service.cpp | 23 +- .../advanced_notification_service_ability.cpp | 2 + services/ans/src/reminder_data_manager.cpp | 36 ++- services/ans/src/reminder_event_manager.cpp | 9 +- 21 files changed, 742 insertions(+), 240 deletions(-) diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index 91fe2a46e..d4db8dd13 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -22,6 +22,7 @@ #include "want_agent_helper.h" #include "reminder_request.h" +#include "reminder_store.h" namespace OHOS { namespace Notification { @@ -52,9 +53,7 @@ const std::string ReminderRequest::SEP_WANT_AGENT = ""; ReminderRequest::ReminderRequest() { - wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; - maxScreenWantAgentInfo_ = - maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; + InitServerObj(); } ReminderRequest::ReminderRequest(const ReminderRequest &other) @@ -82,12 +81,16 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) this->actionButtonMap_ = other.actionButtonMap_; } +ReminderRequest::ReminderRequest(int32_t reminderId) +{ + reminderId_ = reminderId; + InitServerObj(); +} + ReminderRequest::ReminderRequest(ReminderType reminderType) { reminderType_ = reminderType; - wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; - maxScreenWantAgentInfo_ = - maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; + InitServerObj(); } bool ReminderRequest::CanRemove() const @@ -125,6 +128,23 @@ std::string ReminderRequest::Dump() const "]"; } +// std::string ReminderRequest::DumpAll() const +// { +// const time_t nextTriggerTime = static_cast(triggerTimeInMilli_ / MILLI_SECONDS); +// std::string dateTimeInfo = GetTimeInfoInner(nextTriggerTime, TimeFormat::YMDHMS); +// return "Reminder[" +// "reminderId=" + std::to_string(reminderId_) + +// ", type=" + std::to_string(static_cast(reminderType_)) + +// ", state=" + GetState(state_) + +// ", nextTriggerTime=" + dateTimeInfo.c_str() + +// ", content=" + content_ + +// ", expiredContent=" + expiredContent_ + +// ", snoozeContent=" + snoozeContent_ + +// ", title=" + title_ + +// ", isExpired" +// "]"; +// } + ReminderRequest& ReminderRequest::SetActionButton(const std::string &title, const ActionButtonType &type) { if (type != ActionButtonType::CLOSE && type != ActionButtonType::SNOOZE) { @@ -167,11 +187,16 @@ void ReminderRequest::InitReminderId() ANSR_LOGI("reminderId_=%{public}d", reminderId_); } -void ReminderRequest::InitUserId(const int& userId) +void ReminderRequest::InitUserId(const int &userId) { userId_ = userId; } +void ReminderRequest::InitUid(const int32_t &uid) +{ + uid_ = uid; +} + bool ReminderRequest::IsExpired() const { return isExpired_; @@ -373,6 +398,188 @@ bool ReminderRequest::OnTimeZoneChange() return HandleTimeZoneChange(oldZoneTriggerTime, newZoneTriggerTime, nextTriggerTime); } +int64_t ReminderRequest::RecoveryInt64FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType) +{ + if (columnType == DbRecoveryType::INT) { + int value; + resultSet->GetInt(ReminderStore::GetColumnIndex(columnName), value); + return static_cast(value); + } + if (columnType == DbRecoveryType::LONG) { + int64_t value; + resultSet->GetLong(ReminderStore::GetColumnIndex(columnName), value); + return value; + } + ANSR_LOGE("Recovery data error"); + return 0; +} + +void ReminderRequest::RecoveryUint64FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint64_t &attribute) +{ + if (columnType == DbRecoveryType::INT) { + int value; + resultSet->GetInt(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else if (columnType == DbRecoveryType::LONG) { + int64_t value; + resultSet->GetLong(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else { + ANSR_LOGE("Recovery data error"); + } +} + +void ReminderRequest::RecoveryUint32FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint32_t &attribute) +{ + if (columnType == DbRecoveryType::INT) { + int value; + resultSet->GetInt(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else if (columnType == DbRecoveryType::LONG) { + int64_t value; + resultSet->GetLong(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else { + ANSR_LOGE("Recovery data error"); + } +} + +void ReminderRequest::RecoveryUint8FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint8_t &attribute) +{ + if (columnType == DbRecoveryType::INT) { + int value; + resultSet->GetInt(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else if (columnType == DbRecoveryType::LONG) { + int64_t value; + resultSet->GetLong(ReminderStore::GetColumnIndex(columnName), value); + attribute = static_cast(value); + } else { + ANSR_LOGE("Recovery data error"); + } +} + +void ReminderRequest::RecoveryFromDb(const std::shared_ptr &resultSet) +{ + // reminderId + resultSet->GetInt(ReminderStore::GetColumnIndex(Instance::REMINDER_ID), reminderId_); + + // userId + resultSet->GetInt(ReminderStore::GetColumnIndex(Instance::USER_ID), userId_); + + // uid + resultSet->GetInt(ReminderStore::GetColumnIndex(Instance::UID), uid_); + + // reminderType + int reminderType; + resultSet->GetInt(ReminderStore::GetColumnIndex(Instance::REMINDER_TYPE), reminderType); + reminderType_ = ReminderType(reminderType); // todo check + + // reminderTime + // RecoveryUint64FromDb(resultSet, Instance::REMINDER_TIME, DbRecoveryType::INT, reminderTimeInMilli_); + reminderTimeInMilli_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::REMINDER_TIME, DbRecoveryType::INT)); + + // triggerTime + // RecoveryUint64FromDb(resultSet, Instance::TRIGGER_TIME, DbRecoveryType::INT, triggerTimeInMilli_); + triggerTimeInMilli_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::TRIGGER_TIME, DbRecoveryType::INT)); + + // timeInterval + uint64_t timeIntervalInSecond = + static_cast(RecoveryInt64FromDb(resultSet, Instance::TIME_INTERVAL, DbRecoveryType::INT)); + // RecoveryUint64FromDb(resultSet, Instance::TIME_INTERVAL, DbRecoveryType::INT, timeIntervalInSecond); + SetTimeInterval(timeIntervalInSecond); + + // snoozeTimes + // RecoveryUint8FromDb(resultSet, Instance::SNOOZE_TIMES, DbRecoveryType::INT, snoozeTimes_); + snoozeTimes_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::SNOOZE_TIMES, DbRecoveryType::INT)); + + // dynamicSnoozeTimes + // RecoveryUint8FromDb(resultSet, Instance::DYNAMIC_SNOOZE_TIMES, DbRecoveryType::INT, snoozeTimesDynamic_); + snoozeTimesDynamic_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::DYNAMIC_SNOOZE_TIMES, DbRecoveryType::INT)); + + // ringDuration + uint64_t ringDurationInSecond = + static_cast(RecoveryInt64FromDb(resultSet, Instance::RING_DURATION, DbRecoveryType::LONG)); + // RecoveryUint64FromDb(resultSet, Instance::RING_DURATION, DbRecoveryType::LONG, ringDurationInSecond); + SetRingDuration(ringDurationInSecond); + + // isExpired + std::string isExpired; + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::IS_EXPIRED), isExpired); + isExpired_ = isExpired == "true" ? true : false; + + // state + // RecoveryUint8FromDb(resultSet, Instance::STATE, DbRecoveryType::INT, state_); + state_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::STATE, DbRecoveryType::INT)); + + // action buttons + RecoveryActionButton(resultSet); + + // slotType + // values.PutInt(Instance::SLOT_ID, reminder->GetSlotType()); + + // notification id + resultSet->GetInt(ReminderStore::GetColumnIndex(Instance::NOTIFICATION_ID), notificationId_); + + // title + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::TITLE), title_); + + // content + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::CONTENT), content_); + + // snoozeContent + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::SNOOZE_CONTENT), snoozeContent_); + + // expiredContent + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::EXPIRED_CONTENT), expiredContent_); + + // wantAgent + + // maxWantAgent + + // auto wantAgentInfo = reminder->GetWantAgentInfo(); + // if (wantAgentInfo == nullptr) { + // std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; + // values.PutString(Instance::AGENT, info); + // } else { + // values.PutString(Instance::AGENT, wantAgentInfo->pkgName + // + ReminderRequest::SEP_WANT_AGENT + wantAgentInfo->abilityName); + // } + // auto maxScreenWantAgentInfo = reminder->GetMaxScreenWantAgentInfo(); + // if (maxScreenWantAgentInfo == nullptr) { + // std::string info = "null" + ReminderRequest::SEP_WANT_AGENT + "null"; + // values.PutString(Instance::MAX_SCREEN_AGENT, info); + // } else { + // values.PutString(Instance::MAX_SCREEN_AGENT, maxScreenWantAgentInfo->pkgName + // + ReminderRequest::SEP_WANT_AGENT + maxScreenWantAgentInfo->abilityName); + // } +} + +void ReminderRequest::RecoveryActionButton(const std::shared_ptr &resultSet) +{ + std::string actionButtonInfo; + resultSet->GetString(ReminderStore::GetColumnIndex(Instance::ACTION_BUTTON_INFO), actionButtonInfo); + + // std::string info = ""; + // bool isFirst = true; + // for (auto it = actionButtonMap_.begin(); it != actionButtonMap_.end(); ++it) { + // if (!isFirst) { + // info += SEP_BUTTON_MULTI; + // } + // ActionButtonInfo buttonInfo = it->second; + // info += std::to_string(static_cast(it->first)) + SEP_BUTTON_SINGLE + buttonInfo.title; + // isFirst = false; + // } + // return info; +} + ReminderRequest& ReminderRequest::SetMaxScreenWantAgentInfo( const std::shared_ptr &maxScreenWantAgentInfo) { @@ -566,6 +773,16 @@ uint64_t ReminderRequest::GetTriggerTimeInMilli() const return triggerTimeInMilli_; } +int ReminderRequest::GetUserId() const +{ + return userId_; +} + +int32_t ReminderRequest::GetUid() const +{ + return uid_; +} + std::shared_ptr ReminderRequest::GetWantAgentInfo() const { return wantAgentInfo_; @@ -868,6 +1085,13 @@ void ReminderRequest::InitNotificationRequest() displayContent_ = content_; } +void ReminderRequest::InitServerObj() +{ + wantAgentInfo_ = wantAgentInfo_ == nullptr ? std::make_shared() : wantAgentInfo_; + maxScreenWantAgentInfo_ = + maxScreenWantAgentInfo_ == nullptr ? std::make_shared() : maxScreenWantAgentInfo_; +} + bool ReminderRequest::IsAlerting() const { return (state_ & REMINDER_STATUS_ALERTING) != 0; @@ -901,7 +1125,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 @@ -1012,7 +1236,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); @@ -1037,7 +1261,7 @@ void ReminderRequest::AddRemovalWantAgent() nullptr ); std::shared_ptr wantAgent - = WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); + = WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); notificationRequest_->SetRemovalWantAgent(wantAgent); } @@ -1057,7 +1281,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) @@ -1139,7 +1363,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) @@ -1242,7 +1466,8 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, { values.PutInt(Instance::REMINDER_ID, reminder->GetReminderId()); values.PutString(Instance::PKG_NAME, bundleOption->GetBundleName()); - values.PutInt(Instance::USER_ID, GetUserId(bundleOption->GetUid())); + values.PutInt(Instance::USER_ID, reminder->GetUserId()); + values.PutInt(Instance::UID, reminder->GetUid()); values.PutString(Instance::APP_LABEL, ""); // no use values.PutInt(Instance::REMINDER_TYPE, static_cast(reminder->GetReminderType())); values.PutLong(Instance::REMINDER_TIME, reminder->GetReminderTimeInMilli()); @@ -1282,9 +1507,12 @@ void ReminderRequest::AppendValuesBucket(const sptr &reminder, } } + + const std::string ReminderRequest::Instance::REMINDER_ID = "reminder_id"; const std::string ReminderRequest::Instance::PKG_NAME = "package_name"; const std::string ReminderRequest::Instance::USER_ID = "user_id"; +const std::string ReminderRequest::Instance::UID = "uid"; const std::string ReminderRequest::Instance::APP_LABEL = "app_label"; const std::string ReminderRequest::Instance::REMINDER_TYPE = "reminder_type"; const std::string ReminderRequest::Instance::REMINDER_TIME = "reminder_time"; @@ -1317,6 +1545,7 @@ void ReminderRequest::Instance::Init() AddColumn(REMINDER_ID, "INTEGER PRIMARY KEY", false); AddColumn(PKG_NAME, "TEXT NOT NULL", false); AddColumn(USER_ID, "INT NOT NULL", false); + AddColumn(UID, "INT NOT NULL", false); AddColumn(APP_LABEL, "TEXT", false); AddColumn(REMINDER_TYPE, "INT NOT NULL", false); AddColumn(REMINDER_TIME, "BIGINT NOT NULL", false); diff --git a/frameworks/ans/native/src/reminder_request_alarm.cpp b/frameworks/ans/native/src/reminder_request_alarm.cpp index c61258a80..cf9a8bf83 100644 --- a/frameworks/ans/native/src/reminder_request_alarm.cpp +++ b/frameworks/ans/native/src/reminder_request_alarm.cpp @@ -16,6 +16,7 @@ #include "ans_log_wrapper.h" #include "reminder_request_alarm.h" +#include "reminder_store.h" namespace OHOS { namespace Notification { @@ -302,6 +303,26 @@ bool ReminderRequestAlarm::ReadFromParcel(Parcel &parcel) return true; } +void ReminderRequestAlarm::RecoveryFromDb(const std::shared_ptr &resultSet) +{ + ReminderRequest::RecoveryFromDb(resultSet); + + // repeatDays + // RecoveryUint8FromDb(resultSet, Instance::REPEAT_DAYS_OF_WEEK, ReminderRequest::DbRecoveryType::INT, repeatDays_); + repeatDays_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::REPEAT_DAYS_OF_WEEK, DbRecoveryType::INT)); + + // hour + // RecoveryUint8FromDb(resultSet, Instance::ALARM_HOUR, ReminderRequest::DbRecoveryType::INT, hour_); + hour_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::ALARM_HOUR, DbRecoveryType::INT)); + + // minute + // RecoveryUint8FromDb(resultSet, Instance::ALARM_MINUTE, ReminderRequest::DbRecoveryType::INT, minute_); + minute_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::ALARM_MINUTE, DbRecoveryType::INT)); +} + void ReminderRequestAlarm::AppendValuesBucket(const sptr &reminder, const sptr &bundleOption, NativeRdb::ValuesBucket &values) { diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index 2b1b77117..f7e5232c9 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -492,6 +492,35 @@ bool ReminderRequestCalendar::ReadFromParcel(Parcel &parcel) return true; } +void ReminderRequestCalendar::RecoveryFromDb(const std::shared_ptr &resultSet) +{ + ReminderRequest::RecoveryFromDb(resultSet); + + // repeatDay + // RecoveryUint32FromDb(resultSet, Instance::REPEAT_DAYS, ReminderRequest::DbRecoveryType::INT, repeatDay_); + + // repeatMonth + + + // firstDesignateYear + + // firstDesignateMonth + + // firstDesignateDay + + // year + + // month + + // day + + // hour + + // minute + + // second +} + void ReminderRequestCalendar::AppendValuesBucket(const sptr &reminder, const sptr &bundleOption, NativeRdb::ValuesBucket &values) { diff --git a/frameworks/ans/native/src/reminder_store.cpp b/frameworks/ans/native/src/reminder_store.cpp index 490edd1e0..e6fd40381 100644 --- a/frameworks/ans/native/src/reminder_store.cpp +++ b/frameworks/ans/native/src/reminder_store.cpp @@ -31,17 +31,16 @@ namespace Notification { const std::string ReminderStore::REMINDER_DB_DIR = "/data/user/0/reminder/"; // todo replace path const std::string ReminderStore::REMINDER_DB_NAME = "reminder.db"; const uint32_t ReminderStore::REMINDER_RDB_VERSION = 1; +std::vector ReminderStore::COLUMNS; int32_t ReminderStore::ReminderStoreDataCallBack::OnCreate(NativeRdb::RdbStore &store) { ANSR_LOGD("Create table."); - ReminderRequest::Instance::Init(); - ReminderRequestCalendar::Instance::Init(); - ReminderRequestAlarm::Instance::Init(); std::string CREATE_REMINDER_TABLE = "CREATE TABLE IF NOT EXISTS " + REMINDER_DB_TABLE + " (" + ReminderRequest::Instance::SQL_ADD_COLUMNS + ReminderRequestCalendar::Instance::SQL_ADD_COLUMNS + ReminderRequestAlarm::Instance::SQL_ADD_COLUMNS + ")"; + ANSR_LOGD("~~~createTable:%{public}s", CREATE_REMINDER_TABLE.c_str()); return store.ExecuteSql(CREATE_REMINDER_TABLE); } @@ -64,6 +63,16 @@ int32_t ReminderStore::Init() } } */ + ReminderRequest::Instance::Init(); + ReminderRequestCalendar::Instance::Init(); + ReminderRequestAlarm::Instance::Init(); + ReminderStore::COLUMNS.insert(ReminderStore::COLUMNS.begin() + , ReminderRequestAlarm::Instance::COLUMNS.begin(), ReminderRequestAlarm::Instance::COLUMNS.end()); + ReminderStore::COLUMNS.insert(ReminderStore::COLUMNS.begin() + , ReminderRequestCalendar::Instance::COLUMNS.begin(), ReminderRequestCalendar::Instance::COLUMNS.end()); + ReminderStore::COLUMNS.insert(ReminderStore::COLUMNS.begin() + , ReminderRequest::Instance::COLUMNS.begin(), ReminderRequest::Instance::COLUMNS.end()); + int32_t errCode(STATE_FAIL); std::string dbConfig = ReminderStore::REMINDER_DB_DIR + ReminderStore::REMINDER_DB_NAME; NativeRdb::RdbStoreConfig config_(dbConfig); @@ -83,37 +92,36 @@ int32_t ReminderStore::InitData() struct timeb now; ftime(&now); time_t nowTime = now.time; - nowTime -= TIME_INTERVAL_FOR_DELETE; - int64_t overDueRtcTime = nowTime * MILLI_SECONDS + now.millitm; + int64_t overDueRtcTime = (static_cast(nowTime) - TIME_INTERVAL_FOR_DELETE) * MILLI_SECONDS; ANSR_LOGD("OverDueRtcTime: %{public}lld.", overDueRtcTime); - ReminderStore::DeleteRtcTime(overDueRtcTime); + ReminderStore::DeleteRtcTime(overDueRtcTime); // todo check(cannot delete if it is a repeat reminder) - std::string deleteCondition = ReminderRequest::Instance::IS_EXPIRED + " = true"; + std::string deleteCondition = ReminderRequest::Instance::IS_EXPIRED + " is true"; ReminderStore::Delete(deleteCondition); int32_t statusChangedRows = STATE_FAIL; NativeRdb::ValuesBucket statusValues; statusValues.PutInt(ReminderRequest::Instance::STATE, ReminderRequest::GetConstStateInactive()); int32_t statusResult = rdbStore_->Update(statusChangedRows, REMINDER_DB_TABLE, statusValues); - ANSR_LOGD("Status changed rows: %{public}d.", statusChangedRows); + ANSR_LOGD("Change status to inactive, changed rows: %{public}d.", statusChangedRows); int32_t activeChangedRows = STATE_FAIL; NativeRdb::ValuesBucket activeValues; activeValues.PutString(ReminderRequest::Instance::IS_ACTIVE, "false"); - std::string activeUpdateCondition = ReminderRequest::Instance::IS_ACTIVE + " = true"; + std::string activeUpdateCondition = ReminderRequest::Instance::IS_ACTIVE + " is true"; std::vector activeWhereArgs; int32_t activeResult = rdbStore_->Update( activeChangedRows, REMINDER_DB_TABLE, activeValues, activeUpdateCondition, activeWhereArgs); - ANSR_LOGD("Active changed rows: %{public}d.", activeChangedRows); + ANSR_LOGD("Change status isActive to false, changed rows: %{public}d.", activeChangedRows); int32_t scheduledChangedRows = STATE_FAIL; NativeRdb::ValuesBucket scheduledValues; scheduledValues.PutString(ReminderRequest::Instance::HAS_SCHEDULED_TIMEOUT, "false"); - std::string scheduledUpdateCondition = ReminderRequest::Instance::HAS_SCHEDULED_TIMEOUT + " = true"; + std::string scheduledUpdateCondition = ReminderRequest::Instance::HAS_SCHEDULED_TIMEOUT + " is true"; std::vector scheduledWhereArgs; int32_t scheduledResult = rdbStore_->Update( scheduledChangedRows, REMINDER_DB_TABLE, scheduledValues, scheduledUpdateCondition, scheduledWhereArgs); - ANSR_LOGD("Scheduled changed rows: %{public}d.", scheduledChangedRows); + ANSR_LOGD("Change status has_ScheduledTimeout to false, changed rows: %{public}d.", scheduledChangedRows); if (statusResult != NativeRdb::E_OK || activeResult != NativeRdb::E_OK || scheduledResult != NativeRdb::E_OK) { @@ -196,9 +204,11 @@ int64_t ReminderStore::Insert( ReminderStore::GenerateData(reminder, bundleOption, values); int32_t result = rdbStore_->Insert(rowId, REMINDER_DB_TABLE, values); if (result != NativeRdb::E_OK) { - ANSR_LOGE("Insert operation failed, result: %{public}d, row id: %{public}lld.", result, rowId); + ANSR_LOGE("Insert operation failed, result: %{public}d, reminderId=%{public}d." + , result, reminder->GetReminderId()); + return result; } - ANSR_LOGD("Insert successfully, row id: %{public}lld.", rowId); + ANSR_LOGD("Insert successfully, reminderId=%{public}d.", reminder->GetReminderId()); return result; } @@ -217,9 +227,12 @@ int64_t ReminderStore::Update( std::vector whereArgs; int32_t result = rdbStore_->Update(changedRows, REMINDER_DB_TABLE, values, updateCondition, whereArgs); if ((result != NativeRdb::E_OK) || (changedRows <= 0)) { - ANSR_LOGE("Update operation failed, result: %{public}d, updated rows: %{public}d.", result, changedRows); + ANSR_LOGE("Update operation failed, result: %{public}d, updated rows: %{public}d, reminderId=%{public}d." + , result, changedRows, reminder->GetReminderId()); + return result; } - ANSR_LOGD("Update successfully, updated rows: %{public}d.", changedRows); + ANSR_LOGD("Update successfully, updated rows: %{public}d, reminderId=%{public}d." + , changedRows, reminder->GetReminderId()); return result; } @@ -269,6 +282,18 @@ std::vector ReminderStore::GetRepeatInfo(int64_t repeatData, int32_t ma return repeatInfo; } +uint8_t ReminderStore::GetColumnIndex(const std::string& name) +{ + uint8_t index = 0; + for (auto it = ReminderStore::COLUMNS.begin(); it != ReminderStore::COLUMNS.end(); ++it) { + if (name == (*it)) { + break; + } + index++; + } + return index; +} + int32_t ReminderStore::GetMaxId() { if (rdbStore_ == nullptr) { @@ -301,7 +326,7 @@ int32_t ReminderStore::GetMaxId() std::vector> ReminderStore::GetAllValidReminders() { std::string queryCondition = "select * from " + REMINDER_DB_TABLE + " where " - + ReminderRequest::Instance::IS_EXPIRED + " = false order by " + + ReminderRequest::Instance::IS_EXPIRED + " is false order by " + ReminderRequest::Instance::TRIGGER_TIME + " asc"; return GetReminders(queryCondition); } @@ -332,14 +357,11 @@ std::vector> ReminderStore::GetReminders(const std::string sptr ReminderStore::BuildReminder(const std::shared_ptr &resultSet) { - int32_t typeIndex; - int32_t idIndex; - resultSet->GetColumnIndex(ReminderRequest::Instance::REMINDER_TYPE, typeIndex); - resultSet->GetColumnIndex(ReminderRequest::Instance::USER_ID, idIndex); int32_t reminderType; int32_t reminderId; - resultSet->GetInt(typeIndex, reminderType); - resultSet->GetInt(idIndex, reminderId); + resultSet->GetInt(ReminderStore::GetColumnIndex(ReminderRequest::Instance::REMINDER_TYPE), reminderType); + resultSet->GetInt(ReminderStore::GetColumnIndex(ReminderRequest::Instance::REMINDER_ID), reminderId); + sptr reminder = nullptr; switch (reminderType) { case (static_cast(ReminderRequest::ReminderType::TIMER)): { @@ -359,7 +381,7 @@ sptr ReminderStore::BuildReminder(const std::shared_ptrRecoveryFromDb(resultSet); // todo + reminder->RecoveryFromDb(resultSet); ANSR_LOGI("BuildReminder success."); } else { ANSR_LOGW("BuildReminder fail."); @@ -370,7 +392,7 @@ sptr ReminderStore::BuildReminder(const std::shared_ptr &bundleOption) const { std::string queryCondition = "select " + ReminderRequest::Instance::PKG_NAME + ", " - + ReminderRequest::Instance::USER_ID + " from " + REMINDER_DB_TABLE + " where " + + ReminderRequest::Instance::UID + " from " + REMINDER_DB_TABLE + " where " + ReminderRequest::Instance::REMINDER_ID + "=" + std::to_string(reminderId); std::shared_ptr queryResultSet = Query(queryCondition); if (queryResultSet == nullptr) { @@ -381,12 +403,12 @@ bool ReminderStore::GetBundleOption(const int32_t &reminderId, sptrGoToNextRow(); std::string pkgName; GetStringVal(queryResultSet, ReminderRequest::Instance::PKG_NAME, pkgName); - int userId; - GetInt32Val(queryResultSet, ReminderRequest::Instance::USER_ID, userId); - int32_t uid = ReminderRequest::GetUid(userId, pkgName); + int32_t uid; + GetInt32Val(queryResultSet, ReminderRequest::Instance::UID, uid); bundleOption->SetBundleName(pkgName); bundleOption->SetUid(uid); return true; @@ -411,21 +433,6 @@ void ReminderStore::GetStringVal(std::shared_ptr void ReminderStore::GenerateData(const sptr &reminder, const sptr &bundleOption, NativeRdb::ValuesBucket &values) const { - // values.PutString(ReminderRequest::Instance::PKG_NAME, "aaa"); - // values.PutInt(ReminderRequest::Instance::USER_ID, 1); - // values.PutString(ReminderRequest::Instance::APP_LABEL, "bbb"); - // values.PutInt(ReminderRequest::Instance::REMINDER_TYPE, 1); - // values.PutLong(ReminderRequest::Instance::REMINDER_TIME, 1); - // values.PutLong(ReminderRequest::Instance::TRIGGER_TIME, 1); - // values.PutLong(ReminderRequest::Instance::RTC_TRIGGER_TIME, 1602068651948); - // values.PutLong(ReminderRequest::Instance::TIME_INTERVAL, 1); - // values.PutInt(ReminderRequest::Instance::SNOOZE_TIMES, 1); - // values.PutInt(ReminderRequest::Instance::DYNAMIC_SNOOZE_TIMES, 1); - // values.PutLong(ReminderRequest::Instance::RING_DURATION, 1); - // values.PutString(ReminderRequest::Instance::IS_EXPIRED, "true"); - // values.PutString(ReminderRequest::Instance::IS_ACTIVE, "true"); - // values.PutInt(ReminderRequest::Instance::STATE, 1); - // values.PutInt(ReminderRequest::Instance::NOTIFICATION_ID, 1); ReminderRequest::AppendValuesBucket(reminder, bundleOption, values); ReminderRequestCalendar::AppendValuesBucket(reminder, bundleOption, values); ReminderRequestAlarm::AppendValuesBucket(reminder, bundleOption, values); diff --git a/frameworks/ans/native/test/unittest/BUILD.gn b/frameworks/ans/native/test/unittest/BUILD.gn index dd864cd0b..873cdd3b8 100644 --- a/frameworks/ans/native/test/unittest/BUILD.gn +++ b/frameworks/ans/native/test/unittest/BUILD.gn @@ -59,6 +59,7 @@ ohos_unittest("ans_reminder_unit_test") { "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "multimedia_image_standard:image_native", + "native_appdatamgr:native_rdb", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] 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 3e76090e7..7168df3bf 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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 77c61bb7b..a114d9727 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: 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: 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: 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: 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: 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: 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: 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: 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: 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 1f189e9f5..280df95fd 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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 6b39c09bf..a10574341 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: 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: 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: 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 c61a047ec..07a98f869 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: AR000GH8E9 AR00GH8EH */ it("testReminderHelper027", 0, async function (done) { let timer = { diff --git a/frameworks/wantagent/src/want_agent_helper.cpp b/frameworks/wantagent/src/want_agent_helper.cpp index 58f13b142..acd15cff8 100644 --- a/frameworks/wantagent/src/want_agent_helper.cpp +++ b/frameworks/wantagent/src/want_agent_helper.cpp @@ -124,7 +124,49 @@ std::shared_ptr WantAgentHelper::GetWantAgent( return agent; } -std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo ¶msInfo) +// std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo ¶msInfo) +// { +// std::vector> wants = paramsInfo.GetWants(); +// if (wants.empty()) { +// WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent invalid input param."); +// return nullptr; +// } + +// std::shared_ptr want = wants[0]; +// if (want == nullptr) { +// WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent invalid input param."); +// return nullptr; +// } + +// WantsInfo wantsInfo; +// wantsInfo.want = *want; +// wantsInfo.resolvedTypes = want->GetType(); +// if (paramsInfo.GetExtraInfo() != nullptr) { +// wantsInfo.want.SetParams(*paramsInfo.GetExtraInfo()); +// } + +// HILOG_INFO("%{public}s:bundle name = %{public}s; ability name = %{public}s", +// __func__, +// wantsInfo.want.GetElement().GetBundleName().c_str(), +// wantsInfo.want.GetElement().GetAbilityName().c_str()); + +// WantSenderInfo wantSenderInfo; +// wantSenderInfo.allWants.push_back(wantsInfo); +// wantSenderInfo.bundleName = want->GetOperation().GetBundleName(); +// wantSenderInfo.flags = FlagsTransformer(paramsInfo.GetFlags()); +// wantSenderInfo.type = (int32_t)paramsInfo.GetOperationType(); + +// sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); +// if (target == nullptr) { +// WANT_AGENT_LOGE("WantAgentHelper::GetWantAgent target is nullptr."); +// return nullptr; +// } +// std::shared_ptr agent = std::make_shared(std::make_shared(target)); + +// return agent; +// } + +std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo ¶msInfo, int32_t userId) { std::vector> wants = paramsInfo.GetWants(); if (wants.empty()) { @@ -155,6 +197,7 @@ std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo &pa wantSenderInfo.bundleName = want->GetOperation().GetBundleName(); wantSenderInfo.flags = FlagsTransformer(paramsInfo.GetFlags()); wantSenderInfo.type = (int32_t)paramsInfo.GetOperationType(); + wantSenderInfo.userId = userId; sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); if (target == nullptr) { @@ -186,6 +229,9 @@ void WantAgentHelper::TriggerWantAgent(const std::shared_ptr &agent, std::shared_ptr pendingWant = agent->GetPendingWant(); WantAgentConstant::OperationType type = GetType(agent); + + HILOG_INFO("~~~~%{public}d", type); + sptr dispatcher = nullptr; if (callback != nullptr) { dispatcher = new (std::nothrow) CompletedDispatcher(pendingWant, callback, nullptr); diff --git a/interfaces/innerkits/ans/native/include/reminder_request.h b/interfaces/innerkits/ans/native/include/reminder_request.h index 4b5f1517f..882713219 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request.h +++ b/interfaces/innerkits/ans/native/include/reminder_request.h @@ -19,6 +19,7 @@ #include #include +#include "abs_shared_result_set.h" #include "notification_bundle_option.h" #include "notification_constant.h" #include "notification_request.h" @@ -138,9 +139,7 @@ public: * * @param reminderId Indicates reminder id. */ - explicit ReminderRequest(int32_t reminderId) { - reminderId_ = reminderId; - } + explicit ReminderRequest(int32_t reminderId); ReminderRequest& operator = (const ReminderRequest &other); virtual ~ReminderRequest() override {}; @@ -174,6 +173,7 @@ public: * @return Information of the reminder. */ std::string Dump() const; + // std::string DumpAll() const; /** * @brief Obtains the configured action buttons. @@ -268,6 +268,9 @@ public: */ uint64_t GetTriggerTimeInMilli() const; + int GetUserId() const; + int32_t GetUid() const; + /** * @brief Obtains want agent information. * @@ -283,8 +286,24 @@ public: /** * @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 Inites reminder uid when publish reminder success. + * + * When system reboot and recovery from database, we cannot get the uid according user id as BMS has not be + * ready. So we need to record the uid in order to create correct bundleOption. + * + * @param uid Indicates the uid which the reminder belong to. */ - void InitUserId(const int& userId); + void InitUid(const int32_t &uid); /** * @brief Check the reminder is alerting or not. @@ -384,6 +403,14 @@ public: */ virtual bool OnTimeZoneChange(); + /** + * @brief Recovery reminder instance from database record. + * + * @param resultSet Indicates the resultSet with pointer to the row of record data. + */ + virtual void RecoveryFromDb(const std::shared_ptr &resultSet); + void RecoveryActionButton(const std::shared_ptr &resultSet); + /** * @brief Sets action button. * @@ -578,6 +605,7 @@ public: const static std::string REMINDER_ID; const static std::string PKG_NAME; const static std::string USER_ID; + const static std::string UID; const static std::string APP_LABEL; const static std::string REMINDER_TYPE; const static std::string REMINDER_TIME; @@ -611,6 +639,10 @@ private: }; protected: + enum class DbRecoveryType : uint8_t { + INT, + LONG + }; ReminderRequest(); explicit ReminderRequest(ReminderType reminderType); std::string GetDateTimeInfo(const time_t &timeInSecond) const; @@ -618,6 +650,14 @@ protected: { return INVALID_LONG_LONG_VALUE; } + int64_t RecoveryInt64FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType); + void RecoveryUint64FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint64_t &attribute); + void RecoveryUint32FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint32_t &attribute); + void RecoveryUint8FromDb(const std::shared_ptr &resultSet, + const std::string &columnName, const DbRecoveryType &columnType, uint8_t &attribute); static const int BASE_YEAR; private: @@ -632,6 +672,7 @@ private: bool HandleSysTimeChange(uint64_t oriTriggerTime, uint64_t optTriggerTime); bool HandleTimeZoneChange(uint64_t oldZoneTriggerTime, uint64_t newZoneTriggerTime, uint64_t optTriggerTime); void InitNotificationRequest(); + void InitServerObj(); void SetMaxScreenWantAgent(AppExecFwk::ElementName &element); void SetState(bool deSet, const uint8_t newState, std::string function); void SetWantAgent(AppExecFwk::ElementName &element); @@ -675,7 +716,8 @@ private: uint8_t state_ {0}; int32_t notificationId_ {0}; int32_t reminderId_ {-1}; - int userId_ {0}; + int userId_ {-1}; + int32_t uid_ {-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/interfaces/innerkits/ans/native/include/reminder_request_alarm.h b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h index 18ddd2898..d0fd6f4df 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_alarm.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_alarm.h @@ -104,7 +104,7 @@ public: * @return true if read parcel success. */ bool ReadFromParcel(Parcel &parcel) override; - + virtual void RecoveryFromDb(const std::shared_ptr &resultSet) override; static void AppendValuesBucket(const sptr &reminder, const sptr &bundleOption, NativeRdb::ValuesBucket &values); diff --git a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h index d85d224c6..5b90719a0 100644 --- a/interfaces/innerkits/ans/native/include/reminder_request_calendar.h +++ b/interfaces/innerkits/ans/native/include/reminder_request_calendar.h @@ -141,6 +141,7 @@ public: static const uint8_t MAX_MONTHS_OF_YEAR; static const uint8_t MAX_DAYS_OF_MONTH; + virtual void RecoveryFromDb(const std::shared_ptr &resultSet) override; static void AppendValuesBucket(const sptr &reminder, const sptr &bundleOption, NativeRdb::ValuesBucket &values); diff --git a/interfaces/innerkits/ans/native/include/reminder_store.h b/interfaces/innerkits/ans/native/include/reminder_store.h index d698dc250..72d702781 100644 --- a/interfaces/innerkits/ans/native/include/reminder_store.h +++ b/interfaces/innerkits/ans/native/include/reminder_store.h @@ -43,6 +43,8 @@ public: /* std::string ConvertIconToString(std::shared_ptr &icon); std::shared_ptr ConvertStringToIcon(const std::string &icon); */ static std::vector GetRepeatInfo(int64_t repeatData, int32_t maxRepeatVal); + static uint8_t GetColumnIndex(const std::string& name); + static std::vector COLUMNS; private: /** diff --git a/interfaces/innerkits/wantagent/include/want_agent_helper.h b/interfaces/innerkits/wantagent/include/want_agent_helper.h index 52ea8d983..2ead216db 100644 --- a/interfaces/innerkits/wantagent/include/want_agent_helper.h +++ b/interfaces/innerkits/wantagent/include/want_agent_helper.h @@ -67,7 +67,8 @@ public: * WantAgent object to create. * @return Returns the created WantAgent object. */ - static std::shared_ptr GetWantAgent(const WantAgentInfo ¶msInfo); + // static std::shared_ptr GetWantAgent(const WantAgentInfo ¶msInfo); + static std::shared_ptr GetWantAgent(const WantAgentInfo ¶msInfo, int32_t userId = -1); /** * Obtains an WantAgent object operation type. diff --git a/services/ans/include/reminder_data_manager.h b/services/ans/include/reminder_data_manager.h index 6b8c24676..619c63d30 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/ans/include/reminder_data_manager.h @@ -30,9 +30,7 @@ namespace OHOS { namespace Notification { class ReminderDataManager final { public: - ReminderDataManager() { - Init(false); - }; + ReminderDataManager() {}; ~ReminderDataManager() {}; ReminderDataManager(ReminderDataManager &other) = delete; @@ -40,8 +38,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. @@ -458,7 +459,7 @@ private: /** * Indicates the total count of reminders in system. */ - int16_t totalCount_ {0}; + int16_t totalCount_ {0}; // todo recovery from db AdvancedNotificationService *advancedNotificationService_; std::shared_ptr store_ = nullptr; }; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index cb88bde20..ace0c7587 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -101,6 +101,9 @@ inline bool IsSystemApp() bool isSystemApp = false; int callingUid = IPCSkeleton::GetCallingUid(); + ANSR_LOGD("~~~~callingUid=%{public}d", callingUid); + std::string bundleName = GetClientBundleName(); + ANSR_LOGD("~~~~bundleName=%{public}s", bundleName.c_str()); std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); if (bundleManager != nullptr) { @@ -297,17 +300,22 @@ ErrCode AdvancedNotificationService::CancelPreparedNotification( int notificationId, const std::string &label, const sptr &bundleOption) { if (bundleOption == nullptr) { + ANSR_LOGD("~~~~1"); return ERR_ANS_INVALID_BUNDLE; } + ANSR_LOGD("~~~~2"); ErrCode result = ERR_OK; handler_->PostSyncTask(std::bind([&]() { sptr notification = nullptr; result = RemoveFromNotificationList(bundleOption, label, notificationId, notification, true); if (result != ERR_OK) { + ANSR_LOGD("~~~~3"); return; } + ANSR_LOGD("~~~~4"); if (notification != nullptr) { + ANSR_LOGD("~~~~5"); int reason = NotificationConstant::APP_CANCEL_REASON_DELETE; UpdateRecentNotification(notification, true, reason); sptr sortingMap = GenerateSortingMap(); @@ -418,6 +426,7 @@ ErrCode AdvancedNotificationService::Filter(const std::shared_ptr &record) { + ANSR_LOGD("~~~~push_back, notificationId=%{public}d", record->notification->GetId()); notificationList_.push_back(record); SortNotificationList(); } @@ -1107,10 +1116,15 @@ ErrCode AdvancedNotificationService::GetShowBadgeEnabled(bool &enabled) ErrCode AdvancedNotificationService::RemoveFromNotificationList(const sptr &bundleOption, const std::string &label, int notificationId, sptr ¬ification, bool isCancel) { + ANSR_LOGD("~~~~%{public}s, %{public}d, %{public}s, %{public}d" + , bundleOption->GetBundleName().c_str(), bundleOption->GetUid(), label.c_str(), notificationId); + for (auto record : notificationList_) { if (!record->notification->IsRemoveAllowed()) { + ANSR_LOGD("~~~~3.1"); continue; } + ANSR_LOGD("~~~~3.11"); if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) && (record->bundleOption->GetUid() == bundleOption->GetUid()) && (record->notification->GetLabel() == label) && @@ -1119,19 +1133,24 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList(const sptrdeviceId.empty() #endif ) { + ANSR_LOGD("~~~~3.2"); if (!isCancel && record->request->IsUnremovable()) { + ANSR_LOGD("~~~~3.3"); return ERR_ANS_NOTIFICATION_IS_UNREMOVABLE; } notification = record->notification; // delete or delete all, call the function if (!isCancel) { + ANSR_LOGD("~~~~3.4"); TriggerRemoveWantAgent(record->request); } + ANSR_LOGD("~~~~3.5"); notificationList_.remove(record); return ERR_OK; } } + ANSR_LOGD("~~~~3.6"); return ERR_ANS_NOTIFICATION_NOT_EXISTS; } @@ -1601,7 +1620,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/advanced_notification_service_ability.cpp b/services/ans/src/advanced_notification_service_ability.cpp index c96691618..379fc8bf3 100644 --- a/services/ans/src/advanced_notification_service_ability.cpp +++ b/services/ans/src/advanced_notification_service_ability.cpp @@ -30,6 +30,7 @@ AdvancedNotificationServiceAbility::~AdvancedNotificationServiceAbility() void AdvancedNotificationServiceAbility::OnStart() { + ANSR_LOGD("~~~~Service init"); if (service_ != nullptr) { return; } @@ -38,6 +39,7 @@ void AdvancedNotificationServiceAbility::OnStart() if (!Publish(service_)) { return; } + ANSR_LOGD("~~~~Service init 1"); reminderAgent_ = ReminderDataManager::GetInstance(); reminderAgent_->SetService(static_cast(service_.GetRefPtr())); } diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index bccd5eb59..8dd3880e4 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) { @@ -120,15 +121,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();) { @@ -140,6 +141,7 @@ void ReminderDataManager::CancelAllReminders(const sptrsecond->GetBundleName() == bundleOption->GetBundleName()) { + ANSR_LOGD("currently, userId is not supported. userId=%{public}d", userId); if ((*vit)->IsAlerting()) { StopAlertingReminder(*vit); } @@ -200,8 +202,8 @@ void ReminderDataManager::OnProcessDiedLocked(const sptrGetReminderId(); auto mit = notificationBundleOptionMap_.find(reminderId); if (mit == notificationBundleOptionMap_.end()) { - ANSR_LOGD("Not get bundle option, the reminder may has been cancelled, 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; @@ -330,6 +332,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) { @@ -352,8 +355,10 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b std::shared_ptr ReminderDataManager::GetInstance() { if (REMINDER_DATA_MANAGER == nullptr) { + ANSR_LOGD("~~~~GetInstance init"); REMINDER_DATA_MANAGER = std::make_shared(); ReminderEventManager reminderEventManager(REMINDER_DATA_MANAGER); + REMINDER_DATA_MANAGER->Init(false); } return REMINDER_DATA_MANAGER; } @@ -364,6 +369,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); @@ -425,6 +431,7 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( std::lock_guard lock(ReminderDataManager::MUTEX); reminder->InitReminderId(); reminder->InitUserId(ReminderRequest::GetUserId(bundleOption->GetUid())); + reminder->InitUid(bundleOption->GetUid()); int32_t reminderId = reminder->GetReminderId(); ANSR_LOGD("Containers(map) add. reminderId=%{public}d", reminderId); auto ret = notificationBundleOptionMap_.insert( @@ -589,6 +596,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); } @@ -628,8 +636,8 @@ void ReminderDataManager::StartRecentReminder() return; } if (activeReminderId_ != -1) { - StopTimerLocked(TimerType::TRIGGER_TIMER); activeReminder_->OnStop(); + StopTimerLocked(TimerType::TRIGGER_TIMER); // todo store_->UpdateOrInsert() } // if (reminder->ShouldShowImmediately()) { // todo @@ -841,10 +849,11 @@ void ReminderDataManager::Init(bool isFromBootComplete) return; } LoadReminderFromDb(); + ANSR_LOGD("~~~~dump:%{public}s", Dump().c_str()); if (isFromBootComplete) { // todo } - StartRecentReminder(); + StartRecentReminder(); // todo isReminderAgentReady_ = true; ANSR_LOGD("ReminderAgent is ready."); } @@ -1028,6 +1037,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: { @@ -1047,7 +1060,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); @@ -1063,8 +1076,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 e8ad9ec46..13e06d7e0 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/ans/src/reminder_event_manager.cpp @@ -113,8 +113,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 @@ -130,7 +133,7 @@ sptr ReminderEventManager::ReminderEventSubscriber::Ge std::string bundleName = ele.GetBundleName(); int userId = want.GetIntParam(OHOS::AppExecFwk::Constants::USER_ID, -1); int32_t uid = ReminderRequest::GetUid(userId, bundleName); - ANSR_LOGD("bundleName=%{public}s, uid=%{public}d", bundleName.c_str(), uid); + ANSR_LOGD("bundleName=%{public}s, userId=%{public}d, uid=%{public}d", bundleName.c_str(), userId, uid); sptr bundleOption = new NotificationBundleOption(bundleName, uid); return bundleOption; } -- Gitee From 84f217925a7d724846227fae6975670167b2bf1a Mon Sep 17 00:00:00 2001 From: derek Date: Fri, 11 Feb 2022 11:20:55 +0800 Subject: [PATCH 18/18] bugfix for notification is null when recovery from db Signed-off-by: derek Change-Id: I3417ea3ebf1896dbe3972dbd572cf0b219dce35a --- .../ans/native/src/reminder_request.cpp | 9 ++-- .../native/src/reminder_request_calendar.cpp | 18 +++++-- .../unittest/reminder_request_alarm_test.cpp | 22 ++++---- .../reminder_request_calendar_test.cpp | 18 +++---- .../test/unittest/reminder_request_test.cpp | 40 +++++++------- .../unittest/reminder_request_timer_test.cpp | 6 +-- .../ans/test/moduletest/ReminderHelperTest.js | 54 +++++++++---------- 7 files changed, 90 insertions(+), 77 deletions(-) diff --git a/frameworks/ans/native/src/reminder_request.cpp b/frameworks/ans/native/src/reminder_request.cpp index d4db8dd13..5692fe1e9 100644 --- a/frameworks/ans/native/src/reminder_request.cpp +++ b/frameworks/ans/native/src/reminder_request.cpp @@ -482,16 +482,17 @@ void ReminderRequest::RecoveryFromDb(const std::shared_ptr(RecoveryInt64FromDb(resultSet, Instance::REMINDER_TIME, DbRecoveryType::INT)); + static_cast(RecoveryInt64FromDb(resultSet, Instance::REMINDER_TIME, DbRecoveryType::LONG)); // triggerTime // RecoveryUint64FromDb(resultSet, Instance::TRIGGER_TIME, DbRecoveryType::INT, triggerTimeInMilli_); triggerTimeInMilli_ = - static_cast(RecoveryInt64FromDb(resultSet, Instance::TRIGGER_TIME, DbRecoveryType::INT)); + static_cast(RecoveryInt64FromDb(resultSet, Instance::TRIGGER_TIME, DbRecoveryType::LONG)); + ANSR_LOGD("~~~~triggerTimeInMilli_=%{public}llu", triggerTimeInMilli_); // timeInterval uint64_t timeIntervalInSecond = - static_cast(RecoveryInt64FromDb(resultSet, Instance::TIME_INTERVAL, DbRecoveryType::INT)); + static_cast(RecoveryInt64FromDb(resultSet, Instance::TIME_INTERVAL, DbRecoveryType::LONG)); // RecoveryUint64FromDb(resultSet, Instance::TIME_INTERVAL, DbRecoveryType::INT, timeIntervalInSecond); SetTimeInterval(timeIntervalInSecond); @@ -560,6 +561,8 @@ void ReminderRequest::RecoveryFromDb(const std::shared_ptrpkgName // + ReminderRequest::SEP_WANT_AGENT + maxScreenWantAgentInfo->abilityName); // } + + InitNotificationRequest(); } void ReminderRequest::RecoveryActionButton(const std::shared_ptr &resultSet) diff --git a/frameworks/ans/native/src/reminder_request_calendar.cpp b/frameworks/ans/native/src/reminder_request_calendar.cpp index f7e5232c9..1a6b578ec 100644 --- a/frameworks/ans/native/src/reminder_request_calendar.cpp +++ b/frameworks/ans/native/src/reminder_request_calendar.cpp @@ -497,28 +497,38 @@ void ReminderRequestCalendar::RecoveryFromDb(const std::shared_ptr(RecoveryInt64FromDb(resultSet, Instance::REPEAT_DAYS, DbRecoveryType::INT)); // repeatMonth - + repeatMonth_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::REPEAT_MONTHS, DbRecoveryType::INT)); // firstDesignateYear + firstDesignateYear_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::FIRST_DESIGNATE_YEAR, DbRecoveryType::INT)); // firstDesignateMonth + firstDesignateMonth_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::FIRST_DESIGNATE_MONTH, DbRecoveryType::INT)); // firstDesignateDay + firstDesignateDay_ = + static_cast(RecoveryInt64FromDb(resultSet, Instance::FIRST_DESIGNATE_DAY, DbRecoveryType::INT)); // year + year_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::CALENDAR_YEAR, DbRecoveryType::INT)); // month + month_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::CALENDAR_MONTH, DbRecoveryType::INT)); // day + day_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::CALENDAR_DAY, DbRecoveryType::INT)); // hour + hour_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::CALENDAR_HOUR, DbRecoveryType::INT)); // minute - - // second + minute_ = static_cast(RecoveryInt64FromDb(resultSet, Instance::CALENDAR_MINUTE, DbRecoveryType::INT)); } void ReminderRequestCalendar::AppendValuesBucket(const sptr &reminder, 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 7168df3bf..d658d162c 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_alarm_test.cpp @@ -37,7 +37,7 @@ public: * @tc.name: initHour_00100 * @tc.desc: set hour < 0 should throw exception. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00100, Function | SmallTest | Level1) { @@ -54,7 +54,7 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00100, Function | SmallTest | Level1 * @tc.name: initHour_00200 * @tc.desc: set hour > 23 should throw exception. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00200, Function | SmallTest | Level1) { @@ -71,7 +71,7 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00200, Function | SmallTest | Level1 * @tc.name: initHour_00300 * @tc.desc: test set edge value of hour (0 and 23). * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00300, Function | SmallTest | Level1) { @@ -96,7 +96,7 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00300, Function | SmallTest | Level1 * @tc.name: initHour_00400 * @tc.desc: set minute < 0 should throw exception. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00400, Function | SmallTest | Level1) { @@ -113,7 +113,7 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00400, Function | SmallTest | Level1 * @tc.name: initHour_00500 * @tc.desc: set minute > 59 should throw exception. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00500, Function | SmallTest | Level1) { @@ -130,7 +130,7 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00500, Function | SmallTest | Level1 * @tc.name: initHour_00600 * @tc.desc: test set edge value of minute (0 and 59). * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initHour_00600, Function | SmallTest | Level1) { @@ -146,7 +146,7 @@ HWTEST_F(ReminderRequestAlarmTest, initHour_00600, Function | SmallTest | Level1 * @tc.name: initDaysOfWeek_00100 * @tc.desc: test set daysOfWeek with normal value. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00100, Function | SmallTest | Level1) { @@ -161,7 +161,7 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00100, Function | SmallTest | * @tc.name: initDaysOfWeek_00200 * @tc.desc: test set daysOfWeek with edge value. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00200, Function | SmallTest | Level1) { @@ -175,7 +175,7 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00200, Function | SmallTest | * @tc.name: initDaysOfWeek_00300 * @tc.desc: test set daysOfWeek with duplicate value. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00300, Function | SmallTest | Level1) { @@ -189,7 +189,7 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00300, Function | SmallTest | * @tc.name: initDaysOfWeek_00400 * @tc.desc: test set daysOfWeek exceeding maximum length. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00400, Function | SmallTest | Level1) { @@ -207,7 +207,7 @@ HWTEST_F(ReminderRequestAlarmTest, initDaysOfWeek_00400, Function | SmallTest | * @tc.name: initDaysOfWeek_00500 * @tc.desc: test set daysOfWeek with null value. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @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 a114d9727..f7bc5ed5c 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_calendar_test.cpp @@ -82,7 +82,7 @@ public: * @tc.name: initDateTime_00100 * @tc.desc: Check firstDesignateYear set successfully. * @tc.type: FUNC - * @tc.require: AR000GNF1V + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00100, Function | SmallTest | Level1) { @@ -99,7 +99,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00100, Function | SmallTest | * @tc.name: initDateTime_00200 * @tc.desc: Check firstDesignateMonth set successfully. * @tc.type: FUNC - * @tc.require: AR000GNF1V + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00200, Function | SmallTest | Level1) { @@ -116,7 +116,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00200, Function | SmallTest | * @tc.name: initDateTime_00300 * @tc.desc: Check firstDesignateDay set successfully. * @tc.type: FUNC - * @tc.require: AR000GNF1V + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00300, Function | SmallTest | Level1) { @@ -133,7 +133,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00300, Function | SmallTest | * @tc.name: initDateTime_00400 * @tc.desc: Check repeatMonth set with normal value successfully. * @tc.type: FUNC - * @tc.require: AR000GNF1V + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00400, Function | SmallTest | Level1) { @@ -175,7 +175,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00400, Function | SmallTest | * @tc.name: initDateTime_00500 * @tc.desc: Check repeatMonth set with exception value successfully. * @tc.type: FUNC - * @tc.require: AR000GNF1V + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00500, Function | SmallTest | Level1) { @@ -217,7 +217,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00500, Function | SmallTest | * @tc.name: initDateTime_00600 * @tc.desc: Check repeatDay set with nomal value successfully. * @tc.type: FUNC - * @tc.require: AR000GNF1V + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00600, Function | SmallTest | Level1) { @@ -258,7 +258,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00600, Function | SmallTest | * @tc.name: initDateTime_00700 * @tc.desc: Check repeatDay set with exception value successfully. * @tc.type: FUNC - * @tc.require: AR000GNF1V + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00700, Function | SmallTest | Level1) { @@ -301,7 +301,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00700, Function | SmallTest | * @tc.name: initDateTime_00800 * @tc.desc: Check hour set successfully. * @tc.type: FUNC - * @tc.require: AR000GNF1V + * @tc.require: SR000GN4CU AR000GNF1V */ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00800, Function | SmallTest | Level1) { @@ -317,7 +317,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00800, Function | SmallTest | * @tc.name: initDateTime_00900 * @tc.desc: Check minut set successfully. * @tc.type: FUNC - * @tc.require: AR000GNF1V + * @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 280df95fd..7788b8fc7 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_test.cpp @@ -41,7 +41,7 @@ const uint8_t ReminderRequestTest::REMINDER_STATUS_SHOWING = 4; * @tc.name: CanRemove_00100 * @tc.desc: When reminder init, CanRemove should return true. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00100, Function | SmallTest | Level1) { @@ -53,7 +53,7 @@ HWTEST_F(ReminderRequestTest, CanRemove_00100, Function | SmallTest | Level1) * @tc.name: CanRemove_00200 * @tc.desc: When reminder is shown, CanRemove should return false. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00200, Function | SmallTest | Level1) { @@ -66,7 +66,7 @@ HWTEST_F(ReminderRequestTest, CanRemove_00200, Function | SmallTest | Level1) * @tc.name: CanRemove_00300 * @tc.desc: When reminder close, CanRemove should return true. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, CanRemove_00300, Function | SmallTest | Level1) { @@ -80,7 +80,7 @@ HWTEST_F(ReminderRequestTest, CanRemove_00300, Function | SmallTest | Level1) * @tc.name: CanRemove_00400 * @tc.desc: When reminder is covered as same notification id, CanRemove should return true. * @tc.type: FUNC - * @tc.require: AR000GH8EF AR000GH8E6 + * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, CanRemove_00400, Function | SmallTest | Level1) { @@ -95,7 +95,7 @@ HWTEST_F(ReminderRequestTest, CanRemove_00400, Function | SmallTest | Level1) * @tc.name: StateCheck_00100 * @tc.desc: When reminder init, state should be 0. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00100, Function | SmallTest | Level1) { @@ -107,7 +107,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00100, Function | SmallTest | Level1) * @tc.name: StateCheck_00200 * @tc.desc: When reminder close with param true, state REMINDER_STATUS_SHOWING should be unset. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00200, Function | SmallTest | Level1) { @@ -120,7 +120,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00200, Function | SmallTest | Level1) * @tc.name: StateCheck_00300 * @tc.desc: When reminder close with param false, state REMINDER_STATUS_SHOWING should be unset. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00300, Function | SmallTest | Level1) { @@ -133,7 +133,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00300, Function | SmallTest | Level1) * @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: AR000GH8EF AR000GH8E6 + * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, StateCheck_00400, Function | SmallTest | Level1) { @@ -146,7 +146,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00400, Function | SmallTest | Level1) * @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: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00500, Function | SmallTest | Level1) { @@ -159,7 +159,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00500, Function | SmallTest | Level1) * @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: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00600, Function | SmallTest | Level1) { @@ -172,7 +172,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00600, Function | SmallTest | Level1) * @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: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00700, Function | SmallTest | Level1) { @@ -186,7 +186,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00700, Function | SmallTest | Level1) * @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: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, StateCheck_00800, Function | SmallTest | Level1) { @@ -200,7 +200,7 @@ HWTEST_F(ReminderRequestTest, StateCheck_00800, Function | SmallTest | Level1) * @tc.name: initReminderId_00100 * @tc.desc: When reminder create successfully, system should assign unique id to reminder. * @tc.type: FUNC - * @tc.require: AR000GH8EF AR000GH8E6 + * @tc.require: SR000GGGTRD AR000GH8EF AR000GH8E6 */ HWTEST_F(ReminderRequestTest, initReminderId_00100, Function | SmallTest | Level1) { @@ -216,7 +216,7 @@ HWTEST_F(ReminderRequestTest, initReminderId_00100, Function | SmallTest | Level * @tc.name: setContent_00100 * @tc.desc: Test SetContent with normal parameters. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setContent_00100, Function | SmallTest | Level1) { @@ -230,7 +230,7 @@ HWTEST_F(ReminderRequestTest, setContent_00100, Function | SmallTest | Level1) * @tc.name: setContent_00200 * @tc.desc: Test SetContent parameters with special characters. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setContent_00200, Function | SmallTest | Level1) { @@ -244,7 +244,7 @@ HWTEST_F(ReminderRequestTest, setContent_00200, Function | SmallTest | Level1) * @tc.name: setExpiredContent_00100 * @tc.desc: Test SetExpiredContent with normal parameters. * @tc.type: FUNC - * @tc.require: AR000GH8EF AR000GNF1U + * @tc.require: SR000GGGTRD AR000GH8EF AR000GNF1U */ HWTEST_F(ReminderRequestTest, setExpiredContent_00100, Function | SmallTest | Level1) { @@ -258,7 +258,7 @@ HWTEST_F(ReminderRequestTest, setExpiredContent_00100, Function | SmallTest | Le * @tc.name: setExpiredContent_00200 * @tc.desc: Test SetExpiredContent with special characters. * @tc.type: FUNC - * @tc.require: AR000GH8EF AR000GNF1U + * @tc.require: SR000GGGTRD AR000GH8EF AR000GNF1U */ HWTEST_F(ReminderRequestTest, setExpiredContent_00200, Function | SmallTest | Level1) { @@ -272,7 +272,7 @@ HWTEST_F(ReminderRequestTest, setExpiredContent_00200, Function | SmallTest | Le * @tc.name: setTitle_00100 * @tc.desc: Test SetTitle with normal parameters. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setTitle_00100, Function | SmallTest | Level1) { @@ -286,7 +286,7 @@ HWTEST_F(ReminderRequestTest, setTitle_00100, Function | SmallTest | Level1) * @tc.name: setTitle_00200 * @tc.desc: Test SetTitle with special characters. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setTitle_00200, Function | SmallTest | Level1) { @@ -300,7 +300,7 @@ HWTEST_F(ReminderRequestTest, setTitle_00200, Function | SmallTest | Level1) * @tc.name: setNotificationId_00100 * @tc.desc: Test SetNotificationId parameters. * @tc.type: FUNC - * @tc.require: AR000GH8EF + * @tc.require: SR000GGGTRD AR000GH8EF */ HWTEST_F(ReminderRequestTest, setNotificationId_00100, Function | SmallTest | Level1) { 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 a10574341..852fbb84e 100644 --- a/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp +++ b/frameworks/ans/native/test/unittest/reminder_request_timer_test.cpp @@ -40,7 +40,7 @@ public: * @tc.name: initCountDownTime_00100 * @tc.desc: set countDownTime = 0 should throw exception. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00100, Function | SmallTest | Level1) { @@ -57,7 +57,7 @@ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00100, Function | SmallTest * @tc.name: initCountDownTime_00200 * @tc.desc: set countDownTime > (UINT64_MAX / 1000) should throw exception. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @tc.require: SR000GGTRC AR000GH8E8 */ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00200, Function | SmallTest | Level1) { @@ -74,7 +74,7 @@ HWTEST_F(ReminderRequestTimerTest, initCountDownTime_00200, Function | SmallTest * @tc.name: initCountDownTime_00300 * @tc.desc: set countDownTime with normal value. * @tc.type: FUNC - * @tc.require: AR000GH8E8 + * @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 07a98f869..1b29bd76e 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: AR000GH8E9 AR00GH8EH + * @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: AR000GH8E9 AR00GH8EH + * @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: AR000GH8EC + * @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: AR000GH8EC + * @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: AR000GH8EC + * @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: AR000GH8EC + * @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: AR000GH8EA + * @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: AR000GH8EA + * @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: AR000GH8EA + * @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: AR000GH8EA + * @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: AR000GH8EA + * @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: AR000GH8EA + * @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: AR000GH8EB + * @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: AR000GH8EB + * @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: AR000GH8ED + * @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: AR000GH8ED + * @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: AR000GH8ED + * @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: AR000GH8ED + * @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: AR000GH8EB AR000GH8EG + * @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: AR000GH8EB AR000GH8EG + * @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: AR000GH8E9 AR00GH8EH + * @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: AR000GH8E9 AR00GH8EH + * @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: AR000GH8E9 AR00GH8EH + * @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: AR000GH8E9 AR00GH8EH + * @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: AR000GH8E9 AR00GH8EH + * @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: AR000GH8E9 AR00GH8EH + * @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: AR000GH8E9 AR00GH8EH + * @tc.require: SR000GGTRB AR000GH8E9 AR00GH8EH */ it("testReminderHelper027", 0, async function (done) { let timer = { -- Gitee