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_DATA_ABILITY_RECORD_H 17 #define OHOS_ABILITY_RUNTIME_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 : public std::enable_shared_from_this<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 isNotHap); 43 int RemoveClient(const sptr<IRemoteObject> &client, bool isNotHap); 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 isNotHap; 61 int32_t clientPid = 0; 62 }; 63 void OnSchedulerDied(const wptr<IRemoteObject> &remote); 64 int32_t GetDiedCallerPid(const sptr<IRemoteObject> &remote); 65 66 private: 67 std::condition_variable_any loadedCond_ {}; 68 AbilityRequest request_ {}; 69 AbilityRecordPtr ability_ {}; 70 sptr<IAbilityScheduler> scheduler_ {}; 71 std::list<ClientInfo> clients_ {}; 72 sptr<IRemoteObject::DeathRecipient> callerDeathRecipient_; // caller binderDied Recipient 73 }; 74 } // namespace AAFwk 75 } // namespace OHOS 76 #endif // OHOS_ABILITY_RUNTIME_DATA_ABILITY_RECORD_H 77