1 /*
2 * Copyright (c) 2021-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 "application_info.h"
17
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <string.h>
21 #include <set>
22 #include <unistd.h>
23
24 #include "message_parcel.h"
25 #include "nlohmann/json.hpp"
26 #include "parcel_macro.h"
27 #include "string_ex.h"
28
29 #include "app_log_wrapper.h"
30 #include "bundle_constants.h"
31 #include "json_serializer.h"
32 #include "json_util.h"
33
34 namespace OHOS {
35 namespace AppExecFwk {
36 namespace {
37 const std::string APPLICATION_NAME = "name";
38 const std::string APPLICATION_VERSION_CODE = "versionCode";
39 const std::string APPLICATION_VERSION_NAME = "versionName";
40 const std::string APPLICATION_MIN_COMPATIBLE_VERSION_CODE = "minCompatibleVersionCode";
41 const std::string APPLICATION_API_COMPATIBLE_VERSION = "apiCompatibleVersion";
42 const std::string APPLICATION_API_TARGET_VERSION = "apiTargetVersion";
43 const std::string APPLICATION_ICON_PATH = "iconPath";
44 const std::string APPLICATION_ICON_ID = "iconId";
45 const std::string APPLICATION_LABEL = "label";
46 const std::string APPLICATION_LABEL_ID = "labelId";
47 const std::string APPLICATION_DESCRIPTION = "description";
48 const std::string APPLICATION_DESCRIPTION_ID = "descriptionId";
49 const std::string APPLICATION_KEEP_ALIVE = "keepAlive";
50 const std::string APPLICATION_REMOVABLE = "removable";
51 const std::string APPLICATION_SINGLETON = "singleton";
52 const std::string APPLICATION_USER_DATA_CLEARABLE = "userDataClearable";
53 const std::string APPLICATION_IS_SYSTEM_APP = "isSystemApp";
54 const std::string APPLICATION_IS_LAUNCHER_APP = "isLauncherApp";
55 const std::string APPLICATION_IS_FREEINSTALL_APP = "isFreeInstallApp";
56 const std::string APPLICATION_RUNNING_RESOURCES_APPLY = "runningResourcesApply";
57 const std::string APPLICATION_ASSOCIATED_WAKE_UP = "associatedWakeUp";
58 const std::string APPLICATION_HIDE_DESKTOP_ICON = "hideDesktopIcon";
59 const std::string APPLICATION_FORM_VISIBLE_NOTIFY = "formVisibleNotify";
60 const std::string APPLICATION_ALLOW_COMMON_EVENT = "allowCommonEvent";
61 const std::string APPLICATION_CODE_PATH = "codePath";
62 const std::string APPLICATION_DATA_DIR = "dataDir";
63 const std::string APPLICATION_DATA_BASE_DIR = "dataBaseDir";
64 const std::string APPLICATION_CACHE_DIR = "cacheDir";
65 const std::string APPLICATION_ENTRY_DIR = "entryDir";
66 const std::string APPLICATION_API_RELEASETYPE = "apiReleaseType";
67 const std::string APPLICATION_DEBUG = "debug";
68 const std::string APPLICATION_DEVICE_ID = "deviceId";
69 const std::string APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED = "distributedNotificationEnabled";
70 const std::string APPLICATION_ENTITY_TYPE = "entityType";
71 const std::string APPLICATION_PROCESS = "process";
72 const std::string APPLICATION_SUPPORTED_MODES = "supportedModes";
73 const std::string APPLICATION_VENDOR = "vendor";
74 const std::string APPLICATION_ACCESSIBLE = "accessible";
75 const std::string APPLICATION_PRIVILEGE_LEVEL = "appPrivilegeLevel";
76 const std::string APPLICATION_ACCESSTOKEN_ID = "accessTokenId";
77 const std::string APPLICATION_ACCESSTOKEN_ID_EX = "accessTokenIdEx";
78 const std::string APPLICATION_ENABLED = "enabled";
79 const std::string APPLICATION_UID = "uid";
80 const std::string APPLICATION_PERMISSIONS = "permissions";
81 const std::string APPLICATION_MODULE_SOURCE_DIRS = "moduleSourceDirs";
82 const std::string APPLICATION_MODULE_INFOS = "moduleInfos";
83 const std::string APPLICATION_META_DATA_CONFIG_JSON = "metaData";
84 const std::string APPLICATION_META_DATA_MODULE_JSON = "metadata";
85 const std::string APPLICATION_FINGERPRINT = "fingerprint";
86 const std::string APPLICATION_ICON = "icon";
87 const std::string APPLICATION_FLAGS = "flags";
88 const std::string APPLICATION_ENTRY_MODULE_NAME = "entryModuleName";
89 const std::string APPLICATION_NATIVE_LIBRARY_PATH = "nativeLibraryPath";
90 const std::string APPLICATION_CPU_ABI = "cpuAbi";
91 const std::string APPLICATION_ARK_NATIVE_FILE_PATH = "arkNativeFilePath";
92 const std::string APPLICATION_ARK_NATIVE_FILE_ABI = "arkNativeFileAbi";
93 const std::string APPLICATION_IS_COMPRESS_NATIVE_LIBS = "isCompressNativeLibs";
94 const std::string APPLICATION_SIGNATURE_KEY = "signatureKey";
95 const std::string APPLICATION_TARGETBUNDLELIST = "targetBundleList";
96 const std::string APPLICATION_APP_DISTRIBUTION_TYPE = "appDistributionType";
97 const std::string APPLICATION_APP_PROVISION_TYPE = "appProvisionType";
98 const std::string APPLICATION_ICON_RESOURCE = "iconResource";
99 const std::string APPLICATION_LABEL_RESOURCE = "labelResource";
100 const std::string APPLICATION_DESCRIPTION_RESOURCE = "descriptionResource";
101 const std::string APPLICATION_MULTI_PROJECTS = "multiProjects";
102 const std::string APPLICATION_CROWDTEST_DEADLINE = "crowdtestDeadline";
103 const std::string APPLICATION_APP_QUICK_FIX = "appQuickFix";
104 const std::string RESOURCE_ID = "id";
105 const size_t APPLICATION_CAPACITY = 10240; // 10K
106 const std::string APPLICATION_NEED_APP_DETAIL = "needAppDetail";
107 const std::string APPLICATION_APP_DETAIL_ABILITY_LIBRARY_PATH = "appDetailAbilityLibraryPath";
108 const std::string APPLICATION_APP_TARGET_BUNDLE_NAME = "targetBundleName";
109 const std::string APPLICATION_APP_TARGET_PRIORITY = "targetPriority";
110 const std::string APPLICATION_APP_OVERLAY_STATE = "overlayState";
111 const std::string APPLICATION_ASAN_ENABLED = "asanEnabled";
112 const std::string APPLICATION_ASAN_LOG_PATH = "asanLogPath";
113 const std::string APPLICATION_APP_TYPE = "bundleType";
114 const std::string APPLICATION_COMPILE_SDK_VERSION = "compileSdkVersion";
115 const std::string APPLICATION_COMPILE_SDK_TYPE = "compileSdkType";
116 const std::string APPLICATION_RESOURCES_APPLY = "resourcesApply";
117 }
118
Metadata(const std::string & paramName,const std::string & paramValue,const std::string & paramResource)119 Metadata::Metadata(const std::string ¶mName, const std::string ¶mValue, const std::string ¶mResource)
120 : name(paramName), value(paramValue), resource(paramResource)
121 {
122 }
123
ReadFromParcel(Parcel & parcel)124 bool Metadata::ReadFromParcel(Parcel &parcel)
125 {
126 name = Str16ToStr8(parcel.ReadString16());
127 value = Str16ToStr8(parcel.ReadString16());
128 resource = Str16ToStr8(parcel.ReadString16());
129 return true;
130 }
131
Marshalling(Parcel & parcel) const132 bool Metadata::Marshalling(Parcel &parcel) const
133 {
134 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
135 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(value));
136 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(resource));
137 return true;
138 }
139
Unmarshalling(Parcel & parcel)140 Metadata *Metadata::Unmarshalling(Parcel &parcel)
141 {
142 Metadata *metadata = new (std::nothrow) Metadata;
143 if (metadata && !metadata->ReadFromParcel(parcel)) {
144 APP_LOGE("read from parcel failed");
145 delete metadata;
146 metadata = nullptr;
147 }
148 return metadata;
149 }
150
CustomizeData(std::string paramName,std::string paramValue,std::string paramExtra)151 CustomizeData::CustomizeData(std::string paramName, std::string paramValue, std::string paramExtra)
152 :name(paramName), value(paramValue), extra(paramExtra)
153 {
154 }
155
ReadFromParcel(Parcel & parcel)156 bool CustomizeData::ReadFromParcel(Parcel &parcel)
157 {
158 name = Str16ToStr8(parcel.ReadString16());
159 value = Str16ToStr8(parcel.ReadString16());
160 extra = Str16ToStr8(parcel.ReadString16());
161 return true;
162 }
163
Unmarshalling(Parcel & parcel)164 CustomizeData *CustomizeData::Unmarshalling(Parcel &parcel)
165 {
166 CustomizeData *customizeData = new (std::nothrow) CustomizeData;
167 if (customizeData && !customizeData->ReadFromParcel(parcel)) {
168 APP_LOGE("read from parcel failed");
169 delete customizeData;
170 customizeData = nullptr;
171 }
172 return customizeData;
173 }
174
Marshalling(Parcel & parcel) const175 bool CustomizeData::Marshalling(Parcel &parcel) const
176 {
177 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
178 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(value));
179 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(extra));
180 return true;
181 }
182
ReadFromParcel(Parcel & parcel)183 bool Resource::ReadFromParcel(Parcel &parcel)
184 {
185 bundleName = Str16ToStr8(parcel.ReadString16());
186 moduleName = Str16ToStr8(parcel.ReadString16());
187 id = parcel.ReadInt32();
188 return true;
189 }
190
Marshalling(Parcel & parcel) const191 bool Resource::Marshalling(Parcel &parcel) const
192 {
193 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
194 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
195 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, id);
196 return true;
197 }
198
Unmarshalling(Parcel & parcel)199 Resource *Resource::Unmarshalling(Parcel &parcel)
200 {
201 Resource *resource = new (std::nothrow) Resource;
202 if (resource && !resource->ReadFromParcel(parcel)) {
203 APP_LOGE("read from parcel failed");
204 delete resource;
205 resource = nullptr;
206 }
207 return resource;
208 }
209
ReadMetaDataFromParcel(Parcel & parcel)210 bool ApplicationInfo::ReadMetaDataFromParcel(Parcel &parcel)
211 {
212 int32_t metaDataSize = parcel.ReadInt32();
213 CONTAINER_SECURITY_VERIFY(parcel, metaDataSize, &metaData);
214 for (int32_t i = 0; i < metaDataSize; i++) {
215 std::string mouduleName = Str16ToStr8(parcel.ReadString16());
216 int32_t customizeDataSize = parcel.ReadInt32();
217 std::vector<CustomizeData> customizeDatas;
218 metaData[mouduleName] = customizeDatas;
219 CONTAINER_SECURITY_VERIFY(parcel, customizeDataSize, &customizeDatas);
220 for (int j = 0; j < customizeDataSize; j++) {
221 std::unique_ptr<CustomizeData> customizeData(parcel.ReadParcelable<CustomizeData>());
222 if (!customizeData) {
223 APP_LOGE("ReadParcelable<CustomizeData> failed");
224 return false;
225 }
226 metaData[mouduleName].emplace_back(*customizeData);
227 }
228 }
229 return true;
230 }
231
ReadFromParcel(Parcel & parcel)232 bool ApplicationInfo::ReadFromParcel(Parcel &parcel)
233 {
234 name = Str16ToStr8(parcel.ReadString16());
235 bundleName = Str16ToStr8(parcel.ReadString16());
236 versionCode = parcel.ReadUint32();
237 versionName = Str16ToStr8(parcel.ReadString16());
238 minCompatibleVersionCode = parcel.ReadInt32();
239 apiCompatibleVersion = parcel.ReadUint32();
240 apiTargetVersion = parcel.ReadInt32();
241 crowdtestDeadline = parcel.ReadInt64();
242
243 iconPath = Str16ToStr8(parcel.ReadString16());
244 iconId = parcel.ReadInt32();
245 std::unique_ptr<Resource> iconResourcePtr(parcel.ReadParcelable<Resource>());
246 if (!iconResourcePtr) {
247 APP_LOGE("icon ReadParcelable<Resource> failed");
248 return false;
249 }
250 iconResource = *iconResourcePtr;
251
252 label = Str16ToStr8(parcel.ReadString16());
253 labelId = parcel.ReadInt32();
254 std::unique_ptr<Resource> labelResourcePtr(parcel.ReadParcelable<Resource>());
255 if (!labelResourcePtr) {
256 APP_LOGE("label ReadParcelable<Resource> failed");
257 return false;
258 }
259 labelResource = *labelResourcePtr;
260
261 description = Str16ToStr8(parcel.ReadString16());
262 descriptionId = parcel.ReadInt32();
263 std::unique_ptr<Resource> descriptionResourcePtr(parcel.ReadParcelable<Resource>());
264 if (!descriptionResourcePtr) {
265 APP_LOGE("description ReadParcelable<Resource> failed");
266 return false;
267 }
268 descriptionResource = *descriptionResourcePtr;
269
270 keepAlive = parcel.ReadBool();
271 removable = parcel.ReadBool();
272 singleton = parcel.ReadBool();
273 userDataClearable = parcel.ReadBool();
274 accessible = parcel.ReadBool();
275 isSystemApp = parcel.ReadBool();
276 isLauncherApp = parcel.ReadBool();
277 isFreeInstallApp = parcel.ReadBool();
278 runningResourcesApply = parcel.ReadBool();
279 associatedWakeUp = parcel.ReadBool();
280 hideDesktopIcon = parcel.ReadBool();
281 formVisibleNotify = parcel.ReadBool();
282 int32_t allowCommonEventSize;
283 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, allowCommonEventSize);
284 CONTAINER_SECURITY_VERIFY(parcel, allowCommonEventSize, &allowCommonEvent);
285 for (auto i = 0; i < allowCommonEventSize; i++) {
286 allowCommonEvent.emplace_back(Str16ToStr8(parcel.ReadString16()));
287 }
288
289 codePath = Str16ToStr8(parcel.ReadString16());
290 dataDir = Str16ToStr8(parcel.ReadString16());
291 dataBaseDir = Str16ToStr8(parcel.ReadString16());
292 cacheDir = Str16ToStr8(parcel.ReadString16());
293 entryDir = Str16ToStr8(parcel.ReadString16());
294
295 apiReleaseType = Str16ToStr8(parcel.ReadString16());
296 debug = parcel.ReadBool();
297 deviceId = Str16ToStr8(parcel.ReadString16());
298 distributedNotificationEnabled = parcel.ReadBool();
299 entityType = Str16ToStr8(parcel.ReadString16());
300 process = Str16ToStr8(parcel.ReadString16());
301 supportedModes = parcel.ReadInt32();
302 vendor = Str16ToStr8(parcel.ReadString16());
303 appPrivilegeLevel = Str16ToStr8(parcel.ReadString16());
304 appDistributionType = Str16ToStr8(parcel.ReadString16());
305 appProvisionType = Str16ToStr8(parcel.ReadString16());
306 accessTokenId = parcel.ReadUint32();
307 accessTokenIdEx = parcel.ReadUint64();
308 enabled = parcel.ReadBool();
309 uid = parcel.ReadInt32();
310 nativeLibraryPath = Str16ToStr8(parcel.ReadString16());
311 cpuAbi = Str16ToStr8(parcel.ReadString16());
312 arkNativeFilePath = Str16ToStr8(parcel.ReadString16());
313 arkNativeFileAbi = Str16ToStr8(parcel.ReadString16());
314
315 int32_t permissionsSize;
316 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, permissionsSize);
317 CONTAINER_SECURITY_VERIFY(parcel, permissionsSize, &permissions);
318 for (auto i = 0; i < permissionsSize; i++) {
319 permissions.emplace_back(Str16ToStr8(parcel.ReadString16()));
320 }
321
322 int32_t moduleSourceDirsSize;
323 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleSourceDirsSize);
324 CONTAINER_SECURITY_VERIFY(parcel, moduleSourceDirsSize, &moduleSourceDirs);
325 for (auto i = 0; i < moduleSourceDirsSize; i++) {
326 moduleSourceDirs.emplace_back(Str16ToStr8(parcel.ReadString16()));
327 }
328
329 int32_t moduleInfosSize;
330 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleInfosSize);
331 CONTAINER_SECURITY_VERIFY(parcel, moduleInfosSize, &moduleInfos);
332 for (auto i = 0; i < moduleInfosSize; i++) {
333 std::unique_ptr<ModuleInfo> moduleInfo(parcel.ReadParcelable<ModuleInfo>());
334 if (!moduleInfo) {
335 APP_LOGE("ReadParcelable<ModuleInfo> failed");
336 return false;
337 }
338 moduleInfos.emplace_back(*moduleInfo);
339 }
340
341 int32_t metaDataSize;
342 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metaDataSize);
343 CONTAINER_SECURITY_VERIFY(parcel, metaDataSize, &metaData);
344 for (int32_t i = 0; i < metaDataSize; ++i) {
345 std::string key = Str16ToStr8(parcel.ReadString16());
346 int32_t customizeDataSize = parcel.ReadInt32();
347 CONTAINER_SECURITY_VERIFY(parcel, customizeDataSize, &metaData[key]);
348 for (int n = 0; n < customizeDataSize; ++n) {
349 std::unique_ptr<CustomizeData> customizeData(parcel.ReadParcelable<CustomizeData>());
350 if (!customizeData) {
351 APP_LOGE("ReadParcelable<CustomizeData> failed");
352 return false;
353 }
354 metaData[key].emplace_back(*customizeData);
355 }
356 }
357
358 int32_t metadataSize;
359 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metadataSize);
360 CONTAINER_SECURITY_VERIFY(parcel, metadataSize, &metadata);
361 for (int32_t i = 0; i < metadataSize; ++i) {
362 std::string key = Str16ToStr8(parcel.ReadString16());
363 int32_t metaSize = parcel.ReadInt32();
364 CONTAINER_SECURITY_VERIFY(parcel, metaSize, &metadata[key]);
365 for (int n = 0; n < metaSize; ++n) {
366 std::unique_ptr<Metadata> meta(parcel.ReadParcelable<Metadata>());
367 if (!meta) {
368 APP_LOGE("ReadParcelable<Metadata> failed");
369 return false;
370 }
371 metadata[key].emplace_back(*meta);
372 }
373 }
374
375 int32_t targetBundleListSize;
376 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, targetBundleListSize);
377 CONTAINER_SECURITY_VERIFY(parcel, targetBundleListSize, &targetBundleList);
378 for (auto i = 0; i < targetBundleListSize; i++) {
379 targetBundleList.emplace_back(Str16ToStr8(parcel.ReadString16()));
380 }
381
382 fingerprint = Str16ToStr8(parcel.ReadString16());
383 icon = Str16ToStr8(parcel.ReadString16());
384 flags = parcel.ReadInt32();
385 entryModuleName = Str16ToStr8(parcel.ReadString16());
386 isCompressNativeLibs = parcel.ReadBool();
387 signatureKey = Str16ToStr8(parcel.ReadString16());
388 multiProjects = parcel.ReadBool();
389 std::unique_ptr<AppQuickFix> appQuickFixPtr(parcel.ReadParcelable<AppQuickFix>());
390 if (appQuickFixPtr == nullptr) {
391 APP_LOGE("ReadParcelable<AppQuickFixPtr> failed");
392 return false;
393 }
394 appQuickFix = *appQuickFixPtr;
395 needAppDetail = parcel.ReadBool();
396 appDetailAbilityLibraryPath = Str16ToStr8(parcel.ReadString16());
397 targetBundleName = Str16ToStr8(parcel.ReadString16());
398 targetPriority = parcel.ReadInt32();
399 overlayState = parcel.ReadInt32();
400 asanEnabled = parcel.ReadBool();
401 asanLogPath = Str16ToStr8(parcel.ReadString16());
402 bundleType = static_cast<BundleType>(parcel.ReadInt32());
403 compileSdkVersion = Str16ToStr8(parcel.ReadString16());
404 compileSdkType = Str16ToStr8(parcel.ReadString16());
405 int32_t resourceApplySize;
406 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, resourceApplySize);
407 CONTAINER_SECURITY_VERIFY(parcel, resourceApplySize, &resourcesApply);
408 for (int32_t i = 0; i < resourceApplySize; ++i) {
409 resourcesApply.emplace_back(parcel.ReadInt32());
410 }
411 return true;
412 }
413
Unmarshalling(Parcel & parcel)414 ApplicationInfo *ApplicationInfo::Unmarshalling(Parcel &parcel)
415 {
416 ApplicationInfo *info = new (std::nothrow) ApplicationInfo();
417 if (info && !info->ReadFromParcel(parcel)) {
418 APP_LOGW("read from parcel failed");
419 delete info;
420 info = nullptr;
421 }
422 return info;
423 }
424
Marshalling(Parcel & parcel) const425 bool ApplicationInfo::Marshalling(Parcel &parcel) const
426 {
427 APP_LOGD("ApplicationInfo::Marshalling called, bundleName: %{public}s", bundleName.c_str());
428 CHECK_PARCEL_CAPACITY(parcel, APPLICATION_CAPACITY);
429 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
430 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
431 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, versionCode);
432 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(versionName));
433 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, minCompatibleVersionCode);
434
435 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, apiCompatibleVersion);
436 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, apiTargetVersion);
437 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, crowdtestDeadline);
438
439 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(iconPath));
440 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, iconId);
441 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &iconResource);
442
443 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label));
444 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, labelId);
445 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &labelResource);
446
447 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(description));
448 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, descriptionId);
449 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &descriptionResource);
450
451 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, keepAlive);
452 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, removable);
453 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, singleton);
454 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, userDataClearable);
455 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessible);
456 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isSystemApp);
457 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isLauncherApp);
458 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isFreeInstallApp);
459 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, runningResourcesApply);
460 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, associatedWakeUp);
461 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, hideDesktopIcon);
462 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, formVisibleNotify);
463 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, allowCommonEvent.size());
464 for (auto &event : allowCommonEvent) {
465 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(event));
466 }
467
468 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(codePath));
469 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(dataDir));
470 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(dataBaseDir));
471 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(cacheDir));
472 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(entryDir));
473
474 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(apiReleaseType));
475 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, debug);
476 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceId));
477 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, distributedNotificationEnabled);
478 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(entityType));
479 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(process));
480 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportedModes);
481 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(vendor));
482
483 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appPrivilegeLevel));
484 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appDistributionType));
485 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appProvisionType));
486
487 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, accessTokenId);
488 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint64, parcel, accessTokenIdEx);
489 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, enabled);
490 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
491
492 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(nativeLibraryPath));
493 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(cpuAbi));
494 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(arkNativeFilePath));
495 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(arkNativeFileAbi));
496 CHECK_PARCEL_CAPACITY(parcel, APPLICATION_CAPACITY);
497 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, permissions.size());
498 for (auto &permission : permissions) {
499 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(permission));
500 }
501
502 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleSourceDirs.size());
503 for (auto &moduleSourceDir : moduleSourceDirs) {
504 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleSourceDir));
505 }
506
507 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleInfos.size());
508 for (auto &moduleInfo : moduleInfos) {
509 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &moduleInfo);
510 }
511
512 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metaData.size());
513 for (auto &item : metaData) {
514 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(item.first));
515 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, item.second.size());
516 for (auto &customizeData : item.second) {
517 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &customizeData);
518 }
519 }
520
521 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metadata.size());
522 for (auto &item : metadata) {
523 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(item.first));
524 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, item.second.size());
525 for (auto &meta : item.second) {
526 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &meta);
527 }
528 }
529
530 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, targetBundleList.size());
531 for (auto &targetBundle : targetBundleList) {
532 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetBundle));
533 }
534
535 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(fingerprint));
536 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(icon));
537 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, flags);
538 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(entryModuleName));
539 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isCompressNativeLibs);
540 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(signatureKey));
541
542 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, multiProjects);
543 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &appQuickFix);
544 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, needAppDetail);
545 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appDetailAbilityLibraryPath));
546 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetBundleName));
547 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, targetPriority);
548 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, overlayState);
549 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, asanEnabled);
550 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(asanLogPath));
551 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(bundleType));
552 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(compileSdkVersion));
553 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(compileSdkType));
554 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, resourcesApply.size());
555 for (auto &item : resourcesApply) {
556 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, item);
557 }
558 return true;
559 }
560
Dump(std::string prefix,int fd)561 void ApplicationInfo::Dump(std::string prefix, int fd)
562 {
563 APP_LOGI("called dump ApplicationInfo");
564 if (fd < 0) {
565 APP_LOGE("dump ApplicationInfo fd error");
566 return;
567 }
568 int flags = fcntl(fd, F_GETFL);
569 if (flags < 0) {
570 APP_LOGE("dump ApplicationInfo fcntl error, errno : %{public}d", errno);
571 return;
572 }
573 uint uflags = static_cast<uint>(flags);
574 uflags &= O_ACCMODE;
575 if ((uflags == O_WRONLY) || (uflags == O_RDWR)) {
576 nlohmann::json jsonObject = *this;
577 std::string result;
578 result.append(prefix);
579 result.append(jsonObject.dump(Constants::DUMP_INDENT));
580 int ret = TEMP_FAILURE_RETRY(write(fd, result.c_str(), result.size()));
581 if (ret < 0) {
582 APP_LOGE("dump ApplicationInfo write error, errno : %{public}d", errno);
583 }
584 }
585 return;
586 }
587
CheckNeedPreload(const std::string & moduleName) const588 bool ApplicationInfo::CheckNeedPreload(const std::string &moduleName) const
589 {
590 std::set<std::string> preloadModules;
591 auto it = std::find_if(std::begin(moduleInfos), std::end(moduleInfos),
592 [&moduleName](ModuleInfo info) {
593 return info.moduleName == moduleName;
594 });
595 if (it != moduleInfos.end()) {
596 for (const std::string &name : it->preloads) {
597 preloadModules.insert(name);
598 }
599 }
600 if (preloadModules.empty()) {
601 APP_LOGD("the module have no preloads.");
602 return false;
603 }
604 for (const ModuleInfo &moduleInfo : moduleInfos) {
605 auto iter = preloadModules.find(moduleInfo.moduleName);
606 if (iter != preloadModules.end()) {
607 preloadModules.erase(iter);
608 }
609 }
610 if (preloadModules.empty()) {
611 APP_LOGD("all preload modules exist locally.");
612 return false;
613 }
614 APP_LOGD("need to process preload.");
615 return true;
616 }
617
to_json(nlohmann::json & jsonObject,const Resource & resource)618 void to_json(nlohmann::json &jsonObject, const Resource &resource)
619 {
620 jsonObject = nlohmann::json {
621 {Constants::BUNDLE_NAME, resource.bundleName},
622 {Constants::MODULE_NAME, resource.moduleName},
623 {RESOURCE_ID, resource.id}
624 };
625 }
626
from_json(const nlohmann::json & jsonObject,Resource & resource)627 void from_json(const nlohmann::json &jsonObject, Resource &resource)
628 {
629 const auto &jsonObjectEnd = jsonObject.end();
630 int32_t parseResult = ERR_OK;
631 GetValueIfFindKey<std::string>(jsonObject,
632 jsonObjectEnd,
633 Constants::BUNDLE_NAME,
634 resource.bundleName,
635 JsonType::STRING,
636 true,
637 parseResult,
638 ArrayType::NOT_ARRAY);
639 GetValueIfFindKey<std::string>(jsonObject,
640 jsonObjectEnd,
641 Constants::MODULE_NAME,
642 resource.moduleName,
643 JsonType::STRING,
644 true,
645 parseResult,
646 ArrayType::NOT_ARRAY);
647 GetValueIfFindKey<int32_t>(jsonObject,
648 jsonObjectEnd,
649 RESOURCE_ID,
650 resource.id,
651 JsonType::NUMBER,
652 true,
653 parseResult,
654 ArrayType::NOT_ARRAY);
655 if (parseResult != ERR_OK) {
656 APP_LOGE("read Resource from database error, error code : %{public}d", parseResult);
657 }
658 }
659
to_json(nlohmann::json & jsonObject,const ApplicationInfo & applicationInfo)660 void to_json(nlohmann::json &jsonObject, const ApplicationInfo &applicationInfo)
661 {
662 jsonObject = nlohmann::json {
663 {APPLICATION_NAME, applicationInfo.name},
664 {Constants::BUNDLE_NAME, applicationInfo.bundleName},
665 {APPLICATION_VERSION_CODE, applicationInfo.versionCode},
666 {APPLICATION_VERSION_NAME, applicationInfo.versionName},
667 {APPLICATION_MIN_COMPATIBLE_VERSION_CODE, applicationInfo.minCompatibleVersionCode},
668 {APPLICATION_API_COMPATIBLE_VERSION, applicationInfo.apiCompatibleVersion},
669 {APPLICATION_API_TARGET_VERSION, applicationInfo.apiTargetVersion},
670 {APPLICATION_ICON_PATH, applicationInfo.iconPath},
671 {APPLICATION_ICON_ID, applicationInfo.iconId},
672 {APPLICATION_LABEL, applicationInfo.label},
673 {APPLICATION_LABEL_ID, applicationInfo.labelId},
674 {APPLICATION_DESCRIPTION, applicationInfo.description},
675 {APPLICATION_DESCRIPTION_ID, applicationInfo.descriptionId},
676 {APPLICATION_KEEP_ALIVE, applicationInfo.keepAlive},
677 {APPLICATION_REMOVABLE, applicationInfo.removable},
678 {APPLICATION_SINGLETON, applicationInfo.singleton},
679 {APPLICATION_USER_DATA_CLEARABLE, applicationInfo.userDataClearable},
680 {APPLICATION_ACCESSIBLE, applicationInfo.accessible},
681 {APPLICATION_IS_SYSTEM_APP, applicationInfo.isSystemApp},
682 {APPLICATION_IS_LAUNCHER_APP, applicationInfo.isLauncherApp},
683 {APPLICATION_IS_FREEINSTALL_APP, applicationInfo.isFreeInstallApp},
684 {APPLICATION_RUNNING_RESOURCES_APPLY, applicationInfo.runningResourcesApply},
685 {APPLICATION_ASSOCIATED_WAKE_UP, applicationInfo.associatedWakeUp},
686 {APPLICATION_HIDE_DESKTOP_ICON, applicationInfo.hideDesktopIcon},
687 {APPLICATION_FORM_VISIBLE_NOTIFY, applicationInfo.formVisibleNotify},
688 {APPLICATION_ALLOW_COMMON_EVENT, applicationInfo.allowCommonEvent},
689 {APPLICATION_CODE_PATH, applicationInfo.codePath},
690 {APPLICATION_DATA_DIR, applicationInfo.dataDir},
691 {APPLICATION_DATA_BASE_DIR, applicationInfo.dataBaseDir},
692 {APPLICATION_CACHE_DIR, applicationInfo.cacheDir},
693 {APPLICATION_ENTRY_DIR, applicationInfo.entryDir},
694 {APPLICATION_API_RELEASETYPE, applicationInfo.apiReleaseType},
695 {APPLICATION_DEBUG, applicationInfo.debug},
696 {APPLICATION_DEVICE_ID, applicationInfo.deviceId},
697 {APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED, applicationInfo.distributedNotificationEnabled},
698 {APPLICATION_ENTITY_TYPE, applicationInfo.entityType},
699 {APPLICATION_PROCESS, applicationInfo.process},
700 {APPLICATION_SUPPORTED_MODES, applicationInfo.supportedModes},
701 {APPLICATION_VENDOR, applicationInfo.vendor},
702 {APPLICATION_PRIVILEGE_LEVEL, applicationInfo.appPrivilegeLevel},
703 {APPLICATION_ACCESSTOKEN_ID, applicationInfo.accessTokenId},
704 {APPLICATION_ACCESSTOKEN_ID_EX, applicationInfo.accessTokenIdEx},
705 {APPLICATION_ENABLED, applicationInfo.enabled},
706 {APPLICATION_UID, applicationInfo.uid},
707 {APPLICATION_PERMISSIONS, applicationInfo.permissions},
708 {APPLICATION_MODULE_SOURCE_DIRS, applicationInfo.moduleSourceDirs},
709 {APPLICATION_MODULE_INFOS, applicationInfo.moduleInfos},
710 {APPLICATION_META_DATA_CONFIG_JSON, applicationInfo.metaData},
711 {APPLICATION_META_DATA_MODULE_JSON, applicationInfo.metadata},
712 {APPLICATION_FINGERPRINT, applicationInfo.fingerprint},
713 {APPLICATION_ICON, applicationInfo.icon},
714 {APPLICATION_FLAGS, applicationInfo.flags},
715 {APPLICATION_ENTRY_MODULE_NAME, applicationInfo.entryModuleName},
716 {APPLICATION_NATIVE_LIBRARY_PATH, applicationInfo.nativeLibraryPath},
717 {APPLICATION_CPU_ABI, applicationInfo.cpuAbi},
718 {APPLICATION_ARK_NATIVE_FILE_PATH, applicationInfo.arkNativeFilePath},
719 {APPLICATION_ARK_NATIVE_FILE_ABI, applicationInfo.arkNativeFileAbi},
720 {APPLICATION_IS_COMPRESS_NATIVE_LIBS, applicationInfo.isCompressNativeLibs},
721 {APPLICATION_SIGNATURE_KEY, applicationInfo.signatureKey},
722 {APPLICATION_TARGETBUNDLELIST, applicationInfo.targetBundleList},
723 {APPLICATION_APP_DISTRIBUTION_TYPE, applicationInfo.appDistributionType},
724 {APPLICATION_APP_PROVISION_TYPE, applicationInfo.appProvisionType},
725 {APPLICATION_ICON_RESOURCE, applicationInfo.iconResource},
726 {APPLICATION_LABEL_RESOURCE, applicationInfo.labelResource},
727 {APPLICATION_DESCRIPTION_RESOURCE, applicationInfo.descriptionResource},
728 {APPLICATION_MULTI_PROJECTS, applicationInfo.multiProjects},
729 {APPLICATION_CROWDTEST_DEADLINE, applicationInfo.crowdtestDeadline},
730 {APPLICATION_APP_QUICK_FIX, applicationInfo.appQuickFix},
731 {APPLICATION_NEED_APP_DETAIL, applicationInfo.needAppDetail},
732 {APPLICATION_APP_DETAIL_ABILITY_LIBRARY_PATH, applicationInfo.appDetailAbilityLibraryPath},
733 {APPLICATION_APP_TARGET_BUNDLE_NAME, applicationInfo.targetBundleName},
734 {APPLICATION_APP_TARGET_PRIORITY, applicationInfo.targetPriority},
735 {APPLICATION_APP_OVERLAY_STATE, applicationInfo.overlayState},
736 {APPLICATION_ASAN_ENABLED, applicationInfo.asanEnabled},
737 {APPLICATION_ASAN_LOG_PATH, applicationInfo.asanLogPath},
738 {APPLICATION_APP_TYPE, applicationInfo.bundleType},
739 {APPLICATION_COMPILE_SDK_VERSION, applicationInfo.compileSdkVersion},
740 {APPLICATION_COMPILE_SDK_TYPE, applicationInfo.compileSdkType},
741 {APPLICATION_RESOURCES_APPLY, applicationInfo.resourcesApply},
742 };
743 }
744
from_json(const nlohmann::json & jsonObject,ApplicationInfo & applicationInfo)745 void from_json(const nlohmann::json &jsonObject, ApplicationInfo &applicationInfo)
746 {
747 const auto &jsonObjectEnd = jsonObject.end();
748 int32_t parseResult = ERR_OK;
749 GetValueIfFindKey<std::string>(jsonObject,
750 jsonObjectEnd,
751 APPLICATION_NAME,
752 applicationInfo.name,
753 JsonType::STRING,
754 false,
755 parseResult,
756 ArrayType::NOT_ARRAY);
757 GetValueIfFindKey<std::string>(jsonObject,
758 jsonObjectEnd,
759 Constants::BUNDLE_NAME,
760 applicationInfo.bundleName,
761 JsonType::STRING,
762 false,
763 parseResult,
764 ArrayType::NOT_ARRAY);
765 GetValueIfFindKey<uint32_t>(jsonObject,
766 jsonObjectEnd,
767 APPLICATION_VERSION_CODE,
768 applicationInfo.versionCode,
769 JsonType::NUMBER,
770 false,
771 parseResult,
772 ArrayType::NOT_ARRAY);
773 GetValueIfFindKey<std::string>(jsonObject,
774 jsonObjectEnd,
775 APPLICATION_VERSION_NAME,
776 applicationInfo.versionName,
777 JsonType::STRING,
778 false,
779 parseResult,
780 ArrayType::NOT_ARRAY);
781 GetValueIfFindKey<int32_t>(jsonObject,
782 jsonObjectEnd,
783 APPLICATION_MIN_COMPATIBLE_VERSION_CODE,
784 applicationInfo.minCompatibleVersionCode,
785 JsonType::NUMBER,
786 false,
787 parseResult,
788 ArrayType::NOT_ARRAY);
789 GetValueIfFindKey<int32_t>(jsonObject,
790 jsonObjectEnd,
791 APPLICATION_API_COMPATIBLE_VERSION,
792 applicationInfo.apiCompatibleVersion,
793 JsonType::NUMBER,
794 false,
795 parseResult,
796 ArrayType::NOT_ARRAY);
797 GetValueIfFindKey<int32_t>(jsonObject,
798 jsonObjectEnd,
799 APPLICATION_API_TARGET_VERSION,
800 applicationInfo.apiTargetVersion,
801 JsonType::NUMBER,
802 false,
803 parseResult,
804 ArrayType::NOT_ARRAY);
805 GetValueIfFindKey<std::string>(jsonObject,
806 jsonObjectEnd,
807 APPLICATION_ICON_PATH,
808 applicationInfo.iconPath,
809 JsonType::STRING,
810 false,
811 parseResult,
812 ArrayType::NOT_ARRAY);
813 GetValueIfFindKey<int32_t>(jsonObject,
814 jsonObjectEnd,
815 APPLICATION_ICON_ID,
816 applicationInfo.iconId,
817 JsonType::NUMBER,
818 false,
819 parseResult,
820 ArrayType::NOT_ARRAY);
821 GetValueIfFindKey<std::string>(jsonObject,
822 jsonObjectEnd,
823 APPLICATION_LABEL,
824 applicationInfo.label,
825 JsonType::STRING,
826 false,
827 parseResult,
828 ArrayType::NOT_ARRAY);
829 GetValueIfFindKey<int32_t>(jsonObject,
830 jsonObjectEnd,
831 APPLICATION_LABEL_ID,
832 applicationInfo.labelId,
833 JsonType::NUMBER,
834 false,
835 parseResult,
836 ArrayType::NOT_ARRAY);
837 GetValueIfFindKey<std::string>(jsonObject,
838 jsonObjectEnd,
839 APPLICATION_DESCRIPTION,
840 applicationInfo.description,
841 JsonType::STRING,
842 false,
843 parseResult,
844 ArrayType::NOT_ARRAY);
845 GetValueIfFindKey<int32_t>(jsonObject,
846 jsonObjectEnd,
847 APPLICATION_DESCRIPTION_ID,
848 applicationInfo.descriptionId,
849 JsonType::NUMBER,
850 false,
851 parseResult,
852 ArrayType::NOT_ARRAY);
853 GetValueIfFindKey<bool>(jsonObject,
854 jsonObjectEnd,
855 APPLICATION_KEEP_ALIVE,
856 applicationInfo.keepAlive,
857 JsonType::BOOLEAN,
858 false,
859 parseResult,
860 ArrayType::NOT_ARRAY);
861 GetValueIfFindKey<bool>(jsonObject,
862 jsonObjectEnd,
863 APPLICATION_REMOVABLE,
864 applicationInfo.removable,
865 JsonType::BOOLEAN,
866 false,
867 parseResult,
868 ArrayType::NOT_ARRAY);
869 GetValueIfFindKey<bool>(jsonObject,
870 jsonObjectEnd,
871 APPLICATION_SINGLETON,
872 applicationInfo.singleton,
873 JsonType::BOOLEAN,
874 false,
875 parseResult,
876 ArrayType::NOT_ARRAY);
877 GetValueIfFindKey<bool>(jsonObject,
878 jsonObjectEnd,
879 APPLICATION_USER_DATA_CLEARABLE,
880 applicationInfo.userDataClearable,
881 JsonType::BOOLEAN,
882 false,
883 parseResult,
884 ArrayType::NOT_ARRAY);
885 GetValueIfFindKey<bool>(jsonObject,
886 jsonObjectEnd,
887 APPLICATION_ACCESSIBLE,
888 applicationInfo.accessible,
889 JsonType::BOOLEAN,
890 false,
891 parseResult,
892 ArrayType::NOT_ARRAY);
893 GetValueIfFindKey<bool>(jsonObject,
894 jsonObjectEnd,
895 APPLICATION_IS_SYSTEM_APP,
896 applicationInfo.isSystemApp,
897 JsonType::BOOLEAN,
898 false,
899 parseResult,
900 ArrayType::NOT_ARRAY);
901 GetValueIfFindKey<bool>(jsonObject,
902 jsonObjectEnd,
903 APPLICATION_IS_LAUNCHER_APP,
904 applicationInfo.isLauncherApp,
905 JsonType::BOOLEAN,
906 false,
907 parseResult,
908 ArrayType::NOT_ARRAY);
909 GetValueIfFindKey<bool>(jsonObject,
910 jsonObjectEnd,
911 APPLICATION_IS_FREEINSTALL_APP,
912 applicationInfo.isFreeInstallApp,
913 JsonType::BOOLEAN,
914 false,
915 parseResult,
916 ArrayType::NOT_ARRAY);
917 GetValueIfFindKey<bool>(jsonObject,
918 jsonObjectEnd,
919 APPLICATION_RUNNING_RESOURCES_APPLY,
920 applicationInfo.runningResourcesApply,
921 JsonType::BOOLEAN,
922 false,
923 parseResult,
924 ArrayType::NOT_ARRAY);
925 GetValueIfFindKey<bool>(jsonObject,
926 jsonObjectEnd,
927 APPLICATION_ASSOCIATED_WAKE_UP,
928 applicationInfo.associatedWakeUp,
929 JsonType::BOOLEAN,
930 false,
931 parseResult,
932 ArrayType::NOT_ARRAY);
933 GetValueIfFindKey<bool>(jsonObject,
934 jsonObjectEnd,
935 APPLICATION_HIDE_DESKTOP_ICON,
936 applicationInfo.hideDesktopIcon,
937 JsonType::BOOLEAN,
938 false,
939 parseResult,
940 ArrayType::NOT_ARRAY);
941 GetValueIfFindKey<bool>(jsonObject,
942 jsonObjectEnd,
943 APPLICATION_FORM_VISIBLE_NOTIFY,
944 applicationInfo.formVisibleNotify,
945 JsonType::BOOLEAN,
946 false,
947 parseResult,
948 ArrayType::NOT_ARRAY);
949 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
950 jsonObjectEnd,
951 APPLICATION_ALLOW_COMMON_EVENT,
952 applicationInfo.allowCommonEvent,
953 JsonType::ARRAY,
954 false,
955 parseResult,
956 ArrayType::STRING);
957 GetValueIfFindKey<std::string>(jsonObject,
958 jsonObjectEnd,
959 APPLICATION_CODE_PATH,
960 applicationInfo.codePath,
961 JsonType::STRING,
962 false,
963 parseResult,
964 ArrayType::NOT_ARRAY);
965 GetValueIfFindKey<std::string>(jsonObject,
966 jsonObjectEnd,
967 APPLICATION_DATA_DIR,
968 applicationInfo.dataDir,
969 JsonType::STRING,
970 false,
971 parseResult,
972 ArrayType::NOT_ARRAY);
973 GetValueIfFindKey<std::string>(jsonObject,
974 jsonObjectEnd,
975 APPLICATION_DATA_BASE_DIR,
976 applicationInfo.dataBaseDir,
977 JsonType::STRING,
978 false,
979 parseResult,
980 ArrayType::NOT_ARRAY);
981 GetValueIfFindKey<std::string>(jsonObject,
982 jsonObjectEnd,
983 APPLICATION_CACHE_DIR,
984 applicationInfo.cacheDir,
985 JsonType::STRING,
986 false,
987 parseResult,
988 ArrayType::NOT_ARRAY);
989 GetValueIfFindKey<std::string>(jsonObject,
990 jsonObjectEnd,
991 APPLICATION_ENTRY_DIR,
992 applicationInfo.entryDir,
993 JsonType::STRING,
994 false,
995 parseResult,
996 ArrayType::NOT_ARRAY);
997 GetValueIfFindKey<std::string>(jsonObject,
998 jsonObjectEnd,
999 APPLICATION_API_RELEASETYPE,
1000 applicationInfo.apiReleaseType,
1001 JsonType::STRING,
1002 false,
1003 parseResult,
1004 ArrayType::NOT_ARRAY);
1005 GetValueIfFindKey<bool>(jsonObject,
1006 jsonObjectEnd,
1007 APPLICATION_DEBUG,
1008 applicationInfo.debug,
1009 JsonType::BOOLEAN,
1010 false,
1011 parseResult,
1012 ArrayType::NOT_ARRAY);
1013 GetValueIfFindKey<std::string>(jsonObject,
1014 jsonObjectEnd,
1015 APPLICATION_DEVICE_ID,
1016 applicationInfo.deviceId,
1017 JsonType::STRING,
1018 false,
1019 parseResult,
1020 ArrayType::NOT_ARRAY);
1021 GetValueIfFindKey<bool>(jsonObject,
1022 jsonObjectEnd,
1023 APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED,
1024 applicationInfo.distributedNotificationEnabled,
1025 JsonType::BOOLEAN,
1026 false,
1027 parseResult,
1028 ArrayType::NOT_ARRAY);
1029 GetValueIfFindKey<std::string>(jsonObject,
1030 jsonObjectEnd,
1031 APPLICATION_ENTITY_TYPE,
1032 applicationInfo.entityType,
1033 JsonType::STRING,
1034 false,
1035 parseResult,
1036 ArrayType::NOT_ARRAY);
1037 GetValueIfFindKey<std::string>(jsonObject,
1038 jsonObjectEnd,
1039 APPLICATION_PROCESS,
1040 applicationInfo.process,
1041 JsonType::STRING,
1042 false,
1043 parseResult,
1044 ArrayType::NOT_ARRAY);
1045 GetValueIfFindKey<int>(jsonObject,
1046 jsonObjectEnd,
1047 APPLICATION_SUPPORTED_MODES,
1048 applicationInfo.supportedModes,
1049 JsonType::NUMBER,
1050 false,
1051 parseResult,
1052 ArrayType::NOT_ARRAY);
1053 GetValueIfFindKey<std::string>(jsonObject,
1054 jsonObjectEnd,
1055 APPLICATION_VENDOR,
1056 applicationInfo.vendor,
1057 JsonType::STRING,
1058 false,
1059 parseResult,
1060 ArrayType::NOT_ARRAY);
1061 GetValueIfFindKey<std::string>(jsonObject,
1062 jsonObjectEnd,
1063 APPLICATION_PRIVILEGE_LEVEL,
1064 applicationInfo.appPrivilegeLevel,
1065 JsonType::STRING,
1066 false,
1067 parseResult,
1068 ArrayType::NOT_ARRAY);
1069 GetValueIfFindKey<uint32_t>(jsonObject,
1070 jsonObjectEnd,
1071 APPLICATION_ACCESSTOKEN_ID,
1072 applicationInfo.accessTokenId,
1073 JsonType::NUMBER,
1074 false,
1075 parseResult,
1076 ArrayType::NOT_ARRAY);
1077 GetValueIfFindKey<uint64_t>(jsonObject,
1078 jsonObjectEnd,
1079 APPLICATION_ACCESSTOKEN_ID_EX,
1080 applicationInfo.accessTokenIdEx,
1081 JsonType::NUMBER,
1082 false,
1083 parseResult,
1084 ArrayType::NOT_ARRAY);
1085 GetValueIfFindKey<bool>(jsonObject,
1086 jsonObjectEnd,
1087 APPLICATION_ENABLED,
1088 applicationInfo.enabled,
1089 JsonType::BOOLEAN,
1090 false,
1091 parseResult,
1092 ArrayType::NOT_ARRAY);
1093 GetValueIfFindKey<int>(jsonObject,
1094 jsonObjectEnd,
1095 APPLICATION_UID,
1096 applicationInfo.uid,
1097 JsonType::NUMBER,
1098 false,
1099 parseResult,
1100 ArrayType::NOT_ARRAY);
1101 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1102 jsonObjectEnd,
1103 APPLICATION_PERMISSIONS,
1104 applicationInfo.permissions,
1105 JsonType::ARRAY,
1106 false,
1107 parseResult,
1108 ArrayType::STRING);
1109 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1110 jsonObjectEnd,
1111 APPLICATION_MODULE_SOURCE_DIRS,
1112 applicationInfo.moduleSourceDirs,
1113 JsonType::ARRAY,
1114 false,
1115 parseResult,
1116 ArrayType::STRING);
1117 GetValueIfFindKey<std::vector<ModuleInfo>>(jsonObject,
1118 jsonObjectEnd,
1119 APPLICATION_MODULE_INFOS,
1120 applicationInfo.moduleInfos,
1121 JsonType::ARRAY,
1122 false,
1123 parseResult,
1124 ArrayType::OBJECT);
1125 GetValueIfFindKey<std::map<std::string, std::vector<CustomizeData>>>(jsonObject,
1126 jsonObjectEnd,
1127 APPLICATION_META_DATA_CONFIG_JSON,
1128 applicationInfo.metaData,
1129 JsonType::OBJECT,
1130 false,
1131 parseResult,
1132 ArrayType::NOT_ARRAY);
1133 GetValueIfFindKey<std::map<std::string, std::vector<Metadata>>>(jsonObject,
1134 jsonObjectEnd,
1135 APPLICATION_META_DATA_MODULE_JSON,
1136 applicationInfo.metadata,
1137 JsonType::OBJECT,
1138 false,
1139 parseResult,
1140 ArrayType::NOT_ARRAY);
1141 GetValueIfFindKey<std::string>(jsonObject,
1142 jsonObjectEnd,
1143 APPLICATION_FINGERPRINT,
1144 applicationInfo.fingerprint,
1145 JsonType::STRING,
1146 false,
1147 parseResult,
1148 ArrayType::NOT_ARRAY);
1149 GetValueIfFindKey<std::string>(jsonObject,
1150 jsonObjectEnd,
1151 APPLICATION_ICON,
1152 applicationInfo.icon,
1153 JsonType::STRING,
1154 false,
1155 parseResult,
1156 ArrayType::NOT_ARRAY);
1157 GetValueIfFindKey<int>(jsonObject,
1158 jsonObjectEnd,
1159 APPLICATION_FLAGS,
1160 applicationInfo.flags,
1161 JsonType::NUMBER,
1162 false,
1163 parseResult,
1164 ArrayType::NOT_ARRAY);
1165 GetValueIfFindKey<std::string>(jsonObject,
1166 jsonObjectEnd,
1167 APPLICATION_ENTRY_MODULE_NAME,
1168 applicationInfo.entryModuleName,
1169 JsonType::STRING,
1170 false,
1171 parseResult,
1172 ArrayType::NOT_ARRAY);
1173 GetValueIfFindKey<std::string>(jsonObject,
1174 jsonObjectEnd,
1175 APPLICATION_NATIVE_LIBRARY_PATH,
1176 applicationInfo.nativeLibraryPath,
1177 JsonType::STRING,
1178 false,
1179 parseResult,
1180 ArrayType::NOT_ARRAY);
1181 GetValueIfFindKey<std::string>(jsonObject,
1182 jsonObjectEnd,
1183 APPLICATION_CPU_ABI,
1184 applicationInfo.cpuAbi,
1185 JsonType::STRING,
1186 false,
1187 parseResult,
1188 ArrayType::NOT_ARRAY);
1189 GetValueIfFindKey<std::string>(jsonObject,
1190 jsonObjectEnd,
1191 APPLICATION_ARK_NATIVE_FILE_PATH,
1192 applicationInfo.arkNativeFilePath,
1193 JsonType::STRING,
1194 false,
1195 parseResult,
1196 ArrayType::NOT_ARRAY);
1197 GetValueIfFindKey<std::string>(jsonObject,
1198 jsonObjectEnd,
1199 APPLICATION_ARK_NATIVE_FILE_ABI,
1200 applicationInfo.arkNativeFileAbi,
1201 JsonType::STRING,
1202 false,
1203 parseResult,
1204 ArrayType::NOT_ARRAY);
1205 GetValueIfFindKey<bool>(jsonObject,
1206 jsonObjectEnd,
1207 APPLICATION_IS_COMPRESS_NATIVE_LIBS,
1208 applicationInfo.isCompressNativeLibs,
1209 JsonType::BOOLEAN,
1210 false,
1211 parseResult,
1212 ArrayType::NOT_ARRAY);
1213 GetValueIfFindKey<std::string>(jsonObject,
1214 jsonObjectEnd,
1215 APPLICATION_SIGNATURE_KEY,
1216 applicationInfo.signatureKey,
1217 JsonType::STRING,
1218 false,
1219 parseResult,
1220 ArrayType::NOT_ARRAY);
1221 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1222 jsonObjectEnd,
1223 APPLICATION_TARGETBUNDLELIST,
1224 applicationInfo.targetBundleList,
1225 JsonType::ARRAY,
1226 false,
1227 parseResult,
1228 ArrayType::STRING);
1229 GetValueIfFindKey<std::string>(jsonObject,
1230 jsonObjectEnd,
1231 APPLICATION_APP_DISTRIBUTION_TYPE,
1232 applicationInfo.appDistributionType,
1233 JsonType::STRING,
1234 false,
1235 parseResult,
1236 ArrayType::NOT_ARRAY);
1237 GetValueIfFindKey<std::string>(jsonObject,
1238 jsonObjectEnd,
1239 APPLICATION_APP_PROVISION_TYPE,
1240 applicationInfo.appProvisionType,
1241 JsonType::STRING,
1242 false,
1243 parseResult,
1244 ArrayType::NOT_ARRAY);
1245 GetValueIfFindKey<Resource>(jsonObject,
1246 jsonObjectEnd,
1247 APPLICATION_ICON_RESOURCE,
1248 applicationInfo.iconResource,
1249 JsonType::OBJECT,
1250 false,
1251 parseResult,
1252 ArrayType::NOT_ARRAY);
1253 GetValueIfFindKey<Resource>(jsonObject,
1254 jsonObjectEnd,
1255 APPLICATION_LABEL_RESOURCE,
1256 applicationInfo.labelResource,
1257 JsonType::OBJECT,
1258 false,
1259 parseResult,
1260 ArrayType::NOT_ARRAY);
1261 GetValueIfFindKey<Resource>(jsonObject,
1262 jsonObjectEnd,
1263 APPLICATION_DESCRIPTION_RESOURCE,
1264 applicationInfo.descriptionResource,
1265 JsonType::OBJECT,
1266 false,
1267 parseResult,
1268 ArrayType::NOT_ARRAY);
1269 GetValueIfFindKey<bool>(jsonObject,
1270 jsonObjectEnd,
1271 APPLICATION_MULTI_PROJECTS,
1272 applicationInfo.multiProjects,
1273 JsonType::BOOLEAN,
1274 false,
1275 parseResult,
1276 ArrayType::NOT_ARRAY);
1277 GetValueIfFindKey<int64_t>(jsonObject,
1278 jsonObjectEnd,
1279 APPLICATION_CROWDTEST_DEADLINE,
1280 applicationInfo.crowdtestDeadline,
1281 JsonType::NUMBER,
1282 false,
1283 parseResult,
1284 ArrayType::NOT_ARRAY);
1285 GetValueIfFindKey<AppQuickFix>(jsonObject,
1286 jsonObjectEnd,
1287 APPLICATION_APP_QUICK_FIX,
1288 applicationInfo.appQuickFix,
1289 JsonType::OBJECT,
1290 false,
1291 parseResult,
1292 ArrayType::NOT_ARRAY);
1293 GetValueIfFindKey<bool>(jsonObject,
1294 jsonObjectEnd,
1295 APPLICATION_NEED_APP_DETAIL,
1296 applicationInfo.needAppDetail,
1297 JsonType::BOOLEAN,
1298 false,
1299 parseResult,
1300 ArrayType::NOT_ARRAY);
1301 GetValueIfFindKey<std::string>(jsonObject,
1302 jsonObjectEnd,
1303 APPLICATION_APP_DETAIL_ABILITY_LIBRARY_PATH,
1304 applicationInfo.appDetailAbilityLibraryPath,
1305 JsonType::STRING,
1306 false,
1307 parseResult,
1308 ArrayType::NOT_ARRAY);
1309 GetValueIfFindKey<std::string>(jsonObject,
1310 jsonObjectEnd,
1311 APPLICATION_APP_TARGET_BUNDLE_NAME,
1312 applicationInfo.targetBundleName,
1313 JsonType::STRING,
1314 false,
1315 parseResult,
1316 ArrayType::NOT_ARRAY);
1317 GetValueIfFindKey<int>(jsonObject,
1318 jsonObjectEnd,
1319 APPLICATION_APP_TARGET_PRIORITY,
1320 applicationInfo.targetPriority,
1321 JsonType::NUMBER,
1322 false,
1323 parseResult,
1324 ArrayType::NOT_ARRAY);
1325 GetValueIfFindKey<int>(jsonObject,
1326 jsonObjectEnd,
1327 APPLICATION_APP_OVERLAY_STATE,
1328 applicationInfo.overlayState,
1329 JsonType::NUMBER,
1330 false,
1331 parseResult,
1332 ArrayType::NOT_ARRAY);
1333 GetValueIfFindKey<bool>(jsonObject,
1334 jsonObjectEnd,
1335 APPLICATION_ASAN_ENABLED,
1336 applicationInfo.asanEnabled,
1337 JsonType::BOOLEAN,
1338 false,
1339 parseResult,
1340 ArrayType::NOT_ARRAY);
1341 GetValueIfFindKey<std::string>(jsonObject,
1342 jsonObjectEnd,
1343 APPLICATION_ASAN_LOG_PATH,
1344 applicationInfo.asanLogPath,
1345 JsonType::STRING,
1346 false,
1347 parseResult,
1348 ArrayType::NOT_ARRAY);
1349 GetValueIfFindKey<BundleType>(jsonObject,
1350 jsonObjectEnd,
1351 APPLICATION_APP_TYPE,
1352 applicationInfo.bundleType,
1353 JsonType::NUMBER,
1354 false,
1355 parseResult,
1356 ArrayType::NOT_ARRAY);
1357 GetValueIfFindKey<std::string>(jsonObject,
1358 jsonObjectEnd,
1359 APPLICATION_COMPILE_SDK_VERSION,
1360 applicationInfo.compileSdkVersion,
1361 JsonType::STRING,
1362 false,
1363 parseResult,
1364 ArrayType::NOT_ARRAY);
1365 GetValueIfFindKey<std::string>(jsonObject,
1366 jsonObjectEnd,
1367 APPLICATION_COMPILE_SDK_TYPE,
1368 applicationInfo.compileSdkType,
1369 JsonType::STRING,
1370 false,
1371 parseResult,
1372 ArrayType::NOT_ARRAY);
1373 GetValueIfFindKey<std::vector<int32_t>>(jsonObject,
1374 jsonObjectEnd,
1375 APPLICATION_RESOURCES_APPLY,
1376 applicationInfo.resourcesApply,
1377 JsonType::ARRAY,
1378 false,
1379 parseResult,
1380 ArrayType::NUMBER);
1381 if (parseResult != ERR_OK) {
1382 APP_LOGE("from_json error, error code : %{public}d", parseResult);
1383 }
1384 }
1385
ConvertToCompatibleApplicationInfo(CompatibleApplicationInfo & compatibleApplicationInfo) const1386 void ApplicationInfo::ConvertToCompatibleApplicationInfo(CompatibleApplicationInfo& compatibleApplicationInfo) const
1387 {
1388 APP_LOGD("ApplicationInfo::ConvertToCompatibleApplicationInfo called");
1389 compatibleApplicationInfo.name = name;
1390 compatibleApplicationInfo.icon = icon;
1391 compatibleApplicationInfo.label = label;
1392 compatibleApplicationInfo.description = description;
1393 compatibleApplicationInfo.cpuAbi = cpuAbi;
1394 compatibleApplicationInfo.process = process;
1395 compatibleApplicationInfo.systemApp = isSystemApp;
1396 compatibleApplicationInfo.isCompressNativeLibs = isCompressNativeLibs;
1397 compatibleApplicationInfo.iconId = iconId;
1398 compatibleApplicationInfo.labelId = labelId;
1399 compatibleApplicationInfo.descriptionId = descriptionId;
1400 compatibleApplicationInfo.permissions = permissions;
1401 compatibleApplicationInfo.moduleInfos = moduleInfos;
1402 compatibleApplicationInfo.supportedModes = supportedModes;
1403 compatibleApplicationInfo.enabled = enabled;
1404 compatibleApplicationInfo.debug = debug;
1405 }
1406 } // namespace AppExecFwk
1407 } // namespace OHOS
1408