• 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 #include "input_method_core_proxy.h"
17 
18 #include <string_ex.h>
19 
20 #include "input_attribute.h"
21 #include "itypes_util.h"
22 #include "message_option.h"
23 #include "message_parcel.h"
24 
25 namespace OHOS {
26 namespace MiscServices {
InputMethodCoreProxy(const OHOS::sptr<OHOS::IRemoteObject> & impl)27 InputMethodCoreProxy::InputMethodCoreProxy(const OHOS::sptr<OHOS::IRemoteObject> &impl)
28     : IRemoteProxy<IInputMethodCore>(impl)
29 {
30 }
31 
32 InputMethodCoreProxy::~InputMethodCoreProxy() = default;
33 
InitInputControlChannel(const sptr<IInputControlChannel> & inputControlChannel)34 int32_t InputMethodCoreProxy::InitInputControlChannel(const sptr<IInputControlChannel> &inputControlChannel)
35 {
36     return SendRequest(INIT_INPUT_CONTROL_CHANNEL, [&inputControlChannel](MessageParcel &data) {
37         return ITypesUtil::Marshal(data, inputControlChannel->AsObject());
38     });
39 }
40 
StartInput(const InputClientInfo & clientInfo,bool isBindFromClient)41 int32_t InputMethodCoreProxy::StartInput(const InputClientInfo &clientInfo, bool isBindFromClient)
42 {
43     IMSA_HILOGI("CoreProxy");
44     return SendRequest(START_INPUT, [&clientInfo, isBindFromClient](MessageParcel &data) {
45         return ITypesUtil::Marshal(data, isBindFromClient, clientInfo);
46     });
47 }
48 
OnSecurityChange(int32_t security)49 int32_t InputMethodCoreProxy::OnSecurityChange(int32_t security)
50 {
51     return SendRequest(SECURITY_CHANGE, [security](MessageParcel& data) {
52         return ITypesUtil::Marshal(data, security);
53     });
54 }
55 
StopInputService(bool isTerminateIme)56 void InputMethodCoreProxy::StopInputService(bool isTerminateIme)
57 {
58     SendRequest(STOP_INPUT_SERVICE,
59         [isTerminateIme](MessageParcel &data) { return ITypesUtil::Marshal(data, isTerminateIme); });
60 }
61 
ShowKeyboard()62 int32_t InputMethodCoreProxy::ShowKeyboard()
63 {
64     return SendRequest(SHOW_KEYBOARD);
65 }
66 
HideKeyboard()67 int32_t InputMethodCoreProxy::HideKeyboard()
68 {
69     return SendRequest(HIDE_KEYBOARD);
70 }
71 
SetSubtype(const SubProperty & property)72 int32_t InputMethodCoreProxy::SetSubtype(const SubProperty &property)
73 {
74     return SendRequest(SET_SUBTYPE, [&property](MessageParcel &data) { return ITypesUtil::Marshal(data, property); });
75 }
76 
StopInput(const sptr<IInputDataChannel> & channel)77 int32_t InputMethodCoreProxy::StopInput(const sptr<IInputDataChannel> &channel)
78 {
79     return SendRequest(
80         STOP_INPUT, [&channel](MessageParcel &data) { return ITypesUtil::Marshal(data, channel->AsObject()); });
81 }
82 
IsEnable()83 bool InputMethodCoreProxy::IsEnable()
84 {
85     bool isEnable = false;
86     SendRequest(
87         IS_ENABLE, nullptr, [&isEnable](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, isEnable); });
88     return isEnable;
89 }
90 
IsPanelShown(const PanelInfo & panelInfo,bool & isShown)91 int32_t InputMethodCoreProxy::IsPanelShown(const PanelInfo &panelInfo, bool &isShown)
92 {
93     return SendRequest(
94         IS_PANEL_SHOWN, [&panelInfo](MessageParcel &data) { return ITypesUtil::Marshal(data, panelInfo); },
95         [&isShown](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, isShown); });
96 }
97 
OnClientInactive(const sptr<IInputDataChannel> & channel)98 void InputMethodCoreProxy::OnClientInactive(const sptr<IInputDataChannel> &channel)
99 {
100     SendRequest(
101         ON_CLIENT_INACTIVE, [&channel](MessageParcel &data) { return ITypesUtil::Marshal(data, channel->AsObject()); },
102         nullptr, MessageOption::TF_ASYNC);
103 }
104 
OnTextConfigChange(const InputClientInfo & clientInfo)105 int32_t InputMethodCoreProxy::OnTextConfigChange(const InputClientInfo &clientInfo)
106 {
107     return SendRequest(
108         ON_TEXT_CONFIG_CHANGE, [&clientInfo](MessageParcel &data) { return ITypesUtil::Marshal(data, clientInfo); });
109 }
110 
SendRequest(int code,ParcelHandler input,ParcelHandler output,MessageOption option)111 int32_t InputMethodCoreProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output, MessageOption option)
112 {
113     IMSA_HILOGD("InputMethodCoreProxy, run in, code = %{public}d", code);
114     MessageParcel data;
115     MessageParcel reply;
116     if (!data.WriteInterfaceToken(GetDescriptor())) {
117         IMSA_HILOGE("InputMethodCoreProxy::write interface token failed");
118         return ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT;
119     }
120     if (input != nullptr && (!input(data))) {
121         IMSA_HILOGE("InputMethodCoreProxy::write data failed");
122         return ErrorCode::ERROR_EX_PARCELABLE;
123     }
124     auto ret = Remote()->SendRequest(code, data, reply, option);
125     if (ret != NO_ERROR) {
126         IMSA_HILOGE("InputMethodCoreProxy send request failed, code: %{public}d, ret %{public}d", code, ret);
127         return ret;
128     }
129     ret = reply.ReadInt32();
130     if (ret != NO_ERROR) {
131         IMSA_HILOGE("InputMethodCoreProxy::reply error, ret %{public}d", ret);
132         return ret;
133     }
134     if (output != nullptr && (!output(reply))) {
135         IMSA_HILOGE("InputMethodCoreProxy::reply parcel error");
136         return ErrorCode::ERROR_EX_PARCELABLE;
137     }
138     return ret;
139 }
140 } // namespace MiscServices
141 } // namespace OHOS
142