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_FEATURE_ABILITY_COMMON_H
17 #define OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_COMMON_H
18
19 #include "ability.h"
20 #include "ability_info.h"
21 #include "application_info.h"
22 #include "hap_module_info.h"
23 #include "napi/native_api.h"
24 #include "napi/native_common.h"
25 #include "napi/native_node_api.h"
26 #include "napi_common.h"
27 #include "napi_common_util.h"
28 #include "pac_map.h"
29 #include "want.h"
30
31 using Want = OHOS::AAFwk::Want;
32 using Ability = OHOS::AppExecFwk::Ability;
33 using AbilityStartSetting = OHOS::AppExecFwk::AbilityStartSetting;
34
35 namespace OHOS {
36 namespace AppExecFwk {
37 class FeatureAbility;
38
39 struct CallAbilityParam {
40 Want want;
41 int requestCode = 0;
42 bool forResultOption = false;
43 std::shared_ptr<AbilityStartSetting> setting = nullptr;
44 };
45
46 struct OnAbilityCallback {
47 int requestCode = 0;
48 int resultCode = 0;
49 Want resultData;
50 CallbackInfo cb;
51 };
52
53 struct ContinueAbilityOptionsInfo {
54 bool reversible = false;
55 std::string deviceId;
56 };
57
58 struct AsyncCallbackInfo {
59 CallbackInfo cbInfo;
60 napi_async_work asyncWork = nullptr;
61 napi_deferred deferred = nullptr;
62 Ability *ability = nullptr;
63 AbilityRuntime::WantAgent::WantAgent *wantAgent = nullptr;
64 CallAbilityParam param;
65 CallbackInfo aceCallback;
66 bool native_result;
67 AbilityType abilityType = AbilityType::UNKNOWN;
68 int errCode = 0;
69 ContinueAbilityOptionsInfo optionInfo;
70 #ifdef SUPPORT_GRAPHICS
71 sptr<OHOS::Rosen::Window> window;
72 #endif
73 };
74
75 struct CBBase {
76 CallbackInfo cbInfo;
77 napi_async_work asyncWork;
78 napi_deferred deferred;
79 Ability *ability = nullptr;
80 AbilityType abilityType = AbilityType::UNKNOWN;
81 int errCode = 0;
82 };
83
84 struct AppInfoCB {
85 CBBase cbBase;
86 ApplicationInfo appInfo;
87 };
88
89 struct AppTypeCB {
90 CBBase cbBase;
91 std::string name;
92 };
93 struct AbilityInfoCB {
94 CBBase cbBase;
95 AbilityInfo abilityInfo;
96 };
97
98 struct AbilityNameCB {
99 CBBase cbBase;
100 std::string name;
101 };
102
103 struct ProcessInfoCB {
104 CBBase cbBase;
105 pid_t pid = 0;
106 std::string processName;
107 };
108
109 struct ProcessNameCB {
110 CBBase cbBase;
111 std::string processName;
112 };
113
114 struct CallingBundleCB {
115 CBBase cbBase;
116 std::string callingBundleName;
117 };
118
119 struct GetOrCreateLocalDirCB {
120 CBBase cbBase;
121 std::string rootDir;
122 };
123
124 struct DatabaseDirCB {
125 CBBase cbBase;
126 std::string dataBaseDir;
127 };
128
129 struct PreferencesDirCB {
130 CBBase cbBase;
131 std::string preferencesDir;
132 };
133
134 struct ElementNameCB {
135 CBBase cbBase;
136 std::string deviceId;
137 std::string bundleName;
138 std::string abilityName;
139 std::string uri;
140 std::string shortName;
141 };
142
143 struct HapModuleInfoCB {
144 CBBase cbBase;
145 HapModuleInfo hapModuleInfo;
146 };
147
148 struct AppVersionInfo {
149 std::string appName;
150 std::string versionName;
151 int32_t versionCode = 0;
152 };
153
154 struct AppVersionInfoCB {
155 CBBase cbBase;
156 AppVersionInfo appVersionInfo;
157 };
158
159 struct DataAbilityHelperCB {
160 CBBase cbBase;
161 napi_ref uri = nullptr;
162 napi_value result = nullptr;
163 };
164
165 struct ConnectionCallback;
166 class NAPIAbilityConnection;
167 struct AbilityConnectionCB {
168 napi_env env;
169 napi_ref callback[3] = {nullptr}; // onConnect/onDisconnect/onFailed
170 int resultCode = 0;
171 ElementName elementName;
172 sptr<IRemoteObject> connection;
173 };
174 struct ConnectAbilityCB {
175 CBBase cbBase;
176 Want want;
177 sptr<NAPIAbilityConnection> abilityConnection;
178 AbilityConnectionCB abilityConnectionCB;
179 int64_t id;
180 bool result;
181 int errCode = 0;
182 };
183
184 struct ShowOnLockScreenCB {
185 CBBase cbBase;
186 bool isShow;
187 };
188
189 struct SetWakeUpScreenCB {
190 CBBase cbBase;
191 bool wakeUp;
192 };
193
NapiValueToStringUtf8(napi_env env,napi_value value)194 static inline std::string NapiValueToStringUtf8(napi_env env, napi_value value)
195 {
196 std::string result = "";
197 return UnwrapStringFromJS(env, value, result);
198 }
199
NapiValueToArrayStringUtf8(napi_env env,napi_value param,std::vector<std::string> & result)200 static inline bool NapiValueToArrayStringUtf8(napi_env env, napi_value param, std::vector<std::string> &result)
201 {
202 return UnwrapArrayStringFromJS(env, param, result);
203 }
204 } // namespace AppExecFwk
205 } // namespace OHOS
206 #endif /* OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_COMMON_H */
207