diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 9eb97c8488a3fc9c9f3c2e9b8078898fc3e9bf6b..a7b01c4c999376703b435dc33949777c4240ebc3 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)) { @@ -2684,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; } diff --git a/frameworks/ans/src/push_callback_stub.cpp b/frameworks/ans/src/push_callback_stub.cpp index 6e871cfeba0faf4cbe45c3e5f68b590acc77b38b..e6a2103ce8b1ab84b61224118de6cf6340699b34 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 c39b816b0ec6e0cfe8cae2a9140ec9aedec9aa30..4f009a155d49355c783166d6c3a473bb4f1c3fa8 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 b2702770933ee2346c036ce3c99f579745a9b080..93740540cb6eb4b87eb4e630db6912f53fdfd932 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 35b1286b05ce97d556a809eb554c2c1a3cf19e65..38bfd259f2e8f96411e190cf2a055c58a9790acd 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 { @@ -2124,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; } @@ -2189,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(); @@ -2198,13 +2198,37 @@ 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()); + } + } + } - ErrCode result = pushCallBack->OnCheckNotification(jsonObject.dump(), nullptr); + 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."); 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; }