1 /*
2 * Copyright (c) 2023 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 "inner_common_info.h"
17
18 #include <regex>
19 #include <unistd.h>
20 #include "string_ex.h"
21
22 #include "mime_type_mgr.h"
23 #include "parameters.h"
24
25 namespace OHOS {
26 namespace AppExecFwk {
27 namespace {
28 const std::string NAME = "name";
29 const std::string MODULE_PACKAGE = "modulePackage";
30 const std::string MODULE_PATH = "modulePath";
31 const std::string MODULE_NAME = "moduleName";
32 const std::string MODULE_DESCRIPTION = "description";
33 const std::string MODULE_DESCRIPTION_ID = "descriptionId";
34 const std::string MODULE_ICON = "icon";
35 const std::string MODULE_ICON_ID = "iconId";
36 const std::string MODULE_LABEL = "label";
37 const std::string MODULE_LABEL_ID = "labelId";
38 const std::string MODULE_DESCRIPTION_INSTALLATION_FREE = "installationFree";
39 const std::string MODULE_IS_REMOVABLE = "isRemovable";
40 const std::string MODULE_UPGRADE_FLAG = "upgradeFlag";
41 const std::string MODULE_IS_ENTRY = "isEntry";
42 const std::string MODULE_METADATA = "metaData";
43 const std::string MODULE_COLOR_MODE = "colorMode";
44 const std::string MODULE_DISTRO = "distro";
45 const std::string MODULE_REQ_CAPABILITIES = "reqCapabilities";
46 const std::string MODULE_DATA_DIR = "moduleDataDir";
47 const std::string MODULE_RES_PATH = "moduleResPath";
48 const std::string MODULE_HAP_PATH = "hapPath";
49 const std::string MODULE_ABILITY_KEYS = "abilityKeys";
50 const std::string MODULE_SKILL_KEYS = "skillKeys";
51 const std::string MODULE_MAIN_ABILITY = "mainAbility";
52 const std::string MODULE_ENTRY_ABILITY_KEY = "entryAbilityKey";
53 const std::string MODULE_DEPENDENCIES = "dependencies";
54 const std::string MODULE_IS_LIB_ISOLATED = "isLibIsolated";
55 const std::string MODULE_NATIVE_LIBRARY_PATH = "nativeLibraryPath";
56 const std::string MODULE_CPU_ABI = "cpuAbi";
57 const std::string MODULE_SRC_PATH = "srcPath";
58 const std::string MODULE_HASH_VALUE = "hashValue";
59 const std::string SCHEME_SEPARATOR = "://";
60 const std::string PORT_SEPARATOR = ":";
61 const std::string PATH_SEPARATOR = "/";
62 const std::string PARAM_SEPARATOR = "?";
63 const std::string INSTALL_MARK = "installMark";
64 const char WILDCARD = '*';
65 const std::string TYPE_WILDCARD = "*/*";
66 const std::string MODULE_PROCESS = "process";
67 const std::string MODULE_SRC_ENTRANCE = "srcEntrance";
68 const std::string MODULE_DEVICE_TYPES = "deviceTypes";
69 const std::string MODULE_VIRTUAL_MACHINE = "virtualMachine";
70 const std::string MODULE_UI_SYNTAX = "uiSyntax";
71 const std::string MODULE_PAGES = "pages";
72 const std::string MODULE_META_DATA = "metadata";
73 const std::string MODULE_REQUEST_PERMISSIONS = "requestPermissions";
74 const std::string MODULE_DEFINE_PERMISSIONS = "definePermissions";
75 const std::string MODULE_EXTENSION_KEYS = "extensionKeys";
76 const std::string MODULE_EXTENSION_SKILL_KEYS = "extensionSkillKeys";
77 const std::string MODULE_IS_MODULE_JSON = "isModuleJson";
78 const std::string MODULE_IS_STAGE_BASED_MODEL = "isStageBasedModel";
79 const std::string MODULE_COMPILE_MODE = "compileMode";
80 const std::string MODULE_TARGET_MODULE_NAME = "targetModuleName";
81 const std::string MODULE_TARGET_PRIORITY = "targetPriority";
82 const std::string MODULE_OVERLAY_MODULE_INFO = "overlayModuleInfo";
83 const std::string MODULE_PRELOADS = "preloads";
84 const std::string MODULE_BUNDLE_TYPE = "bundleType";
85 const std::string MODULE_VERSION_CODE = "versionCode";
86 const std::string MODULE_VERSION_NAME = "versionName";
87 const std::string MODULE_PROXY_DATAS = "proxyDatas";
88 const std::string MODULE_BUILD_HASH = "buildHash";
89 const std::string MODULE_ISOLATION_MODE = "isolationMode";
90 const std::string MODULE_COMPRESS_NATIVE_LIBS = "compressNativeLibs";
91 const std::string MODULE_NATIVE_LIBRARY_FILE_NAMES = "nativeLibraryFileNames";
92 const std::string MODULE_AOT_COMPILE_STATUS = "aotCompileStatus";
93 const std::string MODULE_FILE_CONTEXT_MENU = "fileContextMenu";
94 const std::string MODULE_IS_ENCRYPTED = "isEncrypted";
95 const std::string STR_PHONE = "phone";
96 const std::string STR_DEFAULT = "default";
97 } // namespace
98
Match(const OHOS::AAFwk::Want & want) const99 bool Skill::Match(const OHOS::AAFwk::Want &want) const
100 {
101 bool matchAction = MatchAction(want.GetAction());
102 if (!matchAction) {
103 APP_LOGD("Action does not match");
104 return false;
105 }
106 bool matchEntities = MatchEntities(want.GetEntities());
107 if (!matchEntities) {
108 APP_LOGD("Entities does not match");
109 return false;
110 }
111 std::vector<std::string> vecTypes;
112 auto deviceType = OHOS::system::GetDeviceType();
113 APP_LOGD("DeviceType %{public}s", deviceType.c_str());
114 if (STR_PHONE == deviceType || STR_DEFAULT == deviceType) {
115 vecTypes = want.GetStringArrayParam(OHOS::AAFwk::Want::PARAM_ABILITY_URITYPES);
116 }
117 if (vecTypes.size() > 0) {
118 for (std::string strType : vecTypes) {
119 if (MatchUriAndType(want.GetUriString(), strType)) {
120 APP_LOGD("type %{public}s, Is Matched", strType.c_str());
121 return true;
122 }
123 }
124 return false;
125 }
126 bool matchUriAndType = MatchUriAndType(want.GetUriString(), want.GetType());
127 if (!matchUriAndType) {
128 APP_LOGD("Uri or Type does not match");
129 return false;
130 }
131 return true;
132 }
133
MatchLauncher(const OHOS::AAFwk::Want & want) const134 bool Skill::MatchLauncher(const OHOS::AAFwk::Want &want) const
135 {
136 bool matchAction = MatchAction(want.GetAction());
137 if (!matchAction) {
138 APP_LOGD("Action does not match");
139 return false;
140 }
141 bool matchEntities = MatchEntities(want.GetEntities());
142 if (!matchEntities) {
143 APP_LOGD("Entities does not match");
144 return false;
145 }
146 return true;
147 }
148
MatchAction(const std::string & action) const149 bool Skill::MatchAction(const std::string &action) const
150 {
151 // config actions empty, no match
152 if (actions.empty()) {
153 return false;
154 }
155 // config actions not empty, param empty, match
156 if (action.empty()) {
157 return true;
158 }
159 auto actionMatcher = [action] (const std::string &configAction) {
160 if (action == configAction) {
161 return true;
162 }
163 if (action == Constants::ACTION_HOME && configAction == Constants::WANT_ACTION_HOME) {
164 return true;
165 }
166 if (action == Constants::WANT_ACTION_HOME && configAction == Constants::ACTION_HOME) {
167 return true;
168 }
169 return false;
170 };
171 // config actions not empty, param not empty, if config actions contains param action, match
172 return std::find_if(actions.cbegin(), actions.cend(), actionMatcher) != actions.cend();
173 }
174
MatchEntities(const std::vector<std::string> & paramEntities) const175 bool Skill::MatchEntities(const std::vector<std::string> ¶mEntities) const
176 {
177 // param entities empty, match
178 if (paramEntities.empty()) {
179 return true;
180 }
181 // config entities empty, param entities not empty, not match
182 if (entities.empty()) {
183 return false;
184 }
185 // config entities not empty, param entities not empty, if every param entity in config entities, match
186 std::vector<std::string>::size_type size = paramEntities.size();
187 for (std::vector<std::string>::size_type i = 0; i < size; i++) {
188 bool ret = std::find(entities.cbegin(), entities.cend(), paramEntities[i]) == entities.cend();
189 if (ret) {
190 return false;
191 }
192 }
193 return true;
194 }
195
MatchUriAndType(const std::string & uriString,const std::string & type) const196 bool Skill::MatchUriAndType(const std::string &uriString, const std::string &type) const
197 {
198 if (uriString.empty() && type.empty()) {
199 // case1 : param uri empty, param type empty
200 if (uris.empty()) {
201 return true;
202 }
203 for (const SkillUri &skillUri : uris) {
204 if (skillUri.scheme.empty() && skillUri.type.empty()) {
205 return true;
206 }
207 }
208 return false;
209 }
210 if (uris.empty()) {
211 return false;
212 }
213 if (!uriString.empty() && type.empty()) {
214 // case2 : param uri not empty, param type empty
215 for (const SkillUri &skillUri : uris) {
216 if (MatchUri(uriString, skillUri) && skillUri.type.empty()) {
217 return true;
218 }
219 }
220 // if uri is a file path, match type by the suffix
221 return MatchMimeType(uriString);
222 } else if (uriString.empty() && !type.empty()) {
223 // case3 : param uri empty, param type not empty
224 for (const SkillUri &skillUri : uris) {
225 if (skillUri.scheme.empty() && MatchType(type, skillUri.type)) {
226 return true;
227 }
228 }
229 return false;
230 } else {
231 // case4 : param uri not empty, param type not empty
232 for (const SkillUri &skillUri : uris) {
233 if (MatchUri(uriString, skillUri) && MatchType(type, skillUri.type)) {
234 return true;
235 }
236 }
237 return false;
238 }
239 }
240
StartsWith(const std::string & sourceString,const std::string & targetPrefix) const241 bool Skill::StartsWith(const std::string &sourceString, const std::string &targetPrefix) const
242 {
243 return sourceString.rfind(targetPrefix, 0) == 0;
244 }
245
GetOptParamUri(const std::string & uriString) const246 std::string Skill::GetOptParamUri(const std::string &uriString) const
247 {
248 std::size_t pos = uriString.rfind(PARAM_SEPARATOR);
249 if (pos == std::string::npos) {
250 return uriString;
251 }
252 return uriString.substr(0, pos);
253 }
254
MatchUri(const std::string & uriString,const SkillUri & skillUri) const255 bool Skill::MatchUri(const std::string &uriString, const SkillUri &skillUri) const
256 {
257 if (skillUri.scheme.empty()) {
258 return uriString.empty();
259 }
260 if (skillUri.host.empty()) {
261 // config uri is : scheme
262 // belows are param uri matched conditions:
263 // 1.scheme
264 // 2.scheme:
265 // 3.scheme:/
266 // 4.scheme://
267 return uriString == skillUri.scheme || StartsWith(uriString, skillUri.scheme + PORT_SEPARATOR);
268 }
269 std::string optParamUri = GetOptParamUri(uriString);
270 std::string skillUriString;
271 skillUriString.append(skillUri.scheme).append(SCHEME_SEPARATOR).append(skillUri.host);
272 if (!skillUri.port.empty()) {
273 skillUriString.append(PORT_SEPARATOR).append(skillUri.port);
274 }
275 if (skillUri.path.empty() && skillUri.pathStartWith.empty() && skillUri.pathRegex.empty()) {
276 // with port, config uri is : scheme://host:port
277 // belows are param uri matched conditions:
278 // 1.scheme://host:port
279 // 2.scheme://host:port/path
280
281 // without port, config uri is : scheme://host
282 // belows are param uri matched conditions:
283 // 1.scheme://host
284 // 2.scheme://host/path
285 // 3.scheme://host:port scheme://host:port/path
286 bool ret = (optParamUri == skillUriString || StartsWith(optParamUri, skillUriString + PATH_SEPARATOR));
287 if (skillUri.port.empty()) {
288 ret = ret || StartsWith(optParamUri, skillUriString + PORT_SEPARATOR);
289 }
290 return ret;
291 }
292 skillUriString.append(PATH_SEPARATOR);
293 // if one of path, pathStartWith, pathRegex match, then match
294 if (!skillUri.path.empty()) {
295 // path match
296 std::string pathUri(skillUriString);
297 pathUri.append(skillUri.path);
298 if (optParamUri == pathUri) {
299 return true;
300 }
301 }
302 if (!skillUri.pathStartWith.empty()) {
303 // pathStartWith match
304 std::string pathStartWithUri(skillUriString);
305 pathStartWithUri.append(skillUri.pathStartWith);
306 if (StartsWith(optParamUri, pathStartWithUri)) {
307 return true;
308 }
309 }
310 if (!skillUri.pathRegex.empty()) {
311 // pathRegex match
312 std::string pathRegexUri(skillUriString);
313 pathRegexUri.append(skillUri.pathRegex);
314 try {
315 std::regex regex(pathRegexUri);
316 if (regex_match(optParamUri, regex)) {
317 return true;
318 }
319 } catch(...) {
320 APP_LOGE("regex error");
321 }
322 }
323 return false;
324 }
325
MatchType(const std::string & type,const std::string & skillUriType) const326 bool Skill::MatchType(const std::string &type, const std::string &skillUriType) const
327 {
328 // type is not empty
329 if (skillUriType.empty()) {
330 return false;
331 }
332 // only match */*
333 if (type == Constants::TYPE_ONLY_MATCH_WILDCARD) {
334 return skillUriType == TYPE_WILDCARD;
335 }
336 if (type == TYPE_WILDCARD || skillUriType == TYPE_WILDCARD) {
337 // param is */* or config is */*
338 return true;
339 }
340 bool paramTypeRegex = type.back() == WILDCARD;
341 if (paramTypeRegex) {
342 // param is string/*
343 std::string prefix = type.substr(0, type.length() - 1);
344 return skillUriType.find(prefix) == 0;
345 }
346 bool typeRegex = skillUriType.back() == WILDCARD;
347 if (typeRegex) {
348 // config is string/*
349 std::string prefix = skillUriType.substr(0, skillUriType.length() - 1);
350 return type.find(prefix) == 0;
351 } else {
352 return type == skillUriType;
353 }
354 }
355
MatchMimeType(const std::string & uriString) const356 bool Skill::MatchMimeType(const std::string & uriString) const
357 {
358 std::vector<std::string> mimeTypes;
359 bool ret = MimeTypeMgr::GetMimeTypeByUri(uriString, mimeTypes);
360 if (!ret) {
361 return false;
362 }
363 for (const SkillUri &skillUri : uris) {
364 for (const auto &mimeType : mimeTypes) {
365 if ((MatchUri(uriString, skillUri) ||
366 (skillUri.scheme.empty() && uriString.find(SCHEME_SEPARATOR) == std::string::npos)) &&
367 MatchType(mimeType, skillUri.type)) {
368 return true;
369 }
370 }
371 }
372 return false;
373 }
374
MatchUtd(const std::string & utd,int32_t count) const375 bool Skill::MatchUtd(const std::string &utd, int32_t count) const
376 {
377 for (const SkillUri &skillUri : uris) {
378 if (skillUri.maxFileSupported < count) {
379 APP_LOGD("exceeds limit");
380 continue;
381 }
382 if (!skillUri.utd.empty()) {
383 if (MimeTypeMgr::MatchUtd(skillUri.utd, utd)) {
384 return true;
385 }
386 } else {
387 if (MimeTypeMgr::MatchTypeWithUtd(skillUri.type, utd)) {
388 return true;
389 }
390 }
391 }
392 return false;
393 }
394
to_json(nlohmann::json & jsonObject,const Distro & distro)395 void to_json(nlohmann::json &jsonObject, const Distro &distro)
396 {
397 jsonObject = nlohmann::json {
398 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, distro.deliveryWithInstall},
399 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME, distro.moduleName},
400 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE, distro.moduleType},
401 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, distro.installationFree}
402 };
403 }
404
to_json(nlohmann::json & jsonObject,const DefinePermission & definePermission)405 void to_json(nlohmann::json &jsonObject, const DefinePermission &definePermission)
406 {
407 jsonObject = nlohmann::json {
408 {Profile::DEFINEPERMISSION_NAME, definePermission.name},
409 {Profile::DEFINEPERMISSION_GRANT_MODE, definePermission.grantMode},
410 {Profile::DEFINEPERMISSION_AVAILABLE_LEVEL, definePermission.availableLevel},
411 {Profile::DEFINEPERMISSION_PROVISION_ENABLE, definePermission.provisionEnable},
412 {Profile::DEFINEPERMISSION_DISTRIBUTED_SCENE_ENABLE, definePermission.distributedSceneEnable},
413 {Profile::LABEL, definePermission.label},
414 {Profile::LABEL_ID, definePermission.labelId},
415 {Profile::DESCRIPTION, definePermission.description},
416 {Profile::DESCRIPTION_ID, definePermission.descriptionId},
417 {Profile::DEFINEPERMISSION_AVAILABLE_TYPE, definePermission.availableType}
418 };
419 }
420
to_json(nlohmann::json & jsonObject,const Dependency & dependency)421 void to_json(nlohmann::json &jsonObject, const Dependency &dependency)
422 {
423 jsonObject = nlohmann::json {
424 {Profile::DEPENDENCIES_MODULE_NAME, dependency.moduleName},
425 {Profile::DEPENDENCIES_BUNDLE_NAME, dependency.bundleName},
426 {Profile::APP_VERSION_CODE, dependency.versionCode}
427 };
428 }
429
to_json(nlohmann::json & jsonObject,const InnerModuleInfo & info)430 void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info)
431 {
432 jsonObject = nlohmann::json {
433 {NAME, info.name},
434 {MODULE_PACKAGE, info.modulePackage},
435 {MODULE_NAME, info.moduleName},
436 {MODULE_PATH, info.modulePath},
437 {MODULE_DATA_DIR, info.moduleDataDir},
438 {MODULE_RES_PATH, info.moduleResPath},
439 {MODULE_IS_ENTRY, info.isEntry},
440 {MODULE_METADATA, info.metaData},
441 {MODULE_COLOR_MODE, info.colorMode},
442 {MODULE_DISTRO, info.distro},
443 {MODULE_DESCRIPTION, info.description},
444 {MODULE_DESCRIPTION_ID, info.descriptionId},
445 {MODULE_ICON, info.icon},
446 {MODULE_ICON_ID, info.iconId},
447 {MODULE_LABEL, info.label},
448 {MODULE_LABEL_ID, info.labelId},
449 {MODULE_DESCRIPTION_INSTALLATION_FREE, info.installationFree},
450 {MODULE_IS_REMOVABLE, info.isRemovable},
451 {MODULE_UPGRADE_FLAG, info.upgradeFlag},
452 {MODULE_REQ_CAPABILITIES, info.reqCapabilities},
453 {MODULE_ABILITY_KEYS, info.abilityKeys},
454 {MODULE_SKILL_KEYS, info.skillKeys},
455 {MODULE_MAIN_ABILITY, info.mainAbility},
456 {MODULE_ENTRY_ABILITY_KEY, info.entryAbilityKey},
457 {MODULE_SRC_PATH, info.srcPath},
458 {MODULE_HASH_VALUE, info.hashValue},
459 {MODULE_PROCESS, info.process},
460 {MODULE_SRC_ENTRANCE, info.srcEntrance},
461 {MODULE_DEVICE_TYPES, info.deviceTypes},
462 {MODULE_VIRTUAL_MACHINE, info.virtualMachine},
463 {MODULE_UI_SYNTAX, info.uiSyntax},
464 {MODULE_PAGES, info.pages},
465 {MODULE_META_DATA, info.metadata},
466 {MODULE_REQUEST_PERMISSIONS, info.requestPermissions},
467 {MODULE_DEFINE_PERMISSIONS, info.definePermissions},
468 {MODULE_EXTENSION_KEYS, info.extensionKeys},
469 {MODULE_EXTENSION_SKILL_KEYS, info.extensionSkillKeys},
470 {MODULE_IS_MODULE_JSON, info.isModuleJson},
471 {MODULE_IS_STAGE_BASED_MODEL, info.isStageBasedModel},
472 {MODULE_DEPENDENCIES, info.dependencies},
473 {MODULE_IS_LIB_ISOLATED, info.isLibIsolated},
474 {MODULE_NATIVE_LIBRARY_PATH, info.nativeLibraryPath},
475 {MODULE_CPU_ABI, info.cpuAbi},
476 {MODULE_HAP_PATH, info.hapPath},
477 {MODULE_COMPILE_MODE, info.compileMode},
478 {MODULE_TARGET_MODULE_NAME, info.targetModuleName},
479 {MODULE_TARGET_PRIORITY, info.targetPriority},
480 {MODULE_OVERLAY_MODULE_INFO, info.overlayModuleInfo},
481 {MODULE_PRELOADS, info.preloads},
482 {MODULE_BUNDLE_TYPE, info.bundleType},
483 {MODULE_VERSION_CODE, info.versionCode},
484 {MODULE_VERSION_NAME, info.versionName},
485 {MODULE_PROXY_DATAS, info.proxyDatas},
486 {MODULE_BUILD_HASH, info.buildHash},
487 {MODULE_ISOLATION_MODE, info.isolationMode},
488 {MODULE_COMPRESS_NATIVE_LIBS, info.compressNativeLibs},
489 {MODULE_NATIVE_LIBRARY_FILE_NAMES, info.nativeLibraryFileNames},
490 {MODULE_AOT_COMPILE_STATUS, info.aotCompileStatus},
491 {MODULE_FILE_CONTEXT_MENU, info.fileContextMenu},
492 {MODULE_IS_ENCRYPTED, info.isEncrypted},
493 };
494 }
495
to_json(nlohmann::json & jsonObject,const SkillUri & uri)496 void to_json(nlohmann::json &jsonObject, const SkillUri &uri)
497 {
498 jsonObject = nlohmann::json {
499 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_SCHEME, uri.scheme},
500 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_HOST, uri.host},
501 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PORT, uri.port},
502 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATH, uri.path},
503 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHSTARTWITH, uri.pathStartWith},
504 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGEX, uri.pathRegex},
505 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_TYPE, uri.type},
506 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_UTD, uri.utd},
507 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MAX_FILE_SUPPORTED, uri.maxFileSupported},
508 };
509 }
510
to_json(nlohmann::json & jsonObject,const Skill & skill)511 void to_json(nlohmann::json &jsonObject, const Skill &skill)
512 {
513 jsonObject = nlohmann::json {
514 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ACTIONS, skill.actions},
515 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ENTITIES, skill.entities},
516 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_URIS, skill.uris}
517 };
518 }
519
to_json(nlohmann::json & jsonObject,const InstallMark & installMark)520 void to_json(nlohmann::json &jsonObject, const InstallMark &installMark)
521 {
522 jsonObject = nlohmann::json {
523 {ProfileReader::BUNDLE_INSTALL_MARK_BUNDLE, installMark.bundleName},
524 {ProfileReader::BUNDLE_INSTALL_MARK_PACKAGE, installMark.packageName},
525 {ProfileReader::BUNDLE_INSTALL_MARK_STATUS, installMark.status}
526 };
527 }
528
from_json(const nlohmann::json & jsonObject,InnerModuleInfo & info)529 void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info)
530 {
531 // these are not required fields.
532 const auto &jsonObjectEnd = jsonObject.end();
533 int32_t parseResult = ERR_OK;
534 GetValueIfFindKey<std::string>(jsonObject,
535 jsonObjectEnd,
536 NAME,
537 info.name,
538 JsonType::STRING,
539 false,
540 parseResult,
541 ArrayType::NOT_ARRAY);
542 GetValueIfFindKey<std::string>(jsonObject,
543 jsonObjectEnd,
544 MODULE_PACKAGE,
545 info.modulePackage,
546 JsonType::STRING,
547 false,
548 parseResult,
549 ArrayType::NOT_ARRAY);
550 GetValueIfFindKey<std::string>(jsonObject,
551 jsonObjectEnd,
552 MODULE_NAME,
553 info.moduleName,
554 JsonType::STRING,
555 false,
556 parseResult,
557 ArrayType::NOT_ARRAY);
558 GetValueIfFindKey<std::string>(jsonObject,
559 jsonObjectEnd,
560 MODULE_PATH,
561 info.modulePath,
562 JsonType::STRING,
563 false,
564 parseResult,
565 ArrayType::NOT_ARRAY);
566 GetValueIfFindKey<std::string>(jsonObject,
567 jsonObjectEnd,
568 MODULE_DATA_DIR,
569 info.moduleDataDir,
570 JsonType::STRING,
571 false,
572 parseResult,
573 ArrayType::NOT_ARRAY);
574 GetValueIfFindKey<std::string>(jsonObject,
575 jsonObjectEnd,
576 MODULE_HAP_PATH,
577 info.hapPath,
578 JsonType::STRING,
579 false,
580 parseResult,
581 ArrayType::NOT_ARRAY);
582 GetValueIfFindKey<std::string>(jsonObject,
583 jsonObjectEnd,
584 MODULE_RES_PATH,
585 info.moduleResPath,
586 JsonType::STRING,
587 false,
588 parseResult,
589 ArrayType::NOT_ARRAY);
590 GetValueIfFindKey<bool>(jsonObject,
591 jsonObjectEnd,
592 MODULE_IS_ENTRY,
593 info.isEntry,
594 JsonType::BOOLEAN,
595 false,
596 parseResult,
597 ArrayType::NOT_ARRAY);
598 GetValueIfFindKey<MetaData>(jsonObject,
599 jsonObjectEnd,
600 MODULE_METADATA,
601 info.metaData,
602 JsonType::OBJECT,
603 false,
604 parseResult,
605 ArrayType::NOT_ARRAY);
606 GetValueIfFindKey<ModuleColorMode>(jsonObject,
607 jsonObjectEnd,
608 MODULE_COLOR_MODE,
609 info.colorMode,
610 JsonType::NUMBER,
611 false,
612 parseResult,
613 ArrayType::NOT_ARRAY);
614 GetValueIfFindKey<Distro>(jsonObject,
615 jsonObjectEnd,
616 MODULE_DISTRO,
617 info.distro,
618 JsonType::OBJECT,
619 false,
620 parseResult,
621 ArrayType::NOT_ARRAY);
622 GetValueIfFindKey<std::string>(jsonObject,
623 jsonObjectEnd,
624 MODULE_DESCRIPTION,
625 info.description,
626 JsonType::STRING,
627 false,
628 parseResult,
629 ArrayType::NOT_ARRAY);
630 GetValueIfFindKey<int32_t>(jsonObject,
631 jsonObjectEnd,
632 MODULE_DESCRIPTION_ID,
633 info.descriptionId,
634 JsonType::NUMBER,
635 false,
636 parseResult,
637 ArrayType::NOT_ARRAY);
638 GetValueIfFindKey<std::string>(jsonObject,
639 jsonObjectEnd,
640 MODULE_ICON,
641 info.icon,
642 JsonType::STRING,
643 false,
644 parseResult,
645 ArrayType::NOT_ARRAY);
646 GetValueIfFindKey<int32_t>(jsonObject,
647 jsonObjectEnd,
648 MODULE_ICON_ID,
649 info.iconId,
650 JsonType::NUMBER,
651 false,
652 parseResult,
653 ArrayType::NOT_ARRAY);
654 GetValueIfFindKey<std::string>(jsonObject,
655 jsonObjectEnd,
656 MODULE_LABEL,
657 info.label,
658 JsonType::STRING,
659 false,
660 parseResult,
661 ArrayType::NOT_ARRAY);
662 GetValueIfFindKey<int32_t>(jsonObject,
663 jsonObjectEnd,
664 MODULE_LABEL_ID,
665 info.labelId,
666 JsonType::NUMBER,
667 false,
668 parseResult,
669 ArrayType::NOT_ARRAY);
670 GetValueIfFindKey<std::string>(jsonObject,
671 jsonObjectEnd,
672 MODULE_MAIN_ABILITY,
673 info.mainAbility,
674 JsonType::STRING,
675 false,
676 parseResult,
677 ArrayType::NOT_ARRAY);
678 GetValueIfFindKey<std::string>(jsonObject,
679 jsonObjectEnd,
680 MODULE_ENTRY_ABILITY_KEY,
681 info.entryAbilityKey,
682 JsonType::STRING,
683 false,
684 parseResult,
685 ArrayType::NOT_ARRAY);
686 GetValueIfFindKey<std::string>(jsonObject,
687 jsonObjectEnd,
688 MODULE_SRC_PATH,
689 info.srcPath,
690 JsonType::STRING,
691 false,
692 parseResult,
693 ArrayType::NOT_ARRAY);
694 GetValueIfFindKey<std::string>(jsonObject,
695 jsonObjectEnd,
696 MODULE_HASH_VALUE,
697 info.hashValue,
698 JsonType::STRING,
699 false,
700 parseResult,
701 ArrayType::NOT_ARRAY);
702 GetValueIfFindKey<bool>(jsonObject,
703 jsonObjectEnd,
704 MODULE_DESCRIPTION_INSTALLATION_FREE,
705 info.installationFree,
706 JsonType::BOOLEAN,
707 false,
708 parseResult,
709 ArrayType::NOT_ARRAY);
710 GetValueIfFindKey<std::map<std::string, bool>>(jsonObject,
711 jsonObjectEnd,
712 MODULE_IS_REMOVABLE,
713 info.isRemovable,
714 JsonType::OBJECT,
715 false,
716 parseResult,
717 ArrayType::NOT_ARRAY);
718 GetValueIfFindKey<int32_t>(jsonObject,
719 jsonObjectEnd,
720 MODULE_UPGRADE_FLAG,
721 info.upgradeFlag,
722 JsonType::NUMBER,
723 false,
724 parseResult,
725 ArrayType::NOT_ARRAY);
726 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
727 jsonObjectEnd,
728 MODULE_REQ_CAPABILITIES,
729 info.reqCapabilities,
730 JsonType::ARRAY,
731 false,
732 parseResult,
733 ArrayType::STRING);
734 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
735 jsonObjectEnd,
736 MODULE_ABILITY_KEYS,
737 info.abilityKeys,
738 JsonType::ARRAY,
739 false,
740 parseResult,
741 ArrayType::STRING);
742 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
743 jsonObjectEnd,
744 MODULE_SKILL_KEYS,
745 info.skillKeys,
746 JsonType::ARRAY,
747 false,
748 parseResult,
749 ArrayType::STRING);
750 GetValueIfFindKey<std::string>(jsonObject,
751 jsonObjectEnd,
752 MODULE_PROCESS,
753 info.process,
754 JsonType::STRING,
755 false,
756 parseResult,
757 ArrayType::NOT_ARRAY);
758 GetValueIfFindKey<std::string>(jsonObject,
759 jsonObjectEnd,
760 MODULE_SRC_ENTRANCE,
761 info.srcEntrance,
762 JsonType::STRING,
763 false,
764 parseResult,
765 ArrayType::NOT_ARRAY);
766 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
767 jsonObjectEnd,
768 MODULE_DEVICE_TYPES,
769 info.deviceTypes,
770 JsonType::ARRAY,
771 false,
772 parseResult,
773 ArrayType::STRING);
774 GetValueIfFindKey<std::string>(jsonObject,
775 jsonObjectEnd,
776 MODULE_VIRTUAL_MACHINE,
777 info.virtualMachine,
778 JsonType::STRING,
779 false,
780 parseResult,
781 ArrayType::NOT_ARRAY);
782 GetValueIfFindKey<std::string>(jsonObject,
783 jsonObjectEnd,
784 MODULE_UI_SYNTAX,
785 info.uiSyntax,
786 JsonType::STRING,
787 false,
788 parseResult,
789 ArrayType::NOT_ARRAY);
790 GetValueIfFindKey<std::string>(jsonObject,
791 jsonObjectEnd,
792 MODULE_PAGES,
793 info.pages,
794 JsonType::STRING,
795 false,
796 parseResult,
797 ArrayType::NOT_ARRAY);
798 GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
799 jsonObjectEnd,
800 MODULE_META_DATA,
801 info.metadata,
802 JsonType::ARRAY,
803 false,
804 parseResult,
805 ArrayType::OBJECT);
806 GetValueIfFindKey<std::vector<RequestPermission>>(jsonObject,
807 jsonObjectEnd,
808 MODULE_REQUEST_PERMISSIONS,
809 info.requestPermissions,
810 JsonType::ARRAY,
811 false,
812 parseResult,
813 ArrayType::OBJECT);
814 GetValueIfFindKey<std::vector<DefinePermission>>(jsonObject,
815 jsonObjectEnd,
816 MODULE_DEFINE_PERMISSIONS,
817 info.definePermissions,
818 JsonType::ARRAY,
819 false,
820 parseResult,
821 ArrayType::OBJECT);
822 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
823 jsonObjectEnd,
824 MODULE_EXTENSION_KEYS,
825 info.extensionKeys,
826 JsonType::ARRAY,
827 false,
828 parseResult,
829 ArrayType::STRING);
830 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
831 jsonObjectEnd,
832 MODULE_EXTENSION_SKILL_KEYS,
833 info.extensionSkillKeys,
834 JsonType::ARRAY,
835 false,
836 parseResult,
837 ArrayType::STRING);
838 GetValueIfFindKey<bool>(jsonObject,
839 jsonObjectEnd,
840 MODULE_IS_MODULE_JSON,
841 info.isModuleJson,
842 JsonType::BOOLEAN,
843 false,
844 parseResult,
845 ArrayType::NOT_ARRAY);
846 GetValueIfFindKey<bool>(jsonObject,
847 jsonObjectEnd,
848 MODULE_IS_STAGE_BASED_MODEL,
849 info.isStageBasedModel,
850 JsonType::BOOLEAN,
851 false,
852 parseResult,
853 ArrayType::NOT_ARRAY);
854 GetValueIfFindKey<std::vector<Dependency>>(jsonObject,
855 jsonObjectEnd,
856 MODULE_DEPENDENCIES,
857 info.dependencies,
858 JsonType::ARRAY,
859 false,
860 parseResult,
861 ArrayType::OBJECT);
862 GetValueIfFindKey<std::string>(jsonObject,
863 jsonObjectEnd,
864 MODULE_COMPILE_MODE,
865 info.compileMode,
866 JsonType::STRING,
867 false,
868 parseResult,
869 ArrayType::NOT_ARRAY);
870 GetValueIfFindKey<bool>(jsonObject,
871 jsonObjectEnd,
872 MODULE_IS_LIB_ISOLATED,
873 info.isLibIsolated,
874 JsonType::BOOLEAN,
875 false,
876 parseResult,
877 ArrayType::NOT_ARRAY);
878 GetValueIfFindKey<std::string>(jsonObject,
879 jsonObjectEnd,
880 MODULE_NATIVE_LIBRARY_PATH,
881 info.nativeLibraryPath,
882 JsonType::STRING,
883 false,
884 parseResult,
885 ArrayType::NOT_ARRAY);
886 GetValueIfFindKey<std::string>(jsonObject,
887 jsonObjectEnd,
888 MODULE_CPU_ABI,
889 info.cpuAbi,
890 JsonType::STRING,
891 false,
892 parseResult,
893 ArrayType::NOT_ARRAY);
894 GetValueIfFindKey<std::string>(jsonObject,
895 jsonObjectEnd,
896 MODULE_TARGET_MODULE_NAME,
897 info.targetModuleName,
898 JsonType::STRING,
899 false,
900 parseResult,
901 ArrayType::NOT_ARRAY);
902 GetValueIfFindKey<int32_t>(jsonObject,
903 jsonObjectEnd,
904 MODULE_TARGET_PRIORITY,
905 info.targetPriority,
906 JsonType::NUMBER,
907 false,
908 parseResult,
909 ArrayType::NOT_ARRAY);
910 GetValueIfFindKey<std::vector<OverlayModuleInfo>>(jsonObject,
911 jsonObjectEnd,
912 MODULE_OVERLAY_MODULE_INFO,
913 info.overlayModuleInfo,
914 JsonType::ARRAY,
915 false,
916 parseResult,
917 ArrayType::OBJECT);
918 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
919 jsonObjectEnd,
920 MODULE_PRELOADS,
921 info.preloads,
922 JsonType::ARRAY,
923 false,
924 parseResult,
925 ArrayType::STRING);
926 GetValueIfFindKey<BundleType>(jsonObject,
927 jsonObjectEnd,
928 MODULE_BUNDLE_TYPE,
929 info.bundleType,
930 JsonType::NUMBER,
931 false,
932 parseResult,
933 ArrayType::NOT_ARRAY);
934 GetValueIfFindKey<uint32_t>(jsonObject,
935 jsonObjectEnd,
936 MODULE_VERSION_CODE,
937 info.versionCode,
938 JsonType::NUMBER,
939 false,
940 parseResult,
941 ArrayType::NOT_ARRAY);
942 GetValueIfFindKey<std::string>(jsonObject,
943 jsonObjectEnd,
944 MODULE_VERSION_NAME,
945 info.versionName,
946 JsonType::STRING,
947 false,
948 parseResult,
949 ArrayType::NOT_ARRAY);
950 GetValueIfFindKey<std::vector<ProxyData>>(jsonObject,
951 jsonObjectEnd,
952 MODULE_PROXY_DATAS,
953 info.proxyDatas,
954 JsonType::ARRAY,
955 false,
956 parseResult,
957 ArrayType::OBJECT);
958 GetValueIfFindKey<std::string>(jsonObject,
959 jsonObjectEnd,
960 MODULE_BUILD_HASH,
961 info.buildHash,
962 JsonType::STRING,
963 false,
964 parseResult,
965 ArrayType::NOT_ARRAY);
966 GetValueIfFindKey<std::string>(jsonObject,
967 jsonObjectEnd,
968 MODULE_ISOLATION_MODE,
969 info.isolationMode,
970 JsonType::STRING,
971 false,
972 parseResult,
973 ArrayType::NOT_ARRAY);
974 GetValueIfFindKey<bool>(jsonObject,
975 jsonObjectEnd,
976 MODULE_COMPRESS_NATIVE_LIBS,
977 info.compressNativeLibs,
978 JsonType::BOOLEAN,
979 false,
980 parseResult,
981 ArrayType::NOT_ARRAY);
982 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
983 jsonObjectEnd,
984 MODULE_NATIVE_LIBRARY_FILE_NAMES,
985 info.nativeLibraryFileNames,
986 JsonType::ARRAY,
987 false,
988 parseResult,
989 ArrayType::STRING);
990 GetValueIfFindKey<AOTCompileStatus>(jsonObject,
991 jsonObjectEnd,
992 MODULE_AOT_COMPILE_STATUS,
993 info.aotCompileStatus,
994 JsonType::NUMBER,
995 false,
996 parseResult,
997 ArrayType::NOT_ARRAY);
998 GetValueIfFindKey<std::string>(jsonObject,
999 jsonObjectEnd,
1000 MODULE_FILE_CONTEXT_MENU,
1001 info.fileContextMenu,
1002 JsonType::STRING,
1003 false,
1004 parseResult,
1005 ArrayType::NOT_ARRAY);
1006 GetValueIfFindKey<bool>(jsonObject,
1007 jsonObjectEnd,
1008 MODULE_IS_ENCRYPTED,
1009 info.isEncrypted,
1010 JsonType::BOOLEAN,
1011 false,
1012 parseResult,
1013 ArrayType::NOT_ARRAY);
1014 if (parseResult != ERR_OK) {
1015 APP_LOGE("read InnerModuleInfo from database error, error code : %{public}d", parseResult);
1016 }
1017 }
1018
from_json(const nlohmann::json & jsonObject,SkillUri & uri)1019 void from_json(const nlohmann::json &jsonObject, SkillUri &uri)
1020 {
1021 // these are required fields.
1022 const auto &jsonObjectEnd = jsonObject.end();
1023 int32_t parseResult = ERR_OK;
1024 GetValueIfFindKey<std::string>(jsonObject,
1025 jsonObjectEnd,
1026 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_SCHEME,
1027 uri.scheme,
1028 JsonType::STRING,
1029 false,
1030 parseResult,
1031 ArrayType::NOT_ARRAY);
1032 // these are not required fields.
1033 GetValueIfFindKey<std::string>(jsonObject,
1034 jsonObjectEnd,
1035 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_HOST,
1036 uri.host,
1037 JsonType::STRING,
1038 false,
1039 parseResult,
1040 ArrayType::NOT_ARRAY);
1041 GetValueIfFindKey<std::string>(jsonObject,
1042 jsonObjectEnd,
1043 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PORT,
1044 uri.port,
1045 JsonType::STRING,
1046 false,
1047 parseResult,
1048 ArrayType::NOT_ARRAY);
1049 GetValueIfFindKey<std::string>(jsonObject,
1050 jsonObjectEnd,
1051 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATH,
1052 uri.path,
1053 JsonType::STRING,
1054 false,
1055 parseResult,
1056 ArrayType::NOT_ARRAY);
1057 GetValueIfFindKey<std::string>(jsonObject,
1058 jsonObjectEnd,
1059 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHSTARTWITH,
1060 uri.pathStartWith,
1061 JsonType::STRING,
1062 false,
1063 parseResult,
1064 ArrayType::NOT_ARRAY);
1065 GetValueIfFindKey<std::string>(jsonObject,
1066 jsonObjectEnd,
1067 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGX,
1068 uri.pathRegex,
1069 JsonType::STRING,
1070 false,
1071 parseResult,
1072 ArrayType::NOT_ARRAY);
1073 GetValueIfFindKey<std::string>(jsonObject,
1074 jsonObjectEnd,
1075 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGEX,
1076 uri.pathRegex,
1077 JsonType::STRING,
1078 false,
1079 parseResult,
1080 ArrayType::NOT_ARRAY);
1081 GetValueIfFindKey<std::string>(jsonObject,
1082 jsonObjectEnd,
1083 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_TYPE,
1084 uri.type,
1085 JsonType::STRING,
1086 false,
1087 parseResult,
1088 ArrayType::NOT_ARRAY);
1089 GetValueIfFindKey<std::string>(jsonObject,
1090 jsonObjectEnd,
1091 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_UTD,
1092 uri.utd,
1093 JsonType::STRING,
1094 false,
1095 parseResult,
1096 ArrayType::NOT_ARRAY);
1097 GetValueIfFindKey<int32_t>(jsonObject,
1098 jsonObjectEnd,
1099 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MAX_FILE_SUPPORTED,
1100 uri.maxFileSupported,
1101 JsonType::NUMBER,
1102 false,
1103 parseResult,
1104 ArrayType::NOT_ARRAY);
1105 if (parseResult != ERR_OK) {
1106 APP_LOGE("SkillUri from_json error, error code : %{public}d", parseResult);
1107 }
1108 }
1109
from_json(const nlohmann::json & jsonObject,Skill & skill)1110 void from_json(const nlohmann::json &jsonObject, Skill &skill)
1111 {
1112 // these are not required fields.
1113 const auto &jsonObjectEnd = jsonObject.end();
1114 int32_t parseResult = ERR_OK;
1115 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1116 jsonObjectEnd,
1117 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ACTIONS,
1118 skill.actions,
1119 JsonType::ARRAY,
1120 false,
1121 parseResult,
1122 ArrayType::STRING);
1123 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1124 jsonObjectEnd,
1125 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ENTITIES,
1126 skill.entities,
1127 JsonType::ARRAY,
1128 false,
1129 parseResult,
1130 ArrayType::STRING);
1131 GetValueIfFindKey<std::vector<SkillUri>>(jsonObject,
1132 jsonObjectEnd,
1133 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_URIS,
1134 skill.uris,
1135 JsonType::ARRAY,
1136 false,
1137 parseResult,
1138 ArrayType::OBJECT);
1139 if (parseResult != ERR_OK) {
1140 APP_LOGE("Skill from_json error, error code : %{public}d", parseResult);
1141 }
1142 }
1143
from_json(const nlohmann::json & jsonObject,Distro & distro)1144 void from_json(const nlohmann::json &jsonObject, Distro &distro)
1145 {
1146 const auto &jsonObjectEnd = jsonObject.end();
1147 int32_t parseResult = ERR_OK;
1148 GetValueIfFindKey<bool>(jsonObject,
1149 jsonObjectEnd,
1150 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL,
1151 distro.deliveryWithInstall,
1152 JsonType::BOOLEAN,
1153 true,
1154 parseResult,
1155 ArrayType::NOT_ARRAY);
1156 GetValueIfFindKey<std::string>(jsonObject,
1157 jsonObjectEnd,
1158 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME,
1159 distro.moduleName,
1160 JsonType::STRING,
1161 true,
1162 parseResult,
1163 ArrayType::NOT_ARRAY);
1164 GetValueIfFindKey<std::string>(jsonObject,
1165 jsonObjectEnd,
1166 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE,
1167 distro.moduleType,
1168 JsonType::STRING,
1169 true,
1170 parseResult,
1171 ArrayType::NOT_ARRAY);
1172 // mustFlag decide by distro.moduleType
1173 GetValueIfFindKey<bool>(jsonObject,
1174 jsonObjectEnd,
1175 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE,
1176 distro.installationFree,
1177 JsonType::BOOLEAN,
1178 false,
1179 parseResult,
1180 ArrayType::NOT_ARRAY);
1181 if (parseResult != ERR_OK) {
1182 APP_LOGE("Distro from_json error, error code : %{public}d", parseResult);
1183 }
1184 }
1185
from_json(const nlohmann::json & jsonObject,InstallMark & installMark)1186 void from_json(const nlohmann::json &jsonObject, InstallMark &installMark)
1187 {
1188 const auto &jsonObjectEnd = jsonObject.end();
1189 int32_t parseResult = ERR_OK;
1190 GetValueIfFindKey<std::string>(jsonObject,
1191 jsonObjectEnd,
1192 ProfileReader::BUNDLE_INSTALL_MARK_BUNDLE,
1193 installMark.bundleName,
1194 JsonType::STRING,
1195 false,
1196 parseResult,
1197 ArrayType::NOT_ARRAY);
1198 GetValueIfFindKey<std::string>(jsonObject,
1199 jsonObjectEnd,
1200 ProfileReader::BUNDLE_INSTALL_MARK_PACKAGE,
1201 installMark.packageName,
1202 JsonType::STRING,
1203 false,
1204 parseResult,
1205 ArrayType::NOT_ARRAY);
1206 GetValueIfFindKey<int32_t>(jsonObject,
1207 jsonObjectEnd,
1208 ProfileReader::BUNDLE_INSTALL_MARK_STATUS,
1209 installMark.status,
1210 JsonType::NUMBER,
1211 false,
1212 parseResult,
1213 ArrayType::NOT_ARRAY);
1214 if (parseResult != ERR_OK) {
1215 APP_LOGE("InstallMark from_json error, error code : %{public}d", parseResult);
1216 }
1217 }
1218
from_json(const nlohmann::json & jsonObject,DefinePermission & definePermission)1219 void from_json(const nlohmann::json &jsonObject, DefinePermission &definePermission)
1220 {
1221 const auto &jsonObjectEnd = jsonObject.end();
1222 int32_t parseResult = ERR_OK;
1223 GetValueIfFindKey<std::string>(jsonObject,
1224 jsonObjectEnd,
1225 Profile::DEFINEPERMISSION_NAME,
1226 definePermission.name,
1227 JsonType::STRING,
1228 false,
1229 parseResult,
1230 ArrayType::NOT_ARRAY);
1231 GetValueIfFindKey<std::string>(jsonObject,
1232 jsonObjectEnd,
1233 Profile::DEFINEPERMISSION_GRANT_MODE,
1234 definePermission.grantMode,
1235 JsonType::STRING,
1236 false,
1237 parseResult,
1238 ArrayType::NOT_ARRAY);
1239 GetValueIfFindKey<std::string>(jsonObject,
1240 jsonObjectEnd,
1241 Profile::DEFINEPERMISSION_AVAILABLE_LEVEL,
1242 definePermission.availableLevel,
1243 JsonType::STRING,
1244 false,
1245 parseResult,
1246 ArrayType::NOT_ARRAY);
1247 GetValueIfFindKey<bool>(jsonObject,
1248 jsonObjectEnd,
1249 Profile::DEFINEPERMISSION_PROVISION_ENABLE,
1250 definePermission.provisionEnable,
1251 JsonType::BOOLEAN,
1252 false,
1253 parseResult,
1254 ArrayType::NOT_ARRAY);
1255 GetValueIfFindKey<bool>(jsonObject,
1256 jsonObjectEnd,
1257 Profile::DEFINEPERMISSION_DISTRIBUTED_SCENE_ENABLE,
1258 definePermission.distributedSceneEnable,
1259 JsonType::BOOLEAN,
1260 false,
1261 parseResult,
1262 ArrayType::NOT_ARRAY);
1263 GetValueIfFindKey<std::string>(jsonObject,
1264 jsonObjectEnd,
1265 Profile::LABEL,
1266 definePermission.label,
1267 JsonType::STRING,
1268 false,
1269 parseResult,
1270 ArrayType::NOT_ARRAY);
1271 GetValueIfFindKey<int32_t>(jsonObject,
1272 jsonObjectEnd,
1273 Profile::LABEL_ID,
1274 definePermission.labelId,
1275 JsonType::NUMBER,
1276 false,
1277 parseResult,
1278 ArrayType::NOT_ARRAY);
1279 GetValueIfFindKey<std::string>(jsonObject,
1280 jsonObjectEnd,
1281 Profile::DESCRIPTION,
1282 definePermission.description,
1283 JsonType::STRING,
1284 false,
1285 parseResult,
1286 ArrayType::NOT_ARRAY);
1287 GetValueIfFindKey<int32_t>(jsonObject,
1288 jsonObjectEnd,
1289 Profile::DESCRIPTION_ID,
1290 definePermission.descriptionId,
1291 JsonType::NUMBER,
1292 false,
1293 parseResult,
1294 ArrayType::NOT_ARRAY);
1295 GetValueIfFindKey<std::string>(jsonObject,
1296 jsonObjectEnd,
1297 Profile::DEFINEPERMISSION_AVAILABLE_TYPE,
1298 definePermission.availableType,
1299 JsonType::STRING,
1300 false,
1301 parseResult,
1302 ArrayType::NOT_ARRAY);
1303 if (parseResult != ERR_OK) {
1304 APP_LOGE("DefinePermission from_json error, error code : %{public}d", parseResult);
1305 }
1306 }
1307
from_json(const nlohmann::json & jsonObject,Dependency & dependency)1308 void from_json(const nlohmann::json &jsonObject, Dependency &dependency)
1309 {
1310 const auto &jsonObjectEnd = jsonObject.end();
1311 int32_t parseResult = ERR_OK;
1312 GetValueIfFindKey<std::string>(jsonObject,
1313 jsonObjectEnd,
1314 Profile::DEPENDENCIES_MODULE_NAME,
1315 dependency.moduleName,
1316 JsonType::STRING,
1317 false,
1318 parseResult,
1319 ArrayType::NOT_ARRAY);
1320 GetValueIfFindKey<std::string>(jsonObject,
1321 jsonObjectEnd,
1322 Profile::DEPENDENCIES_BUNDLE_NAME,
1323 dependency.bundleName,
1324 JsonType::STRING,
1325 false,
1326 parseResult,
1327 ArrayType::NOT_ARRAY);
1328 GetValueIfFindKey<int>(jsonObject,
1329 jsonObjectEnd,
1330 Profile::APP_VERSION_CODE,
1331 dependency.versionCode,
1332 JsonType::NUMBER,
1333 false,
1334 parseResult,
1335 ArrayType::NOT_ARRAY);
1336 if (parseResult != ERR_OK) {
1337 APP_LOGE("Dependency from_json error, error code : %{public}d", parseResult);
1338 }
1339 }
1340 } // namespace AppExecFwk
1341 } // namespace OHOS
1342