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