From 2a851918daddd20be71ed0f229208b67a4a1d2ea Mon Sep 17 00:00:00 2001 From: zhangxin_T Date: Fri, 11 Feb 2022 12:01:54 +0800 Subject: [PATCH] bugfix for get wantagent failed Signed-off-by: zhangxin_T --- .../ans/native/src/notification_request.cpp | 8 +++++++ frameworks/wantagent/BUILD.gn | 1 + frameworks/wantagent/src/pending_want.cpp | 21 +++++++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/frameworks/ans/native/src/notification_request.cpp b/frameworks/ans/native/src/notification_request.cpp index 9807dace3..1c07290ea 100644 --- a/frameworks/ans/native/src/notification_request.cpp +++ b/frameworks/ans/native/src/notification_request.cpp @@ -645,6 +645,7 @@ std::string NotificationRequest::Dump() ", creatorBundleName = " + creatorBundleName_ + ", creatorPid = " + std::to_string(static_cast(creatorPid_)) + ", creatorUid = " + std::to_string(static_cast(creatorUid_)) + + ", creatorUserId = " + std::to_string(static_cast(creatorUserId_)) + ", ownerBundleName = " + ownerBundleName_ + ", groupName = " + groupName_ + ", statusBarText = " + statusBarText_ + ", label = " + label_ + ", shortcutId = " + shortcutId_ + ", sortingKey = " + sortingKey_ + @@ -840,6 +841,11 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteInt32(static_cast(creatorUserId_))) { + ANS_LOGE("Failed to write creator userId"); + return false; + } + // write std::string if (!parcel.WriteString(settingsText_)) { ANS_LOGE("Failed to write settings text"); @@ -1174,6 +1180,7 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) creatorPid_ = static_cast(parcel.ReadInt32()); creatorUid_ = static_cast(parcel.ReadInt32()); + creatorUserId_ = static_cast(parcel.ReadInt32()); if (!parcel.ReadString(settingsText_)) { ANS_LOGE("Failed to read settings text"); @@ -1411,6 +1418,7 @@ void NotificationRequest::CopyBase(const NotificationRequest &other) this->creatorPid_ = other.creatorPid_; this->creatorUid_ = other.creatorUid_; + this->creatorUserId_ = other.creatorUserId_; this->slotType_ = other.slotType_; this->settingsText_ = other.settingsText_; diff --git a/frameworks/wantagent/BUILD.gn b/frameworks/wantagent/BUILD.gn index 49974f7cd..afca46fc1 100644 --- a/frameworks/wantagent/BUILD.gn +++ b/frameworks/wantagent/BUILD.gn @@ -72,6 +72,7 @@ ohos_shared_library("wantagent_innerkits") { "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "os_account_standard:os_account_innerkits", "samgr_standard:samgr_proxy", ] diff --git a/frameworks/wantagent/src/pending_want.cpp b/frameworks/wantagent/src/pending_want.cpp index 62fddd422..c8b9a8cfe 100644 --- a/frameworks/wantagent/src/pending_want.cpp +++ b/frameworks/wantagent/src/pending_want.cpp @@ -16,6 +16,8 @@ #include "pending_want.h" #include "ability_manager_client.h" #include "hilog_wrapper.h" +#include "ipc_skeleton.h" +#include "os_account_manager.h" #include "pending_want_record.h" #include "want_agent_log_wrapper.h" #include "want_sender_info.h" @@ -39,6 +41,17 @@ WantAgentConstant::OperationType PendingWant::GetType(const sptr PendingWant::GetAbility( const std::shared_ptr &context, int requestCode, const std::shared_ptr &want, unsigned int flags) @@ -68,7 +81,7 @@ std::shared_ptr PendingWant::GetAbility( wantSenderInfo.allWants.push_back(wantsInfo); wantSenderInfo.bundleName = context->GetBundleName(); wantSenderInfo.flags = flags; - wantSenderInfo.userId = 0; + wantSenderInfo.userId = GetCurrentUserId(); wantSenderInfo.requestCode = requestCode; sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); WANT_AGENT_LOGI("PendingWant::GetAbility end."); @@ -95,7 +108,7 @@ std::shared_ptr PendingWant::GetAbilities(const std::shared_ptrGetBundleName(); wantSenderInfo.flags = flags; - wantSenderInfo.userId = 0; + wantSenderInfo.userId = GetCurrentUserId(); wantSenderInfo.requestCode = requestCode; for (auto want : wants) { WantsInfo wantsInfo; @@ -140,7 +153,7 @@ std::shared_ptr PendingWant::GetCommonEventAsUser( wantSenderInfo.allWants.push_back(wantsInfo); wantSenderInfo.bundleName = context->GetBundleName(); wantSenderInfo.flags = flags; - wantSenderInfo.userId = 0; + wantSenderInfo.userId = GetCurrentUserId(); wantSenderInfo.requestCode = requestCode; sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); @@ -184,7 +197,7 @@ std::shared_ptr PendingWant::BuildServicePendingWant( wantSenderInfo.allWants.push_back(wantsInfo); wantSenderInfo.bundleName = context->GetBundleName(); wantSenderInfo.flags = flags; - wantSenderInfo.userId = 0; + wantSenderInfo.userId = GetCurrentUserId(); wantSenderInfo.requestCode = requestCode; sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); -- Gitee