• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_types.h"
29 #include "json_util.h"
30 #include "string_ex.h"
31 
32 namespace OHOS {
33 namespace AppExecFwk {
34 namespace {
35 const int32_t LIMIT_PARCEL_SIZE = 1024;
36 const int32_t ASHMEM_LEN = 16;
37 constexpr size_t MAX_PARCEL_CAPACITY = 100 * 1024 * 1024; // 100M
38 
SplitString(const std::string & source,std::vector<std::string> & strings)39 void SplitString(const std::string &source, std::vector<std::string> &strings)
40 {
41     int splitSize = (source.size() / LIMIT_PARCEL_SIZE);
42     if ((source.size() % LIMIT_PARCEL_SIZE) != 0) {
43         splitSize++;
44     }
45     APP_LOGD("the dump string split into %{public}d size", splitSize);
46     for (int i = 0; i < splitSize; i++) {
47         int32_t start = LIMIT_PARCEL_SIZE * i;
48         strings.emplace_back(source.substr(start, LIMIT_PARCEL_SIZE));
49     }
50 }
51 
ClearAshmem(sptr<Ashmem> & optMem)52 inline void ClearAshmem(sptr<Ashmem> &optMem)
53 {
54     if (optMem != nullptr) {
55         optMem->UnmapAshmem();
56         optMem->CloseAshmem();
57     }
58 }
59 }  // namespace
60 
BundleMgrHost()61 BundleMgrHost::BundleMgrHost()
62 {
63     APP_LOGD("create bundle manager host ");
64     init();
65 }
66 
init()67 void BundleMgrHost::init()
68 {
69     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFO),
70         &BundleMgrHost::HandleGetApplicationInfo);
71     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFO_WITH_INT_FLAGS),
72         &BundleMgrHost::HandleGetApplicationInfoWithIntFlags);
73     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFOS),
74         &BundleMgrHost::HandleGetApplicationInfos);
75     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFO_WITH_INT_FLAGS_V9),
76         &BundleMgrHost::HandleGetApplicationInfoWithIntFlagsV9);
77     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFOS_WITH_INT_FLAGS),
78         &BundleMgrHost::HandleGetApplicationInfosWithIntFlags);
79     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_INFOS_WITH_INT_FLAGS_V9),
80         &BundleMgrHost::HandleGetApplicationInfosWithIntFlagsV9);
81     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFO),
82         &BundleMgrHost::HandleGetBundleInfo);
83     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFO_WITH_INT_FLAGS),
84         &BundleMgrHost::HandleGetBundleInfoWithIntFlags);
85     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFO_WITH_INT_FLAGS_V9),
86         &BundleMgrHost::HandleGetBundleInfoWithIntFlagsV9);
87     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_PACK_INFO),
88         &BundleMgrHost::HandleGetBundlePackInfo);
89     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_PACK_INFO_WITH_INT_FLAGS),
90         &BundleMgrHost::HandleGetBundlePackInfoWithIntFlags);
91     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFOS),
92         &BundleMgrHost::HandleGetBundleInfos);
93     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFOS_WITH_INT_FLAGS),
94         &BundleMgrHost::HandleGetBundleInfosWithIntFlags);
95     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFOS_WITH_INT_FLAGS_V9),
96         &BundleMgrHost::HandleGetBundleInfosWithIntFlagsV9);
97     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_NAME_FOR_UID),
98         &BundleMgrHost::HandleGetBundleNameForUid);
99     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLES_FOR_UID),
100         &BundleMgrHost::HandleGetBundlesForUid);
101     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_NAME_FOR_UID),
102         &BundleMgrHost::HandleGetNameForUid);
103     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_GIDS),
104         &BundleMgrHost::HandleGetBundleGids);
105     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_GIDS_BY_UID),
106         &BundleMgrHost::HandleGetBundleGidsByUid);
107     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFOS_BY_METADATA),
108         &BundleMgrHost::HandleGetBundleInfosByMetaData);
109     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO),
110         &BundleMgrHost::HandleQueryAbilityInfo);
111     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_MUTI_PARAM),
112         &BundleMgrHost::HandleQueryAbilityInfoMutiparam);
113     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFOS),
114         &BundleMgrHost::HandleQueryAbilityInfos);
115     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFOS_MUTI_PARAM),
116         &BundleMgrHost::HandleQueryAbilityInfosMutiparam);
117     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFOS_V9),
118         &BundleMgrHost::HandleQueryAbilityInfosV9);
119     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_LAUNCHER_ABILITY_INFO),
120         &BundleMgrHost::HandleQueryLauncherAbilityInfos);
121     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ALL_ABILITY_INFOS),
122         &BundleMgrHost::HandleQueryAllAbilityInfos);
123     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_BY_URI),
124         &BundleMgrHost::HandleQueryAbilityInfoByUri);
125     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFOS_BY_URI),
126         &BundleMgrHost::HandleQueryAbilityInfosByUri);
127     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_BY_URI_FOR_USERID),
128         &BundleMgrHost::HandleQueryAbilityInfoByUriForUserId);
129     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_KEEPALIVE_BUNDLE_INFOS),
130         &BundleMgrHost::HandleQueryKeepAliveBundleInfos);
131     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ABILITY_LABEL),
132         &BundleMgrHost::HandleGetAbilityLabel);
133     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ABILITY_LABEL_WITH_MODULE_NAME),
134         &BundleMgrHost::HandleGetAbilityLabelWithModuleName);
135     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::CHECK_IS_SYSTEM_APP_BY_UID),
136         &BundleMgrHost::HandleCheckIsSystemAppByUid);
137     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO),
138         &BundleMgrHost::HandleGetBundleArchiveInfo);
139     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO_WITH_INT_FLAGS),
140         &BundleMgrHost::HandleGetBundleArchiveInfoWithIntFlags);
141     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO_WITH_INT_FLAGS_V9),
142         &BundleMgrHost::HandleGetBundleArchiveInfoWithIntFlagsV9);
143     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_HAP_MODULE_INFO),
144         &BundleMgrHost::HandleGetHapModuleInfo);
145     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_LAUNCH_WANT_FOR_BUNDLE),
146         &BundleMgrHost::HandleGetLaunchWantForBundle);
147     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_PERMISSION_DEF),
148         &BundleMgrHost::HandleGetPermissionDef);
149     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::CLEAN_BUNDLE_CACHE_FILES),
150         &BundleMgrHost::HandleCleanBundleCacheFiles);
151     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::CREATE_BUNDLE_DATA_DIR),
152         &BundleMgrHost::HandleCreateBundleDataDir);
153     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::CLEAN_BUNDLE_DATA_FILES),
154         &BundleMgrHost::HandleCleanBundleDataFiles);
155     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::REGISTER_BUNDLE_STATUS_CALLBACK),
156         &BundleMgrHost::HandleRegisterBundleStatusCallback);
157     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::REGISTER_BUNDLE_EVENT_CALLBACK),
158         &BundleMgrHost::HandleRegisterBundleEventCallback);
159     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::UNREGISTER_BUNDLE_EVENT_CALLBACK),
160         &BundleMgrHost::HandleUnregisterBundleEventCallback);
161     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::CLEAR_BUNDLE_STATUS_CALLBACK),
162         &BundleMgrHost::HandleClearBundleStatusCallback);
163     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::UNREGISTER_BUNDLE_STATUS_CALLBACK),
164         &BundleMgrHost::HandleUnregisterBundleStatusCallback);
165     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::IS_APPLICATION_ENABLED),
166         &BundleMgrHost::HandleIsApplicationEnabled);
167     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::SET_APPLICATION_ENABLED),
168         &BundleMgrHost::HandleSetApplicationEnabled);
169     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::IS_ABILITY_ENABLED),
170         &BundleMgrHost::HandleIsAbilityEnabled);
171     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::SET_ABILITY_ENABLED),
172         &BundleMgrHost::HandleSetAbilityEnabled);
173     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ABILITY_INFO),
174         &BundleMgrHost::HandleGetAbilityInfo);
175     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ABILITY_INFO_WITH_MODULE_NAME),
176         &BundleMgrHost::HandleGetAbilityInfoWithModuleName);
177     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::DUMP_INFOS),
178         &BundleMgrHost::HandleDumpInfos);
179     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INSTALLER),
180         &BundleMgrHost::HandleGetBundleInstaller);
181     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_FORMS_INFO),
182         &BundleMgrHost::HandleGetAllFormsInfo);
183     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_FORMS_INFO_BY_APP),
184         &BundleMgrHost::HandleGetFormsInfoByApp);
185     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_FORMS_INFO_BY_MODULE),
186         &BundleMgrHost::HandleGetFormsInfoByModule);
187     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SHORTCUT_INFO),
188         &BundleMgrHost::HandleGetShortcutInfos);
189     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SHORTCUT_INFO_V9),
190         &BundleMgrHost::HandleGetShortcutInfoV9);
191     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_COMMON_EVENT_INFO),
192         &BundleMgrHost::HandleGetAllCommonEventInfo);
193     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_USER_MGR),
194         &BundleMgrHost::HandleGetBundleUserMgr);
195     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_DISTRIBUTE_BUNDLE_INFO),
196         &BundleMgrHost::HandleGetDistributedBundleInfo);
197     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPLICATION_PRIVILEGE_LEVEL),
198         &BundleMgrHost::HandleGetAppPrivilegeLevel);
199     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_WITHOUT_TYPE),
200         &BundleMgrHost::HandleQueryExtAbilityInfosWithoutType);
201     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_WITHOUT_TYPE_V9),
202         &BundleMgrHost::HandleQueryExtAbilityInfosWithoutTypeV9);
203     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO),
204         &BundleMgrHost::HandleQueryExtAbilityInfos);
205     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_V9),
206         &BundleMgrHost::HandleQueryExtAbilityInfosV9);
207     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_BY_TYPE),
208         &BundleMgrHost::HandleQueryExtAbilityInfosByType);
209     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::VERIFY_CALLING_PERMISSION),
210         &BundleMgrHost::HandleVerifyCallingPermission);
211     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_ABILITY_INFO_BY_URI),
212         &BundleMgrHost::HandleQueryExtensionAbilityInfoByUri);
213     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APPID_BY_BUNDLE_NAME),
214         &BundleMgrHost::HandleGetAppIdByBundleName);
215     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APP_TYPE),
216         &BundleMgrHost::HandleGetAppType);
217     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_UID_BY_BUNDLE_NAME),
218         &BundleMgrHost::HandleGetUidByBundleName);
219     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::IS_MODULE_REMOVABLE),
220         &BundleMgrHost::HandleIsModuleRemovable);
221     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::SET_MODULE_REMOVABLE),
222         &BundleMgrHost::HandleSetModuleRemovable);
223     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_WITH_CALLBACK),
224         &BundleMgrHost::HandleQueryAbilityInfoWithCallback);
225     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::UPGRADE_ATOMIC_SERVICE),
226         &BundleMgrHost::HandleUpgradeAtomicService);
227     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::IS_MODULE_NEED_UPDATE),
228         &BundleMgrHost::HandleGetModuleUpgradeFlag);
229     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::SET_MODULE_NEED_UPDATE),
230         &BundleMgrHost::HandleSetModuleUpgradeFlag);
231     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_HAP_MODULE_INFO_WITH_USERID),
232         &BundleMgrHost::HandleGetHapModuleInfoWithUserId);
233     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::IMPLICIT_QUERY_INFO_BY_PRIORITY),
234         &BundleMgrHost::HandleImplicitQueryInfoByPriority);
235     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::IMPLICIT_QUERY_INFOS),
236         &BundleMgrHost::HandleImplicitQueryInfos);
237     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_DEPENDENT_MODULE_NAMES),
238         &BundleMgrHost::HandleGetAllDependentModuleNames);
239     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SANDBOX_APP_BUNDLE_INFO),
240         &BundleMgrHost::HandleGetSandboxBundleInfo);
241     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_CALLING_BUNDLE_NAME),
242         &BundleMgrHost::HandleObtainCallingBundleName);
243     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_STATS),
244         &BundleMgrHost::HandleGetBundleStats);
245     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_BUNDLE_STATS),
246         &BundleMgrHost::HandleGetAllBundleStats);
247     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::CHECK_ABILITY_ENABLE_INSTALL),
248         &BundleMgrHost::HandleCheckAbilityEnableInstall);
249     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_STRING_BY_ID),
250         &BundleMgrHost::HandleGetStringById);
251     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ICON_BY_ID),
252         &BundleMgrHost::HandleGetIconById);
253 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
254     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_DEFAULT_APP_PROXY),
255         &BundleMgrHost::HandleGetDefaultAppProxy);
256 #endif
257     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SANDBOX_APP_ABILITY_INFO),
258         &BundleMgrHost::HandleGetSandboxAbilityInfo);
259     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SANDBOX_APP_EXTENSION_INFOS),
260         &BundleMgrHost::HandleGetSandboxExtAbilityInfos);
261     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SANDBOX_MODULE_INFO),
262         &BundleMgrHost::HandleGetSandboxHapModuleInfo);
263     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_MEDIA_DATA),
264         &BundleMgrHost::HandleGetMediaData);
265     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_QUICK_FIX_MANAGER_PROXY),
266         &BundleMgrHost::HandleGetQuickFixManagerProxy);
267 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
268     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APP_CONTROL_PROXY),
269         &BundleMgrHost::HandleGetAppControlProxy);
270 #endif
271     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::SET_DEBUG_MODE),
272         &BundleMgrHost::HandleSetDebugMode);
273     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_INFO_FOR_SELF),
274         &BundleMgrHost::HandleGetBundleInfoForSelf);
275     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::VERIFY_SYSTEM_API),
276         &BundleMgrHost::HandleVerifySystemApi);
277     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY),
278         &BundleMgrHost::HandleGetOverlayManagerProxy);
279     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::SILENT_INSTALL),
280         &BundleMgrHost::HandleSilentInstall);
281     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::PROCESS_PRELOAD),
282         &BundleMgrHost::HandleProcessPreload);
283     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_APP_PROVISION_INFO),
284         &BundleMgrHost::HandleGetAppProvisionInfo);
285     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_PROVISION_METADATA),
286         &BundleMgrHost::HandleGetProvisionMetadata);
287     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BASE_SHARED_BUNDLE_INFOS),
288         &BundleMgrHost::HandleGetBaseSharedBundleInfos);
289     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_SHARED_BUNDLE_INFO),
290         &BundleMgrHost::HandleGetAllSharedBundleInfo);
291     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SHARED_BUNDLE_INFO),
292         &BundleMgrHost::HandleGetSharedBundleInfo);
293     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SHARED_BUNDLE_INFO_BY_SELF),
294         &BundleMgrHost::HandleGetSharedBundleInfoBySelf);
295     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SHARED_DEPENDENCIES),
296         &BundleMgrHost::HandleGetSharedDependencies);
297     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_DEPENDENT_BUNDLE_INFO),
298         &BundleMgrHost::HandleGetDependentBundleInfo);
299     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_UID_BY_DEBUG_BUNDLE_NAME),
300         &BundleMgrHost::HandleGetUidByDebugBundleName);
301     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_PROXY_DATA_INFOS),
302         &BundleMgrHost::HandleGetProxyDataInfos);
303     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ALL_PROXY_DATA_INFOS),
304         &BundleMgrHost::HandleGetAllProxyDataInfos);
305     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_SPECIFIED_DISTRIBUTED_TYPE),
306         &BundleMgrHost::HandleGetSpecifiedDistributionType);
307     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_ADDITIONAL_INFO),
308         &BundleMgrHost::HandleGetAdditionalInfo);
309     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::SET_EXT_NAME_OR_MIME_TO_APP),
310         &BundleMgrHost::HandleSetExtNameOrMIMEToApp);
311     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::DEL_EXT_NAME_OR_MIME_TO_APP),
312         &BundleMgrHost::HandleDelExtNameOrMIMEToApp);
313     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_DATA_GROUP_INFOS),
314         &BundleMgrHost::HandleQueryDataGroupInfos);
315     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_PREFERENCE_DIR_BY_GROUP_ID),
316         &BundleMgrHost::HandleGetPreferenceDirByGroupId);
317     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_APPGALLERY_BUNDLE_NAME),
318         &BundleMgrHost::HandleQueryAppGalleryBundleName);
319     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_ABILITY_INFO_WITH_TYPE_NAME),
320         &BundleMgrHost::HandleQueryExtensionAbilityInfosWithTypeName);
321     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::QUERY_EXTENSION_ABILITY_INFO_ONLY_WITH_TYPE_NAME),
322         &BundleMgrHost::HandleQueryExtensionAbilityInfosOnlyWithTypeName);
323     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::RESET_AOT_COMPILE_STATUS),
324         &BundleMgrHost::HandleResetAOTCompileStatus);
325     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_JSON_PROFILE),
326         &BundleMgrHost::HandleGetJsonProfile);
327     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_BUNDLE_RESOURCE_PROXY),
328         &BundleMgrHost::HandleGetBundleResourceProxy);
329     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_VERIFY_MANAGER),
330         &BundleMgrHost::HandleGetVerifyManager);
331     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_RECOVERABLE_APPLICATION_INFO),
332         &BundleMgrHost::HandleGetRecoverableApplicationInfo);
333     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::GET_UNINSTALLED_BUNDLE_INFO),
334         &BundleMgrHost::HandleGetUninstalledBundleInfo);
335     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::SET_ADDITIONAL_INFO),
336         &BundleMgrHost::HandleSetAdditionalInfo);
337     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::COMPILE_PROCESSAOT),
338         &BundleMgrHost::HandleCompileProcessAOT);
339     funcMap_.emplace(static_cast<uint32_t>(BundleMgrInterfaceCode::COMPILE_RESET),
340         &BundleMgrHost::HandleCompileReset);
341 }
342 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)343 int BundleMgrHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
344 {
345     BundleMemoryGuard memoryGuard;
346     APP_LOGD("bundle mgr host onReceived message, the message code is %{public}u", code);
347     std::u16string descriptor = BundleMgrHost::GetDescriptor();
348     std::u16string remoteDescriptor = data.ReadInterfaceToken();
349     if (descriptor != remoteDescriptor) {
350         APP_LOGE("fail to write reply message in bundle mgr host due to the reply is nullptr");
351         return OBJECT_NULL;
352     }
353 
354     ErrCode errCode = ERR_OK;
355     if (funcMap_.find(code) != funcMap_.end() && funcMap_[code] != nullptr) {
356         errCode = (this->*funcMap_[code])(data, reply);
357     } else {
358         APP_LOGW("bundleMgr host receives unknown code, code = %{public}u", code);
359         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
360     }
361     APP_LOGD("bundleMgr host finish to process message, errCode: %{public}d", errCode);
362     return (errCode == ERR_OK) ? NO_ERROR : UNKNOWN_ERROR;
363 }
364 
HandleGetApplicationInfo(MessageParcel & data,MessageParcel & reply)365 ErrCode BundleMgrHost::HandleGetApplicationInfo(MessageParcel &data, MessageParcel &reply)
366 {
367     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
368     std::string name = data.ReadString();
369     ApplicationFlag flag = static_cast<ApplicationFlag>(data.ReadInt32());
370     int userId = data.ReadInt32();
371     APP_LOGD("name %{public}s, flag %{public}d, userId %{public}d", name.c_str(), flag, userId);
372 
373     ApplicationInfo info;
374     bool ret = GetApplicationInfo(name, flag, userId, info);
375     if (!reply.WriteBool(ret)) {
376         APP_LOGE("write failed");
377         return ERR_APPEXECFWK_PARCEL_ERROR;
378     }
379     if (ret) {
380         if (!reply.WriteParcelable(&info)) {
381             APP_LOGE("write failed");
382             return ERR_APPEXECFWK_PARCEL_ERROR;
383         }
384     }
385     return ERR_OK;
386 }
387 
HandleGetApplicationInfoWithIntFlags(MessageParcel & data,MessageParcel & reply)388 ErrCode BundleMgrHost::HandleGetApplicationInfoWithIntFlags(MessageParcel &data, MessageParcel &reply)
389 {
390     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
391     std::string name = data.ReadString();
392     int flags = data.ReadInt32();
393     int userId = data.ReadInt32();
394     APP_LOGD("name %{public}s, flags %{public}d, userId %{public}d", name.c_str(), flags, userId);
395 
396     ApplicationInfo info;
397     bool ret = GetApplicationInfo(name, flags, userId, info);
398     if (!reply.WriteBool(ret)) {
399         APP_LOGE("write failed");
400         return ERR_APPEXECFWK_PARCEL_ERROR;
401     }
402     if (ret) {
403         if (!reply.WriteParcelable(&info)) {
404             APP_LOGE("write failed");
405             return ERR_APPEXECFWK_PARCEL_ERROR;
406         }
407     }
408     return ERR_OK;
409 }
410 
HandleGetApplicationInfoWithIntFlagsV9(MessageParcel & data,MessageParcel & reply)411 ErrCode BundleMgrHost::HandleGetApplicationInfoWithIntFlagsV9(MessageParcel &data, MessageParcel &reply)
412 {
413     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
414     std::string name = data.ReadString();
415     int32_t flags = data.ReadInt32();
416     int32_t userId = data.ReadInt32();
417     APP_LOGD("name %{public}s, flags %{public}d, userId %{public}d", name.c_str(), flags, userId);
418 
419     ApplicationInfo info;
420     auto ret = GetApplicationInfoV9(name, flags, userId, info);
421     if (!reply.WriteInt32(ret)) {
422         APP_LOGE("write failed");
423         return ERR_APPEXECFWK_PARCEL_ERROR;
424     }
425     if (ret == ERR_OK) {
426         if (!reply.WriteParcelable(&info)) {
427             APP_LOGE("write failed");
428             return ERR_APPEXECFWK_PARCEL_ERROR;
429         }
430     }
431     return ERR_OK;
432 }
433 
HandleGetApplicationInfos(MessageParcel & data,MessageParcel & reply)434 ErrCode BundleMgrHost::HandleGetApplicationInfos(MessageParcel &data, MessageParcel &reply)
435 {
436     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
437     ApplicationFlag flag = static_cast<ApplicationFlag>(data.ReadInt32());
438     int userId = data.ReadInt32();
439     std::vector<ApplicationInfo> infos;
440     bool ret = GetApplicationInfos(flag, userId, infos);
441     if (!reply.WriteBool(ret)) {
442         APP_LOGE("write failed");
443         return ERR_APPEXECFWK_PARCEL_ERROR;
444     }
445     if (ret) {
446         if (!WriteParcelableVector(infos, reply)) {
447             APP_LOGE("write failed");
448             return ERR_APPEXECFWK_PARCEL_ERROR;
449         }
450     }
451     return ERR_OK;
452 }
453 
HandleGetApplicationInfosWithIntFlags(MessageParcel & data,MessageParcel & reply)454 ErrCode BundleMgrHost::HandleGetApplicationInfosWithIntFlags(MessageParcel &data, MessageParcel &reply)
455 {
456     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
457     int flags = data.ReadInt32();
458     int userId = data.ReadInt32();
459     std::vector<ApplicationInfo> infos;
460     bool ret = GetApplicationInfos(flags, userId, infos);
461     if (!reply.WriteBool(ret)) {
462         APP_LOGE("write failed");
463         return ERR_APPEXECFWK_PARCEL_ERROR;
464     }
465     if (ret) {
466         if (!WriteVectorToParcelIntelligent(infos, reply)) {
467             APP_LOGE("write failed");
468             return ERR_APPEXECFWK_PARCEL_ERROR;
469         }
470     }
471     return ERR_OK;
472 }
473 
HandleGetApplicationInfosWithIntFlagsV9(MessageParcel & data,MessageParcel & reply)474 ErrCode BundleMgrHost::HandleGetApplicationInfosWithIntFlagsV9(MessageParcel &data, MessageParcel &reply)
475 {
476     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
477     int32_t flags = data.ReadInt32();
478     int32_t userId = data.ReadInt32();
479     std::vector<ApplicationInfo> infos;
480     auto ret = GetApplicationInfosV9(flags, userId, infos);
481     if (!reply.WriteInt32(ret)) {
482         APP_LOGE("write failed");
483         return ERR_APPEXECFWK_PARCEL_ERROR;
484     }
485     if (ret == ERR_OK) {
486         if (!WriteVectorToParcelIntelligent(infos, reply)) {
487             APP_LOGE("write failed");
488             return ERR_APPEXECFWK_PARCEL_ERROR;
489         }
490     }
491     return ERR_OK;
492 }
493 
HandleGetBundleInfo(MessageParcel & data,MessageParcel & reply)494 ErrCode BundleMgrHost::HandleGetBundleInfo(MessageParcel &data, MessageParcel &reply)
495 {
496     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
497     std::string name = data.ReadString();
498     BundleFlag flag = static_cast<BundleFlag>(data.ReadInt32());
499     int userId = data.ReadInt32();
500     APP_LOGD("name %{public}s, flag %{public}d", name.c_str(), flag);
501     BundleInfo info;
502     bool ret = GetBundleInfo(name, flag, info, userId);
503     if (ret) {
504         WRITE_PARCEL(reply.WriteInt32(ERR_OK));
505         return WriteParcelInfoIntelligent(info, reply);
506     }
507     WRITE_PARCEL(reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR));
508     return ERR_OK;
509 }
510 
HandleGetBundleInfoForSelf(MessageParcel & data,MessageParcel & reply)511 ErrCode BundleMgrHost::HandleGetBundleInfoForSelf(MessageParcel &data, MessageParcel &reply)
512 {
513     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
514     int32_t flags = data.ReadInt32();
515     APP_LOGD("GetBundleInfoForSelf, flags %{public}d", flags);
516     BundleInfo info;
517     reply.SetDataCapacity(Constants::CAPACITY_SIZE);
518     auto ret = GetBundleInfoForSelf(flags, info);
519     if (!reply.WriteInt32(ret)) {
520         APP_LOGE("write failed");
521         return ERR_APPEXECFWK_PARCEL_ERROR;
522     }
523     if (ret == ERR_OK && !reply.WriteParcelable(&info)) {
524         APP_LOGE("write failed");
525         return ERR_APPEXECFWK_PARCEL_ERROR;
526     }
527     return ERR_OK;
528 }
529 
HandleGetDependentBundleInfo(MessageParcel & data,MessageParcel & reply)530 ErrCode BundleMgrHost::HandleGetDependentBundleInfo(MessageParcel &data, MessageParcel &reply)
531 {
532     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
533     std::string name = data.ReadString();
534     GetDependentBundleInfoFlag flag = static_cast<GetDependentBundleInfoFlag>(data.ReadUint32());
535     APP_LOGD("GetDependentBundleInfo, bundle %{public}s", name.c_str());
536     BundleInfo info;
537     reply.SetDataCapacity(Constants::CAPACITY_SIZE);
538     auto ret = GetDependentBundleInfo(name, info, flag);
539     if (!reply.WriteInt32(ret)) {
540         APP_LOGE("write failed");
541         return ERR_APPEXECFWK_PARCEL_ERROR;
542     }
543     if (ret == ERR_OK && !reply.WriteParcelable(&info)) {
544         APP_LOGE("write failed");
545         return ERR_APPEXECFWK_PARCEL_ERROR;
546     }
547     return ERR_OK;
548 }
549 
HandleGetBundleInfoWithIntFlags(MessageParcel & data,MessageParcel & reply)550 ErrCode BundleMgrHost::HandleGetBundleInfoWithIntFlags(MessageParcel &data, MessageParcel &reply)
551 {
552     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
553     std::string name = data.ReadString();
554     int flags = data.ReadInt32();
555     int userId = data.ReadInt32();
556     APP_LOGD("name %{public}s, flags %{public}d", name.c_str(), flags);
557     BundleInfo info;
558     reply.SetDataCapacity(Constants::CAPACITY_SIZE);
559     bool ret = GetBundleInfo(name, flags, info, userId);
560     if (ret) {
561         WRITE_PARCEL(reply.WriteInt32(ERR_OK));
562         return WriteParcelInfoIntelligent(info, reply);
563     }
564     WRITE_PARCEL(reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR));
565     return ERR_OK;
566 }
567 
HandleGetBundleInfoWithIntFlagsV9(MessageParcel & data,MessageParcel & reply)568 ErrCode BundleMgrHost::HandleGetBundleInfoWithIntFlagsV9(MessageParcel &data, MessageParcel &reply)
569 {
570     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
571     std::string name = data.ReadString();
572     if (name.empty()) {
573         APP_LOGE("bundleName is empty");
574         return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
575     }
576     int32_t flags = data.ReadInt32();
577     int32_t userId = data.ReadInt32();
578     APP_LOGD("name %{public}s, flags %{public}d", name.c_str(), flags);
579     BundleInfo info;
580     reply.SetDataCapacity(Constants::CAPACITY_SIZE);
581     auto ret = GetBundleInfoV9(name, flags, info, userId);
582     if (!reply.WriteInt32(ret)) {
583         APP_LOGE("write failed");
584         return ERR_APPEXECFWK_PARCEL_ERROR;
585     }
586     if (ret == ERR_OK) {
587         return WriteParcelInfoIntelligent<BundleInfo>(info, reply);
588     }
589     return ERR_OK;
590 }
591 
HandleGetBundlePackInfo(MessageParcel & data,MessageParcel & reply)592 ErrCode BundleMgrHost::HandleGetBundlePackInfo(MessageParcel &data, MessageParcel &reply)
593 {
594     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
595     std::string name = data.ReadString();
596     BundlePackFlag flag = static_cast<BundlePackFlag>(data.ReadInt32());
597     int userId = data.ReadInt32();
598     APP_LOGD("name %{public}s, flag %{public}d", name.c_str(), flag);
599     BundlePackInfo info;
600     ErrCode ret = GetBundlePackInfo(name, flag, info, userId);
601     if (!reply.WriteInt32(ret)) {
602         APP_LOGE("write failed");
603         return ERR_APPEXECFWK_PARCEL_ERROR;
604     }
605     if (ret == ERR_OK) {
606         if (!reply.WriteParcelable(&info)) {
607             APP_LOGE("write failed");
608             return ERR_APPEXECFWK_PARCEL_ERROR;
609         }
610     }
611     return ERR_OK;
612 }
613 
HandleGetBundlePackInfoWithIntFlags(MessageParcel & data,MessageParcel & reply)614 ErrCode BundleMgrHost::HandleGetBundlePackInfoWithIntFlags(MessageParcel &data, MessageParcel &reply)
615 {
616     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
617     std::string name = data.ReadString();
618     int flags = data.ReadInt32();
619     int userId = data.ReadInt32();
620     APP_LOGD("name %{public}s, flags %{public}d", name.c_str(), flags);
621     BundlePackInfo info;
622     ErrCode ret = GetBundlePackInfo(name, flags, info, userId);
623     if (!reply.WriteInt32(ret)) {
624         APP_LOGE("write failed");
625         return ERR_APPEXECFWK_PARCEL_ERROR;
626     }
627     if (ret == ERR_OK) {
628         if (!reply.WriteParcelable(&info)) {
629             APP_LOGE("write failed");
630             return ERR_APPEXECFWK_PARCEL_ERROR;
631         }
632     }
633     return ERR_OK;
634 }
635 
HandleGetBundleInfos(MessageParcel & data,MessageParcel & reply)636 ErrCode BundleMgrHost::HandleGetBundleInfos(MessageParcel &data, MessageParcel &reply)
637 {
638     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
639     BundleFlag flag = static_cast<BundleFlag>(data.ReadInt32());
640     int userId = data.ReadInt32();
641 
642     std::vector<BundleInfo> infos;
643     reply.SetDataCapacity(Constants::MAX_CAPACITY_BUNDLES);
644     bool ret = GetBundleInfos(flag, infos, userId);
645     if (!reply.WriteBool(ret)) {
646         APP_LOGE("write failed");
647         return ERR_APPEXECFWK_PARCEL_ERROR;
648     }
649     if (ret) {
650         if (!WriteVectorToParcelIntelligent(infos, reply)) {
651             APP_LOGE("write failed");
652             return ERR_APPEXECFWK_PARCEL_ERROR;
653         }
654     }
655     return ERR_OK;
656 }
657 
HandleGetBundleInfosWithIntFlags(MessageParcel & data,MessageParcel & reply)658 ErrCode BundleMgrHost::HandleGetBundleInfosWithIntFlags(MessageParcel &data, MessageParcel &reply)
659 {
660     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
661     int flags = data.ReadInt32();
662     int userId = data.ReadInt32();
663 
664     std::vector<BundleInfo> infos;
665     reply.SetDataCapacity(Constants::MAX_CAPACITY_BUNDLES);
666     bool ret = GetBundleInfos(flags, infos, userId);
667     if (!reply.WriteBool(ret)) {
668         APP_LOGE("write failed");
669         return ERR_APPEXECFWK_PARCEL_ERROR;
670     }
671     if (ret) {
672         if (!WriteVectorToParcelIntelligent(infos, reply)) {
673             APP_LOGE("write failed");
674             return ERR_APPEXECFWK_PARCEL_ERROR;
675         }
676     }
677     return ERR_OK;
678 }
679 
HandleGetBundleInfosWithIntFlagsV9(MessageParcel & data,MessageParcel & reply)680 ErrCode BundleMgrHost::HandleGetBundleInfosWithIntFlagsV9(MessageParcel &data, MessageParcel &reply)
681 {
682     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
683     int32_t flags = data.ReadInt32();
684     int32_t userId = data.ReadInt32();
685 
686     std::vector<BundleInfo> infos;
687     auto ret = GetBundleInfosV9(flags, infos, userId);
688     if (!reply.WriteInt32(ret)) {
689         APP_LOGE("write failed");
690         return ERR_APPEXECFWK_PARCEL_ERROR;
691     }
692     if (ret == ERR_OK) {
693         if (!WriteVectorToParcelIntelligent(infos, reply)) {
694             APP_LOGE("write failed");
695             return ERR_APPEXECFWK_PARCEL_ERROR;
696         }
697     }
698     return ERR_OK;
699 }
700 
HandleGetBundleNameForUid(MessageParcel & data,MessageParcel & reply)701 ErrCode BundleMgrHost::HandleGetBundleNameForUid(MessageParcel &data, MessageParcel &reply)
702 {
703     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
704     auto uid = data.ReadInt32();
705     std::string name;
706     bool ret = GetBundleNameForUid(uid, name);
707     if (!reply.WriteBool(ret)) {
708         APP_LOGE("write failed");
709         return ERR_APPEXECFWK_PARCEL_ERROR;
710     }
711     if (ret) {
712         if (!reply.WriteString(name)) {
713             APP_LOGE("write failed");
714             return ERR_APPEXECFWK_PARCEL_ERROR;
715         }
716     }
717     return ERR_OK;
718 }
719 
HandleGetBundlesForUid(MessageParcel & data,MessageParcel & reply)720 ErrCode BundleMgrHost::HandleGetBundlesForUid(MessageParcel &data, MessageParcel &reply)
721 {
722     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
723     int uid = data.ReadInt32();
724     std::vector<std::string> names;
725     bool ret = GetBundlesForUid(uid, names);
726     if (!reply.WriteBool(ret)) {
727         APP_LOGE("write failed");
728         return ERR_APPEXECFWK_PARCEL_ERROR;
729     }
730     if (ret) {
731         if (!reply.WriteStringVector(names)) {
732             APP_LOGE("write failed");
733             return ERR_APPEXECFWK_PARCEL_ERROR;
734         }
735     }
736     return ERR_OK;
737 }
738 
HandleGetNameForUid(MessageParcel & data,MessageParcel & reply)739 ErrCode BundleMgrHost::HandleGetNameForUid(MessageParcel &data, MessageParcel &reply)
740 {
741     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
742     int uid = data.ReadInt32();
743     std::string name;
744     ErrCode ret = GetNameForUid(uid, name);
745     if (!reply.WriteInt32(ret)) {
746         APP_LOGE("write failed");
747         return ERR_APPEXECFWK_PARCEL_ERROR;
748     }
749     if (ret == ERR_OK) {
750         if (!reply.WriteString(name)) {
751             APP_LOGE("write failed");
752             return ERR_APPEXECFWK_PARCEL_ERROR;
753         }
754     }
755     return ERR_OK;
756 }
757 
HandleGetBundleGids(MessageParcel & data,MessageParcel & reply)758 ErrCode BundleMgrHost::HandleGetBundleGids(MessageParcel &data, MessageParcel &reply)
759 {
760     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
761     std::string name = data.ReadString();
762 
763     std::vector<int> gids;
764     bool ret = GetBundleGids(name, gids);
765     if (!reply.WriteBool(ret)) {
766         APP_LOGE("write failed");
767         return ERR_APPEXECFWK_PARCEL_ERROR;
768     }
769     if (ret) {
770         if (!reply.WriteInt32Vector(gids)) {
771             APP_LOGE("write failed");
772             return ERR_APPEXECFWK_PARCEL_ERROR;
773         }
774     }
775     return ERR_OK;
776 }
777 
HandleGetBundleGidsByUid(MessageParcel & data,MessageParcel & reply)778 ErrCode BundleMgrHost::HandleGetBundleGidsByUid(MessageParcel &data, MessageParcel &reply)
779 {
780     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
781     std::string name = data.ReadString();
782     int uid = data.ReadInt32();
783 
784     std::vector<int> gids;
785     bool ret = GetBundleGidsByUid(name, uid, gids);
786     if (!reply.WriteBool(ret)) {
787         APP_LOGE("write failed");
788         return ERR_APPEXECFWK_PARCEL_ERROR;
789     }
790     if (ret) {
791         if (!reply.WriteInt32Vector(gids)) {
792             APP_LOGE("write failed");
793             return ERR_APPEXECFWK_PARCEL_ERROR;
794         }
795     }
796     return ERR_OK;
797 }
798 
HandleGetBundleInfosByMetaData(MessageParcel & data,MessageParcel & reply)799 ErrCode BundleMgrHost::HandleGetBundleInfosByMetaData(MessageParcel &data, MessageParcel &reply)
800 {
801     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
802     std::string metaData = data.ReadString();
803 
804     std::vector<BundleInfo> infos;
805     bool ret = GetBundleInfosByMetaData(metaData, infos);
806     if (!reply.WriteBool(ret)) {
807         APP_LOGE("write failed");
808         return ERR_APPEXECFWK_PARCEL_ERROR;
809     }
810     if (ret) {
811         if (!WriteParcelableVector(infos, reply)) {
812             APP_LOGE("write failed");
813             return ERR_APPEXECFWK_PARCEL_ERROR;
814         }
815     }
816     return ERR_OK;
817 }
818 
HandleQueryAbilityInfo(MessageParcel & data,MessageParcel & reply)819 ErrCode BundleMgrHost::HandleQueryAbilityInfo(MessageParcel &data, MessageParcel &reply)
820 {
821     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
822     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
823     if (want == nullptr) {
824         APP_LOGE("ReadParcelable<want> failed");
825         return ERR_APPEXECFWK_PARCEL_ERROR;
826     }
827 
828     AbilityInfo info;
829     bool ret = QueryAbilityInfo(*want, info);
830     if (!reply.WriteBool(ret)) {
831         APP_LOGE("write failed");
832         return ERR_APPEXECFWK_PARCEL_ERROR;
833     }
834     if (ret) {
835         if (!reply.WriteParcelable(&info)) {
836             APP_LOGE("write failed");
837             return ERR_APPEXECFWK_PARCEL_ERROR;
838         }
839     }
840     return ERR_OK;
841 }
842 
HandleQueryAbilityInfoMutiparam(MessageParcel & data,MessageParcel & reply)843 ErrCode BundleMgrHost::HandleQueryAbilityInfoMutiparam(MessageParcel &data, MessageParcel &reply)
844 {
845     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
846     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
847     if (want == nullptr) {
848         APP_LOGE("ReadParcelable<want> failed");
849         return ERR_APPEXECFWK_PARCEL_ERROR;
850     }
851     int32_t flags = data.ReadInt32();
852     int32_t userId = data.ReadInt32();
853     AbilityInfo info;
854     bool ret = QueryAbilityInfo(*want, flags, userId, info);
855     if (!reply.WriteBool(ret)) {
856         APP_LOGE("write failed");
857         return ERR_APPEXECFWK_PARCEL_ERROR;
858     }
859     if (ret) {
860         if (!reply.WriteParcelable(&info)) {
861             APP_LOGE("write failed");
862             return ERR_APPEXECFWK_PARCEL_ERROR;
863         }
864     }
865     return ERR_OK;
866 }
867 
HandleQueryAbilityInfos(MessageParcel & data,MessageParcel & reply)868 ErrCode BundleMgrHost::HandleQueryAbilityInfos(MessageParcel &data, MessageParcel &reply)
869 {
870     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
871     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
872     if (want == nullptr) {
873         APP_LOGE("ReadParcelable<want> failed");
874         return ERR_APPEXECFWK_PARCEL_ERROR;
875     }
876 
877     std::vector<AbilityInfo> abilityInfos;
878     bool ret = QueryAbilityInfos(*want, abilityInfos);
879     if (!reply.WriteBool(ret)) {
880         APP_LOGE("write failed");
881         return ERR_APPEXECFWK_PARCEL_ERROR;
882     }
883     if (ret) {
884         if (!WriteParcelableVector(abilityInfos, reply)) {
885             APP_LOGE("write failed");
886             return ERR_APPEXECFWK_PARCEL_ERROR;
887         }
888     }
889     return ERR_OK;
890 }
891 
HandleQueryAbilityInfosMutiparam(MessageParcel & data,MessageParcel & reply)892 ErrCode BundleMgrHost::HandleQueryAbilityInfosMutiparam(MessageParcel &data, MessageParcel &reply)
893 {
894     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
895     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
896     if (want == nullptr) {
897         APP_LOGE("ReadParcelable<want> failed");
898         return ERR_APPEXECFWK_PARCEL_ERROR;
899     }
900     int32_t flags = data.ReadInt32();
901     int32_t userId = data.ReadInt32();
902     std::vector<AbilityInfo> abilityInfos;
903     bool ret = QueryAbilityInfos(*want, flags, userId, abilityInfos);
904     if (!reply.WriteBool(ret)) {
905         APP_LOGE("write failed");
906         return ERR_APPEXECFWK_PARCEL_ERROR;
907     }
908     if (ret) {
909         if (!WriteVectorToParcelIntelligent(abilityInfos, reply)) {
910             APP_LOGE("write failed");
911             return ERR_APPEXECFWK_PARCEL_ERROR;
912         }
913     }
914     return ERR_OK;
915 }
916 
HandleQueryAbilityInfosV9(MessageParcel & data,MessageParcel & reply)917 ErrCode BundleMgrHost::HandleQueryAbilityInfosV9(MessageParcel &data, MessageParcel &reply)
918 {
919     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
920     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
921     if (want == nullptr) {
922         APP_LOGE("ReadParcelable<want> failed");
923         return ERR_APPEXECFWK_PARCEL_ERROR;
924     }
925     int32_t flags = data.ReadInt32();
926     int32_t userId = data.ReadInt32();
927     std::vector<AbilityInfo> abilityInfos;
928     ErrCode ret = QueryAbilityInfosV9(*want, flags, userId, abilityInfos);
929     if (!reply.WriteInt32(ret)) {
930         APP_LOGE("write ret failed");
931         return ERR_APPEXECFWK_PARCEL_ERROR;
932     }
933     if (ret == ERR_OK) {
934         if (!WriteVectorToParcelIntelligent(abilityInfos, reply)) {
935             APP_LOGE("WriteVectorToParcelIntelligent failed");
936             return ERR_APPEXECFWK_PARCEL_ERROR;
937         }
938     }
939     return ERR_OK;
940 }
941 
HandleQueryLauncherAbilityInfos(MessageParcel & data,MessageParcel & reply)942 ErrCode BundleMgrHost::HandleQueryLauncherAbilityInfos(MessageParcel &data, MessageParcel &reply)
943 {
944     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
945     if (want == nullptr) {
946         APP_LOGE("ReadParcelable<want> failed");
947         return ERR_APPEXECFWK_PARCEL_ERROR;
948     }
949     int32_t userId = data.ReadInt32();
950     std::vector<AbilityInfo> abilityInfos;
951     ErrCode ret = QueryLauncherAbilityInfos(*want, userId, abilityInfos);
952     if (!reply.WriteInt32(ret)) {
953         APP_LOGE("write ret failed");
954         return ERR_APPEXECFWK_PARCEL_ERROR;
955     }
956     if (ret == ERR_OK) {
957         if (!WriteVectorToParcelIntelligent(abilityInfos, reply)) {
958             APP_LOGE("WriteVectorToParcelIntelligent failed");
959             return ERR_APPEXECFWK_PARCEL_ERROR;
960         }
961     }
962     return ERR_OK;
963 }
964 
HandleQueryAllAbilityInfos(MessageParcel & data,MessageParcel & reply)965 ErrCode BundleMgrHost::HandleQueryAllAbilityInfos(MessageParcel &data, MessageParcel &reply)
966 {
967     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
968     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
969     if (want == nullptr) {
970         APP_LOGE("ReadParcelable<want> failed");
971         return ERR_APPEXECFWK_PARCEL_ERROR;
972     }
973     int32_t userId = data.ReadInt32();
974     std::vector<AbilityInfo> abilityInfos;
975     bool ret = QueryAllAbilityInfos(*want, userId, abilityInfos);
976     if (!reply.WriteBool(ret)) {
977         APP_LOGE("write failed");
978         return ERR_APPEXECFWK_PARCEL_ERROR;
979     }
980     if (ret) {
981         if (!WriteVectorToParcelIntelligent(abilityInfos, reply)) {
982             APP_LOGE("write failed");
983             return ERR_APPEXECFWK_PARCEL_ERROR;
984         }
985     }
986     return ERR_OK;
987 }
988 
HandleQueryAbilityInfoByUri(MessageParcel & data,MessageParcel & reply)989 ErrCode BundleMgrHost::HandleQueryAbilityInfoByUri(MessageParcel &data, MessageParcel &reply)
990 {
991     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
992     std::string abilityUri = data.ReadString();
993     AbilityInfo info;
994     bool ret = QueryAbilityInfoByUri(abilityUri, info);
995     if (!reply.WriteBool(ret)) {
996         APP_LOGE("write failed");
997         return ERR_APPEXECFWK_PARCEL_ERROR;
998     }
999     if (ret) {
1000         if (!reply.WriteParcelable(&info)) {
1001             APP_LOGE("write failed");
1002             return ERR_APPEXECFWK_PARCEL_ERROR;
1003         }
1004     }
1005     return ERR_OK;
1006 }
1007 
HandleQueryAbilityInfosByUri(MessageParcel & data,MessageParcel & reply)1008 ErrCode BundleMgrHost::HandleQueryAbilityInfosByUri(MessageParcel &data, MessageParcel &reply)
1009 {
1010     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1011     std::string abilityUri = data.ReadString();
1012     std::vector<AbilityInfo> abilityInfos;
1013     bool ret = QueryAbilityInfosByUri(abilityUri, abilityInfos);
1014     if (!reply.WriteBool(ret)) {
1015         APP_LOGE("write failed");
1016         return ERR_APPEXECFWK_PARCEL_ERROR;
1017     }
1018     if (ret) {
1019         if (!WriteParcelableVector(abilityInfos, reply)) {
1020             APP_LOGE("write failed");
1021             return ERR_APPEXECFWK_PARCEL_ERROR;
1022         }
1023     }
1024     return ERR_OK;
1025 }
1026 
HandleQueryAbilityInfoByUriForUserId(MessageParcel & data,MessageParcel & reply)1027 ErrCode BundleMgrHost::HandleQueryAbilityInfoByUriForUserId(MessageParcel &data, MessageParcel &reply)
1028 {
1029     std::string abilityUri = data.ReadString();
1030     int32_t userId = data.ReadInt32();
1031     AbilityInfo info;
1032     bool ret = QueryAbilityInfoByUri(abilityUri, userId, info);
1033     if (!reply.WriteBool(ret)) {
1034         APP_LOGE("write failed");
1035         return ERR_APPEXECFWK_PARCEL_ERROR;
1036     }
1037     if (ret) {
1038         if (!reply.WriteParcelable(&info)) {
1039             APP_LOGE("write failed");
1040             return ERR_APPEXECFWK_PARCEL_ERROR;
1041         }
1042     }
1043     return ERR_OK;
1044 }
1045 
HandleQueryKeepAliveBundleInfos(MessageParcel & data,MessageParcel & reply)1046 ErrCode BundleMgrHost::HandleQueryKeepAliveBundleInfos(MessageParcel &data, MessageParcel &reply)
1047 {
1048     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1049     std::vector<BundleInfo> infos;
1050     bool ret = QueryKeepAliveBundleInfos(infos);
1051     if (!reply.WriteBool(ret)) {
1052         APP_LOGE("write failed");
1053         return ERR_APPEXECFWK_PARCEL_ERROR;
1054     }
1055     if (ret) {
1056         if (!WriteParcelableVector(infos, reply)) {
1057             APP_LOGE("write failed");
1058             return ERR_APPEXECFWK_PARCEL_ERROR;
1059         }
1060     }
1061     return ERR_OK;
1062 }
1063 
HandleGetAbilityLabel(MessageParcel & data,MessageParcel & reply)1064 ErrCode BundleMgrHost::HandleGetAbilityLabel(MessageParcel &data, MessageParcel &reply)
1065 {
1066     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1067     std::string bundleName = data.ReadString();
1068     std::string abilityName = data.ReadString();
1069 
1070     APP_LOGD("bundleName %{public}s, abilityName %{public}s", bundleName.c_str(), abilityName.c_str());
1071     BundleInfo info;
1072     std::string label = GetAbilityLabel(bundleName, abilityName);
1073     if (!reply.WriteString(label)) {
1074         APP_LOGE("write failed");
1075         return ERR_APPEXECFWK_PARCEL_ERROR;
1076     }
1077     return ERR_OK;
1078 }
1079 
HandleGetAbilityLabelWithModuleName(MessageParcel & data,MessageParcel & reply)1080 ErrCode BundleMgrHost::HandleGetAbilityLabelWithModuleName(MessageParcel &data, MessageParcel &reply)
1081 {
1082     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1083     std::string bundleName = data.ReadString();
1084     std::string moduleName = data.ReadString();
1085     std::string abilityName = data.ReadString();
1086     if (bundleName.empty() || moduleName.empty() || abilityName.empty()) {
1087         APP_LOGE("fail to GetAbilityLabel due to params empty");
1088         return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
1089     }
1090     APP_LOGD("GetAbilityLabe bundleName %{public}s, moduleName %{public}s, abilityName %{public}s",
1091         bundleName.c_str(), moduleName.c_str(), abilityName.c_str());
1092     std::string label;
1093     ErrCode ret = GetAbilityLabel(bundleName, moduleName, abilityName, label);
1094     if (!reply.WriteInt32(ret)) {
1095         return ERR_APPEXECFWK_PARCEL_ERROR;
1096     }
1097     if ((ret == ERR_OK) && !reply.WriteString(label)) {
1098         APP_LOGE("write failed");
1099         return ERR_APPEXECFWK_PARCEL_ERROR;
1100     }
1101     return ERR_OK;
1102 }
1103 
HandleCheckIsSystemAppByUid(MessageParcel & data,MessageParcel & reply)1104 ErrCode BundleMgrHost::HandleCheckIsSystemAppByUid(MessageParcel &data, MessageParcel &reply)
1105 {
1106     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1107     int uid = data.ReadInt32();
1108     bool ret = CheckIsSystemAppByUid(uid);
1109     if (!reply.WriteBool(ret)) {
1110         APP_LOGE("write failed");
1111         return ERR_APPEXECFWK_PARCEL_ERROR;
1112     }
1113     return ERR_OK;
1114 }
1115 
HandleGetBundleArchiveInfo(MessageParcel & data,MessageParcel & reply)1116 ErrCode BundleMgrHost::HandleGetBundleArchiveInfo(MessageParcel &data, MessageParcel &reply)
1117 {
1118     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1119     std::string hapFilePath = data.ReadString();
1120     BundleFlag flag = static_cast<BundleFlag>(data.ReadInt32());
1121     APP_LOGD("hapFilePath %{private}s, flag %{public}d", hapFilePath.c_str(), flag);
1122 
1123     BundleInfo info;
1124     bool ret = GetBundleArchiveInfo(hapFilePath, flag, info);
1125     if (!reply.WriteBool(ret)) {
1126         APP_LOGE("write failed");
1127         return ERR_APPEXECFWK_PARCEL_ERROR;
1128     }
1129     if (ret) {
1130         if (!reply.WriteParcelable(&info)) {
1131             APP_LOGE("write failed");
1132             return ERR_APPEXECFWK_PARCEL_ERROR;
1133         }
1134     }
1135     return ERR_OK;
1136 }
1137 
HandleGetBundleArchiveInfoWithIntFlags(MessageParcel & data,MessageParcel & reply)1138 ErrCode BundleMgrHost::HandleGetBundleArchiveInfoWithIntFlags(MessageParcel &data, MessageParcel &reply)
1139 {
1140     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1141     std::string hapFilePath = data.ReadString();
1142     int32_t flags = data.ReadInt32();
1143     APP_LOGD("hapFilePath %{private}s, flagS %{public}d", hapFilePath.c_str(), flags);
1144 
1145     BundleInfo info;
1146     bool ret = GetBundleArchiveInfo(hapFilePath, flags, info);
1147     if (!reply.WriteBool(ret)) {
1148         APP_LOGE("write failed");
1149         return ERR_APPEXECFWK_PARCEL_ERROR;
1150     }
1151     if (ret) {
1152         if (!reply.WriteParcelable(&info)) {
1153             APP_LOGE("write failed");
1154             return ERR_APPEXECFWK_PARCEL_ERROR;
1155         }
1156     }
1157     return ERR_OK;
1158 }
1159 
HandleGetBundleArchiveInfoWithIntFlagsV9(MessageParcel & data,MessageParcel & reply)1160 ErrCode BundleMgrHost::HandleGetBundleArchiveInfoWithIntFlagsV9(MessageParcel &data, MessageParcel &reply)
1161 {
1162     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1163     std::string hapFilePath = data.ReadString();
1164     int32_t flags = data.ReadInt32();
1165     APP_LOGD("hapFilePath %{private}s, flags %{public}d", hapFilePath.c_str(), flags);
1166 
1167     BundleInfo info;
1168     ErrCode ret = GetBundleArchiveInfoV9(hapFilePath, flags, info);
1169     if (!reply.WriteInt32(ret)) {
1170         APP_LOGE("write failed");
1171         return ERR_APPEXECFWK_PARCEL_ERROR;
1172     }
1173     if (ret == ERR_OK) {
1174         if (!reply.WriteParcelable(&info)) {
1175             APP_LOGE("write failed");
1176             return ERR_APPEXECFWK_PARCEL_ERROR;
1177         }
1178     }
1179     return ERR_OK;
1180 }
1181 
HandleGetHapModuleInfo(MessageParcel & data,MessageParcel & reply)1182 ErrCode BundleMgrHost::HandleGetHapModuleInfo(MessageParcel &data, MessageParcel &reply)
1183 {
1184     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1185     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
1186     if (!abilityInfo) {
1187         APP_LOGE("ReadParcelable<abilityInfo> failed");
1188         return ERR_APPEXECFWK_PARCEL_ERROR;
1189     }
1190 
1191     HapModuleInfo info;
1192     bool ret = GetHapModuleInfo(*abilityInfo, info);
1193     if (!reply.WriteBool(ret)) {
1194         APP_LOGE("write failed");
1195         return ERR_APPEXECFWK_PARCEL_ERROR;
1196     }
1197     if (ret) {
1198         if (!reply.WriteParcelable(&info)) {
1199             APP_LOGE("write failed");
1200             return ERR_APPEXECFWK_PARCEL_ERROR;
1201         }
1202     }
1203     return ERR_OK;
1204 }
1205 
HandleGetHapModuleInfoWithUserId(MessageParcel & data,MessageParcel & reply)1206 ErrCode BundleMgrHost::HandleGetHapModuleInfoWithUserId(MessageParcel &data, MessageParcel &reply)
1207 {
1208     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1209     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
1210     if (abilityInfo == nullptr) {
1211         APP_LOGE("ReadParcelable<abilityInfo> failed");
1212         return ERR_APPEXECFWK_PARCEL_ERROR;
1213     }
1214 
1215     int32_t userId = data.ReadInt32();
1216     HapModuleInfo info;
1217     bool ret = GetHapModuleInfo(*abilityInfo, userId, info);
1218     if (!reply.WriteBool(ret)) {
1219         APP_LOGE("write failed");
1220         return ERR_APPEXECFWK_PARCEL_ERROR;
1221     }
1222     if (ret) {
1223         if (!reply.WriteParcelable(&info)) {
1224             APP_LOGE("write failed");
1225             return ERR_APPEXECFWK_PARCEL_ERROR;
1226         }
1227     }
1228     return ERR_OK;
1229 }
1230 
HandleGetLaunchWantForBundle(MessageParcel & data,MessageParcel & reply)1231 ErrCode BundleMgrHost::HandleGetLaunchWantForBundle(MessageParcel &data, MessageParcel &reply)
1232 {
1233     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1234     std::string bundleName = data.ReadString();
1235     int32_t userId = data.ReadInt32();
1236     APP_LOGD("name %{public}s", bundleName.c_str());
1237 
1238     Want want;
1239     ErrCode ret = GetLaunchWantForBundle(bundleName, want, userId);
1240     if (!reply.WriteInt32(ret)) {
1241         APP_LOGE("write failed");
1242         return ERR_APPEXECFWK_PARCEL_ERROR;
1243     }
1244     if (ret == ERR_OK) {
1245         if (!reply.WriteParcelable(&want)) {
1246             APP_LOGE("write failed");
1247             return ERR_APPEXECFWK_PARCEL_ERROR;
1248         }
1249     }
1250     return ERR_OK;
1251 }
1252 
HandleGetPermissionDef(MessageParcel & data,MessageParcel & reply)1253 ErrCode BundleMgrHost::HandleGetPermissionDef(MessageParcel &data, MessageParcel &reply)
1254 {
1255     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1256     std::string permissionName = data.ReadString();
1257     APP_LOGD("name %{public}s", permissionName.c_str());
1258 
1259     PermissionDef permissionDef;
1260     ErrCode ret = GetPermissionDef(permissionName, permissionDef);
1261     if (!reply.WriteInt32(ret)) {
1262         APP_LOGE("write failed");
1263         return ERR_APPEXECFWK_PARCEL_ERROR;
1264     }
1265     if (ret == ERR_OK) {
1266         if (!reply.WriteParcelable(&permissionDef)) {
1267             APP_LOGE("write failed");
1268             return ERR_APPEXECFWK_PARCEL_ERROR;
1269         }
1270     }
1271     return ERR_OK;
1272 }
1273 
HandleCleanBundleCacheFiles(MessageParcel & data,MessageParcel & reply)1274 ErrCode BundleMgrHost::HandleCleanBundleCacheFiles(MessageParcel &data, MessageParcel &reply)
1275 {
1276     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1277     std::string bundleName = data.ReadString();
1278     sptr<IRemoteObject> object = data.ReadRemoteObject();
1279     if (object == nullptr) {
1280         APP_LOGE("read failed");
1281         return ERR_APPEXECFWK_PARCEL_ERROR;
1282     }
1283     sptr<ICleanCacheCallback> cleanCacheCallback = iface_cast<ICleanCacheCallback>(object);
1284     int32_t userId = data.ReadInt32();
1285 
1286     ErrCode ret = CleanBundleCacheFiles(bundleName, cleanCacheCallback, userId);
1287     if (!reply.WriteInt32(ret)) {
1288         APP_LOGE("write failed");
1289         return ERR_APPEXECFWK_PARCEL_ERROR;
1290     }
1291     return ERR_OK;
1292 }
1293 
HandleCleanBundleDataFiles(MessageParcel & data,MessageParcel & reply)1294 ErrCode BundleMgrHost::HandleCleanBundleDataFiles(MessageParcel &data, MessageParcel &reply)
1295 {
1296     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1297     std::string bundleName = data.ReadString();
1298     int userId = data.ReadInt32();
1299 
1300     bool ret = CleanBundleDataFiles(bundleName, userId);
1301     if (!reply.WriteBool(ret)) {
1302         APP_LOGE("write failed");
1303         return ERR_APPEXECFWK_PARCEL_ERROR;
1304     }
1305     return ERR_OK;
1306 }
1307 
HandleRegisterBundleStatusCallback(MessageParcel & data,MessageParcel & reply)1308 ErrCode BundleMgrHost::HandleRegisterBundleStatusCallback(MessageParcel &data, MessageParcel &reply)
1309 {
1310     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1311     std::string bundleName = data.ReadString();
1312     sptr<IRemoteObject> object = data.ReadRemoteObject();
1313     if (object == nullptr) {
1314         APP_LOGE("read failed");
1315         return ERR_APPEXECFWK_PARCEL_ERROR;
1316     }
1317     sptr<IBundleStatusCallback> BundleStatusCallback = iface_cast<IBundleStatusCallback>(object);
1318 
1319     bool ret = false;
1320     if (bundleName.empty() || !BundleStatusCallback) {
1321         APP_LOGE("Get BundleStatusCallback failed");
1322     } else {
1323         BundleStatusCallback->SetBundleName(bundleName);
1324         ret = RegisterBundleStatusCallback(BundleStatusCallback);
1325     }
1326     if (!reply.WriteBool(ret)) {
1327         APP_LOGE("write failed");
1328         return ERR_APPEXECFWK_PARCEL_ERROR;
1329     }
1330     return ERR_OK;
1331 }
1332 
HandleRegisterBundleEventCallback(MessageParcel & data,MessageParcel & reply)1333 ErrCode BundleMgrHost::HandleRegisterBundleEventCallback(MessageParcel &data, MessageParcel &reply)
1334 {
1335     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1336     sptr<IRemoteObject> object = data.ReadRemoteObject();
1337     if (object == nullptr) {
1338         APP_LOGE("read IRemoteObject failed");
1339         return ERR_APPEXECFWK_PARCEL_ERROR;
1340     }
1341     sptr<IBundleEventCallback> bundleEventCallback = iface_cast<IBundleEventCallback>(object);
1342     if (bundleEventCallback == nullptr) {
1343         APP_LOGE("Get bundleEventCallback failed");
1344         return ERR_APPEXECFWK_PARCEL_ERROR;
1345     }
1346     bool ret = RegisterBundleEventCallback(bundleEventCallback);
1347     if (!reply.WriteBool(ret)) {
1348         APP_LOGE("write ret failed");
1349         return ERR_APPEXECFWK_PARCEL_ERROR;
1350     }
1351     return ERR_OK;
1352 }
1353 
HandleUnregisterBundleEventCallback(MessageParcel & data,MessageParcel & reply)1354 ErrCode BundleMgrHost::HandleUnregisterBundleEventCallback(MessageParcel &data, MessageParcel &reply)
1355 {
1356     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1357     sptr<IRemoteObject> object = data.ReadRemoteObject();
1358     if (object == nullptr) {
1359         APP_LOGE("read IRemoteObject failed");
1360         return ERR_APPEXECFWK_PARCEL_ERROR;
1361     }
1362     sptr<IBundleEventCallback> bundleEventCallback = iface_cast<IBundleEventCallback>(object);
1363 
1364     bool ret = UnregisterBundleEventCallback(bundleEventCallback);
1365     if (!reply.WriteBool(ret)) {
1366         APP_LOGE("write ret failed");
1367         return ERR_APPEXECFWK_PARCEL_ERROR;
1368     }
1369     return ERR_OK;
1370 }
1371 
HandleClearBundleStatusCallback(MessageParcel & data,MessageParcel & reply)1372 ErrCode BundleMgrHost::HandleClearBundleStatusCallback(MessageParcel &data, MessageParcel &reply)
1373 {
1374     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1375     sptr<IRemoteObject> object = data.ReadRemoteObject();
1376     if (object == nullptr) {
1377         APP_LOGE("read failed");
1378         return ERR_APPEXECFWK_PARCEL_ERROR;
1379     }
1380     sptr<IBundleStatusCallback> BundleStatusCallback = iface_cast<IBundleStatusCallback>(object);
1381 
1382     bool ret = ClearBundleStatusCallback(BundleStatusCallback);
1383     if (!reply.WriteBool(ret)) {
1384         APP_LOGE("write failed");
1385         return ERR_APPEXECFWK_PARCEL_ERROR;
1386     }
1387     return ERR_OK;
1388 }
1389 
HandleUnregisterBundleStatusCallback(MessageParcel & data,MessageParcel & reply)1390 ErrCode BundleMgrHost::HandleUnregisterBundleStatusCallback(MessageParcel &data, MessageParcel &reply)
1391 {
1392     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1393     bool ret = UnregisterBundleStatusCallback();
1394     if (!reply.WriteBool(ret)) {
1395         APP_LOGE("write failed");
1396         return ERR_APPEXECFWK_PARCEL_ERROR;
1397     }
1398     return ERR_OK;
1399 }
1400 
HandleCompileProcessAOT(MessageParcel & data,MessageParcel & reply)1401 ErrCode BundleMgrHost::HandleCompileProcessAOT(MessageParcel &data, MessageParcel &reply)
1402 {
1403     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1404     std::string bundleName = data.ReadString();
1405     std::string compileMode = data.ReadString();
1406     bool isAllBundle = data.ReadBool();
1407 
1408     APP_LOGI("compile info name %{public}s", bundleName.c_str());
1409     ErrCode ret = CompileProcessAOT(bundleName, compileMode, isAllBundle);
1410     APP_LOGI("ret is %{public}d", ret);
1411     if (!reply.WriteInt32(ret)) {
1412         return ERR_APPEXECFWK_PARCEL_ERROR;
1413     }
1414     return ERR_OK;
1415 }
1416 
HandleCompileReset(MessageParcel & data,MessageParcel & reply)1417 ErrCode BundleMgrHost::HandleCompileReset(MessageParcel &data, MessageParcel &reply)
1418 {
1419     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1420     std::string bundleName = data.ReadString();
1421     bool isAllBundle = data.ReadBool();
1422 
1423     APP_LOGI("reset info name %{public}s", bundleName.c_str());
1424     ErrCode ret = CompileReset(bundleName, isAllBundle);
1425     APP_LOGI("ret is %{public}d", ret);
1426     if (!reply.WriteInt32(ret)) {
1427         return ERR_APPEXECFWK_PARCEL_ERROR;
1428     }
1429     return ERR_OK;
1430 }
1431 
HandleDumpInfos(MessageParcel & data,MessageParcel & reply)1432 ErrCode BundleMgrHost::HandleDumpInfos(MessageParcel &data, MessageParcel &reply)
1433 {
1434     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1435     DumpFlag flag = static_cast<DumpFlag>(data.ReadInt32());
1436     std::string bundleName = data.ReadString();
1437     int32_t userId = data.ReadInt32();
1438 
1439     std::string result;
1440     APP_LOGI("dump info name %{public}s", bundleName.c_str());
1441     bool ret = DumpInfos(flag, bundleName, userId, result);
1442     if (!reply.WriteBool(ret)) {
1443         APP_LOGE("write failed");
1444         return ERR_APPEXECFWK_PARCEL_ERROR;
1445     }
1446     if (ret) {
1447         std::vector<std::string> dumpInfos;
1448         SplitString(result, dumpInfos);
1449         if (!reply.WriteStringVector(dumpInfos)) {
1450             return ERR_APPEXECFWK_PARCEL_ERROR;
1451         }
1452     }
1453     return ERR_OK;
1454 }
1455 
HandleIsApplicationEnabled(MessageParcel & data,MessageParcel & reply)1456 ErrCode BundleMgrHost::HandleIsApplicationEnabled(MessageParcel &data, MessageParcel &reply)
1457 {
1458     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1459     std::string bundleName = data.ReadString();
1460     if (bundleName.empty()) {
1461         APP_LOGE("fail to IsApplicationEnabled due to params empty");
1462         return ERR_BUNDLE_MANAGER_PARAM_ERROR;
1463     }
1464     bool isEnable = false;
1465     ErrCode ret = IsApplicationEnabled(bundleName, isEnable);
1466     if (!reply.WriteInt32(ret)) {
1467         return ERR_APPEXECFWK_PARCEL_ERROR;
1468     }
1469     if (!reply.WriteBool(isEnable)) {
1470         return ERR_APPEXECFWK_PARCEL_ERROR;
1471     }
1472     return ERR_OK;
1473 }
1474 
HandleSetApplicationEnabled(MessageParcel & data,MessageParcel & reply)1475 ErrCode BundleMgrHost::HandleSetApplicationEnabled(MessageParcel &data, MessageParcel &reply)
1476 {
1477     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1478     std::string bundleName = data.ReadString();
1479     if (bundleName.empty()) {
1480         APP_LOGE("fail to SetApplicationEnabled due to params empty");
1481         return ERR_BUNDLE_MANAGER_PARAM_ERROR;
1482     }
1483     bool isEnable = data.ReadBool();
1484     int32_t userId = data.ReadInt32();
1485     ErrCode ret = SetApplicationEnabled(bundleName, isEnable, userId);
1486     if (!reply.WriteInt32(ret)) {
1487         return ERR_APPEXECFWK_PARCEL_ERROR;
1488     }
1489     return ERR_OK;
1490 }
1491 
HandleIsAbilityEnabled(MessageParcel & data,MessageParcel & reply)1492 ErrCode BundleMgrHost::HandleIsAbilityEnabled(MessageParcel &data, MessageParcel &reply)
1493 {
1494     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1495     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
1496     if (abilityInfo == nullptr) {
1497         APP_LOGE("ReadParcelable<abilityInfo> failed");
1498         return ERR_APPEXECFWK_PARCEL_ERROR;
1499     }
1500     bool isEnable = false;
1501     ErrCode ret = IsAbilityEnabled(*abilityInfo, isEnable);
1502     if (!reply.WriteInt32(ret)) {
1503         return ERR_APPEXECFWK_PARCEL_ERROR;
1504     }
1505     if (!reply.WriteBool(isEnable)) {
1506         return ERR_APPEXECFWK_PARCEL_ERROR;
1507     }
1508     return ERR_OK;
1509 }
1510 
HandleSetAbilityEnabled(MessageParcel & data,MessageParcel & reply)1511 ErrCode BundleMgrHost::HandleSetAbilityEnabled(MessageParcel &data, MessageParcel &reply)
1512 {
1513     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1514     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
1515     if (abilityInfo == nullptr) {
1516         APP_LOGE("ReadParcelable<abilityInfo> failed");
1517         return ERR_APPEXECFWK_PARCEL_ERROR;
1518     }
1519     bool isEnabled = data.ReadBool();
1520     int32_t userId = data.ReadInt32();
1521     ErrCode ret = SetAbilityEnabled(*abilityInfo, isEnabled, userId);
1522     if (!reply.WriteInt32(ret)) {
1523         return ERR_APPEXECFWK_PARCEL_ERROR;
1524     }
1525     return ERR_OK;
1526 }
1527 
HandleGetAbilityInfo(MessageParcel & data,MessageParcel & reply)1528 ErrCode BundleMgrHost::HandleGetAbilityInfo(MessageParcel &data, MessageParcel &reply)
1529 {
1530     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1531     AbilityInfo info;
1532     std::string bundleName = data.ReadString();
1533     std::string abilityName = data.ReadString();
1534     bool ret = GetAbilityInfo(bundleName, abilityName, info);
1535     if (!reply.WriteBool(ret)) {
1536         APP_LOGE("write failed");
1537         return ERR_APPEXECFWK_PARCEL_ERROR;
1538     }
1539     if (ret) {
1540         if (!reply.WriteParcelable(&info)) {
1541             APP_LOGE("write failed");
1542             return ERR_APPEXECFWK_PARCEL_ERROR;
1543         }
1544     }
1545     return ERR_OK;
1546 }
1547 
HandleGetAbilityInfoWithModuleName(MessageParcel & data,MessageParcel & reply)1548 ErrCode BundleMgrHost::HandleGetAbilityInfoWithModuleName(MessageParcel &data, MessageParcel &reply)
1549 {
1550     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1551     AbilityInfo info;
1552     std::string bundleName = data.ReadString();
1553     std::string moduleName = data.ReadString();
1554     std::string abilityName = data.ReadString();
1555     bool ret = GetAbilityInfo(bundleName, moduleName, abilityName, info);
1556     if (!reply.WriteBool(ret)) {
1557         APP_LOGE("write failed");
1558         return ERR_APPEXECFWK_PARCEL_ERROR;
1559     }
1560     if (ret) {
1561         if (!reply.WriteParcelable(&info)) {
1562             APP_LOGE("write failed");
1563             return ERR_APPEXECFWK_PARCEL_ERROR;
1564         }
1565     }
1566     return ERR_OK;
1567 }
1568 
HandleGetBundleInstaller(MessageParcel & data,MessageParcel & reply)1569 ErrCode BundleMgrHost::HandleGetBundleInstaller(MessageParcel &data, MessageParcel &reply)
1570 {
1571     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1572     sptr<IBundleInstaller> installer = GetBundleInstaller();
1573     if (installer == nullptr) {
1574         APP_LOGE("bundle installer is nullptr");
1575         return ERR_APPEXECFWK_INSTALL_HOST_INSTALLER_FAILED;
1576     }
1577 
1578     if (!reply.WriteRemoteObject(installer->AsObject())) {
1579         APP_LOGE("failed to reply bundle installer to client, for write MessageParcel error");
1580         return ERR_APPEXECFWK_PARCEL_ERROR;
1581     }
1582     return ERR_OK;
1583 }
1584 
HandleGetBundleUserMgr(MessageParcel & data,MessageParcel & reply)1585 ErrCode BundleMgrHost::HandleGetBundleUserMgr(MessageParcel &data, MessageParcel &reply)
1586 {
1587     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1588     sptr<IBundleUserMgr> bundleUserMgr = GetBundleUserMgr();
1589     if (bundleUserMgr == nullptr) {
1590         APP_LOGE("bundle installer is nullptr");
1591         return ERR_APPEXECFWK_INSTALL_HOST_INSTALLER_FAILED;
1592     }
1593 
1594     if (!reply.WriteRemoteObject(bundleUserMgr->AsObject())) {
1595         APP_LOGE("failed to reply bundle installer to client, for write MessageParcel error");
1596         return ERR_APPEXECFWK_PARCEL_ERROR;
1597     }
1598     return ERR_OK;
1599 }
1600 
HandleGetVerifyManager(MessageParcel & data,MessageParcel & reply)1601 ErrCode BundleMgrHost::HandleGetVerifyManager(MessageParcel &data, MessageParcel &reply)
1602 {
1603     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1604     sptr<IVerifyManager> verifyManager = GetVerifyManager();
1605     if (verifyManager == nullptr) {
1606         APP_LOGE("verifyManager is nullptr");
1607         return ERR_BUNDLE_MANAGER_VERIFY_GET_VERIFY_MGR_FAILED;
1608     }
1609 
1610     if (!reply.WriteRemoteObject(verifyManager->AsObject())) {
1611         APP_LOGE("failed to reply bundle installer to client, for write MessageParcel error");
1612         return ERR_APPEXECFWK_PARCEL_ERROR;
1613     }
1614     return ERR_OK;
1615 }
1616 
HandleGetAllFormsInfo(MessageParcel & data,MessageParcel & reply)1617 ErrCode BundleMgrHost::HandleGetAllFormsInfo(MessageParcel &data, MessageParcel &reply)
1618 {
1619     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1620     std::vector<FormInfo> infos;
1621     bool ret = GetAllFormsInfo(infos);
1622     if (!reply.WriteBool(ret)) {
1623         APP_LOGE("write failed");
1624         return ERR_APPEXECFWK_PARCEL_ERROR;
1625     }
1626 
1627     if (ret) {
1628         if (!WriteParcelableVector(infos, reply)) {
1629             APP_LOGE("write failed");
1630             return ERR_APPEXECFWK_PARCEL_ERROR;
1631         }
1632     }
1633     return ERR_OK;
1634 }
1635 
HandleGetFormsInfoByApp(MessageParcel & data,MessageParcel & reply)1636 ErrCode BundleMgrHost::HandleGetFormsInfoByApp(MessageParcel &data, MessageParcel &reply)
1637 {
1638     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1639     std::string bundlename = data.ReadString();
1640     std::vector<FormInfo> infos;
1641     bool ret = GetFormsInfoByApp(bundlename, infos);
1642     if (!reply.WriteBool(ret)) {
1643         APP_LOGE("write failed");
1644         return ERR_APPEXECFWK_PARCEL_ERROR;
1645     }
1646 
1647     if (ret) {
1648         if (!WriteParcelableVector(infos, reply)) {
1649             APP_LOGE("write failed");
1650             return ERR_APPEXECFWK_PARCEL_ERROR;
1651         }
1652     }
1653     return ERR_OK;
1654 }
1655 
HandleGetFormsInfoByModule(MessageParcel & data,MessageParcel & reply)1656 ErrCode BundleMgrHost::HandleGetFormsInfoByModule(MessageParcel &data, MessageParcel &reply)
1657 {
1658     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1659     std::string bundlename = data.ReadString();
1660     std::string modulename = data.ReadString();
1661     std::vector<FormInfo> infos;
1662     bool ret = GetFormsInfoByModule(bundlename, modulename, infos);
1663     if (!reply.WriteBool(ret)) {
1664         APP_LOGE("write failed");
1665         return ERR_APPEXECFWK_PARCEL_ERROR;
1666     }
1667 
1668     if (ret) {
1669         if (!WriteParcelableVector(infos, reply)) {
1670             APP_LOGE("write failed");
1671             return ERR_APPEXECFWK_PARCEL_ERROR;
1672         }
1673     }
1674     return ERR_OK;
1675 }
1676 
HandleGetShortcutInfos(MessageParcel & data,MessageParcel & reply)1677 ErrCode BundleMgrHost::HandleGetShortcutInfos(MessageParcel &data, MessageParcel &reply)
1678 {
1679     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1680     std::string bundlename = data.ReadString();
1681     std::vector<ShortcutInfo> infos;
1682     bool ret = GetShortcutInfos(bundlename, infos);
1683     if (!reply.WriteBool(ret)) {
1684         APP_LOGE("write failed");
1685         return ERR_APPEXECFWK_PARCEL_ERROR;
1686     }
1687 
1688     if (ret) {
1689         if (!WriteParcelableVector(infos, reply)) {
1690             APP_LOGE("write failed");
1691             return ERR_APPEXECFWK_PARCEL_ERROR;
1692         }
1693     }
1694     return ERR_OK;
1695 }
1696 
HandleGetShortcutInfoV9(MessageParcel & data,MessageParcel & reply)1697 ErrCode BundleMgrHost::HandleGetShortcutInfoV9(MessageParcel &data, MessageParcel &reply)
1698 {
1699     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1700     std::string bundlename = data.ReadString();
1701     std::vector<ShortcutInfo> infos;
1702     ErrCode ret = GetShortcutInfoV9(bundlename, infos);
1703     if (!reply.WriteInt32(ret)) {
1704         APP_LOGE("write result failed");
1705         return ERR_APPEXECFWK_PARCEL_ERROR;
1706     }
1707     if (ret == ERR_OK && !WriteParcelableVector(infos, reply)) {
1708         APP_LOGE("write shortcut infos failed");
1709         return ERR_APPEXECFWK_PARCEL_ERROR;
1710     }
1711     return ERR_OK;
1712 }
1713 
HandleGetAllCommonEventInfo(MessageParcel & data,MessageParcel & reply)1714 ErrCode BundleMgrHost::HandleGetAllCommonEventInfo(MessageParcel &data, MessageParcel &reply)
1715 {
1716     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1717     std::string eventKey = data.ReadString();
1718     std::vector<CommonEventInfo> infos;
1719     bool ret = GetAllCommonEventInfo(eventKey, infos);
1720     if (!reply.WriteBool(ret)) {
1721         APP_LOGE("write failed");
1722         return ERR_APPEXECFWK_PARCEL_ERROR;
1723     }
1724 
1725     if (ret) {
1726         if (!WriteParcelableVector(infos, reply)) {
1727             APP_LOGE("write failed");
1728             return ERR_APPEXECFWK_PARCEL_ERROR;
1729         }
1730     }
1731     return ERR_OK;
1732 }
1733 
HandleGetDistributedBundleInfo(MessageParcel & data,MessageParcel & reply)1734 ErrCode BundleMgrHost::HandleGetDistributedBundleInfo(MessageParcel &data, MessageParcel &reply)
1735 {
1736     std::string networkId = data.ReadString();
1737     std::string bundleName = data.ReadString();
1738     if (networkId.empty() || bundleName.empty()) {
1739         APP_LOGE("networkId or bundleName is invalid");
1740         return ERR_INVALID_VALUE;
1741     }
1742     DistributedBundleInfo distributedBundleInfo;
1743     bool ret = GetDistributedBundleInfo(networkId, bundleName, distributedBundleInfo);
1744     if (!reply.WriteBool(ret)) {
1745         APP_LOGE("write failed");
1746         return ERR_APPEXECFWK_PARCEL_ERROR;
1747     }
1748     if (ret) {
1749         if (!reply.WriteParcelable(&distributedBundleInfo)) {
1750             APP_LOGE("write failed");
1751             return ERR_APPEXECFWK_PARCEL_ERROR;
1752         }
1753     }
1754     return ERR_OK;
1755 }
1756 
HandleGetAppPrivilegeLevel(MessageParcel & data,MessageParcel & reply)1757 ErrCode BundleMgrHost::HandleGetAppPrivilegeLevel(MessageParcel &data, MessageParcel &reply)
1758 {
1759     std::string bundleName = data.ReadString();
1760     int32_t userId = data.ReadInt32();
1761     auto ret = GetAppPrivilegeLevel(bundleName, userId);
1762     if (!reply.WriteString(ret)) {
1763         APP_LOGE("write failed");
1764         return ERR_APPEXECFWK_PARCEL_ERROR;
1765     }
1766     return ERR_OK;
1767 }
1768 
HandleQueryExtAbilityInfosWithoutType(MessageParcel & data,MessageParcel & reply)1769 ErrCode BundleMgrHost::HandleQueryExtAbilityInfosWithoutType(MessageParcel &data, MessageParcel &reply)
1770 {
1771     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1772     if (!want) {
1773         APP_LOGE("ReadParcelable<want> failed");
1774         return ERR_APPEXECFWK_PARCEL_ERROR;
1775     }
1776 
1777     int32_t flag = data.ReadInt32();
1778     int32_t userId = data.ReadInt32();
1779     std::vector<ExtensionAbilityInfo> infos;
1780     bool ret = QueryExtensionAbilityInfos(*want, flag, userId, infos);
1781     if (!reply.WriteBool(ret)) {
1782         APP_LOGE("write result failed");
1783         return ERR_APPEXECFWK_PARCEL_ERROR;
1784     }
1785     if (ret && !WriteParcelableVector(infos, reply)) {
1786         APP_LOGE("write extension infos failed");
1787 
1788         return ERR_APPEXECFWK_PARCEL_ERROR;
1789     }
1790     return ERR_OK;
1791 }
1792 
HandleQueryExtAbilityInfosWithoutTypeV9(MessageParcel & data,MessageParcel & reply)1793 ErrCode BundleMgrHost::HandleQueryExtAbilityInfosWithoutTypeV9(MessageParcel &data, MessageParcel &reply)
1794 {
1795     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1796     if (!want) {
1797         APP_LOGE("ReadParcelable<want> failed");
1798         return ERR_APPEXECFWK_PARCEL_ERROR;
1799     }
1800 
1801     int32_t flags = data.ReadInt32();
1802     int32_t userId = data.ReadInt32();
1803     std::vector<ExtensionAbilityInfo> infos;
1804     ErrCode ret = QueryExtensionAbilityInfosV9(*want, flags, userId, infos);
1805     if (!reply.WriteInt32(ret)) {
1806         APP_LOGE("write result failed");
1807         return ERR_APPEXECFWK_PARCEL_ERROR;
1808     }
1809     if (ret == ERR_OK && !WriteParcelableVector(infos, reply)) {
1810         APP_LOGE("write extension infos failed");
1811         return ERR_APPEXECFWK_PARCEL_ERROR;
1812     }
1813     return ERR_OK;
1814 }
1815 
HandleQueryExtAbilityInfos(MessageParcel & data,MessageParcel & reply)1816 ErrCode BundleMgrHost::HandleQueryExtAbilityInfos(MessageParcel &data, MessageParcel &reply)
1817 {
1818     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1819     if (want == nullptr) {
1820         APP_LOGE("ReadParcelable<want> failed");
1821         return ERR_APPEXECFWK_PARCEL_ERROR;
1822     }
1823 
1824     ExtensionAbilityType type = static_cast<ExtensionAbilityType>(data.ReadInt32());
1825     int32_t flag = data.ReadInt32();
1826     int32_t userId = data.ReadInt32();
1827     std::vector<ExtensionAbilityInfo> infos;
1828     bool ret = QueryExtensionAbilityInfos(*want, type, flag, userId, infos);
1829     if (!reply.WriteBool(ret)) {
1830         APP_LOGE("write result failed");
1831         return ERR_APPEXECFWK_PARCEL_ERROR;
1832     }
1833     if (ret && !WriteParcelableVector(infos, reply)) {
1834         APP_LOGE("write extension infos failed");
1835         return ERR_APPEXECFWK_PARCEL_ERROR;
1836     }
1837     return ERR_OK;
1838 }
1839 
HandleQueryExtAbilityInfosV9(MessageParcel & data,MessageParcel & reply)1840 ErrCode BundleMgrHost::HandleQueryExtAbilityInfosV9(MessageParcel &data, MessageParcel &reply)
1841 {
1842     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1843     if (want == nullptr) {
1844         APP_LOGE("ReadParcelable<want> failed");
1845         return ERR_APPEXECFWK_PARCEL_ERROR;
1846     }
1847 
1848     ExtensionAbilityType type = static_cast<ExtensionAbilityType>(data.ReadInt32());
1849     int32_t flags = data.ReadInt32();
1850     int32_t userId = data.ReadInt32();
1851     std::vector<ExtensionAbilityInfo> infos;
1852     ErrCode ret = QueryExtensionAbilityInfosV9(*want, type, flags, userId, infos);
1853     if (!reply.WriteInt32(ret)) {
1854         APP_LOGE("write result failed");
1855         return ERR_APPEXECFWK_PARCEL_ERROR;
1856     }
1857     if (ret == ERR_OK && !WriteParcelableVector(infos, reply)) {
1858         APP_LOGE("write extension infos failed");
1859         return ERR_APPEXECFWK_PARCEL_ERROR;
1860     }
1861     return ERR_OK;
1862 }
1863 
HandleQueryExtAbilityInfosByType(MessageParcel & data,MessageParcel & reply)1864 ErrCode BundleMgrHost::HandleQueryExtAbilityInfosByType(MessageParcel &data, MessageParcel &reply)
1865 {
1866     ExtensionAbilityType type = static_cast<ExtensionAbilityType>(data.ReadInt32());
1867     int32_t userId = data.ReadInt32();
1868     std::vector<ExtensionAbilityInfo> infos;
1869 
1870     bool ret = QueryExtensionAbilityInfos(type, userId, infos);
1871     if (!reply.WriteBool(ret)) {
1872         APP_LOGE("write result failed");
1873         return ERR_APPEXECFWK_PARCEL_ERROR;
1874     }
1875     if (ret && !WriteParcelableVector(infos, reply)) {
1876         APP_LOGE("write extension infos failed");
1877         return ERR_APPEXECFWK_PARCEL_ERROR;
1878     }
1879     return ERR_OK;
1880 }
1881 
HandleVerifyCallingPermission(MessageParcel & data,MessageParcel & reply)1882 ErrCode BundleMgrHost::HandleVerifyCallingPermission(MessageParcel &data, MessageParcel &reply)
1883 {
1884     std::string permission = data.ReadString();
1885 
1886     bool ret = VerifyCallingPermission(permission);
1887     if (!reply.WriteBool(ret)) {
1888         APP_LOGE("write result failed");
1889         return ERR_APPEXECFWK_PARCEL_ERROR;
1890     }
1891     return ERR_OK;
1892 }
1893 
HandleQueryExtensionAbilityInfoByUri(MessageParcel & data,MessageParcel & reply)1894 ErrCode BundleMgrHost::HandleQueryExtensionAbilityInfoByUri(MessageParcel &data, MessageParcel &reply)
1895 {
1896     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1897     std::string uri = data.ReadString();
1898     int32_t userId = data.ReadInt32();
1899     ExtensionAbilityInfo extensionAbilityInfo;
1900     bool ret = QueryExtensionAbilityInfoByUri(uri, userId, extensionAbilityInfo);
1901     if (!reply.WriteBool(ret)) {
1902         APP_LOGE("write failed");
1903         return ERR_APPEXECFWK_PARCEL_ERROR;
1904     }
1905     if (ret) {
1906         if (!reply.WriteParcelable(&extensionAbilityInfo)) {
1907             APP_LOGE("write failed");
1908             return ERR_APPEXECFWK_PARCEL_ERROR;
1909         }
1910     }
1911     return ERR_OK;
1912 }
1913 
HandleGetAppIdByBundleName(MessageParcel & data,MessageParcel & reply)1914 ErrCode BundleMgrHost::HandleGetAppIdByBundleName(MessageParcel &data, MessageParcel &reply)
1915 {
1916     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1917     std::string bundleName = data.ReadString();
1918     int32_t userId = data.ReadInt32();
1919     std::string appId = GetAppIdByBundleName(bundleName, userId);
1920     APP_LOGD("appId is %{private}s", appId.c_str());
1921     if (!reply.WriteString(appId)) {
1922         APP_LOGE("write failed");
1923         return ERR_APPEXECFWK_PARCEL_ERROR;
1924     }
1925     return ERR_OK;
1926 }
1927 
HandleGetAppType(MessageParcel & data,MessageParcel & reply)1928 ErrCode BundleMgrHost::HandleGetAppType(MessageParcel &data, MessageParcel &reply)
1929 {
1930     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1931     std::string bundleName = data.ReadString();
1932     std::string appType = GetAppType(bundleName);
1933     APP_LOGD("appType is %{public}s", appType.c_str());
1934     if (!reply.WriteString(appType)) {
1935         APP_LOGE("write failed");
1936         return ERR_APPEXECFWK_PARCEL_ERROR;
1937     }
1938     return ERR_OK;
1939 }
1940 
HandleGetUidByBundleName(MessageParcel & data,MessageParcel & reply)1941 ErrCode BundleMgrHost::HandleGetUidByBundleName(MessageParcel &data, MessageParcel &reply)
1942 {
1943     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1944     std::string bundleName = data.ReadString();
1945     int32_t userId = data.ReadInt32();
1946     int32_t uid = GetUidByBundleName(bundleName, userId);
1947     APP_LOGD("uid is %{public}d", uid);
1948     if (!reply.WriteInt32(uid)) {
1949         APP_LOGE("write failed");
1950         return ERR_APPEXECFWK_PARCEL_ERROR;
1951     }
1952     return ERR_OK;
1953 }
1954 
HandleGetUidByDebugBundleName(MessageParcel & data,MessageParcel & reply)1955 ErrCode BundleMgrHost::HandleGetUidByDebugBundleName(MessageParcel &data, MessageParcel &reply)
1956 {
1957     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1958     std::string bundleName = data.ReadString();
1959     int32_t userId = data.ReadInt32();
1960     int32_t uid = GetUidByDebugBundleName(bundleName, userId);
1961     APP_LOGD("uid is %{public}d", uid);
1962     if (!reply.WriteInt32(uid)) {
1963         APP_LOGE("write failed");
1964         return ERR_APPEXECFWK_PARCEL_ERROR;
1965     }
1966     return ERR_OK;
1967 }
1968 
HandleIsModuleRemovable(MessageParcel & data,MessageParcel & reply)1969 ErrCode BundleMgrHost::HandleIsModuleRemovable(MessageParcel &data, MessageParcel &reply)
1970 {
1971     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1972     std::string bundleName = data.ReadString();
1973     std::string moduleName = data.ReadString();
1974 
1975     APP_LOGD("bundleName %{public}s, moduleName %{public}s", bundleName.c_str(), moduleName.c_str());
1976     bool isRemovable = false;
1977     ErrCode ret = IsModuleRemovable(bundleName, moduleName, isRemovable);
1978     if (!reply.WriteInt32(ret)) {
1979         APP_LOGE("write ret failed");
1980         return ERR_APPEXECFWK_PARCEL_ERROR;
1981     }
1982     if (!reply.WriteBool(isRemovable)) {
1983         APP_LOGE("write isRemovable failed");
1984         return ERR_APPEXECFWK_PARCEL_ERROR;
1985     }
1986     return ERR_OK;
1987 }
1988 
HandleSetModuleRemovable(MessageParcel & data,MessageParcel & reply)1989 ErrCode BundleMgrHost::HandleSetModuleRemovable(MessageParcel &data, MessageParcel &reply)
1990 {
1991     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1992     std::string bundleName = data.ReadString();
1993     std::string moduleName = data.ReadString();
1994     bool isEnable = data.ReadBool();
1995     APP_LOGD("bundleName %{public}s, moduleName %{public}s", bundleName.c_str(), moduleName.c_str());
1996     bool ret = SetModuleRemovable(bundleName, moduleName, isEnable);
1997     if (!reply.WriteBool(ret)) {
1998         APP_LOGE("write failed");
1999         return ERR_APPEXECFWK_PARCEL_ERROR;
2000     }
2001     return ERR_OK;
2002 }
2003 
HandleGetModuleUpgradeFlag(MessageParcel & data,MessageParcel & reply)2004 ErrCode BundleMgrHost::HandleGetModuleUpgradeFlag(MessageParcel &data, MessageParcel &reply)
2005 {
2006     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2007     std::string bundleName = data.ReadString();
2008     std::string moduleName = data.ReadString();
2009 
2010     APP_LOGD("bundleName %{public}s, moduleName %{public}s", bundleName.c_str(), moduleName.c_str());
2011     bool ret = GetModuleUpgradeFlag(bundleName, moduleName);
2012     if (!reply.WriteBool(ret)) {
2013         APP_LOGE("write failed");
2014         return ERR_APPEXECFWK_PARCEL_ERROR;
2015     }
2016     return ERR_OK;
2017 }
2018 
HandleSetModuleUpgradeFlag(MessageParcel & data,MessageParcel & reply)2019 ErrCode BundleMgrHost::HandleSetModuleUpgradeFlag(MessageParcel &data, MessageParcel &reply)
2020 {
2021     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2022     std::string bundleName = data.ReadString();
2023     std::string moduleName = data.ReadString();
2024     int32_t upgradeFlag = data.ReadInt32();
2025     APP_LOGD("bundleName %{public}s, moduleName %{public}s", bundleName.c_str(), moduleName.c_str());
2026     ErrCode ret = SetModuleUpgradeFlag(bundleName, moduleName, upgradeFlag);
2027     if (!reply.WriteInt32(ret)) {
2028         APP_LOGE("write failed");
2029         return ERR_APPEXECFWK_PARCEL_ERROR;
2030     }
2031     return ERR_OK;
2032 }
2033 
HandleImplicitQueryInfoByPriority(MessageParcel & data,MessageParcel & reply)2034 ErrCode BundleMgrHost::HandleImplicitQueryInfoByPriority(MessageParcel &data, MessageParcel &reply)
2035 {
2036     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2037     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2038     if (want == nullptr) {
2039         APP_LOGE("ReadParcelable<want> failed");
2040         return ERR_APPEXECFWK_PARCEL_ERROR;
2041     }
2042     int32_t flags = data.ReadInt32();
2043     int32_t userId = data.ReadInt32();
2044     AbilityInfo abilityInfo;
2045     ExtensionAbilityInfo extensionInfo;
2046     bool ret = ImplicitQueryInfoByPriority(*want, flags, userId, abilityInfo, extensionInfo);
2047     if (!reply.WriteBool(ret)) {
2048         APP_LOGE("write failed");
2049         return ERR_APPEXECFWK_PARCEL_ERROR;
2050     }
2051     if (ret) {
2052         if (!reply.WriteParcelable(&abilityInfo)) {
2053             APP_LOGE("write AbilityInfo failed");
2054             return ERR_APPEXECFWK_PARCEL_ERROR;
2055         }
2056         if (!reply.WriteParcelable(&extensionInfo)) {
2057             APP_LOGE("write ExtensionAbilityInfo failed");
2058             return ERR_APPEXECFWK_PARCEL_ERROR;
2059         }
2060     }
2061     return ERR_OK;
2062 }
2063 
HandleImplicitQueryInfos(MessageParcel & data,MessageParcel & reply)2064 ErrCode BundleMgrHost::HandleImplicitQueryInfos(MessageParcel &data, MessageParcel &reply)
2065 {
2066     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2067     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2068     if (want == nullptr) {
2069         APP_LOGE("ReadParcelable want failed.");
2070         return ERR_APPEXECFWK_PARCEL_ERROR;
2071     }
2072     int32_t flags = data.ReadInt32();
2073     int32_t userId = data.ReadInt32();
2074     bool withDefault = data.ReadBool();
2075     std::vector<AbilityInfo> abilityInfos;
2076     std::vector<ExtensionAbilityInfo> extensionInfos;
2077     bool ret = ImplicitQueryInfos(*want, flags, userId, withDefault, abilityInfos, extensionInfos);
2078     if (!reply.WriteBool(ret)) {
2079         APP_LOGE("WriteBool ret failed.");
2080         return ERR_APPEXECFWK_PARCEL_ERROR;
2081     }
2082     if (ret) {
2083         if (!WriteParcelableVector(abilityInfos, reply)) {
2084             APP_LOGE("WriteParcelableVector abilityInfos failed.");
2085             return ERR_APPEXECFWK_PARCEL_ERROR;
2086         }
2087         if (!WriteParcelableVector(extensionInfos, reply)) {
2088             APP_LOGE("WriteParcelableVector extensionInfo failed.");
2089             return ERR_APPEXECFWK_PARCEL_ERROR;
2090         }
2091     }
2092     return ERR_OK;
2093 }
2094 
HandleGetAllDependentModuleNames(MessageParcel & data,MessageParcel & reply)2095 ErrCode BundleMgrHost::HandleGetAllDependentModuleNames(MessageParcel &data, MessageParcel &reply)
2096 {
2097     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2098     std::string bundleName = data.ReadString();
2099     std::string moduleName = data.ReadString();
2100     std::vector<std::string> dependentModuleNames;
2101     bool ret = GetAllDependentModuleNames(bundleName, moduleName, dependentModuleNames);
2102     if (!reply.WriteBool(ret)) {
2103         APP_LOGE("write result failed");
2104         return ERR_APPEXECFWK_PARCEL_ERROR;
2105     }
2106     if (ret && !reply.WriteStringVector(dependentModuleNames)) {
2107         APP_LOGE("write dependentModuleNames failed");
2108         return ERR_APPEXECFWK_PARCEL_ERROR;
2109     }
2110     return ERR_OK;
2111 }
2112 
HandleGetSandboxBundleInfo(MessageParcel & data,MessageParcel & reply)2113 ErrCode BundleMgrHost::HandleGetSandboxBundleInfo(MessageParcel &data, MessageParcel &reply)
2114 {
2115     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2116     std::string bundleName = data.ReadString();
2117     int32_t appIndex = data.ReadInt32();
2118     int32_t userId = data.ReadInt32();
2119 
2120     BundleInfo info;
2121     auto res = GetSandboxBundleInfo(bundleName, appIndex, userId, info);
2122     if (!reply.WriteInt32(res)) {
2123         return ERR_APPEXECFWK_SANDBOX_INSTALL_WRITE_PARCEL_ERROR;
2124     }
2125     if ((res == ERR_OK) && (!reply.WriteParcelable(&info))) {
2126         return ERR_APPEXECFWK_SANDBOX_INSTALL_WRITE_PARCEL_ERROR;
2127     }
2128     return ERR_OK;
2129 }
2130 
HandleObtainCallingBundleName(MessageParcel & data,MessageParcel & reply)2131 ErrCode BundleMgrHost::HandleObtainCallingBundleName(MessageParcel &data, MessageParcel &reply)
2132 {
2133     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2134     std::string bundleName = "";
2135     auto ret = ObtainCallingBundleName(bundleName);
2136     if (!reply.WriteBool(ret)) {
2137         APP_LOGE("write result failed");
2138         return ERR_APPEXECFWK_PARCEL_ERROR;
2139     }
2140     if (ret && !reply.WriteString(bundleName)) {
2141         APP_LOGE("write bundleName failed");
2142         return ERR_APPEXECFWK_PARCEL_ERROR;
2143     }
2144     return ERR_OK;
2145 }
2146 
HandleCheckAbilityEnableInstall(MessageParcel & data,MessageParcel & reply)2147 ErrCode BundleMgrHost::HandleCheckAbilityEnableInstall(MessageParcel &data, MessageParcel &reply)
2148 {
2149     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2150     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2151     if (want == nullptr) {
2152         APP_LOGE("ReadParcelable<want> failed");
2153         return ERR_APPEXECFWK_PARCEL_ERROR;
2154     }
2155     int32_t missionId = data.ReadInt32();
2156     int32_t userId = data.ReadInt32();
2157     sptr<IRemoteObject> object = data.ReadRemoteObject();
2158 
2159     auto ret = CheckAbilityEnableInstall(*want, missionId, userId, object);
2160     if (!reply.WriteBool(ret)) {
2161         APP_LOGE("write result failed");
2162         return ERR_APPEXECFWK_PARCEL_ERROR;
2163     }
2164 
2165     return ERR_OK;
2166 }
2167 
HandleGetStringById(MessageParcel & data,MessageParcel & reply)2168 ErrCode BundleMgrHost::HandleGetStringById(MessageParcel &data, MessageParcel &reply)
2169 {
2170     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2171     std::string bundleName = data.ReadString();
2172     std::string moduleName = data.ReadString();
2173     uint32_t resId = data.ReadUint32();
2174     int32_t userId = data.ReadInt32();
2175     std::string localeInfo = data.ReadString();
2176     APP_LOGD("GetStringById bundleName: %{public}s, moduleName: %{public}s, resId:%{public}d",
2177         bundleName.c_str(), moduleName.c_str(), resId);
2178     if (bundleName.empty() || moduleName.empty()) {
2179         APP_LOGW("fail to GetStringById due to params empty");
2180         return ERR_INVALID_VALUE;
2181     }
2182     std::string label = GetStringById(bundleName, moduleName, resId, userId, localeInfo);
2183     if (!reply.WriteString(label)) {
2184         APP_LOGE("write failed");
2185         return ERR_APPEXECFWK_PARCEL_ERROR;
2186     }
2187     return ERR_OK;
2188 }
2189 
HandleGetIconById(MessageParcel & data,MessageParcel & reply)2190 ErrCode BundleMgrHost::HandleGetIconById(MessageParcel &data, MessageParcel &reply)
2191 {
2192     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2193     std::string bundleName = data.ReadString();
2194     std::string moduleName = data.ReadString();
2195     uint32_t resId = data.ReadUint32();
2196     uint32_t density = data.ReadUint32();
2197     int32_t userId = data.ReadInt32();
2198     APP_LOGD("GetStringById bundleName: %{public}s, moduleName: %{public}s, resId:%{public}d, density:%{public}d",
2199         bundleName.c_str(), moduleName.c_str(), resId, density);
2200     if (bundleName.empty() || moduleName.empty()) {
2201         APP_LOGW("fail to GetStringById due to params empty");
2202         return ERR_INVALID_VALUE;
2203     }
2204     std::string label = GetIconById(bundleName, moduleName, resId, density, userId);
2205     if (!reply.WriteString(label)) {
2206         APP_LOGE("write failed");
2207         return ERR_APPEXECFWK_PARCEL_ERROR;
2208     }
2209     return ERR_OK;
2210 }
2211 
2212 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
HandleGetDefaultAppProxy(MessageParcel & data,MessageParcel & reply)2213 ErrCode BundleMgrHost::HandleGetDefaultAppProxy(MessageParcel &data, MessageParcel &reply)
2214 {
2215     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2216     sptr<IDefaultApp> defaultAppProxy = GetDefaultAppProxy();
2217     if (defaultAppProxy == nullptr) {
2218         APP_LOGE("defaultAppProxy is nullptr.");
2219         return ERR_APPEXECFWK_PARCEL_ERROR;
2220     }
2221 
2222     if (!reply.WriteRemoteObject(defaultAppProxy->AsObject())) {
2223         APP_LOGE("WriteRemoteObject failed.");
2224         return ERR_APPEXECFWK_PARCEL_ERROR;
2225     }
2226     return ERR_OK;
2227 }
2228 #endif
2229 
2230 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
HandleGetAppControlProxy(MessageParcel & data,MessageParcel & reply)2231 ErrCode BundleMgrHost::HandleGetAppControlProxy(MessageParcel &data, MessageParcel &reply)
2232 {
2233     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2234     sptr<IAppControlMgr> appControlProxy = GetAppControlProxy();
2235     if (appControlProxy == nullptr) {
2236         APP_LOGE("appControlProxy is nullptr.");
2237         return ERR_APPEXECFWK_PARCEL_ERROR;
2238     }
2239 
2240     if (!reply.WriteRemoteObject(appControlProxy->AsObject())) {
2241         APP_LOGE("WriteRemoteObject failed.");
2242         return ERR_APPEXECFWK_PARCEL_ERROR;
2243     }
2244     return ERR_OK;
2245 }
2246 #endif
2247 
HandleGetSandboxAbilityInfo(MessageParcel & data,MessageParcel & reply)2248 ErrCode BundleMgrHost::HandleGetSandboxAbilityInfo(MessageParcel &data, MessageParcel &reply)
2249 {
2250     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2251     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2252     if (want == nullptr) {
2253         APP_LOGE("ReadParcelable<want> failed");
2254         return ERR_APPEXECFWK_PARCEL_ERROR;
2255     }
2256 
2257     int32_t appIndex = data.ReadInt32();
2258     int32_t flag = data.ReadInt32();
2259     int32_t userId = data.ReadInt32();
2260     AbilityInfo info;
2261     auto res = GetSandboxAbilityInfo(*want, appIndex, flag, userId, info);
2262     if (!reply.WriteInt32(res)) {
2263         APP_LOGE("write result failed");
2264         return ERR_APPEXECFWK_PARCEL_ERROR;
2265     }
2266     if ((res == ERR_OK) && (!reply.WriteParcelable(&info))) {
2267         APP_LOGE("write ability info failed");
2268         return ERR_APPEXECFWK_PARCEL_ERROR;
2269     }
2270     return ERR_OK;
2271 }
2272 
HandleGetSandboxExtAbilityInfos(MessageParcel & data,MessageParcel & reply)2273 ErrCode BundleMgrHost::HandleGetSandboxExtAbilityInfos(MessageParcel &data, MessageParcel &reply)
2274 {
2275     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2276     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2277     if (!want) {
2278         APP_LOGE("ReadParcelable<want> failed");
2279         return ERR_APPEXECFWK_PARCEL_ERROR;
2280     }
2281 
2282     int32_t appIndex = data.ReadInt32();
2283     int32_t flag = data.ReadInt32();
2284     int32_t userId = data.ReadInt32();
2285     std::vector<ExtensionAbilityInfo> infos;
2286     auto res = GetSandboxExtAbilityInfos(*want, appIndex, flag, userId, infos);
2287     if (!reply.WriteInt32(res)) {
2288         APP_LOGE("write result failed");
2289         return ERR_APPEXECFWK_PARCEL_ERROR;
2290     }
2291     if ((res == ERR_OK) && (!WriteParcelableVector(infos, reply))) {
2292         APP_LOGE("write extension infos failed");
2293         return ERR_APPEXECFWK_PARCEL_ERROR;
2294     }
2295     return ERR_OK;
2296 }
2297 
HandleGetSandboxHapModuleInfo(MessageParcel & data,MessageParcel & reply)2298 ErrCode BundleMgrHost::HandleGetSandboxHapModuleInfo(MessageParcel &data, MessageParcel &reply)
2299 {
2300     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2301     std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
2302     if (abilityInfo == nullptr) {
2303         APP_LOGE("ReadParcelable<abilityInfo> failed");
2304         return ERR_APPEXECFWK_PARCEL_ERROR;
2305     }
2306     int32_t appIndex = data.ReadInt32();
2307     int32_t userId = data.ReadInt32();
2308     HapModuleInfo info;
2309     auto res = GetSandboxHapModuleInfo(*abilityInfo, appIndex, userId, info);
2310     if (!reply.WriteInt32(res)) {
2311         APP_LOGE("write failed");
2312         return ERR_APPEXECFWK_PARCEL_ERROR;
2313     }
2314     if ((res == ERR_OK) && (!reply.WriteParcelable(&info))) {
2315         APP_LOGE("write hap module info failed");
2316         return ERR_APPEXECFWK_PARCEL_ERROR;
2317     }
2318     return ERR_OK;
2319 }
2320 
HandleGetQuickFixManagerProxy(MessageParcel & data,MessageParcel & reply)2321 ErrCode BundleMgrHost::HandleGetQuickFixManagerProxy(MessageParcel &data, MessageParcel &reply)
2322 {
2323     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2324     sptr<IQuickFixManager> quickFixManagerProxy = GetQuickFixManagerProxy();
2325     if (quickFixManagerProxy == nullptr) {
2326         APP_LOGE("quickFixManagerProxy is nullptr.");
2327         return ERR_APPEXECFWK_PARCEL_ERROR;
2328     }
2329 
2330     if (!reply.WriteRemoteObject(quickFixManagerProxy->AsObject())) {
2331         APP_LOGE("WriteRemoteObject failed.");
2332         return ERR_APPEXECFWK_PARCEL_ERROR;
2333     }
2334     return ERR_OK;
2335 }
2336 
HandleVerifySystemApi(MessageParcel & data,MessageParcel & reply)2337 ErrCode BundleMgrHost::HandleVerifySystemApi(MessageParcel &data, MessageParcel &reply)
2338 {
2339     int32_t beginApiVersion = data.ReadInt32();
2340 
2341     bool ret = VerifySystemApi(beginApiVersion);
2342     if (!reply.WriteBool(ret)) {
2343         APP_LOGE("write result failed");
2344         return ERR_APPEXECFWK_PARCEL_ERROR;
2345     }
2346     return ERR_OK;
2347 }
2348 
2349 template<typename T>
WriteParcelableVector(std::vector<T> & parcelableVector,MessageParcel & reply)2350 bool BundleMgrHost::WriteParcelableVector(std::vector<T> &parcelableVector, MessageParcel &reply)
2351 {
2352     if (!reply.WriteInt32(parcelableVector.size())) {
2353         APP_LOGE("write ParcelableVector failed");
2354         return false;
2355     }
2356 
2357     for (auto &parcelable : parcelableVector) {
2358         if (!reply.WriteParcelable(&parcelable)) {
2359             APP_LOGE("write ParcelableVector failed");
2360             return false;
2361         }
2362     }
2363     return true;
2364 }
2365 
2366 template<typename T>
WriteVectorToParcelIntelligent(std::vector<T> & parcelableVector,MessageParcel & reply)2367 bool BundleMgrHost::WriteVectorToParcelIntelligent(std::vector<T> &parcelableVector, MessageParcel &reply)
2368 {
2369     Parcel tempParcel;
2370     (void)tempParcel.SetMaxCapacity(MAX_PARCEL_CAPACITY);
2371     if (!tempParcel.WriteInt32(parcelableVector.size())) {
2372         APP_LOGE("write ParcelableVector failed");
2373         return false;
2374     }
2375 
2376     for (auto &parcelable : parcelableVector) {
2377         if (!tempParcel.WriteParcelable(&parcelable)) {
2378             APP_LOGE("write ParcelableVector failed");
2379             return false;
2380         }
2381     }
2382 
2383     size_t dataSize = tempParcel.GetDataSize();
2384     if (!reply.WriteInt32(static_cast<int32_t>(dataSize))) {
2385         APP_LOGE("write WriteInt32 failed");
2386         return false;
2387     }
2388 
2389     if (!reply.WriteRawData(
2390         reinterpret_cast<uint8_t *>(tempParcel.GetData()), dataSize)) {
2391         APP_LOGE("Failed to write data");
2392         return false;
2393     }
2394 
2395     return true;
2396 }
2397 
AllocatAshmemNum()2398 int32_t BundleMgrHost::AllocatAshmemNum()
2399 {
2400     std::lock_guard<std::mutex> lock(bundleAshmemMutex_);
2401     return ashmemNum_++;
2402 }
2403 
HandleQueryAbilityInfoWithCallback(MessageParcel & data,MessageParcel & reply)2404 ErrCode BundleMgrHost::HandleQueryAbilityInfoWithCallback(MessageParcel &data, MessageParcel &reply)
2405 {
2406     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2407     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2408     if (want == nullptr) {
2409         APP_LOGE("ReadParcelable<want> failed");
2410         return ERR_APPEXECFWK_PARCEL_ERROR;
2411     }
2412     int32_t flags = data.ReadInt32();
2413     int32_t userId = data.ReadInt32();
2414     sptr<IRemoteObject> object = data.ReadRemoteObject();
2415     AbilityInfo info;
2416     bool ret = QueryAbilityInfo(*want, flags, userId, info, object);
2417     if (!reply.WriteBool(ret)) {
2418         APP_LOGE("write ret failed");
2419         return ERR_APPEXECFWK_PARCEL_ERROR;
2420     }
2421     if (ret) {
2422         if (!reply.WriteParcelable(&info)) {
2423             APP_LOGE("write info failed");
2424             return ERR_APPEXECFWK_PARCEL_ERROR;
2425         }
2426     }
2427     return ERR_OK;
2428 }
2429 
HandleSilentInstall(MessageParcel & data,MessageParcel & reply)2430 ErrCode BundleMgrHost::HandleSilentInstall(MessageParcel &data, MessageParcel &reply)
2431 {
2432     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2433     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2434     if (want == nullptr) {
2435         APP_LOGE("ReadParcelable<want> failed");
2436         return ERR_APPEXECFWK_PARCEL_ERROR;
2437     }
2438     int32_t userId = data.ReadInt32();
2439     sptr<IRemoteObject> object = data.ReadRemoteObject();
2440     bool ret = SilentInstall(*want, userId, object);
2441     if (!reply.WriteBool(ret)) {
2442         APP_LOGE("write ret failed");
2443         return ERR_APPEXECFWK_PARCEL_ERROR;
2444     }
2445     return ERR_OK;
2446 }
2447 
HandleUpgradeAtomicService(MessageParcel & data,MessageParcel & reply)2448 ErrCode BundleMgrHost::HandleUpgradeAtomicService(MessageParcel &data, MessageParcel &reply)
2449 {
2450     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2451     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2452     if (want == nullptr) {
2453         APP_LOGE("read parcelable want failed");
2454         return ERR_APPEXECFWK_PARCEL_ERROR;
2455     }
2456     int32_t userId = data.ReadInt32();
2457     UpgradeAtomicService(*want, userId);
2458     return ERR_OK;
2459 }
2460 
HandleGetBundleStats(MessageParcel & data,MessageParcel & reply)2461 ErrCode BundleMgrHost::HandleGetBundleStats(MessageParcel &data, MessageParcel &reply)
2462 {
2463     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2464     std::string bundleName = data.ReadString();
2465     int32_t userId = data.ReadInt32();
2466     std::vector<int64_t> bundleStats;
2467     bool ret = GetBundleStats(bundleName, userId, bundleStats);
2468     if (!reply.WriteBool(ret)) {
2469         APP_LOGE("write result failed");
2470         return ERR_APPEXECFWK_PARCEL_ERROR;
2471     }
2472     if (ret && !reply.WriteInt64Vector(bundleStats)) {
2473         APP_LOGE("write bundleStats failed");
2474         return ERR_APPEXECFWK_PARCEL_ERROR;
2475     }
2476     return ERR_OK;
2477 }
2478 
HandleGetAllBundleStats(MessageParcel & data,MessageParcel & reply)2479 ErrCode BundleMgrHost::HandleGetAllBundleStats(MessageParcel &data, MessageParcel &reply)
2480 {
2481     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2482     int32_t userId = data.ReadInt32();
2483     std::vector<int64_t> bundleStats;
2484     bool ret = GetAllBundleStats(userId, bundleStats);
2485     if (!reply.WriteBool(ret)) {
2486         APP_LOGE("write result failed");
2487         return ERR_APPEXECFWK_PARCEL_ERROR;
2488     }
2489     if (ret && !reply.WriteInt64Vector(bundleStats)) {
2490         APP_LOGE("write bundleStats failed");
2491         return ERR_APPEXECFWK_PARCEL_ERROR;
2492     }
2493     return ERR_OK;
2494 }
2495 
HandleGetMediaData(MessageParcel & data,MessageParcel & reply)2496 ErrCode BundleMgrHost::HandleGetMediaData(MessageParcel &data, MessageParcel &reply)
2497 {
2498     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2499     std::string bundleName = data.ReadString();
2500     std::string abilityName = data.ReadString();
2501     std::string moduleName = data.ReadString();
2502     int32_t userId = data.ReadInt32();
2503     APP_LOGD("HandleGetMediaData:%{public}s, %{public}s, %{public}s", bundleName.c_str(),
2504         abilityName.c_str(), moduleName.c_str());
2505     std::unique_ptr<uint8_t[]> mediaDataPtr = nullptr;
2506     size_t len = 0;
2507     ErrCode ret = GetMediaData(bundleName, moduleName, abilityName, mediaDataPtr, len, userId);
2508     if (!reply.WriteInt32(ret)) {
2509         APP_LOGE("write ret failed");
2510         return ERR_APPEXECFWK_PARCEL_ERROR;
2511     }
2512     if (ret != ERR_OK) {
2513         return ret;
2514     }
2515     if (mediaDataPtr == nullptr || len == 0) {
2516         return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
2517     }
2518     // write ashMem
2519     sptr<Ashmem> ashMem = Ashmem::CreateAshmem((__func__ + std::to_string(AllocatAshmemNum())).c_str(), len);
2520     if (ashMem == nullptr) {
2521         APP_LOGE("CreateAshmem failed");
2522         return ERR_APPEXECFWK_PARCEL_ERROR;
2523     }
2524     if (!ashMem->MapReadAndWriteAshmem()) {
2525         APP_LOGE("MapReadAndWriteAshmem failed");
2526         ClearAshmem(ashMem);
2527         return ERR_APPEXECFWK_PARCEL_ERROR;
2528     }
2529     int32_t offset = 0;
2530     if (!ashMem->WriteToAshmem(mediaDataPtr.get(), len, offset)) {
2531         APP_LOGE("MapReadAndWriteAshmem failed");
2532         ClearAshmem(ashMem);
2533         return ERR_APPEXECFWK_PARCEL_ERROR;
2534     }
2535     MessageParcel *messageParcel = &reply;
2536     if (messageParcel == nullptr || !messageParcel->WriteAshmem(ashMem)) {
2537         APP_LOGE("WriteAshmem failed");
2538         ClearAshmem(ashMem);
2539         return ERR_APPEXECFWK_PARCEL_ERROR;
2540     }
2541     ClearAshmem(ashMem);
2542     return ERR_OK;
2543 }
2544 
HandleSetDebugMode(MessageParcel & data,MessageParcel & reply)2545 ErrCode BundleMgrHost::HandleSetDebugMode(MessageParcel &data, MessageParcel &reply)
2546 {
2547     APP_LOGI("start to process HandleSetDebugMode message");
2548     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2549     bool enable = data.ReadBool();
2550     auto ret = SetDebugMode(enable);
2551     if (ret != ERR_OK) {
2552         APP_LOGE("SetDebugMode failed");
2553     }
2554     if (!reply.WriteInt32(ret)) {
2555         APP_LOGE("write failed");
2556         return ERR_BUNDLEMANAGER_SET_DEBUG_MODE_PARCEL_ERROR;
2557     }
2558     return ERR_OK;
2559 }
2560 
HandleGetOverlayManagerProxy(MessageParcel & data,MessageParcel & reply)2561 ErrCode BundleMgrHost::HandleGetOverlayManagerProxy(MessageParcel &data, MessageParcel &reply)
2562 {
2563     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2564     sptr<IOverlayManager> overlayManagerProxy = GetOverlayManagerProxy();
2565     if (overlayManagerProxy == nullptr) {
2566         APP_LOGE("overlayManagerProxy is nullptr.");
2567         return ERR_APPEXECFWK_PARCEL_ERROR;
2568     }
2569 
2570     if (!reply.WriteRemoteObject(overlayManagerProxy->AsObject())) {
2571         APP_LOGE("WriteRemoteObject failed.");
2572         return ERR_APPEXECFWK_PARCEL_ERROR;
2573     }
2574     return ERR_OK;
2575 }
2576 
HandleProcessPreload(MessageParcel & data,MessageParcel & reply)2577 ErrCode BundleMgrHost::HandleProcessPreload(MessageParcel &data, MessageParcel &reply)
2578 {
2579     APP_LOGD("start to process HandleProcessPreload message");
2580     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2581     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2582     if (want == nullptr) {
2583         APP_LOGE("ReadParcelable<want> failed");
2584         return ERR_APPEXECFWK_PARCEL_ERROR;
2585     }
2586     auto ret = ProcessPreload(*want);
2587     if (!reply.WriteBool(ret)) {
2588         APP_LOGE("write result failed");
2589         return ERR_APPEXECFWK_PARCEL_ERROR;
2590     }
2591     return ERR_OK;
2592 }
2593 
HandleGetAppProvisionInfo(MessageParcel & data,MessageParcel & reply)2594 ErrCode BundleMgrHost::HandleGetAppProvisionInfo(MessageParcel &data, MessageParcel &reply)
2595 {
2596     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2597     std::string bundleName = data.ReadString();
2598     int32_t userId = data.ReadInt32();
2599     AppProvisionInfo appProvisionInfo;
2600     ErrCode ret = GetAppProvisionInfo(bundleName, userId, appProvisionInfo);
2601     if (!reply.WriteInt32(ret)) {
2602         APP_LOGE("HandleGetAppProvisionInfo write failed");
2603         return ERR_APPEXECFWK_PARCEL_ERROR;
2604     }
2605     if ((ret == ERR_OK) && !reply.WriteParcelable(&appProvisionInfo)) {
2606         APP_LOGE("write appProvisionInfo failed");
2607         return ERR_APPEXECFWK_PARCEL_ERROR;
2608     }
2609     return ERR_OK;
2610 }
2611 
HandleGetProvisionMetadata(MessageParcel & data,MessageParcel & reply)2612 ErrCode BundleMgrHost::HandleGetProvisionMetadata(MessageParcel &data, MessageParcel &reply)
2613 {
2614     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2615     std::string bundleName = data.ReadString();
2616     int32_t userId = data.ReadInt32();
2617     APP_LOGD("start to get provision metadata, bundleName is %{public}s, userId is %{public}d",
2618         bundleName.c_str(), userId);
2619     std::vector<Metadata> provisionMetadatas;
2620     ErrCode ret = GetProvisionMetadata(bundleName, userId, provisionMetadatas);
2621     if (ret != ERR_OK) {
2622         APP_LOGE("GetProvisionMetadata failed");
2623     }
2624     if (!reply.WriteInt32(ret)) {
2625         APP_LOGE("write failed");
2626         return ERR_APPEXECFWK_PARCEL_ERROR;
2627     }
2628     if (ret == ERR_OK) {
2629         if (!WriteParcelableVector(provisionMetadatas, reply)) {
2630             APP_LOGE("write failed");
2631             return ERR_APPEXECFWK_PARCEL_ERROR;
2632         }
2633     }
2634     return ERR_OK;
2635 }
2636 
HandleGetBaseSharedBundleInfos(MessageParcel & data,MessageParcel & reply)2637 ErrCode BundleMgrHost::HandleGetBaseSharedBundleInfos(MessageParcel &data, MessageParcel &reply)
2638 {
2639     APP_LOGD("start to process HandleGetBaseSharedBundleInfos message");
2640     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2641     std::string bundleName = data.ReadString();
2642     GetDependentBundleInfoFlag flag = static_cast<GetDependentBundleInfoFlag>(data.ReadUint32());
2643 
2644     std::vector<BaseSharedBundleInfo> infos;
2645     ErrCode ret = GetBaseSharedBundleInfos(bundleName, infos, flag);
2646     if (!reply.WriteInt32(ret)) {
2647         APP_LOGE("write failed");
2648         return ERR_APPEXECFWK_PARCEL_ERROR;
2649     }
2650     if (ret != ERR_OK) {
2651         return ret;
2652     }
2653     if (!WriteParcelableVector(infos, reply)) {
2654         APP_LOGE("write failed");
2655         return ERR_APPEXECFWK_PARCEL_ERROR;
2656     }
2657     return ERR_OK;
2658 }
2659 
HandleGetAllSharedBundleInfo(MessageParcel & data,MessageParcel & reply)2660 ErrCode BundleMgrHost::HandleGetAllSharedBundleInfo(MessageParcel &data, MessageParcel &reply)
2661 {
2662     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2663     std::vector<SharedBundleInfo> infos;
2664     ErrCode ret = GetAllSharedBundleInfo(infos);
2665     if (!reply.WriteInt32(ret)) {
2666         APP_LOGE("HandleGetAllSharedBundleInfo write failed");
2667         return ERR_APPEXECFWK_PARCEL_ERROR;
2668     }
2669     if ((ret == ERR_OK) && !WriteParcelableVector(infos, reply)) {
2670         APP_LOGE("write infos failed");
2671         return ERR_APPEXECFWK_PARCEL_ERROR;
2672     }
2673     return ERR_OK;
2674 }
2675 
HandleGetSharedBundleInfo(MessageParcel & data,MessageParcel & reply)2676 ErrCode BundleMgrHost::HandleGetSharedBundleInfo(MessageParcel &data, MessageParcel &reply)
2677 {
2678     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2679     std::string bundleName = data.ReadString();
2680     std::string moduleName = data.ReadString();
2681     std::vector<SharedBundleInfo> infos;
2682     ErrCode ret = GetSharedBundleInfo(bundleName, moduleName, infos);
2683     if (!reply.WriteInt32(ret)) {
2684         APP_LOGE("HandleGetSharedBundleInfo write failed");
2685         return ERR_APPEXECFWK_PARCEL_ERROR;
2686     }
2687     if ((ret == ERR_OK) && !WriteParcelableVector(infos, reply)) {
2688         APP_LOGE("write infos failed");
2689         return ERR_APPEXECFWK_PARCEL_ERROR;
2690     }
2691     return ERR_OK;
2692 }
2693 
HandleGetSharedBundleInfoBySelf(MessageParcel & data,MessageParcel & reply)2694 ErrCode BundleMgrHost::HandleGetSharedBundleInfoBySelf(MessageParcel &data, MessageParcel &reply)
2695 {
2696     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2697     std::string bundleName = data.ReadString();
2698     SharedBundleInfo shareBundleInfo;
2699     ErrCode ret = GetSharedBundleInfoBySelf(bundleName, shareBundleInfo);
2700     if (!reply.WriteInt32(ret)) {
2701         APP_LOGE("HandleGetSharedBundleInfoBySelf write failed");
2702         return ERR_APPEXECFWK_PARCEL_ERROR;
2703     }
2704     if ((ret == ERR_OK) && !reply.WriteParcelable(&shareBundleInfo)) {
2705         APP_LOGE("write failed");
2706         return ERR_APPEXECFWK_PARCEL_ERROR;
2707     }
2708     return ERR_OK;
2709 }
2710 
HandleGetSharedDependencies(MessageParcel & data,MessageParcel & reply)2711 ErrCode BundleMgrHost::HandleGetSharedDependencies(MessageParcel &data, MessageParcel &reply)
2712 {
2713     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2714     std::string bundleName = data.ReadString();
2715     std::string moduleName = data.ReadString();
2716     std::vector<Dependency> dependencies;
2717     ErrCode ret = GetSharedDependencies(bundleName, moduleName, dependencies);
2718     if (!reply.WriteInt32(ret)) {
2719         APP_LOGE("HandleGetSharedDependencies write failed");
2720         return ERR_APPEXECFWK_PARCEL_ERROR;
2721     }
2722     if ((ret == ERR_OK) && !WriteParcelableVector(dependencies, reply)) {
2723         APP_LOGE("write dependencies failed");
2724         return ERR_APPEXECFWK_PARCEL_ERROR;
2725     }
2726     return ERR_OK;
2727 }
2728 
HandleGetProxyDataInfos(MessageParcel & data,MessageParcel & reply)2729 ErrCode BundleMgrHost::HandleGetProxyDataInfos(MessageParcel &data, MessageParcel &reply)
2730 {
2731     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2732     std::string bundleName = data.ReadString();
2733     std::string moduleName = data.ReadString();
2734     int32_t userId = data.ReadInt32();
2735     std::vector<ProxyData> proxyDatas;
2736     ErrCode ret = GetProxyDataInfos(bundleName, moduleName, proxyDatas, userId);
2737     if (!reply.WriteInt32(ret)) {
2738         APP_LOGE("HandleGetProxyDataInfos write failed");
2739         return ERR_APPEXECFWK_PARCEL_ERROR;
2740     }
2741     if ((ret == ERR_OK) && !WriteParcelableVector(proxyDatas, reply)) {
2742         APP_LOGE("write proxyDatas failed");
2743         return ERR_APPEXECFWK_PARCEL_ERROR;
2744     }
2745     return ERR_OK;
2746 }
2747 
HandleGetAllProxyDataInfos(MessageParcel & data,MessageParcel & reply)2748 ErrCode BundleMgrHost::HandleGetAllProxyDataInfos(MessageParcel &data, MessageParcel &reply)
2749 {
2750     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2751     std::vector<ProxyData> proxyDatas;
2752     int32_t userId = data.ReadInt32();
2753     ErrCode ret = GetAllProxyDataInfos(proxyDatas, userId);
2754     if (!reply.WriteInt32(ret)) {
2755         APP_LOGE("HandleGetProxyDataInfos write failed");
2756         return ERR_APPEXECFWK_PARCEL_ERROR;
2757     }
2758     if ((ret == ERR_OK) && !WriteParcelableVector(proxyDatas, reply)) {
2759         APP_LOGE("write proxyDatas failed");
2760         return ERR_APPEXECFWK_PARCEL_ERROR;
2761     }
2762     return ERR_OK;
2763 }
2764 
HandleGetSpecifiedDistributionType(MessageParcel & data,MessageParcel & reply)2765 ErrCode BundleMgrHost::HandleGetSpecifiedDistributionType(MessageParcel &data, MessageParcel &reply)
2766 {
2767     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2768     std::string bundleName = data.ReadString();
2769     std::string specifiedDistributedType;
2770     ErrCode ret = GetSpecifiedDistributionType(bundleName, specifiedDistributedType);
2771     if (!reply.WriteInt32(ret)) {
2772         APP_LOGE("HandleGetSpecifiedDistributionType write failed");
2773         return ERR_APPEXECFWK_PARCEL_ERROR;
2774     }
2775     if ((ret == ERR_OK) && !reply.WriteString(specifiedDistributedType)) {
2776         APP_LOGE("write specifiedDistributedType failed");
2777         return ERR_APPEXECFWK_PARCEL_ERROR;
2778     }
2779     return ERR_OK;
2780 }
2781 
HandleGetAdditionalInfo(MessageParcel & data,MessageParcel & reply)2782 ErrCode BundleMgrHost::HandleGetAdditionalInfo(MessageParcel &data, MessageParcel &reply)
2783 {
2784     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2785     std::string bundleName = data.ReadString();
2786     std::string additionalInfo;
2787     ErrCode ret = GetAdditionalInfo(bundleName, additionalInfo);
2788     if (!reply.WriteInt32(ret)) {
2789         APP_LOGE("HandleGetAdditionalInfo write failed");
2790         return ERR_APPEXECFWK_PARCEL_ERROR;
2791     }
2792     if ((ret == ERR_OK) && !reply.WriteString(additionalInfo)) {
2793         APP_LOGE("write additionalInfo failed");
2794         return ERR_APPEXECFWK_PARCEL_ERROR;
2795     }
2796     return ERR_OK;
2797 }
2798 
HandleSetExtNameOrMIMEToApp(MessageParcel & data,MessageParcel & reply)2799 ErrCode BundleMgrHost::HandleSetExtNameOrMIMEToApp(MessageParcel &data, MessageParcel &reply)
2800 {
2801     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2802     std::string bundleName = data.ReadString();
2803     std::string moduleName = data.ReadString();
2804     std::string abilityName = data.ReadString();
2805     std::string extName = data.ReadString();
2806     std::string mimeType = data.ReadString();
2807     ErrCode ret = SetExtNameOrMIMEToApp(bundleName, moduleName, abilityName, extName, mimeType);
2808     if (!reply.WriteInt32(ret)) {
2809         APP_LOGE("HandleSetExtNameOrMIMEToApp write failed");
2810         return ERR_APPEXECFWK_PARCEL_ERROR;
2811     }
2812     return ERR_OK;
2813 }
2814 
HandleDelExtNameOrMIMEToApp(MessageParcel & data,MessageParcel & reply)2815 ErrCode BundleMgrHost::HandleDelExtNameOrMIMEToApp(MessageParcel &data, MessageParcel &reply)
2816 {
2817     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2818     std::string bundleName = data.ReadString();
2819     std::string moduleName = data.ReadString();
2820     std::string abilityName = data.ReadString();
2821     std::string extName = data.ReadString();
2822     std::string mimeType = data.ReadString();
2823     ErrCode ret = DelExtNameOrMIMEToApp(bundleName, moduleName, abilityName, extName, mimeType);
2824     if (!reply.WriteInt32(ret)) {
2825         APP_LOGE("HandleDelExtNameOrMIMEToApp write failed");
2826         return ERR_APPEXECFWK_PARCEL_ERROR;
2827     }
2828     return ERR_OK;
2829 }
2830 
HandleQueryDataGroupInfos(MessageParcel & data,MessageParcel & reply)2831 ErrCode BundleMgrHost::HandleQueryDataGroupInfos(MessageParcel &data, MessageParcel &reply)
2832 {
2833     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2834     std::string bundleName = data.ReadString();
2835     int32_t userId = data.ReadInt32();
2836 
2837     std::vector<DataGroupInfo> infos;
2838     bool ret = QueryDataGroupInfos(bundleName, userId, infos);
2839     if (!reply.WriteBool(ret)) {
2840         APP_LOGE("write failed");
2841         return ERR_APPEXECFWK_PARCEL_ERROR;
2842     }
2843     if (ret && !WriteParcelableVector(infos, reply)) {
2844         APP_LOGE("write dataGroupInfo failed");
2845         return ERR_APPEXECFWK_PARCEL_ERROR;
2846     }
2847     return ERR_OK;
2848 }
2849 
HandleGetPreferenceDirByGroupId(MessageParcel & data,MessageParcel & reply)2850 ErrCode BundleMgrHost::HandleGetPreferenceDirByGroupId(MessageParcel &data, MessageParcel &reply)
2851 {
2852     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2853     std::string dataGroupId = data.ReadString();
2854     std::string dir;
2855     bool ret = GetGroupDir(dataGroupId, dir);
2856     if (!reply.WriteBool(ret)) {
2857         APP_LOGE("write failed");
2858         return ERR_APPEXECFWK_PARCEL_ERROR;
2859     }
2860     if (ret) {
2861         if (!reply.WriteString(dir)) {
2862             APP_LOGE("write failed");
2863             return ERR_APPEXECFWK_PARCEL_ERROR;
2864         }
2865     }
2866     return ERR_OK;
2867 }
2868 
HandleQueryAppGalleryBundleName(MessageParcel & data,MessageParcel & reply)2869 ErrCode BundleMgrHost::HandleQueryAppGalleryBundleName(MessageParcel &data, MessageParcel &reply)
2870 {
2871     APP_LOGD("QueryAppGalleryBundleName in bundle mgr hoxt start");
2872     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2873     std::string bundleName;
2874     bool ret = QueryAppGalleryBundleName(bundleName);
2875     if (!reply.WriteBool(ret)) {
2876         APP_LOGE("write failed");
2877         return ERR_APPEXECFWK_PARCEL_ERROR;
2878     }
2879     if (ret) {
2880         if (!reply.WriteString(bundleName)) {
2881             APP_LOGE("write failed");
2882             return ERR_APPEXECFWK_PARCEL_ERROR;
2883         }
2884     }
2885     APP_LOGD("BundleName is %{public}s", bundleName.c_str());
2886     return ERR_OK;
2887 }
2888 
HandleQueryExtensionAbilityInfosWithTypeName(MessageParcel & data,MessageParcel & reply)2889 ErrCode BundleMgrHost::HandleQueryExtensionAbilityInfosWithTypeName(MessageParcel &data, MessageParcel &reply)
2890 {
2891     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
2892     if (want == nullptr) {
2893         APP_LOGE("ReadParcelable<want> failed");
2894         return ERR_APPEXECFWK_PARCEL_ERROR;
2895     }
2896 
2897     std::string extensionTypeName = data.ReadString();
2898     int32_t flags = data.ReadInt32();
2899     int32_t userId = data.ReadInt32();
2900     std::vector<ExtensionAbilityInfo> extensionAbilityInfos;
2901     ErrCode ret =
2902         QueryExtensionAbilityInfosWithTypeName(*want, extensionTypeName, flags, userId, extensionAbilityInfos);
2903     if (!reply.WriteInt32(ret)) {
2904         APP_LOGE("Write result failed");
2905         return ERR_APPEXECFWK_PARCEL_ERROR;
2906     }
2907     if (ret == ERR_OK && !WriteParcelableVector(extensionAbilityInfos, reply)) {
2908         APP_LOGE("Write extension infos failed");
2909             return ERR_APPEXECFWK_PARCEL_ERROR;
2910     }
2911     return ERR_OK;
2912 }
2913 
HandleQueryExtensionAbilityInfosOnlyWithTypeName(MessageParcel & data,MessageParcel & reply)2914 ErrCode BundleMgrHost::HandleQueryExtensionAbilityInfosOnlyWithTypeName(MessageParcel &data, MessageParcel &reply)
2915 {
2916     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2917     std::string extensionTypeName = data.ReadString();
2918     uint32_t flags = data.ReadUint32();
2919     int32_t userId = data.ReadInt32();
2920     std::vector<ExtensionAbilityInfo> extensionAbilityInfos;
2921     ErrCode ret =
2922         QueryExtensionAbilityInfosOnlyWithTypeName(extensionTypeName, flags, userId, extensionAbilityInfos);
2923     if (!reply.WriteInt32(ret)) {
2924         APP_LOGE("Write result failed");
2925         return ERR_APPEXECFWK_PARCEL_ERROR;
2926     }
2927     if (ret == ERR_OK && !WriteVectorToParcelIntelligent(extensionAbilityInfos, reply)) {
2928         APP_LOGE("Write extension infos failed");
2929             return ERR_APPEXECFWK_PARCEL_ERROR;
2930     }
2931     return ERR_OK;
2932 }
2933 
HandleResetAOTCompileStatus(MessageParcel & data,MessageParcel & reply)2934 ErrCode BundleMgrHost::HandleResetAOTCompileStatus(MessageParcel &data, MessageParcel &reply)
2935 {
2936     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2937     std::string bundleName = data.ReadString();
2938     std::string moduleName = data.ReadString();
2939     int32_t triggerMode = data.ReadInt32();
2940     APP_LOGD("bundleName : %{public}s, moduleName : %{public}s, triggerMode : %{public}d",
2941         bundleName.c_str(), moduleName.c_str(), triggerMode);
2942     ErrCode ret = ResetAOTCompileStatus(bundleName, moduleName, triggerMode);
2943     APP_LOGD("ret : %{public}d", ret);
2944     if (!reply.WriteInt32(ret)) {
2945         APP_LOGE("write ret failed");
2946         return ERR_APPEXECFWK_PARCEL_ERROR;
2947     }
2948     return ERR_OK;
2949 }
2950 
HandleGetJsonProfile(MessageParcel & data,MessageParcel & reply)2951 ErrCode BundleMgrHost::HandleGetJsonProfile(MessageParcel &data, MessageParcel &reply)
2952 {
2953     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2954     ProfileType profileType = static_cast<ProfileType>(data.ReadInt32());
2955     std::string bundleName = data.ReadString();
2956     std::string moduleName = data.ReadString();
2957     int32_t userId = data.ReadInt32();
2958     std::string profile;
2959     ErrCode ret = GetJsonProfile(profileType, bundleName, moduleName, profile, userId);
2960     if (!reply.WriteInt32(ret)) {
2961         APP_LOGE("write failed");
2962         return ERR_APPEXECFWK_PARCEL_ERROR;
2963     }
2964     if (ret == ERR_OK && WriteBigString(profile, reply) != ERR_OK) {
2965         APP_LOGE("write failed");
2966         return ERR_APPEXECFWK_PARCEL_ERROR;
2967     }
2968     return ret;
2969 }
2970 
HandleGetBundleResourceProxy(MessageParcel & data,MessageParcel & reply)2971 ErrCode BundleMgrHost::HandleGetBundleResourceProxy(MessageParcel &data, MessageParcel &reply)
2972 {
2973     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2974     sptr<IBundleResource> bundleResourceProxy = GetBundleResourceProxy();
2975     if (bundleResourceProxy == nullptr) {
2976         APP_LOGE("bundleResourceProxy is nullptr.");
2977         return ERR_APPEXECFWK_PARCEL_ERROR;
2978     }
2979 
2980     if (!reply.WriteRemoteObject(bundleResourceProxy->AsObject())) {
2981         APP_LOGE("WriteRemoteObject failed.");
2982         return ERR_APPEXECFWK_PARCEL_ERROR;
2983     }
2984     return ERR_OK;
2985 }
2986 
HandleGetRecoverableApplicationInfo(MessageParcel & data,MessageParcel & reply)2987 ErrCode BundleMgrHost::HandleGetRecoverableApplicationInfo(MessageParcel &data, MessageParcel &reply)
2988 {
2989     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2990     std::vector<RecoverableApplicationInfo> infos;
2991     ErrCode ret = GetRecoverableApplicationInfo(infos);
2992     if (!reply.WriteInt32(ret)) {
2993         APP_LOGE("HandleGetRecoverableApplicationInfo write failed");
2994         return ERR_APPEXECFWK_PARCEL_ERROR;
2995     }
2996     if ((ret == ERR_OK) && !WriteParcelableVector(infos, reply)) {
2997         APP_LOGE("write infos failed");
2998         return ERR_APPEXECFWK_PARCEL_ERROR;
2999     }
3000     return ERR_OK;
3001 }
3002 
HandleGetUninstalledBundleInfo(MessageParcel & data,MessageParcel & reply)3003 ErrCode BundleMgrHost::HandleGetUninstalledBundleInfo(MessageParcel &data, MessageParcel &reply)
3004 {
3005     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3006     std::string name = data.ReadString();
3007     if (name.empty()) {
3008         APP_LOGE("bundleName is empty");
3009         return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
3010     }
3011     BundleInfo info;
3012     reply.SetDataCapacity(Constants::CAPACITY_SIZE);
3013     auto ret = GetUninstalledBundleInfo(name, info);
3014     if (!reply.WriteInt32(ret)) {
3015         APP_LOGE("write failed");
3016         return ERR_APPEXECFWK_PARCEL_ERROR;
3017     }
3018     if (ret == ERR_OK && !reply.WriteParcelable(&info)) {
3019         APP_LOGE("write failed");
3020         return ERR_APPEXECFWK_PARCEL_ERROR;
3021     }
3022     return ERR_OK;
3023 }
3024 
HandleSetAdditionalInfo(MessageParcel & data,MessageParcel & reply)3025 ErrCode BundleMgrHost::HandleSetAdditionalInfo(MessageParcel &data, MessageParcel &reply)
3026 {
3027     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3028     std::string bundleName = data.ReadString();
3029     std::string additionalInfo = data.ReadString();
3030     ErrCode ret = SetAdditionalInfo(bundleName, additionalInfo);
3031     if (!reply.WriteInt32(ret)) {
3032         APP_LOGE("Write reply failed");
3033         return ERR_APPEXECFWK_PARCEL_ERROR;
3034     }
3035     return ERR_OK;
3036 }
3037 
HandleCreateBundleDataDir(MessageParcel & data,MessageParcel & reply)3038 ErrCode BundleMgrHost::HandleCreateBundleDataDir(MessageParcel &data, MessageParcel &reply)
3039 {
3040     HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3041     APP_LOGI("CreateBundleDataDir called");
3042     int32_t userId = data.ReadInt32();
3043     ErrCode ret = CreateBundleDataDir(userId);
3044     if (!reply.WriteInt32(ret)) {
3045         APP_LOGE("Write reply failed");
3046         return ERR_APPEXECFWK_PARCEL_ERROR;
3047     }
3048     return ERR_OK;
3049 }
3050 
3051 template<typename T>
WriteParcelableIntoAshmem(T & parcelable,const char * ashmemName,MessageParcel & reply)3052 bool BundleMgrHost::WriteParcelableIntoAshmem(
3053     T &parcelable, const char *ashmemName, MessageParcel &reply)
3054 {
3055     APP_LOGE("Write parcelable into ashmem");
3056     if (ashmemName == nullptr) {
3057         APP_LOGE("AshmemName is null");
3058         return false;
3059     }
3060 
3061     MessageParcel *messageParcel = reinterpret_cast<MessageParcel *>(&reply);
3062     if (messageParcel == nullptr) {
3063         APP_LOGE("Type conversion failed");
3064         return false;
3065     }
3066 
3067     int32_t totalSize = 0;
3068     auto infoStr = GetJsonStrFromInfo<T>(parcelable);
3069     totalSize += ASHMEM_LEN;
3070     totalSize += strlen(infoStr.c_str());
3071     if (totalSize <= 0) {
3072         APP_LOGE("The size of the ashmem is invalid or the content is empty");
3073         return false;
3074     }
3075 
3076     // The ashmem name must be unique.
3077     sptr<Ashmem> ashmem = Ashmem::CreateAshmem(
3078         (ashmemName + std::to_string(AllocatAshmemNum())).c_str(), totalSize);
3079     if (ashmem == nullptr) {
3080         APP_LOGE("Create shared memory failed");
3081         return false;
3082     }
3083 
3084     // Set the read/write mode of the ashme.
3085     bool ret = ashmem->MapReadAndWriteAshmem();
3086     if (!ret) {
3087         APP_LOGE("Map shared memory fail");
3088         return false;
3089     }
3090 
3091     // Write the size and content of each item to the ashmem.
3092     // The size of item use ASHMEM_LEN.
3093     int32_t offset = 0;
3094     int itemLen = static_cast<int>(strlen(infoStr.c_str()));
3095     ret = ashmem->WriteToAshmem(std::to_string(itemLen).c_str(), ASHMEM_LEN, offset);
3096     if (!ret) {
3097         APP_LOGE("Write itemLen to shared memory fail");
3098         ClearAshmem(ashmem);
3099         return false;
3100     }
3101 
3102     offset += ASHMEM_LEN;
3103     ret = ashmem->WriteToAshmem(infoStr.c_str(), itemLen, offset);
3104     if (!ret) {
3105         APP_LOGE("Write info to shared memory fail");
3106         ClearAshmem(ashmem);
3107         return false;
3108     }
3109 
3110     ret = messageParcel->WriteAshmem(ashmem);
3111     ClearAshmem(ashmem);
3112     if (!ret) {
3113         APP_LOGE("Write ashmem to MessageParcel fail");
3114         return false;
3115     }
3116 
3117     APP_LOGE("Write parcelable vector into ashmem success");
3118     return true;
3119 }
3120 
3121 template<typename T>
WriteBigParcelable(T & parcelable,const char * ashmemName,MessageParcel & reply)3122 ErrCode BundleMgrHost::WriteBigParcelable(T &parcelable, const char *ashmemName, MessageParcel &reply)
3123 {
3124     auto size = sizeof(reply);
3125     APP_LOGD("reply size is %{public}lu", static_cast<unsigned long>(size));
3126     bool useAshMem = size > Constants::ASHMEM_THRESHOLD;
3127     if (!reply.WriteBool(useAshMem)) {
3128         APP_LOGE("write failed");
3129         return ERR_APPEXECFWK_PARCEL_ERROR;
3130     }
3131     if (useAshMem) {
3132         APP_LOGI("reply size %{public}lu, writing into ashmem", static_cast<unsigned long>(size));
3133         if (!WriteParcelableIntoAshmem(parcelable, ashmemName, reply)) {
3134             APP_LOGE("write failed");
3135             return ERR_APPEXECFWK_PARCEL_ERROR;
3136         }
3137     } else {
3138         if (!reply.WriteParcelable(&parcelable)) {
3139             APP_LOGE("write failed");
3140             return ERR_APPEXECFWK_PARCEL_ERROR;
3141         }
3142     }
3143     return ERR_OK;
3144 }
3145 
3146 template<typename T>
WriteParcelInfoIntelligent(const T & parcelInfo,MessageParcel & reply) const3147 ErrCode BundleMgrHost::WriteParcelInfoIntelligent(const T &parcelInfo, MessageParcel &reply) const
3148 {
3149     Parcel tmpParcel;
3150     (void)tmpParcel.SetMaxCapacity(MAX_PARCEL_CAPACITY);
3151     if (!tmpParcel.WriteParcelable(&parcelInfo)) {
3152         APP_LOGE("write parcel failed");
3153         return ERR_APPEXECFWK_PARCEL_ERROR;
3154     }
3155     size_t dataSize = tmpParcel.GetDataSize();
3156     if (!reply.WriteUint32(dataSize)) {
3157         APP_LOGE("write parcel failed");
3158         return ERR_APPEXECFWK_PARCEL_ERROR;
3159     }
3160 
3161     if (!reply.WriteRawData(reinterpret_cast<uint8_t *>(tmpParcel.GetData()), dataSize)) {
3162         APP_LOGE("write parcel failed");
3163         return ERR_APPEXECFWK_PARCEL_ERROR;
3164     }
3165     return ERR_OK;
3166 }
3167 
3168 template<typename T>
WriteParcelInfo(const T & parcelInfo,MessageParcel & reply) const3169 ErrCode BundleMgrHost::WriteParcelInfo(const T &parcelInfo, MessageParcel &reply) const
3170 {
3171     Parcel tmpParcel;
3172     (void)tmpParcel.SetMaxCapacity(MAX_PARCEL_CAPACITY);
3173     WRITE_PARCEL(tmpParcel.WriteParcelable(&parcelInfo));
3174     size_t dataSize = tmpParcel.GetDataSize();
3175 
3176     WRITE_PARCEL(reply.WriteUint32(dataSize));
3177     WRITE_PARCEL(reply.WriteRawData(reinterpret_cast<uint8_t *>(tmpParcel.GetData()), dataSize));
3178     return ERR_OK;
3179 }
3180 
WriteBigString(const std::string & str,MessageParcel & reply) const3181 ErrCode BundleMgrHost::WriteBigString(const std::string &str, MessageParcel &reply) const
3182 {
3183     WRITE_PARCEL(reply.WriteUint32(str.size() + 1));
3184     WRITE_PARCEL(reply.WriteRawData(str.c_str(), str.size() + 1));
3185     return ERR_OK;
3186 }
3187 }  // namespace AppExecFwk
3188 }  // namespace OHOS
3189