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