• 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 #include "accessible_ability_client_proxy.h"
17 #include "accessibility_errorcode.h"
18 #include "parcel.h"
19 
20 namespace OHOS {
21 namespace Accessibility {
AccessibleAbilityClientProxy(const sptr<IRemoteObject> & object)22 AccessibleAbilityClientProxy::AccessibleAbilityClientProxy(const sptr<IRemoteObject> &object)
23     : IRemoteProxy<IAccessibleAbilityClient>(object)
24 {
25 }
26 
WriteInterfaceToken(MessageParcel & data)27 bool AccessibleAbilityClientProxy::WriteInterfaceToken(MessageParcel &data)
28 {
29     HILOG_DEBUG("start.");
30     if (!data.WriteInterfaceToken(AccessibleAbilityClientProxy::GetDescriptor())) {
31         HILOG_ERROR("write interface token failed");
32         return false;
33     }
34     return true;
35 }
36 
Init(const sptr<IAccessibleAbilityChannel> & channel,const int channelId)37 void AccessibleAbilityClientProxy::Init(const sptr<IAccessibleAbilityChannel> &channel, const int channelId)
38 {
39     int error = NO_ERROR;
40     MessageParcel data;
41     MessageParcel reply;
42     MessageOption option(MessageOption::TF_ASYNC);
43 
44     HILOG_DEBUG("start.");
45 
46     if (!WriteInterfaceToken(data)) {
47         return;
48     }
49     if (!channel) {
50         HILOG_ERROR("channel is null.");
51         return;
52     }
53     if (!data.WriteRemoteObject(channel->AsObject())) {
54         HILOG_ERROR("fail, channel write parcelable error");
55         return;
56     }
57 
58     if (!data.WriteInt32(channelId)) {
59         HILOG_ERROR("fail, channelId write int32 error");
60         return;
61     }
62 
63     error = Remote()->SendRequest(static_cast<uint32_t>(IAccessibleAbilityClient::Message::INIT), data, reply, option);
64     if (error != NO_ERROR) {
65         HILOG_ERROR("Init fail, error: %d", error);
66     }
67 }
68 
Disconnect(const int channelId)69 void AccessibleAbilityClientProxy::Disconnect(const int channelId)
70 {
71     int error = NO_ERROR;
72     MessageParcel data;
73     MessageParcel reply;
74     MessageOption option(MessageOption::TF_ASYNC);
75 
76     HILOG_DEBUG("start.");
77 
78     if (!WriteInterfaceToken(data)) {
79         return;
80     }
81 
82     if (!data.WriteInt32(channelId)) {
83         HILOG_ERROR("fail, channelId write int32 error");
84         return;
85     }
86 
87     error = Remote()->SendRequest(static_cast<uint32_t>(IAccessibleAbilityClient::Message::DISCONNECT),
88         data, reply, option);
89     if (error != NO_ERROR) {
90         HILOG_ERROR("Disconnect fail, error: %d", error);
91     }
92 }
93 
OnAccessibilityEvent(const AccessibilityEventInfo & eventInfo)94 void AccessibleAbilityClientProxy::OnAccessibilityEvent(const AccessibilityEventInfo &eventInfo)
95 {
96     int error = NO_ERROR;
97     MessageParcel data;
98     MessageParcel reply;
99     MessageOption option(MessageOption::TF_ASYNC);
100 
101     HILOG_DEBUG("start.");
102 
103     if (!WriteInterfaceToken(data)) {
104         return;
105     }
106     if (!data.WriteParcelable(&eventInfo)) {
107         HILOG_ERROR("fail, eventInfo write parcelable error");
108         return;
109     }
110     error = Remote()->SendRequest(static_cast<uint32_t>(IAccessibleAbilityClient::Message::ON_ACCESSIBILITY_EVENT),
111         data, reply, option);
112     if (error != NO_ERROR) {
113         HILOG_ERROR("OnAccessibilityEvent fail, error: %d", error);
114     }
115 }
116 
OnKeyPressEvent(const MMI::KeyEvent & keyEvent,const int sequence)117 void AccessibleAbilityClientProxy::OnKeyPressEvent(const MMI::KeyEvent &keyEvent, const int sequence)
118 {
119     int error = NO_ERROR;
120     MessageParcel data;
121     MessageParcel reply;
122     MessageOption option(MessageOption::TF_ASYNC);
123 
124     HILOG_DEBUG("start.");
125 
126     if (!WriteInterfaceToken(data)) {
127         return;
128     }
129     if (!data.WriteInt32(sequence)) {
130         HILOG_ERROR("fail, sequence write int32 error");
131         return;
132     }
133 
134     if (!keyEvent.WriteToParcel(data)) {
135         HILOG_ERROR("fail, keyEvent WriteToParcel error");
136         return;
137     }
138 
139     error = Remote()->SendRequest(static_cast<uint32_t>(IAccessibleAbilityClient::Message::ON_KEY_PRESS_EVENT),
140         data, reply, option);
141     if (error != NO_ERROR) {
142         HILOG_ERROR("OnKeyPressEvent fail, error: %d", error);
143     }
144 }
145 
OnDisplayResized(const int displayId,const Rect & rect,const float scale,const float centerX,const float centerY)146 void AccessibleAbilityClientProxy::OnDisplayResized(const int displayId, const Rect &rect, const float scale,
147     const float centerX, const float centerY)
148 {
149     int error = NO_ERROR;
150     MessageParcel data;
151     MessageParcel reply;
152     MessageOption option(MessageOption::TF_ASYNC);
153 
154     HILOG_DEBUG("start.");
155 
156     if (!WriteInterfaceToken(data)) {
157         return;
158     }
159     if (!data.WriteInt32(displayId)) {
160         HILOG_ERROR("fail, displayId write int32 error");
161         return;
162     }
163     if (!data.WriteParcelable(&rect)) {
164         HILOG_ERROR("fail, rect write parcelable error");
165         return;
166     }
167     if (!data.WriteFloat(scale)) {
168         HILOG_ERROR("fail, scale write float error");
169         return;
170     }
171     if (!data.WriteFloat(centerX)) {
172         HILOG_ERROR("fail, centerX write float error");
173         return;
174     }
175     if (!data.WriteFloat(centerY)) {
176         HILOG_ERROR("fail, centerY write float error");
177         return;
178     }
179 
180     error = Remote()->SendRequest(static_cast<uint32_t>(IAccessibleAbilityClient::Message::ON_DISPALYRESIZE_CHANGED),
181         data, reply, option);
182     if (error != NO_ERROR) {
183         HILOG_ERROR("OnDisplayResized fail, error: %d", error);
184     }
185 }
186 
OnGestureSimulateResult(const int sequence,const bool completedSuccessfully)187 void AccessibleAbilityClientProxy::OnGestureSimulateResult(const int sequence, const bool completedSuccessfully)
188 {
189     int error = NO_ERROR;
190     MessageParcel data;
191     MessageParcel reply;
192     MessageOption option(MessageOption::TF_ASYNC);
193 
194     HILOG_DEBUG("start.");
195 
196     if (!WriteInterfaceToken(data)) {
197         return;
198     }
199     if (!data.WriteInt32(sequence)) {
200         HILOG_ERROR("fail, sequence write int32 error");
201         return;
202     }
203     if (!data.WriteBool(completedSuccessfully)) {
204         HILOG_ERROR("fail, completedSuccessfully write bool error");
205         return;
206     }
207     error = Remote()->SendRequest(static_cast<uint32_t>(IAccessibleAbilityClient::Message::ON_GESTURE_SIMULATE_RESULT),
208         data, reply, option);
209     if (error != NO_ERROR) {
210         HILOG_ERROR("OnGestureSimulateResult fail, error: %d", error);
211     }
212 }
213 } // namespace Accessibility
214 } // namespace OHOS