• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_SERVICE_ROUTER_FRAMEWORK_SERVICES_INCLUDE_SERVICE_ROUTER_DATA_MGR_H
17 #define OHOS_ABILITY_RUNTIME_SERVICE_ROUTER_FRAMEWORK_SERVICES_INCLUDE_SERVICE_ROUTER_DATA_MGR_H
18 
19 #include <map>
20 #include <mutex>
21 #include <vector>
22 #include <string>
23 #include <singleton.h>
24 
25 #include "bundle_info.h"
26 #include "bundle_mgr_interface.h"
27 #include "inner_service_info.h"
28 #include "service_info.h"
29 #include "uri.h"
30 #include "want.h"
31 
32 namespace OHOS {
33 namespace AbilityRuntime {
34 class ServiceRouterDataMgr : public DelayedRefSingleton<ServiceRouterDataMgr> {
35 public:
36     using Want = OHOS::AAFwk::Want;
37     using Uri = OHOS::Uri;
38 
39     ServiceRouterDataMgr() = default;
40     ~ServiceRouterDataMgr() = default;
41 
42     /**
43      * @brief Load all installed bundle infos.
44      * @return Returns true if this function is successfully called; returns false otherwise.
45      */
46     bool LoadAllBundleInfos();
47 
48     /**
49      * @brief Load bundle info by bundle name.
50      * @param bundleName Indicates the bundle name.
51      * @return Returns true if this function is successfully called; returns false otherwise.
52      */
53     bool LoadBundleInfo(const std::string &bundleName);
54 
55     /**
56      * @brief update BundleInfo.
57      * @param bundleInfo Indicates the bundle info.
58      */
59     void UpdateBundleInfo(const BundleInfo &bundleInfo);
60 
61     /**
62      * @brief Delete bundle info from an exist BundleInfo.
63      * @param bundleName Indicates the bundle name.
64      */
65     void DeleteBundleInfo(const std::string &bundleName);
66 
67     /**
68      * @brief Query the business ability info of list by the given filter.
69      * @param filter Indicates the filter containing the business ability info to be queried.
70      * @param businessAbilityInfos Indicates the obtained business ability info objects
71      * @return Returns ERR_OK on success, others on failure.
72      */
73     int32_t QueryBusinessAbilityInfos(const BusinessAbilityFilter &filter,
74         std::vector<BusinessAbilityInfo> &businessAbilityInfos) const;
75 
76     /**
77      * @brief Query a PurposeInfo of list by the given Want.
78      * @param want Indicates the information of the purposeInfo.
79      * @param purposeName Indicates the purposeName.
80      * @param purposeInfos Indicates the obtained PurposeInfo of list.
81      * @return Returns ERR_OK on success, others on failure.
82      */
83     int32_t QueryPurposeInfos(const Want &want, const std::string purposeName,
84         std::vector<PurposeInfo> &purposeInfos) const;
85 
86 private:
87     BusinessType GetBusinessType(const BusinessAbilityFilter &filter) const;
88 
89 private:
90     mutable std::mutex bundleInfoMutex_;
91     std::map<std::string, InnerServiceInfo> innerServiceInfos_;
92 };
93 } // namespace AbilityRuntime
94 } // namespace OHOS
95 #endif // OHOS_ABILITY_RUNTIME_SERVICE_ROUTER_FRAMEWORK_SERVICES_INCLUDE_SERVICE_ROUTER_DATA_MGR_H
96