1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ABILITY_RUNTIME_WANT_AGENT_CLIENT_H 17 #define OHOS_ABILITY_RUNTIME_WANT_AGENT_CLIENT_H 18 19 #include <mutex> 20 21 #include "iremote_object.h" 22 #include "want.h" 23 #include "want_receiver_interface.h" 24 #include "want_sender_info.h" 25 #include "want_sender_interface.h" 26 27 namespace OHOS { 28 namespace AAFwk { 29 /** 30 * @class WantAgentClient 31 * WantAgentClient is used to access want agent in ability manager service. 32 */ 33 class WantAgentClient { 34 public: 35 static WantAgentClient &GetInstance(); 36 37 ErrCode GetWantSender(const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken, 38 sptr<IWantSender> &wantSender, int32_t uid = -1); 39 40 ErrCode SendWantSender(sptr<IWantSender> target, const SenderInfo &senderInfo); 41 42 ErrCode CancelWantSender(const sptr<IWantSender> &sender, uint32_t flags = 0); 43 44 ErrCode GetPendingWantUid(const sptr<IWantSender> &target, int32_t &uid); 45 46 ErrCode GetPendingWantUserId(const sptr<IWantSender> &target, int32_t &userId); 47 48 ErrCode GetPendingWantBundleName(const sptr<IWantSender> &target, std::string &bundleName); 49 50 ErrCode GetPendingWantCode(const sptr<IWantSender> &target, int32_t &code); 51 52 ErrCode GetPendingWantType(sptr<IWantSender> target, int32_t &type); 53 54 void RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver); 55 56 void UnregisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver); 57 58 ErrCode GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want); 59 60 ErrCode GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info); 61 private: 62 class WantAgentDeathRecipient : public IRemoteObject::DeathRecipient { 63 public: 64 WantAgentDeathRecipient() = default; 65 ~WantAgentDeathRecipient() = default; 66 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 67 private: 68 DISALLOW_COPY_AND_MOVE(WantAgentDeathRecipient); 69 }; 70 WantAgentClient(); 71 virtual ~WantAgentClient(); 72 DISALLOW_COPY_AND_MOVE(WantAgentClient); 73 74 sptr<IRemoteObject> GetAbilityManager(); 75 void ResetProxy(const wptr<IRemoteObject>& remote); 76 bool WriteInterfaceToken(MessageParcel &data); 77 bool CheckSenderAndRecevier(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver); 78 bool SendRequest(int32_t operation, const sptr<IRemoteObject> &abms, 79 const sptr<IRemoteObject> &remoteObject, MessageParcel &reply, ErrCode &error); 80 81 std::mutex mutex_; 82 sptr<IRemoteObject> proxy_; 83 sptr<IRemoteObject::DeathRecipient> deathRecipient_; 84 }; 85 } // namespace AAFwk 86 } // namespace OHOS 87 #endif // OHOS_ABILITY_RUNTIME_WANT_AGENT_CLIENT_H 88