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