1 /* 2 * Copyright (c) 2021-2022 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_H 17 #define OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_H 18 #include "../inner/napi_common/feature_ability_common.h" 19 using Want = OHOS::AAFwk::Want; 20 21 namespace OHOS { 22 namespace AppExecFwk { 23 using namespace OHOS::AbilityRuntime; 24 /** 25 * @brief FeatureAbility NAPI module registration. 26 * 27 * @param env The environment that the Node-API call is invoked under. 28 * @param exports An empty object via the exports parameter as a convenience. 29 * 30 * @return The return value from Init is treated as the exports object for the module. 31 */ 32 napi_value FeatureAbilityInit(napi_env env, napi_value exports); 33 34 EXTERN_C_START 35 /** 36 * @brief The interface of onAbilityResult provided for ACE to call back to JS. 37 * 38 * @param requestCode Indicates the request code returned after the ability is started. 39 * @param resultCode Indicates the result code returned after the ability is started. 40 * @param resultData Indicates the data returned after the ability is started. 41 * @param callbackInfo The environment and call back info that the Node-API call is invoked under. 42 * 43 * @return The return value from NAPI C++ to JS for the module. 44 */ 45 void CallOnAbilityResult(int requestCode, int resultCode, const Want &resultData, CallbackInfo callbackInfo); 46 EXTERN_C_END 47 48 /** 49 * @brief FeatureAbility NAPI method : startAbility. 50 * 51 * @param env The environment that the Node-API call is invoked under. 52 * @param info The callback info passed into the callback function. 53 * 54 * @return The return value from NAPI C++ to JS for the module. 55 */ 56 napi_value NAPI_StartAbility(napi_env env, napi_callback_info info); 57 58 /** 59 * @brief FeatureAbility NAPI method : startAbilityForResult. 60 * 61 * @param env The environment that the Node-API call is invoked under. 62 * @param info The callback info passed into the callback function. 63 * 64 * @return The return value from NAPI C++ to JS for the module. 65 */ 66 napi_value NAPI_StartAbilityForResult(napi_env env, napi_callback_info info); 67 68 /** 69 * @brief FeatureAbility NAPI method : setResult. 70 * 71 * @param env The environment that the Node-API call is invoked under. 72 * @param info The callback info passed into the callback function. 73 * 74 * @return The return value from NAPI C++ to JS for the module. 75 */ 76 napi_value NAPI_SetResult(napi_env env, napi_callback_info info); 77 78 /** 79 * @brief FeatureAbility NAPI method : terminateAbility. 80 * 81 * @param env The environment that the Node-API call is invoked under. 82 * @param info The callback info passed into the callback function. 83 * 84 * @return The return value from NAPI C++ to JS for the module. 85 */ 86 napi_value NAPI_TerminateAbility(napi_env env, napi_callback_info info); 87 88 /** 89 * @brief Checks whether the main window of this ability has window focus. 90 * 91 * @param env The environment that the Node-API call is invoked under. 92 * @param info The callback info passed into the callback function. 93 * 94 * @return The return value from NAPI C++ to JS for the module. 95 */ 96 napi_value NAPI_HasWindowFocus(napi_env env, napi_callback_info info); 97 98 /** 99 * @brief Get context. 100 * 101 * @param env The environment that the Node-API call is invoked under. 102 * @param info The callback info passed into the callback function. 103 * 104 * @return The return value from NAPI C++ to JS for the module. 105 */ 106 napi_value NAPI_GetContext(napi_env env, napi_callback_info info); 107 108 /** 109 * @brief Get window. 110 * 111 * @param env The environment that the Node-API call is invoked under. 112 * @param info The callback info passed into the callback function. 113 * 114 * @return The return value from NAPI C++ to JS for the module. 115 */ 116 napi_value NAPI_GetWindow(napi_env env, napi_callback_info info); 117 118 /** 119 * @brief Get want. 120 * 121 * @param env The environment that the Node-API call is invoked under. 122 * @param info The callback info passed into the callback function. 123 * 124 * @return The return value from NAPI C++ to JS for the module. 125 */ 126 napi_value NAPI_GetWant(napi_env env, napi_callback_info info); 127 128 /** 129 * @brief Get want(sync). 130 * 131 * @param env The environment that the Node-API call is invoked under. 132 * @param info The callback info passed into the callback function. 133 * 134 * @return The return value from NAPI C++ to JS for the module. 135 */ 136 napi_value NAPI_GetWantSync(napi_env env, napi_callback_info info); 137 138 /** 139 * @brief Obtains the type of this application. 140 * 141 * @param env The environment that the Node-API call is invoked under. 142 * @param info The callback info passed into the callback function. 143 * 144 * @return The return value from NAPI C++ to JS for the module. 145 */ 146 napi_value NAPI_GetAppType(napi_env env, napi_callback_info info); 147 148 /** 149 * @brief Obtains the class name in this ability name, without the prefixed bundle name. 150 * 151 * @param env The environment that the Node-API call is invoked under. 152 * @param info The callback info passed into the callback function. 153 * 154 * @return The return value from NAPI C++ to JS for the module. 155 */ 156 napi_value NAPI_GetAbilityName(napi_env env, napi_callback_info info); 157 158 /** 159 * @brief Obtains information about the current ability. 160 * 161 * @param env The environment that the Node-API call is invoked under. 162 * @param info The callback info passed into the callback function. 163 * 164 * @return The return value from NAPI C++ to JS for the module. 165 */ 166 napi_value NAPI_GetAbilityInfo(napi_env env, napi_callback_info info); 167 168 /** 169 * @brief FeatureAbility NAPI method : getDataAbilityHelper. 170 * 171 * @param env The environment that the Node-API call is invoked under. 172 * @param info The callback info passed into the callback function. 173 * 174 * @return The return value from NAPI C++ to JS for the module. 175 */ 176 napi_value NAPI_GetDataAbilityHelper(napi_env env, napi_callback_info info); 177 178 /** 179 * @brief FeatureAbility NAPI method : acquireDataAbilityHelper. 180 * 181 * @param env The environment that the Node-API call is invoked under. 182 * @param info The callback info passed into the callback function. 183 * 184 * @return The return value from NAPI C++ to JS for the module. 185 */ 186 napi_value NAPI_AcquireDataAbilityHelper(napi_env env, napi_callback_info info); 187 188 /** 189 * @brief Parse the parameters. 190 * 191 * @param param Indicates the parameters saved the parse result. 192 * @param env The environment that the Node-API call is invoked under. 193 * @param args Indicates the arguments passed into the callback. 194 * 195 * @return The return value from NAPI C++ to JS for the module. 196 */ 197 napi_value UnwrapForResultParam(CallAbilityParam ¶m, napi_env env, napi_value args); 198 199 /** 200 * @brief Parse the abilityResult parameters. 201 * 202 * @param param Indicates the abilityResult parameters saved the parse result. 203 * @param env The environment that the Node-API call is invoked under. 204 * @param args Indicates the arguments passed into the callback. 205 * 206 * @return The return value from NAPI C++ to JS for the module. 207 */ 208 napi_value UnwrapAbilityResult(CallAbilityParam ¶m, napi_env env, napi_value args); 209 210 /** 211 * @brief Create asynchronous data. 212 * 213 * @param env The environment that the Node-API call is invoked under. 214 * 215 * @return Return a pointer to AppInfoCB on success, nullptr on failure. 216 */ 217 AppInfoCB *CreateAppInfoCBInfo(napi_env env); 218 219 /** 220 * @brief HasWindowFocus processing function. 221 * 222 * @param env The environment that the Node-API call is invoked under. 223 * @param asyncCallbackInfo Process data asynchronously. 224 * 225 * @return Return JS data successfully, otherwise return nullptr. 226 */ 227 napi_value HasWindowFocusWrap(napi_env env, napi_callback_info info, AsyncCallbackInfo *asyncCallbackInfo); 228 napi_value HasWindowFocusAsync( 229 napi_env env, napi_value *args, const size_t argCallback, AsyncCallbackInfo *asyncCallbackInfo); 230 napi_value HasWindowFocusPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo); 231 232 /** 233 * @brief SetResult processing function. 234 * 235 * @param env The environment that the Node-API call is invoked under. 236 * @param asyncCallbackInfo Process data asynchronously. 237 * 238 * @return Return JS data successfully, otherwise return nullptr. 239 */ 240 napi_value SetResultWrap(napi_env env, napi_callback_info info, AsyncCallbackInfo *asyncCallbackInfo); 241 napi_value SetResultAsync( 242 napi_env env, napi_value *args, const size_t argCallback, AsyncCallbackInfo *asyncCallbackInfo); 243 napi_value SetResultPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo); 244 245 /** 246 * @brief StartAbilityForResult processing function. 247 * 248 * @param env The environment that the Node-API call is invoked under. 249 * @param asyncCallbackInfo Process data asynchronously. 250 * 251 * @return Return JS data successfully, otherwise return nullptr. 252 */ 253 napi_value StartAbilityForResultWrap(napi_env env, napi_callback_info info, AsyncCallbackInfo *asyncCallbackInfo); 254 napi_value StartAbilityForResultAsync(napi_env env, AsyncCallbackInfo *asyncCallbackInfo); 255 napi_value StartAbilityForResultPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo); 256 257 /** 258 * @brief ContinueAbility processing function. 259 * 260 * @param env The environment that the Node-API call is invoked under. 261 * @param asyncCallbackInfo Process data asynchronously. 262 * 263 * @return Return JS data successfully, otherwise return nullptr. 264 */ 265 napi_value ContinueAbilityWrap(napi_env env, napi_callback_info info, AsyncCallbackInfo *asyncCallbackInfo); 266 napi_value ContinueAbilityAsync(napi_env env, napi_value *args, AsyncCallbackInfo *asyncCallbackInfo, size_t argc); 267 napi_value ContinueAbilityPromise(napi_env env, napi_value *args, AsyncCallbackInfo *asyncCallbackInfo, size_t argc); 268 269 /** 270 * @brief Obtains the HapModuleInfo object of the application. 271 * 272 * @param env The environment that the Node-API call is invoked under. 273 * @param info The callback info passed into the callback function. 274 * 275 * @return The return value from NAPI C++ to JS for the module. 276 */ 277 napi_value NAPI_GetHapModuleInfo(napi_env env, napi_callback_info info); 278 279 /** 280 * @brief getDataAbilityHelper processing function. 281 * 282 * @param env The environment that the Node-API call is invoked under. 283 * @param dataAbilityHelperCB Process data asynchronously. 284 * 285 * @return Return JS data successfully, otherwise return nullptr. 286 */ 287 napi_value GetDataAbilityHelperWrap(napi_env env, napi_callback_info info, DataAbilityHelperCB *dataAbilityHelperCB); 288 289 /** 290 * @brief GetDataAbilityHelper Async. 291 * 292 * @param env The environment that the Node-API call is invoked under. 293 * @param args Indicates the arguments passed into the callback. 294 * @param argcPromise Asynchronous data processing. 295 * @param dataAbilityHelperCB Process data asynchronously. 296 * 297 * @return Return JS data successfully, otherwise return nullptr. 298 */ 299 napi_value GetDataAbilityHelperAsync( 300 napi_env env, napi_value *args, const size_t argCallback, DataAbilityHelperCB *dataAbilityHelperCB); 301 302 /** 303 * @brief GetDataAbilityHelper Promise. 304 * 305 * @param env The environment that the Node-API call is invoked under. 306 * @param dataAbilityHelperCB Process data asynchronously. 307 * 308 * @return Return JS data successfully, otherwise return nullptr. 309 */ 310 napi_value GetDataAbilityHelperPromise(napi_env env, DataAbilityHelperCB *dataAbilityHelperCB); 311 312 /** 313 * @brief The callback at the end of the asynchronous callback. 314 * 315 * @param env The environment that the Node-API call is invoked under. 316 * @param data Point to asynchronous processing of data. 317 */ 318 void GetDataAbilityHelperAsyncCompleteCB(napi_env env, napi_status status, void *data); 319 320 /** 321 * @brief The callback at the end of the Promise callback. 322 * 323 * @param env The environment that the Node-API call is invoked under. 324 * @param data Point to asynchronous processing of data. 325 */ 326 void GetDataAbilityHelperPromiseCompleteCB(napi_env env, napi_status status, void *data); 327 328 /** 329 * @brief FeatureAbility NAPI method : connectAbility. 330 * 331 * @param env The environment that the Node-API call is invoked under. 332 * @param info The callback info passed into the callback function. 333 * 334 * @return The return value from NAPI C++ to JS for the module. 335 */ 336 napi_value NAPI_FAConnectAbility(napi_env env, napi_callback_info info); 337 338 /** 339 * @brief FeatureAbility NAPI method : disconnectAbility. 340 * 341 * @param env The environment that the Node-API call is invoked under. 342 * @param info The callback info passed into the callback function. 343 * 344 * @return The return value from NAPI C++ to JS for the module. 345 */ 346 napi_value NAPI_FADisConnectAbility(napi_env env, napi_callback_info info); 347 348 /** 349 * @brief FeatureAbility NAPI method : continueAbility. 350 * 351 * @param env The environment that the Node-API call is invoked under. 352 * @param info The callback info passed into the callback function. 353 * 354 * @return The return value from NAPI C++ to JS for the module. 355 */ 356 napi_value NAPI_FAContinueAbility(napi_env env, napi_callback_info info); 357 358 NativeValue* JsFeatureAbilityInit(NativeEngine *engine, NativeValue *exports); 359 } // namespace AppExecFwk 360 } // namespace OHOS 361 #endif /* OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_H */ 362