From 4b1abf909c6d0d35bb185c59dd1e4ecdc817174e Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Tue, 18 Apr 2023 13:08:56 +0000 Subject: [PATCH 1/3] custom vibration adapt to rk Signed-off-by: lixiangpeng5 Change-Id: I94f31ccdefa9cf2cfc4fa6e616faa45d70f2156c --- frameworks/native/miscdevice/BUILD.gn | 8 -- .../miscdevice/include/i_miscdevice_service.h | 4 - .../include/miscdevice_service_proxy.h | 2 - .../include/vibrator_service_client.h | 2 - .../src/miscdevice_service_proxy.cpp | 2 - .../src/vibrator_service_client.cpp | 2 - interfaces/native/vibrator/BUILD.gn | 4 - .../native/vibrator/src/vibrator_agent.cpp | 9 +- interfaces/native/vibrator/test/BUILD.gn | 5 +- .../vibrator/include/vibrator_napi_error.h | 1 + services/miscdevice_service/BUILD.gn | 13 +-- .../custom_vibration_default_matcher.h | 38 +++++++ ....h => custom_vibration_specific_matcher.h} | 22 ++-- .../include/i_custom_vibration_matcher.h | 37 ++++++ .../src/custom_vibration_default_matcher.cpp | 106 ++++++++++++++++++ ... => custom_vibration_specific_matcher.cpp} | 17 +-- .../adapter/include/compatible_connection.h | 2 - .../adapter/include/hdi_connection.h | 2 - .../adapter/src/compatible_connection.cpp | 2 - .../adapter/src/hdi_connection.cpp | 2 - .../include/i_vibrator_hdi_connection.h | 5 +- .../include/vibrator_hdi_connection.h | 2 - .../interface/src/vibrator_hdi_connection.cpp | 2 - .../include/miscdevice_service.h | 4 - .../include/miscdevice_service_stub.h | 2 - .../include/vibrator_infos.h | 2 - .../src/miscdevice_service.cpp | 47 +++----- .../src/miscdevice_service_stub.cpp | 4 - .../src/vibration_priority_manager.cpp | 4 - utils/include/sensors_errors.h | 2 +- 30 files changed, 229 insertions(+), 125 deletions(-) create mode 100755 services/miscdevice_service/custom_vibrate_decode/include/custom_vibration_default_matcher.h rename services/miscdevice_service/custom_vibrate_decode/include/{custom_vibration_matcher.h => custom_vibration_specific_matcher.h} (71%) create mode 100755 services/miscdevice_service/custom_vibrate_decode/include/i_custom_vibration_matcher.h create mode 100755 services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_default_matcher.cpp rename services/miscdevice_service/custom_vibrate_decode/src/{custom_vibration_matcher.cpp => custom_vibration_specific_matcher.cpp} (87%) diff --git a/frameworks/native/miscdevice/BUILD.gn b/frameworks/native/miscdevice/BUILD.gn index c6e2916..972f3ae 100644 --- a/frameworks/native/miscdevice/BUILD.gn +++ b/frameworks/native/miscdevice/BUILD.gn @@ -45,10 +45,6 @@ ohos_shared_library("liblight_native") { "samgr:samgr_proxy", ] - if (miscdevice_feature_vibrator_custom) { - defines = [ "OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM" ] - } - part_name = "miscdevice" subsystem_name = "sensors" } @@ -79,10 +75,6 @@ ohos_shared_library("libvibrator_native") { "samgr:samgr_proxy", ] - if (miscdevice_feature_vibrator_custom) { - defines = [ "OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM" ] - } - part_name = "miscdevice" subsystem_name = "sensors" } diff --git a/frameworks/native/miscdevice/include/i_miscdevice_service.h b/frameworks/native/miscdevice/include/i_miscdevice_service.h index 3352cfc..9018e49 100755 --- a/frameworks/native/miscdevice/include/i_miscdevice_service.h +++ b/frameworks/native/miscdevice/include/i_miscdevice_service.h @@ -35,9 +35,7 @@ public: virtual int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage) = 0; virtual int32_t PlayVibratorEffect(int32_t vibratorId, const std::string &effect, int32_t loopCount, int32_t usage) = 0; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage) = 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; @@ -48,9 +46,7 @@ public: enum { VIBRATE, 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, diff --git a/frameworks/native/miscdevice/include/miscdevice_service_proxy.h b/frameworks/native/miscdevice/include/miscdevice_service_proxy.h index 6384f13..86b36a2 100755 --- a/frameworks/native/miscdevice/include/miscdevice_service_proxy.h +++ b/frameworks/native/miscdevice/include/miscdevice_service_proxy.h @@ -30,9 +30,7 @@ public: 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, int32_t loopCount, int32_t usage) override; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage) 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; diff --git a/frameworks/native/miscdevice/include/vibrator_service_client.h b/frameworks/native/miscdevice/include/vibrator_service_client.h index 267bc86..b77fb69 100755 --- a/frameworks/native/miscdevice/include/vibrator_service_client.h +++ b/frameworks/native/miscdevice/include/vibrator_service_client.h @@ -29,9 +29,7 @@ class VibratorServiceClient : public Singleton { public: int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage); int32_t Vibrate(int32_t vibratorId, const std::string &effect, int32_t loopCount, int32_t usage); -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage); -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t StopVibrator(int32_t vibratorId, const std::string &mode); int32_t StopVibrator(int32_t vibratorId); int32_t IsSupportEffect(const std::string &effect, bool &state); diff --git a/frameworks/native/miscdevice/src/miscdevice_service_proxy.cpp b/frameworks/native/miscdevice/src/miscdevice_service_proxy.cpp index e6cba9b..43b8485 100644 --- a/frameworks/native/miscdevice/src/miscdevice_service_proxy.cpp +++ b/frameworks/native/miscdevice/src/miscdevice_service_proxy.cpp @@ -182,7 +182,6 @@ int32_t MiscdeviceServiceProxy::IsSupportEffect(const std::string &effect, bool return ret; } -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t MiscdeviceServiceProxy::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage) { MessageParcel data; @@ -222,7 +221,6 @@ int32_t MiscdeviceServiceProxy::PlayVibratorCustom(int32_t vibratorId, const Raw } return ret; } -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM std::vector MiscdeviceServiceProxy::GetLightList() { diff --git a/frameworks/native/miscdevice/src/vibrator_service_client.cpp b/frameworks/native/miscdevice/src/vibrator_service_client.cpp index e162ae7..4c5fd1b 100644 --- a/frameworks/native/miscdevice/src/vibrator_service_client.cpp +++ b/frameworks/native/miscdevice/src/vibrator_service_client.cpp @@ -107,7 +107,6 @@ int32_t VibratorServiceClient::Vibrate(int32_t vibratorId, const std::string &ef return ret; } -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t VibratorServiceClient::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage) { MISC_HILOGD("PlayVibratorCustom begin, fd:%{public}d, offset:%{public}lld, length:%{public}lld", @@ -126,7 +125,6 @@ int32_t VibratorServiceClient::PlayVibratorCustom(int32_t vibratorId, const RawF } return ret; } -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t VibratorServiceClient::StopVibrator(int32_t vibratorId, const std::string &mode) { diff --git a/interfaces/native/vibrator/BUILD.gn b/interfaces/native/vibrator/BUILD.gn index 6873c9a..8c5d55a 100644 --- a/interfaces/native/vibrator/BUILD.gn +++ b/interfaces/native/vibrator/BUILD.gn @@ -46,10 +46,6 @@ ohos_shared_library("vibrator_interface_native") { "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", ] - if (miscdevice_feature_vibrator_custom) { - defines = [ "OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM" ] - } - cflags = [ "-Wno-error=inconsistent-missing-override" ] deps = [ diff --git a/interfaces/native/vibrator/src/vibrator_agent.cpp b/interfaces/native/vibrator/src/vibrator_agent.cpp index 9264fa0..a3d444c 100644 --- a/interfaces/native/vibrator/src/vibrator_agent.cpp +++ b/interfaces/native/vibrator/src/vibrator_agent.cpp @@ -30,6 +30,7 @@ static const int32_t DEFAULT_VIBRATOR_ID = 123; static int32_t g_loopCount = 1; static int32_t g_usage = USAGE_UNKNOWN; const std::string PHONE_TYPE = "phone"; +const std::string DEFAULT_TYPE = "default"; static int32_t NormalizeErrCode(int32_t code) { @@ -92,12 +93,12 @@ int32_t StartVibratorOnce(int32_t duration) bool IsSupportVibratorCustom() { - return (OHOS::system::GetDeviceType() == PHONE_TYPE); + const std::string &deviceType = OHOS::system::GetDeviceType(); + return ((deviceType == DEFAULT_TYPE) || (deviceType == PHONE_TYPE)); } int32_t PlayVibratorCustom(int32_t fd, int64_t offset, int64_t length) { -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM if (fd < 0 || offset < 0 || length <= 0) { MISC_HILOGE("input parameter invalid, fd:%{public}d, offset:%{public}lld, length:%{public}lld", fd, static_cast(offset), static_cast(length)); @@ -116,10 +117,6 @@ int32_t PlayVibratorCustom(int32_t fd, int64_t offset, int64_t length) } g_usage = USAGE_UNKNOWN; return SUCCESS; -#else - MISC_HILOGE("the device does not support this operation"); - return IS_NOT_SUPPORTED; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM } int32_t StopVibrator(const char *mode) diff --git a/interfaces/native/vibrator/test/BUILD.gn b/interfaces/native/vibrator/test/BUILD.gn index 317f917..9ef6e7e 100755 --- a/interfaces/native/vibrator/test/BUILD.gn +++ b/interfaces/native/vibrator/test/BUILD.gn @@ -44,10 +44,7 @@ ohos_unittest("VibratorAgentTest") { "init:libbegetutil", "ipc:ipc_core", ] - - if (miscdevice_feature_vibrator_custom) { - resource_config_file = "$SUBSYSTEM_DIR/miscdevice/interfaces/native/vibrator/test/unittest/resource/ohos_test.xml" - } + resource_config_file = "$SUBSYSTEM_DIR/miscdevice/interfaces/native/vibrator/test/unittest/resource/ohos_test.xml" } ###########################end########################### diff --git a/interfaces/plugin/vibrator/include/vibrator_napi_error.h b/interfaces/plugin/vibrator/include/vibrator_napi_error.h index 3c223b9..175517e 100755 --- a/interfaces/plugin/vibrator/include/vibrator_napi_error.h +++ b/interfaces/plugin/vibrator/include/vibrator_napi_error.h @@ -28,6 +28,7 @@ const std::map ERROR_MESSAGES = { {DEVICE_OPERATION_FAILED, "Device operation failed."}, {PERMISSION_DENIED, "Permission denied."}, {PARAMETER_ERROR, "The parameter invalid."}, + {IS_NOT_SUPPORTED, "Capability not supported."}, }; napi_value CreateBusinessError(const napi_env &env, const int32_t errCode, const std::string &errMessage); diff --git a/services/miscdevice_service/BUILD.gn b/services/miscdevice_service/BUILD.gn index 443007d..ae0651f 100644 --- a/services/miscdevice_service/BUILD.gn +++ b/services/miscdevice_service/BUILD.gn @@ -17,6 +17,10 @@ import("//build/ohos.gni") SUBSYSTEM_DIR = "//base/sensors" ohos_shared_library("libmiscdevice_service") { sources = [ + "custom_vibrate_decode/src/custom_vibration_default_matcher.cpp", + "custom_vibrate_decode/src/custom_vibration_phone_matcher.cpp", + "custom_vibrate_decode/src/default_vibrator_decoder.cpp", + "custom_vibrate_decode/src/default_vibrator_decoder_factory.cpp", "hdi_connection/adapter/src/compatible_connection.cpp", "hdi_connection/adapter/src/compatible_light_connection.cpp", "hdi_connection/adapter/src/hdi_connection.cpp", @@ -40,6 +44,7 @@ ohos_shared_library("libmiscdevice_service") { "hdi_connection/adapter/include", "hdi_connection/interface/include", "//third_party/cJSON", + "custom_vibrate_decode/include", ] cflags = [ "-Wno-error=inconsistent-missing-override" ] @@ -53,19 +58,13 @@ ohos_shared_library("libmiscdevice_service") { "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", + "init:libbegetutil", "ipc:ipc_core", "safwk:system_ability_fwk", ] if (miscdevice_feature_vibrator_custom) { - sources += [ - "custom_vibrate_decode/src/custom_vibration_matcher.cpp", - "custom_vibrate_decode/src/default_vibrator_decoder.cpp", - "custom_vibrate_decode/src/default_vibrator_decoder_factory.cpp", - ] - include_dirs += [ "custom_vibrate_decode/include" ] defines = [ "OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM" ] - external_deps += [ "init:libbegetutil" ] } shlib_type = "sa" diff --git a/services/miscdevice_service/custom_vibrate_decode/include/custom_vibration_default_matcher.h b/services/miscdevice_service/custom_vibrate_decode/include/custom_vibration_default_matcher.h new file mode 100755 index 0000000..7806dde --- /dev/null +++ b/services/miscdevice_service/custom_vibrate_decode/include/custom_vibration_default_matcher.h @@ -0,0 +1,38 @@ +/* + * 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 CUSTOM_VIBRATION_DEFAULT_MATCHER_H +#define CUSTOM_VIBRATION_DEFAULT_MATCHER_H + +#include "i_custom_vibration_matcher.h" + +namespace OHOS { +namespace Sensors { +class CustomVibrationDefaultMatcher : public ICustomVibrationMatcher { +public: + CustomVibrationDefaultMatcher() = default; + ~CustomVibrationDefaultMatcher() = default; + int32_t TransformEffect(const std::set &vibrateSet, + HdfCompositeEffect &hdfCompositeEffect) override; + +private: + void ProcessContinuousEvent(const VibrateEvent &event, int32_t &preStartTime, int32_t &preDuration, + std::vector &compositeEffects); + void ProcessTransientEvent(const VibrateEvent &event, int32_t &preStartTime, int32_t &preDuration, + std::vector &compositeEffects); +}; +} // namespace Sensors +} // namespace OHOS +#endif // CUSTOM_VIBRATION_DEFAULT_MATCHER_H diff --git a/services/miscdevice_service/custom_vibrate_decode/include/custom_vibration_matcher.h b/services/miscdevice_service/custom_vibrate_decode/include/custom_vibration_specific_matcher.h similarity index 71% rename from services/miscdevice_service/custom_vibrate_decode/include/custom_vibration_matcher.h rename to services/miscdevice_service/custom_vibrate_decode/include/custom_vibration_specific_matcher.h index c2f7730..f72d8e0 100755 --- a/services/miscdevice_service/custom_vibrate_decode/include/custom_vibration_matcher.h +++ b/services/miscdevice_service/custom_vibrate_decode/include/custom_vibration_specific_matcher.h @@ -13,23 +13,19 @@ * limitations under the License. */ -#ifndef CUSTOM_VIBRATION_MATCHER_H -#define CUSTOM_VIBRATION_MATCHER_H +#ifndef CUSTOM_VIBRATION_PHONE_MATCHER_H +#define CUSTOM_VIBRATION_PHONE_MATCHER_H -#include -#include -#include - -#include "i_vibrator_hdi_connection.h" -#include "vibrator_infos.h" +#include "i_custom_vibration_matcher.h" namespace OHOS { namespace Sensors { -class CustomVibrationMatcher { +class CustomVibrationSpecificMatcher : public ICustomVibrationMatcher { public: - CustomVibrationMatcher() = default; - ~CustomVibrationMatcher() = default; - int32_t TransformEffect(const std::set &vibrateSet, std::vector &compositeEffects); + CustomVibrationSpecificMatcher() = default; + ~CustomVibrationSpecificMatcher() = default; + int32_t TransformEffect(const std::set &vibrateSet, + HdfCompositeEffect &hdfCompositeEffect) override; private: void ProcessContinuousEvent(const VibrateEvent &event, int32_t &preStartTime, int32_t &preDuration, @@ -39,4 +35,4 @@ private: }; } // namespace Sensors } // namespace OHOS -#endif // CUSTOM_VIBRATION_MATCHER_H +#endif // CUSTOM_VIBRATION_PHONE_MATCHER_H diff --git a/services/miscdevice_service/custom_vibrate_decode/include/i_custom_vibration_matcher.h b/services/miscdevice_service/custom_vibrate_decode/include/i_custom_vibration_matcher.h new file mode 100755 index 0000000..9396def --- /dev/null +++ b/services/miscdevice_service/custom_vibrate_decode/include/i_custom_vibration_matcher.h @@ -0,0 +1,37 @@ +/* + * 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 I_CUSTOM_VIBRATION_MATCHER_H +#define I_CUSTOM_VIBRATION_MATCHER_H + +#include +#include +#include + +#include "i_vibrator_hdi_connection.h" +#include "vibrator_infos.h" + +namespace OHOS { +namespace Sensors { +class ICustomVibrationMatcher { +public: + ICustomVibrationMatcher() = default; + virtual ~ICustomVibrationMatcher() = default; + virtual int32_t TransformEffect(const std::set &vibrateSet, + HdfCompositeEffect &hdfCompositeEffect) = 0; +}; +} // namespace Sensors +} // namespace OHOS +#endif // I_CUSTOM_VIBRATION_MATCHER_H diff --git a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_default_matcher.cpp b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_default_matcher.cpp new file mode 100755 index 0000000..cf4ab7e --- /dev/null +++ b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_default_matcher.cpp @@ -0,0 +1,106 @@ +/* + * 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 "custom_vibration_default_matcher.h" + +#include +#include + +#include "sensors_errors.h" + +namespace OHOS { +namespace Sensors { +namespace { +std::map> TRANSIENT_VIBRATION_INFOS = { + {0x01, {0x4b, 0x35, 0x14}}, {0x02, {0x23, 0x32, 0x14}}, {0x03, {0x0d, 0x2e, 0x14}}, + {0x04, {0x2f, 0x36, 0x14}}, {0x05, {0x17, 0x2f, 0x14}}, {0x06, {0x09, 0x26, 0x14}}, + {0x11, {0x64, 0x32, 0x14}}, {0x12, {0x54, 0x3a, 0x14}}, {0x13, {0x2d, 0x33, 0x14}}, + {0x14, {0x11, 0x30, 0x14}}, {0x15, {0x2f, 0x30, 0x14}}, {0x16, {0x23, 0x25, 0x14}}, + {0x17, {0x14, 0x33, 0x14}}, {0x18, {0x1b, 0x2d, 0x14}}, {0x19, {0x11, 0x2f, 0x14}}, +}; // {Id, {intensity, frequency, duration}} +constexpr int32_t F_RESONANCE = 245; +constexpr int32_t BAND_WIDTH = 100; +constexpr float INTENSITY_WEIGHT = 0.5; +constexpr float FREQUENCY_WEIGHT = 0.5; +constexpr float WEIGHT_SUM_INIT = 100; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "CustomVibrationMatcher" }; +} // namespace + +int32_t CustomVibrationDefaultMatcher::TransformEffect(const std::set &vibrateSet, + HdfCompositeEffect &hdfCompositeEffect) +{ + CALL_LOG_ENTER; + hdfCompositeEffect.type = HDF_EFFECT_TYPE_PRIMITIVE; + int32_t preStartTime = 0; + int32_t preDuration = 0; + for (const auto &event : vibrateSet) { + if ((preDuration != 0) && (event.startTime < preStartTime + preDuration)) { + MISC_HILOGE("Vibration events overlap"); + return ERROR; + } + if (event.tag == EVENT_TAG_CONTINUOUS) { + ProcessContinuousEvent(event, preStartTime, preDuration, hdfCompositeEffect.compositeEffects); + } else if (event.tag == EVENT_TAG_TRANSIENT) { + ProcessTransientEvent(event, preStartTime, preDuration, hdfCompositeEffect.compositeEffects); + } else { + MISC_HILOGE("Unknown event tag, tag:%{public}d", event.tag); + return ERROR; + } + } + return SUCCESS; +} + + +void CustomVibrationDefaultMatcher::ProcessContinuousEvent(const VibrateEvent &event, int32_t &preStartTime, + int32_t &preDuration, std::vector &compositeEffects) +{ + PrimitiveEffect primitiveEffect; + primitiveEffect.delay = event.startTime - preStartTime; + primitiveEffect.effectId = (event.duration << 16) + (event.frequency + F_RESONANCE - BAND_WIDTH / 2.); + primitiveEffect.intensity = event.intensity; + CompositeEffect compositeEffect; + compositeEffect.primitiveEffect = primitiveEffect; + compositeEffects.push_back(compositeEffect); + preStartTime = event.startTime; + preDuration = event.duration; +} + +void CustomVibrationDefaultMatcher::ProcessTransientEvent(const VibrateEvent &event, int32_t &preStartTime, + int32_t &preDuration, std::vector &compositeEffects) +{ + int32_t matchId = 0; + float minWeightSum = WEIGHT_SUM_INIT; + for (const auto &transientInfo : TRANSIENT_VIBRATION_INFOS) { + int32_t id = transientInfo.first; + const std::vector &info = transientInfo.second; + float intensityDistance = std::abs(event.intensity - info[0]); + float frequencyDistance = std::abs(event.frequency - info[1]); + float weightSum = INTENSITY_WEIGHT * intensityDistance + FREQUENCY_WEIGHT * frequencyDistance; + if (weightSum <= minWeightSum) { + minWeightSum = weightSum; + matchId = id; + } + } + PrimitiveEffect primitiveEffect; + primitiveEffect.delay = event.startTime - preStartTime; + primitiveEffect.effectId = matchId; + CompositeEffect compositeEffect; + compositeEffect.primitiveEffect = primitiveEffect; + compositeEffects.push_back(compositeEffect); + preStartTime = event.startTime; + preDuration = event.duration; +} +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_specific_matcher.cpp similarity index 87% rename from services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp rename to services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_specific_matcher.cpp index 8bc861c..878ee0e 100755 --- a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp +++ b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_specific_matcher.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "custom_vibration_matcher.h" +#include "custom_vibration_phone_matcher.h" #include #include @@ -42,10 +42,11 @@ constexpr int32_t DURATION_MAX = 1600; constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "CustomVibrationMatcher" }; } // namespace -int32_t CustomVibrationMatcher::TransformEffect(const std::set &vibrateSet, - std::vector &compositeEffects) +int32_t CustomVibrationSpecificMatcher::TransformEffect(const std::set &vibrateSet, + HdfCompositeEffect &hdfCompositeEffect) { CALL_LOG_ENTER; + hdfCompositeEffect.type = HDF_EFFECT_TYPE_PRIMITIVE; int32_t preStartTime = 0; int32_t preDuration = 0; for (const auto &event : vibrateSet) { @@ -54,9 +55,9 @@ int32_t CustomVibrationMatcher::TransformEffect(const std::set &vi return ERROR; } if (event.tag == EVENT_TAG_CONTINUOUS) { - ProcessContinuousEvent(event, preStartTime, preDuration, compositeEffects); + ProcessContinuousEvent(event, preStartTime, preDuration, hdfCompositeEffect.compositeEffects); } else if (event.tag == EVENT_TAG_TRANSIENT) { - ProcessTransientEvent(event, preStartTime, preDuration, compositeEffects); + ProcessTransientEvent(event, preStartTime, preDuration, hdfCompositeEffect.compositeEffects); } else { MISC_HILOGE("Unknown event tag, tag:%{public}d", event.tag); return ERROR; @@ -67,11 +68,11 @@ int32_t CustomVibrationMatcher::TransformEffect(const std::set &vi primitiveEffect.effectId = STOP_WAVEFORM; CompositeEffect compositeEffect; compositeEffect.primitiveEffect = primitiveEffect; - compositeEffects.push_back(compositeEffect); + hdfCompositeEffect.compositeEffects.push_back(compositeEffect); return SUCCESS; } -void CustomVibrationMatcher::ProcessContinuousEvent(const VibrateEvent &event, int32_t &preStartTime, +void CustomVibrationSpecificMatcher::ProcessContinuousEvent(const VibrateEvent &event, int32_t &preStartTime, int32_t &preDuration, std::vector &compositeEffects) { int32_t grade = -1; @@ -101,7 +102,7 @@ void CustomVibrationMatcher::ProcessContinuousEvent(const VibrateEvent &event, i preDuration = event.duration; } -void CustomVibrationMatcher::ProcessTransientEvent(const VibrateEvent &event, int32_t &preStartTime, +void CustomVibrationSpecificMatcher::ProcessTransientEvent(const VibrateEvent &event, int32_t &preStartTime, int32_t &preDuration, std::vector &compositeEffects) { int32_t matchId = 0; diff --git a/services/miscdevice_service/hdi_connection/adapter/include/compatible_connection.h b/services/miscdevice_service/hdi_connection/adapter/include/compatible_connection.h index f5d8da7..7fc662d 100644 --- a/services/miscdevice_service/hdi_connection/adapter/include/compatible_connection.h +++ b/services/miscdevice_service/hdi_connection/adapter/include/compatible_connection.h @@ -30,10 +30,8 @@ public: int32_t ConnectHdi() override; int32_t StartOnce(uint32_t duration) override; int32_t Start(const std::string &effectType) override; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t EnableCompositeEffect(const HdfCompositeEffect &hdfCompositeEffect) override; bool IsVibratorRunning() override; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM std::optional GetEffectInfo(const std::string &effect) override; int32_t Stop(HdfVibratorMode mode) override; int32_t DestroyHdiConnection() override; diff --git a/services/miscdevice_service/hdi_connection/adapter/include/hdi_connection.h b/services/miscdevice_service/hdi_connection/adapter/include/hdi_connection.h index 7082638..9e04c2c 100644 --- a/services/miscdevice_service/hdi_connection/adapter/include/hdi_connection.h +++ b/services/miscdevice_service/hdi_connection/adapter/include/hdi_connection.h @@ -31,10 +31,8 @@ public: int32_t ConnectHdi() override; int32_t StartOnce(uint32_t duration) override; int32_t Start(const std::string &effectType) override; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t EnableCompositeEffect(const HdfCompositeEffect &hdfCompositeEffect) override; bool IsVibratorRunning() override; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM std::optional GetEffectInfo(const std::string &effect) override; int32_t Stop(HdfVibratorMode mode) override; int32_t DestroyHdiConnection() override; diff --git a/services/miscdevice_service/hdi_connection/adapter/src/compatible_connection.cpp b/services/miscdevice_service/hdi_connection/adapter/src/compatible_connection.cpp index a3cc57f..5ee027e 100644 --- a/services/miscdevice_service/hdi_connection/adapter/src/compatible_connection.cpp +++ b/services/miscdevice_service/hdi_connection/adapter/src/compatible_connection.cpp @@ -71,7 +71,6 @@ int32_t CompatibleConnection::Start(const std::string &effectType) return ERR_OK; } -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t CompatibleConnection::EnableCompositeEffect(const HdfCompositeEffect &hdfCompositeEffect) { CALL_LOG_ENTER; @@ -102,7 +101,6 @@ bool CompatibleConnection::IsVibratorRunning() CALL_LOG_ENTER; return (!isStop_); } -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM std::optional CompatibleConnection::GetEffectInfo(const std::string &effect) { diff --git a/services/miscdevice_service/hdi_connection/adapter/src/hdi_connection.cpp b/services/miscdevice_service/hdi_connection/adapter/src/hdi_connection.cpp index 4a8d825..f150b3e 100644 --- a/services/miscdevice_service/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/miscdevice_service/hdi_connection/adapter/src/hdi_connection.cpp @@ -79,7 +79,6 @@ int32_t HdiConnection::Start(const std::string &effectType) return ERR_OK; } -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t HdiConnection::EnableCompositeEffect(const HdfCompositeEffect &hdfCompositeEffect) { if (hdfCompositeEffect.compositeEffects.empty()) { @@ -104,7 +103,6 @@ bool HdiConnection::IsVibratorRunning() vibratorInterface_->IsVibratorRunning(state); return state; } -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM std::optional HdiConnection::GetEffectInfo(const std::string &effect) { diff --git a/services/miscdevice_service/hdi_connection/interface/include/i_vibrator_hdi_connection.h b/services/miscdevice_service/hdi_connection/interface/include/i_vibrator_hdi_connection.h index 04656fe..bd95acf 100644 --- a/services/miscdevice_service/hdi_connection/interface/include/i_vibrator_hdi_connection.h +++ b/services/miscdevice_service/hdi_connection/interface/include/i_vibrator_hdi_connection.h @@ -30,7 +30,6 @@ using OHOS::HDI::Vibrator::V1_1::HDF_VIBRATOR_MODE_ONCE; using OHOS::HDI::Vibrator::V1_1::HDF_VIBRATOR_MODE_PRESET; using OHOS::HDI::Vibrator::V1_1::HDF_VIBRATOR_MODE_BUTT; using OHOS::HDI::Vibrator::V1_1::HdfEffectInfo; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM using OHOS::HDI::Vibrator::V1_1::HdfEffectType; using OHOS::HDI::Vibrator::V1_1::HDF_EFFECT_TYPE_TIME; using OHOS::HDI::Vibrator::V1_1::HDF_EFFECT_TYPE_PRIMITIVE; @@ -39,7 +38,7 @@ using OHOS::HDI::Vibrator::V1_1::TimeEffect; using OHOS::HDI::Vibrator::V1_1::PrimitiveEffect; using OHOS::HDI::Vibrator::V1_1::CompositeEffect; using OHOS::HDI::Vibrator::V1_1::HdfCompositeEffect; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM + class IVibratorHdiConnection { public: IVibratorHdiConnection() = default; @@ -47,10 +46,8 @@ public: virtual int32_t ConnectHdi() = 0; virtual int32_t StartOnce(uint32_t duration) = 0; virtual int32_t Start(const std::string &effectType) = 0; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t EnableCompositeEffect(const HdfCompositeEffect &hdfCompositeEffect) = 0; virtual bool IsVibratorRunning() = 0; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual std::optional GetEffectInfo(const std::string &effect) = 0; virtual int32_t Stop(HdfVibratorMode mode) = 0; virtual int32_t DestroyHdiConnection() = 0; diff --git a/services/miscdevice_service/hdi_connection/interface/include/vibrator_hdi_connection.h b/services/miscdevice_service/hdi_connection/interface/include/vibrator_hdi_connection.h index 79ebd17..da8042e 100644 --- a/services/miscdevice_service/hdi_connection/interface/include/vibrator_hdi_connection.h +++ b/services/miscdevice_service/hdi_connection/interface/include/vibrator_hdi_connection.h @@ -29,10 +29,8 @@ public: int32_t ConnectHdi() override; int32_t StartOnce(uint32_t duration) override; int32_t Start(const std::string &effectType) override; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t EnableCompositeEffect(const HdfCompositeEffect &hdfCompositeEffect) override; bool IsVibratorRunning() override; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM std::optional GetEffectInfo(const std::string &effect) override; int32_t Stop(HdfVibratorMode mode) override; int32_t DestroyHdiConnection() override; 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 48aa395..d1f2d59 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 @@ -70,7 +70,6 @@ int32_t VibratorHdiConnection::Start(const std::string &effectType) return ERR_OK; } -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t VibratorHdiConnection::EnableCompositeEffect(const HdfCompositeEffect &hdfCompositeEffect) { CHKPR(iVibratorHdiConnection_, VIBRATOR_HDF_CONNECT_ERR); @@ -89,7 +88,6 @@ bool VibratorHdiConnection::IsVibratorRunning() CHKPR(iVibratorHdiConnection_, VIBRATOR_HDF_CONNECT_ERR); return iVibratorHdiConnection_->IsVibratorRunning(); } -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM std::optional VibratorHdiConnection::GetEffectInfo(const std::string &effect) { diff --git a/services/miscdevice_service/include/miscdevice_service.h b/services/miscdevice_service/include/miscdevice_service.h index bc507a0..0d8218f 100644 --- a/services/miscdevice_service/include/miscdevice_service.h +++ b/services/miscdevice_service/include/miscdevice_service.h @@ -60,9 +60,7 @@ public: 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, int32_t loopCount, int32_t usage) override; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage) 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; @@ -78,10 +76,8 @@ private: void StartVibrateThread(VibrateInfo info); bool ShouldIgnoreVibrate(const VibrateInfo &info); bool InitLightList(); -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t DecodeCustomEffect(const RawFileDescriptor &rawFd, std::set &vibrateSequence); int32_t StartCustomVibration(const RawFileDescriptor &rawFd, const VibrateInfo &info); -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM VibratorHdiConnection &vibratorHdiConnection_ = VibratorHdiConnection::GetInstance(); LightHdiConnection &lightHdiConnection_ = LightHdiConnection::GetInstance(); bool lightExist_; diff --git a/services/miscdevice_service/include/miscdevice_service_stub.h b/services/miscdevice_service/include/miscdevice_service_stub.h index 29e17fd..f6fa844 100755 --- a/services/miscdevice_service/include/miscdevice_service_stub.h +++ b/services/miscdevice_service/include/miscdevice_service_stub.h @@ -46,9 +46,7 @@ private: 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); diff --git a/services/miscdevice_service/include/vibrator_infos.h b/services/miscdevice_service/include/vibrator_infos.h index 6975a38..966e981 100755 --- a/services/miscdevice_service/include/vibrator_infos.h +++ b/services/miscdevice_service/include/vibrator_infos.h @@ -45,7 +45,6 @@ enum VibrateUsage { USAGE_MAX = 9, }; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM enum VibrateTag { EVENT_TAG_CONTINUOUS = 0, EVENT_TAG_TRANSIENT = 1, @@ -63,7 +62,6 @@ struct VibrateEvent { int32_t intensity = 0; int32_t frequency = 0; }; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM } // namespace Sensors } // namespace OHOS #endif // VIBRATOR_INFOS_H \ No newline at end of file diff --git a/services/miscdevice_service/src/miscdevice_service.cpp b/services/miscdevice_service/src/miscdevice_service.cpp index ec071fe..b43f963 100644 --- a/services/miscdevice_service/src/miscdevice_service.cpp +++ b/services/miscdevice_service/src/miscdevice_service.cpp @@ -19,16 +19,19 @@ #include #include -#include "sensors_errors.h" +#include "parameters.h" #include "system_ability_definition.h" -#include "vibration_priority_manager.h" #include "v1_0/light_interface_proxy.h" -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM -#include "custom_vibration_matcher.h" #include "default_vibrator_decoder.h" #include "default_vibrator_decoder_factory.h" -#include "parameters.h" +#include "sensors_errors.h" +#include "vibration_priority_manager.h" + +#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM +#include "custom_vibration_specific_matcher.h" +#else +#include "custom_vibration_default_matcher.h" #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM namespace OHOS { @@ -39,11 +42,9 @@ namespace { constexpr HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "MiscdeviceService" }; constexpr int32_t MIN_VIBRATOR_TIME = 0; constexpr int32_t MAX_VIBRATOR_TIME = 1800000; - -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM constexpr int32_t MAX_JSON_FILE_SIZE = 64000; const std::string PHONE_TYPE = "phone"; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM +const std::string DEFAULT_TYPE = "default"; } // namespace REGISTER_SYSTEM_ABILITY_BY_ID(MiscdeviceService, MISCDEVICE_SERVICE_ABILITY_ID, true); @@ -195,7 +196,6 @@ int32_t MiscdeviceService::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t int32_t MiscdeviceService::StopVibrator(int32_t vibratorId) { std::lock_guard lock(vibratorThreadMutex_); -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM if ((vibratorThread_ == nullptr) || (!vibratorThread_->IsRunning() && !vibratorHdiConnection_.IsVibratorRunning())) { MISC_HILOGE("No vibration, no need to stop"); @@ -204,12 +204,6 @@ int32_t MiscdeviceService::StopVibrator(int32_t vibratorId) while (vibratorHdiConnection_.IsVibratorRunning()) { vibratorHdiConnection_.Stop(HDF_VIBRATOR_MODE_PRESET); } -#else - if ((vibratorThread_ == nullptr) || (!vibratorThread_->IsRunning())) { - MISC_HILOGE("No vibration, no need to stop"); - return ERROR; - } -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM while (vibratorThread_->IsRunning()) { MISC_HILOGD("Notify the vibratorThread, vibratorId:%{public}d", vibratorId); vibratorThread_->NotifyExit(); @@ -262,11 +256,9 @@ void MiscdeviceService::StartVibrateThread(VibrateInfo info) vibratorThread_->NotifyExit(); vibratorThread_->NotifyExitSync(); } -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM while (vibratorHdiConnection_.IsVibratorRunning()) { vibratorHdiConnection_.Stop(HDF_VIBRATOR_MODE_PRESET); } -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM vibratorThread_->UpdateVibratorEffect(info); vibratorThread_->Start("VibratorThread"); DumpHelper->SaveVibrateRecord(info); @@ -303,7 +295,6 @@ int32_t MiscdeviceService::IsSupportEffect(const std::string &effect, bool &stat return NO_ERROR; } -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t MiscdeviceService::DecodeCustomEffect(const RawFileDescriptor &rawFd, std::set &vibrateSet) { auto defaultFactory = std::make_unique(); @@ -326,28 +317,25 @@ int32_t MiscdeviceService::StartCustomVibration(const RawFileDescriptor &rawFd, MISC_HILOGE("decoder custom effect error"); return ERROR; } +#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM + CustomVibrationSpecificMatcher matcher; +#else + CustomVibrationDefaultMatcher matcher; +#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM HdfCompositeEffect hdfCompositeEffect; - hdfCompositeEffect.type = HDF_EFFECT_TYPE_PRIMITIVE; - CustomVibrationMatcher matcher; - ret = matcher.TransformEffect(vibrateSet, hdfCompositeEffect.compositeEffects); + ret = matcher.TransformEffect(vibrateSet, hdfCompositeEffect); if (ret != SUCCESS) { MISC_HILOGE("transform custom effect error"); return ERROR; } - size_t size = hdfCompositeEffect.compositeEffects.size(); - MISC_HILOGD("the count of match result:%{public}zu", size); - for (size_t i = 0; i < size; ++i) { - MISC_HILOGD("match result at %{public}zu th, delay:%{public}d, effectId:%{public}d", - i, hdfCompositeEffect.compositeEffects[i].primitiveEffect.delay, - hdfCompositeEffect.compositeEffects[i].primitiveEffect.effectId); - } StartVibrateThread(info); return vibratorHdiConnection_.EnableCompositeEffect(hdfCompositeEffect); } int32_t MiscdeviceService::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage) { - if (OHOS::system::GetDeviceType() != PHONE_TYPE) { + const std::string &deviceType = OHOS::system::GetDeviceType(); + if ((deviceType != DEFAULT_TYPE) && (deviceType != PHONE_TYPE)) { MISC_HILOGE("the device does not support this operation"); return IS_NOT_SUPPORTED; } @@ -374,7 +362,6 @@ int32_t MiscdeviceService::PlayVibratorCustom(int32_t vibratorId, const RawFileD } return StartCustomVibration(rawFd, info); } -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM std::string MiscdeviceService::GetPackageName(AccessTokenID tokenId) { diff --git a/services/miscdevice_service/src/miscdevice_service_stub.cpp b/services/miscdevice_service/src/miscdevice_service_stub.cpp index c008430..1d8e42f 100644 --- a/services/miscdevice_service/src/miscdevice_service_stub.cpp +++ b/services/miscdevice_service/src/miscdevice_service_stub.cpp @@ -39,9 +39,7 @@ MiscdeviceServiceStub::MiscdeviceServiceStub() { baseFuncs_[VIBRATE] = &MiscdeviceServiceStub::VibrateStub; baseFuncs_[PLAY_VIBRATOR_EFFECT] = &MiscdeviceServiceStub::PlayVibratorEffectStub; -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM baseFuncs_[PLAY_VIBRATOR_CUSTOM] = &MiscdeviceServiceStub::PlayVibratorCustomStub; -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM baseFuncs_[STOP_VIBRATOR_ALL] = &MiscdeviceServiceStub::StopVibratorAllStub; baseFuncs_[STOP_VIBRATOR_BY_MODE] = &MiscdeviceServiceStub::StopVibratorByModeStub; baseFuncs_[IS_SUPPORT_EFFECT] = &MiscdeviceServiceStub::IsSupportEffectStub; @@ -153,7 +151,6 @@ int32_t MiscdeviceServiceStub::IsSupportEffectStub(MessageParcel &data, MessageP return ret; } -#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t MiscdeviceServiceStub::PlayVibratorCustomStub(MessageParcel &data, MessageParcel &reply) { PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); @@ -196,7 +193,6 @@ int32_t MiscdeviceServiceStub::PlayVibratorCustomStub(MessageParcel &data, Messa } return ret; } -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t MiscdeviceServiceStub::GetLightListStub(MessageParcel &data, MessageParcel &reply) { diff --git a/services/miscdevice_service/src/vibration_priority_manager.cpp b/services/miscdevice_service/src/vibration_priority_manager.cpp index afdc3a7..b5240a1 100755 --- a/services/miscdevice_service/src/vibration_priority_manager.cpp +++ b/services/miscdevice_service/src/vibration_priority_manager.cpp @@ -47,11 +47,7 @@ VibrateStatus VibrationPriorityManager::ShouldIgnoreVibrate(const VibrateInfo &v bool VibrationPriorityManager::IsCurrentVibrate(std::shared_ptr vibratorThread) const { -#if defined(OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM) return ((vibratorThread != nullptr) && (vibratorThread->IsRunning() || VibratorDevice.IsVibratorRunning())); -#else - return ((vibratorThread != nullptr) && (vibratorThread->IsRunning())); -#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM } bool VibrationPriorityManager::IsLoopVibrate(const VibrateInfo &vibrateInfo) const diff --git a/utils/include/sensors_errors.h b/utils/include/sensors_errors.h index e5d16c9..16ccbfc 100644 --- a/utils/include/sensors_errors.h +++ b/utils/include/sensors_errors.h @@ -28,8 +28,8 @@ namespace Sensors { enum ErrorCode : int32_t { PERMISSION_DENIED = 201, // Use this error code when permission is denied. PARAMETER_ERROR = 401, // Use this error code when the input parameter type or range does not match. + IS_NOT_SUPPORTED = 801, // Use this error code when operating is not supported. DEVICE_OPERATION_FAILED = 14600101, // Use this error code when operating the device fail. - IS_NOT_SUPPORTED = 14600102 // Use this error code when operating is not supported. }; enum { -- Gitee From 159a44701d69dc64e987264eb25a62dac9045e7c Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Mon, 24 Apr 2023 09:36:50 +0000 Subject: [PATCH 2/3] custom vibration adapt to rk, code adjust Signed-off-by: lixiangpeng5 Change-Id: I05b1066190bd81319a341db006d8acc30da33643 --- services/miscdevice_service/BUILD.gn | 2 +- .../src/custom_vibration_specific_matcher.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/miscdevice_service/BUILD.gn b/services/miscdevice_service/BUILD.gn index ae0651f..289da36 100644 --- a/services/miscdevice_service/BUILD.gn +++ b/services/miscdevice_service/BUILD.gn @@ -18,7 +18,7 @@ SUBSYSTEM_DIR = "//base/sensors" ohos_shared_library("libmiscdevice_service") { sources = [ "custom_vibrate_decode/src/custom_vibration_default_matcher.cpp", - "custom_vibrate_decode/src/custom_vibration_phone_matcher.cpp", + "custom_vibrate_decode/src/custom_vibration_specific_matcher.cpp", "custom_vibrate_decode/src/default_vibrator_decoder.cpp", "custom_vibrate_decode/src/default_vibrator_decoder_factory.cpp", "hdi_connection/adapter/src/compatible_connection.cpp", diff --git a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_specific_matcher.cpp b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_specific_matcher.cpp index 003bad6..4a10f83 100755 --- a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_specific_matcher.cpp +++ b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_specific_matcher.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "custom_vibration_phone_matcher.h" +#include "custom_vibration_specific_matcher.h" #include #include -- Gitee From 4e6ba9b4a66432b04a8914fef300cfb5ee692527 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Sat, 3 Jun 2023 07:42:10 +0000 Subject: [PATCH 3/3] merge with master Signed-off-by: lixiangpeng5 Change-Id: I118737648293ee876f5f47535015ef86bc49e70e --- services/miscdevice_service/src/miscdevice_service.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/services/miscdevice_service/src/miscdevice_service.cpp b/services/miscdevice_service/src/miscdevice_service.cpp index da10fc0..8663df2 100644 --- a/services/miscdevice_service/src/miscdevice_service.cpp +++ b/services/miscdevice_service/src/miscdevice_service.cpp @@ -309,9 +309,12 @@ int32_t MiscdeviceService::StartCustomVibration(const RawFileDescriptor &rawFd, } MISC_HILOGD("vibrateSet size:%{public}zu", vibrateSet.size()); HdfCompositeEffect hdfCompositeEffect; - hdfCompositeEffect.type = HDF_EFFECT_TYPE_PRIMITIVE; - CustomVibrationMatcher matcher; - int32_t ret = matcher.TransformEffect(vibrateSet, hdfCompositeEffect.compositeEffects); +#ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM + CustomVibrationSpecificMatcher matcher; +#else + CustomVibrationDefaultMatcher matcher; +#endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM + int32_t ret = matcher.TransformEffect(vibrateSet, hdfCompositeEffect); if (ret != SUCCESS) { MISC_HILOGE("transform custom effect error"); return ERROR; -- Gitee