diff --git a/services/miscdevice_service/include/miscdevice_service.h b/services/miscdevice_service/include/miscdevice_service.h index 2c159524be4e7190d15986eb7ae0ce9a5896f767..c73c4ad23ebcf43e8b44173dfbb5706ba3b856af 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 41447dbd09e42a788e7ad0e4efd0894c726f5348..03faa8de7edc9f45d0c1fdc2518406e3a41ddb25 100644 --- a/services/miscdevice_service/src/miscdevice_service.cpp +++ b/services/miscdevice_service/src/miscdevice_service.cpp @@ -73,7 +73,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 @@ -501,10 +501,10 @@ 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) { + if (info.duration <= SHORT_VIBRATOR_DURATION && currentVibrateInfo.duration <= SHORT_VIBRATOR_DURATION && + 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(); @@ -545,7 +545,11 @@ 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() +#ifdef OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO + && !vibratorHdiConnection_.IsVibratorRunning() +#endif // OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO + )) { #if defined (OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM) && defined (HDF_DRIVERS_INTERFACE_VIBRATOR) if (vibratorHdiConnection_.IsVibratorRunning()) { vibratorHdiConnection_.Stop(HDF_VIBRATOR_MODE_PRESET); @@ -563,6 +567,11 @@ int32_t MiscdeviceService::StopVibratorByMode(int32_t vibratorId, const std::str return ERROR; } StopVibrateThread(); +#ifdef OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO + if (vibratorHdiConnection_.IsVibratorRunning) { + vibratorHdiConnection_.Stop(HDF_VIBRATOR_MODE_PRESET); + } +#endif // OHOS_BUILD_ENABLE_VIBRATOR_PRESET_INFO 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," @@ -1111,5 +1120,16 @@ 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