mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-22 22:09:58 +00:00
commit
692c841d6b
@ -85,6 +85,7 @@ public:
|
||||
void NotifyPackageRemoved(const std::string& sinkBundleName);
|
||||
void OnDeviceScreenOff();
|
||||
void OnContinueSwitchOff();
|
||||
void OnUserSwitch();
|
||||
std::string GetContinueType(const std::string& bundleName);
|
||||
bool CheckRegSoftbusListener();
|
||||
|
||||
@ -106,6 +107,8 @@ private:
|
||||
bool IsBundleContinuable(const AppExecFwk::BundleInfo& bundleInfo, const std::string &srcAbilityName,
|
||||
const std::string &srcContinueType, bool isSameBundle);
|
||||
std::string ContinueTypeFormat(const std::string &continueType);
|
||||
void FindToNotifyRecvBroadcast(const std::string& senderNetworkId, const std::string& bundleName,
|
||||
const std::string& continueType);
|
||||
private:
|
||||
currentIconInfo iconInfo_;
|
||||
sptr<DistributedMissionDiedListener> missionDiedListener_;
|
||||
|
@ -508,6 +508,23 @@ void DMSContinueRecvMgr::OnDeviceScreenOff()
|
||||
}
|
||||
#endif
|
||||
|
||||
void DMSContinueRecvMgr::FindToNotifyRecvBroadcast(const std::string& senderNetworkId, const std::string& bundleName,
|
||||
const std::string& continueType)
|
||||
{
|
||||
std::lock_guard<std::mutex> registerOnListenerMapLock(eventMutex_);
|
||||
auto iterItem = registerOnListener_.find(onType_);
|
||||
if (iterItem == registerOnListener_.end()) {
|
||||
HILOGI("Get iterItem failed from registerOnListener_, nobody registed");
|
||||
return;
|
||||
}
|
||||
std::vector<sptr<IRemoteObject>> objs = iterItem->second;
|
||||
for (auto iter : objs) {
|
||||
NotifyRecvBroadcast(iter,
|
||||
currentIconInfo(senderNetworkId, iconInfo_.sourceBundleName, bundleName, continueType),
|
||||
INACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
void DMSContinueRecvMgr::OnContinueSwitchOff()
|
||||
{
|
||||
auto func = [this]() {
|
||||
@ -529,20 +546,7 @@ void DMSContinueRecvMgr::OnContinueSwitchOff()
|
||||
}
|
||||
HILOGI("Saved iconInfo cleared, networkId: %{public}s, bundleName: %{public}s.",
|
||||
GetAnonymStr(senderNetworkId).c_str(), bundleName.c_str());
|
||||
{
|
||||
std::lock_guard<std::mutex> registerOnListenerMapLock(eventMutex_);
|
||||
auto iterItem = registerOnListener_.find(onType_);
|
||||
if (iterItem == registerOnListener_.end()) {
|
||||
HILOGI("Get iterItem failed from registerOnListener_, nobody registed");
|
||||
return;
|
||||
}
|
||||
std::vector<sptr<IRemoteObject>> objs = iterItem->second;
|
||||
for (auto iter : objs) {
|
||||
NotifyRecvBroadcast(iter,
|
||||
currentIconInfo(senderNetworkId, iconInfo_.sourceBundleName, bundleName, continueType),
|
||||
INACTIVE);
|
||||
}
|
||||
}
|
||||
FindToNotifyRecvBroadcast(senderNetworkId, bundleName, continueType);
|
||||
};
|
||||
if (eventHandler_ == nullptr) {
|
||||
HILOGE("eventHandler_ is nullptr");
|
||||
@ -551,6 +555,31 @@ void DMSContinueRecvMgr::OnContinueSwitchOff()
|
||||
eventHandler_->PostTask(func);
|
||||
}
|
||||
|
||||
void DMSContinueRecvMgr::OnUserSwitch()
|
||||
{
|
||||
HILOGI("OnUserSwitch start.");
|
||||
std::string senderNetworkId;
|
||||
std::string bundleName;
|
||||
std::string continueType;
|
||||
{
|
||||
std::lock_guard<std::mutex> currentIconLock(iconMutex_);
|
||||
if (iconInfo_.isEmpty()) {
|
||||
HILOGW("Saved iconInfo has already been cleared, task abort.");
|
||||
return;
|
||||
}
|
||||
senderNetworkId = iconInfo_.senderNetworkId;
|
||||
bundleName = iconInfo_.bundleName;
|
||||
continueType = iconInfo_.continueType;
|
||||
iconInfo_.senderNetworkId = "";
|
||||
iconInfo_.bundleName = "";
|
||||
iconInfo_.continueType = "";
|
||||
}
|
||||
HILOGI("Saved iconInfo cleared, networkId: %{public}s, bundleName: %{public}s.",
|
||||
GetAnonymStr(senderNetworkId).c_str(), bundleName.c_str());
|
||||
FindToNotifyRecvBroadcast(senderNetworkId, bundleName, continueType);
|
||||
HILOGI("OnUserSwitch end.");
|
||||
}
|
||||
|
||||
void DMSContinueRecvMgr::NotifyDeviceOffline(const std::string& networkId)
|
||||
{
|
||||
if (networkId.empty()) {
|
||||
@ -581,20 +610,7 @@ void DMSContinueRecvMgr::NotifyDeviceOffline(const std::string& networkId)
|
||||
}
|
||||
HILOGI("Saved iconInfo cleared, networkId: %{public}s, bundleName: %{public}s.",
|
||||
GetAnonymStr(senderNetworkId).c_str(), bundleName.c_str());
|
||||
{
|
||||
std::lock_guard<std::mutex> registerOnListenerMapLock(eventMutex_);
|
||||
auto iterItem = registerOnListener_.find(onType_);
|
||||
if (iterItem == registerOnListener_.end()) {
|
||||
HILOGI("Get iterItem failed from registerOnListener_, nobody registed");
|
||||
return;
|
||||
}
|
||||
std::vector<sptr<IRemoteObject>> objs = iterItem->second;
|
||||
for (auto iter : objs) {
|
||||
NotifyRecvBroadcast(iter,
|
||||
currentIconInfo(senderNetworkId, iconInfo_.sourceBundleName, bundleName, continueType),
|
||||
INACTIVE);
|
||||
}
|
||||
}
|
||||
FindToNotifyRecvBroadcast(senderNetworkId, bundleName, continueType);
|
||||
HILOGI("NotifyDeviceOffline end");
|
||||
}
|
||||
|
||||
@ -623,20 +639,7 @@ void DMSContinueRecvMgr::NotifyPackageRemoved(const std::string& sinkBundleName)
|
||||
iconInfo_.continueType = "";
|
||||
}
|
||||
HILOGI("Saved iconInfo cleared, sinkBundleName: %{public}s.", bundleName.c_str());
|
||||
{
|
||||
std::lock_guard<std::mutex> registerOnListenerMapLock(eventMutex_);
|
||||
auto iterItem = registerOnListener_.find(onType_);
|
||||
if (iterItem == registerOnListener_.end()) {
|
||||
HILOGI("Get iterItem failed from registerOnListener_, nobody registed");
|
||||
return;
|
||||
}
|
||||
std::vector<sptr<IRemoteObject>> objs = iterItem->second;
|
||||
for (auto iter : objs) {
|
||||
NotifyRecvBroadcast(iter,
|
||||
currentIconInfo(senderNetworkId, iconInfo_.sourceBundleName, bundleName, continueType),
|
||||
INACTIVE);
|
||||
}
|
||||
}
|
||||
FindToNotifyRecvBroadcast(senderNetworkId, bundleName, continueType);
|
||||
HILOGI("NotifyPackageRemoved end");
|
||||
}
|
||||
|
||||
|
@ -100,6 +100,12 @@ void MultiUserManager::UnInit()
|
||||
void MultiUserManager::OnUserSwitched(int32_t accountId)
|
||||
{
|
||||
HILOGI("UserSwitched start");
|
||||
auto recvMgr = GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
}
|
||||
recvMgr->OnUserSwitch();
|
||||
auto sendMgr = GetCurrentSendMgr();
|
||||
if (sendMgr == nullptr) {
|
||||
HILOGI("GetSendMgr failed.");
|
||||
@ -125,7 +131,7 @@ void MultiUserManager::OnUserSwitched(int32_t accountId)
|
||||
return;
|
||||
}
|
||||
sendMgr->Init();
|
||||
auto recvMgr = GetCurrentRecvMgr();
|
||||
recvMgr = GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
HILOGI("GetRecvMgr failed.");
|
||||
return;
|
||||
|
@ -1488,5 +1488,58 @@ HWTEST_F(DMSContinueManagerTest, OnContinueSwitchOff_001, TestSize.Level1)
|
||||
EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
|
||||
DTEST_LOG << "DMSContinueManagerTest OnContinueSwitchOff_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnUserSwitch_001
|
||||
* @tc.desc: test OnUserSwitch
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DMSContinueManagerTest, OnUserSwitch_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DMSContinueManagerTest OnUserSwitch_001 start" << std::endl;
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
DTEST_LOG << "GetRecvMgr failed." << std::endl;
|
||||
return;
|
||||
}
|
||||
recvMgr->iconInfo_.senderNetworkId = "";
|
||||
recvMgr->iconInfo_.bundleName = "";
|
||||
recvMgr->iconInfo_.continueType = "";
|
||||
recvMgr->OnUserSwitch();
|
||||
EXPECT_EQ(recvMgr->iconInfo_.isEmpty(), true);
|
||||
|
||||
recvMgr->iconInfo_.senderNetworkId = "senderNetworkId";
|
||||
recvMgr->iconInfo_.bundleName = "bundleName";
|
||||
recvMgr->iconInfo_.continueType = "continueType";
|
||||
recvMgr->registerOnListener_.clear();
|
||||
recvMgr->OnUserSwitch();
|
||||
EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
|
||||
DTEST_LOG << "DMSContinueManagerTest OnUserSwitch_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: FindToNotifyRecvBroadcast_001
|
||||
* @tc.desc: test FindToNotifyRecvBroadcast
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DMSContinueManagerTest, FindToNotifyRecvBroadcast_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DMSContinueManagerTest FindToNotifyRecvBroadcast_001 start" << std::endl;
|
||||
auto recvMgr = MultiUserManager::GetInstance().GetCurrentRecvMgr();
|
||||
if (recvMgr == nullptr) {
|
||||
DTEST_LOG << "GetRecvMgr failed." << std::endl;
|
||||
return;
|
||||
}
|
||||
std::string senderNetworkId = "senderNetworkId";
|
||||
std::string bundleName = "bundleName";
|
||||
std::string continueType = "senderNetworkId";
|
||||
recvMgr->iconInfo_.senderNetworkId = senderNetworkId;
|
||||
recvMgr->iconInfo_.bundleName = bundleName;
|
||||
recvMgr->iconInfo_.continueType = continueType;
|
||||
recvMgr->registerOnListener_.clear();
|
||||
recvMgr->FindToNotifyRecvBroadcast(senderNetworkId, bundleName, continueType);
|
||||
EXPECT_EQ(recvMgr->registerOnListener_.empty(), true);
|
||||
DTEST_LOG << "DMSContinueManagerTest FindToNotifyRecvBroadcast_001 end" << std::endl;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user