• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_method_system_ability_stub.h"
17 
18 #include <memory>
19 
20 #include "element_name.h"
21 #include "input_client_proxy.h"
22 #include "input_data_channel_proxy.h"
23 #include "input_method_agent_proxy.h"
24 #include "input_method_core_proxy.h"
25 #include "ipc_skeleton.h"
26 #include "itypes_util.h"
27 #include "os_account_manager.h"
28 
29 namespace OHOS {
30 namespace MiscServices {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t InputMethodSystemAbilityStub::OnRemoteRequest(
32     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
33 {
34     IMSA_HILOGI("IMSA, code = %{public}u, callingPid/Uid: %{public}d/%{public}d", code, IPCSkeleton::GetCallingPid(),
35         IPCSkeleton::GetCallingUid());
36     std::u16string remoteDescriptor = data.ReadInterfaceToken();
37     if (remoteDescriptor != IInputMethodSystemAbility::GetDescriptor()) {
38         IMSA_HILOGE("%{public}s descriptor failed", __func__);
39         return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
40     }
41     if (code >= FIRST_CALL_TRANSACTION && code < static_cast<uint32_t>(InputMethodInterfaceCode::IMS_CMD_LAST)) {
42         return (this->*HANDLERS.at(code))(data, reply);
43     } else {
44         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
45     }
46 }
47 
StartInputOnRemote(MessageParcel & data,MessageParcel & reply)48 int32_t InputMethodSystemAbilityStub::StartInputOnRemote(MessageParcel &data, MessageParcel &reply)
49 {
50     InputClientInfo clientInfo;
51     if (!ITypesUtil::Unmarshal(data, clientInfo)) {
52         IMSA_HILOGE("read clientInfo failed");
53         return ErrorCode::ERROR_EX_PARCELABLE;
54     }
55     sptr<IRemoteObject> agent = nullptr;
56     int32_t ret = StartInput(clientInfo, agent);
57     return reply.WriteInt32(ret) && reply.WriteRemoteObject(agent) ? ErrorCode::NO_ERROR
58                                                                    : ErrorCode::ERROR_EX_PARCELABLE;
59 }
60 
ShowCurrentInputOnRemote(MessageParcel & data,MessageParcel & reply)61 int32_t InputMethodSystemAbilityStub::ShowCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply)
62 {
63     int32_t ret = ShowCurrentInput();
64     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
65 }
66 
HideCurrentInputOnRemote(MessageParcel & data,MessageParcel & reply)67 int32_t InputMethodSystemAbilityStub::HideCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply)
68 {
69     int32_t ret = HideCurrentInput();
70     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
71 }
72 
StopInputSessionOnRemote(MessageParcel & data,MessageParcel & reply)73 int32_t InputMethodSystemAbilityStub::StopInputSessionOnRemote(MessageParcel &data, MessageParcel &reply)
74 {
75     int32_t ret = StopInputSession();
76     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
77 }
78 
ShowInputOnRemote(MessageParcel & data,MessageParcel & reply)79 int32_t InputMethodSystemAbilityStub::ShowInputOnRemote(MessageParcel &data, MessageParcel &reply)
80 {
81     auto clientObject = data.ReadRemoteObject();
82     if (clientObject == nullptr) {
83         IMSA_HILOGE("clientObject is nullptr");
84         return ErrorCode::ERROR_EX_PARCELABLE;
85     }
86     int32_t ret = ShowInput(iface_cast<IInputClient>(clientObject));
87     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
88 }
89 
HideInputOnRemote(MessageParcel & data,MessageParcel & reply)90 int32_t InputMethodSystemAbilityStub::HideInputOnRemote(MessageParcel &data, MessageParcel &reply)
91 {
92     auto clientObject = data.ReadRemoteObject();
93     if (clientObject == nullptr) {
94         IMSA_HILOGE("clientObject is nullptr");
95         return ErrorCode::ERROR_EX_PARCELABLE;
96     }
97     int32_t ret = HideInput(iface_cast<IInputClient>(clientObject));
98     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
99 }
100 
ReleaseInputOnRemote(MessageParcel & data,MessageParcel & reply)101 int32_t InputMethodSystemAbilityStub::ReleaseInputOnRemote(MessageParcel &data, MessageParcel &reply)
102 {
103     auto clientObject = data.ReadRemoteObject();
104     if (clientObject == nullptr) {
105         IMSA_HILOGE("clientObject is nullptr");
106         return ErrorCode::ERROR_EX_PARCELABLE;
107     }
108     int32_t ret = ReleaseInput(iface_cast<IInputClient>(clientObject));
109     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
110 }
111 
RequestShowInputOnRemote(MessageParcel & data,MessageParcel & reply)112 int32_t InputMethodSystemAbilityStub::RequestShowInputOnRemote(MessageParcel &data, MessageParcel &reply)
113 {
114     return reply.WriteInt32(RequestShowInput()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
115 }
116 
RequestHideInputOnRemote(MessageParcel & data,MessageParcel & reply)117 int32_t InputMethodSystemAbilityStub::RequestHideInputOnRemote(MessageParcel &data, MessageParcel &reply)
118 {
119     return reply.WriteInt32(RequestHideInput()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
120 }
121 
DisplayOptionalInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)122 int32_t InputMethodSystemAbilityStub::DisplayOptionalInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
123 {
124     int32_t ret = DisplayOptionalInputMethod();
125     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
126 }
127 
SetCoreAndAgentOnRemote(MessageParcel & data,MessageParcel & reply)128 int32_t InputMethodSystemAbilityStub::SetCoreAndAgentOnRemote(MessageParcel &data, MessageParcel &reply)
129 {
130     auto coreObject = data.ReadRemoteObject();
131     if (coreObject == nullptr) {
132         IMSA_HILOGE("coreObject is nullptr");
133         return ErrorCode::ERROR_EX_PARCELABLE;
134     }
135     auto agentObject = data.ReadRemoteObject();
136     if (agentObject == nullptr) {
137         IMSA_HILOGE("agentObject is nullptr");
138         return ErrorCode::ERROR_EX_PARCELABLE;
139     }
140     int32_t ret = SetCoreAndAgent(iface_cast<IInputMethodCore>(coreObject), iface_cast<IInputMethodAgent>(agentObject));
141     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
142 }
143 
GetDefaultInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)144 int32_t InputMethodSystemAbilityStub::GetDefaultInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
145 {
146     std::shared_ptr<Property> prop = std::make_shared<Property>();
147     auto ret = GetDefaultInputMethod(prop);
148     return ITypesUtil::Marshal(reply, ret, *prop) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
149 }
150 
GetInputMethodConfigOnRemote(MessageParcel & data,MessageParcel & reply)151 int32_t InputMethodSystemAbilityStub::GetInputMethodConfigOnRemote(MessageParcel &data, MessageParcel &reply)
152 {
153     OHOS::AppExecFwk::ElementName inputMethodConfig;
154     auto ret = GetInputMethodConfig(inputMethodConfig);
155     IMSA_HILOGD("GetInputMethodConfigOnRemote inputMethodConfig is %{public}s, %{public}s ",
156         inputMethodConfig.GetBundleName().c_str(), inputMethodConfig.GetAbilityName().c_str());
157     return ITypesUtil::Marshal(reply, ret, inputMethodConfig) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
158 }
159 
GetSecurityModeOnRemote(MessageParcel & data,MessageParcel & reply)160 int32_t InputMethodSystemAbilityStub::GetSecurityModeOnRemote(MessageParcel &data, MessageParcel &reply)
161 {
162     IMSA_HILOGD("GetSecurityModeOnRemote");
163     int32_t security;
164     auto ret = GetSecurityMode(security);
165     IMSA_HILOGD("GetSecurityModeOnRemote, security = %{public}d", security);
166     return ITypesUtil::Marshal(reply, ret, security) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
167 }
168 
GetCurrentInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)169 int32_t InputMethodSystemAbilityStub::GetCurrentInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
170 {
171     auto property = GetCurrentInputMethod();
172     if (property == nullptr) {
173         IMSA_HILOGE("property is nullptr");
174         return reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER) ? ErrorCode::NO_ERROR
175                                                                   : ErrorCode::ERROR_EX_PARCELABLE;
176     }
177     if (!ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, *property)) {
178         IMSA_HILOGE("Marshal failed");
179         return ErrorCode::ERROR_EX_PARCELABLE;
180     }
181     return ErrorCode::NO_ERROR;
182 }
183 
GetCurrentInputMethodSubtypeOnRemote(MessageParcel & data,MessageParcel & reply)184 int32_t InputMethodSystemAbilityStub::GetCurrentInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
185 {
186     auto property = GetCurrentInputMethodSubtype();
187     if (property == nullptr) {
188         IMSA_HILOGE("property is nullptr");
189         return reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER) ? ErrorCode::NO_ERROR
190                                                                   : ErrorCode::ERROR_EX_PARCELABLE;
191     }
192     if (!ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, *property)) {
193         IMSA_HILOGE("Marshal failed");
194         return ErrorCode::ERROR_EX_PARCELABLE;
195     }
196     return ErrorCode::NO_ERROR;
197 }
198 
ListInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)199 int32_t InputMethodSystemAbilityStub::ListInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
200 {
201     uint32_t status;
202     if (!ITypesUtil::Unmarshal(data, status)) {
203         IMSA_HILOGE("read status failed");
204         return ErrorCode::ERROR_EX_PARCELABLE;
205     }
206     std::vector<Property> properties = {};
207     auto ret = ListInputMethod(InputMethodStatus(status), properties);
208     if (!ITypesUtil::Marshal(reply, ret, properties)) {
209         IMSA_HILOGE("Marshal failed");
210         return ErrorCode::ERROR_EX_PARCELABLE;
211     }
212     return ErrorCode::NO_ERROR;
213 }
214 
ListInputMethodSubtypeOnRemote(MessageParcel & data,MessageParcel & reply)215 int32_t InputMethodSystemAbilityStub::ListInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
216 {
217     std::string bundleName;
218     if (!ITypesUtil::Unmarshal(data, bundleName)) {
219         IMSA_HILOGE("read bundleName failed");
220         return ErrorCode::ERROR_EX_PARCELABLE;
221     }
222     std::vector<SubProperty> subProps = {};
223     auto ret = ListInputMethodSubtype(bundleName, subProps);
224     if (!ITypesUtil::Marshal(reply, ret, subProps)) {
225         IMSA_HILOGE("Marshal failed");
226         return ErrorCode::ERROR_EX_PARCELABLE;
227     }
228     return ErrorCode::NO_ERROR;
229 }
230 
ListCurrentInputMethodSubtypeOnRemote(MessageParcel & data,MessageParcel & reply)231 int32_t InputMethodSystemAbilityStub::ListCurrentInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
232 {
233     std::vector<SubProperty> subProps = {};
234     auto ret = ListCurrentInputMethodSubtype(subProps);
235     if (!ITypesUtil::Marshal(reply, ret, subProps)) {
236         IMSA_HILOGE("Marshal failed");
237         return ErrorCode::ERROR_EX_PARCELABLE;
238     }
239     return ErrorCode::NO_ERROR;
240 }
241 
SwitchInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)242 int32_t InputMethodSystemAbilityStub::SwitchInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
243 {
244     std::string name;
245     std::string subName;
246     SwitchTrigger trigger;
247     if (!ITypesUtil::Unmarshal(data, name, subName, trigger)) {
248         IMSA_HILOGE("Unmarshal failed");
249         return ErrorCode::ERROR_EX_PARCELABLE;
250     }
251     return reply.WriteInt32(SwitchInputMethod(name, subName, trigger)) ? ErrorCode::NO_ERROR
252                                                                        : ErrorCode::ERROR_EX_PARCELABLE;
253 }
254 
PanelStatusChangeOnRemote(MessageParcel & data,MessageParcel & reply)255 int32_t InputMethodSystemAbilityStub::PanelStatusChangeOnRemote(MessageParcel &data, MessageParcel &reply)
256 {
257     uint32_t status;
258     InputWindowInfo windowInfo;
259     if (!ITypesUtil::Unmarshal(data, status, windowInfo)) {
260         IMSA_HILOGE("Unmarshal failed");
261         return ErrorCode::ERROR_EX_PARCELABLE;
262     }
263     int32_t ret = PanelStatusChange(static_cast<InputWindowStatus>(status), windowInfo);
264     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
265 }
266 
UpdateListenEventFlagOnRemote(MessageParcel & data,MessageParcel & reply)267 int32_t InputMethodSystemAbilityStub::UpdateListenEventFlagOnRemote(MessageParcel &data, MessageParcel &reply)
268 {
269     InputClientInfo clientInfo;
270     EventType type;
271     if (!ITypesUtil::Unmarshal(data, clientInfo, type)) {
272         IMSA_HILOGE("Unmarshal failed");
273         return ErrorCode::ERROR_EX_PARCELABLE;
274     }
275     int32_t ret = UpdateListenEventFlag(clientInfo, type);
276     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
277 }
278 
ShowCurrentInputOnRemoteDeprecated(MessageParcel & data,MessageParcel & reply)279 int32_t InputMethodSystemAbilityStub::ShowCurrentInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply)
280 {
281     int32_t ret = ShowCurrentInputDeprecated();
282     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
283 }
284 
HideCurrentInputOnRemoteDeprecated(MessageParcel & data,MessageParcel & reply)285 int32_t InputMethodSystemAbilityStub::HideCurrentInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply)
286 {
287     int32_t ret = HideCurrentInputDeprecated();
288     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
289 }
290 
IsCurrentImeOnRemote(MessageParcel & data,MessageParcel & reply)291 int32_t InputMethodSystemAbilityStub::IsCurrentImeOnRemote(MessageParcel &data, MessageParcel &reply)
292 {
293     return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsCurrentIme()) ? ErrorCode::NO_ERROR
294                                                                            : ErrorCode::ERROR_EX_PARCELABLE;
295 }
296 
UnRegisteredProxyImeOnRemote(MessageParcel & data,MessageParcel & reply)297 int32_t InputMethodSystemAbilityStub::UnRegisteredProxyImeOnRemote(MessageParcel &data, MessageParcel &reply)
298 {
299     int32_t type = -1;
300     sptr<IRemoteObject> coreObject = nullptr;
301     if (!ITypesUtil::Unmarshal(data, type, coreObject) || coreObject == nullptr) {
302         IMSA_HILOGE("coreObject is nullptr");
303         return ErrorCode::ERROR_EX_PARCELABLE;
304     }
305     int32_t ret = UnRegisteredProxyIme(static_cast<UnRegisteredType>(type), iface_cast<IInputMethodCore>(coreObject));
306     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
307 }
308 
IsInputTypeSupportedOnRemote(MessageParcel & data,MessageParcel & reply)309 int32_t InputMethodSystemAbilityStub::IsInputTypeSupportedOnRemote(MessageParcel &data, MessageParcel &reply)
310 {
311     InputType type;
312     if (!ITypesUtil::Unmarshal(data, type)) {
313         IMSA_HILOGE("unmarshal failed");
314         return ErrorCode::ERROR_EX_PARCELABLE;
315     }
316     return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsInputTypeSupported(type)) ? ErrorCode::NO_ERROR
317                                                                                        : ErrorCode::ERROR_EX_PARCELABLE;
318 }
319 
StartInputTypeOnRemote(MessageParcel & data,MessageParcel & reply)320 int32_t InputMethodSystemAbilityStub::StartInputTypeOnRemote(MessageParcel &data, MessageParcel &reply)
321 {
322     InputType type;
323     if (!ITypesUtil::Unmarshal(data, type)) {
324         IMSA_HILOGE("unmarshal failed");
325         return ErrorCode::ERROR_EX_PARCELABLE;
326     }
327     return ITypesUtil::Marshal(reply, StartInputType(type)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
328 }
329 
ExitCurrentInputTypeOnRemote(MessageParcel & data,MessageParcel & reply)330 int32_t InputMethodSystemAbilityStub::ExitCurrentInputTypeOnRemote(MessageParcel &data, MessageParcel &reply)
331 {
332     return ITypesUtil::Marshal(reply, ExitCurrentInputType()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
333 }
334 
IsPanelShownOnRemote(MessageParcel & data,MessageParcel & reply)335 int32_t InputMethodSystemAbilityStub::IsPanelShownOnRemote(MessageParcel &data, MessageParcel &reply)
336 {
337     PanelInfo info;
338     if (!ITypesUtil::Unmarshal(data, info)) {
339         IMSA_HILOGE("unmarshal failed");
340         return ErrorCode::ERROR_EX_PARCELABLE;
341     }
342     bool isShown = false;
343     int32_t ret = IsPanelShown(info, isShown);
344     return ITypesUtil::Marshal(reply, ret, isShown) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
345 }
346 } // namespace MiscServices
347 } // namespace OHOS
348