From b83a84e5fbbacdf5dd865ed8d75114eb51f9d202 Mon Sep 17 00:00:00 2001 From: fanzexuan Date: Sat, 12 Jul 2025 16:30:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E7=94=A8=E6=88=B7=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E7=9B=91=E5=90=AC=E7=94=A8=E6=88=B7=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=8E=A5=E5=8F=A3=E5=85=B3=E9=97=AD=E6=94=BE=E5=A4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fanzexuan --- .../aams/include/accessibility_account_data.h | 7 ++++ .../accessible_ability_manager_service.h | 5 ++- .../aams/src/accessibility_account_data.cpp | 8 ++++ .../accessible_ability_manager_service.cpp | 37 ++++++++++++++++++- .../aams/src/magnification_menu_manager.cpp | 4 ++ .../src/mock_accessibility_account_data.cpp | 5 +++ 6 files changed, 63 insertions(+), 3 deletions(-) diff --git a/services/aams/include/accessibility_account_data.h b/services/aams/include/accessibility_account_data.h index 72240972..2ac7618d 100644 --- a/services/aams/include/accessibility_account_data.h +++ b/services/aams/include/accessibility_account_data.h @@ -31,6 +31,7 @@ #include "element_name.h" #include "accessibility_setting_provider.h" #include "os_account_info.h" +#include "os_account_subscriber.h" namespace OHOS { namespace Accessibility { @@ -392,6 +393,12 @@ private: std::map> accountDataMap_; ffrt::mutex accountDataMutex_; }; + +class AccountSubscriber final : public AccountSA::OsAccountSubscriber { +public: + AccountSubscriber(const AccountSA::OsAccountSubscribeInfo &info): OsAccountSubscriber(info) {}; + void OnStateChanged(const AccountSA::OsAccountStateData &data) override; +}; } // namespace Accessibility } // namespace OHOS #endif // ACCESSIBILITY_ACCOUNT_DATA_H \ No newline at end of file diff --git a/services/aams/include/accessible_ability_manager_service.h b/services/aams/include/accessible_ability_manager_service.h index f4861e40..820ff537 100644 --- a/services/aams/include/accessible_ability_manager_service.h +++ b/services/aams/include/accessible_ability_manager_service.h @@ -347,6 +347,7 @@ public: void InitResource(bool needReInit); std::string &GetResource(const std::string &resourceName); void AnnouncedForMagnification(AnnounceType announceType); + void OffZoomGesture(); RetError UpdateUITestConfigureEvents(std::vector needEvents); @@ -466,7 +467,6 @@ private: void RegisterProvisionCallback(); void RegisterShortKeyEvent(); bool IsNeedUnload(); - void OffZoomGesture(); void OnScreenMagnificationStateChanged(); void RegisterScreenMagnificationState(); void OnScreenMagnificationTypeChanged(); @@ -475,6 +475,8 @@ private: void OnVoiceRecognitionChanged(); void RegisterVoiceRecognitionState(); void UpdateVoiceRecognitionState(); + void SubscribeOsAccount(); + void UnsubscribeOsAccount(); int32_t ApplyTreeId(); void RecycleTreeId(int32_t treeId); @@ -537,6 +539,7 @@ private: ffrt::mutex subscribeMSDPMutex_; std::shared_ptr magnificationManager_ = nullptr; bool isResourceInit_ = false; + std::shared_ptr accountSubscriber_ = nullptr; }; } // namespace Accessibility } // namespace OHOS diff --git a/services/aams/src/accessibility_account_data.cpp b/services/aams/src/accessibility_account_data.cpp index 307ff3da..bb9f57e7 100644 --- a/services/aams/src/accessibility_account_data.cpp +++ b/services/aams/src/accessibility_account_data.cpp @@ -1517,5 +1517,13 @@ std::vector AccessibilityAccountData::GetNeedEvents() { return needEvents_; } + +void AccountSubscriber::OnStateChanged(const AccountSA::OsAccountStateData &data) +{ + if (data.state == AccountSA::OsAccountState::SWITCHING) { + HILOG_INFO("account switching."); + Singleton::GetInstance().OffZoomGesture(); + } +} } // namespace Accessibility } // namespace OHOS diff --git a/services/aams/src/accessible_ability_manager_service.cpp b/services/aams/src/accessible_ability_manager_service.cpp index 87f07dc7..97a40944 100644 --- a/services/aams/src/accessible_ability_manager_service.cpp +++ b/services/aams/src/accessible_ability_manager_service.cpp @@ -336,6 +336,7 @@ void AccessibleAbilityManagerService::OnStop() Singleton::GetInstance().UnSubscriberEvent(); Singleton::GetInstance().UnregisterDisplayListener(); Singleton::GetInstance().DeregisterWindowListener(); + UnsubscribeOsAccount(); currentAccountId_ = -1; a11yAccountsData_.Clear(); @@ -1826,7 +1827,7 @@ bool AccessibleAbilityManagerService::Init() HILOG_DEBUG("Query account information success, account id:%{public}d", accountIds[0]); SwitchedUser(accountIds[0]); } - + SubscribeOsAccount(); return true; } @@ -1975,7 +1976,6 @@ void AccessibleAbilityManagerService::SwitchedUser(int32_t accountId) HILOG_WARN("The account is current account id."); return; } - OffZoomGesture(); std::map importantEnabledAbilities; SCREENREADER_STATE screenReaderState = SCREENREADER_STATE::UNINIT; @@ -4226,5 +4226,38 @@ ErrCode AccessibleAbilityManagerService::SearchNeedEvents(std::vector HILOG_DEBUG("GetNeedEvent size is %{public}u", needEvents.size()); return NO_ERROR; } + +void AccessibleAbilityManagerService::SubscribeOsAccount() +{ + HILOG_INFO(); + if (accountSubscriber_ != nullptr) { + HILOG_ERROR("accountSubscriber is already registed!"); + return; + } + std::set states; + states.insert(AccountSA::OsAccountState::SWITCHING); + AccountSA::OsAccountSubscribeInfo info(states, false); + accountSubscriber_ = std::make_shared(info); + if (accountSubscriber_ == nullptr) { + HILOG_ERROR("create accountSubscriber fail!"); + return; + } + auto result = AccountSA::OsAccountManager::SubscribeOsAccount(accountSubscriber_); + if (result != ERR_OK) { + HILOG_ERROR("fail to register subscriber, res:%{public}d.", result); + } +} + +void AccessibleAbilityManagerService::UnsubscribeOsAccount() +{ + if (accountSubscriber_ == nullptr) { + HILOG_ERROR("accountSubscriber is nullptr."); + return; + } + auto res = AccountSA::OsAccountManager::UnsubscribeOsAccount(accountSubscriber_); + if (res != ERR_OK) { + HILOG_ERROR("unregister account event fail res:%{public}d", res); + } +} } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/services/aams/src/magnification_menu_manager.cpp b/services/aams/src/magnification_menu_manager.cpp index e5aec096..99eb1074 100644 --- a/services/aams/src/magnification_menu_manager.cpp +++ b/services/aams/src/magnification_menu_manager.cpp @@ -167,6 +167,10 @@ void MagnificationMenuManager::DisableMenuWindow() { HILOG_INFO(); std::lock_guard lock(mutex_); + if (!isMenuShown_) { + HILOG_INFO("menu not shown."); + return; + } if (surfaceNode_ != nullptr) { surfaceNode_->SetVisible(false); surfaceNode_->ClearChildren(); diff --git a/services/aams/test/mock/src/mock_accessibility_account_data.cpp b/services/aams/test/mock/src/mock_accessibility_account_data.cpp index c9db0573..2248a1f4 100644 --- a/services/aams/test/mock/src/mock_accessibility_account_data.cpp +++ b/services/aams/test/mock/src/mock_accessibility_account_data.cpp @@ -598,5 +598,10 @@ std::vector AccessibilityAccountData::GetNeedEvents() { return needEvents_; } + +void AccountSubscriber::OnStateChanged(const AccountSA::OsAccountStateData &data) +{ + (void)data; +} } // namespace Accessibility } // namespace OHOS \ No newline at end of file -- Gitee