diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 00000000..11f42d3f --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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("//build/ohos.gni") diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..4a459866 --- /dev/null +++ b/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/OAT.xml b/OAT.xml new file mode 100644 index 00000000..aa01ceab --- /dev/null +++ b/OAT.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 00000000..fdfc21f7 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,6 @@ +# XXX系统 + +## 简介 + + + diff --git a/accessibility.gni b/accessibility.gni new file mode 100644 index 00000000..f8b1d99d --- /dev/null +++ b/accessibility.gni @@ -0,0 +1,22 @@ +# Copyright (c) 2021 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. + +accessibility_path = "//base/accessibility" + +services_path = "${accessibility_path}/services" + +aafwk_path = "${accessibility_path}/frameworks/aafwk" +asacfwk_path = "${accessibility_path}/frameworks/asacfwk" + +kits_path = "${accessibility_path}/interfaces/kits" +innerkits_path = "${accessibility_path}/interfaces/innerkits" diff --git a/common/log/include/hilog_wrapper.h b/common/log/include/hilog_wrapper.h new file mode 100644 index 00000000..ecd5e8b8 --- /dev/null +++ b/common/log/include/hilog_wrapper.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef HILOG_WRAPPER_H +#define HILOG_WRAPPER_H + +#define CONFIG_HILOG +#ifdef CONFIG_HILOG +#include "hilog/log.h" + +#ifdef HILOG_FATAL +#undef HILOG_FATAL +#endif + +#ifdef HILOG_ERROR +#undef HILOG_ERROR +#endif + +#ifdef HILOG_WARN +#undef HILOG_WARN +#endif + +#ifdef HILOG_INFO +#undef HILOG_INFO +#endif + +#ifdef HILOG_DEBUG +#undef HILOG_DEBUG +#endif + +#ifndef AAMS_LOG_DOMAIN +#define AAMS_LOG_DOMAIN 0xD005000 +#endif + +#ifndef AAMS_LOG_TAG +#define AAMS_LOG_TAG "AccessibleAbilityManagerService" +#endif + +#ifdef LOG_LABEL +#undef LOG_LABEL +#endif + +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, AAMS_LOG_DOMAIN, AAMS_LOG_TAG}; + +#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) + +#define HILOG_FATAL(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Fatal( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_ERROR(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Error( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_WARN(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Warn( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_INFO(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Info( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_DEBUG(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Debug( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#else + +#define HILOG_FATAL(...) +#define HILOG_ERROR(...) +#define HILOG_WARN(...) +#define HILOG_INFO(...) +#define HILOG_DEBUG(...) +#endif // CONFIG_HILOG + +#endif // HILOG_WRAPPER_H diff --git a/dummyData/dummy.h b/dummyData/dummy.h new file mode 100644 index 00000000..b96bcdc0 --- /dev/null +++ b/dummyData/dummy.h @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef DUMMY_H +#define DUMMY_H + +#include +#include +#include +#include "refbase.h" + +#define ACCESSIBLE_ABILITY_MANAGER_SERVICE_ID 4702 // to be deleted + +namespace OHOS { +namespace Accessibility { + +class IASACStub {}; +class IClient {}; +// class TouchEventInjector:public OHOS::RefBase{}; + /*class AccessibilityInputFilter:public OHOS::RefBase{}; + class KeyEventFilter:public OHOS::RefBase{}; + +class AccessibilityZoomProxy:public OHOS::RefBase{};*/ + +struct AccessibilityAbilityInfoDummy +{ + uint32_t accessibilityEventTypes = 0xFFFFFFFF; // TYPES_ALL_MASK + + // ACCESSIBILITY_ABILITY_TYPE_SPOKEN | ACCESSIBILITY_ABILITY_TYPE_HAPTIC | ACCESSIBILITY_ABILITY_TYPE_AUDIBLE + uint32_t accessibilityAbilityTypes = 0x00000001 | 0x00000002 | 0x00000004; + + // CAPABILITY_KEY_EVENT_OBSERVER | CAPABILITY_TOUCH_GUIDE | CAPABILITY_ZOOM | CAPABILITY_RETRIEVE + uint32_t capabilities = 0x0008 | 0x0002 | 0x0010 | 0x0001; + + std::string description = + "When TalkBack is on, it provides spoken feedback so that you can use your device without looking at the screen."; + + uint32_t uiInteractiveTime = 10000; + + uint32_t notificationTimeout = 0; + + std::string settingsAbility = "com.ohos.talkback.TalkBackPreferencesActivity"; + + // The following two properties talkback is not configured. + uint32_t uiNoninteractiveTime = 0; + std::vector filterBundleNames{}; +}; + +// WMS dummy start +enum WMError { + WM_OK = 0, + WM_NG +}; + +struct WMDisplayInfo:public OHOS::RefBase { + int32_t id; + uint32_t width; + uint32_t height; + uint32_t phyWidth; + uint32_t phyHeight; + uint32_t vsync; + uint32_t dpi; // 额外的像素密度,比如hi3516的mipi屏是 60mmx120mm, 480x960, dpi=203 +}; + +struct GetFocusWindowResult:public OHOS::RefBase { + WMError wret; // 返回结果 + int32_t wid; // 窗口id +}; + +class IWindowManagerDisplayListenerClazz { +public: + IWindowManagerDisplayListenerClazz() = default; + virtual ~IWindowManagerDisplayListenerClazz() {}; + virtual void OnScreenPlugin(int32_t did) = 0; + virtual void OnScreenPlugout(int32_t did) = 0; +}; + +enum WindowMode { + WINDOW_MODE_UNSET = 0, + WINDOW_MODE_FREE = 1, + WINDOW_MODE_TOP = 2, + WINDOW_MODE_MAX, +}; + +enum WMWindowType { + WINDOW_TYPE_NORMAL = 0, + WINDOW_TYPE_STATUS_BAR = 1, + WINDOW_TYPE_NAVI_BAR = 2, + WINDOW_TYPE_ALARM_SCREEN = 3, + WINDOW_TYPE_SYSTEM_UI = 4, + WINDOW_TYPE_LAUNCHER = 5, + WINDOW_TYPE_VIDEO = 6, + WINDOW_TYPE_MAX, +}; + +struct GetWindowInfoResult:public OHOS::RefBase { + WMError wret; // 调用返回值 + int32_t wid; // 窗口ID + int32_t zorder; // 层级 + int32_t width; // 窗口边界 + int32_t height; // 窗口边界 + int32_t positionX; // 窗口边界 + int32_t positionY; // 窗口边界 + int32_t anchorX; // 锚点 + int32_t anchorY; // 锚点 + bool isFocused; // 是否有焦点 + WindowMode mode; // 窗口模式(画中画) + WMWindowType type; // 窗口类型 +}; + +class IWindowChangeListenerClazz { +public: + IWindowChangeListenerClazz() = default; + virtual ~IWindowChangeListenerClazz() {}; + virtual void OnWindowCreate(int32_t wid) = 0; + virtual void OnWindowDestroy(int32_t wid) = 0; +}; + +class IWindowManagerService : public RefBase { +public: + WMError GetDisplays(std::vector &displays) + { + WMDisplayInfo display; + display.dpi = 1; + display.width = 1000; + display.height = 1000; + + displays.push_back(display); + return WM_OK; + } + WMError AddDisplayChangeListener(IWindowManagerDisplayListenerClazz *listener) {return WM_OK;} + sptr GetFocusWindowID() {return nullptr;} + + sptr GetWindowInfo(int32_t wid) { + + window = new GetWindowInfoResult(); + + window->wid = wid; + window->type = WINDOW_TYPE_NORMAL; + return window; + } + + sptr window; + void OnWindowListChange(IWindowChangeListenerClazz *listener) {} +}; +// WMS dummy end + +} // namespace Accessibility +} // namespace OHOS +#endif // DUMMY_H \ No newline at end of file diff --git a/dummyData/dummy_accessibility_ability_config.json b/dummyData/dummy_accessibility_ability_config.json new file mode 100644 index 00000000..9e2fd9bd --- /dev/null +++ b/dummyData/dummy_accessibility_ability_config.json @@ -0,0 +1,11 @@ +{ + "accessibilityEventTypes": ["all"], + "targetBundleNames": ["com.example.ohos.api1", "com.example.ohos.api2"], + "accessibilityAbilityTypes":["spoken", "haptic", "audible"], + "notificationTimeout": 0, + "uiNoninteractiveTimeout": 0, + "uiInteractiveTimeout": 10000, + "accessibilityCapabilities":["keyEventObserver", "touchGuide", "zoom", "retrieve"], + "description": "$string:accessibility_service_description", + "settingsAbility": "com.example.android.accessibility.ServiceSettingsAbility" +} diff --git a/dummyData/multimoduleDummy.cpp b/dummyData/multimoduleDummy.cpp new file mode 100644 index 00000000..16d45b8e --- /dev/null +++ b/dummyData/multimoduleDummy.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2021 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. + */ + + +#include "multimoduleDummy.h" + +namespace OHOS { +namespace Accessibility { +void MultimodalInputFilter::InjectEventToMultimodal(MultimodalEvent &event) { +} + +void MultimodalInputManager::RegisterMultimodalInputFilter(MultimodalInputFilter &inputFilter) { +} + +void MultimodalInputManager::DeregisterMultimodalInputFilter() { +} +} +} \ No newline at end of file diff --git a/dummyData/multimoduleDummy.h b/dummyData/multimoduleDummy.h new file mode 100644 index 00000000..91190789 --- /dev/null +++ b/dummyData/multimoduleDummy.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef MULTIMODULE_DUMMY_H +#define MULTIMODULE_DUMMY_H + +#include +#include "multimodal_event.h" + +namespace OHOS { +namespace Accessibility { +class MultimodalInputFilter { +public: + MultimodalInputFilter() {}; + virtual ~MultimodalInputFilter() = default; + virtual void OnInputEvent(MultimodalEvent &event) {}; + void InjectEventToMultimodal(MultimodalEvent &event); +}; + +class MultimodalInputManager { +public: + // 无障碍子系统将InputFilter对象注册给多模子系统。 + void RegisterMultimodalInputFilter(MultimodalInputFilter &inputFilter); + // 无障碍子系统将InputFilter对象反注册给多模子系统。 + void DeregisterMultimodalInputFilter(); +}; +} +} + +#endif // MULTIMODULE_DUMMY_H \ No newline at end of file diff --git a/dummyData/ttsDummy.cpp b/dummyData/ttsDummy.cpp new file mode 100644 index 00000000..cd44c8f1 --- /dev/null +++ b/dummyData/ttsDummy.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 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. + */ + + +#include "ttsDummy.h" + +namespace OHOS { +namespace TtsFwk { +TtsEngine& TtsEngine::GetInstance() { + static TtsEngine tts; + return tts; +} + +void TtsEngine::Create(sptr &ttsListener) { + +} + +void TtsEngine::Destroy() { + +} + +void TtsEngine::SpeakText(const char *text, int length, int utteranceId) { + +} + +void TtsEngine::StopSpeak() { + +} +} +} \ No newline at end of file diff --git a/dummyData/ttsDummy.h b/dummyData/ttsDummy.h new file mode 100644 index 00000000..0d47ceb1 --- /dev/null +++ b/dummyData/ttsDummy.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef OHOS_FWK_TTS_ENGINE_H +#define OHOS_FWK_TTS_ENGINE_H + +#include "refbase.h" + +namespace OHOS { +namespace TtsFwk { +class TtsListener : public virtual RefBase { +public: + enum TtsEvent { + TTS_EVENT_CREATE_SUCCESS = 0, + TTS_EVENT_CREATE_FAILED, + TTS_EVENT_DESTROY_SUCCESS, + TTS_EVENT_DESTROY_FAILED, + }; + + virtual ~TtsListener() = default; + virtual void OnEvent(int eventType) {} + virtual void OnSpeechStart(int utteranceId) {} + virtual void OnSpeechProgress(int utteranceId, int progress) {} + virtual void OnSpeechFinish(int utteranceId) {} +}; + +class TtsEngine { +public: + TtsEngine() = default; + ~TtsEngine() = default; + + static TtsEngine &GetInstance(); + virtual void Create(sptr &ttsListener); + virtual void Destroy(); + virtual void SpeakText(const char *text, int length, int utteranceId); + virtual void StopSpeak(); +}; +} // TtsFwk +} // OHOS +#endif // OHOS_FWK_TTS_ENGINE_H \ No newline at end of file diff --git a/frameworks/aafwk/BUILD.gn b/frameworks/aafwk/BUILD.gn new file mode 100644 index 00000000..2a4286e5 --- /dev/null +++ b/frameworks/aafwk/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (C) 2021 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("//build/ohos.gni") +import("//base/accessibility/frameworks/aafwk/aafwk.gni") + +config("accessibleability_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//base/accessibility/frameworks/aafwk/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//utils/native/base/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//base/accessibility/interfaces/innerkits/asacfwk/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//base/accessibility/frameworks/asacfwk/include", + "//foundation/appexecfwk/appexecfwk_lite/utils/bundle_lite", + "//base/accessibility/util/include", + "//base/accessibility/common/log/include", + "//base/accessibility/dummyData", + ] + + defines = [ + "AAMS_LOG_TAG = \"accessibility_aakit\"", + "AAMS_LOG_DOMAIN = 0xD005201", + ] + + if (target_cpu == "arm") { + cflags = [ "-DBINDER_IPC_32BIT" ] + } +} + +ohos_shared_library("accessibleability") { + install_enable = true + + sources = aafwk_files + + configs = [ + ":accessibleability_config", + ] + + deps = [ + "//utils/native/base:utils", + "//base/accessibility/interfaces/innerkits/asacfwk:accessibilityclient", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", + ] + + external_deps = [ + "ipc:ipc_core", + "hiviewdfx_hilog_native:libhilog", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "aafwk_standard:want", + "aafwk_standard:ability_manager", + "samgr_standard:samgr_proxy", + "multimodalinput_base:libmmi-client", + ] + + subsystem_name = "accessibility" + part_name = "accessibility_standard" +} diff --git a/frameworks/aafwk/aafwk.gni b/frameworks/aafwk/aafwk.gni new file mode 100644 index 00000000..dfa79990 --- /dev/null +++ b/frameworks/aafwk/aafwk.gni @@ -0,0 +1,24 @@ +# Copyright (c) 2021 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("//base/accessibility/accessibility.gni") + +aafwk_files = [ + "${aafwk_path}/src/accessible_ability_client_stub.cpp", + "${aafwk_path}/src/accessible_ability_client_proxy.cpp", + "${aafwk_path}/src/accessible_ability_client_stub_impl.cpp", + "${aafwk_path}/src/accessible_ability_event_handler.cpp", + "${aafwk_path}/src/accessible_ability.cpp", + "${aafwk_path}/src/display_resize_controller.cpp", + "${aafwk_path}/src/fingerprint_controller.cpp", +] diff --git a/frameworks/aafwk/include/accessible_ability.h b/frameworks/aafwk/include/accessible_ability.h new file mode 100644 index 00000000..3398dd5d --- /dev/null +++ b/frameworks/aafwk/include/accessible_ability.h @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILITY_H +#define ACCESSIBLE_ABILITY_H + +#include +#include +#include +#include +#include + +#include "key_event.h" +#include "accessible_ability_listener.h" +#include "accessibility_element_info.h" +#include "accessibility_window_info.h" +#include "accessibility_event_info.h" +#include "iremote_object.h" +#include "accessible_ability_manager_service_interface.h" +#include "display_resize_controller.h" +#include "fingerprint_controller.h" +#include "gesture_simulation.h" +#include "accessible_ability_client_stub_impl.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace Accessibility { + + // The types of swipe gestures which are performed on the touch screen. + enum GestureTypes : uint32_t { + GESTURE_SWIPE_UP = 0x0001, + GESTURE_SWIPE_DOWN = 0x0002, + GESTURE_SWIPE_LEFT = 0x0003, + GESTURE_SWIPE_RIGHT = 0x0004, + GESTURE_SWIPE_LEFT_THEN_RIGHT = 0x0005, + GESTURE_SWIPE_RIGHT_THEN_LEFT = 0x0006, + GESTURE_SWIPE_UP_THEN_DOWN = 0x0007, + GESTURE_SWIPE_DOWN_THEN_UP = 0x0008, + GESTURE_SWIPE_LEFT_THEN_UP = 0x0009, + GESTURE_SWIPE_LEFT_THEN_DOWN = 0x000A, + GESTURE_SWIPE_RIGHT_THEN_UP = 0x000B, + GESTURE_SWIPE_RIGHT_THEN_DOWN = 0x000C, + GESTURE_SWIPE_UP_THEN_LEFT = 0x000D, + GESTURE_SWIPE_UP_THEN_RIGHT = 0x000E, + GESTURE_SWIPE_DOWN_THEN_LEFT = 0x000F, + GESTURE_SWIPE_DOWN_THEN_RIGHT = 0x0010, + + GESTURE_TAP = 0x0011, + GESTURE_DOUBLETAP = 0x0012, + GESTURE_DOUBLETAP_HOLD = 0x0013, + GESTURE_DRAG = 0x0014, + GESTURE_SWIPE_SLOWLY = 0x0015, + GESTURE_TRIPLETAP = 0x0016, + GESTURE_SCALE = 0x0017, + GESTURE_SCROLL = 0x0018, + GESTURE_GESTURE_ALL = 0xFFFFFFFF + }; + + // The global action types + enum GlobalAction : uint32_t { + GLOBAL_ACTION_INVALID = 0x0000, + GLOBAL_ACTION_BACK = 0x0001, + GLOBAL_ACTION_HOME = 0x0002, + GLOBAL_ACTION_RECENT = 0x0003, + GLOBAL_ACTION_NOTIFICATION = 0x0004, + GLOBAL_ACTION_POP_UP_POWER_DIALOG = 0x0006, + GLOBAL_ACTION_DIVIDE_SCREEN = 0x0007, + GLOBAL_ACTION_LOCK_SCREEN = 0x0008, + GLOBAL_ACTION_CAPTURE_SCREEN = 0x0009 + }; + +class AccessibleAbility { +public: + + /** + * @brief Gets an instance of AccessibleAbility. + * @param + * @return Return an instance of AccessibleAbility. + */ + static AccessibleAbility& GetInstance(); + + /** + * @brief Register listener if you want to receive notification. + * @param listener The listener used to receive notification. + * @return + */ + void RegisterListener(const std::shared_ptr &listener); + + /** + * @brief Connect to AAMS. + * @param + * @return + */ + void ConnectToAAMS(); + + /** + * @brief Disable the accessible ability. + * @param + * @return + */ + void DisableAbility(); + + /** + * @brief Obtains elementInfo of focus. + * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. + * @param elementInfo The elementInfo of focus. + * @return Return true if obtains elementInfo successfully, else return false. + */ + bool GetFocusElementInfo(uint32_t focusType, std::optional& elementInfo); + + /** + * @brief Sends simulate gestures to the screen. + * @param gesturePathDefineList The gesture which need to send. + * @param listener The listener of the gesture. + * @return Return true if the gesture sends successfully, else return false. + */ + bool GestureSimulate(std::vector& gesturePathDefineList, + std::shared_ptr& listener); + + /** + * @brief Obtains the default displayResize controller. + * @param + * @return Return the default displayResize controller. + */ + std::shared_ptr& GetDisplayResizeController(); + + /** + * @brief Obtains the specified displayResize controller by displayId. + * @param displayId The id of display. + * @return Return the specified displayResize controller. + */ + std::shared_ptr& GetDisplayResizeController(uint32_t displayId); + + /** + * @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. + */ + bool GetRootElementInfo(std::optional& elementInfo); + + /** + * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. + * @param + * @return The infomation of windows. + */ + std::vector& GetWindows(); + + /** + * @brief Executes a specified action. + * @param action The action of OHOS::Accessibility::GlobalAction. + * @return Return true if performs action successfully, else return false. + */ + bool PerformCommonAction(uint32_t action); + + /** + * @brief Obtains the controller for fingerprint operations. + * @param + * @return Return the fingerprint controller. + */ + std::shared_ptr& GetFingerprintController(); + + /** + * @brief Dispatch the result of simulation gesture. + * @param sequence The sequence of gesture. + * @param result The result of gesture completion. + * @return + */ + void DispatchOnSimulationGestureResult(uint32_t sequence, bool result); + + /** + * @brief Set channelId. + * @param channelId The id of channel. + * @return + */ + void SetChannelId(uint32_t channelId); + +private: + AccessibleAbility(); + ~AccessibleAbility() = default; + + /** + * @brief Init AccessibleAbility. + * @param + * @return Return true if init successfully, else return false. + */ + bool Init(); + + /** + * @brief Check the type of common action. + * @param action The type of common action. + * @return Return true if the type of common action is right, else return false. + */ + bool CheckCommonAction(uint32_t action); + + std::vector accessibilityWindow_ {}; + std::map> gestureResultListenerInfos_{}; + std::map> displayResizeControllers_{}; + std::shared_ptr fingerprintController_ = nullptr; + std::shared_ptr accessibleAbilityEventHandler_ = nullptr; + std::shared_ptr runner_ = nullptr; + + sptr proxy_ = nullptr; + sptr stub_ = nullptr; + + uint32_t channelId_ = AccessibleAbilityClientStubImpl::INVALID_CHANNEL_ID; + uint32_t gestureStatusListenerSequence_ = 0; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBLE_ABILILTY_H \ No newline at end of file diff --git a/frameworks/aafwk/include/accessible_ability_client_interface.h b/frameworks/aafwk/include/accessible_ability_client_interface.h new file mode 100644 index 00000000..229c4689 --- /dev/null +++ b/frameworks/aafwk/include/accessible_ability_client_interface.h @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILITY_CLIENT_INTERFACE_H +#define ACCESSIBLE_ABILITY_CLIENT_INTERFACE_H + +#include "iremote_broker.h" +#include "refbase.h" +#include "key_event.h" +#include "accessibility_element_info.h" +#include "accessible_ability_channel_interface.h" +#include "accessibility_event_info.h" + +namespace OHOS { +namespace Accessibility { + +class IAccessibleAbilityClient : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.accessibility.IAccessibleAbilityClient"); + + /** + * @brief Init accessible ability. + * @param channel The object of IAccessibleAbilityChannel. + * @param channelId The id of channel. + * @return + */ + virtual void Init(const sptr &channel, const int channelId) = 0; + + /** + * @brief Disconnect accessible ability. + * @param channelId The id of channel. + * @return + */ + virtual void Disconnect(const int channelId) = 0; + + /** + * @brief Called when an accessibility event occurs. + * @param eventInfo The infomation of accessible event. + * @return + */ + virtual void OnAccessibilityEvent(const AccessibilityEventInfo &eventInfo) = 0; + + /** + * @brief Called when the accessibility service is interrupted. + * @param + * @return + */ + virtual void OnInterrupt() = 0; + + /** + * @brief Called when a user performs a specified gesture on the device that + * your accessibility application has requested to be in touch exploration mode. + * @param gestureId The id of gesture. + * @return + */ + virtual void OnGesture(const int gestureId) = 0; + + /** + * @brief Called when a key event occurs. + * @param keyEvent Indicates the key event to send. + * @param sequence The sequence of the key event. + * @return + */ + virtual void OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int sequence) = 0; + + /** + * @brief Called when the rectangle, scale, or center coordinate for performing the resizing operations is changed. + * @param displayId The id of display. + * @param rect Indicates the rectangle for resizing the display. + * @param scale Indicates the scale for resizing the display. + * @param centerX Indicates the X coordinate of the center for resizing the display. + * @param centerY Indicates the Y coordinate of the center for resizing the display. + * @return + */ + virtual void OnDisplayResizeChanged(const int displayId, const Rect &rect, const float scale, const float centerX, + const float centerY) = 0; + + /** + * @brief Called when need to notify the result of simulation gesture. + * @param sequence The sequence of gesture. + * @param completedSuccessfully The result of gesture completion. + * @return + */ + virtual void OnGestureSimulateResult(const int sequence, const bool completedSuccessfully) = 0; + + /** + * @brief Called when the validity status of the fingerprint sensor's gesture detection changes. + * @param validity The validity status of the fingerprint sensor's gesture detection. + * @return + */ + virtual void OnFingerprintGestureValidityChanged(const bool validity) = 0; + + /** + * @brief Called when the fingerprint sensor detects a gesture. + * @param gesture The gesture which is detected by fingerprint sensor. + * @return + */ + virtual void OnFingerprintGesture(const int gesture) = 0; + + enum class Message { + INIT = 0, + DISCONNECT, + ON_ACCESSIBILITY_EVENT, + ON_INTERRUPT, + ON_GESTURE, + ON_KEY_PRESS_EVENT, + ON_DISPALYRESIZE_CHANGED, + ON_GESTURE_SIMULATE_RESULT, + ON_FINGERPRINT_GESTURE_VALIDITY_CHANGED, + ON_FINGERPRINT_GESTURE, + }; +}; + +} // namespace Accessibility +} // namespace OHOS +#endif // ACCESSIBLE_ABILITY_CLIENT_INTERFACE_H \ No newline at end of file diff --git a/frameworks/aafwk/include/accessible_ability_client_proxy.h b/frameworks/aafwk/include/accessible_ability_client_proxy.h new file mode 100644 index 00000000..673d06ad --- /dev/null +++ b/frameworks/aafwk/include/accessible_ability_client_proxy.h @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILITY_CLIENT_PROXY_H +#define ACCESSIBLE_ABILITY_CLIENT_PROXY_H + +#include +#include "accessible_ability_client_interface.h" +#include "iremote_proxy.h" +#include "message_parcel.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace Accessibility { + +class AccessibleAbilityClientProxy : public IRemoteProxy +{ +public: + explicit AccessibleAbilityClientProxy(const sptr &object); + virtual ~AccessibleAbilityClientProxy() = default; + + /** + * @brief Init accessible ability through the proxy object. + * @param channel The object of IAccessibleAbilityChannel. + * @param channelId The id of channel. + * @return + */ + virtual void Init(const sptr &channel, const int channelId) override; + + /** + * @brief Disconnect accessible ability through the proxy object. + * @param channelId The id of channel. + * @return + */ + virtual void Disconnect(const int channelId) override; + + /** + * @brief Called when an accessibility event occurs through the proxy object. + * @param eventInfo The infomation of accessible event. + * @return + */ + virtual void OnAccessibilityEvent(const AccessibilityEventInfo &eventInfo) override; + + /** + * @brief Called when the accessibility service is interrupted through the proxy object. + * @param + * @return + */ + virtual void OnInterrupt() override; + + /** + * @brief Called when a user performs a specified gesture on the device that + * your accessibility application has requested to be in touch exploration mode through the proxy object. + * @param gestureId The id of gesture. + * @return + */ + virtual void OnGesture(const int gestureId) override; + + /** + * @brief Called when a key event occurs through the proxy object. + * @param keyEvent Indicates the key event to send. + * @param sequence The sequence of the key event. + * @return + */ + virtual void OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int sequence) override; + + /** + * @brief Called when the rectangle, scale, or center coordinate for performing the resizing operations is changed + * through the proxy object. + * @param displayId The id of display. + * @param rect Indicates the rectangle for resizing the display. + * @param scale Indicates the scale for resizing the display. + * @param centerX Indicates the X coordinate of the center for resizing the display. + * @param centerY Indicates the Y coordinate of the center for resizing the display. + * @return + */ + virtual void OnDisplayResizeChanged(const int displayId, const Rect &rect, const float scale, const float centerX, + const float centerY) override; + + /** + * @brief Called when need to notify the result of simulation gesture through the proxy object. + * @param sequence The sequence of gesture. + * @param completedSuccessfully The result of gesture completion. + * @return + */ + virtual void OnGestureSimulateResult(const int sequence, const bool completedSuccessfully) override; + + /** + * @brief Called when the validity status of the fingerprint sensor's gesture detection changes + * through the proxy object. + * @param validity The validity status of the fingerprint sensor's gesture detection. + * @return + */ + virtual void OnFingerprintGestureValidityChanged(const bool validity) override; + + /** + * @brief Called when the fingerprint sensor detects a gesture through the proxy object. + * @param gesture The gesture which is detected by fingerprint sensor. + * @return + */ + virtual void OnFingerprintGesture(const int gesture) override; + +private: + bool WriteInterfaceToken(MessageParcel &data); + + static inline BrokerDelegator delegator; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBLE_ABILITY_CLIENT_PROXY_H \ No newline at end of file diff --git a/frameworks/aafwk/include/accessible_ability_client_stub.h b/frameworks/aafwk/include/accessible_ability_client_stub.h new file mode 100644 index 00000000..baf56ba5 --- /dev/null +++ b/frameworks/aafwk/include/accessible_ability_client_stub.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILITY_CLIENT_STUB_H +#define ACCESSIBLE_ABILITY_CLIENT_STUB_H + +#include +#include +#include "accessible_ability_client_interface.h" +#include "accessibility_errorcode.h" +#include "iremote_stub.h" +#include "message_parcel.h" +#include "message_option.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace Accessibility { + +class AccessibleAbilityClientStub : public IRemoteStub { +public: + AccessibleAbilityClientStub(); + virtual ~AccessibleAbilityClientStub(); + + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; + +private: + ErrCode HandleInit(MessageParcel &data, MessageParcel &reply); + ErrCode HandleDisconnect(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnAccessibilityEvent(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnInterrupt(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnGesture(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnKeyPressEvent(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnDisplayResizeChanged(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnGestureSimulateResult(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnFingerprintGestureValidityChanged(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnFingerprintGesture(MessageParcel &data, MessageParcel &reply); + + using AccessibleAbilityClientFunc = + ErrCode (AccessibleAbilityClientStub::*)(MessageParcel &data, MessageParcel &reply); + std::map memberFuncMap_; + + DISALLOW_COPY_AND_MOVE(AccessibleAbilityClientStub); +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBLE_ABILITY_CLIENT_STUB_H \ No newline at end of file diff --git a/frameworks/aafwk/include/accessible_ability_client_stub_impl.h b/frameworks/aafwk/include/accessible_ability_client_stub_impl.h new file mode 100644 index 00000000..8bd845c9 --- /dev/null +++ b/frameworks/aafwk/include/accessible_ability_client_stub_impl.h @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILITY_CLIENT_STUB_IMPL_H +#define ACCESSIBLE_ABILITY_CLIENT_STUB_IMPL_H + +#include +#include "refbase.h" +#include "accessible_ability_client_stub.h" +#include "accessible_ability_event_handler.h" +#include "hilog_wrapper.h" +#include "accessibility_operator.h" +#include "accessible_ability_listener.h" + +namespace OHOS { +namespace Accessibility { + +class AccessibleAbilityClientStubImpl : public AccessibleAbilityClientStub +{ +public: + AccessibleAbilityClientStubImpl( + const std::shared_ptr &accessibleAbilityEventHandler); + ~AccessibleAbilityClientStubImpl() = default; + + static const uint32_t INVALID_CHANNEL_ID = 0xFFFFFFFF; + + /** + * @brief Register listener if you want to receive notification. + * @param listener The listener used to receive notification. + * @return + */ + void RegisterListenerImpl(const std::shared_ptr &listener); + + /** + * @brief Init accessible ability. + * @param channel The object of IAccessibleAbilityChannel. + * @param channelId The id of channel. + * @return + */ + void Init(const sptr &channel, const int channelId) override; + + /** + * @brief Disconnect accessible ability. + * @param channelId The id of channel. + * @return + */ + void Disconnect(const int channelId) override; + + /** + * @brief Called when an accessibility event occurs. + * @param eventInfo The infomation of accessible event. + * @return + */ + void OnAccessibilityEvent(const AccessibilityEventInfo &eventInfo) override; + + /** + * @brief Called when the accessibility service is interrupted. + * @param + * @return + */ + void OnInterrupt() override; + + /** + * @brief Called when a user performs a specified gesture on the device that + * your accessibility application has requested to be in touch exploration mode. + * @param gestureId The id of gesture. + * @return + */ + void OnGesture(const int gestureId) override; + + /** + * @brief Called when a key event occurs. + * @param keyEvent Indicates the key event to send. + * @param sequence The sequence of the key event. + * @return + */ + void OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int sequence) override; + + /** + * @brief Called when the rectangle, scale, or center coordinate for performing the resizing operations is changed. + * @param displayId The id of display. + * @param rect Indicates the rectangle for resizing the display. + * @param scale Indicates the scale for resizing the display. + * @param centerX Indicates the X coordinate of the center for resizing the display. + * @param centerY Indicates the Y coordinate of the center for resizing the display. + * @return + */ + void OnDisplayResizeChanged(const int displayId, const Rect &rect, const float scale, const float centerX, + const float centerY) override; + + /** + * @brief Called when need to notify the result of simulation gesture. + * @param sequence The sequence of gesture. + * @param completedSuccessfully The result of gesture completion. + * @return + */ + void OnGestureSimulateResult(const int sequence, const bool completedSuccessfully) override; + + /** + * @brief Called when the validity status of the fingerprint sensor's gesture detection changes. + * @param validity The validity status of the fingerprint sensor's gesture detection. + * @return + */ + void OnFingerprintGestureValidityChanged(const bool validity) override; + + /** + * @brief Called when the fingerprint sensor detects a gesture. + * @param gesture The gesture which is detected by fingerprint sensor. + * @return + */ + void OnFingerprintGesture(const int gesture) override; + +private: + class AccessibleAbilityDeathRecipient final : public IRemoteObject::DeathRecipient { + public: + AccessibleAbilityDeathRecipient(uint32_t& channelId, sptr& channel) + : recipientChannelId_(channelId), recipientchannel_(channel) {}; + ~AccessibleAbilityDeathRecipient() = default; + DISALLOW_COPY_AND_MOVE(AccessibleAbilityDeathRecipient); + + void OnRemoteDied(const wptr& remote); + + uint32_t& recipientChannelId_; + sptr& recipientchannel_; + }; + + void InitInner(const sptr &channel, const int channelId); + + void OnAccessibilityEventInner(const AccessibilityEventInfo &eventInfo); + + void OnInterruptInner(); + + void OnGestureInner(const int gestureId); + + void OnKeyPressEventInner(const MMI::KeyEvent &keyEvent, const int sequence); + + void OnDisplayResizeChangedInner(const int displayId, const Rect &rect, const float scale, const float centerX, + const float centerY); + + void OnGestureSimulateResultInner(const int sequence, const bool completedSuccessfully); + + void OnFingerprintGestureValidityChangedInner(const bool validity); + + void OnFingerprintGestureInner(const int gesture); + + sptr deathRecipient_{}; + sptr channel_ = nullptr; + std::shared_ptr listener_ = nullptr; + std::shared_ptr handler_ = nullptr; + uint32_t channelId_ = INVALID_CHANNEL_ID; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBLE_ABILITY_CLIENT_STUB_IMPL_H \ No newline at end of file diff --git a/frameworks/aafwk/include/accessible_ability_event_handler.h b/frameworks/aafwk/include/accessible_ability_event_handler.h new file mode 100644 index 00000000..7bdb0688 --- /dev/null +++ b/frameworks/aafwk/include/accessible_ability_event_handler.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILILTY_EVENT_HANDLER_H +#define ACCESSIBLE_ABILILTY_EVENT_HANDLER_H + +#include "event_handler.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace Accessibility { + +class AccessibleAbilityEventHandler : public AppExecFwk::EventHandler { +public: + explicit AccessibleAbilityEventHandler(const std::shared_ptr &runner); + virtual ~AccessibleAbilityEventHandler() override; + + /** + * @brief Process the event. + * @param event Indicates the event to be processed. + * @return + */ + virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; + +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBLE_ABILILTY_EVENT_HANDLER_H diff --git a/frameworks/aafwk/include/accessible_ability_listener.h b/frameworks/aafwk/include/accessible_ability_listener.h new file mode 100644 index 00000000..ab704f20 --- /dev/null +++ b/frameworks/aafwk/include/accessible_ability_listener.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILITY_LISTENER_H +#define ACCESSIBLE_ABILITY_LISTENER_H + +#include +#include "key_event.h" +#include "accessibility_event_info.h" + +namespace OHOS { +namespace Accessibility { + +class AccessibleAbilityListener { +public: + AccessibleAbilityListener() = default; + virtual ~AccessibleAbilityListener() = default; + + /** + * @brief Called when your accessibility service is successfully connected to the OS. + * @param + * @return + */ + virtual void OnAbilityConnected() {} + + /** + * @brief Called when an accessibility event occurs. + * @param eventInfo The infomation of accessible event. + * @return + */ + virtual void OnAccessibilityEvent(const AccessibilityEventInfo& eventInfo) = 0; + + /** + * @brief Called when a user performs a specified gesture on the device that + * your accessibility application has requested to be in touch exploration mode. + * @param gestureId The id of gesture. + * @return + */ + virtual void OnGesture(uint32_t gestureId) {} + + /** + * @brief Called when the accessibility service is interrupted. + * @param + * @return + */ + virtual void OnInterrupt() = 0; + + /** + * @brief Called when a key event occurs. + * @param keyEvent Indicates the key event to send. + * @return Returns true if the event has been consumed; returns false otherwise. + * The event that has been consumed will not be sent to the application. + */ + virtual bool OnKeyPressEvent(const MMI::KeyEvent& keyEvent) {return false;} +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBLE_ABILITY_LISTENER_H \ No newline at end of file diff --git a/frameworks/aafwk/include/display_resize_controller.h b/frameworks/aafwk/include/display_resize_controller.h new file mode 100644 index 00000000..8c18a3b3 --- /dev/null +++ b/frameworks/aafwk/include/display_resize_controller.h @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef DISPLAY_RESIZE_CONTROLLER_H +#define DISPLAY_RESIZE_CONTROLLER_H + +#include +#include +#include "accessible_ability_client_stub_impl.h" +#include "accessibility_element_info.h" + +namespace OHOS { +namespace Accessibility { + +class DisplayResizeListener; + +class DisplayResizeController { +public: + /** + * @brief The constructor of DisplayResizeController. + * @param channelId The id of channel. + * @param displayId The id of display. + */ + DisplayResizeController(uint32_t channelId, uint32_t displayId); + + /** + * @brief Adds a displayresize listener to observe display resizing operations. + * @param listener Indicates the listener to add. + * @return + */ + void AddListener(std::shared_ptr& listener); + + /** + * @brief Removes the specified displayresize listener. + * @param listener Indicates the listener to remove. + * @return Return true if removing listener successfully, else return false. + */ + bool DeleteListener(std::shared_ptr& listener); + + /** + * @brief Obtains the X coordinate of the center in this display resizing rectangle. + * @param + * @return Returns the X coordinate of the center. + */ + float GetCenterX(); + + /** + * @brief Obtains the Y coordinate of the center in this display resizing rectangle. + * @param + * @return Returns the Y coordinate of the center. + */ + float GetCenterY(); + + /** + * @brief Obtains the display resizing rectangle. + * @param + * @return Returns the display resizing rectangle. + */ + Rect GetDisplayResizeRect(); + + /** + * @brief Obtains the resizing scale of this display resizing rectangle. + * @param + * @return Returns the resizing scale. + */ + float GetScale(); + + /** + * @brief Resets the display to its initial size. + * @param isShouldAnimate Specifies whether animation is required. + * @return Returns true if the display is successfully reset; returns false otherwise. + */ + bool Reset(bool isShouldAnimate); + + /** + * @brief Sets the center coordinates for the display resizing rectangle. + * @param centerX Indicates the X coordinate of the center for resizing the display. + * @param centerY Indicates the Y coordinate of the center for resizing the display. + * @param isShouldAnimate Specifies whether animation is required. + * @return Returns true if the center coordinates are successfully set; returns false otherwise. + */ + bool SetCenter(float centerX, float centerY, bool isShouldAnimate); + + /** + * @brief Sets the display resizing scale. + * @param scale Indicates the scale for resizing the display + * @param isShouldAnimate Specifies whether animation is required. + * @return Returns true if the resizing scale is successfully set; returns false otherwise. + */ + bool SetScale(float scale, bool isShouldAnimate); + + /** + * @brief Dispatch displayresize changes to listeners who has been registered. + * @param rect The rectangle of displayresize which needs to dispatch. + * @param scale The scale of displayresize which needs to dispatch. + * @param centerX The centerX of displayresize which needs to dispatch. + * @param centerY The centerY of displayresize which needs to dispatch. + * @return + */ + void DispatchOnDisplayResizeChanged(const Rect& rect, const float scale, const float centerX, const float centerY); + +private: + std::vector> displayResizeListeners_ {}; + uint32_t channelId_ = AccessibleAbilityClientStubImpl::INVALID_CHANNEL_ID; + uint32_t displayId_; +}; + +class DisplayResizeListener { +public: + /** + * @brief Called when the rectangle, scale, or center coordinate for performing the resizing operations is changed. + * @param controller Indicates the controller for display resizing operations. + * @param rect Indicates the rectangle for resizing the display. + * @param scale Indicates the scale for resizing the display. + * @param centerX Indicates the X coordinate of the center for resizing the display. + * @param centerY Indicates the Y coordinate of the center for resizing the display. + * @return + */ + virtual void OnDisplayResizeChanged(const DisplayResizeController& controller, const Rect& rect, const float scale, + const float centerX, const float centerY) = 0; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // DISPLAY_RESIZE_CONTROLLER_H \ No newline at end of file diff --git a/frameworks/aafwk/include/fingerprint_controller.h b/frameworks/aafwk/include/fingerprint_controller.h new file mode 100644 index 00000000..260c7ea1 --- /dev/null +++ b/frameworks/aafwk/include/fingerprint_controller.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef FINGERPRINT_CONTROLLER_H +#define FINGERPRINT_CONTROLLER_H + +#include +#include +#include "refbase.h" +#include "accessible_ability_client_stub_impl.h" + +namespace OHOS { +namespace Accessibility { + +class FingerprintListener { +public: + + /** + * @brief Callback when the validity status of the fingerprint sensor's gesture detection changes. + * @param isActive The validity status of the fingerprint sensor's gesture detection. + * @return + */ + virtual void OnFingerprintGestureStatusChanged(bool isActive) = 0; + + /** + * @brief Callback when the fingerprint sensor detects a gesture. + * @param gesture The gesture which is detected by fingerprint sensor. + * @return + */ + virtual void OnFingerprintGesture(uint32_t gesture) = 0; +}; + +class FingerprintController { +public: + /** + * @brief The constructor of FingerprintController. + * @param channelId The id of channel. + */ + FingerprintController(uint32_t channelId); + + /** + * @brief Judge whether the gesture detection function of the fingerprint sensor is available. + * @param + * @return Return true if the fingerprint sensor is available, else return false. + */ + bool IsFingerprintGestureDetectionValid(); + + /** + * @brief Add listener of fingerprint gesture. + * @param listener The listener to add. + * @return + */ + void AddFingerprintListener(std::shared_ptr& listener); + + /** + * @brief Delete listener of fingerprint gesture. + * @param listener The listener to delete. + * @return + */ + void DeleteFingerprintListener(std::shared_ptr& listener); + + /** + * @brief Dispatch the validity status change of the fingerprint sensor's gesture detection + * to listeners who has been registered. + * @param isActive The validity status of the fingerprint sensor's gesture detection. + * @return + */ + void DispatchOnFingerprintGestureStatusChanged(bool isActive); + + /** + * @brief Dispatch the gesture which is detected by fingerprint sensor to listeners who has been registered. + * @param gesture The gesture which is detected by fingerprint sensor. + * @return + */ + void DispatchOnFingerprintGesture(uint32_t gesture); + +private: + std::shared_ptr fingerprintListener_ = nullptr; + uint32_t channelId_ = AccessibleAbilityClientStubImpl::INVALID_CHANNEL_ID; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // FINGERPRINT_CONTROLLER_H \ No newline at end of file diff --git a/frameworks/aafwk/src/accessible_ability.cpp b/frameworks/aafwk/src/accessible_ability.cpp new file mode 100644 index 00000000..c15224b7 --- /dev/null +++ b/frameworks/aafwk/src/accessible_ability.cpp @@ -0,0 +1,302 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include +#include "accessible_ability.h" +#include "accessibility_element_info.h" +#include "iservice_registry.h" +#include "if_system_ability_manager.h" +#include "accessible_ability_manager_service_proxy.h" +#include "dummy.h" + +using namespace std; + +const string AA_NAME = "AccessibleAbility"; + +namespace OHOS { +namespace Accessibility { + +AccessibleAbility& AccessibleAbility::GetInstance() +{ + HILOG_DEBUG("%{public}s start.", __func__); + static AccessibleAbility accessibleAbility; + return accessibleAbility; +} + +AccessibleAbility::AccessibleAbility() +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!Init()) { + HILOG_ERROR("%{public}s Init failed!", __func__); + } +} + +bool AccessibleAbility::Init() +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!runner_) { + runner_ = AppExecFwk::EventRunner::Create(AA_NAME); + if (!runner_) { + HILOG_ERROR("Create AA runner fail"); + return false; + } + } + HILOG_DEBUG("Get runner_ successfully"); + + if (!accessibleAbilityEventHandler_) { + accessibleAbilityEventHandler_ = std::make_shared(runner_); + if (!accessibleAbilityEventHandler_) { + HILOG_ERROR("Create AA event handler fail"); + return false; + } + } + HILOG_DEBUG("Get accessibleAbilityEventHandler_ successfully"); + + stub_ = new AccessibleAbilityClientStubImpl(accessibleAbilityEventHandler_); + if (!stub_) { + HILOG_ERROR("stub_ is nullptr."); + return false; + } + HILOG_DEBUG("Get stub_ successfully"); + + return true; +} + +void AccessibleAbility::RegisterListener(const std::shared_ptr &listener) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!listener) { + HILOG_ERROR("listener is nullptr."); + return; + } + + if (!stub_) { + HILOG_ERROR("AccessibleAbility::ConnectToAAMS fail, no stub_"); + return; + } + stub_->RegisterListenerImpl(listener); +} + +void AccessibleAbility::ConnectToAAMS() +{ + HILOG_DEBUG("%{public}s start.", __func__); + + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!samgr) { + HILOG_ERROR("AccessibleAbility::ConnectToAAMS Failed to get ISystemAbilityManager"); + return; + } + HILOG_DEBUG("AccessibleAbility::ConnectToAAMS ISystemAbilityManager obtained"); + + sptr object = samgr->GetSystemAbility(ACCESSIBLE_ABILITY_MANAGER_SERVICE_ID); + if (!object) { + HILOG_ERROR("[%s]Get IAccessibleAbilityManagerServiceClient object from samgr failed", __func__); + return; + } + + HILOG_DEBUG("Get remote object ok"); + proxy_ = iface_cast(object); + if (!proxy_) { + HILOG_ERROR("AccessibleAbility::ConnectToAAMS IAccessibleAbilityManagerServiceClient iface_cast failed"); + return; + } + + if (!stub_) { + HILOG_ERROR("AccessibleAbility::stub_ is nullptr"); + return; + } + proxy_->RegisterAbilityConnectionClientTmp(stub_); +} + +void AccessibleAbility::DisableAbility() +{ + HILOG_DEBUG("%{public}s start.", __func__); + AccessibilityOperator::GetInstance().DisableAbility(channelId_); +} + +bool AccessibleAbility::GetFocusElementInfo(uint32_t focusType, std::optional& elementInfo) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if ((focusType != FOCUS_TYPE_INPUT) && (focusType != FOCUS_TYPE_ACCESSIBILITY)) { + HILOG_DEBUG("focusType is not allowed."); + return false; + } + + AccessibilityElementInfo info {}; + bool result = AccessibilityOperator::GetInstance().FindFocusedElementInfo(channelId_, + ANY_WINDOW_ID, ROOT_NODE_ID, focusType, info); + elementInfo = info; + return result; +} + +bool AccessibleAbility::GestureSimulate(std::vector& gesturePathDefineList, + std::shared_ptr& listener) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + if (gesturePathDefineList.size() > gesturePathDefineList.front().GetMaxStrokes() || + gesturePathDefineList.size() <= 0) { + HILOG_ERROR("The number of gesturePathDefine : [%{public}d] is not allowed.", gesturePathDefineList.size()); + return false; + } + + uint32_t totalDurationTime = 0; + for (auto gesturePath : gesturePathDefineList) { + totalDurationTime += gesturePath.GetDurationTime(); + } + HILOG_DEBUG("The total duration time is %{public}d.", totalDurationTime); + + if (totalDurationTime > gesturePathDefineList.front().GetMaxStrokeDuration()) { + HILOG_ERROR("The total duration time : [%{public}d] is not allowed.", totalDurationTime); + return false; + } + + gestureStatusListenerSequence_++; + + if (listener) { + gestureResultListenerInfos_.insert(make_pair(gestureStatusListenerSequence_, + make_shared(gesturePathDefineList, listener))); + } + + AccessibilityOperator::GetInstance().SendSimulateGesture( + channelId_, gestureStatusListenerSequence_, gesturePathDefineList); + + return true; +} + +std::shared_ptr& AccessibleAbility::GetDisplayResizeController() +{ + HILOG_DEBUG("%{public}s start.", __func__); + + // TODO: To make sure the id of DEFAULT_DISPALY. + uint32_t DEFAULT_DISPALY = 0; + return GetDisplayResizeController(DEFAULT_DISPALY); +} + +std::shared_ptr& AccessibleAbility::GetDisplayResizeController(uint32_t displayId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + auto it = displayResizeControllers_.find(displayId); + if (it != displayResizeControllers_.end()) { + return displayResizeControllers_[displayId]; + } else { + HILOG_DEBUG("Have no DisplayResizeController and make a new one."); + displayResizeControllers_.insert(make_pair(displayId, + make_shared(channelId_, displayId))); + return displayResizeControllers_[displayId]; + } +} + +bool AccessibleAbility::GetRootElementInfo(std::optional& elementInfo) +{ + HILOG_DEBUG("%{public}s start.", __func__); + AccessibilityElementInfo info {}; + bool result = AccessibilityOperator::GetInstance().GetRoot(channelId_, info); + elementInfo = info; + return result; +} + +std::vector& AccessibleAbility::GetWindows() +{ + HILOG_DEBUG("%{public}s start.", __func__); + accessibilityWindow_ = AccessibilityOperator::GetInstance().GetWindows(channelId_); + return accessibilityWindow_; +} + +bool AccessibleAbility::PerformCommonAction(uint32_t action) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!CheckCommonAction(action)) { + HILOG_ERROR("action is not allowed."); + return false; + } + + return AccessibilityOperator::GetInstance().PerformCommonAction(channelId_, action); +} + +std::shared_ptr& AccessibleAbility::GetFingerprintController() +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!fingerprintController_) { + fingerprintController_ = make_shared(channelId_); + } + return fingerprintController_; +} + +void AccessibleAbility::DispatchOnSimulationGestureResult(uint32_t sequence, bool result) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + if (gestureResultListenerInfos_.empty()) { + HILOG_ERROR("There is no informations of gestureResultListener"); + return; + } + + shared_ptr gestureResultListenerInfo = nullptr; + auto it = gestureResultListenerInfos_.find(sequence); + if (it != gestureResultListenerInfos_.end()) { + HILOG_DEBUG("gestureResultListenerInfo has been found."); + gestureResultListenerInfo = gestureResultListenerInfos_[sequence]; + } + + if (!gestureResultListenerInfo) { + HILOG_ERROR("There is no gestureResultListenerInfo in gestureResultListenerInfos_[%{public}d", sequence); + return; + } + + shared_ptr listener = gestureResultListenerInfo->GetGestureResultListener(); + if (!listener) { + HILOG_ERROR("listener is nullptr."); + return; + } + + vector gesturePath = gestureResultListenerInfo->GetGesturePathDefine(); + if (gesturePath.empty()) { + HILOG_ERROR("There is no gesturePath"); + return; + } + + if (result) { + HILOG_DEBUG("Gesture has been sent successfully and result is %{public}d", result); + listener->OnCompleted(gesturePath); + } else { + HILOG_DEBUG("Gesture has been sent failed and result is %{public}d", result); + listener->OnCancelled(gesturePath); + } +} + +void AccessibleAbility::SetChannelId(uint32_t channelId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + channelId_ = channelId; +} + +bool AccessibleAbility::CheckCommonAction(uint32_t action) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if ((action != GLOBAL_ACTION_BACK) && (action != GLOBAL_ACTION_HOME) && + (action != GLOBAL_ACTION_RECENT) && (action != GLOBAL_ACTION_NOTIFICATION) && + (action != GLOBAL_ACTION_POP_UP_POWER_DIALOG) && (action != GLOBAL_ACTION_DIVIDE_SCREEN) && + (action != GLOBAL_ACTION_LOCK_SCREEN) && (action != GLOBAL_ACTION_CAPTURE_SCREEN)) { + return false; + } else { + return true; + } +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/aafwk/src/accessible_ability_client_proxy.cpp b/frameworks/aafwk/src/accessible_ability_client_proxy.cpp new file mode 100644 index 00000000..abf8c352 --- /dev/null +++ b/frameworks/aafwk/src/accessible_ability_client_proxy.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (C) 2021 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. + */ +#include +#include "accessible_ability_client_proxy.h" +#include "accessibility_errorcode.h" +#include "parcel.h" + +namespace OHOS { +namespace Accessibility { + +AccessibleAbilityClientProxy::AccessibleAbilityClientProxy(const sptr &object): + IRemoteProxy(object) +{} + +bool AccessibleAbilityClientProxy::WriteInterfaceToken(MessageParcel &data) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!data.WriteInterfaceToken(AccessibleAbilityClientProxy::GetDescriptor())) { + HILOG_ERROR("write interface token failed"); + return false; + } + return true; +} + +void AccessibleAbilityClientProxy::Init(const sptr &channel, const int channelId) { + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + HILOG_DEBUG("%{public}s start.", __func__); + + if (!WriteInterfaceToken(data)) { + return; + } + if (!channel) { + HILOG_ERROR("channel is null."); + return; + } + if (!data.WriteRemoteObject(channel->AsObject())) { + HILOG_ERROR("%{public}s fail, channel write parcelable error", __func__); + return; + } + + if (!data.WriteInt32(channelId)) { + HILOG_ERROR("%{public}s fail, channelId write int32 error", __func__); + return; + } + + error = Remote()->SendRequest(static_cast(IAccessibleAbilityClient::Message::INIT), data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Init fail, error: %d", error); + } +} + +void AccessibleAbilityClientProxy::Disconnect(const int channelId) { + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + HILOG_DEBUG("%{public}s start.", __func__); + + if (!WriteInterfaceToken(data)) { + return; + } + + if (!data.WriteInt32(channelId)) { + HILOG_ERROR("%{public}s fail, channelId write int32 error", __func__); + return; + } + + error = Remote()->SendRequest(static_cast(IAccessibleAbilityClient::Message::DISCONNECT), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Disconnect fail, error: %d", error); + } +} + +void AccessibleAbilityClientProxy::OnAccessibilityEvent(const AccessibilityEventInfo &eventInfo) { + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + HILOG_DEBUG("%{public}s start.", __func__); + + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteParcelable(&eventInfo)) { + HILOG_ERROR("%{public}s fail, eventInfo write parcelable error", __func__); + return; + } + error = Remote()->SendRequest(static_cast(IAccessibleAbilityClient::Message::ON_ACCESSIBILITY_EVENT), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("OnAccessibilityEvent fail, error: %d", error); + } +} + +void AccessibleAbilityClientProxy::OnInterrupt() { + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + HILOG_DEBUG("%{public}s start.", __func__); + + if (!WriteInterfaceToken(data)) { + return; + } + error = Remote()->SendRequest(static_cast(IAccessibleAbilityClient::Message::ON_INTERRUPT), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("OnInterrupt fail, error: %d", error); + } +} + +void AccessibleAbilityClientProxy::OnGesture(const int gestureId) { + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + HILOG_DEBUG("%{public}s start.", __func__); + + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteInt32(gestureId)) { + HILOG_ERROR("%{public}s fail, gestureId write int32 error", __func__); + return; + } + error = Remote()->SendRequest(static_cast(IAccessibleAbilityClient::Message::ON_GESTURE), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("OnGesture fail, error: %d", error); + } +} + +void AccessibleAbilityClientProxy::OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int sequence) { + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + HILOG_DEBUG("%{public}s start.", __func__); + + if (!WriteInterfaceToken(data)) { + return; + } +#if 0 // TODO: Use AccessibilityKeyEvent to instead KeyEvent + if (!data.WriteParcelable(&keyEvent)) { + HILOG_ERROR("%{public}s fail, keyEvent write parcelable error", __func__); + return; + } +#endif + if (!data.WriteInt32(sequence)) { + HILOG_ERROR("%{public}s fail, sequence write int32 error", __func__); + return; + } + error = Remote()->SendRequest(static_cast(IAccessibleAbilityClient::Message::ON_KEY_PRESS_EVENT), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("OnKeyPressEvent fail, error: %d", error); + } +} + +void AccessibleAbilityClientProxy::OnDisplayResizeChanged(const int displayId, const Rect &rect, const float scale, + const float centerX, const float centerY) { + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + HILOG_DEBUG("%{public}s start.", __func__); + + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteInt32(displayId)) { + HILOG_ERROR("%{public}s fail, displayId write int32 error", __func__); + return; + } + if (!data.WriteParcelable(&rect)) { + HILOG_ERROR("%{public}s fail, rect write parcelable error", __func__); + return; + } + if (!data.WriteFloat(scale)) { + HILOG_ERROR("%{public}s fail, scale write float error", __func__); + return; + } + if (!data.WriteFloat(centerX)) { + HILOG_ERROR("%{public}s fail, centerX write float error", __func__); + return; + } + if (!data.WriteFloat(centerY)) { + HILOG_ERROR("%{public}s fail, centerY write float error", __func__); + return; + } + + error = Remote()->SendRequest(static_cast(IAccessibleAbilityClient::Message::ON_DISPALYRESIZE_CHANGED), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("OnDisplayResizeChanged fail, error: %d", error); + } +} + +void AccessibleAbilityClientProxy::OnGestureSimulateResult(const int sequence, const bool completedSuccessfully) { + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + HILOG_DEBUG("%{public}s start.", __func__); + + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteInt32(sequence)) { + HILOG_ERROR("%{public}s fail, sequence write int32 error", __func__); + return; + } + if (!data.WriteBool(completedSuccessfully)) { + HILOG_ERROR("%{public}s fail, completedSuccessfully write bool error", __func__); + return; + } + error = Remote()->SendRequest(static_cast(IAccessibleAbilityClient::Message::ON_GESTURE_SIMULATE_RESULT), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("OnGestureSimulateResult fail, error: %d", error); + } +} + +void AccessibleAbilityClientProxy::OnFingerprintGestureValidityChanged(const bool validity) { + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + HILOG_DEBUG("%{public}s start.", __func__); + + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteBool(validity)) { + HILOG_ERROR("%{public}s fail, validity write bool error", __func__); + return; + } + error = Remote()->SendRequest(static_cast(IAccessibleAbilityClient::Message:: + ON_FINGERPRINT_GESTURE_VALIDITY_CHANGED), data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("OnFingerprintGestureValidityChanged fail, error: %d", error); + } +} + +void AccessibleAbilityClientProxy::OnFingerprintGesture(const int gesture) { + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + HILOG_DEBUG("%{public}s start.", __func__); + + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteInt32(gesture)) { + HILOG_ERROR("%{public}s fail, gesture write int32 error", __func__); + return; + } + error = Remote()->SendRequest(static_cast(IAccessibleAbilityClient::Message::ON_FINGERPRINT_GESTURE), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("OnFingerprintGesture fail, error: %d", error); + } +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/aafwk/src/accessible_ability_client_stub.cpp b/frameworks/aafwk/src/accessible_ability_client_stub.cpp new file mode 100644 index 00000000..81d1b0ec --- /dev/null +++ b/frameworks/aafwk/src/accessible_ability_client_stub.cpp @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessible_ability_client_stub.h" +#include "parcel.h" + +namespace OHOS { +namespace Accessibility { + +AccessibleAbilityClientStub::AccessibleAbilityClientStub() +{ + HILOG_DEBUG("%{public}s start.", __func__); + memberFuncMap_[static_cast(IAccessibleAbilityClient::Message::INIT)] = + &AccessibleAbilityClientStub::HandleInit; + memberFuncMap_[static_cast(IAccessibleAbilityClient::Message::DISCONNECT)] = + &AccessibleAbilityClientStub::HandleDisconnect; + memberFuncMap_[static_cast(IAccessibleAbilityClient::Message::ON_ACCESSIBILITY_EVENT)] = + &AccessibleAbilityClientStub::HandleOnAccessibilityEvent; + memberFuncMap_[static_cast(IAccessibleAbilityClient::Message::ON_INTERRUPT)] = + &AccessibleAbilityClientStub::HandleOnInterrupt; + memberFuncMap_[static_cast(IAccessibleAbilityClient::Message::ON_GESTURE)] = + &AccessibleAbilityClientStub::HandleOnGesture; + memberFuncMap_[static_cast(IAccessibleAbilityClient::Message::ON_KEY_PRESS_EVENT)] = + &AccessibleAbilityClientStub::HandleOnKeyPressEvent; + memberFuncMap_[static_cast(IAccessibleAbilityClient::Message::ON_DISPALYRESIZE_CHANGED)] = + &AccessibleAbilityClientStub::HandleOnDisplayResizeChanged; + memberFuncMap_[static_cast(IAccessibleAbilityClient::Message::ON_GESTURE_SIMULATE_RESULT)] = + &AccessibleAbilityClientStub::HandleOnGestureSimulateResult; + memberFuncMap_[static_cast( + IAccessibleAbilityClient::Message::ON_FINGERPRINT_GESTURE_VALIDITY_CHANGED)] = + &AccessibleAbilityClientStub::HandleOnFingerprintGestureValidityChanged; + memberFuncMap_[static_cast(IAccessibleAbilityClient::Message::ON_FINGERPRINT_GESTURE)] = + &AccessibleAbilityClientStub::HandleOnFingerprintGesture; +} + +AccessibleAbilityClientStub::~AccessibleAbilityClientStub() +{ + HILOG_DEBUG("%{public}s start.", __func__); + memberFuncMap_.clear(); +} + +int AccessibleAbilityClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + HILOG_DEBUG("AccessibleAbilityClientStub::OnRemoteRequest, cmd = %d, flags= %d", code, option.GetFlags()); + std::u16string descriptor = AccessibleAbilityClientStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + HILOG_INFO("local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + auto itFunc = memberFuncMap_.find(code); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data, reply); + } + } + HILOG_WARN("AccessibleAbilityClientStub::OnRemoteRequest, default case, need check."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +ErrCode AccessibleAbilityClientStub::HandleInit(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s start.", __func__); + sptr object = data.ReadRemoteObject(); + if (!object) { + HILOG_ERROR("object is nullptr."); + return ERR_INVALID_VALUE; + } + + sptr channel = iface_cast(object); + if (!channel) { + HILOG_ERROR("channel is nullptr."); + return ERR_INVALID_VALUE; + } + int channelId = data.ReadInt32(); + + Init(channel, channelId); + return NO_ERROR; +} + +ErrCode AccessibleAbilityClientStub::HandleDisconnect(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s start.", __func__); + int channelId = data.ReadInt32(); + Disconnect(channelId); + return NO_ERROR; +} + +ErrCode AccessibleAbilityClientStub::HandleOnAccessibilityEvent(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s start.", __func__); + std::unique_ptr eventInfo(data.ReadParcelable()); + if (!eventInfo) { + HILOG_ERROR("ReadParcelable failed"); + return ERR_INVALID_VALUE; + } + + OnAccessibilityEvent(*eventInfo); + return NO_ERROR; +} + +ErrCode AccessibleAbilityClientStub::HandleOnInterrupt(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s start.", __func__); + OnInterrupt(); + return NO_ERROR; +} + +ErrCode AccessibleAbilityClientStub::HandleOnGesture(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s start.", __func__); + int gestureId = data.ReadInt32(); + OnGesture(gestureId); + return NO_ERROR; +} + +ErrCode AccessibleAbilityClientStub::HandleOnKeyPressEvent(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s start.", __func__); +#if 0 // TODO: Use AccessibilityKeyEvent to instead KeyEvent + std::unique_ptr keyEvent(data.ReadParcelable()); + if (!keyEvent) { + HILOG_ERROR("ReadParcelable failed"); + return ERR_INVALID_VALUE; + } + + int sequence = data.ReadInt32(); + + OnKeyPressEvent(*keyEvent, sequence); +#endif + return NO_ERROR; +} + +ErrCode AccessibleAbilityClientStub::HandleOnDisplayResizeChanged(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s start.", __func__); + int displayId = data.ReadInt32(); + + std::unique_ptr rect(data.ReadParcelable()); + if (!rect) { + HILOG_ERROR("ReadParcelable failed"); + return ERR_INVALID_VALUE; + } + + float scale = data.ReadFloat(); + float centerX = data.ReadFloat(); + float centerY = data.ReadFloat(); + + OnDisplayResizeChanged(displayId, *rect, scale, centerX, centerY); + return NO_ERROR; +} + +ErrCode AccessibleAbilityClientStub::HandleOnGestureSimulateResult(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s start.", __func__); + int sequence = data.ReadInt32(); + bool completedSuccessfully = data.ReadBool(); + + OnGestureSimulateResult(sequence, completedSuccessfully); + return NO_ERROR; +} + +ErrCode AccessibleAbilityClientStub::HandleOnFingerprintGestureValidityChanged( + MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s start.", __func__); + bool validity = data.ReadBool(); + OnFingerprintGestureValidityChanged(validity); + return NO_ERROR; +} + +ErrCode AccessibleAbilityClientStub::HandleOnFingerprintGesture(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s start.", __func__); + int gesture = data.ReadInt32(); + OnFingerprintGesture(gesture); + return NO_ERROR; +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/aafwk/src/accessible_ability_client_stub_impl.cpp b/frameworks/aafwk/src/accessible_ability_client_stub_impl.cpp new file mode 100644 index 00000000..94acb47c --- /dev/null +++ b/frameworks/aafwk/src/accessible_ability_client_stub_impl.cpp @@ -0,0 +1,298 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include "accessible_ability_client_stub_impl.h" +#include "accessible_ability.h" +#include "display_resize_controller.h" +#include "fingerprint_controller.h" + +using namespace std; + +namespace OHOS { +namespace Accessibility { + +const string TASK_INIT = "Init"; +const string TASK_DISCONNECT = "Disconnect"; +const string TASK_ON_ACCESSIBILITY_EVENT = "OnAccessibilityEvent"; +const string TASK_ON_INTERRUPT = "OnInterrupt"; +const string TASK_ON_GESTURE = "OnGesture"; +const string TASK_ON_KEY_PRESS_EVENT = "OnKeyPressEvent"; +const string TASK_ON_DISPLAYRESIZE_CHANGED = "OnDisplayResizeChanged"; +const string TASK_ON_GESTURE_SIMULATE_RESULT = "OnGestureSimulateResult"; +const string TASK_ON_FINGERPRINT_GESTURE_VALIDITY_CHANGED = "OnFingerprintGestureValidityChanged"; +const string TASK_ON_FINGERPRINT_GESTURE = "OnFingerprintGesture"; + +AccessibleAbilityClientStubImpl::AccessibleAbilityClientStubImpl + (const std::shared_ptr &accessibleAbilityEventHandler) + : handler_(accessibleAbilityEventHandler) + {} + +void AccessibleAbilityClientStubImpl::RegisterListenerImpl(const std::shared_ptr &listener) +{ + HILOG_DEBUG("Register AccessibleAbilityClientStubImpl listener."); + if (listener_) { + HILOG_DEBUG("listener already exists."); + return; + } + + listener_ = listener; +} + +void AccessibleAbilityClientStubImpl::Init(const sptr &channel, const int channelId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + std::function initFunc = std::bind(&AccessibleAbilityClientStubImpl::InitInner, this, channel, channelId); + handler_->PostTask(initFunc, TASK_INIT); +} + +void AccessibleAbilityClientStubImpl::Disconnect(const int channelId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + std::function disconnectFunc = std::bind(&AccessibleAbilityClientStubImpl::InitInner, + this, nullptr, channelId); + handler_->PostTask(disconnectFunc, TASK_DISCONNECT); +} + +void AccessibleAbilityClientStubImpl::InitInner(const sptr &channel, const int channelId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!channel) { + HILOG_DEBUG("RemoveChannel start."); + + // Delete death recipient + if (channel_ && channel_->AsObject()) { + HILOG_ERROR("Remove death recipient"); + channel_->AsObject()->RemoveDeathRecipient(deathRecipient_); + } + + // Remove channel + AccessibilityOperator::RemoveChannel(channelId); + channelId_ = INVALID_CHANNEL_ID; + AccessibleAbility::GetInstance().SetChannelId(channelId_); + channel_ = channel; + } else { + HILOG_DEBUG("AddChannel start."); + AccessibilityOperator::AddChannel(channelId, channel); + channelId_ = channelId; + AccessibleAbility::GetInstance().SetChannelId(channelId_); + channel_ = channel; + + // Add death recipient + if (!deathRecipient_) { + deathRecipient_ = new AccessibleAbilityDeathRecipient(channelId_, channel_); + } + + auto object = channel_->AsObject(); + if (object) { + HILOG_DEBUG("Add death recipient"); + object->AddDeathRecipient(deathRecipient_); + } + + // Add listener of ability + if (!listener_) { + HILOG_ERROR("listener is nullptr."); + return; + } + listener_->OnAbilityConnected(); + } +} + +void AccessibleAbilityClientStubImpl::OnAccessibilityEvent(const AccessibilityEventInfo &eventInfo) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (channelId_ != INVALID_CHANNEL_ID) { + std::function onAccessibilityEventFunc = std::bind( + &AccessibleAbilityClientStubImpl::OnAccessibilityEventInner, this, eventInfo); + handler_->PostTask(onAccessibilityEventFunc, TASK_ON_ACCESSIBILITY_EVENT); + } +} + +void AccessibleAbilityClientStubImpl::OnAccessibilityEventInner(const AccessibilityEventInfo &eventInfo) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!listener_) { + HILOG_ERROR("listener is nullptr."); + return; + } + + listener_->OnAccessibilityEvent(eventInfo); +} + +void AccessibleAbilityClientStubImpl::OnInterrupt() +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (channelId_ != INVALID_CHANNEL_ID) { + std::function interruptFunc = std::bind(&AccessibleAbilityClientStubImpl::OnInterruptInner, this); + handler_->PostTask(interruptFunc, TASK_ON_INTERRUPT); + } +} + +void AccessibleAbilityClientStubImpl::AccessibleAbilityClientStubImpl::OnInterruptInner() +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!listener_) { + HILOG_ERROR("listener is nullptr."); + return; + } + listener_->OnInterrupt(); +} + +void AccessibleAbilityClientStubImpl::OnGesture(const int gestureId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (channelId_ != INVALID_CHANNEL_ID) { + std::function onGestureFunc = std::bind(&AccessibleAbilityClientStubImpl::OnGestureInner, + this, gestureId); + handler_->PostTask(onGestureFunc, TASK_ON_GESTURE); + } +} + +void AccessibleAbilityClientStubImpl::OnGestureInner(const int gestureId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!listener_) { + HILOG_ERROR("listener is nullptr."); + return; + } + listener_->OnGesture(gestureId); +} + +void AccessibleAbilityClientStubImpl::OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int sequence) +{ + HILOG_DEBUG("%{public}s start.", __func__); + // TODO: fixme + // std::function onKeyPressEventFunc = std::bind( + // &AccessibleAbilityClientStubImpl::OnKeyPressEventInner, this, keyEvent, sequence); + // handler_->PostTask(onKeyPressEventFunc, TASK_ON_KEY_PRESS_EVENT); +} + +void AccessibleAbilityClientStubImpl::OnKeyPressEventInner(const MMI::KeyEvent &keyEvent, const int sequence) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!listener_) { + HILOG_ERROR("listener is nullptr."); + return; + } + + bool handled = listener_->OnKeyPressEvent(keyEvent); + AccessibilityOperator::GetInstance().SetOnKeyPressEventResult(channelId_, handled, sequence); +} + +void AccessibleAbilityClientStubImpl::OnDisplayResizeChanged(const int displayId, const Rect &rect, const float scale, + const float centerX, const float centerY) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (channelId_ != INVALID_CHANNEL_ID) { + std::function onDisplayResizeChangedFunc = std::bind( + &AccessibleAbilityClientStubImpl::OnDisplayResizeChangedInner, this, + displayId, rect, scale, centerX, centerY); + handler_->PostTask(onDisplayResizeChangedFunc, TASK_ON_DISPLAYRESIZE_CHANGED); + } +} + +void AccessibleAbilityClientStubImpl::OnDisplayResizeChangedInner(const int displayId, const Rect &rect, + const float scale, const float centerX, const float centerY) +{ + HILOG_DEBUG("%{public}s start.", __func__); + shared_ptr displayResizeController = + AccessibleAbility::GetInstance().GetDisplayResizeController(displayId); + if (!displayResizeController) { + HILOG_ERROR("There is no displayResizeController."); + return; + } + + displayResizeController->DispatchOnDisplayResizeChanged(rect, scale, centerX, centerY); +} + +void AccessibleAbilityClientStubImpl::OnGestureSimulateResult(const int sequence, const bool completedSuccessfully) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (channelId_ != INVALID_CHANNEL_ID) { + std::function onGestureSimulateResultFunc = std::bind( + &AccessibleAbilityClientStubImpl::OnGestureSimulateResultInner, this, sequence, completedSuccessfully); + handler_->PostTask(onGestureSimulateResultFunc, TASK_ON_GESTURE_SIMULATE_RESULT); + } +} + +void AccessibleAbilityClientStubImpl::OnGestureSimulateResultInner(const int sequence, + const bool completedSuccessfully) +{ + HILOG_DEBUG("%{public}s start.", __func__); + AccessibleAbility::GetInstance().DispatchOnSimulationGestureResult(sequence, completedSuccessfully); +} + +void AccessibleAbilityClientStubImpl::OnFingerprintGestureValidityChanged(const bool validity) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (channelId_ != INVALID_CHANNEL_ID) { + std::function onFingerprintGestureValidityChangedFunc = std::bind( + &AccessibleAbilityClientStubImpl::OnFingerprintGestureValidityChangedInner, this, validity); + handler_->PostTask(onFingerprintGestureValidityChangedFunc, TASK_ON_FINGERPRINT_GESTURE_VALIDITY_CHANGED); + } +} + +void AccessibleAbilityClientStubImpl::OnFingerprintGestureValidityChangedInner(const bool validity) +{ + HILOG_DEBUG("%{public}s start.", __func__); + shared_ptr fingerprintController = + AccessibleAbility::GetInstance().GetFingerprintController(); + if (!fingerprintController) { + HILOG_ERROR("There is no fingerprintController."); + return; + } + + fingerprintController->DispatchOnFingerprintGestureStatusChanged(validity); +} + +void AccessibleAbilityClientStubImpl::OnFingerprintGesture(const int gesture) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (channelId_ != INVALID_CHANNEL_ID) { + std::function onFingerprintGestureFunc = std::bind( + &AccessibleAbilityClientStubImpl::OnFingerprintGestureInner, this, gesture); + handler_->PostTask(onFingerprintGestureFunc, TASK_ON_FINGERPRINT_GESTURE); + } +} + +void AccessibleAbilityClientStubImpl::OnFingerprintGestureInner(const int gesture) +{ + HILOG_DEBUG("%{public}s start.", __func__); + shared_ptr fingerprintController = + AccessibleAbility::GetInstance().GetFingerprintController(); + if (!fingerprintController) { + HILOG_ERROR("There is no fingerprintController."); + return; + } + + fingerprintController->DispatchOnFingerprintGesture(gesture); +} + +void AccessibleAbilityClientStubImpl::AccessibleAbilityDeathRecipient::OnRemoteDied(const wptr& remote) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + // Delete death recipient + remote->RemoveDeathRecipient(this); + + // Remove channel + AccessibilityOperator::RemoveChannel(recipientChannelId_); + recipientChannelId_ = INVALID_CHANNEL_ID; + AccessibleAbility::GetInstance().SetChannelId(recipientChannelId_); + recipientchannel_ = nullptr; +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/aafwk/src/accessible_ability_event_handler.cpp b/frameworks/aafwk/src/accessible_ability_event_handler.cpp new file mode 100644 index 00000000..951fff07 --- /dev/null +++ b/frameworks/aafwk/src/accessible_ability_event_handler.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessible_ability_event_handler.h" + +namespace OHOS { +namespace Accessibility { + +AccessibleAbilityEventHandler::AccessibleAbilityEventHandler(const std::shared_ptr &runner) + : AppExecFwk::EventHandler(runner) +{ + HILOG_DEBUG("AccessibleAbilityEventHandler is created"); +} + +AccessibleAbilityEventHandler::~AccessibleAbilityEventHandler() +{ + HILOG_DEBUG("AccessibleAbilityEventHandler is destroyed"); +} + +void AccessibleAbilityEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +{ + HILOG_DEBUG("eventId = %{public}d", event->GetInnerEventId()); + switch (event->GetInnerEventId()) { + default: + HILOG_ERROR("the eventId is not supported"); + break; + } +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/aafwk/src/display_resize_controller.cpp b/frameworks/aafwk/src/display_resize_controller.cpp new file mode 100644 index 00000000..f432c515 --- /dev/null +++ b/frameworks/aafwk/src/display_resize_controller.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "display_resize_controller.h" + +using namespace std; + +namespace OHOS { +namespace Accessibility { + +DisplayResizeController::DisplayResizeController(uint32_t channelId, uint32_t displayId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + channelId_ = channelId; + displayId_ = displayId; +} + +void DisplayResizeController::AddListener(std::shared_ptr& listener) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + if (!listener) { + return; + } + + for (auto it = displayResizeListeners_.begin(); it != displayResizeListeners_.end(); ++it) { + if (*it == listener) { + return; + } + } + displayResizeListeners_.push_back(listener); + + return; +} + +bool DisplayResizeController::DeleteListener(std::shared_ptr& listener) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + for (auto it = displayResizeListeners_.begin(); it != displayResizeListeners_.end(); ++it) { + if (*it == listener) { + displayResizeListeners_.erase(it); + return true; + } + } + + return false; +} + +float DisplayResizeController::GetCenterX() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return AccessibilityOperator::GetInstance().GetDisplayResizeCenterX(channelId_, displayId_); +} + +float DisplayResizeController::GetCenterY() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return AccessibilityOperator::GetInstance().GetDisplayResizeCenterY(channelId_, displayId_); +} + +Rect DisplayResizeController::GetDisplayResizeRect() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return AccessibilityOperator::GetInstance().GetDisplayResizeRect(channelId_, displayId_); +} + +float DisplayResizeController::GetScale() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return AccessibilityOperator::GetInstance().GetDisplayResizeScale(channelId_, displayId_); +} + +bool DisplayResizeController::Reset(bool isShouldAnimate) +{ + HILOG_DEBUG("%{public}s start.", __func__); + return AccessibilityOperator::GetInstance().ResetDisplayResize(channelId_, displayId_, isShouldAnimate); +} + +bool DisplayResizeController::SetCenter(float centerX, float centerY, bool isShouldAnimate) +{ + HILOG_DEBUG("%{public}s start.", __func__); + return AccessibilityOperator::GetInstance().SetDisplayResizeScaleAndCenter( + channelId_, displayId_, 1.0, centerX, centerY, isShouldAnimate); +} + +bool DisplayResizeController::SetScale(float scale, bool isShouldAnimate) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + float invalidValue = -1; + return AccessibilityOperator::GetInstance().SetDisplayResizeScaleAndCenter( + channelId_, displayId_, scale, invalidValue, invalidValue, isShouldAnimate); +} + +void DisplayResizeController::DispatchOnDisplayResizeChanged(const Rect& rect, + const float scale, const float centerX, const float centerY) +{ + HILOG_DEBUG("%{public}s start.", __func__); + for (auto listener : displayResizeListeners_) { + listener->OnDisplayResizeChanged(*this, rect, scale, centerX, centerY); + } +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/aafwk/src/fingerprint_controller.cpp b/frameworks/aafwk/src/fingerprint_controller.cpp new file mode 100644 index 00000000..bcd977df --- /dev/null +++ b/frameworks/aafwk/src/fingerprint_controller.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "fingerprint_controller.h" + +using namespace std; + +namespace OHOS { +namespace Accessibility { + +FingerprintController::FingerprintController(uint32_t channelId) +{ + HILOG_DEBUG("%{public}s start and channelId is %{public}d.", __func__, channelId); + channelId_ = channelId; +} + +bool FingerprintController::IsFingerprintGestureDetectionValid() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return AccessibilityOperator::GetInstance().IsFingerprintGestureDetectionValid(channelId_); +} + +void FingerprintController::AddFingerprintListener(std::shared_ptr& listener) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!listener) { + HILOG_ERROR("listener is nullptr."); + return; + } + fingerprintListener_ = listener; +} + +void FingerprintController::DeleteFingerprintListener(std::shared_ptr& listener) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!listener) { + HILOG_ERROR("listener is nullptr."); + return; + } + if (fingerprintListener_ != listener) { + HILOG_ERROR("There is not this listener."); + return; + } + fingerprintListener_ = nullptr; +} + +void FingerprintController::DispatchOnFingerprintGestureStatusChanged(bool isActive) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + if (!fingerprintListener_) { + HILOG_ERROR("fingerprintListener_ is nullptr."); + return; + } + fingerprintListener_->OnFingerprintGestureStatusChanged(isActive); +} + +void FingerprintController::DispatchOnFingerprintGesture(uint32_t gesture) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + if (!fingerprintListener_) { + HILOG_ERROR("fingerprintListener_ is nullptr."); + return; + } + fingerprintListener_->OnFingerprintGesture(gesture); +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/asacfwk.gni b/frameworks/asacfwk/asacfwk.gni new file mode 100644 index 00000000..09c6d914 --- /dev/null +++ b/frameworks/asacfwk/asacfwk.gni @@ -0,0 +1,36 @@ +# Copyright (c) 2021 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("//base/accessibility/accessibility.gni") + +asacfwk_files = [ + "${asacfwk_path}/src/accessibility_event_info.cpp", + "${asacfwk_path}/src/accessibility_element_info.cpp", + "${asacfwk_path}/src/accessibility_window_info.cpp", + "${asacfwk_path}/src/accessibility_state_event.cpp", + "${asacfwk_path}/src/accessibility_system_ability_client.cpp", + "${asacfwk_path}/src/accessible_ability_manager_service_proxy.cpp", + "${asacfwk_path}/src/accessible_ability_manager_service_state_proxy.cpp", + "${asacfwk_path}/src/accessible_ability_manager_service_state_stub.cpp", + "${asacfwk_path}/src/accessible_ability_manager_service_stub.cpp", + "${asacfwk_path}/src/accessibility_interaction_operation_callback_proxy.cpp", + "${asacfwk_path}/src/accessibility_interaction_operation_callback_stub.cpp", + "${asacfwk_path}/src/accessibility_interaction_operation_proxy.cpp", + "${asacfwk_path}/src/accessibility_interaction_operation_stub.cpp", + "${asacfwk_path}/src/accessibility_ability_info.cpp", + "${asacfwk_path}/src/accessible_ability_channel_proxy.cpp", + "${asacfwk_path}/src/accessible_ability_channel_stub.cpp", + "${asacfwk_path}/src/accessibility_operator.cpp", + "${asacfwk_path}/src/gesture_simulation.cpp", + "//base/accessibility/util/src/json_utils.cpp", +] \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessibility_interaction_operation_callback_interface.h b/frameworks/asacfwk/include/accessibility_interaction_operation_callback_interface.h new file mode 100644 index 00000000..3c7a26fb --- /dev/null +++ b/frameworks/asacfwk/include/accessibility_interaction_operation_callback_interface.h @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_INTERACTION_OPERATION_CALLBACK_INTERFACE_H +#define ACCESSIBILITY_INTERACTION_OPERATION_CALLBACK_INTERFACE_H + +#include +#include +#include + +#include "accessibility_element_info.h" + +#include "iremote_broker.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class supply the callback to feedback the result from UI to AA. + +*/ +class IAccessibilityInteractionOperationCallback : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.accessibility.IAccessibilityInteractionOperationCallback"); + + /** + * @brief Set the element information by accessibility id to AA. + * @param infos The element info searched by accessibility id. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetSearchElementInfoByAccessibilityIdResult(const std::vector &infos, + const int requestId) = 0; + + /** + * @brief Set the element informations matched with text to AA. + * @param infos The element informations searched matched with text. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetSearchElementInfoByTextResult(const std::vector &infos, + const int requestId) = 0; + + /** + * @brief Set the element informations matched with focus type to AA. + * @param info The element informations searched matched with focus type. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info, const int requestId) = 0; + + /** + * @brief Set the element informations by focus direction to AA. + * @param info The element informations searched by focus direction. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int requestId) = 0; + + /** + * @brief Set the result of action executed to AA. + * @param succeeded True: The action is executed successfully; otherwise is false. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetPerformActionResult(const bool succeeded, const int requestId) = 0; + + enum class Message { + SET_RESULT_BY_ACCESSIBILITY_ID = 0, + SET_RESULT_BY_TEXT, + SET_RESULT_FOCUSED_INFO, + SET_RESULT_FOCUS_MOVE, + SET_RESULT_PERFORM_ACTION, + }; +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessibility_interaction_operation_callback_proxy.h b/frameworks/asacfwk/include/accessibility_interaction_operation_callback_proxy.h new file mode 100644 index 00000000..4c8e88d9 --- /dev/null +++ b/frameworks/asacfwk/include/accessibility_interaction_operation_callback_proxy.h @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_INTERACTION_OPERATION_CALLBACK_PROXY_H +#define ACCESSIBILITY_INTERACTION_OPERATION_CALLBACK_PROXY_H + +#include +#include +#include + +#include "accessibility_interaction_operation_callback_interface.h" + +#include "iremote_proxy.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class supply the callback to feedback the result from UI to AA. + +*/ +class AccessibilityInteractionOperationCallbackProxy : + public IRemoteProxy { +public: + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + explicit AccessibilityInteractionOperationCallbackProxy(const sptr &object); + + /** + * @brief destruct function + * @param + * @return + */ + virtual ~AccessibilityInteractionOperationCallbackProxy() override; + + /** + * @brief Set the element information by accessibility id to AA. + * @param infos The element info searched by accessibility id. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void SetSearchElementInfoByAccessibilityIdResult(const std::vector &infos, + const int requestId) override; + + /** + * @brief Set the element informations matched with text to AA. + * @param infos The element informations searched matched with text. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void SetSearchElementInfoByTextResult(const std::vector &infos, + const int requestId) override; + + /** + * @brief Set the element informations matched with focus type to AA. + * @param info The element informations searched matched with focus type. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info, const int requestId) override; + + /** + * @brief Set the element informations by focus direction to AA. + * @param info The element informations searched by focus direction. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int requestId) override; + + /** + * @brief Set the result of action executed to AA. + * @param succeeded True: The action is executed successfully; otherwise is false. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void SetPerformActionResult(const bool succeeded, const int requestId) override; + +private: + /** + * @brief Write the descriptor of IPC. + * @param data It is include the descriptor of IPC. + * @return true: Write the descriptor successfully; otherwise is not. + */ + bool WriteInterfaceToken(MessageParcel &data); + + /** + * @brief Write the serializable data + * @param parcelableVector The communication data of IPC + * @param reply Serializable data + * @return true: Write the serializable data successfully; otherwise is not. + */ + template + bool WriteParcelableVector(const std::vector &parcelableVector, Parcel &reply); + static inline BrokerDelegator delegator; +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessibility_interaction_operation_callback_stub.h b/frameworks/asacfwk/include/accessibility_interaction_operation_callback_stub.h new file mode 100644 index 00000000..e94dd43f --- /dev/null +++ b/frameworks/asacfwk/include/accessibility_interaction_operation_callback_stub.h @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_INTERACTION_OPERATION_CALLBACK_STUB_H +#define ACCESSIBILITY_INTERACTION_OPERATION_CALLBACK_STUB_H + +#include +#include +#include + +#include "accessibility_interaction_operation_callback_interface.h" +#include "accessibility_errorcode.h" +#include "iremote_stub.h" +#include "nocopyable.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class define the interface for UI to implement. +* It triggered by ABMS when AA to request the accessibility information. +*/ +class AccessibilityInteractionOperationCallbackStub : public IRemoteStub { +public: + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + AccessibilityInteractionOperationCallbackStub(); + + /** + * @brief destruct function + * @param + * @return + */ + virtual ~AccessibilityInteractionOperationCallbackStub(); + + /** + * @brief Receive the event from proxy by IPC mechanism. + * @param code The code is matched with the process function. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @param option The option paramter of IPC,such as: async,sync + * @return + */ + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; +private: + /** + * @brief Handle the IPC request for the function:SetSearchElementInfoByAccessibilityIdResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSetSearchElementInfoByAccessibilityIdResult(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:SetSearchElementInfoByTextResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSetSearchElementInfoByTextResult(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:SetFindFocusedElementInfoResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSetFindFocusedElementInfoResult(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:SetFocusMoveSearchResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSetFocusMoveSearchResult(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:SetPerformActionResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSetPerformActionResult(MessageParcel &data, MessageParcel &reply); + + using AccessibilityInteractionOperationCallbackFunc = ErrCode (AccessibilityInteractionOperationCallbackStub::*) + (MessageParcel &data, MessageParcel &reply); + std::map memberFuncMap_; +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessibility_interaction_operation_interface.h b/frameworks/asacfwk/include/accessibility_interaction_operation_interface.h new file mode 100644 index 00000000..fbf679fd --- /dev/null +++ b/frameworks/asacfwk/include/accessibility_interaction_operation_interface.h @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_INTERACTION_OPERATION_INTERFACE_H +#define ACCESSIBILITY_INTERACTION_OPERATION_INTERFACE_H + +#include +#include +#include +#include + +#include "accessibility_interaction_operation_callback_interface.h" + +#include "iremote_broker.h" +#include "iremote_object.h" +#include "refbase.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class define the interface for UI to implement. +* It triggered by ABMS when AA to request the accessibility information. +*/ +class IAccessibilityInteractionOperation : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.accessibility.IAccessibilityInteractionOperation"); + + /** + * @brief Make the node information by accessibility ID and set the result by callback. + * @param elementId: The unique id of the component ID. + * @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. + * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also. + * PREFETCH_SIBLINGS: Need to make the sister/brothers node info also. + * PREFETCH_CHILDREN: Need to make the child node info also. + * otherwise: Make the node information by elementId only. + * @return - + * @sysCap Accessibility + */ + virtual void SearchElementInfoByAccessibilityId(const long elementId, + const int requestId, const sptr &callback, const int mode) = 0; + + /** + * @brief Make the child node information by accessibility ID and filtered by text and set the result by callback. + * @param elementId: The unique id of the component ID. + * @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. + * @param text Filter for the child components to matched with the text + * @return + */ + virtual void SearchElementInfosByText(const long elementId, const std::string &text, + const int requestId, const sptr &callback) = 0; + + /** + * @brief Make the node information of the component focused by the focus type specified. + * @param elementId: The unique id of the component ID. + * @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. + * @param focusType FOCUS_TYPE_ACCESSIBILITY: accessibility focus + * FOCUS_TYPE_INPUT: text input focus + * @return + */ + virtual void FindFocusedElementInfo(const long elementId, const int focusType, const int requestId, + const sptr &callback) = 0; + + /** + * @brief Make the node info by current focus move direction. + * @param elementId: The unique id of the component ID. + * @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. + * @param direction Refer to AccessibilityElementInfo.FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD) + * @return - + */ + virtual void FocusMoveSearch(const long elementId, const int direction, const int requestId, + const sptr &callback) = 0; + + /** + * @brief To return the result of perform action. + * @param elementId: The unique id of the component ID. + * @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. + * @param action Refer to [AccessibilityElementInfo.ActionType] + * @param actionArguments The parameter for action type. such as: + * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_NEXT_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_SET_SELECTION, + * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, + * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) + * action: ACCESSIBILITY_ACTION_SET_TEXT, + * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") + * @return + */ + virtual void PerformAction(const long elementId, const int action, + const std::map actionArguments, + const int requestId, const sptr &callback) = 0; + + /** + * @brief The function is called while accessibility System check the id of window is not equal + * to the id of active window when sendAccessibility. + * @param - + * @return + */ + virtual void ClearFocus() = 0; + + /** + * @brief the low layser is notified by the function called while accessibility system execute + * the function of performAction from AS to check the all low windows cared the outside event. + * Example: PopupWindow receive the OUTSIDE_EVENT to close itself. + * @param - + * @return + */ + virtual void OutsideTouch() = 0; + + enum class Message { + SEARCH_BY_ACCESSIBILITY_ID = 0, + SEARCH_BY_TEXT, + FIND_FOCUSED_INFO, + FOCUS_FIND, + PERFORM_ACTION, + CLEAR_FOCUS, + OUTSIDE_TOUCH, + }; +}; + +} // namespace Accessibility +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessibility_interaction_operation_proxy.h b/frameworks/asacfwk/include/accessibility_interaction_operation_proxy.h new file mode 100644 index 00000000..13ceff73 --- /dev/null +++ b/frameworks/asacfwk/include/accessibility_interaction_operation_proxy.h @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_INTERACTION_OPERATION_PROXY_H +#define ACCESSIBILITY_INTERACTION_OPERATION_PROXY_H + +#include +#include +#include + +#include "accessibility_interaction_operation_callback_interface.h" +#include "accessibility_interaction_operation_interface.h" + +#include "iremote_proxy.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class define the interface for UI to implement. +* It triggered by ABMS when AA to request the accessibility information. +*/ +class AccessibilityInteractionOperationProxy : public IRemoteProxy{ +public: + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + explicit AccessibilityInteractionOperationProxy(const sptr &object); + + /** + * @brief destruct function + * @param + * @return + */ + virtual ~AccessibilityInteractionOperationProxy() override; + + /** + * @brief Make the node information by accessibility ID and set the result by callback. + * @param elementId: The unique id of the component ID. + * @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. + * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also. + * PREFETCH_SIBLINGS: Need to make the sister/brothers node info also. + * PREFETCH_CHILDREN: Need to make the child node info also. + * otherwise: Make the node information by elementId only. + * @return - + * @sysCap Accessibility + */ + virtual void SearchElementInfoByAccessibilityId(const long elementId, const int requestId, + const sptr &callback, const int mode) override; + + /** + * @brief Make the child node information by accessibility ID and filtered by text and set the result by callback. + * @param elementId: The unique id of the component ID. + * @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. + * @param text Filter for the child components to matched with the text + * @return + */ + virtual void SearchElementInfosByText(const long elementId, const std::string &text, + const int requestId, const sptr &callback) override; + + /** + * @brief Make the node information of the component focused by the focus type specified. + * @param elementId: The unique id of the component ID. + * @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. + * @param focusType FOCUS_TYPE_ACCESSIBILITY: accessibility focus + * FOCUS_TYPE_INPUT: text input focus + * @return + */ + virtual void FindFocusedElementInfo(const long elementId, const int focusType, const int requestId, + const sptr &callback) override; + + /** + * @brief Make the node info by current focus move direction. + * @param elementId: The unique id of the component ID. + * @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. + * @param direction Refer to AccessibilityElementInfo.FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD) + * @return - + */ + virtual void FocusMoveSearch(const long elementId, const int direction, const int requestId, + const sptr &callback) override; + + /** + * @brief To return the result of perform action. + * @param elementId: The unique id of the component ID. + * @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. + * @param action Refer to [AccessibilityElementInfo.ActionType] + * @param actionArguments The parameter for action type. such as: + * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_NEXT_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_SET_SELECTION, + * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, + * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) + * action: ACCESSIBILITY_ACTION_SET_TEXT, + * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") + * @return + */ + virtual void PerformAction(const long elementId, const int action, + const std::map actionArguments, + int requestId, const sptr &callback) override; + + /** + * @brief The function is called while accessibility System check the id of window is not equal + * to the id of active window when sendAccessibility. + * @param - + * @return + */ + virtual void ClearFocus() override; + + /** + * @brief the low layser is notified by the function called while accessibility system execute + * the function of performAction from AS to check the all low windows cared the outside event. + * Example: PopupWindow receive the OUTSIDE_EVENT to close itself. + * @param - + * @return + */ + virtual void OutsideTouch() override; +private: + /** + * @brief Write the descriptor of IPC. + * @param data It is include the descriptor of IPC. + * @return true: Write the descriptor successfully; otherwise is not. + */ + bool WriteInterfaceToken(MessageParcel &data); + static inline BrokerDelegator delegator; +}; + +} // namespace Accessibility +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessibility_interaction_operation_stub.h b/frameworks/asacfwk/include/accessibility_interaction_operation_stub.h new file mode 100644 index 00000000..954f4197 --- /dev/null +++ b/frameworks/asacfwk/include/accessibility_interaction_operation_stub.h @@ -0,0 +1,325 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_INTERACTION_OPERATION_STUB_H +#define ACCESSIBILITY_INTERACTION_OPERATION_STUB_H + +#include +#include +#include +#include + +#include "accessibility_interaction_operation_interface.h" +#include "accessibility_interaction_operation_callback.h" +#include "accessibility_errorcode.h" +#include "iremote_object.h" +#include "iremote_stub.h" +#include "nocopyable.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class define the interface for UI to implement. +* It is triggered by ABMS when AA to request the accessibility information. +*/ +class AccessibilityInteractionOperationStub : public IRemoteStub{ +public: + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + AccessibilityInteractionOperationStub(); + + /** + * @brief destruct function + * @param + * @return + */ + virtual ~AccessibilityInteractionOperationStub(); + + /** + * @brief Receive the event from proxy by IPC mechanism. + * @param code The code is matched with the process function. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @param option The option paramter of IPC,such as: async,sync + * @return + */ + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; + + /** + * @brief Make the node information by accessibility ID and set the result by callback. + * @param elementId: The unique id of the component ID. + * @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. + * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also. + * PREFETCH_SIBLINGS: Need to make the sister/brothers node info also. + * PREFETCH_CHILDREN: Need to make the child node info also. + * otherwise: Make the node information by elementId only. + * @return - + */ + virtual void SearchElementInfoByAccessibilityId(const long elementId, const int requestId, + const sptr &callback, const int mode) override; + + /** + * @brief Make the child node information by accessibility ID and filtered by text and set the result by callback. + * @param elementId: The unique id of the component ID. + * @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. + * @param text Filter for the child components to matched with the text + * @return + */ + virtual void SearchElementInfosByText(const long elementId, const std::string &text, + const int requestId, const sptr &callback) override; + + /** + * @brief Make the node information of the component focused by the focus type specified. + * @param elementId: The unique id of the component ID. + * @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. + * @param focusType FOCUS_TYPE_ACCESSIBILITY: accessibility focus + * FOCUS_TYPE_INPUT: text input focus + * @return + */ + virtual void FindFocusedElementInfo(const long elementId, const int focusType, const int requestId, + const sptr &callback) override; + + /** + * @brief Make the node info by current focus move direction. + * @param elementId: The unique id of the component ID. + * @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. + * @param direction Refer to AccessibilityElementInfo.FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD) + * @return - + */ + virtual void FocusMoveSearch(const long elementId, const int direction, const int requestId, + const sptr &callback) override; + + /** + * @brief To return the result of perform action. + * @param elementId: The unique id of the component ID. + * @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. + * @param action Refer to [AccessibilityElementInfo.ActionType] + * @param actionArguments The parameter for action type. such as: + * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_NEXT_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_SET_SELECTION, + * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, + * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) + * action: ACCESSIBILITY_ACTION_SET_TEXT, + * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") + * @return + */ + virtual void PerformAction(const long elementId, const int action, + const std::map actionArguments, + int requestId, const sptr &callback) override; + + /** + * @brief The function is called while accessibility System check the id of window is not equal + * to the id of active window when sendAccessibility. + * @param - + * @return + */ + + virtual void ClearFocus() override; + + /** + * @brief the low layser is notified by the function called while accessibility system execute + * the function of performAction from AS to check the all low windows cared the outside event. + * Example: PopupWindow receive the OUTSIDE_EVENT to close itself. + * @param - + * @return + */ + virtual void OutsideTouch() override; + + /** + * @brief Save the window id related with operator object + * @param windowId: The unique id of the window related with operator object. + * @return - + */ + void SetWindowId(int windowId); + + /** + * @brief Get the window id related with operator object + * @param windowId: The unique id of the window related with operator object. + * @return - + */ + int GetWindowId(); + + /** + * Implement the function to set the result to AA when ACE complete the request. + */ + class CallbackImpl : public AccessibilityInteractionOperationCallback { + public: + enum CALL_API_NUM : uint32_t { + CALLBACK_BY_ACCESSIBILITY_ID = 0x00000001, + CALLBACK_BY_TEXT = 0x00000002, + CALLBACK_FIND_FOCUS = 0x00000004, + CALLBACK_BY_FOCUS_MOVE = 0x00000008, + CALLBACK_PERFORM_ACTION = 0x00000010, + }; + + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + CallbackImpl(); + + /** + * @brief construct function + * @param requestId The request id from AA, it is used to match with request and response. + * @param callNum The id is matched handle function of IPC. + * @return + */ + CallbackImpl(const int requestId, CALL_API_NUM callNum); + + /** + * @brief Set the element information by accessibility id to AA. + * @param infos The element info searched by accessibility id. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetSearchElementInfoByAccessibilityIdResult(const std::list &infos, + const int requestId) override; + + /** + * @brief Set the element informations matched with text to AA. + * @param infos The element informations searched matched with text. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetSearchElementInfoByTextResult(const std::list &infos, + const int requestId) override; + + /** + * @brief Set the element informations matched with focus type to AA. + * @param info The element informations searched matched with focus type. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info, + const int requestId) override; + + /** + * @brief Set the element informations by focus direction to AA. + * @param info The element informations searched by focus direction. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int requestId) override; + + /** + * @brief Set the result of action executed to AA. + * @param succeeded True: The action is executed successfully; otherwise is false. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetPerformActionResult(const bool succeeded, const int requestId) override; + + /** + * @brief Get the callback object of AA. + * @param + * @return The callback object of AA and the request id matched. + */ + std::map> GetAACallbackList(); + + /** + * @brief Remove the callback object of AA after send the result to AA. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void RemoveAACallbackList(int requestId); + private: + int requestId_ = 0; + CALL_API_NUM callNum_ = CALLBACK_BY_ACCESSIBILITY_ID; + }; +private: + /** + * @brief Handle the IPC request for the function:SetSearchElementInfoByAccessibilityIdResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSearchElementInfoByAccessibilityId(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:SetSearchElementInfoByTextResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSearchElementInfosByText(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:SetFindFocusedElementInfoResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleFindFocusedElementInfo(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:SetFocusMoveSearchResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleFocusFind(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:SetPerformActionResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandlePerformAction(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:ClearFocus. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleClearFocus(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:OutsideTouch. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleOutsideTouch(MessageParcel &data, MessageParcel &reply); + + using AccessibilityInteractionOperationFunc = ErrCode (AccessibilityInteractionOperationStub::*) + (MessageParcel &data, MessageParcel &reply); + std::map memberFuncMap_ {}; + static std::map> aaCallbacks_; + int windowId_ = 0; + DISALLOW_COPY_AND_MOVE(AccessibilityInteractionOperationStub); +}; + +} // namespace Accessibility +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessibility_operator.h b/frameworks/asacfwk/include/accessibility_operator.h new file mode 100644 index 00000000..3215cc01 --- /dev/null +++ b/frameworks/asacfwk/include/accessibility_operator.h @@ -0,0 +1,372 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_INTERACTION_CLIENT_H +#define ACCESSIBILITY_INTERACTION_CLIENT_H + +#include +#include +#include +#include +#include +#include + +#include "accessible_ability_channel_interface.h" +#include "accessible_ability_channel_proxy.h" +#include "accessibility_element_info.h" +#include "accessibility_window_info.h" +#include "accessibility_interaction_operation_callback_interface.h" +#include "accessibility_interaction_operation_callback_stub.h" +#include "gesture_simulation.h" +#include "refbase.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class supply the api called by AA to get the accessibility info of UI. +* It call the API of AAMS and the request will be proccessed by +* UI and then set the result by callback(AA-->this class(with Callback)--> AAMS +* --> UI process and set Callback). +* It supply one instance for each thread to use this class. +*/ +class AccessibilityOperator : public AccessibilityInteractionOperationCallbackStub{ +public: + static const int NONE_ID = -1; + static const int MAX_INSTANCE = 10; + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + AccessibilityOperator(); + + /** + * @brief Get the instance of AccessibilityOperator + * @param + * @return The instance of AccessibilityOperator + */ + static AccessibilityOperator &GetInstance(); + + /** + * @brief Inner function: Get the instance of AccessibilityOperator for each thread. + * The max instance is MAX_INSTANCE. + * @param threadId The thread id that request to get instance. + * @return The instance of AccessibilityOperator + */ + static AccessibilityOperator &GetInstanceForThread(std::thread::id threadId); + + /** + * @brief Inner function: Get the object connected from AA to AAMS by channel id. + * @param channelId The id matched the object connected from AA to AAMS + * @return The object connected from AA to AAMS. + */ + static sptr GetChannel(int channelId); + + /** + * @brief Set the object connected from AA to AAMS and channel id matched. + * @param channelId The id matched the object connected from AA to AAMS + * @param channel The object connected from AA to AAMS. + * @return + */ + static void AddChannel(const int channelId, const sptr &channel); + + /** + * @brief Remove the object connected from AA to AAMS by channel id. + * @param channelId The id matched the object connected from AA to AAMS + * @return + */ + static void RemoveChannel(int channelId); + + /** + * @brief Get the root component information + * @param channelId The id matched the object connected from AA to AAMS + * @param elementInfo[out] The root component information + * @return + */ + bool GetRoot(int channelId, AccessibilityElementInfo &elementInfo); + + /** + * @brief Get all windows of accessibility. + * @param channelId The id matched the object connected from AA to AAMS + * @return All windows information of accessibility. + */ + std::vector GetWindows(int channelId); + + /** + * @brief Find the node information by accessibility ID. + * @param channelId The id matched the object connected from AA to AAMS. + * @param elementId: The unique id of the component ID. + * @param accessibilityWindowId The window id that the component belongs to. + * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also. + * PREFETCH_SIBLINGS: Need to make the sister/brothers node info also. + * 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 - + */ + bool SearchElementInfosByAccessibilityId(int channelId, + int accessibilityWindowId, int elementId, + int mode, std::vector &elementInfos); + + /** + * @brief Find the node information filtered by text. + * @param channelId The id matched the object connected from AA to AAMS. + * @param elementId: The unique id of the component ID. + * @param accessibilityWindowId The window id that the component belongs to. + * @param text The filter text. + * @param elementInfos[out] The components information matched conditions searched. + * @return - + */ + bool SearchElementInfosByText(int channelId, int accessibilityWindowId, int elementId, + const std::string &text, std::vector& elementInfos); + + /** + * @brief Find the focus node information. + * @param channelId The id matched the object connected from AA to AAMS. + * @param elementId: The unique id of the component ID. + * @param accessibilityWindowId The window id that the component belongs to. + * @param focusType The type of focus. + * FOCUS_TYPE_ACCESSIBILITY: accessibility focus + * FOCUS_TYPE_INPUT: text input focus + * @param elementInfos[out] The components information matched conditions searched. + * @return - + */ + bool FindFocusedElementInfo(int channelId, int accessibilityWindowId, + int elementId, int focusType, AccessibilityElementInfo &elementInfo); + + /** + * @brief Find the node information by focus move direction. + * @param channelId The id matched the object connected from AA to AAMS. + * @param elementId: The unique id of the component ID. + * @param accessibilityWindowId The window id that the component belongs to. + * @param direction The direction of focus move direction. + * Refer to FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD). + * @param elementInfos[out] The components information matched conditions searched. + * @return - + */ + bool FocusMoveSearch(int channelId, int accessibilityWindowId, + int elementId, int direction, AccessibilityElementInfo &elementInfo); + + /** + * @brief Perform the action on the component. + * @param channelId The id matched the object connected from AA to AAMS. + * @param elementId: The unique id of the component ID. + * @param accessibilityWindowId The window id that the component belongs to. + * @param action The action triggered on component. + * Refer to [AccessibilityElementInfo.ActionType] + * @param actionArguments The parameter for action type. such as: + * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_NEXT_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_SET_SELECTION, + * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, + * {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 successfully; otherwise is not. + */ + bool PerformAction(int channelId, int accessibilityWindowId, + int elementId, int action, std::map &actionArguments); + + /** + * @brief Save the elements information searched in ACE side + * @param infos The elements info searched by accessibility id. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void SetSearchElementInfoByAccessibilityIdResult(const std::vector &infos, + const int requestId) override; + + /** + * @brief Save the elements information searched in ACE side + * @param infos The elements info searched by accessibility id. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void SetSearchElementInfoByTextResult(const std::vector &infos, + const int requestId) override; + + /** + * @brief Save the element information searched in ACE side + * @param infos The element info searched by accessibility id. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info, const int requestId) override; + + /** + * @brief Save the element information searched in ACE side + * @param infos The element info searched by accessibility id. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int requestId) override; + + /** + * @brief Save the result of action executed in ACE. + * @param succeeded True: The action is executed successfully; otherwise is false. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + void SetPerformActionResult(const bool succeeded, const int requestId) override; + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @param action: The common action + * @return true: Perform successfully; otherwise is not. + */ + bool PerformCommonAction(const int channelId, const int action); + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @return - + */ + void DisableAbility(const int channelId); + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @param handled True: That is handled; otherwise is not. + * @param sequence The number of sequence. + * @return - + */ + void SetOnKeyPressEventResult(const int channelId, const bool handled, const int sequence); + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @param displayId The display id + * @return - + */ + float GetDisplayResizeScale(const int channelId, const int displayId); + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @param displayId The display id + * @return - + */ + float GetDisplayResizeCenterX(const int channelId, const int displayId); + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @param displayId The display id + * @return - + */ + float GetDisplayResizeCenterY(const int channelId, const int displayId); + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @param displayId The display id + * @return The range displayed. + */ + Rect GetDisplayResizeRect(const int channelId, const int displayId); + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @param displayId The display id + * @param animate true: It is animation; otherwise is not. + * @return true: Reset successfully; otherwise is not. + */ + bool ResetDisplayResize(const int channelId, const int displayId, const bool animate); + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @param displayId The display id + * @param scale The value of scaled. + * @param animate true: It is animation; otherwise is not. + * @param centerX coordinate X. + * @param centerY coordinate Y. + * @return true: Resize successfully; otherwise is not. + */ + bool SetDisplayResizeScaleAndCenter(const int channelId, const int displayId, const float scale, + const float centerX, const float centerY, const bool animate); + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @param sequence The number of sequence. + * @param gestureSteps The value of gesture. + * @return - + */ + void SendSimulateGesture(const int channelId, const int sequence, + const std::vector &gestureSteps); + + /** + * @brief Wrap the function of function expect for ACE related + * @param channelId The id matched the object connected from AA to AAMS. + * @return true: It is valid fingerprint; otherwise is not. + */ + bool IsFingerprintGestureDetectionValid(const int channelId); + + /** + * @brief Inner function: The status requested from AA to ACE. + * @param + * @return true: The requestion is completed; otherwise is not. + */ + bool GetOperationStatus(); + + /** + * @brief Inner function: Set the status requested from AA to ACE. + * @param status true: The requestion is completed; otherwise is not. + * @return - + */ + void SetOperationStatus(bool status); +private: + /** + * @brief Inner function: Set the timer related with the requestion from AA to ACE. + * @param requestId The request id from AA, it is used to match with request and response. + * @return - + */ + bool WaitForResultTimedLocked(int requestId); + + /** + * @brief Inner function: Count the unique id requested + * @param + * @return The request id from AA, it is used to match with request and response. + */ + int CreateRequestId(); + static const long TIMEOUT_OPERATOR_MILLIS = 500000; + static const long SLEEP_MILLIS = 5000; + static const uint32_t SECOND_TO_MILLIS = 1000000; + static const uint32_t MAX_REQUEST = 0x7FFFFFFF; + static std::vector> instances_; + static std::map> channels_; + int responseId_ = 0; + + static int requestId_; //matched request with callback result + AccessibilityElementInfo accessibilityInfoResult_{}; + std::vector accessibilityInfosResult_{}; + std::vector windows_{}; + bool performActionResult_ = false; + static std::recursive_mutex mutex_; + bool completed_ = false; + +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessible_ability_channel_interface.h b/frameworks/asacfwk/include/accessible_ability_channel_interface.h new file mode 100644 index 00000000..455f3e87 --- /dev/null +++ b/frameworks/asacfwk/include/accessible_ability_channel_interface.h @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILITY_CHANNEL_INTERFACE_H +#define ACCESSIBLE_ABILITY_CHANNEL_INTERFACE_H + +#include +#include +#include + +#include "accessibility_interaction_operation_callback_interface.h" +#include "accessibility_element_info.h" +#include "accessibility_window_info.h" +#include "gesture_simulation.h" +#include "iremote_broker.h" +#include "refbase.h" + +namespace OHOS { +namespace Accessibility { + +class IAccessibleAbilityChannel : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.accessibility.IAccessibleAbilityChannel"); + + /** + * @brief Searchs elementInfo by accessibility id and set the result by callback. + * @param accessibilityWindowId The id of accessibility window. + * @param elementId The unique id of the component ID. + * @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. + * @param mode PREFETCH_PREDECESSORS: Need to make the parent element info also. + * 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. + */ + virtual bool SearchElementInfoByAccessibilityId(const int accessibilityWindowId, + const long elementId, const int requestId, const sptr &callback, + const int mode) = 0; + + /** + * @brief Make the child element information by accessibility ID and filtered by text and + * set the result by callback. + * @param accessibilityWindowId The id of accessibility window. + * @param elementId: The unique id of the component ID. + * @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. + */ + virtual bool SearchElementInfosByText(const int accessibilityWindowId, const long elementId, + const std::string &text, const int requestId, + const sptr &callback) = 0; + + /** + * @brief Make the element information of the component focused by the focus type specified. + * @param accessibilityWindowId The id of accessibility window. + * @param elementId: The unique id of the component ID. + * @param focusType FOCUS_TYPE_ACCESSIBILITY: accessibility focus + * 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. + */ + virtual bool FindFocusedElementInfo(const int accessibilityWindowId, const long elementId, + const int focusType, const int requestId, + const sptr &callback) = 0; + + /** + * @brief Make the element info by current focus move direction. + * @param accessibilityWindowId The id of accessibility window. + * @param elementId: The unique id of the component ID. + * @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. + */ + virtual bool FocusMoveSearch(const int accessibilityWindowId, const long elementId, + const int direction, const int requestId, + const sptr &callback) = 0; + + /** + * @brief To perform action. + * @param accessibilityWindowId The id of accessibility window. + * @param elementId: The unique id of the component ID. + * @param action Refer to [AccessibilityElementInfo.ActionType] + * @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. + */ + virtual bool PerformAction(const int accessibilityWindowId, const long elementId, const int action, + std::map &actionArguments, const int requestId, + const sptr &callback) = 0; + + /** + * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. + * @param + * @return The infomation of windows. + */ + virtual std::vector GetWindows() = 0; + + /** + * @brief Executes a specified action. + * @param action The action of OHOS::Accessibility::GlobalAction. + * @return Return true if performs action successfully, else return false. + */ + virtual bool PerformCommonAction(const int action) = 0; + + /** + * @brief Disable the accessible ability. + * @param + * @return + */ + virtual void DisableAbility() = 0; + + /** + * @brief Set the result of key press event. + * @param handled The result of key press event, true if the event has been consumed, otherwise false. + * @param sequence The sequence of key press event result. + * @return + */ + virtual void SetOnKeyPressEventResult(const bool handled, const int sequence) = 0; + + /** + * @brief Obtains the resizing scale of this display resizing rectangle. + * @param displayId The id of display. + * @return Returns the resizing scale. + */ + virtual float GetDisplayResizeScale(const int displayId) = 0; + + /** + * @brief Obtains the X coordinate of the center in this display resizing rectangle. + * @param displayId The id of display. + * @return Returns the X coordinate of the center. + */ + virtual float GetDisplayResizeCenterX(const int displayId) = 0; + + /** + * @brief Obtains the Y coordinate of the center in this display resizing rectangle. + * @param displayId The id of display. + * @return Returns the Y coordinate of the center. + */ + virtual float GetDisplayResizeCenterY(const int displayId) = 0; + + /** + * @brief Obtains the display resizing rectangle. + * @param displayId The id of display. + * @return Returns the display resizing rectangle. + */ + virtual Rect GetDisplayResizeRect(const int displayId) = 0; + + /** + * @brief Resets the display to its initial size. + * @param displayId The id of display. + * @param animate Specifies whether animation is required. + * @return Returns true if the display is successfully reset; returns false otherwise. + */ + virtual bool ResetDisplayResize(const int displayId, const bool animate) = 0; + + /** + * @brief Sets the center coordinates and scale for the display resizing rectangle. + * @param displayId The id of display. + * @param scale Indicates the scale for resizing the display + * @param centerX Indicates the X coordinate of the center for resizing the display. + * @param centerY Indicates the Y coordinate of the center for resizing the display. + * @param animate Specifies whether animation is required. + * @return Returns true if the center coordinates and scale are successfully set; returns false otherwise. + */ + virtual bool SetDisplayResizeScaleAndCenter(const int displayId, const float scale, const float centerX, + const float centerY, const bool animate) = 0; + + /** + * @brief Send simulation gesture. + * @param sequence The sequence of simulation gesture. + * @param gestureSteps The gesture to send. + * @return + */ + virtual void SendSimulateGesture(const int sequence, const std::vector &gestureSteps) = 0; + + /** + * @brief Judge whether the gesture detection function of the fingerprint sensor is available. + * @param + * @return Return true if the fingerprint sensor is available, else return false. + */ + virtual bool IsFingerprintGestureDetectionValid() = 0; + + enum class Message { + SEARCH_ELEMENTINFO_BY_ACCESSIBILITYID = 0, + SEARCH_ELEMENTINFOS_BY_TEXT, + FIND_FOCUSED_ELEMENTINFO, + FOCUS_MOVE_SEARCH, + PERFORM_ACTION, + GET_WINDOWS, + PERFORM_COMMON_ACTION, + DISABLE_ABILITY, + SET_ON_KEY_PRESS_EVENT_RESULT, + GET_DISPALYRESIZE_SCALE, + GET_DISPALYRESIZE_CETER_X, + GET_DISPLAYRESIZE_CETER_Y, + GET_DISPLAYRESIZE_RECT, + RESET_DISPALYRESIZE, + SET_DISPLAYRESIZE_SCALE_AND_CENTER, + SEND_SIMULATE_GESTURE, + IS_FINGERPRINT_GESTURE_DETECTION_VALID, + }; + +}; + +} // namespace Accessibility +} // namespace OHOS +#endif // ACCESSIBLE_ABILITY_CHANNEL_INTERFACE_H \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessible_ability_channel_proxy.h b/frameworks/asacfwk/include/accessible_ability_channel_proxy.h new file mode 100644 index 00000000..1299213f --- /dev/null +++ b/frameworks/asacfwk/include/accessible_ability_channel_proxy.h @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILITY_CHANNEL_PROXY_H +#define ACCESSIBLE_ABILITY_CHANNEL_PROXY_H + +#include +#include +#include +#include "accessible_ability_channel_interface.h" +#include "hilog_wrapper.h" +#include "iremote_proxy.h" +#include "message_parcel.h" + +namespace OHOS { +namespace Accessibility { + +class AccessibleAbilityChannelProxy : public IRemoteProxy { +public: + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + explicit AccessibleAbilityChannelProxy(const sptr &object); + + /** + * @brief destruct function + * @param + * @return + */ + virtual ~AccessibleAbilityChannelProxy() = default; + + /** + * @brief Searchs elementInfo by accessibility id and set the result by callback through the proxy object. + * @param accessibilityWindowId The id of accessibility window. + * @param elementId The unique id of the component ID. + * @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. + * @param mode PREFETCH_PREDECESSORS: Need to make the parent element info also. + * 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. + */ + virtual bool SearchElementInfoByAccessibilityId(const int accessibilityWindowId, + const long elementId, const int requestId, const sptr &callback, + const int mode) override; + + /** + * @brief Make the child element information by accessibility ID and filtered by text and + * set the result by callback through the proxy object. + * @param accessibilityWindowId The id of accessibility window. + * @param elementId: The unique id of the component ID. + * @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. + */ + virtual bool SearchElementInfosByText(const int accessibilityWindowId, const long elementId, + const std::string &text, const int requestId, + const sptr &callback) override; + + /** + * @brief Make the element information of the component focused + * by the focus type specified through the proxy object. + * @param accessibilityWindowId The id of accessibility window. + * @param elementId: The unique id of the component ID. + * @param focusType FOCUS_TYPE_ACCESSIBILITY: accessibility focus + * 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. + */ + virtual bool FindFocusedElementInfo(const int accessibilityWindowId, const long elementId, + const int focusType, const int requestId, + const sptr &callback) override; + + /** + * @brief Make the element info by current focus move direction through the proxy object. + * @param accessibilityWindowId The id of accessibility window. + * @param elementId: The unique id of the component ID. + * @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. + */ + virtual bool FocusMoveSearch(const int accessibilityWindowId, const long elementId, + const int direction, const int requestId, + const sptr &callback) override; + + /** + * @brief To perform action through the proxy object. + * @param accessibilityWindowId The id of accessibility window. + * @param elementId: The unique id of the component ID. + * @param action Refer to [AccessibilityElementInfo.ActionType] + * @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. + */ + virtual bool PerformAction(const int accessibilityWindowId, const long elementId, const int action, + std::map &actionArguments, const int requestId, + const sptr &callback) override; + + /** + * @brief Obtains the list of interactive windows on the device, + * in the layers they are visible to users through the proxy object. + * @param + * @return The infomation of windows. + */ + virtual std::vector GetWindows() override; + + /** + * @brief Executes a specified action through the proxy object. + * @param action The action of OHOS::Accessibility::GlobalAction. + * @return Return true if performs action successfully, else return false. + */ + virtual bool PerformCommonAction(const int action) override; + + /** + * @brief Disable the accessible ability through the proxy object. + * @param + * @return + */ + virtual void DisableAbility() override; + + /** + * @brief Set the result of key press event through the proxy object. + * @param handled The result of key press event, true if the event has been consumed, otherwise false. + * @param sequence The sequence of key press event result. + * @return + */ + virtual void SetOnKeyPressEventResult(const bool handled, const int sequence) override; + + /** + * @brief Obtains the resizing scale of this display resizing rectangle through the proxy object. + * @param displayId The id of display. + * @return Returns the resizing scale. + */ + virtual float GetDisplayResizeScale(const int displayId) override; + + /** + * @brief Obtains the X coordinate of the center in this display resizing rectangle through the proxy object. + * @param displayId The id of display. + * @return Returns the X coordinate of the center. + */ + virtual float GetDisplayResizeCenterX(const int displayId) override; + + /** + * @brief Obtains the Y coordinate of the center in this display resizing rectangle through the proxy object. + * @param displayId The id of display. + * @return Returns the Y coordinate of the center. + */ + virtual float GetDisplayResizeCenterY(const int displayId) override; + + /** + * @brief Obtains the display resizing rectangle through the proxy object. + * @param displayId The id of display. + * @return Returns the display resizing rectangle. + */ + virtual Rect GetDisplayResizeRect(const int displayId) override; + + /** + * @brief Resets the display to its initial size through the proxy object. + * @param displayId The id of display. + * @param animate Specifies whether animation is required. + * @return Returns true if the display is successfully reset; returns false otherwise. + */ + virtual bool ResetDisplayResize(const int displayId, const bool animate) override; + + /** + * @brief Sets the center coordinates and scale for the display resizing rectangle through the proxy object. + * @param displayId The id of display. + * @param scale Indicates the scale for resizing the display + * @param centerX Indicates the X coordinate of the center for resizing the display. + * @param centerY Indicates the Y coordinate of the center for resizing the display. + * @param animate Specifies whether animation is required. + * @return Returns true if the center coordinates and scale are successfully set; returns false otherwise. + */ + virtual bool SetDisplayResizeScaleAndCenter(const int displayId, const float scale, const float centerX, + const float centerY, const bool animate) override; + + /** + * @brief Send simulation gesture through the proxy object. + * @param sequence The sequence of simulation gesture. + * @param gestureSteps The gesture to send. + * @return + */ + virtual void SendSimulateGesture(const int sequence, const std::vector &gestureSteps) override; + + /** + * @brief Judge whether the gesture detection function of the fingerprint sensor is available + * through the proxy object. + * @param + * @return Return true if the fingerprint sensor is available, else return false. + */ + virtual bool IsFingerprintGestureDetectionValid() override; + +private: + /** + * @brief Write the descriptor of IPC. + * @param data It is include the descriptor of IPC. + * @return true: Write the descriptor successfully; otherwise is not. + */ + bool WriteInterfaceToken(MessageParcel &data); + /** + * @brief Send the command data from proxy to stub in IPC mechanism. + * @param code The code matched the function called. + * @param data Serializable data + * @param reply The response of IPC + * @param option The option paramter of IPC,such as: async,sync + * @return true: Write the descriptor successfully; otherwise is not. + */ + bool SendTransactCmd(IAccessibleAbilityChannel::Message code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + static inline BrokerDelegator delegator; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBLE_ABILITY_CHANNEL_PROXY_H \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessible_ability_channel_stub.h b/frameworks/asacfwk/include/accessible_ability_channel_stub.h new file mode 100644 index 00000000..04d9e36d --- /dev/null +++ b/frameworks/asacfwk/include/accessible_ability_channel_stub.h @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILITY_CHANNEL_STUB_H +#define ACCESSIBLE_ABILITY_CHANNEL_STUB_H + +#include +#include +#include "accessible_ability_channel_interface.h" +#include "accessibility_errorcode.h" +#include "hilog_wrapper.h" +#include "iremote_stub.h" +#include "nocopyable.h" +#include "message_parcel.h" +#include "message_option.h" + +namespace OHOS { +namespace Accessibility { + +class AccessibleAbilityChannelStub : public IRemoteStub { +public: + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + AccessibleAbilityChannelStub(); + + /** + * @brief destruct function + * @param + * @return + */ + virtual ~AccessibleAbilityChannelStub(); + + /** + * @brief Receive the event from proxy by IPC mechanism. + * @param code The code is matched with the process function. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @param option The option paramter of IPC,such as: async,sync + * @return + */ + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) override; +private: + /** + * @brief Handle the IPC request for the function:HandleSearchElementInfoByAccessibilityId. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSearchElementInfoByAccessibilityId(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleSearchElementInfosByText. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSearchElementInfosByText(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleFindFocusedElementInfo. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleFindFocusedElementInfo(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleFocusMoveSearch. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleFocusMoveSearch(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandlePerformAction. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandlePerformAction(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleGetWindows. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleGetWindows(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandlePerformCommonAction. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandlePerformCommonAction(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleDisableAbility. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleDisableAbility(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleSetOnKeyPressEventResult. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSetOnKeyPressEventResult(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleGetDisplayResizeScale. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleGetDisplayResizeScale(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleGetDisplayResizeCenterX. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleGetDisplayResizeCenterX(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleGetDisplayResizeCenterY. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleGetDisplayResizeCenterY(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleGetDisplayResizeRect. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleGetDisplayResizeRect(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleResetDisplayResize. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleResetDisplayResize(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleSetDisplayResizeScaleAndCenter. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSetDisplayResizeScaleAndCenter(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleSendSimulateGesture. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSendSimulateGesture(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleIsFingerprintGestureDetectionValid. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleIsFingerprintGestureDetectionValid(MessageParcel &data, MessageParcel &reply); + + using AccessibleAbilityConnectionFunc = ErrCode (AccessibleAbilityChannelStub::*)(MessageParcel &data, + MessageParcel &reply); + std::map memberFuncMap_; + + DISALLOW_COPY_AND_MOVE(AccessibleAbilityChannelStub); +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBLE_ABILITY_CHANNEL_STUB_H \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessible_ability_manager_service_interface.h b/frameworks/asacfwk/include/accessible_ability_manager_service_interface.h new file mode 100644 index 00000000..ea289243 --- /dev/null +++ b/frameworks/asacfwk/include/accessible_ability_manager_service_interface.h @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ABILITY_MANAGER_SERVICE_CLIENT_INTERFACE_H +#define ACCESSIBILITY_ABILITY_MANAGER_SERVICE_CLIENT_INTERFACE_H + +#include +#include +#include +#include "accessibility_ability_info.h" +#include "accessible_ability_manager_service_state_interface.h" +#include "accessibility_event_info.h" +#include "accessibility_interaction_operation_interface.h" +#include "iremote_broker.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class define the interface to call ABMS API. +*/ +class IAccessibleAbilityManagerServiceClient : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.accessibility.IAccessibleAbilityManagerServiceClient"); + + /** + * @brief Sends information about an accessibility event. + * @param uiEvent Indicates the accessibility event information specified by AccessibilityEventInfo. + * @param accountId The user id. + * @return true: send ok; otherwise is refused. + */ + virtual void SendEvent(const AccessibilityEventInfo &uiEvent, const int accountId) = 0; + + /** + * @brief Register the state observer of AAMS. + * @param callback state observer + * @param accountId The user id. + * @return 0: Register ok; otherwise is refused. + */ + virtual uint32_t RegisterStateCallback(const sptr &callback, + const int accountId) = 0; + + /** + * @brief Queries the list of accessibility abilities. + * @param accessibilityAbilityTypes Indicates the accessibility type specified by + * AccessibilityAbilityInfo#ACCESSIBILITY_ABILITY_TYPE_SPOKEN. + * @param stateType Indicates the accessibility ability status. 1 indicates that the ability is enabled; + * 2 indicates that the ability is disabled; 4 indicates that the ability has been installed. + * @return + */ + virtual std::vector GetAbilityList(const int abilityTypes, const int stateType) = 0; + + /** + * @brief Register the interaction operation, so the AA can get node info from ACE. + * @param windowId Window ID + * @param operation The callback object. + * @param accountId User ID + * @return 0: Succeed ; otherwise is failed. + */ + virtual void RegisterInteractionOperation(const int windowId, + const sptr &operation, + const int accountId) = 0; + + /** + * @brief Deregister the interaction operation. + * @param windowId Window ID + * @return + */ + virtual void DeregisterInteractionOperation(const int windowId) = 0; + + /** + * @brief Requests feedback interruption from all accessibility services. + * Remained. + * @param - + * @return + */ + virtual void Interrupt(const int accountId) = 0; //Remained + + /** + * @brief Register AA connection to AAMS. + * Temp Solution. + * @param obj IPC object + * @return + */ + virtual void RegisterAbilityConnectionClientTmp(const sptr& obj) = 0; + + /** + * @brief Obtains the suggested interval for switching the UI. + * @param + * @return Returns the interval. + */ + virtual uint64_t GetSuggestedInterval() = 0; + + enum class Message { + SEND_EVENT = 0, + REGISTER_STATE_CALLBACK, + GET_ABILITYLIST, + REGISTER_INTERACTION_CONNECTION, + DEREGISTER_INTERACTION_CONNECTION, + INTERRUPT, + GET_SUGGESTED_INTERVAL, + REGISTER_ABILITY_CONNECTION_CLIENT // Temp Solution + }; +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessible_ability_manager_service_proxy.h b/frameworks/asacfwk/include/accessible_ability_manager_service_proxy.h new file mode 100644 index 00000000..5e0e6c5c --- /dev/null +++ b/frameworks/asacfwk/include/accessible_ability_manager_service_proxy.h @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ABILITY_MANAGER_SERVICE_CLIENT_PROXY_H +#define ACCESSIBILITY_ABILITY_MANAGER_SERVICE_CLIENT_PROXY_H + +#include +#include +#include "accessible_ability_manager_service_interface.h" +#include "accessible_ability_manager_service_state_interface.h" +#include "accessibility_event_info.h" +#include "iremote_proxy.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class define the interface to call ABMS API. +*/ +class AccessibleAbilityManagerServiceClientProxy : public IRemoteProxy { +public: + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + explicit AccessibleAbilityManagerServiceClientProxy(const sptr &object); + + /** + * @brief destruct function + * @param + * @return + */ + virtual ~AccessibleAbilityManagerServiceClientProxy() override; + + /** + * @brief Sends information about an accessibility event. + * @param uiEvent Indicates the accessibility event information specified by AccessibilityEventInfo. + * @param accountId The user id. + * @return true: send ok; otherwise is refused. + */ + virtual void SendEvent(const AccessibilityEventInfo &uiEvent, const int accountId) override; + + /** + * @brief Register the state observer of AAMS. + * @param callback state observer + * @param accountId The user id. + * @return 0: Register ok; otherwise is refused. + */ + virtual uint32_t RegisterStateCallback(const sptr &callback, + const int accountId) override; + + /** + * @brief Queries the list of accessibility abilities. + * @param accessibilityAbilityTypes Indicates the accessibility type specified by + * AccessibilityAbilityInfo#ACCESSIBILITY_ABILITY_TYPE_SPOKEN. + * @param stateType Indicates the accessibility ability status. 1 indicates that the ability is enabled; + * 2 indicates that the ability is disabled; 4 indicates that the ability has been installed. + * @return + */ + virtual std::vector GetAbilityList(const int abilityTypes, const int stateType) override; + + /** + * @brief Register the interaction operation, so the AA can get node info from ACE. + * @param windowId Window ID + * @param operation The callback object. + * @param accountId User ID + * @return 0: Succeed ; otherwise is failed. + */ + virtual void RegisterInteractionOperation(const int windowId, + const sptr &operation, + const int accountId) override; + + /** + * @brief Deregister the interaction operation. + * @param windowId Window ID + * @return + */ + virtual void DeregisterInteractionOperation(const int windowId) override; + + /** + * @brief Requests feedback interruption from all accessibility services. + * Remained. + * @param - + * @return + */ + virtual void Interrupt(const int accountId) override; + + /** + * @brief Obtains the suggested interval for switching the UI. + * @param + * @return Returns the interval. + */ + virtual uint64_t GetSuggestedInterval() override; + + /** + * @brief Register AA connection to AAMS. + * Temp Solution. + * @param obj IPC object + * @return + */ + virtual void RegisterAbilityConnectionClientTmp(const sptr& obj) override; + + /** + * @brief Get IPC object. + * @param + * @return IPC object + */ + sptr GetObject(); +private: + /** + * @brief Write the descriptor of IPC. + * @param data It is include the descriptor of IPC. + * @return true: Write the descriptor successfully; otherwise is not. + */ + bool WriteInterfaceToken(MessageParcel &data); + static inline BrokerDelegator delegator; +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessible_ability_manager_service_state_interface.h b/frameworks/asacfwk/include/accessible_ability_manager_service_state_interface.h new file mode 100644 index 00000000..fffd13b9 --- /dev/null +++ b/frameworks/asacfwk/include/accessible_ability_manager_service_state_interface.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_SYSTEM_CLIENT_H +#define ACCESSIBILITY_SYSTEM_CLIENT_H + +#include + +#include "iremote_broker.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Accessibility { +class IAccessibleAbilityManagerServiceState: public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.accessibility.IAccessibleAbilityManagerServiceState"); + + /** + * @brief Receive the state notify from AAMS and send it to the observer registed.. + * @param stateType The state type and value. + * state type: Refer to AccessibilityStateEventType. + * value: STATE_ACCESSIBILITY_ENABLED/STATE_EXPLORATION_ENABLED/ + * STATE_ACCESSIBILITY_DISABLED/STATE_EXPLORATION_DISABLED + * @return + */ + virtual void OnStateChanged(const uint32_t stateType) = 0; + + enum class Message { + ON_STATE_CHANGED, + }; +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessible_ability_manager_service_state_proxy.h b/frameworks/asacfwk/include/accessible_ability_manager_service_state_proxy.h new file mode 100644 index 00000000..b12ae880 --- /dev/null +++ b/frameworks/asacfwk/include/accessible_ability_manager_service_state_proxy.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_SYSTEM_CLIENT_PROXY_H +#define ACCESSIBILITY_SYSTEM_CLIENT_PROXY_H + +#include + +#include "accessible_ability_manager_service_state_interface.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace Accessibility { +class AccessibleAbilityManagerServiceStateProxy : public IRemoteProxy { +public: + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + explicit AccessibleAbilityManagerServiceStateProxy(const sptr &object); + + /** + * @brief destruct function + * @param + * @return + */ + virtual ~AccessibleAbilityManagerServiceStateProxy() override; + + /** + * @brief Receive the state notify from AAMS and send it to the observer registed.. + * @param stateType The state type and value. + * state type: Refer to AccessibilityStateEventType. + * value: STATE_ACCESSIBILITY_ENABLED/STATE_EXPLORATION_ENABLED/ + * STATE_ACCESSIBILITY_DISABLED/STATE_EXPLORATION_DISABLED + * @return + */ + virtual void OnStateChanged(const uint32_t stateType) override; +private: + /** + * @brief Write the descriptor of IPC. + * @param data It is include the descriptor of IPC. + * @return true: Write the descriptor successfully; otherwise is not. + */ + bool WriteInterfaceToken(MessageParcel &data); + static inline BrokerDelegator delegator; +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/accessible_ability_manager_service_state_stub.h b/frameworks/asacfwk/include/accessible_ability_manager_service_state_stub.h new file mode 100644 index 00000000..7b274947 --- /dev/null +++ b/frameworks/asacfwk/include/accessible_ability_manager_service_state_stub.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ABILITY_MANAGER_SERVICE_STATE_STUB_H +#define ACCESSIBILITY_ABILITY_MANAGER_SERVICE_STATE_STUB_H + +#include +#include + +#include "accessible_ability_manager_service_state_interface.h" +#include "accessibility_errorcode.h" +#include "iremote_stub.h" +#include "nocopyable.h" + +namespace OHOS { +namespace Accessibility { +class AccessibleAbilityManagerServiceStateStub : public IRemoteStub { +public: + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + AccessibleAbilityManagerServiceStateStub(); + + /** + * @brief destruct function + * @param + * @return + */ + virtual ~AccessibleAbilityManagerServiceStateStub() = default; + + /** + * @brief Receive the event from proxy by IPC mechanism. + * @param code The code is matched with the process function. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @param option The option paramter of IPC,such as: async,sync + * @return + */ + int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; + + /** + * @brief Receive the state notify from AAMS and send it to the observer registed.. + * @param stateType The state type and value. + * state type: Refer to AccessibilityStateEventType. + * value: STATE_ACCESSIBILITY_ENABLED/STATE_EXPLORATION_ENABLED/ + * STATE_ACCESSIBILITY_DISABLED/STATE_EXPLORATION_DISABLED + * @return + */ + void OnStateChanged(const uint32_t stateType) override; +private: + /** + * @brief Handle the IPC request for the function:HandleOnStateChanged. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleOnStateChanged(MessageParcel &data, MessageParcel &reply); + + DISALLOW_COPY_AND_MOVE(AccessibleAbilityManagerServiceStateStub); +}; + +} //namespace Accessibility +} //namespace OHOS +#endif diff --git a/frameworks/asacfwk/include/accessible_ability_manager_service_stub.h b/frameworks/asacfwk/include/accessible_ability_manager_service_stub.h new file mode 100644 index 00000000..83b25dd9 --- /dev/null +++ b/frameworks/asacfwk/include/accessible_ability_manager_service_stub.h @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ABILITY_MANAGER_SERVICE_CLIENT_STUB_H +#define ACCESSIBILITY_ABILITY_MANAGER_SERVICE_CLIENT_STUB_H + +#include +#include "accessibility_ability_info.h" +#include "accessible_ability_manager_service_state_interface.h" +#include "accessible_ability_manager_service_interface.h" +#include "accessibility_event_info.h" +#include "accessibility_errorcode.h" +#include "iremote_object.h" +#include "iremote_stub.h" +#include "nocopyable.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class define the interface to call ABMS API. +*/ +class AccessibleAbilityManagerServiceClientStub : public IRemoteStub { +public: + /** + * @brief construct function + * @param object The object of IPC + * @return + */ + AccessibleAbilityManagerServiceClientStub(); + + /** + * @brief destruct function + * @param + * @return + */ + virtual ~AccessibleAbilityManagerServiceClientStub(); + + /** + * @brief Receive the event from proxy by IPC mechanism. + * @param code The code is matched with the process function. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @param option The option paramter of IPC,such as: async,sync + * @return + */ + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) override; +private: + /** + * @brief Handle the IPC request for the function:HandleSendEvent. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleSendEvent(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleRegisterStateCallback. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleRegisterStateCallback(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleGetAbilityList. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleGetAbilityList(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleRegisterAccessibilityInteractionOperation. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleRegisterAccessibilityInteractionOperation(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleDeregisterAccessibilityInteractionOperation. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleDeregisterAccessibilityInteractionOperation(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleInterrupt. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleInterrupt(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleGetSuggestedInterval. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleGetSuggestedInterval(MessageParcel &data, MessageParcel &reply); + + /** + * @brief Handle the IPC request for the function:HandleRegisterAbilityConnectionClientTmp. + * @param data The data of prcess communication + * @param reply The response of IPC request + * @return NO_ERROR: successful; otherwise is failed. + */ + ErrCode HandleRegisterAbilityConnectionClientTmp(MessageParcel &data, MessageParcel &reply); + + using AccessibilityAbilityManagerServiceFunc = ErrCode (AccessibleAbilityManagerServiceClientStub::*) + (MessageParcel &data, MessageParcel &reply); + std::map memberFuncMap_; + + DISALLOW_COPY_AND_MOVE(AccessibleAbilityManagerServiceClientStub); +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/asacfwk/include/gesture_simulation.h b/frameworks/asacfwk/include/gesture_simulation.h new file mode 100644 index 00000000..50ccafd5 --- /dev/null +++ b/frameworks/asacfwk/include/gesture_simulation.h @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef GESTURE_SIMULATION_H +#define GESTURE_SIMULATION_H + +#include +#include +#include "parcel_util.h" + +namespace OHOS { +namespace Accessibility { + +class GesturePathPositionDefine : public Parcelable +{ +public: + GesturePathPositionDefine() {} + ~GesturePathPositionDefine() {} + + GesturePathPositionDefine(float positionX, float positionY); + + /** + * @brief Obtains the X coordinate of the position. + * @param + * @return Return the X coordinate of the position. + */ + float GetPositionX(); + + /** + * @brief Obtains the Y coordinate of the position. + * @param + * @return Return the Y coordinate of the position. + */ + float GetPositionY(); + + /** + * @brief Sets the X coordinate of the position. + * @param positionX The X coordinate of the position. + * @return + */ + void SetPositionX(float positionX); + + /** + * @brief Sets the Y coordinate of the position. + * @param positionX The Y coordinate of the position. + * @return + */ + void SetPositionY(float positionY); + + /** + * @brief read this sequenceable object from a Parcel. + * @param parcel Indicates the Parcel object into which the sequenceable object has been marshaled. + * @return Return true if read successfully, else return false. + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Marshals this sequenceable object into a Parcel. + * @param parcel Indicates the Parcel object to which the sequenceable object will be marshaled. + * @return Return true if Marshal successfully, else return false. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshals this sequenceable object from a Parcel. + * @param parcel Indicates the Parcel object into which the sequenceable object has been marshaled. + * @return Return a sequenceable object of GesturePathPositionDefine. + */ + static GesturePathPositionDefine *Unmarshalling(Parcel &parcel); + +private: + float positionX_ = 0; + float positionY_ = 0; +}; + +class GesturePathDefine : public Parcelable +{ +public: + GesturePathDefine() {} + ~GesturePathDefine() {} + + GesturePathDefine(GesturePathPositionDefine &startPosition, + GesturePathPositionDefine &endPosition, uint32_t durationTime); + + /** + * @brief Obtains the duration for completing the maximum number of gesture strokes. + * @param + * @return Return the duration for completing the maximum number of gesture strokes. + */ + static uint32_t GetMaxStrokeDuration(); + + /** + * @brief Obtains the maximum number of strokes in this gesture path. + * @param + * @return Return the maximum number of strokes in this gesture path. + */ + static uint32_t GetMaxStrokes(); + + /** + * @brief Obtains the duration in which this gesture path continues. + * @param + * @return Return the duration in which this gesture path continues. + */ + uint32_t GetDurationTime(); + + /** + * @brief Obtains the end position of this gesture path. + * @param + * @return Return the end position of this gesture path. + */ + GesturePathPositionDefine &GetEndPosition(); + + /** + * @brief Obtains the start position of this gesture path. + * @param + * @return Return the start position of this gesture path. + */ + GesturePathPositionDefine &GetStartPosition(); + + /** + * @brief Sets the duration for this gesture path to continue. + * @param durationTime The duration for this gesture path to continue. + * @return + */ + void SetDurationTime(uint32_t durationTime); + + /** + * @brief Sets the end position of this gesture path. + * @param endPosition The end position of this gesture path. + * @return + */ + void SetEndPosition(GesturePathPositionDefine &endPosition); + + /** + * @brief Sets the start position of this gesture path. + * @param startPosition The start position of this gesture path. + * @return + */ + void SetStartPosition(GesturePathPositionDefine &startPosition); + + /** + * @brief read this sequenceable object from a Parcel. + * @param parcel Indicates the Parcel object into which the sequenceable object has been marshaled. + * @return Return true if read successfully, else return false. + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Marshals this sequenceable object into a Parcel. + * @param parcel Indicates the Parcel object to which the sequenceable object will be marshaled. + * @return Return true if Marshal successfully, else return false. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshals this sequenceable object from a Parcel. + * @param parcel Indicates the Parcel object into which the sequenceable object has been marshaled. + * @return Return a sequenceable object of GesturePathDefine. + */ + static GesturePathDefine *Unmarshalling(Parcel &parcel); + +private: + const static uint32_t MAX_STROKE_DURATION = 60 * 1000; + const static uint32_t MAX_STROKES = 10; + + GesturePathPositionDefine startPosition_; + GesturePathPositionDefine endPosition_; + uint32_t durationTime_ = 0; +}; + +class GestureResultListener +{ +public: + + /** + * @brief Called when the gesture is cancelled. + * @param gesturePathDefine The gesture which will be notified to listener. + * @return + */ + virtual void OnCancelled(std::vector &gesturePathDefine) = 0; + + /** + * @brief Called when the gesture is completed. + * @param gesturePathDefine The gesture which will be notified to listener. + * @return + */ + virtual void OnCompleted(std::vector &gesturePathDefine) = 0; +}; + +class GestureResultListenerInfo +{ +public: + GestureResultListenerInfo(std::vector gesturePathDefine, + std::shared_ptr& gestureResultListener); + + /** + * @brief Obtains the listener observing gestures sent to the screen. + * @param + * @return Return the listener observing gestures sent to the screen. + */ + std::shared_ptr& GetGestureResultListener(); + + /** + * @brief Obtains GesturePath of this listenerInfo. + * @param + * @return Return GesturePath of this listenerInfo. + */ + std::vector GetGesturePathDefine(); + +private: + std::vector gesturePathDefine_ {}; + std::shared_ptr gestureResultListener_ = nullptr; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // GESTURE_SIMULATION_H \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessibility_ability_info.cpp b/frameworks/asacfwk/src/accessibility_ability_info.cpp new file mode 100644 index 00000000..489d794f --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_ability_info.cpp @@ -0,0 +1,265 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_ability_info.h" +#include "dummy.h" +#include "hilog_wrapper.h" +#include "parcel_util.h" +#include "json_utils.h" + +using namespace std; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace Accessibility { + +AccessibilityAbilityInfo::AccessibilityAbilityInfo(AbilityInfo abilityInfo) +{ + HILOG_DEBUG("%{public}s start.", __func__); + abilityInfo_ = abilityInfo; + +#if 0 + // dummy data for test. It's temporary. + AccessibilityAbilityInfoDummy accessibilityAbilityInfoDummydata; + capabilities_ = accessibilityAbilityInfoDummydata.capabilities; + abilityTypes_ = accessibilityAbilityInfoDummydata.accessibilityAbilityTypes; + eventTypes_ = accessibilityAbilityInfoDummydata.accessibilityEventTypes; + notificationTimeout_ = accessibilityAbilityInfoDummydata.notificationTimeout; + uiInteractiveTimeout_ = accessibilityAbilityInfoDummydata.uiInteractiveTime; + uiNoninteractiveTimeout_ = accessibilityAbilityInfoDummydata.uiNoninteractiveTime; + targetBundleNames_ = accessibilityAbilityInfoDummydata.filterBundleNames; + description_ = accessibilityAbilityInfoDummydata.description; + settingsAbility_ = accessibilityAbilityInfoDummydata.settingsAbility; + +#else + + if (!ParseAAConfig()) { + HILOG_ERROR("Parse AccessibilityAbility config file failed."); + } + +#endif // 0 +} + +bool AccessibilityAbilityInfo::ParseAAConfig() +{ + HILOG_DEBUG("%{public}s start.", __func__); + + nlohmann::json sourceJson; + if (!JsonUtils::GetJsonObjFromJson(sourceJson, AccessibleAbility_JSON_FILE_PATH)) { + HILOG_ERROR("Get JsonObj from json failed."); + return false; + } + + vector eventTypes; + if (!JsonUtils::GetStringVecFromJson(sourceJson, AccessibleAbility_JSON_KEY_ACCESSIBILITY_EVENT_TYPES, + eventTypes)) { + HILOG_ERROR("Get stringVec from json failed."); + return false; + } + PraseVecUtils::ParseEventTypesFromVec(eventTypes, eventTypes_); + + if (!JsonUtils::GetStringVecFromJson(sourceJson, AccessibleAbility_JSON_KEY_TARGET_BUNDLE_NAMES, + targetBundleNames_)) { + HILOG_ERROR("Get stringVec from json failed."); + return false; + } + + vector abilityType; + if (!JsonUtils::GetStringVecFromJson(sourceJson, AccessibleAbility_JSON_KEY_ACCESSIBILITY_ABILITY_TYPES, + abilityType)) { + HILOG_ERROR("Get stringVec from json failed."); + return false; + } + PraseVecUtils::ParseAbilityTypesFromVec(abilityType, abilityTypes_); + + int notificationTimeout = -1; + if (!JsonUtils::GetIntFromJson(sourceJson, AccessibleAbility_JSON_KEY_NOTIFICATION_TIMEOUT, + notificationTimeout)) { + HILOG_ERROR("Get int from json failed."); + return false; + } + notificationTimeout_ = static_cast(notificationTimeout); + + int uiNoninteractiveTimeout = -1; + if (!JsonUtils::GetIntFromJson(sourceJson, AccessibleAbility_JSON_KEY_UI_NONINTERACTIVE_TIMEOUT, + uiNoninteractiveTimeout)) { + HILOG_ERROR("Get int from json failed."); + return false; + } + uiNoninteractiveTimeout_ = static_cast(uiNoninteractiveTimeout); + + int uiInteractiveTimeout = -1; + if (!JsonUtils::GetIntFromJson(sourceJson, AccessibleAbility_JSON_KEY_UI_INTERACTIVE_TIMEOUT, + uiInteractiveTimeout)) { + HILOG_ERROR("Get int from json failed."); + return false; + } + uiInteractiveTimeout_ = static_cast(uiInteractiveTimeout); + + vector capabilities; + if (!JsonUtils::GetStringVecFromJson(sourceJson, + AccessibleAbility_JSON_KEY_ACCESSIBILITY_CAPABILITIES, capabilities)) { + HILOG_ERROR("Get stringVec from json failed."); + return false; + } + PraseVecUtils::ParseCapabilitiesFromVec(capabilities, capabilities_); + + if (!JsonUtils::GetStringFromJson(sourceJson, AccessibleAbility_JSON_KEY_DESCRIPTION, description_)) { + HILOG_ERROR("Get string from json failed."); + return false; + } + + if (!JsonUtils::GetStringFromJson(sourceJson, AccessibleAbility_JSON_KEY_SETTINGS_ABILITY, settingsAbility_)) { + HILOG_ERROR("Get string from json failed."); + return false; + } + + return true; +} + +const AbilityInfo &AccessibilityAbilityInfo::GetAbilityInfo() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return abilityInfo_; +} + +uint32_t AccessibilityAbilityInfo::GetAccessibilityAbilityType() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return abilityTypes_; +} + +uint32_t AccessibilityAbilityInfo::GetCapabilityValues() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return capabilities_; +} + +string AccessibilityAbilityInfo::GetDescription() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return description_; +} + +uint32_t AccessibilityAbilityInfo::GetEventTypes() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return eventTypes_; +} + +string AccessibilityAbilityInfo::GetId() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return abilityInfo_.bundleName + "/" + abilityInfo_.name; +} + +string AccessibilityAbilityInfo::GetName() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return abilityInfo_.name; +} + +string AccessibilityAbilityInfo::GetPackageName() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return abilityInfo_.bundleName; +} + +vector AccessibilityAbilityInfo::GetFilterBundleNames() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return targetBundleNames_; +} + +std::string AccessibilityAbilityInfo::GetSettingsAbility() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return settingsAbility_; +} + +uint32_t AccessibilityAbilityInfo::GetNotificationTimeout() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return notificationTimeout_; +} + +uint32_t AccessibilityAbilityInfo::GetUiInteractiveTime() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return uiInteractiveTimeout_; +} + +uint32_t AccessibilityAbilityInfo::GetUiNoninteractiveTime() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return uiNoninteractiveTimeout_; +} + +bool AccessibilityAbilityInfo::ReadFromParcel(Parcel &parcel) +{ + HILOG_DEBUG("%{public}s start.", __func__); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, abilityTypes_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, capabilities_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, description_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, eventTypes_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, settingsAbility_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, notificationTimeout_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, uiInteractiveTimeout_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, uiNoninteractiveTimeout_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(StringVector, parcel, &targetBundleNames_); + + std::unique_ptr abilityInfo(parcel.ReadParcelable()); + if (!abilityInfo) { + HILOG_ERROR("ReadParcelable AbilityInfo failed."); + return false; + } + abilityInfo_ = *abilityInfo; + + return true; +} + +bool AccessibilityAbilityInfo::Marshalling(Parcel &parcel) const +{ + HILOG_DEBUG("%{public}s start.", __func__); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, abilityTypes_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, capabilities_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, description_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, eventTypes_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, settingsAbility_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, notificationTimeout_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, uiInteractiveTimeout_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, uiNoninteractiveTimeout_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(StringVector, parcel, targetBundleNames_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &abilityInfo_); + + return true; +} + +AccessibilityAbilityInfo *AccessibilityAbilityInfo::Unmarshalling(Parcel &parcel) +{ + HILOG_DEBUG("%{public}s start.", __func__); + AccessibilityAbilityInfo *accessibilityAbilityInfo = new AccessibilityAbilityInfo(); + + if (accessibilityAbilityInfo && !accessibilityAbilityInfo->ReadFromParcel(parcel)) { + HILOG_ERROR("ReadFromParcel AccessibilityAbilityInfo failed."); + delete accessibilityAbilityInfo; + accessibilityAbilityInfo = nullptr; + } + + return accessibilityAbilityInfo; +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessibility_element_info.cpp b/frameworks/asacfwk/src/accessibility_element_info.cpp new file mode 100644 index 00000000..2caf79c3 --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_element_info.cpp @@ -0,0 +1,1369 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_element_info.h" +#include "parcel_util.h" +#include "hilog_wrapper.h" +#include "accessibility_operator.h" + +namespace OHOS { +namespace Accessibility { + +/* AccessibilityElementInfo Parcel struct */ +bool AccessibilityElementInfo::ReadFromParcel(Parcel &parcel) { + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, elementId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, parentId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, bundleName_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, componentType_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, text_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, hintText_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, accessibilityText_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, accessibilityDescription_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, contentDescription_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, resourceName_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32Vector, parcel, &childNodeIds_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, childCount_); + int32_t operationsSize = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, operationsSize); + for (int i = 0; i < operationsSize; i++) { + std::shared_ptr accessibleOperation(parcel.ReadParcelable()); + if (!accessibleOperation) { + HILOG_ERROR("ReadParcelable failed"); + } + operations_.emplace_back(*accessibleOperation); + } + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, textLengthLimit_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, channelId_); + std::shared_ptr rect(parcel.ReadParcelable()); + if (!rect) { + return false; + } + bounds_ = *rect; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessibilityGroup_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, checkable_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, checked_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, focusable_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, focused_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, visible_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessibilityFocused_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, selected_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, clickable_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, longClickable_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, enable_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, password_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, scrollable_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, editable_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, popupSupported_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, multiLine_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, deletable_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, hint_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isEssential_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, currentIndex_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, beginIndex_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, endIndex_); + std::shared_ptr rangeInfo(parcel.ReadParcelable()); + if (!rangeInfo) { + return false; + } + rangeInfo_ = *rangeInfo; + std::shared_ptr grid(parcel.ReadParcelable()); + if (!grid) { + return false; + } + grid_ = *grid; + std::shared_ptr gridItem(parcel.ReadParcelable()); + if (!gridItem) { + return false; + } + gridItem_ = *gridItem; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, liveRegion_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, contentInvalid_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, error_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, labeled_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, beginSelected_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, endSelected_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, inputType_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, validElement_); + + return true; +} + +bool AccessibilityElementInfo::Marshalling(Parcel &parcel) const{ + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, elementId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, parentId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, bundleName_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, componentType_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, text_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, hintText_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, accessibilityText_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, accessibilityDescription_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, contentDescription_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, resourceName_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32Vector, parcel, childNodeIds_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, childCount_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, operations_.size()); + for (auto &operations : operations_) { + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &operations); + } + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, textLengthLimit_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, channelId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &bounds_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessibilityGroup_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, checkable_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, checked_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, focusable_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, focused_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, visible_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessibilityFocused_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, selected_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, clickable_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, longClickable_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, enable_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, password_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, scrollable_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, editable_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, popupSupported_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, multiLine_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, deletable_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, hint_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isEssential_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, currentIndex_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, beginIndex_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, endIndex_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &rangeInfo_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &grid_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &gridItem_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, liveRegion_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, contentInvalid_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, error_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, labeled_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, beginSelected_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, endSelected_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, inputType_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, validElement_); + return true; +}; + +AccessibilityElementInfo* AccessibilityElementInfo::Unmarshalling(Parcel& parcel) +{ + AccessibilityElementInfo *accessibilityInfo = new AccessibilityElementInfo(); + if (!accessibilityInfo->ReadFromParcel(parcel)) { + HILOG_ERROR("read from parcel failed"); + delete accessibilityInfo; + accessibilityInfo = nullptr; + } + return accessibilityInfo; +} + +void AccessibilityElementInfo::SetComponentId(const int componentId) +{ + elementId_ = componentId; + HILOG_DEBUG("[%{public}s] elementId_[%{public}d]", __func__, elementId_); +} + +bool AccessibilityElementInfo::GetFocus(const int focus, AccessibilityElementInfo &elementInfo) +{ + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], windowId_[%{public}d],\ + elementId_[%{public}d], focus[%{public}d]", + __func__, channelId_, windowId_, elementId_, focus); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + bool result = false; + if (instance != nullptr) { + result = instance->FindFocusedElementInfo(channelId_, windowId_, elementId_, focus, elementInfo); + } else { + HILOG_ERROR("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return result; +} + +bool AccessibilityElementInfo::GetNext(const FocusMoveDirection direction, AccessibilityElementInfo &elementInfo) +{ + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], windowId_[%{public}d],\ + elementId_[%{public}d], direction[%{public}d]", + __func__, channelId_, windowId_, elementId_, direction); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + bool result = false; + if (instance != nullptr) { + result = instance->FocusMoveSearch(channelId_, windowId_, elementId_, direction, elementInfo); + } else { + HILOG_ERROR("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return result; +} + +int AccessibilityElementInfo::GetChildId(const int index) const +{ + HILOG_DEBUG("[%{public}s] index[%{public}d]", __func__, index); + if (index >= childCount_ || index < 0) { + HILOG_ERROR("[%{public}s] called] index[%{public}d] is invalid", __func__, index); + return 0; + } + return childNodeIds_[index]; +} +int AccessibilityElementInfo::GetChildCount() const +{ + HILOG_DEBUG("[%{public}s] childCount_[%{public}d]", __func__, childCount_); + return childCount_; +} + +bool AccessibilityElementInfo::GetChild(const int index, AccessibilityElementInfo &elementInfo) +{ + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], windowId_[%{public}d],\ + elementId_[%{public}d], index[%{public}d]", + __func__, channelId_, windowId_, elementId_, index); + if (index >= childCount_ || index < 0) { + HILOG_ERROR("[%{public}s] called] index[%{public}d] is invalid", __func__, index); + return false; + } + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + bool result = false; + std::vector elementInfos {}; + if (instance != nullptr) { + result = instance->SearchElementInfosByAccessibilityId(channelId_, + windowId_, GetChildId(index), 0, elementInfos); + if (elementInfos.empty()) { + result = false; + } else { + elementInfo = elementInfos.front(); + } + } else { + HILOG_ERROR("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return result; +} + +std::vector AccessibilityElementInfo::GetChildIds() const +{ + HILOG_DEBUG("[%{public}s] childCount_[%{public}d]", __func__, childCount_); + return childNodeIds_; +} +void AccessibilityElementInfo::AddChild(const int childId) +{ + HILOG_DEBUG("[%{public}s] childId[%{public}d]", __func__, childId); + for (int i = 0; i < childCount_; i++) { + if (childNodeIds_[i] == childId) { + HILOG_ERROR("[%{public}s] childId[%{public}d] is exited", __func__, childId); + return; + } + } + childCount_++; + childNodeIds_.push_back(childId); + HILOG_DEBUG("[%{public}s] childId[%{public}d] end", __func__, childId); +} + +bool AccessibilityElementInfo::RemoveChild(const int childId) +{ + HILOG_DEBUG("[%{public}s] childId[%{public}d]", __func__, childId); + for (auto iter = childNodeIds_.begin(); iter != childNodeIds_.end(); iter++) { + if (*iter == childId) { + iter = childNodeIds_.erase(iter); + childCount_--; + return true; + } + } + HILOG_ERROR("[%{public}s] Not find childId[%{public}d]", __func__, childId); + return false; +} + +std::vector AccessibilityElementInfo::GetActionList() const +{ + HILOG_DEBUG("[%{public}s]", __func__); + return operations_; +} + +void AccessibilityElementInfo::AddAction(AccessibleAction &action) +{ + HILOG_DEBUG("[%{public}s]", __func__); + operations_.push_back(action); + HILOG_DEBUG("[%{public}s] actionType[%{public}d] end", __func__, action.GetActionType()); +} + +void AccessibilityElementInfo::DeleteAction(AccessibleAction &action) +{ + HILOG_DEBUG("[%{public}s]", __func__); + for (auto iter = operations_.begin(); iter != operations_.end(); iter++) { + HILOG_DEBUG("[%{public}s] actionType[%{public}d]", __func__, action.GetActionType()); + if (iter->GetActionType() == action.GetActionType()) { + iter = operations_.erase(iter); + return; + } + } + HILOG_ERROR("[%{public}s] Not find actionType[%{public}d]", __func__, action.GetActionType()); +} + +bool AccessibilityElementInfo::DeleteAction(ActionType &actionType) +{ + HILOG_DEBUG("[%{public}s]", __func__); + for (auto iter = operations_.begin(); iter != operations_.end(); iter++) { + HILOG_DEBUG("[%{public}s] actionType[%{public}d]", __func__, actionType); + if (iter->GetActionType() == actionType) { + iter = operations_.erase(iter); + return true; + } + } + HILOG_ERROR("[%{public}s] Not find actionType[%{public}d]", __func__, actionType); + return false; +} + +void AccessibilityElementInfo::DeleteAllActions() +{ + HILOG_DEBUG("[%{public}s]", __func__); + operations_.clear(); +} + +void AccessibilityElementInfo::SetTextLengthLimit(const int max) +{ + textLengthLimit_ = max; + HILOG_DEBUG("[%{public}s] textLengthLimit_[%{public}d]", __func__, textLengthLimit_); +} + +int AccessibilityElementInfo::GetTextLengthLimit() const +{ + HILOG_DEBUG("[%{public}s] textLengthLimit_[%{public}d]", __func__, textLengthLimit_); + return textLengthLimit_; +} + +bool AccessibilityElementInfo::ExecuteAction(const ActionType &action, + const std::map &actionArguments) +{ + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], windowId_[%{public}d], elementId_[%{public}d]", + __func__, channelId_, windowId_, elementId_); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + if (instance != nullptr) { + return instance->PerformAction(channelId_, + windowId_, elementId_, action, + const_cast &>(actionArguments)); + } else { + HILOG_INFO("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + return false; + } +} + +bool AccessibilityElementInfo::GetByContent(const std::string &text, + std::vector &elementInfos) +{ + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], windowId_[%{public}d],\ + elementId_[%{public}d], text[%{public}s]", + __func__, channelId_, windowId_, elementId_, text.c_str()); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + bool result = false; + if (instance != nullptr) { + result = instance->SearchElementInfosByText(channelId_, windowId_, elementId_, text, elementInfos); + } else { + HILOG_INFO("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return result; +} + +bool AccessibilityElementInfo::GetElementInfosById(const int elementId, int mode, + std::vector &elementInfos) +{ + HILOG_DEBUG("[%{public}s]", __func__); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + bool result = false; + if (instance != nullptr) { + result = instance->SearchElementInfosByAccessibilityId(channelId_, + windowId_, elementId, mode, elementInfos); + } else { + HILOG_INFO("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + + return result; +} + +int AccessibilityElementInfo::GetWindowId() const +{ + HILOG_DEBUG("[%{public}s] windowId_[%{public}d]", __func__, windowId_); + return windowId_; +} + +void AccessibilityElementInfo::SetWindowId(const int windowId) +{ + windowId_ = windowId; + HILOG_DEBUG("[%{public}s] windowId_[%{public}d]", __func__, windowId_); +} + +bool AccessibilityElementInfo::GetParent(AccessibilityElementInfo &elementInfo) +{ + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], windowId_[%{public}d], parentId_[%{public}d]", + __func__, channelId_, windowId_, parentId_); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + std::vector elementInfos {}; + bool result = false; + if (instance != nullptr) { + result = instance->SearchElementInfosByAccessibilityId(channelId_, + windowId_, parentId_, 0, elementInfos); + if (elementInfos.empty()) { + result = false; + } else { + elementInfo = elementInfos.front(); + } + } else { + HILOG_INFO("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return result; +} + +int AccessibilityElementInfo::GetParentNodeId() const +{ + HILOG_DEBUG("[%{public}s] parentId_[%{public}d]", __func__, parentId_); + return parentId_; +} + +void AccessibilityElementInfo::SetParent(const int parentId) +{ + parentId_ = parentId; + HILOG_DEBUG("[%{public}s] parentId_[%{public}d]", __func__, parentId_); +} +Rect AccessibilityElementInfo::GetRectInScreen() const +{ + HILOG_DEBUG("[%{public}s]", __func__); + return bounds_; +} + +void AccessibilityElementInfo::SetRectInScreen(Rect &bounds) +{ + HILOG_DEBUG("[%{public}s]", __func__); + bounds_.SetLeftTopScreenPostion(bounds.GetLeftTopXScreenPostion(), bounds.GetLeftTopYScreenPostion()); + bounds_.SetRightBottomScreenPostion(bounds.GetRightBottomXScreenPostion(), bounds.GetRightBottomYScreenPostion()); +} + +bool AccessibilityElementInfo::IsCheckable() const +{ + HILOG_DEBUG("[%{public}s] checkable_[%{public}d]", __func__, checkable_); + return checkable_; +} + +void AccessibilityElementInfo::SetCheckable(const bool checkable) +{ + checkable_ = checkable; + HILOG_DEBUG("[%{public}s] checkable_[%{public}d]", __func__, checkable_); +} + +bool AccessibilityElementInfo::IsChecked() const +{ + HILOG_DEBUG("[%{public}s] checked_[%{public}d]", __func__, checked_); + return checked_; +} + +void AccessibilityElementInfo::SetChecked(const bool checked) +{ + checked_ = checked; + HILOG_DEBUG("[%{public}s] checked_[%{public}d]", __func__, checked_); +} + +bool AccessibilityElementInfo::IsFocusable() const +{ + HILOG_DEBUG("[%{public}s] focusable_[%{public}d]", __func__, focusable_); + return focusable_; +} + +void AccessibilityElementInfo::SetFocusable(const bool focusable) +{ + focusable_ = focusable; + HILOG_DEBUG("[%{public}s] focusable_[%{public}d]", __func__, focusable_); +} + +bool AccessibilityElementInfo::IsFocused() +{ + HILOG_DEBUG("[%{public}s] focused_[%{public}d]", __func__, focused_); + return focused_; +} + +void AccessibilityElementInfo::SetFocused(const bool focused) +{ + focused_ = focused; + HILOG_DEBUG("[%{public}s] focused_[%{public}d]", __func__, focused_); +} + +bool AccessibilityElementInfo::IsVisible() const +{ + HILOG_DEBUG("[%{public}s] visible_[%{public}d]", __func__, visible_); + return visible_; +} + +void AccessibilityElementInfo::SetVisible(const bool visible) +{ + visible_ = visible; + HILOG_DEBUG("[%{public}s] visible_[%{public}d]", __func__, visible_); +} + +bool AccessibilityElementInfo::HasAccessibilityFocus() const +{ + HILOG_DEBUG("[%{public}s] accessibilityFocused_[%{public}d]", __func__, accessibilityFocused_); + return accessibilityFocused_; +} + +void AccessibilityElementInfo::SetAccessibilityFocus(const bool focused) +{ + accessibilityFocused_ = focused; + HILOG_DEBUG("[%{public}s] accessibilityFocused_[%{public}d]", __func__, accessibilityFocused_); +} + +bool AccessibilityElementInfo::IsSelected() const +{ + HILOG_DEBUG("[%{public}s] selected_[%{public}d]", __func__, selected_); + return selected_; +} + +void AccessibilityElementInfo::SetSelected(const bool selected) +{ + selected_ = selected; + HILOG_DEBUG("[%{public}s] selected_[%{public}d]", __func__, selected_); +} + +bool AccessibilityElementInfo::IsClickable() const +{ + HILOG_DEBUG("[%{public}s] clickable_[%{public}d]", __func__, clickable_); + return clickable_; +} + +void AccessibilityElementInfo::SetClickable(const bool clickable) +{ + clickable_ = clickable; + HILOG_DEBUG("[%{public}s] clickable_[%{public}d]", __func__, clickable_); +} + +bool AccessibilityElementInfo::IsLongClickable() const +{ + HILOG_DEBUG("[%{public}s] longClickable_[%{public}d]", __func__, longClickable_); + return longClickable_; +} + +void AccessibilityElementInfo::SetLongClickable(const bool longClickable) +{ + longClickable_ = longClickable; + HILOG_DEBUG("[%{public}s] longClickable_[%{public}d]", __func__, longClickable_); +} + +bool AccessibilityElementInfo::IsEnabled() const +{ + HILOG_DEBUG("[%{public}s] enable_[%{public}d]", __func__, enable_); + return enable_; +} + +void AccessibilityElementInfo::SetEnabled(const bool enabled) +{ + enable_ = enabled; + HILOG_DEBUG("[%{public}s] enable_[%{public}d]", __func__, enable_); +} + +bool AccessibilityElementInfo::IsPassword() const +{ + HILOG_DEBUG("[%{public}s] password_[%{public}d]", __func__, password_); + return password_; +} + +void AccessibilityElementInfo::SetPassword(const bool password) +{ + password_ = password; + HILOG_DEBUG("[%{public}s] password_[%{public}d]", __func__, password_); +} + +bool AccessibilityElementInfo::IsScrollable() const +{ + HILOG_DEBUG("[%{public}s] scrollable_[%{public}d]", __func__, scrollable_); + return scrollable_; +} + +void AccessibilityElementInfo::SetScrollable(const bool scrollable) +{ + scrollable_ = scrollable; + HILOG_DEBUG("[%{public}s] scrollable_[%{public}d]", __func__, scrollable_); +} + +int AccessibilityElementInfo::GetCurrentIndex() const +{ + HILOG_DEBUG("[%{public}s] currentIndex_[%{public}d]", __func__, currentIndex_); + return currentIndex_; +} + +void AccessibilityElementInfo::SetCurrentIndex(const int index) +{ + currentIndex_ = index; + HILOG_DEBUG("[%{public}s] currentIndex_[%{public}d]", __func__, currentIndex_); +} + +int AccessibilityElementInfo::GetBeginIndex() const +{ + HILOG_DEBUG("[%{public}s] beginIndex_[%{public}d]", __func__, beginIndex_); + return beginIndex_; +} + +void AccessibilityElementInfo::SetBeginIndex(const int index) +{ + beginIndex_ = index; + HILOG_DEBUG("[%{public}s] beginIndex_[%{public}d]", __func__, beginIndex_); +} + +int AccessibilityElementInfo::GetEndIndex() const +{ + HILOG_DEBUG("[%{public}s] endIndex_[%{public}d]", __func__, endIndex_); + return endIndex_; +} + +void AccessibilityElementInfo::SetEndIndex(const int index) +{ + endIndex_ = index; + HILOG_DEBUG("[%{public}s] endIndex_[%{public}d]", __func__, endIndex_); +} + +int AccessibilityElementInfo::GetInputType() const +{ + HILOG_DEBUG("[%{public}s] inputType_[%{public}d]", __func__, inputType_); + return inputType_; +} + +void AccessibilityElementInfo::SetInputType(const int inputType) +{ + inputType_ = inputType; + HILOG_DEBUG("[%{public}s] inputType_[%{public}d]", __func__, inputType_); +} + +void AccessibilityElementInfo::SetValidElement(const bool valid) +{ + HILOG_DEBUG("[%{public}s] validElevalidment_[%{public}d]", __func__, valid); + validElement_ = valid; +} + +bool AccessibilityElementInfo::IsValidElement() const +{ + HILOG_DEBUG("[%{public}s] validElement_[%{public}d]", __func__, validElement_); + return validElement_; +} + +bool AccessibilityElementInfo::IsEditable() const +{ + HILOG_DEBUG("[%{public}s] editable_[%{public}d]", __func__, editable_); + return editable_; +} + +void AccessibilityElementInfo::SetEditable(const bool editable) +{ + editable_ = editable; + HILOG_DEBUG("[%{public}s] editable_[%{public}d]", __func__, editable_); +} + +bool AccessibilityElementInfo::IsPluraLineSupported() const +{ + HILOG_DEBUG("[%{public}s] multiLine_[%{public}d]", __func__, multiLine_); + return multiLine_; +} + +void AccessibilityElementInfo::SetPluraLineSupported(const bool multiLine) +{ + multiLine_ = multiLine; + HILOG_DEBUG("[%{public}s] multiLine_[%{public}d]", __func__, multiLine_); +} + +bool AccessibilityElementInfo::IsPopupSupported() const +{ + HILOG_DEBUG("[%{public}s] popupSupported_[%{public}d]", __func__, popupSupported_); + return popupSupported_; +} + +void AccessibilityElementInfo::SetPopupSupported(const bool supportPopup) +{ + popupSupported_ = supportPopup; + HILOG_DEBUG("[%{public}s] popupSupported_[%{public}d]", __func__, popupSupported_); +} + +bool AccessibilityElementInfo::IsDeletable() const +{ + HILOG_DEBUG("[%{public}s] deletable_[%{public}d]", __func__, deletable_); + return deletable_; +} + +void AccessibilityElementInfo::SetDeletable(const bool deletable) +{ + deletable_ = deletable; + HILOG_DEBUG("[%{public}s] deletable_[%{public}d]", __func__, deletable_); +} + +bool AccessibilityElementInfo::IsEssential() const +{ + HILOG_DEBUG("[%{public}s] isEssential_[%{public}d]", __func__, isEssential_); + return isEssential_; +} + +void AccessibilityElementInfo::SetEssential(const bool essential) +{ + isEssential_ = essential; + HILOG_DEBUG("[%{public}s] isEssential_[%{public}d]", __func__, isEssential_); +} + +bool AccessibilityElementInfo::IsGivingHint() const +{ + HILOG_DEBUG("[%{public}s] hint_[%{public}d]", __func__, hint_); + return hint_; +} +void AccessibilityElementInfo::SetHinting(const bool hinting) +{ + hint_ = hinting; + HILOG_DEBUG("[%{public}s] hint_[%{public}d]", __func__, hint_); +} + +std::string AccessibilityElementInfo::GetBundleName() const +{ + HILOG_DEBUG("[%{public}s] bundleName_[%{public}s]", __func__, bundleName_.c_str()); + return bundleName_; +} + +void AccessibilityElementInfo::SetBundleName(const std::string &bundleName) +{ + bundleName_ = bundleName; + HILOG_DEBUG("[%{public}s] bundleName_[%{public}s]", __func__, bundleName_.c_str()); +} + +std::string AccessibilityElementInfo::GetComponentType() const +{ + HILOG_DEBUG("[%{public}s] componentType_[%{public}s]", __func__, componentType_.c_str()); + return componentType_; +} + +void AccessibilityElementInfo::SetComponentType(const std::string &className) +{ + componentType_ = className; + HILOG_DEBUG("[%{public}s] componentType_[%{public}s]", __func__, componentType_.c_str()); +} + +std::string AccessibilityElementInfo::GetContent() const +{ + HILOG_DEBUG("[%{public}s] text_[%{public}s]", __func__, text_.c_str()); + return text_; +} + +void AccessibilityElementInfo::SetContent(const std::string &text) +{ + text_ = text; + HILOG_DEBUG("[%{public}s] text_[%{public}s]", __func__, text_.c_str()); +} + +std::string AccessibilityElementInfo::GetAccessibilityContent() const +{ + HILOG_DEBUG("[%{public}s] accessibilityText_[%{public}s]", __func__, accessibilityText_.c_str()); + return accessibilityText_; +} + +void AccessibilityElementInfo::SetAccessibilityContent(const std::string &text) +{ + accessibilityText_ = text; + HILOG_DEBUG("[%{public}s] accessibilityText_[%{public}s]", __func__, accessibilityText_.c_str()); +} + +void AccessibilityElementInfo::SetSelectedBegin(const int start) +{ + beginSelected_ = start; + HILOG_DEBUG("[%{public}s] beginSelected_[%{public}d]", __func__, beginSelected_); +} + +int AccessibilityElementInfo::GetSelectedBegin() const +{ + HILOG_DEBUG("[%{public}s] beginSelected_[%{public}d]", __func__, beginSelected_); + return beginSelected_; +} + +void AccessibilityElementInfo::SetSelectedEnd(const int end) +{ + endSelected_ = end; + HILOG_DEBUG("[%{public}s] endSelected_[%{public}d]", __func__, endSelected_); +} + +int AccessibilityElementInfo::GetSelectedEnd() const +{ + HILOG_DEBUG("[%{public}s] endSelected_[%{public}d]", __func__, endSelected_); + return endSelected_; +} + +std::string AccessibilityElementInfo::GetAccessibilityDescription() const +{ + HILOG_DEBUG("[%{public}s] endSelected_[%{public}s]", __func__, accessibilityDescription_.c_str()); + return accessibilityDescription_; +} + +void AccessibilityElementInfo::SetAccessibilityDescription(const std::string &text) +{ + accessibilityDescription_ = text; + HILOG_DEBUG("[%{public}s] endSelected_[%{public}s]", __func__, accessibilityDescription_.c_str()); +} + +bool AccessibilityElementInfo::GetAccessibilityGroup() const +{ + HILOG_DEBUG("[%{public}s] accessibilityGroup_[%{public}d]", __func__, accessibilityGroup_); + return accessibilityGroup_; +} + +void AccessibilityElementInfo::SetAccessibilityGroup(const bool group) +{ + accessibilityGroup_ = group; + HILOG_DEBUG("[%{public}s] accessibilityGroup_[%{public}d]", __func__, accessibilityGroup_); +} + +std::string AccessibilityElementInfo::GetHint() const +{ + HILOG_DEBUG("[%{public}s] hintText_[%{public}s]", __func__, hintText_.c_str()); + return hintText_; +} + +void AccessibilityElementInfo::SetHint(const std::string &hintText) +{ + hintText_ = hintText; + HILOG_DEBUG("[%{public}s] hintText_[%{public}s]", __func__, hintText_.c_str()); +} + +std::string AccessibilityElementInfo::GetDescriptionInfo() const +{ + HILOG_DEBUG("[%{public}s] contentDescription_[%{public}s]", __func__, contentDescription_.c_str()); + return contentDescription_; +} + +void AccessibilityElementInfo::SetDescriptionInfo(const std::string contentDescription) +{ + contentDescription_ = contentDescription; + HILOG_DEBUG("[%{public}s] contentDescription_[%{public}s]", __func__, contentDescription_.c_str()); +} + +void AccessibilityElementInfo::SetComponentResourceId(const std::string &viewIdResName) +{ + resourceName_ = viewIdResName; + HILOG_DEBUG("[%{public}s] resourceName_[%{public}s]", __func__, resourceName_.c_str()); +} + +std::string AccessibilityElementInfo::GetComponentResourceId() const +{ + HILOG_DEBUG("[%{public}s] resourceName_[%{public}s]", __func__, resourceName_.c_str()); + return resourceName_; +} + +void AccessibilityElementInfo::SetLiveRegion(const int liveRegion) +{ + liveRegion_ = liveRegion; + HILOG_DEBUG("[%{public}s] liveRegion_[%{public}d]", __func__, liveRegion_); +} + +int AccessibilityElementInfo::GetLiveRegion() const +{ + HILOG_DEBUG("[%{public}s] liveRegion_[%{public}d]", __func__, liveRegion_); + return liveRegion_; +} + +void AccessibilityElementInfo::SetContentInvalid(const bool contentInvalid) +{ + contentInvalid_ = contentInvalid; + HILOG_DEBUG("[%{public}s] contentInvalid_[%{public}d]", __func__, contentInvalid_); +} + +bool AccessibilityElementInfo::GetContentInvalid() const +{ + HILOG_DEBUG("[%{public}s] contentInvalid_[%{public}d]", __func__, contentInvalid_); + return contentInvalid_; +} + +void AccessibilityElementInfo::SetError(const std::string &error) +{ + error_ = error; + HILOG_DEBUG("[%{public}s] error_[%{public}s]", __func__, error_.c_str()); +} + +std::string AccessibilityElementInfo::GetError() +{ + HILOG_DEBUG("[%{public}s] error_[%{public}s]", __func__, error_.c_str()); + return error_; +} + +void AccessibilityElementInfo::SetLabeled(const int componentId) +{ + labeled_ = componentId; + HILOG_DEBUG("[%{public}s] labeled_[%{public}d]", __func__, labeled_); +} + +bool AccessibilityElementInfo::GetLabeled(AccessibilityElementInfo &elementInfo) const +{ + HILOG_DEBUG("[%{public}s] labeled_[%{public}d]", __func__, labeled_); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + + std::vector elementInfos {}; + bool result = false; + if (instance != nullptr) { + result = instance->SearchElementInfosByAccessibilityId(channelId_, + windowId_, labeled_, 0, elementInfos); + if (elementInfos.empty()) { + result = false; + } else { + elementInfo = elementInfos.front(); + } + } else { + HILOG_INFO("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return result; +} + +int AccessibilityElementInfo::GetLabeledAccessibilityId() const +{ + HILOG_DEBUG("[%{public}s] labeled_[%{public}d]", __func__, labeled_); + return labeled_; +} + +int AccessibilityElementInfo::GetChannelId() const +{ + HILOG_DEBUG("[%{public}s] channelId_[%{public}d]", __func__, channelId_); + return channelId_; +} + +void AccessibilityElementInfo::SetChannelId(const int channelId) +{ + channelId_ = channelId; + HILOG_DEBUG("[%{public}s] channelId_[%{public}d]", __func__, channelId_); +} + +void AccessibilityElementInfo::SetAccessibilityId(const int componentId) +{ + elementId_ = componentId; + HILOG_DEBUG("[%{public}s] elementId_[%{public}d]", __func__, elementId_); +} + +int AccessibilityElementInfo::GetAccessibilityId() const +{ + HILOG_DEBUG("[%{public}s] elementId_[%{public}d]", __func__, elementId_); + return elementId_; +} + +RangeInfo AccessibilityElementInfo::GetRange() const +{ + HILOG_DEBUG("[%{public}s]", __func__); + return rangeInfo_; +} + +void AccessibilityElementInfo::SetRange(RangeInfo &rangeInfo) +{ + HILOG_DEBUG("[%{public}s]", __func__); + rangeInfo_.SetMax(rangeInfo.GetMax()); + rangeInfo_.SetMin(rangeInfo.GetMin()); + rangeInfo_.SetCurrent(rangeInfo.GetCurrent()); +} + +GridInfo AccessibilityElementInfo::GetGrid() const +{ + HILOG_DEBUG("[%{public}s]", __func__); + return grid_; +} + +void AccessibilityElementInfo::SetGrid(const GridInfo &grid) +{ + HILOG_DEBUG("[%{public}s]", __func__); + grid_ = grid; +} + +GridItemInfo AccessibilityElementInfo::GetGridItem() const +{ + HILOG_DEBUG("[%{public}s]", __func__); + return gridItem_; +} + +void AccessibilityElementInfo::SetGridItem(const GridItemInfo &gridItem) +{ + HILOG_DEBUG("[%{public}s]", __func__); + gridItem_ = gridItem; +} + +AccessibilityElementInfo::AccessibilityElementInfo() +{ + HILOG_DEBUG("[%{public}s]", __func__); +} + +bool AccessibleAction::ReadFromParcel(Parcel &parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + int type = ActionType::ACCESSIBILITY_ACTION_INVALID; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, type); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, description_); + actionType_ = ActionType(type); + return true; +} + +bool AccessibleAction::Marshalling(Parcel &parcel) const +{ + HILOG_DEBUG("[%{public}s]", __func__); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, int32_t(actionType_)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, description_); + + return true; +}; + +AccessibleAction* AccessibleAction::Unmarshalling(Parcel& parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + AccessibleAction* accessibleOperation = new AccessibleAction(); + if (!accessibleOperation->ReadFromParcel(parcel)) { + HILOG_ERROR("read from parcel failed"); + delete accessibleOperation; + accessibleOperation = nullptr; + } + return accessibleOperation; +} + +AccessibleAction::AccessibleAction(ActionType actionType, std::string description) +{ + HILOG_DEBUG("[%{public}s]", __func__); + actionType_ = actionType; + description_ = description; +} + +ActionType AccessibleAction::GetActionType() +{ + HILOG_DEBUG("[%{public}s] actionType_[%{public}d]", __func__, actionType_); + return actionType_; +} + +std::string AccessibleAction::GetDescriptionInfo() +{ + HILOG_DEBUG("[%{public}s] description_[%{public}s]", __func__, description_.c_str()); + return description_; +} + +bool RangeInfo::ReadFromParcel(Parcel &parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, min_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, max_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, current_); + + return true; +} + +bool RangeInfo::Marshalling(Parcel &parcel) const +{ + HILOG_DEBUG("[%{public}s]", __func__); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, min_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, max_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, current_); + + return true; +} + +RangeInfo* RangeInfo::Unmarshalling(Parcel& parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + RangeInfo* rangeInfo = new RangeInfo(); + if (!rangeInfo->ReadFromParcel(parcel)) { + HILOG_ERROR("read from parcel failed"); + delete rangeInfo; + rangeInfo = nullptr; + } + return rangeInfo; +} + +RangeInfo::RangeInfo(int min, int max, int current) +{ + HILOG_DEBUG("[%{public}s]", __func__); + min_ = min; + max_ = max; + current_ = current; + HILOG_DEBUG("[%{public}s] min_[%{public}d]", __func__, min_); + HILOG_DEBUG("[%{public}s] max_[%{public}d]", __func__, max_); + HILOG_DEBUG("[%{public}s] current_[%{public}d]", __func__, current_); +} + +int RangeInfo::GetMin() +{ + HILOG_DEBUG("[%{public}s] min_[%{public}d]", __func__, min_); + return min_; +} + +int RangeInfo::GetMax() +{ + HILOG_DEBUG("[%{public}s] max_[%{public}d]", __func__, max_); + return max_; +} + +int RangeInfo::GetCurrent() +{ + HILOG_DEBUG("[%{public}s] current_[%{public}d]", __func__, current_); + return current_; +} + +void RangeInfo::SetMin(int min) +{ + min_ = min; + HILOG_DEBUG("[%{public}s] min_[%{public}d]", __func__, min_); +} + +void RangeInfo::SetMax(int max) +{ + max_ = max; + HILOG_DEBUG("[%{public}s] max_[%{public}d]", __func__, max_); +} + +void RangeInfo::SetCurrent(int current) +{ + current_ = current; + HILOG_DEBUG("[%{public}s] current_[%{public}d]", __func__, current_); +} + +bool GridInfo::ReadFromParcel(Parcel &parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rowCount_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, columnCount_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, selectionMode_); + + return true; +} + +bool GridInfo::Marshalling(Parcel &parcel) const +{ + HILOG_DEBUG("[%{public}s]", __func__); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rowCount_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, columnCount_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, selectionMode_); + + return true; +}; + +GridInfo* GridInfo::Unmarshalling(Parcel& parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + GridInfo* grid = new GridInfo(); + if (!grid->ReadFromParcel(parcel)) { + HILOG_ERROR("read from parcel failed"); + delete grid; + grid = nullptr; + } + return grid; +} + +GridInfo::GridInfo(int rowCount, int columnCount, + int mode) +{ + HILOG_DEBUG("[%{public}s]", __func__); + rowCount_ = rowCount; + columnCount_ = columnCount; + selectionMode_ = mode; + + HILOG_DEBUG("[%{public}s] rowCount_[%{public}d]", __func__, rowCount_); + HILOG_DEBUG("[%{public}s] columnCount_[%{public}d]", __func__, columnCount_); + HILOG_DEBUG("[%{public}s] selectionMode_[%{public}d]", __func__, selectionMode_); +} + +void GridInfo::SetGrid(int rowCount, int columnCount, + int mode) +{ + HILOG_DEBUG("[%{public}s]", __func__); + rowCount_ = rowCount; + columnCount_ = columnCount; + selectionMode_ = mode; + + HILOG_DEBUG("[%{public}s] rowCount_[%{public}d]", __func__, rowCount_); + HILOG_DEBUG("[%{public}s] columnCount_[%{public}d]", __func__, columnCount_); + HILOG_DEBUG("[%{public}s] selectionMode_[%{public}d]", __func__, selectionMode_); +} + +void GridInfo::SetGrid(GridInfo other) +{ + HILOG_DEBUG("[%{public}s]", __func__); + rowCount_ = other.rowCount_; + columnCount_ = other.columnCount_; + selectionMode_ = other.selectionMode_; + + HILOG_DEBUG("[%{public}s] rowCount_[%{public}d]", __func__, rowCount_); + HILOG_DEBUG("[%{public}s] columnCount_[%{public}d]", __func__, columnCount_); + HILOG_DEBUG("[%{public}s] selectionMode_[%{public}d]", __func__, selectionMode_); +} + +int GridInfo::GetRowCount() +{ + HILOG_DEBUG("[%{public}s]", __func__); + HILOG_DEBUG("[%{public}s] rowCount_[%{public}d]", __func__, rowCount_); + return rowCount_; +} + +int GridInfo::GetColumnCount() +{ + HILOG_DEBUG("[%{public}s] columnCount_[%{public}d]", __func__, columnCount_); + return columnCount_; +} + +int GridInfo::GetSelectionMode() +{ + HILOG_DEBUG("[%{public}s] selectionMode_[%{public}d]", __func__, selectionMode_); + return selectionMode_; +} + +bool GridItemInfo::ReadFromParcel(Parcel &parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, heading_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, columnIndex_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rowIndex_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, columnSpan_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rowSpan_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, selected_); + + return true; +} + +bool GridItemInfo::Marshalling(Parcel &parcel) const +{ + HILOG_DEBUG("[%{public}s]", __func__); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, heading_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, columnIndex_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rowIndex_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, columnSpan_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rowSpan_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, selected_); + + return true; +}; + +GridItemInfo* GridItemInfo::Unmarshalling(Parcel& parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + GridItemInfo* gridItem = new GridItemInfo(); + if (!gridItem->ReadFromParcel(parcel)) { + HILOG_ERROR("read from parcel failed"); + delete gridItem; + gridItem = nullptr; + } + return gridItem; +} + +GridItemInfo::GridItemInfo(int rowIndex, int rowSpan, int columnIndex, int columnSpan, + bool heading, bool selected) +{ + HILOG_DEBUG("[%{public}s]", __func__); + rowIndex_ = rowIndex; + rowSpan_ = rowSpan; + columnIndex_ = columnIndex; + columnSpan_ = columnSpan; + heading_ = heading; + selected_ = selected; + + HILOG_DEBUG("[%{public}s] rowIndex_[%{public}d]", __func__, rowIndex_); + HILOG_DEBUG("[%{public}s] rowSpan_[%{public}d]", __func__, rowSpan_); + HILOG_DEBUG("[%{public}s] columnIndex_[%{public}d]", __func__, columnIndex_); + HILOG_DEBUG("[%{public}s] columnSpan_[%{public}d]", __func__, columnSpan_); + HILOG_DEBUG("[%{public}s] heading_[%{public}d]", __func__, heading_); + HILOG_DEBUG("[%{public}s] selected_[%{public}d]", __func__, selected_); +} + +void GridItemInfo::SetGridItemInfo(GridItemInfo other) +{ + HILOG_DEBUG("[%{public}s]", __func__); + rowIndex_ = other.rowIndex_; + rowSpan_ = other.rowSpan_; + columnIndex_ = other.columnIndex_; + columnSpan_ = other.columnSpan_; + heading_ = other.heading_; + selected_ = other.selected_; + + HILOG_DEBUG("[%{public}s] rowIndex_[%{public}d]", __func__, rowIndex_); + HILOG_DEBUG("[%{public}s] rowSpan_[%{public}d]", __func__, rowSpan_); + HILOG_DEBUG("[%{public}s] columnIndex_[%{public}d]", __func__, columnIndex_); + HILOG_DEBUG("[%{public}s] columnSpan_[%{public}d]", __func__, columnSpan_); + HILOG_DEBUG("[%{public}s] heading_[%{public}d]", __func__, heading_); + HILOG_DEBUG("[%{public}s] selected_[%{public}d]", __func__, selected_); +} + +void GridItemInfo::SetGridItemInfo(int rowIndex, int rowSpan, + int columnIndex, int columnSpan, bool heading, bool selected) +{ + HILOG_DEBUG("[%{public}s]", __func__); + rowIndex_ = rowIndex; + rowSpan_ = rowSpan; + columnIndex_ = columnIndex; + columnSpan_ = columnSpan; + heading_ = heading; + selected_ = selected; + + HILOG_DEBUG("[%{public}s] rowIndex_[%{public}d]", __func__, rowIndex_); + HILOG_DEBUG("[%{public}s] rowSpan_[%{public}d]", __func__, rowSpan_); + HILOG_DEBUG("[%{public}s] columnIndex_[%{public}d]", __func__, columnIndex_); + HILOG_DEBUG("[%{public}s] columnSpan_[%{public}d]", __func__, columnSpan_); + HILOG_DEBUG("[%{public}s] heading_[%{public}d]", __func__, heading_); + HILOG_DEBUG("[%{public}s] selected_[%{public}d]", __func__, selected_); +} + +int GridItemInfo::GetColumnIndex() +{ + HILOG_DEBUG("[%{public}s] columnIndex_[%{public}d]", __func__, columnIndex_); + return columnIndex_; +} + +int GridItemInfo::GetRowIndex() +{ + HILOG_DEBUG("[%{public}s] rowIndex_[%{public}d]", __func__, rowIndex_); + return rowIndex_; +} + +int GridItemInfo::GetColumnSpan() +{ + HILOG_DEBUG("[%{public}s] columnSpan_[%{public}d]", __func__, columnSpan_); + return columnSpan_; +} + +int GridItemInfo::GetRowSpan() +{ + HILOG_DEBUG("[%{public}s] rowSpan_[%{public}d]", __func__, rowSpan_); + return rowSpan_; +} + +bool GridItemInfo::IsHeading() +{ + HILOG_DEBUG("[%{public}s] heading_[%{public}d]", __func__, heading_); + return heading_; +} + +bool GridItemInfo::IsSelected() +{ + HILOG_DEBUG("[%{public}s] selected_[%{public}d]", __func__, selected_); + return selected_; +} + +bool Rect::ReadFromParcel(Parcel &parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, leftTopX_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, leftTopY_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rightBottomX_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rightBottomY_); + return true; +} + +bool Rect::Marshalling(Parcel &parcel) const +{ + HILOG_DEBUG("[%{public}s]", __func__); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, leftTopX_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, leftTopY_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rightBottomX_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rightBottomY_); + return true; +}; + +Rect *Rect::Unmarshalling(Parcel& parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + Rect *rect = new Rect(); + if (!rect->ReadFromParcel(parcel)) { + HILOG_ERROR("read from parcel failed"); + delete rect; + rect = nullptr; + } + return rect; +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessibility_event_info.cpp b/frameworks/asacfwk/src/accessibility_event_info.cpp new file mode 100644 index 00000000..fe378840 --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_event_info.cpp @@ -0,0 +1,537 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_event_info.h" +#include "accessibility_operator.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace Accessibility { +bool AccessibilityMemo::ReadFromParcel(Parcel &parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, channelId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, componentId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, currentIndex_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, beginIndex_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, endIndex_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(StringVector, parcel, &contents_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, componentType_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, description_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, beforeText_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, latestConent_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, elementId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, itemCounts_); + + return true; +} + +bool AccessibilityMemo::Marshalling(Parcel &parcel) const +{ + HILOG_DEBUG("[%{public}s]", __func__); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, channelId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, componentId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, currentIndex_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, beginIndex_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, endIndex_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(StringVector, parcel, contents_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, componentType_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, description_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, beforeText_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, latestConent_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, elementId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, itemCounts_); + + return true; +} + +AccessibilityMemo* AccessibilityMemo::Unmarshalling(Parcel& parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + AccessibilityMemo* accessibilityRecord = new AccessibilityMemo(); + if (!accessibilityRecord->ReadFromParcel(parcel)) { + HILOG_ERROR("read from parcel failed"); + delete accessibilityRecord; + accessibilityRecord = nullptr; + } + return accessibilityRecord; +} + +void AccessibilityMemo::SetChannelId(const int channelId) +{ + channelId_ = channelId; + HILOG_DEBUG("[%{public}s] channelId_[%{public}d]", __func__, channelId_); +} + +int AccessibilityMemo::GetChannelId() const +{ + HILOG_DEBUG("[%{public}s] channelId_[%{public}d]", __func__, channelId_); + return channelId_; +} + +void AccessibilityMemo::SetSource(const int componentId) +{ + HILOG_DEBUG("[%{public}s] componentId[%{public}d]", __func__, componentId); + componentId_ = componentId; + elementId_ = componentId; +} + +bool AccessibilityMemo::GetSource(AccessibilityElementInfo &elementInfo) const +{ + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], windowId_[%{public}d], elementId_[%{public}d]", + __func__, channelId_, windowId_, elementId_); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + AccessibilityElementInfo element {}; + std::vector elementInfos {}; + bool result = false; + if (instance != nullptr) { + result = instance->SearchElementInfosByAccessibilityId(channelId_, windowId_, elementId_, 0,elementInfos); + for (auto& info : elementInfos) { + HILOG_INFO("[%{public}s] called] GetSource OK", __func__); + result = true; + elementInfo = info; + break; + } + HILOG_INFO("[%{public}s] called] GetSource is null", __func__); + } else { + HILOG_INFO("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return result; +} + +int AccessibilityMemo::GetViewId() const +{ + HILOG_DEBUG("[%{public}s] componentId_[%{public}d]", __func__, componentId_); + return componentId_; +} + +int AccessibilityMemo::GetAccessibilityId() const +{ + HILOG_INFO("[%{public}s] called] elementId_[%{public}d]",__func__, elementId_); + return elementId_; +} + +void AccessibilityMemo::SetWindowId(const int windowId) +{ + HILOG_DEBUG("[%{public}s] windowId[%{public}d]", __func__, windowId); + windowId_ = windowId; +} + +int AccessibilityMemo::GetWindowId() const +{ + HILOG_DEBUG("[%{public}s] windowId_[%{public}d]", __func__, windowId_); + return windowId_; +} + +int AccessibilityMemo::GetCurrentIndex() const +{ + HILOG_DEBUG("[%{public}s] currentIndex_[%{public}d]", __func__, currentIndex_); + return currentIndex_; +} + +void AccessibilityMemo::SetCurrentIndex(const int index) +{ + currentIndex_ = index; + HILOG_DEBUG("[%{public}s] currentIndex_[%{public}d]", __func__, currentIndex_); +} + +int AccessibilityMemo::GetBeginIndex() const +{ + HILOG_DEBUG("[%{public}s] beginIndex_[%{public}d]", __func__, beginIndex_); + return beginIndex_; +} + +void AccessibilityMemo::SetBeginIndex(const int index) +{ + beginIndex_ = index; + HILOG_DEBUG("[%{public}s] beginIndex_[%{public}d]", __func__, beginIndex_); +} + +int AccessibilityMemo::GetEndIndex() const +{ + HILOG_DEBUG("[%{public}s] endIndex_[%{public}d]", __func__, endIndex_); + return endIndex_; +} + +void AccessibilityMemo::SetEndIndex(const int index) +{ + endIndex_ = index; + HILOG_DEBUG("[%{public}s] endIndex_[%{public}d]", __func__, endIndex_); +} + +std::string AccessibilityMemo::GetComponentType() const +{ + HILOG_DEBUG("[%{public}s] componentType_[%{public}s]", __func__, componentType_.c_str()); + return componentType_; +} + +void AccessibilityMemo::SetComponentType(const std::string &className) +{ + componentType_ = className; + HILOG_DEBUG("[%{public}s] componentType_[%{public}s]", __func__, componentType_.c_str()); +} + +std::string AccessibilityMemo::GetBeforeText() const +{ + HILOG_DEBUG("[%{public}s] beforeText_[%{public}s]", __func__, beforeText_.c_str()); + return beforeText_; +} + +void AccessibilityMemo::SetBeforeText(const std::string &beforeText) +{ + beforeText_ = beforeText; + HILOG_DEBUG("[%{public}s] beforeText_[%{public}s]", __func__, beforeText_.c_str()); +} + +void AccessibilityMemo::AddContent(const std::string &content) +{ + contents_.push_back(content); + HILOG_DEBUG("[%{public}s] content[%{public}s]", __func__, content.c_str()); +} + +std::vector AccessibilityMemo::GetContentList() const +{ + return contents_; +} + +std::string AccessibilityMemo::GetLatestContent() const +{ + HILOG_DEBUG("[%{public}s] latestConent_[%{public}s]", __func__, latestConent_.c_str()); + return latestConent_; +} + +void AccessibilityMemo::SetLatestContent(const std::string &content) +{ + latestConent_ = content; + HILOG_DEBUG("[%{public}s] latestConent_[%{public}s]", __func__, latestConent_.c_str()); +} + +std::string AccessibilityMemo::GetDescription() const +{ + HILOG_DEBUG("[%{public}s] description_[%{public}s]", __func__, description_.c_str()); + return description_; +} + +void AccessibilityMemo::SetDescription(const std::string &contentDescription) +{ + description_ = contentDescription; + HILOG_DEBUG("[%{public}s] description_[%{public}s]", __func__, description_.c_str()); +} + +void AccessibilityMemo::SetItemCounts(const int itemCounts) +{ + itemCounts_ = itemCounts; + HILOG_DEBUG("[%{public}s] itemCounts_[%{public}d]", __func__, itemCounts_); +} + +int AccessibilityMemo::GetItemCounts() const +{ + HILOG_DEBUG("[%{public}s] itemCounts_[%{public}d]", __func__, itemCounts_); + return itemCounts_; +} + +bool AccessibilityEventInfo::ReadFromParcel(Parcel &parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + int eventType = TYPE_VIEW_INVALID; + int triggerAction = ACCESSIBILITY_ACTION_INVALID; + int textMoveStep = STEP_CHARACTER; + int windowContentChangeTypes = CONTENT_CHANGE_TYPE_INVALID; + int windowChangeTypes = WINDOW_UPDATE_INVALID; + int category = CATEGORY_INVALID; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, eventType); + eventType_ = static_cast(eventType); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, bundleName_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, triggerAction); + triggerAction_ = static_cast(triggerAction); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, timeStamp_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, textMoveStep); + textMoveStep_ = static_cast(textMoveStep); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowContentChangeTypes); + windowContentChangeTypes_ = static_cast(windowContentChangeTypes); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowChangeTypes); + windowChangeTypes_ = static_cast(windowChangeTypes); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, recordsCount_); + int32_t recordSize = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, recordSize); + for (auto i = 0; i < recordSize; i++) { + std::shared_ptr accessibilityRecord(parcel.ReadParcelable()); + if (!accessibilityRecord) { + HILOG_ERROR("ReadParcelable failed"); + } + records_.emplace_back(*accessibilityRecord); + } + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, category); + category_ = static_cast(category); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pageId_); + + int32_t channelId = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, channelId); + SetChannelId(channelId); + int32_t componentId = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, componentId); + SetSource(componentId); + int32_t windowId = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowId); + SetWindowId(windowId); + int32_t currentIndex = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, currentIndex); + SetCurrentIndex(currentIndex); + int32_t beginIndex = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, beginIndex); + SetBeginIndex(beginIndex); + int32_t endIndex = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, endIndex); + SetEndIndex(endIndex); + int32_t contentSize = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, contentSize); + std::string content; + for (auto i = 0 ; i < contentSize; i++) { + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, content); + AddContent(content); + } + std::string componentType; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, componentType); + SetComponentType(componentType); + std::string description; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, description); + SetDescription(description); + std::string beforeText; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, beforeText); + SetBeforeText(beforeText); + std::string latestConent; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, latestConent); + SetLatestContent(latestConent); + int32_t elementId = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, elementId); + //SetSource(elementId); + int32_t itemCounts = 0; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, itemCounts); + SetItemCounts(itemCounts); + return true; +} + +bool AccessibilityEventInfo::Marshalling(Parcel &parcel) const +{ + HILOG_DEBUG("[%{public}s]", __func__); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(eventType_)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, bundleName_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(triggerAction_)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, timeStamp_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(textMoveStep_)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(windowContentChangeTypes_)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(windowChangeTypes_)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, recordsCount_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, records_.size()); + for (auto &record : records_) { + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &record); + } + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(category_)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pageId_); + + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetChannelId()); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetViewId()); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetWindowId()); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetCurrentIndex()); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetBeginIndex()); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetEndIndex()); + auto contentList = GetContentList(); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, contentList.size()); + for (auto &content : contentList) { + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, content); + } + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, GetComponentType()); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, GetDescription()); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, GetBeforeText()); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, GetLatestContent()); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetAccessibilityId()); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetItemCounts()); + return true; +} + +AccessibilityEventInfo *AccessibilityEventInfo::Unmarshalling(Parcel& parcel) +{ + HILOG_DEBUG("[%{public}s]", __func__); + AccessibilityEventInfo *accessibilityEventInfo = new AccessibilityEventInfo(); + if (!accessibilityEventInfo->ReadFromParcel(parcel)) { + HILOG_ERROR("read from parcel failed"); + delete accessibilityEventInfo; + accessibilityEventInfo = nullptr; + } + return accessibilityEventInfo; +} + +int AccessibilityEventInfo::GetRecordCount() const +{ + HILOG_DEBUG("[%{public}s] recordsCount_[%{public}d]", __func__, recordsCount_); + return recordsCount_; +} + +void AccessibilityEventInfo::SetRecordCount(const int recordCount) +{ + recordsCount_ = recordCount; + HILOG_DEBUG("[%{public}s] recordsCount_[%{public}d]", __func__, recordsCount_); +} + +void AccessibilityEventInfo::AddRecord(const AccessibilityEventInfo &record) +{ + HILOG_DEBUG("[%{public}s]", __func__); + records_.push_back(record); +} + +AccessibilityEventInfo AccessibilityEventInfo::GetRecord(const int index) +{ + HILOG_DEBUG("[%{public}s]", __func__); + if (index >= recordsCount_ || index < 0) { + AccessibilityEventInfo record {}; + HILOG_ERROR("[%{public}s] called] index[%{public}d] is invalid", __func__, index); + return record; + } + return records_[index]; +} + +std::vector AccessibilityEventInfo::GetRecords() +{ + HILOG_DEBUG("[%{public}s]", __func__); + return records_; +} + +EventType AccessibilityEventInfo::GetEventType() const +{ + HILOG_DEBUG("[%{public}s] eventType_[%{public}d]", __func__, eventType_); + return eventType_; +} + +WindowsContentChangeTypes AccessibilityEventInfo::GetWindowContentChangeTypes() const +{ + HILOG_DEBUG("[%{public}s] windowType_[%{public}d]", __func__, windowContentChangeTypes_); + return windowContentChangeTypes_; +} + +void AccessibilityEventInfo::SetWindowContentChangeTypes(const WindowsContentChangeTypes changeTypes) +{ + windowContentChangeTypes_ = changeTypes; + HILOG_DEBUG("[%{public}s] windowType_[%{public}d]", __func__, windowContentChangeTypes_); +} + +WindowUpdateType AccessibilityEventInfo::GetWindowChangeTypes() const +{ + HILOG_DEBUG("[%{public}s] windowType_[%{public}d]", __func__, windowChangeTypes_); + return windowChangeTypes_; +} + +void AccessibilityEventInfo::SetWindowChangeTypes(const WindowUpdateType changeTypes) +{ + windowChangeTypes_ = changeTypes; + HILOG_DEBUG("[%{public}s] windowType_[%{public}d]", __func__, windowChangeTypes_); +} + +void AccessibilityEventInfo::SetEventType(const EventType eventType) +{ + eventType_ = EventType(eventType); + HILOG_DEBUG("[%{public}s] eventType_[%{public}d]", __func__, eventType_); +} + +long long AccessibilityEventInfo::GetTimeStamp() const +{ + HILOG_DEBUG("[%{public}s]", __func__); + return timeStamp_; +} + +void AccessibilityEventInfo::SetTimeStamp(const long long eventTime) +{ + HILOG_DEBUG("[%{public}s]", __func__); + timeStamp_ = eventTime; +} + +std::string AccessibilityEventInfo::GetBundleName() const +{ + HILOG_DEBUG("[%{public}s] bundleName_[%{public}s]", __func__, bundleName_.c_str()); + return bundleName_; +} + +void AccessibilityEventInfo::SetBundleName(const std::string &bundleName) +{ + bundleName_ = bundleName; + HILOG_DEBUG("[%{public}s] bundleName_[%{public}s]", __func__, bundleName_.c_str()); +} + +void AccessibilityEventInfo::SetTextMovementStep(const TextMoveUnit granularity) +{ + textMoveStep_ = granularity; + HILOG_DEBUG("[%{public}s] textMoveStep_[%{public}d]", __func__, textMoveStep_); +} + +TextMoveUnit AccessibilityEventInfo::GetTextMovementStep() const +{ + HILOG_DEBUG("[%{public}s] textMoveStep_[%{public}d]", __func__, textMoveStep_); + return textMoveStep_; +} + +void AccessibilityEventInfo::SetTriggerAction(const ActionType action) +{ + triggerAction_ = action; + HILOG_DEBUG("[%{public}s] triggerAction_[%{public}d]", __func__, triggerAction_); +} + +ActionType AccessibilityEventInfo::GetTriggerAction() const +{ + HILOG_DEBUG("[%{public}s] triggerAction_[%{public}d]", __func__, triggerAction_); + return triggerAction_; +} + +AccessibilityEventInfo::AccessibilityEventInfo( + int windowId, WindowUpdateType windowChangeTypes) +{ + HILOG_DEBUG("[%{public}s]", __func__); + eventType_ = TYPE_WINDOW_UPDATE; + windowChangeTypes_ = windowChangeTypes; + SetWindowId(windowId); +} + +AccessibilityEventInfo::AccessibilityEventInfo(EventType eventType) +{ + eventType_ = eventType; + HILOG_DEBUG("[%{public}s] eventType_[%{public}d]", __func__, eventType_); +} + +void AccessibilityEventInfo::SetNotificationInfo(const NotificationCategory category) +{ + category_ = category; + HILOG_DEBUG("[%{public}s] category_[%{public}d]", __func__, category_); +} + +NotificationCategory AccessibilityEventInfo::GetNotificationInfo() const +{ + HILOG_DEBUG("[%{public}s] category_[%{public}d]", __func__, category_); + return category_; +} + +void AccessibilityEventInfo::SetPageId(const int pageId) +{ + HILOG_DEBUG("[%{public}s] pageId[%{public}d]", __func__, pageId); + pageId_ = pageId; +} + +int AccessibilityEventInfo::GetPageId() const +{ + HILOG_DEBUG("[%{public}s] pageId_[%{public}d]", __func__, pageId_); + return pageId_; +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessibility_interaction_operation_callback_proxy.cpp b/frameworks/asacfwk/src/accessibility_interaction_operation_callback_proxy.cpp new file mode 100644 index 00000000..85f64118 --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_interaction_operation_callback_proxy.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2021 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. + */ +#include "accessibility_interaction_operation_callback_proxy.h" +#include "hilog_wrapper.h" +#include "ipc_types.h" +#include "iremote_object.h" +#include "parcel_util.h" + +namespace OHOS { +namespace Accessibility { +AccessibilityInteractionOperationCallbackProxy::AccessibilityInteractionOperationCallbackProxy( + const sptr &impl) : IRemoteProxy(impl) +{} + +AccessibilityInteractionOperationCallbackProxy::~AccessibilityInteractionOperationCallbackProxy() +{} +bool AccessibilityInteractionOperationCallbackProxy::WriteInterfaceToken(MessageParcel &data) +{ + HILOG_DEBUG("%{public}s" , __func__); + if (!data.WriteInterfaceToken(AccessibilityInteractionOperationCallbackProxy::GetDescriptor())) { + HILOG_ERROR("write interface token failed"); + return false; + } + return true; +} + +void AccessibilityInteractionOperationCallbackProxy::SetSearchElementInfoByAccessibilityIdResult( + const std::vector &infos, const int requestId) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!WriteParcelableVector(infos, data)) { + HILOG_ERROR("write failed"); + return; + } + + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("%{public}s fail, connection write requestId", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(IAccessibilityInteractionOperationCallback::Message::SET_RESULT_BY_ACCESSIBILITY_ID), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("SearchAccessibilityInfoByAccessibility fail, error: %d", error); + } +} + +void AccessibilityInteractionOperationCallbackProxy::SetSearchElementInfoByTextResult( + const std::vector &infos, const int requestId) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!WriteParcelableVector(infos, data)) { + HILOG_ERROR("write failed"); + return; + } + + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("%{public}s fail, connection write requestId", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(IAccessibilityInteractionOperationCallback::Message::SET_RESULT_BY_TEXT), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("SearchAccessibilityInfoByAccessibility fail, error: %d", error); + } +} + +void AccessibilityInteractionOperationCallbackProxy::SetFindFocusedElementInfoResult( + const AccessibilityElementInfo &info, const int requestId) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteParcelable(&info)) { + HILOG_ERROR("%{public}s fail, connection write info", __func__); + return; + } + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("%{public}s fail, connection write requestId", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(IAccessibilityInteractionOperationCallback::Message::SET_RESULT_FOCUSED_INFO), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("SetFindFocusedElementInfo fail, error: %d", error); + } +} + +void AccessibilityInteractionOperationCallbackProxy::SetFocusMoveSearchResult(const AccessibilityElementInfo &info, + const int requestId) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteParcelable(&info)) { + HILOG_ERROR("%{public}s fail, connection write info", __func__); + return; + } + + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("%{public}s fail, connection write requestId", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(IAccessibilityInteractionOperationCallback::Message::SET_RESULT_FOCUS_MOVE), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("SetFocusMoveSearchResult fail, error: %d", error); + } +} + +void AccessibilityInteractionOperationCallbackProxy::SetPerformActionResult(const bool succeeded, const int requestId) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteBool(succeeded)) { + HILOG_ERROR("%{public}s fail, connection write succeeded", __func__); + return; + } + + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("%{public}s fail, connection write requestId", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(IAccessibilityInteractionOperationCallback::Message::SET_RESULT_PERFORM_ACTION), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("SetPerformActionResult fail, error: %d", error); + } +} + +template +bool AccessibilityInteractionOperationCallbackProxy::WriteParcelableVector(const std::vector &parcelableVector, + Parcel &reply) +{ + if (!reply.WriteInt32(parcelableVector.size())) { + HILOG_ERROR("write ParcelableVector failed"); + return false; + } + + for (auto &parcelable : parcelableVector) { + if (!reply.WriteParcelable(&parcelable)) { + HILOG_ERROR("write ParcelableVector failed"); + return false; + } + } + return true; +} + +} //namespace Accessibility +} //namespace OHOS diff --git a/frameworks/asacfwk/src/accessibility_interaction_operation_callback_stub.cpp b/frameworks/asacfwk/src/accessibility_interaction_operation_callback_stub.cpp new file mode 100644 index 00000000..f16d998d --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_interaction_operation_callback_stub.cpp @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2021 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. + */ +#include +#include "accessibility_interaction_operation_callback_stub.h" +#include "hilog_wrapper.h" +#include "ipc_skeleton.h" +#include "ipc_types.h" +#include "iremote_object.h" +#include "accessibility_errorcode.h" + +namespace OHOS { +namespace Accessibility { + +AccessibilityInteractionOperationCallbackStub::AccessibilityInteractionOperationCallbackStub() +{ + memberFuncMap_[static_cast( + IAccessibilityInteractionOperationCallback::Message::SET_RESULT_BY_ACCESSIBILITY_ID)] = + &AccessibilityInteractionOperationCallbackStub::HandleSetSearchElementInfoByAccessibilityIdResult; + memberFuncMap_[static_cast(IAccessibilityInteractionOperationCallback::Message::SET_RESULT_BY_TEXT)] = + &AccessibilityInteractionOperationCallbackStub::HandleSetSearchElementInfoByTextResult; + memberFuncMap_[static_cast( + IAccessibilityInteractionOperationCallback::Message::SET_RESULT_FOCUSED_INFO)] = + &AccessibilityInteractionOperationCallbackStub::HandleSetFindFocusedElementInfoResult; + memberFuncMap_[static_cast(IAccessibilityInteractionOperationCallback::Message::SET_RESULT_FOCUS_MOVE)] = + &AccessibilityInteractionOperationCallbackStub::HandleSetFocusMoveSearchResult; + memberFuncMap_[static_cast( + IAccessibilityInteractionOperationCallback::Message::SET_RESULT_PERFORM_ACTION)] = + &AccessibilityInteractionOperationCallbackStub::HandleSetPerformActionResult; +} + +AccessibilityInteractionOperationCallbackStub::~AccessibilityInteractionOperationCallbackStub() +{ + HILOG_DEBUG("%{public}s start.", __func__); + memberFuncMap_.clear(); +} + +int AccessibilityInteractionOperationCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) + { + HILOG_DEBUG("AccessibilityInteractionOperationCallbackStub::OnRemoteRequest, cmd = %d, flags= %d", + code, option.GetFlags()); + std::u16string descriptor = AccessibilityInteractionOperationCallbackStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + + if (descriptor != remoteDescriptor) { + HILOG_INFO("local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + auto memFunc = memberFuncMap_.find(code); + if (memFunc != memberFuncMap_.end()) { + auto func = memFunc->second; + if (func != nullptr) { + return (this->*func)(data,reply); + } + } + HILOG_WARN("AccessibilityInteractionOperationCallbackStub::OnRemoteRequest, default case, need check."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +ErrCode AccessibilityInteractionOperationCallbackStub::HandleSetSearchElementInfoByAccessibilityIdResult( + MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + std::vector infos{}; + int32_t accessibilityInfosize = data.ReadInt32(); + for (int i = 0; i< accessibilityInfosize; i++) { + std::shared_ptr accessibilityInfo(data.ReadParcelable()); + if (!accessibilityInfo) { + HILOG_ERROR("ReadParcelable failed"); + } + infos.emplace_back(*accessibilityInfo); + } + int requestId = data.ReadInt32(); + + SetSearchElementInfoByAccessibilityIdResult(infos, requestId); + return NO_ERROR; +} + +ErrCode AccessibilityInteractionOperationCallbackStub::HandleSetSearchElementInfoByTextResult( + MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + std::vector infos{}; + int32_t accessibilityInfosize = data.ReadInt32(); + for (int i = 0; i< accessibilityInfosize; i++) { + std::shared_ptr accessibilityInfo(data.ReadParcelable()); + if (!accessibilityInfo) { + HILOG_ERROR("ReadParcelable failed"); + } + infos.emplace_back(*accessibilityInfo); + } + int requestId = data.ReadInt32(); + + SetSearchElementInfoByTextResult(infos, requestId); + + return NO_ERROR; +} + +ErrCode AccessibilityInteractionOperationCallbackStub::HandleSetFindFocusedElementInfoResult(MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + std::shared_ptr info(data.ReadParcelable()); + if (!info) { + HILOG_ERROR("ReadParcelable failed"); + return ERROR; + } + + int requestId = data.ReadInt32(); + + SetFindFocusedElementInfoResult(*info, requestId); + + return NO_ERROR; +} + +ErrCode AccessibilityInteractionOperationCallbackStub::HandleSetFocusMoveSearchResult(MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + std::shared_ptr info(data.ReadParcelable()); + if (!info) { + HILOG_ERROR("ReadParcelable failed"); + return ERROR; + } + + int requestId = data.ReadInt32(); + + SetFocusMoveSearchResult(*info, requestId); + + return NO_ERROR; +} + +ErrCode AccessibilityInteractionOperationCallbackStub::HandleSetPerformActionResult(MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + bool succeeded = data.ReadBool(); + int requestId = data.ReadInt32(); + + SetPerformActionResult(succeeded, requestId); + + return NO_ERROR; +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessibility_interaction_operation_proxy.cpp b/frameworks/asacfwk/src/accessibility_interaction_operation_proxy.cpp new file mode 100644 index 00000000..1e67a564 --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_interaction_operation_proxy.cpp @@ -0,0 +1,325 @@ +/* + * Copyright (C) 2021 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. + */ +#include "accessibility_interaction_operation_proxy.h" +#include "hilog_wrapper.h" +#include "ipc_types.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Accessibility { +AccessibilityInteractionOperationProxy::AccessibilityInteractionOperationProxy( + const sptr &impl) : IRemoteProxy(impl) +{} + +AccessibilityInteractionOperationProxy::~AccessibilityInteractionOperationProxy() +{} + +bool AccessibilityInteractionOperationProxy::WriteInterfaceToken(MessageParcel &data) +{ + HILOG_DEBUG("%{public}s" , __func__); + + if (!data.WriteInterfaceToken(AccessibilityInteractionOperationProxy::GetDescriptor())) { + HILOG_ERROR("write interface token failed"); + return false; + } + return true; +} + +void AccessibilityInteractionOperationProxy::SearchElementInfoByAccessibilityId(const long elementId, + const int requestId, const sptr &callback, const int mode) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteInt32(elementId)) { + HILOG_ERROR("%{public}s fail, connection write parcelable elementId error", __func__); + return; + } + + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("%{public}s fail, connection write parcelable requestId error", __func__); + return; + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("%{public}s fail, connection write parcelable callback error", __func__); + return; + } + + if (!data.WriteInt32(mode)) { + HILOG_ERROR("%{public}s fail, connection write parcelable mode error", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(AccessibilityInteractionOperationProxy::Message::SEARCH_BY_ACCESSIBILITY_ID), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("SearchAccessibilityInfo fail, error: %d", error); + return; + } + +} + +void AccessibilityInteractionOperationProxy::SearchElementInfosByText(const long elementId, + const std::string &text, + const int requestId, const sptr &callback) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteInt32(elementId)) { + HILOG_ERROR("%{public}s fail, connection write parcelable elementId error", __func__); + return; + } + if (!data.WriteString(text)) { + HILOG_ERROR("%{public}s fail, connection write text error", __func__); + return; + } + + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("%{public}s fail, connection write requestId error", __func__); + return; + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("%{public}s fail, connection write callback error", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(AccessibilityInteractionOperationProxy::Message::SEARCH_BY_TEXT), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("SearchElementInfosByText fail, error: %d", error); + return; + } + +} +void AccessibilityInteractionOperationProxy::FindFocusedElementInfo(const long elementId, + const int focusType, const int requestId, const sptr &callback) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteInt32(elementId)) { + HILOG_ERROR("%{public}s fail, connection write elementId error", __func__); + return; + } + + if (!data.WriteInt32(focusType)) { + HILOG_ERROR("%{public}s fail, connection write focusType error", __func__); + return; + } + + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("%{public}s fail, connection write requestId error", __func__); + return; + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("%{public}s fail, connection write callback error", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(AccessibilityInteractionOperationProxy::Message::FIND_FOCUSED_INFO),data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("FindFocusedElementInfo fail, error: %d", error); + return; + } + +} + +void AccessibilityInteractionOperationProxy::FocusMoveSearch(const long elementId, + const int direction, const int requestId, const sptr &callback) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteInt32(elementId)) { + HILOG_ERROR("%{public}s fail, connection write elementId error", __func__); + return; + } + + if (!data.WriteInt32(direction)) { + HILOG_ERROR("%{public}s fail, connection write focusType error", __func__); + return; + } + + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("%{public}s fail, connection write requestId error", __func__); + return; + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("%{public}s fail, connection write callback error", __func__); + return; + } + + error = Remote()->SendRequest(static_cast(AccessibilityInteractionOperationProxy::Message::FOCUS_FIND), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("FindFocusedElementInfo fail, error: %d", error); + return; + } +} + +void AccessibilityInteractionOperationProxy::PerformAction(const long elementId, const int action, + const std::map arguments, const int requestId, + const sptr &callback) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteInt32(elementId)) { + HILOG_ERROR("%{public}s fail, connection write elementId error", __func__); + return; + } + + if (!data.WriteInt32(action)) { + HILOG_ERROR("%{public}s fail, connection write focusType error", __func__); + return; + } + + auto iter = arguments.begin(); + std::vector argumentKey; + std::vector argumentValue; + while(iter != arguments.end()) { + argumentKey.push_back(iter->first); + argumentValue.push_back(iter->second); + iter++; + } + + if (!data.WriteStringVector(argumentKey)) { + HILOG_ERROR("%{public}s fail, connection write argumentKey error", __func__); + return; + } + + if (!data.WriteStringVector(argumentValue)) { + HILOG_ERROR("%{public}s fail, connection write argumentValue error", __func__); + return; + } + + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("%{public}s fail, connection write requestId error", __func__); + return; + } + + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("%{public}s fail, connection write callback error", __func__); + return; + } + + error = Remote()->SendRequest(static_cast( + AccessibilityInteractionOperationProxy::Message::PERFORM_ACTION), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("PerformAction fail, error: %d", error); + return; + } + +} + +void AccessibilityInteractionOperationProxy::ClearFocus() +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + error = Remote()->SendRequest(static_cast(AccessibilityInteractionOperationProxy::Message::CLEAR_FOCUS), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("PerformAction fail, error: %d", error); + return; + } +} + +void AccessibilityInteractionOperationProxy::OutsideTouch() +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(AccessibilityInteractionOperationProxy::Message::OUTSIDE_TOUCH), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("PerformAction fail, error: %d", error); + return; + } +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessibility_interaction_operation_stub.cpp b/frameworks/asacfwk/src/accessibility_interaction_operation_stub.cpp new file mode 100644 index 00000000..3152efa1 --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_interaction_operation_stub.cpp @@ -0,0 +1,413 @@ +/* + * Copyright (C) 2021 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. + */ +#include "accessibility_interaction_operation_callback_proxy.h" +#include "accessibility_interaction_operation_callback_stub.h" +#include "accessibility_interaction_operation_stub.h" +#include "accessibility_system_ability_client.h" +#include "hilog_wrapper.h" +#include "ipc_skeleton.h" +#include "ipc_types.h" +#include "iremote_object.h" +#include "parcel_util.h" + +namespace OHOS { +namespace Accessibility { +std::map> + AccessibilityInteractionOperationStub::aaCallbacks_ = {}; +AccessibilityInteractionOperationStub::AccessibilityInteractionOperationStub() +{ + memberFuncMap_[static_cast(IAccessibilityInteractionOperation::Message::SEARCH_BY_ACCESSIBILITY_ID)] = + &AccessibilityInteractionOperationStub::HandleSearchElementInfoByAccessibilityId; + memberFuncMap_[static_cast(IAccessibilityInteractionOperation::Message::SEARCH_BY_TEXT)] = + &AccessibilityInteractionOperationStub::HandleSearchElementInfosByText; + memberFuncMap_[static_cast(IAccessibilityInteractionOperation::Message::FIND_FOCUSED_INFO)] = + &AccessibilityInteractionOperationStub::HandleFindFocusedElementInfo; + memberFuncMap_[static_cast(IAccessibilityInteractionOperation::Message::FOCUS_FIND)] = + &AccessibilityInteractionOperationStub::HandleFocusFind; + memberFuncMap_[static_cast(IAccessibilityInteractionOperation::Message::PERFORM_ACTION)] = + &AccessibilityInteractionOperationStub::HandlePerformAction; + memberFuncMap_[static_cast(IAccessibilityInteractionOperation::Message::CLEAR_FOCUS)] = + &AccessibilityInteractionOperationStub::HandleClearFocus; + memberFuncMap_[static_cast(IAccessibilityInteractionOperation::Message::OUTSIDE_TOUCH)] = + &AccessibilityInteractionOperationStub::HandleOutsideTouch; +} + +AccessibilityInteractionOperationStub::~AccessibilityInteractionOperationStub() +{ + HILOG_DEBUG("%{public}s start.", __func__); + memberFuncMap_.clear(); +} + +int AccessibilityInteractionOperationStub::OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) + { + HILOG_DEBUG("AccessibilityInteractionOperationStub::OnRemoteRequest,cmd = %d,flags= %d", code, option.GetFlags()); + std::u16string descriptor = AccessibilityInteractionOperationStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + + if (descriptor != remoteDescriptor) { + HILOG_INFO("local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + auto memFunc = memberFuncMap_.find(code); + if (memFunc != memberFuncMap_.end()) { + auto func = memFunc->second; + if (func != nullptr) { + return (this->*func)(data,reply); + } + } + HILOG_WARN("AccessibilityInteractionOperationStub::OnRemoteRequest, default case, need check."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +ErrCode AccessibilityInteractionOperationStub::HandleSearchElementInfoByAccessibilityId(MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + long elementId = data.ReadInt32(); + int requestId = data.ReadInt32(); + sptr obj = data.ReadRemoteObject(); + + sptr callback = + new AccessibilityInteractionOperationCallbackProxy(obj); + int mode = data.ReadInt32(); + SearchElementInfoByAccessibilityId(elementId, requestId, callback, mode); + return NO_ERROR; +} + +ErrCode AccessibilityInteractionOperationStub::HandleSearchElementInfosByText(MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + long elementId = data.ReadInt32(); + std::string text = data.ReadString(); + int requestId = data.ReadInt32(); + sptr obj = data.ReadRemoteObject(); + + sptr callback = + new AccessibilityInteractionOperationCallbackProxy(obj); + SearchElementInfosByText(elementId, text, requestId, callback); + return NO_ERROR; +} + +ErrCode AccessibilityInteractionOperationStub::HandleFindFocusedElementInfo(MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + long elementId = data.ReadInt32(); + int focusType = data.ReadInt32(); + int requestId = data.ReadInt32(); + sptr obj = data.ReadRemoteObject(); + + sptr callback = + new AccessibilityInteractionOperationCallbackProxy(obj); + FindFocusedElementInfo(elementId, focusType, requestId, callback); + return NO_ERROR; +} + +ErrCode AccessibilityInteractionOperationStub::HandleFocusFind(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + long elementId = data.ReadInt32(); + int direction = data.ReadInt32(); + int requestId = data.ReadInt32(); + sptr obj = data.ReadRemoteObject(); + + sptr callback = + new AccessibilityInteractionOperationCallbackProxy(obj); + FocusMoveSearch(elementId, direction, requestId, callback); + return NO_ERROR; +} + +ErrCode AccessibilityInteractionOperationStub::HandlePerformAction(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + std::vector argumentKey{}; + std::vector argumentValue{}; + long elementId = data.ReadInt32(); + int action = data.ReadInt32(); + if (!data.ReadStringVector(&argumentKey)) { + return ERROR; + } + if (!data.ReadStringVector(&argumentValue)) { + return ERROR; + } + if (argumentKey.size() != argumentValue.size()) { + return ERROR; + } + std::map arguments{}; + for (unsigned int i = 0;i < argumentKey.size(); i++) { + arguments.insert(std::pair(argumentKey[i],argumentValue[i])); + } + int requestId = data.ReadInt32(); + sptr obj = data.ReadRemoteObject(); + + sptr callback = + new AccessibilityInteractionOperationCallbackProxy(obj); + PerformAction(elementId, action, arguments, requestId, callback); + return NO_ERROR; +} + +ErrCode AccessibilityInteractionOperationStub::HandleClearFocus(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + ClearFocus(); + + return NO_ERROR; +} + +ErrCode AccessibilityInteractionOperationStub::HandleOutsideTouch(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + OutsideTouch(); + + return NO_ERROR; +} + +void AccessibilityInteractionOperationStub::SearchElementInfoByAccessibilityId(const long elementId, + const int requestId, const sptr &callback, const int mode) +{ + HILOG_DEBUG("%{public}s", __func__); + + AccessibilityInteractionOperationCallback *tempCallback = new CallbackImpl(requestId, + CallbackImpl::CALLBACK_BY_ACCESSIBILITY_ID); + aaCallbacks_.insert( + std::pair>(requestId, callback)); + std::shared_ptr obj = + AccessibilitySystemAbilityClient::GetInstance()->GetInteractionObject(GetWindowId()); + if (obj != nullptr) { + obj->SearchElementInfoByAccessibilityId(elementId, requestId, *tempCallback, mode); + } else { + HILOG_DEBUG("%{public}s Can not find interaction object", __func__); + } +} + +void AccessibilityInteractionOperationStub::SearchElementInfosByText(const long elementId, + const std::string &text, + const int requestId, const sptr &callback) +{ + HILOG_DEBUG("%{public}s", __func__); + + AccessibilityInteractionOperationCallback *tempCallback = new CallbackImpl(requestId, + CallbackImpl::CALLBACK_BY_TEXT); + aaCallbacks_.insert( + std::pair>(requestId, callback)); + std::shared_ptr obj = + AccessibilitySystemAbilityClient::GetInstance()->GetInteractionObject(GetWindowId()); + if (obj != nullptr) { + obj->SearchElementInfosByText(elementId, text, requestId, *tempCallback); + } else { + HILOG_DEBUG("%{public}s Can not find interaction object", __func__); + } +} + +void AccessibilityInteractionOperationStub::FindFocusedElementInfo(const long elementId, + const int focusType, const int requestId, + const sptr &callback) +{ + HILOG_DEBUG("%{public}s", __func__); + + AccessibilityInteractionOperationCallback *tempCallback = new CallbackImpl(requestId, + CallbackImpl::CALLBACK_FIND_FOCUS); + aaCallbacks_.insert( + std::pair>(requestId, callback)); + std::shared_ptr obj = + AccessibilitySystemAbilityClient::GetInstance()->GetInteractionObject(GetWindowId()); + if (obj != nullptr) { + obj->FindFocusedElementInfo(elementId, focusType, requestId, *tempCallback); + } else { + HILOG_DEBUG("%{public}s Can not find interaction object", __func__); + } +} + +void AccessibilityInteractionOperationStub::FocusMoveSearch(const long elementId, + const int direction, const int requestId, + const sptr &callback) +{ + HILOG_DEBUG("%{public}s", __func__); + + AccessibilityInteractionOperationCallback *tempCallback = new CallbackImpl(requestId, + CallbackImpl::CALLBACK_BY_FOCUS_MOVE); + aaCallbacks_.insert( + std::pair>(requestId, callback)); + std::shared_ptr obj = + AccessibilitySystemAbilityClient::GetInstance()->GetInteractionObject(GetWindowId()); + if (obj != nullptr) { + obj->FocusMoveSearch(elementId, direction, requestId, *tempCallback); + } else { + HILOG_DEBUG("%{public}s Can not find interaction object", __func__); + } +} + +void AccessibilityInteractionOperationStub::PerformAction(const long elementId, + const int action, const std::map actionArguments, + int requestId, const sptr &callback) +{ + HILOG_DEBUG("%{public}s", __func__); + + AccessibilityInteractionOperationCallback *tempCallback = new CallbackImpl(requestId, + CallbackImpl::CALLBACK_PERFORM_ACTION); + aaCallbacks_.insert( + std::pair>(requestId, callback)); + std::shared_ptr obj = + AccessibilitySystemAbilityClient::GetInstance()->GetInteractionObject(GetWindowId()); + if (obj != nullptr) { + obj->PerformAction(elementId, action, actionArguments, requestId, *tempCallback); + } else { + HILOG_DEBUG("%{public}s Can not find interaction object", __func__); + } +} + +void AccessibilityInteractionOperationStub::ClearFocus() +{ + HILOG_DEBUG("%{public}s", __func__); + std::shared_ptr obj = + AccessibilitySystemAbilityClient::GetInstance()->GetInteractionObject(GetWindowId()); + if (obj != nullptr) { + obj->ClearFocus(); + } else { + HILOG_DEBUG("%{public}s Can not find interaction object", __func__); + } +} + +void AccessibilityInteractionOperationStub::OutsideTouch() +{ + HILOG_DEBUG("%{public}s", __func__); + std::shared_ptr obj = + AccessibilitySystemAbilityClient::GetInstance()->GetInteractionObject(GetWindowId()); + if (obj != nullptr) { + obj->OutsideTouch(); + } else { + HILOG_DEBUG("%{public}s Can not find interaction object", __func__); + } +} + +AccessibilityInteractionOperationStub::CallbackImpl::CallbackImpl() +{ + +} + +AccessibilityInteractionOperationStub::CallbackImpl::CallbackImpl(const int requestId, + CALL_API_NUM callNum) +{ + requestId_ = requestId; + callNum_ = callNum; +} + +void AccessibilityInteractionOperationStub::CallbackImpl::SetSearchElementInfoByAccessibilityIdResult( + const std::list &infos, const int requestId) +{ + HILOG_DEBUG("%{public}s", __func__); + std::vector myInfos = TranslateListToVector(infos); + auto callback = GetAACallbackList().find(requestId); + if (callback != GetAACallbackList().end() && callback->second != nullptr) { + callback->second->SetSearchElementInfoByAccessibilityIdResult(myInfos, requestId); + } else { + HILOG_DEBUG("%s Can't find the callback [requestId:%d]", __func__, requestId); + } + RemoveAACallbackList(requestId); +} + +void AccessibilityInteractionOperationStub::CallbackImpl::SetSearchElementInfoByTextResult( + const std::list &infos, const int requestId) +{ + HILOG_DEBUG("%{public}s", __func__); + std::vector myInfos = TranslateListToVector(infos); + auto callback = GetAACallbackList().find(requestId); + if (callback != GetAACallbackList().end() && callback->second != nullptr) { + callback->second->SetSearchElementInfoByTextResult(myInfos, requestId); + } else { + HILOG_DEBUG("%s Can't find the callback [requestId:%d]", __func__, requestId); + } + RemoveAACallbackList(requestId); +} + +void AccessibilityInteractionOperationStub::CallbackImpl::SetFindFocusedElementInfoResult( + const AccessibilityElementInfo &info, const int requestId) +{ + HILOG_DEBUG("%{public}s", __func__); + auto callback = GetAACallbackList().find(requestId); + if (callback != GetAACallbackList().end() && callback->second != nullptr) { + callback->second->SetFindFocusedElementInfoResult(info, requestId); + } else { + HILOG_DEBUG("%s Can't find the callback [requestId:%d]", __func__, requestId); + } + RemoveAACallbackList(requestId); +} + +void AccessibilityInteractionOperationStub::CallbackImpl::SetFocusMoveSearchResult( + const AccessibilityElementInfo &info, const int requestId) +{ + HILOG_DEBUG("%{public}s", __func__); + auto callback = GetAACallbackList().find(requestId); + if (callback != GetAACallbackList().end() && callback->second != nullptr) { + callback->second->SetFocusMoveSearchResult(info, requestId); + } else { + HILOG_DEBUG("%s Can't find the callback [requestId:%d]", __func__, requestId); + } + RemoveAACallbackList(requestId); +} + +void AccessibilityInteractionOperationStub::CallbackImpl::SetPerformActionResult( + const bool succeeded, const int requestId) +{ + HILOG_DEBUG("%{public}s", __func__); + auto callback = GetAACallbackList().find(requestId); + if (callback != GetAACallbackList().end() && callback->second != nullptr) { + callback->second->SetPerformActionResult(succeeded, requestId); + } else { + HILOG_DEBUG("%s Can't find the callback [requestId:%d]", __func__, requestId); + } + RemoveAACallbackList(requestId); +} + +std::map> + AccessibilityInteractionOperationStub::CallbackImpl::GetAACallbackList() +{ + HILOG_DEBUG("%{public}s", __func__); + return aaCallbacks_; +} + +void AccessibilityInteractionOperationStub::CallbackImpl::RemoveAACallbackList(int requestId) +{ + for (auto iter = aaCallbacks_.begin(); iter != aaCallbacks_.end();) { + if (iter->first == requestId) { + aaCallbacks_.erase(iter++); + return; + } else { + iter++; + } + } + HILOG_DEBUG("%{public}s Not find requestID[%{public}d]", __func__, requestId); +} + +void AccessibilityInteractionOperationStub::SetWindowId(int windowId) +{ + windowId_ = windowId; +} + +int AccessibilityInteractionOperationStub::GetWindowId() +{ + return windowId_; +} +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessibility_operator.cpp b/frameworks/asacfwk/src/accessibility_operator.cpp new file mode 100644 index 00000000..b2f66eb6 --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_operator.cpp @@ -0,0 +1,514 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_operator.h" +#include +#include + +namespace OHOS { +namespace Accessibility { +std::map> AccessibilityOperator::channels_ = {}; +std::vector> AccessibilityOperator::instances_ = {}; +std::recursive_mutex AccessibilityOperator::mutex_ = {}; +int AccessibilityOperator::requestId_ = 0; + +AccessibilityOperator::AccessibilityOperator() +{ + performActionResult_ = false; +} + +AccessibilityOperator &AccessibilityOperator::GetInstance() +{ + std::thread::id tid = std::this_thread::get_id(); + return GetInstanceForThread(tid); +} + +AccessibilityOperator &AccessibilityOperator::GetInstanceForThread(std::thread::id threadId) +{ + HILOG_DEBUG("[%{public}s] threadId[%{public}u]", __func__, (*(uint32_t*)&threadId)); + std::lock_guard lock(mutex_); + if (instances_.size() >= MAX_INSTANCE) { + for (auto iter = instances_.begin(); iter != instances_.end();iter++) { + if (iter->GetRefPtr() != nullptr && + iter->GetRefPtr()->GetOperationStatus()) { + HILOG_DEBUG("[%{public}s] complete instance is removed", __func__); + instances_.erase(iter); + break; + } + } + } + + HILOG_DEBUG("[%{public}s] new instance instanceSize[%{public}u]", __func__, instances_.size()); + sptr inst(new AccessibilityOperator()); + instances_.push_back(inst); + + HILOG_DEBUG("[%{public}s] End instanceSize[%{public}u]", __func__, instances_.size()); + return *(inst.GetRefPtr()); +} + +sptr AccessibilityOperator::GetChannel(int channelId) +{ + auto channel = channels_.find(channelId); + if (channel != channels_.end()) { + HILOG_DEBUG("[%{public}s] Find aams [channelId:%{public}d]", __func__, channelId); + return channel->second; + } else { + HILOG_ERROR("[%{public}s] Failed to find aams [channelId:%{public}d]", __func__, channelId); + return nullptr; + } +} + +bool AccessibilityOperator::GetOperationStatus() +{ + HILOG_DEBUG("[%{public}s] [completed_:%{public}d]", __func__, completed_); + return completed_; +} + +void AccessibilityOperator::SetOperationStatus(bool status) +{ + completed_ = status; +} + +void AccessibilityOperator::AddChannel(const int channelId, const sptr &channel) +{ + HILOG_DEBUG("[%{public}s] Add connection to aams [channelId:%{public}d]", __func__, channelId); + int tempId = *(const_cast(&channelId)); + for (auto iter = channels_.begin(); iter != channels_.end(); iter++) { + if (iter->first == tempId) { + HILOG_ERROR("[%{public}s] Connection to aams [channelId:%{public}d] is exited", __func__, channelId); + return; + } + } + sptr tempChanel = const_cast &>(channel); + channels_.insert(std::pair>(tempId, tempChanel)); +} + +void AccessibilityOperator::RemoveChannel(int channelId) +{ + HILOG_DEBUG("[%{public}s] Remove connection to aams [channelId:%{public}d]", __func__, channelId); + auto iter = channels_.find(channelId); + if (iter != channels_.end()) { + channels_.erase(iter); + } else { + HILOG_DEBUG("[%{public}s] Failed to remove connection with aams [channelId:%{public}d]", __func__, channelId); + } +} + +bool AccessibilityOperator::GetRoot(int channelId, AccessibilityElementInfo &elementInfo) +{ + AccessibilityElementInfo element {}; + std::vector elementInfos {}; + bool result = SearchElementInfosByAccessibilityId(channelId, ACTIVE_WINDOW_ID, NONE_ID, 0, elementInfos); + for (auto& info : elementInfos) { + HILOG_DEBUG("[%{public}s] element [elementSize:%{public}d]", __func__, accessibilityInfosResult_.size()); + elementInfo = info; + break; + } + return result; +} + +std::vector AccessibilityOperator::GetWindows(int channelId) +{ + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + auto windows = connectService->GetWindows(); + for (auto &window : windows) { + window.SetChannelId(channelId); + } + return windows; + } else { + HILOG_ERROR("[%{public}s] Failed to connection to aams [channelId:%{public}d]", __func__, channelId); + return windows_; + } +} + +bool AccessibilityOperator::SearchElementInfosByAccessibilityId(int channelId, + int accessibilityWindowId, int elementId, int mode, std::vector& elementInfos) +{ + HILOG_DEBUG("[%{public}s] [channelId:%{public}d]", __func__, channelId); + bool result = false; + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + int requestId = CreateRequestId(); + HILOG_DEBUG("[%{public}s] search element info [channelId:%{public}d] [requestId:%{public}d]", __func__, + channelId, requestId); + result = connectService->SearchElementInfoByAccessibilityId(accessibilityWindowId, elementId, requestId, + this, mode); + if (!result) { + return result; + } + HILOG_DEBUG("[%{public}s] search element info End[channelId:%{public}d] [requestId:%{public}d]", __func__, + channelId, requestId); + if (!WaitForResultTimedLocked(requestId)) { + HILOG_ERROR("[%{public}s] Failed to wait result", __func__); + result = false; + return result; + } + } + HILOG_DEBUG("[%{public}s] search element info OK [channelId:%{public}d]", __func__, channelId); + for (auto& info : accessibilityInfosResult_) { + info.SetChannelId(channelId); + } + completed_ = true; + HILOG_DEBUG("[%{public}s] search element info End[size:%{public}d]", __func__, accessibilityInfosResult_.size()); + elementInfos = accessibilityInfosResult_; + return result; +} + +bool AccessibilityOperator::SearchElementInfosByText(int channelId, int accessibilityWindowId, + int elementId, const std::string &text,std::vector& elementInfos) +{ + HILOG_DEBUG("[%{public}s] [channelId:%{public}d]", __func__, channelId); + bool result = false; + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + int requestId = CreateRequestId(); + result = connectService->SearchElementInfosByText(accessibilityWindowId, elementId, text, requestId, + this); + if (!result) { + return result; + } + if (!WaitForResultTimedLocked(requestId)) { + HILOG_ERROR("[%{public}s] Failed to wait result", __func__); + result = false; + return result; + } + } + + for (auto& info : accessibilityInfosResult_) { + info.SetChannelId(channelId); + } + completed_ = true; + HILOG_DEBUG("[%{public}s] [size:%{public}d] end", __func__, accessibilityInfosResult_.size()); + elementInfos = accessibilityInfosResult_; + + return result; +} + +bool AccessibilityOperator::FindFocusedElementInfo(int channelId, int accessibilityWindowId, + int elementId, int focusType, AccessibilityElementInfo& elementInfo) +{ + HILOG_DEBUG("[%{public}s] [channelId:%{public}d]", __func__, channelId); + bool result = false; + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + int requestId = CreateRequestId(); + result = connectService->FindFocusedElementInfo(accessibilityWindowId, elementId, focusType, requestId, + this); + if (!result) { + return result; + } + HILOG_DEBUG( + "FindFocusedElementInfo channelId[%{public}d] elementId[%{public}d],\ + focusType[%{public}d] requestId[%{public}d]", + channelId, accessibilityWindowId, elementId, focusType); + if (!WaitForResultTimedLocked(requestId)) { + HILOG_ERROR("[%{public}s] Failed to wait result", __func__); + result = false; + return result; + } + } + accessibilityInfoResult_.SetChannelId(channelId); + completed_ = true; + HILOG_DEBUG("[%{public}s] [channelId:%{public}d] end", __func__, channelId); + elementInfo = accessibilityInfoResult_; + if (accessibilityInfoResult_.GetWindowId() == 0 && + accessibilityInfoResult_.GetAccessibilityId() == 0) { + HILOG_DEBUG("[%{public}s] Can't find the component info", __func__); + result = false; + } else { + result = true; + } + + return result; +} + +bool AccessibilityOperator::FocusMoveSearch(int channelId, int accessibilityWindowId, + int elementId, int direction, AccessibilityElementInfo& elementInfo) +{ + HILOG_DEBUG("[%{public}s] [channelId:%{public}d]", __func__, channelId); + bool result = false; + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + int requestId = CreateRequestId(); + result = connectService->FocusMoveSearch(accessibilityWindowId, elementId, direction, requestId, this); + if (!result) { + return result; + } + if (!WaitForResultTimedLocked(requestId)) { + HILOG_ERROR("[%{public}s] Failed to wait result", __func__); + result = false; + return result; + } + } + + accessibilityInfoResult_.SetChannelId(channelId); + completed_ = true; + HILOG_DEBUG("[%{public}s] [channelId:%{public}d] end", __func__, channelId); + elementInfo = accessibilityInfoResult_; + if (accessibilityInfoResult_.GetWindowId() == 0 && + accessibilityInfoResult_.GetAccessibilityId() == 0) { + HILOG_DEBUG("[%{public}s] Can't find the component info", __func__); + result = false; + } else { + result = true; + } + return result; +} + +bool AccessibilityOperator::PerformAction(int channelId, int accessibilityWindowId, + int elementId, int action, std::map &actionArguments) +{ + HILOG_DEBUG("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + int requestId = CreateRequestId(); + bool result = connectService->PerformAction(accessibilityWindowId, elementId, action, actionArguments, + requestId, + this); + if (!result) { + return result; + } + + if (!WaitForResultTimedLocked(requestId)) { + HILOG_ERROR("[%{public}s] Failed to wait result", __func__); + return false; + } + } + completed_ = true; + HILOG_DEBUG("[%{public}s] [channelId:%{public}d] end", __func__, channelId); + return performActionResult_; +} + +void AccessibilityOperator::SetSearchElementInfoByAccessibilityIdResult( + const std::vector &infos, const int requestId) +{ + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d]", __func__, requestId); + responseId_ = requestId; + for (auto iter = infos.begin(); iter != infos.end(); iter++) { + HILOG_DEBUG("[%{public}s] Response", __func__); + accessibilityInfosResult_.push_back(*iter); + } + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d] end", __func__, requestId); +} + +void AccessibilityOperator::SetSearchElementInfoByTextResult(const std::vector &infos, + const int requestId) +{ + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d]", __func__, requestId); + responseId_ = requestId; + for (auto iter = infos.begin(); iter != infos.end(); iter++) { + accessibilityInfosResult_.push_back(*iter); + } + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d] end", __func__, requestId); +} + +void AccessibilityOperator::SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info, const int requestId) +{ + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d]", __func__, requestId); + responseId_ = requestId; + accessibilityInfoResult_ = info; + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d] end", __func__, requestId); +} + +void AccessibilityOperator::SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int requestId) +{ + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d]", __func__, requestId); + responseId_ = requestId; + accessibilityInfoResult_ = info; + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d] end", __func__, requestId); +} + +void AccessibilityOperator::SetPerformActionResult(const bool succeeded, const int requestId) +{ + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d] result[%{public}d]", __func__, requestId, succeeded); + performActionResult_ = succeeded; + responseId_ = requestId; + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d] end", __func__, requestId); +} + +bool AccessibilityOperator::WaitForResultTimedLocked(const int requestId) +{ + std::lock_guard lock(mutex_); + struct timeval getTime {}; + gettimeofday(&getTime, NULL); + uint64_t startTime = getTime.tv_sec * SECOND_TO_MILLIS + getTime.tv_usec; + HILOG_DEBUG("[%{public}s] element requestId[%{public}d]", __func__, requestId); + + do { + if (responseId_ == requestId) { + return true; + } + gettimeofday(&getTime, NULL); + uint64_t endTime = getTime.tv_sec * SECOND_TO_MILLIS + getTime.tv_usec; + uint64_t waitTime = endTime - startTime; + if (TIMEOUT_OPERATOR_MILLIS < waitTime) { + completed_ = true; + HILOG_ERROR("[%{public}s] Failed to wait requestId[%{public}d], responseId_[%{public}d]", __func__, + requestId, responseId_); + return false; + } + usleep(SLEEP_MILLIS); + } while (true); + HILOG_DEBUG("[%{public}s] Response [requestId:%{public}d] end", __func__, requestId); + return true; +} + +int AccessibilityOperator::CreateRequestId() +{ + std::lock_guard lock(mutex_); + HILOG_INFO("[%{public}s] [requestId_:%{public}d]", __func__, requestId_); + requestId_++; + requestId_ = requestId_ % MAX_REQUEST; + HILOG_INFO("[%{public}s] [requestId_:%{public}d] end", __func__, requestId_); + return requestId_; +} + +bool AccessibilityOperator::PerformCommonAction(const int channelId, const int action) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + return connectService->PerformCommonAction(action); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + return false; + } +} + +void AccessibilityOperator::DisableAbility(const int channelId) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + connectService->DisableAbility(); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + } +} + +void AccessibilityOperator::SetOnKeyPressEventResult(const int channelId, const bool handled, const int sequence) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + connectService->SetOnKeyPressEventResult(handled, sequence); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + } +} + +float AccessibilityOperator::GetDisplayResizeScale(const int channelId, const int displayId) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + return connectService->GetDisplayResizeScale(displayId); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + return 1; + } +} + +float AccessibilityOperator::GetDisplayResizeCenterX(const int channelId, const int displayId) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + return connectService->GetDisplayResizeCenterX(displayId); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + return 1; + } +} + +float AccessibilityOperator::GetDisplayResizeCenterY(const int channelId, const int displayId) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + return connectService->GetDisplayResizeCenterY(displayId); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + return 1; + } +} + +Rect AccessibilityOperator::GetDisplayResizeRect(const int channelId, const int displayId) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + return connectService->GetDisplayResizeRect(displayId); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + Rect rect {}; + return rect; + } +} + +bool AccessibilityOperator::ResetDisplayResize(const int channelId, const int displayId, const bool animate) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + return connectService->ResetDisplayResize(displayId, animate); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + return false; + } +} + +bool AccessibilityOperator::SetDisplayResizeScaleAndCenter(const int channelId, + const int displayId, const float scale, const float centerX, + const float centerY, const bool animate) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + return connectService->SetDisplayResizeScaleAndCenter(displayId, scale, centerX, + centerY, animate); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + return false; + } +} + +void AccessibilityOperator::SendSimulateGesture(const int channelId, + const int sequence, const std::vector &gestureSteps) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + connectService->SendSimulateGesture(sequence, gestureSteps); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + } +} + +bool AccessibilityOperator::IsFingerprintGestureDetectionValid(const int channelId) +{ + HILOG_INFO("[%{public}s] [channelId:%{public}d]", __func__, channelId); + auto connectService = GetChannel(channelId); + if (connectService != nullptr) { + return connectService->IsFingerprintGestureDetectionValid(); + } else { + HILOG_ERROR("[%{public}s] Failed to Get connection to aams [channelId:%{public}d]", __func__, channelId); + return false; + } +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessibility_state_event.cpp b/frameworks/asacfwk/src/accessibility_state_event.cpp new file mode 100644 index 00000000..55b18c23 --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_state_event.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_state_event.h" + +namespace OHOS { +namespace Accessibility { + +AccessibilityStateEvent::AccessibilityStateEvent() +{ + +} + +AccessibilityStateEventType AccessibilityStateEvent::GetEventType() const +{ + return eventType_; +} + +int AccessibilityStateEvent::GetEventResult() const +{ + return enabled_; +} + +std::string AccessibilityStateEvent::GetEventMsg() const +{ + return describeEvent_; +} + +void AccessibilityStateEvent::SetEventType(const AccessibilityStateEventType eventType) +{ + eventType_ = *(const_cast(&eventType)); +} + +void AccessibilityStateEvent::SetEventResult(const int enabled) +{ + enabled_ = enabled; +} + +void AccessibilityStateEvent::SetEventMsg(std::string &description) +{ + describeEvent_ = description; +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessibility_system_ability_client.cpp b/frameworks/asacfwk/src/accessibility_system_ability_client.cpp new file mode 100644 index 00000000..727dc2a9 --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_system_ability_client.cpp @@ -0,0 +1,576 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_system_ability_client.h" +#include "ability_context.h" +#include "accessible_ability_manager_service_proxy.h" +#include "accessibility_interaction_operation.h" +#include "accessible_ability_manager_service_state_stub.h" +#include "accessibility_interaction_operation_stub.h" +#include "dummy.h" +#include "hilog_wrapper.h" +#include "iservice_registry.h" +#include "if_system_ability_manager.h" +#include "system_ability_definition.h" + +using namespace OHOS::AppExecFwk; +using namespace std; + +namespace OHOS { +namespace Accessibility { +shared_ptr AccessibilitySystemAbilityClient::instance_ = nullptr; + +struct AccessibilitySystemAbilityClient::Impl { + class DeathRecipient : public IRemoteObject::DeathRecipient { + public: + DeathRecipient() = default; + ~DeathRecipient() = default; + DISALLOW_COPY_AND_MOVE(DeathRecipient); + + void OnRemoteDied(const wptr& remote) { + AccessibilitySystemAbilityClient::GetInstance()->ResetService(remote); + } + }; + sptr deathRecipient_{}; + sptr stateCallback_{}; + sptr serviceProxy_{}; + sptr GetService() { + if (serviceProxy_ != nullptr) { + return serviceProxy_; + } + + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + HILOG_ERROR("[%s] Failed to get ISystemAbilityManager", __func__); + return nullptr; + } + + sptr object = samgr->GetSystemAbility(ACCESSIBLE_ABILITY_MANAGER_SERVICE_ID); + if (object == nullptr) { + HILOG_ERROR("[%s]Get IAccessibleAbilityManagerServiceClient object from samgr failed", __func__); + return nullptr; + } + + if (deathRecipient_ == nullptr) { + deathRecipient_ = new DeathRecipient(); + } + + if ((object->IsProxyObject()) && (!object->AddDeathRecipient(deathRecipient_))) { + HILOG_ERROR("Failed to add death recipient"); + } + + HILOG_DEBUG("get remote object ok"); + serviceProxy_ = iface_cast(object); + if (serviceProxy_ == nullptr) { + HILOG_ERROR("IAccessibleAbilityManagerServiceClient iface_cast failed"); + } + return serviceProxy_; + } + +}; + +AccessibilitySystemAbilityClient::AccessibilitySystemAbilityClient(const Context &context, + int accountId) : pimpl(std::make_unique()) +{ + interactionOperator_ = nullptr; + accountId_ = accountId; + pimpl->stateCallback_ = new AccessibleAbilityManagerServiceStateStub(); + auto proxyService = pimpl->GetService(); + if (proxyService == nullptr) { + HILOG_ERROR("[%{public}s] Failed to get aams service", __func__); + return; + } + uint32_t stateType = proxyService->RegisterStateCallback(pimpl->stateCallback_, accountId_); + + if (stateType & AccessibilitySystemAbilityClient::STATE_ACCESSIBILITY_ENABLED) { + isEnabled_ = true; + } else { + isEnabled_ = false; + } + + if (stateType & AccessibilitySystemAbilityClient::STATE_EXPLORATION_ENABLED) { + isTouchExplorationEnabled_ = true; + } else { + isTouchExplorationEnabled_ = false; + } + +} + +void AccessibilitySystemAbilityClient::Interrupt() //Remained: target app called +{ + HILOG_DEBUG("AccessibilitySystemAbilityClient Interrupt"); + + auto proxyService = pimpl->GetService(); + if (proxyService == nullptr) { + HILOG_ERROR("[%{public}s] Failed to get aams service", __func__); + return; + } + proxyService->Interrupt(accountId_); + + HILOG_DEBUG("AccessibilitySystemAbilityClient Interrupt OK"); +} + +void AccessibilitySystemAbilityClient::ResetService(const wptr& remote) +{ + HILOG_DEBUG("[%{public}s]", __func__); + std::lock_guard lock(asacProxyLock_); + if (pimpl->serviceProxy_ != nullptr) { + sptr object = pimpl->serviceProxy_->GetObject(); + if ((object != nullptr) && (remote == object)) { + object->RemoveDeathRecipient(pimpl->deathRecipient_); + pimpl->serviceProxy_ = nullptr; + HILOG_DEBUG("[%{public}s] Reset OK", __func__); + } + } +} + +int AccessibilitySystemAbilityClient::RegisterInteractionOperation(const int windowId, + const shared_ptr &operation, int user) +{ + HILOG_INFO("[%{public}s]", __func__); + if (!operation) { + HILOG_ERROR("[%{public}s] Input operation is null", __func__); + return -1; + } + int result = 0; + connectionWindowId_ = windowId; + for (auto iter = interactionOperators_.begin(); iter != interactionOperators_.end(); iter++) { + if (iter->first == windowId) { + HILOG_ERROR("[%{public}s] windowID[%{public}d] is exited", __func__, windowId); + return result; + } + } + interactionOperators_.insert(pair>(windowId, operation)); + if (operation != nullptr) { + interactionOperator_ = operation; + sptr aamsInteractionOperator = + new AccessibilityInteractionOperationStub(); + aamsInteractionOperator->SetWindowId(windowId); + auto proxyService = pimpl->GetService(); + if (proxyService == nullptr) { + HILOG_ERROR("[%{public}s] Failed to get aams service", __func__); + return -1; + } + proxyService->RegisterInteractionOperation(windowId, aamsInteractionOperator, user); + } else { + HILOG_DEBUG("AccessibilitySystemAbilityClient had register AccessibilityInteractionOperation."); + } + + return result; +} + +void AccessibilitySystemAbilityClient::DeregisterInteractionOperation(const int windowId) +{ + HILOG_DEBUG("[%{public}s]", __func__); + auto proxyService = pimpl->GetService(); + if (proxyService == nullptr) { + HILOG_ERROR("[%{public}s] Failed to get aams service", __func__); + return; + } + proxyService->DeregisterInteractionOperation(windowId); + for (auto iter = interactionOperators_.begin(); iter != interactionOperators_.end(); iter++) { + if (iter->first == windowId) { + HILOG_DEBUG("[%{public}s] windowID[%{public}d] is erase", __func__, windowId); + interactionOperator_ = nullptr; + connectionWindowId_ = -1; + interactionOperators_.erase(iter); + return; + } + } + HILOG_DEBUG("[%{public}s] Not find windowID[%{public}d]", __func__, windowId); +} + +shared_ptr AccessibilitySystemAbilityClient::GetInteractionObject(int windowId) +{ + HILOG_DEBUG("[%{public}s] windowId[%{public}d]", __func__, windowId); + for (auto it = interactionOperators_.begin(); it != interactionOperators_.end(); it++) { + if (it->second != nullptr && it->first == windowId) { + HILOG_DEBUG("[%{public}s] find interaction object windowId[%{public}d]", __func__, windowId); + return it->second; + } + } + HILOG_DEBUG("[%{public}s] Failed to get interaction", __func__); + return nullptr; +} + +bool AccessibilitySystemAbilityClient::IsEnabled() +{ + HILOG_DEBUG("[%{public}s] isEnabled_[%{public}d]", __func__, isEnabled_); + return isEnabled_; +} + +bool AccessibilitySystemAbilityClient::IsTouchExplorationEnabled() +{ + HILOG_DEBUG("[%{public}s] isEnabled_[%{public}d]", __func__, isTouchExplorationEnabled_); + return isTouchExplorationEnabled_; +} + +std::vector AccessibilitySystemAbilityClient::GetAbilityList( + const int accessibilityAbilityTypes, const AbilityStateType stateType) +{ + HILOG_DEBUG("[%{public}s]", __func__); + bool check = false; + if ((accessibilityAbilityTypes & AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN) || + (accessibilityAbilityTypes & AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_HAPTIC) || + (accessibilityAbilityTypes & AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_AUDIBLE) || + (accessibilityAbilityTypes & AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_VISUAL) || + (accessibilityAbilityTypes & AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_GENERIC)) { + check = true; + } + if (stateType == ABILITY_STATE_INVALID) { + check = false; + } + auto proxyService = pimpl->GetService(); + if (proxyService == nullptr || !check) { + HILOG_ERROR("[%{public}s] Failed to get aams service", __func__); + std::vector infos; + return infos; + } + return (proxyService->GetAbilityList(accessibilityAbilityTypes, stateType)); +} + +shared_ptr AccessibilitySystemAbilityClient::GetInstance( + const Context &abilityContext) +{ + HILOG_DEBUG("[%{public}s]", __func__); + if (instance_ == nullptr) { + int accountId = 0; + instance_ = std::make_shared(abilityContext, accountId); + } else { + HILOG_DEBUG("IAccessibleAbilityManagerServiceClient had construct instance"); + } + + return instance_; +} + +shared_ptr AccessibilitySystemAbilityClient::GetInstance() +{ + HILOG_DEBUG("[%{public}s]", __func__); + AbilityContext abilityContext {}; + if (instance_ == nullptr) { + int accountId = 0; + instance_ = std::make_shared(abilityContext, accountId); + } else { + HILOG_DEBUG("IAccessibleAbilityManagerServiceClient had construct instance"); + } + + return instance_; +} + +int AccessibilitySystemAbilityClient::GetSuggestedInterval(const int timeout, const int contentType) +{ + HILOG_DEBUG("[%{public}s]", __func__); + int interval = 0; + int64_t timeSuggested = 0; + auto proxyService = pimpl->GetService(); + if (proxyService == nullptr) { + HILOG_ERROR("[%{public}s] Failed to get aams service", __func__); + return -1; + } + timeSuggested = proxyService->GetSuggestedInterval(); + if (contentType == CONTENT_CONTROLS) { + interval = timeSuggested; + } else { + interval = timeSuggested >> NUM_INT32; + } + + if (interval < timeout) { + interval = timeout; + } + return interval; +} + +CaptionProperties AccessibilitySystemAbilityClient::GetAccessibilityCaptionProperties() const +{ + HILOG_DEBUG("[%{public}s]", __func__); + return captionProperties_; +} + +bool AccessibilitySystemAbilityClient::IsAccessibilityCaptionEnabled() const +{ + HILOG_DEBUG("[%{public}s]", __func__); + return true; +} + +bool AccessibilitySystemAbilityClient::CheckEventType(EventType eventType) +{ + if ((eventType & EventType::TYPE_VIEW_CLICKED_EVENT) != EventType::TYPE_VIEW_CLICKED_EVENT && + (eventType & EventType::TYPE_VIEW_LONG_CLICKED_EVENT) != EventType::TYPE_VIEW_LONG_CLICKED_EVENT && + (eventType & EventType::TYPE_VIEW_SELECTED_EVENT) != EventType::TYPE_VIEW_SELECTED_EVENT && + (eventType & EventType::TYPE_VIEW_FOCUSED_EVENT) != EventType::TYPE_VIEW_FOCUSED_EVENT && + (eventType & EventType::TYPE_VIEW_TEXT_UPDATE_EVENT) != EventType::TYPE_VIEW_TEXT_UPDATE_EVENT && + (eventType & EventType::TYPE_PAGE_STATE_UPDATE) != EventType::TYPE_PAGE_STATE_UPDATE && + (eventType & EventType::TYPE_NOTIFICATION_UPDATE_EVENT) != EventType::TYPE_NOTIFICATION_UPDATE_EVENT && + (eventType & EventType::TYPE_VIEW_HOVER_ENTER_EVENT) != EventType::TYPE_VIEW_HOVER_ENTER_EVENT && + (eventType & EventType::TYPE_VIEW_HOVER_EXIT_EVENT) != EventType::TYPE_VIEW_HOVER_EXIT_EVENT && + (eventType & EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN) != EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN && + (eventType & EventType::TYPE_TOUCH_GUIDE_GESTURE_END) != EventType::TYPE_TOUCH_GUIDE_GESTURE_END && + (eventType & EventType::TYPE_PAGE_CONTENT_UPDATE) != EventType::TYPE_PAGE_CONTENT_UPDATE && + (eventType & EventType::TYPE_VIEW_SCROLLED_EVENT) != EventType::TYPE_VIEW_SCROLLED_EVENT && + (eventType & EventType::TYPE_VIEW_TEXT_SELECTION_UPDATE_EVENT) != + EventType::TYPE_VIEW_TEXT_SELECTION_UPDATE_EVENT && + (eventType & EventType::TYPE_PUBLIC_NOTICE_EVENT) != EventType::TYPE_PUBLIC_NOTICE_EVENT && + (eventType & EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT) != + EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT && + (eventType & EventType::TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED_EVENT) != + EventType::TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED_EVENT && + (eventType & EventType::TYPE_VIEW_TEXT_MOVE_UNIT_EVENT) != EventType::TYPE_VIEW_TEXT_MOVE_UNIT_EVENT && + (eventType & EventType::TYPE_TOUCH_GUIDE_BEGIN) != EventType::TYPE_TOUCH_GUIDE_BEGIN && + (eventType & EventType::TYPE_TOUCH_GUIDE_END) != EventType::TYPE_TOUCH_GUIDE_END && + (eventType & EventType::TYPE_TOUCH_BEGIN) != EventType::TYPE_TOUCH_BEGIN && + (eventType & EventType::TYPE_TOUCH_END) != EventType::TYPE_TOUCH_END && + (eventType & EventType::TYPE_WINDOW_UPDATE) != EventType::TYPE_WINDOW_UPDATE && + (eventType & EventType::TYPES_ALL_MASK) != EventType::TYPES_ALL_MASK) { + HILOG_ERROR("[%{public}s] event type is invalid", __func__); + return false; + + } else { + return true; + } +} + +bool AccessibilitySystemAbilityClient::SendEvent(const EventType eventType, const int componentId) +{ + HILOG_DEBUG("[%{public}s] componentId[%{public}d], eventType[%{public}d]", __func__, componentId, eventType); + if (!CheckEventType(eventType)) { + return false; + } + AccessibilityEventInfo event; + event.SetEventType(eventType); + event.SetSource(componentId); + auto proxyService = pimpl->GetService(); + if (proxyService == nullptr) { + HILOG_ERROR("[%{public}s] Failed to get aams service", __func__); + return false; + } + proxyService->SendEvent(event, accountId_); + return true; +} + +bool AccessibilitySystemAbilityClient::SendEvent(const AccessibilityEventInfo &event) +{ + HILOG_DEBUG("[%{public}s] EventType[%{public}d]", __func__, event.GetEventType()); + if (!CheckEventType(event.GetEventType())) { + return false; + } + auto proxyService = pimpl->GetService(); + if (proxyService == nullptr) { + HILOG_ERROR("[%{public}s] Failed to get aams service", __func__); + return false; + } + proxyService->SendEvent(event, accountId_); + return true; +} + +bool AccessibilitySystemAbilityClient::SubscribeStateObserver(const shared_ptr &observer, + const int eventType) +{ + HILOG_DEBUG("[%{public}s]", __func__); + if (eventType != AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED && + eventType != AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED) { + HILOG_ERROR("[%{public}s] Input eventType is out of scope", __func__); + return false; + } + if (!observer) { + HILOG_ERROR("[%{public}s] Input observer is null", __func__); + return false; + } + AccessibilityStateEventType et = AccessibilityStateEventType( + *(const_cast(&eventType))); + shared_ptr ob = const_cast &>(observer); + if (et == AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED) { + observersAceessibilityState_.push_back(ob); + } else { + observersTouchState_.push_back(ob); + } + HILOG_DEBUG("[%{public}s] end", __func__); + return true; +} + +bool AccessibilitySystemAbilityClient::UnsubscribeStateObserver(const shared_ptr &observer, + const int eventType) +{ + HILOG_DEBUG("[%{public}s]", __func__); + if (eventType != AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED && + eventType != AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED) { + HILOG_ERROR("[%{public}s] Input eventType is out of scope", __func__); + return false; + } + if (!observer) { + HILOG_ERROR("[%{public}s] Input observer is null", __func__); + return false; + } + AccessibilityStateEventType et = AccessibilityStateEventType(*(const_cast(&eventType))); + if (et == AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED) { + for (auto it = observersAceessibilityState_.begin(); it != observersAceessibilityState_.end(); it++) { + if (*it == observer) { + observersAceessibilityState_.erase(it); + return true; + } + } + } else { + for (auto it = observersTouchState_.begin(); it != observersTouchState_.end(); it++) { + if (*it == observer) { + observersTouchState_.erase(it); + return true; + } + } + } + HILOG_DEBUG("%{public}s Not find eventType[%{public}d]" , __func__, eventType); + return false; +} + +bool AccessibilitySystemAbilityClient::UnsubscribeStateObserver(const shared_ptr &observer) +{ + HILOG_DEBUG("[%{public}s]", __func__); + if (!observer) { + HILOG_ERROR("[%{public}s] Input observer is null", __func__); + return false; + } + bool result = false; + for (auto it = observersAceessibilityState_.begin(); it != observersAceessibilityState_.end(); it++) { + if (*it == observer) { + observersAceessibilityState_.erase(it); + result = true; + break; + } + } + + for (auto it = observersTouchState_.begin(); it != observersTouchState_.end(); it++) { + if (*it == observer) { + observersTouchState_.erase(it); + result = true; + break; + } + } + return result; +} + +void AccessibilitySystemAbilityClient::SetEnabled(const bool enabled) +{ + HILOG_DEBUG("%{public}s" , __func__); + isEnabled_ = enabled; + NotifyAccessibilityStateChanged(); + HILOG_DEBUG("[%{public}s] end", __func__); +} + +void AccessibilitySystemAbilityClient::SetTouchExplorationEnabled(const bool enabled) +{ + HILOG_DEBUG("%{public}s" , __func__); + isTouchExplorationEnabled_ = enabled; + NotifyTouchExplorationStateChanged(); + HILOG_DEBUG("[%{public}s] end", __func__); +} + +void AccessibilitySystemAbilityClient::NotifyAccessibilityStateChanged() +{ + HILOG_DEBUG("%{public}s" , __func__); + std::lock_guard lock(asacProxyLock_); + if (observersAceessibilityState_.size() == 0) { + HILOG_DEBUG("%{public}s observersAceessibilityState_ is null" , __func__); + return; + } + for (auto it = observersAceessibilityState_.begin(); it != observersAceessibilityState_.end(); it++) { + AccessibilityStateEvent stateEvent; + stateEvent.SetEventType(EVENT_ACCESSIBILITY_STATE_CHANGED); + stateEvent.SetEventResult(isEnabled_); + if (*it != nullptr && it->get() != nullptr) { + it->get()->OnStateChanged(stateEvent); + } else { + HILOG_ERROR("%{public}s end observersAceessibilityState_ is null" , __func__); + } + } + HILOG_DEBUG("[%{public}s] end", __func__); +} + +void AccessibilitySystemAbilityClient::NotifyTouchExplorationStateChanged() +{ + HILOG_DEBUG("[%{public}s]", __func__); + std::lock_guard lock(asacProxyLock_); + if (observersTouchState_.size() == 0) { + HILOG_DEBUG("%{public}s observersTouchState_ is null" , __func__); + return; + } + for (auto it = observersTouchState_.begin(); it != observersTouchState_.end(); it++) { + AccessibilityStateEvent stateEvent; + stateEvent.SetEventType(EVENT_TOUCH_GUIDE_STATE_CHANGED); + stateEvent.SetEventResult(isTouchExplorationEnabled_); + if (*it != nullptr && it->get() != nullptr) { + it->get()->OnStateChanged(stateEvent); + } else { + HILOG_ERROR("%{public}s end observersTouchState_ is null" , __func__); + } + } + HILOG_DEBUG("[%{public}s] end", __func__); +} + +bool CaptionProperties::CheckProperty(const std::string &property) +{ + bool result = true; + return result; +} + +int CaptionProperties::GetBackgroundColor() const +{ + return backgroundColor_; +} + +int CaptionProperties::GetForegroundColor() const +{ + return foregroundColor_; +} + +int CaptionProperties::GetEdgeType() const +{ + return edgeType_; +} + +int CaptionProperties::GetEdgeColor() const +{ + return edgeColor_; +} + +int CaptionProperties::GetWindowColor() const +{ + return windowColor_; +} + +bool CaptionProperties::HasBackgroundColor() +{ + return hasBackgroundColor_; +} + +bool CaptionProperties::HasForegroundColor() +{ + return hasForegroundColor_; +} + +bool CaptionProperties::HasEdgeType() +{ + return hasEdgeType_; +} + +bool CaptionProperties::HasEdgeColor() +{ + return hasEdgeColor_; +} + +bool CaptionProperties::HasWindowColor() +{ + return hasWindowColor_; +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessibility_window_info.cpp b/frameworks/asacfwk/src/accessibility_window_info.cpp new file mode 100644 index 00000000..75264714 --- /dev/null +++ b/frameworks/asacfwk/src/accessibility_window_info.cpp @@ -0,0 +1,319 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_window_info.h" +#include "accessibility_operator.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace Accessibility { + +/* AccessibleAction Parcel struct */ +bool AccessibilityWindowInfo::ReadFromParcel(Parcel &parcel) +{ + int windowType = TYPE_WINDOW_INVALID; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowType); + windowType_ = static_cast(windowType); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowLayer_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, parentId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, windowTitle_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32Vector, parcel, &childIds_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, anchorId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, childNum_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, channelId_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, active_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, focused_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessibilityFocused_); + std::shared_ptr boundsInScreen(parcel.ReadParcelable()); + if (!boundsInScreen) { + HILOG_ERROR("ReadParcelable boundsInScreen failed."); + return false; + } + boundsInScreen_ = *boundsInScreen; + + return true; +} + +bool AccessibilityWindowInfo::Marshalling(Parcel &parcel) const +{ + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast(windowType_)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowLayer_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, parentId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, windowTitle_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32Vector, parcel, childIds_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, anchorId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, childNum_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, channelId_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, active_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, focused_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessibilityFocused_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &boundsInScreen_); + + return true; +}; + +AccessibilityWindowInfo* AccessibilityWindowInfo::Unmarshalling(Parcel& parcel) +{ + AccessibilityWindowInfo *accessibilityWindow = new AccessibilityWindowInfo(); + if (!accessibilityWindow->ReadFromParcel(parcel)) { + delete accessibilityWindow; + accessibilityWindow = nullptr; + } + return accessibilityWindow; +} + +std::string AccessibilityWindowInfo::GetWindowTitle() const +{ + HILOG_DEBUG("[%{public}s] windowTitle_[%{public}s]", __func__, windowTitle_.c_str()); + return windowTitle_; +} + +void AccessibilityWindowInfo::SetWindowTitle(std::string &title) +{ + windowTitle_ = title; + HILOG_DEBUG("[%{public}s] windowTitle_[%{public}s]", __func__, windowTitle_.c_str()); +} + +WindowType AccessibilityWindowInfo::GetWindowType() const +{ + HILOG_DEBUG("[%{public}s] windowType_[%{public}d]", __func__, windowType_); + return windowType_; +} + +void AccessibilityWindowInfo::SetWindowType(const WindowType type) +{ + windowType_ = type; + HILOG_DEBUG("[%{public}s] windowType_[%{public}d]", __func__, windowType_); +} + +int AccessibilityWindowInfo::GetWindowLayer() const +{ + HILOG_DEBUG("[%{public}s] windowLayer_[%{public}d]", __func__, windowLayer_); + return windowLayer_; +} + +void AccessibilityWindowInfo::SetWindowLayer(const int layer) +{ + windowLayer_ = layer; + HILOG_DEBUG("[%{public}s] windowLayer_[%{public}d]", __func__, windowLayer_); +} + +bool AccessibilityWindowInfo::GetRootAccessibilityInfo(AccessibilityElementInfo &elementInfo) +{ + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], windowId_[%{public}d]", + __func__, channelId_, windowId_); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + + std::vector elementInfos {}; + bool result = false; + if (instance != nullptr) { + result = instance->SearchElementInfosByAccessibilityId(channelId_, windowId_, -1, 0, elementInfos); + if (elementInfos.empty()) { + result = false; + } else { + elementInfo = elementInfos.front(); + } + } else { + HILOG_INFO("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return result; +} + +void AccessibilityWindowInfo::SetAnchorId(const int anchorId) +{ + anchorId_ = anchorId; + HILOG_DEBUG("[%{public}s] anchorId_[%{public}d]", __func__, anchorId_); +} + +bool AccessibilityWindowInfo::GetAnchor(AccessibilityElementInfo &elementInfo) +{ + HILOG_DEBUG("GetAnchor of windowInfo is not support!"); + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], windowId_[%{public}d], anchorId_[%{public}d]", + __func__, channelId_, windowId_, anchorId_); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + + std::vector elementInfos {}; + bool result = false; + if (instance != nullptr) { + result = instance->SearchElementInfosByAccessibilityId(channelId_, windowId_, anchorId_, 0, elementInfos); + if (elementInfos.empty()) { + result = false; + } else { + elementInfo = elementInfos.front(); + } + } else { + HILOG_INFO("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return result; +} + +AccessibilityWindowInfo AccessibilityWindowInfo::GetParent() +{ + HILOG_DEBUG("GetParent of windowInfo is not support!"); + AccessibilityWindowInfo win {}; + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], parentId_[%{public}d]", + __func__, channelId_, parentId_); + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + if (instance != nullptr) { + for (auto window : instance->GetWindows(channelId_)) { + if (window.GetWindowId() == parentId_) { + return window; + } + } + } else { + HILOG_INFO("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return win; +} + +void AccessibilityWindowInfo::SetParentId(const int parentId) +{ + parentId_ = parentId; + HILOG_DEBUG("[%{public}s] parentId_[%{public}d]", __func__, parentId_); +} + +int AccessibilityWindowInfo::GetParentId() +{ + HILOG_DEBUG("[%{public}s] parentId_[%{public}d]", __func__, parentId_); + return parentId_; +} + +std::vector AccessibilityWindowInfo::GetChildIds() +{ + return childIds_; +} + +int AccessibilityWindowInfo::GetAnchorId() +{ + HILOG_DEBUG("[%{public}s] anchorId_[%{public}d]", __func__, anchorId_); + return anchorId_; +} +int AccessibilityWindowInfo::GetWindowId() const +{ + HILOG_DEBUG("[%{public}s] windowId_[%{public}d]", __func__, windowId_); + return windowId_; +} + +void AccessibilityWindowInfo::SetWindowId(const int id) +{ + windowId_ = id; + HILOG_DEBUG("[%{public}s] windowId_[%{public}d]", __func__, windowId_); +} + +void AccessibilityWindowInfo::SetChannelId(const int channelId) +{ + channelId_ = channelId; + HILOG_DEBUG("[%{public}s] channelId_[%{public}d]", __func__, channelId_); +} + +int AccessibilityWindowInfo::GetChannelId() const +{ + HILOG_DEBUG("[%{public}s] channelId_[%{public}d]", __func__, channelId_); + return channelId_; +} + +Rect AccessibilityWindowInfo::GetRectInScreen() const +{ + return boundsInScreen_; +} + +void AccessibilityWindowInfo::SetRectInScreen(const Rect &bounds) +{ + boundsInScreen_.SetLeftTopScreenPostion(const_cast(bounds).GetLeftTopXScreenPostion(), + const_cast(bounds).GetLeftTopYScreenPostion()); + boundsInScreen_.SetRightBottomScreenPostion(const_cast(bounds).GetRightBottomXScreenPostion(), + const_cast(bounds).GetRightBottomYScreenPostion()); +} + +bool AccessibilityWindowInfo::IsActive() const +{ + HILOG_DEBUG("[%{public}s] active_[%{public}d]", __func__, active_); + return active_; +} + +void AccessibilityWindowInfo::SetActive(bool active) +{ + active_ = active; + HILOG_DEBUG("[%{public}s] active_[%{public}d]", __func__, active_); +} + +bool AccessibilityWindowInfo::IsFocused() const +{ + HILOG_DEBUG("[%{public}s] focused_[%{public}d]", __func__, focused_); + return focused_; +} + +void AccessibilityWindowInfo::SetFocused(bool focused) +{ + focused_ = focused; + HILOG_DEBUG("[%{public}s] focused_[%{public}d]", __func__, focused_); +} + +bool AccessibilityWindowInfo::IsAccessibilityFocused() const +{ + HILOG_DEBUG("[%{public}s] accessibilityFocused_[%{public}d]", __func__, accessibilityFocused_); + return accessibilityFocused_; +} + +void AccessibilityWindowInfo::SetAccessibilityFocused(const bool accessibilityfocused) +{ + accessibilityFocused_ = accessibilityfocused; + HILOG_DEBUG("[%{public}s] accessibilityFocused_[%{public}d]", __func__, accessibilityFocused_); +} + +int AccessibilityWindowInfo::GetChildNum() const +{ + HILOG_DEBUG("[%{public}s] childNum_[%{public}d]", __func__, childNum_); + return childNum_; +} + +AccessibilityWindowInfo AccessibilityWindowInfo::GetChild(const int index) +{ + HILOG_DEBUG("GetChild of windowInfo is not support!"); + AccessibilityWindowInfo win {}; + HILOG_INFO("[%{public}s] called] channelId_[%{public}d], childNum_[%{public}d], index[%{public}d]", + __func__, channelId_, childNum_, index); + if (index >= childNum_ || index < 0) { + HILOG_ERROR("[%{public}s] called] index[%{public}d] is invalid", __func__, index); + return win; + } + AccessibilityOperator * instance = &AccessibilityOperator::GetInstance(); + if (instance != nullptr) { + for (auto window : instance->GetWindows(channelId_)) { + if (window.GetWindowId() == childIds_[index]) { + return window; + } + } + } else { + HILOG_INFO("[%{public}s] called] Can't get AccessibilityOperator instance", __func__); + } + return win; +} + +void AccessibilityWindowInfo::AddChild(const int childId) +{ + childIds_.push_back(childId); + childNum_++; +} + +AccessibilityWindowInfo::AccessibilityWindowInfo() +{ + +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessible_ability_channel_proxy.cpp b/frameworks/asacfwk/src/accessible_ability_channel_proxy.cpp new file mode 100644 index 00000000..4aabbce3 --- /dev/null +++ b/frameworks/asacfwk/src/accessible_ability_channel_proxy.cpp @@ -0,0 +1,596 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessible_ability_channel_proxy.h" +#include "parcel.h" +#include "accessibility_errorcode.h" + +using namespace std; + +namespace OHOS { +namespace Accessibility { + +AccessibleAbilityChannelProxy::AccessibleAbilityChannelProxy( + const sptr &object): IRemoteProxy(object) +{ + +} + +bool AccessibleAbilityChannelProxy::WriteInterfaceToken(MessageParcel &data) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + if (!data.WriteInterfaceToken(AccessibleAbilityChannelProxy::GetDescriptor())) { + HILOG_ERROR("write interface token failed"); + return false; + } + return true; +} + +bool AccessibleAbilityChannelProxy::SendTransactCmd(IAccessibleAbilityChannel::Message code, + MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + sptr remote = Remote(); + if (!remote) { + HILOG_ERROR("fail to send transact cmd %{public}d due to remote object", code); + return false; + } + int32_t result = remote->SendRequest(static_cast(code), data, reply, option); + if (result != NO_ERROR) { + HILOG_ERROR("receive error transact code %{public}d in transact cmd %{public}d", result, code); + return false; + } + return true; +} + +bool AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const int accessibilityWindowId, + const long elementId, const int requestId, const sptr &callback, + const int mode) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return false; + } + if (!data.WriteInt32(accessibilityWindowId)) { + HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); + return false; + } + if (!data.WriteInt64(elementId)) { + HILOG_ERROR("elementId write error: %{public}ld, ", elementId); + return false; + } + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("requestId write error: %{public}d, ", requestId); + return false; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("callback write error"); + return false; + } + if (!data.WriteInt32(mode)) { + HILOG_ERROR("mode write error: %{public}d, ", mode); + return false; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::SEARCH_ELEMENTINFO_BY_ACCESSIBILITYID, + data, reply, option)) { + HILOG_ERROR("fail to find elementInfo by elementId"); + return false; + } + return reply.ReadBool(); +} + +bool AccessibleAbilityChannelProxy::SearchElementInfosByText(const int accessibilityWindowId, + const long elementId, const std::string &text, const int requestId, + const sptr &callback) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return false; + } + if (!data.WriteInt32(accessibilityWindowId)) { + HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); + return false; + } + if (!data.WriteInt32(elementId)) { + HILOG_ERROR("elementId write error: %{public}ld, ", elementId); + return false; + } + if (!data.WriteString(text)) { + HILOG_ERROR("text write error: %{public}s, ", text.c_str()); + return false; + } + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("requestId write error: %{public}d, ", requestId); + return false; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("callback write error"); + return false; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::SEARCH_ELEMENTINFOS_BY_TEXT, + data, reply, option)) { + HILOG_ERROR("fail to find elementInfo by text"); + return false; + } + return reply.ReadBool(); +} + +bool AccessibleAbilityChannelProxy::FindFocusedElementInfo(const int accessibilityWindowId, + const long elementId, const int focusType, const int requestId, + const sptr &callback) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return false; + } + if (!data.WriteInt32(accessibilityWindowId)) { + HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); + return false; + } + if (!data.WriteInt32(elementId)) { + HILOG_ERROR("elementId write error: %{public}ld, ", elementId); + return false; + } + if (!data.WriteInt32(focusType)) { + HILOG_ERROR("focusType write error: %{public}d, ", focusType); + return false; + } + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("requestId write error: %{public}d, ", requestId); + return false; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("callback write error"); + return false; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::FIND_FOCUSED_ELEMENTINFO, data, reply, option)) { + HILOG_ERROR("fail to gain focus"); + return false; + } + return reply.ReadBool(); +} + +bool AccessibleAbilityChannelProxy::FocusMoveSearch(const int accessibilityWindowId, const long elementId, + const int direction, const int requestId, const sptr &callback) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return false; + } + if (!data.WriteInt32(accessibilityWindowId)) { + HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); + return false; + } + if (!data.WriteInt32(elementId)) { + HILOG_ERROR("elementId write error: %{public}ld, ", elementId); + return false; + } + if (!data.WriteInt32(direction)) { + HILOG_ERROR("direction write error: %{public}d, ", direction); + return false; + } + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("requestId write error: %{public}d, ", requestId); + return false; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("callback write error"); + return false; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::FOCUS_MOVE_SEARCH, data, reply, option)) { + HILOG_ERROR("fail to search focus"); + return false; + } + return reply.ReadBool(); +} + +bool AccessibleAbilityChannelProxy::PerformAction(const int accessibilityWindowId, const long elementId, + const int action, std::map &actionArguments, const int requestId, + const sptr &callback) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return false; + } + if (!data.WriteInt32(accessibilityWindowId)) { + HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); + return false; + } + if (!data.WriteInt32(elementId)) { + HILOG_ERROR("elementId write error: %{public}ld, ", elementId); + return false; + } + if (!data.WriteInt32(action)) { + HILOG_ERROR("action write error: %{public}d, ", action); + return false; + } + + vector actionArgumentsKey{}; + vector actionArgumentsValue{}; + for (auto iter = actionArguments.begin(); iter != actionArguments.end(); iter++) { + actionArgumentsKey.push_back(iter->first); + actionArgumentsValue.push_back(iter->second); + } + if (!data.WriteStringVector(actionArgumentsKey)) { + HILOG_ERROR("actionArgumentsKey write error"); + return false; + } + if (!data.WriteStringVector(actionArgumentsValue)) { + HILOG_ERROR("actionArgumentsValue write error"); + return false; + } + + if (!data.WriteInt32(requestId)) { + HILOG_ERROR("requestId write error: %{public}d, ", requestId); + return false; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("callback write error"); + return false; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::PERFORM_ACTION, + data, reply, option)) { + HILOG_ERROR("fail to perform accessibility action"); + return false; + } + return reply.ReadBool(); +} + +vector AccessibleAbilityChannelProxy::GetWindows() +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + vector windowsError; + vector windows; + + if (!WriteInterfaceToken(data)) { + return windowsError; + } + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::GET_WINDOWS, data, reply, option)) { + HILOG_ERROR("fail to get windows"); + return windowsError; + } + + int32_t windowsSize = reply.ReadInt32(); + for (int32_t i = 0; i < windowsSize; i++) { + unique_ptr window(reply.ReadParcelable()); + if (!window) { + HILOG_ERROR("ReadParcelable failed"); + return windowsError; + } + windows.emplace_back(*window); + } + + return windows; +} + +bool AccessibleAbilityChannelProxy::PerformCommonAction(const int action) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return false; + } + if (!data.WriteInt32(action)) { + HILOG_ERROR("action write error: %{public}d, ", action); + return false; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::PERFORM_COMMON_ACTION, data, reply, option)) { + HILOG_ERROR("fail to perform common action"); + return false; + } + return reply.ReadBool(); +} + +void AccessibleAbilityChannelProxy::DisableAbility() +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!WriteInterfaceToken(data)) { + return; + } + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::DISABLE_ABILITY, data, reply, option)) { + HILOG_ERROR("fail to disable ability"); + } +} + +void AccessibleAbilityChannelProxy::SetOnKeyPressEventResult(const bool handled, const int sequence) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteBool(handled)) { + HILOG_ERROR("handled write error: %{public}d, ", handled); + return; + } + if (!data.WriteInt32(sequence)) { + HILOG_ERROR("sequence write error: %{public}d, ", sequence); + return; + } + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::SET_ON_KEY_PRESS_EVENT_RESULT, + data, reply, option)) { + HILOG_ERROR("fail to set onKeyPressEvent result"); + } +} + +float AccessibleAbilityChannelProxy::GetDisplayResizeScale(const int displayId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return 0; + } + if (!data.WriteInt32(displayId)) { + HILOG_ERROR("displayId write error: %{public}d, ", displayId); + return 0; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::GET_DISPALYRESIZE_SCALE, data, reply, option)) { + HILOG_ERROR("fail to get displayResize scale"); + return 0; + } + return reply.ReadFloat(); +} + +float AccessibleAbilityChannelProxy::GetDisplayResizeCenterX(const int displayId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return 0; + } + if (!data.WriteInt32(displayId)) { + HILOG_ERROR("displayId write error: %{public}d, ", displayId); + return 0; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::GET_DISPALYRESIZE_CETER_X, data, reply, option)) { + HILOG_ERROR("fail to get displayResize centerX"); + return 0; + } + return reply.ReadFloat(); +} + +float AccessibleAbilityChannelProxy::GetDisplayResizeCenterY(const int displayId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return 0; + } + if (!data.WriteInt32(displayId)) { + HILOG_ERROR("displayId write error: %{public}d, ", displayId); + return 0; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::GET_DISPLAYRESIZE_CETER_Y, data, reply, option)) { + HILOG_ERROR("fail to get displayResize centerY"); + return 0; + } + return reply.ReadFloat(); +} + +Rect AccessibleAbilityChannelProxy::GetDisplayResizeRect(const int displayId) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + Rect rect(0, 0, 0, 0); + + if (!WriteInterfaceToken(data)) { + return rect; + } + if (!data.WriteInt32(displayId)) { + HILOG_ERROR("displayId write error: %{public}d, ", displayId); + return rect; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::GET_DISPLAYRESIZE_RECT, data, reply, option)) { + HILOG_ERROR("fail to get displayResize rect"); + return rect; + } + + std::shared_ptr result(reply.ReadParcelable()); + if (!result) { + HILOG_ERROR("ReadParcelable failed"); + return rect; + } + return *result; +} + +bool AccessibleAbilityChannelProxy::ResetDisplayResize(const int displayId, const bool animate) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return false; + } + if (!data.WriteInt32(displayId)) { + HILOG_ERROR("displayId write error: %{public}d, ", displayId); + return false; + } + if (!data.WriteBool(animate)) { + HILOG_ERROR("animate write error: %{public}d, ", animate); + return false; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::RESET_DISPALYRESIZE, data, reply, option)) { + HILOG_ERROR("fail to reset displayResize"); + return false; + } + return reply.ReadBool(); +} + +bool AccessibleAbilityChannelProxy::SetDisplayResizeScaleAndCenter(const int displayId, const float scale, + const float centerX, const float centerY, const bool animate) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return false; + } + if (!data.WriteInt32(displayId)) { + HILOG_ERROR("displayId write error: %{public}d, ", displayId); + return false; + } + if (!data.WriteFloat(scale)) { + HILOG_ERROR("scale write error: %{public}f, ", scale); + return false; + } + if (!data.WriteFloat(centerX)) { + HILOG_ERROR("centerX write error: %{public}f, ", centerX); + return false; + } + if (!data.WriteFloat(centerY)) { + HILOG_ERROR("centerY write error: %{public}f, ", centerY); + return false; + } + if (!data.WriteBool(animate)) { + HILOG_ERROR("animate write error: %{public}d, ", animate); + return false; + } + + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::SET_DISPLAYRESIZE_SCALE_AND_CENTER, + data, reply, option)) { + HILOG_ERROR("fail to set displayResize scale and center"); + return false; + } + return reply.ReadBool(); +} + +void AccessibleAbilityChannelProxy::SendSimulateGesture(const int sequence, + const std::vector &gestureSteps) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteInt32(sequence)) { + HILOG_ERROR("sequence write error: %{public}d, ", sequence); + return; + } + if (!data.WriteInt32(gestureSteps.size())) { + HILOG_ERROR("gestureSteps.size() write error: %{public}d, ", gestureSteps.size()); + return; + } + for (auto &step : gestureSteps) { + if (!data.WriteParcelable(&step)) { + HILOG_ERROR("gestureSteps write error"); + return; + } + } + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::SEND_SIMULATE_GESTURE, data, reply, option)) { + HILOG_ERROR("fail to send simulation gesture"); + } +} + +bool AccessibleAbilityChannelProxy::IsFingerprintGestureDetectionValid() +{ + HILOG_DEBUG("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + return false; + } + if (!SendTransactCmd(IAccessibleAbilityChannel::Message::IS_FINGERPRINT_GESTURE_DETECTION_VALID, + data, reply, option)) { + HILOG_ERROR("fail to get fingerprint gesture detection's validity"); + return false; + } + return reply.ReadBool(); +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessible_ability_channel_stub.cpp b/frameworks/asacfwk/src/accessible_ability_channel_stub.cpp new file mode 100644 index 00000000..acbe3dec --- /dev/null +++ b/frameworks/asacfwk/src/accessible_ability_channel_stub.cpp @@ -0,0 +1,364 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessible_ability_channel_stub.h" +#include "parcel.h" + +using namespace std; + +namespace OHOS { +namespace Accessibility { + +AccessibleAbilityChannelStub::AccessibleAbilityChannelStub() { + HILOG_DEBUG("%{public}s start.", __func__); + + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::SEARCH_ELEMENTINFO_BY_ACCESSIBILITYID)] = + &AccessibleAbilityChannelStub::HandleSearchElementInfoByAccessibilityId; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::SEARCH_ELEMENTINFOS_BY_TEXT)] = + &AccessibleAbilityChannelStub::HandleSearchElementInfosByText; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::FIND_FOCUSED_ELEMENTINFO)] = + &AccessibleAbilityChannelStub::HandleFindFocusedElementInfo; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::FOCUS_MOVE_SEARCH)] = + &AccessibleAbilityChannelStub::HandleFocusMoveSearch; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::PERFORM_ACTION)] = + &AccessibleAbilityChannelStub::HandlePerformAction; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::GET_WINDOWS)] = + &AccessibleAbilityChannelStub::HandleGetWindows; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::PERFORM_COMMON_ACTION)] = + &AccessibleAbilityChannelStub::HandlePerformCommonAction; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::DISABLE_ABILITY)] = + &AccessibleAbilityChannelStub::HandleDisableAbility; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::SET_ON_KEY_PRESS_EVENT_RESULT)] = + &AccessibleAbilityChannelStub::HandleSetOnKeyPressEventResult; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::GET_DISPALYRESIZE_SCALE)] = + &AccessibleAbilityChannelStub::HandleGetDisplayResizeScale; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::GET_DISPALYRESIZE_CETER_X)] = + &AccessibleAbilityChannelStub::HandleGetDisplayResizeCenterX; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::GET_DISPLAYRESIZE_CETER_Y)] = + &AccessibleAbilityChannelStub::HandleGetDisplayResizeCenterY; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::GET_DISPLAYRESIZE_RECT)] = + &AccessibleAbilityChannelStub::HandleGetDisplayResizeRect; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::RESET_DISPALYRESIZE)] = + &AccessibleAbilityChannelStub::HandleResetDisplayResize; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::SET_DISPLAYRESIZE_SCALE_AND_CENTER)] = + &AccessibleAbilityChannelStub::HandleSetDisplayResizeScaleAndCenter; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::SEND_SIMULATE_GESTURE)] = + &AccessibleAbilityChannelStub::HandleSendSimulateGesture; + memberFuncMap_[static_cast(IAccessibleAbilityChannel::Message::IS_FINGERPRINT_GESTURE_DETECTION_VALID)] = + &AccessibleAbilityChannelStub::HandleIsFingerprintGestureDetectionValid; +} + +AccessibleAbilityChannelStub::~AccessibleAbilityChannelStub() { + HILOG_DEBUG("%{public}s start.", __func__); + memberFuncMap_.clear(); +} + +int32_t AccessibleAbilityChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) { + HILOG_DEBUG("AccessibleAbilityChannelStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", + code, option.GetFlags()); + std::u16string descriptor = AccessibleAbilityChannelStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + HILOG_INFO("local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + auto itFunc = memberFuncMap_.find(code); + if (itFunc != memberFuncMap_.end()) { + auto requestFunc = itFunc->second; + if (requestFunc != nullptr) { + return (this->*requestFunc)(data, reply); + } + } + HILOG_WARN("AbilityManagerStub::OnRemoteRequest, default case, need check."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +ErrCode AccessibleAbilityChannelStub::HandleSearchElementInfoByAccessibilityId(MessageParcel &data, + MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int accessibilityWindowId = data.ReadInt32(); + int elementId = data.ReadInt64(); + int requestId = data.ReadInt32(); + + sptr object = data.ReadRemoteObject(); + if (!object) { + HILOG_ERROR("object is nullptr."); + return ERR_INVALID_VALUE; + } + sptr callback = + iface_cast(object); + if (!callback) { + HILOG_ERROR("callback is nullptr."); + return ERR_INVALID_VALUE; + } + + int mode = data.ReadInt32(); + bool result = SearchElementInfoByAccessibilityId(accessibilityWindowId, elementId, requestId, callback, mode); + HILOG_DEBUG("SearchElementInfoByAccessibilityId ret = %{public}d", result); + reply.WriteBool(result); + + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleSearchElementInfosByText(MessageParcel &data, + MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int accessibilityWindowId = data.ReadInt32(); + long elementId = data.ReadInt32(); + string text = data.ReadString(); + int requestId = data.ReadInt32(); + + sptr object = data.ReadRemoteObject(); + sptr callback = + iface_cast(object); + + bool result = SearchElementInfosByText(accessibilityWindowId, elementId, text, requestId, callback); + HILOG_DEBUG("SearchElementInfosByText ret = %{public}d", result); + reply.WriteBool(result); + + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleFindFocusedElementInfo(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int accessibilityWindowId = data.ReadInt32(); + long elementId = data.ReadInt32(); + int focusType = data.ReadInt32(); + int requestId = data.ReadInt32(); + + sptr object = data.ReadRemoteObject(); + sptr callback = + iface_cast(object); + + bool result = FindFocusedElementInfo(accessibilityWindowId, elementId, focusType, requestId, callback); + HILOG_DEBUG("FindFocusedElementInfo ret = %{public}d", result); + reply.WriteBool(result); + + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleFocusMoveSearch(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int accessibilityWindowId = data.ReadInt32(); + long elementId = data.ReadInt32(); + int direction = data.ReadInt32(); + int requestId = data.ReadInt32(); + + sptr object = data.ReadRemoteObject(); + sptr callback = + iface_cast(object); + + bool result = FocusMoveSearch(accessibilityWindowId, elementId, direction, requestId, callback); + HILOG_DEBUG("FocusMoveSearch ret = %{public}d", result); + reply.WriteBool(result); + + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandlePerformAction(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int accessibilityWindowId = data.ReadInt32(); + long elementId = data.ReadInt32(); + int action = data.ReadInt32(); + + vector actionArgumentsKey{}; + vector actionArgumentsValue{}; + map actionArguments{}; + + if (!data.ReadStringVector(&actionArgumentsKey)) { + HILOG_ERROR("ReadStringVector actionArgumentsKey failed"); + return ERR_INVALID_VALUE; + } + if (!data.ReadStringVector(&actionArgumentsValue)) { + HILOG_ERROR("ReadStringVector actionArgumentsValue failed"); + return ERR_INVALID_VALUE; + } + if (actionArgumentsKey.size() != actionArgumentsValue.size()) { + HILOG_ERROR("Read actionArguments failed."); + return ERR_INVALID_VALUE; + } + for (unsigned int i = 0; i < actionArgumentsKey.size(); i++) { + actionArguments.insert(make_pair(actionArgumentsKey[i], actionArgumentsValue[i])); + } + + int requestId = data.ReadInt32(); + + auto callback = iface_cast(data.ReadRemoteObject()); + if (!callback) { + HILOG_ERROR("callback is nullptr"); + return ERR_INVALID_VALUE; + } + + bool result = PerformAction(accessibilityWindowId, elementId, action, actionArguments, requestId, callback); + HILOG_DEBUG("PerformAction ret = %{public}d", result); + reply.WriteBool(result); + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleGetWindows(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + vector windows = GetWindows(); + if (!reply.WriteInt32((int32_t)windows.size())) { + HILOG_ERROR("windows.size() write error: %{public}d, ", windows.size()); + return ERR_INVALID_VALUE; + } + for (auto &window : windows) { + if (!reply.WriteParcelable(&window)) { + HILOG_ERROR("write windows failed"); + return ERR_INVALID_VALUE; + } + } + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandlePerformCommonAction(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int action = data.ReadInt32(); + bool result = PerformCommonAction(action); + + HILOG_DEBUG("PerformCommonAction ret = %{public}d", result); + reply.WriteBool(result); + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleDisableAbility(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + DisableAbility(); + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleSetOnKeyPressEventResult(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + bool handled = data.ReadBool(); + int sequence = data.ReadInt32(); + SetOnKeyPressEventResult(handled, sequence); + + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleGetDisplayResizeScale(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int displayId = data.ReadInt32(); + float result = GetDisplayResizeScale(displayId); + + HILOG_DEBUG("GetDisplayResizeScale ret = %{public}f", result); + reply.WriteFloat(result); + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleGetDisplayResizeCenterX(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int displayId = data.ReadInt32(); + float result = GetDisplayResizeCenterX(displayId); + + HILOG_DEBUG("GetDisplayResizeCenterX ret = %{public}f", result); + reply.WriteFloat(result); + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleGetDisplayResizeCenterY(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int displayId = data.ReadInt32(); + float result = GetDisplayResizeCenterY(displayId); + + HILOG_DEBUG("GetDisplayResizeCenterY ret = %{public}f", result); + reply.WriteFloat(result); + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleGetDisplayResizeRect(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int displayId = data.ReadInt32(); + Rect rect = GetDisplayResizeRect(displayId); + + HILOG_DEBUG("GetDisplayResizeRect"); + reply.WriteParcelable(&rect); + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleResetDisplayResize(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int displayId = data.ReadInt32(); + bool animate = data.ReadBool(); + bool result = ResetDisplayResize(displayId, animate); + + HILOG_DEBUG("ResetDisplayResize ret = %{public}d", result); + reply.WriteBool(result); + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleSetDisplayResizeScaleAndCenter(MessageParcel &data, + MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int displayId = data.ReadInt32(); + float scale = data.ReadFloat(); + float centerX = data.ReadFloat(); + float centerY = data.ReadFloat(); + bool animate = data.ReadBool(); + bool result = SetDisplayResizeScaleAndCenter(displayId, scale, centerX, centerY, animate); + + HILOG_DEBUG("SetDisplayResizeScaleAndCenter ret = %{public}d", result); + reply.WriteBool(result); + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleSendSimulateGesture(MessageParcel &data, MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + int32_t sequence = data.ReadInt32(); + + vector gestureSteps; + int32_t stepSize = data.ReadInt32(); + for (int32_t i = 0; i < stepSize; i++) { + std::shared_ptr gestureStep(data.ReadParcelable()); + if (!gestureStep) { + HILOG_ERROR("ReadParcelable failed"); + return ERR_INVALID_VALUE; + } + gestureSteps.emplace_back(*gestureStep); + } + SendSimulateGesture(sequence, gestureSteps); + return NO_ERROR; +} + +ErrCode AccessibleAbilityChannelStub::HandleIsFingerprintGestureDetectionValid(MessageParcel &data, + MessageParcel &reply) { + HILOG_DEBUG("%{public}s start.", __func__); + + bool result = IsFingerprintGestureDetectionValid(); + + HILOG_DEBUG("IsFingerprintGestureDetectionValid ret = %{public}d", result); + reply.WriteBool(result); + return NO_ERROR; +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessible_ability_manager_service_proxy.cpp b/frameworks/asacfwk/src/accessible_ability_manager_service_proxy.cpp new file mode 100644 index 00000000..0f001bc6 --- /dev/null +++ b/frameworks/asacfwk/src/accessible_ability_manager_service_proxy.cpp @@ -0,0 +1,322 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessible_ability_manager_service_proxy.h" +#include "accessibility_errorcode.h" +#include "hilog_wrapper.h" +#include "ipc_types.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Accessibility { +AccessibleAbilityManagerServiceClientProxy::AccessibleAbilityManagerServiceClientProxy( + const sptr &impl) : IRemoteProxy(impl) +{ + +} + +AccessibleAbilityManagerServiceClientProxy::~AccessibleAbilityManagerServiceClientProxy() +{ + +} + +bool AccessibleAbilityManagerServiceClientProxy::WriteInterfaceToken(MessageParcel &data) +{ + HILOG_DEBUG("%{public}s" , __func__); + if (!data.WriteInterfaceToken(IAccessibleAbilityManagerServiceClient::GetDescriptor())) { + HILOG_ERROR("write interface token failed"); + return false; + } + return true; +} + +void AccessibleAbilityManagerServiceClientProxy::SendEvent(const AccessibilityEventInfo &uiEvent, const int userId) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteParcelable(&uiEvent)) { + HILOG_ERROR("%{public}s fail, connection write parcelable AccessibilityEventInfo error", __func__); + return; + } + + if (!data.WriteInt32(userId)) { + HILOG_ERROR("%{public}s fail, connection write userId error", __func__); + return; + } + + error = Remote()->SendRequest(static_cast(IAccessibleAbilityManagerServiceClient::Message::SEND_EVENT), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("SendEvent fail, error: %{public}d", error); + return; + } +} + +uint32_t AccessibleAbilityManagerServiceClientProxy::RegisterStateCallback( + const sptr &client, const int userId) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (client == nullptr) { + HILOG_ERROR("%{public}s fail, Input client is null", __func__); + return ErrCode::ERROR; + } + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token error", __func__); + return ErrCode::ERROR; + } + + if (!data.WriteRemoteObject(client->AsObject())) { + HILOG_ERROR("%{public}s fail, connection write client error", __func__); + return ErrCode::ERROR; + } + + if (!data.WriteInt32(userId)) { + HILOG_ERROR("%{public}s fail, connection write userId error", __func__); + return ErrCode::ERROR; + } + + error = Remote()->SendRequest( + static_cast(IAccessibleAbilityManagerServiceClient::Message::REGISTER_STATE_CALLBACK), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("SendEvent fail, error: %{public}d", error); + return ErrCode::ERROR; + } + + return reply.ReadUint32(); +} + +std::vector AccessibleAbilityManagerServiceClientProxy::GetAbilityList(const int abilityTypes, + const int stateType) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::vector errorList{}; + std::vector abilityInfos{}; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token error", __func__); + return errorList; + } + + if (!data.WriteInt32(abilityTypes)) { + HILOG_ERROR("%{public}s fail, connection write abilityTypes error", __func__); + return errorList; + } + + if (!data.WriteInt32(stateType)) { + HILOG_ERROR("%{public}s fail, connection write stateType error", __func__); + return errorList; + } + + error = Remote()->SendRequest( + static_cast(IAccessibleAbilityManagerServiceClient::Message::GET_ABILITYLIST), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("SendEvent fail, error: %d", error); + return errorList; + } + // read result + int32_t abilityInfoSize = reply.ReadInt32(); + for (int i = 0; i < abilityInfoSize; i++) { + std::shared_ptr accessibilityAbilityInfo( + reply.ReadParcelable()); + if (!accessibilityAbilityInfo) { + HILOG_ERROR("ReadParcelable failed"); + return errorList; + } + abilityInfos.emplace_back(*accessibilityAbilityInfo); + } + return abilityInfos; +} + +void AccessibleAbilityManagerServiceClientProxy::RegisterInteractionOperation(int windowId, + const sptr &operation, const int userId) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (operation == nullptr) { + HILOG_ERROR("%{public}s fail, Input operation is null", __func__); + return; + } + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteInt32(windowId)) { + HILOG_ERROR("%{public}s fail, connection write windowId error", __func__); + return; + } + + if (!data.WriteRemoteObject(operation->AsObject())) { + HILOG_ERROR("%{public}s fail, connection write parcelable operation error", __func__); + return; + } + + if (!data.WriteInt32(userId)) { + HILOG_ERROR("%{public}s fail, connection write userId error", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(IAccessibleAbilityManagerServiceClient::Message::REGISTER_INTERACTION_CONNECTION), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Register fail, error: %{public}d", error); + return; + } +} + +void AccessibleAbilityManagerServiceClientProxy::DeregisterInteractionOperation(const int windowId) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteInt32(windowId)) { + HILOG_ERROR("%{public}s fail, connection write userId error", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(IAccessibleAbilityManagerServiceClient::Message::DEREGISTER_INTERACTION_CONNECTION), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Deregister fail, error: %{public}d", error); + return; + } +} + +void AccessibleAbilityManagerServiceClientProxy::Interrupt(const int userId) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteInt32(userId)) { + HILOG_ERROR("%{public}s fail, connection write userId error", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(IAccessibleAbilityManagerServiceClient::Message::INTERRUPT), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Interrupt fail, error: %{public}d", error); + return; + } +} + +uint64_t AccessibleAbilityManagerServiceClientProxy::GetSuggestedInterval() +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return ErrCode::ERROR; + } + error = Remote()->SendRequest( + static_cast(IAccessibleAbilityManagerServiceClient::Message::GET_SUGGESTED_INTERVAL), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Interrupt fail, error: %{public}d", error); + return ErrCode::ERROR; + } + return reply.ReadInt64(); +} + +void AccessibleAbilityManagerServiceClientProxy::RegisterAbilityConnectionClientTmp(const sptr& obj) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteRemoteObject(obj)) { + HILOG_ERROR("%{public}s fail, connection write obj", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(IAccessibleAbilityManagerServiceClient::Message::REGISTER_ABILITY_CONNECTION_CLIENT), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Interrupt fail, error: %{public}d", error); + return; + } +} + +sptr AccessibleAbilityManagerServiceClientProxy::GetObject() +{ + return this->AsObject(); +} + +} //namespace Accessibility +} //namespace OHOS diff --git a/frameworks/asacfwk/src/accessible_ability_manager_service_state_proxy.cpp b/frameworks/asacfwk/src/accessible_ability_manager_service_state_proxy.cpp new file mode 100644 index 00000000..780cb298 --- /dev/null +++ b/frameworks/asacfwk/src/accessible_ability_manager_service_state_proxy.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2021 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. + */ +#include "accessible_ability_manager_service_state_proxy.h" +#include "hilog_wrapper.h" +#include "ipc_types.h" +#include "iremote_object.h" + +namespace OHOS { +namespace Accessibility { +AccessibleAbilityManagerServiceStateProxy::AccessibleAbilityManagerServiceStateProxy( + const sptr &impl) : IRemoteProxy(impl) +{} + +AccessibleAbilityManagerServiceStateProxy::~AccessibleAbilityManagerServiceStateProxy() +{} + +bool AccessibleAbilityManagerServiceStateProxy::WriteInterfaceToken(MessageParcel &data) +{ + HILOG_DEBUG("%{public}s" , __func__); + if (!data.WriteInterfaceToken(AccessibleAbilityManagerServiceStateProxy::GetDescriptor())) { + HILOG_ERROR("write interface token failed"); + return false; + } + return true; +} + +void AccessibleAbilityManagerServiceStateProxy::OnStateChanged(const uint32_t stateType) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int error = NO_ERROR; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s fail, connection write Token", __func__); + return; + } + + if (!data.WriteUint32(stateType)) { + HILOG_ERROR("%{public}s fail, connection write stateType error", __func__); + return; + } + + error = Remote()->SendRequest( + static_cast(IAccessibleAbilityManagerServiceState::Message::ON_STATE_CHANGED), + data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("OnStateChanged fail, error: %{public}d", error); + return; + } +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessible_ability_manager_service_state_stub.cpp b/frameworks/asacfwk/src/accessible_ability_manager_service_state_stub.cpp new file mode 100644 index 00000000..019979e7 --- /dev/null +++ b/frameworks/asacfwk/src/accessible_ability_manager_service_state_stub.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2021 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. + */ +#include "accessible_ability_manager_service_state_stub.h" +#include "hilog_wrapper.h" +#include "ipc_skeleton.h" +#include "ipc_types.h" +#include "iremote_object.h" +#include "accessibility_system_ability_client.h" + +namespace OHOS { +namespace Accessibility { + +AccessibleAbilityManagerServiceStateStub::AccessibleAbilityManagerServiceStateStub() +{ + HILOG_DEBUG("%{public}s" , __func__); +} + +int AccessibleAbilityManagerServiceStateStub::OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + HILOG_DEBUG("AccessibleAbilityManagerServiceStateStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", + code, option.GetFlags()); + std::u16string descriptor = AccessibleAbilityManagerServiceStateStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + + if (descriptor != remoteDescriptor) { + HILOG_INFO("local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + if (code == static_cast(IAccessibleAbilityManagerServiceState::Message::ON_STATE_CHANGED)) { + HandleOnStateChanged(data, reply); + } + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +ErrCode AccessibleAbilityManagerServiceStateStub::HandleOnStateChanged(MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + int stateType = data.ReadUint32(); + OnStateChanged(stateType); + + return NO_ERROR; +} + +void AccessibleAbilityManagerServiceStateStub::OnStateChanged(const uint32_t stateType) +{ + HILOG_DEBUG("%{public}s stateType[%{public}d} " , __func__, stateType); + std::shared_ptr instance = AccessibilitySystemAbilityClient::GetInstance(); + if (instance == nullptr) { + HILOG_DEBUG("%{public}s Can't get asac instance" , __func__); + return; + } + if (stateType & AccessibilitySystemAbilityClient::STATE_ACCESSIBILITY_ENABLED) { + instance->SetEnabled(true); + } else { + instance->SetEnabled(false); + } + + if (stateType & AccessibilitySystemAbilityClient::STATE_EXPLORATION_ENABLED) { + instance->SetTouchExplorationEnabled(true); + } else { + instance->SetTouchExplorationEnabled(false); + } +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/accessible_ability_manager_service_stub.cpp b/frameworks/asacfwk/src/accessible_ability_manager_service_stub.cpp new file mode 100644 index 00000000..edb74ebd --- /dev/null +++ b/frameworks/asacfwk/src/accessible_ability_manager_service_stub.cpp @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2021 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. + */ +#include +#include "accessible_ability_manager_service_stub.h" + +#include "hilog_wrapper.h" +#include "ipc_skeleton.h" +#include "ipc_types.h" +#include "iremote_object.h" +#include "refbase.h" + +namespace OHOS { +namespace Accessibility { + +AccessibleAbilityManagerServiceClientStub::AccessibleAbilityManagerServiceClientStub() +{ + HILOG_DEBUG("%{public}s" , __func__); + + memberFuncMap_[static_cast(IAccessibleAbilityManagerServiceClient::Message::SEND_EVENT)] = + &AccessibleAbilityManagerServiceClientStub::HandleSendEvent; + memberFuncMap_[static_cast(IAccessibleAbilityManagerServiceClient::Message::REGISTER_STATE_CALLBACK)] = + &AccessibleAbilityManagerServiceClientStub::HandleRegisterStateCallback; + memberFuncMap_[static_cast(IAccessibleAbilityManagerServiceClient::Message::GET_ABILITYLIST)] = + &AccessibleAbilityManagerServiceClientStub::HandleGetAbilityList; + memberFuncMap_[static_cast + (IAccessibleAbilityManagerServiceClient::Message::REGISTER_INTERACTION_CONNECTION)] = + &AccessibleAbilityManagerServiceClientStub::HandleRegisterAccessibilityInteractionOperation; + memberFuncMap_[static_cast + (IAccessibleAbilityManagerServiceClient::Message::DEREGISTER_INTERACTION_CONNECTION)] = + &AccessibleAbilityManagerServiceClientStub::HandleDeregisterAccessibilityInteractionOperation; + memberFuncMap_[static_cast(IAccessibleAbilityManagerServiceClient::Message::INTERRUPT)] = + &AccessibleAbilityManagerServiceClientStub::HandleInterrupt; + memberFuncMap_[static_cast + (IAccessibleAbilityManagerServiceClient::Message::GET_SUGGESTED_INTERVAL)] = + &AccessibleAbilityManagerServiceClientStub::HandleGetSuggestedInterval; + memberFuncMap_[static_cast + (IAccessibleAbilityManagerServiceClient::Message::REGISTER_ABILITY_CONNECTION_CLIENT)] = + &AccessibleAbilityManagerServiceClientStub::HandleRegisterAbilityConnectionClientTmp; +} + +AccessibleAbilityManagerServiceClientStub::~AccessibleAbilityManagerServiceClientStub() +{ + HILOG_DEBUG("%{public}s start.", __func__); + memberFuncMap_.clear(); +} + +int AccessibleAbilityManagerServiceClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) + { + HILOG_DEBUG("AccessibleAbilityManagerServiceClientStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", + code, option.GetFlags()); + std::u16string descriptor = AccessibleAbilityManagerServiceClientStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + + if (descriptor != remoteDescriptor) { + HILOG_INFO("local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + auto memFunc = memberFuncMap_.find(code); + if (memFunc != memberFuncMap_.end()) { + auto func = memFunc->second; + if (func != nullptr) { + return (this->*func)(data,reply); + } + } + HILOG_WARN("AccessibleAbilityManagerServiceClientStub::OnRemoteRequest, default case, need check."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +ErrCode AccessibleAbilityManagerServiceClientStub::HandleSendEvent(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + std::shared_ptr uiEvent(data.ReadParcelable()); + if (!uiEvent) { + HILOG_DEBUG("ReadParcelable failed"); + return ERROR; + } + int userId = data.ReadInt32(); + SendEvent(*uiEvent, userId); + + return ErrCode::NO_ERROR; +} + +ErrCode AccessibleAbilityManagerServiceClientStub::HandleRegisterStateCallback(MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + sptr obj = data.ReadRemoteObject(); + sptr client = iface_cast(obj); + int userId = data.ReadInt32(); + uint64_t result = RegisterStateCallback(client, userId); + reply.WriteUint64(result); + + return ErrCode::NO_ERROR; +} + +ErrCode AccessibleAbilityManagerServiceClientStub::HandleGetAbilityList(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int abilityTypes = data.ReadInt32(); + int stateType = data.ReadInt32(); + std::vector abilityInfos{}; + abilityInfos = GetAbilityList(abilityTypes, stateType); + + int32_t abilityInfoSize = abilityInfos.size(); + reply.WriteInt32(abilityInfoSize); + for (auto &abilityInfo : abilityInfos) { + if (!reply.WriteParcelable(&abilityInfo)) { + HILOG_ERROR("ReadParcelable failed"); + return ERROR; + } + } + return ErrCode::NO_ERROR; +} + +ErrCode AccessibleAbilityManagerServiceClientStub::HandleRegisterAccessibilityInteractionOperation( + MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int windowId = data.ReadInt32(); + sptr obj = data.ReadRemoteObject(); + sptr operation = iface_cast(obj); + int userId = data.ReadInt32(); + RegisterInteractionOperation(windowId, operation, userId); + + return ErrCode::NO_ERROR; +} + +ErrCode AccessibleAbilityManagerServiceClientStub::HandleDeregisterAccessibilityInteractionOperation( + MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int windowId = data.ReadInt32(); + DeregisterInteractionOperation(windowId); + + return ErrCode::NO_ERROR; +} + +ErrCode AccessibleAbilityManagerServiceClientStub::HandleInterrupt(MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + int userId = data.ReadInt32(); + Interrupt(userId); + + return ErrCode::NO_ERROR; +} + +ErrCode AccessibleAbilityManagerServiceClientStub::HandleGetSuggestedInterval(MessageParcel &data, + MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + uint64_t result = GetSuggestedInterval(); + + reply.WriteUint64(result); + + return ErrCode::NO_ERROR; +} + +ErrCode AccessibleAbilityManagerServiceClientStub::HandleRegisterAbilityConnectionClientTmp( + MessageParcel &data, MessageParcel &reply) +{ + HILOG_DEBUG("%{public}s" , __func__); + + sptr obj = data.ReadRemoteObject(); + + RegisterAbilityConnectionClientTmp(obj); + + return ErrCode::NO_ERROR; +} + +} //namespace Accessibility +} //namespace OHOS \ No newline at end of file diff --git a/frameworks/asacfwk/src/gesture_simulation.cpp b/frameworks/asacfwk/src/gesture_simulation.cpp new file mode 100644 index 00000000..f83f1936 --- /dev/null +++ b/frameworks/asacfwk/src/gesture_simulation.cpp @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include "gesture_simulation.h" +#include "hilog_wrapper.h" +#include "parcel_util.h" + +namespace OHOS { +namespace Accessibility { + +GesturePathPositionDefine::GesturePathPositionDefine(float positionX, float positionY) +{ + HILOG_DEBUG("%{public}s start.", __func__); + positionX_ = positionX; + positionY_ = positionY; +} + +float GesturePathPositionDefine::GetPositionX() +{ + HILOG_DEBUG("%{public}s start and positionX_ is %{public}f", __func__, positionX_); + return positionX_; +} + +float GesturePathPositionDefine::GetPositionY() +{ + HILOG_DEBUG("%{public}s start and positionY_ is %{public}f", __func__, positionY_); + return positionY_; +} + +void GesturePathPositionDefine::SetPositionX(float positionX) +{ + HILOG_DEBUG("%{public}s start.", __func__); + positionX_ = positionX; +} + +void GesturePathPositionDefine::SetPositionY(float positionY) +{ + HILOG_DEBUG("%{public}s start.", __func__); + positionY_ = positionY; +} + +bool GesturePathPositionDefine::ReadFromParcel(Parcel &parcel) +{ + HILOG_DEBUG("%{public}s start.", __func__); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, positionX_); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, positionY_); + return true; +} + +bool GesturePathPositionDefine::Marshalling(Parcel &parcel) const +{ + HILOG_DEBUG("%{public}s start.", __func__); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, positionX_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, positionY_); + return true; +} + +GesturePathPositionDefine *GesturePathPositionDefine::Unmarshalling(Parcel &parcel) +{ + HILOG_DEBUG("%{public}s start.", __func__); + GesturePathPositionDefine *gesturePathPositionDefine = new GesturePathPositionDefine(); + + if (gesturePathPositionDefine && !gesturePathPositionDefine->ReadFromParcel(parcel)) { + HILOG_ERROR("ReadFromParcel GesturePathPositionDefine failed."); + delete gesturePathPositionDefine; + gesturePathPositionDefine = nullptr; + } + + return gesturePathPositionDefine; +} + +GesturePathDefine::GesturePathDefine(GesturePathPositionDefine &startPosition, + GesturePathPositionDefine &endPosition, uint32_t durationTime) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + if (startPosition.GetPositionX() < 0 || startPosition.GetPositionY() < 0) { + HILOG_ERROR("startPosition: (%{public}f , %{public}f) is not allowed.", + startPosition.GetPositionX(), startPosition.GetPositionY()); + return; + } + startPosition_ = startPosition; + + if (endPosition.GetPositionX() < 0 || endPosition.GetPositionY() < 0) { + HILOG_ERROR("endPosition : (%{public}f , %{public}f) is not allowed.", + endPosition.GetPositionX(), endPosition.GetPositionY()); + return; + } + endPosition_ = endPosition; + + durationTime_ = durationTime; +} + +uint32_t GesturePathDefine::GetDurationTime() +{ + HILOG_DEBUG("%{public}s start and max stroke duration is %{public}d", __func__, durationTime_); + return durationTime_; +} + +GesturePathPositionDefine &GesturePathDefine::GetEndPosition() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return endPosition_; +} + +uint32_t GesturePathDefine::GetMaxStrokeDuration() +{ + HILOG_DEBUG("%{public}s start and max stroke duration is %{public}d", __func__, MAX_STROKE_DURATION); + return MAX_STROKE_DURATION; +} + +uint32_t GesturePathDefine::GetMaxStrokes() +{ + HILOG_DEBUG("%{public}s start and max strokes is %{public}d", __func__, MAX_STROKES); + return MAX_STROKES; +} + +GesturePathPositionDefine &GesturePathDefine::GetStartPosition() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return startPosition_; +} + +void GesturePathDefine::SetDurationTime(uint32_t durationTime) +{ + HILOG_DEBUG("%{public}s start.", __func__); + durationTime_ = durationTime; +} + +void GesturePathDefine::SetEndPosition(GesturePathPositionDefine &endPosition) +{ + HILOG_DEBUG("%{public}s start.", __func__); + endPosition_ = endPosition; +} + +void GesturePathDefine::SetStartPosition(GesturePathPositionDefine &startPosition) +{ + HILOG_DEBUG("%{public}s start.", __func__); + startPosition_ = startPosition; +} + +bool GesturePathDefine::ReadFromParcel(Parcel &parcel) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + std::unique_ptr startPosition(parcel.ReadParcelable()); + if (!startPosition) { + HILOG_ERROR("ReadParcelable startPosition failed."); + return false; + } + startPosition_ = *startPosition; + + std::unique_ptr endPosition(parcel.ReadParcelable()); + if (!endPosition) { + HILOG_ERROR("ReadParcelable endPosition failed."); + return false; + } + endPosition_ = *endPosition; + + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, durationTime_); + + return true; +} + +bool GesturePathDefine::Marshalling(Parcel &parcel) const +{ + HILOG_DEBUG("%{public}s start.", __func__); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &startPosition_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &endPosition_); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, durationTime_); + return true; +} + +GesturePathDefine *GesturePathDefine::Unmarshalling(Parcel &parcel) +{ + HILOG_DEBUG("%{public}s start.", __func__); + GesturePathDefine *gesturePathDefine = new GesturePathDefine(); + + if (gesturePathDefine && !gesturePathDefine->ReadFromParcel(parcel)) { + HILOG_ERROR("ReadFromParcel GesturePathDefine failed."); + delete gesturePathDefine; + gesturePathDefine = nullptr; + } + + return gesturePathDefine; +} + +GestureResultListenerInfo::GestureResultListenerInfo(std::vector gesturePathDefine, + std::shared_ptr& gestureResultListener) +{ + HILOG_DEBUG("%{public}s start.", __func__); + + if (gesturePathDefine.empty()) { + HILOG_ERROR("There is no gesture path."); + gestureResultListener = nullptr; + } else { + for (auto gesturePath : gesturePathDefine) { + gesturePathDefine_.push_back(gesturePath); + } + gestureResultListener_ = gestureResultListener; + } +} + +std::shared_ptr& GestureResultListenerInfo::GetGestureResultListener() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return gestureResultListener_; +} + +std::vector GestureResultListenerInfo::GetGesturePathDefine() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return gesturePathDefine_; +} + +} // namespace Accessibility +} // namespace OHOS diff --git a/interfaces/innerkits/asacfwk/BUILD.gn b/interfaces/innerkits/asacfwk/BUILD.gn new file mode 100644 index 00000000..08471e44 --- /dev/null +++ b/interfaces/innerkits/asacfwk/BUILD.gn @@ -0,0 +1,70 @@ +# Copyright (C) 2021 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("//build/ohos.gni") +import("//base/accessibility/frameworks/asacfwk/asacfwk.gni") + +config("accessibilityclient_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//base/accessibility/frameworks/asacfwk/include", + "//base/accessibility/util/include", + "//base/accessibility/common/log/include", + "//base/accessibility/dummyData", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + #"//foundation/appexecfwk/standard/common/log/include", + ] + + defines = [ + "AAMS_LOG_TAG = \"accessibility_aakit\"", + "AAMS_LOG_DOMAIN = 0xD005202", + ] + + if (target_cpu == "arm") { + cflags = [ "-DBINDER_IPC_32BIT" ] + } +} + +ohos_shared_library("accessibilityclient") { + install_enable = true + + sources = asacfwk_files + + configs = [ + ":accessibilityclient_config", +# "//foundation/aafwk/standard/interfaces/innerkits/base:base_public_config", + ] + + deps = [ + "//utils/native/base:utils", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//base/miscservices/time/services:time_service", + ] + + external_deps = [ + "ipc:ipc_core", + "hiviewdfx_hilog_native:libhilog", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "aafwk_standard:want", + "aafwk_standard:ability_manager", + "samgr_standard:samgr_proxy", + + ] + + subsystem_name = "accessibility" + part_name = "accessibility_standard" +} diff --git a/interfaces/innerkits/asacfwk/include/accessibility_ability_info.h b/interfaces/innerkits/asacfwk/include/accessibility_ability_info.h new file mode 100644 index 00000000..f89d3410 --- /dev/null +++ b/interfaces/innerkits/asacfwk/include/accessibility_ability_info.h @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ABILILTY_INFO_H +#define ACCESSIBILITY_ABILILTY_INFO_H + +#include +#include +#include +#include "ability_info.h" +#include "parcel.h" + +namespace OHOS { +namespace Accessibility { + + // The capability types of the accessible ability. + enum Capability : uint32_t { + CAPABILITY_RETRIEVE = 0x0001, + CAPABILITY_TOUCH_GUIDE = 0x0002, + CAPABILITY_KEY_EVENT_OBSERVER = 0x0008, + CAPABILITY_ZOOM = 0x0010, + CAPABILITY_GESTURE = 0x0020, + }; + + // The accessibility ability types for feedbacks. + enum AccessibilityAbilityTypes : uint32_t { + ACCESSIBILITY_ABILITY_TYPE_INVALID = 0x00000000, + ACCESSIBILITY_ABILITY_TYPE_SPOKEN = 0x00000001, + ACCESSIBILITY_ABILITY_TYPE_HAPTIC = 0x00000002, + ACCESSIBILITY_ABILITY_TYPE_AUDIBLE = 0x00000004, + ACCESSIBILITY_ABILITY_TYPE_VISUAL = 0x00000008, + ACCESSIBILITY_ABILITY_TYPE_GENERIC = 0x00000010, + ACCESSIBILITY_ABILITY_TYPE_ALL = 0xFFFFFFFF, + }; + + // The swipe types of fingerprint gesture. + // enum FingerprintGestureTypes : uint32_t { + // FINGERPRINT_GESTURE_UP = 0x1, + // FINGERPRINT_GESTURE_DOWN = 0x2, + // FINGERPRINT_GESTURE_LEFT = 0x4, + // FINGERPRINT_GESTURE_RIGHT = 0x8, + // FINGERPRINT_GESTURE_ALL = 0xFFFFFFFF, + // }; + + // The interception types of key event. + // enum KeyEventInterceptionTypes : uint32_t{ + // INTERCEPT_KEY_POWER = 0x001, + // INTERCEPT_KEY_VOLUME_UP = 0x002, + // INTERCEPT_KEY_VOLUME_DOWN = 0x004, + // INETRCEPT_KEY_ALL = 0xFFFFFFFF, + // }; + +class AccessibilityAbilityInfo : public Parcelable { +public: + + AccessibilityAbilityInfo() = default; + ~AccessibilityAbilityInfo() = default; + + AccessibilityAbilityInfo(AppExecFwk::AbilityInfo abilityInfo); + + /** + * @brief Obtains information about the application with the accessible ability. + * @param + * @return Return information about the application with the accessible ability. + */ + const AppExecFwk::AbilityInfo &GetAbilityInfo(); + + /** + * @brief Obtains the types of the accessible ability. + * @param + * @return Return the type of the accessible ability. + */ + uint32_t GetAccessibilityAbilityType(); + + /** + * @brief Obtains the types of the capabilities. + * @param + * @return Return the types of the capabilities. + */ + uint32_t GetCapabilityValues(); + + /** + * @brief Obtains the description of the accessible ability. + * @param + * @return Return the description of the accessible ability. + */ + std::string GetDescription(); + + /** + * @brief Obtains the type of the accessible events. + * @param + * @return Return the type of the accessible events. + */ + uint32_t GetEventTypes(); + + /** + * @brief Obtains the id of the accessible ability. + * @param + * @return Return the id of the accessible ability. + */ + std::string GetId(); + + /** + * @brief Obtains the name of the accessible ability. + * @param + * @return Return the name of the accessible ability. + */ + std::string GetName(); + + /** + * @brief Obtains the package name of the accessible ability. + * @param + * @return Return the package name of the accessible ability. + */ + std::string GetPackageName(); + + /** + * @brief Obtains the target bundles's name that you are listening on. + * @param + * @return Return the target bundles's name that you are listening on. + */ + std::vector GetFilterBundleNames(); + + /** + * @brief Obtains the setting ability of the accessible ability. + * @param + * @return Return the setting ability of the accessible ability. + */ + std::string GetSettingsAbility(); + + /** + * @brief Get notification timeout in ms. + * @param + * @return Return notification timeout in ms. + */ + uint32_t GetNotificationTimeout(); + + /** + * @brief Get UI interactive timeout in ms + * @param + * @return Return UI interactive timeout in ms + */ + uint32_t GetUiInteractiveTime(); + + /* get UI noninteractive timeout in ms. */ + /** + * @brief Get UI noninteractive timeout in ms. + * @param + * @return Return UI noninteractive timeout in ms. + */ + uint32_t GetUiNoninteractiveTime(); + + /** + * @brief read this sequenceable object from a Parcel. + * @param parcel Indicates the Parcel object into which the sequenceable object has been marshaled. + * @return Return true if read successfully, else return false. + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Marshals this sequenceable object into a Parcel. + * @param parcel Indicates the Parcel object to which the sequenceable object will be marshaled. + * @return Return true if Marshal successfully, else return false. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshals this sequenceable object from a Parcel. + * @param parcel Indicates the Parcel object into which the sequenceable object has been marshaled. + * @return Return a sequenceable object of AccessibilityAbilityInfo. + */ + static AccessibilityAbilityInfo *Unmarshalling(Parcel &parcel); + + /** + * @brief Set the types of the capabilities. + * @param capabilities the capabilities to set. + * @return + */ + inline void SetCapabilityValues(uint32_t capabilities) {capabilities_ = capabilities;}; + +private: + + /** + * @brief Parse config files of the accessible ability. + * @param + * @return Return true if parses config files successfully, else return false. + */ + bool ParseAAConfig(); + + AppExecFwk::AbilityInfo abilityInfo_; + uint32_t abilityTypes_ = 0; + uint32_t capabilities_ = 0; + uint32_t eventTypes_ = 0; + uint32_t notificationTimeout_ = 0; + uint32_t uiInteractiveTimeout_ = 10000; + uint32_t uiNoninteractiveTimeout_ = 2000; + std::string description_; + std::string settingsAbility_; + std::vector targetBundleNames_; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBILITY_ABILITY_INFO_H \ No newline at end of file diff --git a/interfaces/innerkits/asacfwk/include/accessibility_element_info.h b/interfaces/innerkits/asacfwk/include/accessibility_element_info.h new file mode 100644 index 00000000..23e6c2e8 --- /dev/null +++ b/interfaces/innerkits/asacfwk/include/accessibility_element_info.h @@ -0,0 +1,1827 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_INFO_H +#define ACCESSIBILITY_INFO_H + +#include +#include +#include +#include +#include + +#include "parcel.h" + +namespace OHOS { +namespace Accessibility { +enum ActionType :int { + ACCESSIBILITY_ACTION_INVALID = 0, + ACCESSIBILITY_ACTION_FOCUS = 0x00000001, + ACCESSIBILITY_ACTION_CLEAR_FOCUS = 0x00000002, + ACCESSIBILITY_ACTION_SELECT = 0x00000004, + ACCESSIBILITY_ACTION_CLEAR_SELECTION = 0x00000008, + ACCESSIBILITY_ACTION_CLICK = 0x00000010, + ACCESSIBILITY_ACTION_LONG_CLICK = 0x00000020, + ACCESSIBILITY_ACTION_ACCESSIBILITY_FOCUS = 0x00000040, + ACCESSIBILITY_ACTION_CLEAR_ACCESSIBILITY_FOCUS = 0x00000080, + ACCESSIBILITY_ACTION_SCROLL_FORWARD = 0x00000100, + ACCESSIBILITY_ACTION_SCROLL_BACKWARD = 0x00000200, + ACCESSIBILITY_ACTION_COPY = 0x00000400, + ACCESSIBILITY_ACTION_PASTE = 0x00000800, + ACCESSIBILITY_ACTION_CUT = 0x00001000, + ACCESSIBILITY_ACTION_SET_SELECTION = 0x00002000, + ACCESSIBILITY_ACTION_SET_TEXT = 0x00004000, + ACCESSIBILITY_ACTION_NEXT_TEXT = 0x00200000, + ACCESSIBILITY_ACTION_PREVIOUS_TEXT = 0x00400000, + ACCESSIBILITY_ACTION_UNFOLD = 0x00800000, + ACCESSIBILITY_ACTION_FOLD = 0x01000000, + ACCESSIBILITY_ACTION_NEXT_HTML_ITEM = 0x02000000, + ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM = 0x04000000, + ACCESSIBILITY_ACTION_DELETED = 0x08000000, + ACCESSIBILITY_ACTION_TYPE_MASK = 0x1FFFFFFF, +}; + +//text move step +enum TextMoveUnit : int { + STEP_INVALID = 0, + STEP_CHARACTER = 0x00000001, + STEP_WORD = 0x00000002, + STEP_LINE = 0x00000004, + STEP_PAGE = 0x00000008, + STEP_PARAGRAPH = 0x00000010, +}; +//text move step +static const std::string MOVE_UNIT_CHARACTER = "char"; +static const std::string MOVE_UNIT_WORD = "word"; +static const std::string MOVE_UNIT_LINE = "line"; +static const std::string MOVE_UNIT_PAGE = "page"; +static const std::string MOVE_UNIT_PARAGRAPH = "paragraph"; + +//Operation Arguments Type +static const std::string ACTION_ARGU_INVALID = "invalid"; +static const std::string ACTION_ARGU_SELECT_TEXT_START = "selectTextBegin"; +static const std::string ACTION_ARGU_SELECT_TEXT_END = "selectTextEnd"; +static const std::string ACTION_ARGU_HTML_ELEMENT = "htmlItem"; +static const std::string ACTION_ARGU_SET_TEXT = "setText"; +static const std::string ACTION_ARGU_MOVE_UNIT = "textMoveUnit"; + +//HtmlItemType +static const std::string HTML_ITEM_INVALID = "invalid"; +static const std::string HTML_ITEM_LINK = "link"; +static const std::string HTML_ITEM_CONTROL = "control"; +static const std::string HTML_ITEM_GRAPHIC = "graphic"; +static const std::string HTML_ITEM_LIST_ITEM = "listItem"; +static const std::string HTML_ITEM_LIST = "list"; +static const std::string HTML_ITEM_TABLE = "table"; +static const std::string HTML_ITEM_COMBOX = "combox"; +static const std::string HTML_ITEM_HEADING = "heading"; +static const std::string HTML_ITEM_BUTTON = "button"; +static const std::string HTML_ITEM_CHECKBOX = "checkBox"; +static const std::string HTML_ITEM_LANDMARK = "landmark"; +static const std::string HTML_ITEM_TEXT_FIELD= "textField"; +static const std::string HTML_ITEM_FOCUSABLE = "focusable"; +static const std::string HTML_ITEM_H1 = "h1"; +static const std::string HTML_ITEM_H2 = "h2"; +static const std::string HTML_ITEM_H3= "h3"; +static const std::string HTML_ITEM_H4 = "h4"; +static const std::string HTML_ITEM_H5 = "h5"; +static const std::string HTML_ITEM_H6 = "h6"; +static const std::string HTML_ITEM_UNKOWN = "unknown"; + +enum FocusMoveDirection :int { + DIRECTION_INVALID = 0, + UP = 0x00000001, + DOWN = 0x00000002, + LEFT = 0x00000004, + RIGHT = 0x00000008, + FORWARD = 0x00000010, + BACKWARD = 0x00000020, +}; +static const int PREFETCH_PREDECESSORS = 1 << 0; +static const int PREFETCH_SIBLINGS = 1 << 1; +static const int PREFETCH_CHILDREN = 1 << 2; +static const int UNDEFINED = -1; +static const int GET_SOURCE_PREFETCH_MODE = + PREFETCH_PREDECESSORS + | PREFETCH_SIBLINGS + | PREFETCH_CHILDREN; +static const int UNDEFINED_CHANNEL_ID = -1; +static const int UNDEFINED_SELECTION_INDEX = -1; +static const int UNDEFINED_ITEM_ID = 0x1FFFFFF; +static const int ROOT_ITEM_ID = -1; +static const int MAX_TEXT_LENGTH = 500; +static const int HOST_VIEW_ID = -1; +static const int ROOT_NODE_ID = -1; + +// Focus types +static const int FOCUS_TYPE_INVALID = -1; +static const int FOCUS_TYPE_INPUT = 1 << 0; +static const int FOCUS_TYPE_ACCESSIBILITY = 1 << 1; + +//grid mode +static const int SELECTION_MODE_NONE = 0; +static const int SELECTION_MODE_SINGLE = 1; +static const int SELECTION_MODE_MULTIPLE = 2; +/* +* class define the action on Accessibility info +*/ +class AccessibleAction : public Parcelable{ +public: + /** + * @brief Construct + * @param + * @return + */ + AccessibleAction() {} + + /** + * @brief Construct + * @param actionType The type of action, refer to [ActionType] + * @param description The description message of action. + * @return + */ + AccessibleAction(ActionType actionType, std::string description); + + /** + * @brief Gets the action type. + * @param - + * @return The type of action, refer to [ActionType] + */ + ActionType GetActionType(); + + /** + * @brief Gets the action description. + * @param - + * @return he description message of action. + */ + std::string GetDescriptionInfo(); + + /** + * @brief Used for IPC communication + * @param parcel + * @return true: Read parcel date successfully; otherwise is not + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Used for IPC communication + * @param parcel + * @return + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Used for IPC communication + * @param parcel + * @return Read AccessibleAction from parcel data + */ + static AccessibleAction *Unmarshalling(Parcel &parcel); +private: + ActionType actionType_ = ACCESSIBILITY_ACTION_INVALID; + std::string description_ = ""; +}; + +/** + * @brief Define the RangInfo for progress bar + * @note + * @retval None + */ +class RangeInfo : public Parcelable{ +public: + /** + * @brief Construct + * @param + * @return + */ + RangeInfo() {} + + /** + * @brief Construct + * @param min The min value + * @param max The max value + * @param current current value + * @return + */ + RangeInfo(int min, int max, int current); + + /** + * @brief Gets the min value. + * @param + * @return min value + */ + int GetMin(); + + /** + * @brief Gets the max value. + * @param + * @return max value. + */ + int GetMax(); + + /** + * @brief Gets the current value. + * @param + * @return + */ + int GetCurrent(); + + /** + * @brief Sets the min value. + * @param min min value + * @return + */ + void SetMin(int min); + + /** + * @brief Sets the max value. + * @param max max value. + * @return + */ + void SetMax(int max); + + /** + * @brief Sets the current value. + * @param current current value + * @return + */ + void SetCurrent(int current); + + /*Parcel*/ + /** + * @brief Used for IPC communication + * @param parcel + * @return + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Used for IPC communication + * @param parcel + * @return + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Used for IPC communication + * @param parcel + * @return + */ + static RangeInfo *Unmarshalling(Parcel &parcel); +private: + int min_ = 0; + int max_ = 0; + int current_ = 0; +}; + +/** + * @brief Define the list/grid component + * @note + * @retval None + */ +class GridInfo : public Parcelable{ +public: + /** + * @brief Construct + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + GridInfo() {} + + /** + * @brief Construct + * @param rowCount The number of row + * @param columnCount The number of column + * @param mode 0: select one line only, otherwise select multilines. + * @return + * @since 3 + * @sysCap Accessibility + */ + GridInfo(int rowCount, int columnCount, int mode); + + /** + * @brief Set the grid object + * @param rowCount The number of row + * @param columnCount The number of column + * @param mode 0: select one line only, otherwise select multilines. + * @return grid object + * @since 3 + * @sysCap Accessibility + */ + void SetGrid(int rowCount, int columnCount, int mode); + + /** + * @brief Copy grid object. + * @param other The copied grid + * @return grid object + * @since 3 + * @sysCap Accessibility + */ + void SetGrid(GridInfo other); + + /** + * @brief Gets the number of rows. + * @param - + * @return number of rows. + * @since 3 + * @sysCap Accessibility + */ + int GetRowCount(); + + /** + * @brief Gets the number of columns. + * @param + * @return number of columns. + * @since 3 + * @sysCap Accessibility + */ + int GetColumnCount(); + + /** + * @brief Get the mode of grid + * @param + * @return 0: Selected by one line, otherwise is multilines. + * @since 3 + * @sysCap Accessibility + */ + int GetSelectionMode(); + + /*Parcel*/ + /** + * @brief Used for IPC communication + * @param parcel + * @return + * @since 3 + * @sysCap Accessibility + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Used for IPC communication + * @param parcel + * @return + * @since 3 + * @sysCap Accessibility + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Used for IPC communication + * @param parcel + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + static GridInfo *Unmarshalling(Parcel &parcel); +private: + int rowCount_ = 0; + int columnCount_ = 0; + int selectionMode_ = 0; +}; + +class GridItemInfo : public Parcelable{ +public: + /** + * @brief Construct + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + GridItemInfo() {} + + /** + * @brief Construct + * @param rowIndex The index of row. + * @param rowSpan The row spanned. + * @param columnIndex The index of column + * @param columnSpan THe column spanned + * @param heading true: The item isHeading, otherwise is not + * @param selected true: The item is selected,otherwise is not + * @return + * @since 3 + * @sysCap Accessibility + */ + GridItemInfo(int rowIndex, int rowSpan, int columnIndex, int columnSpan, bool heading, bool selected); + + /** + * @brief Copy the GridItemInfo + * @param other The object of GridItemInfo copied. + * @return GridItemInfo object + * @since 3 + * @sysCap Accessibility + */ + void SetGridItemInfo(GridItemInfo other); + + /** + * @brief Set grid object + * @param rowIndex The index of row. + * @param rowSpan The row spanned. + * @param columnIndex The index of column + * @param columnSpan THe column spanned + * @param heading true: The item isHeading, otherwise is not + * @param selected true: The item is selected,otherwise is not + * @return GridItemInfo object + * @since 3 + * @sysCap Accessibility + */ + void SetGridItemInfo(int rowIndex, int rowSpan, + int columnIndex, int columnSpan, bool heading, bool selected); + + /** + * @brief Gets the column index at which the item is located. + * @param + * @return The column index. + * @since 3 + * @sysCap Accessibility + */ + int GetColumnIndex(); + + /** + * @brief Gets the row index at which the item is located. + * @param + * @return The row index. + * @since 3 + * @sysCap Accessibility + */ + int GetRowIndex(); + + /** + * @brief Gets the number of columns the item spans. + * @param + * @return The column span. + * @since 3 + * @sysCap Accessibility + */ + int GetColumnSpan(); + + /** + * @brief Gets the number of rows the item spans. + * @param + * @return The row span. + * @since 3 + * @sysCap Accessibility + */ + int GetRowSpan(); + + /** + * @brief Checks if the grid item is a heading. + * @param + * @return true: If the item is a heading, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsHeading(); + + /** + * @brief Checks if the grid item is a selected. + * @param + * @return true: If the item is a selected, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsSelected(); + + /*Parcel*/ + /** + * @brief Used for IPC communication + * @param parcel + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Used for IPC communication + * @param parcel + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Used for IPC communication + * @param parcel + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + static GridItemInfo *Unmarshalling(Parcel &parcel); +private: + bool heading_ = false; + int columnIndex_ = 0; + int rowIndex_ = 0; + int columnSpan_ = 0; + int rowSpan_ = 0; + bool selected_ = 0; +}; + +class Rect : public Parcelable { +public: + /** + * @brief Construct + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + Rect() {} + + /** + * @brief Destruct + * @param - + * @return + * @since 3 + * @sysCap Accessibility + */ + virtual ~Rect() = default; + + /** + * @brief Construct + * @param leftTopX : The left top x pixel coordinates + * @param leftTopY : The left top y pixel coordinates + * @param rightBottomY : The right bottom y pixel coordinates + * @param rightBottomX : The right bottom x pixel coordinates + * @return + * @since 3 + * @sysCap Accessibility + */ + Rect(int leftTopX, int leftTopY, int rightBottomX, int rightBottomY) { + leftTopX_ = leftTopX; + leftTopY_ = leftTopY; + rightBottomX_ = rightBottomX; + rightBottomY_ = rightBottomY; + } + + /** + * @brief Get the left top point's pixel coordinates + * @param - + * @return The left top x pixel coordinates + * @since 3 + * @sysCap Accessibility + */ + int GetLeftTopXScreenPostion() { + return leftTopX_; + } + + /** + * @brief Get the left top point's pixel coordinates + * @param - + * @return The left top y pixel coordinates + * @since 3 + * @sysCap Accessibility + */ + int GetLeftTopYScreenPostion() { + return leftTopY_; + } + + /** + * @brief Get the right bottom point's pixel coordinates + * @param - + * @return The bottom x pixel coordinates + * @since 3 + * @sysCap Accessibility + */ + int GetRightBottomXScreenPostion() { + return rightBottomX_; + } + + /** + * @brief Get the right bottom point's pixel coordinates + * @param - + * @return The bottom y pixel coordinates + * @since 3 + * @sysCap Accessibility + */ + int GetRightBottomYScreenPostion() { + return rightBottomY_; + } + /** + * @brief Set the left top point's pixel coordinates + * @param leftTopX(out) The left top x pixel coordinates + * @param leftTopY(out) The left top y pixel coordinates + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetLeftTopScreenPostion(int leftTopX, int leftTopY) { + leftTopY_ = leftTopY; + leftTopX_ = leftTopX; + } + + /** + * @brief Get the right bottom point's pixel coordinates + * @param rightBottomX(out) The right bottom x pixel coordinates + * @param rightBottomY(out) The right bottom y pixel coordinates + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetRightBottomScreenPostion(int rightBottomX, int rightBottomY) { + rightBottomY_ = rightBottomY; + rightBottomX_ = rightBottomX; + } + + /*Parcel*/ + /** + * @brief Used for IPC communication + * @param parcel + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Used for IPC communication + * @param parcel + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Used for IPC communication + * @param parcel + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + static Rect *Unmarshalling(Parcel &parcel); + +private: + int leftTopX_ = 0; + int leftTopY_ = 0; + int rightBottomX_= 0; + int rightBottomY_ = 0; +}; + +/* +* The class supply the api to set/get ui component property +*/ +class AccessibilityElementInfo : public Parcelable { +public: + static const int UNDEFINED_ACCESSIBILITY_ID = -1; + static const int MAX_SIZE = 50; + + /** + * @brief Construct + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + AccessibilityElementInfo(); + + /** + * @brief Set the AccessibilityElementInfo + * @param componentId The id of component. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetComponentId(const int componentId); + + /** + * @brief Gets information about the node that gains accessibility focus + * @param focus Indicates the focus type, which is described in AccessibilityElementInfo#FOCUS_TYPE_ACCESSIBILITY. + * @return Returns information about the focused accessibility node. + * @since 3 + * @sysCap Accessibility + */ + bool GetFocus(const int focus, AccessibilityElementInfo &elementInfo); + + /** + * @brief Gets the next focused node in the specified direction of the currently focused node. + * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection + * @return + * @since 3 + * @sysCap Accessibility + */ + bool GetNext(const FocusMoveDirection direction, AccessibilityElementInfo &elementInfo); + + /** + * @brief Get the childe accessibility Id by index. + * @param index The index of child + * @return accessibility Id + * @since 3 + * @sysCap Accessibility + */ + int GetChildId(const int index) const; + + /** + * @brief Gets the number of children + * @param - + * @return The number of children + * @since 3 + * @sysCap Accessibility + */ + int GetChildCount() const; + + /** + * @brief Gets the id of children + * @param - + * @return The list of children id + * @since 3 + * @sysCap Accessibility + */ + std::vector GetChildIds() const; + + /** + * @brief Get the child node information by index + * @param index The index of child + * @param elementInfo The componet info of child + * @return true: get child component info; otherwise is null + * @since 3 + * @sysCap Accessibility + */ + bool GetChild(const int index, AccessibilityElementInfo &elementInfo); + + /** + * @brief Add child node information + * @param childId The id of child node + * @return + * @since 3 + * @sysCap Accessibility + */ + void AddChild(const int childId); + + /** + * @brief Remove child specified. + * @param childId Remove child + * @return true: Removed succeed, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool RemoveChild(const int childId); + + /** + * @brief Gets an action list. + * @param - + * @return action list. Refer to ActionType + * @since 3 + * @sysCap Accessibility + */ + std::vector GetActionList() const; + + /** + * @brief Add action on the component + * @param action The action on the component. + * @return + * @since 3 + * @sysCap Accessibility + */ + void AddAction(AccessibleAction &action); + + /** + * @brief Remove action on the component + * @param action The action object. + * @return + * @since 3 + * @sysCap Accessibility + */ + void DeleteAction(AccessibleAction &action); + + /** + * @brief Remove the action on the component. + * @param actionType The action type. + * @return + * @since 3 + * @sysCap Accessibility + */ + bool DeleteAction(ActionType &actionType); + + /** + * @brief Remove all the action on the component. + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + void DeleteAllActions(); + + /** + * @brief Sets the maximum length of text allowed for this node. + * @param max The maximum length of text + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetTextLengthLimit(const int max); + + /** + * @brief Gets the maximum length of text allowed for this node. + * @param + * @return The maximum length of text + * @since 3 + * @sysCap Accessibility + */ + int GetTextLengthLimit() const; + + /** + * @brief Executes a specified action. + * @param action: the action type + * @param actionArguments: The parameter for action type. such as: + * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_NEXT_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_SET_SELECTION, + * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, + * {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. + * @since 3 + * @sysCap Accessibility + */ + bool ExecuteAction(const ActionType &action, const std::map &actionArguments); + + /** + * @brief Searches for node information based on the specified content. + * @param text specified content + * @return The child node infomations matched the text filterred. + * @since 3 + * @sysCap Accessibility + */ + bool GetByContent(const std::string &text, std::vector &elementInfos); + + /** + * @brief Searches for node information by elementId. + * @param elementId The unique id of the accessibility ID. It composed by componentId(component id) and virtualId + * accessibility ID Low 32 bit: It is componentId(component id), the id of component + * accessibility ID High 32 bit: virtualId, It is used when the component is complex and + * componentId can't describe the component clearly otherwise the virtualId maybe is -1. + * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also. + * PREFETCH_SIBLINGS: Need to make the sister/brothers node info also. + * PREFETCH_CHILDREN: Need to make the child node info also. + * otherwise: Make the node information by elementId only. + * @return node information + * @since 3 + * @sysCap Accessibility + */ + bool GetElementInfosById(const int elementId, int mode, std::vector &elementInfos); + + /** + * @brief Get the window Id of the component is belongs to the window. + * @param + * @return window id + * @since 3 + * @sysCap Accessibility + */ + int GetWindowId() const; + + /** + * @brief Set the window Id of the component is belongs to the window. + * @param windowId + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetWindowId(const int windowId); + + /** + * @brief Get Parent node information + * @param + * @return Parent node information + * @since 3 + * @sysCap Accessibility + */ + bool GetParent(AccessibilityElementInfo &elementInfo); + + /** + * @brief Get Parent accessibility Id. + * @param + * @return accessibility Id. + * @since 3 + * @sysCap Accessibility + */ + int GetParentNodeId() const; + + /** + * @brief Set Parent node information + * @param parentId Parent node id + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetParent(const int parentId); + + /** + * @brief Gets the rectangular area of this accessibility node control in the screen. + * @param + * @return The rectangular area of this accessibility node + * @since 3 + * @sysCap Accessibility + */ + Rect GetRectInScreen() const; + + /** + * @brief Set the rectangular area of this accessibility node control in the screen. + * @param bounds The rectangular area of this accessibility node + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetRectInScreen(Rect &bounds); + + /** + * @brief Checks whether this node (a check box as an example) is checkable. + * @param + * @return whether this node (a check box as an example) is checkable. + * @since 3 + * @sysCap Accessibility + */ + bool IsCheckable() const; + + /** + * @brief Set whether this node (a check box as an example) is checkable. + * @param + * @return true : Is checkable, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + void SetCheckable(const bool checkable); + + /** + * @brief Checks whether this node is checked. + * @param + * @return true : Is checked, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsChecked() const; + + /** + * @brief Set whether this node is checked. + * @param checked true : Is checked, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetChecked(const bool checked); + + /** + * @brief Checks whether this node can be focused. + * @param + * @return true : Can be focused, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsFocusable() const; + + /** + * @brief Set whether this node can be focused. + * @param focusable true : Can be focused, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetFocusable(const bool focusable); + + /** + * @brief Checks whether this node has gained focus. + * @param + * @return true : Focused, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsFocused(); + + /** + * @brief Set whether this node has gained focus. + * @param focused true : Focused, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetFocused(const bool focused); + + /** + * @brief Checks whether this node is visible to users. + * @param + * @return true : visible, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsVisible() const; + + /** + * @brief Set whether this node is visible to users. + * @param visible true : visible, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetVisible(const bool visible); + + /** + * @brief Checks whether this node has gained accessibility focus. + * @param + * @return true : Gained accessibility focus, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool HasAccessibilityFocus() const; + + /** + * @brief Set whether this node has gained accessibility focus. + * @param focused true : Gained accessibility focus, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetAccessibilityFocus(const bool focused); + + /** + * @brief Checks whether this node is selected. + * @param + * @return true: selected, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsSelected() const; + + /** + * @brief Set whether this node is selected. + * @param selected true: selected, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetSelected(const bool selected); + + /** + * @brief Checks whether this node is clickable. + * @param + * @return true: clickable, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsClickable() const; + + /** + * @brief Set whether this node is clickable. + * @param clickable true: clickable, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetClickable(const bool clickable); + + /** + * @brief Checks whether this node is long clickable. + * @param + * @return true: long clickable, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsLongClickable() const; + + /** + * @brief Set whether this node is long clickable. + * @param longClickable true: long clickable, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetLongClickable(const bool longClickable); + + /** + * @brief Checks whether this node is enabled. + * @param + * @return true: enabled, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsEnabled() const; + + /** + * @brief Set whether this node is enabled. + * @param enabled true: enabled, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetEnabled(const bool enabled); + + /** + * @brief Checks whether the content in this node is a password. + * @param + * @return true: password, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsPassword() const; + + /** + * @brief Set whether the content in this node is a password + * @param password true: password, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetPassword(const bool password); + + /** + * @brief Checks whether this node is scrollable. + * @param + * @return true: scrollable, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsScrollable() const; + + /** + * @brief Set whether this node is scrollable. + * @param scrollable true: scrollable, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetScrollable(const bool scrollable); + + /** + * @brief Checks whether this node is editable. + * @param + * @return true: editable, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsEditable() const; + + /** + * @brief Set whether this node is editable. + * @param editable true: editable, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetEditable(const bool editable); + + /** + * @brief Checks whether this node can display text in multiple lines. + * @param + * @return true: multilines, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsPluraLineSupported() const; + + /** + * @brief Set whether this node can display text in multiple lines. + * @param multiLine true: multilines, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetPluraLineSupported(const bool multiLine); + + /** + * @brief Checks whether pop-up windows are supported. + * @param + * @return true: Support popup, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsPopupSupported() const; + + /** + * @brief Set whether pop-up windows are supported. + * @param supportPopup true: Support popup, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetPopupSupported(const bool supportPopup); + + /** + * @brief Checks whether this node is deletable. + * @param + * @return true: deletable, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsDeletable() const; + + /** + * @brief Set whether this node is deletable. + * @param deletable true: deletable, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetDeletable(const bool deletable); + + /** + * @brief Checks whether this node is essential to users. + * @param + * @return true: essential to user, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsEssential() const; + + /** + * @brief Set whether this node is essential to users. + * @param essential true: essential to user, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetEssential(const bool essential); + + /** + * @brief Checks whether this node is displaying a hint. + * @param + * @return true: displaying a hint, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsGivingHint() const; + + /** + * @brief Set whether this node is displaying a hint. + * @param hinting true: displaying a hint, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetHinting(const bool hinting); + + /** + * @brief Gets the bundle name of application target. + * @param + * @return bundle name + * @since 3 + * @sysCap Accessibility + */ + std::string GetBundleName() const; + + /** + * @brief Set the bundle name of application target. + * @param bundleName The bundle name of application target. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetBundleName(const std::string &bundleName); + + /** + * @brief Gets the class name. + * @param + * @return class name. + * @since 3 + * @sysCap Accessibility + */ + std::string GetComponentType() const; + + /** + * @brief Sets the class name. + * @param className class name. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetComponentType(const std::string &className); + + /** + * @brief Gets the text of node. + * @param + * @return The text of node + * @since 3 + * @sysCap Accessibility + */ + std::string GetContent() const; + + /** + * @brief Set the text of node. + * @param text The text of node + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetContent(const std::string &text); + + /** + * @brief Gets the accessibility text of node. + * @param + * @return the accessibility text of node + * @since 3 + * @sysCap Accessibility + */ + std::string GetAccessibilityContent() const; + + /** + * @brief Set the accessibility text of node. + * @param text The accessibility text of node. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetAccessibilityContent(const std::string &text); + + /** + * @brief Gets the accessibility description of node. + * @param + * @return The accessibility description of node. + * @since 3 + * @sysCap Accessibility + */ + std::string GetAccessibilityDescription() const; + + /** + * @brief Set the accessibility description of node. + * @param text The accessibility description of node. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetAccessibilityDescription(const std::string &text); + + /** + * @brief Checks whether this node is accessibility group. + * @param + * @return true Accessibility group, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool GetAccessibilityGroup() const; + + /** + * @brief Set whether this node is accessibility group + * @param group true Accessibility group, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetAccessibilityGroup(const bool group); + + /** + * @brief Gets the hint information. + * @param + * @return the hint information. + * @since 3 + * @sysCap Accessibility + */ + std::string GetHint() const; + + /** + * @brief Sets the hint information. + * @param hintText the hint information. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetHint(const std::string &hintText); + + /** + * @brief Gets the description of the accessibility node. + * @param + * @return the description of the accessibility node. + * @since 3 + * @sysCap Accessibility + */ + std::string GetDescriptionInfo() const; + + /** + * @brief Set the description of the accessibility node. + * @param contentDescription the description of the accessibility node. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetDescriptionInfo(const std::string contentDescription); + + /** + * @brief Set the resource name of the component. + * @param viewIdResName The resource name. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetComponentResourceId(const std::string &viewIdResName); + + /** + * @brief Gets the resource name. + * @param + * @return the resource name. + * @since 3 + * @sysCap Accessibility + */ + std::string GetComponentResourceId() const; + + /** + * @brief Set whether this node has live region + * @note If the node has live region, the changed information will be notified to user. such as: + * Input error password. + * @param liveRegion live region: 0: not live region; 1: interrupt current talkback; 2: talk back by order + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetLiveRegion(const int liveRegion); + /** + * @brief Get whether this node has live region + * @param + * @return live region + * @since 3 + * @sysCap Accessibility + */ + int GetLiveRegion() const; + + /** + * @brief Set whether this node has content Invalid. + * @note If the node has content Invalid,when input invalid information, it will be talkbacked. such as: + * The editbox permit number only, you input character("a"), The invalid information will be talkbacked. + * @param contentInvalid content Invalid + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetContentInvalid(const bool contentInvalid); + + /** + * @brief Get whether this node has content Invalid. + * @param + * @return true Is setted content invalid, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool GetContentInvalid() const; + + /** + * @brief Set error information, it used with contentInvalid is setted true. + * @param error error information + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetError(const std::string &error); + + /** + * @brief Get error information,it used with contentInvalid is setted true. + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + std::string GetError(); + + /** + * @brief Set the id of component labeled + * @param componentId the id of component + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetLabeled(const int componentId); + + /** + * @brief Get the node information labeled component + * @param + * @return the node information labeled + * @since 3 + * @sysCap Accessibility + */ + bool GetLabeled(AccessibilityElementInfo &elementInfo) const; + + /** + * @brief Get labeled accessibility Id + * @param + * @return accessibility Id + * @since 3 + * @sysCap Accessibility + */ + int GetLabeledAccessibilityId() const; + + /** + * @brief Get the id of the IAccessibleAbilityChannel + * @param + * @return The id of the IAccessibleAbilityChannel + * @since 3 + * @sysCap Accessibility + */ + int GetChannelId() const; + + /** + * @brief AAMS called to set the id of the IAccessibleAbilityChannel + * @param channelId The id of the IAccessibleAbilityChannel + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetChannelId(const int channelId); + + /** + * @brief Set accessibility Id + * @param componentId The id of component + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetAccessibilityId(const int componentId); + + /** + * @brief Get accessibility Id + * @param + * @return accessibility Id + * @since 3 + * @sysCap Accessibility + */ + int GetAccessibilityId() const; + + /** + * @brief Get the object of RangeInfo + * @param + * @return the object of RangeInfo + * @since 3 + * @sysCap Accessibility + */ + RangeInfo GetRange() const; + + /** + * @brief Set the object of RangeInfo + * @param rangeInfo the object of RangeInfo + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetRange(RangeInfo &rangeInfo); + + /** + * @brief Set the start location of text selected. + * @param start the end location of text selected. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetSelectedBegin(const int start); + + /** + * @brief Get the start location of text selected. + * @param + * @return the start location of text selected. + * @since 3 + * @sysCap Accessibility + */ + int GetSelectedBegin() const; + + /** + * @brief Set the end location of text selected. + * @param end the end location of text selected. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetSelectedEnd(const int end); + + /** + * @brief Get the end location of text selected. + * @param + * @return the end location of text selected. + * @since 3 + * @sysCap Accessibility + */ + int GetSelectedEnd() const; + + /** + * @brief Get the object of GridInfo + * @param + * @return the object of GridInfo + * @since 3 + * @sysCap Accessibility + */ + GridInfo GetGrid() const; + + /** + * @brief Set the object of GridInfo + * @param grid the object of GridInfo + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetGrid(const GridInfo &grid); + + /** + * @brief Get the object of GridItemInfo + * @param + * @return the object of GridItemInfo + * @since 3 + * @sysCap Accessibility + */ + GridItemInfo GetGridItem() const; + + /** + * @brief Set the object of GridItemInfo + * @param gridItem the object of GridItemInfo + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetGridItem(const GridItemInfo &gridItem); + + /** + * @brief Get the current index of list or location text + * @param + * @return the current index of list or location text + * @since 3 + * @sysCap Accessibility + */ + int GetCurrentIndex() const; + + /** + * @brief Set the current index of list or location text + * @param index the current index of list or location text + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetCurrentIndex(const int index); + + /** + * @brief Get the start index of list or location text + * @param + * @return the start index of list or location text + * @since 3 + * @sysCap Accessibility + */ + int GetBeginIndex() const; + + /** + * @brief Set the start index of list or location text + * @param index the start index of list or location text + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetBeginIndex(const int index); + + /** + * @brief Get the end index of list or location text + * @param + * @return the end index of list or location text + * @since 3 + * @sysCap Accessibility + */ + int GetEndIndex() const; + + /** + * @brief Set the end index of list or location text + * @param index the end index of list or location text + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetEndIndex(const int index); + + /** + * @brief Get the input type of text + * @param + * @return The input type of text + * @since 3 + * @sysCap Accessibility + */ + int GetInputType() const; + + /** + * @brief Set the input type of text + * @param inputType The input type of text + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetInputType(const int inputType); + + /** + * @brief Checks whether this node is valid + * @param + * @return true: valid, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsValidElement() const; + + /** + * @brief Set whether this node is valid + * @param valid true: valid, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetValidElement(const bool valid); + + /*Parcel*/ + /** + * @brief Used for IPC communication + * @param parcel + * @return true: Read parcel data successfully; ohterwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool ReadFromParcel(Parcel &parcel); + + /*Parcel*/ + /** + * @brief Used for IPC communication + * @param parcel + * @return true: Write parcel data successfully; ohterwise is not. + * @since 3 + * @sysCap Accessibility + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /*Parcel*/ + /** + * @brief Used for IPC communication + * @param parcel + * @return Read AccessibilityElementInfo from parcel data + * @since 3 + * @sysCap Accessibility + */ + static AccessibilityElementInfo *Unmarshalling(Parcel &parcel); + +private: + int windowId_ = -1; + int elementId_ = UNDEFINED_ACCESSIBILITY_ID; + int parentId_ = UNDEFINED_ACCESSIBILITY_ID; + std::string bundleName_ = ""; + std::string componentType_ = ""; + std::string text_ = ""; + std::string hintText_ = ""; + std::string accessibilityText_ = ""; + std::string accessibilityDescription_ = ""; + std::string contentDescription_ = ""; + std::string resourceName_ = ""; + std::vectorchildNodeIds_{}; + int childCount_ = 0; + std::vector operations_{}; + int textLengthLimit_ = -1; + int channelId_ = UNDEFINED_CHANNEL_ID; //rename + Rect bounds_ {}; + bool accessibilityGroup_ = false; + bool checkable_ = false; + bool checked_ = false; + bool focusable_ = false; + bool focused_ = false; + bool visible_ = false; + bool accessibilityFocused_ = false; + bool selected_ = false; + bool clickable_ = false; + bool longClickable_ = false; + bool enable_ = false; + bool password_ = false; + bool scrollable_ = false; + bool editable_ = false; + bool popupSupported_ = false; + bool multiLine_ = false; + bool deletable_ = false; + bool hint_ = false; + bool isEssential_ = false; + int currentIndex_ = 0; + int beginIndex_ = 0; + int endIndex_= 0; + RangeInfo rangeInfo_ {}; + GridInfo grid_{}; + GridItemInfo gridItem_{}; + int liveRegion_ = 0; + bool contentInvalid_ = true; + std::string error_ = ""; + int labeled_ = 0; + int beginSelected_ = 0; + int endSelected_ = 0; + int inputType_ = 0; //text input type added + bool validElement_ = true; +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/interfaces/innerkits/asacfwk/include/accessibility_event_info.h b/interfaces/innerkits/asacfwk/include/accessibility_event_info.h new file mode 100644 index 00000000..c53fd113 --- /dev/null +++ b/interfaces/innerkits/asacfwk/include/accessibility_event_info.h @@ -0,0 +1,685 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_EVENT_INFO_H +#define ACCESSIBILITY_EVENT_INFO_H + +#include +#include +#include +#include + +#include "accessibility_element_info.h" +#include "parcel.h" + +namespace OHOS { +namespace Accessibility { +enum WindowUpdateType : int { + WINDOW_UPDATE_INVALID = 0, + WINDOW_UPDATE_ACCESSIBILITY_FOCUSED = 0x00000001, + WINDOW_UPDATE_FOCUSED = 0x00000002, + WINDOW_UPDATE_ACTIVE = 0x00000004, + WINDOW_UPDATE_ADDED = 0x00000008, + WINDOW_UPDATE_REMOVED = 0x00000010, + WINDOW_UPDATE_BOUNDS = 0x00000020, + WINDOW_UPDATE_TITLE = 0x00000040, + WINDOW_UPDATE_LAYER = 0x00000080, + WINDOW_UPDATE_PARENT = 0x00000100, + WINDOW_UPDATE_CHILDREN = 0x00000200, + WINDOW_UPDATE_PIP = 0x00000400, +}; + +enum WindowsContentChangeTypes : int { + CONTENT_CHANGE_TYPE_INVALID = 0, + CONTENT_CHANGE_TYPE_SUBTREE = 0x00000001, + CONTENT_CHANGE_TYPE_TEXT = 0x00000002, + CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION = 0x00000004, +}; + +enum EventType : int { + TYPE_VIEW_INVALID = 0, + TYPE_VIEW_CLICKED_EVENT = 0x00000001, + TYPE_VIEW_LONG_CLICKED_EVENT = 0x00000002, + TYPE_VIEW_SELECTED_EVENT = 0x00000004, + TYPE_VIEW_FOCUSED_EVENT = 0x00000008, + TYPE_VIEW_TEXT_UPDATE_EVENT = 0x00000010, + TYPE_PAGE_STATE_UPDATE = 0x00000020, + TYPE_NOTIFICATION_UPDATE_EVENT = 0x00000040, + TYPE_VIEW_HOVER_ENTER_EVENT = 0x00000080, + TYPE_VIEW_HOVER_EXIT_EVENT = 0x00000100, + TYPE_TOUCH_GUIDE_GESTURE_BEGIN = 0x00000200, + TYPE_TOUCH_GUIDE_GESTURE_END = 0x00000400, + TYPE_PAGE_CONTENT_UPDATE = 0x00000800, + TYPE_VIEW_SCROLLED_EVENT = 0x000001000, + TYPE_VIEW_TEXT_SELECTION_UPDATE_EVENT = 0x000002000, + TYPE_PUBLIC_NOTICE_EVENT = 0x00004000, + TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT = 0x00008000, + TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED_EVENT = 0x00010000, + TYPE_VIEW_TEXT_MOVE_UNIT_EVENT = 0x00020000, + TYPE_TOUCH_GUIDE_BEGIN = 0x00040000, + TYPE_TOUCH_GUIDE_END = 0x00080000, + TYPE_TOUCH_BEGIN = 0x00100000, + TYPE_TOUCH_END = 0x00200000, + TYPE_WINDOW_UPDATE = 0x00400000, + TYPES_ALL_MASK = 0xFFFFFFFF, +}; + +enum NotificationCategory : int { + CATEGORY_INVALID = 0, + CATEGORY_CALL = 0x00000001, + CATEGORY_MSG = 0x00000002, + CATEGORY_EMAIL = 0x00000004, + CATEGORY_EVENT = 0x00000008, + CATEGORY_PROMO = 0x00000010, + CATEGORY_ALARM = 0x00000020, + CATEGORY_PROGRESS = 0x00000040, + CATEGORY_SOCIAL = 0x00000080, + CATEGORY_ERR = 0x00000100, + CATEGORY_TRANSPORT = 0x00000200, + CATEGORY_SYS = 0x00000400, + CATEGORY_SERVICE = 0x00000800, + CATEGORY_OTHERS = 0x00001000, +}; +/* +* The class supply the content information about the event. +* The SetXxx() API is almost supplied to ACE to set the information. +* Parts of SetXxx() API is called by AAMS, such as: SetConnectId(). +* The GetXxx() API is almost supplied to AA to get the information. +*/ +class AccessibilityMemo : public Parcelable { +public: + /** + * @brief Construct + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + AccessibilityMemo() {} + + /** + * @brief AAMS called to set the id of the IAccessibleAbilityChannel + * @param channelId The id of the IAccessibleAbilityChannel + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetChannelId(const int channelId); + + /** + * @brief Get the id of the IAccessibleAbilityChannel + * @param - + * @return The id of the IAccessibleAbilityChannel + * @since 3 + * @sysCap Accessibility + */ + int GetChannelId() const; + + /** + * @brief Set the component of the event related. + * @param componentId The id of component. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetSource(const int componentId); + + /** + * @brief Get the node information related with the event + * @param - + * @return The node information related with the event + * @since 3 + * @sysCap Accessibility + */ + bool GetSource(AccessibilityElementInfo &elementInfo) const; + + /** + * @brief Gets the view(component) ID associated with the accessibility event. + * @param - + * @return The view(component) ID associated with the accessibility event. + * @since 3 + * @sysCap Accessibility + */ + int GetViewId() const; + + /** + * @brief Gets the accessibility ID of the component. + * @param - + * @return The accessibility ID of the component. + * @since 3 + * @sysCap Accessibility + */ + int GetAccessibilityId() const; + + /** + * @brief Set the window ID associated with the accessibility event. + * @param windowId The window ID associated with the accessibility event. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetWindowId(const int windowId); + + /** + * @brief Gets the window ID associated with the accessibility event. + * @param - + * @return The window ID associated with the accessibility event. + * @since 3 + * @sysCap Accessibility + */ + + int GetWindowId() const; + + /** + * @brief Gets the current index of listed items or text postion associated with the current event. + * @param - + * @return The current index of listed items or text postion associated with the current event. + * @since 3 + * @sysCap Accessibility + */ + int GetCurrentIndex() const; + + /** + * @brief Sets the current index of listed items or text postion associated with the current event. + * @param index The current index of listed items or text postion associated with the current event. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetCurrentIndex(const int index); + + /** + * @brief Gets the start index of listed items on the screen. + * @param - + * @return The start index of listed items. It is unique value for the listed items. + * @since 3 + * @sysCap Accessibility + */ + int GetBeginIndex() const; + + /** + * @brief Sets the start index of listed items on the screen. + * @param index The start index of listed items. It is unique value for the listed items. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetBeginIndex(const int index); + + /** + * @brief Gets the number items on the screen. + * @param - + * @return The number of items. + * @since 3 + * @sysCap Accessibility + */ + int GetItemCounts() const; + + /** + * @brief Sets the number items on the screen. + * @param ItemCounts The number of items. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetItemCounts(const int itemCounts); + + /** + * @brief Gets the end index of listed items on the screen. + * @param - + * @return The end index of listed items on the screen. + * @since 3 + * @sysCap Accessibility + */ + int GetEndIndex() const; + + /** + * @brief Sets the end index of listed items on the screen. + * @param index The end index of listed items on the screen. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetEndIndex(const int index); + + /** + * @brief Gets the class(component type) name. + * @param - + * @return The class(component type) name. + * @since 3 + * @sysCap Accessibility + */ + std::string GetComponentType() const; + + /** + * @brief Sets the class(component type) name. + * @param className The class(component type) name. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetComponentType(const std::string &className); + + /** + * @brief Gets the before text changed of the component. + * @param - + * @return The before text changed of the component. + * @since 3 + * @sysCap Accessibility + */ + std::string GetBeforeText() const; + + /** + * @brief Set the before text changed of the component. + * @param beforeText The before text changed of the component. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetBeforeText(const std::string &beforeText); + + /** + * @brief Adds an text to the content list. + * @param content Indicates the text to add. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void AddContent(const std::string &content); + + /** + * @brief Gets the content list in the event. + * @param - + * @return Returns the content list in the event. + * @since 3 + * @sysCap Accessibility + */ + std::vector GetContentList() const; + + /** + * @brief Gets the last content of the component(The text of changed after). + * @param - + * @return The last content of the component(The text of changed after). + * @since 3 + * @sysCap Accessibility + */ + std::string GetLatestContent() const; + + /** + * @brief Sets the last content of the component. + * @param content Indicates the last content to set for the component. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetLatestContent(const std::string &content); + + /** + * @brief Gets the accessibility event description. + * @param - + * @return The accessibility event description + * @since 3 + * @sysCap Accessibility + */ + std::string GetDescription() const; + + /** + * @brief Sets the accessibility event description. + * @param contentDescription The accessibility event description + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetDescription(const std::string &contentDescription); + + /*Parcel*//** + * @brief Used for IPC communication + * @param parcel + * @return rue: Read parcel data successfully; ohterwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Used for IPC communication + * @param parcel + * @return true: Write parcel data successfully; ohterwise is not. + * @since 3 + * @sysCap Accessibility + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief + * @param parcel Used for IPC communication + * @return Read AccessibilityMemo from parcel data + * @since 3 + * @sysCap Accessibility + */ + static AccessibilityMemo *Unmarshalling(Parcel &parcel); + +private: + int channelId_ = 0; + int componentId_ = 0; + int windowId_ = 0; + int currentIndex_ = 0; + int beginIndex_ = 0; + int endIndex_ = 0; + std::vector contents_{}; + std::string componentType_ = ""; + std::string description_ = ""; + std::string beforeText_ = ""; + std::string latestConent_ = ""; + int elementId_ = 0; + int itemCounts_ = 0; +}; + +/* +* The class define the event types and supply the api to +* get/set the property of event. and it triggerred by UI +* changed and sent to AA. According to the event property, +* AA can get event properties, such as: action triggerred +* the event and the source. +*/ +class AccessibilityEventInfo : public AccessibilityMemo{ +public: + /** + * @brief Construct + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + AccessibilityEventInfo() {} + + /** + * @brief Construct + * @param eventType the type of event info + * @return + * @since 3 + * @sysCap Accessibility + */ + AccessibilityEventInfo(EventType eventType); + + /** + * @brief Construct + * @param windowId The id of window + * @param windowChangeTypes the window change type + * @return + * @since 3 + * @sysCap Accessibility + */ + AccessibilityEventInfo(int windowId, WindowUpdateType windowChangeTypes); + + /** + * @brief Gets the number of accessibility records. + * @note It is same to getCount​() + * @param - + * @return The number of the records that describe the information of current event + * @since 3 + * @sysCap Accessibility + */ + int GetRecordCount() const; + + /** + * @brief Set the number of accessibility records. + * @note It is same to setCount​(int count) + * @param recordCount The number of the records that describe the information of current event + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetRecordCount(const int recordCount); + + /** + * @brief Adds an accessibility record to describe the information of the current event. + * @note It is same to addRecord​(AccessibilityEventInfo eventInfo) + * @param record The records that describe the information of current event + * @return - + * @since 3 + * @sysCap Accessibility + */ + void AddRecord(const AccessibilityEventInfo &record); + + /** + * @brief Get the record by index. + * @note Remained + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + AccessibilityEventInfo GetRecord(const int index); //remained + + /** + * @brief Gets the accessibility record list. + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + std::vector GetRecords(); + + /** + * @brief Gets the type of an accessibility event. + * @note It is same to the getAccessibilityEventType​() + * @param - + * @return The type of an accessibility event. + * @since 3 + * @sysCap Accessibility + */ + EventType GetEventType() const; + + /** + * @brief Get the window content changed types + * @param - + * @return The window content changed types. Refer to "WindowsContentChangeTypes" + * @since 3 + * * @sysCap Accessibility + */ + WindowsContentChangeTypes GetWindowContentChangeTypes() const; + + /** + * @brief Set the window content changed types + * @param changeTypes The window content changed types. Refer to "WindowsContentChangeTypes" + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetWindowContentChangeTypes(const WindowsContentChangeTypes changeTypes); + + /** + * @brief Get the window changed types + * @param - + * @return The window changed types.refer to WindowUpdateType + * @since 3 + * @sysCap Accessibility + */ + WindowUpdateType GetWindowChangeTypes() const; + + /** + * @brief Set the window changed types + * @param changeTypes The window changed types.refer to WindowUpdateType + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetWindowChangeTypes(const WindowUpdateType changeTypes); + + /** + * @brief Sets the type of an accessibility event. + * @note It is same to setAccessibilityEventType​(int accessibilityEventType) + * @param eventType The type of an accessibility event. Refer to "EventType" + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetEventType(const EventType eventType); + + /** + * @brief AA get the time of accessibility event is sent from ASAC. + * @param - + * @return The time of accessibility event is sent from ASAC + * @since 3 + * @sysCap Accessibility + */ + long long GetTimeStamp() const; + + /** + * @brief ASAC set the time of accessibility is sent to AA + * @param eventTime The time of accessibility event is sent from ASAC + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetTimeStamp(const long long eventTime); //remained:for send event timestamp + + /** + * @brief Gets the bundle name of the event source, that is, the bundle name of the target application. + * @param - + * @return Returns the bundle name of the event source. + * @since 3 + * @sysCap Accessibility + */ + std::string GetBundleName() const; + + /** + * @brief Set the bundle name of the event source, that is, the bundle name of the target application. + * @param bundleName The bundle name of the event source. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetBundleName(const std::string &bundleName); + + /** + * @brief Set the move granularity of the text + * @param granularity The move granularity of the text. Refer to "AccessibilityElementInfo.TextMoveUnit" + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetTextMovementStep(const TextMoveUnit granularity); + + /** + * @brief Get the move granularity of the text + * @param - + * @return he move granularity of the text. Refer to "AccessibilityElementInfo.TextMoveUnit" + * @since 3 + * @sysCap Accessibility + */ + TextMoveUnit GetTextMovementStep() const; + + /** + * @brief Sets the action that triggers the accessibility event. + * @param action The operation of the event. Refer to "AccessibilityElementInfo.ActionType" + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetTriggerAction(const ActionType action); + + /** + * @brief Gets the action that triggers the accessibility event. + * @param - + * @return The operation of the event. Refer to "AccessibilityElementInfo.ActionType" + * @since 3 + * @sysCap Accessibility + */ + ActionType GetTriggerAction() const; + + /** + * @brief Set the information of accessibility event of [TYPE_NOTIFICATION_UPDATE_EVENT] + * @param category Refer to [NotificationCategory], It maybe changed from APP + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetNotificationInfo(const NotificationCategory category); + + /** + * @brief Get the information of accessibility event of [TYPE_NOTIFICATION_UPDATE_EVENT] + * @param - + * @return Refer to [NotificationCategory], It maybe changed from APP + * @since 3 + * @sysCap Accessibility + */ + NotificationCategory GetNotificationInfo() const; + + /*Parcel*/ + /** + * @brief Used for IPC comminication + * @param parcel + * @return true: Read parcel data successfully; ohterwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Used for IPC comminication + * @param parcel + * @return true: Write parcel data successfully; ohterwise is not. + * @since 3 + * @sysCap Accessibility + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Used for IPC comminication + * @param parcel + * @return Read AccessibilityEventInfo from parcel data + * @since 3 + * @sysCap Accessibility + */ + static AccessibilityEventInfo *Unmarshalling(Parcel &parcel); + + /** + * @brief Set the page ID associated with the accessibility event. + * @param pageId The page ID associated with the accessibility event. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetPageId(const int pageId); + + /** + * @brief Gets the page ID associated with the accessibility event. + * @param - + * @return The page ID associated with the accessibility event. + * @since 3 + * @sysCap Accessibility + */ + + int GetPageId() const; + +private: + EventType eventType_ = TYPE_VIEW_INVALID; + std::string bundleName_ = ""; + ActionType triggerAction_ = ACCESSIBILITY_ACTION_INVALID; + long long timeStamp_ = 0; + TextMoveUnit textMoveStep_ = STEP_CHARACTER; + WindowsContentChangeTypes windowContentChangeTypes_ = CONTENT_CHANGE_TYPE_INVALID; + WindowUpdateType windowChangeTypes_ = WINDOW_UPDATE_INVALID; + int recordsCount_ = 0; + std::vector records_{}; + NotificationCategory category_ = CATEGORY_INVALID; + int pageId_ = 0; +}; + +} //namesapce Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/interfaces/innerkits/asacfwk/include/accessibility_interaction_operation.h b/interfaces/innerkits/asacfwk/include/accessibility_interaction_operation.h new file mode 100644 index 00000000..d50e3833 --- /dev/null +++ b/interfaces/innerkits/asacfwk/include/accessibility_interaction_operation.h @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_INTERACTION_OPERATION_H +#define ACCESSIBILITY_INTERACTION_OPERATION_H + +#include +#include +#include + +#include "accessibility_interaction_operation_callback.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class define the interface for UI to implement. +* It triggered by AAMS when AA to request the accessibility information. +*/ +class AccessibilityInteractionOperation { +public: + /** + * @brief Make the node information by accessibility ID and set the result by callback. + * @param elementId: The unique id of the component ID. + * @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. + * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also. + * PREFETCH_SIBLINGS: Need to make the sister/brothers node info also. + * PREFETCH_CHILDREN: Need to make the child node info also. + * otherwise: Make the node information by elementId only. + * @return - + */ + virtual void SearchElementInfoByAccessibilityId(const long elementId, + const int requestId, AccessibilityInteractionOperationCallback &callback, const int mode) = 0; + + /** + * @brief Make the child node information by accessibility ID and filtered by text and set the result by callback. + * @param elementId: The unique id of the component ID. + * @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. + * @param text Filter for the child components to matched with the text + * @return + */ + virtual void SearchElementInfosByText(const long elementId, const std::string &text, + const int requestId, AccessibilityInteractionOperationCallback &callback) = 0; + + /** + * @brief Make the node information of the component focused by the focus type specified. + * @param elementId: The unique id of the component ID. + * @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. + * @param focusType FOCUS_TYPE_ACCESSIBILITY: accessibility focus + * FOCUS_TYPE_INPUT: text input focus + * @return + */ + virtual void FindFocusedElementInfo(const long elementId, const int focusType, const int requestId, + AccessibilityInteractionOperationCallback &callback) = 0; + + /** + * @brief Make the node info by current focus move direction. + * @param elementId: The unique id of the component ID. + * @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. + * @param direction Refer to AccessibilityElementInfo.FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD) + * @return - + */ + virtual void FocusMoveSearch(const long elementId, const int direction, const int requestId, + AccessibilityInteractionOperationCallback &callback) = 0; + + /** + * @brief To return the result of perform action. + * @param elementId: The unique id of the component ID. + * @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. + * @param action Refer to [AccessibilityElementInfo.ActionType] + * @param actionArguments The parameter for action type. such as: + * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, + * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) + * action: ACCESSIBILITY_ACTION_NEXT_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, + * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) + * action: ACCESSIBILITY_ACTION_SET_SELECTION, + * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, + * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) + * action: ACCESSIBILITY_ACTION_SET_TEXT, + * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") + * @return + */ + virtual void PerformAction(const long elementId, const int action, const std::map actionArguments, + const int requestId, AccessibilityInteractionOperationCallback &callback) = 0; + + /** + * @brief The function is called while accessibility System check the id of window is not equal + * to the id of active window when sendAccessibility. + * @param - + * @return + */ + virtual void ClearFocus() = 0; + + /** + * @brief The low layser is notified by the function called while accessibility system execute + * the function of performAction from AS to check the all low windows cared the outside event. + * Example: PopupWindow receive the OUTSIDE_EVENT to close itself. + * @param - + * @return + */ + virtual void OutsideTouch() = 0; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/asacfwk/include/accessibility_interaction_operation_callback.h b/interfaces/innerkits/asacfwk/include/accessibility_interaction_operation_callback.h new file mode 100644 index 00000000..2798c075 --- /dev/null +++ b/interfaces/innerkits/asacfwk/include/accessibility_interaction_operation_callback.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_INTERACTION_OPERATION_CALLBACK_H +#define ACCESSIBILITY_INTERACTION_OPERATION_CALLBACK_H + +#include +#include +#include + +#include "accessibility_element_info.h" + +namespace OHOS { +namespace Accessibility { +/* +* The class supply the callback to feedback the result from UI to AA. + +*/ +class AccessibilityInteractionOperationCallback { +public: + /** + * @brief Set the element information by accessibility id to AA. + * @param infos The element info searched by accessibility id. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetSearchElementInfoByAccessibilityIdResult(const std::list &infos, + const int requestId) = 0; + + /** + * @brief Set the element informations matched with text to AA. + * @param infos The element informations searched matched with text. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetSearchElementInfoByTextResult(const std::list &infos, + const int requestId) = 0; + + /** + * @brief Set the element informations matched with focus type to AA. + * @param info The element informations searched matched with focus type. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info, const int requestId) = 0; + + /** + * @brief Set the element informations by focus direction to AA. + * @param info The element informations searched by focus direction. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int requestId) = 0; + + /** + * @brief Set the result of action executed to AA. + * @param succeeded True: The action is executed successfully; otherwise is false. + * @param requestId The request id from AA, it is used to match with request and response. + * @return + */ + virtual void SetPerformActionResult(const bool succeeded, const int requestId) = 0; +}; + +} //namespace Accessibility +} //namesapce OHOS +#endif \ No newline at end of file diff --git a/interfaces/innerkits/asacfwk/include/accessibility_state_event.h b/interfaces/innerkits/asacfwk/include/accessibility_state_event.h new file mode 100644 index 00000000..6b47195c --- /dev/null +++ b/interfaces/innerkits/asacfwk/include/accessibility_state_event.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_STATE_EVENT_H +#define ACCESSIBILITY_STATE_EVENT_H + +#include +#include + +namespace OHOS { +namespace Accessibility { +enum AccessibilityStateEventType : int { + EVENT_ACCESSIBILITY_STATE_CHANGED = 0x00000001, + EVENT_TOUCH_GUIDE_STATE_CHANGED = 0x00000002, +}; +/* +* This class is used for ASAC as the listener of AAMS. + +*/ +class AccessibilityStateEvent { +public: + AccessibilityStateEvent(); + + /** + * @brief Get the type of the state event. + * @return EVENT_ACCESSIBILITY_STATE_CHANGED/EVENT_TOUCH_GUIDE_STATE_CHANGED + * @since 3 + * @sysCap Accessibility + */ + AccessibilityStateEventType GetEventType() const; + + /** + * @brief Get the state of the ability. + * @return 0:enabled; otherwise is disabled; + * @since 3 + * @sysCap Accessibility + */ + int GetEventResult() const; + + /** + * @brief Get the description of the ability. + * @return The description of the ability + * @since 3 + * @sysCap Accessibility + */ + std::string GetEventMsg() const; + + /** + * @brief Set the type of the state event. + * @param eventType EVENT_ACCESSIBILITY_STATE_CHANGED/EVENT_TOUCH_GUIDE_STATE_CHANGED + * @since 3 + * @sysCap Accessibility + */ + void SetEventType(const AccessibilityStateEventType eventType); + + /** + * @brief Get the state of the ability. + * @param enabled 0:enabled; otherwise is disabled; + * @since 3 + * @sysCap Accessibility + */ + void SetEventResult(const int enabled); + + /** + * @brief Set the description of the ability. + * @param description The description of the ability + * @since 3 + * @sysCap Accessibility + */ + void SetEventMsg(std::string &description); +private: + AccessibilityStateEventType eventType_ = EVENT_ACCESSIBILITY_STATE_CHANGED; + int enabled_ = 0; + std::string describeEvent_ = ""; +}; + +class AccessibilityStateObserver { +public: + /** + * @brief Receives notifications on accessibility status changes. + * @param stateEvent Indicates the status change event. + * @return + * @since 3 + * @sysCap Accessibility + */ + virtual void OnStateChanged(const AccessibilityStateEvent& stateEvent) = 0; + + /** + * @brief Construct + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + AccessibilityStateObserver() {} + + /** + * @brief Destruct + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + virtual ~AccessibilityStateObserver() = default; +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/interfaces/innerkits/asacfwk/include/accessibility_system_ability_client.h b/interfaces/innerkits/asacfwk/include/accessibility_system_ability_client.h new file mode 100644 index 00000000..e3102939 --- /dev/null +++ b/interfaces/innerkits/asacfwk/include/accessibility_system_ability_client.h @@ -0,0 +1,322 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_SYSTEM_ABILITY_CLIENT_H +#define ACCESSIBILITY_SYSTEM_ABILITY_CLIENT_H + +#include +#include +#include +#include +#include +#include + +#include "accessibility_event_info.h" +#include "accessibility_state_event.h" +#include "accessibility_interaction_operation.h" +#include "accessibility_ability_info.h" +#include "context.h" +#include "refbase.h" + +namespace OHOS { +namespace Accessibility { +#define ACCESSIBILITY_DECLARE_IMPL() \ + struct Impl; \ + std::unique_ptr pimpl + +enum AccessibilityControlType : int { + CONTENT_CONTROLS = 0x00000001, + CONTENT_ICONS = 0x00000002, + CONTENT_TEXT = 0x00000004, +}; + +enum AbilityStateType: int { + ABILITY_STATE_INVALID = 0, + ABILITY_STATE_ENABLE, + ABILITY_STATE_DISABLE, + ABILITY_STATE_INSTALLED, +}; + +/* +* The class register the accessibility service observer to AAMS,and +* dispatch the accessibility service status changed. such as Service Enable, +* Accessibility Enable. It calls AAMS API to send the event to AA. +* It supply sington instance for each process. +*/ +class CaptionProperties { +public: + CaptionProperties() {} + bool CheckProperty(const std::string &property); + int GetBackgroundColor() const; //remained + int GetForegroundColor() const; //remained + int GetEdgeType() const; //remained + int GetEdgeColor() const; //remained + int GetWindowColor() const; //remained + +private: + bool HasBackgroundColor(); + bool HasForegroundColor(); + bool HasEdgeType(); + bool HasEdgeColor(); + bool HasWindowColor(); + + bool hasBackgroundColor_ = false; + bool hasEdgeType_ = false; + bool hasEdgeColor_ = false; + bool hasWindowColor_ = false; + bool hasForegroundColor_ = false; + int backgroundColor_ = 0; //remained + int edgeType_ = 0; //remained + int edgeColor_ = 0; //remained + int windowColor_ = 0; //remained + int foregroundColor_ =0; //remained +}; + +class AccessibilitySystemAbilityClient { +public: + static const int NUM_INT32 = 32; + static const uint32_t STATE_ACCESSIBILITY_ENABLED = 0x00000001; + static const uint32_t STATE_EXPLORATION_ENABLED = 0x00000002; + static const uint32_t STATE_ACCESSIBILITY_DISABLED = 0x00000004; + static const uint32_t STATE_EXPLORATION_DISABLED = 0x00000008; + + /** + * @brief Construct. + * @param context Indicates the context of the associated ability. + * @param accountId User Id + */ + AccessibilitySystemAbilityClient(const AppExecFwk::Context &context, int accountId); + + /** + * @brief Register the interaction operation, so the AA can get node info from ACE. + * @param windowId Window ID + * @param operation The callback object. + * @param accountId User ID + * @return 0: Succeed ; otherwise is failed. + */ + int RegisterInteractionOperation(const int windowId, + const std::shared_ptr &operation, int accountId); + + /** + * @brief Deregister the interaction operation. + * @param windowId Window ID + * @return + */ + void DeregisterInteractionOperation(const int windowId); + + /** + * @brief Checks whether accessibility ability is enabled. + * @param - + * @return true: enabled; false: disabled + */ + bool IsEnabled(); + + /** + * @brief Checks whether touch exploration ability is enabled. + * @param - + * @return true: enabled; false: disabled + */ + bool IsTouchExplorationEnabled(); + + /** + * @brief Queries the list of accessibility abilities. + * @param accessibilityAbilityTypes Indicates the accessibility type specified by + * AccessibilityAbilityInfo#ACCESSIBILITY_ABILITY_TYPE_SPOKEN. + * @param stateType Indicates the accessibility ability status. + * 1 indicates that the ability is enabled; + * 2 indicates that the ability is disabled; + * 4 indicates that the ability has been installed. + * @return + */ + std::vector GetAbilityList(const int accessibilityAbilityTypes, + const AbilityStateType stateType); + + /** + * @brief Obtains the AccessibilitySystemAbilityClient instance. + * @param abilityContext Indicates the context of the associated ability. + * @return AccessibilitySystemAbilityClient instance + */ + static std::shared_ptr GetInstance(const AppExecFwk::Context &abilityContext); + + /** + * @brief Obtains the AccessibilitySystemAbilityClient instance. + * @param - + * @return AccessibilitySystemAbilityClient instance + */ + static std::shared_ptr GetInstance(); + + /** + * @brief Obtains the suggested interval for switching the UI. + * Remained. + * @param timeout Indicates the interval at which the UI is changed. + * @param contentType Indicates the type of the UI control. + * @return Returns the interval. + */ + int GetSuggestedInterval(const int timeout, const int contentType); + + /** + * @brief Obtains the properties of the accessibility caption function. + * Remained for caption. + * @param - + * @return Returns the properties of the accessibility caption function. + */ + CaptionProperties GetAccessibilityCaptionProperties() const; + + /** + * @brief Checks whether the accessibility caption function is enabled. + * Remained for caption. + * @param - + * @return True if the caption function is enabled; returns False otherwise. + */ + bool IsAccessibilityCaptionEnabled() const; + + /** + * @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. + */ + bool SendEvent(const EventType eventType, const int componentId); + + /** + * @brief Sends information about an accessibility event. + * @param event Indicates the accessibility event information specified by AccessibilityEventInfo. + * @return true: send ok; otherwise is refused. + */ + bool SendEvent(const AccessibilityEventInfo &event); + + /** + * @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 AccessibilityStateEvent + * #EVENT_ACCESSIBILITY_STATE_CHANGED and AccessibilityStateEvent#EVENT_TOUCH_BROWSE_STATE_CHANGED + * @return true: send ok; otherwise is refused. + */ + bool SubscribeStateObserver(const std::shared_ptr &observer, const int eventType); + + /** + * @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 AccessibilityStateEvent + * #EVENT_ACCESSIBILITY_STATE_CHANGED and AccessibilityStateEvent#EVENT_TOUCH_BROWSE_STATE_CHANGED + * @return true: send ok; otherwise is refused. + */ + bool UnsubscribeStateObserver(const std::shared_ptr &observer, const int eventType); + + /** + * @brief Unsubscribe the accessibility status change events from the observer. + * @param observer Indicates the registered accessibility status event observer. + * @return true is succeed otherwise is failed. + */ + bool UnsubscribeStateObserver(const std::shared_ptr &observer); + + /** + * @brief Inner function for aams status update; + * Set whether accessibility ability is enabled. + * @param enabled true is enabled otherwise is disabled. + * @return - + */ + void SetEnabled(const bool enabled); + + /** + * @brief Inner function for aams status update; + * Set whether touch exploration is enabled. + * @param enabled true is enabled otherwise is disabled. + * @return - + */ + void SetTouchExplorationEnabled(const bool enabled); + + /** + * @brief Check otherwise Accessibility Ability(AA) is conflicted with other AA. + * Remained for setting subsystem. + * @param abilityName The AA specified (include deviceId/bundleName/abilityName) + * @return LAUNCH_CONFLICT_NONE: no conflict; + * LAUNCH_CONFLICT_TOUCH_BROWSER: conflict with touch browser; + * LAUNCH_CONFLICT_DISPLAY_RESIZE: conflict with display resize; + * LAUNCH_CONFLICT_KEY_EVENT: conflict with key event; + * LAUNCH_CONFLICT_FINGERPRINT_GESTURE: conflict with fingerprint gesture. + */ + int CheckConflictWithEnabledAbility(const AppExecFwk::ElementName &abilityName) { return 0;} + + /** + * @brief Get the AA specified capability. + * Remained for setting subsystem. + * @param abilityName The AA specified (include deviceId/bundleName/abilityName) + * @return refer to AccessibilityAbilityInfo.Capability + */ + int GetAccessibleAbilityCapability(const AppExecFwk::ElementName &abilityName) { return 0;} + + /** + * @brief Requests feedback interruption from all accessibility services. + * Remained. + * @param - + * @return + */ + void Interrupt(); + + /** + * @brief Inner function. + * Get the callback object registed by ACE. + * @param windowId The window id related the operation object registed. + * @return The callback object of ACE. + */ + std::shared_ptr GetInteractionObject(int windowId); + +private: + /** + * @brief Clean the AAMS object data. + * @param remote The object access to AAMS. + * @return + */ + void ResetService(const wptr& remote); + + /** + * @brief Notify the state of accessibility is changed. + * @param + * @return + */ + void NotifyAccessibilityStateChanged(); + + /** + * @brief Notify the state of touch exploration is changed. + * @param + * @return + */ + void NotifyTouchExplorationStateChanged(); + + /** + * @brief Check the event type is valid or not. + * @param eventType The data of event type. + * @return True: The data of event type is valid; otherwise is not. + */ + bool CheckEventType(EventType eventType); + std::vector> observersAceessibilityState_{}; + std::vector> observersTouchState_{}; + CaptionProperties captionProperties_ {}; + int accountId_ = 0; + bool isEnabled_ = 0; + bool isTouchExplorationEnabled_ = 0; + std::recursive_mutex asacProxyLock_; + static std::shared_ptr instance_ ; + std::shared_ptr interactionOperator_; + std::map> interactionOperators_{}; + int connectionWindowId_ = 0; + ACCESSIBILITY_DECLARE_IMPL(); +}; + +} //namespace Accessibility +} //namespace OHOS +#endif \ No newline at end of file diff --git a/interfaces/innerkits/asacfwk/include/accessibility_window_info.h b/interfaces/innerkits/asacfwk/include/accessibility_window_info.h new file mode 100644 index 00000000..a2d96053 --- /dev/null +++ b/interfaces/innerkits/asacfwk/include/accessibility_window_info.h @@ -0,0 +1,357 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_WINDOW_H +#define ACCESSIBILITY_WINDOW_H + +#include +#include +#include "accessibility_element_info.h" +#include "accessibility_event_info.h" +#include "parcel.h" + +namespace OHOS { +namespace Accessibility { +enum WindowType : int { + TYPE_WINDOW_INVALID = 0, + TYPE_ACCESSIBILITY_OVERLAY = 0x00000001, + TYPE_APPLICATION = 0x00000002, + TYPE_INPUT_METHOD = 0x00000004, + TYPE_SPLIT_SCREEN_DIVIDER = 0x00000008, + TYPE_SYSTEM = 0x00000010, +}; +static const int INVALID_WINDOW_ID = -1; +static const int ANY_WINDOW_ID = -2; +static const int ACTIVE_WINDOW_ID = 0x7FFFFFFF; + +class AccessibilityWindowInfo : public Parcelable { +public: + /** + * @brief Construct + * @param + * @return + * @since 3 + * @sysCap Accessibility + */ + AccessibilityWindowInfo(); + + /** + * @brief Get the title of window + * @param - + * @return The title of window + * @since 3 + * @sysCap Accessibility + */ + std::string GetWindowTitle() const; + + /** + * @brief Set the title of window + * @param title The title of window + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetWindowTitle(std::string &title); + + /** + * @brief Get the window type. + * @param - + * @return The window type. Refer to [WindowType]. + * @since 3 + * @sysCap Accessibility + */ + WindowType GetWindowType() const; + + /** + * @brief Set the window type. + * @param type The window type. Refer to [WindowType]. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetWindowType(const WindowType type); + + /** + * @brief Get The window layer + * @param - + * @return The layer of window + * @since 3 + * @sysCap Accessibility + */ + int GetWindowLayer() const; + + /** + * @brief Set The window layer + * @param layer The window layer + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetWindowLayer(const int layer); + + /** + * @brief Get the root node information of the window. + * @param - + * @return The root node information. + * @since 3 + * @sysCap Accessibility + */ + bool GetRootAccessibilityInfo(AccessibilityElementInfo &elementInfo); + + /** + * @brief Set an anchor accessibility node that anchors this window to another window. + * @param anchorId The accessibility id of component. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetAnchorId(const int anchorId); + + /** + * @brief Obtains an anchor accessibility node that anchors this window to another window. + * @param - + * @return The node information of the anchored component. + * @since 3 + * @sysCap Accessibility + */ + bool GetAnchor(AccessibilityElementInfo &elementInfo); + + /** + * @brief Get the parent window + * @param - + * @return - + * @since 3 + * @sysCap Accessibility + */ + AccessibilityWindowInfo GetParent(); + + /** + * @brief Set the parent window + * @param parentId The window id of the parent. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetParentId(const int parentId); + + /** + * @brief Get the parent window + * @param - + * @return The window id of the parent. + * @since 3 + * @sysCap Accessibility + */ + int GetParentId(); + + /** + * @brief Get the anchor window + * @param - + * @return The anchor id of the window. + * @since 3 + * @sysCap Accessibility + */ + int GetAnchorId(); + + /** + * @brief Get the parent window + * @param - + * @return The window id of the parent. + * @since 3 + * @sysCap Accessibility + */ + std::vector GetChildIds(); + + /** + * @brief Get the widnow id of current window. + * @param - + * @return The widnow id of current window. + * @since 3 + * @sysCap Accessibility + */ + int GetWindowId() const; + + /** + * @brief Set the widnow id of current window. + * @param id The widnow id of current window. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetWindowId(const int id); + + /** + * @brief AAMS called to set the id of the IAccessibleAbilityChannel. + * @param channelId The id of the IAccessibleAbilityChannel. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetChannelId(const int channelId); + + /** + * @brief Get the id of the IAccessibleAbilityChannel. + * @param + * @return The id of the IAccessibleAbilityChannel. + * @since 3 + * @sysCap Accessibility + */ + int GetChannelId() const; + + /** + * @brief Get the screen pixel coordinates + * @param - + * @return The screen pixel coordinates + * @since 3 + * @sysCap Accessibility + */ + Rect GetRectInScreen() const; + + /** + * @brief Set the screen pixel coordinates + * @param bounds The screen pixel coordinates + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetRectInScreen(const Rect &bounds); + + /** + * @brief Check whether the window is active or not. + * @param - + * @return true: the window is active, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsActive() const; + + /** + * @brief Set whether the window is active or not. + * @param active true: the window is active, otherwise is not. + * @return + * @since 3 + * @sysCap Accessibility + */ + void SetActive(bool active); + + /** + * @brief Checks whether this window has gained focus. + * @param + * @return true: the window has gained focus, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsFocused() const; + + /** + * @brief Set whether this window has gained focus. + * @param focused true: the window has gained focus, otherwise is not. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetFocused(bool focused); + + /** + * @brief Checks whether this window has gained accessibility focus. + * @param - + * @return true: this window has gained accessibility focus, otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool IsAccessibilityFocused() const; + + /** + * @brief Set whether this window has gained accessibility focus. + * @param accessibilityfocused true: this window has gained accessibility focus, otherwise is not. + * @return - + * @since 3 + * @sysCap Accessibility + */ + void SetAccessibilityFocused(const bool accessibilityfocused); + + /** + * @brief Obtains the quantity of child windows. + * @param - + * @return The quantity of child windows. + * @since 3 + * @sysCap Accessibility + */ + int GetChildNum() const; + + /** + * @brief Obtains information about the accessibility child window at a specified index. + * @param index The index of the child + * @return The child window specified by index. + * @since 3 + * @sysCap Accessibility + */ + AccessibilityWindowInfo GetChild(const int index); + + /** + * @brief Add the child window + * @param childId the window id of the child + * @return - + * @since 3 + * @sysCap Accessibility + */ + void AddChild(const int childId); + + /*Parcel*/ + /** + * @brief Used for IPC communication. + * @param parcel Serializable data. + * @return true: Read parcel data successfully; otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + bool ReadFromParcel(Parcel &parcel); + + /** + * @brief Used for IPC communication. + * @param parcel + * @return true: Write parcel data successfully; otherwise is not. + * @since 3 + * @sysCap Accessibility + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Used for IPC communication. + * @param parcel + * @return The data of AccessibilityWindowInfo + * @since 3 + * @sysCap Accessibility + */ + static AccessibilityWindowInfo *Unmarshalling(Parcel &parcel); + +private: + WindowType windowType_ = TYPE_WINDOW_INVALID; + int windowLayer_ = INVALID_WINDOW_ID; + int windowId_ = INVALID_WINDOW_ID; + int parentId_ = INVALID_WINDOW_ID; + std::string windowTitle_ = ""; + std::vector childIds_{}; + int anchorId_ = -1; + int childNum_ = 0; + int channelId_ = INVALID_WINDOW_ID; + bool active_ = false; + bool focused_ = false; + bool accessibilityFocused_ = false; + Rect boundsInScreen_ {}; +}; + +} // namespace Accessibility +} // namespace OHOS +#endif diff --git a/interfaces/kits/js/@component/displayResizeInfo.d.ts b/interfaces/kits/js/@component/displayResizeInfo.d.ts new file mode 100644 index 00000000..5856b44a --- /dev/null +++ b/interfaces/kits/js/@component/displayResizeInfo.d.ts @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2021 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 { Rect } from './rect' +//@note hide +export interface DisplayResizeInfo { + /** + * The rect of the display resized. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + rect: Rect; + + /** + * The scale of the display resized. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + scale: number; + + /** + * the x coordinate of the resize center. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + centerX: number; + + /** + * the y coordinate of the resize center. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + centerY: number; +} \ No newline at end of file diff --git a/interfaces/kits/js/@component/gesturePath.d.ts b/interfaces/kits/js/@component/gesturePath.d.ts new file mode 100644 index 00000000..208bf6e9 --- /dev/null +++ b/interfaces/kits/js/@component/gesturePath.d.ts @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2021 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. + */ + +//@note hide +export class GesturePath { + /** + * The path list of the gesture. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + * @note The max number of the path is 10; + */ + pos: Array; + + /** + * The start position of the gesture. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + startPos: GesturePos; + + /** + * The end position of the gesture. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + endPos: GesturePos; + + /** + * The duration time of the gesture. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + * @note The max of the durationtime is 60 * 1000 ms; + */ + durationTime: number; +} +//@note hide +export class GesturePos { + constructor(x: number, y: number); + /** + * The x coordinate of position. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + posX: number; + + /** + * The y coordinate of position. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + posY: number; +} \ No newline at end of file diff --git a/interfaces/kits/js/@component/gridInfo.d.ts b/interfaces/kits/js/@component/gridInfo.d.ts new file mode 100644 index 00000000..7a8ae5f4 --- /dev/null +++ b/interfaces/kits/js/@component/gridInfo.d.ts @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2021 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. + */ + +export interface GridInfo { + /** + * Row count of the collection. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + rowCount: number; + + /** + * Column count of the collection. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + columnCount: number; + + /** + * Selection mode of collection. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + selectionMode: number; +} + +export interface GridItemInfo { + /** + * Whether is head. + * @default false + * @since 3 + * @sysCap Accessibility + */ + heading: boolean; + + /** + * The index of the column. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + columnIndex: number; + + /** + * The index of the row. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + rowIndex: number; + + /** + * column span. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + columnSpan: number; + + /** + * row span. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + rowSpan: number; + + /** + * Whether is selected. + * @default false + * @since 3 + * @sysCap Accessibility + */ + selected: boolean; + +} \ No newline at end of file diff --git a/interfaces/kits/js/@component/progress.d.ts b/interfaces/kits/js/@component/progress.d.ts new file mode 100644 index 00000000..e8c66ad6 --- /dev/null +++ b/interfaces/kits/js/@component/progress.d.ts @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2021 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. + */ + +//define for progressbar +export interface RangeInfo { + /** + * The min of the ProgressBar. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + min: number; + + /** + * The max of the ProgressBar. + * @default 100 + * @since 3 + * @sysCap Accessibility + */ + max: number; + + /** + * The current value of the ProgressBar. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + current: number; +} \ No newline at end of file diff --git a/interfaces/kits/js/@component/rect.d.ts b/interfaces/kits/js/@component/rect.d.ts new file mode 100644 index 00000000..896efdd9 --- /dev/null +++ b/interfaces/kits/js/@component/rect.d.ts @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2021 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. + */ + +// Rect +export interface Rect{ + leftTopX:number; + leftTopY: number; + rightBottomX: number; + rightBottomY: number; +} \ No newline at end of file diff --git a/interfaces/kits/js/@ohos.accessibility.d.ts b/interfaces/kits/js/@ohos.accessibility.d.ts new file mode 100644 index 00000000..d36f99f9 --- /dev/null +++ b/interfaces/kits/js/@ohos.accessibility.d.ts @@ -0,0 +1,1180 @@ +/* + * Copyright (C) 2021 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 { AsyncCallback, Callback} from 'basic'; +import { AbilityInfo } from 'abilityinfo' +import { Rect } from './@component/rect' +import { GridInfo, GridItemInfo } from "./@component/gridInfo" +import { RangeInfo } from "./@component/progress" +/** + * Accessibility + * @name Accessibility + * @since 3 + * @sysCap Accessibility + * @devices phone, tablet + * @child NotSupport + * @permission 权限列表 + * @note 标记说明 + */ +declare namespace accessibility { +/************************************************************************************************ + * Type define +***********************************************************************************************/ + /** + * The type of the Ability app. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type AbilityType = 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual'; + + /** + * The action that the ability can execute. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type Action = 'accessibilityFocus' | 'clearAccessibilityFocus' | 'focus' | 'clearFocus' | 'clearSelection' | + 'click' | 'longClick' | 'cut' | 'copy' | 'paste' | 'select' | 'setText' | 'delete' | + 'scrollForward' | 'scrollBackward' | + 'setSelection' | + 'unfold' | 'fold' | 'nextText' | 'previousText' | 'nextHtmlItem' | 'previousHtmlItem'; + + /** + * The type of the accessibility event. + * @note windowsChange:页面变化(迁移)的通知,旁白需要确定新画面的焦点【must】 + * @note windowContentChange:窗口中内容变更通知,旁白朗读屏幕变更的内容(在焦点控件/LiveRegion的情况下)【must】 + * @note windowStateChange:页面变化通知(比如迁移到新页面,弹出Alert画面),用于朗读新页面的title信息,提示用户页面迁移。【must】 + * @note announcement:应用程序发布公告的事件,(A侧)会通知来电的电话号码信息,以及通知栏中的具体控件(如蓝牙快捷键)操作信息。【Must】 + * @note notificationChange:应用程序的通知,比如邮件、短信等通知消息,旁白需要朗读通知中的内容【must】 + * @note textTraversedAtMove:编辑情况下光标移动,会朗读光标移动期间的文本信息【must】 + * @since 3 + * @sysCap Accessibility + */ + type EventType = 'accessibilityFocus' | 'accessibilityFocusClear' | + 'click' | 'longClick' | 'focus' | 'select' | 'hoverEnter' | 'hoverExit' | + 'textUpdate' | 'textSelectionUpdate' | 'scroll' | 'textMoveUnit' | + 'touchBegin' | 'touchEnd' | 'touchGuideBegin' | 'touchGuideEnd' | + 'touchGuideGestureBegin' | 'touchGuideGestureEnd' | + 'windowUpdate' | 'pageContentUpdate' | 'pageStateUpdate' | + 'publicNotice' | 'notificationUpdate'; + + /** + * The change type of the windowsChange event. + * @note It's used when received the {@code windowsChange} event. + * @since 3 + * @sysCap Accessibility + */ + type WindowUpdateType = 'add' | 'remove' | 'title' | 'bounds' | 'layer' | 'active' | + 'focus' | 'accessibilityFocus' | 'parent' | 'children' | 'pip'; + + /** + * The type of the StateEvent. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type StateEventType = 'accessibility' | 'touchGuide'; + + /** + * The type of the window. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type WindowType = 'application' | 'inputMethod' | 'system' | 'accessibilityOverlay' | 'screenDivider'; + + /** + * The type of the focus. + * @note accessibility: accessibility focus; input: input focus; + * @since 3 + * @sysCap Accessibility + */ + type FocusType = 'accessibility' | 'normal'; + + /** + * The type of the ability state. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type AbilityState = 'enable' | 'disable' | 'install'; + + /** + * The direction of the focus move. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type Direction = 'up' | 'down' | 'left' | 'right' | 'forward' | 'backward'; + + /** + * The ability that accessibility subsystem support. + * @note touchExplorer: Describes the capability to talkback. + magnification: Describes the capability to request to control the display magnification. + gesturesSimulation: Describes the capability to request to simulate the gesture. + windowContent: Describes the capability to search for the content of the active window. + filterKeyEvents: Describes the capability to request to filter key events. + fingerprintGesture: Describes the capability to request to fingerprint gesture. + * @since 3 + * @sysCap Accessibility + */ + type Capability = 'retrieve' | 'touchGuide' | 'keyEventObserver' | 'zoom' | 'gesture'; + + /** + * The global action that the ability can execute. + * @note back: Indicates a global action of returning to the previous page. + home: Indicates a global action of returning to the home page. + recents: Indicates a global action of displaying a list of recent tasks. + notifications: Indicates a global action of opening the notification panel. + quickSettings: Indicates a global action of opening quick settings. + powerDialog: Indicates a global action of pressing and holding the power button. + toggleSplitScreen: Indicates a global action of switching between split screens. + lockScreen: Indicates a global action of locking the screen. + takeScreenShot: Indicates a global action of taking a screenshot. + * @since 3 + * @sysCap Accessibility + */ + type GlobalActionType = 'back' | 'home' | 'recent' | 'notification' | 'popUpPowerDialog' | 'divideScreen' | + 'lockScreen' | 'captureScreen'; + + /** + * The types of swipe gestures which are performed on the touch screen. + * And they are also the gesture's interception type. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type GestureType = 'left' | 'leftThenRight' | 'leftThenUp' | 'leftThenDown' | + 'right' | 'rightThenLeft' | 'rightThenUp' | 'rightThenDown' | + 'up' | 'upThenLeft' | 'upThenRight' | 'upThenDown' | + 'down' | 'downThenLeft' | 'downThenRight' | 'downThenUp'; + + /** + * The granularity of text move. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type TextMoveUnit = 'char' | 'word' | 'line' | 'page' | 'paragraph'; + + /** + * The argument type for operation. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type OperatorParamType = 'selectTextBegin' | 'selectTextEnd' | 'htmlItem' | 'setText' | 'textMoveUnit'; + + /** + * The category of the notification + * @note 应用Notification的具体分类,用于朗读通知信息时提示是哪类通知. + * @since 3 + * @sysCap Accessibility + */ + type NotificationCategory = 'call' | 'msg' | 'email' | 'event' | + 'promo' | 'alarm' | 'progress' | 'social' | 'err' | 'transport' | 'sys' | 'service'; + + /** + * The html element type. The arguments of nextHtmlElement/previousHtmlElement + * @note html元素的具体分类,用于实现网页的按类别导航,如“跳到下一个链接或按钮”. + * @since 3 + * @sysCap Accessibility + */ + type HtmlItemType = 'link' | 'control' | 'graphic' | 'listItem' | 'list' | 'table' | + 'combox' | 'heading' | 'button' | 'checkBox' | 'landmark' | 'textField' | 'focusable' | + 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; + + /** + * Checks whether accessibility ability is enabled. + * @since 3 + * @sysCap Accessibility + * @param - + * @return Returns {@code true} if the accessibility is enabled; returns {@code false} otherwise. + */ + function isOpenAccessibility(callback: AsyncCallback): void; + function isOpenAccessibility(): Promise; + + /** + * Checks touch browser ability (which is used by talkback) is enabled. + * @since 3 + * @sysCap Accessibility + * @param - + * @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 3 + * @sysCap Accessibility + * @param abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken + * @param stateType The state of the accessibility ability. {@code AbilityState} eg.installed + * @return Returns the list of abilityInfos. + */ + function getAbilityLists(abilityType: AbilityType, stateType: AbilityState, + callback: AsyncCallback>): void; + function getAbilityLists(abilityType: AbilityType, + stateType: AbilityState): Promise>; + + /** + * Send accessibility Event. + * @since 3 + * @sysCap Accessibility + * @param event The object of the accessibility {@code EventInfo} . + * @return Returns {@code true} if successed; returns {@code false} otherwise. + */ + function sendEvent(event: EventInfo, callback: AsyncCallback): void; + function sendEvent(event: EventInfo): Promise; + + /** + * Register the observe of the state changed. + * @since 3 + * @sysCap Accessibility + * @param type state event type + * @return Returns {@code true} if the register is successed; returns {@code false} otherwise. + */ + function on(type: StateEventType, callback: Callback): void; + + /** + * Deregister the observe of the state changed. + * @since 3 + * @sysCap Accessibility + * @param type state event type + * @return Returns {@code true} if the deregister is successed; returns {@code false} otherwise. + */ + function off(type: StateEventType, callback?: Callback): void; + + /** + * Get the ability client. + * @since 3 + * @sysCap Accessibility + * @return Returns the object of ability. + */ + function getAccessibleAbility(callback: AsyncCallback): void; + function getAccessibleAbility(): Promise; + + interface AccessibleAbility { + /** + * Connect to the accessibility subsystem. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return -. + */ + connect(callback: AsyncCallback): void; + connect(): Promise; + + /** + * Obtains the accessibility node that gains the focus. + * @since 3 + * @sysCap AccessibilityAbility + * @param focusType The type of focus. {@code FocusType} + * @return -. + */ + getFocusElementInfo(focusType: FocusType, callback: AsyncCallback): void; + getFocusElementInfo(focusType: FocusType): Promise; + + /** + * Obtains information about the accessibility root node. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return The root node info. + */ + getRootElementInfo(callback: AsyncCallback): void; + getRootElementInfo(): Promise; + + /** + * Obtains the list of interactive windows on the device, in the layers they are visible to users. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return the list of interactive windows. + */ + getWindows(callback: AsyncCallback>): void; + getWindows(): Promise>; + + /** + * Executes a specified action. + * @since 3 + * @sysCap AccessibilityAbility + * @param action The action wanted to be excused. + * @return The window info. + */ + performCommonAction(action: GlobalActionType, callback: AsyncCallback): void; + performCommonAction(action: GlobalActionType): Promise; + + /** + * Disables the accessibility ability + * @since 3 + * @note hide + * @sysCap Accessibility + * @param name ability name + * @return Returns the object of ability. + */ + disableAbility(callback: AsyncCallback): void; + disableAbility(): Promise; + + /** + * Called when an accessibility event occurs. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return - + */ + on(type: 'accessibilityEvent', callback: Callback): void; + + /** + * Called when a user performs a specified gesture on the device that your accessibility application + has requested to be in touch browser mode. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return - + */ + on(type: 'gesture', callback: Callback): void; + + /** + * Called when your accessibility service is successfully connected to the OS. You can implement + this method to perform subsequent initialization operations. + * @since 3 + * @note hide + * @sysCap AccessibilityAbility + * @param - + * @return - + */ + on(type: 'AbilityConnected', callback: Callback): void; + + } + + interface AccessibilityAbilityInfo { + /** + * The ability id. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly id: string; + + /* The ability name. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly name: string; + + /* The bundle name of the ability. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly bundleName: string; + + /** + * The ability info. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly abilityInfo: AbilityInfo; + + /** + * The type of the ability. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly abilityTypes: Array; + + /** + * The capabilities of the ability. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly capabilities: Array; + + /** + * The description of the ability. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly description: string; + + /** + * The events which the accessibility ability wants to observe. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly eventTypes: Array; + + /** + * The application names which the accessibility ability wants to observe. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly filterBundleNames: Array; + } + + // AccessibilityEventInfo + class EventInfo { + constructor(); + /** + * The type of an accessibility event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + type: EventType; + + /** + * The type of the window change event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + windowUpdateType?: WindowUpdateType; + + /** + * The bundle name of the target application. + * @default - + * @since 3 + * @sysCap Accessibility + */ + bundleName: string; + + /** + * The type of the event source component,such as button, chart. + * @default - + * @since 3 + * @sysCap Accessibility + */ + componentType?: string; + + /** + * The time stamp when send the event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + timeStamp?: number; + + /** + * The window id of the event source. + * @default - + * @since 3 + * @sysCap Accessibility + */ + windowId?: number; + + /** The page id of the event source. + * @default - + * @since 3 + * @sysCap Accessibility + */ + pageId ?: number; + + /** + * The component Id associated with the accessibility event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + componentId?: number; + + /** + * The accessibility event description. + * @default - + * @since 3 + * @sysCap Accessibility + */ + description?: string; + + /** + * The action that triggers the accessibility event, for example, clicking or focusing a view. + * @default - + * @since 3 + * @sysCap Accessibility + */ + triggerAction: Action; + + /** + * The movement step used for reading texts. + * @default - + * @since 3 + * @sysCap Accessibility + */ + textMoveUnit?: TextMoveUnit; + + /** + * The content list. + * @note 旁白朗读Event信息时,会优先朗读description(通常由开发者定义),如果无description信息,则朗读contents. + * @default - + * @since 3 + * @sysCap Accessibility + */ + contents?: Array; + + /** + * The content changed before. + * @default - + * @since 3 + * @sysCap Accessibility + */ + lastContent?: string; + + /** + * The start index of listed items on the screen. + * @default - + * @since 3 + * @sysCap Accessibility + */ + beginIndex?: number; + + /** + * The index of the current item on the screen. + * @default - + * @since 3 + * @sysCap Accessibility + */ + currentIndex?: number; + + /** + * The end index of listed items on the screen. + * @default - + * @since 3 + * @sysCap Accessibility + */ + endIndex?: number; + + /** + * The total of the items. + * @note talkback used it when scroll. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + itemCount?: number; + + /** + * The category type for notificationChanged event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + categoryNotification?: NotificationCategory; + + /** + * Get the nodeinfo who send the event. + * @since 3 + * @sysCap Accessibility + * @return AccessibilityElementInfo. + */ + getSource(callback: AsyncCallback): void; + getSource(): Promise; + } + // AccessibilityElementInfo + interface AccessibilityElementInfo { + /** + * The id of the window which the node in. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly windowId: number; + + /** + * The accessibility id of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly accessibilityId: number; + + /** + * The id of the view which the node in. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly componentId: number; + + /** + * The bundle name. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly bundleName: string; + + /** + * The type of the event source component,such as button, chart. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly componentType: string; + + /** + * The type of the input text. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly inputType: number; + + /** + * The text of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly text: string; + + /** + * The hint text of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly hintText: string; + + /** + * The description of the node. + * @node 朗读控件时用到的信息,通常是控件名称,比如“蓝牙”开关 + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly description: string; + + /** + * The resource name of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly resourceName: string; + + /** + * The list of the children node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly childNodeIds: Array; + + /** + * The operation list of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly operations: Array; + + /** + * The max text length of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly textLengthLimit: number; + + /** + * The rect of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly rect: Rect; + + /** + * Whether the node can be check. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly checkable: boolean; + + /** + * Whether the node is checked. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly checked: boolean; + + /** + * Whether the node can be focused. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly focusable: boolean; + + /** + * Whether the node is focused. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly focused: boolean; + + /** + * Whether the node is visible. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isVisible: boolean; + + /** + * Whether the node is accessibility focused. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly accessibilityFocused: boolean; + + /** + * Whether the node is selected. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly selected: boolean; + + /** + * Whether the node can be click. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly clickable: boolean; + + /** + * Whether the node can be long click. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly longClickable: boolean; + + /** + * Whether the node can be enable. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isEnable: boolean; + + /** + * Whether the node is password. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isPassword: boolean; + + /** + * Whether the node can be scrollable. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly scrollable: boolean; + + /** + * Whether the node can be editable. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly editable: boolean; + + /** + * Whether the node can popup. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly popupSupported: boolean; + + /** + * Whether the node is multiline. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly pluralLineSupported: boolean; + + /** + * Whether the node can be delete. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly deleteable: boolean; + + /** + * Whether the node is displaying hint. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isHint: boolean; + + /** + * Whether the node is important. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isEssential: boolean; + + /** + * current index of children. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly currentIndex: number; + + /** + * start index of children. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly startIndex: number; + + /** + * end index of children. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly endIndex: number; + + /** + * Range info of the progress node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly rangeInfo: RangeInfo; + + /** + * It is used when the node is collection. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly grid: GridInfo; + + /** + * collection item info. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly gridItem: GridItemInfo; + + /** + * The live range of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly activeRegion: number; + + /** + * Whether the content is invalid. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isContentInvalid: boolean; + + /** + * error information. + * @note 控件发生错误,如输入类型不合法,旁白会读出错误信息。 + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly error: string; + + /** + * The label of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly label: number; + + /** + * The start position of text selected. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly beginSelected: number; + + /** + * The end position of text selected. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly endSelected: number; + + /** + * Perform the specified action on the node. + * @since 3 + * @sysCap AccessibilityAbility + * @param action: accessibility action. + * @param args: Key: specify the argument type, such as: OperatorParamType + * Value: The value of arguments for Node + * @return true: success, false: failed. + */ + executeAction(action: Action, callback: AsyncCallback, args?: object): void; + executeAction(action: Action, args?: object): Promise; + + /** + * Find node list information through text. + * @since 3 + * @sysCap AccessibilityAbility + * @param text: Text information to find. + * @return the list of accessibleInfo. + */ + getByContent(text: string, callback: AsyncCallback>): void; + getByContent(text: string): Promise>; + + /** + * Obtains information about the node that gains accessibility focus. + * @since 3 + * @sysCap AccessibilityAbility + * @param focus: focus view. + * @return Node information of focus view conforming to focus type. + */ + get(focus: FocusType, callback: AsyncCallback): void; + get(focus: FocusType): Promise; + + /** + * The information of nodes near focus is retrieved according to the input direction. + * @since 3 + * @sysCap AccessibilityAbility + * @param direction: Direction relative to the current node position. + * @return Node information of focus view conforming to focus type. + */ + next(direction: Direction, callback: AsyncCallback): void; + next(direction: Direction): Promise; + + /** + * Obtains information about the child node at a specified index. + * @since 3 + * @sysCap AccessibilityAbility + * @param index: The child node information of the specified index of the current node. + * @return Node information of focus view conforming to focus type. + */ + getChild(index: number, callback: AsyncCallback): void; + getChild(index: number): Promise; + + /** + * Gets the parent node information of this node. + * @since 3 + * @sysCap AccessibilityAbility + * @param none + * @return Parent node information. + */ + getParent(callback: AsyncCallback): void; + getParent(): Promise; + } + + // Defines an accessibility operation. + interface Operation { + /** + * The type of the operation. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly type: Action; + + /** + * The description of the operation. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly description: string; + } + + interface StateEvent { + /** + * The type of the state event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly eventType: StateEventType; + + /** + * The state of the ability. + * @default false + * @since 3 + * @sysCap Accessibility + */ + readonly state: boolean; + + /** + * The description of the ability. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly description: string; + } + + interface WindowInfo { + /** + * The rect of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly screenRect: Rect; + + /** + * The id of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly id: number; + + /** + * The layer of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly layer: number; + + /** + * The title of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly title: string; + + /** + * The type of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly type: WindowType; + + /** + * The list of the children windows. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly childIds: Array; + + /** + * The parent of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly parentId: number; + + /** + * The accessibility focus of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isAccessibilityFocused: boolean; + + /** + * The status of the window is active or not. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isActive: boolean; + + /** + * The window gained focus or not. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isFocused: boolean; + + /** + * Obtains an anchor accessibility node that anchors this window to another window. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return An anchor accessibility node. + */ + getAnchorElementInfo(callback: AsyncCallback): void; + getAnchorElementInfo(): Promise; + + /** + * Obtains an root accessibility in the active window. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return An anchor accessibility node. + */ + getRootElementInfo(callback: AsyncCallback): void; + getRootElementInfo(): Promise; + + /** + * Obtains an parent AccessibilityWindowInfo instance. + * @since 3 + * @sysCap AccessibilityAbility + * @param options The object of window + * @return The instance of parent Accessibility WindowInfo. + */ + getParent(callback: AsyncCallback): void; + getParent(): Promise; + + /** + * Obtains an child AccessibilityWindowInfo instance. + * @since 3 + * @sysCap AccessibilityAbility + * @param index The index of child window + * @return The instance of Accessibility WindowInfo. + */ + getChild(index: number, callback: AsyncCallback): void; + getChild(index: number): Promise; + } + +} +export default accessibility; \ No newline at end of file diff --git a/interfaces/kits/js/@ohos.accessibility.full.d.ts b/interfaces/kits/js/@ohos.accessibility.full.d.ts new file mode 100644 index 00000000..ab21ed31 --- /dev/null +++ b/interfaces/kits/js/@ohos.accessibility.full.d.ts @@ -0,0 +1,1435 @@ +/* + * Copyright (C) 2021 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 { AsyncCallback, Callback } from 'basic'; +import { AbilityInfo } from 'abilityinfo' +import { KeyEvent } from 'keyevent' +import { Rect } from './@componet/rect' +import { GridInfo, GridItemInfo } from "./@componet/gridInfo" +import { RangeInfo } from "./@componet/progress" +import { GesturePath, GesturePos } from "./@componet/gesturePath" +import { DisplayResizeInfo } from "./@componet/displayResizeInfo" +/** + * Accessibility + * @name Accessibility + * @since 3 + * @sysCap Accessibility + * @devices phone, tablet + * @child NotSupport + * @permission 权限列表 + * @note 标记说明 + */ +declare namespace accessibility { +/************************************************************************************************ + * Type define +***********************************************************************************************/ + /** + * The type of the Ability app. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type AbilityType = 'audible' | 'generic' | 'haptic' | 'spoken' | 'visual'; + + /** + * The action that the ability can execute. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type Action = 'accessibilityFocus' | 'clearAccessibilityFocus' | 'focus' | 'clearFocus' | 'clearSelection' | + 'click' | 'longClick' | 'cut' | 'copy' | 'paste' | 'select' | 'setText' | 'delete' | + 'scrollForward' | 'scrollBackward' | + 'setSelection' | + 'unfold' | 'fold' | 'nextText' | 'previousText' | 'nextHtmlItem' | 'previousHtmlItem'; + + /** + * The type of the accessibility event. + * @note windowsChange:页面变化(迁移)的通知,旁白需要确定新画面的焦点【must】 + * @note windowContentChange:窗口中内容变更通知,旁白朗读屏幕变更的内容(在焦点控件/LiveRegion的情况下)【must】 + * @note windowStateChange:页面变化通知(比如迁移到新页面,弹出Alert画面),用于朗读新页面的title信息,提示用户页面迁移。【must】 + * @note announcement:应用程序发布公告的事件,(A侧)会通知来电的电话号码信息,以及通知栏中的具体控件(如蓝牙快捷键)操作信息。【Must】 + * @note notificationChange:应用程序的通知,比如邮件、短信等通知消息,旁白需要朗读通知中的内容【must】 + * @note textTraversedAtMove:编辑情况下光标移动,会朗读光标移动期间的文本信息【must】 + * @since 3 + * @sysCap Accessibility + */ + type EventType = 'accessibilityFocus' | 'accessibilityFocusClear' | + 'click' | 'longClick' | 'focus' | 'select' | 'hoverEnter' | 'hoverExit' | + 'textUpdate' | 'textSelectionUpdate' | 'scroll' | 'textMoveUnit' | + 'touchBegin' | 'touchEnd' | 'touchGuideBegin' | 'touchGuideEnd' | + 'touchGuideGestureBegin' | 'touchGuideGestureEnd' | + 'windowUpdate' | 'pageContentUpdate' | 'pageStateUpdate' | + 'publicNotice' | 'notificationUpdate'; + + /** + * The change type of the windowsChange event. + * @note It's used when received the {@code windowsChange} event. + * @since 3 + * @sysCap Accessibility + */ + type WindowUpdateType = 'add' | 'remove' | 'title' | 'bounds' | 'layer' | 'active' | + 'focus' | 'accessibilityFocus' | 'parent' | 'children' | 'pip'; + + /** + * The type of the StateEvent. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type StateEventType = 'accessibility' | 'touchGuide'; + + /** + * The type of the window. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type WindowType = 'application' | 'inputMethod' | 'system' | 'accessibilityOverlay' | 'screenDivider'; + + /** + * The type of the focus. + * @note accessibility: accessibility focus; input: input focus; + * @since 3 + * @sysCap Accessibility + */ + type FocusType = 'accessibility' | 'normal'; + + /** + * The type of the ability state. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type AbilityState = 'enable' | 'disable' | 'install'; + + /** + * The direction of the focus move. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type Direction = 'up' | 'down' | 'left' | 'right' | 'forward' | 'backward'; + + /** + * The ability that accessibility subsystem support. + * @note touchExplorer: Describes the capability to talkback. + magnification: Describes the capability to request to control the display magnification. + gesturesSimulation: Describes the capability to request to simulate the gesture. + windowContent: Describes the capability to search for the content of the active window. + filterKeyEvents: Describes the capability to request to filter key events. + fingerprintGesture: Describes the capability to request to fingerprint gesture. + * @since 3 + * @sysCap Accessibility + */ + type Capability = 'retrieve' | 'touchGuide' | 'keyEventObserver' | 'zoom' | 'gesture'; + + /** + * The global action that the ability can execute. + * @note back: Indicates a global action of returning to the previous page. + home: Indicates a global action of returning to the home page. + recents: Indicates a global action of displaying a list of recent tasks. + notifications: Indicates a global action of opening the notification panel. + quickSettings: Indicates a global action of opening quick settings. + powerDialog: Indicates a global action of pressing and holding the power button. + toggleSplitScreen: Indicates a global action of switching between split screens. + lockScreen: Indicates a global action of locking the screen. + takeScreenShot: Indicates a global action of taking a screenshot. + * @since 3 + * @sysCap Accessibility + */ + type GlobalActionType = 'back' | 'home' | 'recent' | 'notification' | 'popUpPowerDialog' | 'divideScreen' + | 'lockScreen' | 'captureScreen'; + + /** + * The types of swipe gestures which are performed on the touch screen. + * And they are also the gesture's interception type. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type GestureType = 'left' | 'leftThenRight' | 'leftThenUp' | 'leftThenDown' | + 'right' | 'rightThenLeft' | 'rightThenUp' | 'rightThenDown' | + 'up' | 'upThenLeft' | 'upThenRight' | 'upThenDown' | + 'down' | 'downThenLeft' | 'downThenRight' | 'downThenUp'; + + /** + * The granularity of text move. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type TextMoveUnit = 'char' | 'word' | 'line' | 'page' | 'paragraph'; + + /** + * The argument type for operation. + * @note - + * @since 3 + * @sysCap Accessibility + */ + type OperatorParamType = 'selectTextBegin' | 'selectTextEnd' | 'htmlItem' | 'setText' | 'textMoveUnit'; + + /** + * The category of the notification + * @note 应用Notification的具体分类,用于朗读通知信息时提示是哪类通知. + * @since 3 + * @sysCap Accessibility + */ + type NotificationCategory = 'call' | 'msg' | 'email' | 'event' | + 'promo' | 'alarm' | 'progress' | 'social' | 'err' | 'transport' | 'sys' | 'service'; + + /** + * The html element type. The arguments of nextHtmlElement/previousHtmlElement + * @note html元素的具体分类,用于实现网页的按类别导航,如“跳到下一个链接或按钮”. + * @since 3 + * @sysCap Accessibility + */ + type HtmlItemType = 'link' | 'control' | 'graphic' | 'listItem' | 'list' | 'table' | + 'combox' | 'heading' | 'button' | 'checkBox' | 'landmark' | 'textField' | 'focusable' | + 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; + + /** + * The key that the ability can intercept. + * @note hide + * @since 3 + * @sysCap Accessibility + */ + type KeyInterceptCode = 'power' | 'volumeUp' | 'volumeDown'; + + /** + * The softkey boad show mode . + * @note hide + * @since 3 + * @sysCap Accessibility + */ + type ShowModeKeyboard = 'auto' | 'hide' | 'ignoreHardKeyboard' | 'hardKeyboardOverridden'; + + /** + * The swipe type of fingerprint gesture. + * @note hide + * @since 3 + * @sysCap Accessibility + */ + type FingerprintGestureType = 'up' | 'donw' | 'left' | 'right'; + + + + /** + * Checks whether accessibility ability is enabled. + * @since 3 + * @sysCap Accessibility + * @param - + * @return Returns {@code true} if the accessibility is enabled; returns {@code false} otherwise. + */ + function isOpenAccessibility(callback: AsyncCallback): void; + function isOpenAccessibility(): Promise; + + /** + * Checks touch browser ability (which is used by talkback) is enabled. + * @since 3 + * @sysCap Accessibility + * @param - + * @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 3 + * @sysCap Accessibility + * @param abilityType The type of the accessibility ability. {@code AbilityType} eg.spoken + * @param stateType The state of the accessibility ability. {@code AbilityState} eg.installed + * @return Returns the list of abilityInfos. + */ + function getAbilityLists(abilityType: AbilityType, stateType: AbilityState, + callback: AsyncCallback>): void; + function getAbilityLists(abilityType: AbilityType, + stateType: AbilityState): Promise>; + + /** + * Send accessibility Event. + * @since 3 + * @sysCap Accessibility + * @param event The object of the accessibility {@code EventInfo} . + * @return Returns {@code true} if successed; returns {@code false} otherwise. + */ + function sendEvent(event: EventInfo, callback: AsyncCallback): void; + function sendEvent(event: EventInfo): Promise; + + /** + * Register the observe of the state changed. + * @since 3 + * @sysCap Accessibility + * @param type state event type + * @return Returns {@code true} if the register is successed; returns {@code false} otherwise. + */ + function on(type: StateEventType, callback: Callback): void; + + /** + * Deregister the observe of the state changed. + * @since 3 + * @sysCap Accessibility + * @param type state event type + * @return Returns {@code true} if the deregister is successed; returns {@code false} otherwise. + */ + function off(type: StateEventType, callback?: Callback): void; + + /** + * Get the ablity client. + * @since 3 + * @sysCap Accessibility + * @return Returns the object of ability. + */ + function getAccessibleAbility(callback: AsyncCallback): void; + function getAccessibleAbility(): Promise; + + /** + * Obtains the suggested interval for switching the UI.e. + * @since 3 + * @note hide + * @sysCap Accessibility + * @param name ability name + * @return Returns the object of ability. + */ + function getSuggestedInterval(timeout: number, contentType: number, callback: AsyncCallback): void; + function getSuggestedInterval(timeout: number, contentType: number): Promise; + + + interface AccessibleAbility { + /** + * Connect to the accessibility subsystem. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return -. + */ + connect(callback: AsyncCallback): void; + connect(): Promise; + + /** + * The controller for display resizing operations. + * @default - + * @note hide + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly displayResizeController: DisplayResizeController; + + /** + * The controller for softkeyboard. + * @default - + * @note hide + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly softKeyBoardController: SoftKeyBoardController; + /** + * The controller for fingerPrint. + * @default - + * @note hide + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly fingerprintController: FingerprintController; + + /** + * Obtains the accessibility node that gains the focus. + * @since 3 + * @sysCap AccessibilityAbility + * @param focusType The type of focus. {@code FocusType} + * @return -. + */ + getFocusElementInfo(focusType: FocusType, callback: AsyncCallback): void; + getFocusElementInfo(focusType: FocusType): Promise; + + /** + * Obtains information about the accessibility root node. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return The root node info. + */ + getRootElementInfo(callback: AsyncCallback): void; + getRootElementInfo(): Promise; + + /** + * Obtains the list of interactive windows on the device, in the layers they are visible to users. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return the list of interactive windows. + */ + getWindows(callback: AsyncCallback>): void; + getWindows(): Promise>; + + /** + * Executes a specified action. + * @since 3 + * @sysCap AccessibilityAbility + * @param action The action wanted to be excused. + * @return The window info. + */ + performCommonAction(action: GlobalActionType, callback: AsyncCallback): void; + performCommonAction(action: GlobalActionType): Promise; + + /** + * Disables the accessibility ability + * @since 3 + * @note hide + * @sysCap Accessibility + * @param name ability name + * @return Returns the object of ability. + */ + disableAbility(callback: AsyncCallback): void; + disableAbility(): Promise; + + /** + * Called when an accessibility event occurs. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return - + */ + on(type: 'accessibilityEvent', callback: Callback): void; + + /** + * Called when a user performs a specified gesture on the device that your accessibility application + has requested to be in touch browser mode. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return - + */ + on(type: 'gesture', callback: Callback): void; + + /** + * Sends customized gestures to the screen. + * @since 3 + * @note hide + * @sysCap AccessibilityAbility + * @param gesturePathDefineList The path of simulation gesture. + * @param listener The result of simulation gesture. + * @return -. + */ + gestureInject(gesturePathDefineList: Array, callback: AsyncCallback): void; + gestureInject(gesturePathDefineList: Array): Promise; + + /** + * Disables the accessibility ability + * @since 3 + * @note hide + * @sysCap Accessibility + * @param name ability name + * @return Returns the object of ability. + */ + disableAbility(callback: AsyncCallback): void; + disableAbility(): Promise; + + /** + * Called when a key event occurs, for example, a user presses the key to increase or decrease the volume. + * @since 3 + * @note hide + * @sysCap AccessibilityAbility + * @param - + * @return - + */ + on(type: 'keyPress', callback: Callback): void; + + /** + * Called when your accessibility service is successfully connected to the OS. You can implement + this method to perform subsequent initialization operations. + * @since 3 + * @note hide + * @sysCap AccessibilityAbility + * @param - + * @return - + */ + on(type: 'AbilityConnected' | 'interrupt', callback: Callback): void; + } + + interface AccessibilityAbilityInfo { + /** + * The ability id. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly id: string; + + /* The ability name. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly name: string; + + /* The bundle name of the ability. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly bundleName: string; + + /** + * The ability info. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly abilityInfo: AbilityInfo; + + /** + * The type of the ability. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly abilityTypes: Array; + + /** + * The capabilities of the ability. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly capabilities: Array; + + /** + * The desciption of the ability. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly description: string; + + /** + * The events which the accesisibility ability wants to observe. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly eventTypes: Array; + + /** + * The applition names which the accessiblity ability wants to observe. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly filterBundleNames: Array; + } + + // AccessibilityEventInfo + class EventInfo { + constructor(); + /** + * The type of an accessibility event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + type: EventType; + + /** + * The type of the window change event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + windowUpdateType?: WindowUpdateType; + + /** + * The bundle name of the target application. + * @default - + * @since 3 + * @sysCap Accessibility + */ + bundleName: string; + + /** + * The type of the event source component,such as button, chart. + * @default - + * @since 3 + * @sysCap Accessibility + */ + componentType?: string; + + /** + * The time stamp when send the event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + timeStamp?: number; + + /** + * The window id of the event source. + * @default - + * @since 3 + * @sysCap Accessibility + */ + windowId?: number; + + /** The page id of the event source. + * @default - + * @since 3 + * @sysCap Accessibility + */ + pageId?: number; + + /** + * The component Id associated with the accessibility event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + componentId?: number; + + /** + * The accessibility event description. + * @default - + * @since 3 + * @sysCap Accessibility + */ + description?: string; + + /** + * The action that triggers the accessibility event, for example, clicking or focusing a view. + * @default - + * @since 3 + * @sysCap Accessibility + */ + triggerAction: Action; + + /** + * The movement step used for reading texts. + * @default - + * @since 3 + * @sysCap Accessibility + */ + textMoveUnit?: TextMoveUnit; + + /** + * The content list. + * @note 旁白朗读Event信息时,会优先朗读description(通常由开发者定义),如果无description信息,则朗读contents. + * @default - + * @since 3 + * @sysCap Accessibility + */ + contents?: Array; + + /** + * The content changed before. + * @default - + * @since 3 + * @sysCap Accessibility + */ + lastContent?: string; + + /** + * The start index of listed items on the screen. + * @default - + * @since 3 + * @sysCap Accessibility + */ + beginIndex?: number; + + /** + * The index of the current item on the screen. + * @default - + * @since 3 + * @sysCap Accessibility + */ + currentIndex?: number; + + /** + * The end index of listed items on the screen. + * @default - + * @since 3 + * @sysCap Accessibility + */ + endIndex?: number; + + /** + * The total of the items. + * @note talkback used it when scroll. + * @default 0 + * @since 3 + * @sysCap Accessibility + */ + itemCount?: number; + + /** + * The category type for notificationChanged event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + categoryNotification?: NotificationCategory; + + /** + * Get the nodeinfo who send the event. + * @since 3 + * @sysCap Accessibility + * @return AccessibilityElementInfo. + */ + getSource(callback: AsyncCallback): void; + getSource(): Promise; + } + // AccessibilityElementInfo + interface AccessibilityElementInfo { + /** + * The id of the window which the node in. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly windowId: number; + + /** + * The accessibility id of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly accessibilityId: number; + + /** + * The id of the view which the node in. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly componentId: number; + + /** + * The bundle name. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly bundleName: string; + + /** + * The type of the event source component,such as button, chart. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly componentType: string; + + /** + * The type of the input text. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly inputType: number; + + /** + * The text of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly text: string; + + /** + * The hint text of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly hintText: string; + + /** + * The description of the node. + * @node 朗读控件时用到的信息,通常是控件名称,比如“蓝牙”开关 + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly description: string; + + /** + * The resource name of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly resourceName: string; + + /** + * The list of the children node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly childNodeIds: Array; + + /** + * The operation list of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly operations: Array; + + /** + * The max text length of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly textLengthLimit: number; + + /** + * The rect of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly rect: Rect; + + /** + * Whether the node can be check. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly checkable: boolean; + + /** + * Whether the node is checked. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly checked: boolean; + + /** + * Whether the node can be focused. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly focusable: boolean; + + /** + * Whether the node is focused. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly focused: boolean; + + /** + * Whether the node is visible. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isVisible: boolean; + + /** + * Whether the node is accessibility focused. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly accessibilityFocused: boolean; + + /** + * Whether the node is selected. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly selected: boolean; + + /** + * Whether the node can be click. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly clickable: boolean; + + /** + * Whether the node can be long click. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly longClickable: boolean; + + /** + * Whether the node can be enable. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isEnable: boolean; + + /** + * Whether the node is password. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isPassword: boolean; + + /** + * Whether the node can be scrollable. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly scrollable: boolean; + + /** + * Whether the node can be editable. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly editable: boolean; + + /** + * Whether the node can popup. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly popupSupported: boolean; + + /** + * Whether the node is multiline. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly pluralLineSupported: boolean; + + /** + * Whether the node can be delete. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly deleteable: boolean; + + /** + * Whether the node is displaying hint. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isHint: boolean; + + /** + * Whether the node is important. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isEssential: boolean; + + /** + * current index of children. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly currentIndex: number; + + /** + * start index of children. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly startIndex: number; + + /** + * end index of children. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly endIndex: number; + + /** + * Range info of the progess node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly rangeInfo: RangeInfo; + + /** + * It is used when the node is collection. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly grid: GridInfo; + + /** + * collection item info. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly gridItem: GridItemInfo; + + /** + * The live range of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly activeRegion: number; + + /** + * Whether the content is invalid. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isContentInvalid: boolean; + + /** + * error information. + * @note 控件发生错误,如输入类型不合法,旁白会读出错误信息。 + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly error: string; + + /** + * The label of the node. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly label: number; + + /** + * The start position of text selected. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly beginSelected: number; + + /** + * The end position of text selected. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly endSelected: number; + + /** + * Perform the specified action on the node. + * @since 3 + * @sysCap AccessibilityAbility + * @param action: accessibility action. + * @param args: Key: specify the argument type, such as: OperatorParamType + * Value: The value of arguments for Node + * @return true: success, false: failed. + */ + executeAction(action: Action, callback: AsyncCallback, args?: object): void; + executeAction(action: Action, args?: object): Promise; + + /** + * Find node list information through text. + * @since 3 + * @sysCap AccessibilityAbility + * @param text: Text information to find. + * @return the list of accessibleInfo. + */ + getByContent(text: string, callback: AsyncCallback>): void; + getByContent(text: string): Promise>; + + /** + * Obtains information about the node that gains accessibility focus. + * @since 3 + * @sysCap AccessibilityAbility + * @param focus: focus view. + * @return Node information of focus view conforming to focus type. + */ + get(focus: FocusType, callback: AsyncCallback): void; + get(focus: FocusType): Promise; + + /** + * The information of nodes near focus is retrieved according to the input direction. + * @since 3 + * @sysCap AccessibilityAbility + * @param direction: Direction relative to the current node position. + * @return Node information of focus view conforming to focus type. + */ + next(direction: Direction, callback: AsyncCallback): void; + next(direction: Direction): Promise; + + /** + * Obtains information about the child node at a specified index. + * @since 3 + * @sysCap AccessibilityAbility + * @param index: The child node information of the specified index of the current node. + * @return Node information of focus view conforming to focus type. + */ + getChild(index: number, callback: AsyncCallback): void; + getChild(index: number): Promise; + + /** + * Gets the parent node information of this node. + * @since 3 + * @sysCap AccessibilityAbility + * @param none + * @return Parent node information. + */ + getParent(callback: AsyncCallback): void; + getParent(): Promise; + } + + // Defines an accessibility operation. + interface Operation { + /** + * The type of the operation. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly type: Action; + + /** + * The description of the operation. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly description: string; + } + + interface StateEvent { + /** + * The type of the state event. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly eventType: StateEventType; + + /** + * The state of the ability. + * @default false + * @since 3 + * @sysCap Accessibility + */ + readonly state: boolean; + + /** + * The description of the ability. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly description: string; + } + + interface WindowInfo { + /** + * The rect of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly screenRect: Rect; + + /** + * The id of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly id: number; + + /** + * The layer of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly layer: number; + + /** + * The title of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly title: string; + + /** + * The type of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly type: WindowType; + + /** + * The list of the children windows. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly childIds: Array; + + /** + * The parent of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly parentId: number; + + /** + * The accessibility focus of the window. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isAccessibilityFocused: boolean; + + /** + * The status of the window is active or not. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isActive: boolean; + + /** + * The window gained focus or not. + * @default - + * @since 3 + * @sysCap Accessibility + */ + readonly isFocused: boolean; + + /** + * Obtains an anchor accessibility node that anchors this window to another window. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return An anchor accessibility node. + */ + getAnchorElementInfo(callback: AsyncCallback): void; + getAnchorElementInfo(): Promise; + + /** + * Obtains an root accessibility in the active window. + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return An anchor accessibility node. + */ + getRootElementInfo(callback: AsyncCallback): void; + getRootElementInfo(): Promise; + + /** + * Obtains an parent AccessibilityWindowInfo instance. + * @since 3 + * @sysCap AccessibilityAbility + * @param options The object of window + * @return The instance of parent Accessibility WindowInfo. + */ + getParent(callback: AsyncCallback): void; + getParent(): Promise; + + /** + * Obtains an child AccessibilityWindowInfo instance. + * @since 3 + * @sysCap AccessibilityAbility + * @param index The index of child window + * @return The instance of Accessibility WindowInfo. + */ + getChild(index: number, callback: AsyncCallback): void; + getChild(index: number): Promise; + } + + //@note hide + interface DisplayResizeController { + /** + * The id of the display. + * @default - + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly displayId: number; + + /** + * Obtains the X coordinate of the center in this display resizing rectangle. + * @devices phone + * @since 3 + * @sysCap AccessibilityAbility + * @return Returns the x coordinate of the resize center. + */ + getCenterX(callback: AsyncCallback): void; + getCenterX(): Promise; + + /** + * Obtains the Y coordinate of the center in this display resizing rectangle. + * @devices phone + * @since 3 + * @sysCap AccessibilityAbility + * @return Returns the y coordinate of the resize center. + */ + getCenterY(callback: AsyncCallback): void; + getCenterY(): Promise; + + /** + * Obtains the display resizing rectangle. + * @devices phone + * @since 3 + * @sysCap AccessibilityAbility + * @return Returns the rectangle of the display. + */ + getDisplayResizeRect(callback: AsyncCallback): void; + getDisplayResizeRect(): Promise; + + /** + * Obtains the resizing scale of this display resizing rectangle. + * @devices phone + * @since 3 + * @sysCap AccessibilityAbility + * @return Returns the scale of the resizing display. + */ + getScale(callback: AsyncCallback): void; + getScale(): Promise; + + /** + * Sets the center coordinates for the display resizing rectangle. + * @devices phone + * @since 3 + * @sysCap AccessibilityAbility + * @param centerX the x coordinate of the resize center + * @param centerY the y coordinate of the resize center + * @param isShouldAnimate set true if need animate + * @return Returns true if the coordinate is successfully set; returns false otherwise. + */ + setCenter(centerX: number, centerY: number, isShouldAnimate: boolean, callback: AsyncCallback): void; + setCenter(centerX: number, centerY: number, isShouldAnimate: boolean): Promise; + + /** + * Sets the display resizing scale. + * @devices phone + * @since 3 + * @sysCap AccessibilityAbility + * @param scale the scale wanted to be set + * @param isShouldAnimate set true if need animate + * @return Returns true if the scale is successfully set; returns false otherwise. + */ + setScale(scale: number, isShouldAnimate: boolean, callback: AsyncCallback): void; + setScale(scale: number, isShouldAnimate: boolean): Promise; + + /** + * Resets the display to its initial size. + * @devices phone + * @since 3 + * @sysCap AccessibilityAbility + * @param isShouldAnimate set true if need animate + * @return Returns true if the display is successfully reset; returns false otherwise. + */ + reset(isShouldAnimate: boolean, callback: AsyncCallback): void; + reset(isShouldAnimate: boolean): Promise; + + /** + * Called when the rectangle, scale, or center coordinate for performing the resizing operations is changed. + * @devices phone + * @since 3 + * @sysCap AccessibilityAbility + * @param - + * @return - + */ + on(type: 'displayResized', callback: Callback): void; + off(type: 'displayResized', callback: Callback): void; + } + + //@note hide + interface SoftKeyBoardController { + /** + * The show mode of the softkeyboard. + * @default auto + * @since 3 + * @sysCap AccessibilityAbility + */ + readonly showMode: ShowModeKeyboard; + + /** + * Called when the show/hide mode of the soft keyboard changes. + * @devices phone + * @since 3 + * @sysCap - + * @param - + * @return - + */ + on(type: 'softKeyBoardShowModeChanged', callback: Callback): void; + off(type: 'softKeyBoardShowModeChanged', callback?: Callback): void; + } + + //@note hide + interface FingerprintController { + /** + * Determine whether the gesture detection function of the fingerprint sensor is available. + * @devices phone + * @since 3 + * @sysCap - + * @param - + * @return Returns true if the fingerprint sensor's gesture detection function is available; + * Otherwise it returns false(for example, if the fingerprint sensor is registering a gesture). + */ + isFingerprintGestureDetectionValid(callback: AsyncCallback): void; + + /** + * Callback when the validity status of the fingerprint sensor's gesture detection changes. + * @devices phone + * @since 3 + * @sysCap - + * @param - + * @return - + */ + on(type: 'fingerprintGestureStatusChanged', callback: Callback): void; + off(type: 'fingerprintGestureStatusChanged', callback?: Callback): void; + + /** + * Callback when the fingerprint sensor detects a gesture. + * @devices phone + * @since 3 + * @sysCap - + * @param - + * @return - + */ + on(type: 'fingerprintGesture', callback: Callback): void; + off(type: 'fingerprintGesture', callback?: Callback): void; + } + +} +export default accessibility; \ No newline at end of file diff --git a/interfaces/kits/js/@ohos.tts.d.ts b/interfaces/kits/js/@ohos.tts.d.ts new file mode 100644 index 00000000..e30141b9 --- /dev/null +++ b/interfaces/kits/js/@ohos.tts.d.ts @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 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. + */ + +declare namespace tts { + + function getInstance(): TtsClient; + + interface TtsClient { + + create(context, ttsListener): void; + + release(): void; //不用实现,有接口就可以 + + init(ttsParams): boolean; //不用实现,有接口就可以,返回true + + setParams(ttsParams):boolean; //不用实现,有接口就可以,返回true + + setAudioType(audioType): boolean; //不用实现,有接口就可以,返回true + + speakText(text, utteranceId): void; + + isSpeaking(): boolean; + + stopSpeak(): void; + + destroy(): void; + } +} + +export default media; \ No newline at end of file diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn new file mode 100644 index 00000000..6637c429 --- /dev/null +++ b/interfaces/kits/napi/BUILD.gn @@ -0,0 +1,123 @@ +# Copyright (c) 2021 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("//build/ohos.gni") + +ohos_shared_library("accessibility") { + #visiblity = [ ":*" ] + + include_dirs = [ + "//foundation/ace/napi/interfaces/kits", + "//third_party/node/src", + "//utils/system/safwk/native/include", + "//base/accessibility/common/log/include", + "//base/accessibility/frameworks/aafwk/include", + "//base/accessibility/interfaces/innerkits/asacfwk/include", + "//base/accessibility/frameworks/aafwk/include", + "//base/accessibility/frameworks/asacfwk/include", + "//base/accessibility/util/include", + "./include", + ] + + defines = [ + "AAMS_LOG_TAG = \"accessibility_napi\"", + "AAMS_LOG_DOMAIN = 0xD005210", + ] + + sources = [ + "./src/native_module.cpp", + "./src/napi_accessible_ability.cpp", + "./src/napi_accessibility_system_ability_client.cpp", + "./src/napi_accessibility_utils.cpp", + "./src/napi_accessible_ability_observer.cpp", + "./src/napi_accessibility_event_info.cpp", + "./src/napi_accessibility_window_info.cpp", + "./src/napi_accessibility_info.cpp", + ] + + configs = [ + "//foundation/aafwk/standard/interfaces/innerkits/base:base_public_config", + ] + + deps = [ + #"//foundation/aafwk/standard/interfaces/innerkits/base:base", + #"//foundation/aafwk/standard/interfaces/innerkits/want:want", + #"//foundation/appexecfwk/standard/common:libappexecfwk_common", + #"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + #"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + #"//foundation/appexecfwk/standard/libs/libeventhandler:libeventhandler_target", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", + #"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + #"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/ace/napi:ace_napi", + "//base/accessibility/frameworks/aafwk:accessibleability", + "//base/accessibility/interfaces/innerkits/asacfwk:accessibilityclient", + "//utils/native/base:utils", + "//foundation/appexecfwk/standard/kits:appkit_native", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "multimodalinput_base:libmmi-client", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "aafwk_standard:want", + "aafwk_standard:ability_manager", + ] + + relative_install_dir = "module" + subsystem_name = "accessibility" + part_name = "accessibility_standard" +} + +ohos_shared_library("tts") { + include_dirs = [ + "//base/accessibility/common/log/include", + "//foundation/ace/napi/interfaces/kits", + "//third_party/node/src", + "./include", + "//base/accessibility/dummyData", + "//utils/native/base/include", + #"//foundation/tts/interfaces/innerkits/native_cpp/framework/include", + ] + + defines = [ + "AAMS_LOG_TAG = \"tts_napi\"", + "AAMS_LOG_DOMAIN = 0xD005299", + ] + + sources = [ + "./src/napi_tts.cpp", + "//base/accessibility/dummyData/ttsDummy.cpp", + ] + + #configs = [ + # "//foundation/aafwk/standard/interfaces/innerkits/base:base_public_config", + #] + + deps = [ + "//foundation/ace/napi:ace_napi", + "//utils/native/base:utils", + #"//foundation/tts/interfaces/innerkits/native_cpp/framework:tts_engine", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + ] + + relative_install_dir = "module" + subsystem_name = "accessibility" + part_name = "accessibility_standard" +} \ No newline at end of file diff --git a/interfaces/kits/napi/include/napi_accessibility_def.h b/interfaces/kits/napi/include/napi_accessibility_def.h new file mode 100644 index 00000000..123a1403 --- /dev/null +++ b/interfaces/kits/napi/include/napi_accessibility_def.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef NAPI_ACCESSIBILITY_DEF_H +#define NAPI_ACCESSIBILITY_DEF_H + +enum AccessibleAbilityObserverFlag: uint32_t { + A11Y_OBSERVER_FLAG_ABILITY_CONNECTED = 0x01, + A11Y_OBSERVER_FLAG_ACCESSIBILITY_EVENT = 0x02, + A11Y_OBSERVER_FLAG_INTERRUPT = 0x04, + A11Y_OBSERVER_FLAG_GESTURE = 0x08, + A11Y_OBSERVER_FLAG_KEY_PRESS = 0x0A, +}; + +#endif // NAPI_ACCESSIBILITY_DEF_H \ No newline at end of file diff --git a/interfaces/kits/napi/include/napi_accessibility_event_info.h b/interfaces/kits/napi/include/napi_accessibility_event_info.h new file mode 100644 index 00000000..c2502dce --- /dev/null +++ b/interfaces/kits/napi/include/napi_accessibility_event_info.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef NAPI_ACCESSIBILITY_EVENT_INFO_H +#define NAPI_ACCESSIBILITY_EVENT_INFO_H + +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "accessibility_event_info.h" +#include "accessibility_element_info.h" + + +struct NAccessibilityEventInfoData { + napi_async_work work_ {}; + napi_deferred deferred_ {}; + napi_ref thisRefer_ {}; + napi_ref callback_ {}; + napi_env env_ {}; + bool result_ = false; + OHOS::Accessibility::AccessibilityEventInfo eventInfo_ {}; + OHOS::Accessibility::AccessibilityElementInfo nodeInfo_ {}; + std::string content_ = ""; + int childIndex_ = 0; +}; + +class NAccessibilityEventInfo { +public: + static void DefineJSAccessibilityEventInfo(napi_env env); + static napi_value JSConstructor(napi_env env, napi_callback_info info); + + static napi_value GetSource(napi_env env, napi_callback_info info); + + static napi_value cons_; +private: + NAccessibilityEventInfo() = default; + ~NAccessibilityEventInfo() = default; +}; + +#endif // NAPI_ACCESSIBILITY_EVENT_INFO_H \ No newline at end of file diff --git a/interfaces/kits/napi/include/napi_accessibility_info.h b/interfaces/kits/napi/include/napi_accessibility_info.h new file mode 100644 index 00000000..836db30f --- /dev/null +++ b/interfaces/kits/napi/include/napi_accessibility_info.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef NAPI_ACCESSIBILITY_INFO_H +#define NAPI_ACCESSIBILITY_INFO_H + +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "accessibility_element_info.h" + +struct NAccessibilityInfoData { + napi_async_work work_ {}; + napi_deferred deferred_ {}; + napi_ref thisRefer_ {}; + napi_ref callback_ {}; + napi_env env_ {}; + bool result_ = false; + OHOS::Accessibility::AccessibilityElementInfo nativeNodeInfo_ = {}; + std::vector nodeInfos_ {}; + OHOS::Accessibility::AccessibilityElementInfo nodeInfo_ {}; + std::string content_ = ""; + int childIndex_ = 0; + std::map actionArguments_; + bool ret_ = false; +}; + +class NElementInfo { +public: + static void DefineJSElementInfo(napi_env env); + static napi_value JSConstructor(napi_env env, napi_callback_info info); + + static napi_value ExecuteAction(napi_env env, napi_callback_info info); + static napi_value GetByContent(napi_env env, napi_callback_info info); + static napi_value GetFocus(napi_env env, napi_callback_info info); + static napi_value GetNext(napi_env env, napi_callback_info info); + static napi_value GetChild(napi_env env, napi_callback_info info); + static napi_value GetParent(napi_env env, napi_callback_info info); + + static napi_value cons_; +private: + NElementInfo() = default; + ~NElementInfo() = default; +}; +#endif // NAPI_ACCESSIBILITY_INFO_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 new file mode 100644 index 00000000..9728945e --- /dev/null +++ b/interfaces/kits/napi/include/napi_accessibility_system_ability_client.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef NAPI_ACCESSIBILITY_SYSTEM_ABILITY_CLIENT_H +#define NAPI_ACCESSIBILITY_SYSTEM_ABILITY_CLIENT_H + +#include +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "accessibility_system_ability_client.h" +#include "accessibility_state_event.h" +#include "accessibility_ability_info.h" + +class StateListener : public OHOS::Accessibility::AccessibilityStateObserver { +public: + StateListener(); + static void NotifyJS(napi_env env, bool enabled, std::string stateType, std::string desc, napi_ref handlerRef); + std::string GetEventType() {return eventType_;} + napi_value StartWork(napi_env env, size_t functionIndex, napi_value *args); + void OnStateChanged(const OHOS::Accessibility::AccessibilityStateEvent& stateEvent) override; + OHOS::Accessibility::AccessibilityStateEventType GetStateType(); + napi_env GetEnv() {return env_;}; + napi_ref GetHandler() {return handlerRef_;} +private: + napi_ref handlerRef_ = nullptr; + napi_env env_ = nullptr; + std::string eventType_ = ""; + std::string description_ = ""; +}; + +struct NAccessibilitySystemAbilityClient { + napi_async_work work_ {}; + napi_deferred deferred_ {}; + napi_ref thisRefer_ {}; + napi_ref callback_ {}; + napi_env env_ {}; + bool enabled_ = false; + bool touchEnabled_ = false; + OHOS::Accessibility::AbilityStateType stateTypes_; + int32_t abilityTypes_ = 0; + std::vector abilityList_ {}; + OHOS::Accessibility::AccessibilityEventInfo eventInfo_ {}; + bool result_ = false; + std::vector> stateListener_ {}; + std::string eventType_ = ""; +}; + +napi_value IsOpenAccessibility(napi_env env, napi_callback_info info); +napi_value IsOpenTouchExploration(napi_env env, napi_callback_info info); +napi_value GetAbilityList(napi_env env, napi_callback_info info); +napi_value SubscribeState(napi_env env, napi_callback_info info); +napi_value UnsubscribeState(napi_env env, napi_callback_info info); +napi_value SendEvent(napi_env env, napi_callback_info info); +#endif // NAPI_ACCESSIBILITY_SYSTEM_ABILITY_CLIENT_H \ No newline at end of file diff --git a/interfaces/kits/napi/include/napi_accessibility_utils.h b/interfaces/kits/napi/include/napi_accessibility_utils.h new file mode 100644 index 00000000..88a57cf2 --- /dev/null +++ b/interfaces/kits/napi/include/napi_accessibility_utils.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef NAPI_ACCESSIBILITY_UTILS_H +#define NAPI_ACCESSIBILITY_UTILS_H + +#include +#include +#include "accessibility_ability_info.h" +#include "accessibility_event_info.h" +#include "accessibility_element_info.h" +#include "accessible_ability.h" +#include "napi_accessibility_system_ability_client.h" +#include "accessibility_window_info.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +constexpr size_t CALLBACK_SIZE = 1; +constexpr size_t ARGS_SIZE_ONE = 1; +constexpr size_t ARGS_SIZE_TWO = 2; +constexpr size_t ARGS_SIZE_THREE = 3; +constexpr size_t ARGS_SIZE_FOUR = 4; +constexpr int32_t DEFAULT_INT32 = 0; +constexpr int32_t PARAM0 = 0; +constexpr int32_t PARAM1 = 1; +constexpr int32_t CODE_SUCCESS = 0; +constexpr int32_t CODE_FAILED = -1; + +std::string GetStringFromNAPI(napi_env env, napi_value value); +bool ParseString(napi_env env, std::string ¶m, napi_value args); +bool ParseUint32(napi_env env, uint32_t ¶m, napi_value args); +napi_value GetErrorValue(napi_env env, int errCode); + + +void ConvertRectToJS(napi_env env, napi_value result, OHOS::Accessibility::Rect& rect); +void ConvertAccessibilityWindowInfoToJS(napi_env env, napi_value result, + OHOS::Accessibility::AccessibilityWindowInfo& accessibilityWindowInfo); +void ConvertAccessibilityWindowInfosToJS(napi_env env, napi_value result, + std::vector& accessibilityWindowInfos); +void ConvertAccessibilityEventInfoToJS(napi_env env, napi_value objEventInfo, + const OHOS::Accessibility::AccessibilityEventInfo &eventInfo); +void ConvertAccessibleAbilityInfoToJS(napi_env env, napi_value result, + OHOS::Accessibility::AccessibilityAbilityInfo& info); +void ConvertAccessibleAbilityInfosToJS(napi_env env, napi_value result, + std::vector& accessibleAbilityInfos); + +void ConvertAbilityInfoToJS(napi_env env, napi_value result, OHOS::AppExecFwk::AbilityInfo& info); + +void ConvertAbilityApplicationInfoToJS(napi_env env, napi_value result, OHOS::AppExecFwk::ApplicationInfo& info); + +void ConvertElementInfoToJS(napi_env env, napi_value result, + OHOS::Accessibility::AccessibilityElementInfo& elementInfo); +void ConvertOperationToJS(napi_env env, napi_value result, OHOS::Accessibility::AccessibleAction& operation); +void ConvertRangeInfoToJS(napi_env env, napi_value nRangeInfo, OHOS::Accessibility::RangeInfo& rangeInfo); +void ConvertGridInfoToJS(napi_env env, napi_value nGrid, OHOS::Accessibility::GridInfo& grid); +void ConvertGridItemToJS(napi_env env, napi_value nGridItem, + OHOS::Accessibility::GridItemInfo& gridItem); +void ConvertEventInfoJSToNAPI(napi_env env, napi_value object, OHOS::Accessibility::AccessibilityEventInfo &eventInfo); +void ConvertElementInfosToJS(napi_env env, napi_value result, + std::vector& elementInfos); +OHOS::Accessibility::ActionType ConvertStringToAccessibleOperationType(std::string type); +OHOS::Accessibility::AccessibilityAbilityTypes ConvertStringToAccessibilityAbilityTypes(std::string type); +OHOS::Accessibility::AbilityStateType ConvertStringToAbilityStateTypes(std::string type); +OHOS::Accessibility::GlobalAction ConvertStringToGlobalAction(std::string type); +void ConvertActionArgsJSToNAPI(napi_env env, napi_value object, std::map &args, OHOS::Accessibility::ActionType action); +std::vector ParseAbilityTypesToVec(uint32_t abilityTypesValue); +std::vector ParseCapabilitiesToVec(uint32_t capabilitiesValue); +std::vector ParseEventTypesToVec(uint32_t eventTypesValue); +#endif // NAPI_ACCESSIBILITY_UTILS_H \ No newline at end of file diff --git a/interfaces/kits/napi/include/napi_accessibility_window_info.h b/interfaces/kits/napi/include/napi_accessibility_window_info.h new file mode 100644 index 00000000..ae33ca01 --- /dev/null +++ b/interfaces/kits/napi/include/napi_accessibility_window_info.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef NAPI_ACCESSIBILITY_WINDOW_H +#define NAPI_ACCESSIBILITY_WINDOW_H + +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "accessibility_window_info.h" +#include "accessibility_element_info.h" + +struct NAccessibilityWindowInfoData { + napi_async_work work_ {}; + napi_deferred deferred_ {}; + napi_ref thisRefer_ {}; + napi_ref callback_ {}; + napi_env env_ {}; + bool result_ = false; + OHOS::Accessibility::AccessibilityWindowInfo nativeWindowInfo_; + OHOS::Accessibility::AccessibilityElementInfo nodeInfo_ {}; + OHOS::Accessibility::AccessibilityWindowInfo window_ {}; + std::string content_ = ""; + int childIndex_ = 0; +}; + +class NAccessibilityWindowInfo { +public: + static void DefineJSAccessibilityWindowInfo(napi_env env); + static napi_value JSConstructor(napi_env env, napi_callback_info info); + + static napi_value GetAnchorElementInfo(napi_env env, napi_callback_info info); + static napi_value GetRootElementInfo(napi_env env, napi_callback_info info); + static napi_value GetParent(napi_env env, napi_callback_info info); + static napi_value GetChild(napi_env env, napi_callback_info info); + + static napi_value cons_; +private: + NAccessibilityWindowInfo() = default; + ~NAccessibilityWindowInfo() = default; +}; +#endif // NAPI_ACCESSIBILITY_WINDOW_H \ No newline at end of file diff --git a/interfaces/kits/napi/include/napi_accessible_ability.h b/interfaces/kits/napi/include/napi_accessible_ability.h new file mode 100644 index 00000000..8144404c --- /dev/null +++ b/interfaces/kits/napi/include/napi_accessible_ability.h @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef NAPI_ACCESSIBLE_ABILITY_H +#define NAPI_ACCESSIBLE_ABILITY_H + +#include +#include + +#include "accessibility_window_info.h" +#include "accessible_ability_listener.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +const std::string STR_A11Y_OBSERVER_ABILITY_CONNECTED = "AbilityConnected"; +const std::string STR_A11Y_OBSERVER_INTERRUPT = "interrupt"; +const std::string STR_A11Y_OBSERVER_ACCESSIBILITY_EVENT = "accessibilityEvent"; +const std::string STR_A11Y_OBSERVER_GESTURE = "gesture"; +const std::string STR_A11Y_OBSERVER_KEY_PRESS = "keyPress"; + +struct AsyncGetAccessibleAbilityCallbackInfo { + napi_env env_; + napi_async_work asyncWork_; + napi_deferred deferred_; + napi_ref callback_ = 0; +}; + +struct AsyncDisableAbilityCallbackInfo { + napi_env env_; + napi_async_work asyncWork_; + napi_deferred deferred_; + napi_ref callback_ = 0; +}; + +struct AsyncGetWindowsCallbackInfo { + napi_env env_; + napi_async_work asyncWork_; + napi_deferred deferred_; + napi_ref callback_ = 0; + std::vector accessibilityWindows_; +}; + +struct AsyncGetRootElementInfoCallbackInfo { +public: + napi_env env_; + napi_async_work asyncWork_; + napi_deferred deferred_; + napi_ref callback_ = 0; + std::optional elementInfo_; + bool result_ = false; +}; + +struct AccessibleAbilityCallbackInfo { + napi_env env_; + // napi_async_work asyncWork_; + // napi_deferred deferred_; + napi_ref callback_ = 0; +}; + +struct AsyncGetFocusElementInfoCallbackInfo { + napi_env env_; + napi_async_work asyncWork_; + napi_deferred deferred_; + napi_ref callback_ = 0; + std::string focusType_ = ""; + std::optional elementInfo_; + bool result_ = false; +}; + +struct AsyncPerformCommonActionCallbackInfo { + napi_env env_; + napi_async_work asyncWork_; + napi_deferred deferred_; + napi_ref callback_ = 0; + uint32_t action_ = 0xFFFFFFFF; + bool performActionResult_ = false; +}; + +void CreateGlobalAccessibleAbilityJSObject(napi_env env); +napi_value AccessibleAbilityConstructor(napi_env env, napi_callback_info info); +napi_value GetAccessibleAbility(napi_env env, napi_callback_info info); + +napi_value RegisterCallback(napi_env env, napi_callback_info info); +napi_value DisableAbility(napi_env env, napi_callback_info info); +napi_value GetWindows(napi_env env, napi_callback_info info); +napi_value GetRootElementInfo(napi_env env, napi_callback_info info); +napi_value GetFocusElementInfo(napi_env env, napi_callback_info info); +napi_value PerformCommonAction(napi_env env, napi_callback_info info); + +// Dummy +napi_value ConnectToAAMS(napi_env env, napi_callback_info info); +#endif // NAPI_ACCESSIBLE_ABILITY_H \ No newline at end of file diff --git a/interfaces/kits/napi/include/napi_accessible_ability_observer.h b/interfaces/kits/napi/include/napi_accessible_ability_observer.h new file mode 100644 index 00000000..96a5057b --- /dev/null +++ b/interfaces/kits/napi/include/napi_accessible_ability_observer.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef NAPI_ACCESSIBLE_ABILITY_OBSERVER_H +#define NAPI_ACCESSIBLE_ABILITY_OBSERVER_H + +#include "accessible_ability_listener.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +class AccessibleAbilityObserver: public OHOS::Accessibility::AccessibleAbilityListener { +public: + AccessibleAbilityObserver() = default; + ~AccessibleAbilityObserver() = default; + + void OnAccessibilityEvent(const OHOS::Accessibility::AccessibilityEventInfo& eventInfo) override; + void OnInterrupt() override; + void OnAbilityConnected() override; + void OnGesture(uint32_t gestureId) override; + bool OnKeyPressEvent(const OHOS::MMI::KeyEvent& keyEvent) override; +}; +#endif // NAPI_ACCESSIBLE_ABILITY_OBSERVER_H \ No newline at end of file diff --git a/interfaces/kits/napi/include/napi_tts.h b/interfaces/kits/napi/include/napi_tts.h new file mode 100644 index 00000000..09676c72 --- /dev/null +++ b/interfaces/kits/napi/include/napi_tts.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef NAPI_TTS_H +#define NAPI_TTS_H + +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "ttsDummy.h" +// #include "tts_engine.h" + +namespace OHOS { +class TtsObserver : public TtsFwk::TtsListener { +public: + TtsObserver() = default; + ~TtsObserver() = default; + + void OnEvent(int eventType) override; + void OnSpeechStart(int utteranceId) override; + void OnSpeechProgress(int utteranceId, int progress) override; + void OnSpeechFinish(int utteranceId) override; +}; + +class NTTSClient { +public: + static napi_value Create(napi_env env, napi_callback_info info); + static napi_value Release(napi_env env, napi_callback_info info); + static napi_value InitTTS(napi_env env, napi_callback_info info); + static napi_value SetParams(napi_env env, napi_callback_info info); + static napi_value SetAudioType(napi_env env, napi_callback_info info); + static napi_value SpeakText(napi_env env, napi_callback_info info); + static napi_value StopSpeak(napi_env env, napi_callback_info info); + static napi_value Destroy(napi_env env, napi_callback_info info); + + static napi_value ttsClientCons_; + static napi_env env_; + static napi_ref onEventRef_; + static napi_ref onSpeechFinishedRef_; + static sptr listener_; +}; +}// namespace OHOS + + +#endif // NAPI_TTS_H \ No newline at end of file diff --git a/interfaces/kits/napi/src/napi_accessibility_event_info.cpp b/interfaces/kits/napi/src/napi_accessibility_event_info.cpp new file mode 100644 index 00000000..833b0f7b --- /dev/null +++ b/interfaces/kits/napi/src/napi_accessibility_event_info.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include +#include +#include + +#include "accessibility_event_info.h" + +#include "hilog_wrapper.h" +#include "napi_accessibility_def.h" +#include "napi_accessibility_utils.h" +#include "napi_accessibility_window_info.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "napi_accessibility_event_info.h" +#include "napi_accessibility_info.h" + +using namespace OHOS; +using namespace OHOS::Accessibility; + +napi_value NAccessibilityEventInfo::cons_ = nullptr; + +void NAccessibilityEventInfo::DefineJSAccessibilityEventInfo(napi_env env) { + napi_property_descriptor descForAccessibilityEventInfo[] = { + DECLARE_NAPI_FUNCTION("getSource", NAccessibilityEventInfo::GetSource), + }; + + NAPI_CALL_RETURN_VOID(env, + napi_define_class(env, + "EventInfo", + NAPI_AUTO_LENGTH, + NAccessibilityEventInfo::JSConstructor, + nullptr, + sizeof(descForAccessibilityEventInfo) / sizeof(descForAccessibilityEventInfo[0]), + descForAccessibilityEventInfo, + &NAccessibilityEventInfo::cons_)); +} + +napi_value NAccessibilityEventInfo::JSConstructor(napi_env env, napi_callback_info info) { + napi_value jsthis = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr)); + return jsthis; +} + +napi_value NAccessibilityEventInfo::GetSource(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + size_t argc = ARGS_SIZE_ONE; + napi_value argv[ARGS_SIZE_ONE] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityEventInfo* eventInfo = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + HILOG_DEBUG("argc = %{public}d", (int)argc); + + status = napi_unwrap(env, thisVar, (void**)&eventInfo); + HILOG_DEBUG("napi_unwrap status: %{public}d", (int)status); + if (!eventInfo) { + HILOG_DEBUG("eventInfo is null!!"); + } + + NAccessibilityEventInfoData *callbackInfo = new NAccessibilityEventInfoData(); + callbackInfo->eventInfo_ = *eventInfo; + + napi_value promise = nullptr; + if (argc > 0) { + HILOG_DEBUG("GetSource callback mode"); + napi_create_reference(env, argv[PARAM0], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_DEBUG("GetSource promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetSource", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilityEventInfoData *callbackInfo = (NAccessibilityEventInfoData*)data; + AccessibilityEventInfo eventInfo = callbackInfo->eventInfo_; + callbackInfo->result_ = eventInfo.GetSource(callbackInfo->nodeInfo_); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + HILOG_DEBUG("GetSource execute back"); + NAccessibilityEventInfoData* callbackInfo = (NAccessibilityEventInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + napi_new_instance(env, NElementInfo::cons_, 0, nullptr, &argv[PARAM1]); + ConvertElementInfoToJS(env, argv[PARAM1], callbackInfo->nodeInfo_); + + argv[PARAM0] = GetErrorValue(env, callbackInfo->result_ ? CODE_SUCCESS : CODE_FAILED); + if (callbackInfo->callback_) { + // Callback mode + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + if (callbackInfo->result_) { + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, argv[PARAM0]); + } + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} \ No newline at end of file diff --git a/interfaces/kits/napi/src/napi_accessibility_info.cpp b/interfaces/kits/napi/src/napi_accessibility_info.cpp new file mode 100644 index 00000000..8e17d696 --- /dev/null +++ b/interfaces/kits/napi/src/napi_accessibility_info.cpp @@ -0,0 +1,551 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "hilog_wrapper.h" +#include "napi_accessibility_info.h" +#include "napi_accessibility_utils.h" + +using namespace OHOS; +using namespace OHOS::Accessibility; + +napi_value NElementInfo::cons_ = nullptr; + +void NElementInfo::DefineJSElementInfo(napi_env env) { + napi_property_descriptor descForElementInfo[] = { + DECLARE_NAPI_FUNCTION("executeAction", NElementInfo::ExecuteAction), + DECLARE_NAPI_FUNCTION("getByContent", NElementInfo::GetByContent), + DECLARE_NAPI_FUNCTION("get", NElementInfo::GetFocus), + DECLARE_NAPI_FUNCTION("next", NElementInfo::GetNext), + DECLARE_NAPI_FUNCTION("getChild", NElementInfo::GetChild), + DECLARE_NAPI_FUNCTION("getParent", NElementInfo::GetParent), + }; + + NAPI_CALL_RETURN_VOID(env, + napi_define_class(env, + "AccessibilityElementInfo", + NAPI_AUTO_LENGTH, + NElementInfo::JSConstructor, + nullptr, + sizeof(descForElementInfo) / sizeof(descForElementInfo[0]), + descForElementInfo, + &NElementInfo::cons_)); +} + +napi_value NElementInfo::JSConstructor(napi_env env, napi_callback_info info) { + napi_value jsthis = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr)); + return jsthis; +} + +napi_value NElementInfo::ExecuteAction(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + size_t argc = ARGS_SIZE_THREE; + napi_value argv[ARGS_SIZE_THREE] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityElementInfo* nodeInfo = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + std::string action; + ParseString(env, action, argv[PARAM0]); + HILOG_DEBUG("argc = %{public}d", (int)argc); + HILOG_INFO("action = %{public}s", action.c_str()); + status = napi_unwrap(env, thisVar, (void**)&nodeInfo); + if (!nodeInfo) { + HILOG_ERROR("nodeInfo is null!!"); + } + NAccessibilityInfoData *callbackInfo = new NAccessibilityInfoData(); + ConvertActionArgsJSToNAPI(env, argv[ARGS_SIZE_TWO], callbackInfo->actionArguments_, + ConvertStringToAccessibleOperationType(action)); + callbackInfo->nativeNodeInfo_ = *nodeInfo; + callbackInfo->content_ = action; + napi_value promise = nullptr; + + //Parse function + napi_valuetype valueType = napi_undefined; + if (argc >= ARGS_SIZE_TWO) { + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valueType)); + } + if (valueType == napi_function) { + HILOG_ERROR("ExecuteAction callback mode"); + napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_ERROR("ExecuteAction promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "ExecuteAction", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { + NAccessibilityInfoData *callbackInfo = (NAccessibilityInfoData*)data; + ActionType action = ConvertStringToAccessibleOperationType(callbackInfo->content_); + AccessibilityElementInfo nodeInfo = callbackInfo->nativeNodeInfo_; + callbackInfo->result_ = nodeInfo.ExecuteAction(action, callbackInfo->actionArguments_); + }, + [](napi_env env, napi_status status, void* data) { + HILOG_DEBUG("ExecuteAction execute back"); + NAccessibilityInfoData* callbackInfo = (NAccessibilityInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + napi_get_boolean(env, callbackInfo->result_, &argv[PARAM1]); + HILOG_DEBUG("callbackInfo->result_[%{public}d]", callbackInfo->result_); + + if (callbackInfo->callback_) { + // Callback mode + argv[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} + +napi_value NElementInfo::GetByContent(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s start", __func__); + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityElementInfo* nodeInfo = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + std::string content; + ParseString(env, content, argv[PARAM0]); + HILOG_DEBUG("argc = %{public}d", (int)argc); + HILOG_INFO("content[%{public}s]", content.c_str()); + + status = napi_unwrap(env, thisVar, (void**)&nodeInfo); + if (!nodeInfo) { + HILOG_ERROR("nodeInfo is null!!"); + } + + NAccessibilityInfoData *callbackInfo = new NAccessibilityInfoData(); + callbackInfo->nativeNodeInfo_ = *nodeInfo; + callbackInfo->content_ = content; + napi_value promise = nullptr; + if (argc > ARGS_SIZE_ONE) { + HILOG_ERROR("callback mode"); + napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_ERROR("promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetByContent", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilityInfoData *callbackInfo = (NAccessibilityInfoData*)data; + AccessibilityElementInfo nodeInfo = callbackInfo->nativeNodeInfo_; + callbackInfo->ret_ = nodeInfo.GetByContent(callbackInfo->content_, callbackInfo->nodeInfos_); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + HILOG_DEBUG("execute back"); + NAccessibilityInfoData* callbackInfo = (NAccessibilityInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + napi_create_array(env, &argv[PARAM1]); + ConvertElementInfosToJS(env, argv[PARAM1], callbackInfo->nodeInfos_); + + + argv[PARAM0] = GetErrorValue(env, callbackInfo->ret_ ? CODE_SUCCESS : CODE_FAILED); + if (callbackInfo->callback_) { + // Callback mode + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + if (callbackInfo->ret_) { + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, argv[PARAM0]); + } + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} + +napi_value NElementInfo::GetFocus(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityElementInfo* nodeInfo = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + std::string focusType; + ParseString(env, focusType, argv[PARAM0]); + HILOG_DEBUG("argc = %{public}d", (int)argc); + HILOG_INFO("focusType[%{public}s]", focusType.c_str()); + + status = napi_unwrap(env, thisVar, (void**)&nodeInfo); + if (!nodeInfo) { + HILOG_ERROR("nodeInfo is null!!"); + } + + NAccessibilityInfoData *callbackInfo = new NAccessibilityInfoData(); + callbackInfo->nativeNodeInfo_ = *nodeInfo; + callbackInfo->content_ = focusType; + napi_value promise = nullptr; + if (argc > ARGS_SIZE_ONE) { + HILOG_DEBUG("callback mode"); + napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_DEBUG("promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetFocus", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { + NAccessibilityInfoData *callbackInfo = (NAccessibilityInfoData*)data; + int focus = 0; + if (std::strcmp(callbackInfo->content_.c_str(), "accessibility") == 0) { + focus = FOCUS_TYPE_ACCESSIBILITY; + } else if (std::strcmp(callbackInfo->content_.c_str(), "normal") == 0) { + focus = FOCUS_TYPE_INPUT; + } else { + focus = FOCUS_TYPE_INVALID; + } + AccessibilityElementInfo nodeInfo = callbackInfo->nativeNodeInfo_; + callbackInfo->ret_ = nodeInfo.GetFocus(focus, callbackInfo->nodeInfo_); + }, + [](napi_env env, napi_status status, void* data) { + HILOG_DEBUG("execute back"); + NAccessibilityInfoData* callbackInfo = (NAccessibilityInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + napi_new_instance(env, NElementInfo::cons_, 0, nullptr, &argv[PARAM1]); + ConvertElementInfoToJS(env, argv[PARAM1], callbackInfo->nodeInfo_); + + argv[PARAM0] = GetErrorValue(env, callbackInfo->ret_ ? CODE_SUCCESS : CODE_FAILED); + if (callbackInfo->callback_) { + // Callback mode + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + if (callbackInfo->ret_) { + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, argv[PARAM0]); + } + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} + +static FocusMoveDirection CovertStringToDirection(std::string str) { + static const std::map focusMoveDirectionTable = { + {"up", FocusMoveDirection::UP}, + {"down", FocusMoveDirection::DOWN}, + {"left", FocusMoveDirection::LEFT}, + {"right", FocusMoveDirection::RIGHT}, + {"forward", FocusMoveDirection::FORWARD}, + {"backward", FocusMoveDirection::BACKWARD} + }; + + if (focusMoveDirectionTable.find(str) == focusMoveDirectionTable.end()) { + return FocusMoveDirection::DIRECTION_INVALID; + } + + return focusMoveDirectionTable.at(str); +} + +napi_value NElementInfo::GetNext(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityElementInfo* nodeInfo = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + std::string direction; + ParseString(env, direction, argv[PARAM0]); + HILOG_DEBUG("argc = %{public}d", (int)argc); + HILOG_INFO("direction[%{public}s]", direction.c_str()); + + status = napi_unwrap(env, thisVar, (void**)&nodeInfo); + if (!nodeInfo) { + HILOG_ERROR("nodeInfo is null!!"); + } + + NAccessibilityInfoData *callbackInfo = new NAccessibilityInfoData(); + callbackInfo->nativeNodeInfo_ = *nodeInfo; + callbackInfo->content_ = direction; + napi_value promise = nullptr; + if (argc > ARGS_SIZE_ONE) { + HILOG_DEBUG("GetNext callback mode"); + napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_DEBUG("GetNext promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetNext", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilityInfoData *callbackInfo = (NAccessibilityInfoData*)data; + AccessibilityElementInfo nodeInfo = callbackInfo->nativeNodeInfo_; + callbackInfo->ret_ = nodeInfo.GetNext(CovertStringToDirection(callbackInfo->content_), + callbackInfo->nodeInfo_); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + HILOG_DEBUG("GetNext execute back"); + NAccessibilityInfoData* callbackInfo = (NAccessibilityInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + napi_new_instance(env, NElementInfo::cons_, 0, nullptr, &argv[PARAM1]); + ConvertElementInfoToJS(env, argv[PARAM1], callbackInfo->nodeInfo_); + + argv[PARAM0] = GetErrorValue(env, callbackInfo->ret_ ? CODE_SUCCESS : CODE_FAILED); + if (callbackInfo->callback_) { + // Callback mode + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + if (callbackInfo->ret_) { + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, argv[PARAM0]); + } + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} + +napi_value NElementInfo::GetChild(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityElementInfo* nodeInfo = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + HILOG_DEBUG("argc = %{public}d", (int)argc); + int childIndex; + napi_get_value_int32(env, argv[PARAM0], &childIndex); + HILOG_INFO("childIndex[%{public}d]", childIndex); + + status = napi_unwrap(env, thisVar, (void**)&nodeInfo); + if (!nodeInfo) { + HILOG_ERROR("nodeInfo is null!!"); + } + + NAccessibilityInfoData *callbackInfo = new NAccessibilityInfoData(); + callbackInfo->nativeNodeInfo_ = *nodeInfo; + callbackInfo->childIndex_ = childIndex; + napi_value promise = nullptr; + if (argc > ARGS_SIZE_ONE) { + HILOG_DEBUG("GetChild callback mode"); + napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_DEBUG("GetChild promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetChild", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilityInfoData *callbackInfo = (NAccessibilityInfoData*)data; + AccessibilityElementInfo nodeInfo = callbackInfo->nativeNodeInfo_; + callbackInfo->ret_ = nodeInfo.GetChild(callbackInfo->childIndex_, callbackInfo->nodeInfo_); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + HILOG_DEBUG("GetChild execute back"); + NAccessibilityInfoData* callbackInfo = (NAccessibilityInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + napi_new_instance(env, NElementInfo::cons_, 0, nullptr, &argv[PARAM1]); + ConvertElementInfoToJS(env, argv[PARAM1], callbackInfo->nodeInfo_); + + argv[PARAM0] = GetErrorValue(env, callbackInfo->ret_ ? CODE_SUCCESS : CODE_FAILED); + if (callbackInfo->callback_) { + // Callback mode + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + if (callbackInfo->ret_) { + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, argv[PARAM0]); + } + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} + +napi_value NElementInfo::GetParent(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + size_t argc = ARGS_SIZE_ONE; + napi_value argv[ARGS_SIZE_ONE] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityElementInfo* nodeInfo = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + HILOG_DEBUG("argc = %{public}d", (int)argc); + + status = napi_unwrap(env, thisVar, (void**)&nodeInfo); + if (!nodeInfo) { + HILOG_ERROR("nodeInfo is null!!"); + } + + NAccessibilityInfoData *callbackInfo = new NAccessibilityInfoData(); + callbackInfo->nativeNodeInfo_ = *nodeInfo; + + napi_value promise = nullptr; + if (argc > 0) { + HILOG_DEBUG("GetParent callback mode"); + napi_create_reference(env, argv[PARAM0], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_DEBUG("GetParent promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetParent", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilityInfoData *callbackInfo = (NAccessibilityInfoData*)data; + AccessibilityElementInfo nodeInfo = callbackInfo->nativeNodeInfo_; + callbackInfo->ret_ = nodeInfo.GetParent(callbackInfo->nodeInfo_); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + HILOG_DEBUG("GetParent execute back"); + NAccessibilityInfoData* callbackInfo = (NAccessibilityInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + napi_new_instance(env, NElementInfo::cons_, 0, nullptr, &argv[PARAM1]); + ConvertElementInfoToJS(env, argv[PARAM1], callbackInfo->nodeInfo_); + + argv[PARAM0] = GetErrorValue(env, callbackInfo->ret_ ? CODE_SUCCESS : CODE_FAILED); + if (callbackInfo->callback_) { + // Callback mode + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + if (callbackInfo->ret_) { + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, argv[PARAM0]); + } + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} \ No newline at end of file diff --git a/interfaces/kits/napi/src/napi_accessibility_system_ability_client.cpp b/interfaces/kits/napi/src/napi_accessibility_system_ability_client.cpp new file mode 100644 index 00000000..a0711044 --- /dev/null +++ b/interfaces/kits/napi/src/napi_accessibility_system_ability_client.cpp @@ -0,0 +1,435 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "napi_accessibility_system_ability_client.h" +#include "hilog_wrapper.h" +#include "napi_accessibility_utils.h" +#include "accessibility_state_event.h" + +using namespace OHOS; +using namespace OHOS::Accessibility; + +std::vector> g_states; +napi_value IsOpenAccessibility(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s start", __func__); + size_t argc = ARGS_SIZE_ONE; + napi_value argv; + napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr); + + napi_value promise = nullptr; + NAccessibilitySystemAbilityClient *callbackInfo = new NAccessibilitySystemAbilityClient(); + if (argc > 0) { + HILOG_DEBUG("IsOpenAccessibility callback mode"); + napi_create_reference(env, argv, 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_DEBUG("IsOpenAccessibility promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "IsOpenAccessibility", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilitySystemAbilityClient *callbackInfo = (NAccessibilitySystemAbilityClient*)data; + callbackInfo->enabled_ = AccessibilitySystemAbilityClient::GetInstance()->IsEnabled(); + HILOG_INFO("IsOpenAccessibility Executing enabled[%{public}d]", callbackInfo->enabled_); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + NAccessibilitySystemAbilityClient *callbackInfo = (NAccessibilitySystemAbilityClient*)data; + napi_value result[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, callbackInfo->enabled_, &result[PARAM1])); + HILOG_INFO("IsOpenAccessibility completed enabled[%{public}d]", callbackInfo->enabled_); + + if (callbackInfo->callback_) { + result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_value return_val; + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &return_val); + napi_delete_reference(env, callbackInfo->callback_); + } else { + napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + } + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + return promise; +} + +napi_value IsOpenTouchExploration(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s start", __func__); + size_t argc = ARGS_SIZE_ONE; + napi_value argv; + napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr); + + napi_value promise = nullptr; + NAccessibilitySystemAbilityClient *callbackInfo = new NAccessibilitySystemAbilityClient(); + if (argc > 0) { + HILOG_DEBUG("IsOpenTouchExploration callback mode"); + napi_create_reference(env, argv, 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_DEBUG("IsOpenTouchExploration promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "IsOpenTouchExploration", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilitySystemAbilityClient *callbackInfo = (NAccessibilitySystemAbilityClient*)data; + callbackInfo->enabled_ = AccessibilitySystemAbilityClient::GetInstance()->IsEnabled(); + HILOG_INFO("IsOpenTouchExploration Executing touchEnabled[%{public}d]", callbackInfo->touchEnabled_); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + NAccessibilitySystemAbilityClient *callbackInfo = (NAccessibilitySystemAbilityClient*)data; + napi_value result[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, callbackInfo->enabled_, &result[PARAM1])); + HILOG_INFO("IsOpenTouchExploration completed touchEnabled_[%{public}d]", callbackInfo->touchEnabled_); + + if (callbackInfo->callback_) { + result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_value return_val; + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &return_val); + napi_delete_reference(env, callbackInfo->callback_); + } else { + napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + } + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + return promise; +} + +napi_value GetAbilityList(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s start", __func__); + size_t argc = 3; + napi_value parameters[3] = {0}; + napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); + + std::string abilityTypes = GetStringFromNAPI(env, parameters[0]); + std::string stateTypes = GetStringFromNAPI(env, parameters[1]);; + + HILOG_INFO("abilityTypes[%{public}s]", abilityTypes.c_str()); + HILOG_INFO("stateTypes[%{public}s]", stateTypes.c_str()); + + NAccessibilitySystemAbilityClient *callbackInfo = new NAccessibilitySystemAbilityClient(); + callbackInfo->abilityTypes_ = ConvertStringToAccessibilityAbilityTypes(abilityTypes); + callbackInfo->stateTypes_ = ConvertStringToAbilityStateTypes(stateTypes); + + napi_value promise = nullptr; + + if (argc > ARGS_SIZE_TWO) { + HILOG_DEBUG("GetAbilityList callback mode"); + napi_create_reference(env, parameters[2], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_DEBUG("GetAbilityList promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetAbilityList", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilitySystemAbilityClient *callbackInfo = (NAccessibilitySystemAbilityClient*)data; + callbackInfo->abilityList_ = AccessibilitySystemAbilityClient::GetInstance()->GetAbilityList( + int(callbackInfo->abilityTypes_), + callbackInfo->stateTypes_); + HILOG_INFO("GetAbilityList Executing GetAbilityList[%{public}d]", callbackInfo->abilityList_.size()); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + NAccessibilitySystemAbilityClient *callbackInfo = (NAccessibilitySystemAbilityClient*)data; + napi_value result[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + napi_create_array(env, &result[PARAM1]); + HILOG_INFO("GetAbilityList ENTER ConvertAccessibleAbilityInfosToJS"); + ConvertAccessibleAbilityInfosToJS(env, result[PARAM1], callbackInfo->abilityList_); + if (callbackInfo->callback_) { + result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_value return_val; + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &return_val); + napi_delete_reference(env, callbackInfo->callback_); + } else { + napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + } + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + return promise; +} + +napi_value SendEvent(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s start", __func__); + size_t argc = ARGS_SIZE_TWO; + napi_value parameters[ARGS_SIZE_TWO] = {0}; + napi_get_cb_info(env, info, &argc, parameters, nullptr, nullptr); + + NAccessibilitySystemAbilityClient *callbackInfo = new NAccessibilitySystemAbilityClient(); + ConvertEventInfoJSToNAPI(env, parameters[0], callbackInfo->eventInfo_); + napi_value promise = nullptr; + + if (argc > ARGS_SIZE_ONE) { + HILOG_DEBUG("SendEvent callback mode"); + napi_create_reference(env, parameters[1], 1, &callbackInfo->callback_); + } else { + HILOG_DEBUG("SendEvent promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "SendEvent", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { + NAccessibilitySystemAbilityClient *callbackInfo = (NAccessibilitySystemAbilityClient*)data; + callbackInfo->result_ = AccessibilitySystemAbilityClient::GetInstance()->SendEvent( + callbackInfo->eventInfo_); + HILOG_INFO("SendEvent result[%{public}d]", callbackInfo->result_); + }, + [](napi_env env, napi_status status, void* data) { + NAccessibilitySystemAbilityClient *callbackInfo = (NAccessibilitySystemAbilityClient*)data; + napi_value result[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, callbackInfo->result_, &result[PARAM1])); + if (callbackInfo->callback_) { + result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_value return_val; + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &return_val); + napi_delete_reference(env, callbackInfo->callback_); + } else { + napi_resolve_deferred(env, callbackInfo->deferred_, result[PARAM1]); + } + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} + +napi_value SubscribeState(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s start", __func__); + 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); + NAPI_ASSERT(env, status == napi_ok, "Failed to get event type"); + + std::shared_ptr stateListener = std::make_shared(); + stateListener->StartWork(env, 1, args); + g_states.push_back(stateListener); + std::string eventType = GetStringFromNAPI(env, args[0]); + AccessibilityStateEventType type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; + if (std::strcmp(eventType.c_str(), "accessibility") == 0) { + type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; + } else if (std::strcmp(eventType.c_str(), "touchExplorer") == 0) { + type = AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED; + } else { + HILOG_ERROR("SubscribeState eventType[%{public}s] is error", eventType.c_str()); + } + bool result = AccessibilitySystemAbilityClient::GetInstance()->SubscribeStateObserver(stateListener, type); + napi_value ret = {0}; + napi_get_boolean(env, result, &ret); + return ret; +} + +napi_value UnsubscribeState(napi_env env, napi_callback_info info) +{ + HILOG_INFO("%{public}s start observer size%{public}d", __func__, g_states.size()); + bool result = false; + 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); + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + //NAPI_ASSERT(env, status == napi_ok, "Failed to get event type"); + std::string eventType = GetStringFromNAPI(env, args[0]); + + if (argc > ARGS_SIZE_ONE) { + HILOG_DEBUG("UnsubscribeState callback mode %{public}d", g_states.size()); + NAccessibilitySystemAbilityClient *callbackInfo = new NAccessibilitySystemAbilityClient(); + napi_create_reference(env, args[1], 1, &callbackInfo->callback_); + napi_value resource = nullptr; + napi_create_string_utf8(env, "off", NAPI_AUTO_LENGTH, &resource); + callbackInfo->eventType_ = eventType; + callbackInfo->stateListener_ = g_states; + //async to sync start + AccessibilityStateEventType type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; + std::string eventType = callbackInfo->eventType_ ; + if (std::strcmp(eventType.c_str(), "accessibility") == 0) { + type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; + } else if (std::strcmp(eventType.c_str(), "touchExplorer") == 0) { + type = AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED; + } else { + HILOG_ERROR("SubscribeState eventType[%{public}s] is error", eventType.c_str()); + } + int i = 0; + HILOG_INFO("%{public}s *******observer size%{public}d*******", __func__, g_states.size()); + for (auto observer : g_states) { + if (observer->GetEnv() == env && strcmp(observer->GetEventType().c_str(), eventType.c_str()) == 0) { + callbackInfo->result_ = AccessibilitySystemAbilityClient::GetInstance()->UnsubscribeStateObserver(observer, type); + HILOG_INFO("%{public}s ***********i%{public}d*********", __func__, i); + g_states.erase(g_states.begin() + i); + HILOG_INFO("%{public}s unregister result%{public}d", __func__, callbackInfo->result_); + break; + } + i++; + } + napi_value result[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + napi_get_boolean(env, callbackInfo->result_, &result[PARAM1]); + // NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, callbackInfo->result_, &result[PARAM1])); + if (callbackInfo->callback_) { + result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_value return_val; + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &return_val); + napi_delete_reference(env, callbackInfo->callback_); + } else { + HILOG_ERROR("SubscribeState end eventType[%{public}s] is error", callbackInfo->eventType_.c_str()); + } + //async to sync end + } else { + AccessibilityStateEventType type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; + if (std::strcmp(eventType.c_str(), "accessibility") == 0) { + type = AccessibilityStateEventType::EVENT_ACCESSIBILITY_STATE_CHANGED; + } else if (std::strcmp(eventType.c_str(), "touchExplorer") == 0) { + type = AccessibilityStateEventType::EVENT_TOUCH_GUIDE_STATE_CHANGED; + } else { + HILOG_ERROR("SubscribeState eventType[%{public}s] is error", eventType.c_str()); + } + int i = 0; + for (auto observer : g_states) { + if (observer->GetEnv() == env && strcmp(observer->GetEventType().c_str(), eventType.c_str()) == 0) { + result = AccessibilitySystemAbilityClient::GetInstance()->UnsubscribeStateObserver(observer, type); + g_states.erase(g_states.begin() + i); + break; + } + i++; + } + } + napi_value ret = 0; + napi_get_boolean(env, result, &ret); + return ret; +} + +StateListener::StateListener() +{ + +} + +AccessibilityStateEventType StateListener::GetStateType() +{ + HILOG_INFO("%{public}s" , __func__); + AccessibilityStateEventType type = EVENT_ACCESSIBILITY_STATE_CHANGED; + if (std::strcmp(eventType_.c_str(), "accessibility") == 0) { + type = EVENT_ACCESSIBILITY_STATE_CHANGED; + } else if (std::strcmp(eventType_.c_str(), "touchExplorer") == 0) { + type = EVENT_TOUCH_GUIDE_STATE_CHANGED; + } else { + HILOG_ERROR("SubscribeState eventType[%s] is error", eventType_.c_str()); + } + return type; +} + +napi_value StateListener::StartWork(napi_env env, size_t functionIndex, napi_value *args) +{ + HILOG_INFO("%{public}s" , __func__); + eventType_ = GetStringFromNAPI(env, args[0]); + napi_create_reference(env, args[functionIndex], 1, &handlerRef_); + env_ = env; + napi_value result = {0}; + return result; +} + +void StateListener::NotifyJS(napi_env env, bool enabled, std::string stateType, std::string desc, napi_ref handlerRef) +{ + HILOG_INFO("%{public}s" , __func__); + napi_value jsEvent; + napi_create_object(env, &jsEvent); + + napi_value eventType; + napi_create_string_utf8(env, stateType.c_str(), NAPI_AUTO_LENGTH, &eventType); + napi_set_named_property(env, jsEvent, "eventType", eventType); + + napi_value state; + napi_get_boolean(env, enabled, &state); + napi_set_named_property(env, jsEvent, "state", state); + + napi_value description; + napi_create_string_utf8(env, desc.c_str(), NAPI_AUTO_LENGTH, &description); + napi_set_named_property(env, jsEvent, "description", description); + + napi_value handler = nullptr; + napi_value callResult; + napi_get_reference_value(env, handlerRef, &handler); + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + napi_call_function(env, undefined, handler, 1, &jsEvent, &callResult); + int32_t result; + napi_get_value_int32(env, callResult, &result); + HILOG_INFO("NotifyJS napi_call_function result[%{public}d]", result); +} + +void StateListener::OnStateChanged(const OHOS::Accessibility::AccessibilityStateEvent& stateEvent) +{ + HILOG_INFO("%{public}s" , __func__); + for (auto observer : g_states) { + if (observer->GetStateType() == stateEvent.GetEventType()) { + if (stateEvent.GetEventResult()) { + observer->NotifyJS(observer->GetEnv(), true, observer->GetEventType(), + stateEvent.GetEventMsg(), observer->GetHandler()); + } else { + observer->NotifyJS(observer->GetEnv(), false, observer->GetEventType(), + stateEvent.GetEventMsg(), observer->GetHandler()); + } + } + } +} \ No newline at end of file diff --git a/interfaces/kits/napi/src/napi_accessibility_utils.cpp b/interfaces/kits/napi/src/napi_accessibility_utils.cpp new file mode 100644 index 00000000..1a7b8f83 --- /dev/null +++ b/interfaces/kits/napi/src/napi_accessibility_utils.cpp @@ -0,0 +1,1722 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include "hilog_wrapper.h" +#include "napi_accessibility_event_info.h" +#include "napi_accessibility_info.h" +#include "napi_accessibility_utils.h" +#include "napi_accessibility_window_info.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "napi_accessible_ability.h" + +using namespace OHOS; +using namespace OHOS::Accessibility; + +std::string GetStringFromNAPI(napi_env env, napi_value value) { + std::string result; + size_t size = 0; + + if (napi_get_value_string_utf8(env, value, nullptr, 0, &size) != napi_ok) { + HILOG_ERROR("can not get string size"); + return ""; + } + result.reserve(size + 1); + result.resize(size); + if (napi_get_value_string_utf8(env, value, result.data(), (size + 1), &size) != napi_ok) { + HILOG_ERROR("can not get string value"); + return ""; + } + return result; +} + +bool ParseString(napi_env env, std::string ¶m, napi_value args) { + napi_status status; + napi_valuetype valuetype; + status = napi_typeof(env, args, &valuetype); + if (status != napi_ok) { + HILOG_INFO("napi_typeof error and status is %{public}d", status); + return false; + } + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + param = GetStringFromNAPI(env, args); + HILOG_INFO("param=%{public}s.", param.c_str()); + return true; +} + +bool ParseUint32(napi_env env, uint32_t ¶m, napi_value args) +{ + napi_status status; + napi_valuetype valuetype; + status = napi_typeof(env, args, &valuetype); + if (status != napi_ok) { + HILOG_INFO("napi_typeof error and status is %{public}d", status); + return false; + } + HILOG_INFO("param=%{public}d.", valuetype); + NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. uint32 expected."); + napi_get_value_uint32(env, args, ¶m); + return true; +} + +napi_value GetErrorValue(napi_env env, int 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)); + return result; +} + +/********************************************************** + * Convert native object to js object + *********************************************************/ +void ConvertRectToJS(napi_env env, napi_value result, Accessibility::Rect& rect) { + napi_value nLeftTopX; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, rect.GetLeftTopXScreenPostion(), &nLeftTopX)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "leftTopX", nLeftTopX)); + + napi_value nLeftTopY; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, rect.GetLeftTopYScreenPostion(), &nLeftTopY)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "leftTopY", nLeftTopY)); + + napi_value nRightBottomX; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, rect.GetRightBottomXScreenPostion(), &nRightBottomX)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "rightBottomX", nRightBottomX)); + + napi_value nRightBottomY; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, rect.GetRightBottomYScreenPostion(), &nRightBottomY)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "rightBottomY", nRightBottomY)); +} + +static std::string ConvertWindowTypeToString(WindowType type) { + static const std::map windowTypeTable = { + {WindowType::TYPE_ACCESSIBILITY_OVERLAY, "accessibilityOverlay"}, + {WindowType::TYPE_APPLICATION, "application"}, + {WindowType::TYPE_INPUT_METHOD, "inputMethod"}, + {WindowType::TYPE_SPLIT_SCREEN_DIVIDER, "screenDivider"}, + {WindowType::TYPE_SYSTEM, "system"} + }; + + if (windowTypeTable.find(type) == windowTypeTable.end()) { + return ""; + } + + return windowTypeTable.at(type); +} + +void ConvertAccessibleAbilityInfoToJS(napi_env env, napi_value result, AccessibilityAbilityInfo& info) +{ + napi_value nId; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.GetId().c_str(), NAPI_AUTO_LENGTH, &nId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "id", nId)); + + napi_value nName; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.GetName().c_str(), NAPI_AUTO_LENGTH, &nName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "name", nName)); + + napi_value nBundleName; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.GetPackageName().c_str(), NAPI_AUTO_LENGTH, &nBundleName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "bundleName", nBundleName)); + + napi_value ability; + napi_create_object(env, &ability); + OHOS::AppExecFwk::AbilityInfo abilityInfo = info.GetAbilityInfo(); + ConvertAbilityInfoToJS(env, ability, abilityInfo); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "abilityInfo", ability)); + + napi_value nAbilityType; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &nAbilityType)); + uint32_t abilityTypesValue = info.GetAccessibilityAbilityType(); + std::vector abilityTypes = ParseAbilityTypesToVec(abilityTypesValue); + for (size_t idx = 0; idx < abilityTypes.size(); idx++) { + napi_value nType; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, abilityTypes[idx].c_str(), NAPI_AUTO_LENGTH, &nType)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, nAbilityType, idx, nType)); + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "abilityTypes", nAbilityType)); + + napi_value nCapabilities; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &nCapabilities)); + uint32_t capabilitiesValue = info.GetCapabilityValues(); + std::vector capabilities = ParseCapabilitiesToVec(capabilitiesValue); + for (size_t idx = 0; idx < capabilities.size(); idx++) { + napi_value nType; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, capabilities[idx].c_str(), NAPI_AUTO_LENGTH, &nType)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, nCapabilities, idx, nType)); + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "capabilities", nCapabilities)); + + napi_value description; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.GetDescription().c_str(), NAPI_AUTO_LENGTH, &description)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "description", description)); + + napi_value nEventTypes; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &nEventTypes)); + uint32_t eventTypesValue = info.GetEventTypes(); + std::vector eventTypes = ParseEventTypesToVec(eventTypesValue); + for (size_t idx = 0; idx < eventTypes.size(); idx++) { + napi_value nType; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, eventTypes[idx].c_str(), NAPI_AUTO_LENGTH, &nType)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, nEventTypes, idx, nType)); + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "eventTypes", nEventTypes)); + + // napi_value fingerprintGestureInterception; + // NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, info.GetFingerprintGestureInterception(), + // &fingerprintGestureInterception)); + // NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "fingerprintGestureInterception", + // fingerprintGestureInterception)); + + // napi_value keyEventInterception; + // NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, info.GetKeyEventType(), &keyEventInterception)); + // NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "keyEventInterception", keyEventInterception)); + + // napi_value uiInteractiveTime; + // NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, info.GetUiInteractiveTime(), &uiInteractiveTime)); + // NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "uiInteractiveTime", uiInteractiveTime)); + + // napi_value uiNoninteractiveTime; + // NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, info.GetUiNoninteractiveTime(), &uiNoninteractiveTime)); + // NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "uiNoninteractiveTime", uiNoninteractiveTime)); + + napi_value filterBundleNames; + size_t idx = 0; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &filterBundleNames)); + std::vector strFilterBundleNames = info.GetFilterBundleNames(); + for (auto filterBundleName : strFilterBundleNames) { + napi_value bundleName; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, filterBundleName.c_str(), NAPI_AUTO_LENGTH, &bundleName)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, filterBundleNames, idx, bundleName)); + idx++; + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "filterBundleNames", filterBundleNames)); +} + +void ConvertAbilityApplicationInfoToJS(napi_env env, napi_value result, OHOS::AppExecFwk::ApplicationInfo& info) +{ + napi_value name; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.name.c_str(), NAPI_AUTO_LENGTH, &name)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "name", name)); + + napi_value bundleName; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.bundleName.c_str(), NAPI_AUTO_LENGTH, &bundleName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "bundleName", bundleName)); + + napi_value description; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.description.c_str(), NAPI_AUTO_LENGTH, &description)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "description", description)); + + napi_value iconPath; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.iconPath.c_str(), NAPI_AUTO_LENGTH, &iconPath)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "iconPath", iconPath)); + + napi_value label; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.label.c_str(), NAPI_AUTO_LENGTH, &label)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "label", label)); + + napi_value labelId; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, int32_t(info.labelId), &labelId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "labelId", labelId)); + + napi_value iconId; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, int32_t(info.iconId), &iconId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "iconId", iconId)); + + napi_value descriptionId; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, int32_t(info.descriptionId), &descriptionId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "descriptionId", descriptionId)); + + napi_value deviceId; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.deviceId.c_str(), NAPI_AUTO_LENGTH, &deviceId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "deviceId", deviceId)); + + napi_value signatureKey; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.signatureKey.c_str(), NAPI_AUTO_LENGTH, &signatureKey)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "signatureKey", signatureKey)); + + napi_value isSystemApp; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, info.isSystemApp, &isSystemApp)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "systemApp", isSystemApp)); + + napi_value isLauncherApp; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, info.isLauncherApp, &isLauncherApp)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isLauncherApp", isLauncherApp)); + + napi_value supportedModes; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, int32_t(info.supportedModes), &supportedModes)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "supportedModes", supportedModes)); + + napi_value process; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.process.c_str(), NAPI_AUTO_LENGTH, &process)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "process", process)); + + napi_value permissions; + size_t idx = 0; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &permissions)); + for (auto permission : info.permissions) { + napi_value per; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, permission.c_str(), NAPI_AUTO_LENGTH, &per)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, permissions, idx, per)); + idx++; + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "permissions", permissions)); + + napi_value moduleSourceDirs; + idx = 0; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &moduleSourceDirs)); + for (auto moduleSourceDir : info.moduleSourceDirs) { + napi_value moduleSource; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, moduleSourceDir.c_str(), NAPI_AUTO_LENGTH, &moduleSource)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, moduleSourceDirs, idx, moduleSource)); + idx++; + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "moduleSourceDirs", moduleSourceDirs)); + + napi_value moduleInfos; + idx = 0; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &moduleInfos)); + for (auto moduleInfo : info.moduleInfos) { + napi_value module = 0; + napi_value moduleName; + napi_value moduleSourceDir; + napi_create_object(env, &module); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, moduleInfo.moduleName.c_str(), NAPI_AUTO_LENGTH, &moduleName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, module, "moduleName", moduleName)); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, moduleInfo.moduleSourceDir.c_str(), NAPI_AUTO_LENGTH, &moduleSourceDir)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, module, "moduleSourceDir", moduleSourceDir)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, moduleInfos, idx, module)); + idx++; + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "moduleInfos", moduleInfos)); + + napi_value entryDir; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.entryDir.c_str(), NAPI_AUTO_LENGTH, &entryDir)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "entryDir", entryDir)); + + napi_value codePath; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.codePath.c_str(), NAPI_AUTO_LENGTH, &codePath)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "codePath", codePath)); + + napi_value dataDir; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.dataDir.c_str(), NAPI_AUTO_LENGTH, &dataDir)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "dataDir", dataDir)); + + napi_value dataBaseDir; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.dataBaseDir.c_str(), NAPI_AUTO_LENGTH, &dataBaseDir)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "dataBaseDir", dataBaseDir)); + + napi_value cacheDir; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.cacheDir.c_str(), NAPI_AUTO_LENGTH, &cacheDir)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "cacheDir", cacheDir)); + + napi_value flags; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, int32_t(info.flags), &flags)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "flags", flags)); + + napi_value enabled; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, info.enabled, &enabled)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "enabled", enabled)); +} + +void ConvertAbilityInfoToJS(napi_env env, napi_value result, OHOS::AppExecFwk::AbilityInfo& info) +{ + napi_value name; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.name.c_str(), NAPI_AUTO_LENGTH, &name)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "name", name)); + + napi_value label; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.label.c_str(), NAPI_AUTO_LENGTH, &label)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "label", label)); + + napi_value description; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.description.c_str(), NAPI_AUTO_LENGTH, &description)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "description", description)); + + napi_value iconPath; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.iconPath.c_str(), NAPI_AUTO_LENGTH, &iconPath)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "iconPath", iconPath)); + + napi_value visible; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, info.visible, &visible)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "visible", visible)); + + napi_value kind; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.kind.c_str(), NAPI_AUTO_LENGTH, &kind)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "kind", kind)); + + napi_value type; + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, uint32_t(info.type), &type)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "type", type)); + + napi_value orientation; + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, uint32_t(info.orientation), &orientation)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "orientation", orientation)); + + napi_value launchMode; + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, uint32_t(info.launchMode), &launchMode)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "launchMode", launchMode)); + + napi_value permissions; + size_t idx = 0; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &permissions)); + for (auto permission : info.permissions) { + napi_value per; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, permission.c_str(), NAPI_AUTO_LENGTH, &per)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, permissions, idx, per)); + idx++; + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "permissions", permissions)); + + napi_value process; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.process.c_str(), NAPI_AUTO_LENGTH, &process)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "process", process)); + + napi_value deviceTypes; + idx = 0; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &deviceTypes)); + for (auto deviceType : info.deviceTypes) { + napi_value device; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, deviceType.c_str(), NAPI_AUTO_LENGTH, &device)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, deviceTypes, idx, device)); + idx++; + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "deviceTypes", deviceTypes)); + + napi_value deviceCapabilities; + idx = 0; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &deviceCapabilities)); + for (auto deviceCap : info.deviceCapabilities) { + napi_value cap; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, deviceCap.c_str(), NAPI_AUTO_LENGTH, &cap)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, deviceCapabilities, idx, cap)); + idx++; + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "deviceCapabilities", deviceCapabilities)); + + napi_value uri; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.uri.c_str(), NAPI_AUTO_LENGTH, &uri)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "uri", uri)); + + napi_value targetAbility; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.targetAbility.c_str(), NAPI_AUTO_LENGTH, &targetAbility)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "targetAbility", targetAbility)); + + napi_value applicationInfo = 0; + napi_create_object(env, &applicationInfo); + ConvertAbilityApplicationInfoToJS(env, applicationInfo, info.applicationInfo); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "applicationInfo", applicationInfo)); + + napi_value isLauncherAbility; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, info.isLauncherAbility, &isLauncherAbility)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isLauncherAbility", isLauncherAbility)); + + napi_value isNativeAbility; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, info.isNativeAbility, &isNativeAbility)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isNativeAbility", isNativeAbility)); + + napi_value enabled; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, info.enabled, &enabled)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "enabled", enabled)); + + napi_value package; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.package.c_str(), NAPI_AUTO_LENGTH, &package)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "package", package)); + + napi_value bundleName; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.bundleName.c_str(), NAPI_AUTO_LENGTH, &bundleName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "bundleName", bundleName)); + + napi_value moduleName; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.moduleName.c_str(), NAPI_AUTO_LENGTH, &moduleName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "moduleName", moduleName)); + + napi_value applicationName; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.applicationName.c_str(), NAPI_AUTO_LENGTH, &applicationName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "applicationName", applicationName)); + + napi_value deviceId; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.deviceId.c_str(), NAPI_AUTO_LENGTH, &deviceId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "deviceId", deviceId)); + + napi_value codePath; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.codePath.c_str(), NAPI_AUTO_LENGTH, &codePath)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "codePath", codePath)); + + napi_value resourcePath; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.resourcePath.c_str(), NAPI_AUTO_LENGTH, &resourcePath)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "resourcePath", resourcePath)); + + napi_value libPath; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, info.libPath.c_str(), NAPI_AUTO_LENGTH, &libPath)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "libPath", libPath)); + +} + +void ConvertAccessibilityWindowInfoToJS(napi_env env, napi_value result, AccessibilityWindowInfo& accessibilityWindowInfo) { + napi_value nRect; + NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &nRect)); + Accessibility::Rect rect = accessibilityWindowInfo.GetRectInScreen(); + ConvertRectToJS(env, nRect, rect); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "screenRect", nRect)); + + napi_value nId; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, accessibilityWindowInfo.GetWindowId(), &nId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "id", nId)); + + napi_value nLayer; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, accessibilityWindowInfo.GetWindowLayer(), &nLayer)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "layer", nLayer)); + + napi_value nTitle; + std::string strTitle = accessibilityWindowInfo.GetWindowTitle(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strTitle.c_str(), NAPI_AUTO_LENGTH, &nTitle)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "title", nTitle)); + + napi_value nWindowType; + WindowType windowType = accessibilityWindowInfo.GetWindowType(); + std::string strWindowType = ConvertWindowTypeToString(windowType); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strWindowType.c_str(), NAPI_AUTO_LENGTH, &nWindowType)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "type", nWindowType)); + + napi_value nChildIds; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &nChildIds)); + std::vector childIds = accessibilityWindowInfo.GetChildIds(); + for (auto childId : childIds) { + size_t idx = 0; + napi_value nChildId; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, childId, &nChildId)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, nChildIds, idx, nChildId)); + idx++; + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "childIds", nChildIds)); + + napi_value nParentId; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, accessibilityWindowInfo.GetParentId(), &nParentId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "parentId", nParentId)); + + napi_value nAccessibilityFocused; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, + accessibilityWindowInfo.IsAccessibilityFocused(), &nAccessibilityFocused)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isAccessibilityFocused", nAccessibilityFocused)); + + napi_value nIsActive; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, + accessibilityWindowInfo.IsActive(), &nIsActive)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isActive", nIsActive)); + + napi_value nIsFocused; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, + accessibilityWindowInfo.IsFocused(), &nIsFocused)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isFocused", nIsFocused)); + + // Bind js object to a Native object + AccessibilityWindowInfo* pAccessibilityWindowInfo = new AccessibilityWindowInfo(); + *pAccessibilityWindowInfo = accessibilityWindowInfo; + napi_status sts = napi_wrap(env, result, pAccessibilityWindowInfo, + [](napi_env env, void* data, void* hint) { + AccessibilityWindowInfo* info = (AccessibilityWindowInfo*)data; + delete info; + }, + nullptr, nullptr); + HILOG_DEBUG("napi_wrap status: %{public}d", (int)sts); +} + +void ConvertAccessibilityWindowInfosToJS(napi_env env, napi_value result, + std::vector& accessibilityWindowInfos) { + size_t idx = 0; + + if (accessibilityWindowInfos.empty()) { + return; + } + + for (auto& windowInfo : accessibilityWindowInfos) { + napi_value obj = nullptr; + napi_new_instance(env, NAccessibilityWindowInfo::cons_, 0, nullptr, &obj); + ConvertAccessibilityWindowInfoToJS(env, obj, windowInfo); + napi_set_element(env, result, idx, obj); + idx++; + } +} + +void ConvertAccessibleAbilityInfosToJS(napi_env env, napi_value result, + std::vector& accessibleAbilityInfos) +{ + size_t index = 0; + + if (accessibleAbilityInfos.empty()) { + return; + } + + for (auto& abilityInfo : accessibleAbilityInfos) { + napi_value obj = nullptr; + napi_create_object(env, &obj); + ConvertAccessibleAbilityInfoToJS(env, obj, abilityInfo); + napi_set_element(env, result, index, obj); + index++; + } +} + +static const std::string ConvertAccessibilityEventTypeToString(EventType type) { + static const std::map a11yEvtTypeTable = { + {EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT, "accessibilityFocus"}, + {EventType::TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED_EVENT, "accessibilityFocusClear"}, + {EventType::TYPE_VIEW_CLICKED_EVENT, "click"}, + {EventType::TYPE_VIEW_LONG_CLICKED_EVENT, "longClick"}, + {EventType::TYPE_VIEW_FOCUSED_EVENT, "focus"}, + {EventType::TYPE_VIEW_SELECTED_EVENT, "select"}, + {EventType::TYPE_VIEW_SCROLLED_EVENT, "scroll"}, + {EventType::TYPE_VIEW_HOVER_ENTER_EVENT, "hoverEnter"}, + {EventType::TYPE_VIEW_HOVER_EXIT_EVENT, "hoverExit"}, + {EventType::TYPE_VIEW_TEXT_UPDATE_EVENT, "textUpdate"}, + {EventType::TYPE_VIEW_TEXT_SELECTION_UPDATE_EVENT, "textSelectionUpdate"}, + {EventType::TYPE_VIEW_TEXT_MOVE_UNIT_EVENT, "textMoveUnit"}, + {EventType::TYPE_WINDOW_UPDATE, "windowUpdate"}, + {EventType::TYPE_PAGE_CONTENT_UPDATE, "pageContentUpdate"}, + {EventType::TYPE_PAGE_STATE_UPDATE, "pageStateUpdate"}, + {EventType::TYPE_TOUCH_BEGIN, "touchBegin"}, + {EventType::TYPE_TOUCH_END, "touchEnd"}, + {EventType::TYPE_TOUCH_GUIDE_BEGIN, "touchGuideBegin"}, + {EventType::TYPE_TOUCH_GUIDE_END, "touchGuideEnd"}, + {EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN, "touchGuideGestureBegin"}, + {EventType::TYPE_TOUCH_GUIDE_GESTURE_END, "touchGuideGestureEnd"}, + {EventType::TYPE_PUBLIC_NOTICE_EVENT, "publicNotice"}, + {EventType::TYPE_NOTIFICATION_UPDATE_EVENT, "notificationUpdate"}, + // {EventType::TYPE_VIEW_CONTEXT_CLICKED_EVENT, ""} + }; + + if (a11yEvtTypeTable.find(type) == a11yEvtTypeTable.end()) { + return ""; + } + + return a11yEvtTypeTable.at(type); +} + +static const std::string ConvertWindowUpdateTypeToString(WindowUpdateType type) { + static const std::map WindowUpdateTypeTable = { + {WindowUpdateType::WINDOW_UPDATE_ACCESSIBILITY_FOCUSED, "accessibilityFocus"}, + {WindowUpdateType::WINDOW_UPDATE_FOCUSED, "focus"}, + {WindowUpdateType::WINDOW_UPDATE_ACTIVE, "active"}, + {WindowUpdateType::WINDOW_UPDATE_ADDED, "add"}, + {WindowUpdateType::WINDOW_UPDATE_REMOVED, "remove"}, + {WindowUpdateType::WINDOW_UPDATE_BOUNDS, "bounds"}, + {WindowUpdateType::WINDOW_UPDATE_TITLE, "title"}, + {WindowUpdateType::WINDOW_UPDATE_LAYER, "layer"}, + {WindowUpdateType::WINDOW_UPDATE_PARENT, "parent"}, + {WindowUpdateType::WINDOW_UPDATE_CHILDREN, "children"}, + {WindowUpdateType::WINDOW_UPDATE_PIP, "pip"} + }; + + if (WindowUpdateTypeTable.find(type) == WindowUpdateTypeTable.end()) { + return ""; + } + + return WindowUpdateTypeTable.at(type); +} + +static const std::string ConvertOperationTypeToString(ActionType type) { + static const std::map triggerActionTable = { + {ActionType::ACCESSIBILITY_ACTION_FOCUS, "focus"}, + {ActionType::ACCESSIBILITY_ACTION_CLEAR_FOCUS, "clearFocus"}, + {ActionType::ACCESSIBILITY_ACTION_SELECT, "select"}, + {ActionType::ACCESSIBILITY_ACTION_CLEAR_SELECTION, "clearSelection"}, + {ActionType::ACCESSIBILITY_ACTION_CLICK, "click"}, + {ActionType::ACCESSIBILITY_ACTION_LONG_CLICK, "longClick"}, + {ActionType::ACCESSIBILITY_ACTION_ACCESSIBILITY_FOCUS, "accessibilityFocus"}, + {ActionType::ACCESSIBILITY_ACTION_CLEAR_ACCESSIBILITY_FOCUS, "clearAccessibilityFocus"}, + {ActionType::ACCESSIBILITY_ACTION_SCROLL_FORWARD, "scrollForward"}, + {ActionType::ACCESSIBILITY_ACTION_SCROLL_BACKWARD, "scrollBackward"}, + {ActionType::ACCESSIBILITY_ACTION_COPY, "copy"}, + {ActionType::ACCESSIBILITY_ACTION_PASTE, "paste"}, + {ActionType::ACCESSIBILITY_ACTION_CUT, "cut"}, + {ActionType::ACCESSIBILITY_ACTION_SET_SELECTION, "setSelection"}, + {ActionType::ACCESSIBILITY_ACTION_SET_TEXT, "setText"}, + {ActionType::ACCESSIBILITY_ACTION_NEXT_TEXT, "nextText"}, + {ActionType::ACCESSIBILITY_ACTION_PREVIOUS_TEXT, "previousText"}, + {ActionType::ACCESSIBILITY_ACTION_UNFOLD, "unfold"}, + {ActionType::ACCESSIBILITY_ACTION_FOLD, "fold"}, + {ActionType::ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, "nextHtmlItem"}, + {ActionType::ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, "previousHtmlItem"}, + {ActionType::ACCESSIBILITY_ACTION_DELETED, "delete"}, + }; + + if (triggerActionTable.find(type) == triggerActionTable.end()) { + return ""; + } + + return triggerActionTable.at(type); +} + +static const std::string CovertTextMoveStepToString(TextMoveUnit step) { + static const std::map textMoveStepTable = { + {TextMoveUnit::STEP_CHARACTER, "char"}, + {TextMoveUnit::STEP_WORD, "word"}, + {TextMoveUnit::STEP_LINE, "line"}, + {TextMoveUnit::STEP_PAGE, "page"}, + {TextMoveUnit::STEP_PARAGRAPH, "paragraph"} + }; + + if (textMoveStepTable.find(step) == textMoveStepTable.end()) { + return ""; + } + + return textMoveStepTable.at(step); +} + +static const std::string ConvertCategoryNotificationToString(NotificationCategory category) { + static const std::map categoryTable = { + {NotificationCategory::CATEGORY_CALL, "call"}, + {NotificationCategory::CATEGORY_MSG, "msg"}, + {NotificationCategory::CATEGORY_EMAIL, "email"}, + {NotificationCategory::CATEGORY_EVENT, "event"}, + {NotificationCategory::CATEGORY_PROMO, "promo"}, + {NotificationCategory::CATEGORY_ALARM, "alarm"}, + {NotificationCategory::CATEGORY_PROGRESS, "progress"}, + {NotificationCategory::CATEGORY_SOCIAL, "social"}, + {NotificationCategory::CATEGORY_ERR, "err"}, + {NotificationCategory::CATEGORY_TRANSPORT, "transport"}, + {NotificationCategory::CATEGORY_SYS, "sys"}, + {NotificationCategory::CATEGORY_SERVICE, "service"}, + {NotificationCategory::CATEGORY_OTHERS, ""}, + }; + + if (categoryTable.find(category) == categoryTable.end()) { + return ""; + } + + return categoryTable.at(category); +} + +void ConvertAccessibilityEventInfoToJS(napi_env env,napi_value objEventInfo, const AccessibilityEventInfo &eventInfo) { + + napi_value nType; + EventType type = eventInfo.GetEventType(); + std::string strType = ConvertAccessibilityEventTypeToString(type); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strType.c_str(), NAPI_AUTO_LENGTH, &nType)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "type", nType)); + HILOG_DEBUG("%{public}s: type[%{public}s]", __func__, strType.c_str()); + + napi_value nWindowUpdateType; + WindowUpdateType windowUpdateType = eventInfo.GetWindowChangeTypes(); + std::string strWindowUpdateType = ConvertWindowUpdateTypeToString(windowUpdateType); + NAPI_CALL_RETURN_VOID(env, + napi_create_string_utf8(env, strWindowUpdateType.c_str(), NAPI_AUTO_LENGTH, &nWindowUpdateType)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "windowUpdateType", nWindowUpdateType)); + HILOG_DEBUG("%{public}s: windowUpdateType[%{public}s]", __func__, strWindowUpdateType.c_str()); + + napi_value nBundleName; + std::string bundleName = eventInfo.GetBundleName(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, bundleName.c_str(), NAPI_AUTO_LENGTH, &nBundleName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "bundleName", nBundleName)); + + napi_value nComponentType; + std::string componentType = eventInfo.GetComponentType(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, componentType.c_str(), NAPI_AUTO_LENGTH, &nComponentType)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "componentType", nComponentType)); + HILOG_DEBUG("%{public}s: componentType[%{public}s]", __func__, componentType.c_str()); + + napi_value nTimeStamp; + int64_t timeStamp = eventInfo.GetTimeStamp(); + NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, timeStamp, &nTimeStamp)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "timeStamp", nTimeStamp)); + + napi_value nWindowId; + int windowId = eventInfo.GetWindowId(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, windowId, &nWindowId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "windowId", nWindowId)); + HILOG_DEBUG("%{public}s: windowId[%{public}d]", __func__, windowId); + + napi_value nPageId; + int pageId = eventInfo.GetPageId(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, pageId, &nPageId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "pageId", nPageId)); + HILOG_DEBUG("%{public}s: pageId[%{public}d]", __func__, pageId); + + napi_value nComponentId; + int componentId = eventInfo.GetViewId(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, componentId, &nComponentId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "componentId", nComponentId)); + HILOG_DEBUG("%{public}s: componentId[%{public}d]", __func__, componentId); + + napi_value nDescription; + std::string description = eventInfo.GetDescription(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, description.c_str(), NAPI_AUTO_LENGTH, &nDescription)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "description", nDescription)); + + napi_value nTriggerAction; + ActionType triggerAction = eventInfo.GetTriggerAction(); + std::string strTriggerAction = ConvertOperationTypeToString(triggerAction); + NAPI_CALL_RETURN_VOID(env, + napi_create_string_utf8(env, strTriggerAction.c_str(), NAPI_AUTO_LENGTH, &nTriggerAction)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "triggerAction", nTriggerAction)); + + napi_value nTextMoveUnit; + TextMoveUnit textMoveUnit = eventInfo.GetTextMovementStep(); + std::string strTextMoveUnit = CovertTextMoveStepToString(textMoveUnit); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strTextMoveUnit.c_str(), NAPI_AUTO_LENGTH, &nTextMoveUnit)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "textMoveUnit", nTextMoveUnit)); + + napi_value nContents; + std::vector contents = eventInfo.GetContentList(); + size_t contentCount = contents.size(); + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &nContents)); + for (size_t idx = 0; idx < contentCount; idx++) { + napi_value nContent; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, contents[idx].c_str(), NAPI_AUTO_LENGTH, &nContent)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, nContents, idx, nContent)); + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "contents", nContents)); + + napi_value nLastContent; + std::string lastContent = eventInfo.GetLatestContent(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, lastContent.c_str(), NAPI_AUTO_LENGTH, &nLastContent)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "lastContent", nLastContent)); + + napi_value nBeginIndex; + int beginIndex = eventInfo.GetBeginIndex(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, beginIndex, &nBeginIndex)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "beginIndex", nBeginIndex)); + + napi_value nCurrentIndex; + int currentIndex = eventInfo.GetCurrentIndex(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, currentIndex, &nCurrentIndex)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "currentIndex", nCurrentIndex)); + + napi_value nEndIndex; + int endIndex = eventInfo.GetEndIndex(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, endIndex, &nEndIndex)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "endIndex", nEndIndex)); + + napi_value nItemCount; + int itemCount = eventInfo.GetItemCounts(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, itemCount, &nItemCount)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "itemCount", nItemCount)); + + // napi_value nBeforeText; + // std::string beforeText = eventInfo.GetBeforeText(); + // NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, beforeText.c_str(), NAPI_AUTO_LENGTH, &nBeforeText)); + // NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "beforeText", nBeforeText)); + + napi_value nCategoryNotification; + NotificationCategory categoryNotification = eventInfo.GetNotificationInfo(); + std::string strCategoryNotification = ConvertCategoryNotificationToString(categoryNotification); + NAPI_CALL_RETURN_VOID(env, + napi_create_string_utf8(env, strCategoryNotification.c_str(), NAPI_AUTO_LENGTH, &nCategoryNotification)); + NAPI_CALL_RETURN_VOID(env, + napi_set_named_property(env, objEventInfo, "categoryNotification", nCategoryNotification)); + + // Bind js object to a Native object + AccessibilityEventInfo* pAccessibilityEventInfo = new AccessibilityEventInfo(); + *pAccessibilityEventInfo = eventInfo; + napi_status sts = napi_wrap(env, objEventInfo, pAccessibilityEventInfo, + [](napi_env env, void* data, void* hint) { + AccessibilityEventInfo* info = (AccessibilityEventInfo*)data; + delete info; + }, + nullptr, nullptr); + HILOG_DEBUG("napi_wrap status: %{public}d", (int)sts); +} + +void ConvertOperationToJS(napi_env env, napi_value result, AccessibleAction& operation) { + napi_value nType; + ActionType type = operation.GetActionType(); + std::string strType = ConvertOperationTypeToString(type); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strType.c_str(), NAPI_AUTO_LENGTH, &nType)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "type", nType)); + HILOG_DEBUG("%{public}s: operationType[%{public}s]", __func__, strType.c_str()); + + napi_value nDescription; + std::string strDescription = operation.GetDescriptionInfo(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strDescription.c_str(), NAPI_AUTO_LENGTH, &nDescription)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "description", nDescription)); +} + +void ConvertRangeInfoToJS(napi_env env, napi_value nRangeInfo, OHOS::Accessibility::RangeInfo& rangeInfo) { + napi_value nMin; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, rangeInfo.GetMin(), &nMin)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nRangeInfo, "min", nMin)); + + napi_value nMax; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, rangeInfo.GetMax(), &nMax)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nRangeInfo, "max", nMax)); + + napi_value nCurrent; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, rangeInfo.GetCurrent(), &nCurrent)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nRangeInfo, "current", nCurrent)); +} + +void ConvertGridInfoToJS(napi_env env, napi_value nGrid, OHOS::Accessibility::GridInfo& grid) { + napi_value nRowCount; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, grid.GetRowCount(), &nRowCount)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nGrid, "rowCount", nRowCount)); + + napi_value nColumnCount; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, grid.GetColumnCount(), &nColumnCount)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nGrid, "columnCount", nColumnCount)); + + napi_value nSelectionMode; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, grid.GetSelectionMode(), &nSelectionMode)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nGrid, "selectionMode", nSelectionMode)); +} + +void ConvertGridItemToJS(napi_env env, napi_value nGridItem, GridItemInfo& gridItem) { + napi_value nHeading; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, gridItem.IsHeading(), &nHeading)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nGridItem, "heading", nHeading)); + + napi_value nColumnIndex; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, gridItem.GetColumnIndex(), &nColumnIndex)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nGridItem, "columnIndex", nColumnIndex)); + + napi_value nRowIndex; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, gridItem.GetRowIndex(), &nRowIndex)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nGridItem, "rowIndex", nRowIndex)); + + napi_value nColumnSpan; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, gridItem.GetColumnSpan(), &nColumnSpan)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nGridItem, "columnSpan", nColumnSpan)); + + napi_value nRowSpan; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, gridItem.GetRowSpan(), &nRowSpan)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nGridItem, "rowSpan", nRowSpan)); + + napi_value nSelected; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, gridItem.IsSelected(), &nSelected)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, nGridItem, "selected", nSelected)); +} + +void ConvertElementInfosToJS(napi_env env, napi_value result, + std::vector& elementInfos) +{ + size_t index = 0; + + for (auto& elementInfo : elementInfos) { + napi_value obj = nullptr; + napi_new_instance(env, NElementInfo::cons_, 0, nullptr, &obj); + ConvertElementInfoToJS(env, obj, elementInfo); + napi_set_element(env, result, index, obj); + index++; + } +} + +void ConvertElementInfoToJS(napi_env env, napi_value result, AccessibilityElementInfo& elementInfo) { + + napi_value nWindowsId; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, elementInfo.GetWindowId(), &nWindowsId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "windowId", nWindowsId)); + HILOG_DEBUG("%{public}s: windowId[%{public}d]", __func__, elementInfo.GetWindowId()); + + napi_value nAccessibilityId; + int accessibilityId = elementInfo.GetAccessibilityId(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, accessibilityId, &nAccessibilityId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "accessibilityId", nAccessibilityId)); + HILOG_DEBUG("%{public}s: accessibilityId[%{public}d]", __func__, accessibilityId); + + napi_value nComponentId; + int componentId = elementInfo.GetAccessibilityId(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, componentId, &nComponentId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "componentId", nComponentId)); + + napi_value nBundleName; + std::string strBundleName = elementInfo.GetBundleName(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strBundleName.c_str(), NAPI_AUTO_LENGTH, &nBundleName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "bundleName", nBundleName)); + + napi_value nComponentType; + std::string strComponentType = elementInfo.GetComponentType(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strComponentType.c_str(), NAPI_AUTO_LENGTH, + &nComponentType)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "componentType", nComponentType)); + HILOG_DEBUG("%{public}s: componentType[%{public}s]", __func__, strComponentType.c_str()); + + napi_value nInputType; + int inputType = elementInfo.GetInputType(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, inputType, &nInputType)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "inputType", nInputType)); + + napi_value nText; + std::string strText = elementInfo.GetContent(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strText.c_str(), NAPI_AUTO_LENGTH, &nText)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "text", nText)); + HILOG_DEBUG("%{public}s: text[%{public}s]", __func__, strText.c_str()); + + napi_value nHintText; + std::string strHintText = elementInfo.GetHint(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strHintText.c_str(), NAPI_AUTO_LENGTH, &nHintText)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "hintText", nHintText)); + + napi_value nDescription; + std::string strDescription = elementInfo.GetDescriptionInfo(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strDescription.c_str(), NAPI_AUTO_LENGTH, &nDescription)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "description", nDescription)); + + napi_value nResourceName; + std::string strResourceName = elementInfo.GetComponentResourceId(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strResourceName.c_str(), NAPI_AUTO_LENGTH, &nResourceName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "resourceName", nResourceName)); + + napi_value nChildNodeIds; + std::vector childIds = elementInfo.GetChildIds(); + size_t childCount = childIds.size(); + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &nChildNodeIds)); + + for (size_t idx = 0; idx < childCount; idx++) { + napi_value nChildId; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, childIds[idx], &nChildId)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, nChildNodeIds, idx, nChildId)); + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "childNodeIds", nChildNodeIds)); + + napi_value nOperations; + NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &nOperations)); + std::vector operations = elementInfo.GetActionList(); + size_t operationCount = operations.size(); + for (size_t idx = 0; idx < operationCount; idx++) { + napi_value nOp; + napi_create_object(env, &nOp); + ConvertOperationToJS(env, nOp, operations[idx]); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, nOperations, idx, nOp)); + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "operations", nOperations)); + + napi_value nTextLengthLimit; + int textLengthLimit = elementInfo.GetTextLengthLimit(); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, textLengthLimit, &nTextLengthLimit)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "textLengthLimit", nTextLengthLimit)); + + napi_value nRect; + napi_create_object(env, &nRect); + Accessibility::Rect rect = elementInfo.GetRectInScreen(); + ConvertRectToJS(env, nRect, rect); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "rect", nRect)); + + napi_value nCheckable; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsCheckable(), &nCheckable)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "checkable", nCheckable)); + + napi_value nChecked; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsChecked(), &nChecked)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "checked", nChecked)); + + napi_value nFocusable; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsFocusable(), &nFocusable)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "focusable", nFocusable)); + HILOG_DEBUG("%{public}s: focusable[%{public}d]", __func__, elementInfo.IsFocusable()); + + napi_value nFocused; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsFocused(), &nFocused)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "focused", nFocused)); + HILOG_DEBUG("%{public}s: focused[%{public}d]", __func__, elementInfo.IsFocused()); + + napi_value nVisable; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsVisible(), &nVisable)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isVisible", nVisable)); + HILOG_DEBUG("%{public}s: isVisible[%{public}d]", __func__, elementInfo.IsVisible()); + + napi_value nAccessibilityFocused; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.HasAccessibilityFocus(), &nAccessibilityFocused)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "accessibilityFocused", nAccessibilityFocused)); + HILOG_DEBUG("%{public}s: accessibilityFocused[%{public}d]", __func__, elementInfo.HasAccessibilityFocus()); + + napi_value nSelected; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsSelected(), &nSelected)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "selected", nSelected)); + + napi_value nClickable; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsClickable(), &nClickable)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "clickable", nClickable)); + + napi_value nLongClickable; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsLongClickable(), &nLongClickable)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "longClickable", nLongClickable)); + + napi_value nIsEnable; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsEnabled(), &nIsEnable)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isEnable", nIsEnable)); + + napi_value nIsPassword; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsPassword(), &nIsPassword)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isPassword", nIsPassword)); + + napi_value nScrollable; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsScrollable(), &nScrollable)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "scrollable", nScrollable)); + + napi_value nEditable; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsEditable(), &nEditable)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "editable", nEditable)); + + napi_value nPopupSupported; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsPopupSupported(), &nPopupSupported)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "popupSupported", nPopupSupported)); + + napi_value nPluraLineSupported; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsPluraLineSupported(), &nPluraLineSupported)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "pluraLineSupported", nPluraLineSupported)); + + napi_value nDeleteable; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsDeletable(), &nDeleteable)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "deleteable", nDeleteable)); + + napi_value nIsHint; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsGivingHint(), &nIsHint)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isHint", nIsHint)); + + napi_value nIsEssential; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.IsEssential(), &nIsEssential)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isEssential", nIsEssential)); + HILOG_DEBUG("%{public}s: isEssential[%{public}d]", __func__, elementInfo.IsEssential()); + + napi_value nCurrentIndex; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, elementInfo.GetCurrentIndex(), &nCurrentIndex)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "currentIndex", nCurrentIndex)); + + napi_value nStartIndex; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, elementInfo.GetBeginIndex(), &nStartIndex)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "startIndex", nStartIndex)); + + napi_value nEndIndex; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, elementInfo.GetEndIndex(), &nEndIndex)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "endIndex", nEndIndex)); + + napi_value nRangeInfo; + napi_create_object(env, &nRangeInfo); + RangeInfo rangeInfo = elementInfo.GetRange(); + ConvertRangeInfoToJS(env, nRangeInfo, rangeInfo); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "rangeInfo", nRangeInfo)); + + napi_value nGrid; + napi_create_object(env, &nGrid); + GridInfo grid = elementInfo.GetGrid(); + ConvertGridInfoToJS(env, nGrid, grid); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "grid", nGrid)); + + napi_value nGridItem; + napi_create_object(env, &nGridItem); + GridItemInfo gridItem = elementInfo.GetGridItem(); + ConvertGridItemToJS(env, nGridItem, gridItem); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "gridItem", nGridItem)); + + napi_value nActiveRegion; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, elementInfo.GetLiveRegion(), &nActiveRegion)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "activeRegion", nActiveRegion)); + + napi_value nIsContentInvalid; + NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, elementInfo.GetContentInvalid(), &nIsContentInvalid)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "isContentInvalid", nIsContentInvalid)); + + napi_value nError; + std::string strError = elementInfo.GetError(); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, strError.c_str(), NAPI_AUTO_LENGTH, &nError)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "error", nError)); + + napi_value nLabel; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, elementInfo.GetLabeledAccessibilityId(), &nLabel)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "label", nLabel)); + + napi_value nBeginSelected; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, elementInfo.GetSelectedBegin(), &nBeginSelected)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "beginSelected", nBeginSelected)); + + napi_value nEndSelected; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, elementInfo.GetSelectedEnd(), &nEndSelected)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, "endSelected", nEndSelected)); + // Bind js object to a Native object + AccessibilityElementInfo* pElementInfo = new AccessibilityElementInfo(elementInfo); + napi_status sts = napi_wrap(env, result, pElementInfo, + [](napi_env env, void* data, void* hint) { + AccessibilityElementInfo* info = (AccessibilityElementInfo*)data; + delete info; + }, + nullptr, nullptr); + HILOG_DEBUG("napi_wrap status: %{public}d", (int)sts); +} + +static WindowUpdateType ConvertStringToWindowUpdateTypes(std::string type) { + static const std::map windowsUpdateTypesTable = { + {"accessibilityFocus", WindowUpdateType::WINDOW_UPDATE_ACCESSIBILITY_FOCUSED}, + {"focus", WindowUpdateType::WINDOW_UPDATE_FOCUSED}, + {"active", WindowUpdateType::WINDOW_UPDATE_ACTIVE}, + {"add", WindowUpdateType::WINDOW_UPDATE_ADDED}, + {"remove", WindowUpdateType::WINDOW_UPDATE_REMOVED}, + {"bounds", WindowUpdateType::WINDOW_UPDATE_BOUNDS}, + {"title", WindowUpdateType::WINDOW_UPDATE_TITLE}, + {"layer", WindowUpdateType::WINDOW_UPDATE_LAYER}, + {"parent", WindowUpdateType::WINDOW_UPDATE_PARENT}, + {"children", WindowUpdateType::WINDOW_UPDATE_CHILDREN}, + {"pip", WindowUpdateType::WINDOW_UPDATE_PIP} + }; + + if (windowsUpdateTypesTable.find(type) == windowsUpdateTypesTable.end()) { + HILOG_WARN("%{public}s: invalid key[%{public}s]", __func__, type.c_str()); + return WINDOW_UPDATE_INVALID; + } + + return windowsUpdateTypesTable.at(type); +} + +static EventType ConvertStringToEventInfoTypes(std::string type) { + static const std::map eventInfoTypesTable = { + {"click", EventType::TYPE_VIEW_CLICKED_EVENT}, + {"longClick", EventType::TYPE_VIEW_LONG_CLICKED_EVENT}, + {"select", EventType::TYPE_VIEW_SELECTED_EVENT}, + {"focus", EventType::TYPE_VIEW_FOCUSED_EVENT}, + {"textUpdate", EventType::TYPE_VIEW_TEXT_UPDATE_EVENT}, + {"pageStateUpdate", EventType::TYPE_PAGE_STATE_UPDATE}, + {"notificationUpdate", EventType::TYPE_NOTIFICATION_UPDATE_EVENT}, + {"hoverEnter", EventType::TYPE_VIEW_HOVER_ENTER_EVENT}, + {"hoverExit", EventType::TYPE_VIEW_HOVER_EXIT_EVENT}, + {"touchGuideGestureBegin", EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN}, + {"touchGuideGestureEnd", EventType::TYPE_TOUCH_GUIDE_GESTURE_END}, + {"pageContentUpdate", EventType::TYPE_PAGE_CONTENT_UPDATE}, + {"scroll", EventType::TYPE_VIEW_SCROLLED_EVENT}, + {"textSelectionUpdate", EventType::TYPE_VIEW_TEXT_SELECTION_UPDATE_EVENT}, + {"publicNotice", EventType::TYPE_PUBLIC_NOTICE_EVENT}, + {"accessibilityFocus", EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT}, + {"accessibilityFocusClear", EventType::TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED_EVENT}, + {"textMoveUnit", EventType::TYPE_VIEW_TEXT_MOVE_UNIT_EVENT}, + {"touchGuideBegin", EventType::TYPE_TOUCH_GUIDE_BEGIN}, + {"touchGuideEnd", EventType::TYPE_TOUCH_GUIDE_END}, + {"touchBegin", EventType::TYPE_TOUCH_BEGIN}, + {"touchEnd", EventType::TYPE_TOUCH_END}, + {"windowUpdate", EventType::TYPE_WINDOW_UPDATE} + }; + + if (eventInfoTypesTable.find(type) == eventInfoTypesTable.end()) { + HILOG_WARN("%{public}s: invalid key[%{public}s]", __func__, type.c_str()); + return TYPE_VIEW_INVALID; + } + + return eventInfoTypesTable.at(type); +} + +ActionType ConvertStringToAccessibleOperationType(std::string type) { + std::map accessibleOperationTypeTable = { + {"focus", ActionType::ACCESSIBILITY_ACTION_FOCUS}, + {"clearFocus", ActionType::ACCESSIBILITY_ACTION_CLEAR_FOCUS}, + {"select", ActionType::ACCESSIBILITY_ACTION_SELECT}, + {"clearSelection", ActionType::ACCESSIBILITY_ACTION_CLEAR_SELECTION}, + {"click", ActionType::ACCESSIBILITY_ACTION_CLICK}, + {"longClick", ActionType::ACCESSIBILITY_ACTION_LONG_CLICK}, + {"accessibilityFocus", ActionType::ACCESSIBILITY_ACTION_ACCESSIBILITY_FOCUS}, + {"clearAccessibilityFocus", ActionType::ACCESSIBILITY_ACTION_CLEAR_ACCESSIBILITY_FOCUS}, + {"scrollForward", ActionType::ACCESSIBILITY_ACTION_SCROLL_FORWARD}, + {"scrollBackward", ActionType::ACCESSIBILITY_ACTION_SCROLL_BACKWARD}, + {"copy", ActionType::ACCESSIBILITY_ACTION_COPY}, + {"paste", ActionType::ACCESSIBILITY_ACTION_PASTE}, + {"cut", ActionType::ACCESSIBILITY_ACTION_CUT}, + {"setSelection", ActionType::ACCESSIBILITY_ACTION_SET_SELECTION}, + {"setText", ActionType::ACCESSIBILITY_ACTION_SET_TEXT}, + {"nextText", ActionType::ACCESSIBILITY_ACTION_NEXT_TEXT}, + {"previousText", ActionType::ACCESSIBILITY_ACTION_PREVIOUS_TEXT}, + {"unfold", ActionType::ACCESSIBILITY_ACTION_UNFOLD}, + {"fold", ActionType::ACCESSIBILITY_ACTION_FOLD}, + {"nextHtmlItem", ActionType::ACCESSIBILITY_ACTION_NEXT_HTML_ITEM}, + {"previousHtmlItem", ActionType::ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM}, + {"delete", ActionType::ACCESSIBILITY_ACTION_DELETED} + }; + + if (accessibleOperationTypeTable.find(type) == accessibleOperationTypeTable.end()) { + HILOG_WARN("%{public}s: invalid key[%{public}s]", __func__, type.c_str()); + return ACCESSIBILITY_ACTION_INVALID; + } + + return accessibleOperationTypeTable.at(type); +} + +AccessibilityAbilityTypes ConvertStringToAccessibilityAbilityTypes(std::string type) +{ + std::map accessibilityAbilityTypesTable = { + {"spoken", AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN}, + {"haptic", AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_HAPTIC}, + {"audible", AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_AUDIBLE}, + {"visual", AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_VISUAL}, + {"generic", AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_GENERIC}, + }; + + if (accessibilityAbilityTypesTable.find(type) == accessibilityAbilityTypesTable.end()) { + HILOG_WARN("%{public}s: invalid key[%{public}s]", __func__, type.c_str()); + return AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_INVALID; + } + + return accessibilityAbilityTypesTable.at(type); +} + +AbilityStateType ConvertStringToAbilityStateTypes(std::string type) +{ + std::map abilityStateTypeTable = { + {"enable", AbilityStateType::ABILITY_STATE_ENABLE}, + {"disable", AbilityStateType::ABILITY_STATE_DISABLE}, + {"install", AbilityStateType::ABILITY_STATE_INSTALLED} + }; + + if (abilityStateTypeTable.find(type) == abilityStateTypeTable.end()) { + HILOG_WARN("%{public}s: invalid key[%{public}s]", __func__, type.c_str()); + return ABILITY_STATE_INVALID; + } + + return abilityStateTypeTable.at(type); +} + +GlobalAction ConvertStringToGlobalAction(std::string type) +{ + std::map globalActionTable = { + {"back", GlobalAction::GLOBAL_ACTION_BACK}, + {"home", GlobalAction::GLOBAL_ACTION_HOME}, + {"recent", GlobalAction::GLOBAL_ACTION_RECENT}, + {"notification", GlobalAction::GLOBAL_ACTION_NOTIFICATION}, + {"popUpPowerDialog", GlobalAction::GLOBAL_ACTION_POP_UP_POWER_DIALOG}, + {"divideScreen", GlobalAction::GLOBAL_ACTION_DIVIDE_SCREEN}, + {"lockScreen", GlobalAction::GLOBAL_ACTION_LOCK_SCREEN}, + {"captureScreen", GlobalAction::GLOBAL_ACTION_CAPTURE_SCREEN} + }; + + if (globalActionTable.find(type) == globalActionTable.end()) { + HILOG_WARN("%{public}s: invalid key[%{public}s]", __func__, type.c_str()); + return GLOBAL_ACTION_INVALID; + } + + return globalActionTable.at(type); +} + +static TextMoveUnit ConvertStringToTextMoveStep(std::string type) { + static const std::map textMoveStepTable = { + {"char", TextMoveUnit::STEP_CHARACTER}, + {"word", TextMoveUnit::STEP_WORD}, + {"line", TextMoveUnit::STEP_LINE}, + {"page", TextMoveUnit::STEP_PAGE}, + {"paragraph", TextMoveUnit::STEP_PARAGRAPH} + }; + + if (textMoveStepTable.find(type) == textMoveStepTable.end()) { + HILOG_WARN("%{public}s: invalid key[%{public}s]", __func__, type.c_str()); + return STEP_INVALID; + } + + return textMoveStepTable.at(type); +} + +static NotificationCategory ConvertStringToNotificationCategory(std::string type) { + static const std::map notificationCategoryTable = { + {"call", NotificationCategory::CATEGORY_CALL}, + {"msg", NotificationCategory::CATEGORY_MSG}, + {"email", NotificationCategory::CATEGORY_EMAIL}, + {"event", NotificationCategory::CATEGORY_EVENT}, + {"promo", NotificationCategory::CATEGORY_PROMO}, + {"alarm", NotificationCategory::CATEGORY_ALARM}, + {"progress", NotificationCategory::CATEGORY_PROGRESS}, + {"social", NotificationCategory::CATEGORY_SOCIAL}, + {"err", NotificationCategory::CATEGORY_ERR}, + {"transport", NotificationCategory::CATEGORY_TRANSPORT}, + {"sys", NotificationCategory::CATEGORY_SYS}, + {"service", NotificationCategory::CATEGORY_SERVICE} + }; + + if (notificationCategoryTable.find(type) == notificationCategoryTable.end()) { + HILOG_WARN("%{public}s: invalid key[%{public}s]", __func__, type.c_str()); + return CATEGORY_INVALID; + } + + return notificationCategoryTable.at(type); +} + +void ConvertActionArgsJSToNAPI(napi_env env, napi_value object, std::map &args, + OHOS::Accessibility::ActionType action) +{ + napi_value propertyNameValue = nullptr; + bool hasProperty = false; + std::string str = ""; + switch(action) { + case ActionType::ACCESSIBILITY_ACTION_NEXT_HTML_ITEM: + napi_create_string_utf8(env, "htmlItem", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + args.insert(std::pair("htmlItem", str.c_str())); + } + break; + case ActionType::ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM: + napi_create_string_utf8(env, "htmlItem", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + args.insert(std::pair("htmlItem", str.c_str())); + } + break; + case ActionType::ACCESSIBILITY_ACTION_NEXT_TEXT: + napi_create_string_utf8(env, "textMoveUnit", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + args.insert(std::pair("textMoveUnit", str.c_str())); + } + break; + case ActionType::ACCESSIBILITY_ACTION_PREVIOUS_TEXT: + napi_create_string_utf8(env, "textMoveUnit", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + args.insert(std::pair("textMoveUnit", str.c_str())); + } + break; + case ActionType::ACCESSIBILITY_ACTION_SET_SELECTION: + napi_create_string_utf8(env, "selectTextBegin", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + args.insert(std::pair("selectTextBegin", str.c_str())); + } + napi_create_string_utf8(env, "selectTextEnd", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + args.insert(std::pair("selectTextEnd", str.c_str())); + } + break; + case ActionType::ACCESSIBILITY_ACTION_SET_TEXT: + napi_create_string_utf8(env, "setText", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + args.insert(std::pair("setText", str.c_str())); + } + break; + default: + break; + } +} + +void ConvertEventInfoJSToNAPI(napi_env env, napi_value object, AccessibilityEventInfo &eventInfo) +{ + napi_value propertyNameValue = nullptr; + bool hasProperty = false; + int32_t dataValue = 0; + std::string str = ""; + napi_create_string_utf8(env, "type", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + eventInfo.SetEventType(ConvertStringToEventInfoTypes(str)); + } + + napi_create_string_utf8(env, "windowUpdateType", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + eventInfo.SetWindowChangeTypes(ConvertStringToWindowUpdateTypes(str)); + } + + napi_create_string_utf8(env, "bundleName", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + eventInfo.SetBundleName(str); + } + + napi_create_string_utf8(env, "componentType", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + eventInfo.SetComponentType(str); + } + + int64_t timestamp = 0; + napi_create_string_utf8(env, "timeStamp", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + napi_get_value_int64(env, value, ×tamp); + eventInfo.SetTimeStamp(timestamp); + } + + napi_create_string_utf8(env, "windowId", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + napi_get_value_int32(env, value, &dataValue); + eventInfo.SetWindowId(dataValue); + } + + napi_create_string_utf8(env, "pageId", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + napi_get_value_int32(env, value, &dataValue); + eventInfo.SetPageId(dataValue); + } + + napi_create_string_utf8(env, "componentId", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + napi_get_value_int32(env, value, &dataValue); + eventInfo.SetSource(dataValue); + } + + napi_create_string_utf8(env, "description", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + eventInfo.SetComponentType(str); + } + + napi_create_string_utf8(env, "triggerAction", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + eventInfo.SetTriggerAction(ConvertStringToAccessibleOperationType(str)); + } + + napi_create_string_utf8(env, "textMoveUnit", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + eventInfo.SetTextMovementStep(ConvertStringToTextMoveStep(str)); + } + + napi_create_string_utf8(env, "contents", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + void *datas = nullptr; + size_t dataLen = 0; + napi_get_arraybuffer_info(env, value, &datas, &dataLen); + auto rawData = (std::string *)datas; + for (int i = 0; i < int(dataLen); i++) { + eventInfo.AddContent(*(rawData+i)); + } + } + + napi_create_string_utf8(env, "lastContent", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + eventInfo.SetLatestContent(str); + } + + napi_create_string_utf8(env, "beginIndex", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + napi_get_value_int32(env, value, &dataValue); + eventInfo.SetBeginIndex(dataValue); + } + + napi_create_string_utf8(env, "currentIndex", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + napi_get_value_int32(env, value, &dataValue); + eventInfo.SetCurrentIndex(dataValue); + } + + napi_create_string_utf8(env, "endIndex", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + napi_get_value_int32(env, value, &dataValue); + eventInfo.SetEndIndex(dataValue); + } + + napi_create_string_utf8(env, "itemCount", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + napi_get_value_int32(env, value, &dataValue); + eventInfo.SetItemCounts(dataValue); + } + + // napi_create_string_utf8(env, "beforeText", NAPI_AUTO_LENGTH, &propertyNameValue); + // napi_has_property(env, object, propertyNameValue, &hasProperty); + // if (hasProperty) { + // napi_value value = nullptr; + // napi_get_property(env, object, propertyNameValue, &value); + // str = GetStringFromNAPI(env, value); + // eventInfo.SetBeforeText(str); + // } + + + napi_create_string_utf8(env, "categoryNotification", NAPI_AUTO_LENGTH, &propertyNameValue); + napi_has_property(env, object, propertyNameValue, &hasProperty); + if (hasProperty) { + napi_value value = nullptr; + napi_get_property(env, object, propertyNameValue, &value); + str = GetStringFromNAPI(env, value); + eventInfo.SetNotificationInfo(ConvertStringToNotificationCategory(str)); + } +} + +std::vector ParseAbilityTypesToVec(uint32_t abilityTypesValue) +{ + std::vector result; + + if (abilityTypesValue & AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN) { + result.push_back("spoken"); + } + if (abilityTypesValue & AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_HAPTIC) { + result.push_back("haptic"); + } + if (abilityTypesValue & AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_AUDIBLE) { + result.push_back("audible"); + } + if (abilityTypesValue & AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_VISUAL) { + result.push_back("visual"); + } + if (abilityTypesValue & AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_GENERIC) { + result.push_back("generic"); + } + + return result; +} + +std::vector ParseCapabilitiesToVec(uint32_t capabilitiesValue) +{ + std::vector result; + + if (capabilitiesValue & Capability::CAPABILITY_RETRIEVE) { + result.push_back("retrieve"); + } + if (capabilitiesValue & Capability::CAPABILITY_TOUCH_GUIDE) { + result.push_back("touchGuide"); + } + if (capabilitiesValue & Capability::CAPABILITY_KEY_EVENT_OBSERVER) { + result.push_back("keyEventObserver"); + } + if (capabilitiesValue & Capability::CAPABILITY_ZOOM) { + result.push_back("zoom"); + } + if (capabilitiesValue & Capability::CAPABILITY_GESTURE) { + result.push_back("gesture"); + } + + return result; +} + +std::vector ParseEventTypesToVec(uint32_t eventTypesValue) +{ + std::vector result; + + if (eventTypesValue & EventType::TYPE_VIEW_CLICKED_EVENT) { + result.push_back("click"); + } + if (eventTypesValue & EventType::TYPE_VIEW_LONG_CLICKED_EVENT) { + result.push_back("longClick"); + } + if (eventTypesValue & EventType::TYPE_VIEW_SELECTED_EVENT) { + result.push_back("select"); + } + if (eventTypesValue & EventType::TYPE_VIEW_FOCUSED_EVENT) { + result.push_back("focus"); + } + if (eventTypesValue & EventType::TYPE_VIEW_TEXT_UPDATE_EVENT) { + result.push_back("textUpdate"); + } + if (eventTypesValue & EventType::TYPE_PAGE_STATE_UPDATE) { + result.push_back("pageStateUpdate"); + } + if (eventTypesValue & EventType::TYPE_NOTIFICATION_UPDATE_EVENT) { + result.push_back("notificationUpdate"); + } + if (eventTypesValue & EventType::TYPE_VIEW_HOVER_ENTER_EVENT) { + result.push_back("hoverEnter"); + } + if (eventTypesValue & EventType::TYPE_VIEW_HOVER_EXIT_EVENT) { + result.push_back("hoverExit"); + } + if (eventTypesValue & EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN) { + result.push_back("touchGuideGestureBegin"); + } + if (eventTypesValue & EventType::TYPE_TOUCH_GUIDE_GESTURE_END) { + result.push_back("touchGuideGestureEnd"); + } + if (eventTypesValue & EventType::TYPE_PAGE_CONTENT_UPDATE) { + result.push_back("pageContentUpdate"); + } + if (eventTypesValue & EventType::TYPE_VIEW_SCROLLED_EVENT) { + result.push_back("scroll"); + } + if (eventTypesValue & EventType::TYPE_VIEW_TEXT_SELECTION_UPDATE_EVENT) { + result.push_back("textSelectionUpdate"); + } + if (eventTypesValue & EventType::TYPE_PUBLIC_NOTICE_EVENT) { + result.push_back("publicNotice"); + } + if (eventTypesValue & EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT) { + result.push_back("accessibilityFocus"); + } + if (eventTypesValue & EventType::TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED_EVENT) { + result.push_back("accessibilityFocusClear"); + } + if (eventTypesValue & EventType::TYPE_VIEW_TEXT_MOVE_UNIT_EVENT) { + result.push_back("textMoveUnit"); + } + if (eventTypesValue & EventType::TYPE_TOUCH_GUIDE_BEGIN) { + result.push_back("touchGuideBegin"); + } + if (eventTypesValue & EventType::TYPE_TOUCH_GUIDE_END) { + result.push_back("touchGuideEnd"); + } + if (eventTypesValue & EventType::TYPE_TOUCH_BEGIN) { + result.push_back("touchBegin"); + } + if (eventTypesValue & EventType::TYPE_TOUCH_END) { + result.push_back("touchEnd"); + } + if (eventTypesValue & EventType::TYPE_WINDOW_UPDATE) { + result.push_back("windowUpdate"); + } + + return result; +} \ No newline at end of file diff --git a/interfaces/kits/napi/src/napi_accessibility_window_info.cpp b/interfaces/kits/napi/src/napi_accessibility_window_info.cpp new file mode 100644 index 00000000..3e63c6f5 --- /dev/null +++ b/interfaces/kits/napi/src/napi_accessibility_window_info.cpp @@ -0,0 +1,355 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "hilog_wrapper.h" +#include "napi_accessibility_window_info.h" +#include "napi_accessibility_utils.h" +#include "napi_accessibility_info.h" + +using namespace OHOS; +using namespace OHOS::Accessibility; + +napi_value NAccessibilityWindowInfo::cons_ = nullptr; + +void NAccessibilityWindowInfo::DefineJSAccessibilityWindowInfo(napi_env env) { + napi_property_descriptor descForAccessibilityWindowInfo[] = { + DECLARE_NAPI_FUNCTION("getAnchorElementInfo", NAccessibilityWindowInfo::GetAnchorElementInfo), + DECLARE_NAPI_FUNCTION("getRootElementInfo", NAccessibilityWindowInfo::GetRootElementInfo), + DECLARE_NAPI_FUNCTION("getParent", NAccessibilityWindowInfo::GetParent), + DECLARE_NAPI_FUNCTION("getChild", NAccessibilityWindowInfo::GetChild), + }; + + NAPI_CALL_RETURN_VOID(env, + napi_define_class(env, + "AccessibilityWindowInfo", + NAPI_AUTO_LENGTH, + NAccessibilityWindowInfo::JSConstructor, + nullptr, + sizeof(descForAccessibilityWindowInfo) / sizeof(descForAccessibilityWindowInfo[0]), + descForAccessibilityWindowInfo, + &NAccessibilityWindowInfo::cons_)); +} + +napi_value NAccessibilityWindowInfo::JSConstructor(napi_env env, napi_callback_info info) { + napi_value jsthis = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr)); + return jsthis; +} + +napi_value NAccessibilityWindowInfo::GetAnchorElementInfo(napi_env env, napi_callback_info info) { + HILOG_DEBUG("GetAnchorElementInfo called"); + size_t argc = ARGS_SIZE_ONE; + napi_value argv[ARGS_SIZE_ONE] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityWindowInfo* windowInfo = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + HILOG_DEBUG("argc = %{public}d", (int)argc); + + status = napi_unwrap(env, thisVar, (void**)&windowInfo); + HILOG_DEBUG("napi_unwrap status: %{public}d", (int)status); + if (!windowInfo) { + HILOG_DEBUG("windowInfo is null!!"); + } + + NAccessibilityWindowInfoData *callbackInfo = new NAccessibilityWindowInfoData(); + callbackInfo->nativeWindowInfo_ = *windowInfo; + + napi_value promise = nullptr; + if (argc > 0) { + HILOG_ERROR("GetAnchorElementInfo callback mode"); + napi_create_reference(env, argv[PARAM0], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_ERROR("GetAnchorElementInfo promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetAnchorElementInfo", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilityWindowInfoData *callbackInfo = (NAccessibilityWindowInfoData*)data; + AccessibilityWindowInfo windowInfo = callbackInfo->nativeWindowInfo_; + callbackInfo->result_ = windowInfo.GetAnchor(callbackInfo->nodeInfo_ ); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + HILOG_DEBUG("GetAnchorElementInfo execute back"); + NAccessibilityWindowInfoData* callbackInfo = (NAccessibilityWindowInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + // napi_create_object(env, &argv); + napi_new_instance(env, NElementInfo::cons_, 0, nullptr, &argv[PARAM1]); + ConvertElementInfoToJS(env, argv[PARAM1], callbackInfo->nodeInfo_); + + argv[PARAM0] = GetErrorValue(env, callbackInfo->result_ ? CODE_SUCCESS : CODE_FAILED); + if (callbackInfo->callback_) { + // Callback mode + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + if (callbackInfo->result_) { + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, argv[PARAM0]); + } + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} + +napi_value NAccessibilityWindowInfo::GetRootElementInfo(napi_env env, napi_callback_info info) { + HILOG_DEBUG("GetRootElementInfo called"); + size_t argc = ARGS_SIZE_ONE; + napi_value argv[ARGS_SIZE_ONE] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityWindowInfo* windowInfo = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + HILOG_DEBUG("argc = %{public}d", (int)argc); + + status = napi_unwrap(env, thisVar, (void**)&windowInfo); + HILOG_DEBUG("napi_unwrap status: %{public}d", (int)status); + if (!windowInfo) { + HILOG_DEBUG("windowInfo is null!!"); + } + + NAccessibilityWindowInfoData *callbackInfo = new NAccessibilityWindowInfoData(); + callbackInfo->nativeWindowInfo_ = *windowInfo; + + napi_value promise = nullptr; + if (argc > 0) { + HILOG_ERROR("GetRootElementInfo callback mode"); + napi_create_reference(env, argv[PARAM0], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_ERROR("GetRootElementInfo promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetRootElementInfo", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilityWindowInfoData *callbackInfo = (NAccessibilityWindowInfoData*)data; + AccessibilityWindowInfo windowInfo = callbackInfo->nativeWindowInfo_; + callbackInfo->result_ = windowInfo.GetRootAccessibilityInfo(callbackInfo->nodeInfo_); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + HILOG_DEBUG("GetRootElementInfo execute back"); + NAccessibilityWindowInfoData* callbackInfo = (NAccessibilityWindowInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + // napi_create_object(env, &argv); + napi_new_instance(env, NElementInfo::cons_, 0, nullptr, &argv[PARAM1]); + ConvertElementInfoToJS(env, argv[PARAM1], callbackInfo->nodeInfo_); + + argv[PARAM0] = GetErrorValue(env, callbackInfo->result_ ? CODE_SUCCESS : CODE_FAILED); + if (callbackInfo->callback_) { + // Callback mode + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + if (callbackInfo->result_) { + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } else { + napi_reject_deferred(env, callbackInfo->deferred_, argv[PARAM0]); + } + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} + +napi_value NAccessibilityWindowInfo::GetParent(napi_env env, napi_callback_info info) { + HILOG_DEBUG("GetParent called"); + size_t argc = ARGS_SIZE_ONE; + napi_value argv[ARGS_SIZE_ONE] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityWindowInfo* windowInfo = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + HILOG_DEBUG("argc = %{public}d", (int)argc); + + status = napi_unwrap(env, thisVar, (void**)&windowInfo); + HILOG_DEBUG("napi_unwrap status: %{public}d", (int)status); + if (!windowInfo) { + HILOG_DEBUG("windowInfo is null!!"); + } + + NAccessibilityWindowInfoData *callbackInfo = new NAccessibilityWindowInfoData(); + callbackInfo->nativeWindowInfo_ = *windowInfo; + + napi_value promise = nullptr; + if (argc > 0) { + HILOG_ERROR("GetParent callback mode"); + napi_create_reference(env, argv[PARAM0], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_ERROR("GetParent promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetParent", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilityWindowInfoData *callbackInfo = (NAccessibilityWindowInfoData*)data; + AccessibilityWindowInfo windowInfo = callbackInfo->nativeWindowInfo_; + callbackInfo->window_ = windowInfo.GetParent(); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + HILOG_DEBUG("GetParent execute back"); + NAccessibilityWindowInfoData* callbackInfo = (NAccessibilityWindowInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + napi_new_instance(env, NAccessibilityWindowInfo::cons_, 0, nullptr, &argv[PARAM1]); + ConvertAccessibilityWindowInfoToJS(env, argv[PARAM1], callbackInfo->window_); + + if (callbackInfo->callback_) { + // Callback mode + argv[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} + +napi_value NAccessibilityWindowInfo::GetChild(napi_env env, napi_callback_info info) { + HILOG_DEBUG("GetChild called"); + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_status status; + napi_value thisVar; + void* data = nullptr; + AccessibilityWindowInfo* windowInfo = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)); + HILOG_DEBUG("argc = %{public}d", (int)argc); + + status = napi_unwrap(env, thisVar, (void**)&windowInfo); + HILOG_DEBUG("napi_unwrap status: %{public}d", (int)status); + if (!windowInfo) { + HILOG_DEBUG("windowInfo is null!!"); + } + int childIndex; + napi_get_value_int32(env, argv[PARAM0], &childIndex); + HILOG_INFO("GetChild childIndex = %{public}d", childIndex); + + NAccessibilityWindowInfoData *callbackInfo = new NAccessibilityWindowInfoData(); + callbackInfo->nativeWindowInfo_ = *windowInfo; + callbackInfo->childIndex_ = childIndex; + + napi_value promise = nullptr; + if (argc >= ARGS_SIZE_TWO) { + HILOG_ERROR("GetChild callback mode"); + napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + HILOG_ERROR("GetChild promise mode"); + napi_create_promise(env, &callbackInfo->deferred_, &promise); + } + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetChild", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { // execute async to call c++ function + NAccessibilityWindowInfoData *callbackInfo = (NAccessibilityWindowInfoData*)data; + AccessibilityWindowInfo windowInfo = callbackInfo->nativeWindowInfo_; + callbackInfo->window_ = windowInfo.GetChild(callbackInfo->childIndex_ ); + }, + [](napi_env env, napi_status status, void* data) { //execute the complete function + HILOG_DEBUG("GetChild execute back"); + NAccessibilityWindowInfoData* callbackInfo = (NAccessibilityWindowInfoData*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + napi_new_instance(env, NAccessibilityWindowInfo::cons_, 0, nullptr, &argv[PARAM1]); + ConvertAccessibilityWindowInfoToJS(env, argv[PARAM1], callbackInfo->window_); + + if (callbackInfo->callback_) { + // Callback mode + argv[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, callbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, callbackInfo->callback_); + } else { + // Promise mode + napi_resolve_deferred(env, callbackInfo->deferred_, argv[PARAM1]); + } + + napi_delete_async_work(env, callbackInfo->work_); + delete callbackInfo; + }, + (void*)callbackInfo, + &callbackInfo->work_); + napi_queue_async_work(env, callbackInfo->work_); + + return promise; +} \ No newline at end of file diff --git a/interfaces/kits/napi/src/napi_accessible_ability.cpp b/interfaces/kits/napi/src/napi_accessible_ability.cpp new file mode 100644 index 00000000..f6813762 --- /dev/null +++ b/interfaces/kits/napi/src/napi_accessible_ability.cpp @@ -0,0 +1,551 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include +#include +#include + +#include "accessible_ability.h" +#include "accessibility_element_info.h" +#include "hilog_wrapper.h" +#include "napi_accessibility_info.h" +#include "napi_accessible_ability.h" +#include "napi_accessible_ability_observer.h" +#include "napi_accessibility_def.h" +#include "napi_accessibility_utils.h" +#include "napi_accessibility_window_info.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +using namespace OHOS; +using namespace OHOS::Accessibility; + +napi_value g_accessibleAbility; +std::map> g_JsAACallbacks = {}; +std::shared_ptr g_AAObserver = std::make_shared(); + +void CreateGlobalAccessibleAbilityJSObject(napi_env env) { + napi_property_descriptor accessibleAbilityDesc[] = { + DECLARE_NAPI_FUNCTION("on", RegisterCallback), + DECLARE_NAPI_FUNCTION("connect", ConnectToAAMS), + DECLARE_NAPI_FUNCTION("disableAbility", DisableAbility), + DECLARE_NAPI_FUNCTION("getWindows", GetWindows), + DECLARE_NAPI_FUNCTION("getRootElementInfo", GetRootElementInfo), + DECLARE_NAPI_FUNCTION("getFocusElementInfo", GetFocusElementInfo), + DECLARE_NAPI_FUNCTION("performCommonAction", PerformCommonAction), + }; + + NAPI_CALL_RETURN_VOID(env, + napi_define_class(env, + "AccessibleAbility", + NAPI_AUTO_LENGTH, + AccessibleAbilityConstructor, + nullptr, + sizeof(accessibleAbilityDesc) / sizeof(accessibleAbilityDesc[0]), + accessibleAbilityDesc, + &g_accessibleAbility)); +} + +napi_value AccessibleAbilityConstructor(napi_env env, napi_callback_info info) { + napi_value jsthis = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr)); + return jsthis; +} + +napi_value GetAccessibleAbility(napi_env env, napi_callback_info info) { + HILOG_INFO("GetAccessibleAbility called"); + size_t expectedArgsCount = ARGS_SIZE_ONE; + size_t argc = expectedArgsCount; + napi_value argv = 0; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr)); + NAPI_ASSERT(env, argc <= expectedArgsCount, "Requires up to 1 argument."); + + AsyncGetAccessibleAbilityCallbackInfo* pCallbackInfo = new AsyncGetAccessibleAbilityCallbackInfo(); + pCallbackInfo->env_ = env; + + napi_value promise = nullptr; + + if (argc > (expectedArgsCount - CALLBACK_SIZE)) { + // Callback mode + HILOG_INFO("GetAccessibleAbility callback mode"); + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv, &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "Wrong argument type. Function expected."); + napi_create_reference(env, argv, 1, &pCallbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + // Promise mode + HILOG_INFO("GetAccessibleAbility promise mode"); + napi_create_promise(env, &pCallbackInfo->deferred_, &promise); + } + + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetAccessibleAbility", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) {}, + [](napi_env env, napi_status status, void* data) { + AsyncGetAccessibleAbilityCallbackInfo* pCallbackInfo = (AsyncGetAccessibleAbilityCallbackInfo*)data; + napi_value result[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_value callResult = 0; + napi_get_undefined(env, &undefined); + napi_new_instance(env, g_accessibleAbility, 0, nullptr, &result[PARAM1]); + + if (pCallbackInfo->callback_) { + // Callback mode + result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, pCallbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &callResult); + napi_delete_reference(env, pCallbackInfo->callback_); + } else { + // Promise mode + napi_resolve_deferred(env, pCallbackInfo->deferred_, result[PARAM1]); + } + + napi_delete_async_work(env, pCallbackInfo->asyncWork_); + delete pCallbackInfo; + }, + (void*)pCallbackInfo, + &pCallbackInfo->asyncWork_); + napi_queue_async_work(env, pCallbackInfo->asyncWork_); + + return promise; +} + +napi_value RegisterCallback(napi_env env, napi_callback_info info) { + HILOG_INFO("RegisterCallback called"); + size_t expectedArgsCount = ARGS_SIZE_TWO; + size_t argc = expectedArgsCount; + napi_value argv[ARGS_SIZE_TWO] = {0}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + NAPI_ASSERT(env, argc == expectedArgsCount, "Requires 2 arguments."); + std::string type; + ParseString(env, type, argv[PARAM0]); + std::shared_ptr pCallbackInfo = std::make_shared(); + pCallbackInfo->env_ = env; + + napi_valuetype valueType = napi_undefined; + napi_typeof(env, argv[PARAM1], &valueType); + NAPI_ASSERT(env, valueType == napi_function, "Wrong argument type. Function expected."); + NAPI_CALL(env, napi_create_reference(env, argv[PARAM1], 1, &pCallbackInfo->callback_)); + g_JsAACallbacks[type] = pCallbackInfo; + + napi_value ret = nullptr; + napi_get_undefined(env, &ret); + return ret; +} + +napi_value DisableAbility(napi_env env, napi_callback_info info) { + HILOG_INFO("DisableAbility called"); + size_t argc = ARGS_SIZE_ONE; + napi_value argv; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr)); + NAPI_ASSERT(env, argc <= ARGS_SIZE_ONE, "Requires up to 1 argument."); + + AsyncDisableAbilityCallbackInfo* pCallbackInfo = new AsyncDisableAbilityCallbackInfo(); + pCallbackInfo->env_ = env; + + napi_value promise = nullptr; + + if (argc == ARGS_SIZE_ONE) { + // Callback mode + HILOG_INFO("DisableAbility callback mode"); + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv, &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "Wrong argument type. Function expected."); + napi_create_reference(env, argv, 1, &pCallbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + // Promise mode + HILOG_INFO("DisableAbility promise mode"); + napi_create_promise(env, &pCallbackInfo->deferred_, &promise); + } + + napi_value resource = nullptr; + napi_create_string_utf8(env, "DisableAbility", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { + HILOG_DEBUG("DisableAbility execute"); + AccessibleAbility::GetInstance().DisableAbility(); + }, + [](napi_env env, napi_status status, void* data) { + HILOG_DEBUG("DisableAbility execute back"); + AsyncDisableAbilityCallbackInfo* pCallbackInfo = (AsyncDisableAbilityCallbackInfo*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + napi_get_undefined(env, &argv[PARAM1]); + + if (pCallbackInfo->callback_) { + // Callback mode + argv[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, pCallbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, pCallbackInfo->callback_); + } else { + // Promise mode + napi_resolve_deferred(env, pCallbackInfo->deferred_, argv[PARAM1]); + } + + napi_delete_async_work(env, pCallbackInfo->asyncWork_); + delete pCallbackInfo; + }, + (void*)pCallbackInfo, + &pCallbackInfo->asyncWork_); + + napi_queue_async_work(env, pCallbackInfo->asyncWork_); + return promise; +} + +napi_value GetWindows(napi_env env, napi_callback_info info) { + HILOG_INFO("GetWindows called"); + size_t argc = ARGS_SIZE_ONE; + napi_value argv; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr)); + NAPI_ASSERT(env, argc <= ARGS_SIZE_ONE, "Requires up to 1 argument."); + + AsyncGetWindowsCallbackInfo* pCallbackInfo = new AsyncGetWindowsCallbackInfo(); + pCallbackInfo->env_ = env; + + napi_value promise = nullptr; + + if (argc == ARGS_SIZE_ONE) { + // Callback mode + HILOG_INFO("GetWindows callback mode"); + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv, &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "Wrong argument type. Function expected."); + napi_create_reference(env, argv, 1, &pCallbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + // Promise mode + HILOG_INFO("GetWindows promise mode"); + napi_create_promise(env, &pCallbackInfo->deferred_, &promise); + } + + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetWindows", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { + HILOG_DEBUG("GetWindows execute"); + AsyncGetWindowsCallbackInfo* pCallbackInfo = (AsyncGetWindowsCallbackInfo*)data; + pCallbackInfo->accessibilityWindows_ = Accessibility::AccessibleAbility::GetInstance().GetWindows(); + }, + [](napi_env env, napi_status status, void* data) { + HILOG_DEBUG("GetWindows execute back"); + AsyncGetWindowsCallbackInfo* pCallbackInfo = (AsyncGetWindowsCallbackInfo*)data; + napi_value result[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_value callResult = 0; + napi_get_undefined(env, &undefined); + + if (!pCallbackInfo->accessibilityWindows_.empty()) { + HILOG_DEBUG("GetWindows accessibilityWindows is not null"); + napi_create_array(env, &result[PARAM1]); + ConvertAccessibilityWindowInfosToJS(env, result[PARAM1], pCallbackInfo->accessibilityWindows_); + } else { + HILOG_DEBUG("GetWindows accessibilityWindows is null"); + napi_get_undefined(env, &result[PARAM1]); + } + + if (pCallbackInfo->callback_) { + // Callback mode + result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, pCallbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &callResult); + napi_delete_reference(env, pCallbackInfo->callback_); + } else { + // Promise mode + napi_resolve_deferred(env, pCallbackInfo->deferred_, result[PARAM1]); + } + + napi_delete_async_work(env, pCallbackInfo->asyncWork_); + delete pCallbackInfo; + }, + (void*)pCallbackInfo, + &pCallbackInfo->asyncWork_); + + napi_queue_async_work(env, pCallbackInfo->asyncWork_); + return promise; +} + +napi_value GetRootElementInfo(napi_env env, napi_callback_info info) { + HILOG_INFO("GetRootElementInfo called"); + size_t argc = ARGS_SIZE_ONE; + napi_value argv; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr)); + NAPI_ASSERT(env, argc <= ARGS_SIZE_ONE, "Requires up to 1 argument."); + + AsyncGetRootElementInfoCallbackInfo* pCallbackInfo = new AsyncGetRootElementInfoCallbackInfo(); + pCallbackInfo->env_ = env; + + napi_value promise = nullptr; + + if (argc == ARGS_SIZE_ONE) { + // Callback mode + HILOG_INFO("GetRootElementInfo callback mode"); + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv, &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "Wrong argument type. Function expected."); + napi_create_reference(env, argv, 1, &pCallbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + // Promise mode + HILOG_INFO("GetRootElementInfo promise mode"); + napi_create_promise(env, &pCallbackInfo->deferred_, &promise); + } + + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetRootElementInfo", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { + HILOG_DEBUG("GetRootElementInfo execute"); + AsyncGetRootElementInfoCallbackInfo* pCallbackInfo = (AsyncGetRootElementInfoCallbackInfo*)data; + pCallbackInfo->result_ = AccessibleAbility::GetInstance().GetRootElementInfo(pCallbackInfo->elementInfo_); + }, + [](napi_env env, napi_status status, void* data) { + HILOG_DEBUG("GetRootElementInfo execute back"); + AsyncGetRootElementInfoCallbackInfo* pCallbackInfo = (AsyncGetRootElementInfoCallbackInfo*)data; + napi_value jsReturnValue = 0; + napi_value argv[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(env, &undefined); + + if (pCallbackInfo->elementInfo_.has_value()) { + HILOG_DEBUG("GetRootElementInfo elementInfo is not null"); + napi_new_instance(env, NElementInfo::cons_, 0, nullptr, &argv[PARAM1]); + ConvertElementInfoToJS(env, argv[PARAM1], *(pCallbackInfo->elementInfo_)); + } else { + HILOG_DEBUG("GetRootElementInfo elementInfo is null"); + napi_get_undefined(env, &argv[PARAM1]); + } + + argv[PARAM0] = GetErrorValue(env, pCallbackInfo->result_ ? CODE_SUCCESS : CODE_FAILED); + if (pCallbackInfo->callback_) { + // Callback mode + napi_get_reference_value(env, pCallbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, argv, &jsReturnValue); + napi_delete_reference(env, pCallbackInfo->callback_); + } else { + // Promise mode + if (pCallbackInfo->result_) { + napi_resolve_deferred(env, pCallbackInfo->deferred_, argv[PARAM1]); + } else { + napi_reject_deferred(env, pCallbackInfo->deferred_, argv[PARAM0]); + } + } + + napi_delete_async_work(env, pCallbackInfo->asyncWork_); + delete pCallbackInfo; + }, + (void*)pCallbackInfo, + &pCallbackInfo->asyncWork_); + + napi_queue_async_work(env, pCallbackInfo->asyncWork_); + return promise; +} + +napi_value ConnectToAAMS(napi_env env, napi_callback_info info) { + HILOG_INFO("ConnectToAAMS called"); + + AccessibleAbility& aa = AccessibleAbility::GetInstance(); + aa.RegisterListener(g_AAObserver); + aa.ConnectToAAMS(); + + napi_value ret = nullptr; + napi_get_undefined(env, &ret); + return ret; +} + +napi_value GetFocusElementInfo(napi_env env, napi_callback_info info) { + HILOG_INFO("GetFocusElementInfo called"); + size_t expectedArgsCount = ARGS_SIZE_TWO; + size_t argc = expectedArgsCount; + napi_value argv[ARGS_SIZE_TWO] = {0}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + NAPI_ASSERT(env, argc <= expectedArgsCount, "Requires at most 2 arguments."); + std::string focusType; + ParseString(env, focusType, argv[PARAM0]); + HILOG_INFO("GetFocusElementInfo focusType = %{public}s", focusType.c_str()); + + AsyncGetFocusElementInfoCallbackInfo* pCallbackInfo = new AsyncGetFocusElementInfoCallbackInfo(); + pCallbackInfo->env_ = env; + pCallbackInfo->focusType_ = focusType; + + napi_value promise = nullptr; + + if (argc > (expectedArgsCount - CALLBACK_SIZE)) { + // Callback mode + HILOG_INFO("GetFocusElementInfo callback mode"); + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "Wrong argument type. Function expected."); + napi_create_reference(env, argv[PARAM1], 1, &pCallbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + // Promise mode + HILOG_INFO("GetFocusElementInfo promise mode"); + napi_create_promise(env, &pCallbackInfo->deferred_, &promise); + } + + napi_value resource = nullptr; + napi_create_string_utf8(env, "GetFocusElementInfo", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { + HILOG_DEBUG("GetFocusElementInfo execute"); + AsyncGetFocusElementInfoCallbackInfo* pCallbackInfo = (AsyncGetFocusElementInfoCallbackInfo*)data; + uint32_t focus = 0; + if (std::strcmp(pCallbackInfo->focusType_.c_str(), "accessibility") == 0) { + focus = FOCUS_TYPE_ACCESSIBILITY; + } else if (std::strcmp(pCallbackInfo->focusType_.c_str(), "normal") == 0) { + focus = FOCUS_TYPE_INPUT; + } else { + focus = FOCUS_TYPE_INVALID; + } + pCallbackInfo->result_ = AccessibleAbility::GetInstance().GetFocusElementInfo( + focus, pCallbackInfo->elementInfo_); + }, + [](napi_env env, napi_status status, void* data) { + HILOG_DEBUG("GetFocusElementInfo execute back"); + AsyncGetFocusElementInfoCallbackInfo* pCallbackInfo = (AsyncGetFocusElementInfoCallbackInfo*)data; + napi_value result[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_value callResult = 0; + napi_get_undefined(env, &undefined); + + if (pCallbackInfo->elementInfo_.has_value()) { + HILOG_DEBUG("GetFocusElementInfo elementInfo is not null"); + napi_new_instance(env, NElementInfo::cons_, 0, nullptr, &result[PARAM1]); + ConvertElementInfoToJS(env, result[PARAM1], *(pCallbackInfo->elementInfo_)); + } else { + HILOG_DEBUG("GetFocusElementInfo elementInfo is null"); + napi_get_undefined(env, &result[PARAM1]); + } + + result[PARAM0] = GetErrorValue(env, pCallbackInfo->result_ ? CODE_SUCCESS : CODE_FAILED); + if (pCallbackInfo->callback_) { + // Callback mode + napi_get_reference_value(env, pCallbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &callResult); + napi_delete_reference(env, pCallbackInfo->callback_); + } else { + // Promise mode + if (pCallbackInfo->result_) { + napi_resolve_deferred(env, pCallbackInfo->deferred_, result[PARAM1]); + } else { + napi_reject_deferred(env, pCallbackInfo->deferred_, result[PARAM0]); + } + } + + napi_delete_async_work(env, pCallbackInfo->asyncWork_); + delete pCallbackInfo; + }, + (void*)pCallbackInfo, + &pCallbackInfo->asyncWork_); + + napi_queue_async_work(env, pCallbackInfo->asyncWork_); + return promise; +} + +napi_value PerformCommonAction(napi_env env, napi_callback_info info) { + HILOG_INFO("PerformCommonAction called"); + size_t expectedArgsCount = ARGS_SIZE_TWO; + size_t argc = expectedArgsCount; + napi_value argv[ARGS_SIZE_TWO] = {0}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + NAPI_ASSERT(env, argc <= expectedArgsCount, "Requires at most 2 arguments."); + std::string action; + ParseString(env, action, argv[PARAM0]); + HILOG_INFO("PerformCommonAction action = %{public}s", action.c_str()); + + AsyncPerformCommonActionCallbackInfo* pCallbackInfo = new AsyncPerformCommonActionCallbackInfo(); + pCallbackInfo->env_ = env; + pCallbackInfo->action_ = ConvertStringToGlobalAction(action); + + napi_value promise = nullptr; + + if (argc > (expectedArgsCount - CALLBACK_SIZE)) { + // Callback mode + HILOG_INFO("PerformCommonAction callback mode"); + napi_valuetype valueType = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valueType)); + NAPI_ASSERT(env, valueType == napi_function, "Wrong argument type. Function expected."); + napi_create_reference(env, argv[PARAM1], 1, &pCallbackInfo->callback_); + napi_get_undefined(env, &promise); + } else { + // Promise mode + HILOG_INFO("PerformCommonAction promise mode"); + napi_create_promise(env, &pCallbackInfo->deferred_, &promise); + } + + napi_value resource = nullptr; + napi_create_string_utf8(env, "PerformCommonAction", NAPI_AUTO_LENGTH, &resource); + + napi_create_async_work( + env, nullptr, resource, + [](napi_env env, void* data) { + HILOG_DEBUG("PerformCommonAction execute"); + AsyncPerformCommonActionCallbackInfo* pCallbackInfo = (AsyncPerformCommonActionCallbackInfo*)data; + pCallbackInfo->performActionResult_ = AccessibleAbility::GetInstance().PerformCommonAction(pCallbackInfo->action_); + HILOG_DEBUG("PerformCommonAction result is %{public}d!", pCallbackInfo->performActionResult_); + }, + [](napi_env env, napi_status status, void* data) { + HILOG_DEBUG("PerformCommonAction execute back"); + AsyncPerformCommonActionCallbackInfo* pCallbackInfo = (AsyncPerformCommonActionCallbackInfo*)data; + napi_value result[ARGS_SIZE_TWO] = {0}; + napi_value callback = 0; + napi_value undefined = 0; + napi_value callResult = 0; + napi_get_undefined(env, &undefined); + napi_get_boolean(env, pCallbackInfo->performActionResult_, &result[PARAM1]); + HILOG_DEBUG("PerformCommonAction result is %{public}d!", pCallbackInfo->performActionResult_); + + if (pCallbackInfo->callback_) { + // Callback mode + result[PARAM0] = GetErrorValue(env, CODE_SUCCESS); + napi_get_reference_value(env, pCallbackInfo->callback_, &callback); + napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, result, &callResult); + napi_delete_reference(env, pCallbackInfo->callback_); + } else { + // Promise mode + napi_resolve_deferred(env, pCallbackInfo->deferred_, result[PARAM1]); + } + + napi_delete_async_work(env, pCallbackInfo->asyncWork_); + delete pCallbackInfo; + }, + (void*)pCallbackInfo, + &pCallbackInfo->asyncWork_); + + napi_queue_async_work(env, pCallbackInfo->asyncWork_); + return promise; +} \ No newline at end of file diff --git a/interfaces/kits/napi/src/napi_accessible_ability_observer.cpp b/interfaces/kits/napi/src/napi_accessible_ability_observer.cpp new file mode 100644 index 00000000..7d1cbde3 --- /dev/null +++ b/interfaces/kits/napi/src/napi_accessible_ability_observer.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include +#include + +#include "hilog_wrapper.h" +#include "napi_accessible_ability_observer.h" +#include "napi_accessible_ability.h" +#include "napi_accessibility_event_info.h" +#include "napi_accessibility_utils.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +using namespace OHOS; +using namespace OHOS::Accessibility; + +extern std::map> g_JsAACallbacks; + +void AccessibleAbilityObserver::OnAccessibilityEvent(const AccessibilityEventInfo& eventInfo) { + HILOG_INFO("NAPI OnAccessibilityEvent called"); + if (!g_JsAACallbacks[STR_A11Y_OBSERVER_ACCESSIBILITY_EVENT]) { + HILOG_WARN("This callback is not registered by ability."); + return; + } + + std::shared_ptr callbackInfo = + g_JsAACallbacks[STR_A11Y_OBSERVER_ACCESSIBILITY_EVENT]; + napi_value result = 0; + napi_value callback = 0; + napi_value undefined = 0; + napi_value argv = 0; + napi_get_undefined(callbackInfo->env_, &undefined); + napi_new_instance(callbackInfo->env_, NAccessibilityEventInfo::cons_, 0, nullptr, &argv); + ConvertAccessibilityEventInfoToJS(callbackInfo->env_, argv, eventInfo); + napi_get_reference_value(callbackInfo->env_, callbackInfo->callback_, &callback); + napi_call_function(callbackInfo->env_, undefined, callback, ARGS_SIZE_ONE, &argv, &result); +} + +void AccessibleAbilityObserver::OnInterrupt() { + HILOG_INFO("NAPI OnInterrupt called"); + if (!g_JsAACallbacks[STR_A11Y_OBSERVER_INTERRUPT]) { + HILOG_WARN("This callback is not registered by ability."); + return; + } + + std::shared_ptr callbackInfo = g_JsAACallbacks[STR_A11Y_OBSERVER_INTERRUPT]; + napi_value result = 0; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(callbackInfo->env_, &undefined); + napi_get_reference_value(callbackInfo->env_, callbackInfo->callback_, &callback); + napi_call_function(callbackInfo->env_, undefined, callback, 0, nullptr, &result); +} + +void AccessibleAbilityObserver::OnAbilityConnected() { + HILOG_INFO("NAPI OnAbilityConnected called"); + if (!g_JsAACallbacks[STR_A11Y_OBSERVER_ABILITY_CONNECTED]) { + HILOG_WARN("This callback is not registered by ability."); + return; + } + + std::shared_ptr callbackInfo = g_JsAACallbacks[STR_A11Y_OBSERVER_ABILITY_CONNECTED]; + napi_value result = 0; + napi_value callback = 0; + napi_value undefined = 0; + napi_get_undefined(callbackInfo->env_, &undefined); + napi_get_reference_value(callbackInfo->env_, callbackInfo->callback_, &callback); + napi_call_function(callbackInfo->env_, undefined, callback, 0, nullptr, &result); +} + +void AccessibleAbilityObserver::OnGesture(uint32_t gestureId) { + HILOG_INFO("NAPI OnGesture called"); + if (!g_JsAACallbacks[STR_A11Y_OBSERVER_GESTURE]) { + HILOG_WARN("This callback is not registered by ability."); + return; + } + + std::shared_ptr callbackInfo = g_JsAACallbacks[STR_A11Y_OBSERVER_GESTURE]; + napi_value callback = 0; + napi_value undefined = 0; + napi_value result = 0; + napi_value callResult = 0; + napi_get_undefined(callbackInfo->env_, &undefined); + napi_create_uint32(callbackInfo->env_, gestureId, &result); + napi_get_reference_value(callbackInfo->env_, callbackInfo->callback_, &callback); + napi_call_function(callbackInfo->env_, undefined, callback, ARGS_SIZE_ONE, &result, &callResult); +} + +bool AccessibleAbilityObserver::OnKeyPressEvent(const OHOS::MMI::KeyEvent& keyEvent) { + HILOG_INFO("NAPI OnKeyPressEvent called"); + if (!g_JsAACallbacks[STR_A11Y_OBSERVER_KEY_PRESS]) { + HILOG_WARN("This callback is not registered by ability."); + return false; + } + return false; +} \ No newline at end of file diff --git a/interfaces/kits/napi/src/napi_tts.cpp b/interfaces/kits/napi/src/napi_tts.cpp new file mode 100644 index 00000000..08e1b690 --- /dev/null +++ b/interfaces/kits/napi/src/napi_tts.cpp @@ -0,0 +1,261 @@ +/* + * Copyright (c) 2021 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. + */ +#include +#include + +#include "hilog_wrapper.h" +#include "napi_tts.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +namespace OHOS { +napi_value NTTSClient::ttsClientCons_ = nullptr; +napi_env NTTSClient::env_ = nullptr; +napi_ref NTTSClient::onEventRef_ = nullptr; +napi_ref NTTSClient::onSpeechFinishedRef_ = nullptr; +sptr NTTSClient::listener_ = nullptr; + +void TtsObserver::OnEvent(int eventType) { + HILOG_INFO("%{public}s start, eventType[%{public}d]", __func__, eventType); + int argc = 2; + napi_value argv[2] = {0}; + napi_value fn; + napi_value undefined; + napi_value callResult; + + napi_create_int32(NTTSClient::env_, eventType, &argv[0]); + napi_create_int32(NTTSClient::env_, 1, &argv[1]); + napi_get_reference_value(NTTSClient::env_, NTTSClient::onEventRef_, &fn); + napi_get_undefined(NTTSClient::env_, &undefined); + napi_call_function(NTTSClient::env_, undefined, fn, argc, argv, &callResult); +} + +void TtsObserver::OnSpeechFinish(int utteranceId) { + HILOG_INFO("%{public}s start, utteranceId[%{public}d]", __func__, utteranceId); + int argc = 1; + napi_value argv; + napi_value fn; + napi_value undefined; + napi_value callResult; + + napi_create_int32(NTTSClient::env_, utteranceId, &argv); + napi_get_reference_value(NTTSClient::env_, NTTSClient::onSpeechFinishedRef_, &fn); + napi_get_undefined(NTTSClient::env_, &undefined); + napi_call_function(NTTSClient::env_, undefined, fn, argc, &argv, &callResult); +} + +void TtsObserver::OnSpeechStart(int utteranceId) { +} + +void TtsObserver::OnSpeechProgress(int utteranceId, int progress) { + +} + +static std::string GetStringFromNAPI(napi_env env, napi_value value) { + std::string result; + size_t size = 0; + + if (napi_get_value_string_utf8(env, value, nullptr, 0, &size) != napi_ok) { + HILOG_ERROR("can not get string size"); + return ""; + } + result.reserve(size + 1); + result.resize(size); + if (napi_get_value_string_utf8(env, value, result.data(), (size + 1), &size) != napi_ok) { + HILOG_ERROR("can not get string value"); + return ""; + } + return result; +} + +static bool ParseString(napi_env env, std::string ¶m, napi_value args) { + napi_status status; + napi_valuetype valuetype; + status = napi_typeof(env, args, &valuetype); + if (status != napi_ok) { + HILOG_INFO("napi_typeof error and status is %{public}d", status); + return false; + } + NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected."); + param = GetStringFromNAPI(env, args); + HILOG_INFO("param=%{public}s.", param.c_str()); + return true; +} + +static bool ParseInt32(napi_env env, int32_t ¶m, napi_value args) +{ + napi_status status; + napi_valuetype valuetype; + status = napi_typeof(env, args, &valuetype); + if (status != napi_ok) { + HILOG_INFO("napi_typeof error and status is %{public}d", status); + return false; + } + HILOG_INFO("param=%{public}d.", valuetype); + NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. int32 expected."); + napi_get_value_int32(env, args, ¶m); + return true; +} + +napi_value NTTSClient::Create(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + napi_value ret = nullptr; + size_t argc = 2; + napi_value argv[2] = {0}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + napi_value fnOnEvent; + napi_value fnOnSpeechFinished; + napi_get_named_property(env, argv[1], "onEvent", &fnOnEvent); + napi_create_reference(env, fnOnEvent, 1, &NTTSClient::onEventRef_); + napi_get_named_property(env, argv[1], "onSpeechFinish", &fnOnSpeechFinished); + napi_create_reference(env, fnOnSpeechFinished, 1, &NTTSClient::onSpeechFinishedRef_); + NTTSClient::listener_ = new TtsObserver(); + TtsFwk::TtsEngine::GetInstance().Create(NTTSClient::listener_); + return ret; +} + +napi_value NTTSClient::Release(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + napi_value ret = nullptr; + return ret; +} + +napi_value NTTSClient::InitTTS(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + napi_value ret = nullptr; + napi_get_boolean(env, true, &ret); + return ret; +} + +napi_value NTTSClient::SetParams(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + napi_value ret = nullptr; + napi_get_boolean(env, true, &ret); + return ret; +} + +napi_value NTTSClient::SetAudioType(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + napi_value ret = nullptr; + napi_get_boolean(env, true, &ret); + return ret; +} + +napi_value NTTSClient::SpeakText(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + napi_value ret = nullptr; + std::string text; + int utteranceId = 0; + size_t argc = 2; + napi_value argv[2] = {0}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + ParseString(env, text, argv[0]); + ParseInt32(env, utteranceId, argv[1]); + HILOG_INFO("%{public}s start, test[%{public}s], utteranceId[%{public}d]", __func__, text.c_str(), utteranceId); + TtsFwk::TtsEngine::GetInstance().SpeakText(text.c_str(), text.size(), utteranceId); + return ret; +} + +napi_value NTTSClient::StopSpeak(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + napi_value ret = nullptr; + TtsFwk::TtsEngine::GetInstance().StopSpeak(); + return ret; +} + +napi_value NTTSClient::Destroy(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + napi_value ret = nullptr; + TtsFwk::TtsEngine::GetInstance().Destroy(); + return ret; +} + +napi_value TtsClientConstructor(napi_env env, napi_callback_info info) { + napi_value jsthis = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr)); + return jsthis; +} + +void DefineJsTTSClient(napi_env env) { + napi_property_descriptor ttsDesc[] = { + DECLARE_NAPI_FUNCTION("create", NTTSClient::Create), + DECLARE_NAPI_FUNCTION("release", NTTSClient::Release), + DECLARE_NAPI_FUNCTION("init", NTTSClient::InitTTS), + DECLARE_NAPI_FUNCTION("setParams", NTTSClient::SetParams), + DECLARE_NAPI_FUNCTION("setAudioType", NTTSClient::SetAudioType), + DECLARE_NAPI_FUNCTION("speakText", NTTSClient::SpeakText), + DECLARE_NAPI_FUNCTION("stopSpeak", NTTSClient::StopSpeak), + DECLARE_NAPI_FUNCTION("destroy", NTTSClient::Destroy), + }; + + NAPI_CALL_RETURN_VOID(env, + napi_define_class(env, + "TtsClient", + NAPI_AUTO_LENGTH, + TtsClientConstructor, + nullptr, + sizeof(ttsDesc) / sizeof(ttsDesc[0]), + ttsDesc, + &NTTSClient::ttsClientCons_)); +} + +napi_value GetTTSClient(napi_env env, napi_callback_info info) { + HILOG_INFO("%{public}s start", __func__); + napi_value result; + napi_new_instance(env, NTTSClient::ttsClientCons_, 0, nullptr, &result); + return result; +} + +EXTERN_C_START +/* + * function for module exports + */ +static napi_value Init(napi_env env, napi_value exports) +{ + HILOG_INFO("%{public}s start", __func__); + napi_property_descriptor desc[] = { + DECLARE_NAPI_FUNCTION("getInstance", GetTTSClient), + }; + + NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); + + DefineJsTTSClient(env); + NTTSClient::env_ = env; + + HILOG_INFO("-----Init end------"); + return exports; +} +EXTERN_C_END + +/* + * Module define + */ +static napi_module _module = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "media", + .nm_priv = ((void *)0), + .reserved = {0} +}; +/* + * Module register function + */ +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module_register(&_module); +} +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/src/native_module.cpp b/interfaces/kits/napi/src/native_module.cpp new file mode 100644 index 00000000..edbe55c2 --- /dev/null +++ b/interfaces/kits/napi/src/native_module.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021 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. + */ +#include +#include +#include +#include + +#include "hilog_wrapper.h" +#include "napi_accessible_ability.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "napi_accessibility_system_ability_client.h" +#include "napi_accessibility_event_info.h" +#include "napi_accessibility_window_info.h" +#include "napi_accessibility_info.h" + +EXTERN_C_START +/* + * function for module exports + */ +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + DECLARE_NAPI_FUNCTION("getAccessibleAbility", GetAccessibleAbility), + DECLARE_NAPI_FUNCTION("isOpenAccessibility", IsOpenAccessibility), + DECLARE_NAPI_FUNCTION("isOpenTouchGuide", IsOpenTouchExploration), + DECLARE_NAPI_FUNCTION("getAbilityLists", GetAbilityList), + DECLARE_NAPI_FUNCTION("on", SubscribeState), + DECLARE_NAPI_FUNCTION("off", UnsubscribeState), + DECLARE_NAPI_FUNCTION("sendEvent", SendEvent), + }; + + NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); + + CreateGlobalAccessibleAbilityJSObject(env); + NElementInfo::DefineJSElementInfo(env); + NAccessibilityWindowInfo::DefineJSAccessibilityWindowInfo(env); + NAccessibilityEventInfo::DefineJSAccessibilityEventInfo(env); + NAPI_CALL(env, napi_set_named_property(env, exports, "EventInfo", NAccessibilityEventInfo::cons_)); + + HILOG_INFO("-----Init end------"); + return exports; +} +EXTERN_C_END + +/* + * Module define + */ +static napi_module _module = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "accessibility", + .nm_priv = ((void *)0), + .reserved = {0} +}; +/* + * Module register function + */ +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module_register(&_module); +} diff --git a/ohos.build b/ohos.build new file mode 100644 index 00000000..c36c70a0 --- /dev/null +++ b/ohos.build @@ -0,0 +1,54 @@ +{ + "subsystem": "accessibility", + "parts": { + "accessibility_standard": { + "module_list": [ + "//base/accessibility/services/aams:accessibleabilityms", + "//base/accessibility/frameworks/aafwk:accessibleability", + "//base/accessibility/interfaces/innerkits/asacfwk:accessibilityclient", + "//base/accessibility/test/resource/native_application:aams_system_test_app", + "//base/accessibility/interfaces/kits/napi:accessibility", + "//base/accessibility/sa_profile:aams_sa_profile", + "//base/accessibility/interfaces/kits/napi:tts" + ], + "inner_kits": [ + { + "type": "so", + "name": "//base/accessibility/frameworks/aafwk:accessibleability", + "header": { + "header_files": [ + "accessible_ability_client_interface.h", + "accessible_ability_client_proxy.h", + "accessible_ability_client_stub.h", + "accessible_ability_client_stub_impl.h", + "accessible_ability_event_handler.h", + "accessible_ability.h", + "accessible_ability_listener.h", + "display_resize_controller.h", + "fingerprint_controller.h" + ], + "header_base": "//base/accessibility/frameworks/aafwk/include" + } + }, + { + "type": "so", + "name": "//base/accessibility/interfaces/innerkits/asacfwk:accessibilityclient", + "header": { + "header_files": [ + "accessibility_event_info.h", + "accessibility_element_info.h", + "accessibility_state_event.h", + "accessibility_system_ability_client.h", + "accessibility_ability_info.h", + "accessibility_window_info.h" + ], + "header_base": "//base/accessibility/interfaces/innerkits/asacfwk/include" + } + } + ], + "test_list": [ + + ] + } + } +} diff --git a/sa_profile/4702.xml b/sa_profile/4702.xml new file mode 100644 index 00000000..37be78c0 --- /dev/null +++ b/sa_profile/4702.xml @@ -0,0 +1,27 @@ + + + + foundation + + 4702 + /system/lib64/libaccessibleabilityms.z.so + + + true + false + 1 + + diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn new file mode 100644 index 00000000..c0380756 --- /dev/null +++ b/sa_profile/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (c) 2021 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("//build/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("aams_sa_profile") { + sources = [ "4702.xml" ] + + part_name = "accessibility_standard" +} diff --git a/services/aams/BUILD.gn b/services/aams/BUILD.gn new file mode 100644 index 00000000..2c945bbf --- /dev/null +++ b/services/aams/BUILD.gn @@ -0,0 +1,97 @@ +# Copyright (C) 2021 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("//build/ohos.gni") +import("//base/accessibility/services/aams/accessibleabilityms.gni") + +ohos_prebuilt_etc("accessibility_service.rc") { + source = "etc/accessibility_service.rc" + relative_install_dir = "init" + part_name = "accessibility_standard" + subsystem_name = "accessibility" +} + +config("aams_service_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "//third_party/icu/icu4c/source/common", + "//base/accessibility/frameworks/asacfwk/include", + "//base/accessibility/interfaces/innerkits/asacfwk/include", + "//base/accessibility/frameworks/aafwk/include", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//base/accessibility/util/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/aafwk/standard/interfaces/innerkits/want/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//base/notification/ces_standard/interfaces/innerkits/native/include", + "//base/accessibility/dummyData", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//base/accessibility/common/log/include", + "//utils/system/safwk/native/include", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//utils/native/base/include", + "//base/powermgr/power_manager/interfaces/innerkits/native/include", + "//foundation/appexecfwk/standard/kits/appkit/native/app/include", + "//base/global/resmgr_standard/interfaces/innerkits/include", + ] + + defines = [ + "AAMS_LOG_TAG = \"accessibility\"", + "AAMS_LOG_DOMAIN = 0xD005200", + ] + + if (target_cpu == "arm") { + cflags = [ "-DBINDER_IPC_32BIT" ] + # cflags_cc = ["-frtti"] + } +} + +# remove_configs = [ "//build/config/compiler:no_rtti" ] + +ohos_shared_library("accessibleabilityms") { + install_enable = true + + sources = accessibleabilityms_files + + configs = [ + ":aams_service_config", + ] + + deps = [ + "//utils/native/base:utils", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", + "//base/accessibility/frameworks/aafwk:accessibleability", + "//base/accessibility/interfaces/innerkits/asacfwk:accessibilityclient", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//base/powermgr/power_manager/interfaces/innerkits:powermgr_client", + ] + + external_deps = [ + "ipc:ipc_core", + "hiviewdfx_hilog_native:libhilog", + "multimodalinput_base:libmmi-client", + "aafwk_standard:want", + "ces_standard:cesfwk_innerkits", + ] + + subsystem_name = "accessibility" + part_name = "accessibility_standard" +} diff --git a/services/aams/accessibleabilityms.gni b/services/aams/accessibleabilityms.gni new file mode 100644 index 00000000..b1daee00 --- /dev/null +++ b/services/aams/accessibleabilityms.gni @@ -0,0 +1,35 @@ +# Copyright (c) 2021 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("//base/accessibility/accessibility.gni") + +accessibleabilityms_files = [ + "${services_path}/aams/src/accessible_ability_connection.cpp", + "${services_path}/aams/src/accessible_ability_manager_service_event_handler.cpp", + "${services_path}/aams/src/accessible_ability_manager_service.cpp", + "${services_path}/aams/src/accessibility_account_data.cpp", + "${services_path}/aams/src/accessibility_interaction_connection.cpp", + "${services_path}/aams/src/accessibility_zoom_gesture.cpp", + "${services_path}/aams/src/accessibility_zoom_handler.cpp", + "${services_path}/aams/src/accessibility_common_event_registry.cpp", + "${services_path}/aams/src/accessibility_touch_guider.cpp", + "${services_path}/aams/src/accessibility_gesture_recognizer.cpp", + "${services_path}/aams/src/accessibility_event_transmission.cpp", + "${services_path}/aams/src/accessibility_input_filter.cpp", + "${services_path}/aams/src/accessibility_touchEvent_injector.cpp", + "${services_path}/aams/src/accessibility_keyevent_filter.cpp", + "${services_path}/aams/src/accessibility_window_manager.cpp", + "${services_path}/aams/src/accessibility_display_manager.cpp", + "${services_path}/aams/src/accessibility_interaction_bridge.cpp", + "//base/accessibility/dummyData/multimoduleDummy.cpp", +] diff --git a/services/aams/include/accessibility_account_data.h b/services/aams/include/accessibility_account_data.h new file mode 100644 index 00000000..d00f42a9 --- /dev/null +++ b/services/aams/include/accessibility_account_data.h @@ -0,0 +1,351 @@ +/* + * Copyright (C) 2021 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. + */ +#ifndef ACCESSIBILITY_ACCOUNT_DATA_H +#define ACCESSIBILITY_ACCOUNT_DATA_H + +#include +#include +#include +#include +#include "accessibility_interaction_connection.h" +#include "accessible_ability_connection.h" +#include "accessible_ability_manager_service_state_interface.h" +#include "element_name.h" +#include "refbase.h" +#include "accessibility_state_event.h" +#include "accessibility_system_ability_client.h" + +namespace OHOS { +namespace Accessibility { + +class AccessibleAbilityConnection; + +class IAccessibleAbilityManagerServiceState; + +class AccessibilityInteractionConnection; + +class AccessibilityAccountData final : public RefBase { +public: + AccessibilityAccountData(int accountId); + ~AccessibilityAccountData(); + + /** + * @brief Get the ID of the account. + * @param + * @return Returns accountId. + */ + int GetAccountId(); + + /** + * @brief Get Accessibility state. + * @param + * @return returns whether accessibility is connected and whether can touch browse. + */ + uint32_t GetAccessibilityState(); + + /** + * @brief Switch users and clear old user data. + * @param + * @return + */ + void OnAccountSwitched(); + + /** + * @brief Add connected accessibility services. + * @param connection Accessible ability connection. + * @return + */ + void AddConnectedAbility(sptr &connection); + + /** + * @brief Remove connected accessibility services. + * @param connection Accessible ability connection. + * @return + */ + void RemoveConnectedAbility(sptr &connection); + + /** + * @brief Accessibility services disconnected, accessibility changes from connected state to connecting state. + * @param connection Accessible ability connection. + * @return + */ + void AbilityDisconnected(sptr &connection); + + /** + * @brief Remove connecting accessibility services. + * @param elementName Accessibility corresponding elementName. + * @return + */ + void RemoveConnectingA11yAbility(const AppExecFwk::ElementName &elementName); + + /** + * @brief Add accessibility monitoring connection. + * @param callback Accessibility monitoring connection. + * @return + */ + void AddStateCallback(const sptr &callback); + + /** + * @brief Remove accessibility monitoring connection. + * @param callback Accessibility monitoring connection. + * @return + */ + void RemoveStateCallback(const wptr &callback); + + /** + * @brief Add interface operation interactive connection. + * @param windowId Interface operation interactive connection the corresponding window id. + * @param interactionConnection Interface interface operation interactive connection. + * @return + */ + void AddAccessibilityInteractionConnection(const int windowId, const sptr &interactionConnection); + + /** + * @brief Remove interface operation interactive connection. + * @param windowId Interface operation interactive connection the corresponding window id. + * @return + */ + void RemoveAccessibilityInteractionConnection(const int windowId); + + /** + * @brief Add connecting accessibility. + * @param elementName Accessibility corresponding elementName. + * @return + */ + void AddConnectingA11yAbility(const AppExecFwk::ElementName &elementName); + + void AddEnabledAbility(const AppExecFwk::ElementName &elementName); // For UT + + /** + * @brief Remove accessibility that have been opened. + * @param elementName Accessibility corresponding elementName. + * @return + */ + void RemoveEnabledAbility(const AppExecFwk::ElementName &elementName); + + void AddInstalledAbility(AccessibilityAbilityInfo &abilityInfo); // For UT + + /** + * @brief Empty installed accessibility list. + * @param abilityInfo Accessibility ability info. + * @return + */ + void RemoveInstalledAbility(AccessibilityAbilityInfo &abilityInfo); + + /** + * @brief The real procedure for add connecting ability. + * @param + * @return + */ + void ClearInstalledAbility(); + + /** + * @brief Get connected accessibility list. + * @param + * @return Store map of connected accessibility abilities. + */ + const std::map> GetConnectedA11yAbilities(); + + /** + * @brief Get accessibility listening connection list. + * @param + * @return Store vector of accessibility listening connection. + */ + const std::vector> GetStateCallbacks(); + + /** + * @brief Get interface operation interactive connection list. + * @param + * @return Store map of interface operation interactive connection. + */ + const std::map> GetAsacConnections(); + + /** + * @brief Query accessible ability connection through elementName URI. + * @param elementName Accessibility elementName URI + * @return Accessible ability connection corresponding to elementName URI. + */ + const sptr GetAccessibleAbilityConnection(const std::string elementName); + + /** + * @brief Query interface operation interactive connection through window id. + * @param windowId Interface operation interactive connection the corresponding window id. + * @return Interface operation interactive connection corresponding to window id. + */ + const sptr GetAccessibilityInteractionConnection(const int windowId); + + /** + * @brief Get connecting abilities list. + * @param + * @return Store map of connecting abilities. + */ + const std::map GetConnectingA11yAbilities(); + + /** + * @brief Get the accessibility ability info of the corresponding state according to the + * ability state type. + * @param state Ability state type. + * @return + */ + const std::vector GetAbilitiesByState(AbilityStateType state); + + /** + * @brief Get enable accessibility list. + * @param + * @return Store map of enable accessibility abilities. + */ + const std::map GetEnabledAbilities(); + + /** + * @brief Get install accessibility list. + * @param + * @return Store vector of install accessibility abilities. + */ + const std::vector GetInstalledAbilities(); + + /** + * @brief Get interactive Ui interval time. + * @param + * @return Interactive Ui interval time. + */ + uint32_t GetInteractiveUiInterval(); + + /** + * @brief Get noninteractive Ui interval time. + * @param + * @return NonInteractive Ui interval time. + */ + uint32_t GetNonInteractiveUiInterval(); + + /** + * @brief Gets the interactive Ui interval time set by the user. + * @param + * @return User set the Interactive Ui interval time. + */ + uint32_t GetAccountInteractiveUiInterval(); + + /** + * @brief Gets the noninteractive Ui interval time set by the user. + * @param + * @return User set the noninteractive Ui interval time. + */ + uint32_t GetAccountNonInteractiveUiInterval(); + + /** + * @brief Update interactive Ui interval time. + * @param + * @return + */ + void UpdateInteractiveUiInterval(); + + /** + * @brief Update user enabled accessibility capabilities. + * @param + * @return + */ + void UpdateAccountCapabilities(); + + /** + * @brief Read accessibility information in settings. + * @param + * @return Success return true, failed return false. + */ + bool ReadConfigurationForAccountData(); + + /** + * @brief Get flag with whether have zoom capability. + * @param + * @return isScreenMagnification_. + */ + bool GetScreenMagnificationFlag() {return isScreenMagnification_;} + + /** + * @brief Get flag with whether have touch guide capability. + * @param + * @return isEventTouchGuideState_. + */ + bool GetEventTouchGuideStateFlag() {return isEventTouchGuideState_;} + + /** + * @brief Get flag with whether have key event observer capability. + * @param + * @return isFilteringKeyEvents_. + */ + bool GetFilteringKeyEventsFlag() {return isFilteringKeyEvents_;} + + /** + * @brief Get flag with whether have gesture capability. + * @param + * @return isGesturesSimulation_. + */ + bool GetGesturesSimulationFlag() {return isGesturesSimulation_;} + +private: + /** + * @brief Update connected accessibility whether have touch guide capability. + * Have touch guide capability isEventTouchGuideState_ is true, + * otherwise isEventTouchGuideState_ is false. + * @param + * @return + */ + void UpdateEventTouchGuideCapability(); + + /** + * @brief Update connected accessibility whether have gesture capability. + * Have gesture capability isGesturesSimulation_ is true, + * otherwise isGesturesSimulation_ is false. + * @param + * @return + */ + void UpdateGesturesSimulationCapability(); + + /** + * @brief Update connected accessibility whether have key event observer capability. + * Have key event observer capability isFilteringKeyEvents_ is true, + * otherwise isFilteringKeyEvents_ is false. + * @param + * @return + */ + void UpdateFilteringKeyEventsCapability(); + + /** + * @brief Update connected accessibility whether have zoom capability. + * Have zoom capability isScreenMagnification_ is true, + * otherwise isScreenMagnification_ is false. + * @param + * @return + */ + void UpdateMagnificationCapability(); + + int id_; + uint32_t interactiveUiInterval_ = 0; + uint32_t nonInteractiveUiInterval_ = 0; + uint32_t accountInteractiveUiInterval_ = 0; + uint32_t accountNonInteractiveUiInterval_ = 0; + bool isEventTouchGuideState_ = false; + bool isScreenMagnification_ = false; + bool isFilteringKeyEvents_ = false; + bool isGesturesSimulation_ = false; + std::map> connectedA11yAbilities_ {}; // key: The URI of the ElementName. + std::vector> stateCallbacks_ {}; + std::map> asacConnections_ {}; // key: windowId + std::vector installedAbilities_ {}; + std::map enabledAbilities_ {}; // key: The URI of the ElementName. + std::map connectingA11yAbilities_ {}; // key: The URI of the ElementName. +}; +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBILITY_ACCOUNT_DATA_H \ No newline at end of file diff --git a/services/aams/include/accessibility_common_event_registry.h b/services/aams/include/accessibility_common_event_registry.h new file mode 100644 index 00000000..3da2cbf7 --- /dev/null +++ b/services/aams/include/accessibility_common_event_registry.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_COMMON_EVENT_REGISTRY_H +#define ACCESSIBILITY_COMMON_EVENT_REGISTRY_H + +#include +#include +#include +#include +#include "want.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "bundlemgr/bundle_mgr_interface.h" + +using EventHandle = std::function; + +namespace OHOS { +namespace Accessibility { + +class AccessibilityCommonEventSubscriber : public EventFwk::CommonEventSubscriber { +public: + AccessibilityCommonEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo, + const std::map &handles) + : CommonEventSubscriber(subscriberInfo), eventHandles_(handles) {} + + ~AccessibilityCommonEventSubscriber() = default; + + void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + +private: + void HandleEvent(const AAFwk::Want &want); + const std::map &eventHandles_; +}; + +class AccessibilityCommonEventRegistry { +public: + AccessibilityCommonEventRegistry(); + ~AccessibilityCommonEventRegistry() = default; + + bool StartRegister(); + void UnRegister(); + +private: + bool RegisterSubscriber(); + + void HandleSwitchedUser(const AAFwk::Want &want) const; + void HandleUnlockedUser(const AAFwk::Want &want) const; + void HandleRemovedUser(const AAFwk::Want &want) const; + void HandlePresentUser(const AAFwk::Want &want) const; + + void HandlePackageRemoved(const AAFwk::Want &want) const; + void HandlePackageUpdateFinished(const AAFwk::Want &want) const; + void HandlePackageChanged(const AAFwk::Want &want) const; + + typedef void (AccessibilityCommonEventRegistry::*HandleEventFunc)(const AAFwk::Want&) const; + std::map handleEventFunc_; + std::shared_ptr accessibilityCommonEventSubscriber_; + std::map eventHandles_; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBILITY_COMMON_EVENT_REGISTRY_H \ No newline at end of file diff --git a/services/aams/include/accessibility_display_manager.h b/services/aams/include/accessibility_display_manager.h new file mode 100644 index 00000000..6d5dc1f0 --- /dev/null +++ b/services/aams/include/accessibility_display_manager.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_DISPLAY_MANAGER_H +#define ACCESSIBILITY_DISPLAY_MANAGER_H + +#include +#include +#include "dummy.h" + +namespace OHOS { +namespace Accessibility { +class AccessibilityDisplayManager: public IWindowManagerDisplayListenerClazz { +public: + ~AccessibilityDisplayManager() = default; + + static AccessibilityDisplayManager &GetInstance(); + WMDisplayInfo GetDisplay(int id); + std::vector GetDisplays(); + WMDisplayInfo GetDefaultDisplay(); + void RegisterDisplayChangeListener(); + + // add for UT test + void SetDisplay(WMDisplayInfo newWM); + + virtual void OnScreenPlugin(int32_t did) override; + virtual void OnScreenPlugout(int32_t did) override; + +private: + AccessibilityDisplayManager(); + std::vector displays_ {}; +}; +} // namespace Accessibility +} // namespace OHOS +#endif // ACCESSIBILITY_DISPLAY_MANAGER_H \ No newline at end of file diff --git a/services/aams/include/accessibility_event_transmission.h b/services/aams/include/accessibility_event_transmission.h new file mode 100644 index 00000000..d8a1f5f2 --- /dev/null +++ b/services/aams/include/accessibility_event_transmission.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef OHOS_EVENT_TRANSMISSION_H_ +#define OHOS_EVENT_TRANSMISSION_H_ + +#include + +#include "key_event.h" +#include "mouse_event.h" +#include "touch_event.h" +#include "refbase.h" + +#include "accessibility_event_info.h" + +namespace OHOS { +namespace Accessibility{ + +class EventTransmission : public RefBase { +public: + EventTransmission() {}; + virtual ~EventTransmission() {}; + virtual void OnTouchEvent(TouchEvent &event); + virtual void OnMouseEvent(MouseEvent &event); + virtual void OnKeyEvent(MMI::KeyEvent &event); + virtual void OnAccessibilityEvent(AccessibilityEventInfo &event); + void SetNext(const sptr &next); + sptr GetNext(); + virtual void ClearEvents(uint32_t inputSource); + virtual void DestroyEvents(); +private: + sptr next_ = nullptr; +}; +} // namespace Accessibility +} // namespace OHOS + +#endif // OHOS_EVENT_TRANSMISSION_H_ \ No newline at end of file diff --git a/services/aams/include/accessibility_gesture_recognizer.h b/services/aams/include/accessibility_gesture_recognizer.h new file mode 100644 index 00000000..07c5625e --- /dev/null +++ b/services/aams/include/accessibility_gesture_recognizer.h @@ -0,0 +1,347 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef ACCESSIBILITYGESTURERECOGNIZER_H +#define ACCESSIBILITYGESTURERECOGNIZER_H + +#include +#include +#include "touch_event.h" +#include "singleton.h" +#include "event_handler.h" +#include "event_runner.h" +#include "hilog_wrapper.h" +#include "accessible_ability.h" +#include "accessibility_display_manager.h" +#include "accessible_ability_manager_service.h" + +namespace OHOS { +namespace Accessibility { + +#define GESTURE_STARTED_TIME_THRESHOLD 300 +#define GESTURE_NOT_STARTED_TIME_THRESHOLD 150 +#define DOUBLE_TAP_SLOP 100 +#define MIN_DOUBLE_TAP_TIME 40 +#define DOUBLE_TAP_TIMEOUT 300 +#define LONG_PRESS_TIMEOUT 400 +#define DEGREES_THRESHOLD 0.0 +#define DIRECTION_NUM 4 +#define CALCULATION_DIMENSION(xdpi) ((xdpi) * (1.0f / 25.4f) * 10) +#define MIN_PIXELS(xyDpi) ((xyDpi) * 0.1f) + +struct Pointer { + float px_; + float py_; +}; + +class AccessibilityGestureRecognizer; +class GestureHandler : public AppExecFwk::EventHandler { +public: + GestureHandler(const std::shared_ptr &runner, AccessibilityGestureRecognizer &server); + virtual ~GestureHandler() = default; + /** + * @brief Process the event of install system bundles. + * @param event Indicates the event to be processed. + * @return + */ + virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; +private: + AccessibilityGestureRecognizer &server_; +}; + +class AccessibilityGestureRecognizeListener{ +public: + /** + * @brief A destructor used to delete the listener instance. + * @param + * @return + */ + virtual ~AccessibilityGestureRecognizeListener() = default; + + /** + * @brief The callback function when performed a double tap and then held down the second tap. + * @param event the touch event received. + * @return + */ + virtual void OnDoubleTapLongPress(TouchEvent &event); + + /** + * @brief The callback function when lifted the finger on the second tap of a double tap. + * + * @param event the touch event received. + * @return true if the event is consumed, else false + */ + virtual bool OnDoubleTap(TouchEvent &event); + + /** + * @brief The callback function when recognized an event stream as a gesture. + * @param + * @return true if the event is consumed, else false + */ + virtual bool OnStarted(); + + /** + * @brief The callback function when decided the event stream is a gesture. + * @param gestureId the recognized gesture ID. + * @return true if the event is consumed, else false + */ + virtual bool OnCompleted(int gestureId); + + /** + * @brief The callback function when decided an event stream doesn't match any known gesture. + * @param event the touch event received. + * @return true if the event is consumed, else false + */ + virtual bool OnCancelled(TouchEvent &event); +}; + +class AccessibilityGestureRecognizer : public AppExecFwk::EventHandler{ +public: + /** + * @brief A constructor used to create a accessibilityGestureRecognizer instance. + * @param + * @return + */ + AccessibilityGestureRecognizer(); + + /** + * @brief A destructor used to delete the accessibilityGestureRecognizer instance. + * @param + * @return + */ + ~AccessibilityGestureRecognizer() {} + + /** + * @brief Register GestureRecognizeListener. + * @param listener the listener from touchguide + * @return + */ + void registerListener(AccessibilityGestureRecognizeListener *listener); + + /** + * @brief Register GestureRecognizeListener. + * @param listener the listener from touchguide + * @return + */ + void UnregisterListener(AccessibilityGestureRecognizeListener *listener); + + /** + * @brief Determine whether a single tap has occurred. + * @param + * @return true if a single tap has occurred, else false. + */ + bool IsfirstTap() { + return isFirstTapUp_; + } + + /** + * @brief Handle a touch event. If an action is completed, the appropriate callback is called. + * + * @param event the touch event to be handled. + * @param rawEvent The raw touch event. + * @return true if the gesture be recognized, else false + */ + bool OnTouchEvent(TouchEvent &event); + + /** + * @brief Clear state. + * @param + * @return + */ + void Clear(); + + /** + * @brief If a double tap occurred, call OnDoubleTapLongPress callback. + * @param event the touch event from touchguide + * @return + */ + void MaybeRecognizeLongPress(TouchEvent &event); + + /** + * @brief If a single tap completed. + * @param + * @return + */ + void SingleTapDetected(); + + /** + * @brief Set isLongpress_ flag; + * @param value set isLongpress_ flag + * @return + */ + void SetIsLongpress (bool value) { + isLongpress_ = value; + } + + /** + * @brief Get pCurDown_ ptr. + * @param + * @return + */ + std::shared_ptr GetCurDown() { + return pCurDown_; + } + + /** + * @brief Get continueDown_ flag. + * @param + * @return + */ + bool GetContinueDown() { + return continueDown_; + } + + static constexpr uint32_t LONG_PRESS_MSG = 1; + static constexpr uint32_t SINGLE_TAP_MSG = 2; + +private: + /** + * @brief Recognize the standard gesture. + * @param event the touch event from touchguide + * @return true if the standard gesture be recognized, else false + */ + bool StandardGestureRecognizer(TouchEvent &event); + + /** + * @brief A double tap has occurred, call OnDoubleTap callback. + * @param event the touch event from touchguide + * @return true if the DoubleTap be recognized, else false + */ + bool DoubleTapRecognized(TouchEvent &event); + + /** + * @brief Recognize gestures based on the sequence of motions. + * @param event the touch event from touchguide + * @return true if the Direction be recognized, else false + */ + bool recognizeDirectionGesture(TouchEvent &event); + + /** + * @brief Handle the down event from touchguide. + * @param event the touch event from touchguide + * @return + */ + void HandleTouchDownEvent(TouchEvent &event); + + /** + * @brief Handle the move event from touchguide. + * @param event the touch event from touchguide + * @return + */ + bool HandleTouchMoveEvent(TouchEvent &event); + + /** + * @brief Handle the up event from touchguide. + * @param event the touch event from touchguide + * @return + */ + bool HandleTouchUpEvent(TouchEvent &event); + + /** + * @brief Check if it's double tap. + * @param event the touch event from touchguide + * @return true if it's double tap, else false + */ + bool isDoubleTap(TouchEvent &event); + + /** + * @brief Cancel the gesture. + * @param + * @return + */ + void StandardGestureCancled(); + + /** + * @brief Get pointer path. + * @param route all pointer route + * @return the vector of PointerPath + */ + std::vector GetPointerPath(std::vector &route); + + /** + * @brief Get swipe direction. + * @param firstP the startpoint + * @param secondP the endpoint + * @return the type of swipe direction + */ + int GetSwipeDirection(Pointer firstP, Pointer secondP); + + static constexpr int SWIPE_UP = 0; + static constexpr int SWIPE_DOWN = 1; + static constexpr int SWIPE_LEFT = 2; + static constexpr int SWIPE_RIGHT = 3; + + static constexpr uint32_t GESTURE_DIRECTION[DIRECTION_NUM] = { + GestureTypes::GESTURE_SWIPE_UP, + GestureTypes::GESTURE_SWIPE_DOWN, + GestureTypes::GESTURE_SWIPE_LEFT, + GestureTypes::GESTURE_SWIPE_RIGHT + }; + + static constexpr uint32_t GESTURE_DIRECTION_TO_ID[DIRECTION_NUM][DIRECTION_NUM] = { + { + GestureTypes::GESTURE_SWIPE_UP, + GestureTypes::GESTURE_SWIPE_UP_THEN_DOWN, + GestureTypes::GESTURE_SWIPE_UP_THEN_LEFT, + GestureTypes::GESTURE_SWIPE_UP_THEN_RIGHT, + }, + { + GestureTypes::GESTURE_SWIPE_DOWN_THEN_UP, + GestureTypes::GESTURE_SWIPE_DOWN, + GestureTypes::GESTURE_SWIPE_DOWN_THEN_LEFT, + GestureTypes::GESTURE_SWIPE_DOWN_THEN_RIGHT, + + }, + { + GestureTypes::GESTURE_SWIPE_LEFT_THEN_UP, + GestureTypes::GESTURE_SWIPE_LEFT_THEN_DOWN, + GestureTypes::GESTURE_SWIPE_LEFT, + GestureTypes::GESTURE_SWIPE_LEFT_THEN_RIGHT, + + }, + { + GestureTypes::GESTURE_SWIPE_RIGHT_THEN_UP, + GestureTypes::GESTURE_SWIPE_RIGHT_THEN_DOWN, + GestureTypes::GESTURE_SWIPE_RIGHT_THEN_LEFT, + GestureTypes::GESTURE_SWIPE_RIGHT + } + }; + + bool continueDown_ = false; + bool isLongpress_ = false; + bool isDoubleTapdetecting_ = false; + bool isTapDown_ = false; + bool isFirstTapUp_ = false; + bool isDoubleTap_ = false; + bool isRecognizingGesture_ = false; + bool isGestureStarted_ = false; + unsigned int startTime_ = 0; + float xMinPixels_ = 0; + float yMinPixels_ = 0; + float threshold_ = 0; + int doubleTapScaledSlop_ = 0; + MmiPoint prePointer_ = {}; + MmiPoint startPointer_ = {}; + std::vector pointerRoute_{}; + AccessibilityGestureRecognizeListener *listener_; + std::unique_ptr pPreUp_ = nullptr; + std::shared_ptr pCurDown_ = nullptr; + std::shared_ptr handler_ = nullptr; + std::shared_ptr runner_ = nullptr; +}; +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBILITYGESTURERECOGNIZER_H \ No newline at end of file diff --git a/services/aams/include/accessibility_input_filter.h b/services/aams/include/accessibility_input_filter.h new file mode 100644 index 00000000..2ce5f8b0 --- /dev/null +++ b/services/aams/include/accessibility_input_filter.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2021 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. + */ +#ifndef ACCESSIBILITY_INPUT_FILTER_H +#define ACCESSIBILITY_INPUT_FILTER_H + +#include +#include +#include + +#include "dummy.h" +#include "multimoduleDummy.h" +#include "event_handler.h" + +#include "accessibility_event_transmission.h" + +namespace OHOS { +namespace Accessibility { + +class AccessibleAbilityManagerService; + +// Extended from input module +class AccessibilityInputFilter : public EventTransmission, public MultimodalInputFilter { +public: + // Feature flag for screen magnification. + const static uint32_t FEATURE_SCREEN_MAGNIFICATION = 0x00000001; + + // Feature flag for touch exploration. + const static uint32_t FEATURE_TOUCH_EXPLORATION = 0x00000002; + + // Feature flag for filtering key events. + const static uint32_t FEATURE_FILTER_KEY_EVENTS = 0x00000004; + + // Feature flag for inject touch events. + const static uint32_t FEATURE_INJECT_TOUCH_EVENTS = 0x00000008; + + AccessibilityInputFilter(); + ~AccessibilityInputFilter(); + + void OnInputEvent(MultimodalEvent &event) override; + void OnTouchEvent(TouchEvent &event) override; + void OnMouseEvent(MouseEvent &event) override; + void OnKeyEvent(MMI::KeyEvent &event) override; + // void OnAccessibilityEvent(AccessibilityEventInfo &event) override {}; // TBD + void SetUser(uint32_t userId); + void SetAvailableFunctions(uint32_t availableFunctions); + void NotifyAccessibilityEvent(AccessibilityEventInfo &event) const; + +private: + enum class EventType { + KEY = 0, + OTHER = 1, + }; + + void ProcessTouchEvent(TouchEvent &event); + void ProcessMouseEvent(MouseEvent &event); + void ProcessKeyEvent(MMI::KeyEvent &event); + void CreateTransmitters(); + void DestroyTransmitters(); + void SetNextEventTransmitter(sptr &header, sptr ¤t, + const sptr &next); + + std::shared_ptr ams_ = nullptr; + std::map> eventTransmitters_ {}; + uint32_t userId_ = 0; + uint32_t availableFunctions_ = 0; + std::shared_ptr eventHandler_ = nullptr; +}; + +} // namespace Accessibility +} // namespace OHOS +#endif // ACCESSIBILITY_INPUT_FILTER_H diff --git a/services/aams/include/accessibility_interaction_bridge.h b/services/aams/include/accessibility_interaction_bridge.h new file mode 100644 index 00000000..d29aa293 --- /dev/null +++ b/services/aams/include/accessibility_interaction_bridge.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2021 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. + */ +#ifndef ACCESSIBILITY_INTERACTION_BRIDGE_H +#define ACCESSIBILITY_INTERACTION_BRIDGE_H + +#include +#include "accessible_ability_manager_service.h" +#include "accessibility_element_info.h" +#include "accessibility_operator.h" +#include "accessibility_interaction_operation_interface.h" +#include "mmi_point.h" +namespace OHOS { +namespace Accessibility{ + +class AccessibilityInteractionBridge +{ +public: + /** + * @brief Get the instance of Interaction Bridge. + * @return Returns Static reference the instance of Interaction Bridge. + */ + static AccessibilityInteractionBridge &GetInstance(); + + /** + * @brief Focused Element Info from ACE. + * @return Returns Element Info. + */ + AccessibilityElementInfo FindFocusedElementInfo(); + + /** + * @brief Perform action on Accessibility Focus. + * @param action the action of Accessibility node. + * @return Returns true if the action perform successfully; returns false code otherwise. + */ + bool PerformActionOnAccessibilityFocusedItem(const ActionType &action); + bool GetAccessibilityFocusClickPointInScreen(MmiPoint &point); + ~AccessibilityInteractionBridge() = default; +private: + AccessibilityInteractionBridge(); + AccessibilityElementInfo FindFocusedElementInfo(const int &windowId); + std::shared_ptr aams_ = nullptr; + sptr accountData_ = nullptr; + sptr connection_ = nullptr; + sptr channel_ = nullptr; +}; +} // namespace Accessibility +} // namespace OHOS +#endif // ACCESSIBILITY_INTERACTION_BRIDGE_H \ No newline at end of file diff --git a/services/aams/include/accessibility_interaction_connection.h b/services/aams/include/accessibility_interaction_connection.h new file mode 100644 index 00000000..28ccf155 --- /dev/null +++ b/services/aams/include/accessibility_interaction_connection.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2021 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. + */ +#ifndef ACCESSIBILITY_INTERACTION_CONNECTION_H +#define ACCESSIBILITY_INTERACTION_CONNECTION_H +#include +#include "accessibility_interaction_operation_interface.h" + +namespace OHOS { +namespace Accessibility{ + +class AccessibilityInteractionConnection : public RefBase { +public: + AccessibilityInteractionConnection(const int windowId, const sptr &connection, + const int accountId); + ~AccessibilityInteractionConnection(); + + inline sptr GetProxy() {return proxy_;} + +private: + int windowId_; + int accountId_; + sptr proxy_; +}; + +} // namespace Accessibility +} // namespace OHOS +#endif // ACCESSIBILITY_INTERACTION_CONNECTION_H \ No newline at end of file diff --git a/services/aams/include/accessibility_keyevent_filter.h b/services/aams/include/accessibility_keyevent_filter.h new file mode 100644 index 00000000..b1e639aa --- /dev/null +++ b/services/aams/include/accessibility_keyevent_filter.h @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef OHOS_KEYEVENT_FILTER_H_ +#define OHOS_KEYEVENT_FILTER_H_ + +#include +#include +#include + +#include "accessibility_event_transmission.h" +#include "event_handler.h" + +namespace OHOS { +namespace Accessibility{ + +class AccessibleAbilityConnection; +class AccessibleAbilityManagerService; +class KeyEventFilterEventHandler; + +class KeyEventFilter : public EventTransmission { +public: + + struct ProcessingEvent { + std::shared_ptr event_; + uint32_t usedCount_; + uint32_t seqNum_; + }; + + /** + * @brief A constructor used to create a KeyEventFilter instance. + * @param + * @return + */ + KeyEventFilter(); + + /** + * @brief A destructor used to delete the KeyEventFilter instance. + * @param + * @return + */ + virtual ~KeyEventFilter(); + + /** + * @brief Handle key events from previous event stream node. + * @param event the key event from Multimodal + * @return + */ + void OnKeyEvent(MMI::KeyEvent &event) override; + + /** + * @brief Send key event to next stream node. + * @param event the key event prepared to send + * @return + */ + void SendEventToParent(MMI::KeyEvent &event); + + /** + * @brief Set AccessibleAbility keyevent result. + * @param connection the AccessibleAbility + * @param isHandled true if the AccessibleAbility can handle the event else false + * @param sequenceNum the sequence of keyevent + * @return + */ + void SetServiceOnKeyEventResult(AccessibleAbilityConnection &connection, bool isHandled, uint32_t sequenceNum); + + /** + * @brief Clear AccessibleAbility keyevents. + * @param connection the AccessibleAbility + * @return + */ + void ClearServiceKeyEvents(AccessibleAbilityConnection &connection); + + /** + * @brief Destroy the events. + * @param + * @return + */ + void DestroyEvents() override; + + /** + * @brief Remove the processing event. + * @param event the event be removed + * @return true if remove successfully else false + */ + bool RemoveProcessingEvent(std::shared_ptr event); + +private: + /** + * @brief Dispatch the keyevents. + * @param event the keyevent from Multimodal + * @return + */ + void DispatchKeyEvent(MMI::KeyEvent &event); + + /** + * @brief Find processing event. + * @param connection the corresponding AccessiblityAbility + * @param sequenceNum the squence of event + * @return the processing event + */ + std::shared_ptr FindProcessingEvent(AccessibleAbilityConnection &connection, + uint32_t sequenceNum); + + std::shared_ptr aams_ = nullptr; + std::map, std::vector>> eventMaps_ = {}; + std::shared_ptr timeouthandler_ = nullptr; + std::shared_ptr runner_ = nullptr; + uint32_t sequenceNum_ = 0; +}; + +class KeyEventFilterEventHandler : public AppExecFwk::EventHandler{ +public: + /** + * @brief A constructor used to create a KeyEventFilterEventHandler instance. + * @param + * @return + */ + KeyEventFilterEventHandler(const std::shared_ptr &runner, KeyEventFilter &keyEventFilter); + virtual ~KeyEventFilterEventHandler() = default; + + /** + * @brief Process the event of install system bundles. + * @param event Indicates the event to be processed. + * @return + */ + virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; + +private: + KeyEventFilter &keyEventFilter_; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // OHOS_KEYEVENT_FILTER_H_ \ No newline at end of file diff --git a/services/aams/include/accessibility_touchEvent_injector.h b/services/aams/include/accessibility_touchEvent_injector.h new file mode 100644 index 00000000..52f086d1 --- /dev/null +++ b/services/aams/include/accessibility_touchEvent_injector.h @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2021 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. + */ + + +#ifndef ACCESSIBILITY_TOUCHEVENT_INJECTOR_H +#define ACCESSIBILITY_TOUCHEVENT_INJECTOR_H + +#include +#include "touch_event.h" +#include "singleton.h" +#include "event_handler.h" +#include "event_runner.h" +#include "hilog_wrapper.h" +#include "gesture_simulation.h" +#include "accessibility_event_transmission.h" +#include "accessible_ability_manager_service.h" +#include "accessible_ability_client_interface.h" + +namespace OHOS { +namespace Accessibility { + +#define DOUBLE_TAP_MIN_TIME 50 +class AccessibleAbilityManagerService; + +struct SendEventArgs { + TouchEvent event_; + bool isLastEvent_; +}; + +class TouchEventInjector; +class TouchInjectHandler : public AppExecFwk::EventHandler { +public: + TouchInjectHandler(const std::shared_ptr &runner, TouchEventInjector &server); + virtual ~TouchInjectHandler() = default; + /** + * @brief Process the event of install system bundles. + * @param event Indicates the event to be processed. + * @return + */ + virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; +private: + TouchEventInjector &server_; +}; + +class TouchEventInjector : public EventTransmission, public AppExecFwk::EventHandler { +public: + /** + * @brief A constructor used to create a TouchEventInjector instance. + * @param + * @return + */ + TouchEventInjector(); + + /** + * @brief A destructor used to delete the TouchEventInjector instance. + * @param + * @return + */ + ~TouchEventInjector() {} + + /** + * @brief Handle touch events from previous event stream node. + * @param event the touch event from Multimodal + * @return + */ + void OnTouchEvent(TouchEvent &event) override; + + /** + * @brief Handle mouse events from previous event stream node. + * @param event the mouse event from Multimodal + * @return + */ + void OnMouseEvent(MouseEvent &event) override; + + /** + * @brief Clear event state from specific input source. + * @param inputSource the input source + * @return + */ + void ClearEvents(uint32_t inputSource) override; + + /** + * @brief Destroy event state. + * @param + * @return + */ + void DestroyEvents() override; + + /** + * @brief Inject simulated gestures. + * @param gesturePath the vector of gesture path + * @param service the corresponding AccessiblityAbility + * @param sequence the sequence of gesture + * @return + */ + void InjectEvents(const std::vector &gesturePath, + const sptr &service, int sequence ); + + /** + * @brief Send touch event to next stream node. + * @param event the touch event prepared to send + * @return + */ + void SendTouchEvent(TouchEvent &event); + + /** + * @brief Parsing inject simulated gestures. + * @param + * @return + */ + void InjectEventsInner(); + + /** + * @brief Get current gesture service. + * @param + * @return the corresponding AccessiblityAbility + */ + sptr GetCurrentGestureService() { + return currentGestureService_; + } + + /** + * @brief Get sequence of gesture. + * @param + * @return the sequence of gesture + */ + int GetSequence() { + return sequence_; + } + + + static constexpr uint32_t SEND_TOUCH_EVENT_MSG = 1; + static constexpr uint32_t INJECT_EVENT_MSG = 2; + +private: + + /** + * @brief Cancel the gesture. + * @param + * @return + */ + void CancelGesture(); + + /** + * @brief Cancel the injected events. + * @param + * @return + */ + void CancelInjectedEvents(); + + /** + * @brief Get taps events. + * @param + * @return + */ + void GetTapsEvents(long startTime); + + /** + * @brief Get move events. + * @param + * @return + */ + void GetMovesEvents(long startTime); + + /** + * @brief Get touchevents from gesturepath. + * @param + * @return + */ + void GetTouchEventsFromGesturePath(long startTime); + + /** + * @brief create touchevent. + * @param startTime the starttime of gesture + * @param occurredTime the occurredtime of event + * @param action the action of event + * @param point the endpoint of event + * @return the created touchevent + */ + TouchEvent obtainTouchEvent(long startTime, long occurredTime, + int action, MmiPoint point); + + /** + * @brief Get the number of milliseconds elapsed since the system was booted. + * @param + * @return the number of milliseconds elapsed since the system was booted + */ + long getSystemTime(); + + + + int sequence_ = -1; + bool isGestureUnderway_ = false; + bool isDestroyEvent_ = false; + std::vector gesturePath_; + sptr currentGestureService_ = nullptr; + std::shared_ptr handler_ = nullptr; + std::shared_ptr runner_ = nullptr; + std::vector injectedEvents_; +}; +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBILITY_TOUCHEVENT_INJECTOR_H \ No newline at end of file diff --git a/services/aams/include/accessibility_touch_guider.h b/services/aams/include/accessibility_touch_guider.h new file mode 100644 index 00000000..30a33006 --- /dev/null +++ b/services/aams/include/accessibility_touch_guider.h @@ -0,0 +1,458 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef ACCESSIBILITY_TOUCH_GUIDER_H +#define ACCESSIBILITY_TOUCH_GUIDER_H + +#include +#include "accessibility_element_info.h" +#include "accessibility_event_transmission.h" +#include "accessibility_gesture_recognizer.h" + +namespace OHOS { +namespace Accessibility { +class TouchGuider; +class AccessibleAbilityManagerService; +class AccessibilityGestureRecognizer; + +#define MAX_POINTER_COUNT 32 +#define EXIT_GESTURE_REC_TIMEOUT 2000 +#define MAX_DRAG_GESTURE_COSINE 0.525321989 +#define POINTER_COUNT_1 1 +#define POINTER_COUNT_2 2 +#define MINI_POINTER_DISTANCE_DIP 200 +#define DIVIDE_2(num) ((num) / 2) +#define INDEX_0 0 +#define INDEX_1 1 +#define INIT_POINT_ID -1 +#define INIT_MMIPOINT 0 + +/** + * @brief touch Guider state define + */ +enum class TouchGuideState : int { + TOUCH_GUIDING, + DRAGGING, + TRANSMITING, + GESTURE_RECOGNIZING +}; + +/** + * @brief Click location define + */ +enum ClickLocation : int { + CLICK_NONE, + CLICK_ACCESSIBILITY_FOCUS, + CLICK_LAST_TOUCH_GUIDE +}; + +/** + * @brief struct to record injected pointers. + */ +struct InjectedEventRecorder { + int downPointers; + int downPointerNum; + long lastDownTime; + std::shared_ptr lastHoverEvent; +}; + +/** + * @brief struct to record received pointers. + */ +struct ReceivedEventRecorder { + float pointerDownX[MAX_POINTER_COUNT]; + float pointerDownY[MAX_POINTER_COUNT]; + std::shared_ptr lastEvent; +}; + +class TGEventHandler : public AppExecFwk::EventHandler { +public: + TGEventHandler(const std::shared_ptr &runner, TouchGuider &tgServer); + virtual ~TGEventHandler() = default; + /** + * @brief Process the event of install system bundles. + * @param event Indicates the event to be processed. + * @return + */ + virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; +private: + /** + * @brief Send HoverEnter and HoverMove to Multimodal. + * @param + * @return + */ + void HoverEnterAndMoveRunner(); + + /** + * @brief Send HoverExit to Multimodal. + * @param + * @return + */ + void HoverExitRunner(); + TouchGuider &tgServer_; +}; + +class TouchGuider : public EventTransmission { +public: + /** + * @brief A constructor used to create a touchGuide instance. + * @param + * @return + */ + TouchGuider(); + + /** + * @brief A destructor used to delete the touchGuide instance. + * @param + * @return + */ + ~TouchGuider() {} + + /** + * @brief TouchGuide start up. + * @param + * @return + */ + void StartUp(); + + /** + * @brief Handle touch events from previous event stream node. + * + * @param event the touch event to be handled. + * @return + */ + void OnTouchEvent(TouchEvent &event) override; + + /** + * @brief Handle accessibility events from previous event stream node. + * + * @param event the accessibility event to be handled. + * @return + */ + void OnAccessibilityEvent(AccessibilityEventInfo &event) override; + + /** + * @brief Clear event state from specific input source. + * @param inputSource the input source. + * @return + */ + void ClearEvents(uint32_t inputSource) override; + + /** + * @brief Destroy event state. + * @param + * @return + */ + void DestroyEvents() override; + + /** + * @brief Send event to multimodal input. + * @param event the event prepared to send to Multimodal + * @param action the action of the event + * @return + */ + void SendEventToMultimodal(TouchEvent &event, int action); + + /** + * @brief Send accessibility event to specific AccessiblityAbility. + * @param eventType the type of the event + * @return + */ + void SendAccessibilityEventToAA(EventType eventType); + + /** + * @brief Get hover enter and move event. + * @param + * @return Returns motionEvent_ vector. + */ + std::vector getHoverEnterAndMoveEvent(); + + /** + * @brief Clear hover enter and move event. + * @param + * @return + */ + void ClearHoverEnterAndMoveEvent(); + + /** + * @brief Get last received event. + * @param + * @return Returns last event ptr. + */ + std::shared_ptr getLastReceivedEvent(); + + static constexpr uint32_t EXIT_GESTURE_REC_MSG = 0; + static constexpr uint32_t SEND_HOVER_ENTER_MOVE_MSG = 1; + static constexpr uint32_t SEND_HOVER_EXIT_MSG = 2; + static constexpr uint32_t SEND_TOUCH_INTERACTION_END_MSG = 3; + static constexpr uint32_t SEND_TOUCH_GUIDE_END_MSG = 4; + +private: + class TouchGuideListener : public AccessibilityGestureRecognizeListener{ + public: + /** + * @brief A constructor used to create a TouchGuideListener instance. + * @param + * @return + */ + explicit TouchGuideListener(TouchGuider &server) : server_(server) {}; + + /** + * @brief Prepare to send the event corresponding to the long press to the Multimodal. + * @param event the touch event from Multimodal + * @return + */ + void OnDoubleTapLongPress(TouchEvent &event) override; + + /** + * @brief Prepare to send the event corresponding to the single tap to the Multimodal. + * @param event the touch event from Multimodal + * @return + */ + bool OnDoubleTap(TouchEvent &event) override; + + /** + * @brief Send GESTURE_BEGIN to AccessiblityAbility. + * @param + * @return + */ + bool OnStarted() override; + + /** + * @brief Send GESTURE_END and TOUCH_END to AccessiblityAbility. + * @param gestureId the id of gesture + * @return + */ + bool OnCompleted(int gestureId) override; + + /** + * @brief The gesture has been cancelled. + * @param event the touch event from Multimodal + * @return + */ + bool OnCancelled(TouchEvent &event) override; + private: + + /** + * @brief Get the click position. + * @param outPoint the click point + * @return the click location + */ + int GetClickPosition(MmiPoint &outPoint); + + /** + * @brief Send the single tap events to the Multimodal. + * @param event the event prepared to send to Multimodal + * @param point the click point + * @return whether the message is successfully sent. + */ + bool TransformToSingleTap(TouchEvent &event, MmiPoint &point); + TouchGuider &server_; + }; + /** + * @brief Determine whether to clear the touchguide. + * @param + * @return + */ + void Clear(); + + /** + * @brief clear the touchguide. + * @param event the last event from Multimodal + * @return + */ + void Clear(TouchEvent &event); + + /** + * @brief Handle touch events on touchExploring state. + * @param event the touch event from Multimodal + * @return + */ + void HandleTouchGuidingState(TouchEvent &event); + + /** + * @brief Handle touch events on dragging state. + * @param event the touch event from Multimodal + * @return + */ + void HandleDraggingState(TouchEvent &event); + + /** + * @brief Handle touch events on transmiting state. + * @param event the touch event from Multimodal + * @return + */ + void HandleTransmitingState(TouchEvent &event); + + /** + * @brief Determine whether it is a drag gesture. + * @param event the touch event from Multimodal + * @return whether the dragGesture is accepted. + */ + bool IsDragGestureAccept(TouchEvent &event); + + /** + * @brief Get Angle Cos value. + * @param offsetX the X value + * @param offsetY the Y value + * @param isGetX whether is the Angle corresponding to the X axis + * @return Angle Cos value. + */ + float GetAngleCos(float offsetX, float offsetY, bool isGetX); + + /** + * @brief Get the info of injected event. + * @param event the event prepared to send to Multimodal + * @return + */ + void RecordInjectedEvent(TouchEvent &event); + + /** + * @brief Get the info of Received event. + * @param event event the touch event from Multimodal + * @return + */ + void RecordReceivedEvent(TouchEvent &event); + + /** + * @brief Clear received recorder info. + * @param + * @return + */ + void ClearReceivedEventRecorder(); + + /** + * @brief Clear Injected recorder info. + * @param + * @return + */ + void ClearInjectedEventRecorder(); + + /** + * @brief Send exit event to multimodal. + * @param + * @return + */ + void SendExitEvents(); + + /** + * @brief Send all down events to multimodal. + * @param event the event prepared to send to Multimodal + * @return + */ + void SendAllDownEvents(TouchEvent &event); + + /** + * @brief Send all up events to multimodal. + * @param event the event prepared to send to Multimodal + * @return + */ + void SendUpForAllInjectedEvent(TouchEvent &event); + + /** + * @brief Send exit message. + * @param + * @return + */ + void PostGestureRecognizeExit(); + + /** + * @brief Send enter and move message. + * @param event event the touch event from Multimodal + * @return + */ + void PostHoverEnterAndMove(TouchEvent &event); + + /** + * @brief Send exit message. + * @param + * @return + */ + void PostHoverExit(); + + /** + * @brief Send accessibility event message. + * @param innerEventID the id of inner event + * @return + */ + void PostAccessibilityEvent(uint32_t innerEventID); + + /** + * @brief Cancel message. + * @param innerEventID the id of inner event + * @return + */ + void CancelPostEvent(uint32_t innerEventID); + + /** + * @brief Cancel message if it has been sent. + * @param innerEventID the id of inner event + * @return + */ + void CancelPostEventIfNeed(uint32_t innerEventID); + + /** + * @brief Check whether it has been sending. + * @param innerEventID the id of inner event + * @return + */ + bool HasEventPending(uint32_t innerEventID); + + /** + * @brief Force send and remove event. + * @param innerEventID the id of inner event + * @param event event the touch event from Multimodal + * @return + */ + void ForceSendAndRemoveEvent(uint32_t innerEventID, TouchEvent &event); + + /** + * @brief Handle down events on touchExploring state. + * @param event event the touch event from Multimodal + * @return + */ + void HandleTouchGuidingStateInnerDown(TouchEvent &event); + + /** + * @brief Handle move events on touchExploring state. + * @param event event the touch event from Multimodal + * @return + */ + void HandleTouchGuidingStateInnerMove(TouchEvent &event); + + /** + * @brief Handle move events on dragging state. + * @param event event the touch event from Multimodal + * @return + */ + void HandleDraggingStateInnerMove(TouchEvent &event); + + int currentState_ = -1; + int longPressPointId_ = INIT_POINT_ID; + float longPressOffsetX_ = INIT_MMIPOINT; + float longPressOffsetY_ = INIT_MMIPOINT; + bool isTouchGuiding_ = false; + ReceivedEventRecorder receivedRecorder_ = {}; + InjectedEventRecorder injectedRecorder_ = {}; + std::vector motionEvent_{}; + AccessibilityGestureRecognizer gestureRecognizer_; + std::unique_ptr touchGuideListener_ = nullptr; + std::shared_ptr pAams_ = nullptr; + std::shared_ptr handler_ = nullptr; + std::shared_ptr runner_ = nullptr; +}; +} // namespace Accessibility +} // namespace OHOS +#endif // ACCESSIBILITY_TOUCH_GUIDER_H \ No newline at end of file diff --git a/services/aams/include/accessibility_window_manager.h b/services/aams/include/accessibility_window_manager.h new file mode 100644 index 00000000..5aa1ca11 --- /dev/null +++ b/services/aams/include/accessibility_window_manager.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_WINDOW_MANGER_H +#define ACCESSIBILITY_WINDOW_MANGER_H + +#include +#include +#include +#include "accessibility_window_info.h" +#include "dummy.h" + +namespace OHOS { +namespace Accessibility { +class AccessibilityWindowInfoManager: public IWindowChangeListenerClazz { +public: + ~AccessibilityWindowInfoManager() = default; + static AccessibilityWindowInfoManager &GetInstance(); + static AccessibilityWindowInfo CreateAccessibilityWindowInfo(GetWindowInfoResult &windowInfo); + int ConvertToRealWindowId(int windowId, int focusType); + void RegisterWindowChangeListener(); + void DeregisterWindowChangeListener(); + void SetActiveWindow(int windowId); + void SetAccessibilityFocusedWindow(int windowId); + void SetInputFocusedWindow(int windowId); + std::vector GetAccessibilityWindows(); + bool GetAccessibilityWindow(int windowId, AccessibilityWindowInfo &window); + bool IsValidWindow(int windowId); + + virtual void OnWindowCreate(int32_t wid) override; + virtual void OnWindowDestroy(int32_t wid) override; + + // test for ut to resize a window + void SetWindowSize(int windowId, Rect rect); + + std::map a11yWindows_ {}; + int activeWindowId_ = INVALID_WINDOW_ID; + int a11yFocusedWindowId_ = INVALID_WINDOW_ID; + int inputFocusedWindowId_ = 0; + + bool registerFlag_ = false; + +private: + AccessibilityWindowInfoManager() = default; + void OnWindowChanged(int windowId, bool add); +}; +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBILITY_WINDOW_MANGER_H \ No newline at end of file diff --git a/services/aams/include/accessibility_zoom_gesture.h b/services/aams/include/accessibility_zoom_gesture.h new file mode 100644 index 00000000..822d02bd --- /dev/null +++ b/services/aams/include/accessibility_zoom_gesture.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ZOOM_GESTURE_H +#define ACCESSIBILITY_ZOOM_GESTURE_H + +// #include "accessibility_gesture_recognizer.h" +#include "touch_event.h" +// #include "accessibility_zoom_mock.h" + +namespace OHOS { +namespace Accessibility { + +class AccessibilityZoomGesture { +public: + AccessibilityZoomGesture(); + ~AccessibilityZoomGesture(); + + /** + * @brief Is it a triple tip. + */ + bool Triple(TouchEvent &event); + void Up(); + void Clear(); + +private: + int distance_ = 0; + int timeout_ = 0; + int upCount_ = 0; + int downCount_ = 0; + TouchEvent lastDown_ {}; + + void Initialize(); + void Reset(const TouchEvent &event); + + /** + * @brief Is it a valid continuous DOWN event. + */ + bool ValidDown(TouchEvent &event); + + + /** + * @brief Gets the effective distance between two touch events + * set by the system. + */ + int GetSysDistance() const; + + /** + * @brief Gets the effective time interval between two touch events + * set by the system. + */ + int GetSysTimeout() const; +}; +} // namespace accessibility +} // namespace OHOS +#endif // ACCESSIBILITY_ZOOM_GESTURE_H diff --git a/services/aams/include/accessibility_zoom_handler.h b/services/aams/include/accessibility_zoom_handler.h new file mode 100644 index 00000000..96f1c7d3 --- /dev/null +++ b/services/aams/include/accessibility_zoom_handler.h @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ZOOM_HANDLER_H +#define ACCESSIBILITY_ZOOM_HANDLER_H + +#include +#include +// #include "accessibility_gesture_recognizer.h" +#include "accessibility_event_transmission.h" +#include "accessibility_zoom_proxy.h" +#include "accessibility_zoom_gesture.h" + +namespace OHOS { +namespace Accessibility { + +/** + * @brief Zoom state machine. + * When the magnifying function is turned on, it is in ReadyState. + * After the triple event, it will enter the ZoomInState. + * After another triple event, it will exit the magnifying state + * and enter the ReadyState again. + * In the amplification state, if the two fingers are pressed down, + * it will enter the SlidingState, and any finger will be lifted + * up to exit the SlidingState and enter the ZoomInState again. + * + * (ReadyState) + * | ^ + * Triple | | (Triple|Action_cancel|screen_off) + * V | + * (ZoomInState) + * | ^ + * Two fingers down | | Any finger up + * V | + * (SlidingState) + * + */ +enum ACCESSIBILITY_ZOOM_STATE { + READY_STATE, + ZOOMIN_STATE, + SLIDING_STATE +}; + +class ZoomObserver { +public: + ZoomObserver() {} + virtual ~ZoomObserver() {} + virtual void OnTransitionTo(const int state) {} + virtual void OnBack(TouchEvent &event) {} + virtual void OnZoomIn() {} + virtual void OnZoomOut() {} +}; + +class ZoomState { +public: + virtual void Enter() {} + virtual void Exit() {} + virtual void OnTouchEvent(TouchEvent &event) {} + std::vector observer_ {}; + +public: + void Register(ZoomObserver &observer) + { + observer_.push_back(observer); + } + void UnRegisterAll() + { + observer_.erase(observer_.begin(), observer_.end()); + } + +private: +}; + +/** + * @brief The event processing. + * + * @since 1.0 + * @version 1.0 + */ +class AccessibilityZoomHandler : public ZoomObserver, public EventTransmission { +public: + /** + * @brief A constructor used to create a zoom handler. + * + * @param proxy AccessibilityZoomProxy reference. + * @param displayId The Logical display id. + * @since 1.0 + * @version 1.0 + */ + explicit AccessibilityZoomHandler(int displayId); + + /** + * @brief A destructor used to delete the zoom handler. + * + * @since 1.0 + * @version 1.0 + */ + virtual ~AccessibilityZoomHandler(); + + /** + * @brief Callback function when handle a motion event. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnTouchEvent(TouchEvent &event) override; + //AccessibilityZoomProxy &GetProxy(); + +private: + + class ReadyState: public ZoomState { + public: + virtual void Enter() override; + virtual void Exit() override; + virtual void OnTouchEvent(TouchEvent &event) override; + private: + AccessibilityZoomGesture gesture_ {}; + }; + + /** + * Triple down. + */ + class ZoomInState: public ZoomState { + public: + virtual void Enter() override; + virtual void Exit() override; + virtual void OnTouchEvent(TouchEvent &event) override; + private: + AccessibilityZoomGesture gesture_ {}; + }; + + /** + * the two fingers are pressed down. + */ + class SlidingState: public ZoomState /*,public XXX.GestureRecognizeListener*/ { + public: + virtual void Enter() override; + virtual void Exit() override; + virtual void OnTouchEvent(TouchEvent &event) override; + virtual bool OnScroll( /*TouchEvent first, TouchEvent second, float distanceX, float distanceY*/ ); // override; + virtual bool OnScale(); // override; + }; + + ZoomState currentState_ {}; + + ReadyState readyState_ {}; + ZoomInState zoomInState_ {}; + SlidingState slidingState_ {}; + + std::recursive_mutex stateMutex_ {}; + + int displayId_ = 0; + + // AccessibilityZoomProxy zoomProxy_ {}; + + void Initialize(); + + // void HandleEvent(TouchEvent &event); + void OnBack(TouchEvent &event) override; + + void OnTransitionTo(const int state) override; + + void OnZoomIn() override; + void OnZoomOut() override; + + // 屏幕关闭会结束放大. 需要监听屏幕事件. + /* + class AccessibilityScreenListener : public *** { + public: + void onScreenTurnedOff(); + } + */ +}; +} // namespace accessibility +} // namespace OHOS +#endif // ACCESSIBILITY_ZOOM_HANDLER_H diff --git a/services/aams/include/accessibility_zoom_mock.h b/services/aams/include/accessibility_zoom_mock.h new file mode 100644 index 00000000..884344d0 --- /dev/null +++ b/services/aams/include/accessibility_zoom_mock.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ZOOM_MOCK_H +#define ACCESSIBILITY_ZOOM_MOCK_H + +#include "accessibility_element_info.h" + +namespace OHOS { +namespace Accessibility { +/* +struct TouchEvent { + int getActionMasked() { return 0; } + int time; + float x; + float y; +}; + +enum TYPE_ACTION { + ACTION_UP, + ACTION_DOWN, + ACTION_POINTER_UP, + ACTION_POINTER_DOWN, + ACTION_MOVE, + ACTION_CANCEL +}; + +struct Rect { + float x; + float y; +}; +*/ +} // namespace accessibility +} // namespace OHOS +#endif // ACCESSIBILITY_ZOOM_MOCK_H + diff --git a/services/aams/include/accessibility_zoom_proxy.h b/services/aams/include/accessibility_zoom_proxy.h new file mode 100644 index 00000000..cc3ecde6 --- /dev/null +++ b/services/aams/include/accessibility_zoom_proxy.h @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ZOOM_PROXY_H +#define ACCESSIBILITY_ZOOM_PROXY_H + +// #include "accessibility_ability_manager_service.h" +#include +#include "accessibility_zoom_mock.h" +#include "refbase.h" +// #include "gfx_utils/rect.h" + +namespace OHOS { +namespace Accessibility { +/** + * @brief Magnification callback function, including zone change, rotation, user change. + * + * @since 1.0 + * @version 1.0 + */ +// WMS需要定义的接口, 目前WMS还没有这些功能和接口. +// 需要包括下面的几种情况:区域改变,旋转,用户变更. +class AccessibilityDisplayResizeListener /*: public WMS***.DisplayResizeCallbacks*/ { +public: + /** + * @brief + */ + AccessibilityDisplayResizeListener() {} + + /** + * @brief + */ + virtual ~AccessibilityDisplayResizeListener() {} + + /** + * @brief Callback function when zone change. + * + * @param aams AccessibilityAbilityManagerServicethe reference. + * @since 1.0 + * @version 1.0 + */ + virtual void OnDisplayResizeChanged(Rect &outRegion) {} + + /** + * @brief Callback function when rotation. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnRotationChanged() {} + + /** + * @brief Callback function when user changed. + * + * @since 1.0 + * @version 1.0 + */ + virtual void OnUserContextChanged() {} +}; + +class AccessibilityZoomProxy : public RefBase { +public: + /** + * @brief AccessibilityZoomProxy instance. + * + * @since 1.0 + * @version 1.0 + */ + static AccessibilityZoomProxy &GetInstance() + { + static AccessibilityZoomProxy instance_ {}; + return instance_; + } + + /** + * @brief A constructor used to create a magnification controller instance. + * + * @since 1.0 + * @version 1.0 + */ + AccessibilityZoomProxy() {} + + /** + * @brief A destructor used to delete the magnification controller instance. + * + * @since 1.0 + * @version 1.0 + */ + virtual ~AccessibilityZoomProxy() {} + + /** + * @brief Register the listener of magnification. + * + * @param listener Reference to the magnification listener. + * @since 1.0 + * @version 1.0 + */ + void AddListener(AccessibilityDisplayResizeListener &listener) {} + + /** + * @brief Unregister the listener of magnification. + * + * @param listener Reference to the magnification listener. + * @since 1.0 + * @version 1.0 + */ + void DeleteListener(AccessibilityDisplayResizeListener &listener) {} + + // 假定鸿蒙也有display、windows,activity的对应关系. + // android: 一个activity对应一个window,一个display对应一个屏幕,一个display可以有多个windows. + // 放大的效果是整个屏幕放大,不是某个window. 如果进行应用切换,即windows的切换,放大要保持不变. + // android: 当放大时会启动一个放大图层,处于最外层。和别的图层最终合成一个屏幕. + // + // 下面内容不确定,display不确定,待定. + // ----------------------------------------- + void Register(int displayId) {} + void Unregister(int displayId) {} + bool IsRegistered(int displayId) { return false; } + bool IsRunning(int displayId) { return false; } + // ----------------------------------------- + + + /** + * @brief Gets the scale. + * + * @param displayId The logical display id. + * @return Returns scale value. + * @since 1.0 + * @version 1.0 + */ + float GetScale(int displayId) { return 0.0; } + + /** + * @brief Gets the screen-relative X coordinate that is centered. + * + * @param displayId The logical display id. + * @return Returns the X coordinate of focus. + * @since 1.0 + * @version 1.0 + */ + float GetCenterX(int displayId) { return 0.0; } + + /** + * @brief Gets the screen-relative Y coordinate that is centered. + * + * @param displayId The logical display id. + * @return Returns the Y coordinate of focus. + * @since 1.0 + * @version 1.0 + */ + float GetCenterY(int displayId) { return 0.0; } + + /** + * @brief Gets the current magnification area. + * + * @param displayId The logical display id. + * @return Returns the region of magnification. + * @since 1.0 + * @version 1.0 + */ + Rect GetDisplayResizeRect(int displayId) { Rect rc {}; return rc; } + + /** + * @brief Reset magnification. + * + * @param displayId The logical display id. + * @return Returns the region of . + * @since 1.0 + * @version 1.0 + */ + bool Reset(int displayId) { return false; } + + /** + * @brief Set the magnification center and scale. + * + * @param displayId The logical display id. + * @param scale the target scale. + * @param centerX The screen-relative X coordinate that is centered and scaled. + * @param centerY The screen-relative Y coordinate that is centered and scaled. + * @since 1.0 + * @version 1.0 + */ + bool SetScaleAndCenter(int displayId, float scale, float centerX, float centerY) { return false; } + +private: + std::vector mListeners_ {}; + + /** + * @brief Set the magnification scale. + * + * @param displayId The logical display id. + * @param scale the target scale. + * @return Returns the region of . + * @since 1.0 + * @version 1.0 + */ + // 下面两个函数参数需要参考display屏幕设置的参数,需要屏幕生效,需要确认鸿蒙:屏幕、window的关系和api. + // 还需要确认鸿蒙下,动画的API使用,动画与WMS之间的关系,是否有关联. + // 动画与放大需要联动. + // 参数:需要不需要带x,y坐标,动画是否执行,需要依照WMS的实现来定。目前WMS尚不支持该功能. + bool SetScale(int displayId, float scale, float pivotX, float pivotY, + bool animate, int id) + { + return false; + } + + /** + * @brief Set the magnification center. + * + * @param displayId The logical display id. + * @param centerX The screen-relative X coordinate that is centered and scaled. + * @param centerY The screen-relative Y coordinate that is centered and scaled. + * @since 1.0 + * @version 1.0 + */ + bool SetCenter(int displayId, float centerX, float centerY, bool animate, int id) { return false; } + + /** + * @brief Set the magnifying offset. + * + * @param displayId corresponds to one screen. + * @param offsetX Offset the distance in the X direction, in current + * screen pixels. + * @param offsetY Offset the distance in the Y direction, in current + * screen pixels. + * @since 1.0 + * @version 1.0 + */ + void SetDisplayResizeOffset(int displayId, float offsetX, float offsetY) {} + +private: + // 动画使用什么控件?是否需要 继承动画事件? +/* + class AccessibilityAnimationListener : public ValueAnimator.AnimatorUpdateListener { + private: + explicit AnimationListener(int displayId); + virtual ~AnimationListener(); + void onAnimationUpdate(ValueAnimator animation); + }; +*/ +}; +} // namespace accessibility +} // namespace OHOS +#endif // ACCESSIBILITY_ZOOM_PROXY_H diff --git a/services/aams/include/accessible_ability_connection.h b/services/aams/include/accessible_ability_connection.h new file mode 100644 index 00000000..5351cf65 --- /dev/null +++ b/services/aams/include/accessible_ability_connection.h @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef OHOS_ACCESSIBLE_ABILITY_CONNECTION_H_ +#define OHOS_ACCESSIBLE_ABILITY_CONNECTION_H_ + +#include +#include +#include +#include "ability_connect_callback_stub.h" +#include "accessible_ability_client_proxy.h" +#include "accessible_ability_channel_stub.h" +#include "accessibility_ability_info.h" +#include "accessible_ability_manager_service.h" +#include "common_event_manager.h" +#include "dummy.h" + +namespace OHOS { +namespace Accessibility{ + +class AccessibilityAccountData; +class AccessibleAbilityManagerService; +class AccessibleAbilityConnection; + +class AccessibleAbilityChannelStubImpl : public AccessibleAbilityChannelStub { + +public: + AccessibleAbilityChannelStubImpl(AccessibleAbilityConnection &connection); + ~AccessibleAbilityChannelStubImpl(); + bool SearchElementInfoByAccessibilityId(const int accessibilityWindowId, const long elementId, + const int requestId, const sptr &callback, const int mode) override; + + bool SearchElementInfosByText(const int accessibilityWindowId, const long elementId, + const std::string &text, const int requestId, + const sptr &callback) override; + + bool FindFocusedElementInfo(const int accessibilityWindowId, const long elementId, + const int focusType, const int requestId, + const sptr &callback) override; + + bool FocusMoveSearch(const int accessibilityWindowId, const long elementId, const int direction, + const int requestId, const sptr &callback) override; + + bool PerformAction(const int accessibilityWindowId, const long elementId, const int action, + std::map &actionArguments, const int requestId, + const sptr &callback) override; + + std::vector GetWindows() override; + + bool PerformCommonAction(const int action) override; + + void DisableAbility() override; + + void SetOnKeyPressEventResult(const bool handled, const int sequence) override; + + float GetDisplayResizeScale(const int displayId) override; + + float GetDisplayResizeCenterX(const int displayId) override; + + float GetDisplayResizeCenterY(const int displayId) override; + + Rect GetDisplayResizeRect(const int displayId) override; + + bool ResetDisplayResize(const int displayId, bool animate) override; + + bool SetDisplayResizeScaleAndCenter(const int displayId, const float scale, const float centerX, + const float centerY, const bool animate) override; + + void SendSimulateGesture(const int sequence, const std::vector &gestureSteps) override; + + bool IsFingerprintGestureDetectionValid() override; + +private: + AccessibleAbilityConnection& connection_; + std::shared_ptr aams_ = nullptr; +}; + +class AccessibleAbilityConnection : public AAFwk::AbilityConnectionStub { +public: + AccessibleAbilityConnection(const wptr &accountData, const int connectionId, + AccessibilityAbilityInfo &abilityInfo); + + virtual ~AccessibleAbilityConnection(); + + virtual void OnAbilityConnectDone(const AppExecFwk::ElementName &element, + const sptr &remoteObject, + int resultCode) override; + + virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; + + //For AccessibleAbilityClientProxy + void OnAccessibilityEvent(AccessibilityEventInfo &eventInfo); + + void OnInterrupt(); + + void OnGesture(const int gestureId); + + bool OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int sequence); + + void OnDisplayResizeChanged(const int displayId, const Rect &rect, const float scale, const float centerX, + const float centerY); + + void OnGestureSimulateResult(const int sequence, const bool completedSuccessfully); + + void OnFingerprintGestureValidityChanged(const bool validity); + + void OnFingerprintGesture(const int gesture); + + //Get Attribution + inline AccessibilityAbilityInfo& GetAbilityInfo() {return abilityInfo_;} + + inline AppExecFwk::ElementName& GetElementName() {return elementName_;} + + inline wptr GetAccountData() {return accountData_;} + + inline sptr GetProxy() {return proxy_;} + + void Disconnect(); + + void Connect(); + + int GetChannelId(); + +private: + class AccessibleAbilityConnectionDeathRecipient final : public IRemoteObject::DeathRecipient { + public: + AccessibleAbilityConnectionDeathRecipient(wptr& accountData, + AppExecFwk::ElementName& elementName) + : recipientAccountData_(accountData), recipientElementName_(elementName) {}; + ~AccessibleAbilityConnectionDeathRecipient() = default; + DISALLOW_COPY_AND_MOVE(AccessibleAbilityConnectionDeathRecipient); + + void OnRemoteDied(const wptr& remote); + + wptr& recipientAccountData_; + AppExecFwk::ElementName& recipientElementName_; + }; + + bool IsWantedEvent(int eventType); + bool IsWhiteListEvent(EventType eventType); + + sptr deathRecipient_{}; + sptr proxy_ = nullptr; + sptr stub_ = nullptr; + AccessibilityAbilityInfo abilityInfo_; + AppExecFwk::ElementName elementName_; + wptr accountData_; + + int connectionId_; +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // OHOS_ACCESSIBLE_ABILITY_CONNECTION_H_ \ No newline at end of file diff --git a/services/aams/include/accessible_ability_manager_service.h b/services/aams/include/accessible_ability_manager_service.h new file mode 100644 index 00000000..f3d8d8ae --- /dev/null +++ b/services/aams/include/accessible_ability_manager_service.h @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBLE_ABILITY_MANAGER_SERVICE_H +#define ACCESSIBLE_ABILITY_MANAGER_SERVICE_H + +#define INT32_BIT_NUM 32 + +#include +#include +#include + +#include "accessible_ability_manager_service_stub.h" +#include "accessible_ability_manager_service_event_handler.h" +#include "accessibility_account_data.h" +#include "accessibility_common_event_registry.h" +#include "accessibility_input_filter.h" +#include "accessibility_keyevent_filter.h" +#include "accessibility_touchEvent_injector.h" +#include "accessibility_zoom_proxy.h" +#include "accessibility_window_info.h" +#include "bundlemgr/bundle_mgr_interface.h" +#include "singleton.h" +#include "system_ability.h" +#include "dummy.h" +#include "multimoduleDummy.h" + + +namespace OHOS { +namespace Accessibility { + +class AccessibilityAccountData; +class TouchEventInjector; + +class AccessibleAbilityManagerService : public SystemAbility, public AccessibleAbilityManagerServiceClientStub { + DECLARE_DELAYED_SINGLETON(AccessibleAbilityManagerService) + DECLEAR_SYSTEM_ABILITY(AccessibleAbilityManagerService) +public: + void OnStart() override; + void OnStop() override; + + /* For AccessibleAbilityManagerServiceClientStub */ + void SendEvent(const AccessibilityEventInfo &uiEvent, const int accountId) override; + + uint32_t RegisterStateCallback(const sptr &callback, + const int accountId) override; + + std::vector GetAbilityList(const int abilityTypes, const int stateType) override; + + void RegisterInteractionOperation(const int windowId, + const sptr &operation, + const int accountId) override; + + void DeregisterInteractionOperation(const int windowId) override; + + void Interrupt(const int accountId) override; + + uint64_t GetSuggestedInterval() override; + + void PersistElementNamesToSetting(std::string &bundleName, std::map &componentNames, + int accountId); + + /* For InputFilter */ + void SetTouchEventInjector(const sptr &touchEventInjector); + + inline sptr GetTouchEventInjector() {return touchEventInjector_;} + + /* For Key Event Filter */ + bool IsWantedKeyEvent(MMI::KeyEvent &event); + + inline sptr GetKeyEventFilter() {return keyEventFilter_;} + + void SetKeyEventFilter(const sptr &keyEventFilter); + + /* For DisplayResize */ + void NotifyDisplayResizeStateChanged(int displayId, Rect &rect, float scale, float centerX, float centerY); + + /* For TouchExplore */ + inline void OnTouchInteractionStart() {isTouchInteraction_ = true;} + + inline void OnTouchInteractionEnd() {isTouchInteraction_ = false;} + + void OnGesture(int id); + + void RegisterAbilityConnectionClientTmp(const sptr& obj) override; + + inline sptr GetInputFilter() {return inputFilter_;} + + inline int32_t GetCurrentAccountId() {return currentAccountId_;} + + inline uint32_t GetConnectCounter() {return connectCounter_;} + + inline std::shared_ptr& GetMainHandler() {return handler_;} + + inline std::shared_ptr& GetMainRunner() {return runner_;} + + sptr GetCurrentAccountData(); + + bool HasInputFilter() {return hasInputFilter_;} + + std::shared_ptr GetInputManager() {return inputManager_;} + + sptr GetBundleMgrProxy(); + sptr GetWindowMgrProxy(); + + /* Interaction Bridge*/ + AccessibilityElementInfo FindFocusedElementInfo(); + + bool PerformActionOnAccessibilityFocusedItem(const ActionType& action); + + bool GetAccessibilityFocusClickPointInScreen(MmiPoint &point); + + /* For common event */ + void SwitchedUser(int32_t accountId); + void UnlockedUser(int32_t accountId); + void RemovedUser(int32_t accountId); + void PresentUser(); + void PackageChanged(); + void PackageRemoved(std::string &bundleName); + void PackageUpdateFinished(std::string &bundleName); + + void UpdateAccessibilityManagerService(); + void UpdateAbilities(); + +private: + class StateCallbackDeathRecipient final : public IRemoteObject::DeathRecipient { + public: + StateCallbackDeathRecipient() = default; + ~StateCallbackDeathRecipient() final = default; + DISALLOW_COPY_AND_MOVE(StateCallbackDeathRecipient); + + void OnRemoteDied(const wptr& remote) final; + }; + + class InteractionOperationDeathRecipient final : public IRemoteObject::DeathRecipient { + public: + InteractionOperationDeathRecipient(int windowId) : windowId_(windowId) {}; + ~InteractionOperationDeathRecipient() final = default; + DISALLOW_COPY_AND_MOVE(InteractionOperationDeathRecipient); + + void OnRemoteDied(const wptr& remote) final; + int windowId_ = INVALID_WINDOW_ID; + }; + + bool Init(); + void SendEventInner(AccessibilityEventInfo &uiEvent); + void InterruptInner(); + sptr GetAccessibilityInteractionConnection(int windowId); + void ClearFocus(int windowId); + void OutsideTouch(int windowId); + void OnChanging(bool selfChange, Uri &uri); + void UpdateAccessibilityWindowStateByAccessibilityEvent(const AccessibilityEventInfo &event); + /* For common event */ + void PublicNoticeEventInner(); + + void UpdateAccessibilityState(); + void UpdateInputFilter(); + void UpdateMagnification(); + void UpdateWindowChangeListener(); + + bool isRunning_ = false; + int32_t currentAccountId_ = 0; + uint32_t connectCounter_ = 1; + bool isTouchInteraction_ = false; + AccessibilityCommonEventRegistry accessibilityCommonEventRegistry_; + std::map> a11yAccountsData_; + sptr bundleManager_; + sptr windowManager_; + + sptr inputFilter_; + sptr touchEventInjector_; + sptr keyEventFilter_; + std::shared_ptr inputManager_; + + bool hasInputFilter_ = false; + + std::shared_ptr runner_; + std::shared_ptr handler_; + + sptr stateCallbackDeathRecipient_ = nullptr; + sptr interactionOperationDeathRecipient_ = nullptr; + + DISALLOW_COPY_AND_MOVE(AccessibleAbilityManagerService); +}; +} // namespace Accessibility +} // namespace OHOS +#endif // ACCESSIBLE_ABILITY_MANAGER_SERVICE_H \ No newline at end of file diff --git a/services/aams/include/accessible_ability_manager_service_event_handler.h b/services/aams/include/accessible_ability_manager_service_event_handler.h new file mode 100644 index 00000000..3265b3f2 --- /dev/null +++ b/services/aams/include/accessible_ability_manager_service_event_handler.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ABILITY_MANAGER_SERVICE_EVENT_HANDLER_H +#define ACCESSIBILITY_ABILITY_MANAGER_SERVICE_EVENT_HANDLER_H + +#include "event_handler.h" + +namespace OHOS { +namespace Accessibility { +class AAMSEventHandler: public AppExecFwk::EventHandler { +public: + explicit AAMSEventHandler(const std::shared_ptr &runner); + virtual ~AAMSEventHandler() override; + /** + * @brief Process the event of install system bundles. + * @param event Indicates the event to be processed. + * @return + */ + virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; + + // T.B.D + // enum { + // ACCESSIBILITY_XXX_XXX = 1, + // ACCESSIBILITY_XXX_XXX, + // }; +}; +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBILITY_ABILITY_MANAGER_SERVICE_EVENT_HANDLER_H \ No newline at end of file diff --git a/services/aams/src/accessibility_account_data.cpp b/services/aams/src/accessibility_account_data.cpp new file mode 100644 index 00000000..9e03448a --- /dev/null +++ b/services/aams/src/accessibility_account_data.cpp @@ -0,0 +1,401 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_account_data.h" +#include "accessibility_display_manager.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace Accessibility { + +AccessibilityAccountData::AccessibilityAccountData(int accountId) { + id_ = accountId; +} + +AccessibilityAccountData::~AccessibilityAccountData() {} + +int AccessibilityAccountData::GetAccountId() +{ + HILOG_DEBUG("%{public}s start.", __func__); + return id_; +} + +// get client state. +uint32_t AccessibilityAccountData::GetAccessibilityState() { + HILOG_DEBUG("%{public}s start.", __func__); + uint32_t state = 0; + if (!connectedA11yAbilities_.empty() || !connectingA11yAbilities_.empty()) { + state |= AccessibilitySystemAbilityClient::STATE_ACCESSIBILITY_ENABLED; + } else { + state |= AccessibilitySystemAbilityClient::STATE_ACCESSIBILITY_DISABLED; + } + + if (isEventTouchGuideState_) { + state |= AccessibilitySystemAbilityClient::STATE_EXPLORATION_ENABLED; + } else { + state |= AccessibilitySystemAbilityClient::STATE_EXPLORATION_DISABLED; + } + + return state; +} + +// switch the user causes state changed. +void AccessibilityAccountData::OnAccountSwitched() { + HILOG_DEBUG("%{public}s start.", __func__); + // reset AccessibleAbilityConnection + for (auto itr = connectedA11yAbilities_.begin(); itr != connectedA11yAbilities_.end(); itr++) { + itr->second->Disconnect(); + } + + // Clear all abilities. + connectedA11yAbilities_.clear(); + connectingA11yAbilities_.clear(); + enabledAbilities_.clear(); + installedAbilities_.clear(); + + // Clear Setting State. + isEventTouchGuideState_ = false; + isScreenMagnification_ = false; + isFilteringKeyEvents_ = false; + isGesturesSimulation_ = false; + + // Clear UI timeOut. + interactiveUiInterval_ = 0; + nonInteractiveUiInterval_ = 0; + accountInteractiveUiInterval_ = 0; + accountNonInteractiveUiInterval_ = 0; +} + +// add connect ability. +void AccessibilityAccountData::AddConnectedAbility(sptr &connection) { + HILOG_DEBUG("%{public}s start.", __func__); + if (!connectedA11yAbilities_.count(connection->GetElementName().GetURI())) { + connectedA11yAbilities_.insert(make_pair(connection->GetElementName().GetURI(), connection)); + } + + HILOG_DEBUG("Add ConnectedAbility: %{public}d", connectedA11yAbilities_.size()); + + UpdateInteractiveUiInterval(); +} + +// remove connect ability. +void AccessibilityAccountData::RemoveConnectedAbility(sptr &connection) { + HILOG_DEBUG("%{public}s start.", __func__); + std::map>::iterator it = connectedA11yAbilities_.find(connection->GetElementName().GetURI()); + if (it != connectedA11yAbilities_.end()) { + connectedA11yAbilities_.erase(it); + } + + HILOG_DEBUG("Remove ConnectedAbility: %{public}d", connectedA11yAbilities_.size()); + + UpdateInteractiveUiInterval(); +} + +// ability disconnect. +void AccessibilityAccountData::AbilityDisconnected(sptr &connection) { + HILOG_DEBUG("%{public}s start.", __func__); + RemoveConnectedAbility(connection); + connectingA11yAbilities_.insert(make_pair(connection->GetElementName().GetURI(), connection->GetElementName())); +} + +void AccessibilityAccountData::AddStateCallback(const sptr &callback) { + HILOG_DEBUG("%{public}s start.", __func__); + stateCallbacks_.push_back(callback); +} + +// remove IAccessibleAbilityManagerServiceState +void AccessibilityAccountData::RemoveStateCallback(const wptr &callback) { + HILOG_DEBUG("%{public}s start.", __func__); + for (auto itr = stateCallbacks_.begin(); itr != stateCallbacks_.end(); itr++) { + if (*itr == callback) { + stateCallbacks_.erase(itr); + break; + } + } +} + +// add AccessibilityInteractionConnection +void AccessibilityAccountData::AddAccessibilityInteractionConnection(const int windowId, const sptr &interactionConnection) { + HILOG_DEBUG("%{public}s start.", __func__); + if (!asacConnections_.count(windowId)) { + asacConnections_.insert(std::make_pair(windowId, interactionConnection)); + } +} + +// remove AccessibilityInteractionConnection +void AccessibilityAccountData::RemoveAccessibilityInteractionConnection(const int windowId) { + HILOG_DEBUG("%{public}s start.", __func__); + std::map>::iterator it = asacConnections_.find(windowId); + if (it != asacConnections_.end()) { + asacConnections_.erase(it); + } +} + +void AccessibilityAccountData::AddConnectingA11yAbility(const AppExecFwk::ElementName &elementName) { + HILOG_DEBUG("%{public}s start.", __func__); + if (!connectingA11yAbilities_.count(elementName.GetURI())) { + connectingA11yAbilities_.insert(make_pair(elementName.GetURI(), elementName)); + } + + HILOG_DEBUG("Add ConnectingA11yAbility: %{public}d", connectingA11yAbilities_.size()); +} + +void AccessibilityAccountData::RemoveConnectingA11yAbility(const AppExecFwk::ElementName &elementName) { + HILOG_DEBUG("%{public}s start.", __func__); + std::map::iterator it = connectingA11yAbilities_.find(elementName.GetURI()); + if (it != connectingA11yAbilities_.end()) { + connectingA11yAbilities_.erase(it); + } + + HILOG_DEBUG("Remove ConnectingA11yAbility: %{public}d", connectingA11yAbilities_.size()); +} + +// For UT +void AccessibilityAccountData::AddEnabledAbility(const AppExecFwk::ElementName &elementName) { + HILOG_DEBUG("%{public}s start.", __func__); + if (!enabledAbilities_.count(elementName.GetURI())) { + enabledAbilities_.insert(make_pair(elementName.GetURI(), elementName)); + } + + HILOG_DEBUG("Add EnabledAbility: %{public}d", enabledAbilities_.size()); +} + +void AccessibilityAccountData::RemoveEnabledAbility(const AppExecFwk::ElementName &elementName) { + HILOG_DEBUG("%{public}s start.", __func__); + std::map::iterator it = enabledAbilities_.find(elementName.GetURI()); + if (it != enabledAbilities_.end()) { + enabledAbilities_.erase(it); + } + + HILOG_DEBUG("Remove EnabledAbility: %{public}d", enabledAbilities_.size()); +} + +// For UT +void AccessibilityAccountData::AddInstalledAbility(AccessibilityAbilityInfo &abilityInfo) { + HILOG_DEBUG("%{public}s start.", __func__); + installedAbilities_.push_back(abilityInfo); +} + +void AccessibilityAccountData::RemoveInstalledAbility(AccessibilityAbilityInfo &abilityInfo) { + HILOG_DEBUG("%{public}s start.", __func__); + for (auto it = installedAbilities_.begin(); it != installedAbilities_.end();) { + if (it->GetPackageName() == abilityInfo.GetPackageName()) { + installedAbilities_.erase(it); + } else { + ++it; + } + } +} + +void AccessibilityAccountData::ClearInstalledAbility() { + HILOG_DEBUG("%{public}s start.", __func__); + installedAbilities_.clear(); +} + +// get AccessibleAbilityConnection +const sptr AccessibilityAccountData::GetAccessibleAbilityConnection(const std::string elementName) { + HILOG_DEBUG("%{public}s start.", __func__); + if (connectedA11yAbilities_.count(elementName) > 0) { + return connectedA11yAbilities_[elementName]; + } + + return nullptr; +} + +// get AccessibilityInteractionConnection. +const sptr AccessibilityAccountData::GetAccessibilityInteractionConnection(const int windowId) { + HILOG_DEBUG("%{public}s start.", __func__); + if (asacConnections_.count(windowId) > 0) { + return asacConnections_[windowId]; + } + + return nullptr; +} + +// get map> connectedA11yAbilities_ +const std::map> AccessibilityAccountData::GetConnectedA11yAbilities() { + HILOG_DEBUG("%{public}s start.", __func__); + return connectedA11yAbilities_; +} + +const std::vector> AccessibilityAccountData::GetStateCallbacks() { + HILOG_DEBUG("%{public}s start.", __func__); + return stateCallbacks_; +} + +// get map> asacConnections_ +const std::map> AccessibilityAccountData::GetAsacConnections() { + HILOG_DEBUG("%{public}s start.", __func__); + return asacConnections_; +} + +// get connectingA11yAbilities_. +const std::map AccessibilityAccountData::GetConnectingA11yAbilities() { + HILOG_DEBUG("%{public}s start.", __func__); + return connectingA11yAbilities_; +} + +// get enabledAbilities_. +const std::map AccessibilityAccountData::GetEnabledAbilities() { + HILOG_DEBUG("%{public}s start.", __func__); + return enabledAbilities_; +} + +// get installedAbilities_. +const std::vector AccessibilityAccountData::GetInstalledAbilities() { + HILOG_DEBUG("%{public}s start.", __func__); + return installedAbilities_; +} + +const std::vector AccessibilityAccountData::GetAbilitiesByState(AbilityStateType state) { + HILOG_DEBUG("%{public}s start.", __func__); + if (state == ABILITY_STATE_ENABLE) { + std::vector enabledAbilities; + for (auto ability : connectedA11yAbilities_) { + enabledAbilities.push_back(ability.second->GetAbilityInfo()); + } + return enabledAbilities; + } else if (state == ABILITY_STATE_DISABLE) { + std::vector disabledAbilities = installedAbilities_; + for (auto enabledAbility : connectedA11yAbilities_) { + for (auto itr = disabledAbilities.begin(); itr != disabledAbilities.end();) { + if (itr->GetId() == enabledAbility.second->GetAbilityInfo().GetId()) { + disabledAbilities.erase(itr); + } else { + itr++; + } + } + } + return disabledAbilities; + } else { + return installedAbilities_; + } +} + +// get interactiveUiInterval_. +uint32_t AccessibilityAccountData::GetInteractiveUiInterval() { + HILOG_DEBUG("%{public}s start.", __func__); + return interactiveUiInterval_; +} + +// get nonInteractiveUiInterval_. +uint32_t AccessibilityAccountData::GetNonInteractiveUiInterval() { + HILOG_DEBUG("%{public}s start.", __func__); + return nonInteractiveUiInterval_; +} + +// get accountInteractiveUiInterval_. +uint32_t AccessibilityAccountData::GetAccountInteractiveUiInterval() { + HILOG_DEBUG("%{public}s start.", __func__); + return accountInteractiveUiInterval_; +} + +// get accountNonInteractiveUiInterval_. +uint32_t AccessibilityAccountData::GetAccountNonInteractiveUiInterval() { + HILOG_DEBUG("%{public}s start.", __func__); + return accountNonInteractiveUiInterval_; +} + +void AccessibilityAccountData::UpdateAccountCapabilities() { + HILOG_DEBUG("%{public}s start.", __func__); + UpdateFilteringKeyEventsCapability(); + UpdateEventTouchGuideCapability(); + UpdateGesturesSimulationCapability(); + UpdateMagnificationCapability(); +} + +void AccessibilityAccountData::UpdateEventTouchGuideCapability() { + HILOG_DEBUG("%{public}s start.", __func__); + for (auto itr = connectedA11yAbilities_.begin(); itr != connectedA11yAbilities_.end(); itr++) { + if (itr->second->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_TOUCH_GUIDE) { + isEventTouchGuideState_ = true; + return; + } + } + isEventTouchGuideState_ = false; +} + +void AccessibilityAccountData::UpdateGesturesSimulationCapability() { + HILOG_DEBUG("%{public}s start.", __func__); + for (auto itr = connectedA11yAbilities_.begin(); itr != connectedA11yAbilities_.end(); itr++) { + if (itr->second->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_GESTURE) { + isGesturesSimulation_ = true; + return; + } + } + isGesturesSimulation_ = false; +} + +void AccessibilityAccountData::UpdateFilteringKeyEventsCapability() { + HILOG_DEBUG("%{public}s start.", __func__); + for (auto itr = connectedA11yAbilities_.begin(); itr != connectedA11yAbilities_.end(); itr++) { + if (itr->second->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_KEY_EVENT_OBSERVER) { + isFilteringKeyEvents_ = true; + return; + } + } + isFilteringKeyEvents_ = false; +} + +void AccessibilityAccountData::UpdateMagnificationCapability() { + HILOG_DEBUG("%{public}s start.", __func__); + for (auto itr = connectedA11yAbilities_.begin(); itr != connectedA11yAbilities_.end(); itr++) { + if (itr->second->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_ZOOM) { + isScreenMagnification_ = true; + return; + } + } + isScreenMagnification_ = false; +} + +void AccessibilityAccountData::UpdateInteractiveUiInterval() { + HILOG_DEBUG("%{public}s start.", __func__); + // User setting value. + interactiveUiInterval_ = accountInteractiveUiInterval_; + nonInteractiveUiInterval_ = accountNonInteractiveUiInterval_; + // User does not setting value. + if (accountInteractiveUiInterval_ == 0 || accountNonInteractiveUiInterval_ == 0) { + // read from a11y. + uint32_t abilityInterval = 0; + uint32_t abilityNonInterval = 0; + for (auto itr = connectedA11yAbilities_.begin(); itr != connectedA11yAbilities_.end(); itr++) { + uint32_t interval = itr->second->GetAbilityInfo().GetUiInteractiveTime(); + uint32_t nonInterval = itr->second->GetAbilityInfo().GetUiNoninteractiveTime(); + if (interval > abilityInterval) { + abilityInterval = interval; + } + if (nonInterval > abilityNonInterval) { + abilityNonInterval = nonInterval; + } + } + // User only setting nonInterval. + if (accountInteractiveUiInterval_ == 0) { + interactiveUiInterval_ = abilityInterval; + } + // User only setting interval. + if (accountNonInteractiveUiInterval_ == 0) { + nonInteractiveUiInterval_ = abilityNonInterval; + } + } +} + +bool AccessibilityAccountData::ReadConfigurationForAccountData() { + HILOG_DEBUG("%{public}s start.", __func__); + return true; + // TODO: readConfigurationForUserStateLocked. +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/services/aams/src/accessibility_common_event_registry.cpp b/services/aams/src/accessibility_common_event_registry.cpp new file mode 100644 index 00000000..b0550fa6 --- /dev/null +++ b/services/aams/src/accessibility_common_event_registry.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2021 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. + */ + +#include +#include "accessibility_common_event_registry.h" +#include "accessible_ability_manager_service.h" +#include "hilog_wrapper.h" + +using namespace std; +using namespace OHOS::EventFwk; +using namespace OHOS::AAFwk; + +namespace OHOS{ +namespace Accessibility{ + +AccessibilityCommonEventRegistry::AccessibilityCommonEventRegistry() +{ + HILOG_DEBUG("AccessibilityCommonEventRegistry AccessibilityCommonEventRegistry"); + handleEventFunc_[CommonEventSupport::COMMON_EVENT_USER_SWITCHED] = + &AccessibilityCommonEventRegistry::HandleSwitchedUser; + handleEventFunc_[CommonEventSupport::COMMON_EVENT_USER_UNLOCKED] = + &AccessibilityCommonEventRegistry::HandleUnlockedUser; + handleEventFunc_[CommonEventSupport::COMMON_EVENT_USER_REMOVED] = + &AccessibilityCommonEventRegistry::HandleRemovedUser; + handleEventFunc_[CommonEventSupport::COMMON_EVENT_USER_PRESENT] = + &AccessibilityCommonEventRegistry::HandlePresentUser; + + handleEventFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED] = + &AccessibilityCommonEventRegistry::HandlePackageRemoved; + handleEventFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED] = + &AccessibilityCommonEventRegistry::HandlePackageChanged; +} + +bool AccessibilityCommonEventRegistry::StartRegister() +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!eventHandles_.empty()) { + HILOG_DEBUG("eventHandles_ is not empty"); + eventHandles_.clear(); + } + + for (auto it = handleEventFunc_.begin(); it != handleEventFunc_.end(); ++it) + { + HILOG_DEBUG("Add event: %{public}s", it->first.c_str()); + eventHandles_.emplace(it->first, bind(it->second, this, placeholders::_1)); + } + + if (!RegisterSubscriber()) { + HILOG_ERROR("RegisterSubscriber failed"); + return false; + } + + return true; +} + +bool AccessibilityCommonEventRegistry::RegisterSubscriber() +{ + HILOG_DEBUG("%{public}s start.", __func__); + + bool subscribeResult = false; + MatchingSkills matchingSkills; + for (auto &event : handleEventFunc_) { + HILOG_DEBUG("Add event: %{public}s", event.first.c_str()); + matchingSkills.AddEvent(event.first); + } + + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPermission("ohos.permission.MANAGE_USERS"); + accessibilityCommonEventSubscriber_ = + std::make_shared(subscribeInfo, eventHandles_); + + int retry = 3; + do { + subscribeResult = CommonEventManager::SubscribeCommonEvent(accessibilityCommonEventSubscriber_); + if (subscribeResult) { + break; + } else { + HILOG_DEBUG("SubscribeCommonEvent failed, retry %{public}d", retry); + retry--; + sleep(1); + } + } while (retry); + + return subscribeResult; +} + +void AccessibilityCommonEventRegistry::UnRegister() +{ + HILOG_DEBUG("%{public}s start.", __func__); + eventHandles_.clear(); + if (accessibilityCommonEventSubscriber_ != nullptr) { + bool subscribeResult = CommonEventManager::UnSubscribeCommonEvent(accessibilityCommonEventSubscriber_); + HILOG_DEBUG("subscribeResult = %{public}d", subscribeResult); + accessibilityCommonEventSubscriber_.reset(); + } + HILOG_DEBUG("UnRegister end."); +} + +void AccessibilityCommonEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + HILOG_DEBUG("%{public}s start.", __func__); + HandleEvent(data.GetWant()); +} + +void AccessibilityCommonEventSubscriber::HandleEvent(const Want &want) +{ + HILOG_DEBUG("%{public}s start.", __func__); + auto action = want.GetAction(); + auto it = eventHandles_.find(action); + if (it == eventHandles_.end()) { + HILOG_ERROR("Ignore event: %{public}s", action.c_str()); + return; + } + HILOG_DEBUG("Handle event: %{public}s", action.c_str()); + it->second(want); +} + +void AccessibilityCommonEventRegistry::HandleSwitchedUser(const Want &want) const +{ + HILOG_DEBUG("%{public}s start.", __func__); + + // TODO: To make sure the invalid accoundId. -1 is temporary. + int32_t accountId = want.GetIntParam(CommonEventSupport::COMMON_EVENT_USER_SWITCHED, -1); + DelayedSingleton::GetInstance()->SwitchedUser(accountId); +} + +void AccessibilityCommonEventRegistry::HandleUnlockedUser(const Want &want) const +{ + HILOG_DEBUG("%{public}s start.", __func__); + + int32_t accountId = want.GetIntParam(CommonEventSupport::COMMON_EVENT_USER_UNLOCKED, -1); + DelayedSingleton::GetInstance()->UnlockedUser(accountId); +} + +void AccessibilityCommonEventRegistry::HandleRemovedUser(const Want &want) const +{ + HILOG_DEBUG("%{public}s start.", __func__); + + int32_t accountId = want.GetIntParam(CommonEventSupport::COMMON_EVENT_USER_REMOVED, -1); + DelayedSingleton::GetInstance()->RemovedUser(accountId); +} + +void AccessibilityCommonEventRegistry::HandlePresentUser(const Want &want) const +{ + HILOG_DEBUG("%{public}s start.", __func__); + DelayedSingleton::GetInstance()->PresentUser(); +} + +void AccessibilityCommonEventRegistry::HandlePackageRemoved(const Want &want) const +{ + HILOG_DEBUG("%{public}s start.", __func__); + string bundleName = want.GetBundle(); + DelayedSingleton::GetInstance()->PackageRemoved(bundleName); +} + +void AccessibilityCommonEventRegistry::HandlePackageUpdateFinished(const Want &want) const +{ + HILOG_DEBUG("%{public}s start.", __func__); + string bundleName = want.GetBundle(); + DelayedSingleton::GetInstance()->PackageUpdateFinished(bundleName); +} + +void AccessibilityCommonEventRegistry::HandlePackageChanged(const Want &want) const +{ + HILOG_DEBUG("%{public}s start.", __func__); + DelayedSingleton::GetInstance()->PackageChanged(); +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/services/aams/src/accessibility_display_manager.cpp b/services/aams/src/accessibility_display_manager.cpp new file mode 100644 index 00000000..796cb68e --- /dev/null +++ b/services/aams/src/accessibility_display_manager.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "accessibility_display_manager.h" +#include "accessible_ability_manager_service.h" +#include "hilog_wrapper.h" +#include "singleton.h" + +namespace OHOS { +namespace Accessibility { + +void GetDisplayFromWms(std::vector &displays) { + auto aams = DelayedSingleton::GetInstance(); + sptr wms = aams->GetWindowMgrProxy(); + WMError err = wms->GetDisplays(displays); + if (err != WM_OK) { + HILOG_ERROR("GetDisplayFromWms failed"); + } +} + +AccessibilityDisplayManager::AccessibilityDisplayManager() { + GetDisplayFromWms(displays_); +} + +AccessibilityDisplayManager &AccessibilityDisplayManager::GetInstance() { + static AccessibilityDisplayManager displayMgr; + return displayMgr; +} + +WMDisplayInfo AccessibilityDisplayManager::GetDisplay(int id) { + for (auto display : displays_) { + if (display.id == id) { + return display; + } + } + + HILOG_ERROR("Invalid display id!! Return default display"); + return displays_.front(); +} + +std::vector AccessibilityDisplayManager::GetDisplays() { + return displays_; +} + +WMDisplayInfo AccessibilityDisplayManager::GetDefaultDisplay() { + return displays_.front(); +} + +void AccessibilityDisplayManager::RegisterDisplayChangeListener() { + auto aams = DelayedSingleton::GetInstance(); + sptr wms = aams->GetWindowMgrProxy(); + wms->AddDisplayChangeListener(this); +} + +void AccessibilityDisplayManager::OnScreenPlugin(int32_t did) { + // TODO: Do something for zoom + displays_.clear(); + GetDisplayFromWms(displays_); +} + +void AccessibilityDisplayManager::OnScreenPlugout(int32_t did) { + // TODO: Do something for zoom + displays_.clear(); + GetDisplayFromWms(displays_); +} + +void AccessibilityDisplayManager::SetDisplay(WMDisplayInfo newWM) { + displays_.clear(); + displays_.push_back(newWM); +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/services/aams/src/accessibility_event_transmission.cpp b/services/aams/src/accessibility_event_transmission.cpp new file mode 100644 index 00000000..d507046b --- /dev/null +++ b/services/aams/src/accessibility_event_transmission.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_event_transmission.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace Accessibility{ +void EventTransmission::OnTouchEvent(TouchEvent &event) +{ + HILOG_DEBUG(); + + auto next = GetNext(); + if (next != nullptr) { + next->OnTouchEvent(event); + } +} + +void EventTransmission::OnMouseEvent(MouseEvent &event) +{ + HILOG_DEBUG(); + + auto next = GetNext(); + if (next != nullptr) { + next->OnMouseEvent(event); + } +} + +void EventTransmission::OnKeyEvent(MMI::KeyEvent &event) +{ + HILOG_DEBUG(); + + auto next = GetNext(); + if (next != nullptr) { + next->OnKeyEvent(event); + } +} + +void EventTransmission::OnAccessibilityEvent(AccessibilityEventInfo &event) +{ + HILOG_DEBUG(); + + auto next = GetNext(); + if (next != nullptr) { + next->OnAccessibilityEvent(event); + } +} + +void EventTransmission::SetNext(const sptr &next) +{ + HILOG_DEBUG(); + + next_ = next; +} + +sptr EventTransmission::GetNext() +{ + HILOG_DEBUG(); + + return next_; +} + +void EventTransmission::ClearEvents(uint32_t inputSource) +{ + HILOG_DEBUG(); + + auto next = GetNext(); + if (next != nullptr) { + next->ClearEvents(inputSource); + } +} + +void EventTransmission::DestroyEvents() +{ + HILOG_DEBUG(); + + auto next = GetNext(); + if (next != nullptr) { + next->DestroyEvents(); + } +} + +} // namespace Accessibility +} // namespace OHOS diff --git a/services/aams/src/accessibility_gesture_recognizer.cpp b/services/aams/src/accessibility_gesture_recognizer.cpp new file mode 100644 index 00000000..d216e623 --- /dev/null +++ b/services/aams/src/accessibility_gesture_recognizer.cpp @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "accessibility_gesture_recognizer.h" + +namespace OHOS{ +namespace Accessibility{ + +GestureHandler::GestureHandler( + const std::shared_ptr &runner, AccessibilityGestureRecognizer &server) + : AppExecFwk::EventHandler(runner),server_(server) { + +} + +void GestureHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) { + switch (event->GetInnerEventId()) { + case AccessibilityGestureRecognizer::LONG_PRESS_MSG: + RemoveEvent(AccessibilityGestureRecognizer::SINGLE_TAP_MSG); + server_.SetIsLongpress(true); + server_.MaybeRecognizeLongPress(*server_.GetCurDown()); + break; + case AccessibilityGestureRecognizer::SINGLE_TAP_MSG: + if (!server_.GetContinueDown()) { + server_.SingleTapDetected(); + } + break; + default: + break; + } +} + +AccessibilityGestureRecognizer::AccessibilityGestureRecognizer() { + AccessibilityDisplayManager &displayMgr = AccessibilityDisplayManager::GetInstance(); + struct WMDisplayInfo displayInfo = displayMgr.GetDefaultDisplay(); + + threshold_ = CALCULATION_DIMENSION(displayInfo.width); + xMinPixels_= MIN_PIXELS(displayInfo.width); + yMinPixels_ = MIN_PIXELS(displayInfo.height); + + float densityPixels = displayInfo.dpi; + int slop = (int) (densityPixels * DOUBLE_TAP_SLOP + 0.5f); + doubleTapScaledSlop_ = slop * slop; + + runner_ = DelayedSingleton::GetInstance()->GetMainRunner(); + if (!runner_) { + HILOG_ERROR("get runner failed"); + return ; + } + handler_ = std::make_shared(runner_, *this); + if (!handler_) { + HILOG_ERROR("create event handler failed"); + return ; + } +} + +void AccessibilityGestureRecognizer::registerListener(AccessibilityGestureRecognizeListener *listener) { + listener_ = listener; +} + +void AccessibilityGestureRecognizer::UnregisterListener(AccessibilityGestureRecognizeListener *listener) { + listener_ = nullptr; +} + +bool AccessibilityGestureRecognizer::OnTouchEvent(TouchEvent &event) { + switch (event.GetAction()) { + case TouchEnum::PRIMARY_POINT_DOWN: + HandleTouchDownEvent(event); + break; + case TouchEnum::POINT_MOVE: + return HandleTouchMoveEvent(event); + case TouchEnum::PRIMARY_POINT_UP: + return HandleTouchUpEvent(event); + case TouchEnum::OTHER_POINT_DOWN: + isRecognizingGesture_ = false; + isGestureStarted_ = false; + pointerRoute_.clear(); + break; + case TouchEnum::CANCEL: + Clear(); + break; + default: + break; + } + if (!isRecognizingGesture_) { + return false; + } + return StandardGestureRecognizer(event); +} + +void AccessibilityGestureRecognizer::Clear() { + isFirstTapUp_ = false; + isDoubleTap_ = false; + isGestureStarted_ = false; + isRecognizingGesture_ = false; + pointerRoute_.clear(); + continueDown_ = false; + StandardGestureCancled(); +} + +void AccessibilityGestureRecognizer::HandleTouchDownEvent(TouchEvent &event) { + Pointer mp; + MmiPoint point = event.GetPointerPosition(event.GetIndex()); + unsigned int eventTime = event.GetOccurredTime(); + mp.px_ = point.GetX(); + mp.py_ = point.GetY(); + isDoubleTap_ = false; + isRecognizingGesture_ = true; + isGestureStarted_ = false; + pointerRoute_.clear(); + pointerRoute_.push_back(mp); + prePointer_ = point; + startPointer_ = point; + startTime_ = eventTime; +} + +bool AccessibilityGestureRecognizer::HandleTouchMoveEvent(TouchEvent &event) { + Pointer mp; + MmiPoint point = event.GetPointerPosition(event.GetIndex()); + unsigned int eventTime = event.GetOccurredTime(); + float offsetX = startPointer_.GetX() - point.GetX(); + float offsetY = startPointer_.GetY() - point.GetY(); + double duration = hypot(offsetX, offsetY); + if (isRecognizingGesture_) { + if (duration > threshold_) { + startPointer_ = point; + startTime_ = eventTime; + isFirstTapUp_ = false; + isDoubleTap_ = false; + if (!isGestureStarted_) { + isGestureStarted_ = true; + return listener_->OnStarted(); + } + } else if (!isFirstTapUp_) { + unsigned int durationTime = eventTime - startTime_; + unsigned int thresholdTime = isGestureStarted_ ? + GESTURE_STARTED_TIME_THRESHOLD : GESTURE_NOT_STARTED_TIME_THRESHOLD; + if (durationTime > thresholdTime) { + isRecognizingGesture_ = false; + isGestureStarted_ = false; + pointerRoute_.clear(); + return listener_->OnCancelled(event); + } + } + if ((abs(point.GetX() - prePointer_.GetX())) >= xMinPixels_ || + (abs(point.GetY() - prePointer_.GetY())) >= yMinPixels_) { + prePointer_ = point; + mp.px_ = point.GetX(); + mp.py_ = point.GetY(); + pointerRoute_.push_back(mp); + } + } + if (!isRecognizingGesture_) { + return false; + } + return StandardGestureRecognizer(event); +} + +bool AccessibilityGestureRecognizer::HandleTouchUpEvent(TouchEvent &event) { + Pointer mp; + MmiPoint point = event.GetPointerPosition(event.GetIndex()); + + if (isDoubleTap_) { + return DoubleTapRecognized(event); + } + if (isGestureStarted_) { + if ((abs(point.GetX() - prePointer_.GetX())) >= xMinPixels_ || + (abs(point.GetY() - prePointer_.GetY())) >= yMinPixels_) { + mp.px_ = point.GetX(); + mp.py_ = point.GetY(); + pointerRoute_.push_back(mp); + } + return recognizeDirectionGesture(event); + } + if (!isRecognizingGesture_) { + return false; + } + return StandardGestureRecognizer(event); +} + +bool AccessibilityGestureRecognizer::StandardGestureRecognizer(TouchEvent &event) { + switch (event.GetAction()) { + case TouchEnum::PRIMARY_POINT_DOWN: + if (pCurDown_ && pPreUp_ && isDoubleTap(event)) { + isDoubleTapdetecting_ = true; + isDoubleTap_ = true; + } else { + handler_->SendEvent(SINGLE_TAP_MSG, 0, DOUBLE_TAP_TIMEOUT); + } + pCurDown_ = std::make_shared(event); + isTapDown_ = true; + continueDown_ = true; + isLongpress_ = false; + handler_->RemoveEvent(LONG_PRESS_MSG); + handler_->SendEvent(LONG_PRESS_MSG, 0, LONG_PRESS_TIMEOUT); + break; + case TouchEnum::PRIMARY_POINT_UP: + continueDown_ = false; + if (isLongpress_) { + handler_->RemoveEvent(SINGLE_TAP_MSG); + isLongpress_ = false; + } else if (!isDoubleTapdetecting_ && isTapDown_) { + isFirstTapUp_ = true; + } + pPreUp_ = std::make_unique(event); + isDoubleTapdetecting_ = false; + handler_->RemoveEvent(LONG_PRESS_MSG); + break; + case TouchEnum::OTHER_POINT_DOWN: + StandardGestureCancled(); + break; + default: + break; + } + return false; +} + +void AccessibilityGestureRecognizer::StandardGestureCancled() { + handler_->RemoveEvent(LONG_PRESS_MSG); + handler_->RemoveEvent(SINGLE_TAP_MSG); + isLongpress_ = false; + isDoubleTapdetecting_ = false; + isTapDown_ = false; +} + +void AccessibilityGestureRecognizer::SingleTapDetected() { + Clear(); +} + +void AccessibilityGestureRecognizer::MaybeRecognizeLongPress(TouchEvent &event) { + if (!isDoubleTap_) { + return; + } + Clear(); + listener_->OnDoubleTapLongPress(event); +} + +bool AccessibilityGestureRecognizer::DoubleTapRecognized(TouchEvent &event) { + Clear(); + return listener_->OnDoubleTap(event); +} + +bool AccessibilityGestureRecognizer::recognizeDirectionGesture(TouchEvent &event) { + if (pointerRoute_.size() < 2) { + return listener_->OnCancelled(event); + } + + /* Check the angle of the most recent motion vector versus the preceding motion vector, + * segment the line if the angle is about 90 degrees. + */ + std::vector pointerPath = GetPointerPath(pointerRoute_); + + if (pointerPath.size() == 2) { + int swipeDirection = GetSwipeDirection(pointerPath[0], pointerPath[1]); + return listener_->OnCompleted(GESTURE_DIRECTION[swipeDirection]); + } else if (pointerPath.size() == 3) { + int swipeDirectionH = GetSwipeDirection(pointerPath[0], pointerPath[1]); + int swipeDirectionHV = GetSwipeDirection(pointerPath[1], pointerPath[2]); + return listener_->OnCompleted(GESTURE_DIRECTION_TO_ID[swipeDirectionH][swipeDirectionHV]); + } + return listener_->OnCancelled(event); +} + +int AccessibilityGestureRecognizer::GetSwipeDirection(Pointer firstP, Pointer secondP) { + float offsetX = secondP.px_ - firstP.px_; + float offsetY = secondP.py_ - firstP.py_; + if (abs(offsetX) > abs(offsetY)) { + return offsetX > 0.0 ? SWIPE_RIGHT : SWIPE_LEFT; + } else { + return offsetY > 0.0 ? SWIPE_UP : SWIPE_DOWN; + } +} + +std::vector AccessibilityGestureRecognizer::GetPointerPath(std::vector &route) { + std::vector pointerPath; + Pointer firstSeparation = route[0]; + Pointer nextPoint; + Pointer newSeparation; + float xUnitVector = 0; + float yUnitVector = 0; + float xVector = 0; + float yVector = 0; + float vectorLength = 0; + int numSinceFirstSep = 0; + + pointerPath.push_back(firstSeparation); + for (unsigned int i = 1; i < route.size(); i++) { + nextPoint = route[i]; + if (numSinceFirstSep > 0) { + xVector = xUnitVector / numSinceFirstSep; + yVector = yUnitVector / numSinceFirstSep; + newSeparation.px_ = vectorLength * xVector + firstSeparation.px_; + newSeparation.py_ = vectorLength * yVector + firstSeparation.py_; + + float xNextUnitVector = nextPoint.px_ - newSeparation.px_; + float yNextUnitVector = nextPoint.py_ - newSeparation.py_; + float nextVectorLength = hypot(xNextUnitVector, yNextUnitVector); + xNextUnitVector /= nextVectorLength; + yNextUnitVector /= nextVectorLength; + + if ((xVector * xNextUnitVector + yVector * yNextUnitVector) < DEGREES_THRESHOLD) { + pointerPath.push_back(newSeparation); + firstSeparation = newSeparation; + xUnitVector = 0; + yUnitVector = 0; + numSinceFirstSep = 0; + } + } + xVector = nextPoint.px_ - firstSeparation.px_; + yVector = nextPoint.py_ - firstSeparation.py_; + vectorLength = hypot(xVector, yVector); + numSinceFirstSep += 1; + xUnitVector += xVector / vectorLength; + yUnitVector += yVector / vectorLength; + } + pointerPath.push_back(nextPoint); + return pointerPath; +} + +bool AccessibilityGestureRecognizer::isDoubleTap(TouchEvent &event) { + int durationTime = event.GetOccurredTime() - pPreUp_->GetOccurredTime(); + if (!(durationTime <= DOUBLE_TAP_TIMEOUT && durationTime >= MIN_DOUBLE_TAP_TIME)) { + return false; + } + + MmiPoint firstMp = pCurDown_->GetPointerPosition(event.GetIndex()); + MmiPoint secondMp = event.GetPointerPosition(event.GetIndex()); + int durationX = (int)firstMp.GetX() - (int)secondMp.GetX(); + int durationY = (int)firstMp.GetY() - (int)secondMp.GetY(); + + return (durationX * durationX + durationY * durationY < doubleTapScaledSlop_); +} + +} // namespace Accessibility +} // namespace OHOS diff --git a/services/aams/src/accessibility_input_filter.cpp b/services/aams/src/accessibility_input_filter.cpp new file mode 100644 index 00000000..5160cb42 --- /dev/null +++ b/services/aams/src/accessibility_input_filter.cpp @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2021 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. + */ + +#include + +#include "accessible_ability_manager_service.h" +#include "accessibility_input_filter.h" +#include "accessibility_keyevent_filter.h" +#include "accessibility_touch_guider.h" +#include "accessibility_touchEvent_injector.h" +#include "accessibility_zoom_handler.h" +#include "hilog_wrapper.h" +#include "power_mgr_client.h" + +namespace OHOS { +namespace Accessibility { + +AccessibilityInputFilter::AccessibilityInputFilter() +{ + HILOG_DEBUG(); + + ams_ = DelayedSingleton::GetInstance(); + if (ams_ != nullptr) { + eventHandler_ = std::make_shared(ams_->GetMainRunner()); + } +} + +AccessibilityInputFilter::~AccessibilityInputFilter() +{ + HILOG_DEBUG(); + + DestroyTransmitters(); +} + +void AccessibilityInputFilter::OnInputEvent(MultimodalEvent &event) +{ + HILOG_DEBUG(); + + if (eventHandler_ == nullptr) { + HILOG_ERROR("EventHandler_ is null."); + InjectEventToMultimodal(event); + return; + } + + int sourceType = event.GetSourceDevice(); + HILOG_DEBUG("Source type[%d].", sourceType); + switch (sourceType) { + case SourceDevice::TOUCH_PANEL: { + TouchEvent touchEvent = static_cast(event); + auto task = std::bind(&AccessibilityInputFilter::ProcessTouchEvent, this, touchEvent); + eventHandler_->PostTask(task, AppExecFwk::EventQueue::Priority::LOW); + } + break; + case SourceDevice::MOUSE: { + MouseEvent mouseEvent = static_cast(event); + auto task = std::bind(&AccessibilityInputFilter::ProcessMouseEvent, this, mouseEvent); + eventHandler_->PostTask(task, AppExecFwk::EventQueue::Priority::LOW); + } + break; + case SourceDevice::KEYBOARD: { + // TODO: fixme + // MMI::KeyEvent keyEvent = static_cast(event); + // auto task = std::bind(&AccessibilityInputFilter::ProcessKeyEvent, this, keyEvent); + // eventHandler_->PostTask(task, AppExecFwk::EventQueue::Priority::LOW); + } + break; + default: + InjectEventToMultimodal(event); + break; + } +} + +void AccessibilityInputFilter::OnTouchEvent(TouchEvent &event) +{ + HILOG_DEBUG(); + + InjectEventToMultimodal(event); +} + +void AccessibilityInputFilter::OnMouseEvent(MouseEvent &event) +{ + HILOG_DEBUG(); + + InjectEventToMultimodal(event); +} + +void AccessibilityInputFilter::OnKeyEvent(MMI::KeyEvent &event) +{ + HILOG_DEBUG(); + + // TODO: fixme + // InjectEventToMultimodal(event); +} + +void AccessibilityInputFilter::SetUser(uint32_t userId) +{ + HILOG_DEBUG("userId[%d].", userId); + + if (userId_ == userId) { + return; + } + userId_ = userId; + DestroyTransmitters(); + CreateTransmitters(); +} + +void AccessibilityInputFilter::SetAvailableFunctions(uint32_t availableFunctions) +{ + HILOG_DEBUG("function[%d].", availableFunctions); + + if (availableFunctions_ == availableFunctions) { + return; + } + availableFunctions_ = availableFunctions; + DestroyTransmitters(); + CreateTransmitters(); +} + +void AccessibilityInputFilter::CreateTransmitters() +{ + HILOG_DEBUG("function[%d].", availableFunctions_); + + if (availableFunctions_ == 0) { + return; + } + + sptr header = nullptr; + sptr current = nullptr; + + if (availableFunctions_ & FEATURE_INJECT_TOUCH_EVENTS) { + sptr touchEventInjector = new TouchEventInjector(); + SetNextEventTransmitter(header, current, touchEventInjector); + ams_->SetTouchEventInjector(touchEventInjector); + } + + if (availableFunctions_ & FEATURE_SCREEN_MAGNIFICATION) { + sptr zoomHandler = new AccessibilityZoomHandler(0); + SetNextEventTransmitter(header, current, zoomHandler); + } + + if (availableFunctions_ & FEATURE_TOUCH_EXPLORATION) { + sptr touchGuider = new TouchGuider(); + touchGuider->StartUp(); + SetNextEventTransmitter(header, current, touchGuider); + } + + SetNextEventTransmitter(header, current, this); + eventTransmitters_.insert(std::make_pair(EventType::OTHER, header)); + + if (availableFunctions_ & FEATURE_FILTER_KEY_EVENTS) { + sptr keyEventFilter = new KeyEventFilter(); + ams_->SetKeyEventFilter(keyEventFilter); + keyEventFilter->SetNext(this); + eventTransmitters_.insert(std::make_pair(EventType::KEY, keyEventFilter)); + } +} + +void AccessibilityInputFilter::DestroyTransmitters() +{ + HILOG_DEBUG(); + + for (auto iter = eventTransmitters_.begin(); iter != eventTransmitters_.end(); iter++) { + iter->second->DestroyEvents(); + } + ams_->SetTouchEventInjector(nullptr); + ams_->SetKeyEventFilter(nullptr); + eventTransmitters_.clear(); +} + +void AccessibilityInputFilter::NotifyAccessibilityEvent(AccessibilityEventInfo &event) const +{ + HILOG_DEBUG(); + + for (auto iter = eventTransmitters_.begin(); iter != eventTransmitters_.end(); iter++) { + iter->second->OnAccessibilityEvent(event); + } +} + +void AccessibilityInputFilter::ProcessTouchEvent(TouchEvent &event) +{ + HILOG_DEBUG(); + + if (eventTransmitters_.empty() || + (eventTransmitters_.find(EventType::OTHER) == eventTransmitters_.end())) { + HILOG_DEBUG("eventTransmitters_ is empty."); + return; + } + PowerMgr::PowerMgrClient::GetInstance().RefreshActivity(); + eventTransmitters_.at(EventType::OTHER)->OnTouchEvent(event); +} + +void AccessibilityInputFilter::ProcessMouseEvent(MouseEvent &event) +{ + HILOG_DEBUG(); + + if (eventTransmitters_.empty() || + (eventTransmitters_.find(EventType::OTHER) == eventTransmitters_.end())) { + HILOG_DEBUG("eventTransmitters_ is empty."); + return; + } + PowerMgr::PowerMgrClient::GetInstance().RefreshActivity(); + eventTransmitters_.at(EventType::OTHER)->OnMouseEvent(event); +} + +void AccessibilityInputFilter::ProcessKeyEvent(MMI::KeyEvent &event) +{ + HILOG_DEBUG(); + + if (eventTransmitters_.empty() || + (eventTransmitters_.find(EventType::KEY) == eventTransmitters_.end())) { + HILOG_DEBUG("eventTransmitters_ is empty."); + return; + } + + eventTransmitters_.at(EventType::KEY)->OnKeyEvent(event); +} + +void AccessibilityInputFilter::SetNextEventTransmitter(sptr &header, + sptr ¤t, const sptr &next) +{ + HILOG_DEBUG(); + + if (current != nullptr) { + current->SetNext(next); + } else { + header = next; + } + current = next; +} + +} +} // namespace accessibility \ No newline at end of file diff --git a/services/aams/src/accessibility_interaction_bridge.cpp b/services/aams/src/accessibility_interaction_bridge.cpp new file mode 100644 index 00000000..ffcec318 --- /dev/null +++ b/services/aams/src/accessibility_interaction_bridge.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2021 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. + */ +#include "accessibility_interaction_bridge.h" +#include +#include "accessibility_ability_info.h" +#include "accessibility_account_data.h" +#include "accessibility_display_manager.h" +#include "accessibility_window_manager.h" +#include "accessible_ability_connection.h" +#include "dummy.h" + +namespace OHOS { +namespace Accessibility { +const int INTERACTION_BRIDGE_CHANNEL_ID = 0; +const int NONE_ID = -1; + +AccessibilityInteractionBridge& AccessibilityInteractionBridge::GetInstance() +{ + HILOG_DEBUG("[%{public}s]", __func__); + static AccessibilityInteractionBridge instance_; + + return instance_; +} + +AccessibilityInteractionBridge::AccessibilityInteractionBridge() +{ + HILOG_DEBUG("[%{public}s]", __func__); + AppExecFwk::AbilityInfo info; + sptr abilityInfo = new AccessibilityAbilityInfo(info); + abilityInfo->SetCapabilityValues(Capability::CAPABILITY_RETRIEVE); + accountData_ = DelayedSingleton::GetInstance()->GetCurrentAccountData(); + connection_ = new AccessibleAbilityConnection(accountData_, INTERACTION_BRIDGE_CHANNEL_ID, *abilityInfo); + channel_ = new AccessibleAbilityChannelStubImpl(*connection_); + if (!channel_) { + HILOG_DEBUG("channel is nullptr."); + AccessibilityOperator::GetInstance().RemoveChannel(INTERACTION_BRIDGE_CHANNEL_ID); + } else { + HILOG_DEBUG("AddChannel start."); + AccessibilityOperator::GetInstance().AddChannel(INTERACTION_BRIDGE_CHANNEL_ID, channel_); + } + HILOG_INFO("AccessibleAbilityManagerService::AccessibilityInteractionBridge successfully"); +} + +AccessibilityElementInfo AccessibilityInteractionBridge::FindFocusedElementInfo() +{ + HILOG_DEBUG("[%{public}s without window]", __func__); + + return FindFocusedElementInfo(ANY_WINDOW_ID); +} + +bool AccessibilityInteractionBridge::PerformActionOnAccessibilityFocusedItem(const ActionType& action) +{ + HILOG_DEBUG("[%{public}s]", __func__); + auto focus = FindFocusedElementInfo(); + std::map actionArguments{}; + HILOG_DEBUG("[%{public}s ExecuteAction]", __func__); + return focus.ExecuteAction(action, actionArguments); +} + +bool Intersect(Rect& focus, Rect source) { + HILOG_DEBUG("[%{public}s]", __func__); + int minx = std::max(focus.GetLeftTopXScreenPostion(), source.GetLeftTopXScreenPostion()); + int miny = std::max(focus.GetLeftTopYScreenPostion(), source.GetLeftTopYScreenPostion()); + int maxx = std::min(focus.GetRightBottomXScreenPostion(), source.GetRightBottomXScreenPostion()); + int maxy = std::min(focus.GetRightBottomYScreenPostion(), source.GetRightBottomYScreenPostion()); + if ((minx > maxx) || (miny > maxy)) { + HILOG_DEBUG("The two Rects do not intersect"); + return false; + } + focus.SetLeftTopScreenPostion(minx,miny); + focus.SetRightBottomScreenPostion(maxx,maxy); + return true; +} + +bool Intersect(Rect& rect, AccessibilityWindowInfo window) { + HILOG_DEBUG("[%{public}s]", __func__); + if (!Intersect(rect, window.GetRectInScreen())) { + return false; + } + return true; +} + +bool Intersect(Rect& rect, WMDisplayInfo display) { + HILOG_DEBUG("[%{public}s]", __func__); + Rect source(0, 0, display.width, display.height); + if (!Intersect(rect,source)) { + return false; + } + return true; +} + + +bool AccessibilityInteractionBridge::GetAccessibilityFocusClickPointInScreen(MmiPoint &point) +{ + HILOG_DEBUG("[%{public}s]", __func__); + auto focus = FindFocusedElementInfo(); + auto focusRect = focus.GetRectInScreen(); + /* Apply magnification if needed.**/ + //TODO + /* Apply magnification if needed.**/ + //Intersect with window + auto windowManager = AccessibilityWindowInfoManager::GetInstance(); + AccessibilityWindowInfo window; + auto result = windowManager.GetAccessibilityWindow(windowManager.activeWindowId_, window); + if (!result) { + return false; + } + if (!Intersect(focusRect, window)) { + return false; + } + //Intersect with display dummy + auto displayInfo = AccessibilityDisplayManager::GetInstance().GetDefaultDisplay(); + if (!Intersect(focusRect, displayInfo)) { + return false; + } + + float px = (focusRect.GetLeftTopXScreenPostion() + focusRect.GetRightBottomXScreenPostion())/2; + float py = (focusRect.GetLeftTopYScreenPostion() + focusRect.GetRightBottomYScreenPostion())/2; + point.Setxy(px, py); + return true; +} +AccessibilityElementInfo AccessibilityInteractionBridge::FindFocusedElementInfo(const int &windowId) +{ + HILOG_DEBUG("[%{public}s with window]", __func__); + AccessibilityElementInfo info {}; + bool result = AccessibilityOperator::GetInstance().FindFocusedElementInfo(INTERACTION_BRIDGE_CHANNEL_ID, + windowId,NONE_ID,FOCUS_TYPE_ACCESSIBILITY, info); + if (!result) { + HILOG_ERROR("result is false"); + } + return info; +} + +} // namespace Accessibility +} // namespace OHOS diff --git a/services/aams/src/accessibility_interaction_connection.cpp b/services/aams/src/accessibility_interaction_connection.cpp new file mode 100644 index 00000000..93816cfc --- /dev/null +++ b/services/aams/src/accessibility_interaction_connection.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_interaction_connection.h" + +using namespace std; + +namespace OHOS{ +namespace Accessibility{ + +AccessibilityInteractionConnection::AccessibilityInteractionConnection(const int windowId, + const sptr &connection, const int accountId) { + windowId_ = windowId; + proxy_ = connection; + accountId_ = accountId; +} + +AccessibilityInteractionConnection::~AccessibilityInteractionConnection() { + +} + +} // namespace Accessibility +} // namespace OHOS diff --git a/services/aams/src/accessibility_keyevent_filter.cpp b/services/aams/src/accessibility_keyevent_filter.cpp new file mode 100644 index 00000000..703f04c6 --- /dev/null +++ b/services/aams/src/accessibility_keyevent_filter.cpp @@ -0,0 +1,239 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_keyevent_filter.h" +#include "accessible_ability_manager_service.h" +#include "hilog_wrapper.h" +#include "power_mgr_client.h" + +namespace OHOS { +namespace Accessibility { + +int64_t TASK_TIME = 500; + +KeyEventFilter::KeyEventFilter() +{ + HILOG_DEBUG(); + + aams_ = DelayedSingleton::GetInstance(); + if (aams_ != nullptr) { + HILOG_DEBUG(); + + runner_ = aams_->GetMainRunner(); + if (!runner_) { + HILOG_ERROR("get runner failed"); + return ; + } + + timeouthandler_ = std::make_shared(runner_, *this); + if (!timeouthandler_) { + HILOG_ERROR("create event handler failed"); + return ; + } + } +} + +KeyEventFilter::~KeyEventFilter() +{ + HILOG_DEBUG(); + + eventMaps_.clear(); +} + +void KeyEventFilter::OnKeyEvent(MMI::KeyEvent &event) +{ + HILOG_DEBUG(); + + bool whetherIntercept = aams_->IsWantedKeyEvent(event); + if (whetherIntercept) { + DispatchKeyEvent(event); + } else { + EventTransmission::OnKeyEvent(event); + } +} + +void KeyEventFilter::SetServiceOnKeyEventResult(AccessibleAbilityConnection &connection, bool isHandled, + uint32_t sequenceNum) +{ + HILOG_DEBUG("isHandled[%{public}d], sequenceNum[%{public}u].", isHandled, sequenceNum); + + std::shared_ptr processingEvent = FindProcessingEvent(connection, sequenceNum); + if (processingEvent == nullptr) { + HILOG_DEBUG("No event being processed."); + return; + } + + if (!isHandled) { + if (processingEvent->usedCount_ == 0) { + timeouthandler_->RemoveEvent(processingEvent->seqNum_); + EventTransmission::OnKeyEvent(*processingEvent->event_); + } + } else { + timeouthandler_->RemoveEvent(processingEvent->seqNum_); + PowerMgr::PowerMgrClient::GetInstance().RefreshActivity( + PowerMgr::UserActivityType::USER_ACTIVITY_TYPE_ACCESSIBILITY); + RemoveProcessingEvent(processingEvent); + } +} + +void KeyEventFilter::ClearServiceKeyEvents(AccessibleAbilityConnection &connection) +{ + HILOG_DEBUG(); + + for (auto iter = eventMaps_.begin(); iter != eventMaps_.end(); iter++) { + if (iter->first.GetRefPtr() != &connection) { + continue; + } + + for (auto val : iter->second) { + val->usedCount_--; + if (val->usedCount_ == 0) { + EventTransmission::OnKeyEvent(*val->event_); + } + } + eventMaps_.erase(iter); + break; + } +} + +void KeyEventFilter::DispatchKeyEvent(MMI::KeyEvent &event) +{ + HILOG_DEBUG(); + + sptr accountData = aams_->GetCurrentAccountData(); + std::map> connectionMaps = accountData->GetConnectedA11yAbilities(); + + std::shared_ptr processingEvent = nullptr; + std::shared_ptr copyEvent = nullptr; + sequenceNum_++; + for (auto iter = connectionMaps.begin(); iter != connectionMaps.end(); iter++) { + if (iter->second->OnKeyPressEvent(event, sequenceNum_)) { + if (processingEvent == nullptr) { + processingEvent = std::make_shared(); + // TODO: fixme + // copyEvent = std::make_shared(event); + // processingEvent->event_ = copyEvent; + processingEvent->seqNum_ = sequenceNum_; + } + processingEvent->usedCount_++; + + if (eventMaps_.find(iter->second) == eventMaps_.end()) { + std::vector> processingEvens; + eventMaps_.insert(std::make_pair(iter->second, processingEvens)); + } + eventMaps_.at(iter->second).emplace_back(processingEvent); + } + } + + if (processingEvent == nullptr) { + HILOG_DEBUG("No service handles the event."); + sequenceNum_--; + EventTransmission::OnKeyEvent(event); + return; + } + + timeouthandler_->SendEvent(sequenceNum_, processingEvent, TASK_TIME); +} + +bool KeyEventFilter::RemoveProcessingEvent(std::shared_ptr event) +{ + HILOG_DEBUG(); + + bool haveEvent = false; + for (auto iter = eventMaps_.begin(); iter != eventMaps_.end(); iter++) { + for (auto val = iter->second.begin(); val != iter->second.end(); val++) { + if (*val != event) { + continue; + } + (*val)->usedCount_--; + iter->second.erase(val); + haveEvent = true; + break; + } + } + + return haveEvent; +} + +std::shared_ptr KeyEventFilter::FindProcessingEvent( + AccessibleAbilityConnection &connection, uint32_t sequenceNum) +{ + HILOG_DEBUG(); + + std::shared_ptr processingEvent = nullptr; + + for (auto iter = eventMaps_.begin(); iter != eventMaps_.end(); iter++) { + if (iter->first.GetRefPtr() != &connection) { + continue; + } + + for (auto val = iter->second.begin(); val != iter->second.end(); val++) { + if ((*val)->seqNum_ != sequenceNum) { + continue; + } + processingEvent = *val; + iter->second.erase(val); + processingEvent->usedCount_--; + break; + } + break; + } + + return processingEvent; +} + +void KeyEventFilter::DestroyEvents() +{ + HILOG_DEBUG(); + + timeouthandler_->RemoveAllEvents(); + eventMaps_.clear(); +} + +void KeyEventFilter::SendEventToParent(MMI::KeyEvent &event) +{ + HILOG_DEBUG(); + EventTransmission::OnKeyEvent(event); +} + +KeyEventFilterEventHandler::KeyEventFilterEventHandler(const std::shared_ptr &runner, KeyEventFilter &keyEventFilter) + : AppExecFwk::EventHandler(runner), keyEventFilter_(keyEventFilter) +{ + HILOG_DEBUG("KeyEventFilterEventHandler is created"); +} + +void KeyEventFilterEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +{ + HILOG_DEBUG(); + + if (event == nullptr) { + HILOG_ERROR("event is null."); + return; + } + + auto processingEvent = event->GetSharedObject(); + if (processingEvent->seqNum_ != event->GetInnerEventId()) { + HILOG_ERROR("event is wrong."); + return; + } + + bool haveEvent = keyEventFilter_.RemoveProcessingEvent(processingEvent); + if (haveEvent) { + keyEventFilter_.SendEventToParent(*processingEvent->event_); + } +} + +} +} // namespace accessibility \ No newline at end of file diff --git a/services/aams/src/accessibility_touchEvent_injector.cpp b/services/aams/src/accessibility_touchEvent_injector.cpp new file mode 100644 index 00000000..3c04801f --- /dev/null +++ b/services/aams/src/accessibility_touchEvent_injector.cpp @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "accessibility_touchEvent_injector.h" + +namespace OHOS { +namespace Accessibility { + +TouchInjectHandler::TouchInjectHandler( + const std::shared_ptr &runner, TouchEventInjector &server) + : AppExecFwk::EventHandler(runner),server_(server) { + +} + +void TouchInjectHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) { + std::shared_ptr parameters = nullptr; + switch (event->GetInnerEventId()) { + case TouchEventInjector::SEND_TOUCH_EVENT_MSG: + parameters = event->GetSharedObject(); + server_.SendTouchEvent(parameters->event_); + if (parameters->isLastEvent_) { + server_.GetCurrentGestureService()->OnGestureSimulateResult(server_.GetSequence(), true); + } + break; + case TouchEventInjector::INJECT_EVENT_MSG: + server_.InjectEventsInner(); + break; + default: + break; + } +} + +TouchEventInjector::TouchEventInjector() { + runner_ = DelayedSingleton::GetInstance()->GetMainRunner(); + if (!runner_) { + HILOG_ERROR("get runner failed"); + return ; + } + handler_ = std::make_shared(runner_, *this); + if (!handler_) { + HILOG_ERROR("create event handler failed"); + return ; + } + +} + +void TouchEventInjector::OnTouchEvent(TouchEvent &event) { + CancelInjectedEvents(); + SendTouchEvent(event); +} + +void TouchEventInjector::OnMouseEvent(MouseEvent &event) { + if (event.GetAction() == TouchEnum::HOVER_POINTER_MOVE && isGestureUnderway_) { + return; + } + CancelInjectedEvents(); + EventTransmission::OnMouseEvent(event); +} + +void TouchEventInjector::ClearEvents(uint32_t inputSource) { + if (!handler_->HasInnerEvent(SEND_TOUCH_EVENT_MSG)) { + isGestureUnderway_ = false; + } + EventTransmission::ClearEvents(inputSource); +} + +void TouchEventInjector::DestroyEvents() { + HILOG_INFO("TouchEventInjector::DestroyEvents: start"); + CancelInjectedEvents(); + isDestroyEvent_ = true; + EventTransmission::DestroyEvents(); +} + +void TouchEventInjector::GetTapsEvents(long startTime) { + HILOG_INFO("TouchEventInjector::GetTapsEvents: start"); + TouchEvent event; + MmiPoint point; + long downTime = startTime; + long nowTime = startTime; + for (unsigned int i = 0; i < gesturePath_.size(); i++) { + /* append down event */ + float px = gesturePath_[i].GetStartPosition().GetPositionX(); + float py = gesturePath_[i].GetStartPosition().GetPositionY(); + point.Setxy(px, py); + event = obtainTouchEvent(downTime, nowTime, TouchEnum::PRIMARY_POINT_DOWN, point); + HILOG_INFO("append down event"); + injectedEvents_.push_back(event); + + nowTime += gesturePath_[i].GetDurationTime(); + /* append up event */ + px = gesturePath_[i].GetEndPosition().GetPositionX(); + py = gesturePath_[i].GetEndPosition().GetPositionY(); + point.Setxy(px, py); + event = obtainTouchEvent(downTime, nowTime, TouchEnum::PRIMARY_POINT_UP, point); + HILOG_INFO("append up event"); + injectedEvents_.push_back(event); + nowTime += DOUBLE_TAP_MIN_TIME; + } +} + +void TouchEventInjector::GetMovesEvents(long startTime) { + HILOG_INFO("TouchEventInjector::GetTapsEvents: start"); + TouchEvent event; + MmiPoint point; + long downTime = startTime; + long nowTime = startTime; + /* append down event */ + float px = gesturePath_[0].GetStartPosition().GetPositionX(); + float py = gesturePath_[0].GetStartPosition().GetPositionY(); + point.Setxy(px, py); + event = obtainTouchEvent(downTime, nowTime, TouchEnum::PRIMARY_POINT_DOWN, point); + HILOG_INFO("append down event"); + injectedEvents_.push_back(event); + for (unsigned int i = 0; i < gesturePath_.size(); i++) { + px = gesturePath_[i].GetEndPosition().GetPositionX(); + py = gesturePath_[i].GetEndPosition().GetPositionY(); + point.Setxy(px, py); + HILOG_INFO("append move event"); + event = obtainTouchEvent(downTime, nowTime, TouchEnum::POINT_MOVE, point); + injectedEvents_.push_back(event); + nowTime += gesturePath_[i].GetDurationTime(); + } + /* append up event */ + px = gesturePath_[gesturePath_.size() - 1].GetEndPosition().GetPositionX(); + py = gesturePath_[gesturePath_.size() - 1].GetEndPosition().GetPositionY(); + point.Setxy(px, py); + event = obtainTouchEvent(downTime, nowTime, TouchEnum::PRIMARY_POINT_UP, point); + HILOG_INFO("append up event"); + injectedEvents_.push_back(event); +} + +void TouchEventInjector::InjectEvents(const std::vector &gesturePath, + const sptr &service, int sequence ) { + sequence_ = sequence; + currentGestureService_ = service; + gesturePath_ = gesturePath; + handler_->SendEvent(INJECT_EVENT_MSG, 0, 0); +} + +void TouchEventInjector::InjectEventsInner() { + HILOG_INFO("TouchEventInjector::InjectEventsInner: start"); + + long curTime = getSystemTime(); + if (isDestroyEvent_ || !GetNext()) { + currentGestureService_->OnGestureSimulateResult(sequence_, false); + return; + } + CancelInjectedEvents(); + CancelGesture(); + + GetTouchEventsFromGesturePath(curTime); + + if (injectedEvents_.empty()) { + currentGestureService_->OnGestureSimulateResult(sequence_, false); + return; + } + for (unsigned int i = 0; i < injectedEvents_.size(); i++) { + std::shared_ptr parameters = std::make_shared(); + parameters->isLastEvent_ = (i == injectedEvents_.size() -1) ? true : false; + parameters->event_ = injectedEvents_[i]; + int64_t timeout = injectedEvents_[i].GetOccurredTime() - curTime; + + handler_->SendEvent(SEND_TOUCH_EVENT_MSG, parameters, timeout); + } + injectedEvents_.clear(); +} + +void TouchEventInjector::SendTouchEvent(TouchEvent &event) { + HILOG_INFO("TouchEventInjector::SendTouchEvent: start"); + if (GetNext() != nullptr) { + EventTransmission::OnTouchEvent(event); + if (event.GetAction() == TouchEnum::PRIMARY_POINT_DOWN) { + isGestureUnderway_ = true; + } + if (event.GetAction() == TouchEnum::PRIMARY_POINT_UP) { + isGestureUnderway_ = false; + } + } +} + +void TouchEventInjector::CancelGesture() { + HILOG_INFO("TouchEventInjector::CancelGesture: start"); + TouchEvent event; + MmiPoint point(0, 0); + long time = getSystemTime(); + if (GetNext() != nullptr && isGestureUnderway_) { + TouchEvent event = obtainTouchEvent(time, time, TouchEnum::CANCEL, point); + SendTouchEvent(event); + isGestureUnderway_ = false; + } +} + +void TouchEventInjector::CancelInjectedEvents() { + HILOG_INFO("TouchEventInjector::CancelInjectedEvents: start"); + if (handler_->HasInnerEvent(SEND_TOUCH_EVENT_MSG)) { + handler_->RemoveEvent(SEND_TOUCH_EVENT_MSG); + CancelGesture(); + currentGestureService_->OnGestureSimulateResult(sequence_, false); + } +} + +void TouchEventInjector::GetTouchEventsFromGesturePath(long startTime) { + HILOG_INFO("TouchEventInjector::GetTouchEventsFromGesturePath: start"); + if (gesturePath_[0].GetStartPosition().GetPositionX() == gesturePath_[0].GetEndPosition().GetPositionX() && + gesturePath_[0].GetStartPosition().GetPositionY() == gesturePath_[0].GetEndPosition().GetPositionY()) { + GetTapsEvents(startTime); + } else { + GetMovesEvents(startTime); + } +} + +TouchEvent TouchEventInjector::obtainTouchEvent(long startTime, long occurredTime, + int action, MmiPoint point) { + HILOG_INFO("TouchEventInjector::obtainTouchEvent: start"); + TouchEvent touchEvent; +#if 0 // TODO: Construct touchEvent + struct MultimodalProperty multimodal = { + .sourceType = SourceDevice::TOUCH_PANEL, + .occurredTime = occurredTime, + .deviceId = "", + .inputDeviceId = 0, + }; + struct ManipulationProperty manipulationProperty = { + .startTime = startTime, + .pointerCount = 1, + .pointerId = 0, + .mp = point, + .offsetX = 0, + .offsetY = 0 + }; + struct TouchProperty touch = { + .action = action, + .index = 0, + }; + touchEvent.Initialize(multimodal, manipulationProperty, touch); +#endif + return touchEvent; +} + +long TouchEventInjector::getSystemTime() { + HILOG_INFO("TouchEventInjector::getSystemTime: start"); + struct timespec times = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, ×); + long millisecond = times.tv_sec * 1000 + times.tv_nsec / 1000000; + + return millisecond; +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/services/aams/src/accessibility_touch_guider.cpp b/services/aams/src/accessibility_touch_guider.cpp new file mode 100644 index 00000000..212dfa9e --- /dev/null +++ b/services/aams/src/accessibility_touch_guider.cpp @@ -0,0 +1,764 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "accessibility_touch_guider.h" +#include "accessibility_window_manager.h" + +namespace OHOS{ +namespace Accessibility{ + +TGEventHandler::TGEventHandler( + const std::shared_ptr &runner, TouchGuider &tgServer) + : AppExecFwk::EventHandler(runner),tgServer_(tgServer) { + +} + +TouchGuider::TouchGuider() { + + currentState_ = static_cast(TouchGuideState::TOUCH_GUIDING); + pAams_ = DelayedSingleton::GetInstance(); +} + +void TouchGuider::StartUp() { + touchGuideListener_ = std::make_unique(*this); + gestureRecognizer_.registerListener(touchGuideListener_.get()); + runner_ = pAams_->GetMainRunner(); + if (!runner_) { + HILOG_ERROR("get runner failed"); + return ; + } + + handler_ = std::make_shared(runner_, *this); + if (!handler_) { + HILOG_ERROR("create event handler failed"); + return ; + } +} + +void TGEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) { + switch (event->GetInnerEventId()) { + case TouchGuider::EXIT_GESTURE_REC_MSG: + tgServer_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_GESTURE_END); + break; + case TouchGuider::SEND_HOVER_ENTER_MOVE_MSG: + HoverEnterAndMoveRunner(); + break; + case TouchGuider::SEND_HOVER_EXIT_MSG: + HoverExitRunner(); + break; + case TouchGuider::SEND_TOUCH_INTERACTION_END_MSG: + tgServer_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END); + break; + case TouchGuider::SEND_TOUCH_GUIDE_END_MSG: + tgServer_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_END); + break; + default: + break; + } +} + +void TouchGuider::OnTouchEvent(TouchEvent &event) { + if (event.GetAction() == TouchEnum::CANCEL) { + Clear(event); + return; + } + + RecordReceivedEvent(event); + + if (gestureRecognizer_.OnTouchEvent(event)) { + return; + } + + switch (static_cast(currentState_)) { + case TouchGuideState::TOUCH_GUIDING: + HandleTouchGuidingState(event); + break; + case TouchGuideState::DRAGGING: + HandleDraggingState(event); + break; + case TouchGuideState::TRANSMITING: + HandleTransmitingState(event); + break; + case TouchGuideState::GESTURE_RECOGNIZING: + break; + default: + break; + } +} + +void TouchGuider::OnAccessibilityEvent(AccessibilityEventInfo &event) { + int eventType = event.GetEventType(); + + if (eventType == EventType::TYPE_VIEW_HOVER_EXIT_EVENT) { + if (HasEventPending(SEND_TOUCH_GUIDE_END_MSG)) { + CancelPostEvent(SEND_TOUCH_GUIDE_END_MSG); + SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_END); + } + if (HasEventPending(SEND_TOUCH_INTERACTION_END_MSG)) { + CancelPostEvent(SEND_TOUCH_INTERACTION_END_MSG); + SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END); + } + } + EventTransmission::OnAccessibilityEvent(event); +} + +void TouchGuider::ClearEvents(uint32_t inputSource) { + if (inputSource == SourceDevice::TOUCH_PANEL) { + Clear(); + } + EventTransmission::ClearEvents(inputSource); +} + +void TouchGuider::DestroyEvents() { + Clear(); + EventTransmission::DestroyEvents(); +} + +void TouchGuider::SendAccessibilityEventToAA(EventType eventType) { + AccessibilityEventInfo eventInfo {}; + eventInfo.SetEventType(eventType); + int windowsId = AccessibilityWindowInfoManager::GetInstance().activeWindowId_; + eventInfo.SetWindowId(windowsId); + pAams_->SendEvent(eventInfo, pAams_->GetCurrentAccountId()); + if (eventType == EventType::TYPE_TOUCH_GUIDE_BEGIN) { + isTouchGuiding_ = true; + } else if (eventType == EventType::TYPE_TOUCH_GUIDE_END) { + isTouchGuiding_ = false; + } +} + +void TouchGuider::SendEventToMultimodal(TouchEvent &event, int action) { + TouchEvent touchEvent; + // struct MultimodalProperty multimodal = { + // .highLevelEvent = event.GetHighLevelEvent(), + // .uuid = event.GetUuid(), + // .sourceType = event.GetSourceDevice(), + // .occurredTime = event.GetOccurredTime(), + // .deviceId = event.GetDeviceId(), + // .inputDeviceId = event.GetInputDeviceId(), + // .isHighLevelEvent = event.IsHighLevelInput() + // }; + // struct ManipulationProperty manipulationProperty = { + // .operationState = event.GetPhase(), + // .pointerCount = event.GetPointerCount(), + // .pointerId = event.GetPointerId(event.GetIndex()), + // .mp = event.GetPointerScreenPosition(event.GetIndex()), + // .touchArea = event.GetForce(event.GetIndex()), + // .touchPressure = event.GetRadius(event.GetIndex()) + // }; + // struct TouchProperty touch = { + // .action = action, + // .index = event.GetIndex(), + // .forcePrecision = event.GetForcePrecision(), + // .maxForce = event.GetMaxForce(), + // .tapCount = event.GetTapCount() + // }; +#if 0 // TODO: Set Property + if (action == TouchEnum::PRIMARY_POINT_DOWN) { + manipulationProperty.startTime = event.GetStartTime(); + } else { + manipulationProperty.startTime = injectedRecorder_.lastDownTime; + } + if (longPressPointId_ >= 0) { + manipulationProperty.offsetX = longPressOffsetX_; + manipulationProperty.offsetY = longPressOffsetY_; + } +#endif + // touchEvent.Initialize(multimodal, manipulationProperty, touch); + touchEvent.Initialize(event); + EventTransmission::OnTouchEvent(touchEvent); + RecordInjectedEvent(touchEvent); +} + +std::vector TouchGuider::getHoverEnterAndMoveEvent() { + return motionEvent_; +} + +void TouchGuider::ClearHoverEnterAndMoveEvent() { + motionEvent_.clear(); + gestureRecognizer_.Clear(); +} + +std::shared_ptr TouchGuider::getLastReceivedEvent() { + return receivedRecorder_.lastEvent; +} + +void TouchGuider::TouchGuideListener::OnDoubleTapLongPress(TouchEvent &event) { + MmiPoint clickPoint(INIT_MMIPOINT, INIT_MMIPOINT); + if (server_.currentState_ != static_cast(TouchGuideState::TOUCH_GUIDING)) { + return; + } + if (server_.getLastReceivedEvent() && + server_.getLastReceivedEvent()->GetPointerCount() == 0) { + return; + } + int ret = GetClickPosition(clickPoint); + if (ret == CLICK_NONE) { + return; + } + server_.longPressPointId_ = event.GetPointerId(event.GetIndex()); + MmiPoint eventPoint = event.GetPointerPosition(event.GetIndex()); + server_.longPressOffsetX_ = eventPoint.GetX() - clickPoint.GetX(); + server_.longPressOffsetY_ = eventPoint.GetY() - clickPoint.GetY(); + + server_.SendExitEvents(); + server_.currentState_ = static_cast(TouchGuideState::TRANSMITING); + server_.SendAllDownEvents(event); +} + +bool TouchGuider::TouchGuideListener::OnDoubleTap(TouchEvent &event) { + MmiPoint clickPoint(INIT_MMIPOINT, INIT_MMIPOINT); + if (server_.currentState_ != static_cast(TouchGuideState::TOUCH_GUIDING)) { + return false; + } + server_.pAams_->OnTouchInteractionEnd(); + server_.CancelPostEventIfNeed(server_.SEND_HOVER_ENTER_MOVE_MSG); + server_.CancelPostEventIfNeed(server_.SEND_HOVER_EXIT_MSG); + server_.ForceSendAndRemoveEvent(server_.SEND_TOUCH_GUIDE_END_MSG, event); + server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END); + + if (server_.pAams_->PerformActionOnAccessibilityFocusedItem(ActionType::ACCESSIBILITY_ACTION_CLICK)) { + return true; + } + int ret = GetClickPosition(clickPoint); + if (ret == CLICK_NONE) { + return true; + } + return TransformToSingleTap(event, clickPoint); +} + +bool TouchGuider::TouchGuideListener::OnStarted() { + server_.currentState_ = static_cast(TouchGuideState::TRANSMITING); + server_.CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG); + server_.CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG); + server_.PostGestureRecognizeExit(); + server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN); + return false; +} + +bool TouchGuider::TouchGuideListener::OnCompleted(int gestureId) { + if (server_.currentState_ != static_cast(TouchGuideState::TRANSMITING)) { + return false; + } + server_.pAams_->OnTouchInteractionEnd(); + server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_GESTURE_END); + server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END); + server_.CancelPostEvent(EXIT_GESTURE_REC_MSG); + server_.currentState_ = static_cast(TouchGuideState::TOUCH_GUIDING); + + server_.pAams_->OnGesture(gestureId); + + return true; +} + +bool TouchGuider::TouchGuideListener::OnCancelled(TouchEvent &event) { + switch (static_cast(server_.currentState_)) { + case TouchGuideState::TRANSMITING: + server_.pAams_->OnTouchInteractionEnd(); + server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_GESTURE_END); + if (event.GetAction() == TouchEnum::PRIMARY_POINT_UP) { + server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END); + } + server_.CancelPostEvent(EXIT_GESTURE_REC_MSG); + server_.currentState_ = static_cast(TouchGuideState::TOUCH_GUIDING); + break; + case TouchGuideState::TOUCH_GUIDING: + server_.motionEvent_.push_back(event); + server_.ForceSendAndRemoveEvent(SEND_HOVER_ENTER_MOVE_MSG, event); + server_.CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG); + server_.SendEventToMultimodal(event, TouchEnum::HOVER_POINTER_MOVE); + break; + default: + return false; + } + return true; +} + +int TouchGuider::TouchGuideListener::GetClickPosition(MmiPoint &outPoint) { + std::shared_ptr lastTGEvent = server_.injectedRecorder_.lastHoverEvent; + if (lastTGEvent) { + float px = lastTGEvent->GetPointerPosition(lastTGEvent->GetIndex()).GetX(); + float py = lastTGEvent->GetPointerPosition(lastTGEvent->GetIndex()).GetY(); + outPoint.Setxy(px, py); + if (server_.pAams_->GetAccessibilityFocusClickPointInScreen(outPoint)) { + return CLICK_ACCESSIBILITY_FOCUS; + } else { + return CLICK_LAST_TOUCH_GUIDE; + } + } + if (server_.pAams_->GetAccessibilityFocusClickPointInScreen(outPoint)) { + return CLICK_ACCESSIBILITY_FOCUS; + } + + return CLICK_NONE; +} + +bool TouchGuider::TouchGuideListener::TransformToSingleTap(TouchEvent &event, MmiPoint &point) { + TouchEvent touchEvent; +#if 0 // TODO + struct MultimodalProperty multimodal = { + .highLevelEvent = event.GetHighLevelEvent(), + .uuid = event.GetUuid(), + .sourceType = event.GetSourceDevice(), + .occurredTime = event.GetOccurredTime(), + .deviceId = event.GetDeviceId(), + .inputDeviceId = event.GetInputDeviceId(), + .isHighLevelEvent = event.IsHighLevelInput() + }; + struct ManipulationProperty manipulationProperty = { + .startTime = event.GetStartTime(), + .operationState = event.GetPhase(), + .pointerCount = event.GetPointerCount(), + .pointerId = event.GetPointerId(event.GetIndex()), + .mp = point, + .touchArea = event.GetForce(event.GetIndex()), + .touchPressure = event.GetRadius(event.GetIndex()), + .offsetX = 0, + .offsetY = 0 + }; + struct TouchProperty touch = { + .action = TouchEnum::PRIMARY_POINT_DOWN, + .index = event.GetIndex(), + .forcePrecision = event.GetForcePrecision(), + .maxForce = event.GetMaxForce(), + .tapCount = event.GetTapCount() + }; + touchEvent.Initialize(multimodal, manipulationProperty, touch); +#endif + server_.SendEventToMultimodal(touchEvent, TouchEnum::PRIMARY_POINT_DOWN); + server_.SendEventToMultimodal(touchEvent, TouchEnum::PRIMARY_POINT_UP); + + return true; +} + +void TouchGuider::HandleTouchGuidingState(TouchEvent &event) { + switch (event.GetAction()) { + case TouchEnum::PRIMARY_POINT_DOWN: + HandleTouchGuidingStateInnerDown(event); + break; + case TouchEnum::OTHER_POINT_DOWN: + CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG); + CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG); + break; + case TouchEnum::POINT_MOVE: + HandleTouchGuidingStateInnerMove(event); + break; + case TouchEnum::PRIMARY_POINT_UP: + pAams_->OnTouchInteractionEnd(); + if (HasEventPending(SEND_HOVER_ENTER_MOVE_MSG)) { + PostHoverExit(); + } else { + SendExitEvents(); + } + if (!HasEventPending(SEND_TOUCH_INTERACTION_END_MSG)) { + PostAccessibilityEvent(SEND_TOUCH_INTERACTION_END_MSG); + } + break; + default: + break; + } +} + +void TouchGuider::HandleDraggingState(TouchEvent &event) { + switch (event.GetAction()) { + case TouchEnum::PRIMARY_POINT_DOWN: + Clear(event); + break; + case TouchEnum::OTHER_POINT_DOWN: + currentState_ = static_cast(TouchGuideState::TRANSMITING); + SendEventToMultimodal(event, TouchEnum::PRIMARY_POINT_UP); + SendAllDownEvents(event); + break; + case TouchEnum::POINT_MOVE: + HandleDraggingStateInnerMove(event); + break; + case TouchEnum::OTHER_POINT_UP: + SendEventToMultimodal(event, TouchEnum::PRIMARY_POINT_UP); + break; + case TouchEnum::PRIMARY_POINT_UP: + pAams_->OnTouchInteractionEnd(); + SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END); + SendEventToMultimodal(event, TouchEnum::PRIMARY_POINT_UP); + currentState_ = static_cast(TouchGuideState::TOUCH_GUIDING); + break; + default: + break; + } +} + +void TouchGuider::HandleTransmitingState(TouchEvent &event) { + switch (event.GetAction()) { + case TouchEnum::PRIMARY_POINT_DOWN: + Clear(event); + break; + case TouchEnum::PRIMARY_POINT_UP: + if (longPressPointId_ >= 0) { + event.SetScreenOffset(longPressOffsetX_, longPressOffsetY_); + longPressPointId_ = INIT_POINT_ID; + longPressOffsetX_ = INIT_MMIPOINT; + longPressOffsetY_ = INIT_MMIPOINT; + } + SendEventToMultimodal(event, TouchEnum::PRIMARY_POINT_UP); + pAams_->OnTouchInteractionEnd(); + SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END); + currentState_ = static_cast(TouchGuideState::TOUCH_GUIDING); + break; + default: + SendEventToMultimodal(event, event.GetAction()); + break; + } +} + +void TouchGuider::Clear(TouchEvent &event) { + if (currentState_ == static_cast(TouchGuideState::TOUCH_GUIDING)) { + SendExitEvents(); + } else if (currentState_ == static_cast(TouchGuideState::DRAGGING) + || currentState_ == static_cast(TouchGuideState::TRANSMITING)) { + SendUpForAllInjectedEvent(event); + } + + CancelPostEvent(EXIT_GESTURE_REC_MSG); + CancelPostEvent(SEND_TOUCH_INTERACTION_END_MSG); + CancelPostEvent(SEND_TOUCH_GUIDE_END_MSG); + CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG); + CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG); + ClearInjectedEventRecorder(); + ClearReceivedEventRecorder(); + motionEvent_.clear(); + currentState_ = static_cast(TouchGuideState::TOUCH_GUIDING); + isTouchGuiding_ = false; + gestureRecognizer_.Clear(); + longPressPointId_ = INIT_POINT_ID; + longPressOffsetX_ = INIT_MMIPOINT; + longPressOffsetY_ = INIT_MMIPOINT; + pAams_->OnTouchInteractionEnd(); +} + +void TouchGuider::Clear() { + std::shared_ptr event = getLastReceivedEvent(); + if (event) { + Clear(*event); + } +} + +void TouchGuider::SendExitEvents() { + std::shared_ptr event = injectedRecorder_.lastHoverEvent; + if (event && event->GetAction() != TouchEnum::HOVER_POINTER_EXIT) { + if (!HasEventPending(SEND_TOUCH_GUIDE_END_MSG)) { + PostAccessibilityEvent(SEND_TOUCH_GUIDE_END_MSG); + } + SendEventToMultimodal(*event, TouchEnum::HOVER_POINTER_EXIT); + } +} + +void TouchGuider::HandleTouchGuidingStateInnerDown(TouchEvent &event) { + pAams_->OnTouchInteractionStart(); + CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG); + CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG); + if (isTouchGuiding_) { + SendExitEvents(); + } + if (!gestureRecognizer_.IsfirstTap()) { + ForceSendAndRemoveEvent(SEND_TOUCH_GUIDE_END_MSG, event); + ForceSendAndRemoveEvent(SEND_TOUCH_INTERACTION_END_MSG, event); + SendAccessibilityEventToAA(EventType::TYPE_TOUCH_BEGIN); + if (!isTouchGuiding_) { + if (!HasEventPending(SEND_HOVER_ENTER_MOVE_MSG)) { + PostHoverEnterAndMove(event); + } else { + motionEvent_.push_back(event); + } + } + } else { + CancelPostEvent(SEND_TOUCH_INTERACTION_END_MSG); + } +} + +void TouchGuider::HandleTouchGuidingStateInnerMove(TouchEvent &event) { + std::shared_ptr lastInjectEvent = injectedRecorder_.lastHoverEvent; + switch (event.GetPointerCount()) { + case POINTER_COUNT_1: + if (HasEventPending(SEND_HOVER_ENTER_MOVE_MSG)) { + motionEvent_.push_back(event); + } else if (isTouchGuiding_) { + if (lastInjectEvent && lastInjectEvent->GetAction() != TouchEnum::HOVER_POINTER_EXIT) { + SendEventToMultimodal(*lastInjectEvent, TouchEnum::HOVER_POINTER_ENTER); + } + SendEventToMultimodal(event, TouchEnum::HOVER_POINTER_MOVE); + } + break; + case POINTER_COUNT_2: + CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG); + CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG); + if (IsDragGestureAccept(event)) { + currentState_ = static_cast(TouchGuideState::DRAGGING); + SendEventToMultimodal(event, TouchEnum::PRIMARY_POINT_DOWN); + } else { + currentState_ = static_cast(TouchGuideState::TRANSMITING); + SendAllDownEvents(event); + } + break; + default: + if (HasEventPending(SEND_HOVER_ENTER_MOVE_MSG)) { + CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG); + CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG); + } else { + SendExitEvents(); + } + currentState_ = static_cast(TouchGuideState::TRANSMITING); + SendAllDownEvents(event); + break; + } +} + +void TouchGuider::HandleDraggingStateInnerMove(TouchEvent &event) { + int pointCount = event.GetPointerCount(); + if (pointCount == POINTER_COUNT_1) { + HILOG_INFO("Only two pointers can be received in the draging state"); + } else if (pointCount == POINTER_COUNT_2 && IsDragGestureAccept(event)) { + /* get densityPixels from WMS */ + AccessibilityDisplayManager &displayMgr = AccessibilityDisplayManager::GetInstance(); + float densityPixels = displayMgr.GetDefaultDisplay().dpi; + int miniZoomPointerDistance = (int)MINI_POINTER_DISTANCE_DIP * densityPixels; + float xPointF = event.GetPointerPosition(INDEX_0).GetX(); + float xPointS = event.GetPointerPosition(INDEX_1).GetX(); + float yPointF = event.GetPointerPosition(INDEX_0).GetY(); + float yPointS = event.GetPointerPosition(INDEX_1).GetY(); + float offsetX = abs(xPointF - xPointS); + float offsetY = abs(yPointF - yPointS); + double duration = hypot(offsetX , offsetY); + if (duration > miniZoomPointerDistance) { + event.SetScreenOffset(DIVIDE_2(offsetX), DIVIDE_2(offsetY)); + } + SendEventToMultimodal(event, TouchEnum::POINT_MOVE); + } else { + currentState_ = static_cast(TouchGuideState::TRANSMITING); + SendEventToMultimodal(event, TouchEnum::PRIMARY_POINT_UP); + SendAllDownEvents(event); + } +} + +float TouchGuider::GetAngleCos(float offsetX, float offsetY, bool isGetX) { + float ret = isGetX ? offsetX : offsetY; + double duration = hypot(offsetX, offsetY); + if (duration != 0) { + ret = ret / duration; + } + return ret; +} + +bool TouchGuider::IsDragGestureAccept(TouchEvent &event) { + float xPointF = event.GetPointerPosition(INDEX_0).GetX(); + float xPointS = event.GetPointerPosition(INDEX_1).GetX(); + float yPointF = event.GetPointerPosition(INDEX_0).GetY(); + float yPointS = event.GetPointerPosition(INDEX_1).GetY(); + float xPointDownF = receivedRecorder_.pointerDownX[INDEX_0]; + float xPointDownS = receivedRecorder_.pointerDownX[INDEX_1]; + float yPointDownF = receivedRecorder_.pointerDownY[INDEX_0]; + float yPointDownS = receivedRecorder_.pointerDownY[INDEX_1]; + + float firstOffsetX = xPointF - xPointDownF; + float firstOffsetY = yPointF - yPointDownF; + float secondOffsetX = xPointS - xPointDownS; + float secondOffsetY = yPointS - yPointDownS; + + if ((firstOffsetX == 0 && firstOffsetY == 0) || + (secondOffsetX == 0 && secondOffsetY == 0)) + return true; + + float firstXCos = GetAngleCos(firstOffsetX, firstOffsetY, true); + float firstYCos = GetAngleCos(firstOffsetX, firstOffsetY, false); + float secondXCos = GetAngleCos(secondOffsetX, secondOffsetY, true); + float secondYCos = GetAngleCos(secondOffsetX, secondOffsetY, false); + + if ((firstXCos * secondXCos + firstYCos * secondYCos) < MAX_DRAG_GESTURE_COSINE) + return false; + + return true; +} + +void TouchGuider::RecordInjectedEvent(TouchEvent &event) { + int pointId = event.GetPointerId(event.GetIndex()); + switch (event.GetAction()) { + case TouchEnum::PRIMARY_POINT_DOWN: + case TouchEnum::OTHER_POINT_DOWN: + injectedRecorder_.downPointerNum++; + injectedRecorder_.downPointers |= (1 << pointId); + injectedRecorder_.lastDownTime = event.GetStartTime(); + break; + case TouchEnum::PRIMARY_POINT_UP: + case TouchEnum::OTHER_POINT_UP: + injectedRecorder_.downPointers &= ~(1 << pointId); + if (injectedRecorder_.downPointerNum > 0) { + injectedRecorder_.downPointerNum--; + } + if (injectedRecorder_.downPointers == 0) { + injectedRecorder_.lastDownTime = 0; + } + break; + case TouchEnum::HOVER_POINTER_ENTER: + case TouchEnum::HOVER_POINTER_MOVE: + case TouchEnum::HOVER_POINTER_EXIT: + injectedRecorder_.lastHoverEvent = std::make_shared(event); + break; + default: + break; + } +} + +void TouchGuider::RecordReceivedEvent(TouchEvent &event) { + int index = event.GetIndex(); + int pointId = event.GetPointerId(index); + receivedRecorder_.lastEvent = std::make_shared(event); + switch (event.GetAction()) { + case TouchEnum::PRIMARY_POINT_DOWN: + case TouchEnum::OTHER_POINT_DOWN: + receivedRecorder_.pointerDownX[pointId] = event.GetPointerPosition(index).GetX(); + receivedRecorder_.pointerDownY[pointId] = event.GetPointerPosition(index).GetY(); + break; + case TouchEnum::PRIMARY_POINT_UP: + case TouchEnum::OTHER_POINT_UP: + receivedRecorder_.pointerDownX[pointId] = 0; + receivedRecorder_.pointerDownY[pointId] = 0; + break; + default: + break; + } +} + +void TouchGuider::ClearReceivedEventRecorder() { + memset(receivedRecorder_.pointerDownX, 0, sizeof(receivedRecorder_.pointerDownX)); + memset(receivedRecorder_.pointerDownY, 0, sizeof(receivedRecorder_.pointerDownY)); + receivedRecorder_.lastEvent = nullptr; +} + +void TouchGuider::ClearInjectedEventRecorder() { + injectedRecorder_.downPointerNum = 0; + injectedRecorder_.downPointers = 0; + injectedRecorder_.lastHoverEvent = nullptr; +} + +void TouchGuider::SendAllDownEvents(TouchEvent &event) { + int pointId = INIT_POINT_ID; + for (int i = 0; i < event.GetPointerCount(); i++) { + pointId = event.GetPointerId(i); + if (!(injectedRecorder_.downPointers & (1 << pointId))) { + int action = injectedRecorder_.downPointerNum == 0 ? TouchEnum::PRIMARY_POINT_DOWN : TouchEnum::OTHER_POINT_DOWN; + SendEventToMultimodal(event, action); + } + } +} + +void TouchGuider::SendUpForAllInjectedEvent(TouchEvent &event) { + int pointId = INIT_POINT_ID; + for (int i = 0; i < event.GetPointerCount(); i++) { + pointId = event.GetPointerId(i); + if (!(injectedRecorder_.downPointers & (1 << pointId))) { + continue; + } + int action = injectedRecorder_.downPointerNum == 1 ? TouchEnum::PRIMARY_POINT_UP : TouchEnum::OTHER_POINT_UP; + SendEventToMultimodal(event, action); + } +} + +void TouchGuider::PostGestureRecognizeExit() { + handler_->SendEvent(EXIT_GESTURE_REC_MSG, 0, EXIT_GESTURE_REC_TIMEOUT); +} + +void TouchGuider::PostHoverEnterAndMove(TouchEvent &event) { + CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG); + motionEvent_.push_back(event); + handler_->SendEvent(SEND_HOVER_ENTER_MOVE_MSG, 0, DOUBLE_TAP_TIMEOUT); +} + +void TouchGuider::PostHoverExit() { + CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG); + handler_->SendEvent(SEND_HOVER_EXIT_MSG, 0, DOUBLE_TAP_TIMEOUT); +} + +void TouchGuider::PostAccessibilityEvent(uint32_t innerEventID) { + handler_->SendEvent(innerEventID, 0, EXIT_GESTURE_REC_TIMEOUT ); +} + +void TouchGuider::CancelPostEvent(uint32_t innerEventID) { + handler_->RemoveEvent(innerEventID); +} + +void TouchGuider::CancelPostEventIfNeed(uint32_t innerEventID) { + if (HasEventPending(innerEventID)) { + handler_->RemoveEvent(innerEventID); + if (innerEventID == SEND_HOVER_ENTER_MOVE_MSG) { + motionEvent_.clear(); + } + } +} + +bool TouchGuider::HasEventPending(uint32_t innerEventID) { + return handler_->HasInnerEvent(innerEventID); +} + +void TouchGuider::ForceSendAndRemoveEvent(uint32_t innerEventID, TouchEvent &event) { + if (HasEventPending(innerEventID)) { + switch (innerEventID) { + case SEND_HOVER_ENTER_MOVE_MSG: + SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_BEGIN); + if (!motionEvent_.empty()) { + SendEventToMultimodal(motionEvent_[INDEX_0], TouchEnum::HOVER_POINTER_ENTER); + for (unsigned int i = INDEX_1; i < motionEvent_.size(); i++) { + SendEventToMultimodal(motionEvent_[i], TouchEnum::HOVER_POINTER_MOVE); + } + } + motionEvent_.clear(); + break; + case SEND_TOUCH_INTERACTION_END_MSG: + SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END); + break; + case SEND_TOUCH_GUIDE_END_MSG: + SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_END); + break; + default: + break; + } + CancelPostEvent(innerEventID); + } +} + +void TGEventHandler::HoverEnterAndMoveRunner() { + std::vector motionEvent = tgServer_.getHoverEnterAndMoveEvent(); + tgServer_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_BEGIN); + if (!motionEvent.empty()) { + tgServer_.SendEventToMultimodal(motionEvent[INDEX_0], TouchEnum::HOVER_POINTER_ENTER); + for (unsigned int i = INDEX_1; i < motionEvent.size(); i++) { + tgServer_. SendEventToMultimodal(motionEvent[i], TouchEnum::HOVER_POINTER_MOVE); + } + } + tgServer_.ClearHoverEnterAndMoveEvent(); +} + +void TGEventHandler::HoverExitRunner() { + std::shared_ptr pEvent = tgServer_.getLastReceivedEvent(); + tgServer_.SendEventToMultimodal(*pEvent, TouchEnum::HOVER_POINTER_EXIT); + if (!HasInnerEvent(TouchGuider::SEND_TOUCH_GUIDE_END_MSG)) { + RemoveEvent(TouchGuider::SEND_TOUCH_GUIDE_END_MSG); + SendEvent(TouchGuider::SEND_TOUCH_GUIDE_END_MSG, 0, EXIT_GESTURE_REC_TIMEOUT ); + } + if (HasInnerEvent(TouchGuider::SEND_TOUCH_INTERACTION_END_MSG)) { + RemoveEvent(TouchGuider::SEND_TOUCH_INTERACTION_END_MSG); + SendEvent(TouchGuider::SEND_TOUCH_INTERACTION_END_MSG, 0, EXIT_GESTURE_REC_TIMEOUT ); + } +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/services/aams/src/accessibility_window_manager.cpp b/services/aams/src/accessibility_window_manager.cpp new file mode 100644 index 00000000..fbca4de3 --- /dev/null +++ b/services/aams/src/accessibility_window_manager.cpp @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "accessibility_window_manager.h" +#include "accessible_ability_manager_service.h" + +namespace OHOS { +namespace Accessibility { + +AccessibilityWindowInfoManager &AccessibilityWindowInfoManager::GetInstance() { + static AccessibilityWindowInfoManager windowManager; + return windowManager; +} + +int AccessibilityWindowInfoManager::ConvertToRealWindowId(int windowId, int focusType) { + HILOG_DEBUG("ConvertToRealWindowId called, windowId[%{public}d], focusType[%{public}d]", windowId, focusType); + if (windowId == ACTIVE_WINDOW_ID) { + HILOG_DEBUG("ConvertToRealWindowId called, after convert windowId[%{public}d]", activeWindowId_); + return activeWindowId_; + } + + if (windowId == ANY_WINDOW_ID) { + if (focusType == FOCUS_TYPE_ACCESSIBILITY) { + HILOG_DEBUG("ConvertToRealWindowId called, after convert windowId[%{public}d]", a11yFocusedWindowId_); + return a11yFocusedWindowId_; + } else if (focusType == FOCUS_TYPE_INPUT) { + HILOG_DEBUG("ConvertToRealWindowId called, after convert windowId[%{public}d]", inputFocusedWindowId_); + return inputFocusedWindowId_; + } + } + HILOG_DEBUG("ConvertToRealWindowId called, after convert windowId[%{public}d]", windowId); + return windowId; +} + +WindowType ConvertWindowType(WMWindowType type) { + WindowType winType = TYPE_WINDOW_INVALID; + switch (type) { + case WINDOW_TYPE_NORMAL: + winType = TYPE_APPLICATION; + break; + case WINDOW_TYPE_STATUS_BAR: + case WINDOW_TYPE_NAVI_BAR: + case WINDOW_TYPE_SYSTEM_UI: + case WINDOW_TYPE_ALARM_SCREEN: + case WINDOW_TYPE_LAUNCHER: + winType = TYPE_SYSTEM; + break; + default: + break; + } + return winType; +} + +AccessibilityWindowInfo AccessibilityWindowInfoManager::CreateAccessibilityWindowInfo(GetWindowInfoResult &windowInfo) { + AccessibilityWindowInfo info; + info.SetWindowId(windowInfo.wid); + info.SetWindowType(ConvertWindowType(windowInfo.type)); + info.SetWindowLayer(windowInfo.zorder); + // TODO: Set anchorId or anchorPosition + info.SetFocused(windowInfo.isFocused); + Rect bound; + bound.SetLeftTopScreenPostion(windowInfo.positionX, windowInfo.positionY); + bound.SetRightBottomScreenPostion(windowInfo.positionX + windowInfo.width, + windowInfo.positionY + windowInfo.height); + info.SetRectInScreen(bound); + + return info; +} + +void AccessibilityWindowInfoManager::RegisterWindowChangeListener() { + if (!registerFlag_) { + auto aams = DelayedSingleton::GetInstance(); + sptr wms = aams->GetWindowMgrProxy(); + wms->OnWindowListChange(this); + registerFlag_ = true; + return; + } +} + +void AccessibilityWindowInfoManager::DeregisterWindowChangeListener() { + if (registerFlag_) { + auto aams = DelayedSingleton::GetInstance(); + sptr wms = aams->GetWindowMgrProxy(); + wms->OnWindowListChange(nullptr); + registerFlag_ = false; + return; + } +} + +void AccessibilityWindowInfoManager::OnWindowChanged(int windowId, bool add) { + auto aams = DelayedSingleton::GetInstance(); + HILOG_DEBUG("%{public}s: windowId[%{public}d] add[%{public}d]", __func__, windowId, add); + if (add) { + auto accountData = aams->GetCurrentAccountData(); + if (accountData->GetAccessibilityInteractionConnection(windowId)) { + sptr wms = aams->GetWindowMgrProxy(); + sptr windowInfo = wms->GetWindowInfo(windowId); + if (!windowInfo) { + HILOG_ERROR("GetWindowInfo failed by window id!!"); + return; + } + + auto a11yWindowInfo = CreateAccessibilityWindowInfo(*windowInfo); + a11yWindows_.emplace(windowId, a11yWindowInfo); + + AccessibilityEventInfo evtInf(windowId, WINDOW_UPDATE_ADDED); + aams->SendEvent(evtInf, aams->GetCurrentAccountId()); + if (a11yWindowInfo.IsFocused()) { + SetActiveWindow(windowId); + } + } + } else { + if (!a11yWindows_.count(windowId)) { + return; + } + + if (windowId == activeWindowId_) { + SetActiveWindow(INVALID_WINDOW_ID); + } + + if (windowId == a11yFocusedWindowId_) { + SetAccessibilityFocusedWindow(INVALID_WINDOW_ID); + } + + if (windowId == inputFocusedWindowId_) { + SetInputFocusedWindow(INVALID_WINDOW_ID); + } + + a11yWindows_.erase(windowId); + + AccessibilityEventInfo evtInf(windowId, WINDOW_UPDATE_REMOVED); + aams->SendEvent(evtInf, aams->GetCurrentAccountId()); + } +} + +void AccessibilityWindowInfoManager::OnWindowCreate(int32_t wid) { + OnWindowChanged(wid, true); +} + +void AccessibilityWindowInfoManager::OnWindowDestroy(int32_t wid) { + OnWindowChanged(wid, false); +} + +void AccessibilityWindowInfoManager::SetActiveWindow(int windowId) { + HILOG_DEBUG("%{public}s start", __func__); + if (windowId == INVALID_WINDOW_ID) { + if (a11yWindows_.count(activeWindowId_)) { + a11yWindows_[activeWindowId_].SetActive(false); + } + activeWindowId_ = INVALID_WINDOW_ID; + return; + } + + if (!a11yWindows_.count(windowId)) { + HILOG_WARN("Window id is not found"); + return; + } + + if (activeWindowId_ != windowId) { + if (a11yWindows_.count(activeWindowId_)) { + a11yWindows_[activeWindowId_].SetActive(false); + } + activeWindowId_ = windowId; + a11yWindows_[activeWindowId_].SetActive(true); + auto aams = DelayedSingleton::GetInstance(); + AccessibilityEventInfo evtInf(activeWindowId_, WINDOW_UPDATE_ACTIVE); + aams->SendEvent(evtInf, aams->GetCurrentAccountId()); + } + HILOG_DEBUG("%{public}s %{public}d", __func__, activeWindowId_); +} + +void AccessibilityWindowInfoManager::SetAccessibilityFocusedWindow(int windowId) { + HILOG_DEBUG("%{public}s start", __func__); + if (windowId == INVALID_WINDOW_ID) { + if (a11yWindows_.count(a11yFocusedWindowId_)) { + a11yWindows_[a11yFocusedWindowId_].SetAccessibilityFocused(false); + } + a11yFocusedWindowId_ = INVALID_WINDOW_ID; + return; + } + + if (!a11yWindows_.count(windowId)) { + HILOG_WARN("Window id is not found"); + return; + } + + if (a11yFocusedWindowId_ != windowId) { + if (a11yWindows_.count(a11yFocusedWindowId_)) { + a11yWindows_[a11yFocusedWindowId_].SetAccessibilityFocused(false); + } + a11yFocusedWindowId_ = windowId; + a11yWindows_[a11yFocusedWindowId_].SetAccessibilityFocused(true); + } + HILOG_DEBUG("%{public}s %{public}d", __func__, a11yFocusedWindowId_); +} + +void AccessibilityWindowInfoManager::SetInputFocusedWindow(int windowId) { + if (windowId == INVALID_WINDOW_ID) { + if (a11yWindows_.count(inputFocusedWindowId_)) { + a11yWindows_[inputFocusedWindowId_].SetFocused(false); + } + inputFocusedWindowId_ = INVALID_WINDOW_ID; + return; + } + + if (!a11yWindows_.count(windowId)) { + HILOG_WARN("Window id is not found"); + return; + } + + if (inputFocusedWindowId_ != windowId) { + if (a11yWindows_.count(inputFocusedWindowId_)) { + a11yWindows_[inputFocusedWindowId_].SetFocused(false); + } + inputFocusedWindowId_ = windowId; + a11yWindows_[inputFocusedWindowId_].SetFocused(true); + } +} + +std::vector AccessibilityWindowInfoManager::GetAccessibilityWindows() { + HILOG_INFO("%{public}s", __func__); + HILOG_DEBUG("a11yWindows_ size[%{public}d]", a11yWindows_.size()); + std::vector windows; + for (auto window : a11yWindows_) { + windows.push_back(window.second); + } + HILOG_DEBUG("window size[%{public}d]", windows.size()); + for (auto logWindow : windows) { + HILOG_DEBUG("logWindow id[%{public}d]", logWindow.GetWindowId()); + } + return windows; +} + +bool AccessibilityWindowInfoManager::GetAccessibilityWindow(int windowId, AccessibilityWindowInfo &window) +{ + HILOG_INFO("%{public}s", __func__); + if (a11yWindows_.count(windowId)) { + window = a11yWindows_[windowId]; + return true; + } + return false; +} + +bool AccessibilityWindowInfoManager::IsValidWindow(int windowId) +{ + HILOG_INFO("%{public}s", __func__); + if (a11yWindows_.count(windowId)) { + return true; + } + return false; +} + +void AccessibilityWindowInfoManager::SetWindowSize(int windowId, Rect rect) +{ + HILOG_INFO("%{public}s", __func__); + for (auto &window : a11yWindows_) { + if (window.first == windowId) { + window.second.SetRectInScreen(rect); + return; + } + } +} +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/services/aams/src/accessibility_zoom_gesture.cpp b/services/aams/src/accessibility_zoom_gesture.cpp new file mode 100644 index 00000000..bee45e05 --- /dev/null +++ b/services/aams/src/accessibility_zoom_gesture.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_zoom_gesture.h" +#include + +namespace OHOS { +namespace Accessibility { +/** + * Triple: DOWN UP DOWN UP DOWN + */ +const int DOWN_COUNT = 3; +const int UP_COUNT = 2; + +AccessibilityZoomGesture::AccessibilityZoomGesture() +{ + Initialize(); +} + +AccessibilityZoomGesture::~AccessibilityZoomGesture() +{ +} + +void AccessibilityZoomGesture::Initialize() +{ + distance_ = GetSysDistance(); + timeout_ = GetSysTimeout(); +} + +int AccessibilityZoomGesture::GetSysDistance() const +{ + return 0; +} + +int AccessibilityZoomGesture::GetSysTimeout() const +{ + return 0; +} + +bool AccessibilityZoomGesture::ValidDown(TouchEvent &event) +{ + if (downCount_ == 0) { + lastDown_ = event; + } else { + if (event.GetMultimodalEvent()->GetOccurredTime() - lastDown_.GetMultimodalEvent()->GetOccurredTime() > timeout_) { + Reset(event); + return false; + } + int dist = sqrt(pow(event.GetPointerScreenPosition(event.GetIndex()).GetX() - lastDown_.GetPointerScreenPosition(lastDown_.GetIndex()).GetX(), 2) + pow(event.GetPointerScreenPosition(event.GetIndex()).GetY() - lastDown_.GetPointerScreenPosition(lastDown_.GetIndex()).GetY(), 2)); + if (dist > distance_) { + Reset(event); + return false; + } + lastDown_ = event; + } + downCount_ ++; + return true; +} + +bool AccessibilityZoomGesture::Triple(TouchEvent &event) +{ + if (ValidDown(event) && downCount_ >= DOWN_COUNT && upCount_ >= UP_COUNT) { + return true; + } + return false; +} + +void AccessibilityZoomGesture::Up() +{ + upCount_ ++; +} + +void AccessibilityZoomGesture::Reset(const TouchEvent &event) +{ + upCount_ = 0; + downCount_ = 1; + lastDown_ = event; +} + +void AccessibilityZoomGesture::Clear() +{ + upCount_ = 0; + downCount_ = 0; +} +} // namespace accessibility +} // namespace OHOS diff --git a/services/aams/src/accessibility_zoom_handler.cpp b/services/aams/src/accessibility_zoom_handler.cpp new file mode 100644 index 00000000..8f043425 --- /dev/null +++ b/services/aams/src/accessibility_zoom_handler.cpp @@ -0,0 +1,214 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessibility_zoom_handler.h" +#include +#include +#include "hilog_wrapper.h" + +using namespace std; + +namespace OHOS { +namespace Accessibility { + +AccessibilityZoomHandler::AccessibilityZoomHandler(int displayId) +{ + displayId_ = displayId; + // zoomProxy_ = proxy; + + readyState_.Register(*this); + zoomInState_.Register(*this); + slidingState_.Register(*this); + currentState_ = readyState_; +} + +AccessibilityZoomHandler::~AccessibilityZoomHandler() +{ + readyState_.UnRegisterAll(); + zoomInState_.UnRegisterAll(); + slidingState_.UnRegisterAll(); + EventTransmission::DestroyEvents(); +} + +void AccessibilityZoomHandler::Initialize() +{ + // currentState_ = readyState_; +} + +/* +AccessibilityZoomProxy &AccessibilityZoomHandler::GetProxy() +{ + return zoomProxy_; +} +*/ + +void AccessibilityZoomHandler::OnTouchEvent(TouchEvent &event) +{ + currentState_.OnTouchEvent(event); +} + +void AccessibilityZoomHandler::OnTransitionTo(const int state) +{ + currentState_.Exit(); + { + // std::lock_guard lock(stateMutex_); + switch (state) { + case READY_STATE: + currentState_ = readyState_; + break; + case ZOOMIN_STATE: + currentState_ = zoomInState_; + break; + case SLIDING_STATE: + currentState_ = slidingState_; + break; + default: + std::cout << "State input error" << std::endl; + break; + } + } + currentState_.Enter(); +} + +void AccessibilityZoomHandler::OnZoomIn() +{ + +} + +void AccessibilityZoomHandler::OnZoomOut() +{ + +} + +void AccessibilityZoomHandler::OnBack(TouchEvent &event) +{ + EventTransmission::OnTouchEvent(event); +} + +void AccessibilityZoomHandler::ReadyState::Enter() +{ + HILOG_DEBUG("AccessibilityZoomHandler READY_STATE Enter."); + gesture_.Clear(); +} + +void AccessibilityZoomHandler::ReadyState::Exit() +{ + HILOG_DEBUG("AccessibilityZoomHandler READY_STATE Exit."); + gesture_.Clear(); +} + +void AccessibilityZoomHandler::ReadyState::OnTouchEvent(TouchEvent &event) +{ + switch (event.GetAction()) { + case TouchEnum::PRIMARY_POINT_UP: + gesture_.Up(); + observer_[0].OnBack(event); + break; + case TouchEnum::PRIMARY_POINT_DOWN: + if (gesture_.Triple(event)) { + observer_[0].OnTransitionTo(ZOOMIN_STATE); + } else { + observer_[0].OnBack(event); + } + break; + default: + observer_[0].OnBack(event); + break; + } +} + +void AccessibilityZoomHandler::ZoomInState::Enter() +{ + HILOG_DEBUG("AccessibilityZoomHandler ZOOMIN_STATE Enter."); + gesture_.Clear(); + observer_[0].OnZoomIn(); +} + +void AccessibilityZoomHandler::ZoomInState::Exit() +{ + HILOG_DEBUG("AccessibilityZoomHandler ZOOMIN_STATE Exit."); + gesture_.Clear(); + observer_[0].OnZoomOut(); +} + +void AccessibilityZoomHandler::ZoomInState::OnTouchEvent(TouchEvent &event) +{ + switch (event.GetAction()) { + case TouchEnum::PRIMARY_POINT_UP: + gesture_.Up(); + observer_[0].OnBack(event); + break; + case TouchEnum::PRIMARY_POINT_DOWN: + if (gesture_.Triple(event)) { + observer_[0].OnTransitionTo(READY_STATE); + } else { + observer_[0].OnBack(event); + } + break; + case TouchEnum::OTHER_POINT_DOWN: + observer_[0].OnTransitionTo(SLIDING_STATE); + break; + case TouchEnum::CANCEL: + observer_[0].OnTransitionTo(READY_STATE); + break; + default: + observer_[0].OnBack(event); + break; + } + +} + +void AccessibilityZoomHandler::SlidingState::Enter() +{ + HILOG_DEBUG("AccessibilityZoomHandler SLIDING_STATE Enter."); +} + +void AccessibilityZoomHandler::SlidingState::Exit() +{ + HILOG_DEBUG("AccessibilityZoomHandler SLIDING_STATE Exit."); +} + +void AccessibilityZoomHandler::SlidingState::OnTouchEvent(TouchEvent &event) +{ + switch (event.GetAction()) { + case TouchEnum::OTHER_POINT_UP: + observer_[0].OnTransitionTo(ZOOMIN_STATE); + break; + case TouchEnum::POINT_MOVE: + OnScroll(/*event*/); + break; + case TouchEnum::CANCEL: + observer_[0].OnTransitionTo(READY_STATE); + observer_[0].OnZoomOut(); + break; + default: + observer_[0].OnBack(event); + break; + } + +} + +bool AccessibilityZoomHandler::SlidingState::OnScroll( /*TouchEvent &event*/ ) +{ + return true; +} + +bool AccessibilityZoomHandler::SlidingState::OnScale( /*TouchEvent &event*/ ) +{ + return true; +} + +} // namespace accessibility +} // namespace OHOS diff --git a/services/aams/src/accessible_ability_connection.cpp b/services/aams/src/accessible_ability_connection.cpp new file mode 100644 index 00000000..b61edd4e --- /dev/null +++ b/services/aams/src/accessible_ability_connection.cpp @@ -0,0 +1,568 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include +#include +#include "accessible_ability_connection.h" +#include "ability_manager_client.h" +#include "accessibility_window_manager.h" +#include "accessibility_interaction_connection.h" +#include "singleton.h" +#include "hilog_wrapper.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "accessible_ability.h" +#include "dummy.h" + +using namespace std; + +namespace OHOS { +namespace Accessibility { + +AccessibleAbilityChannelStubImpl::AccessibleAbilityChannelStubImpl( + AccessibleAbilityConnection& connection): connection_(connection) { + aams_ = DelayedSingleton::GetInstance(); + if (!aams_) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::AccessibleAbilityChannelStubImpl failed: no aams"); + } + HILOG_DEBUG("AccessibleAbilityChannelStubImpl::AccessibleAbilityChannelStubImpl successfully"); +} + +AccessibleAbilityChannelStubImpl::~AccessibleAbilityChannelStubImpl() { + +} +bool AccessibleAbilityChannelStubImpl::SearchElementInfoByAccessibilityId(const int accessibilityWindowId, + const long elementId, const int requestId, const sptr &callback, + const int mode) +{ + wptr accountData = connection_.GetAccountData(); + int realWindowId = AccessibilityWindowInfoManager::GetInstance().ConvertToRealWindowId(accessibilityWindowId, + FOCUS_TYPE_INVALID); + sptr connection = + accountData->GetAccessibilityInteractionConnection(realWindowId); + if (!connection) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::SearchElementInfoByAccessibilityId failed: no connection"); + return false; + } + if (!(connection_.GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::SearchElementInfoByAccessibilityId failed: no capability"); + return false; + } + if (!connection->GetProxy()) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::SearchElementInfoByAccessibilityId failed: no proxy"); + return false; + } + connection->GetProxy()->SearchElementInfoByAccessibilityId(elementId, requestId, callback, + mode); + HILOG_ERROR("AccessibleAbilityChannelStubImpl::SearchElementInfoByAccessibilityId successfully"); + return true; +} + +bool AccessibleAbilityChannelStubImpl::SearchElementInfosByText(const int accessibilityWindowId, + const long elementId, const string &text, const int requestId, + const sptr &callback) { + + wptr accountData = connection_.GetAccountData(); + int realWindowId = AccessibilityWindowInfoManager::GetInstance().ConvertToRealWindowId(accessibilityWindowId, + FOCUS_TYPE_INVALID); + + sptr connection = + accountData->GetAccessibilityInteractionConnection(realWindowId); + if (!connection) { + HILOG_ERROR("SearchElementInfosByText failed"); + return false; + } + if (!(connection_.GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::SearchElementInfosByText failed: no capability"); + return false; + } + connection->GetProxy()->SearchElementInfosByText(elementId, text, requestId, callback); + return true; +} + +bool AccessibleAbilityChannelStubImpl::FindFocusedElementInfo(const int accessibilityWindowId, + const long elementId, const int focusType, const int requestId, + const sptr &callback) { + + wptr accountData = connection_.GetAccountData(); + int realWindowId = AccessibilityWindowInfoManager::GetInstance().ConvertToRealWindowId(accessibilityWindowId, + focusType); + + sptr connection = + accountData->GetAccessibilityInteractionConnection(realWindowId); + if (!connection) { + HILOG_ERROR("FindFocusedElementInfo failed"); + return false; + } + if (!(connection_.GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::FindFocusedElementInfo failed: no capability"); + return false; + } + connection->GetProxy()->FindFocusedElementInfo(elementId, focusType, requestId, callback); + return true; +} + +bool AccessibleAbilityChannelStubImpl::FocusMoveSearch(const int accessibilityWindowId, const long elementId, + const int direction, const int requestId, const sptr &callback) { + + wptr accountData = connection_.GetAccountData(); + int realWindowId = AccessibilityWindowInfoManager::GetInstance().ConvertToRealWindowId(accessibilityWindowId, + FOCUS_TYPE_INVALID); + + sptr connection = + accountData->GetAccessibilityInteractionConnection(realWindowId); + if (!connection) { + HILOG_ERROR("FocusMoveSearch failed"); + return false; + } + if (!(connection_.GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::FocusMoveSearch failed: no capability"); + return false; + } + connection->GetProxy()->FocusMoveSearch(elementId, direction, requestId, callback); + return true; +} + +bool AccessibleAbilityChannelStubImpl::PerformAction(const int accessibilityWindowId, const long elementId, + const int action, std::map &actionArguments, const int requestId, + const sptr &callback) { + HILOG_DEBUG("PerformAction accessibilityWindowId = %{public}d", accessibilityWindowId); + wptr accountData = connection_.GetAccountData(); + int realWindowId = AccessibilityWindowInfoManager::GetInstance().ConvertToRealWindowId(accessibilityWindowId, + FOCUS_TYPE_INVALID); + + sptr connection = + accountData->GetAccessibilityInteractionConnection(realWindowId); + if (!connection) { + HILOG_ERROR("PerformAction failed"); + return false; + } + if (!(connection_.GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::PerformAction failed: no capability"); + return false; + } + connection->GetProxy()->PerformAction(elementId, action, actionArguments, requestId, callback); + return true; +} + +vector AccessibleAbilityChannelStubImpl::GetWindows() { + if (!(connection_.GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE)) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::GetWindows failed: no capability"); + vector windows; + return windows; + } + + std::vector windowInfos = + AccessibilityWindowInfoManager::GetInstance().GetAccessibilityWindows(); + size_t size = windowInfos.size(); + int currentChannelId = connection_.GetChannelId(); + for (size_t i = 0; i < size; i++) { + windowInfos[i].SetChannelId(currentChannelId); + } + return windowInfos; +} + +bool AccessibleAbilityChannelStubImpl::PerformCommonAction(int action) { + HILOG_DEBUG("PerformCommonAction action = %{public}d", action); + bool ret = true; + switch (action) + { + case GlobalAction::GLOBAL_ACTION_BACK: + HILOG_DEBUG("PerformCommonAction action = GLOBAL_ACTION_BACK"); + break; + case GlobalAction::GLOBAL_ACTION_HOME: + HILOG_DEBUG("PerformCommonAction action = GLOBAL_ACTION_HOME"); + break; + case GlobalAction::GLOBAL_ACTION_RECENT: + HILOG_DEBUG("PerformCommonAction action = GLOBAL_ACTION_RECENT"); + break; + case GlobalAction::GLOBAL_ACTION_NOTIFICATION: + HILOG_DEBUG("PerformCommonAction action = GLOBAL_ACTION_NOTIFICATION"); + break; + case GlobalAction::GLOBAL_ACTION_POP_UP_POWER_DIALOG: + HILOG_DEBUG("PerformCommonAction action = GLOBAL_ACTION_POP_UP_POWER_DIALOG"); + break; + case GlobalAction::GLOBAL_ACTION_DIVIDE_SCREEN: + HILOG_DEBUG("PerformCommonAction action = GLOBAL_ACTION_DIVIDE_SCREEN"); + break; + case GlobalAction::GLOBAL_ACTION_LOCK_SCREEN: + HILOG_DEBUG("PerformCommonAction action = GLOBAL_ACTION_LOCK_SCREEN"); + break; + case GlobalAction::GLOBAL_ACTION_CAPTURE_SCREEN: + HILOG_DEBUG("PerformCommonAction action = GLOBAL_ACTION_CAPTURE_SCREEN"); + break; + default: + HILOG_DEBUG("The action is not exist. %{public}d", action); + ret = false; + break; + } + + // TODO: need external dependence + return ret; +} + +void AccessibleAbilityChannelStubImpl::DisableAbility() +{ + connection_.GetAccountData()->RemoveEnabledAbility(connection_.GetElementName()); + +#if 0 + aams_->UpdateAbilities(); + +#else + connection_.GetProxy()->Disconnect(connection_.GetChannelId()); + connection_.OnAbilityDisconnectDone(connection_.GetElementName(), 0); + +#endif // 0 + +} + +void AccessibleAbilityChannelStubImpl::SetOnKeyPressEventResult(const bool handled, const int sequence) { + sptr keyEventFilter = aams_->GetKeyEventFilter(); + if (!keyEventFilter) { + return; + } + keyEventFilter->SetServiceOnKeyEventResult(connection_, handled, sequence); +} + +float AccessibleAbilityChannelStubImpl::GetDisplayResizeScale(const int displayId) { + return AccessibilityZoomProxy::GetInstance().GetScale(displayId); +} + +float AccessibleAbilityChannelStubImpl::GetDisplayResizeCenterX(const int displayId) { + return AccessibilityZoomProxy::GetInstance().GetCenterX(displayId); +} + +float AccessibleAbilityChannelStubImpl::GetDisplayResizeCenterY(const int displayId) { + return AccessibilityZoomProxy::GetInstance().GetCenterY(displayId); +} + +Rect AccessibleAbilityChannelStubImpl::GetDisplayResizeRect(const int displayId) { + return AccessibilityZoomProxy::GetInstance().GetDisplayResizeRect(displayId); +} + +bool AccessibleAbilityChannelStubImpl::ResetDisplayResize(const int displayId, const bool animate) { + if (!(connection_.GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_ZOOM)) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::ResetDisplayResize failed: no capability"); + return false; + } + return AccessibilityZoomProxy::GetInstance().Reset(displayId); +} + +bool AccessibleAbilityChannelStubImpl::SetDisplayResizeScaleAndCenter(const int displayId, const float scale, + const float centerX, const float centerY, const bool animate) { + if (!(connection_.GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_ZOOM)) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::SetDisplayResizeScaleAndCenter failed: no capability"); + return false; + } + return AccessibilityZoomProxy::GetInstance().SetScaleAndCenter(displayId, scale, centerX, centerY); +} + +void AccessibleAbilityChannelStubImpl::SendSimulateGesture(const int sequence, + const std::vector &gestureSteps) { + sptr proxy = connection_.GetProxy(); + if (!proxy) { + return; + } + if (!(connection_.GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_GESTURE)) { + HILOG_ERROR("AccessibleAbilityChannelStubImpl::SendSimulateGesture failed: no capability"); + proxy->OnGestureSimulateResult(sequence, false); + return; + } + sptr touchEventInjector = aams_->GetTouchEventInjector(); + if (!touchEventInjector) { + proxy->OnGestureSimulateResult(sequence, false); + return; + } + touchEventInjector->InjectEvents(gestureSteps, connection_.GetProxy(), sequence); +} + +bool AccessibleAbilityChannelStubImpl::IsFingerprintGestureDetectionValid() { + // if (!(connection_.GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_TOUCH_GUIDE)) { + // HILOG_ERROR("AccessibleAbilityChannelStubImpl::IsFingerprintGestureDetectionValid failed: no capability"); + // return false; + // } + return false; +} + +AccessibleAbilityConnection::AccessibleAbilityConnection(const wptr &accountData, + int connectionId, AccessibilityAbilityInfo &abilityInfo) { + + connectionId_ = connectionId; + abilityInfo_ = abilityInfo; + accountData_ = accountData; +} + +AccessibleAbilityConnection::~AccessibleAbilityConnection() { + HILOG_DEBUG(" %{public}s", __func__); + if (proxy_ && proxy_->AsObject()) { + proxy_->AsObject()->RemoveDeathRecipient(deathRecipient_); + proxy_ = nullptr; + } +} + +void AccessibleAbilityConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element, + const sptr &remoteObject, int resultCode) { + elementName_ = element; + + if (resultCode != NO_ERROR) { + HILOG_DEBUG("Connect failed!"); + accountData_->RemoveEnabledAbility(elementName_); + accountData_->RemoveConnectingA11yAbility(elementName_); + + // TODO: Notify setting + + return; + } + + if (!remoteObject) { + HILOG_ERROR("AccessibleAbilityConnection::OnAbilityConnectDone get remoteObject failed"); + return; + } + + if (!proxy_) { + proxy_ = new AccessibleAbilityClientProxy(remoteObject); + } + + if (!proxy_) { + HILOG_ERROR("AccessibleAbilityConnection::OnAbilityConnectDone get AccessibleAbilityClientProxy failed"); + return; + } + HILOG_ERROR("AccessibleAbilityConnection::OnAbilityConnectDone get AccessibleAbilityClientProxy successfully"); + + if (!deathRecipient_) { + deathRecipient_ = new AccessibleAbilityConnectionDeathRecipient(accountData_, elementName_); + } + + if (!proxy_->AsObject()->AddDeathRecipient(deathRecipient_)) { + HILOG_ERROR("Failed to add death recipient"); + } + + sptr pointer = this; + stub_ = new AccessibleAbilityChannelStubImpl(*pointer); + proxy_->Init(stub_, connectionId_); + + accountData_->AddConnectedAbility(pointer); + DelayedSingleton::GetInstance()->UpdateAccessibilityManagerService(); +} + +void AccessibleAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) { + HILOG_DEBUG("%{public}s start.", __func__); + + if (resultCode != NO_ERROR) { + HILOG_ERROR("Disconnect failed!"); + return; + } + + sptr pointer = this; + accountData_->RemoveConnectedAbility(pointer); + + int32_t currentAccountId = DelayedSingleton::GetInstance()->GetCurrentAccountId(); + if (accountData_->GetAccountId() == currentAccountId) { + DelayedSingleton::GetInstance()->UpdateAccessibilityManagerService(); + } +} + +void AccessibleAbilityConnection::OnAccessibilityEvent(AccessibilityEventInfo &eventInfo) { + HILOG_INFO("OnAccessibilityEvent called"); + if (!proxy_) { + HILOG_ERROR("OnAccessibilityEvent​ failed"); + return; + } + + bool send = false; + if (IsWhiteListEvent(eventInfo.GetEventType())) { + HILOG_DEBUG("Get event type is whilte list!"); + send = true; + } else { + int windowId = eventInfo.GetWindowId(); + bool validWindow = AccessibilityWindowInfoManager::GetInstance().IsValidWindow(windowId); + vector filterBundleNames = abilityInfo_.GetFilterBundleNames(); + if (validWindow && IsWantedEvent(eventInfo.GetEventType()) && (filterBundleNames.empty() || + find(filterBundleNames.begin(), filterBundleNames.end(), + eventInfo.GetBundleName()) != filterBundleNames.end())) { + send = true; + } + } + + if (send) { + eventInfo.SetChannelId(connectionId_); + proxy_->OnAccessibilityEvent(eventInfo); + HILOG_INFO("windowId[%{public}d] evtType[%{public}d] windowChangeType[%{public}d]", + eventInfo.GetWindowId(), (int)eventInfo.GetEventType(), (int)eventInfo.GetWindowChangeTypes()); + } + + return; +} + + +bool AccessibleAbilityConnection::IsWhiteListEvent(EventType eventType) { + bool ret = false; + switch (eventType) { + case EventType::TYPE_PAGE_STATE_UPDATE: + case EventType::TYPE_NOTIFICATION_UPDATE_EVENT: + case EventType::TYPE_PUBLIC_NOTICE_EVENT: + case EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN: + case EventType::TYPE_TOUCH_GUIDE_GESTURE_END: + case EventType::TYPE_TOUCH_GUIDE_BEGIN: + case EventType::TYPE_TOUCH_GUIDE_END: + case EventType::TYPE_TOUCH_BEGIN: + case EventType::TYPE_TOUCH_END: + case EventType::TYPE_VIEW_HOVER_ENTER_EVENT: + case EventType::TYPE_VIEW_HOVER_EXIT_EVENT: + case EventType::TYPE_WINDOW_UPDATE: { + ret = true; + break; + } + default: + break; + } + return ret; +} + +void AccessibleAbilityConnection::OnInterrupt() { + if (!proxy_) { + HILOG_ERROR("OnInterrupt failed"); + return; + } + proxy_->OnInterrupt(); +} + +void AccessibleAbilityConnection::OnGesture(const int gestureId) { + if (!proxy_) { + HILOG_ERROR("OnGesture failed"); + return; + } + proxy_->OnGesture(gestureId); +} + +bool AccessibleAbilityConnection::OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int sequence) { + if (!proxy_) { + HILOG_ERROR("OnKeyPressEvent failed"); + return false; + } + + if (!(abilityInfo_.GetCapabilityValues() & Capability::CAPABILITY_KEY_EVENT_OBSERVER)) { + HILOG_ERROR("Capability failed"); + return false; + } + + if (DelayedSingleton::GetInstance()-> + IsWantedKeyEvent(const_cast(keyEvent))) { + proxy_->OnKeyPressEvent(keyEvent, sequence); + return true; + } + return false; +} + +void AccessibleAbilityConnection::OnDisplayResizeChanged(const int displayId, const Rect &rect, const float scale, + const float centerX, const float centerY) { + if (!proxy_) { + HILOG_ERROR("OnDisplayResizeChanged​ failed"); + return; + } + proxy_->OnDisplayResizeChanged(displayId, rect, scale, centerX, centerY); +} + +void AccessibleAbilityConnection::OnGestureSimulateResult(const int sequence, const bool completedSuccessfully) { + if (!proxy_) { + HILOG_ERROR("OnGestureSimulateResult failed"); + return; + } + proxy_->OnGestureSimulateResult(sequence, completedSuccessfully); +} + +void AccessibleAbilityConnection::OnFingerprintGestureValidityChanged(const bool validity) { + if (!proxy_) { + HILOG_ERROR("OnFingerprintGestureValidityChanged failed"); + return; + } + proxy_->OnFingerprintGestureValidityChanged(validity); +} + +void AccessibleAbilityConnection::OnFingerprintGesture(const int gesture) { + if (!proxy_) { + HILOG_ERROR("OnFingerprintGesture failed"); + return; + } + proxy_->OnFingerprintGesture(gesture); +} + +bool AccessibleAbilityConnection::IsWantedEvent(int eventType) { + uint32_t type = static_cast(eventType); + if ((type & abilityInfo_.GetEventTypes()) != type) { + return false; + } + return true; +} + +AAFwk::Want CreateWant(AppExecFwk::ElementName& element) { + AAFwk::Want want; + want.SetElement(element); + + return want; +} + +void AccessibleAbilityConnection::Disconnect() { + proxy_->Disconnect(connectionId_); + + // TODO: +#if 1 + if (AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(this) != ERR_OK) { + HILOG_ERROR("Disconnect failed!"); + return; + } +#else + OnAbilityDisconnectDone(elementName_, 0); +#endif +} + +void AccessibleAbilityConnection::Connect() { + AAFwk::Want want = CreateWant(elementName_); + if (AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, nullptr) != ERR_OK) { + HILOG_ERROR("ConnectAbility failed!"); + // TODO: Remove this enabled ability from Setting + return; + } + accountData_->AddConnectingA11yAbility(elementName_); +} + +int AccessibleAbilityConnection::GetChannelId() +{ + HILOG_DEBUG(" %{public}s connectionId_ is %{public}d", __func__, connectionId_); + return connectionId_; +} + +void AccessibleAbilityConnection::AccessibleAbilityConnectionDeathRecipient::OnRemoteDied( + const wptr& remote) +{ + HILOG_DEBUG(" %{public}s", __func__); + + if (!recipientAccountData_.promote()) { + HILOG_ERROR("recipientAccountData_ is null."); + } + + sptr connection = recipientAccountData_-> + GetAccessibleAbilityConnection(recipientElementName_.GetURI()); + recipientAccountData_->RemoveConnectedAbility(connection); + recipientAccountData_->RemoveEnabledAbility(recipientElementName_); + DelayedSingleton::GetInstance()->UpdateAccessibilityManagerService(); + + // TODO: notify setting + +} + +} // 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 new file mode 100644 index 00000000..36bf1086 --- /dev/null +++ b/services/aams/src/accessible_ability_manager_service.cpp @@ -0,0 +1,817 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include +#include +#include "accessible_ability_manager_service.h" +#include "accessibility_event_info.h" +#include "accessibility_window_manager.h" +#include "hilog_wrapper.h" +#include "system_ability_definition.h" +#include "iservice_registry.h" +#include "dummy.h" +#include "multimoduleDummy.h" +#include "ability_info.h" +#include "accessibility_interaction_bridge.h" +#include "accessibility_display_manager.h" + +using namespace std; + +namespace OHOS { +namespace Accessibility { + + +const string TASK_SEND_EVENT = "SendEvent"; +const string TASK_INTERRUPT = "Interrupt"; +const string AAMS_SERVICE_NAME = "AccessibleAbilityManagerService"; +const string TASK_PUBLIC_NOTICE_EVENT = "PublicNoticeEvent"; +const string TASK_SEND_PUBLIC_NOTICE_EVENT = "SendPublicNoticeEvent"; + +const bool REGISTER_RESULT = + SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); + +AccessibleAbilityManagerService::AccessibleAbilityManagerService() + : SystemAbility(ACCESSIBLE_ABILITY_MANAGER_SERVICE_ID, true), + bundleManager_(nullptr) { + HILOG_INFO("AccessibleAbilityManagerService is constructed"); +} + +AccessibleAbilityManagerService::~AccessibleAbilityManagerService() { +} + +void AccessibleAbilityManagerService::OnStart() { + HILOG_DEBUG(" %{public}s", __func__); + HILOG_INFO("AccessibleAbilityManagerService::OnStart start"); + + if (isRunning_) { + HILOG_DEBUG("AccessibleAbilityManagerService is already start."); + return; + } + + if (!Init()) { + HILOG_ERROR("AccessibleAbilityManagerService::Init failed!"); + return; + } + bool ret = Publish(DelayedSingleton::GetInstance().get()); + if (!ret) { + HILOG_ERROR("AccessibleAbilityManagerService::Publish failed!"); + return; + } + HILOG_INFO("AccessibleAbilityManagerService::OnStart OK."); + isRunning_ = true; +} + +void AccessibleAbilityManagerService::OnStop() { + HILOG_DEBUG(" %{public}s", __func__); + HILOG_INFO("stop AccessibleAbilityManagerService"); + + if (!isRunning_) { + HILOG_DEBUG("AccessibleAbilityManagerService is already stop."); + return; + } + + accessibilityCommonEventRegistry_.UnRegister(); + a11yAccountsData_.clear(); + bundleManager_ = nullptr; + windowManager_ = nullptr; + inputFilter_ = nullptr; + touchEventInjector_ = nullptr; + keyEventFilter_ = nullptr; + stateCallbackDeathRecipient_ = nullptr; + inputManager_.reset(); + runner_.reset(); + handler_.reset(); + isTouchInteraction_ = false; + hasInputFilter_ = false; + + HILOG_INFO("AccessibleAbilityManagerService::OnStop OK."); + isRunning_ = false; +} + +bool AccessibleAbilityManagerService::Init() { + HILOG_DEBUG(" %{public}s", __func__); + if (!runner_) { + runner_ = AppExecFwk::EventRunner::Create(AAMS_SERVICE_NAME); + if (!runner_) { + HILOG_ERROR("AccessibleAbilityManagerService::Init failed:create AAMS runner failed"); + return false; + } + } + + if (!handler_) { + handler_ = std::make_shared(runner_); + if (!handler_) { + HILOG_ERROR("AccessibleAbilityManagerService::Init failed:create AAMS event handler failed"); + return false; + } + } + + if (!accessibilityCommonEventRegistry_.StartRegister()) { + HILOG_ERROR("AccessibleAbilityManagerService::Init failed:Failed to subscribe common event"); + return false; + } + + // TODO: [setting] Add listener of setting's URI. + + HILOG_INFO("AccessibleAbilityManagerService::Init OK"); + return true; +} + +void AccessibleAbilityManagerService::RegisterAbilityConnectionClientTmp(const sptr& obj) { + HILOG_DEBUG(" %{public}s", __func__); + HILOG_INFO("AccessibleAbilityManagerService::RegisterAbilityConnectionClientTmp start"); + currentAccountId_ = 0; + AppExecFwk::AbilityInfo info; + AAFwk::Want want; + AppExecFwk::ElementName name; + name.SetAbilityName("com.example.aalisttest.MainAbility"); + name.SetBundleName("com.example.aalisttest"); + want.SetElement(name); + GetBundleMgrProxy()->QueryAbilityInfo(want, info); + sptr abilityInfo = new AccessibilityAbilityInfo(info); + AppExecFwk::ElementName elementName(info.deviceId, info.bundleName, info.name); + sptr accountData = GetCurrentAccountData(); + + a11yAccountsData_.insert(make_pair(0, accountData)); + sptr connection = new AccessibleAbilityConnection(accountData, connectCounter_++, + *abilityInfo); + connection->OnAbilityConnectDone(elementName, obj, 0); + accountData->AddInstalledAbility(*abilityInfo); + + HILOG_INFO("AccessibleAbilityManagerService::RegisterAbilityConnectionClientTmp successfully"); +} + +void AccessibleAbilityManagerService::SendEvent(const AccessibilityEventInfo &uiEvent, const int accountId) { + HILOG_DEBUG(" %{public}s", __func__); + HILOG_INFO("eventType[%{public}d]", (int)uiEvent.GetEventType()); + if (accountId != currentAccountId_) { + HILOG_ERROR(" %{public}s accountId[%{public}d] is not matched", __func__, accountId); + return; + } + AccessibilityEventInfo& event = const_cast(uiEvent); + UpdateAccessibilityWindowStateByAccessibilityEvent(event); + + std::function sendEventFunc = + std::bind(&AccessibleAbilityManagerService::SendEventInner, this, event); + + handler_->PostTask(sendEventFunc, TASK_SEND_EVENT); +} + +void AccessibleAbilityManagerService::SendEventInner(AccessibilityEventInfo &uiEvent) { + HILOG_DEBUG(" %{public}s", __func__); + sptr accountData = GetCurrentAccountData(); + map> abilities = accountData->GetConnectedA11yAbilities(); + for (auto &ability : abilities) { + ability.second->OnAccessibilityEvent(uiEvent); + } +} + +uint32_t AccessibleAbilityManagerService::RegisterStateCallback( + const sptr &callback, const int accountId) { + HILOG_DEBUG(" %{public}s", __func__); + if (accountId != currentAccountId_) { + HILOG_ERROR(" %{public}s accountId[%{public}d] is not matched", __func__, accountId); + return 0; + } + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + HILOG_ERROR("Account data is null"); + return 0; + } + + if (!stateCallbackDeathRecipient_) { + stateCallbackDeathRecipient_ = new StateCallbackDeathRecipient(); + } + + callback->AsObject()->AddDeathRecipient(stateCallbackDeathRecipient_); + accountData->AddStateCallback(callback); + printf("accountData AddStateCallback %d\n",accountData->GetStateCallbacks().size()); + HILOG_INFO("AccessibleAbilityManagerService::RegisterStateCallback successfully"); + + return accountData->GetAccessibilityState(); +} + +vector AccessibleAbilityManagerService::GetAbilityList(const int abilityTypes, + const int stateType) { + HILOG_DEBUG(" %{public}s", __func__); + vector infoList; + if ((stateType > ABILITY_STATE_INSTALLED) || (stateType < ABILITY_STATE_ENABLE)) { + HILOG_ERROR("stateType is out of range!!"); + return infoList; + } + + sptr accountData = GetCurrentAccountData(); + + if (!accountData) { + HILOG_ERROR("Get current account data failed!!"); + return infoList; + } + + AbilityStateType state = static_cast(stateType); + vector abilities = accountData->GetAbilitiesByState(state); + for (auto &ability : abilities) { + if (ability.GetAccessibilityAbilityType() & static_cast(abilityTypes)) { + infoList.push_back(ability); + } + } + return infoList; +} + +void AccessibleAbilityManagerService::RegisterInteractionOperation(const int windowId, + const sptr &operation, int accountId) +{ + HILOG_DEBUG(" %{public}s", __func__); + sptr accountData = GetCurrentAccountData(); + if (accountData->GetAccessibilityInteractionConnection(windowId)) { + HILOG_WARN("This operation already exists, do not register twice!!"); + return; + } + + sptr bundleMgrProxy = GetBundleMgrProxy(); + sptr connection = new AccessibilityInteractionConnection(windowId, operation, + accountId); + accountData->AddAccessibilityInteractionConnection(windowId, connection); + + if (!interactionOperationDeathRecipient_) { + interactionOperationDeathRecipient_ = new InteractionOperationDeathRecipient(windowId); + } + + if (connection->GetProxy()) { + auto object = connection->GetProxy()->AsObject(); + if (object) { + HILOG_DEBUG("Add death recipient of operation"); + bool result = object->AddDeathRecipient(interactionOperationDeathRecipient_); + HILOG_DEBUG("The result of adding operation's death recipient is %{public}d", result); + } + } + + AccessibilityWindowInfoManager::GetInstance().OnWindowCreate(windowId); +} + +void AccessibleAbilityManagerService::DeregisterInteractionOperation(int windowId) { + HILOG_DEBUG(" %{public}s", __func__); + sptr accountData = GetCurrentAccountData(); + sptr connection = accountData->GetAccessibilityInteractionConnection(windowId); + if (!connection) { + HILOG_WARN("The operation of windowId[%{public}d] has not been registered.", windowId); + return; + } + + if (connection->GetProxy()) { + auto object = connection->GetProxy()->AsObject(); + if (object) { + HILOG_DEBUG("Delete death recipient of operation"); + bool result = object->RemoveDeathRecipient(interactionOperationDeathRecipient_); + HILOG_DEBUG("The result of deleting operation's death recipient is %{public}d", result); + } + } + + accountData->RemoveAccessibilityInteractionConnection(windowId); + auto& a11yWindowMgr = AccessibilityWindowInfoManager::GetInstance(); + a11yWindowMgr.OnWindowDestroy(windowId); +} + +void AccessibleAbilityManagerService::InteractionOperationDeathRecipient::OnRemoteDied( + const wptr& remote) +{ + HILOG_DEBUG(" %{public}s", __func__); + auto aams = DelayedSingleton::GetInstance(); + aams->DeregisterInteractionOperation(windowId_); +} + +void AccessibleAbilityManagerService::Interrupt(const int accountId) { + HILOG_DEBUG(" %{public}s", __func__); + if (accountId != currentAccountId_) { + return; + } + std::function interruptFunc = std::bind(&AccessibleAbilityManagerService::InterruptInner, this); + + handler_->PostTask(interruptFunc, TASK_INTERRUPT); +} + +void AccessibleAbilityManagerService::InterruptInner() { + HILOG_DEBUG(" %{public}s", __func__); + sptr accountData = GetCurrentAccountData(); + map> abilities = accountData->GetConnectedA11yAbilities(); + for (auto &ability : abilities) { + ability.second->OnInterrupt(); + } +} + +uint64_t AccessibleAbilityManagerService::GetSuggestedInterval() { + HILOG_DEBUG(" %{public}s", __func__); + sptr accountData = GetCurrentAccountData(); + + return static_cast(accountData->GetNonInteractiveUiInterval()) << INT32_BIT_NUM | + accountData->GetInteractiveUiInterval(); +} + +void AccessibleAbilityManagerService::PersistElementNamesToSetting(std::string &bundleName, std::map &componentNames, int accountId) { + // TODO: Update specified item to setting. +} + +sptr AccessibleAbilityManagerService::GetCurrentAccountData() { + HILOG_DEBUG(" %{public}s", __func__); + auto iter = a11yAccountsData_.find(currentAccountId_); + if (iter != a11yAccountsData_.end()) { + return iter->second; + } + sptr accountData = new AccessibilityAccountData(currentAccountId_); + a11yAccountsData_.insert(make_pair(currentAccountId_, accountData)); + return accountData; +} + +bool AccessibleAbilityManagerService::IsWantedKeyEvent(MMI::KeyEvent &event) { +#if 0 + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + return false; + } + map> abilities = accountData->GetConnectedA11yAbilities(); + + for (auto &ability : abilities) { + if (ability.second->GetAbilityInfo().GetKeyEventType() == static_cast(event.GetKeyCode())) { + return true; + } + } + return false; +#else + return true; +#endif +} + +void AccessibleAbilityManagerService::NotifyDisplayResizeStateChanged(int displayId, Rect &rect, float scale, + float centerX, float centerY) { + sptr accountData = GetCurrentAccountData(); + map> abilities = accountData->GetConnectedA11yAbilities(); + for (auto &ability : abilities) { + ability.second->OnDisplayResizeChanged(displayId, rect, scale, centerX, centerY); + } +} + +void AccessibleAbilityManagerService::OnGesture(int id) { + HILOG_DEBUG(" %{public}s", __func__); + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + return; + } + map> abilities = accountData->GetConnectedA11yAbilities(); + for (auto &ability : abilities) { + ability.second->OnGesture(id); + } +} + +sptr AccessibleAbilityManagerService::GetBundleMgrProxy() { + HILOG_DEBUG(" %{public}s", __func__); + if (bundleManager_) { + return bundleManager_; + } + + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + HILOG_ERROR("failed:fail to get system ability mgr."); + return nullptr; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (!remoteObject) { + HILOG_ERROR("failed:fail to get bundle manager proxy."); + return nullptr; + } + + bundleManager_ = iface_cast(remoteObject); + HILOG_INFO("AccessibleAbilityManagerService::GetBundleMgrProxy OK"); + + return bundleManager_; +} + +sptr AccessibleAbilityManagerService::GetWindowMgrProxy() { + HILOG_DEBUG(" %{public}s", __func__); + if (!windowManager_) { + windowManager_ = new IWindowManagerService(); + } + + return windowManager_; +} + +sptr AccessibleAbilityManagerService::GetAccessibilityInteractionConnection( + int windowId) { + HILOG_DEBUG(" %{public}s", __func__); + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + HILOG_ERROR("Get account data failed"); + return nullptr; + } + return accountData->GetAccessibilityInteractionConnection(windowId); +} + +void AccessibleAbilityManagerService::ClearFocus(int windowId) { + HILOG_DEBUG(" %{public}s", __func__); + sptr connection = GetAccessibilityInteractionConnection(windowId); + connection->GetProxy()->ClearFocus(); +} + +void AccessibleAbilityManagerService::OutsideTouch(int windowId) { + HILOG_DEBUG(" %{public}s", __func__); + sptr connection = GetAccessibilityInteractionConnection(windowId); + connection->GetProxy()->OutsideTouch(); +} + +void AccessibleAbilityManagerService::OnChanging(bool selfChange, Uri &uri) { + HILOG_DEBUG(" %{public}s", __func__); + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + return; + } + // TODO: Do something for Setting + UpdateAbilities(); +} + +void AccessibleAbilityManagerService::SetTouchEventInjector(const sptr &touchEventInjector) { + HILOG_DEBUG(" %{public}s", __func__); + touchEventInjector_ = touchEventInjector; +} + +void AccessibleAbilityManagerService::SetKeyEventFilter(const sptr &keyEventFilter) { + HILOG_DEBUG(" %{public}s", __func__); + keyEventFilter_ = keyEventFilter; +} + +void AccessibleAbilityManagerService::StateCallbackDeathRecipient::OnRemoteDied(const wptr& remote) { + HILOG_DEBUG(" %{public}s", __func__); + remote->RemoveDeathRecipient(this); + auto aams = DelayedSingleton::GetInstance(); + sptr accountData = aams->GetCurrentAccountData(); + if (!accountData) { + HILOG_ERROR("Current account data is null"); + return; + } + accountData->RemoveStateCallback(remote); +} + +void AccessibleAbilityManagerService::SwitchedUser(int32_t accountId) +{ + HILOG_DEBUG("%{public}s start", __func__); + + if (accountId == GetCurrentAccountId()) { + HILOG_ERROR("The account id is same as current account id."); + return; + } + + // Disconnect the old account. + sptr oldAccountData = GetCurrentAccountData(); + if (!oldAccountData) { + HILOG_ERROR("Get oldAccountData failed."); + return; + } + oldAccountData->OnAccountSwitched(); + printf("oldAccountData->OnAccountSwitched %d\n",oldAccountData->GetStateCallbacks().size()); + if (oldAccountData->GetStateCallbacks().size() > 0) { + HILOG_DEBUG("Send state to callbacks start."); + for (auto &callback: GetCurrentAccountData()->GetStateCallbacks()) { + callback->OnStateChanged(0); + } + } + + // Change to the new account. + currentAccountId_ = accountId; + sptr newAccountData = GetCurrentAccountData(); + if (!newAccountData) { + HILOG_ERROR("Get newAccountData failed."); + return; + } + + newAccountData->ReadConfigurationForAccountData(); + UpdateAbilities(); + + if (GetConnectCounter() >= 1 && + (!newAccountData->GetConnectedA11yAbilities().empty() || + !newAccountData->GetConnectingA11yAbilities().empty())) { + HILOG_DEBUG("Post task PublicNoticeEvent start."); + std::function PublicNoticeEventFunc = + std::bind(&AccessibleAbilityManagerService::PublicNoticeEventInner, this); + handler_->PostTask(PublicNoticeEventFunc, TASK_PUBLIC_NOTICE_EVENT); + } +} + +void AccessibleAbilityManagerService::PublicNoticeEventInner() +{ + HILOG_DEBUG("%{public}s start", __func__); + sptr event = new AccessibilityEventInfo(); + event->SetEventType(EventType::TYPE_PUBLIC_NOTICE_EVENT); + + // TODO: event add message + + struct timespec times = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, ×); + long timeStamp = times.tv_sec * 1000 + times.tv_nsec / 1000000; + event->SetTimeStamp(timeStamp); + + HILOG_DEBUG("Post task SendEvent start."); + std::function SendEventFunc = + std::bind(&AccessibleAbilityManagerService::SendEventInner, this, *event); + handler_->PostTask(SendEventFunc, TASK_SEND_PUBLIC_NOTICE_EVENT); +} + +void AccessibleAbilityManagerService::UnlockedUser(int32_t accountId) +{ + HILOG_DEBUG("%{public}s start", __func__); + + if (accountId == GetCurrentAccountId()) { + UpdateAbilities(); + } +} + +void AccessibleAbilityManagerService::RemovedUser(int32_t accountId) +{ + HILOG_DEBUG("%{public}s start", __func__); + a11yAccountsData_.erase(accountId); +} + +void AccessibleAbilityManagerService::PresentUser() +{ + HILOG_DEBUG("%{public}s start", __func__); + + GetCurrentAccountData()->ReadConfigurationForAccountData(); + UpdateAbilities(); +} + +void AccessibleAbilityManagerService::PackageRemoved(std::string &bundleName) { + HILOG_DEBUG("%{public}s start", __func__); + + sptr packageAccount = GetCurrentAccountData(); + if (packageAccount->GetEnabledAbilities().empty()) { + return; + } + + bool needUpdateAbility = false; + std::map enabledAbilities = packageAccount->GetEnabledAbilities(); + for (auto &enableAbility : enabledAbilities) { + if (enableAbility.second.GetBundleName() == bundleName) { + packageAccount->RemoveEnabledAbility(enableAbility.second); + packageAccount->RemoveConnectingA11yAbility(enableAbility.second); + PersistElementNamesToSetting(bundleName, enabledAbilities, currentAccountId_); + needUpdateAbility = true; + } + } + + if (needUpdateAbility) { + UpdateAccessibilityManagerService(); + } +} + +void AccessibleAbilityManagerService::PackageChanged() { + HILOG_DEBUG("%{public}s start", __func__); + + sptr packageAccount = GetCurrentAccountData(); + if (packageAccount->GetInstalledAbilities().empty()) { + return; + } + + packageAccount->ClearInstalledAbility(); + if (packageAccount->ReadConfigurationForAccountData()) { + UpdateAbilities(); + } +} + +void AccessibleAbilityManagerService::PackageUpdateFinished(std::string &bundleName) { + HILOG_DEBUG("%{public}s start", __func__); + sptr packageAccount = GetCurrentAccountData(); + if (packageAccount->GetConnectingA11yAbilities().empty()) { + return; + } + + bool needUpdateAbility = false; + std::map connectingAbilities = packageAccount->GetConnectingA11yAbilities(); + for (auto &ability : connectingAbilities) { + if (ability.second.GetBundleName() == bundleName) { + packageAccount->RemoveConnectingA11yAbility(ability.second); + needUpdateAbility = true; + } + } + + if (needUpdateAbility) { + UpdateAbilities(); + } +} + +void AccessibleAbilityManagerService::UpdateAccessibilityWindowStateByAccessibilityEvent(const AccessibilityEventInfo &event) { + EventType evtType = event.GetEventType(); + HILOG_DEBUG("%{public}s start %{public}d", __func__, event.GetWindowId()); + switch (evtType) { + case TYPE_VIEW_HOVER_ENTER_EVENT: + case TYPE_VIEW_FOCUSED_EVENT: + AccessibilityWindowInfoManager::GetInstance().SetActiveWindow(event.GetWindowId()); + AccessibilityWindowInfoManager::GetInstance().SetAccessibilityFocusedWindow(event.GetWindowId()); + break; + default: + break; + } +} + +AccessibilityElementInfo AccessibleAbilityManagerService::FindFocusedElementInfo() +{ + HILOG_DEBUG("[%{public}s]", __func__); + + return AccessibilityInteractionBridge::GetInstance().FindFocusedElementInfo(); +} + +bool AccessibleAbilityManagerService::PerformActionOnAccessibilityFocusedItem(const ActionType& action) +{ + HILOG_DEBUG("[%{public}s]", __func__); + + return AccessibilityInteractionBridge::GetInstance().PerformActionOnAccessibilityFocusedItem(action); +} + +bool AccessibleAbilityManagerService::GetAccessibilityFocusClickPointInScreen(MmiPoint &point) +{ + HILOG_DEBUG("[%{public}s]", __func__); + + return AccessibilityInteractionBridge::GetInstance().GetAccessibilityFocusClickPointInScreen(point); +} + +void AccessibleAbilityManagerService::UpdateAccessibilityManagerService() { + HILOG_DEBUG("%{public}s start.", __func__); + + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + HILOG_ERROR("Account data is null"); + return; + } + + accountData->UpdateAccountCapabilities(); + UpdateWindowChangeListener(); + UpdateMagnification(); + UpdateInputFilter(); + UpdateAccessibilityState(); +} + +void AccessibleAbilityManagerService::UpdateAbilities() { + HILOG_DEBUG("%{public}s start.", __func__); + + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + HILOG_ERROR("Account data is null"); + return; + } + + vector installedAbilities = accountData->GetInstalledAbilities(); + for (auto &installAbility : installedAbilities) { + AppExecFwk::ElementName element(installAbility.GetAbilityInfo().deviceId, + installAbility.GetPackageName(), + installAbility.GetName()); + std::string elementName = element.GetURI(); + // wait for the connecting ability. + if (accountData->GetConnectingA11yAbilities().count(elementName)) { + continue; + } + + sptr connection = accountData->GetAccessibleAbilityConnection(elementName); + if (accountData->GetEnabledAbilities().count(elementName)) { + if (!connection) { + connection = new AccessibleAbilityConnection(accountData, connectCounter_++, installAbility); + connection->Connect(); + } + } else { + if (connection) { + connection->Disconnect(); + } + } + } +} + +void AccessibleAbilityManagerService::UpdateAccessibilityState() { + HILOG_DEBUG("%{public}s start.", __func__); + + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + HILOG_ERROR("Account data is null"); + return; + } + + uint32_t state = accountData->GetAccessibilityState(); + for (auto &callback: accountData->GetStateCallbacks()) { + callback->OnStateChanged(state); + } +} + +void AccessibleAbilityManagerService::UpdateInputFilter() { + HILOG_DEBUG("%{public}s start.", __func__); + + bool notifyInputManager = false; + + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + HILOG_ERROR("Account data is null"); + return; + } + + int flag = 0; + if (accountData->GetScreenMagnificationFlag()) { + flag |= AccessibilityInputFilter::FEATURE_SCREEN_MAGNIFICATION; + } + if (accountData->GetEventTouchGuideStateFlag()) { + flag |= AccessibilityInputFilter::FEATURE_TOUCH_EXPLORATION; + } + if (accountData->GetFilteringKeyEventsFlag()) { + flag |= AccessibilityInputFilter::FEATURE_FILTER_KEY_EVENTS; + } + if (accountData->GetGesturesSimulationFlag()) { + flag |= AccessibilityInputFilter::FEATURE_INJECT_TOUCH_EVENTS; + } + HILOG_DEBUG("InputFilter flag is %{public}d", flag); + + if (flag != 0) { + if (!hasInputFilter_) { + HILOG_DEBUG("Has no InputFilter before."); + hasInputFilter_ = true; + if (inputFilter_ == nullptr) { + inputFilter_ = new AccessibilityInputFilter(); + } + notifyInputManager = true; + } + inputFilter_->SetUser(currentAccountId_); + inputFilter_->SetAvailableFunctions(flag); + } else { + if (hasInputFilter_) { + HILOG_DEBUG("Has InputFilter before."); + hasInputFilter_ = false; + inputFilter_->SetUser(currentAccountId_); + inputFilter_->SetAvailableFunctions(0); + notifyInputManager = true; + } + } + + if (notifyInputManager) { + if (hasInputFilter_) { + GetInputManager()->RegisterMultimodalInputFilter(*inputFilter_); + } else { + GetInputManager()->DeregisterMultimodalInputFilter(); + } + } +} + +void AccessibleAbilityManagerService::UpdateMagnification() { + HILOG_DEBUG("%{public}s start.", __func__); + + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + HILOG_ERROR("Account data is null"); + return; + } + + std::vector displays = AccessibilityDisplayManager::GetInstance().GetDisplays(); + + if (accountData->GetScreenMagnificationFlag()) { + for (WMDisplayInfo& display : displays) { + AccessibilityZoomProxy::GetInstance().Register(display.id); + } + } else { + for (WMDisplayInfo& display : displays) { + AccessibilityZoomProxy::GetInstance().Unregister(display.id); + } + } + +} + +void AccessibleAbilityManagerService::UpdateWindowChangeListener() { + HILOG_DEBUG("%{public}s start.", __func__); + + bool isWindowRetrieve = false; + sptr accountData = GetCurrentAccountData(); + if (!accountData) { + HILOG_ERROR("Account data is null"); + return; + } + + std::map> connectedA11yAbilities = accountData->GetConnectedA11yAbilities(); + for (auto itr = connectedA11yAbilities.begin(); itr != connectedA11yAbilities.end(); itr++) { + if (itr->second->GetAbilityInfo().GetCapabilityValues() & Capability::CAPABILITY_RETRIEVE) { + isWindowRetrieve = true; + break; + } + } + if (isWindowRetrieve) { + AccessibilityWindowInfoManager::GetInstance().RegisterWindowChangeListener(); + } else { + AccessibilityWindowInfoManager::GetInstance().DeregisterWindowChangeListener(); + AccessibilityWindowInfoManager::GetInstance().GetAccessibilityWindows().clear(); + } +} + +} // namespace OHOS +} // Accessibility \ No newline at end of file diff --git a/services/aams/src/accessible_ability_manager_service_event_handler.cpp b/services/aams/src/accessible_ability_manager_service_event_handler.cpp new file mode 100644 index 00000000..44f45aad --- /dev/null +++ b/services/aams/src/accessible_ability_manager_service_event_handler.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 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. + */ + +#include "accessible_ability_manager_service_event_handler.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace Accessibility { +AAMSEventHandler::AAMSEventHandler(const std::shared_ptr &runner) : AppExecFwk::EventHandler(runner) { + +} + +AAMSEventHandler::~AAMSEventHandler() {} + +void AAMSEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +{ + switch (event->GetInnerEventId()) { + // case ACCESSIBILITY_XXX_XXX: + default: + HILOG_ERROR("the eventId is not supported"); + break; + } +} +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/native_application/BUILD.gn b/test/resource/native_application/BUILD.gn new file mode 100644 index 00000000..dcc7b977 --- /dev/null +++ b/test/resource/native_application/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2021 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. + +group("aams_system_test_app") { + deps = [ + "aamsSystemTestA:aamsSystemTestA", + "aamsSystemTestB:aamsSystemTestB", + ] +} diff --git a/test/resource/native_application/aamsSystemTestA/BUILD.gn b/test/resource/native_application/aamsSystemTestA/BUILD.gn new file mode 100644 index 00000000..da04439f --- /dev/null +++ b/test/resource/native_application/aamsSystemTestA/BUILD.gn @@ -0,0 +1,58 @@ +# Copyright (c) 2021 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("//build/ohos.gni") +SUBDEMOSYSTEM_DIR = "//base/accessibility/test/resource/native_application/aamsSystemTestA" +config("aamsSystemTestAConfig") { + visibility = [ ":*" ] + include_dirs = [ + "${SUBDEMOSYSTEM_DIR}/include", + "//foundation/appexecfwk/standard/kits/appkit/native/app", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//base/accessibility/common/log/include", + "//base/accessibility/frameworks/aafwk/include", + "//base/accessibility/interfaces/innerkits/asacfwk/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//base/accessibility/frameworks/asacfwk/include", + "//base/accessibility/util/include", + "//base/accessibility/frameworks/aafwk/include", + ] + defines = [ + "AAMS_LOG_TAG = \"aamsSystemTest\"", + "AAMS_LOG_DOMAIN = 0xD005203", + ] +} +ohos_shared_library("aamsSystemTestA") { + sources = [ + "${SUBDEMOSYSTEM_DIR}/src/amsstabilitya1.cpp", + ] + configs = [ ":aamsSystemTestAConfig" ] + deps = [ + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "//foundation/appexecfwk/standard/kits:appkit_native", + "//utils/native/base:utilsbase", + "//base/accessibility/frameworks/aafwk:accessibleability", + "//base/accessibility/interfaces/innerkits/asacfwk:accessibilityclient", + "//base/accessibility/services/aams:accessibleabilityms", + ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + subsystem_name = "aamssystemtest" +} diff --git a/test/resource/native_application/aamsSystemTestA/config.json b/test/resource/native_application/aamsSystemTestA/config.json new file mode 100644 index 00000000..80302316 --- /dev/null +++ b/test/resource/native_application/aamsSystemTestA/config.json @@ -0,0 +1,40 @@ +{ + "app":{ + "bundleName": "com.ohos.aamsst.appA", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.AamsSystemTestA.src", + "name":"AamsSystemTestA", + "deviceType": [ + "tv", + "car" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "testability", + "moduleType": "entry" + }, + "abilities": [{ + "name": "AamsStAbilityA1", + "icon": "$media:snowball", + "label": "AamsStAbilityA1 Ability", + "launchType": "singletop", + "orientation": "unspecified", + "type": "page", + "visible": true + }] + } +} \ No newline at end of file diff --git a/test/resource/native_application/aamsSystemTestA/include/amsstabilitya1.h b/test/resource/native_application/aamsSystemTestA/include/amsstabilitya1.h new file mode 100644 index 00000000..eaf735a6 --- /dev/null +++ b/test/resource/native_application/aamsSystemTestA/include/amsstabilitya1.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef _AAMS_ST_ABILITY_A1_ +#define _AAMS_ST_ABILITY_A1_ +// #include "stpageabilityevent.h" +#include +#include +#include "ability_loader.h" +#include "hilog_wrapper.h" +#include "accessible_ability.h" +#include "accessibility_event_info.h" +#include "key_event.h" + +namespace OHOS { +namespace AppExecFwk { + +class AccessibleAbilityListenerTest; + +class AamsStAbilityA1 : public Ability { +public: + AamsStAbilityA1() {} + ~AamsStAbilityA1() {} + void DisableAbility(); + void GetFocusElementInfo(); + void GestureSimulate(); + void GetDisplayResizeController(); + void GetRootElementInfo(); + void GetWindows(); + void PerformCommonAction(); + void GetFingerprintController(); + +protected: + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; + virtual void OnForeground(const Want &want) override; + virtual void OnNewWant(const Want &want) override; + +private: + void Clear(); + void GetWantInfo(const Want &want); + + void RegisterListenerToAA(); + void ConnectToAAMS(); + + std::string shouldReturn; + std::string targetBundle; + std::string targetAbility; + // STPageAbilityEvent pageAbilityEvent; + + std::shared_ptr listener_ = nullptr; +}; + +class AccessibleAbilityListenerTest : public Accessibility::AccessibleAbilityListener { +public: + AccessibleAbilityListenerTest() {} + ~AccessibleAbilityListenerTest() {} + + void OnAbilityConnected() override; + void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& eventInfo) override; + void OnGesture(uint32_t gestureId) override; + void OnInterrupt() override; + bool OnKeyPressEvent(const MMI::KeyEvent& keyEvent) override; + +private: + std::shared_ptr aamsStAbilityA1_ = std::make_shared(); +}; + +} // namespace AppExecFwk +} // namespace OHOS +#endif // _AMS_ST_ABILITY_A1_ \ No newline at end of file diff --git a/test/resource/native_application/aamsSystemTestA/src/amsstabilitya1.cpp b/test/resource/native_application/aamsSystemTestA/src/amsstabilitya1.cpp new file mode 100644 index 00000000..582667ba --- /dev/null +++ b/test/resource/native_application/aamsSystemTestA/src/amsstabilitya1.cpp @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2021 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. + */ + +#include +#include "amsstabilitya1.h" +#include "accessibility_element_info.h" + +using namespace OHOS::Accessibility; + +namespace OHOS { +namespace AppExecFwk { + +void AccessibleAbilityListenerTest::OnAbilityConnected() +{ + HILOG_INFO("AamsStAbilityA1: Accessible application is connected."); + aamsStAbilityA1_->GetWindows(); +} + +void AccessibleAbilityListenerTest::OnAccessibilityEvent(const AccessibilityEventInfo& eventInfo) +{ + HILOG_INFO("AamsStAbilityA1: An Accessibility event is received and eventType is %{public}d", eventInfo.GetEventType()); +} + +void AccessibleAbilityListenerTest::OnGesture(uint32_t gestureId) +{ + HILOG_INFO("AamsStAbilityA1: A gesture is received and gestureId is %{public}d.", gestureId); +} + +void AccessibleAbilityListenerTest::OnInterrupt() +{ + HILOG_INFO("AamsStAbilityA1: Accessible application is on interrupt."); +} + +bool AccessibleAbilityListenerTest::OnKeyPressEvent(const MMI::KeyEvent& keyEvent) +{ + HILOG_INFO("AamsStAbilityA1: A key press event is received"); + return true; +} + +void AamsStAbilityA1::OnStart(const Want &want) +{ + GetWantInfo(want); + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); + Ability::OnStart(want); + + RegisterListenerToAA(); + ConnectToAAMS(); +} + +void AamsStAbilityA1::OnNewWant(const Want &want) +{ + GetWantInfo(want); + + HILOG_INFO("AamsStAbilityA1::OnNewWant"); + Ability::OnNewWant(want); +} + +void AamsStAbilityA1::OnForeground(const Want &want) +{ + GetWantInfo(want); + + HILOG_INFO("AamsStAbilityA1::OnForeground"); + Ability::OnForeground(want); +} + +void AamsStAbilityA1::OnStop() +{ + HILOG_INFO("AamsStAbilityA1::onStop"); + Ability::OnStop(); +} + +void AamsStAbilityA1::OnActive() +{ + HILOG_INFO("AamsStAbilityA1::OnActive"); + Ability::OnActive(); + if (std::string::npos != shouldReturn.find(GetAbilityName())) { + TerminateAbility(); + } + Clear(); +} + +void AamsStAbilityA1::OnInactive() +{ + HILOG_INFO("AamsStAbilityA1::OnInactive"); + Ability::OnInactive(); +} + +void AamsStAbilityA1::OnBackground() +{ + HILOG_INFO("AamsStAbilityA1::OnBackground"); + Ability::OnBackground(); +} + +void AamsStAbilityA1::Clear() +{ + shouldReturn = ""; + targetBundle = ""; + targetAbility = ""; +} + +void AamsStAbilityA1::GetWantInfo(const Want &want) +{ + Want mWant(want); + shouldReturn = mWant.GetStringParam("shouldReturn"); + targetBundle = mWant.GetStringParam("targetBundle"); + targetAbility = mWant.GetStringParam("targetAbility"); +} + +void AamsStAbilityA1::RegisterListenerToAA() +{ + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); + listener_ = std::make_shared(); + if (!listener_) { + HILOG_ERROR("listener_ is nullptr."); + return; + } + Accessibility::AccessibleAbility::GetInstance().RegisterListener(listener_); +} + +void AamsStAbilityA1::ConnectToAAMS() +{ + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); + Accessibility::AccessibleAbility::GetInstance().ConnectToAAMS(); +} + +void AamsStAbilityA1::DisableAbility() +{ + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); +} + +void AamsStAbilityA1::GetFocusElementInfo() +{ + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); +} + +void AamsStAbilityA1::GestureSimulate() +{ + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); +} + +void AamsStAbilityA1::GetDisplayResizeController() +{ + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); +} + +void AamsStAbilityA1::GetRootElementInfo() +{ + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); + std::optional elementInfo; + Accessibility::AccessibleAbility::GetInstance().GetRootElementInfo(elementInfo); + + if (elementInfo.has_value()) { + HILOG_INFO("elementInfo has value."); + } else { + HILOG_INFO("elementInfo has no value."); + } +} + +void AamsStAbilityA1::GetWindows() +{ + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); + + std::vector accessibilityWindow = + Accessibility::AccessibleAbility::GetInstance().GetWindows(); + + HILOG_INFO("accessibilityWindow.size() is %{public}d.", accessibilityWindow.size()); +} + +void AamsStAbilityA1::PerformCommonAction() +{ + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); +} + +void AamsStAbilityA1::GetFingerprintController() { + HILOG_INFO("AamsStAbilityA1::%{public}s start", __func__); +} + +REGISTER_AA(AamsStAbilityA1) +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/native_application/aamsSystemTestB/BUILD.gn b/test/resource/native_application/aamsSystemTestB/BUILD.gn new file mode 100644 index 00000000..9986f24b --- /dev/null +++ b/test/resource/native_application/aamsSystemTestB/BUILD.gn @@ -0,0 +1,58 @@ +# Copyright (c) 2021 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("//build/ohos.gni") +SUBDEMOSYSTEM_DIR = "//base/accessibility/test/resource/native_application/aamsSystemTestB" +config("aamsSystemTestBConfig") { + visibility = [ ":*" ] + include_dirs = [ + "${SUBDEMOSYSTEM_DIR}/include", + "//foundation/appexecfwk/standard/kits/appkit/native/app", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//base/accessibility/frameworks/asacfwk/include", + "//base/accessibility/interfaces/innerkits/asacfwk/include", + "//base/accessibility/frameworks/aafwk/include", + "//base/accessibility/util/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//base/accessibility/common/log/include", + ] + defines = [ + "AAMS_LOG_TAG = \"aamsSystemTest\"", + "AAMS_LOG_DOMAIN = 0xD005203", + ] +} +ohos_shared_library("aamsSystemTestB") { + sources = [ + "${SUBDEMOSYSTEM_DIR}/src/amsstabilityb1.cpp", + ] + configs = [ ":aamsSystemTestBConfig" ] + deps = [ + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "//foundation/appexecfwk/standard/kits:appkit_native", + "//utils/native/base:utilsbase", + "//base/accessibility/interfaces/innerkits/asacfwk:accessibilityclient", + "//utils/native/base:utils", + "//base/accessibility/services/aams:accessibleabilityms", + "//base/accessibility/frameworks/aafwk:accessibleability", + ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + subsystem_name = "aamssystemtest" +} diff --git a/test/resource/native_application/aamsSystemTestB/config.json b/test/resource/native_application/aamsSystemTestB/config.json new file mode 100644 index 00000000..3a1d8cb5 --- /dev/null +++ b/test/resource/native_application/aamsSystemTestB/config.json @@ -0,0 +1,40 @@ +{ + "app":{ + "bundleName": "com.ohos.amsst.appB", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.AamsSystemTestB.src", + "name":"AamsSystemTestB", + "deviceType": [ + "tv", + "car" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "testability", + "moduleType": "entry" + }, + "abilities": [{ + "name": "AamsStAbilityB1", + "icon": "$media:snowball", + "label": "AbilityB1 Ability", + "launchType": "singleton", + "orientation": "unspecified", + "type": "page", + "visible": true + }] + } +} \ No newline at end of file diff --git a/test/resource/native_application/aamsSystemTestB/include/amsstabilityb1.h b/test/resource/native_application/aamsSystemTestB/include/amsstabilityb1.h new file mode 100644 index 00000000..e6281b4b --- /dev/null +++ b/test/resource/native_application/aamsSystemTestB/include/amsstabilityb1.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef _AAMS_ST_ABILITY_B1_ +#define _AAMS_ST_ABILITY_B1_ +#include +#include "ability_loader.h" +#include "accessibility_interaction_operation.h" +#include "accessibility_state_event.h" +#include "accessible_ability.h" +#include "key_event.h" + +namespace OHOS { +namespace AppExecFwk { + +class AccessibleAbilityListenerTest; + +class AamsStAbilityB1 : public Ability { +protected: + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; + virtual void OnForeground(const Want &want) override; + virtual void OnNewWant(const Want &want) override; +public: + //aams + void Interrupt(); + void RegisterInteractionOperation(); + void DeregisterInteractionOperation(); + void GetAbilityList(); + void GetSuggestedInterval(); + void GetAccessibilityCaptionProperties(); + void SendEventWithType(); + void SendEvent(); + //state callback + void SubscribeStateObserver(); + void UnsubscribeStateObserver(); + void UnsubscribeStateObserverEventType(); + + //AA->AAMS + void RegisterListenerToAA(); + void ConnectToAAMS(); + void GetRootElementInfo(); + std::string shouldReturn; +private: + void Clear(); + void GetWantInfo(const Want &want); + + std::string targetBundle; + std::string targetAbility; + + std::shared_ptr listener_ = nullptr; +}; + +class AccessibilityInteractionOperationTest : public Accessibility::AccessibilityInteractionOperation{ +public: + AccessibilityInteractionOperationTest() {} + virtual ~AccessibilityInteractionOperationTest() = default; + void SearchElementInfoByAccessibilityId(const long elementId, + const int requestId, Accessibility::AccessibilityInteractionOperationCallback &callback, const int mode)override; + void SearchElementInfosByText(const long elementId, const std::string &text, + const int requestId, Accessibility::AccessibilityInteractionOperationCallback &callback)override; + void FindFocusedElementInfo(const long elementId, const int focusType, const int requestId, + Accessibility::AccessibilityInteractionOperationCallback &callback)override; + void FocusMoveSearch(const long elementId, const int direction, const int requestId, + Accessibility::AccessibilityInteractionOperationCallback &callback)override; + void PerformAction(const long elementId, const int action, const std::map actionArguments, + const int requestId, Accessibility::AccessibilityInteractionOperationCallback &callback)override; + void ClearFocus()override; + void OutsideTouch()override; +}; + +class AccessibilityStateObserverTest : public Accessibility::AccessibilityStateObserver{ +public: + AccessibilityStateObserverTest() {} + virtual ~AccessibilityStateObserverTest() = default; + void OnStateChanged(const Accessibility::AccessibilityStateEvent& stateEvent) override; +}; + +class AccessibleAbilityListenerTest : public Accessibility::AccessibleAbilityListener { +public: + AccessibleAbilityListenerTest() {} + ~AccessibleAbilityListenerTest() {} + + void OnAbilityConnected() override; + void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& eventInfo) override; + void OnGesture(uint32_t gestureId) override; + void OnInterrupt() override; + bool OnKeyPressEvent(const MMI::KeyEvent& keyEvent) override; + +private: + std::shared_ptr aamsStAbilityB1_ = std::make_shared(); +}; + +} // namespace AppExecFwk +} // namespace OHOS +#endif // _AMS_ST_ABILITY_E1_ \ No newline at end of file diff --git a/test/resource/native_application/aamsSystemTestB/src/amsstabilityb1.cpp b/test/resource/native_application/aamsSystemTestB/src/amsstabilityb1.cpp new file mode 100644 index 00000000..02c082d1 --- /dev/null +++ b/test/resource/native_application/aamsSystemTestB/src/amsstabilityb1.cpp @@ -0,0 +1,355 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "amsstabilityb1.h" +#include "accessibility_system_ability_client.h" +#include "accessibility_ability_info.h" + +#include "hilog_wrapper.h" +#include "refbase.h" + +using namespace OHOS::Accessibility; + +namespace OHOS { +namespace AppExecFwk { + +#define TESTWINDOWID 0 +#define TESTUSERID 0 +#define STATETYPE 1 + +void AccessibleAbilityListenerTest::OnAbilityConnected() +{ + HILOG_INFO("######################AamsStAbilityB1: Accessible application is connected."); + AbilityContext context; + auto eventType = Accessibility::EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT; + int componentId = 1; + AccessibilitySystemAbilityClient::GetInstance(context)->SendEvent(eventType, componentId); +} + +void AccessibleAbilityListenerTest::OnAccessibilityEvent(const AccessibilityEventInfo& eventInfo) +{ + HILOG_INFO("######################AamsStAbilityB1: An Accessibility event is received and eventType is %{public}d", eventInfo.GetEventType()); + + //Accessibility::AccessibleAbility::GetInstance().GetRootElementInfo(); + std::optional elementInfo; + Accessibility::AccessibleAbility::GetInstance().GetRootElementInfo(elementInfo); + + if (elementInfo.has_value()) { + HILOG_INFO("elementInfo has value."); + } else { + HILOG_INFO("elementInfo has no value."); + } +} + +void AccessibleAbilityListenerTest::OnGesture(uint32_t gestureId) +{ + HILOG_INFO("######################AamsStAbilityB1: A gesture is received and gestureId is %{public}d.", gestureId); +} + +void AccessibleAbilityListenerTest::OnInterrupt() +{ + HILOG_INFO("######################AamsStAbilityB1: Accessible application is on interrupt."); +} + +bool AccessibleAbilityListenerTest::OnKeyPressEvent(const MMI::KeyEvent& keyEvent) +{ + HILOG_INFO("######################AamsStAbilityB1: A key press event is received"); + return true; +} + +void AamsStAbilityB1::OnStart(const Want &want) +{ + GetWantInfo(want); + + HILOG_INFO("######################AamsStAbilityB1::onStart"); + RegisterInteractionOperation(); + AbilityContext context; + auto eventType = Accessibility::EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT; + int componentId = 1; + AccessibilitySystemAbilityClient::GetInstance(context)->SendEvent(eventType, componentId); + //RegisterListenerToAA(); + //ConnectToAAMS(); + //SendEventWithType(); +} + +void AamsStAbilityB1::OnForeground(const Want &want) +{ + GetWantInfo(want); + + HILOG_INFO("AamsStAbilityB1::OnForeground"); + Ability::OnForeground(want); +} + +void AamsStAbilityB1::OnNewWant(const Want &want) +{ + GetWantInfo(want); + + HILOG_INFO("AamsStAbilityB1::OnNewWant"); + Ability::OnNewWant(want); +} + +void AamsStAbilityB1::OnStop() +{ + HILOG_INFO("AamsStAbilityB1::onStop"); + Ability::OnStop(); +} + +void AamsStAbilityB1::OnActive() +{ + HILOG_INFO("AamsStAbilityB1::OnActive"); + Ability::OnActive(); + if (std::string::npos != shouldReturn.find(GetAbilityName())) { + TerminateAbility(); + } + Clear(); +} + +void AamsStAbilityB1::OnInactive() +{ + HILOG_INFO("AamsStAbilityB1::OnInactive"); + Ability::OnInactive(); +} + +void AamsStAbilityB1::OnBackground() +{ + HILOG_INFO("AamsStAbilityB1::OnBackground"); + Ability::OnBackground(); +} + +void AamsStAbilityB1::Clear() +{ + shouldReturn = ""; + targetBundle = ""; + targetAbility = ""; +} + +void AamsStAbilityB1::GetWantInfo(const Want &want) +{ + Want mWant(want); + shouldReturn = mWant.GetStringParam("shouldReturn"); + targetBundle = mWant.GetStringParam("targetBundle"); + targetAbility = mWant.GetStringParam("targetAbility"); +} + +void AamsStAbilityB1::Interrupt() +{ + HILOG_INFO("AamsStAbilityB1::Interrupt"); + AbilityContext context; + Accessibility::AccessibilitySystemAbilityClient::GetInstance(context)->Interrupt(); +} + +void AamsStAbilityB1::RegisterInteractionOperation() +{ + HILOG_INFO("AamsStAbilityB1::RegisterInteractionOperation"); + AbilityContext context; + int windowId = 0; + int userId = TESTUSERID; + std::shared_ptr interactionOperation(new AccessibilityInteractionOperationTest()); + Accessibility::AccessibilitySystemAbilityClient::GetInstance(context)->RegisterInteractionOperation( + windowId, interactionOperation, userId); +} + +void AamsStAbilityB1::DeregisterInteractionOperation() +{ + HILOG_INFO("AamsStAbilityB1::DeregisterInteractionOperation"); + AbilityContext context; + int windowId = TESTWINDOWID; + Accessibility::AccessibilitySystemAbilityClient::GetInstance(context)->DeregisterInteractionOperation(windowId); +} + +void AamsStAbilityB1::GetAbilityList() +{ + HILOG_INFO("AamsStAbilityB1::GetAbilityList"); + AbilityContext context; + int accessibilityAbilityTypes = Accessibility::AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN; + auto stateType = Accessibility::AbilityStateType::ABILITY_STATE_ENABLE; + AccessibilitySystemAbilityClient::GetInstance(context)->GetAbilityList(accessibilityAbilityTypes, stateType); +} + +void AamsStAbilityB1::GetSuggestedInterval() +{ + HILOG_INFO("AamsStAbilityB1::GetSuggestedInterval"); + AbilityContext context; + int timeout = 1; + int contentType = 1; + AccessibilitySystemAbilityClient::GetInstance(context)->GetSuggestedInterval(timeout, contentType); +} + +void AamsStAbilityB1::SendEventWithType() +{ + HILOG_INFO("###################AamsStAbilityB1::SendEventWithType"); + AbilityContext context; + auto eventType = Accessibility::EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT; + int componentId = 1; + AccessibilitySystemAbilityClient::GetInstance(context)->SendEvent(eventType, componentId); +} + +void AamsStAbilityB1::SendEvent() +{ + HILOG_INFO("AamsStAbilityB1::SendEvent"); + AbilityContext context; + AccessibilityEventInfo eventInfo; + AccessibilitySystemAbilityClient::GetInstance(context)->SendEvent(eventInfo); +} + +void AamsStAbilityB1::SubscribeStateObserver() +{ + HILOG_INFO("AamsStAbilityB1::SubscribeStateObserver"); + AbilityContext context; + auto eventType = Accessibility::EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT; + std::shared_ptr stateObserver(new AccessibilityStateObserverTest()); + + AccessibilitySystemAbilityClient::GetInstance(context)->SubscribeStateObserver(stateObserver, eventType); +} + +void AamsStAbilityB1::UnsubscribeStateObserver() +{ + HILOG_INFO("AamsStAbilityB1::UnsubscribeStateObserver"); + AbilityContext context; + auto eventType = Accessibility::EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT; + std::shared_ptr stateObserver(new AccessibilityStateObserverTest()); + + AccessibilitySystemAbilityClient::GetInstance(context)->UnsubscribeStateObserver(stateObserver, eventType); +} + +void AamsStAbilityB1::UnsubscribeStateObserverEventType() +{ + HILOG_INFO("AamsStAbilityB1::UnsubscribeStateObserverEventType"); + AbilityContext context; + std::shared_ptr stateObserver(new AccessibilityStateObserverTest()); + AccessibilitySystemAbilityClient::GetInstance(context)->UnsubscribeStateObserver(stateObserver); +} + +void AamsStAbilityB1::RegisterListenerToAA() +{ + HILOG_INFO("###############################AamsStAbilityB1::%{public}s start", __func__); + listener_ = std::make_shared(); + if (!listener_) { + HILOG_ERROR("###############################listener_ is nullptr."); + return; + } + Accessibility::AccessibleAbility::GetInstance().RegisterListener(listener_); +} + +void AamsStAbilityB1::ConnectToAAMS() +{ + HILOG_INFO("###############################AamsStAbilityB1::%{public}s start", __func__); + Accessibility::AccessibleAbility::GetInstance().ConnectToAAMS(); +} + +void AamsStAbilityB1::GetRootElementInfo() +{ + HILOG_INFO("####################AamsStAbilityB1::%{public}s start", __func__); + std::optional elementInfo; + Accessibility::AccessibleAbility::GetInstance().GetRootElementInfo(elementInfo); + + if (elementInfo.has_value()) { + HILOG_INFO("elementInfo has value."); + } else { + HILOG_INFO("elementInfo has no value."); + } +} + +void AccessibilityInteractionOperationTest::SearchElementInfoByAccessibilityId(const long elementId, + const int requestId, Accessibility::AccessibilityInteractionOperationCallback &callback, const int mode) +{ + HILOG_INFO("###############################AamsStAbilityB1::%{public}s start", __func__); + AccessibilityElementInfo info; + info.SetBundleName("testapp_B1"); + info.SetWindowId(0); + info.SetCheckable(true); + info.SetHint("testapp_B1_findFocus_fang-ch"); + info.AddChild(2); + std::list infos{}; + infos.push_back(info); + //Accessibility::AccessibilityInteractionOperationStub::CallbackImpl tempCallback = const_cast(callback); + callback.SetSearchElementInfoByAccessibilityIdResult(infos,requestId); +} + +void AccessibilityInteractionOperationTest::SearchElementInfosByText(const long elementId, const std::string &text, + const int requestId, Accessibility::AccessibilityInteractionOperationCallback &callback) +{ + HILOG_INFO("###############################AamsStAbilityB1::%{public}s start", __func__); + AccessibilityElementInfo info; + info.SetBundleName("fang-ch"); + info.SetWindowId(0); + info.SetComponentType("2021年"); + info.SetCheckable(true); + info.SetHint("testapp_B1_findFocus_fang-ch"); + std::list infos{}; + infos.push_back(info); + callback.SetSearchElementInfoByTextResult(infos, requestId); + HILOG_INFO("###############################AamsStAbilityB1::=================SearchElementInfosByText===========success========="); +} + +void AccessibilityInteractionOperationTest::FindFocusedElementInfo(const long elementId, const int focusType, const int requestId, + Accessibility::AccessibilityInteractionOperationCallback &callback) +{ + HILOG_INFO("###############################AamsStAbilityB1::%{public}s start", __func__); + AccessibilityElementInfo info; + info.SetWindowId(0); + info.SetBundleName("testapp_B1_findFocus"); + info.SetCheckable(true); + info.SetHint("testapp_B1_findFocus_fang-ch"); + callback.SetFindFocusedElementInfoResult(info, requestId); + HILOG_INFO("###############################AamsStAbilityB1::=================FindFocusedElementInfo===========success========="); +} + +void AccessibilityInteractionOperationTest::FocusMoveSearch(const long elementId, const int direction, const int requestId, + Accessibility::AccessibilityInteractionOperationCallback &callback) +{ + HILOG_INFO("###############################AamsStAbilityB1::%{public}s start", __func__); + AccessibilityElementInfo info; + info.SetWindowId(0); + info.SetBundleName("testapp_B1_FocusMoveSearch"); + info.SetCheckable(true); + info.SetHint("testapp_B1_FocusMoveSearch_fang-ch"); + info.SetParent(2); + + callback.SetFocusMoveSearchResult(info, requestId); + HILOG_INFO("###############################AamsStAbilityB1::=================FocusMoveSearch===========success========="); +} + +void AccessibilityInteractionOperationTest::PerformAction(const long elementId, const int action, const std::map actionArguments, + int requestId, Accessibility::AccessibilityInteractionOperationCallback &callback) +{ + HILOG_INFO("###############################AamsStAbilityB1::%{public}s start", __func__); + AccessibilityElementInfo info; + info.SetWindowId(0); + info.SetBundleName("testapp_B1_findFocus"); + info.SetCheckable(true); + info.SetHint("testapp_B1_findFocus_fang-ch"); + callback.SetPerformActionResult(true, requestId); + HILOG_INFO("###############################AamsStAbilityB1::=================PerformAction===========success========="); +} + +void AccessibilityInteractionOperationTest::ClearFocus() +{ + HILOG_INFO("###############################AamsStAbilityB1::%{public}s start", __func__); +} + +void AccessibilityInteractionOperationTest::OutsideTouch() +{ + HILOG_INFO("###############################AamsStAbilityB1::%{public}s start", __func__); +} + +void AccessibilityStateObserverTest::OnStateChanged(const Accessibility::AccessibilityStateEvent& stateEvent) +{ + HILOG_INFO("###############################AamsStAbilityB1::%{public}s start", __func__); +} + +REGISTER_AA(AamsStAbilityB1); +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/native_application/common/kit_test_common_info.h b/test/resource/native_application/common/kit_test_common_info.h new file mode 100644 index 00000000..ab1dc4dc --- /dev/null +++ b/test/resource/native_application/common/kit_test_common_info.h @@ -0,0 +1,429 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef KIT_TEST_COMMON_INFO_H +#define KIT_TEST_COMMON_INFO_H + +namespace OHOS { +namespace AppExecFwk { +constexpr int pressureTimes = 3; +const std::string g_EVENT_REQU_FIRST = "requ_com_ohos_amsst_appkit_first"; +const std::string g_EVENT_RESP_FIRST = "resp_com_ohos_amsst_appkit_first"; +const std::string g_EVENT_RESP_FIRST_LIFECYCLE = "resp_com_ohos_amsst_appkit_first_lifecycle"; +const std::string g_EVENT_RESP_FIRST_LIFECYCLE_CALLBACK = "resp_com_ohos_amsst_appkit_first_lifecycle_callbacks"; +const std::string g_EVENT_RESP_FIRST_LIFECYCLE_OBSERVER = "resp_com_ohos_amsst_appkit_first_lifecycle_observer"; +const std::string g_EVENT_RESP_FIRST_LIFECYCLE_OBSERVER2 = "resp_com_ohos_amsst_appkit_first_lifecycle_observer2"; +const std::string g_EVENT_RESP_FIRST_ON_ABILITY_RESULT = "resp_com_ohos_amsst_appkit_first_onabilityresult"; +const std::string g_EVENT_RESP_FIRST_ON_BACK_PRESSED = "resp_com_ohos_amsst_appkit_first_onbackpressed"; +const std::string g_EVENT_RESP_FIRST_ON_NEW_WANT = "resp_com_ohos_amsst_appkit_first_onnewwant"; +const std::string g_EVENT_REQU_FIRSTB = "requ_com_ohos_amsst_appkit_firstb"; +const std::string g_EVENT_RESP_FIRSTB = "resp_com_ohos_amsst_appkit_firstb"; +const std::string g_EVENT_RESP_FIRSTB_LIFECYCLE = "resp_com_ohos_amsst_appkit_firstb_lifecycle"; +const std::string g_EVENT_REQU_SECOND = "requ_com_ohos_amsst_appkit_second"; +const std::string g_EVENT_RESP_SECOND = "resp_com_ohos_amsst_appkit_second"; +const std::string g_EVENT_RESP_SECOND_LIFECYCLE = "resp_com_ohos_amsst_appkit_second_lifecycle"; +const std::string g_EVENT_RESP_SECOND_ABILITY_CONTEXT = "resp_com_ohos_amsst_appkit_secondability_ability_context"; +const std::string g_EVENT_RESP_SECOND_ABILITY_API = "resp_com_ohos_amsst_appkit_secondability_ability_api"; +// PageAbility: ThirdAbility Constants to use +const std::string g_respPageThirdAbilityST = "resp_com_ohos_amsst_appkit_third_ability"; +const std::string g_requPageThirdAbilityST = "requ_com_ohos_amsst_appkit_third_ability"; +const std::vector g_requPageThirdAbilitySTVector = {g_requPageThirdAbilityST}; +// PageAbility: FourthAbility Constants to use +const std::string g_respPageFourthAbilityST = "resp_com_ohos_amsst_appkit_fourth_ability"; +const std::string g_requPageFourthAbilityST = "requ_com_ohos_amsst_appkit_fourth_ability"; +const std::vector g_requPageFourthAbilitySTVector = {g_requPageFourthAbilityST}; +// PageAbility: SixthAbility Constants to use +const std::string g_respPageSixthAbilityST = "resp_com_ohos_amsst_appkit_sixth_ability"; +const std::string g_respPageSixthAbilityLifecycleCallbacks = "resp_sixth_ability_lifecycle_callback"; +const std::string g_requPageSixthAbilityST = "requ_com_ohos_amsst_appkit_sixth_ability"; +const std::vector g_requPageSixthAbilitySTVector = {g_requPageSixthAbilityST}; +// PageAbility: KitTestAbilityManager Constants to use +const std::string g_respPageManagerAbilityST = "resp_com_ohos_amsst_appkit_manager_ability"; +const std::string g_requPageManagerAbilityST = "requ_com_ohos_amsst_appkit_manager_ability"; +const std::vector g_requPageManagerAbilitySTVector = {g_requPageManagerAbilityST}; +// PageAbility: KitTestAbilityManagerSecond Constants to use +const std::string g_respPageManagerSecondAbilityST = "resp_com_ohos_amsst_appkit_manager_second_ability"; +const std::string g_requPageManagerSecondAbilityST = "requ_com_ohos_amsst_appkit_manager_second_ability"; +const std::vector g_requPageManagerSecondAbilitySTVector = {g_requPageManagerSecondAbilityST}; +const std::string g_onAbilityStart = ":OnAbilityStart"; +const std::string g_onAbilityInactive = ":OnAbilityInactive"; +const std::string g_onAbilityBackground = ":OnAbilityBackground"; +const std::string g_onAbilityForeground = ":OnAbilityForeground"; +const std::string g_onAbilityActive = ":OnAbilityActive"; +const std::string g_onAbilityStop = ":OnAbilityStop"; +const std::string g_onAbilitySaveState = ":OnAbilitySaveState"; +const std::string g_memoryLevel = ":OnMemoryLevel"; +const std::string g_configuration = ":OnConfigurationUpdated"; +const std::string g_abilityStateOnStart = ":OnStart"; +const std::string g_abilityStateOnStop = ":OnStop"; +const std::string g_abilityStateOnActive = ":OnActive"; +const std::string g_abilityStateOnInactive = ":OnInactive"; +const std::string g_abilityStateOnBackground = ":OnBackground"; +const std::string g_abilityStateOnForeground = ":OnForeground"; +const std::string g_abilityStateOnNewWant = ":OnNewWant"; +const std::string g_EVENT_REQU_FIFTH = "requ_com_ohos_amsst_appkit_fifth"; +const std::string g_EVENT_RESP_FIFTH = "resp_com_ohos_amsst_appkit_fifth"; + +enum class WantApi { + WantCopy, + WantAssign, + AddEntity, + AddFlags, + ClearWant, + CountEntities, + FormatMimeType, + FormatType, + FormatUri, + FormatUriAndType, + GetAction, + GetBundle, + GetEntities, + GetElement, + GetUri, + GetUriString, + GetFlags, + GetScheme, + GetType, + HasEntity, + MakeMainAbility, + Marshalling, + ParseUri, + RemoveEntity, + RemoveFlags, + SetAction, + SetBundle, + SetElement, + SetElementName_String_String, + SetElementName_String_String_String, + SetFlags, + SetType, + SetUri, + SetUriAndType, + ToUri, + Unmarshalling, + WantParseUri, + WantToUri, + GetParams, + GetByteParam, + GetByteArrayParam, + GetBoolParam, + GetBoolArrayParam, + GetCharParam, + GetCharArrayParam, + GetIntParam, + GetIntArrayParam, + GetDoubleParam, + GetDoubleArrayParam, + GetFloatParam, + GetFloatArrayParam, + GetLongParam, + GetLongArrayParam, + GetShortParam, + GetShortArrayParam, + GetStringParam, + GetStringArrayParam, + SetParam_WantParams, + SetParam_byte, + SetParam_byte_array, + SetParam_bool, + SetParam_bool_array, + SetParam_char, + SetParam_char_array, + SetParam_int, + SetParam_int_array, + SetParam_double, + SetParam_double_array, + SetParam_float, + SetParam_float_array, + SetParam_long, + SetParam_long_array, + SetParam_short, + SetParam_short_array, + SetParam_string, + SetParam_string_array, + HasParameter, + ReplaceParams_WantParams, + ReplaceParams_Want, + RemoveParam, + GetOperation, + SetOperation, + OperationEquals, + CloneOperation, + End +}; + +enum class SkillsApi { + AddAction = (int)WantApi::End, + CountActions, + GetAction, + HasAction, + RemoveAction, + AddEntity, + CountEntities, + GetEntity, + HasEntity, + RemoveEntity, + AddAuthority, + CountAuthorities, + GetAuthority, + HasAuthority, + RemoveAuthority, + AddScheme, + CountSchemes, + GetScheme, + HasScheme, + RemoveScheme, + AddSchemeSpecificPart, + CountSchemeSpecificParts, + GetSchemeSpecificPart, + HasSchemeSpecificPart, + RemoveSchemeSpecificPart, + AddPath_String, + AddPath_String_MatchType, + AddPath_PatternMatcher, + AddPath_String_CountPaths, + AddPath_String_MatchType_CountPaths, + AddPath_PatternMatcher_CountPaths, + CountPaths, + AddPath_String_GetPath, + AddPath_String_MatchType_GetPath, + AddPath_PatternMatcher_GetPath, + GetPath, + AddPath_String_HasPath, + AddPath_String_MatchType_HasPath, + AddPath_PatternMatcher_HasPath, + HasPath, + RemovePath_String, + RemovePath_String_MatchType, + RemovePath_PatternMatcher, + RemovePath_Other, + AddType_String, + AddType_String_MatchType, + AddType_PatternMatcher, + AddType_String_CountTypes, + AddType_String_MatchType_CountTypes, + AddType_PatternMatcher_CountTypes, + CountTypes, + AddType_String_GetType, + AddType_String_MatchType_GetType, + AddType_PatternMatcher_GetType, + GetType, + AddType_String_HasType, + AddType_String_MatchType_HasType, + AddType_PatternMatcher_HasType, + HasType, + RemoveType_String, + RemoveType_String_MatchType, + RemoveType_PatternMatcher, + RemoveType_Other, + GetEntities, + GetWantParams, + Match, + Unmarshalling, + Marshalling, + Skills, + Skills_Skills, + End +}; + +enum class AbilityApi { + GetAbilityName = (int)SkillsApi::End, + GetAbilityPackage, + GetLifecycle, + GetWant, + GetWindow, + Dump, + OnStart, + OnActive, + OnBackground, + OnInactive, + OnStop, + OnForeground, + OnAbilityResult, + OnBackPressed, + OnNewWant, + Reload, + SetResult, + SetWant, + StartAbilityForResult_Want_int, + StartAbility_Want, + StartAbility_Want_AbilityStartSetting, + TerminateAbility, + BatchInsert, + GetType, + OnKeyDown, + OnKeyUp, + OnTouchEvent, + End +}; + +enum class AbilityContextApi { + GetApplicationInfo = (int)AbilityApi::End, + GetCacheDir, + GetCodeCacheDir, + GetDatabaseDir, + GetDataDir, + GetDir, + GetNoBackupFilesDir, + GetBundleManager, + VerifyCallingPermission, + VerifyPermission, + VerifySelfPermission, + GetBundleCodePath, + GetBundleName, + GetBundleResourcePath, + CanRequestPermission, + GetApplicationContext, + GetCallingAbility, + GetContext, + GetAbilityManager, + GetProcessInfo, + GetAppType, + GetCallingBundle, + StartAbility_Want_int, + TerminateAbility, + GetElementName, + GetHapModuleInfo, + End +}; + +enum class LifeCycleApi { + GetLifecycleState = (int)AbilityContextApi::End, + AddObserver, + DispatchLifecycle_Event_Want, + DispatchLifecycle_Event, + RemoveObserver, + End +}; + +enum class AbilityLifecycleCallbacksApi { + OnAbilityStart = (int)LifeCycleApi::End, + OnAbilityInactive, + OnAbilityBackground, + OnAbilityForeground, + OnAbilityActive, + OnAbilityStop, + OnAbilitySaveState, + End +}; + +enum class AbilityManagerApi { + ClearUpApplicationData = (int)AbilityLifecycleCallbacksApi::End, + GetAllRunningProcesses, + GetAllStackInfo, + QueryRecentAbilityMissionInfo, + QueryRunningAbilityMissionInfo, + MoveMissionToTop, + End +}; + +enum class ContextApi { + CanRequestPermission = (int)AbilityManagerApi::End, + DeleteFile, + GetAbilityInfo, + GetApplicationInfo, + GetApplicationContext, + GetBundleCodePath, + GetBundleManager, + GetBundleName, + GetBundleResourcePath, + GetCallingBundle, + GetCacheDir, + GetCodeCacheDir, + GetDatabaseDir, + GetDataDir, + GetDir, + GetFilesDir, + GetHapModuleInfo, + GetNoBackupFilesDir, + GetProcessName, + GetResourceManager, + VerifyCallingPermission, + VerifySelfPermission, + StartAbility_Want_int, + TerminateAbility_int, + CreateBundleContext, + VerifyCallingOrSelfPermission, + VerifyPermission, + End +}; + +enum class ElementNameApi { + SetElementDeviceID = (int)ContextApi::End, + SetElementBundleName, + SetElementAbilityName, + ClearElement, + End +}; + +enum class OHOSApplicationApi { + RegisterAbilityLifecycleCallbacks = (int)ElementNameApi::End, + UnregisterAbilityLifecycleCallbacks, + DispatchAbilitySavedState, + OnConfigurationUpdated, + OnMemoryLevel, + OnStart, + OnTerminate, + RegisterElementsCallbacks, + UnregisterElementsCallbacks, + End +}; + +enum class LifecycleObserverApi { + OnActive = (int)OHOSApplicationApi::End, + OnBackground, + OnForeground, + OnInactive, + OnStart, + OnStop, + OnStateChanged_Event_Want, + OnStateChanged_Event, + End +}; + +enum class ProcessInfoApi { + GetPid = (int)LifecycleObserverApi::End, + GetProcessName, + Marshalling, + Unmarshalling, + ProcessInfo, + ProcessInfo_String_int, + End +}; + +enum class RunningProcessInfoApi { + GetProcessName = (int)ProcessInfoApi::End, + GetPid, + GetUid, + End, +}; + +enum class WantParamsApi { + HasParam = (int)RunningProcessInfoApi::End, + IsEmpty, + Marshalling, + Unmarshalling, + Size, + WantParamsCopy, + GetParam, + KeySet, + Remove, + SetParam, + End, +}; + +} // namespace AppExecFwk +} // namespace OHOS +#endif // KIT_TEST_COMMON_INFO_H \ No newline at end of file diff --git a/test/resource/native_application/tools/include/event.h b/test/resource/native_application/tools/include/event.h new file mode 100644 index 00000000..00ced741 --- /dev/null +++ b/test/resource/native_application/tools/include/event.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 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. + */ +#pragma once +#include +#include +#include + +namespace STtools { + +class Event { +public: + Event(); + ~Event(); + bool Compare(); + int WaitingMessage(const std::string &message, int timeout_ms, bool locked); + void CompleteMessage(const std::string &message); + void Clean(); + +private: + std::mutex mutex_; + std::condition_variable cv_; + std::string waiting_message_; + std::vector complete_message_; +}; + +int WaitCompleted(Event &event, const std::string &eventName, const int code, const int timeout = 60); +void Completed(Event &event, const std::string &eventName, const int code); +void CleanMsg(Event &event); + +} // namespace STtools \ No newline at end of file diff --git a/test/resource/native_application/tools/include/stoperator.h b/test/resource/native_application/tools/include/stoperator.h new file mode 100644 index 00000000..c0683c1a --- /dev/null +++ b/test/resource/native_application/tools/include/stoperator.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021 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. + */ +#pragma once +#include +#include +#include + +namespace STtools { +using std::string; +class StOperator; + +std::vector SerializationStOperatorToVector(StOperator &ParentOperator); + +void DeserializationStOperatorFromVector(StOperator &ParentOperator, std::vector &vectorOperator); + +class StOperator { +private: + std::vector> g_childOperator; + std::shared_ptr g_parentOperator; + string g_abilityType; + string g_bundleName; + string g_abilityName; + string g_operatorName; // data ability + string g_message; + /* data */ + static int countChild; + +public: + StOperator(); + StOperator(const string &type, const string &bundle, const string &ability, const string &operatorName = "", + const string &message = ""); + ~StOperator(); + static int GetCountChild(); + string GetAbilityType(); + StOperator &SetAbilityType(const string &type); + string GetBundleName(); + StOperator &SetBundleName(const string &bundleName); + string GetAbilityName(); + StOperator &SetAbilityName(const string &abilityName); + string GetOperatorName(); + StOperator &SetOperatorName(const string &operatorName); + string GetMessage(); + StOperator &SetMessage(const string &message); + StOperator &AddChildOperator(std::shared_ptr childOperator); + std::vector> GetChildOperator(); + std::vector> PopChildOperator(); +}; + +} // namespace STtools diff --git a/test/resource/native_application/tools/include/stpageabilityevent.h b/test/resource/native_application/tools/include/stpageabilityevent.h new file mode 100644 index 00000000..e90b2328 --- /dev/null +++ b/test/resource/native_application/tools/include/stpageabilityevent.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2021 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. + */ +#ifndef _AMS_ST_PAGE_ABILITY_EVENT_H_ +#define _AMS_ST_PAGE_ABILITY_EVENT_H_ + +#include +#include +#include +#include "common_event.h" +#include "common_event_manager.h" +#include "ability_loader.h" +#include "app_log_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { + +namespace STEventName { +const std::string g_eventName = "resp_st_page_ability_callback"; +const std::string g_pidEventName = "resp_st_page_ability_pid_callback"; +const std::string g_abilityStateOnStart = ":OnStart"; +const std::string g_abilityStateOnStop = ":OnStop"; +const std::string g_abilityStateOnActive = ":OnActive"; +const std::string g_abilityStateOnInactive = ":OnInactive"; +const std::string g_abilityStateOnBackground = ":OnBackground"; +const std::string g_abilityStateOnForeground = ":OnForeground"; +const std::string g_abilityStateOnNewWant = ":OnNewWant"; +const int eventCode = 0; +const std::vector g_eventList = {"requ_page_ability_terminate"}; +} // namespace STEventName + +class STPageAbilityEventSubscriber : public EventFwk::CommonEventSubscriber { +public: + STPageAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp, const std::shared_ptr &ability) + : CommonEventSubscriber(sp), ability_(std::move(ability)) + {} + ~STPageAbilityEventSubscriber() + {} + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + +private: + std::shared_ptr ability_; +}; + +class STPageAbilityEvent { +public: + STPageAbilityEvent() = default; + STPageAbilityEvent(const std::string &className); + ~STPageAbilityEvent() = default; + + bool PublishEvent(const std::string &eventName, const int &code, const std::string &data); + void SubscribeEvent(std::vector eventList, const std::shared_ptr &ability); + void UnsubscribeEvent(); + std::string GetEventDate(const std::string &stateCallbackCount); + std::string GetCallBackPath(const std::string &callBackPath); + std::string GetAbilityStatus(const std::string &abilityStatus); + + int GetOnStartCount(); + int GetOnStopCount(); + int GetOnActiveCount(); + int GetOnInactiveCount(); + int GetOnBackgroundCount(); + int GetOnForegroundCount(); + int GetOnNewWantCount(); + +private: + std::shared_ptr subscriber_; + int onStartCount_ = 0; + int onStopCount_ = 0; + int onActiveCount_ = 0; + int onInactiveCount_ = 0; + int onBackgroundCount_ = 0; + int onForegroundCount_ = 0; + int onNewWantCount_ = 0; + std::string componentType_; + std::string callBackPath_; + std::string abilityStatus_; +}; + +} // namespace AppExecFwk +} // namespace OHOS + +#endif //_AMS_ST_PAGE_ABILITY_EVENT_H_ \ No newline at end of file diff --git a/test/resource/native_application/tools/src/event.cpp b/test/resource/native_application/tools/src/event.cpp new file mode 100644 index 00000000..a51291b4 --- /dev/null +++ b/test/resource/native_application/tools/src/event.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021 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. + */ +#include "event.h" +#include +#include + +namespace STtools { + +int WaitCompleted(Event &event, const std::string &eventName, const int code, const int timeout) +{ + return event.WaitingMessage(std::to_string(code) + eventName, timeout, false); +} + +void Completed(Event &event, const std::string &eventName, const int code) +{ + return event.CompleteMessage(std::to_string(code) + eventName); +} + +void CleanMsg(Event &event) +{ + return event.Clean(); +} + +Event::Event() +{ + waiting_message_ = ""; + complete_message_.clear(); +} + +Event::~Event() +{ + waiting_message_ = ""; + std::vector tmp_vector; + tmp_vector.swap(complete_message_); + complete_message_.clear(); +} + +bool Event::Compare() +{ + if (!waiting_message_.empty()) { + for (size_t i = 0; i < complete_message_.size(); i++) { + if (waiting_message_.compare(complete_message_.at(i)) == 0) { + complete_message_.erase(std::begin(complete_message_) + i, std::begin(complete_message_) + i + 1); + waiting_message_ = ""; + return true; + } + } + } + return false; +} + +int Event::WaitingMessage(const std::string &message, int timeout_ms, bool locked) +{ + std::unique_lock lock(mutex_); + waiting_message_ = message; + if (Compare()) { + return 0; + } + + if (locked) { + cv_.wait(lock); + return 0; + } + + if (cv_.wait_for(lock, std::chrono::seconds(timeout_ms)) == std::cv_status::timeout) { + waiting_message_ = ""; + return -1; + } + return 0; +} + +void Event::CompleteMessage(const std::string &message) +{ + std::unique_lock lock(mutex_); + if (waiting_message_.compare(message) == 0) { + waiting_message_ = ""; + cv_.notify_all(); + return; + } + complete_message_.push_back(message); + return; +} + +void Event::Clean() +{ + waiting_message_ = ""; + complete_message_.clear(); +} + +} // namespace STtools \ No newline at end of file diff --git a/test/resource/native_application/tools/src/stoperator.cpp b/test/resource/native_application/tools/src/stoperator.cpp new file mode 100644 index 00000000..2c7ea20b --- /dev/null +++ b/test/resource/native_application/tools/src/stoperator.cpp @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2021 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. + */ +#include "stoperator.h" +#include + +namespace STtools { +using std::string; + +void PushOperatorInVector(std::vector &vectorOperator, StOperator &ParentOperator) +{ + vectorOperator.emplace_back(std::to_string(ParentOperator.GetChildOperator().size())); + vectorOperator.emplace_back(ParentOperator.GetAbilityType()); + vectorOperator.emplace_back(ParentOperator.GetBundleName()); + vectorOperator.emplace_back(ParentOperator.GetAbilityName()); + vectorOperator.emplace_back(ParentOperator.GetOperatorName()); + vectorOperator.emplace_back(ParentOperator.GetMessage()); + for (auto child : ParentOperator.GetChildOperator()) { + PushOperatorInVector(vectorOperator, *child); + } +} + +std::vector SerializationStOperatorToVector(StOperator &ParentOperator) +{ + std::vector vectorOperator; + PushOperatorInVector(vectorOperator, ParentOperator); + return vectorOperator; +} + +void PullOperatorFromVector(StOperator &ParentOperator, std::vector &vectorOperator) +{ + int childnum = std::stoi(vectorOperator.front()); + vectorOperator.erase(vectorOperator.begin()); + string abilityType = vectorOperator.front(); + vectorOperator.erase(vectorOperator.begin()); + string bundleName = vectorOperator.front(); + vectorOperator.erase(vectorOperator.begin()); + string abilityName = vectorOperator.front(); + vectorOperator.erase(vectorOperator.begin()); + string operatorName = vectorOperator.front(); + vectorOperator.erase(vectorOperator.begin()); + string message = vectorOperator.front(); + vectorOperator.erase(vectorOperator.begin()); + ParentOperator.SetAbilityType(abilityType) + .SetBundleName(bundleName) + .SetAbilityName(abilityName) + .SetOperatorName(operatorName) + .SetMessage(message); + for (int i = 0; i < childnum; i++) { + auto child = std::make_shared(); + if (child == nullptr) { + return; + } + ParentOperator.AddChildOperator(child); + PullOperatorFromVector(*(child.get()), vectorOperator); + } +} + +void DeserializationStOperatorFromVector(StOperator &ParentOperator, std::vector &vectorOperator) +{ + PullOperatorFromVector(ParentOperator, vectorOperator); +} + +int StOperator::countChild = 0; + +StOperator::StOperator() + : g_parentOperator(nullptr), g_abilityType("0"), g_bundleName(""), g_abilityName(""), g_operatorName(""), g_message("") +{ + g_childOperator.clear(); + StOperator::countChild++; +} + +StOperator::StOperator( + const string &type, const string &bundle, const string &ability, const string &operatorName, const string &message) + : g_parentOperator(nullptr), + g_abilityType(type), + g_bundleName(bundle), + g_abilityName(ability), + g_operatorName(operatorName), + g_message("") +{ + g_childOperator.clear(); + StOperator::countChild++; +} + +StOperator::~StOperator() +{ + g_childOperator.clear(); + StOperator::countChild--; +} + +int StOperator::GetCountChild() +{ + return StOperator::countChild; +} + +string StOperator::GetAbilityType() +{ + return g_abilityType; +} + +StOperator &StOperator::SetAbilityType(const string &type) +{ + g_abilityType = type; + return *this; +} + +string StOperator::GetBundleName() +{ + return g_bundleName; +} + +StOperator &StOperator::SetBundleName(const string &bundleName) +{ + g_bundleName = bundleName; + return *this; +} + +string StOperator::GetAbilityName() +{ + return g_abilityName; +} + +StOperator &StOperator::SetAbilityName(const string &abilityName) +{ + g_abilityName = abilityName; + return *this; +} + +string StOperator::GetOperatorName() +{ + return g_operatorName; +} + +StOperator &StOperator::SetOperatorName(const string &operatorName) +{ + g_operatorName = operatorName; + return *this; +} + +string StOperator::GetMessage() +{ + return g_message; +} + +StOperator &StOperator::SetMessage(const string &message) +{ + g_message = message; + return *this; +} + +StOperator &StOperator::AddChildOperator(std::shared_ptr childOperator) +{ + if (childOperator == nullptr) { + return *this; + } + childOperator->g_parentOperator = std::make_shared(*this); + g_childOperator.emplace_back(childOperator); + return *this; +} + +std::vector> StOperator::GetChildOperator() +{ + return g_childOperator; +} + +std::vector> StOperator::PopChildOperator() +{ + std::vector> popChildOperator = g_childOperator; + for (auto child : popChildOperator) { + child->g_parentOperator = nullptr; + } + g_childOperator.clear(); + return popChildOperator; +} +} // namespace STtools \ No newline at end of file diff --git a/test/resource/native_application/tools/src/stpageabilityevent.cpp b/test/resource/native_application/tools/src/stpageabilityevent.cpp new file mode 100644 index 00000000..d51f3510 --- /dev/null +++ b/test/resource/native_application/tools/src/stpageabilityevent.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "stpageabilityevent.h" + +namespace OHOS { +namespace AppExecFwk { + +using namespace OHOS::EventFwk; + +STPageAbilityEvent::STPageAbilityEvent(const std::string &className) +{ + this->componentType_ = className; +} + +bool STPageAbilityEvent::PublishEvent(const std::string &eventName, const int &code, const std::string &data) +{ + Want want; + want.SetAction(eventName); + CommonEventData commonData; + commonData.SetWant(want); + commonData.SetCode(code); + commonData.SetData(data); + return CommonEventManager::PublishCommonEvent(commonData); +} + +void STPageAbilityEvent::SubscribeEvent(std::vector eventList, const std::shared_ptr &ability) +{ + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo, ability); + CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +void STPageAbilityEvent::UnsubscribeEvent() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} + +std::string STPageAbilityEvent::GetEventDate(const std::string &stateCallbackCount) +{ + return this->componentType_ + stateCallbackCount; +} + +std::string STPageAbilityEvent::GetCallBackPath(const std::string &callBackPath) +{ + this->callBackPath_ += callBackPath; + return this->callBackPath_; +} + +std::string STPageAbilityEvent::GetAbilityStatus(const std::string &abilityStatus) +{ + this->abilityStatus_ += abilityStatus; + return this->abilityStatus_; +} + +int STPageAbilityEvent::GetOnStartCount() +{ + onStartCount_++; + return onStartCount_; +} + +int STPageAbilityEvent::GetOnStopCount() +{ + onStopCount_++; + return onStopCount_; +} + +int STPageAbilityEvent::GetOnActiveCount() +{ + onActiveCount_++; + return onActiveCount_; +} + +int STPageAbilityEvent::GetOnInactiveCount() +{ + onInactiveCount_++; + return onInactiveCount_; +} + +int STPageAbilityEvent::GetOnBackgroundCount() +{ + onBackgroundCount_++; + return onBackgroundCount_; +} + +int STPageAbilityEvent::GetOnForegroundCount() +{ + onForegroundCount_++; + return onForegroundCount_; +} + +int STPageAbilityEvent::GetOnNewWantCount() +{ + onNewWantCount_++; + return onNewWantCount_; +} + +void STPageAbilityEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("DataTestPageAEventSubscriber::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("DataTestPageAEventSubscriber::OnReceiveEvent:data=%{public}s", data.GetData().c_str()); + APP_LOGI("DataTestPageAEventSubscriber::OnReceiveEvent:code=%{public}d", data.GetCode()); + auto eventName = data.GetWant().GetAction(); + if (eventName.compare("requ_page_ability_terminate") == 0) { + std::string target = data.GetData(); + if (target.compare(this->ability_->GetAbilityName()) == 0) { + this->ability_->TerminateAbility(); + } + } +} + +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/util/include/accessibility_errorcode.h b/util/include/accessibility_errorcode.h new file mode 100644 index 00000000..c100dfaf --- /dev/null +++ b/util/include/accessibility_errorcode.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef ACCESSIBILITY_ERRORCODE_H +#define ACCESSIBILITY_ERRORCODE_H + +namespace OHOS { +namespace Accessibility { + +/* Accessibility errcode defines */ +enum ErrCode { + NO_ERROR = 0, + ERR_INVALID_STATE, + ERR_INVALID_VALUE, + ERROR, + +}; +} // namespace Accessibility +} // namespace OHOS + +#endif // ACCESSIBILITY_ERRORCODE_H \ No newline at end of file diff --git a/util/include/json_utils.h b/util/include/json_utils.h new file mode 100644 index 00000000..0605fc7f --- /dev/null +++ b/util/include/json_utils.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef JSON_UTILS_H +#define JSON_UTILS_H + +#include +#include +#include "nlohmann/json.hpp" + +namespace OHOS { +namespace Accessibility { + +const static std::string AccessibleAbility_JSON_FILE_PATH = "/system/app/dummy_accessibility_ability_config.json"; +const static std::string AccessibleAbility_JSON_KEY_ACCESSIBILITY_EVENT_TYPES = "accessibilityEventTypes"; +const static std::string AccessibleAbility_JSON_KEY_TARGET_BUNDLE_NAMES = "targetBundleNames"; +const static std::string AccessibleAbility_JSON_KEY_ACCESSIBILITY_ABILITY_TYPES = "accessibilityAbilityTypes"; +const static std::string AccessibleAbility_JSON_KEY_NOTIFICATION_TIMEOUT = "notificationTimeout"; +const static std::string AccessibleAbility_JSON_KEY_UI_NONINTERACTIVE_TIMEOUT = "uiNoninteractiveTimeout"; +const static std::string AccessibleAbility_JSON_KEY_UI_INTERACTIVE_TIMEOUT = "uiInteractiveTimeout"; +const static std::string AccessibleAbility_JSON_KEY_ACCESSIBILITY_CAPABILITIES = "accessibilityCapabilities"; +const static std::string AccessibleAbility_JSON_KEY_DESCRIPTION = "description"; +const static std::string AccessibleAbility_JSON_KEY_SETTINGS_ABILITY = "settingsAbility"; + +// The json value of event types +const static std::string EVENT_TYPES_JSON_VALUE_CLICK = "click"; +const static std::string EVENT_TYPES_JSON_VALUE_LONG_CLICK = "longClick"; +const static std::string EVENT_TYPES_JSON_VALUE_SELECT = "select"; +const static std::string EVENT_TYPES_JSON_VALUE_FOCUS = "focus"; +const static std::string EVENT_TYPES_JSON_VALUE_TEXT_UPDATE = "textUpdate"; +const static std::string EVENT_TYPES_JSON_VALUE_PAGE_STATE_UPDATE = "pageStateUpdate"; +const static std::string EVENT_TYPES_JSON_VALUE_NOTIFICATION_UPDATE = "notificationUpdate"; +const static std::string EVENT_TYPES_JSON_VALUE_HOVER_ENTER = "hoverEnter"; +const static std::string EVENT_TYPES_JSON_VALUE_HOVER_EXIT = "hoverExit"; +const static std::string EVENT_TYPES_JSON_VALUE_TOUCH_GUIDE_BEGIN = "touchGuideBegin"; +const static std::string EVENT_TYPES_JSON_VALUE_TOUCH_GUIDE_END = "touchGuideEnd"; +const static std::string EVENT_TYPES_JSON_VALUE_PAGE_CONTENT_UPDATE = "pageContentUpdate"; +const static std::string EVENT_TYPES_JSON_VALUE_SCROLL = "scroll"; +const static std::string EVENT_TYPES_JSON_VALUE_TEXT_SELECTION_UPDATE = "textSelectionUpdate"; +const static std::string EVENT_TYPES_JSON_VALUE_PUBLIC_NOTICE = "publicNotice"; +const static std::string EVENT_TYPES_JSON_VALUE_ACCESSIBILITY_FOCUS = "accessibilityFocus"; +const static std::string EVENT_TYPES_JSON_VALUE_ACCESSIBILITY_FOCUS_CLEAR = "accessibilityFocusClear"; +const static std::string EVENT_TYPES_JSON_VALUE_TEXT_MOVE_UNIT = "textMoveUnit"; +const static std::string EVENT_TYPES_JSON_VALUE_TOUCH_GUIDE_GESTURE_BEGIN = "touchGuideGestureBegin"; +const static std::string EVENT_TYPES_JSON_VALUE_TOUCH_GUIDE_GESTURE_END = "touchGuideGestureEnd"; +const static std::string EVENT_TYPES_JSON_VALUE_TOUCH_BEGIN = "touchBegin"; +const static std::string EVENT_TYPES_JSON_VALUE_TOUCH_END = "touchEnd"; +const static std::string EVENT_TYPES_JSON_VALUE_WINDOW_UPDATE = "windowUpdate"; +const static std::string EVENT_TYPES_JSON_VALUE_ALL = "all"; + +// The json value of accessibilityAbility type +const static std::string ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_SPOKEN = "spoken"; +const static std::string ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_HAPIC = "haptic"; +const static std::string ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_AUDIBLE = "audible"; +const static std::string ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_VISUAL = "visual"; +const static std::string ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_GENERIC = "generic"; +const static std::string ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_ALL = "all"; + +// The json value of capabilities +const static std::string CAPABILITIES_JSON_VALUE_RETRIEVE = "retrieve"; +const static std::string CAPABILITIES_JSON_VALUE_TOUCH_GUIDE = "touchGuide"; +const static std::string CAPABILITIES_JSON_VALUE_KEY_EVENT_OBSERVER = "keyEventObserver"; +const static std::string CAPABILITIES_JSON_VALUE_ZOOM = "zoom"; +const static std::string CAPABILITIES_JSON_VALUE_GESTURE = "gesture"; + +class JsonUtils { +public: + static bool GetJsonObjFromJson(nlohmann::json& jsonObj, const std::string& jsonPath); + static bool GetStringFromJson(const nlohmann::json& json, const std::string& key, std::string& value); + static bool GetIntFromJson(const nlohmann::json& json, const std::string& key, int& value); + static bool GetStringVecFromJson(const nlohmann::json& json, const std::string& key, + std::vector& value); + static bool ParseObjVecFromJson(const nlohmann::json& json, const std::string& key, + std::vector& value); +}; + +class PraseVecUtils { +public: + static void ParseEventTypesFromVec(const std::vector& events, uint32_t& eventTypes); + static void ParseAbilityTypesFromVec(const std::vector& abilities, uint32_t& abilityTypes); + static void ParseCapabilitiesFromVec(const std::vector& capabilities, uint32_t& capabilitiesValue); +}; + +} // namespace Accessibility +} // namespace OHOS + +#endif // JSON_UTILS_H \ No newline at end of file diff --git a/util/include/parcel_util.h b/util/include/parcel_util.h new file mode 100644 index 00000000..5195e739 --- /dev/null +++ b/util/include/parcel_util.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef PACEL_UTIL_H +#define PACEL_UTIL_H + +#include +#include +#include "parcel.h" + +namespace OHOS { +namespace Accessibility{ + +#define READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(type, parcel, data) \ + do \ + { \ + if (!(parcel).Read##type(data)) \ + { \ + return false; \ + } \ + } while (0) + +#define WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(type, parcel, data) \ + do \ + { \ + if (!(parcel).Write##type(data)) \ + { \ + return false; \ + } \ + } while (0) + +template +std::vector TranslateListToVector(const std::list &originList) +{ + int len = originList.size(); + std::vector destVector(len); + std::copy(originList.begin(), originList.end(), destVector.begin()); + + return destVector; +} + +template +std::list TranslateVectorToList(const std::vector &originVector) +{ + int len = originVector.length(); + std::list destList(len); + std::copy(originVector.begin(), originVector.end(), destList.begin()); + + return destList; +} + +} // namespace Accessibility +} // namespace OHOS + +#endif // PACEL_UTIL_H \ No newline at end of file diff --git a/util/src/json_utils.cpp b/util/src/json_utils.cpp new file mode 100644 index 00000000..5fa9f72c --- /dev/null +++ b/util/src/json_utils.cpp @@ -0,0 +1,276 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include +#include "json_utils.h" +#include "hilog_wrapper.h" +#include "accessibility_event_info.h" +#include "accessibility_ability_info.h" + +using namespace std; + +namespace OHOS { +namespace Accessibility { + +bool JsonUtils::GetJsonObjFromJson(nlohmann::json &jsonObj, const std::string &jsonPath) +{ + HILOG_DEBUG("%{public}s start.", __func__); + std::ifstream jsonFileStream; + jsonFileStream.open(jsonPath.c_str(), std::ios::in); + if (!jsonFileStream.is_open()) { + HILOG_ERROR("Open json file failed."); + return false; + } + + std::ostringstream buf; + char ch; + while (buf && jsonFileStream.get(ch)) { + buf.put(ch); + } + jsonFileStream.close(); + + jsonObj = nlohmann::json::parse(buf.str(), nullptr, false); + if (!jsonObj.is_structured()) { + HILOG_ERROR("Parse json file into jsonObj failed."); + return false; + } + return true; +} + +bool JsonUtils::GetStringFromJson(const nlohmann::json &json, const std::string &key, std::string &value) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!json.is_object()) { + HILOG_ERROR("json is not object."); + return false; + } + if (json.find(key) != json.end() && json.at(key).is_string()) { + HILOG_DEBUG("Find key[%{public}s] successful.", key.c_str()); + value = json.at(key).get(); + } + return true; +} + +bool JsonUtils::GetIntFromJson(const nlohmann::json &json, const std::string &key, int &value) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!json.is_object()) { + HILOG_ERROR("json is not object."); + return false; + } + if (json.find(key) != json.end() && json.at(key).is_number()) { + HILOG_DEBUG("Find key[%{public}s] successful.", key.c_str()); + value = json.at(key).get(); + } + return true; +} + +bool JsonUtils::GetStringVecFromJson(const nlohmann::json &json, const std::string &key, + std::vector &value) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!json.is_object()) { + HILOG_ERROR("json is not object."); + return false; + } + if (json.find(key) != json.end() && json.at(key).is_array()) { + HILOG_DEBUG("Find key[%{public}s] successful.", key.c_str()); + value = json.at(key).get>(); + } + return true; +} + +bool JsonUtils::ParseObjVecFromJson(const nlohmann::json &json, const std::string &key, + std::vector &value) +{ + HILOG_DEBUG("%{public}s start.", __func__); + if (!json.is_object()) { + HILOG_ERROR("json is not object."); + return false; + } + if (json.find(key) != json.end() && json.at(key).is_array()) { + HILOG_DEBUG("Find key[%{public}s] successful.", key.c_str()); + value = json.at(key).get>(); + } + return true; +} + +void PraseVecUtils::ParseEventTypesFromVec(const vector& events, uint32_t& eventTypes) +{ + HILOG_DEBUG("%{public}s start.", __func__); + eventTypes = EventType::TYPE_VIEW_INVALID; + + for (auto it = events.begin(); it != events.end(); it++) { + if (*it == EVENT_TYPES_JSON_VALUE_CLICK) { + eventTypes |= EventType::TYPE_VIEW_CLICKED_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_LONG_CLICK) { + eventTypes |= EventType::TYPE_VIEW_LONG_CLICKED_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_SELECT) { + eventTypes |= EventType::TYPE_VIEW_SELECTED_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_FOCUS) { + eventTypes |= EventType::TYPE_VIEW_FOCUSED_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_TEXT_UPDATE) { + eventTypes |= EventType::TYPE_VIEW_TEXT_UPDATE_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_PAGE_STATE_UPDATE) { + eventTypes |= EventType::TYPE_PAGE_STATE_UPDATE; + } + + if (*it == EVENT_TYPES_JSON_VALUE_NOTIFICATION_UPDATE) { + eventTypes |= EventType::TYPE_NOTIFICATION_UPDATE_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_HOVER_ENTER) { + eventTypes |= EventType::TYPE_VIEW_HOVER_ENTER_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_HOVER_EXIT) { + eventTypes |= EventType::TYPE_VIEW_HOVER_EXIT_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_TOUCH_GUIDE_BEGIN) { + eventTypes |= EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN; + } + + if (*it == EVENT_TYPES_JSON_VALUE_TOUCH_GUIDE_END) { + eventTypes |= EventType::TYPE_TOUCH_GUIDE_GESTURE_END; + } + + if (*it == EVENT_TYPES_JSON_VALUE_PAGE_CONTENT_UPDATE) { + eventTypes |= EventType::TYPE_PAGE_CONTENT_UPDATE; + } + + if (*it == EVENT_TYPES_JSON_VALUE_SCROLL) { + eventTypes |= EventType::TYPE_VIEW_SCROLLED_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_TEXT_SELECTION_UPDATE) { + eventTypes |= EventType::TYPE_VIEW_TEXT_SELECTION_UPDATE_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_PUBLIC_NOTICE) { + eventTypes |= EventType::TYPE_PUBLIC_NOTICE_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_ACCESSIBILITY_FOCUS) { + eventTypes |= EventType::TYPE_VIEW_ACCESSIBILITY_FOCUSED_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_ACCESSIBILITY_FOCUS_CLEAR) { + eventTypes |= EventType::TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_TEXT_MOVE_UNIT) { + eventTypes |= EventType::TYPE_VIEW_TEXT_MOVE_UNIT_EVENT; + } + + if (*it == EVENT_TYPES_JSON_VALUE_TOUCH_GUIDE_GESTURE_BEGIN) { + eventTypes |= EventType::TYPE_TOUCH_GUIDE_BEGIN; + } + + if (*it == EVENT_TYPES_JSON_VALUE_TOUCH_GUIDE_GESTURE_END) { + eventTypes |= EventType::TYPE_TOUCH_GUIDE_END; + } + + if (*it == EVENT_TYPES_JSON_VALUE_TOUCH_BEGIN) { + eventTypes |= EventType::TYPE_TOUCH_BEGIN; + } + + if (*it == EVENT_TYPES_JSON_VALUE_TOUCH_END) { + eventTypes |= EventType::TYPE_TOUCH_END; + } + + if (*it == EVENT_TYPES_JSON_VALUE_WINDOW_UPDATE) { + eventTypes |= EventType::TYPE_WINDOW_UPDATE; + } + + if (*it == EVENT_TYPES_JSON_VALUE_ALL) { + eventTypes |= EventType::TYPES_ALL_MASK; + } + } +} + +void PraseVecUtils::ParseAbilityTypesFromVec(const vector& abilities, uint32_t& abilityTypes) +{ + HILOG_DEBUG("%{public}s start.", __func__); + abilityTypes = 0; + + for (auto it = abilities.begin(); it != abilities.end(); it++) { + if (*it == ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_SPOKEN) { + abilityTypes |= AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_SPOKEN; + } + + if (*it == ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_HAPIC) { + abilityTypes |= AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_HAPTIC; + } + + if (*it == ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_AUDIBLE) { + abilityTypes |= AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_AUDIBLE; + } + + if (*it == ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_VISUAL) { + abilityTypes |= AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_VISUAL; + } + + if (*it == ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_GENERIC) { + abilityTypes |= AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_GENERIC; + } + + if (*it == ACCESSIBILITY_ABILITY_TYPES_JSON_VALUE_ALL) { + abilityTypes |= AccessibilityAbilityTypes::ACCESSIBILITY_ABILITY_TYPE_ALL; + } + } +} + +void PraseVecUtils::ParseCapabilitiesFromVec(const vector& capabilities, uint32_t& capabilitiesValue) +{ + HILOG_DEBUG("%{public}s start.", __func__); + capabilitiesValue = 0; + + for (auto it = capabilities.begin(); it != capabilities.end(); it++) { + if (*it == CAPABILITIES_JSON_VALUE_RETRIEVE) { + capabilitiesValue |= Capability::CAPABILITY_RETRIEVE; + } + + if (*it == CAPABILITIES_JSON_VALUE_TOUCH_GUIDE) { + capabilitiesValue |= Capability::CAPABILITY_TOUCH_GUIDE; + } + + if (*it == CAPABILITIES_JSON_VALUE_KEY_EVENT_OBSERVER) { + capabilitiesValue |= Capability::CAPABILITY_KEY_EVENT_OBSERVER; + } + + if (*it == CAPABILITIES_JSON_VALUE_ZOOM) { + capabilitiesValue |= Capability::CAPABILITY_ZOOM; + } + + if (*it == CAPABILITIES_JSON_VALUE_GESTURE) { + capabilitiesValue |= Capability::CAPABILITY_GESTURE; + } + } +} + +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file