• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_installer_host.h"
17 
18 #include "ipc_skeleton.h"
19 #include "ipc_types.h"
20 #include "string_ex.h"
21 
22 #include "app_log_wrapper.h"
23 #include "appexecfwk_errors.h"
24 #include "bundle_constants.h"
25 #include "bundle_permission_mgr.h"
26 #include "bundle_sandbox_app_helper.h"
27 #include "bundle_util.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
31 namespace {
32 const std::string INSTALL_THREAD = "InstallThread";
33 const std::string GET_MANAGER_FAIL = "fail to get bundle installer manager";
34 int32_t INVALID_APP_INDEX = 0;
35 int32_t LOWER_DLP_TYPE_BOUND = 0;
36 int32_t UPPER_DLP_TYPE_BOUND = 3;
37 }  // namespace
38 
BundleInstallerHost()39 BundleInstallerHost::BundleInstallerHost()
40 {
41     APP_LOGI("create bundle installer host instance");
42 }
43 
~BundleInstallerHost()44 BundleInstallerHost::~BundleInstallerHost()
45 {
46     APP_LOGI("destroy bundle installer host instance");
47 }
48 
Init()49 bool BundleInstallerHost::Init()
50 {
51     APP_LOGD("begin to init");
52     auto installRunner = EventRunner::Create(INSTALL_THREAD);
53     if (!installRunner) {
54         APP_LOGE("create install runner fail");
55         return false;
56     }
57     manager_ = std::make_shared<BundleInstallerManager>(installRunner);
58     APP_LOGD("init successfully");
59     return true;
60 }
61 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)62 int BundleInstallerHost::OnRemoteRequest(
63     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
64 {
65     APP_LOGD("bundle installer host onReceived message, the message code is %{public}u", code);
66     std::u16string descripter = GetDescriptor();
67     std::u16string remoteDescripter = data.ReadInterfaceToken();
68     if (descripter != remoteDescripter) {
69         APP_LOGE("fail to write reply message in bundle mgr host due to the reply is nullptr");
70         return OBJECT_NULL;
71     }
72 
73     switch (code) {
74         case IBundleInstaller::Message::INSTALL:
75             HandleInstallMessage(data);
76             break;
77         case IBundleInstaller::Message::INSTALL_MULTIPLE_HAPS:
78             HandleInstallMultipleHapsMessage(data);
79             break;
80         case IBundleInstaller::Message::UNINSTALL:
81             HandleUninstallMessage(data);
82             break;
83         case IBundleInstaller::Message::UNINSTALL_MODULE:
84             HandleUninstallModuleMessage(data);
85             break;
86         case IBundleInstaller::Message::RECOVER:
87             HandleRecoverMessage(data);
88             break;
89         case IBundleInstaller::Message::INSTALL_SANDBOX_APP:
90             HandleInstallSandboxApp(data, reply);
91             break;
92         case IBundleInstaller::Message::UNINSTALL_SANDBOX_APP:
93             HandleUninstallSandboxApp(data, reply);
94             break;
95         case IBundleInstaller::Message::CREATE_STREAM_INSTALLER:
96             HandleCreateStreamInstaller(data, reply);
97             break;
98         case IBundleInstaller::Message::DESTORY_STREAM_INSTALLER:
99             HandleDestoryBundleStreamInstaller(data, reply);
100             break;
101         default:
102             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
103     }
104     return NO_ERROR;
105 }
106 
HandleInstallMessage(Parcel & data)107 void BundleInstallerHost::HandleInstallMessage(Parcel &data)
108 {
109     APP_LOGD("handle install message");
110     std::string bundlePath = Str16ToStr8(data.ReadString16());
111     std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
112     if (installParam == nullptr) {
113         APP_LOGE("ReadParcelable<InstallParam> failed");
114         return;
115     }
116     sptr<IRemoteObject> object = data.ReadObject<IRemoteObject>();
117     if (object == nullptr) {
118         APP_LOGE("read failed");
119         return;
120     }
121     sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
122 
123     Install(bundlePath, *installParam, statusReceiver);
124     APP_LOGD("handle install message finished");
125 }
126 
HandleRecoverMessage(Parcel & data)127 void BundleInstallerHost::HandleRecoverMessage(Parcel &data)
128 {
129     APP_LOGD("handle install message by bundleName");
130     std::string bundleName = Str16ToStr8(data.ReadString16());
131     std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
132     if (installParam == nullptr) {
133         APP_LOGE("ReadParcelable<InstallParam> failed");
134         return;
135     }
136     sptr<IRemoteObject> object = data.ReadObject<IRemoteObject>();
137     if (object == nullptr) {
138         APP_LOGE("read failed");
139         return;
140     }
141     sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
142 
143     Recover(bundleName, *installParam, statusReceiver);
144     APP_LOGD("handle install message by bundleName finished");
145 }
146 
HandleInstallMultipleHapsMessage(Parcel & data)147 void BundleInstallerHost::HandleInstallMultipleHapsMessage(Parcel &data)
148 {
149     APP_LOGD("handle install multiple haps message");
150     int32_t size = data.ReadInt32();
151     if (size > Constants::MAX_HAP_NUMBER) {
152         APP_LOGE("bundle path size is greater than the max hap number 128");
153         return;
154     }
155     std::vector<std::string> pathVec;
156     for (int i = 0; i < size; ++i) {
157         pathVec.emplace_back(Str16ToStr8(data.ReadString16()));
158     }
159     if (size == 0 || pathVec.empty()) {
160         APP_LOGE("inputted bundlepath vector is empty");
161         return;
162     }
163     std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
164     if (installParam == nullptr) {
165         APP_LOGE("ReadParcelable<InstallParam> failed");
166         return;
167     }
168     sptr<IRemoteObject> object = data.ReadObject<IRemoteObject>();
169     if (object == nullptr) {
170         APP_LOGE("read failed");
171         return;
172     }
173     sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
174 
175     Install(pathVec, *installParam, statusReceiver);
176     APP_LOGD("handle install multiple haps finished");
177 }
178 
HandleUninstallMessage(Parcel & data)179 void BundleInstallerHost::HandleUninstallMessage(Parcel &data)
180 {
181     APP_LOGD("handle uninstall message");
182     std::string bundleName = Str16ToStr8(data.ReadString16());
183     std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
184     if (installParam == nullptr) {
185         APP_LOGE("ReadParcelable<InstallParam> failed");
186         return;
187     }
188     sptr<IRemoteObject> object = data.ReadObject<IRemoteObject>();
189     if (object == nullptr) {
190         APP_LOGE("read failed");
191         return;
192     }
193     sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
194 
195     Uninstall(bundleName, *installParam, statusReceiver);
196     APP_LOGD("handle uninstall message finished");
197 }
198 
HandleUninstallModuleMessage(Parcel & data)199 void BundleInstallerHost::HandleUninstallModuleMessage(Parcel &data)
200 {
201     APP_LOGD("handle uninstall module message");
202     std::string bundleName = Str16ToStr8(data.ReadString16());
203     std::string modulePackage = Str16ToStr8(data.ReadString16());
204     std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
205     if (installParam == nullptr) {
206         APP_LOGE("ReadParcelable<InstallParam> failed");
207         return;
208     }
209     sptr<IRemoteObject> object = data.ReadObject<IRemoteObject>();
210     if (object == nullptr) {
211         APP_LOGE("read failed");
212         return;
213     }
214     sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
215 
216     Uninstall(bundleName, modulePackage, *installParam, statusReceiver);
217     APP_LOGD("handle uninstall message finished");
218 }
219 
HandleInstallSandboxApp(Parcel & data,Parcel & reply)220 void BundleInstallerHost::HandleInstallSandboxApp(Parcel &data, Parcel &reply)
221 {
222     APP_LOGD("handle install sandbox app message");
223     std::string bundleName = Str16ToStr8(data.ReadString16());
224     int32_t dplType = data.ReadInt32();
225     int32_t userId = data.ReadInt32();
226     int32_t appIndex = Constants::INITIAL_APP_INDEX;
227     auto ret = InstallSandboxApp(bundleName, dplType, userId, appIndex);
228     if (!reply.WriteInt32(ret)) {
229         APP_LOGE("write failed");
230     }
231     if (ret == ERR_OK && !reply.WriteInt32(appIndex)) {
232         APP_LOGE("write failed");
233     }
234     APP_LOGD("handle install sandbox app message finished");
235 }
236 
HandleUninstallSandboxApp(Parcel & data,Parcel & reply)237 void BundleInstallerHost::HandleUninstallSandboxApp(Parcel &data, Parcel &reply)
238 {
239     APP_LOGD("handle install sandbox app message");
240     std::string bundleName = Str16ToStr8(data.ReadString16());
241     int32_t appIndex = data.ReadInt32();
242     int32_t userId = data.ReadInt32();
243     auto ret = UninstallSandboxApp(bundleName, appIndex, userId);
244     if (!reply.WriteInt32(ret)) {
245         APP_LOGE("write failed");
246     }
247     APP_LOGD("handle install sandbox app message finished");
248 }
249 
HandleCreateStreamInstaller(Parcel & data,Parcel & reply)250 void BundleInstallerHost::HandleCreateStreamInstaller(Parcel &data, Parcel &reply)
251 {
252     APP_LOGD("handle create stream installer message begin");
253     std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
254     if (installParam == nullptr) {
255         APP_LOGE("ReadParcelable<InstallParam> failed");
256         return;
257     }
258     sptr<IRemoteObject> object = data.ReadObject<IRemoteObject>();
259     if (object == nullptr) {
260         reply.WriteBool(false);
261         APP_LOGE("read receiver failed");
262         return;
263     }
264     sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
265     if (statusReceiver == nullptr) {
266         reply.WriteBool(false);
267         APP_LOGE("cast remote object to status receiver error");
268         return;
269     }
270 
271     sptr<IBundleStreamInstaller> streamInstaller = CreateStreamInstaller(*installParam, statusReceiver);
272     if (streamInstaller == nullptr) {
273         if (!reply.WriteBool(false)) {
274             APP_LOGE("write result failed");
275         }
276         return;
277     }
278     if (!reply.WriteBool(true)) {
279         APP_LOGE("write result failed");
280         return;
281     }
282     if (!reply.WriteUint32(streamInstaller->GetInstallerId())) {
283         APP_LOGE("write stream installe id failed");
284         return;
285     }
286     if (!reply.WriteRemoteObject(streamInstaller->AsObject())) {
287         APP_LOGE("write stream installer remote object failed");
288         return;
289     }
290 
291     std::lock_guard<std::mutex> lock(streamInstallMutex_);
292     streamInstallers_.emplace_back(streamInstaller);
293     APP_LOGD("handle create stream installer message finish");
294 }
295 
HandleDestoryBundleStreamInstaller(Parcel & data,Parcel & reply)296 void BundleInstallerHost::HandleDestoryBundleStreamInstaller(Parcel &data, Parcel &reply)
297 {
298     APP_LOGD("handle destory stream installer message begin");
299     uint32_t installeId = data.ReadUint32();
300     DestoryBundleStreamInstaller(installeId);
301     APP_LOGD("handle destoy stream installer message finish");
302 }
303 
304 
Install(const std::string & bundleFilePath,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)305 bool BundleInstallerHost::Install(
306     const std::string &bundleFilePath, const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
307 {
308     if (!CheckBundleInstallerManager(statusReceiver)) {
309         APP_LOGE("statusReceiver invalid");
310         return false;
311     }
312     if (!BundlePermissionMgr::VerifySystemApp(Constants::API_VERSION_NINE)) {
313         APP_LOGE("install permission denied");
314         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
315         return false;
316     }
317     if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_INSTALL_BUNDLE)) {
318         APP_LOGE("install permission denied");
319         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
320         return false;
321     }
322 
323     manager_->CreateInstallTask(bundleFilePath, installParam, statusReceiver);
324     return true;
325 }
326 
Install(const std::vector<std::string> & bundleFilePaths,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)327 bool BundleInstallerHost::Install(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam,
328     const sptr<IStatusReceiver> &statusReceiver)
329 {
330     if (!CheckBundleInstallerManager(statusReceiver)) {
331         APP_LOGE("statusReceiver invalid");
332         return false;
333     }
334     if (!BundlePermissionMgr::VerifySystemApp(Constants::API_VERSION_NINE)) {
335         APP_LOGE("install permission denied");
336         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
337         return false;
338     }
339     if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_INSTALL_BUNDLE)) {
340         APP_LOGE("install permission denied");
341         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
342         return false;
343     }
344 
345     manager_->CreateInstallTask(bundleFilePaths, installParam, statusReceiver);
346     return true;
347 }
348 
Recover(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)349 bool BundleInstallerHost::Recover(
350     const std::string &bundleName, const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
351 {
352     if (!CheckBundleInstallerManager(statusReceiver)) {
353         APP_LOGE("statusReceiver invalid");
354         return false;
355     }
356     if (!BundlePermissionMgr::VerifySystemApp(Constants::API_VERSION_NINE)) {
357         APP_LOGE("install permission denied");
358         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
359         return false;
360     }
361     if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_INSTALL_BUNDLE)) {
362         APP_LOGE("install permission denied");
363         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
364         return false;
365     }
366     manager_->CreateRecoverTask(bundleName, CheckInstallParam(installParam), statusReceiver);
367     return true;
368 }
369 
Uninstall(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)370 bool BundleInstallerHost::Uninstall(
371     const std::string &bundleName, const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
372 {
373     if (!CheckBundleInstallerManager(statusReceiver)) {
374         APP_LOGE("statusReceiver invalid");
375         return false;
376     }
377     if (!BundlePermissionMgr::VerifySystemApp(Constants::API_VERSION_NINE)) {
378         APP_LOGE("install permission denied");
379         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
380         return false;
381     }
382     if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_INSTALL_BUNDLE)) {
383         APP_LOGE("uninstall permission denied");
384         statusReceiver->OnFinished(ERR_APPEXECFWK_UNINSTALL_PERMISSION_DENIED, "");
385         return false;
386     }
387     manager_->CreateUninstallTask(bundleName, CheckInstallParam(installParam), statusReceiver);
388     return true;
389 }
390 
Uninstall(const std::string & bundleName,const std::string & modulePackage,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)391 bool BundleInstallerHost::Uninstall(const std::string &bundleName, const std::string &modulePackage,
392     const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
393 {
394     if (!CheckBundleInstallerManager(statusReceiver)) {
395         APP_LOGE("statusReceiver invalid");
396         return false;
397     }
398     if (!BundlePermissionMgr::VerifySystemApp(Constants::API_VERSION_NINE)) {
399         APP_LOGE("install permission denied");
400         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
401         return false;
402     }
403     if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_INSTALL_BUNDLE)) {
404         APP_LOGE("uninstall permission denied");
405         statusReceiver->OnFinished(ERR_APPEXECFWK_UNINSTALL_PERMISSION_DENIED, "");
406         return false;
407     }
408     manager_->CreateUninstallTask(
409         bundleName, modulePackage, CheckInstallParam(installParam), statusReceiver);
410     return true;
411 }
412 
InstallByBundleName(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)413 bool BundleInstallerHost::InstallByBundleName(const std::string &bundleName,
414     const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
415 {
416     if (!CheckBundleInstallerManager(statusReceiver)) {
417         APP_LOGE("statusReceiver invalid");
418         return false;
419     }
420     if (!BundlePermissionMgr::VerifySystemApp(Constants::API_VERSION_NINE)) {
421         APP_LOGE("install permission denied");
422         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
423         return false;
424     }
425     if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_INSTALL_BUNDLE)) {
426         APP_LOGE("install permission denied");
427         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
428         return false;
429     }
430 
431     manager_->CreateInstallByBundleNameTask(bundleName, CheckInstallParam(installParam), statusReceiver);
432     return true;
433 }
434 
InstallSandboxApp(const std::string & bundleName,int32_t dplType,int32_t userId,int32_t & appIndex)435 ErrCode BundleInstallerHost::InstallSandboxApp(const std::string &bundleName, int32_t dplType, int32_t userId,
436     int32_t &appIndex)
437 {
438     if (bundleName.empty() || dplType <= LOWER_DLP_TYPE_BOUND || dplType >= UPPER_DLP_TYPE_BOUND) {
439         APP_LOGE("install sandbox failed due to error parameters");
440         return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
441     }
442     if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_INSTALL_BUNDLE)) {
443         APP_LOGE("InstallSandboxApp permission denied");
444         return ERR_APPEXECFWK_PERMISSION_DENIED;
445     }
446     auto helper = DelayedSingleton<BundleSandboxAppHelper>::GetInstance();
447     if (helper == nullptr) {
448         return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
449     }
450     auto res = helper->InstallSandboxApp(bundleName, dplType, userId, appIndex);
451     if (res != ERR_OK) {
452         APP_LOGE("install sandbox failed due to error code : %{public}d", res);
453     }
454     return res;
455 }
456 
UninstallSandboxApp(const std::string & bundleName,int32_t appIndex,int32_t userId)457 ErrCode BundleInstallerHost::UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId)
458 {
459     // check bundle name
460     if (bundleName.empty()) {
461         APP_LOGE("install sandbox failed due to empty bundleName");
462         return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
463     }
464     // check appIndex
465     if (appIndex <= INVALID_APP_INDEX || appIndex > Constants::MAX_APP_INDEX) {
466         APP_LOGE("the appIndex %{public}d is invalid", appIndex);
467         return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
468     }
469     if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_INSTALL_BUNDLE)) {
470         APP_LOGE("UninstallSandboxApp permission denied");
471         return ERR_APPEXECFWK_PERMISSION_DENIED;
472     }
473     auto helper = DelayedSingleton<BundleSandboxAppHelper>::GetInstance();
474     if (helper == nullptr) {
475         return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
476     }
477     auto res = helper->UninstallSandboxApp(bundleName, appIndex, userId);
478     if (res != ERR_OK) {
479         APP_LOGE("uninstall sandbox failed due to error code : %{public}d", res);
480     }
481     return res;
482 }
483 
StreamInstall(const std::vector<std::string> & bundleFilePaths,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)484 ErrCode BundleInstallerHost::StreamInstall(const std::vector<std::string> &bundleFilePaths,
485     const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
486 {
487     return ERR_OK;
488 }
489 
CreateStreamInstaller(const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)490 sptr<IBundleStreamInstaller> BundleInstallerHost::CreateStreamInstaller(const InstallParam &installParam,
491     const sptr<IStatusReceiver> &statusReceiver)
492 {
493     if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_INSTALL_BUNDLE)) {
494         APP_LOGE("install permission denied");
495         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
496         return nullptr;
497     }
498     auto uid = IPCSkeleton::GetCallingUid();
499     sptr<BundleStreamInstallerHostImpl> streamInstaller(new (std::nothrow) BundleStreamInstallerHostImpl(
500         ++streamInstallerIds_, uid));
501     if (streamInstaller == nullptr) {
502         APP_LOGE("streamInstaller is nullptr");
503         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR, "");
504         return nullptr;
505     }
506     bool res = streamInstaller->Init(installParam, statusReceiver);
507     if (!res) {
508         APP_LOGE("stream installer init failed");
509         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR, "");
510         return nullptr;
511     }
512     return streamInstaller;
513 }
514 
DestoryBundleStreamInstaller(uint32_t streamInstallerId)515 bool BundleInstallerHost::DestoryBundleStreamInstaller(uint32_t streamInstallerId)
516 {
517     if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_INSTALL_BUNDLE)) {
518         APP_LOGE("install permission denied");
519         return false;
520     }
521     std::lock_guard<std::mutex> lock(streamInstallMutex_);
522     for (auto it = streamInstallers_.begin(); it != streamInstallers_.end();) {
523         if ((*it)->GetInstallerId() == streamInstallerId) {
524             (*it)->UnInit();
525             it = streamInstallers_.erase(it);
526         } else {
527             it++;
528         }
529     }
530     return true;
531 }
532 
CheckBundleInstallerManager(const sptr<IStatusReceiver> & statusReceiver) const533 bool BundleInstallerHost::CheckBundleInstallerManager(const sptr<IStatusReceiver> &statusReceiver) const
534 {
535     if (statusReceiver == nullptr) {
536         APP_LOGE("the receiver is nullptr");
537         return false;
538     }
539     if (manager_ == nullptr) {
540         APP_LOGE("the bundle installer manager is nullptr");
541         statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR, GET_MANAGER_FAIL);
542         return false;
543     }
544     return true;
545 }
546 
CheckInstallParam(const InstallParam & installParam)547 InstallParam BundleInstallerHost::CheckInstallParam(const InstallParam &installParam)
548 {
549     if (installParam.userId == Constants::UNSPECIFIED_USERID) {
550         APP_LOGI("installParam userId is unspecified and get calling userId by callingUid");
551         InstallParam callInstallParam = installParam;
552         callInstallParam.userId = BundleUtil::GetUserIdByCallingUid();
553         return callInstallParam;
554     }
555 
556     return installParam;
557 }
558 
559 }  // namespace AppExecFwk
560 }  // namespace OHOS