• 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 
~InputClientStub()31 InputClientStub::~InputClientStub() { }
32 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int32_t InputClientStub::OnRemoteRequest(
34     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
35 {
36     IMSA_HILOGD("InputClientStub code = %{public}u, callingPid: %{public}d, callingUid: %{public}d", code,
37         IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
38     auto descriptorToken = data.ReadInterfaceToken();
39     if (descriptorToken != GetDescriptor()) {
40         return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
41     }
42     switch (code) {
43         case ON_INPUT_READY: {
44             OnInputReadyOnRemote(data, reply);
45             break;
46         }
47         case ON_INPUT_STOP: {
48             OnInputStopOnRemote(data, reply);
49             break;
50         }
51         case ON_SWITCH_INPUT: {
52             return OnSwitchInputOnRemote(data, reply);
53         }
54         case ON_PANEL_STATUS_CHANGE: {
55             return OnPanelStatusChangeOnRemote(data, reply);
56         }
57         case DEACTIVATE_CLIENT: {
58             return DeactivateClientOnRemote(data, reply);
59         }
60         case ON_NOTIFY_INPUT_START: {
61             return NotifyInputStartOnRemote(data, reply);
62         }
63         case ON_NOTIFY_INPUT_STOP: {
64             return NotifyInputStopOnRemote(data, reply);
65         }
66         default:
67             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
68     }
69     return NO_ERROR;
70 }
71 
OnInputReadyOnRemote(MessageParcel & data,MessageParcel & reply)72 void InputClientStub::OnInputReadyOnRemote(MessageParcel &data, MessageParcel &reply)
73 {
74     IMSA_HILOGI("ClientStub start.");
75     std::pair<int64_t, std::string> imeInfo{ 0, "" };
76     sptr<IRemoteObject> agentObject = nullptr;
77     ITypesUtil::Unmarshal(data, agentObject, imeInfo.first, imeInfo.second);
78     InputMethodController::GetInstance()->OnInputReady(agentObject, imeInfo);
79 }
80 
OnInputStopOnRemote(MessageParcel & data,MessageParcel & reply)81 int32_t InputClientStub::OnInputStopOnRemote(MessageParcel &data, MessageParcel &reply)
82 {
83     bool isStopInactiveClient = false;
84     if (!ITypesUtil::Unmarshal(data, isStopInactiveClient)) {
85         IMSA_HILOGE("failed to unmarshall isStopInactiveClient");
86         return ErrorCode::ERROR_EX_PARCELABLE;
87     }
88     return reply.WriteInt32(OnInputStop(isStopInactiveClient)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
89 }
90 
OnSwitchInputOnRemote(MessageParcel & data,MessageParcel & reply)91 int32_t InputClientStub::OnSwitchInputOnRemote(MessageParcel &data, MessageParcel &reply)
92 {
93     Property property;
94     SubProperty subProperty;
95     if (!ITypesUtil::Unmarshal(data, property, subProperty)) {
96         IMSA_HILOGE("read message parcel failed!");
97         return ErrorCode::ERROR_EX_PARCELABLE;
98     }
99     return reply.WriteInt32(OnSwitchInput(property, subProperty)) ? ErrorCode::NO_ERROR :
100                                                                     ErrorCode::ERROR_EX_PARCELABLE;
101 }
102 
OnPanelStatusChangeOnRemote(MessageParcel & data,MessageParcel & reply)103 int32_t InputClientStub::OnPanelStatusChangeOnRemote(MessageParcel &data, MessageParcel &reply)
104 {
105     uint32_t status = 0;
106     ImeWindowInfo info;
107     if (!ITypesUtil::Unmarshal(data, status, info)) {
108         IMSA_HILOGE("read message parcel failed!");
109         return ErrorCode::ERROR_EX_PARCELABLE;
110     }
111     return reply.WriteInt32(OnPanelStatusChange(static_cast<InputWindowStatus>(status), info)) ?
112         ErrorCode::NO_ERROR :
113         ErrorCode::ERROR_EX_PARCELABLE;
114 }
115 
DeactivateClientOnRemote(MessageParcel & data,MessageParcel & reply)116 int32_t InputClientStub::DeactivateClientOnRemote(MessageParcel &data, MessageParcel &reply)
117 {
118     DeactivateClient();
119     return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
120 }
121 
NotifyInputStartOnRemote(MessageParcel & data,MessageParcel & reply)122 int32_t InputClientStub::NotifyInputStartOnRemote(MessageParcel &data, MessageParcel &reply)
123 {
124     uint32_t callingWndId = 0;
125     int32_t requestKeyboardReason = 0;
126     if (!ITypesUtil::Unmarshal(data, callingWndId, requestKeyboardReason)) {
127         IMSA_HILOGE("read message parcel failed!");
128         return ErrorCode::ERROR_EX_PARCELABLE;
129     }
130     return reply.WriteInt32(NotifyInputStart(callingWndId, requestKeyboardReason)) ? ErrorCode::NO_ERROR
131                                                                                    : ErrorCode::ERROR_EX_PARCELABLE;
132 }
133 
NotifyInputStopOnRemote(MessageParcel & data,MessageParcel & reply)134 int32_t InputClientStub::NotifyInputStopOnRemote(MessageParcel &data, MessageParcel &reply)
135 {
136     return reply.WriteInt32(NotifyInputStop()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
137 }
138 
OnInputReady(const sptr<IRemoteObject> & agent,const std::pair<int64_t,std::string> & imeInfo)139 int32_t InputClientStub::OnInputReady(const sptr<IRemoteObject> &agent, const std::pair<int64_t, std::string> &imeInfo)
140 {
141     return ErrorCode::NO_ERROR;
142 }
143 
OnInputStop(bool isStopInactiveClient,bool isAsync)144 int32_t InputClientStub::OnInputStop(bool isStopInactiveClient, bool isAsync)
145 {
146     InputMethodController::GetInstance()->OnInputStop(isStopInactiveClient);
147     return ErrorCode::NO_ERROR;
148 }
149 
OnSwitchInput(const Property & property,const SubProperty & subProperty)150 int32_t InputClientStub::OnSwitchInput(const Property &property, const SubProperty &subProperty)
151 {
152     return ImeEventMonitorManagerImpl::GetInstance().OnImeChange(property, subProperty);
153 }
154 
OnPanelStatusChange(const InputWindowStatus & status,const ImeWindowInfo & info)155 int32_t InputClientStub::OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info)
156 {
157     return ImeEventMonitorManagerImpl::GetInstance().OnPanelStatusChange(status, info);
158 }
159 
NotifyInputStart(uint32_t callingWndId,int32_t requestKeyboardReason)160 int32_t InputClientStub::NotifyInputStart(uint32_t callingWndId, int32_t requestKeyboardReason)
161 {
162     return ImeEventMonitorManagerImpl::GetInstance().OnInputStart(callingWndId, requestKeyboardReason);
163 }
164 
NotifyInputStop()165 int32_t InputClientStub::NotifyInputStop()
166 {
167     return ImeEventMonitorManagerImpl::GetInstance().OnInputStop();
168 }
169 
DeactivateClient()170 void InputClientStub::DeactivateClient()
171 {
172     InputMethodController::GetInstance()->DeactivateClient();
173 }
174 } // namespace MiscServices
175 } // namespace OHOS