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