mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 01:10:52 +00:00
BundleMgrHelper增加bmsReady前置校验
Signed-off-by: zhangyuhang72 <zhangyuhang72@huawei.com> Change-Id: I11074ed291829230478d79cee18397a3dc946f61
This commit is contained in:
parent
13bb6dd2d8
commit
77eaf807c7
@ -35,7 +35,7 @@ BundleMgrHelper::~BundleMgrHelper()
|
||||
|
||||
void BundleMgrHelper::PreConnect()
|
||||
{
|
||||
Connect();
|
||||
Connect(false);
|
||||
}
|
||||
|
||||
ErrCode BundleMgrHelper::GetNameForUid(const int32_t uid, std::string &name)
|
||||
@ -216,18 +216,27 @@ std::string BundleMgrHelper::GetAppIdByBundleName(const std::string &bundleName,
|
||||
|
||||
void BundleMgrHelper::ConnectTillSuccess()
|
||||
{
|
||||
while (Connect() == nullptr) {
|
||||
while (Connect(false) == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "connect failed, now retry");
|
||||
usleep(REPOLL_TIME_MICRO_SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
sptr<IBundleMgr> BundleMgrHelper::Connect()
|
||||
{
|
||||
return Connect(true);
|
||||
}
|
||||
|
||||
sptr<IBundleMgr> BundleMgrHelper::Connect(bool checkBmsReady)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (bundleMgr_ == nullptr) {
|
||||
if (checkBmsReady && !bmsReady_) {
|
||||
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Bms not ready");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemAbilityManager == nullptr) {
|
||||
@ -240,6 +249,7 @@ sptr<IBundleMgr> BundleMgrHelper::Connect()
|
||||
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Failed to get bundle mgr service remote object");
|
||||
return nullptr;
|
||||
}
|
||||
bmsReady_ = true;
|
||||
std::weak_ptr<BundleMgrHelper> weakPtr = shared_from_this();
|
||||
auto deathCallback = [weakPtr](const wptr<IRemoteObject>& object) {
|
||||
auto sharedPtr = weakPtr.lock();
|
||||
@ -262,6 +272,13 @@ sptr<IBundleMgr> BundleMgrHelper::Connect()
|
||||
return bundleMgr_;
|
||||
}
|
||||
|
||||
void BundleMgrHelper::SetBmsReady(bool bmsReady)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::BUNDLEMGRHELPER, "SetBmsReady:%{public}d", bmsReady);
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
bmsReady_ = bmsReady;
|
||||
}
|
||||
|
||||
sptr<IBundleInstaller> BundleMgrHelper::ConnectBundleInstaller()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called");
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
DISALLOW_COPY_AND_MOVE(BundleMgrHelper);
|
||||
void PreConnect();
|
||||
void ConnectTillSuccess();
|
||||
void SetBmsReady(bool bmsReady);
|
||||
ErrCode GetNameForUid(const int32_t uid, std::string &name);
|
||||
ErrCode GetNameAndIndexForUid(const int32_t uid, std::string &bundleName, int32_t &appIndex);
|
||||
bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId);
|
||||
@ -110,6 +111,7 @@ public:
|
||||
|
||||
private:
|
||||
sptr<IBundleMgr> Connect();
|
||||
sptr<IBundleMgr> Connect(bool checkBmsReady);
|
||||
sptr<IBundleInstaller> ConnectBundleInstaller();
|
||||
void OnDeath();
|
||||
std::string ParseBundleNameByAppId(const std::string &appId) const;
|
||||
@ -120,6 +122,7 @@ private:
|
||||
sptr<IBundleMgr> bundleMgr_;
|
||||
sptr<IBundleInstaller> bundleInstaller_;
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
|
||||
bool bmsReady_ = true;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -295,6 +295,10 @@ void AbilityManagerService::OnStart()
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "instance_ null");
|
||||
return;
|
||||
}
|
||||
auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
|
||||
if (bundleMgrHelper) {
|
||||
bundleMgrHelper->SetBmsReady(false);
|
||||
}
|
||||
bool ret = Publish(instance_);
|
||||
if (!ret) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "publish failed");
|
||||
@ -2513,6 +2517,10 @@ void AbilityManagerService::OnAddSystemAbility(int32_t systemAbilityId, const st
|
||||
break;
|
||||
}
|
||||
case BUNDLE_MGR_SERVICE_SYS_ABILITY_ID: {
|
||||
auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
|
||||
if (bundleMgrHelper) {
|
||||
bundleMgrHelper->SetBmsReady(true);
|
||||
}
|
||||
SubscribeBundleEventCallback();
|
||||
break;
|
||||
}
|
||||
@ -6219,9 +6227,13 @@ void AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isB
|
||||
AppExecFwk::AbilityInfo abilityInfo;
|
||||
AppExecFwk::ExtensionAbilityInfo extensionAbilityInfo;
|
||||
int attemptNums = 0;
|
||||
while (!IN_PROCESS_CALL(bms->ImplicitQueryInfoByPriority(want,
|
||||
AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, userId,
|
||||
abilityInfo, extensionAbilityInfo))) {
|
||||
while (true) {
|
||||
bms->PreConnect();
|
||||
if (IN_PROCESS_CALL(bms->ImplicitQueryInfoByPriority(want,
|
||||
AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, userId,
|
||||
abilityInfo, extensionAbilityInfo))) {
|
||||
break;
|
||||
}
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "waiting query highest priority ability info completed");
|
||||
++attemptNums;
|
||||
if (!isBoot && attemptNums > SWITCH_ACCOUNT_TRY) {
|
||||
|
Loading…
Reference in New Issue
Block a user