mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2025-02-17 11:18:42 +00:00
connectExtension增加BMS ready校验
Signed-off-by: zhangyuhang72 <zhangyuhang72@huawei.com> Change-Id: Ia8d6a1abd19e6fcfdd431118cc639970a64abb3f
This commit is contained in:
parent
13bb6dd2d8
commit
bed752fd64
@ -73,11 +73,13 @@ private:
|
||||
|
||||
sptr<IExtensionManager> GetExtensionManager();
|
||||
void Connect();
|
||||
bool QueryBMSReady();
|
||||
void ResetProxy(const wptr<IRemoteObject>& remote);
|
||||
|
||||
std::mutex mutex_;
|
||||
sptr<IExtensionManager> proxy_;
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_;
|
||||
bool bmsReady_ = false;
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "extension_manager_client.h"
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "bundle_mgr_interface.h"
|
||||
#include "extension_ability_info.h"
|
||||
#include "extension_manager_proxy.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
@ -45,6 +46,14 @@ sptr<IExtensionManager> ExtensionManagerClient::GetExtensionManager()
|
||||
Connect();
|
||||
}
|
||||
|
||||
if (!bmsReady_) {
|
||||
if (!QueryBMSReady()) {
|
||||
TAG_LOGE(AAFwkTag::EXTMGR, "BMS not ready");
|
||||
return nullptr;
|
||||
}
|
||||
bmsReady_ = true;
|
||||
}
|
||||
|
||||
return proxy_;
|
||||
}
|
||||
|
||||
@ -71,9 +80,27 @@ void ExtensionManagerClient::Connect()
|
||||
TAG_LOGD(AAFwkTag::EXTMGR, "Connect AMS success");
|
||||
}
|
||||
|
||||
bool ExtensionManagerClient::QueryBMSReady()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::EXTMGR, "QueryBMSReady");
|
||||
auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (saManager == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::EXTMGR, "Get SAMgr failed");
|
||||
return false;
|
||||
}
|
||||
sptr<IRemoteObject> remoteObj = saManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
if (remoteObj == nullptr || iface_cast<AppExecFwk::IBundleMgr>(remoteObj) == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::EXTMGR, "Get bundleMgr remote object failed");
|
||||
return false;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::EXTMGR, "QueryBMSReady success");
|
||||
return true;
|
||||
}
|
||||
|
||||
void ExtensionManagerClient::ResetProxy(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
bmsReady_ = false;
|
||||
if (proxy_ == nullptr) {
|
||||
TAG_LOGI(AAFwkTag::EXTMGR, "null proxy_, no need reset");
|
||||
return;
|
||||
|
@ -62,6 +62,7 @@ HWTEST_F(ExtensionManagerClientTest, ExtensionManagerClientTest_001, TestSize.Le
|
||||
HWTEST_F(ExtensionManagerClientTest, ExtensionManagerClientTest_002, TestSize.Level1)
|
||||
{
|
||||
auto client = std::make_shared<ExtensionManagerClient>();
|
||||
client->bmsReady_ = true;
|
||||
EXPECT_NE(client->GetExtensionManager(), nullptr);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user