diff --git a/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h b/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h index 228695a84e93121e97bb19f0b4281031b746985f..709dd77691c3051dbd049819f8f7bd6c08b213c8 100644 --- a/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h +++ b/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h @@ -322,6 +322,11 @@ private: void Init(); + sptr GetProxy() const + { + return serviceProxy_; + } + /** * @brief Notify the state is changed. * @param stateType The state type and value. diff --git a/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp b/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp index 5c15a927ea942e104540b91191dc79b492f683f1..37a5c2ac3baa0f6fd9e2cbcbd89f456d947caaa6 100644 --- a/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp +++ b/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp @@ -275,7 +275,9 @@ RetError AccessibilitySystemAbilityClientImpl::RegisterElementOperator( HILOG_ERROR("Input operation is null"); return RET_ERR_INVALID_PARAM; } - if (serviceProxy_ == nullptr) { + + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("Failed to get aams service"); return RET_ERR_SAMGR; } @@ -293,7 +295,7 @@ RetError AccessibilitySystemAbilityClientImpl::RegisterElementOperator( return RET_ERR_NULLPTR; } elementOperators_[windowId] = aamsInteractionOperator; - return static_cast(serviceProxy_->RegisterElementOperatorByWindowId(windowId, aamsInteractionOperator)); + return static_cast(proxy->RegisterElementOperatorByWindowId(windowId, aamsInteractionOperator)); } RetError AccessibilitySystemAbilityClientImpl::RegisterElementOperator(Registration parameter, @@ -313,7 +315,8 @@ RetError AccessibilitySystemAbilityClientImpl::RegisterElementOperator(Registrat return RET_ERR_INVALID_PARAM; } - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("Failed to get aams service"); return RET_ERR_SAMGR; } @@ -331,7 +334,7 @@ RetError AccessibilitySystemAbilityClientImpl::RegisterElementOperator(Registrat .parentTreeId = parameter.parentTreeId, .elementId = parameter.elementId, }; - return static_cast(serviceProxy_->RegisterElementOperatorByParameter(registrationPara, + return static_cast(proxy->RegisterElementOperatorByParameter(registrationPara, aamsInteractionOperator)); } @@ -360,11 +363,12 @@ RetError AccessibilitySystemAbilityClientImpl::DeregisterElementOperator(const i HILOG_WARN("Not find windowID[%{public}d]", windowId); return RET_ERR_NO_REGISTER; } - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("Failed to get aams service"); return RET_ERR_SAMGR; } - return static_cast(serviceProxy_->DeregisterElementOperatorByWindowId(windowId)); + return static_cast(proxy->DeregisterElementOperatorByWindowId(windowId)); } RetError AccessibilitySystemAbilityClientImpl::DeregisterElementOperator(const int32_t windowId, const int32_t treeId) @@ -372,12 +376,13 @@ RetError AccessibilitySystemAbilityClientImpl::DeregisterElementOperator(const i HILOG_INFO("Deregister windowId[%{public}d] treeId[%{public}d] start", windowId, treeId); std::lock_guard lock(mutex_); - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("Failed to get aams service"); return RET_ERR_SAMGR; } - return static_cast(serviceProxy_->DeregisterElementOperatorByWindowIdAndTreeId(windowId, treeId)); + return static_cast(proxy->DeregisterElementOperatorByWindowIdAndTreeId(windowId, treeId)); } RetError AccessibilitySystemAbilityClientImpl::IsScreenReaderEnabled(bool &isEnabled) @@ -387,12 +392,13 @@ RetError AccessibilitySystemAbilityClientImpl::IsScreenReaderEnabled(bool &isEna ApiReportHelper reporter("AccessibilitySystemAbilityClientImpl.IsScreenReaderEnabled"); #endif // ACCESSIBILITY_EMULATOR_DEFINED std::lock_guard lock(mutex_); - - if (serviceProxy_ == nullptr) { + + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("Failed to get aams service"); return RET_ERR_SAMGR; } - serviceProxy_->GetScreenReaderState(isEnabled); + proxy->GetScreenReaderState(isEnabled); return RET_OK; } @@ -451,12 +457,13 @@ RetError AccessibilitySystemAbilityClientImpl::GetAbilityList(const uint32_t acc accessibilityAbilityTypes, stateType); return RET_ERR_INVALID_PARAM; } - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("Failed to get aams service"); return RET_ERR_SAMGR; } std::vector infosParcel = {}; - RetError ret = static_cast(serviceProxy_->GetAbilityList(accessibilityAbilityTypes, stateType, + RetError ret = static_cast(proxy->GetAbilityList(accessibilityAbilityTypes, stateType, infosParcel)); if (infosParcel.size() < 0 || infosParcel.size() > ABILITY_SIZE_MAX) { HILOG_ERROR("abilityInfoSize is invalid"); @@ -492,12 +499,13 @@ RetError AccessibilitySystemAbilityClientImpl::SendEvent(const EventType eventTy AccessibilityEventInfo event; event.SetEventType(eventType); event.SetSource(componentId); - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("Failed to get aams service"); return RET_ERR_SAMGR; } AccessibilityEventInfoParcel eventInfoParcel(event); - return static_cast(serviceProxy_->SendEvent(eventInfoParcel, 1)); + return static_cast(proxy->SendEvent(eventInfoParcel, 1)); } RetError AccessibilitySystemAbilityClientImpl::SendEvent(const AccessibilityEventInfo &event) @@ -507,12 +515,13 @@ RetError AccessibilitySystemAbilityClientImpl::SendEvent(const AccessibilityEven if (!CheckEventType(event.GetEventType())) { return RET_ERR_INVALID_PARAM; } - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("Failed to get aams service"); return RET_ERR_SAMGR; } AccessibilityEventInfoParcel eventInfoParcel(event); - return static_cast(serviceProxy_->SendEvent(eventInfoParcel, 1)); + return static_cast(proxy->SendEvent(eventInfoParcel, 1)); } RetError AccessibilitySystemAbilityClientImpl::SubscribeStateObserver( @@ -631,11 +640,12 @@ RetError AccessibilitySystemAbilityClientImpl::GetEnabledAbilities(std::vector lock(mutex_); - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("Failed to get aams service"); return RET_ERR_SAMGR; } - RetError ret = static_cast(serviceProxy_->GetEnabledAbilities(enabledAbilities)); + RetError ret = static_cast(proxy->GetEnabledAbilities(enabledAbilities)); if (enabledAbilities.size() < 0 || enabledAbilities.size() > ABILITY_SIZE_MAX) { HILOG_ERROR("dev_num is invalid"); return RET_ERR_INVALID_PARAM; @@ -675,7 +685,8 @@ void AccessibilitySystemAbilityClientImpl::SetSearchElementInfoByAccessibilityId { std::lock_guard lock(mutex_); HILOG_DEBUG("search element requestId[%{public}d]", requestId); - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("serviceProxy_ is nullptr"); return; } @@ -690,7 +701,7 @@ void AccessibilitySystemAbilityClientImpl::SetSearchElementInfoByAccessibilityId if (callback->GetFilter()) { AccessibilityElementOperatorImpl::SetFiltering(filterInfos); } - serviceProxy_->RemoveRequestId(requestId); + proxy->RemoveRequestId(requestId); callback->SetSearchElementInfoByAccessibilityIdResult(filterInfos, requestId); AccessibilityElementOperatorImpl::EraseCallback(requestId); } else { @@ -703,7 +714,8 @@ void AccessibilitySystemAbilityClientImpl::SetSearchDefaultFocusByWindowIdResult { std::lock_guard lock(mutex_); HILOG_DEBUG("search element requestId[%{public}d]", requestId); - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("serviceProxy_ is nullptr"); return; } @@ -718,7 +730,7 @@ void AccessibilitySystemAbilityClientImpl::SetSearchDefaultFocusByWindowIdResult if (callback->GetFilter()) { AccessibilityElementOperatorImpl::SetFiltering(filterInfos); } - serviceProxy_->RemoveRequestId(requestId); + proxy->RemoveRequestId(requestId); callback->SetSearchDefaultFocusByWindowIdResult(filterInfos, requestId); AccessibilityElementOperatorImpl::EraseCallback(requestId); } else { @@ -731,7 +743,8 @@ void AccessibilitySystemAbilityClientImpl::SetSearchElementInfoByTextResult( { std::lock_guard lock(mutex_); HILOG_DEBUG("requestId[%{public}d]", requestId); - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("serviceProxy_ is nullptr"); return; } @@ -740,7 +753,7 @@ void AccessibilitySystemAbilityClientImpl::SetSearchElementInfoByTextResult( AccessibilityElementOperatorImpl::GetCallbackByRequestId(requestId); if (requestId >= 0) { if (callback != nullptr) { - serviceProxy_->RemoveRequestId(requestId); + proxy->RemoveRequestId(requestId); callback->SetSearchElementInfoByTextResult(filterInfos, requestId); AccessibilityElementOperatorImpl::EraseCallback(requestId); } else { @@ -754,7 +767,9 @@ void AccessibilitySystemAbilityClientImpl::SetFindFocusedElementInfoResult( { std::lock_guard lock(mutex_); HILOG_DEBUG("requestId[%{public}d]", requestId); - if (serviceProxy_ == nullptr) { + + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("serviceProxy_ is nullptr"); return; } @@ -762,7 +777,7 @@ void AccessibilitySystemAbilityClientImpl::SetFindFocusedElementInfoResult( AccessibilityElementOperatorImpl::GetCallbackByRequestId(requestId); if (requestId >= 0) { if (callback != nullptr) { - serviceProxy_->RemoveRequestId(requestId); + proxy->RemoveRequestId(requestId); callback->SetFindFocusedElementInfoResult(info, requestId); AccessibilityElementOperatorImpl::EraseCallback(requestId); } else { @@ -776,7 +791,8 @@ void AccessibilitySystemAbilityClientImpl::SetFocusMoveSearchResult( { std::lock_guard lock(mutex_); HILOG_DEBUG("requestId[%{public}d]", requestId); - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("serviceProxy_ is nullptr"); return; } @@ -784,7 +800,7 @@ void AccessibilitySystemAbilityClientImpl::SetFocusMoveSearchResult( AccessibilityElementOperatorImpl::GetCallbackByRequestId(requestId); if (requestId >= 0) { if (callback != nullptr) { - serviceProxy_->RemoveRequestId(requestId); + proxy->RemoveRequestId(requestId); callback->SetFocusMoveSearchResult(info, requestId); AccessibilityElementOperatorImpl::EraseCallback(requestId); } else { @@ -798,7 +814,8 @@ void AccessibilitySystemAbilityClientImpl::SetExecuteActionResult( { std::lock_guard lock(mutex_); HILOG_DEBUG("requestId[%{public}d]", requestId); - if (serviceProxy_ == nullptr) { + auto proxy = GetProxy(); + if (proxy == nullptr) { HILOG_ERROR("serviceProxy_ is nullptr"); return; } @@ -806,7 +823,7 @@ void AccessibilitySystemAbilityClientImpl::SetExecuteActionResult( AccessibilityElementOperatorImpl::GetCallbackByRequestId(requestId); if (requestId >= 0) { if (callback != nullptr) { - serviceProxy_->RemoveRequestId(requestId); + proxy->RemoveRequestId(requestId); callback->SetExecuteActionResult(succeeded, requestId); AccessibilityElementOperatorImpl::EraseCallback(requestId); } else {