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 Delete bundle info from an exist BundleInfo.
57      * @param bundleName Indicates the bundle name.
58      */
59     void DeleteBundleInfo(const std::string &bundleName);
60 
61     /**
62      * @brief Query the business ability info of list by the given filter.
63      * @param filter Indicates the filter containing the business ability info to be queried.
64      * @param businessAbilityInfos Indicates the obtained business ability info objects
65      * @return Returns ERR_OK on success, others on failure.
66      */
67     int32_t QueryBusinessAbilityInfos(const BusinessAbilityFilter &filter,
68         std::vector<BusinessAbilityInfo> &businessAbilityInfos) const;
69 
70     /**
71      * @brief Query a PurposeInfo of list by the given Want.
72      * @param want Indicates the information of the purposeInfo.
73      * @param purposeName Indicates the purposeName.
74      * @param purposeInfos Indicates the obtained PurposeInfo of list.
75      * @return Returns ERR_OK on success, others on failure.
76      */
77     int32_t QueryPurposeInfos(const Want &want, const std::string purposeName,
78         std::vector<PurposeInfo> &purposeInfos) const;
79 
80 private:
81     /**
82      * @brief update BundleInfo.
83      * @param bundleInfo Indicates the bundle info.
84      */
85     void UpdateBundleInfoLocked(const BundleInfo &bundleInfo);
86 
87     BusinessType GetBusinessType(const BusinessAbilityFilter &filter) const;
88 
89     void ClearAllBundleInfos();
90 
91 private:
92     mutable std::mutex bundleInfoMutex_;
93     std::map<std::string, InnerServiceInfo> innerServiceInfos_;
94 };
95 } // namespace AbilityRuntime
96 } // namespace OHOS
97 #endif // OHOS_ABILITY_RUNTIME_SERVICE_ROUTER_FRAMEWORK_SERVICES_INCLUDE_SERVICE_ROUTER_DATA_MGR_H
98