• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ACCESSIBLE_ABILITY_CLIENT_STUB_IMPL_H
17 #define ACCESSIBLE_ABILITY_CLIENT_STUB_IMPL_H
18 
19 #include <memory>
20 #include "accessible_ability_client_stub.h"
21 #include "accessibility_extension.h"
22 #include "accessibility_operator.h"
23 #include "accessibility_ui_test_ability_listener.h"
24 #include "hilog_wrapper.h"
25 #include "refbase.h"
26 
27 namespace OHOS {
28 namespace Accessibility {
29 class AccessibleAbilityClientStubImpl : public AccessibleAbilityClientStub {
30 public:
31     AccessibleAbilityClientStubImpl() = default;
32     ~AccessibleAbilityClientStubImpl() = default;
33 
34     static const uint32_t INVALID_CHANNEL_ID = 0xFFFFFFFF;
35 
36     /**
37      * @brief Register listener if you want to receive notification.
38      * @param listener The listener used to receive notification.
39      * @return
40      */
41     void RegisterListenerImpl(const std::shared_ptr<AccessibilityExtension> &listener);
42 
43     void SetUITestEnabled();
44 
45     bool RegisterUITestAbilityListener(const std::shared_ptr<IAccessibleUITestAbilityListener> &listener);
46 
47     /**
48      * @brief Init accessible ability.
49      * @param channel The object of IAccessibleAbilityChannel.
50      * @param channelId The id of channel.
51      * @return
52      */
53     void Init(const sptr<IAccessibleAbilityChannel> &channel, const int channelId) override;
54 
55     /**
56      * @brief Disconnect accessible ability.
57      * @param channelId The id of channel.
58      * @return
59      */
60     void Disconnect(const int channelId) override;
61 
62     /**
63      * @brief Called when an accessibility event occurs.
64      * @param eventInfo The information of accessible event.
65      * @return
66      */
67     void OnAccessibilityEvent(const AccessibilityEventInfo &eventInfo) override;
68 
69     /**
70      * @brief Called when a key event occurs.
71      * @param keyEvent Indicates the key event to send.
72      * @param sequence The sequence of the key event.
73      * @return
74      */
75     void OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int sequence) override;
76 
77     /**
78      * @brief Called when the rectangle, scale, or center coordinate for performing the resizing operations is changed.
79      * @param displayId The id of display.
80      * @param rect Indicates the rectangle for resizing the display.
81      * @param scale Indicates the scale for resizing the display.
82      * @param centerX Indicates the X coordinate of the center for resizing the display.
83      * @param centerY Indicates the Y coordinate of the center for resizing the display.
84      * @return
85      */
86     void OnDisplayResized(const int displayId, const Rect &rect, const float scale, const float centerX,
87         const float centerY) override;
88 
89     /**
90      * @brief Called when need to notify the result of simulation gesture.
91      * @param sequence The sequence of gesture.
92      * @param completedSuccessfully The result of gesture completion.
93      * @return
94      */
95     void OnGestureSimulateResult(const int sequence, const bool completedSuccessfully) override;
96 
97 private:
98     class AccessibleAbilityDeathRecipient final : public IRemoteObject::DeathRecipient {
99     public:
AccessibleAbilityDeathRecipient(uint32_t & channelId,sptr<IAccessibleAbilityChannel> & channel)100         AccessibleAbilityDeathRecipient(uint32_t& channelId, sptr<IAccessibleAbilityChannel>& channel)
101             : recipientChannelId_(channelId), recipientchannel_(channel) {};
102         ~AccessibleAbilityDeathRecipient() = default;
103         DISALLOW_COPY_AND_MOVE(AccessibleAbilityDeathRecipient);
104 
105         void OnRemoteDied(const wptr<IRemoteObject>& remote);
106 
107         uint32_t& recipientChannelId_;
108         sptr<IAccessibleAbilityChannel>& recipientchannel_;
109     };
110 
111     void InitInner(const sptr<IAccessibleAbilityChannel> &channel, const int channelId);
112 
113     void OnAccessibilityEventInner(const AccessibilityEventInfo &eventInfo);
114 
115     void OnKeyPressEventInner(const MMI::KeyEvent &keyEvent, const int sequence);
116 
117     void OnDisplayResizedInner(const int displayId, const Rect &rect, const float scale, const float centerX,
118         const float centerY);
119 
120     void OnGestureSimulateResultInner(const int sequence, const bool completedSuccessfully);
121 
122     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
123     sptr<IAccessibleAbilityChannel> channel_ = nullptr;
124     std::shared_ptr<AccessibilityExtension> listener_ = nullptr;
125     std::shared_ptr<IAccessibleUITestAbilityListener> uiTestListener_ = nullptr;
126     uint32_t channelId_ = INVALID_CHANNEL_ID;
127     bool uiTestEnabled_ = false;
128 };
129 } // namespace Accessibility
130 } // namespace OHOS
131 #endif // ACCESSIBLE_ABILITY_CLIENT_STUB_IMPL_H