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