mirror of
https://github.com/openharmony/appexecfwk_standard.git
synced 2026-07-19 22:14:29 -04:00
@@ -73,6 +73,7 @@ public:
|
||||
*/
|
||||
bool UpgradeInstallSafely(const TargetAbilityInfo &targetAbilityInfo, const Want &want,
|
||||
const sptr<IRemoteObject> &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<std::string> &bundleNames, std::vector<std::string>& 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> &targetAbilityInfo, sptr<TargetInfo> &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<IRemoteObject> &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<IRemoteObject> &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<IRemoteObject> &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<IRemoteObject> &callBack);
|
||||
bool GetAbilityMgrProxy();
|
||||
|
||||
mutable std::atomic<int> transactId_ = 0;
|
||||
std::condition_variable cv_;
|
||||
std::mutex mutex_;
|
||||
sptr<AAFwk::IAbilityManager> abilityMgrProxy_;
|
||||
sptr<ServiceCenterConnection> mServiceCenterConnection_;
|
||||
sptr<ServiceCenterConnection> serviceCenterConnection_;
|
||||
std::map<std::string, FreeInstallParams> freeInstallParamsMap_;
|
||||
sptr<IRemoteObject> serviceCenterRemoteObject_;
|
||||
int32_t connectState_ = ServiceCenterConnectState::SERVICE_CENTER_DISCONNECTED;
|
||||
|
||||
@@ -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<IRemoteObject> &callerToken, int32_t userId)
|
||||
{
|
||||
APP_LOGI("start to SilentInstallSafely");
|
||||
APP_LOGI("SilentInstallSafely");
|
||||
std::shared_ptr<TaskDispatcherContext> context = std::make_shared<TaskDispatcherContext>();
|
||||
TaskPriority defaultPriority = TaskPriority::DEFAULT;
|
||||
std::shared_ptr<TaskDispatcher> 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<IRemoteObject> &callerToken, int32_t userId)
|
||||
{
|
||||
APP_LOGI("start to UpgradeCheckSafely");
|
||||
APP_LOGI("UpgradeCheckSafely");
|
||||
std::shared_ptr<TaskDispatcherContext> context = std::make_shared<TaskDispatcherContext>();
|
||||
TaskPriority defaultPriority = TaskPriority::DEFAULT;
|
||||
std::shared_ptr<TaskDispatcher> 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<IRemoteObject> &callerToken, int32_t userId)
|
||||
{
|
||||
APP_LOGI("start to UpgradeInstallSafely");
|
||||
APP_LOGI("UpgradeInstallSafely");
|
||||
std::shared_ptr<TaskDispatcherContext> context = std::make_shared<TaskDispatcherContext>();
|
||||
TaskPriority defaultPriority = TaskPriority::DEFAULT;
|
||||
std::shared_ptr<TaskDispatcher> 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<IRemot
|
||||
{
|
||||
APP_LOGI("ConnectAbility start target bundle = %{public}s", want.GetBundle().c_str());
|
||||
std::unique_lock<std::mutex> 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<BundleMgrService> bms = DelayedSingleton<BundleMgrService>::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(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<IRemoteObject> &wptrDeath)
|
||||
{
|
||||
@@ -73,8 +73,9 @@ void ServiceCenterDeathRecipient::SendCallBack(FreeInstallParams &freeInstallPar
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
sptr<IRemoteObject> 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
|
||||
|
||||
Reference in New Issue
Block a user