• 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 APP_DOMAIN_VERIFY_MGR_CLIENT_H
17 #define APP_DOMAIN_VERIFY_MGR_CLIENT_H
18 
19 #include <memory>
20 #include "singleton.h"
21 
22 #include "app_domain_verify_mgr_service_proxy.h"
23 #include "errors.h"
24 #include "i_app_domain_verify_mgr_service.h"
25 #include "skill_uri.h"
26 #include "domain_verify_status.h"
27 #include "want.h"
28 
29 namespace OHOS {
30 namespace AppDomainVerify {
31 
32 class AppDomainVerifyMgrClient : public DelayedSingleton<AppDomainVerifyMgrClient> {
33     DECLARE_DELAYED_SINGLETON(AppDomainVerifyMgrClient);
34 
35 public:
36     DISALLOW_COPY_AND_MOVE(AppDomainVerifyMgrClient);
37     /**
38      * VerifyDomain
39      * @descrition verify applink in skillUris.
40      * @param appIdentifier appIdentifier.
41      * @param bundleName bundleName.
42      * @param fingerprint fingerprint.
43      * @param skillUris skillUris.
44      */
45     void VerifyDomain(const std::string& appIdentifier, const std::string& bundleName, const std::string& fingerprint,
46         const std::vector<SkillUri>& skillUris);
47 
48     /**
49      * ClearDomainVerifyStatus
50      * @descrition delete domain name verification result.
51      * @param appIdentifier appIdentifier.
52      * @param bundleName bundleName.
53      * @return bool clear result.
54      */
55     bool ClearDomainVerifyStatus(const std::string& appIdentifier, const std::string& bundleName);
56 
57     /**
58      * FilterAbilities
59      * @descrition Perform a further filtering on the ability list based on the domain verification.
60      * @param want want to start ability.
61      * @param originAbilityInfos AbilityInfo vector input.
62      * @param filtedAbilityInfos AbilityInfo vector output.
63      * @return bool filterAbilities success or not.
64      */
65     bool FilterAbilities(const OHOS::AAFwk::Want& want,
66         const std::vector<OHOS::AppExecFwk::AbilityInfo>& originAbilityInfos,
67         std::vector<OHOS::AppExecFwk::AbilityInfo>& filtedAbilityInfos);
68 
69     /**
70      * QueryDomainVerifyStatus
71      * @descrition query domain verify status.
72      * @param bundleName bundleName.
73      * @param domainVerificationState domainVerificationState.
74      * @return bool query success or not.
75      */
76     bool QueryDomainVerifyStatus(const std::string& bundleName, DomainVerifyStatus& domainVerificationState);
77 
78     /**
79      * QueryAllDomainVerifyStatus
80      * @descrition QueryAllDomainVerifyStatus.
81      * @param bundleVerifyStatusInfo bundleVerifyStatusInfo.
82      * @return bool query success or not.
83      */
84     bool QueryAllDomainVerifyStatus(BundleVerifyStatusInfo& bundleVerifyStatusInfo);
85 
86     /**
87      * SaveDomainVerifyStatus
88      * @descrition SaveDomainVerifyStatus.
89      * @param bundleName bundleName.
90      * @param verifyResultInfo verifyResultInfo.
91      * @return bool query success or not.
92      */
93     bool SaveDomainVerifyStatus(const std::string& bundleName, const VerifyResultInfo& verifyResultInfo);
94 
95     /**
96      * IsAtomicServiceUrl
97      * @descrition check input url is atomic service or not.
98      * @param url input url to check.
99      * @return bool is atomic service or not.
100      */
101     bool IsAtomicServiceUrl(const std::string& url);
102 
103     /**
104      * UpdateWhiteListUrl
105      * @descrition update whitelist urls.
106      * @param urls input whitelist urls.
107      */
108     void UpdateWhiteListUrls(const std::vector<std::string>& urls);
109     /**
110      * ConvertToExplicitWant
111      * @descrition convert implicit want to explicit want.
112      * @param implicitWant implicit want to convert.
113      * @param callback callback when convert finish.
114      */
115     void ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr<IConvertCallback>& callback);
116 
117     /**
118      * QueryAssociatedDomains
119      * @descrition query domains associated to bundle name.
120      * @param bundleName bundleName as key.
121      * @param domains domains as result.
122      * @return int result of query.
123      */
124     int QueryAssociatedDomains(const std::string& bundleName, std::vector<std::string>& domains);
125     /**
126      * QueryAssociatedBundleNames
127      * @descrition query bundleNames associated to domain.
128      * @param bundleName domain as key.
129      * @param bundleNames domains as result.
130      * @return int result of query.
131      */
132     int QueryAssociatedBundleNames(const std::string& domain, std::vector<std::string>& bundleNames);
133 
134     /**
135     * QueryAppDetailsWant
136     * @descrition query app details as want.
137     * @param link uri.
138     * @param want appdetails want.
139     * @return int result of query.
140     */
141     int QueryAppDetailsWant(const std::string& link, AAFwk::Want& want);
142 
143     /**
144      * GetDeferredLink
145      * @descrition get deferred link for app.
146      * @param link link to get.
147      * @return result status.
148      */
149     int GetDeferredLink(std::string& link);
150 
151     /**
152      * OnRemoteSaDied
153      * @descrition
154      * @param object systemAbility proxy object
155      * @return void.
156      */
157     void OnRemoteSaDied(const wptr<IRemoteObject>& object);
158 
159 private:
160     bool IsServiceAvailable();
161     void ConnectService();
162     bool IsValidUrl(OHOS::Uri& uri);
163     bool IsValidPath(const std::string& url);
164 
165 private:
166     class StaticDestoryMonitor {
167     public:
StaticDestoryMonitor()168         StaticDestoryMonitor() : destoryed_(false)
169         {
170         }
~StaticDestoryMonitor()171         ~StaticDestoryMonitor()
172         {
173             destoryed_ = true;
174         }
175 
IsDestoryed()176         bool IsDestoryed() const
177         {
178             return destoryed_;
179         }
180 
181     private:
182         bool destoryed_;
183     };
184 
185 private:
186     static std::mutex proxyLock_;
187     static sptr<IAppDomainVerifyMgrService> appDomainVerifyMgrServiceProxy_;
188     static StaticDestoryMonitor staticDestoryMonitor_;
189     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
190 };
191 
192 class AppDomainVerifyMgrSaDeathRecipient : public IRemoteObject::DeathRecipient {
193 public:
194     explicit AppDomainVerifyMgrSaDeathRecipient();
195     virtual ~AppDomainVerifyMgrSaDeathRecipient();
196     void OnRemoteDied(const wptr<IRemoteObject>& object) override;
197 
198 private:
199     DISALLOW_COPY_AND_MOVE(AppDomainVerifyMgrSaDeathRecipient);
200 };
201 }  // namespace AppDomainVerify
202 }  // namespace OHOS
203 
204 #endif