!1034 失焦事件上报后,清理焦点信息

Merge pull request !1034 from m30043719/master
This commit is contained in:
openharmony_ci 2024-08-20 10:49:04 +00:00 committed by Gitee
commit bec1a7df9a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 44 additions and 14 deletions

View File

@ -145,6 +145,7 @@ private:
int32_t FocusedBusinessSendEvent(std::string bundleName, const std::string& abilityName);
int32_t GetBundleNameIdAndContinueTypeId(const int32_t missionId, const AAFwk::ContinueState& state,
uint16_t& bundleNameId, uint8_t& continueTypeId);
void EraseFocusedMission(const std::string& bundleName, const int32_t& missionId, const UnfocusedReason& reason);
private:
currentMissionInfo info_ = { INVALID_MISSION_ID, false };
std::map<std::string, int32_t> focusedMission_;

View File

@ -370,45 +370,39 @@ int32_t DMSContinueSendMgr::DealUnfocusedBusiness(const int32_t missionId, Unfoc
}
HILOGI("Get bundleName success, mission is continuable, missionId: %{public}d, bundleName: %{public}s",
missionId, bundleName.c_str());
std::string abilityName;
ret = GetAbilityNameByMissionId(missionId, abilityName);
if (ret != ERR_OK) {
HILOGE("get abilityName failed, missionId: %{public}d, ret: %{public}d", missionId, ret);
return ret;
}
if (reason != UnfocusedReason::TIMEOUT) {
bool isContinue = IsContinue(missionId, bundleName);
if (!isContinue) {
HILOGE("Not current mission to be continued, missionId: %{public}d", missionId);
EraseFocusedMission(bundleName, missionId, reason);
return NO_MISSION_INFO_FOR_MISSION_ID;
}
#ifdef SUPPORT_MULTIMODALINPUT_SERVICE
RemoveMMIListener();
#endif
}
ret = CheckContinueState(missionId);
if (ret != ERR_OK) {
HILOGE("Continue state is inactive or can't be obtained, mission id : %{public}d, ret: %{public}d",
missionId, ret);
EraseFocusedMission(bundleName, missionId, reason);
return ret;
}
uint16_t bundleNameId = 0;
uint8_t continueTypeId = 0;
ret = GetAccessTokenIdSendEvent(bundleName, reason, bundleNameId, continueTypeId);
if (ret != ERR_OK) {
HILOGE("GetAccessTokenIdSendEvent failed");
EraseFocusedMission(bundleName, missionId, reason);
return ret;
}
if (reason != UnfocusedReason::TIMEOUT) {
std::lock_guard<std::mutex> focusedMissionMapLock(eventMutex_);
focusedMission_.erase(bundleName);
focusedMissionAbility_.erase(missionId);
}
EraseFocusedMission(bundleName, missionId, reason);
if (reason == UnfocusedReason::NORMAL && screenOffHandler_ != nullptr) {
screenOffHandler_->SetScreenOffInfo(missionId, bundleName, bundleNameId, abilityName);
}
@ -416,6 +410,16 @@ int32_t DMSContinueSendMgr::DealUnfocusedBusiness(const int32_t missionId, Unfoc
return ERR_OK;
}
void DMSContinueSendMgr::EraseFocusedMission(const std::string& bundleName, const int32_t& missionId,
const UnfocusedReason& reason)
{
if (reason == UnfocusedReason::NORMAL) {
std::lock_guard<std::mutex> focusedMissionMapLock(eventMutex_);
focusedMission_.erase(bundleName);
focusedMissionAbility_.erase(missionId);
}
}
int32_t DMSContinueSendMgr::SendScreenOffEvent(uint8_t type)
{
if (screenOffHandler_ == nullptr) {
@ -492,9 +496,6 @@ bool DMSContinueSendMgr::IsContinue(const int32_t& missionId, const std::string&
if (missionId != info_.currentMissionId && info_.currentIsContinuable) {
/*missionId and currentMissionId are not equal but currentMission can change,
continue to not send unfocus broadcast*/
std::lock_guard<std::mutex> focusedMissionMapLock(eventMutex_);
focusedMission_.erase(bundleName);
focusedMissionAbility_.erase(missionId);
HILOGI("mission is not continue, missionId: %{public}d, currentMissionId: %{public}d",
missionId, info_.currentMissionId);
return false;
@ -532,7 +533,8 @@ int32_t DMSContinueSendMgr::DealSetMissionContinueStateBusiness(const int32_t mi
const AAFwk::ContinueState &state)
{
HILOGI("DealSetMissionContinueStateBusiness start, missionId: %{public}d, state: %{public}d", missionId, state);
if (info_.currentMissionId != missionId) {
std::string bundleName;
if (info_.currentMissionId != missionId && GetBundleNameByMissionId(missionId, bundleName) != ERR_OK) {
HILOGE("mission is not focused, broadcast task abort, missionId: %{public}d", missionId);
return INVALID_PARAMETERS_ERR;
}

View File

@ -527,6 +527,33 @@ HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState001, TestSize.Level3
DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState001 end" << std::endl;
}
/**
* @tc.name: testSetMissionContinueState002
* @tc.desc: test SetMissionContinueState
* @tc.type: FUNC
*/
HWTEST_F(DMSContinueManagerTest, testSetMissionContinueState002, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState002 start" << std::endl;
DistributedSchedUtil::MockManageMissions();
DMSContinueSendMgr::GetInstance().Init();
OHOS::AAFwk::ContinueState state = OHOS::AAFwk::ContinueState::CONTINUESTATE_INACTIVE;
/**
* @tc.steps: step1. test SetMissionContinueState when eventHandler is not nullptr;
*/
DMSContinueSendMgr::GetInstance().SetMissionContinueState(0, state);
EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
/**
* @tc.steps: step2. test SetMissionContinueState when eventHandler is nullptr;
*/
DMSContinueSendMgr::GetInstance().UnInit();
DMSContinueSendMgr::GetInstance().SetMissionContinueState(0, state);
EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
DTEST_LOG << "DMSContinueManagerTest testSetMissionContinueState002 end" << std::endl;
}
/**
* @tc.name: testDealSetMissionContinueStateBusiness001
* @tc.desc: test DealSetMissionContinueStateBusiness.