diff --git a/frameworks/ans/core/common/include/ans_const_define.h b/frameworks/ans/core/common/include/ans_const_define.h index bda3a1ffe01ad41d9d4252496668b5e299701ba0..fda0f44b0a23475c3b47484793dc8f7fa631aab1 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 6bc3b1ed56af11c18edb8a4dab03959f0113bc1d..894bd0e34403a863a78466ab6ffedaa42d085dc4 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 1efa212505c3f0296f50e3258adfedf40848dcfe..7f26cc3378e9fdca0b15a5cb4ac4a7d06908f614 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 2864281d6a025a9f0b488091ac35f251e96bfb0e..caa11fb2159dba55b021514860e420c85a56ffc6 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 3af77500ade5304fc254fd96455fc9cd031a67ab..574dd705c3c8fcbebda1abf06ddc9c7e95fcf0b9 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 6d0397203218fc1913a1337ade42ab81f3469b32..0d8f333ab1752d7e0782b0487f3ac58222aad33c 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 8f2af8f4f510f264566a89a6dd1eea852766609d..52c284baa6a7ef1a1464e049729c52e8e625c562 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 d29b10ee98212b72f64be5c305b387912281fa2c..a03e0226a0b73dc8c3fabf1da4c34aee54c71431 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 217cb3f368201d7c2c0ba90ebfde5f365a6f55dc..024c9416558aad96cfaa676ae482e62ce82cbee9 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",