mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 09:21:28 +00:00
Signed-off-by: caochunlei <caochunlei1@huawei.com>
This commit is contained in:
parent
d5eb24c613
commit
c46a858cba
@ -71,7 +71,7 @@ public:
|
||||
|
||||
private:
|
||||
static void ResolveAbilityInfos(const std::vector<AbilityInfo> &abilityInfos,
|
||||
std::vector<PurposeInfo> &purposeInfos, const AppInfo appInfo)
|
||||
std::vector<PurposeInfo> &purposeInfos, const AppInfo &appInfo)
|
||||
{
|
||||
if (abilityInfos.empty()) {
|
||||
return;
|
||||
@ -83,7 +83,7 @@ private:
|
||||
|
||||
static void ResolveExtAbilityInfos(const std::vector<ExtensionAbilityInfo> &extensionInfos,
|
||||
std::vector<PurposeInfo> &purposeInfos, std::vector<BusinessAbilityInfo> &businessAbilityInfos,
|
||||
const AppInfo appInfo)
|
||||
const AppInfo &appInfo)
|
||||
{
|
||||
if (extensionInfos.empty()) {
|
||||
return;
|
||||
@ -95,7 +95,7 @@ private:
|
||||
}
|
||||
|
||||
static void ConvertAbilityToPurposes(const AbilityInfo &abilityInfo, std::vector<PurposeInfo> &purposeInfos,
|
||||
const AppInfo appInfo)
|
||||
const AppInfo &appInfo)
|
||||
{
|
||||
std::string supportPurpose = GetAbilityMetadataValue(abilityInfo, SrConstants::METADATA_SUPPORT_PURPOSE_KEY);
|
||||
if (supportPurpose.empty()) {
|
||||
@ -118,7 +118,7 @@ private:
|
||||
}
|
||||
|
||||
static void ConvertExtAbilityToPurposes(const ExtensionAbilityInfo &extAbilityInfo,
|
||||
std::vector<PurposeInfo> &purposeInfos, const AppInfo appInfo)
|
||||
std::vector<PurposeInfo> &purposeInfos, const AppInfo &appInfo)
|
||||
{
|
||||
if (extAbilityInfo.type != ExtensionAbilityType::FORM && extAbilityInfo.type != ExtensionAbilityType::UI) {
|
||||
return;
|
||||
@ -161,7 +161,7 @@ private:
|
||||
}
|
||||
|
||||
static void ConvertExtAbilityToService(const ExtensionAbilityInfo &extAbilityInfo,
|
||||
std::vector<BusinessAbilityInfo> &businessAbilityInfos, const AppInfo appInfo)
|
||||
std::vector<BusinessAbilityInfo> &businessAbilityInfos, const AppInfo &appInfo)
|
||||
{
|
||||
if (extAbilityInfo.type != ExtensionAbilityType::UI) {
|
||||
return;
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "app_log_wrapper.h"
|
||||
#include "application_info.h"
|
||||
#include "bundle_info.h"
|
||||
#include "nocopyable.h"
|
||||
#include "service_info.h"
|
||||
#include "want.h"
|
||||
|
||||
@ -44,7 +43,7 @@ public:
|
||||
* @brief Find purposeInfo by purposeName.
|
||||
* @param purposeName Indicates the purposeName.
|
||||
* @param purposeInfos Indicates the PurposeInfos to be find.
|
||||
* @return Returns the PurposeInfo object if find it; returns null otherwise.
|
||||
* @return
|
||||
*/
|
||||
void FindPurposeInfos(const std::string &purposeName, std::vector<PurposeInfo> &purposeInfos) const;
|
||||
|
||||
|
@ -52,12 +52,6 @@ public:
|
||||
*/
|
||||
bool LoadBundleInfo(const std::string &bundleName);
|
||||
|
||||
/**
|
||||
* @brief update BundleInfo.
|
||||
* @param bundleInfo Indicates the bundle info.
|
||||
*/
|
||||
void UpdateBundleInfo(const BundleInfo &bundleInfo);
|
||||
|
||||
/**
|
||||
* @brief Delete bundle info from an exist BundleInfo.
|
||||
* @param bundleName Indicates the bundle name.
|
||||
@ -84,8 +78,16 @@ public:
|
||||
std::vector<PurposeInfo> &purposeInfos) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief update BundleInfo.
|
||||
* @param bundleInfo Indicates the bundle info.
|
||||
*/
|
||||
void UpdateBundleInfoLocked(const BundleInfo &bundleInfo);
|
||||
|
||||
BusinessType GetBusinessType(const BusinessAbilityFilter &filter) const;
|
||||
|
||||
void ClearAllBundleInfos();
|
||||
|
||||
private:
|
||||
mutable std::mutex bundleInfoMutex_;
|
||||
std::map<std::string, InnerServiceInfo> innerServiceInfos_;
|
||||
|
@ -47,8 +47,20 @@ public:
|
||||
static int32_t GetCurrentActiveUserId();
|
||||
|
||||
private:
|
||||
class BmsDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
BmsDeathRecipient() = default;
|
||||
virtual ~BmsDeathRecipient() = default;
|
||||
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
|
||||
};
|
||||
|
||||
void ConnectBundleMgrLocked();
|
||||
void ResetProxy(const wptr<IRemoteObject> &remote);
|
||||
|
||||
std::mutex bundleMgrMutex_;
|
||||
sptr<IBundleMgr> iBundleMgr_ = nullptr;
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_; // bms death recipient.
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -25,13 +25,14 @@
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
const std::string SCHEME_SEPARATOR = "://";
|
||||
const std::string SCHEME_SERVICE_ROUTER = "servicerouter";
|
||||
const std::string SCHEME_SEPARATOR = "://";
|
||||
const std::string SCHEME_SERVICE_ROUTER = "servicerouter";
|
||||
}
|
||||
|
||||
bool ServiceRouterDataMgr::LoadAllBundleInfos()
|
||||
{
|
||||
APP_LOGD("SRDM LoadAllBundleInfos");
|
||||
ClearAllBundleInfos();
|
||||
auto bms = SrSamgrHelper::GetInstance().GetBundleMgr();
|
||||
if (bms == nullptr) {
|
||||
APP_LOGE("SRDM GetBundleMgr return null");
|
||||
@ -39,17 +40,16 @@ bool ServiceRouterDataMgr::LoadAllBundleInfos()
|
||||
}
|
||||
auto flags = (BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO);
|
||||
std::vector<BundleInfo> bundleInfos;
|
||||
bool ret = bms->GetBundleInfos(flags, bundleInfos, SrSamgrHelper::GetCurrentActiveUserId());
|
||||
if (!ret) {
|
||||
if (!bms->GetBundleInfos(flags, bundleInfos, SrSamgrHelper::GetCurrentActiveUserId())) {
|
||||
APP_LOGE("SRDM bms->GetBundleInfos return false");
|
||||
return false;
|
||||
}
|
||||
if (!innerServiceInfos_.empty()) {
|
||||
innerServiceInfos_.clear();
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(bundleInfoMutex_);
|
||||
for (const auto &bundleInfo : bundleInfos) {
|
||||
UpdateBundleInfo(bundleInfo);
|
||||
UpdateBundleInfoLocked(bundleInfo);
|
||||
}
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ServiceRouterDataMgr::LoadBundleInfo(const std::string &bundleName)
|
||||
@ -62,15 +62,17 @@ bool ServiceRouterDataMgr::LoadBundleInfo(const std::string &bundleName)
|
||||
}
|
||||
BundleInfo bundleInfo;
|
||||
auto flags = (BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO);
|
||||
bool ret = bms->GetBundleInfo(bundleName, flags, bundleInfo, SrSamgrHelper::GetCurrentActiveUserId());
|
||||
if (!ret) {
|
||||
if (!bms->GetBundleInfo(bundleName, flags, bundleInfo, SrSamgrHelper::GetCurrentActiveUserId())) {
|
||||
APP_LOGE("SRDM bms->GetBundleInfos return false");
|
||||
return false;
|
||||
}
|
||||
UpdateBundleInfo(bundleInfo);
|
||||
return ret;
|
||||
|
||||
std::lock_guard<std::mutex> lock(bundleInfoMutex_);
|
||||
UpdateBundleInfoLocked(bundleInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ServiceRouterDataMgr::UpdateBundleInfo(const BundleInfo &bundleInfo)
|
||||
void ServiceRouterDataMgr::UpdateBundleInfoLocked(const BundleInfo &bundleInfo)
|
||||
{
|
||||
APP_LOGD("SRDM UpdateBundleInfo");
|
||||
InnerServiceInfo innerServiceInfo;
|
||||
@ -84,7 +86,6 @@ void ServiceRouterDataMgr::UpdateBundleInfo(const BundleInfo &bundleInfo)
|
||||
std::vector<BusinessAbilityInfo> businessAbilityInfos;
|
||||
if (BundleInfoResolveUtil::ResolveBundleInfo(bundleInfo, purposeInfos, businessAbilityInfos,
|
||||
innerServiceInfo.GetAppInfo())) {
|
||||
std::lock_guard<std::mutex> lock(bundleInfoMutex_);
|
||||
innerServiceInfo.UpdateInnerServiceInfo(purposeInfos, businessAbilityInfos);
|
||||
innerServiceInfos_.try_emplace(bundleInfo.name, innerServiceInfo);
|
||||
}
|
||||
@ -112,6 +113,7 @@ int32_t ServiceRouterDataMgr::QueryBusinessAbilityInfos(const BusinessAbilityFil
|
||||
return ERR_BUNDLE_MANAGER_PARAM_ERROR;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(bundleInfoMutex_);
|
||||
for (const auto &item : innerServiceInfos_) {
|
||||
item.second.FindBusinessAbilityInfos(validType, businessAbilityInfos);
|
||||
}
|
||||
@ -127,6 +129,7 @@ int32_t ServiceRouterDataMgr::QueryPurposeInfos(const Want &want, const std::str
|
||||
return ERR_BUNDLE_MANAGER_PARAM_ERROR;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(bundleInfoMutex_);
|
||||
ElementName element = want.GetElement();
|
||||
std::string bundleName = element.GetBundleName();
|
||||
if (bundleName.empty()) {
|
||||
@ -161,5 +164,13 @@ BusinessType ServiceRouterDataMgr::GetBusinessType(const BusinessAbilityFilter &
|
||||
}
|
||||
return BundleInfoResolveUtil::findBusinessType(uri.GetHost());
|
||||
}
|
||||
|
||||
void ServiceRouterDataMgr::ClearAllBundleInfos()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(bundleInfoMutex_);
|
||||
if (!innerServiceInfos_.empty()) {
|
||||
innerServiceInfos_.clear();
|
||||
}
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -86,11 +86,11 @@ void ServiceRouterMgrService::DelayUnloadTask()
|
||||
APP_LOGI("DelayUnloadTask, handler_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::lock_guard<std::mutex> lock(delayTaskMutex_);
|
||||
handler_->RemoveTask(TASK_NAME);
|
||||
auto task = [this]() {
|
||||
APP_LOGE("UnloadSA start.");
|
||||
APP_LOGI("UnloadSA start.");
|
||||
sptr<ISystemAbilityManager> saManager =
|
||||
OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (saManager == nullptr) {
|
||||
@ -110,9 +110,9 @@ void ServiceRouterMgrService::DelayUnloadTask()
|
||||
bool ServiceRouterMgrService::LoadAllBundleInfos()
|
||||
{
|
||||
APP_LOGD("LoadAllBundleInfos start");
|
||||
ServiceRouterDataMgr::GetInstance().LoadAllBundleInfos();
|
||||
bool ret = ServiceRouterDataMgr::GetInstance().LoadAllBundleInfos();
|
||||
APP_LOGD("LoadAllBundleInfos end");
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ServiceRouterMgrService::InitEventRunnerAndHandler()
|
||||
@ -158,7 +158,7 @@ bool ServiceRouterMgrService::ServiceRouterMgrService::SubscribeCommonEvent()
|
||||
int32_t ServiceRouterMgrService::QueryBusinessAbilityInfos(const BusinessAbilityFilter &filter,
|
||||
std::vector< BusinessAbilityInfo> &businessAbilityInfos)
|
||||
{
|
||||
APP_LOGD("%{public}s coldStart:", __func__);
|
||||
APP_LOGD("coldStart:");
|
||||
DelayUnloadTask();
|
||||
return ServiceRouterDataMgr::GetInstance().QueryBusinessAbilityInfos(filter, businessAbilityInfos);
|
||||
}
|
||||
@ -166,7 +166,7 @@ int32_t ServiceRouterMgrService::QueryBusinessAbilityInfos(const BusinessAbility
|
||||
int32_t ServiceRouterMgrService::QueryPurposeInfos(const Want &want, const std::string purposeName,
|
||||
std::vector<PurposeInfo> &purposeInfos)
|
||||
{
|
||||
APP_LOGD("%{public}s coldStart:", __func__);
|
||||
APP_LOGD("coldStart:");
|
||||
DelayUnloadTask();
|
||||
return ServiceRouterDataMgr::GetInstance().QueryPurposeInfos(want, purposeName, purposeInfos);
|
||||
}
|
||||
|
@ -69,16 +69,14 @@ int ServiceRouterMgrStub::HandleQueryBusinessAbilityInfos(MessageParcel &data, M
|
||||
APP_LOGE("verify GET_BUNDLE_INFO_PRIVILEGED failed");
|
||||
return ERR_BUNDLE_MANAGER_PERMISSION_DENIED;
|
||||
}
|
||||
BusinessAbilityFilter *filter = data.ReadParcelable<BusinessAbilityFilter>();
|
||||
|
||||
std::unique_ptr<BusinessAbilityFilter> filter(data.ReadParcelable<BusinessAbilityFilter>());
|
||||
if (filter == nullptr) {
|
||||
APP_LOGE("ReadParcelable<filter> failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
std::vector<BusinessAbilityInfo> infos;
|
||||
int ret = QueryBusinessAbilityInfos(*filter, infos);
|
||||
if (filter != nullptr) {
|
||||
delete filter;
|
||||
}
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
APP_LOGE("write ret failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
@ -99,7 +97,7 @@ int ServiceRouterMgrStub::HandleQueryPurposeInfos(MessageParcel &data, MessagePa
|
||||
APP_LOGE("verify GET_BUNDLE_INFO_PRIVILEGED failed");
|
||||
return ERR_BUNDLE_MANAGER_PERMISSION_DENIED;
|
||||
}
|
||||
Want *want = data.ReadParcelable<Want>();
|
||||
std::unique_ptr<Want> want(data.ReadParcelable<Want>());
|
||||
if (want == nullptr) {
|
||||
APP_LOGE("ReadParcelable<want> failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
@ -107,9 +105,6 @@ int ServiceRouterMgrStub::HandleQueryPurposeInfos(MessageParcel &data, MessagePa
|
||||
std::string purposeName = data.ReadString();
|
||||
std::vector<PurposeInfo> infos;
|
||||
int ret = QueryPurposeInfos(*want, purposeName, infos);
|
||||
if (want != nullptr) {
|
||||
delete want;
|
||||
}
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
APP_LOGE("write ret failed");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
|
@ -39,15 +39,15 @@ void SrCommonEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &ev
|
||||
std::string action = want.GetAction();
|
||||
std::string bundleName = want.GetElement().GetBundleName();
|
||||
if (action.empty() || eventHandler_ == nullptr) {
|
||||
APP_LOGE("%{public}s failed, empty action: %{public}s, or invalid event handler", __func__, action.c_str());
|
||||
APP_LOGE("failed, empty action: %{public}s, or invalid event handler", action.c_str());
|
||||
return;
|
||||
}
|
||||
if (bundleName.empty() && action != EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
|
||||
APP_LOGE("%{public}s failed, invalid param, action: %{public}s, bundleName: %{public}s",
|
||||
__func__, action.c_str(), bundleName.c_str());
|
||||
APP_LOGE("failed, invalid param, action: %{public}s, bundleName: %{public}s",
|
||||
action.c_str(), bundleName.c_str());
|
||||
return;
|
||||
}
|
||||
APP_LOGI("%{public}s, action:%{public}s.", __func__, action.c_str());
|
||||
APP_LOGI("action:%{public}s.", action.c_str());
|
||||
std::weak_ptr<SrCommonEventSubscriber> weakThis = shared_from_this();
|
||||
if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
|
||||
int32_t userId = eventData.GetCode();
|
||||
@ -79,7 +79,7 @@ void SrCommonEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &ev
|
||||
};
|
||||
eventHandler_->PostTask(task);
|
||||
} else {
|
||||
APP_LOGW("%{public}s warnning, invalid action.", __func__);
|
||||
APP_LOGW("warnning, invalid action.");
|
||||
}
|
||||
}
|
||||
} // AbilityRuntime
|
||||
|
@ -39,19 +39,7 @@ sptr<IBundleMgr> SrSamgrHelper::GetBundleMgr()
|
||||
APP_LOGI("GetBundleMgr called.");
|
||||
std::lock_guard<std::mutex> lock(bundleMgrMutex_);
|
||||
if (iBundleMgr_ == nullptr) {
|
||||
sptr<ISystemAbilityManager> saManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
auto remoteObj = saManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
if (remoteObj == nullptr) {
|
||||
APP_LOGE("%{public}s error, failed to get bms remoteObj.", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
iBundleMgr_ = iface_cast<IBundleMgr>(remoteObj);
|
||||
if (iBundleMgr_ == nullptr) {
|
||||
APP_LOGE("%{public}s error, failed to get bms", __func__);
|
||||
return nullptr;
|
||||
}
|
||||
ConnectBundleMgrLocked();
|
||||
}
|
||||
return iBundleMgr_;
|
||||
}
|
||||
@ -76,5 +64,58 @@ int32_t SrSamgrHelper::GetCurrentActiveUserId()
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SrSamgrHelper::ConnectBundleMgrLocked()
|
||||
{
|
||||
if (iBundleMgr_ != nullptr) {
|
||||
return;
|
||||
}
|
||||
sptr<ISystemAbilityManager> saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (saManager == nullptr) {
|
||||
APP_LOGE("failed to get bms saManager.");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObj = saManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
if (remoteObj == nullptr) {
|
||||
APP_LOGE("failed to get bms remoteObj.");
|
||||
return;
|
||||
}
|
||||
|
||||
deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new (std::nothrow) BmsDeathRecipient());
|
||||
if (deathRecipient_ == nullptr) {
|
||||
APP_LOGE("Failed to create BmsDeathRecipient!");
|
||||
return;
|
||||
}
|
||||
if ((remoteObj->IsProxyObject()) && (!remoteObj->AddDeathRecipient(deathRecipient_))) {
|
||||
APP_LOGE("Add death recipient to bms failed.");
|
||||
return;
|
||||
}
|
||||
iBundleMgr_ = iface_cast<IBundleMgr>(remoteObj);
|
||||
if (iBundleMgr_ == nullptr) {
|
||||
APP_LOGE("iface_cast failed, failed to get bms");
|
||||
}
|
||||
}
|
||||
|
||||
void SrSamgrHelper::ResetProxy(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(bundleMgrMutex_);
|
||||
if (iBundleMgr_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto serviceRemote = iBundleMgr_->AsObject();
|
||||
if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
|
||||
APP_LOGD("To remove death recipient.");
|
||||
serviceRemote->RemoveDeathRecipient(deathRecipient_);
|
||||
iBundleMgr_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void SrSamgrHelper::BmsDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
APP_LOGI("BmsDeathRecipient handle remote abilityms died.");
|
||||
SrSamgrHelper::GetInstance().ResetProxy(remote);
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user