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_NAPI_CONTEXT_H 17 #define OHOS_ABILITY_RUNTIME_NAPI_CONTEXT_H 18 #include "napi_common.h" 19 #include "ability.h" 20 #include "napi/native_api.h" 21 #include "napi/native_common.h" 22 #include "napi/native_node_api.h" 23 #include "js_runtime_utils.h" 24 25 using Ability = OHOS::AppExecFwk::Ability; 26 #define MODE 0771 27 namespace OHOS { 28 namespace AppExecFwk { 29 struct CallAbilityPermissionParam { 30 std::vector<std::string> permission_list; 31 int requestCode = 0; 32 int syncOption = false; 33 }; 34 35 /** 36 * @brief Context NAPI module registration. 37 * 38 * @param env The environment that the Node-API call is invoked under. 39 * @param exports An empty object via the exports parameter as a convenience. 40 * 41 * @return The return value from Init is treated as the exports object for the module. 42 */ 43 napi_value ContextPermissionInit(napi_env env, napi_value exports); 44 45 EXTERN_C_START 46 /** 47 * @brief The interface of onRequestPermissionsFromUserResult provided for ACE to call back to JS. 48 * 49 * @param requestCode Indicates the request code returned after the ability is started. 50 * @param permissions Indicates list of permission. 51 * @param grantResults Indicates List of authorization results. 52 * @param callbackInfo The environment and call back info that the Node-API call is invoked under. 53 */ 54 void CallOnRequestPermissionsFromUserResult(int requestCode, const std::vector<std::string> &permissions, 55 const std::vector<int> &grantResults, OHOS::AppExecFwk::CallbackInfo callbackInfo); 56 EXTERN_C_END 57 napi_value ContextConstructor(napi_env env, napi_callback_info info); 58 59 /** 60 * @brief Set lock screen Permit list. 61 * 62 * @param env The environment that the Node-API call is invoked under. 63 * @param info The callback info passed into the callback function. 64 * 65 * @return The return value from NAPI C++ to JS for the module. 66 */ 67 napi_value NAPI_SetShowOnLockScreen(napi_env env, napi_callback_info info); 68 69 /** 70 * @brief Obtains information about the current application. 71 * 72 * @param env The environment that the Node-API call is invoked under. 73 * @param info The callback info passed into the callback function. 74 * 75 * @return The return value from NAPI C++ to JS for the module. 76 */ 77 napi_value NAPI_GetApplicationInfo(napi_env env, napi_callback_info info); 78 79 /** 80 * @brief Obtains the elementName object of the current ability. 81 * 82 * @param env The environment that the Node-API call is invoked under. 83 * @param info The callback info passed into the callback function. 84 * 85 * @return The return value from NAPI C++ to JS for the module. 86 */ 87 napi_value NAPI_GetElementName(napi_env env, napi_callback_info info); 88 89 /** 90 * @brief Obtains the process Info this application. 91 * 92 * @param env The environment that the Node-API call is invoked under. 93 * @param info The callback info passed into the callback function. 94 * 95 * @return The return value from NAPI C++ to JS for the module. 96 */ 97 napi_value NAPI_GetProcessInfo(napi_env env, napi_callback_info info); 98 99 /** 100 * @brief Obtains the name of the current process. 101 * 102 * @param env The environment that the Node-API call is invoked under. 103 * @param info The callback info passed into the callback function. 104 * 105 * @return The return value from NAPI C++ to JS for the module. 106 */ 107 napi_value NAPI_GetProcessName(napi_env env, napi_callback_info info); 108 109 /** 110 * @brief Obtains the bundle name of the ability that called the current ability. 111 * 112 * @param env The environment that the Node-API call is invoked under. 113 * @param info The callback info passed into the callback function. 114 * 115 * @return The return value from NAPI C++ to JS for the module. 116 */ 117 napi_value NAPI_GetCallingBundle(napi_env env, napi_callback_info info); 118 119 napi_value NAPI_GetOrCreateDistributedDir(napi_env env, napi_callback_info info); 120 121 napi_value NAPI_GetFilesDir(napi_env env, napi_callback_info info); 122 123 napi_value NAPI_GetCacheDir(napi_env env, napi_callback_info info); 124 125 /** 126 * @brief Obtains the type of this application. 127 * 128 * @param env The environment that the Node-API call is invoked under. 129 * @param info The callback info passed into the callback function. 130 * 131 * @return The return value from NAPI C++ to JS for the module. 132 */ 133 napi_value NAPI_GetCtxAppType(napi_env env, napi_callback_info info); 134 135 /** 136 * @brief Obtains the HapModuleInfo object of the application. 137 * 138 * @param env The environment that the Node-API call is invoked under. 139 * @param info The callback info passed into the callback function. 140 * 141 * @return The return value from NAPI C++ to JS for the module. 142 */ 143 napi_value NAPI_GetCtxHapModuleInfo(napi_env env, napi_callback_info info); 144 145 napi_value NAPI_GetAppVersionInfo(napi_env env, napi_callback_info info); 146 147 napi_value NAPI_GetApplicationContext(napi_env env, napi_callback_info info); 148 149 /** 150 * @brief Obtains information about the current ability. 151 * 152 * @param env The environment that the Node-API call is invoked under. 153 * @param info The callback info passed into the callback function. 154 * 155 * @return The return value from NAPI C++ to JS for the module. 156 */ 157 napi_value NAPI_GetCtxAbilityInfo(napi_env env, napi_callback_info info); 158 159 /** 160 * @brief Set wake up screen screen Permit list. 161 * 162 * @param env The environment that the Node-API call is invoked under. 163 * @param info The callback info passed into the callback function. 164 * 165 * @return The return value from NAPI C++ to JS for the module. 166 */ 167 napi_value NAPI_SetWakeUpScreen(napi_env env, napi_callback_info info); 168 169 /** 170 * @brief Set the display orientation of the main window. 171 * 172 * @param env The environment that the Node-API call is invoked under. 173 * @param info The callback info passed into the callback function. 174 * 175 * @return The return value from NAPI C++ to JS for the module. 176 */ 177 napi_value NAPI_SetDisplayOrientation(napi_env env, napi_callback_info info); 178 #ifdef SUPPORT_GRAPHICS 179 napi_value NAPI_SetDisplayOrientationWrap(napi_env env, napi_callback_info info, 180 AsyncJSCallbackInfo *asyncCallbackInfo); 181 bool UnwrapSetDisplayOrientation(napi_env env, size_t argc, napi_value *argv, AsyncJSCallbackInfo *asyncCallbackInfo); 182 void SetDisplayOrientationExecuteCallbackWork(napi_env env, void *data); 183 #endif 184 185 /** 186 * @brief Get the display orientation of the main window. 187 * 188 * @param env The environment that the Node-API call is invoked under. 189 * @param info The callback info passed into the callback function. 190 * 191 * @return The return value from NAPI C++ to JS for the module. 192 */ 193 napi_value NAPI_GetDisplayOrientation(napi_env env, napi_callback_info info); 194 195 /** 196 * @brief Get the application context 197 * 198 * @param engine Native JS engine. 199 * 200 * @return The return value from C++ to JS for the module. 201 */ 202 napi_value CreateNapiJSContext(napi_env env); 203 } // namespace AppExecFwk 204 } // namespace OHOS 205 #endif /* OHOS_ABILITY_RUNTIME_NAPI_CONTEXT_H */ 206