已开启
新增wms断开重连状态监听器 #2721
taojuncun创建于 12 天前
新增wms断开重连状态监听器 #2721
已开启
共 5 个文件变更+81-36
| @@ -21,7 +21,8 @@ | |||
| 21 | "features": [ | 21 | "features": [ |
| 22 | "accessibility_feature_coverage", | 22 | "accessibility_feature_coverage", |
| 23 | "accessibility_watch_feature", | 23 | "accessibility_watch_feature", |
| 24 | - "accessibility_dynamic_support" | 24 | + "accessibility_dynamic_support", |
| 25 | + "accessibility_product_feature" | ||
| 25 | ], | 26 | ], |
| 26 | "adapted_system_type": [ | 27 | "adapted_system_type": [ |
| 27 | "standard" | 28 | "standard" |
| @@ -59,7 +59,6 @@ public: | |||
| 59 | void SetEventInfoBundleNameOld(AccessibilityEventInfo &uiEvent, const int32_t windowId, | 59 | void SetEventInfoBundleNameOld(AccessibilityEventInfo &uiEvent, const int32_t windowId, |
| 60 | std::map<int32_t, AccessibilityWindowInfo> &oldA11yWindows); | 60 | std::map<int32_t, AccessibilityWindowInfo> &oldA11yWindows); |
| 61 | bool IsValidWindow(int32_t windowId); | 61 | bool IsValidWindow(int32_t windowId); |
| 62 | - bool NeedSetActive(const int32_t windowId); | ||
| 63 | bool IsMagnificationWindow(const sptr<Rosen::AccessibilityWindowInfo> &window); | 62 | bool IsMagnificationWindow(const sptr<Rosen::AccessibilityWindowInfo> &window); |
| 64 | void SetAccessibilityFocusedWindow(); | 63 | void SetAccessibilityFocusedWindow(); |
| 65 | void ClearAccessibilityFocused(); | 64 | void ClearAccessibilityFocused(); |
| @@ -96,6 +95,9 @@ public: | |||
| 96 | void IsCheckWindowIdEventExist(int32_t windowId); | 95 | void IsCheckWindowIdEventExist(int32_t windowId); |
| 97 | bool CheckWindowRegister(int32_t windowId); | 96 | bool CheckWindowRegister(int32_t windowId); |
| 98 | 97 | ||
| 98 | + void OnWmsConnected(int32_t userId, int32_t screenId); | ||
| 99 | + void OnWmsDisconnected(int32_t userId, int32_t screenId); | ||
| 100 | + | ||
| 99 | std::map<int32_t, AccessibilityWindowInfo> a11yWindows_ {}; | 101 | std::map<int32_t, AccessibilityWindowInfo> a11yWindows_ {}; |
| 100 | int32_t previousActiveWindowId_ = INVALID_WINDOW_ID; | 102 | int32_t previousActiveWindowId_ = INVALID_WINDOW_ID; |
| 101 | int32_t activeWindowId_ = INVALID_WINDOW_ID; | 103 | int32_t activeWindowId_ = INVALID_WINDOW_ID; |
| @@ -135,13 +137,21 @@ private: | |||
| 135 | AccessibilityWindowManager &windInfoMgr_; | 137 | AccessibilityWindowManager &windInfoMgr_; |
| 136 | }; | 138 | }; |
| 137 | 139 | ||
| 138 | - class WindowRotationChangeListener : public Rosen::IWindowRotationChangeListener { | 140 | + class WMSConnectionChangedListener : public Rosen::IWMSConnectionChangedListener { |
| 139 | public: | 141 | public: |
| 140 | - explicit WindowRotationChangeListener(); | 142 | + explicit WMSConnectionChangedListener(AccessibilityWindowManager &windInfoMgr) |
| 141 | - ~WindowRotationChangeListener() = default; | 143 | + : windInfoMgr_(windInfoMgr) {} |
| 142 | - | 144 | + ~WMSConnectionChangedListener() = default; |
| 143 | - virtual void OnRotationChange(const Rosen::RotationChangeInfo& rotationChangeInfo, | 145 | + void OnConnected(int32_t userId, int32_t screenId) override |
| 144 | - Rosen::RotationChangeResult& rotationChangeResult) override; | 146 | + { |
| 147 | + windInfoMgr_.OnWmsConnected(userId, screenId); | ||
| 148 | + } | ||
| 149 | + void OnDisconnected(int32_t userId, int32_t screenId) override | ||
| 150 | + { | ||
| 151 | + windInfoMgr_.OnWmsDisconnected(userId, screenId); | ||
| 152 | + } | ||
| 153 | + private: | ||
| 154 | + AccessibilityWindowManager &windInfoMgr_; | ||
| 145 | }; | 155 | }; |
| 146 | 156 | ||
| 147 | bool CompareRect(const Rect &rectAccessibility, const Rosen::Rect &rectWindow); | 157 | bool CompareRect(const Rect &rectAccessibility, const Rosen::Rect &rectWindow); |
| @@ -180,6 +190,8 @@ private: | |||
| 180 | 190 | ||
| 181 | int32_t accountId_ = -1; | 191 | int32_t accountId_ = -1; |
| 182 | sptr<AccessibilityWindowListener> windowListener_ = nullptr; | 192 | sptr<AccessibilityWindowListener> windowListener_ = nullptr; |
| 193 | + sptr<WMSConnectionChangedListener> wmsConnectionListener_ = nullptr; | ||
| 194 | + bool isWindowListenerRegistered_ = false; | ||
| 183 | std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr; | 195 | std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr; |
| 184 | ffrt::recursive_mutex interfaceMutex_; // mutex for interface to make sure AccessibilityWindowManager thread-safe | 196 | ffrt::recursive_mutex interfaceMutex_; // mutex for interface to make sure AccessibilityWindowManager thread-safe |
| 185 | SafeMap<int32_t, int32_t> windowTreeIdMap_; // map for tree id to window id | 197 | SafeMap<int32_t, int32_t> windowTreeIdMap_; // map for tree id to window id |
| @@ -137,15 +137,42 @@ void AccessibilityWindowManager::RegisterWindowListener(const std::shared_ptr<Ap | |||
| 137 | HILOG_ERROR("Create window listener fail!"); | 137 | HILOG_ERROR("Create window listener fail!"); |
| 138 | return; | 138 | return; |
| 139 | } | 139 | } |
| 140 | - OHOS::Rosen::WindowManager::GetInstance(accountId_).RegisterWindowUpdateListener(windowListener_); | 140 | + Rosen::WMError err = |
| 141 | + OHOS::Rosen::WindowManager::GetInstance(accountId_).RegisterWindowUpdateListener(windowListener_); | ||
| 142 | + if (err == Rosen::WMError::WM_OK) { | ||
| 143 | + isWindowListenerRegistered_ = true; | ||
| 144 | + } else { | ||
| 145 | + isWindowListenerRegistered_ = false; | ||
| 146 | + HILOG_ERROR("RegisterWindowUpdateListener failed %{public}d %{public}d", accountId_, err); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + if (!wmsConnectionListener_) { | ||
| 150 | + wmsConnectionListener_ = new (std::nothrow) WMSConnectionChangedListener(*this); | ||
| 151 | + if (wmsConnectionListener_) { | ||
| 152 | + auto wmsRet = OHOS::Rosen::WindowManager::GetInstance(accountId_) | ||
| 153 | + .RegisterWMSConnectionChangedListener(wmsConnectionListener_); | ||
| 154 | + if (wmsRet != Rosen::WMError::WM_OK) { | ||
| 155 | + HILOG_ERROR("RegisterWMSConnectionChangedListener failed %{public}d", wmsRet); | ||
| 156 | + wmsConnectionListener_ = nullptr; | ||
| 157 | + } | ||
| 158 | + } else { | ||
| 159 | + HILOG_ERROR("Create WMSConnectionChangedListener fail!"); | ||
| 160 | + } | ||
| 161 | + } | ||
| 141 | } | 162 | } |
| 142 | 163 | ||
| 143 | void AccessibilityWindowManager::DeregisterWindowListener() | 164 | void AccessibilityWindowManager::DeregisterWindowListener() |
| 144 | { | 165 | { |
| 166 | + std::lock_guard<ffrt::recursive_mutex> lock(interfaceMutex_); | ||
| 145 | if (windowListener_) { | 167 | if (windowListener_) { |
| 146 | OHOS::Rosen::WindowManager::GetInstance(accountId_).UnregisterWindowUpdateListener(windowListener_); | 168 | OHOS::Rosen::WindowManager::GetInstance(accountId_).UnregisterWindowUpdateListener(windowListener_); |
| 147 | windowListener_ = nullptr; | 169 | windowListener_ = nullptr; |
| 148 | eventHandler_ = nullptr; | 170 | eventHandler_ = nullptr; |
| 171 | + isWindowListenerRegistered_ = false; | ||
| 172 | + } | ||
| 173 | + if (wmsConnectionListener_) { | ||
| 174 | + OHOS::Rosen::WindowManager::GetInstance(accountId_).UnregisterWMSConnectionChangedListener(); | ||
| 175 | + wmsConnectionListener_ = nullptr; | ||
| 149 | } | 176 | } |
| 150 | } | 177 | } |
| 151 | 178 | ||
| @@ -1035,27 +1062,6 @@ void AccessibilityWindowManager::SetAccessibilityFocusedWindow() | |||
| 1035 | } | 1062 | } |
| 1036 | } | 1063 | } |
| 1037 | 1064 | ||
| 1038 | -bool AccessibilityWindowManager::NeedSetActive(const int32_t windowId) | ||
| 1039 | -{ | ||
| 1040 | - std::lock_guard<ffrt::recursive_mutex> lock(interfaceMutex_); | ||
| 1041 | - if (windowId == INVALID_WINDOW_ID || !a11yWindows_.count(windowId)) { | ||
| 1042 | - return false; | ||
| 1043 | - } | ||
| 1044 | - | ||
| 1045 | - const std::string& currentBundleName = a11yWindows_[windowId].GetBundleName(); | ||
| 1046 | - auto it = std::find_if(UNFOCUSABLE_WINDOW.begin(), UNFOCUSABLE_WINDOW.end(), | ||
| 1047 | - [¤tBundleName](const std::string& pattern) { | ||
| 1048 | - return currentBundleName.find(pattern) != std::string::npos; | ||
| 1049 | - }); | ||
| 1050 | - if (it == UNFOCUSABLE_WINDOW.end()) { | ||
| 1051 | - return true; | ||
| 1052 | - } else { | ||
| 1053 | - HILOG_INFO("skip set active, current BundleName: %{public}s, windowId: %{public}d", | ||
| 1054 | - currentBundleName.c_str(), windowId); | ||
| 1055 | - return false; | ||
| 1056 | - } | ||
| 1057 | -} | ||
| 1058 | - | ||
| 1059 | void AccessibilityWindowManager::WindowUpdateAll(const std::vector<sptr<Rosen::AccessibilityWindowInfo>>& infos) | 1065 | void AccessibilityWindowManager::WindowUpdateAll(const std::vector<sptr<Rosen::AccessibilityWindowInfo>>& infos) |
| 1060 | { | 1066 | { |
| 1061 | std::lock_guard<ffrt::recursive_mutex> lock(interfaceMutex_); | 1067 | std::lock_guard<ffrt::recursive_mutex> lock(interfaceMutex_); |
| @@ -1378,6 +1384,38 @@ void AccessibilityWindowManager::IsCheckWindowIdEventExist(int32_t windowId) | |||
| 1378 | windowFocusEventMap_.Erase(windowId); | 1384 | windowFocusEventMap_.Erase(windowId); |
| 1379 | } | 1385 | } |
| 1380 | } | 1386 | } |
| 1387 | + | ||
| 1388 | +void AccessibilityWindowManager::OnWmsConnected(int32_t userId, int32_t screenId) | ||
| 1389 | +{ | ||
| 1390 | + Init(); | ||
| 1391 | + std::lock_guard<ffrt::recursive_mutex> lock(interfaceMutex_); | ||
| 1392 | + if (userId != accountId_) { | ||
| 1393 | + HILOG_DEBUG("userId[%{public}d] != accountId_[%{public}d], skip", userId, accountId_); | ||
| 1394 | + return; | ||
| 1395 | + } | ||
| 1396 | + HILOG_INFO("WMS connected, userId[%{public}d] screenId[%{public}d]", userId, screenId); | ||
| 1397 | + if (!isWindowListenerRegistered_ && windowListener_) { | ||
| 1398 | + auto err = OHOS::Rosen::WindowManager::GetInstance(accountId_) | ||
| 1399 | + .RegisterWindowUpdateListener(windowListener_); | ||
| 1400 | + if (err == Rosen::WMError::WM_OK) { | ||
| 1401 | + isWindowListenerRegistered_ = true; | ||
| 1402 | + } else { | ||
| 1403 | + HILOG_ERROR("Retry RegisterWindowUpdateListener failed %{public}d", err); | ||
| 1404 | + } | ||
| 1405 | + } | ||
| 1406 | +} | ||
| 1407 | + | ||
| 1408 | +void AccessibilityWindowManager::OnWmsDisconnected(int32_t userId, int32_t screenId) | ||
| 1409 | +{ | ||
| 1410 | + DeInit(); | ||
| 1411 | + std::lock_guard<ffrt::recursive_mutex> lock(interfaceMutex_); | ||
| 1412 | + if (userId != accountId_) { | ||
| 1413 | + HILOG_DEBUG("userId[%{public}d] != accountId_[%{public}d], skip", userId, accountId_); | ||
| 1414 | + return; | ||
| 1415 | + } | ||
| 1416 | + HILOG_INFO("WMS disconnected, userId[%{public}d] screenId[%{public}d]", userId, screenId); | ||
| 1417 | + isWindowListenerRegistered_ = false; | ||
| 1418 | +} | ||
| 1381 | // LCOV_EXCL_STOP | 1419 | // LCOV_EXCL_STOP |
| 1382 | } // namespace Accessibility | 1420 | } // namespace Accessibility |
| 1383 | } // namespace OHOS | 1421 | } // namespace OHOS |
| @@ -35,7 +35,6 @@ public: | |||
| 35 | MOCK_METHOD2(ConvertToRealWindowId, std::pair<int32_t, uint64_t>(int32_t windowId, int32_t focusType)); | 35 | MOCK_METHOD2(ConvertToRealWindowId, std::pair<int32_t, uint64_t>(int32_t windowId, int32_t focusType)); |
| 36 | MOCK_METHOD1(RegisterWindowListener, void(const std::shared_ptr<AppExecFwk::EventHandler> &handler)); | 36 | MOCK_METHOD1(RegisterWindowListener, void(const std::shared_ptr<AppExecFwk::EventHandler> &handler)); |
| 37 | MOCK_METHOD0(DeregisterWindowListener, void()); | 37 | MOCK_METHOD0(DeregisterWindowListener, void()); |
| 38 | - MOCK_METHOD1(NeedSetActive, bool(const int32_t windowId)); | ||
| 39 | MOCK_METHOD1(SetActiveWindow, void(int32_t windowId, bool isSendEvent)); | 38 | MOCK_METHOD1(SetActiveWindow, void(int32_t windowId, bool isSendEvent)); |
| 40 | MOCK_METHOD1(SetAccessibilityFocusedWindow, void(int32_t windowId)); | 39 | MOCK_METHOD1(SetAccessibilityFocusedWindow, void(int32_t windowId)); |
| 41 | MOCK_METHOD0(GetAccessibilityWindows, std::vector<AccessibilityWindowInfo>()); | 40 | MOCK_METHOD0(GetAccessibilityWindows, std::vector<AccessibilityWindowInfo>()); |
| @@ -100,11 +100,6 @@ AccessibilityWindowInfo AccessibilityWindowManager::CreateAccessibilityWindowInf | |||
| 100 | return info; | 100 | return info; |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | -bool AccessibilityWindowManager::NeedSetActive(const int32_t windowId) | ||
| 104 | -{ | ||
| 105 | - return false; | ||
| 106 | -} | ||
| 107 | - | ||
| 108 | void AccessibilityWindowManager::SetActiveWindow(int32_t windowId, bool isSendEvent) | 103 | void AccessibilityWindowManager::SetActiveWindow(int32_t windowId, bool isSendEvent) |
| 109 | { | 104 | { |
| 110 | activeWindowId_ = windowId; | 105 | activeWindowId_ = windowId; |