• 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 <utils.h>
19 
20 #include <memory>
21 
22 #include "ipc_skeleton.h"
23 #include "itypes_util.h"
24 
25 namespace OHOS {
26 namespace MiscServices {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int32_t InputMethodSystemAbilityStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
28     MessageOption &option)
29 {
30     IMSA_HILOGE("code:%{public}u, callingPid:%{public}d", code, IPCSkeleton::GetCallingPid());
31     std::u16string remoteDescriptor = data.ReadInterfaceToken();
32     if (remoteDescriptor != IInputMethodSystemAbility::GetDescriptor()) {
33         IMSA_HILOGE("%{public}s descriptor failed", __func__);
34         return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
35     }
36     if (code >= 0 && code < INPUT_SERVICE_CMD_LAST) {
37         return (this->*HANDLERS[code])(data, reply);
38     } else {
39         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
40     }
41 }
42 
PrepareInputOnRemote(MessageParcel & data,MessageParcel & reply)43 int32_t InputMethodSystemAbilityStub::PrepareInputOnRemote(MessageParcel &data, MessageParcel &reply)
44 {
45     int32_t displayId = data.ReadInt32();
46     auto clientObject = data.ReadRemoteObject();
47     if (clientObject == nullptr) {
48         reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER);
49         IMSA_HILOGE("%{public}s nullptr", __func__);
50         return ErrorCode::ERROR_EX_NULL_POINTER;
51     }
52     auto channelObject = data.ReadRemoteObject();
53     if (channelObject == nullptr) {
54         reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER);
55         IMSA_HILOGE("%{public}s nullptr", __func__);
56         return ErrorCode::ERROR_EX_NULL_POINTER;
57     }
58     InputAttribute attribute;
59     if (!InputAttribute::Unmarshalling(attribute, data)) {
60         reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT);
61         IMSA_HILOGE("%{public}s illegal argument", __func__);
62         return ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT;
63     }
64     int32_t ret = PrepareInput(displayId, iface_cast<IInputClient>(clientObject),
65         iface_cast<IInputDataChannel>(channelObject), attribute);
66     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
67 }
68 
StartInputOnRemote(MessageParcel & data,MessageParcel & reply)69 int32_t InputMethodSystemAbilityStub::StartInputOnRemote(MessageParcel &data, MessageParcel &reply)
70 {
71     auto clientObject = data.ReadRemoteObject();
72     if (clientObject == nullptr) {
73         reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER);
74         IMSA_HILOGE("%{public}s nullptr", __func__);
75         return ErrorCode::ERROR_EX_NULL_POINTER;
76     }
77     bool isShowKeyboard = data.ReadBool();
78     int32_t ret = StartInput(iface_cast<IInputClient>(clientObject), isShowKeyboard);
79     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
80 }
81 
ShowCurrentInputOnRemote(MessageParcel & data,MessageParcel & reply)82 int32_t InputMethodSystemAbilityStub::ShowCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply)
83 {
84     int32_t ret = ShowCurrentInput();
85     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
86 }
87 
HideCurrentInputOnRemote(MessageParcel & data,MessageParcel & reply)88 int32_t InputMethodSystemAbilityStub::HideCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply)
89 {
90     int32_t ret = HideCurrentInput();
91     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
92 }
93 
StopInputSessionOnRemote(MessageParcel & data,MessageParcel & reply)94 int32_t InputMethodSystemAbilityStub::StopInputSessionOnRemote(MessageParcel &data, MessageParcel &reply)
95 {
96     int32_t ret = StopInputSession();
97     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
98 }
99 
StopInputOnRemote(MessageParcel & data,MessageParcel & reply)100 int32_t InputMethodSystemAbilityStub::StopInputOnRemote(MessageParcel &data, MessageParcel &reply)
101 {
102     auto clientObject = data.ReadRemoteObject();
103     if (clientObject == nullptr) {
104         reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER);
105         IMSA_HILOGE("%{public}s nullptr", __func__);
106         return ErrorCode::ERROR_EX_NULL_POINTER;
107     }
108     int32_t ret = StopInput(iface_cast<IInputClient>(clientObject));
109     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
110 }
111 
ReleaseInputOnRemote(MessageParcel & data,MessageParcel & reply)112 int32_t InputMethodSystemAbilityStub::ReleaseInputOnRemote(MessageParcel &data, MessageParcel &reply)
113 {
114     auto clientObject = data.ReadRemoteObject();
115     if (clientObject == nullptr) {
116         reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER);
117         IMSA_HILOGE("%{public}s nullptr", __func__);
118         return ErrorCode::ERROR_EX_NULL_POINTER;
119     }
120     int32_t ret = ReleaseInput(iface_cast<IInputClient>(clientObject));
121     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
122 }
123 
DisplayOptionalInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)124 int32_t InputMethodSystemAbilityStub::DisplayOptionalInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
125 {
126     int32_t ret = DisplayOptionalInputMethod();
127     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
128 }
129 
SetCoreAndAgentOnRemote(MessageParcel & data,MessageParcel & reply)130 int32_t InputMethodSystemAbilityStub::SetCoreAndAgentOnRemote(MessageParcel &data, MessageParcel &reply)
131 {
132     auto coreObject = data.ReadRemoteObject();
133     if (coreObject == nullptr) {
134         reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER);
135         IMSA_HILOGE("%{public}s nullptr", __func__);
136         return ErrorCode::ERROR_EX_NULL_POINTER;
137     }
138     auto agentObject = data.ReadRemoteObject();
139     if (agentObject == nullptr) {
140         reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER);
141         IMSA_HILOGE("%{public}s nullptr", __func__);
142         return ErrorCode::ERROR_EX_NULL_POINTER;
143     }
144     int32_t ret = SetCoreAndAgent(iface_cast<IInputMethodCore>(coreObject), iface_cast<IInputMethodAgent>(agentObject));
145     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
146 }
147 
GetCurrentInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)148 int32_t InputMethodSystemAbilityStub::GetCurrentInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
149 {
150     auto property = GetCurrentInputMethod();
151     if (property == nullptr) {
152         reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER);
153         IMSA_HILOGE("%{public}s property is nullptr", __func__);
154         return ErrorCode::ERROR_EX_NULL_POINTER;
155     }
156     if (!ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, *property, ErrorCode::ERROR_EX_PARCELABLE)) {
157         IMSA_HILOGE("%{public}s parcel failed", __func__);
158         return ErrorCode::ERROR_EX_PARCELABLE;
159     }
160     return ErrorCode::NO_ERROR;
161 }
162 
GetCurrentInputMethodSubtypeOnRemote(MessageParcel & data,MessageParcel & reply)163 int32_t InputMethodSystemAbilityStub::GetCurrentInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
164 {
165     auto property = GetCurrentInputMethodSubtype();
166     if (property == nullptr) {
167         reply.WriteInt32(ErrorCode::ERROR_EX_NULL_POINTER);
168         IMSA_HILOGE("%{public}s property is nullptr", __func__);
169         return ErrorCode::ERROR_EX_NULL_POINTER;
170     }
171     if (!ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, *property, ErrorCode::ERROR_EX_PARCELABLE)) {
172         IMSA_HILOGE("%{public}s parcel failed", __func__);
173         return ErrorCode::ERROR_EX_PARCELABLE;
174     }
175     return ErrorCode::NO_ERROR;
176 }
177 
ListInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)178 int32_t InputMethodSystemAbilityStub::ListInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
179 {
180     uint32_t status;
181     if (!ITypesUtil::Unmarshal(data, status)) {
182         IMSA_HILOGE("read status failed");
183     }
184     std::vector<Property> properties = {};
185     auto ret = ListInputMethod(InputMethodStatus(status), properties);
186     if (ret != ErrorCode::NO_ERROR) {
187         IMSA_HILOGE("ListInputMethod failed");
188         return ret;
189     }
190     if (!ITypesUtil::Marshal(reply, ret, properties)) {
191         IMSA_HILOGE("write reply failed");
192         return ErrorCode::ERROR_EX_PARCELABLE;
193     }
194     return ret;
195 }
196 
ListInputMethodSubtypeOnRemote(MessageParcel & data,MessageParcel & reply)197 int32_t InputMethodSystemAbilityStub::ListInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
198 {
199     std::string bundleName;
200     if (!ITypesUtil::Unmarshal(data, bundleName)) {
201         IMSA_HILOGE("InputMethodSystemAbilityStub::read bundleName failed");
202         return ErrorCode::ERROR_EX_PARCELABLE;
203     }
204     std::vector<SubProperty> subProps = {};
205     auto ret = ListInputMethodSubtype(bundleName, subProps);
206     if (ret != ErrorCode::NO_ERROR) {
207         IMSA_HILOGE("ListInputMethodSubtype failed");
208         return ret;
209     }
210     if (!ITypesUtil::Marshal(reply, ret, subProps)) {
211         IMSA_HILOGE("InputMethodSystemAbilityStub::write reply failed");
212         return ErrorCode::ERROR_EX_PARCELABLE;
213     }
214     return ret;
215 }
216 
ListCurrentInputMethodSubtypeOnRemote(MessageParcel & data,MessageParcel & reply)217 int32_t InputMethodSystemAbilityStub::ListCurrentInputMethodSubtypeOnRemote(MessageParcel &data, MessageParcel &reply)
218 {
219     std::vector<SubProperty> subProps = {};
220     auto ret = ListCurrentInputMethodSubtype(subProps);
221     if (ret != ErrorCode::NO_ERROR) {
222         IMSA_HILOGE("ListCurrentInputMethodSubtype failed");
223         return ret;
224     }
225     if (!ITypesUtil::Marshal(reply, ret, subProps)) {
226         IMSA_HILOGE("InputMethodSystemAbilityStub::write reply failed");
227         return ErrorCode::ERROR_EX_PARCELABLE;
228     }
229     return ret;
230 }
231 
SwitchInputMethodOnRemote(MessageParcel & data,MessageParcel & reply)232 int32_t InputMethodSystemAbilityStub::SwitchInputMethodOnRemote(MessageParcel &data, MessageParcel &reply)
233 {
234     std::string name;
235     std::string subName;
236     if (!ITypesUtil::Unmarshal(data, name, subName)) {
237         reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT);
238         IMSA_HILOGE("%{public}s parcel failed", __func__);
239         return ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT;
240     }
241     int32_t ret = SwitchInputMethod(name, subName);
242     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
243 }
244 
ShowCurrentInputOnRemoteDeprecated(MessageParcel & data,MessageParcel & reply)245 int32_t InputMethodSystemAbilityStub::ShowCurrentInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply)
246 {
247     int32_t ret = ShowCurrentInputDeprecated();
248     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
249 }
250 
HideCurrentInputOnRemoteDeprecated(MessageParcel & data,MessageParcel & reply)251 int32_t InputMethodSystemAbilityStub::HideCurrentInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply)
252 {
253     int32_t ret = HideCurrentInputDeprecated();
254     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
255 }
256 
DisplayInputOnRemoteDeprecated(MessageParcel & data,MessageParcel & reply)257 int32_t InputMethodSystemAbilityStub::DisplayInputOnRemoteDeprecated(MessageParcel &data, MessageParcel &reply)
258 {
259     int32_t ret = DisplayOptionalInputMethodDeprecated();
260     return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
261 }
262 } // namespace MiscServices
263 } // namespace OHOS
264