1 /*
2 * Copyright (c) 2021-2025 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 <cstdint>
19 #include <errno.h>
20 #include <fcntl.h>
21 #include <string>
22 #include <unistd.h>
23
24 #include "bundle_constants.h"
25 #include "common_json_converter.h"
26 #include "json_util.h"
27 #include "nlohmann/json.hpp"
28 #include "parcel_macro.h"
29 #include "string_ex.h"
30
31 namespace OHOS {
32 namespace AppExecFwk {
33 namespace {
34 constexpr const char* META_DATA_VALUEID = "valueId";
35 constexpr const char* META_DATA_NAME = "name";
36 constexpr const char* META_DATA_VALUE = "value";
37 constexpr const char* META_DATA_RESOURCE = "resource";
38 constexpr const char* START_WINDOW_APP_ICON_ID = "startWindowAppIconId";
39 constexpr const char* START_WINDOW_ILLUSTRATION_ID = "startWindowIllustrationId";
40 constexpr const char* START_WINDOW_BRANDING_IMAGE_ID = "startWindowBrandingImageId";
41 constexpr const char* START_WINDOW_BACKGROUND_COLOR_ID = "startWindowBackgroundColorId";
42 constexpr const char* START_WINDOW_BACKGROUND_IMAGE_ID = "startWindowBackgroundImageId";
43 constexpr const char* START_WINDOW_BACKGROUND_IMAGE_FIT = "startWindowBackgroundImageFit";
44 constexpr const uint32_t ABILITY_CAPACITY = 204800; // 200K
45 } // namespace
46
ReadFromParcel(Parcel & parcel)47 bool AbilityInfo::ReadFromParcel(Parcel &parcel)
48 {
49 name = Str16ToStr8(parcel.ReadString16());
50 label = Str16ToStr8(parcel.ReadString16());
51 description = Str16ToStr8(parcel.ReadString16());
52 iconPath = Str16ToStr8(parcel.ReadString16());
53 labelId = parcel.ReadUint32();
54 descriptionId = parcel.ReadUint32();
55 iconId = parcel.ReadUint32();
56 theme = Str16ToStr8(parcel.ReadString16());
57 visible = parcel.ReadBool();
58 kind = Str16ToStr8(parcel.ReadString16());
59 type = static_cast<AbilityType>(parcel.ReadInt32());
60 extensionTypeName = Str16ToStr8(parcel.ReadString16());
61 extensionAbilityType = static_cast<ExtensionAbilityType>(parcel.ReadInt32());
62 orientation = static_cast<DisplayOrientation>(parcel.ReadInt32());
63 launchMode = static_cast<LaunchMode>(parcel.ReadInt32());
64 srcPath = Str16ToStr8(parcel.ReadString16());
65 srcLanguage = Str16ToStr8(parcel.ReadString16());
66 arkTSMode = parcel.ReadString();
67
68 int32_t permissionsSize;
69 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, permissionsSize);
70 CONTAINER_SECURITY_VERIFY(parcel, permissionsSize, &permissions);
71 for (auto i = 0; i < permissionsSize; i++) {
72 permissions.emplace_back(Str16ToStr8(parcel.ReadString16()));
73 }
74
75 process = Str16ToStr8(parcel.ReadString16());
76
77 int32_t deviceTypesSize;
78 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceTypesSize);
79 CONTAINER_SECURITY_VERIFY(parcel, deviceTypesSize, &deviceTypes);
80 for (auto i = 0; i < deviceTypesSize; i++) {
81 deviceTypes.emplace_back(Str16ToStr8(parcel.ReadString16()));
82 }
83
84 int32_t deviceCapabilitiesSize;
85 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceCapabilitiesSize);
86 CONTAINER_SECURITY_VERIFY(parcel, deviceCapabilitiesSize, &deviceCapabilities);
87 for (auto i = 0; i < deviceCapabilitiesSize; i++) {
88 deviceCapabilities.emplace_back(Str16ToStr8(parcel.ReadString16()));
89 }
90 uri = Str16ToStr8(parcel.ReadString16());
91 targetAbility = Str16ToStr8(parcel.ReadString16());
92
93 std::unique_ptr<ApplicationInfo> appInfo(parcel.ReadParcelable<ApplicationInfo>());
94 if (!appInfo) {
95 APP_LOGE("ReadParcelable<ApplicationInfo> failed");
96 return false;
97 }
98 applicationInfo = *appInfo;
99
100 isLauncherAbility = parcel.ReadBool();
101 isNativeAbility = parcel.ReadBool();
102 enabled = parcel.ReadBool();
103 supportPipMode = parcel.ReadBool();
104 formEnabled = parcel.ReadBool();
105 removeMissionAfterTerminate = parcel.ReadBool();
106
107 readPermission = Str16ToStr8(parcel.ReadString16());
108 writePermission = Str16ToStr8(parcel.ReadString16());
109 int32_t configChangesSize;
110 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, configChangesSize);
111 CONTAINER_SECURITY_VERIFY(parcel, configChangesSize, &configChanges);
112 for (auto i = 0; i < configChangesSize; i++) {
113 configChanges.emplace_back(Str16ToStr8(parcel.ReadString16()));
114 }
115 formEntity = parcel.ReadUint32();
116 minFormHeight = parcel.ReadInt32();
117 defaultFormHeight = parcel.ReadInt32();
118 minFormWidth = parcel.ReadInt32();
119 defaultFormWidth = parcel.ReadInt32();
120 int32_t metaDataSize;
121 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metaDataSize);
122 CONTAINER_SECURITY_VERIFY(parcel, metaDataSize, &metaData.customizeData);
123 for (auto i = 0; i < metaDataSize; i++) {
124 std::unique_ptr<CustomizeData> customizeDataPtr(parcel.ReadParcelable<CustomizeData>());
125 if (!customizeDataPtr) {
126 APP_LOGE("ReadParcelable<Metadata> failed");
127 return false;
128 }
129 metaData.customizeData.emplace_back(*customizeDataPtr);
130 }
131 backgroundModes = parcel.ReadUint32();
132
133 package = Str16ToStr8(parcel.ReadString16());
134 bundleName = Str16ToStr8(parcel.ReadString16());
135 moduleName = Str16ToStr8(parcel.ReadString16());
136 applicationName = Str16ToStr8(parcel.ReadString16());
137
138 codePath = Str16ToStr8(parcel.ReadString16());
139 resourcePath = Str16ToStr8(parcel.ReadString16());
140 hapPath = Str16ToStr8(parcel.ReadString16());
141
142 srcEntrance = Str16ToStr8(parcel.ReadString16());
143 int32_t metadataSize;
144 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metadataSize);
145 CONTAINER_SECURITY_VERIFY(parcel, metadataSize, &metadata);
146 for (auto i = 0; i < metadataSize; i++) {
147 std::unique_ptr<Metadata> metadataPtr(parcel.ReadParcelable<Metadata>());
148 if (!metadataPtr) {
149 APP_LOGE("ReadParcelable<Metadata> failed");
150 return false;
151 }
152 metadata.emplace_back(*metadataPtr);
153 }
154 isModuleJson = parcel.ReadBool();
155 isStageBasedModel = parcel.ReadBool();
156 continuable = parcel.ReadBool();
157 priority = parcel.ReadInt32();
158
159 startWindow = Str16ToStr8(parcel.ReadString16());
160 startWindowId = parcel.ReadUint32();
161 startWindowIcon = Str16ToStr8(parcel.ReadString16());
162 startWindowIconId = parcel.ReadUint32();
163 startWindowBackground = Str16ToStr8(parcel.ReadString16());
164 startWindowBackgroundId = parcel.ReadUint32();
165
166 originalBundleName = Str16ToStr8(parcel.ReadString16());
167 appName = Str16ToStr8(parcel.ReadString16());
168 privacyUrl = Str16ToStr8(parcel.ReadString16());
169 privacyName = Str16ToStr8(parcel.ReadString16());
170 downloadUrl = Str16ToStr8(parcel.ReadString16());
171 versionName = Str16ToStr8(parcel.ReadString16());
172 className = Str16ToStr8(parcel.ReadString16());
173 originalClassName = Str16ToStr8(parcel.ReadString16());
174 uriPermissionMode = Str16ToStr8(parcel.ReadString16());
175 uriPermissionPath = Str16ToStr8(parcel.ReadString16());
176 packageSize = parcel.ReadUint32();
177 multiUserShared = parcel.ReadBool();
178 grantPermission = parcel.ReadBool();
179 directLaunch = parcel.ReadBool();
180 subType = static_cast<AbilitySubType>(parcel.ReadInt32());
181 libPath = Str16ToStr8(parcel.ReadString16());
182 deviceId = Str16ToStr8(parcel.ReadString16());
183 compileMode = static_cast<CompileMode>(parcel.ReadInt32());
184
185 int32_t windowModeSize = parcel.ReadInt32();
186 CONTAINER_SECURITY_VERIFY(parcel, windowModeSize, &windowModes);
187 for (auto index = 0; index < windowModeSize; ++index) {
188 windowModes.emplace_back(static_cast<SupportWindowMode>(parcel.ReadInt32()));
189 }
190 maxWindowRatio = parcel.ReadDouble();
191 minWindowRatio = parcel.ReadDouble();
192 maxWindowWidth = parcel.ReadUint32();
193 minWindowWidth = parcel.ReadUint32();
194 maxWindowHeight = parcel.ReadUint32();
195 minWindowHeight = parcel.ReadUint32();
196 uid = parcel.ReadInt32();
197 recoverable = parcel.ReadBool();
198 installTime = parcel.ReadInt64();
199 int32_t supportExtNameSize;
200 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportExtNameSize);
201 CONTAINER_SECURITY_VERIFY(parcel, supportExtNameSize, &supportExtNames);
202 for (auto i = 0; i < supportExtNameSize; i++) {
203 supportExtNames.emplace_back(Str16ToStr8(parcel.ReadString16()));
204 }
205 int32_t supportMimeTypeSize;
206 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportMimeTypeSize);
207 CONTAINER_SECURITY_VERIFY(parcel, supportMimeTypeSize, &supportMimeTypes);
208 for (auto i = 0; i < supportMimeTypeSize; i++) {
209 supportMimeTypes.emplace_back(Str16ToStr8(parcel.ReadString16()));
210 }
211 int32_t skillUriSize;
212 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, skillUriSize);
213 CONTAINER_SECURITY_VERIFY(parcel, skillUriSize, &skillUri);
214 for (auto i = 0; i < skillUriSize; i++) {
215 SkillUriForAbilityAndExtension stctUri;
216 stctUri.scheme = Str16ToStr8(parcel.ReadString16());
217 stctUri.host = Str16ToStr8(parcel.ReadString16());
218 stctUri.port = Str16ToStr8(parcel.ReadString16());
219 stctUri.path = Str16ToStr8(parcel.ReadString16());
220 stctUri.pathStartWith = Str16ToStr8(parcel.ReadString16());
221 stctUri.pathRegex = Str16ToStr8(parcel.ReadString16());
222 stctUri.type = Str16ToStr8(parcel.ReadString16());
223 stctUri.utd = Str16ToStr8(parcel.ReadString16());
224 stctUri.maxFileSupported = parcel.ReadInt32();
225 stctUri.linkFeature = Str16ToStr8(parcel.ReadString16());
226 stctUri.isMatch = parcel.ReadBool();
227 skillUri.emplace_back(stctUri);
228 }
229 isolationProcess = parcel.ReadBool();
230 excludeFromMissions = parcel.ReadBool();
231 unclearableMission = parcel.ReadBool();
232 excludeFromDock = parcel.ReadBool();
233 preferMultiWindowOrientation = Str16ToStr8(parcel.ReadString16());
234 int32_t continueTypeSize;
235 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, continueTypeSize);
236 CONTAINER_SECURITY_VERIFY(parcel, continueTypeSize, &continueType);
237 for (auto i = 0; i < continueTypeSize; i++) {
238 continueType.emplace_back(Str16ToStr8(parcel.ReadString16()));
239 }
240
241 int32_t continueBundleNameSize = 0;
242 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, continueBundleNameSize);
243 CONTAINER_SECURITY_VERIFY(parcel, continueBundleNameSize, &continueBundleNames);
244 for (auto i = 0; i < continueBundleNameSize; ++i) {
245 continueBundleNames.emplace(Str16ToStr8(parcel.ReadString16()));
246 }
247
248 linkType = static_cast<LinkType>(parcel.ReadInt32());
249
250 int32_t skillsSize;
251 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, skillsSize);
252 CONTAINER_SECURITY_VERIFY(parcel, skillsSize, &skills);
253 for (auto i = 0; i < skillsSize; i++) {
254 std::unique_ptr<Skill> abilitySkillPtr(parcel.ReadParcelable<Skill>());
255 if (!abilitySkillPtr) {
256 APP_LOGE("ReadParcelable<SkillForAbility> failed");
257 return false;
258 }
259 skills.emplace_back(*abilitySkillPtr);
260 }
261 appIndex = parcel.ReadInt32();
262 orientationId = parcel.ReadUint32();
263 std::unique_ptr<StartWindowResource> startWindowResourcePtr(parcel.ReadParcelable<StartWindowResource>());
264 if (!startWindowResourcePtr) {
265 APP_LOGE("ReadParcelable<StartWindowResource> failed");
266 return false;
267 }
268 startWindowResource = *startWindowResourcePtr;
269 return true;
270 }
271
Unmarshalling(Parcel & parcel)272 AbilityInfo *AbilityInfo::Unmarshalling(Parcel &parcel)
273 {
274 AbilityInfo *info = new (std::nothrow) AbilityInfo();
275 if (info && !info->ReadFromParcel(parcel)) {
276 APP_LOGW("read from parcel failed");
277 delete info;
278 info = nullptr;
279 }
280 return info;
281 }
282
Marshalling(Parcel & parcel) const283 bool AbilityInfo::Marshalling(Parcel &parcel) const
284 {
285 CHECK_PARCEL_CAPACITY(parcel, ABILITY_CAPACITY);
286 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
287 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label));
288 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(description));
289 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(iconPath));
290 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, labelId);
291 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, descriptionId);
292 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, iconId);
293 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(theme));
294 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, visible);
295 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(kind));
296 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(type));
297 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(extensionTypeName));
298 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(extensionAbilityType));
299 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(orientation));
300 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(launchMode));
301 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcPath));
302 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcLanguage));
303 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, arkTSMode);
304 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, permissions.size());
305 for (auto &permission : permissions) {
306 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(permission));
307 }
308
309 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(process));
310 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceTypes.size());
311 for (auto &deviceType : deviceTypes) {
312 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceType));
313 }
314
315 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, deviceCapabilities.size());
316 for (auto &deviceCapability : deviceCapabilities) {
317 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceCapability));
318 }
319 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri));
320 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetAbility));
321 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &applicationInfo);
322 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isLauncherAbility);
323 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isNativeAbility);
324 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, enabled);
325 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, supportPipMode);
326 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, formEnabled);
327 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, removeMissionAfterTerminate);
328 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(readPermission));
329 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(writePermission));
330 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, configChanges.size());
331 for (auto &configChange : configChanges) {
332 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(configChange));
333 }
334 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, formEntity);
335 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, minFormHeight);
336 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, defaultFormHeight);
337 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, minFormWidth);
338 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, defaultFormWidth);
339 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metaData.customizeData.size());
340 for (auto &meta : metaData.customizeData) {
341 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &meta);
342 }
343 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, backgroundModes);
344
345 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(package));
346 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
347 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
348 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(applicationName));
349 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(codePath));
350 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(resourcePath));
351 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hapPath));
352
353 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcEntrance));
354
355 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metadata.size());
356 for (auto &meta : metadata) {
357 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &meta);
358 }
359
360 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isModuleJson);
361 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isStageBasedModel);
362 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, continuable);
363 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, priority);
364
365 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(startWindow));
366 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowId);
367 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(startWindowIcon));
368 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowIconId);
369 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(startWindowBackground));
370 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowBackgroundId);
371
372 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(originalBundleName));
373 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appName));
374 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(privacyUrl));
375 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(privacyName));
376 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(downloadUrl));
377 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(versionName));
378 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(className));
379 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(originalClassName));
380 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uriPermissionMode));
381 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uriPermissionPath));
382 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, packageSize);
383 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, multiUserShared);
384 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, grantPermission);
385 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, directLaunch);
386 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(subType));
387 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(libPath));
388 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceId));
389 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(compileMode));
390
391 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowModes.size());
392 for (auto &mode : windowModes) {
393 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(mode));
394 }
395 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Double, parcel, maxWindowRatio);
396 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Double, parcel, minWindowRatio);
397 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, maxWindowWidth);
398 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, minWindowWidth);
399 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, maxWindowHeight);
400 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, minWindowHeight);
401 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
402 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, recoverable);
403 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, installTime);
404 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportExtNames.size());
405 for (auto &supporExtName : supportExtNames) {
406 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(supporExtName));
407 }
408 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportMimeTypes.size());
409 for (auto &supportMimeType : supportMimeTypes) {
410 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(supportMimeType));
411 }
412 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, skillUri.size());
413 for (auto &uri : skillUri) {
414 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.scheme));
415 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.host));
416 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.port));
417 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.path));
418 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.pathStartWith));
419 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.pathRegex));
420 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.type));
421 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.utd));
422 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uri.maxFileSupported);
423 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(uri.linkFeature));
424 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, uri.isMatch);
425 }
426 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isolationProcess);
427 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, excludeFromMissions);
428 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, unclearableMission);
429 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, excludeFromDock);
430 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(preferMultiWindowOrientation));
431 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, continueType.size());
432 for (auto &continueTypeItem : continueType) {
433 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(continueTypeItem));
434 }
435 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, continueBundleNames.size());
436 for (auto &continueBundleNameItem : continueBundleNames) {
437 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(continueBundleNameItem));
438 }
439 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(linkType));
440 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, skills.size());
441 for (auto &skill : skills) {
442 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &skill);
443 }
444 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex);
445 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, orientationId);
446 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &startWindowResource);
447 return true;
448 }
449
Dump(std::string prefix,int fd)450 void AbilityInfo::Dump(std::string prefix, int fd)
451 {
452 APP_LOGI("call Dump");
453 if (fd < 0) {
454 APP_LOGE("dump Abilityinfo fd error");
455 return;
456 }
457 int flags = fcntl(fd, F_GETFL);
458 if (flags < 0) {
459 APP_LOGE("dump Abilityinfo fcntl error : %{public}d", errno);
460 return;
461 }
462 uint uflags = static_cast<uint>(flags);
463 uflags &= O_ACCMODE;
464 if ((uflags == O_WRONLY) || (uflags == O_RDWR)) {
465 nlohmann::json jsonObject = *this;
466 std::string result;
467 result.append(prefix);
468 result.append(jsonObject.dump(Constants::DUMP_INDENT));
469 int ret = TEMP_FAILURE_RETRY(write(fd, result.c_str(), result.size()));
470 if (ret < 0) {
471 APP_LOGE("dump Abilityinfo write error : %{public}d", errno);
472 }
473 }
474 return;
475 }
476
to_json(nlohmann::json & jsonObject,const StartWindowResource & startWindowResource)477 void to_json(nlohmann::json &jsonObject, const StartWindowResource &startWindowResource)
478 {
479 jsonObject = nlohmann::json {
480 {START_WINDOW_APP_ICON_ID, startWindowResource.startWindowAppIconId},
481 {START_WINDOW_ILLUSTRATION_ID, startWindowResource.startWindowIllustrationId},
482 {START_WINDOW_BRANDING_IMAGE_ID, startWindowResource.startWindowBrandingImageId},
483 {START_WINDOW_BACKGROUND_COLOR_ID, startWindowResource.startWindowBackgroundColorId},
484 {START_WINDOW_BACKGROUND_IMAGE_ID, startWindowResource.startWindowBackgroundImageId},
485 {START_WINDOW_BACKGROUND_IMAGE_FIT, startWindowResource.startWindowBackgroundImageFit}
486 };
487 }
488
from_json(const nlohmann::json & jsonObject,StartWindowResource & startWindowResource)489 void from_json(const nlohmann::json &jsonObject, StartWindowResource &startWindowResource)
490 {
491 const auto &jsonObjectEnd = jsonObject.end();
492 int32_t parseResult = ERR_OK;
493 GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd,
494 START_WINDOW_APP_ICON_ID,
495 startWindowResource.startWindowAppIconId,
496 JsonType::NUMBER, false,
497 parseResult,
498 ArrayType::NOT_ARRAY);
499 GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd,
500 START_WINDOW_ILLUSTRATION_ID,
501 startWindowResource.startWindowIllustrationId,
502 JsonType::NUMBER, false,
503 parseResult,
504 ArrayType::NOT_ARRAY);
505 GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd,
506 START_WINDOW_BRANDING_IMAGE_ID,
507 startWindowResource.startWindowBrandingImageId,
508 JsonType::NUMBER, false,
509 parseResult,
510 ArrayType::NOT_ARRAY);
511 GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd,
512 START_WINDOW_BACKGROUND_COLOR_ID,
513 startWindowResource.startWindowBackgroundColorId,
514 JsonType::NUMBER, false,
515 parseResult,
516 ArrayType::NOT_ARRAY);
517 GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd,
518 START_WINDOW_BACKGROUND_IMAGE_ID,
519 startWindowResource.startWindowBackgroundImageId,
520 JsonType::NUMBER, false,
521 parseResult,
522 ArrayType::NOT_ARRAY);
523 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, jsonObjectEnd,
524 START_WINDOW_BACKGROUND_IMAGE_FIT,
525 startWindowResource.startWindowBackgroundImageFit,
526 false,
527 parseResult);
528 if (parseResult != ERR_OK) {
529 APP_LOGE("read Resource error %{public}d", parseResult);
530 }
531 }
532
to_json(nlohmann::json & jsonObject,const CustomizeData & customizeData)533 void to_json(nlohmann::json &jsonObject, const CustomizeData &customizeData)
534 {
535 jsonObject = nlohmann::json {
536 {JSON_KEY_NAME, customizeData.name},
537 {JSON_KEY_META_VALUE, customizeData.value},
538 {JSON_KEY_META_EXTRA, customizeData.extra}
539 };
540 }
541
to_json(nlohmann::json & jsonObject,const MetaData & metaData)542 void to_json(nlohmann::json &jsonObject, const MetaData &metaData)
543 {
544 jsonObject = nlohmann::json {
545 {JSON_KEY_CUSTOMIZE_DATA, metaData.customizeData}
546 };
547 }
548
to_json(nlohmann::json & jsonObject,const Metadata & metadata)549 void to_json(nlohmann::json &jsonObject, const Metadata &metadata)
550 {
551 jsonObject = nlohmann::json {
552 {META_DATA_VALUEID, metadata.valueId},
553 {META_DATA_NAME, metadata.name},
554 {META_DATA_VALUE, metadata.value},
555 {META_DATA_RESOURCE, metadata.resource}
556 };
557 }
558
to_json(nlohmann::json & jsonObject,const AbilityInfo & abilityInfo)559 void to_json(nlohmann::json &jsonObject, const AbilityInfo &abilityInfo)
560 {
561 APP_LOGD("AbilityInfo to_json begin");
562 AbilityToJson(jsonObject, abilityInfo);
563 }
564
from_json(const nlohmann::json & jsonObject,CustomizeData & customizeData)565 void from_json(const nlohmann::json &jsonObject, CustomizeData &customizeData)
566 {
567 const auto &jsonObjectEnd = jsonObject.end();
568 int32_t parseResult = ERR_OK;
569 BMSJsonUtil::GetStrValueIfFindKey(jsonObject,
570 jsonObjectEnd,
571 JSON_KEY_NAME,
572 customizeData.name,
573 false,
574 parseResult);
575 BMSJsonUtil::GetStrValueIfFindKey(jsonObject,
576 jsonObjectEnd,
577 JSON_KEY_META_VALUE,
578 customizeData.value,
579 false,
580 parseResult);
581 BMSJsonUtil::GetStrValueIfFindKey(jsonObject,
582 jsonObjectEnd,
583 JSON_KEY_META_EXTRA,
584 customizeData.extra,
585 false,
586 parseResult);
587 }
588
from_json(const nlohmann::json & jsonObject,MetaData & metaData)589 void from_json(const nlohmann::json &jsonObject, MetaData &metaData)
590 {
591 const auto &jsonObjectEnd = jsonObject.end();
592 int32_t parseResult = ERR_OK;
593 GetValueIfFindKey<std::vector<CustomizeData>>(jsonObject,
594 jsonObjectEnd,
595 JSON_KEY_CUSTOMIZE_DATA,
596 metaData.customizeData,
597 JsonType::ARRAY,
598 false,
599 parseResult,
600 ArrayType::OBJECT);
601 }
602
from_json(const nlohmann::json & jsonObject,Metadata & metadata)603 void from_json(const nlohmann::json &jsonObject, Metadata &metadata)
604 {
605 const auto &jsonObjectEnd = jsonObject.end();
606 int32_t parseResult = ERR_OK;
607 GetValueIfFindKey<uint32_t>(jsonObject,
608 jsonObjectEnd,
609 META_DATA_VALUEID,
610 metadata.valueId,
611 JsonType::NUMBER,
612 false,
613 parseResult,
614 ArrayType::NOT_ARRAY);
615 BMSJsonUtil::GetStrValueIfFindKey(jsonObject,
616 jsonObjectEnd,
617 META_DATA_NAME,
618 metadata.name,
619 false,
620 parseResult);
621 BMSJsonUtil::GetStrValueIfFindKey(jsonObject,
622 jsonObjectEnd,
623 META_DATA_VALUE,
624 metadata.value,
625 false,
626 parseResult);
627 BMSJsonUtil::GetStrValueIfFindKey(jsonObject,
628 jsonObjectEnd,
629 META_DATA_RESOURCE,
630 metadata.resource,
631 false,
632 parseResult);
633 if (parseResult != ERR_OK) {
634 APP_LOGE("read database error : %{public}d", parseResult);
635 }
636 }
637
from_json(const nlohmann::json & jsonObject,AbilityInfo & abilityInfo)638 void from_json(const nlohmann::json &jsonObject, AbilityInfo &abilityInfo)
639 {
640 APP_LOGD("AbilityInfo from_json begin");
641 AbilityFromJson(jsonObject, abilityInfo);
642 }
643
ConvertToCompatiableAbilityInfo(CompatibleAbilityInfo & compatibleAbilityInfo) const644 void AbilityInfo::ConvertToCompatiableAbilityInfo(CompatibleAbilityInfo& compatibleAbilityInfo) const
645 {
646 APP_LOGE("AbilityInfo::ConvertToCompatiableAbilityInfo called");
647 compatibleAbilityInfo.package = package;
648 compatibleAbilityInfo.name = name;
649 compatibleAbilityInfo.label = label;
650 compatibleAbilityInfo.description = description;
651 compatibleAbilityInfo.iconPath = iconPath;
652 compatibleAbilityInfo.uri = uri;
653 compatibleAbilityInfo.moduleName = moduleName;
654 compatibleAbilityInfo.process = process;
655 compatibleAbilityInfo.targetAbility = targetAbility;
656 compatibleAbilityInfo.appName = appName;
657 compatibleAbilityInfo.privacyUrl = privacyUrl;
658 compatibleAbilityInfo.privacyName = privacyName;
659 compatibleAbilityInfo.downloadUrl = downloadUrl;
660 compatibleAbilityInfo.versionName = versionName;
661 compatibleAbilityInfo.backgroundModes = backgroundModes;
662 compatibleAbilityInfo.packageSize = packageSize;
663 compatibleAbilityInfo.visible = visible;
664 compatibleAbilityInfo.formEnabled = formEnabled;
665 compatibleAbilityInfo.multiUserShared = multiUserShared;
666 compatibleAbilityInfo.type = type;
667 compatibleAbilityInfo.subType = subType;
668 compatibleAbilityInfo.orientation = orientation;
669 compatibleAbilityInfo.launchMode = launchMode;
670 compatibleAbilityInfo.permissions = permissions;
671 compatibleAbilityInfo.deviceTypes = deviceTypes;
672 compatibleAbilityInfo.deviceCapabilities = deviceCapabilities;
673 compatibleAbilityInfo.supportPipMode = supportPipMode;
674 compatibleAbilityInfo.grantPermission = grantPermission;
675 compatibleAbilityInfo.readPermission = readPermission;
676 compatibleAbilityInfo.writePermission = writePermission;
677 compatibleAbilityInfo.uriPermissionMode = uriPermissionMode;
678 compatibleAbilityInfo.uriPermissionPath = uriPermissionPath;
679 compatibleAbilityInfo.directLaunch = directLaunch;
680 compatibleAbilityInfo.bundleName = bundleName;
681 compatibleAbilityInfo.className = className;
682 compatibleAbilityInfo.originalClassName = originalClassName;
683 compatibleAbilityInfo.deviceId = deviceId;
684 CompatibleApplicationInfo convertedCompatibleApplicationInfo;
685 applicationInfo.ConvertToCompatibleApplicationInfo(convertedCompatibleApplicationInfo);
686 compatibleAbilityInfo.applicationInfo = convertedCompatibleApplicationInfo;
687 compatibleAbilityInfo.formEntity = formEntity;
688 compatibleAbilityInfo.minFormHeight = minFormHeight;
689 compatibleAbilityInfo.defaultFormHeight = defaultFormHeight;
690 compatibleAbilityInfo.minFormWidth = minFormWidth;
691 compatibleAbilityInfo.defaultFormWidth = defaultFormWidth;
692 compatibleAbilityInfo.iconId = iconId;
693 compatibleAbilityInfo.labelId = labelId;
694 compatibleAbilityInfo.descriptionId = descriptionId;
695 compatibleAbilityInfo.enabled = enabled;
696 }
697
ReadFromParcel(Parcel & parcel)698 bool StartWindowResource::ReadFromParcel(Parcel &parcel)
699 {
700 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowAppIconId);
701 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowIllustrationId);
702 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowBrandingImageId);
703 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowBackgroundColorId);
704 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowBackgroundImageId);
705 std::u16string startWindowBackgroundImageFitVal;
706 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, startWindowBackgroundImageFitVal);
707 startWindowBackgroundImageFit = Str16ToStr8(startWindowBackgroundImageFitVal);
708 return true;
709 }
710
Marshalling(Parcel & parcel) const711 bool StartWindowResource::Marshalling(Parcel &parcel) const
712 {
713 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowAppIconId);
714 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowIllustrationId);
715 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowBrandingImageId);
716 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowBackgroundColorId);
717 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, startWindowBackgroundImageId);
718 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(startWindowBackgroundImageFit));
719 return true;
720 }
721
Unmarshalling(Parcel & parcel)722 StartWindowResource *StartWindowResource::Unmarshalling(Parcel &parcel)
723 {
724 StartWindowResource *startWindowResource = new (std::nothrow) StartWindowResource;
725 if (startWindowResource && !startWindowResource->ReadFromParcel(parcel)) {
726 APP_LOGE("read from parcel failed");
727 delete startWindowResource;
728 startWindowResource = nullptr;
729 }
730 return startWindowResource;
731 }
732 } // namespace AppExecFwk
733 } // namespace OHOS
734