From 1b5a2a790c6c0f15f8367a63518f6043fa785300 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Sat, 8 Mar 2025 10:49:51 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=B2=89=E6=B5=B8=E9=94=81=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- frameworks/ans/src/notification_request.cpp | 1 + frameworks/ans/src/push_callback_stub.cpp | 37 ++++++++++++++++++- interfaces/inner_api/push_callback_proxy.h | 1 + interfaces/inner_api/push_promise_callback.h | 2 + .../ans/src/advanced_notification_service.cpp | 23 +++++++++++- 5 files changed, 62 insertions(+), 2 deletions(-) diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 9eb97c848..84f18c562 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -2670,6 +2670,7 @@ void NotificationRequest::FillMissingParameters(const sptr if (newExtraInfo == nullptr) { newLiveViewContent->SetExtraInfo(oldExtraInfo); } else if (oldExtraInfo != nullptr) { + newExtraInfo->Remove("eventControl"); auto oldKeySet = oldExtraInfo->KeySet(); for (const auto &key : oldKeySet) { if (!newExtraInfo->HasParam(key)) { diff --git a/frameworks/ans/src/push_callback_stub.cpp b/frameworks/ans/src/push_callback_stub.cpp index 6e871cfeb..d4244c5eb 100644 --- a/frameworks/ans/src/push_callback_stub.cpp +++ b/frameworks/ans/src/push_callback_stub.cpp @@ -22,6 +22,7 @@ #include "push_callback_proxy.h" #include "singleton.h" #include "ans_inner_errors.h" +#include "nlohmann/json.hpp" using namespace OHOS::AppExecFwk; namespace OHOS { @@ -143,7 +144,41 @@ int32_t PushCallBackProxy::OnCheckNotification( return false; } - return reply.ReadInt32(); + + int result = reply.ReadInt32(); + std::string eventControl; + if (reply.ReadString(eventControl)) { + ANS_LOGI("HandleEventControl"); + HandleEventControl(eventControl, pushCallBackParam); + } + return result; +} + +void PushCallBackProxy::HandleEventControl( + std::string eventControl, const std::shared_ptr &pushCallBackParam) +{ + if (pushCallBackParam == nullptr) { + ANS_LOGI("pushCallBackParam is null"); + return; + } + std::string event = pushCallBackParam->event; + if (event.empty()) { + ANS_LOGI("event is null"); + return; + } + ANS_LOGI("eventControl:%{public}s,event:%{public}s", eventControl.c_str(), event.c_str()); + if (eventControl.empty() || !nlohmann::json::accept(eventControl)) { + return; + } + auto jsonObject = nlohmann::json::parse(eventControl); + if (jsonObject.is_null() || !jsonObject.is_object()) { + ANS_LOGE("jsonObject is not right"); + return; + } + if (jsonObject.find(event) == jsonObject.cend()) { + ANS_LOGI("This event has not eventControl"); + return; + } + pushCallBackParam->eventControl = jsonObject.at(event).dump(); } } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/push_callback_proxy.h b/interfaces/inner_api/push_callback_proxy.h index c39b816b0..4f009a155 100644 --- a/interfaces/inner_api/push_callback_proxy.h +++ b/interfaces/inner_api/push_callback_proxy.h @@ -42,6 +42,7 @@ public: int32_t OnCheckNotification( const std::string ¬ificationData, const std::shared_ptr &pushCallBackParam) override; + void HandleEventControl(std::string eventControl, const std::shared_ptr &pushCallBackParam); private: static inline BrokerDelegator delegator_; }; diff --git a/interfaces/inner_api/push_promise_callback.h b/interfaces/inner_api/push_promise_callback.h index b27027709..93740540c 100644 --- a/interfaces/inner_api/push_promise_callback.h +++ b/interfaces/inner_api/push_promise_callback.h @@ -27,6 +27,8 @@ struct PushCallBackParam { std::condition_variable callBackCondition; bool ready = false; int32_t result; + std::string event; + std::string eventControl; }; class PromiseCallbackInfo { diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 35b1286b0..40142bdcb 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -80,6 +80,7 @@ #include "distributed_device_manager.h" #include "liveview_all_scenarios_extension_wrapper.h" #include "notification_operation_service.h" +#include "string_wrapper.h" namespace OHOS { namespace Notification { @@ -2198,13 +2199,33 @@ ErrCode AdvancedNotificationService::PushCheck(const sptr & if (request->IsCommonLiveView()) { FillExtraInfoToJson(request, checkRequest, jsonObject); } + std::shared_ptr pushCallBackParam = std::make_shared(); + std::shared_ptr extroInfo = nullptr; + if (request->IsCommonLiveView()) { + auto content = request->GetContent()->GetNotificationContent(); + auto liveViewContent = std::static_pointer_cast(content); + extroInfo = liveViewContent->GetExtraInfo(); + if (pushCallBackParam != nullptr) { + if (extroInfo != nullptr && extroInfo->HasParam("event")) { + pushCallBackParam->event = extroInfo->GetStringParam("event"); + ANS_LOGI("get event,%{public}s", pushCallBackParam->event.c_str()); + } else { + ANS_LOGI("get event fail"); + } + } + } - ErrCode result = pushCallBack->OnCheckNotification(jsonObject.dump(), nullptr); + ErrCode result = pushCallBack->OnCheckNotification(jsonObject.dump(), pushCallBackParam); if (result != ERR_OK) { HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_2, EventBranchId::BRANCH_5) .ErrorCode(result).Message("Push OnCheckNotification failed."); NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); } + if (pushCallBackParam != nullptr && !pushCallBackParam->eventControl.empty() && extroInfo != nullptr) { + extroInfo->SetParam("eventControl", AAFwk::String::Box(pushCallBackParam->eventControl)); + } else { + extroInfo->Remove("eventControl"); + } return result; } -- Gitee From 2f059bea977f090e78e215f6f8ed5fd4c5c3835b Mon Sep 17 00:00:00 2001 From: songbao1 Date: Sat, 8 Mar 2025 15:01:40 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=B2=89=E6=B5=B8=E9=94=81=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- services/ans/src/advanced_notification_publish_service.cpp | 6 ++++++ services/ans/src/advanced_notification_service.cpp | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index bb8001b55..f04b2a10a 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -171,6 +171,12 @@ ErrCode AdvancedNotificationService::Publish(const std::string &label, const spt #ifndef IS_EMULATOR if (IsNeedPushCheck(request)) { result = PushCheck(request); + if (AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER) && + AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER) && + result != ERR_OK) { + ANS_LOGI("The application with the permission fails to pushcheck."); + result = ERR_OK; + } } #endif diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 40142bdcb..d00f415a4 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2125,11 +2125,6 @@ bool AdvancedNotificationService::IsNeedPushCheck(const sptrNotifyApplicationInfoNeedChanged(request->GetCreatorBundleName()); - if (AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER) && - AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER)) { - ANS_LOGI("The creator has the permission, no need to check."); - return false; - } ANS_LOGI("Common live view requires push check."); return true; } -- Gitee From 8c78d456b971663f271e4847f0e6f3180c04dbbc Mon Sep 17 00:00:00 2001 From: songbao1 Date: Sat, 8 Mar 2025 15:32:49 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=B2=89=E6=B5=B8=E9=94=81=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- frameworks/ans/src/push_callback_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ans/src/push_callback_stub.cpp b/frameworks/ans/src/push_callback_stub.cpp index d4244c5eb..e6a2103ce 100644 --- a/frameworks/ans/src/push_callback_stub.cpp +++ b/frameworks/ans/src/push_callback_stub.cpp @@ -144,7 +144,7 @@ int32_t PushCallBackProxy::OnCheckNotification( return false; } - + int result = reply.ReadInt32(); + int result = reply.ReadInt32(); std::string eventControl; if (reply.ReadString(eventControl)) { ANS_LOGI("HandleEventControl"); -- Gitee From 751d1a8034299bd62a5b9911ba076b7c7d301282 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Mon, 10 Mar 2025 14:14:49 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=B2=89=E6=B5=B8=E9=94=81=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- services/ans/src/advanced_notification_service.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index d00f415a4..5c9a24b53 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2185,7 +2185,11 @@ ErrCode AdvancedNotificationService::PushCheck(const sptr & } nlohmann::json jsonObject; - jsonObject["pkgName"] = request->GetCreatorBundleName(); + if (request->IsAgentNotification() && !request->GetOwnerBundleName().empty()) { + jsonObject["pkgName"] = request->GetOwnerBundleName(); + } else { + jsonObject["pkgName"] = request->GetCreatorBundleName(); + } jsonObject["notifyId"] = request->GetNotificationId(); jsonObject["contentType"] = static_cast(request->GetNotificationType()); jsonObject["creatorUserId"] = request->GetCreatorUserId(); @@ -2204,8 +2208,6 @@ ErrCode AdvancedNotificationService::PushCheck(const sptr & if (extroInfo != nullptr && extroInfo->HasParam("event")) { pushCallBackParam->event = extroInfo->GetStringParam("event"); ANS_LOGI("get event,%{public}s", pushCallBackParam->event.c_str()); - } else { - ANS_LOGI("get event fail"); } } } -- Gitee From 791b6ef3f249c317202e61756aab70706f636f9e Mon Sep 17 00:00:00 2001 From: songbao1 Date: Mon, 10 Mar 2025 14:27:10 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=B2=89=E6=B5=B8=E9=94=81=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- frameworks/ans/src/notification_request.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 84f18c562..a7b01c4c9 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -2685,9 +2685,8 @@ void NotificationRequest::FillMissingParameters(const sptr } auto newPicture = newLiveViewContent->GetPicture(); - auto oldPicture = oldLiveViewContent->GetPicture(); bool isSet = false; - for (const auto &pictureRecord : oldPicture) { + for (const auto &pictureRecord : oldLiveViewContent->GetPicture()) { if (newPicture.find(pictureRecord.first) != newPicture.end()) { continue; } -- Gitee From 2ad28bb39b704579f7246d405290191f66e8dd16 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Mon, 10 Mar 2025 14:31:48 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=B2=89=E6=B5=B8=E9=94=81=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- services/ans/src/advanced_notification_publish_service.cpp | 6 ------ services/ans/src/advanced_notification_service.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index f04b2a10a..bb8001b55 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -171,12 +171,6 @@ ErrCode AdvancedNotificationService::Publish(const std::string &label, const spt #ifndef IS_EMULATOR if (IsNeedPushCheck(request)) { result = PushCheck(request); - if (AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER) && - AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER) && - result != ERR_OK) { - ANS_LOGI("The application with the permission fails to pushcheck."); - result = ERR_OK; - } } #endif diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 5c9a24b53..38bfd259f 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -2213,6 +2213,12 @@ ErrCode AdvancedNotificationService::PushCheck(const sptr & } ErrCode result = pushCallBack->OnCheckNotification(jsonObject.dump(), pushCallBackParam); + if (AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER) && + AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER) && + result != ERR_OK) { + ANS_LOGI("The application with the permission fails to pushcheck."); + result = ERR_OK; + } if (result != ERR_OK) { HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_2, EventBranchId::BRANCH_5) .ErrorCode(result).Message("Push OnCheckNotification failed."); -- Gitee