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_control_channel_stub.h"
17
18 #include "ipc_skeleton.h"
19 #include "inputmethod_message_handler.h"
20 #include "os_account_adapter.h"
21
22 namespace OHOS {
23 namespace MiscServices {
InputControlChannelStub(int32_t userId)24 InputControlChannelStub::InputControlChannelStub(int32_t userId)
25 {
26 userId_ = userId;
27 }
28
~InputControlChannelStub()29 InputControlChannelStub::~InputControlChannelStub()
30 {
31 }
32
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int32_t InputControlChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
34 MessageOption &option)
35 {
36 IMSA_HILOGD("InputControlChannelStub, 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 HIDE_KEYBOARD_SELF: {
44 reply.WriteInt32(HideKeyboardSelf());
45 break;
46 }
47 default: {
48 return IRemoteStub::OnRemoteRequest(code, data, reply, option);
49 }
50 }
51 return NO_ERROR;
52 }
53
HideKeyboardSelf()54 int32_t InputControlChannelStub::HideKeyboardSelf()
55 {
56 auto userId = OsAccountAdapter::GetOsAccountLocalIdFromUid(IPCSkeleton::GetCallingUid());
57 if (userId == OsAccountAdapter::INVALID_USER_ID) {
58 return ErrorCode::ERROR_EX_ILLEGAL_STATE;
59 }
60 MessageParcel *parcel = new (std::nothrow) MessageParcel();
61 if (parcel == nullptr) {
62 return ErrorCode::ERROR_NULL_POINTER;
63 }
64 parcel->WriteInt32(userId);
65 Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_HIDE_KEYBOARD_SELF, parcel);
66 if (msg == nullptr) {
67 delete parcel;
68 return ErrorCode::ERROR_NULL_POINTER;
69 }
70 MessageHandler::Instance()->SendMessage(msg);
71 return ErrorCode::NO_ERROR;
72 }
73 } // namespace MiscServices
74 } // namespace OHOS