无障碍修改获取activeWindowId_加锁

Signed-off-by: qianchuang <qianchuang1@huawei.com>
This commit is contained in:
qianchuang 2024-09-02 14:37:26 +08:00
parent 1abfc1def4
commit 2961a99f66
8 changed files with 33 additions and 4 deletions

View File

@ -45,6 +45,7 @@ public:
void RegisterWindowListener(const std::shared_ptr<AppExecFwk::EventHandler> &handler);
void DeregisterWindowListener();
void SetActiveWindow(int32_t windowId, bool isSendEvent = true);
int32_t GetActiveWindowId();
void SetAccessibilityFocusedWindow(int32_t windowId);
std::vector<AccessibilityWindowInfo> GetAccessibilityWindows();
bool GetAccessibilityWindow(int32_t windowId, AccessibilityWindowInfo &window);

View File

@ -105,7 +105,7 @@ int AccessibilityDumper::DumpAccessibilityWindowInfo(std::string& dumpInfo) cons
}
oss << std::endl << "active window id: " <<
Singleton<AccessibilityWindowManager>::GetInstance().activeWindowId_ << std::endl;
Singleton<AccessibilityWindowManager>::GetInstance().GetActiveWindowId() << std::endl;
oss << "accessibility focused window id: " <<
Singleton<AccessibilityWindowManager>::GetInstance().a11yFocusedWindowId_ << std::endl;

View File

@ -195,7 +195,7 @@ void TouchGuider::SendAccessibilityEventToAA(EventType eventType)
AccessibilityEventInfo eventInfo {};
eventInfo.SetEventType(eventType);
int32_t windowsId = Singleton<AccessibilityWindowManager>::GetInstance().activeWindowId_;
int32_t windowsId = Singleton<AccessibilityWindowManager>::GetInstance().GetActiveWindowId();
eventInfo.SetWindowId(windowsId);
Singleton<AccessibleAbilityManagerService>::GetInstance().SendEvent(eventInfo);
if (eventType == EventType::TYPE_TOUCH_GUIDE_BEGIN) {
@ -210,7 +210,7 @@ void TouchGuider::SendGestureEventToAA(GestureType gestureId)
HILOG_DEBUG("gestureId is %{public}d.", gestureId);
AccessibilityEventInfo eventInfo {};
int32_t windowsId = Singleton<AccessibilityWindowManager>::GetInstance().activeWindowId_;
int32_t windowsId = Singleton<AccessibilityWindowManager>::GetInstance().GetActiveWindowId();
eventInfo.SetWindowId(windowsId);
eventInfo.SetEventType(EventType::TYPE_GESTURE_EVENT);
eventInfo.SetGestureType(gestureId);

View File

@ -376,6 +376,13 @@ void AccessibilityWindowManager::SetActiveWindow(int32_t windowId, bool isSendEv
HILOG_DEBUG("activeWindowId is %{public}d", activeWindowId_);
}
int32_t AccessibilityWindowManager::GetActiveWindowId()
{
std::lock_guard<ffrt::recursive_mutex> lock(interfaceMutex_);
HILOG_DEBUG("activeWindowId_ is %{public}d", activeWindowId_);
return activeWindowId_;
}
void AccessibilityWindowManager::SetAccessibilityFocusedWindow(int32_t windowId)
{
HILOG_DEBUG("windowId is %{public}d", windowId);

View File

@ -1411,7 +1411,7 @@ RetError AccessibleAbilityManagerService::DisableUITestAbility()
int32_t AccessibleAbilityManagerService::GetActiveWindow()
{
HILOG_DEBUG();
return Singleton<AccessibilityWindowManager>::GetInstance().activeWindowId_;
return Singleton<AccessibilityWindowManager>::GetInstance().GetActiveWindowId();
}
bool AccessibleAbilityManagerService::Init()

View File

@ -45,6 +45,7 @@ public:
MOCK_METHOD2(GetRealWindowAndElementId, void(int32_t windowId, int64_t elementId));
MOCK_METHOD3(GetSceneBoardInnerWinId, void(int32_t windowId, int64_t elementId, int32_t& innerWid));
MOCK_METHOD1(GetFocusedWindowId, RetError(int32_t &focusedWindowId));
MOCK_METHOD0(GetActiveWindowId, int32_t());
};
} // namespace Accessibility
} // namespace OHOS

View File

@ -192,5 +192,10 @@ bool AccessibilityWindowManager::IsInnerWindowRootElement(int64_t elementId)
(void)elementId;
return true;
}
int32_t AccessibilityWindowManager::GetActiveWindowId()
{
return activeWindowId_;
}
} // namespace Accessibility
} // namespace OHOS

View File

@ -303,6 +303,21 @@ HWTEST_F(AccessibilityWindowManagerTest, AccessibilityWindowManager_Unittest_Cre
GTEST_LOG_(INFO) << "AccessibilityWindowManager_Unittest_CreateAccessibilityWindowInfo004 end";
}
/**
* @tc.number: AccessibilityWindowManager_Unittest_GetActiveWindowId_001
* @tc.name: GetActiveWindowId
* @tc.desc: Test function GetActiveWindowId
*/
HWTEST_F(AccessibilityWindowManagerTest, AccessibilityWindowManager_Unittest_GetActiveWindowId001,
TestSize.Level1)
{
GTEST_LOG_(INFO) << "AccessibilityWindowManager_Unittest_GetActiveWindowId_001 start";
Singleton<AccessibilityWindowManager>::GetInstance().GetActiveWindowId();
GTEST_LOG_(INFO) << "AccessibilityWindowManager_Unittest_GetActiveWindowId_001 end";
}
/**
* @tc.number: AccessibilityWindowManager_Unittest_RegisterWindowListener001
* @tc.name: RegisterWindowListener