diff --git a/frameworks/acfwk/src/accessibility_config_impl.cpp b/frameworks/acfwk/src/accessibility_config_impl.cpp index 1aba96d3e64d68a9a08a35d9405b72ae8628d6e1..ce512c7e62089e1911631c7ac95f69a531c98bfc 100644 --- a/frameworks/acfwk/src/accessibility_config_impl.cpp +++ b/frameworks/acfwk/src/accessibility_config_impl.cpp @@ -125,7 +125,11 @@ bool AccessibilityConfig::Impl::RegisterToService() HILOG_ERROR("Create captionObserver_ failed."); return false; } - serviceProxy_->RegisterCaptionObserver(captionObserver_); + uint32_t ret = serviceProxy_->RegisterCaptionObserver(captionObserver_); + if (ret != 0) { + HILOG_ERROR("Register captionObserver failed."); + return false; + } } if (!enableAbilityListsObserver_) { @@ -143,7 +147,11 @@ bool AccessibilityConfig::Impl::RegisterToService() HILOG_ERROR("Create configObserver_ failed."); return false; } - serviceProxy_->RegisterConfigObserver(configObserver_); + uint32_t ret = serviceProxy_->RegisterConfigObserver(configObserver_); + if (ret != 0) { + HILOG_ERROR("Register configObserver failed."); + return false; + } } HILOG_DEBUG("RegisterToService succeaddss"); diff --git a/services/aams/src/accessible_ability_channel.cpp b/services/aams/src/accessible_ability_channel.cpp index eb716f612088e5c94671bcfe66b40929124d646e..fb6d5af4f3bc3e3a1f4b78cab5ca2ecb650022fd 100644 --- a/services/aams/src/accessible_ability_channel.cpp +++ b/services/aams/src/accessible_ability_channel.cpp @@ -22,6 +22,10 @@ namespace OHOS { namespace Accessibility { +namespace { + constexpr uint32_t TIME_OUT_OPERATOR = 5000; +} // namespace + AccessibleAbilityChannel::AccessibleAbilityChannel(const int32_t accountId, const std::string &clientName) : clientName_(clientName), accountId_(accountId) { @@ -56,6 +60,12 @@ RetError AccessibleAbilityChannel::SearchElementInfoByAccessibilityId(const int3 HILOG_DEBUG("AccessibleAbilityChannel::SearchElementInfoByAccessibilityId successfully"); syncPromise.set_value(RET_OK); }, accountId_, clientName_), "SearchElementInfoByAccessibilityId"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait SearchElementInfoByAccessibilityId result"); + return RET_ERR_TIME_OUT; + } return syncFuture.get(); } @@ -85,6 +95,12 @@ RetError AccessibleAbilityChannel::SearchElementInfosByText(const int32_t access elementOperator->SearchElementInfosByText(elementId, text, requestId, callback); syncPromise.set_value(RET_OK); }, accountId_, clientName_), "SearchElementInfosByText"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait SearchElementInfosByText result"); + return RET_ERR_TIME_OUT; + } return syncFuture.get(); } @@ -114,6 +130,12 @@ RetError AccessibleAbilityChannel::FindFocusedElementInfo(const int32_t accessib elementOperator->FindFocusedElementInfo(elementId, focusType, requestId, callback); syncPromise.set_value(RET_OK); }, accountId_, clientName_), "FindFocusedElementInfo"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait FindFocusedElementInfo result"); + return RET_ERR_TIME_OUT; + } return syncFuture.get(); } @@ -142,6 +164,12 @@ RetError AccessibleAbilityChannel::FocusMoveSearch(const int32_t accessibilityWi elementOperator->FocusMoveSearch(elementId, direction, requestId, callback); syncPromise.set_value(RET_OK); }, accountId_, clientName_), "FocusMoveSearch"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait FocusMoveSearch result"); + return RET_ERR_TIME_OUT; + } return syncFuture.get(); } @@ -171,6 +199,12 @@ RetError AccessibleAbilityChannel::ExecuteAction(const int32_t accessibilityWind elementOperator->ExecuteAction(elementId, action, actionArguments, requestId, callback); syncPromise.set_value(RET_OK); }, accountId_, clientName_), "ExecuteAction"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait ExecuteAction result"); + return RET_ERR_TIME_OUT; + } return syncFuture.get(); } @@ -206,6 +240,12 @@ RetError AccessibleAbilityChannel::GetWindow(const int32_t windowId, Accessibili syncPromise.set_value(RET_ERR_NO_WINDOW_CONNECTION); } }, accountId_, clientName_), "GetWindow"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait GetWindow result"); + return RET_ERR_TIME_OUT; + } return syncFuture.get(); } @@ -258,6 +298,12 @@ RetError AccessibleAbilityChannel::GetWindows(uint64_t displayId, std::vectorInjectEvents(gesturePath); syncPromise.set_value(RET_OK); }, accountId_, clientName_), "SendSimulateGesture"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait SendSimulateGesture result"); + return RET_ERR_TIME_OUT; + } return syncFuture.get(); } @@ -348,6 +400,12 @@ RetError AccessibleAbilityChannel::SetTargetBundleName(const std::vectorSetAbilityInfoTargetBundleName(targetBundleNames); syncPromise.set_value(RET_OK); }, accountId_, clientName_), "SetTargetBundleName"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait SetTargetBundleName result"); + return RET_ERR_TIME_OUT; + } return syncFuture.get(); } diff --git a/services/aams/src/accessible_ability_manager_service.cpp b/services/aams/src/accessible_ability_manager_service.cpp index 0d68b22007c3708b3faa77b126ff807e13141c06..39945882446bffecdf797cf3deec6e411bfc0731 100644 --- a/services/aams/src/accessible_ability_manager_service.cpp +++ b/services/aams/src/accessible_ability_manager_service.cpp @@ -45,6 +45,7 @@ namespace { const std::string ARKUI_ANIMATION_SCALE_NAME = "persist.sys.arkui.animationscale"; constexpr int32_t QUERY_USER_ID_RETRY_COUNT = 600; constexpr int32_t QUERY_USER_ID_SLEEP_TIME = 50; + constexpr uint32_t TIME_OUT_OPERATOR = 5000; } // namespace const bool REGISTER_RESULT = @@ -349,6 +350,12 @@ uint32_t AccessibleAbilityManagerService::RegisterCaptionObserver( accountData->GetCaptionPropertyCallbacks().size()); syncPromise.set_value(NO_ERROR); }), "TASK_REGISTER_CAPTION_OBSERVER"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait RegisterCaptionObserver result"); + return RET_ERR_TIME_OUT; + } return syncFuture.get(); } @@ -388,6 +395,12 @@ void AccessibleAbilityManagerService::RegisterEnableAbilityListsObserver( accountData->AddEnableAbilityListsObserver(observer); syncPromise.set_value(); }), "TASK_REGISTER_ENABLE_ABILITY_LISTS_OBSERVER"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait RegisterEnableAbilityListsObserver result"); + return; + } return syncFuture.get(); } @@ -1985,6 +1998,12 @@ uint32_t AccessibleAbilityManagerService::RegisterConfigObserver( accountData->GetConfigCallbacks().size()); syncPromise.set_value(NO_ERROR); }), "TASK_REGISTER_CONFIG_OBSERVER"); + + std::future_status wait = syncFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); + if (wait != std::future_status::ready) { + HILOG_ERROR("Failed to wait RegisterConfigObserver result"); + return RET_ERR_TIME_OUT; + } return syncFuture.get(); }