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_COMMON_ABILITY_H
17 #define OHOS_ABILITY_RUNTIME_NAPI_COMMON_ABILITY_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <list>
22 
23 #include "ability_info.h"
24 #include "ability_manager_errors.h"
25 #include "application_info.h"
26 #include "feature_ability_common.h"
27 #include "napi_common_ability_wrap_utils.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
31 napi_status SetGlobalClassContext(napi_env env, napi_value constructor);
32 napi_value GetGlobalClassContext(napi_env env);
33 
34 napi_status SaveGlobalDataAbilityHelper(napi_env env, napi_value constructor);
35 napi_value GetGlobalDataAbilityHelper(napi_env env);
36 bool& GetDataAbilityHelperStatus();
37 
38 /**
39  * @brief Get Files Dir.
40  *
41  * @param env The environment that the Node-API call is invoked under.
42  * @param info The callback info passed into the callback function.
43  *
44  * @return The return value from NAPI C++ to JS for the module.
45  */
46 napi_value NAPI_GetFilesDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
47 
48 /**
49  * @brief Get OrCreateDistribute Dir.
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_GetOrCreateDistributedDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
57 
58 napi_value NAPI_GetCacheDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
59 
60 napi_value NAPI_GetExternalCacheDirCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
61 
62 napi_value NAPI_IsUpdatingConfigurationsCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
63 
64 napi_value NAPI_PrintDrawnCompletedCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
65 
66 /**
67  * @brief Obtains the type of this application.
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_GetAppTypeCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
75 
76 /**
77  * @brief Get the display orientation of the main window.
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 #ifdef SUPPORT_GRAPHICS
85 napi_value NAPI_GetDisplayOrientationCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
86 bool UnwrapParamGetDisplayOrientationWrap(napi_env env, size_t argc, napi_value *argv,
87     AsyncJSCallbackInfo *asyncCallbackInfo);
88 void GetDisplayOrientationExecuteCallback(napi_env env, void *data);
89 #endif
90 
91 /**
92  * @brief Obtains information about the current ability.
93  *
94  * @param env The environment that the Node-API call is invoked under.
95  * @param info The callback info passed into the callback function.
96  *
97  * @return The return value from NAPI C++ to JS for the module.
98  */
99 napi_value NAPI_GetAbilityInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
100 
101 /**
102  * @brief Obtains the HapModuleInfo object of the application.
103  *
104  * @param env The environment that the Node-API call is invoked under.
105  * @param info The callback info passed into the callback function.
106  *
107  * @return The return value from NAPI C++ to JS for the module.
108  */
109 napi_value NAPI_GetHapModuleInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
110 
111 /**
112  * @brief Obtains the AppVersionInfo object of the application.
113  *
114  * @param env The environment that the Node-API call is invoked under.
115  * @param info The callback info passed into the callback function.
116  *
117  * @return The return value from NAPI C++ to JS for the module.
118  */
119 napi_value NAPI_GetAppVersionInfoCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
120 
121 /**
122  * @brief Create asynchronous data.
123  *
124  * @param env The environment that the Node-API call is invoked under.
125  *
126  * @return Return a pointer to AsyncCallbackInfo on success, nullptr on failure
127  */
128 AsyncCallbackInfo *CreateAsyncCallbackInfo(napi_env env);
129 /**
130  * @brief Get context.
131  *
132  * @param env The environment that the Node-API call is invoked under.
133  * @param info The callback info passed into the callback function.
134  *
135  * @return The return value from NAPI C++ to JS for the module.
136  */
137 napi_value NAPI_GetContextCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
138 
139 /**
140  * @brief Get want.
141  *
142  * @param env The environment that the Node-API call is invoked under.
143  * @param info The callback info passed into the callback function.
144  *
145  * @return The return value from NAPI C++ to JS for the module.
146  */
147 napi_value NAPI_GetWantCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
148 
149 /**
150  * @brief Obtains the class name in this ability name, without the prefixed bundle name.
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_GetAbilityNameCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
158 
159 /**
160  * @brief stopAbility.
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_StopAbilityCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
168 
169 /**
170  * @brief acquireDataAbilityHelper processing function.
171  *
172  * @param env The environment that the Node-API call is invoked under.
173  * @param dataAbilityHelperCB Process data asynchronously.
174  *
175  * @return Return JS data successfully, otherwise return nullptr.
176  */
177 napi_value AcquireDataAbilityHelperWrap(
178     napi_env env, napi_callback_info info, DataAbilityHelperCB *dataAbilityHelperCB);
179 
180 /**
181  * @brief AcquireDataAbilityHelper.
182  *
183  * @param env The environment that the Node-API call is invoked under.
184  * @param info The callback info passed into the callback function.
185  *
186  * @return The return value from NAPI C++ to JS for the module.
187  */
188 napi_value NAPI_AcquireDataAbilityHelperCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
189 
190 napi_value ConvertAbilityInfo(napi_env env, const AbilityInfo &abilityInfo);
191 
192 /**
193  * @brief start background running.
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_StartBackgroundRunningCommon(napi_env env, napi_callback_info info);
201 
202 /**
203  * @brief cancel background running.
204  *
205  * @param env The environment that the Node-API call is invoked under.
206  * @param info The callback info passed into the callback function.
207  *
208  * @return The return value from NAPI C++ to JS for the module.
209  */
210 napi_value NAPI_CancelBackgroundRunningCommon(napi_env env, napi_callback_info info);
211 
212 enum ErrorCode {
213     NO_ERROR = 0,
214     INVALID_PARAMETER = -1,
215     ABILITY_NOT_FOUND = -2,
216     PERMISSION_DENY = -3,
217 };
218 }  // namespace AppExecFwk
219 }  // namespace OHOS
220 #endif  // OHOS_ABILITY_RUNTIME_NAPI_COMMON_ABILITY_H
221