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