From 4db58675de0630b56a3b82b986ee62750ef7bb68 Mon Sep 17 00:00:00 2001 From: laiguizhong Date: Tue, 18 Oct 2022 19:36:18 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"!432=20=E5=9B=9E=E9=80=80=20'Pull=20R?= =?UTF-8?q?equest=20!425=20:=20=E6=97=A0=E9=9A=9C=E7=A2=8D=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0ErrorCode'"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7a48329c6ec925414e95d5cb311dd7824188e5c5, reversing changes made to 5841ac57bff163c487970829b4227c64491c1cf4. Signed-off-by: laiguizhong Change-Id: I654d33838ef48aef2aeba1402a174e52d03b3310 --- .../accessible_ability_channel_proxy.h | 40 +- ...accessible_ability_manager_service_proxy.h | 24 +- .../accessible_ability_manager_service_stub.h | 1 - .../include/i_accessible_ability_channel.h | 40 +- .../i_accessible_ability_manager_service.h | 26 +- .../src/accessible_ability_channel_proxy.cpp | 185 +++---- .../src/accessible_ability_channel_stub.cpp | 40 +- ...cessible_ability_manager_service_proxy.cpp | 83 +-- ...ccessible_ability_manager_service_stub.cpp | 108 ++-- .../accessibility_ui_test_ability_impl.h | 82 +-- .../accessible_ability_channel_client.h | 40 +- .../include/accessible_ability_client_impl.h | 77 +-- .../accessibility_ui_test_ability_impl.cpp | 80 +-- .../src/accessible_ability_channel_client.cpp | 113 ++-- .../src/accessible_ability_client_impl.cpp | 166 +++--- .../mock_accessible_ability_channel_proxy.h | 26 +- .../mock_accessible_ability_channel_stub.h | 28 +- .../include/mock_accessible_ability_client.h | 38 +- .../mock_accessible_ability_channel_proxy.cpp | 35 +- .../src/mock_accessible_ability_client.cpp | 77 +-- ...ccessibility_ui_test_ability_impl_test.cpp | 70 +-- ...accessible_ability_channel_client_test.cpp | 96 ++-- .../accessible_ability_client_impl_test.cpp | 102 ++-- .../acfwk/include/accessibility_config_impl.h | 16 +- frameworks/acfwk/src/accessibility_config.cpp | 32 +- .../acfwk/src/accessibility_config_impl.cpp | 26 +- .../accessibility_config_impl_test.cpp | 5 +- ...accessibility_system_ability_client_impl.h | 41 +- ...cessibility_system_ability_client_impl.cpp | 88 +-- ...bility_system_ability_client_impl_test.cpp | 57 +- .../common/src/accessibility_window_info.cpp | 4 +- .../include/accessibility_ui_test_ability.h | 81 +-- .../aafwk/include/accessible_ability_client.h | 73 +-- .../acfwk/include/accessibility_config.h | 53 +- .../accessibility_system_ability_client.h | 41 +- .../common/include/accessibility_def.h | 27 +- ...cessibility_system_ability_client_test.cpp | 6 +- .../js/@ohos.accessibility.GesturePath.d.ts | 6 +- .../js/@ohos.accessibility.GesturePoint.d.ts | 4 +- .../kits/js/@ohos.accessibility.config.d.ts | 71 ++- interfaces/kits/js/@ohos.accessibility.d.ts | 218 ++++---- .../js/AccessibilityExtensionContext.d.ts | 25 +- .../include/napi_accessibility_config.h | 2 +- .../src/napi_accessibility_config.cpp | 505 ++++++++++++------ .../include/accessibility_extension_context.h | 56 +- .../include/napi_accessibility_element.h | 3 +- .../src/accessibility_extension_context.cpp | 64 +-- .../src/napi_accessibility_element.cpp | 426 +++++++++------ .../src/napi_accessibility_extension.cpp | 4 +- .../napi_accessibility_extension_context.cpp | 80 ++- .../napi/include/napi_accessibility_def.h | 77 +++ ...napi_accessibility_system_ability_client.h | 1 + .../napi/include/napi_accessibility_utils.h | 9 +- ...pi_accessibility_system_ability_client.cpp | 476 ++++++++++++----- .../napi/src/napi_accessibility_utils.cpp | 56 +- interfaces/kits/napi/src/native_module.cpp | 2 + .../aams/include/accessibility_account_data.h | 9 +- .../aams/include/accessible_ability_channel.h | 26 +- .../accessible_ability_manager_service.h | 20 +- .../aams/src/accessibility_account_data.cpp | 69 +-- .../aams/src/accessibility_window_manager.cpp | 2 +- .../aams/src/accessible_ability_channel.cpp | 171 +++--- .../accessible_ability_manager_service.cpp | 97 ++-- services/aams/test/BUILD.gn | 4 +- .../include/mock_accessibility_account_data.h | 2 +- .../mock_accessible_ability_connection.h | 17 +- .../mock_accessible_ability_manager_service.h | 12 +- .../src/mock_accessibility_account_data.cpp | 12 +- .../mock_accessible_ability_channel_proxy.cpp | 43 +- .../mock_accessible_ability_connection.cpp | 45 +- ...ock_accessible_ability_manager_service.cpp | 29 +- .../accessibility_account_data_test.cpp | 28 +- .../accessibility_input_interceptor_test.cpp | 2 - ...accessibility_touchEvent_injector_test.cpp | 2 - .../accessible_ability_channel_test.cpp | 22 +- ...ccessible_ability_manager_service_test.cpp | 42 +- ...ccessible_ability_manager_service_stub.cpp | 29 +- ..._accessible_ability_manager_service_stub.h | 16 +- .../src/mock_input_manager.cpp | 14 +- ...ams_accessibility_keyevent_filter_test.cpp | 16 +- ...accessibility_touchEvent_injector_test.cpp | 281 +++++----- .../aams_accessibility_touch_guider_test.cpp | 10 +- .../aams_accessible_ability_channel_test.cpp | 151 +++--- .../aams_common_event_registry_test.cpp | 23 +- .../aams_server_test/aams_server_test.cpp | 19 +- 85 files changed, 3140 insertions(+), 2285 deletions(-) diff --git a/common/interface/include/accessible_ability_channel_proxy.h b/common/interface/include/accessible_ability_channel_proxy.h index adbbde25d..e391281c4 100644 --- a/common/interface/include/accessible_ability_channel_proxy.h +++ b/common/interface/include/accessible_ability_channel_proxy.h @@ -44,9 +44,9 @@ public: * PREFETCH_SIBLINGS: Need to make the sister/brothers element info also. * PREFETCH_CHILDREN: Need to make the child element info also. * otherwise: Make the element information by elementId only. - * @return Return true if search elementInfo successfully, else return false. + * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, + virtual RetError SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr &callback, const int32_t mode) override; @@ -58,9 +58,9 @@ public: * @param text Filter for the child components to matched with the text * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only. * @param callback To transfer the element info to ASAC and it defined by ASAC. - * @return Return true if search elementInfo successfully, else return false. + * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, + virtual RetError SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, const std::string &text, const int32_t requestId, const sptr &callback) override; @@ -73,9 +73,9 @@ public: * FOCUS_TYPE_INPUT: text input focus * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only. * @param callback To transfer the element info to ASAC and it defined by ASAC. - * @return Return true if find elementInfo successfully, else return false. + * @return Return RET_OK if find elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, + virtual RetError FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, const int32_t requestId, const sptr &callback) override; @@ -86,9 +86,9 @@ public: * @param direction Refer to AccessibilityElementInfo.FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD) * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only. * @param callback To transfer the element info to ASAC and it defined by ASAC. - * @return Return true if search elementInfo successfully, else return false. + * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, + virtual RetError FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, const int32_t requestId, const sptr &callback) override; @@ -100,9 +100,9 @@ public: * @param actionArguments The parameter for action type. * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only. * @param callback To transfer the node info to ASAC and it defined by ASAC. - * @return Return true if perform action successfully, else return false. + * @return Return RET_OK if perform action successfully, otherwise refer to the RetError for the failure. */ - virtual bool ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, + virtual RetError ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map &actionArguments, const int32_t requestId, const sptr &callback) override; @@ -110,24 +110,24 @@ public: * @brief Get the window information related with the event * @param windowId The window id. * @param windowInfo The window information. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; + virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindows(std::vector &windows) override; + virtual RetError GetWindows(std::vector &windows) override; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param displayId the id of display * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindowsByDisplayId(const uint64_t displayId, + virtual RetError GetWindowsByDisplayId(const uint64_t displayId, std::vector &windows) override; /** @@ -140,16 +140,16 @@ public: /** * @brief Send simulation gesture through the proxy object. * @param gesturePath The gesture path to send. - * @return Return true if gesture injection is successfully, otherwise return false. + * @return Return RET_OK if gesture injection is successfully, otherwise refer to the RetError for the failure. */ - virtual bool SendSimulateGesture(const std::shared_ptr& gesturePath) override; + virtual RetError SendSimulateGesture(const std::shared_ptr& gesturePath) override; /** * @brief Set target bundle names. * @param targetBundleNames The target bundle name - * @return Return true if sets target bundle names successfully, else return false. + * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. */ - virtual bool SetTargetBundleName(const std::vector &targetBundleNames) override; + virtual RetError SetTargetBundleName(const std::vector &targetBundleNames) override; private: /** diff --git a/common/interface/include/accessible_ability_manager_service_proxy.h b/common/interface/include/accessible_ability_manager_service_proxy.h index fe88d17fb..0db78c9cc 100644 --- a/common/interface/include/accessible_ability_manager_service_proxy.h +++ b/common/interface/include/accessible_ability_manager_service_proxy.h @@ -40,9 +40,9 @@ public: /** * @brief Sends information about an accessibility event. * @param uiEvent Indicates the accessibility event information specified by AccessibilityEventInfo. - * @return true: send ok; otherwise is refused. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual void SendEvent(const AccessibilityEventInfo &uiEvent) override; + virtual RetError SendEvent(const AccessibilityEventInfo &uiEvent) override; /** * @brief Register the state observer of AAMS. @@ -64,25 +64,26 @@ public: * 2 indicates that the ability is disabled; * 3 indicates that the ability has been installed. * @param infos accessibility ability infos by specified types. - * @return Return true if get ability lists successfully, else return false. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, + virtual RetError GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, std::vector &infos) override; /** * @brief Register the element operator, so the AA can get node info from ACE. * @param windowId Window ID * @param operation The callback object. - * @return 0: Succeed ; otherwise is failed. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual void RegisterElementOperator(const int32_t windowId, + virtual RetError RegisterElementOperator(const int32_t windowId, const sptr &operation) override; /** * @brief Deregister the element operator. * @param windowId Window ID + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual void DeregisterElementOperator(const int32_t windowId) override; + virtual RetError DeregisterElementOperator(const int32_t windowId) override; virtual RetError GetCaptionProperty(AccessibilityConfig::CaptionProperty &caption) override; virtual RetError SetCaptionProperty(const AccessibilityConfig::CaptionProperty &caption) override; @@ -94,14 +95,13 @@ public: virtual bool GetGestureState() override; virtual bool GetKeyEventObserverState() override; - virtual bool EnableAbility(const std::string &name, const uint32_t capabilities) override; - virtual bool GetEnabledAbilities(std::vector &enabledAbilities) override; - - virtual bool DisableAbility(const std::string &name) override; + virtual RetError EnableAbility(const std::string &name, const uint32_t capabilities) override; + virtual RetError GetEnabledAbilities(std::vector &enabledAbilities) override; + virtual RetError DisableAbility(const std::string &name) override; virtual int32_t GetActiveWindow() override; virtual RetError EnableUITestAbility(const sptr &obj) override; - virtual bool DisableUITestAbility() override; + virtual RetError DisableUITestAbility() override; virtual RetError SetScreenMagnificationState(const bool state) override; virtual RetError SetShortKeyState(const bool state) override; diff --git a/common/interface/include/accessible_ability_manager_service_stub.h b/common/interface/include/accessible_ability_manager_service_stub.h index 3e31e0c36..35c8773ab 100644 --- a/common/interface/include/accessible_ability_manager_service_stub.h +++ b/common/interface/include/accessible_ability_manager_service_stub.h @@ -107,7 +107,6 @@ private: ErrCode HandleEnableAbility(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetEnabledAbilities(MessageParcel &data, MessageParcel &reply); - ErrCode HandleDisableAbility(MessageParcel &data, MessageParcel &reply); ErrCode HandleEnableUITestAbility(MessageParcel &data, MessageParcel &reply); ErrCode HandleDisableUITestAbility(MessageParcel &data, MessageParcel &reply); diff --git a/common/interface/include/i_accessible_ability_channel.h b/common/interface/include/i_accessible_ability_channel.h index 6f5c926c5..6f602f68a 100644 --- a/common/interface/include/i_accessible_ability_channel.h +++ b/common/interface/include/i_accessible_ability_channel.h @@ -41,9 +41,9 @@ public: * PREFETCH_SIBLINGS: Need to make the sister/brothers element info also. * PREFETCH_CHILDREN: Need to make the child element info also. * otherwise: Make the element information by elementId only. - * @return Return true if search elementInfo successfully, else return false. + * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, + virtual RetError SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr &callback, const int32_t mode) = 0; @@ -55,9 +55,9 @@ public: * @param text Filter for the child components to matched with the text * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only. * @param callback To transfer the element info to ASAC and it defined by ASAC. - * @return Return true if search elementInfo successfully, else return false. + * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, + virtual RetError SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, const std::string &text, const int32_t requestId, const sptr &callback) = 0; @@ -69,9 +69,9 @@ public: * FOCUS_TYPE_INPUT: text input focus * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only. * @param callback To transfer the element info to ASAC and it defined by ASAC. - * @return Return true if find elementInfo successfully, else return false. + * @return Return RET_OK if find elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, + virtual RetError FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, const int32_t requestId, const sptr &callback) = 0; @@ -82,9 +82,9 @@ public: * @param direction Refer to AccessibilityElementInfo.FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD) * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only. * @param callback To transfer the element info to ASAC and it defined by ASAC. - * @return Return true if search elementInfo successfully, else return false. + * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, + virtual RetError FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, const int32_t requestId, const sptr &callback) = 0; @@ -96,9 +96,9 @@ public: * @param actionArguments The parameter for action type. * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only. * @param callback To transfer the node info to ASAC and it defined by ASAC. - * @return Return true if perform action successfully, else return false. + * @return Return RET_OK if perform action successfully, otherwise refer to the RetError for the failure. */ - virtual bool ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, + virtual RetError ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map &actionArguments, const int32_t requestId, const sptr &callback) = 0; @@ -106,24 +106,24 @@ public: * @brief Get the window information related with the event * @param windowId The window id. * @param windowInfo The window information. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) = 0; + virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) = 0; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindows(std::vector &windows) = 0; + virtual RetError GetWindows(std::vector &windows) = 0; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param displayId the id of display * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindowsByDisplayId(const uint64_t displayId, + virtual RetError GetWindowsByDisplayId(const uint64_t displayId, std::vector &windows) = 0; /** @@ -136,16 +136,16 @@ public: /** * @brief Send simulation gesture. * @param gesturePath The gesture path to send. - * @return Return true if gesture injection is successfully, otherwise return false. + * @return Return RET_OK if gesture injection is successfully, otherwise refer to the RetError for the failure. */ - virtual bool SendSimulateGesture(const std::shared_ptr& gesturePath) = 0; + virtual RetError SendSimulateGesture(const std::shared_ptr& gesturePath) = 0; /** * @brief Set target bundle names. * @param targetBundleNames The target bundle name - * @return Return true if sets target bundle names successfully, else return false. + * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. */ - virtual bool SetTargetBundleName(const std::vector &targetBundleNames) = 0; + virtual RetError SetTargetBundleName(const std::vector &targetBundleNames) = 0; enum class Message { SEARCH_ELEMENTINFO_BY_ACCESSIBILITY_ID = 0, diff --git a/common/interface/include/i_accessible_ability_manager_service.h b/common/interface/include/i_accessible_ability_manager_service.h index 49d342413..8d23fcac5 100644 --- a/common/interface/include/i_accessible_ability_manager_service.h +++ b/common/interface/include/i_accessible_ability_manager_service.h @@ -58,9 +58,9 @@ public: /** * @brief Sends information about an accessibility event. * @param uiEvent Indicates the accessibility event information specified by AccessibilityEventInfo. - * @return true: send ok; otherwise is refused. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual void SendEvent(const AccessibilityEventInfo &uiEvent) = 0; + virtual RetError SendEvent(const AccessibilityEventInfo &uiEvent) = 0; /** * @brief Register the state observer of AAMS. @@ -82,25 +82,26 @@ public: * 2 indicates that the ability is disabled; * 3 indicates that the ability has been installed. * @param infos accessibility ability infos by specified types. - * @return Return true if get ability lists successfully, else return false. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, + virtual RetError GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, std::vector &infos) = 0; /** * @brief Register the element operator, so the AA can get node info from ACE. * @param windowId Window ID * @param operation The callback object. - * @return 0: Succeed ; otherwise is failed. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual void RegisterElementOperator( - const int32_t windowId, const sptr &operation) = 0; + virtual RetError RegisterElementOperator(const int32_t windowId, + const sptr &operation) = 0; /** * @brief Deregister the element operator. * @param windowId Window ID + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual void DeregisterElementOperator(const int32_t windowId) = 0; + virtual RetError DeregisterElementOperator(const int32_t windowId) = 0; virtual RetError GetCaptionProperty(AccessibilityConfig::CaptionProperty &caption) = 0; virtual bool GetEnabledState() = 0; @@ -112,14 +113,13 @@ public: virtual RetError SetCaptionProperty(const AccessibilityConfig::CaptionProperty &caption) = 0; virtual RetError SetCaptionState(const bool state) = 0; - virtual bool EnableAbility(const std::string &name, const uint32_t capabilities) = 0; - virtual bool GetEnabledAbilities(std::vector &enabledAbilities) = 0; - - virtual bool DisableAbility(const std::string &name) = 0; + virtual RetError EnableAbility(const std::string &name, const uint32_t capabilities) = 0; + virtual RetError GetEnabledAbilities(std::vector &enabledAbilities) = 0; + virtual RetError DisableAbility(const std::string &name) = 0; virtual int32_t GetActiveWindow() = 0; virtual RetError EnableUITestAbility(const sptr &obj) = 0; - virtual bool DisableUITestAbility() = 0; + virtual RetError DisableUITestAbility() = 0; virtual RetError SetScreenMagnificationState(const bool state) = 0; virtual RetError SetShortKeyState(const bool state) = 0; diff --git a/common/interface/src/accessible_ability_channel_proxy.cpp b/common/interface/src/accessible_ability_channel_proxy.cpp index a01408798..1a9f5ab32 100644 --- a/common/interface/src/accessible_ability_channel_proxy.cpp +++ b/common/interface/src/accessible_ability_channel_proxy.cpp @@ -58,188 +58,189 @@ bool AccessibleAbilityChannelProxy::SendTransactCmd(IAccessibleAbilityChannel::M return true; } -bool AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr &callback, const int32_t mode) { HILOG_DEBUG(); + if (!callback) { + HILOG_ERROR("callback is nullptr."); + return RET_ERR_INVALID_PARAM; + } MessageParcel data; MessageParcel reply; MessageOption option; if (!WriteInterfaceToken(data)) { - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(accessibilityWindowId)) { HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(elementId)) { HILOG_ERROR("elementId write error: %{public}d, ", elementId); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(requestId)) { HILOG_ERROR("requestId write error: %{public}d, ", requestId); - return false; - } - if (!callback) { - HILOG_ERROR("callback is nullptr."); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteRemoteObject(callback->AsObject())) { HILOG_ERROR("callback write error"); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(mode)) { HILOG_ERROR("mode write error: %{public}d, ", mode); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityChannel::Message::SEARCH_ELEMENTINFO_BY_ACCESSIBILITY_ID, data, reply, option)) { HILOG_ERROR("fail to find elementInfo by elementId"); - return false; + return RET_ERR_IPC_FAILED; } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } -bool AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, const std::string &text, const int32_t requestId, const sptr &callback) { HILOG_DEBUG(); + if (!callback) { + HILOG_ERROR("callback is nullptr."); + return RET_ERR_INVALID_PARAM; + } + MessageParcel data; MessageParcel reply; MessageOption option; if (!WriteInterfaceToken(data)) { - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(accessibilityWindowId)) { HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(elementId)) { HILOG_ERROR("elementId write error: %{public}d, ", elementId); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteString(text)) { HILOG_ERROR("text write error: %{public}s, ", text.c_str()); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(requestId)) { HILOG_ERROR("requestId write error: %{public}d, ", requestId); - return false; - } - if (!callback) { - HILOG_ERROR("callback is nullptr."); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteRemoteObject(callback->AsObject())) { HILOG_ERROR("callback write error"); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityChannel::Message::SEARCH_ELEMENTINFOS_BY_TEXT, data, reply, option)) { HILOG_ERROR("fail to find elementInfo by text"); - return false; + return RET_ERR_IPC_FAILED; } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } -bool AccessibleAbilityChannelProxy::FindFocusedElementInfo(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelProxy::FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, const int32_t requestId, const sptr &callback) { HILOG_DEBUG(); + if (!callback) { + HILOG_ERROR("callback is nullptr."); + return RET_ERR_INVALID_PARAM; + } MessageParcel data; MessageParcel reply; MessageOption option; if (!WriteInterfaceToken(data)) { - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(accessibilityWindowId)) { HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(elementId)) { HILOG_ERROR("elementId write error: %{public}d, ", elementId); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(focusType)) { HILOG_ERROR("focusType write error: %{public}d, ", focusType); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(requestId)) { HILOG_ERROR("requestId write error: %{public}d, ", requestId); - return false; - } - if (!callback) { - HILOG_ERROR("callback is nullptr."); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteRemoteObject(callback->AsObject())) { HILOG_ERROR("callback write error"); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityChannel::Message::FIND_FOCUSED_ELEMENTINFO, data, reply, option)) { HILOG_ERROR("fail to gain focus"); - return false; + return RET_ERR_IPC_FAILED; } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } -bool AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, +RetError AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, const int32_t requestId, const sptr &callback) { HILOG_DEBUG(); + if (!callback) { + HILOG_ERROR("callback is nullptr."); + return RET_ERR_INVALID_PARAM; + } MessageParcel data; MessageParcel reply; MessageOption option; if (!WriteInterfaceToken(data)) { - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(accessibilityWindowId)) { HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(elementId)) { HILOG_ERROR("elementId write error: %{public}d, ", elementId); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(direction)) { HILOG_ERROR("direction write error: %{public}d, ", direction); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(requestId)) { HILOG_ERROR("requestId write error: %{public}d, ", requestId); - return false; - } - if (!callback) { - HILOG_ERROR("callback is nullptr."); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteRemoteObject(callback->AsObject())) { HILOG_ERROR("callback write error"); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityChannel::Message::FOCUS_MOVE_SEARCH, data, reply, option)) { HILOG_ERROR("fail to search focus"); - return false; + return RET_ERR_IPC_FAILED; } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } -bool AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, +RetError AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map &actionArguments, const int32_t requestId, const sptr &callback) { @@ -250,19 +251,19 @@ bool AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWin MessageOption option; if (!WriteInterfaceToken(data)) { - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(accessibilityWindowId)) { HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(elementId)) { HILOG_ERROR("elementId write error: %{public}d, ", elementId); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(action)) { HILOG_ERROR("action write error: %{public}d, ", action); - return false; + return RET_ERR_IPC_FAILED; } std::vector actionArgumentsKey {}; @@ -273,31 +274,31 @@ bool AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWin } if (!data.WriteStringVector(actionArgumentsKey)) { HILOG_ERROR("actionArgumentsKey write error"); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteStringVector(actionArgumentsValue)) { HILOG_ERROR("actionArgumentsValue write error"); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(requestId)) { HILOG_ERROR("requestId write error: %{public}d, ", requestId); - return false; + return RET_ERR_IPC_FAILED; } if (!callback || !data.WriteRemoteObject(callback->AsObject())) { HILOG_ERROR("callback write error"); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityChannel::Message::PERFORM_ACTION, data, reply, option)) { HILOG_ERROR("fail to perform accessibility action"); - return false; + return RET_ERR_IPC_FAILED; } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } -bool AccessibleAbilityChannelProxy::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) +RetError AccessibleAbilityChannelProxy::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) { HILOG_DEBUG(); @@ -306,30 +307,30 @@ bool AccessibleAbilityChannelProxy::GetWindow(const int32_t windowId, Accessibil MessageOption option; if (!WriteInterfaceToken(data)) { - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(windowId)) { HILOG_ERROR("windowId write error: %{public}d, ", windowId); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityChannel::Message::GET_WINDOW, data, reply, option)) { HILOG_ERROR("fail to get window"); - return false; + return RET_ERR_IPC_FAILED; } sptr windowInfoParcel = reply.ReadStrongParcelable(); if (!windowInfoParcel) { HILOG_ERROR("ReadStrongParcelable failed"); - return false; + return RET_ERR_IPC_FAILED; } windowInfo = *windowInfoParcel; - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } -bool AccessibleAbilityChannelProxy::GetWindows(std::vector &windows) +RetError AccessibleAbilityChannelProxy::GetWindows(std::vector &windows) { HILOG_DEBUG(); MessageParcel data; @@ -337,12 +338,12 @@ bool AccessibleAbilityChannelProxy::GetWindows(std::vector window = reply.ReadStrongParcelable(); if (!window) { HILOG_ERROR("ReadStrongParcelable failed"); - return false; + return RET_ERR_IPC_FAILED; } windows.emplace_back(*window); } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } -bool AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t displayId, +RetError AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t displayId, std::vector &windows) { HILOG_DEBUG(); @@ -368,17 +369,17 @@ bool AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t display MessageOption option; if (!WriteInterfaceToken(data)) { - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteUint64(displayId)) { HILOG_ERROR("displayId write error: %{public}" PRIu64 ", ", displayId); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityChannel::Message::GET_WINDOWS_BY_DISPLAY_ID, data, reply, option)) { HILOG_ERROR("fail to get windows"); - return false; + return RET_ERR_IPC_FAILED; } int32_t windowsSize = reply.ReadInt32(); @@ -386,12 +387,12 @@ bool AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t display sptr window = reply.ReadStrongParcelable(); if (!window) { HILOG_ERROR("ReadStrongParcelable failed"); - return false; + return RET_ERR_IPC_FAILED; } windows.emplace_back(*window); } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } void AccessibleAbilityChannelProxy::SetOnKeyPressEventResult(const bool handled, const int32_t sequence) @@ -419,7 +420,7 @@ void AccessibleAbilityChannelProxy::SetOnKeyPressEventResult(const bool handled, } } -bool AccessibleAbilityChannelProxy::SendSimulateGesture( +RetError AccessibleAbilityChannelProxy::SendSimulateGesture( const std::shared_ptr& gesturePath) { HILOG_DEBUG(); @@ -427,7 +428,7 @@ bool AccessibleAbilityChannelProxy::SendSimulateGesture( new(std::nothrow) AccessibilityGestureInjectPathParcel(*gesturePath); if (!path) { HILOG_ERROR("Failed to create path."); - return false; + return RET_ERR_NULLPTR; } MessageParcel data; @@ -435,22 +436,22 @@ bool AccessibleAbilityChannelProxy::SendSimulateGesture( MessageOption option(MessageOption::TF_SYNC); if (!WriteInterfaceToken(data)) { - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteStrongParcelable(path)) { HILOG_ERROR("WriteStrongParcelable failed"); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityChannel::Message::SEND_SIMULATE_GESTURE_PATH, data, reply, option)) { HILOG_ERROR("fail to send simulation gesture path"); - return false; + return RET_ERR_IPC_FAILED; } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } -bool AccessibleAbilityChannelProxy::SetTargetBundleName(const std::vector &targetBundleNames) +RetError AccessibleAbilityChannelProxy::SetTargetBundleName(const std::vector &targetBundleNames) { HILOG_DEBUG(); @@ -459,23 +460,23 @@ bool AccessibleAbilityChannelProxy::SetTargetBundleName(const std::vector(reply.ReadInt32()); } } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/common/interface/src/accessible_ability_channel_stub.cpp b/common/interface/src/accessible_ability_channel_stub.cpp index e944fc6cb..84fabeb80 100644 --- a/common/interface/src/accessible_ability_channel_stub.cpp +++ b/common/interface/src/accessible_ability_channel_stub.cpp @@ -99,9 +99,9 @@ ErrCode AccessibleAbilityChannelStub::HandleSearchElementInfoByAccessibilityId(M } int32_t mode = data.ReadInt32(); - bool result = SearchElementInfoByAccessibilityId(accessibilityWindowId, elementId, requestId, callback, mode); + RetError result = SearchElementInfoByAccessibilityId(accessibilityWindowId, elementId, requestId, callback, mode); HILOG_DEBUG("SearchElementInfoByAccessibilityId ret = %{public}d", result); - reply.WriteBool(result); + reply.WriteInt32(result); return NO_ERROR; } @@ -120,9 +120,9 @@ ErrCode AccessibleAbilityChannelStub::HandleSearchElementInfosByText(MessageParc sptr callback = iface_cast(remote); - bool result = SearchElementInfosByText(accessibilityWindowId, elementId, text, requestId, callback); + RetError result = SearchElementInfosByText(accessibilityWindowId, elementId, text, requestId, callback); HILOG_DEBUG("SearchElementInfosByText ret = %{public}d", result); - reply.WriteBool(result); + reply.WriteInt32(result); return NO_ERROR; } @@ -140,9 +140,9 @@ ErrCode AccessibleAbilityChannelStub::HandleFindFocusedElementInfo(MessageParcel sptr callback = iface_cast(remote); - bool result = FindFocusedElementInfo(accessibilityWindowId, elementId, focusType, requestId, callback); + RetError result = FindFocusedElementInfo(accessibilityWindowId, elementId, focusType, requestId, callback); HILOG_DEBUG("FindFocusedElementInfo ret = %{public}d", result); - reply.WriteBool(result); + reply.WriteInt32(result); return NO_ERROR; } @@ -160,9 +160,9 @@ ErrCode AccessibleAbilityChannelStub::HandleFocusMoveSearch(MessageParcel &data, sptr callback = iface_cast(remote); - bool result = FocusMoveSearch(accessibilityWindowId, elementId, direction, requestId, callback); + RetError result = FocusMoveSearch(accessibilityWindowId, elementId, direction, requestId, callback); HILOG_DEBUG("FocusMoveSearch ret = %{public}d", result); - reply.WriteBool(result); + reply.WriteInt32(result); return NO_ERROR; } @@ -203,9 +203,9 @@ ErrCode AccessibleAbilityChannelStub::HandleExecuteAction(MessageParcel &data, M return ERR_INVALID_VALUE; } - bool result = ExecuteAction(accessibilityWindowId, elementId, action, actionArguments, requestId, callback); + RetError result = ExecuteAction(accessibilityWindowId, elementId, action, actionArguments, requestId, callback); HILOG_DEBUG("ExecuteAction ret = %{public}d", result); - reply.WriteBool(result); + reply.WriteInt32(result); return NO_ERROR; } @@ -220,13 +220,13 @@ ErrCode AccessibleAbilityChannelStub::HandleGetWindow(MessageParcel &data, Messa return ERR_NULL_OBJECT; } - bool result = GetWindow(windowId, *windowInfoParcel); + RetError result = GetWindow(windowId, *windowInfoParcel); if (!reply.WriteStrongParcelable(windowInfoParcel)) { HILOG_ERROR("WriteStrongParcelable windows failed"); return ERR_INVALID_VALUE; } - reply.WriteBool(result); + reply.WriteInt32(result); return NO_ERROR; } @@ -234,7 +234,7 @@ ErrCode AccessibleAbilityChannelStub::HandleGetWindows(MessageParcel &data, Mess { HILOG_DEBUG(); std::vector windows; - bool result = GetWindows(windows); + RetError result = GetWindows(windows); if (!reply.WriteInt32(static_cast(windows.size()))) { HILOG_ERROR("windows.size() write error: %{public}zu, ", windows.size()); return ERR_INVALID_VALUE; @@ -250,7 +250,7 @@ ErrCode AccessibleAbilityChannelStub::HandleGetWindows(MessageParcel &data, Mess return ERR_INVALID_VALUE; } } - reply.WriteBool(result); + reply.WriteInt32(result); return NO_ERROR; } @@ -260,7 +260,7 @@ ErrCode AccessibleAbilityChannelStub::HandleGetWindowsByDisplayId(MessageParcel uint64_t displayId = data.ReadUint64(); std::vector windows; - bool result = GetWindowsByDisplayId(displayId, windows); + RetError result = GetWindowsByDisplayId(displayId, windows); if (!reply.WriteInt32(static_cast(windows.size()))) { HILOG_ERROR("windows.size() write error: %{public}zu, ", windows.size()); return ERR_INVALID_VALUE; @@ -276,7 +276,7 @@ ErrCode AccessibleAbilityChannelStub::HandleGetWindowsByDisplayId(MessageParcel return ERR_INVALID_VALUE; } } - reply.WriteBool(result); + reply.WriteInt32(result); return NO_ERROR; } @@ -304,8 +304,8 @@ ErrCode AccessibleAbilityChannelStub::HandleSendSimulateGesturePath(MessageParce std::shared_ptr gesturePath = std::make_shared(*positions); - bool result = SendSimulateGesture(gesturePath); - reply.WriteBool(result); + RetError result = SendSimulateGesture(gesturePath); + reply.WriteInt32(result); return NO_ERROR; } @@ -318,8 +318,8 @@ ErrCode AccessibleAbilityChannelStub::HandleSetTargetBundleName(MessageParcel &d std::string temp = data.ReadString(); targetBundleNames.emplace_back(temp); } - bool result = SetTargetBundleName(targetBundleNames); - reply.WriteBool(result); + RetError result = SetTargetBundleName(targetBundleNames); + reply.WriteInt32(result); return NO_ERROR; } } // namespace Accessibility diff --git a/common/interface/src/accessible_ability_manager_service_proxy.cpp b/common/interface/src/accessible_ability_manager_service_proxy.cpp index f5e5343fe..03c2f4c2d 100644 --- a/common/interface/src/accessible_ability_manager_service_proxy.cpp +++ b/common/interface/src/accessible_ability_manager_service_proxy.cpp @@ -56,7 +56,7 @@ bool AccessibleAbilityManagerServiceProxy::SendTransactCmd(IAccessibleAbilityMan return true; } -void AccessibleAbilityManagerServiceProxy::SendEvent(const AccessibilityEventInfo &uiEvent) +RetError AccessibleAbilityManagerServiceProxy::SendEvent(const AccessibilityEventInfo &uiEvent) { HILOG_DEBUG(); MessageParcel data; @@ -66,18 +66,19 @@ void AccessibleAbilityManagerServiceProxy::SendEvent(const AccessibilityEventInf if (!WriteInterfaceToken(data)) { HILOG_ERROR("fail, connection write Token"); - return; + return RET_ERR_IPC_FAILED; } if (!data.WriteParcelable(&eventInfoParcel)) { HILOG_ERROR("fail, connection write parcelable AccessibilityEventInfo error"); - return; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityManagerService::Message::SEND_EVENT, data, reply, option)) { HILOG_ERROR("SendEvent fail"); - return; + return RET_ERR_IPC_FAILED; } + return RET_OK; } RetError AccessibleAbilityManagerServiceProxy::SetCaptionProperty(const AccessibilityConfig::CaptionProperty &caption) @@ -161,7 +162,7 @@ uint32_t AccessibleAbilityManagerServiceProxy::RegisterStateObserver( return reply.ReadUint32(); } -bool AccessibleAbilityManagerServiceProxy::GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, +RetError AccessibleAbilityManagerServiceProxy::GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, std::vector &infos) { HILOG_DEBUG(); @@ -171,23 +172,23 @@ bool AccessibleAbilityManagerServiceProxy::GetAbilityList(const uint32_t ability if (!WriteInterfaceToken(data)) { HILOG_ERROR("fail, connection write Token error"); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteUint32(abilityTypes)) { HILOG_ERROR("fail, connection write abilityTypes error"); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(stateType)) { HILOG_ERROR("fail, connection write stateType error"); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityManagerService::Message::GET_ABILITYLIST, data, reply, option)) { HILOG_ERROR("GetAbilityList fail"); - return false; + return RET_ERR_IPC_FAILED; } // read result int32_t abilityInfoSize = reply.ReadInt32(); @@ -195,14 +196,14 @@ bool AccessibleAbilityManagerServiceProxy::GetAbilityList(const uint32_t ability sptr info = reply.ReadStrongParcelable(); if (!info) { HILOG_ERROR("ReadStrongParcelable failed"); - return false; + return RET_ERR_IPC_FAILED; } infos.emplace_back(*info); } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } -void AccessibleAbilityManagerServiceProxy::RegisterElementOperator( +RetError AccessibleAbilityManagerServiceProxy::RegisterElementOperator( int32_t windowId, const sptr &operation) { HILOG_DEBUG(); @@ -212,32 +213,33 @@ void AccessibleAbilityManagerServiceProxy::RegisterElementOperator( if (!operation) { HILOG_ERROR("fail, Input operation is null"); - return; + return RET_ERR_INVALID_PARAM; } if (!WriteInterfaceToken(data)) { HILOG_ERROR("fail, connection write Token"); - return; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(windowId)) { HILOG_ERROR("fail, connection write windowId error"); - return; + return RET_ERR_IPC_FAILED; } if (!data.WriteRemoteObject(operation->AsObject())) { HILOG_ERROR("fail, connection write parcelable operation error"); - return; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityManagerService::Message::REGISTER_INTERACTION_CONNECTION, data, reply, option)) { HILOG_ERROR("RegisterElementOperator fail"); - return; + return RET_ERR_IPC_FAILED; } + return RET_OK; } -void AccessibleAbilityManagerServiceProxy::DeregisterElementOperator(const int32_t windowId) +RetError AccessibleAbilityManagerServiceProxy::DeregisterElementOperator(const int32_t windowId) { HILOG_DEBUG("windowId(%{public}d)", windowId); MessageParcel data; @@ -246,19 +248,20 @@ void AccessibleAbilityManagerServiceProxy::DeregisterElementOperator(const int32 if (!WriteInterfaceToken(data)) { HILOG_ERROR("fail, connection write Token"); - return; + return RET_ERR_IPC_FAILED; } if (!data.WriteInt32(windowId)) { HILOG_ERROR("fail, connection write userId error"); - return; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityManagerService::Message::DEREGISTER_INTERACTION_CONNECTION, data, reply, option)) { HILOG_ERROR("DeregisterElementOperator fail"); - return; + return RET_ERR_IPC_FAILED; } + return RET_OK; } RetError AccessibleAbilityManagerServiceProxy::GetCaptionProperty(AccessibilityConfig::CaptionProperty &caption) @@ -416,7 +419,7 @@ bool AccessibleAbilityManagerServiceProxy::GetKeyEventObserverState() return reply.ReadBool(); } -bool AccessibleAbilityManagerServiceProxy::EnableAbility(const std::string &name, const uint32_t capabilities) +RetError AccessibleAbilityManagerServiceProxy::EnableAbility(const std::string &name, const uint32_t capabilities) { HILOG_DEBUG(); MessageParcel data; @@ -425,28 +428,28 @@ bool AccessibleAbilityManagerServiceProxy::EnableAbility(const std::string &name if (!WriteInterfaceToken(data)) { HILOG_ERROR("fail, connection write Token"); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteString(name)) { HILOG_ERROR("name write error: %{public}s, ", name.c_str()); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteUint32(capabilities)) { HILOG_ERROR("capabilities write error: %{public}d, ", capabilities); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityManagerService::Message::ENABLE_ABILITIES, data, reply, option)) { HILOG_ERROR("EnableAbility fail"); - return false; + return RET_ERR_IPC_FAILED; } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } -bool AccessibleAbilityManagerServiceProxy::GetEnabledAbilities(std::vector &enabledAbilities) +RetError AccessibleAbilityManagerServiceProxy::GetEnabledAbilities(std::vector &enabledAbilities) { HILOG_DEBUG(); MessageParcel data; @@ -455,22 +458,22 @@ bool AccessibleAbilityManagerServiceProxy::GetEnabledAbilities(std::vector(reply.ReadInt32()); } -bool AccessibleAbilityManagerServiceProxy::DisableAbility(const std::string &name) +RetError AccessibleAbilityManagerServiceProxy::DisableAbility(const std::string &name) { HILOG_DEBUG(); MessageParcel data; @@ -479,19 +482,19 @@ bool AccessibleAbilityManagerServiceProxy::DisableAbility(const std::string &nam if (!WriteInterfaceToken(data)) { HILOG_ERROR("fail, connection write Token"); - return false; + return RET_ERR_IPC_FAILED; } if (!data.WriteString(name)) { HILOG_ERROR("name write error: %{public}s, ", name.c_str()); - return false; + return RET_ERR_IPC_FAILED; } if (!SendTransactCmd(IAccessibleAbilityManagerService::Message::DISABLE_ABILITIES, data, reply, option)) { HILOG_ERROR("DisableAbility fail"); - return false; + return RET_ERR_IPC_FAILED; } - return reply.ReadBool(); + return static_cast(reply.ReadInt32()); } int32_t AccessibleAbilityManagerServiceProxy::GetActiveWindow() @@ -541,7 +544,7 @@ RetError AccessibleAbilityManagerServiceProxy::EnableUITestAbility(const sptr(reply.ReadInt32()); } RetError AccessibleAbilityManagerServiceProxy::SetScreenMagnificationState(const bool state) diff --git a/common/interface/src/accessible_ability_manager_service_stub.cpp b/common/interface/src/accessible_ability_manager_service_stub.cpp index f431e2e63..8d111ad8c 100644 --- a/common/interface/src/accessible_ability_manager_service_stub.cpp +++ b/common/interface/src/accessible_ability_manager_service_stub.cpp @@ -224,7 +224,7 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetAbilityList(MessageParcel uint32_t abilityTypes = data.ReadUint32(); int32_t stateType = data.ReadInt32(); std::vector abilityInfos {}; - bool result = GetAbilityList(abilityTypes, stateType, abilityInfos); + RetError result = GetAbilityList(abilityTypes, stateType, abilityInfos); int32_t abilityInfoSize = static_cast(abilityInfos.size()); reply.WriteInt32(abilityInfoSize); @@ -239,7 +239,7 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetAbilityList(MessageParcel return TRANSACTION_ERR; } } - reply.WriteBool(result); + reply.WriteInt32(static_cast(result)); return NO_ERROR; } @@ -285,9 +285,15 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetCaptionProperty(MessagePar ErrCode AccessibleAbilityManagerServiceStub::HandleSetCaptionProperty(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); + if (!CheckPermission(OHOS_PERMISSION_WRITE_ACCESSIBILITY_CONFIG)) { + HILOG_WARN("Permission denied!"); + reply.WriteInt32(RET_ERR_NO_PERMISSION); + return NO_ERROR; + } sptr caption = data.ReadStrongParcelable(); if (!caption) { - HILOG_DEBUG("ReadStrongParcelable failed"); + HILOG_ERROR("ReadStrongParcelable failed"); + reply.WriteInt32(RET_ERR_IPC_FAILED); return TRANSACTION_ERR; } reply.WriteInt32(SetCaptionProperty(*caption)); @@ -298,6 +304,11 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleSetCaptionProperty(MessagePar ErrCode AccessibleAbilityManagerServiceStub::HandleSetCaptionState(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); + if (!CheckPermission(OHOS_PERMISSION_WRITE_ACCESSIBILITY_CONFIG)) { + HILOG_WARN("Permission denied!"); + reply.WriteInt32(RET_ERR_NO_PERMISSION); + return NO_ERROR; + } bool state = data.ReadBool(); reply.WriteInt32(SetCaptionState(state)); @@ -372,10 +383,15 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetKeyEventObserverState( ErrCode AccessibleAbilityManagerServiceStub::HandleEnableAbility(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); + if (!CheckPermission(OHOS_PERMISSION_WRITE_ACCESSIBILITY_CONFIG)) { + HILOG_WARN("Permission denied!"); + reply.WriteInt32(RET_ERR_NO_PERMISSION); + return NO_ERROR; + } std::string name = data.ReadString(); uint32_t capabilities = data.ReadUint32(); - bool result = EnableAbility(name, capabilities); - reply.WriteBool(result); + RetError result = EnableAbility(name, capabilities); + reply.WriteInt32(result); return NO_ERROR; } @@ -384,7 +400,7 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetEnabledAbilities(MessagePa HILOG_DEBUG(); std::vector enabledAbilities; - bool result = GetEnabledAbilities(enabledAbilities); + RetError result = GetEnabledAbilities(enabledAbilities); reply.WriteInt32(enabledAbilities.size()); for (auto &ability : enabledAbilities) { if (!reply.WriteString(ability)) { @@ -392,16 +408,21 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetEnabledAbilities(MessagePa return TRANSACTION_ERR; } } - reply.WriteBool(result); + reply.WriteInt32(result); return NO_ERROR; } ErrCode AccessibleAbilityManagerServiceStub::HandleDisableAbility(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); + if (!CheckPermission(OHOS_PERMISSION_WRITE_ACCESSIBILITY_CONFIG)) { + HILOG_WARN("Permission denied!"); + reply.WriteInt32(RET_ERR_NO_PERMISSION); + return NO_ERROR; + } std::string name = data.ReadString(); - bool result = DisableAbility(name); - reply.WriteBool(result); + RetError result = DisableAbility(name); + reply.WriteInt32(result); return NO_ERROR; } @@ -432,8 +453,8 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleDisableUITestAbility( MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - bool result = DisableUITestAbility(); - if (!reply.WriteBool(result)) { + int32_t result = DisableUITestAbility(); + if (!reply.WriteInt32(result)) { HILOG_ERROR("WriteBool failed"); return TRANSACTION_ERR; } @@ -642,11 +663,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetScreenMagnificationState( MessageParcel& data, MessageParcel& reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } bool result = false; RetError ret = GetScreenMagnificationState(result); reply.WriteInt32(ret); @@ -659,11 +675,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetScreenMagnificationState( ErrCode AccessibleAbilityManagerServiceStub::HandleGetShortKeyState(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } bool result = false; RetError ret = GetShortKeyState(result); reply.WriteInt32(ret); @@ -676,11 +687,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetShortKeyState(MessageParce ErrCode AccessibleAbilityManagerServiceStub::HandleGetMouseKeyState(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } bool result = false; RetError ret = GetMouseKeyState(result); reply.WriteInt32(ret); @@ -693,11 +699,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetMouseKeyState(MessageParce ErrCode AccessibleAbilityManagerServiceStub::HandleGetShortkeyTarget(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } std::string result = ""; RetError ret = GetShortkeyTarget(result); reply.WriteInt32(ret); @@ -710,11 +711,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetShortkeyTarget(MessageParc ErrCode AccessibleAbilityManagerServiceStub::HandleGetMouseAutoClick(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } int32_t result = 0; RetError ret = GetMouseAutoClick(result); reply.WriteInt32(ret); @@ -727,11 +723,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetMouseAutoClick(MessageParc ErrCode AccessibleAbilityManagerServiceStub::HandleGetInvertColorState(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } bool result = false; RetError ret = GetInvertColorState(result); reply.WriteInt32(ret); @@ -744,11 +735,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetInvertColorState(MessagePa ErrCode AccessibleAbilityManagerServiceStub::HandleGetHighContrastTextState(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } bool result = false; RetError ret = GetHighContrastTextState(result); reply.WriteInt32(ret); @@ -761,11 +747,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetHighContrastTextState(Mess ErrCode AccessibleAbilityManagerServiceStub::HandleGetAudioMonoState(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } bool result = false; RetError ret = GetAudioMonoState(result); reply.WriteInt32(ret); @@ -778,11 +759,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetAudioMonoState(MessageParc ErrCode AccessibleAbilityManagerServiceStub::HandleGetAnimationOffState(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } bool result = false; RetError ret = GetAnimationOffState(result); reply.WriteInt32(ret); @@ -796,11 +772,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetDaltonizationColorFilter( MessageParcel& data, MessageParcel& reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } uint32_t result = 0; RetError ret = GetDaltonizationColorFilter(result); reply.WriteInt32(ret); @@ -813,11 +784,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetDaltonizationColorFilter( ErrCode AccessibleAbilityManagerServiceStub::HandleGetContentTimeout(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } uint32_t result = 0; RetError ret = GetContentTimeout(result); reply.WriteInt32(ret); @@ -830,11 +796,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetContentTimeout(MessageParc ErrCode AccessibleAbilityManagerServiceStub::HandleGetBrightnessDiscount(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } float result = 0; RetError ret = GetBrightnessDiscount(result); reply.WriteInt32(ret); @@ -847,11 +808,6 @@ ErrCode AccessibleAbilityManagerServiceStub::HandleGetBrightnessDiscount(Message ErrCode AccessibleAbilityManagerServiceStub::HandleGetAudioBalance(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); - if (!CheckPermission(OHOS_PERMISSION_READ_ACCESSIBILITY_CONFIG)) { - HILOG_WARN("Permission denied!"); - reply.WriteInt32(RET_ERR_NO_PERMISSION); - return NO_ERROR; - } float result = 0; RetError ret = GetAudioBalance(result); reply.WriteInt32(ret); diff --git a/frameworks/aafwk/include/accessibility_ui_test_ability_impl.h b/frameworks/aafwk/include/accessibility_ui_test_ability_impl.h index f407c8c37..a387c2976 100644 --- a/frameworks/aafwk/include/accessibility_ui_test_ability_impl.h +++ b/frameworks/aafwk/include/accessibility_ui_test_ability_impl.h @@ -36,94 +36,96 @@ public: /** * @brief Register ability listener. * @param listener The listener to add. - * @return Return true if registers listener successfully, else return false. + * @return Return RET_OK if registers listener successfully, otherwise refer to the RetError for the failure. */ - virtual bool RegisterAbilityListener(const std::shared_ptr &listener) override; + virtual RetError RegisterAbilityListener(const std::shared_ptr &listener) override; /** * @brief Connect to AAMS. For UI test. - * @return Return RET_OK if the command of connection is sent successfully. + * @return Return RET_OK if the command of connection is sent successfully, + * otherwise refer to the RetError for the failure. */ virtual RetError Connect() override; /** * @brief disconnect to AAMS. For UI test. - * @return Return true if the command of disconnect is sent successfully, else return false. + * @return Return RET_OK if the command of disconnect is sent successfully, + * otherwise refer to the RetError for the failure. */ - virtual bool Disconnect() override; + virtual RetError Disconnect() override; /** * @brief Obtains elementInfo of focus. * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. * @param elementInfo The accessibilityElementInfo of focus. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) override; + virtual RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) override; /** * @brief Obtains elementInfo of focus. * @param sourceInfo The source info to get focus. * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. * @param elementInfo The accessibilityElementInfo of focus. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, + virtual RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo) override; /** * @brief Sends simulate gestures to the screen. * @param gesturePath The gesture which need to send. - * @return Return true if the gesture sends successfully, else return false. + * @return Return RET_OK if the gesture sends successfully, otherwise refer to the RetError for the failure. */ - virtual bool InjectGesture(const std::shared_ptr& gesturePath) override; + virtual RetError InjectGesture(const std::shared_ptr& gesturePath) override; /** * @brief Obtains elementInfo of the accessible root node. * @param elementInfo The elementInfo of the accessible root node. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetRoot(AccessibilityElementInfo &elementInfo) override; + virtual RetError GetRoot(AccessibilityElementInfo &elementInfo) override; /** * @brief Obtains elementInfo of the accessible root node. * @param windowInfo The source window info to get root. * @param elementInfo The elementInfo of the accessible root node. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetRootByWindow(const AccessibilityWindowInfo &windowInfo, + virtual RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo) override; /** * @brief Get the window information related with the event * @param windowId The window id. * @param windowInfo The window information. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; + virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindows(std::vector &windows) override; + virtual RetError GetWindows(std::vector &windows) override; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param displayId the id of display * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindows(const uint64_t displayId, std::vector &windows) override; + virtual RetError GetWindows(const uint64_t displayId, std::vector &windows) override; /** * @brief Gets the next focused node in the specified direction of the currently focused node. * @param elementInfo The source info to get next info. * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection * @param nextElementInfo The info of next element. - * @return Return true if gets next elementInfo successfully, else return false. + * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, + virtual RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo) override; /** @@ -131,18 +133,18 @@ public: * @param index The index of the child. * @param parent The parent info to get child. * @param child The element info of child. - * @return Return true if gets child elementInfo successfully, else return false. + * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, + virtual RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, AccessibilityElementInfo &child) override; /** * @brief Get the child node information * @param parent The parent info to get child. * @param children The element info of children. - * @return Return true if gets child elementInfo successfully, else return false. + * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetChildren(const AccessibilityElementInfo &parent, + virtual RetError GetChildren(const AccessibilityElementInfo &parent, std::vector &children) override; /** @@ -150,26 +152,27 @@ public: * @param elementInfo The source info. * @param text specified content * @param elementInfos The element infos of specified content. - * @return Return true if gets elementInfos successfully, else return false. + * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, + virtual RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, std::vector &elementInfos) override; /** * @brief Get the node information related with the event * @param eventInfo The source info to get source. * @param elementInfo The element info of source. - * @return Return true if gets elementInfos successfully, else return false. + * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) override; + virtual RetError GetSource(const AccessibilityEventInfo &eventInfo, + AccessibilityElementInfo &elementInfo) override; /** * @brief Get Parent node information * @param child The child element info to get parent. * @param parent The parent element info. - * @return Return true if gets info successfully, else return false. + * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetParentElementInfo(const AccessibilityElementInfo &child, + virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) override; /** @@ -190,17 +193,17 @@ public: * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) * action: ACCESSIBILITY_ACTION_SET_TEXT, * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") - * @return true Perform action succeed, otherwise is not. + * @return Return RET_OK if performs action succeed, otherwise refer to the RetError for the failure. */ - virtual bool ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, + virtual RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, const std::map &actionArguments) override; /** * @brief Set target bundle names. * @param targetBundleNames The target bundle name - * @return Return true if sets target bundle names successfully, else return false. + * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. */ - virtual bool SetTargetBundleName(const std::vector &targetBundleNames) override; + virtual RetError SetTargetBundleName(const std::vector &targetBundleNames) override; /** * @brief Set cache mode. @@ -211,12 +214,13 @@ public: * PREFETCH_SIBLINGS: cache the sister/brothers node info also. * PREFETCH_CHILDREN: cache the child node info also. * otherwise: no cache. + * @return Return RET_OK if sets cache mode successfully, otherwise refer to the RetError for the failure. */ - virtual void SetCacheMode(const int32_t cacheMode) override; + virtual RetError SetCacheMode(const int32_t cacheMode) override; private: sptr serviceProxy_ = nullptr; }; } // namespace Accessibility } // namespace OHOS -#endif // ACCESSIBILITY_UI_TEST_ABILITY_IMPL_H +#endif // ACCESSIBILITY_UI_TEST_ABILITY_IMPL_H \ No newline at end of file diff --git a/frameworks/aafwk/include/accessible_ability_channel_client.h b/frameworks/aafwk/include/accessible_ability_channel_client.h index ad5dfe105..4b280ea68 100644 --- a/frameworks/aafwk/include/accessible_ability_channel_client.h +++ b/frameworks/aafwk/include/accessible_ability_channel_client.h @@ -57,17 +57,17 @@ public: * FOCUS_TYPE_ACCESSIBILITY: accessibility focus * FOCUS_TYPE_INPUT: text input focus * @param elementInfo[out] The components information matched conditions searched. - * @return Return true if finds focus element info successfully, else return false. + * @return Return RET_OK if finds focus element info successfully, otherwise refer to the RetError for the failure. */ - bool FindFocusedElementInfo(int32_t accessibilityWindowId, int32_t elementId, + RetError FindFocusedElementInfo(int32_t accessibilityWindowId, int32_t elementId, int32_t focusType, AccessibilityElementInfo &elementInfo); /** * @brief Send simulate gesture to aams. * @param gesturePath The path of gesture. - * @return Return true if gesture injection is successfully, otherwise return false. + * @return Return RET_OK if gesture injection is successfully, otherwise refer to the RetError for the failure. */ - bool SendSimulateGesture(const std::shared_ptr &gesturePath); + RetError SendSimulateGesture(const std::shared_ptr &gesturePath); /** * @brief execute the action on the component. @@ -89,9 +89,9 @@ public: * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) * action: ACCESSIBILITY_ACTION_SET_TEXT, * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") - * @return true: execute action successfully; otherwise is not. + * @return RET_OK: execute action successfully; otherwise refer to the RetError for the failure. */ - bool ExecuteAction(int32_t accessibilityWindowId, + RetError ExecuteAction(int32_t accessibilityWindowId, int32_t elementId, int32_t action, const std::map &actionArguments); /** @@ -103,33 +103,33 @@ public: * PREFETCH_CHILDREN: Need to make the child node info also. * otherwise: Make the node information by elementId only. * @param elementInfos[out] The components information matched conditions searched. - * @return Return true if search element info successfully, else return false. + * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure. */ - bool SearchElementInfosByAccessibilityId(int32_t accessibilityWindowId, int32_t elementId, + RetError SearchElementInfosByAccessibilityId(int32_t accessibilityWindowId, int32_t elementId, int32_t mode, std::vector &elementInfos); /** * @brief Get the window information related with the event * @param windowId The window id. * @param windowInfo The window information. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo); + RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo); /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetWindows(std::vector &windows); + RetError GetWindows(std::vector &windows); /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param displayId the id of display * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetWindows(const uint64_t displayId, std::vector &windows) const; + RetError GetWindows(const uint64_t displayId, std::vector &windows) const; /** * @brief Find the node information filtered by text. @@ -137,9 +137,9 @@ public: * @param elementId: The unique id of the component ID. * @param text The filter text. * @param elementInfos[out] The components information matched conditions searched. - * @return Return true if search element info successfully, else return false. + * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure. */ - bool SearchElementInfosByText(int32_t accessibilityWindowId, int32_t elementId, + RetError SearchElementInfosByText(int32_t accessibilityWindowId, int32_t elementId, const std::string &text, std::vector &elementInfos); /** @@ -149,17 +149,17 @@ public: * @param direction The direction of focus move direction. * Refer to FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD). * @param elementInfo[out] The components information matched conditions searched. - * @return Return true if find element info successfully, else return false. + * @return Return RET_OK if find element info successfully, otherwise refer to the RetError for the failure. */ - bool FocusMoveSearch(int32_t accessibilityWindowId, + RetError FocusMoveSearch(int32_t accessibilityWindowId, int32_t elementId, int32_t direction, AccessibilityElementInfo &elementInfo); /** * @brief Set target bundle names. * @param targetBundleNames The target bundle name - * @return Return true if sets target bundle names successfully, else return false. + * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. */ - bool SetTargetBundleName(const std::vector &targetBundleNames); + RetError SetTargetBundleName(const std::vector &targetBundleNames); private: int32_t GenerateRequestId(); diff --git a/frameworks/aafwk/include/accessible_ability_client_impl.h b/frameworks/aafwk/include/accessible_ability_client_impl.h index 14329bd02..2281e622a 100644 --- a/frameworks/aafwk/include/accessible_ability_client_impl.h +++ b/frameworks/aafwk/include/accessible_ability_client_impl.h @@ -46,9 +46,9 @@ public: /** * @brief Register ability listener. * @param listener The listener to add. - * @return Return true if registers listener successfully, else return false. + * @return Return RET_OK if registers listener successfully, otherwise refer to the RetError for the failure. */ - virtual bool RegisterAbilityListener(const std::shared_ptr &listener) override; + virtual RetError RegisterAbilityListener(const std::shared_ptr &listener) override; /** * @brief Init accessible ability. @@ -80,74 +80,74 @@ public: * @brief Obtains elementInfo of focus. * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. * @param elementInfo The accessibilityElementInfo of focus. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) override; + virtual RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) override; /** * @brief Obtains elementInfo of focus. * @param sourceInfo The source info to get focus. * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. * @param elementInfo The accessibilityElementInfo of focus. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, + virtual RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo) override; /** * @brief Sends simulate gestures to the screen. * @param gesturePath The gesture which need to send. - * @return Return true if the gesture sends successfully, else return false. + * @return Return RET_OK if the gesture sends successfully, otherwise refer to the RetError for the failure. */ - virtual bool InjectGesture(const std::shared_ptr &gesturePath) override; + virtual RetError InjectGesture(const std::shared_ptr &gesturePath) override; /** * @brief Obtains elementInfo of the accessible root node. * @param elementInfo The elementInfo of the accessible root node. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetRoot(AccessibilityElementInfo &elementInfo) override; + virtual RetError GetRoot(AccessibilityElementInfo &elementInfo) override; /** * @brief Obtains elementInfo of the accessible root node. * @param windowInfo The source window info to get root. * @param elementInfo The elementInfo of the accessible root node. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetRootByWindow(const AccessibilityWindowInfo &windowInfo, + virtual RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo) override; /** * @brief Get the window information related with the event * @param windowId The window id. * @param windowInfo The window information. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; + virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindows(std::vector &windows) override; + virtual RetError GetWindows(std::vector &windows) override; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param displayId the id of display * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindows(const uint64_t displayId, std::vector &windows) override; + virtual RetError GetWindows(const uint64_t displayId, std::vector &windows) override; /** * @brief Gets the next focused node in the specified direction of the currently focused node. * @param elementInfo The source info to get next info. * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection * @param nextElementInfo The info of next element. - * @return Return true if gets next elementInfo successfully, else return false. + * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, + virtual RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo) override; /** @@ -155,18 +155,18 @@ public: * @param index The index of the child. * @param parent The parent info to get child. * @param child The element info of child. - * @return Return true if gets child elementInfo successfully, else return false. + * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, + virtual RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, AccessibilityElementInfo &child) override; /** * @brief Get the child node information * @param parent The parent info to get child. * @param children The element info of children. - * @return Return true if gets child elementInfo successfully, else return false. + * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetChildren(const AccessibilityElementInfo &parent, + virtual RetError GetChildren(const AccessibilityElementInfo &parent, std::vector &children) override; /** @@ -174,26 +174,28 @@ public: * @param elementInfo The source info. * @param text specified content * @param elementInfos The element infos of specified content. - * @return Return true if gets elementInfos successfully, else return false. + * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, + virtual RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, std::vector &elementInfos) override; /** * @brief Get the node information related with the event * @param eventInfo The source info to get source. * @param elementInfo The element info of source. - * @return Return true if gets elementInfos successfully, else return false. + * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) override; + virtual RetError GetSource(const AccessibilityEventInfo &eventInfo, + AccessibilityElementInfo &elementInfo) override; /** * @brief Get Parent node information * @param child The child element info to get parent. * @param parent The parent element info. - * @return Return true if gets info successfully, else return false. + * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) override; + virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child, + AccessibilityElementInfo &parent) override; /** * @brief Executes a specified action. @@ -213,17 +215,17 @@ public: * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) * action: ACCESSIBILITY_ACTION_SET_TEXT, * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") - * @return true Perform action succeed, otherwise is not. + * @return Return RET_OK if performs action succeed, otherwise refer to the RetError for the failure. */ - virtual bool ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, + virtual RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, const std::map &actionArguments) override; /** * @brief Set target bundle names. * @param targetBundleNames The target bundle name - * @return Return true if sets target bundle names successfully, else return false. + * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. */ - virtual bool SetTargetBundleName(const std::vector &targetBundleNames) override; + virtual RetError SetTargetBundleName(const std::vector &targetBundleNames) override; /** * @brief Set cache mode. @@ -234,8 +236,9 @@ public: * PREFETCH_SIBLINGS: cache the sister/brothers node info also. * PREFETCH_CHILDREN: cache the child node info also. * otherwise: no cache. + * @return Return RET_OK if sets cache mode successfully, otherwise refer to the RetError for the failure. */ - virtual void SetCacheMode(const int32_t cacheMode) override; + virtual RetError SetCacheMode(const int32_t cacheMode) override; /** * @brief Clean data. @@ -276,7 +279,7 @@ private: const int32_t elementId, AccessibilityElementInfo &elementInfo) const; void SetCacheElementInfo(const int32_t windowId, const std::vector &elementInfos); - bool SearchElementInfoFromAce(const int32_t windowId, const int32_t elementId, + RetError SearchElementInfoFromAce(const int32_t windowId, const int32_t elementId, const uint32_t mode, AccessibilityElementInfo &info); sptr deathRecipient_ = nullptr; @@ -291,4 +294,4 @@ private: }; } // namespace Accessibility } // namespace OHOS -#endif // ACCESSIBLE_ABILITY_CLIENT_IMPL_H +#endif // ACCESSIBLE_ABILITY_CLIENT_IMPL_H \ No newline at end of file diff --git a/frameworks/aafwk/src/accessibility_ui_test_ability_impl.cpp b/frameworks/aafwk/src/accessibility_ui_test_ability_impl.cpp index 48484a293..b0de427ea 100644 --- a/frameworks/aafwk/src/accessibility_ui_test_ability_impl.cpp +++ b/frameworks/aafwk/src/accessibility_ui_test_ability_impl.cpp @@ -59,18 +59,19 @@ AccessibilityUITestAbilityImpl::AccessibilityUITestAbilityImpl() } } -bool AccessibilityUITestAbilityImpl::RegisterAbilityListener(const std::shared_ptr &listener) +RetError AccessibilityUITestAbilityImpl::RegisterAbilityListener( + const std::shared_ptr &listener) { HILOG_DEBUG(); if (!listener) { HILOG_ERROR("listener is nullptr."); - return false; + return RET_ERR_INVALID_PARAM; } sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->RegisterAbilityListener(listener); } @@ -92,199 +93,200 @@ RetError AccessibilityUITestAbilityImpl::Connect() return serviceProxy_->EnableUITestAbility(aaClient->GetRemoteObject()); } -bool AccessibilityUITestAbilityImpl::Disconnect() +RetError AccessibilityUITestAbilityImpl::Disconnect() { HILOG_INFO(); if (!serviceProxy_) { HILOG_ERROR("Failed to get aams service"); - return false; + return RET_ERR_SAMGR; } return serviceProxy_->DisableUITestAbility(); } -bool AccessibilityUITestAbilityImpl::GetFocus( +RetError AccessibilityUITestAbilityImpl::GetFocus( const int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetFocus(focusType, elementInfo); } -bool AccessibilityUITestAbilityImpl::GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, +RetError AccessibilityUITestAbilityImpl::GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetFocusByElementInfo(sourceInfo, focusType, elementInfo); } -bool AccessibilityUITestAbilityImpl::InjectGesture(const std::shared_ptr &gesturePath) +RetError AccessibilityUITestAbilityImpl::InjectGesture( + const std::shared_ptr &gesturePath) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->InjectGesture(gesturePath); } -bool AccessibilityUITestAbilityImpl::GetRoot(AccessibilityElementInfo &elementInfo) +RetError AccessibilityUITestAbilityImpl::GetRoot(AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetRoot(elementInfo); } -bool AccessibilityUITestAbilityImpl::GetRootByWindow(const AccessibilityWindowInfo &windowInfo, +RetError AccessibilityUITestAbilityImpl::GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetRootByWindow(windowInfo, elementInfo); } -bool AccessibilityUITestAbilityImpl::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) +RetError AccessibilityUITestAbilityImpl::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetWindow(windowId, windowInfo); } -bool AccessibilityUITestAbilityImpl::GetWindows(std::vector &windows) +RetError AccessibilityUITestAbilityImpl::GetWindows(std::vector &windows) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetWindows(windows); } -bool AccessibilityUITestAbilityImpl::GetWindows(const uint64_t displayId, +RetError AccessibilityUITestAbilityImpl::GetWindows(const uint64_t displayId, std::vector &windows) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetWindows(displayId, windows); } -bool AccessibilityUITestAbilityImpl::GetNext(const AccessibilityElementInfo &elementInfo, +RetError AccessibilityUITestAbilityImpl::GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetNext(elementInfo, direction, nextElementInfo); } -bool AccessibilityUITestAbilityImpl::GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, - AccessibilityElementInfo &child) +RetError AccessibilityUITestAbilityImpl::GetChildElementInfo(const int32_t index, + const AccessibilityElementInfo &parent, AccessibilityElementInfo &child) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetChildElementInfo(index, parent, child); } -bool AccessibilityUITestAbilityImpl::GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, - std::vector &elementInfos) +RetError AccessibilityUITestAbilityImpl::GetByContent(const AccessibilityElementInfo &elementInfo, + const std::string &text, std::vector &elementInfos) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetByContent(elementInfo, text, elementInfos); } -bool AccessibilityUITestAbilityImpl::GetSource(const AccessibilityEventInfo &eventInfo, +RetError AccessibilityUITestAbilityImpl::GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetSource(eventInfo, elementInfo); } -bool AccessibilityUITestAbilityImpl::GetParentElementInfo(const AccessibilityElementInfo &child, +RetError AccessibilityUITestAbilityImpl::GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetParentElementInfo(child, parent); } -bool AccessibilityUITestAbilityImpl::ExecuteAction(const AccessibilityElementInfo &elementInfo, +RetError AccessibilityUITestAbilityImpl::ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, const std::map &actionArguments) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->ExecuteAction(elementInfo, action, actionArguments); } -bool AccessibilityUITestAbilityImpl::SetTargetBundleName(const std::vector &targetBundleNames) +RetError AccessibilityUITestAbilityImpl::SetTargetBundleName(const std::vector &targetBundleNames) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->SetTargetBundleName(targetBundleNames); } -bool AccessibilityUITestAbilityImpl::GetChildren(const AccessibilityElementInfo &parent, +RetError AccessibilityUITestAbilityImpl::GetChildren(const AccessibilityElementInfo &parent, std::vector &children) { HILOG_DEBUG(); return AccessibleAbilityClient::GetInstance()->GetChildren(parent, children); } -void AccessibilityUITestAbilityImpl::SetCacheMode(const int32_t cacheMode) +RetError AccessibilityUITestAbilityImpl::SetCacheMode(const int32_t cacheMode) { HILOG_DEBUG(); return AccessibleAbilityClient::GetInstance()->SetCacheMode(cacheMode); diff --git a/frameworks/aafwk/src/accessible_ability_channel_client.cpp b/frameworks/aafwk/src/accessible_ability_channel_client.cpp index 6f1bc861f..07422976c 100644 --- a/frameworks/aafwk/src/accessible_ability_channel_client.cpp +++ b/frameworks/aafwk/src/accessible_ability_channel_client.cpp @@ -51,14 +51,14 @@ void AccessibleAbilityChannelClient::SetOnKeyPressEventResult(const bool handled } } -bool AccessibleAbilityChannelClient::FindFocusedElementInfo(int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelClient::FindFocusedElementInfo(int32_t accessibilityWindowId, int32_t elementId, int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG("[channelId:%{public}d]", channelId_); HITRACE_METER_NAME(HITRACE_TAG_ACCESSIBILITY_MANAGER, "FindFocusedElement"); if (!proxy_) { HILOG_ERROR("Failed to connect to aams [channelId:%{public}d]", channelId_); - return false; + return RET_ERR_SAMGR; } int32_t requestId = GenerateRequestId(); @@ -66,12 +66,15 @@ bool AccessibleAbilityChannelClient::FindFocusedElementInfo(int32_t accessibilit new(std::nothrow) AccessibilityElementOperatorCallbackImpl(); if (!elementOperator) { HILOG_ERROR("Failed to create elementOperator."); - return false; + return RET_ERR_NULLPTR; } std::future promiseFuture = elementOperator->promise_.get_future(); - if (!proxy_->FindFocusedElementInfo(accessibilityWindowId, elementId, focusType, requestId, elementOperator)) { - return false; + RetError ret = proxy_->FindFocusedElementInfo(accessibilityWindowId, + elementId, focusType, requestId, elementOperator); + if (ret != RET_OK) { + HILOG_ERROR("FindFocusedElementInfo failed. ret[%{public}d]", ret); + return ret; } HILOG_DEBUG("channelId:%{public}d, accessibilityWindowId:%{public}d, elementId:%{public}d, focusType:%{public}d", channelId_, accessibilityWindowId, elementId, focusType); @@ -79,21 +82,21 @@ bool AccessibleAbilityChannelClient::FindFocusedElementInfo(int32_t accessibilit std::future_status wait = promiseFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); if (wait != std::future_status::ready) { HILOG_ERROR("Failed to wait result"); - return false; + return RET_ERR_TIME_OUT; } if (elementOperator->accessibilityInfoResult_.GetAccessibilityId() == AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID) { HILOG_ERROR("The elementInfo from ace is wrong"); - return false; + return RET_ERR_INVALID_ELEMENT_INFO_FROM_ACE; } HILOG_INFO("Get result successfully from ace."); elementInfo = elementOperator->accessibilityInfoResult_; - return true; + return RET_OK; } -bool AccessibleAbilityChannelClient::SendSimulateGesture( +RetError AccessibleAbilityChannelClient::SendSimulateGesture( const std::shared_ptr &gesturePath) { HILOG_INFO("[channelId:%{public}d]", channelId_); @@ -101,18 +104,18 @@ bool AccessibleAbilityChannelClient::SendSimulateGesture( return proxy_->SendSimulateGesture(gesturePath); } else { HILOG_ERROR("Failed to connect to aams [channelId:%{public}d]", channelId_); - return false; + return RET_ERR_SAMGR; } } -bool AccessibleAbilityChannelClient::ExecuteAction(int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelClient::ExecuteAction(int32_t accessibilityWindowId, int32_t elementId, int32_t action, const std::map &actionArguments) { HILOG_DEBUG("[channelId:%{public}d]", channelId_); HITRACE_METER_NAME(HITRACE_TAG_ACCESSIBILITY_MANAGER, "ExecuteAction"); if (!proxy_) { HILOG_ERROR("Failed to connect to aams [channelId:%{public}d]", channelId_); - return false; + return RET_ERR_SAMGR; } int32_t requestId = GenerateRequestId(); @@ -120,32 +123,35 @@ bool AccessibleAbilityChannelClient::ExecuteAction(int32_t accessibilityWindowId new(std::nothrow) AccessibilityElementOperatorCallbackImpl(); if (!elementOperator) { HILOG_ERROR("Failed to create elementOperator."); - return false; + return RET_ERR_NULLPTR; } std::future promiseFuture = elementOperator->promise_.get_future(); - if (!proxy_->ExecuteAction(accessibilityWindowId, elementId, action, actionArguments, requestId, elementOperator)) { - return false; + RetError ret = proxy_->ExecuteAction(accessibilityWindowId, + elementId, action, actionArguments, requestId, elementOperator); + if (ret != RET_OK) { + HILOG_ERROR("ExecuteAction failed. ret[%{public}d]", ret); + return ret; } std::future_status wait = promiseFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); if (wait != std::future_status::ready) { HILOG_ERROR("Failed to wait result"); - return false; + return RET_ERR_TIME_OUT; } HILOG_INFO("Get result successfully from ace. executeActionResult_[%{public}d]", elementOperator->executeActionResult_); - return elementOperator->executeActionResult_; + return elementOperator->executeActionResult_ ? RET_OK : RET_ERR_PERFORM_ACTION_FAILED_BY_ACE; } -bool AccessibleAbilityChannelClient::SearchElementInfosByAccessibilityId(int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelClient::SearchElementInfosByAccessibilityId(int32_t accessibilityWindowId, int32_t elementId, int32_t mode, std::vector &elementInfos) { HILOG_DEBUG("[channelId:%{public}d] [windowId:%{public}d]", channelId_, accessibilityWindowId); HITRACE_METER_NAME(HITRACE_TAG_ACCESSIBILITY_MANAGER, "SearchElementById"); if (!proxy_) { HILOG_ERROR("Failed to connect to aams [channelId:%{public}d]", channelId_); - return false; + return RET_ERR_SAMGR; } int32_t requestId = GenerateRequestId(); @@ -153,44 +159,46 @@ bool AccessibleAbilityChannelClient::SearchElementInfosByAccessibilityId(int32_t new(std::nothrow) AccessibilityElementOperatorCallbackImpl(); if (!elementOperator) { HILOG_ERROR("Failed to create elementOperator."); - return false; + return RET_ERR_NULLPTR; } std::future promiseFuture = elementOperator->promise_.get_future(); - if (!proxy_->SearchElementInfoByAccessibilityId(accessibilityWindowId, elementId, requestId, - elementOperator, mode)) { - return false; + RetError ret = proxy_->SearchElementInfoByAccessibilityId(accessibilityWindowId, elementId, requestId, + elementOperator, mode); + if (ret != RET_OK) { + HILOG_ERROR("SearchElementInfosByAccessibilityId failed. ret[%{public}d]", ret); + return ret; } std::future_status wait = promiseFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); if (wait != std::future_status::ready) { HILOG_ERROR("Failed to wait result"); - return false; + return RET_ERR_TIME_OUT; } for (auto &info : elementOperator->elementInfosResult_) { if (info.GetAccessibilityId() == AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID) { HILOG_ERROR("The elementInfo from ace is wrong"); - return false; + return RET_ERR_INVALID_ELEMENT_INFO_FROM_ACE; } } HILOG_INFO("Get result successfully from ace. size[%{public}zu]", elementOperator->elementInfosResult_.size()); elementInfos = elementOperator->elementInfosResult_; - return true; + return RET_OK; } -bool AccessibleAbilityChannelClient::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) +RetError AccessibleAbilityChannelClient::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) { HILOG_DEBUG("[channelId:%{public}d] [windowId:%{public}d]", channelId_, windowId); HITRACE_METER(HITRACE_TAG_ACCESSIBILITY_MANAGER); if (!proxy_) { HILOG_ERROR("Failed to connect to aams [channelId:%{public}d]", channelId_); - return false; + return RET_ERR_SAMGR; } return proxy_->GetWindow(windowId, windowInfo); } -bool AccessibleAbilityChannelClient::GetWindows(std::vector &windows) +RetError AccessibleAbilityChannelClient::GetWindows(std::vector &windows) { HILOG_DEBUG("[channelId:%{public}d]", channelId_); HITRACE_METER(HITRACE_TAG_ACCESSIBILITY_MANAGER); @@ -198,11 +206,11 @@ bool AccessibleAbilityChannelClient::GetWindows(std::vectorGetWindows(windows); } else { HILOG_ERROR("Failed to connect to aams [channelId:%{public}d]", channelId_); - return false; + return RET_ERR_SAMGR; } } -bool AccessibleAbilityChannelClient::GetWindows(const uint64_t displayId, +RetError AccessibleAbilityChannelClient::GetWindows(const uint64_t displayId, std::vector &windows) const { HILOG_DEBUG("[channelId:%{public}d] [displayId:%{public}" PRIu64 "]", channelId_, displayId); @@ -211,18 +219,18 @@ bool AccessibleAbilityChannelClient::GetWindows(const uint64_t displayId, return proxy_->GetWindowsByDisplayId(displayId, windows); } else { HILOG_ERROR("Failed to connect to aams [channelId:%{public}d]", channelId_); - return false; + return RET_ERR_SAMGR; } } -bool AccessibleAbilityChannelClient::SearchElementInfosByText(int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelClient::SearchElementInfosByText(int32_t accessibilityWindowId, int32_t elementId, const std::string &text, std::vector &elementInfos) { HILOG_DEBUG("[channelId:%{public}d]", channelId_); HITRACE_METER_NAME(HITRACE_TAG_ACCESSIBILITY_MANAGER, "SearchElementByText"); if (!proxy_) { HILOG_ERROR("Failed to connect to aams [channelId:%{public}d]", channelId_); - return false; + return RET_ERR_SAMGR; } int32_t requestId = GenerateRequestId(); @@ -230,38 +238,41 @@ bool AccessibleAbilityChannelClient::SearchElementInfosByText(int32_t accessibil new(std::nothrow) AccessibilityElementOperatorCallbackImpl(); if (!elementOperator) { HILOG_ERROR("Failed to create elementOperator."); - return false; + return RET_ERR_NULLPTR; } std::future promiseFuture = elementOperator->promise_.get_future(); - if (!proxy_->SearchElementInfosByText(accessibilityWindowId, elementId, text, requestId, elementOperator)) { - return false; + RetError ret = proxy_->SearchElementInfosByText(accessibilityWindowId, + elementId, text, requestId, elementOperator); + if (ret != RET_OK) { + HILOG_ERROR("SearchElementInfosByText failed. ret[%{public}d]", ret); + return ret; } std::future_status wait = promiseFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); if (wait != std::future_status::ready) { HILOG_ERROR("Failed to wait result"); - return false; + return RET_ERR_TIME_OUT; } for (auto &info : elementOperator->elementInfosResult_) { if (info.GetAccessibilityId() == AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID) { HILOG_ERROR("The elementInfo from ace is wrong"); - return false; + return RET_ERR_INVALID_ELEMENT_INFO_FROM_ACE; } } HILOG_INFO("Get result successfully from ace. size[%{public}zu]", elementOperator->elementInfosResult_.size()); elementInfos = elementOperator->elementInfosResult_; - return true; + return RET_OK; } -bool AccessibleAbilityChannelClient::FocusMoveSearch(int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelClient::FocusMoveSearch(int32_t accessibilityWindowId, int32_t elementId, int32_t direction, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG("[channelId:%{public}d]", channelId_); if (!proxy_) { HILOG_ERROR("Failed to connect to aams [channelId:%{public}d]", channelId_); - return false; + return RET_ERR_SAMGR; } int32_t requestId = GenerateRequestId(); @@ -269,39 +280,41 @@ bool AccessibleAbilityChannelClient::FocusMoveSearch(int32_t accessibilityWindow new(std::nothrow) AccessibilityElementOperatorCallbackImpl(); if (!elementOperator) { HILOG_ERROR("Failed to create elementOperator."); - return false; + return RET_ERR_NULLPTR; } std::future promiseFuture = elementOperator->promise_.get_future(); - if (!proxy_->FocusMoveSearch(accessibilityWindowId, elementId, direction, requestId, elementOperator)) { - return false; + RetError ret = proxy_->FocusMoveSearch(accessibilityWindowId, elementId, direction, requestId, elementOperator); + if (ret != RET_OK) { + HILOG_ERROR("FocusMoveSearch failed. ret[%{public}d]", ret); + return ret; } std::future_status wait = promiseFuture.wait_for(std::chrono::milliseconds(TIME_OUT_OPERATOR)); if (wait != std::future_status::ready) { HILOG_ERROR("Failed to wait result"); - return false; + return RET_ERR_TIME_OUT; } if (elementOperator->accessibilityInfoResult_.GetAccessibilityId() == AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID) { HILOG_ERROR("The elementInfo from ace is wrong"); - return false; + return RET_ERR_INVALID_ELEMENT_INFO_FROM_ACE; } HILOG_INFO("Get result successfully from ace"); elementInfo = elementOperator->accessibilityInfoResult_; - return true; + return RET_OK; } -bool AccessibleAbilityChannelClient::SetTargetBundleName(const std::vector &targetBundleNames) +RetError AccessibleAbilityChannelClient::SetTargetBundleName(const std::vector &targetBundleNames) { HILOG_INFO("[channelId:%{public}d]", channelId_); if (proxy_) { return proxy_->SetTargetBundleName(targetBundleNames); } else { HILOG_ERROR("Failed to connect to aams [channelId:%{public}d]", channelId_); - return false; + return RET_ERR_SAMGR; } } } // namespace Accessibility diff --git a/frameworks/aafwk/src/accessible_ability_client_impl.cpp b/frameworks/aafwk/src/accessible_ability_client_impl.cpp index 47fbe40c6..f4b4229c5 100644 --- a/frameworks/aafwk/src/accessible_ability_client_impl.cpp +++ b/frameworks/aafwk/src/accessible_ability_client_impl.cpp @@ -103,17 +103,18 @@ sptr AccessibleAbilityClientImpl::GetRemoteObject() return g_Instance->AsObject(); } -bool AccessibleAbilityClientImpl::RegisterAbilityListener(const std::shared_ptr &listener) +RetError AccessibleAbilityClientImpl::RegisterAbilityListener( + const std::shared_ptr &listener) { HILOG_INFO(); std::lock_guard lock(mutex_); if (listener_) { HILOG_DEBUG("listener already exists."); - return false; + return RET_ERR_REGISTER_EXIST; } listener_ = listener; - return true; + return RET_OK; } void AccessibleAbilityClientImpl::Init(const sptr &channel, const int32_t channelId) @@ -219,36 +220,36 @@ void AccessibleAbilityClientImpl::OnKeyPressEvent(const MMI::KeyEvent &keyEvent, channel->SetOnKeyPressEventResult(handled, sequence); } -bool AccessibleAbilityClientImpl::GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) +RetError AccessibleAbilityClientImpl::GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_INFO("focusType[%{public}d]", focusType); std::lock_guard lock(mutex_); if ((focusType != FOCUS_TYPE_INPUT) && (focusType != FOCUS_TYPE_ACCESSIBILITY)) { HILOG_ERROR("focusType is not allowed."); - return false; + return RET_ERR_INVALID_PARAM; } if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } return channelClient_->FindFocusedElementInfo(ANY_WINDOW_ID, ROOT_NODE_ID, focusType, elementInfo); } -bool AccessibleAbilityClientImpl::GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, +RetError AccessibleAbilityClientImpl::GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_INFO("focusType[%{public}d]", focusType); std::lock_guard lock(mutex_); if ((focusType != FOCUS_TYPE_INPUT) && (focusType != FOCUS_TYPE_ACCESSIBILITY)) { HILOG_ERROR("focusType is not allowed."); - return false; + return RET_ERR_INVALID_PARAM; } if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } int32_t windowId = sourceInfo.GetWindowId(); @@ -258,112 +259,110 @@ bool AccessibleAbilityClientImpl::GetFocusByElementInfo(const AccessibilityEleme return channelClient_->FindFocusedElementInfo(windowId, elementId, focusType, elementInfo); } -bool AccessibleAbilityClientImpl::InjectGesture(const std::shared_ptr &gesturePath) +RetError AccessibleAbilityClientImpl::InjectGesture(const std::shared_ptr &gesturePath) { HILOG_INFO(); std::lock_guard lock(mutex_); if (!gesturePath) { HILOG_ERROR("The gesturePath is null."); - return false; + return RET_ERR_INVALID_PARAM; } std::vector positions = gesturePath->GetPositions(); if (positions.size() == 0) { HILOG_ERROR("The number of gesture path position is not allowed."); - return false; + return RET_ERR_INVALID_PARAM; } if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } return channelClient_->SendSimulateGesture(gesturePath); } -bool AccessibleAbilityClientImpl::GetRoot(AccessibilityElementInfo &elementInfo) +RetError AccessibleAbilityClientImpl::GetRoot(AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); std::lock_guard lock(mutex_); - if (!channelClient_ || !serviceProxy_) { + if (!serviceProxy_) { + HILOG_ERROR("Failed to connect to aams"); + return RET_ERR_SAMGR; + } + + if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } int32_t activeWindow = serviceProxy_->GetActiveWindow(); HILOG_INFO("activeWindow[%{public}d]", activeWindow); if (GetCacheElementInfo(activeWindow, ROOT_NONE_ID, elementInfo)) { HILOG_DEBUG("get element info from cache"); - return true; + return RET_OK; } - if (!SearchElementInfoFromAce(activeWindow, ROOT_NONE_ID, cacheMode_, elementInfo)) { - HILOG_ERROR("Get element info from ace failed"); - return false; - } - return true; + return SearchElementInfoFromAce(activeWindow, ROOT_NONE_ID, cacheMode_, elementInfo); } -bool AccessibleAbilityClientImpl::GetRootByWindow(const AccessibilityWindowInfo &windowInfo, +RetError AccessibleAbilityClientImpl::GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } int32_t windowId = windowInfo.GetWindowId(); HILOG_INFO("windowId[%{public}d]", windowId); if (GetCacheElementInfo(windowId, ROOT_NONE_ID, elementInfo)) { HILOG_DEBUG("get element info from cache"); - return true; + return RET_OK; } - if (!SearchElementInfoFromAce(windowId, ROOT_NONE_ID, cacheMode_, elementInfo)) { - HILOG_ERROR("Get element info from ace failed"); - return false; - } - return true; + return SearchElementInfoFromAce(windowId, ROOT_NONE_ID, cacheMode_, elementInfo); } -bool AccessibleAbilityClientImpl::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) +RetError AccessibleAbilityClientImpl::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) { HILOG_INFO("windowId[%{public}d]", windowId); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } return channelClient_->GetWindow(windowId, windowInfo); } -bool AccessibleAbilityClientImpl::GetWindows(std::vector &windows) +RetError AccessibleAbilityClientImpl::GetWindows(std::vector &windows) { HILOG_INFO(); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } return channelClient_->GetWindows(windows); } -bool AccessibleAbilityClientImpl::GetWindows(const uint64_t displayId, std::vector &windows) +RetError AccessibleAbilityClientImpl::GetWindows(const uint64_t displayId, + std::vector &windows) { HILOG_INFO("displayId[%{public}" PRIu64 "]", displayId); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } return channelClient_->GetWindows(displayId, windows); } -bool AccessibleAbilityClientImpl::GetNext(const AccessibilityElementInfo &elementInfo, +RetError AccessibleAbilityClientImpl::GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo) { HILOG_INFO("windowId[%{public}d], elementId[%{public}d], direction[%{public}d]", @@ -371,24 +370,24 @@ bool AccessibleAbilityClientImpl::GetNext(const AccessibilityElementInfo &elemen std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } if (direction == DIRECTION_INVALID) { HILOG_ERROR("direction is invalid."); - return false; + return RET_ERR_INVALID_PARAM; } return channelClient_->FocusMoveSearch(elementInfo.GetWindowId(), elementInfo.GetAccessibilityId(), direction, nextElementInfo); } -bool AccessibleAbilityClientImpl::GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, +RetError AccessibleAbilityClientImpl::GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, AccessibilityElementInfo &child) { HILOG_DEBUG(); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } int32_t windowId = parent.GetWindowId(); @@ -396,28 +395,24 @@ bool AccessibleAbilityClientImpl::GetChildElementInfo(const int32_t index, const HILOG_INFO("windowId[%{public}d], childId[%{public}d]", windowId, childId); if (childId == -1) { HILOG_ERROR("childId[%{public}d] is invalid", childId); - return false; + return RET_ERR_INVALID_PARAM; } if (GetCacheElementInfo(windowId, childId, child)) { HILOG_DEBUG("get element info from cache"); - return true; + return RET_OK; } - if (!SearchElementInfoFromAce(windowId, childId, cacheMode_, child)) { - HILOG_ERROR("Get element info from ace failed"); - return false; - } - return true; + return SearchElementInfoFromAce(windowId, childId, cacheMode_, child); } -bool AccessibleAbilityClientImpl::GetChildren(const AccessibilityElementInfo &parent, +RetError AccessibleAbilityClientImpl::GetChildren(const AccessibilityElementInfo &parent, std::vector &children) { HILOG_DEBUG(); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } int32_t windowId = parent.GetWindowId(); @@ -427,7 +422,7 @@ bool AccessibleAbilityClientImpl::GetChildren(const AccessibilityElementInfo &pa HILOG_DEBUG("childId[%{public}d]", childId); if (childId == -1) { HILOG_ERROR("childId is invalid"); - return false; + return RET_ERR_INVALID_PARAM; } AccessibilityElementInfo child; @@ -437,23 +432,24 @@ bool AccessibleAbilityClientImpl::GetChildren(const AccessibilityElementInfo &pa continue; } - if (!SearchElementInfoFromAce(windowId, childId, cacheMode_, child)) { + RetError ret = SearchElementInfoFromAce(windowId, childId, cacheMode_, child); + if (ret != RET_OK) { HILOG_ERROR("Get element info from ace failed"); - return false; + return ret; } children.emplace_back(child); } - return true; + return RET_OK; } -bool AccessibleAbilityClientImpl::GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, - std::vector &elementInfos) +RetError AccessibleAbilityClientImpl::GetByContent(const AccessibilityElementInfo &elementInfo, + const std::string &text, std::vector &elementInfos) { HILOG_DEBUG(); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } int32_t windowId = elementInfo.GetWindowId(); int32_t elementId = elementInfo.GetAccessibilityId(); @@ -461,66 +457,57 @@ bool AccessibleAbilityClientImpl::GetByContent(const AccessibilityElementInfo &e return channelClient_->SearchElementInfosByText(windowId, elementId, text, elementInfos); } -bool AccessibleAbilityClientImpl::GetSource(const AccessibilityEventInfo &eventInfo, +RetError AccessibleAbilityClientImpl::GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } int32_t windowId = eventInfo.GetWindowId(); int32_t elementId = eventInfo.GetAccessibilityId(); HILOG_INFO("windowId[%{public}d], elementId[%{public}d]", windowId, elementId); if (GetCacheElementInfo(windowId, elementId, elementInfo)) { HILOG_DEBUG("get element info from cache"); - return true; + return RET_OK; } - - if (!SearchElementInfoFromAce(windowId, elementId, cacheMode_, elementInfo)) { - HILOG_ERROR("Get element info from ace failed"); - return false; - } - return true; + return SearchElementInfoFromAce(windowId, elementId, cacheMode_, elementInfo); } -bool AccessibleAbilityClientImpl::GetParentElementInfo(const AccessibilityElementInfo &child, +RetError AccessibleAbilityClientImpl::GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) { HILOG_DEBUG(); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } int32_t windowId = child.GetWindowId(); int32_t elementId = child.GetParentNodeId(); HILOG_INFO("windowId[%{public}d], parentId[%{public}d]", windowId, elementId); if (GetCacheElementInfo(windowId, elementId, parent)) { HILOG_DEBUG("get element info from cache"); - return true; + return RET_OK; } - if (!SearchElementInfoFromAce(windowId, elementId, cacheMode_, parent)) { - HILOG_ERROR("Get element info from ace failed"); - return false; - } - return true; + return SearchElementInfoFromAce(windowId, elementId, cacheMode_, parent); } -bool AccessibleAbilityClientImpl::ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, - const std::map &actionArguments) +RetError AccessibleAbilityClientImpl::ExecuteAction(const AccessibilityElementInfo &elementInfo, + const ActionType action, const std::map &actionArguments) { HILOG_DEBUG(); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } if (action == ACCESSIBILITY_ACTION_INVALID) { HILOG_ERROR("action is invalid."); - return false; + return RET_ERR_INVALID_PARAM; } int32_t windowId = elementInfo.GetWindowId(); int32_t elementId = elementInfo.GetAccessibilityId(); @@ -529,13 +516,13 @@ bool AccessibleAbilityClientImpl::ExecuteAction(const AccessibilityElementInfo & const_cast &>(actionArguments)); } -bool AccessibleAbilityClientImpl::SetTargetBundleName(const std::vector &targetBundleNames) +RetError AccessibleAbilityClientImpl::SetTargetBundleName(const std::vector &targetBundleNames) { HILOG_INFO("targetBundleNames size[%{public}zu]", targetBundleNames.size()); std::lock_guard lock(mutex_); if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } return channelClient_->SetTargetBundleName(targetBundleNames); } @@ -591,7 +578,7 @@ void AccessibleAbilityClientImpl::ResetAAClient(const wptr &remot } } -void AccessibleAbilityClientImpl::SetCacheMode(const int32_t cacheMode) +RetError AccessibleAbilityClientImpl::SetCacheMode(const int32_t cacheMode) { HILOG_INFO("set cache mode: [%{public}d]", cacheMode); std::lock_guard lock(mutex_); @@ -603,6 +590,7 @@ void AccessibleAbilityClientImpl::SetCacheMode(const int32_t cacheMode) uint32_t mode = static_cast(cacheMode); cacheMode_ = mode & static_cast(GET_SOURCE_PREFETCH_MODE); } + return RET_OK; } bool AccessibleAbilityClientImpl::GetCacheElementInfo(const int32_t windowId, @@ -635,30 +623,32 @@ void AccessibleAbilityClientImpl::SetCacheElementInfo(const int32_t windowId, } } -bool AccessibleAbilityClientImpl::SearchElementInfoFromAce(const int32_t windowId, const int32_t elementId, +RetError AccessibleAbilityClientImpl::SearchElementInfoFromAce(const int32_t windowId, const int32_t elementId, const uint32_t mode, AccessibilityElementInfo &info) { if (!channelClient_) { HILOG_ERROR("The channel is invalid."); - return false; + return RET_ERR_NO_CONNECTION; } std::vector elementInfos {}; - if (!channelClient_->SearchElementInfosByAccessibilityId( - windowId, elementId, static_cast(mode), elementInfos)) { + + RetError ret = channelClient_->SearchElementInfosByAccessibilityId( + windowId, elementId, static_cast(mode), elementInfos); + if (ret != RET_OK) { HILOG_ERROR("search element info failed. windowId[%{public}d] elementId[%{public}d] mode[%{public}d]", windowId, elementId, mode); - return false; + return ret; } if (elementInfos.empty()) { HILOG_ERROR("elementInfos from ace is empty"); - return false; + return RET_ERR_INVALID_ELEMENT_INFO_FROM_ACE; } HILOG_DEBUG("element [elementSize:%{public}zu]", elementInfos.size()); SetCacheElementInfo(windowId, elementInfos); info = elementInfos.front(); - return true; + return RET_OK; } } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/frameworks/aafwk/test/mock/include/mock_accessible_ability_channel_proxy.h b/frameworks/aafwk/test/mock/include/mock_accessible_ability_channel_proxy.h index 5bfbaaf16..3cbeed8e0 100644 --- a/frameworks/aafwk/test/mock/include/mock_accessible_ability_channel_proxy.h +++ b/frameworks/aafwk/test/mock/include/mock_accessible_ability_channel_proxy.h @@ -27,27 +27,27 @@ public: virtual ~MockAccessibleAbilityChannelProxy() = default; MOCK_METHOD5(SearchElementInfoByAccessibilityId, - bool(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, + RetError(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr& callback, const int32_t mode)); MOCK_METHOD5(SearchElementInfosByText, - bool(const int32_t accessibilityWindowId, const int32_t elementId, const std::string& text, + RetError(const int32_t accessibilityWindowId, const int32_t elementId, const std::string& text, const int32_t requestId, const sptr& callback)); MOCK_METHOD5(FindFocusedElementInfo, - bool(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, + RetError(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, const int32_t requestId, const sptr& callback)); - MOCK_METHOD5( - FocusMoveSearch, bool(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, - const int32_t requestId, const sptr& callback)); - - MOCK_METHOD6(ExecuteAction, bool(const int32_t accessibilityWindowId, const int32_t elementId, + MOCK_METHOD5(FocusMoveSearch, RetError(const int32_t accessibilityWindowId, const int32_t elementId, + const int32_t direction, const int32_t requestId, + const sptr& callback)); + MOCK_METHOD6(ExecuteAction, RetError(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map& actionArguments, const int32_t requestId, const sptr& callback)); - MOCK_METHOD2(GetWindow, bool(const int32_t windowId, AccessibilityWindowInfo &windowInfo)); - MOCK_METHOD1(GetWindows, bool(std::vector &windows)); - MOCK_METHOD2(GetWindowsByDisplayId, bool(const uint64_t displayId, std::vector &windows)); + MOCK_METHOD2(GetWindow, RetError(const int32_t windowId, AccessibilityWindowInfo &windowInfo)); + MOCK_METHOD1(GetWindows, RetError(std::vector &windows)); + MOCK_METHOD2(GetWindowsByDisplayId, RetError(const uint64_t displayId, + std::vector &windows)); MOCK_METHOD2(SetOnKeyPressEventResult, void(const bool handled, const int32_t sequence)); - MOCK_METHOD1(SendSimulateGesture, bool(const std::shared_ptr& gesturePath)); - MOCK_METHOD1(SetTargetBundleName, bool(const std::vector &targetBundleNames)); + MOCK_METHOD1(SendSimulateGesture, RetError(const std::shared_ptr& gesturePath)); + MOCK_METHOD1(SetTargetBundleName, RetError(const std::vector &targetBundleNames)); }; } // namespace Accessibility } // namespace OHOS diff --git a/frameworks/aafwk/test/mock/include/mock_accessible_ability_channel_stub.h b/frameworks/aafwk/test/mock/include/mock_accessible_ability_channel_stub.h index 5ffccd002..780b21de6 100644 --- a/frameworks/aafwk/test/mock/include/mock_accessible_ability_channel_stub.h +++ b/frameworks/aafwk/test/mock/include/mock_accessible_ability_channel_stub.h @@ -26,28 +26,30 @@ public: MockAccessibleAbilityChannelStub(); virtual ~MockAccessibleAbilityChannelStub(); - MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); + MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, + MessageParcel& reply, MessageOption& option)); MOCK_METHOD5(SearchElementInfoByAccessibilityId, - bool(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, + RetError(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr& callback, const int32_t mode)); MOCK_METHOD5(SearchElementInfosByText, - bool(const int32_t accessibilityWindowId, const int32_t elementId, const std::string& text, + RetError(const int32_t accessibilityWindowId, const int32_t elementId, const std::string& text, const int32_t requestId, const sptr& callback)); MOCK_METHOD5(FindFocusedElementInfo, - bool(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, + RetError(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, const int32_t requestId, const sptr& callback)); - MOCK_METHOD5( - FocusMoveSearch, bool(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, - const int32_t requestId, const sptr& callback)); - MOCK_METHOD6(ExecuteAction, bool(const int32_t accessibilityWindowId, const int32_t elementId, + MOCK_METHOD5(FocusMoveSearch, RetError(const int32_t accessibilityWindowId, const int32_t elementId, + const int32_t direction, const int32_t requestId, + const sptr& callback)); + MOCK_METHOD6(ExecuteAction, RetError(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map& actionArguments, const int32_t requestId, const sptr& callback)); - MOCK_METHOD2(GetWindow, bool(const int32_t windowId, AccessibilityWindowInfo &windowInfo)); - MOCK_METHOD1(GetWindows, bool(std::vector &windows)); - MOCK_METHOD2(GetWindowsByDisplayId, bool(const uint64_t displayId, std::vector &windows)); + MOCK_METHOD2(GetWindow, RetError(const int32_t windowId, AccessibilityWindowInfo &windowInfo)); + MOCK_METHOD1(GetWindows, RetError(std::vector &windows)); + MOCK_METHOD2(GetWindowsByDisplayId, RetError(const uint64_t displayId, + std::vector &windows)); MOCK_METHOD2(SetOnKeyPressEventResult, void(const bool handled, const int32_t sequence)); - MOCK_METHOD1(SendSimulateGesture, bool(const std::shared_ptr& gesturePath)); - MOCK_METHOD1(SetTargetBundleName, bool(const std::vector &targetBundleNames)); + MOCK_METHOD1(SendSimulateGesture, RetError(const std::shared_ptr& gesturePath)); + MOCK_METHOD1(SetTargetBundleName, RetError(const std::vector &targetBundleNames)); }; } // namespace Accessibility } // namespace OHOS diff --git a/frameworks/aafwk/test/mock/include/mock_accessible_ability_client.h b/frameworks/aafwk/test/mock/include/mock_accessible_ability_client.h index dd3617d12..c9972649d 100644 --- a/frameworks/aafwk/test/mock/include/mock_accessible_ability_client.h +++ b/frameworks/aafwk/test/mock/include/mock_accessible_ability_client.h @@ -25,29 +25,31 @@ public: MockAccessibleAbilityClient(); ~MockAccessibleAbilityClient() = default; sptr GetRemoteObject() override; - bool RegisterAbilityListener(const std::shared_ptr &listener) override; - bool GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) override; - bool GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, + RetError RegisterAbilityListener(const std::shared_ptr &listener) override; + RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) override; + RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo) override; - bool InjectGesture(const std::shared_ptr &gesturePath) override; - bool GetRoot(AccessibilityElementInfo &elementInfo) override; - bool GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo) override; - bool GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; - bool GetWindows(std::vector &windows) override; - bool GetWindows(const uint64_t displayId, std::vector &windows) override; - bool GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, + RetError InjectGesture(const std::shared_ptr &gesturePath) override; + RetError GetRoot(AccessibilityElementInfo &elementInfo) override; + RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo, + AccessibilityElementInfo &elementInfo) override; + RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; + RetError GetWindows(std::vector &windows) override; + RetError GetWindows(const uint64_t displayId, std::vector &windows) override; + RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo) override; - bool GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, + RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, AccessibilityElementInfo &child) override; - bool GetChildren(const AccessibilityElementInfo &parent, std::vector &children) override; - bool GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, + RetError GetChildren(const AccessibilityElementInfo &parent, + std::vector &children) override; + RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, std::vector &elementInfos) override; - bool GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) override; - bool GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) override; - bool ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, + RetError GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) override; + RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) override; + RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, const std::map &actionArguments) override; - bool SetTargetBundleName(const std::vector &targetBundleNames) override; - void SetCacheMode(const int32_t cacheMode) override; + RetError SetTargetBundleName(const std::vector &targetBundleNames) override; + RetError SetCacheMode(const int32_t cacheMode) override; }; } // namespace Accessibility } // namespace OHOS diff --git a/frameworks/aafwk/test/mock/src/mock_accessible_ability_channel_proxy.cpp b/frameworks/aafwk/test/mock/src/mock_accessible_ability_channel_proxy.cpp index ef9686f50..8d697c4dc 100644 --- a/frameworks/aafwk/test/mock/src/mock_accessible_ability_channel_proxy.cpp +++ b/frameworks/aafwk/test/mock/src/mock_accessible_ability_channel_proxy.cpp @@ -39,7 +39,7 @@ bool AccessibleAbilityChannelProxy::SendTransactCmd( return true; } -bool AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr& callback, const int32_t mode) { @@ -48,10 +48,10 @@ bool AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const int (void)requestId; (void)callback; (void)mode; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, const std::string& text, const int32_t requestId, const sptr& callback) { @@ -60,21 +60,22 @@ bool AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t acces (void)text; (void)requestId; (void)callback; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, - const int32_t focusType, const int32_t requestId, const sptr& callback) +RetError AccessibleAbilityChannelProxy::FindFocusedElementInfo(const int32_t accessibilityWindowId, + const int32_t elementId, const int32_t focusType, const int32_t requestId, + const sptr& callback) { (void)accessibilityWindowId; (void)elementId; (void)focusType; (void)requestId; (void)callback; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, +RetError AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, const int32_t requestId, const sptr& callback) { (void)accessibilityWindowId; @@ -82,10 +83,10 @@ bool AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityW (void)direction; (void)requestId; (void)callback; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, +RetError AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map& actionArguments, const int32_t requestId, const sptr& callback) { @@ -95,21 +96,21 @@ bool AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWin (void)actionArguments; (void)requestId; (void)callback; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::GetWindows(std::vector &windows) +RetError AccessibleAbilityChannelProxy::GetWindows(std::vector &windows) { (void)windows; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t displayId, +RetError AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t displayId, std::vector &windows) { (void)displayId; (void)windows; - return true; + return RET_OK; } void AccessibleAbilityChannelProxy::SetOnKeyPressEventResult(const bool handled, const int32_t sequence) @@ -118,11 +119,11 @@ void AccessibleAbilityChannelProxy::SetOnKeyPressEventResult(const bool handled, (void)sequence; } -bool AccessibleAbilityChannelProxy::SendSimulateGesture( +RetError AccessibleAbilityChannelProxy::SendSimulateGesture( const std::shared_ptr& gesturePath) { (void)gesturePath; - return true; + return RET_OK; } MockAccessibleAbilityChannelProxy::MockAccessibleAbilityChannelProxy(const sptr& object) diff --git a/frameworks/aafwk/test/mock/src/mock_accessible_ability_client.cpp b/frameworks/aafwk/test/mock/src/mock_accessible_ability_client.cpp index 9b54e57ed..5c8585830 100644 --- a/frameworks/aafwk/test/mock/src/mock_accessible_ability_client.cpp +++ b/frameworks/aafwk/test/mock/src/mock_accessible_ability_client.cpp @@ -48,24 +48,25 @@ sptr MockAccessibleAbilityClient::GetRemoteObject() return nullptr; } -bool MockAccessibleAbilityClient::RegisterAbilityListener(const std::shared_ptr &listener) +RetError MockAccessibleAbilityClient::RegisterAbilityListener( + const std::shared_ptr &listener) { HILOG_DEBUG(); (void)listener; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) +RetError MockAccessibleAbilityClient::GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); (void)focusType; (void)elementInfo; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, +RetError MockAccessibleAbilityClient::GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); @@ -73,62 +74,63 @@ bool MockAccessibleAbilityClient::GetFocusByElementInfo(const AccessibilityEleme (void)sourceInfo; (void)focusType; (void)elementInfo; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::InjectGesture(const std::shared_ptr &gesturePath) +RetError MockAccessibleAbilityClient::InjectGesture(const std::shared_ptr &gesturePath) { HILOG_INFO(); (void)gesturePath; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetRoot(AccessibilityElementInfo &elementInfo) +RetError MockAccessibleAbilityClient::GetRoot(AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); (void)elementInfo; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetRootByWindow(const AccessibilityWindowInfo &windowInfo, +RetError MockAccessibleAbilityClient::GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); (void)windowInfo; (void)elementInfo; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) +RetError MockAccessibleAbilityClient::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) { HILOG_DEBUG(); (void)windowId; (void)windowInfo; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetWindows(std::vector &windows) +RetError MockAccessibleAbilityClient::GetWindows(std::vector &windows) { HILOG_DEBUG(); (void)windows; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetWindows(const uint64_t displayId, std::vector &windows) +RetError MockAccessibleAbilityClient::GetWindows(const uint64_t displayId, + std::vector &windows) { HILOG_DEBUG(); (void)displayId; (void)windows; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetNext(const AccessibilityElementInfo &elementInfo, +RetError MockAccessibleAbilityClient::GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo) { HILOG_DEBUG(); @@ -136,10 +138,10 @@ bool MockAccessibleAbilityClient::GetNext(const AccessibilityElementInfo &elemen (void)elementInfo; (void)direction; (void)nextElementInfo; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, +RetError MockAccessibleAbilityClient::GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, AccessibilityElementInfo &child) { HILOG_DEBUG(); @@ -147,73 +149,74 @@ bool MockAccessibleAbilityClient::GetChildElementInfo(const int32_t index, const (void)index; (void)parent; (void)child; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetChildren(const AccessibilityElementInfo &parent, +RetError MockAccessibleAbilityClient::GetChildren(const AccessibilityElementInfo &parent, std::vector &children) { HILOG_DEBUG(); (void)parent; (void)children; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, - std::vector &elementInfos) +RetError MockAccessibleAbilityClient::GetByContent(const AccessibilityElementInfo &elementInfo, + const std::string &text, std::vector &elementInfos) { HILOG_DEBUG(); (void)elementInfo; (void)text; (void)elementInfos; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetSource(const AccessibilityEventInfo &eventInfo, +RetError MockAccessibleAbilityClient::GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); (void)eventInfo; (void)elementInfo; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::GetParentElementInfo(const AccessibilityElementInfo &child, +RetError MockAccessibleAbilityClient::GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) { HILOG_DEBUG(); (void)child; (void)parent; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, - const std::map &actionArguments) +RetError MockAccessibleAbilityClient::ExecuteAction(const AccessibilityElementInfo &elementInfo, + const ActionType action, const std::map &actionArguments) { HILOG_DEBUG(); (void)elementInfo; (void)action; (void)actionArguments; - return true; + return RET_OK; } -bool MockAccessibleAbilityClient::SetTargetBundleName(const std::vector &targetBundleNames) +RetError MockAccessibleAbilityClient::SetTargetBundleName(const std::vector &targetBundleNames) { HILOG_DEBUG(); (void)targetBundleNames; - return true; + return RET_OK; } -void MockAccessibleAbilityClient::SetCacheMode(const int32_t cacheMode) +RetError MockAccessibleAbilityClient::SetCacheMode(const int32_t cacheMode) { HILOG_DEBUG(); AccessibilityAbilityUtHelper::GetInstance().SetCacheMode(cacheMode); + return RET_OK; } } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/frameworks/aafwk/test/unittest/accessibility_ui_test_ability_impl_test.cpp b/frameworks/aafwk/test/unittest/accessibility_ui_test_ability_impl_test.cpp index b3cd5baf2..934173247 100644 --- a/frameworks/aafwk/test/unittest/accessibility_ui_test_ability_impl_test.cpp +++ b/frameworks/aafwk/test/unittest/accessibility_ui_test_ability_impl_test.cpp @@ -85,7 +85,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, RegisterAbilityListener_001, TestSi return; } std::shared_ptr listener = nullptr; - EXPECT_FALSE(instance_->RegisterAbilityListener(listener)); + EXPECT_EQ(instance_->RegisterAbilityListener(listener), RET_ERR_INVALID_PARAM); GTEST_LOG_(INFO) << "RegisterAbilityListener_001 end"; } @@ -105,7 +105,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, RegisterAbilityListener_002, TestSi } AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); std::shared_ptr listener = std::make_shared(); - EXPECT_FALSE(instance_->RegisterAbilityListener(listener)); + EXPECT_EQ(instance_->RegisterAbilityListener(listener), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "RegisterAbilityListener_002 end"; @@ -125,7 +125,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, RegisterAbilityListener_003, TestSi return; } std::shared_ptr listener = std::make_shared(); - EXPECT_TRUE(instance_->RegisterAbilityListener(listener)); + EXPECT_EQ(instance_->RegisterAbilityListener(listener), RET_OK); GTEST_LOG_(INFO) << "RegisterAbilityListener_003 end"; } @@ -161,7 +161,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, Disconnect_001, TestSize.Level1) GTEST_LOG_(INFO) << "Cann't get AccessibilityUITestAbilityImpl instance_"; return; } - EXPECT_FALSE(instance_->Disconnect()); + EXPECT_EQ(instance_->Disconnect(), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "Disconnect_001 end"; } @@ -181,7 +181,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetFocus_001, TestSize.Level1) } AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); AccessibilityElementInfo elementInfo {}; - EXPECT_FALSE(instance_->GetFocus(FOCUS_TYPE, elementInfo)); + EXPECT_EQ(instance_->GetFocus(FOCUS_TYPE, elementInfo), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetFocus_001 end"; @@ -201,7 +201,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetFocus_002, TestSize.Level1) return; } AccessibilityElementInfo elementInfo {}; - EXPECT_TRUE(instance_->GetFocus(FOCUS_TYPE, elementInfo)); + EXPECT_EQ(instance_->GetFocus(FOCUS_TYPE, elementInfo), RET_OK); GTEST_LOG_(INFO) << "GetFocus_002 end"; } @@ -222,7 +222,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetFocusByElementInfo_001, TestSize AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); AccessibilityElementInfo sourceInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_FALSE(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE, elementInfo)); + EXPECT_EQ(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE, elementInfo), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetFocusByElementInfo_001 end"; @@ -243,7 +243,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetFocusByElementInfo_002, TestSize } AccessibilityElementInfo sourceInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_TRUE(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE, elementInfo)); + EXPECT_EQ(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE, elementInfo), RET_OK); GTEST_LOG_(INFO) << "GetFocusByElementInfo_002 end"; } @@ -263,7 +263,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, InjectGesture_001, TestSize.Level1) } AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); std::shared_ptr gesturePath = std::make_shared(); - EXPECT_FALSE(instance_->InjectGesture(gesturePath)); + EXPECT_EQ(instance_->InjectGesture(gesturePath), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "InjectGesture_001 end"; @@ -283,7 +283,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, InjectGesture_002, TestSize.Level1) return; } std::shared_ptr gesturePath = std::make_shared(); - EXPECT_TRUE(instance_->InjectGesture(gesturePath)); + EXPECT_EQ(instance_->InjectGesture(gesturePath), RET_OK); GTEST_LOG_(INFO) << "InjectGesture_002 end"; } @@ -303,7 +303,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetRoot_001, TestSize.Level1) } AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); AccessibilityElementInfo elementInfo {}; - EXPECT_FALSE(instance_->GetRoot(elementInfo)); + EXPECT_EQ(instance_->GetRoot(elementInfo), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetRoot_001 end"; @@ -323,7 +323,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetRoot_002, TestSize.Level1) return; } AccessibilityElementInfo elementInfo {}; - EXPECT_TRUE(instance_->GetRoot(elementInfo)); + EXPECT_EQ(instance_->GetRoot(elementInfo), RET_OK); GTEST_LOG_(INFO) << "GetRoot_002 end"; } @@ -344,7 +344,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetRootByWindow_001, TestSize.Level AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); AccessibilityWindowInfo windowInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_FALSE(instance_->GetRootByWindow(windowInfo, elementInfo)); + EXPECT_EQ(instance_->GetRootByWindow(windowInfo, elementInfo), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetRootByWindow_001 end"; @@ -365,7 +365,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetRootByWindow_002, TestSize.Level } AccessibilityWindowInfo windowInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_TRUE(instance_->GetRootByWindow(windowInfo, elementInfo)); + EXPECT_EQ(instance_->GetRootByWindow(windowInfo, elementInfo), RET_OK); GTEST_LOG_(INFO) << "GetRootByWindow_002 end"; } @@ -385,7 +385,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetWindow_001, TestSize.Level1) } AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); AccessibilityWindowInfo winInfo {}; - EXPECT_FALSE(instance_->GetWindow(WINDOW_ID, winInfo)); + EXPECT_EQ(instance_->GetWindow(WINDOW_ID, winInfo), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetWindow_001 end"; } @@ -404,7 +404,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetWindow_002, TestSize.Level1) return; } AccessibilityWindowInfo winInfo {}; - EXPECT_TRUE(instance_->GetWindow(WINDOW_ID, winInfo)); + EXPECT_EQ(instance_->GetWindow(WINDOW_ID, winInfo), RET_OK); GTEST_LOG_(INFO) << "GetWindow_002 end"; } @@ -423,7 +423,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetWindows_001, TestSize.Level1) } AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); std::vector res {}; - EXPECT_FALSE(instance_->GetWindows(res)); + EXPECT_EQ(instance_->GetWindows(res), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetWindows_001 end"; } @@ -442,7 +442,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetWindows_002, TestSize.Level1) return; } std::vector res {}; - EXPECT_TRUE(instance_->GetWindows(res)); + EXPECT_EQ(instance_->GetWindows(res), RET_OK); GTEST_LOG_(INFO) << "GetWindows_002 end"; } @@ -461,7 +461,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetWindows_003, TestSize.Level1) } AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); std::vector res {}; - EXPECT_FALSE(instance_->GetWindows(DISPLAY_ID, res)); + EXPECT_EQ(instance_->GetWindows(DISPLAY_ID, res), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetWindows_003 end"; } @@ -480,7 +480,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetWindows_004, TestSize.Level1) return; } std::vector res {}; - EXPECT_TRUE(instance_->GetWindows(DISPLAY_ID, res)); + EXPECT_EQ(instance_->GetWindows(DISPLAY_ID, res), RET_OK); GTEST_LOG_(INFO) << "GetWindows_004 end"; } @@ -501,7 +501,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetNext_001, TestSize.Level1) AccessibilityElementInfo nextElementInfo {}; AccessibilityElementInfo elementInfo {}; FocusMoveDirection direction = DIRECTION_INVALID; - EXPECT_FALSE(instance_->GetNext(elementInfo, direction, elementInfo)); + EXPECT_EQ(instance_->GetNext(elementInfo, direction, elementInfo), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetNext_001 end"; @@ -523,7 +523,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetNext_002, TestSize.Level1) AccessibilityElementInfo nextElementInfo {}; AccessibilityElementInfo elementInfo {}; FocusMoveDirection direction = DIRECTION_INVALID; - EXPECT_TRUE(instance_->GetNext(elementInfo, direction, elementInfo)); + EXPECT_EQ(instance_->GetNext(elementInfo, direction, elementInfo), RET_OK); GTEST_LOG_(INFO) << "GetNext_002 end"; } @@ -545,7 +545,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetChildElementInfo_001, TestSize.L AccessibilityElementInfo parent {}; AccessibilityElementInfo child {}; int32_t index = 1; - EXPECT_FALSE(instance_->GetChildElementInfo(index, parent, child)); + EXPECT_EQ(instance_->GetChildElementInfo(index, parent, child), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetChildElementInfo_001 end"; @@ -567,7 +567,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetChildElementInfo_002, TestSize.L AccessibilityElementInfo parent {}; AccessibilityElementInfo child {}; int32_t index = 1; - EXPECT_TRUE(instance_->GetChildElementInfo(index, parent, child)); + EXPECT_EQ(instance_->GetChildElementInfo(index, parent, child), RET_OK); GTEST_LOG_(INFO) << "GetChildElementInfo_002 end"; } @@ -588,7 +588,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetByContent_001, TestSize.Level1) AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); AccessibilityElementInfo parent {}; std::vector elementInfos {}; - EXPECT_FALSE(instance_->GetByContent(parent, TEST, elementInfos)); + EXPECT_EQ(instance_->GetByContent(parent, TEST, elementInfos), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetByContent_001 end"; @@ -609,7 +609,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetByContent_002, TestSize.Level1) } AccessibilityElementInfo parent {}; std::vector elementInfos {}; - EXPECT_TRUE(instance_->GetByContent(parent, TEST, elementInfos)); + EXPECT_EQ(instance_->GetByContent(parent, TEST, elementInfos), RET_OK); GTEST_LOG_(INFO) << "GetByContent_002 end"; } @@ -630,7 +630,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetSource_001, TestSize.Level1) AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); AccessibilityEventInfo eventInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_FALSE(instance_->GetSource(eventInfo, elementInfo)); + EXPECT_EQ(instance_->GetSource(eventInfo, elementInfo), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetSource_001 end"; @@ -651,7 +651,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetSource_002, TestSize.Level1) } AccessibilityEventInfo eventInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_TRUE(instance_->GetSource(eventInfo, elementInfo)); + EXPECT_EQ(instance_->GetSource(eventInfo, elementInfo), RET_OK); GTEST_LOG_(INFO) << "GetSource_002 end"; } @@ -672,7 +672,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetParentElementInfo_001, TestSize. AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); AccessibilityElementInfo child {}; AccessibilityElementInfo parent {}; - EXPECT_FALSE(instance_->GetParentElementInfo(child, parent)); + EXPECT_EQ(instance_->GetParentElementInfo(child, parent), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "GetParentElementInfo_001 end"; @@ -693,7 +693,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetParentElementInfo_002, TestSize. } AccessibilityElementInfo child {}; AccessibilityElementInfo parent {}; - EXPECT_TRUE(instance_->GetParentElementInfo(child, parent)); + EXPECT_EQ(instance_->GetParentElementInfo(child, parent), RET_OK); GTEST_LOG_(INFO) << "GetParentElementInfo_002 end"; } @@ -715,7 +715,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, ExecuteAction_001, TestSize.Level1) AccessibilityElementInfo elementInfo {}; ActionType action = ACCESSIBILITY_ACTION_INVALID; std::map actionArguments {}; - EXPECT_FALSE(instance_->ExecuteAction(elementInfo, action, actionArguments)); + EXPECT_EQ(instance_->ExecuteAction(elementInfo, action, actionArguments), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "ExecuteAction_001 end"; @@ -737,7 +737,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, ExecuteAction_002, TestSize.Level1) AccessibilityElementInfo elementInfo {}; ActionType action = ACCESSIBILITY_ACTION_INVALID; std::map actionArguments {}; - EXPECT_TRUE(instance_->ExecuteAction(elementInfo, action, actionArguments)); + EXPECT_EQ(instance_->ExecuteAction(elementInfo, action, actionArguments), RET_OK); GTEST_LOG_(INFO) << "ExecuteAction_002 end"; } @@ -757,7 +757,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, SetTargetBundleName_001, TestSize.L } AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(true); std::vector targetBundleNames; - EXPECT_FALSE(instance_->SetTargetBundleName(targetBundleNames)); + EXPECT_EQ(instance_->SetTargetBundleName(targetBundleNames), RET_ERR_NULLPTR); AccessibilityAbilityUtHelper::GetInstance().SetAbilityClientNullFlag(false); GTEST_LOG_(INFO) << "SetTargetBundleName_001 end"; @@ -777,7 +777,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, SetTargetBundleName_002, TestSize.L return; } std::vector targetBundleNames; - EXPECT_TRUE(instance_->SetTargetBundleName(targetBundleNames)); + EXPECT_EQ(instance_->SetTargetBundleName(targetBundleNames), RET_OK); GTEST_LOG_(INFO) << "SetTargetBundleName_002 end"; } @@ -797,7 +797,7 @@ HWTEST_F(AccessibilityUITestAbilityImplTest, GetChildren_001, TestSize.Level1) } AccessibilityElementInfo parent; std::vector children; - EXPECT_TRUE(instance_->GetChildren(parent, children)); + EXPECT_EQ(instance_->GetChildren(parent, children), RET_OK); GTEST_LOG_(INFO) << "GetChildren_001 end"; } diff --git a/frameworks/aafwk/test/unittest/accessible_ability_channel_client_test.cpp b/frameworks/aafwk/test/unittest/accessible_ability_channel_client_test.cpp index 2a12d3837..be5a9393d 100644 --- a/frameworks/aafwk/test/unittest/accessible_ability_channel_client_test.cpp +++ b/frameworks/aafwk/test/unittest/accessible_ability_channel_client_test.cpp @@ -109,10 +109,10 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SetOnKeyPressEventResult, TestSize. HWTEST_F(AccessibleAbilityChannelClientTest, FindFocusedElementInfo_001, TestSize.Level1) { GTEST_LOG_(INFO) << "FindFocusedElementInfo_001 start"; - EXPECT_CALL(*stub_, FindFocusedElementInfo(_, _, _, _, _)).Times(1).WillOnce(Return(false)); + EXPECT_CALL(*stub_, FindFocusedElementInfo(_, _, _, _, _)).Times(1).WillOnce(Return(RET_ERR_FAILED)); AccessibilityElementInfo info {}; - EXPECT_FALSE(instance_->FindFocusedElementInfo(ACCESSIBILITY_WINDOW_ID, - ELEMENT_ID, FOCUS_TYPE_INPUT, info)); + EXPECT_EQ(instance_->FindFocusedElementInfo(ACCESSIBILITY_WINDOW_ID, + ELEMENT_ID, FOCUS_TYPE_INPUT, info), RET_ERR_FAILED); GTEST_LOG_(INFO) << "FindFocusedElementInfo_001 end"; } @@ -128,7 +128,8 @@ HWTEST_F(AccessibleAbilityChannelClientTest, FindFocusedElementInfo_002, TestSiz std::make_shared(CHANNEL_ID, nullptr); ASSERT_TRUE(client); AccessibilityElementInfo info {}; - EXPECT_FALSE(client->FindFocusedElementInfo(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, FOCUS_TYPE_INPUT, info)); + EXPECT_EQ(client->FindFocusedElementInfo( + ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, FOCUS_TYPE_INPUT, info), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "FindFocusedElementInfo_002 end"; } @@ -140,9 +141,10 @@ HWTEST_F(AccessibleAbilityChannelClientTest, FindFocusedElementInfo_002, TestSiz HWTEST_F(AccessibleAbilityChannelClientTest, FindFocusedElementInfo_003, TestSize.Level1) { GTEST_LOG_(INFO) << "FindFocusedElementInfo_003 start"; - EXPECT_CALL(*stub_, FindFocusedElementInfo(_, _, _, _, _)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, FindFocusedElementInfo(_, _, _, _, _)).Times(1).WillOnce(Return(RET_OK)); AccessibilityElementInfo info {}; - EXPECT_FALSE(instance_->FindFocusedElementInfo(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, FOCUS_TYPE_INPUT, info)); + EXPECT_EQ(instance_->FindFocusedElementInfo( + ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, FOCUS_TYPE_INPUT, info), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "FindFocusedElementInfo_003 end"; } @@ -154,9 +156,9 @@ HWTEST_F(AccessibleAbilityChannelClientTest, FindFocusedElementInfo_003, TestSiz HWTEST_F(AccessibleAbilityChannelClientTest, SendSimulateGesture_001, TestSize.Level1) { GTEST_LOG_(INFO) << "SendSimulateGesture_001 start"; - EXPECT_CALL(*stub_, SendSimulateGesture(_)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, SendSimulateGesture(_)).Times(1).WillOnce(Return(RET_OK)); std::shared_ptr gesturePath = std::make_shared(); - EXPECT_TRUE(instance_->SendSimulateGesture(gesturePath)); + EXPECT_EQ(instance_->SendSimulateGesture(gesturePath), RET_OK); GTEST_LOG_(INFO) << "SendSimulateGesture_001 end"; } @@ -172,7 +174,7 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SendSimulateGesture_002, TestSize.L std::make_shared(CHANNEL_ID, nullptr); ASSERT_TRUE(client); std::shared_ptr gesturePath = std::make_shared(); - EXPECT_FALSE(client->SendSimulateGesture(gesturePath)); + EXPECT_EQ(client->SendSimulateGesture(gesturePath), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "SendSimulateGesture_002 end"; } @@ -184,10 +186,10 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SendSimulateGesture_002, TestSize.L HWTEST_F(AccessibleAbilityChannelClientTest, ExecuteAction_001, TestSize.Level1) { GTEST_LOG_(INFO) << "ExecuteAction_001 start"; - EXPECT_CALL(*stub_, ExecuteAction(_, _, _, _, _, _)).Times(1).WillOnce(Return(false)); + EXPECT_CALL(*stub_, ExecuteAction(_, _, _, _, _, _)).Times(1).WillOnce(Return(RET_ERR_FAILED)); std::map actionArguments; - EXPECT_FALSE(instance_->ExecuteAction(ACCESSIBILITY_WINDOW_ID, - ELEMENT_ID, ActionType::ACCESSIBILITY_ACTION_SELECT, actionArguments)); + EXPECT_EQ(instance_->ExecuteAction(ACCESSIBILITY_WINDOW_ID, + ELEMENT_ID, ActionType::ACCESSIBILITY_ACTION_SELECT, actionArguments), RET_ERR_FAILED); GTEST_LOG_(INFO) << "ExecuteAction_001 end"; } @@ -203,8 +205,8 @@ HWTEST_F(AccessibleAbilityChannelClientTest, ExecuteAction_002, TestSize.Level1) std::make_shared(CHANNEL_ID, nullptr); ASSERT_TRUE(client); std::map actionArguments; - EXPECT_FALSE(client->ExecuteAction(ACCESSIBILITY_WINDOW_ID, - ELEMENT_ID, ActionType::ACCESSIBILITY_ACTION_SELECT, actionArguments)); + EXPECT_EQ(client->ExecuteAction(ACCESSIBILITY_WINDOW_ID, + ELEMENT_ID, ActionType::ACCESSIBILITY_ACTION_SELECT, actionArguments), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "ExecuteAction_002 end"; } @@ -216,10 +218,10 @@ HWTEST_F(AccessibleAbilityChannelClientTest, ExecuteAction_002, TestSize.Level1) HWTEST_F(AccessibleAbilityChannelClientTest, ExecuteAction_003, TestSize.Level1) { GTEST_LOG_(INFO) << "ExecuteAction_003 start"; - EXPECT_CALL(*stub_, ExecuteAction(_, _, _, _, _, _)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, ExecuteAction(_, _, _, _, _, _)).Times(1).WillOnce(Return(RET_OK)); std::map actionArguments; - EXPECT_FALSE(instance_->ExecuteAction(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, - ActionType::ACCESSIBILITY_ACTION_SELECT, actionArguments)); + EXPECT_EQ(instance_->ExecuteAction(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, + ActionType::ACCESSIBILITY_ACTION_SELECT, actionArguments), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "ExecuteAction_003 end"; } @@ -235,7 +237,7 @@ HWTEST_F(AccessibleAbilityChannelClientTest, GetWindow_001, TestSize.Level1) std::make_shared(CHANNEL_ID, nullptr); ASSERT_TRUE(client); AccessibilityWindowInfo windowInfo; - EXPECT_FALSE(client->GetWindow(0, windowInfo)); + EXPECT_EQ(client->GetWindow(0, windowInfo), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "GetWindow_001 end"; } @@ -247,9 +249,9 @@ HWTEST_F(AccessibleAbilityChannelClientTest, GetWindow_001, TestSize.Level1) HWTEST_F(AccessibleAbilityChannelClientTest, GetWindow_002, TestSize.Level1) { GTEST_LOG_(INFO) << "GetWindow_002 start"; - EXPECT_CALL(*stub_, GetWindow(_, _)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, GetWindow(_, _)).Times(1).WillOnce(Return(RET_OK)); AccessibilityWindowInfo windowInfo; - EXPECT_TRUE(instance_->GetWindow(0, windowInfo)); + EXPECT_EQ(instance_->GetWindow(0, windowInfo), RET_OK); GTEST_LOG_(INFO) << "GetWindow_002 end"; } @@ -265,7 +267,7 @@ HWTEST_F(AccessibleAbilityChannelClientTest, GetWindows_001, TestSize.Level1) std::make_shared(CHANNEL_ID, nullptr); ASSERT_TRUE(client); std::vector windowInfo {}; - EXPECT_FALSE(client->GetWindows(windowInfo)); + EXPECT_EQ(client->GetWindows(windowInfo), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "GetWindows_001 end"; } @@ -277,9 +279,9 @@ HWTEST_F(AccessibleAbilityChannelClientTest, GetWindows_001, TestSize.Level1) HWTEST_F(AccessibleAbilityChannelClientTest, GetWindows_002, TestSize.Level1) { GTEST_LOG_(INFO) << "GetWindows_002 start"; - EXPECT_CALL(*stub_, GetWindows(_)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, GetWindows(_)).Times(1).WillOnce(Return(RET_OK)); std::vector windowInfo {}; - EXPECT_TRUE(instance_->GetWindows(windowInfo)); + EXPECT_EQ(instance_->GetWindows(windowInfo), RET_OK); GTEST_LOG_(INFO) << "GetWindows_002 end"; } @@ -295,7 +297,7 @@ HWTEST_F(AccessibleAbilityChannelClientTest, GetWindows_003, TestSize.Level1) std::make_shared(CHANNEL_ID, nullptr); ASSERT_TRUE(client); std::vector windowInfo {}; - EXPECT_FALSE(client->GetWindows(0, windowInfo)); + EXPECT_EQ(client->GetWindows(0, windowInfo), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "GetWindows_003 end"; } @@ -307,9 +309,9 @@ HWTEST_F(AccessibleAbilityChannelClientTest, GetWindows_003, TestSize.Level1) HWTEST_F(AccessibleAbilityChannelClientTest, GetWindows_004, TestSize.Level1) { GTEST_LOG_(INFO) << "GetWindows_004 start"; - EXPECT_CALL(*stub_, GetWindowsByDisplayId(_, _)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, GetWindowsByDisplayId(_, _)).Times(1).WillOnce(Return(RET_OK)); std::vector windowInfo {}; - EXPECT_TRUE(instance_->GetWindows(0, windowInfo)); + EXPECT_EQ(instance_->GetWindows(0, windowInfo), RET_OK); GTEST_LOG_(INFO) << "GetWindows_004 end"; } @@ -325,7 +327,7 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SearchElementInfosByText_001, TestS std::make_shared(CHANNEL_ID, nullptr); ASSERT_TRUE(client); std::vector infos; - EXPECT_FALSE(client->SearchElementInfosByText(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, TEST, infos)); + EXPECT_EQ(client->SearchElementInfosByText(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, TEST, infos), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "SearchElementInfosByText_001 end"; } @@ -337,9 +339,9 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SearchElementInfosByText_001, TestS HWTEST_F(AccessibleAbilityChannelClientTest, SearchElementInfosByText_002, TestSize.Level1) { GTEST_LOG_(INFO) << "SearchElementInfosByText_002 start"; - EXPECT_CALL(*stub_, SearchElementInfosByText(_, _, _, _, _)).Times(1).WillOnce(Return(false)); + EXPECT_CALL(*stub_, SearchElementInfosByText(_, _, _, _, _)).Times(1).WillOnce(Return(RET_ERR_FAILED)); std::vector infos; - EXPECT_FALSE(instance_->SearchElementInfosByText(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, TEST, infos)); + EXPECT_EQ(instance_->SearchElementInfosByText(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, TEST, infos), RET_ERR_FAILED); GTEST_LOG_(INFO) << "SearchElementInfosByText_002 end"; } @@ -351,9 +353,9 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SearchElementInfosByText_002, TestS HWTEST_F(AccessibleAbilityChannelClientTest, SearchElementInfosByText_003, TestSize.Level1) { GTEST_LOG_(INFO) << "SearchElementInfosByText_003 start"; - EXPECT_CALL(*stub_, SearchElementInfosByText(_, _, _, _, _)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, SearchElementInfosByText(_, _, _, _, _)).Times(1).WillOnce(Return(RET_OK)); std::vector infos; - EXPECT_FALSE(instance_->SearchElementInfosByText(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, TEST, infos)); + EXPECT_EQ(instance_->SearchElementInfosByText(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, TEST, infos), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "SearchElementInfosByText_003 end"; } @@ -369,7 +371,8 @@ HWTEST_F(AccessibleAbilityChannelClientTest, FocusMoveSearch_001, TestSize.Level std::make_shared(CHANNEL_ID, nullptr); ASSERT_TRUE(client); AccessibilityElementInfo info {}; - EXPECT_FALSE(client->FocusMoveSearch(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, FocusMoveDirection::DOWN, info)); + EXPECT_EQ(client->FocusMoveSearch(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, + FocusMoveDirection::DOWN, info), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "FocusMoveSearch_001 end"; } @@ -381,9 +384,10 @@ HWTEST_F(AccessibleAbilityChannelClientTest, FocusMoveSearch_001, TestSize.Level HWTEST_F(AccessibleAbilityChannelClientTest, FocusMoveSearch_002, TestSize.Level1) { GTEST_LOG_(INFO) << "FocusMoveSearch_002 start"; - EXPECT_CALL(*stub_, FocusMoveSearch(_, _, _, _, _)).Times(1).WillOnce(Return(false)); + EXPECT_CALL(*stub_, FocusMoveSearch(_, _, _, _, _)).Times(1).WillOnce(Return(RET_ERR_FAILED)); AccessibilityElementInfo info {}; - EXPECT_FALSE(instance_->FocusMoveSearch(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, FocusMoveDirection::DOWN, info)); + EXPECT_EQ(instance_->FocusMoveSearch(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, + FocusMoveDirection::DOWN, info), RET_ERR_FAILED); GTEST_LOG_(INFO) << "FocusMoveSearch_002 end"; } @@ -395,9 +399,10 @@ HWTEST_F(AccessibleAbilityChannelClientTest, FocusMoveSearch_002, TestSize.Level HWTEST_F(AccessibleAbilityChannelClientTest, FocusMoveSearch_003, TestSize.Level1) { GTEST_LOG_(INFO) << "FocusMoveSearch_003 start"; - EXPECT_CALL(*stub_, FocusMoveSearch(_, _, _, _, _)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, FocusMoveSearch(_, _, _, _, _)).Times(1).WillOnce(Return(RET_OK)); AccessibilityElementInfo info {}; - EXPECT_FALSE(instance_->FocusMoveSearch(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, FocusMoveDirection::DOWN, info)); + EXPECT_EQ(instance_->FocusMoveSearch(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, + FocusMoveDirection::DOWN, info), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "FocusMoveSearch_003 end"; } @@ -413,7 +418,7 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SetTargetBundleName_001, TestSize.L std::make_shared(CHANNEL_ID, nullptr); ASSERT_TRUE(client); std::vector targetBundleNames; - EXPECT_FALSE(client->SetTargetBundleName(targetBundleNames)); + EXPECT_EQ(client->SetTargetBundleName(targetBundleNames), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "SetTargetBundleName_001 end"; } @@ -425,9 +430,9 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SetTargetBundleName_001, TestSize.L HWTEST_F(AccessibleAbilityChannelClientTest, SetTargetBundleName_002, TestSize.Level1) { GTEST_LOG_(INFO) << "SetTargetBundleName_002 start"; - EXPECT_CALL(*stub_, SetTargetBundleName(_)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, SetTargetBundleName(_)).Times(1).WillOnce(Return(RET_OK)); std::vector targetBundleNames; - EXPECT_TRUE(instance_->SetTargetBundleName(targetBundleNames)); + EXPECT_EQ(instance_->SetTargetBundleName(targetBundleNames), RET_OK); GTEST_LOG_(INFO) << "SetTargetBundleName_002 end"; } @@ -439,9 +444,10 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SetTargetBundleName_002, TestSize.L HWTEST_F(AccessibleAbilityChannelClientTest, SearchElementInfosByAccessibilityId_001, TestSize.Level1) { GTEST_LOG_(INFO) << "SearchElementInfosByAccessibilityId_001 start"; - EXPECT_CALL(*stub_, SearchElementInfoByAccessibilityId(_, _, _, _, _)).Times(1).WillOnce(Return(false)); + EXPECT_CALL(*stub_, SearchElementInfoByAccessibilityId(_, _, _, _, _)).Times(1).WillOnce(Return(RET_ERR_FAILED)); std::vector infos; - EXPECT_FALSE(instance_->SearchElementInfosByAccessibilityId(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, MODE, infos)); + EXPECT_EQ(instance_->SearchElementInfosByAccessibilityId(ACCESSIBILITY_WINDOW_ID, + ELEMENT_ID, MODE, infos), RET_ERR_FAILED); GTEST_LOG_(INFO) << "SearchElementInfosByAccessibilityId_001 end"; } @@ -457,7 +463,8 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SearchElementInfosByAccessibilityId std::make_shared(CHANNEL_ID, nullptr); ASSERT_TRUE(client); std::vector infos; - EXPECT_FALSE(client->SearchElementInfosByAccessibilityId(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, MODE, infos)); + EXPECT_EQ(client->SearchElementInfosByAccessibilityId(ACCESSIBILITY_WINDOW_ID, + ELEMENT_ID, MODE, infos), RET_ERR_SAMGR); GTEST_LOG_(INFO) << "SearchElementInfosByAccessibilityId_002 end"; } @@ -469,9 +476,10 @@ HWTEST_F(AccessibleAbilityChannelClientTest, SearchElementInfosByAccessibilityId HWTEST_F(AccessibleAbilityChannelClientTest, SearchElementInfosByAccessibilityId_003, TestSize.Level1) { GTEST_LOG_(INFO) << "SearchElementInfosByAccessibilityId_003 start"; - EXPECT_CALL(*stub_, SearchElementInfoByAccessibilityId(_, _, _, _, _)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, SearchElementInfoByAccessibilityId(_, _, _, _, _)).Times(1).WillOnce(Return(RET_OK)); std::vector infos; - EXPECT_FALSE(instance_->SearchElementInfosByAccessibilityId(ACCESSIBILITY_WINDOW_ID, ELEMENT_ID, MODE, infos)); + EXPECT_EQ(instance_->SearchElementInfosByAccessibilityId(ACCESSIBILITY_WINDOW_ID, + ELEMENT_ID, MODE, infos), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "SearchElementInfosByAccessibilityId_003 end"; } } // namespace Accessibility diff --git a/frameworks/aafwk/test/unittest/accessible_ability_client_impl_test.cpp b/frameworks/aafwk/test/unittest/accessible_ability_client_impl_test.cpp index 4fd844cdc..8701e8806 100644 --- a/frameworks/aafwk/test/unittest/accessible_ability_client_impl_test.cpp +++ b/frameworks/aafwk/test/unittest/accessible_ability_client_impl_test.cpp @@ -85,7 +85,7 @@ public: void AccessibleAbilityClientImplTest::Connect() { - EXPECT_TRUE(instance_->RegisterAbilityListener(listener_)); + EXPECT_EQ(instance_->RegisterAbilityListener(listener_), RET_OK); instance_->Init(channel_, CHANNEL_ID); EXPECT_EQ(AccessibilityAbilityHelper::GetInstance().GetTestChannelId(), static_cast(CHANNEL_ID)); } @@ -146,7 +146,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetFocus_001, TestSize.Level1) GTEST_LOG_(INFO) << "GetFocus_001 start"; Connect(); AccessibilityElementInfo info {}; - EXPECT_FALSE(instance_->GetFocus(FOCUS_TYPE_INPUT, info)); + EXPECT_EQ(instance_->GetFocus(FOCUS_TYPE_INPUT, info), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "GetFocus_001 end"; } @@ -159,7 +159,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetFocus_002, TestSize.Level1) { GTEST_LOG_(INFO) << "GetFocus_002 start"; AccessibilityElementInfo info {}; - EXPECT_FALSE(instance_->GetFocus(FOCUS_TYPE_INVALID, info)); + EXPECT_EQ(instance_->GetFocus(FOCUS_TYPE_INVALID, info), RET_ERR_INVALID_PARAM); GTEST_LOG_(INFO) << "GetFocus_002 end"; } @@ -172,7 +172,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetFocus_003, TestSize.Level1) { GTEST_LOG_(INFO) << "GetFocus_003 start"; AccessibilityElementInfo info {}; - EXPECT_FALSE(instance_->GetFocus(FOCUS_TYPE_INPUT, info)); + EXPECT_EQ(instance_->GetFocus(FOCUS_TYPE_INPUT, info), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetFocus_003 end"; } @@ -197,8 +197,8 @@ HWTEST_F(AccessibleAbilityClientImplTest, RegisterAbilityListener_001, TestSize. { GTEST_LOG_(INFO) << "RegisterAbilityListener_001 start"; std::shared_ptr listener = std::make_shared(); - EXPECT_TRUE(instance_->RegisterAbilityListener(listener)); - EXPECT_FALSE(instance_->RegisterAbilityListener(listener)); + EXPECT_EQ(instance_->RegisterAbilityListener(listener), RET_OK); + EXPECT_EQ(instance_->RegisterAbilityListener(listener), RET_ERR_REGISTER_EXIST); GTEST_LOG_(INFO) << "RegisterAbilityListener_001 end"; } @@ -225,7 +225,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, Init_002, TestSize.Level1) { GTEST_LOG_(INFO) << "Init_002 start"; std::shared_ptr listener = std::make_shared(); - EXPECT_TRUE(instance_->RegisterAbilityListener(listener)); + EXPECT_EQ(instance_->RegisterAbilityListener(listener), RET_OK); sptr stub = new MockAccessibleAbilityChannelStub(); sptr channel = new MockAccessibleAbilityChannelProxy(stub->AsObject()); @@ -260,7 +260,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetFocusByElementInfo_001, TestSize.Le Connect(); AccessibilityElementInfo sourceInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_FALSE(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE_INPUT, elementInfo)); + EXPECT_EQ(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE_INPUT, elementInfo), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "GetFocusByElementInfo_001 end"; } @@ -274,7 +274,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetFocusByElementInfo_002, TestSize.Le GTEST_LOG_(INFO) << "GetFocusByElementInfo_002 start"; AccessibilityElementInfo sourceInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_FALSE(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE_INVALID, elementInfo)); + EXPECT_EQ(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE_INVALID, elementInfo), RET_ERR_INVALID_PARAM); GTEST_LOG_(INFO) << "GetFocusByElementInfo_002 end"; } @@ -288,7 +288,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetFocusByElementInfo_003, TestSize.Le GTEST_LOG_(INFO) << "GetFocusByElementInfo_003 start"; AccessibilityElementInfo sourceInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_FALSE(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE_INPUT, elementInfo)); + EXPECT_EQ(instance_->GetFocusByElementInfo(sourceInfo, FOCUS_TYPE_INPUT, elementInfo), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetFocusByElementInfo_003 end"; } @@ -301,7 +301,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, InjectGesture_001, TestSize.Level1) { GTEST_LOG_(INFO) << "InjectGesture_001 start"; std::shared_ptr gesturePath = std::make_shared(); - EXPECT_FALSE(instance_->InjectGesture(gesturePath)); + EXPECT_EQ(instance_->InjectGesture(gesturePath), RET_ERR_INVALID_PARAM); GTEST_LOG_(INFO) << "InjectGesture_001 end"; } @@ -314,7 +314,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, InjectGesture_002, TestSize.Level1) { GTEST_LOG_(INFO) << "InjectGesture_002 start"; std::shared_ptr gesturePath = nullptr; - EXPECT_FALSE(instance_->InjectGesture(gesturePath)); + EXPECT_EQ(instance_->InjectGesture(gesturePath), RET_ERR_INVALID_PARAM); GTEST_LOG_(INFO) << "InjectGesture_002 end"; } @@ -326,12 +326,12 @@ HWTEST_F(AccessibleAbilityClientImplTest, InjectGesture_002, TestSize.Level1) HWTEST_F(AccessibleAbilityClientImplTest, InjectGesture_003, TestSize.Level1) { GTEST_LOG_(INFO) << "InjectGesture_003 start"; - EXPECT_CALL(*stub_, SendSimulateGesture(_)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, SendSimulateGesture(_)).Times(1).WillOnce(Return(RET_OK)); Connect(); std::shared_ptr gesturePath = std::make_shared(); AccessibilityGesturePosition position; gesturePath->AddPosition(position); - EXPECT_TRUE(instance_->InjectGesture(gesturePath)); + EXPECT_EQ(instance_->InjectGesture(gesturePath), RET_OK); GTEST_LOG_(INFO) << "InjectGesture_003 end"; } @@ -346,7 +346,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, InjectGesture_004, TestSize.Level1) std::shared_ptr gesturePath = std::make_shared(); AccessibilityGesturePosition position; gesturePath->AddPosition(position); - EXPECT_FALSE(instance_->InjectGesture(gesturePath)); + EXPECT_EQ(instance_->InjectGesture(gesturePath), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "InjectGesture_004 end"; } @@ -361,7 +361,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetRoot_001, TestSize.Level1) Connect(); AccessibilityElementInfo info {}; instance_->SetCacheMode(0); - EXPECT_FALSE(instance_->GetRoot(info)); + EXPECT_EQ(instance_->GetRoot(info), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "GetRoot_001 end"; } @@ -375,7 +375,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetRoot_002, TestSize.Level1) GTEST_LOG_(INFO) << "GetRoot_002 start"; AccessibilityElementInfo info {}; instance_->SetCacheMode(INVALID_ID); - EXPECT_FALSE(instance_->GetRoot(info)); + EXPECT_EQ(instance_->GetRoot(info), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetRoot_002 end"; } @@ -390,7 +390,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetRootByWindow_001, TestSize.Level1) Connect(); AccessibilityElementInfo info {}; AccessibilityWindowInfo windowInfo {}; - EXPECT_FALSE(instance_->GetRootByWindow(windowInfo, info)); + EXPECT_EQ(instance_->GetRootByWindow(windowInfo, info), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "GetRootByWindow_001 end"; } @@ -405,7 +405,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetRootByWindow_002, TestSize.Level1) GTEST_LOG_(INFO) << "GetRootByWindow_002 start"; AccessibilityElementInfo info {}; AccessibilityWindowInfo windowInfo {}; - EXPECT_FALSE(instance_->GetRootByWindow(windowInfo, info)); + EXPECT_EQ(instance_->GetRootByWindow(windowInfo, info), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetRootByWindow_002 end"; } @@ -422,7 +422,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetNext_001, TestSize.Level1) AccessibilityElementInfo info {}; AccessibilityElementInfo nextElementInfo {}; FocusMoveDirection direction = DIRECTION_INVALID; - EXPECT_FALSE(instance_->GetNext(info, direction, nextElementInfo)); + EXPECT_EQ(instance_->GetNext(info, direction, nextElementInfo), RET_ERR_INVALID_PARAM); GTEST_LOG_(INFO) << "GetNext_001 end"; } @@ -437,7 +437,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetNext_002, TestSize.Level1) AccessibilityElementInfo info {}; AccessibilityElementInfo nextElementInfo {}; FocusMoveDirection direction = UP; - EXPECT_FALSE(instance_->GetNext(info, direction, nextElementInfo)); + EXPECT_EQ(instance_->GetNext(info, direction, nextElementInfo), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetNext_002 end"; } @@ -453,7 +453,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetNext_003, TestSize.Level1) AccessibilityElementInfo info {}; AccessibilityElementInfo nextElementInfo {}; FocusMoveDirection direction = DOWN; - EXPECT_FALSE(instance_->GetNext(info, direction, nextElementInfo)); + EXPECT_EQ(instance_->GetNext(info, direction, nextElementInfo), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "GetNext_003 end"; } @@ -468,7 +468,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetByContent_001, TestSize.Level1) Connect(); AccessibilityElementInfo elementInfo {}; std::vector inelementInfosfos; - EXPECT_FALSE(instance_->GetByContent(elementInfo, TEST, inelementInfosfos)); + EXPECT_EQ(instance_->GetByContent(elementInfo, TEST, inelementInfosfos), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "GetByContent_001 end"; } @@ -482,7 +482,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetByContent_002, TestSize.Level1) GTEST_LOG_(INFO) << "GetByContent_002 start"; AccessibilityElementInfo elementInfo {}; std::vector inelementInfosfos; - EXPECT_FALSE(instance_->GetByContent(elementInfo, TEST, inelementInfosfos)); + EXPECT_EQ(instance_->GetByContent(elementInfo, TEST, inelementInfosfos), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetByContent_002 end"; } @@ -497,7 +497,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetSource_001, TestSize.Level1) Connect(); AccessibilityEventInfo eventInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_FALSE(instance_->GetSource(eventInfo, elementInfo)); + EXPECT_EQ(instance_->GetSource(eventInfo, elementInfo), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "GetSource_001 end"; } @@ -511,7 +511,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetSource_002, TestSize.Level1) GTEST_LOG_(INFO) << "GetSource_002 start"; AccessibilityEventInfo eventInfo {}; AccessibilityElementInfo elementInfo {}; - EXPECT_FALSE(instance_->GetSource(eventInfo, elementInfo)); + EXPECT_EQ(instance_->GetSource(eventInfo, elementInfo), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetSource_002 end"; } @@ -526,7 +526,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetParentElementInfo_001, TestSize.Lev Connect(); AccessibilityElementInfo parent {}; AccessibilityElementInfo child {}; - EXPECT_FALSE(instance_->GetParentElementInfo(child, parent)); + EXPECT_EQ(instance_->GetParentElementInfo(child, parent), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "GetParentElementInfo_001 end"; } @@ -540,7 +540,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetParentElementInfo_002, TestSize.Lev GTEST_LOG_(INFO) << "GetParentElementInfo_002 start"; AccessibilityElementInfo parent {}; AccessibilityElementInfo child {}; - EXPECT_FALSE(instance_->GetParentElementInfo(child, parent)); + EXPECT_EQ(instance_->GetParentElementInfo(child, parent), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetParentElementInfo_002 end"; } @@ -556,7 +556,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, ExecuteAction_001, TestSize.Level1) AccessibilityElementInfo elementInfo {}; ActionType action = ACCESSIBILITY_ACTION_INVALID; std::map actionArguments {}; - EXPECT_FALSE(instance_->ExecuteAction(elementInfo, action, actionArguments)); + EXPECT_EQ(instance_->ExecuteAction(elementInfo, action, actionArguments), RET_ERR_INVALID_PARAM); GTEST_LOG_(INFO) << "ExecuteAction_001 end"; } @@ -571,7 +571,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, ExecuteAction_002, TestSize.Level1) AccessibilityElementInfo elementInfo {}; ActionType action = ACCESSIBILITY_ACTION_SELECT; std::map actionArguments {}; - EXPECT_FALSE(instance_->ExecuteAction(elementInfo, action, actionArguments)); + EXPECT_EQ(instance_->ExecuteAction(elementInfo, action, actionArguments), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "ExecuteAction_002 end"; } @@ -587,7 +587,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, ExecuteAction_003, TestSize.Level1) AccessibilityElementInfo elementInfo {}; ActionType action = ACCESSIBILITY_ACTION_SELECT; std::map actionArguments {}; - EXPECT_FALSE(instance_->ExecuteAction(elementInfo, action, actionArguments)); + EXPECT_EQ(instance_->ExecuteAction(elementInfo, action, actionArguments), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "ExecuteAction_003 end"; } @@ -599,12 +599,12 @@ HWTEST_F(AccessibleAbilityClientImplTest, ExecuteAction_003, TestSize.Level1) HWTEST_F(AccessibleAbilityClientImplTest, ResetAAClient_001, TestSize.Level1) { GTEST_LOG_(INFO) << "ResetAAClient_001 start"; - EXPECT_CALL(*stub_, GetWindows(_)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, GetWindows(_)).Times(1).WillOnce(Return(RET_OK)); Connect(); wptr remote = nullptr; instance_->ResetAAClient(remote); std::vector infos; - EXPECT_TRUE(instance_->GetWindows(infos)); + EXPECT_EQ(instance_->GetWindows(infos), RET_OK); GTEST_LOG_(INFO) << "ResetAAClient_001 end"; } @@ -647,10 +647,10 @@ HWTEST_F(AccessibleAbilityClientImplTest, OnKeyPressEvent_002, TestSize.Level1) HWTEST_F(AccessibleAbilityClientImplTest, GetWindows_001, TestSize.Level1) { GTEST_LOG_(INFO) << "GetWindows_001 start"; - EXPECT_CALL(*stub_, GetWindows(_)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, GetWindows(_)).Times(1).WillOnce(Return(RET_OK)); Connect(); std::vector infos; - EXPECT_TRUE(instance_->GetWindows(infos)); + EXPECT_EQ(instance_->GetWindows(infos), RET_OK); GTEST_LOG_(INFO) << "GetWindows_001 end"; } @@ -662,10 +662,10 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetWindows_001, TestSize.Level1) HWTEST_F(AccessibleAbilityClientImplTest, GetWindows_002, TestSize.Level1) { GTEST_LOG_(INFO) << "GetWindows_002 start"; - EXPECT_CALL(*stub_, GetWindowsByDisplayId(_, _)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, GetWindowsByDisplayId(_, _)).Times(1).WillOnce(Return(RET_OK)); Connect(); std::vector infos; - EXPECT_TRUE(instance_->GetWindows(0, infos)); + EXPECT_EQ(instance_->GetWindows(0, infos), RET_OK); GTEST_LOG_(INFO) << "GetWindows_002 end"; } @@ -678,7 +678,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetWindows_003, TestSize.Level1) { GTEST_LOG_(INFO) << "GetWindows_003 start"; std::vector infos; - EXPECT_FALSE(instance_->GetWindows(infos)); + EXPECT_EQ(instance_->GetWindows(infos), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetWindows_003 end"; } @@ -691,7 +691,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetWindows_004, TestSize.Level1) { GTEST_LOG_(INFO) << "GetWindows_004 start"; std::vector infos; - EXPECT_FALSE(instance_->GetWindows(0, infos)); + EXPECT_EQ(instance_->GetWindows(0, infos), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetWindows_004 end"; } @@ -705,7 +705,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetChildElementInfo_001, TestSize.Leve GTEST_LOG_(INFO) << "GetChildElementInfo_001 start"; AccessibilityElementInfo parent; AccessibilityElementInfo child; - EXPECT_FALSE(instance_->GetChildElementInfo(0, parent, child)); + EXPECT_EQ(instance_->GetChildElementInfo(0, parent, child), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetChildElementInfo_001 end"; } @@ -720,7 +720,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetChildElementInfo_002, TestSize.Leve Connect(); AccessibilityElementInfo parent; AccessibilityElementInfo child; - EXPECT_FALSE(instance_->GetChildElementInfo(0, parent, child)); + EXPECT_EQ(instance_->GetChildElementInfo(0, parent, child), RET_ERR_INVALID_PARAM); GTEST_LOG_(INFO) << "GetChildElementInfo_002 end"; } @@ -737,7 +737,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetChildElementInfo_003, TestSize.Leve AccessibilityElementInfo parent; parent.AddChild(1); AccessibilityElementInfo child; - EXPECT_FALSE(instance_->GetChildElementInfo(0, parent, child)); + EXPECT_EQ(instance_->GetChildElementInfo(0, parent, child), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "GetChildElementInfo_003 end"; } @@ -751,7 +751,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetChildren_001, TestSize.Level1) GTEST_LOG_(INFO) << "GetChildren_001 start"; AccessibilityElementInfo parent; std::vector children; - EXPECT_FALSE(instance_->GetChildren(parent, children)); + EXPECT_EQ(instance_->GetChildren(parent, children), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetChildren_001 end"; } @@ -768,7 +768,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetChildren_002, TestSize.Level1) AccessibilityElementInfo parent; parent.AddChild(INVALID_CHILD_ID); std::vector children; - EXPECT_FALSE(instance_->GetChildren(parent, children)); + EXPECT_EQ(instance_->GetChildren(parent, children), RET_ERR_INVALID_PARAM); GTEST_LOG_(INFO) << "GetChildren_002 end"; } @@ -785,7 +785,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetChildren_003, TestSize.Level1) AccessibilityElementInfo parent; parent.AddChild(1); std::vector children; - EXPECT_FALSE(instance_->GetChildren(parent, children)); + EXPECT_EQ(instance_->GetChildren(parent, children), RET_ERR_TIME_OUT); GTEST_LOG_(INFO) << "GetChildren_003 end"; } @@ -798,7 +798,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, SetTargetBundleName_001, TestSize.Leve { GTEST_LOG_(INFO) << "SetTargetBundleName_001 start"; std::vector targetBundleNames; - EXPECT_FALSE(instance_->SetTargetBundleName(targetBundleNames)); + EXPECT_EQ(instance_->SetTargetBundleName(targetBundleNames), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "SetTargetBundleName_001 end"; } @@ -810,10 +810,10 @@ HWTEST_F(AccessibleAbilityClientImplTest, SetTargetBundleName_001, TestSize.Leve HWTEST_F(AccessibleAbilityClientImplTest, SetTargetBundleName_002, TestSize.Level1) { GTEST_LOG_(INFO) << "SetTargetBundleName_002 start"; - EXPECT_CALL(*stub_, SetTargetBundleName(_)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, SetTargetBundleName(_)).Times(1).WillOnce(Return(RET_OK)); Connect(); std::vector targetBundleNames; - EXPECT_TRUE(instance_->SetTargetBundleName(targetBundleNames)); + EXPECT_EQ(instance_->SetTargetBundleName(targetBundleNames), RET_OK); GTEST_LOG_(INFO) << "SetTargetBundleName_002 end"; } @@ -826,7 +826,7 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetWindow_001, TestSize.Level1) { GTEST_LOG_(INFO) << "GetWindow_001 start"; AccessibilityWindowInfo windowInfo; - EXPECT_FALSE(instance_->GetWindow(0, windowInfo)); + EXPECT_EQ(instance_->GetWindow(0, windowInfo), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "GetWindow_001 end"; } @@ -838,10 +838,10 @@ HWTEST_F(AccessibleAbilityClientImplTest, GetWindow_001, TestSize.Level1) HWTEST_F(AccessibleAbilityClientImplTest, GetWindow_002, TestSize.Level1) { GTEST_LOG_(INFO) << "GetWindow_002 start"; - EXPECT_CALL(*stub_, GetWindow(_, _)).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*stub_, GetWindow(_, _)).Times(1).WillOnce(Return(RET_OK)); Connect(); AccessibilityWindowInfo windowInfo; - EXPECT_TRUE(instance_->GetWindow(0, windowInfo)); + EXPECT_EQ(instance_->GetWindow(0, windowInfo), RET_OK); GTEST_LOG_(INFO) << "GetWindow_002 end"; } diff --git a/frameworks/acfwk/include/accessibility_config_impl.h b/frameworks/acfwk/include/accessibility_config_impl.h index a7ffc9ba4..379dd55cc 100644 --- a/frameworks/acfwk/include/accessibility_config_impl.h +++ b/frameworks/acfwk/include/accessibility_config_impl.h @@ -33,16 +33,18 @@ public: bool InitializeContext(); - void SubscribeConfigObserver(const CONFIG_ID id, const std::shared_ptr &observer, - const bool retFlag); - void UnsubscribeConfigObserver(const CONFIG_ID id, const std::shared_ptr &observer); + Accessibility::RetError SubscribeConfigObserver(const CONFIG_ID id, + const std::shared_ptr &observer, const bool retFlag); + Accessibility::RetError UnsubscribeConfigObserver(const CONFIG_ID id, + const std::shared_ptr &observer); - void SubscribeEnableAbilityListsObserver(const std::shared_ptr &observer); - void UnsubscribeEnableAbilityListsObserver( + Accessibility::RetError SubscribeEnableAbilityListsObserver( + const std::shared_ptr &observer); + Accessibility::RetError UnsubscribeEnableAbilityListsObserver( const std::shared_ptr &observer); - bool EnableAbility(const std::string &name, const uint32_t capabilities); - bool DisableAbility(const std::string &name); + Accessibility::RetError EnableAbility(const std::string &name, const uint32_t capabilities); + Accessibility::RetError DisableAbility(const std::string &name); Accessibility::RetError SetScreenMagnificationState(const bool state); Accessibility::RetError SetShortKeyState(const bool state); diff --git a/frameworks/acfwk/src/accessibility_config.cpp b/frameworks/acfwk/src/accessibility_config.cpp index 5f5585285..f0ac3c6fc 100644 --- a/frameworks/acfwk/src/accessibility_config.cpp +++ b/frameworks/acfwk/src/accessibility_config.cpp @@ -44,43 +44,43 @@ bool AccessibilityConfig::InitializeContext() return pImpl_->InitializeContext(); } -void AccessibilityConfig::SubscribeConfigObserver(const CONFIG_ID id, +Accessibility::RetError AccessibilityConfig::SubscribeConfigObserver(const CONFIG_ID id, const std::shared_ptr &observer, const bool retFlag) { - CHECK_IMPL_PTR() - pImpl_->SubscribeConfigObserver(id, observer, retFlag); + CHECK_IMPL_PTR(Accessibility::RET_ERR_NULLPTR) + return pImpl_->SubscribeConfigObserver(id, observer, retFlag); } -void AccessibilityConfig::UnsubscribeConfigObserver(const CONFIG_ID id, +Accessibility::RetError AccessibilityConfig::UnsubscribeConfigObserver(const CONFIG_ID id, const std::shared_ptr &observer) { - CHECK_IMPL_PTR() - pImpl_->UnsubscribeConfigObserver(id, observer); + CHECK_IMPL_PTR(Accessibility::RET_ERR_NULLPTR) + return pImpl_->UnsubscribeConfigObserver(id, observer); } -void AccessibilityConfig::SubscribeEnableAbilityListsObserver( +Accessibility::RetError AccessibilityConfig::SubscribeEnableAbilityListsObserver( const std::shared_ptr &observer) { - CHECK_IMPL_PTR() - pImpl_->SubscribeEnableAbilityListsObserver(observer); + CHECK_IMPL_PTR(Accessibility::RET_ERR_NULLPTR) + return pImpl_->SubscribeEnableAbilityListsObserver(observer); } -void AccessibilityConfig::UnsubscribeEnableAbilityListsObserver( +Accessibility::RetError AccessibilityConfig::UnsubscribeEnableAbilityListsObserver( const std::shared_ptr &observer) { - CHECK_IMPL_PTR() - pImpl_->UnsubscribeEnableAbilityListsObserver(observer); + CHECK_IMPL_PTR(Accessibility::RET_ERR_NULLPTR) + return pImpl_->UnsubscribeEnableAbilityListsObserver(observer); } -bool AccessibilityConfig::EnableAbility(const std::string &name, const uint32_t capabilities) +Accessibility::RetError AccessibilityConfig::EnableAbility(const std::string &name, const uint32_t capabilities) { - CHECK_IMPL_PTR(false) + CHECK_IMPL_PTR(Accessibility::RET_ERR_NULLPTR) return pImpl_->EnableAbility(name, capabilities); } -bool AccessibilityConfig::DisableAbility(const std::string &name) +Accessibility::RetError AccessibilityConfig::DisableAbility(const std::string &name) { - CHECK_IMPL_PTR(false) + CHECK_IMPL_PTR(Accessibility::RET_ERR_NULLPTR) return pImpl_->DisableAbility(name); } diff --git a/frameworks/acfwk/src/accessibility_config_impl.cpp b/frameworks/acfwk/src/accessibility_config_impl.cpp index ebfd97c2e..15306eaad 100644 --- a/frameworks/acfwk/src/accessibility_config_impl.cpp +++ b/frameworks/acfwk/src/accessibility_config_impl.cpp @@ -216,24 +216,24 @@ void AccessibilityConfig::Impl::ResetService(const wptr &remote) } } -bool AccessibilityConfig::Impl::EnableAbility(const std::string &name, const uint32_t capabilities) +Accessibility::RetError AccessibilityConfig::Impl::EnableAbility(const std::string &name, const uint32_t capabilities) { HILOG_INFO("name = [%{private}s] capabilities = [%{private}u]", name.c_str(), capabilities); std::lock_guard lock(mutex_); if (!serviceProxy_) { HILOG_ERROR("Failed to get accessibility service"); - return false; + return Accessibility::RET_ERR_SAMGR; } return serviceProxy_->EnableAbility(name, capabilities); } -bool AccessibilityConfig::Impl::DisableAbility(const std::string &name) +Accessibility::RetError AccessibilityConfig::Impl::DisableAbility(const std::string &name) { HILOG_INFO("name = [%{private}s]", name.c_str()); std::lock_guard lock(mutex_); if (!serviceProxy_) { HILOG_ERROR("Failed to get accessibility service"); - return false; + return Accessibility::RET_ERR_SAMGR; } return serviceProxy_->DisableAbility(name); } @@ -314,7 +314,7 @@ void AccessibilityConfig::Impl::NotifyCaptionChanged( } } -void AccessibilityConfig::Impl::SubscribeConfigObserver(const CONFIG_ID id, +Accessibility::RetError AccessibilityConfig::Impl::SubscribeConfigObserver(const CONFIG_ID id, const std::shared_ptr &observer, const bool retFlag) { HILOG_INFO("id = [%{public}d]", static_cast(id)); @@ -334,9 +334,10 @@ void AccessibilityConfig::Impl::SubscribeConfigObserver(const CONFIG_ID id, if (retFlag && observer) { NotifyImmediately(id, observer); } + return Accessibility::RET_OK; } -void AccessibilityConfig::Impl::UnsubscribeConfigObserver(const CONFIG_ID id, +Accessibility::RetError AccessibilityConfig::Impl::UnsubscribeConfigObserver(const CONFIG_ID id, const std::shared_ptr &observer) { HILOG_INFO("id = [%{public}d]", static_cast(id)); @@ -349,12 +350,13 @@ void AccessibilityConfig::Impl::UnsubscribeConfigObserver(const CONFIG_ID id, HILOG_DEBUG("erase observer"); it->second.erase(iter); HILOG_DEBUG("observer's size is %{public}zu", it->second.size()); - return; + return Accessibility::RET_OK; } } } else { HILOG_DEBUG("%{public}d has not subscribed ", id); } + return Accessibility::RET_OK; } void AccessibilityConfig::Impl::OnAccessibleAbilityManagerCaptionPropertyChanged(const CaptionProperty& property) @@ -1051,7 +1053,7 @@ Accessibility::RetError AccessibilityConfig::Impl::GetAudioBalance(float &balanc return ret; } -void AccessibilityConfig::Impl::SubscribeEnableAbilityListsObserver( +Accessibility::RetError AccessibilityConfig::Impl::SubscribeEnableAbilityListsObserver( const std::shared_ptr &observer) { HILOG_INFO(); @@ -1061,13 +1063,14 @@ void AccessibilityConfig::Impl::SubscribeEnableAbilityListsObserver( return listObserver == observer; })) { HILOG_ERROR("the observer is exist"); - return; + return Accessibility::RET_OK; } enableAbilityListsObservers_.push_back(observer); HILOG_DEBUG("observer's size is %{public}zu", enableAbilityListsObservers_.size()); + return Accessibility::RET_OK; } -void AccessibilityConfig::Impl::UnsubscribeEnableAbilityListsObserver( +Accessibility::RetError AccessibilityConfig::Impl::UnsubscribeEnableAbilityListsObserver( const std::shared_ptr &observer) { HILOG_INFO(); @@ -1077,9 +1080,10 @@ void AccessibilityConfig::Impl::UnsubscribeEnableAbilityListsObserver( HILOG_DEBUG("erase observer"); enableAbilityListsObservers_.erase(iter); HILOG_DEBUG("observer's size is %{public}zu", enableAbilityListsObservers_.size()); - return; + return Accessibility::RET_OK; } } + return Accessibility::RET_OK; } void AccessibilityConfig::Impl::OnAccessibilityEnableAbilityListsChanged() diff --git a/frameworks/acfwk/test/unittest/accessibility_config_impl_test.cpp b/frameworks/acfwk/test/unittest/accessibility_config_impl_test.cpp index 51386e822..d64704777 100644 --- a/frameworks/acfwk/test/unittest/accessibility_config_impl_test.cpp +++ b/frameworks/acfwk/test/unittest/accessibility_config_impl_test.cpp @@ -791,7 +791,6 @@ HWTEST_F(AccessibilityConfigImplTest, UnsubscribeEnableAbilityListsObserver_001, GTEST_LOG_(INFO) << "UnsubscribeEnableAbilityListsObserver_001 end"; } - /** * @tc.number: EnableAbility_001 * @tc.name: EnableAbility_001 @@ -804,7 +803,7 @@ HWTEST_F(AccessibilityConfigImplTest, EnableAbility_001, TestSize.Level1) std::string name = "test"; auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); instance.InitializeContext(); - EXPECT_TRUE(instance.EnableAbility(name, 0)); + EXPECT_EQ(Accessibility::RET_OK, instance.EnableAbility(name, 0)); sleep(1); GTEST_LOG_(INFO) << "EnableAbility_001 end"; } @@ -821,7 +820,7 @@ HWTEST_F(AccessibilityConfigImplTest, DisableAbility_001, TestSize.Level1) std::string name = "test"; auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); instance.InitializeContext(); - EXPECT_TRUE(instance.DisableAbility(name)); + EXPECT_EQ(Accessibility::RET_OK, instance.DisableAbility(name)); GTEST_LOG_(INFO) << "DisableAbility_001 end"; } } // namespace AccessibilityConfig diff --git a/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h b/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h index 34a892dc2..209ae10b7 100644 --- a/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h +++ b/frameworks/asacfwk/include/accessibility_system_ability_client_impl.h @@ -45,28 +45,31 @@ public: * @brief Register the element operator, so the AA can get node info from ACE. * @param windowId Window ID * @param operation The callback object. - * @return 0: Succeed ; otherwise is failed. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual int32_t RegisterElementOperator(const int32_t windowId, + virtual RetError RegisterElementOperator(const int32_t windowId, const std::shared_ptr &operation) override; /** * @brief Deregister the element operator. * @param windowId Window ID + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual void DeregisterElementOperator(const int32_t windowId) override; + virtual RetError DeregisterElementOperator(const int32_t windowId) override; /** * @brief Checks whether accessibility ability is enabled. - * @return true: enabled; false: disabled + * @param isEnabled true: enabled; false: disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool IsEnabled() override; + virtual RetError IsEnabled(bool &isEnabled) override; /** * @brief Checks whether touch exploration ability is enabled. - * @return true: enabled; false: disabled + * @param isEnabled true: enabled; false: disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool IsTouchExplorationEnabled() override; + virtual RetError IsTouchExplorationEnabled(bool &isEnabled) override; /** * @brief Queries the list of accessibility abilities. @@ -76,51 +79,51 @@ public: * 2 indicates that the ability is disabled; * 3 indicates that the ability has been installed. * @param infos accessibility ability infos by specified types. - * @return Return true if get ability lists successfully, else return false. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool GetAbilityList(const uint32_t accessibilityAbilityTypes, const AbilityStateType stateType, + virtual RetError GetAbilityList(const uint32_t accessibilityAbilityTypes, const AbilityStateType stateType, std::vector &infos) override; /** * @brief Sends an accessibility event. * @param eventType Identifies the accessibility event specified by AccessibilityEventInfo. * @param componentId Indicates the ID of the component to be associated with the event. - * @return true: send ok; otherwise is refused. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool SendEvent(const EventType eventType, const int32_t componentId) override; + virtual RetError SendEvent(const EventType eventType, const int32_t componentId) override; /** * @brief Sends information about an accessibility event. * @param event Indicates the accessibility event information specified by AccessibilityEventInfo. - * @return true: send ok; otherwise is refused. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool SendEvent(const AccessibilityEventInfo &event) override; + virtual RetError SendEvent(const AccessibilityEventInfo &event) override; /** * @brief Subscribes to the specified type of accessibility status change events. * @param observer Indicates the observer for listening to status events, which is specified * by AccessibilityStateObserver. * @param eventType Indicates the status type, which is specified by AccessibilityStateEventType. - * @return true: send ok; otherwise is refused. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool SubscribeStateObserver(const std::shared_ptr &observer, + virtual RetError SubscribeStateObserver(const std::shared_ptr &observer, const uint32_t eventType) override; /** * @brief Unsubscribe the specified type of accessibility status change events. * @param observer Indicates the registered accessibility status event observer. * @param eventType Indicates the status type, which is specified by AccessibilityStateEventType. - * @return true: send ok; otherwise is refused. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool UnsubscribeStateObserver(const std::shared_ptr &observer, + virtual RetError UnsubscribeStateObserver(const std::shared_ptr &observer, const uint32_t eventType) override; /** * @brief Get enabled abilities. * @param enabledAbilities The infos of enabled abilities. - * @return Return true if get enabled abilities successfully, else return false. + * @return Return RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool GetEnabledAbilities(std::vector &enabledAbilities) override; + virtual RetError GetEnabledAbilities(std::vector &enabledAbilities) override; /** * @brief Clean the AAMS object data. diff --git a/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp b/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp index 3639087df..e4d6d03e4 100644 --- a/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp +++ b/frameworks/asacfwk/src/accessibility_system_ability_client_impl.cpp @@ -42,6 +42,8 @@ std::shared_ptr AccessibilitySystemAbilityClie AccessibilitySystemAbilityClientImpl::AccessibilitySystemAbilityClientImpl() { + HILOG_DEBUG(); + stateArray_.fill(false); if (!ConnectToService()) { HILOG_ERROR("Failed to connect to aams service"); return; @@ -56,6 +58,7 @@ AccessibilitySystemAbilityClientImpl::~AccessibilitySystemAbilityClientImpl() bool AccessibilitySystemAbilityClientImpl::ConnectToService() { + HILOG_DEBUG(); if (serviceProxy_) { HILOG_DEBUG("AAMS Service is connected"); return true; @@ -131,70 +134,73 @@ void AccessibilitySystemAbilityClientImpl::ResetService(const wptr &operation) { HILOG_INFO("Register windowId[%{public}d] start", windowId); std::lock_guard lock(mutex_); if (!operation) { HILOG_ERROR("Input operation is null"); - return -1; + return RET_ERR_INVALID_PARAM; } if (!serviceProxy_) { HILOG_ERROR("Failed to get aams service"); - return -1; + return RET_ERR_SAMGR; } auto iter = elementOperators_.find(windowId); if (iter != elementOperators_.end()) { HILOG_ERROR("windowID[%{public}d] is exited", windowId); - return 0; + return RET_ERR_CONNECTION_EXIST; } sptr aamsInteractionOperator = new(std::nothrow) AccessibilityElementOperatorImpl(windowId, operation, *this); if (!aamsInteractionOperator) { HILOG_ERROR("Failed to create aamsInteractionOperator."); - return -1; + return RET_ERR_NULLPTR; } elementOperators_[windowId] = aamsInteractionOperator; - serviceProxy_->RegisterElementOperator(windowId, aamsInteractionOperator); - - return 0; + return serviceProxy_->RegisterElementOperator(windowId, aamsInteractionOperator); } -void AccessibilitySystemAbilityClientImpl::DeregisterElementOperator(const int32_t windowId) +RetError AccessibilitySystemAbilityClientImpl::DeregisterElementOperator(const int32_t windowId) { HILOG_INFO("Deregister windowId[%{public}d] start", windowId); std::lock_guard lock(mutex_); if (!serviceProxy_) { HILOG_ERROR("Failed to get aams service"); - return; + return RET_ERR_SAMGR; } - serviceProxy_->DeregisterElementOperator(windowId); auto iter = elementOperators_.find(windowId); if (iter != elementOperators_.end()) { HILOG_DEBUG("windowID[%{public}d] is erase", windowId); elementOperators_.erase(iter); - return; + } else { + HILOG_WARN("Not find windowID[%{public}d]", windowId); + return RET_ERR_NO_REGISTER; } - HILOG_DEBUG("Not find windowID[%{public}d]", windowId); + return serviceProxy_->DeregisterElementOperator(windowId); } -bool AccessibilitySystemAbilityClientImpl::IsEnabled() +RetError AccessibilitySystemAbilityClientImpl::IsEnabled(bool &isEnabled) { + HILOG_DEBUG(); std::lock_guard lock(mutex_); - return stateArray_[AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED]; + isEnabled = stateArray_[AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED]; + return RET_OK; } -bool AccessibilitySystemAbilityClientImpl::IsTouchExplorationEnabled() +RetError AccessibilitySystemAbilityClientImpl::IsTouchExplorationEnabled(bool &isEnabled) { + HILOG_DEBUG(); std::lock_guard lock(mutex_); - return stateArray_[AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED]; + isEnabled = stateArray_[AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED]; + return RET_OK; } -bool AccessibilitySystemAbilityClientImpl::GetAbilityList(const uint32_t accessibilityAbilityTypes, +RetError AccessibilitySystemAbilityClientImpl::GetAbilityList(const uint32_t accessibilityAbilityTypes, const AbilityStateType stateType, std::vector &infos) { HILOG_DEBUG(); @@ -213,11 +219,11 @@ bool AccessibilitySystemAbilityClientImpl::GetAbilityList(const uint32_t accessi if (!check) { HILOG_ERROR("Invalid params: accessibilityAbilityTypes[%{public}d] stateType[%{public}d]", accessibilityAbilityTypes, stateType); - return false; + return RET_ERR_INVALID_PARAM; } if (!serviceProxy_) { HILOG_ERROR("Failed to get aams service"); - return false; + return RET_ERR_SAMGR; } return serviceProxy_->GetAbilityList(accessibilityAbilityTypes, stateType, infos); } @@ -233,87 +239,85 @@ bool AccessibilitySystemAbilityClientImpl::CheckEventType(EventType eventType) } } -bool AccessibilitySystemAbilityClientImpl::SendEvent(const EventType eventType, const int32_t componentId) +RetError AccessibilitySystemAbilityClientImpl::SendEvent(const EventType eventType, const int32_t componentId) { HILOG_DEBUG("componentId[%{public}d], eventType[%{public}d]", componentId, eventType); std::lock_guard lock(mutex_); if (!CheckEventType(eventType)) { - return false; + return RET_ERR_INVALID_PARAM; } AccessibilityEventInfo event; event.SetEventType(eventType); event.SetSource(componentId); if (!serviceProxy_) { HILOG_ERROR("Failed to get aams service"); - return false; + return RET_ERR_SAMGR; } - serviceProxy_->SendEvent(event); - return true; + return serviceProxy_->SendEvent(event); } -bool AccessibilitySystemAbilityClientImpl::SendEvent(const AccessibilityEventInfo &event) +RetError AccessibilitySystemAbilityClientImpl::SendEvent(const AccessibilityEventInfo &event) { HILOG_DEBUG("EventType[%{public}d]", event.GetEventType()); std::lock_guard lock(mutex_); if (!CheckEventType(event.GetEventType())) { - return false; + return RET_ERR_INVALID_PARAM; } if (!serviceProxy_) { HILOG_ERROR("Failed to get aams service"); - return false; + return RET_ERR_SAMGR; } - serviceProxy_->SendEvent(event); - return true; + return serviceProxy_->SendEvent(event); } -bool AccessibilitySystemAbilityClientImpl::SubscribeStateObserver( +RetError AccessibilitySystemAbilityClientImpl::SubscribeStateObserver( const std::shared_ptr &observer, const uint32_t eventType) { HILOG_DEBUG(); std::lock_guard lock(mutex_); if (eventType >= AccessibilityStateEventType::EVENT_TYPE_MAX) { HILOG_ERROR("Input eventType is out of scope"); - return false; + return RET_ERR_INVALID_PARAM; } if (!observer) { HILOG_ERROR("Input observer is null"); - return false; + return RET_ERR_INVALID_PARAM; } StateObserverVector &observerVector = stateObserversArray_[eventType]; for (auto iter = observerVector.begin(); iter != observerVector.end(); ++iter) { if (*iter == observer) { HILOG_INFO("Observer has subscribed!"); - return true; + return RET_ERR_REGISTER_EXIST; } } observerVector.push_back(observer); - return true; + return RET_OK; } -bool AccessibilitySystemAbilityClientImpl::UnsubscribeStateObserver( +RetError AccessibilitySystemAbilityClientImpl::UnsubscribeStateObserver( const std::shared_ptr &observer, const uint32_t eventType) { HILOG_DEBUG("eventType is [%{public}d]", eventType); std::lock_guard lock(mutex_); if (eventType >= AccessibilityStateEventType::EVENT_TYPE_MAX) { HILOG_ERROR("Input eventType is out of scope"); - return false; + return RET_ERR_INVALID_PARAM; } if (!observer) { HILOG_ERROR("Input observer is null"); - return false; + return RET_ERR_INVALID_PARAM; } StateObserverVector &observerVector = stateObserversArray_[eventType]; for (auto iter = observerVector.begin(); iter != observerVector.end(); ++iter) { if (*iter == observer) { observerVector.erase(iter); - return true; + return RET_OK; } } HILOG_ERROR("The observer has not subscribed."); - return false; + return RET_ERR_NO_REGISTER; } void AccessibilitySystemAbilityClientImpl::NotifyStateChanged(uint32_t eventType, bool value) @@ -341,13 +345,13 @@ void AccessibilitySystemAbilityClientImpl::NotifyStateChanged(uint32_t eventType HILOG_DEBUG("end"); } -bool AccessibilitySystemAbilityClientImpl::GetEnabledAbilities(std::vector &enabledAbilities) +RetError AccessibilitySystemAbilityClientImpl::GetEnabledAbilities(std::vector &enabledAbilities) { HILOG_DEBUG(); std::lock_guard lock(mutex_); if (!serviceProxy_) { HILOG_ERROR("Failed to get aams service"); - return false; + return RET_ERR_SAMGR; } return serviceProxy_->GetEnabledAbilities(enabledAbilities); } diff --git a/frameworks/asacfwk/test/unittest/accessibility_system_ability_client_impl_test.cpp b/frameworks/asacfwk/test/unittest/accessibility_system_ability_client_impl_test.cpp index bf6c033a7..d75b9668b 100644 --- a/frameworks/asacfwk/test/unittest/accessibility_system_ability_client_impl_test.cpp +++ b/frameworks/asacfwk/test/unittest/accessibility_system_ability_client_impl_test.cpp @@ -71,7 +71,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, RegisterElementOperator_001, GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - EXPECT_EQ(-1, impl_->RegisterElementOperator(WINDOW_ID, nullptr)); + EXPECT_EQ(RET_ERR_INVALID_PARAM, impl_->RegisterElementOperator(WINDOW_ID, nullptr)); impl_ = nullptr; GTEST_LOG_(INFO) << "RegisterElementOperator_001 end"; } @@ -90,7 +90,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, RegisterElementOperator_002, return; } std::shared_ptr mockOperator = std::make_shared(); - EXPECT_EQ(-1, impl_->RegisterElementOperator(WINDOW_ID, mockOperator)); + EXPECT_EQ(RET_ERR_SAMGR, impl_->RegisterElementOperator(WINDOW_ID, mockOperator)); impl_ = nullptr; GTEST_LOG_(INFO) << "RegisterElementOperator_002 end"; } @@ -111,7 +111,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, RegisterElementOperator_003, return; } std::shared_ptr mockOperator = std::make_shared(); - EXPECT_EQ(0, impl_->RegisterElementOperator(WINDOW_ID, mockOperator)); + EXPECT_EQ(RET_OK, impl_->RegisterElementOperator(WINDOW_ID, mockOperator)); impl_ = nullptr; GTEST_LOG_(INFO) << "RegisterElementOperator_003 end"; } @@ -132,8 +132,8 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, RegisterElementOperator_004, return; } std::shared_ptr mockOperator = std::make_shared(); - EXPECT_EQ(0, impl_->RegisterElementOperator(WINDOW_ID, mockOperator)); - EXPECT_EQ(0, impl_->RegisterElementOperator(WINDOW_ID, mockOperator)); + EXPECT_EQ(RET_OK, impl_->RegisterElementOperator(WINDOW_ID, mockOperator)); + EXPECT_EQ(RET_ERR_CONNECTION_EXIST, impl_->RegisterElementOperator(WINDOW_ID, mockOperator)); impl_ = nullptr; GTEST_LOG_(INFO) << "RegisterElementOperator_004 end"; } @@ -151,7 +151,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, DeregisterElementOperator_001 GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - impl_->DeregisterElementOperator(WINDOW_ID); + EXPECT_EQ(RET_ERR_SAMGR, impl_->DeregisterElementOperator(WINDOW_ID)); impl_ = nullptr; GTEST_LOG_(INFO) << "DeregisterElementOperator_001 end"; } @@ -172,8 +172,8 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, DeregisterElementOperator_002 return; } std::shared_ptr mockOperator = std::make_shared(); - EXPECT_EQ(0, impl_->RegisterElementOperator(WINDOW_ID, mockOperator)); - impl_->DeregisterElementOperator(WINDOW_ID); + EXPECT_EQ(RET_OK, impl_->RegisterElementOperator(WINDOW_ID, mockOperator)); + EXPECT_EQ(RET_OK, impl_->DeregisterElementOperator(WINDOW_ID)); impl_ = nullptr; GTEST_LOG_(INFO) << "DeregisterElementOperator_002 end"; } @@ -193,7 +193,8 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, GetAbilityList_001, TestSize. } std::vector infos {}; - EXPECT_FALSE(impl_->GetAbilityList(ACCESSIBILITY_ABILITY_TYPE_ALL, ABILITY_STATE_INVALID, infos)); + auto ret = impl_->GetAbilityList(ACCESSIBILITY_ABILITY_TYPE_ALL, ABILITY_STATE_INVALID, infos); + EXPECT_EQ(RET_ERR_INVALID_PARAM, ret); impl_ = nullptr; GTEST_LOG_(INFO) << "GetAbilityList_001 end"; } @@ -213,7 +214,8 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, GetAbilityList_002, TestSize. } std::vector infos {}; - EXPECT_FALSE(impl_->GetAbilityList(ACCESSIBILITY_ABILITY_TYPE_ALL, ABILITY_STATE_ENABLE, infos)); + auto ret = impl_->GetAbilityList(ACCESSIBILITY_ABILITY_TYPE_ALL, ABILITY_STATE_ENABLE, infos); + EXPECT_EQ(RET_ERR_SAMGR, ret); impl_ = nullptr; GTEST_LOG_(INFO) << "GetAbilityList_002 end"; } @@ -235,7 +237,8 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, GetAbilityList_003, TestSize. } std::vector infos {}; - EXPECT_TRUE(impl_->GetAbilityList(ACCESSIBILITY_ABILITY_TYPE_ALL, ABILITY_STATE_ENABLE, infos)); + auto ret = impl_->GetAbilityList(ACCESSIBILITY_ABILITY_TYPE_ALL, ABILITY_STATE_ENABLE, infos); + EXPECT_EQ(RET_OK, ret); impl_ = nullptr; GTEST_LOG_(INFO) << "GetAbilityList_003 end"; } @@ -253,7 +256,9 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, IsEnabled_001, TestSize.Level GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - EXPECT_FALSE(impl_->IsEnabled()); + bool isEnable = false; + impl_->IsEnabled(isEnable); + EXPECT_FALSE(isEnable); impl_ = nullptr; GTEST_LOG_(INFO) << "IsEnabled_001 end"; } @@ -271,7 +276,9 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, IsTouchExplorationEnabled_001 GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - EXPECT_FALSE(impl_->IsTouchExplorationEnabled()); + bool isEnable = false; + impl_->IsTouchExplorationEnabled(isEnable); + EXPECT_FALSE(isEnable); impl_ = nullptr; GTEST_LOG_(INFO) << "IsTouchExplorationEnabled_001 end"; } @@ -289,7 +296,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, SendEvent_001, TestSize.Level GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - EXPECT_FALSE(impl_->SendEvent(TYPE_VIEW_LONG_CLICKED_EVENT, COMPONENT_ID)); + EXPECT_EQ(RET_ERR_SAMGR, impl_->SendEvent(TYPE_VIEW_LONG_CLICKED_EVENT, COMPONENT_ID)); impl_ = nullptr; GTEST_LOG_(INFO) << "SendEvent_001 end"; } @@ -307,7 +314,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, SendEvent_002, TestSize.Level GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - EXPECT_FALSE(impl_->SendEvent(TYPE_VIEW_INVALID, COMPONENT_ID)); + EXPECT_EQ(RET_ERR_INVALID_PARAM, impl_->SendEvent(TYPE_VIEW_INVALID, COMPONENT_ID)); impl_ = nullptr; GTEST_LOG_(INFO) << "SendEvent_002 end"; } @@ -327,7 +334,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, SendEvent_003, TestSize.Level GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - EXPECT_TRUE(impl_->SendEvent(TYPE_VIEW_LONG_CLICKED_EVENT, COMPONENT_ID)); + EXPECT_EQ(RET_OK, impl_->SendEvent(TYPE_VIEW_LONG_CLICKED_EVENT, COMPONENT_ID)); impl_ = nullptr; GTEST_LOG_(INFO) << "SendEvent_003 end"; } @@ -347,7 +354,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, SendEvent_004, TestSize.Level } AccessibilityEventInfo event {}; event.SetEventType(TYPE_VIEW_LONG_CLICKED_EVENT); - EXPECT_FALSE(impl_->SendEvent(event)); + EXPECT_EQ(RET_ERR_SAMGR, impl_->SendEvent(event)); impl_ = nullptr; GTEST_LOG_(INFO) << "SendEvent_004 end"; } @@ -367,7 +374,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, SendEvent_005, TestSize.Level } AccessibilityEventInfo event {}; event.SetEventType(TYPE_VIEW_INVALID); - EXPECT_FALSE(impl_->SendEvent(event)); + EXPECT_EQ(RET_ERR_INVALID_PARAM, impl_->SendEvent(event)); impl_ = nullptr; GTEST_LOG_(INFO) << "SendEvent_005 end"; } @@ -389,7 +396,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, SendEvent_006, TestSize.Level } AccessibilityEventInfo event {}; event.SetEventType(TYPE_VIEW_LONG_CLICKED_EVENT); - EXPECT_TRUE(impl_->SendEvent(event)); + EXPECT_EQ(RET_OK, impl_->SendEvent(event)); impl_ = nullptr; GTEST_LOG_(INFO) << "SendEvent_006 end"; } @@ -407,7 +414,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, SubscribeStateObserver_001, T GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - EXPECT_FALSE(impl_->SubscribeStateObserver(nullptr, EVENT_TOUCH_GUIDE_STATE_CHANGED)); + EXPECT_EQ(RET_ERR_INVALID_PARAM, impl_->SubscribeStateObserver(nullptr, EVENT_TOUCH_GUIDE_STATE_CHANGED)); impl_ = nullptr; GTEST_LOG_(INFO) << "SubscribeStateObserver_001 end"; } @@ -425,7 +432,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, SubscribeStateObserver_002, T GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - EXPECT_FALSE(impl_->SubscribeStateObserver(nullptr, EVENT_TYPE_MAX)); + EXPECT_EQ(RET_ERR_INVALID_PARAM, impl_->SubscribeStateObserver(nullptr, EVENT_TYPE_MAX)); impl_ = nullptr; GTEST_LOG_(INFO) << "SubscribeStateObserver_002 end"; } @@ -443,7 +450,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, UnsubscribeStateObserver_001, GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - EXPECT_FALSE(impl_->UnsubscribeStateObserver(nullptr, EVENT_TYPE_MAX)); + EXPECT_EQ(RET_ERR_INVALID_PARAM, impl_->UnsubscribeStateObserver(nullptr, EVENT_TYPE_MAX)); impl_ = nullptr; GTEST_LOG_(INFO) << "UnsubscribeStateObserver_001 end"; } @@ -461,7 +468,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, UnsubscribeStateObserver_002, GTEST_LOG_(INFO) << "Cann't get AccessibilitySystemAbilityClientImpl impl_"; return; } - EXPECT_FALSE(impl_->UnsubscribeStateObserver(nullptr, EVENT_KEVEVENT_STATE_CHANGED)); + EXPECT_EQ(RET_ERR_INVALID_PARAM, impl_->UnsubscribeStateObserver(nullptr, EVENT_KEVEVENT_STATE_CHANGED)); impl_ = nullptr; GTEST_LOG_(INFO) << "UnsubscribeStateObserver_002 end"; } @@ -538,7 +545,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, GetEnabledAbilities_001, Test return; } std::vector enabledAbilities; - EXPECT_FALSE(impl_->GetEnabledAbilities(enabledAbilities)); + EXPECT_EQ(RET_ERR_SAMGR, impl_->GetEnabledAbilities(enabledAbilities)); impl_ = nullptr; GTEST_LOG_(INFO) << "GetEnabledAbilities_001 end"; } @@ -559,7 +566,7 @@ HWTEST_F(AccessibilitySystemAbilityClientImplTest, GetEnabledAbilities_002, Test return; } std::vector enabledAbilities; - EXPECT_TRUE(impl_->GetEnabledAbilities(enabledAbilities)); + EXPECT_EQ(RET_OK, impl_->GetEnabledAbilities(enabledAbilities)); impl_ = nullptr; GTEST_LOG_(INFO) << "GetEnabledAbilities_002 end"; } diff --git a/frameworks/common/src/accessibility_window_info.cpp b/frameworks/common/src/accessibility_window_info.cpp index a1f1653ed..94de4942a 100644 --- a/frameworks/common/src/accessibility_window_info.cpp +++ b/frameworks/common/src/accessibility_window_info.cpp @@ -72,14 +72,14 @@ void AccessibilityWindowInfo::SetRectInScreen(const Rect &bounds) bool AccessibilityWindowInfo::IsActive() const { - HILOG_DEBUG("active_[%{public}d]", active_); + HILOG_DEBUG("active_[%{public}d] windowId_[%{public}d]", active_, windowId_); return active_; } void AccessibilityWindowInfo::SetActive(bool active) { active_ = active; - HILOG_DEBUG("active_[%{public}d]", active_); + HILOG_DEBUG("active_[%{public}d] windowId_[%{public}d]", active_, windowId_); } bool AccessibilityWindowInfo::IsFocused() const diff --git a/interfaces/innerkits/aafwk/include/accessibility_ui_test_ability.h b/interfaces/innerkits/aafwk/include/accessibility_ui_test_ability.h index fd4753f31..82d43812f 100644 --- a/interfaces/innerkits/aafwk/include/accessibility_ui_test_ability.h +++ b/interfaces/innerkits/aafwk/include/accessibility_ui_test_ability.h @@ -40,94 +40,96 @@ public: /** * @brief Register ability listener. * @param listener The listener to add. - * @return Return true if registers listener successfully, else return false. + * @return Return RET_OK if registers listener successfully, otherwise refer to the RetError for the failure. */ - virtual bool RegisterAbilityListener(const std::shared_ptr &listener) = 0; + virtual RetError RegisterAbilityListener(const std::shared_ptr &listener) = 0; /** * @brief Connect to AAMS. For UI test. - * @return Return RET_OK if the command of connection is sent successfully. + * @return Return RET_OK if the command of connection is sent successfully, + * otherwise refer to the RetError for the failure. */ virtual RetError Connect() = 0; /** * @brief disconnect to AAMS. For UI test. - * @return Return true if the command of disconnect is sent successfully, else return false. + * @return Return RET_OK if the command of disconnect is sent successfully, + * otherwise refer to the RetError for the failure. */ - virtual bool Disconnect() = 0; + virtual RetError Disconnect() = 0; /** * @brief Obtains elementInfo of focus. * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. * @param elementInfo The accessibilityElementInfo of focus. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) = 0; + virtual RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) = 0; /** * @brief Obtains elementInfo of focus. * @param sourceInfo The source info to get focus. * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. * @param elementInfo The accessibilityElementInfo of focus. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, + virtual RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo) = 0; /** * @brief Sends simulate gestures to the screen. * @param gesturePath The gesture which need to send. - * @return Return true if the gesture sends successfully, else return false. + * @return Return RET_OK if the gesture sends successfully, otherwise refer to the RetError for the failure. */ - virtual bool InjectGesture(const std::shared_ptr &gesturePath) = 0; + virtual RetError InjectGesture(const std::shared_ptr &gesturePath) = 0; /** * @brief Obtains elementInfo of the accessible root node. * @param elementInfo The elementInfo of the accessible root node. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetRoot(AccessibilityElementInfo &elementInfo) = 0; + virtual RetError GetRoot(AccessibilityElementInfo &elementInfo) = 0; /** * @brief Obtains elementInfo of the accessible root node. * @param windowInfo The source window info to get root. * @param elementInfo The elementInfo of the accessible root node. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetRootByWindow(const AccessibilityWindowInfo &windowInfo, + virtual RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo) = 0; /** * @brief Get the window information related with the event * @param windowId The window id. * @param windowInfo The window information. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) = 0; + virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) = 0; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindows(std::vector &windows) = 0; + virtual RetError GetWindows(std::vector &windows) = 0; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param displayId the id of display * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindows(const uint64_t displayId, std::vector &windows) = 0; + virtual RetError GetWindows(const uint64_t displayId, std::vector &windows) = 0; /** * @brief Gets the next focused node in the specified direction of the currently focused node. * @param elementInfo The source info to get next info. * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection * @param nextElementInfo The info of next element. - * @return Return true if gets next elementInfo successfully, else return false. + * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, + virtual RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo) = 0; /** @@ -135,18 +137,18 @@ public: * @param index The index of the child. * @param parent The parent info to get child. * @param child The element info of child. - * @return Return true if gets child elementInfo successfully, else return false. + * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, + virtual RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, AccessibilityElementInfo &child) = 0; /** * @brief Get the children node information * @param parent The parent info to get children. * @param children The element info of children. - * @return Return true if gets children elementInfo successfully, else return false. + * @return Return RET_OK if gets children elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetChildren(const AccessibilityElementInfo &parent, + virtual RetError GetChildren(const AccessibilityElementInfo &parent, std::vector &children) = 0; /** @@ -154,26 +156,26 @@ public: * @param elementInfo The source info. * @param text specified content * @param elementInfos The element infos of specified content. - * @return Return true if gets elementInfos successfully, else return false. + * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, + virtual RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, std::vector &elementInfos) = 0; /** * @brief Get the node information related with the event * @param eventInfo The source info to get source. * @param elementInfo The element info of source. - * @return Return true if gets elementInfos successfully, else return false. + * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) = 0; + virtual RetError GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) = 0; /** * @brief Get Parent node information * @param child The child element info to get parent. * @param parent The parent element info. - * @return Return true if gets info successfully, else return false. + * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) = 0; + virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) = 0; /** * @brief Executes a specified action. @@ -193,17 +195,17 @@ public: * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) * action: ACCESSIBILITY_ACTION_SET_TEXT, * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") - * @return true Perform action succeed, otherwise is not. + * @return Return RET_OK if performs action successfully, otherwise refer to the RetError for the failure. */ - virtual bool ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, + virtual RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, const std::map &actionArguments) = 0; /** * @brief Set target bundle names. * @param targetBundleNames The target bundle name - * @return Return true if sets target bundle names successfully, else return false. + * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. */ - virtual bool SetTargetBundleName(const std::vector &targetBundleNames) = 0; + virtual RetError SetTargetBundleName(const std::vector &targetBundleNames) = 0; /** * @brief Set cache mode. @@ -214,9 +216,10 @@ public: * PREFETCH_SIBLINGS: cache the sister/brothers node info also. * PREFETCH_CHILDREN: cache the child node info also. * otherwise: no cache. + * @return Return RET_OK if sets cache mode successfully, otherwise refer to the RetError for the failure. */ - virtual void SetCacheMode(const int32_t cacheMode) = 0; + virtual RetError SetCacheMode(const int32_t cacheMode) = 0; }; } // namespace Accessibility } // namespace OHOS -#endif // ACCESSIBILITY_UI_TEST_ABILITY_H +#endif // ACCESSIBILITY_UI_TEST_ABILITY_H \ No newline at end of file diff --git a/interfaces/innerkits/aafwk/include/accessible_ability_client.h b/interfaces/innerkits/aafwk/include/accessible_ability_client.h index 74749d098..b43a63716 100644 --- a/interfaces/innerkits/aafwk/include/accessible_ability_client.h +++ b/interfaces/innerkits/aafwk/include/accessible_ability_client.h @@ -50,74 +50,74 @@ public: * @brief Obtains elementInfo of focus. * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. * @param elementInfo The accessibilityElementInfo of focus. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) = 0; + virtual RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) = 0; /** * @brief Obtains elementInfo of focus. * @param sourceInfo The source info to get focus. * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. * @param elementInfo The accessibilityElementInfo of focus. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, + virtual RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo) = 0; /** * @brief Sends simulate gestures to the screen. * @param gesturePath The gesture which need to send. - * @return Return true if the gesture sends successfully, else return false. + * @return Return RET_OK if the gesture sends successfully, otherwise refer to the RetError for the failure. */ - virtual bool InjectGesture(const std::shared_ptr &gesturePath) = 0; + virtual RetError InjectGesture(const std::shared_ptr &gesturePath) = 0; /** * @brief Obtains elementInfo of the accessible root node. * @param elementInfo The elementInfo of the accessible root node. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetRoot(AccessibilityElementInfo &elementInfo) = 0; + virtual RetError GetRoot(AccessibilityElementInfo &elementInfo) = 0; /** * @brief Obtains elementInfo of the accessible root node. * @param windowInfo The source window info to get root. * @param elementInfo The elementInfo of the accessible root node. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetRootByWindow(const AccessibilityWindowInfo &windowInfo, + virtual RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo) = 0; /** * @brief Get the window information related with the event * @param windowId The window id. * @param windowInfo The window information. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) = 0; + virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) = 0; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindows(std::vector &windows) = 0; + virtual RetError GetWindows(std::vector &windows) = 0; /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param displayId the id of display * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetWindows(const uint64_t displayId, std::vector &windows) = 0; + virtual RetError GetWindows(const uint64_t displayId, std::vector &windows) = 0; /** * @brief Gets the next focused node in the specified direction of the currently focused node. * @param elementInfo The source info to get next info. * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection * @param nextElementInfo The info of next element. - * @return Return true if gets next elementInfo successfully, else return false. + * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, + virtual RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo) = 0; /** @@ -125,18 +125,18 @@ public: * @param index The index of the child. * @param parent The parent info to get child. * @param child The element info of child. - * @return Return true if gets child elementInfo successfully, else return false. + * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, + virtual RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, AccessibilityElementInfo &child) = 0; /** * @brief Get the children node information * @param parent The parent info to get children. * @param children The element info of children. - * @return Return true if gets children elementInfo successfully, else return false. + * @return Return RET_OK if gets children elementInfo successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetChildren(const AccessibilityElementInfo &parent, + virtual RetError GetChildren(const AccessibilityElementInfo &parent, std::vector &children) = 0; /** @@ -144,26 +144,26 @@ public: * @param elementInfo The source info. * @param text specified content * @param elementInfos The element infos of specified content. - * @return Return true if gets elementInfos successfully, else return false. + * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, + virtual RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, std::vector &elementInfos) = 0; /** * @brief Get the node information related with the event * @param eventInfo The source info to get source. * @param elementInfo The element info of source. - * @return Return true if gets elementInfos successfully, else return false. + * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) = 0; + virtual RetError GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) = 0; /** * @brief Get Parent node information * @param child The child element info to get parent. * @param parent The parent element info. - * @return Return true if gets info successfully, else return false. + * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. */ - virtual bool GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) = 0; + virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) = 0; /** * @brief Executes a specified action. @@ -183,24 +183,24 @@ public: * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) * action: ACCESSIBILITY_ACTION_SET_TEXT, * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") - * @return true Perform action succeed, otherwise is not. + * @return Return RET_OK if performs action succeed, otherwise refer to the RetError for the failure. */ - virtual bool ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, + virtual RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, const std::map &actionArguments) = 0; /** * @brief Register ability listener. * @param listener The listener to add. - * @return Return true if registers listener successfully, else return false. + * @return Return RET_OK if registers listener successfully, otherwise refer to the RetError for the failure. */ - virtual bool RegisterAbilityListener(const std::shared_ptr &listener) = 0; + virtual RetError RegisterAbilityListener(const std::shared_ptr &listener) = 0; /** * @brief Set target bundle names. * @param targetBundleNames The target bundle name - * @return Return true if sets target bundle names successfully, else return false. + * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. */ - virtual bool SetTargetBundleName(const std::vector &targetBundleNames) = 0; + virtual RetError SetTargetBundleName(const std::vector &targetBundleNames) = 0; /** * @brief Set cache mode. @@ -211,9 +211,10 @@ public: * PREFETCH_SIBLINGS: cache the sister/brothers node info also. * PREFETCH_CHILDREN: cache the child node info also. * otherwise: no cache. + * @return Return RET_OK if sets cache mode successfully, otherwise refer to the RetError for the failure. */ - virtual void SetCacheMode(const int32_t cacheMode) = 0; + virtual RetError SetCacheMode(const int32_t cacheMode) = 0; }; } // namespace Accessibility } // namespace OHOS -#endif // ACCESSIBLE_ABILITY_CLIENT_H +#endif // ACCESSIBLE_ABILITY_CLIENT_H \ No newline at end of file diff --git a/interfaces/innerkits/acfwk/include/accessibility_config.h b/interfaces/innerkits/acfwk/include/accessibility_config.h index 135d44156..b4a0fca8f 100644 --- a/interfaces/innerkits/acfwk/include/accessibility_config.h +++ b/interfaces/innerkits/acfwk/include/accessibility_config.h @@ -107,181 +107,209 @@ public: * @brief Subscribes to accessibility config value. * @param id the config id which is observed. * @param observer Indicates the observer for listening to accessibility + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - void SubscribeConfigObserver(const CONFIG_ID id, const std::shared_ptr &observer, - const bool retFlag = true); + Accessibility::RetError SubscribeConfigObserver(const CONFIG_ID id, + const std::shared_ptr &observer, const bool retFlag = true); /** * @brief Unsubscribe the accessibility config value observer. * @param id the id which is observed. * @param observer Indicates the registered accessibility config observer. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - void UnsubscribeConfigObserver(const CONFIG_ID id, const std::shared_ptr &observer); + Accessibility::RetError UnsubscribeConfigObserver(const CONFIG_ID id, + const std::shared_ptr &observer); /** * @brief Subscribes the observer of enable Ability lists * @param observer Indicates the observer for listening to enable Ability lists + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - void SubscribeEnableAbilityListsObserver( + Accessibility::RetError SubscribeEnableAbilityListsObserver( const std::shared_ptr &observer); /** * @brief Unsubscribe the observer of enable Ability lists * @param observer Indicates the observer for listening to enable Ability lists + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - void UnsubscribeEnableAbilityListsObserver( + Accessibility::RetError UnsubscribeEnableAbilityListsObserver( const std::shared_ptr &observer); /** * @brief Enabled specified abilities * @param name The string formatted by 'bundleName/abilityName'. * @param capabilities The capabilities you permit. - * @return Return true if the command is sent successfully, else return false. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - bool EnableAbility(const std::string &name, const uint32_t capabilities); + Accessibility::RetError EnableAbility(const std::string &name, const uint32_t capabilities); /** * @brief Disabled specified ability * @param name The string formatted by 'bundleName/abilityName'. - * @return Return true if the command is sent successfully, else return false. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - bool DisableAbility(const std::string &name); + Accessibility::RetError DisableAbility(const std::string &name); /** * @brief Set whether to enable the magnification function * @param state true:enable magnification function; false:disable magnification function + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetScreenMagnificationState(const bool state); /** * @brief Set whether to enable the function of using short key to open accessibility ability * @param state true:enable short key function; false:disable short key function + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetShortKeyState(const bool state); /** * @brief Set whether to enable the mouse key function * @param state true:enable mouse key function; false:disable mouse key function + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetMouseKeyState(const bool state); /** * @brief Set whether to enable the caption function * @param state true:enable caption function; false:disable caption function + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetCaptionsState(const bool state); /** * @brief Set caption properties * @param caption caption properties + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetCaptionsProperty(const CaptionProperty &caption); /** * @brief Set the time for the cursor to stop for the mouse to automatically perform the click action * @param time The valid time is 1000ms~5000ms, otherwise the automatic mouse click action will not be enabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetMouseAutoClick(const int32_t time); /** * @brief Set the name of the accessibility ability to be opened by the short key * @param name name The string formatted by 'bundleName/abilityName' + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetShortkeyTarget(const std::string &name); /** * @brief Set whether to enable the high-contrast text function * @param state true:enable high-contrast text function; false:disable high-contrast text function + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetHighContrastTextState(bool state); /** * @brief Set whether to enable the invert color function * @param state true:enable invert color function; false:disable invert color function + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetInvertColorState(const bool state); /** * @brief Set daltonization color filter * @param type Daltonization color filter type + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetDaltonizationColorFilter(const DALTONIZATION_TYPE type); /** * @brief Set content duration * @param timer duration + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetContentTimeout(const uint32_t timer); /** * @brief Set whether to turn off animation * @param state true:turn off animation; false:turn on animation + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetAnimationOffState(const bool state); /** * @brief Set brightness discount * @param brightness The discount of brightness + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetBrightnessDiscount(const float brightness); /** * @brief Set whether to enable audio mono * @param state true:enable audio mono; false:disable audio mono + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetAudioMonoState(const bool state); /** * @brief Set audio balance * @param balance The balance of audio + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError SetAudioBalance(const float balance); /** * @brief Get the status of whether the magnification function is enabled * @param state(out) true:the magnification function is enabled; false:the magnification function is disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetScreenMagnificationState(bool &state) const; /** * @brief Get the status of whether the use of short key to open accessibility ability is enabled * @param state(out) true:the short key is enabled; false:the short key is disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetShortKeyState(bool &state) const; /** * @brief Get the status of whether the mouse key function is enabled * @param state(out) true:the mouse key function is enabled; false:the mouse key function is disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetMouseKeyState(bool &state) const; /** * @brief Get the status of whether the caption function is enabled * @param state(out) true:the caption function is enabled; false:the caption function is disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetCaptionsState(bool &state) const; /** * @brief Get caption properties * @param caption(out) caption properties + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetCaptionsProperty(CaptionProperty &caption) const; /** * @brief Get the time for the cursor to stop for the mouse to automatically perform the click action * @param time(out) the time for the cursor to stop for the mouse to automatically perform the click action + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetMouseAutoClick(int32_t &time) const; /** * @brief Get the name of the accessibility ability to be opened by the short key * @param name(out) The string formatted by 'bundleName/abilityName' + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetShortkeyTarget(std::string &name) const; /** * @brief Get the status of whether the invert color function is enabled * @param state(out) true:the invert color function is enabled; false:the invert color function is disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetInvertColorState(bool &state) const; @@ -289,42 +317,49 @@ public: * @brief Get the status of whether the high-contrast text function is enabled * @param state(out) true:the high-contrast text function is enabled; * false:the high-contrast text function is disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetHighContrastTextState(bool &state) const; /** * @brief Get daltonization color filter * @param type(out) Daltonization color filter type + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetDaltonizationColorFilter(DALTONIZATION_TYPE &type) const; /** * @brief Get content duration * @param timer(out) duration + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetContentTimeout(uint32_t &timer) const; /** * @brief Get the status of whether animation is disabled * @param state(out) true:animation is disabled; false:animation is enabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetAnimationOffState(bool &state) const; /** * @brief Get brightness discount parameter * @param brightness(out) The discount parameter of brightness + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetBrightnessDiscount(float &brightness) const; /** * @brief Get the status of whether the audio mono is enabled * @param state(out) true:audio mono is enabled; false:audio mono is disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetAudioMonoState(bool &state) const; /** * @brief Get the value of the audio balance * @param balance(out) The value of the audio balance + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ Accessibility::RetError GetAudioBalance(float &balance) const; diff --git a/interfaces/innerkits/asacfwk/include/accessibility_system_ability_client.h b/interfaces/innerkits/asacfwk/include/accessibility_system_ability_client.h index 0807864f8..023f1cfc2 100644 --- a/interfaces/innerkits/asacfwk/include/accessibility_system_ability_client.h +++ b/interfaces/innerkits/asacfwk/include/accessibility_system_ability_client.h @@ -55,28 +55,31 @@ public: * @brief Register the element operator, so the AA can get node info from ACE. * @param windowId Window ID * @param operation The callback object. - * @return 0: Succeed ; otherwise is failed. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual int32_t RegisterElementOperator(const int32_t windowId, + virtual RetError RegisterElementOperator(const int32_t windowId, const std::shared_ptr &operation) = 0; /** * @brief Deregister the element operator. * @param windowId Window ID + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual void DeregisterElementOperator(const int32_t windowId) = 0; + virtual RetError DeregisterElementOperator(const int32_t windowId) = 0; /** * @brief Checks whether accessibility ability is enabled. - * @return true: enabled; false: disabled + * @param isEnabled true: enabled; false: disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool IsEnabled() = 0; + virtual RetError IsEnabled(bool &isEnabled)= 0; /** * @brief Checks whether touch exploration ability is enabled. - * @return true: enabled; false: disabled + * @param isEnabled true: enabled; false: disabled + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool IsTouchExplorationEnabled() = 0; + virtual RetError IsTouchExplorationEnabled(bool &isEnabled) = 0; /** * @brief Queries the list of accessibility abilities. @@ -86,51 +89,51 @@ public: * 2 indicates that the ability is disabled; * 3 indicates that the ability has been installed. * @param infos accessibility ability infos by specified types. - * @return Return true if get ability lists successfully, else return false. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool GetAbilityList(const uint32_t accessibilityAbilityTypes, const AbilityStateType stateType, + virtual RetError GetAbilityList(const uint32_t accessibilityAbilityTypes, const AbilityStateType stateType, std::vector &infos) = 0; /** * @brief Sends an accessibility event. * @param eventType Identifies the accessibility event specified by AccessibilityEventInfo. * @param componentId Indicates the ID of the component to be associated with the event. - * @return true: send ok; otherwise is refused. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool SendEvent(const EventType eventType, const int32_t componentId) = 0; + virtual RetError SendEvent(const EventType eventType, const int32_t componentId) = 0; /** * @brief Sends information about an accessibility event. * @param event Indicates the accessibility event information specified by AccessibilityEventInfo. - * @return true: send ok; otherwise is refused. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool SendEvent(const AccessibilityEventInfo &event) = 0; + virtual RetError SendEvent(const AccessibilityEventInfo &event) = 0; /** * @brief Subscribes to the specified type of accessibility status change events. * @param observer Indicates the observer for listening to status events, which is specified * by AccessibilityStateObserver. * @param eventType Indicates the status type, which is specified by AccessibilityStateEventType. - * @return true: send ok; otherwise is refused. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool SubscribeStateObserver(const std::shared_ptr &observer, + virtual RetError SubscribeStateObserver(const std::shared_ptr &observer, const uint32_t eventType) = 0; /** * @brief Unsubscribe the specified type of accessibility status change events. * @param observer Indicates the registered accessibility status event observer. * @param eventType Indicates the status type, which is specified by AccessibilityStateEventType. - * @return true: send ok; otherwise is refused. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool UnsubscribeStateObserver(const std::shared_ptr &observer, + virtual RetError UnsubscribeStateObserver(const std::shared_ptr &observer, const uint32_t eventType) = 0; /** * @brief Get enabled abilities. * @param enabledAbilities The infos of enabled abilities. - * @return Return true if get enabled abilities successfully, else return false. + * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. */ - virtual bool GetEnabledAbilities(std::vector &enabledAbilities) = 0; + virtual RetError GetEnabledAbilities(std::vector &enabledAbilities) = 0; }; } // namespace Accessibility } // namespace OHOS diff --git a/interfaces/innerkits/common/include/accessibility_def.h b/interfaces/innerkits/common/include/accessibility_def.h index 60bd1b10d..6dcd443dc 100644 --- a/interfaces/innerkits/common/include/accessibility_def.h +++ b/interfaces/innerkits/common/include/accessibility_def.h @@ -23,12 +23,27 @@ namespace Accessibility { enum RetError : int32_t { RET_OK = 0, RET_ERR_FAILED = -1, - RET_ERR_INVALID_PARAM = 1, - RET_ERR_NULLPTR = 2, - RET_ERR_CONNECTION_EXIST = 3, - RET_ERR_IPC_FAILED = 4, - RET_ERR_SAMGR = 5, - RET_ERR_NO_PERMISSION = 6, + RET_ERR_INVALID_PARAM = 1001, + RET_ERR_NULLPTR, + RET_ERR_IPC_FAILED, + RET_ERR_SAMGR, + RET_ERR_NO_PERMISSION, + RET_ERR_TIME_OUT, + RET_ERR_NOT_SUPPORT, + + RET_ERR_REGISTER_EXIST = 4001, + RET_ERR_NO_REGISTER, + RET_ERR_CONNECTION_EXIST, + RET_ERR_NO_CONNECTION, + RET_ERR_NO_WINDOW_CONNECTION, + RET_ERR_NO_CAPABILITY, + RET_ERR_INVALID_ELEMENT_INFO_FROM_ACE, + RET_ERR_PERFORM_ACTION_FAILED_BY_ACE, + RET_ERR_NO_INJECTOR, + RET_ERR_NOT_INSTALLED, + RET_ERR_NOT_ENABLED, + RET_ERR_PROPERTY_NOT_EXIST, + RET_ERR_ACTION_NOT_SUPPORT, }; enum GlobalAction : uint32_t { diff --git a/interfaces/innerkits/test/benchmarktest/accessibility_system_ability_client_test/accessibility_system_ability_client_test.cpp b/interfaces/innerkits/test/benchmarktest/accessibility_system_ability_client_test/accessibility_system_ability_client_test.cpp index 57388931c..63429fef3 100644 --- a/interfaces/innerkits/test/benchmarktest/accessibility_system_ability_client_test/accessibility_system_ability_client_test.cpp +++ b/interfaces/innerkits/test/benchmarktest/accessibility_system_ability_client_test/accessibility_system_ability_client_test.cpp @@ -30,14 +30,14 @@ namespace { if (!asaClient) { return; } + bool isEnable = false; for (auto _ : state) { /* @tc.steps: step1.call IsEnabled in loop */ - (void)asaClient->IsEnabled(); + (void)asaClient->IsEnabled(isEnable); } } - - /** + /** * @tc.name: BenchmarkTestForGetEnabledAbilities * @tc.desc: Testcase for testing 'GetEnabledAbilities' function. * @tc.type: FUNC diff --git a/interfaces/kits/js/@ohos.accessibility.GesturePath.d.ts b/interfaces/kits/js/@ohos.accessibility.GesturePath.d.ts index 2846f11ae..7a92fce43 100644 --- a/interfaces/kits/js/@ohos.accessibility.GesturePath.d.ts +++ b/interfaces/kits/js/@ohos.accessibility.GesturePath.d.ts @@ -17,17 +17,19 @@ import { GesturePoint } from "./@ohos.accessibility.GesturePoint"; /** * Indicates the path of the gesture. - * @since 9 * @syscap SystemCapability.BarrierFree.Accessibility.Core + * @since 9 */ - export declare class GesturePath { +export declare class GesturePath { constructor(durationTime: number); /** * Indicates the position of the points that make up the gesture. + * @type {Array} */ points: Array; /** * Indicates the duration of the gesture. + * @type {number} */ durationTime: number; } \ No newline at end of file diff --git a/interfaces/kits/js/@ohos.accessibility.GesturePoint.d.ts b/interfaces/kits/js/@ohos.accessibility.GesturePoint.d.ts index d24666300..53ff76252 100644 --- a/interfaces/kits/js/@ohos.accessibility.GesturePoint.d.ts +++ b/interfaces/kits/js/@ohos.accessibility.GesturePoint.d.ts @@ -15,17 +15,19 @@ /** * Indicates the point of the gesture. - * @since 9 * @syscap SystemCapability.BarrierFree.Accessibility.Core + * @since 9 */ export declare class GesturePoint { constructor(positionX: number, positionY: number); /** * Indicates the X coordinate of point. + * @type {number} */ positionX: number; /** * Indicates the Y coordinate of point. + * @type {number} */ positionY: number; } \ No newline at end of file diff --git a/interfaces/kits/js/@ohos.accessibility.config.d.ts b/interfaces/kits/js/@ohos.accessibility.config.d.ts index 9897104a7..8dfa8bd00 100644 --- a/interfaces/kits/js/@ohos.accessibility.config.d.ts +++ b/interfaces/kits/js/@ohos.accessibility.config.d.ts @@ -1,6 +1,21 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"), + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import accessibility from './@ohos.accessibility'; import { AsyncCallback, Callback } from './basic'; - + /** * Configuration of the accessibility. * @@ -46,7 +61,7 @@ declare namespace config { */ var audioBalance: Config; /** - * Indicates the configuration of monse key state. + * Indicates the configuration of mouse key state. */ var mouseKey: Config; /** @@ -54,11 +69,11 @@ declare namespace config { */ var mouseAutoClick: Config; /** - * Indicates the configuration of shortkey state. + * Indicates the configuration of short key state. */ var shortkey: Config; /** - * Indicates the configuration of shortkey target. + * Indicates the configuration of short key target. */ var shortkeyTarget: Config; /** @@ -69,36 +84,45 @@ declare namespace config { * Indicates the configuration of captions style. */ var captionsStyle: Config; - + /** - * Enable the acceessibility extension ability. + * Enable the accessibility extension ability. * @param name Indicates the accessibility extension name, in "bundleName/abilityName" format. * @param capability Indicates the ability. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 401 - Input parameter error. + * @throws { BusinessError } 9300001 - Invalid bundle name or ability name. + * @throws { BusinessError } 9300002 - Target ability already enabled. */ function enableAbility(name: string, capability: Array): Promise; function enableAbility(name: string, capability: Array, callback: AsyncCallback): void; - + /** - * Disable the acceessibility extension ability. + * Disable the accessibility extension ability. * @param name Indicates the accessibility extension name, in "bundleName/abilityName" format. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 401 - Input parameter error. + * @throws { BusinessError } 9300001 - Invalid bundle name or ability name. */ function disableAbility(name: string): Promise; function disableAbility(name: string, callback: AsyncCallback): void; - + /** - * Register the listener to listen for for changes in the enabled status of accessibility extensions. - * @param type Indicates the enableAbilityListsStateChanged type. + * Register the listener that watches for changes in the enabled status of accessibility extensions. + * @param type Indicates the type of event. * @param callback Indicates the listener. + * @throws { BusinessError } 401 - Input parameter error. */ - function on(type: 'enableAbilityListsStateChanged', callback: Callback): void; - + function on(type: 'enabledAccessibilityExtensionListChange', callback: Callback): void; + /** - * Deregister listener that watch for changes in the enabled status of accessibility extensions. - * @param type Indicates the enableAbilityListsStateChanged type. + * Deregister listener that watches for changes in the enabled status of accessibility extensions. + * @param type Indicates the type of event. * @param callback Indicates the listener. + * @throws { BusinessError } 401 - Input parameter error. */ - function off(type: 'enableAbilityListsStateChanged', callback?: Callback): void; - + function off(type: 'enabledAccessibilityExtensionListChange', callback?: Callback): void; + /** * Indicates setting, getting, and listening to changes in configuration. */ @@ -106,29 +130,34 @@ declare namespace config { /** * Setting configuration value. * @param value Indicates the value. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 401 - Input parameter error. */ set(value: T): Promise; set(value: T, callback: AsyncCallback): void; - + /** * Getting configuration value. + * @throws { BusinessError } 201 - Permission denied. */ get(): Promise; get(callback: AsyncCallback): void; - + /** * Register the listener to listen for configuration changes. * @param callback Indicates the listener. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 401 - Input parameter error. */ on(callback: Callback): void; - + /** * Deregister the listener to listen for configuration changes. * @param callback Indicates the listener. */ off(callback?: Callback): void; } - + /** * Indicates the type of daltonization color filter. */ diff --git a/interfaces/kits/js/@ohos.accessibility.d.ts b/interfaces/kits/js/@ohos.accessibility.d.ts index 4082f720e..a7013616c 100644 --- a/interfaces/kits/js/@ohos.accessibility.d.ts +++ b/interfaces/kits/js/@ohos.accessibility.d.ts @@ -24,13 +24,19 @@ import { Callback } from './basic'; * @import basic,abilityInfo */ declare namespace accessibility { - /** * The type of the Ability app. + * @type { 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual' } * @syscap SystemCapability.BarrierFree.Accessibility.Core * @since 7 */ - type AbilityType = 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual'; + /** + * The type of the Ability app. + * @type { 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual' | 'all' } + * @syscap SystemCapability.BarrierFree.Accessibility.Core + * @since 9 + */ + type AbilityType = 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual' | 'all'; /** * The action that the ability can execute. @@ -98,7 +104,7 @@ declare namespace accessibility { * @param callback Asynchronous callback interface. * @syscap SystemCapability.BarrierFree.Accessibility.Core * @return Returns {@code true} if the accessibility is enabled; returns {@code false} otherwise. - */ + */ function isOpenAccessibility(callback: AsyncCallback): void; function isOpenAccessibility(): Promise; @@ -108,18 +114,19 @@ declare namespace accessibility { * @param callback Asynchronous callback interface. * @syscap SystemCapability.BarrierFree.Accessibility.Vision * @return Returns {@code true} if the touch browser is enabled; returns {@code false} otherwise. - */ + */ function isOpenTouchGuide(callback: AsyncCallback): void; function isOpenTouchGuide(): Promise; /** * Queries the list of accessibility abilities. * @since 7 + * @deprecated since 9 * @param abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken * @param stateType The state of the accessibility ability. {@code AbilityState} eg.installed * @syscap SystemCapability.BarrierFree.Accessibility.Core * @return Returns the list of abilityInfos. - */ + */ function getAbilityLists(abilityType: AbilityType, stateType: AbilityState, callback: AsyncCallback>): void; function getAbilityLists(abilityType: AbilityType, @@ -128,19 +135,19 @@ declare namespace accessibility { /** * Queries the list of accessibility abilities. * @since 9 - * @param abilityType The all type of the accessibility ability. + * @param abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken * @param stateType The state of the accessibility ability. {@code AbilityState} eg.installed * @syscap SystemCapability.BarrierFree.Accessibility.Core * @return Returns the list of abilityInfos. - */ - function getAbilityLists(abilityType: 'all', stateType: AbilityState, - callback: AsyncCallback>): void; - function getAbilityLists(abilityType: 'all', - stateType: AbilityState): Promise>; + * @throws { BusinessError } 401 - Input parameter error. + */ + function getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState): Promise>; + function getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState, callback: AsyncCallback>): void; /** * Send accessibility Event. * @since 7 + * @deprecated since 9 * @param event The object of the accessibility {@code EventInfo} . * @param callback Asynchronous callback interface. * @syscap SystemCapability.BarrierFree.Accessibility.Core @@ -149,6 +156,18 @@ declare namespace accessibility { function sendEvent(event: EventInfo, callback: AsyncCallback): void; function sendEvent(event: EventInfo): Promise; + /** + * Send accessibility event. + * @since 9 + * @param event The object of the accessibility {@code EventInfo} . + * @param callback Asynchronous callback interface. + * @syscap SystemCapability.BarrierFree.Accessibility.Core + * @return Returns {@code true} if success ; returns {@code false} otherwise. + * @throws { BusinessError } 401 - Input parameter error. + */ + function sendAccessibilityEvent(event: EventInfo, callback: AsyncCallback): void; + function sendAccessibilityEvent(event: EventInfo): Promise; + /** * Register the observe of the accessibility state changed. * @since 7 @@ -156,6 +175,7 @@ declare namespace accessibility { * @param callback Asynchronous callback interface. * @syscap SystemCapability.BarrierFree.Accessibility.Core * @return Returns {@code true} if the register is success ; returns {@code false} otherwise. + * @throws { BusinessError } 401 - Input parameter error. */ function on(type: 'accessibilityStateChange', callback: Callback): void; @@ -166,6 +186,7 @@ declare namespace accessibility { * @param callback Asynchronous callback interface. * @syscap SystemCapability.BarrierFree.Accessibility.Vision * @return Returns {@code true} if the register is success ; returns {@code false} otherwise. + * @throws { BusinessError } 401 - Input parameter error. */ function on(type: 'touchGuideStateChange', callback: Callback): void; @@ -176,6 +197,7 @@ declare namespace accessibility { * @param callback Asynchronous callback interface. * @syscap SystemCapability.BarrierFree.Accessibility.Core * @return Returns {@code true} if the deregister is success ; returns {@code false} otherwise. + * @throws { BusinessError } 401 - Input parameter error. */ function off(type: 'accessibilityStateChange', callback?: Callback): void; @@ -185,8 +207,9 @@ declare namespace accessibility { * @param type state event type * @param callback Asynchronous callback interface. * @return Returns {@code true} if the deregister is success ; returns {@code false} otherwise. + * @throws { BusinessError } 401 - Input parameter error. */ - function off(type: 'touchGuideStateChange', callback?: Callback): void; + function off(type: 'touchGuideStateChange', callback?: Callback): void; /** * Get the captions manager. @@ -194,91 +217,98 @@ declare namespace accessibility { * @since 8 * @return Returns the captions manager. */ - function getCaptionsManager(): CaptionsManager; + function getCaptionsManager(): CaptionsManager; - /** - * Indicates the captions manager. - * @syscap SystemCapability.BarrierFree.Accessibility.Hearing - * @since 8 - */ - interface CaptionsManager { - /** - * Indicates whether captions are enabled. - */ - enabled: boolean; - /** - * Indicates the style of captions. - */ - style: CaptionsStyle; + /** + * Indicates the captions manager. + * @syscap SystemCapability.BarrierFree.Accessibility.Hearing + * @since 8 + */ + interface CaptionsManager { + /** + * Indicates whether captions are enabled. + */ + enabled: boolean; + /** + * Indicates the style of captions. + */ + style: CaptionsStyle; + + /** + * Register the observe of the enable state. + * @throws { BusinessError } 401 - Input parameter error. + */ + on(type: 'enableChange', callback: Callback): void; - /** - * Register the observe of the enable state. - */ - on(type: 'enableChange', callback: Callback): void; - /** - * Register the observer of the style. - */ - on(type: 'styleChange', callback: Callback): void; - /** - * Deregister the observe of the enable state. - */ - off(type: 'enableChange', callback?: Callback): void; - /** - * Deregister the observer of the style. - */ - off(type: 'styleChange', callback?: Callback): void; - } + /** + * Register the observer of the style. + * @throws { BusinessError } 401 - Input parameter error. + */ + on(type: 'styleChange', callback: Callback): void; - /** - * Indicates the edge type of the captions font. - * @syscap SystemCapability.BarrierFree.Accessibility.Hearing - * @since 8 - */ - type CaptionsFontEdgeType = 'none' | 'raised' | 'depressed' | 'uniform' | 'dropShadow'; - /** - * Indicates the font family of captions. - * @syscap SystemCapability.BarrierFree.Accessibility.Hearing - * @since 8 - */ - type CaptionsFontFamily = 'default' | 'monospacedSerif' | 'serif' | - 'monospacedSansSerif' | 'sansSerif' | 'casual' | 'cursive' | 'smallCapitals'; - /** - * Indicates the style of captions. - * @syscap SystemCapability.BarrierFree.Accessibility.Hearing - * @since 8 - */ - interface CaptionsStyle { - /** - * Indicates the font family of captions. - */ - fontFamily: CaptionsFontFamily; - /** - * Indicates the font scaling of captions. - */ - fontScale: number; - /** - * Indicates the font color of captions. - */ - fontColor: number | string; - /** - * Indicates the edge type of the captions font. - */ - fontEdgeType: CaptionsFontEdgeType; - /** - * Indicates the background color of captions. - */ - backgroundColor: number | string; - /** - * Indicates the window color of captions. - */ - windowColor: number | string; - } + /** + * Deregister the observe of the enable state. + * @throws { BusinessError } 401 - Input parameter error. + */ + off(type: 'enableChange', callback?: Callback): void; - /** - * Indicates the info of accessibility. - * @syscap SystemCapability.BarrierFree.Accessibility.Core - * @since 7 - */ + /** + * Deregister the observer of the style. + * @throws { BusinessError } 401 - Input parameter error. + */ + off(type: 'styleChange', callback?: Callback): void; + } + + /** + * Indicates the edge type of the captions font. + * @syscap SystemCapability.BarrierFree.Accessibility.Hearing + * @since 8 + */ + type CaptionsFontEdgeType = 'none' | 'raised' | 'depressed' | 'uniform' | 'dropShadow'; + /** + * Indicates the font family of captions. + * @syscap SystemCapability.BarrierFree.Accessibility.Hearing + * @since 8 + */ + type CaptionsFontFamily = 'default' | 'monospacedSerif' | 'serif' | + 'monospacedSansSerif' | 'sansSerif' | 'casual' | 'cursive' | 'smallCapitals'; + /** + * Indicates the style of captions. + * @syscap SystemCapability.BarrierFree.Accessibility.Hearing + * @since 8 + */ + interface CaptionsStyle { + /** + * Indicates the font family of captions. + */ + fontFamily: CaptionsFontFamily; + /** + * Indicates the font scaling of captions. + */ + fontScale: number; + /** + * Indicates the font color of captions. + */ + fontColor: number | string; + /** + * Indicates the edge type of the captions font. + */ + fontEdgeType: CaptionsFontEdgeType; + /** + * Indicates the background color of captions. + */ + backgroundColor: number | string; + /** + * Indicates the window color of captions. + */ + windowColor: number | string; + } + + /** + * Indicates the info of accessibility. + * @syscap SystemCapability.BarrierFree.Accessibility.Core + * @since 7 + */ interface AccessibilityAbilityInfo { /** * The ability id. @@ -361,7 +391,7 @@ declare namespace accessibility { /** The page id of the event source. * @since 7 */ - pageId?: number; + pageId ?: number; /** * The accessibility event description. diff --git a/interfaces/kits/js/AccessibilityExtensionContext.d.ts b/interfaces/kits/js/AccessibilityExtensionContext.d.ts index f28513507..b631c6b1d 100644 --- a/interfaces/kits/js/AccessibilityExtensionContext.d.ts +++ b/interfaces/kits/js/AccessibilityExtensionContext.d.ts @@ -28,6 +28,7 @@ export default class AccessibilityExtensionContext extends ExtensionContext { /** * Set the name of the bundle name that is interested in sending the event. * @param targetNames + * @throws { BusinessError } 401 - Input parameter error. */ setTargetBundleName(targetNames: Array): Promise; setTargetBundleName(targetNames: Array, callback: AsyncCallback): void; @@ -35,6 +36,8 @@ export default class AccessibilityExtensionContext extends ExtensionContext { /** * Get focus element. * @param isAccessibilityFocus Indicates whether the acquired element has an accessibility focus. + * @throws { BusinessError } 401 - Input parameter error. + * @throws { BusinessError } 9300003 - Do not have accessibility right for this operation. */ getFocusElement(isAccessibilityFocus?: boolean): Promise; getFocusElement(callback: AsyncCallback): void; @@ -43,6 +46,8 @@ export default class AccessibilityExtensionContext extends ExtensionContext { /** * Get window root element. * @param windowId Indicates the window ID. + * @throws { BusinessError } 401 - Input parameter error. + * @throws { BusinessError } 9300003 - Do not have accessibility right for this operation. */ getWindowRootElement(windowId?: number): Promise; getWindowRootElement(callback: AsyncCallback): void; @@ -51,6 +56,8 @@ export default class AccessibilityExtensionContext extends ExtensionContext { /** * Get window list. * @param displayId Indicates the display ID. + * @throws { BusinessError } 401 - Input parameter error. + * @throws { BusinessError } 9300003 - Do not have accessibility right for this operation. */ getWindows(displayId?: number): Promise>; getWindows(callback: AsyncCallback>): void; @@ -59,6 +66,8 @@ export default class AccessibilityExtensionContext extends ExtensionContext { /** * Inject gesture path events. * @param gesturePath Indicates the gesture path. + * @throws { BusinessError } 401 - Input parameter error. + * @throws { BusinessError } 9300003 - Do not have accessibility right for this operation. */ injectGesture(gesturePath: GesturePath): Promise; injectGesture(gesturePath: GesturePath, callback: AsyncCallback): void; @@ -81,6 +90,8 @@ declare interface AccessibilityElement { /** * Get the value of an attribute. * @param attributeName Indicates the attribute name. + * @throws { BusinessError } 401 - Input parameter error. + * @throws { BusinessError } 9300004 - This property does not exist. */ attributeValue(attributeName: T): Promise; attributeValue(attributeName: T, @@ -96,15 +107,18 @@ declare interface AccessibilityElement { * Perform the specified action. * @param actionName Indicates the action name. * @param parameters Indicates the parameters needed to execute the action. + * @throws { BusinessError } 401 - Input parameter error. + * @throws { BusinessError } 9300005 - This action is not supported. */ - performAction(actionName: string, parameters?: object): Promise; - performAction(actionName: string, callback: AsyncCallback): void; - performAction(actionName: string, parameters: object, callback: AsyncCallback): void; + performAction(actionName: string, parameters?: object): Promise; + performAction(actionName: string, callback: AsyncCallback): void; + performAction(actionName: string, parameters: object, callback: AsyncCallback): void; /** * Find elements that match the condition. * @param type The type of query condition is content. * @param condition Indicates the specific content to be queried. + * @throws { BusinessError } 401 - Input parameter error. */ findElement(type: 'content', condition: string): Promise>; findElement(type: 'content', condition: string, callback: AsyncCallback>): void @@ -113,6 +127,7 @@ declare interface AccessibilityElement { * Find elements that match the condition. * @param type The type of query condition is focus type. * @param condition Indicates the type of focus to query. + * @throws { BusinessError } 401 - Input parameter error. */ findElement(type: 'focusType', condition: FocusType): Promise; findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback): void @@ -121,6 +136,7 @@ declare interface AccessibilityElement { * Find elements that match the condition. * @param type The type of query condition is focus direction. * @param condition Indicates the direction of search focus to query. + * @throws { BusinessError } 401 - Input parameter error. */ findElement(type: 'focusDirection', condition: FocusDirection): Promise; findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCallback): void @@ -212,6 +228,9 @@ type ElementAttributeValues = { * Indicates whether the element is enable or not. */ 'isEnable': boolean; + /** + * Indicates whether the element is hint state or not. + */ 'isHint': boolean; /** * Indicates whether the element is focused or not. diff --git a/interfaces/kits/napi/accessibility_config/include/napi_accessibility_config.h b/interfaces/kits/napi/accessibility_config/include/napi_accessibility_config.h index b76004e92..96e37aa6a 100644 --- a/interfaces/kits/napi/accessibility_config/include/napi_accessibility_config.h +++ b/interfaces/kits/napi/accessibility_config/include/napi_accessibility_config.h @@ -60,7 +60,7 @@ struct NAccessibilityConfigData { OHOS::AccessibilityConfig::CaptionProperty captionProperty_ {}; OHOS::AccessibilityConfig::CONFIG_ID id_ = OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_ID_MAX; bool boolConfig_ = false; - bool ret_ = false; + OHOS::Accessibility::RetError ret_ = OHOS::Accessibility::RET_ERR_FAILED; }; class NAccessibilityConfigClass { diff --git a/interfaces/kits/napi/accessibility_config/src/napi_accessibility_config.cpp b/interfaces/kits/napi/accessibility_config/src/napi_accessibility_config.cpp index 098daf2eb..776df95d6 100644 --- a/interfaces/kits/napi/accessibility_config/src/napi_accessibility_config.cpp +++ b/interfaces/kits/napi/accessibility_config/src/napi_accessibility_config.cpp @@ -35,6 +35,8 @@ napi_value NAccessibilityConfig::EnableAbility(napi_env env, napi_callback_info NAccessibilityConfigData* callbackInfo = new(std::nothrow) NAccessibilityConfigData(); if (!callbackInfo) { HILOG_ERROR("callbackInfo is nullptr"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_NULLPTR); + napi_throw(env, err); return nullptr; } @@ -42,23 +44,52 @@ napi_value NAccessibilityConfig::EnableAbility(napi_env env, napi_callback_info napi_value parameters[ARGS_SIZE_THREE] = {0}; napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); - // parse name - std::string ability = ""; - ParseString(env, ability, parameters[PARAM0]); - HILOG_INFO("ability = %{private}s", ability.c_str()); - callbackInfo->abilityName_ = ability; + OHOS::Accessibility::RetError errCode = OHOS::Accessibility::RET_OK; + if (argc < ARGS_SIZE_THREE - 1) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } - // parse capability - ConvertJSToCapabilities(env, parameters[PARAM1], callbackInfo->capabilities_); + if (errCode == OHOS::Accessibility::RET_OK) { + // parse name + std::string ability = ""; + if (ParseString(env, ability, parameters[PARAM0])) { + HILOG_INFO("ability = %{private}s", ability.c_str()); + callbackInfo->abilityName_ = ability; + } else { + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + + // parse capability + if (!ConvertJSToCapabilities(env, parameters[PARAM1], callbackInfo->capabilities_)) { + HILOG_ERROR("convert capabilities failed"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + + if (errCode == OHOS::Accessibility::RET_ERR_INVALID_PARAM) { + delete callbackInfo; + callbackInfo = nullptr; + napi_value err = CreateBusinessError(env, errCode); + HILOG_ERROR("invalid param"); + napi_throw(env, err); + return nullptr; + } - // parse function if it needs napi_value promise = nullptr; - if (argc >= ARGS_SIZE_THREE) { - napi_create_reference(env, parameters[PARAM2], 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); + if (argc > ARGS_SIZE_THREE - 1) { + napi_valuetype valueType = napi_null; + napi_typeof(env, parameters[PARAM2], &valueType); + if (valueType == napi_function) { + napi_create_reference(env, parameters[PARAM2], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } } else { napi_create_promise(env, &callbackInfo->deferred_, &promise); } + napi_value resource = nullptr; napi_create_string_utf8(env, "EnableAbility", NAPI_AUTO_LENGTH, &resource); @@ -82,6 +113,8 @@ napi_value NAccessibilityConfig::DisableAbility(napi_env env, napi_callback_info NAccessibilityConfigData* callbackInfo = new(std::nothrow) NAccessibilityConfigData(); if (!callbackInfo) { HILOG_ERROR("callbackInfo is nullptr"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_NULLPTR); + napi_throw(env, err); return nullptr; } @@ -89,20 +122,46 @@ napi_value NAccessibilityConfig::DisableAbility(napi_env env, napi_callback_info napi_value parameters[ARGS_SIZE_TWO] = {0}; napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); - // parse name - std::string ability = ""; - ParseString(env, ability, parameters[PARAM0]); - HILOG_INFO("ability = %{private}s", ability.c_str()); - callbackInfo->abilityName_ = ability; + OHOS::Accessibility::RetError errCode = OHOS::Accessibility::RET_OK; + if (argc < ARGS_SIZE_TWO - 1) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + + if (errCode == OHOS::Accessibility::RET_OK) { + // parse name + std::string ability = ""; + if (ParseString(env, ability, parameters[PARAM0])) { + HILOG_INFO("ability = %{private}s", ability.c_str()); + callbackInfo->abilityName_ = ability; + } else { + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + + if (errCode == OHOS::Accessibility::RET_ERR_INVALID_PARAM) { + delete callbackInfo; + callbackInfo = nullptr; + napi_value err = CreateBusinessError(env, errCode); + HILOG_ERROR("invalid param"); + napi_throw(env, err); + return nullptr; + } - // parse function if it needs napi_value promise = nullptr; - if (argc >= ARGS_SIZE_TWO) { - napi_create_reference(env, parameters[PARAM1], 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); + if (argc > ARGS_SIZE_TWO - 1) { + napi_valuetype valueType = napi_null; + napi_typeof(env, parameters[PARAM1], &valueType); + if (valueType == napi_function) { + napi_create_reference(env, parameters[PARAM1], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } } else { napi_create_promise(env, &callbackInfo->deferred_, &promise); } + napi_value resource = nullptr; napi_create_string_utf8(env, "DisableAbility", NAPI_AUTO_LENGTH, &resource); @@ -125,16 +184,40 @@ napi_value NAccessibilityConfig::SubscribeState(napi_env env, napi_callback_info HILOG_INFO(); size_t argc = ARGS_SIZE_TWO; napi_value args[ARGS_SIZE_TWO] = {0}; - napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - if (status != napi_ok) { - HILOG_ERROR("Failed to get callback info"); - return nullptr; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + OHOS::Accessibility::RetError errCode = OHOS::Accessibility::RET_OK; + if (argc < ARGS_SIZE_TWO) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; } - std::string observerType = ""; - ParseString(env, observerType, args[PARAM0]); - if (std::strcmp(observerType.c_str(), "enableAbilityListsStateChanged")) { - HILOG_ERROR("args[PARAM0] is wrong[%{public}s]", observerType.c_str()); + if (errCode == OHOS::Accessibility::RET_OK) { + std::string observerType = ""; + if (!ParseString(env, observerType, args[PARAM0])) { + HILOG_ERROR("observer type parse failed"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } else { + if (std::strcmp(observerType.c_str(), "enabledAccessibilityExtensionListChange") != 0) { + HILOG_ERROR("args[PARAM0] is wrong[%{public}s", observerType.c_str()); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + } + + if (errCode == OHOS::Accessibility::RET_OK) { + napi_valuetype valueType = napi_null; + napi_typeof(env, args[PARAM1], &valueType); + if (valueType != napi_function) { + HILOG_ERROR("args[PARAM1] format is wrong"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + + if (errCode == OHOS::Accessibility::RET_ERR_INVALID_PARAM) { + napi_value err = CreateBusinessError(env, errCode); + HILOG_ERROR("invalid param"); + napi_throw(env, err); return nullptr; } @@ -151,21 +234,42 @@ napi_value NAccessibilityConfig::UnsubscribeState(napi_env env, napi_callback_in HILOG_INFO(); size_t argc = ARGS_SIZE_TWO; napi_value args[ARGS_SIZE_TWO] = {0}; - napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - if (status != napi_ok) { - HILOG_ERROR("Failed to get callback info"); + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + OHOS::Accessibility::RetError errCode = OHOS::Accessibility::RET_OK; + if (argc < ARGS_SIZE_TWO - 1) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + + if (errCode == OHOS::Accessibility::RET_OK) { + std::string observerType = ""; + if (!ParseString(env, observerType, args[PARAM0])) { + HILOG_ERROR("observer type parse failed"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } else { + if (std::strcmp(observerType.c_str(), "enabledAccessibilityExtensionListChange") != 0) { + HILOG_ERROR("args[PARAM0] is wrong[%{public}s", observerType.c_str()); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + } + + if (errCode == OHOS::Accessibility::RET_ERR_INVALID_PARAM) { + napi_value err = CreateBusinessError(env, errCode); + HILOG_ERROR("invalid param"); + napi_throw(env, err); return nullptr; } - std::string observerType = ""; - ParseString(env, observerType, args[PARAM0]); - if (std::strcmp(observerType.c_str(), "enableAbilityListsStateChanged")) { - HILOG_ERROR("args[PARAM0] is wrong[%{public}s]", observerType.c_str()); - return nullptr; - } - - if (argc >= ARGS_SIZE_TWO) { - enableAbilityListsObservers_->UnsubscribeObserver(args[PARAM1]); + if (argc > ARGS_SIZE_TWO - 1) { + napi_valuetype valueType = napi_null; + napi_typeof(env, args[PARAM1], &valueType); + if (valueType == napi_function) { + enableAbilityListsObservers_->UnsubscribeObserver(args[PARAM1]); + } else { + enableAbilityListsObservers_->UnsubscribeObservers(); + } } else { enableAbilityListsObservers_->UnsubscribeObservers(); } @@ -180,29 +284,22 @@ void NAccessibilityConfig::AsyncWorkComplete(napi_env env, napi_status status, v HILOG_ERROR("callbackInfo is nullptr"); return; } - napi_value result[ARGS_SIZE_TWO] = {0}; + napi_value result[ARGS_SIZE_ONE] = {0}; napi_value callback = 0; + napi_value returnVal = 0; napi_value undefined = 0; - napi_value ret = 0; napi_get_undefined(env, &undefined); - napi_get_undefined(env, &ret); + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); if (callbackInfo->callback_) { - if (callbackInfo->ret_) { - result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); - } else { - result[PARAM0] = GetErrorValue(env, CODE_FAILED); - } - result[PARAM1] = ret; napi_get_reference_value(env, callbackInfo->callback_, &callback); - napi_value returnVal; - napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &returnVal); + napi_call_function(env, undefined, callback, ARGS_SIZE_ONE, result, &returnVal); napi_delete_reference(env, callbackInfo->callback_); HILOG_DEBUG("complete function callback mode"); } else { - if (callbackInfo->ret_) { + if (callbackInfo->ret_ == OHOS::Accessibility::RET_OK) { napi_resolve_deferred(env, callbackInfo->deferred_, undefined); } else { - napi_reject_deferred(env, callbackInfo->deferred_, undefined); + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); } HILOG_DEBUG("complete function promise mode"); } @@ -219,59 +316,55 @@ void NAccessibilityConfig::SetConfigExecute(napi_env env, void* data) HILOG_ERROR("callbackInfo is nullptr"); return; } - if (!callbackInfo->ret_) { - HILOG_ERROR("check param error"); - return; - } auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); switch (callbackInfo->id_) { case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_HIGH_CONTRAST_TEXT: - callbackInfo->ret_ = RET_OK == instance.SetHighContrastTextState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.SetHighContrastTextState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_INVERT_COLOR: - callbackInfo->ret_ = RET_OK == instance.SetInvertColorState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.SetInvertColorState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_ANIMATION_OFF: - callbackInfo->ret_ = RET_OK == instance.SetAnimationOffState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.SetAnimationOffState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SCREEN_MAGNIFICATION: - callbackInfo->ret_ = RET_OK == instance.SetScreenMagnificationState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.SetScreenMagnificationState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_AUDIO_MONO: - callbackInfo->ret_ = RET_OK == instance.SetAudioMonoState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.SetAudioMonoState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_MOUSE_KEY: - callbackInfo->ret_ = RET_OK == instance.SetMouseKeyState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.SetMouseKeyState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SHORT_KEY: - callbackInfo->ret_ = RET_OK == instance.SetShortKeyState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.SetShortKeyState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CAPTION_STATE: - callbackInfo->ret_ = RET_OK == instance.SetCaptionsState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.SetCaptionsState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CONTENT_TIMEOUT: - callbackInfo->ret_ = RET_OK == instance.SetContentTimeout(callbackInfo->uint32Config_); + callbackInfo->ret_ = instance.SetContentTimeout(callbackInfo->uint32Config_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_MOUSE_AUTOCLICK: - callbackInfo->ret_ = RET_OK == instance.SetMouseAutoClick(callbackInfo->int32Config_); + callbackInfo->ret_ = instance.SetMouseAutoClick(callbackInfo->int32Config_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_AUDIO_BALANCE: - callbackInfo->ret_ = RET_OK == instance.SetAudioBalance(callbackInfo->floatConfig_); + callbackInfo->ret_ = instance.SetAudioBalance(callbackInfo->floatConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_BRIGHTNESS_DISCOUNT: - callbackInfo->ret_ = RET_OK == instance.SetBrightnessDiscount(callbackInfo->floatConfig_); + callbackInfo->ret_ = instance.SetBrightnessDiscount(callbackInfo->floatConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_DALTONIZATION_COLOR_FILTER: { auto filter = ConvertStringToDaltonizationTypes(callbackInfo->stringConfig_); - callbackInfo->ret_ = RET_OK == instance.SetDaltonizationColorFilter(filter); + callbackInfo->ret_ = instance.SetDaltonizationColorFilter(filter); } break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SHORT_KEY_TARGET: - callbackInfo->ret_ = RET_OK == instance.SetShortkeyTarget(callbackInfo->stringConfig_); + callbackInfo->ret_ = instance.SetShortkeyTarget(callbackInfo->stringConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CAPTION_STYLE: - callbackInfo->ret_ = RET_OK == instance.SetCaptionsProperty(callbackInfo->captionProperty_); + callbackInfo->ret_ = instance.SetCaptionsProperty(callbackInfo->captionProperty_); break; default: break; @@ -286,11 +379,8 @@ void NAccessibilityConfig::GetConfigComplete(napi_env env, napi_status status, v HILOG_ERROR("callbackInfo is nullptr"); return; } - napi_value result[ARGS_SIZE_TWO] = {0}; - napi_value callback = 0; - napi_value undefined = 0; - napi_get_undefined(env, &undefined); HILOG_INFO("callbackInfo->id_ = %{public}d", callbackInfo->id_); + napi_value result[ARGS_SIZE_TWO] = {0}; switch (callbackInfo->id_) { case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_HIGH_CONTRAST_TEXT: case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_INVERT_COLOR: @@ -321,22 +411,22 @@ void NAccessibilityConfig::GetConfigComplete(napi_env env, napi_status status, v default: break; } + + napi_value returnVal = 0; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); if (callbackInfo->callback_) { - if (callbackInfo->ret_) { - result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); - } else { - result[PARAM0] = GetErrorValue(env, CODE_FAILED); - } napi_get_reference_value(env, callbackInfo->callback_, &callback); - napi_value returnVal; napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &returnVal); napi_delete_reference(env, callbackInfo->callback_); HILOG_DEBUG("complete function callback mode"); } else { - if (callbackInfo->ret_) { + if (callbackInfo->ret_ == OHOS::Accessibility::RET_OK) { napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); } else { - napi_reject_deferred(env, callbackInfo->deferred_, undefined); + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); } } napi_delete_async_work(env, callbackInfo->work_); @@ -355,57 +445,57 @@ void NAccessibilityConfig::GetConfigExecute(napi_env env, void* data) auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); switch (callbackInfo->id_) { case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_HIGH_CONTRAST_TEXT: - callbackInfo->ret_ = RET_OK == instance.GetHighContrastTextState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.GetHighContrastTextState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_INVERT_COLOR: - callbackInfo->ret_ = RET_OK == instance.GetInvertColorState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.GetInvertColorState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_ANIMATION_OFF: - callbackInfo->ret_ = RET_OK == instance.GetAnimationOffState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.GetAnimationOffState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SCREEN_MAGNIFICATION: - callbackInfo->ret_ = RET_OK == instance.GetScreenMagnificationState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.GetScreenMagnificationState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_AUDIO_MONO: - callbackInfo->ret_ = RET_OK == instance.GetAudioMonoState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.GetAudioMonoState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_MOUSE_KEY: - callbackInfo->ret_ = RET_OK == instance.GetMouseKeyState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.GetMouseKeyState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SHORT_KEY: - callbackInfo->ret_ = RET_OK == instance.GetShortKeyState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.GetShortKeyState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CAPTION_STATE: - callbackInfo->ret_ = RET_OK == instance.GetCaptionsState(callbackInfo->boolConfig_); + callbackInfo->ret_ = instance.GetCaptionsState(callbackInfo->boolConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CONTENT_TIMEOUT: { uint32_t timeout = 0; - callbackInfo->ret_ = RET_OK == instance.GetContentTimeout(timeout); + callbackInfo->ret_ = instance.GetContentTimeout(timeout); callbackInfo->int32Config_ = static_cast(timeout); } break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_MOUSE_AUTOCLICK: - callbackInfo->ret_ = RET_OK == instance.GetMouseAutoClick(callbackInfo->int32Config_); + callbackInfo->ret_ = instance.GetMouseAutoClick(callbackInfo->int32Config_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_AUDIO_BALANCE: - callbackInfo->ret_ = RET_OK == instance.GetAudioBalance(callbackInfo->floatConfig_); + callbackInfo->ret_ = instance.GetAudioBalance(callbackInfo->floatConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_BRIGHTNESS_DISCOUNT: - callbackInfo->ret_ = RET_OK == instance.GetBrightnessDiscount(callbackInfo->floatConfig_); + callbackInfo->ret_ = instance.GetBrightnessDiscount(callbackInfo->floatConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_DALTONIZATION_COLOR_FILTER: { OHOS::AccessibilityConfig::DALTONIZATION_TYPE type; - callbackInfo->ret_ = RET_OK == instance.GetDaltonizationColorFilter(type); + callbackInfo->ret_ = instance.GetDaltonizationColorFilter(type); callbackInfo->stringConfig_ = ConvertDaltonizationTypeToString(type); } break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SHORT_KEY_TARGET: - callbackInfo->ret_ = RET_OK == instance.GetShortkeyTarget(callbackInfo->stringConfig_); + callbackInfo->ret_ = instance.GetShortkeyTarget(callbackInfo->stringConfig_); break; case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CAPTION_STYLE: - callbackInfo->ret_ = RET_OK == instance.GetCaptionsProperty(callbackInfo->captionProperty_); + callbackInfo->ret_ = instance.GetCaptionsProperty(callbackInfo->captionProperty_); break; default: break; @@ -421,76 +511,113 @@ napi_value NAccessibilityConfig::SetConfig(napi_env env, napi_callback_info info napi_get_cb_info(env, info, &argc, parameters, &jsthis, nullptr); NAccessibilityConfigClass* obj; - NAPI_CALL(env, napi_unwrap(env, jsthis, reinterpret_cast(&obj))); + napi_status status = napi_unwrap(env, jsthis, reinterpret_cast(&obj)); + if (status != napi_ok) { + HILOG_ERROR("Failed to get unwrap obj"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_FAILED); + napi_throw(env, err); + return nullptr; + } if (!obj) { HILOG_ERROR("obj is nullptr"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_NULLPTR); + napi_throw(env, err); return nullptr; } HILOG_INFO("ConfigID = %{public}d", obj->GetConfigId()); NAccessibilityConfigData* callbackInfo = new(std::nothrow) NAccessibilityConfigData(); if (!callbackInfo) { HILOG_ERROR("callbackInfo is nullptr"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_NULLPTR); + napi_throw(env, err); return nullptr; } + OHOS::Accessibility::RetError errCode = OHOS::Accessibility::RET_OK; + if (argc < ARGS_SIZE_TWO - 1) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + bool ret = false; - switch (obj->GetConfigId()) { - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_HIGH_CONTRAST_TEXT: - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_INVERT_COLOR: - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_ANIMATION_OFF: - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SCREEN_MAGNIFICATION: - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_AUDIO_MONO: - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_MOUSE_KEY: - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SHORT_KEY: - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CAPTION_STATE: - { - bool state = false; - callbackInfo->ret_ = ParseBool(env, state, parameters[PARAM0]); - callbackInfo->boolConfig_ = state; - } - break; - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CONTENT_TIMEOUT: - { - int32_t timeout = 0; - callbackInfo->ret_ = ParseInt32(env, timeout, parameters[PARAM0]); - callbackInfo->uint32Config_ = static_cast(timeout); - } - break; - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_MOUSE_AUTOCLICK: - { - int32_t time = 0; - callbackInfo->ret_ = ParseInt32(env, time, parameters[PARAM0]); - callbackInfo->int32Config_ = time; - } - break; - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_AUDIO_BALANCE: - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_BRIGHTNESS_DISCOUNT: - { - double doubleTemp = 0; - callbackInfo->ret_ = ParseDouble(env, doubleTemp, parameters[PARAM0]); - callbackInfo->floatConfig_ = static_cast(doubleTemp); - } - break; - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_DALTONIZATION_COLOR_FILTER: - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SHORT_KEY_TARGET: - { - std::string target = ""; - callbackInfo->ret_ = ParseString(env, target, parameters[PARAM0]) && target.length() > 0; - callbackInfo->stringConfig_ = target; - } - break; - case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CAPTION_STYLE: - callbackInfo->ret_ = ConvertObjToCaptionProperty(env, parameters[PARAM0], &callbackInfo->captionProperty_); - break; - default: - break; + if (errCode == OHOS::Accessibility::RET_OK) { + switch (obj->GetConfigId()) { + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_HIGH_CONTRAST_TEXT: + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_INVERT_COLOR: + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_ANIMATION_OFF: + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SCREEN_MAGNIFICATION: + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_AUDIO_MONO: + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_MOUSE_KEY: + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SHORT_KEY: + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CAPTION_STATE: + { + bool state = false; + ret = ParseBool(env, state, parameters[PARAM0]); + callbackInfo->boolConfig_ = state; + } + break; + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CONTENT_TIMEOUT: + { + int32_t timeout = 0; + ret = ParseInt32(env, timeout, parameters[PARAM0]); + callbackInfo->uint32Config_ = static_cast(timeout); + } + break; + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_MOUSE_AUTOCLICK: + { + int32_t time = 0; + ret = ParseInt32(env, time, parameters[PARAM0]); + callbackInfo->int32Config_ = time; + } + break; + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_AUDIO_BALANCE: + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_BRIGHTNESS_DISCOUNT: + { + double doubleTemp = 0; + ret = ParseDouble(env, doubleTemp, parameters[PARAM0]); + callbackInfo->floatConfig_ = static_cast(doubleTemp); + } + break; + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_DALTONIZATION_COLOR_FILTER: + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_SHORT_KEY_TARGET: + { + std::string target = ""; + ret = ParseString(env, target, parameters[PARAM0]) && target.length() > 0; + callbackInfo->stringConfig_ = target; + } + break; + case OHOS::AccessibilityConfig::CONFIG_ID::CONFIG_CAPTION_STYLE: + ret = ConvertObjToCaptionProperty(env, parameters[PARAM0], &callbackInfo->captionProperty_); + break; + default: + break; + } + if (!ret) { + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + if (errCode == OHOS::Accessibility::RET_ERR_INVALID_PARAM) { + delete callbackInfo; + callbackInfo = nullptr; + delete obj; + obj = nullptr; + napi_value err = CreateBusinessError(env, errCode); + HILOG_ERROR("invalid param"); + napi_throw(env, err); + return nullptr; } callbackInfo->id_ = obj->GetConfigId(); // parse function if it needs napi_value promise = nullptr; if (argc >= ARGS_SIZE_TWO) { - napi_create_reference(env, parameters[PARAM1], 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); + napi_valuetype valueType = napi_null; + napi_typeof(env, parameters[PARAM1], &valueType); + if (valueType == napi_function) { + napi_create_reference(env, parameters[PARAM1], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } } else { napi_create_promise(env, &callbackInfo->deferred_, &promise); } @@ -518,9 +645,17 @@ napi_value NAccessibilityConfig::GetConfig(napi_env env, napi_callback_info info napi_get_cb_info(env, info, &argc, parameters, &jsthis, nullptr); NAccessibilityConfigClass* obj; - NAPI_CALL(env, napi_unwrap(env, jsthis, reinterpret_cast(&obj))); + napi_status status = napi_unwrap(env, jsthis, reinterpret_cast(&obj)); + if (status != napi_ok) { + HILOG_ERROR("Failed to get unwrap obj"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_FAILED); + napi_throw(env, err); + return nullptr; + } if (!obj) { HILOG_ERROR("obj is nullptr"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_NULLPTR); + napi_throw(env, err); return nullptr; } HILOG_INFO("ConfigID = %{public}d", obj->GetConfigId()); @@ -528,6 +663,8 @@ napi_value NAccessibilityConfig::GetConfig(napi_env env, napi_callback_info info NAccessibilityConfigData* callbackInfo = new(std::nothrow) NAccessibilityConfigData(); if (!callbackInfo) { HILOG_ERROR("callbackInfo is nullptr"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_NULLPTR); + napi_throw(env, err); return nullptr; } callbackInfo->id_ = obj->GetConfigId(); @@ -535,8 +672,14 @@ napi_value NAccessibilityConfig::GetConfig(napi_env env, napi_callback_info info // parse function if it needs napi_value promise = nullptr; if (argc >= ARGS_SIZE_ONE) { - napi_create_reference(env, parameters[PARAM0], 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); + napi_valuetype valueType = napi_null; + napi_typeof(env, parameters[PARAM0], &valueType); + if (valueType == napi_function) { + napi_create_reference(env, parameters[PARAM0], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } } else { napi_create_promise(env, &callbackInfo->deferred_, &promise); } @@ -562,9 +705,41 @@ napi_value NAccessibilityConfig::SubscribeConfigObserver(napi_env env, napi_call napi_value jsthis; napi_get_cb_info(env, info, &argc, parameters, &jsthis, nullptr); NAccessibilityConfigClass* obj; - NAPI_CALL(env, napi_unwrap(env, jsthis, reinterpret_cast(&obj))); + napi_status status = napi_unwrap(env, jsthis, reinterpret_cast(&obj)); + if (status != napi_ok) { + HILOG_ERROR("Failed to get unwrap obj"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_FAILED); + napi_throw(env, err); + return nullptr; + } if (!obj) { HILOG_ERROR("obj is nullptr"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_NULLPTR); + napi_throw(env, err); + return nullptr; + } + + OHOS::Accessibility::RetError errCode = OHOS::Accessibility::RET_OK; + if (argc < ARGS_SIZE_ONE) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + + if (errCode == OHOS::Accessibility::RET_OK) { + napi_valuetype valueType = napi_null; + napi_typeof(env, parameters[PARAM0], &valueType); + if (valueType != napi_function) { + HILOG_ERROR("parameters[PARAM1] format is wrong"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + + if (errCode == OHOS::Accessibility::RET_ERR_INVALID_PARAM) { + delete obj; + obj = nullptr; + napi_value err = CreateBusinessError(env, errCode); + HILOG_ERROR("invalid param"); + napi_throw(env, err); return nullptr; } @@ -585,13 +760,27 @@ napi_value NAccessibilityConfig::UnSubscribeConfigObserver(napi_env env, napi_ca napi_value parameters[ARGS_SIZE_ONE] = {0}; napi_get_cb_info(env, info, &argc, parameters, &jsthis, nullptr); NAccessibilityConfigClass* obj; - NAPI_CALL(env, napi_unwrap(env, jsthis, reinterpret_cast(&obj))); + napi_status status = napi_unwrap(env, jsthis, reinterpret_cast(&obj)); + if (status != napi_ok) { + HILOG_ERROR("Failed to get unwrap obj"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_FAILED); + napi_throw(env, err); + return nullptr; + } if (!obj) { HILOG_ERROR("obj is nullptr"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_NULLPTR); + napi_throw(env, err); return nullptr; } if (argc >= ARGS_SIZE_ONE) { - configObservers_->UnsubscribeObserver(obj->GetConfigId(), parameters[PARAM0]); + napi_valuetype valueType = napi_null; + napi_typeof(env, parameters[PARAM0], &valueType); + if (valueType == napi_function) { + configObservers_->UnsubscribeObserver(obj->GetConfigId(), parameters[PARAM0]); + } else { + configObservers_->UnsubscribeObservers(obj->GetConfigId()); + } } else { configObservers_->UnsubscribeObservers(obj->GetConfigId()); } diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/include/accessibility_extension_context.h b/interfaces/kits/napi/accessibility_extension_module_loader/include/accessibility_extension_context.h index 43b651ca9..06aae8a6b 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/include/accessibility_extension_context.h +++ b/interfaces/kits/napi/accessibility_extension_module_loader/include/accessibility_extension_context.h @@ -35,73 +35,73 @@ public: * @brief Obtains elementInfo of focus. * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. * @param elementInfo The accessibilityElementInfo of focus. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo); + RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo); /** * @brief Obtains elementInfo of focus. * @param sourceInfo * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. * @param elementInfo The accessibilityElementInfo of focus. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, + RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo); /** * @brief Sends simulate gestures to the screen. * @param gesturePath The gesture which need to send. - * @return Return true if the gesture sends successfully, else return false. + * @return Return RET_OK if the gesture sends successfully, otherwise refer to the RetError for the failure. */ - bool InjectGesture(const std::shared_ptr &gesturePath); + RetError InjectGesture(const std::shared_ptr &gesturePath); /** * @brief Sends simulate gestures to the screen. * @param gesturePaths The gesture which need to send. - * @return Return true if the gesture sends successfully, else return false. + * @return Return RET_OK if the gesture sends successfully, otherwise refer to the RetError for the failure. */ - bool InjectGesture(const std::vector> &gesturePaths); + RetError InjectGesture(const std::vector> &gesturePaths); /** * @brief Obtains elementInfo of the accessible root node. * @param elementInfo The elementInfo of the accessible root node. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetRoot(AccessibilityElementInfo &elementInfo); + RetError GetRoot(AccessibilityElementInfo &elementInfo); /** * @brief Obtains elementInfo of the accessible root node. * @param windowInfo The source window info to get root. * @param elementInfo The elementInfo of the accessible root node. - * @return Return true if obtains elementInfo successfully, else return false. + * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetRootByWindow(const AccessibilityWindowInfo &windowInfo, + RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo); /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetWindows(std::vector &windows); + RetError GetWindows(std::vector &windows); /** * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. * @param displayId the id of display * @param windows The information of windows. - * @return Return true if obtains windowInfo successfully, else return false. + * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetWindows(const uint64_t displayId, std::vector &windows); + RetError GetWindows(const uint64_t displayId, std::vector &windows); /** * @brief Gets the next focused node in the specified direction of the currently focused node. * @param elementInfo * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection * @param nextElementInfo The info of next element. - * @return Return true if gets next elementInfo successfully, else return false. + * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, + RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo); /** @@ -109,9 +109,9 @@ public: * @param index * @param parent * @param child The element info of child - * @return Return true if gets child elementInfo successfully, else return false. + * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. */ - bool GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, + RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, AccessibilityElementInfo &child); /** @@ -119,18 +119,18 @@ public: * @param elementInfo * @param text specified content * @param elementInfos - * @return Return true if gets elementInfos successfully, else return false. + * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. */ - bool GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, + RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, std::vector &elementInfos); /** * @brief Get Parent node information * @param child * @param parent - * @return Return true if gets info successfully, else return false. + * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. */ - bool GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent); + RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent); /** * @brief Executes a specified action. @@ -150,17 +150,17 @@ public: * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) * action: ACCESSIBILITY_ACTION_SET_TEXT, * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") - * @return true Perform action succeed, otherwise is not. + * @return Return RET_OK if performs action succeed, otherwise refer to the RetError for the failure. */ - bool ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, + RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, const std::map &actionArguments); /** * @brief Set target bundle names. * @param targetBundleNames The target bundle name - * @return Return true if sets target bundle names successfully, else return false. + * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. */ - bool SetTargetBundleName(const std::vector &targetBundleNames); + RetError SetTargetBundleName(const std::vector &targetBundleNames); }; } // namespace Accessibility } // namespace OHOS diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/include/napi_accessibility_element.h b/interfaces/kits/napi/accessibility_extension_module_loader/include/napi_accessibility_element.h index e16237c1b..a293323c0 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/include/napi_accessibility_element.h +++ b/interfaces/kits/napi/accessibility_extension_module_loader/include/napi_accessibility_element.h @@ -16,6 +16,7 @@ #ifndef NAPI_ACCESSIBILITY_ELEMENT_H #define NAPI_ACCESSIBILITY_ELEMENT_H +#include "napi_accessibility_def.h" #include "accessibility_event_info.h" #include "accessibility_window_info.h" #include "napi/native_api.h" @@ -55,7 +56,7 @@ struct NAccessibilityElementData { std::string attribute_ = ""; std::string actionName_ = ""; std::string condition_ = ""; - bool ret_ = false; + OHOS::Accessibility::RetError ret_ = OHOS::Accessibility::RetError::RET_ERR_FAILED; }; class NAccessibilityElement { diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/accessibility_extension_context.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/accessibility_extension_context.cpp index 00394d224..e213825b4 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/accessibility_extension_context.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/accessibility_extension_context.cpp @@ -21,159 +21,161 @@ using namespace std; namespace OHOS { namespace Accessibility { -bool AccessibilityExtensionContext::GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) +RetError AccessibilityExtensionContext::GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetFocus(focusType, elementInfo); } -bool AccessibilityExtensionContext::GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, +RetError AccessibilityExtensionContext::GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetFocusByElementInfo(sourceInfo, focusType, elementInfo); } -bool AccessibilityExtensionContext::InjectGesture(const std::shared_ptr &gesturePath) +RetError AccessibilityExtensionContext::InjectGesture( + const std::shared_ptr &gesturePath) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->InjectGesture(gesturePath); } -bool AccessibilityExtensionContext::InjectGesture( +RetError AccessibilityExtensionContext::InjectGesture( const std::vector> &gesturePaths) { HILOG_DEBUG("This method is temporarily not implemented!"); - return false; + return RET_ERR_NOT_SUPPORT; } -bool AccessibilityExtensionContext::GetRoot(AccessibilityElementInfo &elementInfo) +RetError AccessibilityExtensionContext::GetRoot(AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetRoot(elementInfo); } -bool AccessibilityExtensionContext::GetRootByWindow(const AccessibilityWindowInfo &windowInfo, +RetError AccessibilityExtensionContext::GetRootByWindow(const AccessibilityWindowInfo &windowInfo, AccessibilityElementInfo &elementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetRootByWindow(windowInfo, elementInfo); } -bool AccessibilityExtensionContext::GetWindows(std::vector &windows) +RetError AccessibilityExtensionContext::GetWindows(std::vector &windows) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetWindows(windows); } -bool AccessibilityExtensionContext::GetWindows(const uint64_t displayId, std::vector &windows) +RetError AccessibilityExtensionContext::GetWindows(const uint64_t displayId, + std::vector &windows) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetWindows(displayId, windows); } -bool AccessibilityExtensionContext::GetNext(const AccessibilityElementInfo &elementInfo, +RetError AccessibilityExtensionContext::GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, AccessibilityElementInfo &nextElementInfo) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetNext(elementInfo, direction, nextElementInfo); } -bool AccessibilityExtensionContext::GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, - AccessibilityElementInfo &child) +RetError AccessibilityExtensionContext::GetChildElementInfo(const int32_t index, + const AccessibilityElementInfo &parent, AccessibilityElementInfo &child) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetChildElementInfo(index, parent, child); } -bool AccessibilityExtensionContext::GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, - std::vector &elementInfos) +RetError AccessibilityExtensionContext::GetByContent(const AccessibilityElementInfo &elementInfo, + const std::string &text, std::vector &elementInfos) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetByContent(elementInfo, text, elementInfos); } -bool AccessibilityExtensionContext::GetParentElementInfo(const AccessibilityElementInfo &child, +RetError AccessibilityExtensionContext::GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->GetParentElementInfo(child, parent); } -bool AccessibilityExtensionContext::ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, - const std::map &actionArguments) +RetError AccessibilityExtensionContext::ExecuteAction(const AccessibilityElementInfo &elementInfo, + const ActionType action, const std::map &actionArguments) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->ExecuteAction(elementInfo, action, actionArguments); } -bool AccessibilityExtensionContext::SetTargetBundleName(const std::vector &targetBundleNames) +RetError AccessibilityExtensionContext::SetTargetBundleName(const std::vector &targetBundleNames) { HILOG_DEBUG(); sptr aaClient = AccessibleAbilityClient::GetInstance(); if (!aaClient) { HILOG_ERROR("aaClient is nullptr"); - return false; + return RET_ERR_NULLPTR; } return aaClient->SetTargetBundleName(targetBundleNames); } diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_element.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_element.cpp index 0216386d2..ddaa671ee 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_element.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_element.cpp @@ -186,16 +186,17 @@ napi_value NAccessibilityElement::AttributeNames(napi_env env, napi_callback_inf callbackInfo->env_ = env; napi_value promise = nullptr; - if (argc == ARGS_SIZE_ZERO) { - HILOG_DEBUG("promise mode"); - napi_create_promise(env, &callbackInfo->deferred_, &promise); - } else if (argc == ARGS_SIZE_ONE) { - HILOG_DEBUG("callback mode"); - napi_create_reference(env, argv, 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); + if (argc > ARGS_SIZE_ONE - 1) { + napi_valuetype valueType = napi_null; + napi_typeof(env, argv, &valueType); + if (valueType == napi_function) { + napi_create_reference(env, argv, 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } } else { - HILOG_ERROR("The size of args is err[%{public}zu]", argc); - return ErrorOperation(callbackInfo); + napi_create_promise(env, &callbackInfo->deferred_, &promise); } AccessibilityElement* accessibilityElement = nullptr; @@ -241,7 +242,7 @@ void NAccessibilityElement::AttributeNamesComplete(napi_env env, napi_status sta if (callbackInfo->callback_) { // Callback mode - result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + result[PARAM0] = CreateBusinessError(env, OHOS::Accessibility::RetError::RET_OK); napi_get_reference_value(env, callbackInfo->callback_, &callback); napi_value returnVal; napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &returnVal); @@ -261,44 +262,77 @@ napi_value NAccessibilityElement::AttributeValue(napi_env env, napi_callback_inf napi_value argv[ARGS_SIZE_TWO] = {0}; napi_value thisVar = nullptr; void* data = nullptr; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + if (status != napi_ok) { + HILOG_ERROR("Failed to get cb info"); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_FAILED); + napi_throw(env, err); + return nullptr; + } HILOG_DEBUG("argc = %{public}d", (int)argc); + // Unwrap AccessibilityElement + AccessibilityElement* accessibilityElement = nullptr; + status = napi_unwrap(env, thisVar, (void**)&accessibilityElement); + if (!accessibilityElement || status != napi_ok) { + HILOG_ERROR("accessibilityElement is null or status[%{public}d] is wrong", status); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_NULLPTR); + napi_throw(env, err); + return nullptr; + } + NAccessibilityElementData *callbackInfo = new(std::nothrow) NAccessibilityElementData(); if (!callbackInfo) { HILOG_ERROR("Failed to create callbackInfo."); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_NULLPTR); + napi_throw(env, err); return nullptr; } callbackInfo->env_ = env; + callbackInfo->accessibilityElement_ = *accessibilityElement; + + NAccessibilityErrorCode errCode = NAccessibilityErrorCode::ACCESSIBILITY_OK; + if (argc < ARGS_SIZE_TWO - 1) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM; + } + + if (errCode == NAccessibilityErrorCode::ACCESSIBILITY_OK) { + // Parse attribute name + std::string attribute = ""; + if (ParseString(env, attribute, argv[PARAM0])) { + HILOG_INFO("attribute = %{public}s", attribute.c_str()); + callbackInfo->attribute_ = attribute; + } else { + errCode = NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM; + } + } + + if (errCode == NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM) { + delete callbackInfo; + callbackInfo = nullptr; + delete accessibilityElement; + accessibilityElement = nullptr; + napi_value err = CreateBusinessError(env, RetError::RET_ERR_INVALID_PARAM); + HILOG_ERROR("invalid param"); + napi_throw(env, err); + return nullptr; + } napi_value promise = nullptr; - if (argc == ARGS_SIZE_ONE) { - // Promise mode - napi_create_promise(env, &callbackInfo->deferred_, &promise); - } else if (argc == ARGS_SIZE_TWO) { - // Callback mode - napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); + if (argc > ARGS_SIZE_TWO - 1) { + napi_valuetype valueType = napi_null; + napi_typeof(env, argv[PARAM1], &valueType); + if (valueType == napi_function) { + napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } } else { - HILOG_ERROR("The size of args is err[%{public}zu]", argc); - return ErrorOperation(callbackInfo); + napi_create_promise(env, &callbackInfo->deferred_, &promise); } - // Parse attribute name - std::string attribute = ""; - ParseString(env, attribute, argv[PARAM0]); - HILOG_INFO("attribute = %{public}s", attribute.c_str()); - callbackInfo->attribute_ = attribute; - - // Unwrap AccessibilityElement - AccessibilityElement* accessibilityElement = nullptr; - napi_status status = napi_unwrap(env, thisVar, (void**)&accessibilityElement); - if (!accessibilityElement || status != napi_ok) { - HILOG_ERROR("accessibilityElement is null or status[%{public}d] is wrong", status); - return ErrorOperation(callbackInfo); - } - callbackInfo->accessibilityElement_ = *accessibilityElement; - napi_value resource = nullptr; napi_create_string_utf8(env, "AttributeValue", NAPI_AUTO_LENGTH, &resource); napi_create_async_work(env, nullptr, resource, NAccessibilityElement::AttributeValueExecute, @@ -337,7 +371,7 @@ void NAccessibilityElement::AttributeValueExecute(napi_env env, void* data) HILOG_ERROR("windowInfo is nullptr"); } } else { - callbackInfo->ret_ = true; + callbackInfo->ret_ = RET_OK; } HILOG_INFO("attribute[%{public}s], result[%{public}d]", callbackInfo->attribute_.c_str(), callbackInfo->ret_); } @@ -357,7 +391,7 @@ void NAccessibilityElement::AttributeValueComplete(napi_env env, napi_status sta if (elementIter == elementInfoCompleteMap.end()) { HILOG_ERROR("There is no the attribute[%{public}s] in element info", callbackInfo->attribute_.c_str()); napi_get_undefined(callbackInfo->env_, &result[PARAM1]); - callbackInfo->ret_ = false; + callbackInfo->ret_ = RET_ERR_PROPERTY_NOT_EXIST; } else { (*elementIter->second)(callbackInfo, result[PARAM1]); } @@ -367,25 +401,25 @@ void NAccessibilityElement::AttributeValueComplete(napi_env env, napi_status sta if (windowIter == windowInfoCompleteMap.end()) { HILOG_ERROR("There is no the attribute[%{public}s]", callbackInfo->attribute_.c_str()); napi_get_undefined(callbackInfo->env_, &result[PARAM1]); - callbackInfo->ret_ = false; + callbackInfo->ret_ = RET_ERR_PROPERTY_NOT_EXIST; } else { (*windowIter->second)(callbackInfo, result[PARAM1]); } } HILOG_DEBUG("result is %{public}d", callbackInfo->ret_); + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); if (callbackInfo->callback_) { - result[PARAM0] = callbackInfo->ret_ ? GetErrorValue(env, CODE_SUCCESS) : GetErrorValue(env, CODE_FAILED); napi_value callback, returnVal, undefined; napi_get_reference_value(env, callbackInfo->callback_, &callback); napi_get_undefined(env, &undefined); napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &returnVal); napi_delete_reference(env, callbackInfo->callback_); } else { - if (callbackInfo->ret_) { + if (callbackInfo->ret_ == RET_OK) { napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); } else { - napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM1]); + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); } } napi_delete_async_work(env, callbackInfo->work_); @@ -402,7 +436,7 @@ bool NAccessibilityElement::CheckElementInfoParameter(NAccessibilityElementData if (!callbackInfo->accessibilityElement_.elementInfo_) { HILOG_ERROR("element info is nullptr"); napi_get_undefined(callbackInfo->env_, &value); - callbackInfo->ret_ = false; + callbackInfo->ret_ = RET_ERR_FAILED; return false; } return true; @@ -726,10 +760,10 @@ void NAccessibilityElement::GetElementInfoTextMoveUnit(NAccessibilityElementData callbackInfo->accessibilityElement_.elementInfo_->GetTextMovementStep()); HILOG_DEBUG("ConvertTextMoveUnitToString: [%{public}s]", textMoveUnit.c_str()); if (textMoveUnit == "") { - callbackInfo->ret_ = false; + callbackInfo->ret_ = RET_ERR_FAILED; napi_get_undefined(callbackInfo->env_, &value); } else { - callbackInfo->ret_ = true; + callbackInfo->ret_ = RET_OK; NAPI_CALL_RETURN_VOID(callbackInfo->env_, napi_create_string_utf8(callbackInfo->env_, textMoveUnit.c_str(), NAPI_AUTO_LENGTH, &value)); } @@ -740,7 +774,7 @@ void NAccessibilityElement::GetElementInfoParent(NAccessibilityElementData *call if (!CheckElementInfoParameter(callbackInfo, value)) { return; } - if (callbackInfo->ret_) { + if (callbackInfo->ret_ == RET_OK) { napi_value constructor = nullptr; NAPI_CALL_RETURN_VOID(callbackInfo->env_, napi_get_reference_value(callbackInfo->env_, NAccessibilityElement::consRef_, &constructor)); @@ -758,7 +792,7 @@ void NAccessibilityElement::GetElementInfoChildren(NAccessibilityElementData *ca if (!CheckElementInfoParameter(callbackInfo, value)) { return; } - if (callbackInfo->ret_) { + if (callbackInfo->ret_ == RET_OK) { NAPI_CALL_RETURN_VOID(callbackInfo->env_, napi_create_array(callbackInfo->env_, &value)); ConvertElementInfosToJS(callbackInfo->env_, value, callbackInfo->nodeInfos_); } else { @@ -776,10 +810,10 @@ void NAccessibilityElement::GetElementInfoTriggerAction(NAccessibilityElementDat callbackInfo->accessibilityElement_.elementInfo_->GetTriggerAction()); HILOG_DEBUG("GetElementInfoTriggerAction: [%{public}s]", triggerAction.c_str()); if (triggerAction == "") { - callbackInfo->ret_ = false; + callbackInfo->ret_ = RET_ERR_FAILED; napi_get_undefined(callbackInfo->env_, &value); } else { - callbackInfo->ret_ = true; + callbackInfo->ret_ = RET_OK; NAPI_CALL_RETURN_VOID(callbackInfo->env_, napi_create_string_utf8(callbackInfo->env_, triggerAction.c_str(), NAPI_AUTO_LENGTH, &value)); } @@ -841,7 +875,7 @@ bool NAccessibilityElement::CheckWindowInfoParameter(NAccessibilityElementData * if (!callbackInfo->accessibilityElement_.windowInfo_) { HILOG_ERROR("window info is nullptr"); napi_get_undefined(callbackInfo->env_, &value); - callbackInfo->ret_ = false; + callbackInfo->ret_ = RET_ERR_FAILED; return false; } return true; @@ -884,10 +918,10 @@ void NAccessibilityElement::GetWindowInfoType(NAccessibilityElementData *callbac callbackInfo->accessibilityElement_.windowInfo_->GetAccessibilityWindowType()); HILOG_DEBUG("GetWindowInfoType: [%{public}s]", accessibilityWindowType.c_str()); if (accessibilityWindowType == "") { - callbackInfo->ret_ = false; + callbackInfo->ret_ = RET_ERR_FAILED; napi_get_undefined(callbackInfo->env_, &value); } else { - callbackInfo->ret_ = true; + callbackInfo->ret_ = RET_OK; NAPI_CALL_RETURN_VOID(callbackInfo->env_, napi_create_string_utf8(callbackInfo->env_, accessibilityWindowType.c_str(), NAPI_AUTO_LENGTH, &value)); } @@ -898,7 +932,7 @@ void NAccessibilityElement::GetWindowInfoRootElement(NAccessibilityElementData * if (!CheckWindowInfoParameter(callbackInfo, value)) { return; } - if (callbackInfo->ret_) { + if (callbackInfo->ret_ == RET_OK) { napi_value constructor = nullptr; NAPI_CALL_RETURN_VOID(callbackInfo->env_, napi_get_reference_value(callbackInfo->env_, NAccessibilityElement::consRef_, &constructor)); @@ -947,16 +981,17 @@ napi_value NAccessibilityElement::ActionNames(napi_env env, napi_callback_info i callbackInfo->env_ = env; napi_value promise = nullptr; - if (argc == ARGS_SIZE_ZERO) { - HILOG_DEBUG("promise mode"); - napi_create_promise(env, &callbackInfo->deferred_, &promise); - } else if (argc == ARGS_SIZE_ONE) { - HILOG_DEBUG("callback mode"); - napi_create_reference(env, argv, 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); + if (argc > ARGS_SIZE_ONE - 1) { + napi_valuetype valueType = napi_null; + napi_typeof(env, argv, &valueType); + if (valueType == napi_function) { + napi_create_reference(env, argv, 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } } else { - HILOG_ERROR("The size of args is err[%{public}zu]", argc); - return ErrorOperation(callbackInfo); + napi_create_promise(env, &callbackInfo->deferred_, &promise); } AccessibilityElement* accessibilityElement = nullptr; @@ -1010,13 +1045,13 @@ void NAccessibilityElement::ActionNamesComplete(napi_env env, napi_status status ConvertStringVecToJS(env, result[PARAM1], actionNames); } else { HILOG_ERROR("no elementInfo_"); + callbackInfo->ret_ = RET_ERR_FAILED; napi_get_undefined(env, &result[PARAM1]); } + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); if (callbackInfo->callback_) { // Callback mode - result[PARAM0] = callbackInfo->accessibilityElement_.elementInfo_ ? - GetErrorValue(env, CODE_SUCCESS) : GetErrorValue(env, CODE_FAILED); napi_get_reference_value(env, callbackInfo->callback_, &callback); napi_value returnVal; napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &returnVal); @@ -1026,7 +1061,7 @@ void NAccessibilityElement::ActionNamesComplete(napi_env env, napi_status status if (callbackInfo->accessibilityElement_.elementInfo_) { napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); } else { - napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM1]); + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); } } napi_delete_async_work(env, callbackInfo->work_); @@ -1040,67 +1075,101 @@ napi_value NAccessibilityElement::PerformAction(napi_env env, napi_callback_info napi_value argv[ARGS_SIZE_THREE] = {0}; napi_value thisVar; void* data = nullptr; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + if (status != napi_ok) { + HILOG_ERROR("Failed to get cb info"); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_FAILED); + napi_throw(env, err); + return nullptr; + } HILOG_DEBUG("argc = %{public}zu", argc); + // Unwrap AccessibilityElement + AccessibilityElement* accessibilityElement = nullptr; + status = napi_unwrap(env, thisVar, (void**)&accessibilityElement); + if (!accessibilityElement || status != napi_ok) { + HILOG_ERROR("accessibilityElement is null or status[%{public}d] is wrong", status); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_NULLPTR); + napi_throw(env, err); + return nullptr; + } + if (!(accessibilityElement->isElementInfo_ && accessibilityElement->elementInfo_)) { + HILOG_ERROR("accessibilityElement is wrong. isElementInfo_[%{public}d]", accessibilityElement->isElementInfo_); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_FAILED); + napi_throw(env, err); + return nullptr; + } + NAccessibilityElementData *callbackInfo = new(std::nothrow) NAccessibilityElementData(); if (!callbackInfo) { HILOG_ERROR("Failed to create callbackInfo."); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_NULLPTR); + napi_throw(env, err); return nullptr; } callbackInfo->env_ = env; + NAccessibilityErrorCode errCode = NAccessibilityErrorCode::ACCESSIBILITY_OK; + if (argc < ARGS_SIZE_ONE) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM; + } + std::string actionName; + if (errCode == NAccessibilityErrorCode::ACCESSIBILITY_OK) { + if (!ParseString(env, actionName, argv[PARAM0])) { + HILOG_ERROR("parse action name failed"); + errCode = NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM; + } + } + + if (errCode == NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM) { + delete callbackInfo; + callbackInfo = nullptr; + delete accessibilityElement; + accessibilityElement = nullptr; + napi_value err = CreateBusinessError(env, RetError::RET_ERR_INVALID_PARAM); + HILOG_ERROR("invalid param"); + napi_throw(env, err); + return nullptr; + } + napi_value promise = nullptr; std::map actionArguments {}; - if (argc == ARGS_SIZE_ONE) { - // Promise mode - napi_create_promise(env, &callbackInfo->deferred_, &promise); - ParseString(env, actionName, argv[PARAM0]); - } else if (argc == ARGS_SIZE_TWO) { - ParseString(env, actionName, argv[PARAM0]); - napi_valuetype valuetype; - napi_status status = napi_typeof(env, argv[PARAM1], &valuetype); - if (status != napi_ok) { - HILOG_ERROR("napi_typeof error and status is %{public}d", status); - return ErrorOperation(callbackInfo); + if (argc == ARGS_SIZE_THREE) { + napi_valuetype secondParamType = napi_null; + napi_typeof(env, argv[PARAM1], &secondParamType); + napi_valuetype thirdParamType = napi_null; + napi_typeof(env, argv[PARAM2], &thirdParamType); + if (secondParamType == napi_undefined && thirdParamType == napi_function) { + ConvertActionArgsJSToNAPI(env, argv[PARAM1], actionArguments, + ConvertStringToAccessibleOperationType(actionName)); + napi_create_reference(env, argv[PARAM2], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_INFO("argc is three, use promise"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); } - - if (valuetype == napi_function) { - // Callback mode + } else if (argc == ARGS_SIZE_TWO) { + napi_valuetype valueType = napi_null; + napi_typeof(env, argv[PARAM1], &valueType); + if (valueType == napi_function) { napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); napi_get_undefined(env, &promise); } else { - // Promise mode + if (valueType == napi_undefined) { + ConvertActionArgsJSToNAPI(env, argv[PARAM1], actionArguments, + ConvertStringToAccessibleOperationType(actionName)); + } + HILOG_INFO("argc is two, use promise"); napi_create_promise(env, &callbackInfo->deferred_, &promise); - HILOG_INFO("actionName = %{public}s", actionName.c_str()); - ConvertActionArgsJSToNAPI(env, argv[PARAM1], actionArguments, - ConvertStringToAccessibleOperationType(actionName)); } - } else if (argc == ARGS_SIZE_THREE) { - // Callback mode - ParseString(env, actionName, argv[PARAM0]); - HILOG_INFO("actionName = %{public}s", actionName.c_str()); - ConvertActionArgsJSToNAPI(env, argv[PARAM1], actionArguments, - ConvertStringToAccessibleOperationType(actionName)); - napi_create_reference(env, argv[PARAM2], 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); } else { - HILOG_ERROR("The size of args is err[%{public}zu]", argc); - return ErrorOperation(callbackInfo); + HILOG_INFO("argc is others, use promise"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); } - // Unwrap AccessibilityElement - AccessibilityElement* accessibilityElement = nullptr; - napi_status status = napi_unwrap(env, thisVar, (void**)&accessibilityElement); - if (!accessibilityElement || status != napi_ok) { - HILOG_ERROR("accessibilityElement is null or status[%{public}d] is wrong", status); - return ErrorOperation(callbackInfo); - } - if (!(accessibilityElement->isElementInfo_ && accessibilityElement->elementInfo_)) { - HILOG_ERROR("accessibilityElement is wrong. isElementInfo_[%{public}d]", accessibilityElement->isElementInfo_); - return ErrorOperation(callbackInfo); - } + HILOG_INFO("actionName = %{public}s", actionName.c_str()); callbackInfo->accessibilityElement_ = *accessibilityElement; callbackInfo->actionName_ = actionName; callbackInfo->actionArguments_ = actionArguments; @@ -1123,6 +1192,11 @@ void NAccessibilityElement::PerformActionExecute(napi_env env, void* data) } ActionType action = ConvertStringToAccessibleOperationType(callbackInfo->actionName_); + if (action == ActionType::ACCESSIBILITY_ACTION_INVALID) { + HILOG_ERROR("The action is not supported"); + callbackInfo->ret_ = OHOS::Accessibility::RetError::RET_ERR_ACTION_NOT_SUPPORT; + return; + } callbackInfo->ret_ = AccessibleAbilityClient::GetInstance()->ExecuteAction( *callbackInfo->accessibilityElement_.elementInfo_, action, callbackInfo->actionArguments_); HILOG_DEBUG("callbackInfo->ret_[%{public}d]", callbackInfo->ret_); @@ -1140,17 +1214,21 @@ void NAccessibilityElement::PerformActionComplete(napi_env env, napi_status stat napi_value callback = 0; napi_value undefined = 0; napi_get_undefined(env, &undefined); - napi_get_boolean(callbackInfo->env_, callbackInfo->ret_, &result[PARAM1]); + napi_get_undefined(env, &result[PARAM1]); + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); if (callbackInfo->callback_) { // Callback mode - result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); napi_get_reference_value(env, callbackInfo->callback_, &callback); napi_value returnVal; napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &returnVal); napi_delete_reference(env, callbackInfo->callback_); } else { // Promise mode - napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + if (callbackInfo->ret_ == RET_OK) { + napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); + } } napi_delete_async_work(env, callbackInfo->work_); @@ -1164,52 +1242,98 @@ napi_value NAccessibilityElement::FindElement(napi_env env, napi_callback_info i napi_value argv[ARGS_SIZE_THREE] = {0}; napi_value thisVar; void* data = nullptr; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); + if (status != napi_ok) { + HILOG_ERROR("Failed to get cb info"); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_FAILED); + napi_throw(env, err); + return nullptr; + } HILOG_DEBUG("argc = %{public}d", (int)argc); + // Unwrap AccessibilityElement + AccessibilityElement* accessibilityElement = nullptr; + status = napi_unwrap(env, thisVar, (void**)&accessibilityElement); + if (!accessibilityElement || status != napi_ok) { + HILOG_ERROR("accessibilityElement is null or status[%{public}d] is wrong", status); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_NULLPTR); + napi_throw(env, err); + return nullptr; + } + if (!accessibilityElement->isElementInfo_) { + HILOG_ERROR("Type of AccessibilityElement is not right"); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_FAILED); + napi_throw(env, err); + return nullptr; + } + NAccessibilityElementData *callbackInfo = new(std::nothrow) NAccessibilityElementData(); if (!callbackInfo) { HILOG_ERROR("Failed to create callbackInfo."); + napi_value err = CreateBusinessError(env, RetError::RET_ERR_NULLPTR); + napi_throw(env, err); return nullptr; } callbackInfo->env_ = env; + NAccessibilityErrorCode errCode = NAccessibilityErrorCode::ACCESSIBILITY_OK; + if (argc < ARGS_SIZE_THREE - 1) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM; + } + + if (errCode == NAccessibilityErrorCode::ACCESSIBILITY_OK) { + // Parse conditionType name + std::string conditionType = ""; + if (ParseString(env, conditionType, argv[PARAM0])) { + HILOG_INFO("conditionType = %{public}s", conditionType.c_str()); + if (std::strcmp(conditionType.c_str(), "content") != 0 && + std::strcmp(conditionType.c_str(), "focusType") != 0 && + std::strcmp(conditionType.c_str(), "focusDirection") != 0) { + HILOG_ERROR("argv[PARAM0] is wrong[%{public}s", conditionType.c_str()); + errCode = NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM; + } else { + callbackInfo->conditionId_ = ConvertStringToCondition(conditionType); + } + } else { + errCode = NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM; + } + + // Parse queryData name + std::string queryData = ""; + if (ParseString(env, queryData, argv[PARAM1])) { + HILOG_INFO("queryData = %{public}s", queryData.c_str()); + callbackInfo->condition_ = queryData; + } else { + errCode = NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM; + } + } + + if (errCode == NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM) { + delete callbackInfo; + callbackInfo = nullptr; + delete accessibilityElement; + accessibilityElement = nullptr; + napi_value err = CreateBusinessError(env, RetError::RET_ERR_INVALID_PARAM); + HILOG_ERROR("invalid param"); + napi_throw(env, err); + return nullptr; + } + napi_value promise = nullptr; - if (argc == ARGS_SIZE_TWO) { - // Promise mode - napi_create_promise(env, &callbackInfo->deferred_, &promise); - } else if (argc == ARGS_SIZE_THREE) { - // Callback mode - napi_create_reference(env, argv[PARAM2], 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); + if (argc > ARGS_SIZE_THREE - 1) { + napi_valuetype valueType = napi_null; + napi_typeof(env, argv[PARAM2], &valueType); + if (valueType == napi_function) { + napi_create_reference(env, argv[PARAM2], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } } else { - HILOG_ERROR("The size of args is err[%{public}zu]", argc); - return ErrorOperation(callbackInfo); + napi_create_promise(env, &callbackInfo->deferred_, &promise); } - // Parse conditionType name - std::string conditionType = ""; - ParseString(env, conditionType, argv[PARAM0]); - HILOG_INFO("conditionType = %{public}s", conditionType.c_str()); - callbackInfo->conditionId_ = ConvertStringToCondition(conditionType); - - // Parse queryData name - std::string queryData = ""; - ParseString(env, queryData, argv[PARAM1]); - HILOG_INFO("queryData = %{public}s", queryData.c_str()); - callbackInfo->condition_ = queryData; - - // Unwrap AccessibilityElement - AccessibilityElement* accessibilityElement = nullptr; - napi_status status = napi_unwrap(env, thisVar, (void**)&accessibilityElement); - if (!accessibilityElement || status != napi_ok) { - HILOG_ERROR("accessibilityElement is null or status[%{public}d] is wrong", status); - return ErrorOperation(callbackInfo); - } - if (!accessibilityElement->isElementInfo_) { - HILOG_ERROR("Type of AccessibilityElement is not right"); - return ErrorOperation(callbackInfo); - } callbackInfo->accessibilityElement_ = *accessibilityElement; napi_value resource = nullptr; @@ -1231,7 +1355,7 @@ void NAccessibilityElement::FindElementExecute(napi_env env, void* data) switch (callbackInfo->conditionId_) { case FindElementCondition::FIND_ELEMENT_CONDITION_INVALID: HILOG_ERROR("condition id is invalid"); - callbackInfo->ret_ = false; + callbackInfo->ret_ = RET_ERR_INVALID_PARAM; return; case FindElementCondition::FIND_ELEMENT_CONDITION_CONTENT: callbackInfo->ret_ = AccessibleAbilityClient::GetInstance()->GetByContent( @@ -1243,7 +1367,8 @@ void NAccessibilityElement::FindElementExecute(napi_env env, void* data) int32_t focusType = ConvertStringToFocusType(callbackInfo->condition_); HILOG_INFO("focusType is %{public}d", focusType); callbackInfo->ret_ = AccessibleAbilityClient::GetInstance()->GetFocusByElementInfo( - *(callbackInfo->accessibilityElement_.elementInfo_), focusType, callbackInfo->nodeInfo_); + *(callbackInfo->accessibilityElement_.elementInfo_), + focusType, callbackInfo->nodeInfo_); } break; case FindElementCondition::FIND_ELEMENT_CONDITION_FOCUS_DIRECTION: @@ -1251,7 +1376,8 @@ void NAccessibilityElement::FindElementExecute(napi_env env, void* data) FocusMoveDirection direction = ConvertStringToDirection(callbackInfo->condition_); HILOG_INFO("direction is %{public}d", direction); callbackInfo->ret_ = AccessibleAbilityClient::GetInstance()->GetNext( - *(callbackInfo->accessibilityElement_.elementInfo_), direction, callbackInfo->nodeInfo_); + *(callbackInfo->accessibilityElement_.elementInfo_), direction, + callbackInfo->nodeInfo_); } break; default: @@ -1270,9 +1396,9 @@ void NAccessibilityElement::FindElementComplete(napi_env env, napi_status status napi_value result[ARGS_SIZE_TWO] = {0}; GetElement(callbackInfo, result[PARAM1]); + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); if (callbackInfo->callback_) { HILOG_DEBUG("callback mode. result is %{public}d", callbackInfo->ret_); - result[PARAM0] = callbackInfo->ret_ ? GetErrorValue(env, CODE_SUCCESS) : GetErrorValue(env, CODE_FAILED); napi_value callback = 0; napi_get_reference_value(env, callbackInfo->callback_, &callback); napi_value returnVal; @@ -1282,10 +1408,10 @@ void NAccessibilityElement::FindElementComplete(napi_env env, napi_status status napi_delete_reference(env, callbackInfo->callback_); } else { HILOG_DEBUG("promise mode. result is %{public}d", callbackInfo->ret_); - if (callbackInfo->ret_) { + if (callbackInfo->ret_ == RET_OK) { napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); } else { - napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM1]); + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); } } napi_delete_async_work(env, callbackInfo->work_); @@ -1297,7 +1423,7 @@ void NAccessibilityElement::GetElement(NAccessibilityElementData *callbackInfo, { HILOG_INFO("condition id[%{public}d]", callbackInfo->conditionId_); napi_env env = callbackInfo->env_; - if (!callbackInfo->ret_) { + if (callbackInfo->ret_ != RET_OK) { HILOG_ERROR("GetElementInfo failed!"); napi_get_undefined(env, &value); return; @@ -1306,7 +1432,7 @@ void NAccessibilityElement::GetElement(NAccessibilityElementData *callbackInfo, switch (callbackInfo->conditionId_) { case FindElementCondition::FIND_ELEMENT_CONDITION_INVALID: HILOG_ERROR("condition id is invalid"); - callbackInfo->ret_ = false; + callbackInfo->ret_ = RET_ERR_INVALID_PARAM; return; case FindElementCondition::FIND_ELEMENT_CONDITION_CONTENT: napi_create_array(env, &value); @@ -1365,9 +1491,9 @@ napi_value NAccessibilityElement::ErrorOperation(NAccessibilityElementData *call napi_value callback = 0; napi_value undefined = 0; napi_get_undefined(env, &undefined); + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); if (callbackInfo->callback_) { // Callback mode - result[PARAM0] = GetErrorValue(env, CODE_FAILED); result[PARAM1] = undefined; napi_get_reference_value(env, callbackInfo->callback_, &callback); napi_value returnVal; @@ -1375,7 +1501,7 @@ napi_value NAccessibilityElement::ErrorOperation(NAccessibilityElementData *call napi_delete_reference(env, callbackInfo->callback_); } else { // Promise mode - napi_reject_deferred(env, callbackInfo->deferred_, undefined); + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); } napi_delete_async_work(env, callbackInfo->work_); delete callbackInfo; diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp index 0a49176bd..1c19e23dd 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp @@ -219,12 +219,12 @@ std::shared_ptr NAccessibilityExtension::GetElement(const std::shared_ptr element = nullptr; if (componentId > 0) { std::shared_ptr elementInfo = std::make_shared(); - if (aaClient->GetSource(eventInfo, *elementInfo)) { + if (aaClient->GetSource(eventInfo, *elementInfo) == RET_OK) { element = std::make_shared(elementInfo); } } else if (windowId > 0) { std::shared_ptr windowInfo = std::make_shared(); - if (aaClient->GetWindow(windowId, *windowInfo)) { + if (aaClient->GetWindow(windowId, *windowInfo) == RET_OK) { element = std::make_shared(windowInfo); } } else { diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension_context.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension_context.cpp index 50f6c88cb..13f819235 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension_context.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension_context.cpp @@ -29,10 +29,6 @@ using namespace OHOS::AccessibilityNapi; namespace OHOS { namespace Accessibility { namespace { -constexpr int32_t CONTEXT_ERROR = 1; -constexpr int32_t PARAMETER_ERROR = 2; -constexpr int32_t RESULT_ERROR = 3; - static void ConvertAccessibilityWindowInfoToJS( napi_env env, napi_value result, const AccessibilityWindowInfo& accessibilityWindowInfo) { @@ -146,16 +142,20 @@ private: auto context = weak.lock(); if (!context) { HILOG_ERROR("context is released"); - task.Reject(engine, CreateJsError(engine, CONTEXT_ERROR, "Context is released")); + task.Reject(engine, CreateJsError(engine, + static_cast(NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY), + ERROR_MESSAGE_SYSTEM_ABNORMALITY)); return; } - bool ret = context->SetTargetBundleName(targetBundleNames); - if (ret) { + RetError ret = context->SetTargetBundleName(targetBundleNames); + if (ret == RET_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { HILOG_ERROR("set target bundle name failed. ret: %{public}d.", ret); - task.Reject(engine, CreateJsError(engine, RESULT_ERROR, "set target bundle name failed.")); + task.Reject(engine, CreateJsError(engine, + static_cast(NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY), + ERROR_MESSAGE_SYSTEM_ABNORMALITY)); } }; @@ -207,13 +207,15 @@ private: auto context = weak.lock(); if (!context) { HILOG_ERROR("context is released"); - task.Reject(engine, CreateJsError(engine, CONTEXT_ERROR, "Context is released")); + task.Reject(engine, CreateJsError(engine, + static_cast(NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY), + ERROR_MESSAGE_SYSTEM_ABNORMALITY)); return; } OHOS::Accessibility::AccessibilityElementInfo elementInfo; - bool ret = context->GetFocus(focus, elementInfo); - if (ret) { + RetError ret = context->GetFocus(focus, elementInfo); + if (ret == RET_OK) { napi_value constructor = nullptr; napi_get_reference_value(reinterpret_cast(&engine), NAccessibilityElement::consRef_, &constructor); @@ -225,7 +227,9 @@ private: task.Resolve(engine, nativeElementInfo); } else { HILOG_ERROR("Get focus elementInfo failed. ret: %{public}d", ret); - task.Reject(engine, CreateJsError(engine, RESULT_ERROR, "Get focus elementInfo failed.")); + task.Reject(engine, CreateJsError(engine, + static_cast(ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(ret).errCode), + ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(ret).message)); } }; @@ -277,13 +281,15 @@ private: auto context = weak.lock(); if (!context) { HILOG_ERROR("context is released"); - task.Reject(engine, CreateJsError(engine, CONTEXT_ERROR, "Context is released")); + task.Reject(engine, CreateJsError(engine, + static_cast(NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY), + ERROR_MESSAGE_SYSTEM_ABNORMALITY)); return; } HILOG_DEBUG("isActiveWindow[%{public}d] windowId[%{public}d]", isActiveWindow, windowId); OHOS::Accessibility::AccessibilityElementInfo elementInfo; - bool ret = false; + RetError ret = RET_OK; if (isActiveWindow) { ret = context->GetRoot(elementInfo); } else { @@ -291,7 +297,7 @@ private: windowInfo.SetWindowId(windowId); ret = context->GetRootByWindow(windowInfo, elementInfo); } - if (ret) { + if (ret == RET_OK) { napi_value constructor = nullptr; napi_get_reference_value(reinterpret_cast(&engine), NAccessibilityElement::consRef_, &constructor); @@ -305,7 +311,9 @@ private: task.Resolve(engine, nativeElementInfo); } else { HILOG_ERROR("Get root elementInfo failed. ret : %{public}d", ret); - task.Reject(engine, CreateJsError(engine, RESULT_ERROR, "Get root elementInfo failed.")); + task.Reject(engine, CreateJsError(engine, + static_cast(ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(ret).errCode), + ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(ret).message)); } }; @@ -365,13 +373,15 @@ private: auto context = weak.lock(); if (!context) { HILOG_ERROR("context is released"); - task.Reject(engine, CreateJsError(engine, CONTEXT_ERROR, "Context is released")); + task.Reject(engine, CreateJsError(engine, + static_cast(NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY), + ERROR_MESSAGE_SYSTEM_ABNORMALITY)); return; } std::vector accessibilityWindows; - bool ret = context->GetWindows(accessibilityWindows); - if (ret) { + RetError ret = context->GetWindows(accessibilityWindows); + if (ret == RET_OK) { napi_value napiWindowInfos = nullptr; napi_create_array(reinterpret_cast(&engine), &napiWindowInfos); ConvertAccessibilityWindowInfosToJS( @@ -380,7 +390,9 @@ private: task.Resolve(engine, nativeWindowInfos); } else { HILOG_ERROR("Get windowInfos failed."); - task.Reject(engine, CreateJsError(engine, RESULT_ERROR, "Get windowInfos failed.")); + task.Reject(engine, CreateJsError(engine, + static_cast(ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(ret).errCode), + ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(ret).message)); } }; @@ -399,19 +411,23 @@ private: auto context = weak.lock(); if (!context) { HILOG_ERROR("context is released"); - task.Reject(engine, CreateJsError(engine, CONTEXT_ERROR, "Context is released")); + task.Reject(engine, CreateJsError(engine, + static_cast(NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY), + ERROR_MESSAGE_SYSTEM_ABNORMALITY)); return; } if (displayId < 0) { HILOG_ERROR("displayId is error: %{public}" PRId64 "", displayId); - task.Reject(engine, CreateJsError(engine, PARAMETER_ERROR, "displayId is error")); + task.Reject(engine, CreateJsError(engine, + static_cast(NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM), + ERROR_MESSAGE_PARAMETER_ERROR)); return; } std::vector accessibilityWindows; - bool ret = context->GetWindows(static_cast(displayId), accessibilityWindows); - if (ret) { + RetError ret = context->GetWindows(static_cast(displayId), accessibilityWindows); + if (ret == RET_OK) { napi_value napiWindowInfos = nullptr; napi_create_array(reinterpret_cast(&engine), &napiWindowInfos); ConvertAccessibilityWindowInfosToJS( @@ -420,7 +436,9 @@ private: task.Resolve(engine, nativeWindowInfos); } else { HILOG_ERROR("Get windowInfos failed."); - task.Reject(engine, CreateJsError(engine, RESULT_ERROR, "Get windowInfos failed.")); + task.Reject(engine, CreateJsError(engine, + static_cast(ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(ret).errCode), + ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(ret).message)); } }; @@ -454,20 +472,24 @@ private: auto context = weak.lock(); if (!context) { HILOG_ERROR("context is released"); - task.Reject(engine, CreateJsError(engine, CONTEXT_ERROR, "Context is released")); + task.Reject(engine, CreateJsError(engine, + static_cast(NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY), + ERROR_MESSAGE_SYSTEM_ABNORMALITY)); return; } - bool ret = false; + RetError ret = RET_OK; if (isParameterArray) { ret = context->InjectGesture(gesturePathArray); } else { ret = context->InjectGesture(gesturePath); } - if (ret) { + if (ret == RET_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { HILOG_ERROR("Gesture inject failed. ret: %{public}d.", ret); - task.Reject(engine, CreateJsError(engine, RESULT_ERROR, "Gesture inject failed.")); + task.Reject(engine, CreateJsError(engine, + static_cast(ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(ret).errCode), + ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(ret).message)); } }; diff --git a/interfaces/kits/napi/include/napi_accessibility_def.h b/interfaces/kits/napi/include/napi_accessibility_def.h index 7ff49c30d..ae6a92826 100644 --- a/interfaces/kits/napi/include/napi_accessibility_def.h +++ b/interfaces/kits/napi/include/napi_accessibility_def.h @@ -18,6 +18,9 @@ #include #include +#include +#include +#include "accessibility_def.h" constexpr size_t CALLBACK_SIZE = 1; constexpr size_t ARGS_SIZE_ZERO = 0; @@ -32,5 +35,79 @@ constexpr int32_t PARAM2 = 2; constexpr int32_t CODE_SUCCESS = 0; constexpr int32_t CODE_FAILED = -1; constexpr int32_t CHAE_BUFFER_MAX = 1024; +const std::string ERROR_MESSAGE_PARAMETER_ERROR = "Input parameter error"; +const std::string ERROR_MESSAGE_NO_PERMISSION = "Permission denied"; +const std::string ERROR_MESSAGE_NO_RIGHT = "Do not have accessibility right for this operation"; +const std::string ERROR_MESSAGE_SYSTEM_ABNORMALITY = "System abnormality"; +const std::string ERROR_MESSAGE_PROPERTY_NOT_EXIST = "This property does not exist"; +const std::string ERROR_MESSAGE_ACTION_NOT_SUPPORT = "This action is not supported"; +const std::string ERROR_MESSAGE_INVALID_BUNDLE_NAME_OR_ABILITY_NAME = "Invalid bundle name or ability name"; +const std::string ERROR_MESSAGE_TARGET_ABILITY_ALREADY_ENABLED = "Target ability already enabled"; +enum class NAccessibilityErrorCode : int32_t { + ACCESSIBILITY_OK = 0, + ACCESSIBILITY_ERROR_NO_PERMISSION = 201, + ACCESSIBILITY_ERROR_INVALID_PARAM = 401, + ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY = 9300000, + ACCESSIBILITY_ERROR_ERROR_EXTENSION_NAME = 9300001, + ACCESSIBILITY_ERROR_TARGET_ABILITY_ALREADY_ENABLED = 9300002, + ACCESSIBILITY_ERROR_NO_RIGHT = 9300003, + ACCESSIBILITY_ERROR_PROPERTY_NOT_EXIST = 9300004, + ACCESSIBILITY_ERROR_ACTION_NOT_SUPPORT = 9300005, +}; + +struct NAccessibilityErrMsg { + NAccessibilityErrorCode errCode; + std::string message; +}; + +const std::map ACCESSIBILITY_JS_TO_ERROR_CODE_MAP { + {OHOS::Accessibility::RetError::RET_OK, + {NAccessibilityErrorCode::ACCESSIBILITY_OK, ""}}, + {OHOS::Accessibility::RetError::RET_ERR_FAILED, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_INVALID_PARAM, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_INVALID_PARAM, ERROR_MESSAGE_PARAMETER_ERROR}}, + {OHOS::Accessibility::RetError::RET_ERR_NULLPTR, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_IPC_FAILED, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_SAMGR, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_NO_PERMISSION, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_NO_PERMISSION, ERROR_MESSAGE_NO_PERMISSION}}, + {OHOS::Accessibility::RetError::RET_ERR_TIME_OUT, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_NOT_SUPPORT, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_REGISTER_EXIST, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_NO_REGISTER, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_CONNECTION_EXIST, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_TARGET_ABILITY_ALREADY_ENABLED, + ERROR_MESSAGE_TARGET_ABILITY_ALREADY_ENABLED}}, + {OHOS::Accessibility::RetError::RET_ERR_NO_CONNECTION, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_NO_WINDOW_CONNECTION, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_NO_CAPABILITY, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_NO_RIGHT, ERROR_MESSAGE_NO_RIGHT}}, + {OHOS::Accessibility::RetError::RET_ERR_INVALID_ELEMENT_INFO_FROM_ACE, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_PERFORM_ACTION_FAILED_BY_ACE, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_NO_INJECTOR, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_SYSTEM_ABNORMALITY, ERROR_MESSAGE_SYSTEM_ABNORMALITY}}, + {OHOS::Accessibility::RetError::RET_ERR_NOT_INSTALLED, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_ERROR_EXTENSION_NAME, + ERROR_MESSAGE_INVALID_BUNDLE_NAME_OR_ABILITY_NAME}}, + {OHOS::Accessibility::RetError::RET_ERR_NOT_ENABLED, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_ERROR_EXTENSION_NAME, + ERROR_MESSAGE_INVALID_BUNDLE_NAME_OR_ABILITY_NAME}}, + {OHOS::Accessibility::RetError::RET_ERR_PROPERTY_NOT_EXIST, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_PROPERTY_NOT_EXIST, ERROR_MESSAGE_PROPERTY_NOT_EXIST}}, + {OHOS::Accessibility::RetError::RET_ERR_ACTION_NOT_SUPPORT, + {NAccessibilityErrorCode::ACCESSIBILITY_ERROR_ACTION_NOT_SUPPORT, ERROR_MESSAGE_ACTION_NOT_SUPPORT}}, +}; #endif // NAPI_ACCESSIBILITY_DEF_H \ No newline at end of file diff --git a/interfaces/kits/napi/include/napi_accessibility_system_ability_client.h b/interfaces/kits/napi/include/napi_accessibility_system_ability_client.h index 47eb0e754..655e6ecc6 100644 --- a/interfaces/kits/napi/include/napi_accessibility_system_ability_client.h +++ b/interfaces/kits/napi/include/napi_accessibility_system_ability_client.h @@ -78,6 +78,7 @@ struct NAccessibilitySystemAbilityClient { bool setKeyEvenReturn_ = false; OHOS::Accessibility::AccessibilityEventInfo eventInfo_ {}; bool result_ = false; + OHOS::Accessibility::RetError ret_ = OHOS::Accessibility::RET_ERR_FAILED; std::string eventType_ = ""; std::map>> stateListeners_; diff --git a/interfaces/kits/napi/include/napi_accessibility_utils.h b/interfaces/kits/napi/include/napi_accessibility_utils.h index 280206a4a..fcd71612d 100644 --- a/interfaces/kits/napi/include/napi_accessibility_utils.h +++ b/interfaces/kits/napi/include/napi_accessibility_utils.h @@ -45,7 +45,8 @@ bool ParseString(napi_env env, std::string& param, napi_value args); bool ParseNumber(napi_env env, napi_value args); bool ParseInt32(napi_env env, int32_t& param, napi_value args); bool ParseDouble(napi_env env, double& param, napi_value args); -napi_value GetErrorValue(napi_env env, int errCode); +NAccessibilityErrMsg QueryRetMsg(OHOS::Accessibility::RetError errorCode); +napi_value CreateBusinessError(napi_env env, OHOS::Accessibility::RetError errCode); std::string ConvertWindowTypeToString(OHOS::Accessibility::AccessibilityWindowType type); std::string ConvertDaltonizationTypeToString(OHOS::AccessibilityConfig::DALTONIZATION_TYPE type); @@ -66,10 +67,10 @@ void ConvertCaptionPropertyToJS(napi_env env, napi_value& result, OHOS::AccessibilityConfig::CaptionProperty captionProperty); bool ConvertObjToCaptionProperty( napi_env env, napi_value object, OHOS::AccessibilityConfig::CaptionProperty* ptrCaptionProperty); -void ConvertJSToStringVec(napi_env env, napi_value arrayValue, std::vector &values); +bool ConvertJSToStringVec(napi_env env, napi_value arrayValue, std::vector &values); void ConvertStringVecToJS(napi_env env, napi_value &result, std::vector values); void ConvertJSToEventTypes(napi_env env, napi_value arrayValue, uint32_t &eventTypes); -void ConvertJSToCapabilities(napi_env env, napi_value arrayValue, uint32_t &capabilities); +bool ConvertJSToCapabilities(napi_env env, napi_value arrayValue, uint32_t &capabilities); uint32_t GetColorValue(napi_env env, napi_value object, napi_value propertyNameValue); uint32_t GetColorValue(napi_env env, napi_value value); uint32_t ConvertColorStringToNumer(std::string colorStr); @@ -87,7 +88,7 @@ const std::string ConvertWindowUpdateTypeToString(OHOS::Accessibility::WindowUpd const std::string ConvertAccessibilityEventTypeToString(OHOS::Accessibility::EventType type); void ConvertEventTypeToString(const OHOS::Accessibility::AccessibilityEventInfo &eventInfo, std::string &eventTypeString); -void ConvertGesturePathsJSToNAPI(napi_env env, napi_value object, +bool ConvertGesturePathsJSToNAPI(napi_env env, napi_value object, std::shared_ptr& gesturePath, std::vector>& gesturePathArray, bool &isParameterArray); diff --git a/interfaces/kits/napi/src/napi_accessibility_system_ability_client.cpp b/interfaces/kits/napi/src/napi_accessibility_system_ability_client.cpp index a10042288..883530d35 100644 --- a/interfaces/kits/napi/src/napi_accessibility_system_ability_client.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_system_ability_client.cpp @@ -48,9 +48,15 @@ napi_value NAccessibilityClient::IsOpenAccessibility(napi_env env, napi_callback napi_value promise = nullptr; if (argc > 0) { - HILOG_DEBUG("IsOpenAccessibility callback mode"); - napi_create_reference(env, argv, 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); + napi_valuetype valueType = napi_null; + napi_typeof(env, argv, &valueType); + if (valueType == napi_function) { + HILOG_DEBUG("IsOpenAccessibility callback mode"); + napi_create_reference(env, argv, 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } } else { HILOG_DEBUG("IsOpenAccessibility promise mode"); napi_create_promise(env, &callbackInfo->deferred_, &promise); @@ -64,7 +70,7 @@ napi_value NAccessibilityClient::IsOpenAccessibility(napi_env env, napi_callback NAccessibilitySystemAbilityClient* callbackInfo = static_cast(data); auto asaClient = AccessibilitySystemAbilityClient::GetInstance(); if (asaClient) { - callbackInfo->enabled_ = asaClient->IsEnabled(); + callbackInfo->ret_ = asaClient->IsEnabled(callbackInfo->enabled_); HILOG_INFO("IsOpenAccessibility Executing enabled[%{public}d]", callbackInfo->enabled_); } }, @@ -78,15 +84,18 @@ napi_value NAccessibilityClient::IsOpenAccessibility(napi_env env, napi_callback NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, callbackInfo->enabled_, &result[PARAM1])); HILOG_INFO("IsOpenAccessibility completed enabled[%{public}d]", callbackInfo->enabled_); - + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); if (callbackInfo->callback_) { - result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); napi_get_reference_value(env, callbackInfo->callback_, &callback); napi_value returnVal; napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &returnVal); napi_delete_reference(env, callbackInfo->callback_); } else { - napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + if (callbackInfo->ret_ == OHOS::Accessibility::RET_OK) { + napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); + } } napi_delete_async_work(env, callbackInfo->work_); delete callbackInfo; @@ -111,9 +120,15 @@ napi_value NAccessibilityClient::IsOpenTouchExploration(napi_env env, napi_callb napi_value promise = nullptr; if (argc > 0) { - HILOG_DEBUG("IsOpenTouchExploration callback mode"); - napi_create_reference(env, argv, 1, &callbackInfo->callback_); - napi_get_undefined(env, &promise); + napi_valuetype valueType = napi_null; + napi_typeof(env, argv, &valueType); + if (valueType == napi_function) { + HILOG_DEBUG("IsOpenTouchExploration callback mode"); + napi_create_reference(env, argv, 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } } else { HILOG_DEBUG("IsOpenTouchExploration promise mode"); napi_create_promise(env, &callbackInfo->deferred_, &promise); @@ -127,7 +142,7 @@ napi_value NAccessibilityClient::IsOpenTouchExploration(napi_env env, napi_callb NAccessibilitySystemAbilityClient* callbackInfo = static_cast(data); auto asaClient = AccessibilitySystemAbilityClient::GetInstance(); if (asaClient) { - callbackInfo->touchEnabled_ = asaClient->IsTouchExplorationEnabled(); + callbackInfo->ret_ = asaClient->IsTouchExplorationEnabled(callbackInfo->touchEnabled_); HILOG_INFO("IsOpenTouchExploration Executing touchEnabled[%{public}d]", callbackInfo->touchEnabled_); } }, @@ -141,15 +156,18 @@ napi_value NAccessibilityClient::IsOpenTouchExploration(napi_env env, napi_callb NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, callbackInfo->touchEnabled_, &result[PARAM1])); HILOG_INFO("IsOpenTouchExploration completed touchEnabled_[%{public}d]", callbackInfo->touchEnabled_); - + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); if (callbackInfo->callback_) { - result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); napi_get_reference_value(env, callbackInfo->callback_, &callback); napi_value returnVal; napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &returnVal); napi_delete_reference(env, callbackInfo->callback_); } else { - napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + if (callbackInfo->ret_ == OHOS::Accessibility::RET_OK) { + napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); + } } napi_delete_async_work(env, callbackInfo->work_); delete callbackInfo; @@ -196,7 +214,7 @@ napi_value NAccessibilityClient::GetAbilityList(napi_env env, napi_callback_info NAccessibilitySystemAbilityClient* callbackInfo = static_cast(data); auto asaClient = AccessibilitySystemAbilityClient::GetInstance(); if (asaClient) { - callbackInfo->result_ = asaClient->GetAbilityList(callbackInfo->abilityTypes_, + callbackInfo->ret_ = asaClient->GetAbilityList(callbackInfo->abilityTypes_, callbackInfo->stateTypes_, callbackInfo->abilityList_); } }, @@ -209,18 +227,18 @@ napi_value NAccessibilityClient::GetAbilityList(napi_env env, napi_callback_info napi_get_undefined(env, &undefined); napi_create_array(env, &result[PARAM1]); ConvertAccessibleAbilityInfosToJS(env, result[PARAM1], callbackInfo->abilityList_); + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); if (callbackInfo->callback_) { - if (callbackInfo->result_) { - result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); - } else { - result[PARAM0] = GetErrorValue(env, CODE_FAILED); - } napi_get_reference_value(env, callbackInfo->callback_, &callback); napi_value returnVal; napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &returnVal); napi_delete_reference(env, callbackInfo->callback_); } else { - napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + if (callbackInfo->ret_ == OHOS::Accessibility::RET_OK) { + napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); + } } napi_delete_async_work(env, callbackInfo->work_); delete callbackInfo; @@ -263,9 +281,9 @@ napi_value NAccessibilityClient::SendEvent(napi_env env, napi_callback_info info NAccessibilitySystemAbilityClient* callbackInfo = static_cast(data); auto asaClient = AccessibilitySystemAbilityClient::GetInstance(); if (callbackInfo->result_ && asaClient) { - callbackInfo->result_ = asaClient->SendEvent(callbackInfo->eventInfo_); + callbackInfo->ret_ = asaClient->SendEvent(callbackInfo->eventInfo_); } - HILOG_INFO("SendEvent result[%{public}d]", callbackInfo->result_); + HILOG_INFO("SendEvent result[%{public}d]", callbackInfo->ret_); }, [](napi_env env, napi_status status, void* data) { NAccessibilitySystemAbilityClient* callbackInfo = static_cast(data); @@ -275,22 +293,18 @@ napi_value NAccessibilityClient::SendEvent(napi_env env, napi_callback_info info napi_value ret = 0; napi_get_undefined(env, &undefined); napi_get_undefined(env, &ret); + result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_); + result[PARAM1] = ret; if (callbackInfo->callback_) { - if (callbackInfo->result_) { - result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); - } else { - result[PARAM0] = GetErrorValue(env, CODE_FAILED); - } - result[PARAM1] = ret; napi_get_reference_value(env, callbackInfo->callback_, &callback); napi_value returnVal; napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &returnVal); napi_delete_reference(env, callbackInfo->callback_); } else { - if (callbackInfo->result_) { - napi_resolve_deferred(env, callbackInfo->deferred_, undefined); + if (callbackInfo->ret_ == OHOS::Accessibility::RET_OK) { + napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); } else { - napi_reject_deferred(env, callbackInfo->deferred_, undefined); + napi_reject_deferred(env, callbackInfo->deferred_, result[PARAM0]); } } napi_delete_async_work(env, callbackInfo->work_); @@ -312,17 +326,48 @@ napi_value NAccessibilityClient::SubscribeState(napi_env env, napi_callback_info napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); if (status != napi_ok) { HILOG_ERROR("Failed to get event type"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_FAILED); + napi_throw(env, err); return nullptr; } - std::string eventType = GetStringFromNAPI(env, args[0]); + OHOS::Accessibility::RetError errCode = OHOS::Accessibility::RET_OK; + if (argc < ARGS_SIZE_TWO) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + uint32_t type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; - if (!std::strcmp(eventType.c_str(), "accessibilityStateChange")) { - type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; - } else if (!std::strcmp(eventType.c_str(), "touchGuideStateChange")) { - type = AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED; - } else { - HILOG_ERROR("SubscribeState eventType[%{public}s] is error", eventType.c_str()); + if (errCode == OHOS::Accessibility::RET_OK) { + std::string eventType = ""; + if (!ParseString(env, eventType, args[PARAM0])) { + HILOG_ERROR("eventType type parse failed"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } else { + if (std::strcmp(eventType.c_str(), "accessibilityStateChange") == 0) { + type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; + } else if (std::strcmp(eventType.c_str(), "touchGuideStateChange") == 0) { + type = AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED; + } else { + HILOG_ERROR("SubscribeState eventType[%{public}s] is error", eventType.c_str()); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + } + + if (errCode == OHOS::Accessibility::RET_OK) { + napi_valuetype valueType = napi_null; + napi_typeof(env, args[PARAM1], &valueType); + if (valueType != napi_function) { + HILOG_ERROR("args[PARAM1] format is wrong"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + + if (errCode == OHOS::Accessibility::RET_ERR_INVALID_PARAM) { + napi_value err = CreateBusinessError(env, errCode); + HILOG_ERROR("invalid param"); + napi_throw(env, err); return nullptr; } @@ -349,27 +394,60 @@ napi_value NAccessibilityClient::UnsubscribeState(napi_env env, napi_callback_in size_t argc = ARGS_SIZE_TWO; napi_value args[ARGS_SIZE_TWO] = {0}; napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - std::string eventType = GetStringFromNAPI(env, args[PARAM0]); + + OHOS::Accessibility::RetError errCode = OHOS::Accessibility::RET_OK; + if (argc < ARGS_SIZE_TWO - 1) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + uint32_t type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; - if (!std::strcmp(eventType.c_str(), "accessibilityStateChange")) { - type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; - } else if (!std::strcmp(eventType.c_str(), "touchGuideStateChange")) { - type = AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED; - } else { - HILOG_ERROR("UnsubscribeState eventType[%{public}s] is error", eventType.c_str()); + if (errCode == OHOS::Accessibility::RET_OK) { + std::string eventType = ""; + if (!ParseString(env, eventType, args[PARAM0])) { + HILOG_ERROR("eventType type parse failed"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } else { + if (std::strcmp(eventType.c_str(), "accessibilityStateChange") == 0) { + type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; + } else if (std::strcmp(eventType.c_str(), "touchGuideStateChange") == 0) { + type = AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED; + } else { + HILOG_ERROR("SubscribeState eventType[%{public}s] is error", eventType.c_str()); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + } + + if (errCode == OHOS::Accessibility::RET_ERR_INVALID_PARAM) { + napi_value err = CreateBusinessError(env, errCode); + HILOG_ERROR("invalid param"); + napi_throw(env, err); return nullptr; } switch (type) { case AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED: if (argc >= ARGS_SIZE_TWO) { - accessibilityStateListeners_->UnsubscribeObserver(args[PARAM1]); + napi_valuetype valueType = napi_null; + napi_typeof(env, args[PARAM1], &valueType); + if (valueType == napi_function) { + accessibilityStateListeners_->UnsubscribeObserver(args[PARAM1]); + } else { + accessibilityStateListeners_->UnsubscribeObservers(); + } } else { accessibilityStateListeners_->UnsubscribeObservers(); } break; case AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED: if (argc >= ARGS_SIZE_TWO) { - touchGuideStateListeners_->UnsubscribeObserver(args[PARAM1]); + napi_valuetype valueType = napi_null; + napi_typeof(env, args[PARAM1], &valueType); + if (valueType == napi_function) { + touchGuideStateListeners_->UnsubscribeObserver(args[PARAM1]); + } else { + touchGuideStateListeners_->UnsubscribeObservers(); + } } else { touchGuideStateListeners_->UnsubscribeObservers(); } @@ -485,22 +563,32 @@ napi_value NAccessibilityClient::SetCaptionStateEnabled(napi_env env, napi_callb { HILOG_INFO(); size_t argc = ARGS_SIZE_ONE; - bool captionState = false; napi_value parameters[ARGS_SIZE_ONE] = {0}; napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); if (argc >= ARGS_SIZE_ONE) { - napi_get_value_bool(env, parameters[PARAM0], &captionState); - HILOG_INFO("captionState = %{public}s", captionState ? "True" : "False"); + bool captionState = false; + OHOS::Accessibility::RetError ret = OHOS::Accessibility::RET_OK; + if (!ParseBool(env, captionState, parameters[PARAM0])) { + ret = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } else { + HILOG_INFO("captionState = %{public}s", captionState ? "True" : "False"); - auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); - instance.SetCaptionsState(captionState); + auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); + ret = instance.SetCaptionsState(captionState); + } + if (ret != OHOS::Accessibility::RET_OK) { + napi_value err = CreateBusinessError(env, ret); + napi_throw(env, err); + } } else { HILOG_ERROR("argc size Error"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_INVALID_PARAM); + napi_throw(env, err); } - napi_value ret = nullptr; - napi_get_undefined(env, &ret); - return ret; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + return undefined; } napi_value NAccessibilityClient::GetCaptionStateEnabled(napi_env env, napi_callback_info info) @@ -523,19 +611,29 @@ napi_value NAccessibilityClient::SetCaptionStyle(napi_env env, napi_callback_inf HILOG_INFO(); size_t argc = ARGS_SIZE_ONE; napi_value parameters[ARGS_SIZE_ONE] = {0}; - OHOS::AccessibilityConfig::CaptionProperty captionProperty = {}; napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); if (argc >= ARGS_SIZE_ONE) { - ConvertObjToCaptionProperty(env, parameters[PARAM0], &captionProperty); - auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); - instance.SetCaptionsProperty(captionProperty); + OHOS::AccessibilityConfig::CaptionProperty captionProperty = {}; + OHOS::Accessibility::RetError ret = OHOS::Accessibility::RET_OK; + if (!ConvertObjToCaptionProperty(env, parameters[PARAM0], &captionProperty)) { + ret = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } else { + auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); + ret = instance.SetCaptionsProperty(captionProperty); + } + if (ret != OHOS::Accessibility::RET_OK) { + napi_value err = CreateBusinessError(env, ret); + napi_throw(env, err); + } } else { HILOG_ERROR("argc size Error"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_INVALID_PARAM); + napi_throw(env, err); } - napi_value ret = nullptr; - napi_get_undefined(env, &ret); - return ret; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + return undefined; } napi_value NAccessibilityClient::GetCaptionStyle(napi_env env, napi_callback_info info) @@ -556,18 +654,48 @@ napi_value NAccessibilityClient::RegisterCaptionStateCallback(napi_env env, napi napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); if (status != napi_ok) { HILOG_ERROR("Failed to get event type"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_FAILED); + napi_throw(env, err); return nullptr; } - std::string eventType = GetStringFromNAPI(env, args[0]); - OHOS::AccessibilityConfig::CONFIG_ID type = - OHOS::AccessibilityConfig::CONFIG_ID_MAX; - if (!std::strcmp(eventType.c_str(), "enableChange")) { - type = OHOS::AccessibilityConfig::CONFIG_CAPTION_STATE; - } else if (!std::strcmp(eventType.c_str(), "styleChange")) { - type = OHOS::AccessibilityConfig::CONFIG_CAPTION_STYLE; - } else { - HILOG_ERROR("SubscribeState eventType[%{public}s] is error", eventType.c_str()); + OHOS::Accessibility::RetError errCode = OHOS::Accessibility::RET_OK; + if (argc < ARGS_SIZE_TWO) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + + OHOS::AccessibilityConfig::CONFIG_ID type = OHOS::AccessibilityConfig::CONFIG_ID_MAX; + if (errCode == OHOS::Accessibility::RET_OK) { + std::string eventType = ""; + if (!ParseString(env, eventType, args[PARAM0])) { + HILOG_ERROR("eventType type parse failed"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } else { + if (std::strcmp(eventType.c_str(), "enableChange") == 0) { + type = OHOS::AccessibilityConfig::CONFIG_CAPTION_STATE; + } else if (std::strcmp(eventType.c_str(), "styleChange") == 0) { + type = OHOS::AccessibilityConfig::CONFIG_CAPTION_STYLE; + } else { + HILOG_ERROR("SubscribeState eventType[%{public}s] is error", eventType.c_str()); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + } + + if (errCode == OHOS::Accessibility::RET_OK) { + napi_valuetype valueType = napi_null; + napi_typeof(env, args[PARAM1], &valueType); + if (valueType != napi_function) { + HILOG_ERROR("args[PARAM1] format is wrong"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + + if (errCode == OHOS::Accessibility::RET_ERR_INVALID_PARAM) { + napi_value err = CreateBusinessError(env, errCode); + HILOG_ERROR("invalid param"); + napi_throw(env, err); return nullptr; } @@ -586,21 +714,46 @@ napi_value NAccessibilityClient::DeregisterCaptionStateCallback(napi_env env, na size_t argc = ARGS_SIZE_TWO; napi_value args[ARGS_SIZE_TWO] = {0}; napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - std::string eventType = GetStringFromNAPI(env, args[0]); - OHOS::AccessibilityConfig::CONFIG_ID type = - OHOS::AccessibilityConfig::CONFIG_ID_MAX; - if (!std::strcmp(eventType.c_str(), "enableChange")) { - type = OHOS::AccessibilityConfig::CONFIG_CAPTION_STATE; - } else if (!std::strcmp(eventType.c_str(), "styleChange")) { - type = OHOS::AccessibilityConfig::CONFIG_CAPTION_STYLE; - } else { - HILOG_ERROR("DeregisterCaptionStateCallback eventType[%{public}s] is error", eventType.c_str()); + OHOS::Accessibility::RetError errCode = OHOS::Accessibility::RET_OK; + if (argc < ARGS_SIZE_TWO - 1) { + HILOG_ERROR("argc is invalid: %{public}zu", argc); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + + OHOS::AccessibilityConfig::CONFIG_ID type = OHOS::AccessibilityConfig::CONFIG_ID_MAX; + if (errCode == OHOS::Accessibility::RET_OK) { + std::string eventType = ""; + if (!ParseString(env, eventType, args[PARAM0])) { + HILOG_ERROR("eventType type parse failed"); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } else { + if (std::strcmp(eventType.c_str(), "enableChange") == 0) { + type = OHOS::AccessibilityConfig::CONFIG_CAPTION_STATE; + } else if (std::strcmp(eventType.c_str(), "styleChange") == 0) { + type = OHOS::AccessibilityConfig::CONFIG_CAPTION_STYLE; + } else { + HILOG_ERROR("SubscribeState eventType[%{public}s] is error", eventType.c_str()); + errCode = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + } + } + + if (errCode == OHOS::Accessibility::RET_ERR_INVALID_PARAM) { + napi_value err = CreateBusinessError(env, errCode); + HILOG_ERROR("invalid param"); + napi_throw(env, err); return nullptr; } if (argc >= ARGS_SIZE_TWO) { - captionListeners_->UnsubscribeObserver(type, args[PARAM1]); + napi_valuetype valueType = napi_null; + napi_typeof(env, args[PARAM1], &valueType); + if (valueType == napi_function) { + captionListeners_->UnsubscribeObserver(type, args[PARAM1]); + } else { + captionListeners_->UnsubscribeObservers(type); + } } else { captionListeners_->UnsubscribeObservers(type); } @@ -669,23 +822,31 @@ napi_value NAccessibilityClient::SetCaptionsFontFamily(napi_env env, napi_callba napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); if (argc >= ARGS_SIZE_ONE) { // Get input FontFamily - char outBuffer[CHAE_BUFFER_MAX + 1] = {0}; - size_t outSize = 0; - napi_get_value_string_utf8(env, parameters[PARAM0], outBuffer, CHAE_BUFFER_MAX, &outSize); - HILOG_INFO("FontFamily = %{public}s", outBuffer); - // Get CaptionProperty - auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); - OHOS::AccessibilityConfig::CaptionProperty captionProperty {}; - instance.GetCaptionsProperty(captionProperty); - // Change the input info and then set the CaptionProperty - captionProperty.SetFontFamily(std::string(outBuffer)); - instance.SetCaptionsProperty(captionProperty); + std::string fontFamily = ""; + OHOS::Accessibility::RetError ret = OHOS::Accessibility::RET_OK; + if (ParseString(env, fontFamily, parameters[PARAM0]) && fontFamily.length() > 0) { + HILOG_INFO("FontFamily = %{public}s", fontFamily.c_str()); + auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); + OHOS::AccessibilityConfig::CaptionProperty captionProperty {}; + instance.GetCaptionsProperty(captionProperty); + // Change the input info and then set the CaptionProperty + captionProperty.SetFontFamily(std::string(fontFamily)); + ret = instance.SetCaptionsProperty(captionProperty); + } else { + ret = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + if (ret != OHOS::Accessibility::RET_OK) { + napi_value err = CreateBusinessError(env, ret); + napi_throw(env, err); + } } else { HILOG_ERROR("argc size Error"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_INVALID_PARAM); + napi_throw(env, err); } - napi_value ret = nullptr; - napi_get_undefined(env, &ret); - return ret; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + return undefined; } napi_value NAccessibilityClient::GetCaptionsFontScale(napi_env env, napi_callback_info info) @@ -708,21 +869,30 @@ napi_value NAccessibilityClient::SetCaptionsFontScale(napi_env env, napi_callbac if (argc >= ARGS_SIZE_ONE) { // Get input FontScale int32_t num = 0; - napi_get_value_int32(env, parameters[PARAM0], &num); - HILOG_INFO("FontScale = %{public}d", num); - // Get CaptionProperty - auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); - OHOS::AccessibilityConfig::CaptionProperty captionProperty = {}; - instance.GetCaptionsProperty(captionProperty); - // Change the input info and then set the CaptionProperty - captionProperty.SetFontScale(num); - instance.SetCaptionsProperty(captionProperty); + OHOS::Accessibility::RetError ret = OHOS::Accessibility::RET_OK; + if (ParseInt32(env, num, parameters[PARAM0])) { + HILOG_INFO("FontScale = %{public}d", num); + auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); + OHOS::AccessibilityConfig::CaptionProperty captionProperty {}; + instance.GetCaptionsProperty(captionProperty); + // Change the input info and then set the CaptionProperty + captionProperty.SetFontScale(num); + ret = instance.SetCaptionsProperty(captionProperty); + } else { + ret = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + if (ret != OHOS::Accessibility::RET_OK) { + napi_value err = CreateBusinessError(env, ret); + napi_throw(env, err); + } } else { HILOG_ERROR("argc size Error"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_INVALID_PARAM); + napi_throw(env, err); } - napi_value ret = nullptr; - napi_get_undefined(env, &ret); - return ret; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + return undefined; } napi_value NAccessibilityClient::GetCaptionFrontColor(napi_env env, napi_callback_info info) @@ -746,19 +916,25 @@ napi_value NAccessibilityClient::SetCaptionFrontColor(napi_env env, napi_callbac napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); if (argc >= ARGS_SIZE_ONE) { uint32_t color = GetColorValue(env, parameters[PARAM0]); - // Get CaptionProperty + OHOS::Accessibility::RetError ret = OHOS::Accessibility::RET_OK; auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); - OHOS::AccessibilityConfig::CaptionProperty captionProperty = {}; + OHOS::AccessibilityConfig::CaptionProperty captionProperty {}; instance.GetCaptionsProperty(captionProperty); // Change the input info and then set the CaptionProperty captionProperty.SetFontColor(color); - (void)instance.SetCaptionsProperty(captionProperty); + ret = instance.SetCaptionsProperty(captionProperty); + if (ret != OHOS::Accessibility::RET_OK) { + napi_value err = CreateBusinessError(env, ret); + napi_throw(env, err); + } } else { HILOG_ERROR("argc size Error"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_INVALID_PARAM); + napi_throw(env, err); } - napi_value ret = nullptr; - napi_get_undefined(env, &ret); - return ret; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + return undefined; } napi_value NAccessibilityClient::GetCaptionFontEdgeType(napi_env env, napi_callback_info info) @@ -781,23 +957,31 @@ napi_value NAccessibilityClient::SetCaptionFontEdgeType(napi_env env, napi_callb napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); if (argc >= ARGS_SIZE_ONE) { // Get input FontEdgeType - char outBuffer[CHAE_BUFFER_MAX + 1] = {0}; - size_t outSize = 0; - napi_get_value_string_utf8(env, parameters[PARAM0], outBuffer, CHAE_BUFFER_MAX, &outSize); - HILOG_INFO("FontEdgeType = %{public}s", outBuffer); - // Get CaptionProperty - auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); - OHOS::AccessibilityConfig::CaptionProperty captionProperty = {}; - instance.GetCaptionsProperty(captionProperty); - // Change the input info and then set the CaptionProperty - captionProperty.SetFontEdgeType(std::string(outBuffer)); - instance.SetCaptionsProperty(captionProperty); + std::string fontEdgeType = ""; + OHOS::Accessibility::RetError ret = OHOS::Accessibility::RET_OK; + if (ParseString(env, fontEdgeType, parameters[PARAM0]) && fontEdgeType.length() > 0) { + HILOG_INFO("fontEdgeType = %{public}s", fontEdgeType.c_str()); + auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); + OHOS::AccessibilityConfig::CaptionProperty captionProperty {}; + instance.GetCaptionsProperty(captionProperty); + // Change the input info and then set the CaptionProperty + captionProperty.SetFontEdgeType(std::string(fontEdgeType)); + ret = instance.SetCaptionsProperty(captionProperty); + } else { + ret = OHOS::Accessibility::RET_ERR_INVALID_PARAM; + } + if (ret != OHOS::Accessibility::RET_OK) { + napi_value err = CreateBusinessError(env, ret); + napi_throw(env, err); + } } else { HILOG_ERROR("argc size Error"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_INVALID_PARAM); + napi_throw(env, err); } - napi_value ret = nullptr; - napi_get_undefined(env, &ret); - return ret; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + return undefined; } napi_value NAccessibilityClient::GetCaptionBackgroundColor(napi_env env, napi_callback_info info) @@ -821,19 +1005,25 @@ napi_value NAccessibilityClient::SetCaptionBackgroundColor(napi_env env, napi_ca napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); if (argc >= ARGS_SIZE_ONE) { uint32_t color = GetColorValue(env, parameters[PARAM0]); - // Get CaptionProperty + OHOS::Accessibility::RetError ret = OHOS::Accessibility::RET_OK; auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); - OHOS::AccessibilityConfig::CaptionProperty captionProperty = {}; + OHOS::AccessibilityConfig::CaptionProperty captionProperty {}; instance.GetCaptionsProperty(captionProperty); // Change the input info and then set the CaptionProperty captionProperty.SetBackgroundColor(color); - (void)instance.SetCaptionsProperty(captionProperty); + ret = instance.SetCaptionsProperty(captionProperty); + if (ret != OHOS::Accessibility::RET_OK) { + napi_value err = CreateBusinessError(env, ret); + napi_throw(env, err); + } } else { HILOG_ERROR("argc size Error"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_INVALID_PARAM); + napi_throw(env, err); } - napi_value ret = nullptr; - napi_get_undefined(env, &ret); - return ret; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + return undefined; } napi_value NAccessibilityClient::GetCaptionWindowColor(napi_env env, napi_callback_info info) @@ -857,19 +1047,25 @@ napi_value NAccessibilityClient::SetCaptionWindowColor(napi_env env, napi_callba napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); if (argc >= ARGS_SIZE_ONE) { uint32_t color = GetColorValue(env, parameters[PARAM0]); - // Get CaptionProperty + OHOS::Accessibility::RetError ret = OHOS::Accessibility::RET_OK; auto &instance = OHOS::AccessibilityConfig::AccessibilityConfig::GetInstance(); - OHOS::AccessibilityConfig::CaptionProperty captionProperty = {}; + OHOS::AccessibilityConfig::CaptionProperty captionProperty {}; instance.GetCaptionsProperty(captionProperty); // Change the input info and then set the CaptionProperty captionProperty.SetWindowColor(color); - (void)instance.SetCaptionsProperty(captionProperty); + ret = instance.SetCaptionsProperty(captionProperty); + if (ret != OHOS::Accessibility::RET_OK) { + napi_value err = CreateBusinessError(env, ret); + napi_throw(env, err); + } } else { HILOG_ERROR("argc size Error"); + napi_value err = CreateBusinessError(env, OHOS::Accessibility::RET_ERR_INVALID_PARAM); + napi_throw(env, err); } - napi_value ret = nullptr; - napi_get_undefined(env, &ret); - return ret; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + return undefined; } void StateListenerImpl::SubscribeToFramework() diff --git a/interfaces/kits/napi/src/napi_accessibility_utils.cpp b/interfaces/kits/napi/src/napi_accessibility_utils.cpp index ea7488c09..90746c322 100644 --- a/interfaces/kits/napi/src/napi_accessibility_utils.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_utils.cpp @@ -148,13 +148,32 @@ bool ParseDouble(napi_env env, double& param, napi_value args) return true; } -napi_value GetErrorValue(napi_env env, int errCode) +NAccessibilityErrMsg QueryRetMsg(OHOS::Accessibility::RetError errorCode) +{ + auto iter = ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.find(errorCode); + if (iter != ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.end()) { + return iter->second; + } else { + return ACCESSIBILITY_JS_TO_ERROR_CODE_MAP.at(OHOS::Accessibility::RetError::RET_ERR_FAILED); + } +} + +napi_value CreateBusinessError(napi_env env, OHOS::Accessibility::RetError errCode) { napi_value result = nullptr; - napi_value eCode = nullptr; - NAPI_CALL(env, napi_create_int32(env, errCode, &eCode)); - NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_CALL(env, napi_set_named_property(env, result, "code", eCode)); + if (errCode == OHOS::Accessibility::RetError::RET_OK) { + napi_get_undefined(env, &result); + } else { + napi_value eCode = nullptr; + NAccessibilityErrMsg errMsg = QueryRetMsg(errCode); + NAPI_CALL(env, napi_create_int32(env, static_cast(errMsg.errCode), &eCode)); + NAPI_CALL(env, napi_create_object(env, &result)); + NAPI_CALL(env, napi_set_named_property(env, result, "code", eCode)); + + napi_value eMsg = nullptr; + NAPI_CALL(env, napi_create_string_utf8(env, errMsg.message.c_str(), NAPI_AUTO_LENGTH, &eMsg)); + NAPI_CALL(env, napi_set_named_property(env, result, "message", eMsg)); + } return result; } @@ -964,7 +983,7 @@ static void ConvertGesturePathJSToNAPI(napi_env env, napi_value object, } } -void ConvertGesturePathsJSToNAPI(napi_env env, napi_value object, +bool ConvertGesturePathsJSToNAPI(napi_env env, napi_value object, std::shared_ptr& gesturePath, std::vector>& gesturePathArray, bool &isParameterArray) @@ -972,21 +991,21 @@ void ConvertGesturePathsJSToNAPI(napi_env env, napi_value object, HILOG_DEBUG(); if (napi_is_array(env, object, &isParameterArray) != napi_ok) { HILOG_ERROR("judge array error."); - return; + return false; } if (isParameterArray) { uint32_t dataLen = 0; if (napi_get_array_length(env, object, &dataLen) != napi_ok) { HILOG_ERROR("get array length failed."); - return; + return false; } napi_value gesturePathJs = nullptr; for (uint32_t i = 0; i < dataLen; i++) { gesturePathJs = nullptr; if (napi_get_element(env, object, i, &gesturePathJs) != napi_ok) { HILOG_ERROR("get element of paths failed and i = %{public}d", i); - return; + return false; } std::shared_ptr path = std::make_shared(); ConvertGesturePathJSToNAPI(env, gesturePathJs, path); @@ -995,6 +1014,7 @@ void ConvertGesturePathsJSToNAPI(napi_env env, napi_value object, } else { ConvertGesturePathJSToNAPI(env, object, gesturePath); } + return true; } KeyAction TransformKeyActionValue(int32_t keyAction) @@ -1412,7 +1432,7 @@ bool ConvertObjToCaptionProperty( return true; } -void ConvertJSToStringVec(napi_env env, napi_value arrayValue, std::vector& values) +bool ConvertJSToStringVec(napi_env env, napi_value arrayValue, std::vector& values) { HILOG_DEBUG(); values.clear(); @@ -1422,15 +1442,22 @@ void ConvertJSToStringVec(napi_env env, napi_value arrayValue, std::vector values) diff --git a/interfaces/kits/napi/src/native_module.cpp b/interfaces/kits/napi/src/native_module.cpp index 879a8f5ec..2e9630ba1 100644 --- a/interfaces/kits/napi/src/native_module.cpp +++ b/interfaces/kits/napi/src/native_module.cpp @@ -34,9 +34,11 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("isOpenAccessibility", NAccessibilityClient::IsOpenAccessibility), DECLARE_NAPI_FUNCTION("isOpenTouchGuide", NAccessibilityClient::IsOpenTouchExploration), DECLARE_NAPI_FUNCTION("getAbilityLists", NAccessibilityClient::GetAbilityList), + DECLARE_NAPI_FUNCTION("getAccessibilityExtensionList", NAccessibilityClient::GetAbilityList), DECLARE_NAPI_FUNCTION("on", NAccessibilityClient::SubscribeState), DECLARE_NAPI_FUNCTION("off", NAccessibilityClient::UnsubscribeState), DECLARE_NAPI_FUNCTION("sendEvent", NAccessibilityClient::SendEvent), + DECLARE_NAPI_FUNCTION("sendAccessibilityEvent", NAccessibilityClient::SendEvent), DECLARE_NAPI_FUNCTION("getCaptionsManager", NAccessibilityClient::GetCaptionsManager), }; diff --git a/services/aams/include/accessibility_account_data.h b/services/aams/include/accessibility_account_data.h index 12e1361d8..9bab48e66 100644 --- a/services/aams/include/accessibility_account_data.h +++ b/services/aams/include/accessibility_account_data.h @@ -122,9 +122,9 @@ public: /** * @brief Remove accessibility that have been opened. * @param name bundle name + / + ability name. - * @return return true if removes enabled ability successfully, else return false. + * @return return true if removes enabled ability successfully, otherwise refer to the RetError for the failure. */ - bool RemoveEnabledAbility(const std::string &name); + RetError RemoveEnabledAbility(const std::string &name); void AddInstalledAbility(AccessibilityAbilityInfo& abilityInfo); // For UT @@ -248,7 +248,7 @@ public: std::shared_ptr GetConfig(); - bool EnableAbility(const std::string &name, const uint32_t capabilities); + RetError EnableAbility(const std::string &name, const uint32_t capabilities); void Init(); @@ -300,9 +300,6 @@ private: void UpdateEnableAbilityListsState(); - bool SetAbilityCapabilities(const std::string &name, const uint32_t capabilities); - uint32_t GetAbilityStaticCapabilities(const std::string &name) const; - int32_t id_; bool isEventTouchGuideState_ = false; bool isScreenMagnification_ = false; diff --git a/services/aams/include/accessible_ability_channel.h b/services/aams/include/accessible_ability_channel.h index d22c4b513..26f93789d 100644 --- a/services/aams/include/accessible_ability_channel.h +++ b/services/aams/include/accessible_ability_channel.h @@ -28,42 +28,42 @@ class AccessibleAbilityChannel : public AccessibleAbilityChannelStub { public: AccessibleAbilityChannel(const int32_t accountId, const std::string &clientName); ~AccessibleAbilityChannel() = default; - bool SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, const int32_t elementId, + RetError SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr &callback, const int32_t mode) override; - bool SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, + RetError SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, const std::string &text, const int32_t requestId, const sptr &callback) override; - bool FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, + RetError FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, const int32_t requestId, const sptr &callback) override; - bool FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, + RetError FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, const int32_t requestId, const sptr &callback) override; - bool ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, + RetError ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map &actionArguments, const int32_t requestId, const sptr &callback) override; - bool GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; + RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override; - bool GetWindows(std::vector &windows) override; + RetError GetWindows(std::vector &windows) override; - bool GetWindowsByDisplayId(const uint64_t displayId, std::vector &windows) override; + RetError GetWindowsByDisplayId(const uint64_t displayId, std::vector &windows) override; void SetOnKeyPressEventResult(const bool handled, const int32_t sequence) override; - bool SendSimulateGesture(const std::shared_ptr& gesturePath) override; + RetError SendSimulateGesture(const std::shared_ptr& gesturePath) override; - bool SetTargetBundleName(const std::vector &targetBundleNames) override; + RetError SetTargetBundleName(const std::vector &targetBundleNames) override; private: static sptr GetConnection(int32_t accountId, const std::string &clientName); - static sptr GetElementOperator( - int32_t accountId, int32_t windowId, int32_t focusType, const std::string &clientName); - bool GetWindows(uint64_t displayId, std::vector &windows) const; + static RetError GetElementOperator(int32_t accountId, int32_t windowId, int32_t focusType, + const std::string &clientName, sptr &elementOperator); + RetError GetWindows(uint64_t displayId, std::vector &windows) const; std::string clientName_ = ""; int32_t accountId_ = -1; diff --git a/services/aams/include/accessible_ability_manager_service.h b/services/aams/include/accessible_ability_manager_service.h index e55a0178d..0619a6190 100644 --- a/services/aams/include/accessible_ability_manager_service.h +++ b/services/aams/include/accessible_ability_manager_service.h @@ -63,7 +63,7 @@ public: public: /* For AccessibleAbilityManagerServiceStub */ - void SendEvent(const AccessibilityEventInfo &uiEvent) override; + RetError SendEvent(const AccessibilityEventInfo &uiEvent) override; uint32_t RegisterStateObserver(const sptr &callback) override; @@ -72,13 +72,13 @@ public: void RegisterEnableAbilityListsObserver( const sptr &observer) override; - bool GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, + RetError GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, std::vector &infos) override; - void RegisterElementOperator(const int32_t windowId, + RetError RegisterElementOperator(const int32_t windowId, const sptr &operation) override; - void DeregisterElementOperator(const int32_t windowId) override; + RetError DeregisterElementOperator(const int32_t windowId) override; RetError GetCaptionProperty(AccessibilityConfig::CaptionProperty &caption) override; RetError SetCaptionProperty(const AccessibilityConfig::CaptionProperty &caption) override; @@ -90,11 +90,11 @@ public: bool GetGestureState() override; bool GetKeyEventObserverState() override; - bool EnableAbility(const std::string &name, const uint32_t capabilities) override; - bool GetEnabledAbilities(std::vector &enabledAbilities) override; - bool DisableAbility(const std::string &name) override; + RetError EnableAbility(const std::string &name, const uint32_t capabilities) override; + RetError GetEnabledAbilities(std::vector &enabledAbilities) override; + RetError DisableAbility(const std::string &name) override; RetError EnableUITestAbility(const sptr& obj) override; - bool DisableUITestAbility() override; + RetError DisableUITestAbility() override; int32_t GetActiveWindow() override; public: @@ -249,8 +249,8 @@ private: void OnRemoteDied(const wptr &remote) final; }; - bool InnerEnableAbility(const std::string &name, const uint32_t capabilities); - bool InnerDisableAbility(const std::string &name); + RetError InnerEnableAbility(const std::string &name, const uint32_t capabilities); + RetError InnerDisableAbility(const std::string &name); sptr GetAccessibilityWindowConnection(int32_t windowId); void ClearFocus(int32_t windowId); diff --git a/services/aams/src/accessibility_account_data.cpp b/services/aams/src/accessibility_account_data.cpp index f24a3cf2f..df5130b2d 100644 --- a/services/aams/src/accessibility_account_data.cpp +++ b/services/aams/src/accessibility_account_data.cpp @@ -244,7 +244,7 @@ void AccessibilityAccountData::AddEnabledAbility(const std::string &name) HILOG_DEBUG("Add EnabledAbility: %{public}zu", enabledAbilities_.size()); } -bool AccessibilityAccountData::RemoveEnabledAbility(const std::string &name) +RetError AccessibilityAccountData::RemoveEnabledAbility(const std::string &name) { HILOG_DEBUG("start"); for (auto it = enabledAbilities_.begin(); it != enabledAbilities_.end(); it++) { @@ -253,11 +253,11 @@ bool AccessibilityAccountData::RemoveEnabledAbility(const std::string &name) enabledAbilities_.erase(it); UpdateEnableAbilityListsState(); HILOG_DEBUG("EnabledAbility size(%{public}zu)", enabledAbilities_.size()); - return true; + return RET_OK; } } HILOG_ERROR("The ability(%{public}s) is not enabled.", name.c_str()); - return false; + return RET_ERR_NOT_ENABLED; } void AccessibilityAccountData::AddInstalledAbility(AccessibilityAbilityInfo& abilityInfo) @@ -469,25 +469,30 @@ void AccessibilityAccountData::UpdateMagnificationCapability() isScreenMagnification_ = false; } -bool AccessibilityAccountData::EnableAbility(const std::string &name, const uint32_t capabilities) +RetError AccessibilityAccountData::EnableAbility(const std::string &name, const uint32_t capabilities) { HILOG_DEBUG("start and name[%{public}s] capabilities[%{public}d]", name.c_str(), capabilities); - // Parse config from bms according to bundle name and ability name - uint32_t configCapabilities = GetAbilityStaticCapabilities(name); + bool isInstalled = false; + for (auto itr = installedAbilities_.begin(); itr != installedAbilities_.end(); itr++) { + if (itr->GetId() == name) { + isInstalled = true; - // Judge capabilities - uint32_t resultCapabilities = configCapabilities & capabilities; - HILOG_DEBUG("resultCapabilities is [%{public}d]", resultCapabilities); - if (resultCapabilities == 0) { - HILOG_ERROR("the result of capabilities is wrong"); - return false; + // Judge capabilities + uint32_t resultCapabilities = itr->GetStaticCapabilityValues() & capabilities; + HILOG_DEBUG("resultCapabilities is [%{public}d]", resultCapabilities); + if (resultCapabilities == 0) { + HILOG_ERROR("the result of capabilities is wrong"); + return RET_ERR_NO_CAPABILITY; + } + + itr->SetCapabilityValues(capabilities); + break; + } } - - bool result = SetAbilityCapabilities(name, resultCapabilities); - if (!result) { - HILOG_ERROR("Reset capabilities failed"); - return false; + if (!isInstalled) { + HILOG_ERROR("the ability[%{public}s] is not installed", name.c_str()); + return RET_ERR_NOT_INSTALLED; } // Add enabled ability @@ -496,13 +501,13 @@ bool AccessibilityAccountData::EnableAbility(const std::string &name, const uint return abilityName == name; })) { HILOG_ERROR("The ability[%{public}s] is already enabled", name.c_str()); - return false; + return RET_ERR_CONNECTION_EXIST; } enabledAbilities_.push_back(name); UpdateEnableAbilityListsState(); UpdateAbilities(); Utils::RecordStartingA11yEvent(name); - return true; + return RET_OK; } bool AccessibilityAccountData::GetInstalledAbilitiesFromBMS() @@ -542,32 +547,6 @@ void AccessibilityAccountData::Init() } } -bool AccessibilityAccountData::SetAbilityCapabilities(const std::string &name, const uint32_t capabilities) -{ - HILOG_DEBUG("start. name[%{public}s] capabilities[%{public}d]", name.c_str(), capabilities); - for (auto &installedAbility : installedAbilities_) { - if (installedAbility.GetId() == name) { - HILOG_DEBUG("reset ability capabilities"); - installedAbility.SetCapabilityValues(capabilities); - return true; - } - } - HILOG_ERROR("not found the ability %{public}s", name.c_str()); - return false; -} - -uint32_t AccessibilityAccountData::GetAbilityStaticCapabilities(const std::string &name) const -{ - HILOG_DEBUG("start. name[%{public}s]", name.c_str()); - for (auto &installedAbility : installedAbilities_) { - if (installedAbility.GetId() == name) { - return installedAbility.GetStaticCapabilityValues(); - } - } - HILOG_ERROR("not found the ability %{public}s", name.c_str()); - return 0; -} - void AccessibilityAccountData::AddConfigCallback( const sptr& callback) { diff --git a/services/aams/src/accessibility_window_manager.cpp b/services/aams/src/accessibility_window_manager.cpp index f810b06c1..e9ac21270 100644 --- a/services/aams/src/accessibility_window_manager.cpp +++ b/services/aams/src/accessibility_window_manager.cpp @@ -149,7 +149,7 @@ int32_t AccessibilityWindowManager::ConvertToRealWindowId(int32_t windowId, int3 return activeWindowId_; } } - HILOG_DEBUG("After convert windowId[%{public}d]", windowId); + HILOG_DEBUG("After convert windowId[%{public}d] and activeId[%{public}d]", windowId, activeWindowId_); return windowId; } diff --git a/services/aams/src/accessible_ability_channel.cpp b/services/aams/src/accessible_ability_channel.cpp index 2d9b20ec5..eb716f612 100644 --- a/services/aams/src/accessible_ability_channel.cpp +++ b/services/aams/src/accessible_ability_channel.cpp @@ -29,7 +29,7 @@ AccessibleAbilityChannel::AccessibleAbilityChannel(const int32_t accountId, cons Singleton::GetInstance().GetMainRunner()); } -bool AccessibleAbilityChannel::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannel::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr &callback, const int32_t mode) { @@ -37,24 +37,29 @@ bool AccessibleAbilityChannel::SearchElementInfoByAccessibilityId(const int32_t if (!eventHandler_) { HILOG_ERROR("eventHandler_ is nullptr."); - return false; + return RET_ERR_NULLPTR; } - eventHandler_->PostTask(std::bind([=](int32_t accountId, const std::string &name) -> void { + std::promise syncPromise; + std::future syncFuture = syncPromise.get_future(); + eventHandler_->PostTask(std::bind([&syncPromise, accessibilityWindowId, elementId, requestId, callback, mode]( + int32_t accountId, const std::string &name) -> void { HILOG_DEBUG("accountId[%{public}d], name[%{public}s]", accountId, name.c_str()); - sptr elementOperator = - GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name); - if (!elementOperator) { + sptr elementOperator = nullptr; + RetError ret = GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name, elementOperator); + if (ret != RET_OK) { HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", accessibilityWindowId); + syncPromise.set_value(ret); return; } elementOperator->SearchElementInfoByAccessibilityId(elementId, requestId, callback, mode); HILOG_DEBUG("AccessibleAbilityChannel::SearchElementInfoByAccessibilityId successfully"); + syncPromise.set_value(RET_OK); }, accountId_, clientName_), "SearchElementInfoByAccessibilityId"); - return true; + return syncFuture.get(); } -bool AccessibleAbilityChannel::SearchElementInfosByText(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannel::SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, const std::string &text, const int32_t requestId, const sptr &callback) { @@ -62,23 +67,28 @@ bool AccessibleAbilityChannel::SearchElementInfosByText(const int32_t accessibil if (!eventHandler_) { HILOG_ERROR("eventHandler_ is nullptr."); - return false; + return RET_ERR_NULLPTR; } - eventHandler_->PostTask(std::bind([=](int32_t accountId, const std::string &name) -> void { + std::promise syncPromise; + std::future syncFuture = syncPromise.get_future(); + eventHandler_->PostTask(std::bind([&syncPromise, accessibilityWindowId, elementId, text, requestId, callback]( + int32_t accountId, const std::string &name) -> void { HILOG_DEBUG("accountId[%{public}d], name[%{public}s]", accountId, name.c_str()); - sptr elementOperator = - GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name); - if (!elementOperator) { + sptr elementOperator = nullptr; + RetError ret = GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name, elementOperator); + if (ret != RET_OK) { HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", accessibilityWindowId); + syncPromise.set_value(ret); return; } elementOperator->SearchElementInfosByText(elementId, text, requestId, callback); + syncPromise.set_value(RET_OK); }, accountId_, clientName_), "SearchElementInfosByText"); - return true; + return syncFuture.get(); } -bool AccessibleAbilityChannel::FindFocusedElementInfo(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannel::FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, const int32_t requestId, const sptr &callback) { @@ -86,46 +96,56 @@ bool AccessibleAbilityChannel::FindFocusedElementInfo(const int32_t accessibilit if (!eventHandler_) { HILOG_ERROR("eventHandler_ is nullptr."); - return false; + return RET_ERR_NULLPTR; } - eventHandler_->PostTask(std::bind([=](int32_t accountId, const std::string &name) -> void { + std::promise syncPromise; + std::future syncFuture = syncPromise.get_future(); + eventHandler_->PostTask(std::bind([&syncPromise, accessibilityWindowId, elementId, + focusType, requestId, callback](int32_t accountId, const std::string &name) -> void { HILOG_DEBUG("accountId[%{public}d], name[%{public}s]", accountId, name.c_str()); - sptr elementOperator = - GetElementOperator(accountId, accessibilityWindowId, focusType, name); - if (!elementOperator) { + sptr elementOperator = nullptr; + RetError ret = GetElementOperator(accountId, accessibilityWindowId, focusType, name, elementOperator); + if (ret != RET_OK) { HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", accessibilityWindowId); + syncPromise.set_value(ret); return; } elementOperator->FindFocusedElementInfo(elementId, focusType, requestId, callback); + syncPromise.set_value(RET_OK); }, accountId_, clientName_), "FindFocusedElementInfo"); - return true; + return syncFuture.get(); } -bool AccessibleAbilityChannel::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, +RetError AccessibleAbilityChannel::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, const int32_t requestId, const sptr &callback) { HILOG_DEBUG(); if (!eventHandler_) { HILOG_ERROR("eventHandler_ is nullptr."); - return false; + return RET_ERR_NULLPTR; } - eventHandler_->PostTask(std::bind([=](int32_t accountId, const std::string &name) -> void { + std::promise syncPromise; + std::future syncFuture = syncPromise.get_future(); + eventHandler_->PostTask(std::bind([&syncPromise, accessibilityWindowId, + elementId, direction, requestId, callback](int32_t accountId, const std::string &name) -> void { HILOG_DEBUG("accountId[%{public}d], name[%{public}s]", accountId, name.c_str()); - sptr elementOperator = - GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name); - if (!elementOperator) { + sptr elementOperator = nullptr; + RetError ret = GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name, elementOperator); + if (ret != RET_OK) { HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", accessibilityWindowId); + syncPromise.set_value(ret); return; } elementOperator->FocusMoveSearch(elementId, direction, requestId, callback); + syncPromise.set_value(RET_OK); }, accountId_, clientName_), "FocusMoveSearch"); - return true; + return syncFuture.get(); } -bool AccessibleAbilityChannel::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, +RetError AccessibleAbilityChannel::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map &actionArguments, const int32_t requestId, const sptr &callback) { @@ -133,32 +153,37 @@ bool AccessibleAbilityChannel::ExecuteAction(const int32_t accessibilityWindowId if (!eventHandler_) { HILOG_ERROR("eventHandler_ is nullptr."); - return false; + return RET_ERR_NULLPTR; } - eventHandler_->PostTask(std::bind([=](int32_t accountId, const std::string &name) -> void { + std::promise syncPromise; + std::future syncFuture = syncPromise.get_future(); + eventHandler_->PostTask(std::bind([&syncPromise, accessibilityWindowId, elementId, action, + actionArguments, requestId, callback](int32_t accountId, const std::string &name) -> void { HILOG_DEBUG("accountId[%{public}d], name[%{public}s]", accountId, name.c_str()); - sptr elementOperator = - GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name); - if (!elementOperator) { + sptr elementOperator = nullptr; + RetError ret = GetElementOperator(accountId, accessibilityWindowId, FOCUS_TYPE_INVALID, name, elementOperator); + if (ret != RET_OK) { HILOG_ERROR("Get elementOperator failed! accessibilityWindowId[%{public}d]", accessibilityWindowId); + syncPromise.set_value(ret); return; } elementOperator->ExecuteAction(elementId, action, actionArguments, requestId, callback); + syncPromise.set_value(RET_OK); }, accountId_, clientName_), "ExecuteAction"); - return true; + return syncFuture.get(); } -bool AccessibleAbilityChannel::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) +RetError AccessibleAbilityChannel::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) { HILOG_DEBUG("windowId:%{public}d", windowId); if (!eventHandler_) { HILOG_ERROR("eventHandler_ is nullptr."); - return false; + return RET_ERR_NULLPTR; } - std::promise syncPromise; + std::promise syncPromise; std::future syncFuture = syncPromise.get_future(); eventHandler_->PostTask(std::bind([windowId, &windowInfo, &syncPromise]( int32_t accountId, const std::string &name) -> void { @@ -166,25 +191,25 @@ bool AccessibleAbilityChannel::GetWindow(const int32_t windowId, AccessibilityWi sptr clientConnection = GetConnection(accountId, name); if (!clientConnection) { HILOG_ERROR("There is no client connection"); - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NO_CONNECTION); return; } if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) { HILOG_ERROR("AccessibleAbilityChannel::GetWindow failed: no capability"); - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NO_CAPABILITY); return; } if (Singleton::GetInstance().GetAccessibilityWindow(windowId, windowInfo)) { - syncPromise.set_value(true); + syncPromise.set_value(RET_OK); } else { - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NO_WINDOW_CONNECTION); } }, accountId_, clientName_), "GetWindow"); return syncFuture.get(); } -bool AccessibleAbilityChannel::GetWindows(std::vector &windows) +RetError AccessibleAbilityChannel::GetWindows(std::vector &windows) { HILOG_DEBUG(); uint64_t displayId = Singleton::GetInstance().GetDefaultDisplayId(); @@ -192,21 +217,21 @@ bool AccessibleAbilityChannel::GetWindows(std::vector & return GetWindows(displayId, windows); } -bool AccessibleAbilityChannel::GetWindowsByDisplayId(const uint64_t displayId, +RetError AccessibleAbilityChannel::GetWindowsByDisplayId(const uint64_t displayId, std::vector &windows) { HILOG_DEBUG(); return GetWindows(displayId, windows); } -bool AccessibleAbilityChannel::GetWindows(uint64_t displayId, std::vector &windows) const +RetError AccessibleAbilityChannel::GetWindows(uint64_t displayId, std::vector &windows) const { if (!eventHandler_) { HILOG_ERROR("eventHandler_ is nullptr."); - return false; + return RET_ERR_NULLPTR; } - std::promise syncPromise; + std::promise syncPromise; std::future syncFuture = syncPromise.get_future(); eventHandler_->PostTask(std::bind([displayId, &windows, &syncPromise]( int32_t accountId, const std::string &name) -> void { @@ -214,13 +239,13 @@ bool AccessibleAbilityChannel::GetWindows(uint64_t displayId, std::vector clientConnection = GetConnection(accountId, name); if (!clientConnection) { HILOG_ERROR("There is no client connection"); - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NO_CONNECTION); return; } if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) { HILOG_ERROR("GetWindows failed: no capability"); - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NO_CAPABILITY); return; } @@ -231,7 +256,7 @@ bool AccessibleAbilityChannel::GetWindows(uint64_t displayId, std::vector& gesturePath) +RetError AccessibleAbilityChannel::SendSimulateGesture( + const std::shared_ptr& gesturePath) { HILOG_INFO(); if (!eventHandler_) { HILOG_ERROR("eventHandler_ is nullptr"); - return false; + return RET_ERR_NULLPTR; } - std::promise syncPromise; + std::promise syncPromise; std::future syncFuture = syncPromise.get_future(); eventHandler_->PostTask(std::bind([gesturePath, &syncPromise](int32_t accountId, const std::string &name) -> void { @@ -276,13 +302,13 @@ bool AccessibleAbilityChannel::SendSimulateGesture(const std::shared_ptr clientConnection = GetConnection(accountId, name); if (!clientConnection) { HILOG_ERROR("There is no client connection"); - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NO_CONNECTION); return; } if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_GESTURE)) { HILOG_ERROR("AccessibleAbilityChannel::SendSimulateGesture failed: no capability"); - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NO_CAPABILITY); return; } @@ -290,23 +316,23 @@ bool AccessibleAbilityChannel::SendSimulateGesture(const std::shared_ptr::GetInstance().GetTouchEventInjector(); if (!touchEventInjector) { HILOG_ERROR("touchEventInjector is null"); - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NO_INJECTOR); return; } touchEventInjector->InjectEvents(gesturePath); - syncPromise.set_value(true); + syncPromise.set_value(RET_OK); }, accountId_, clientName_), "SendSimulateGesture"); return syncFuture.get(); } -bool AccessibleAbilityChannel::SetTargetBundleName(const std::vector &targetBundleNames) +RetError AccessibleAbilityChannel::SetTargetBundleName(const std::vector &targetBundleNames) { HILOG_DEBUG(); if (!eventHandler_) { HILOG_ERROR("eventHandler_ is nullptr"); - return false; + return RET_ERR_NULLPTR; } - std::promise syncPromise; + std::promise syncPromise; std::future syncFuture = syncPromise.get_future(); eventHandler_->PostTask(std::bind([targetBundleNames, &syncPromise]( @@ -315,12 +341,12 @@ bool AccessibleAbilityChannel::SetTargetBundleName(const std::vector clientConnection = GetConnection(accountId, name); if (!clientConnection) { HILOG_ERROR("There is no client connection"); - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NO_CONNECTION); return; } clientConnection->SetAbilityInfoTargetBundleName(targetBundleNames); - syncPromise.set_value(true); + syncPromise.set_value(RET_OK); }, accountId_, clientName_), "SetTargetBundleName"); return syncFuture.get(); } @@ -340,33 +366,40 @@ sptr AccessibleAbilityChannel::GetConnection( return accountData->GetAccessibleAbilityConnection(clientName); } -sptr AccessibleAbilityChannel::GetElementOperator( - int32_t accountId, int32_t windowId, int32_t focusType, const std::string &clientName) +RetError AccessibleAbilityChannel::GetElementOperator( + int32_t accountId, int32_t windowId, int32_t focusType, const std::string &clientName, + sptr &elementOperator) { HILOG_DEBUG(); + elementOperator = nullptr; sptr clientConnection = GetConnection(accountId, clientName); if (!clientConnection) { HILOG_ERROR("There is no client connection"); - return nullptr; + return RET_ERR_NO_CONNECTION; } if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) { HILOG_ERROR("the client has no retieve capability"); - return nullptr; + return RET_ERR_NO_CAPABILITY; } sptr accountData = Singleton::GetInstance().GetAccountData(accountId); if (!accountData) { HILOG_ERROR("accountData is nullptr"); - return nullptr; + return RET_ERR_NULLPTR; } int32_t realId = Singleton::GetInstance().ConvertToRealWindowId(windowId, focusType); sptr connection = accountData->GetAccessibilityWindowConnection(realId); if (!connection) { HILOG_ERROR("windowId[%{public}d] has no connection", realId); - return nullptr; + return RET_ERR_NO_WINDOW_CONNECTION; } - return connection->GetProxy(); + elementOperator = connection->GetProxy(); + if (!elementOperator) { + HILOG_ERROR("The proxy of window connection is nullptr"); + return RET_ERR_NULLPTR; + } + return RET_OK; } } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/services/aams/src/accessible_ability_manager_service.cpp b/services/aams/src/accessible_ability_manager_service.cpp index a5935bcbb..8b6599040 100644 --- a/services/aams/src/accessible_ability_manager_service.cpp +++ b/services/aams/src/accessible_ability_manager_service.cpp @@ -210,12 +210,12 @@ int AccessibleAbilityManagerService::Dump(int fd, const std::vectorDump(fd, args); } -void AccessibleAbilityManagerService::SendEvent(const AccessibilityEventInfo &uiEvent) +RetError AccessibleAbilityManagerService::SendEvent(const AccessibilityEventInfo &uiEvent) { HILOG_DEBUG("eventType[%{public}d] gestureId[%{public}d]", uiEvent.GetEventType(), uiEvent.GetGestureType()); if (!handler_) { HILOG_ERROR("Parameters check failed!"); - return; + return RET_ERR_NULLPTR; } UpdateAccessibilityWindowStateByEvent(uiEvent); @@ -235,6 +235,7 @@ void AccessibleAbilityManagerService::SendEvent(const AccessibilityEventInfo &ui } } }, uiEvent), "TASK_SEND_EVENT"); + return RET_OK; } uint32_t AccessibleAbilityManagerService::RegisterStateObserver( @@ -364,22 +365,22 @@ void AccessibleAbilityManagerService::RegisterEnableAbilityListsObserver( return syncFuture.get(); } -bool AccessibleAbilityManagerService::GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, +RetError AccessibleAbilityManagerService::GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, std::vector &infos) { HILOG_DEBUG("abilityTypes(%{public}d) stateType(%{public}d)", abilityTypes, stateType); if (!handler_ || (stateType > ABILITY_STATE_INSTALLED) || (stateType < ABILITY_STATE_ENABLE)) { HILOG_ERROR("Parameters check failed! stateType:%{public}d, handler:%{public}p", stateType, handler_.get()); - return false; + return RET_ERR_INVALID_PARAM; } - std::promise syncPromise; + std::promise syncPromise; std::future syncFuture = syncPromise.get_future(); handler_->PostTask(std::bind([this, &syncPromise, &infos, abilityTypes, stateType]() -> void { sptr accountData = GetCurrentAccountData(); if (!accountData) { HILOG_ERROR("Get current account data failed!!"); - syncPromise.set_value(); + syncPromise.set_value(RET_ERR_FAILED); return; } @@ -393,21 +394,19 @@ bool AccessibleAbilityManagerService::GetAbilityList(const uint32_t abilityTypes } } HILOG_DEBUG("infos count is %{public}zu", infos.size()); - syncPromise.set_value(); + syncPromise.set_value(RET_OK); }), "TASK_GET_ABILITY_LIST"); - syncFuture.get(); - - return true; + return syncFuture.get(); } -void AccessibleAbilityManagerService::RegisterElementOperator( +RetError AccessibleAbilityManagerService::RegisterElementOperator( const int32_t windowId, const sptr &operation) { if (!handler_) { Utils::RecordUnavailableEvent(A11yUnavailableEvent::CONNECT_EVENT, A11yError::ERROR_CONNECT_TARGET_APPLICATION_FAILED); HILOG_ERROR("handler_ is nullptr."); - return; + return RET_ERR_NULLPTR; } handler_->PostTask(std::bind([=]() -> void { @@ -452,13 +451,14 @@ void AccessibleAbilityManagerService::RegisterElementOperator( HILOG_DEBUG("The result of adding operation's death recipient is %{public}d", result); } }), "TASK_REGISTER_ELEMENT_OPERATOR"); + return RET_OK; } -void AccessibleAbilityManagerService::DeregisterElementOperator(int32_t windowId) +RetError AccessibleAbilityManagerService::DeregisterElementOperator(int32_t windowId) { if (!handler_) { HILOG_ERROR("handler_ is nullptr."); - return; + return RET_ERR_NULLPTR; } handler_->PostTask(std::bind([=]() -> void { @@ -491,6 +491,7 @@ void AccessibleAbilityManagerService::DeregisterElementOperator(int32_t windowId } } }), "TASK_DEREGISTER_ELEMENT_OPERATOR"); + return RET_OK; } RetError AccessibleAbilityManagerService::GetCaptionProperty(AccessibilityConfig::CaptionProperty &caption) @@ -686,94 +687,92 @@ bool AccessibleAbilityManagerService::GetKeyEventObserverState() return syncFuture.get(); } -bool AccessibleAbilityManagerService::EnableAbility(const std::string &name, const uint32_t capabilities) +RetError AccessibleAbilityManagerService::EnableAbility(const std::string &name, const uint32_t capabilities) { HILOG_DEBUG(); if (!handler_) { HILOG_ERROR("handler_ is nullptr."); - return false; + return RET_ERR_NULLPTR; } - std::promise syncPromise; + std::promise syncPromise; std::future syncFuture = syncPromise.get_future(); handler_->PostTask(std::bind([this, &syncPromise, &name, &capabilities]() -> void { HILOG_DEBUG(); - bool result = InnerEnableAbility(name, capabilities); + RetError result = InnerEnableAbility(name, capabilities); syncPromise.set_value(result); }), "TASK_ENABLE_ABILITIES"); return syncFuture.get(); } -bool AccessibleAbilityManagerService::InnerEnableAbility(const std::string &name, const uint32_t capabilities) +RetError AccessibleAbilityManagerService::InnerEnableAbility(const std::string &name, const uint32_t capabilities) { HILOG_DEBUG(); sptr accountData = GetCurrentAccountData(); if (!accountData) { HILOG_ERROR("accountData is nullptr"); - return false; + return RET_ERR_NULLPTR; } - bool result = accountData->EnableAbility(name, capabilities); - return result; + return accountData->EnableAbility(name, capabilities); } -bool AccessibleAbilityManagerService::GetEnabledAbilities(std::vector &enabledAbilities) +RetError AccessibleAbilityManagerService::GetEnabledAbilities(std::vector &enabledAbilities) { HILOG_DEBUG(); if (!handler_) { HILOG_ERROR("handler_ is nullptr."); - return false; + return RET_ERR_NULLPTR; } - std::promise syncPromise; + std::promise syncPromise; std::future syncFuture = syncPromise.get_future(); handler_->PostTask(std::bind([this, &syncPromise, &enabledAbilities]() -> void { HILOG_DEBUG(); sptr accountData = GetCurrentAccountData(); if (!accountData) { HILOG_ERROR("accountData is nullptr"); - syncPromise.set_value(); + syncPromise.set_value(RET_ERR_NULLPTR); return; } enabledAbilities = accountData->GetEnabledAbilities(); - syncPromise.set_value(); + syncPromise.set_value(RET_OK); }), "TASK_GET_ENABLE_ABILITIES"); - syncFuture.get(); - - return true; + return syncFuture.get(); } -bool AccessibleAbilityManagerService::DisableAbility(const std::string &name) +RetError AccessibleAbilityManagerService::DisableAbility(const std::string &name) { HILOG_DEBUG(); if (!handler_) { HILOG_ERROR("handler_ is nullptr."); - return false; + return RET_ERR_NULLPTR; } - std::promise syncPromise; + std::promise syncPromise; std::future syncFuture = syncPromise.get_future(); handler_->PostTask(std::bind([this, &syncPromise, &name]() -> void { HILOG_DEBUG(); - bool result = InnerDisableAbility(name); + RetError result = InnerDisableAbility(name); syncPromise.set_value(result); }), "TASK_DISABLE_ABILITIES"); return syncFuture.get(); } -bool AccessibleAbilityManagerService::InnerDisableAbility(const std::string &name) +RetError AccessibleAbilityManagerService::InnerDisableAbility(const std::string &name) { HILOG_DEBUG(); sptr accountData = GetCurrentAccountData(); if (!accountData) { HILOG_ERROR("accountData is nullptr"); - return false; + return RET_ERR_NULLPTR; } - if (!accountData->RemoveEnabledAbility(name)) { + RetError ret = accountData->RemoveEnabledAbility(name); + if (ret != RET_OK) { HILOG_ERROR("RemoveEnabledAbility failed"); - return false; + return ret; } accountData->UpdateAbilities(); - return true; + return RET_OK; } RetError AccessibleAbilityManagerService::EnableUITestAbility(const sptr &obj) @@ -810,35 +809,35 @@ RetError AccessibleAbilityManagerService::EnableUITestAbility(const sptr syncPromise; + std::promise syncPromise; std::future syncFuture = syncPromise.get_future(); handler_->PostTask(std::bind([this, &syncPromise]() -> void { HILOG_DEBUG(); sptr accountData = GetCurrentAccountData(); if (!accountData) { HILOG_ERROR("accountData is nullptr"); - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NULLPTR); return; } std::string uiTestUri = Utils::GetUri(UI_TEST_BUNDLE_NAME, UI_TEST_ABILITY_NAME); sptr connection = accountData->GetAccessibleAbilityConnection(uiTestUri); if (!connection) { HILOG_ERROR("connection is not existed!!"); - syncPromise.set_value(false); + syncPromise.set_value(RET_ERR_NO_CONNECTION); return; } std::function removeUITestClientFunc = std::bind(&AccessibilityAccountData::RemoveUITestClient, accountData, connection, UI_TEST_BUNDLE_NAME); handler_->PostTask(removeUITestClientFunc, "RemoveUITestClient"); - syncPromise.set_value(true); + syncPromise.set_value(RET_OK); }), "TASK_DISABLE_UI_TEST_ABILITIES"); return syncFuture.get(); } @@ -1888,9 +1887,7 @@ bool AccessibleAbilityManagerService::EnableShortKeyTargetAbility() } uint32_t capabilities = CAPABILITY_GESTURE | CAPABILITY_KEY_EVENT_OBSERVER | CAPABILITY_RETRIEVE | CAPABILITY_TOUCH_GUIDE | CAPABILITY_ZOOM; - bool result = InnerEnableAbility(targetAbility, capabilities); - HILOG_DEBUG("result is %{public}d", result); - return result; + return InnerEnableAbility(targetAbility, capabilities) == RET_OK; } bool AccessibleAbilityManagerService::DisableShortKeyTargetAbility() @@ -1908,9 +1905,7 @@ bool AccessibleAbilityManagerService::DisableShortKeyTargetAbility() HILOG_ERROR("target ability is null"); return false; } - bool result = InnerDisableAbility(targetAbility); - HILOG_DEBUG("result is %{public}d", result); - return result; + return InnerDisableAbility(targetAbility) == RET_OK; } uint32_t AccessibleAbilityManagerService::RegisterConfigObserver( diff --git a/services/aams/test/BUILD.gn b/services/aams/test/BUILD.gn index 149785a27..567de38b4 100644 --- a/services/aams/test/BUILD.gn +++ b/services/aams/test/BUILD.gn @@ -290,7 +290,6 @@ ohos_unittest("accessibility_input_interceptor_test") { "../src/accessibility_mouse_autoclick.cpp", "../src/accessibility_mouse_key.cpp", "../src/accessibility_short_key.cpp", - "../src/accessible_ability_manager_service.cpp", "../src/accessible_ability_manager_service_event_handler.cpp", "../src/utils.cpp", "//foundation/barrierfree/accessibility/common/interface/src/accessible_ability_channel_proxy.cpp", @@ -307,6 +306,7 @@ ohos_unittest("accessibility_input_interceptor_test") { "mock/src/mock_accessibility_touchEvent_injector.cpp", "mock/src/mock_accessibility_touch_guider.cpp", "mock/src/mock_accessibility_window_manager.cpp", + "mock/src/mock_accessible_ability_manager_service.cpp", "mock/src/mock_accessible_ability_manager_service_stub.cpp", "mock/src/mock_os_account_manager.cpp", "mock/src/mock_system_ability.cpp", @@ -600,6 +600,7 @@ ohos_unittest("accessibility_touchevent_injector_test") { "mock/src/mock_accessibility_common_event.cpp", "mock/src/mock_accessibility_event_transmission.cpp", "mock/src/mock_accessible_ability_client_stub_impl.cpp", + "mock/src/mock_accessible_ability_manager_service.cpp", "mock/src/mock_common_event_data.cpp", "mock/src/mock_common_event_manager.cpp", "mock/src/mock_common_event_subscribe_info.cpp", @@ -627,6 +628,7 @@ ohos_unittest("accessibility_touchevent_injector_test") { external_deps = [ "ability_base:want", "c_utils:utils", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "input:libmmi-client", "ipc:ipc_core", diff --git a/services/aams/test/mock/include/mock_accessibility_account_data.h b/services/aams/test/mock/include/mock_accessibility_account_data.h index 92720d7e4..2e7a9b084 100644 --- a/services/aams/test/mock/include/mock_accessibility_account_data.h +++ b/services/aams/test/mock/include/mock_accessibility_account_data.h @@ -40,7 +40,7 @@ public: MOCK_METHOD1(RemoveAccessibilityWindowConnection, void(const int32_t windowId)); MOCK_METHOD1(AddConnectingA11yAbility, void(const AppExecFwk::ElementName& elementName)); MOCK_METHOD1(AddEnabledAbility, void(const AppExecFwk::ElementName& elementName)); - MOCK_METHOD1(RemoveEnabledAbility, bool(const std::string& bundleName)); + MOCK_METHOD1(RemoveEnabledAbility, RetError(const std::string& bundleName)); MOCK_METHOD1(AddInstalledAbility, void(AccessibilityAbilityInfo& abilityInfo)); MOCK_METHOD1(RemoveInstalledAbility, void(const std::string &bundleName)); MOCK_METHOD0(ClearInstalledAbility, void()); diff --git a/services/aams/test/mock/include/mock_accessible_ability_connection.h b/services/aams/test/mock/include/mock_accessible_ability_connection.h index 6fc430735..6a2381e7c 100644 --- a/services/aams/test/mock/include/mock_accessible_ability_connection.h +++ b/services/aams/test/mock/include/mock_accessible_ability_connection.h @@ -27,26 +27,27 @@ public: ~MockAccessibleAbilityChannel(); MOCK_METHOD5(SearchElementInfoByAccessibilityId, - bool(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, + RetError(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr& callback, const int32_t mode)); MOCK_METHOD5(SearchElementInfosByText, - bool(const int32_t accessibilityWindowId, const int32_t elementId, const std::string& text, + RetError(const int32_t accessibilityWindowId, const int32_t elementId, const std::string& text, const int32_t requestId, const sptr& callback)); MOCK_METHOD5(FindFocusedElementInfo, - bool(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, + RetError(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, const int32_t requestId, const sptr& callback)); MOCK_METHOD5( - FocusMoveSearch, bool(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, + FocusMoveSearch, RetError(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, const int32_t requestId, const sptr& callback)); - MOCK_METHOD6(ExecuteAction, bool(const int32_t accessibilityWindowId, const int32_t elementId, + MOCK_METHOD6(ExecuteAction, RetError(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map &actionArguments, const int32_t requestId, const sptr& callback)); - MOCK_METHOD1(GetWindows, bool(std::vector &windows)); - MOCK_METHOD2(GetWindowsByDisplayId, bool(const uint64_t displayId, std::vector &windows)); + MOCK_METHOD1(GetWindows, RetError(std::vector &windows)); + MOCK_METHOD2(GetWindowsByDisplayId, RetError(const uint64_t displayId, + std::vector &windows)); MOCK_METHOD2(SetOnKeyPressEventResult, void(const bool handled, const int32_t sequence)); - MOCK_METHOD1(SendSimulateGesture, bool(const std::shared_ptr& gesturePath)); + MOCK_METHOD1(SendSimulateGesture, RetError(const std::shared_ptr& gesturePath)); }; class MockAccessibleAbilityConnection : public AccessibleAbilityConnection { diff --git a/services/aams/test/mock/include/mock_accessible_ability_manager_service.h b/services/aams/test/mock/include/mock_accessible_ability_manager_service.h index 1dc16b22f..4f8ba0800 100644 --- a/services/aams/test/mock/include/mock_accessible_ability_manager_service.h +++ b/services/aams/test/mock/include/mock_accessible_ability_manager_service.h @@ -27,16 +27,16 @@ class MockAccessibleAbilityManagerService : public AccessibleAbilityManagerServi public: MOCK_METHOD0(OnStart, void()); MOCK_METHOD0(OnStop, void()); - MOCK_METHOD1(SendEvent, void(const AccessibilityEventInfo& uiEvent)); + MOCK_METHOD1(SendEvent, RetError(const AccessibilityEventInfo& uiEvent)); MOCK_METHOD2(RegisterStateCallback, uint32_t(const sptr& callback, const int32_t accountId)); MOCK_METHOD2(RegisterCaptionPropertyCallback, uint32_t(const sptr& callback, const int32_t accountId)); - MOCK_METHOD3(GetAbilityList, bool(const uint32_t abilityTypes, const int32_t stateType, + MOCK_METHOD3(GetAbilityList, RetError(const uint32_t abilityTypes, const int32_t stateType, std::vector &infos)); MOCK_METHOD2(RegisterElementOperator, - void(const int32_t windowId, const sptr& operation)); - MOCK_METHOD1(DeregisterElementOperator, void(const int32_t windowId)); + RetError(const int32_t windowId, const sptr& operation)); + MOCK_METHOD1(DeregisterElementOperator, RetError(const int32_t windowId)); MOCK_METHOD1(GetCaptionProperty, RetError(AccessibilityConfig::CaptionProperty& caption)); MOCK_METHOD1(SetCaptionProperty, RetError(const AccessibilityConfig::CaptionProperty& caption)); MOCK_METHOD1(SetCaptionState, RetError(const bool state)); @@ -92,9 +92,7 @@ public: MOCK_METHOD1(SetGestureState, bool(const bool state)); MOCK_METHOD1(SetKeyEventObserverState, bool(const bool state)); MOCK_METHOD1(SetEnabledObj, bool(std::map it)); - MOCK_METHOD1(GetEnabledAbilities, bool(std::vector &enabledAbilities)); - MOCK_METHOD1(RegisterUITestAbilityConnectionClient, bool(const sptr& obj)); - MOCK_METHOD0(DeregisterUITestAbilityConnectionClient, bool()); + MOCK_METHOD1(GetEnabledAbilities, RetError(std::vector &enabledAbilities)); MOCK_METHOD0(GetActiveWindow, int32_t()); }; } // namespace Accessibility 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 26269924b..34644bd82 100644 --- a/services/aams/test/mock/src/mock_accessibility_account_data.cpp +++ b/services/aams/test/mock/src/mock_accessibility_account_data.cpp @@ -167,7 +167,7 @@ void AccessibilityAccountData::AddEnabledAbility(const std::string& bundleName) HILOG_DEBUG("Add EnabledAbility: %{public}zu", enabledAbilities_.size()); } -bool AccessibilityAccountData::RemoveEnabledAbility(const std::string &name) +RetError AccessibilityAccountData::RemoveEnabledAbility(const std::string &name) { HILOG_DEBUG("start"); for (auto it = enabledAbilities_.begin(); it != enabledAbilities_.end(); it++) { @@ -175,11 +175,11 @@ bool AccessibilityAccountData::RemoveEnabledAbility(const std::string &name) HILOG_DEBUG("Removed %{public}s from EnabledAbility: ", name.c_str()); enabledAbilities_.erase(it); HILOG_DEBUG("EnabledAbility size(%{public}zu)", enabledAbilities_.size()); - return true; + return RET_OK; } } HILOG_ERROR("The ability(%{public}s) is not enabled.", name.c_str()); - return false; + return RET_ERR_NOT_ENABLED; } // For UT @@ -286,17 +286,17 @@ void AccessibilityAccountData::UpdateMagnificationCapability() isScreenMagnification_ = false; } -bool AccessibilityAccountData::EnableAbility(const std::string &name, const uint32_t capabilities) +RetError AccessibilityAccountData::EnableAbility(const std::string &name, const uint32_t capabilities) { HILOG_DEBUG("start."); for (const auto &enabledAbility : enabledAbilities_) { if (enabledAbility == name) { HILOG_ERROR("The ability[%{public}s] is already enabled", name.c_str()); - return false; + return RET_ERR_CONNECTION_EXIST; } } enabledAbilities_.push_back(name); - return true; + return RET_OK; } bool AccessibilityAccountData::GetInstalledAbilitiesFromBMS() diff --git a/services/aams/test/mock/src/mock_accessible_ability_channel_proxy.cpp b/services/aams/test/mock/src/mock_accessible_ability_channel_proxy.cpp index 2d1ac1dfe..5b80391f9 100644 --- a/services/aams/test/mock/src/mock_accessible_ability_channel_proxy.cpp +++ b/services/aams/test/mock/src/mock_accessible_ability_channel_proxy.cpp @@ -39,7 +39,7 @@ bool AccessibleAbilityChannelProxy::SendTransactCmd( return true; } -bool AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr& callback, const int32_t mode) { @@ -48,10 +48,10 @@ bool AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const int (void)requestId; (void)callback; (void)mode; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, const std::string& text, const int32_t requestId, const sptr& callback) { @@ -60,21 +60,22 @@ bool AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t acces (void)requestId; (void)callback; (void)text; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, - const int32_t focusType, const int32_t requestId, const sptr& callback) +RetError AccessibleAbilityChannelProxy::FindFocusedElementInfo(const int32_t accessibilityWindowId, + const int32_t elementId, const int32_t focusType, const int32_t requestId, + const sptr& callback) { (void)accessibilityWindowId; (void)elementId; (void)requestId; (void)callback; (void)focusType; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, +RetError AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, const int32_t requestId, const sptr& callback) { (void)accessibilityWindowId; @@ -82,10 +83,10 @@ bool AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityW (void)requestId; (void)callback; (void)direction; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, +RetError AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map &actionArguments, const int32_t requestId, const sptr& callback) { @@ -94,28 +95,28 @@ bool AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWin (void)requestId; (void)callback; (void)actionArguments; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) +RetError AccessibleAbilityChannelProxy::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) { (void)windowId; (void)windowInfo; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::GetWindows(std::vector &windows) +RetError AccessibleAbilityChannelProxy::GetWindows(std::vector &windows) { (void)windows; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t displayId, +RetError AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t displayId, std::vector &windows) { (void)displayId; (void)windows; - return true; + return RET_OK; } void AccessibleAbilityChannelProxy::SetOnKeyPressEventResult(const bool handled, const int32_t sequence) @@ -124,17 +125,17 @@ void AccessibleAbilityChannelProxy::SetOnKeyPressEventResult(const bool handled, (void)sequence; } -bool AccessibleAbilityChannelProxy::SendSimulateGesture( +RetError AccessibleAbilityChannelProxy::SendSimulateGesture( const std::shared_ptr& gesturePath) { (void)gesturePath; - return true; + return RET_OK; } -bool AccessibleAbilityChannelProxy::SetTargetBundleName(const std::vector &targetBundleNames) +RetError AccessibleAbilityChannelProxy::SetTargetBundleName(const std::vector &targetBundleNames) { (void)targetBundleNames; - return true; + return RET_OK; } } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/services/aams/test/mock/src/mock_accessible_ability_connection.cpp b/services/aams/test/mock/src/mock_accessible_ability_connection.cpp index 778eac1f0..6434dd909 100644 --- a/services/aams/test/mock/src/mock_accessible_ability_connection.cpp +++ b/services/aams/test/mock/src/mock_accessible_ability_connection.cpp @@ -40,7 +40,7 @@ AccessibleAbilityChannel::AccessibleAbilityChannel(const int32_t accountId, cons { } -bool AccessibleAbilityChannel::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannel::SearchElementInfoByAccessibilityId(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t requestId, const sptr& callback, const int32_t mode) { @@ -49,10 +49,10 @@ bool AccessibleAbilityChannel::SearchElementInfoByAccessibilityId(const int32_t (void)requestId; (void)callback; (void)mode; - return true; + return RET_OK; } -bool AccessibleAbilityChannel::SearchElementInfosByText(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannel::SearchElementInfosByText(const int32_t accessibilityWindowId, const int32_t elementId, const std::string& text, const int32_t requestId, const sptr& callback) { @@ -61,10 +61,10 @@ bool AccessibleAbilityChannel::SearchElementInfosByText(const int32_t accessibil (void)text; (void)requestId; (void)callback; - return true; + return RET_OK; } -bool AccessibleAbilityChannel::FindFocusedElementInfo(const int32_t accessibilityWindowId, +RetError AccessibleAbilityChannel::FindFocusedElementInfo(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t focusType, const int32_t requestId, const sptr& callback) { @@ -73,10 +73,10 @@ bool AccessibleAbilityChannel::FindFocusedElementInfo(const int32_t accessibilit (void)focusType; (void)requestId; (void)callback; - return true; + return RET_OK; } -bool AccessibleAbilityChannel::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, +RetError AccessibleAbilityChannel::FocusMoveSearch(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t direction, const int32_t requestId, const sptr& callback) { (void)accessibilityWindowId; @@ -84,10 +84,10 @@ bool AccessibleAbilityChannel::FocusMoveSearch(const int32_t accessibilityWindow (void)direction; (void)requestId; (void)callback; - return true; + return RET_OK; } -bool AccessibleAbilityChannel::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, +RetError AccessibleAbilityChannel::ExecuteAction(const int32_t accessibilityWindowId, const int32_t elementId, const int32_t action, const std::map &actionArguments, const int32_t requestId, const sptr& callback) { @@ -97,46 +97,46 @@ bool AccessibleAbilityChannel::ExecuteAction(const int32_t accessibilityWindowId (void)actionArguments; (void)requestId; (void)callback; - return true; + return RET_OK; } -bool AccessibleAbilityChannel::GetWindows(uint64_t displayId, std::vector &windows) const +RetError AccessibleAbilityChannel::GetWindows(uint64_t displayId, std::vector &windows) const { (void)displayId; (void)windows; sptr clientConnection = GetConnection(accountId_, clientName_); if (!clientConnection) { HILOG_ERROR("There is no client connection"); - return false; + return RET_ERR_NO_CONNECTION; } if (!(clientConnection->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) { HILOG_ERROR("AccessibleAbilityChannel::GetWindows failed: no capability"); - return false; + return RET_ERR_NO_CAPABILITY; } - return true; + return RET_OK; } -bool AccessibleAbilityChannel::GetWindows(std::vector &windows) +RetError AccessibleAbilityChannel::GetWindows(std::vector &windows) { uint64_t displayId = 0; return GetWindows(displayId, windows); } -bool AccessibleAbilityChannel::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) +RetError AccessibleAbilityChannel::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) { (void)windowId; (void)windowInfo; - return true; + return RET_OK; } -bool AccessibleAbilityChannel::SetTargetBundleName(const std::vector &targetBundleNames) +RetError AccessibleAbilityChannel::SetTargetBundleName(const std::vector &targetBundleNames) { (void)targetBundleNames; - return true; + return RET_OK; } -bool AccessibleAbilityChannel::GetWindowsByDisplayId(const uint64_t displayId, +RetError AccessibleAbilityChannel::GetWindowsByDisplayId(const uint64_t displayId, std::vector &windows) { return GetWindows(displayId, windows); @@ -148,10 +148,11 @@ void AccessibleAbilityChannel::SetOnKeyPressEventResult(const bool handled, cons (void)sequence; } -bool AccessibleAbilityChannel::SendSimulateGesture(const std::shared_ptr& gesturePath) +RetError AccessibleAbilityChannel::SendSimulateGesture( + const std::shared_ptr& gesturePath) { (void)gesturePath; - return true; + return RET_OK; } sptr AccessibleAbilityChannel::GetConnection(int32_t accountId, diff --git a/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp b/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp index 015ed434c..880a5bfe0 100644 --- a/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp +++ b/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp @@ -79,7 +79,7 @@ int AccessibleAbilityManagerService::Dump(int fd, const std::vector &infos) { (void)abilityTypes; (void)stateType; (void)infos; - return true; + return RET_OK; } -void AccessibleAbilityManagerService::RegisterElementOperator( +RetError AccessibleAbilityManagerService::RegisterElementOperator( const int32_t windowId, const sptr& operation) { (void)windowId; (void)operation; + return RET_OK; } -void AccessibleAbilityManagerService::DeregisterElementOperator(int32_t windowId) +RetError AccessibleAbilityManagerService::DeregisterElementOperator(int32_t windowId) { (void)windowId; + return RET_OK; } sptr AccessibleAbilityManagerService::GetCurrentAccountData() @@ -195,17 +198,17 @@ bool AccessibleAbilityManagerService::GetKeyEventObserverState() return true; } -bool AccessibleAbilityManagerService::EnableAbility(const std::string &name, const uint32_t capabilities) +RetError AccessibleAbilityManagerService::EnableAbility(const std::string &name, const uint32_t capabilities) { (void)name; (void)capabilities; - return true; + return RET_OK; } -bool AccessibleAbilityManagerService::GetEnabledAbilities(std::vector &enabledAbilities) +RetError AccessibleAbilityManagerService::GetEnabledAbilities(std::vector &enabledAbilities) { (void)enabledAbilities; - return true; + return RET_OK; } uint32_t AccessibleAbilityManagerService::RegisterCaptionObserver( @@ -215,10 +218,10 @@ uint32_t AccessibleAbilityManagerService::RegisterCaptionObserver( return NO_ERROR; } -bool AccessibleAbilityManagerService::DisableAbility(const std::string &name) +RetError AccessibleAbilityManagerService::DisableAbility(const std::string &name) { (void)name; - return true; + return RET_OK; } RetError AccessibleAbilityManagerService::EnableUITestAbility(const sptr& obj) @@ -227,9 +230,9 @@ RetError AccessibleAbilityManagerService::EnableUITestAbility(const sptr accountData = new AccessibilityAccountData(accountId); accountData->Init(); + + AccessibilityAbilityInitParams initParams; + initParams.bundleName = "bundle"; + initParams.name = "ability"; + std::shared_ptr abilityInfo = std::make_shared(initParams); + accountData->AddInstalledAbility(*abilityInfo); + const std::string name = "bundle/ability"; uint32_t capabilities = 0; - bool test = accountData->EnableAbility(name, capabilities); - EXPECT_FALSE(test); + RetError test = accountData->EnableAbility(name, capabilities); + EXPECT_EQ(test, RET_ERR_NO_CAPABILITY); ASSERT_EQ(0, (int)accountData->GetConfig()->GetEnabledAbilityInfos().size()); GTEST_LOG_(INFO) << "AccessibilityAccountData_Unittest_EnableAbility_001 end"; @@ -949,7 +956,7 @@ HWTEST_F(AccessibilityAccountDataTest, AccessibilityAccountData_Unittest_EnableA accountData->AddInstalledAbility(*abilityInfo); std::string name = "bundle/ability"; accountData->AddEnabledAbility(name); - EXPECT_FALSE(accountData->EnableAbility(name, CAPABILITY_RETRIEVE)); + EXPECT_EQ(RET_ERR_CONNECTION_EXIST, accountData->EnableAbility(name, CAPABILITY_RETRIEVE)); GTEST_LOG_(INFO) << "AccessibilityAccountData_Unittest_EnableAbility_002 end"; } @@ -972,11 +979,24 @@ HWTEST_F(AccessibilityAccountDataTest, AccessibilityAccountData_Unittest_EnableA std::shared_ptr abilityInfo = std::make_shared(initParams); accountData->AddInstalledAbility(*abilityInfo); const std::string name = "bundle/ability"; - EXPECT_TRUE(accountData->EnableAbility(name, CAPABILITY_RETRIEVE)); + EXPECT_EQ(RET_OK, accountData->EnableAbility(name, CAPABILITY_RETRIEVE)); GTEST_LOG_(INFO) << "AccessibilityAccountData_Unittest_EnableAbility_003 end"; } +/** + * @tc.number: AccessibilityAccountData_Unittest_EnableAbility_004 + * @tc.name: EnableAbility + * @tc.desc: Enable specified ability which is not installed. + */ +HWTEST_F(AccessibilityAccountDataTest, AccessibilityAccountData_Unittest_EnableAbility_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityAccountData_Unittest_EnableAbility_004 start"; + sptr accountData = new AccessibilityAccountData(0); + EXPECT_EQ(RET_ERR_NOT_INSTALLED, accountData->EnableAbility("bundle/ability", 0)); + GTEST_LOG_(INFO) << "AccessibilityAccountData_Unittest_EnableAbility_004 end"; +} + /** * @tc.number: AccessibilityAccountData_Unittest_GetImportantEnabledAbilities_001 * @tc.name: GetImportantEnabledAbilities diff --git a/services/aams/test/unittest/accessibility_input_interceptor_test.cpp b/services/aams/test/unittest/accessibility_input_interceptor_test.cpp index 0438a6183..55db5ad25 100755 --- a/services/aams/test/unittest/accessibility_input_interceptor_test.cpp +++ b/services/aams/test/unittest/accessibility_input_interceptor_test.cpp @@ -51,8 +51,6 @@ void AccessibilityInputInterceptorTest::SetUpTestCase() { GTEST_LOG_(INFO) << "AccessibilityInputInterceptorTest SetUpTestCase"; Singleton::GetInstance().OnStart(); - AccessibilityCommonHelper::GetInstance().WaitForServicePublish(); - Singleton::GetInstance().SwitchedUser(AccessibilityAbilityHelper::accountId_); } void AccessibilityInputInterceptorTest::TearDownTestCase() diff --git a/services/aams/test/unittest/accessibility_touchEvent_injector_test.cpp b/services/aams/test/unittest/accessibility_touchEvent_injector_test.cpp index caa69d14d..53f26d1e9 100644 --- a/services/aams/test/unittest/accessibility_touchEvent_injector_test.cpp +++ b/services/aams/test/unittest/accessibility_touchEvent_injector_test.cpp @@ -55,8 +55,6 @@ void TouchEventInjectorTest::SetUpTestCase() { GTEST_LOG_(INFO) << "TouchEventInjectorTest SetUpTestCase"; Singleton::GetInstance().OnStart(); - AccessibilityCommonHelper::GetInstance().WaitForServicePublish(); - Singleton::GetInstance().SwitchedUser(AccessibilityAbilityHelper::accountId_); } void TouchEventInjectorTest::TearDownTestCase() diff --git a/services/aams/test/unittest/accessible_ability_channel_test.cpp b/services/aams/test/unittest/accessible_ability_channel_test.cpp index 5a196351c..0076b390f 100644 --- a/services/aams/test/unittest/accessible_ability_channel_test.cpp +++ b/services/aams/test/unittest/accessible_ability_channel_test.cpp @@ -210,7 +210,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, { GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_GetWindow_001 start"; AccessibilityWindowInfo windowInfo; - EXPECT_FALSE(channel_->GetWindow(WINDOW_ID, windowInfo)); + EXPECT_EQ(channel_->GetWindow(WINDOW_ID, windowInfo), RET_ERR_NO_WINDOW_CONNECTION); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_GetWindow_001 end"; } @@ -231,7 +231,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, sptr channel = new AccessibleAbilityChannel(accountData->GetAccountId(), ability); AccessibilityWindowInfo windowInfo; - EXPECT_FALSE(channel->GetWindow(WINDOW_ID, windowInfo)); + EXPECT_EQ(channel->GetWindow(WINDOW_ID, windowInfo), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_GetWindow_002 end"; } @@ -259,7 +259,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, EXPECT_TRUE(accountData->GetAccessibleAbilityConnection(ability)); AccessibilityWindowInfo windowInfo; - EXPECT_FALSE(channel->GetWindow(WINDOW_ID, windowInfo)); + EXPECT_EQ(channel->GetWindow(WINDOW_ID, windowInfo), RET_ERR_NO_CAPABILITY); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_GetWindow_003 end"; } @@ -273,7 +273,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, { GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_GetWindows_001 start"; std::vector windows; - EXPECT_TRUE(channel_->GetWindows(windows)); + EXPECT_EQ(channel_->GetWindows(windows), RET_OK); EXPECT_EQ(static_cast(windows.size()), 0); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_GetWindows_001 end"; } @@ -295,7 +295,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, sptr channel = new AccessibleAbilityChannel(accountData->GetAccountId(), abilityName); std::vector windows; - EXPECT_FALSE(channel->GetWindows(windows)); + EXPECT_EQ(channel->GetWindows(windows), RET_ERR_NO_CONNECTION); EXPECT_EQ(static_cast(windows.size()), 0); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_GetWindows_002 end"; } @@ -327,7 +327,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, EXPECT_TRUE(accountData->GetAccessibleAbilityConnection(abilityInfo->GetId())); std::vector windows; - EXPECT_FALSE(channel->GetWindows(windows)); + EXPECT_EQ(channel->GetWindows(windows), RET_ERR_NO_CAPABILITY); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_GetWindows_003 end"; } @@ -341,7 +341,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, { GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_GetWindowsByDisplayId_001 start"; std::vector windows; - EXPECT_TRUE(channel_->GetWindowsByDisplayId(DISPLAY_ID, windows)); + EXPECT_EQ(channel_->GetWindowsByDisplayId(DISPLAY_ID, windows), RET_OK); EXPECT_EQ(static_cast(windows.size()), 0); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_GetWindowsByDisplayId_001 end"; } @@ -391,7 +391,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, AccessibleAbilityChannel_Unittest_SendSimulateGesture_001, TestSize.Level1) { GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_SendSimulateGesture_001 start"; - EXPECT_FALSE(channel_->SendSimulateGesture(nullptr)); + EXPECT_EQ(channel_->SendSimulateGesture(nullptr), RET_ERR_NO_INJECTOR); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_SendSimulateGesture_001 end"; } @@ -410,7 +410,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, ASSERT_TRUE(accountData); EXPECT_FALSE(accountData->GetAccessibleAbilityConnection(abilityName)); sptr channel = new AccessibleAbilityChannel(accountData->GetAccountId(), abilityName); - EXPECT_FALSE(channel->SendSimulateGesture(nullptr)); + EXPECT_EQ(channel->SendSimulateGesture(nullptr), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_SendSimulateGesture_002 end"; } @@ -424,7 +424,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, { GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_SetTargetBundleName_001 start"; std::vector targetBundleNames; - EXPECT_TRUE(channel_->SetTargetBundleName(targetBundleNames)); + EXPECT_EQ(channel_->SetTargetBundleName(targetBundleNames), RET_OK); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_SetTargetBundleName_001 end"; } @@ -444,7 +444,7 @@ HWTEST_F(AccessibleAbilityChannelUnitTest, EXPECT_FALSE(accountData->GetAccessibleAbilityConnection(abilityName)); sptr channel = new AccessibleAbilityChannel(accountData->GetAccountId(), abilityName); std::vector targetBundleNames; - EXPECT_FALSE(channel->SetTargetBundleName(targetBundleNames)); + EXPECT_EQ(channel->SetTargetBundleName(targetBundleNames), RET_ERR_NO_CONNECTION); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_Unittest_SetTargetBundleName_002 end"; } } // namespace Accessibility diff --git a/services/aams/test/unittest/accessible_ability_manager_service_test.cpp b/services/aams/test/unittest/accessible_ability_manager_service_test.cpp index 4e36fb22d..1b21b9fcf 100644 --- a/services/aams/test/unittest/accessible_ability_manager_service_test.cpp +++ b/services/aams/test/unittest/accessible_ability_manager_service_test.cpp @@ -161,11 +161,12 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, GetAbilityList_001, TestSize.L HWTEST_F(AccessibleAbilityManagerServiceUnitTest, RegisterElementOperator_001, TestSize.Level1) { GTEST_LOG_(INFO) << "AccessibleAbilityManagerServiceUnitTest_Unittest_RegisterElementOperator_001 start"; - auto accountData = Singleton::GetInstance().GetCurrentAccountData(); + auto &aams = Singleton::GetInstance(); + auto accountData = aams.GetCurrentAccountData(); ASSERT_TRUE(accountData); auto map = accountData->GetAsacConnections(); EXPECT_EQ(int(map.size()), 0); - Singleton::GetInstance().RegisterElementOperator(0, nullptr); + EXPECT_EQ(RET_OK, aams.RegisterElementOperator(0, nullptr)); sleep(SLEEP_TIME_1); GTEST_LOG_(INFO) << "RegisterElementOperator OK"; map = accountData->GetAsacConnections(); @@ -182,9 +183,10 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, RegisterElementOperator_001, T HWTEST_F(AccessibleAbilityManagerServiceUnitTest, DeregisterElementOperator_001, TestSize.Level1) { GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_DeregisterElementOperator_001 start"; - auto accountData = Singleton::GetInstance().GetCurrentAccountData(); + auto &aams = Singleton::GetInstance(); + auto accountData = aams.GetCurrentAccountData(); ASSERT_TRUE(accountData); - Singleton::GetInstance().DeregisterElementOperator(0); + EXPECT_EQ(RET_OK, aams.DeregisterElementOperator(0)); sleep(SLEEP_TIME_1); auto map = accountData->GetAsacConnections(); EXPECT_EQ(int(map.size()), 0); @@ -528,6 +530,18 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, SetCaptionState_001, TestSize. GTEST_LOG_(INFO) << "AccessibleAbilityManagerServiceUnitTest_SetCaptionState_001 end"; } +/** + * @tc.number: AccessibleAbilityManagerServiceUnitTest_GetEnabledState_001 + * @tc.name: GetEnabledState + * @tc.desc: Test function GetEnabledState + */ +HWTEST_F(AccessibleAbilityManagerServiceUnitTest, GetEnabledState_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibleAbilityManagerServiceUnitTest_GetEnabledState_001 start"; + EXPECT_TRUE(Singleton::GetInstance().GetEnabledState()); + GTEST_LOG_(INFO) << "AccessibleAbilityManagerServiceUnitTest_GetEnabledState_001 end"; +} + /** * @tc.number: AccessibleAbilityManagerServiceUnitTest_GetTouchGuideState_001 * @tc.name: GetTouchGuideState @@ -670,7 +684,8 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, EnableAbility_001, TestSize.Le GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_EnableAbility_001 start"; std::string name = "test"; uint32_t capabilities = 1; - EXPECT_FALSE(Singleton::GetInstance().EnableAbility(name, capabilities)); + EXPECT_EQ(RET_ERR_NOT_INSTALLED, + Singleton::GetInstance().EnableAbility(name, capabilities)); GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_EnableAbility_001 end"; } @@ -683,7 +698,7 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, DisableAbility_001, TestSize.L { GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_DisableAbility_001 start"; std::string name = "test"; - EXPECT_FALSE(Singleton::GetInstance().DisableAbility(name)); + EXPECT_EQ(RET_ERR_NOT_ENABLED, Singleton::GetInstance().DisableAbility(name)); GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_DisableAbility_001 end"; } @@ -696,7 +711,8 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, GetEnabledAbilities_001, TestS { GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_GetEnabledAbilities_001 start"; std::vector enabledAbilities; - EXPECT_TRUE(Singleton::GetInstance().GetEnabledAbilities(enabledAbilities)); + EXPECT_EQ(RET_OK, + Singleton::GetInstance().GetEnabledAbilities(enabledAbilities)); GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_GetEnabledAbilities_001 end"; } @@ -721,7 +737,7 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, EnableUITestAbility_001, TestS HWTEST_F(AccessibleAbilityManagerServiceUnitTest, DisableUITestAbility_001, TestSize.Level1) { GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_DisableUITestAbility_001 start"; - EXPECT_FALSE(Singleton::GetInstance().DisableUITestAbility()); + EXPECT_EQ(RET_ERR_NO_CONNECTION, Singleton::GetInstance().DisableUITestAbility()); GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_DisableUITestAbility_001 end"; } @@ -968,7 +984,8 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, EnableAbility_002, TestSize.Le Singleton::GetInstance().SwitchedUser(-1); std::string name = "test"; uint32_t capabilities = 1; - EXPECT_FALSE(Singleton::GetInstance().EnableAbility(name, capabilities)); + EXPECT_EQ(RET_ERR_NULLPTR, + Singleton::GetInstance().EnableAbility(name, capabilities)); GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_EnableAbility_002 end"; } @@ -982,7 +999,8 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, GetEnabledAbilities_002, TestS GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_GetEnabledAbilities_002 start"; Singleton::GetInstance().SwitchedUser(-1); std::vector enabledAbilities; - EXPECT_TRUE(Singleton::GetInstance().GetEnabledAbilities(enabledAbilities)); + EXPECT_EQ(RET_ERR_NULLPTR, + Singleton::GetInstance().GetEnabledAbilities(enabledAbilities)); GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_GetEnabledAbilities_002 end"; } @@ -996,7 +1014,7 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, DisableAbility_002, TestSize.L GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_DisableAbility_002 start"; Singleton::GetInstance().SwitchedUser(-1); std::string name = "test"; - EXPECT_FALSE(Singleton::GetInstance().DisableAbility(name)); + EXPECT_EQ(RET_ERR_NULLPTR, Singleton::GetInstance().DisableAbility(name)); GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_DisableAbility_002 end"; } @@ -1023,7 +1041,7 @@ HWTEST_F(AccessibleAbilityManagerServiceUnitTest, DisableUITestAbility_002, Test { GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_DisableUITestAbility_002 start"; Singleton::GetInstance().SwitchedUser(-1); - EXPECT_FALSE(Singleton::GetInstance().DisableUITestAbility()); + EXPECT_EQ(Singleton::GetInstance().DisableUITestAbility(), RET_ERR_NULLPTR); GTEST_LOG_(INFO) << "Accessible_Ability_Manager_ServiceUnittest_DisableUITestAbility_002 end"; } diff --git a/services/test/mock/mock_accessible_ability_manager_service_stub.cpp b/services/test/mock/mock_accessible_ability_manager_service_stub.cpp index 73037bdee..cde6c6588 100644 --- a/services/test/mock/mock_accessible_ability_manager_service_stub.cpp +++ b/services/test/mock/mock_accessible_ability_manager_service_stub.cpp @@ -54,9 +54,10 @@ int MockAccessibleAbilityManagerServiceStub::OnRemoteRequest( return 0; } -void MockAccessibleAbilityManagerServiceStub::SendEvent(const AccessibilityEventInfo &uiEvent) +RetError MockAccessibleAbilityManagerServiceStub::SendEvent(const AccessibilityEventInfo &uiEvent) { (void)uiEvent; + return RET_OK; } RetError MockAccessibleAbilityManagerServiceStub::SetCaptionProperty( @@ -79,25 +80,27 @@ uint32_t MockAccessibleAbilityManagerServiceStub::RegisterStateObserver( return 0; } -bool MockAccessibleAbilityManagerServiceStub::GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, +RetError MockAccessibleAbilityManagerServiceStub::GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, std::vector &infos) { (void)abilityTypes; (void)stateType; (void)infos; - return true; + return RET_OK; } -void MockAccessibleAbilityManagerServiceStub::RegisterElementOperator( +RetError MockAccessibleAbilityManagerServiceStub::RegisterElementOperator( int32_t windowId, const sptr &operation) { (void)windowId; (void)operation; + return RET_OK; } -void MockAccessibleAbilityManagerServiceStub::DeregisterElementOperator(const int32_t windowId) +RetError MockAccessibleAbilityManagerServiceStub::DeregisterElementOperator(const int32_t windowId) { (void)windowId; + return RET_OK; } RetError MockAccessibleAbilityManagerServiceStub::GetCaptionProperty(AccessibilityConfig::CaptionProperty &caption) @@ -139,7 +142,7 @@ bool MockAccessibleAbilityManagerServiceStub::GetKeyEventObserverState() return true; } -bool MockAccessibleAbilityManagerServiceStub::EnableAbility(const std::string &name, const uint32_t capabilities) +RetError MockAccessibleAbilityManagerServiceStub::EnableAbility(const std::string &name, const uint32_t capabilities) { (void)name; (void)capabilities; @@ -148,19 +151,19 @@ bool MockAccessibleAbilityManagerServiceStub::EnableAbility(const std::string &n abilityObserver_->OnAccessibilityEnableAbilityListsChanged(); }), "NotifyEnableAbility"); } - return true; + return RET_OK; } -bool MockAccessibleAbilityManagerServiceStub::GetEnabledAbilities(std::vector &enabledAbilities) +RetError MockAccessibleAbilityManagerServiceStub::GetEnabledAbilities(std::vector &enabledAbilities) { (void)enabledAbilities; - return true; + return RET_OK; } -bool MockAccessibleAbilityManagerServiceStub::DisableAbility(const std::string &name) +RetError MockAccessibleAbilityManagerServiceStub::DisableAbility(const std::string &name) { (void)name; - return true; + return RET_OK; } int32_t MockAccessibleAbilityManagerServiceStub::GetActiveWindow() @@ -174,9 +177,9 @@ RetError MockAccessibleAbilityManagerServiceStub::EnableUITestAbility(const sptr return RET_ERR_IPC_FAILED; } -bool MockAccessibleAbilityManagerServiceStub::DisableUITestAbility() +RetError MockAccessibleAbilityManagerServiceStub::DisableUITestAbility() { - return true; + return RET_OK; } RetError MockAccessibleAbilityManagerServiceStub::SetScreenMagnificationState(const bool state) diff --git a/services/test/mock/mock_accessible_ability_manager_service_stub.h b/services/test/mock/mock_accessible_ability_manager_service_stub.h index c139a4533..f820c7c2f 100644 --- a/services/test/mock/mock_accessible_ability_manager_service_stub.h +++ b/services/test/mock/mock_accessible_ability_manager_service_stub.h @@ -34,7 +34,7 @@ public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - void SendEvent(const AccessibilityEventInfo &uiEvent) override; + RetError SendEvent(const AccessibilityEventInfo &uiEvent) override; uint32_t RegisterStateObserver(const sptr &callback) override; @@ -43,13 +43,13 @@ public: void RegisterEnableAbilityListsObserver( const sptr &observer) override; - bool GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, + RetError GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, std::vector &infos) override; - void RegisterElementOperator(const int32_t windowId, + RetError RegisterElementOperator(const int32_t windowId, const sptr &operation) override; - void DeregisterElementOperator(const int32_t windowId) override; + RetError DeregisterElementOperator(const int32_t windowId) override; RetError GetCaptionProperty(AccessibilityConfig::CaptionProperty &caption) override; RetError SetCaptionProperty(const AccessibilityConfig::CaptionProperty &caption) override; @@ -61,14 +61,14 @@ public: bool GetGestureState() override; bool GetKeyEventObserverState() override; - bool EnableAbility(const std::string &name, const uint32_t capabilities) override; - bool GetEnabledAbilities(std::vector &enabledAbilities) override; + RetError EnableAbility(const std::string &name, const uint32_t capabilities) override; + RetError GetEnabledAbilities(std::vector &enabledAbilities) override; - bool DisableAbility(const std::string &name) override; + RetError DisableAbility(const std::string &name) override; int32_t GetActiveWindow() override; RetError EnableUITestAbility(const sptr &obj) override; - bool DisableUITestAbility() override; + RetError DisableUITestAbility() override; RetError SetScreenMagnificationState(const bool state) override; RetError SetShortKeyState(const bool state) override; diff --git a/services/test/mock/multimodalinput/src/mock_input_manager.cpp b/services/test/mock/multimodalinput/src/mock_input_manager.cpp index 56d2e6883..d1d50afcd 100644 --- a/services/test/mock/multimodalinput/src/mock_input_manager.cpp +++ b/services/test/mock/multimodalinput/src/mock_input_manager.cpp @@ -15,6 +15,7 @@ #include #include "mock_input_manager.h" +#include "hilog_wrapper.h" namespace OHOS { namespace MMI { @@ -53,33 +54,39 @@ int32_t MockInputManager::GetTouchActionOfTargetIndex(int32_t index) void MockInputManager::ClearInputEventConsumer() { + HILOG_DEBUG(); mockInputEventConsumer = nullptr; } std::shared_ptr MockInputManager::GetInputEventConsumer() { + HILOG_DEBUG(); return mockInputEventConsumer; } InputManager *InputManager::instance_ = new(std::nothrow) InputManager(); InputManager *InputManager::GetInstance() { + HILOG_DEBUG(); return instance_; } void InputManager::MoveMouse(int32_t offsetX, int32_t offsetY) { + HILOG_DEBUG(); (void)offsetX; (void)offsetY; } void InputManager::SimulateInputEvent(std::shared_ptr keyEvent) { + HILOG_DEBUG(); mockKeyCode = keyEvent->GetKeyCode(); } void InputManager::SimulateInputEvent(std::shared_ptr pointerEvent) { + HILOG_DEBUG(); std::lock_guard lock(g_mtx); int32_t touchAction = pointerEvent->GetPointerAction(); mockTouchActions.push_back(touchAction); @@ -87,22 +94,27 @@ void InputManager::SimulateInputEvent(std::shared_ptr pointerEvent int32_t InputManager::AddInterceptor(std::shared_ptr interceptorId) { + HILOG_DEBUG(); mockInputEventConsumer = interceptorId; return 0; } int32_t InputManager::AddInterceptor(std::function)> interceptor) { + HILOG_DEBUG(); mockKeyEventCallback = interceptor; return 0; } std::function)> MockInputManager::GetKeyEventInterceptor() { + HILOG_DEBUG(); return mockKeyEventCallback; } void InputManager::RemoveInterceptor(int32_t interceptorId) -{} +{ + HILOG_DEBUG(); +} } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/services/test/moduletest/aamstest/aams_accessibility_keyevent_filter_test/aams_accessibility_keyevent_filter_test.cpp b/services/test/moduletest/aamstest/aams_accessibility_keyevent_filter_test/aams_accessibility_keyevent_filter_test.cpp index 4d0b9c277..56e18339f 100644 --- a/services/test/moduletest/aamstest/aams_accessibility_keyevent_filter_test/aams_accessibility_keyevent_filter_test.cpp +++ b/services/test/moduletest/aamstest/aams_accessibility_keyevent_filter_test/aams_accessibility_keyevent_filter_test.cpp @@ -79,17 +79,21 @@ public: }; void AamsKeyEventFilterTest::SetUpTestCase(void) -{} -void AamsKeyEventFilterTest::TearDownTestCase(void) -{} -void AamsKeyEventFilterTest::SetUp() { - GTEST_LOG_(INFO) << "AamsKeyEventFilterTest ModuleTest SetUp"; - Singleton::GetInstance().OnStart(); AccessibilityCommonHelper::GetInstance().WaitForServicePublish(); Singleton::GetInstance().SwitchedUser(AccessibilityHelper::accountId_); GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published"; +} + +void AamsKeyEventFilterTest::TearDownTestCase(void) +{ + Singleton::GetInstance().OnStop(); +} + +void AamsKeyEventFilterTest::SetUp() +{ + GTEST_LOG_(INFO) << "AamsKeyEventFilterTest ModuleTest SetUp"; // Add an ability connection client AccessibilityAbilityInitParams initParams; diff --git a/services/test/moduletest/aamstest/aams_accessibility_touchEvent_injector_test/aams_accessibility_touchEvent_injector_test.cpp b/services/test/moduletest/aamstest/aams_accessibility_touchEvent_injector_test/aams_accessibility_touchEvent_injector_test.cpp index f52845434..1e458cbd6 100644 --- a/services/test/moduletest/aamstest/aams_accessibility_touchEvent_injector_test/aams_accessibility_touchEvent_injector_test.cpp +++ b/services/test/moduletest/aamstest/aams_accessibility_touchEvent_injector_test/aams_accessibility_touchEvent_injector_test.cpp @@ -53,32 +53,30 @@ public: void SetUp() override; void TearDown() override; - sptr inputInterceptor_ = nullptr; sptr aacs_ = nullptr; sptr aastub_ = nullptr; - void WritefileAll(const char* fname, const char* data); void AddAccessibilityWindowConnection(); }; void AamsInjectorTest::SetUpTestCase() { GTEST_LOG_(INFO) << "AamsInjectorTest SetUpTestCase"; + Singleton::GetInstance().OnStart(); + AccessibilityCommonHelper::GetInstance().WaitForServicePublish(); + Singleton::GetInstance().SwitchedUser(AccessibilityHelper::accountId_); + GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published"; } void AamsInjectorTest::TearDownTestCase() { GTEST_LOG_(INFO) << "AamsInjectorTest TearDownTestCase"; + Singleton::GetInstance().OnStop(); } void AamsInjectorTest::SetUp() { GTEST_LOG_(INFO) << "AamsInjectorTest SetUp"; - Singleton::GetInstance().OnStart(); - AccessibilityCommonHelper::GetInstance().WaitForServicePublish(); - Singleton::GetInstance().SwitchedUser(AccessibilityHelper::accountId_); - GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published"; - // add an ability connection client AccessibilityAbilityInitParams initParams; std::shared_ptr abilityInfo = std::make_shared(initParams); @@ -108,27 +106,24 @@ void AamsInjectorTest::SetUp() void AamsInjectorTest::TearDown() { GTEST_LOG_(INFO) << "TouchEventInjectorTest TearDown"; - inputInterceptor_ = nullptr; aacs_ = nullptr; aastub_ = nullptr; Singleton::GetInstance().DeregisterElementOperator(0); - sleep(SLEEP_TIME_2); + bool ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + auto &aams = Singleton::GetInstance(); + if (aams.GetMainRunner()->GetEventQueue()->IsIdle()) { + return true; + } else { + return false; + } + }), 1); + if (!ret) { + GTEST_LOG_(INFO) << "AamsAccessibleAbilityChannelTest TearDown EventQueue is not empty"; + } MMI::MockInputManager::ClearTouchActions(); AccessibilityHelper::GetInstance().GetEventType().clear(); } -void AamsInjectorTest::WritefileAll(const char* fname, const char* data) -{ - FILE* fp; - if (!(fp = fopen(fname, "w"))) { - printf("open file %s fail \n", fname); - return; - } - - (void)fprintf(fp, "%s", data); - (void)fclose(fp); -} - void AamsInjectorTest::AddAccessibilityWindowConnection() { GTEST_LOG_(INFO) << "AamsInjectorTest AddAccessibilityWindowConnection"; @@ -151,38 +146,48 @@ HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_001, { GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_001 start"; - AccessibilityHelper::GetInstance().GetEventType() = {}; + AccessibilityHelper::GetInstance().GetEventType().clear(); MMI::MockInputManager::ClearTouchActions(); AccessibilityGesturePosition point {500.0f, 500.0f}; std::shared_ptr gesturePath = std::make_shared(); gesturePath->AddPosition(point); gesturePath->SetDurationTime(100); aacs_->SendSimulateGesture(gesturePath); - sleep(3); + bool ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (MMI::PointerEvent::POINTER_ACTION_MOVE == MMI::MockInputManager::GetTouchActionOfTargetIndex(1)) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); + EXPECT_EQ(MMI::PointerEvent::POINTER_ACTION_MOVE, MMI::MockInputManager::GetTouchActionOfTargetIndex(0)); - int32_t expectValue = MMI::PointerEvent::POINTER_ACTION_MOVE; - auto mtTouchAction = MMI::MockInputManager::GetTouchActions(); - EXPECT_EQ(mtTouchAction[0], expectValue); - EXPECT_EQ(mtTouchAction[1], expectValue); - - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[0], EventType::TYPE_TOUCH_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[1], EventType::TYPE_TOUCH_GUIDE_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[2], EventType::TYPE_TOUCH_GUIDE_END); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[3], EventType::TYPE_TOUCH_END); + ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (EventType::TYPE_TOUCH_END == AccessibilityHelper::GetInstance().GetEventTypeOfTargetIndex(3)) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); + EXPECT_EQ(EventType::TYPE_TOUCH_BEGIN, AccessibilityHelper::GetInstance().GetEventTypeOfTargetIndex(0)); + EXPECT_EQ(EventType::TYPE_TOUCH_GUIDE_BEGIN, AccessibilityHelper::GetInstance().GetEventTypeOfTargetIndex(1)); + EXPECT_EQ(EventType::TYPE_TOUCH_GUIDE_END, AccessibilityHelper::GetInstance().GetEventTypeOfTargetIndex(2)); GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_001 end"; } /** - * @tc.number: TouchEventInjector004 + * @tc.number: TouchEventInjector002 * @tc.name:TouchEventInjector * @tc.desc: Check that the injected LEFT gesture can be recognized in touchGuide. */ -HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_004, TestSize.Level1) +HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_002, TestSize.Level1) { - GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_004 start"; + GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_002 start"; - AccessibilityHelper::GetInstance().GetEventType() = {}; + AccessibilityHelper::GetInstance().GetEventType().clear(); MMI::MockInputManager::ClearTouchActions(); AccessibilityGesturePosition point1 {2500.0f, 2500.0f}; AccessibilityGesturePosition point2 {1000.0f, 2500.0f}; @@ -194,33 +199,38 @@ HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_004, gesturePath->SetDurationTime(200); aacs_->SendSimulateGesture(gesturePath); - sleep(3); + bool ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (MMI::PointerEvent::POINTER_ACTION_MOVE == MMI::MockInputManager::GetTouchActionOfTargetIndex(1)) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); + EXPECT_EQ(MMI::PointerEvent::POINTER_ACTION_MOVE, MMI::MockInputManager::GetTouchActionOfTargetIndex(0)); - int32_t expectValue = MMI::PointerEvent::POINTER_ACTION_MOVE; - auto mtTouchAction = MMI::MockInputManager::GetTouchActions(); - EXPECT_EQ(mtTouchAction[0], expectValue); - EXPECT_EQ(mtTouchAction[1], expectValue); - - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[0], EventType::TYPE_TOUCH_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[1], EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[2], EventType::TYPE_TOUCH_GUIDE_GESTURE_END); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[3], EventType::TYPE_TOUCH_END); - - EXPECT_EQ(AccessibilityHelper::GetInstance().GetGestureId(), static_cast(GestureType::GESTURE_SWIPE_LEFT)); - - GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_004 end"; + ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (static_cast(GestureType::GESTURE_SWIPE_LEFT) == + AccessibilityHelper::GetInstance().GetGestureId()) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); + GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_002 end"; } /** - * @tc.number: TouchEventInjector005 + * @tc.number: TouchEventInjector003 * @tc.name:TouchEventInjector * @tc.desc: Check that the injected RIGHT_THEN_DOWN gesture can be recognized in touchGuide. */ -HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_005, TestSize.Level1) +HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_003, TestSize.Level1) { - GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_005 start"; + GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_003 start"; - AccessibilityHelper::GetInstance().GetEventType() = {}; + AccessibilityHelper::GetInstance().GetEventType().clear(); MMI::MockInputManager::ClearTouchActions(); AccessibilityGesturePosition point1 {2500.0f, 2500.0f}; AccessibilityGesturePosition point2 {3500.0f, 2500.0f}; @@ -234,34 +244,40 @@ HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_005, gesturePath->SetDurationTime(300); aacs_->SendSimulateGesture(gesturePath); - sleep(3); - int32_t expectValue = MMI::PointerEvent::POINTER_ACTION_MOVE; - auto mtTouchAction = MMI::MockInputManager::GetTouchActions(); - EXPECT_EQ(mtTouchAction[0], expectValue); - EXPECT_EQ(mtTouchAction[1], expectValue); - EXPECT_EQ(mtTouchAction[2], expectValue); + bool ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (MMI::PointerEvent::POINTER_ACTION_MOVE == MMI::MockInputManager::GetTouchActionOfTargetIndex(2)) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); + EXPECT_EQ(MMI::PointerEvent::POINTER_ACTION_MOVE, MMI::MockInputManager::GetTouchActionOfTargetIndex(0)); + EXPECT_EQ(MMI::PointerEvent::POINTER_ACTION_MOVE, MMI::MockInputManager::GetTouchActionOfTargetIndex(1)); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[0], EventType::TYPE_TOUCH_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[1], EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[2], EventType::TYPE_TOUCH_GUIDE_GESTURE_END); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[3], EventType::TYPE_TOUCH_END); + ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (static_cast(GestureType::GESTURE_SWIPE_RIGHT_THEN_UP) == + AccessibilityHelper::GetInstance().GetGestureId()) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetGestureId(), - static_cast(GestureType::GESTURE_SWIPE_RIGHT_THEN_UP)); - - GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_005 end"; + GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_003 end"; } /** - * @tc.number: TouchEventInjector006 + * @tc.number: TouchEventInjector004 * @tc.name:TouchEventInjector * @tc.desc: Check that the injected LEFT_THEN_DOWN gesture can be recognized in touchGuide. */ -HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_006, TestSize.Level1) +HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_004, TestSize.Level1) { - GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_006 start"; + GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_004 start"; - AccessibilityHelper::GetInstance().GetEventType() = {}; + AccessibilityHelper::GetInstance().GetEventType().clear(); MMI::MockInputManager::ClearTouchActions(); AccessibilityGesturePosition point1 {2500.0f, 2500.0f}; AccessibilityGesturePosition point2 {1500.0f, 2500.0f}; @@ -275,35 +291,40 @@ HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_006, gesturePath->SetDurationTime(300); aacs_->SendSimulateGesture(gesturePath); - sleep(3); + bool ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (MMI::PointerEvent::POINTER_ACTION_MOVE == MMI::MockInputManager::GetTouchActionOfTargetIndex(2)) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); + EXPECT_EQ(MMI::PointerEvent::POINTER_ACTION_MOVE, MMI::MockInputManager::GetTouchActionOfTargetIndex(0)); + EXPECT_EQ(MMI::PointerEvent::POINTER_ACTION_MOVE, MMI::MockInputManager::GetTouchActionOfTargetIndex(1)); - int32_t expectValue = MMI::PointerEvent::POINTER_ACTION_MOVE; - auto mtTouchAction = MMI::MockInputManager::GetTouchActions(); - EXPECT_EQ(mtTouchAction[0], expectValue); - EXPECT_EQ(mtTouchAction[1], expectValue); - EXPECT_EQ(mtTouchAction[2], expectValue); + ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (static_cast(GestureType::GESTURE_SWIPE_LEFT_THEN_UP) == + AccessibilityHelper::GetInstance().GetGestureId()) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[0], EventType::TYPE_TOUCH_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[1], EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[2], EventType::TYPE_TOUCH_GUIDE_GESTURE_END); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[3], EventType::TYPE_TOUCH_END); - - EXPECT_EQ(AccessibilityHelper::GetInstance().GetGestureId(), - static_cast(GestureType::GESTURE_SWIPE_LEFT_THEN_UP)); - - GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_006 end"; + GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_004 end"; } /** - * @tc.number: TouchEventInjector007 + * @tc.number: TouchEventInjector005 * @tc.name:TouchEventInjector * @tc.desc: Check that the injected UP_THEN_LEFT gesture can be recognized in touchGuide. */ -HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_007, TestSize.Level1) +HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_005, TestSize.Level1) { - GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_007 start"; + GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_005 start"; - AccessibilityHelper::GetInstance().GetEventType() = {}; + AccessibilityHelper::GetInstance().GetEventType().clear(); MMI::MockInputManager::ClearTouchActions(); AccessibilityGesturePosition point1 {2500.0f, 2500.0f}; AccessibilityGesturePosition point2 {2500.0f, 3500.0f}; @@ -317,35 +338,40 @@ HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_007, gesturePath->SetDurationTime(300); aacs_->SendSimulateGesture(gesturePath); - sleep(3); + bool ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (MMI::PointerEvent::POINTER_ACTION_MOVE == MMI::MockInputManager::GetTouchActionOfTargetIndex(2)) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); + EXPECT_EQ(MMI::PointerEvent::POINTER_ACTION_MOVE, MMI::MockInputManager::GetTouchActionOfTargetIndex(0)); + EXPECT_EQ(MMI::PointerEvent::POINTER_ACTION_MOVE, MMI::MockInputManager::GetTouchActionOfTargetIndex(1)); - int32_t expectValue = MMI::PointerEvent::POINTER_ACTION_MOVE; - auto mtTouchAction = MMI::MockInputManager::GetTouchActions(); - EXPECT_EQ(mtTouchAction[0], expectValue); - EXPECT_EQ(mtTouchAction[1], expectValue); - EXPECT_EQ(mtTouchAction[2], expectValue); + ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (static_cast(GestureType::GESTURE_SWIPE_DOWN_THEN_LEFT) == + AccessibilityHelper::GetInstance().GetGestureId()) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[0], EventType::TYPE_TOUCH_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[1], EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[2], EventType::TYPE_TOUCH_GUIDE_GESTURE_END); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[3], EventType::TYPE_TOUCH_END); - - EXPECT_EQ(AccessibilityHelper::GetInstance().GetGestureId(), - static_cast(GestureType::GESTURE_SWIPE_DOWN_THEN_LEFT)); - - GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_007 end"; + GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_005 end"; } /** - * @tc.number: TouchEventInjector008 + * @tc.number: TouchEventInjector006 * @tc.name:TouchEventInjector * @tc.desc: Check that the injected UP_THEN_RIGHT gesture can be recognized in touchGuide. */ -HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_008, TestSize.Level1) +HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_006, TestSize.Level1) { - GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_008 start"; + GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_006 start"; - AccessibilityHelper::GetInstance().GetEventType() = {}; + AccessibilityHelper::GetInstance().GetEventType().clear(); MMI::MockInputManager::ClearTouchActions(); AccessibilityGesturePosition point1 {2500.0f, 2500.0f}; AccessibilityGesturePosition point2 {2500.0f, 3500.0f}; @@ -359,23 +385,28 @@ HWTEST_F(AamsInjectorTest, TouchEventInjector_ModuleTest_TouchEventInjector_008, gesturePath->SetDurationTime(300); aacs_->SendSimulateGesture(gesturePath); - sleep(3); + bool ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (MMI::PointerEvent::POINTER_ACTION_MOVE == MMI::MockInputManager::GetTouchActionOfTargetIndex(2)) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); + EXPECT_EQ(MMI::PointerEvent::POINTER_ACTION_MOVE, MMI::MockInputManager::GetTouchActionOfTargetIndex(0)); + EXPECT_EQ(MMI::PointerEvent::POINTER_ACTION_MOVE, MMI::MockInputManager::GetTouchActionOfTargetIndex(1)); - int32_t expectValue = MMI::PointerEvent::POINTER_ACTION_MOVE; - auto mtTouchAction = MMI::MockInputManager::GetTouchActions(); - EXPECT_EQ(mtTouchAction[0], expectValue); - EXPECT_EQ(mtTouchAction[1], expectValue); - EXPECT_EQ(mtTouchAction[2], expectValue); + ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { + if (static_cast(GestureType::GESTURE_SWIPE_DOWN_THEN_RIGHT) == + AccessibilityHelper::GetInstance().GetGestureId()) { + return true; + } else { + return false; + } + }), SLEEP_TIME_2); + EXPECT_TRUE(ret); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[0], EventType::TYPE_TOUCH_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[1], EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[2], EventType::TYPE_TOUCH_GUIDE_GESTURE_END); - EXPECT_EQ(AccessibilityHelper::GetInstance().GetEventType()[3], EventType::TYPE_TOUCH_END); - - EXPECT_EQ(AccessibilityHelper::GetInstance().GetGestureId(), - static_cast(GestureType::GESTURE_SWIPE_DOWN_THEN_RIGHT)); - - GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_008 end"; + GTEST_LOG_(INFO) << "TouchEventInjector_ModuleTest_TouchEventInjector_006 end"; } } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/services/test/moduletest/aamstest/aams_accessibility_touch_guider_test/aams_accessibility_touch_guider_test.cpp b/services/test/moduletest/aamstest/aams_accessibility_touch_guider_test/aams_accessibility_touch_guider_test.cpp index d0e4fdfec..cd7dd055f 100755 --- a/services/test/moduletest/aamstest/aams_accessibility_touch_guider_test/aams_accessibility_touch_guider_test.cpp +++ b/services/test/moduletest/aamstest/aams_accessibility_touch_guider_test/aams_accessibility_touch_guider_test.cpp @@ -79,22 +79,22 @@ void AamsTouchGuideTest::WritefileAll(const char* fname, const char* data) void AamsTouchGuideTest::SetUpTestCase() { GTEST_LOG_(INFO) << "AamsTouchGuideTest SetUpTestCase"; + Singleton::GetInstance().OnStart(); + AccessibilityCommonHelper::GetInstance().WaitForServicePublish(); + Singleton::GetInstance().SwitchedUser(AccessibilityHelper::accountId_); + GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published"; } void AamsTouchGuideTest::TearDownTestCase() { GTEST_LOG_(INFO) << "AamsTouchGuideTest TearDownTestCase"; + Singleton::GetInstance().OnStop(); } void AamsTouchGuideTest::SetUp() { GTEST_LOG_(INFO) << "AamsTouchGuideTest SetUp"; - Singleton::GetInstance().OnStart(); - AccessibilityCommonHelper::GetInstance().WaitForServicePublish(); - Singleton::GetInstance().SwitchedUser(AccessibilityHelper::accountId_); - GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published"; - interceptorId_ = std::make_shared(); MMI::InputManager::GetInstance()->AddInterceptor(interceptorId_); diff --git a/services/test/moduletest/aamstest/aams_accessible_ability_channel_test/aams_accessible_ability_channel_test.cpp b/services/test/moduletest/aamstest/aams_accessible_ability_channel_test/aams_accessible_ability_channel_test.cpp index 2346405cd..9d5d14033 100644 --- a/services/test/moduletest/aamstest/aams_accessible_ability_channel_test/aams_accessible_ability_channel_test.cpp +++ b/services/test/moduletest/aamstest/aams_accessible_ability_channel_test/aams_accessible_ability_channel_test.cpp @@ -56,17 +56,6 @@ public: void AamsAccessibleAbilityChannelTest::SetUpTestCase() { GTEST_LOG_(INFO) << "AamsAccessibleAbilityChannelTest SetUpTestCase"; -} - -void AamsAccessibleAbilityChannelTest::TearDownTestCase() -{ - GTEST_LOG_(INFO) << "AamsAccessibleAbilityChannelTest TearDownTestCase"; -} - -void AamsAccessibleAbilityChannelTest::SetUp() -{ - GTEST_LOG_(INFO) << "AamsAccessibleAbilityChannelTest SetUp"; - // Start AAMS Singleton::GetInstance().OnStart(); AccessibilityCommonHelper::GetInstance().WaitForServicePublish(); @@ -74,10 +63,23 @@ void AamsAccessibleAbilityChannelTest::SetUp() GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published"; } +void AamsAccessibleAbilityChannelTest::TearDownTestCase() +{ + GTEST_LOG_(INFO) << "AamsAccessibleAbilityChannelTest TearDownTestCase"; + // Stop AAMS + Singleton::GetInstance().OnStop(); +} + +void AamsAccessibleAbilityChannelTest::SetUp() +{ + GTEST_LOG_(INFO) << "AamsAccessibleAbilityChannelTest SetUp"; +} + void AamsAccessibleAbilityChannelTest::TearDown() { GTEST_LOG_(INFO) << "AamsAccessibleAbilityChannelTest TearDown"; + Singleton::GetInstance().GetCurrentAccountData()->OnAccountSwitched(); // Deregister ElementOperator Singleton::GetInstance().DeregisterElementOperator(0); bool ret = AccessibilityCommonHelper::GetInstance().WaitForLoop(std::bind([=]() -> bool { @@ -91,8 +93,6 @@ void AamsAccessibleAbilityChannelTest::TearDown() if (!ret) { GTEST_LOG_(INFO) << "AamsAccessibleAbilityChannelTest TearDown EventQueue is not empty"; } - // Stop AAMS - Singleton::GetInstance().OnStop(); accountData_ = nullptr; aastub_ = nullptr; elementName_ = nullptr; @@ -125,10 +125,12 @@ void AamsAccessibleAbilityChannelTest::AddAccessibleAbilityConnection(bool isNoC AccessibilityAbilityInitParams initParams; std::shared_ptr abilityInfo = std::make_shared(initParams); abilityInfo->SetAccessibilityAbilityType(AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_ALL); + uint32_t capabilities = 0; if (!isNoCapability) { - abilityInfo->SetCapabilityValues(Capability::CAPABILITY_RETRIEVE | Capability::CAPABILITY_TOUCH_GUIDE | - Capability::CAPABILITY_GESTURE | Capability::CAPABILITY_KEY_EVENT_OBSERVER); + capabilities = Capability::CAPABILITY_RETRIEVE | Capability::CAPABILITY_TOUCH_GUIDE | + Capability::CAPABILITY_GESTURE | Capability::CAPABILITY_KEY_EVENT_OBSERVER; } + abilityInfo->SetCapabilityValues(capabilities); accountData_ = Singleton::GetInstance().GetCurrentAccountData(); accountData_->Init(); AAConnection_ = new AccessibleAbilityConnection(accountData_->GetAccountId(), 0, *abilityInfo); @@ -178,16 +180,14 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_S AddAccessibilityWindowConnection(); AddAccessibleAbilityConnection(); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); - bool result = + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfoByAccessibilityId(0, 0, 0, nullptr, 0); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(0, proxy_->testChannelElementId_); EXPECT_EQ(0, proxy_->testChannelRequestId_); EXPECT_EQ(0, proxy_->testChannelMode_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_OK); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_001 end"; } @@ -206,16 +206,14 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_S AddAccessibilityWindowConnection(); AddAccessibleAbilityConnection(); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); - bool result = AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfoByAccessibilityId( + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfoByAccessibilityId( ACTIVE_WINDOW_ID, 0, 0, nullptr, 0); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(-1, proxy_->testChannelElementId_); EXPECT_EQ(-1, proxy_->testChannelRequestId_); EXPECT_EQ(-1, proxy_->testChannelMode_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_ERR_NO_WINDOW_CONNECTION); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_002 end"; } @@ -234,15 +232,14 @@ HWTEST_F( AddAccessibleAbilityConnection(); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); string text = "text"; - bool result = AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfosByText(0, 0, text, 0, nullptr); + RetError result = + AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfosByText(0, 0, text, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(0, proxy_->testChannelElementId_); EXPECT_EQ(0, proxy_->testChannelRequestId_); EXPECT_EQ(text, proxy_->testText_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_OK); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_001 end"; } @@ -261,16 +258,14 @@ HWTEST_F( AddAccessibleAbilityConnection(); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); string text = "text"; - bool result = AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfosByText( + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfosByText( ACTIVE_WINDOW_ID, 0, text, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(-1, proxy_->testChannelElementId_); EXPECT_EQ(-1, proxy_->testChannelRequestId_); EXPECT_NE(text, proxy_->testText_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_ERR_NO_WINDOW_CONNECTION); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_002 end"; } @@ -289,15 +284,14 @@ HWTEST_F( AddAccessibleAbilityConnection(); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); int32_t focusType = OHOS::Accessibility::FOCUS_TYPE_INPUT; - bool result = AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo(0, 0, focusType, 0, nullptr); + RetError result = + AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo(0, 0, focusType, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(0, proxy_->testChannelElementId_); EXPECT_EQ(0, proxy_->testChannelRequestId_); EXPECT_EQ(focusType, proxy_->testFocusType_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_OK); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_001 end"; } @@ -316,16 +310,14 @@ HWTEST_F( AddAccessibleAbilityConnection(); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); int32_t focusType = OHOS::Accessibility::FOCUS_TYPE_INPUT; - bool result = AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo( + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo( ACTIVE_WINDOW_ID, 0, focusType, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(-1, proxy_->testChannelElementId_); EXPECT_EQ(-1, proxy_->testChannelRequestId_); EXPECT_NE(focusType, proxy_->testFocusType_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_ERR_NO_WINDOW_CONNECTION); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_002 end"; } @@ -344,15 +336,14 @@ HWTEST_F( AddAccessibleAbilityConnection(); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); int32_t focusType = OHOS::Accessibility::FOCUS_TYPE_ACCESSIBILITY; - bool result = AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo(0, 0, focusType, 1, nullptr); + RetError result = + AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo(0, 0, focusType, 1, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(0, proxy_->testChannelElementId_); EXPECT_EQ(1, proxy_->testChannelRequestId_); EXPECT_EQ(focusType, proxy_->testFocusType_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_OK); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_003 end"; } @@ -370,15 +361,13 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_F AddAccessibleAbilityConnection(); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); int32_t direction = FocusMoveDirection::UP; - bool result = AccessibilityHelper::GetInstance().GetTestStub()->FocusMoveSearch(0, 0, direction, 0, nullptr); + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->FocusMoveSearch(0, 0, direction, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(0, proxy_->testChannelElementId_); EXPECT_EQ(0, proxy_->testChannelRequestId_); EXPECT_EQ(direction, proxy_->testDirection_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_OK); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_001 end"; } @@ -396,16 +385,14 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_F AddAccessibleAbilityConnection(); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); int32_t direction = FocusMoveDirection::UP; - bool result = + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->FocusMoveSearch(ACTIVE_WINDOW_ID, 0, direction, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(-1, proxy_->testChannelElementId_); EXPECT_EQ(-1, proxy_->testChannelRequestId_); EXPECT_NE(direction, proxy_->testDirection_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_ERR_NO_WINDOW_CONNECTION); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_002 end"; } @@ -425,16 +412,15 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_E actionArguments.insert(std::make_pair("invalid", "invalid")); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); - bool result = AccessibilityHelper::GetInstance().GetTestStub()->ExecuteAction(0, 4, 3, actionArguments, 0, nullptr); + RetError result = + AccessibilityHelper::GetInstance().GetTestStub()->ExecuteAction(0, 4, 3, actionArguments, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(4, proxy_->testChannelElementId_); EXPECT_EQ(0, proxy_->testChannelRequestId_); EXPECT_EQ(3, proxy_->testAction_); EXPECT_EQ(actionArguments, proxy_->testActionArguments_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_OK); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_ExecuteAction_001 end"; } @@ -454,16 +440,14 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_E actionArguments.insert(std::make_pair("invalid", "invalid")); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); - bool result = AccessibilityHelper::GetInstance().GetTestStub()->ExecuteAction( + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->ExecuteAction( ACTIVE_WINDOW_ID, 4, 3, actionArguments, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(-1, proxy_->testChannelElementId_); EXPECT_EQ(-1, proxy_->testChannelRequestId_); EXPECT_EQ(0, proxy_->testAction_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_ERR_NO_WINDOW_CONNECTION); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_ExecuteAction_002 end"; } @@ -485,8 +469,6 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_G sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(0, windows.size()); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_GetWindows_002 end"; } @@ -509,10 +491,8 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_S gesturePath->SetDurationTime(100); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); - AccessibilityHelper::GetInstance().GetTestStub()->SendSimulateGesture(gesturePath); - sleep(2); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->SendSimulateGesture(gesturePath); + EXPECT_EQ(result, RET_OK); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SendSimulateGesture_001 end"; } @@ -532,16 +512,14 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AddAccessibilityWindowConnection(); AddAccessibleAbilityConnection(true); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); - bool result = + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfoByAccessibilityId(0, 0, 0, nullptr, 0); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(-1, proxy_->testChannelElementId_); EXPECT_EQ(-1, proxy_->testChannelRequestId_); EXPECT_EQ(-1, proxy_->testChannelMode_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_ERR_NO_CAPABILITY); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfoByAccessibilityId_NoCapability_001 end"; } @@ -560,15 +538,14 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AddAccessibleAbilityConnection(true); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); string text = "text"; - bool result = AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfosByText(0, 0, text, 0, nullptr); + RetError result = + AccessibilityHelper::GetInstance().GetTestStub()->SearchElementInfosByText(0, 0, text, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(-1, proxy_->testChannelElementId_); EXPECT_EQ(-1, proxy_->testChannelRequestId_); EXPECT_NE(text, proxy_->testText_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_ERR_NO_CAPABILITY); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SearchElementInfosByText_NoCapability_001 end"; } @@ -587,15 +564,14 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_F AddAccessibleAbilityConnection(true); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); int32_t focusType = OHOS::Accessibility::FOCUS_TYPE_INPUT; - bool result = AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo(0, 0, focusType, 0, nullptr); + RetError result = + AccessibilityHelper::GetInstance().GetTestStub()->FindFocusedElementInfo(0, 0, focusType, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(-1, proxy_->testChannelElementId_); EXPECT_EQ(-1, proxy_->testChannelRequestId_); EXPECT_NE(focusType, proxy_->testFocusType_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_ERR_NO_CAPABILITY); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FindFocusedElementInfo_NoCapability_001 end"; } @@ -614,15 +590,13 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_F AddAccessibleAbilityConnection(true); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); int32_t direction = FocusMoveDirection::UP; - bool result = AccessibilityHelper::GetInstance().GetTestStub()->FocusMoveSearch(0, 0, direction, 0, nullptr); + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->FocusMoveSearch(0, 0, direction, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(-1, proxy_->testChannelElementId_); EXPECT_EQ(-1, proxy_->testChannelRequestId_); EXPECT_NE(direction, proxy_->testDirection_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_ERR_NO_CAPABILITY); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_FocusMoveSearch_NoCapability_001 end"; } @@ -643,16 +617,15 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_E actionArguments.insert(std::make_pair("invalid", "invalid")); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); - bool result = AccessibilityHelper::GetInstance().GetTestStub()->ExecuteAction(0, 4, 3, actionArguments, 0, nullptr); + RetError result = + AccessibilityHelper::GetInstance().GetTestStub()->ExecuteAction(0, 4, 3, actionArguments, 0, nullptr); sleep(2); GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(-1, proxy_->testChannelElementId_); EXPECT_EQ(-1, proxy_->testChannelRequestId_); EXPECT_EQ(0, proxy_->testAction_); EXPECT_NE(actionArguments, proxy_->testActionArguments_); - EXPECT_TRUE(result); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + EXPECT_EQ(result, RET_ERR_NO_CAPABILITY); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_ExecuteAction_NoCapability_001 end"; } @@ -676,8 +649,6 @@ HWTEST_F( GTEST_LOG_(INFO) << "Test result"; EXPECT_EQ(0, windows.size()); - - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_GetWindows_NoCapability_001 end"; } @@ -701,10 +672,8 @@ HWTEST_F(AamsAccessibleAbilityChannelTest, AccessibleAbilityChannel_ModuleTest_S gesturePath->SetDurationTime(100); ASSERT_TRUE(AccessibilityHelper::GetInstance().GetTestStub()); - AccessibilityHelper::GetInstance().GetTestStub()->SendSimulateGesture(gesturePath); - sleep(2); - GTEST_LOG_(INFO) << "clear end"; - AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); + RetError result = AccessibilityHelper::GetInstance().GetTestStub()->SendSimulateGesture(gesturePath); + EXPECT_EQ(result, RET_ERR_NO_CAPABILITY); GTEST_LOG_(INFO) << "AccessibleAbilityChannel_ModuleTest_SendSimulateGesture_NoCapability_001 end"; } } // namespace Accessibility diff --git a/services/test/moduletest/aamstest/aams_common_event_registry_test/aams_common_event_registry_test.cpp b/services/test/moduletest/aamstest/aams_common_event_registry_test/aams_common_event_registry_test.cpp index 1018badcb..da52382d9 100644 --- a/services/test/moduletest/aamstest/aams_common_event_registry_test/aams_common_event_registry_test.cpp +++ b/services/test/moduletest/aamstest/aams_common_event_registry_test/aams_common_event_registry_test.cpp @@ -50,17 +50,6 @@ public: void AccessibilityCommonEventRegistryTest::SetUpTestCase() { GTEST_LOG_(INFO) << "AccessibilityCommonEventRegistryTest SetUpTestCase"; -} - -void AccessibilityCommonEventRegistryTest::TearDownTestCase() -{ - GTEST_LOG_(INFO) << "AccessibilityCommonEventRegistryTest TearDownTestCase"; -} - -void AccessibilityCommonEventRegistryTest::SetUp() -{ - GTEST_LOG_(INFO) << "SetUp"; - // Start AAMS Singleton::GetInstance().OnStart(); AccessibilityCommonHelper::GetInstance().WaitForServicePublish(); @@ -68,10 +57,20 @@ void AccessibilityCommonEventRegistryTest::SetUp() GTEST_LOG_(INFO) << "AccessibleAbilityManagerService is published"; } +void AccessibilityCommonEventRegistryTest::TearDownTestCase() +{ + GTEST_LOG_(INFO) << "AccessibilityCommonEventRegistryTest TearDownTestCase"; + Singleton::GetInstance().OnStop(); +} + +void AccessibilityCommonEventRegistryTest::SetUp() +{ + GTEST_LOG_(INFO) << "SetUp"; +} + void AccessibilityCommonEventRegistryTest::TearDown() { GTEST_LOG_(INFO) << "TearDown"; - Singleton::GetInstance().OnStop(); accountData_ = nullptr; aastub_ = nullptr; elementName_ = nullptr; diff --git a/services/test/moduletest/aamstest/aams_server_test/aams_server_test.cpp b/services/test/moduletest/aamstest/aams_server_test/aams_server_test.cpp index 020aea6ca..d4593bfc1 100644 --- a/services/test/moduletest/aamstest/aams_server_test/aams_server_test.cpp +++ b/services/test/moduletest/aamstest/aams_server_test/aams_server_test.cpp @@ -156,7 +156,8 @@ HWTEST_F(AAMSServerTest, GetAbilityList_001, TestSize.Level1) GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_001 start"; std::vector infos; auto &aams = Singleton::GetInstance(); - aams.GetAbilityList(0, AbilityStateType::ABILITY_STATE_ENABLE, infos); + auto ret = aams.GetAbilityList(0, AbilityStateType::ABILITY_STATE_ENABLE, infos); + EXPECT_EQ(RET_OK, ret); EXPECT_EQ(infos.size(), 0); GTEST_LOG_(INFO) << "AAMSServerTest GetAbilityList_001 end"; @@ -274,16 +275,17 @@ HWTEST_F(AAMSServerTest, RegisterElementOperator_001, TestSize.Level1) { GTEST_LOG_(INFO) << "AAMSServerTest RegisterElementOperator_001 start"; AddAccessibleAbilityConnection(); - auto accountData = Singleton::GetInstance().GetCurrentAccountData(); + auto &aams = Singleton::GetInstance(); + auto accountData = aams.GetCurrentAccountData(); auto map = accountData->GetAsacConnections(); EXPECT_EQ(int(map.size()), 0); - Singleton::GetInstance().RegisterElementOperator(0, nullptr); + EXPECT_EQ(RET_OK, aams.RegisterElementOperator(0, nullptr)); sleep(1); GTEST_LOG_(INFO) << "RegisterElementOperator OK"; map = accountData->GetAsacConnections(); EXPECT_EQ(int(map.size()), 1); - Singleton::GetInstance().DeregisterElementOperator(0); + aams.DeregisterElementOperator(0); sleep(1); AAConnection_->OnAbilityDisconnectDoneSync(*elementName_); accountData_->ClearInstalledAbility(); @@ -299,25 +301,26 @@ HWTEST_F(AAMSServerTest, RegisterElementOperator_001, TestSize.Level1) HWTEST_F(AAMSServerTest, DeregisterElementOperator_001, TestSize.Level1) { GTEST_LOG_(INFO) << "AAMSServerTest DeregisterElementOperator_001 start"; - auto accountData = Singleton::GetInstance().GetCurrentAccountData(); + auto &aams = Singleton::GetInstance(); + auto accountData = aams.GetCurrentAccountData(); auto map = accountData->GetAsacConnections(); EXPECT_EQ(int(map.size()), 0); AddAccessibleAbilityConnection(); sleep(1); - Singleton::GetInstance().RegisterElementOperator(0, nullptr); + aams.RegisterElementOperator(0, nullptr); sleep(1); map = accountData->GetAsacConnections(); EXPECT_EQ(int(map.size()), 1); // wrong windowId - Singleton::GetInstance().DeregisterElementOperator(1); + aams.DeregisterElementOperator(1); sleep(1); map = accountData->GetAsacConnections(); EXPECT_EQ(int(map.size()), 1); // true windowId - Singleton::GetInstance().DeregisterElementOperator(0); + aams.DeregisterElementOperator(0); sleep(1); map = accountData->GetAsacConnections(); EXPECT_EQ(int(map.size()), 0);