auto sysAbilityMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (sysAbilityMgr == nullptr) {
PHLOGE("get system ability manager fail.");
DeleteFiles();
return APP_ERR_SYSTEM_ABNORMALLY;
}
auto remoteObject = sysAbilityMgr->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
auto iBundleMgr = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
if (iBundleMgr == nullptr) {
PHLOGE("can not get iBundleMgr");
DeleteFiles();
return APP_ERR_SYSTEM_ABNORMALLY;
}
auto iBundleInstaller = iBundleMgr->GetBundleInstaller();
if ((iBundleInstaller == nullptr) || (iBundleInstaller->AsObject() == nullptr)) {
PHLOGE("can not get iBundleInstaller");
DeleteFiles();
return APP_ERR_SYSTEM_ABNORMALLY;
}
sptr<AppInstallCallback> callback = new (std::nothrow) AppInstallCallback();
if (callback == nullptr) {
PHLOGE("AppInstallCallback failed");
DeleteFiles();
return APP_ERR_SYSTEM_ABNORMALLY;
}