diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index ab0ba0f8f3f0ac0773775eb4d0b0e89c22045d9d..10fb081d45a4e4dc23b084e0812bed0ed8b2ee25 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -2549,6 +2549,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)) { @@ -2563,9 +2564,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..aefe12c23f04a13e8b65c2a6cf4ecebb39ae8f73 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,40 @@ int32_t PushCallBackProxy::OnCheckNotification( return false; } - return reply.ReadInt32(); + int result = reply.ReadInt32(); + std::string eventControl; + if (reply.ReadString(eventControl)) { + 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..76a9411a49cb04d5318cf71bc33a46bc3aa51376 100644 --- a/interfaces/inner_api/push_callback_proxy.h +++ b/interfaces/inner_api/push_callback_proxy.h @@ -42,6 +42,8 @@ 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/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index fbfded21e6085ea3594c71d9b923c4bf330e2b93..60485435b85164b9a151ac7d1beca57d44e98fed 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1337,6 +1337,8 @@ private: bool IsNeedPushCheck(const sptr &request); void FillExtraInfoToJson(const sptr &request, sptr &checkRequest, nlohmann::json &jsonObject); + void CreatePushCheckJson(const sptr &request, + sptr &checkRequest, nlohmann::json &jsonObject); ErrCode PushCheck(const sptr &request); uint64_t StartAutoDelete(const std::shared_ptr &record, int64_t deleteTimePoint, int32_t reason); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index bdf5f4921d00d2370e651028ce580fe92c5ff9d9..f9caf3922d69ae8380288f4f9bdae47658f37f7b 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -76,6 +76,7 @@ #include "advanced_datashare_helper_ext.h" #include "notification_analytics_util.h" #include "advanced_notification_flow_control_service.h" +#include "string_wrapper.h" namespace OHOS { namespace Notification { @@ -2016,11 +2017,6 @@ bool AdvancedNotificationService::IsNeedPushCheck(const sptrIsCommonLiveView()) { - 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; - } std::shared_ptr content = request->GetContent(); auto liveViewContent = std::static_pointer_cast(content->GetNotificationContent()); auto status = liveViewContent->GetLiveViewStatus(); @@ -2075,6 +2071,24 @@ void AdvancedNotificationService::FillExtraInfoToJson( } } +void AdvancedNotificationService::CreatePushCheckJson( + const sptr &request, sptr &checkRequest, nlohmann::json &jsonObject) +{ + if (request->IsAgentNotification()) { + jsonObject["pkgName"] = request->GetOwnerBundleName(); + } else { + jsonObject["pkgName"] = request->GetCreatorBundleName(); + } + jsonObject["notifyId"] = request->GetNotificationId(); + jsonObject["contentType"] = static_cast(request->GetNotificationType()); + jsonObject["creatorUserId"] = request->GetCreatorUserId(); + jsonObject["slotType"] = static_cast(request->GetSlotType()); + jsonObject["label"] = request->GetLabel(); + if (request->IsCommonLiveView()) { + FillExtraInfoToJson(request, checkRequest, jsonObject); + } +} + ErrCode AdvancedNotificationService::PushCheck(const sptr &request) { ANS_LOGD("start."); @@ -2088,22 +2102,38 @@ ErrCode AdvancedNotificationService::PushCheck(const sptr & } nlohmann::json jsonObject; - jsonObject["pkgName"] = request->GetCreatorBundleName(); - jsonObject["notifyId"] = request->GetNotificationId(); - jsonObject["contentType"] = static_cast(request->GetNotificationType()); - jsonObject["creatorUserId"] = request->GetCreatorUserId(); - jsonObject["slotType"] = static_cast(request->GetSlotType()); - jsonObject["label"] = request->GetLabel(); + CreatePushCheckJson(request, checkRequest, jsonObject); + std::shared_ptr pushCallBackParam = std::make_shared(); + std::shared_ptr extroInfo = nullptr; if (request->IsCommonLiveView()) { - FillExtraInfoToJson(request, checkRequest, jsonObject); + 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; }