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