From 62ed29c855d96f78bfe7ca5f380c37e8455546ac Mon Sep 17 00:00:00 2001 From: zhaoyuan Date: Wed, 13 Oct 2021 10:16:20 +0000 Subject: [PATCH] update depends in sa xml and modify the unsubscribe code Signed-off-by: zhaoyuan --- frameworks/ans/core/src/ans_manager_proxy.cpp | 20 +++++++++++-------- interfaces/kits/napi/ans/src/unsubscribe.cpp | 11 +++++++++- sa_profile/3203.xml | 2 ++ .../ans/src/advanced_notification_service.cpp | 4 ++-- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/frameworks/ans/core/src/ans_manager_proxy.cpp b/frameworks/ans/core/src/ans_manager_proxy.cpp index ae493cd9d..b7ac0f7d0 100644 --- a/frameworks/ans/core/src/ans_manager_proxy.cpp +++ b/frameworks/ans/core/src/ans_manager_proxy.cpp @@ -354,10 +354,12 @@ ErrCode AnsManagerProxy::GetSlotByType(const NotificationConstant::SlotType &slo return ERR_ANS_PARCELABLE_FAILED; } - slot = reply.ReadParcelable(); - if (slot == nullptr) { - ANS_LOGW("[GetSlotByType] fail: read slot failed"); - return ERR_ANS_PARCELABLE_FAILED; + if (result == ERR_OK) { + slot = reply.ReadParcelable(); + if (slot == nullptr) { + ANS_LOGW("[GetSlotByType] fail: read slot failed"); + return ERR_ANS_PARCELABLE_FAILED; + } } return result; @@ -418,10 +420,12 @@ ErrCode AnsManagerProxy::GetSlotGroup(const std::string &groupId, sptr(); - if (group == nullptr) { - ANS_LOGW("[GetSlotGroup] fail: read group failed"); - return ERR_ANS_PARCELABLE_FAILED; + if (result == ERR_OK) { + group = reply.ReadParcelable(); + if (group == nullptr) { + ANS_LOGW("[GetSlotGroup] fail: read group failed"); + return ERR_ANS_PARCELABLE_FAILED; + } } return result; diff --git a/interfaces/kits/napi/ans/src/unsubscribe.cpp b/interfaces/kits/napi/ans/src/unsubscribe.cpp index f50a80441..a8b188eeb 100644 --- a/interfaces/kits/napi/ans/src/unsubscribe.cpp +++ b/interfaces/kits/napi/ans/src/unsubscribe.cpp @@ -16,6 +16,8 @@ #include "unsubscribe.h" #include "subscribe.h" +#include "ans_inner_errors.h" + namespace OHOS { namespace NotificationNapi { const int UNSUBSCRIBE_MAX_PARA = 2; @@ -48,8 +50,9 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, SubscriberInstancesInfo subscriberInstancesInfo; if (!HasNotificationSubscriber(env, argv[0], subscriberInstancesInfo)) { - return nullptr; + ANS_LOGW("Subscriber not found"); } + paras.objectInfo = subscriberInstancesInfo.subscriber; ANS_LOGI("ObjectInfo = %{public}p start", paras.objectInfo); @@ -91,6 +94,12 @@ napi_value Unsubscribe(napi_env env, napi_callback_info info) ANS_LOGI("Unsubscribe napi_create_async_work start"); AsyncCallbackInfoUnsubscribe *asynccallbackinfo = (AsyncCallbackInfoUnsubscribe *)data; + if (asynccallbackinfo->objectInfo == nullptr) { + ANS_LOGE("invalid object info"); + asynccallbackinfo->info.errorCode = ERR_ANS_INVALID_PARAM; + return; + } + asynccallbackinfo->info.errorCode = NotificationHelper::UnSubscribeNotification(*(asynccallbackinfo->objectInfo)); }, diff --git a/sa_profile/3203.xml b/sa_profile/3203.xml index 7f45c1fc0..ccaa7c4fb 100755 --- a/sa_profile/3203.xml +++ b/sa_profile/3203.xml @@ -17,6 +17,8 @@ 3203 /system/lib/libans.z.so + 3299 + 5000 true false 1 diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 875112f77..d67e8c031 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1403,10 +1403,10 @@ void AdvancedNotificationService::OnBundleRemoved(const sptrPostTask(std::bind([&]() { + handler_->PostTask(std::bind([bundleOption]() { ErrCode result = NotificationPreferences::GetInstance().RemoveNotificationForBundle(bundleOption); if (result != ERR_OK) { - ANS_LOGE("NotificationPreferences::RemoveNotificationForBundle failed: %{public}d", result); + ANS_LOGW("NotificationPreferences::RemoveNotificationForBundle failed: %{public}d", result); } })); } -- Gitee