1 /* 2 * Copyright (c) 2021-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_DATA_ABILITY_MANAGER_H 17 #define OHOS_ABILITY_RUNTIME_DATA_ABILITY_MANAGER_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 #include "cpp/mutex.h" 24 25 #include "ability_record.h" 26 #include "ability_running_info.h" 27 #include "data_ability_record.h" 28 #include "nocopyable.h" 29 30 namespace OHOS { 31 namespace AAFwk { 32 class DataAbilityManager : public NoCopyable { 33 public: 34 DataAbilityManager(); 35 virtual ~DataAbilityManager(); 36 37 public: 38 sptr<IAbilityScheduler> Acquire( 39 const AbilityRequest &abilityRequest, bool tryBind, const sptr<IRemoteObject> &client, bool isNotHap); 40 int Release(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &client, bool isNotHap); 41 int AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token); 42 int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state); 43 void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state); 44 void OnAppStateChanged(const AppInfo &info); 45 void OnAbilityDied(const std::shared_ptr<AbilityRecord> &abilityRecord); 46 std::shared_ptr<AbilityRecord> GetAbilityRecordById(int64_t id); 47 std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token); 48 std::shared_ptr<AbilityRecord> GetAbilityRecordByScheduler(const sptr<IAbilityScheduler> &scheduler); 49 void Dump(const char *func, int line); 50 void DumpState(std::vector<std::string> &info, const std::string &args = "") const; 51 void DumpSysState(std::vector<std::string> &info, bool isClient = false, const std::string &args = "") const; 52 bool ContainsDataAbility(const sptr<IAbilityScheduler> &scheduler); 53 void GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info, bool isPerm); 54 55 private: 56 using DataAbilityRecordPtr = std::shared_ptr<DataAbilityRecord>; 57 using DataAbilityRecordPtrMap = std::map<std::string, DataAbilityRecordPtr>; 58 59 private: 60 DataAbilityRecordPtr LoadLocked(const std::string &name, const AbilityRequest &req); 61 void DumpLocked(const char *func, int line); 62 void RestartDataAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 63 void ReportDataAbilityAcquired(const sptr<IRemoteObject> &client, bool isNotHap, 64 std::shared_ptr<DataAbilityRecord> &record); 65 void ReportDataAbilityReleased(const sptr<IRemoteObject> &client, bool isNotHap, 66 std::shared_ptr<DataAbilityRecord> &record); 67 void DumpClientInfo(std::vector<std::string> &info, bool isClient, 68 std::shared_ptr<DataAbilityRecord> dataAbilityRecord) const; 69 private: 70 mutable ffrt::mutex mutex_; 71 DataAbilityRecordPtrMap dataAbilityRecordsLoaded_; 72 DataAbilityRecordPtrMap dataAbilityRecordsLoading_; 73 }; 74 } // namespace AAFwk 75 } // namespace OHOS 76 77 #endif // OHOS_ABILITY_RUNTIME_DATA_ABILITY_MANAGER_H 78