122736c2fSopenharmony_ci/*
222736c2fSopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
322736c2fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
422736c2fSopenharmony_ci * you may not use this file except in compliance with the License.
522736c2fSopenharmony_ci * You may obtain a copy of the License at
622736c2fSopenharmony_ci *
722736c2fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
822736c2fSopenharmony_ci *
922736c2fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1022736c2fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1122736c2fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1222736c2fSopenharmony_ci * See the License for the specific language governing permissions and
1322736c2fSopenharmony_ci * limitations under the License.
1422736c2fSopenharmony_ci  */
1522736c2fSopenharmony_ci
1622736c2fSopenharmony_ci#include "input_control_channel_stub.h"
1722736c2fSopenharmony_ci
1822736c2fSopenharmony_ci#include "ipc_skeleton.h"
1922736c2fSopenharmony_ci#include "message_handler.h"
2022736c2fSopenharmony_ci#include "message_parcel.h"
2122736c2fSopenharmony_ci#include "os_account_adapter.h"
2222736c2fSopenharmony_ci
2322736c2fSopenharmony_cinamespace OHOS {
2422736c2fSopenharmony_cinamespace MiscServices {
2522736c2fSopenharmony_ciInputControlChannelStub::InputControlChannelStub(int32_t userId)
2622736c2fSopenharmony_ci{
2722736c2fSopenharmony_ci    userId_ = userId;
2822736c2fSopenharmony_ci}
2922736c2fSopenharmony_ci
3022736c2fSopenharmony_ciInputControlChannelStub::~InputControlChannelStub()
3122736c2fSopenharmony_ci{
3222736c2fSopenharmony_ci}
3322736c2fSopenharmony_ci
3422736c2fSopenharmony_ciint32_t InputControlChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
3522736c2fSopenharmony_ci    MessageOption &option)
3622736c2fSopenharmony_ci{
3722736c2fSopenharmony_ci    IMSA_HILOGD("InputControlChannelStub, code = %{public}u, callingPid: %{public}d, callingUid: %{public}d.", code,
3822736c2fSopenharmony_ci        IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
3922736c2fSopenharmony_ci    auto descriptorToken = data.ReadInterfaceToken();
4022736c2fSopenharmony_ci    if (descriptorToken != GetDescriptor()) {
4122736c2fSopenharmony_ci        return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
4222736c2fSopenharmony_ci    }
4322736c2fSopenharmony_ci    switch (code) {
4422736c2fSopenharmony_ci        case HIDE_KEYBOARD_SELF: {
4522736c2fSopenharmony_ci            reply.WriteInt32(HideKeyboardSelf());
4622736c2fSopenharmony_ci            break;
4722736c2fSopenharmony_ci        }
4822736c2fSopenharmony_ci        default: {
4922736c2fSopenharmony_ci            return IRemoteStub::OnRemoteRequest(code, data, reply, option);
5022736c2fSopenharmony_ci        }
5122736c2fSopenharmony_ci    }
5222736c2fSopenharmony_ci    return NO_ERROR;
5322736c2fSopenharmony_ci}
5422736c2fSopenharmony_ci
5522736c2fSopenharmony_ciint32_t InputControlChannelStub::HideKeyboardSelf()
5622736c2fSopenharmony_ci{
5722736c2fSopenharmony_ci    auto userId = OsAccountAdapter::GetOsAccountLocalIdFromUid(IPCSkeleton::GetCallingUid());
5822736c2fSopenharmony_ci    if (userId == OsAccountAdapter::INVALID_USER_ID) {
5922736c2fSopenharmony_ci        return ErrorCode::ERROR_EX_ILLEGAL_STATE;
6022736c2fSopenharmony_ci    }
6122736c2fSopenharmony_ci    MessageParcel *parcel = new (std::nothrow) MessageParcel();
6222736c2fSopenharmony_ci    if (parcel == nullptr) {
6322736c2fSopenharmony_ci        return ErrorCode::ERROR_NULL_POINTER;
6422736c2fSopenharmony_ci    }
6522736c2fSopenharmony_ci    parcel->WriteInt32(userId);
6622736c2fSopenharmony_ci    Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_HIDE_KEYBOARD_SELF, parcel);
6722736c2fSopenharmony_ci    if (msg == nullptr) {
6822736c2fSopenharmony_ci        delete parcel;
6922736c2fSopenharmony_ci        return ErrorCode::ERROR_NULL_POINTER;
7022736c2fSopenharmony_ci    }
7122736c2fSopenharmony_ci    MessageHandler::Instance()->SendMessage(msg);
7222736c2fSopenharmony_ci    return ErrorCode::NO_ERROR;
7322736c2fSopenharmony_ci}
7422736c2fSopenharmony_ci} // namespace MiscServices
7522736c2fSopenharmony_ci} // namespace OHOS