• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ability_info.h"
17 
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <string.h>
21 #include <unistd.h>
22 
23 #include "bundle_constants.h"
24 #include "json_util.h"
25 #include "nlohmann/json.hpp"
26 #include "parcel_macro.h"
27 #include "string_ex.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
31 namespace {
32 const std::string JSON_KEY_PACKAGE = "package";
33 const std::string JSON_KEY_NAME = "name";
34 const std::string JSON_KEY_APPLICATION_NAME = "applicationName";
35 const std::string JSON_KEY_LABEL = "label";
36 const std::string JSON_KEY_DESCRIPTION = "description";
37 const std::string JSON_KEY_ICON_PATH = "iconPath";
38 const std::string JSON_KEY_THEME = "theme";
39 const std::string JSON_KEY_VISIBLE = "visible";
40 const std::string JSON_KEY_KIND = "kind";
41 const std::string JSON_KEY_TYPE = "type";
42 const std::string JSON_KEY_EXTENSION_ABILITY_TYPE = "extensionAbilityType";
43 const std::string JSON_KEY_ORIENTATION = "orientation";
44 const std::string JSON_KEY_LAUNCH_MODE = "launchMode";
45 const std::string JSON_KEY_CODE_PATH = "codePath";
46 const std::string JSON_KEY_RESOURCE_PATH = "resourcePath";
47 const std::string JSON_KEY_PERMISSIONS = "permissions";
48 const std::string JSON_KEY_PROCESS = "process";
49 const std::string JSON_KEY_DEVICE_TYPES = "deviceTypes";
50 const std::string JSON_KEY_DEVICE_CAPABILITIES = "deviceCapabilities";
51 const std::string JSON_KEY_URI = "uri";
52 const std::string JSON_KEY_IS_LAUNCHER_ABILITY = "isLauncherAbility";
53 const std::string JSON_KEY_REMOVE_MISSION_AFTER_TERMINATE = "removeMissionAfterTerminate";
54 const std::string JSON_KEY_IS_NATIVE_ABILITY = "isNativeAbility";
55 const std::string JSON_KEY_ENABLED = "enabled";
56 const std::string JSON_KEY_SUPPORT_PIP_MODE = "supportPipMode";
57 const std::string JSON_KEY_TARGET_ABILITY = "targetAbility";
58 const std::string JSON_KEY_READ_PERMISSION = "readPermission";
59 const std::string JSON_KEY_WRITE_PERMISSION = "writePermission";
60 const std::string JSON_KEY_CONFIG_CHANGES = "configChanges";
61 const std::string JSON_KEY_FORM = "form";
62 const std::string JSON_KEY_FORM_ENTITY = "formEntity";
63 const std::string JSON_KEY_MIN_FORM_HEIGHT = "minFormHeight";
64 const std::string JSON_KEY_DEFAULT_FORM_HEIGHT = "defaultFormHeight";
65 const std::string JSON_KEY_MIN_FORM_WIDTH = "minFormWidth";
66 const std::string JSON_KEY_DEFAULT_FORM_WIDTH = "defaultFormWidth";
67 const std::string JSON_KEY_BACKGROUND_MODES = "backgroundModes";
68 const std::string JSON_KEY_CUSTOMIZE_DATA = "customizeData";
69 const std::string JSON_KEY_META_DATA = "metaData";
70 const std::string JSON_KEY_META_VALUE = "value";
71 const std::string JSON_KEY_META_EXTRA = "extra";
72 const std::string JSON_KEY_LABEL_ID = "labelId";
73 const std::string JSON_KEY_DESCRIPTION_ID = "descriptionId";
74 const std::string JSON_KEY_ICON_ID = "iconId";
75 const std::string JSON_KEY_FORM_ENABLED = "formEnabled";
76 const std::string JSON_KEY_SRC_PATH = "srcPath";
77 const std::string JSON_KEY_SRC_LANGUAGE = "srcLanguage";
78 const std::string JSON_KEY_START_WINDOW_ICON = "startWindowIcon";
79 const std::string JSON_KEY_START_WINDOW_ICON_ID = "startWindowIconId";
80 const std::string JSON_KEY_START_WINDOW_BACKGROUND = "startWindowBackground";
81 const std::string JSON_KEY_START_WINDOW_BACKGROUND_ID = "startWindowBackgroundId";
82 const std::string JSON_KEY_COMPILE_MODE = "compileMode";
83 const std::string META_DATA = "metadata";
84 const std::string META_DATA_NAME = "name";
85 const std::string META_DATA_VALUE = "value";
86 const std::string META_DATA_RESOURCE = "resource";
87 const std::string SRC_ENTRANCE = "srcEntrance";
88 const std::string IS_MODULE_JSON = "isModuleJson";
89 const std::string IS_STAGE_BASED_MODEL = "isStageBasedModel";
90 const std::string CONTINUABLE = "continuable";
91 const std::string PRIORITY = "priority";
92 const std::string JOSN_KEY_SUPPORT_WINDOW_MODE = "supportWindowMode";
93 const std::string JOSN_KEY_MAX_WINDOW_RATIO = "maxWindowRatio";
94 const std::string JOSN_KEY_MIN_WINDOW_RATIO = "minWindowRatio";
95 const std::string JOSN_KEY_MAX_WINDOW_WIDTH = "maxWindowWidth";
96 const std::string JOSN_KEY_MIN_WINDOW_WIDTH = "minWindowWidth";
97 const std::string JOSN_KEY_MAX_WINDOW_HEIGHT = "maxWindowHeight";
98 const std::string JOSN_KEY_MIN_WINDOW_HEIGHT = "minWindowHeight";
99 const std::string JOSN_KEY_UID = "uid";
100 const std::string JOSN_KEY_EXCLUDE_FROM_MISSIONS = "excludeFromMissions";
101 const std::string JOSN_KEY_UNCLEARABLE_MISSION = "unclearableMission";
102 const std::string JSON_KEY_RECOVERABLE = "recoverable";
103 const std::string JSON_KEY_SUPPORT_EXT_NAMES = "supportExtNames";
104 const std::string JSON_KEY_SUPPORT_MIME_TYPES = "supportMimeTypes";
105 const size_t ABILITY_CAPACITY = 10240; // 10K
106 }  // namespace
107 
ReadFromParcel(Parcel & parcel)108 bool AbilityInfo::ReadFromParcel(Parcel &parcel)
109 {
110     name = Str16ToStr8(parcel.ReadString16());
111     label = Str16ToStr8(parcel.ReadString16());
112     description = Str16ToStr8(parcel.ReadString16());
113     iconPath = Str16ToStr8(parcel.ReadString16());
114     labelId = parcel.ReadInt32();
115     descriptionId = parcel.ReadInt32();
116     iconId = parcel.ReadInt32();
117     theme = Str16ToStr8(parcel.ReadString16());
118     visible = parcel.ReadBool();
119     kind = Str16ToStr8(parcel.ReadString16());
120     type = static_cast<AbilityType>(parcel.ReadInt32());
121     extensionAbilityType = static_cast<ExtensionAbilityType>(parcel.ReadInt32());
122     orientation = static_cast<DisplayOrientation>(parcel.ReadInt32());
123     launchMode = static_cast<LaunchMode>(parcel.ReadInt32());
124     srcPath = Str16ToStr8(parcel.ReadString16());
125     srcLanguage = Str16ToStr8(parcel.ReadString16());
126 
127     int32_t permissionsSize;
128     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, permissionsSize);
129     CONTAINER_SECURITY_VERIFY(parcel, permissionsSize, &permissions);
130     for (auto i = 0; i < permissionsSize; i++) {
131         permissions.emplace_back(Str16ToStr8(parcel.ReadString16()));
132     }
133 
134     process = Str16ToStr8(parcel.ReadString16());
135 
136     int32_t deviceTypesSize;
137     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceTypesSize);
138     CONTAINER_SECURITY_VERIFY(parcel, deviceTypesSize, &deviceTypes);
139     for (auto i = 0; i < deviceTypesSize; i++) {
140         deviceTypes.emplace_back(Str16ToStr8(parcel.ReadString16()));
141     }
142 
143     int32_t deviceCapabilitiesSize;
144     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceCapabilitiesSize);
145     CONTAINER_SECURITY_VERIFY(parcel, deviceCapabilitiesSize, &deviceCapabilities);
146     for (auto i = 0; i < deviceCapabilitiesSize; i++) {
147         deviceCapabilities.emplace_back(Str16ToStr8(parcel.ReadString16()));
148     }
149     uri = Str16ToStr8(parcel.ReadString16());
150     targetAbility = Str16ToStr8(parcel.ReadString16());
151 
152     std::unique_ptr<ApplicationInfo> appInfo(parcel.ReadParcelable<ApplicationInfo>());
153     if (!appInfo) {
154         APP_LOGE("ReadParcelable<ApplicationInfo> failed");
155         return false;
156     }
157     applicationInfo = *appInfo;
158 
159     isLauncherAbility = parcel.ReadBool();
160     isNativeAbility = parcel.ReadBool();
161     enabled = parcel.ReadBool();
162     supportPipMode = parcel.ReadBool();
163     formEnabled = parcel.ReadBool();
164     removeMissionAfterTerminate = parcel.ReadBool();
165 
166     readPermission = Str16ToStr8(parcel.ReadString16());
167     writePermission = Str16ToStr8(parcel.ReadString16());
168     int32_t configChangesSize;
169     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, configChangesSize);
170     CONTAINER_SECURITY_VERIFY(parcel, configChangesSize, &configChanges);
171     for (auto i = 0; i < configChangesSize; i++) {
172         configChanges.emplace_back(Str16ToStr8(parcel.ReadString16()));
173     }
174     formEntity = parcel.ReadUint32();
175     minFormHeight = parcel.ReadInt32();
176     defaultFormHeight = parcel.ReadInt32();
177     minFormWidth = parcel.ReadInt32();
178     defaultFormWidth = parcel.ReadInt32();
179     int32_t metaDataSize;
180     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metaDataSize);
181     CONTAINER_SECURITY_VERIFY(parcel, metaDataSize, &metaData.customizeData);
182     for (auto i = 0; i < metaDataSize; i++) {
183         std::unique_ptr<CustomizeData> customizeDataPtr(parcel.ReadParcelable<CustomizeData>());
184         if (!customizeDataPtr) {
185             APP_LOGE("ReadParcelable<Metadata> failed");
186             return false;
187         }
188         metaData.customizeData.emplace_back(*customizeDataPtr);
189     }
190     backgroundModes = parcel.ReadUint32();
191 
192     package = Str16ToStr8(parcel.ReadString16());
193     bundleName = Str16ToStr8(parcel.ReadString16());
194     moduleName = Str16ToStr8(parcel.ReadString16());
195     applicationName = Str16ToStr8(parcel.ReadString16());
196 
197     codePath = Str16ToStr8(parcel.ReadString16());
198     resourcePath = Str16ToStr8(parcel.ReadString16());
199     hapPath = Str16ToStr8(parcel.ReadString16());
200 
201     srcEntrance = Str16ToStr8(parcel.ReadString16());
202     int32_t metadataSize;
203     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metadataSize);
204     CONTAINER_SECURITY_VERIFY(parcel, metadataSize, &metadata);
205     for (auto i = 0; i < metadataSize; i++) {
206         std::unique_ptr<Metadata> metadataPtr(parcel.ReadParcelable<Metadata>());
207         if (!metadataPtr) {
208             APP_LOGE("ReadParcelable<Metadata> failed");
209             return false;
210         }
211         metadata.emplace_back(*metadataPtr);
212     }
213     isModuleJson = parcel.ReadBool();
214     isStageBasedModel = parcel.ReadBool();
215     continuable = parcel.ReadBool();
216     priority = parcel.ReadInt32();
217 
218     startWindowIcon = Str16ToStr8(parcel.ReadString16());
219     startWindowIconId = parcel.ReadInt32();
220     startWindowBackground = Str16ToStr8(parcel.ReadString16());
221     startWindowBackgroundId = parcel.ReadInt32();
222 
223     originalBundleName = Str16ToStr8(parcel.ReadString16());
224     appName = Str16ToStr8(parcel.ReadString16());
225     privacyUrl = Str16ToStr8(parcel.ReadString16());
226     privacyName = Str16ToStr8(parcel.ReadString16());
227     downloadUrl = Str16ToStr8(parcel.ReadString16());
228     versionName = Str16ToStr8(parcel.ReadString16());
229     className = Str16ToStr8(parcel.ReadString16());
230     originalClassName = Str16ToStr8(parcel.ReadString16());
231     uriPermissionMode = Str16ToStr8(parcel.ReadString16());
232     uriPermissionPath = Str16ToStr8(parcel.ReadString16());
233     packageSize = parcel.ReadUint32();
234     multiUserShared = parcel.ReadBool();
235     grantPermission = parcel.ReadBool();
236     directLaunch = parcel.ReadBool();
237     subType = static_cast<AbilitySubType>(parcel.ReadInt32());
238     libPath = Str16ToStr8(parcel.ReadString16());
239     deviceId = Str16ToStr8(parcel.ReadString16());
240     compileMode = static_cast<CompileMode>(parcel.ReadInt32());
241 
242     int32_t windowModeSize = parcel.ReadInt32();
243     CONTAINER_SECURITY_VERIFY(parcel, windowModeSize, &windowModes);
244     for (auto index = 0; index < windowModeSize; ++index) {
245         windowModes.emplace_back(static_cast<SupportWindowMode>(parcel.ReadInt32()));
246     }
247     maxWindowRatio = parcel.ReadDouble();
248     minWindowRatio = parcel.ReadDouble();
249     maxWindowWidth = parcel.ReadUint32();
250     minWindowWidth = parcel.ReadUint32();
251     maxWindowHeight = parcel.ReadUint32();
252     minWindowHeight = parcel.ReadUint32();
253     uid = parcel.ReadInt32();
254     recoverable = parcel.ReadBool();
255     installTime = parcel.ReadInt64();
256     int32_t supportExtNameSize;
257     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportExtNameSize);
258     CONTAINER_SECURITY_VERIFY(parcel, supportExtNameSize, &supportExtNames);
259     for (auto i = 0; i < supportExtNameSize; i++) {
260         supportExtNames.emplace_back(Str16ToStr8(parcel.ReadString16()));
261     }
262     int32_t supportMimeTypeSize;
263     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportMimeTypeSize);
264     CONTAINER_SECURITY_VERIFY(parcel, supportMimeTypeSize, &supportMimeTypes);
265     for (auto i = 0; i < supportMimeTypeSize; i++) {
266         supportMimeTypes.emplace_back(Str16ToStr8(parcel.ReadString16()));
267     }
268     int32_t skillUriSize;
269     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, skillUriSize);
270     CONTAINER_SECURITY_VERIFY(parcel, skillUriSize, &skillUri);
271     for (auto i = 0; i < skillUriSize; i++) {
272         SkillUriForAbilityAndExtension stctUri;
273         stctUri.scheme = Str16ToStr8(parcel.ReadString16());
274         stctUri.host = Str16ToStr8(parcel.ReadString16());
275         stctUri.port = Str16ToStr8(parcel.ReadString16());
276         stctUri.path = Str16ToStr8(parcel.ReadString16());
277         stctUri.pathStartWith = Str16ToStr8(parcel.ReadString16());
278         stctUri.pathRegex = Str16ToStr8(parcel.ReadString16());
279         stctUri.type = Str16ToStr8(parcel.ReadString16());
280         skillUri.emplace_back(stctUri);
281     }
282     return true;
283 }
284 
Unmarshalling(Parcel & parcel)285 AbilityInfo *AbilityInfo::Unmarshalling(Parcel &parcel)
286 {
287     AbilityInfo *info = new (std::nothrow) AbilityInfo();
288     if (info && !info->ReadFromParcel(parcel)) {
289         APP_LOGW("read from parcel failed");
290         delete info;
291         info = nullptr;
292     }
293     return info;
294 }
295 
Marshalling(Parcel & parcel) const296 bool AbilityInfo::Marshalling(Parcel &parcel) const
297 {
298     CHECK_PARCEL_CAPACITY(parcel, ABILITY_CAPACITY);
299     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
300     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label));
301     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(description));
302     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(iconPath));
303     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, labelId);
304     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, descriptionId);
305     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, iconId);
306     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(theme));
307     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, visible);
308     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(kind));
309     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(type));
310     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(extensionAbilityType));
311     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(orientation));
312     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(launchMode));
313     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcPath));
314     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcLanguage));
315     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, permissions.size());
316     for (auto &permission : permissions) {
317         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(permission));
318     }
319 
320     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(process));
321     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceTypes.size());
322     for (auto &deviceType : deviceTypes) {
323         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceType));
324     }
325 
326     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceCapabilities.size());
327     for (auto &deviceCapability : deviceCapabilities) {
328         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceCapability));
329     }
330     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri));
331     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetAbility));
332     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &applicationInfo);
333     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isLauncherAbility);
334     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isNativeAbility);
335     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, enabled);
336     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, supportPipMode);
337     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, formEnabled);
338     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, removeMissionAfterTerminate);
339     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(readPermission));
340     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(writePermission));
341     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, configChanges.size());
342     for (auto &configChange : configChanges) {
343         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(configChange));
344     }
345     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, formEntity);
346     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, minFormHeight);
347     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, defaultFormHeight);
348     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, minFormWidth);
349     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, defaultFormWidth);
350     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metaData.customizeData.size());
351     for (auto &meta : metaData.customizeData) {
352         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &meta);
353     }
354     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, backgroundModes);
355 
356     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(package));
357     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
358     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
359     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(applicationName));
360     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(codePath));
361     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(resourcePath));
362     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hapPath));
363 
364     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcEntrance));
365 
366     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metadata.size());
367     for (auto &meta : metadata) {
368         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &meta);
369     }
370 
371     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isModuleJson);
372     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isStageBasedModel);
373     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, continuable);
374     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, priority);
375 
376     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(startWindowIcon));
377     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, startWindowIconId);
378     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(startWindowBackground));
379     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, startWindowBackgroundId);
380 
381     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(originalBundleName));
382     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appName));
383     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(privacyUrl));
384     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(privacyName));
385     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(downloadUrl));
386     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(versionName));
387     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(className));
388     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(originalClassName));
389     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uriPermissionMode));
390     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uriPermissionPath));
391     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, packageSize);
392     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, multiUserShared);
393     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, grantPermission);
394     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, directLaunch);
395     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(subType));
396     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(libPath));
397     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceId));
398     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(compileMode));
399 
400     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowModes.size());
401     for (auto &mode : windowModes) {
402         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(mode));
403     }
404     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Double, parcel, maxWindowRatio);
405     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Double, parcel, minWindowRatio);
406     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, maxWindowWidth);
407     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, minWindowWidth);
408     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, maxWindowHeight);
409     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, minWindowHeight);
410     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
411     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, recoverable);
412     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, installTime);
413     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportExtNames.size());
414     for (auto &supporExtName : supportExtNames) {
415         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(supporExtName));
416     }
417     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportMimeTypes.size());
418     for (auto &supportMimeType : supportMimeTypes) {
419         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(supportMimeType));
420     }
421     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, skillUri.size());
422     for (auto &uri : skillUri) {
423         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.scheme));
424         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.host));
425         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.port));
426         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.path));
427         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.pathStartWith));
428         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.pathRegex));
429         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.type));
430     }
431     return true;
432 }
433 
Dump(std::string prefix,int fd)434 void AbilityInfo::Dump(std::string prefix, int fd)
435 {
436     APP_LOGI("called dump Abilityinfo");
437     if (fd < 0) {
438         APP_LOGE("dump Abilityinfo fd error");
439         return;
440     }
441     int flags = fcntl(fd, F_GETFL);
442     if (flags < 0) {
443         APP_LOGE("dump Abilityinfo fcntl error, errno : %{public}d", errno);
444         return;
445     }
446     uint uflags = static_cast<uint>(flags);
447     uflags &= O_ACCMODE;
448     if ((uflags == O_WRONLY) || (uflags == O_RDWR)) {
449         nlohmann::json jsonObject = *this;
450         std::string result;
451         result.append(prefix);
452         result.append(jsonObject.dump(Constants::DUMP_INDENT));
453         int ret = TEMP_FAILURE_RETRY(write(fd, result.c_str(), result.size()));
454         if (ret < 0) {
455             APP_LOGE("dump Abilityinfo write error, errno : %{public}d", errno);
456         }
457     }
458     return;
459 }
460 
to_json(nlohmann::json & jsonObject,const CustomizeData & customizeData)461 void to_json(nlohmann::json &jsonObject, const CustomizeData &customizeData)
462 {
463     jsonObject = nlohmann::json {
464         {JSON_KEY_NAME, customizeData.name},
465         {JSON_KEY_META_VALUE, customizeData.value},
466         {JSON_KEY_META_EXTRA, customizeData.extra}
467     };
468 }
469 
to_json(nlohmann::json & jsonObject,const MetaData & metaData)470 void to_json(nlohmann::json &jsonObject, const MetaData &metaData)
471 {
472     jsonObject = nlohmann::json {
473         {JSON_KEY_CUSTOMIZE_DATA, metaData.customizeData}
474     };
475 }
476 
to_json(nlohmann::json & jsonObject,const Metadata & metadata)477 void to_json(nlohmann::json &jsonObject, const Metadata &metadata)
478 {
479     jsonObject = nlohmann::json {
480         {META_DATA_NAME, metadata.name},
481         {META_DATA_VALUE, metadata.value},
482         {META_DATA_RESOURCE, metadata.resource}
483     };
484 }
485 
to_json(nlohmann::json & jsonObject,const AbilityInfo & abilityInfo)486 void to_json(nlohmann::json &jsonObject, const AbilityInfo &abilityInfo)
487 {
488     APP_LOGD("AbilityInfo to_json begin");
489     jsonObject = nlohmann::json {
490         {JSON_KEY_NAME, abilityInfo.name},
491         {JSON_KEY_LABEL, abilityInfo.label},
492         {JSON_KEY_DESCRIPTION, abilityInfo.description},
493         {JSON_KEY_ICON_PATH, abilityInfo.iconPath},
494         {JSON_KEY_LABEL_ID, abilityInfo.labelId},
495         {JSON_KEY_DESCRIPTION_ID, abilityInfo.descriptionId},
496         {JSON_KEY_ICON_ID, abilityInfo.iconId},
497         {JSON_KEY_THEME, abilityInfo.theme},
498         {JSON_KEY_VISIBLE, abilityInfo.visible},
499         {JSON_KEY_KIND, abilityInfo.kind},
500         {JSON_KEY_TYPE, abilityInfo.type},
501         {JSON_KEY_EXTENSION_ABILITY_TYPE, abilityInfo.extensionAbilityType},
502         {JSON_KEY_ORIENTATION, abilityInfo.orientation},
503         {JSON_KEY_LAUNCH_MODE, abilityInfo.launchMode},
504         {JSON_KEY_SRC_PATH, abilityInfo.srcPath},
505         {JSON_KEY_SRC_LANGUAGE, abilityInfo.srcLanguage},
506         {JSON_KEY_PERMISSIONS, abilityInfo.permissions},
507         {JSON_KEY_PROCESS, abilityInfo.process},
508         {JSON_KEY_DEVICE_TYPES, abilityInfo.deviceTypes},
509         {JSON_KEY_DEVICE_CAPABILITIES, abilityInfo.deviceCapabilities},
510         {JSON_KEY_URI, abilityInfo.uri},
511         {JSON_KEY_TARGET_ABILITY, abilityInfo.targetAbility},
512         {JSON_KEY_IS_LAUNCHER_ABILITY, abilityInfo.isLauncherAbility},
513         {JSON_KEY_IS_NATIVE_ABILITY, abilityInfo.isNativeAbility},
514         {JSON_KEY_ENABLED, abilityInfo.enabled},
515         {JSON_KEY_SUPPORT_PIP_MODE, abilityInfo.supportPipMode},
516         {JSON_KEY_FORM_ENABLED, abilityInfo.formEnabled},
517         {JSON_KEY_READ_PERMISSION, abilityInfo.readPermission},
518         {JSON_KEY_WRITE_PERMISSION, abilityInfo.writePermission},
519         {JSON_KEY_CONFIG_CHANGES, abilityInfo.configChanges},
520         {JSON_KEY_FORM_ENTITY, abilityInfo.formEntity},
521         {JSON_KEY_MIN_FORM_HEIGHT, abilityInfo.minFormHeight},
522         {JSON_KEY_DEFAULT_FORM_HEIGHT, abilityInfo.defaultFormHeight},
523         {JSON_KEY_MIN_FORM_WIDTH, abilityInfo.minFormWidth},
524         {JSON_KEY_DEFAULT_FORM_WIDTH, abilityInfo.defaultFormWidth},
525         {JSON_KEY_META_DATA, abilityInfo.metaData},
526         {JSON_KEY_BACKGROUND_MODES, abilityInfo.backgroundModes},
527         {JSON_KEY_PACKAGE, abilityInfo.package},
528         {Constants::BUNDLE_NAME, abilityInfo.bundleName},
529         {Constants::MODULE_NAME, abilityInfo.moduleName},
530         {JSON_KEY_APPLICATION_NAME, abilityInfo.applicationName},
531         {JSON_KEY_CODE_PATH, abilityInfo.codePath},
532         {JSON_KEY_RESOURCE_PATH, abilityInfo.resourcePath},
533         {Constants::HAP_PATH, abilityInfo.hapPath},
534         {SRC_ENTRANCE, abilityInfo.srcEntrance},
535         {META_DATA, abilityInfo.metadata},
536         {IS_MODULE_JSON, abilityInfo.isModuleJson},
537         {IS_STAGE_BASED_MODEL, abilityInfo.isStageBasedModel},
538         {CONTINUABLE, abilityInfo.continuable},
539         {PRIORITY, abilityInfo.priority},
540         {JSON_KEY_START_WINDOW_ICON, abilityInfo.startWindowIcon},
541         {JSON_KEY_START_WINDOW_ICON_ID, abilityInfo.startWindowIconId},
542         {JSON_KEY_START_WINDOW_BACKGROUND, abilityInfo.startWindowBackground},
543         {JSON_KEY_START_WINDOW_BACKGROUND_ID, abilityInfo.startWindowBackgroundId},
544         {JSON_KEY_REMOVE_MISSION_AFTER_TERMINATE, abilityInfo.removeMissionAfterTerminate},
545         {JSON_KEY_COMPILE_MODE, abilityInfo.compileMode},
546         {JOSN_KEY_SUPPORT_WINDOW_MODE, abilityInfo.windowModes},
547         {JOSN_KEY_MAX_WINDOW_WIDTH, abilityInfo.maxWindowWidth},
548         {JOSN_KEY_MIN_WINDOW_WIDTH, abilityInfo.minWindowWidth},
549         {JOSN_KEY_MAX_WINDOW_HEIGHT, abilityInfo.maxWindowHeight},
550         {JOSN_KEY_MIN_WINDOW_HEIGHT, abilityInfo.minWindowHeight},
551         {JOSN_KEY_UID, abilityInfo.uid},
552         {JOSN_KEY_EXCLUDE_FROM_MISSIONS, abilityInfo.excludeFromMissions},
553         {JOSN_KEY_UNCLEARABLE_MISSION, abilityInfo.unclearableMission},
554         {JSON_KEY_RECOVERABLE, abilityInfo.recoverable},
555         {JSON_KEY_SUPPORT_EXT_NAMES, abilityInfo.supportExtNames},
556         {JSON_KEY_SUPPORT_MIME_TYPES, abilityInfo.supportMimeTypes},
557     };
558     if (abilityInfo.maxWindowRatio == 0) {
559         // maxWindowRatio in json string will be 0 instead of 0.0
560         jsonObject[JOSN_KEY_MAX_WINDOW_RATIO] = 0;
561     } else {
562         jsonObject[JOSN_KEY_MAX_WINDOW_RATIO] = abilityInfo.maxWindowRatio;
563     }
564 
565     if (abilityInfo.minWindowRatio == 0) {
566         jsonObject[JOSN_KEY_MIN_WINDOW_RATIO] = 0;
567     } else {
568         jsonObject[JOSN_KEY_MIN_WINDOW_RATIO] = abilityInfo.minWindowRatio;
569     }
570 }
571 
from_json(const nlohmann::json & jsonObject,CustomizeData & customizeData)572 void from_json(const nlohmann::json &jsonObject, CustomizeData &customizeData)
573 {
574     const auto &jsonObjectEnd = jsonObject.end();
575     int32_t parseResult = ERR_OK;
576     GetValueIfFindKey<std::string>(jsonObject,
577         jsonObjectEnd,
578         JSON_KEY_NAME,
579         customizeData.name,
580         JsonType::STRING,
581         false,
582         parseResult,
583         ArrayType::NOT_ARRAY);
584     GetValueIfFindKey<std::string>(jsonObject,
585         jsonObjectEnd,
586         JSON_KEY_META_VALUE,
587         customizeData.value,
588         JsonType::STRING,
589         false,
590         parseResult,
591         ArrayType::NOT_ARRAY);
592     GetValueIfFindKey<std::string>(jsonObject,
593         jsonObjectEnd,
594         JSON_KEY_META_EXTRA,
595         customizeData.extra,
596         JsonType::STRING,
597         false,
598         parseResult,
599         ArrayType::NOT_ARRAY);
600 }
601 
from_json(const nlohmann::json & jsonObject,MetaData & metaData)602 void from_json(const nlohmann::json &jsonObject, MetaData &metaData)
603 {
604     const auto &jsonObjectEnd = jsonObject.end();
605     int32_t parseResult = ERR_OK;
606     GetValueIfFindKey<std::vector<CustomizeData>>(jsonObject,
607         jsonObjectEnd,
608         JSON_KEY_CUSTOMIZE_DATA,
609         metaData.customizeData,
610         JsonType::ARRAY,
611         false,
612         parseResult,
613         ArrayType::OBJECT);
614 }
615 
from_json(const nlohmann::json & jsonObject,Metadata & metadata)616 void from_json(const nlohmann::json &jsonObject, Metadata &metadata)
617 {
618     const auto &jsonObjectEnd = jsonObject.end();
619     int32_t parseResult = ERR_OK;
620     GetValueIfFindKey<std::string>(jsonObject,
621         jsonObjectEnd,
622         META_DATA_NAME,
623         metadata.name,
624         JsonType::STRING,
625         false,
626         parseResult,
627         ArrayType::NOT_ARRAY);
628     GetValueIfFindKey<std::string>(jsonObject,
629         jsonObjectEnd,
630         META_DATA_VALUE,
631         metadata.value,
632         JsonType::STRING,
633         false,
634         parseResult,
635         ArrayType::NOT_ARRAY);
636     GetValueIfFindKey<std::string>(jsonObject,
637         jsonObjectEnd,
638         META_DATA_RESOURCE,
639         metadata.resource,
640         JsonType::STRING,
641         false,
642         parseResult,
643         ArrayType::NOT_ARRAY);
644     if (parseResult != ERR_OK) {
645         APP_LOGE("read Ability Metadata from database error, error code : %{public}d", parseResult);
646     }
647 }
648 
from_json(const nlohmann::json & jsonObject,AbilityInfo & abilityInfo)649 void from_json(const nlohmann::json &jsonObject, AbilityInfo &abilityInfo)
650 {
651     APP_LOGD("AbilityInfo from_json begin");
652     const auto &jsonObjectEnd = jsonObject.end();
653     int32_t parseResult = ERR_OK;
654     GetValueIfFindKey<std::string>(jsonObject,
655         jsonObjectEnd,
656         JSON_KEY_NAME,
657         abilityInfo.name,
658         JsonType::STRING,
659         false,
660         parseResult,
661         ArrayType::NOT_ARRAY);
662     GetValueIfFindKey<std::string>(jsonObject,
663         jsonObjectEnd,
664         JSON_KEY_LABEL,
665         abilityInfo.label,
666         JsonType::STRING,
667         false,
668         parseResult,
669         ArrayType::NOT_ARRAY);
670     GetValueIfFindKey<std::string>(jsonObject,
671         jsonObjectEnd,
672         JSON_KEY_DESCRIPTION,
673         abilityInfo.description,
674         JsonType::STRING,
675         false,
676         parseResult,
677         ArrayType::NOT_ARRAY);
678     GetValueIfFindKey<std::string>(jsonObject,
679         jsonObjectEnd,
680         JSON_KEY_ICON_PATH,
681         abilityInfo.iconPath,
682         JsonType::STRING,
683         false,
684         parseResult,
685         ArrayType::NOT_ARRAY);
686     GetValueIfFindKey<int32_t>(jsonObject,
687         jsonObjectEnd,
688         JSON_KEY_LABEL_ID,
689         abilityInfo.labelId,
690         JsonType::NUMBER,
691         false,
692         parseResult,
693         ArrayType::NOT_ARRAY);
694     GetValueIfFindKey<int32_t>(jsonObject,
695         jsonObjectEnd,
696         JSON_KEY_DESCRIPTION_ID,
697         abilityInfo.descriptionId,
698         JsonType::NUMBER,
699         false,
700         parseResult,
701         ArrayType::NOT_ARRAY);
702     GetValueIfFindKey<int32_t>(jsonObject,
703         jsonObjectEnd,
704         JSON_KEY_ICON_ID,
705         abilityInfo.iconId,
706         JsonType::NUMBER,
707         false,
708         parseResult,
709         ArrayType::NOT_ARRAY);
710     GetValueIfFindKey<std::string>(jsonObject,
711         jsonObjectEnd,
712         JSON_KEY_THEME,
713         abilityInfo.theme,
714         JsonType::STRING,
715         false,
716         parseResult,
717         ArrayType::NOT_ARRAY);
718     GetValueIfFindKey<bool>(jsonObject,
719         jsonObjectEnd,
720         JSON_KEY_VISIBLE,
721         abilityInfo.visible,
722         JsonType::BOOLEAN,
723         false,
724         parseResult,
725         ArrayType::NOT_ARRAY);
726     GetValueIfFindKey<std::string>(jsonObject,
727         jsonObjectEnd,
728         JSON_KEY_KIND,
729         abilityInfo.kind,
730         JsonType::STRING,
731         false,
732         parseResult,
733         ArrayType::NOT_ARRAY);
734     GetValueIfFindKey<AbilityType>(jsonObject,
735         jsonObjectEnd,
736         JSON_KEY_TYPE,
737         abilityInfo.type,
738         JsonType::NUMBER,
739         false,
740         parseResult,
741         ArrayType::NOT_ARRAY);
742     GetValueIfFindKey<ExtensionAbilityType>(jsonObject,
743         jsonObjectEnd,
744         JSON_KEY_EXTENSION_ABILITY_TYPE,
745         abilityInfo.extensionAbilityType,
746         JsonType::NUMBER,
747         false,
748         parseResult,
749         ArrayType::NOT_ARRAY);
750     GetValueIfFindKey<DisplayOrientation>(jsonObject,
751         jsonObjectEnd,
752         JSON_KEY_ORIENTATION,
753         abilityInfo.orientation,
754         JsonType::NUMBER,
755         false,
756         parseResult,
757         ArrayType::NOT_ARRAY);
758     GetValueIfFindKey<LaunchMode>(jsonObject,
759         jsonObjectEnd,
760         JSON_KEY_LAUNCH_MODE,
761         abilityInfo.launchMode,
762         JsonType::NUMBER,
763         false,
764         parseResult,
765         ArrayType::NOT_ARRAY);
766     GetValueIfFindKey<std::string>(jsonObject,
767         jsonObjectEnd,
768         JSON_KEY_SRC_PATH,
769         abilityInfo.srcPath,
770         JsonType::STRING,
771         false,
772         parseResult,
773         ArrayType::NOT_ARRAY);
774     GetValueIfFindKey<std::string>(jsonObject,
775         jsonObjectEnd,
776         JSON_KEY_SRC_LANGUAGE,
777         abilityInfo.srcLanguage,
778         JsonType::STRING,
779         false,
780         parseResult,
781         ArrayType::NOT_ARRAY);
782     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
783         jsonObjectEnd,
784         JSON_KEY_PERMISSIONS,
785         abilityInfo.permissions,
786         JsonType::ARRAY,
787         false,
788         parseResult,
789         ArrayType::STRING);
790     GetValueIfFindKey<std::string>(jsonObject,
791         jsonObjectEnd,
792         JSON_KEY_PROCESS,
793         abilityInfo.process,
794         JsonType::STRING,
795         false,
796         parseResult,
797         ArrayType::NOT_ARRAY);
798     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
799         jsonObjectEnd,
800         JSON_KEY_DEVICE_TYPES,
801         abilityInfo.deviceTypes,
802         JsonType::ARRAY,
803         false,
804         parseResult,
805         ArrayType::STRING);
806     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
807         jsonObjectEnd,
808         JSON_KEY_DEVICE_CAPABILITIES,
809         abilityInfo.deviceCapabilities,
810         JsonType::ARRAY,
811         false,
812         parseResult,
813         ArrayType::STRING);
814     GetValueIfFindKey<std::string>(jsonObject,
815         jsonObjectEnd,
816         JSON_KEY_URI,
817         abilityInfo.uri,
818         JsonType::STRING,
819         false,
820         parseResult,
821         ArrayType::NOT_ARRAY);
822     GetValueIfFindKey<std::string>(jsonObject,
823         jsonObjectEnd,
824         JSON_KEY_TARGET_ABILITY,
825         abilityInfo.targetAbility,
826         JsonType::STRING,
827         false,
828         parseResult,
829         ArrayType::NOT_ARRAY);
830     GetValueIfFindKey<bool>(jsonObject,
831         jsonObjectEnd,
832         JSON_KEY_IS_LAUNCHER_ABILITY,
833         abilityInfo.isLauncherAbility,
834         JsonType::BOOLEAN,
835         false,
836         parseResult,
837         ArrayType::NOT_ARRAY);
838     GetValueIfFindKey<bool>(jsonObject,
839         jsonObjectEnd,
840         JSON_KEY_IS_NATIVE_ABILITY,
841         abilityInfo.isNativeAbility,
842         JsonType::BOOLEAN,
843         false,
844         parseResult,
845         ArrayType::NOT_ARRAY);
846     GetValueIfFindKey<bool>(jsonObject,
847         jsonObjectEnd,
848         JSON_KEY_ENABLED,
849         abilityInfo.enabled,
850         JsonType::BOOLEAN,
851         false,
852         parseResult,
853         ArrayType::NOT_ARRAY);
854     GetValueIfFindKey<bool>(jsonObject,
855         jsonObjectEnd,
856         JSON_KEY_SUPPORT_PIP_MODE,
857         abilityInfo.supportPipMode,
858         JsonType::BOOLEAN,
859         false,
860         parseResult,
861         ArrayType::NOT_ARRAY);
862     GetValueIfFindKey<bool>(jsonObject,
863         jsonObjectEnd,
864         JSON_KEY_FORM_ENABLED,
865         abilityInfo.formEnabled,
866         JsonType::BOOLEAN,
867         false,
868         parseResult,
869         ArrayType::NOT_ARRAY);
870     GetValueIfFindKey<std::string>(jsonObject,
871         jsonObjectEnd,
872         JSON_KEY_READ_PERMISSION,
873         abilityInfo.readPermission,
874         JsonType::STRING,
875         false,
876         parseResult,
877         ArrayType::NOT_ARRAY);
878     GetValueIfFindKey<std::string>(jsonObject,
879         jsonObjectEnd,
880         JSON_KEY_WRITE_PERMISSION,
881         abilityInfo.writePermission,
882         JsonType::STRING,
883         false,
884         parseResult,
885         ArrayType::NOT_ARRAY);
886     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
887         jsonObjectEnd,
888         JSON_KEY_CONFIG_CHANGES,
889         abilityInfo.configChanges,
890         JsonType::ARRAY,
891         false,
892         parseResult,
893         ArrayType::STRING);
894     GetValueIfFindKey<uint32_t>(jsonObject,
895         jsonObjectEnd,
896         JSON_KEY_FORM_ENTITY,
897         abilityInfo.formEntity,
898         JsonType::NUMBER,
899         false,
900         parseResult,
901         ArrayType::NOT_ARRAY);
902     GetValueIfFindKey<int32_t>(jsonObject,
903         jsonObjectEnd,
904         JSON_KEY_MIN_FORM_HEIGHT,
905         abilityInfo.minFormHeight,
906         JsonType::NUMBER,
907         false,
908         parseResult,
909         ArrayType::NOT_ARRAY);
910     GetValueIfFindKey<int32_t>(jsonObject,
911         jsonObjectEnd,
912         JSON_KEY_DEFAULT_FORM_HEIGHT,
913         abilityInfo.defaultFormHeight,
914         JsonType::NUMBER,
915         false,
916         parseResult,
917         ArrayType::NOT_ARRAY);
918     GetValueIfFindKey<int32_t>(jsonObject,
919         jsonObjectEnd,
920         JSON_KEY_MIN_FORM_WIDTH,
921         abilityInfo.minFormWidth,
922         JsonType::NUMBER,
923         false,
924         parseResult,
925         ArrayType::NOT_ARRAY);
926     GetValueIfFindKey<int32_t>(jsonObject,
927         jsonObjectEnd,
928         JSON_KEY_DEFAULT_FORM_WIDTH,
929         abilityInfo.defaultFormWidth,
930         JsonType::NUMBER,
931         false,
932         parseResult,
933         ArrayType::NOT_ARRAY);
934     GetValueIfFindKey<MetaData>(jsonObject,
935         jsonObjectEnd,
936         JSON_KEY_META_DATA,
937         abilityInfo.metaData,
938         JsonType::OBJECT,
939         false,
940         parseResult,
941         ArrayType::NOT_ARRAY);
942     GetValueIfFindKey<uint32_t>(jsonObject,
943         jsonObjectEnd,
944         JSON_KEY_BACKGROUND_MODES,
945         abilityInfo.backgroundModes,
946         JsonType::NUMBER,
947         false,
948         parseResult,
949         ArrayType::NOT_ARRAY);
950     GetValueIfFindKey<std::string>(jsonObject,
951         jsonObjectEnd,
952         JSON_KEY_PACKAGE,
953         abilityInfo.package,
954         JsonType::STRING,
955         false,
956         parseResult,
957         ArrayType::NOT_ARRAY);
958     GetValueIfFindKey<std::string>(jsonObject,
959         jsonObjectEnd,
960         Constants::BUNDLE_NAME,
961         abilityInfo.bundleName,
962         JsonType::STRING,
963         false,
964         parseResult,
965         ArrayType::NOT_ARRAY);
966     GetValueIfFindKey<std::string>(jsonObject,
967         jsonObjectEnd,
968         Constants::MODULE_NAME,
969         abilityInfo.moduleName,
970         JsonType::STRING,
971         false,
972         parseResult,
973         ArrayType::NOT_ARRAY);
974     GetValueIfFindKey<std::string>(jsonObject,
975         jsonObjectEnd,
976         JSON_KEY_APPLICATION_NAME,
977         abilityInfo.applicationName,
978         JsonType::STRING,
979         false,
980         parseResult,
981         ArrayType::NOT_ARRAY);
982     GetValueIfFindKey<std::string>(jsonObject,
983         jsonObjectEnd,
984         JSON_KEY_CODE_PATH,
985         abilityInfo.codePath,
986         JsonType::STRING,
987         false,
988         parseResult,
989         ArrayType::NOT_ARRAY);
990     GetValueIfFindKey<std::string>(jsonObject,
991         jsonObjectEnd,
992         JSON_KEY_RESOURCE_PATH,
993         abilityInfo.resourcePath,
994         JsonType::STRING,
995         false,
996         parseResult,
997         ArrayType::NOT_ARRAY);
998     GetValueIfFindKey<std::string>(jsonObject,
999         jsonObjectEnd,
1000         Constants::HAP_PATH,
1001         abilityInfo.hapPath,
1002         JsonType::STRING,
1003         false,
1004         parseResult,
1005         ArrayType::NOT_ARRAY);
1006     GetValueIfFindKey<std::string>(jsonObject,
1007         jsonObjectEnd,
1008         SRC_ENTRANCE,
1009         abilityInfo.srcEntrance,
1010         JsonType::STRING,
1011         false,
1012         parseResult,
1013         ArrayType::NOT_ARRAY);
1014     GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
1015         jsonObjectEnd,
1016         META_DATA,
1017         abilityInfo.metadata,
1018         JsonType::ARRAY,
1019         false,
1020         parseResult,
1021         ArrayType::OBJECT);
1022     GetValueIfFindKey<bool>(jsonObject,
1023         jsonObjectEnd,
1024         IS_MODULE_JSON,
1025         abilityInfo.isModuleJson,
1026         JsonType::BOOLEAN,
1027         false,
1028         parseResult,
1029         ArrayType::NOT_ARRAY);
1030     GetValueIfFindKey<bool>(jsonObject,
1031         jsonObjectEnd,
1032         IS_STAGE_BASED_MODEL,
1033         abilityInfo.isStageBasedModel,
1034         JsonType::BOOLEAN,
1035         false,
1036         parseResult,
1037         ArrayType::NOT_ARRAY);
1038     GetValueIfFindKey<bool>(jsonObject,
1039         jsonObjectEnd,
1040         CONTINUABLE,
1041         abilityInfo.continuable,
1042         JsonType::BOOLEAN,
1043         false,
1044         parseResult,
1045         ArrayType::NOT_ARRAY);
1046     GetValueIfFindKey<int32_t>(jsonObject,
1047         jsonObjectEnd,
1048         PRIORITY,
1049         abilityInfo.priority,
1050         JsonType::NUMBER,
1051         false,
1052         parseResult,
1053         ArrayType::NOT_ARRAY);
1054     GetValueIfFindKey<std::string>(jsonObject,
1055         jsonObjectEnd,
1056         JSON_KEY_START_WINDOW_ICON,
1057         abilityInfo.startWindowIcon,
1058         JsonType::STRING,
1059         false,
1060         parseResult,
1061         ArrayType::NOT_ARRAY);
1062     GetValueIfFindKey<int32_t>(jsonObject,
1063         jsonObjectEnd,
1064         JSON_KEY_START_WINDOW_ICON_ID,
1065         abilityInfo.startWindowIconId,
1066         JsonType::NUMBER,
1067         false,
1068         parseResult,
1069         ArrayType::NOT_ARRAY);
1070     GetValueIfFindKey<std::string>(jsonObject,
1071         jsonObjectEnd,
1072         JSON_KEY_START_WINDOW_BACKGROUND,
1073         abilityInfo.startWindowBackground,
1074         JsonType::STRING,
1075         false,
1076         parseResult,
1077         ArrayType::NOT_ARRAY);
1078     GetValueIfFindKey<int32_t>(jsonObject,
1079         jsonObjectEnd,
1080         JSON_KEY_START_WINDOW_BACKGROUND_ID,
1081         abilityInfo.startWindowBackgroundId,
1082         JsonType::NUMBER,
1083         false,
1084         parseResult,
1085         ArrayType::NOT_ARRAY);
1086     GetValueIfFindKey<bool>(jsonObject,
1087         jsonObjectEnd,
1088         JSON_KEY_REMOVE_MISSION_AFTER_TERMINATE,
1089         abilityInfo.removeMissionAfterTerminate,
1090         JsonType::BOOLEAN,
1091         false,
1092         parseResult,
1093         ArrayType::NOT_ARRAY);
1094     GetValueIfFindKey<CompileMode>(jsonObject,
1095         jsonObjectEnd,
1096         JSON_KEY_COMPILE_MODE,
1097         abilityInfo.compileMode,
1098         JsonType::NUMBER,
1099         false,
1100         parseResult,
1101         ArrayType::NOT_ARRAY);
1102     GetValueIfFindKey<std::vector<SupportWindowMode>>(jsonObject,
1103         jsonObjectEnd,
1104         JOSN_KEY_SUPPORT_WINDOW_MODE,
1105         abilityInfo.windowModes,
1106         JsonType::ARRAY,
1107         false,
1108         parseResult,
1109         ArrayType::NUMBER);
1110     GetValueIfFindKey<double>(jsonObject,
1111         jsonObjectEnd,
1112         JOSN_KEY_MAX_WINDOW_RATIO,
1113         abilityInfo.maxWindowRatio,
1114         JsonType::NUMBER,
1115         false,
1116         parseResult,
1117         ArrayType::NOT_ARRAY);
1118     GetValueIfFindKey<double>(jsonObject,
1119         jsonObjectEnd,
1120         JOSN_KEY_MIN_WINDOW_RATIO,
1121         abilityInfo.minWindowRatio,
1122         JsonType::NUMBER,
1123         false,
1124         parseResult,
1125         ArrayType::NOT_ARRAY);
1126     GetValueIfFindKey<uint32_t>(jsonObject,
1127         jsonObjectEnd,
1128         JOSN_KEY_MAX_WINDOW_WIDTH,
1129         abilityInfo.maxWindowWidth,
1130         JsonType::NUMBER,
1131         false,
1132         parseResult,
1133         ArrayType::NOT_ARRAY);
1134     GetValueIfFindKey<uint32_t>(jsonObject,
1135         jsonObjectEnd,
1136         JOSN_KEY_MIN_WINDOW_WIDTH,
1137         abilityInfo.minWindowWidth,
1138         JsonType::NUMBER,
1139         false,
1140         parseResult,
1141         ArrayType::NOT_ARRAY);
1142     GetValueIfFindKey<uint32_t>(jsonObject,
1143         jsonObjectEnd,
1144         JOSN_KEY_MAX_WINDOW_HEIGHT,
1145         abilityInfo.maxWindowHeight,
1146         JsonType::NUMBER,
1147         false,
1148         parseResult,
1149         ArrayType::NOT_ARRAY);
1150     GetValueIfFindKey<uint32_t>(jsonObject,
1151         jsonObjectEnd,
1152         JOSN_KEY_MIN_WINDOW_HEIGHT,
1153         abilityInfo.minWindowHeight,
1154         JsonType::NUMBER,
1155         false,
1156         parseResult,
1157         ArrayType::NOT_ARRAY);
1158     GetValueIfFindKey<int32_t>(jsonObject,
1159         jsonObjectEnd,
1160         JOSN_KEY_UID,
1161         abilityInfo.uid,
1162         JsonType::NUMBER,
1163         false,
1164         parseResult,
1165         ArrayType::NOT_ARRAY);
1166     GetValueIfFindKey<bool>(jsonObject,
1167         jsonObjectEnd,
1168         JOSN_KEY_EXCLUDE_FROM_MISSIONS,
1169         abilityInfo.excludeFromMissions,
1170         JsonType::BOOLEAN,
1171         false,
1172         parseResult,
1173         ArrayType::NOT_ARRAY);
1174     GetValueIfFindKey<bool>(jsonObject,
1175         jsonObjectEnd,
1176         JOSN_KEY_UNCLEARABLE_MISSION,
1177         abilityInfo.unclearableMission,
1178         JsonType::BOOLEAN,
1179         false,
1180         parseResult,
1181         ArrayType::NOT_ARRAY);
1182     GetValueIfFindKey<bool>(jsonObject,
1183         jsonObjectEnd,
1184         JSON_KEY_RECOVERABLE,
1185         abilityInfo.recoverable,
1186         JsonType::BOOLEAN,
1187         false,
1188         parseResult,
1189         ArrayType::NOT_ARRAY);
1190     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1191         jsonObjectEnd,
1192         JSON_KEY_SUPPORT_EXT_NAMES,
1193         abilityInfo.supportExtNames,
1194         JsonType::ARRAY,
1195         false,
1196         parseResult,
1197         ArrayType::STRING);
1198     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1199         jsonObjectEnd,
1200         JSON_KEY_SUPPORT_MIME_TYPES,
1201         abilityInfo.supportMimeTypes,
1202         JsonType::ARRAY,
1203         false,
1204         parseResult,
1205         ArrayType::STRING);
1206     if (parseResult != ERR_OK) {
1207         APP_LOGE("AbilityInfo from_json error, error code : %{public}d", parseResult);
1208     }
1209 }
1210 
ConvertToCompatiableAbilityInfo(CompatibleAbilityInfo & compatibleAbilityInfo) const1211 void AbilityInfo::ConvertToCompatiableAbilityInfo(CompatibleAbilityInfo& compatibleAbilityInfo) const
1212 {
1213     APP_LOGE("AbilityInfo::ConvertToCompatiableAbilityInfo called");
1214     compatibleAbilityInfo.package = package;
1215     compatibleAbilityInfo.name = name;
1216     compatibleAbilityInfo.label = label;
1217     compatibleAbilityInfo.description = description;
1218     compatibleAbilityInfo.iconPath = iconPath;
1219     compatibleAbilityInfo.uri = uri;
1220     compatibleAbilityInfo.moduleName = moduleName;
1221     compatibleAbilityInfo.process = process;
1222     compatibleAbilityInfo.targetAbility = targetAbility;
1223     compatibleAbilityInfo.appName = appName;
1224     compatibleAbilityInfo.privacyUrl = privacyUrl;
1225     compatibleAbilityInfo.privacyName = privacyName;
1226     compatibleAbilityInfo.downloadUrl = downloadUrl;
1227     compatibleAbilityInfo.versionName = versionName;
1228     compatibleAbilityInfo.backgroundModes = backgroundModes;
1229     compatibleAbilityInfo.packageSize = packageSize;
1230     compatibleAbilityInfo.visible = visible;
1231     compatibleAbilityInfo.formEnabled = formEnabled;
1232     compatibleAbilityInfo.multiUserShared = multiUserShared;
1233     compatibleAbilityInfo.type = type;
1234     compatibleAbilityInfo.subType = subType;
1235     compatibleAbilityInfo.orientation = orientation;
1236     compatibleAbilityInfo.launchMode = launchMode;
1237     compatibleAbilityInfo.permissions = permissions;
1238     compatibleAbilityInfo.deviceTypes = deviceTypes;
1239     compatibleAbilityInfo.deviceCapabilities = deviceCapabilities;
1240     compatibleAbilityInfo.supportPipMode = supportPipMode;
1241     compatibleAbilityInfo.grantPermission = grantPermission;
1242     compatibleAbilityInfo.readPermission = readPermission;
1243     compatibleAbilityInfo.writePermission = writePermission;
1244     compatibleAbilityInfo.uriPermissionMode = uriPermissionMode;
1245     compatibleAbilityInfo.uriPermissionPath = uriPermissionPath;
1246     compatibleAbilityInfo.directLaunch = directLaunch;
1247     compatibleAbilityInfo.bundleName = bundleName;
1248     compatibleAbilityInfo.className = className;
1249     compatibleAbilityInfo.originalClassName = originalClassName;
1250     compatibleAbilityInfo.deviceId = deviceId;
1251     CompatibleApplicationInfo convertedCompatibleApplicationInfo;
1252     applicationInfo.ConvertToCompatibleApplicationInfo(convertedCompatibleApplicationInfo);
1253     compatibleAbilityInfo.applicationInfo = convertedCompatibleApplicationInfo;
1254     compatibleAbilityInfo.formEntity = formEntity;
1255     compatibleAbilityInfo.minFormHeight = minFormHeight;
1256     compatibleAbilityInfo.defaultFormHeight = defaultFormHeight;
1257     compatibleAbilityInfo.minFormWidth = minFormWidth;
1258     compatibleAbilityInfo.defaultFormWidth = defaultFormWidth;
1259     compatibleAbilityInfo.iconId = iconId;
1260     compatibleAbilityInfo.labelId = labelId;
1261     compatibleAbilityInfo.descriptionId = descriptionId;
1262     compatibleAbilityInfo.enabled = enabled;
1263 }
1264 }  // namespace AppExecFwk
1265 }  // namespace OHOS
1266