From 257d885496a209e7c1f4a52da19ac9351257952a Mon Sep 17 00:00:00 2001 From: fangjinliang1 Date: Mon, 17 Jan 2022 22:21:48 +0800 Subject: [PATCH] fixed 098daa5 from https://gitee.com/fangJinliang1/notification_ans_standard/pulls/151 12.20 code recovery :Signed-off-by: fangjinliang1 XChange-Id: I4d2bba6b4c027bb7292de53c714bdc88388574fc Change-Id: I12a4565f91fd8ddddfc4c2a035ac332b30958044 Change-Id: I8adb8c65b1385040967c8098a3d8fc619e114a29 --- .../core/common/include/ans_const_define.h | 2 +- .../ans/native/src/notification_template.cpp | 7 +++++ interfaces/kits/napi/ans/src/ans_template.cpp | 4 +-- interfaces/kits/napi/ans/src/common.cpp | 2 +- services/ans/BUILD.gn | 1 + .../include/advanced_notification_service.h | 1 + .../ans/src/advanced_notification_service.cpp | 27 +++++++++++++++++++ services/ans/test/unittest/BUILD.gn | 1 + services/test/moduletest/BUILD.gn | 1 + 9 files changed, 42 insertions(+), 4 deletions(-) diff --git a/frameworks/ans/core/common/include/ans_const_define.h b/frameworks/ans/core/common/include/ans_const_define.h index bda3a1ffe..fda0f44b0 100644 --- a/frameworks/ans/core/common/include/ans_const_define.h +++ b/frameworks/ans/core/common/include/ans_const_define.h @@ -43,7 +43,7 @@ const static Uri DEFAULT_NOTIFICATION_SOUND("file://system/etc/Light.ogg"); const static std::vector DEFAULT_NOTIFICATION_VIBRATION = {200}; // Default path for template -const static std::string DEFAULT_TEMPLATE_PATH("/system/etc/external.json"); +const static std::string DEFAULT_TEMPLATE_PATH("/system/etc/NotificationTemplate/external.json"); } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/native/src/notification_template.cpp b/frameworks/ans/native/src/notification_template.cpp index 6bc3b1ed5..894bd0e34 100644 --- a/frameworks/ans/native/src/notification_template.cpp +++ b/frameworks/ans/native/src/notification_template.cpp @@ -57,6 +57,13 @@ bool NotificationTemplate::Marshalling(Parcel &parcel) const return false; } + if (valid) { + if (!parcel.WriteParcelable(templateData_.get())) { + ANS_LOGE("Failed to write templateData"); + return false; + } + } + return true; } diff --git a/interfaces/kits/napi/ans/src/ans_template.cpp b/interfaces/kits/napi/ans/src/ans_template.cpp index 1efa21250..7f26cc337 100644 --- a/interfaces/kits/napi/ans/src/ans_template.cpp +++ b/interfaces/kits/napi/ans/src/ans_template.cpp @@ -41,7 +41,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_value argv[IS_TEMPLATE_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_TEMPLATE_MAX_PARA, "Wrong number of arguments"); + NAPI_ASSERT(env, argc <= IS_TEMPLATE_MAX_PARA, "Wrong number of arguments"); napi_valuetype valuetype = napi_undefined; // argv[0]: name: string @@ -89,7 +89,7 @@ napi_value IsSupportTemplate(napi_env env, napi_callback_info info) ANS_LOGI("IsSupportTemplate napi_create_async_work start"); AsyncCallbackInfoTemplate *asyncCallbackinfo = (AsyncCallbackInfoTemplate *)data; - asyncCallbackinfo->info.errorCode = NotificationHelper::CancelNotification( + asyncCallbackinfo->info.errorCode = NotificationHelper::IsSupportTemplate( asyncCallbackinfo->params.templateName, asyncCallbackinfo->params.support); }, [](napi_env env, napi_status status, void *data) { diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 2864281d6..caa11fb21 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -3787,7 +3787,7 @@ napi_value Common::GetNotificationTemplate(const napi_env &env, const napi_value ANS_LOGE("template is null"); return nullptr; } - if (GetNotificationTemplateInfo(env, value, templ) == nullptr) { + if (GetNotificationTemplateInfo(env, result, templ) == nullptr) { return nullptr; } diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 3af77500a..574dd705c 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -66,6 +66,7 @@ ohos_shared_library("libans") { "${frameworks_path}/wantagent:wantagent_innerkits", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/miscservices/time/services:time_service", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/services/abilitymgr:abilityms", "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr:distributedschedsvr", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 6d0397203..0d8f333ab 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -160,6 +160,7 @@ private: bool CheckPermission(const std::string &bundleName); ErrCode PrepereContinuousTaskNotificationRequest(const sptr &request, const int &uid); bool GetActiveUserId(int& userId); + void TriggerRemoveWantAgent(const sptr &request); private: static sptr instance_; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 8f2af8f4f..52c284baa 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -19,6 +19,7 @@ #include #include +#include "ability_context.h" #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" @@ -33,6 +34,8 @@ #include "os_account_manager.h" #include "permission_filter.h" #include "reminder_data_manager.h" +#include "trigger_info.h" +#include "want_agent_helper.h" namespace OHOS { namespace Notification { @@ -1004,6 +1007,10 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList(const sptrnotification; + // delete or delete all, call the function + if (!isCancel) { + TriggerRemoveWantAgent(record->request); + } notificationList_.remove(record); return ERR_OK; } @@ -1743,6 +1750,7 @@ ErrCode AdvancedNotificationService::RemoveNotification( handler_->PostSyncTask(std::bind([&]() { sptr notification = nullptr; + sptr notificationRequest = nullptr; for (auto record : notificationList_) { if ((record->bundleOption->GetBundleName() == bundle->GetBundleName()) && @@ -1753,6 +1761,7 @@ ErrCode AdvancedNotificationService::RemoveNotification( break; } notification = record->notification; + notificationRequest = record->request; notificationList_.remove(record); result = ERR_OK; break; @@ -1765,6 +1774,8 @@ ErrCode AdvancedNotificationService::RemoveNotification( sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, sortingMap, reason); } + + TriggerRemoveWantAgent(notificationRequest); })); return result; @@ -1808,6 +1819,8 @@ ErrCode AdvancedNotificationService::RemoveAllNotifications(const sptr sortingMap = GenerateSortingMap(); NotificationSubscriberManager::GetInstance()->NotifyCanceled(record->notification, sortingMap, reason); } + + TriggerRemoveWantAgent(record->request); } })); @@ -2132,6 +2145,7 @@ ErrCode AdvancedNotificationService::IsSupportTemplate(const std::string& templa })); return result; } + bool AdvancedNotificationService::GetActiveUserId(int& userId) { std::vector osAccountInfos; @@ -2145,5 +2159,18 @@ bool AdvancedNotificationService::GetActiveUserId(int& userId) } return false; } + +void AdvancedNotificationService::TriggerRemoveWantAgent(const sptr &request) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + + if (request == nullptr || request->GetRemovalWantAgent() == nullptr) { + return; + } + OHOS::Notification::WantAgent::TriggerInfo triggerInfo; + std::shared_ptr context = std::make_shared(); + std::shared_ptr agent = request->GetRemovalWantAgent(); + WantAgent::WantAgentHelper::TriggerWantAgent(context, agent, nullptr, triggerInfo); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index d29b10ee9..a03e0226a 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -83,6 +83,7 @@ ohos_unittest("ans_unit_test") { "${frameworks_path}/wantagent:wantagent_innerkits", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/miscservices/time/services:time_service", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr:distributedschedsvr", diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 217cb3f36..024c94165 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -75,6 +75,7 @@ ohos_moduletest("ans_module_test") { "${frameworks_path}/wantagent:wantagent_innerkits", "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/miscservices/time/services:time_service", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/aafwk/standard/services/abilitymgr:abilityms", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", -- Gitee