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_MANAGER_H 17 #define OHOS_AAFWK_DATA_ABILITY_MANAGER_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 24 #include "ability_record.h" 25 #include "data_ability_record.h" 26 #include "nocopyable.h" 27 28 namespace OHOS { 29 namespace AAFwk { 30 class DataAbilityManager : public NoCopyable { 31 public: 32 DataAbilityManager(); 33 virtual ~DataAbilityManager(); 34 35 public: 36 sptr<IAbilityScheduler> Acquire( 37 const AbilityRequest &abilityRequest, bool tryBind, const sptr<IRemoteObject> &client, bool isSystem); 38 int Release(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &client, bool isSystem); 39 int AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token); 40 int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state); 41 void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state); 42 void OnAppStateChanged(const AppInfo &info); 43 void OnAbilityDied(const std::shared_ptr<AbilityRecord> &abilityRecord); 44 std::shared_ptr<AbilityRecord> GetAbilityRecordById(int64_t id); 45 std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token); 46 std::shared_ptr<AbilityRecord> GetAbilityRecordByScheduler(const sptr<IAbilityScheduler> &scheduler); 47 void Dump(const char *func, int line); 48 void DumpState(std::vector<std::string> &info, const std::string &args = "") const; 49 50 private: 51 using DataAbilityRecordPtr = std::shared_ptr<DataAbilityRecord>; 52 using DataAbilityRecordPtrMap = std::map<std::string, DataAbilityRecordPtr>; 53 54 private: 55 DataAbilityRecordPtr LoadLocked(const std::string &name, const AbilityRequest &req); 56 void DumpLocked(const char *func, int line); 57 58 private: 59 std::mutex mutex_; 60 DataAbilityRecordPtrMap dataAbilityRecordsLoaded_; 61 DataAbilityRecordPtrMap dataAbilityRecordsLoading_; 62 }; 63 } // namespace AAFwk 64 } // namespace OHOS 65 66 #endif // OHOS_AAFWK_DATA_ABILITY_MANAGER_H 67