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 class NAPIAbilityConnection;
177 struct AbilityConnectionCB {
178 napi_env env;
179 napi_ref callback[3] = {nullptr}; // onConnect/onDisconnect/onFailed
180 int resultCode = 0;
181 ElementName elementName;
182 sptr<IRemoteObject> connection;
183 };
184 struct ConnectAbilityCB {
185 CBBase cbBase;
186 Want want;
187 sptr<NAPIAbilityConnection> abilityConnection;
188 AbilityConnectionCB abilityConnectionCB;
189 int64_t id;
190 bool result;
191 int errCode = 0;
192 };
193
194 struct DAHelperNotifyChangeCB {
195 CBBase cbBase;
196 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
197 std::string uri;
198 int execResult;
199 };
200
201 class NAPIDataAbilityObserver;
202 struct DAHelperOnOffCB {
203 CBBase cbBase;
204 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
205 sptr<NAPIDataAbilityObserver> observer;
206 std::string uri;
207 int result = 0;
208 std::vector<DAHelperOnOffCB *> NotifyList;
209 std::vector<DAHelperOnOffCB *> DestroyList;
210 };
211
212 struct ShowOnLockScreenCB {
213 CBBase cbBase;
214 bool isShow;
215 };
216
217 struct SetWakeUpScreenCB {
218 CBBase cbBase;
219 bool wakeUp;
220 };
221
NapiValueToStringUtf8(napi_env env,napi_value value)222 static inline std::string NapiValueToStringUtf8(napi_env env, napi_value value)
223 {
224 std::string result = "";
225 return UnwrapStringFromJS(env, value, result);
226 }
227
NapiValueToArrayStringUtf8(napi_env env,napi_value param,std::vector<std::string> & result)228 static inline bool NapiValueToArrayStringUtf8(napi_env env, napi_value param, std::vector<std::string> &result)
229 {
230 return UnwrapArrayStringFromJS(env, param, result);
231 }
232
233 struct DAHelperGetTypeCB {
234 CBBase cbBase;
235 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
236 std::string uri;
237 std::string result = "";
238 int execResult;
239 };
240
241 struct DAHelperGetFileTypesCB {
242 CBBase cbBase;
243 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
244 std::string uri;
245 std::string mimeTypeFilter;
246 std::vector<std::string> result;
247 int execResult;
248 };
249
250 struct DAHelperNormalizeUriCB {
251 CBBase cbBase;
252 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
253 std::string uri;
254 std::string result = "";
255 int execResult;
256 };
257 struct DAHelperDenormalizeUriCB {
258 CBBase cbBase;
259 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
260 std::string uri;
261 std::string result = "";
262 int execResult;
263 };
264
265 struct DAHelperDeleteCB {
266 CBBase cbBase;
267 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
268 std::string uri;
269 NativeRdb::DataAbilityPredicates predicates;
270 int result = 0;
271 int execResult;
272 };
273
274 struct DAHelperQueryCB {
275 CBBase cbBase;
276 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
277 std::string uri;
278 std::vector<std::string> columns;
279 NativeRdb::DataAbilityPredicates predicates;
280 std::shared_ptr<NativeRdb::AbsSharedResultSet> result;
281 int execResult;
282 };
283
284 struct DAHelperUpdateCB {
285 CBBase cbBase;
286 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
287 std::string uri;
288 NativeRdb::ValuesBucket valueBucket;
289 NativeRdb::DataAbilityPredicates predicates;
290 int result = 0;
291 int execResult;
292 };
293
294 struct DAHelperCallCB {
295 CBBase cbBase;
296 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
297 std::string uri;
298 std::string method;
299 std::string arg;
300 AppExecFwk::PacMap pacMap;
301 std::shared_ptr<AppExecFwk::PacMap> result;
302 int execResult;
303 };
304
305 struct DAHelperErrorCB {
306 CBBase cbBase;
307 int execResult;
308 };
309 struct DAHelperBatchInsertCB {
310 CBBase cbBase;
311 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
312 std::string uri;
313 std::vector<NativeRdb::ValuesBucket> values;
314 int result = 0;
315 int execResult;
316 };
317 struct DAHelperOpenFileCB {
318 CBBase cbBase;
319 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
320 std::string uri;
321 std::string mode;
322 int result = 0;
323 int execResult;
324 };
325
326 struct DAHelperExecuteBatchCB {
327 CBBase cbBase;
328 std::string uri;
329 std::vector<std::shared_ptr<DataAbilityOperation>> operations;
330 std::shared_ptr<DataAbilityHelper> dataAbilityHelper;
331 std::vector<std::shared_ptr<DataAbilityResult>> result;
332 };
333 } // namespace AppExecFwk
334 } // namespace OHOS
335 #endif /* OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_COMMON_H */
336