From c713c040d5441769b8169e8837775d1f24f09108 Mon Sep 17 00:00:00 2001 From: rwx1283129 Date: Wed, 8 Nov 2023 06:36:15 +0000 Subject: [PATCH] isolate the user/eng and dump data of sensor Signed-off-by: rwx1283129 Change-Id: I37925b7e4db294ffb89f58d4a61fedffea4ce919 --- .../common/include/i_miscdevice_service.h | 6 +- .../common/include/miscdevice_service_proxy.h | 4 +- .../common/src/miscdevice_service_proxy.cpp | 29 ++--- .../native/light/include/light_client.h | 2 +- frameworks/native/light/src/light_client.cpp | 16 ++- frameworks/native/vibrator/BUILD.gn | 10 +- miscdevice.gni | 7 ++ services/miscdevice_service/BUILD.gn | 30 ++++- .../include/compatible_light_connection.h | 4 +- .../adapter/include/hdi_light_connection.h | 4 +- .../src/compatible_light_connection.cpp | 20 +++- .../adapter/src/hdi_light_connection.cpp | 25 ++--- .../include/i_light_hdi_connection.h | 6 +- .../interface/include/light_hdi_connection.h | 6 +- .../interface/src/light_hdi_connection.cpp | 9 +- .../interface/src/vibrator_hdi_connection.cpp | 4 + .../include/miscdevice_service.h | 8 +- .../src/miscdevice_service.cpp | 19 ++-- .../src/miscdevice_service_stub.cpp | 26 ++--- utils/BUILD.gn | 2 + utils/include/light_animation_ipc.h | 44 ++++++++ utils/include/light_info_ipc.h | 49 +++++++++ utils/src/light_animation_ipc.cpp | 88 +++++++++++++++ utils/src/light_info_ipc.cpp | 103 ++++++++++++++++++ 24 files changed, 426 insertions(+), 95 deletions(-) create mode 100644 utils/include/light_animation_ipc.h create mode 100644 utils/include/light_info_ipc.h create mode 100644 utils/src/light_animation_ipc.cpp create mode 100644 utils/src/light_info_ipc.cpp diff --git a/frameworks/native/common/include/i_miscdevice_service.h b/frameworks/native/common/include/i_miscdevice_service.h index 7018033..0e15a84 100644 --- a/frameworks/native/common/include/i_miscdevice_service.h +++ b/frameworks/native/common/include/i_miscdevice_service.h @@ -22,6 +22,8 @@ #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" @@ -42,8 +44,8 @@ public: 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 LightAnimation &animation) = 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; }; } // namespace Sensors diff --git a/frameworks/native/common/include/miscdevice_service_proxy.h b/frameworks/native/common/include/miscdevice_service_proxy.h index 6384f13..7d029e9 100644 --- a/frameworks/native/common/include/miscdevice_service_proxy.h +++ b/frameworks/native/common/include/miscdevice_service_proxy.h @@ -36,8 +36,8 @@ public: 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 LightAnimation &animation) 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; private: diff --git a/frameworks/native/common/src/miscdevice_service_proxy.cpp b/frameworks/native/common/src/miscdevice_service_proxy.cpp index 2c0f4dd..cd0a8a9 100644 --- a/frameworks/native/common/src/miscdevice_service_proxy.cpp +++ b/frameworks/native/common/src/miscdevice_service_proxy.cpp @@ -230,10 +230,10 @@ int32_t MiscdeviceServiceProxy::PlayVibratorCustom(int32_t vibratorId, const Raw } #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM -std::vector MiscdeviceServiceProxy::GetLightList() +std::vector MiscdeviceServiceProxy::GetLightList() { MessageParcel data; - std::vector lightInfos; + std::vector lightInfos; if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { MISC_HILOGE("WriteInterfaceToken failed"); return lightInfos; @@ -259,23 +259,16 @@ std::vector MiscdeviceServiceProxy::GetLightList() if (lightCount > MAX_LIGHT_COUNT) { lightCount = MAX_LIGHT_COUNT; } + LightInfoIPC lightInfo; for (uint32_t i = 0; i < lightCount; ++i) { - const uint8_t *info = reply.ReadBuffer(sizeof(LightInfo)); - if (info == nullptr) { - MISC_HILOGE("ReadBuffer failed"); - return lightInfos; - } - LightInfo lightInfo; - if (memcpy_s(&lightInfo, sizeof(LightInfo), info, sizeof(LightInfo)) != EOK) { - MISC_HILOGE("memcpy_s failed"); - return lightInfos; - } - lightInfos.push_back(lightInfo); + auto tmpLightInfo = lightInfo.Unmarshalling(reply); + CHKPC(tmpLightInfo); + lightInfos.push_back(*tmpLightInfo); } return lightInfos; } -int32_t MiscdeviceServiceProxy::TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation) +int32_t MiscdeviceServiceProxy::TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) { MessageParcel data; if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { @@ -286,12 +279,12 @@ int32_t MiscdeviceServiceProxy::TurnOn(int32_t lightId, const LightColor &color, MISC_HILOGE("WriteUint32 lightId failed"); return WRITE_MSG_ERR; } - if (!data.WriteBuffer(&color, sizeof(LightColor))) { - MISC_HILOGE("WriteBuffer color failed"); + if (!data.WriteInt32(color.singleColor)) { + MISC_HILOGE("Write color failed"); return WRITE_MSG_ERR; } - if (!data.WriteBuffer(&animation, sizeof(LightAnimation))) { - MISC_HILOGE("WriteBuffer animation failed"); + if (!animation.Marshalling(data)) { + MISC_HILOGE("Write animation failed"); return WRITE_MSG_ERR; } sptr remote = Remote(); diff --git a/frameworks/native/light/include/light_client.h b/frameworks/native/light/include/light_client.h index 2354556..7d17ac3 100644 --- a/frameworks/native/light/include/light_client.h +++ b/frameworks/native/light/include/light_client.h @@ -44,7 +44,7 @@ private: int32_t lightInfoCount_ {-1}; sptr serviceDeathObserver_ = nullptr; sptr miscdeviceProxy_ = nullptr; - std::vector lightInfoList_; + std::vector lightInfoList_; std::mutex clientMutex_; }; } // namespace Sensors diff --git a/frameworks/native/light/src/light_client.cpp b/frameworks/native/light/src/light_client.cpp index 5fcd110..ee78cc6 100644 --- a/frameworks/native/light/src/light_client.cpp +++ b/frameworks/native/light/src/light_client.cpp @@ -87,7 +87,7 @@ bool LightClient::IsLightIdValid(int32_t lightId) return false; } for (const auto &item : lightInfoList_) { - if (lightId == item.lightId) { + if (lightId == item.GetLightId()) { return true; } } @@ -143,7 +143,11 @@ int32_t LightClient::TurnOn(int32_t lightId, const LightColor &color, const Ligh return PARAMETER_ERROR; } CHKPR(miscdeviceProxy_, ERROR); - return miscdeviceProxy_->TurnOn(lightId, color, animation); + LightAnimationIPC animationIPC; + animationIPC.SetMode(animation.mode); + animationIPC.SetOnTime(animation.onTime); + animationIPC.SetOffTime(animation.offTime); + return miscdeviceProxy_->TurnOn(lightId, color, animationIPC); } int32_t LightClient::TurnOff(int32_t lightId) @@ -191,7 +195,13 @@ int32_t LightClient::ConvertLightInfos() lightInfos_ = (LightInfo *)malloc(sizeof(LightInfo) * count); CHKPR(lightInfos_, ERROR); for (size_t i = 0; i < count; ++i) { - *(lightInfos_ + i) = lightInfoList_[i]; + LightInfo *lightInfo = lightInfos_ + i; + errno_t ret = strcpy_s(lightInfo->lightName, NAME_MAX_LEN, + lightInfoList_[i].GetLightName().c_str()); + CHKCR(ret == EOK, ERROR, "strcpy_s error"); + lightInfo->lightId = lightInfoList_[i].GetLightId(); + lightInfo->lightNumber = lightInfoList_[i].GetLightNumber(); + lightInfo->lightType = lightInfoList_[i].GetLightType(); } lightInfoCount_ = static_cast(count); return SUCCESS; diff --git a/frameworks/native/vibrator/BUILD.gn b/frameworks/native/vibrator/BUILD.gn index b071b59..298bf9a 100644 --- a/frameworks/native/vibrator/BUILD.gn +++ b/frameworks/native/vibrator/BUILD.gn @@ -50,8 +50,8 @@ ohos_shared_library("vibrator_interface_native") { deps = [ "$SUBSYSTEM_DIR/frameworks/native/light:light_ndk_header", - "$SUBSYSTEM_DIR/frameworks/native/vibrator:libvibrator_ndk", "$SUBSYSTEM_DIR/frameworks/native/vibrator:libvibrator_native", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:libvibrator_ndk", ] external_deps = [ @@ -80,6 +80,8 @@ ohos_shared_library("libvibrator_native") { "$SUBSYSTEM_DIR/utils/include", ] + deps = [ "$SUBSYSTEM_DIR/utils:libmiscdevice_utils" ] + external_deps = [ "c_utils:utils", "hilog:libhilog", @@ -97,6 +99,8 @@ ohos_shared_library("libvibrator_native") { } group("vibrator_target") { - deps = [ ":vibrator_interface_native", - ":libvibrator_native" ] + deps = [ + ":libvibrator_native", + ":vibrator_interface_native", + ] } diff --git a/miscdevice.gni b/miscdevice.gni index a7f6ed3..9ad3317 100644 --- a/miscdevice.gni +++ b/miscdevice.gni @@ -37,3 +37,10 @@ if (!defined(global_parts_info) || } else { hdf_drivers_interface_light = false } + +if (build_variant == "eng") { + miscdevice_default_defines += [ "BUILD_VARIANT_ENG" ] + miscdevice_build_eng = true +} else { + miscdevice_build_eng = false +} diff --git a/services/miscdevice_service/BUILD.gn b/services/miscdevice_service/BUILD.gn index 789b4f2..b5b42e8 100644 --- a/services/miscdevice_service/BUILD.gn +++ b/services/miscdevice_service/BUILD.gn @@ -16,8 +16,6 @@ import("./../../miscdevice.gni") ohos_shared_library("libmiscdevice_service") { sources = [ - "hdi_connection/adapter/src/compatible_connection.cpp", - "hdi_connection/adapter/src/compatible_light_connection.cpp", "hdi_connection/adapter/src/hdi_connection.cpp", "hdi_connection/interface/src/light_hdi_connection.cpp", "hdi_connection/interface/src/vibrator_hdi_connection.cpp", @@ -38,6 +36,19 @@ ohos_shared_library("libmiscdevice_service") { "//third_party/cJSON", ] + if (miscdevice_build_eng) { + sources += [ + "hdi_connection/adapter/src/compatible_connection.cpp", + "hdi_connection/adapter/src/compatible_light_connection.cpp", + ] + } + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + cflags = [ "-Wno-error=inconsistent-missing-override" ] deps = [ "$SUBSYSTEM_DIR/utils:libmiscdevice_utils" ] @@ -78,8 +89,6 @@ ohos_shared_library("libmiscdevice_service") { ############################################################################# ohos_shared_library("libmiscdevice_service_static") { sources = [ - "hdi_connection/adapter/src/compatible_connection.cpp", - "hdi_connection/adapter/src/compatible_light_connection.cpp", "hdi_connection/adapter/src/hdi_connection.cpp", "hdi_connection/interface/src/light_hdi_connection.cpp", "hdi_connection/interface/src/vibrator_hdi_connection.cpp", @@ -100,6 +109,19 @@ ohos_shared_library("libmiscdevice_service_static") { "//third_party/cJSON", ] + if (miscdevice_build_eng) { + sources += [ + "hdi_connection/adapter/src/compatible_connection.cpp", + "hdi_connection/adapter/src/compatible_light_connection.cpp", + ] + } + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + cflags = [ "-Wno-error=inconsistent-missing-override" ] deps = [ "$SUBSYSTEM_DIR/utils:libmiscdevice_utils" ] diff --git a/services/miscdevice_service/hdi_connection/adapter/include/compatible_light_connection.h b/services/miscdevice_service/hdi_connection/adapter/include/compatible_light_connection.h index ba0503f..a4d1c8e 100644 --- a/services/miscdevice_service/hdi_connection/adapter/include/compatible_light_connection.h +++ b/services/miscdevice_service/hdi_connection/adapter/include/compatible_light_connection.h @@ -29,8 +29,8 @@ public: CompatibleLightConnection() = default; virtual ~CompatibleLightConnection() = default; int32_t ConnectHdi() override; - int32_t GetLightList(std::vector &lightList) const override; - int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation) override; + int32_t GetLightList(std::vector &lightList) const override; + int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) override; int32_t TurnOff(int32_t lightId) override; int32_t DestroyHdiConnection() override; diff --git a/services/miscdevice_service/hdi_connection/adapter/include/hdi_light_connection.h b/services/miscdevice_service/hdi_connection/adapter/include/hdi_light_connection.h index fc4d8d9..9873818 100644 --- a/services/miscdevice_service/hdi_connection/adapter/include/hdi_light_connection.h +++ b/services/miscdevice_service/hdi_connection/adapter/include/hdi_light_connection.h @@ -28,8 +28,8 @@ public: HdiLightConnection() = default; virtual ~HdiLightConnection() {}; int32_t ConnectHdi() override; - int32_t GetLightList(std::vector &lightList) const override; - int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation) override; + int32_t GetLightList(std::vector &lightList) const override; + int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) override; int32_t TurnOff(int32_t lightId) override; int32_t DestroyHdiConnection() override; void ProcessDeathObserver(const wptr &object); diff --git a/services/miscdevice_service/hdi_connection/adapter/src/compatible_light_connection.cpp b/services/miscdevice_service/hdi_connection/adapter/src/compatible_light_connection.cpp index 26b0f54..226884c 100644 --- a/services/miscdevice_service/hdi_connection/adapter/src/compatible_light_connection.cpp +++ b/services/miscdevice_service/hdi_connection/adapter/src/compatible_light_connection.cpp @@ -36,22 +36,32 @@ int32_t CompatibleLightConnection::ConnectHdi() return ERR_OK; } -int32_t CompatibleLightConnection::GetLightList(std::vector &lightList) const +int32_t CompatibleLightConnection::GetLightList(std::vector &lightList) const { CALL_LOG_ENTER; - lightList.assign(lightInfo.begin(), lightInfo.end()); + for (size_t i = 0; i < lightInfo.size(); ++i) { + LightInfoIPC light; + light.SetLightName(lightInfo[i].lightName); + light.SetLightId(lightInfo[i].lightId); + light.SetLightNumber(lightInfo[i].lightNumber); + light.SetLightType(lightInfo[i].lightType); + lightList.push_back(light); + } return ERR_OK; } -int32_t CompatibleLightConnection::TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation) +int32_t CompatibleLightConnection::TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) { CALL_LOG_ENTER; if (std::find(supportLights.begin(), supportLights.end(), lightId) == supportLights.end()) { MISC_HILOGE("Not support TurnOn lightId:%{public}d", lightId); return LIGHT_ID_NOT_SUPPORT; } - if ((animation.mode == LIGHT_MODE_BLINK || animation.mode == LIGHT_MODE_GRADIENT) && - (animation.onTime <= 0 || animation.offTime <= 0)) { + int32_t mode = animation.GetMode(); + int32_t onTime = animation.GetOnTime(); + int32_t offTime = animation.GetOffTime(); + if ((mode == LIGHT_MODE_BLINK || mode == LIGHT_MODE_GRADIENT) && + (onTime <= 0 || offTime <= 0)) { MISC_HILOGE("animation parameter error"); return LIGHT_ERR; } diff --git a/services/miscdevice_service/hdi_connection/adapter/src/hdi_light_connection.cpp b/services/miscdevice_service/hdi_connection/adapter/src/hdi_light_connection.cpp index bfd656d..3e4bb4a 100644 --- a/services/miscdevice_service/hdi_connection/adapter/src/hdi_light_connection.cpp +++ b/services/miscdevice_service/hdi_connection/adapter/src/hdi_light_connection.cpp @@ -49,7 +49,7 @@ int32_t HdiLightConnection::ConnectHdi() return ERR_INVALID_VALUE; } -int32_t HdiLightConnection::GetLightList(std::vector &lightList) const +int32_t HdiLightConnection::GetLightList(std::vector &lightList) const { CALL_LOG_ENTER; std::vector lightInfos; @@ -60,31 +60,26 @@ int32_t HdiLightConnection::GetLightList(std::vector &lightList) cons return ret; } for (size_t i = 0; i < lightInfos.size(); ++i) { - LightInfo light; - light.lightId = lightInfos[i].lightId; - light.lightNumber = lightInfos[i].lightNumber; - ret = memcpy_s(light.lightName, NAME_MAX_LEN, lightInfos[i].lightName.c_str(), - lightInfos[i].lightName.length()); - if (ret != EOK) { - MISC_HILOGE("memcpy_s failed, error number:%{public}d", errno); - return ret; - } - light.lightType = lightInfos[i].lightType; + LightInfoIPC light; + light.SetLightName(lightInfos[i].lightName); + light.SetLightId(lightInfos[i].lightId); + light.SetLightNumber(lightInfos[i].lightNumber); + light.SetLightType(lightInfos[i].lightType); lightList.push_back(light); } return ERR_OK; } -int32_t HdiLightConnection::TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation) +int32_t HdiLightConnection::TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) { CALL_LOG_ENTER; HDI::Light::V1_0::HdfLightColor lightColor; lightColor.colorValue.singleColor = color.singleColor; HDI::Light::V1_0::HdfLightFlashEffect flashEffect; - flashEffect.flashMode = animation.mode; - flashEffect.onTime = animation.onTime; - flashEffect.offTime = animation.offTime; + flashEffect.flashMode = animation.GetMode(); + flashEffect.onTime = animation.GetOnTime(); + flashEffect.offTime = animation.GetOffTime(); HDI::Light::V1_0::HdfLightEffect effect; effect.lightColor = lightColor; diff --git a/services/miscdevice_service/hdi_connection/interface/include/i_light_hdi_connection.h b/services/miscdevice_service/hdi_connection/interface/include/i_light_hdi_connection.h index fbc1c46..7eabe99 100644 --- a/services/miscdevice_service/hdi_connection/interface/include/i_light_hdi_connection.h +++ b/services/miscdevice_service/hdi_connection/interface/include/i_light_hdi_connection.h @@ -21,6 +21,8 @@ #include #include "light_agent_type.h" +#include "light_animation_ipc.h" +#include "light_info_ipc.h" namespace OHOS { namespace Sensors { @@ -29,8 +31,8 @@ public: ILightHdiConnection() = default; virtual ~ILightHdiConnection() = default; virtual int32_t ConnectHdi() = 0; - virtual int32_t GetLightList(std::vector &lightList) const = 0; - virtual int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation) = 0; + virtual int32_t GetLightList(std::vector &lightList) const = 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 DestroyHdiConnection() = 0; diff --git a/services/miscdevice_service/hdi_connection/interface/include/light_hdi_connection.h b/services/miscdevice_service/hdi_connection/interface/include/light_hdi_connection.h index 30d7fcb..7904ad0 100644 --- a/services/miscdevice_service/hdi_connection/interface/include/light_hdi_connection.h +++ b/services/miscdevice_service/hdi_connection/interface/include/light_hdi_connection.h @@ -28,8 +28,8 @@ public: LightHdiConnection() = default; virtual ~LightHdiConnection() {} int32_t ConnectHdi() override; - int32_t GetLightList(std::vector &lightList) const override; - int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation) override; + int32_t GetLightList(std::vector &lightList) const override; + int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) override; int32_t TurnOff(int32_t lightId) override; int32_t DestroyHdiConnection() override; @@ -37,7 +37,7 @@ private: DISALLOW_COPY_AND_MOVE(LightHdiConnection); int32_t ConnectHdiService(); std::unique_ptr iLightHdiConnection_; - std::vector lightInfoList_; + std::vector lightInfoList_; }; } // namespace Sensors } // namespace OHOS diff --git a/services/miscdevice_service/hdi_connection/interface/src/light_hdi_connection.cpp b/services/miscdevice_service/hdi_connection/interface/src/light_hdi_connection.cpp index 4ab6db4..4c5c92a 100644 --- a/services/miscdevice_service/hdi_connection/interface/src/light_hdi_connection.cpp +++ b/services/miscdevice_service/hdi_connection/interface/src/light_hdi_connection.cpp @@ -15,8 +15,9 @@ #include "light_hdi_connection.h" #include - +#ifdef BUILD_VARIANT_ENG #include "compatible_light_connection.h" +#endif #ifdef HDF_DRIVERS_INTERFACE_LIGHT #include "hdi_light_connection.h" #endif // HDF_DRIVERS_INTERFACE_LIGHT @@ -41,7 +42,9 @@ int32_t LightHdiConnection::ConnectHdi() return ERR_OK; } #endif // HDF_DRIVERS_INTERFACE_LIGHT +#ifdef BUILD_VARIANT_ENG iLightHdiConnection_ = std::make_unique(); +#endif return ConnectHdiService(); } @@ -56,13 +59,13 @@ int32_t LightHdiConnection::ConnectHdiService() return iLightHdiConnection_->GetLightList(lightInfoList_); } -int32_t LightHdiConnection::GetLightList(std::vector &lightList) const +int32_t LightHdiConnection::GetLightList(std::vector &lightList) const { lightList.assign(lightInfoList_.begin(), lightInfoList_.end()); return ERR_OK; } -int32_t LightHdiConnection::TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation) +int32_t LightHdiConnection::TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) { CHKPR(iLightHdiConnection_, ERROR); int32_t ret = iLightHdiConnection_->TurnOn(lightId, color, animation); diff --git a/services/miscdevice_service/hdi_connection/interface/src/vibrator_hdi_connection.cpp b/services/miscdevice_service/hdi_connection/interface/src/vibrator_hdi_connection.cpp index 8090b65..aebfd70 100644 --- a/services/miscdevice_service/hdi_connection/interface/src/vibrator_hdi_connection.cpp +++ b/services/miscdevice_service/hdi_connection/interface/src/vibrator_hdi_connection.cpp @@ -16,7 +16,9 @@ #include "hitrace_meter.h" +#ifdef BUILD_VARIANT_ENG #include "compatible_connection.h" +#endif #include "hdi_connection.h" #include "sensors_errors.h" @@ -34,8 +36,10 @@ int32_t VibratorHdiConnection::ConnectHdi() int32_t ret = iVibratorHdiConnection_->ConnectHdi(); if (ret != ERR_OK) { MISC_HILOGE("Hdi direct failed"); +#ifdef BUILD_VARIANT_ENG iVibratorHdiConnection_ = std::make_unique(); ret = iVibratorHdiConnection_->ConnectHdi(); +#endif } if (ret != ERR_OK) { MISC_HILOGE("Hdi connection failed"); diff --git a/services/miscdevice_service/include/miscdevice_service.h b/services/miscdevice_service/include/miscdevice_service.h index 347c9cc..943297a 100644 --- a/services/miscdevice_service/include/miscdevice_service.h +++ b/services/miscdevice_service/include/miscdevice_service.h @@ -57,7 +57,7 @@ public: void OnStop() override; void OnStartFuzz(); bool IsValid(int32_t lightId); - bool IsLightAnimationValid(const LightAnimation &animation); + bool IsLightAnimationValid(const LightAnimationIPC &animation); int32_t Dump(int32_t fd, const std::vector &args) override; virtual int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage) override; virtual int32_t PlayVibratorEffect(int32_t vibratorId, const std::string &effect, @@ -68,8 +68,8 @@ public: 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 LightAnimation &animation) 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; private: @@ -88,7 +88,7 @@ private: LightHdiConnection &lightHdiConnection_ = LightHdiConnection::GetInstance(); bool lightExist_; bool vibratorExist_; - std::vector lightInfos_; + std::vector lightInfos_; std::map miscDeviceIdMap_; MiscdeviceServiceState state_; std::shared_ptr vibratorThread_ = nullptr; diff --git a/services/miscdevice_service/src/miscdevice_service.cpp b/services/miscdevice_service/src/miscdevice_service.cpp index 931263d..a823e32 100644 --- a/services/miscdevice_service/src/miscdevice_service.cpp +++ b/services/miscdevice_service/src/miscdevice_service.cpp @@ -159,22 +159,25 @@ bool MiscdeviceService::IsValid(int32_t lightId) { CALL_LOG_ENTER; for (const auto &item : lightInfos_) { - if (lightId == item.lightId) { + if (lightId == item.GetLightId()) { return true; } } return false; } -bool MiscdeviceService::IsLightAnimationValid(const LightAnimation &animation) +bool MiscdeviceService::IsLightAnimationValid(const LightAnimationIPC &animation) { - if ((animation.mode < 0) || (animation.mode >= LIGHT_MODE_BUTT)) { - MISC_HILOGE("animation mode is invalid, mode:%{pubilc}d", animation.mode); + int32_t mode = animation.GetMode(); + int32_t onTime = animation.GetOnTime(); + int32_t offTime = animation.GetOffTime(); + if ((mode < 0) || (mode >= LIGHT_MODE_BUTT)) { + MISC_HILOGE("animation mode is invalid, mode:%{pubilc}d", mode); return false; } - if ((animation.onTime < 0) || (animation.offTime < 0)) { + if ((onTime < 0) || (offTime < 0)) { MISC_HILOGE("animation onTime or offTime is invalid, onTime:%{pubilc}d, offTime:%{pubilc}d", - animation.onTime, animation.offTime); + onTime, offTime); return false; } return true; @@ -428,7 +431,7 @@ std::string MiscdeviceService::GetPackageName(AccessTokenID tokenId) return packageName; } -std::vector MiscdeviceService::GetLightList() +std::vector MiscdeviceService::GetLightList() { if (!InitLightList()) { MISC_HILOGE("InitLightList init failed"); @@ -447,7 +450,7 @@ bool MiscdeviceService::InitLightList() return true; } -int32_t MiscdeviceService::TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation) +int32_t MiscdeviceService::TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) { CALL_LOG_ENTER; if (!IsValid(lightId)) { diff --git a/services/miscdevice_service/src/miscdevice_service_stub.cpp b/services/miscdevice_service/src/miscdevice_service_stub.cpp index d439ca5..dfe6814 100644 --- a/services/miscdevice_service/src/miscdevice_service_stub.cpp +++ b/services/miscdevice_service/src/miscdevice_service_stub.cpp @@ -210,7 +210,7 @@ int32_t MiscdeviceServiceStub::PlayVibratorCustomStub(MessageParcel &data, Messa int32_t MiscdeviceServiceStub::GetLightListStub(MessageParcel &data, MessageParcel &reply) { (void)data; - std::vector lightInfos(GetLightList()); + std::vector lightInfos(GetLightList()); size_t lightCount = lightInfos.size(); MISC_HILOGE("lightCount:%{public}zu", lightCount); if (!reply.WriteUint32(lightCount)) { @@ -218,8 +218,8 @@ int32_t MiscdeviceServiceStub::GetLightListStub(MessageParcel &data, MessageParc return WRITE_MSG_ERR; } for (size_t i = 0; i < lightCount; ++i) { - if (!reply.WriteBuffer(&lightInfos[i], sizeof(LightInfo))) { - MISC_HILOGE("WriteBuffer failed"); + if (!lightInfos[i].Marshalling(reply)) { + MISC_HILOGE("lightInfo %{public}zu marshalling failed", i); return WRITE_MSG_ERR; } } @@ -229,22 +229,12 @@ int32_t MiscdeviceServiceStub::GetLightListStub(MessageParcel &data, MessageParc int32_t MiscdeviceServiceStub::TurnOnStub(MessageParcel &data, MessageParcel &reply) { int32_t lightId = data.ReadInt32(); - const unsigned char *info = data.ReadBuffer(sizeof(LightColor)); - CHKPR(info, ERROR); LightColor lightColor; - if (memcpy_s(&lightColor, sizeof(LightColor), info, sizeof(LightColor)) != EOK) { - MISC_HILOGE("memcpy_s lightColor failed"); - return ERROR; - } - - const unsigned char *buf = data.ReadBuffer(sizeof(LightAnimation)); - CHKPR(buf, ERROR); - LightAnimation lightAnimation; - if (memcpy_s(&lightAnimation, sizeof(LightAnimation), buf, sizeof(LightAnimation)) != EOK) { - MISC_HILOGE("memcpy_s lightAnimation failed"); - return ERROR; - } - return TurnOn(lightId, lightColor, lightAnimation); + 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) diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 65008c6..e32a33f 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -18,6 +18,8 @@ ohos_shared_library("libmiscdevice_utils") { sources = [ "src/file_utils.cpp", "src/json_parser.cpp", + "src/light_animation_ipc.cpp", + "src/light_info_ipc.cpp", "src/miscdevice_common.cpp", "src/permission_util.cpp", ] diff --git a/utils/include/light_animation_ipc.h b/utils/include/light_animation_ipc.h new file mode 100644 index 0000000..e81a85b --- /dev/null +++ b/utils/include/light_animation_ipc.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 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 LIGHT_ANIMATION_IPC_H +#define LIGHT_ANIMATION_IPC_H + +#include "parcel.h" + +namespace OHOS { +namespace Sensors { +class LightAnimationIPC : public Parcelable { +public: + LightAnimationIPC() = default; + virtual ~LightAnimationIPC() = default; + int32_t GetMode() const; + void SetMode(int32_t mode); + int32_t GetOnTime() const; + void SetOnTime(int32_t onTime); + int32_t GetOffTime() const; + void SetOffTime(int32_t offTime); + bool ReadFromParcel(Parcel &parcel); + static std::unique_ptr Unmarshalling(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + +private: + int32_t mode_ = 0; + int32_t onTime_ = 0; + int32_t offTime_ = 0; +}; +} // namespace Sensors +} // namespace OHOS +#endif // LIGHT_ANIMATION_IPC_H diff --git a/utils/include/light_info_ipc.h b/utils/include/light_info_ipc.h new file mode 100644 index 0000000..5ec4093 --- /dev/null +++ b/utils/include/light_info_ipc.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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 LIGHT_INFO_IPC_H +#define LIGHT_INFO_IPC_H + +#include + +#include "parcel.h" + +namespace OHOS { +namespace Sensors { +class LightInfoIPC : public Parcelable { +public: + LightInfoIPC() = default; + virtual ~LightInfoIPC() = default; + std::string GetLightName() const; + void SetLightName(const std::string &lightName); + int32_t GetLightId() const; + void SetLightId(int32_t lightId); + int32_t GetLightNumber() const; + void SetLightNumber(int32_t lightNumber); + int32_t GetLightType() const; + void SetLightType(int32_t lightType); + bool ReadFromParcel(Parcel &parcel); + static std::unique_ptr Unmarshalling(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + +private: + std::string lightName_ = ""; + int32_t lightId_ = 0; + int32_t lightNumber_ = 0; + int32_t lightType_ = 0; +}; +} // namespace Sensors +} // namespace OHOS +#endif // LIGHT_INFO_IPC_H diff --git a/utils/src/light_animation_ipc.cpp b/utils/src/light_animation_ipc.cpp new file mode 100644 index 0000000..1f57512 --- /dev/null +++ b/utils/src/light_animation_ipc.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2023 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 "light_animation_ipc.h" + +#include "sensors_errors.h" + +namespace OHOS { +namespace Sensors { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "LightAnimationIPC" }; +} // namespace + +int32_t LightAnimationIPC::GetMode() const +{ + return mode_; +} + +void LightAnimationIPC::SetMode(int32_t mode) +{ + mode_ = mode; +} + +int32_t LightAnimationIPC::GetOnTime() const +{ + return onTime_; +} + +void LightAnimationIPC::SetOnTime(int32_t onTime) +{ + onTime_ = onTime; +} + +int32_t LightAnimationIPC::GetOffTime() const +{ + return offTime_; +} + +void LightAnimationIPC::SetOffTime(int32_t offTime) +{ + offTime_ = offTime; +} + +bool LightAnimationIPC::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteInt32(mode_)) { + MISC_HILOGE("Failed, write mode failed"); + return false; + } + if (!parcel.WriteInt32(onTime_)) { + MISC_HILOGE("Failed, write onTime failed"); + return false; + } + if (!parcel.WriteInt32(offTime_)) { + MISC_HILOGE("Failed, write offTime failed"); + return false; + } + return true; +} + +std::unique_ptr LightAnimationIPC::Unmarshalling(Parcel &parcel) +{ + auto lightAnimation = std::make_unique(); + if (!lightAnimation->ReadFromParcel(parcel)) { + MISC_HILOGE("ReadFromParcel is failed"); + return nullptr; + } + return lightAnimation; +} + +bool LightAnimationIPC::ReadFromParcel(Parcel &parcel) +{ + return (parcel.ReadInt32(mode_)) && (parcel.ReadInt32(onTime_)) && (parcel.ReadInt32(offTime_)); +} +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/utils/src/light_info_ipc.cpp b/utils/src/light_info_ipc.cpp new file mode 100644 index 0000000..4a73459 --- /dev/null +++ b/utils/src/light_info_ipc.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023 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 "light_info_ipc.h" + +#include "sensors_errors.h" + +namespace OHOS { +namespace Sensors { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "LightInfoIPC" }; +} // namespace + +std::string LightInfoIPC::GetLightName() const +{ + return lightName_; +} + +void LightInfoIPC::SetLightName(const std::string &lightName) +{ + lightName_ = lightName; +} + +int32_t LightInfoIPC::GetLightId() const +{ + return lightId_; +} + +void LightInfoIPC::SetLightId(int32_t lightId) +{ + lightId_ = lightId; +} + +int32_t LightInfoIPC::GetLightNumber() const +{ + return lightNumber_; +} + +void LightInfoIPC::SetLightNumber(int32_t lightNumber) +{ + lightNumber_ = lightNumber; +} + +int32_t LightInfoIPC::GetLightType() const +{ + return lightType_; +} + +void LightInfoIPC::SetLightType(int32_t lightType) +{ + lightType_ = lightType; +} + +bool LightInfoIPC::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString(lightName_)) { + MISC_HILOGE("Failed, write lightName failed"); + return false; + } + if (!parcel.WriteInt32(lightId_)) { + MISC_HILOGE("Failed, write lightId failed"); + return false; + } + if (!parcel.WriteInt32(lightNumber_)) { + MISC_HILOGE("Failed, write lightNumber failed"); + return false; + } + if (!parcel.WriteInt32(lightType_)) { + MISC_HILOGE("Failed, write lightType failed"); + return false; + } + return true; +} + +std::unique_ptr LightInfoIPC::Unmarshalling(Parcel &parcel) +{ + auto lightInfo = std::make_unique(); + if (!lightInfo->ReadFromParcel(parcel)) { + MISC_HILOGE("ReadFromParcel is failed"); + return nullptr; + } + return lightInfo; +} + +bool LightInfoIPC::ReadFromParcel(Parcel &parcel) +{ + return (parcel.ReadString(lightName_)) && (parcel.ReadInt32(lightId_)) && + (parcel.ReadInt32(lightNumber_)) && (parcel.ReadInt32(lightType_)); +} +} // namespace Sensors +} // namespace OHOS \ No newline at end of file -- Gitee