1eace7efcSopenharmony_ci/*
2eace7efcSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License.
5eace7efcSopenharmony_ci * You may obtain a copy of the License at
6eace7efcSopenharmony_ci *
7eace7efcSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8eace7efcSopenharmony_ci *
9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and
13eace7efcSopenharmony_ci * limitations under the License.
14eace7efcSopenharmony_ci */
15eace7efcSopenharmony_ci
16eace7efcSopenharmony_ci#ifndef OHOS_ABILITY_RUNTIME_DATA_ABILITY_MANAGER_H
17eace7efcSopenharmony_ci#define OHOS_ABILITY_RUNTIME_DATA_ABILITY_MANAGER_H
18eace7efcSopenharmony_ci
19eace7efcSopenharmony_ci#include <map>
20eace7efcSopenharmony_ci#include <memory>
21eace7efcSopenharmony_ci#include <mutex>
22eace7efcSopenharmony_ci#include <string>
23eace7efcSopenharmony_ci#include "cpp/mutex.h"
24eace7efcSopenharmony_ci
25eace7efcSopenharmony_ci#include "ability_record.h"
26eace7efcSopenharmony_ci#include "ability_running_info.h"
27eace7efcSopenharmony_ci#include "data_ability_record.h"
28eace7efcSopenharmony_ci#include "nocopyable.h"
29eace7efcSopenharmony_ci
30eace7efcSopenharmony_cinamespace OHOS {
31eace7efcSopenharmony_cinamespace AAFwk {
32eace7efcSopenharmony_ciclass DataAbilityManager : public NoCopyable {
33eace7efcSopenharmony_cipublic:
34eace7efcSopenharmony_ci    DataAbilityManager();
35eace7efcSopenharmony_ci    virtual ~DataAbilityManager();
36eace7efcSopenharmony_ci
37eace7efcSopenharmony_cipublic:
38eace7efcSopenharmony_ci    sptr<IAbilityScheduler> Acquire(
39eace7efcSopenharmony_ci        const AbilityRequest &abilityRequest, bool tryBind, const sptr<IRemoteObject> &client, bool isNotHap);
40eace7efcSopenharmony_ci    int Release(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &client, bool isNotHap);
41eace7efcSopenharmony_ci    int AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token);
42eace7efcSopenharmony_ci    int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state);
43eace7efcSopenharmony_ci    void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state);
44eace7efcSopenharmony_ci    void OnAppStateChanged(const AppInfo &info);
45eace7efcSopenharmony_ci    void OnAbilityDied(const std::shared_ptr<AbilityRecord> &abilityRecord);
46eace7efcSopenharmony_ci    std::shared_ptr<AbilityRecord> GetAbilityRecordById(int64_t id);
47eace7efcSopenharmony_ci    std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token);
48eace7efcSopenharmony_ci    std::shared_ptr<AbilityRecord> GetAbilityRecordByScheduler(const sptr<IAbilityScheduler> &scheduler);
49eace7efcSopenharmony_ci    void Dump(const char *func, int line);
50eace7efcSopenharmony_ci    void DumpState(std::vector<std::string> &info, const std::string &args = "") const;
51eace7efcSopenharmony_ci    void DumpSysState(std::vector<std::string> &info, bool isClient = false, const std::string &args = "") const;
52eace7efcSopenharmony_ci    bool ContainsDataAbility(const sptr<IAbilityScheduler> &scheduler);
53eace7efcSopenharmony_ci    void GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info, bool isPerm);
54eace7efcSopenharmony_ci
55eace7efcSopenharmony_ciprivate:
56eace7efcSopenharmony_ci    using DataAbilityRecordPtr = std::shared_ptr<DataAbilityRecord>;
57eace7efcSopenharmony_ci    using DataAbilityRecordPtrMap = std::map<std::string, DataAbilityRecordPtr>;
58eace7efcSopenharmony_ci
59eace7efcSopenharmony_ciprivate:
60eace7efcSopenharmony_ci    DataAbilityRecordPtr LoadLocked(const std::string &name, const AbilityRequest &req);
61eace7efcSopenharmony_ci    void DumpLocked(const char *func, int line);
62eace7efcSopenharmony_ci    void RestartDataAbility(const std::shared_ptr<AbilityRecord> &abilityRecord);
63eace7efcSopenharmony_ci    void ReportDataAbilityAcquired(const sptr<IRemoteObject> &client, bool isNotHap,
64eace7efcSopenharmony_ci        std::shared_ptr<DataAbilityRecord> &record);
65eace7efcSopenharmony_ci    void ReportDataAbilityReleased(const sptr<IRemoteObject> &client, bool isNotHap,
66eace7efcSopenharmony_ci        std::shared_ptr<DataAbilityRecord> &record);
67eace7efcSopenharmony_ci    void DumpClientInfo(std::vector<std::string> &info, bool isClient,
68eace7efcSopenharmony_ci        std::shared_ptr<DataAbilityRecord> dataAbilityRecord) const;
69eace7efcSopenharmony_ciprivate:
70eace7efcSopenharmony_ci    mutable ffrt::mutex mutex_;
71eace7efcSopenharmony_ci    DataAbilityRecordPtrMap dataAbilityRecordsLoaded_;
72eace7efcSopenharmony_ci    DataAbilityRecordPtrMap dataAbilityRecordsLoading_;
73eace7efcSopenharmony_ci};
74eace7efcSopenharmony_ci}  // namespace AAFwk
75eace7efcSopenharmony_ci}  // namespace OHOS
76eace7efcSopenharmony_ci
77eace7efcSopenharmony_ci#endif  // OHOS_ABILITY_RUNTIME_DATA_ABILITY_MANAGER_H
78