diff --git a/frameworks/ans/core/common/include/ans_const_define.h b/frameworks/ans/core/common/include/ans_const_define.h index a38245ac7c9190694121c613418c64f9055175a4..0f42c1d3449f31cf7c217b103dd771d0109b0e68 100644 --- a/frameworks/ans/core/common/include/ans_const_define.h +++ b/frameworks/ans/core/common/include/ans_const_define.h @@ -45,7 +45,8 @@ 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..8c33a73f75dda73d4f59f4474657d91cdff55736 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) { @@ -105,7 +105,7 @@ napi_value IsSupportTemplate(napi_env env, napi_callback_info info) } napi_delete_async_work(env, asyncCallbackinfo->asyncWork); - if (asyncCallbackinfo) { + if (asyncCallbackinfo != nullptr) { delete asyncCallbackinfo; asyncCallbackinfo = nullptr; } diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 8849e7e610c21a8354a5f2d4239725b9725944f1..6ec637d36355352c0fd1fc87fc1d6814be8f02f6 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -3970,7 +3970,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 7694c78b15a20a262c7db9c4ee594773c9e1107c..a3de29582f7648ac5752ca8f704e2fbcc42c145e 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -65,6 +65,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/distributedschedule/dmsfwk/services/dtbschedmgr:distributedschedsvr", "//utils/native/base:utils", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index e1fb967dc201372fdf656d8c03e6acce59231110..46244f4b99a4380802ad522e7bf6eb0b847f6332 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -172,6 +172,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); #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED std::vector GetLocalNotificationKeys(const sptr &bundleOption); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 95ae995b2e72840a580d8cafc0de30df113da888..084703d88b5a15f6b7bb666b8fa7987bd3a57f97 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" #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED #include "distributed_notification_manager.h" @@ -1105,6 +1108,10 @@ ErrCode AdvancedNotificationService::RemoveFromNotificationList(const sptrnotification; + // delete or delete all, call the function + if (!isCancel) { + TriggerRemoveWantAgent(record->request); + } notificationList_.remove(record); return ERR_OK; } @@ -1874,6 +1881,8 @@ ErrCode AdvancedNotificationService::RemoveNotification( handler_->PostSyncTask(std::bind([&]() { sptr notification = nullptr; + sptr notificationRequest = nullptr; + #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED std::string deviceId; #endif @@ -1892,6 +1901,7 @@ ErrCode AdvancedNotificationService::RemoveNotification( deviceId = record->deviceId; #endif notification = record->notification; + notificationRequest = record->request; notificationList_.remove(record); result = ERR_OK; break; @@ -1907,6 +1917,8 @@ ErrCode AdvancedNotificationService::RemoveNotification( DoDistributedDelete(deviceId, notification); #endif } + + TriggerRemoveWantAgent(notificationRequest); })); return result; @@ -1957,6 +1969,8 @@ ErrCode AdvancedNotificationService::RemoveAllNotifications(const sptrdeviceId, record->notification); #endif } + + TriggerRemoveWantAgent(record->request); } })); @@ -2664,6 +2678,7 @@ ErrCode AdvancedNotificationService::IsSupportTemplate(const std::string& templa })); return result; } + bool AdvancedNotificationService::GetActiveUserId(int& userId) { std::vector osAccountInfos; @@ -2677,5 +2692,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 \ No newline at end of file diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 86c2c6e2b5e4674ed735eaf1132d9ff99d560834..bf2a10e6b514c4fe41542ad90d39f09b0f54374a 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -81,6 +81,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/services/dtbschedmgr:distributedschedsvr", "//third_party/googletest:gtest_main", diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index c5587e171b2ce4f18e4a3a9716df9ef4f89489b8..405b7fb7c02f52ff7935ddf374a3860cc7e3a5ec 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -74,6 +74,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/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr:distributedschedsvr",