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_installer_host.h"
17
18 #include "app_log_tag_wrapper.h"
19 #include "bundle_clone_installer.h"
20 #include "bundle_framework_core_ipc_interface_code.h"
21 #include "bundle_memory_guard.h"
22 #include "bundle_multiuser_installer.h"
23 #include "bundle_permission_mgr.h"
24 #include "ipc_skeleton.h"
25
26 namespace OHOS {
27 namespace AppExecFwk {
28 namespace {
29 const std::string GET_MANAGER_FAIL = "fail to get bundle installer manager";
30 int32_t INVALID_APP_INDEX = 0;
31 int32_t LOWER_DLP_TYPE_BOUND = 0;
32 int32_t UPPER_DLP_TYPE_BOUND = 3;
33 } // namespace
34
BundleInstallerHost()35 BundleInstallerHost::BundleInstallerHost()
36 {
37 LOG_NOFUNC_I(BMS_TAG_INSTALLER, "create bundle installer host instance");
38 }
39
~BundleInstallerHost()40 BundleInstallerHost::~BundleInstallerHost()
41 {
42 LOG_NOFUNC_I(BMS_TAG_INSTALLER, "destroy bundle installer host instance");
43 }
44
Init()45 void BundleInstallerHost::Init()
46 {
47 LOG_D(BMS_TAG_INSTALLER, "begin to init");
48 manager_ = std::make_shared<BundleInstallerManager>();
49 LOG_D(BMS_TAG_INSTALLER, "init successfully");
50 }
51
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)52 int BundleInstallerHost::OnRemoteRequest(
53 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
54 {
55 BundleMemoryGuard memoryGuard;
56 LOG_D(BMS_TAG_INSTALLER, "bundle installer host onReceived message, the message code is %{public}u", code);
57 std::u16string descripter = GetDescriptor();
58 std::u16string remoteDescripter = data.ReadInterfaceToken();
59 if (descripter != remoteDescripter) {
60 LOG_E(BMS_TAG_INSTALLER, "fail to write reply message in bundle mgr host due to the reply is nullptr");
61 return OBJECT_NULL;
62 }
63 switch (code) {
64 case static_cast<uint32_t>(BundleInstallerInterfaceCode::INSTALL):
65 HandleInstallMessage(data);
66 break;
67 case static_cast<uint32_t>(BundleInstallerInterfaceCode::INSTALL_MULTIPLE_HAPS):
68 HandleInstallMultipleHapsMessage(data);
69 break;
70 case static_cast<uint32_t>(BundleInstallerInterfaceCode::UNINSTALL):
71 HandleUninstallMessage(data);
72 break;
73 case static_cast<uint32_t>(BundleInstallerInterfaceCode::UNINSTALL_MODULE):
74 HandleUninstallModuleMessage(data);
75 break;
76 case static_cast<uint32_t>(BundleInstallerInterfaceCode::UNINSTALL_BY_UNINSTALL_PARAM):
77 HandleUninstallByUninstallParam(data);
78 break;
79 case static_cast<uint32_t>(BundleInstallerInterfaceCode::RECOVER):
80 HandleRecoverMessage(data);
81 break;
82 case static_cast<uint32_t>(BundleInstallerInterfaceCode::INSTALL_SANDBOX_APP):
83 HandleInstallSandboxApp(data, reply);
84 break;
85 case static_cast<uint32_t>(BundleInstallerInterfaceCode::UNINSTALL_SANDBOX_APP):
86 HandleUninstallSandboxApp(data, reply);
87 break;
88 case static_cast<uint32_t>(BundleInstallerInterfaceCode::CREATE_STREAM_INSTALLER):
89 HandleCreateStreamInstaller(data, reply);
90 break;
91 case static_cast<uint32_t>(BundleInstallerInterfaceCode::DESTORY_STREAM_INSTALLER):
92 HandleDestoryBundleStreamInstaller(data, reply);
93 break;
94 case static_cast<uint32_t>(BundleInstallerInterfaceCode::UNINSTALL_AND_RECOVER):
95 HandleUninstallAndRecoverMessage(data);
96 break;
97 case static_cast<uint32_t>(BundleInstallerInterfaceCode::INSTALL_CLONE_APP):
98 HandleInstallCloneApp(data, reply);
99 break;
100 case static_cast<uint32_t>(BundleInstallerInterfaceCode::UNINSTALL_CLONE_APP):
101 HandleUninstallCloneApp(data, reply);
102 break;
103 case static_cast<uint32_t>(BundleInstallerInterfaceCode::INSTALL_EXISTED):
104 HandleInstallExisted(data, reply);
105 break;
106 default:
107 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
108 }
109 return NO_ERROR;
110 }
111
HandleInstallMessage(MessageParcel & data)112 void BundleInstallerHost::HandleInstallMessage(MessageParcel &data)
113 {
114 LOG_D(BMS_TAG_INSTALLER, "handle install message");
115 std::string bundlePath = Str16ToStr8(data.ReadString16());
116 std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
117 if (installParam == nullptr) {
118 LOG_E(BMS_TAG_INSTALLER, "ReadParcelable<InstallParam> failed");
119 return;
120 }
121 sptr<IRemoteObject> object = data.ReadRemoteObject();
122 if (object == nullptr) {
123 LOG_E(BMS_TAG_INSTALLER, "read failed");
124 return;
125 }
126 sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
127 installParam->withCopyHaps = true;
128 Install(bundlePath, *installParam, statusReceiver);
129 LOG_D(BMS_TAG_INSTALLER, "handle install message finished");
130 }
131
HandleRecoverMessage(MessageParcel & data)132 void BundleInstallerHost::HandleRecoverMessage(MessageParcel &data)
133 {
134 LOG_D(BMS_TAG_INSTALLER, "handle install message by bundleName");
135 std::string bundleName = Str16ToStr8(data.ReadString16());
136 std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
137 if (installParam == nullptr) {
138 LOG_E(BMS_TAG_INSTALLER, "ReadParcelable<InstallParam> failed");
139 return;
140 }
141 sptr<IRemoteObject> object = data.ReadRemoteObject();
142 if (object == nullptr) {
143 LOG_E(BMS_TAG_INSTALLER, "read failed");
144 return;
145 }
146 sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
147
148 installParam->preinstallSourceFlag = ApplicationInfoFlag::FLAG_RECOVER_INSTALLED;
149 Recover(bundleName, *installParam, statusReceiver);
150 LOG_D(BMS_TAG_INSTALLER, "handle install message by bundleName finished");
151 }
152
HandleInstallMultipleHapsMessage(MessageParcel & data)153 void BundleInstallerHost::HandleInstallMultipleHapsMessage(MessageParcel &data)
154 {
155 LOG_D(BMS_TAG_INSTALLER, "handle install multiple haps message");
156 int32_t size = data.ReadInt32();
157 if (size > ServiceConstants::MAX_HAP_NUMBER) {
158 LOG_E(BMS_TAG_INSTALLER, "bundle path size is greater than the max hap number 128");
159 return;
160 }
161 std::vector<std::string> pathVec;
162 for (int i = 0; i < size; ++i) {
163 pathVec.emplace_back(Str16ToStr8(data.ReadString16()));
164 }
165 if (size == 0 || pathVec.empty()) {
166 LOG_E(BMS_TAG_INSTALLER, "inputted bundlepath vector is empty");
167 return;
168 }
169 std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
170 if (installParam == nullptr) {
171 LOG_E(BMS_TAG_INSTALLER, "ReadParcelable<InstallParam> failed");
172 return;
173 }
174 sptr<IRemoteObject> object = data.ReadRemoteObject();
175 if (object == nullptr) {
176 LOG_E(BMS_TAG_INSTALLER, "read failed");
177 return;
178 }
179 sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
180 installParam->withCopyHaps = true;
181 Install(pathVec, *installParam, statusReceiver);
182 LOG_D(BMS_TAG_INSTALLER, "handle install multiple haps finished");
183 }
184
HandleUninstallMessage(MessageParcel & data)185 void BundleInstallerHost::HandleUninstallMessage(MessageParcel &data)
186 {
187 LOG_D(BMS_TAG_INSTALLER, "handle uninstall message");
188 std::string bundleName = Str16ToStr8(data.ReadString16());
189 std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
190 if (installParam == nullptr) {
191 LOG_E(BMS_TAG_INSTALLER, "ReadParcelable<InstallParam> failed");
192 return;
193 }
194 sptr<IRemoteObject> object = data.ReadRemoteObject();
195 if (object == nullptr) {
196 LOG_E(BMS_TAG_INSTALLER, "read failed");
197 return;
198 }
199 sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
200
201 Uninstall(bundleName, *installParam, statusReceiver);
202 LOG_D(BMS_TAG_INSTALLER, "handle uninstall message finished");
203 }
204
HandleUninstallModuleMessage(MessageParcel & data)205 void BundleInstallerHost::HandleUninstallModuleMessage(MessageParcel &data)
206 {
207 LOG_D(BMS_TAG_INSTALLER, "handle uninstall module message");
208 std::string bundleName = Str16ToStr8(data.ReadString16());
209 std::string modulePackage = Str16ToStr8(data.ReadString16());
210 std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
211 if (installParam == nullptr) {
212 LOG_E(BMS_TAG_INSTALLER, "ReadParcelable<InstallParam> failed");
213 return;
214 }
215 sptr<IRemoteObject> object = data.ReadRemoteObject();
216 if (object == nullptr) {
217 LOG_E(BMS_TAG_INSTALLER, "read failed");
218 return;
219 }
220 sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
221 Uninstall(bundleName, modulePackage, *installParam, statusReceiver);
222 LOG_D(BMS_TAG_INSTALLER, "handle uninstall message finished");
223 }
224
HandleUninstallByUninstallParam(MessageParcel & data)225 void BundleInstallerHost::HandleUninstallByUninstallParam(MessageParcel &data)
226 {
227 std::unique_ptr<UninstallParam> uninstallParam(data.ReadParcelable<UninstallParam>());
228 if (uninstallParam == nullptr) {
229 LOG_E(BMS_TAG_INSTALLER, "ReadParcelable<UninstallParam failed");
230 return;
231 }
232 sptr<IRemoteObject> object = data.ReadRemoteObject();
233 if (object == nullptr) {
234 LOG_E(BMS_TAG_INSTALLER, "read failed");
235 return;
236 }
237 sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
238 Uninstall(*uninstallParam, statusReceiver);
239 }
240
HandleInstallSandboxApp(MessageParcel & data,MessageParcel & reply)241 void BundleInstallerHost::HandleInstallSandboxApp(MessageParcel &data, MessageParcel &reply)
242 {
243 LOG_D(BMS_TAG_INSTALLER, "handle install sandbox app message");
244 std::string bundleName = Str16ToStr8(data.ReadString16());
245 int32_t dplType = data.ReadInt32();
246 int32_t userId = data.ReadInt32();
247 int32_t appIndex = Constants::INITIAL_SANDBOX_APP_INDEX;
248 auto ret = InstallSandboxApp(bundleName, dplType, userId, appIndex);
249 if (!reply.WriteInt32(ret)) {
250 LOG_E(BMS_TAG_INSTALLER, "write failed");
251 }
252 if (ret == ERR_OK && !reply.WriteInt32(appIndex)) {
253 LOG_E(BMS_TAG_INSTALLER, "write failed");
254 }
255 LOG_D(BMS_TAG_INSTALLER, "handle install sandbox app message finished");
256 }
257
HandleUninstallSandboxApp(MessageParcel & data,MessageParcel & reply)258 void BundleInstallerHost::HandleUninstallSandboxApp(MessageParcel &data, MessageParcel &reply)
259 {
260 LOG_D(BMS_TAG_INSTALLER, "handle install sandbox app message");
261 std::string bundleName = Str16ToStr8(data.ReadString16());
262 int32_t appIndex = data.ReadInt32();
263 int32_t userId = data.ReadInt32();
264 auto ret = UninstallSandboxApp(bundleName, appIndex, userId);
265 if (!reply.WriteInt32(ret)) {
266 LOG_E(BMS_TAG_INSTALLER, "write failed");
267 }
268 LOG_D(BMS_TAG_INSTALLER, "handle install sandbox app message finished");
269 }
270
HandleCreateStreamInstaller(MessageParcel & data,MessageParcel & reply)271 void BundleInstallerHost::HandleCreateStreamInstaller(MessageParcel &data, MessageParcel &reply)
272 {
273 LOG_D(BMS_TAG_INSTALLER, "handle create stream installer message begin");
274 std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
275 if (installParam == nullptr) {
276 LOG_E(BMS_TAG_INSTALLER, "ReadParcelable<InstallParam> failed");
277 return;
278 }
279 sptr<IRemoteObject> object = data.ReadRemoteObject();
280 if (object == nullptr) {
281 reply.WriteBool(false);
282 LOG_E(BMS_TAG_INSTALLER, "read receiver failed");
283 return;
284 }
285 sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
286 if (statusReceiver == nullptr) {
287 reply.WriteBool(false);
288 LOG_E(BMS_TAG_INSTALLER, "cast remote object to status receiver error");
289 return;
290 }
291
292 sptr<IBundleStreamInstaller> streamInstaller = CreateStreamInstaller(*installParam, statusReceiver);
293 if (streamInstaller == nullptr) {
294 if (!reply.WriteBool(false)) {
295 LOG_E(BMS_TAG_INSTALLER, "write result failed");
296 }
297 return;
298 }
299 if (!reply.WriteBool(true)) {
300 LOG_E(BMS_TAG_INSTALLER, "write result failed");
301 return;
302 }
303 if (!reply.WriteUint32(streamInstaller->GetInstallerId())) {
304 LOG_E(BMS_TAG_INSTALLER, "write stream installe id failed");
305 return;
306 }
307 if (!reply.WriteRemoteObject(streamInstaller->AsObject())) {
308 LOG_E(BMS_TAG_INSTALLER, "write stream installer remote object failed");
309 return;
310 }
311
312 std::lock_guard<std::mutex> lock(streamInstallMutex_);
313 streamInstallers_.emplace_back(streamInstaller);
314 LOG_D(BMS_TAG_INSTALLER, "handle create stream installer message finish");
315 }
316
HandleDestoryBundleStreamInstaller(MessageParcel & data,MessageParcel & reply)317 void BundleInstallerHost::HandleDestoryBundleStreamInstaller(MessageParcel &data, MessageParcel &reply)
318 {
319 LOG_D(BMS_TAG_INSTALLER, "handle destory stream installer message begin");
320 uint32_t installeId = data.ReadUint32();
321 DestoryBundleStreamInstaller(installeId);
322 LOG_D(BMS_TAG_INSTALLER, "handle destoy stream installer message finish");
323 }
324
HandleUninstallAndRecoverMessage(MessageParcel & data)325 void BundleInstallerHost::HandleUninstallAndRecoverMessage(MessageParcel &data)
326 {
327 LOG_D(BMS_TAG_INSTALLER, "handle UninstallAndRecover message");
328 std::string bundleName = Str16ToStr8(data.ReadString16());
329 std::unique_ptr<InstallParam> installParam(data.ReadParcelable<InstallParam>());
330 if (installParam == nullptr) {
331 LOG_E(BMS_TAG_INSTALLER, "ReadParcelable<InstallParam> failed");
332 return;
333 }
334 sptr<IRemoteObject> object = data.ReadRemoteObject();
335 if (object == nullptr) {
336 LOG_E(BMS_TAG_INSTALLER, "read failed");
337 return;
338 }
339 sptr<IStatusReceiver> statusReceiver = iface_cast<IStatusReceiver>(object);
340 installParam->preinstallSourceFlag = ApplicationInfoFlag::FLAG_RECOVER_INSTALLED;
341 UninstallAndRecover(bundleName, *installParam, statusReceiver);
342 LOG_D(BMS_TAG_INSTALLER, "handle UninstallAndRecover message finished");
343 }
344
Install(const std::string & bundleFilePath,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)345 bool BundleInstallerHost::Install(
346 const std::string &bundleFilePath, const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
347 {
348 if (!CheckBundleInstallerManager(statusReceiver)) {
349 LOG_E(BMS_TAG_INSTALLER, "statusReceiver invalid");
350 return false;
351 }
352 if (!BundlePermissionMgr::IsSystemApp() &&
353 !BundlePermissionMgr::VerifyCallingBundleSdkVersion(ServiceConstants::API_VERSION_NINE)) {
354 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
355 statusReceiver->OnFinished(ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, "");
356 return false;
357 }
358 if (!BundlePermissionMgr::IsSelfCalling() &&
359 !BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_INSTALL_BUNDLE) &&
360 !BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_BUNDLE) &&
361 !BundlePermissionMgr::VerifyCallingPermissionForAll(
362 ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_NORMAL_BUNDLE) &&
363 !BundlePermissionMgr::VerifyCallingPermissionForAll(
364 ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_MDM_BUNDLE)) {
365 LOG_E(BMS_TAG_INSTALLER, "install permission denied");
366 statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
367 return false;
368 }
369
370 manager_->CreateInstallTask(bundleFilePath, installParam, statusReceiver);
371 return true;
372 }
373
Install(const std::vector<std::string> & bundleFilePaths,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)374 bool BundleInstallerHost::Install(const std::vector<std::string> &bundleFilePaths, const InstallParam &installParam,
375 const sptr<IStatusReceiver> &statusReceiver)
376 {
377 if (!CheckBundleInstallerManager(statusReceiver)) {
378 LOG_E(BMS_TAG_INSTALLER, "statusReceiver invalid");
379 return false;
380 }
381 if (!BundlePermissionMgr::IsSystemApp() &&
382 !BundlePermissionMgr::VerifyCallingBundleSdkVersion(ServiceConstants::API_VERSION_NINE)) {
383 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
384 statusReceiver->OnFinished(ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, "");
385 return false;
386 }
387 if (!BundlePermissionMgr::IsSelfCalling() &&
388 !BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_INSTALL_BUNDLE) &&
389 !BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_BUNDLE) &&
390 !BundlePermissionMgr::VerifyCallingPermissionForAll(
391 ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_NORMAL_BUNDLE) &&
392 !BundlePermissionMgr::VerifyCallingPermissionForAll(
393 ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_MDM_BUNDLE)) {
394 LOG_E(BMS_TAG_INSTALLER, "install permission denied");
395 statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
396 return false;
397 }
398
399 manager_->CreateInstallTask(bundleFilePaths, installParam, statusReceiver);
400 return true;
401 }
402
Recover(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)403 bool BundleInstallerHost::Recover(
404 const std::string &bundleName, const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
405 {
406 if (!CheckBundleInstallerManager(statusReceiver)) {
407 LOG_E(BMS_TAG_INSTALLER, "statusReceiver invalid");
408 return false;
409 }
410 if (!BundlePermissionMgr::IsSystemApp() &&
411 !BundlePermissionMgr::VerifyCallingBundleSdkVersion(ServiceConstants::API_VERSION_NINE)) {
412 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
413 statusReceiver->OnFinished(ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, "");
414 return false;
415 }
416 if (!BundlePermissionMgr::VerifyRecoverPermission()) {
417 LOG_E(BMS_TAG_INSTALLER, "Recover permission denied");
418 statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
419 return false;
420 }
421 manager_->CreateRecoverTask(bundleName, CheckInstallParam(installParam), statusReceiver);
422 return true;
423 }
424
Uninstall(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)425 bool BundleInstallerHost::Uninstall(
426 const std::string &bundleName, const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
427 {
428 if (!CheckBundleInstallerManager(statusReceiver)) {
429 LOG_E(BMS_TAG_INSTALLER, "statusReceiver invalid");
430 return false;
431 }
432 if (!BundlePermissionMgr::IsSystemApp() &&
433 !BundlePermissionMgr::VerifyCallingBundleSdkVersion(ServiceConstants::API_VERSION_NINE)) {
434 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
435 statusReceiver->OnFinished(ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, "");
436 return false;
437 }
438 if (!BundlePermissionMgr::VerifyUninstallPermission()) {
439 LOG_E(BMS_TAG_INSTALLER, "uninstall permission denied");
440 statusReceiver->OnFinished(ERR_APPEXECFWK_UNINSTALL_PERMISSION_DENIED, "");
441 return false;
442 }
443 manager_->CreateUninstallTask(bundleName, CheckInstallParam(installParam), statusReceiver);
444 return true;
445 }
446
Uninstall(const std::string & bundleName,const std::string & modulePackage,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)447 bool BundleInstallerHost::Uninstall(const std::string &bundleName, const std::string &modulePackage,
448 const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
449 {
450 if (!CheckBundleInstallerManager(statusReceiver)) {
451 LOG_E(BMS_TAG_INSTALLER, "statusReceiver invalid");
452 return false;
453 }
454 if (!BundlePermissionMgr::IsSystemApp() &&
455 !BundlePermissionMgr::VerifyCallingBundleSdkVersion(ServiceConstants::API_VERSION_NINE)) {
456 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
457 statusReceiver->OnFinished(ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, "");
458 return false;
459 }
460 if (!BundlePermissionMgr::VerifyUninstallPermission()) {
461 LOG_E(BMS_TAG_INSTALLER, "uninstall permission denied");
462 statusReceiver->OnFinished(ERR_APPEXECFWK_UNINSTALL_PERMISSION_DENIED, "");
463 return false;
464 }
465 manager_->CreateUninstallTask(
466 bundleName, modulePackage, CheckInstallParam(installParam), statusReceiver);
467 return true;
468 }
469
Uninstall(const UninstallParam & uninstallParam,const sptr<IStatusReceiver> & statusReceiver)470 bool BundleInstallerHost::Uninstall(const UninstallParam &uninstallParam,
471 const sptr<IStatusReceiver> &statusReceiver)
472 {
473 if (!CheckBundleInstallerManager(statusReceiver)) {
474 LOG_E(BMS_TAG_INSTALLER, "statusReceiver invalid");
475 return false;
476 }
477 if (!BundlePermissionMgr::IsSystemApp()) {
478 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
479 statusReceiver->OnFinished(ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, "");
480 return false;
481 }
482 if (!BundlePermissionMgr::VerifyUninstallPermission()) {
483 LOG_E(BMS_TAG_INSTALLER, "uninstall permission denied");
484 statusReceiver->OnFinished(ERR_APPEXECFWK_UNINSTALL_PERMISSION_DENIED, "");
485 return false;
486 }
487 manager_->CreateUninstallTask(uninstallParam, statusReceiver);
488 return true;
489 }
490
InstallByBundleName(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)491 bool BundleInstallerHost::InstallByBundleName(const std::string &bundleName,
492 const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
493 {
494 if (!CheckBundleInstallerManager(statusReceiver)) {
495 LOG_E(BMS_TAG_INSTALLER, "statusReceiver invalid");
496 return false;
497 }
498 if (!BundlePermissionMgr::IsSystemApp() &&
499 !BundlePermissionMgr::VerifyCallingBundleSdkVersion(ServiceConstants::API_VERSION_NINE)) {
500 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
501 statusReceiver->OnFinished(ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, "");
502 return false;
503 }
504 if (!BundlePermissionMgr::IsSelfCalling() &&
505 !BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_INSTALL_BUNDLE) &&
506 !BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_BUNDLE) &&
507 !BundlePermissionMgr::VerifyCallingPermissionForAll(
508 ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_NORMAL_BUNDLE) &&
509 !BundlePermissionMgr::VerifyCallingPermissionForAll(
510 ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_MDM_BUNDLE)) {
511 LOG_E(BMS_TAG_INSTALLER, "install permission denied");
512 statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
513 return false;
514 }
515
516 manager_->CreateInstallByBundleNameTask(bundleName, CheckInstallParam(installParam), statusReceiver);
517 return true;
518 }
519
InstallSandboxApp(const std::string & bundleName,int32_t dplType,int32_t userId,int32_t & appIndex)520 ErrCode BundleInstallerHost::InstallSandboxApp(const std::string &bundleName, int32_t dplType, int32_t userId,
521 int32_t &appIndex)
522 {
523 if (bundleName.empty() || dplType <= LOWER_DLP_TYPE_BOUND || dplType >= UPPER_DLP_TYPE_BOUND) {
524 LOG_E(BMS_TAG_INSTALLER, "install sandbox failed due to error parameters");
525 return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
526 }
527 if (!BundlePermissionMgr::IsSystemApp()) {
528 LOG_E(BMS_TAG_INSTALLER, "vnon-system app calling system api");
529 return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED;
530 }
531 if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_INSTALL_BUNDLE) &&
532 !BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_SANDBOX_BUNDLE)) {
533 LOG_E(BMS_TAG_INSTALLER, "InstallSandboxApp permission denied");
534 return ERR_APPEXECFWK_PERMISSION_DENIED;
535 }
536 auto helper = DelayedSingleton<BundleSandboxAppHelper>::GetInstance();
537 if (helper == nullptr) {
538 return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
539 }
540 auto res = helper->InstallSandboxApp(bundleName, dplType, userId, appIndex);
541 if (res != ERR_OK) {
542 LOG_E(BMS_TAG_INSTALLER, "install sandbox failed due to error code : %{public}d", res);
543 }
544 return res;
545 }
546
UninstallSandboxApp(const std::string & bundleName,int32_t appIndex,int32_t userId)547 ErrCode BundleInstallerHost::UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId)
548 {
549 // check bundle name
550 if (bundleName.empty()) {
551 LOG_E(BMS_TAG_INSTALLER, "uninstall sandbox failed due to empty bundleName");
552 return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
553 }
554 // check appIndex
555 if (appIndex <= INVALID_APP_INDEX || appIndex > Constants::MAX_SANDBOX_APP_INDEX) {
556 LOG_E(BMS_TAG_INSTALLER, "the appIndex %{public}d is invalid", appIndex);
557 return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
558 }
559 if (!BundlePermissionMgr::IsSystemApp()) {
560 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
561 return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED;
562 }
563 if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_INSTALL_BUNDLE) &&
564 !BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_UNINSTALL_SANDBOX_BUNDLE)) {
565 LOG_E(BMS_TAG_INSTALLER, "UninstallSandboxApp permission denied");
566 return ERR_APPEXECFWK_PERMISSION_DENIED;
567 }
568 auto helper = DelayedSingleton<BundleSandboxAppHelper>::GetInstance();
569 if (helper == nullptr) {
570 return ERR_APPEXECFWK_SANDBOX_INSTALL_INTERNAL_ERROR;
571 }
572 auto res = helper->UninstallSandboxApp(bundleName, appIndex, userId);
573 if (res != ERR_OK) {
574 LOG_E(BMS_TAG_INSTALLER, "uninstall sandbox failed due to error code : %{public}d", res);
575 }
576 return res;
577 }
578
StreamInstall(const std::vector<std::string> & bundleFilePaths,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)579 ErrCode BundleInstallerHost::StreamInstall(const std::vector<std::string> &bundleFilePaths,
580 const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
581 {
582 return ERR_OK;
583 }
584
CreateStreamInstaller(const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)585 sptr<IBundleStreamInstaller> BundleInstallerHost::CreateStreamInstaller(const InstallParam &installParam,
586 const sptr<IStatusReceiver> &statusReceiver)
587 {
588 if (!CheckBundleInstallerManager(statusReceiver)) {
589 LOG_E(BMS_TAG_INSTALLER, "statusReceiver invalid");
590 return nullptr;
591 }
592 if (!BundlePermissionMgr::IsSystemApp()) {
593 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
594 statusReceiver->OnFinished(ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, "");
595 return nullptr;
596 }
597 InstallParam verifiedInstallParam = installParam;
598 if (!IsPermissionVaild(installParam, verifiedInstallParam)) {
599 LOG_E(BMS_TAG_INSTALLER, "install permission denied");
600 statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
601 return nullptr;
602 }
603 auto uid = IPCSkeleton::GetCallingUid();
604 sptr<BundleStreamInstallerHostImpl> streamInstaller(new (std::nothrow) BundleStreamInstallerHostImpl(
605 ++streamInstallerIds_, uid));
606 if (streamInstaller == nullptr) {
607 LOG_E(BMS_TAG_INSTALLER, "streamInstaller is nullptr, uid : %{public}d", uid);
608 statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR, "");
609 return nullptr;
610 }
611 bool res = streamInstaller->Init(verifiedInstallParam, statusReceiver);
612 if (!res) {
613 LOG_E(BMS_TAG_INSTALLER, "stream installer init failed");
614 statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR, "");
615 return nullptr;
616 }
617 return streamInstaller;
618 }
619
IsPermissionVaild(const InstallParam & installParam,InstallParam & verifiedInstallParam)620 bool BundleInstallerHost::IsPermissionVaild(const InstallParam &installParam, InstallParam &verifiedInstallParam)
621 {
622 verifiedInstallParam.isCallByShell = BundlePermissionMgr::IsShellTokenType();
623 verifiedInstallParam.installBundlePermissionStatus =
624 BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_INSTALL_BUNDLE) ?
625 PermissionStatus::HAVE_PERMISSION_STATUS : PermissionStatus::NON_HAVE_PERMISSION_STATUS;
626 verifiedInstallParam.installEnterpriseBundlePermissionStatus =
627 BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_BUNDLE) ?
628 PermissionStatus::HAVE_PERMISSION_STATUS : PermissionStatus::NON_HAVE_PERMISSION_STATUS;
629 verifiedInstallParam.installEtpNormalBundlePermissionStatus =
630 BundlePermissionMgr::VerifyCallingPermissionForAll(
631 ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_NORMAL_BUNDLE) ?
632 PermissionStatus::HAVE_PERMISSION_STATUS : PermissionStatus::NON_HAVE_PERMISSION_STATUS;
633 verifiedInstallParam.installEtpMdmBundlePermissionStatus =
634 BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_MDM_BUNDLE) ?
635 PermissionStatus::HAVE_PERMISSION_STATUS : PermissionStatus::NON_HAVE_PERMISSION_STATUS;
636 verifiedInstallParam.installUpdateSelfBundlePermissionStatus =
637 BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_SELF_BUNDLE) ?
638 PermissionStatus::HAVE_PERMISSION_STATUS : PermissionStatus::NON_HAVE_PERMISSION_STATUS;
639 return (verifiedInstallParam.installBundlePermissionStatus == PermissionStatus::HAVE_PERMISSION_STATUS ||
640 verifiedInstallParam.installEnterpriseBundlePermissionStatus == PermissionStatus::HAVE_PERMISSION_STATUS ||
641 verifiedInstallParam.installEtpNormalBundlePermissionStatus == PermissionStatus::HAVE_PERMISSION_STATUS ||
642 verifiedInstallParam.installEtpMdmBundlePermissionStatus == PermissionStatus::HAVE_PERMISSION_STATUS ||
643 verifiedInstallParam.installUpdateSelfBundlePermissionStatus == PermissionStatus::HAVE_PERMISSION_STATUS ||
644 BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_QUICK_FIX_BUNDLE));
645 }
646
DestoryBundleStreamInstaller(uint32_t streamInstallerId)647 bool BundleInstallerHost::DestoryBundleStreamInstaller(uint32_t streamInstallerId)
648 {
649 if (!BundlePermissionMgr::IsSystemApp()) {
650 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
651 return false;
652 }
653 if (!BundlePermissionMgr::IsSelfCalling() &&
654 !BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_INSTALL_BUNDLE) &&
655 !BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_BUNDLE) &&
656 !BundlePermissionMgr::VerifyCallingPermissionForAll(
657 ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_NORMAL_BUNDLE) &&
658 !BundlePermissionMgr::VerifyCallingPermissionForAll(
659 ServiceConstants::PERMISSION_INSTALL_ENTERPRISE_MDM_BUNDLE) &&
660 !BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_QUICK_FIX_BUNDLE)) {
661 LOG_E(BMS_TAG_INSTALLER, "install permission denied");
662 return false;
663 }
664 std::lock_guard<std::mutex> lock(streamInstallMutex_);
665 for (auto it = streamInstallers_.begin(); it != streamInstallers_.end();) {
666 if ((*it)->GetInstallerId() == streamInstallerId) {
667 (*it)->UnInit();
668 it = streamInstallers_.erase(it);
669 } else {
670 it++;
671 }
672 }
673 return true;
674 }
675
CheckBundleInstallerManager(const sptr<IStatusReceiver> & statusReceiver) const676 bool BundleInstallerHost::CheckBundleInstallerManager(const sptr<IStatusReceiver> &statusReceiver) const
677 {
678 if (statusReceiver == nullptr) {
679 LOG_E(BMS_TAG_INSTALLER, "the receiver is nullptr");
680 return false;
681 }
682 if (manager_ == nullptr) {
683 LOG_E(BMS_TAG_INSTALLER, "the bundle installer manager is nullptr");
684 statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR, GET_MANAGER_FAIL);
685 return false;
686 }
687 return true;
688 }
689
CheckInstallParam(const InstallParam & installParam)690 InstallParam BundleInstallerHost::CheckInstallParam(const InstallParam &installParam)
691 {
692 if (installParam.userId == Constants::UNSPECIFIED_USERID) {
693 LOG_I(BMS_TAG_INSTALLER, "installParam userId is unspecified and get calling userId by callingUid");
694 InstallParam callInstallParam = installParam;
695 callInstallParam.userId = BundleUtil::GetUserIdByCallingUid();
696 return callInstallParam;
697 }
698
699 return installParam;
700 }
701
UpdateBundleForSelf(const std::vector<std::string> & bundleFilePaths,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)702 bool BundleInstallerHost::UpdateBundleForSelf(const std::vector<std::string> &bundleFilePaths,
703 const InstallParam &installParam, const sptr<IStatusReceiver> &statusReceiver)
704 {
705 if (!CheckBundleInstallerManager(statusReceiver)) {
706 LOG_E(BMS_TAG_INSTALLER, "statusReceiver invalid");
707 return false;
708 }
709 if (!BundlePermissionMgr::IsSystemApp()) {
710 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
711 statusReceiver->OnFinished(ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, "");
712 return false;
713 }
714 if (!BundlePermissionMgr::IsSelfCalling() &&
715 !BundlePermissionMgr::VerifyCallingPermissionForAll(ServiceConstants::PERMISSION_INSTALL_SELF_BUNDLE)) {
716 LOG_E(BMS_TAG_INSTALLER, "install permission denied");
717 statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
718 return false;
719 }
720 manager_->CreateInstallTask(bundleFilePaths, installParam, statusReceiver);
721 return true;
722 }
723
UninstallAndRecover(const std::string & bundleName,const InstallParam & installParam,const sptr<IStatusReceiver> & statusReceiver)724 bool BundleInstallerHost::UninstallAndRecover(const std::string &bundleName, const InstallParam &installParam,
725 const sptr<IStatusReceiver> &statusReceiver)
726 {
727 if (!CheckBundleInstallerManager(statusReceiver)) {
728 LOG_E(BMS_TAG_INSTALLER, "statusReceiver invalid");
729 return false;
730 }
731 if (!BundlePermissionMgr::IsSystemApp()) {
732 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api");
733 statusReceiver->OnFinished(ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED, "");
734 return false;
735 }
736 if (!BundlePermissionMgr::IsSelfCalling() &&
737 !BundlePermissionMgr::VerifyCallingPermissionsForAll({Constants::PERMISSION_INSTALL_BUNDLE,
738 ServiceConstants::PERMISSION_UNINSTALL_BUNDLE})) {
739 LOG_E(BMS_TAG_INSTALLER, "install permission denied");
740 statusReceiver->OnFinished(ERR_APPEXECFWK_INSTALL_PERMISSION_DENIED, "");
741 return false;
742 }
743 manager_->CreateUninstallAndRecoverTask(bundleName, CheckInstallParam(installParam), statusReceiver);
744 return true;
745 }
746
AddTask(const ThreadPoolTask & task,const std::string & taskName)747 void BundleInstallerHost::AddTask(const ThreadPoolTask &task, const std::string &taskName)
748 {
749 manager_->AddTask(task, taskName);
750 }
751
GetThreadsNum()752 int32_t BundleInstallerHost::GetThreadsNum()
753 {
754 return manager_->GetThreadsNum();
755 }
756
GetCurTaskNum()757 size_t BundleInstallerHost::GetCurTaskNum()
758 {
759 return manager_->GetCurTaskNum();
760 }
761
InstallCloneApp(const std::string & bundleName,int32_t userId,int32_t & appIndex)762 ErrCode BundleInstallerHost::InstallCloneApp(const std::string &bundleName, int32_t userId, int32_t& appIndex)
763 {
764 LOG_D(BMS_TAG_INSTALLER, "params[bundleName: %{public}s, user_id: %{public}d, appIndex: %{public}d]",
765 bundleName.c_str(), userId, appIndex);
766 if (bundleName.empty()) {
767 LOG_E(BMS_TAG_INSTALLER, "install clone app failed due to error parameters");
768 return ERR_APPEXECFWK_CLONE_INSTALL_PARAM_ERROR;
769 }
770 if (!BundlePermissionMgr::IsSystemApp()) {
771 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api bundleName: %{public}s", bundleName.c_str());
772 return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED;
773 }
774 if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_INSTALL_CLONE_BUNDLE)) {
775 LOG_E(BMS_TAG_INSTALLER, "InstallCloneApp permission denied");
776 return ERR_APPEXECFWK_PERMISSION_DENIED;
777 }
778 std::shared_ptr<BundleCloneInstaller> installer = std::make_shared<BundleCloneInstaller>();
779 return installer->InstallCloneApp(bundleName, userId, appIndex);
780 }
781
HandleInstallCloneApp(MessageParcel & data,MessageParcel & reply)782 void BundleInstallerHost::HandleInstallCloneApp(MessageParcel &data, MessageParcel &reply)
783 {
784 LOG_D(BMS_TAG_INSTALLER, "handle install clone app message");
785 std::string bundleName = Str16ToStr8(data.ReadString16());
786 int32_t userId = data.ReadInt32();
787 int32_t appIndex = data.ReadInt32();
788
789 LOG_I(BMS_TAG_INSTALLER, "receive Install CLone App Request");
790
791 auto ret = InstallCloneApp(bundleName, userId, appIndex);
792 if (!reply.WriteInt32(ret)) {
793 LOG_E(BMS_TAG_INSTALLER, "write failed");
794 }
795
796 if (ret == ERR_OK && !reply.WriteInt32(appIndex)) {
797 LOG_E(BMS_TAG_INSTALLER, "write failed");
798 }
799 LOG_D(BMS_TAG_INSTALLER, "handle install clone app message finished");
800 }
801
UninstallCloneApp(const std::string & bundleName,int32_t userId,int32_t appIndex)802 ErrCode BundleInstallerHost::UninstallCloneApp(const std::string &bundleName, int32_t userId, int32_t appIndex)
803 {
804 LOG_D(BMS_TAG_INSTALLER, "params[bundleName: %{public}s, user_id: %{public}d, appIndex: %{public}d]",
805 bundleName.c_str(), userId, appIndex);
806 if (bundleName.empty()) {
807 LOG_E(BMS_TAG_INSTALLER, "install clone app failed due to empty bundleName");
808 return ERR_APPEXECFWK_CLONE_UNINSTALL_INVALID_BUNDLE_NAME;
809 }
810 if (!BundlePermissionMgr::IsSystemApp()) {
811 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api, bundleName: %{public}s", bundleName.c_str());
812 return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED;
813 }
814 if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_UNINSTALL_CLONE_BUNDLE)) {
815 LOG_E(BMS_TAG_INSTALLER, "UninstallCloneApp permission denied");
816 return ERR_APPEXECFWK_PERMISSION_DENIED;
817 }
818 std::shared_ptr<BundleCloneInstaller> installer = std::make_shared<BundleCloneInstaller>();
819 return installer->UninstallCloneApp(bundleName, userId, appIndex);
820 }
821
HandleUninstallCloneApp(MessageParcel & data,MessageParcel & reply)822 void BundleInstallerHost::HandleUninstallCloneApp(MessageParcel &data, MessageParcel &reply)
823 {
824 LOG_D(BMS_TAG_INSTALLER, "handle uninstall clone app message");
825 std::string bundleName = Str16ToStr8(data.ReadString16());
826 int32_t userId = data.ReadInt32();
827 int32_t appIndex = data.ReadInt32();
828
829 LOG_I(BMS_TAG_INSTALLER, "receive Uninstall CLone App Request");
830
831 auto ret = UninstallCloneApp(bundleName, userId, appIndex);
832 if (!reply.WriteInt32(ret)) {
833 LOG_E(BMS_TAG_INSTALLER, "write failed");
834 }
835 LOG_D(BMS_TAG_INSTALLER, "handle uninstall clone app message finished");
836 }
837
InstallExisted(const std::string & bundleName,int32_t userId)838 ErrCode BundleInstallerHost::InstallExisted(const std::string &bundleName, int32_t userId)
839 {
840 LOG_D(BMS_TAG_INSTALLER, "params[bundleName: %{public}s, user_id: %{public}d]",
841 bundleName.c_str(), userId);
842 if (bundleName.empty()) {
843 LOG_E(BMS_TAG_INSTALLER, "install existed app failed due to error parameters");
844 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
845 }
846 if (!BundlePermissionMgr::IsSystemApp()) {
847 LOG_E(BMS_TAG_INSTALLER, "non-system app calling system api bundleName: %{public}s", bundleName.c_str());
848 return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED;
849 }
850 if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_INSTALL_BUNDLE)) {
851 LOG_E(BMS_TAG_INSTALLER, "InstallExisted permission denied");
852 return ERR_APPEXECFWK_PERMISSION_DENIED;
853 }
854 std::shared_ptr<BundleMultiUserInstaller> installer = std::make_shared<BundleMultiUserInstaller>();
855 return installer->InstallExistedApp(bundleName, userId);
856 }
857
HandleInstallExisted(MessageParcel & data,MessageParcel & reply)858 void BundleInstallerHost::HandleInstallExisted(MessageParcel &data, MessageParcel &reply)
859 {
860 LOG_D(BMS_TAG_INSTALLER, "handle install existed app message");
861 std::string bundleName = Str16ToStr8(data.ReadString16());
862 int32_t userId = data.ReadInt32();
863
864 LOG_I(BMS_TAG_INSTALLER, "receive InstallExisted Request -n %{public}s -u %{public}d",
865 bundleName.c_str(), userId);
866
867 auto ret = InstallExisted(bundleName, userId);
868 if (!reply.WriteInt32(ret)) {
869 LOG_E(BMS_TAG_INSTALLER, "write failed");
870 }
871 LOG_D(BMS_TAG_INSTALLER, "handle installExisted message finished");
872 }
873 } // namespace AppExecFwk
874 } // namespace OHOS