/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "distributed_input_source_stub.h" #include "accesstoken_kit.h" #include "constants_dinput.h" #include "dinput_errcode.h" #include "dinput_ipc_interface_code.h" #include "dinput_log.h" #include "ipc_skeleton.h" namespace OHOS { namespace DistributedHardware { namespace DistributedInput { DistributedInputSourceStub::DistributedInputSourceStub() { } DistributedInputSourceStub::~DistributedInputSourceStub() { } bool DistributedInputSourceStub::HasEnableDHPermission() { Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); const std::string permissionName = "ohos.permission.ENABLE_DISTRIBUTED_HARDWARE"; int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, permissionName); return (result == Security::AccessToken::PERMISSION_GRANTED); } bool DistributedInputSourceStub::HasAccessDHPermission() { Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); const std::string permissionName = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, permissionName); return (result == Security::AccessToken::PERMISSION_GRANTED); } int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel &reply) { if (!HasEnableDHPermission()) { DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ENABLE_PERMISSION_CHECK_FAIL; } std::unique_lock lock(operatorMutex_); if (sourceManagerInitFlag_.load()) { DHLOGE("DistributedInputSourceStub already init."); return DH_SUCCESS; } int32_t ret = Init(); if (!reply.WriteInt32(ret)) { DHLOGE("DistributedInputSourceStub Init write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } sourceManagerInitFlag_.store(true); return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleReleaseDistributedHardware(MessageParcel &reply) { if (!HasEnableDHPermission()) { DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ENABLE_PERMISSION_CHECK_FAIL; } std::unique_lock lock(operatorMutex_); if (!sourceManagerInitFlag_.load()) { DHLOGE("DistributedInputSourceStub already Release."); return DH_SUCCESS; } int32_t ret = Release(); if (!reply.WriteInt32(ret)) { DHLOGE("DistributedInputSourceStub release write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } sourceManagerInitFlag_.store(false); return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleRegisterDistributedHardware(MessageParcel &data, MessageParcel &reply) { if (!HasEnableDHPermission()) { DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ENABLE_PERMISSION_CHECK_FAIL; } std::string devId = data.ReadString(); std::string dhId = data.ReadString(); std::string params = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleRegisterDistributedHardware failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = RegisterDistributedHardware(devId, dhId, params, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleRegisterDistributedHardware write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleUnregisterDistributedHardware(MessageParcel &data, MessageParcel &reply) { if (!HasEnableDHPermission()) { DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ENABLE_PERMISSION_CHECK_FAIL; } std::string devId = data.ReadString(); std::string dhId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleUnregisterDistributedHardware failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = UnregisterDistributedHardware(devId, dhId, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleUnregisterDistributedHardware write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string deviceId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandlePrepareRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = PrepareRemoteInput(deviceId, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandlePrepareRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleUnprepareRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string deviceId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleUnprepareRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = UnprepareRemoteInput(deviceId, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleUnprepareRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleStartRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string deviceId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleStartRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = StartRemoteInput(deviceId, inputTypes, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStartRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleStopRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string deviceId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleStopRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = StopRemoteInput(deviceId, inputTypes, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStopRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleStartRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleStartRelayTypeRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = StartRemoteInput(srcId, sinkId, inputTypes, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStartRelayTypeRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleStopRelayTypeRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleStopRelayTypeRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = StopRemoteInput(srcId, sinkId, inputTypes, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStopRelayTypeRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandlePrepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandlePrepareRelayRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = PrepareRemoteInput(srcId, sinkId, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandlePrepareRelayRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleUnprepareRelayRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleUnprepareRelayRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = UnprepareRemoteInput(srcId, sinkId, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleUnprepareRelayRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleStartDhidRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string sinkId = data.ReadString(); std::vector tempVector; uint32_t vecSize = data.ReadUint32(); if (vecSize > IPC_VECTOR_MAX_SIZE) { DHLOGE("HandleStartDhidRemoteInput vecSize too large"); return ERR_DH_INPUT_IPC_READ_VALID_FAIL; } for (uint32_t i = 0; i < vecSize; i++) { std::string dhid = data.ReadString(); if (dhid.empty()) { DHLOGE("HandleStartDhidRemoteInput dhid is empty"); continue; } tempVector.push_back(dhid); } sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleStartDhidRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = StartRemoteInput(sinkId, tempVector, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStartDhidRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleStopDhidRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string sinkId = data.ReadString(); std::vector tempVector; uint32_t vecSize = data.ReadUint32(); if (vecSize > IPC_VECTOR_MAX_SIZE) { DHLOGE("HandleStopDhidRemoteInput vecSize too large"); return ERR_DH_INPUT_IPC_READ_VALID_FAIL; } for (uint32_t i = 0; i < vecSize; i++) { std::string dhid = data.ReadString(); if (dhid.empty()) { DHLOGE("HandleStopDhidRemoteInput dhid is empty"); continue; } tempVector.push_back(dhid); } sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleStopDhidRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = StopRemoteInput(sinkId, tempVector, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStopDhidRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleStartRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); std::vector tempVector; uint32_t vecSize = data.ReadUint32(); if (vecSize > IPC_VECTOR_MAX_SIZE) { DHLOGE("HandleStartRelayDhidRemoteInput vecSize too large"); return ERR_DH_INPUT_IPC_READ_VALID_FAIL; } for (uint32_t i = 0; i < vecSize; i++) { std::string dhid = data.ReadString(); if (dhid.empty()) { DHLOGE("HandleStartRelayDhidRemoteInput dhid is empty"); continue; } tempVector.push_back(dhid); } sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleStartRelayDhidRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = StartRemoteInput(srcId, sinkId, tempVector, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStartRelayDhidRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleStopRelayDhidRemoteInput(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); std::vector tempVector; uint32_t vecSize = data.ReadUint32(); if (vecSize > IPC_VECTOR_MAX_SIZE) { DHLOGE("HandleStopRelayDhidRemoteInput vecSize too large"); return ERR_DH_INPUT_IPC_READ_VALID_FAIL; } for (uint32_t i = 0; i < vecSize; i++) { std::string dhid = data.ReadString(); if (dhid.empty()) { DHLOGE("HandleStopRelayDhidRemoteInput dhid is empty"); continue; } tempVector.push_back(dhid); } sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleStopRelayDhidRemoteInput failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = StopRemoteInput(srcId, sinkId, tempVector, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStopRelayDhidRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleRegisterAddWhiteListCallback(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleRegisterAddWhiteListCallback failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = RegisterAddWhiteListCallback(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleRegisterAddWhiteListCallback write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleRegisterDelWhiteListCallback(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleRegisterDelWhiteListCallback failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = RegisterDelWhiteListCallback(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleRegisterDelWhiteListCallback write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleRegisterSimulationEventListener(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleRegisterSimulationEventListener failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = RegisterSimulationEventListener(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleRegisterSimulationEventListener write ret failed, ret = %{public}d", ret); return ERR_DH_INPUT_SOURCE_STUB_REGISTER_SIMULATION_EVENT_LISTENER_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleUnregisterSimulationEventListener failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = UnregisterSimulationEventListener(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleUnregisterSimulationEventListener write ret failed, ret = %{public}d", ret); return ERR_DH_INPUT_SOURCE_STUB_UNREGISTER_SIMULATION_EVENT_LISTENER_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleRegisterSessionStateCb(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { DHLOGE("HandleRegisterSessionStateCb failed, callback is nullptr."); return ERR_DH_INPUT_POINTER_NULL; } int32_t ret = RegisterSessionStateCb(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleRegisterSessionStateCb write ret failed, ret = %{public}d", ret); return ERR_DH_INPUT_SRC_STUB_REGISTER_SESSION_STATE_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleUnregisterSessionStateCb(MessageParcel &data, MessageParcel &reply) { if (!HasAccessDHPermission()) { DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); return ERR_DH_INPUT_SRC_ACCESS_PERMISSION_CHECK_FAIL; } int32_t ret = UnregisterSessionStateCb(); if (!reply.WriteInt32(ret)) { DHLOGE("HandleUnregisterSessionStateCb write ret failed, ret = %{public}d", ret); return ERR_DH_INPUT_SRC_STUB_UNREGISTER_SESSION_STATE_FAIL; } return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { switch (code) { case static_cast(IDInputSourceInterfaceCode::START_RELAY_DHID_REMOTE_INPUT): return HandleStartRelayDhidRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::STOP_RELAY_DHID_REMOTE_INPUT): return HandleStopRelayDhidRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::REGISTER_ADD_WHITE_LIST_CB_REMOTE_INPUT): return HandleRegisterAddWhiteListCallback(data, reply); case static_cast(IDInputSourceInterfaceCode::REGISTER_DEL_WHITE_LIST_CB_REMOTE_INPUT): return HandleRegisterDelWhiteListCallback(data, reply); case static_cast(IDInputSourceInterfaceCode::REGISTER_SIMULATION_EVENT_LISTENER): return HandleRegisterSimulationEventListener(data, reply); case static_cast(IDInputSourceInterfaceCode::UNREGISTER_SIMULATION_EVENT_LISTENER): return HandleUnregisterSimulationEventListener(data, reply); case static_cast(IDInputSourceInterfaceCode::REGISTER_SESSION_STATE_CB): return HandleRegisterSessionStateCb(data, reply); case static_cast(IDInputSourceInterfaceCode::UNREGISTER_SESSION_STATE_CB): return HandleUnregisterSessionStateCb(data, reply); default: DHLOGE("invalid request code is %{public}u.", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } int32_t DistributedInputSourceStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { DHLOGI("OnRemoteRequest code: %{public}u.", code); if (data.ReadInterfaceToken() != GetDescriptor()) { DHLOGE("DistributedInputSourceStub read token valid failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } if (code == static_cast(IDInputSourceInterfaceCode::REGISTER_REMOTE_INPUT)) { DHLOGI("Receive Register DInput cmd"); } if (code == static_cast(IDInputSourceInterfaceCode::UNREGISTER_REMOTE_INPUT)) { DHLOGI("Receive UnRegister DInput cmd"); } switch (code) { case static_cast(IDInputSourceInterfaceCode::INIT): return HandleInitDistributedHardware(reply); case static_cast(IDInputSourceInterfaceCode::RELEASE): return HandleReleaseDistributedHardware(reply); case static_cast(IDInputSourceInterfaceCode::REGISTER_REMOTE_INPUT): return HandleRegisterDistributedHardware(data, reply); case static_cast(IDInputSourceInterfaceCode::UNREGISTER_REMOTE_INPUT): return HandleUnregisterDistributedHardware(data, reply); case static_cast(IDInputSourceInterfaceCode::PREPARE_REMOTE_INPUT): return HandlePrepareRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::UNPREPARE_REMOTE_INPUT): return HandleUnprepareRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::START_REMOTE_INPUT): return HandleStartRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::STOP_REMOTE_INPUT): return HandleStopRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::START_RELAY_TYPE_REMOTE_INPUT): return HandleStartRelayTypeRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::STOP_RELAY_TYPE_REMOTE_INPUT): return HandleStopRelayTypeRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::PREPARE_RELAY_REMOTE_INPUT): return HandlePrepareRelayRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::UNPREPARE_RELAY_REMOTE_INPUT): return HandleUnprepareRelayRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::START_DHID_REMOTE_INPUT): return HandleStartDhidRemoteInput(data, reply); case static_cast(IDInputSourceInterfaceCode::STOP_DHID_REMOTE_INPUT): return HandleStopDhidRemoteInput(data, reply); default: return HandleRemoteRequest(code, data, reply, option); } } } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS