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 "input_method_controller.h"
20 #include "ipc_object_stub.h"
21 #include "ipc_skeleton.h"
22 #include "ipc_types.h"
23 #include "itypes_util.h"
24 #include "message.h"
25
26 namespace OHOS {
27 namespace MiscServices {
InputClientStub()28 InputClientStub::InputClientStub()
29 {
30 }
31
~InputClientStub()32 InputClientStub::~InputClientStub()
33 {
34 }
35
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int32_t InputClientStub::OnRemoteRequest(
37 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
38 {
39 IMSA_HILOGD("InputClientStub code = %{public}u, callingPid: %{public}d, callingUid: %{public}d", code,
40 IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
41 auto descriptorToken = data.ReadInterfaceToken();
42 if (descriptorToken != GetDescriptor()) {
43 return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
44 }
45 switch (code) {
46 case ON_INPUT_READY: {
47 OnInputReadyOnRemote(data, reply);
48 break;
49 }
50 case ON_INPUT_STOP: {
51 OnInputStopOnRemote(data, reply);
52 break;
53 }
54 case ON_SWITCH_INPUT: {
55 return OnSwitchInputOnRemote(data, reply);
56 }
57 case ON_PANEL_STATUS_CHANGE: {
58 return OnPanelStatusChangeOnRemote(data, reply);
59 }
60 case DEACTIVATE_CLIENT: {
61 return DeactivateClientOnRemote(data, reply);
62 }
63 default:
64 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
65 }
66 return NO_ERROR;
67 }
68
OnInputReadyOnRemote(MessageParcel & data,MessageParcel & reply)69 void InputClientStub::OnInputReadyOnRemote(MessageParcel &data, MessageParcel &reply)
70 {
71 IMSA_HILOGI("ClientStub, run in");
72 auto object = data.ReadRemoteObject();
73 InputMethodController::GetInstance()->OnInputReady(object);
74 }
75
OnInputStopOnRemote(MessageParcel & data,MessageParcel & reply)76 int32_t InputClientStub::OnInputStopOnRemote(MessageParcel &data, MessageParcel &reply)
77 {
78 return reply.WriteInt32(OnInputStop()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
79 }
80
OnSwitchInputOnRemote(MessageParcel & data,MessageParcel & reply)81 int32_t InputClientStub::OnSwitchInputOnRemote(MessageParcel &data, MessageParcel &reply)
82 {
83 Property property;
84 SubProperty subProperty;
85 if (!ITypesUtil::Unmarshal(data, property, subProperty)) {
86 IMSA_HILOGE("read message parcel failed");
87 return ErrorCode::ERROR_EX_PARCELABLE;
88 }
89 return reply.WriteInt32(OnSwitchInput(property, subProperty)) ? ErrorCode::NO_ERROR
90 : ErrorCode::ERROR_EX_PARCELABLE;
91 }
92
OnPanelStatusChangeOnRemote(MessageParcel & data,MessageParcel & reply)93 int32_t InputClientStub::OnPanelStatusChangeOnRemote(MessageParcel &data, MessageParcel &reply)
94 {
95 uint32_t status;
96 std::vector<InputWindowInfo> windowInfo;
97 if (!ITypesUtil::Unmarshal(data, status, windowInfo)) {
98 IMSA_HILOGE("read message parcel failed");
99 return ErrorCode::ERROR_EX_PARCELABLE;
100 }
101 return reply.WriteInt32(OnPanelStatusChange(static_cast<InputWindowStatus>(status), windowInfo))
102 ? ErrorCode::NO_ERROR
103 : ErrorCode::ERROR_EX_PARCELABLE;
104 }
105
DeactivateClientOnRemote(MessageParcel & data,MessageParcel & reply)106 int32_t InputClientStub::DeactivateClientOnRemote(MessageParcel &data, MessageParcel &reply)
107 {
108 DeactivateClient();
109 return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
110 }
111
OnInputReady(const sptr<IInputMethodAgent> & agent)112 int32_t InputClientStub::OnInputReady(const sptr<IInputMethodAgent> &agent)
113 {
114 return ErrorCode::NO_ERROR;
115 }
116
OnInputStop()117 int32_t InputClientStub::OnInputStop()
118 {
119 InputMethodController::GetInstance()->OnInputStop();
120 return ErrorCode::NO_ERROR;
121 }
122
OnSwitchInput(const Property & property,const SubProperty & subProperty)123 int32_t InputClientStub::OnSwitchInput(const Property &property, const SubProperty &subProperty)
124 {
125 return InputMethodController::GetInstance()->OnSwitchInput(property, subProperty);
126 }
127
OnPanelStatusChange(const InputWindowStatus & status,const std::vector<InputWindowInfo> & windowInfo)128 int32_t InputClientStub::OnPanelStatusChange(
129 const InputWindowStatus &status, const std::vector<InputWindowInfo> &windowInfo)
130 {
131 return InputMethodController::GetInstance()->OnPanelStatusChange(status, windowInfo);
132 }
133
DeactivateClient()134 void InputClientStub::DeactivateClient()
135 {
136 InputMethodController::GetInstance()->DeactivateClient();
137 }
138 } // namespace MiscServices
139 } // namespace OHOS
140