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