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_proxy.h"
17
18 #include <numeric>
19 #include <set>
20 #include <unistd.h>
21
22 #include "ipc_types.h"
23 #include "parcel.h"
24 #include "string_ex.h"
25 #include "parcel_macro.h"
26
27 #include "app_log_wrapper.h"
28 #include "app_log_tag_wrapper.h"
29 #include "appexecfwk_errors.h"
30 #include "bundle_constants.h"
31 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
32 #include "default_app_proxy.h"
33 #endif
34 #include "hitrace_meter.h"
35 #include "json_util.h"
36 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
37 #include "quick_fix_manager_proxy.h"
38 #endif
39 #include "securec.h"
40
41 namespace OHOS {
42 namespace AppExecFwk {
43 namespace {
ClearAshmem(sptr<Ashmem> & optMem)44 inline void ClearAshmem(sptr<Ashmem> &optMem)
45 {
46 if (optMem != nullptr) {
47 optMem->UnmapAshmem();
48 optMem->CloseAshmem();
49 }
50 }
51
SendData(void * & buffer,size_t size,const void * data)52 bool SendData(void *&buffer, size_t size, const void *data)
53 {
54 if (data == nullptr) {
55 APP_LOGE("data is nullptr");
56 return false;
57 }
58
59 if (size == 0) {
60 APP_LOGE("size is invalid");
61 return false;
62 }
63
64 buffer = malloc(size);
65 if (buffer == nullptr) {
66 APP_LOGE("buffer malloc failed");
67 return false;
68 }
69
70 if (memcpy_s(buffer, size, data, size) != EOK) {
71 free(buffer);
72 APP_LOGE("memcpy_s failed");
73 return false;
74 }
75
76 return true;
77 }
78
GetData(void * & buffer,size_t size,const void * data)79 bool GetData(void *&buffer, size_t size, const void *data)
80 {
81 if (data == nullptr) {
82 APP_LOGE("GetData failed due to null data");
83 return false;
84 }
85 if (size == 0) {
86 APP_LOGE("GetData failed due to zero size");
87 return false;
88 }
89 buffer = malloc(size);
90 if (buffer == nullptr) {
91 APP_LOGE("GetData failed due to malloc buffer failed");
92 return false;
93 }
94 if (memcpy_s(buffer, size, data, size) != EOK) {
95 free(buffer);
96 APP_LOGE("GetData failed due to memcpy_s failed");
97 return false;
98 }
99 return true;
100 }
101 } // namespace
102
BundleMgrProxy(const sptr<IRemoteObject> & impl)103 BundleMgrProxy::BundleMgrProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IBundleMgr>(impl)
104 {
105 APP_LOGD("create bundle mgr proxy instance");
106 }
107
~BundleMgrProxy()108 BundleMgrProxy::~BundleMgrProxy()
109 {
110 APP_LOGD("destroy create bundle mgr proxy instance");
111 }
112
GetApplicationInfo(const std::string & appName,const ApplicationFlag flag,const int userId,ApplicationInfo & appInfo)113 bool BundleMgrProxy::GetApplicationInfo(
114 const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo)
115 {
116 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
117 LOG_D(BMS_TAG_QUERY, "begin to GetApplicationInfo of %{public}s", appName.c_str());
118 if (appName.empty()) {
119 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to params empty");
120 return false;
121 }
122
123 MessageParcel data;
124 if (!data.WriteInterfaceToken(GetDescriptor())) {
125 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write descriptor fail");
126 return false;
127 }
128 if (!data.WriteString(appName)) {
129 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write appName fail");
130 return false;
131 }
132 if (!data.WriteInt32(static_cast<int>(flag))) {
133 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write flag fail");
134 return false;
135 }
136 if (!data.WriteInt32(userId)) {
137 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write userId fail");
138 return false;
139 }
140
141 if (!GetParcelableInfo<ApplicationInfo>(BundleMgrInterfaceCode::GET_APPLICATION_INFO, data, appInfo)) {
142 LOG_NOFUNC_E(BMS_TAG_QUERY, "fail to GetApplicationInfo from server");
143 return false;
144 }
145 return true;
146 }
147
GetApplicationInfo(const std::string & appName,int32_t flags,int32_t userId,ApplicationInfo & appInfo)148 bool BundleMgrProxy::GetApplicationInfo(
149 const std::string &appName, int32_t flags, int32_t userId, ApplicationInfo &appInfo)
150 {
151 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
152 LOG_D(BMS_TAG_QUERY, "begin to GetApplicationInfo of %{public}s", appName.c_str());
153 if (appName.empty()) {
154 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to params empty");
155 return false;
156 }
157
158 MessageParcel data;
159 if (!data.WriteInterfaceToken(GetDescriptor())) {
160 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write MessageParcel fail");
161 return false;
162 }
163 if (!data.WriteString(appName)) {
164 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write appName fail");
165 return false;
166 }
167 if (!data.WriteInt32(flags)) {
168 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write flag fail");
169 return false;
170 }
171 if (!data.WriteInt32(userId)) {
172 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write userId fail");
173 return false;
174 }
175
176 if (!GetParcelableInfo<ApplicationInfo>(
177 BundleMgrInterfaceCode::GET_APPLICATION_INFO_WITH_INT_FLAGS, data, appInfo)) {
178 LOG_NOFUNC_E(BMS_TAG_QUERY, "fail to GetApplicationInfo from server");
179 return false;
180 }
181 return true;
182 }
183
GetApplicationInfoV9(const std::string & appName,int32_t flags,int32_t userId,ApplicationInfo & appInfo)184 ErrCode BundleMgrProxy::GetApplicationInfoV9(
185 const std::string &appName, int32_t flags, int32_t userId, ApplicationInfo &appInfo)
186 {
187 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
188 LOG_D(BMS_TAG_QUERY, "begin to GetApplicationInfoV9 of %{public}s", appName.c_str());
189 if (appName.empty()) {
190 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfoV9 due to params empty");
191 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
192 }
193
194 MessageParcel data;
195 if (!data.WriteInterfaceToken(GetDescriptor())) {
196 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfoV9 due to write MessageParcel fail");
197 return ERR_APPEXECFWK_PARCEL_ERROR;
198 }
199 if (!data.WriteString(appName)) {
200 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfoV9 due to write appName fail");
201 return ERR_APPEXECFWK_PARCEL_ERROR;
202 }
203 if (!data.WriteInt32(flags)) {
204 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfoV9 due to write flag fail");
205 return ERR_APPEXECFWK_PARCEL_ERROR;
206 }
207 if (!data.WriteInt32(userId)) {
208 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfoV9 due to write userId fail");
209 return ERR_APPEXECFWK_PARCEL_ERROR;
210 }
211
212 auto res = GetParcelableInfoWithErrCode<ApplicationInfo>(
213 BundleMgrInterfaceCode::GET_APPLICATION_INFO_WITH_INT_FLAGS_V9, data, appInfo);
214 if (res != ERR_OK) {
215 LOG_NOFUNC_E(BMS_TAG_QUERY, "GetApplicationInfoV9 failed: %{public}d", res);
216 return res;
217 }
218 return ERR_OK;
219 }
220
GetApplicationInfos(const ApplicationFlag flag,int userId,std::vector<ApplicationInfo> & appInfos)221 bool BundleMgrProxy::GetApplicationInfos(
222 const ApplicationFlag flag, int userId, std::vector<ApplicationInfo> &appInfos)
223 {
224 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
225 LOG_D(BMS_TAG_QUERY, "begin to get GetApplicationInfos of specific userId id %{private}d", userId);
226 MessageParcel data;
227 if (!data.WriteInterfaceToken(GetDescriptor())) {
228 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write descriptor fail");
229 return false;
230 }
231 if (!data.WriteInt32(static_cast<int>(flag))) {
232 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write flag fail");
233 return false;
234 }
235 if (!data.WriteInt32(userId)) {
236 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfos due to write userId error");
237 return false;
238 }
239
240 if (!GetParcelableInfos<ApplicationInfo>(BundleMgrInterfaceCode::GET_APPLICATION_INFOS, data, appInfos)) {
241 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfos from server");
242 return false;
243 }
244 return true;
245 }
246
GetApplicationInfos(int32_t flags,int32_t userId,std::vector<ApplicationInfo> & appInfos)247 bool BundleMgrProxy::GetApplicationInfos(
248 int32_t flags, int32_t userId, std::vector<ApplicationInfo> &appInfos)
249 {
250 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
251 LOG_D(BMS_TAG_QUERY, "begin to get GetApplicationInfos of specific userId id %{private}d", userId);
252 MessageParcel data;
253 if (!data.WriteInterfaceToken(GetDescriptor())) {
254 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write MessageParcel fail");
255 return false;
256 }
257 if (!data.WriteInt32(flags)) {
258 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfo due to write flag fail");
259 return false;
260 }
261 if (!data.WriteInt32(userId)) {
262 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfos due to write userId error");
263 return false;
264 }
265 if (!GetVectorFromParcelIntelligent<ApplicationInfo>(
266 BundleMgrInterfaceCode::GET_APPLICATION_INFOS_WITH_INT_FLAGS, data, appInfos)) {
267 LOG_E(BMS_TAG_QUERY, "failed to GetApplicationInfos from server");
268 return false;
269 }
270 return true;
271 }
272
GetApplicationInfosV9(int32_t flags,int32_t userId,std::vector<ApplicationInfo> & appInfos)273 ErrCode BundleMgrProxy::GetApplicationInfosV9(
274 int32_t flags, int32_t userId, std::vector<ApplicationInfo> &appInfos)
275 {
276 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
277 LOG_D(BMS_TAG_QUERY, "begin to get GetApplicationInfosV9 of specific userId id %{private}d", userId);
278 MessageParcel data;
279 if (!data.WriteInterfaceToken(GetDescriptor())) {
280 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfosV9 due to write MessageParcel fail");
281 return ERR_APPEXECFWK_PARCEL_ERROR;
282 }
283 if (!data.WriteInt32(flags)) {
284 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfosV9 due to write flag fail");
285 return ERR_APPEXECFWK_PARCEL_ERROR;
286 }
287 if (!data.WriteInt32(userId)) {
288 LOG_E(BMS_TAG_QUERY, "fail to GetApplicationInfosV9 due to write userId error");
289 return ERR_APPEXECFWK_PARCEL_ERROR;
290 }
291 return GetVectorFromParcelIntelligentWithErrCode<ApplicationInfo>(
292 BundleMgrInterfaceCode::GET_APPLICATION_INFOS_WITH_INT_FLAGS_V9, data, appInfos);
293 }
294
GetBundleInfo(const std::string & bundleName,const BundleFlag flag,BundleInfo & bundleInfo,int32_t userId)295 bool BundleMgrProxy::GetBundleInfo(
296 const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId)
297 {
298 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
299 LOG_D(BMS_TAG_QUERY, "begin to get bundle info of %{public}s", bundleName.c_str());
300 if (bundleName.empty()) {
301 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to params empty");
302 return false;
303 }
304
305 MessageParcel data;
306 if (!data.WriteInterfaceToken(GetDescriptor())) {
307 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write InterfaceToken fail");
308 return false;
309 }
310 if (!data.WriteString(bundleName)) {
311 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write bundleName fail");
312 return false;
313 }
314 if (!data.WriteInt32(static_cast<int>(flag))) {
315 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write flag fail");
316 return false;
317 }
318 if (!data.WriteInt32(userId)) {
319 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write userId fail");
320 return false;
321 }
322
323 return GetParcelInfoIntelligent<BundleInfo>(
324 BundleMgrInterfaceCode::GET_BUNDLE_INFO, data, bundleInfo) == ERR_OK;
325 }
326
GetBundleInfo(const std::string & bundleName,int32_t flags,BundleInfo & bundleInfo,int32_t userId)327 bool BundleMgrProxy::GetBundleInfo(
328 const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId)
329 {
330 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
331 LOG_D(BMS_TAG_QUERY, "begin to get bundle info of %{public}s", bundleName.c_str());
332 if (bundleName.empty()) {
333 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to params empty");
334 return false;
335 }
336
337 MessageParcel data;
338 if (!data.WriteInterfaceToken(GetDescriptor())) {
339 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write InterfaceToken fail");
340 return false;
341 }
342 if (!data.WriteString(bundleName)) {
343 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write bundleName fail");
344 return false;
345 }
346 if (!data.WriteInt32(flags)) {
347 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write flag fail");
348 return false;
349 }
350 if (!data.WriteInt32(userId)) {
351 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write userId fail");
352 return false;
353 }
354 if (GetParcelInfoIntelligent<BundleInfo>(
355 BundleMgrInterfaceCode::GET_BUNDLE_INFO_WITH_INT_FLAGS, data, bundleInfo)!= ERR_OK) {
356 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo from server");
357 return false;
358 }
359 return true;
360 }
361
GetBundleInfoV9(const std::string & bundleName,int32_t flags,BundleInfo & bundleInfo,int32_t userId)362 ErrCode BundleMgrProxy::GetBundleInfoV9(
363 const std::string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId)
364 {
365 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
366 LOG_D(BMS_TAG_QUERY, "begin to get bundle info of %{public}s", bundleName.c_str());
367 if (bundleName.empty()) {
368 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfoV9 due to params empty");
369 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
370 }
371
372 MessageParcel data;
373 if (!data.WriteInterfaceToken(GetDescriptor())) {
374 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfoV9 due to write InterfaceToken fail");
375 return ERR_APPEXECFWK_PARCEL_ERROR;
376 }
377 if (!data.WriteString(bundleName)) {
378 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfoV9 due to write bundleName fail");
379 return ERR_APPEXECFWK_PARCEL_ERROR;
380 }
381 if (!data.WriteInt32(flags)) {
382 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfoV9 due to write flag fail");
383 return ERR_APPEXECFWK_PARCEL_ERROR;
384 }
385 if (!data.WriteInt32(userId)) {
386 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfoV9 due to write userId fail");
387 return ERR_APPEXECFWK_PARCEL_ERROR;
388 }
389
390 auto res = GetParcelInfoIntelligent<BundleInfo>(
391 BundleMgrInterfaceCode::GET_BUNDLE_INFO_WITH_INT_FLAGS_V9, data, bundleInfo);
392 if (res != ERR_OK) {
393 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfoV9 from server, error code: %{public}d", res);
394 return res;
395 }
396 return ERR_OK;
397 }
398
BatchGetBundleInfo(const std::vector<Want> & wants,int32_t flags,std::vector<BundleInfo> & bundleInfos,int32_t userId)399 ErrCode BundleMgrProxy::BatchGetBundleInfo(const std::vector<Want> &wants, int32_t flags,
400 std::vector<BundleInfo> &bundleInfos, int32_t userId)
401 {
402 std::vector<std::string> bundleNames;
403 for (size_t i = 0; i < wants.size(); i++) {
404 bundleNames.push_back(wants[i].GetElement().GetBundleName());
405 }
406 return BatchGetBundleInfo(bundleNames, flags, bundleInfos, userId);
407 }
408
BatchGetBundleInfo(const std::vector<std::string> & bundleNames,int32_t flags,std::vector<BundleInfo> & bundleInfos,int32_t userId)409 ErrCode BundleMgrProxy::BatchGetBundleInfo(const std::vector<std::string> &bundleNames, int32_t flags,
410 std::vector<BundleInfo> &bundleInfos, int32_t userId)
411 {
412 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
413 APP_LOGD("begin to batch get bundle info, bundle name count=%{public}u",
414 static_cast<unsigned int>(bundleNames.size()));
415 if (bundleNames.empty()) {
416 APP_LOGE("fail to BatchGetBundleInfo due to params empty");
417 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
418 }
419 for (size_t i = 0; i < bundleNames.size(); i++) {
420 APP_LOGD("begin to get bundle info of %{public}s", bundleNames[i].c_str());
421 if (bundleNames[i].empty()) {
422 APP_LOGE("fail to BatchGetBundleInfo due to bundleName %{public}zu empty", i);
423 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
424 }
425 }
426 std::set<std::string> bundleNameSet(bundleNames.begin(), bundleNames.end());
427 std::vector<std::string> newBundleNames(bundleNameSet.begin(), bundleNameSet.end());
428 MessageParcel data;
429 if (!data.WriteInterfaceToken(GetDescriptor())) {
430 APP_LOGE("fail to BatchGetBundleInfo due to write InterfaceToken fail");
431 return ERR_APPEXECFWK_PARCEL_ERROR;
432 }
433 if (!data.WriteInt32(newBundleNames.size())) {
434 APP_LOGE("fail to BatchGetBundleInfo due to write bundle name count fail");
435 return ERR_APPEXECFWK_PARCEL_ERROR;
436 }
437 for (size_t i = 0; i < newBundleNames.size(); i++) {
438 if (!data.WriteString(newBundleNames[i])) {
439 APP_LOGE("write bundleName %{public}zu failed", i);
440 return ERR_APPEXECFWK_PARCEL_ERROR;
441 }
442 }
443 if (!data.WriteInt32(flags)) {
444 APP_LOGE("fail to BatchGetBundleInfo due to write flag fail");
445 return ERR_APPEXECFWK_PARCEL_ERROR;
446 }
447 if (!data.WriteInt32(userId)) {
448 APP_LOGE("fail to BatchGetBundleInfo due to write userId fail");
449 return ERR_APPEXECFWK_PARCEL_ERROR;
450 }
451 return GetVectorFromParcelIntelligentWithErrCode<BundleInfo>(
452 BundleMgrInterfaceCode::BATCH_GET_BUNDLE_INFO, data, bundleInfos);
453 }
454
GetBundleInfoForSelf(int32_t flags,BundleInfo & bundleInfo)455 ErrCode BundleMgrProxy::GetBundleInfoForSelf(int32_t flags, BundleInfo &bundleInfo)
456 {
457 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
458 LOG_D(BMS_TAG_QUERY, "begin to get bundle info for self");
459
460 MessageParcel data;
461 if (!data.WriteInterfaceToken(GetDescriptor())) {
462 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfoForSelf due to write InterfaceToken fail");
463 return ERR_APPEXECFWK_PARCEL_ERROR;
464 }
465 if (!data.WriteInt32(flags)) {
466 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfoForSelf due to write flag fail");
467 return ERR_APPEXECFWK_PARCEL_ERROR;
468 }
469
470 auto res = GetParcelableInfoWithErrCode<BundleInfo>(
471 BundleMgrInterfaceCode::GET_BUNDLE_INFO_FOR_SELF, data, bundleInfo);
472 if (res != ERR_OK) {
473 LOG_NOFUNC_E(BMS_TAG_QUERY, "GetBundleInfoForSelf failed err:%{public}d", res);
474 return res;
475 }
476 return ERR_OK;
477 }
478
GetDependentBundleInfo(const std::string & bundleName,BundleInfo & bundleInfo,GetDependentBundleInfoFlag flag)479 ErrCode BundleMgrProxy::GetDependentBundleInfo(const std::string &bundleName, BundleInfo &bundleInfo,
480 GetDependentBundleInfoFlag flag)
481 {
482 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
483 APP_LOGD("begin to get dependent bundle info");
484 MessageParcel data;
485 if (!data.WriteInterfaceToken(GetDescriptor())) {
486 APP_LOGE("fail to GetDependentBundleInfo due to write InterfaceToken fail");
487 return ERR_APPEXECFWK_PARCEL_ERROR;
488 }
489 if (!data.WriteString(bundleName)) {
490 APP_LOGE("fail to GetDependentBundleInfo due to write bundleName fail");
491 return ERR_APPEXECFWK_PARCEL_ERROR;
492 }
493 if (!data.WriteUint32(static_cast<uint32_t>(flag))) {
494 APP_LOGE("fail to GetDependentBundleInfo due to write flag fail");
495 return ERR_APPEXECFWK_PARCEL_ERROR;
496 }
497 auto res = GetParcelableInfoWithErrCode<BundleInfo>(
498 BundleMgrInterfaceCode::GET_DEPENDENT_BUNDLE_INFO, data, bundleInfo);
499 if (res != ERR_OK) {
500 APP_LOGE("fail to GetDependentBundleInfo from server, error code: %{public}d", res);
501 return res;
502 }
503 return ERR_OK;
504 }
505
GetBundlePackInfo(const std::string & bundleName,const BundlePackFlag flag,BundlePackInfo & bundlePackInfo,int32_t userId)506 ErrCode BundleMgrProxy::GetBundlePackInfo(
507 const std::string &bundleName, const BundlePackFlag flag, BundlePackInfo &bundlePackInfo, int32_t userId)
508 {
509 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
510 APP_LOGD("begin to get bundle info of %{public}s", bundleName.c_str());
511 if (bundleName.empty()) {
512 APP_LOGE("fail to GetBundlePackInfo due to params empty");
513 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
514 }
515
516 MessageParcel data;
517 if (!data.WriteInterfaceToken(GetDescriptor())) {
518 APP_LOGE("fail to GetBundlePackInfo due to write InterfaceToken fail");
519 return ERR_APPEXECFWK_PARCEL_ERROR;
520 }
521 if (!data.WriteString(bundleName)) {
522 APP_LOGE("fail to GetBundlePackInfo due to write bundleName fail");
523 return ERR_APPEXECFWK_PARCEL_ERROR;
524 }
525 if (!data.WriteInt32(static_cast<int>(flag))) {
526 APP_LOGE("fail to GetBundlePackInfo due to write flag fail");
527 return ERR_APPEXECFWK_PARCEL_ERROR;
528 }
529 if (!data.WriteInt32(userId)) {
530 APP_LOGE("fail to GetBundlePackInfo due to write userId fail");
531 return ERR_APPEXECFWK_PARCEL_ERROR;
532 }
533
534 return GetParcelableInfoWithErrCode<BundlePackInfo>(BundleMgrInterfaceCode::GET_BUNDLE_PACK_INFO, data,
535 bundlePackInfo);
536 }
537
GetBundlePackInfo(const std::string & bundleName,int32_t flags,BundlePackInfo & bundlePackInfo,int32_t userId)538 ErrCode BundleMgrProxy::GetBundlePackInfo(
539 const std::string &bundleName, int32_t flags, BundlePackInfo &bundlePackInfo, int32_t userId)
540 {
541 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
542 APP_LOGD("begin to get bundle info of %{public}s", bundleName.c_str());
543 if (bundleName.empty()) {
544 APP_LOGE("fail to GetBundlePackInfo due to params empty");
545 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
546 }
547
548 MessageParcel data;
549 if (!data.WriteInterfaceToken(GetDescriptor())) {
550 APP_LOGE("fail to GetBundlePackInfo due to write InterfaceToken fail");
551 return ERR_APPEXECFWK_PARCEL_ERROR;
552 }
553 if (!data.WriteString(bundleName)) {
554 APP_LOGE("fail to GetBundlePackInfo due to write bundleName fail");
555 return ERR_APPEXECFWK_PARCEL_ERROR;
556 }
557 if (!data.WriteInt32(flags)) {
558 APP_LOGE("fail to GetBundlePackInfo due to write flag fail");
559 return ERR_APPEXECFWK_PARCEL_ERROR;
560 }
561 if (!data.WriteInt32(userId)) {
562 APP_LOGE("fail to GetBundlePackInfo due to write userId fail");
563 return ERR_APPEXECFWK_PARCEL_ERROR;
564 }
565
566 return GetParcelableInfoWithErrCode<BundlePackInfo>(
567 BundleMgrInterfaceCode::GET_BUNDLE_PACK_INFO_WITH_INT_FLAGS, data, bundlePackInfo);
568 }
569
GetBundleInfos(const BundleFlag flag,std::vector<BundleInfo> & bundleInfos,int32_t userId)570 bool BundleMgrProxy::GetBundleInfos(
571 const BundleFlag flag, std::vector<BundleInfo> &bundleInfos, int32_t userId)
572 {
573 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
574 LOG_D(BMS_TAG_QUERY, "begin to get bundle infos");
575 MessageParcel data;
576 if (!data.WriteInterfaceToken(GetDescriptor())) {
577 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfos due to write InterfaceToken fail");
578 return false;
579 }
580 if (!data.WriteInt32(static_cast<int>(flag))) {
581 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfos due to write flag fail");
582 return false;
583 }
584 if (!data.WriteInt32(userId)) {
585 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write userId fail");
586 return false;
587 }
588 if (!GetVectorFromParcelIntelligent<BundleInfo>(
589 BundleMgrInterfaceCode::GET_BUNDLE_INFOS, data, bundleInfos)) {
590 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfos from server");
591 return false;
592 }
593 return true;
594 }
595
GetBundleInfos(int32_t flags,std::vector<BundleInfo> & bundleInfos,int32_t userId)596 bool BundleMgrProxy::GetBundleInfos(
597 int32_t flags, std::vector<BundleInfo> &bundleInfos, int32_t userId)
598 {
599 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
600 LOG_D(BMS_TAG_QUERY, "begin to get bundle infos");
601 MessageParcel data;
602 if (!data.WriteInterfaceToken(GetDescriptor())) {
603 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfos due to write InterfaceToken fail");
604 return false;
605 }
606 if (!data.WriteInt32(flags)) {
607 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfos due to write flag fail");
608 return false;
609 }
610 if (!data.WriteInt32(userId)) {
611 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write userId fail");
612 return false;
613 }
614 if (!GetVectorFromParcelIntelligent<BundleInfo>(
615 BundleMgrInterfaceCode::GET_BUNDLE_INFOS_WITH_INT_FLAGS, data, bundleInfos)) {
616 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfos from server");
617 return false;
618 }
619 return true;
620 }
621
GetBundleInfosV9(int32_t flags,std::vector<BundleInfo> & bundleInfos,int32_t userId)622 ErrCode BundleMgrProxy::GetBundleInfosV9(int32_t flags, std::vector<BundleInfo> &bundleInfos, int32_t userId)
623 {
624 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
625 LOG_NOFUNC_I(BMS_TAG_QUERY, "begin to get bundleinfos");
626 MessageParcel data;
627 if (!data.WriteInterfaceToken(GetDescriptor())) {
628 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfosV9 due to write InterfaceToken fail");
629 return ERR_APPEXECFWK_PARCEL_ERROR;
630 }
631 if (!data.WriteInt32(flags)) {
632 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfosV9 due to write flag fail");
633 return ERR_APPEXECFWK_PARCEL_ERROR;
634 }
635 if (!data.WriteInt32(userId)) {
636 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfosV9 due to write userId fail");
637 return ERR_APPEXECFWK_PARCEL_ERROR;
638 }
639 LOG_NOFUNC_I(BMS_TAG_QUERY, "get bundleinfos end");
640 return GetVectorFromParcelIntelligentWithErrCode<BundleInfo>(
641 BundleMgrInterfaceCode::GET_BUNDLE_INFOS_WITH_INT_FLAGS_V9, data, bundleInfos);
642 }
643
GetUidByBundleName(const std::string & bundleName,const int userId)644 int BundleMgrProxy::GetUidByBundleName(const std::string &bundleName, const int userId)
645 {
646 return GetUidByBundleName(bundleName, userId, 0);
647 }
648
GetUidByBundleName(const std::string & bundleName,const int32_t userId,int32_t appIndex)649 int32_t BundleMgrProxy::GetUidByBundleName(const std::string &bundleName, const int32_t userId, int32_t appIndex)
650 {
651 if (bundleName.empty()) {
652 APP_LOGE("failed to GetUidByBundleName due to bundleName empty");
653 return Constants::INVALID_UID;
654 }
655 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
656 APP_LOGD("begin to get uid of %{public}s, userId : %{public}d, appIndex : %{public}d", bundleName.c_str(),
657 userId, appIndex);
658
659 MessageParcel data;
660 if (!data.WriteInterfaceToken(GetDescriptor())) {
661 APP_LOGE("failed to GetUidByBundleName due to write InterfaceToken fail");
662 return Constants::INVALID_UID;
663 }
664 if (!data.WriteString(bundleName)) {
665 APP_LOGE("failed to GetUidByBundleName due to write bundleName fail");
666 return Constants::INVALID_UID;
667 }
668 if (!data.WriteInt32(userId)) {
669 APP_LOGE("failed to GetUidByBundleName due to write uid fail");
670 return Constants::INVALID_UID;
671 }
672 if (!data.WriteInt32(appIndex)) {
673 APP_LOGE("failed to GetUidByBundleName due to write uid fail");
674 return Constants::INVALID_UID;
675 }
676
677 MessageParcel reply;
678 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_UID_BY_BUNDLE_NAME, data, reply)) {
679 APP_LOGE("failed to GetUidByBundleName from server");
680 return Constants::INVALID_UID;
681 }
682 int32_t uid = reply.ReadInt32();
683 APP_LOGD("uid is %{public}d", uid);
684 return uid;
685 }
686
GetUidByDebugBundleName(const std::string & bundleName,const int userId)687 int BundleMgrProxy::GetUidByDebugBundleName(const std::string &bundleName, const int userId)
688 {
689 if (bundleName.empty()) {
690 APP_LOGE("failed to GetUidByBundleName due to bundleName empty");
691 return Constants::INVALID_UID;
692 }
693 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
694 APP_LOGD("begin to get uid of %{public}s, userId : %{public}d", bundleName.c_str(), userId);
695
696 MessageParcel data;
697 if (!data.WriteInterfaceToken(GetDescriptor())) {
698 APP_LOGE("failed to GetUidByBundleName due to write InterfaceToken fail");
699 return Constants::INVALID_UID;
700 }
701 if (!data.WriteString(bundleName)) {
702 APP_LOGE("failed to GetUidByBundleName due to write bundleName fail");
703 return Constants::INVALID_UID;
704 }
705 if (!data.WriteInt32(userId)) {
706 APP_LOGE("failed to GetUidByBundleName due to write uid fail");
707 return Constants::INVALID_UID;
708 }
709
710 MessageParcel reply;
711 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_UID_BY_DEBUG_BUNDLE_NAME, data, reply)) {
712 APP_LOGE("failed to GetUidByBundleName from server");
713 return Constants::INVALID_UID;
714 }
715 int32_t uid = reply.ReadInt32();
716 APP_LOGD("uid is %{public}d", uid);
717 return uid;
718 }
719
GetAppIdByBundleName(const std::string & bundleName,const int userId)720 std::string BundleMgrProxy::GetAppIdByBundleName(const std::string &bundleName, const int userId)
721 {
722 if (bundleName.empty()) {
723 APP_LOGE("failed to GetAppIdByBundleName due to bundleName empty");
724 return Constants::EMPTY_STRING;
725 }
726 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
727 APP_LOGD("begin to get appId of %{public}s", bundleName.c_str());
728
729 MessageParcel data;
730 if (!data.WriteInterfaceToken(GetDescriptor())) {
731 APP_LOGE("failed to GetAppIdByBundleName due to write InterfaceToken fail");
732 return Constants::EMPTY_STRING;
733 }
734 if (!data.WriteString(bundleName)) {
735 APP_LOGE("failed to GetAppIdByBundleName due to write bundleName fail");
736 return Constants::EMPTY_STRING;
737 }
738 if (!data.WriteInt32(userId)) {
739 APP_LOGE("failed to GetAppIdByBundleName due to write uid fail");
740 return Constants::EMPTY_STRING;
741 }
742
743 MessageParcel reply;
744 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_APPID_BY_BUNDLE_NAME, data, reply)) {
745 APP_LOGE("failed to GetAppIdByBundleName from server");
746 return Constants::EMPTY_STRING;
747 }
748 std::string appId = reply.ReadString();
749 APP_LOGD("appId is %{private}s", appId.c_str());
750 return appId;
751 }
752
GetBundleNameForUid(const int uid,std::string & bundleName)753 bool BundleMgrProxy::GetBundleNameForUid(const int uid, std::string &bundleName)
754 {
755 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
756 APP_LOGD("begin to GetBundleNameForUid of %{public}d", uid);
757 MessageParcel data;
758 if (!data.WriteInterfaceToken(GetDescriptor())) {
759 APP_LOGE("fail to GetBundleNameForUid due to write InterfaceToken fail");
760 return false;
761 }
762 if (!data.WriteInt32(uid)) {
763 APP_LOGE("fail to GetBundleNameForUid due to write uid fail");
764 return false;
765 }
766
767 MessageParcel reply;
768 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_BUNDLE_NAME_FOR_UID, data, reply)) {
769 APP_LOGE("fail to GetBundleNameForUid from server");
770 return false;
771 }
772 if (!reply.ReadBool()) {
773 if (uid > Constants::BASE_APP_UID) {
774 APP_LOGE("reply result false");
775 }
776 return false;
777 }
778 bundleName = reply.ReadString();
779 return true;
780 }
781
GetBundlesForUid(const int uid,std::vector<std::string> & bundleNames)782 bool BundleMgrProxy::GetBundlesForUid(const int uid, std::vector<std::string> &bundleNames)
783 {
784 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
785 APP_LOGD("begin to GetBundlesForUid of %{public}d", uid);
786 MessageParcel data;
787 if (!data.WriteInterfaceToken(GetDescriptor())) {
788 APP_LOGE("fail to GetBundlesForUid due to write InterfaceToken fail");
789 return false;
790 }
791 if (!data.WriteInt32(uid)) {
792 APP_LOGE("fail to GetBundlesForUid due to write uid fail");
793 return false;
794 }
795
796 MessageParcel reply;
797 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_BUNDLES_FOR_UID, data, reply)) {
798 APP_LOGE("fail to GetBundlesForUid from server");
799 return false;
800 }
801 if (!reply.ReadBool()) {
802 APP_LOGD("reply result false");
803 return false;
804 }
805 if (!reply.ReadStringVector(&bundleNames)) {
806 APP_LOGE("fail to GetBundlesForUid from reply");
807 return false;
808 }
809 return true;
810 }
811
GetNameForUid(const int uid,std::string & name)812 ErrCode BundleMgrProxy::GetNameForUid(const int uid, std::string &name)
813 {
814 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
815 APP_LOGD("begin to GetNameForUid of %{public}d", uid);
816 MessageParcel data;
817 if (!data.WriteInterfaceToken(GetDescriptor())) {
818 APP_LOGE("fail to GetNameForUid due to write InterfaceToken fail");
819 return ERR_APPEXECFWK_PARCEL_ERROR;
820 }
821 if (!data.WriteInt32(uid)) {
822 APP_LOGE("fail to GetNameForUid due to write uid fail");
823 return ERR_APPEXECFWK_PARCEL_ERROR;
824 }
825
826 MessageParcel reply;
827 if (!SendTransactCmdWithLog(BundleMgrInterfaceCode::GET_NAME_FOR_UID, data, reply)) {
828 APP_LOGE("fail to GetNameForUid from server");
829 return ERR_APPEXECFWK_PARCEL_ERROR;
830 }
831 ErrCode ret = reply.ReadInt32();
832 if (ret != ERR_OK) {
833 return ret;
834 }
835 name = reply.ReadString();
836 return ERR_OK;
837 }
838
GetNameAndIndexForUid(const int32_t uid,std::string & bundleName,int32_t & appIndex)839 ErrCode BundleMgrProxy::GetNameAndIndexForUid(const int32_t uid, std::string &bundleName, int32_t &appIndex)
840 {
841 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
842 APP_LOGD("begin to GetNameAndIndexForUid of %{public}d", uid);
843 MessageParcel data;
844 if (!data.WriteInterfaceToken(GetDescriptor())) {
845 APP_LOGE("fail to GetNameAndIndexForUid due to write InterfaceToken fail");
846 return ERR_APPEXECFWK_PARCEL_ERROR;
847 }
848 if (!data.WriteInt32(uid)) {
849 APP_LOGE("fail to GetNameAndIndexForUid due to write uid fail");
850 return ERR_APPEXECFWK_PARCEL_ERROR;
851 }
852
853 MessageParcel reply;
854 if (!SendTransactCmdWithLog(BundleMgrInterfaceCode::GET_NAME_AND_APPINDEX_FOR_UID, data, reply)) {
855 APP_LOGE("fail to GetNameAndIndexForUid from server");
856 return ERR_APPEXECFWK_PARCEL_ERROR;
857 }
858 ErrCode ret = reply.ReadInt32();
859 if (ret != ERR_OK) {
860 return ret;
861 }
862 bundleName = reply.ReadString();
863 appIndex = reply.ReadInt32();
864 return ERR_OK;
865 }
866
GetBundleGids(const std::string & bundleName,std::vector<int> & gids)867 bool BundleMgrProxy::GetBundleGids(const std::string &bundleName, std::vector<int> &gids)
868 {
869 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
870 APP_LOGD("begin to GetBundleGids of %{public}s", bundleName.c_str());
871 MessageParcel data;
872 if (!data.WriteInterfaceToken(GetDescriptor())) {
873 APP_LOGE("fail to GetBundleGids due to write InterfaceToken fail");
874 return false;
875 }
876 if (!data.WriteString(bundleName)) {
877 APP_LOGE("fail to GetBundleGids due to write bundleName fail");
878 return false;
879 }
880
881 MessageParcel reply;
882 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_BUNDLE_GIDS, data, reply)) {
883 APP_LOGE("fail to GetBundleGids from server");
884 return false;
885 }
886 if (!reply.ReadBool()) {
887 APP_LOGE("reply result false");
888 return false;
889 }
890 if (!reply.ReadInt32Vector(&gids)) {
891 APP_LOGE("fail to GetBundleGids from reply");
892 return false;
893 }
894 return true;
895 }
896
GetBundleGidsByUid(const std::string & bundleName,const int & uid,std::vector<int> & gids)897 bool BundleMgrProxy::GetBundleGidsByUid(const std::string &bundleName, const int &uid, std::vector<int> &gids)
898 {
899 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
900 APP_LOGD("begin to GetBundleGidsByUid of %{public}s", bundleName.c_str());
901 MessageParcel data;
902 if (!data.WriteInterfaceToken(GetDescriptor())) {
903 APP_LOGE("fail to GetBundleGidsByUid due to write InterfaceToken fail");
904 return false;
905 }
906 if (!data.WriteString(bundleName)) {
907 APP_LOGE("fail to GetBundleGidsByUid due to write bundleName fail");
908 return false;
909 }
910 if (!data.WriteInt32(uid)) {
911 APP_LOGE("fail to GetBundleGidsByUid due to write uid fail");
912 return false;
913 }
914
915 MessageParcel reply;
916 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_BUNDLE_GIDS_BY_UID, data, reply)) {
917 APP_LOGE("fail to GetBundleGidsByUid from server");
918 return false;
919 }
920 if (!reply.ReadBool()) {
921 APP_LOGE("reply result false");
922 return false;
923 }
924 if (!reply.ReadInt32Vector(&gids)) {
925 APP_LOGE("fail to GetBundleGidsByUid from reply");
926 return false;
927 }
928 return true;
929 }
930
GetAppType(const std::string & bundleName)931 std::string BundleMgrProxy::GetAppType(const std::string &bundleName)
932 {
933 if (bundleName.empty()) {
934 APP_LOGE("failed to GetAppType due to bundleName empty");
935 return Constants::EMPTY_STRING;
936 }
937 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
938 APP_LOGD("begin to GetAppType of %{public}s", bundleName.c_str());
939
940 MessageParcel data;
941 if (!data.WriteInterfaceToken(GetDescriptor())) {
942 APP_LOGE("failed to GetAppType due to write InterfaceToken fail");
943 return Constants::EMPTY_STRING;
944 }
945 if (!data.WriteString(bundleName)) {
946 APP_LOGE("failed to GetAppType due to write bundleName fail");
947 return Constants::EMPTY_STRING;
948 }
949
950 MessageParcel reply;
951 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_APP_TYPE, data, reply)) {
952 APP_LOGE("failed to GetAppType from server");
953 return Constants::EMPTY_STRING;
954 }
955 std::string appType = reply.ReadString();
956 APP_LOGD("appType is %{public}s", appType.c_str());
957 return appType;
958 }
959
CheckIsSystemAppByUid(const int uid)960 bool BundleMgrProxy::CheckIsSystemAppByUid(const int uid)
961 {
962 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
963 APP_LOGD("begin to CheckIsSystemAppByUid of %{public}d", uid);
964 MessageParcel data;
965 if (!data.WriteInterfaceToken(GetDescriptor())) {
966 APP_LOGE("fail to CheckIsSystemAppByUid due to write InterfaceToken fail");
967 return false;
968 }
969 if (!data.WriteInt32(uid)) {
970 APP_LOGE("fail to CheckIsSystemAppByUid due to write uid fail");
971 return false;
972 }
973
974 MessageParcel reply;
975 if (!SendTransactCmd(BundleMgrInterfaceCode::CHECK_IS_SYSTEM_APP_BY_UID, data, reply)) {
976 APP_LOGE("fail to CheckIsSystemAppByUid from server");
977 return false;
978 }
979 return reply.ReadBool();
980 }
981
GetBundleInfosByMetaData(const std::string & metaData,std::vector<BundleInfo> & bundleInfos)982 bool BundleMgrProxy::GetBundleInfosByMetaData(const std::string &metaData, std::vector<BundleInfo> &bundleInfos)
983 {
984 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
985 APP_LOGD("begin to GetBundleInfosByMetaData of %{public}s", metaData.c_str());
986 if (metaData.empty()) {
987 APP_LOGE("fail to GetBundleInfosByMetaData due to params empty");
988 return false;
989 }
990
991 MessageParcel data;
992 if (!data.WriteInterfaceToken(GetDescriptor())) {
993 APP_LOGE("fail to GetBundleInfosByMetaData due to write InterfaceToken fail");
994 return false;
995 }
996 if (!data.WriteString(metaData)) {
997 APP_LOGE("fail to GetBundleInfosByMetaData due to write metaData fail");
998 return false;
999 }
1000
1001 if (!GetParcelableInfos<BundleInfo>(BundleMgrInterfaceCode::GET_BUNDLE_INFOS_BY_METADATA, data, bundleInfos)) {
1002 APP_LOGE("fail to GetBundleInfosByMetaData from server");
1003 return false;
1004 }
1005 return true;
1006 }
1007
QueryAbilityInfo(const Want & want,AbilityInfo & abilityInfo)1008 bool BundleMgrProxy::QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo)
1009 {
1010 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1011 MessageParcel data;
1012 if (!data.WriteInterfaceToken(GetDescriptor())) {
1013 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo write MessageParcel fail");
1014 return false;
1015 }
1016 if (!data.WriteParcelable(&want)) {
1017 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo write want fail");
1018 return false;
1019 }
1020
1021 if (!GetParcelableInfo<AbilityInfo>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO, data, abilityInfo)) {
1022 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo from server fail");
1023 return false;
1024 }
1025 return true;
1026 }
1027
QueryAbilityInfo(const Want & want,int32_t flags,int32_t userId,AbilityInfo & abilityInfo,const sptr<IRemoteObject> & callBack)1028 bool BundleMgrProxy::QueryAbilityInfo(const Want &want, int32_t flags, int32_t userId,
1029 AbilityInfo &abilityInfo, const sptr<IRemoteObject> &callBack)
1030 {
1031 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1032 MessageParcel data;
1033 if (!data.WriteInterfaceToken(GetDescriptor())) {
1034 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo write MessageParcel fail");
1035 return false;
1036 }
1037 if (!data.WriteParcelable(&want)) {
1038 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo write want fail");
1039 return false;
1040 }
1041
1042 if (!data.WriteInt32(flags)) {
1043 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo write flags fail");
1044 return false;
1045 }
1046
1047 if (!data.WriteInt32(userId)) {
1048 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo write userId fail");
1049 return false;
1050 }
1051
1052 if (!data.WriteRemoteObject(callBack)) {
1053 LOG_E(BMS_TAG_QUERY, "callBack write parcel fail");
1054 return false;
1055 }
1056
1057 if (!GetParcelableInfo<AbilityInfo>(
1058 BundleMgrInterfaceCode::QUERY_ABILITY_INFO_WITH_CALLBACK, data, abilityInfo)) {
1059 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo from server fail");
1060 return false;
1061 }
1062 return true;
1063 }
1064
SilentInstall(const Want & want,int32_t userId,const sptr<IRemoteObject> & callBack)1065 bool BundleMgrProxy::SilentInstall(const Want &want, int32_t userId, const sptr<IRemoteObject> &callBack)
1066 {
1067 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1068 APP_LOGD("begin to silent install");
1069
1070 MessageParcel data;
1071 if (!data.WriteInterfaceToken(GetDescriptor())) {
1072 APP_LOGE("fail to SilentInstall due to write token");
1073 return false;
1074 }
1075 if (!data.WriteParcelable(&want)) {
1076 APP_LOGE("fail to SilentInstall due to write want");
1077 return false;
1078 }
1079
1080 if (!data.WriteInt32(userId)) {
1081 APP_LOGE("fail to SilentInstall due to write userId");
1082 return false;
1083 }
1084
1085 if (!data.WriteRemoteObject(callBack)) {
1086 APP_LOGE("fail to SilentInstall due to write callBack");
1087 return false;
1088 }
1089
1090 MessageParcel reply;
1091 return SendTransactCmd(BundleMgrInterfaceCode::SILENT_INSTALL, data, reply);
1092 }
1093
UpgradeAtomicService(const Want & want,int32_t userId)1094 void BundleMgrProxy::UpgradeAtomicService(const Want &want, int32_t userId)
1095 {
1096 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1097 MessageParcel data;
1098 if (!data.WriteInterfaceToken(GetDescriptor())) {
1099 APP_LOGE("fail to UpgradeAtomicService due to write descriptor");
1100 return;
1101 }
1102 if (!data.WriteParcelable(&want)) {
1103 APP_LOGE("fail to UpgradeAtomicService due to write want");
1104 return;
1105 }
1106
1107 if (!data.WriteInt32(userId)) {
1108 APP_LOGE("fail to UpgradeAtomicService due to write userId");
1109 return;
1110 }
1111 return;
1112 }
1113
QueryAbilityInfo(const Want & want,int32_t flags,int32_t userId,AbilityInfo & abilityInfo)1114 bool BundleMgrProxy::QueryAbilityInfo(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo)
1115 {
1116 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1117 MessageParcel data;
1118 if (!data.WriteInterfaceToken(GetDescriptor())) {
1119 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo mutiparam write MessageParcel fail");
1120 return false;
1121 }
1122 if (!data.WriteParcelable(&want)) {
1123 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo mutiparam write want fail");
1124 return false;
1125 }
1126 if (!data.WriteInt32(flags)) {
1127 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo mutiparam write flags fail");
1128 return false;
1129 }
1130 if (!data.WriteInt32(userId)) {
1131 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo mutiparam write userId fail");
1132 return false;
1133 }
1134
1135 if (!GetParcelableInfo<AbilityInfo>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_MUTI_PARAM, data, abilityInfo)) {
1136 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo mutiparam from server fail");
1137 return false;
1138 }
1139 return true;
1140 }
1141
QueryAbilityInfos(const Want & want,std::vector<AbilityInfo> & abilityInfos)1142 bool BundleMgrProxy::QueryAbilityInfos(const Want &want, std::vector<AbilityInfo> &abilityInfos)
1143 {
1144 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1145 MessageParcel data;
1146 if (!data.WriteInterfaceToken(GetDescriptor())) {
1147 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos write MessageParcel fail");
1148 return false;
1149 }
1150 if (!data.WriteParcelable(&want)) {
1151 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos write want fail");
1152 return false;
1153 }
1154
1155 if (!GetParcelableInfos<AbilityInfo>(BundleMgrInterfaceCode::QUERY_ABILITY_INFOS, data, abilityInfos)) {
1156 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos from server fail");
1157 return false;
1158 }
1159 return true;
1160 }
1161
QueryAbilityInfos(const Want & want,int32_t flags,int32_t userId,std::vector<AbilityInfo> & abilityInfos)1162 bool BundleMgrProxy::QueryAbilityInfos(
1163 const Want &want, int32_t flags, int32_t userId, std::vector<AbilityInfo> &abilityInfos)
1164 {
1165 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1166 MessageParcel data;
1167 if (!data.WriteInterfaceToken(GetDescriptor())) {
1168 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos mutiparam write MessageParcel fail");
1169 return false;
1170 }
1171 if (!data.WriteParcelable(&want)) {
1172 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos mutiparam write want fail");
1173 return false;
1174 }
1175 if (!data.WriteInt32(flags)) {
1176 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos mutiparam write flags fail");
1177 return false;
1178 }
1179 if (!data.WriteInt32(userId)) {
1180 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos mutiparam write userId fail");
1181 return false;
1182 }
1183 if (!GetVectorFromParcelIntelligent<AbilityInfo>(
1184 BundleMgrInterfaceCode::QUERY_ABILITY_INFOS_MUTI_PARAM, data, abilityInfos)) {
1185 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos mutiparam from server fail");
1186 return false;
1187 }
1188 return true;
1189 }
1190
QueryAbilityInfosV9(const Want & want,int32_t flags,int32_t userId,std::vector<AbilityInfo> & abilityInfos)1191 ErrCode BundleMgrProxy::QueryAbilityInfosV9(
1192 const Want &want, int32_t flags, int32_t userId, std::vector<AbilityInfo> &abilityInfos)
1193 {
1194 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1195 MessageParcel data;
1196 if (!data.WriteInterfaceToken(GetDescriptor())) {
1197 LOG_E(BMS_TAG_QUERY, "write interfaceToken failed");
1198 return ERR_APPEXECFWK_PARCEL_ERROR;
1199 }
1200 if (!data.WriteParcelable(&want)) {
1201 LOG_E(BMS_TAG_QUERY, "write want failed");
1202 return ERR_APPEXECFWK_PARCEL_ERROR;
1203 }
1204 if (!data.WriteInt32(flags)) {
1205 LOG_E(BMS_TAG_QUERY, "write flags failed");
1206 return ERR_APPEXECFWK_PARCEL_ERROR;
1207 }
1208 if (!data.WriteInt32(userId)) {
1209 LOG_E(BMS_TAG_QUERY, "write userId failed");
1210 return ERR_APPEXECFWK_PARCEL_ERROR;
1211 }
1212 return GetVectorFromParcelIntelligentWithErrCode<AbilityInfo>(
1213 BundleMgrInterfaceCode::QUERY_ABILITY_INFOS_V9, data, abilityInfos);
1214 }
1215
BatchQueryAbilityInfos(const std::vector<Want> & wants,int32_t flags,int32_t userId,std::vector<AbilityInfo> & abilityInfos)1216 ErrCode BundleMgrProxy::BatchQueryAbilityInfos(
1217 const std::vector<Want> &wants, int32_t flags, int32_t userId, std::vector<AbilityInfo> &abilityInfos)
1218 {
1219 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1220 MessageParcel data;
1221 if (!data.WriteInterfaceToken(GetDescriptor())) {
1222 APP_LOGE("write interfaceToken failed");
1223 return ERR_APPEXECFWK_PARCEL_ERROR;
1224 }
1225 if (!data.WriteInt32(wants.size())) {
1226 APP_LOGE("write wants count failed");
1227 return ERR_APPEXECFWK_PARCEL_ERROR;
1228 }
1229 for (size_t i = 0; i < wants.size(); i++) {
1230 if (!data.WriteParcelable(&wants[i])) {
1231 APP_LOGE("write want %{public}zu failed", i);
1232 return ERR_APPEXECFWK_PARCEL_ERROR;
1233 }
1234 }
1235 if (!data.WriteInt32(flags)) {
1236 APP_LOGE("write flags failed");
1237 return ERR_APPEXECFWK_PARCEL_ERROR;
1238 }
1239 if (!data.WriteInt32(userId)) {
1240 APP_LOGE("write userId failed");
1241 return ERR_APPEXECFWK_PARCEL_ERROR;
1242 }
1243 return GetVectorFromParcelIntelligentWithErrCode<AbilityInfo>(
1244 BundleMgrInterfaceCode::BATCH_QUERY_ABILITY_INFOS, data, abilityInfos);
1245 }
1246
QueryLauncherAbilityInfos(const Want & want,int32_t userId,std::vector<AbilityInfo> & abilityInfo)1247 ErrCode BundleMgrProxy::QueryLauncherAbilityInfos(
1248 const Want &want, int32_t userId, std::vector<AbilityInfo> &abilityInfo)
1249 {
1250 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1251 MessageParcel data;
1252 if (!data.WriteInterfaceToken(GetDescriptor())) {
1253 LOG_E(BMS_TAG_QUERY, "write interfaceToken failed");
1254 return ERR_APPEXECFWK_PARCEL_ERROR;
1255 }
1256 if (!data.WriteParcelable(&want)) {
1257 LOG_E(BMS_TAG_QUERY, "write want failed");
1258 return ERR_APPEXECFWK_PARCEL_ERROR;
1259 }
1260 if (!data.WriteInt32(userId)) {
1261 LOG_E(BMS_TAG_QUERY, "write userId failed");
1262 return ERR_APPEXECFWK_PARCEL_ERROR;
1263 }
1264 return GetVectorFromParcelIntelligentWithErrCode<AbilityInfo>(
1265 BundleMgrInterfaceCode::QUERY_LAUNCHER_ABILITY_INFO, data, abilityInfo);
1266 }
1267
QueryAllAbilityInfos(const Want & want,int32_t userId,std::vector<AbilityInfo> & abilityInfos)1268 bool BundleMgrProxy::QueryAllAbilityInfos(const Want &want, int32_t userId, std::vector<AbilityInfo> &abilityInfos)
1269 {
1270 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1271 MessageParcel data;
1272 if (!data.WriteInterfaceToken(GetDescriptor())) {
1273 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo write MessageParcel fail");
1274 return false;
1275 }
1276 if (!data.WriteParcelable(&want)) {
1277 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos write want fail");
1278 return false;
1279 }
1280 if (!data.WriteInt32(userId)) {
1281 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos write userId fail");
1282 return false;
1283 }
1284 if (!GetVectorFromParcelIntelligent<AbilityInfo>(
1285 BundleMgrInterfaceCode::QUERY_ALL_ABILITY_INFOS, data, abilityInfos)) {
1286 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfos from server fail");
1287 return false;
1288 }
1289 return true;
1290 }
1291
QueryAbilityInfoByUri(const std::string & abilityUri,AbilityInfo & abilityInfo)1292 bool BundleMgrProxy::QueryAbilityInfoByUri(const std::string &abilityUri, AbilityInfo &abilityInfo)
1293 {
1294 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1295 MessageParcel data;
1296 if (!data.WriteInterfaceToken(GetDescriptor())) {
1297 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfoByUri write MessageParcel fail");
1298 return false;
1299 }
1300 if (!data.WriteString(abilityUri)) {
1301 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfoByUri write abilityUri fail");
1302 return false;
1303 }
1304
1305 if (!GetParcelableInfo<AbilityInfo>(BundleMgrInterfaceCode::QUERY_ABILITY_INFO_BY_URI, data, abilityInfo)) {
1306 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfoByUri from server fail");
1307 return false;
1308 }
1309 return true;
1310 }
1311
QueryAbilityInfosByUri(const std::string & abilityUri,std::vector<AbilityInfo> & abilityInfos)1312 bool BundleMgrProxy::QueryAbilityInfosByUri(const std::string &abilityUri, std::vector<AbilityInfo> &abilityInfos)
1313 {
1314 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1315 MessageParcel data;
1316 if (!data.WriteInterfaceToken(GetDescriptor())) {
1317 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfosByUri write MessageParcel fail");
1318 return false;
1319 }
1320 if (!data.WriteString(abilityUri)) {
1321 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfosByUri write abilityUri fail");
1322 return false;
1323 }
1324
1325 if (!GetParcelableInfos<AbilityInfo>(BundleMgrInterfaceCode::QUERY_ABILITY_INFOS_BY_URI, data, abilityInfos)) {
1326 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfosByUri from server fail");
1327 return false;
1328 }
1329 return true;
1330 }
1331
QueryAbilityInfoByUri(const std::string & abilityUri,int32_t userId,AbilityInfo & abilityInfo)1332 bool BundleMgrProxy::QueryAbilityInfoByUri(
1333 const std::string &abilityUri, int32_t userId, AbilityInfo &abilityInfo)
1334 {
1335 MessageParcel data;
1336 if (!data.WriteInterfaceToken(GetDescriptor())) {
1337 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfoByUri write MessageParcel fail");
1338 return false;
1339 }
1340 if (!data.WriteString(abilityUri)) {
1341 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfoByUri write abilityUri fail");
1342 return false;
1343 }
1344 if (!data.WriteInt32(userId)) {
1345 LOG_E(BMS_TAG_QUERY, "QueryAbilityInfo write userId fail");
1346 return false;
1347 }
1348
1349 if (!GetParcelableInfo<AbilityInfo>(
1350 BundleMgrInterfaceCode::QUERY_ABILITY_INFO_BY_URI_FOR_USERID, data, abilityInfo)) {
1351 APP_LOGE("fail to QueryAbilityInfoByUri from server");
1352 return false;
1353 }
1354 return true;
1355 }
1356
QueryKeepAliveBundleInfos(std::vector<BundleInfo> & bundleInfos)1357 bool BundleMgrProxy::QueryKeepAliveBundleInfos(std::vector<BundleInfo> &bundleInfos)
1358 {
1359 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1360 APP_LOGD("begin to QueryKeepAliveBundleInfos");
1361
1362 MessageParcel data;
1363 if (!data.WriteInterfaceToken(GetDescriptor())) {
1364 APP_LOGE("fail to QueryKeepAliveBundleInfos due to write InterfaceToken fail");
1365 return false;
1366 }
1367
1368 if (!GetParcelableInfos<BundleInfo>(BundleMgrInterfaceCode::QUERY_KEEPALIVE_BUNDLE_INFOS, data, bundleInfos)) {
1369 APP_LOGE("fail to QueryKeepAliveBundleInfos from server");
1370 return false;
1371 }
1372 return true;
1373 }
1374
GetAbilityLabel(const std::string & bundleName,const std::string & abilityName)1375 std::string BundleMgrProxy::GetAbilityLabel(const std::string &bundleName, const std::string &abilityName)
1376 {
1377 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1378 APP_LOGD("begin to GetAbilityLabel of %{public}s", bundleName.c_str());
1379 if (bundleName.empty() || abilityName.empty()) {
1380 APP_LOGE("fail to GetAbilityLabel due to params empty");
1381 return Constants::EMPTY_STRING;
1382 }
1383
1384 MessageParcel data;
1385 if (!data.WriteInterfaceToken(GetDescriptor())) {
1386 APP_LOGE("fail to GetAbilityLabel due to write InterfaceToken fail");
1387 return Constants::EMPTY_STRING;
1388 }
1389 if (!data.WriteString(bundleName)) {
1390 APP_LOGE("fail to GetAbilityLabel due to write bundleName fail");
1391 return Constants::EMPTY_STRING;
1392 }
1393 if (!data.WriteString(abilityName)) {
1394 APP_LOGE("fail to GetAbilityLabel due to write abilityName fail");
1395 return Constants::EMPTY_STRING;
1396 }
1397
1398 MessageParcel reply;
1399 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ABILITY_LABEL, data, reply)) {
1400 APP_LOGE("fail to GetAbilityLabel from server");
1401 return Constants::EMPTY_STRING;
1402 }
1403 return reply.ReadString();
1404 }
1405
GetAbilityLabel(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,std::string & label)1406 ErrCode BundleMgrProxy::GetAbilityLabel(const std::string &bundleName, const std::string &moduleName,
1407 const std::string &abilityName, std::string &label)
1408 {
1409 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1410 APP_LOGI("GetAbilityLabel begin %{public}s", bundleName.c_str());
1411 if (bundleName.empty() || moduleName.empty() || abilityName.empty()) {
1412 APP_LOGE("fail to GetAbilityLabel due to params empty");
1413 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
1414 }
1415 MessageParcel data;
1416 if (!data.WriteInterfaceToken(GetDescriptor())) {
1417 APP_LOGE("fail to GetAbilityLabel due to write InterfaceToken fail");
1418 return ERR_APPEXECFWK_PARCEL_ERROR;
1419 }
1420 if (!data.WriteString(bundleName)) {
1421 APP_LOGE("fail to GetAbilityLabel due to write bundleName fail");
1422 return ERR_APPEXECFWK_PARCEL_ERROR;
1423 }
1424 if (!data.WriteString(moduleName)) {
1425 APP_LOGE("fail to GetAbilityLabel due to write moduleName fail");
1426 return ERR_APPEXECFWK_PARCEL_ERROR;
1427 }
1428 if (!data.WriteString(abilityName)) {
1429 APP_LOGE("fail to GetAbilityLabel due to write abilityName fail");
1430 return ERR_APPEXECFWK_PARCEL_ERROR;
1431 }
1432 MessageParcel reply;
1433 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ABILITY_LABEL_WITH_MODULE_NAME, data, reply)) {
1434 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
1435 }
1436 int32_t errCode = reply.ReadInt32();
1437 if (errCode != ERR_OK) {
1438 return errCode;
1439 }
1440 label = reply.ReadString();
1441 return ERR_OK;
1442 }
1443
GetBundleArchiveInfo(const std::string & hapFilePath,const BundleFlag flag,BundleInfo & bundleInfo)1444 bool BundleMgrProxy::GetBundleArchiveInfo(const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo)
1445 {
1446 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1447 APP_LOGD("begin to GetBundleArchiveInfo of %{private}s", hapFilePath.c_str());
1448 if (hapFilePath.empty()) {
1449 APP_LOGE("fail to GetBundleArchiveInfo due to params empty");
1450 return false;
1451 }
1452
1453 MessageParcel data;
1454 if (!data.WriteInterfaceToken(GetDescriptor())) {
1455 APP_LOGE("fail to GetBundleArchiveInfo due to write InterfaceToken fail");
1456 return false;
1457 }
1458 if (!data.WriteString(hapFilePath)) {
1459 APP_LOGE("fail to GetBundleArchiveInfo due to write hapFilePath fail");
1460 return false;
1461 }
1462 if (!data.WriteInt32(static_cast<int>(flag))) {
1463 APP_LOGE("fail to GetBundleArchiveInfo due to write flag fail");
1464 return false;
1465 }
1466
1467 if (!GetParcelableInfo<BundleInfo>(BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO, data, bundleInfo)) {
1468 APP_LOGE("fail to GetBundleArchiveInfo from server");
1469 return false;
1470 }
1471 return true;
1472 }
1473
GetBundleArchiveInfo(const std::string & hapFilePath,int32_t flags,BundleInfo & bundleInfo)1474 bool BundleMgrProxy::GetBundleArchiveInfo(const std::string &hapFilePath, int32_t flags, BundleInfo &bundleInfo)
1475 {
1476 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1477 APP_LOGD("begin to GetBundleArchiveInfo with int flags of %{private}s", hapFilePath.c_str());
1478 if (hapFilePath.empty()) {
1479 APP_LOGE("fail to GetBundleArchiveInfo due to params empty");
1480 return false;
1481 }
1482
1483 MessageParcel data;
1484 if (!data.WriteInterfaceToken(GetDescriptor())) {
1485 APP_LOGE("fail to GetBundleArchiveInfo due to write InterfaceToken fail");
1486 return false;
1487 }
1488 if (!data.WriteString(hapFilePath)) {
1489 APP_LOGE("fail to GetBundleArchiveInfo due to write hapFilePath fail");
1490 return false;
1491 }
1492 if (!data.WriteInt32(flags)) {
1493 APP_LOGE("fail to GetBundleArchiveInfo due to write flags fail");
1494 return false;
1495 }
1496
1497 if (!GetParcelableInfo<BundleInfo>(
1498 BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO_WITH_INT_FLAGS, data, bundleInfo)) {
1499 APP_LOGE("fail to GetBundleArchiveInfo from server");
1500 return false;
1501 }
1502 return true;
1503 }
1504
GetBundleArchiveInfoV9(const std::string & hapFilePath,int32_t flags,BundleInfo & bundleInfo)1505 ErrCode BundleMgrProxy::GetBundleArchiveInfoV9(const std::string &hapFilePath, int32_t flags, BundleInfo &bundleInfo)
1506 {
1507 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1508 APP_LOGD("begin to GetBundleArchiveInfoV9 with int flags of %{private}s", hapFilePath.c_str());
1509 if (hapFilePath.empty()) {
1510 APP_LOGE("fail to GetBundleArchiveInfoV9 due to params empty");
1511 return ERR_BUNDLE_MANAGER_INVALID_HAP_PATH;
1512 }
1513
1514 MessageParcel data;
1515 if (!data.WriteInterfaceToken(GetDescriptor())) {
1516 APP_LOGE("fail to GetBundleArchiveInfoV9 due to write InterfaceToken fail");
1517 return ERR_APPEXECFWK_PARCEL_ERROR;
1518 }
1519 if (!data.WriteString(hapFilePath)) {
1520 APP_LOGE("fail to GetBundleArchiveInfoV9 due to write hapFilePath fail");
1521 return ERR_APPEXECFWK_PARCEL_ERROR;
1522 }
1523 if (!data.WriteInt32(flags)) {
1524 APP_LOGE("fail to GetBundleArchiveInfoV9 due to write flags fail");
1525 return ERR_APPEXECFWK_PARCEL_ERROR;
1526 }
1527 return GetParcelableInfoWithErrCode<BundleInfo>(
1528 BundleMgrInterfaceCode::GET_BUNDLE_ARCHIVE_INFO_WITH_INT_FLAGS_V9, data, bundleInfo);
1529 }
1530
GetHapModuleInfo(const AbilityInfo & abilityInfo,HapModuleInfo & hapModuleInfo)1531 bool BundleMgrProxy::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo)
1532 {
1533 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1534 APP_LOGD("begin to GetHapModuleInfo of %{public}s", abilityInfo.package.c_str());
1535 if (abilityInfo.bundleName.empty() || abilityInfo.package.empty()) {
1536 APP_LOGE("fail to GetHapModuleInfo due to params empty");
1537 return false;
1538 }
1539
1540 MessageParcel data;
1541 if (!data.WriteInterfaceToken(GetDescriptor())) {
1542 APP_LOGE("fail to GetHapModuleInfo due to write InterfaceToken fail");
1543 return false;
1544 }
1545 if (!data.WriteParcelable(&abilityInfo)) {
1546 APP_LOGE("fail to GetHapModuleInfo due to write abilityInfo fail");
1547 return false;
1548 }
1549
1550 if (!GetParcelableInfo<HapModuleInfo>(BundleMgrInterfaceCode::GET_HAP_MODULE_INFO, data, hapModuleInfo)) {
1551 APP_LOGE("fail to GetHapModuleInfo from server");
1552 return false;
1553 }
1554 return true;
1555 }
1556
GetHapModuleInfo(const AbilityInfo & abilityInfo,int32_t userId,HapModuleInfo & hapModuleInfo)1557 bool BundleMgrProxy::GetHapModuleInfo(const AbilityInfo &abilityInfo, int32_t userId, HapModuleInfo &hapModuleInfo)
1558 {
1559 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1560 APP_LOGD("begin to GetHapModuleInfo of %{public}s", abilityInfo.package.c_str());
1561 if (abilityInfo.bundleName.empty() || abilityInfo.package.empty()) {
1562 APP_LOGE("fail to GetHapModuleInfo due to params empty");
1563 return false;
1564 }
1565
1566 MessageParcel data;
1567 if (!data.WriteInterfaceToken(GetDescriptor())) {
1568 APP_LOGE("fail to GetHapModuleInfo due to write InterfaceToken fail");
1569 return false;
1570 }
1571 if (!data.WriteParcelable(&abilityInfo)) {
1572 APP_LOGE("fail to GetHapModuleInfo due to write abilityInfo fail");
1573 return false;
1574 }
1575 if (!data.WriteInt32(userId)) {
1576 APP_LOGE("fail to QueryAbilityInfo due to write want fail");
1577 return false;
1578 }
1579
1580 if (!GetParcelableInfo<HapModuleInfo>(
1581 BundleMgrInterfaceCode::GET_HAP_MODULE_INFO_WITH_USERID, data, hapModuleInfo)) {
1582 APP_LOGE_NOFUNC("fail to GetHapModuleInfo from server");
1583 return false;
1584 }
1585 return true;
1586 }
1587
GetLaunchWantForBundle(const std::string & bundleName,Want & want,int32_t userId)1588 ErrCode BundleMgrProxy::GetLaunchWantForBundle(const std::string &bundleName, Want &want, int32_t userId)
1589 {
1590 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1591 APP_LOGD("begin to GetLaunchWantForBundle of %{public}s", bundleName.c_str());
1592 if (bundleName.empty()) {
1593 APP_LOGE("fail to GetHapModuleInfo due to params empty");
1594 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
1595 }
1596
1597 MessageParcel data;
1598 if (!data.WriteInterfaceToken(GetDescriptor())) {
1599 APP_LOGE("fail to GetLaunchWantForBundle due to write InterfaceToken fail");
1600 return ERR_APPEXECFWK_PARCEL_ERROR;
1601 }
1602
1603 if (!data.WriteString(bundleName)) {
1604 APP_LOGE("fail to GetLaunchWantForBundle due to write bundleName fail");
1605 return ERR_APPEXECFWK_PARCEL_ERROR;
1606 }
1607
1608 if (!data.WriteInt32(userId)) {
1609 APP_LOGE("fail to GetLaunchWantForBundle due to write userId fail");
1610 return false;
1611 }
1612
1613 return GetParcelableInfoWithErrCode<Want>(
1614 BundleMgrInterfaceCode::GET_LAUNCH_WANT_FOR_BUNDLE, data, want);
1615 }
1616
GetPermissionDef(const std::string & permissionName,PermissionDef & permissionDef)1617 ErrCode BundleMgrProxy::GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef)
1618 {
1619 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1620 APP_LOGD("begin to GetPermissionDef of %{public}s", permissionName.c_str());
1621 MessageParcel data;
1622 if (!data.WriteInterfaceToken(GetDescriptor())) {
1623 APP_LOGE("fail to GetPermissionDef due to write InterfaceToken fail");
1624 return ERR_APPEXECFWK_PARCEL_ERROR;
1625 }
1626 if (!data.WriteString(permissionName)) {
1627 APP_LOGE("fail to GetPermissionDef due to write permissionName fail");
1628 return ERR_APPEXECFWK_PARCEL_ERROR;
1629 }
1630
1631 return GetParcelableInfoWithErrCode<PermissionDef>(
1632 BundleMgrInterfaceCode::GET_PERMISSION_DEF, data, permissionDef);
1633 }
1634
CleanBundleCacheFilesAutomatic(uint64_t cacheSize)1635 ErrCode BundleMgrProxy::CleanBundleCacheFilesAutomatic(uint64_t cacheSize)
1636 {
1637 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1638
1639 if (cacheSize == 0) {
1640 APP_LOGE("parameter error, cache size must be greater than 0");
1641 return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
1642 }
1643
1644 MessageParcel data;
1645 if (!data.WriteInterfaceToken(GetDescriptor())) {
1646 APP_LOGE("fail to CleanBundleCacheFilesAutomatic due to write InterfaceToken fail");
1647 return ERR_APPEXECFWK_PARCEL_ERROR;
1648 }
1649 if (!data.WriteUint64(cacheSize)) {
1650 APP_LOGE("fail to CleanBundleCacheFilesAutomatic due to write cache size fail");
1651 return ERR_APPEXECFWK_PARCEL_ERROR;
1652 }
1653
1654 MessageParcel reply;
1655 if (!SendTransactCmd(BundleMgrInterfaceCode::AUTO_CLEAN_CACHE_BY_SIZE, data, reply)) {
1656 APP_LOGE("fail to CleanBundleCacheFilesAutomatic from server");
1657 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
1658 }
1659 return reply.ReadInt32();
1660 }
1661
CleanBundleCacheFiles(const std::string & bundleName,const sptr<ICleanCacheCallback> cleanCacheCallback,int32_t userId,int32_t appIndex)1662 ErrCode BundleMgrProxy::CleanBundleCacheFiles(
1663 const std::string &bundleName, const sptr<ICleanCacheCallback> cleanCacheCallback, int32_t userId, int32_t appIndex)
1664 {
1665 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1666 APP_LOGD("begin to CleanBundleCacheFiles of %{public}s, userId:%{public}d, appIndex:%{public}d",
1667 bundleName.c_str(), userId, appIndex);
1668 if (bundleName.empty()) {
1669 APP_LOGE("fail to CleanBundleCacheFiles due to bundleName empty");
1670 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
1671 }
1672 if (cleanCacheCallback == nullptr) {
1673 APP_LOGE("fail to CleanBundleCacheFiles due to params error");
1674 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
1675 }
1676
1677 MessageParcel data;
1678 if (!data.WriteInterfaceToken(GetDescriptor())) {
1679 APP_LOGE("fail to CleanBundleCacheFiles due to write InterfaceToken fail");
1680 return ERR_APPEXECFWK_PARCEL_ERROR;
1681 }
1682 if (!data.WriteString(bundleName)) {
1683 APP_LOGE("fail to CleanBundleCacheFiles due to write bundleName fail");
1684 return ERR_APPEXECFWK_PARCEL_ERROR;
1685 }
1686 if (!data.WriteRemoteObject(cleanCacheCallback->AsObject())) {
1687 APP_LOGE("fail to CleanBundleCacheFiles, for write parcel failed");
1688 return ERR_APPEXECFWK_PARCEL_ERROR;
1689 }
1690 if (!data.WriteInt32(userId)) {
1691 APP_LOGE("fail to CleanBundleCacheFiles due to write userId fail");
1692 return ERR_APPEXECFWK_PARCEL_ERROR;
1693 }
1694 if (!data.WriteInt32(appIndex)) {
1695 APP_LOGE("fail to CleanBundleDataFiles due to write appIndex fail");
1696 return false;
1697 }
1698
1699 MessageParcel reply;
1700 if (!SendTransactCmd(BundleMgrInterfaceCode::CLEAN_BUNDLE_CACHE_FILES, data, reply)) {
1701 APP_LOGE("fail to CleanBundleCacheFiles from server");
1702 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
1703 }
1704 return reply.ReadInt32();
1705 }
1706
CleanBundleDataFiles(const std::string & bundleName,const int userId,const int appIndex)1707 bool BundleMgrProxy::CleanBundleDataFiles(const std::string &bundleName, const int userId, const int appIndex)
1708 {
1709 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1710 APP_LOGD("begin to CleanBundleDataFiles of %{public}s, userId:%{public}d, appIndex:%{public}d",
1711 bundleName.c_str(), userId, appIndex);
1712 if (bundleName.empty()) {
1713 APP_LOGE("fail to CleanBundleDataFiles due to params empty");
1714 return false;
1715 }
1716
1717 MessageParcel data;
1718 if (!data.WriteInterfaceToken(GetDescriptor())) {
1719 APP_LOGE("fail to CleanBundleDataFiles due to write InterfaceToken fail");
1720 return false;
1721 }
1722 if (!data.WriteString(bundleName)) {
1723 APP_LOGE("fail to CleanBundleDataFiles due to write hapFilePath fail");
1724 return false;
1725 }
1726 if (!data.WriteInt32(userId)) {
1727 APP_LOGE("fail to CleanBundleDataFiles due to write userId fail");
1728 return false;
1729 }
1730 if (!data.WriteInt32(appIndex)) {
1731 APP_LOGE("fail to CleanBundleDataFiles due to write appIndex fail");
1732 return false;
1733 }
1734
1735 MessageParcel reply;
1736 if (!SendTransactCmd(BundleMgrInterfaceCode::CLEAN_BUNDLE_DATA_FILES, data, reply)) {
1737 APP_LOGE("fail to CleanBundleDataFiles from server");
1738 return false;
1739 }
1740 return reply.ReadBool();
1741 }
1742
RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> & bundleStatusCallback)1743 bool BundleMgrProxy::RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback)
1744 {
1745 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1746 APP_LOGD("begin to RegisterBundleStatusCallback");
1747 if (!bundleStatusCallback || bundleStatusCallback->GetBundleName().empty()) {
1748 APP_LOGE("fail to RegisterBundleStatusCallback");
1749 return false;
1750 }
1751
1752 MessageParcel data;
1753 if (!data.WriteInterfaceToken(GetDescriptor())) {
1754 APP_LOGE("fail to RegisterBundleStatusCallback due to write InterfaceToken fail");
1755 return false;
1756 }
1757 if (!data.WriteString(bundleStatusCallback->GetBundleName())) {
1758 APP_LOGE("fail to RegisterBundleStatusCallback due to write bundleName fail");
1759 return false;
1760 }
1761 if (!data.WriteInt32(bundleStatusCallback->GetUserId())) {
1762 APP_LOGE("fail to RegisterBundleStatusCallback due to write userId fail");
1763 return false;
1764 }
1765 if (!data.WriteRemoteObject(bundleStatusCallback->AsObject())) {
1766 APP_LOGE("fail to RegisterBundleStatusCallback, for write parcel failed");
1767 return false;
1768 }
1769
1770 MessageParcel reply;
1771 if (!SendTransactCmd(BundleMgrInterfaceCode::REGISTER_BUNDLE_STATUS_CALLBACK, data, reply)) {
1772 APP_LOGE("fail to RegisterBundleStatusCallback from server");
1773 return false;
1774 }
1775 return reply.ReadBool();
1776 }
1777
RegisterBundleEventCallback(const sptr<IBundleEventCallback> & bundleEventCallback)1778 bool BundleMgrProxy::RegisterBundleEventCallback(const sptr<IBundleEventCallback> &bundleEventCallback)
1779 {
1780 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1781 APP_LOGD("begin to RegisterBundleEventCallback");
1782 if (!bundleEventCallback) {
1783 APP_LOGE("bundleEventCallback is null");
1784 return false;
1785 }
1786
1787 MessageParcel data;
1788 if (!data.WriteInterfaceToken(GetDescriptor())) {
1789 APP_LOGE("fail to RegisterBundleEventCallback due to write InterfaceToken fail");
1790 return false;
1791 }
1792 if (!data.WriteRemoteObject(bundleEventCallback->AsObject())) {
1793 APP_LOGE("write BundleEventCallback failed");
1794 return false;
1795 }
1796
1797 MessageParcel reply;
1798 if (!SendTransactCmd(BundleMgrInterfaceCode::REGISTER_BUNDLE_EVENT_CALLBACK, data, reply)) {
1799 APP_LOGE("fail to RegisterBundleEventCallback from server");
1800 return false;
1801 }
1802 return reply.ReadBool();
1803 }
1804
UnregisterBundleEventCallback(const sptr<IBundleEventCallback> & bundleEventCallback)1805 bool BundleMgrProxy::UnregisterBundleEventCallback(const sptr<IBundleEventCallback> &bundleEventCallback)
1806 {
1807 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1808 APP_LOGD("begin to UnregisterBundleEventCallback");
1809 if (!bundleEventCallback) {
1810 APP_LOGE("bundleEventCallback is null");
1811 return false;
1812 }
1813
1814 MessageParcel data;
1815 if (!data.WriteInterfaceToken(GetDescriptor())) {
1816 APP_LOGE("fail to UnregisterBundleEventCallback due to write InterfaceToken fail");
1817 return false;
1818 }
1819 if (!data.WriteRemoteObject(bundleEventCallback->AsObject())) {
1820 APP_LOGE("fail to UnregisterBundleEventCallback, for write parcel failed");
1821 return false;
1822 }
1823
1824 MessageParcel reply;
1825 if (!SendTransactCmd(BundleMgrInterfaceCode::UNREGISTER_BUNDLE_EVENT_CALLBACK, data, reply)) {
1826 APP_LOGE("fail to UnregisterBundleEventCallback from server");
1827 return false;
1828 }
1829 return reply.ReadBool();
1830 }
1831
ClearBundleStatusCallback(const sptr<IBundleStatusCallback> & bundleStatusCallback)1832 bool BundleMgrProxy::ClearBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback)
1833 {
1834 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1835 APP_LOGD("begin to ClearBundleStatusCallback");
1836 if (!bundleStatusCallback) {
1837 APP_LOGE("fail to ClearBundleStatusCallback, for bundleStatusCallback is nullptr");
1838 return false;
1839 }
1840
1841 MessageParcel data;
1842 if (!data.WriteInterfaceToken(GetDescriptor())) {
1843 APP_LOGE("fail to ClearBundleStatusCallback due to write InterfaceToken fail");
1844 return false;
1845 }
1846 if (!data.WriteRemoteObject(bundleStatusCallback->AsObject())) {
1847 APP_LOGE("fail to ClearBundleStatusCallback, for write parcel failed");
1848 return false;
1849 }
1850
1851 MessageParcel reply;
1852 if (!SendTransactCmd(BundleMgrInterfaceCode::CLEAR_BUNDLE_STATUS_CALLBACK, data, reply)) {
1853 APP_LOGE("fail to CleanBundleCacheFiles from server");
1854 return false;
1855 }
1856 return reply.ReadBool();
1857 }
1858
UnregisterBundleStatusCallback()1859 bool BundleMgrProxy::UnregisterBundleStatusCallback()
1860 {
1861 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1862 APP_LOGD("begin to UnregisterBundleStatusCallback");
1863 MessageParcel data;
1864 if (!data.WriteInterfaceToken(GetDescriptor())) {
1865 APP_LOGE("fail to UnregisterBundleStatusCallback due to write InterfaceToken fail");
1866 return false;
1867 }
1868
1869 MessageParcel reply;
1870 if (!SendTransactCmd(BundleMgrInterfaceCode::UNREGISTER_BUNDLE_STATUS_CALLBACK, data, reply)) {
1871 APP_LOGE("fail to UnregisterBundleStatusCallback from server");
1872 return false;
1873 }
1874 return reply.ReadBool();
1875 }
1876
DumpInfos(const DumpFlag flag,const std::string & bundleName,int32_t userId,std::string & result)1877 bool BundleMgrProxy::DumpInfos(
1878 const DumpFlag flag, const std::string &bundleName, int32_t userId, std::string &result)
1879 {
1880 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1881 APP_LOGD("begin to dump");
1882 MessageParcel data;
1883 if (!data.WriteInterfaceToken(GetDescriptor())) {
1884 APP_LOGE("fail to dump due to write InterfaceToken fail");
1885 return false;
1886 }
1887 if (!data.WriteInt32(static_cast<int>(flag))) {
1888 APP_LOGE("fail to dump due to write flag fail");
1889 return false;
1890 }
1891 if (!data.WriteString(bundleName)) {
1892 APP_LOGE("fail to dump due to write bundleName fail");
1893 return false;
1894 }
1895 if (!data.WriteInt32(userId)) {
1896 APP_LOGE("fail to dump due to write userId fail");
1897 return false;
1898 }
1899
1900 MessageParcel reply;
1901 if (!SendTransactCmd(BundleMgrInterfaceCode::DUMP_INFOS, data, reply)) {
1902 APP_LOGE("fail to dump from server");
1903 return false;
1904 }
1905 if (!reply.ReadBool()) {
1906 APP_LOGE("readParcelableInfo failed");
1907 return false;
1908 }
1909 std::vector<std::string> dumpInfos;
1910 if (!reply.ReadStringVector(&dumpInfos)) {
1911 APP_LOGE("fail to dump from reply");
1912 return false;
1913 }
1914 result = std::accumulate(dumpInfos.begin(), dumpInfos.end(), result);
1915 return true;
1916 }
1917
IsModuleRemovable(const std::string & bundleName,const std::string & moduleName,bool & isRemovable)1918 ErrCode BundleMgrProxy::IsModuleRemovable(const std::string &bundleName, const std::string &moduleName,
1919 bool &isRemovable)
1920 {
1921 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1922 APP_LOGD("begin to IsModuleRemovable of %{public}s", bundleName.c_str());
1923 if (bundleName.empty()) {
1924 APP_LOGE("fail to IsModuleRemovable due to bundleName empty");
1925 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
1926 }
1927 if (moduleName.empty()) {
1928 APP_LOGE("fail to IsModuleRemovable due to moduleName empty");
1929 return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
1930 }
1931
1932 MessageParcel data;
1933 if (!data.WriteInterfaceToken(GetDescriptor())) {
1934 APP_LOGE("fail to IsModuleRemovable due to write InterfaceToken fail");
1935 return ERR_APPEXECFWK_PARCEL_ERROR;
1936 }
1937 if (!data.WriteString(bundleName)) {
1938 APP_LOGE("fail to IsModuleRemovable due to write bundleName fail");
1939 return ERR_APPEXECFWK_PARCEL_ERROR;
1940 }
1941
1942 if (!data.WriteString(moduleName)) {
1943 APP_LOGE("fail to IsModuleRemovable due to write moduleName fail");
1944 return ERR_APPEXECFWK_PARCEL_ERROR;
1945 }
1946 MessageParcel reply;
1947 if (!SendTransactCmd(BundleMgrInterfaceCode::IS_MODULE_REMOVABLE, data, reply)) {
1948 APP_LOGE("fail to IsModuleRemovable from server");
1949 return false;
1950 }
1951 ErrCode ret = reply.ReadInt32();
1952 if (ret == ERR_OK) {
1953 isRemovable = reply.ReadBool();
1954 }
1955 return ret;
1956 }
1957
SetModuleRemovable(const std::string & bundleName,const std::string & moduleName,bool isEnable)1958 bool BundleMgrProxy::SetModuleRemovable(const std::string &bundleName, const std::string &moduleName, bool isEnable)
1959 {
1960 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1961 APP_LOGD("begin to SetModuleRemovable of %{public}s", bundleName.c_str());
1962 if (bundleName.empty() || moduleName.empty()) {
1963 APP_LOGE("fail to SetModuleRemovable due to params empty");
1964 return false;
1965 }
1966
1967 MessageParcel data;
1968 if (!data.WriteInterfaceToken(GetDescriptor())) {
1969 APP_LOGE("fail to SetModuleRemovable due to write InterfaceToken fail");
1970 return false;
1971 }
1972 if (!data.WriteString(bundleName)) {
1973 APP_LOGE("fail to SetModuleRemovable due to write bundleName fail");
1974 return false;
1975 }
1976
1977 if (!data.WriteString(moduleName)) {
1978 APP_LOGE("fail to SetModuleRemovable due to write moduleName fail");
1979 return false;
1980 }
1981 if (!data.WriteBool(isEnable)) {
1982 APP_LOGE("fail to SetModuleRemovable due to write isEnable fail");
1983 return false;
1984 }
1985 MessageParcel reply;
1986 if (!SendTransactCmd(BundleMgrInterfaceCode::SET_MODULE_REMOVABLE, data, reply)) {
1987 APP_LOGE("fail to SetModuleRemovable from server");
1988 return false;
1989 }
1990 return reply.ReadBool();
1991 }
1992
GetModuleUpgradeFlag(const std::string & bundleName,const std::string & moduleName)1993 bool BundleMgrProxy::GetModuleUpgradeFlag(const std::string &bundleName, const std::string &moduleName)
1994 {
1995 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
1996 APP_LOGD("begin to GetModuleUpgradeFlag of %{public}s", bundleName.c_str());
1997 if (bundleName.empty() || moduleName.empty()) {
1998 APP_LOGE("fail to GetModuleUpgradeFlag due to params empty");
1999 return false;
2000 }
2001
2002 MessageParcel data;
2003 if (!data.WriteInterfaceToken(GetDescriptor())) {
2004 APP_LOGE("fail to GetModuleUpgradeFlag due to write InterfaceToken fail");
2005 return false;
2006 }
2007 if (!data.WriteString(bundleName)) {
2008 APP_LOGE("fail to GetModuleUpgradeFlag due to write bundleName fail");
2009 return false;
2010 }
2011
2012 if (!data.WriteString(moduleName)) {
2013 APP_LOGE("fail to GetModuleUpgradeFlag due to write moduleName fail");
2014 return false;
2015 }
2016 MessageParcel reply;
2017 if (!SendTransactCmd(BundleMgrInterfaceCode::IS_MODULE_NEED_UPDATE, data, reply)) {
2018 APP_LOGE("fail to GetModuleUpgradeFlag from server");
2019 return false;
2020 }
2021 return reply.ReadBool();
2022 }
2023
SetModuleUpgradeFlag(const std::string & bundleName,const std::string & moduleName,int32_t upgradeFlag)2024 ErrCode BundleMgrProxy::SetModuleUpgradeFlag(const std::string &bundleName,
2025 const std::string &moduleName, int32_t upgradeFlag)
2026 {
2027 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2028 APP_LOGD("begin to SetModuleUpgradeFlag of %{public}s", bundleName.c_str());
2029 if (bundleName.empty()) {
2030 APP_LOGE("fail to SetModuleUpgradeFlag due to bundleName empty");
2031 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
2032 }
2033 if (moduleName.empty()) {
2034 APP_LOGE("fail to SetModuleUpgradeFlag due to moduleName empty");
2035 return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
2036 }
2037
2038 MessageParcel data;
2039 if (!data.WriteInterfaceToken(GetDescriptor())) {
2040 APP_LOGE("fail to SetModuleUpgradeFlag due to write InterfaceToken fail");
2041 return ERR_APPEXECFWK_PARCEL_ERROR;
2042 }
2043 if (!data.WriteString(bundleName)) {
2044 APP_LOGE("fail to SetModuleUpgradeFlag due to write bundleName fail");
2045 return ERR_APPEXECFWK_PARCEL_ERROR;
2046 }
2047
2048 if (!data.WriteString(moduleName)) {
2049 APP_LOGE("fail to SetModuleUpgradeFlag due to write moduleName fail");
2050 return ERR_APPEXECFWK_PARCEL_ERROR;
2051 }
2052 if (!data.WriteInt32(upgradeFlag)) {
2053 APP_LOGE("fail to SetModuleUpgradeFlag due to write isEnable fail");
2054 return ERR_APPEXECFWK_PARCEL_ERROR;
2055 }
2056 MessageParcel reply;
2057 if (!SendTransactCmd(BundleMgrInterfaceCode::SET_MODULE_NEED_UPDATE, data, reply)) {
2058 APP_LOGE("fail to SetModuleUpgradeFlag from server");
2059 return ERR_APPEXECFWK_PARCEL_ERROR;
2060 }
2061 return reply.ReadInt32();
2062 }
2063
IsApplicationEnabled(const std::string & bundleName,bool & isEnable)2064 ErrCode BundleMgrProxy::IsApplicationEnabled(const std::string &bundleName, bool &isEnable)
2065 {
2066 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2067 APP_LOGD("begin to IsApplicationEnabled of %{public}s", bundleName.c_str());
2068 if (bundleName.empty()) {
2069 APP_LOGE("fail to IsApplicationEnabled due to params empty");
2070 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
2071 }
2072
2073 MessageParcel data;
2074 if (!data.WriteInterfaceToken(GetDescriptor())) {
2075 APP_LOGE("fail to IsApplicationEnabled due to write InterfaceToken fail");
2076 return ERR_APPEXECFWK_PARCEL_ERROR;
2077 }
2078 if (!data.WriteString(bundleName)) {
2079 APP_LOGE("fail to IsApplicationEnabled due to write bundleName fail");
2080 return ERR_APPEXECFWK_PARCEL_ERROR;
2081 }
2082 MessageParcel reply;
2083 if (!SendTransactCmd(BundleMgrInterfaceCode::IS_APPLICATION_ENABLED, data, reply)) {
2084 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
2085 }
2086 int32_t ret = reply.ReadInt32();
2087 if (ret != NO_ERROR) {
2088 return ret;
2089 }
2090 isEnable = reply.ReadBool();
2091 return NO_ERROR;
2092 }
2093
IsCloneApplicationEnabled(const std::string & bundleName,int32_t appIndex,bool & isEnable)2094 ErrCode BundleMgrProxy::IsCloneApplicationEnabled(const std::string &bundleName, int32_t appIndex, bool &isEnable)
2095 {
2096 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2097 APP_LOGD("begin to IsCloneApplicationEnabled of %{public}s", bundleName.c_str());
2098 if (bundleName.empty()) {
2099 APP_LOGE("fail to IsCloneApplicationEnabled due to params empty");
2100 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
2101 }
2102
2103 MessageParcel data;
2104 if (!data.WriteInterfaceToken(GetDescriptor())) {
2105 APP_LOGE("fail to IsCloneApplicationEnabled due to write InterfaceToken fail");
2106 return ERR_APPEXECFWK_PARCEL_ERROR;
2107 }
2108 if (!data.WriteString(bundleName)) {
2109 APP_LOGE("fail to IsCloneApplicationEnabled due to write bundleName fail");
2110 return ERR_APPEXECFWK_PARCEL_ERROR;
2111 }
2112 if (!data.WriteInt32(appIndex)) {
2113 APP_LOGE("fail to IsCloneApplicationEnabled due to write appIndex fail");
2114 return ERR_APPEXECFWK_PARCEL_ERROR;
2115 }
2116 MessageParcel reply;
2117 if (!SendTransactCmd(BundleMgrInterfaceCode::IS_CLONE_APPLICATION_ENABLED, data, reply)) {
2118 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
2119 }
2120 int32_t ret = reply.ReadInt32();
2121 if (ret != NO_ERROR) {
2122 return ret;
2123 }
2124 isEnable = reply.ReadBool();
2125 return NO_ERROR;
2126 }
2127
SetApplicationEnabled(const std::string & bundleName,bool isEnable,int32_t userId)2128 ErrCode BundleMgrProxy::SetApplicationEnabled(const std::string &bundleName, bool isEnable, int32_t userId)
2129 {
2130 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2131 APP_LOGD("begin to SetApplicationEnabled of %{public}s", bundleName.c_str());
2132 if (bundleName.empty()) {
2133 APP_LOGE("fail to SetApplicationEnabled due to params empty");
2134 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
2135 }
2136
2137 MessageParcel data;
2138 if (!data.WriteInterfaceToken(GetDescriptor())) {
2139 APP_LOGE("fail to SetApplicationEnabled due to write InterfaceToken fail");
2140 return ERR_APPEXECFWK_PARCEL_ERROR;
2141 }
2142 if (!data.WriteString(bundleName)) {
2143 APP_LOGE("fail to SetApplicationEnabled due to write bundleName fail");
2144 return ERR_APPEXECFWK_PARCEL_ERROR;
2145 }
2146 if (!data.WriteBool(isEnable)) {
2147 APP_LOGE("fail to SetApplicationEnabled due to write isEnable fail");
2148 return ERR_APPEXECFWK_PARCEL_ERROR;
2149 }
2150 if (!data.WriteInt32(userId)) {
2151 APP_LOGE("fail to SetApplicationEnabled due to write userId fail");
2152 return ERR_APPEXECFWK_PARCEL_ERROR;
2153 }
2154 MessageParcel reply;
2155 if (!SendTransactCmd(BundleMgrInterfaceCode::SET_APPLICATION_ENABLED, data, reply)) {
2156 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
2157 }
2158 return reply.ReadInt32();
2159 }
2160
SetCloneApplicationEnabled(const std::string & bundleName,int32_t appIndex,bool isEnable,int32_t userId)2161 ErrCode BundleMgrProxy::SetCloneApplicationEnabled(
2162 const std::string &bundleName, int32_t appIndex, bool isEnable, int32_t userId)
2163 {
2164 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2165 APP_LOGD("begin to SetCloneApplicationEnabled of %{public}s", bundleName.c_str());
2166 if (bundleName.empty()) {
2167 APP_LOGE("fail to SetCloneApplicationEnabled due to params empty");
2168 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
2169 }
2170
2171 MessageParcel data;
2172 if (!data.WriteInterfaceToken(GetDescriptor())) {
2173 APP_LOGE("fail to SetCloneApplicationEnabled due to write InterfaceToken fail");
2174 return ERR_APPEXECFWK_PARCEL_ERROR;
2175 }
2176 if (!data.WriteString(bundleName)) {
2177 APP_LOGE("fail to SetCloneApplicationEnabled due to write bundleName fail");
2178 return ERR_APPEXECFWK_PARCEL_ERROR;
2179 }
2180 if (!data.WriteInt32(appIndex)) {
2181 APP_LOGE("fail to SetCloneApplicationEnabled due to write appIndex fail");
2182 return ERR_APPEXECFWK_PARCEL_ERROR;
2183 }
2184 if (!data.WriteBool(isEnable)) {
2185 APP_LOGE("fail to SetCloneApplicationEnabled due to write isEnable fail");
2186 return ERR_APPEXECFWK_PARCEL_ERROR;
2187 }
2188 if (!data.WriteInt32(userId)) {
2189 APP_LOGE("fail to SetCloneApplicationEnabled due to write userId fail");
2190 return ERR_APPEXECFWK_PARCEL_ERROR;
2191 }
2192 MessageParcel reply;
2193 if (!SendTransactCmd(BundleMgrInterfaceCode::SET_CLONE_APPLICATION_ENABLED, data, reply)) {
2194 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
2195 }
2196 return reply.ReadInt32();
2197 }
2198
IsAbilityEnabled(const AbilityInfo & abilityInfo,bool & isEnable)2199 ErrCode BundleMgrProxy::IsAbilityEnabled(const AbilityInfo &abilityInfo, bool &isEnable)
2200 {
2201 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2202 APP_LOGD("begin to IsAbilityEnabled of %{public}s", abilityInfo.name.c_str());
2203 if (abilityInfo.bundleName.empty() || abilityInfo.name.empty()) {
2204 APP_LOGE("fail to IsAbilityEnabled due to params empty");
2205 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
2206 }
2207 MessageParcel data;
2208 if (!data.WriteInterfaceToken(GetDescriptor())) {
2209 APP_LOGE("fail to IsAbilityEnabled due to write InterfaceToken fail");
2210 return ERR_APPEXECFWK_PARCEL_ERROR;
2211 }
2212 if (!data.WriteParcelable(&abilityInfo)) {
2213 APP_LOGE("fail to IsAbilityEnabled due to write abilityInfo fail");
2214 return ERR_APPEXECFWK_PARCEL_ERROR;
2215 }
2216 MessageParcel reply;
2217 if (!SendTransactCmd(BundleMgrInterfaceCode::IS_ABILITY_ENABLED, data, reply)) {
2218 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
2219 }
2220 int32_t ret = reply.ReadInt32();
2221 if (ret != NO_ERROR) {
2222 return ret;
2223 }
2224 isEnable = reply.ReadBool();
2225 return NO_ERROR;
2226 }
2227
IsCloneAbilityEnabled(const AbilityInfo & abilityInfo,int32_t appIndex,bool & isEnable)2228 ErrCode BundleMgrProxy::IsCloneAbilityEnabled(const AbilityInfo &abilityInfo, int32_t appIndex, bool &isEnable)
2229 {
2230 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2231 APP_LOGD("begin to IsCloneAbilityEnabled of %{public}s", abilityInfo.name.c_str());
2232 if (abilityInfo.bundleName.empty() || abilityInfo.name.empty()) {
2233 APP_LOGE("fail to IsCloneAbilityEnabled due to params empty");
2234 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
2235 }
2236 MessageParcel data;
2237 if (!data.WriteInterfaceToken(GetDescriptor())) {
2238 APP_LOGE("fail to IsCloneAbilityEnabled due to write InterfaceToken fail");
2239 return ERR_APPEXECFWK_PARCEL_ERROR;
2240 }
2241 if (!data.WriteParcelable(&abilityInfo)) {
2242 APP_LOGE("fail to IsCloneAbilityEnabled due to write abilityInfo fail");
2243 return ERR_APPEXECFWK_PARCEL_ERROR;
2244 }
2245 if (!data.WriteInt32(appIndex)) {
2246 APP_LOGE("fail to IsCloneAbilityEnabled due to write appIndex fail");
2247 return ERR_APPEXECFWK_PARCEL_ERROR;
2248 }
2249 MessageParcel reply;
2250 if (!SendTransactCmd(BundleMgrInterfaceCode::IS_CLONE_ABILITY_ENABLED, data, reply)) {
2251 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
2252 }
2253 int32_t ret = reply.ReadInt32();
2254 if (ret != NO_ERROR) {
2255 return ret;
2256 }
2257 isEnable = reply.ReadBool();
2258 return NO_ERROR;
2259 }
2260
SetAbilityEnabled(const AbilityInfo & abilityInfo,bool isEnabled,int32_t userId)2261 ErrCode BundleMgrProxy::SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled, int32_t userId)
2262 {
2263 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2264 APP_LOGD("begin to SetAbilityEnabled of %{public}s", abilityInfo.name.c_str());
2265 if (abilityInfo.bundleName.empty() || abilityInfo.name.empty()) {
2266 APP_LOGE("fail to SetAbilityEnabled due to params empty");
2267 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
2268 }
2269 MessageParcel data;
2270 if (!data.WriteInterfaceToken(GetDescriptor())) {
2271 APP_LOGE("fail to SetAbilityEnabled due to write InterfaceToken fail");
2272 return ERR_APPEXECFWK_PARCEL_ERROR;
2273 }
2274 if (!data.WriteParcelable(&abilityInfo)) {
2275 APP_LOGE("fail to SetAbilityEnabled due to write abilityInfo fail");
2276 return ERR_APPEXECFWK_PARCEL_ERROR;
2277 }
2278 if (!data.WriteBool(isEnabled)) {
2279 APP_LOGE("fail to SetAbilityEnabled due to write isEnabled fail");
2280 return ERR_APPEXECFWK_PARCEL_ERROR;
2281 }
2282 if (!data.WriteInt32(userId)) {
2283 APP_LOGE("fail to SetAbilityEnabled due to write userId fail");
2284 return ERR_APPEXECFWK_PARCEL_ERROR;
2285 }
2286
2287 MessageParcel reply;
2288 if (!SendTransactCmd(BundleMgrInterfaceCode::SET_ABILITY_ENABLED, data, reply)) {
2289 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
2290 }
2291 return reply.ReadInt32();
2292 }
2293
SetCloneAbilityEnabled(const AbilityInfo & abilityInfo,int32_t appIndex,bool isEnabled,int32_t userId)2294 ErrCode BundleMgrProxy::SetCloneAbilityEnabled(
2295 const AbilityInfo &abilityInfo, int32_t appIndex, bool isEnabled, int32_t userId)
2296 {
2297 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2298 APP_LOGD("begin to SetCloneAbilityEnabled of %{public}s", abilityInfo.name.c_str());
2299 if (abilityInfo.bundleName.empty() || abilityInfo.name.empty()) {
2300 APP_LOGE("fail to SetCloneAbilityEnabled due to params empty");
2301 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
2302 }
2303 MessageParcel data;
2304 if (!data.WriteInterfaceToken(GetDescriptor())) {
2305 APP_LOGE("fail to SetCloneAbilityEnabled due to write InterfaceToken fail");
2306 return ERR_APPEXECFWK_PARCEL_ERROR;
2307 }
2308 if (!data.WriteParcelable(&abilityInfo)) {
2309 APP_LOGE("fail to SetCloneAbilityEnabled due to write abilityInfo fail");
2310 return ERR_APPEXECFWK_PARCEL_ERROR;
2311 }
2312 if (!data.WriteInt32(appIndex)) {
2313 APP_LOGE("fail to SetCloneAbilityEnabled due to write appIndex fail");
2314 return ERR_APPEXECFWK_PARCEL_ERROR;
2315 }
2316 if (!data.WriteBool(isEnabled)) {
2317 APP_LOGE("fail to SetCloneAbilityEnabled due to write isEnabled fail");
2318 return ERR_APPEXECFWK_PARCEL_ERROR;
2319 }
2320 if (!data.WriteInt32(userId)) {
2321 APP_LOGE("fail to SetCloneAbilityEnabled due to write userId fail");
2322 return ERR_APPEXECFWK_PARCEL_ERROR;
2323 }
2324
2325 MessageParcel reply;
2326 if (!SendTransactCmd(BundleMgrInterfaceCode::SET_CLONE_ABILITY_ENABLED, data, reply)) {
2327 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
2328 }
2329 return reply.ReadInt32();
2330 }
2331
GetAbilityInfo(const std::string & bundleName,const std::string & abilityName,AbilityInfo & abilityInfo)2332 bool BundleMgrProxy::GetAbilityInfo(
2333 const std::string &bundleName, const std::string &abilityName, AbilityInfo &abilityInfo)
2334 {
2335 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2336 LOG_D(BMS_TAG_QUERY, "GetAbilityInfo bundleName:%{public}s abilityName:%{public}s",
2337 bundleName.c_str(), abilityName.c_str());
2338 if (bundleName.empty() || abilityName.empty()) {
2339 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo failed params empty");
2340 return false;
2341 }
2342
2343 MessageParcel data;
2344 if (!data.WriteInterfaceToken(GetDescriptor())) {
2345 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo write MessageParcel fail");
2346 return false;
2347 }
2348 if (!data.WriteString(bundleName)) {
2349 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo write bundleName fail");
2350 return false;
2351 }
2352 if (!data.WriteString(abilityName)) {
2353 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo write abilityName fail");
2354 return false;
2355 }
2356
2357 if (!GetParcelableInfo<AbilityInfo>(BundleMgrInterfaceCode::GET_ABILITY_INFO, data, abilityInfo)) {
2358 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo from server fail");
2359 return false;
2360 }
2361 return true;
2362 }
2363
GetAbilityInfo(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,AbilityInfo & abilityInfo)2364 bool BundleMgrProxy::GetAbilityInfo(
2365 const std::string &bundleName, const std::string &moduleName,
2366 const std::string &abilityName, AbilityInfo &abilityInfo)
2367 {
2368 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2369 LOG_D(BMS_TAG_QUERY, "GetAbilityInfo bundleName:%{public}s moduleName:%{public}s abilityName:%{public}s",
2370 bundleName.c_str(), moduleName.c_str(), abilityName.c_str());
2371 if (bundleName.empty() || moduleName.empty() || abilityName.empty()) {
2372 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo failed params empty");
2373 return false;
2374 }
2375
2376 MessageParcel data;
2377 if (!data.WriteInterfaceToken(GetDescriptor())) {
2378 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo write MessageParcel fail");
2379 return false;
2380 }
2381 if (!data.WriteString(bundleName)) {
2382 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo write bundleName fail");
2383 return false;
2384 }
2385 if (!data.WriteString(moduleName)) {
2386 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo write moduleName fail");
2387 return false;
2388 }
2389 if (!data.WriteString(abilityName)) {
2390 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo write abilityName fail");
2391 return false;
2392 }
2393
2394 if (!GetParcelableInfo<AbilityInfo>(
2395 BundleMgrInterfaceCode::GET_ABILITY_INFO_WITH_MODULE_NAME, data, abilityInfo)) {
2396 LOG_E(BMS_TAG_QUERY, "GetAbilityInfo from server fail");
2397 return false;
2398 }
2399 return true;
2400 }
2401
GetBundleInstaller()2402 sptr<IBundleInstaller> BundleMgrProxy::GetBundleInstaller()
2403 {
2404 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2405 APP_LOGD("begin to get bundle installer");
2406 MessageParcel data;
2407 MessageParcel reply;
2408 if (!data.WriteInterfaceToken(GetDescriptor())) {
2409 APP_LOGE("fail to GetBundleInstaller due to write InterfaceToken fail");
2410 return nullptr;
2411 }
2412 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_BUNDLE_INSTALLER, data, reply)) {
2413 return nullptr;
2414 }
2415
2416 sptr<IRemoteObject> object = reply.ReadRemoteObject();
2417 if (object == nullptr) {
2418 APP_LOGE("read failed");
2419 return nullptr;
2420 }
2421 sptr<IBundleInstaller> installer = iface_cast<IBundleInstaller>(object);
2422 if (installer == nullptr) {
2423 APP_LOGE("bundle installer is nullptr");
2424 }
2425
2426 APP_LOGD("get bundle installer success");
2427 return installer;
2428 }
2429
GetBundleUserMgr()2430 sptr<IBundleUserMgr> BundleMgrProxy::GetBundleUserMgr()
2431 {
2432 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2433 MessageParcel data;
2434 MessageParcel reply;
2435 if (!data.WriteInterfaceToken(GetDescriptor())) {
2436 APP_LOGE("fail to get bundle user mgr due to write InterfaceToken fail");
2437 return nullptr;
2438 }
2439 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_BUNDLE_USER_MGR, data, reply)) {
2440 return nullptr;
2441 }
2442
2443 sptr<IRemoteObject> object = reply.ReadRemoteObject();
2444 if (object == nullptr) {
2445 APP_LOGE("read failed");
2446 return nullptr;
2447 }
2448 sptr<IBundleUserMgr> bundleUserMgr = iface_cast<IBundleUserMgr>(object);
2449 if (bundleUserMgr == nullptr) {
2450 APP_LOGE("bundleUserMgr is nullptr");
2451 }
2452
2453 return bundleUserMgr;
2454 }
2455
GetVerifyManager()2456 sptr<IVerifyManager> BundleMgrProxy::GetVerifyManager()
2457 {
2458 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2459 MessageParcel data;
2460 MessageParcel reply;
2461 if (!data.WriteInterfaceToken(GetDescriptor())) {
2462 APP_LOGE("fail to get VerifyManager due to write InterfaceToken fail");
2463 return nullptr;
2464 }
2465 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_VERIFY_MANAGER, data, reply)) {
2466 return nullptr;
2467 }
2468
2469 sptr<IRemoteObject> object = reply.ReadRemoteObject();
2470 if (object == nullptr) {
2471 APP_LOGE("read failed");
2472 return nullptr;
2473 }
2474 sptr<IVerifyManager> verifyManager = iface_cast<IVerifyManager>(object);
2475 if (verifyManager == nullptr) {
2476 APP_LOGE("VerifyManager is nullptr");
2477 }
2478
2479 return verifyManager;
2480 }
2481
GetExtendResourceManager()2482 sptr<IExtendResourceManager> BundleMgrProxy::GetExtendResourceManager()
2483 {
2484 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2485 MessageParcel data;
2486 MessageParcel reply;
2487 if (!data.WriteInterfaceToken(GetDescriptor())) {
2488 APP_LOGE("fail to get GetExtendResourceManager due to write InterfaceToken fail");
2489 return nullptr;
2490 }
2491 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_EXTEND_RESOURCE_MANAGER, data, reply)) {
2492 return nullptr;
2493 }
2494
2495 sptr<IRemoteObject> object = reply.ReadRemoteObject();
2496 if (object == nullptr) {
2497 APP_LOGE("read failed");
2498 return nullptr;
2499 }
2500 sptr<IExtendResourceManager> extendResourceManager = iface_cast<IExtendResourceManager>(object);
2501 if (extendResourceManager == nullptr) {
2502 APP_LOGE("extendResourceManager is nullptr");
2503 }
2504 return extendResourceManager;
2505 }
2506
GetAllFormsInfo(std::vector<FormInfo> & formInfos)2507 bool BundleMgrProxy::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
2508 {
2509 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2510 MessageParcel data;
2511 if (!data.WriteInterfaceToken(GetDescriptor())) {
2512 APP_LOGE("fail to GetAllFormsInfo due to write MessageParcel fail");
2513 return false;
2514 }
2515
2516 if (!GetParcelableInfos<FormInfo>(BundleMgrInterfaceCode::GET_ALL_FORMS_INFO, data, formInfos)) {
2517 APP_LOGE("fail to GetAllFormsInfo from server");
2518 return false;
2519 }
2520 return true;
2521 }
2522
GetFormsInfoByApp(const std::string & bundleName,std::vector<FormInfo> & formInfos)2523 bool BundleMgrProxy::GetFormsInfoByApp(const std::string &bundleName, std::vector<FormInfo> &formInfos)
2524 {
2525 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2526 if (bundleName.empty()) {
2527 APP_LOGE("fail to GetFormsInfoByApp due to params empty");
2528 return false;
2529 }
2530
2531 MessageParcel data;
2532 if (!data.WriteInterfaceToken(GetDescriptor())) {
2533 APP_LOGE("fail to GetFormsInfoByApp due to write MessageParcel fail");
2534 return false;
2535 }
2536 if (!data.WriteString(bundleName)) {
2537 APP_LOGE("fail to GetFormsInfoByApp due to write bundleName fail");
2538 return false;
2539 }
2540 if (!GetParcelableInfos<FormInfo>(BundleMgrInterfaceCode::GET_FORMS_INFO_BY_APP, data, formInfos)) {
2541 APP_LOGE("fail to GetFormsInfoByApp from server");
2542 return false;
2543 }
2544 return true;
2545 }
2546
GetFormsInfoByModule(const std::string & bundleName,const std::string & moduleName,std::vector<FormInfo> & formInfos)2547 bool BundleMgrProxy::GetFormsInfoByModule(
2548 const std::string &bundleName, const std::string &moduleName, std::vector<FormInfo> &formInfos)
2549 {
2550 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2551 if (bundleName.empty() || moduleName.empty()) {
2552 APP_LOGE("fail to GetFormsByModule due to params empty");
2553 return false;
2554 }
2555
2556 MessageParcel data;
2557 if (!data.WriteInterfaceToken(GetDescriptor())) {
2558 APP_LOGE("fail to GetFormsInfoByModule due to write MessageParcel fail");
2559 return false;
2560 }
2561
2562 if (!data.WriteString(bundleName)) {
2563 APP_LOGE("fail to GetFormsInfoByModule due to write bundleName fail");
2564 return false;
2565 }
2566
2567 if (!data.WriteString(moduleName)) {
2568 APP_LOGE("fail to GetFormsInfoByModule due to write moduleName fail");
2569 return false;
2570 }
2571
2572 if (!GetParcelableInfos<FormInfo>(BundleMgrInterfaceCode::GET_FORMS_INFO_BY_MODULE, data, formInfos)) {
2573 APP_LOGE("fail to GetFormsInfoByModule from server");
2574 return false;
2575 }
2576 return true;
2577 }
2578
GetShortcutInfos(const std::string & bundleName,std::vector<ShortcutInfo> & shortcutInfos)2579 bool BundleMgrProxy::GetShortcutInfos(const std::string &bundleName, std::vector<ShortcutInfo> &shortcutInfos)
2580 {
2581 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2582 if (bundleName.empty()) {
2583 APP_LOGE("fail to GetShortcutInfos due to params empty");
2584 return false;
2585 }
2586
2587 MessageParcel data;
2588 if (!data.WriteInterfaceToken(GetDescriptor())) {
2589 APP_LOGE("fail to GetShortcutInfos due to write MessageParcel fail");
2590 return false;
2591 }
2592
2593 if (!data.WriteString(bundleName)) {
2594 APP_LOGE("fail to GetShortcutInfos due to write bundleName fail");
2595 return false;
2596 }
2597
2598 if (!GetParcelableInfos<ShortcutInfo>(BundleMgrInterfaceCode::GET_SHORTCUT_INFO, data, shortcutInfos)) {
2599 APP_LOGE("fail to GetShortcutInfos from server");
2600 return false;
2601 }
2602 return true;
2603 }
2604
GetShortcutInfoV9(const std::string & bundleName,std::vector<ShortcutInfo> & shortcutInfos,int32_t userId)2605 ErrCode BundleMgrProxy::GetShortcutInfoV9(const std::string &bundleName,
2606 std::vector<ShortcutInfo> &shortcutInfos, int32_t userId)
2607 {
2608 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2609 if (bundleName.empty()) {
2610 APP_LOGE("fail to GetShortcutInfos due to params empty");
2611 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
2612 }
2613
2614 MessageParcel data;
2615 if (!data.WriteInterfaceToken(GetDescriptor())) {
2616 APP_LOGE("fail to GetShortcutInfos due to write MessageParcel fail");
2617 return ERR_APPEXECFWK_PARCEL_ERROR;
2618 }
2619
2620 if (!data.WriteString(bundleName)) {
2621 APP_LOGE("fail to GetShortcutInfos due to write bundleName fail");
2622 return ERR_APPEXECFWK_PARCEL_ERROR;
2623 }
2624 if (!data.WriteInt32(userId)) {
2625 APP_LOGE("fail to GetShortcutInfos due to write userId fail");
2626 return ERR_APPEXECFWK_PARCEL_ERROR;
2627 }
2628 return GetParcelableInfosWithErrCode<ShortcutInfo>(
2629 BundleMgrInterfaceCode::GET_SHORTCUT_INFO_V9, data, shortcutInfos);
2630 }
2631
GetAllCommonEventInfo(const std::string & eventKey,std::vector<CommonEventInfo> & commonEventInfos)2632 bool BundleMgrProxy::GetAllCommonEventInfo(const std::string &eventKey, std::vector<CommonEventInfo> &commonEventInfos)
2633 {
2634 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2635 if (eventKey.empty()) {
2636 APP_LOGE("fail to GetAllCommonEventInfo due to eventKey empty");
2637 return false;
2638 }
2639
2640 MessageParcel data;
2641 if (!data.WriteInterfaceToken(GetDescriptor())) {
2642 APP_LOGE("fail to GetAllCommonEventInfo due to write MessageParcel fail");
2643 return false;
2644 }
2645
2646 if (!data.WriteString(eventKey)) {
2647 APP_LOGE("fail to GetAllCommonEventInfo due to write eventKey fail");
2648 return false;
2649 }
2650
2651 if (!GetParcelableInfos<CommonEventInfo>(
2652 BundleMgrInterfaceCode::GET_ALL_COMMON_EVENT_INFO, data, commonEventInfos)) {
2653 APP_LOGE("fail to GetAllCommonEventInfo from server");
2654 return false;
2655 }
2656 return true;
2657 }
2658
GetDistributedBundleInfo(const std::string & networkId,const std::string & bundleName,DistributedBundleInfo & distributedBundleInfo)2659 bool BundleMgrProxy::GetDistributedBundleInfo(const std::string &networkId, const std::string &bundleName,
2660 DistributedBundleInfo &distributedBundleInfo)
2661 {
2662 APP_LOGD("begin to GetDistributedBundleInfo of %{public}s", bundleName.c_str());
2663 if (networkId.empty() || bundleName.empty()) {
2664 APP_LOGE("fail to GetDistributedBundleInfo due to params empty");
2665 return false;
2666 }
2667 MessageParcel data;
2668 if (!data.WriteInterfaceToken(GetDescriptor())) {
2669 APP_LOGE("fail to GetDistributedBundleInfo due to write MessageParcel fail");
2670 return false;
2671 }
2672
2673 if (!data.WriteString(networkId)) {
2674 APP_LOGE("fail to GetDistributedBundleInfo due to write networkId fail");
2675 return false;
2676 }
2677
2678 if (!data.WriteString(bundleName)) {
2679 APP_LOGE("fail to GetDistributedBundleInfo due to write bundleName fail");
2680 return false;
2681 }
2682 MessageParcel reply;
2683 if (!GetParcelableInfo<DistributedBundleInfo>(
2684 BundleMgrInterfaceCode::GET_DISTRIBUTE_BUNDLE_INFO, data, distributedBundleInfo)) {
2685 APP_LOGE("fail to GetDistributedBundleInfo from server");
2686 return false;
2687 }
2688 return true;
2689 }
2690
GetAppPrivilegeLevel(const std::string & bundleName,int32_t userId)2691 std::string BundleMgrProxy::GetAppPrivilegeLevel(const std::string &bundleName, int32_t userId)
2692 {
2693 APP_LOGD("begin to GetAppPrivilegeLevel of %{public}s", bundleName.c_str());
2694 if (bundleName.empty()) {
2695 APP_LOGE("fail to GetAppPrivilegeLevel due to params empty");
2696 return Constants::EMPTY_STRING;
2697 }
2698 MessageParcel data;
2699 if (!data.WriteInterfaceToken(GetDescriptor())) {
2700 APP_LOGE("fail to GetAppPrivilegeLevel due to write InterfaceToken fail");
2701 return Constants::EMPTY_STRING;
2702 }
2703 if (!data.WriteString(bundleName)) {
2704 APP_LOGE("fail to GetAppPrivilegeLevel due to write bundleName fail");
2705 return Constants::EMPTY_STRING;
2706 }
2707 if (!data.WriteInt32(userId)) {
2708 APP_LOGE("fail to GetAppPrivilegeLevel due to write userId fail");
2709 return Constants::EMPTY_STRING;
2710 }
2711
2712 MessageParcel reply;
2713 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_APPLICATION_PRIVILEGE_LEVEL, data, reply)) {
2714 APP_LOGE("fail to GetAppPrivilegeLevel from server");
2715 return Constants::EMPTY_STRING;
2716 }
2717 return reply.ReadString();
2718 }
2719
QueryExtensionAbilityInfos(const Want & want,const int32_t & flag,const int32_t & userId,std::vector<ExtensionAbilityInfo> & extensionInfos)2720 bool BundleMgrProxy::QueryExtensionAbilityInfos(const Want &want, const int32_t &flag, const int32_t &userId,
2721 std::vector<ExtensionAbilityInfo> &extensionInfos)
2722 {
2723 MessageParcel data;
2724 if (!data.WriteInterfaceToken(GetDescriptor())) {
2725 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write InterfaceToken fail");
2726 return false;
2727 }
2728 if (!data.WriteParcelable(&want)) {
2729 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write want fail");
2730 return false;
2731 }
2732 if (!data.WriteInt32(flag)) {
2733 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write flag fail");
2734 return false;
2735 }
2736 if (!data.WriteInt32(userId)) {
2737 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write userId fail");
2738 return false;
2739 }
2740
2741 if (!GetParcelableInfos(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_WITHOUT_TYPE, data, extensionInfos)) {
2742 LOG_E(BMS_TAG_QUERY, "fail to obtain extensionInfos");
2743 return false;
2744 }
2745 return true;
2746 }
2747
QueryExtensionAbilityInfosV9(const Want & want,int32_t flags,int32_t userId,std::vector<ExtensionAbilityInfo> & extensionInfos)2748 ErrCode BundleMgrProxy::QueryExtensionAbilityInfosV9(const Want &want, int32_t flags, int32_t userId,
2749 std::vector<ExtensionAbilityInfo> &extensionInfos)
2750 {
2751 MessageParcel data;
2752 if (!data.WriteInterfaceToken(GetDescriptor())) {
2753 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfosV9 write InterfaceToken fail");
2754 return ERR_APPEXECFWK_PARCEL_ERROR;
2755 }
2756 if (!data.WriteParcelable(&want)) {
2757 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfosV9 write want fail");
2758 return ERR_APPEXECFWK_PARCEL_ERROR;
2759 }
2760 if (!data.WriteInt32(flags)) {
2761 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfosV9 write flag fail");
2762 return ERR_APPEXECFWK_PARCEL_ERROR;
2763 }
2764 if (!data.WriteInt32(userId)) {
2765 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfosV9 write userId fail");
2766 return ERR_APPEXECFWK_PARCEL_ERROR;
2767 }
2768 return GetParcelableInfosWithErrCode(
2769 BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_WITHOUT_TYPE_V9, data, extensionInfos);
2770 }
2771
QueryExtensionAbilityInfos(const Want & want,const ExtensionAbilityType & extensionType,const int32_t & flag,const int32_t & userId,std::vector<ExtensionAbilityInfo> & extensionInfos)2772 bool BundleMgrProxy::QueryExtensionAbilityInfos(const Want &want, const ExtensionAbilityType &extensionType,
2773 const int32_t &flag, const int32_t &userId, std::vector<ExtensionAbilityInfo> &extensionInfos)
2774 {
2775 MessageParcel data;
2776 if (!data.WriteInterfaceToken(GetDescriptor())) {
2777 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write InterfaceToken fail");
2778 return false;
2779 }
2780 if (!data.WriteParcelable(&want)) {
2781 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write want fail");
2782 return false;
2783 }
2784 if (!data.WriteInt32(static_cast<int32_t>(extensionType))) {
2785 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write type fail");
2786 return false;
2787 }
2788 if (!data.WriteInt32(flag)) {
2789 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write flag fail");
2790 return false;
2791 }
2792 if (!data.WriteInt32(userId)) {
2793 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write userId fail");
2794 return false;
2795 }
2796
2797 if (!GetParcelableInfos(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO, data, extensionInfos)) {
2798 LOG_E(BMS_TAG_QUERY, "fail to obtain extensionInfos");
2799 return false;
2800 }
2801 return true;
2802 }
2803
QueryExtensionAbilityInfosV9(const Want & want,const ExtensionAbilityType & extensionType,int32_t flags,int32_t userId,std::vector<ExtensionAbilityInfo> & extensionInfos)2804 ErrCode BundleMgrProxy::QueryExtensionAbilityInfosV9(const Want &want, const ExtensionAbilityType &extensionType,
2805 int32_t flags, int32_t userId, std::vector<ExtensionAbilityInfo> &extensionInfos)
2806 {
2807 MessageParcel data;
2808 if (!data.WriteInterfaceToken(GetDescriptor())) {
2809 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfosV9 write InterfaceToken fail");
2810 return ERR_APPEXECFWK_PARCEL_ERROR;
2811 }
2812 if (!data.WriteParcelable(&want)) {
2813 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfosV9 write want fail");
2814 return ERR_APPEXECFWK_PARCEL_ERROR;
2815 }
2816 if (!data.WriteInt32(static_cast<int32_t>(extensionType))) {
2817 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfosV9 write type fail");
2818 return ERR_APPEXECFWK_PARCEL_ERROR;
2819 }
2820 if (!data.WriteInt32(flags)) {
2821 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfosV9 write flag fail");
2822 return ERR_APPEXECFWK_PARCEL_ERROR;
2823 }
2824 if (!data.WriteInt32(userId)) {
2825 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfosV9 write userId fail");
2826 return ERR_APPEXECFWK_PARCEL_ERROR;
2827 }
2828 return GetParcelableInfosWithErrCode(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_V9, data, extensionInfos);
2829 }
2830
QueryExtensionAbilityInfos(const ExtensionAbilityType & extensionType,const int32_t & userId,std::vector<ExtensionAbilityInfo> & extensionInfos)2831 bool BundleMgrProxy::QueryExtensionAbilityInfos(const ExtensionAbilityType &extensionType, const int32_t &userId,
2832 std::vector<ExtensionAbilityInfo> &extensionInfos)
2833 {
2834 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2835 MessageParcel data;
2836 if (!data.WriteInterfaceToken(GetDescriptor())) {
2837 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write InterfaceToken fail");
2838 return false;
2839 }
2840 if (!data.WriteInt32(static_cast<int32_t>(extensionType))) {
2841 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write type fail");
2842 return false;
2843 }
2844 if (!data.WriteInt32(userId)) {
2845 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfos write userId fail");
2846 return false;
2847 }
2848
2849 if (!GetParcelableInfos(BundleMgrInterfaceCode::QUERY_EXTENSION_INFO_BY_TYPE, data, extensionInfos)) {
2850 LOG_E(BMS_TAG_QUERY, "fail to obtain extensionInfos");
2851 return false;
2852 }
2853 return true;
2854 }
2855
VerifyCallingPermission(const std::string & permission)2856 bool BundleMgrProxy::VerifyCallingPermission(const std::string &permission)
2857 {
2858 APP_LOGD("VerifyCallingPermission begin");
2859 MessageParcel data;
2860 if (!data.WriteInterfaceToken(GetDescriptor())) {
2861 APP_LOGE("fail to VerifyCallingPermission due to write InterfaceToken fail");
2862 return false;
2863 }
2864
2865 if (!data.WriteString(permission)) {
2866 APP_LOGE("fail to VerifyCallingPermission due to write bundleName fail");
2867 return false;
2868 }
2869
2870 MessageParcel reply;
2871 if (!SendTransactCmd(BundleMgrInterfaceCode::VERIFY_CALLING_PERMISSION, data, reply)) {
2872 APP_LOGE("fail to sendRequest");
2873 return false;
2874 }
2875 return reply.ReadBool();
2876 }
2877
QueryExtensionAbilityInfoByUri(const std::string & uri,int32_t userId,ExtensionAbilityInfo & extensionAbilityInfo)2878 bool BundleMgrProxy::QueryExtensionAbilityInfoByUri(const std::string &uri, int32_t userId,
2879 ExtensionAbilityInfo &extensionAbilityInfo)
2880 {
2881 LOG_D(BMS_TAG_QUERY, "begin to QueryExtensionAbilityInfoByUri");
2882 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2883 if (uri.empty()) {
2884 LOG_E(BMS_TAG_QUERY, "uri is empty");
2885 return false;
2886 }
2887 MessageParcel data;
2888 if (!data.WriteInterfaceToken(GetDescriptor())) {
2889 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfoByUri write MessageParcel fail");
2890 return false;
2891 }
2892 if (!data.WriteString(uri)) {
2893 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfoByUri write uri fail");
2894 return false;
2895 }
2896 if (!data.WriteInt32(userId)) {
2897 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfoByUri write userId fail");
2898 return false;
2899 }
2900
2901 if (!GetParcelableInfo<ExtensionAbilityInfo>(
2902 BundleMgrInterfaceCode::QUERY_EXTENSION_ABILITY_INFO_BY_URI, data, extensionAbilityInfo)) {
2903 LOG_E(BMS_TAG_QUERY, "failed to QueryExtensionAbilityInfoByUri from server");
2904 return false;
2905 }
2906 return true;
2907 }
2908
ImplicitQueryInfoByPriority(const Want & want,int32_t flags,int32_t userId,AbilityInfo & abilityInfo,ExtensionAbilityInfo & extensionInfo)2909 bool BundleMgrProxy::ImplicitQueryInfoByPriority(const Want &want, int32_t flags, int32_t userId,
2910 AbilityInfo &abilityInfo, ExtensionAbilityInfo &extensionInfo)
2911 {
2912 LOG_D(BMS_TAG_QUERY, "begin to ImplicitQueryInfoByPriority");
2913 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2914 MessageParcel data;
2915 if (!data.WriteInterfaceToken(GetDescriptor())) {
2916 LOG_E(BMS_TAG_QUERY, "ImplicitQueryInfoByPriority write MessageParcel fail");
2917 return false;
2918 }
2919 if (!data.WriteParcelable(&want)) {
2920 LOG_E(BMS_TAG_QUERY, "ImplicitQueryInfoByPriority write want fail");
2921 return false;
2922 }
2923 if (!data.WriteInt32(flags)) {
2924 LOG_E(BMS_TAG_QUERY, "ImplicitQueryInfoByPriority write flags fail");
2925 return false;
2926 }
2927 if (!data.WriteInt32(userId)) {
2928 LOG_E(BMS_TAG_QUERY, "ImplicitQueryInfoByPriority write userId error");
2929 return false;
2930 }
2931
2932 MessageParcel reply;
2933 if (!SendTransactCmd(BundleMgrInterfaceCode::IMPLICIT_QUERY_INFO_BY_PRIORITY, data, reply)) {
2934 return false;
2935 }
2936
2937 if (!reply.ReadBool()) {
2938 LOG_E(BMS_TAG_QUERY, "reply result false");
2939 return false;
2940 }
2941
2942 std::unique_ptr<AbilityInfo> abilityInfoPtr(reply.ReadParcelable<AbilityInfo>());
2943 if (abilityInfoPtr == nullptr) {
2944 LOG_E(BMS_TAG_QUERY, "read AbilityInfo failed");
2945 return false;
2946 }
2947 abilityInfo = *abilityInfoPtr;
2948
2949 std::unique_ptr<ExtensionAbilityInfo> extensionInfoPtr(reply.ReadParcelable<ExtensionAbilityInfo>());
2950 if (extensionInfoPtr == nullptr) {
2951 LOG_E(BMS_TAG_QUERY, "read ExtensionAbilityInfo failed");
2952 return false;
2953 }
2954 extensionInfo = *extensionInfoPtr;
2955 return true;
2956 }
2957
ImplicitQueryInfos(const Want & want,int32_t flags,int32_t userId,bool withDefault,std::vector<AbilityInfo> & abilityInfos,std::vector<ExtensionAbilityInfo> & extensionInfos,bool & findDefaultApp)2958 bool BundleMgrProxy::ImplicitQueryInfos(const Want &want, int32_t flags, int32_t userId, bool withDefault,
2959 std::vector<AbilityInfo> &abilityInfos, std::vector<ExtensionAbilityInfo> &extensionInfos, bool &findDefaultApp)
2960 {
2961 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
2962 MessageParcel data;
2963 if (!data.WriteInterfaceToken(GetDescriptor())) {
2964 LOG_E(BMS_TAG_QUERY, "WriteInterfaceToken failed");
2965 return false;
2966 }
2967 if (!data.WriteParcelable(&want)) {
2968 LOG_E(BMS_TAG_QUERY, "WriteParcelable want failed");
2969 return false;
2970 }
2971 if (!data.WriteInt32(flags)) {
2972 LOG_E(BMS_TAG_QUERY, "WriteInt32 flags failed");
2973 return false;
2974 }
2975 if (!data.WriteInt32(userId)) {
2976 LOG_E(BMS_TAG_QUERY, "WriteInt32 userId failed");
2977 return false;
2978 }
2979 if (!data.WriteBool(withDefault)) {
2980 LOG_E(BMS_TAG_QUERY, "WriteBool withDefault failed");
2981 return false;
2982 }
2983
2984 MessageParcel reply;
2985 if (!SendTransactCmd(BundleMgrInterfaceCode::IMPLICIT_QUERY_INFOS, data, reply)) {
2986 return false;
2987 }
2988 if (!reply.ReadBool()) {
2989 LOG_E(BMS_TAG_QUERY, "reply result false");
2990 return false;
2991 }
2992 int32_t abilityInfoSize = reply.ReadInt32();
2993 for (int32_t i = 0; i < abilityInfoSize; i++) {
2994 std::unique_ptr<AbilityInfo> abilityInfoPtr(reply.ReadParcelable<AbilityInfo>());
2995 if (abilityInfoPtr == nullptr) {
2996 LOG_E(BMS_TAG_QUERY, "Read Parcelable abilityInfos failed");
2997 return false;
2998 }
2999 abilityInfos.emplace_back(*abilityInfoPtr);
3000 }
3001 int32_t extensionInfoSize = reply.ReadInt32();
3002 for (int32_t i = 0; i < extensionInfoSize; i++) {
3003 std::unique_ptr<ExtensionAbilityInfo> extensionInfoPtr(reply.ReadParcelable<ExtensionAbilityInfo>());
3004 if (extensionInfoPtr == nullptr) {
3005 LOG_E(BMS_TAG_QUERY, "Read Parcelable extensionInfos failed");
3006 return false;
3007 }
3008 extensionInfos.emplace_back(*extensionInfoPtr);
3009 }
3010 findDefaultApp = reply.ReadBool();
3011
3012 return true;
3013 }
3014
GetSandboxBundleInfo(const std::string & bundleName,int32_t appIndex,int32_t userId,BundleInfo & info)3015 ErrCode BundleMgrProxy::GetSandboxBundleInfo(const std::string &bundleName, int32_t appIndex, int32_t userId,
3016 BundleInfo &info)
3017 {
3018 APP_LOGD("begin to GetSandboxBundleInfo");
3019 if (bundleName.empty() || appIndex <= Constants::INITIAL_SANDBOX_APP_INDEX) {
3020 APP_LOGE("GetSandboxBundleInfo params are invalid");
3021 return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
3022 }
3023
3024 MessageParcel data;
3025 if (!data.WriteInterfaceToken(GetDescriptor())) {
3026 APP_LOGE("failed to GetSandboxBundleInfo due to write MessageParcel fail");
3027 return ERR_APPEXECFWK_SANDBOX_INSTALL_WRITE_PARCEL_ERROR;
3028 }
3029 if (!data.WriteString(bundleName)) {
3030 APP_LOGE("failed to GetSandboxBundleInfo due to write bundleName fail");
3031 return ERR_APPEXECFWK_SANDBOX_INSTALL_WRITE_PARCEL_ERROR;
3032 }
3033 if (!data.WriteInt32(appIndex)) {
3034 APP_LOGE("failed to GetSandboxBundleInfo due to write appIndex fail");
3035 return ERR_APPEXECFWK_SANDBOX_INSTALL_WRITE_PARCEL_ERROR;
3036 }
3037 if (!data.WriteInt32(userId)) {
3038 APP_LOGE("failed to GetSandboxBundleInfo due to write userId fail");
3039 return ERR_APPEXECFWK_SANDBOX_INSTALL_WRITE_PARCEL_ERROR;
3040 }
3041
3042 return GetParcelableInfoWithErrCode<BundleInfo>(BundleMgrInterfaceCode::GET_SANDBOX_APP_BUNDLE_INFO, data, info);
3043 }
3044
GetAllDependentModuleNames(const std::string & bundleName,const std::string & moduleName,std::vector<std::string> & dependentModuleNames)3045 bool BundleMgrProxy::GetAllDependentModuleNames(const std::string &bundleName, const std::string &moduleName,
3046 std::vector<std::string> &dependentModuleNames)
3047 {
3048 APP_LOGD("begin to GetAllDependentModuleNames");
3049 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3050 if (bundleName.empty() || moduleName.empty()) {
3051 APP_LOGE("bundleName or moduleName is empty");
3052 return false;
3053 }
3054 MessageParcel data;
3055 if (!data.WriteInterfaceToken(GetDescriptor())) {
3056 APP_LOGE("failed to GetAllDependentModuleNames due to write MessageParcel fail");
3057 return false;
3058 }
3059 if (!data.WriteString(bundleName)) {
3060 APP_LOGE("failed to GetAllDependentModuleNames due to write bundleName fail");
3061 return false;
3062 }
3063 if (!data.WriteString(moduleName)) {
3064 APP_LOGE("failed to GetAllDependentModuleNames due to write moduleName fail");
3065 return false;
3066 }
3067
3068 MessageParcel reply;
3069 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ALL_DEPENDENT_MODULE_NAMES, data, reply)) {
3070 APP_LOGE("fail to GetAllDependentModuleNames from server");
3071 return false;
3072 }
3073 if (!reply.ReadBool()) {
3074 APP_LOGE("reply result false");
3075 return false;
3076 }
3077 if (!reply.ReadStringVector(&dependentModuleNames)) {
3078 APP_LOGE("fail to GetAllDependentModuleNames from reply");
3079 return false;
3080 }
3081 return true;
3082 }
3083
ObtainCallingBundleName(std::string & bundleName)3084 bool BundleMgrProxy::ObtainCallingBundleName(std::string &bundleName)
3085 {
3086 APP_LOGD("begin to ObtainCallingBundleName");
3087 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3088
3089 MessageParcel data;
3090 if (!data.WriteInterfaceToken(GetDescriptor())) {
3091 APP_LOGE("failed to ObtainCallingBundleName due to write MessageParcel fail");
3092 return false;
3093 }
3094
3095 MessageParcel reply;
3096 if (!SendTransactCmd(BundleMgrInterfaceCode::QUERY_CALLING_BUNDLE_NAME, data, reply)) {
3097 APP_LOGE("fail to ObtainCallingBundleName from server");
3098 return false;
3099 }
3100 if (!reply.ReadBool()) {
3101 APP_LOGE("reply result false");
3102 return false;
3103 }
3104 bundleName = reply.ReadString();
3105 if (bundleName.empty()) {
3106 APP_LOGE("bundleName is empty");
3107 return false;
3108 }
3109 return true;
3110 }
3111
GetBundleStats(const std::string & bundleName,int32_t userId,std::vector<int64_t> & bundleStats,int32_t appIndex,uint32_t statFlag)3112 bool BundleMgrProxy::GetBundleStats(const std::string &bundleName, int32_t userId,
3113 std::vector<int64_t> &bundleStats, int32_t appIndex, uint32_t statFlag)
3114 {
3115 APP_LOGD("begin to GetBundleStats");
3116 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3117 MessageParcel data;
3118 if (!data.WriteInterfaceToken(GetDescriptor())) {
3119 APP_LOGE("failed to GetBundleStats due to write MessageParcel fail");
3120 return false;
3121 }
3122 if (!data.WriteString(bundleName)) {
3123 APP_LOGE("fail to GetBundleStats due to write bundleName fail");
3124 return false;
3125 }
3126 if (!data.WriteInt32(userId)) {
3127 APP_LOGE("fail to GetBundleStats due to write userId fail");
3128 return false;
3129 }
3130 if (!data.WriteInt32(appIndex)) {
3131 APP_LOGE("fail to GetBundleStats due to write appIndex fail");
3132 return false;
3133 }
3134 if (!data.WriteUint32(statFlag)) {
3135 APP_LOGE("fail to GetBundleStats due to write statFlag fail");
3136 return false;
3137 }
3138
3139 MessageParcel reply;
3140 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_BUNDLE_STATS, data, reply)) {
3141 APP_LOGE("fail to GetBundleStats from server");
3142 return false;
3143 }
3144 if (!reply.ReadBool()) {
3145 APP_LOGE("reply result false");
3146 return false;
3147 }
3148 if (!reply.ReadInt64Vector(&bundleStats)) {
3149 APP_LOGE("fail to GetBundleStats from reply");
3150 return false;
3151 }
3152 return true;
3153 }
3154
GetAllBundleStats(int32_t userId,std::vector<int64_t> & bundleStats)3155 bool BundleMgrProxy::GetAllBundleStats(int32_t userId, std::vector<int64_t> &bundleStats)
3156 {
3157 APP_LOGI("GetAllBundleStats start");
3158 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3159 MessageParcel data;
3160 if (!data.WriteInterfaceToken(GetDescriptor())) {
3161 APP_LOGE("failed to GetAllBundleStats due to write MessageParcel fail");
3162 return false;
3163 }
3164 if (!data.WriteInt32(userId)) {
3165 APP_LOGE("fail to GetAllBundleStats due to write userId fail");
3166 return false;
3167 }
3168
3169 MessageParcel reply;
3170 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ALL_BUNDLE_STATS, data, reply)) {
3171 APP_LOGE("fail to GetAllBundleStats from server");
3172 return false;
3173 }
3174 if (!reply.ReadBool()) {
3175 APP_LOGE("reply result false");
3176 return false;
3177 }
3178 if (!reply.ReadInt64Vector(&bundleStats)) {
3179 APP_LOGE("fail to GetAllBundleStats from reply");
3180 return false;
3181 }
3182 APP_LOGI("GetAllBundleStats end");
3183 return true;
3184 }
3185
CheckAbilityEnableInstall(const Want & want,int32_t missionId,int32_t userId,const sptr<IRemoteObject> & callback)3186 bool BundleMgrProxy::CheckAbilityEnableInstall(
3187 const Want &want, int32_t missionId, int32_t userId, const sptr<IRemoteObject> &callback)
3188 {
3189 APP_LOGD("begin to CheckAbilityEnableInstall");
3190 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3191
3192 MessageParcel data;
3193 if (!data.WriteInterfaceToken(GetDescriptor())) {
3194 APP_LOGE("failed to CheckAbilityEnableInstall due to write MessageParcel fail");
3195 return false;
3196 }
3197
3198 if (!data.WriteParcelable(&want)) {
3199 APP_LOGE("fail to CheckAbilityEnableInstall due to write want fail");
3200 return false;
3201 }
3202
3203 if (!data.WriteInt32(missionId)) {
3204 APP_LOGE("fail to CheckAbilityEnableInstall due to write missionId fail");
3205 return false;
3206 }
3207
3208 if (!data.WriteInt32(userId)) {
3209 APP_LOGE("fail to CheckAbilityEnableInstall due to write userId fail");
3210 return false;
3211 }
3212
3213 if (!data.WriteRemoteObject(callback)) {
3214 APP_LOGE("fail to callback, for write parcel");
3215 return false;
3216 }
3217
3218 MessageParcel reply;
3219 if (!SendTransactCmd(BundleMgrInterfaceCode::CHECK_ABILITY_ENABLE_INSTALL, data, reply)) {
3220 return false;
3221 }
3222 return reply.ReadBool();
3223 }
3224
GetStringById(const std::string & bundleName,const std::string & moduleName,uint32_t resId,int32_t userId,const std::string & localeInfo)3225 std::string BundleMgrProxy::GetStringById(const std::string &bundleName, const std::string &moduleName,
3226 uint32_t resId, int32_t userId, const std::string &localeInfo)
3227 {
3228 APP_LOGD("begin to GetStringById");
3229 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3230 if (bundleName.empty() || moduleName.empty()) {
3231 APP_LOGE("fail to GetStringById due to params empty");
3232 return Constants::EMPTY_STRING;
3233 }
3234 APP_LOGD("GetStringById bundleName: %{public}s, moduleName: %{public}s, resId:%{public}d",
3235 bundleName.c_str(), moduleName.c_str(), resId);
3236 MessageParcel data;
3237 if (!data.WriteInterfaceToken(GetDescriptor())) {
3238 APP_LOGE("fail to GetStringById due to write InterfaceToken fail");
3239 return Constants::EMPTY_STRING;
3240 }
3241 if (!data.WriteString(bundleName)) {
3242 APP_LOGE("fail to GetStringById due to write bundleName fail");
3243 return Constants::EMPTY_STRING;
3244 }
3245 if (!data.WriteString(moduleName)) {
3246 APP_LOGE("fail to GetStringById due to write moduleName fail");
3247 return Constants::EMPTY_STRING;
3248 }
3249 if (!data.WriteUint32(resId)) {
3250 APP_LOGE("fail to GetStringById due to write resId fail");
3251 return Constants::EMPTY_STRING;
3252 }
3253 if (!data.WriteInt32(userId)) {
3254 APP_LOGE("fail to GetStringById due to write userId fail");
3255 return Constants::EMPTY_STRING;
3256 }
3257 if (!data.WriteString(localeInfo)) {
3258 APP_LOGE("fail to GetStringById due to write localeInfo fail");
3259 return Constants::EMPTY_STRING;
3260 }
3261 MessageParcel reply;
3262 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_STRING_BY_ID, data, reply)) {
3263 APP_LOGE("fail to GetStringById from server");
3264 return Constants::EMPTY_STRING;
3265 }
3266 return reply.ReadString();
3267 }
3268
GetIconById(const std::string & bundleName,const std::string & moduleName,uint32_t resId,uint32_t density,int32_t userId)3269 std::string BundleMgrProxy::GetIconById(
3270 const std::string &bundleName, const std::string &moduleName, uint32_t resId, uint32_t density, int32_t userId)
3271 {
3272 APP_LOGD("begin to GetIconById");
3273 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3274 if (bundleName.empty() || moduleName.empty()) {
3275 APP_LOGE("fail to GetIconById due to params empty");
3276 return Constants::EMPTY_STRING;
3277 }
3278 APP_LOGD("GetIconById bundleName: %{public}s, moduleName: %{public}s, resId:%{public}d",
3279 bundleName.c_str(), moduleName.c_str(), resId);
3280 MessageParcel data;
3281 if (!data.WriteInterfaceToken(GetDescriptor())) {
3282 APP_LOGE("fail to GetIconById due to write InterfaceToken fail");
3283 return Constants::EMPTY_STRING;
3284 }
3285 if (!data.WriteString(bundleName)) {
3286 APP_LOGE("fail to GetIconById due to write bundleName fail");
3287 return Constants::EMPTY_STRING;
3288 }
3289
3290 if (!data.WriteString(moduleName)) {
3291 APP_LOGE("fail to GetIconById due to write moduleName fail");
3292 return Constants::EMPTY_STRING;
3293 }
3294 if (!data.WriteUint32(resId)) {
3295 APP_LOGE("fail to GetIconById due to write resId fail");
3296 return Constants::EMPTY_STRING;
3297 }
3298 if (!data.WriteUint32(density)) {
3299 APP_LOGE("fail to GetIconById due to write density fail");
3300 return Constants::EMPTY_STRING;
3301 }
3302 if (!data.WriteInt32(userId)) {
3303 APP_LOGE("fail to GetIconById due to write userId fail");
3304 return Constants::EMPTY_STRING;
3305 }
3306 MessageParcel reply;
3307 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ICON_BY_ID, data, reply)) {
3308 APP_LOGE("fail to GetIconById from server");
3309 return Constants::EMPTY_STRING;
3310 }
3311 return reply.ReadString();
3312 }
3313
3314 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
GetDefaultAppProxy()3315 sptr<IDefaultApp> BundleMgrProxy::GetDefaultAppProxy()
3316 {
3317 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3318 MessageParcel data;
3319 MessageParcel reply;
3320 if (!data.WriteInterfaceToken(GetDescriptor())) {
3321 APP_LOGE("fail to get default app proxy due to write InterfaceToken failed");
3322 return nullptr;
3323 }
3324 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_DEFAULT_APP_PROXY, data, reply)) {
3325 return nullptr;
3326 }
3327
3328 sptr<IRemoteObject> object = reply.ReadRemoteObject();
3329 if (object == nullptr) {
3330 APP_LOGE("reply failed");
3331 return nullptr;
3332 }
3333 sptr<IDefaultApp> defaultAppProxy = iface_cast<IDefaultApp>(object);
3334 if (defaultAppProxy == nullptr) {
3335 APP_LOGE("defaultAppProxy is nullptr");
3336 }
3337
3338 return defaultAppProxy;
3339 }
3340 #endif
3341
3342 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
GetAppControlProxy()3343 sptr<IAppControlMgr> BundleMgrProxy::GetAppControlProxy()
3344 {
3345 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3346 MessageParcel data;
3347 MessageParcel reply;
3348 if (!data.WriteInterfaceToken(GetDescriptor())) {
3349 APP_LOGE("fail to get app control proxy due to write InterfaceToken failed");
3350 return nullptr;
3351 }
3352 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_APP_CONTROL_PROXY, data, reply)) {
3353 return nullptr;
3354 }
3355
3356 sptr<IRemoteObject> object = reply.ReadRemoteObject();
3357 if (object == nullptr) {
3358 APP_LOGE("reply failed");
3359 return nullptr;
3360 }
3361 sptr<IAppControlMgr> appControlProxy = iface_cast<IAppControlMgr>(object);
3362 if (appControlProxy == nullptr) {
3363 APP_LOGE("appControlProxy is nullptr");
3364 }
3365
3366 return appControlProxy;
3367 }
3368 #endif
3369
GetSandboxAbilityInfo(const Want & want,int32_t appIndex,int32_t flags,int32_t userId,AbilityInfo & info)3370 ErrCode BundleMgrProxy::GetSandboxAbilityInfo(const Want &want, int32_t appIndex, int32_t flags, int32_t userId,
3371 AbilityInfo &info)
3372 {
3373 APP_LOGD("begin to GetSandboxAbilityInfo");
3374 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3375 if (appIndex <= Constants::INITIAL_SANDBOX_APP_INDEX || appIndex > Constants::MAX_SANDBOX_APP_INDEX) {
3376 APP_LOGE("GetSandboxAbilityInfo params are invalid");
3377 return ERR_APPEXECFWK_SANDBOX_QUERY_INTERNAL_ERROR;
3378 }
3379 MessageParcel data;
3380 if (!data.WriteInterfaceToken(GetDescriptor())) {
3381 APP_LOGE("WriteInterfaceToken failed");
3382 return ERR_APPEXECFWK_PARCEL_ERROR;
3383 }
3384 if (!data.WriteParcelable(&want)) {
3385 APP_LOGE("WriteParcelable want failed");
3386 return ERR_APPEXECFWK_PARCEL_ERROR;
3387 }
3388 if (!data.WriteInt32(appIndex)) {
3389 APP_LOGE("failed to GetSandboxAbilityInfo due to write appIndex fail");
3390 return ERR_APPEXECFWK_PARCEL_ERROR;
3391 }
3392 if (!data.WriteInt32(flags)) {
3393 APP_LOGE("failed to GetSandboxAbilityInfo due to write flags fail");
3394 return ERR_APPEXECFWK_PARCEL_ERROR;
3395 }
3396 if (!data.WriteInt32(userId)) {
3397 APP_LOGE("failed to GetSandboxAbilityInfo due to write userId fail");
3398 return ERR_APPEXECFWK_PARCEL_ERROR;
3399 }
3400
3401 return GetParcelableInfoWithErrCode<AbilityInfo>(
3402 BundleMgrInterfaceCode::GET_SANDBOX_APP_ABILITY_INFO, data, info);
3403 }
3404
GetSandboxExtAbilityInfos(const Want & want,int32_t appIndex,int32_t flags,int32_t userId,std::vector<ExtensionAbilityInfo> & infos)3405 ErrCode BundleMgrProxy::GetSandboxExtAbilityInfos(const Want &want, int32_t appIndex, int32_t flags, int32_t userId,
3406 std::vector<ExtensionAbilityInfo> &infos)
3407 {
3408 APP_LOGD("begin to GetSandboxExtAbilityInfos");
3409 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3410 if (appIndex <= Constants::INITIAL_SANDBOX_APP_INDEX || appIndex > Constants::MAX_SANDBOX_APP_INDEX) {
3411 APP_LOGE("GetSandboxExtAbilityInfos params are invalid");
3412 return ERR_APPEXECFWK_SANDBOX_QUERY_INTERNAL_ERROR;
3413 }
3414 MessageParcel data;
3415 if (!data.WriteInterfaceToken(GetDescriptor())) {
3416 APP_LOGE("WriteInterfaceToken failed");
3417 return ERR_APPEXECFWK_PARCEL_ERROR;
3418 }
3419 if (!data.WriteParcelable(&want)) {
3420 APP_LOGE("WriteParcelable want failed");
3421 return ERR_APPEXECFWK_PARCEL_ERROR;
3422 }
3423 if (!data.WriteInt32(appIndex)) {
3424 APP_LOGE("failed to GetSandboxExtAbilityInfos due to write appIndex fail");
3425 return ERR_APPEXECFWK_PARCEL_ERROR;
3426 }
3427 if (!data.WriteInt32(flags)) {
3428 APP_LOGE("failed to GetSandboxExtAbilityInfos due to write flags fail");
3429 return ERR_APPEXECFWK_PARCEL_ERROR;
3430 }
3431 if (!data.WriteInt32(userId)) {
3432 APP_LOGE("failed to GetSandboxExtAbilityInfos due to write userId fail");
3433 return ERR_APPEXECFWK_PARCEL_ERROR;
3434 }
3435
3436 return GetParcelableInfosWithErrCode<ExtensionAbilityInfo>(
3437 BundleMgrInterfaceCode::GET_SANDBOX_APP_EXTENSION_INFOS, data, infos);
3438 }
3439
GetSandboxHapModuleInfo(const AbilityInfo & abilityInfo,int32_t appIndex,int32_t userId,HapModuleInfo & info)3440 ErrCode BundleMgrProxy::GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo, int32_t appIndex, int32_t userId,
3441 HapModuleInfo &info)
3442 {
3443 APP_LOGD("begin to GetSandboxHapModuleInfo");
3444 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3445 if (appIndex <= Constants::INITIAL_SANDBOX_APP_INDEX || appIndex > Constants::MAX_SANDBOX_APP_INDEX) {
3446 APP_LOGE("GetSandboxHapModuleInfo params are invalid");
3447 return ERR_APPEXECFWK_SANDBOX_QUERY_INTERNAL_ERROR;
3448 }
3449 MessageParcel data;
3450 if (!data.WriteInterfaceToken(GetDescriptor())) {
3451 APP_LOGE("WriteInterfaceToken failed");
3452 return ERR_APPEXECFWK_PARCEL_ERROR;
3453 }
3454 if (!data.WriteParcelable(&abilityInfo)) {
3455 APP_LOGE("WriteParcelable want failed");
3456 return ERR_APPEXECFWK_PARCEL_ERROR;
3457 }
3458 if (!data.WriteInt32(appIndex)) {
3459 APP_LOGE("failed to GetSandboxHapModuleInfo due to write flags fail");
3460 return ERR_APPEXECFWK_PARCEL_ERROR;
3461 }
3462 if (!data.WriteInt32(userId)) {
3463 APP_LOGE("failed to GetSandboxHapModuleInfo due to write userId fail");
3464 return ERR_APPEXECFWK_PARCEL_ERROR;
3465 }
3466
3467 return GetParcelableInfoWithErrCode<HapModuleInfo>(BundleMgrInterfaceCode::GET_SANDBOX_MODULE_INFO, data, info);
3468 }
3469
GetMediaData(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,std::unique_ptr<uint8_t[]> & mediaDataPtr,size_t & len,int32_t userId)3470 ErrCode BundleMgrProxy::GetMediaData(const std::string &bundleName, const std::string &moduleName,
3471 const std::string &abilityName, std::unique_ptr<uint8_t[]> &mediaDataPtr, size_t &len, int32_t userId)
3472 {
3473 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3474 APP_LOGD("begin to get media data of %{public}s, %{public}s", bundleName.c_str(), abilityName.c_str());
3475 if (bundleName.empty() || abilityName.empty()) {
3476 APP_LOGE("fail to GetMediaData due to params empty");
3477 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
3478 }
3479
3480 MessageParcel data;
3481 if (!data.WriteInterfaceToken(GetDescriptor())) {
3482 APP_LOGE("fail to GetMediaData due to write InterfaceToken fail");
3483 return ERR_APPEXECFWK_PARCEL_ERROR;
3484 }
3485 if (!data.WriteString(bundleName)) {
3486 APP_LOGE("fail to GetMediaData due to write bundleName fail");
3487 return ERR_APPEXECFWK_PARCEL_ERROR;
3488 }
3489 if (!data.WriteString(abilityName)) {
3490 APP_LOGE("fail to GetMediaData due to write abilityName fail");
3491 return ERR_APPEXECFWK_PARCEL_ERROR;
3492 }
3493 if (!data.WriteString(moduleName)) {
3494 APP_LOGE("fail to GetMediaData due to write abilityName fail");
3495 return ERR_APPEXECFWK_PARCEL_ERROR;
3496 }
3497 if (!data.WriteInt32(userId)) {
3498 APP_LOGE("fail to GetMediaData due to write userId fail");
3499 return ERR_APPEXECFWK_PARCEL_ERROR;
3500 }
3501 MessageParcel reply;
3502 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_MEDIA_DATA, data, reply)) {
3503 APP_LOGE("SendTransactCmd result false");
3504 return ERR_APPEXECFWK_PARCEL_ERROR;
3505 }
3506 ErrCode ret = reply.ReadInt32();
3507 if (ret != ERR_OK) {
3508 APP_LOGE("host return error : %{public}d", ret);
3509 return ret;
3510 }
3511 return GetMediaDataFromAshMem(reply, mediaDataPtr, len);
3512 }
3513
GetMediaDataFromAshMem(MessageParcel & reply,std::unique_ptr<uint8_t[]> & mediaDataPtr,size_t & len)3514 ErrCode BundleMgrProxy::GetMediaDataFromAshMem(
3515 MessageParcel &reply, std::unique_ptr<uint8_t[]> &mediaDataPtr, size_t &len)
3516 {
3517 sptr<Ashmem> ashMem = reply.ReadAshmem();
3518 if (ashMem == nullptr) {
3519 APP_LOGE("Ashmem is nullptr");
3520 return ERR_APPEXECFWK_PARCEL_ERROR;
3521 }
3522 if (!ashMem->MapReadOnlyAshmem()) {
3523 APP_LOGE("MapReadOnlyAshmem failed");
3524 ClearAshmem(ashMem);
3525 return ERR_APPEXECFWK_PARCEL_ERROR;
3526 }
3527 int32_t ashMemSize = ashMem->GetAshmemSize();
3528 int32_t offset = 0;
3529 const uint8_t* ashDataPtr = reinterpret_cast<const uint8_t*>(ashMem->ReadFromAshmem(ashMemSize, offset));
3530 if (ashDataPtr == nullptr) {
3531 APP_LOGE("ashDataPtr is nullptr");
3532 ClearAshmem(ashMem);
3533 return ERR_APPEXECFWK_PARCEL_ERROR;
3534 }
3535 len = static_cast<size_t>(ashMemSize);
3536 mediaDataPtr = std::make_unique<uint8_t[]>(len);
3537 if (memcpy_s(mediaDataPtr.get(), len, ashDataPtr, len) != 0) {
3538 mediaDataPtr.reset();
3539 len = 0;
3540 ClearAshmem(ashMem);
3541 return ERR_APPEXECFWK_PARCEL_ERROR;
3542 }
3543 ClearAshmem(ashMem);
3544 return ERR_OK;
3545 }
3546
GetQuickFixManagerProxy()3547 sptr<IQuickFixManager> BundleMgrProxy::GetQuickFixManagerProxy()
3548 {
3549 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3550 MessageParcel data;
3551 if (!data.WriteInterfaceToken(GetDescriptor())) {
3552 APP_LOGE("fail to get quick fix manager proxy due to write InterfaceToken failed");
3553 return nullptr;
3554 }
3555 MessageParcel reply;
3556 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_QUICK_FIX_MANAGER_PROXY, data, reply)) {
3557 return nullptr;
3558 }
3559
3560 sptr<IRemoteObject> object = reply.ReadRemoteObject();
3561 if (object == nullptr) {
3562 APP_LOGE("reply failed");
3563 return nullptr;
3564 }
3565 sptr<IQuickFixManager> quickFixManagerProxy = iface_cast<IQuickFixManager>(object);
3566 if (quickFixManagerProxy == nullptr) {
3567 APP_LOGE("quickFixManagerProxy is nullptr");
3568 }
3569
3570 return quickFixManagerProxy;
3571 }
3572
SetDebugMode(bool isDebug)3573 ErrCode BundleMgrProxy::SetDebugMode(bool isDebug)
3574 {
3575 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3576 MessageParcel data;
3577 if (!data.WriteInterfaceToken(GetDescriptor())) {
3578 APP_LOGE("fail to get bundle manager proxy due to write InterfaceToken failed");
3579 return ERR_BUNDLEMANAGER_SET_DEBUG_MODE_PARCEL_ERROR;
3580 }
3581 if (!data.WriteBool(isDebug)) {
3582 APP_LOGE("fail to SetDebugMode due to write bundleName fail");
3583 return ERR_BUNDLEMANAGER_SET_DEBUG_MODE_PARCEL_ERROR;
3584 }
3585 MessageParcel reply;
3586 if (!SendTransactCmd(BundleMgrInterfaceCode::SET_DEBUG_MODE, data, reply)) {
3587 return ERR_BUNDLEMANAGER_SET_DEBUG_MODE_SEND_REQUEST_ERROR;
3588 }
3589
3590 return reply.ReadInt32();
3591 }
3592
VerifySystemApi(int32_t beginApiVersion)3593 bool BundleMgrProxy::VerifySystemApi(int32_t beginApiVersion)
3594 {
3595 APP_LOGD("begin to verify system app");
3596 MessageParcel data;
3597 if (!data.WriteInterfaceToken(GetDescriptor())) {
3598 APP_LOGE("fail to VerifySystemApi due to write InterfaceToken fail");
3599 return false;
3600 }
3601
3602 if (!data.WriteInt32(beginApiVersion)) {
3603 APP_LOGE("fail to VerifySystemApi due to write apiVersion fail");
3604 return false;
3605 }
3606
3607 MessageParcel reply;
3608 if (!SendTransactCmd(BundleMgrInterfaceCode::VERIFY_SYSTEM_API, data, reply)) {
3609 APP_LOGE("fail to sendRequest");
3610 return false;
3611 }
3612 return reply.ReadBool();
3613 }
3614
ProcessPreload(const Want & want)3615 bool BundleMgrProxy::ProcessPreload(const Want &want)
3616 {
3617 APP_LOGD("BundleMgrProxy::ProcessPreload is called");
3618 MessageParcel data;
3619 if (!data.WriteInterfaceToken(GetDescriptor())) {
3620 APP_LOGE("fail to ProcessPreload due to write InterfaceToken fail");
3621 return false;
3622 }
3623 if (!data.WriteParcelable(&want)) {
3624 APP_LOGE("fail to ProcessPreload due to write want fail");
3625 return false;
3626 }
3627 MessageParcel reply;
3628 MessageOption option(MessageOption::TF_ASYNC);
3629 auto remoteObj = Remote();
3630 if (remoteObj == nullptr) {
3631 APP_LOGE("remote is null");
3632 return false;
3633 }
3634 auto res = remoteObj->SendRequest(
3635 static_cast<uint32_t>(BundleMgrInterfaceCode::PROCESS_PRELOAD), data, reply, option);
3636 if (res != ERR_OK) {
3637 APP_LOGE("SendRequest fail, error: %{public}d", res);
3638 return false;
3639 }
3640 return reply.ReadBool();
3641 }
3642
GetOverlayManagerProxy()3643 sptr<IOverlayManager> BundleMgrProxy::GetOverlayManagerProxy()
3644 {
3645 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3646 MessageParcel data;
3647 if (!data.WriteInterfaceToken(GetDescriptor())) {
3648 APP_LOGE("fail to get bundle manager proxy due to write InterfaceToken failed");
3649 return nullptr;
3650 }
3651 MessageParcel reply;
3652 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_OVERLAY_MANAGER_PROXY, data, reply)) {
3653 return nullptr;
3654 }
3655
3656 sptr<IRemoteObject> object = reply.ReadRemoteObject();
3657 if (object == nullptr) {
3658 APP_LOGE("reply failed");
3659 return nullptr;
3660 }
3661 sptr<IOverlayManager> overlayManagerProxy = iface_cast<IOverlayManager>(object);
3662 if (overlayManagerProxy == nullptr) {
3663 APP_LOGE("overlayManagerProxy is nullptr");
3664 }
3665
3666 return overlayManagerProxy;
3667 }
3668
GetAppProvisionInfo(const std::string & bundleName,int32_t userId,AppProvisionInfo & appProvisionInfo)3669 ErrCode BundleMgrProxy::GetAppProvisionInfo(const std::string &bundleName, int32_t userId,
3670 AppProvisionInfo &appProvisionInfo)
3671 {
3672 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3673 APP_LOGD("begin to get AppProvisionInfo of %{public}s", bundleName.c_str());
3674 if (bundleName.empty()) {
3675 APP_LOGE("fail to GetAppProvisionInfo due to params empty");
3676 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
3677 }
3678
3679 MessageParcel data;
3680 if (!data.WriteInterfaceToken(GetDescriptor())) {
3681 APP_LOGE("fail to GetAppProvisionInfo due to write InterfaceToken fail");
3682 return ERR_APPEXECFWK_PARCEL_ERROR;
3683 }
3684 if (!data.WriteString(bundleName)) {
3685 APP_LOGE("fail to GetAppProvisionInfo due to write bundleName fail");
3686 return ERR_APPEXECFWK_PARCEL_ERROR;
3687 }
3688 if (!data.WriteInt32(userId)) {
3689 APP_LOGE("fail to GetAppProvisionInfo due to write userId fail");
3690 return ERR_APPEXECFWK_PARCEL_ERROR;
3691 }
3692 return GetParcelableInfoWithErrCode<AppProvisionInfo>(BundleMgrInterfaceCode::GET_APP_PROVISION_INFO,
3693 data, appProvisionInfo);
3694 }
3695
GetBaseSharedBundleInfos(const std::string & bundleName,std::vector<BaseSharedBundleInfo> & baseSharedBundleInfos,GetDependentBundleInfoFlag flag)3696 ErrCode BundleMgrProxy::GetBaseSharedBundleInfos(const std::string &bundleName,
3697 std::vector<BaseSharedBundleInfo> &baseSharedBundleInfos, GetDependentBundleInfoFlag flag)
3698 {
3699 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3700 APP_LOGD("begin to get base shared package infos");
3701 if (bundleName.empty()) {
3702 APP_LOGE("fail to GetBaseSharedBundleInfos due to bundleName empty");
3703 return ERR_APPEXECFWK_PARCEL_ERROR;
3704 }
3705 MessageParcel data;
3706 if (!data.WriteInterfaceToken(GetDescriptor())) {
3707 APP_LOGE("fail to GetBaseSharedBundleInfos due to write InterfaceToken fail");
3708 return ERR_APPEXECFWK_PARCEL_ERROR;
3709 }
3710 if (!data.WriteString(bundleName)) {
3711 APP_LOGE("fail to GetBaseSharedBundleInfos due to write bundleName fail");
3712 return ERR_APPEXECFWK_PARCEL_ERROR;
3713 }
3714 if (!data.WriteUint32(static_cast<uint32_t>(flag))) {
3715 APP_LOGE("fail to GetBaseSharedBundleInfos due to write flag fail");
3716 return ERR_APPEXECFWK_PARCEL_ERROR;
3717 }
3718 return GetParcelableInfosWithErrCode<BaseSharedBundleInfo>(BundleMgrInterfaceCode::GET_BASE_SHARED_BUNDLE_INFOS,
3719 data, baseSharedBundleInfos);
3720 }
3721
GetAllSharedBundleInfo(std::vector<SharedBundleInfo> & sharedBundles)3722 ErrCode BundleMgrProxy::GetAllSharedBundleInfo(std::vector<SharedBundleInfo> &sharedBundles)
3723 {
3724 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3725 APP_LOGD("begin to GetAllSharedBundleInfo");
3726
3727 MessageParcel data;
3728 if (!data.WriteInterfaceToken(GetDescriptor())) {
3729 APP_LOGE("fail to GetAllSharedBundleInfo due to write InterfaceToken fail");
3730 return ERR_APPEXECFWK_PARCEL_ERROR;
3731 }
3732 return GetParcelableInfosWithErrCode<SharedBundleInfo>(BundleMgrInterfaceCode::GET_ALL_SHARED_BUNDLE_INFO,
3733 data, sharedBundles);
3734 }
3735
GetSharedBundleInfo(const std::string & bundleName,const std::string & moduleName,std::vector<SharedBundleInfo> & sharedBundles)3736 ErrCode BundleMgrProxy::GetSharedBundleInfo(const std::string &bundleName, const std::string &moduleName,
3737 std::vector<SharedBundleInfo> &sharedBundles)
3738 {
3739 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3740 APP_LOGD("begin to GetSharedBundleInfo");
3741 MessageParcel data;
3742 if (!data.WriteInterfaceToken(GetDescriptor())) {
3743 APP_LOGE("fail to GetSharedBundleInfo due to write InterfaceToken fail");
3744 return ERR_APPEXECFWK_PARCEL_ERROR;
3745 }
3746 if (!data.WriteString(bundleName)) {
3747 APP_LOGE("fail to GetSharedBundleInfo due to write bundleName fail");
3748 return ERR_APPEXECFWK_PARCEL_ERROR;
3749 }
3750 if (!data.WriteString(moduleName)) {
3751 APP_LOGE("fail to GetSharedBundleInfo due to write moduleName fail");
3752 return ERR_APPEXECFWK_PARCEL_ERROR;
3753 }
3754 return GetParcelableInfosWithErrCode<SharedBundleInfo>(BundleMgrInterfaceCode::GET_SHARED_BUNDLE_INFO,
3755 data, sharedBundles);
3756 }
3757
GetSharedBundleInfoBySelf(const std::string & bundleName,SharedBundleInfo & sharedBundleInfo)3758 ErrCode BundleMgrProxy::GetSharedBundleInfoBySelf(const std::string &bundleName, SharedBundleInfo &sharedBundleInfo)
3759 {
3760 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3761 APP_LOGD("begin to GetSharedBundleInfoBySelf");
3762 MessageParcel data;
3763 if (!data.WriteInterfaceToken(GetDescriptor())) {
3764 APP_LOGE("fail to GetSharedBundleInfoBySelf due to write InterfaceToken fail");
3765 return ERR_APPEXECFWK_PARCEL_ERROR;
3766 }
3767 if (!data.WriteString(bundleName)) {
3768 APP_LOGE("fail to GetSharedBundleInfoBySelf due to write bundleName fail");
3769 return ERR_APPEXECFWK_PARCEL_ERROR;
3770 }
3771 return GetParcelableInfoWithErrCode<SharedBundleInfo>(BundleMgrInterfaceCode::GET_SHARED_BUNDLE_INFO_BY_SELF,
3772 data, sharedBundleInfo);
3773 }
3774
GetSharedDependencies(const std::string & bundleName,const std::string & moduleName,std::vector<Dependency> & dependencies)3775 ErrCode BundleMgrProxy::GetSharedDependencies(const std::string &bundleName, const std::string &moduleName,
3776 std::vector<Dependency> &dependencies)
3777 {
3778 APP_LOGD("begin to GetSharedDependencies");
3779 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3780 if (bundleName.empty() || moduleName.empty()) {
3781 APP_LOGE("bundleName or moduleName is empty");
3782 return false;
3783 }
3784
3785 MessageParcel data;
3786 if (!data.WriteInterfaceToken(GetDescriptor())) {
3787 APP_LOGE("fail to GetSharedDependencies due to write InterfaceToken fail");
3788 return ERR_APPEXECFWK_PARCEL_ERROR;
3789 }
3790 if (!data.WriteString(bundleName)) {
3791 APP_LOGE("fail to GetSharedDependencies due to write bundleName fail");
3792 return ERR_APPEXECFWK_PARCEL_ERROR;
3793 }
3794 if (!data.WriteString(moduleName)) {
3795 APP_LOGE("fail to GetSharedDependencies due to write moduleName fail");
3796 return ERR_APPEXECFWK_PARCEL_ERROR;
3797 }
3798 return GetParcelableInfosWithErrCode<Dependency>(
3799 BundleMgrInterfaceCode::GET_SHARED_DEPENDENCIES, data, dependencies);
3800 }
3801
GetProxyDataInfos(const std::string & bundleName,const std::string & moduleName,std::vector<ProxyData> & proxyDatas,int32_t userId)3802 ErrCode BundleMgrProxy::GetProxyDataInfos(const std::string &bundleName, const std::string &moduleName,
3803 std::vector<ProxyData> &proxyDatas, int32_t userId)
3804 {
3805 APP_LOGD("begin to GetProxyDataInfos");
3806 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3807 if (bundleName.empty()) {
3808 APP_LOGE("bundleName is empty");
3809 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
3810 }
3811
3812 MessageParcel data;
3813 if (!data.WriteInterfaceToken(GetDescriptor())) {
3814 APP_LOGE("fail to GetProxyDataInfos due to write InterfaceToken fail");
3815 return ERR_APPEXECFWK_PARCEL_ERROR;
3816 }
3817 if (!data.WriteString(bundleName)) {
3818 APP_LOGE("fail to GetProxyDataInfos due to write bundleName fail");
3819 return ERR_APPEXECFWK_PARCEL_ERROR;
3820 }
3821 if (!data.WriteString(moduleName)) {
3822 APP_LOGE("fail to GetProxyDataInfos due to write moduleName fail");
3823 return ERR_APPEXECFWK_PARCEL_ERROR;
3824 }
3825 if (!data.WriteInt32(userId)) {
3826 APP_LOGE("fail to GetProxyDataInfos due to write userId fail");
3827 return ERR_APPEXECFWK_PARCEL_ERROR;
3828 }
3829 return GetParcelableInfosWithErrCode<ProxyData>(BundleMgrInterfaceCode::GET_PROXY_DATA_INFOS, data, proxyDatas);
3830 }
3831
GetAllProxyDataInfos(std::vector<ProxyData> & proxyDatas,int32_t userId)3832 ErrCode BundleMgrProxy::GetAllProxyDataInfos(std::vector<ProxyData> &proxyDatas, int32_t userId)
3833 {
3834 APP_LOGD("begin to GetAllProxyDatas");
3835 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3836 MessageParcel data;
3837 if (!data.WriteInterfaceToken(GetDescriptor())) {
3838 APP_LOGE("fail to GetAllProxyDatas due to write InterfaceToken fail");
3839 return ERR_APPEXECFWK_PARCEL_ERROR;
3840 }
3841 if (!data.WriteInt32(userId)) {
3842 APP_LOGE("fail to GetProxyDataInfos due to write userId fail");
3843 return ERR_APPEXECFWK_PARCEL_ERROR;
3844 }
3845 return GetParcelableInfosWithErrCode<ProxyData>(
3846 BundleMgrInterfaceCode::GET_ALL_PROXY_DATA_INFOS, data, proxyDatas);
3847 }
3848
GetSpecifiedDistributionType(const std::string & bundleName,std::string & specifiedDistributionType)3849 ErrCode BundleMgrProxy::GetSpecifiedDistributionType(const std::string &bundleName,
3850 std::string &specifiedDistributionType)
3851 {
3852 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3853 if (bundleName.empty()) {
3854 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
3855 }
3856 MessageParcel data;
3857 if (!data.WriteInterfaceToken(GetDescriptor())) {
3858 APP_LOGE("fail to GetSpecifiedDistributionType due to write InterfaceToken failed");
3859 return ERR_APPEXECFWK_PARCEL_ERROR;
3860 }
3861 if (!data.WriteString(bundleName)) {
3862 APP_LOGE("fail to GetSpecifiedDistributionType due to write bundleName fail");
3863 return ERR_APPEXECFWK_PARCEL_ERROR;
3864 }
3865 MessageParcel reply;
3866 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_SPECIFIED_DISTRIBUTED_TYPE, data, reply)) {
3867 return ERR_APPEXECFWK_PARCEL_ERROR;
3868 }
3869 auto ret = reply.ReadInt32();
3870 if (ret == ERR_OK) {
3871 specifiedDistributionType = reply.ReadString();
3872 }
3873 return ret;
3874 }
3875
GetAdditionalInfo(const std::string & bundleName,std::string & additionalInfo)3876 ErrCode BundleMgrProxy::GetAdditionalInfo(const std::string &bundleName,
3877 std::string &additionalInfo)
3878 {
3879 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3880 if (bundleName.empty()) {
3881 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
3882 }
3883 MessageParcel data;
3884 if (!data.WriteInterfaceToken(GetDescriptor())) {
3885 APP_LOGE("fail to GetAdditionalInfo due to write InterfaceToken failed");
3886 return ERR_APPEXECFWK_PARCEL_ERROR;
3887 }
3888 if (!data.WriteString(bundleName)) {
3889 APP_LOGE("fail to GetAdditionalInfo due to write bundleName fail");
3890 return ERR_APPEXECFWK_PARCEL_ERROR;
3891 }
3892 MessageParcel reply;
3893 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ADDITIONAL_INFO, data, reply)) {
3894 return ERR_APPEXECFWK_PARCEL_ERROR;
3895 }
3896 auto ret = reply.ReadInt32();
3897 if (ret == ERR_OK) {
3898 additionalInfo = reply.ReadString();
3899 }
3900 return ret;
3901 }
3902
SetExtNameOrMIMEToApp(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,const std::string & extName,const std::string & mimeType)3903 ErrCode BundleMgrProxy::SetExtNameOrMIMEToApp(const std::string &bundleName, const std::string &moduleName,
3904 const std::string &abilityName, const std::string &extName, const std::string &mimeType)
3905 {
3906 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3907 if (bundleName.empty() || moduleName.empty() || abilityName.empty()) {
3908 APP_LOGE("bundleName, moduleName or abilityName is empty");
3909 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
3910 }
3911 if (extName.empty() && mimeType.empty()) {
3912 APP_LOGE("extName and mimeType are empty");
3913 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
3914 }
3915 MessageParcel data;
3916 if (!data.WriteInterfaceToken(GetDescriptor())) {
3917 APP_LOGE("fail to SetExtNameOrMIMEToApp due to write InterfaceToken failed");
3918 return ERR_APPEXECFWK_PARCEL_ERROR;
3919 }
3920 if (!data.WriteString(bundleName)) {
3921 APP_LOGE("fail to SetExtNameOrMIMEToApp due to write bundleName fail");
3922 return ERR_APPEXECFWK_PARCEL_ERROR;
3923 }
3924 if (!data.WriteString(moduleName)) {
3925 APP_LOGE("fail to SetExtNameOrMIMEToApp due to write moduleName fail");
3926 return ERR_APPEXECFWK_PARCEL_ERROR;
3927 }
3928 if (!data.WriteString(abilityName)) {
3929 APP_LOGE("fail to SetExtNameOrMIMEToApp due to write abilityName fail");
3930 return ERR_APPEXECFWK_PARCEL_ERROR;
3931 }
3932 if (!data.WriteString(extName)) {
3933 APP_LOGE("fail to SetExtNameOrMIMEToApp due to write extName fail");
3934 return ERR_APPEXECFWK_PARCEL_ERROR;
3935 }
3936 if (!data.WriteString(mimeType)) {
3937 APP_LOGE("fail to SetExtNameOrMIMEToApp due to write mimeType fail");
3938 return ERR_APPEXECFWK_PARCEL_ERROR;
3939 }
3940
3941 MessageParcel reply;
3942 if (!SendTransactCmd(BundleMgrInterfaceCode::SET_EXT_NAME_OR_MIME_TO_APP, data, reply)) {
3943 return ERR_APPEXECFWK_PARCEL_ERROR;
3944 }
3945 auto ret = reply.ReadInt32();
3946 return ret;
3947 }
3948
DelExtNameOrMIMEToApp(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,const std::string & extName,const std::string & mimeType)3949 ErrCode BundleMgrProxy::DelExtNameOrMIMEToApp(const std::string &bundleName, const std::string &moduleName,
3950 const std::string &abilityName, const std::string &extName, const std::string &mimeType)
3951 {
3952 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3953 if (bundleName.empty() || moduleName.empty() || abilityName.empty()) {
3954 APP_LOGE("bundleName, moduleName or abilityName is empty");
3955 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
3956 }
3957 if (extName.empty() && mimeType.empty()) {
3958 APP_LOGE("extName and mimeType are empty");
3959 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
3960 }
3961 MessageParcel data;
3962 if (!data.WriteInterfaceToken(GetDescriptor())) {
3963 APP_LOGE("fail to DelExtNameOrMIMEToApp due to write InterfaceToken failed");
3964 return ERR_APPEXECFWK_PARCEL_ERROR;
3965 }
3966 if (!data.WriteString(bundleName)) {
3967 APP_LOGE("fail to DelExtNameOrMIMEToApp due to write bundleName fail");
3968 return ERR_APPEXECFWK_PARCEL_ERROR;
3969 }
3970 if (!data.WriteString(moduleName)) {
3971 APP_LOGE("fail to DelExtNameOrMIMEToApp due to write moduleName fail");
3972 return ERR_APPEXECFWK_PARCEL_ERROR;
3973 }
3974 if (!data.WriteString(abilityName)) {
3975 APP_LOGE("fail to DelExtNameOrMIMEToApp due to write abilityName fail");
3976 return ERR_APPEXECFWK_PARCEL_ERROR;
3977 }
3978 if (!data.WriteString(extName)) {
3979 APP_LOGE("fail to DelExtNameOrMIMEToApp due to write extName fail");
3980 return ERR_APPEXECFWK_PARCEL_ERROR;
3981 }
3982 if (!data.WriteString(mimeType)) {
3983 APP_LOGE("fail to DelExtNameOrMIMEToApp due to write mimeType fail");
3984 return ERR_APPEXECFWK_PARCEL_ERROR;
3985 }
3986
3987 MessageParcel reply;
3988 if (!SendTransactCmd(BundleMgrInterfaceCode::DEL_EXT_NAME_OR_MIME_TO_APP, data, reply)) {
3989 return ERR_APPEXECFWK_PARCEL_ERROR;
3990 }
3991 auto ret = reply.ReadInt32();
3992 return ret;
3993 }
3994
QueryDataGroupInfos(const std::string & bundleName,int32_t userId,std::vector<DataGroupInfo> & infos)3995 bool BundleMgrProxy::QueryDataGroupInfos(const std::string &bundleName,
3996 int32_t userId, std::vector<DataGroupInfo> &infos)
3997 {
3998 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
3999 if (bundleName.empty()) {
4000 APP_LOGE("bundleName is empty");
4001 return false;
4002 }
4003 MessageParcel data;
4004 if (!data.WriteInterfaceToken(GetDescriptor())) {
4005 APP_LOGE("fail to QueryDataGroupInfos due to write InterfaceToken failed");
4006 return false;
4007 }
4008 if (!data.WriteString(bundleName)) {
4009 APP_LOGE("fail to QueryDataGroupInfos due to write dataGroupId fail");
4010 return false;
4011 }
4012 if (!data.WriteInt32(userId)) {
4013 APP_LOGE("fail to QueryDataGroupInfos due to write userId fail");
4014 return false;
4015 }
4016
4017 if (!GetParcelableInfos<DataGroupInfo>(BundleMgrInterfaceCode::QUERY_DATA_GROUP_INFOS, data, infos)) {
4018 APP_LOGE("failed to QueryDataGroupInfos from server");
4019 return false;
4020 }
4021 return true;
4022 }
4023
GetGroupDir(const std::string & dataGroupId,std::string & dir)4024 bool BundleMgrProxy::GetGroupDir(const std::string &dataGroupId, std::string &dir)
4025 {
4026 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4027 if (dataGroupId.empty()) {
4028 APP_LOGE("dataGroupId is empty");
4029 return false;
4030 }
4031 MessageParcel data;
4032 if (!data.WriteInterfaceToken(GetDescriptor())) {
4033 APP_LOGE("fail to GetGroupDir due to write InterfaceToken failed");
4034 return false;
4035 }
4036 if (!data.WriteString(dataGroupId)) {
4037 APP_LOGE("fail to GetGroupDir due to write dataGroupId fail");
4038 return false;
4039 }
4040
4041 MessageParcel reply;
4042 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_PREFERENCE_DIR_BY_GROUP_ID, data, reply)) {
4043 APP_LOGE("fail to GetGroupDir from server");
4044 return false;
4045 }
4046 if (!reply.ReadBool()) {
4047 APP_LOGE("reply result false");
4048 return false;
4049 }
4050 dir = reply.ReadString();
4051 return true;
4052 }
4053
QueryAppGalleryBundleName(std::string & bundleName)4054 bool BundleMgrProxy::QueryAppGalleryBundleName(std::string &bundleName)
4055 {
4056 APP_LOGD("QueryAppGalleryBundleName in bundle proxy start");
4057 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4058 MessageParcel data;
4059 if (!data.WriteInterfaceToken(GetDescriptor())) {
4060 APP_LOGE("fail to QueryAppGalleryBundleName due to write InterfaceToken failed");
4061 return false;
4062 }
4063
4064 MessageParcel reply;
4065 if (!SendTransactCmd(BundleMgrInterfaceCode::QUERY_APPGALLERY_BUNDLE_NAME, data, reply)) {
4066 APP_LOGE("fail to QueryAppGalleryBundleName from server");
4067 return false;
4068 }
4069 if (!reply.ReadBool()) {
4070 APP_LOGE("reply result false");
4071 return false;
4072 }
4073 bundleName = reply.ReadString();
4074 if (bundleName.length() > Constants::MAX_BUNDLE_NAME) {
4075 APP_LOGE("reply result false");
4076 return false;
4077 }
4078 APP_LOGD("bundleName is %{public}s", bundleName.c_str());
4079 return true;
4080 }
4081
QueryExtensionAbilityInfosWithTypeName(const Want & want,const std::string & extensionTypeName,const int32_t flag,const int32_t userId,std::vector<ExtensionAbilityInfo> & extensionInfos)4082 ErrCode BundleMgrProxy::QueryExtensionAbilityInfosWithTypeName(const Want &want, const std::string &extensionTypeName,
4083 const int32_t flag, const int32_t userId, std::vector<ExtensionAbilityInfo> &extensionInfos)
4084 {
4085 MessageParcel data;
4086 if (!data.WriteInterfaceToken(GetDescriptor())) {
4087 LOG_E(BMS_TAG_QUERY, "Write InterfaceToken fail");
4088 return ERR_APPEXECFWK_PARCEL_ERROR;
4089 }
4090 if (!data.WriteParcelable(&want)) {
4091 LOG_E(BMS_TAG_QUERY, "Write want fail");
4092 return ERR_APPEXECFWK_PARCEL_ERROR;
4093 }
4094 if (!data.WriteString(extensionTypeName)) {
4095 LOG_E(BMS_TAG_QUERY, "Write type fail");
4096 return ERR_APPEXECFWK_PARCEL_ERROR;
4097 }
4098 if (!data.WriteInt32(flag)) {
4099 LOG_E(BMS_TAG_QUERY, "Write flag fail");
4100 return ERR_APPEXECFWK_PARCEL_ERROR;
4101 }
4102 if (!data.WriteInt32(userId)) {
4103 LOG_E(BMS_TAG_QUERY, "Write userId fail");
4104 return ERR_APPEXECFWK_PARCEL_ERROR;
4105 }
4106 return GetParcelableInfosWithErrCode(BundleMgrInterfaceCode::QUERY_EXTENSION_ABILITY_INFO_WITH_TYPE_NAME,
4107 data, extensionInfos);
4108 }
4109
QueryExtensionAbilityInfosOnlyWithTypeName(const std::string & extensionTypeName,const uint32_t flag,const int32_t userId,std::vector<ExtensionAbilityInfo> & extensionInfos)4110 ErrCode BundleMgrProxy::QueryExtensionAbilityInfosOnlyWithTypeName(const std::string &extensionTypeName,
4111 const uint32_t flag, const int32_t userId, std::vector<ExtensionAbilityInfo> &extensionInfos)
4112 {
4113 MessageParcel data;
4114 if (!data.WriteInterfaceToken(GetDescriptor())) {
4115 APP_LOGE("Write InterfaceToken fail");
4116 return ERR_APPEXECFWK_PARCEL_ERROR;
4117 }
4118 if (!data.WriteString(extensionTypeName)) {
4119 APP_LOGE("Write type fail");
4120 return ERR_APPEXECFWK_PARCEL_ERROR;
4121 }
4122 if (!data.WriteUint32(flag)) {
4123 APP_LOGE("Write flag fail");
4124 return ERR_APPEXECFWK_PARCEL_ERROR;
4125 }
4126 if (!data.WriteInt32(userId)) {
4127 APP_LOGE("Write userId fail");
4128 return ERR_APPEXECFWK_PARCEL_ERROR;
4129 }
4130 return GetVectorFromParcelIntelligentWithErrCode(
4131 BundleMgrInterfaceCode::QUERY_EXTENSION_ABILITY_INFO_ONLY_WITH_TYPE_NAME, data,
4132 extensionInfos);
4133 }
4134
ResetAOTCompileStatus(const std::string & bundleName,const std::string & moduleName,int32_t triggerMode)4135 ErrCode BundleMgrProxy::ResetAOTCompileStatus(const std::string &bundleName, const std::string &moduleName,
4136 int32_t triggerMode)
4137 {
4138 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4139 APP_LOGD("ResetAOTCompileStatus begin, bundleName : %{public}s, moduleName : %{public}s, triggerMode : %{public}d",
4140 bundleName.c_str(), moduleName.c_str(), triggerMode);
4141 if (bundleName.empty() || moduleName.empty()) {
4142 APP_LOGE("invalid param");
4143 return ERR_BUNDLE_MANAGER_INVALID_PARAMETER;
4144 }
4145 MessageParcel data;
4146 if (!data.WriteInterfaceToken(GetDescriptor())) {
4147 APP_LOGE("write interfaceToken failed");
4148 return ERR_APPEXECFWK_PARCEL_ERROR;
4149 }
4150 if (!data.WriteString(bundleName)) {
4151 APP_LOGE("write bundleName failed");
4152 return ERR_APPEXECFWK_PARCEL_ERROR;
4153 }
4154 if (!data.WriteString(moduleName)) {
4155 APP_LOGE("write moduleName failed");
4156 return ERR_APPEXECFWK_PARCEL_ERROR;
4157 }
4158 if (!data.WriteInt32(triggerMode)) {
4159 APP_LOGE("write triggerMode failed");
4160 return ERR_APPEXECFWK_PARCEL_ERROR;
4161 }
4162 MessageParcel reply;
4163 if (!SendTransactCmd(BundleMgrInterfaceCode::RESET_AOT_COMPILE_STATUS, data, reply)) {
4164 APP_LOGE("SendTransactCmd failed");
4165 return ERR_APPEXECFWK_PARCEL_ERROR;
4166 }
4167 return reply.ReadInt32();
4168 }
4169
GetJsonProfile(ProfileType profileType,const std::string & bundleName,const std::string & moduleName,std::string & profile,int32_t userId)4170 ErrCode BundleMgrProxy::GetJsonProfile(ProfileType profileType, const std::string &bundleName,
4171 const std::string &moduleName, std::string &profile, int32_t userId)
4172 {
4173 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4174 APP_LOGD("begin to GetJsonProfile");
4175 if (bundleName.empty()) {
4176 APP_LOGE("bundleName is empty");
4177 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
4178 }
4179
4180 MessageParcel data;
4181 if (!data.WriteInterfaceToken(GetDescriptor())) {
4182 APP_LOGE("fail to GetJsonProfile due to write InterfaceToken fail");
4183 return ERR_APPEXECFWK_PARCEL_ERROR;
4184 }
4185 if (!data.WriteInt32(profileType)) {
4186 APP_LOGE("fail to GetJsonProfile due to write flags fail");
4187 return ERR_APPEXECFWK_PARCEL_ERROR;
4188 }
4189 if (!data.WriteString(bundleName)) {
4190 APP_LOGE("fail to GetJsonProfile due to write bundleName fail");
4191 return ERR_APPEXECFWK_PARCEL_ERROR;
4192 }
4193 if (!data.WriteString(moduleName)) {
4194 APP_LOGE("fail to GetJsonProfile due to write moduleName fail");
4195 return ERR_APPEXECFWK_PARCEL_ERROR;
4196 }
4197 if (!data.WriteInt32(userId)) {
4198 APP_LOGE("fail to GetBundleInfo due to write userId fail");
4199 return ERR_APPEXECFWK_PARCEL_ERROR;
4200 }
4201
4202 return GetBigString(BundleMgrInterfaceCode::GET_JSON_PROFILE, data, profile);
4203 }
4204
GetBundleResourceProxy()4205 sptr<IBundleResource> BundleMgrProxy::GetBundleResourceProxy()
4206 {
4207 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4208 MessageParcel data;
4209 MessageParcel reply;
4210 if (!data.WriteInterfaceToken(GetDescriptor())) {
4211 APP_LOGE("write InterfaceToken failed");
4212 return nullptr;
4213 }
4214 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_BUNDLE_RESOURCE_PROXY, data, reply)) {
4215 return nullptr;
4216 }
4217
4218 sptr<IRemoteObject> object = reply.ReadRemoteObject();
4219 if (object == nullptr) {
4220 APP_LOGE("reply failed");
4221 return nullptr;
4222 }
4223 sptr<IBundleResource> bundleResourceProxy = iface_cast<IBundleResource>(object);
4224 if (bundleResourceProxy == nullptr) {
4225 APP_LOGE("bundleResourceProxy is nullptr");
4226 }
4227
4228 return bundleResourceProxy;
4229 }
4230
GetRecoverableApplicationInfo(std::vector<RecoverableApplicationInfo> & recoverableApplications)4231 ErrCode BundleMgrProxy::GetRecoverableApplicationInfo(
4232 std::vector<RecoverableApplicationInfo> &recoverableApplications)
4233 {
4234 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4235 APP_LOGD("begin to GetRecoverableApplicationInfo");
4236
4237 MessageParcel data;
4238 if (!data.WriteInterfaceToken(GetDescriptor())) {
4239 APP_LOGE("fail to GetRecoverableApplicationInfo due to write InterfaceToken fail");
4240 return ERR_APPEXECFWK_PARCEL_ERROR;
4241 }
4242 return GetParcelableInfosWithErrCode<RecoverableApplicationInfo>(
4243 BundleMgrInterfaceCode::GET_RECOVERABLE_APPLICATION_INFO, data, recoverableApplications);
4244 }
4245
GetUninstalledBundleInfo(const std::string bundleName,BundleInfo & bundleInfo)4246 ErrCode BundleMgrProxy::GetUninstalledBundleInfo(const std::string bundleName, BundleInfo &bundleInfo)
4247 {
4248 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4249 APP_LOGD("begin to GetUninstalledBundleInfo of %{public}s", bundleName.c_str());
4250 if (bundleName.empty()) {
4251 APP_LOGE("fail to GetUninstalledBundleInfo due to params empty");
4252 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
4253 }
4254
4255 MessageParcel data;
4256 if (!data.WriteInterfaceToken(GetDescriptor())) {
4257 APP_LOGE("fail to GetUninstalledBundleInfo due to write InterfaceToken fail");
4258 return ERR_APPEXECFWK_PARCEL_ERROR;
4259 }
4260 if (!data.WriteString(bundleName)) {
4261 APP_LOGE("fail to GetUninstalledBundleInfo due to write bundleName fail");
4262 return ERR_APPEXECFWK_PARCEL_ERROR;
4263 }
4264
4265 auto res = GetParcelableInfoWithErrCode<BundleInfo>(
4266 BundleMgrInterfaceCode::GET_UNINSTALLED_BUNDLE_INFO, data, bundleInfo);
4267 if (res != ERR_OK) {
4268 APP_LOGE_NOFUNC("GetUninstalledBundleInfo failed: %{public}d", res);
4269 return res;
4270 }
4271 return ERR_OK;
4272 }
4273
SetAdditionalInfo(const std::string & bundleName,const std::string & additionalInfo)4274 ErrCode BundleMgrProxy::SetAdditionalInfo(const std::string &bundleName, const std::string &additionalInfo)
4275 {
4276 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4277 APP_LOGD("Called. BundleName : %{public}s", bundleName.c_str());
4278 if (bundleName.empty()) {
4279 APP_LOGE("Invalid param");
4280 return ERR_BUNDLE_MANAGER_PARAM_ERROR;
4281 }
4282 MessageParcel data;
4283 if (!data.WriteInterfaceToken(GetDescriptor())) {
4284 APP_LOGE("Write interfaceToken failed");
4285 return ERR_APPEXECFWK_PARCEL_ERROR;
4286 }
4287 if (!data.WriteString(bundleName)) {
4288 APP_LOGE("Write bundleName failed");
4289 return ERR_APPEXECFWK_PARCEL_ERROR;
4290 }
4291 if (!data.WriteString(additionalInfo)) {
4292 APP_LOGE("Write additionalInfo failed");
4293 return ERR_APPEXECFWK_PARCEL_ERROR;
4294 }
4295
4296 MessageParcel reply;
4297 if (!SendTransactCmd(BundleMgrInterfaceCode::SET_ADDITIONAL_INFO, data, reply)) {
4298 APP_LOGE("Call failed");
4299 return ERR_APPEXECFWK_PARCEL_ERROR;
4300 }
4301 return reply.ReadInt32();
4302 }
4303
CreateBundleDataDir(int32_t userId)4304 ErrCode BundleMgrProxy::CreateBundleDataDir(int32_t userId)
4305 {
4306 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4307 APP_LOGD("CreateBundleDataDir Called. userId: %{public}d", userId);
4308 MessageParcel data;
4309 if (!data.WriteInterfaceToken(GetDescriptor())) {
4310 APP_LOGE("Write interfaceToken failed");
4311 return ERR_APPEXECFWK_PARCEL_ERROR;
4312 }
4313 if (!data.WriteInt32(userId)) {
4314 APP_LOGE("fail to CreateBundleDataDir due to write userId fail");
4315 return ERR_APPEXECFWK_PARCEL_ERROR;
4316 }
4317
4318 MessageParcel reply;
4319 if (!SendTransactCmd(BundleMgrInterfaceCode::CREATE_BUNDLE_DATA_DIR, data, reply)) {
4320 APP_LOGE("Call failed");
4321 return ERR_APPEXECFWK_PARCEL_ERROR;
4322 }
4323 return reply.ReadInt32();
4324 }
4325
GetOdid(std::string & odid)4326 ErrCode BundleMgrProxy::GetOdid(std::string &odid)
4327 {
4328 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4329 APP_LOGD("GetOdid Called");
4330 MessageParcel data;
4331 if (!data.WriteInterfaceToken(GetDescriptor())) {
4332 APP_LOGE("Write interfaceToken failed");
4333 return ERR_APPEXECFWK_PARCEL_ERROR;
4334 }
4335
4336 MessageParcel reply;
4337 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ODID, data, reply)) {
4338 return ERR_APPEXECFWK_PARCEL_ERROR;
4339 }
4340 auto ret = reply.ReadInt32();
4341 if (ret == ERR_OK) {
4342 odid = reply.ReadString();
4343 }
4344 APP_LOGD("GetOdid ret: %{public}d, odid: %{private}s", ret, odid.c_str());
4345 return ret;
4346 }
4347
GetAllBundleInfoByDeveloperId(const std::string & developerId,std::vector<BundleInfo> & bundleInfos,int32_t userId)4348 ErrCode BundleMgrProxy::GetAllBundleInfoByDeveloperId(const std::string &developerId,
4349 std::vector<BundleInfo> &bundleInfos, int32_t userId)
4350 {
4351 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4352 APP_LOGI("begin GetAllBundleInfoByDeveloperId, developerId: %{public}s, userId :%{public}d",
4353 developerId.c_str(), userId);
4354 MessageParcel data;
4355 if (!data.WriteInterfaceToken(GetDescriptor())) {
4356 APP_LOGE("fail to GetAllBundleInfoByDeveloperId due to write InterfaceToken fail");
4357 return ERR_APPEXECFWK_PARCEL_ERROR;
4358 }
4359 if (!data.WriteString(developerId)) {
4360 APP_LOGE("failed to GetAllBundleInfoByDeveloperId due to write developerId fail");
4361 return ERR_APPEXECFWK_PARCEL_ERROR;
4362 }
4363 if (!data.WriteInt32(userId)) {
4364 APP_LOGE("fail to GetAllBundleInfoByDeveloperId due to write userId fail");
4365 return ERR_APPEXECFWK_PARCEL_ERROR;
4366 }
4367 return GetVectorFromParcelIntelligentWithErrCode<BundleInfo>(
4368 BundleMgrInterfaceCode::GET_ALL_BUNDLE_INFO_BY_DEVELOPER_ID, data, bundleInfos);
4369 }
4370
GetDeveloperIds(const std::string & appDistributionType,std::vector<std::string> & developerIdList,int32_t userId)4371 ErrCode BundleMgrProxy::GetDeveloperIds(const std::string &appDistributionType,
4372 std::vector<std::string> &developerIdList, int32_t userId)
4373 {
4374 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4375 APP_LOGI("begin to GetDeveloperIds of %{public}s", appDistributionType.c_str());
4376 MessageParcel data;
4377 if (!data.WriteInterfaceToken(GetDescriptor())) {
4378 APP_LOGE("fail to GetDeveloperIds due to write InterfaceToken fail");
4379 return ERR_APPEXECFWK_PARCEL_ERROR;
4380 }
4381 if (!data.WriteString(appDistributionType)) {
4382 APP_LOGE("failed to GetDeveloperIds due to write appDistributionType fail");
4383 return ERR_APPEXECFWK_PARCEL_ERROR;
4384 }
4385 if (!data.WriteInt32(userId)) {
4386 APP_LOGE("fail to GetDeveloperIds due to write userId fail");
4387 return ERR_APPEXECFWK_PARCEL_ERROR;
4388 }
4389
4390 MessageParcel reply;
4391 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_DEVELOPER_IDS, data, reply)) {
4392 APP_LOGE("SendTransactCmd failed");
4393 return ERR_APPEXECFWK_PARCEL_ERROR;
4394 }
4395 ErrCode res = reply.ReadInt32();
4396 if (res != ERR_OK) {
4397 APP_LOGE("host reply err %{public}d", res);
4398 return res;
4399 }
4400 if (!reply.ReadStringVector(&developerIdList)) {
4401 APP_LOGE("fail to GetDeveloperIds from reply");
4402 return ERR_APPEXECFWK_PARCEL_ERROR;
4403 }
4404 return ERR_OK;
4405 }
4406
4407 template<typename T>
GetParcelableInfo(BundleMgrInterfaceCode code,MessageParcel & data,T & parcelableInfo)4408 bool BundleMgrProxy::GetParcelableInfo(BundleMgrInterfaceCode code, MessageParcel &data, T &parcelableInfo)
4409 {
4410 MessageParcel reply;
4411 if (!SendTransactCmd(code, data, reply)) {
4412 return false;
4413 }
4414
4415 if (!reply.ReadBool()) {
4416 APP_LOGE_NOFUNC("GetParcelableInfo reply false");
4417 return false;
4418 }
4419
4420 std::unique_ptr<T> info(reply.ReadParcelable<T>());
4421 if (info == nullptr) {
4422 APP_LOGE("readParcelableInfo failed");
4423 return false;
4424 }
4425 parcelableInfo = *info;
4426 APP_LOGD("get parcelable info success");
4427 return true;
4428 }
4429
4430 template <typename T>
GetParcelableInfoWithErrCode(BundleMgrInterfaceCode code,MessageParcel & data,T & parcelableInfo)4431 ErrCode BundleMgrProxy::GetParcelableInfoWithErrCode(
4432 BundleMgrInterfaceCode code, MessageParcel &data, T &parcelableInfo)
4433 {
4434 MessageParcel reply;
4435 if (!SendTransactCmd(code, data, reply)) {
4436 APP_LOGE("SendTransactCmd failed");
4437 return ERR_APPEXECFWK_PARCEL_ERROR;
4438 }
4439
4440 ErrCode res = reply.ReadInt32();
4441 if (res == ERR_OK) {
4442 std::unique_ptr<T> info(reply.ReadParcelable<T>());
4443 if (info == nullptr) {
4444 APP_LOGE("readParcelableInfo failed");
4445 return ERR_APPEXECFWK_PARCEL_ERROR;
4446 }
4447 parcelableInfo = *info;
4448 }
4449
4450 APP_LOGD("GetParcelableInfoWithErrCode ErrCode : %{public}d", res);
4451 return res;
4452 }
4453
4454 template<typename T>
GetParcelableInfos(BundleMgrInterfaceCode code,MessageParcel & data,std::vector<T> & parcelableInfos)4455 bool BundleMgrProxy::GetParcelableInfos(
4456 BundleMgrInterfaceCode code, MessageParcel &data, std::vector<T> &parcelableInfos)
4457 {
4458 MessageParcel reply;
4459 if (!SendTransactCmd(code, data, reply)) {
4460 return false;
4461 }
4462
4463 if (!reply.ReadBool()) {
4464 APP_LOGE("readParcelableInfo failed");
4465 return false;
4466 }
4467
4468 int32_t infoSize = reply.ReadInt32();
4469 for (int32_t i = 0; i < infoSize; i++) {
4470 std::unique_ptr<T> info(reply.ReadParcelable<T>());
4471 if (info == nullptr) {
4472 APP_LOGE("Read Parcelable infos failed");
4473 return false;
4474 }
4475 parcelableInfos.emplace_back(*info);
4476 }
4477 APP_LOGD("get parcelable infos success");
4478 return true;
4479 }
4480
4481 template<typename T>
GetParcelableInfosWithErrCode(BundleMgrInterfaceCode code,MessageParcel & data,std::vector<T> & parcelableInfos)4482 ErrCode BundleMgrProxy::GetParcelableInfosWithErrCode(BundleMgrInterfaceCode code, MessageParcel &data,
4483 std::vector<T> &parcelableInfos)
4484 {
4485 MessageParcel reply;
4486 if (!SendTransactCmd(code, data, reply)) {
4487 APP_LOGE("SendTransactCmd failed");
4488 return ERR_APPEXECFWK_PARCEL_ERROR;
4489 }
4490
4491 ErrCode res = reply.ReadInt32();
4492 if (res == ERR_OK) {
4493 int32_t infoSize = reply.ReadInt32();
4494 CONTAINER_SECURITY_VERIFY(reply, infoSize, &parcelableInfos);
4495 for (int32_t i = 0; i < infoSize; i++) {
4496 std::unique_ptr<T> info(reply.ReadParcelable<T>());
4497 if (info == nullptr) {
4498 APP_LOGE("Read Parcelable infos failed");
4499 return ERR_APPEXECFWK_PARCEL_ERROR;
4500 }
4501 parcelableInfos.emplace_back(*info);
4502 }
4503 APP_LOGD("get parcelable infos success");
4504 }
4505 APP_LOGD("GetParcelableInfosWithErrCode ErrCode : %{public}d", res);
4506 return res;
4507 }
4508
4509 template<typename T>
GetParcelInfoIntelligent(BundleMgrInterfaceCode code,MessageParcel & data,T & parcelInfo)4510 ErrCode BundleMgrProxy::GetParcelInfoIntelligent(
4511 BundleMgrInterfaceCode code, MessageParcel &data, T &parcelInfo)
4512 {
4513 MessageParcel reply;
4514 if (!SendTransactCmd(code, data, reply)) {
4515 APP_LOGE("SendTransactCmd failed");
4516 return ERR_APPEXECFWK_PARCEL_ERROR;
4517 }
4518 ErrCode ret = reply.ReadInt32();
4519 if (ret != ERR_OK) {
4520 APP_LOGE_NOFUNC("reply ErrCode: %{public}d", ret);
4521 return ret;
4522 }
4523 size_t dataSize = reply.ReadUint32();
4524 void *buffer = nullptr;
4525 if (!GetData(buffer, dataSize, reply.ReadRawData(dataSize))) {
4526 APP_LOGE("GetData failed dataSize : %{public}zu", dataSize);
4527 return ERR_APPEXECFWK_PARCEL_ERROR;
4528 }
4529
4530 MessageParcel tmpParcel;
4531 if (!tmpParcel.ParseFrom(reinterpret_cast<uintptr_t>(buffer), dataSize)) {
4532 APP_LOGE("ParseFrom failed");
4533 return ERR_APPEXECFWK_PARCEL_ERROR;
4534 }
4535
4536 std::unique_ptr<T> info(tmpParcel.ReadParcelable<T>());
4537 if (info == nullptr) {
4538 APP_LOGE("ReadParcelable failed");
4539 return ERR_APPEXECFWK_PARCEL_ERROR;
4540 }
4541 parcelInfo = *info;
4542 return ERR_OK;
4543 }
4544
4545 template<typename T>
GetVectorFromParcelIntelligent(BundleMgrInterfaceCode code,MessageParcel & data,std::vector<T> & parcelableInfos)4546 bool BundleMgrProxy::GetVectorFromParcelIntelligent(
4547 BundleMgrInterfaceCode code, MessageParcel &data, std::vector<T> &parcelableInfos)
4548 {
4549 APP_LOGD("GetParcelableInfos start");
4550 MessageParcel reply;
4551 if (!SendTransactCmd(code, data, reply)) {
4552 return false;
4553 }
4554
4555 if (!reply.ReadBool()) {
4556 APP_LOGE("readParcelableInfo failed");
4557 return false;
4558 }
4559
4560 if (InnerGetVectorFromParcelIntelligent<T>(reply, parcelableInfos) != ERR_OK) {
4561 APP_LOGE("InnerGetVectorFromParcelIntelligent failed");
4562 return false;
4563 }
4564
4565 return true;
4566 }
4567
4568 template<typename T>
GetVectorFromParcelIntelligentWithErrCode(BundleMgrInterfaceCode code,MessageParcel & data,std::vector<T> & parcelableInfos)4569 ErrCode BundleMgrProxy::GetVectorFromParcelIntelligentWithErrCode(
4570 BundleMgrInterfaceCode code, MessageParcel &data, std::vector<T> &parcelableInfos)
4571 {
4572 MessageParcel reply;
4573 if (!SendTransactCmd(code, data, reply)) {
4574 APP_LOGE("SendTransactCmd failed");
4575 return ERR_APPEXECFWK_PARCEL_ERROR;
4576 }
4577
4578 ErrCode res = reply.ReadInt32();
4579 if (res != ERR_OK) {
4580 APP_LOGE("GetParcelableInfosWithErrCode: %{public}d", res);
4581 return res;
4582 }
4583
4584 return InnerGetVectorFromParcelIntelligent<T>(reply, parcelableInfos);
4585 }
4586
4587 template<typename T>
InnerGetVectorFromParcelIntelligent(MessageParcel & reply,std::vector<T> & parcelableInfos)4588 ErrCode BundleMgrProxy::InnerGetVectorFromParcelIntelligent(
4589 MessageParcel &reply, std::vector<T> &parcelableInfos)
4590 {
4591 size_t dataSize = static_cast<size_t>(reply.ReadInt32());
4592 if (dataSize == 0) {
4593 APP_LOGW("Parcel no data");
4594 return ERR_OK;
4595 }
4596
4597 void *buffer = nullptr;
4598 if (!SendData(buffer, dataSize, reply.ReadRawData(dataSize))) {
4599 APP_LOGE("Fail read raw data length %{public}zu", dataSize);
4600 return ERR_APPEXECFWK_PARCEL_ERROR;
4601 }
4602
4603 MessageParcel tempParcel;
4604 if (!tempParcel.ParseFrom(reinterpret_cast<uintptr_t>(buffer), dataSize)) {
4605 APP_LOGE("Fail to ParseFrom");
4606 return ERR_APPEXECFWK_PARCEL_ERROR;
4607 }
4608
4609 int32_t infoSize = tempParcel.ReadInt32();
4610 CONTAINER_SECURITY_VERIFY(tempParcel, infoSize, &parcelableInfos);
4611 for (int32_t i = 0; i < infoSize; i++) {
4612 std::unique_ptr<T> info(tempParcel.ReadParcelable<T>());
4613 if (info == nullptr) {
4614 APP_LOGE("Read Parcelable infos failed");
4615 return false;
4616 }
4617 parcelableInfos.emplace_back(*info);
4618 }
4619
4620 return ERR_OK;
4621 }
4622
SendTransactCmd(BundleMgrInterfaceCode code,MessageParcel & data,MessageParcel & reply)4623 bool BundleMgrProxy::SendTransactCmd(BundleMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply)
4624 {
4625 MessageOption option(MessageOption::TF_SYNC);
4626
4627 sptr<IRemoteObject> remote = Remote();
4628 if (remote == nullptr) {
4629 APP_LOGE("fail send transact cmd %{public}d due remote object", code);
4630 return false;
4631 }
4632 int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
4633 if (result != NO_ERROR) {
4634 APP_LOGE("receive error transact code %{public}d in transact cmd %{public}d", result, code);
4635 return false;
4636 }
4637 return true;
4638 }
4639
SendTransactCmdWithLog(BundleMgrInterfaceCode code,MessageParcel & data,MessageParcel & reply)4640 bool BundleMgrProxy::SendTransactCmdWithLog(BundleMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply)
4641 {
4642 MessageOption option(MessageOption::TF_SYNC);
4643
4644 sptr<IRemoteObject> remote = Remote();
4645 if (remote == nullptr) {
4646 APP_LOGE("fail send transact cmd %{public}d due remote object", code);
4647 return false;
4648 }
4649 int32_t sptrRefCount = remote->GetSptrRefCount();
4650 int32_t wptrRefCount = remote->GetWptrRefCount();
4651 if (sptrRefCount <= 0 || wptrRefCount <= 0) {
4652 APP_LOGI("SendRequest before sptrRefCount: %{public}d wptrRefCount: %{public}d",
4653 sptrRefCount, wptrRefCount);
4654 }
4655 int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
4656 if (result != NO_ERROR) {
4657 APP_LOGE("receive error transact code %{public}d in transact cmd %{public}d", result, code);
4658 return false;
4659 }
4660 return true;
4661 }
4662
ParseStr(const char * buf,const int itemLen,int index,std::string & result)4663 bool ParseStr(const char *buf, const int itemLen, int index, std::string &result)
4664 {
4665 APP_LOGD("ParseStr itemLen:%{public}d index:%{public}d", itemLen, index);
4666 if (buf == nullptr || itemLen <= 0 || index < 0) {
4667 APP_LOGE("param invalid");
4668 return false;
4669 }
4670
4671 char item[itemLen + 1];
4672 if (strncpy_s(item, sizeof(item), buf + index, itemLen) != 0) {
4673 APP_LOGE("ParseStr failed due to strncpy_s error");
4674 return false;
4675 }
4676
4677 std::string str(item, 0, itemLen);
4678 result = str;
4679 return true;
4680 }
4681
4682 template<typename T>
GetParcelInfo(BundleMgrInterfaceCode code,MessageParcel & data,T & parcelInfo)4683 ErrCode BundleMgrProxy::GetParcelInfo(BundleMgrInterfaceCode code, MessageParcel &data, T &parcelInfo)
4684 {
4685 MessageParcel reply;
4686 if (!SendTransactCmd(code, data, reply)) {
4687 APP_LOGE("SendTransactCmd failed");
4688 return ERR_APPEXECFWK_PARCEL_ERROR;
4689 }
4690 ErrCode ret = reply.ReadInt32();
4691 if (ret != ERR_OK) {
4692 APP_LOGE("host reply err : %{public}d", ret);
4693 return ret;
4694 }
4695 return InnerGetParcelInfo<T>(reply, parcelInfo);
4696 }
4697
4698 template<typename T>
InnerGetParcelInfo(MessageParcel & reply,T & parcelInfo)4699 ErrCode BundleMgrProxy::InnerGetParcelInfo(MessageParcel &reply, T &parcelInfo)
4700 {
4701 size_t dataSize = reply.ReadUint32();
4702 void *buffer = nullptr;
4703 if (!GetData(buffer, dataSize, reply.ReadRawData(dataSize))) {
4704 APP_LOGE("GetData failed, dataSize : %{public}zu", dataSize);
4705 return ERR_APPEXECFWK_PARCEL_ERROR;
4706 }
4707
4708 MessageParcel tmpParcel;
4709 if (!tmpParcel.ParseFrom(reinterpret_cast<uintptr_t>(buffer), dataSize)) {
4710 APP_LOGE("ParseFrom failed");
4711 return ERR_APPEXECFWK_PARCEL_ERROR;
4712 }
4713
4714 std::unique_ptr<T> info(tmpParcel.ReadParcelable<T>());
4715 if (info == nullptr) {
4716 APP_LOGE("ReadParcelable failed");
4717 return ERR_APPEXECFWK_PARCEL_ERROR;
4718 }
4719 parcelInfo = *info;
4720 APP_LOGD("InnerGetParcelInfo success");
4721 return ERR_OK;
4722 }
4723
4724 template<typename T>
WriteParcelInfoIntelligent(const T & parcelInfo,MessageParcel & reply) const4725 ErrCode BundleMgrProxy::WriteParcelInfoIntelligent(const T &parcelInfo, MessageParcel &reply) const
4726 {
4727 Parcel tempParcel;
4728 (void)tempParcel.SetMaxCapacity(Constants::MAX_PARCEL_CAPACITY);
4729 if (!tempParcel.WriteParcelable(&parcelInfo)) {
4730 APP_LOGE("Write parcelable failed");
4731 return ERR_APPEXECFWK_PARCEL_ERROR;
4732 }
4733 size_t dataSize = tempParcel.GetDataSize();
4734 if (!reply.WriteUint32(dataSize)) {
4735 APP_LOGE("Write parcel size failed");
4736 return ERR_APPEXECFWK_PARCEL_ERROR;
4737 }
4738
4739 if (!reply.WriteRawData(reinterpret_cast<uint8_t *>(tempParcel.GetData()), dataSize)) {
4740 APP_LOGE("Write parcel raw data failed");
4741 return ERR_APPEXECFWK_PARCEL_ERROR;
4742 }
4743 return ERR_OK;
4744 }
4745
GetBigString(BundleMgrInterfaceCode code,MessageParcel & data,std::string & result)4746 ErrCode BundleMgrProxy::GetBigString(BundleMgrInterfaceCode code, MessageParcel &data, std::string &result)
4747 {
4748 MessageParcel reply;
4749 if (!SendTransactCmd(code, data, reply)) {
4750 APP_LOGE("SendTransactCmd failed");
4751 return ERR_APPEXECFWK_PARCEL_ERROR;
4752 }
4753 ErrCode ret = reply.ReadInt32();
4754 if (ret != ERR_OK) {
4755 APP_LOGE("host reply err %{public}d", ret);
4756 return ret;
4757 }
4758 return InnerGetBigString(reply, result);
4759 }
4760
InnerGetBigString(MessageParcel & reply,std::string & result)4761 ErrCode BundleMgrProxy::InnerGetBigString(MessageParcel &reply, std::string &result)
4762 {
4763 size_t dataSize = reply.ReadUint32();
4764 if (dataSize == 0) {
4765 APP_LOGE("Invalid data size");
4766 return ERR_APPEXECFWK_PARCEL_ERROR;
4767 }
4768 const char *data = reinterpret_cast<const char *>(reply.ReadRawData(dataSize));
4769 if (!data) {
4770 APP_LOGE("Fail read raw data length %{public}zu", dataSize);
4771 return ERR_APPEXECFWK_PARCEL_ERROR;
4772 }
4773 result = data;
4774 APP_LOGD("InnerGetBigString success");
4775 return ERR_OK;
4776 }
4777
CompileProcessAOT(const std::string & bundleName,const std::string & compileMode,bool isAllBundle,std::vector<std::string> & compileResults)4778 ErrCode BundleMgrProxy::CompileProcessAOT(const std::string &bundleName, const std::string &compileMode,
4779 bool isAllBundle, std::vector<std::string> &compileResults)
4780 {
4781 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4782 APP_LOGD("begin to compile");
4783 MessageParcel data;
4784 if (!data.WriteInterfaceToken(GetDescriptor())) {
4785 APP_LOGE("fail to compile due to write InterfaceToken fail");
4786 return ERR_APPEXECFWK_PARCEL_ERROR;
4787 }
4788 if (!data.WriteString(bundleName)) {
4789 APP_LOGE("fail to compile due to write bundleName fail");
4790 return ERR_APPEXECFWK_PARCEL_ERROR;
4791 }
4792 if (!data.WriteString(compileMode)) {
4793 APP_LOGE("fail to compile due to write compileMode fail");
4794 return ERR_APPEXECFWK_PARCEL_ERROR;
4795 }
4796 if (!data.WriteBool(isAllBundle)) {
4797 APP_LOGE("fail to compile due to write isAllBundle fail");
4798 return ERR_APPEXECFWK_PARCEL_ERROR;
4799 }
4800
4801 MessageParcel reply;
4802 if (!SendTransactCmd(BundleMgrInterfaceCode::COMPILE_PROCESSAOT, data, reply)) {
4803 APP_LOGE("fail to compile from server");
4804 return ERR_APPEXECFWK_PARCEL_ERROR;
4805 }
4806 ErrCode ret = reply.ReadInt32();
4807 if (ret != ERR_OK) {
4808 if (!reply.ReadStringVector(&compileResults)) {
4809 APP_LOGE("fail to get compile results from reply");
4810 return ERR_APPEXECFWK_PARCEL_ERROR;
4811 }
4812 }
4813 return ret;
4814 }
4815
CompileReset(const std::string & bundleName,bool isAllBundle)4816 ErrCode BundleMgrProxy::CompileReset(const std::string &bundleName, bool isAllBundle)
4817 {
4818 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4819 APP_LOGD("begin to reset");
4820 MessageParcel data;
4821 if (!data.WriteInterfaceToken(GetDescriptor())) {
4822 APP_LOGE("fail to reset due to write InterfaceToken fail");
4823 return ERR_APPEXECFWK_PARCEL_ERROR;
4824 }
4825 if (!data.WriteString(bundleName)) {
4826 APP_LOGE("fail to reset due to write bundleName fail");
4827 return ERR_APPEXECFWK_PARCEL_ERROR;
4828 }
4829 if (!data.WriteBool(isAllBundle)) {
4830 APP_LOGE("fail to reset due to write isAllBundle fail");
4831 return ERR_APPEXECFWK_PARCEL_ERROR;
4832 }
4833
4834 MessageParcel reply;
4835 if (!SendTransactCmd(BundleMgrInterfaceCode::COMPILE_RESET, data, reply)) {
4836 APP_LOGE("fail to reset from server");
4837 return ERR_APPEXECFWK_PARCEL_ERROR;
4838 }
4839 return ERR_OK;
4840 }
4841
CopyAp(const std::string & bundleName,bool isAllBundle,std::vector<std::string> & results)4842 ErrCode BundleMgrProxy::CopyAp(const std::string &bundleName, bool isAllBundle, std::vector<std::string> &results)
4843 {
4844 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4845 APP_LOGD("begin to CopyAp");
4846 MessageParcel data;
4847 if (!data.WriteInterfaceToken(GetDescriptor())) {
4848 APP_LOGE("fail to CopyAp due to write InterfaceToken fail");
4849 return ERR_APPEXECFWK_PARCEL_ERROR;
4850 }
4851 if (!data.WriteString(bundleName)) {
4852 APP_LOGE("fail to CopyAp due to write bundleName fail");
4853 return ERR_APPEXECFWK_PARCEL_ERROR;
4854 }
4855 if (!data.WriteBool(isAllBundle)) {
4856 APP_LOGE("fail to CopyAp due to write isAllBundle fail");
4857 return ERR_APPEXECFWK_PARCEL_ERROR;
4858 }
4859
4860 MessageParcel reply;
4861 if (!SendTransactCmd(BundleMgrInterfaceCode::COPY_AP, data, reply)) {
4862 APP_LOGE("fail to CopyAp from server");
4863 return ERR_APPEXECFWK_PARCEL_ERROR;
4864 }
4865 ErrCode res = reply.ReadInt32();
4866 if (res != ERR_OK) {
4867 APP_LOGE("host reply err: %{public}d", res);
4868 return res;
4869 }
4870 if (!reply.ReadStringVector(&results)) {
4871 APP_LOGE("fail to CopyAp from reply");
4872 return ERR_APPEXECFWK_PARCEL_ERROR;
4873 }
4874 APP_LOGD("end to CopyAp");
4875 return ERR_OK;
4876 }
4877
CanOpenLink(const std::string & link,bool & canOpen)4878 ErrCode BundleMgrProxy::CanOpenLink(
4879 const std::string &link, bool &canOpen)
4880 {
4881 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4882 MessageParcel data;
4883 if (!data.WriteInterfaceToken(GetDescriptor())) {
4884 APP_LOGE("write interfaceToken failed");
4885 return ERR_APPEXECFWK_PARCEL_ERROR;
4886 }
4887 if (!data.WriteString(link)) {
4888 APP_LOGE("write link failed");
4889 return ERR_APPEXECFWK_PARCEL_ERROR;
4890 }
4891
4892 MessageParcel reply;
4893 if (!SendTransactCmd(BundleMgrInterfaceCode::CAN_OPEN_LINK, data, reply)) {
4894 APP_LOGE("SendTransactCmd failed");
4895 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
4896 }
4897 ErrCode res = reply.ReadInt32();
4898 if (res != ERR_OK) {
4899 APP_LOGE("host reply err: %{public}d", res);
4900 return res;
4901 }
4902 canOpen = reply.ReadBool();
4903 return ERR_OK;
4904 }
4905
GetAllPreinstalledApplicationInfos(std::vector<PreinstalledApplicationInfo> & preinstalledApplicationInfos)4906 ErrCode BundleMgrProxy::GetAllPreinstalledApplicationInfos(
4907 std::vector<PreinstalledApplicationInfo> &preinstalledApplicationInfos)
4908 {
4909 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4910 APP_LOGD("Called");
4911 MessageParcel data;
4912 if (!data.WriteInterfaceToken(GetDescriptor())) {
4913 APP_LOGE("Fail to reset due to WriteInterfaceToken fail");
4914 return ERR_APPEXECFWK_PARCEL_ERROR;
4915 }
4916 return GetParcelableInfosWithErrCode<PreinstalledApplicationInfo>(
4917 BundleMgrInterfaceCode::GET_PREINSTALLED_APPLICATION_INFO, data, preinstalledApplicationInfos);
4918 }
4919
SwitchUninstallState(const std::string & bundleName,const bool & state,bool isNeedSendNotify)4920 ErrCode BundleMgrProxy::SwitchUninstallState(const std::string &bundleName, const bool &state,
4921 bool isNeedSendNotify)
4922 {
4923 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4924 MessageParcel data;
4925 if (!data.WriteInterfaceToken(GetDescriptor())) {
4926 APP_LOGE("write interfaceToken failed");
4927 return ERR_APPEXECFWK_PARCEL_ERROR;
4928 }
4929 if (!data.WriteString(bundleName)) {
4930 APP_LOGE("write bundleName failed");
4931 return ERR_APPEXECFWK_PARCEL_ERROR;
4932 }
4933 if (!data.WriteBool(state)) {
4934 APP_LOGE("write state failed");
4935 return ERR_APPEXECFWK_PARCEL_ERROR;
4936 }
4937 if (!data.WriteBool(isNeedSendNotify)) {
4938 APP_LOGE("write isNeedSendNotify failed");
4939 return ERR_APPEXECFWK_PARCEL_ERROR;
4940 }
4941 MessageParcel reply;
4942 if (!SendTransactCmd(BundleMgrInterfaceCode::SWITCH_UNINSTALL_STATE, data, reply)) {
4943 APP_LOGE("SendTransactCmd failed");
4944 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
4945 }
4946 return reply.ReadInt32();
4947 }
4948
QueryAbilityInfoByContinueType(const std::string & bundleName,const std::string & continueType,AbilityInfo & abilityInfo,int32_t userId)4949 ErrCode BundleMgrProxy::QueryAbilityInfoByContinueType(const std::string &bundleName,
4950 const std::string &continueType, AbilityInfo &abilityInfo, int32_t userId)
4951 {
4952 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4953 MessageParcel data;
4954 if (!data.WriteInterfaceToken(GetDescriptor())) {
4955 APP_LOGE("fail to QueryAbilityInfoByContinueType due to write interfaceToken fail");
4956 return ERR_APPEXECFWK_PARCEL_ERROR;
4957 }
4958 if (!data.WriteString(bundleName)) {
4959 APP_LOGE("fail to QueryAbilityInfoByContinueType due to write bundleName fail");
4960 return ERR_APPEXECFWK_PARCEL_ERROR;
4961 }
4962 if (!data.WriteString(continueType)) {
4963 APP_LOGE("fail to QueryAbilityInfoByContinueType due to write continueType fail");
4964 return ERR_APPEXECFWK_PARCEL_ERROR;
4965 }
4966 if (!data.WriteInt32(userId)) {
4967 APP_LOGE("fail to QueryAbilityInfoByContinueType due to write userId fail");
4968 return ERR_APPEXECFWK_PARCEL_ERROR;
4969 }
4970 return GetParcelableInfoWithErrCode<AbilityInfo>(
4971 BundleMgrInterfaceCode::QUERY_ABILITY_INFO_BY_CONTINUE_TYPE, data, abilityInfo);
4972 }
4973
QueryCloneAbilityInfo(const ElementName & element,int32_t flags,int32_t appIndex,AbilityInfo & abilityInfo,int32_t userId)4974 ErrCode BundleMgrProxy::QueryCloneAbilityInfo(const ElementName &element,
4975 int32_t flags, int32_t appIndex, AbilityInfo &abilityInfo, int32_t userId)
4976 {
4977 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
4978 MessageParcel data;
4979 if (!data.WriteInterfaceToken(GetDescriptor())) {
4980 LOG_E(BMS_TAG_QUERY, "write interfaceToken failed");
4981 return ERR_APPEXECFWK_PARCEL_ERROR;
4982 }
4983 if (!data.WriteParcelable(&element)) {
4984 LOG_E(BMS_TAG_QUERY, "write element fail");
4985 return ERR_APPEXECFWK_PARCEL_ERROR;
4986 }
4987 if (!data.WriteInt32(flags)) {
4988 LOG_E(BMS_TAG_QUERY, "write flags failed");
4989 return ERR_APPEXECFWK_PARCEL_ERROR;
4990 }
4991 if (!data.WriteInt32(appIndex)) {
4992 LOG_E(BMS_TAG_QUERY, "write appIndex failed");
4993 return ERR_APPEXECFWK_PARCEL_ERROR;
4994 }
4995 if (!data.WriteInt32(userId)) {
4996 LOG_E(BMS_TAG_QUERY, "write userId failed");
4997 return ERR_APPEXECFWK_PARCEL_ERROR;
4998 }
4999 return GetParcelableInfoWithErrCode<AbilityInfo>(
5000 BundleMgrInterfaceCode::GET_CLONE_ABILITY_INFO, data, abilityInfo);
5001 }
5002
GetCloneBundleInfo(const std::string & bundleName,int32_t flags,int32_t appIndex,BundleInfo & bundleInfo,int32_t userId)5003 ErrCode BundleMgrProxy::GetCloneBundleInfo(const std::string &bundleName, int32_t flags, int32_t appIndex,
5004 BundleInfo &bundleInfo, int32_t userId)
5005 {
5006 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5007 APP_LOGD("begin to GetCloneBundleInfo of %{public}s", bundleName.c_str());
5008 MessageParcel data;
5009 if (!data.WriteInterfaceToken(GetDescriptor())) {
5010 APP_LOGE("fail to GetCloneBundleInfo due to write InterfaceToken fail");
5011 return ERR_APPEXECFWK_PARCEL_ERROR;
5012 }
5013 if (!data.WriteString(bundleName)) {
5014 APP_LOGE("failed to GetCloneBundleInfo due to write bundleName fail");
5015 return ERR_APPEXECFWK_PARCEL_ERROR;
5016 }
5017 if (!data.WriteInt32(flags)) {
5018 APP_LOGE("fail to GetCloneBundleInfo due to write flag fail");
5019 return ERR_APPEXECFWK_PARCEL_ERROR;
5020 }
5021 if (!data.WriteInt32(appIndex)) {
5022 APP_LOGE("fail to GetCloneBundleInfo due to write appIndex fail");
5023 return ERR_APPEXECFWK_PARCEL_ERROR;
5024 }
5025 if (!data.WriteInt32(userId)) {
5026 APP_LOGE("fail to GetCloneBundleInfo due to write userId fail");
5027 return ERR_APPEXECFWK_PARCEL_ERROR;
5028 }
5029
5030 return GetParcelableInfoWithErrCode<BundleInfo>(
5031 BundleMgrInterfaceCode::GET_CLONE_BUNDLE_INFO, data, bundleInfo);
5032 }
5033
GetCloneAppIndexes(const std::string & bundleName,std::vector<int32_t> & appIndexes,int32_t userId)5034 ErrCode BundleMgrProxy::GetCloneAppIndexes(const std::string &bundleName, std::vector<int32_t> &appIndexes,
5035 int32_t userId)
5036 {
5037 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5038 APP_LOGD("begin to GetCloneAppIndexes of %{public}s", bundleName.c_str());
5039 MessageParcel data;
5040 if (!data.WriteInterfaceToken(GetDescriptor())) {
5041 APP_LOGE("fail to GetCloneAppIndexes due to write InterfaceToken fail");
5042 return ERR_APPEXECFWK_PARCEL_ERROR;
5043 }
5044 if (!data.WriteString(bundleName)) {
5045 APP_LOGE("failed to GetCloneAppIndexes due to write bundleName fail");
5046 return ERR_APPEXECFWK_PARCEL_ERROR;
5047 }
5048 if (!data.WriteInt32(userId)) {
5049 APP_LOGE("fail to GetCloneAppIndexes due to write userId fail");
5050 return ERR_APPEXECFWK_PARCEL_ERROR;
5051 }
5052
5053 MessageParcel reply;
5054 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_CLONE_APP_INDEXES, data, reply)) {
5055 APP_LOGE("fail to GetCloneAppIndexes from server");
5056 return ERR_APPEXECFWK_PARCEL_ERROR;
5057 }
5058 ErrCode ret = reply.ReadInt32();
5059 if (ret != ERR_OK) {
5060 return ret;
5061 }
5062 if (!reply.ReadInt32Vector(&appIndexes)) {
5063 APP_LOGE("fail to GetCloneAppIndexes from reply");
5064 return ERR_APPEXECFWK_PARCEL_ERROR;
5065 }
5066 return ret;
5067 }
5068
GetLaunchWant(Want & want)5069 ErrCode BundleMgrProxy::GetLaunchWant(Want &want)
5070 {
5071 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5072 APP_LOGD("begin to GetLaunchWant");
5073 MessageParcel data;
5074 if (!data.WriteInterfaceToken(GetDescriptor())) {
5075 APP_LOGE("write InterfaceToken fail");
5076 return ERR_APPEXECFWK_PARCEL_ERROR;
5077 }
5078
5079 return GetParcelableInfoWithErrCode<Want>(BundleMgrInterfaceCode::GET_LAUNCH_WANT, data, want);
5080 }
5081
QueryCloneExtensionAbilityInfoWithAppIndex(const ElementName & elementName,int32_t flags,int32_t appIndex,ExtensionAbilityInfo & extensionAbilityInfo,int32_t userId)5082 ErrCode BundleMgrProxy::QueryCloneExtensionAbilityInfoWithAppIndex(const ElementName &elementName,
5083 int32_t flags, int32_t appIndex, ExtensionAbilityInfo &extensionAbilityInfo, int32_t userId)
5084 {
5085 MessageParcel data;
5086 if (!data.WriteInterfaceToken(GetDescriptor())) {
5087 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfo write InterfaceToken fail");
5088 return ERR_APPEXECFWK_PARCEL_ERROR;
5089 }
5090 if (!data.WriteParcelable(&elementName)) {
5091 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfo write elementName fail");
5092 return ERR_APPEXECFWK_PARCEL_ERROR;
5093 }
5094 if (!data.WriteInt32(flags)) {
5095 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfo write flag fail");
5096 return ERR_APPEXECFWK_PARCEL_ERROR;
5097 }
5098 if (!data.WriteInt32(appIndex)) {
5099 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfo write appIndex fail");
5100 return ERR_APPEXECFWK_PARCEL_ERROR;
5101 }
5102 if (!data.WriteInt32(userId)) {
5103 LOG_E(BMS_TAG_QUERY, "QueryExtensionAbilityInfo write userId fail");
5104 return ERR_APPEXECFWK_PARCEL_ERROR;
5105 }
5106
5107 return GetParcelableInfoWithErrCode<ExtensionAbilityInfo>(
5108 BundleMgrInterfaceCode::QUERY_CLONE_EXTENSION_ABILITY_INFO_WITH_APP_INDEX, data, extensionAbilityInfo);
5109 }
5110
GetSignatureInfoByBundleName(const std::string & bundleName,SignatureInfo & signatureInfo)5111 ErrCode BundleMgrProxy::GetSignatureInfoByBundleName(const std::string &bundleName, SignatureInfo &signatureInfo)
5112 {
5113 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5114 APP_LOGD("begin %{public}s", bundleName.c_str());
5115 MessageParcel data;
5116 if (!data.WriteInterfaceToken(GetDescriptor())) {
5117 APP_LOGE("write InterfaceToken fail");
5118 return ERR_APPEXECFWK_PARCEL_ERROR;
5119 }
5120 if (!data.WriteString(bundleName)) {
5121 APP_LOGE("write bundleName fail");
5122 return ERR_APPEXECFWK_PARCEL_ERROR;
5123 }
5124 return GetParcelInfoIntelligent<SignatureInfo>(BundleMgrInterfaceCode::GET_SIGNATURE_INFO, data, signatureInfo);
5125 }
5126
AddDesktopShortcutInfo(const ShortcutInfo & shortcutInfo,int32_t userId)5127 ErrCode BundleMgrProxy::AddDesktopShortcutInfo(const ShortcutInfo &shortcutInfo, int32_t userId)
5128 {
5129 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5130 MessageParcel data;
5131 if (!data.WriteInterfaceToken(GetDescriptor())) {
5132 APP_LOGE("AddDesktopShortcutInfo write InterfaceToken fail");
5133 return ERR_APPEXECFWK_PARCEL_ERROR;
5134 }
5135 auto ret = WriteParcelInfoIntelligent(shortcutInfo, data);
5136 if (ret != ERR_OK) {
5137 APP_LOGE("AddDesktopShortcutInfo write ParcelInfo fail");
5138 return ERR_APPEXECFWK_PARCEL_ERROR;
5139 }
5140 if (!data.WriteInt32(userId)) {
5141 APP_LOGE("AddDesktopShortcutInfo write userId fail");
5142 return ERR_APPEXECFWK_PARCEL_ERROR;
5143 }
5144 MessageParcel reply;
5145 if (!SendTransactCmd(BundleMgrInterfaceCode::ADD_DESKTOP_SHORTCUT_INFO, data, reply)) {
5146 APP_LOGE("SendTransactCmd failed");
5147 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
5148 }
5149 return reply.ReadInt32();
5150 }
5151
DeleteDesktopShortcutInfo(const ShortcutInfo & shortcutInfo,int32_t userId)5152 ErrCode BundleMgrProxy::DeleteDesktopShortcutInfo(const ShortcutInfo &shortcutInfo, int32_t userId)
5153 {
5154 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5155 MessageParcel data;
5156 if (!data.WriteInterfaceToken(GetDescriptor())) {
5157 APP_LOGE("DeleteDesktopShortcutInfo write InterfaceToken fail");
5158 return ERR_APPEXECFWK_PARCEL_ERROR;
5159 }
5160 auto ret = WriteParcelInfoIntelligent(shortcutInfo, data);
5161 if (ret != ERR_OK) {
5162 APP_LOGE("DeleteDesktopShortcutInfo write ParcelInfo fail");
5163 return ERR_APPEXECFWK_PARCEL_ERROR;
5164 }
5165 if (!data.WriteInt32(userId)) {
5166 APP_LOGE("DeleteDesktopShortcutInfo write userId fail");
5167 return ERR_APPEXECFWK_PARCEL_ERROR;
5168 }
5169 MessageParcel reply;
5170 if (!SendTransactCmd(BundleMgrInterfaceCode::DELETE_DESKTOP_SHORTCUT_INFO, data, reply)) {
5171 APP_LOGE("SendTransactCmd failed");
5172 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
5173 }
5174 return reply.ReadInt32();
5175 }
5176
GetAllDesktopShortcutInfo(int32_t userId,std::vector<ShortcutInfo> & shortcutInfos)5177 ErrCode BundleMgrProxy::GetAllDesktopShortcutInfo(int32_t userId, std::vector<ShortcutInfo> &shortcutInfos)
5178 {
5179 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5180 MessageParcel data;
5181 if (!data.WriteInterfaceToken(GetDescriptor())) {
5182 APP_LOGE("GetAllDesktopShortcutInfo write InterfaceToken fail");
5183 return ERR_APPEXECFWK_PARCEL_ERROR;
5184 }
5185 if (!data.WriteInt32(userId)) {
5186 APP_LOGE("GetAllDesktopShortcutInfo write bundleName fail");
5187 return ERR_APPEXECFWK_PARCEL_ERROR;
5188 }
5189 return GetVectorFromParcelIntelligentWithErrCode<ShortcutInfo>(
5190 BundleMgrInterfaceCode::GET_ALL_DESKTOP_SHORTCUT_INFO, data, shortcutInfos);
5191 }
5192
GetOdidByBundleName(const std::string & bundleName,std::string & odid)5193 ErrCode BundleMgrProxy::GetOdidByBundleName(const std::string &bundleName, std::string &odid)
5194 {
5195 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5196 APP_LOGD("GetOdidByBundleName Called");
5197 MessageParcel data;
5198 if (!data.WriteInterfaceToken(GetDescriptor())) {
5199 APP_LOGE("Write interfaceToken failed");
5200 return ERR_APPEXECFWK_PARCEL_ERROR;
5201 }
5202 if (!data.WriteString(bundleName)) {
5203 APP_LOGE("Write bundleName failed");
5204 return ERR_APPEXECFWK_PARCEL_ERROR;
5205 }
5206
5207 MessageParcel reply;
5208 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_ODID_BY_BUNDLENAME, data, reply)) {
5209 return ERR_APPEXECFWK_PARCEL_ERROR;
5210 }
5211 auto ret = reply.ReadInt32();
5212 if (ret == ERR_OK) {
5213 odid = reply.ReadString();
5214 }
5215 APP_LOGD("GetOdidByBundleName ret: %{public}d, odid: %{private}s", ret, odid.c_str());
5216 return ret;
5217 }
5218
GetBundleInfosForContinuation(int32_t flags,std::vector<BundleInfo> & bundleInfos,int32_t userId)5219 bool BundleMgrProxy::GetBundleInfosForContinuation(
5220 int32_t flags, std::vector<BundleInfo> &bundleInfos, int32_t userId)
5221 {
5222 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5223 LOG_D(BMS_TAG_QUERY, "begin to get bundle infos");
5224 MessageParcel data;
5225 if (!data.WriteInterfaceToken(GetDescriptor())) {
5226 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfosForContinuation due to write InterfaceToken fail");
5227 return false;
5228 }
5229 if (!data.WriteInt32(flags)) {
5230 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfosForContinuation due to write flag fail");
5231 return false;
5232 }
5233 if (!data.WriteInt32(userId)) {
5234 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfo due to write userId fail");
5235 return false;
5236 }
5237 if (!GetVectorFromParcelIntelligent<BundleInfo>(
5238 BundleMgrInterfaceCode::GET_BUNDLE_INFOS_FOR_CONTINUATION, data, bundleInfos)) {
5239 LOG_E(BMS_TAG_QUERY, "fail to GetBundleInfosForContinuation from server");
5240 return false;
5241 }
5242 return true;
5243 }
5244
GetContinueBundleNames(const std::string & continueBundleName,std::vector<std::string> & bundleNames,int32_t userId)5245 ErrCode BundleMgrProxy::GetContinueBundleNames(
5246 const std::string &continueBundleName, std::vector<std::string> &bundleNames, int32_t userId)
5247 {
5248 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5249 MessageParcel data;
5250 if (!data.WriteInterfaceToken(GetDescriptor())) {
5251 APP_LOGE("Write interface token fail");
5252 return ERR_APPEXECFWK_PARCEL_ERROR;
5253 }
5254 if (!data.WriteString(continueBundleName)) {
5255 APP_LOGE("Write bundle name fail");
5256 return ERR_APPEXECFWK_PARCEL_ERROR;
5257 }
5258 if (!data.WriteInt32(userId)) {
5259 APP_LOGE("Write user id fail");
5260 return ERR_APPEXECFWK_PARCEL_ERROR;
5261 }
5262
5263 MessageParcel reply;
5264 if (!SendTransactCmd(BundleMgrInterfaceCode::GET_CONTINUE_BUNDLE_NAMES, data, reply)) {
5265 APP_LOGE("Fail to GetContinueBundleNames from server");
5266 return ERR_APPEXECFWK_PARCEL_ERROR;
5267 }
5268 auto ret = reply.ReadInt32();
5269 if (ret != ERR_OK) {
5270 APP_LOGE("Reply err : %{public}d", ret);
5271 return ret;
5272 }
5273 if (!reply.ReadStringVector(&bundleNames)) {
5274 APP_LOGE("Fail to GetContinueBundleNames from reply");
5275 return ERR_APPEXECFWK_PARCEL_ERROR;
5276 }
5277 return ERR_OK;
5278 }
5279
IsBundleInstalled(const std::string & bundleName,int32_t userId,int32_t appIndex,bool & isInstalled)5280 ErrCode BundleMgrProxy::IsBundleInstalled(const std::string &bundleName, int32_t userId,
5281 int32_t appIndex, bool &isInstalled)
5282 {
5283 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
5284 MessageParcel data;
5285 if (!data.WriteInterfaceToken(GetDescriptor())) {
5286 APP_LOGE("Write interface token fail");
5287 return ERR_APPEXECFWK_PARCEL_ERROR;
5288 }
5289 if (!data.WriteString(bundleName)) {
5290 APP_LOGE("Write bundle name fail");
5291 return ERR_APPEXECFWK_PARCEL_ERROR;
5292 }
5293 if (!data.WriteInt32(userId)) {
5294 APP_LOGE("Write user id fail");
5295 return ERR_APPEXECFWK_PARCEL_ERROR;
5296 }
5297 if (!data.WriteInt32(appIndex)) {
5298 APP_LOGE("Write appIndex id fail");
5299 return ERR_APPEXECFWK_PARCEL_ERROR;
5300 }
5301
5302 MessageParcel reply;
5303 if (!SendTransactCmd(BundleMgrInterfaceCode::IS_BUNDLE_INSTALLED, data, reply)) {
5304 APP_LOGE("Fail to IsBundleInstalled from server");
5305 return ERR_BUNDLE_MANAGER_IPC_TRANSACTION;
5306 }
5307 auto ret = reply.ReadInt32();
5308 if (ret != ERR_OK) {
5309 APP_LOGE("IsBundleInstalled err: %{public}d", ret);
5310 return ret;
5311 }
5312 isInstalled = reply.ReadBool();
5313 return ERR_OK;
5314 }
5315 } // namespace AppExecFwk
5316 } // namespace OHOS
5317