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_proxy.h" 17 #include "message_parcel.h" 18 19 namespace OHOS { 20 namespace MiscServices { InputDataChannelProxy(const sptr<IRemoteObject> & object)21 InputDataChannelProxy::InputDataChannelProxy(const sptr<IRemoteObject> &object) 22 : IRemoteProxy<IInputDataChannel>(object) 23 { 24 } 25 InsertText(const std::u16string & text)26 bool InputDataChannelProxy::InsertText(const std::u16string& text) 27 { 28 IMSA_HILOGI("InputDataChannelProxy::InsertText"); 29 MessageParcel data, reply; 30 MessageOption option; 31 data.WriteInterfaceToken(GetDescriptor()); 32 data.WriteString16(text); 33 34 auto ret = Remote()->SendRequest(INSERT_TEXT, data, reply, option); 35 if (ret != NO_ERROR) { 36 return false; 37 } 38 auto result = reply.ReadBool(); 39 return result; 40 } 41 DeleteForward(int32_t length)42 bool InputDataChannelProxy::DeleteForward(int32_t length) 43 { 44 IMSA_HILOGI("InputDataChannelProxy::DeleteForward"); 45 MessageParcel data, reply; 46 MessageOption option; 47 data.WriteInterfaceToken(GetDescriptor()); 48 data.WriteInt32(length); 49 50 auto ret = Remote()->SendRequest(DELETE_FORWARD, data, reply, option); 51 if (ret != NO_ERROR) { 52 return false; 53 } 54 auto result = reply.ReadBool(); 55 return result; 56 } 57 DeleteBackward(int32_t length)58 bool InputDataChannelProxy::DeleteBackward(int32_t length) 59 { 60 IMSA_HILOGI("InputDataChannelProxy::DeleteBackward"); 61 MessageParcel data, reply; 62 MessageOption option; 63 data.WriteInterfaceToken(GetDescriptor()); 64 data.WriteInt32(length); 65 66 auto ret = Remote()->SendRequest(DELETE_BACKWARD, data, reply, option); 67 if (ret != NO_ERROR) { 68 return false; 69 } 70 auto result = reply.ReadBool(); 71 return result; 72 } 73 Close()74 void InputDataChannelProxy::Close() 75 { 76 IMSA_HILOGI("InputDataChannelProxy::Close"); 77 MessageParcel data, reply; 78 MessageOption option; 79 data.WriteInterfaceToken(GetDescriptor()); 80 81 auto ret = Remote()->SendRequest(CLOSE, data, reply, option); 82 if (ret != NO_ERROR) { 83 } 84 } 85 GetTextBeforeCursor(int32_t number)86 std::u16string InputDataChannelProxy::GetTextBeforeCursor(int32_t number) 87 { 88 IMSA_HILOGI("InputDataChannelProxy::GetTextBeforeCursor"); 89 MessageParcel data, reply; 90 MessageOption option; 91 data.WriteInterfaceToken(GetDescriptor()); 92 data.WriteInt32(number); 93 94 Remote()->SendRequest(GET_TEXT_BEFORE_CURSOR, data, reply, option); 95 auto result = reply.ReadString16(); 96 return result; 97 } 98 GetTextAfterCursor(int32_t number)99 std::u16string InputDataChannelProxy::GetTextAfterCursor(int32_t number) 100 { 101 IMSA_HILOGI("InputDataChannelProxy::GetTextAfterCursor"); 102 MessageParcel data, reply; 103 MessageOption option; 104 data.WriteInterfaceToken(GetDescriptor()); 105 data.WriteInt32(number); 106 107 Remote()->SendRequest(GET_TEXT_AFTER_CURSOR, data, reply, option); 108 auto result = reply.ReadString16(); 109 return result; 110 } 111 SendKeyboardStatus(int32_t status)112 void InputDataChannelProxy::SendKeyboardStatus(int32_t status) 113 { 114 IMSA_HILOGI("InputDataChannelProxy::SendKeyboardStatus"); 115 MessageParcel data, reply; 116 MessageOption option; 117 data.WriteInterfaceToken(GetDescriptor()); 118 data.WriteInt32(status); 119 120 Remote()->SendRequest(SEND_KEYBOARD_STATUS, data, reply, option); 121 } 122 SendFunctionKey(int32_t funcKey)123 void InputDataChannelProxy::SendFunctionKey(int32_t funcKey) 124 { 125 IMSA_HILOGI("InputDataChannelProxy::SendFunctionKey"); 126 MessageParcel data, reply; 127 MessageOption option; 128 data.WriteInterfaceToken(GetDescriptor()); 129 data.WriteInt32(funcKey); 130 131 Remote()->SendRequest(SEND_FUNCTION_KEY, data, reply, option); 132 } 133 MoveCursor(int32_t keyCode)134 void InputDataChannelProxy::MoveCursor(int32_t keyCode) 135 { 136 IMSA_HILOGI("InputDataChannelProxy::MoveCursor"); 137 138 MessageParcel data, reply; 139 MessageOption option; 140 data.WriteInterfaceToken(GetDescriptor()); 141 data.WriteInt32(keyCode); 142 143 Remote()->SendRequest(MOVE_CURSOR, data, reply, option); 144 } 145 GetEnterKeyType()146 int32_t InputDataChannelProxy::GetEnterKeyType() 147 { 148 IMSA_HILOGI("InputDataChannelProxy::GetEnterKeyType"); 149 MessageParcel data, reply; 150 MessageOption option; 151 data.WriteInterfaceToken(GetDescriptor()); 152 153 Remote()->SendRequest(GET_ENTER_KEY_TYPE, data, reply, option); 154 auto result = reply.ReadInt32(); 155 return result; 156 } 157 GetInputPattern()158 int32_t InputDataChannelProxy::GetInputPattern() 159 { 160 IMSA_HILOGI("InputDataChannelProxy::GetInputPattern"); 161 MessageParcel data, reply; 162 MessageOption option; 163 data.WriteInterfaceToken(GetDescriptor()); 164 165 Remote()->SendRequest(GET_INPUT_PATTERN, data, reply, option); 166 auto result = reply.ReadInt32(); 167 return result; 168 } 169 StopInput()170 void InputDataChannelProxy::StopInput() 171 { 172 IMSA_HILOGI("InputDataChannelProxy::StopInput"); 173 MessageParcel data, reply; 174 MessageOption option; 175 data.WriteInterfaceToken(GetDescriptor()); 176 177 Remote()->SendRequest(STOP_INPUT, data, reply, option); 178 } 179 } 180 } 181