1 /*
2  * Copyright (c) 2024 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_COMMON_H
17 #define OHOS_ABILITY_RUNTIME_NAPI_COMMON_ABILITY_COMMON_H
18 
19 #include <map>
20 
21 #include "ability_manager_client.h"
22 #include "js_napi_common_ability.h"
23 #include "js_runtime_utils.h"
24 #include "napi_common_error.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 
29 bool CheckAbilityType(const CBBase *cbBase);
30 bool CheckAbilityType(const AsyncJSCallbackInfo *asyncCallbackInfo);
31 bool CheckAbilityType(const AsyncCallbackInfo *asyncCallbackInfo);
32 
33 /**
34  * @brief Obtains the continue ability Info this application.
35  *
36  * @param env The environment that the Node-API call is invoked under.
37  * @param value The value passed into the info.
38  * @param info The continue ability options info
39  *
40  * @return The return value from NAPI C++ to JS for the module.
41  */
42 napi_value GetContinueAbilityOptionsInfoCommon(
43     const napi_env &env, const napi_value &value, ContinueAbilityOptionsInfo &info);
44 
45 /**
46  * @brief Obtains the continue ability can reversible or not
47  *
48  * @param env The environment that the Node-API call is invoked under.
49  * @param value The value passed into the info.
50  * @param info The continue ability options info
51  *
52  * @return The return value from NAPI C++ to JS for the module.
53  */
54 napi_value GetContinueAbilityOptionsReversible(
55     const napi_env &env, const napi_value &value, ContinueAbilityOptionsInfo &info);
56 
57 /**
58  * @brief Obtains the continue ability Info this application.
59  *
60  * @param env The environment that the Node-API call is invoked under.
61  * @param value The value passed into the info.
62  * @param info The continue ability options info
63  *
64  * @return The return value from NAPI C++ to JS for the module.
65  */
66 napi_value GetContinueAbilityOptionsDeviceID(
67     const napi_env &env, const napi_value &value, ContinueAbilityOptionsInfo &info);
68 
69 napi_value WrapAppInfo(napi_env env, const ApplicationInfo &appInfo);
70 int32_t GetStartAbilityErrorCode(ErrCode innerErrorCode);
71 
72 /**
73  * @brief GetFilesDir asynchronous processing function.
74  *
75  * @param env The environment that the Node-API call is invoked under.
76  * @param data Point to asynchronous processing of data.
77  */
78 void GetFilesDirExecuteCallback(napi_env, void *data);
79 void IsUpdatingConfigurationsExecuteCallback(napi_env, void *data);
80 
81 /**
82  * @brief PrintDrawnCompleted asynchronous processing function.
83  *
84  * @param env The environment that the Node-API call is invoked under.
85  * @param data Point to asynchronous processing of data.
86  */
87 void PrintDrawnCompletedExecuteCallback(napi_env, void *data);
88 void GetOrCreateDistributedDirExecuteCallback(napi_env, void *data);
89 
90 /**
91  * @brief GetCacheDir asynchronous processing function.
92  *
93  * @param env The environment that the Node-API call is invoked under.
94  * @param data Point to asynchronous processing of data.
95  */
96 void GetCacheDirExecuteCallback(napi_env, void *data);
97 
98 /**
99  * @brief GetExternalCacheDir asynchronous processing function.
100  *
101  * @param env The environment that the Node-API call is invoked under.
102  * @param data Point to asynchronous processing of data.
103  */
104 void GetExternalCacheDirExecuteCallback(napi_env, void *data);
105 
106 /**
107  * @brief Create asynchronous data.
108  *
109  * @param env The environment that the Node-API call is invoked under.
110  *
111  * @return Return a pointer to AppTypeCB on success, nullptr on failure.
112  */
113 AppTypeCB *CreateAppTypeCBInfo(napi_env env);
114 
115 /**
116  * @brief Create asynchronous data.
117  *
118  * @param env The environment that the Node-API call is invoked under.
119  *
120  * @return Return a pointer to AbilityInfoCB on success, nullptr on failure.
121  */
122 AbilityInfoCB *CreateAbilityInfoCBInfo(napi_env env);
123 
124 napi_value WrapAbilityInfo(napi_env env, const AbilityInfo &abilityInfo);
125 napi_value WrapProperties(napi_env env, const std::vector<std::string> properties, const std::string &proName,
126     napi_value &result);
127 napi_value WrapModuleInfos(napi_env env, const ApplicationInfo &appInfo, napi_value &result);
128 
129 /**
130  * @brief Create asynchronous data.
131  *
132  * @param env The environment that the Node-API call is invoked under.
133  *
134  * @return Return a pointer to HapModuleInfoCB on success, nullptr on failure.
135  */
136 HapModuleInfoCB *CreateHapModuleInfoCBInfo(napi_env env);
137 napi_value WrapHapModuleInfo(napi_env env, const HapModuleInfoCB &cb);
138 
139 /**
140  * @brief Create asynchronous data.
141  *
142  * @param env The environment that the Node-API call is invoked under.
143  *
144  * @return Return a pointer to AppVersionInfoCB on success, nullptr on failure.
145  */
146 AppVersionInfoCB *CreateAppVersionInfoCBInfo(napi_env env);
147 void SaveAppVersionInfo(AppVersionInfo &appVersionInfo, const std::string appName, const std::string versionName,
148     const int32_t versionCode);
149 napi_value WrapAppVersionInfo(napi_env env, const AppVersionInfoCB &appVersionInfoCB);
150 
151 /**
152  * @brief Create asynchronous data.
153  *
154  * @param env The environment that the Node-API call is invoked under.
155  *
156  * @return Return a pointer to AbilityNameCB on success, nullptr on failure.
157  */
158 AbilityNameCB *CreateAbilityNameCBInfo(napi_env env);
159 napi_value WrapAbilityName(napi_env env, const AbilityNameCB *abilityNameCB);
160 
161 bool UnwrapAbilityStartSetting(napi_env env, napi_value param, AAFwk::AbilityStartSetting &setting);
162 
163 bool UnwrapParamStopAbilityWrap(napi_env env, size_t argc, napi_value *argv, AsyncJSCallbackInfo *asyncCallbackInfo);
164 napi_value UnwrapParamForWantAgent(napi_env &env, napi_value &args, AbilityRuntime::WantAgent::WantAgent *&wantAgent);
165 
166 }  // namespace AppExecFwk
167 }  // namespace OHOS
168 #endif  // OHOS_ABILITY_RUNTIME_NAPI_COMMON_ABILITY_COMMON_H