1 /*
2 * Copyright (c) 2021-2024 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 "pre_bundle_profile.h"
17
18 namespace OHOS {
19 namespace AppExecFwk {
20 namespace {
21 constexpr int8_t COMMON_PRIORITY = 0;
22 constexpr int8_t HIGH_PRIORITY = 1;
23 constexpr const char* INSTALL_LIST = "install_list";
24 constexpr const char* APP_LIST = "app_list";
25 constexpr const char* ON_DEMAND_INSTALL_LIST = "on_demand_install_list";
26 constexpr const char* UNINSTALL_LIST = "uninstall_list";
27 constexpr const char* EXTENSION_TYPE = "extensionType";
28 constexpr const char* RECOVER_LIST = "recover_list";
29 constexpr const char* ARK_STARTUP_SNAPSHOT_LIST = "ark_startup_snapshot_list";
30 constexpr const char* APP_DIR = "app_dir";
31 constexpr const char* REMOVABLE = "removable";
32 constexpr const char* APPIDENTIFIER = "appIdentifier";
33 constexpr const char* ON_DEMAND_INSTALL = "on_demand_install";
34 constexpr const char* BUNDLE_NAME = "bundleName";
35 constexpr const char* TYPE_NAME = "name";
36 constexpr const char* KEEP_ALIVE = "keepAlive";
37 constexpr const char* SINGLETON = "singleton";
38 constexpr const char* ALLOW_COMMON_EVENT = "allowCommonEvent";
39 constexpr const char* RUNNING_RESOURCES_APPLY = "runningResourcesApply";
40 constexpr const char* APP_SIGNATURE = "app_signature";
41 constexpr const char* ASSOCIATED_WAKE_UP = "associatedWakeUp";
42 constexpr const char* RESOURCES_PATH_1 = "/app/ohos.global.systemres";
43 constexpr const char* RESOURCES_PATH_2 = "/app/SystemResources";
44 constexpr const char* DATA_PRELOAD_APP = "/data/preload/app/";
45 constexpr const char* ALLOW_APP_DATA_NOT_CLEARED = "allowAppDataNotCleared";
46 constexpr const char* ALLOW_APP_MULTI_PROCESS = "allowAppMultiProcess";
47 constexpr const char* ALLOW_APP_DESKTOP_ICON_HIDE = "allowAppDesktopIconHide";
48 constexpr const char* ALLOW_ABILITY_PRIORITY_QUERIED = "allowAbilityPriorityQueried";
49 constexpr const char* ALLOW_ABILITY_EXCLUDE_FROM_MISSIONS = "allowAbilityExcludeFromMissions";
50 constexpr const char* ALLOW_MISSION_NOT_CLEARED = "allowMissionNotCleared";
51 constexpr const char* ALLOW_APP_USE_PRIVILEGE_EXTENSION = "allowAppUsePrivilegeExtension";
52 constexpr const char* ALLOW_FORM_VISIBLE_NOTIFY = "allowFormVisibleNotify";
53 constexpr const char* ALLOW_APP_SHARE_LIBRARY = "allowAppShareLibrary";
54 constexpr const char* ALLOW_ENABLE_NOTIFICATION = "allowEnableNotification";
55 constexpr const char* ALLOW_APP_RUN_WHEN_DEVICE_FIRST_LOCKED = "allowAppRunWhenDeviceFirstLocked";
56 constexpr const char* RESOURCES_APPLY = "resourcesApply";
57 }
58
TransformTo(const nlohmann::json & jsonBuf,std::set<PreScanInfo> & scanInfos) const59 ErrCode PreBundleProfile::TransformTo(
60 const nlohmann::json &jsonBuf,
61 std::set<PreScanInfo> &scanInfos) const
62 {
63 APP_LOGI_NOFUNC("transform jsonBuf to PreScanInfos");
64 if (jsonBuf.is_discarded()) {
65 APP_LOGE("profile format error");
66 return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
67 }
68
69 if (jsonBuf.find(INSTALL_LIST) == jsonBuf.end()) {
70 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
71 }
72
73 auto arrays = jsonBuf.at(INSTALL_LIST);
74 if (!arrays.is_array() || arrays.empty()) {
75 APP_LOGE("value is not array");
76 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
77 }
78 int32_t result = ERR_OK;
79 PreScanInfo preScanInfo;
80 for (const auto &array : arrays) {
81 if (!array.is_object()) {
82 APP_LOGE("array is not json object");
83 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
84 }
85
86 preScanInfo.Reset();
87 const auto &jsonObjectEnd = array.end();
88 int32_t parseResult = ERR_OK;
89 BMSJsonUtil::GetStrValueIfFindKey(array,
90 jsonObjectEnd,
91 APP_DIR,
92 preScanInfo.bundleDir,
93 true,
94 parseResult);
95 BMSJsonUtil::GetBoolValueIfFindKey(array,
96 jsonObjectEnd,
97 REMOVABLE,
98 preScanInfo.removable,
99 false,
100 parseResult);
101 bool isResourcesPath =
102 (preScanInfo.bundleDir.find(RESOURCES_PATH_1) != preScanInfo.bundleDir.npos) ||
103 (preScanInfo.bundleDir.find(RESOURCES_PATH_2) != preScanInfo.bundleDir.npos);
104 preScanInfo.priority = isResourcesPath ? HIGH_PRIORITY : COMMON_PRIORITY;
105 if (parseResult == ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP) {
106 APP_LOGE("bundleDir must exist, and it is empty here");
107 continue;
108 }
109
110 if (parseResult != ERR_OK) {
111 APP_LOGE("parse from install json failed, error %{public}d", parseResult);
112 result = parseResult;
113 continue;
114 }
115
116 APP_LOGD("preScanInfo(%{public}s)", preScanInfo.ToString().c_str());
117 auto iter = std::find(scanInfos.begin(), scanInfos.end(), preScanInfo);
118 if (iter != scanInfos.end()) {
119 APP_LOGD("Replace old preScanInfo(%{public}s)", preScanInfo.bundleDir.c_str());
120 scanInfos.erase(iter);
121 }
122
123 scanInfos.insert(preScanInfo);
124 }
125
126 return result;
127 }
128
TransformToAppList(const nlohmann::json & jsonBuf,std::set<PreScanInfo> & scanAppInfos,std::set<PreScanInfo> & scanDemandInfos) const129 ErrCode PreBundleProfile::TransformToAppList(const nlohmann::json &jsonBuf, std::set<PreScanInfo> &scanAppInfos,
130 std::set<PreScanInfo> &scanDemandInfos) const
131 {
132 if (jsonBuf.is_discarded()) {
133 return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
134 }
135
136 if (jsonBuf.find(APP_LIST) == jsonBuf.end()) {
137 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
138 }
139
140 auto arrays = jsonBuf.at(APP_LIST);
141 if (!arrays.is_array() || arrays.empty()) {
142 APP_LOGE("value is not array");
143 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
144 }
145 int32_t result = ERR_OK;
146 PreScanInfo preScanInfo;
147 for (const auto &array : arrays) {
148 if (!array.is_object()) {
149 APP_LOGE("array is not json object");
150 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
151 }
152
153 preScanInfo.Reset();
154 const auto &jsonObjectEnd = array.end();
155 int32_t parseResult = ERR_OK;
156 BMSJsonUtil::GetStrValueIfFindKey(array, jsonObjectEnd, APP_DIR, preScanInfo.bundleDir, true, parseResult);
157 BMSJsonUtil::GetStrValueIfFindKey(
158 array, jsonObjectEnd, APPIDENTIFIER, preScanInfo.appIdentifier, true, parseResult);
159 BMSJsonUtil::GetBoolValueIfFindKey(
160 array, jsonObjectEnd, ON_DEMAND_INSTALL, preScanInfo.onDemandInstall, false, parseResult);
161 preScanInfo.priority = COMMON_PRIORITY;
162 preScanInfo.isDataPreloadHap = (preScanInfo.bundleDir.find(DATA_PRELOAD_APP) == 0);
163 if (!preScanInfo.isDataPreloadHap || preScanInfo.bundleDir.empty() || preScanInfo.appIdentifier.empty()) {
164 APP_LOGE("set parameter BMS_DATA_PRELOAD false");
165 result = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP;
166 continue;
167 }
168
169 if (parseResult != ERR_OK) {
170 APP_LOGE("parse from install json failed, error %{public}d", parseResult);
171 result = parseResult;
172 continue;
173 }
174
175 auto iter = std::find(scanAppInfos.begin(), scanAppInfos.end(), preScanInfo);
176 if (iter != scanAppInfos.end()) {
177 APP_LOGD("replace old preScanInfo(%{public}s)", preScanInfo.bundleDir.c_str());
178 scanAppInfos.erase(iter);
179 }
180
181 scanAppInfos.insert(preScanInfo);
182 }
183
184 ProcessOnDemandList(scanAppInfos, scanDemandInfos);
185 return result;
186 }
187
TransformToDemandList(const nlohmann::json & jsonBuf,std::set<PreScanInfo> & scanDemandInfos) const188 ErrCode PreBundleProfile::TransformToDemandList(const nlohmann::json &jsonBuf,
189 std::set<PreScanInfo> &scanDemandInfos) const
190 {
191 if (jsonBuf.is_discarded()) {
192 return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
193 }
194
195 if (jsonBuf.find(ON_DEMAND_INSTALL_LIST) == jsonBuf.end()) {
196 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
197 }
198
199 auto arrays = jsonBuf.at(ON_DEMAND_INSTALL_LIST);
200 if (!arrays.is_array() || arrays.empty()) {
201 APP_LOGE("value is not array");
202 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
203 }
204 int32_t result = ERR_OK;
205 PreScanInfo preScanInfo;
206 for (const auto &array : arrays) {
207 if (!array.is_object()) {
208 APP_LOGE("array is not json object");
209 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
210 }
211
212 preScanInfo.Reset();
213 const auto &jsonObjectEnd = array.end();
214 int32_t parseResult = ERR_OK;
215 BMSJsonUtil::GetStrValueIfFindKey(array, jsonObjectEnd, APP_DIR, preScanInfo.bundleDir, true, parseResult);
216 preScanInfo.priority = COMMON_PRIORITY;
217 preScanInfo.onDemandInstall = true;
218 if (parseResult == ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP) {
219 APP_LOGE("bundleDir must exist, and it is empty here");
220 continue;
221 }
222
223 if (parseResult != ERR_OK) {
224 APP_LOGE("parse from on demand install json failed, error %{public}d", parseResult);
225 result = parseResult;
226 continue;
227 }
228
229 auto iter = std::find(scanDemandInfos.begin(), scanDemandInfos.end(), preScanInfo);
230 if (iter != scanDemandInfos.end()) {
231 APP_LOGD("replace old scanDemandInfos(%{public}s)", preScanInfo.bundleDir.c_str());
232 scanDemandInfos.erase(iter);
233 }
234
235 scanDemandInfos.insert(preScanInfo);
236 }
237
238 return result;
239 }
240
TransformTo(const nlohmann::json & jsonBuf,std::set<std::string> & uninstallList) const241 ErrCode PreBundleProfile::TransformTo(
242 const nlohmann::json &jsonBuf,
243 std::set<std::string> &uninstallList) const
244 {
245 APP_LOGD("transform jsonBuf to bundleNames");
246 if (jsonBuf.is_discarded()) {
247 APP_LOGE("profile format error");
248 return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
249 }
250
251 const auto &jsonObjectEnd = jsonBuf.end();
252 int32_t parseResult = ERR_OK;
253 std::vector<std::string> names;
254 GetValueIfFindKey<std::vector<std::string>>(jsonBuf,
255 jsonObjectEnd,
256 UNINSTALL_LIST,
257 names,
258 JsonType::ARRAY,
259 false,
260 parseResult,
261 ArrayType::STRING);
262 for (const auto &name : names) {
263 APP_LOGD("uninstall bundleName %{public}s", name.c_str());
264 uninstallList.insert(name);
265 }
266
267 names.clear();
268 GetValueIfFindKey<std::vector<std::string>>(jsonBuf,
269 jsonObjectEnd,
270 RECOVER_LIST,
271 names,
272 JsonType::ARRAY,
273 false,
274 parseResult,
275 ArrayType::STRING);
276 for (const auto &name : names) {
277 APP_LOGD("recover bundleName %{public}s", name.c_str());
278 uninstallList.erase(name);
279 }
280
281 return parseResult;
282 }
283
TransformTo(const nlohmann::json & jsonBuf,std::set<PreBundleConfigInfo> & preBundleConfigInfos) const284 ErrCode PreBundleProfile::TransformTo(
285 const nlohmann::json &jsonBuf,
286 std::set<PreBundleConfigInfo> &preBundleConfigInfos) const
287 {
288 APP_LOGI("transform jsonBuf to preBundleConfigInfos");
289 if (jsonBuf.is_discarded()) {
290 APP_LOGE("profile format error");
291 return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
292 }
293
294 if (jsonBuf.find(INSTALL_LIST) == jsonBuf.end()) {
295 APP_LOGE("installList no exist");
296 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
297 }
298
299 auto arrays = jsonBuf.at(INSTALL_LIST);
300 if (!arrays.is_array() || arrays.empty()) {
301 APP_LOGE("value is not array");
302 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
303 }
304
305 int32_t result = ERR_OK;
306 PreBundleConfigInfo preBundleConfigInfo;
307 for (const auto &array : arrays) {
308 if (!array.is_object()) {
309 APP_LOGE("array is not json object");
310 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
311 }
312
313 preBundleConfigInfo.Reset();
314 const auto &jsonObjectEnd = array.end();
315 int32_t parseResult = ERR_OK;
316 BMSJsonUtil::GetStrValueIfFindKey(array,
317 jsonObjectEnd,
318 BUNDLE_NAME,
319 preBundleConfigInfo.bundleName,
320 true,
321 parseResult);
322 BMSJsonUtil::GetBoolValueIfFindKey(array,
323 jsonObjectEnd,
324 KEEP_ALIVE,
325 preBundleConfigInfo.keepAlive,
326 false,
327 parseResult);
328 BMSJsonUtil::GetBoolValueIfFindKey(array,
329 jsonObjectEnd,
330 SINGLETON,
331 preBundleConfigInfo.singleton,
332 false,
333 parseResult);
334 GetValueIfFindKey<std::vector<std::string>>(array,
335 jsonObjectEnd,
336 ALLOW_COMMON_EVENT,
337 preBundleConfigInfo.allowCommonEvent,
338 JsonType::ARRAY,
339 false,
340 parseResult,
341 ArrayType::STRING);
342 GetValueIfFindKey<std::vector<std::string>>(array,
343 jsonObjectEnd,
344 APP_SIGNATURE,
345 preBundleConfigInfo.appSignature,
346 JsonType::ARRAY,
347 false,
348 parseResult,
349 ArrayType::STRING);
350 BMSJsonUtil::GetBoolValueIfFindKey(array,
351 jsonObjectEnd,
352 RUNNING_RESOURCES_APPLY,
353 preBundleConfigInfo.runningResourcesApply,
354 false,
355 parseResult);
356 BMSJsonUtil::GetBoolValueIfFindKey(array,
357 jsonObjectEnd,
358 ASSOCIATED_WAKE_UP,
359 preBundleConfigInfo.associatedWakeUp,
360 false,
361 parseResult);
362 BMSJsonUtil::GetBoolValueIfFindKey(array,
363 jsonObjectEnd,
364 ALLOW_APP_DATA_NOT_CLEARED,
365 preBundleConfigInfo.userDataClearable,
366 false,
367 parseResult);
368 BMSJsonUtil::GetBoolValueIfFindKey(array,
369 jsonObjectEnd,
370 ALLOW_APP_MULTI_PROCESS,
371 preBundleConfigInfo.allowMultiProcess,
372 false,
373 parseResult);
374 BMSJsonUtil::GetBoolValueIfFindKey(array,
375 jsonObjectEnd,
376 ALLOW_APP_DESKTOP_ICON_HIDE,
377 preBundleConfigInfo.hideDesktopIcon,
378 false,
379 parseResult);
380 BMSJsonUtil::GetBoolValueIfFindKey(array,
381 jsonObjectEnd,
382 ALLOW_ABILITY_PRIORITY_QUERIED,
383 preBundleConfigInfo.allowQueryPriority,
384 false,
385 parseResult);
386 BMSJsonUtil::GetBoolValueIfFindKey(array,
387 jsonObjectEnd,
388 ALLOW_ABILITY_EXCLUDE_FROM_MISSIONS,
389 preBundleConfigInfo.allowExcludeFromMissions,
390 false,
391 parseResult);
392 BMSJsonUtil::GetBoolValueIfFindKey(array,
393 jsonObjectEnd,
394 ALLOW_MISSION_NOT_CLEARED,
395 preBundleConfigInfo.allowMissionNotCleared,
396 false,
397 parseResult);
398 BMSJsonUtil::GetBoolValueIfFindKey(array,
399 jsonObjectEnd,
400 ALLOW_APP_USE_PRIVILEGE_EXTENSION,
401 preBundleConfigInfo.allowUsePrivilegeExtension,
402 false,
403 parseResult);
404 BMSJsonUtil::GetBoolValueIfFindKey(array,
405 jsonObjectEnd,
406 ALLOW_FORM_VISIBLE_NOTIFY,
407 preBundleConfigInfo.formVisibleNotify,
408 false,
409 parseResult);
410 BMSJsonUtil::GetBoolValueIfFindKey(array,
411 jsonObjectEnd,
412 ALLOW_APP_SHARE_LIBRARY,
413 preBundleConfigInfo.appShareLibrary,
414 false,
415 parseResult);
416 BMSJsonUtil::GetBoolValueIfFindKey(array,
417 jsonObjectEnd,
418 ALLOW_ENABLE_NOTIFICATION,
419 preBundleConfigInfo.allowEnableNotification,
420 false,
421 parseResult);
422 BMSJsonUtil::GetBoolValueIfFindKey(array,
423 jsonObjectEnd,
424 ALLOW_APP_RUN_WHEN_DEVICE_FIRST_LOCKED,
425 preBundleConfigInfo.allowAppRunWhenDeviceFirstLocked,
426 false,
427 parseResult);
428 GetValueIfFindKey<std::vector<int32_t>>(array,
429 jsonObjectEnd,
430 RESOURCES_APPLY,
431 preBundleConfigInfo.resourcesApply,
432 JsonType::ARRAY,
433 false,
434 parseResult,
435 ArrayType::NUMBER);
436 if (array.find(ALLOW_APP_DATA_NOT_CLEARED) != jsonObjectEnd) {
437 preBundleConfigInfo.existInJsonFile.push_back(ALLOW_APP_DATA_NOT_CLEARED);
438 preBundleConfigInfo.userDataClearable = !preBundleConfigInfo.userDataClearable;
439 }
440 if (array.find(ALLOW_APP_MULTI_PROCESS) != jsonObjectEnd) {
441 preBundleConfigInfo.existInJsonFile.push_back(ALLOW_APP_MULTI_PROCESS);
442 }
443 if (array.find(ALLOW_APP_DESKTOP_ICON_HIDE) != jsonObjectEnd) {
444 preBundleConfigInfo.existInJsonFile.push_back(ALLOW_APP_DESKTOP_ICON_HIDE);
445 }
446 if (array.find(ALLOW_ABILITY_PRIORITY_QUERIED) != jsonObjectEnd) {
447 preBundleConfigInfo.existInJsonFile.push_back(ALLOW_ABILITY_PRIORITY_QUERIED);
448 }
449 if (array.find(ALLOW_ABILITY_EXCLUDE_FROM_MISSIONS) != jsonObjectEnd) {
450 preBundleConfigInfo.existInJsonFile.push_back(ALLOW_ABILITY_EXCLUDE_FROM_MISSIONS);
451 }
452 if (array.find(ALLOW_MISSION_NOT_CLEARED) != jsonObjectEnd) {
453 preBundleConfigInfo.existInJsonFile.push_back(ALLOW_MISSION_NOT_CLEARED);
454 }
455 if (array.find(ALLOW_APP_USE_PRIVILEGE_EXTENSION) != jsonObjectEnd) {
456 preBundleConfigInfo.existInJsonFile.push_back(ALLOW_APP_USE_PRIVILEGE_EXTENSION);
457 }
458 if (array.find(ALLOW_FORM_VISIBLE_NOTIFY) != jsonObjectEnd) {
459 preBundleConfigInfo.existInJsonFile.push_back(ALLOW_FORM_VISIBLE_NOTIFY);
460 }
461 if (array.find(ALLOW_APP_SHARE_LIBRARY) != jsonObjectEnd) {
462 preBundleConfigInfo.existInJsonFile.push_back(ALLOW_APP_SHARE_LIBRARY);
463 }
464 if (array.find(ALLOW_ENABLE_NOTIFICATION) != jsonObjectEnd) {
465 preBundleConfigInfo.existInJsonFile.push_back(ALLOW_ENABLE_NOTIFICATION);
466 }
467 if (parseResult == ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP) {
468 APP_LOGE("bundlename must exist, and it is empty here");
469 continue;
470 }
471
472 if (parseResult != ERR_OK) {
473 APP_LOGE("parse from capability json failed, error %{public}d", parseResult);
474 result = parseResult;
475 continue;
476 }
477
478 APP_LOGD("preBundleConfigInfo(%{public}s)", preBundleConfigInfo.ToString().c_str());
479 auto iter = preBundleConfigInfos.find(preBundleConfigInfo);
480 if (iter != preBundleConfigInfos.end()) {
481 APP_LOGD("Replace old preBundleConfigInfo(%{public}s)",
482 preBundleConfigInfo.bundleName.c_str());
483 preBundleConfigInfos.erase(iter);
484 }
485
486 preBundleConfigInfos.insert(preBundleConfigInfo);
487 }
488
489 return result;
490 }
491
TransformJsonToExtensionTypeList(const nlohmann::json & jsonBuf,std::set<std::string> & extensionTypeList) const492 ErrCode PreBundleProfile::TransformJsonToExtensionTypeList(
493 const nlohmann::json &jsonBuf, std::set<std::string> &extensionTypeList) const
494 {
495 if (jsonBuf.is_discarded()) {
496 APP_LOGE("Profile format error");
497 return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
498 }
499
500 if (jsonBuf.find(EXTENSION_TYPE) == jsonBuf.end()) {
501 APP_LOGE("Profile does not have 'extensionType'key");
502 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
503 }
504
505 auto arrays = jsonBuf.at(EXTENSION_TYPE);
506 if (!arrays.is_array() || arrays.empty()) {
507 APP_LOGE("Value is not array");
508 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
509 }
510
511 for (const auto &array : arrays) {
512 if (!array.is_object()) {
513 APP_LOGE("Array is not json object");
514 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
515 }
516
517 std::string extensionAbilityType;
518 const auto &jsonObjectEnd = array.end();
519 int32_t parseResult = ERR_OK;
520 BMSJsonUtil::GetStrValueIfFindKey(array,
521 jsonObjectEnd,
522 TYPE_NAME,
523 extensionAbilityType,
524 true,
525 parseResult);
526 extensionTypeList.insert(extensionAbilityType);
527 }
528
529 return ERR_OK;
530 }
531
ProcessOnDemandList(std::set<PreScanInfo> & scanAppInfos,std::set<PreScanInfo> & scanDemandInfos) const532 void PreBundleProfile::ProcessOnDemandList(std::set<PreScanInfo> &scanAppInfos,
533 std::set<PreScanInfo> &scanDemandInfos) const
534 {
535 for (auto iter = scanAppInfos.begin(); iter != scanAppInfos.end();) {
536 if (iter->onDemandInstall) {
537 PreScanInfo preScanInfo;
538 preScanInfo.removable = iter->removable;
539 preScanInfo.isDataPreloadHap = iter->isDataPreloadHap;
540 preScanInfo.priority = iter->priority;
541 preScanInfo.bundleDir = iter->bundleDir;
542 preScanInfo.appIdentifier = iter->appIdentifier;
543 preScanInfo.onDemandInstall = iter->onDemandInstall;
544 scanDemandInfos.insert(preScanInfo);
545 iter = scanAppInfos.erase(iter);
546 APP_LOGI("%{public}s is onDemandInstall", iter->bundleDir.c_str());
547 } else {
548 ++iter;
549 }
550 }
551 }
552
TransToArkStartupCacheList(const nlohmann::json & jsonBuf,std::unordered_set<std::string> & arkStartupCacheList) const553 ErrCode PreBundleProfile::TransToArkStartupCacheList(
554 const nlohmann::json &jsonBuf,
555 std::unordered_set<std::string> &arkStartupCacheList) const
556 {
557 APP_LOGD("transform jsonBuf to bundleNames");
558 if (jsonBuf.is_discarded()) {
559 APP_LOGE("profile format error");
560 return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
561 }
562
563 const auto &jsonObjectEnd = jsonBuf.end();
564 int32_t parseResult = ERR_OK;
565 std::vector<std::string> names;
566 GetValueIfFindKey<std::vector<std::string>>(jsonBuf,
567 jsonObjectEnd,
568 ARK_STARTUP_SNAPSHOT_LIST,
569 names,
570 JsonType::ARRAY,
571 false,
572 parseResult,
573 ArrayType::STRING);
574 for (const auto &name : names) {
575 APP_LOGD("ark startup cache bundleName %{public}s", name.c_str());
576 arkStartupCacheList.insert(name);
577 }
578 names.clear();
579 return parseResult;
580 }
581 } // namespace AppExecFwk
582 } // namespace OHOS
583