From a326784a817295800d68b74259208dc819bf9e25 Mon Sep 17 00:00:00 2001 From: maan4 Date: Mon, 19 May 2025 11:35:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=89=E6=8B=A9=E8=A1=A8?= =?UTF-8?q?=E8=A7=82=E4=B8=8D=E9=9C=87=E5=8A=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: maan4 --- .../include/miscdevice_service.h | 3 +++ .../src/miscdevice_service.cpp | 24 +++++++++++++++---- test/unittest/vibrator/js/config.json | 3 ++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/services/miscdevice_service/include/miscdevice_service.h b/services/miscdevice_service/include/miscdevice_service.h index 0a4b531..e08f645 100644 --- a/services/miscdevice_service/include/miscdevice_service.h +++ b/services/miscdevice_service/include/miscdevice_service.h @@ -75,6 +75,9 @@ private: bool InitInterface(); bool InitLightInterface(); std::string GetPackageName(AccessTokenID tokenId); +#ifdef OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO + int32_t FastVibratorEffect(const VibrateInfo &info); +#endif // OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO void StartVibrateThread(VibrateInfo info); int32_t StopVibratorService(int32_t vibratorId); void StopVibrateThread(); diff --git a/services/miscdevice_service/src/miscdevice_service.cpp b/services/miscdevice_service/src/miscdevice_service.cpp index 401f2e7..b7d0655 100644 --- a/services/miscdevice_service/src/miscdevice_service.cpp +++ b/services/miscdevice_service/src/miscdevice_service.cpp @@ -70,7 +70,7 @@ VibratorCapacity g_capacity; const std::string PHONE_TYPE = "phone"; #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM #ifdef OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO -constexpr int32_t VIBRATOR_DURATION = 50; +constexpr int32_t SHORT_VIBRATOR_DURATION = 50; #endif // OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO } // namespace @@ -476,9 +476,9 @@ void MiscdeviceService::StartVibrateThread(VibrateInfo info) #ifdef OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO VibrateInfo currentVibrateInfo = vibratorThread_->GetCurrentVibrateInfo(); if (info.duration <= VIBRATOR_DURATION && currentVibrateInfo.duration <= VIBRATOR_DURATION && - info.mode == VIBRATE_PRESET && currentVibrateInfo.mode == VIBRATE_PRESET) { + info.mode == VIBRATE_PRESET && currentVibrateInfo.mode == VIBRATE_PRESET && info.count == 1) { vibratorThread_->UpdateVibratorEffect(info); - vibratorThread_->Start("VibratorThread"); + FastVibratorEffect(info); } else { #endif // OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO StopVibrateThread(); @@ -519,7 +519,8 @@ int32_t MiscdeviceService::StopVibratorByMode(int32_t vibratorId, const std::str MISC_HILOGE("CheckVibratePermission failed, ret:%{public}d", ret); return PERMISSION_DENIED; } - if ((vibratorThread_ == nullptr) || (!vibratorThread_->IsRunning())) { + if ((vibratorThread_ == nullptr) || (!vibratorThread_->IsRunning() && + !vibratorHdiConnection_.IsVibratorRunning())) { MISC_HILOGD("No vibration, no need to stop"); return ERROR; } @@ -529,6 +530,9 @@ int32_t MiscdeviceService::StopVibratorByMode(int32_t vibratorId, const std::str return ERROR; } StopVibrateThread(); + if (vibratorHdiConnection_.IsVibratorRunning()) { + vibratorHdiConnection_.Stop(HDF_VIBRATOR_MODE_PRESET); + } std::string packageName = GetPackageName(GetCallingTokenID()); std::string curVibrateTime = GetCurrentTime(); MISC_HILOGI("Stop vibrator, currentTime:%{public}s, package:%{public}s, pid:%{public}d, vibratorId:%{public}d," @@ -1073,5 +1077,17 @@ int32_t MiscdeviceService::GetVibratorCapacity(VibratorCapacity &capacity) capacity = g_capacity; return ERR_OK; } + +// 手表短振快速下发不启动线程 +#ifdef OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO +int32_t MiscdeviceService::FastVibratorEffect(const VibrateInfo &info) +{ + int32_t ret = VibratorDevice.StartByIntensity(info.effect, info.intensity); + if (ret != SUCCESS) { + MISC_HILOGE("Vibrate effect %{public}s failed.", info.effect.c_str()); + } + return NO_ERROR; +} +#endif // OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO } // namespace Sensors } // namespace OHOS diff --git a/test/unittest/vibrator/js/config.json b/test/unittest/vibrator/js/config.json index e5ff851..cf70146 100644 --- a/test/unittest/vibrator/js/config.json +++ b/test/unittest/vibrator/js/config.json @@ -18,7 +18,8 @@ "deviceType": [ "default", "tablet", - "2in1" + "2in1", + "wearable" ], "distro": { "deliveryWithInstall": true, -- Gitee