From e44446f73f5930745c11442fc3109dfa221ac789 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 27 Jul 2022 16:36:53 +0800 Subject: [PATCH 1/3] add user Signed-off-by: unknown --- .../wantagent/include/want_agent_client.h | 9 +- .../wantagent/src/want_agent_client.cpp | 285 ++++++++++++++++-- 2 files changed, 266 insertions(+), 28 deletions(-) diff --git a/interfaces/inner_api/wantagent/include/want_agent_client.h b/interfaces/inner_api/wantagent/include/want_agent_client.h index 8ad0d46dba7..340cc3df7a8 100644 --- a/interfaces/inner_api/wantagent/include/want_agent_client.h +++ b/interfaces/inner_api/wantagent/include/want_agent_client.h @@ -18,9 +18,11 @@ #include -#include "ability_manager_interface.h" #include "iremote_object.h" #include "want.h" +#include "want_receiver_interface.h" +#include "want_sender_info.h" +#include "want_sender_interface.h" namespace OHOS { namespace AAFwk { @@ -68,11 +70,12 @@ private: virtual ~WantAgentClient(); DISALLOW_COPY_AND_MOVE(WantAgentClient); - sptr GetAbilityManager(); + sptr GetAbilityManager(); void ResetProxy(const wptr& remote); + bool WriteInterfaceToken(MessageParcel &data); std::recursive_mutex mutex_; - sptr proxy_; + sptr proxy_; sptr deathRecipient_; }; } // namespace AAFwk diff --git a/interfaces/inner_api/wantagent/src/want_agent_client.cpp b/interfaces/inner_api/wantagent/src/want_agent_client.cpp index 5d05561293f..01ad8845b59 100644 --- a/interfaces/inner_api/wantagent/src/want_agent_client.cpp +++ b/interfaces/inner_api/wantagent/src/want_agent_client.cpp @@ -16,6 +16,7 @@ #include "want_agent_client.h" #include "ability_manager_errors.h" +#include "ability_manager_interface.h" #include "hilog_wrapper.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" @@ -41,7 +42,38 @@ sptr WantAgentClient::GetWantSender( HILOG_ERROR("ability proxy is nullptr."); return nullptr; } - return abms->GetWantSender(wantSenderInfo, callerToken); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return nullptr; + } + if (!data.WriteParcelable(&wantSenderInfo)) { + HILOG_ERROR("wantSenderInfo write failed."); + return nullptr; + } + if (callerToken) { + if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) { + HILOG_ERROR("flag and callerToken write failed."); + return nullptr; + } + } else { + if (!data.WriteBool(false)) { + HILOG_ERROR("flag write failed."); + return nullptr; + } + } + + auto error = abms->SendRequest(IAbilityManager::GET_PENDING_WANT_SENDER, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return nullptr; + } + sptr wantSender = iface_cast(reply.ReadRemoteObject()); + if (!wantSender) { + return nullptr; + } + return wantSender; } ErrCode WantAgentClient::SendWantSender(const sptr &target, const SenderInfo &senderInfo) @@ -51,7 +83,27 @@ ErrCode WantAgentClient::SendWantSender(const sptr &target, const S HILOG_ERROR("ability proxy is nullptr."); return ABILITY_SERVICE_NOT_CONNECTED; } - return abms->SendWantSender(target, senderInfo); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + HILOG_ERROR("target write failed."); + return INNER_ERR; + } + if (!data.WriteParcelable(&senderInfo)) { + HILOG_ERROR("senderInfo write failed."); + return INNER_ERR; + } + + auto error = abms->SendRequest(IAbilityManager::SEND_PENDING_WANT_SENDER, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); } void WantAgentClient::CancelWantSender(const sptr &sender) @@ -61,7 +113,21 @@ void WantAgentClient::CancelWantSender(const sptr &sender) HILOG_ERROR("ability proxy is nullptr."); return; } - abms->CancelWantSender(sender); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return; + } + if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) { + HILOG_ERROR("sender write failed."); + return; + } + auto error = abms->SendRequest(IAbilityManager::CANCEL_PENDING_WANT_SENDER, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return; + } } ErrCode WantAgentClient::GetPendingWantUid(const sptr &target, int32_t &uid) @@ -75,7 +141,22 @@ ErrCode WantAgentClient::GetPendingWantUid(const sptr &target, int3 HILOG_ERROR("ability proxy is nullptr."); return ABILITY_SERVICE_NOT_CONNECTED; } - uid = abms->GetPendingWantUid(target); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + HILOG_ERROR("target write failed."); + return ERR_INVALID_VALUE; + } + auto error = abms->SendRequest(IAbilityManager::GET_PENDING_WANT_UID, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return INNER_ERR; + } + uid = reply.ReadInt32(); return ERR_OK; } @@ -90,7 +171,22 @@ ErrCode WantAgentClient::GetPendingWantUserId(const sptr &target, i HILOG_ERROR("ability proxy is nullptr."); return ABILITY_SERVICE_NOT_CONNECTED; } - userId = abms->GetPendingWantUserId(target); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + HILOG_ERROR("target write failed."); + return ERR_INVALID_VALUE; + } + auto error = abms->SendRequest(IAbilityManager::GET_PENDING_WANT_USERID, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return INNER_ERR; + } + userId = reply.ReadInt32(); return ERR_OK; } @@ -105,7 +201,22 @@ ErrCode WantAgentClient::GetPendingWantBundleName(const sptr &targe HILOG_ERROR("ability proxy is nullptr."); return ABILITY_SERVICE_NOT_CONNECTED; } - bundleName = abms->GetPendingWantBundleName(target); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (!data.WriteRemoteObject(target->AsObject())) { + HILOG_ERROR("target write failed."); + return INNER_ERR; + } + auto error = abms->SendRequest(IAbilityManager::GET_PENDING_WANT_BUNDLENAME, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return INNER_ERR; + } + bundleName = Str16ToStr8(reply.ReadString16()); return ERR_OK; } @@ -120,7 +231,22 @@ ErrCode WantAgentClient::GetPendingWantCode(const sptr &target, int HILOG_ERROR("ability proxy is nullptr."); return ABILITY_SERVICE_NOT_CONNECTED; } - code = abms->GetPendingWantCode(target); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + HILOG_ERROR("target write failed."); + return ERR_INVALID_VALUE; + } + auto error = abms->SendRequest(IAbilityManager::GET_PENDING_WANT_CODE, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return INNER_ERR; + } + code = reply.ReadInt32(); return ERR_OK; } @@ -135,19 +261,34 @@ ErrCode WantAgentClient::GetPendingWantType(const sptr &target, int HILOG_ERROR("ability proxy is nullptr."); return ABILITY_SERVICE_NOT_CONNECTED; } - type = abms->GetPendingWantType(target); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + HILOG_ERROR("target write failed."); + return ERR_INVALID_VALUE; + } + auto error = abms->SendRequest(IAbilityManager::GET_PENDING_WANT_TYPE, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return INNER_ERR; + } + type = reply.ReadInt32(); type < 0 ? type = 0 : type; return ERR_OK; } -void WantAgentClient::RegisterCancelListener(const sptr &sender, const sptr &recevier) +void WantAgentClient::RegisterCancelListener(const sptr &sender, const sptr &receiver) { if (sender == nullptr) { HILOG_ERROR("sender is nullptr."); return; } - if (recevier == nullptr) { - HILOG_ERROR("recevier is nullptr."); + if (receiver == nullptr) { + HILOG_ERROR("receiver is nullptr."); return; } auto abms = GetAbilityManager(); @@ -155,18 +296,36 @@ void WantAgentClient::RegisterCancelListener(const sptr &sender, co HILOG_ERROR("ability proxy is nullptr."); return; } - abms->RegisterCancelListener(sender, recevier); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return; + } + if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) { + HILOG_ERROR("sender write failed."); + return; + } + if (receiver == nullptr || !data.WriteRemoteObject(receiver->AsObject())) { + HILOG_ERROR("receiver write failed."); + return; + } + auto error = abms->SendRequest(IAbilityManager::REGISTER_CANCEL_LISTENER, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return; + } } void WantAgentClient::UnregisterCancelListener( - const sptr &sender, const sptr &recevier) + const sptr &sender, const sptr &receiver) { if (sender == nullptr) { HILOG_ERROR("sender is nullptr."); return; } - if (recevier == nullptr) { - HILOG_ERROR("recevier is nullptr."); + if (receiver == nullptr) { + HILOG_ERROR("receiver is nullptr."); return; } auto abms = GetAbilityManager(); @@ -174,7 +333,25 @@ void WantAgentClient::UnregisterCancelListener( HILOG_ERROR("ability proxy is nullptr."); return; } - abms->UnregisterCancelListener(sender, recevier); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteRemoteObject(sender->AsObject())) { + HILOG_ERROR("sender write failed."); + return; + } + if (!data.WriteRemoteObject(receiver->AsObject())) { + HILOG_ERROR("receiver write failed."); + return; + } + auto error = abms->SendRequest(IAbilityManager::UNREGISTER_CANCEL_LISTENER, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return; + } } ErrCode WantAgentClient::GetPendingRequestWant(const sptr &target, std::shared_ptr &want) @@ -192,7 +369,33 @@ ErrCode WantAgentClient::GetPendingRequestWant(const sptr &target, HILOG_ERROR("ability proxy is nullptr."); return ABILITY_SERVICE_NOT_CONNECTED; } - return abms->GetPendingRequestWant(target, want); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + HILOG_ERROR("target write failed."); + return INNER_ERR; + } + if (want == nullptr || !data.WriteParcelable(want.get())) { + HILOG_ERROR("want write failed."); + return INNER_ERR; + } + auto error = abms->SendRequest(IAbilityManager::GET_PENDING_REQUEST_WANT, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + std::unique_ptr wantInfo(reply.ReadParcelable()); + if (!wantInfo) { + HILOG_ERROR("readParcelableInfo failed"); + return INNER_ERR; + } + want = std::move(wantInfo); + + return NO_ERROR; } ErrCode WantAgentClient::GetWantSenderInfo(const sptr &target, std::shared_ptr &info) @@ -210,10 +413,36 @@ ErrCode WantAgentClient::GetWantSenderInfo(const sptr &target, std: HILOG_ERROR("ability proxy is nullptr."); return ABILITY_SERVICE_NOT_CONNECTED; } - return abms->GetWantSenderInfo(target, info); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + HILOG_ERROR("target write failed."); + return INNER_ERR; + } + if (info == nullptr || !data.WriteParcelable(info.get())) { + HILOG_ERROR("info write failed."); + return INNER_ERR; + } + auto error = abms->SendRequest(IAbilityManager::GET_PENDING_WANT_SENDER_INFO, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + std::unique_ptr wantSenderInfo(reply.ReadParcelable()); + if (!wantSenderInfo) { + HILOG_ERROR("readParcelable Info failed"); + return INNER_ERR; + } + info = std::move(wantSenderInfo); + + return NO_ERROR; } -sptr WantAgentClient::GetAbilityManager() +sptr WantAgentClient::GetAbilityManager() { std::lock_guard lock(mutex_); if (proxy_ == nullptr) { @@ -233,11 +462,11 @@ sptr WantAgentClient::GetAbilityManager() HILOG_ERROR("%{public}s :Failed to create AbilityMgrDeathRecipient!", __func__); return nullptr; } - if ((remoteObj->IsProxyObject()) && (!remoteObj->AddDeathRecipient(deathRecipient_))) { + if (!remoteObj->AddDeathRecipient(deathRecipient_)) { HILOG_ERROR("%{public}s :Add death recipient to AbilityManagerService failed.", __func__); return nullptr; } - proxy_ = iface_cast(remoteObj); + proxy_ = remoteObj; } return proxy_; @@ -256,11 +485,17 @@ void WantAgentClient::ResetProxy(const wptr& remote) return; } - auto serviceRemote = proxy_->AsObject(); - if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) { - serviceRemote->RemoveDeathRecipient(deathRecipient_); - } + proxy_->RemoveDeathRecipient(deathRecipient_); proxy_ = nullptr; } + +bool WantAgentClient::WriteInterfaceToken(MessageParcel &data) +{ + if (!data.WriteInterfaceToken(IAbilityManager::GetDescriptor())) { + HILOG_ERROR("write interface token failed."); + return false; + } + return true; +} } // namespace AAFwk } // namespace OHOS -- Gitee From 88cc9ae47545aafa670bf6b348c97015ce75fbb2 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 27 Jul 2022 18:24:33 +0800 Subject: [PATCH 2/3] add user Signed-off-by: unknown --- .../wantagent/include/want_agent_client.h | 8 ++--- .../wantagent/src/want_agent_client.cpp | 36 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/interfaces/inner_api/wantagent/include/want_agent_client.h b/interfaces/inner_api/wantagent/include/want_agent_client.h index 340cc3df7a8..35b9b071126 100644 --- a/interfaces/inner_api/wantagent/include/want_agent_client.h +++ b/interfaces/inner_api/wantagent/include/want_agent_client.h @@ -58,13 +58,13 @@ public: ErrCode GetWantSenderInfo(const sptr &target, std::shared_ptr &info); private: - class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient { + class WantAgentDeathRecipient : public IRemoteObject::DeathRecipient { public: - AbilityMgrDeathRecipient() = default; - ~AbilityMgrDeathRecipient() = default; + WantAgentDeathRecipient() = default; + ~WantAgentDeathRecipient() = default; void OnRemoteDied(const wptr& remote) override; private: - DISALLOW_COPY_AND_MOVE(AbilityMgrDeathRecipient); + DISALLOW_COPY_AND_MOVE(WantAgentDeathRecipient); }; WantAgentClient(); virtual ~WantAgentClient(); diff --git a/interfaces/inner_api/wantagent/src/want_agent_client.cpp b/interfaces/inner_api/wantagent/src/want_agent_client.cpp index 01ad8845b59..7a1e99c5985 100644 --- a/interfaces/inner_api/wantagent/src/want_agent_client.cpp +++ b/interfaces/inner_api/wantagent/src/want_agent_client.cpp @@ -147,7 +147,7 @@ ErrCode WantAgentClient::GetPendingWantUid(const sptr &target, int3 if (!WriteInterfaceToken(data)) { return INNER_ERR; } - if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + if (!data.WriteRemoteObject(target->AsObject())) { HILOG_ERROR("target write failed."); return ERR_INVALID_VALUE; } @@ -177,7 +177,7 @@ ErrCode WantAgentClient::GetPendingWantUserId(const sptr &target, i if (!WriteInterfaceToken(data)) { return INNER_ERR; } - if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + if (!data.WriteRemoteObject(target->AsObject())) { HILOG_ERROR("target write failed."); return ERR_INVALID_VALUE; } @@ -237,7 +237,7 @@ ErrCode WantAgentClient::GetPendingWantCode(const sptr &target, int if (!WriteInterfaceToken(data)) { return INNER_ERR; } - if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + if (!data.WriteRemoteObject(target->AsObject())) { HILOG_ERROR("target write failed."); return ERR_INVALID_VALUE; } @@ -267,7 +267,7 @@ ErrCode WantAgentClient::GetPendingWantType(const sptr &target, int if (!WriteInterfaceToken(data)) { return INNER_ERR; } - if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + if (!data.WriteRemoteObject(target->AsObject())) { HILOG_ERROR("target write failed."); return ERR_INVALID_VALUE; } @@ -302,11 +302,11 @@ void WantAgentClient::RegisterCancelListener(const sptr &sender, co if (!WriteInterfaceToken(data)) { return; } - if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) { + if (!data.WriteRemoteObject(sender->AsObject())) { HILOG_ERROR("sender write failed."); return; } - if (receiver == nullptr || !data.WriteRemoteObject(receiver->AsObject())) { + if (!data.WriteRemoteObject(receiver->AsObject())) { HILOG_ERROR("receiver write failed."); return; } @@ -375,11 +375,11 @@ ErrCode WantAgentClient::GetPendingRequestWant(const sptr &target, if (!WriteInterfaceToken(data)) { return INNER_ERR; } - if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + if (!data.WriteRemoteObject(target->AsObject())) { HILOG_ERROR("target write failed."); return INNER_ERR; } - if (want == nullptr || !data.WriteParcelable(want.get())) { + if (!data.WriteParcelable(want.get())) { HILOG_ERROR("want write failed."); return INNER_ERR; } @@ -419,11 +419,11 @@ ErrCode WantAgentClient::GetWantSenderInfo(const sptr &target, std: if (!WriteInterfaceToken(data)) { return INNER_ERR; } - if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) { + if (!data.WriteRemoteObject(target->AsObject())) { HILOG_ERROR("target write failed."); return INNER_ERR; } - if (info == nullptr || !data.WriteParcelable(info.get())) { + if (!data.WriteParcelable(info.get())) { HILOG_ERROR("info write failed."); return INNER_ERR; } @@ -457,14 +457,13 @@ sptr WantAgentClient::GetAbilityManager() return nullptr; } - deathRecipient_ = sptr(new (std::nothrow) AbilityMgrDeathRecipient()); + deathRecipient_ = sptr(new (std::nothrow) WantAgentDeathRecipient()); if (deathRecipient_ == nullptr) { - HILOG_ERROR("%{public}s :Failed to create AbilityMgrDeathRecipient!", __func__); + HILOG_ERROR("%{public}s :Failed to create WantAgentDeathRecipient!", __func__); return nullptr; } if (!remoteObj->AddDeathRecipient(deathRecipient_)) { - HILOG_ERROR("%{public}s :Add death recipient to AbilityManagerService failed.", __func__); - return nullptr; + HILOG_INFO("%{public}s :Add death recipient to failed, maybe already add.", __func__); } proxy_ = remoteObj; } @@ -472,9 +471,9 @@ sptr WantAgentClient::GetAbilityManager() return proxy_; } -void WantAgentClient::AbilityMgrDeathRecipient::OnRemoteDied(const wptr& remote) +void WantAgentClient::WantAgentDeathRecipient::OnRemoteDied(const wptr& remote) { - HILOG_INFO("AbilityMgrDeathRecipient handle remote died."); + HILOG_INFO("WantAgentDeathRecipient handle remote died."); WantAgentClient::GetInstance().ResetProxy(remote); } @@ -484,8 +483,9 @@ void WantAgentClient::ResetProxy(const wptr& remote) if (!proxy_) { return; } - - proxy_->RemoveDeathRecipient(deathRecipient_); + if(proxy_ == remote.promote()) { + proxy_->RemoveDeathRecipient(deathRecipient_); + } proxy_ = nullptr; } -- Gitee From 967ed45f41aba64c2c50a45c4afa5f2b948be2a8 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 27 Jul 2022 18:35:52 +0800 Subject: [PATCH 3/3] add user Signed-off-by: unknown --- interfaces/inner_api/wantagent/src/want_agent_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/wantagent/src/want_agent_client.cpp b/interfaces/inner_api/wantagent/src/want_agent_client.cpp index 7a1e99c5985..98458a1d8cf 100644 --- a/interfaces/inner_api/wantagent/src/want_agent_client.cpp +++ b/interfaces/inner_api/wantagent/src/want_agent_client.cpp @@ -483,7 +483,7 @@ void WantAgentClient::ResetProxy(const wptr& remote) if (!proxy_) { return; } - if(proxy_ == remote.promote()) { + if (proxy_ == remote.promote()) { proxy_->RemoveDeathRecipient(deathRecipient_); } proxy_ = nullptr; -- Gitee