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