mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 06:20:07 +00:00
Init时序修改
Signed-off-by: 韦国庆 <weiguoqing2@huawei.com>
This commit is contained in:
parent
aa4bb7e4c5
commit
0713d0c9d9
@ -87,7 +87,6 @@ public:
|
||||
void OnContinueSwitchOff();
|
||||
void OnUserSwitch();
|
||||
std::string GetContinueType(const std::string& bundleName);
|
||||
bool CheckRegSoftbusListener();
|
||||
|
||||
private:
|
||||
void StartEvent();
|
||||
@ -119,7 +118,6 @@ private:
|
||||
std::mutex eventMutex_;
|
||||
std::mutex iconMutex_;
|
||||
std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler_;
|
||||
bool hasRegSoftbusEventListener_ = false;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -34,8 +34,8 @@ public:
|
||||
void OnUserSwitched(int32_t userId);
|
||||
void OnUserRemoved(int32_t userId);
|
||||
AccountSA::OsAccountType GetOsAccountType(int32_t &accountId);
|
||||
int32_t CreateNewSendMgr();
|
||||
int32_t CreateNewRecvMgr();
|
||||
int32_t CreateNewSendMgrLocked();
|
||||
int32_t CreateNewRecvMgrLocked();
|
||||
std::shared_ptr<DMSContinueSendMgr> GetCurrentSendMgr();
|
||||
std::shared_ptr<DMSContinueRecvMgr> GetCurrentRecvMgr();
|
||||
std::shared_ptr<DMSContinueSendMgr> GetSendMgrByCallingUid(int32_t callingUid);
|
||||
@ -45,6 +45,8 @@ public:
|
||||
int32_t GetForegroundUser();
|
||||
bool IsUserForeground(int32_t userId);
|
||||
bool IsCallerForeground(int32_t callingUid);
|
||||
bool CheckRegSoftbusListener();
|
||||
void RegisterSoftbusListener();
|
||||
|
||||
private:
|
||||
void UserSwitchedOnRegisterListenerCache();
|
||||
@ -57,6 +59,7 @@ private:
|
||||
std::mutex sendMutex_;
|
||||
std::mutex recvMutex_;
|
||||
std::mutex listenerMutex_;
|
||||
bool hasRegSoftbusEventListener_ = false;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -270,15 +270,10 @@ void DistributedSchedService::DeviceOnlineNotify(const std::string& networkId)
|
||||
DistributedSchedAdapter::GetInstance().DeviceOnline(networkId);
|
||||
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
|
||||
DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(networkId);
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
if (!recvMgr->CheckRegSoftbusListener() &&
|
||||
if (!MultiUserManager::GetInstance().CheckRegSoftbusListener() &&
|
||||
DistributedHardware::DeviceManager::GetInstance().IsSameAccount(networkId)) {
|
||||
HILOGI("DMSContinueRecvMgr need init");
|
||||
recvMgr->Init();
|
||||
MultiUserManager::GetInstance().RegisterSoftbusListener();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -403,15 +403,10 @@ void DtbschedmgrDeviceInfoStorage::DeviceOfflineNotify(const std::string& networ
|
||||
void DtbschedmgrDeviceInfoStorage::OnDeviceInfoChanged(const std::string& deviceId)
|
||||
{
|
||||
HILOGI("OnDeviceInfoChanged called");
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
if (!recvMgr->CheckRegSoftbusListener() &&
|
||||
if (!MultiUserManager::GetInstance().CheckRegSoftbusListener() &&
|
||||
DistributedHardware::DeviceManager::GetInstance().IsSameAccount(deviceId)) {
|
||||
HILOGI("DMSContinueRecvMgr need init");
|
||||
recvMgr->Init();
|
||||
MultiUserManager::GetInstance().RegisterSoftbusListener();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,6 @@ void DMSContinueRecvMgr::Init()
|
||||
return;
|
||||
}
|
||||
{
|
||||
hasRegSoftbusEventListener_ = true;
|
||||
missionDiedListener_ = new DistributedMissionDiedListener();
|
||||
eventThread_ = std::thread(&DMSContinueRecvMgr::StartEvent, this);
|
||||
std::unique_lock<std::mutex> lock(eventMutex_);
|
||||
@ -658,10 +657,5 @@ std::string DMSContinueRecvMgr::GetContinueType(const std::string& bundleName)
|
||||
|
||||
return iconInfo_.continueType;
|
||||
}
|
||||
|
||||
bool DMSContinueRecvMgr::CheckRegSoftbusListener()
|
||||
{
|
||||
return hasRegSoftbusEventListener_;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -44,18 +44,13 @@ void MultiUserManager::Init()
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->Init();
|
||||
auto recvMgr = GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
recvMgr->Init();
|
||||
std::shared_ptr<SoftbusAdapterListener> missionBroadcastListener =
|
||||
std::make_shared<DistributedMissionBroadcastListener>();
|
||||
int32_t ret = SoftbusAdapter::GetInstance().RegisterSoftbusEventListener(missionBroadcastListener);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("get RegisterSoftbusEventListener failed, ret: %{public}d", ret);
|
||||
if (!CheckRegSoftbusListener()) {
|
||||
RegisterSoftbusListener();
|
||||
}
|
||||
HILOGI("Init end.");
|
||||
}
|
||||
@ -130,14 +125,11 @@ void MultiUserManager::OnUserSwitched(int32_t accountId)
|
||||
HILOGI("GetSendMgr failed.");
|
||||
return;
|
||||
}
|
||||
sendMgr->Init();
|
||||
recvMgr = GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
recvMgr->Init();
|
||||
|
||||
if (!DataShareManager::GetInstance().IsCurrentContinueSwitchOn()) {
|
||||
recvMgr->OnContinueSwitchOff();
|
||||
HILOGI("ICurrentContinueSwitch is off, %{public}d", DataShareManager::GetInstance()
|
||||
@ -214,19 +206,21 @@ AccountSA::OsAccountType MultiUserManager::GetOsAccountType(int32_t &accountId)
|
||||
return type;
|
||||
}
|
||||
|
||||
int32_t MultiUserManager::CreateNewSendMgr()
|
||||
int32_t MultiUserManager::CreateNewSendMgrLocked()
|
||||
{
|
||||
HILOGI("CreateNewSendMgr begin. accountId: %{public}d.", currentUserId_);
|
||||
auto sendMgr = std::make_shared<DMSContinueSendMgr>();
|
||||
sendMgr->Init();
|
||||
sendMgrMap_.emplace(currentUserId_, sendMgr);
|
||||
HILOGI("CreateNewSendMgr end.");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t MultiUserManager::CreateNewRecvMgr()
|
||||
int32_t MultiUserManager::CreateNewRecvMgrLocked()
|
||||
{
|
||||
HILOGI("CreateNewRecvMgr begin. accountId: %{public}d.", currentUserId_);
|
||||
auto recvMgr = std::make_shared<DMSContinueRecvMgr>();
|
||||
recvMgr->Init();
|
||||
recvMgrMap_.emplace(currentUserId_, recvMgr);
|
||||
HILOGI("CreateNewRecvMgr end.");
|
||||
return ERR_OK;
|
||||
@ -238,7 +232,7 @@ std::shared_ptr<DMSContinueSendMgr> MultiUserManager::GetCurrentSendMgr()
|
||||
std::lock_guard<std::mutex> lock(sendMutex_);
|
||||
if (sendMgrMap_.empty() || sendMgrMap_.find(currentUserId_) == sendMgrMap_.end()) {
|
||||
HILOGI("sendMgr need to create.");
|
||||
CreateNewSendMgr();
|
||||
CreateNewSendMgrLocked();
|
||||
}
|
||||
auto cur = sendMgrMap_.find(currentUserId_);
|
||||
return cur->second;
|
||||
@ -250,7 +244,7 @@ std::shared_ptr<DMSContinueRecvMgr> MultiUserManager::GetCurrentRecvMgr()
|
||||
std::lock_guard<std::mutex> lock(recvMutex_);
|
||||
if (recvMgrMap_.empty() || recvMgrMap_.find(currentUserId_) == recvMgrMap_.end()) {
|
||||
HILOGI("recvMgr need to create.");
|
||||
CreateNewRecvMgr();
|
||||
CreateNewRecvMgrLocked();
|
||||
}
|
||||
auto cur = recvMgrMap_.find(currentUserId_);
|
||||
return cur->second;
|
||||
@ -260,11 +254,11 @@ std::shared_ptr<DMSContinueSendMgr> MultiUserManager::GetSendMgrByCallingUid(int
|
||||
{
|
||||
int32_t accountId = -1;
|
||||
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, accountId);
|
||||
HILOGI("GetRecvMgrByCallingUid. accountId: %{public}d , callingUid: %{public}d.", accountId, callingUid);
|
||||
HILOGI("GetSendMgrByCallingUid. accountId: %{public}d , callingUid: %{public}d.", accountId, callingUid);
|
||||
std::lock_guard<std::mutex> lock(sendMutex_);
|
||||
if (sendMgrMap_.empty() || sendMgrMap_.find(accountId) == sendMgrMap_.end()) {
|
||||
HILOGI("sendMgr need to create.");
|
||||
CreateNewSendMgr();
|
||||
CreateNewSendMgrLocked();
|
||||
}
|
||||
auto cur = sendMgrMap_.find(accountId);
|
||||
return cur->second;
|
||||
@ -278,7 +272,7 @@ std::shared_ptr<DMSContinueRecvMgr> MultiUserManager::GetRecvMgrByCallingUid(int
|
||||
std::lock_guard<std::mutex> lock(recvMutex_);
|
||||
if (recvMgrMap_.empty() || recvMgrMap_.find(accountId) == recvMgrMap_.end()) {
|
||||
HILOGI("recvMgr need to create.");
|
||||
CreateNewRecvMgr();
|
||||
CreateNewRecvMgrLocked();
|
||||
}
|
||||
auto cur = recvMgrMap_.find(accountId);
|
||||
return cur->second;
|
||||
@ -361,5 +355,23 @@ bool MultiUserManager::IsCallerForeground(int32_t callingUid)
|
||||
OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, accountId);
|
||||
return IsUserForeground(accountId);
|
||||
}
|
||||
|
||||
void MultiUserManager::RegisterSoftbusListener()
|
||||
{
|
||||
HILOGI("Register softbusListener start. accountId: %{public}d.", currentUserId_);
|
||||
std::shared_ptr<SoftbusAdapterListener> missionBroadcastListener =
|
||||
std::make_shared<DistributedMissionBroadcastListener>();
|
||||
int32_t ret = SoftbusAdapter::GetInstance().RegisterSoftbusEventListener(missionBroadcastListener);
|
||||
if (ret != ERR_OK) {
|
||||
HILOGE("get RegisterSoftbusEventListener failed, ret: %{public}d", ret);
|
||||
}
|
||||
hasRegSoftbusEventListener_ = true;
|
||||
HILOGI("Register softbusListener end.");
|
||||
}
|
||||
|
||||
bool MultiUserManager::CheckRegSoftbusListener()
|
||||
{
|
||||
return hasRegSoftbusEventListener_;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
@ -179,11 +179,8 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_CreateNewSendMgr_001, TestSize.L
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with create current user sendMgr;
|
||||
*/
|
||||
MultiUserManager::GetInstance().Init();
|
||||
int32_t ret = MultiUserManager::GetInstance().CreateNewSendMgr();
|
||||
int32_t ret = MultiUserManager::GetInstance().CreateNewSendMgrLocked();
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_CreateNewSendMgr_001 end" << std::endl;
|
||||
}
|
||||
|
||||
@ -198,11 +195,8 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_CreateNewRecvMgr_001, TestSize.L
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with create current user recvMgr;
|
||||
*/
|
||||
MultiUserManager::GetInstance().Init();
|
||||
int32_t ret = MultiUserManager::GetInstance().CreateNewRecvMgr();
|
||||
int32_t ret = MultiUserManager::GetInstance().CreateNewRecvMgrLocked();
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_CreateNewRecvMgr_001 end" << std::endl;
|
||||
}
|
||||
|
||||
@ -246,7 +240,7 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_GetCurrentRecvMgr_001, TestSize.
|
||||
int32_t accountId = 100;
|
||||
MultiUserManager::GetInstance().Init();
|
||||
auto recvMgr = MultiUserManager::GetInstance().recvMgrMap_.find(accountId)->second;
|
||||
|
||||
MultiUserManager::GetInstance().hasRegSoftbusEventListener_ = true;
|
||||
auto ret = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
EXPECT_EQ(ret, recvMgr);
|
||||
|
||||
@ -259,6 +253,53 @@ HWTEST_F(MultiUserManagerTest, MultiUserManager_GetCurrentRecvMgr_001, TestSize.
|
||||
DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_GetCurrentRecvMgr_002
|
||||
* @tc.desc: test GetCurrentRecvMgr
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_GetCurrentRecvMgr_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_002 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with create current user recvMgr;
|
||||
*/
|
||||
int32_t accountId = 100;
|
||||
MultiUserManager::GetInstance().Init();
|
||||
auto recvMgr = MultiUserManager::GetInstance().recvMgrMap_.find(accountId)->second;
|
||||
MultiUserManager::GetInstance().hasRegSoftbusEventListener_ = false;
|
||||
auto ret = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
EXPECT_EQ(ret, recvMgr);
|
||||
EXPECT_TRUE(MultiUserManager::GetInstance().hasRegSoftbusEventListener_);
|
||||
|
||||
MultiUserManager::GetInstance().recvMgrMap_.insert({accountId, nullptr});
|
||||
ret = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
EXPECT_NE(ret, nullptr);
|
||||
|
||||
|
||||
MultiUserManager::GetInstance().UnInit();
|
||||
DTEST_LOG << "MultiUserManager_GetCurrentRecvMgr_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_CheckRegSoftbusListener_001
|
||||
* @tc.desc: test CheckRegSoftbusListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MultiUserManagerTest, MultiUserManager_CheckRegSoftbusListener_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "MultiUserManager_CheckRegSoftbusListener_001 start" << std::endl;
|
||||
/**
|
||||
* @tc.steps: step1. test OnUserRemoved with create current user recvMgr;
|
||||
*/
|
||||
MultiUserManager::GetInstance().hasRegSoftbusEventListener_ = false;
|
||||
EXPECT_FALSE(MultiUserManager::GetInstance().CheckRegSoftbusListener());
|
||||
MultiUserManager::GetInstance().RegisterSoftbusListener();
|
||||
EXPECT_TRUE(MultiUserManager::GetInstance().hasRegSoftbusEventListener_);
|
||||
EXPECT_TRUE(MultiUserManager::GetInstance().CheckRegSoftbusListener());
|
||||
DTEST_LOG << "MultiUserManager_CheckRegSoftbusListener_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MultiUserManager_OnRegisterOnListener_001
|
||||
* @tc.desc: test OnRegisterOnListener
|
||||
|
Loading…
Reference in New Issue
Block a user