diff --git a/services/bundlemgr/include/free_install/bundle_connect_ability_mgr.h b/services/bundlemgr/include/free_install/bundle_connect_ability_mgr.h index 14225a82..e7f1e7ba 100644 --- a/services/bundlemgr/include/free_install/bundle_connect_ability_mgr.h +++ b/services/bundlemgr/include/free_install/bundle_connect_ability_mgr.h @@ -73,6 +73,7 @@ public: */ bool UpgradeInstallSafely(const TargetAbilityInfo &targetAbilityInfo, const Want &want, const sptr &callerToken, int32_t userId); + /** * @brief Obtains the Calling Info object * @param innerBundleInfo Indicates the innerBundleInfo of the bundle which will be returned. @@ -82,6 +83,7 @@ public: */ void GetCallingInfo(InnerBundleInfo &innerBundleInfo, std::vector &bundleNames, std::vector& callingAppIds); + /** * @brief Obtains the target ability Info object which will be send to service center. * @param want Indicates the information of the ability. @@ -92,14 +94,7 @@ public: */ bool GetTargetAbilityInfo(const Want &want, InnerBundleInfo &innerBundleInfo, sptr &targetAbilityInfo, sptr &targetInfo); - /** - * @brief Send callback to ability manager service - * @param resultCode The result code to ability manager service call back - * @param want Indicates the information of the ability. - * @param userId Indicates the user ID. - * @param callBack Indicates the callback object for ability manager service. - */ - void CallAbilityManager(int32_t resultCode, const Want &want, int32_t userId, const sptr &callBack); + /** * @brief Check is need update module. * @param innerBundleInfo Indicates the innerBundleInfo of the bundle which will be using. @@ -110,6 +105,7 @@ public: */ bool CheckIsModuleNeedUpdate( InnerBundleInfo &innerBundleInfo, const Want &want, int32_t userId, const sptr &callBack); + /** * @brief Query the AbilityInfo by the given Want. * @param want Indicates the information of the ability. @@ -121,6 +117,7 @@ public: */ bool QueryAbilityInfo(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo, const sptr &callBack); + /** * @brief Upgrade atomic service status * @param want Query the AbilityInfo by the given Want. @@ -200,12 +197,21 @@ public: } private: + /** + * @brief Send callback to ability manager service + * @param resultCode The result code to ability manager service call back + * @param want Indicates the information of the ability. + * @param userId Indicates the user ID. + * @param callBack Indicates the callback object for ability manager service. + */ + void CallAbilityManager(int32_t resultCode, const Want &want, int32_t userId, const sptr &callBack); bool GetAbilityMgrProxy(); + mutable std::atomic transactId_ = 0; std::condition_variable cv_; std::mutex mutex_; sptr abilityMgrProxy_; - sptr mServiceCenterConnection_; + sptr serviceCenterConnection_; std::map freeInstallParamsMap_; sptr serviceCenterRemoteObject_; int32_t connectState_ = ServiceCenterConnectState::SERVICE_CENTER_DISCONNECTED; diff --git a/services/bundlemgr/src/free_install/bundle_connect_ability_mgr.cpp b/services/bundlemgr/src/free_install/bundle_connect_ability_mgr.cpp index ce13d7aa..9d68d8af 100644 --- a/services/bundlemgr/src/free_install/bundle_connect_ability_mgr.cpp +++ b/services/bundlemgr/src/free_install/bundle_connect_ability_mgr.cpp @@ -34,7 +34,7 @@ namespace AppExecFwk { const std::u16string ATOMIC_SERVICE_STATUS_CALLBACK_TOKEN = u"ohos.aafwk.IAtomicServiceStatusCallback"; const std::string serviceCenterBundleName = "com.ohos.hag.famanager"; const std::string serviceCenterAbilityName = "com.ohos.hag.famanager.HapInstallServiceAbility"; -constexpr uint32_t IAtomicServiceStatusCallback_ON_FREE_INSTALL_DONE = 0; +constexpr uint32_t FREE_INSTALL_DONE = 0; constexpr uint32_t CALLING_TYPE_HARMONY = 2; constexpr uint32_t BIT_ONE_COMPATIBLE = 0; constexpr uint32_t BIT_TWO_BACK_MODE = 1; @@ -61,7 +61,7 @@ BundleConnectAbilityMgr::~BundleConnectAbilityMgr() bool BundleConnectAbilityMgr::SilentInstallSafely(const TargetAbilityInfo &targetAbilityInfo, const Want &want, const sptr &callerToken, int32_t userId) { - APP_LOGI("start to SilentInstallSafely"); + APP_LOGI("SilentInstallSafely"); std::shared_ptr context = std::make_shared(); TaskPriority defaultPriority = TaskPriority::DEFAULT; std::shared_ptr ptrGlobalTaskDispatcher = context->GetGlobalTaskDispatcher(defaultPriority); @@ -89,7 +89,7 @@ bool BundleConnectAbilityMgr::SilentInstallSafely(const TargetAbilityInfo &targe bool BundleConnectAbilityMgr::UpgradeCheckSafely(const TargetAbilityInfo &targetAbilityInfo, const Want &want, const sptr &callerToken, int32_t userId) { - APP_LOGI("start to UpgradeCheckSafely"); + APP_LOGI("UpgradeCheckSafely"); std::shared_ptr context = std::make_shared(); TaskPriority defaultPriority = TaskPriority::DEFAULT; std::shared_ptr ptrGlobalTaskDispatcher = context->GetGlobalTaskDispatcher(defaultPriority); @@ -117,7 +117,7 @@ bool BundleConnectAbilityMgr::UpgradeCheckSafely(const TargetAbilityInfo &target bool BundleConnectAbilityMgr::UpgradeInstallSafely(const TargetAbilityInfo &targetAbilityInfo, const Want &want, const sptr &callerToken, int32_t userId) { - APP_LOGI("start to UpgradeInstallSafely"); + APP_LOGI("UpgradeInstallSafely"); std::shared_ptr context = std::make_shared(); TaskPriority defaultPriority = TaskPriority::DEFAULT; std::shared_ptr ptrGlobalTaskDispatcher = context->GetGlobalTaskDispatcher(defaultPriority); @@ -140,7 +140,6 @@ bool BundleConnectAbilityMgr::UpgradeInstallSafely(const TargetAbilityInfo &targ FreeInstallErrorCode::FREE_INSTALL_UNDEFINED_ERROR, want, userId, targetAbilityInfo.targetInfo.transactId); return false; } - APP_LOGI("end to create UpgradeInstallSafely"); return true; } @@ -150,7 +149,6 @@ bool BundleConnectAbilityMgr::RunnableFun(int32_t flag, const TargetAbilityInfo APP_LOGI("RunnableFun start"); Want serviceCenterWant; serviceCenterWant.SetElementName(serviceCenterBundleName, serviceCenterAbilityName); - APP_LOGI("ConnectAbility start"); bool isConnectSuccess = ConnectAbility(serviceCenterWant, callerToken); if (!isConnectSuccess) { APP_LOGE("fail to connect ServiceCenter"); @@ -165,9 +163,9 @@ bool BundleConnectAbilityMgr::RunnableFun(int32_t flag, const TargetAbilityInfo void BundleConnectAbilityMgr::DisconnectAbility() { - if (mServiceCenterConnection_ != nullptr) { + if (serviceCenterConnection_ != nullptr) { APP_LOGI("DisconnectAbility"); - abilityMgrProxy_->DisconnectAbility(mServiceCenterConnection_); + abilityMgrProxy_->DisconnectAbility(serviceCenterConnection_); } } @@ -175,36 +173,38 @@ bool BundleConnectAbilityMgr::ConnectAbility(const Want &want, const sptr lock(mutex_); - APP_LOGI("ConnectAbility lock"); if (connectState_ == ServiceCenterConnectState::SERVICE_CENTER_CONNECTING) { - APP_LOGI("ConnectAbility await start ServiceCenterConnectState::CONNECTING"); + APP_LOGI("ConnectAbility await start SERVICE_CENTER_CONNECTING"); cv_.wait(lock); - APP_LOGI("ConnectAbility await end ServiceCenterConnectState::CONNECTING"); + APP_LOGI("ConnectAbility await end SERVICE_CENTER_CONNECTING"); } else if (connectState_ == ServiceCenterConnectState::SERVICE_CENTER_DISCONNECTED) { connectState_ = ServiceCenterConnectState::SERVICE_CENTER_CONNECTING; if (!GetAbilityMgrProxy()) { + cv_.notify_all(); return false; } - APP_LOGI("Create mServiceCenterConnection"); - mServiceCenterConnection_ = new (std::nothrow) ServiceCenterConnection(connectState_, + + serviceCenterConnection_ = new (std::nothrow) ServiceCenterConnection(connectState_, cv_, freeInstallParamsMap_); - if (!mServiceCenterConnection_) { - APP_LOGE("mServiceCenterConnection_is nullptr"); + if (serviceCenterConnection_ == nullptr) { + APP_LOGE("mServiceCenterConnection is nullptr"); + cv_.notify_all(); return false; } APP_LOGI("Start ConnectAbility"); - int result = abilityMgrProxy_->ConnectAbility(want, mServiceCenterConnection_, callerToken); + int result = abilityMgrProxy_->ConnectAbility(want, serviceCenterConnection_, callerToken); if (result == ERR_OK) { if (connectState_ != ServiceCenterConnectState::SERVICE_CENTER_CONNECTED) { - APP_LOGI("ConnectAbility await start ServiceCenterConnectState::SERVICE_CENTER_CONNECTED"); + APP_LOGI("ConnectAbility await start SERVICE_CENTER_CONNECTED"); cv_.wait(lock); - serviceCenterRemoteObject_ = mServiceCenterConnection_->GetRemoteObject(); - APP_LOGI("ConnectAbility await end ServiceCenterConnectState::SERVICE_CENTER_CONNECTED"); + APP_LOGI("ConnectAbility await end SERVICE_CENTER_CONNECTED"); + serviceCenterRemoteObject_ = serviceCenterConnection_->GetRemoteObject(); } } else { APP_LOGE("ConnectAbility fail result = %{public}d", result); } } + APP_LOGI("ConnectAbility end"); if (connectState_ == ServiceCenterConnectState::SERVICE_CENTER_CONNECTED) { return true; @@ -256,7 +256,10 @@ void BundleConnectAbilityMgr::SendCallBack( } MessageParcel reply; MessageOption option; - amsCallBack->SendRequest(IAtomicServiceStatusCallback_ON_FREE_INSTALL_DONE, data, reply, option); + + if (amsCallBack->SendRequest(FREE_INSTALL_DONE, data, reply, option) != OHOS::NO_ERROR) { + APP_LOGE("BundleConnectAbilityMgr::SendCallBack SendRequest failed"); + } if (freeInstallParamsMap_.erase(transactId) && freeInstallParamsMap_.size() == 0) { if (connectState_ == ServiceCenterConnectState::SERVICE_CENTER_CONNECTED) { @@ -278,7 +281,7 @@ void BundleConnectAbilityMgr::OnServiceCenterCall(std::string installResultStr) FreeInstallParams freeInstallParams; auto node = freeInstallParamsMap_.find(installResult.result.transactId); if (node == freeInstallParamsMap_.end()) { - APP_LOGI("can not find node"); + APP_LOGE("can not find node"); return; } freeInstallParams = node->second; @@ -289,14 +292,10 @@ void BundleConnectAbilityMgr::OnServiceCenterCall(std::string installResultStr) installResult.progress.downloadSize, installResult.progress.totalSize); return; } - std::string bundleName = freeInstallParams.want.GetElement().GetBundleName(); - std::string moduleName = freeInstallParams.want.GetStringParam("moduleName"); - std::shared_ptr bms = DelayedSingleton::GetInstance(); - APP_LOGD("OnServiceCenterCall, freeInstallParams ServiceCenterFunction = %{public}d", - freeInstallParams.serviceCenterFunction); + APP_LOGD("serviceCenterFunction = %{public}d", freeInstallParams.serviceCenterFunction); SendCallBack(resultCode, freeInstallParams.want, freeInstallParams.userId, installResult.result.transactId); - APP_LOGD("OnServiceCenterCall, end"); + APP_LOGD("OnServiceCenterCall end"); } void BundleConnectAbilityMgr::OutTimeMonitor(std::string transactId) @@ -348,7 +347,7 @@ void BundleConnectAbilityMgr::SendRequest( return; } APP_LOGI("serviceCenterRemoteObject->SendRequest"); - serviceCenterRemoteObject_ = mServiceCenterConnection_->GetRemoteObject(); + serviceCenterRemoteObject_ = serviceCenterConnection_->GetRemoteObject(); int32_t result = serviceCenterRemoteObject_->SendRequest(flag, data, reply, option); APP_LOGI("SendRequest result = %{public}d", result); if (result != ERR_OK) { @@ -430,22 +429,25 @@ void BundleConnectAbilityMgr::CallAbilityManager( MessageParcel reply; MessageOption option; if (!data.WriteInterfaceToken(ATOMIC_SERVICE_STATUS_CALLBACK_TOKEN)) { - APP_LOGE("Write interface token failed"); - return; + APP_LOGE("Write interface token failed"); + return; } if (!data.WriteInt32(resultCode)) { - APP_LOGE("Write result code error"); - return; + APP_LOGE("Write result code error"); + return; } if (!data.WriteParcelable(&want)) { - APP_LOGE("Write want failed"); - return; + APP_LOGE("Write want failed"); + return; } if (!data.WriteInt32(userId)) { - APP_LOGE("Write userId error"); - return; + APP_LOGE("Write userId error"); + return; + } + + if (callBack->SendRequest(FREE_INSTALL_DONE, data, reply, option) != OHOS::NO_ERROR) { + APP_LOGE("BundleConnectAbilityMgr::CallAbilityManager SendRequest failed"); } - callBack->SendRequest(IAtomicServiceStatusCallback_ON_FREE_INSTALL_DONE, data, reply, option); } bool BundleConnectAbilityMgr::CheckIsModuleNeedUpdate( diff --git a/services/bundlemgr/src/free_install/service_center_connection.cpp b/services/bundlemgr/src/free_install/service_center_connection.cpp index 0d897d9d..f2817205 100644 --- a/services/bundlemgr/src/free_install/service_center_connection.cpp +++ b/services/bundlemgr/src/free_install/service_center_connection.cpp @@ -34,11 +34,13 @@ void ServiceCenterConnection::OnAbilityConnectDone( APP_LOGI("OnAbilityConnectDone start"); if (resultCode != ERR_OK) { APP_LOGE("OnAbilityConnectDone resultCode = %{public}d", resultCode); + cv_.notify_all(); return; } if (remoteObject == nullptr) { APP_LOGE("OnAbilityConnectDone resultCode is nullptr"); + cv_.notify_all(); return; } serviceCenterRemoteObject_ = remoteObject; diff --git a/services/bundlemgr/src/free_install/service_center_death_recipient.cpp b/services/bundlemgr/src/free_install/service_center_death_recipient.cpp index 2e66a841..1a2ab809 100644 --- a/services/bundlemgr/src/free_install/service_center_death_recipient.cpp +++ b/services/bundlemgr/src/free_install/service_center_death_recipient.cpp @@ -23,7 +23,7 @@ namespace OHOS { namespace AppExecFwk { const std::u16string ATOMIC_SERVICE_STATUS_CALLBACK_TOKEN = u"ohos.aafwk.IAtomicServiceStatusCallback"; -constexpr uint32_t IAtomicServiceStatusCallback_ON_FREE_INSTALL_DONE = 0; +constexpr uint32_t FREE_INSTALL_DONE = 0; void ServiceCenterDeathRecipient::OnRemoteDied(const wptr &wptrDeath) { @@ -73,8 +73,9 @@ void ServiceCenterDeathRecipient::SendCallBack(FreeInstallParams &freeInstallPar } MessageParcel reply; MessageOption option; - sptr amsCallBack = freeInstallParams.callback; - amsCallBack->SendRequest(IAtomicServiceStatusCallback_ON_FREE_INSTALL_DONE, data, reply, option); + if (freeInstallParams.callback->SendRequest(FREE_INSTALL_DONE, data, reply, option) != OHOS::NO_ERROR) { + APP_LOGE("BundleConnectAbilityMgr::SendCallBack SendRequest failed"); + } freeInstallParamsMap_.erase(transactId); } } // namespace AppExecFwk