From 884d65c22a91e1a0710e6eb7ec079c35a4b9cd81 Mon Sep 17 00:00:00 2001 From: shenpeixing Date: Mon, 17 Feb 2025 09:27:56 +0800 Subject: [PATCH] =?UTF-8?q?miscdevice=E6=9C=8D=E5=8A=A1idl=E5=8C=96?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shenpeixing --- .../common/include/i_miscdevice_service.h | 62 -- .../common/include/miscdevice_service_proxy.h | 57 -- .../include/sensors_ipc_interface_code.h | 42 -- .../common/src/miscdevice_service_proxy.cpp | 538 ------------------ frameworks/native/light/BUILD.gn | 9 +- frameworks/native/light/src/light_client.cpp | 5 +- frameworks/native/vibrator/BUILD.gn | 94 ++- .../vibrator/all/IMiscdeviceService.idl | 40 ++ .../vibrator/part/IMiscdeviceService.idl | 39 ++ .../vibrator/src/vibrator_service_client.cpp | 19 +- services/miscdevice_service/BUILD.gn | 14 +- .../include/miscdevice_service.h | 12 +- .../include/miscdevice_service_stub.h | 67 --- .../src/miscdevice_service.cpp | 211 ++++++- .../src/miscdevice_service_stub.cpp | 439 -------------- .../service/getdelaytimestub_fuzzer/BUILD.gn | 1 + .../getdelaytimestub_fuzzer.cpp | 2 +- .../service/getlightliststub_fuzzer/BUILD.gn | 1 + .../getlightliststub_fuzzer.cpp | 2 +- .../getvibratorcapacitystub_fuzzer/BUILD.gn | 1 + .../getvibratorcapacitystub_fuzzer.cpp | 2 +- .../issupporteffectstub_fuzzer/BUILD.gn | 1 + .../issupporteffectstub_fuzzer.cpp | 2 +- .../service/playpatternstub_fuzzer/BUILD.gn | 1 + .../playpatternstub_fuzzer.cpp | 2 +- .../playprimitiveeffectstub_fuzzer/BUILD.gn | 1 + .../playprimitiveeffectstub_fuzzer.cpp | 2 +- .../playvibratorcustomstub_fuzzer/BUILD.gn | 1 + .../playvibratorcustomstub_fuzzer.cpp | 2 +- .../playvibratoreffectstub_fuzzer/BUILD.gn | 1 + .../playvibratoreffectstub_fuzzer.cpp | 2 +- .../stopvibratorallstub_fuzzer/BUILD.gn | 1 + .../stopvibratorallstub_fuzzer.cpp | 2 +- .../stopvibratorbymodestub_fuzzer/BUILD.gn | 1 + .../stopvibratorbymodestub_fuzzer.cpp | 2 +- .../BUILD.gn | 1 + .../transferclientremoteobjectstub_fuzzer.cpp | 2 +- .../service/turnoffstub_fuzzer/BUILD.gn | 1 + .../turnoffstub_fuzzer/turnoffstub_fuzzer.cpp | 2 +- .../service/turnonstub_fuzzer/BUILD.gn | 1 + .../turnonstub_fuzzer/turnonstub_fuzzer.cpp | 2 +- .../service/vibratestub_fuzzer/BUILD.gn | 1 + .../vibratestub_fuzzer/vibratestub_fuzzer.cpp | 2 +- .../vibratoronremoterequest_fuzzer/BUILD.gn | 1 + utils/common/include/light_animation_ipc.h | 2 +- utils/common/include/light_info_ipc.h | 2 +- utils/common/include/vibrator_infos.h | 12 +- utils/common/src/light_animation_ipc.cpp | 8 +- utils/common/src/light_info_ipc.cpp | 8 +- utils/common/src/vibrator_infos.cpp | 128 ++--- 50 files changed, 479 insertions(+), 1372 deletions(-) delete mode 100644 frameworks/native/common/include/i_miscdevice_service.h delete mode 100644 frameworks/native/common/include/miscdevice_service_proxy.h delete mode 100644 frameworks/native/common/include/sensors_ipc_interface_code.h delete mode 100644 frameworks/native/common/src/miscdevice_service_proxy.cpp create mode 100644 frameworks/native/vibrator/all/IMiscdeviceService.idl create mode 100644 frameworks/native/vibrator/part/IMiscdeviceService.idl delete mode 100644 services/miscdevice_service/include/miscdevice_service_stub.h delete mode 100644 services/miscdevice_service/src/miscdevice_service_stub.cpp diff --git a/frameworks/native/common/include/i_miscdevice_service.h b/frameworks/native/common/include/i_miscdevice_service.h deleted file mode 100644 index f555c7a..0000000 --- a/frameworks/native/common/include/i_miscdevice_service.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. - */ - -#ifndef I_MISCDEVICE_SERVICE_H -#define I_MISCDEVICE_SERVICE_H - -#include -#include - -#include "iremote_broker.h" - -#include "light_agent_type.h" -#include "light_animation_ipc.h" -#include "light_info_ipc.h" -#include "miscdevice_common.h" -#include "raw_file_descriptor.h" -#include "sensors_ipc_interface_code.h" -#include "vibrator_infos.h" - -namespace OHOS { -namespace Sensors { -class IMiscdeviceService : public IRemoteBroker { -public: - IMiscdeviceService() = default; - virtual ~IMiscdeviceService() = default; - DECLARE_INTERFACE_DESCRIPTOR(u"IMiscdeviceService"); - virtual int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage) = 0; - virtual int32_t PlayVibratorEffect(int32_t vibratorId, const std::string &effect, - int32_t loopCount, int32_t usage, bool systemUsage) = 0; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - virtual int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - bool systemUsage, const VibrateParameter ¶meter) = 0; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - virtual int32_t StopVibrator(int32_t vibratorId) = 0; - virtual int32_t StopVibrator(int32_t vibratorId, const std::string &mode) = 0; - virtual int32_t IsSupportEffect(const std::string &effect, bool &state) = 0; - virtual std::vector GetLightList() = 0; - virtual int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) = 0; - virtual int32_t TurnOff(int32_t lightId) = 0; - virtual int32_t GetDelayTime(int32_t &delayTime) = 0; - virtual int32_t PlayPattern(const VibratePattern &pattern, int32_t usage, bool systemUsage, - const VibrateParameter ¶meter) = 0; - virtual int32_t TransferClientRemoteObject(const sptr &vibratorClient) = 0; - virtual int32_t PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, - int32_t usage, bool systemUsage, int32_t count) = 0; - virtual int32_t GetVibratorCapacity(VibratorCapacity &capacity) = 0; -}; -} // namespace Sensors -} // namespace OHOS -#endif // I_MISCDEVICE_SERVICE_H diff --git a/frameworks/native/common/include/miscdevice_service_proxy.h b/frameworks/native/common/include/miscdevice_service_proxy.h deleted file mode 100644 index 9af91e7..0000000 --- a/frameworks/native/common/include/miscdevice_service_proxy.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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. - */ - -#ifndef MISCDEVICE_SERVICE_PROXY_H -#define MISCDEVICE_SERVICE_PROXY_H - -#include "iremote_proxy.h" -#include "nocopyable.h" - -#include "i_miscdevice_service.h" - -namespace OHOS { -namespace Sensors { -class MiscdeviceServiceProxy : public IRemoteProxy { -public: - explicit MiscdeviceServiceProxy(const sptr &impl); - ~MiscdeviceServiceProxy() = default; - virtual int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage) override; - virtual int32_t PlayVibratorEffect(int32_t vibratorId, const std::string &effect, - int32_t loopCount, int32_t usage, bool systemUsage) override; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - virtual int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - bool systemUsage, const VibrateParameter ¶meter) override; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - virtual int32_t StopVibrator(int32_t vibratorId) override; - virtual int32_t StopVibrator(int32_t vibratorId, const std::string &mode) override; - virtual int32_t IsSupportEffect(const std::string &effect, bool &state) override; - virtual std::vector GetLightList() override; - virtual int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) override; - virtual int32_t TurnOff(int32_t lightId) override; - virtual int32_t GetDelayTime(int32_t &delayTime) override; - virtual int32_t PlayPattern(const VibratePattern &pattern, int32_t usage, - bool systemUsage, const VibrateParameter ¶meter) override; - virtual int32_t TransferClientRemoteObject(const sptr &vibratorClient) override; - virtual int32_t PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, - int32_t usage, bool systemUsage, int32_t count) override; - virtual int32_t GetVibratorCapacity(VibratorCapacity &capacity) override; - -private: - DISALLOW_COPY_AND_MOVE(MiscdeviceServiceProxy); - static inline BrokerDelegator delegator_; -}; -} // namespace Sensors -} // namespace OHOS -#endif // MISCDEVICE_SERVICE_PROXY_H diff --git a/frameworks/native/common/include/sensors_ipc_interface_code.h b/frameworks/native/common/include/sensors_ipc_interface_code.h deleted file mode 100644 index f6daaee..0000000 --- a/frameworks/native/common/include/sensors_ipc_interface_code.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2023-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. - */ - -#ifndef SENSORS_IPC_INTERFACE_CODE_H -#define SENSORS_IPC_INTERFACE_CODE_H - -/* SAID:3602 */ -namespace OHOS { -namespace Sensors { -enum class MiscdeviceInterfaceCode { - VIBRATE = 0, - PLAY_VIBRATOR_EFFECT, -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - PLAY_VIBRATOR_CUSTOM, -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - STOP_VIBRATOR_ALL, - STOP_VIBRATOR_BY_MODE, - IS_SUPPORT_EFFECT, - GET_LIGHT_LIST, - TURN_ON, - TURN_OFF, - PlAY_PATTERN, - GET_DELAY_TIME, - TRANSFER_CLIENT_REMOTE_OBJECT, - PLAY_PRIMITIVE_EFFECT, - GET_VIBRATOR_CAPACITY, -}; -} // namespace Sensors -} // namespace OHOS -#endif // SENSORS_IPC_INTERFACE_CODE_H diff --git a/frameworks/native/common/src/miscdevice_service_proxy.cpp b/frameworks/native/common/src/miscdevice_service_proxy.cpp deleted file mode 100644 index 6905a99..0000000 --- a/frameworks/native/common/src/miscdevice_service_proxy.cpp +++ /dev/null @@ -1,538 +0,0 @@ -/* - * 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 "miscdevice_service_proxy.h" - -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE -#include "hisysevent.h" -#endif // HIVIEWDFX_HISYSEVENT_ENABLE -#include "securec.h" - -#include "sensors_errors.h" - -#undef LOG_TAG -#define LOG_TAG "MiscdeviceServiceProxy" - -namespace OHOS { -namespace Sensors { -using namespace OHOS::HiviewDFX; - -namespace { -constexpr int32_t MAX_LIGHT_COUNT = 0XFF; -} // namespace - -MiscdeviceServiceProxy::MiscdeviceServiceProxy(const sptr &impl) : IRemoteProxy(impl) -{} - -int32_t MiscdeviceServiceProxy::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(vibratorId)) { - MISC_HILOGE("WriteInt32 vibratorId failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(timeOut)) { - MISC_HILOGE("WriteInt32 timeOut failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(usage)) { - MISC_HILOGE("WriteInt32 usage failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteBool(systemUsage)) { - MISC_HILOGE("WritBool systemUsage failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::VIBRATE), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "Vibrate", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGD("SendRequest failed, ret:%{public}d", ret); - } - return ret; -} - -int32_t MiscdeviceServiceProxy::StopVibrator(int32_t vibratorId) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(vibratorId)) { - MISC_HILOGE("WriteInt32 vibratorId failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::STOP_VIBRATOR_ALL), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "StopVibrator", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGD("SendRequest failed, ret:%{public}d", ret); - } - return ret; -} - -int32_t MiscdeviceServiceProxy::PlayVibratorEffect(int32_t vibratorId, const std::string &effect, - int32_t loopCount, int32_t usage, bool systemUsage) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(vibratorId)) { - MISC_HILOGE("WriteInt32 vibratorId failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteString(effect)) { - MISC_HILOGE("WriteString effect failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(loopCount)) { - MISC_HILOGE("WriteInt32 loopCount failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(usage)) { - MISC_HILOGE("WriteInt32 usage failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteBool(systemUsage)) { - MISC_HILOGE("Writebool systemUsage failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::PLAY_VIBRATOR_EFFECT), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "PlayVibratorEffect", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGD("SendRequest failed, ret:%{public}d", ret); - } - return ret; -} - -int32_t MiscdeviceServiceProxy::StopVibrator(int32_t vibratorId, const std::string &mode) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(vibratorId)) { - MISC_HILOGE("WriteInt32 vibratorId failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteString(mode)) { - MISC_HILOGE("WriteString mode failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::STOP_VIBRATOR_BY_MODE), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "StopVibrator", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGD("SendRequest failed, ret:%{public}d", ret); - } - return ret; -} - -int32_t MiscdeviceServiceProxy::IsSupportEffect(const std::string &effect, bool &state) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteString(effect)) { - MISC_HILOGE("WriteString effect failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::IS_SUPPORT_EFFECT), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "IsSupportEffect", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGD("SendRequest failed, ret:%{public}d", ret); - return ret; - } - if (!reply.ReadBool(state)) { - MISC_HILOGE("Parcel read state failed"); - return READ_MSG_ERR; - } - return ret; -} - -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM -int32_t MiscdeviceServiceProxy::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - bool systemUsage, const VibrateParameter ¶meter) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(vibratorId)) { - MISC_HILOGE("WriteInt32 vibratorId failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(usage)) { - MISC_HILOGE("Writeint32 usage failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteBool(systemUsage)) { - MISC_HILOGE("Writebool systemUsage failed"); - return WRITE_MSG_ERR; - } - if (!parameter.Marshalling(data)) { - MISC_HILOGE("Write adjust parameter failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt64(rawFd.offset)) { - MISC_HILOGE("Writeint64 offset failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt64(rawFd.length)) { - MISC_HILOGE("Writeint64 length failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteFileDescriptor(rawFd.fd)) { - MISC_HILOGE("WriteFileDescriptor fd failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::PLAY_VIBRATOR_CUSTOM), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "PlayVibratorCustom", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGD("SendRequest failed, ret:%{public}d", ret); - } - return ret; -} -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - -std::vector MiscdeviceServiceProxy::GetLightList() -{ - MessageParcel data; - std::vector lightInfos; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("WriteInterfaceToken failed"); - return lightInfos; - } - sptr remote = Remote(); - if (remote == nullptr) { - MISC_HILOGE("remote is nullptr"); - return lightInfos; - } - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::GET_LIGHT_LIST), - data, reply, option); - if (ret != NO_ERROR) { - MISC_HILOGE("SendRequest failed, ret:%{public}d", ret); - return lightInfos; - } - uint32_t lightCount = 0; - if (!reply.ReadUint32(lightCount)) { - MISC_HILOGE("Parcel read failed"); - return lightInfos; - } - if (lightCount > MAX_LIGHT_COUNT) { - lightCount = MAX_LIGHT_COUNT; - } - LightInfoIPC lightInfo; - for (uint32_t i = 0; i < lightCount; ++i) { - auto tmpLightInfo = lightInfo.Unmarshalling(reply); - CHKPC(tmpLightInfo); - lightInfos.push_back(*tmpLightInfo); - } - return lightInfos; -} - -int32_t MiscdeviceServiceProxy::TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(lightId)) { - MISC_HILOGE("WriteUint32 lightId failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(color.singleColor)) { - MISC_HILOGE("Write color failed"); - return WRITE_MSG_ERR; - } - if (!animation.Marshalling(data)) { - MISC_HILOGE("Write animation failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::TURN_ON), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "TurnOn", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("SendRequest failed, ret:%{public}d", ret); - } - return ret; -} - -int32_t MiscdeviceServiceProxy::TurnOff(int32_t lightId) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(lightId)) { - MISC_HILOGE("WriteInt32 lightId failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::TURN_OFF), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "TurnOff", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("SendRequest failed, ret:%{public}d", ret); - } - return ret; -} - -int32_t MiscdeviceServiceProxy::GetDelayTime(int32_t &delayTime) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::GET_DELAY_TIME), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "GetDelayTime", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGD("SendRequest failed, ret:%{public}d", ret); - } - if (!reply.ReadInt32(delayTime)) { - MISC_HILOGE("Parcel read failed"); - return ERROR; - } - return ret; -} - -int32_t MiscdeviceServiceProxy::PlayPattern(const VibratePattern &pattern, int32_t usage, - bool systemUsage, const VibrateParameter ¶meter) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!pattern.Marshalling(data)) { - MISC_HILOGE("Marshalling failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(usage)) { - MISC_HILOGE("WriteUint32 usage failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteBool(systemUsage)) { - MISC_HILOGE("WriteBool systemUsage failed"); - return WRITE_MSG_ERR; - } - if (!parameter.Marshalling(data)) { - MISC_HILOGE("Write adjust parameter failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::PlAY_PATTERN), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "PlayPattern", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGD("SendRequest failed, ret:%{public}d", ret); - } - return ret; -} - -int32_t MiscdeviceServiceProxy::TransferClientRemoteObject(const sptr &vibratorClient) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteRemoteObject(vibratorClient)) { - MISC_HILOGE("Parcel writeRemoteObject failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::TRANSFER_CLIENT_REMOTE_OBJECT), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "TransferClientRemoteObject", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("SendRequest failed, ret:%{public}d", ret); - } - return ret; -} - -int32_t MiscdeviceServiceProxy::PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, - int32_t usage, bool systemUsage, int32_t count) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(vibratorId)) { - MISC_HILOGE("WriteInt32 vibratorId failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteString(effect)) { - MISC_HILOGE("WriteString effect failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(intensity)) { - MISC_HILOGE("WriteInt32 intensity failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(usage)) { - MISC_HILOGE("Writeint32 usage failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteBool(systemUsage)) { - MISC_HILOGE("WriteBool systemUsage failed"); - return WRITE_MSG_ERR; - } - if (!data.WriteInt32(count)) { - MISC_HILOGE("Writeint32 count failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::PLAY_PRIMITIVE_EFFECT), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "PlayPrimitiveEffect", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGD("SendRequest failed, ret:%{public}d", ret); - } - return ret; -} - -int32_t MiscdeviceServiceProxy::GetVibratorCapacity(VibratorCapacity &capacity) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { - MISC_HILOGE("Write descriptor failed"); - return WRITE_MSG_ERR; - } - sptr remote = Remote(); - CHKPR(remote, ERROR); - MessageParcel reply; - MessageOption option; - int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::GET_VIBRATOR_CAPACITY), - data, reply, option); - if (ret != NO_ERROR) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "GetVibratorCapacity", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("SendRequest failed, ret:%{public}d", ret); - return ret; - } - auto vibratorCapacity = capacity.Unmarshalling(reply); - if (!vibratorCapacity.has_value()) { - MISC_HILOGE("VibratorCapacity Unmarshalling failed"); - return ERROR; - } - capacity = vibratorCapacity.value(); - return ret; -} -} // namespace Sensors -} // namespace OHOS diff --git a/frameworks/native/light/BUILD.gn b/frameworks/native/light/BUILD.gn index 10bd791..3fd866b 100644 --- a/frameworks/native/light/BUILD.gn +++ b/frameworks/native/light/BUILD.gn @@ -37,7 +37,6 @@ ohos_shared_library("light_interface_native") { sources = [ "light_agent.cpp" ] include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/common/include", "$SUBSYSTEM_DIR/interfaces/inner_api/light", "$SUBSYSTEM_DIR/utils/common/include", "include", @@ -56,6 +55,7 @@ ohos_shared_library("light_interface_native") { "$SUBSYSTEM_DIR/frameworks/native/light:liblight_native", "$SUBSYSTEM_DIR/frameworks/native/light:liblight_ndk", "$SUBSYSTEM_DIR/frameworks/native/light:light_ndk_header", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_file_h", ] external_deps = [ @@ -71,14 +71,10 @@ ohos_shared_library("light_interface_native") { } ohos_shared_library("liblight_native") { - sources = [ - "$SUBSYSTEM_DIR/frameworks/native/common/src/miscdevice_service_proxy.cpp", - "src/light_client.cpp", - ] + sources = [ "src/light_client.cpp" ] include_dirs = [ "include", - "$SUBSYSTEM_DIR/frameworks/native/common/include", "$SUBSYSTEM_DIR/interfaces/inner_api/light", "$SUBSYSTEM_DIR/utils/common/include", ] @@ -94,6 +90,7 @@ ohos_shared_library("liblight_native") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_ndk_header", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_proxy", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", ] diff --git a/frameworks/native/light/src/light_client.cpp b/frameworks/native/light/src/light_client.cpp index 32e5624..1ae3ffa 100644 --- a/frameworks/native/light/src/light_client.cpp +++ b/frameworks/native/light/src/light_client.cpp @@ -65,7 +65,8 @@ int32_t LightClient::InitLightClient() auto remoteObject = miscdeviceProxy_->AsObject(); CHKPR(remoteObject, MISC_NATIVE_GET_SERVICE_ERR); remoteObject->AddDeathRecipient(serviceDeathObserver_); - lightInfoList_ = miscdeviceProxy_->GetLightList(); + lightInfoList_.clear(); + miscdeviceProxy_->GetLightList(lightInfoList_); return ERR_OK; } #ifdef HIVIEWDFX_HISYSEVENT_ENABLE @@ -148,7 +149,7 @@ int32_t LightClient::TurnOn(int32_t lightId, const LightColor &color, const Ligh animationIPC.SetMode(animation.mode); animationIPC.SetOnTime(animation.onTime); animationIPC.SetOffTime(animation.offTime); - return miscdeviceProxy_->TurnOn(lightId, color, animationIPC); + return miscdeviceProxy_->TurnOn(lightId, color.singleColor, animationIPC); } int32_t LightClient::TurnOff(int32_t lightId) diff --git a/frameworks/native/vibrator/BUILD.gn b/frameworks/native/vibrator/BUILD.gn index 630fbcd..1072d6d 100644 --- a/frameworks/native/vibrator/BUILD.gn +++ b/frameworks/native/vibrator/BUILD.gn @@ -11,9 +11,90 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import("./../../../miscdevice.gni") +idl_gen_interface("miscdevice_service_interface") { + if (miscdevice_feature_vibrator_custom) { + sources = [ "all/IMiscdeviceService.idl" ] + } else { + sources = [ "part/IMiscdeviceService.idl" ] + } + log_domainid = "0xD002701" + log_tag = "IMiscdeviceServiceIdl" + part_name = "miscdevice" + subsystem_name = "sensors" +} + +config("miscdevice_service_idl_config") { + include_dirs = [ + "${target_gen_dir}", + "include", + "$SUBSYSTEM_DIR/interfaces/inner_api/light", + "$SUBSYSTEM_DIR/interfaces/inner_api/vibrator", + "$SUBSYSTEM_DIR/utils/common/include", + ] +} + +ohos_source_set("miscdevice_service_stub") { + public_configs = [ ":miscdevice_service_idl_config" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":miscdevice_service_interface") + sources = filter_include(output_values, [ "*_stub.cpp" ]) + deps = [ ":miscdevice_service_interface" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + "samgr:samgr_proxy", + ] + part_name = "miscdevice" + subsystem_name = "sensors" +} + +ohos_source_set("miscdevice_service_proxy") { + public_configs = [ ":miscdevice_service_idl_config" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":miscdevice_service_interface") + sources = filter_include(output_values, [ "*_proxy.cpp" ]) + deps = [ ":miscdevice_service_interface" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + "samgr:samgr_proxy", + ] + part_name = "miscdevice" + subsystem_name = "sensors" +} + +ohos_source_set("miscdevice_service_file_h") { + public_configs = [ ":miscdevice_service_idl_config" ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + deps = [ ":miscdevice_service_interface" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + "samgr:samgr_proxy", + ] + part_name = "miscdevice" + subsystem_name = "sensors" +} + ohos_ndk_library("libvibrator_ndk") { output_name = "vibrator_agent" ndk_description_file = "./libvibrator.json" @@ -37,8 +118,8 @@ ohos_shared_library("vibrator_interface_native") { sources = [ "vibrator_agent.cpp" ] include_dirs = [ + "${target_gen_dir}", "include", - "$SUBSYSTEM_DIR/frameworks/native/common/include", "$SUBSYSTEM_DIR/interfaces/inner_api/light", "$SUBSYSTEM_DIR/interfaces/inner_api/vibrator", "$SUBSYSTEM_DIR/utils/common/include", @@ -60,6 +141,7 @@ ohos_shared_library("vibrator_interface_native") { "$SUBSYSTEM_DIR/frameworks/native/light:light_ndk_header", "$SUBSYSTEM_DIR/frameworks/native/vibrator:libvibrator_native", "$SUBSYSTEM_DIR/frameworks/native/vibrator:libvibrator_ndk", + "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", ] external_deps = [ @@ -77,22 +159,26 @@ ohos_shared_library("vibrator_interface_native") { } ohos_shared_library("libvibrator_native") { + output_values = get_target_outputs(":miscdevice_service_interface") sources = [ - "$SUBSYSTEM_DIR/frameworks/native/common/src/miscdevice_service_proxy.cpp", "src/vibrator_client_stub.cpp", "src/vibrator_service_client.cpp", ] + sources += filter_include(output_values, [ "*_proxy.cpp" ]) include_dirs = [ + "${target_gen_dir}", "$SUBSYSTEM_DIR/utils/haptic_decoder/interface", "$SUBSYSTEM_DIR/interfaces/inner_api/vibrator", "include", - "$SUBSYSTEM_DIR/frameworks/native/common/include", "$SUBSYSTEM_DIR/interfaces/inner_api/light", "$SUBSYSTEM_DIR/utils/common/include", ] - deps = [ "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils" ] + deps = [ + ":miscdevice_service_interface", + "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", + ] branch_protector_ret = "pac_ret" sanitize = { diff --git a/frameworks/native/vibrator/all/IMiscdeviceService.idl b/frameworks/native/vibrator/all/IMiscdeviceService.idl new file mode 100644 index 0000000..2e2ceea --- /dev/null +++ b/frameworks/native/vibrator/all/IMiscdeviceService.idl @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 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. + */ + +sequenceable light_agent_type..LightColor; +sequenceable light_animation_ipc..OHOS.Sensors.LightAnimationIPC; +sequenceable light_info_ipc..OHOS.Sensors.LightInfoIPC; +sequenceable OHOS.IRemoteObject; +sequenceable raw_file_descriptor..OHOS.Sensors.RawFileDescriptor; +sequenceable vibrator_infos..OHOS.Sensors.VibrateParameter; +sequenceable vibrator_infos..OHOS.Sensors.VibratePattern; +sequenceable vibrator_infos..OHOS.Sensors.VibratorCapacity; + +interface OHOS.Sensors.IMiscdeviceService { + void Vibrate([in] int vibratorId, [in] int timeOut, [in] int usage, [in] boolean systemUsage); + void PlayVibratorEffect([in] int vibratorId, [in] String effect, [in] int loopCount, [in] int usage, [in] boolean systemUsage); + void PlayVibratorCustom([in] int vibratorId, [in] FileDescriptor fd, [in] long offset, [in] long length, [in] int usage, [in] boolean systemUsage, [in] VibrateParameter parameter); + void StopVibrator([in] int vibratorId); + void StopVibratorByMode([in] int vibratorId, [in] String mode); + void IsSupportEffect([in] String effect, [out] boolean state); + void GetLightList([out] LightInfoIPC[] lightInfoIpcList); + void TurnOn([in] int lightId, [in] int singleColor, [in] LightAnimationIPC animation); + void TurnOff([in] int lightId); + void GetDelayTime([out] int delayTime); + void PlayPattern([in] VibratePattern pattern, [in] int usage, [in] boolean systemUsage, [in] VibrateParameter parameter); + void TransferClientRemoteObject([in] IRemoteObject vibratorClient); + void PlayPrimitiveEffect([in] int vibratorId, [in] String effect, [in] int intensity, [in] int usage, [in] boolean systemUsage, [in] int count); + void GetVibratorCapacity([out] VibratorCapacity capacity); +} \ No newline at end of file diff --git a/frameworks/native/vibrator/part/IMiscdeviceService.idl b/frameworks/native/vibrator/part/IMiscdeviceService.idl new file mode 100644 index 0000000..2415e99 --- /dev/null +++ b/frameworks/native/vibrator/part/IMiscdeviceService.idl @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 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. + */ + +sequenceable light_agent_type..LightColor; +sequenceable light_animation_ipc..OHOS.Sensors.LightAnimationIPC; +sequenceable light_info_ipc..OHOS.Sensors.LightInfoIPC; +sequenceable OHOS.IRemoteObject; +sequenceable raw_file_descriptor..OHOS.Sensors.RawFileDescriptor; +sequenceable vibrator_infos..OHOS.Sensors.VibrateParameter; +sequenceable vibrator_infos..OHOS.Sensors.VibratePattern; +sequenceable vibrator_infos..OHOS.Sensors.VibratorCapacity; + +interface OHOS.Sensors.IMiscdeviceService { + void Vibrate([in] int vibratorId, [in] int timeOut, [in] int usage, [in] boolean systemUsage); + void PlayVibratorEffect([in] int vibratorId, [in] String effect, [in] int loopCount, [in] int usage, [in] boolean systemUsage); + void StopVibrator([in] int vibratorId); + void StopVibratorByMode([in] int vibratorId, [in] String mode); + void IsSupportEffect([in] String effect, [out] boolean state); + void GetLightList([out] LightInfoIPC[] lightInfoIpcList); + void TurnOn([in] int lightId, [in] int singleColor, [in] LightAnimationIPC animation); + void TurnOff([in] int lightId); + void GetDelayTime([out] int delayTime); + void PlayPattern([in] VibratePattern pattern, [in] int usage, [in] boolean systemUsage, [in] VibrateParameter parameter); + void TransferClientRemoteObject([in] IRemoteObject vibratorClient); + void PlayPrimitiveEffect([in] int vibratorId, [in] String effect, [in] int intensity, [in] int usage, [in] boolean systemUsage, [in] int count); + void GetVibratorCapacity([out] VibratorCapacity capacity); +} \ No newline at end of file diff --git a/frameworks/native/vibrator/src/vibrator_service_client.cpp b/frameworks/native/vibrator/src/vibrator_service_client.cpp index ab9b01b..31acf28 100644 --- a/frameworks/native/vibrator/src/vibrator_service_client.cpp +++ b/frameworks/native/vibrator/src/vibrator_service_client.cpp @@ -187,11 +187,11 @@ int32_t VibratorServiceClient::PlayVibratorCustom(int32_t vibratorId, const RawF #ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "PlayVibratorCustom"); #endif // HIVIEWDFX_HITRACE_ENABLE - VibrateParameter vibateParameter = { - .intensity = parameter.intensity, - .frequency = parameter.frequency - }; - ret = miscdeviceProxy_->PlayVibratorCustom(vibratorId, rawFd, usage, systemUsage, vibateParameter); + VibrateParameter vibateParameter; + vibateParameter.intensity = parameter.intensity; + vibateParameter.frequency = parameter.frequency; + ret = miscdeviceProxy_->PlayVibratorCustom(vibratorId, rawFd.fd, rawFd.offset, rawFd.length, usage, systemUsage, + vibateParameter); #ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); #endif // HIVIEWDFX_HITRACE_ENABLE @@ -215,7 +215,7 @@ int32_t VibratorServiceClient::StopVibrator(int32_t vibratorId, const std::strin #ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "StopVibratorByMode"); #endif // HIVIEWDFX_HITRACE_ENABLE - ret = miscdeviceProxy_->StopVibrator(vibratorId, mode); + ret = miscdeviceProxy_->StopVibratorByMode(vibratorId, mode); #ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); #endif // HIVIEWDFX_HITRACE_ENABLE @@ -410,10 +410,9 @@ int32_t VibratorServiceClient::InitPlayPattern(const VibratorPattern &pattern, i vibratePattern.events.emplace_back(event); vibratePattern.patternDuration = pattern.patternDuration; } - VibrateParameter vibateParameter = { - .intensity = parameter.intensity, - .frequency = parameter.frequency - }; + VibrateParameter vibateParameter; + vibateParameter.intensity = parameter.intensity; + vibateParameter.frequency = parameter.frequency; std::lock_guard clientLock(clientMutex_); CHKPR(miscdeviceProxy_, ERROR); return miscdeviceProxy_->PlayPattern(vibratePattern, usage, systemUsage, vibateParameter); diff --git a/services/miscdevice_service/BUILD.gn b/services/miscdevice_service/BUILD.gn index a1a9412..85905a2 100644 --- a/services/miscdevice_service/BUILD.gn +++ b/services/miscdevice_service/BUILD.gn @@ -24,7 +24,6 @@ ohos_shared_library("libmiscdevice_service") { "src/miscdevice_dump.cpp", "src/miscdevice_observer.cpp", "src/miscdevice_service.cpp", - "src/miscdevice_service_stub.cpp", "src/vibration_priority_manager.cpp", "src/vibrator_thread.cpp", ] @@ -32,7 +31,6 @@ ohos_shared_library("libmiscdevice_service") { include_dirs = [ "haptic_matcher/include", "include", - "$SUBSYSTEM_DIR/frameworks/native/common/include", "$SUBSYSTEM_DIR/interfaces/inner_api/light", "$SUBSYSTEM_DIR/services/miscdevice_service/hdi_connection/adapter/include", "$SUBSYSTEM_DIR/services/miscdevice_service/hdi_connection/interface/include", @@ -67,7 +65,10 @@ ohos_shared_library("libmiscdevice_service") { debug = false } - deps = [ "$SUBSYSTEM_DIR/utils:miscdevice_utils_target" ] + deps = [ + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", + "$SUBSYSTEM_DIR/utils:miscdevice_utils_target", + ] external_deps = [ "ability_base:want", @@ -146,7 +147,6 @@ ohos_static_library("libmiscdevice_service_static") { "src/miscdevice_dump.cpp", "src/miscdevice_observer.cpp", "src/miscdevice_service.cpp", - "src/miscdevice_service_stub.cpp", "src/vibration_priority_manager.cpp", "src/vibrator_thread.cpp", ] @@ -154,7 +154,6 @@ ohos_static_library("libmiscdevice_service_static") { include_dirs = [ "haptic_matcher/include", "include", - "$SUBSYSTEM_DIR/frameworks/native/common/include", "$SUBSYSTEM_DIR/interfaces/inner_api/light", "$SUBSYSTEM_DIR/services/miscdevice_service/hdi_connection/adapter/include", "$SUBSYSTEM_DIR/services/miscdevice_service/hdi_connection/interface/include", @@ -189,7 +188,10 @@ ohos_static_library("libmiscdevice_service_static") { debug = false } - deps = [ "$SUBSYSTEM_DIR/utils:miscdevice_utils_target" ] + deps = [ + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", + "$SUBSYSTEM_DIR/utils:miscdevice_utils_target", + ] external_deps = [ "ability_base:want", diff --git a/services/miscdevice_service/include/miscdevice_service.h b/services/miscdevice_service/include/miscdevice_service.h index f1c9783..0350467 100644 --- a/services/miscdevice_service/include/miscdevice_service.h +++ b/services/miscdevice_service/include/miscdevice_service.h @@ -67,14 +67,14 @@ public: virtual int32_t PlayVibratorEffect(int32_t vibratorId, const std::string &effect, int32_t loopCount, int32_t usage, bool systemUsage) override; #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - virtual int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, + virtual int32_t PlayVibratorCustom(int32_t vibratorId, int32_t fd, int64_t offset, int64_t length, int32_t usage, bool systemUsage, const VibrateParameter ¶meter) override; #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t StopVibrator(int32_t vibratorId) override; - virtual int32_t StopVibrator(int32_t vibratorId, const std::string &mode) override; + virtual int32_t StopVibratorByMode(int32_t vibratorId, const std::string &mode) override; virtual int32_t IsSupportEffect(const std::string &effect, bool &state) override; - virtual std::vector GetLightList() override; - virtual int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) override; + virtual int32_t GetLightList(std::vector &lightInfoIpcList) override; + virtual int32_t TurnOn(int32_t lightId, int32_t singleColor, const LightAnimationIPC &animation) override; virtual int32_t TurnOff(int32_t lightId) override; virtual int32_t PlayPattern(const VibratePattern &pattern, int32_t usage, bool systemUsage, const VibrateParameter ¶meter) override; @@ -103,6 +103,10 @@ private: void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; int32_t SubscribeCommonEvent(const std::string &eventName, EventReceiver receiver); void OnReceiveEvent(const EventFwk::CommonEventData &data); + int32_t CheckAuthAndParam(int32_t usage, const VibrateParameter ¶meter); + int32_t PlayPatternCheckAuthAndParam(int32_t usage, const VibrateParameter ¶meter); + int32_t PlayPrimitiveEffectCheckAuthAndParam(int32_t intensity, int32_t usage); + int32_t PlayVibratorEffectCheckAuthAndParam(int32_t count, int32_t usage); std::mutex isVibrationPriorityReadyMutex_; static bool isVibrationPriorityReady_; VibratorHdiConnection &vibratorHdiConnection_ = VibratorHdiConnection::GetInstance(); diff --git a/services/miscdevice_service/include/miscdevice_service_stub.h b/services/miscdevice_service/include/miscdevice_service_stub.h deleted file mode 100644 index bca5639..0000000 --- a/services/miscdevice_service/include/miscdevice_service_stub.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - */ - -#ifndef MISCDEVICE_SERVICE_STUB_H -#define MISCDEVICE_SERVICE_STUB_H - -#include - -#include "iremote_stub.h" -#include "message_parcel.h" -#include "nocopyable.h" - -#include "i_miscdevice_service.h" - -namespace OHOS { -namespace Sensors { -using ServiceStub = std::function; - -class MiscdeviceServiceStub : public IRemoteStub { -public: - MiscdeviceServiceStub(); - virtual ~MiscdeviceServiceStub(); - virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) override; - -private: - DISALLOW_COPY_AND_MOVE(MiscdeviceServiceStub); - - int32_t IsAbilityAvailableStub(MessageParcel &data, MessageParcel &reply); - int32_t IsVibratorEffectAvailableStub(MessageParcel &data, MessageParcel &reply); - int32_t GetVibratorIdListStub(MessageParcel &data, MessageParcel &reply); - int32_t VibrateStub(MessageParcel &data, MessageParcel &reply); - int32_t PlayVibratorEffectStub(MessageParcel &data, MessageParcel &reply); - int32_t SetVibratorParameterStub(MessageParcel &data, MessageParcel &reply); - int32_t GetVibratorParameterStub(MessageParcel &data, MessageParcel &reply); -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - int32_t PlayVibratorCustomStub(MessageParcel &data, MessageParcel &reply); -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - int32_t StopVibratorAllStub(MessageParcel &data, MessageParcel &reply); - int32_t StopVibratorByModeStub(MessageParcel &data, MessageParcel &reply); - int32_t IsSupportEffectStub(MessageParcel &data, MessageParcel &reply); - int32_t GetLightListStub(MessageParcel &data, MessageParcel &reply); - int32_t TurnOnStub(MessageParcel &data, MessageParcel &reply); - int32_t TurnOffStub(MessageParcel &data, MessageParcel &reply); - bool CheckVibratePermission(); - int32_t ProcessRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); - int32_t PlayPatternStub(MessageParcel &data, MessageParcel &reply); - int32_t GetDelayTimeStub(MessageParcel &data, MessageParcel &reply); - int32_t TransferClientRemoteObjectStub(MessageParcel &data, MessageParcel &reply); - int32_t PlayPrimitiveEffectStub(MessageParcel &data, MessageParcel &reply); - int32_t GetVibratorCapacityStub(MessageParcel &data, MessageParcel &reply); -}; -} // namespace Sensors -} // namespace OHOS -#endif // MISCDEVICE_SERVICE_STUB_H diff --git a/services/miscdevice_service/src/miscdevice_service.cpp b/services/miscdevice_service/src/miscdevice_service.cpp index 9f05623..c41816b 100644 --- a/services/miscdevice_service/src/miscdevice_service.cpp +++ b/services/miscdevice_service/src/miscdevice_service.cpp @@ -20,6 +20,9 @@ #include #include "death_recipient_template.h" +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE +#include "hisysevent.h" +#endif // HIVIEWDFX_HISYSEVENT_ENABLE #ifdef MEMMGR_ENABLE #include "iservice_registry.h" #include "mem_mgr_client.h" @@ -35,6 +38,7 @@ #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM #include "parameters.h" +#include "permission_util.h" #include "default_vibrator_decoder.h" #include "default_vibrator_decoder_factory.h" #include "vibrator_decoder_creator.h" @@ -45,9 +49,13 @@ namespace OHOS { namespace Sensors { +using namespace OHOS::HiviewDFX; namespace { auto g_miscdeviceService = MiscdeviceDelayedSpSingleton::GetInstance(); const bool G_REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(g_miscdeviceService.GetRefPtr()); +const std::string VIBRATE_PERMISSION = "ohos.permission.VIBRATE"; +const std::string LIGHT_PERMISSION = "ohos.permission.SYSTEM_LIGHT_CONTROL"; +constexpr int32_t MAX_LIGHT_COUNT = 0XFF; constexpr int32_t MIN_VIBRATOR_TIME = 0; constexpr int32_t MAX_VIBRATOR_TIME = 1800000; constexpr int32_t MIN_VIBRATOR_COUNT = 1; @@ -321,6 +329,16 @@ bool MiscdeviceService::ShouldIgnoreVibrate(const VibrateInfo &info) int32_t MiscdeviceService::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage) { + PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); + int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); + if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", + HiSysEvent::EventType::SECURITY, "PKG_NAME", "VibrateStub", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); + return PERMISSION_DENIED; + } if ((timeOut <= MIN_VIBRATOR_TIME) || (timeOut > MAX_VIBRATOR_TIME) || (usage >= USAGE_MAX) || (usage < 0)) { MISC_HILOGE("Invalid parameter"); @@ -351,6 +369,16 @@ int32_t MiscdeviceService::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t int32_t MiscdeviceService::StopVibrator(int32_t vibratorId) { std::lock_guard lock(vibratorThreadMutex_); + PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); + int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); + if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", + HiSysEvent::EventType::SECURITY, "PKG_NAME", "StopVibratorStub", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + MISC_HILOGE("Result:%{public}d", ret); + return PERMISSION_DENIED; + } #if defined (OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM) && defined (HDF_DRIVERS_INTERFACE_VIBRATOR) if ((vibratorThread_ == nullptr) || (!vibratorThread_->IsRunning() && !vibratorHdiConnection_.IsVibratorRunning())) { @@ -378,9 +406,10 @@ int32_t MiscdeviceService::StopVibrator(int32_t vibratorId) int32_t MiscdeviceService::PlayVibratorEffect(int32_t vibratorId, const std::string &effect, int32_t count, int32_t usage, bool systemUsage) { - if ((count < MIN_VIBRATOR_COUNT) || (count > MAX_VIBRATOR_COUNT) || (usage >= USAGE_MAX) || (usage < 0)) { - MISC_HILOGE("Invalid parameter"); - return PARAMETER_ERROR; + int32_t checkResult = PlayVibratorEffectCheckAuthAndParam(count, usage); + if (checkResult != ERR_OK) { + MISC_HILOGE("CheckAuthAndParam failed, ret:%{public}d", checkResult); + return checkResult; } #ifdef HDF_DRIVERS_INTERFACE_VIBRATOR std::optional effectInfo = vibratorHdiConnection_.GetEffectInfo(effect); @@ -420,6 +449,25 @@ int32_t MiscdeviceService::PlayVibratorEffect(int32_t vibratorId, const std::str return NO_ERROR; } +int32_t MiscdeviceService::PlayVibratorEffectCheckAuthAndParam(int32_t count, int32_t usage) +{ + PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); + int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); + if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", + HiSysEvent::EventType::SECURITY, "PKG_NAME", "PlayVibratorEffectStub", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); + return PERMISSION_DENIED; + } + if ((count < MIN_VIBRATOR_COUNT) || (count > MAX_VIBRATOR_COUNT) || (usage >= USAGE_MAX) || (usage < 0)) { + MISC_HILOGE("Invalid parameter"); + return PARAMETER_ERROR; + } + return ERR_OK; +} + void MiscdeviceService::StartVibrateThread(VibrateInfo info) { if (vibratorThread_ == nullptr) { @@ -447,9 +495,19 @@ void MiscdeviceService::StopVibrateThread() } } -int32_t MiscdeviceService::StopVibrator(int32_t vibratorId, const std::string &mode) +int32_t MiscdeviceService::StopVibratorByMode(int32_t vibratorId, const std::string &mode) { std::lock_guard lock(vibratorThreadMutex_); + PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); + int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); + if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", + HiSysEvent::EventType::SECURITY, "PKG_NAME", "StopVibratorByModeStub", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); + return PERMISSION_DENIED; + } if ((vibratorThread_ == nullptr) || (!vibratorThread_->IsRunning())) { MISC_HILOGD("No vibration, no need to stop"); return ERROR; @@ -503,17 +561,18 @@ std::string MiscdeviceService::GetCurrentTime() } #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM -int32_t MiscdeviceService::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - bool systemUsage, const VibrateParameter ¶meter) +int32_t MiscdeviceService::PlayVibratorCustom(int32_t vibratorId, int32_t fd, int64_t offset, int64_t length, + int32_t usage, bool systemUsage, const VibrateParameter ¶meter) { - if (!(g_capacity.isSupportHdHaptic || g_capacity.isSupportPresetMapping || g_capacity.isSupportTimeDelay)) { - MISC_HILOGE("The device does not support this operation"); - return IS_NOT_SUPPORTED; - } - if ((usage >= USAGE_MAX) || (usage < 0) || (!CheckVibratorParmeters(parameter))) { - MISC_HILOGE("Invalid parameter, usage:%{public}d", usage); - return PARAMETER_ERROR; - } + int32_t checkResult = CheckAuthAndParam(usage, parameter); + if (checkResult != ERR_OK) { + MISC_HILOGE("CheckAuthAndParam failed, ret:%{public}d", checkResult); + return checkResult; + } + RawFileDescriptor rawFd; + rawFd.fd = fd; + rawFd.offset = offset; + rawFd.length = length; JsonParser parser(rawFd); VibratorDecoderCreator creator; std::unique_ptr decoder(creator.CreateDecoder(parser)); @@ -555,6 +614,29 @@ int32_t MiscdeviceService::PlayVibratorCustom(int32_t vibratorId, const RawFileD } #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM +int32_t MiscdeviceService::CheckAuthAndParam(int32_t usage, const VibrateParameter ¶meter) +{ + PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); + int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); + if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", + HiSysEvent::EventType::SECURITY, "PKG_NAME", "PlayVibratorCustomStub", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); + return PERMISSION_DENIED; + } + if (!(g_capacity.isSupportHdHaptic || g_capacity.isSupportPresetMapping || g_capacity.isSupportTimeDelay)) { + MISC_HILOGE("The device does not support this operation"); + return IS_NOT_SUPPORTED; + } + if ((usage >= USAGE_MAX) || (usage < 0) || (!CheckVibratorParmeters(parameter))) { + MISC_HILOGE("Invalid parameter, usage:%{public}d", usage); + return PARAMETER_ERROR; + } + return ERR_OK; +} + std::string MiscdeviceService::GetPackageName(AccessTokenID tokenId) { std::string packageName; @@ -587,7 +669,7 @@ std::string MiscdeviceService::GetPackageName(AccessTokenID tokenId) return packageName; } -std::vector MiscdeviceService::GetLightList() +int32_t MiscdeviceService::GetLightList(std::vector &lightInfoIpcList) { std::lock_guard lightInfosLock(lightInfosMutex_); std::string packageName = GetPackageName(GetCallingTokenID()); @@ -596,11 +678,31 @@ std::vector MiscdeviceService::GetLightList() if (ret != ERR_OK) { MISC_HILOGE("GetLightList failed, ret:%{public}d", ret); } - return lightInfos_; + size_t lightCount = lightInfos_.size(); + MISC_HILOGI("lightCount:%{public}zu", lightCount); + if (lightCount > MAX_LIGHT_COUNT) { + lightCount = MAX_LIGHT_COUNT; + } + for (size_t i = 0; i < lightCount; ++i) { + lightInfoIpcList.push_back(lightInfos_[i]); + } + return ERR_OK; } -int32_t MiscdeviceService::TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) +int32_t MiscdeviceService::TurnOn(int32_t lightId, int32_t singleColor, const LightAnimationIPC &animation) { + PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); + int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), LIGHT_PERMISSION); + if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "LIGHT_PERMISSIONS_EXCEPTION", HiSysEvent::EventType::SECURITY, + "PKG_NAME", "turnOnStub", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + MISC_HILOGE("CheckLightPermission failed, ret:%{public}d", ret); + return PERMISSION_DENIED; + } + LightColor color; + color.singleColor = singleColor; std::string packageName = GetPackageName(GetCallingTokenID()); MISC_HILOGI("TurnOn, package:%{public}s", packageName.c_str()); if (!IsValid(lightId)) { @@ -611,7 +713,7 @@ int32_t MiscdeviceService::TurnOn(int32_t lightId, const LightColor &color, cons MISC_HILOGE("animation is invalid"); return MISCDEVICE_NATIVE_SAM_ERR; } - int32_t ret = lightHdiConnection_.TurnOn(lightId, color, animation); + ret = lightHdiConnection_.TurnOn(lightId, color, animation); if (ret != ERR_OK) { MISC_HILOGE("TurnOn failed, error:%{public}d", ret); return ERROR; @@ -621,13 +723,23 @@ int32_t MiscdeviceService::TurnOn(int32_t lightId, const LightColor &color, cons int32_t MiscdeviceService::TurnOff(int32_t lightId) { + PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); + int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), LIGHT_PERMISSION); + if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "LIGHT_PERMISSIONS_EXCEPTION", HiSysEvent::EventType::SECURITY, + "PKG_NAME", "TurnOffStub", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + MISC_HILOGE("CheckLightPermission failed, ret:%{public}d", ret); + return PERMISSION_DENIED; + } std::string packageName = GetPackageName(GetCallingTokenID()); MISC_HILOGI("TurnOff, package:%{public}s", packageName.c_str()); if (!IsValid(lightId)) { MISC_HILOGE("lightId is invalid, lightId:%{public}d", lightId); return MISCDEVICE_NATIVE_SAM_ERR; } - int32_t ret = lightHdiConnection_.TurnOff(lightId); + ret = lightHdiConnection_.TurnOff(lightId); if (ret != ERR_OK) { MISC_HILOGE("TurnOff failed, error:%{public}d", ret); return ERROR; @@ -660,14 +772,14 @@ int32_t MiscdeviceService::Dump(int32_t fd, const std::vector &a int32_t MiscdeviceService::PlayPattern(const VibratePattern &pattern, int32_t usage, bool systemUsage, const VibrateParameter ¶meter) { - if ((usage >= USAGE_MAX) || (usage < 0) || (!CheckVibratorParmeters(parameter))) { - MISC_HILOGE("Invalid parameter, usage:%{public}d", usage); - return PARAMETER_ERROR; - } - VibratePattern vibratePattern = { - .startTime = 0, - .events = pattern.events - }; + int32_t checkResult = PlayPatternCheckAuthAndParam(usage, parameter); + if (checkResult != ERR_OK) { + MISC_HILOGE("CheckAuthAndParam failed, ret:%{public}d", checkResult); + return checkResult; + } + VibratePattern vibratePattern; + vibratePattern.startTime = 0; + vibratePattern.events = pattern.events; std::vector patterns = {vibratePattern}; VibratePackage package = { .patterns = patterns @@ -710,6 +822,25 @@ int32_t MiscdeviceService::PlayPattern(const VibratePattern &pattern, int32_t us return ERR_OK; } +int32_t MiscdeviceService::PlayPatternCheckAuthAndParam(int32_t usage, const VibrateParameter ¶meter) +{ + PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); + int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); + if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", + HiSysEvent::EventType::SECURITY, "PKG_NAME", "PlayPatternStub", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); + return PERMISSION_DENIED; + } + if ((usage >= USAGE_MAX) || (usage < 0) || (!CheckVibratorParmeters(parameter))) { + MISC_HILOGE("Invalid parameter, usage:%{public}d", usage); + return PARAMETER_ERROR; + } + return ERR_OK; +} + int32_t MiscdeviceService::GetDelayTime(int32_t &delayTime) { std::string packageName = GetPackageName(GetCallingTokenID()); @@ -864,9 +995,10 @@ void MiscdeviceService::DestroyClientPid(const sptr &vibratorServ int32_t MiscdeviceService::PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, int32_t usage, bool systemUsage, int32_t count) { - if ((intensity <= INTENSITY_MIN) || (intensity > INTENSITY_MAX) || (usage >= USAGE_MAX) || (usage < 0)) { - MISC_HILOGE("Invalid parameter"); - return PARAMETER_ERROR; + int32_t checkResult = PlayPrimitiveEffectCheckAuthAndParam(intensity, usage); + if (checkResult != ERR_OK) { + MISC_HILOGE("CheckAuthAndParam failed, ret:%{public}d", checkResult); + return checkResult; } #ifdef HDF_DRIVERS_INTERFACE_VIBRATOR std::optional effectInfo = vibratorHdiConnection_.GetEffectInfo(effect); @@ -906,6 +1038,25 @@ int32_t MiscdeviceService::PlayPrimitiveEffect(int32_t vibratorId, const std::st return NO_ERROR; } +int32_t MiscdeviceService::PlayPrimitiveEffectCheckAuthAndParam(int32_t intensity, int32_t usage) +{ + PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); + int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); + if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", + HiSysEvent::EventType::SECURITY, "PKG_NAME", "PlayPrimitiveEffectStub", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); + return PERMISSION_DENIED; + } + if ((intensity <= INTENSITY_MIN) || (intensity > INTENSITY_MAX) || (usage >= USAGE_MAX) || (usage < 0)) { + MISC_HILOGE("Invalid parameter"); + return PARAMETER_ERROR; + } + return ERR_OK; +} + int32_t MiscdeviceService::GetVibratorCapacity(VibratorCapacity &capacity) { capacity = g_capacity; diff --git a/services/miscdevice_service/src/miscdevice_service_stub.cpp b/services/miscdevice_service/src/miscdevice_service_stub.cpp deleted file mode 100644 index f9d995a..0000000 --- a/services/miscdevice_service/src/miscdevice_service_stub.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/* - * 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 "miscdevice_service_stub.h" - -#include -#include - -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE -#include "hisysevent.h" -#endif // HIVIEWDFX_HISYSEVENT_ENABLE -#include "ipc_skeleton.h" -#include "message_parcel.h" -#include "securec.h" - -#include "permission_util.h" -#include "sensors_errors.h" - -#undef LOG_TAG -#define LOG_TAG "MiscdeviceServiceStub" - -namespace OHOS { -namespace Sensors { -using namespace OHOS::HiviewDFX; - -namespace { -const std::string VIBRATE_PERMISSION = "ohos.permission.VIBRATE"; -const std::string LIGHT_PERMISSION = "ohos.permission.SYSTEM_LIGHT_CONTROL"; -} // namespace - -MiscdeviceServiceStub::MiscdeviceServiceStub() {} - -MiscdeviceServiceStub::~MiscdeviceServiceStub() {} - -int32_t MiscdeviceServiceStub::VibrateStub(MessageParcel &data, MessageParcel &reply) -{ - PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); - int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); - if (ret != PERMISSION_GRANTED) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", - HiSysEvent::EventType::SECURITY, "PKG_NAME", "VibrateStub", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); - return PERMISSION_DENIED; - } - int32_t vibratorId; - int32_t duration; - int32_t usage; - bool systemUsage; - if ((!data.ReadInt32(vibratorId)) || (!data.ReadInt32(duration)) || (!data.ReadInt32(usage))|| - (!data.ReadBool(systemUsage))) { - MISC_HILOGE("Parcel read failed"); - return ERROR; - } - return Vibrate(vibratorId, duration, usage, systemUsage); -} - -int32_t MiscdeviceServiceStub::StopVibratorAllStub(MessageParcel &data, MessageParcel &reply) -{ - PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); - int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); - if (ret != PERMISSION_GRANTED) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", - HiSysEvent::EventType::SECURITY, "PKG_NAME", "StopVibratorStub", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("Result:%{public}d", ret); - return PERMISSION_DENIED; - } - int32_t vibratorId; - if (!data.ReadInt32(vibratorId)) { - MISC_HILOGE("Parcel read failed"); - return ERROR; - } - return StopVibrator(vibratorId); -} - -int32_t MiscdeviceServiceStub::PlayVibratorEffectStub(MessageParcel &data, MessageParcel &reply) -{ - PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); - int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); - if (ret != PERMISSION_GRANTED) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", - HiSysEvent::EventType::SECURITY, "PKG_NAME", "PlayVibratorEffectStub", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); - return PERMISSION_DENIED; - } - int32_t vibratorId; - std::string effect; - int32_t count; - int32_t usage; - bool systemUsage; - if ((!data.ReadInt32(vibratorId)) || (!data.ReadString(effect)) || - (!data.ReadInt32(count)) || (!data.ReadInt32(usage)) || (!data.ReadBool(systemUsage))) { - MISC_HILOGE("Parcel read failed"); - return ERROR; - } - return PlayVibratorEffect(vibratorId, effect, count, usage, systemUsage); -} - -int32_t MiscdeviceServiceStub::StopVibratorByModeStub(MessageParcel &data, MessageParcel &reply) -{ - PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); - int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); - if (ret != PERMISSION_GRANTED) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", - HiSysEvent::EventType::SECURITY, "PKG_NAME", "StopVibratorByModeStub", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); - return PERMISSION_DENIED; - } - int32_t vibratorId; - std::string mode; - if ((!data.ReadInt32(vibratorId)) || (!data.ReadString(mode))) { - MISC_HILOGE("Parcel read failed"); - return ERROR; - } - return StopVibrator(vibratorId, mode); -} - -int32_t MiscdeviceServiceStub::IsSupportEffectStub(MessageParcel &data, MessageParcel &reply) -{ - std::string effect; - if (!data.ReadString(effect)) { - MISC_HILOGE("Parcel read effect failed"); - return ERROR; - } - bool state = false; - int32_t ret = IsSupportEffect(effect, state); - if (ret != NO_ERROR) { - MISC_HILOGE("Query support effect failed"); - return ret; - } - if (!reply.WriteBool(state)) { - MISC_HILOGE("Parcel write state failed"); - } - return ret; -} - -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM -int32_t MiscdeviceServiceStub::PlayVibratorCustomStub(MessageParcel &data, MessageParcel &reply) -{ - PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); - int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); - if (ret != PERMISSION_GRANTED) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", - HiSysEvent::EventType::SECURITY, "PKG_NAME", "PlayVibratorCustomStub", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); - return PERMISSION_DENIED; - } - int32_t vibratorId; - if (!data.ReadInt32(vibratorId)) { - MISC_HILOGE("Parcel read vibratorId failed"); - return ERROR; - } - int32_t usage; - bool systemUsage; - if (!data.ReadInt32(usage) || !data.ReadBool(systemUsage)) { - MISC_HILOGE("Parcel read failed"); - return ERROR; - } - VibrateParameter vibrateParameter; - auto parameter = vibrateParameter.Unmarshalling(data); - if (!parameter.has_value()) { - MISC_HILOGE("Parameter Unmarshalling failed"); - return ERROR; - } - RawFileDescriptor rawFd; - if (!data.ReadInt64(rawFd.offset)) { - MISC_HILOGE("Parcel read offset failed"); - return ERROR; - } - if (!data.ReadInt64(rawFd.length)) { - MISC_HILOGE("Parcel read length failed"); - return ERROR; - } - rawFd.fd = data.ReadFileDescriptor(); - if (rawFd.fd < 0) { - MISC_HILOGE("Parcel ReadFileDescriptor failed"); - return ERROR; - } - ret = PlayVibratorCustom(vibratorId, rawFd, usage, systemUsage, parameter.value()); - if (ret != ERR_OK) { - MISC_HILOGD("PlayVibratorCustom failed, ret:%{public}d", ret); - return ret; - } - return ret; -} -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - -int32_t MiscdeviceServiceStub::GetLightListStub(MessageParcel &data, MessageParcel &reply) -{ - (void)data; - std::vector lightInfos(GetLightList()); - size_t lightCount = lightInfos.size(); - MISC_HILOGI("lightCount:%{public}zu", lightCount); - if (!reply.WriteUint32(lightCount)) { - MISC_HILOGE("Parcel write failed"); - return WRITE_MSG_ERR; - } - for (size_t i = 0; i < lightCount; ++i) { - if (!lightInfos[i].Marshalling(reply)) { - MISC_HILOGE("lightInfo %{public}zu marshalling failed", i); - return WRITE_MSG_ERR; - } - } - return NO_ERROR; -} - -int32_t MiscdeviceServiceStub::TurnOnStub(MessageParcel &data, MessageParcel &reply) -{ - PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); - int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), LIGHT_PERMISSION); - if (ret != PERMISSION_GRANTED) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "LIGHT_PERMISSIONS_EXCEPTION", - HiSysEvent::EventType::SECURITY, "PKG_NAME", "turnOnStub", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("CheckLightPermission failed, ret:%{public}d", ret); - return PERMISSION_DENIED; - } - int32_t lightId = data.ReadInt32(); - LightColor lightColor; - lightColor.singleColor = data.ReadInt32(); - LightAnimationIPC lightAnimation; - auto tmpAnimation = lightAnimation.Unmarshalling(data); - CHKPR(tmpAnimation, ERROR); - return TurnOn(lightId, lightColor, *tmpAnimation); -} - -int32_t MiscdeviceServiceStub::TurnOffStub(MessageParcel &data, MessageParcel &reply) -{ - PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); - int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), LIGHT_PERMISSION); - if (ret != PERMISSION_GRANTED) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "LIGHT_PERMISSIONS_EXCEPTION", - HiSysEvent::EventType::SECURITY, "PKG_NAME", "TurnOffStub", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("CheckLightPermission failed, ret:%{public}d", ret); - return PERMISSION_DENIED; - } - int32_t lightId = data.ReadInt32(); - return TurnOff(lightId); -} - -int32_t MiscdeviceServiceStub::ProcessRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - switch (code) { - case static_cast(MiscdeviceInterfaceCode::VIBRATE): { - return VibrateStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::PLAY_VIBRATOR_EFFECT): { - return PlayVibratorEffectStub(data, reply); - } -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - case static_cast(MiscdeviceInterfaceCode::PLAY_VIBRATOR_CUSTOM): { - return PlayVibratorCustomStub(data, reply); - } -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM - case static_cast(MiscdeviceInterfaceCode::STOP_VIBRATOR_ALL): { - return StopVibratorAllStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::STOP_VIBRATOR_BY_MODE): { - return StopVibratorByModeStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::IS_SUPPORT_EFFECT): { - return IsSupportEffectStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::GET_LIGHT_LIST): { - return GetLightListStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::TURN_ON): { - return TurnOnStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::TURN_OFF): { - return TurnOffStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::PlAY_PATTERN): { - return PlayPatternStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::GET_DELAY_TIME): { - return GetDelayTimeStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::TRANSFER_CLIENT_REMOTE_OBJECT): { - return TransferClientRemoteObjectStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::PLAY_PRIMITIVE_EFFECT): { - return PlayPrimitiveEffectStub(data, reply); - } - case static_cast(MiscdeviceInterfaceCode::GET_VIBRATOR_CAPACITY): { - return GetVibratorCapacityStub(data, reply); - } - default: { - MISC_HILOGD("Remoterequest no member function default process"); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - } -} - -int32_t MiscdeviceServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - MISC_HILOGD("Remoterequest begin, cmd:%{public}u", code); - std::u16string descriptor = MiscdeviceServiceStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - MISC_HILOGE("Client and service descriptors are inconsistent"); - return OBJECT_NULL; - } - return ProcessRemoteRequest(code, data, reply, option); -} - -int32_t MiscdeviceServiceStub::PlayPatternStub(MessageParcel &data, MessageParcel &reply) -{ - CALL_LOG_ENTER; - PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); - int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); - if (ret != PERMISSION_GRANTED) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", - HiSysEvent::EventType::SECURITY, "PKG_NAME", "PlayPatternStub", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); - return PERMISSION_DENIED; - } - VibratePattern vibratePattern; - auto pattern = vibratePattern.Unmarshalling(data); - if (!pattern.has_value()) { - MISC_HILOGE("Pattern Unmarshalling failed"); - return ERROR; - } - int32_t usage = 0; - if (!data.ReadInt32(usage)) { - MISC_HILOGE("Parcel read usage failed"); - return ERROR; - } - bool systemUsage = false; - if (!data.ReadBool(systemUsage)) { - MISC_HILOGE("Parcel read systemUsage failed"); - return ERROR; - } - VibrateParameter vibrateParameter; - auto parameter = vibrateParameter.Unmarshalling(data); - if (!parameter.has_value()) { - MISC_HILOGE("Parameter Unmarshalling failed"); - return ERROR; - } - return PlayPattern(pattern.value(), usage, systemUsage, parameter.value()); -} - -int32_t MiscdeviceServiceStub::GetDelayTimeStub(MessageParcel &data, MessageParcel &reply) -{ - CALL_LOG_ENTER; - int32_t delayTime = 0; - if (GetDelayTime(delayTime) != ERR_OK) { - MISC_HILOGE("GetDelayTime failed"); - return ERROR; - } - if (!reply.WriteInt32(delayTime)) { - MISC_HILOGE("Failed, write delayTime failed"); - return ERROR; - } - return NO_ERROR; -} - -int32_t MiscdeviceServiceStub::TransferClientRemoteObjectStub(MessageParcel &data, MessageParcel &reply) -{ - CALL_LOG_ENTER; - sptr vibratorServiceClient = data.ReadRemoteObject(); - if (vibratorServiceClient == nullptr) { - MISC_HILOGE("vibratorServiceClient is null"); - return ERROR; - } - return TransferClientRemoteObject(vibratorServiceClient); -} - -int32_t MiscdeviceServiceStub::PlayPrimitiveEffectStub(MessageParcel &data, MessageParcel &reply) -{ - PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); - int32_t ret = permissionUtil.CheckVibratePermission(this->GetCallingTokenID(), VIBRATE_PERMISSION); - if (ret != PERMISSION_GRANTED) { -#ifdef HIVIEWDFX_HISYSEVENT_ENABLE - HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "VIBRATOR_PERMISSIONS_EXCEPTION", - HiSysEvent::EventType::SECURITY, "PKG_NAME", "PlayPrimitiveEffectStub", "ERROR_CODE", ret); -#endif // HIVIEWDFX_HISYSEVENT_ENABLE - MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); - return PERMISSION_DENIED; - } - int32_t vibratorId = 0; - std::string effect; - int32_t intensity = 0; - int32_t usage = 0; - bool systemUsage = false; - int32_t count = 0; - if ((!data.ReadInt32(vibratorId)) || (!data.ReadString(effect)) || - (!data.ReadInt32(intensity)) || (!data.ReadInt32(usage)) || (!data.ReadBool(systemUsage)) || - (!data.ReadInt32(count))) { - MISC_HILOGE("Parcel read failed"); - return ERROR; - } - return PlayPrimitiveEffect(vibratorId, effect, intensity, usage, systemUsage, count); -} - -int32_t MiscdeviceServiceStub::GetVibratorCapacityStub(MessageParcel &data, MessageParcel &reply) -{ - VibratorCapacity capacity; - int32_t ret = GetVibratorCapacity(capacity); - if (ret != NO_ERROR) { - MISC_HILOGE("Query support custom vibration failed"); - return ret; - } - if (!capacity.Marshalling(reply)) { - MISC_HILOGE("VibratorCapacity marshalling failed"); - return WRITE_MSG_ERR; - } - return ret; -} -} // namespace Sensors -} // namespace OHOS diff --git a/test/fuzztest/service/getdelaytimestub_fuzzer/BUILD.gn b/test/fuzztest/service/getdelaytimestub_fuzzer/BUILD.gn index 21a97f3..38f4d7a 100644 --- a/test/fuzztest/service/getdelaytimestub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/getdelaytimestub_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("GetDelayTimeStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/getdelaytimestub_fuzzer/getdelaytimestub_fuzzer.cpp b/test/fuzztest/service/getdelaytimestub_fuzzer/getdelaytimestub_fuzzer.cpp index 8734462..46f4966 100644 --- a/test/fuzztest/service/getdelaytimestub_fuzzer/getdelaytimestub_fuzzer.cpp +++ b/test/fuzztest/service/getdelaytimestub_fuzzer/getdelaytimestub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::GET_DELAY_TIME), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_GET_DELAY_TIME), datas, reply, option); return true; } diff --git a/test/fuzztest/service/getlightliststub_fuzzer/BUILD.gn b/test/fuzztest/service/getlightliststub_fuzzer/BUILD.gn index 98fc715..f82fad6 100644 --- a/test/fuzztest/service/getlightliststub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/getlightliststub_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("GetLightListStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/getlightliststub_fuzzer/getlightliststub_fuzzer.cpp b/test/fuzztest/service/getlightliststub_fuzzer/getlightliststub_fuzzer.cpp index 22f9e04..ed0f00d 100644 --- a/test/fuzztest/service/getlightliststub_fuzzer/getlightliststub_fuzzer.cpp +++ b/test/fuzztest/service/getlightliststub_fuzzer/getlightliststub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::GET_LIGHT_LIST), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_GET_LIGHT_LIST), datas, reply, option); return true; } diff --git a/test/fuzztest/service/getvibratorcapacitystub_fuzzer/BUILD.gn b/test/fuzztest/service/getvibratorcapacitystub_fuzzer/BUILD.gn index 8718908..dca5557 100644 --- a/test/fuzztest/service/getvibratorcapacitystub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/getvibratorcapacitystub_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("GetVibratorCapacityStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/getvibratorcapacitystub_fuzzer/getvibratorcapacitystub_fuzzer.cpp b/test/fuzztest/service/getvibratorcapacitystub_fuzzer/getvibratorcapacitystub_fuzzer.cpp index 0d7aa62..a1ac5a1 100644 --- a/test/fuzztest/service/getvibratorcapacitystub_fuzzer/getvibratorcapacitystub_fuzzer.cpp +++ b/test/fuzztest/service/getvibratorcapacitystub_fuzzer/getvibratorcapacitystub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::GET_VIBRATOR_CAPACITY), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_GET_VIBRATOR_CAPACITY), datas, reply, option); return true; } diff --git a/test/fuzztest/service/issupporteffectstub_fuzzer/BUILD.gn b/test/fuzztest/service/issupporteffectstub_fuzzer/BUILD.gn index f9d151d..c009c52 100644 --- a/test/fuzztest/service/issupporteffectstub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/issupporteffectstub_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("IsSupportEffectStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/issupporteffectstub_fuzzer/issupporteffectstub_fuzzer.cpp b/test/fuzztest/service/issupporteffectstub_fuzzer/issupporteffectstub_fuzzer.cpp index e1c9549..a6a8957 100644 --- a/test/fuzztest/service/issupporteffectstub_fuzzer/issupporteffectstub_fuzzer.cpp +++ b/test/fuzztest/service/issupporteffectstub_fuzzer/issupporteffectstub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::IS_SUPPORT_EFFECT), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_IS_SUPPORT_EFFECT), datas, reply, option); return true; } diff --git a/test/fuzztest/service/playpatternstub_fuzzer/BUILD.gn b/test/fuzztest/service/playpatternstub_fuzzer/BUILD.gn index 2a584d1..ed8b84b 100644 --- a/test/fuzztest/service/playpatternstub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/playpatternstub_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("PlayPatternStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/playpatternstub_fuzzer/playpatternstub_fuzzer.cpp b/test/fuzztest/service/playpatternstub_fuzzer/playpatternstub_fuzzer.cpp index cf8111e..9179cab 100644 --- a/test/fuzztest/service/playpatternstub_fuzzer/playpatternstub_fuzzer.cpp +++ b/test/fuzztest/service/playpatternstub_fuzzer/playpatternstub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::PlAY_PATTERN), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_PLAY_PATTERN), datas, reply, option); return true; } diff --git a/test/fuzztest/service/playprimitiveeffectstub_fuzzer/BUILD.gn b/test/fuzztest/service/playprimitiveeffectstub_fuzzer/BUILD.gn index 69ec08c..7418684 100644 --- a/test/fuzztest/service/playprimitiveeffectstub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/playprimitiveeffectstub_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("PlayPrimitiveEffectStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/playprimitiveeffectstub_fuzzer/playprimitiveeffectstub_fuzzer.cpp b/test/fuzztest/service/playprimitiveeffectstub_fuzzer/playprimitiveeffectstub_fuzzer.cpp index 077c9a6..74750ff 100644 --- a/test/fuzztest/service/playprimitiveeffectstub_fuzzer/playprimitiveeffectstub_fuzzer.cpp +++ b/test/fuzztest/service/playprimitiveeffectstub_fuzzer/playprimitiveeffectstub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::PLAY_PRIMITIVE_EFFECT), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_PLAY_PRIMITIVE_EFFECT), datas, reply, option); return true; } diff --git a/test/fuzztest/service/playvibratorcustomstub_fuzzer/BUILD.gn b/test/fuzztest/service/playvibratorcustomstub_fuzzer/BUILD.gn index 8a039bf..670b6a3 100644 --- a/test/fuzztest/service/playvibratorcustomstub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/playvibratorcustomstub_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("PlayVibratorCustomStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/playvibratorcustomstub_fuzzer/playvibratorcustomstub_fuzzer.cpp b/test/fuzztest/service/playvibratorcustomstub_fuzzer/playvibratorcustomstub_fuzzer.cpp index 9e3f586..917e4e1 100644 --- a/test/fuzztest/service/playvibratorcustomstub_fuzzer/playvibratorcustomstub_fuzzer.cpp +++ b/test/fuzztest/service/playvibratorcustomstub_fuzzer/playvibratorcustomstub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::PLAY_VIBRATOR_CUSTOM), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_PLAY_VIBRATOR_CUSTOM), datas, reply, option); return true; } diff --git a/test/fuzztest/service/playvibratoreffectstub_fuzzer/BUILD.gn b/test/fuzztest/service/playvibratoreffectstub_fuzzer/BUILD.gn index f9260c1..90c1bd8 100644 --- a/test/fuzztest/service/playvibratoreffectstub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/playvibratoreffectstub_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("PlayVibratorEffectStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/playvibratoreffectstub_fuzzer/playvibratoreffectstub_fuzzer.cpp b/test/fuzztest/service/playvibratoreffectstub_fuzzer/playvibratoreffectstub_fuzzer.cpp index 60f4679..da278d7 100644 --- a/test/fuzztest/service/playvibratoreffectstub_fuzzer/playvibratoreffectstub_fuzzer.cpp +++ b/test/fuzztest/service/playvibratoreffectstub_fuzzer/playvibratoreffectstub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::PLAY_VIBRATOR_EFFECT), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_PLAY_VIBRATOR_EFFECT), datas, reply, option); return true; } diff --git a/test/fuzztest/service/stopvibratorallstub_fuzzer/BUILD.gn b/test/fuzztest/service/stopvibratorallstub_fuzzer/BUILD.gn index c9c9ebf..9c4e64a 100644 --- a/test/fuzztest/service/stopvibratorallstub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/stopvibratorallstub_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("StopVibratorAllStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/stopvibratorallstub_fuzzer/stopvibratorallstub_fuzzer.cpp b/test/fuzztest/service/stopvibratorallstub_fuzzer/stopvibratorallstub_fuzzer.cpp index 6fe7165..8b68f01 100644 --- a/test/fuzztest/service/stopvibratorallstub_fuzzer/stopvibratorallstub_fuzzer.cpp +++ b/test/fuzztest/service/stopvibratorallstub_fuzzer/stopvibratorallstub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::STOP_VIBRATOR_ALL), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_STOP_VIBRATOR), datas, reply, option); return true; } diff --git a/test/fuzztest/service/stopvibratorbymodestub_fuzzer/BUILD.gn b/test/fuzztest/service/stopvibratorbymodestub_fuzzer/BUILD.gn index 0a3abf1..ffc80db 100644 --- a/test/fuzztest/service/stopvibratorbymodestub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/stopvibratorbymodestub_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("StopVibratorByModeStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/stopvibratorbymodestub_fuzzer/stopvibratorbymodestub_fuzzer.cpp b/test/fuzztest/service/stopvibratorbymodestub_fuzzer/stopvibratorbymodestub_fuzzer.cpp index 268601f..ee2466a 100644 --- a/test/fuzztest/service/stopvibratorbymodestub_fuzzer/stopvibratorbymodestub_fuzzer.cpp +++ b/test/fuzztest/service/stopvibratorbymodestub_fuzzer/stopvibratorbymodestub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::STOP_VIBRATOR_BY_MODE), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_STOP_VIBRATOR_BY_MODE), datas, reply, option); return true; } diff --git a/test/fuzztest/service/transferclientremoteobjectstub_fuzzer/BUILD.gn b/test/fuzztest/service/transferclientremoteobjectstub_fuzzer/BUILD.gn index 9afa0bd..66fe84e 100644 --- a/test/fuzztest/service/transferclientremoteobjectstub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/transferclientremoteobjectstub_fuzzer/BUILD.gn @@ -43,6 +43,7 @@ ohos_fuzztest("TransferClientRemoteObjectStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/transferclientremoteobjectstub_fuzzer/transferclientremoteobjectstub_fuzzer.cpp b/test/fuzztest/service/transferclientremoteobjectstub_fuzzer/transferclientremoteobjectstub_fuzzer.cpp index 4e4da6f..909c311 100644 --- a/test/fuzztest/service/transferclientremoteobjectstub_fuzzer/transferclientremoteobjectstub_fuzzer.cpp +++ b/test/fuzztest/service/transferclientremoteobjectstub_fuzzer/transferclientremoteobjectstub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::TRANSFER_CLIENT_REMOTE_OBJECT), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_TRANSFER_CLIENT_REMOTE_OBJECT), datas, reply, option); return true; } diff --git a/test/fuzztest/service/turnoffstub_fuzzer/BUILD.gn b/test/fuzztest/service/turnoffstub_fuzzer/BUILD.gn index 326a39d..c522715 100644 --- a/test/fuzztest/service/turnoffstub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/turnoffstub_fuzzer/BUILD.gn @@ -43,6 +43,7 @@ ohos_fuzztest("TurnOffStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/turnoffstub_fuzzer/turnoffstub_fuzzer.cpp b/test/fuzztest/service/turnoffstub_fuzzer/turnoffstub_fuzzer.cpp index 34e0294..70f7e76 100644 --- a/test/fuzztest/service/turnoffstub_fuzzer/turnoffstub_fuzzer.cpp +++ b/test/fuzztest/service/turnoffstub_fuzzer/turnoffstub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::TURN_OFF), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_TURN_OFF), datas, reply, option); return true; } diff --git a/test/fuzztest/service/turnonstub_fuzzer/BUILD.gn b/test/fuzztest/service/turnonstub_fuzzer/BUILD.gn index 99ee4b7..8076a34 100644 --- a/test/fuzztest/service/turnonstub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/turnonstub_fuzzer/BUILD.gn @@ -43,6 +43,7 @@ ohos_fuzztest("TurnOnStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/turnonstub_fuzzer/turnonstub_fuzzer.cpp b/test/fuzztest/service/turnonstub_fuzzer/turnonstub_fuzzer.cpp index 8eb483a..f3a768e 100644 --- a/test/fuzztest/service/turnonstub_fuzzer/turnonstub_fuzzer.cpp +++ b/test/fuzztest/service/turnonstub_fuzzer/turnonstub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::TURN_ON), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_TURN_ON), datas, reply, option); return true; } diff --git a/test/fuzztest/service/vibratestub_fuzzer/BUILD.gn b/test/fuzztest/service/vibratestub_fuzzer/BUILD.gn index 698efb1..7b8337e 100644 --- a/test/fuzztest/service/vibratestub_fuzzer/BUILD.gn +++ b/test/fuzztest/service/vibratestub_fuzzer/BUILD.gn @@ -43,6 +43,7 @@ ohos_fuzztest("VibrateStubFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/test/fuzztest/service/vibratestub_fuzzer/vibratestub_fuzzer.cpp b/test/fuzztest/service/vibratestub_fuzzer/vibratestub_fuzzer.cpp index 93e3a3e..78dc1c4 100644 --- a/test/fuzztest/service/vibratestub_fuzzer/vibratestub_fuzzer.cpp +++ b/test/fuzztest/service/vibratestub_fuzzer/vibratestub_fuzzer.cpp @@ -69,7 +69,7 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) MessageParcel reply; MessageOption option; g_service->OnStartFuzz(); - g_service->OnRemoteRequest(static_cast(MiscdeviceInterfaceCode::VIBRATE), + g_service->OnRemoteRequest(static_cast(IMiscdeviceServiceIpcCode::COMMAND_VIBRATE), datas, reply, option); return true; } diff --git a/test/fuzztest/service/vibratoronremoterequest_fuzzer/BUILD.gn b/test/fuzztest/service/vibratoronremoterequest_fuzzer/BUILD.gn index 55ec05f..10d568f 100644 --- a/test/fuzztest/service/vibratoronremoterequest_fuzzer/BUILD.gn +++ b/test/fuzztest/service/vibratoronremoterequest_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("VibratorOnRemoteRequestFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_interface_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:miscdevice_service_stub", "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", "$SUBSYSTEM_DIR/services/miscdevice_service:libmiscdevice_service_static", "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", diff --git a/utils/common/include/light_animation_ipc.h b/utils/common/include/light_animation_ipc.h index 47f8535..8761e86 100644 --- a/utils/common/include/light_animation_ipc.h +++ b/utils/common/include/light_animation_ipc.h @@ -31,7 +31,7 @@ public: int32_t GetOffTime() const; void SetOffTime(int32_t offTime); bool ReadFromParcel(Parcel &parcel); - static std::unique_ptr Unmarshalling(Parcel &parcel); + static LightAnimationIPC* Unmarshalling(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; private: diff --git a/utils/common/include/light_info_ipc.h b/utils/common/include/light_info_ipc.h index 5f81d02..100e191 100644 --- a/utils/common/include/light_info_ipc.h +++ b/utils/common/include/light_info_ipc.h @@ -35,7 +35,7 @@ public: int32_t GetLightType() const; void SetLightType(int32_t lightType); bool ReadFromParcel(Parcel &parcel); - static std::unique_ptr Unmarshalling(Parcel &parcel); + static LightInfoIPC* Unmarshalling(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; private: diff --git a/utils/common/include/vibrator_infos.h b/utils/common/include/vibrator_infos.h index 04887f4..6302516 100644 --- a/utils/common/include/vibrator_infos.h +++ b/utils/common/include/vibrator_infos.h @@ -82,7 +82,7 @@ struct VibrateEvent { std::vector points; }; -struct VibratePattern { +struct VibratePattern : public Parcelable { bool operator<(const VibratePattern &rhs) const { return startTime < rhs.startTime; @@ -92,7 +92,7 @@ struct VibratePattern { std::vector events; void Dump() const; bool Marshalling(Parcel &parcel) const; - std::optional Unmarshalling(Parcel &data); + static VibratePattern* Unmarshalling(Parcel &data); }; struct VibratePackage { @@ -101,14 +101,14 @@ struct VibratePackage { void Dump() const; }; -struct VibratorCapacity { +struct VibratorCapacity : public Parcelable { bool isSupportHdHaptic = false; bool isSupportPresetMapping = false; bool isSupportTimeDelay = false; void Dump() const; int32_t GetVibrateMode(); bool Marshalling(Parcel &parcel) const; - std::optional Unmarshalling(Parcel &data); + static VibratorCapacity* Unmarshalling(Parcel &data); }; struct VibrateSlice { @@ -132,13 +132,13 @@ struct VibrateInfo { VibratePackage package; }; -struct VibrateParameter { +struct VibrateParameter : public Parcelable { int32_t intensity = 100; // from 0 to 100 int32_t frequency = 0; // from -100 to 100 int32_t reserved = 0; void Dump() const; bool Marshalling(Parcel &parcel) const; - std::optional Unmarshalling(Parcel &data); + static VibrateParameter* Unmarshalling(Parcel &data); }; } // namespace Sensors } // namespace OHOS diff --git a/utils/common/src/light_animation_ipc.cpp b/utils/common/src/light_animation_ipc.cpp index 6cbc04c..335b072 100644 --- a/utils/common/src/light_animation_ipc.cpp +++ b/utils/common/src/light_animation_ipc.cpp @@ -69,12 +69,12 @@ bool LightAnimationIPC::Marshalling(Parcel &parcel) const return true; } -std::unique_ptr LightAnimationIPC::Unmarshalling(Parcel &parcel) +LightAnimationIPC* LightAnimationIPC::Unmarshalling(Parcel &parcel) { - auto lightAnimation = std::make_unique(); - if (!lightAnimation->ReadFromParcel(parcel)) { + auto lightAnimation = new (std::nothrow) LightAnimationIPC(); + if (lightAnimation != nullptr && !lightAnimation->ReadFromParcel(parcel)) { MISC_HILOGE("ReadFromParcel is failed"); - return nullptr; + lightAnimation = nullptr; } return lightAnimation; } diff --git a/utils/common/src/light_info_ipc.cpp b/utils/common/src/light_info_ipc.cpp index ca6519e..b9fb5af 100644 --- a/utils/common/src/light_info_ipc.cpp +++ b/utils/common/src/light_info_ipc.cpp @@ -83,12 +83,12 @@ bool LightInfoIPC::Marshalling(Parcel &parcel) const return true; } -std::unique_ptr LightInfoIPC::Unmarshalling(Parcel &parcel) +LightInfoIPC* LightInfoIPC::Unmarshalling(Parcel &parcel) { - auto lightInfo = std::make_unique(); - if (!lightInfo->ReadFromParcel(parcel)) { + auto lightInfo = new (std::nothrow) LightInfoIPC(); + if (lightInfo != nullptr && !lightInfo->ReadFromParcel(parcel)) { MISC_HILOGE("ReadFromParcel is failed"); - return nullptr; + lightInfo = nullptr; } return lightInfo; } diff --git a/utils/common/src/vibrator_infos.cpp b/utils/common/src/vibrator_infos.cpp index 8ac1e47..4b3eaee 100644 --- a/utils/common/src/vibrator_infos.cpp +++ b/utils/common/src/vibrator_infos.cpp @@ -95,20 +95,27 @@ bool VibratorCapacity::Marshalling(Parcel &parcel) const return true; } -std::optional VibratorCapacity::Unmarshalling(Parcel &data) +VibratorCapacity* VibratorCapacity::Unmarshalling(Parcel &data) { - VibratorCapacity capacity; - if (!(data.ReadBool(capacity.isSupportHdHaptic))) { + auto capacity = new (std::nothrow) VibratorCapacity(); + if (capacity == nullptr) { + MISC_HILOGE("Read init capacity failed"); + return nullptr; + } + if (!(data.ReadBool(capacity->isSupportHdHaptic))) { MISC_HILOGE("Read isSupportHdHaptic failed"); - return std::nullopt; + capacity = nullptr; + return capacity; } - if (!(data.ReadBool(capacity.isSupportPresetMapping))) { + if (!(data.ReadBool(capacity->isSupportPresetMapping))) { MISC_HILOGE("Read isSupportPresetMapping failed"); - return std::nullopt; + capacity = nullptr; + return capacity; } - if (!(data.ReadBool(capacity.isSupportTimeDelay))) { + if (!(data.ReadBool(capacity->isSupportTimeDelay))) { MISC_HILOGE("Read isSupportTimeDelay failed"); - return std::nullopt; + capacity = nullptr; + return capacity; } return capacity; } @@ -174,79 +181,50 @@ bool VibratePattern::Marshalling(Parcel &parcel) const return true; } -std::optional VibratePattern::Unmarshalling(Parcel &data) +VibratePattern* VibratePattern::Unmarshalling(Parcel &data) { - VibratePattern pattern; - if (!(data.ReadInt32(pattern.startTime))) { - MISC_HILOGE("Read time failed"); - return std::nullopt; - } - if (!(data.ReadInt32(pattern.patternDuration))) { - MISC_HILOGE("Read duration failed"); - return std::nullopt; - } - int32_t eventSize { 0 }; - if (!(data.ReadInt32(eventSize))) { - MISC_HILOGE("Read eventSize failed"); - return std::nullopt; + auto pattern = new (std::nothrow) VibratePattern(); + if (pattern == nullptr || !(data.ReadInt32(pattern->startTime)) || !(data.ReadInt32(pattern->patternDuration))) { + MISC_HILOGE("Read pattern basic info failed"); + pattern = nullptr; + return pattern; } - if (eventSize > MAX_EVENT_SIZE) { - MISC_HILOGE("eventSize exceed the maximum"); - return std::nullopt; + int32_t eventSize{ 0 }; + if (!(data.ReadInt32(eventSize)) || eventSize > MAX_EVENT_SIZE) { + MISC_HILOGE("Read eventSize failed or eventSize exceed the maximum"); + pattern = nullptr; + return pattern; } for (int32_t i = 0; i < eventSize; ++i) { VibrateEvent event; - int32_t tag { -1 }; + int32_t tag{ -1 }; if (!data.ReadInt32(tag)) { MISC_HILOGE("Read type failed"); - return std::nullopt; + pattern = nullptr; + return pattern; } event.tag = static_cast(tag); - if (!data.ReadInt32(event.time)) { - MISC_HILOGE("Read events's time failed"); - return std::nullopt; - } - if (!data.ReadInt32(event.duration)) { - MISC_HILOGE("Read duration failed"); - return std::nullopt; - } - if (!data.ReadInt32(event.intensity)) { - MISC_HILOGE("Read intensity failed"); - return std::nullopt; - } - if (!data.ReadInt32(event.frequency)) { - MISC_HILOGE("Read frequency failed"); - return std::nullopt; + if (!data.ReadInt32(event.time) || !data.ReadInt32(event.duration) || !data.ReadInt32(event.intensity) || + !data.ReadInt32(event.frequency) || !data.ReadInt32(event.index)) { + MISC_HILOGE("Read events info failed"); + pattern = nullptr; + return pattern; } - if (!data.ReadInt32(event.index)) { - MISC_HILOGE("Read index failed"); - return std::nullopt; + int32_t pointSize{ 0 }; + if (!data.ReadInt32(pointSize) || pointSize > MAX_POINT_SIZE) { + MISC_HILOGE("Read pointSize failed or pointSize exceed the maximum"); + pattern = nullptr; + return pattern; } - int32_t pointSize { 0 }; - if (!data.ReadInt32(pointSize)) { - MISC_HILOGE("Read pointSize failed"); - return std::nullopt; - } - if (pointSize > MAX_POINT_SIZE) { - MISC_HILOGE("pointSize exceed the maximum"); - return std::nullopt; - } - pattern.events.emplace_back(event); + pattern->events.emplace_back(event); for (int32_t j = 0; j < pointSize; ++j) { VibrateCurvePoint point; - if (!data.ReadInt32(point.time)) { - MISC_HILOGE("Read points's time failed"); - return std::nullopt; - } - if (!data.ReadInt32(point.intensity)) { - MISC_HILOGE("Read points's intensity failed"); - return std::nullopt; + if (!data.ReadInt32(point.time) || !data.ReadInt32(point.intensity) || !data.ReadInt32(point.frequency)) { + MISC_HILOGE("Read points info time failed"); + pattern = nullptr; + return pattern; } - if (!data.ReadInt32(point.frequency)) { - MISC_HILOGE("Read points's frequency failed"); - return std::nullopt; - } - pattern.events[i].points.emplace_back(point); + pattern->events[i].points.emplace_back(point); } } return pattern; @@ -270,16 +248,16 @@ bool VibrateParameter::Marshalling(Parcel &parcel) const return true; } -std::optional VibrateParameter::Unmarshalling(Parcel &data) +VibrateParameter* VibrateParameter::Unmarshalling(Parcel &data) { - VibrateParameter parameter; - if (!(data.ReadInt32(parameter.intensity))) { - MISC_HILOGE("Read parameter's intensity failed"); - return std::nullopt; + auto parameter = new (std::nothrow) VibrateParameter(); + if (parameter == nullptr) { + MISC_HILOGE("Read init parameter failed"); + return nullptr; } - if (!(data.ReadInt32(parameter.frequency))) { - MISC_HILOGE("Read parameter's frequency failed"); - return std::nullopt; + if (!(data.ReadInt32(parameter->intensity)) && !(data.ReadInt32(parameter->frequency))) { + MISC_HILOGE("Read parameter's intensity failed"); + parameter = nullptr; } return parameter; } -- Gitee