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 #ifndef FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_CORE_STUB_H 17 #define FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_CORE_STUB_H 18 19 #include <condition_variable> 20 #include <cstdint> 21 #include <mutex> 22 23 #include "i_input_method_core.h" 24 #include "input_attribute.h" 25 #include "iremote_broker.h" 26 #include "iremote_stub.h" 27 #include "message_handler.h" 28 #include "message_parcel.h" 29 30 namespace OHOS { 31 namespace MiscServices { 32 class InputMethodCoreStub : public IRemoteStub<IInputMethodCore> { 33 public: 34 DISALLOW_COPY_AND_MOVE(InputMethodCoreStub); 35 InputMethodCoreStub(); 36 virtual ~InputMethodCoreStub(); 37 int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 38 int32_t StartInput(const InputClientInfo &clientInfo, bool isBindFromClient) override; 39 int32_t StopInput(const sptr<IRemoteObject> &channel) override; 40 int32_t ShowKeyboard() override; 41 int32_t HideKeyboard() override; 42 int32_t InitInputControlChannel(const sptr<IInputControlChannel> &inputControlChannel) override; 43 int32_t StopInputService(bool isTerminateIme) override; 44 int32_t SetSubtype(const SubProperty &property) override; 45 bool IsEnable() override; 46 int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) override; 47 int32_t OnSecurityChange(int32_t security) override; 48 int32_t OnConnectSystemCmd(const sptr<IRemoteObject> &channel, sptr<IRemoteObject> &agent) override; 49 void OnClientInactive(const sptr<IRemoteObject> &channel) override; 50 void SetMessageHandler(MessageHandler *msgHandler); 51 52 private: 53 MessageHandler *msgHandler_; 54 int32_t StartInputOnRemote(MessageParcel &data, MessageParcel &reply); 55 int32_t StopInputOnRemote(MessageParcel &data, MessageParcel &reply); 56 int32_t ShowKeyboardOnRemote(MessageParcel &data, MessageParcel &reply); 57 int32_t HideKeyboardOnRemote(MessageParcel &data, MessageParcel &reply); 58 int32_t InitInputControlChannelOnRemote(MessageParcel &data, MessageParcel &reply); 59 int32_t StopInputServiceOnRemote(MessageParcel &data, MessageParcel &reply); 60 int32_t SetSubtypeOnRemote(MessageParcel &data, MessageParcel &reply); 61 int32_t IsEnableOnRemote(MessageParcel &data, MessageParcel &reply); 62 int32_t IsPanelShownOnRemote(MessageParcel &data, MessageParcel &reply); 63 int32_t SecurityChangeOnRemote(MessageParcel &data, MessageParcel &reply); 64 int32_t OnClientInactiveOnRemote(MessageParcel &data, MessageParcel &reply); 65 int32_t OnConnectSystemCmdOnRemote(MessageParcel &data, MessageParcel &reply); 66 using ParcelHandler = std::function<bool(MessageParcel &)>; 67 int32_t SendMessage(int code, ParcelHandler input = nullptr); 68 using RequestHandler = int32_t (InputMethodCoreStub::*)(MessageParcel &, MessageParcel &); 69 static constexpr RequestHandler HANDLERS[CORE_CMD_END] = { 70 [SHOW_KEYBOARD] = &InputMethodCoreStub::ShowKeyboardOnRemote, 71 [STOP_INPUT_SERVICE] = &InputMethodCoreStub::StopInputServiceOnRemote, 72 [HIDE_KEYBOARD] = &InputMethodCoreStub::HideKeyboardOnRemote, 73 [INIT_INPUT_CONTROL_CHANNEL] = &InputMethodCoreStub::InitInputControlChannelOnRemote, 74 [SET_SUBTYPE] = &InputMethodCoreStub::SetSubtypeOnRemote, 75 [START_INPUT] = &InputMethodCoreStub::StartInputOnRemote, 76 [STOP_INPUT] = &InputMethodCoreStub::StopInputOnRemote, 77 [IS_ENABLE] = &InputMethodCoreStub::IsEnableOnRemote, 78 [IS_PANEL_SHOWN] = &InputMethodCoreStub::IsPanelShownOnRemote, 79 [SECURITY_CHANGE] = &InputMethodCoreStub::SecurityChangeOnRemote, 80 [ON_CLIENT_INACTIVE] = &InputMethodCoreStub::OnClientInactiveOnRemote, 81 [ON_CONNECT_SYSTEM_CMD] = &InputMethodCoreStub::OnConnectSystemCmdOnRemote, 82 }; 83 }; 84 } // namespace MiscServices 85 } // namespace OHOS 86 #endif // FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_CORE_STUB_H 87