/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ABILITY_RUNTIME_DATA_ABILITY_MANAGER_H #define OHOS_ABILITY_RUNTIME_DATA_ABILITY_MANAGER_H #include #include #include #include #include "cpp/mutex.h" #include "ability_record.h" #include "ability_running_info.h" #include "data_ability_record.h" #include "nocopyable.h" namespace OHOS { namespace AAFwk { class DataAbilityManager : public NoCopyable { public: DataAbilityManager(); virtual ~DataAbilityManager(); public: sptr Acquire( const AbilityRequest &abilityRequest, bool tryBind, const sptr &client, bool isNotHap); int Release(const sptr &scheduler, const sptr &client, bool isNotHap); int AttachAbilityThread(const sptr &scheduler, const sptr &token); int AbilityTransitionDone(const sptr &token, int state); void OnAbilityRequestDone(const sptr &token, const int32_t state); void OnAppStateChanged(const AppInfo &info); void OnAbilityDied(const std::shared_ptr &abilityRecord); std::shared_ptr GetAbilityRecordById(int64_t id); std::shared_ptr GetAbilityRecordByToken(const sptr &token); std::shared_ptr GetAbilityRecordByScheduler(const sptr &scheduler); void Dump(const char *func, int line); void DumpState(std::vector &info, const std::string &args = "") const; void DumpSysState(std::vector &info, bool isClient = false, const std::string &args = "") const; bool ContainsDataAbility(const sptr &scheduler); void GetAbilityRunningInfos(std::vector &info, bool isPerm); private: using DataAbilityRecordPtr = std::shared_ptr; using DataAbilityRecordPtrMap = std::map; private: DataAbilityRecordPtr LoadLocked(const std::string &name, const AbilityRequest &req); void DumpLocked(const char *func, int line); void RestartDataAbility(const std::shared_ptr &abilityRecord); void ReportDataAbilityAcquired(const sptr &client, bool isNotHap, std::shared_ptr &record); void ReportDataAbilityReleased(const sptr &client, bool isNotHap, std::shared_ptr &record); void DumpClientInfo(std::vector &info, bool isClient, std::shared_ptr dataAbilityRecord) const; private: mutable ffrt::mutex mutex_; DataAbilityRecordPtrMap dataAbilityRecordsLoaded_; DataAbilityRecordPtrMap dataAbilityRecordsLoading_; }; } // namespace AAFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_DATA_ABILITY_MANAGER_H