• 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_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         case ON_NOTIFY_INPUT_START: {
65             return NotifyInputStartOnRemote(data, reply);
66         }
67         case ON_NOTIFY_INPUT_STOP: {
68             return NotifyInputStopOnRemote(data, reply);
69         }
70         default:
71             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
72     }
73     return NO_ERROR;
74 }
75 
OnInputReadyOnRemote(MessageParcel & data,MessageParcel & reply)76 void InputClientStub::OnInputReadyOnRemote(MessageParcel &data, MessageParcel &reply)
77 {
78     IMSA_HILOGI("ClientStub start.");
79     auto object = data.ReadRemoteObject();
80     InputMethodController::GetInstance()->OnInputReady(object);
81 }
82 
OnInputStopOnRemote(MessageParcel & data,MessageParcel & reply)83 int32_t InputClientStub::OnInputStopOnRemote(MessageParcel &data, MessageParcel &reply)
84 {
85     bool isStopInactiveClient = false;
86     if (!ITypesUtil::Unmarshal(data, isStopInactiveClient)) {
87         IMSA_HILOGE("failed to unmarshall isStopInactiveClient");
88         return ErrorCode::ERROR_EX_PARCELABLE;
89     }
90     return reply.WriteInt32(OnInputStop(isStopInactiveClient)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
91 }
92 
OnSwitchInputOnRemote(MessageParcel & data,MessageParcel & reply)93 int32_t InputClientStub::OnSwitchInputOnRemote(MessageParcel &data, MessageParcel &reply)
94 {
95     Property property;
96     SubProperty subProperty;
97     if (!ITypesUtil::Unmarshal(data, property, subProperty)) {
98         IMSA_HILOGE("read message parcel failed!");
99         return ErrorCode::ERROR_EX_PARCELABLE;
100     }
101     return reply.WriteInt32(OnSwitchInput(property, subProperty)) ? ErrorCode::NO_ERROR
102                                                                   : ErrorCode::ERROR_EX_PARCELABLE;
103 }
104 
OnPanelStatusChangeOnRemote(MessageParcel & data,MessageParcel & reply)105 int32_t InputClientStub::OnPanelStatusChangeOnRemote(MessageParcel &data, MessageParcel &reply)
106 {
107     uint32_t status = 0;
108     ImeWindowInfo info;
109     if (!ITypesUtil::Unmarshal(data, status, info)) {
110         IMSA_HILOGE("read message parcel failed!");
111         return ErrorCode::ERROR_EX_PARCELABLE;
112     }
113     return reply.WriteInt32(OnPanelStatusChange(static_cast<InputWindowStatus>(status), info))
114                ? ErrorCode::NO_ERROR
115                : ErrorCode::ERROR_EX_PARCELABLE;
116 }
117 
DeactivateClientOnRemote(MessageParcel & data,MessageParcel & reply)118 int32_t InputClientStub::DeactivateClientOnRemote(MessageParcel &data, MessageParcel &reply)
119 {
120     DeactivateClient();
121     return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
122 }
123 
NotifyInputStartOnRemote(MessageParcel & data,MessageParcel & reply)124 int32_t InputClientStub::NotifyInputStartOnRemote(MessageParcel &data, MessageParcel &reply)
125 {
126     uint32_t callingWndId = 0;
127     int32_t requestKeyboardReason = 0;
128     if (!ITypesUtil::Unmarshal(data, callingWndId, requestKeyboardReason)) {
129         IMSA_HILOGE("read message parcel failed!");
130         return ErrorCode::ERROR_EX_PARCELABLE;
131     }
132     return reply.WriteInt32(NotifyInputStart(callingWndId, requestKeyboardReason)) ? ErrorCode::NO_ERROR
133                                                                                    : ErrorCode::ERROR_EX_PARCELABLE;
134 }
135 
NotifyInputStopOnRemote(MessageParcel & data,MessageParcel & reply)136 int32_t InputClientStub::NotifyInputStopOnRemote(MessageParcel &data, MessageParcel &reply)
137 {
138     return reply.WriteInt32(NotifyInputStop()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
139 }
140 
OnInputReady(const sptr<IRemoteObject> & agent)141 int32_t InputClientStub::OnInputReady(const sptr<IRemoteObject> &agent)
142 {
143     return ErrorCode::NO_ERROR;
144 }
145 
OnInputStop(bool isStopInactiveClient)146 int32_t InputClientStub::OnInputStop(bool isStopInactiveClient)
147 {
148     InputMethodController::GetInstance()->OnInputStop(isStopInactiveClient);
149     return ErrorCode::NO_ERROR;
150 }
151 
OnSwitchInput(const Property & property,const SubProperty & subProperty)152 int32_t InputClientStub::OnSwitchInput(const Property &property, const SubProperty &subProperty)
153 {
154     return ImeEventMonitorManagerImpl::GetInstance().OnImeChange(property, subProperty);
155 }
156 
OnPanelStatusChange(const InputWindowStatus & status,const ImeWindowInfo & info)157 int32_t InputClientStub::OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info)
158 {
159     return ImeEventMonitorManagerImpl::GetInstance().OnPanelStatusChange(status, info);
160 }
161 
NotifyInputStart(uint32_t callingWndId,int32_t requestKeyboardReason)162 int32_t InputClientStub::NotifyInputStart(uint32_t callingWndId, int32_t requestKeyboardReason)
163 {
164     return ImeEventMonitorManagerImpl::GetInstance().OnInputStart(callingWndId, requestKeyboardReason);
165 }
166 
NotifyInputStop()167 int32_t InputClientStub::NotifyInputStop()
168 {
169     return ImeEventMonitorManagerImpl::GetInstance().OnInputStop();
170 }
171 
DeactivateClient()172 void InputClientStub::DeactivateClient()
173 {
174     InputMethodController::GetInstance()->DeactivateClient();
175 }
176 } // namespace MiscServices
177 } // namespace OHOS
178