• 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_client_proxy.h"
17 
18 #include "global.h"
19 #include "itypes_util.h"
20 #include "message_option.h"
21 #include "message_parcel.h"
22 
23 namespace OHOS {
24 namespace MiscServices {
25 using namespace ErrorCode;
InputClientProxy(const sptr<IRemoteObject> & object)26 InputClientProxy::InputClientProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IInputClient>(object)
27 {
28 }
29 
OnInputReady(const sptr<IRemoteObject> & agent)30 int32_t InputClientProxy::OnInputReady(const sptr<IRemoteObject> &agent)
31 {
32     return SendRequest(ON_INPUT_READY, [agent](MessageParcel &data) { return ITypesUtil::Marshal(data, agent); });
33 }
34 
OnInputStop(bool isStopInactiveClient)35 int32_t InputClientProxy::OnInputStop(bool isStopInactiveClient)
36 {
37     return SendRequest(ON_INPUT_STOP,
38         [isStopInactiveClient](MessageParcel &data) { return ITypesUtil::Marshal(data, isStopInactiveClient); });
39 }
40 
OnSwitchInput(const Property & property,const SubProperty & subProperty)41 int32_t InputClientProxy::OnSwitchInput(const Property &property, const SubProperty &subProperty)
42 {
43     return SendRequest(ON_SWITCH_INPUT,
44         [&property, &subProperty](MessageParcel &data) { return ITypesUtil::Marshal(data, property, subProperty); });
45 }
46 
OnPanelStatusChange(const InputWindowStatus & status,const ImeWindowInfo & info)47 int32_t InputClientProxy::OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info)
48 {
49     return SendRequest(ON_PANEL_STATUS_CHANGE, [&status, &info](MessageParcel &data) {
50         return ITypesUtil::Marshal(data, static_cast<uint32_t>(status), info);
51     });
52 }
53 
NotifyInputStart(uint32_t callingWndId,int32_t requestKeyboardReason)54 int32_t InputClientProxy::NotifyInputStart(uint32_t callingWndId, int32_t requestKeyboardReason)
55 {
56     IMSA_HILOGD("InputClientProxy::NotifyInputStart");
57     return SendRequest(ON_NOTIFY_INPUT_START, [callingWndId, requestKeyboardReason](MessageParcel &data) {
58         return ITypesUtil::Marshal(data, callingWndId, requestKeyboardReason);
59     });
60 }
61 
NotifyInputStop()62 int32_t InputClientProxy::NotifyInputStop()
63 {
64     IMSA_HILOGD("InputClientProxy::NotifyInputStop");
65     return SendRequest(ON_NOTIFY_INPUT_STOP, nullptr);
66 }
DeactivateClient()67 void InputClientProxy::DeactivateClient()
68 {
69     SendRequest(DEACTIVATE_CLIENT, nullptr, nullptr, MessageOption::TF_ASYNC);
70 }
71 
SendRequest(int code,ParcelHandler input,ParcelHandler output,MessageOption option)72 int32_t InputClientProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output, MessageOption option)
73 {
74     IMSA_HILOGD("InputClientProxy run in, code = %{public}d", code);
75     MessageParcel data;
76     MessageParcel reply;
77     if (!data.WriteInterfaceToken(GetDescriptor())) {
78         IMSA_HILOGE("write interface token failed!");
79         return ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT;
80     }
81     if (input != nullptr && (!input(data))) {
82         IMSA_HILOGE("write data failed!");
83         return ErrorCode::ERROR_EX_PARCELABLE;
84     }
85     auto remote = Remote();
86     if (remote == nullptr) {
87         IMSA_HILOGE("remote is nullptr!");
88         return ErrorCode::ERROR_EX_NULL_POINTER;
89     }
90     auto ret = remote->SendRequest(code, data, reply, option);
91     if (ret != NO_ERROR) {
92         IMSA_HILOGE("send request failed, code: %{public}d, ret: %{public}d!", code, ret);
93         return ret;
94     }
95     ret = reply.ReadInt32();
96     if (ret != NO_ERROR) {
97         IMSA_HILOGE("reply error, ret: %{public}d", ret);
98         return ret;
99     }
100     if (output != nullptr && (!output(reply))) {
101         IMSA_HILOGE("reply parcel error!");
102         return ErrorCode::ERROR_EX_PARCELABLE;
103     }
104     return ret;
105 }
106 } // namespace MiscServices
107 } // namespace OHOS