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