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_AAFWK_DATA_ABILITY_RECORD_H 17 #define OHOS_AAFWK_DATA_ABILITY_RECORD_H 18 19 #include <list> 20 #include <string> 21 #include <memory> 22 #include <mutex> 23 #include <condition_variable> 24 #include <chrono> 25 26 #include "ability_record.h" 27 #include "data_ability_caller_recipient.h" 28 29 namespace OHOS { 30 namespace AAFwk { 31 class DataAbilityRecord { 32 public: 33 explicit DataAbilityRecord(const AbilityRequest &req); 34 virtual ~DataAbilityRecord(); 35 36 public: 37 int StartLoading(); 38 int WaitForLoaded(std::mutex &mutex, const std::chrono::system_clock::duration &timeout); 39 sptr<IAbilityScheduler> GetScheduler(); 40 int Attach(const sptr<IAbilityScheduler> &scheduler); 41 int OnTransitionDone(int state); 42 int AddClient(const sptr<IRemoteObject> &client, bool tryBind, bool isSystem); 43 int RemoveClient(const sptr<IRemoteObject> &client, bool isSystem); 44 int RemoveClients(const std::shared_ptr<AbilityRecord> &client = nullptr); 45 size_t GetClientCount(const sptr<IRemoteObject> &client = nullptr) const; 46 int KillBoundClientProcesses(); 47 const AbilityRequest &GetRequest() const; 48 std::shared_ptr<AbilityRecord> GetAbilityRecord(); 49 sptr<IRemoteObject> GetToken(); 50 void Dump() const; 51 void Dump(std::vector<std::string> &info) const; 52 53 private: 54 using IRemoteObjectPtr = sptr<IRemoteObject>; 55 using AbilityRecordPtr = std::shared_ptr<AbilityRecord>; 56 57 struct ClientInfo { 58 IRemoteObjectPtr client; 59 bool tryBind; 60 bool isSystem; 61 }; 62 void OnSchedulerDied(const wptr<IRemoteObject> &remote); 63 64 private: 65 std::condition_variable_any loadedCond_{}; 66 AbilityRequest request_{}; 67 AbilityRecordPtr ability_{}; 68 sptr<IAbilityScheduler> scheduler_{}; 69 std::list<ClientInfo> clients_{}; 70 sptr<IRemoteObject::DeathRecipient> callerDeathRecipient_; // caller binderDied Recipient 71 }; 72 } // namespace AAFwk 73 } // namespace OHOS 74 #endif // OHOS_AAFWK_DATA_ABILITY_RECORD_H 75