• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_INFO_MGR_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_INFO_MGR_H
18 
19 #include <shared_mutex>
20 #include <singleton.h>
21 #include <unordered_map>
22 
23 #include "appexecfwk_errors.h"
24 #include "bundle_info.h"
25 #include "form_info.h"
26 #include "form_info_storage.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 class FormInfoHelper {
31 public:
32     static ErrCode LoadFormConfigInfoByBundleName(const std::string &bundleName, std::vector<FormInfo> &formInfos,
33         int32_t userId);
34 
35 private:
36     static ErrCode LoadAbilityFormConfigInfo(const BundleInfo &bundleInfo, std::vector<FormInfo> &formInfos);
37 
38     static ErrCode LoadStageFormConfigInfo(const BundleInfo &bundleInfo, std::vector<FormInfo> &formInfos);
39 };
40 
41 class BundleFormInfo {
42 public:
43     explicit BundleFormInfo(std::string bundleName);
44 
45     ErrCode InitFromJson(const std::string &formInfoStoragesJson);
46 
47     ErrCode Update(int32_t userId);
48 
49     ErrCode Remove(int32_t userId);
50 
51     bool Empty();
52 
53     ErrCode GetAllFormsInfo(std::vector<FormInfo> &formInfos);
54 
55     ErrCode GetFormsInfoByModule(const std::string &moduleName, std::vector<FormInfo> &formInfos);
56 
57 private:
58     std::string bundleName_ {};
59     mutable std::shared_timed_mutex formInfosMutex_ {};
60     std::vector<AAFwk::FormInfoStorage> formInfoStorages_ {};
61 };
62 
63 class FormInfoMgr final : public DelayedRefSingleton<FormInfoMgr> {
64 DECLARE_DELAYED_REF_SINGLETON(FormInfoMgr)
65 
66 public:
67     DISALLOW_COPY_AND_MOVE(FormInfoMgr);
68 
69     ErrCode Start();
70 
71     ErrCode Update(const std::string &bundleNamef, int32_t userId);
72 
73     ErrCode Remove(const std::string &bundleName, int32_t userId);
74 
75     ErrCode GetAllFormsInfo(std::vector<FormInfo> &formInfos);
76 
77     ErrCode GetFormsInfoByBundle(const std::string &bundleName, std::vector<FormInfo> &formInfos);
78 
79     ErrCode GetFormsInfoByModule(const std::string &bundleName, const std::string &moduleName,
80                                  std::vector<FormInfo> &formInfos);
81 
82 private:
83     std::shared_ptr<BundleFormInfo> GetOrCreateBundleFromInfo(const std::string &bundleName);
84     bool IsCaller(std::string bundleName);
85     bool CheckBundlePermission();
86 
87     mutable std::shared_timed_mutex bundleFormInfoMapMutex_ {};
88     std::unordered_map<std::string, std::shared_ptr<BundleFormInfo>> bundleFormInfoMap_ {};
89 };
90 }  // namespace AppExecFwk
91 }  // namespace OHOS
92 #endif // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_INFO_MGR_H
93