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 "message_handler.h" 17 #include "input_control_channel_stub.h" 18 #include "i_input_control_channel.h" 19 #include "input_channel.h" 20 #include "input_method_agent_proxy.h" 21 #include "message_parcel.h" 22 23 namespace OHOS { 24 namespace MiscServices { 25 /*! Constructor 26 \param userId the id of the user to whom the object is linking 27 */ InputControlChannelStub(int userId)28 InputControlChannelStub::InputControlChannelStub(int userId) 29 { 30 userId_ = userId; 31 } 32 33 /*! Destructor 34 */ ~InputControlChannelStub()35 InputControlChannelStub::~InputControlChannelStub() 36 { 37 } 38 39 /*! Handle the transaction from the remote binder 40 \n Run in binder thread 41 \param code transaction code number 42 \param data the params from remote binder 43 \param[out] reply the result of the transaction replied to the remote binder 44 \param flags the flags of handling transaction 45 \return int32_t 46 */ OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)47 int32_t InputControlChannelStub::OnRemoteRequest(uint32_t code, MessageParcel& data, 48 MessageParcel& reply, MessageOption& option) 49 { 50 IMSA_HILOGI("InputControlChannelStub::OnRemoteRequest code = %{public}u", code); 51 auto descriptorToken = data.ReadInterfaceToken(); 52 if (descriptorToken != GetDescriptor()) { 53 return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION; 54 } 55 switch (code) { 56 case HIDE_KEYBOARD_SELF: { 57 int flag = data.ReadInt32(); 58 reply.WriteInt32(HideKeyboardSelf(flag)); 59 break; 60 } 61 default: { 62 return IRemoteStub::OnRemoteRequest(code, data, reply, option); 63 } 64 } 65 return NO_ERROR; 66 } 67 68 69 /*! Send HideKeyboardSelf command to work thread. 70 \n This call is running in binder thread, 71 but the handling of HideKeyboardSelf is in the work thread of PerUserSession. 72 \see PerUserSession::OnHideKeyboardSelf 73 \param flags the flag value of hiding keyboard 74 */ HideKeyboardSelf(int flags)75 int32_t InputControlChannelStub::HideKeyboardSelf(int flags) 76 { 77 IMSA_HILOGI("InputControlChannelStub::HideKeyboardSelf flags = %{public}d", flags); 78 MessageParcel *parcel = new MessageParcel(); 79 parcel->WriteInt32(userId_); 80 parcel->WriteInt32(flags); 81 82 Message *msg = new Message(MessageID::MSG_ID_HIDE_KEYBOARD_SELF, parcel); 83 MessageHandler::Instance()->SendMessage(msg); 84 return ErrorCode::NO_ERROR; 85 } 86 } // namespace MiscServices 87 } // namespace OHOS 88