• 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 OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_COMMON_H
17 #define OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_COMMON_H
18 #include "ability.h"
19 #include "ability_info.h"
20 #include "abs_shared_result_set.h"
21 #include "application_info.h"
22 #include "data_ability_predicates.h"
23 #include "hap_module_info.h"
24 #include "napi/native_api.h"
25 #include "napi/native_common.h"
26 #include "napi/native_node_api.h"
27 #include "napi_common.h"
28 #include "napi_common_util.h"
29 #include "pac_map.h"
30 #include "values_bucket.h"
31 #include "want.h"
32 
33 using Want = OHOS::AAFwk::Want;
34 using Ability = OHOS::AppExecFwk::Ability;
35 using AbilityStartSetting = OHOS::AppExecFwk::AbilityStartSetting;
36 
37 namespace OHOS {
38 namespace AppExecFwk {
39 class FeatureAbility;
40 
41 struct CallAbilityParam {
42     Want want;
43     int requestCode = 0;
44     bool forResultOption = false;
45     std::shared_ptr<AbilityStartSetting> setting = nullptr;
46 };
47 
48 struct OnAbilityCallback {
49     int requestCode = 0;
50     int resultCode = 0;
51     Want resultData;
52     CallbackInfo cb;
53 };
54 
55 struct ContinueAbilityOptionsInfo {
56     bool reversible = false;
57     std::string deviceId;
58 };
59 
60 struct AsyncCallbackInfo {
61     CallbackInfo cbInfo;
62     napi_async_work asyncWork = nullptr;
63     napi_deferred deferred = nullptr;
64     Ability *ability = nullptr;
65     AbilityRuntime::WantAgent::WantAgent *wantAgent = nullptr;
66     CallAbilityParam param;
67     CallbackInfo aceCallback;
68     bool native_result;
69     AbilityType abilityType = AbilityType::UNKNOWN;
70     int errCode = 0;
71     ContinueAbilityOptionsInfo optionInfo;
72 #ifdef SUPPORT_GRAPHICS
73     sptr<OHOS::Rosen::Window> window;
74 #endif
75 };
76 
77 struct CBBase {
78     CallbackInfo cbInfo;
79     napi_async_work asyncWork;
80     napi_deferred deferred;
81     Ability *ability = nullptr;
82     AbilityType abilityType = AbilityType::UNKNOWN;
83     int errCode = 0;
84 };
85 
86 struct AppInfoCB {
87     CBBase cbBase;
88     ApplicationInfo appInfo;
89 };
90 
91 struct AppTypeCB {
92     CBBase cbBase;
93     std::string name;
94 };
95 struct AbilityInfoCB {
96     CBBase cbBase;
97     AbilityInfo abilityInfo;
98 };
99 
100 struct AbilityNameCB {
101     CBBase cbBase;
102     std::string name;
103 };
104 
105 struct ProcessInfoCB {
106     CBBase cbBase;
107     pid_t pid = 0;
108     std::string processName;
109 };
110 
111 struct ProcessNameCB {
112     CBBase cbBase;
113     std::string processName;
114 };
115 
116 struct CallingBundleCB {
117     CBBase cbBase;
118     std::string callingBundleName;
119 };
120 
121 struct GetOrCreateLocalDirCB {
122     CBBase cbBase;
123     std::string rootDir;
124 };
125 
126 struct DatabaseDirCB {
127     CBBase cbBase;
128     std::string dataBaseDir;
129 };
130 
131 struct PreferencesDirCB {
132     CBBase cbBase;
133     std::string preferencesDir;
134 };
135 
136 struct ElementNameCB {
137     CBBase cbBase;
138     std::string deviceId;
139     std::string bundleName;
140     std::string abilityName;
141     std::string uri;
142     std::string shortName;
143 };
144 
145 struct HapModuleInfoCB {
146     CBBase cbBase;
147     HapModuleInfo hapModuleInfo;
148 };
149 
150 struct AppVersionInfo {
151     std::string appName;
152     std::string versionName;
153     int32_t versionCode = 0;
154 };
155 
156 struct AppVersionInfoCB {
157     CBBase cbBase;
158     AppVersionInfo appVersionInfo;
159 };
160 
161 struct DataAbilityHelperCB {
162     CBBase cbBase;
163     napi_ref uri = nullptr;
164     napi_value result = nullptr;
165 };
166 
167 struct DAHelperInsertCB {
168     CBBase cbBase;
169     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
170     std::string uri;
171     NativeRdb::ValuesBucket valueBucket;
172     int result = 0;
173     int execResult;
174 };
175 
176 struct ConnectionCallback;
177 class NAPIAbilityConnection;
178 struct AbilityConnectionCB {
179     napi_env env;
180     napi_ref callback[3] = {nullptr};  // onConnect/onDisconnect/onFailed
181     int resultCode = 0;
182     ElementName elementName;
183     sptr<IRemoteObject> connection;
184 };
185 struct ConnectAbilityCB {
186     CBBase cbBase;
187     Want want;
188     sptr<NAPIAbilityConnection> abilityConnection;
189     AbilityConnectionCB abilityConnectionCB;
190     int64_t id;
191     bool result;
192     int errCode = 0;
193 };
194 
195 struct DAHelperNotifyChangeCB {
196     CBBase cbBase;
197     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
198     std::string uri;
199     int execResult;
200 };
201 
202 class NAPIDataAbilityObserver;
203 struct DAHelperOnOffCB {
204     CBBase cbBase;
205     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
206     sptr<NAPIDataAbilityObserver> observer;
207     std::string uri;
208     int result = 0;
209     std::vector<DAHelperOnOffCB *> NotifyList;
210     std::vector<DAHelperOnOffCB *> DestroyList;
211 };
212 
213 struct ShowOnLockScreenCB {
214     CBBase cbBase;
215     bool isShow;
216 };
217 
218 struct SetWakeUpScreenCB {
219     CBBase cbBase;
220     bool wakeUp;
221 };
222 
NapiValueToStringUtf8(napi_env env,napi_value value)223 static inline std::string NapiValueToStringUtf8(napi_env env, napi_value value)
224 {
225     std::string result = "";
226     return UnwrapStringFromJS(env, value, result);
227 }
228 
NapiValueToArrayStringUtf8(napi_env env,napi_value param,std::vector<std::string> & result)229 static inline bool NapiValueToArrayStringUtf8(napi_env env, napi_value param, std::vector<std::string> &result)
230 {
231     return UnwrapArrayStringFromJS(env, param, result);
232 }
233 
234 struct DAHelperGetTypeCB {
235     CBBase cbBase;
236     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
237     std::string uri;
238     std::string result = "";
239     int execResult;
240 };
241 
242 struct DAHelperGetFileTypesCB {
243     CBBase cbBase;
244     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
245     std::string uri;
246     std::string mimeTypeFilter;
247     std::vector<std::string> result;
248     int execResult;
249 };
250 
251 struct DAHelperNormalizeUriCB {
252     CBBase cbBase;
253     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
254     std::string uri;
255     std::string result = "";
256     int execResult;
257 };
258 struct DAHelperDenormalizeUriCB {
259     CBBase cbBase;
260     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
261     std::string uri;
262     std::string result = "";
263     int execResult;
264 };
265 
266 struct DAHelperDeleteCB {
267     CBBase cbBase;
268     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
269     std::string uri;
270     NativeRdb::DataAbilityPredicates predicates;
271     int result = 0;
272     int execResult;
273 };
274 
275 struct DAHelperQueryCB {
276     CBBase cbBase;
277     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
278     std::string uri;
279     std::vector<std::string> columns;
280     NativeRdb::DataAbilityPredicates predicates;
281     std::shared_ptr<NativeRdb::AbsSharedResultSet> result;
282     int execResult;
283 };
284 
285 struct DAHelperUpdateCB {
286     CBBase cbBase;
287     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
288     std::string uri;
289     NativeRdb::ValuesBucket valueBucket;
290     NativeRdb::DataAbilityPredicates predicates;
291     int result = 0;
292     int execResult;
293 };
294 
295 struct DAHelperCallCB {
296     CBBase cbBase;
297     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
298     std::string uri;
299     std::string method;
300     std::string arg;
301     AppExecFwk::PacMap pacMap;
302     std::shared_ptr<AppExecFwk::PacMap> result;
303     int execResult;
304 };
305 
306 struct DAHelperErrorCB {
307     CBBase cbBase;
308     int execResult;
309 };
310 struct DAHelperBatchInsertCB {
311     CBBase cbBase;
312     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
313     std::string uri;
314     std::vector<NativeRdb::ValuesBucket> values;
315     int result = 0;
316     int execResult;
317 };
318 struct DAHelperOpenFileCB {
319     CBBase cbBase;
320     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
321     std::string uri;
322     std::string mode;
323     int result = 0;
324     int execResult;
325 };
326 
327 struct DAHelperExecuteBatchCB {
328     CBBase cbBase;
329     std::string uri;
330     std::vector<std::shared_ptr<DataAbilityOperation>> operations;
331     std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
332     std::vector<std::shared_ptr<DataAbilityResult>> result;
333 };
334 }  // namespace AppExecFwk
335 }  // namespace OHOS
336 #endif /* OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_COMMON_H */
337