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