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_client_stub.h" 17 18 #include "global.h" 19 #include "ipc_object_stub.h" 20 #include "ipc_types.h" 21 #include "itypes_util.h" 22 #include "message.h" 23 24 namespace OHOS { 25 namespace MiscServices { InputClientStub()26 InputClientStub::InputClientStub() 27 { 28 } 29 ~InputClientStub()30 InputClientStub::~InputClientStub() 31 { 32 } 33 OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int32_t InputClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, 35 MessageOption &option) 36 { 37 IMSA_HILOGI("InputClientStub::OnRemoteRequest. code = %{public}u", code); 38 auto descriptorToken = data.ReadInterfaceToken(); 39 if (descriptorToken != GetDescriptor()) { 40 return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION; 41 } 42 switch (code) { 43 case ON_INPUT_READY: { 44 if (!msgHandler) { 45 break; 46 } 47 MessageParcel *parcel = new MessageParcel(); 48 parcel->WriteRemoteObject(data.ReadRemoteObject()); 49 50 Message *msg = new Message(MessageID::MSG_ID_ON_INPUT_READY, parcel); 51 msgHandler->SendMessage(msg); 52 break; 53 } 54 case ON_SWITCH_INPUT: { 55 OnSwitchInputOnRemote(data, reply); 56 break; 57 } 58 default: 59 return IPCObjectStub::OnRemoteRequest(code, data, reply, option); 60 } 61 return NO_ERROR; 62 } 63 OnSwitchInputOnRemote(MessageParcel & data,MessageParcel & reply)64 void InputClientStub::OnSwitchInputOnRemote(MessageParcel &data, MessageParcel &reply) 65 { 66 IMSA_HILOGI("InputClientStub::OnSwitchInputOnRemote"); 67 if (msgHandler == nullptr) { 68 IMSA_HILOGE("InputClientStub::msgHandler is nullptr"); 69 return; 70 } 71 auto *parcel = new (std::nothrow) MessageParcel(); 72 if (parcel == nullptr) { 73 IMSA_HILOGE("parcel is nullptr"); 74 reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER); 75 return; 76 } 77 Property property; 78 SubProperty subProperty; 79 if (!ITypesUtil::Unmarshal(data, property, subProperty)) { 80 IMSA_HILOGE("read message parcel failed"); 81 reply.WriteInt32(ErrorCode::ERROR_EX_PARCELABLE); 82 delete parcel; 83 return; 84 } 85 if (!ITypesUtil::Marshal(*parcel, property, subProperty)) { 86 IMSA_HILOGE("write message parcel failed"); 87 reply.WriteInt32(ErrorCode::ERROR_EX_PARCELABLE); 88 delete parcel; 89 return; 90 } 91 auto *msg = new (std::nothrow) Message(MessageID::MSG_ID_ON_SWITCH_INPUT, parcel); 92 if (msg == nullptr) { 93 IMSA_HILOGE("msg is nullptr"); 94 delete parcel; 95 reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER); 96 return; 97 } 98 msgHandler->SendMessage(msg); 99 reply.WriteInt32(ErrorCode::NO_ERROR); 100 } 101 onInputReady(const sptr<IInputMethodAgent> & agent)102 int32_t InputClientStub::onInputReady(const sptr<IInputMethodAgent>& agent) 103 { 104 return ErrorCode::NO_ERROR; 105 } 106 107 SetHandler(MessageHandler * handler)108 void InputClientStub::SetHandler(MessageHandler *handler) 109 { 110 msgHandler = handler; 111 } 112 OnSwitchInput(const Property & property,const SubProperty & subProperty)113 int32_t InputClientStub::OnSwitchInput(const Property &property, const SubProperty &subProperty) 114 { 115 return ErrorCode::NO_ERROR; 116 } 117 } // namespace MiscServices 118 } // namespace OHOS 119