1 /*
2 * Copyright (C) 2021 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 "input_data_channel_stub.h"
17
18 #include "ffrt_inner.h"
19 #include "global.h"
20 #include "input_method_controller.h"
21 #include "ipc_object_stub.h"
22 #include "ipc_skeleton.h"
23 #include "ipc_types.h"
24 #include "itypes_util.h"
25 #include "message.h"
26 namespace OHOS {
27 namespace MiscServices {
InputDataChannelStub()28 InputDataChannelStub::InputDataChannelStub()
29 {
30 }
31
~InputDataChannelStub()32 InputDataChannelStub::~InputDataChannelStub()
33 {
34 }
35
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int32_t InputDataChannelStub::OnRemoteRequest(
37 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
38 {
39 IMSA_HILOGD("InputDataChannelStub, code: %{public}u, callingPid: %{public}d, callingUid: %{public}d", code,
40 IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
41 auto descriptorToken = data.ReadInterfaceToken();
42 if (descriptorToken != IInputDataChannel::GetDescriptor()) {
43 IMSA_HILOGE("InputDataChannelStub descriptor error");
44 return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
45 }
46 if (code >= FIRST_CALL_TRANSACTION && code < static_cast<uint32_t>(DATA_CHANNEL_CMD_LAST)) {
47 return (this->*HANDLERS.at(code))(data, reply);
48 } else {
49 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51 }
52
InsertTextOnRemote(MessageParcel & data,MessageParcel & reply)53 int32_t InputDataChannelStub::InsertTextOnRemote(MessageParcel &data, MessageParcel &reply)
54 {
55 std::u16string text;
56 if (!ITypesUtil::Unmarshal(data, text)) {
57 IMSA_HILOGE("failed to read message parcel");
58 return ErrorCode::ERROR_EX_PARCELABLE;
59 }
60 return reply.WriteInt32(InsertText(text)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
61 }
62
DeleteForwardOnRemote(MessageParcel & data,MessageParcel & reply)63 int32_t InputDataChannelStub::DeleteForwardOnRemote(MessageParcel &data, MessageParcel &reply)
64 {
65 int32_t length = 0;
66 if (!ITypesUtil::Unmarshal(data, length)) {
67 IMSA_HILOGE("failed to read message parcel");
68 return ErrorCode::ERROR_EX_PARCELABLE;
69 }
70 return reply.WriteInt32(DeleteForward(length)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
71 }
72
DeleteBackwardOnRemote(MessageParcel & data,MessageParcel & reply)73 int32_t InputDataChannelStub::DeleteBackwardOnRemote(MessageParcel &data, MessageParcel &reply)
74 {
75 int32_t length = 0;
76 if (!ITypesUtil::Unmarshal(data, length)) {
77 IMSA_HILOGE("failed to read message parcel");
78 return ErrorCode::ERROR_EX_PARCELABLE;
79 }
80 return reply.WriteInt32(DeleteBackward(length)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
81 }
82
GetTextBeforeCursorOnRemote(MessageParcel & data,MessageParcel & reply)83 int32_t InputDataChannelStub::GetTextBeforeCursorOnRemote(MessageParcel &data, MessageParcel &reply)
84 {
85 int32_t length = 0;
86 if (!ITypesUtil::Unmarshal(data, length)) {
87 IMSA_HILOGE("failed to unmarshal");
88 return ErrorCode::ERROR_EX_PARCELABLE;
89 }
90 std::u16string text;
91 return ITypesUtil::Marshal(reply, GetTextBeforeCursor(length, text), text) ? ErrorCode::NO_ERROR
92 : ErrorCode::ERROR_EX_PARCELABLE;
93 }
94
GetTextAfterCursorOnRemote(MessageParcel & data,MessageParcel & reply)95 int32_t InputDataChannelStub::GetTextAfterCursorOnRemote(MessageParcel &data, MessageParcel &reply)
96 {
97 int32_t length = 0;
98 if (!ITypesUtil::Unmarshal(data, length)) {
99 IMSA_HILOGE("failed to unmarshal");
100 return ErrorCode::ERROR_EX_PARCELABLE;
101 }
102 std::u16string text;
103 return ITypesUtil::Marshal(reply, GetTextAfterCursor(length, text), text) ? ErrorCode::NO_ERROR
104 : ErrorCode::ERROR_EX_PARCELABLE;
105 }
106
GetTextConfigOnRemote(MessageParcel & data,MessageParcel & reply)107 int32_t InputDataChannelStub::GetTextConfigOnRemote(MessageParcel &data, MessageParcel &reply)
108 {
109 TextTotalConfig config;
110 return ITypesUtil::Marshal(reply, GetTextConfig(config), config) ? ErrorCode::NO_ERROR
111 : ErrorCode::ERROR_EX_PARCELABLE;
112 }
113
SendKeyboardStatusOnRemote(MessageParcel & data,MessageParcel & reply)114 int32_t InputDataChannelStub::SendKeyboardStatusOnRemote(MessageParcel &data, MessageParcel &reply)
115 {
116 int32_t status = -1;
117 if (!ITypesUtil::Unmarshal(data, status)) {
118 IMSA_HILOGE("failed to read message parcel");
119 return ErrorCode::ERROR_EX_PARCELABLE;
120 }
121 SendKeyboardStatus(static_cast<KeyboardStatus>(status));
122 return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
123 }
124
SendFunctionKeyOnRemote(MessageParcel & data,MessageParcel & reply)125 int32_t InputDataChannelStub::SendFunctionKeyOnRemote(MessageParcel &data, MessageParcel &reply)
126 {
127 int32_t functionKey = 0;
128 if (!ITypesUtil::Unmarshal(data, functionKey)) {
129 IMSA_HILOGE("failed to read message parcel");
130 return ErrorCode::ERROR_EX_PARCELABLE;
131 }
132 return reply.WriteInt32(SendFunctionKey(functionKey)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
133 }
134
MoveCursorOnRemote(MessageParcel & data,MessageParcel & reply)135 int32_t InputDataChannelStub::MoveCursorOnRemote(MessageParcel &data, MessageParcel &reply)
136 {
137 int32_t direction = 0;
138 if (!ITypesUtil::Unmarshal(data, direction)) {
139 IMSA_HILOGE("failed to read message parcel");
140 return ErrorCode::ERROR_EX_PARCELABLE;
141 }
142 return reply.WriteInt32(MoveCursor(direction)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
143 }
144
GetEnterKeyTypeOnRemote(MessageParcel & data,MessageParcel & reply)145 int32_t InputDataChannelStub::GetEnterKeyTypeOnRemote(MessageParcel &data, MessageParcel &reply)
146 {
147 int32_t type = 0;
148 return ITypesUtil::Marshal(reply, GetEnterKeyType(type), type) ? ErrorCode::NO_ERROR
149 : ErrorCode::ERROR_EX_PARCELABLE;
150 }
151
GetInputPatternOnRemote(MessageParcel & data,MessageParcel & reply)152 int32_t InputDataChannelStub::GetInputPatternOnRemote(MessageParcel &data, MessageParcel &reply)
153 {
154 int32_t pattern = 0;
155 return ITypesUtil::Marshal(reply, GetInputPattern(pattern), pattern) ? ErrorCode::NO_ERROR
156 : ErrorCode::ERROR_EX_PARCELABLE;
157 }
158
SelectByRangeOnRemote(MessageParcel & data,MessageParcel & reply)159 int32_t InputDataChannelStub::SelectByRangeOnRemote(MessageParcel &data, MessageParcel &reply)
160 {
161 int32_t start = 0;
162 int32_t end = 0;
163 if (!ITypesUtil::Unmarshal(data, start, end)) {
164 IMSA_HILOGE("failed to read message parcel");
165 return ErrorCode::ERROR_EX_PARCELABLE;
166 }
167 return reply.WriteInt32(SelectByRange(start, end)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
168 }
169
SelectByMovementOnRemote(MessageParcel & data,MessageParcel & reply)170 int32_t InputDataChannelStub::SelectByMovementOnRemote(MessageParcel &data, MessageParcel &reply)
171 {
172 int32_t direction = 0;
173 int32_t skip = 0;
174 if (!ITypesUtil::Unmarshal(data, direction, skip)) {
175 IMSA_HILOGE("failed to read message parcel");
176 return ErrorCode::ERROR_EX_PARCELABLE;
177 }
178 return reply.WriteInt32(SelectByMovement(direction, skip)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
179 }
180
HandleExtendActionOnRemote(MessageParcel & data,MessageParcel & reply)181 int32_t InputDataChannelStub::HandleExtendActionOnRemote(MessageParcel &data, MessageParcel &reply)
182 {
183 int32_t action = 0;
184 if (!ITypesUtil::Unmarshal(data, action)) {
185 IMSA_HILOGE("failed to read message parcel");
186 return ErrorCode::ERROR_EX_PARCELABLE;
187 }
188 return reply.WriteInt32(HandleExtendAction(action)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
189 }
190
GetTextIndexAtCursorOnRemote(MessageParcel & data,MessageParcel & reply)191 int32_t InputDataChannelStub::GetTextIndexAtCursorOnRemote(MessageParcel &data, MessageParcel &reply)
192 {
193 int32_t index = -1;
194 return ITypesUtil::Marshal(reply, GetTextIndexAtCursor(index), index) ? ErrorCode::NO_ERROR
195 : ErrorCode::ERROR_EX_PARCELABLE;
196 }
197
NotifyPanelStatusInfoOnRemote(MessageParcel & data,MessageParcel & reply)198 int32_t InputDataChannelStub::NotifyPanelStatusInfoOnRemote(MessageParcel &data, MessageParcel &reply)
199 {
200 PanelStatusInfo info{};
201 if (!ITypesUtil::Unmarshal(data, info)) {
202 IMSA_HILOGE("failed to read message parcel");
203 return ErrorCode::ERROR_EX_PARCELABLE;
204 }
205 NotifyPanelStatusInfo(info);
206 return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
207 }
208
NotifyKeyboardHeightOnRemote(MessageParcel & data,MessageParcel & reply)209 int32_t InputDataChannelStub::NotifyKeyboardHeightOnRemote(MessageParcel &data, MessageParcel &reply)
210 {
211 uint32_t height = 0;
212 if (!ITypesUtil::Unmarshal(data, height)) {
213 IMSA_HILOGE("failed to read message parcel");
214 return ErrorCode::ERROR_EX_PARCELABLE;
215 }
216 NotifyKeyboardHeight(height);
217 return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
218 }
219
InsertText(const std::u16string & text)220 int32_t InputDataChannelStub::InsertText(const std::u16string &text)
221 {
222 return InputMethodController::GetInstance()->InsertText(text);
223 }
224
DeleteForward(int32_t length)225 int32_t InputDataChannelStub::DeleteForward(int32_t length)
226 {
227 return InputMethodController::GetInstance()->DeleteForward(length);
228 }
229
DeleteBackward(int32_t length)230 int32_t InputDataChannelStub::DeleteBackward(int32_t length)
231 {
232 return InputMethodController::GetInstance()->DeleteBackward(length);
233 }
234
GetTextBeforeCursor(int32_t number,std::u16string & text)235 int32_t InputDataChannelStub::GetTextBeforeCursor(int32_t number, std::u16string &text)
236 {
237 return InputMethodController::GetInstance()->GetLeft(number, text);
238 }
239
GetTextAfterCursor(int32_t number,std::u16string & text)240 int32_t InputDataChannelStub::GetTextAfterCursor(int32_t number, std::u16string &text)
241 {
242 return InputMethodController::GetInstance()->GetRight(number, text);
243 }
244
GetTextIndexAtCursor(int32_t & index)245 int32_t InputDataChannelStub::GetTextIndexAtCursor(int32_t &index)
246 {
247 return InputMethodController::GetInstance()->GetTextIndexAtCursor(index);
248 }
249
GetEnterKeyType(int32_t & keyType)250 int32_t InputDataChannelStub::GetEnterKeyType(int32_t &keyType)
251 {
252 return InputMethodController::GetInstance()->GetEnterKeyType(keyType);
253 }
254
GetInputPattern(int32_t & inputPattern)255 int32_t InputDataChannelStub::GetInputPattern(int32_t &inputPattern)
256 {
257 return InputMethodController::GetInstance()->GetInputPattern(inputPattern);
258 }
259
GetTextConfig(TextTotalConfig & textConfig)260 int32_t InputDataChannelStub::GetTextConfig(TextTotalConfig &textConfig)
261 {
262 return InputMethodController::GetInstance()->GetTextConfig(textConfig);
263 }
264
SendKeyboardStatus(KeyboardStatus status)265 void InputDataChannelStub::SendKeyboardStatus(KeyboardStatus status)
266 {
267 InputMethodController::GetInstance()->SendKeyboardStatus(status);
268 }
269
SendFunctionKey(int32_t funcKey)270 int32_t InputDataChannelStub::SendFunctionKey(int32_t funcKey)
271 {
272 return InputMethodController::GetInstance()->SendFunctionKey(funcKey);
273 }
274
MoveCursor(int32_t keyCode)275 int32_t InputDataChannelStub::MoveCursor(int32_t keyCode)
276 {
277 return InputMethodController::GetInstance()->MoveCursor(static_cast<Direction>(keyCode));
278 }
279
SelectByRange(int32_t start,int32_t end)280 int32_t InputDataChannelStub::SelectByRange(int32_t start, int32_t end)
281 {
282 InputMethodController::GetInstance()->SelectByRange(start, end);
283 return ErrorCode::NO_ERROR;
284 }
285
SelectByMovement(int32_t direction,int32_t cursorMoveSkip)286 int32_t InputDataChannelStub::SelectByMovement(int32_t direction, int32_t cursorMoveSkip)
287 {
288 InputMethodController::GetInstance()->SelectByMovement(direction, cursorMoveSkip);
289 return ErrorCode::NO_ERROR;
290 }
291
HandleExtendAction(int32_t action)292 int32_t InputDataChannelStub::HandleExtendAction(int32_t action)
293 {
294 return InputMethodController::GetInstance()->HandleExtendAction(action);
295 }
296
NotifyPanelStatusInfo(const PanelStatusInfo & info)297 void InputDataChannelStub::NotifyPanelStatusInfo(const PanelStatusInfo &info)
298 {
299 InputMethodController::GetInstance()->NotifyPanelStatusInfo(info);
300 }
301
NotifyKeyboardHeight(uint32_t height)302 void InputDataChannelStub::NotifyKeyboardHeight(uint32_t height)
303 {
304 InputMethodController::GetInstance()->NotifyKeyboardHeight(height);
305 }
306 } // namespace MiscServices
307 } // namespace OHOS
308