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