1 /* 2 * Copyright (c) 2021 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_PENDING_WANT_RECORD_H 17 #define OHOS_ABILITY_RUNTIME_PENDING_WANT_RECORD_H 18 19 #include <list> 20 #include <mutex> 21 #include "cpp/mutex.h" 22 23 #include "iremote_object.h" 24 #include "pending_want_key.h" 25 #include "refbase.h" 26 #include "sender_info.h" 27 #include "want_sender_stub.h" 28 29 namespace OHOS { 30 namespace AAFwk { 31 class PendingWantManager; 32 class PendingWantRecord : public WantSenderStub { 33 public: 34 static const int START_CANCELED = -96; 35 36 PendingWantRecord(); 37 PendingWantRecord(const std::shared_ptr<PendingWantManager> &pendingWantManager, int32_t uid, 38 int32_t callerTokenId, const sptr<IRemoteObject> &callerToken, std::shared_ptr<PendingWantKey> key); 39 virtual ~PendingWantRecord(); 40 41 virtual void Send(SenderInfo &senderInfo); 42 virtual void RegisterCancelListener(const sptr<IWantReceiver> &receiver); 43 virtual void UnregisterCancelListener(const sptr<IWantReceiver> &receiver); 44 45 virtual int32_t SenderInner(SenderInfo &senderInfo); 46 47 public: 48 std::shared_ptr<PendingWantKey> GetKey(); 49 int32_t GetUid() const; 50 void SetCallerUid(const int32_t callerUid); 51 void SetCanceled(); 52 bool GetCanceled(); 53 std::list<sptr<IWantReceiver>> GetCancelCallbacks(); 54 55 private: 56 void BuildSendWant(SenderInfo &senderInfo, Want &want); 57 int32_t ExecuteOperation( 58 std::shared_ptr<PendingWantManager> pendingWantManager, SenderInfo &senderInfo, Want &want); 59 60 private: 61 std::weak_ptr<PendingWantManager> pendingWantManager_ = {}; 62 int32_t uid_ = 0; 63 int32_t callerUid_ = 0; 64 int32_t callerTokenId_ = 0; 65 sptr<IRemoteObject> callerToken_ = {}; 66 bool canceled_ = false; 67 std::shared_ptr<PendingWantKey> key_ = {}; 68 std::list<sptr<IWantReceiver>> mCancelCallbacks_ = {}; 69 ffrt::mutex lock_ = {}; 70 }; 71 } // namespace AAFwk 72 } // namespace OHOS 73 #endif // OHOS_ABILITY_RUNTIME_PENDING_WANT_RECORD_H 74