diff --git a/services/miscdevice_service/include/miscdevice_service.h b/services/miscdevice_service/include/miscdevice_service.h index 2c159524be4e7190d15986eb7ae0ce9a5896f767..9cdbd48819cb14f08e032eef78c79795f08cea4d 100644 --- a/services/miscdevice_service/include/miscdevice_service.h +++ b/services/miscdevice_service/include/miscdevice_service.h @@ -97,6 +97,7 @@ private: int32_t PlayPatternCheckAuthAndParam(int32_t usage, const VibrateParameter ¶meter); int32_t PlayPrimitiveEffectCheckAuthAndParam(int32_t intensity, int32_t usage); int32_t PlayVibratorEffectCheckAuthAndParam(int32_t count, int32_t usage); + std::optional GetEffectInfo(const std::string &effect); std::mutex isVibrationPriorityReadyMutex_; static bool isVibrationPriorityReady_; VibratorHdiConnection &vibratorHdiConnection_ = VibratorHdiConnection::GetInstance(); @@ -114,6 +115,7 @@ private: std::mutex clientPidMapMutex_; std::mutex miscDeviceIdMapMutex_; std::mutex lightInfosMutex_; + std::map> effectInfoMap_; }; } // namespace Sensors } // namespace OHOS diff --git a/services/miscdevice_service/src/miscdevice_service.cpp b/services/miscdevice_service/src/miscdevice_service.cpp index 50c20668be8fcdf25cfb3b56165fd34068e0cbcc..6200e4c24bcd0d6b048536ef195135849767d0d1 100644 --- a/services/miscdevice_service/src/miscdevice_service.cpp +++ b/services/miscdevice_service/src/miscdevice_service.cpp @@ -437,7 +437,7 @@ int32_t MiscdeviceService::PlayVibratorEffect(int32_t vibratorId, const std::str return checkResult; } #ifdef HDF_DRIVERS_INTERFACE_VIBRATOR - std::optional effectInfo = vibratorHdiConnection_.GetEffectInfo(effect); + std::optional effectInfo = GetEffectInfo(effect); if (!effectInfo) { MISC_HILOGE("GetEffectInfo fail"); return ERROR; @@ -561,7 +561,7 @@ int32_t MiscdeviceService::StopVibratorByMode(int32_t vibratorId, const std::str int32_t MiscdeviceService::IsSupportEffect(const std::string &effect, bool &state) { #ifdef HDF_DRIVERS_INTERFACE_VIBRATOR - std::optional effectInfo = vibratorHdiConnection_.GetEffectInfo(effect); + std::optional effectInfo = GetEffectInfo(effect); if (!effectInfo) { MISC_HILOGE("GetEffectInfo fail"); return ERROR; @@ -575,6 +575,24 @@ int32_t MiscdeviceService::IsSupportEffect(const std::string &effect, bool &stat return NO_ERROR; } +std::optional MiscdeviceService::GetEffectInfo(const std::string &effect) +{ + auto it = effectInfoMap_.find(effect); + if (it != effectInfoMap_.end()) { + return it->second; + } + std::optional effectInfo = vibratorHdiConnection_.GetEffectInfo(effect); + if (!effectInfo) { + MISC_HILOGE("GetEffectInfo fail"); + return effectInfo; + } + effectInfoMap_.insert(std::make_pair(effect, effectInfo)); + for (auto iter = effectInfoMap_.begin(); iter != effectInfoMap_.end(); ++iter) { + MISC_HILOGD("effect:%{public}s, state:%{public}d", iter->first.c_str(), iter->second->isSupportEffect); + } + return effectInfo; +} + std::string MiscdeviceService::GetCurrentTime() { timespec curTime; @@ -1034,7 +1052,7 @@ int32_t MiscdeviceService::PlayPrimitiveEffect(int32_t vibratorId, const std::st return checkResult; } #ifdef HDF_DRIVERS_INTERFACE_VIBRATOR - std::optional effectInfo = vibratorHdiConnection_.GetEffectInfo(effect); + std::optional effectInfo = GetEffectInfo(effect); if (!effectInfo) { MISC_HILOGE("GetEffectInfo fail"); return ERROR;