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