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 "bundle_mgr_host.h"
17 
18 #include <algorithm>
19 #include <cinttypes>
20 #include <unistd.h>
21 
22 #include "app_log_wrapper.h"
23 #include "bundle_constants.h"
24 #include "bundle_framework_core_ipc_interface_code.h"
25 #include "bundle_memory_guard.h"
26 #include "hitrace_meter.h"
27 #include "datetime_ex.h"
28 #include "ipc_skeleton.h"
29 #include "ipc_types.h"
30 #include "json_util.h"
31 #include "preinstalled_application_info.h"
32 #include "string_ex.h"
33 #include "securec.h"
34 
35 namespace OHOS {
36 namespace AppExecFwk {
37 namespace {
38 const int16_t LIMIT_PARCEL_SIZE = 1024;
39 const int8_t ASHMEM_LEN = 16;
40 constexpr size_t MAX_PARCEL_CAPACITY = 100 * 1024 * 1024; // 100M
41 constexpr int32_t ASHMEM_THRESHOLD  = 200 * 1024; // 200K
42 constexpr int32_t PREINSTALL_PARCEL_CAPACITY  = 400 * 1024; // 400K
43 constexpr int32_t MAX_CAPACITY_BUNDLES = 5 * 1024 * 1000; // 5M
44 constexpr int16_t MAX_BATCH_QUERY_BUNDLE_SIZE = 1000;
45 const int16_t MAX_STATUS_VECTOR_NUM = 1000;
46 constexpr int16_t MAX_BATCH_QUERY_ABILITY_SIZE = 1000;
47 constexpr size_t MAX_PARCEL_CAPACITY_OF_ASHMEM = 1024 * 1024 * 1024; // max allow 1 GB resource size
48 constexpr size_t MAX_IPC_REWDATA_SIZE = 120 * 1024 * 1024; // max ipc size 120MB
49 const std::string BUNDLE_MANAGER_ASHMEM_NAME = "bundleManagerAshemeName";
50 
SplitString(const std::string & source,std::vector<std::string> & strings)51 void SplitString(const std::string &source, std::vector<std::string> &strings)
52 {
53     int splitSize = (source.size() / LIMIT_PARCEL_SIZE);
54     if ((source.size() % LIMIT_PARCEL_SIZE) != 0) {
55         splitSize++;
56     }
57     APP_LOGD("the dump string split into %{public}d size", splitSize);
58     for (int i = 0; i < splitSize; i++) {
59         int32_t start = LIMIT_PARCEL_SIZE * i;
60         strings.emplace_back(source.substr(start, LIMIT_PARCEL_SIZE));
61     }
62 }
63 
GetData(void * & buffer,size_t size,const void * data)64 bool GetData(void *&buffer, size_t size, const void *data)
65 {
66     if (data == nullptr) {
67         APP_LOGE("GetData failed due to null data");
68         return false;
69     }
70     if (size == 0 || size > MAX_PARCEL_CAPACITY) {
71         APP_LOGE("GetData failed due to zero size");
72         return false;
73     }
74     buffer = malloc(size);
75     if (buffer == nullptr) {
76         APP_LOGE("GetData failed due to malloc buffer failed");
77         return false;
78     }
79     if (memcpy_s(buffer, size, data, size) != EOK) {
80         free(buffer);
81         APP_LOGE("GetData failed due to memcpy_s failed");
82         return false;
83     }
84     return true;
85 }
86 }  // namespace
87 
BundleMgrHost()88 BundleMgrHost::BundleMgrHost()
89 {
90     APP_LOGD("create bundle manager host ");
91 }
92 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)93 int BundleMgrHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
94 {
95     BundleMemoryGuard memoryGuard;
96     APP_LOGD("bundle mgr host onReceived message, the message code is %{public}u", code);
97     std::u16string descriptor = BundleMgrHost::GetDescriptor();
98     std::u16string remoteDescriptor = data.ReadInterfaceToken();
99     if (descriptor != remoteDescriptor) {
100         APP_LOGE("fail to write reply message in bundle mgr host due to the reply is nullptr");
101         return OBJECT_NULL;
102     }
103 
104     ErrCode errCode = ERR_OK;
105     switch (code) {
106         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFO):
107             errCode = this->HandleGetApplicationInfo(data, reply);
108             break;
109         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFO_WITH_INT_FLAGS):
110             errCode = this->HandleGetApplicationInfoWithIntFlags(data, reply);
111             break;
112         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFOS):
113             errCode = this->HandleGetApplicationInfos(data, reply);
114             break;
115         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFO_WITH_INT_FLAGS_V9):
116             errCode = this->HandleGetApplicationInfoWithIntFlagsV9(data, reply);
117             break;
118         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFOS_WITH_INT_FLAGS):
119             errCode = this->HandleGetApplicationInfosWithIntFlags(data, reply);
120             break;
121         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFOS_WITH_INT_FLAGS_V9):
122             errCode = this->HandleGetApplicationInfosWithIntFlagsV9(data, reply);
123             break;
124         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFO):
125             errCode = this->HandleGetBundleInfo(data, reply);
126             break;
127         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFO_WITH_INT_FLAGS):
128             errCode = this->HandleGetBundleInfoWithIntFlags(data, reply);
129             break;
130         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFO_WITH_INT_FLAGS_V9):
131             errCode = this->HandleGetBundleInfoWithIntFlagsV9(data, reply);
132             break;
133         case static_cast<uint32_t>(BundleMgrInterfaceCode::BATCH_GET_BUNDLE_INFO):
134             errCode = this->HandleBatchGetBundleInfo(data, reply);
135             break;
136         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_PACK_INFO):
137             errCode = this->HandleGetBundlePackInfo(data, reply);
138             break;
139         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_PACK_INFO_WITH_INT_FLAGS):
140             errCode = this->HandleGetBundlePackInfoWithIntFlags(data, reply);
141             break;
142         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFOS):
143             errCode = this->HandleGetBundleInfos(data, reply);
144             break;
145         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFOS_WITH_INT_FLAGS):
146             errCode = this->HandleGetBundleInfosWithIntFlags(data, reply);
147             break;
148         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFOS_WITH_INT_FLAGS_V9):
149             errCode = this->HandleGetBundleInfosWithIntFlagsV9(data, reply);
150             break;
151         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_NAME_FOR_UID):
152             errCode = this->HandleGetBundleNameForUid(data, reply);
153             break;
154         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLES_FOR_UID):
155             errCode = this->HandleGetBundlesForUid(data, reply);
156             break;
157         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_NAME_FOR_UID):
158             errCode = this->HandleGetNameForUid(data, reply);
159             break;
160         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_NAME_AND_APPINDEX_FOR_UID):
161             errCode = this->HandleGetNameAndIndexForUid(data, reply);
162             break;
163         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_GIDS):
164             errCode = this->HandleGetBundleGids(data, reply);
165             break;
166         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_GIDS_BY_UID):
167             errCode = this->HandleGetBundleGidsByUid(data, reply);
168             break;
169         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFOS_BY_METADATA):
170             errCode = this->HandleGetBundleInfosByMetaData(data, reply);
171             break;
172         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO):
173             errCode = this->HandleQueryAbilityInfo(data, reply);
174             break;
175         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_MUTI_PARAM):
176             errCode = this->HandleQueryAbilityInfoMutiparam(data, reply);
177             break;
178         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFOS):
179             errCode = this->HandleQueryAbilityInfos(data, reply);
180             break;
181         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFOS_MUTI_PARAM):
182             errCode = this->HandleQueryAbilityInfosMutiparam(data, reply);
183             break;
184         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFOS_V9):
185             errCode = this->HandleQueryAbilityInfosV9(data, reply);
186             break;
187         case static_cast<uint32_t>(BundleMgrInterfaceCode::BATCH_QUERY_ABILITY_INFOS):
188             errCode = this->HandleBatchQueryAbilityInfos(data, reply);
189             break;
190         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_LAUNCHER_ABILITY_INFO):
191             errCode = this->HandleQueryLauncherAbilityInfos(data, reply);
192             break;
193         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ALL_ABILITY_INFOS):
194             errCode = this->HandleQueryAllAbilityInfos(data, reply);
195             break;
196         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_BY_URI):
197             errCode = this->HandleQueryAbilityInfoByUri(data, reply);
198             break;
199         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFOS_BY_URI):
200             errCode = this->HandleQueryAbilityInfosByUri(data, reply);
201             break;
202         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_BY_URI_FOR_USERID):
203             errCode = this->HandleQueryAbilityInfoByUriForUserId(data, reply);
204             break;
205         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_KEEPALIVE_BUNDLE_INFOS):
206             errCode = this->HandleQueryKeepAliveBundleInfos(data, reply);
207             break;
208         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ABILITY_LABEL):
209             errCode = this->HandleGetAbilityLabel(data, reply);
210             break;
211         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ABILITY_LABEL_WITH_MODULE_NAME):
212             errCode = this->HandleGetAbilityLabelWithModuleName(data, reply);
213             break;
214         case static_cast<uint32_t>(BundleMgrInterfaceCode::CHECK_IS_SYSTEM_APP_BY_UID):
215             errCode = this->HandleCheckIsSystemAppByUid(data, reply);
216             break;
217         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO):
218             errCode = this->HandleGetBundleArchiveInfo(data, reply);
219             break;
220         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO_WITH_INT_FLAGS):
221             errCode = this->HandleGetBundleArchiveInfoWithIntFlags(data, reply);
222             break;
223         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO_WITH_INT_FLAGS_V9):
224             errCode = this->HandleGetBundleArchiveInfoWithIntFlagsV9(data, reply);
225             break;
226         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_HAP_MODULE_INFO):
227             errCode = this->HandleGetHapModuleInfo(data, reply);
228             break;
229         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_LAUNCH_WANT_FOR_BUNDLE):
230             errCode = this->HandleGetLaunchWantForBundle(data, reply);
231             break;
232         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_PERMISSION_DEF):
233             errCode = this->HandleGetPermissionDef(data, reply);
234             break;
235         case static_cast<uint32_t>(BundleMgrInterfaceCode::AUTO_CLEAN_CACHE_BY_SIZE):
236             errCode = this->HandleCleanBundleCacheFilesAutomatic(data, reply);
237             break;
238         case static_cast<uint32_t>(BundleMgrInterfaceCode::CLEAN_BUNDLE_CACHE_FILES):
239             errCode = this->HandleCleanBundleCacheFiles(data, reply);
240             break;
241         case static_cast<uint32_t>(BundleMgrInterfaceCode::CREATE_BUNDLE_DATA_DIR):
242             errCode = this->HandleCreateBundleDataDir(data, reply);
243             break;
244         case static_cast<uint32_t>(BundleMgrInterfaceCode::CLEAN_BUNDLE_DATA_FILES):
245             errCode = this->HandleCleanBundleDataFiles(data, reply);
246             break;
247         case static_cast<uint32_t>(BundleMgrInterfaceCode::REGISTER_BUNDLE_STATUS_CALLBACK):
248             errCode = this->HandleRegisterBundleStatusCallback(data, reply);
249             break;
250         case static_cast<uint32_t>(BundleMgrInterfaceCode::REGISTER_BUNDLE_EVENT_CALLBACK):
251             errCode = this->HandleRegisterBundleEventCallback(data, reply);
252             break;
253         case static_cast<uint32_t>(BundleMgrInterfaceCode::UNREGISTER_BUNDLE_EVENT_CALLBACK):
254             errCode = this->HandleUnregisterBundleEventCallback(data, reply);
255             break;
256         case static_cast<uint32_t>(BundleMgrInterfaceCode::CLEAR_BUNDLE_STATUS_CALLBACK):
257             errCode = this->HandleClearBundleStatusCallback(data, reply);
258             break;
259         case static_cast<uint32_t>(BundleMgrInterfaceCode::UNREGISTER_BUNDLE_STATUS_CALLBACK):
260             errCode = this->HandleUnregisterBundleStatusCallback(data, reply);
261             break;
262         case static_cast<uint32_t>(BundleMgrInterfaceCode::IS_APPLICATION_ENABLED):
263             errCode = this->HandleIsApplicationEnabled(data, reply);
264             break;
265         case static_cast<uint32_t>(BundleMgrInterfaceCode::SET_APPLICATION_ENABLED):
266             errCode = this->HandleSetApplicationEnabled(data, reply);
267             break;
268         case static_cast<uint32_t>(BundleMgrInterfaceCode::IS_ABILITY_ENABLED):
269             errCode = this->HandleIsAbilityEnabled(data, reply);
270             break;
271         case static_cast<uint32_t>(BundleMgrInterfaceCode::SET_ABILITY_ENABLED):
272             errCode = this->HandleSetAbilityEnabled(data, reply);
273             break;
274         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ABILITY_INFO):
275             errCode = this->HandleGetAbilityInfo(data, reply);
276             break;
277         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ABILITY_INFO_WITH_MODULE_NAME):
278             errCode = this->HandleGetAbilityInfoWithModuleName(data, reply);
279             break;
280         case static_cast<uint32_t>(BundleMgrInterfaceCode::DUMP_INFOS):
281             errCode = this->HandleDumpInfos(data, reply);
282             break;
283         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INSTALLER):
284             errCode = this->HandleGetBundleInstaller(data, reply);
285             break;
286         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_FORMS_INFO):
287             errCode = this->HandleGetAllFormsInfo(data, reply);
288             break;
289         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_FORMS_INFO_BY_APP):
290             errCode = this->HandleGetFormsInfoByApp(data, reply);
291             break;
292         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_FORMS_INFO_BY_MODULE):
293             errCode = this->HandleGetFormsInfoByModule(data, reply);
294             break;
295         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SHORTCUT_INFO):
296             errCode = this->HandleGetShortcutInfos(data, reply);
297             break;
298         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SHORTCUT_INFO_V9):
299             errCode = this->HandleGetShortcutInfoV9(data, reply);
300             break;
301         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_COMMON_EVENT_INFO):
302             errCode = this->HandleGetAllCommonEventInfo(data, reply);
303             break;
304         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_USER_MGR):
305             errCode = this->HandleGetBundleUserMgr(data, reply);
306             break;
307         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_DISTRIBUTE_BUNDLE_INFO):
308             errCode = this->HandleGetDistributedBundleInfo(data, reply);
309             break;
310         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_PRIVILEGE_LEVEL):
311             errCode = this->HandleGetAppPrivilegeLevel(data, reply);
312             break;
313         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_WITHOUT_TYPE):
314             errCode = this->HandleQueryExtAbilityInfosWithoutType(data, reply);
315             break;
316         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_WITHOUT_TYPE_V9):
317             errCode = this->HandleQueryExtAbilityInfosWithoutTypeV9(data, reply);
318             break;
319         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO):
320             errCode = this->HandleQueryExtAbilityInfos(data, reply);
321             break;
322         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_V9):
323             errCode = this->HandleQueryExtAbilityInfosV9(data, reply);
324             break;
325         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_BY_TYPE):
326             errCode = this->HandleQueryExtAbilityInfosByType(data, reply);
327             break;
328         case static_cast<uint32_t>(BundleMgrInterfaceCode::VERIFY_CALLING_PERMISSION):
329             errCode = this->HandleVerifyCallingPermission(data, reply);
330             break;
331         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_ABILITY_INFO_BY_URI):
332             errCode = this->HandleQueryExtensionAbilityInfoByUri(data, reply);
333             break;
334         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPID_BY_BUNDLE_NAME):
335             errCode = this->HandleGetAppIdByBundleName(data, reply);
336             break;
337         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APP_TYPE):
338             errCode = this->HandleGetAppType(data, reply);
339             break;
340         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_UID_BY_BUNDLE_NAME):
341             errCode = this->HandleGetUidByBundleName(data, reply);
342             break;
343         case static_cast<uint32_t>(BundleMgrInterfaceCode::IS_MODULE_REMOVABLE):
344             errCode = this->HandleIsModuleRemovable(data, reply);
345             break;
346         case static_cast<uint32_t>(BundleMgrInterfaceCode::SET_MODULE_REMOVABLE):
347             errCode = this->HandleSetModuleRemovable(data, reply);
348             break;
349         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_WITH_CALLBACK):
350             errCode = this->HandleQueryAbilityInfoWithCallback(data, reply);
351             break;
352         case static_cast<uint32_t>(BundleMgrInterfaceCode::UPGRADE_ATOMIC_SERVICE):
353             errCode = this->HandleUpgradeAtomicService(data, reply);
354             break;
355         case static_cast<uint32_t>(BundleMgrInterfaceCode::IS_MODULE_NEED_UPDATE):
356             errCode = this->HandleGetModuleUpgradeFlag(data, reply);
357             break;
358         case static_cast<uint32_t>(BundleMgrInterfaceCode::SET_MODULE_NEED_UPDATE):
359             errCode = this->HandleSetModuleUpgradeFlag(data, reply);
360             break;
361         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_HAP_MODULE_INFO_WITH_USERID):
362             errCode = this->HandleGetHapModuleInfoWithUserId(data, reply);
363             break;
364         case static_cast<uint32_t>(BundleMgrInterfaceCode::IMPLICIT_QUERY_INFO_BY_PRIORITY):
365             errCode = this->HandleImplicitQueryInfoByPriority(data, reply);
366             break;
367         case static_cast<uint32_t>(BundleMgrInterfaceCode::IMPLICIT_QUERY_INFOS):
368             errCode = this->HandleImplicitQueryInfos(data, reply);
369             break;
370         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_DEPENDENT_MODULE_NAMES):
371             errCode = this->HandleGetAllDependentModuleNames(data, reply);
372             break;
373         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SANDBOX_APP_BUNDLE_INFO):
374             errCode = this->HandleGetSandboxBundleInfo(data, reply);
375             break;
376         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_CALLING_BUNDLE_NAME):
377             errCode = this->HandleObtainCallingBundleName(data, reply);
378             break;
379         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_STATS):
380             errCode = this->HandleGetBundleStats(data, reply);
381             break;
382         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_BUNDLE_STATS):
383             errCode = this->HandleGetAllBundleStats(data, reply);
384             break;
385         case static_cast<uint32_t>(BundleMgrInterfaceCode::CHECK_ABILITY_ENABLE_INSTALL):
386             errCode = this->HandleCheckAbilityEnableInstall(data, reply);
387             break;
388         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_STRING_BY_ID):
389             errCode = this->HandleGetStringById(data, reply);
390             break;
391         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ICON_BY_ID):
392             errCode = this->HandleGetIconById(data, reply);
393             break;
394 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
395         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_DEFAULT_APP_PROXY):
396             errCode = this->HandleGetDefaultAppProxy(data, reply);
397             break;
398 #endif
399         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SANDBOX_APP_ABILITY_INFO):
400             errCode = this->HandleGetSandboxAbilityInfo(data, reply);
401             break;
402         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SANDBOX_APP_EXTENSION_INFOS):
403             errCode = this->HandleGetSandboxExtAbilityInfos(data, reply);
404             break;
405         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SANDBOX_MODULE_INFO):
406             errCode = this->HandleGetSandboxHapModuleInfo(data, reply);
407             break;
408         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_MEDIA_DATA):
409             errCode = this->HandleGetMediaData(data, reply);
410             break;
411         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_QUICK_FIX_MANAGER_PROXY):
412             errCode = this->HandleGetQuickFixManagerProxy(data, reply);
413             break;
414 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
415         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APP_CONTROL_PROXY):
416             errCode = this->HandleGetAppControlProxy(data, reply);
417             break;
418 #endif
419         case static_cast<uint32_t>(BundleMgrInterfaceCode::SET_DEBUG_MODE):
420             errCode = this->HandleSetDebugMode(data, reply);
421             break;
422         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFO_FOR_SELF):
423             errCode = this->HandleGetBundleInfoForSelf(data, reply);
424             break;
425         case static_cast<uint32_t>(BundleMgrInterfaceCode::VERIFY_SYSTEM_API):
426             errCode = this->HandleVerifySystemApi(data, reply);
427             break;
428         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY):
429             errCode = this->HandleGetOverlayManagerProxy(data, reply);
430             break;
431         case static_cast<uint32_t>(BundleMgrInterfaceCode::SILENT_INSTALL):
432             errCode = this->HandleSilentInstall(data, reply);
433             break;
434         case static_cast<uint32_t>(BundleMgrInterfaceCode::PROCESS_PRELOAD):
435             errCode = this->HandleProcessPreload(data, reply);
436             break;
437         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APP_PROVISION_INFO):
438             errCode = this->HandleGetAppProvisionInfo(data, reply);
439             break;
440         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_PROVISION_METADATA):
441             errCode = this->HandleGetProvisionMetadata(data, reply);
442             break;
443         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BASE_SHARED_BUNDLE_INFOS):
444             errCode = this->HandleGetBaseSharedBundleInfos(data, reply);
445             break;
446         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_SHARED_BUNDLE_INFO):
447             errCode = this->HandleGetAllSharedBundleInfo(data, reply);
448             break;
449         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SHARED_BUNDLE_INFO):
450             errCode = this->HandleGetSharedBundleInfo(data, reply);
451             break;
452         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SHARED_BUNDLE_INFO_BY_SELF):
453             errCode = this->HandleGetSharedBundleInfoBySelf(data, reply);
454             break;
455         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SHARED_DEPENDENCIES):
456             errCode = this->HandleGetSharedDependencies(data, reply);
457             break;
458         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_DEPENDENT_BUNDLE_INFO):
459             errCode = this->HandleGetDependentBundleInfo(data, reply);
460             break;
461         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_UID_BY_DEBUG_BUNDLE_NAME):
462             errCode = this->HandleGetUidByDebugBundleName(data, reply);
463             break;
464         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_PROXY_DATA_INFOS):
465             errCode = this->HandleGetProxyDataInfos(data, reply);
466             break;
467         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_PROXY_DATA_INFOS):
468             errCode = this->HandleGetAllProxyDataInfos(data, reply);
469             break;
470         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SPECIFIED_DISTRIBUTED_TYPE):
471             errCode = this->HandleGetSpecifiedDistributionType(data, reply);
472             break;
473         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ADDITIONAL_INFO):
474             errCode = this->HandleGetAdditionalInfo(data, reply);
475             break;
476         case static_cast<uint32_t>(BundleMgrInterfaceCode::SET_EXT_NAME_OR_MIME_TO_APP):
477             errCode = this->HandleSetExtNameOrMIMEToApp(data, reply);
478             break;
479         case static_cast<uint32_t>(BundleMgrInterfaceCode::DEL_EXT_NAME_OR_MIME_TO_APP):
480             errCode = this->HandleDelExtNameOrMIMEToApp(data, reply);
481             break;
482         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_DATA_GROUP_INFOS):
483             errCode = this->HandleQueryDataGroupInfos(data, reply);
484             break;
485         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_PREFERENCE_DIR_BY_GROUP_ID):
486             errCode = this->HandleGetPreferenceDirByGroupId(data, reply);
487             break;
488         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_APPGALLERY_BUNDLE_NAME):
489             errCode = this->HandleQueryAppGalleryBundleName(data, reply);
490             break;
491         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_ABILITY_INFO_WITH_TYPE_NAME):
492             errCode = this->HandleQueryExtensionAbilityInfosWithTypeName(data, reply);
493             break;
494         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_ABILITY_INFO_ONLY_WITH_TYPE_NAME):
495             errCode = this->HandleQueryExtensionAbilityInfosOnlyWithTypeName(data, reply);
496             break;
497         case static_cast<uint32_t>(BundleMgrInterfaceCode::RESET_AOT_COMPILE_STATUS):
498             errCode = this->HandleResetAOTCompileStatus(data, reply);
499             break;
500         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_JSON_PROFILE):
501             errCode = this->HandleGetJsonProfile(data, reply);
502             break;
503         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_RESOURCE_PROXY):
504             errCode = this->HandleGetBundleResourceProxy(data, reply);
505             break;
506         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_VERIFY_MANAGER):
507             errCode = this->HandleGetVerifyManager(data, reply);
508             break;
509         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_RECOVERABLE_APPLICATION_INFO):
510             errCode = this->HandleGetRecoverableApplicationInfo(data, reply);
511             break;
512         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_UNINSTALLED_BUNDLE_INFO):
513             errCode = this->HandleGetUninstalledBundleInfo(data, reply);
514             break;
515         case static_cast<uint32_t>(BundleMgrInterfaceCode::SET_ADDITIONAL_INFO):
516             errCode = this->HandleSetAdditionalInfo(data, reply);
517             break;
518         case static_cast<uint32_t>(BundleMgrInterfaceCode::COMPILE_PROCESSAOT):
519             errCode = this->HandleCompileProcessAOT(data, reply);
520             break;
521         case static_cast<uint32_t>(BundleMgrInterfaceCode::COMPILE_RESET):
522             errCode = this->HandleCompileReset(data, reply);
523             break;
524         case static_cast<uint32_t>(BundleMgrInterfaceCode::CAN_OPEN_LINK):
525             errCode = this->HandleCanOpenLink(data, reply);
526             break;
527         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ODID):
528             errCode = this->HandleGetOdid(data, reply);
529             break;
530         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_PREINSTALLED_APPLICATION_INFO):
531             errCode = this->HandleGetAllPreinstalledApplicationInfos(data, reply);
532             break;
533         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_EXTEND_RESOURCE_MANAGER):
534             errCode = this->HandleGetExtendResourceManager(data, reply);
535             break;
536         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_BUNDLE_INFO_BY_DEVELOPER_ID):
537             errCode = this->HandleGetAllBundleInfoByDeveloperId(data, reply);
538             break;
539         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_DEVELOPER_IDS):
540             errCode = this->HandleGetDeveloperIds(data, reply);
541             break;
542         case static_cast<uint32_t>(BundleMgrInterfaceCode::SWITCH_UNINSTALL_STATE):
543             errCode = this->HandleSwitchUninstallState(data, reply);
544             break;
545         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_BY_CONTINUE_TYPE):
546             errCode = this->HandleQueryAbilityInfoByContinueType(data, reply);
547             break;
548         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_CLONE_ABILITY_INFO):
549             errCode = this->HandleQueryCloneAbilityInfo(data, reply);
550             break;
551         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_CLONE_BUNDLE_INFO):
552             errCode = this->HandleGetCloneBundleInfo(data, reply);
553             break;
554         case static_cast<uint32_t>(BundleMgrInterfaceCode::COPY_AP):
555             errCode = this->HandleCopyAp(data, reply);
556             break;
557         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_CLONE_APP_INDEXES):
558             errCode = this->HandleGetCloneAppIndexes(data, reply);
559             break;
560         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_LAUNCH_WANT):
561             errCode = this->HandleGetLaunchWant(data, reply);
562             break;
563         case static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_CLONE_EXTENSION_ABILITY_INFO_WITH_APP_INDEX):
564             errCode = this->HandleQueryCloneExtensionAbilityInfoWithAppIndex(data, reply);
565             break;
566         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SIGNATURE_INFO):
567             errCode = this->HandleGetSignatureInfoByBundleName(data, reply);
568             break;
569         case static_cast<uint32_t>(BundleMgrInterfaceCode::SET_CLONE_APPLICATION_ENABLED):
570             errCode = this->HandleSetCloneApplicationEnabled(data, reply);
571             break;
572         case static_cast<uint32_t>(BundleMgrInterfaceCode::IS_CLONE_APPLICATION_ENABLED):
573             errCode = this->HandleIsCloneApplicationEnabled(data, reply);
574             break;
575         case static_cast<uint32_t>(BundleMgrInterfaceCode::SET_CLONE_ABILITY_ENABLED):
576             errCode = this->HandleSetCloneAbilityEnabled(data, reply);
577             break;
578         case static_cast<uint32_t>(BundleMgrInterfaceCode::IS_CLONE_ABILITY_ENABLED):
579             errCode = this->HandleIsCloneAbilityEnabled(data, reply);
580             break;
581         case static_cast<uint32_t>(BundleMgrInterfaceCode::ADD_DESKTOP_SHORTCUT_INFO):
582             errCode = this->HandleAddDesktopShortcutInfo(data, reply);
583             break;
584         case static_cast<uint32_t>(BundleMgrInterfaceCode::DELETE_DESKTOP_SHORTCUT_INFO):
585             errCode = this->HandleDeleteDesktopShortcutInfo(data, reply);
586             break;
587         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_DESKTOP_SHORTCUT_INFO):
588             errCode = this->HandleGetAllDesktopShortcutInfo(data, reply);
589             break;
590         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_COMPATIBLED_DEVICE_TYPE_NATIVE):
591             errCode = HandleGetCompatibleDeviceTypeNative(data, reply);
592             break;
593         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_COMPATIBLED_DEVICE_TYPE):
594             errCode = HandleGetCompatibleDeviceType(data, reply);
595             break;
596         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ODID_BY_BUNDLENAME):
597             errCode = this->HandleGetOdidByBundleName(data, reply);
598             break;
599         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFOS_FOR_CONTINUATION):
600             errCode = this->HandleGetBundleInfosForContinuation(data, reply);
601             break;
602         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_CONTINUE_BUNDLE_NAMES):
603             errCode = HandleGetContinueBundleNames(data, reply);
604             break;
605         case static_cast<uint32_t>(BundleMgrInterfaceCode::IS_BUNDLE_INSTALLED):
606             errCode = HandleIsBundleInstalled(data, reply);
607             break;
608         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_NAME_BY_APP_ID_OR_APP_IDENTIFIER):
609             errCode = HandleGetBundleNameByAppId(data, reply);
610             break;
611         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_DIR_BY_BUNDLENAME_AND_APPINDEX):
612             errCode = HandleGetDirByBundleNameAndAppIndex(data, reply);
613             break;
614         case static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_BUNDLE_DIRS):
615             errCode = HandleGetAllBundleDirs(data, reply);
616             break;
617         default :
618             APP_LOGW("bundleMgr host receives unknown code %{public}u", code);
619             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
620     }
621     APP_LOGD("bundleMgr host finish to process message, errCode: %{public}d", errCode);
622     return (errCode == ERR_OK) ? NO_ERROR : UNKNOWN_ERROR;
623 }
624 
HandleGetApplicationInfo(MessageParcel & data,MessageParcel & reply)625 ErrCode BundleMgrHost::HandleGetApplicationInfo(MessageParcel &data, MessageParcel &reply)
626 {
627     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
628     std::string name = data.ReadString();
629     ApplicationFlag flag = static_cast<ApplicationFlag>(data.ReadInt32());
630     int userId = data.ReadInt32();
631     APP_LOGD("name %{public}s, flag %{public}d, userId %{public}d", name.c_str(), flag, userId);
632 
633     ApplicationInfo info;
634     bool ret = GetApplicationInfo(name, flag, userId, info);
635     if (!reply.WriteBool(ret)) {
636         APP_LOGE("write failed");
637         return ERR_APPEXECFWK_PARCEL_ERROR;
638     }
639     if (ret) {
640         if (!reply.WriteParcelable(&info)) {
641             APP_LOGE("write failed");
642             return ERR_APPEXECFWK_PARCEL_ERROR;
643         }
644     }
645     return ERR_OK;
646 }
647 
HandleGetApplicationInfoWithIntFlags(MessageParcel & data,MessageParcel & reply)648 ErrCode BundleMgrHost::HandleGetApplicationInfoWithIntFlags(MessageParcel &data, MessageParcel &reply)
649 {
650     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
651     std::string name = data.ReadString();
652     int flags = data.ReadInt32();
653     int userId = data.ReadInt32();
654     APP_LOGD("name %{public}s, flags %{public}d, userId %{public}d", name.c_str(), flags, userId);
655 
656     ApplicationInfo info;
657     bool ret = GetApplicationInfo(name, flags, userId, info);
658     if (!reply.WriteBool(ret)) {
659         APP_LOGE("write failed");
660         return ERR_APPEXECFWK_PARCEL_ERROR;
661     }
662     if (ret) {
663         if (!reply.WriteParcelable(&info)) {
664             APP_LOGE("write failed");
665             return ERR_APPEXECFWK_PARCEL_ERROR;
666         }
667     }
668     return ERR_OK;
669 }
670 
HandleGetApplicationInfoWithIntFlagsV9(MessageParcel & data,MessageParcel & reply)671 ErrCode BundleMgrHost::HandleGetApplicationInfoWithIntFlagsV9(MessageParcel &data, MessageParcel &reply)
672 {
673     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
674     std::string name = data.ReadString();
675     int32_t flags = data.ReadInt32();
676     int32_t userId = data.ReadInt32();
677     APP_LOGD("name %{public}s, flags %{public}d, userId %{public}d", name.c_str(), flags, userId);
678 
679     ApplicationInfo info;
680     auto ret = GetApplicationInfoV9(name, flags, userId, info);
681     if (!reply.WriteInt32(ret)) {
682         APP_LOGE("write failed");
683         return ERR_APPEXECFWK_PARCEL_ERROR;
684     }
685     if (ret == ERR_OK) {
686         if (!reply.WriteParcelable(&info)) {
687             APP_LOGE("write failed");
688             return ERR_APPEXECFWK_PARCEL_ERROR;
689         }
690     }
691     return ERR_OK;
692 }
693 
HandleGetApplicationInfos(MessageParcel & data,MessageParcel & reply)694 ErrCode BundleMgrHost::HandleGetApplicationInfos(MessageParcel &data, MessageParcel &reply)
695 {
696     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
697     ApplicationFlag flag = static_cast<ApplicationFlag>(data.ReadInt32());
698     int userId = data.ReadInt32();
699     std::vector<ApplicationInfo> infos;
700     bool ret = GetApplicationInfos(flag, userId, infos);
701     if (!reply.WriteBool(ret)) {
702         APP_LOGE("write failed");
703         return ERR_APPEXECFWK_PARCEL_ERROR;
704     }
705     if (ret) {
706         if (!WriteParcelableVector(infos, reply)) {
707             APP_LOGE("write failed");
708             return ERR_APPEXECFWK_PARCEL_ERROR;
709         }
710     }
711     return ERR_OK;
712 }
713 
HandleGetApplicationInfosWithIntFlags(MessageParcel & data,MessageParcel & reply)714 ErrCode BundleMgrHost::HandleGetApplicationInfosWithIntFlags(MessageParcel &data, MessageParcel &reply)
715 {
716     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
717     int flags = data.ReadInt32();
718     int userId = data.ReadInt32();
719     std::vector<ApplicationInfo> infos;
720     bool ret = GetApplicationInfos(flags, userId, infos);
721     if (!reply.WriteBool(ret)) {
722         APP_LOGE("write failed");
723         return ERR_APPEXECFWK_PARCEL_ERROR;
724     }
725     if (ret) {
726         if (!WriteVectorToParcelIntelligent(infos, reply)) {
727             APP_LOGE("write failed");
728             return ERR_APPEXECFWK_PARCEL_ERROR;
729         }
730     }
731     return ERR_OK;
732 }
733 
HandleGetApplicationInfosWithIntFlagsV9(MessageParcel & data,MessageParcel & reply)734 ErrCode BundleMgrHost::HandleGetApplicationInfosWithIntFlagsV9(MessageParcel &data, MessageParcel &reply)
735 {
736     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
737     int32_t flags = data.ReadInt32();
738     int32_t userId = data.ReadInt32();
739     std::vector<ApplicationInfo> infos;
740     auto ret = GetApplicationInfosV9(flags, userId, infos);
741     if (!reply.WriteInt32(ret)) {
742         APP_LOGE("write failed");
743         return ERR_APPEXECFWK_PARCEL_ERROR;
744     }
745     if (ret == ERR_OK) {
746         if (!WriteVectorToParcelIntelligent(infos, reply)) {
747             APP_LOGE("write failed");
748             return ERR_APPEXECFWK_PARCEL_ERROR;
749         }
750     }
751     return ERR_OK;
752 }
753 
HandleGetBundleInfo(MessageParcel & data,MessageParcel & reply)754 ErrCode BundleMgrHost::HandleGetBundleInfo(MessageParcel &data, MessageParcel &reply)
755 {
756     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
757     std::string name = data.ReadString();
758     BundleFlag flag = static_cast<BundleFlag>(data.ReadInt32());
759     int userId = data.ReadInt32();
760     APP_LOGD("name %{public}s, flag %{public}d", name.c_str(), flag);
761     BundleInfo info;
762     bool ret = GetBundleInfo(name, flag, info, userId);
763     if (ret) {
764         WRITE_PARCEL(reply.WriteInt32(ERR_OK));
765         return WriteParcelInfoIntelligent(info, reply);
766     }
767     WRITE_PARCEL(reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR));
768     return ERR_OK;
769 }
770 
HandleGetBundleInfoForSelf(MessageParcel & data,MessageParcel & reply)771 ErrCode BundleMgrHost::HandleGetBundleInfoForSelf(MessageParcel &data, MessageParcel &reply)
772 {
773     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
774     int32_t flags = data.ReadInt32();
775     APP_LOGD("GetBundleInfoForSelf, flags %{public}d", flags);
776     BundleInfo info;
777     auto ret = GetBundleInfoForSelf(flags, info);
778     if (!reply.WriteInt32(ret)) {
779         APP_LOGE("write failed");
780         return ERR_APPEXECFWK_PARCEL_ERROR;
781     }
782     reply.SetDataCapacity(Constants::CAPACITY_SIZE);
783     if (ret == ERR_OK && !reply.WriteParcelable(&info)) {
784         APP_LOGE("write failed");
785         return ERR_APPEXECFWK_PARCEL_ERROR;
786     }
787     return ERR_OK;
788 }
789 
HandleGetDependentBundleInfo(MessageParcel & data,MessageParcel & reply)790 ErrCode BundleMgrHost::HandleGetDependentBundleInfo(MessageParcel &data, MessageParcel &reply)
791 {
792     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
793     std::string name = data.ReadString();
794     GetDependentBundleInfoFlag flag = static_cast<GetDependentBundleInfoFlag>(data.ReadUint32());
795     APP_LOGD("GetDependentBundleInfo, bundle %{public}s", name.c_str());
796     BundleInfo info;
797     auto ret = GetDependentBundleInfo(name, info, flag);
798     if (!reply.WriteInt32(ret)) {
799         APP_LOGE("write failed");
800         return ERR_APPEXECFWK_PARCEL_ERROR;
801     }
802     reply.SetDataCapacity(Constants::CAPACITY_SIZE);
803     if (ret == ERR_OK && !reply.WriteParcelable(&info)) {
804         APP_LOGE("write failed");
805         return ERR_APPEXECFWK_PARCEL_ERROR;
806     }
807     return ERR_OK;
808 }
809 
HandleGetBundleInfoWithIntFlags(MessageParcel & data,MessageParcel & reply)810 ErrCode BundleMgrHost::HandleGetBundleInfoWithIntFlags(MessageParcel &data, MessageParcel &reply)
811 {
812     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
813     std::string name = data.ReadString();
814     int flags = data.ReadInt32();
815     int userId = data.ReadInt32();
816     APP_LOGD("name %{public}s, flags %{public}d", name.c_str(), flags);
817     BundleInfo info;
818     bool ret = GetBundleInfo(name, flags, info, userId);
819     if (ret) {
820         reply.SetDataCapacity(Constants::CAPACITY_SIZE);
821         WRITE_PARCEL(reply.WriteInt32(ERR_OK));
822         return WriteParcelInfoIntelligent(info, reply);
823     }
824     WRITE_PARCEL(reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR));
825     return ERR_OK;
826 }
827 
HandleGetBundleInfoWithIntFlagsV9(MessageParcel & data,MessageParcel & reply)828 ErrCode BundleMgrHost::HandleGetBundleInfoWithIntFlagsV9(MessageParcel &data, MessageParcel &reply)
829 {
830     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
831     std::string name = data.ReadString();
832     if (name.empty()) {
833         APP_LOGE("bundleName is empty");
834         return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
835     }
836     int32_t flags = data.ReadInt32();
837     int32_t userId = data.ReadInt32();
838     APP_LOGD("name %{public}s, flags %{public}d", name.c_str(), flags);
839     BundleInfo info;
840     auto ret = GetBundleInfoV9(name, flags, info, userId);
841     if (!reply.WriteInt32(ret)) {
842         APP_LOGE("write failed");
843         return ERR_APPEXECFWK_PARCEL_ERROR;
844     }
845     if (ret == ERR_OK) {
846         reply.SetDataCapacity(Constants::CAPACITY_SIZE);
847         return WriteParcelInfoIntelligent<BundleInfo>(info, reply);
848     }
849     return ERR_OK;
850 }
851 
HandleBatchGetBundleInfo(MessageParcel & data,MessageParcel & reply)852 ErrCode BundleMgrHost::HandleBatchGetBundleInfo(MessageParcel &data, MessageParcel &reply)
853 {
854     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
855     int32_t bundleNameCount = data.ReadInt32();
856     if (bundleNameCount <= 0 || bundleNameCount > MAX_BATCH_QUERY_BUNDLE_SIZE) {
857         APP_LOGE("bundleName count is error");
858         return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
859     }
860     std::vector<std::string> bundleNames;
861     for (int i = 0; i < bundleNameCount; i++) {
862         std::string bundleName = data.ReadString();
863         if (bundleName.empty()) {
864             APP_LOGE("bundleName %{public}d is empty", i);
865             return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
866         }
867         bundleNames.push_back(bundleName);
868     }
869 
870     int32_t flags = data.ReadInt32();
871     int32_t userId = data.ReadInt32();
872     std::vector<BundleInfo> bundleInfos;
873     auto ret = BatchGetBundleInfo(bundleNames, flags, bundleInfos, userId);
874     if (!reply.WriteInt32(ret)) {
875         APP_LOGE("write failed");
876         return ERR_APPEXECFWK_PARCEL_ERROR;
877     }
878     if (ret == ERR_OK) {
879         reply.SetDataCapacity(Constants::CAPACITY_SIZE);
880         if (!WriteVectorToParcelIntelligent(bundleInfos, reply)) {
881             APP_LOGE("write failed");
882             return ERR_APPEXECFWK_PARCEL_ERROR;
883         }
884     }
885     return ERR_OK;
886 }
887 
HandleGetBundlePackInfo(MessageParcel & data,MessageParcel & reply)888 ErrCode BundleMgrHost::HandleGetBundlePackInfo(MessageParcel &data, MessageParcel &reply)
889 {
890     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
891     std::string name = data.ReadString();
892     BundlePackFlag flag = static_cast<BundlePackFlag>(data.ReadInt32());
893     int userId = data.ReadInt32();
894     APP_LOGD("name %{public}s, flag %{public}d", name.c_str(), flag);
895     BundlePackInfo info;
896     ErrCode ret = GetBundlePackInfo(name, flag, info, userId);
897     if (!reply.WriteInt32(ret)) {
898         APP_LOGE("write failed");
899         return ERR_APPEXECFWK_PARCEL_ERROR;
900     }
901     if (ret == ERR_OK) {
902         if (!reply.WriteParcelable(&info)) {
903             APP_LOGE("write failed");
904             return ERR_APPEXECFWK_PARCEL_ERROR;
905         }
906     }
907     return ERR_OK;
908 }
909 
HandleGetBundlePackInfoWithIntFlags(MessageParcel & data,MessageParcel & reply)910 ErrCode BundleMgrHost::HandleGetBundlePackInfoWithIntFlags(MessageParcel &data, MessageParcel &reply)
911 {
912     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
913     std::string name = data.ReadString();
914     int flags = data.ReadInt32();
915     int userId = data.ReadInt32();
916     APP_LOGD("name %{public}s, flags %{public}d", name.c_str(), flags);
917     BundlePackInfo info;
918     ErrCode ret = GetBundlePackInfo(name, flags, info, userId);
919     if (!reply.WriteInt32(ret)) {
920         APP_LOGE("write failed");
921         return ERR_APPEXECFWK_PARCEL_ERROR;
922     }
923     if (ret == ERR_OK) {
924         if (!reply.WriteParcelable(&info)) {
925             APP_LOGE("write failed");
926             return ERR_APPEXECFWK_PARCEL_ERROR;
927         }
928     }
929     return ERR_OK;
930 }
931 
HandleGetBundleInfos(MessageParcel & data,MessageParcel & reply)932 ErrCode BundleMgrHost::HandleGetBundleInfos(MessageParcel &data, MessageParcel &reply)
933 {
934     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
935     BundleFlag flag = static_cast<BundleFlag>(data.ReadInt32());
936     int userId = data.ReadInt32();
937 
938     std::vector<BundleInfo> infos;
939     bool ret = GetBundleInfos(flag, infos, userId);
940     if (!reply.WriteBool(ret)) {
941         APP_LOGE("write failed");
942         return ERR_APPEXECFWK_PARCEL_ERROR;
943     }
944     if (ret) {
945         reply.SetDataCapacity(MAX_CAPACITY_BUNDLES);
946         if (!WriteVectorToParcelIntelligent(infos, reply)) {
947             APP_LOGE("write failed");
948             return ERR_APPEXECFWK_PARCEL_ERROR;
949         }
950     }
951     APP_LOGI("bundles %{public}zu, size %{public}zu", infos.size(), reply.GetRawDataSize());
952     return ERR_OK;
953 }
954 
HandleGetBundleInfosWithIntFlags(MessageParcel & data,MessageParcel & reply)955 ErrCode BundleMgrHost::HandleGetBundleInfosWithIntFlags(MessageParcel &data, MessageParcel &reply)
956 {
957     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
958     int flags = data.ReadInt32();
959     int userId = data.ReadInt32();
960 
961     std::vector<BundleInfo> infos;
962     bool ret = GetBundleInfos(flags, infos, userId);
963     if (!reply.WriteBool(ret)) {
964         APP_LOGE("write failed");
965         return ERR_APPEXECFWK_PARCEL_ERROR;
966     }
967     if (ret) {
968         reply.SetDataCapacity(MAX_CAPACITY_BUNDLES);
969         if (!WriteVectorToParcelIntelligent(infos, reply)) {
970             APP_LOGE("write failed");
971             return ERR_APPEXECFWK_PARCEL_ERROR;
972         }
973     }
974     APP_LOGI("bundles %{public}zu, size %{public}zu", infos.size(), reply.GetRawDataSize());
975     return ERR_OK;
976 }
977 
HandleGetBundleInfosWithIntFlagsV9(MessageParcel & data,MessageParcel & reply)978 ErrCode BundleMgrHost::HandleGetBundleInfosWithIntFlagsV9(MessageParcel &data, MessageParcel &reply)
979 {
980     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
981     int32_t flags = data.ReadInt32();
982     int32_t userId = data.ReadInt32();
983 
984     std::vector<BundleInfo> infos;
985     auto ret = GetBundleInfosV9(flags, infos, userId);
986     if (!reply.WriteInt32(ret)) {
987         APP_LOGE("write failed");
988         return ERR_APPEXECFWK_PARCEL_ERROR;
989     }
990     if (ret == ERR_OK) {
991         if (!WriteVectorToParcelIntelligent(infos, reply)) {
992             APP_LOGE("write failed");
993             return ERR_APPEXECFWK_PARCEL_ERROR;
994         }
995     }
996     APP_LOGI("bundles %{public}zu, size %{public}zu", infos.size(), reply.GetRawDataSize());
997     return ERR_OK;
998 }
999 
HandleGetBundleNameForUid(MessageParcel & data,MessageParcel & reply)1000 ErrCode BundleMgrHost::HandleGetBundleNameForUid(MessageParcel &data, MessageParcel &reply)
1001 {
1002     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1003     auto uid = data.ReadInt32();
1004     std::string name;
1005     bool ret = GetBundleNameForUid(uid, name);
1006     if (!reply.WriteBool(ret)) {
1007         APP_LOGE("write failed");
1008         return ERR_APPEXECFWK_PARCEL_ERROR;
1009     }
1010     if (ret) {
1011         if (!reply.WriteString(name)) {
1012             APP_LOGE("write failed");
1013             return ERR_APPEXECFWK_PARCEL_ERROR;
1014         }
1015     }
1016     return ERR_OK;
1017 }
1018 
HandleGetBundlesForUid(MessageParcel & data,MessageParcel & reply)1019 ErrCode BundleMgrHost::HandleGetBundlesForUid(MessageParcel &data, MessageParcel &reply)
1020 {
1021     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1022     int uid = data.ReadInt32();
1023     std::vector<std::string> names;
1024     bool ret = GetBundlesForUid(uid, names);
1025     if (!reply.WriteBool(ret)) {
1026         APP_LOGE("write failed");
1027         return ERR_APPEXECFWK_PARCEL_ERROR;
1028     }
1029     if (ret) {
1030         if (!reply.WriteStringVector(names)) {
1031             APP_LOGE("write failed");
1032             return ERR_APPEXECFWK_PARCEL_ERROR;
1033         }
1034     }
1035     return ERR_OK;
1036 }
1037 
HandleGetNameForUid(MessageParcel & data,MessageParcel & reply)1038 ErrCode BundleMgrHost::HandleGetNameForUid(MessageParcel &data, MessageParcel &reply)
1039 {
1040     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1041     int uid = data.ReadInt32();
1042     std::string name;
1043     ErrCode ret = GetNameForUid(uid, name);
1044     if (!reply.WriteInt32(ret)) {
1045         APP_LOGE("write failed");
1046         return ERR_APPEXECFWK_PARCEL_ERROR;
1047     }
1048     if (ret == ERR_OK) {
1049         if (!reply.WriteString(name)) {
1050             APP_LOGE("write failed");
1051             return ERR_APPEXECFWK_PARCEL_ERROR;
1052         }
1053     }
1054     return ERR_OK;
1055 }
1056 
HandleGetNameAndIndexForUid(MessageParcel & data,MessageParcel & reply)1057 ErrCode BundleMgrHost::HandleGetNameAndIndexForUid(MessageParcel &data, MessageParcel &reply)
1058 {
1059     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1060     int uid = data.ReadInt32();
1061     std::string bundleName;
1062     int32_t appIndex;
1063     ErrCode ret = GetNameAndIndexForUid(uid, bundleName, appIndex);
1064     if (!reply.WriteInt32(ret)) {
1065         APP_LOGE("write failed");
1066         return ERR_APPEXECFWK_PARCEL_ERROR;
1067     }
1068     if (ret == ERR_OK) {
1069         if (!reply.WriteString(bundleName)) {
1070             APP_LOGE("write failed");
1071             return ERR_APPEXECFWK_PARCEL_ERROR;
1072         }
1073         if (!reply.WriteInt32(appIndex)) {
1074             APP_LOGE("write failed");
1075             return ERR_APPEXECFWK_PARCEL_ERROR;
1076         }
1077     }
1078     return ERR_OK;
1079 }
1080 
HandleGetBundleGids(MessageParcel & data,MessageParcel & reply)1081 ErrCode BundleMgrHost::HandleGetBundleGids(MessageParcel &data, MessageParcel &reply)
1082 {
1083     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1084     std::string name = data.ReadString();
1085 
1086     std::vector<int> gids;
1087     bool ret = GetBundleGids(name, gids);
1088     if (!reply.WriteBool(ret)) {
1089         APP_LOGE("write failed");
1090         return ERR_APPEXECFWK_PARCEL_ERROR;
1091     }
1092     if (ret) {
1093         if (!reply.WriteInt32Vector(gids)) {
1094             APP_LOGE("write failed");
1095             return ERR_APPEXECFWK_PARCEL_ERROR;
1096         }
1097     }
1098     return ERR_OK;
1099 }
1100 
HandleGetBundleGidsByUid(MessageParcel & data,MessageParcel & reply)1101 ErrCode BundleMgrHost::HandleGetBundleGidsByUid(MessageParcel &data, MessageParcel &reply)
1102 {
1103     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1104     std::string name = data.ReadString();
1105     int uid = data.ReadInt32();
1106 
1107     std::vector<int> gids;
1108     bool ret = GetBundleGidsByUid(name, uid, gids);
1109     if (!reply.WriteBool(ret)) {
1110         APP_LOGE("write failed");
1111         return ERR_APPEXECFWK_PARCEL_ERROR;
1112     }
1113     if (ret) {
1114         if (!reply.WriteInt32Vector(gids)) {
1115             APP_LOGE("write failed");
1116             return ERR_APPEXECFWK_PARCEL_ERROR;
1117         }
1118     }
1119     return ERR_OK;
1120 }
1121 
HandleGetBundleInfosByMetaData(MessageParcel & data,MessageParcel & reply)1122 ErrCode BundleMgrHost::HandleGetBundleInfosByMetaData(MessageParcel &data, MessageParcel &reply)
1123 {
1124     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1125     std::string metaData = data.ReadString();
1126 
1127     std::vector<BundleInfo> infos;
1128     bool ret = GetBundleInfosByMetaData(metaData, infos);
1129     if (!reply.WriteBool(ret)) {
1130         APP_LOGE("write failed");
1131         return ERR_APPEXECFWK_PARCEL_ERROR;
1132     }
1133     if (ret) {
1134         if (!WriteParcelableVector(infos, reply)) {
1135             APP_LOGE("write failed");
1136             return ERR_APPEXECFWK_PARCEL_ERROR;
1137         }
1138     }
1139     return ERR_OK;
1140 }
1141 
HandleQueryAbilityInfo(MessageParcel & data,MessageParcel & reply)1142 ErrCode BundleMgrHost::HandleQueryAbilityInfo(MessageParcel &data, MessageParcel &reply)
1143 {
1144     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1145     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1146     if (want == nullptr) {
1147         APP_LOGE("ReadParcelable<want> failed");
1148         return ERR_APPEXECFWK_PARCEL_ERROR;
1149     }
1150 
1151     AbilityInfo info;
1152     bool ret = QueryAbilityInfo(*want, info);
1153     if (!reply.WriteBool(ret)) {
1154         APP_LOGE("write failed");
1155         return ERR_APPEXECFWK_PARCEL_ERROR;
1156     }
1157     if (ret) {
1158         if (!reply.WriteParcelable(&info)) {
1159             APP_LOGE("write failed");
1160             return ERR_APPEXECFWK_PARCEL_ERROR;
1161         }
1162     }
1163     return ERR_OK;
1164 }
1165 
HandleQueryAbilityInfoMutiparam(MessageParcel & data,MessageParcel & reply)1166 ErrCode BundleMgrHost::HandleQueryAbilityInfoMutiparam(MessageParcel &data, MessageParcel &reply)
1167 {
1168     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1169     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1170     if (want == nullptr) {
1171         APP_LOGE("ReadParcelable<want> failed");
1172         return ERR_APPEXECFWK_PARCEL_ERROR;
1173     }
1174     int32_t flags = data.ReadInt32();
1175     int32_t userId = data.ReadInt32();
1176     AbilityInfo info;
1177     bool ret = QueryAbilityInfo(*want, flags, userId, info);
1178     if (!reply.WriteBool(ret)) {
1179         APP_LOGE("write failed");
1180         return ERR_APPEXECFWK_PARCEL_ERROR;
1181     }
1182     if (ret) {
1183         if (!reply.WriteParcelable(&info)) {
1184             APP_LOGE("write failed");
1185             return ERR_APPEXECFWK_PARCEL_ERROR;
1186         }
1187     }
1188     return ERR_OK;
1189 }
1190 
HandleQueryAbilityInfos(MessageParcel & data,MessageParcel & reply)1191 ErrCode BundleMgrHost::HandleQueryAbilityInfos(MessageParcel &data, MessageParcel &reply)
1192 {
1193     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1194     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1195     if (want == nullptr) {
1196         APP_LOGE("ReadParcelable<want> failed");
1197         return ERR_APPEXECFWK_PARCEL_ERROR;
1198     }
1199 
1200     std::vector<AbilityInfo> abilityInfos;
1201     bool ret = QueryAbilityInfos(*want, abilityInfos);
1202     if (!reply.WriteBool(ret)) {
1203         APP_LOGE("write failed");
1204         return ERR_APPEXECFWK_PARCEL_ERROR;
1205     }
1206     if (ret) {
1207         if (!WriteParcelableVector(abilityInfos, reply)) {
1208             APP_LOGE("write failed");
1209             return ERR_APPEXECFWK_PARCEL_ERROR;
1210         }
1211     }
1212     return ERR_OK;
1213 }
1214 
HandleQueryAbilityInfosMutiparam(MessageParcel & data,MessageParcel & reply)1215 ErrCode BundleMgrHost::HandleQueryAbilityInfosMutiparam(MessageParcel &data, MessageParcel &reply)
1216 {
1217     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1218     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1219     if (want == nullptr) {
1220         APP_LOGE("ReadParcelable<want> failed");
1221         return ERR_APPEXECFWK_PARCEL_ERROR;
1222     }
1223     int32_t flags = data.ReadInt32();
1224     int32_t userId = data.ReadInt32();
1225     std::vector<AbilityInfo> abilityInfos;
1226     bool ret = QueryAbilityInfos(*want, flags, userId, abilityInfos);
1227     if (!reply.WriteBool(ret)) {
1228         APP_LOGE("write failed");
1229         return ERR_APPEXECFWK_PARCEL_ERROR;
1230     }
1231     if (ret) {
1232         if (!WriteVectorToParcelIntelligent(abilityInfos, reply)) {
1233             APP_LOGE("write failed");
1234             return ERR_APPEXECFWK_PARCEL_ERROR;
1235         }
1236     }
1237     return ERR_OK;
1238 }
1239 
HandleQueryAbilityInfosV9(MessageParcel & data,MessageParcel & reply)1240 ErrCode BundleMgrHost::HandleQueryAbilityInfosV9(MessageParcel &data, MessageParcel &reply)
1241 {
1242     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1243     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1244     if (want == nullptr) {
1245         APP_LOGE("ReadParcelable<want> failed");
1246         return ERR_APPEXECFWK_PARCEL_ERROR;
1247     }
1248     int32_t flags = data.ReadInt32();
1249     int32_t userId = data.ReadInt32();
1250     std::vector<AbilityInfo> abilityInfos;
1251     ErrCode ret = QueryAbilityInfosV9(*want, flags, userId, abilityInfos);
1252     if (!reply.WriteInt32(ret)) {
1253         APP_LOGE("write ret failed");
1254         return ERR_APPEXECFWK_PARCEL_ERROR;
1255     }
1256     if (ret == ERR_OK) {
1257         if (!WriteVectorToParcelIntelligent(abilityInfos, reply)) {
1258             APP_LOGE("WriteVectorToParcelIntelligent failed");
1259             return ERR_APPEXECFWK_PARCEL_ERROR;
1260         }
1261     }
1262     return ERR_OK;
1263 }
1264 
HandleBatchQueryAbilityInfos(MessageParcel & data,MessageParcel & reply)1265 ErrCode BundleMgrHost::HandleBatchQueryAbilityInfos(MessageParcel &data, MessageParcel &reply)
1266 {
1267     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1268     int32_t wantCount = data.ReadInt32();
1269     if (wantCount <= 0 || wantCount > MAX_BATCH_QUERY_ABILITY_SIZE) {
1270         APP_LOGE("want count is error");
1271         return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
1272     }
1273     std::vector<Want> wants;
1274     for (int i = 0; i < wantCount; i++) {
1275         std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1276         if (want == nullptr) {
1277             APP_LOGE("ReadParcelable<want> failed");
1278             return ERR_APPEXECFWK_PARCEL_ERROR;
1279         }
1280         wants.push_back(*want);
1281     }
1282 
1283     int32_t flags = data.ReadInt32();
1284     int32_t userId = data.ReadInt32();
1285     std::vector<AbilityInfo> abilityInfos;
1286     ErrCode ret = BatchQueryAbilityInfos(wants, flags, userId, abilityInfos);
1287     if (!reply.WriteInt32(ret)) {
1288         APP_LOGE("write ret failed");
1289         return ERR_APPEXECFWK_PARCEL_ERROR;
1290     }
1291     if (ret == ERR_OK) {
1292         if (!WriteVectorToParcelIntelligent(abilityInfos, reply)) {
1293             APP_LOGE("WriteVectorToParcelIntelligent failed");
1294             return ERR_APPEXECFWK_PARCEL_ERROR;
1295         }
1296     }
1297     return ERR_OK;
1298 }
1299 
HandleQueryLauncherAbilityInfos(MessageParcel & data,MessageParcel & reply)1300 ErrCode BundleMgrHost::HandleQueryLauncherAbilityInfos(MessageParcel &data, MessageParcel &reply)
1301 {
1302     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1303     if (want == nullptr) {
1304         APP_LOGE("ReadParcelable<want> failed");
1305         return ERR_APPEXECFWK_PARCEL_ERROR;
1306     }
1307     int32_t userId = data.ReadInt32();
1308     std::vector<AbilityInfo> abilityInfos;
1309     ErrCode ret = QueryLauncherAbilityInfos(*want, userId, abilityInfos);
1310     if (!reply.WriteInt32(ret)) {
1311         APP_LOGE("write ret failed");
1312         return ERR_APPEXECFWK_PARCEL_ERROR;
1313     }
1314     if (ret == ERR_OK) {
1315         if (!WriteVectorToParcelIntelligent(abilityInfos, reply)) {
1316             APP_LOGE("WriteVectorToParcelIntelligent failed");
1317             return ERR_APPEXECFWK_PARCEL_ERROR;
1318         }
1319     }
1320     return ERR_OK;
1321 }
1322 
HandleQueryAllAbilityInfos(MessageParcel & data,MessageParcel & reply)1323 ErrCode BundleMgrHost::HandleQueryAllAbilityInfos(MessageParcel &data, MessageParcel &reply)
1324 {
1325     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1326     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1327     if (want == nullptr) {
1328         APP_LOGE("ReadParcelable<want> failed");
1329         return ERR_APPEXECFWK_PARCEL_ERROR;
1330     }
1331     int32_t userId = data.ReadInt32();
1332     std::vector<AbilityInfo> abilityInfos;
1333     bool ret = QueryAllAbilityInfos(*want, userId, abilityInfos);
1334     if (!reply.WriteBool(ret)) {
1335         APP_LOGE("write failed");
1336         return ERR_APPEXECFWK_PARCEL_ERROR;
1337     }
1338     if (ret) {
1339         if (!WriteVectorToParcelIntelligent(abilityInfos, reply)) {
1340             APP_LOGE("write failed");
1341             return ERR_APPEXECFWK_PARCEL_ERROR;
1342         }
1343     }
1344     return ERR_OK;
1345 }
1346 
HandleQueryAbilityInfoByUri(MessageParcel & data,MessageParcel & reply)1347 ErrCode BundleMgrHost::HandleQueryAbilityInfoByUri(MessageParcel &data, MessageParcel &reply)
1348 {
1349     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1350     std::string abilityUri = data.ReadString();
1351     AbilityInfo info;
1352     bool ret = QueryAbilityInfoByUri(abilityUri, info);
1353     if (!reply.WriteBool(ret)) {
1354         APP_LOGE("write failed");
1355         return ERR_APPEXECFWK_PARCEL_ERROR;
1356     }
1357     if (ret) {
1358         if (!reply.WriteParcelable(&info)) {
1359             APP_LOGE("write failed");
1360             return ERR_APPEXECFWK_PARCEL_ERROR;
1361         }
1362     }
1363     return ERR_OK;
1364 }
1365 
HandleQueryAbilityInfosByUri(MessageParcel & data,MessageParcel & reply)1366 ErrCode BundleMgrHost::HandleQueryAbilityInfosByUri(MessageParcel &data, MessageParcel &reply)
1367 {
1368     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1369     std::string abilityUri = data.ReadString();
1370     std::vector<AbilityInfo> abilityInfos;
1371     bool ret = QueryAbilityInfosByUri(abilityUri, abilityInfos);
1372     if (!reply.WriteBool(ret)) {
1373         APP_LOGE("write failed");
1374         return ERR_APPEXECFWK_PARCEL_ERROR;
1375     }
1376     if (ret) {
1377         if (!WriteParcelableVector(abilityInfos, reply)) {
1378             APP_LOGE("write failed");
1379             return ERR_APPEXECFWK_PARCEL_ERROR;
1380         }
1381     }
1382     return ERR_OK;
1383 }
1384 
HandleQueryAbilityInfoByUriForUserId(MessageParcel & data,MessageParcel & reply)1385 ErrCode BundleMgrHost::HandleQueryAbilityInfoByUriForUserId(MessageParcel &data, MessageParcel &reply)
1386 {
1387     std::string abilityUri = data.ReadString();
1388     int32_t userId = data.ReadInt32();
1389     AbilityInfo info;
1390     bool ret = QueryAbilityInfoByUri(abilityUri, userId, info);
1391     if (!reply.WriteBool(ret)) {
1392         APP_LOGE("write failed");
1393         return ERR_APPEXECFWK_PARCEL_ERROR;
1394     }
1395     if (ret) {
1396         if (!reply.WriteParcelable(&info)) {
1397             APP_LOGE("write failed");
1398             return ERR_APPEXECFWK_PARCEL_ERROR;
1399         }
1400     }
1401     return ERR_OK;
1402 }
1403 
HandleQueryKeepAliveBundleInfos(MessageParcel & data,MessageParcel & reply)1404 ErrCode BundleMgrHost::HandleQueryKeepAliveBundleInfos(MessageParcel &data, MessageParcel &reply)
1405 {
1406     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1407     std::vector<BundleInfo> infos;
1408     bool ret = QueryKeepAliveBundleInfos(infos);
1409     if (!reply.WriteBool(ret)) {
1410         APP_LOGE("write failed");
1411         return ERR_APPEXECFWK_PARCEL_ERROR;
1412     }
1413     if (ret) {
1414         if (!WriteParcelableVector(infos, reply)) {
1415             APP_LOGE("write failed");
1416             return ERR_APPEXECFWK_PARCEL_ERROR;
1417         }
1418     }
1419     return ERR_OK;
1420 }
1421 
HandleGetAbilityLabel(MessageParcel & data,MessageParcel & reply)1422 ErrCode BundleMgrHost::HandleGetAbilityLabel(MessageParcel &data, MessageParcel &reply)
1423 {
1424     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1425     std::string bundleName = data.ReadString();
1426     std::string abilityName = data.ReadString();
1427 
1428     APP_LOGD("bundleName %{public}s, abilityName %{public}s", bundleName.c_str(), abilityName.c_str());
1429     BundleInfo info;
1430     std::string label = GetAbilityLabel(bundleName, abilityName);
1431     if (!reply.WriteString(label)) {
1432         APP_LOGE("write failed");
1433         return ERR_APPEXECFWK_PARCEL_ERROR;
1434     }
1435     return ERR_OK;
1436 }
1437 
HandleGetAbilityLabelWithModuleName(MessageParcel & data,MessageParcel & reply)1438 ErrCode BundleMgrHost::HandleGetAbilityLabelWithModuleName(MessageParcel &data, MessageParcel &reply)
1439 {
1440     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1441     std::string bundleName = data.ReadString();
1442     std::string moduleName = data.ReadString();
1443     std::string abilityName = data.ReadString();
1444     if (bundleName.empty() || moduleName.empty() || abilityName.empty()) {
1445         APP_LOGE("fail to GetAbilityLabel due to params empty");
1446         return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
1447     }
1448     APP_LOGD("GetAbilityLabe bundleName %{public}s, moduleName %{public}s, abilityName %{public}s",
1449         bundleName.c_str(), moduleName.c_str(), abilityName.c_str());
1450     std::string label;
1451     ErrCode ret = GetAbilityLabel(bundleName, moduleName, abilityName, label);
1452     if (!reply.WriteInt32(ret)) {
1453         return ERR_APPEXECFWK_PARCEL_ERROR;
1454     }
1455     if ((ret == ERR_OK) && !reply.WriteString(label)) {
1456         APP_LOGE("write failed");
1457         return ERR_APPEXECFWK_PARCEL_ERROR;
1458     }
1459     return ERR_OK;
1460 }
1461 
HandleCheckIsSystemAppByUid(MessageParcel & data,MessageParcel & reply)1462 ErrCode BundleMgrHost::HandleCheckIsSystemAppByUid(MessageParcel &data, MessageParcel &reply)
1463 {
1464     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1465     int uid = data.ReadInt32();
1466     bool ret = CheckIsSystemAppByUid(uid);
1467     if (!reply.WriteBool(ret)) {
1468         APP_LOGE("write failed");
1469         return ERR_APPEXECFWK_PARCEL_ERROR;
1470     }
1471     return ERR_OK;
1472 }
1473 
HandleGetBundleArchiveInfo(MessageParcel & data,MessageParcel & reply)1474 ErrCode BundleMgrHost::HandleGetBundleArchiveInfo(MessageParcel &data, MessageParcel &reply)
1475 {
1476     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1477     std::string hapFilePath = data.ReadString();
1478     BundleFlag flag = static_cast<BundleFlag>(data.ReadInt32());
1479     APP_LOGD("hapFilePath %{private}s, flag %{public}d", hapFilePath.c_str(), flag);
1480 
1481     BundleInfo info;
1482     bool ret = GetBundleArchiveInfo(hapFilePath, flag, info);
1483     if (!reply.WriteBool(ret)) {
1484         APP_LOGE("write failed");
1485         return ERR_APPEXECFWK_PARCEL_ERROR;
1486     }
1487     if (ret) {
1488         if (!reply.WriteParcelable(&info)) {
1489             APP_LOGE("write failed");
1490             return ERR_APPEXECFWK_PARCEL_ERROR;
1491         }
1492     }
1493     return ERR_OK;
1494 }
1495 
HandleGetBundleArchiveInfoWithIntFlags(MessageParcel & data,MessageParcel & reply)1496 ErrCode BundleMgrHost::HandleGetBundleArchiveInfoWithIntFlags(MessageParcel &data, MessageParcel &reply)
1497 {
1498     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1499     std::string hapFilePath = data.ReadString();
1500     int32_t flags = data.ReadInt32();
1501     APP_LOGD("hapFilePath %{private}s, flagS %{public}d", hapFilePath.c_str(), flags);
1502 
1503     BundleInfo info;
1504     bool ret = GetBundleArchiveInfo(hapFilePath, flags, info);
1505     if (!reply.WriteBool(ret)) {
1506         APP_LOGE("write failed");
1507         return ERR_APPEXECFWK_PARCEL_ERROR;
1508     }
1509     if (ret) {
1510         if (!reply.WriteParcelable(&info)) {
1511             APP_LOGE("write failed");
1512             return ERR_APPEXECFWK_PARCEL_ERROR;
1513         }
1514     }
1515     return ERR_OK;
1516 }
1517 
HandleGetBundleArchiveInfoWithIntFlagsV9(MessageParcel & data,MessageParcel & reply)1518 ErrCode BundleMgrHost::HandleGetBundleArchiveInfoWithIntFlagsV9(MessageParcel &data, MessageParcel &reply)
1519 {
1520     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1521     std::string hapFilePath = data.ReadString();
1522     int32_t flags = data.ReadInt32();
1523     APP_LOGD("hapFilePath %{private}s, flags %{public}d", hapFilePath.c_str(), flags);
1524 
1525     BundleInfo info;
1526     ErrCode ret = GetBundleArchiveInfoV9(hapFilePath, flags, info);
1527     if (!reply.WriteInt32(ret)) {
1528         APP_LOGE("write failed");
1529         return ERR_APPEXECFWK_PARCEL_ERROR;
1530     }
1531     if (ret == ERR_OK) {
1532         if (!reply.WriteParcelable(&info)) {
1533             APP_LOGE("write failed");
1534             return ERR_APPEXECFWK_PARCEL_ERROR;
1535         }
1536     }
1537     return ERR_OK;
1538 }
1539 
HandleGetHapModuleInfo(MessageParcel & data,MessageParcel & reply)1540 ErrCode BundleMgrHost::HandleGetHapModuleInfo(MessageParcel &data, MessageParcel &reply)
1541 {
1542     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1543     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
1544     if (!abilityInfo) {
1545         APP_LOGE("ReadParcelable<abilityInfo> failed");
1546         return ERR_APPEXECFWK_PARCEL_ERROR;
1547     }
1548 
1549     HapModuleInfo info;
1550     bool ret = GetHapModuleInfo(*abilityInfo, info);
1551     if (!reply.WriteBool(ret)) {
1552         APP_LOGE("write failed");
1553         return ERR_APPEXECFWK_PARCEL_ERROR;
1554     }
1555     if (ret) {
1556         if (!reply.WriteParcelable(&info)) {
1557             APP_LOGE("write failed");
1558             return ERR_APPEXECFWK_PARCEL_ERROR;
1559         }
1560     }
1561     return ERR_OK;
1562 }
1563 
HandleGetHapModuleInfoWithUserId(MessageParcel & data,MessageParcel & reply)1564 ErrCode BundleMgrHost::HandleGetHapModuleInfoWithUserId(MessageParcel &data, MessageParcel &reply)
1565 {
1566     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1567     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
1568     if (abilityInfo == nullptr) {
1569         APP_LOGE("ReadParcelable<abilityInfo> failed");
1570         return ERR_APPEXECFWK_PARCEL_ERROR;
1571     }
1572 
1573     int32_t userId = data.ReadInt32();
1574     HapModuleInfo info;
1575     bool ret = GetHapModuleInfo(*abilityInfo, userId, info);
1576     if (!reply.WriteBool(ret)) {
1577         APP_LOGE("write failed");
1578         return ERR_APPEXECFWK_PARCEL_ERROR;
1579     }
1580     if (ret) {
1581         if (!reply.WriteParcelable(&info)) {
1582             APP_LOGE("write failed");
1583             return ERR_APPEXECFWK_PARCEL_ERROR;
1584         }
1585     }
1586     return ERR_OK;
1587 }
1588 
HandleGetLaunchWantForBundle(MessageParcel & data,MessageParcel & reply)1589 ErrCode BundleMgrHost::HandleGetLaunchWantForBundle(MessageParcel &data, MessageParcel &reply)
1590 {
1591     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1592     std::string bundleName = data.ReadString();
1593     int32_t userId = data.ReadInt32();
1594     APP_LOGD("name %{public}s", bundleName.c_str());
1595 
1596     Want want;
1597     ErrCode ret = GetLaunchWantForBundle(bundleName, want, userId);
1598     if (!reply.WriteInt32(ret)) {
1599         APP_LOGE("write failed");
1600         return ERR_APPEXECFWK_PARCEL_ERROR;
1601     }
1602     if (ret == ERR_OK) {
1603         if (!reply.WriteParcelable(&want)) {
1604             APP_LOGE("write failed");
1605             return ERR_APPEXECFWK_PARCEL_ERROR;
1606         }
1607     }
1608     return ERR_OK;
1609 }
1610 
HandleGetPermissionDef(MessageParcel & data,MessageParcel & reply)1611 ErrCode BundleMgrHost::HandleGetPermissionDef(MessageParcel &data, MessageParcel &reply)
1612 {
1613     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1614     std::string permissionName = data.ReadString();
1615     APP_LOGD("name %{public}s", permissionName.c_str());
1616 
1617     PermissionDef permissionDef;
1618     ErrCode ret = GetPermissionDef(permissionName, permissionDef);
1619     if (!reply.WriteInt32(ret)) {
1620         APP_LOGE("write failed");
1621         return ERR_APPEXECFWK_PARCEL_ERROR;
1622     }
1623     if (ret == ERR_OK) {
1624         if (!reply.WriteParcelable(&permissionDef)) {
1625             APP_LOGE("write failed");
1626             return ERR_APPEXECFWK_PARCEL_ERROR;
1627         }
1628     }
1629     return ERR_OK;
1630 }
1631 
HandleCleanBundleCacheFilesAutomatic(MessageParcel & data,MessageParcel & reply)1632 ErrCode BundleMgrHost::HandleCleanBundleCacheFilesAutomatic(MessageParcel &data, MessageParcel &reply)
1633 {
1634     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1635 
1636     uint64_t cacheSize = data.ReadUint64();
1637     ErrCode ret = CleanBundleCacheFilesAutomatic(cacheSize);
1638 
1639     if (!reply.WriteInt32(ret)) {
1640         APP_LOGE("WriteInt32 failed");
1641         return ERR_APPEXECFWK_PARCEL_ERROR;
1642     }
1643     return ERR_OK;
1644 }
1645 
HandleCleanBundleCacheFiles(MessageParcel & data,MessageParcel & reply)1646 ErrCode BundleMgrHost::HandleCleanBundleCacheFiles(MessageParcel &data, MessageParcel &reply)
1647 {
1648     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1649     std::string bundleName = data.ReadString();
1650     sptr<IRemoteObject> object = data.ReadRemoteObject();
1651     if (object == nullptr) {
1652         APP_LOGE("read failed");
1653         return ERR_APPEXECFWK_PARCEL_ERROR;
1654     }
1655     sptr<ICleanCacheCallback> cleanCacheCallback = iface_cast<ICleanCacheCallback>(object);
1656     int32_t userId = data.ReadInt32();
1657     int32_t appIndex = data.ReadInt32();
1658 
1659     ErrCode ret = CleanBundleCacheFiles(bundleName, cleanCacheCallback, userId, appIndex);
1660     if (!reply.WriteInt32(ret)) {
1661         APP_LOGE("write failed");
1662         return ERR_APPEXECFWK_PARCEL_ERROR;
1663     }
1664     return ERR_OK;
1665 }
1666 
HandleCleanBundleDataFiles(MessageParcel & data,MessageParcel & reply)1667 ErrCode BundleMgrHost::HandleCleanBundleDataFiles(MessageParcel &data, MessageParcel &reply)
1668 {
1669     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1670     std::string bundleName = data.ReadString();
1671     int userId = data.ReadInt32();
1672     int appIndex = data.ReadInt32();
1673 
1674     bool ret = CleanBundleDataFiles(bundleName, userId, appIndex);
1675     if (!reply.WriteBool(ret)) {
1676         APP_LOGE("write failed");
1677         return ERR_APPEXECFWK_PARCEL_ERROR;
1678     }
1679     return ERR_OK;
1680 }
1681 
HandleRegisterBundleStatusCallback(MessageParcel & data,MessageParcel & reply)1682 ErrCode BundleMgrHost::HandleRegisterBundleStatusCallback(MessageParcel &data, MessageParcel &reply)
1683 {
1684     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1685     std::string bundleName = data.ReadString();
1686     int32_t userId = data.ReadInt32();
1687     sptr<IRemoteObject> object = data.ReadRemoteObject();
1688     if (object == nullptr) {
1689         APP_LOGE("read failed");
1690         return ERR_APPEXECFWK_PARCEL_ERROR;
1691     }
1692     sptr<IBundleStatusCallback> BundleStatusCallback = iface_cast<IBundleStatusCallback>(object);
1693 
1694     bool ret = false;
1695     if (bundleName.empty() || !BundleStatusCallback) {
1696         APP_LOGE("Get BundleStatusCallback failed");
1697     } else {
1698         BundleStatusCallback->SetBundleName(bundleName);
1699         BundleStatusCallback->SetUserId(userId);
1700         ret = RegisterBundleStatusCallback(BundleStatusCallback);
1701     }
1702     if (!reply.WriteBool(ret)) {
1703         APP_LOGE("write failed");
1704         return ERR_APPEXECFWK_PARCEL_ERROR;
1705     }
1706     return ERR_OK;
1707 }
1708 
HandleRegisterBundleEventCallback(MessageParcel & data,MessageParcel & reply)1709 ErrCode BundleMgrHost::HandleRegisterBundleEventCallback(MessageParcel &data, MessageParcel &reply)
1710 {
1711     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1712     sptr<IRemoteObject> object = data.ReadRemoteObject();
1713     if (object == nullptr) {
1714         APP_LOGE("read IRemoteObject failed");
1715         return ERR_APPEXECFWK_PARCEL_ERROR;
1716     }
1717     sptr<IBundleEventCallback> bundleEventCallback = iface_cast<IBundleEventCallback>(object);
1718     if (bundleEventCallback == nullptr) {
1719         APP_LOGE("Get bundleEventCallback failed");
1720         return ERR_APPEXECFWK_PARCEL_ERROR;
1721     }
1722     bool ret = RegisterBundleEventCallback(bundleEventCallback);
1723     if (!reply.WriteBool(ret)) {
1724         APP_LOGE("write ret failed");
1725         return ERR_APPEXECFWK_PARCEL_ERROR;
1726     }
1727     return ERR_OK;
1728 }
1729 
HandleUnregisterBundleEventCallback(MessageParcel & data,MessageParcel & reply)1730 ErrCode BundleMgrHost::HandleUnregisterBundleEventCallback(MessageParcel &data, MessageParcel &reply)
1731 {
1732     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1733     sptr<IRemoteObject> object = data.ReadRemoteObject();
1734     if (object == nullptr) {
1735         APP_LOGE("read IRemoteObject failed");
1736         return ERR_APPEXECFWK_PARCEL_ERROR;
1737     }
1738     sptr<IBundleEventCallback> bundleEventCallback = iface_cast<IBundleEventCallback>(object);
1739 
1740     bool ret = UnregisterBundleEventCallback(bundleEventCallback);
1741     if (!reply.WriteBool(ret)) {
1742         APP_LOGE("write ret failed");
1743         return ERR_APPEXECFWK_PARCEL_ERROR;
1744     }
1745     return ERR_OK;
1746 }
1747 
HandleClearBundleStatusCallback(MessageParcel & data,MessageParcel & reply)1748 ErrCode BundleMgrHost::HandleClearBundleStatusCallback(MessageParcel &data, MessageParcel &reply)
1749 {
1750     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1751     sptr<IRemoteObject> object = data.ReadRemoteObject();
1752     if (object == nullptr) {
1753         APP_LOGE("read failed");
1754         return ERR_APPEXECFWK_PARCEL_ERROR;
1755     }
1756     sptr<IBundleStatusCallback> BundleStatusCallback = iface_cast<IBundleStatusCallback>(object);
1757 
1758     bool ret = ClearBundleStatusCallback(BundleStatusCallback);
1759     if (!reply.WriteBool(ret)) {
1760         APP_LOGE("write failed");
1761         return ERR_APPEXECFWK_PARCEL_ERROR;
1762     }
1763     return ERR_OK;
1764 }
1765 
HandleUnregisterBundleStatusCallback(MessageParcel & data,MessageParcel & reply)1766 ErrCode BundleMgrHost::HandleUnregisterBundleStatusCallback(MessageParcel &data, MessageParcel &reply)
1767 {
1768     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1769     bool ret = UnregisterBundleStatusCallback();
1770     if (!reply.WriteBool(ret)) {
1771         APP_LOGE("write failed");
1772         return ERR_APPEXECFWK_PARCEL_ERROR;
1773     }
1774     return ERR_OK;
1775 }
1776 
HandleCompileProcessAOT(MessageParcel & data,MessageParcel & reply)1777 ErrCode BundleMgrHost::HandleCompileProcessAOT(MessageParcel &data, MessageParcel &reply)
1778 {
1779     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1780     std::string bundleName = data.ReadString();
1781     std::string compileMode = data.ReadString();
1782     bool isAllBundle = data.ReadBool();
1783     std::vector<std::string> compileResults;
1784 
1785     APP_LOGI("compile info %{public}s", bundleName.c_str());
1786     ErrCode ret = CompileProcessAOT(bundleName, compileMode, isAllBundle, compileResults);
1787     APP_LOGI("ret %{public}d", ret);
1788     if (!reply.WriteInt32(ret)) {
1789         APP_LOGE("write failed");
1790         return ERR_APPEXECFWK_PARCEL_ERROR;
1791     }
1792     if (ret != ERR_OK) {
1793         if (!reply.WriteStringVector(compileResults)) {
1794             APP_LOGE("write compile process AOT results failed");
1795             return ERR_APPEXECFWK_PARCEL_ERROR;
1796         }
1797     }
1798     return ERR_OK;
1799 }
1800 
HandleCompileReset(MessageParcel & data,MessageParcel & reply)1801 ErrCode BundleMgrHost::HandleCompileReset(MessageParcel &data, MessageParcel &reply)
1802 {
1803     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1804     std::string bundleName = data.ReadString();
1805     bool isAllBundle = data.ReadBool();
1806 
1807     APP_LOGI("reset info %{public}s", bundleName.c_str());
1808     ErrCode ret = CompileReset(bundleName, isAllBundle);
1809     APP_LOGI("ret %{public}d", ret);
1810     if (!reply.WriteInt32(ret)) {
1811         APP_LOGE("write failed");
1812         return ERR_APPEXECFWK_PARCEL_ERROR;
1813     }
1814     return ERR_OK;
1815 }
1816 
HandleCopyAp(MessageParcel & data,MessageParcel & reply)1817 ErrCode BundleMgrHost::HandleCopyAp(MessageParcel &data, MessageParcel &reply)
1818 {
1819     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1820     std::string bundleName = data.ReadString();
1821     bool isAllBundle = data.ReadBool();
1822     std::vector<std::string> results;
1823     ErrCode ret = CopyAp(bundleName, isAllBundle, results);
1824     APP_LOGI("ret %{public}d", ret);
1825     if (!reply.WriteInt32(ret)) {
1826         APP_LOGE("HandleCopyAp write failed");
1827         return ERR_APPEXECFWK_PARCEL_ERROR;
1828     }
1829     if (ret == ERR_OK && !reply.WriteStringVector(results)) {
1830         APP_LOGE("write HandleCopyAp results failed");
1831         return ERR_APPEXECFWK_PARCEL_ERROR;
1832     }
1833     return ERR_OK;
1834 }
1835 
HandleDumpInfos(MessageParcel & data,MessageParcel & reply)1836 ErrCode BundleMgrHost::HandleDumpInfos(MessageParcel &data, MessageParcel &reply)
1837 {
1838     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1839     DumpFlag flag = static_cast<DumpFlag>(data.ReadInt32());
1840     std::string bundleName = data.ReadString();
1841     int32_t userId = data.ReadInt32();
1842 
1843     std::string result;
1844     APP_LOGI("dump info %{public}s", bundleName.c_str());
1845     bool ret = DumpInfos(flag, bundleName, userId, result);
1846     (void)reply.SetMaxCapacity(MAX_PARCEL_CAPACITY);
1847     if (!reply.WriteBool(ret)) {
1848         APP_LOGE("write failed");
1849         return ERR_APPEXECFWK_PARCEL_ERROR;
1850     }
1851     if (ret) {
1852         std::vector<std::string> dumpInfos;
1853         SplitString(result, dumpInfos);
1854         if (!reply.WriteStringVector(dumpInfos)) {
1855             return ERR_APPEXECFWK_PARCEL_ERROR;
1856         }
1857     }
1858     return ERR_OK;
1859 }
1860 
HandleIsApplicationEnabled(MessageParcel & data,MessageParcel & reply)1861 ErrCode BundleMgrHost::HandleIsApplicationEnabled(MessageParcel &data, MessageParcel &reply)
1862 {
1863     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1864     std::string bundleName = data.ReadString();
1865     if (bundleName.empty()) {
1866         APP_LOGE("fail to IsApplicationEnabled due to params empty");
1867         return ERR_BUNDLE_MANAGER_PARAM_ERROR;
1868     }
1869     bool isEnable = false;
1870     ErrCode ret = IsApplicationEnabled(bundleName, isEnable);
1871     if (!reply.WriteInt32(ret)) {
1872         APP_LOGE("WriteInt32 failed");
1873         return ERR_APPEXECFWK_PARCEL_ERROR;
1874     }
1875     if (!reply.WriteBool(isEnable)) {
1876         APP_LOGE("WriteBool failed");
1877         return ERR_APPEXECFWK_PARCEL_ERROR;
1878     }
1879     return ERR_OK;
1880 }
1881 
HandleIsCloneApplicationEnabled(MessageParcel & data,MessageParcel & reply)1882 ErrCode BundleMgrHost::HandleIsCloneApplicationEnabled(MessageParcel &data, MessageParcel &reply)
1883 {
1884     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1885     std::string bundleName = data.ReadString();
1886     if (bundleName.empty()) {
1887         APP_LOGE("fail to HandleIsCloneApplicationEnabled due to params empty");
1888         return ERR_BUNDLE_MANAGER_PARAM_ERROR;
1889     }
1890     int32_t appIndex = data.ReadInt32();
1891     bool isEnable = false;
1892     ErrCode ret = IsCloneApplicationEnabled(bundleName, appIndex, isEnable);
1893     if (!reply.WriteInt32(ret)) {
1894         return ERR_APPEXECFWK_PARCEL_ERROR;
1895     }
1896     if ((ret == ERR_OK) && !reply.WriteBool(isEnable)) {
1897         return ERR_APPEXECFWK_PARCEL_ERROR;
1898     }
1899     return ERR_OK;
1900 }
1901 
HandleSetApplicationEnabled(MessageParcel & data,MessageParcel & reply)1902 ErrCode BundleMgrHost::HandleSetApplicationEnabled(MessageParcel &data, MessageParcel &reply)
1903 {
1904     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1905     std::string bundleName = data.ReadString();
1906     if (bundleName.empty()) {
1907         APP_LOGE("fail to SetApplicationEnabled due to params empty");
1908         return ERR_BUNDLE_MANAGER_PARAM_ERROR;
1909     }
1910     bool isEnable = data.ReadBool();
1911     int32_t userId = data.ReadInt32();
1912     ErrCode ret = SetApplicationEnabled(bundleName, isEnable, userId);
1913     if (!reply.WriteInt32(ret)) {
1914         APP_LOGE("WriteInt32 failed");
1915         return ERR_APPEXECFWK_PARCEL_ERROR;
1916     }
1917     return ERR_OK;
1918 }
1919 
HandleSetCloneApplicationEnabled(MessageParcel & data,MessageParcel & reply)1920 ErrCode BundleMgrHost::HandleSetCloneApplicationEnabled(MessageParcel &data, MessageParcel &reply)
1921 {
1922     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1923     std::string bundleName = data.ReadString();
1924     if (bundleName.empty()) {
1925         APP_LOGE("fail to SetCloneApplicationEnabled due to params empty");
1926         return ERR_BUNDLE_MANAGER_PARAM_ERROR;
1927     }
1928     int32_t appIndex = data.ReadInt32();
1929     bool isEnable = data.ReadBool();
1930     int32_t userId = data.ReadInt32();
1931     ErrCode ret = SetCloneApplicationEnabled(bundleName, appIndex, isEnable, userId);
1932     if (!reply.WriteInt32(ret)) {
1933         return ERR_APPEXECFWK_PARCEL_ERROR;
1934     }
1935     return ERR_OK;
1936 }
1937 
HandleIsAbilityEnabled(MessageParcel & data,MessageParcel & reply)1938 ErrCode BundleMgrHost::HandleIsAbilityEnabled(MessageParcel &data, MessageParcel &reply)
1939 {
1940     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1941     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
1942     if (abilityInfo == nullptr) {
1943         APP_LOGE("ReadParcelable<abilityInfo> failed");
1944         return ERR_APPEXECFWK_PARCEL_ERROR;
1945     }
1946     bool isEnable = false;
1947     ErrCode ret = IsAbilityEnabled(*abilityInfo, isEnable);
1948     if (!reply.WriteInt32(ret)) {
1949         APP_LOGE("WriteInt32 failed");
1950         return ERR_APPEXECFWK_PARCEL_ERROR;
1951     }
1952     if (!reply.WriteBool(isEnable)) {
1953         APP_LOGE("WriteBool failed");
1954         return ERR_APPEXECFWK_PARCEL_ERROR;
1955     }
1956     return ERR_OK;
1957 }
1958 
HandleIsCloneAbilityEnabled(MessageParcel & data,MessageParcel & reply)1959 ErrCode BundleMgrHost::HandleIsCloneAbilityEnabled(MessageParcel &data, MessageParcel &reply)
1960 {
1961     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1962     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
1963     if (abilityInfo == nullptr) {
1964         APP_LOGE("ReadParcelable<abilityInfo> failed");
1965         return ERR_APPEXECFWK_PARCEL_ERROR;
1966     }
1967     int32_t appIndex = data.ReadInt32();
1968     bool isEnable = false;
1969     ErrCode ret = IsCloneAbilityEnabled(*abilityInfo, appIndex, isEnable);
1970     if (!reply.WriteInt32(ret)) {
1971         return ERR_APPEXECFWK_PARCEL_ERROR;
1972     }
1973     if ((ret == ERR_OK) && !reply.WriteBool(isEnable)) {
1974         return ERR_APPEXECFWK_PARCEL_ERROR;
1975     }
1976     return ERR_OK;
1977 }
1978 
HandleSetAbilityEnabled(MessageParcel & data,MessageParcel & reply)1979 ErrCode BundleMgrHost::HandleSetAbilityEnabled(MessageParcel &data, MessageParcel &reply)
1980 {
1981     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1982     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
1983     if (abilityInfo == nullptr) {
1984         APP_LOGE("ReadParcelable<abilityInfo> failed");
1985         return ERR_APPEXECFWK_PARCEL_ERROR;
1986     }
1987     bool isEnabled = data.ReadBool();
1988     int32_t userId = data.ReadInt32();
1989     ErrCode ret = SetAbilityEnabled(*abilityInfo, isEnabled, userId);
1990     if (!reply.WriteInt32(ret)) {
1991         APP_LOGE("WriteInt32 failed");
1992         return ERR_APPEXECFWK_PARCEL_ERROR;
1993     }
1994     return ERR_OK;
1995 }
1996 
HandleSetCloneAbilityEnabled(MessageParcel & data,MessageParcel & reply)1997 ErrCode BundleMgrHost::HandleSetCloneAbilityEnabled(MessageParcel &data, MessageParcel &reply)
1998 {
1999     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2000     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
2001     if (abilityInfo == nullptr) {
2002         APP_LOGE("ReadParcelable<abilityInfo> failed");
2003         return ERR_APPEXECFWK_PARCEL_ERROR;
2004     }
2005     int32_t appIndex = data.ReadInt32();
2006     bool isEnabled = data.ReadBool();
2007     int32_t userId = data.ReadInt32();
2008     ErrCode ret = SetCloneAbilityEnabled(*abilityInfo, appIndex, isEnabled, userId);
2009     if (!reply.WriteInt32(ret)) {
2010         return ERR_APPEXECFWK_PARCEL_ERROR;
2011     }
2012     return ERR_OK;
2013 }
2014 
HandleGetAbilityInfo(MessageParcel & data,MessageParcel & reply)2015 ErrCode BundleMgrHost::HandleGetAbilityInfo(MessageParcel &data, MessageParcel &reply)
2016 {
2017     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2018     AbilityInfo info;
2019     std::string bundleName = data.ReadString();
2020     std::string abilityName = data.ReadString();
2021     bool ret = GetAbilityInfo(bundleName, abilityName, info);
2022     if (!reply.WriteBool(ret)) {
2023         APP_LOGE("write failed");
2024         return ERR_APPEXECFWK_PARCEL_ERROR;
2025     }
2026     if (ret) {
2027         if (!reply.WriteParcelable(&info)) {
2028             APP_LOGE("write failed");
2029             return ERR_APPEXECFWK_PARCEL_ERROR;
2030         }
2031     }
2032     return ERR_OK;
2033 }
2034 
HandleGetAbilityInfoWithModuleName(MessageParcel & data,MessageParcel & reply)2035 ErrCode BundleMgrHost::HandleGetAbilityInfoWithModuleName(MessageParcel &data, MessageParcel &reply)
2036 {
2037     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2038     AbilityInfo info;
2039     std::string bundleName = data.ReadString();
2040     std::string moduleName = data.ReadString();
2041     std::string abilityName = data.ReadString();
2042     bool ret = GetAbilityInfo(bundleName, moduleName, abilityName, info);
2043     if (!reply.WriteBool(ret)) {
2044         APP_LOGE("write failed");
2045         return ERR_APPEXECFWK_PARCEL_ERROR;
2046     }
2047     if (ret) {
2048         if (!reply.WriteParcelable(&info)) {
2049             APP_LOGE("write failed");
2050             return ERR_APPEXECFWK_PARCEL_ERROR;
2051         }
2052     }
2053     return ERR_OK;
2054 }
2055 
HandleGetBundleInstaller(MessageParcel & data,MessageParcel & reply)2056 ErrCode BundleMgrHost::HandleGetBundleInstaller(MessageParcel &data, MessageParcel &reply)
2057 {
2058     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2059     sptr<IBundleInstaller> installer = GetBundleInstaller();
2060     if (installer == nullptr) {
2061         APP_LOGE("bundle installer is nullptr");
2062         return ERR_APPEXECFWK_INSTALL_HOST_INSTALLER_FAILED;
2063     }
2064 
2065     if (!reply.WriteRemoteObject(installer->AsObject())) {
2066         APP_LOGE("failed to reply bundle installer to client, for write MessageParcel error");
2067         return ERR_APPEXECFWK_PARCEL_ERROR;
2068     }
2069     return ERR_OK;
2070 }
2071 
HandleGetBundleUserMgr(MessageParcel & data,MessageParcel & reply)2072 ErrCode BundleMgrHost::HandleGetBundleUserMgr(MessageParcel &data, MessageParcel &reply)
2073 {
2074     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2075     sptr<IBundleUserMgr> bundleUserMgr = GetBundleUserMgr();
2076     if (bundleUserMgr == nullptr) {
2077         APP_LOGE("bundle installer is nullptr");
2078         return ERR_APPEXECFWK_INSTALL_HOST_INSTALLER_FAILED;
2079     }
2080 
2081     if (!reply.WriteRemoteObject(bundleUserMgr->AsObject())) {
2082         APP_LOGE("failed to reply bundle installer to client, for write MessageParcel error");
2083         return ERR_APPEXECFWK_PARCEL_ERROR;
2084     }
2085     return ERR_OK;
2086 }
2087 
HandleGetVerifyManager(MessageParcel & data,MessageParcel & reply)2088 ErrCode BundleMgrHost::HandleGetVerifyManager(MessageParcel &data, MessageParcel &reply)
2089 {
2090     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2091     sptr<IVerifyManager> verifyManager = GetVerifyManager();
2092     if (verifyManager == nullptr) {
2093         APP_LOGE("verifyManager is nullptr");
2094         return ERR_BUNDLE_MANAGER_VERIFY_GET_VERIFY_MGR_FAILED;
2095     }
2096 
2097     if (!reply.WriteRemoteObject(verifyManager->AsObject())) {
2098         APP_LOGE("failed to reply bundle installer to client, for write MessageParcel error");
2099         return ERR_APPEXECFWK_PARCEL_ERROR;
2100     }
2101     return ERR_OK;
2102 }
2103 
HandleGetExtendResourceManager(MessageParcel & data,MessageParcel & reply)2104 ErrCode BundleMgrHost::HandleGetExtendResourceManager(MessageParcel &data, MessageParcel &reply)
2105 {
2106     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2107     sptr<IExtendResourceManager> extendResourceManager = GetExtendResourceManager();
2108     if (extendResourceManager == nullptr) {
2109         APP_LOGE("extendResourceManager is nullptr");
2110         return ERR_EXT_RESOURCE_MANAGER_GET_EXT_RESOURCE_MGR_FAILED;
2111     }
2112 
2113     if (!reply.WriteRemoteObject(extendResourceManager->AsObject())) {
2114         APP_LOGE("failed to reply extendResourceManager, for write MessageParcel error");
2115         return ERR_APPEXECFWK_PARCEL_ERROR;
2116     }
2117     return ERR_OK;
2118 }
2119 
HandleGetAllFormsInfo(MessageParcel & data,MessageParcel & reply)2120 ErrCode BundleMgrHost::HandleGetAllFormsInfo(MessageParcel &data, MessageParcel &reply)
2121 {
2122     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2123     std::vector<FormInfo> infos;
2124     bool ret = GetAllFormsInfo(infos);
2125     if (!reply.WriteBool(ret)) {
2126         APP_LOGE("write failed");
2127         return ERR_APPEXECFWK_PARCEL_ERROR;
2128     }
2129 
2130     if (ret) {
2131         if (!WriteParcelableVector(infos, reply)) {
2132             APP_LOGE("write failed");
2133             return ERR_APPEXECFWK_PARCEL_ERROR;
2134         }
2135     }
2136     return ERR_OK;
2137 }
2138 
HandleGetFormsInfoByApp(MessageParcel & data,MessageParcel & reply)2139 ErrCode BundleMgrHost::HandleGetFormsInfoByApp(MessageParcel &data, MessageParcel &reply)
2140 {
2141     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2142     std::string bundlename = data.ReadString();
2143     std::vector<FormInfo> infos;
2144     bool ret = GetFormsInfoByApp(bundlename, infos);
2145     if (!reply.WriteBool(ret)) {
2146         APP_LOGE("write failed");
2147         return ERR_APPEXECFWK_PARCEL_ERROR;
2148     }
2149 
2150     if (ret) {
2151         if (!WriteParcelableVector(infos, reply)) {
2152             APP_LOGE("write failed");
2153             return ERR_APPEXECFWK_PARCEL_ERROR;
2154         }
2155     }
2156     return ERR_OK;
2157 }
2158 
HandleGetFormsInfoByModule(MessageParcel & data,MessageParcel & reply)2159 ErrCode BundleMgrHost::HandleGetFormsInfoByModule(MessageParcel &data, MessageParcel &reply)
2160 {
2161     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2162     std::string bundlename = data.ReadString();
2163     std::string modulename = data.ReadString();
2164     std::vector<FormInfo> infos;
2165     bool ret = GetFormsInfoByModule(bundlename, modulename, infos);
2166     if (!reply.WriteBool(ret)) {
2167         APP_LOGE("write failed");
2168         return ERR_APPEXECFWK_PARCEL_ERROR;
2169     }
2170 
2171     if (ret) {
2172         if (!WriteParcelableVector(infos, reply)) {
2173             APP_LOGE("write failed");
2174             return ERR_APPEXECFWK_PARCEL_ERROR;
2175         }
2176     }
2177     return ERR_OK;
2178 }
2179 
HandleGetShortcutInfos(MessageParcel & data,MessageParcel & reply)2180 ErrCode BundleMgrHost::HandleGetShortcutInfos(MessageParcel &data, MessageParcel &reply)
2181 {
2182     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2183     std::string bundlename = data.ReadString();
2184     std::vector<ShortcutInfo> infos;
2185     bool ret = GetShortcutInfos(bundlename, infos);
2186     if (!reply.WriteBool(ret)) {
2187         APP_LOGE("write failed");
2188         return ERR_APPEXECFWK_PARCEL_ERROR;
2189     }
2190 
2191     if (ret) {
2192         if (!WriteParcelableVector(infos, reply)) {
2193             APP_LOGE("write failed");
2194             return ERR_APPEXECFWK_PARCEL_ERROR;
2195         }
2196     }
2197     return ERR_OK;
2198 }
2199 
HandleGetShortcutInfoV9(MessageParcel & data,MessageParcel & reply)2200 ErrCode BundleMgrHost::HandleGetShortcutInfoV9(MessageParcel &data, MessageParcel &reply)
2201 {
2202     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2203     std::string bundlename = data.ReadString();
2204     int32_t userId = data.ReadInt32();
2205     std::vector<ShortcutInfo> infos;
2206     ErrCode ret = GetShortcutInfoV9(bundlename, infos, userId);
2207     if (!reply.WriteInt32(ret)) {
2208         APP_LOGE("write result failed");
2209         return ERR_APPEXECFWK_PARCEL_ERROR;
2210     }
2211     if (ret == ERR_OK && !WriteParcelableVector(infos, reply)) {
2212         APP_LOGE("write shortcut infos failed");
2213         return ERR_APPEXECFWK_PARCEL_ERROR;
2214     }
2215     return ERR_OK;
2216 }
2217 
HandleGetAllCommonEventInfo(MessageParcel & data,MessageParcel & reply)2218 ErrCode BundleMgrHost::HandleGetAllCommonEventInfo(MessageParcel &data, MessageParcel &reply)
2219 {
2220     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2221     std::string eventKey = data.ReadString();
2222     std::vector<CommonEventInfo> infos;
2223     bool ret = GetAllCommonEventInfo(eventKey, infos);
2224     if (!reply.WriteBool(ret)) {
2225         APP_LOGE("write failed");
2226         return ERR_APPEXECFWK_PARCEL_ERROR;
2227     }
2228 
2229     if (ret) {
2230         if (!WriteParcelableVector(infos, reply)) {
2231             APP_LOGE("write failed");
2232             return ERR_APPEXECFWK_PARCEL_ERROR;
2233         }
2234     }
2235     return ERR_OK;
2236 }
2237 
HandleGetDistributedBundleInfo(MessageParcel & data,MessageParcel & reply)2238 ErrCode BundleMgrHost::HandleGetDistributedBundleInfo(MessageParcel &data, MessageParcel &reply)
2239 {
2240     std::string networkId = data.ReadString();
2241     std::string bundleName = data.ReadString();
2242     if (networkId.empty() || bundleName.empty()) {
2243         APP_LOGE("networkId or bundleName is invalid");
2244         return ERR_INVALID_VALUE;
2245     }
2246     DistributedBundleInfo distributedBundleInfo;
2247     bool ret = GetDistributedBundleInfo(networkId, bundleName, distributedBundleInfo);
2248     if (!reply.WriteBool(ret)) {
2249         APP_LOGE("write failed");
2250         return ERR_APPEXECFWK_PARCEL_ERROR;
2251     }
2252     if (ret) {
2253         if (!reply.WriteParcelable(&distributedBundleInfo)) {
2254             APP_LOGE("write failed");
2255             return ERR_APPEXECFWK_PARCEL_ERROR;
2256         }
2257     }
2258     return ERR_OK;
2259 }
2260 
HandleGetAppPrivilegeLevel(MessageParcel & data,MessageParcel & reply)2261 ErrCode BundleMgrHost::HandleGetAppPrivilegeLevel(MessageParcel &data, MessageParcel &reply)
2262 {
2263     std::string bundleName = data.ReadString();
2264     int32_t userId = data.ReadInt32();
2265     auto ret = GetAppPrivilegeLevel(bundleName, userId);
2266     if (!reply.WriteString(ret)) {
2267         APP_LOGE("write failed");
2268         return ERR_APPEXECFWK_PARCEL_ERROR;
2269     }
2270     return ERR_OK;
2271 }
2272 
HandleQueryExtAbilityInfosWithoutType(MessageParcel & data,MessageParcel & reply)2273 ErrCode BundleMgrHost::HandleQueryExtAbilityInfosWithoutType(MessageParcel &data, MessageParcel &reply)
2274 {
2275     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2276     if (!want) {
2277         APP_LOGE("ReadParcelable<want> failed");
2278         return ERR_APPEXECFWK_PARCEL_ERROR;
2279     }
2280 
2281     int32_t flag = data.ReadInt32();
2282     int32_t userId = data.ReadInt32();
2283     std::vector<ExtensionAbilityInfo> infos;
2284     bool ret = QueryExtensionAbilityInfos(*want, flag, userId, infos);
2285     if (!reply.WriteBool(ret)) {
2286         APP_LOGE("write result failed");
2287         return ERR_APPEXECFWK_PARCEL_ERROR;
2288     }
2289     if (ret && !WriteParcelableVector(infos, reply)) {
2290         APP_LOGE("write extension infos failed");
2291 
2292         return ERR_APPEXECFWK_PARCEL_ERROR;
2293     }
2294     return ERR_OK;
2295 }
2296 
HandleQueryExtAbilityInfosWithoutTypeV9(MessageParcel & data,MessageParcel & reply)2297 ErrCode BundleMgrHost::HandleQueryExtAbilityInfosWithoutTypeV9(MessageParcel &data, MessageParcel &reply)
2298 {
2299     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2300     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2301     if (!want) {
2302         APP_LOGE("ReadParcelable<want> failed");
2303         return ERR_APPEXECFWK_PARCEL_ERROR;
2304     }
2305 
2306     int32_t flags = data.ReadInt32();
2307     int32_t userId = data.ReadInt32();
2308     std::vector<ExtensionAbilityInfo> infos;
2309     ErrCode ret = QueryExtensionAbilityInfosV9(*want, flags, userId, infos);
2310     if (!reply.WriteInt32(ret)) {
2311         APP_LOGE("write result failed");
2312         return ERR_APPEXECFWK_PARCEL_ERROR;
2313     }
2314     if (ret == ERR_OK && !WriteParcelableVector(infos, reply)) {
2315         APP_LOGE("write extension infos failed");
2316         return ERR_APPEXECFWK_PARCEL_ERROR;
2317     }
2318     return ERR_OK;
2319 }
2320 
HandleQueryExtAbilityInfos(MessageParcel & data,MessageParcel & reply)2321 ErrCode BundleMgrHost::HandleQueryExtAbilityInfos(MessageParcel &data, MessageParcel &reply)
2322 {
2323     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2324     if (want == nullptr) {
2325         APP_LOGE("ReadParcelable<want> failed");
2326         return ERR_APPEXECFWK_PARCEL_ERROR;
2327     }
2328 
2329     ExtensionAbilityType type = static_cast<ExtensionAbilityType>(data.ReadInt32());
2330     int32_t flag = data.ReadInt32();
2331     int32_t userId = data.ReadInt32();
2332     std::vector<ExtensionAbilityInfo> infos;
2333     bool ret = QueryExtensionAbilityInfos(*want, type, flag, userId, infos);
2334     if (!reply.WriteBool(ret)) {
2335         APP_LOGE("write result failed");
2336         return ERR_APPEXECFWK_PARCEL_ERROR;
2337     }
2338     if (ret && !WriteParcelableVector(infos, reply)) {
2339         APP_LOGE("write extension infos failed");
2340         return ERR_APPEXECFWK_PARCEL_ERROR;
2341     }
2342     return ERR_OK;
2343 }
2344 
HandleQueryExtAbilityInfosV9(MessageParcel & data,MessageParcel & reply)2345 ErrCode BundleMgrHost::HandleQueryExtAbilityInfosV9(MessageParcel &data, MessageParcel &reply)
2346 {
2347     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2348     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2349     if (want == nullptr) {
2350         APP_LOGE("ReadParcelable<want> failed");
2351         return ERR_APPEXECFWK_PARCEL_ERROR;
2352     }
2353 
2354     ExtensionAbilityType type = static_cast<ExtensionAbilityType>(data.ReadInt32());
2355     int32_t flags = data.ReadInt32();
2356     int32_t userId = data.ReadInt32();
2357     std::vector<ExtensionAbilityInfo> infos;
2358     ErrCode ret = QueryExtensionAbilityInfosV9(*want, type, flags, userId, infos);
2359     if (!reply.WriteInt32(ret)) {
2360         APP_LOGE("write result failed");
2361         return ERR_APPEXECFWK_PARCEL_ERROR;
2362     }
2363     if (ret == ERR_OK && !WriteParcelableVector(infos, reply)) {
2364         APP_LOGE("write extension infos failed");
2365         return ERR_APPEXECFWK_PARCEL_ERROR;
2366     }
2367     return ERR_OK;
2368 }
2369 
HandleQueryExtAbilityInfosByType(MessageParcel & data,MessageParcel & reply)2370 ErrCode BundleMgrHost::HandleQueryExtAbilityInfosByType(MessageParcel &data, MessageParcel &reply)
2371 {
2372     ExtensionAbilityType type = static_cast<ExtensionAbilityType>(data.ReadInt32());
2373     int32_t userId = data.ReadInt32();
2374     std::vector<ExtensionAbilityInfo> infos;
2375 
2376     bool ret = QueryExtensionAbilityInfos(type, userId, infos);
2377     if (!reply.WriteBool(ret)) {
2378         APP_LOGE("write result failed");
2379         return ERR_APPEXECFWK_PARCEL_ERROR;
2380     }
2381     if (ret && !WriteParcelableVector(infos, reply)) {
2382         APP_LOGE("write extension infos failed");
2383         return ERR_APPEXECFWK_PARCEL_ERROR;
2384     }
2385     return ERR_OK;
2386 }
2387 
HandleVerifyCallingPermission(MessageParcel & data,MessageParcel & reply)2388 ErrCode BundleMgrHost::HandleVerifyCallingPermission(MessageParcel &data, MessageParcel &reply)
2389 {
2390     std::string permission = data.ReadString();
2391 
2392     bool ret = VerifyCallingPermission(permission);
2393     if (!reply.WriteBool(ret)) {
2394         APP_LOGE("write result failed");
2395         return ERR_APPEXECFWK_PARCEL_ERROR;
2396     }
2397     return ERR_OK;
2398 }
2399 
HandleQueryExtensionAbilityInfoByUri(MessageParcel & data,MessageParcel & reply)2400 ErrCode BundleMgrHost::HandleQueryExtensionAbilityInfoByUri(MessageParcel &data, MessageParcel &reply)
2401 {
2402     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2403     std::string uri = data.ReadString();
2404     int32_t userId = data.ReadInt32();
2405     ExtensionAbilityInfo extensionAbilityInfo;
2406     bool ret = QueryExtensionAbilityInfoByUri(uri, userId, extensionAbilityInfo);
2407     if (!reply.WriteBool(ret)) {
2408         APP_LOGE("write failed");
2409         return ERR_APPEXECFWK_PARCEL_ERROR;
2410     }
2411     if (ret) {
2412         if (!reply.WriteParcelable(&extensionAbilityInfo)) {
2413             APP_LOGE("write failed");
2414             return ERR_APPEXECFWK_PARCEL_ERROR;
2415         }
2416     }
2417     return ERR_OK;
2418 }
2419 
HandleGetAppIdByBundleName(MessageParcel & data,MessageParcel & reply)2420 ErrCode BundleMgrHost::HandleGetAppIdByBundleName(MessageParcel &data, MessageParcel &reply)
2421 {
2422     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2423     std::string bundleName = data.ReadString();
2424     int32_t userId = data.ReadInt32();
2425     std::string appId = GetAppIdByBundleName(bundleName, userId);
2426     APP_LOGD("appId is %{private}s", appId.c_str());
2427     if (!reply.WriteString(appId)) {
2428         APP_LOGE("write failed");
2429         return ERR_APPEXECFWK_PARCEL_ERROR;
2430     }
2431     return ERR_OK;
2432 }
2433 
HandleGetAppType(MessageParcel & data,MessageParcel & reply)2434 ErrCode BundleMgrHost::HandleGetAppType(MessageParcel &data, MessageParcel &reply)
2435 {
2436     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2437     std::string bundleName = data.ReadString();
2438     std::string appType = GetAppType(bundleName);
2439     APP_LOGD("appType is %{public}s", appType.c_str());
2440     if (!reply.WriteString(appType)) {
2441         APP_LOGE("write failed");
2442         return ERR_APPEXECFWK_PARCEL_ERROR;
2443     }
2444     return ERR_OK;
2445 }
2446 
HandleGetUidByBundleName(MessageParcel & data,MessageParcel & reply)2447 ErrCode BundleMgrHost::HandleGetUidByBundleName(MessageParcel &data, MessageParcel &reply)
2448 {
2449     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2450     std::string bundleName = data.ReadString();
2451     int32_t userId = data.ReadInt32();
2452     int32_t appIndex = data.ReadInt32();
2453     int32_t uid = GetUidByBundleName(bundleName, userId, appIndex);
2454     APP_LOGD("uid is %{public}d", uid);
2455     if (!reply.WriteInt32(uid)) {
2456         APP_LOGE("write failed");
2457         return ERR_APPEXECFWK_PARCEL_ERROR;
2458     }
2459     return ERR_OK;
2460 }
2461 
HandleGetUidByDebugBundleName(MessageParcel & data,MessageParcel & reply)2462 ErrCode BundleMgrHost::HandleGetUidByDebugBundleName(MessageParcel &data, MessageParcel &reply)
2463 {
2464     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2465     std::string bundleName = data.ReadString();
2466     int32_t userId = data.ReadInt32();
2467     int32_t uid = GetUidByDebugBundleName(bundleName, userId);
2468     APP_LOGD("uid is %{public}d", uid);
2469     if (!reply.WriteInt32(uid)) {
2470         APP_LOGE("write failed");
2471         return ERR_APPEXECFWK_PARCEL_ERROR;
2472     }
2473     return ERR_OK;
2474 }
2475 
HandleIsModuleRemovable(MessageParcel & data,MessageParcel & reply)2476 ErrCode BundleMgrHost::HandleIsModuleRemovable(MessageParcel &data, MessageParcel &reply)
2477 {
2478     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2479     std::string bundleName = data.ReadString();
2480     std::string moduleName = data.ReadString();
2481 
2482     APP_LOGD("bundleName %{public}s, moduleName %{public}s", bundleName.c_str(), moduleName.c_str());
2483     bool isRemovable = false;
2484     ErrCode ret = IsModuleRemovable(bundleName, moduleName, isRemovable);
2485     if (!reply.WriteInt32(ret)) {
2486         APP_LOGE("write ret failed");
2487         return ERR_APPEXECFWK_PARCEL_ERROR;
2488     }
2489     if (!reply.WriteBool(isRemovable)) {
2490         APP_LOGE("write isRemovable failed");
2491         return ERR_APPEXECFWK_PARCEL_ERROR;
2492     }
2493     return ERR_OK;
2494 }
2495 
HandleSetModuleRemovable(MessageParcel & data,MessageParcel & reply)2496 ErrCode BundleMgrHost::HandleSetModuleRemovable(MessageParcel &data, MessageParcel &reply)
2497 {
2498     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2499     std::string bundleName = data.ReadString();
2500     std::string moduleName = data.ReadString();
2501     bool isEnable = data.ReadBool();
2502     APP_LOGD("bundleName %{public}s, moduleName %{public}s", bundleName.c_str(), moduleName.c_str());
2503     bool ret = SetModuleRemovable(bundleName, moduleName, isEnable);
2504     if (!reply.WriteBool(ret)) {
2505         APP_LOGE("write failed");
2506         return ERR_APPEXECFWK_PARCEL_ERROR;
2507     }
2508     return ERR_OK;
2509 }
2510 
HandleGetModuleUpgradeFlag(MessageParcel & data,MessageParcel & reply)2511 ErrCode BundleMgrHost::HandleGetModuleUpgradeFlag(MessageParcel &data, MessageParcel &reply)
2512 {
2513     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2514     std::string bundleName = data.ReadString();
2515     std::string moduleName = data.ReadString();
2516 
2517     APP_LOGD("bundleName %{public}s, moduleName %{public}s", bundleName.c_str(), moduleName.c_str());
2518     bool ret = GetModuleUpgradeFlag(bundleName, moduleName);
2519     if (!reply.WriteBool(ret)) {
2520         APP_LOGE("write failed");
2521         return ERR_APPEXECFWK_PARCEL_ERROR;
2522     }
2523     return ERR_OK;
2524 }
2525 
HandleSetModuleUpgradeFlag(MessageParcel & data,MessageParcel & reply)2526 ErrCode BundleMgrHost::HandleSetModuleUpgradeFlag(MessageParcel &data, MessageParcel &reply)
2527 {
2528     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2529     std::string bundleName = data.ReadString();
2530     std::string moduleName = data.ReadString();
2531     int32_t upgradeFlag = data.ReadInt32();
2532     APP_LOGD("bundleName %{public}s, moduleName %{public}s", bundleName.c_str(), moduleName.c_str());
2533     ErrCode ret = SetModuleUpgradeFlag(bundleName, moduleName, upgradeFlag);
2534     if (!reply.WriteInt32(ret)) {
2535         APP_LOGE("write failed");
2536         return ERR_APPEXECFWK_PARCEL_ERROR;
2537     }
2538     return ERR_OK;
2539 }
2540 
HandleImplicitQueryInfoByPriority(MessageParcel & data,MessageParcel & reply)2541 ErrCode BundleMgrHost::HandleImplicitQueryInfoByPriority(MessageParcel &data, MessageParcel &reply)
2542 {
2543     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2544     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2545     if (want == nullptr) {
2546         APP_LOGE("ReadParcelable<want> failed");
2547         return ERR_APPEXECFWK_PARCEL_ERROR;
2548     }
2549     int32_t flags = data.ReadInt32();
2550     int32_t userId = data.ReadInt32();
2551     AbilityInfo abilityInfo;
2552     ExtensionAbilityInfo extensionInfo;
2553     bool ret = ImplicitQueryInfoByPriority(*want, flags, userId, abilityInfo, extensionInfo);
2554     if (!reply.WriteBool(ret)) {
2555         APP_LOGE("write failed");
2556         return ERR_APPEXECFWK_PARCEL_ERROR;
2557     }
2558     if (ret) {
2559         if (!reply.WriteParcelable(&abilityInfo)) {
2560             APP_LOGE("write AbilityInfo failed");
2561             return ERR_APPEXECFWK_PARCEL_ERROR;
2562         }
2563         if (!reply.WriteParcelable(&extensionInfo)) {
2564             APP_LOGE("write ExtensionAbilityInfo failed");
2565             return ERR_APPEXECFWK_PARCEL_ERROR;
2566         }
2567     }
2568     return ERR_OK;
2569 }
2570 
HandleImplicitQueryInfos(MessageParcel & data,MessageParcel & reply)2571 ErrCode BundleMgrHost::HandleImplicitQueryInfos(MessageParcel &data, MessageParcel &reply)
2572 {
2573     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2574     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2575     if (want == nullptr) {
2576         APP_LOGE("ReadParcelable want failed");
2577         return ERR_APPEXECFWK_PARCEL_ERROR;
2578     }
2579     int32_t flags = data.ReadInt32();
2580     int32_t userId = data.ReadInt32();
2581     bool withDefault = data.ReadBool();
2582     bool findDefaultApp = false;
2583     std::vector<AbilityInfo> abilityInfos;
2584     std::vector<ExtensionAbilityInfo> extensionInfos;
2585     bool ret = ImplicitQueryInfos(*want, flags, userId, withDefault, abilityInfos, extensionInfos, findDefaultApp);
2586     if (!reply.WriteBool(ret)) {
2587         APP_LOGE("WriteBool ret failed");
2588         return ERR_APPEXECFWK_PARCEL_ERROR;
2589     }
2590     if (ret) {
2591         if (!WriteParcelableVector(abilityInfos, reply)) {
2592             APP_LOGE("WriteParcelableVector abilityInfos failed");
2593             return ERR_APPEXECFWK_PARCEL_ERROR;
2594         }
2595         if (!WriteParcelableVector(extensionInfos, reply)) {
2596             APP_LOGE("WriteParcelableVector extensionInfo failed");
2597             return ERR_APPEXECFWK_PARCEL_ERROR;
2598         }
2599         if (!reply.WriteBool(findDefaultApp)) {
2600             APP_LOGE("write findDefaultApp failed");
2601             return ERR_APPEXECFWK_PARCEL_ERROR;
2602         }
2603     }
2604     return ERR_OK;
2605 }
2606 
HandleGetAllDependentModuleNames(MessageParcel & data,MessageParcel & reply)2607 ErrCode BundleMgrHost::HandleGetAllDependentModuleNames(MessageParcel &data, MessageParcel &reply)
2608 {
2609     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2610     std::string bundleName = data.ReadString();
2611     std::string moduleName = data.ReadString();
2612     std::vector<std::string> dependentModuleNames;
2613     bool ret = GetAllDependentModuleNames(bundleName, moduleName, dependentModuleNames);
2614     if (!reply.WriteBool(ret)) {
2615         APP_LOGE("write result failed");
2616         return ERR_APPEXECFWK_PARCEL_ERROR;
2617     }
2618     if (ret && !reply.WriteStringVector(dependentModuleNames)) {
2619         APP_LOGE("write dependentModuleNames failed");
2620         return ERR_APPEXECFWK_PARCEL_ERROR;
2621     }
2622     return ERR_OK;
2623 }
2624 
HandleGetSandboxBundleInfo(MessageParcel & data,MessageParcel & reply)2625 ErrCode BundleMgrHost::HandleGetSandboxBundleInfo(MessageParcel &data, MessageParcel &reply)
2626 {
2627     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2628     std::string bundleName = data.ReadString();
2629     int32_t appIndex = data.ReadInt32();
2630     int32_t userId = data.ReadInt32();
2631 
2632     BundleInfo info;
2633     auto res = GetSandboxBundleInfo(bundleName, appIndex, userId, info);
2634     if (!reply.WriteInt32(res)) {
2635         APP_LOGE("WriteInt32 failed");
2636         return ERR_APPEXECFWK_SANDBOX_INSTALL_WRITE_PARCEL_ERROR;
2637     }
2638     if ((res == ERR_OK) && (!reply.WriteParcelable(&info))) {
2639         return ERR_APPEXECFWK_SANDBOX_INSTALL_WRITE_PARCEL_ERROR;
2640     }
2641     return ERR_OK;
2642 }
2643 
HandleObtainCallingBundleName(MessageParcel & data,MessageParcel & reply)2644 ErrCode BundleMgrHost::HandleObtainCallingBundleName(MessageParcel &data, MessageParcel &reply)
2645 {
2646     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2647     std::string bundleName = "";
2648     auto ret = ObtainCallingBundleName(bundleName);
2649     if (!reply.WriteBool(ret)) {
2650         APP_LOGE("write result failed");
2651         return ERR_APPEXECFWK_PARCEL_ERROR;
2652     }
2653     if (ret && !reply.WriteString(bundleName)) {
2654         APP_LOGE("write bundleName failed");
2655         return ERR_APPEXECFWK_PARCEL_ERROR;
2656     }
2657     return ERR_OK;
2658 }
2659 
HandleCheckAbilityEnableInstall(MessageParcel & data,MessageParcel & reply)2660 ErrCode BundleMgrHost::HandleCheckAbilityEnableInstall(MessageParcel &data, MessageParcel &reply)
2661 {
2662     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2663     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2664     if (want == nullptr) {
2665         APP_LOGE("ReadParcelable<want> failed");
2666         return ERR_APPEXECFWK_PARCEL_ERROR;
2667     }
2668     int32_t missionId = data.ReadInt32();
2669     int32_t userId = data.ReadInt32();
2670     sptr<IRemoteObject> object = data.ReadRemoteObject();
2671 
2672     auto ret = CheckAbilityEnableInstall(*want, missionId, userId, object);
2673     if (!reply.WriteBool(ret)) {
2674         APP_LOGE("write result failed");
2675         return ERR_APPEXECFWK_PARCEL_ERROR;
2676     }
2677 
2678     return ERR_OK;
2679 }
2680 
HandleGetStringById(MessageParcel & data,MessageParcel & reply)2681 ErrCode BundleMgrHost::HandleGetStringById(MessageParcel &data, MessageParcel &reply)
2682 {
2683     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2684     std::string bundleName = data.ReadString();
2685     std::string moduleName = data.ReadString();
2686     uint32_t resId = data.ReadUint32();
2687     int32_t userId = data.ReadInt32();
2688     std::string localeInfo = data.ReadString();
2689     APP_LOGD("GetStringById bundleName: %{public}s, moduleName: %{public}s, resId:%{public}d",
2690         bundleName.c_str(), moduleName.c_str(), resId);
2691     if (bundleName.empty() || moduleName.empty()) {
2692         APP_LOGW("fail to GetStringById due to params empty");
2693         return ERR_INVALID_VALUE;
2694     }
2695     std::string label = GetStringById(bundleName, moduleName, resId, userId, localeInfo);
2696     if (!reply.WriteString(label)) {
2697         APP_LOGE("write failed");
2698         return ERR_APPEXECFWK_PARCEL_ERROR;
2699     }
2700     return ERR_OK;
2701 }
2702 
HandleGetIconById(MessageParcel & data,MessageParcel & reply)2703 ErrCode BundleMgrHost::HandleGetIconById(MessageParcel &data, MessageParcel &reply)
2704 {
2705     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2706     std::string bundleName = data.ReadString();
2707     std::string moduleName = data.ReadString();
2708     uint32_t resId = data.ReadUint32();
2709     uint32_t density = data.ReadUint32();
2710     int32_t userId = data.ReadInt32();
2711     APP_LOGD("GetStringById bundleName: %{public}s, moduleName: %{public}s, resId:%{public}d, density:%{public}d",
2712         bundleName.c_str(), moduleName.c_str(), resId, density);
2713     if (bundleName.empty() || moduleName.empty()) {
2714         APP_LOGW("fail to GetStringById due to params empty");
2715         return ERR_INVALID_VALUE;
2716     }
2717     std::string label = GetIconById(bundleName, moduleName, resId, density, userId);
2718     if (!reply.WriteString(label)) {
2719         APP_LOGE("write failed");
2720         return ERR_APPEXECFWK_PARCEL_ERROR;
2721     }
2722     return ERR_OK;
2723 }
2724 
2725 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
HandleGetDefaultAppProxy(MessageParcel & data,MessageParcel & reply)2726 ErrCode BundleMgrHost::HandleGetDefaultAppProxy(MessageParcel &data, MessageParcel &reply)
2727 {
2728     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2729     sptr<IDefaultApp> defaultAppProxy = GetDefaultAppProxy();
2730     if (defaultAppProxy == nullptr) {
2731         APP_LOGE("defaultAppProxy is nullptr");
2732         return ERR_APPEXECFWK_PARCEL_ERROR;
2733     }
2734 
2735     if (!reply.WriteRemoteObject(defaultAppProxy->AsObject())) {
2736         APP_LOGE("WriteRemoteObject failed");
2737         return ERR_APPEXECFWK_PARCEL_ERROR;
2738     }
2739     return ERR_OK;
2740 }
2741 #endif
2742 
2743 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
HandleGetAppControlProxy(MessageParcel & data,MessageParcel & reply)2744 ErrCode BundleMgrHost::HandleGetAppControlProxy(MessageParcel &data, MessageParcel &reply)
2745 {
2746     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2747     sptr<IAppControlMgr> appControlProxy = GetAppControlProxy();
2748     if (appControlProxy == nullptr) {
2749         APP_LOGE("appControlProxy is nullptr");
2750         return ERR_APPEXECFWK_PARCEL_ERROR;
2751     }
2752 
2753     if (!reply.WriteRemoteObject(appControlProxy->AsObject())) {
2754         APP_LOGE("WriteRemoteObject failed");
2755         return ERR_APPEXECFWK_PARCEL_ERROR;
2756     }
2757     return ERR_OK;
2758 }
2759 #endif
2760 
HandleGetSandboxAbilityInfo(MessageParcel & data,MessageParcel & reply)2761 ErrCode BundleMgrHost::HandleGetSandboxAbilityInfo(MessageParcel &data, MessageParcel &reply)
2762 {
2763     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2764     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2765     if (want == nullptr) {
2766         APP_LOGE("ReadParcelable<want> failed");
2767         return ERR_APPEXECFWK_PARCEL_ERROR;
2768     }
2769 
2770     int32_t appIndex = data.ReadInt32();
2771     int32_t flag = data.ReadInt32();
2772     int32_t userId = data.ReadInt32();
2773     AbilityInfo info;
2774     auto res = GetSandboxAbilityInfo(*want, appIndex, flag, userId, info);
2775     if (!reply.WriteInt32(res)) {
2776         APP_LOGE("write result failed");
2777         return ERR_APPEXECFWK_PARCEL_ERROR;
2778     }
2779     if ((res == ERR_OK) && (!reply.WriteParcelable(&info))) {
2780         APP_LOGE("write ability info failed");
2781         return ERR_APPEXECFWK_PARCEL_ERROR;
2782     }
2783     return ERR_OK;
2784 }
2785 
HandleGetSandboxExtAbilityInfos(MessageParcel & data,MessageParcel & reply)2786 ErrCode BundleMgrHost::HandleGetSandboxExtAbilityInfos(MessageParcel &data, MessageParcel &reply)
2787 {
2788     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2789     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2790     if (!want) {
2791         APP_LOGE("ReadParcelable<want> failed");
2792         return ERR_APPEXECFWK_PARCEL_ERROR;
2793     }
2794 
2795     int32_t appIndex = data.ReadInt32();
2796     int32_t flag = data.ReadInt32();
2797     int32_t userId = data.ReadInt32();
2798     std::vector<ExtensionAbilityInfo> infos;
2799     auto res = GetSandboxExtAbilityInfos(*want, appIndex, flag, userId, infos);
2800     if (!reply.WriteInt32(res)) {
2801         APP_LOGE("write result failed");
2802         return ERR_APPEXECFWK_PARCEL_ERROR;
2803     }
2804     if ((res == ERR_OK) && (!WriteParcelableVector(infos, reply))) {
2805         APP_LOGE("write extension infos failed");
2806         return ERR_APPEXECFWK_PARCEL_ERROR;
2807     }
2808     return ERR_OK;
2809 }
2810 
HandleGetSandboxHapModuleInfo(MessageParcel & data,MessageParcel & reply)2811 ErrCode BundleMgrHost::HandleGetSandboxHapModuleInfo(MessageParcel &data, MessageParcel &reply)
2812 {
2813     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2814     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
2815     if (abilityInfo == nullptr) {
2816         APP_LOGE("ReadParcelable<abilityInfo> failed");
2817         return ERR_APPEXECFWK_PARCEL_ERROR;
2818     }
2819     int32_t appIndex = data.ReadInt32();
2820     int32_t userId = data.ReadInt32();
2821     HapModuleInfo info;
2822     auto res = GetSandboxHapModuleInfo(*abilityInfo, appIndex, userId, info);
2823     if (!reply.WriteInt32(res)) {
2824         APP_LOGE("write failed");
2825         return ERR_APPEXECFWK_PARCEL_ERROR;
2826     }
2827     if ((res == ERR_OK) && (!reply.WriteParcelable(&info))) {
2828         APP_LOGE("write hap module info failed");
2829         return ERR_APPEXECFWK_PARCEL_ERROR;
2830     }
2831     return ERR_OK;
2832 }
2833 
HandleGetQuickFixManagerProxy(MessageParcel & data,MessageParcel & reply)2834 ErrCode BundleMgrHost::HandleGetQuickFixManagerProxy(MessageParcel &data, MessageParcel &reply)
2835 {
2836     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2837     sptr<IQuickFixManager> quickFixManagerProxy = GetQuickFixManagerProxy();
2838     if (quickFixManagerProxy == nullptr) {
2839         APP_LOGE("quickFixManagerProxy is nullptr");
2840         return ERR_APPEXECFWK_PARCEL_ERROR;
2841     }
2842 
2843     if (!reply.WriteRemoteObject(quickFixManagerProxy->AsObject())) {
2844         APP_LOGE("WriteRemoteObject failed");
2845         return ERR_APPEXECFWK_PARCEL_ERROR;
2846     }
2847     return ERR_OK;
2848 }
2849 
HandleVerifySystemApi(MessageParcel & data,MessageParcel & reply)2850 ErrCode BundleMgrHost::HandleVerifySystemApi(MessageParcel &data, MessageParcel &reply)
2851 {
2852     int32_t beginApiVersion = data.ReadInt32();
2853 
2854     bool ret = VerifySystemApi(beginApiVersion);
2855     if (!reply.WriteBool(ret)) {
2856         APP_LOGE("write result failed");
2857         return ERR_APPEXECFWK_PARCEL_ERROR;
2858     }
2859     return ERR_OK;
2860 }
2861 
2862 template<typename T>
WriteParcelableVector(std::vector<T> & parcelableVector,MessageParcel & reply)2863 bool BundleMgrHost::WriteParcelableVector(std::vector<T> &parcelableVector, MessageParcel &reply)
2864 {
2865     if (!reply.WriteInt32(parcelableVector.size())) {
2866         APP_LOGE("write ParcelableVector failed");
2867         return false;
2868     }
2869 
2870     for (auto &parcelable : parcelableVector) {
2871         if (!reply.WriteParcelable(&parcelable)) {
2872             APP_LOGE("write ParcelableVector failed");
2873             return false;
2874         }
2875     }
2876     return true;
2877 }
2878 
2879 template<typename T>
WriteVectorToParcelIntelligent(std::vector<T> & parcelableVector,MessageParcel & reply)2880 bool BundleMgrHost::WriteVectorToParcelIntelligent(std::vector<T> &parcelableVector, MessageParcel &reply)
2881 {
2882     MessageParcel tempParcel;
2883     (void)tempParcel.SetMaxCapacity(MAX_PARCEL_CAPACITY);
2884     if (!tempParcel.WriteInt32(parcelableVector.size())) {
2885         APP_LOGE("write ParcelableVector failed");
2886         return false;
2887     }
2888 
2889     for (auto &parcelable : parcelableVector) {
2890         if (!tempParcel.WriteParcelable(&parcelable)) {
2891             APP_LOGE("write ParcelableVector failed");
2892             return false;
2893         }
2894     }
2895 
2896     size_t dataSize = tempParcel.GetDataSize();
2897     if (!reply.WriteInt32(static_cast<int32_t>(dataSize))) {
2898         APP_LOGE("write WriteInt32 failed");
2899         return false;
2900     }
2901 
2902     if (dataSize > MAX_IPC_REWDATA_SIZE) {
2903         (void)tempParcel.SetMaxCapacity(MAX_PARCEL_CAPACITY_OF_ASHMEM);
2904         int32_t callingUid = IPCSkeleton::GetCallingUid();
2905         APP_LOGI("datasize is too large, use ashmem %{public}d", callingUid);
2906         return WriteParcelableIntoAshmem(tempParcel, reply);
2907     }
2908 
2909     if (!reply.WriteRawData(
2910         reinterpret_cast<uint8_t *>(tempParcel.GetData()), dataSize)) {
2911         APP_LOGE("Failed to write data");
2912         return false;
2913     }
2914 
2915     return true;
2916 }
2917 
AllocatAshmemNum()2918 int32_t BundleMgrHost::AllocatAshmemNum()
2919 {
2920     std::lock_guard<std::mutex> lock(bundleAshmemMutex_);
2921     return ashmemNum_++;
2922 }
2923 
HandleQueryAbilityInfoWithCallback(MessageParcel & data,MessageParcel & reply)2924 ErrCode BundleMgrHost::HandleQueryAbilityInfoWithCallback(MessageParcel &data, MessageParcel &reply)
2925 {
2926     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2927     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2928     if (want == nullptr) {
2929         APP_LOGE("ReadParcelable<want> failed");
2930         return ERR_APPEXECFWK_PARCEL_ERROR;
2931     }
2932     int32_t flags = data.ReadInt32();
2933     int32_t userId = data.ReadInt32();
2934     sptr<IRemoteObject> object = data.ReadRemoteObject();
2935     AbilityInfo info;
2936     bool ret = QueryAbilityInfo(*want, flags, userId, info, object);
2937     if (!reply.WriteBool(ret)) {
2938         APP_LOGE("write ret failed");
2939         return ERR_APPEXECFWK_PARCEL_ERROR;
2940     }
2941     if (ret) {
2942         if (!reply.WriteParcelable(&info)) {
2943             APP_LOGE("write info failed");
2944             return ERR_APPEXECFWK_PARCEL_ERROR;
2945         }
2946     }
2947     return ERR_OK;
2948 }
2949 
HandleSilentInstall(MessageParcel & data,MessageParcel & reply)2950 ErrCode BundleMgrHost::HandleSilentInstall(MessageParcel &data, MessageParcel &reply)
2951 {
2952     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2953     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2954     if (want == nullptr) {
2955         APP_LOGE("ReadParcelable<want> failed");
2956         return ERR_APPEXECFWK_PARCEL_ERROR;
2957     }
2958     int32_t userId = data.ReadInt32();
2959     sptr<IRemoteObject> object = data.ReadRemoteObject();
2960     bool ret = SilentInstall(*want, userId, object);
2961     if (!reply.WriteBool(ret)) {
2962         APP_LOGE("write ret failed");
2963         return ERR_APPEXECFWK_PARCEL_ERROR;
2964     }
2965     return ERR_OK;
2966 }
2967 
HandleUpgradeAtomicService(MessageParcel & data,MessageParcel & reply)2968 ErrCode BundleMgrHost::HandleUpgradeAtomicService(MessageParcel &data, MessageParcel &reply)
2969 {
2970     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2971     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2972     if (want == nullptr) {
2973         APP_LOGE("read parcelable want failed");
2974         return ERR_APPEXECFWK_PARCEL_ERROR;
2975     }
2976     int32_t userId = data.ReadInt32();
2977     UpgradeAtomicService(*want, userId);
2978     return ERR_OK;
2979 }
2980 
HandleGetBundleStats(MessageParcel & data,MessageParcel & reply)2981 ErrCode BundleMgrHost::HandleGetBundleStats(MessageParcel &data, MessageParcel &reply)
2982 {
2983     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2984     std::string bundleName = data.ReadString();
2985     int32_t userId = data.ReadInt32();
2986     int32_t appIndex = data.ReadInt32();
2987     uint32_t statFlag = data.ReadUint32();
2988     std::vector<int64_t> bundleStats;
2989     bool ret = GetBundleStats(bundleName, userId, bundleStats, appIndex, statFlag);
2990     if (!reply.WriteBool(ret)) {
2991         APP_LOGE("write result failed");
2992         return ERR_APPEXECFWK_PARCEL_ERROR;
2993     }
2994     if (ret && !reply.WriteInt64Vector(bundleStats)) {
2995         APP_LOGE("write bundleStats failed");
2996         return ERR_APPEXECFWK_PARCEL_ERROR;
2997     }
2998     return ERR_OK;
2999 }
3000 
HandleGetAllBundleStats(MessageParcel & data,MessageParcel & reply)3001 ErrCode BundleMgrHost::HandleGetAllBundleStats(MessageParcel &data, MessageParcel &reply)
3002 {
3003     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3004     int32_t userId = data.ReadInt32();
3005     std::vector<int64_t> bundleStats;
3006     bool ret = GetAllBundleStats(userId, bundleStats);
3007     if (!reply.WriteBool(ret)) {
3008         APP_LOGE("write result failed");
3009         return ERR_APPEXECFWK_PARCEL_ERROR;
3010     }
3011     if (ret && !reply.WriteInt64Vector(bundleStats)) {
3012         APP_LOGE("write bundleStats failed");
3013         return ERR_APPEXECFWK_PARCEL_ERROR;
3014     }
3015     return ERR_OK;
3016 }
3017 
HandleGetMediaData(MessageParcel & data,MessageParcel & reply)3018 ErrCode BundleMgrHost::HandleGetMediaData(MessageParcel &data, MessageParcel &reply)
3019 {
3020     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3021     std::string bundleName = data.ReadString();
3022     std::string abilityName = data.ReadString();
3023     std::string moduleName = data.ReadString();
3024     int32_t userId = data.ReadInt32();
3025     APP_LOGD("HandleGetMediaData:%{public}s, %{public}s, %{public}s", bundleName.c_str(),
3026         abilityName.c_str(), moduleName.c_str());
3027     std::unique_ptr<uint8_t[]> mediaDataPtr = nullptr;
3028     size_t len = 0;
3029     ErrCode ret = GetMediaData(bundleName, moduleName, abilityName, mediaDataPtr, len, userId);
3030     if (!reply.WriteInt32(ret)) {
3031         APP_LOGE("write ret failed");
3032         return ERR_APPEXECFWK_PARCEL_ERROR;
3033     }
3034     if (ret != ERR_OK) {
3035         return ERR_OK;
3036     }
3037     if (mediaDataPtr == nullptr || len == 0) {
3038         return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
3039     }
3040     // write ashMem
3041     sptr<Ashmem> ashMem = Ashmem::CreateAshmem((__func__ + std::to_string(AllocatAshmemNum())).c_str(), len);
3042     if (ashMem == nullptr) {
3043         APP_LOGE("CreateAshmem failed");
3044         return ERR_APPEXECFWK_PARCEL_ERROR;
3045     }
3046     if (!ashMem->MapReadAndWriteAshmem()) {
3047         APP_LOGE("MapReadAndWriteAshmem failed");
3048         return ERR_APPEXECFWK_PARCEL_ERROR;
3049     }
3050     int32_t offset = 0;
3051     if (!ashMem->WriteToAshmem(mediaDataPtr.get(), len, offset)) {
3052         APP_LOGE("MapReadAndWriteAshmem failed");
3053         return ERR_APPEXECFWK_PARCEL_ERROR;
3054     }
3055     MessageParcel *messageParcel = &reply;
3056     if (messageParcel == nullptr || !messageParcel->WriteAshmem(ashMem)) {
3057         APP_LOGE("WriteAshmem failed");
3058         return ERR_APPEXECFWK_PARCEL_ERROR;
3059     }
3060     return ERR_OK;
3061 }
3062 
HandleSetDebugMode(MessageParcel & data,MessageParcel & reply)3063 ErrCode BundleMgrHost::HandleSetDebugMode(MessageParcel &data, MessageParcel &reply)
3064 {
3065     APP_LOGI("start to process HandleSetDebugMode message");
3066     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3067     bool enable = data.ReadBool();
3068     auto ret = SetDebugMode(enable);
3069     if (ret != ERR_OK) {
3070         APP_LOGE("SetDebugMode failed");
3071     }
3072     if (!reply.WriteInt32(ret)) {
3073         APP_LOGE("write failed");
3074         return ERR_BUNDLEMANAGER_SET_DEBUG_MODE_PARCEL_ERROR;
3075     }
3076     return ERR_OK;
3077 }
3078 
HandleGetOverlayManagerProxy(MessageParcel & data,MessageParcel & reply)3079 ErrCode BundleMgrHost::HandleGetOverlayManagerProxy(MessageParcel &data, MessageParcel &reply)
3080 {
3081     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3082     sptr<IOverlayManager> overlayManagerProxy = GetOverlayManagerProxy();
3083     if (overlayManagerProxy == nullptr) {
3084         APP_LOGE("overlayManagerProxy is nullptr");
3085         return ERR_APPEXECFWK_PARCEL_ERROR;
3086     }
3087 
3088     if (!reply.WriteRemoteObject(overlayManagerProxy->AsObject())) {
3089         APP_LOGE("WriteRemoteObject failed");
3090         return ERR_APPEXECFWK_PARCEL_ERROR;
3091     }
3092     return ERR_OK;
3093 }
3094 
HandleProcessPreload(MessageParcel & data,MessageParcel & reply)3095 ErrCode BundleMgrHost::HandleProcessPreload(MessageParcel &data, MessageParcel &reply)
3096 {
3097     APP_LOGD("start to process HandleProcessPreload message");
3098     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3099     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
3100     if (want == nullptr) {
3101         APP_LOGE("ReadParcelable<want> failed");
3102         return ERR_APPEXECFWK_PARCEL_ERROR;
3103     }
3104     auto ret = ProcessPreload(*want);
3105     if (!reply.WriteBool(ret)) {
3106         APP_LOGE("write result failed");
3107         return ERR_APPEXECFWK_PARCEL_ERROR;
3108     }
3109     return ERR_OK;
3110 }
3111 
HandleGetAppProvisionInfo(MessageParcel & data,MessageParcel & reply)3112 ErrCode BundleMgrHost::HandleGetAppProvisionInfo(MessageParcel &data, MessageParcel &reply)
3113 {
3114     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3115     std::string bundleName = data.ReadString();
3116     int32_t userId = data.ReadInt32();
3117     AppProvisionInfo appProvisionInfo;
3118     ErrCode ret = GetAppProvisionInfo(bundleName, userId, appProvisionInfo);
3119     if (!reply.WriteInt32(ret)) {
3120         APP_LOGE("HandleGetAppProvisionInfo write failed");
3121         return ERR_APPEXECFWK_PARCEL_ERROR;
3122     }
3123     if ((ret == ERR_OK) && !reply.WriteParcelable(&appProvisionInfo)) {
3124         APP_LOGE("write appProvisionInfo failed");
3125         return ERR_APPEXECFWK_PARCEL_ERROR;
3126     }
3127     return ERR_OK;
3128 }
3129 
HandleGetProvisionMetadata(MessageParcel & data,MessageParcel & reply)3130 ErrCode BundleMgrHost::HandleGetProvisionMetadata(MessageParcel &data, MessageParcel &reply)
3131 {
3132     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3133     std::string bundleName = data.ReadString();
3134     int32_t userId = data.ReadInt32();
3135     APP_LOGD("start to get provision metadata, bundleName is %{public}s, userId is %{public}d",
3136         bundleName.c_str(), userId);
3137     std::vector<Metadata> provisionMetadatas;
3138     ErrCode ret = GetProvisionMetadata(bundleName, userId, provisionMetadatas);
3139     if (ret != ERR_OK) {
3140         APP_LOGE("GetProvisionMetadata failed");
3141     }
3142     if (!reply.WriteInt32(ret)) {
3143         APP_LOGE("write failed");
3144         return ERR_APPEXECFWK_PARCEL_ERROR;
3145     }
3146     if (ret == ERR_OK) {
3147         if (!WriteParcelableVector(provisionMetadatas, reply)) {
3148             APP_LOGE("write failed");
3149             return ERR_APPEXECFWK_PARCEL_ERROR;
3150         }
3151     }
3152     return ERR_OK;
3153 }
3154 
HandleGetBaseSharedBundleInfos(MessageParcel & data,MessageParcel & reply)3155 ErrCode BundleMgrHost::HandleGetBaseSharedBundleInfos(MessageParcel &data, MessageParcel &reply)
3156 {
3157     APP_LOGD("start to process HandleGetBaseSharedBundleInfos message");
3158     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3159     std::string bundleName = data.ReadString();
3160     GetDependentBundleInfoFlag flag = static_cast<GetDependentBundleInfoFlag>(data.ReadUint32());
3161 
3162     std::vector<BaseSharedBundleInfo> infos;
3163     ErrCode ret = GetBaseSharedBundleInfos(bundleName, infos, flag);
3164     if (!reply.WriteInt32(ret)) {
3165         APP_LOGE("write failed");
3166         return ERR_APPEXECFWK_PARCEL_ERROR;
3167     }
3168     if (ret != ERR_OK) {
3169         return ERR_OK;
3170     }
3171     if (!WriteParcelableVector(infos, reply)) {
3172         APP_LOGE("write failed");
3173         return ERR_APPEXECFWK_PARCEL_ERROR;
3174     }
3175     return ERR_OK;
3176 }
3177 
HandleGetAllSharedBundleInfo(MessageParcel & data,MessageParcel & reply)3178 ErrCode BundleMgrHost::HandleGetAllSharedBundleInfo(MessageParcel &data, MessageParcel &reply)
3179 {
3180     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3181     std::vector<SharedBundleInfo> infos;
3182     ErrCode ret = GetAllSharedBundleInfo(infos);
3183     if (!reply.WriteInt32(ret)) {
3184         APP_LOGE("HandleGetAllSharedBundleInfo write failed");
3185         return ERR_APPEXECFWK_PARCEL_ERROR;
3186     }
3187     if ((ret == ERR_OK) && !WriteParcelableVector(infos, reply)) {
3188         APP_LOGE("write infos failed");
3189         return ERR_APPEXECFWK_PARCEL_ERROR;
3190     }
3191     return ERR_OK;
3192 }
3193 
HandleGetSharedBundleInfo(MessageParcel & data,MessageParcel & reply)3194 ErrCode BundleMgrHost::HandleGetSharedBundleInfo(MessageParcel &data, MessageParcel &reply)
3195 {
3196     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3197     std::string bundleName = data.ReadString();
3198     std::string moduleName = data.ReadString();
3199     std::vector<SharedBundleInfo> infos;
3200     ErrCode ret = GetSharedBundleInfo(bundleName, moduleName, infos);
3201     if (!reply.WriteInt32(ret)) {
3202         APP_LOGE("HandleGetSharedBundleInfo write failed");
3203         return ERR_APPEXECFWK_PARCEL_ERROR;
3204     }
3205     if ((ret == ERR_OK) && !WriteParcelableVector(infos, reply)) {
3206         APP_LOGE("write infos failed");
3207         return ERR_APPEXECFWK_PARCEL_ERROR;
3208     }
3209     return ERR_OK;
3210 }
3211 
HandleGetSharedBundleInfoBySelf(MessageParcel & data,MessageParcel & reply)3212 ErrCode BundleMgrHost::HandleGetSharedBundleInfoBySelf(MessageParcel &data, MessageParcel &reply)
3213 {
3214     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3215     std::string bundleName = data.ReadString();
3216     SharedBundleInfo shareBundleInfo;
3217     ErrCode ret = GetSharedBundleInfoBySelf(bundleName, shareBundleInfo);
3218     if (!reply.WriteInt32(ret)) {
3219         APP_LOGE("HandleGetSharedBundleInfoBySelf write failed");
3220         return ERR_APPEXECFWK_PARCEL_ERROR;
3221     }
3222     if ((ret == ERR_OK) && !reply.WriteParcelable(&shareBundleInfo)) {
3223         APP_LOGE("write failed");
3224         return ERR_APPEXECFWK_PARCEL_ERROR;
3225     }
3226     return ERR_OK;
3227 }
3228 
HandleGetSharedDependencies(MessageParcel & data,MessageParcel & reply)3229 ErrCode BundleMgrHost::HandleGetSharedDependencies(MessageParcel &data, MessageParcel &reply)
3230 {
3231     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3232     std::string bundleName = data.ReadString();
3233     std::string moduleName = data.ReadString();
3234     std::vector<Dependency> dependencies;
3235     ErrCode ret = GetSharedDependencies(bundleName, moduleName, dependencies);
3236     if (!reply.WriteInt32(ret)) {
3237         APP_LOGE("HandleGetSharedDependencies write failed");
3238         return ERR_APPEXECFWK_PARCEL_ERROR;
3239     }
3240     if ((ret == ERR_OK) && !WriteParcelableVector(dependencies, reply)) {
3241         APP_LOGE("write dependencies failed");
3242         return ERR_APPEXECFWK_PARCEL_ERROR;
3243     }
3244     return ERR_OK;
3245 }
3246 
HandleGetProxyDataInfos(MessageParcel & data,MessageParcel & reply)3247 ErrCode BundleMgrHost::HandleGetProxyDataInfos(MessageParcel &data, MessageParcel &reply)
3248 {
3249     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3250     std::string bundleName = data.ReadString();
3251     std::string moduleName = data.ReadString();
3252     int32_t userId = data.ReadInt32();
3253     std::vector<ProxyData> proxyDatas;
3254     ErrCode ret = GetProxyDataInfos(bundleName, moduleName, proxyDatas, userId);
3255     if (!reply.WriteInt32(ret)) {
3256         APP_LOGE("HandleGetProxyDataInfos write failed");
3257         return ERR_APPEXECFWK_PARCEL_ERROR;
3258     }
3259     if ((ret == ERR_OK) && !WriteParcelableVector(proxyDatas, reply)) {
3260         APP_LOGE("write proxyDatas failed");
3261         return ERR_APPEXECFWK_PARCEL_ERROR;
3262     }
3263     return ERR_OK;
3264 }
3265 
HandleGetAllProxyDataInfos(MessageParcel & data,MessageParcel & reply)3266 ErrCode BundleMgrHost::HandleGetAllProxyDataInfos(MessageParcel &data, MessageParcel &reply)
3267 {
3268     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3269     std::vector<ProxyData> proxyDatas;
3270     int32_t userId = data.ReadInt32();
3271     ErrCode ret = GetAllProxyDataInfos(proxyDatas, userId);
3272     if (!reply.WriteInt32(ret)) {
3273         APP_LOGE("HandleGetProxyDataInfos write failed");
3274         return ERR_APPEXECFWK_PARCEL_ERROR;
3275     }
3276     if ((ret == ERR_OK) && !WriteParcelableVector(proxyDatas, reply)) {
3277         APP_LOGE("write proxyDatas failed");
3278         return ERR_APPEXECFWK_PARCEL_ERROR;
3279     }
3280     return ERR_OK;
3281 }
3282 
HandleGetSpecifiedDistributionType(MessageParcel & data,MessageParcel & reply)3283 ErrCode BundleMgrHost::HandleGetSpecifiedDistributionType(MessageParcel &data, MessageParcel &reply)
3284 {
3285     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3286     std::string bundleName = data.ReadString();
3287     std::string specifiedDistributedType;
3288     ErrCode ret = GetSpecifiedDistributionType(bundleName, specifiedDistributedType);
3289     if (!reply.WriteInt32(ret)) {
3290         APP_LOGE("HandleGetSpecifiedDistributionType write failed");
3291         return ERR_APPEXECFWK_PARCEL_ERROR;
3292     }
3293     if ((ret == ERR_OK) && !reply.WriteString(specifiedDistributedType)) {
3294         APP_LOGE("write specifiedDistributedType failed");
3295         return ERR_APPEXECFWK_PARCEL_ERROR;
3296     }
3297     return ERR_OK;
3298 }
3299 
HandleGetAdditionalInfo(MessageParcel & data,MessageParcel & reply)3300 ErrCode BundleMgrHost::HandleGetAdditionalInfo(MessageParcel &data, MessageParcel &reply)
3301 {
3302     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3303     std::string bundleName = data.ReadString();
3304     std::string additionalInfo;
3305     ErrCode ret = GetAdditionalInfo(bundleName, additionalInfo);
3306     if (!reply.WriteInt32(ret)) {
3307         APP_LOGE("HandleGetAdditionalInfo write failed");
3308         return ERR_APPEXECFWK_PARCEL_ERROR;
3309     }
3310     if ((ret == ERR_OK) && !reply.WriteString(additionalInfo)) {
3311         APP_LOGE("write additionalInfo failed");
3312         return ERR_APPEXECFWK_PARCEL_ERROR;
3313     }
3314     return ERR_OK;
3315 }
3316 
HandleSetExtNameOrMIMEToApp(MessageParcel & data,MessageParcel & reply)3317 ErrCode BundleMgrHost::HandleSetExtNameOrMIMEToApp(MessageParcel &data, MessageParcel &reply)
3318 {
3319     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3320     std::string bundleName = data.ReadString();
3321     std::string moduleName = data.ReadString();
3322     std::string abilityName = data.ReadString();
3323     std::string extName = data.ReadString();
3324     std::string mimeType = data.ReadString();
3325     ErrCode ret = SetExtNameOrMIMEToApp(bundleName, moduleName, abilityName, extName, mimeType);
3326     if (!reply.WriteInt32(ret)) {
3327         APP_LOGE("HandleSetExtNameOrMIMEToApp write failed");
3328         return ERR_APPEXECFWK_PARCEL_ERROR;
3329     }
3330     return ERR_OK;
3331 }
3332 
HandleDelExtNameOrMIMEToApp(MessageParcel & data,MessageParcel & reply)3333 ErrCode BundleMgrHost::HandleDelExtNameOrMIMEToApp(MessageParcel &data, MessageParcel &reply)
3334 {
3335     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3336     std::string bundleName = data.ReadString();
3337     std::string moduleName = data.ReadString();
3338     std::string abilityName = data.ReadString();
3339     std::string extName = data.ReadString();
3340     std::string mimeType = data.ReadString();
3341     ErrCode ret = DelExtNameOrMIMEToApp(bundleName, moduleName, abilityName, extName, mimeType);
3342     if (!reply.WriteInt32(ret)) {
3343         APP_LOGE("HandleDelExtNameOrMIMEToApp write failed");
3344         return ERR_APPEXECFWK_PARCEL_ERROR;
3345     }
3346     return ERR_OK;
3347 }
3348 
HandleQueryDataGroupInfos(MessageParcel & data,MessageParcel & reply)3349 ErrCode BundleMgrHost::HandleQueryDataGroupInfos(MessageParcel &data, MessageParcel &reply)
3350 {
3351     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3352     std::string bundleName = data.ReadString();
3353     int32_t userId = data.ReadInt32();
3354 
3355     std::vector<DataGroupInfo> infos;
3356     bool ret = QueryDataGroupInfos(bundleName, userId, infos);
3357     if (!reply.WriteBool(ret)) {
3358         APP_LOGE("write failed");
3359         return ERR_APPEXECFWK_PARCEL_ERROR;
3360     }
3361     if (ret && !WriteParcelableVector(infos, reply)) {
3362         APP_LOGE("write dataGroupInfo failed");
3363         return ERR_APPEXECFWK_PARCEL_ERROR;
3364     }
3365     return ERR_OK;
3366 }
3367 
HandleGetPreferenceDirByGroupId(MessageParcel & data,MessageParcel & reply)3368 ErrCode BundleMgrHost::HandleGetPreferenceDirByGroupId(MessageParcel &data, MessageParcel &reply)
3369 {
3370     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3371     std::string dataGroupId = data.ReadString();
3372     std::string dir;
3373     bool ret = GetGroupDir(dataGroupId, dir);
3374     if (!reply.WriteBool(ret)) {
3375         APP_LOGE("write failed");
3376         return ERR_APPEXECFWK_PARCEL_ERROR;
3377     }
3378     if (ret) {
3379         if (!reply.WriteString(dir)) {
3380             APP_LOGE("write failed");
3381             return ERR_APPEXECFWK_PARCEL_ERROR;
3382         }
3383     }
3384     return ERR_OK;
3385 }
3386 
HandleQueryAppGalleryBundleName(MessageParcel & data,MessageParcel & reply)3387 ErrCode BundleMgrHost::HandleQueryAppGalleryBundleName(MessageParcel &data, MessageParcel &reply)
3388 {
3389     APP_LOGD("QueryAppGalleryBundleName in bundle mgr hoxt start");
3390     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3391     std::string bundleName;
3392     bool ret = QueryAppGalleryBundleName(bundleName);
3393     if (!reply.WriteBool(ret)) {
3394         APP_LOGE("write failed");
3395         return ERR_APPEXECFWK_PARCEL_ERROR;
3396     }
3397     if (ret) {
3398         if (!reply.WriteString(bundleName)) {
3399             APP_LOGE("write failed");
3400             return ERR_APPEXECFWK_PARCEL_ERROR;
3401         }
3402     }
3403     APP_LOGD("BundleName is %{public}s", bundleName.c_str());
3404     return ERR_OK;
3405 }
3406 
HandleQueryExtensionAbilityInfosWithTypeName(MessageParcel & data,MessageParcel & reply)3407 ErrCode BundleMgrHost::HandleQueryExtensionAbilityInfosWithTypeName(MessageParcel &data, MessageParcel &reply)
3408 {
3409     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
3410     if (want == nullptr) {
3411         APP_LOGE("ReadParcelable<want> failed");
3412         return ERR_APPEXECFWK_PARCEL_ERROR;
3413     }
3414 
3415     std::string extensionTypeName = data.ReadString();
3416     int32_t flags = data.ReadInt32();
3417     int32_t userId = data.ReadInt32();
3418     std::vector<ExtensionAbilityInfo> extensionAbilityInfos;
3419     ErrCode ret =
3420         QueryExtensionAbilityInfosWithTypeName(*want, extensionTypeName, flags, userId, extensionAbilityInfos);
3421     if (!reply.WriteInt32(ret)) {
3422         APP_LOGE("Write result failed");
3423         return ERR_APPEXECFWK_PARCEL_ERROR;
3424     }
3425     if (ret == ERR_OK && !WriteParcelableVector(extensionAbilityInfos, reply)) {
3426         APP_LOGE("Write extension infos failed");
3427             return ERR_APPEXECFWK_PARCEL_ERROR;
3428     }
3429     return ERR_OK;
3430 }
3431 
HandleQueryExtensionAbilityInfosOnlyWithTypeName(MessageParcel & data,MessageParcel & reply)3432 ErrCode BundleMgrHost::HandleQueryExtensionAbilityInfosOnlyWithTypeName(MessageParcel &data, MessageParcel &reply)
3433 {
3434     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3435     std::string extensionTypeName = data.ReadString();
3436     uint32_t flags = data.ReadUint32();
3437     int32_t userId = data.ReadInt32();
3438     std::vector<ExtensionAbilityInfo> extensionAbilityInfos;
3439     ErrCode ret =
3440         QueryExtensionAbilityInfosOnlyWithTypeName(extensionTypeName, flags, userId, extensionAbilityInfos);
3441     if (!reply.WriteInt32(ret)) {
3442         APP_LOGE("Write result failed");
3443         return ERR_APPEXECFWK_PARCEL_ERROR;
3444     }
3445     if (ret == ERR_OK && !WriteVectorToParcelIntelligent(extensionAbilityInfos, reply)) {
3446         APP_LOGE("Write extension infos failed");
3447             return ERR_APPEXECFWK_PARCEL_ERROR;
3448     }
3449     return ERR_OK;
3450 }
3451 
HandleResetAOTCompileStatus(MessageParcel & data,MessageParcel & reply)3452 ErrCode BundleMgrHost::HandleResetAOTCompileStatus(MessageParcel &data, MessageParcel &reply)
3453 {
3454     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3455     std::string bundleName = data.ReadString();
3456     std::string moduleName = data.ReadString();
3457     int32_t triggerMode = data.ReadInt32();
3458     APP_LOGD("bundleName : %{public}s, moduleName : %{public}s, triggerMode : %{public}d",
3459         bundleName.c_str(), moduleName.c_str(), triggerMode);
3460     ErrCode ret = ResetAOTCompileStatus(bundleName, moduleName, triggerMode);
3461     APP_LOGD("ret : %{public}d", ret);
3462     if (!reply.WriteInt32(ret)) {
3463         APP_LOGE("write ret failed");
3464         return ERR_APPEXECFWK_PARCEL_ERROR;
3465     }
3466     return ERR_OK;
3467 }
3468 
HandleGetJsonProfile(MessageParcel & data,MessageParcel & reply)3469 ErrCode BundleMgrHost::HandleGetJsonProfile(MessageParcel &data, MessageParcel &reply)
3470 {
3471     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3472     ProfileType profileType = static_cast<ProfileType>(data.ReadInt32());
3473     std::string bundleName = data.ReadString();
3474     std::string moduleName = data.ReadString();
3475     int32_t userId = data.ReadInt32();
3476     std::string profile;
3477     ErrCode ret = GetJsonProfile(profileType, bundleName, moduleName, profile, userId);
3478     if (!reply.WriteInt32(ret)) {
3479         APP_LOGE("write failed");
3480         return ERR_APPEXECFWK_PARCEL_ERROR;
3481     }
3482     if (ret == ERR_OK && WriteBigString(profile, reply) != ERR_OK) {
3483         APP_LOGE("write failed");
3484         return ERR_APPEXECFWK_PARCEL_ERROR;
3485     }
3486     return ERR_OK;
3487 }
3488 
HandleGetBundleResourceProxy(MessageParcel & data,MessageParcel & reply)3489 ErrCode BundleMgrHost::HandleGetBundleResourceProxy(MessageParcel &data, MessageParcel &reply)
3490 {
3491     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3492     sptr<IBundleResource> bundleResourceProxy = GetBundleResourceProxy();
3493     if (bundleResourceProxy == nullptr) {
3494         APP_LOGE("bundleResourceProxy is nullptr");
3495         return ERR_APPEXECFWK_PARCEL_ERROR;
3496     }
3497 
3498     if (!reply.WriteRemoteObject(bundleResourceProxy->AsObject())) {
3499         APP_LOGE("WriteRemoteObject failed");
3500         return ERR_APPEXECFWK_PARCEL_ERROR;
3501     }
3502     return ERR_OK;
3503 }
3504 
HandleGetRecoverableApplicationInfo(MessageParcel & data,MessageParcel & reply)3505 ErrCode BundleMgrHost::HandleGetRecoverableApplicationInfo(MessageParcel &data, MessageParcel &reply)
3506 {
3507     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3508     std::vector<RecoverableApplicationInfo> infos;
3509     ErrCode ret = GetRecoverableApplicationInfo(infos);
3510     if (!reply.WriteInt32(ret)) {
3511         APP_LOGE("HandleGetRecoverableApplicationInfo write failed");
3512         return ERR_APPEXECFWK_PARCEL_ERROR;
3513     }
3514     if ((ret == ERR_OK) && !WriteParcelableVector(infos, reply)) {
3515         APP_LOGE("write infos failed");
3516         return ERR_APPEXECFWK_PARCEL_ERROR;
3517     }
3518     return ERR_OK;
3519 }
3520 
HandleGetUninstalledBundleInfo(MessageParcel & data,MessageParcel & reply)3521 ErrCode BundleMgrHost::HandleGetUninstalledBundleInfo(MessageParcel &data, MessageParcel &reply)
3522 {
3523     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3524     std::string name = data.ReadString();
3525     if (name.empty()) {
3526         APP_LOGE("bundleName is empty");
3527         return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
3528     }
3529     BundleInfo info;
3530     auto ret = GetUninstalledBundleInfo(name, info);
3531     if (!reply.WriteInt32(ret)) {
3532         APP_LOGE("write failed");
3533         return ERR_APPEXECFWK_PARCEL_ERROR;
3534     }
3535     reply.SetDataCapacity(Constants::CAPACITY_SIZE);
3536     if (ret == ERR_OK && !reply.WriteParcelable(&info)) {
3537         APP_LOGE("write failed");
3538         return ERR_APPEXECFWK_PARCEL_ERROR;
3539     }
3540     return ERR_OK;
3541 }
3542 
HandleSetAdditionalInfo(MessageParcel & data,MessageParcel & reply)3543 ErrCode BundleMgrHost::HandleSetAdditionalInfo(MessageParcel &data, MessageParcel &reply)
3544 {
3545     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3546     std::string bundleName = data.ReadString();
3547     std::string additionalInfo = data.ReadString();
3548     ErrCode ret = SetAdditionalInfo(bundleName, additionalInfo);
3549     if (!reply.WriteInt32(ret)) {
3550         APP_LOGE("Write reply failed");
3551         return ERR_APPEXECFWK_PARCEL_ERROR;
3552     }
3553     return ERR_OK;
3554 }
3555 
HandleCreateBundleDataDir(MessageParcel & data,MessageParcel & reply)3556 ErrCode BundleMgrHost::HandleCreateBundleDataDir(MessageParcel &data, MessageParcel &reply)
3557 {
3558     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3559     APP_LOGI("CreateBundleDataDir called");
3560     int32_t userId = data.ReadInt32();
3561     ErrCode ret = CreateBundleDataDir(userId);
3562     if (!reply.WriteInt32(ret)) {
3563         APP_LOGE("Write reply failed");
3564         return ERR_APPEXECFWK_PARCEL_ERROR;
3565     }
3566     return ERR_OK;
3567 }
3568 
3569 template<typename T>
WriteParcelableIntoAshmem(T & parcelable,const char * ashmemName,MessageParcel & reply)3570 bool BundleMgrHost::WriteParcelableIntoAshmem(
3571     T &parcelable, const char *ashmemName, MessageParcel &reply)
3572 {
3573     APP_LOGE("Write parcelable into ashmem");
3574     if (ashmemName == nullptr) {
3575         APP_LOGE("AshmemName is null");
3576         return false;
3577     }
3578 
3579     MessageParcel *messageParcel = reinterpret_cast<MessageParcel *>(&reply);
3580     if (messageParcel == nullptr) {
3581         APP_LOGE("Type conversion failed");
3582         return false;
3583     }
3584 
3585     int32_t totalSize = 0;
3586     auto infoStr = GetJsonStrFromInfo<T>(parcelable);
3587     totalSize += ASHMEM_LEN;
3588     totalSize += strlen(infoStr.c_str());
3589     if (totalSize <= 0) {
3590         APP_LOGE("The size of the ashmem is invalid or the content is empty");
3591         return false;
3592     }
3593 
3594     // The ashmem name must be unique.
3595     sptr<Ashmem> ashmem = Ashmem::CreateAshmem(
3596         (ashmemName + std::to_string(AllocatAshmemNum())).c_str(), totalSize);
3597     if (ashmem == nullptr) {
3598         APP_LOGE("Create shared memory failed");
3599         return false;
3600     }
3601 
3602     // Set the read/write mode of the ashme.
3603     bool ret = ashmem->MapReadAndWriteAshmem();
3604     if (!ret) {
3605         APP_LOGE("Map shared memory fail");
3606         return false;
3607     }
3608 
3609     // Write the size and content of each item to the ashmem.
3610     // The size of item use ASHMEM_LEN.
3611     int32_t offset = 0;
3612     int itemLen = static_cast<int>(strlen(infoStr.c_str()));
3613     ret = ashmem->WriteToAshmem(std::to_string(itemLen).c_str(), ASHMEM_LEN, offset);
3614     if (!ret) {
3615         APP_LOGE("Write itemLen to shared memory fail");
3616         return false;
3617     }
3618 
3619     offset += ASHMEM_LEN;
3620     ret = ashmem->WriteToAshmem(infoStr.c_str(), itemLen, offset);
3621     if (!ret) {
3622         APP_LOGE("Write info to shared memory fail");
3623         return false;
3624     }
3625 
3626     ret = messageParcel->WriteAshmem(ashmem);
3627     if (!ret) {
3628         APP_LOGE("Write ashmem to MessageParcel fail");
3629         return false;
3630     }
3631 
3632     APP_LOGE("Write parcelable vector into ashmem success");
3633     return true;
3634 }
3635 
3636 template<typename T>
WriteBigParcelable(T & parcelable,const char * ashmemName,MessageParcel & reply)3637 ErrCode BundleMgrHost::WriteBigParcelable(T &parcelable, const char *ashmemName, MessageParcel &reply)
3638 {
3639     auto size = sizeof(reply);
3640     APP_LOGD("reply size is %{public}lu", static_cast<unsigned long>(size));
3641     bool useAshMem = size > ASHMEM_THRESHOLD;
3642     if (!reply.WriteBool(useAshMem)) {
3643         APP_LOGE("write failed");
3644         return ERR_APPEXECFWK_PARCEL_ERROR;
3645     }
3646     if (useAshMem) {
3647         APP_LOGI("reply size %{public}lu, writing ashmem", static_cast<unsigned long>(size));
3648         if (!WriteParcelableIntoAshmem(parcelable, ashmemName, reply)) {
3649             APP_LOGE("write failed");
3650             return ERR_APPEXECFWK_PARCEL_ERROR;
3651         }
3652     } else {
3653         if (!reply.WriteParcelable(&parcelable)) {
3654             APP_LOGE("write failed");
3655             return ERR_APPEXECFWK_PARCEL_ERROR;
3656         }
3657     }
3658     return ERR_OK;
3659 }
3660 
3661 template<typename T>
WriteParcelInfoIntelligent(const T & parcelInfo,MessageParcel & reply) const3662 ErrCode BundleMgrHost::WriteParcelInfoIntelligent(const T &parcelInfo, MessageParcel &reply) const
3663 {
3664     Parcel tmpParcel;
3665     (void)tmpParcel.SetMaxCapacity(MAX_PARCEL_CAPACITY);
3666     if (!tmpParcel.WriteParcelable(&parcelInfo)) {
3667         APP_LOGE("write parcel failed");
3668         return ERR_APPEXECFWK_PARCEL_ERROR;
3669     }
3670     size_t dataSize = tmpParcel.GetDataSize();
3671     if (!reply.WriteUint32(dataSize)) {
3672         APP_LOGE("write parcel failed");
3673         return ERR_APPEXECFWK_PARCEL_ERROR;
3674     }
3675 
3676     if (!reply.WriteRawData(reinterpret_cast<uint8_t *>(tmpParcel.GetData()), dataSize)) {
3677         APP_LOGE("write parcel failed");
3678         return ERR_APPEXECFWK_PARCEL_ERROR;
3679     }
3680     return ERR_OK;
3681 }
3682 
3683 template<typename T>
WriteParcelInfo(const T & parcelInfo,MessageParcel & reply) const3684 ErrCode BundleMgrHost::WriteParcelInfo(const T &parcelInfo, MessageParcel &reply) const
3685 {
3686     Parcel tmpParcel;
3687     (void)tmpParcel.SetMaxCapacity(MAX_PARCEL_CAPACITY);
3688     WRITE_PARCEL(tmpParcel.WriteParcelable(&parcelInfo));
3689     size_t dataSize = tmpParcel.GetDataSize();
3690 
3691     WRITE_PARCEL(reply.WriteUint32(dataSize));
3692     WRITE_PARCEL(reply.WriteRawData(reinterpret_cast<uint8_t *>(tmpParcel.GetData()), dataSize));
3693     return ERR_OK;
3694 }
3695 
WriteBigString(const std::string & str,MessageParcel & reply) const3696 ErrCode BundleMgrHost::WriteBigString(const std::string &str, MessageParcel &reply) const
3697 {
3698     WRITE_PARCEL(reply.WriteUint32(str.size() + 1));
3699     WRITE_PARCEL(reply.WriteRawData(str.c_str(), str.size() + 1));
3700     return ERR_OK;
3701 }
3702 
3703 template<typename T>
ReadParcelInfoIntelligent(MessageParcel & data,T & parcelInfo)3704 ErrCode BundleMgrHost::ReadParcelInfoIntelligent(MessageParcel &data, T &parcelInfo)
3705 {
3706     size_t dataSize = data.ReadUint32();
3707     void *buffer = nullptr;
3708     if (!GetData(buffer, dataSize, data.ReadRawData(dataSize))) {
3709         APP_LOGE("GetData failed dataSize : %{public}zu", dataSize);
3710         return ERR_APPEXECFWK_PARCEL_ERROR;
3711     }
3712     MessageParcel tempParcel;
3713     if (!tempParcel.ParseFrom(reinterpret_cast<uintptr_t>(buffer), dataSize)) {
3714         APP_LOGE("ParseFrom failed");
3715         return ERR_APPEXECFWK_PARCEL_ERROR;
3716     }
3717     std::unique_ptr<T> info(tempParcel.ReadParcelable<T>());
3718     if (info == nullptr) {
3719         APP_LOGE("ReadParcelable failed");
3720         return ERR_APPEXECFWK_PARCEL_ERROR;
3721     }
3722     parcelInfo = *info;
3723     return ERR_OK;
3724 }
3725 
HandleCanOpenLink(MessageParcel & data,MessageParcel & reply)3726 ErrCode BundleMgrHost::HandleCanOpenLink(MessageParcel &data, MessageParcel &reply)
3727 {
3728     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3729     std::string link = data.ReadString();
3730     bool canOpen = false;
3731     ErrCode ret = CanOpenLink(link, canOpen);
3732     if (!reply.WriteInt32(ret)) {
3733         APP_LOGE("write failed");
3734         return ERR_APPEXECFWK_PARCEL_ERROR;
3735     }
3736     if (!reply.WriteBool(canOpen)) {
3737         APP_LOGE("write failed");
3738         return ERR_APPEXECFWK_PARCEL_ERROR;
3739     }
3740     return ERR_OK;
3741 }
3742 
HandleGetOdid(MessageParcel & data,MessageParcel & reply)3743 ErrCode BundleMgrHost::HandleGetOdid(MessageParcel &data, MessageParcel &reply)
3744 {
3745     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3746     std::string odid;
3747     auto ret = GetOdid(odid);
3748     if (!reply.WriteInt32(ret)) {
3749         APP_LOGE("write failed");
3750         return ERR_APPEXECFWK_PARCEL_ERROR;
3751     }
3752     if (!reply.WriteString(odid)) {
3753         APP_LOGE("write failed");
3754         return ERR_APPEXECFWK_PARCEL_ERROR;
3755     }
3756     APP_LOGD("odid is %{private}s", odid.c_str());
3757     return ERR_OK;
3758 }
3759 
HandleGetAllPreinstalledApplicationInfos(MessageParcel & data,MessageParcel & reply)3760 ErrCode BundleMgrHost::HandleGetAllPreinstalledApplicationInfos(MessageParcel &data, MessageParcel &reply)
3761 {
3762     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3763     APP_LOGD("Called");
3764     std::vector<PreinstalledApplicationInfo> preinstalledApplicationInfos;
3765     ErrCode ret = GetAllPreinstalledApplicationInfos(preinstalledApplicationInfos);
3766     int32_t vectorSize = static_cast<int32_t>(preinstalledApplicationInfos.size());
3767     if (vectorSize > MAX_STATUS_VECTOR_NUM) {
3768         APP_LOGE("PreinstallApplicationInfos vector is over size");
3769         return ERR_APPEXECFWK_PARCEL_ERROR;
3770     }
3771 
3772     constexpr int32_t VECTOR_SIZE_UNDER_DEFAULT_DATA = 500;
3773     if (vectorSize > VECTOR_SIZE_UNDER_DEFAULT_DATA &&
3774         !reply.SetDataCapacity(PREINSTALL_PARCEL_CAPACITY)) {
3775         APP_LOGE("SetDataCapacity failed");
3776         return ERR_APPEXECFWK_PARCEL_ERROR;
3777     }
3778     if (!reply.WriteInt32(ret)) {
3779         APP_LOGE("Write reply failed");
3780         return ERR_APPEXECFWK_PARCEL_ERROR;
3781     }
3782     if (ret == ERR_OK && !WriteParcelableVector(preinstalledApplicationInfos, reply)) {
3783         APP_LOGE("Write preinstalled app infos failed");
3784         return ERR_APPEXECFWK_PARCEL_ERROR;
3785     }
3786 
3787     return ERR_OK;
3788 }
3789 
HandleGetAllBundleInfoByDeveloperId(MessageParcel & data,MessageParcel & reply)3790 ErrCode BundleMgrHost::HandleGetAllBundleInfoByDeveloperId(MessageParcel &data, MessageParcel &reply)
3791 {
3792     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3793     std::string developerId = data.ReadString();
3794     int32_t userId = data.ReadInt32();
3795     std::vector<BundleInfo> infos;
3796     auto ret = GetAllBundleInfoByDeveloperId(developerId, infos, userId);
3797     if (!reply.WriteInt32(ret)) {
3798         APP_LOGE("write failed");
3799         return ERR_APPEXECFWK_PARCEL_ERROR;
3800     }
3801     if (ret == ERR_OK) {
3802         if (!WriteVectorToParcelIntelligent(infos, reply)) {
3803             APP_LOGE("write failed");
3804             return ERR_APPEXECFWK_PARCEL_ERROR;
3805         }
3806     }
3807     return ERR_OK;
3808 }
3809 
HandleGetDeveloperIds(MessageParcel & data,MessageParcel & reply)3810 ErrCode BundleMgrHost::HandleGetDeveloperIds(MessageParcel &data, MessageParcel &reply)
3811 {
3812     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3813     std::string appDistributionType = data.ReadString();
3814     int32_t userId = data.ReadInt32();
3815     std::vector<std::string> developerIdList;
3816     auto ret = GetDeveloperIds(appDistributionType, developerIdList, userId);
3817     if (!reply.WriteInt32(ret)) {
3818         APP_LOGE("write failed");
3819         return ERR_APPEXECFWK_PARCEL_ERROR;
3820     }
3821     if (ret == ERR_OK) {
3822         if (!reply.WriteStringVector(developerIdList)) {
3823             APP_LOGE("write failed");
3824             return ERR_APPEXECFWK_PARCEL_ERROR;
3825         }
3826     }
3827     return ERR_OK;
3828 }
3829 
HandleSwitchUninstallState(MessageParcel & data,MessageParcel & reply)3830 ErrCode BundleMgrHost::HandleSwitchUninstallState(MessageParcel &data, MessageParcel &reply)
3831 {
3832     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3833     std::string bundleName = data.ReadString();
3834     bool state = data.ReadBool();
3835     bool isNeedSendNotify = data.ReadBool();
3836     ErrCode ret = SwitchUninstallState(bundleName, state, isNeedSendNotify);
3837     if (!reply.WriteInt32(ret)) {
3838         APP_LOGE("write failed");
3839         return ERR_APPEXECFWK_PARCEL_ERROR;
3840     }
3841     return ERR_OK;
3842 }
3843 
HandleQueryAbilityInfoByContinueType(MessageParcel & data,MessageParcel & reply)3844 ErrCode BundleMgrHost::HandleQueryAbilityInfoByContinueType(MessageParcel &data, MessageParcel &reply)
3845 {
3846     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3847     std::string bundleName = data.ReadString();
3848     std::string continueType = data.ReadString();
3849     int32_t userId = data.ReadInt32();
3850     AbilityInfo abilityInfo;
3851     auto ret = QueryAbilityInfoByContinueType(bundleName, continueType, abilityInfo, userId);
3852     if (!reply.WriteInt32(ret)) {
3853         APP_LOGE("write failed");
3854         return ERR_APPEXECFWK_PARCEL_ERROR;
3855     }
3856     if (ret == ERR_OK && !reply.WriteParcelable(&abilityInfo)) {
3857         APP_LOGE("write failed");
3858         return ERR_APPEXECFWK_PARCEL_ERROR;
3859     }
3860     return ERR_OK;
3861 }
3862 
HandleQueryCloneAbilityInfo(MessageParcel & data,MessageParcel & reply)3863 ErrCode BundleMgrHost::HandleQueryCloneAbilityInfo(MessageParcel &data, MessageParcel &reply)
3864 {
3865     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3866 
3867     std::unique_ptr<ElementName> elementNamePtr(data.ReadParcelable<ElementName>());
3868     if (!elementNamePtr) {
3869         APP_LOGE("ReadParcelable<ElementName> failed");
3870         return ERR_APPEXECFWK_PARCEL_ERROR;
3871     }
3872 
3873     int32_t flags = data.ReadInt32();
3874     int32_t appIndex = data.ReadInt32();
3875     int32_t userId = data.ReadInt32();
3876 
3877     AbilityInfo abilityInfo;
3878     auto ret = QueryCloneAbilityInfo(*elementNamePtr, flags, appIndex, abilityInfo, userId);
3879     if (!reply.WriteInt32(ret)) {
3880         APP_LOGE("write failed");
3881         return ERR_APPEXECFWK_PARCEL_ERROR;
3882     }
3883     if (ret == ERR_OK && !reply.WriteParcelable(&abilityInfo)) {
3884         APP_LOGE("write failed");
3885         return ERR_APPEXECFWK_PARCEL_ERROR;
3886     }
3887     return ERR_OK;
3888 }
3889 
HandleGetCloneBundleInfo(MessageParcel & data,MessageParcel & reply)3890 ErrCode BundleMgrHost::HandleGetCloneBundleInfo(MessageParcel &data, MessageParcel &reply)
3891 {
3892     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3893     std::string bundleName = data.ReadString();
3894     int32_t flags = data.ReadInt32();
3895     int32_t appIndex = data.ReadInt32();
3896     int32_t userId = data.ReadInt32();
3897 
3898     BundleInfo bundleInfo;
3899     auto ret = GetCloneBundleInfo(bundleName, flags, appIndex, bundleInfo, userId);
3900     if (!reply.WriteInt32(ret)) {
3901         APP_LOGE("write failed");
3902         return ERR_APPEXECFWK_PARCEL_ERROR;
3903     }
3904     if (ret == ERR_OK && !reply.WriteParcelable(&bundleInfo)) {
3905         APP_LOGE("write failed");
3906         return ERR_APPEXECFWK_PARCEL_ERROR;
3907     }
3908     return ERR_OK;
3909 }
3910 
HandleGetCloneAppIndexes(MessageParcel & data,MessageParcel & reply)3911 ErrCode BundleMgrHost::HandleGetCloneAppIndexes(MessageParcel &data, MessageParcel &reply)
3912 {
3913     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3914     std::string bundleName = data.ReadString();
3915     int32_t userId = data.ReadInt32();
3916 
3917     std::vector<int32_t> appIndexes;
3918     auto ret = GetCloneAppIndexes(bundleName, appIndexes, userId);
3919     if (!reply.WriteInt32(ret)) {
3920         APP_LOGE("write failed");
3921         return ERR_APPEXECFWK_PARCEL_ERROR;
3922     }
3923     if (ret == ERR_OK && !reply.WriteInt32Vector(appIndexes)) {
3924         APP_LOGE("write failed");
3925         return ERR_APPEXECFWK_PARCEL_ERROR;
3926     }
3927     return ERR_OK;
3928 }
3929 
HandleGetLaunchWant(MessageParcel & data,MessageParcel & reply)3930 ErrCode BundleMgrHost::HandleGetLaunchWant(MessageParcel &data, MessageParcel &reply)
3931 {
3932     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3933     Want want;
3934     ErrCode ret = GetLaunchWant(want);
3935     if (!reply.WriteInt32(ret)) {
3936         APP_LOGE("write failed");
3937         return ERR_APPEXECFWK_PARCEL_ERROR;
3938     }
3939     if (ret == ERR_OK) {
3940         if (!reply.WriteParcelable(&want)) {
3941             APP_LOGE("write failed");
3942             return ERR_APPEXECFWK_PARCEL_ERROR;
3943         }
3944     }
3945     return ERR_OK;
3946 }
3947 
HandleQueryCloneExtensionAbilityInfoWithAppIndex(MessageParcel & data,MessageParcel & reply)3948 ErrCode BundleMgrHost::HandleQueryCloneExtensionAbilityInfoWithAppIndex(MessageParcel &data, MessageParcel &reply)
3949 {
3950     std::unique_ptr<ElementName> element(data.ReadParcelable<ElementName>());
3951     if (!element) {
3952         APP_LOGE("ReadParcelable<ElementName> failed");
3953         return ERR_APPEXECFWK_PARCEL_ERROR;
3954     }
3955 
3956     int32_t flag = data.ReadInt32();
3957     int32_t appIndex = data.ReadInt32();
3958     int32_t userId = data.ReadInt32();
3959     ExtensionAbilityInfo extensionAbilityInfo;
3960     auto ret = QueryCloneExtensionAbilityInfoWithAppIndex(*element, flag, appIndex, extensionAbilityInfo, userId);
3961     if (!reply.WriteInt32(ret)) {
3962         APP_LOGE("write result failed");
3963         return ERR_APPEXECFWK_PARCEL_ERROR;
3964     }
3965     if (ret == ERR_OK && !reply.WriteParcelable(&extensionAbilityInfo)) {
3966         APP_LOGE("write extension infos failed");
3967         return ERR_APPEXECFWK_PARCEL_ERROR;
3968     }
3969     return ERR_OK;
3970 }
3971 
HandleGetSignatureInfoByBundleName(MessageParcel & data,MessageParcel & reply)3972 ErrCode BundleMgrHost::HandleGetSignatureInfoByBundleName(MessageParcel &data, MessageParcel &reply)
3973 {
3974     std::string name = data.ReadString();
3975     SignatureInfo info;
3976     ErrCode ret = GetSignatureInfoByBundleName(name, info);
3977     if (!reply.WriteInt32(ret)) {
3978         APP_LOGE("write failed");
3979         return ERR_APPEXECFWK_PARCEL_ERROR;
3980     }
3981     if (ret == ERR_OK) {
3982         return WriteParcelInfoIntelligent<SignatureInfo>(info, reply);
3983     }
3984     return ret;
3985 }
3986 
HandleAddDesktopShortcutInfo(MessageParcel & data,MessageParcel & reply)3987 ErrCode BundleMgrHost::HandleAddDesktopShortcutInfo(MessageParcel &data, MessageParcel &reply)
3988 {
3989     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3990     ShortcutInfo shortcutInfo;
3991     auto ret = ReadParcelInfoIntelligent(data, shortcutInfo);
3992     if (ret != ERR_OK) {
3993         APP_LOGE("Read ParcelInfo failed");
3994         return ERR_APPEXECFWK_PARCEL_ERROR;
3995     }
3996     int32_t userId = data.ReadInt32();
3997     ret = AddDesktopShortcutInfo(shortcutInfo, userId);
3998     if (!reply.WriteInt32(ret)) {
3999         APP_LOGE("Write result failed");
4000         return ERR_APPEXECFWK_PARCEL_ERROR;
4001     }
4002     return ERR_OK;
4003 }
4004 
HandleDeleteDesktopShortcutInfo(MessageParcel & data,MessageParcel & reply)4005 ErrCode BundleMgrHost::HandleDeleteDesktopShortcutInfo(MessageParcel &data, MessageParcel &reply)
4006 {
4007     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4008     ShortcutInfo shortcutInfo;
4009     auto ret = ReadParcelInfoIntelligent(data, shortcutInfo);
4010     if (ret != ERR_OK) {
4011         APP_LOGE("Read ParcelInfo failed");
4012         return ERR_APPEXECFWK_PARCEL_ERROR;
4013     }
4014     int32_t userId = data.ReadInt32();
4015     ret = DeleteDesktopShortcutInfo(shortcutInfo, userId);
4016     if (!reply.WriteInt32(ret)) {
4017         APP_LOGE("Write result failed");
4018         return ERR_APPEXECFWK_PARCEL_ERROR;
4019     }
4020     return ERR_OK;
4021 }
4022 
HandleGetAllDesktopShortcutInfo(MessageParcel & data,MessageParcel & reply)4023 ErrCode BundleMgrHost::HandleGetAllDesktopShortcutInfo(MessageParcel &data, MessageParcel &reply)
4024 {
4025     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4026     int32_t userId = data.ReadInt32();
4027     std::vector<ShortcutInfo> infos;
4028     auto ret = GetAllDesktopShortcutInfo(userId, infos);
4029     if (!reply.WriteInt32(ret)) {
4030         APP_LOGE("Write result failed");
4031         return ERR_APPEXECFWK_PARCEL_ERROR;
4032     }
4033     if (ret == ERR_OK && !WriteVectorToParcelIntelligent(infos, reply)) {
4034         APP_LOGE("Write shortcut infos failed");
4035         return ERR_APPEXECFWK_PARCEL_ERROR;
4036     }
4037     return ERR_OK;
4038 }
4039 
HandleGetCompatibleDeviceTypeNative(MessageParcel & data,MessageParcel & reply)4040 ErrCode BundleMgrHost::HandleGetCompatibleDeviceTypeNative(MessageParcel &data, MessageParcel &reply)
4041 {
4042     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4043     std::string deviceType;
4044     auto ret = GetCompatibleDeviceTypeNative(deviceType);
4045     if (!reply.WriteInt32(ret)) {
4046         APP_LOGE("write failed");
4047         return ERR_APPEXECFWK_PARCEL_ERROR;
4048     }
4049     if (!reply.WriteString(deviceType)) {
4050         APP_LOGE("write failed");
4051         return ERR_APPEXECFWK_PARCEL_ERROR;
4052     }
4053     return ERR_OK;
4054 }
4055 
HandleGetCompatibleDeviceType(MessageParcel & data,MessageParcel & reply)4056 ErrCode BundleMgrHost::HandleGetCompatibleDeviceType(MessageParcel &data, MessageParcel &reply)
4057 {
4058     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4059     std::string bundleName = data.ReadString();
4060     std::string deviceType;
4061     auto ret = GetCompatibleDeviceType(bundleName, deviceType);
4062     if (!reply.WriteInt32(ret)) {
4063         APP_LOGE("write failed");
4064         return ERR_APPEXECFWK_PARCEL_ERROR;
4065     }
4066     if (!reply.WriteString(deviceType)) {
4067         APP_LOGE("write failed");
4068         return ERR_APPEXECFWK_PARCEL_ERROR;
4069     }
4070     return ERR_OK;
4071 }
4072 
HandleGetOdidByBundleName(MessageParcel & data,MessageParcel & reply)4073 ErrCode BundleMgrHost::HandleGetOdidByBundleName(MessageParcel &data, MessageParcel &reply)
4074 {
4075     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4076     std::string bundleName = data.ReadString();
4077     std::string odid;
4078     auto ret = GetOdidByBundleName(bundleName, odid);
4079     if (!reply.WriteInt32(ret)) {
4080         APP_LOGE("write failed");
4081         return ERR_APPEXECFWK_PARCEL_ERROR;
4082     }
4083     if (!reply.WriteString(odid)) {
4084         APP_LOGE("write failed");
4085         return ERR_APPEXECFWK_PARCEL_ERROR;
4086     }
4087     APP_LOGD("odid is %{private}s", odid.c_str());
4088     return ERR_OK;
4089 }
4090 
HandleGetBundleInfosForContinuation(MessageParcel & data,MessageParcel & reply)4091 ErrCode BundleMgrHost::HandleGetBundleInfosForContinuation(MessageParcel &data, MessageParcel &reply)
4092 {
4093     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4094     int flags = data.ReadInt32();
4095     int userId = data.ReadInt32();
4096 
4097     std::vector<BundleInfo> infos;
4098     bool ret = GetBundleInfosForContinuation(flags, infos, userId);
4099     if (!reply.WriteBool(ret)) {
4100         APP_LOGE("write failed");
4101         return ERR_APPEXECFWK_PARCEL_ERROR;
4102     }
4103     if (ret) {
4104         reply.SetDataCapacity(MAX_CAPACITY_BUNDLES);
4105         if (!WriteVectorToParcelIntelligent(infos, reply)) {
4106             APP_LOGE("write failed");
4107             return ERR_APPEXECFWK_PARCEL_ERROR;
4108         }
4109     }
4110     return ERR_OK;
4111 }
4112 
HandleGetContinueBundleNames(MessageParcel & data,MessageParcel & reply)4113 ErrCode BundleMgrHost::HandleGetContinueBundleNames(MessageParcel &data, MessageParcel &reply)
4114 {
4115     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4116     std::string continueBundleName = data.ReadString();
4117     int userId = data.ReadInt32();
4118 
4119     std::vector<std::string> bundleNames;
4120     auto ret = GetContinueBundleNames(continueBundleName, bundleNames, userId);
4121     if (!reply.WriteInt32(ret)) {
4122         APP_LOGE("GetContinueBundleNames write failed");
4123         return ERR_APPEXECFWK_PARCEL_ERROR;
4124     }
4125     reply.SetDataCapacity(MAX_CAPACITY_BUNDLES);
4126     if (ret == ERR_OK && !reply.WriteStringVector(bundleNames)) {
4127         APP_LOGE("Write bundleNames results failed");
4128         return ERR_APPEXECFWK_PARCEL_ERROR;
4129     }
4130     return ERR_OK;
4131 }
4132 
HandleIsBundleInstalled(MessageParcel & data,MessageParcel & reply)4133 ErrCode BundleMgrHost::HandleIsBundleInstalled(MessageParcel &data, MessageParcel &reply)
4134 {
4135     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4136     std::string bundleName = data.ReadString();
4137     int32_t userId = data.ReadInt32();
4138     int32_t apppIndex = data.ReadInt32();
4139     bool isBundleInstalled = false;
4140     auto ret = IsBundleInstalled(bundleName, userId, apppIndex, isBundleInstalled);
4141     if (!reply.WriteInt32(ret)) {
4142         APP_LOGE("IsBundleInstalled write failed");
4143         return ERR_APPEXECFWK_PARCEL_ERROR;
4144     }
4145     if ((ret == ERR_OK) && !reply.WriteBool(isBundleInstalled)) {
4146         APP_LOGE("Write isInstalled result failed");
4147         return ERR_APPEXECFWK_PARCEL_ERROR;
4148     }
4149     return ERR_OK;
4150 }
4151 
HandleGetBundleNameByAppId(MessageParcel & data,MessageParcel & reply)4152 ErrCode BundleMgrHost::HandleGetBundleNameByAppId(MessageParcel &data, MessageParcel &reply)
4153 {
4154     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4155     std::string appId = data.ReadString();
4156     std::string bundleName;
4157     auto ret = GetBundleNameByAppId(appId, bundleName);
4158     if (!reply.WriteInt32(ret)) {
4159         APP_LOGE("write failed");
4160         return ERR_APPEXECFWK_PARCEL_ERROR;
4161     }
4162     if (!reply.WriteString(bundleName)) {
4163         APP_LOGE("write failed");
4164         return ERR_APPEXECFWK_PARCEL_ERROR;
4165     }
4166     return ERR_OK;
4167 }
4168 
HandleGetDirByBundleNameAndAppIndex(MessageParcel & data,MessageParcel & reply)4169 ErrCode BundleMgrHost::HandleGetDirByBundleNameAndAppIndex(MessageParcel &data, MessageParcel &reply)
4170 {
4171     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4172     std::string bundleName = data.ReadString();
4173     int32_t appIndex = data.ReadInt32();
4174     std::string dataDir;
4175     auto ret = GetDirByBundleNameAndAppIndex(bundleName, appIndex, dataDir);
4176     if (!reply.WriteInt32(ret)) {
4177         APP_LOGE("write failed");
4178         return ERR_APPEXECFWK_PARCEL_ERROR;
4179     }
4180     if (!reply.WriteString(dataDir)) {
4181         APP_LOGE("write failed");
4182         return ERR_APPEXECFWK_PARCEL_ERROR;
4183     }
4184     return ERR_OK;
4185 }
4186 
HandleGetAllBundleDirs(MessageParcel & data,MessageParcel & reply)4187 ErrCode BundleMgrHost::HandleGetAllBundleDirs(MessageParcel &data, MessageParcel &reply)
4188 {
4189     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4190     int32_t userId = data.ReadInt32();
4191     std::vector<BundleDir> bundleDirs;
4192     auto ret = GetAllBundleDirs(userId, bundleDirs);
4193     if (!reply.WriteInt32(ret)) {
4194         APP_LOGE("write failed");
4195         return ERR_APPEXECFWK_PARCEL_ERROR;
4196     }
4197     if (ret == ERR_OK) {
4198         if (!WriteVectorToParcelIntelligent(bundleDirs, reply)) {
4199             APP_LOGE("write failed");
4200             return ERR_APPEXECFWK_PARCEL_ERROR;
4201         }
4202     }
4203     return ERR_OK;
4204 }
4205 
WriteParcelableIntoAshmem(MessageParcel & tempParcel,MessageParcel & reply)4206 ErrCode BundleMgrHost::WriteParcelableIntoAshmem(MessageParcel &tempParcel, MessageParcel &reply)
4207 {
4208     size_t dataSize = tempParcel.GetDataSize();
4209     // The ashmem name must be unique.
4210     sptr<Ashmem> ashmem = Ashmem::CreateAshmem(
4211         (BUNDLE_MANAGER_ASHMEM_NAME + std::to_string(AllocatAshmemNum())).c_str(), dataSize);
4212     if (ashmem == nullptr) {
4213         APP_LOGE("Create shared memory failed");
4214         return ERR_APPEXECFWK_PARCEL_ERROR;
4215     }
4216 
4217     // Set the read/write mode of the ashme.
4218     if (!ashmem->MapReadAndWriteAshmem()) {
4219         APP_LOGE("Map shared memory fail");
4220         return ERR_APPEXECFWK_PARCEL_ERROR;
4221     }
4222     // Write the size and content of each item to the ashmem.
4223     int32_t offset = 0;
4224     if (!ashmem->WriteToAshmem(reinterpret_cast<uint8_t *>(tempParcel.GetData()), dataSize, offset)) {
4225         APP_LOGE("Write info to shared memory fail");
4226         return ERR_APPEXECFWK_PARCEL_ERROR;
4227     }
4228 
4229     if (!reply.WriteAshmem(ashmem)) {
4230         APP_LOGE("Write ashmem to tempParcel fail");
4231         return ERR_APPEXECFWK_PARCEL_ERROR;
4232     }
4233     return ERR_OK;
4234 }
4235 }  // namespace AppExecFwk
4236 }  // namespace OHOS