• 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 #include "ability_info.h"
17 
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <errno.h>
21 #include <string.h>
22 
23 #include "nlohmann/json.hpp"
24 #include "string_ex.h"
25 #include "app_log_wrapper.h"
26 #include "parcel_macro.h"
27 #include "json_serializer.h"
28 #include "bundle_constants.h"
29 
30 namespace OHOS {
31 namespace AppExecFwk {
32 
33 namespace {
34 
35 const std::string JSON_KEY_PACKAGE = "package";
36 const std::string JSON_KEY_NAME = "name";
37 const std::string JSON_KEY_BUNDLE_NAME = "bundleName";
38 const std::string JSON_KEY_APPLICATION_NAME = "applicationName";
39 const std::string JSON_KEY_LABEL = "label";
40 const std::string JSON_KEY_DESCRIPTION = "description";
41 const std::string JSON_KEY_ICON_PATH = "iconPath";
42 const std::string JSON_KEY_THEME = "theme";
43 const std::string JSON_KEY_VISIBLE = "visible";
44 const std::string JSON_KEY_KIND = "kind";
45 const std::string JSON_KEY_TYPE = "type";
46 const std::string JSON_KEY_ORIENTATION = "orientation";
47 const std::string JSON_KEY_LAUNCH_MODE = "launchMode";
48 const std::string JSON_KEY_CODE_PATH = "codePath";
49 const std::string JSON_KEY_RESOURCE_PATH = "resourcePath";
50 const std::string JSON_KEY_LIB_PATH = "libPath";
51 const std::string JSON_KEY_PERMISSIONS = "permissions";
52 const std::string JSON_KEY_PROCESS = "process";
53 const std::string JSON_KEY_DEVICE_TYPES = "deviceTypes";
54 const std::string JSON_KEY_DEVICE_CAPABILITIES = "deviceCapabilities";
55 const std::string JSON_KEY_URI = "uri";
56 const std::string JSON_KEY_MODULE_NAME = "moduleName";
57 const std::string JSON_KEY_DEVICE_ID = "deviceId";
58 const std::string JSON_KEY_IS_LAUNCHER_ABILITY = "isLauncherAbility";
59 const std::string JSON_KEY_IS_NATIVE_ABILITY = "isNativeAbility";
60 const std::string JSON_KEY_ENABLED = "enabled";
61 const std::string JSON_KEY_SUPPORT_PIP_MODE = "supportPipMode";
62 const std::string JSON_KEY_TARGET_ABILITY = "targetAbility";
63 const std::string JSON_KEY_READ_PERMISSION = "readPermission";
64 const std::string JSON_KEY_WRITE_PERMISSION = "writePermission";
65 const std::string JSON_KEY_CONFIG_CHANGES = "configChanges";
66 const std::string JSON_KEY_FORM = "form";
67 const std::string JSON_KEY_FORM_ENTITY = "formEntity";
68 const std::string JSON_KEY_MIN_FORM_HEIGHT = "minFormHeight";
69 const std::string JSON_KEY_DEFAULT_FORM_HEIGHT = "defaultFormHeight";
70 const std::string JSON_KEY_MIN_FORM_WIDTH = "minFormWidth";
71 const std::string JSON_KEY_DEFAULT_FORM_WIDTH = "defaultFormWidth";
72 const std::string JSON_KEY_PARAMETERS = "parameters";
73 const std::string JSON_KEY_RESULTS = "results";
74 const std::string JSON_KEY_CUSTOMIZE_DATA = "customizeData";
75 const std::string JSON_KEY_META_DATA = "metaData";
76 const std::string JSON_KEY_META_VALUE = "value";
77 const std::string JSON_KEY_META_EXTRA = "extra";
78 const std::string JSON_KEY_LABEL_ID = "labelId";
79 const std::string JSON_KEY_DESCRIPTION_ID = "descriptionId";
80 const std::string JSON_KEY_ICON_ID = "iconId";
81 const std::string JSON_KEY_FORM_ENABLED = "formEnabled";
82 const std::string JSON_KEY_SRC_PATH = "srcPath";
83 const std::string JSON_KEY_SRC_LANGUAGE = "srcLanguage";
84 }  // namespace
85 
ReadFromParcel(Parcel & parcel)86 bool AbilityInfo::ReadFromParcel(Parcel &parcel)
87 {
88     name = Str16ToStr8(parcel.ReadString16());
89     label = Str16ToStr8(parcel.ReadString16());
90     description = Str16ToStr8(parcel.ReadString16());
91     iconPath = Str16ToStr8(parcel.ReadString16());
92     theme = Str16ToStr8(parcel.ReadString16());
93     kind = Str16ToStr8(parcel.ReadString16());
94     uri = Str16ToStr8(parcel.ReadString16());
95     package = Str16ToStr8(parcel.ReadString16());
96     bundleName = Str16ToStr8(parcel.ReadString16());
97     moduleName = Str16ToStr8(parcel.ReadString16());
98     applicationName = Str16ToStr8(parcel.ReadString16());
99     process = Str16ToStr8(parcel.ReadString16());
100     deviceId = Str16ToStr8(parcel.ReadString16());
101     codePath = Str16ToStr8(parcel.ReadString16());
102     resourcePath = Str16ToStr8(parcel.ReadString16());
103     libPath = Str16ToStr8(parcel.ReadString16());
104     targetAbility = Str16ToStr8(parcel.ReadString16());
105     readPermission = Str16ToStr8(parcel.ReadString16());
106     writePermission = Str16ToStr8(parcel.ReadString16());
107     srcPath = Str16ToStr8(parcel.ReadString16());
108     srcLanguage = Str16ToStr8(parcel.ReadString16());
109     visible = parcel.ReadBool();
110     isLauncherAbility = parcel.ReadBool();
111     isNativeAbility = parcel.ReadBool();
112     enabled = parcel.ReadBool();
113     supportPipMode = parcel.ReadBool();
114     formEnabled = parcel.ReadBool();
115     int32_t configChangesSize;
116     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, configChangesSize);
117     for (int32_t i = 0; i < configChangesSize; i++) {
118         configChanges.emplace_back(Str16ToStr8(parcel.ReadString16()));
119     }
120     formEntity = parcel.ReadInt32();
121     minFormHeight = parcel.ReadInt32();
122     defaultFormHeight = parcel.ReadInt32();
123     minFormWidth = parcel.ReadInt32();
124     defaultFormWidth = parcel.ReadInt32();
125     labelId = parcel.ReadInt32();
126     descriptionId = parcel.ReadInt32();
127     iconId = parcel.ReadInt32();
128 
129     int32_t typeData;
130     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, typeData);
131     type = static_cast<AbilityType>(typeData);
132 
133     int32_t orientationData;
134     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, orientationData);
135     orientation = static_cast<DisplayOrientation>(orientationData);
136 
137     int32_t launchModeData;
138     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, launchModeData);
139     launchMode = static_cast<LaunchMode>(launchModeData);
140 
141     int32_t permissionsSize;
142     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, permissionsSize);
143     for (int32_t i = 0; i < permissionsSize; i++) {
144         permissions.emplace_back(Str16ToStr8(parcel.ReadString16()));
145     }
146 
147     int32_t deviceTypesSize;
148     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceTypesSize);
149     for (int32_t i = 0; i < deviceTypesSize; i++) {
150         deviceTypes.emplace_back(Str16ToStr8(parcel.ReadString16()));
151     }
152 
153     int32_t deviceCapabilitiesSize;
154     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceCapabilitiesSize);
155     for (int32_t i = 0; i < deviceCapabilitiesSize; i++) {
156         deviceCapabilities.emplace_back(Str16ToStr8(parcel.ReadString16()));
157     }
158 
159     int32_t customizeDataSize;
160     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, customizeDataSize);
161     for (auto i = 0; i < customizeDataSize; i++) {
162         CustomizeData customizeData;
163         std::string customizeName = Str16ToStr8(parcel.ReadString16());
164         std::string customizeValue = Str16ToStr8(parcel.ReadString16());
165         std::string customizeExtra = Str16ToStr8(parcel.ReadString16());
166         customizeData.name = customizeName;
167         customizeData.value = customizeValue;
168         customizeData.extra = customizeExtra;
169         metaData.customizeData.emplace_back(customizeData);
170     }
171 
172     int32_t parametersSize;
173     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, parametersSize);
174     for (auto i = 0; i < parametersSize; i++) {
175         Parameters parameters;
176         std::string parametersDescription = Str16ToStr8(parcel.ReadString16());
177         std::string parametersName = Str16ToStr8(parcel.ReadString16());
178         std::string parametersType = Str16ToStr8(parcel.ReadString16());
179         parameters.description = parametersDescription;
180         parameters.name = parametersName;
181         parameters.type = parametersType;
182         metaData.parameters.emplace_back(parameters);
183     }
184 
185     int32_t ResultsSize;
186     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, ResultsSize);
187     for (auto i = 0; i < ResultsSize; i++) {
188         Results results;
189         std::string resultsDescription = Str16ToStr8(parcel.ReadString16());
190         std::string resultsName = Str16ToStr8(parcel.ReadString16());
191         std::string resultsType = Str16ToStr8(parcel.ReadString16());
192         results.description = resultsDescription;
193         results.name = resultsName;
194         results.type = resultsType;
195         metaData.results.emplace_back(results);
196     }
197 
198     std::unique_ptr<ApplicationInfo> appInfo(parcel.ReadParcelable<ApplicationInfo>());
199     if (!appInfo) {
200         APP_LOGE("ReadParcelable<ApplicationInfo> failed");
201         return false;
202     }
203     applicationInfo = *appInfo;
204     return true;
205 }
206 
Unmarshalling(Parcel & parcel)207 AbilityInfo *AbilityInfo::Unmarshalling(Parcel &parcel)
208 {
209     AbilityInfo *info = new (std::nothrow) AbilityInfo();
210     if (info && !info->ReadFromParcel(parcel)) {
211         APP_LOGW("read from parcel failed");
212         delete info;
213         info = nullptr;
214     }
215     return info;
216 }
217 
Marshalling(Parcel & parcel) const218 bool AbilityInfo::Marshalling(Parcel &parcel) const
219 {
220     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
221     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label));
222     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(description));
223     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(iconPath));
224     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(theme));
225     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(kind));
226     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri));
227     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(package));
228     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
229     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
230     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(applicationName));
231     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(process));
232     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceId));
233     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(codePath));
234     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(resourcePath));
235     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(libPath));
236     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetAbility));
237     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(readPermission));
238     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(writePermission));
239     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcPath));
240     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcLanguage));
241     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, visible);
242     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isLauncherAbility);
243     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isNativeAbility);
244     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, enabled);
245     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, supportPipMode);
246     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, formEnabled);
247     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, configChanges.size());
248     for (auto &configChange : configChanges) {
249         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(configChange));
250     }
251     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, formEntity);
252     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, minFormHeight);
253     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, defaultFormHeight);
254     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, minFormWidth);
255     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, defaultFormWidth);
256     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, labelId);
257     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, descriptionId);
258     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, iconId);
259     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(type));
260     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(orientation));
261     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(launchMode));
262 
263     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, permissions.size());
264     for (auto &permission : permissions) {
265         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(permission));
266     }
267 
268     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceTypes.size());
269     for (auto &deviceType : deviceTypes) {
270         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceType));
271     }
272 
273     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceCapabilities.size());
274     for (auto &deviceCapability : deviceCapabilities) {
275         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceCapability));
276     }
277 
278     const auto customizeDataSize = static_cast<int32_t>(metaData.customizeData.size());
279     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, customizeDataSize);
280     for (auto i = 0; i < customizeDataSize; i++) {
281         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(metaData.customizeData[i].name));
282         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(metaData.customizeData[i].value));
283         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(metaData.customizeData[i].extra));
284     }
285 
286     const auto parametersSize = static_cast<int32_t>(metaData.parameters.size());
287     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, parametersSize);
288     for (auto i = 0; i < parametersSize; i++) {
289         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(metaData.parameters[i].description));
290         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(metaData.parameters[i].name));
291         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(metaData.parameters[i].type));
292     }
293 
294     const auto resultsSize = static_cast<int32_t>(metaData.results.size());
295     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, resultsSize);
296     for (auto i = 0; i < resultsSize; i++) {
297         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(metaData.results[i].description));
298         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(metaData.results[i].name));
299         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(metaData.results[i].type));
300     }
301 
302     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &applicationInfo);
303     return true;
304 }
305 
Dump(std::string prefix,int fd)306 void AbilityInfo::Dump(std::string prefix, int fd)
307 {
308     APP_LOGI("called dump Abilityinfo");
309     if (fd < 0) {
310         APP_LOGE("dump Abilityinfo fd error");
311         return;
312     }
313     int flags = fcntl(fd, F_GETFL);
314     if (flags < 0) {
315         APP_LOGE("dump Abilityinfo fcntl error %{public}s", strerror(errno));
316         return;
317     }
318     uint uflags = static_cast<uint>(flags);
319     uflags &= O_ACCMODE;
320     if ((uflags == O_WRONLY) || (uflags == O_RDWR)) {
321         nlohmann::json jsonObject = *this;
322         std::string result;
323         result.append(prefix);
324         result.append(jsonObject.dump(Constants::DUMP_INDENT));
325         int ret = TEMP_FAILURE_RETRY(write(fd, result.c_str(), result.size()));
326         if (ret < 0) {
327             APP_LOGE("dump Abilityinfo write error %{public}s", strerror(errno));
328         }
329     }
330     return;
331 }
332 
to_json(nlohmann::json & jsonObject,const Parameters & parameters)333 void to_json(nlohmann::json &jsonObject, const Parameters &parameters)
334 {
335     jsonObject = nlohmann::json {
336         {JSON_KEY_DESCRIPTION, parameters.description},
337         {JSON_KEY_NAME, parameters.name},
338         {JSON_KEY_TYPE, parameters.type}
339     };
340 }
341 
to_json(nlohmann::json & jsonObject,const Results & results)342 void to_json(nlohmann::json &jsonObject, const Results &results)
343 {
344     jsonObject = nlohmann::json {
345         {JSON_KEY_DESCRIPTION, results.description},
346         {JSON_KEY_NAME, results.name},
347         {JSON_KEY_TYPE, results.type}
348     };
349 }
350 
to_json(nlohmann::json & jsonObject,const CustomizeData & customizeData)351 void to_json(nlohmann::json &jsonObject, const CustomizeData &customizeData)
352 {
353     jsonObject = nlohmann::json {
354         {JSON_KEY_NAME, customizeData.name},
355         {JSON_KEY_META_VALUE, customizeData.value},
356         {JSON_KEY_META_EXTRA, customizeData.extra}
357     };
358 }
359 
to_json(nlohmann::json & jsonObject,const MetaData & metaData)360 void to_json(nlohmann::json &jsonObject, const MetaData &metaData)
361 {
362     jsonObject = nlohmann::json {
363         {JSON_KEY_PARAMETERS, metaData.parameters},
364         {JSON_KEY_RESULTS, metaData.results},
365         {JSON_KEY_CUSTOMIZE_DATA, metaData.customizeData}
366     };
367 }
368 
to_json(nlohmann::json & jsonObject,const AbilityInfo & abilityInfo)369 void to_json(nlohmann::json &jsonObject, const AbilityInfo &abilityInfo)
370 {
371     jsonObject = nlohmann::json {
372         {JSON_KEY_NAME, abilityInfo.name},
373         {JSON_KEY_LABEL, abilityInfo.label},
374         {JSON_KEY_DESCRIPTION, abilityInfo.description},
375         {JSON_KEY_ICON_PATH, abilityInfo.iconPath},
376         {JSON_KEY_THEME, abilityInfo.theme},
377         {JSON_KEY_VISIBLE, abilityInfo.visible},
378         {JSON_KEY_IS_LAUNCHER_ABILITY, abilityInfo.isLauncherAbility},
379         {JSON_KEY_IS_NATIVE_ABILITY, abilityInfo.isNativeAbility},
380         {JSON_KEY_ENABLED, abilityInfo.enabled},
381         {JSON_KEY_SUPPORT_PIP_MODE, abilityInfo.supportPipMode},
382         {JSON_KEY_READ_PERMISSION, abilityInfo.readPermission},
383         {JSON_KEY_WRITE_PERMISSION, abilityInfo.writePermission},
384         {JSON_KEY_SRC_PATH, abilityInfo.srcPath},
385         {JSON_KEY_SRC_LANGUAGE, abilityInfo.srcLanguage},
386         {JSON_KEY_CONFIG_CHANGES, abilityInfo.configChanges},
387         {JSON_KEY_FORM_ENTITY, abilityInfo.formEntity},
388         {JSON_KEY_MIN_FORM_HEIGHT, abilityInfo.minFormHeight},
389         {JSON_KEY_DEFAULT_FORM_HEIGHT, abilityInfo.defaultFormHeight},
390         {JSON_KEY_MIN_FORM_WIDTH, abilityInfo.minFormWidth},
391         {JSON_KEY_DEFAULT_FORM_WIDTH, abilityInfo.defaultFormWidth},
392         {JSON_KEY_LABEL_ID, abilityInfo.labelId},
393         {JSON_KEY_DESCRIPTION_ID, abilityInfo.descriptionId},
394         {JSON_KEY_ICON_ID, abilityInfo.iconId},
395         {JSON_KEY_KIND, abilityInfo.kind},
396         {JSON_KEY_TYPE, abilityInfo.type},
397         {JSON_KEY_ORIENTATION, abilityInfo.orientation},
398         {JSON_KEY_LAUNCH_MODE, abilityInfo.launchMode},
399         {JSON_KEY_PERMISSIONS, abilityInfo.permissions},
400         {JSON_KEY_PROCESS, abilityInfo.process},
401         {JSON_KEY_DEVICE_TYPES, abilityInfo.deviceTypes},
402         {JSON_KEY_DEVICE_CAPABILITIES, abilityInfo.deviceCapabilities},
403         {JSON_KEY_URI, abilityInfo.uri},
404         {JSON_KEY_TARGET_ABILITY, abilityInfo.targetAbility},
405         {JSON_KEY_PACKAGE, abilityInfo.package},
406         {JSON_KEY_BUNDLE_NAME, abilityInfo.bundleName},
407         {JSON_KEY_MODULE_NAME, abilityInfo.moduleName},
408         {JSON_KEY_APPLICATION_NAME, abilityInfo.applicationName},
409         {JSON_KEY_DEVICE_ID, abilityInfo.deviceId},
410         {JSON_KEY_CODE_PATH, abilityInfo.codePath},
411         {JSON_KEY_RESOURCE_PATH, abilityInfo.resourcePath},
412         {JSON_KEY_LIB_PATH, abilityInfo.libPath},
413         {JSON_KEY_META_DATA, abilityInfo.metaData},
414         {JSON_KEY_FORM_ENABLED, abilityInfo.formEnabled}
415     };
416 }
417 
from_json(const nlohmann::json & jsonObject,Parameters & parameters)418 void from_json(const nlohmann::json &jsonObject, Parameters &parameters)
419 {
420     parameters.description = jsonObject.at(JSON_KEY_DESCRIPTION).get<std::string>();
421     parameters.name = jsonObject.at(JSON_KEY_NAME).get<std::string>();
422     parameters.type = jsonObject.at(JSON_KEY_TYPE).get<std::string>();
423 }
424 
from_json(const nlohmann::json & jsonObject,Results & results)425 void from_json(const nlohmann::json &jsonObject, Results &results)
426 {
427     results.description = jsonObject.at(JSON_KEY_DESCRIPTION).get<std::string>();
428     results.name = jsonObject.at(JSON_KEY_NAME).get<std::string>();
429     results.type = jsonObject.at(JSON_KEY_TYPE).get<std::string>();
430 }
431 
from_json(const nlohmann::json & jsonObject,CustomizeData & customizeData)432 void from_json(const nlohmann::json &jsonObject, CustomizeData &customizeData)
433 {
434     customizeData.name = jsonObject.at(JSON_KEY_NAME).get<std::string>();
435     customizeData.value = jsonObject.at(JSON_KEY_META_VALUE).get<std::string>();
436     customizeData.extra = jsonObject.at(JSON_KEY_META_EXTRA).get<std::string>();
437 }
438 
from_json(const nlohmann::json & jsonObject,MetaData & metaData)439 void from_json(const nlohmann::json &jsonObject, MetaData &metaData)
440 {
441     metaData.parameters = jsonObject.at(JSON_KEY_PARAMETERS).get<std::vector<Parameters>>();
442     metaData.results = jsonObject.at(JSON_KEY_RESULTS).get<std::vector<Results>>();
443     metaData.customizeData = jsonObject.at(JSON_KEY_CUSTOMIZE_DATA).get<std::vector<CustomizeData>>();
444 }
445 
from_json(const nlohmann::json & jsonObject,AbilityInfo & abilityInfo)446 void from_json(const nlohmann::json &jsonObject, AbilityInfo &abilityInfo)
447 {
448     abilityInfo.name = jsonObject.at(JSON_KEY_NAME).get<std::string>();
449     abilityInfo.label = jsonObject.at(JSON_KEY_LABEL).get<std::string>();
450     abilityInfo.description = jsonObject.at(JSON_KEY_DESCRIPTION).get<std::string>();
451     abilityInfo.iconPath = jsonObject.at(JSON_KEY_ICON_PATH).get<std::string>();
452     abilityInfo.theme = jsonObject.at(JSON_KEY_THEME).get<std::string>();
453     abilityInfo.visible = jsonObject.at(JSON_KEY_VISIBLE).get<bool>();
454     abilityInfo.isLauncherAbility = jsonObject.at(JSON_KEY_IS_LAUNCHER_ABILITY).get<bool>();
455     abilityInfo.isNativeAbility = jsonObject.at(JSON_KEY_IS_NATIVE_ABILITY).get<bool>();
456     abilityInfo.enabled = jsonObject.at(JSON_KEY_ENABLED).get<bool>();
457     abilityInfo.supportPipMode = jsonObject.at(JSON_KEY_SUPPORT_PIP_MODE).get<bool>();
458     abilityInfo.readPermission = jsonObject.at(JSON_KEY_READ_PERMISSION).get<std::string>();
459     abilityInfo.writePermission = jsonObject.at(JSON_KEY_WRITE_PERMISSION).get<std::string>();
460     abilityInfo.srcPath = jsonObject.at(JSON_KEY_SRC_PATH).get<std::string>();
461     abilityInfo.srcLanguage = jsonObject.at(JSON_KEY_SRC_LANGUAGE).get<std::string>();
462     abilityInfo.configChanges = jsonObject.at(JSON_KEY_CONFIG_CHANGES).get<std::vector<std::string>>();
463     abilityInfo.formEntity = jsonObject.at(JSON_KEY_FORM_ENTITY).get<uint32_t>();
464     abilityInfo.minFormHeight = jsonObject.at(JSON_KEY_MIN_FORM_HEIGHT).get<int32_t>();
465     abilityInfo.defaultFormHeight = jsonObject.at(JSON_KEY_DEFAULT_FORM_HEIGHT).get<int32_t>();
466     abilityInfo.minFormWidth = jsonObject.at(JSON_KEY_MIN_FORM_WIDTH).get<int32_t>();
467     abilityInfo.defaultFormWidth = jsonObject.at(JSON_KEY_DEFAULT_FORM_WIDTH).get<int32_t>();
468     abilityInfo.labelId = jsonObject.at(JSON_KEY_LABEL_ID).get<int32_t>();
469     abilityInfo.descriptionId = jsonObject.at(JSON_KEY_DESCRIPTION_ID).get<int32_t>();
470     abilityInfo.iconId = jsonObject.at(JSON_KEY_ICON_ID).get<int32_t>();
471     abilityInfo.kind = jsonObject.at(JSON_KEY_KIND).get<std::string>();
472     abilityInfo.type = jsonObject.at(JSON_KEY_TYPE).get<AbilityType>();
473     abilityInfo.orientation = jsonObject.at(JSON_KEY_ORIENTATION).get<DisplayOrientation>();
474     abilityInfo.launchMode = jsonObject.at(JSON_KEY_LAUNCH_MODE).get<LaunchMode>();
475     abilityInfo.permissions = jsonObject.at(JSON_KEY_PERMISSIONS).get<std::vector<std::string>>();
476     abilityInfo.process = jsonObject.at(JSON_KEY_PROCESS).get<std::string>();
477     abilityInfo.deviceTypes = jsonObject.at(JSON_KEY_DEVICE_TYPES).get<std::vector<std::string>>();
478     abilityInfo.deviceCapabilities = jsonObject.at(JSON_KEY_DEVICE_CAPABILITIES).get<std::vector<std::string>>();
479     abilityInfo.uri = jsonObject.at(JSON_KEY_URI).get<std::string>();
480     abilityInfo.targetAbility = jsonObject.at(JSON_KEY_TARGET_ABILITY).get<std::string>();
481     abilityInfo.package = jsonObject.at(JSON_KEY_PACKAGE).get<std::string>();
482     abilityInfo.bundleName = jsonObject.at(JSON_KEY_BUNDLE_NAME).get<std::string>();
483     abilityInfo.moduleName = jsonObject.at(JSON_KEY_MODULE_NAME).get<std::string>();
484     abilityInfo.applicationName = jsonObject.at(JSON_KEY_APPLICATION_NAME).get<std::string>();
485     abilityInfo.deviceId = jsonObject.at(JSON_KEY_DEVICE_ID).get<std::string>();
486     abilityInfo.codePath = jsonObject.at(JSON_KEY_CODE_PATH).get<std::string>();
487     abilityInfo.resourcePath = jsonObject.at(JSON_KEY_RESOURCE_PATH).get<std::string>();
488     abilityInfo.libPath = jsonObject.at(JSON_KEY_LIB_PATH).get<std::string>();
489     abilityInfo.metaData = jsonObject.at(JSON_KEY_META_DATA).get<MetaData>();
490     abilityInfo.formEnabled = jsonObject.at(JSON_KEY_FORM_ENABLED).get<bool>();
491 }
492 
ConvertToCompatiableAbilityInfo(CompatibleAbilityInfo & compatibleAbilityInfo) const493 void AbilityInfo::ConvertToCompatiableAbilityInfo(CompatibleAbilityInfo& compatibleAbilityInfo) const
494 {
495     APP_LOGE("AbilityInfo::ConvertToCompatiableAbilityInfo called");
496     compatibleAbilityInfo.package = package;
497     compatibleAbilityInfo.name = name;
498     compatibleAbilityInfo.label = label;
499     compatibleAbilityInfo.description = description;
500     compatibleAbilityInfo.iconPath = iconPath;
501     compatibleAbilityInfo.uri = uri;
502     compatibleAbilityInfo.moduleName = moduleName;
503     compatibleAbilityInfo.process = process;
504     compatibleAbilityInfo.targetAbility = targetAbility;
505     compatibleAbilityInfo.appName = appName;
506     compatibleAbilityInfo.privacyUrl = privacyUrl;
507     compatibleAbilityInfo.privacyName = privacyName;
508     compatibleAbilityInfo.downloadUrl = downloadUrl;
509     compatibleAbilityInfo.versionName = versionName;
510     compatibleAbilityInfo.backgroundModes = backgroundModes;
511     compatibleAbilityInfo.packageSize = packageSize;
512     compatibleAbilityInfo.visible = visible;
513     compatibleAbilityInfo.formEnabled = formEnabled;
514     compatibleAbilityInfo.multiUserShared = multiUserShared;
515     compatibleAbilityInfo.type = type;
516     compatibleAbilityInfo.subType = subType;
517     compatibleAbilityInfo.orientation = orientation;
518     compatibleAbilityInfo.launchMode = launchMode;
519     compatibleAbilityInfo.permissions = permissions;
520     compatibleAbilityInfo.deviceTypes = deviceTypes;
521     compatibleAbilityInfo.deviceCapabilities = deviceCapabilities;
522     compatibleAbilityInfo.supportPipMode = supportPipMode;
523     compatibleAbilityInfo.grantPermission = grantPermission;
524     compatibleAbilityInfo.readPermission = readPermission;
525     compatibleAbilityInfo.writePermission = writePermission;
526     compatibleAbilityInfo.uriPermissionMode = uriPermissionMode;
527     compatibleAbilityInfo.uriPermissionPath = uriPermissionPath;
528     compatibleAbilityInfo.directLaunch = directLaunch;
529     compatibleAbilityInfo.bundleName = bundleName;
530     compatibleAbilityInfo.className = className;
531     compatibleAbilityInfo.originalClassName = originalClassName;
532     compatibleAbilityInfo.deviceId = deviceId;
533     CompatibleApplicationInfo convertedCompatibleApplicationInfo;
534     applicationInfo.ConvertToCompatibleApplicationInfo(convertedCompatibleApplicationInfo);
535     compatibleAbilityInfo.applicationInfo = convertedCompatibleApplicationInfo;
536     compatibleAbilityInfo.formEntity = formEntity;
537     compatibleAbilityInfo.minFormHeight = minFormHeight;
538     compatibleAbilityInfo.defaultFormHeight = defaultFormHeight;
539     compatibleAbilityInfo.minFormWidth = minFormWidth;
540     compatibleAbilityInfo.defaultFormWidth = defaultFormWidth;
541     compatibleAbilityInfo.iconId = iconId;
542     compatibleAbilityInfo.labelId = labelId;
543     compatibleAbilityInfo.descriptionId = descriptionId;
544     compatibleAbilityInfo.enabled = enabled;
545 }
546 
547 }  // namespace AppExecFwk
548 }  // namespace OHOS