1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // TODO(b/308452413): remove this file once android.os.vibrator.remove_hidl_support is removed 18 19 #ifndef ANDROID_OS_VIBRATORHALWRAPPER_H 20 #define ANDROID_OS_VIBRATORHALWRAPPER_H 21 22 #include <aidl/android/hardware/vibrator/BnVibratorCallback.h> 23 #include <aidl/android/hardware/vibrator/IVibrator.h> 24 25 #include <android-base/thread_annotations.h> 26 #include <android/binder_manager.h> 27 #include <binder/IServiceManager.h> 28 29 #include <vibratorservice/VibratorCallbackScheduler.h> 30 31 namespace android { 32 33 namespace vibrator { 34 35 // ------------------------------------------------------------------------------------------------- 36 37 // Base class to represent a generic result of a call to the Vibrator HAL wrapper. 38 class BaseHalResult { 39 public: isOk()40 bool isOk() const { return mStatus == SUCCESS; } isFailed()41 bool isFailed() const { return mStatus == FAILED; } isUnsupported()42 bool isUnsupported() const { return mStatus == UNSUPPORTED; } shouldRetry()43 bool shouldRetry() const { return isFailed() && mDeadObject; } errorMessage()44 const char* errorMessage() const { return mErrorMessage.c_str(); } 45 46 protected: 47 enum Status { SUCCESS, UNSUPPORTED, FAILED }; 48 Status mStatus; 49 std::string mErrorMessage; 50 bool mDeadObject; 51 52 explicit BaseHalResult(Status status, const char* errorMessage = "", bool deadObject = false) mStatus(status)53 : mStatus(status), mErrorMessage(errorMessage), mDeadObject(deadObject) {} 54 virtual ~BaseHalResult() = default; 55 }; 56 57 // Result of a call to the Vibrator HAL wrapper, holding data if successful. 58 template <typename T> 59 class HalResult : public BaseHalResult { 60 public: ok(T value)61 static HalResult<T> ok(T value) { return HalResult(value); } unsupported()62 static HalResult<T> unsupported() { return HalResult(Status::UNSUPPORTED); } failed(const char * msg)63 static HalResult<T> failed(const char* msg) { return HalResult(Status::FAILED, msg); } transactionFailed(const char * msg)64 static HalResult<T> transactionFailed(const char* msg) { 65 return HalResult(Status::FAILED, msg, /* deadObject= */ true); 66 } 67 68 // This will throw std::bad_optional_access if this result is not ok. value()69 const T& value() const { return mValue.value(); } valueOr(T && defaultValue)70 const T valueOr(T&& defaultValue) const { return mValue.value_or(defaultValue); } 71 72 private: 73 std::optional<T> mValue; 74 HalResult(T value)75 explicit HalResult(T value) 76 : BaseHalResult(Status::SUCCESS), mValue(std::make_optional(value)) {} 77 explicit HalResult(Status status, const char* errorMessage = "", bool deadObject = false) BaseHalResult(status,errorMessage,deadObject)78 : BaseHalResult(status, errorMessage, deadObject), mValue() {} 79 }; 80 81 // Empty result of a call to the Vibrator HAL wrapper. 82 template <> 83 class HalResult<void> : public BaseHalResult { 84 public: ok()85 static HalResult<void> ok() { return HalResult(Status::SUCCESS); } unsupported()86 static HalResult<void> unsupported() { return HalResult(Status::UNSUPPORTED); } failed(const char * msg)87 static HalResult<void> failed(const char* msg) { return HalResult(Status::FAILED, msg); } transactionFailed(const char * msg)88 static HalResult<void> transactionFailed(const char* msg) { 89 return HalResult(Status::FAILED, msg, /* deadObject= */ true); 90 } 91 92 private: 93 explicit HalResult(Status status, const char* errorMessage = "", bool deadObject = false) BaseHalResult(status,errorMessage,deadObject)94 : BaseHalResult(status, errorMessage, deadObject) {} 95 }; 96 97 // ------------------------------------------------------------------------------------------------- 98 99 // Factory functions that convert failed HIDL/AIDL results into HalResult instances. 100 // Implementation of static template functions needs to be in this header file for the linker. 101 class HalResultFactory { 102 public: 103 template <typename T> fromStatus(ndk::ScopedAStatus && status,T data)104 static HalResult<T> fromStatus(ndk::ScopedAStatus&& status, T data) { 105 return status.isOk() ? HalResult<T>::ok(std::move(data)) 106 : fromFailedStatus<T>(std::move(status)); 107 } 108 fromStatus(status_t status)109 static HalResult<void> fromStatus(status_t status) { 110 return (status == android::OK) ? HalResult<void>::ok() 111 : fromFailedStatus<void>(std::move(status)); 112 } 113 fromStatus(ndk::ScopedAStatus && status)114 static HalResult<void> fromStatus(ndk::ScopedAStatus&& status) { 115 return status.isOk() ? HalResult<void>::ok() : fromFailedStatus<void>(std::move(status)); 116 } 117 118 private: 119 template <typename T> fromFailedStatus(status_t status)120 static HalResult<T> fromFailedStatus(status_t status) { 121 auto msg = "status_t = " + statusToString(status); 122 return (status == android::DEAD_OBJECT) ? HalResult<T>::transactionFailed(msg.c_str()) 123 : HalResult<T>::failed(msg.c_str()); 124 } 125 126 template <typename T> fromFailedStatus(ndk::ScopedAStatus && status)127 static HalResult<T> fromFailedStatus(ndk::ScopedAStatus&& status) { 128 if (status.getExceptionCode() == EX_UNSUPPORTED_OPERATION || 129 status.getStatus() == STATUS_UNKNOWN_TRANSACTION) { 130 // STATUS_UNKNOWN_TRANSACTION means the HAL implementation is an older version, so this 131 // is the same as the operation being unsupported by this HAL. Should not retry. 132 return HalResult<T>::unsupported(); 133 } 134 if (status.getExceptionCode() == EX_TRANSACTION_FAILED) { 135 return HalResult<T>::transactionFailed(status.getMessage()); 136 } 137 return HalResult<T>::failed(status.getMessage()); 138 } 139 }; 140 141 // ------------------------------------------------------------------------------------------------- 142 143 class HalCallbackWrapper : public aidl::android::hardware::vibrator::BnVibratorCallback { 144 public: HalCallbackWrapper(std::function<void ()> completionCallback)145 HalCallbackWrapper(std::function<void()> completionCallback) 146 : mCompletionCallback(completionCallback) {} 147 onComplete()148 ndk::ScopedAStatus onComplete() override { 149 mCompletionCallback(); 150 return ndk::ScopedAStatus::ok(); 151 } 152 153 private: 154 const std::function<void()> mCompletionCallback; 155 }; 156 157 // ------------------------------------------------------------------------------------------------- 158 159 // Vibrator HAL capabilities. 160 enum class Capabilities : int32_t { 161 NONE = 0, 162 ON_CALLBACK = aidl::android::hardware::vibrator::IVibrator::CAP_ON_CALLBACK, 163 PERFORM_CALLBACK = aidl::android::hardware::vibrator::IVibrator::CAP_PERFORM_CALLBACK, 164 AMPLITUDE_CONTROL = aidl::android::hardware::vibrator::IVibrator::CAP_AMPLITUDE_CONTROL, 165 EXTERNAL_CONTROL = aidl::android::hardware::vibrator::IVibrator::CAP_EXTERNAL_CONTROL, 166 EXTERNAL_AMPLITUDE_CONTROL = 167 aidl::android::hardware::vibrator::IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL, 168 COMPOSE_EFFECTS = aidl::android::hardware::vibrator::IVibrator::CAP_COMPOSE_EFFECTS, 169 COMPOSE_PWLE_EFFECTS = aidl::android::hardware::vibrator::IVibrator::CAP_COMPOSE_PWLE_EFFECTS, 170 ALWAYS_ON_CONTROL = aidl::android::hardware::vibrator::IVibrator::CAP_ALWAYS_ON_CONTROL, 171 }; 172 173 inline Capabilities operator|(Capabilities lhs, Capabilities rhs) { 174 using underlying = typename std::underlying_type<Capabilities>::type; 175 return static_cast<Capabilities>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs)); 176 } 177 178 inline Capabilities& operator|=(Capabilities& lhs, Capabilities rhs) { 179 return lhs = lhs | rhs; 180 } 181 182 inline Capabilities operator&(Capabilities lhs, Capabilities rhs) { 183 using underlying = typename std::underlying_type<Capabilities>::type; 184 return static_cast<Capabilities>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs)); 185 } 186 187 inline Capabilities& operator&=(Capabilities& lhs, Capabilities rhs) { 188 return lhs = lhs & rhs; 189 } 190 191 // ------------------------------------------------------------------------------------------------- 192 193 class Info { 194 public: 195 using Effect = aidl::android::hardware::vibrator::Effect; 196 using EffectStrength = aidl::android::hardware::vibrator::EffectStrength; 197 using CompositePrimitive = aidl::android::hardware::vibrator::CompositePrimitive; 198 using Braking = aidl::android::hardware::vibrator::Braking; 199 using FrequencyAccelerationMapEntry = 200 aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry; 201 202 const HalResult<Capabilities> capabilities; 203 const HalResult<std::vector<Effect>> supportedEffects; 204 const HalResult<std::vector<Braking>> supportedBraking; 205 const HalResult<std::vector<CompositePrimitive>> supportedPrimitives; 206 const HalResult<std::vector<std::chrono::milliseconds>> primitiveDurations; 207 const HalResult<std::chrono::milliseconds> primitiveDelayMax; 208 const HalResult<std::chrono::milliseconds> pwlePrimitiveDurationMax; 209 const HalResult<int32_t> compositionSizeMax; 210 const HalResult<int32_t> pwleSizeMax; 211 const HalResult<float> minFrequency; 212 const HalResult<float> resonantFrequency; 213 const HalResult<float> frequencyResolution; 214 const HalResult<float> qFactor; 215 const HalResult<std::vector<float>> maxAmplitudes; 216 const HalResult<int32_t> maxEnvelopeEffectSize; 217 const HalResult<std::chrono::milliseconds> minEnvelopeEffectControlPointDuration; 218 const HalResult<std::chrono::milliseconds> maxEnvelopeEffectControlPointDuration; 219 const HalResult<std::vector<FrequencyAccelerationMapEntry>> frequencyToOutputAccelerationMap; 220 logFailures()221 void logFailures() const { 222 logFailure<Capabilities>(capabilities, "getCapabilities"); 223 logFailure<std::vector<Effect>>(supportedEffects, "getSupportedEffects"); 224 logFailure<std::vector<Braking>>(supportedBraking, "getSupportedBraking"); 225 logFailure<std::vector<CompositePrimitive>>(supportedPrimitives, "getSupportedPrimitives"); 226 logFailure<std::vector<std::chrono::milliseconds>>(primitiveDurations, 227 "getPrimitiveDuration"); 228 logFailure<std::chrono::milliseconds>(primitiveDelayMax, "getPrimitiveDelayMax"); 229 logFailure<std::chrono::milliseconds>(pwlePrimitiveDurationMax, 230 "getPwlePrimitiveDurationMax"); 231 logFailure<int32_t>(compositionSizeMax, "getCompositionSizeMax"); 232 logFailure<int32_t>(pwleSizeMax, "getPwleSizeMax"); 233 logFailure<float>(minFrequency, "getMinFrequency"); 234 logFailure<float>(resonantFrequency, "getResonantFrequency"); 235 logFailure<float>(frequencyResolution, "getFrequencyResolution"); 236 logFailure<float>(qFactor, "getQFactor"); 237 logFailure<std::vector<float>>(maxAmplitudes, "getMaxAmplitudes"); 238 logFailure<int32_t>(maxEnvelopeEffectSize, "getMaxEnvelopeEffectSize"); 239 logFailure<std::chrono::milliseconds>(minEnvelopeEffectControlPointDuration, 240 "getMinEnvelopeEffectControlPointDuration"); 241 logFailure<std::chrono::milliseconds>(maxEnvelopeEffectControlPointDuration, 242 "getMaxEnvelopeEffectControlPointDuration"); 243 logFailure< 244 std::vector<FrequencyAccelerationMapEntry>>(frequencyToOutputAccelerationMap, 245 "getfrequencyToOutputAccelerationMap"); 246 } 247 shouldRetry()248 bool shouldRetry() const { 249 return capabilities.shouldRetry() || supportedEffects.shouldRetry() || 250 supportedBraking.shouldRetry() || supportedPrimitives.shouldRetry() || 251 primitiveDurations.shouldRetry() || primitiveDelayMax.shouldRetry() || 252 pwlePrimitiveDurationMax.shouldRetry() || compositionSizeMax.shouldRetry() || 253 pwleSizeMax.shouldRetry() || minFrequency.shouldRetry() || 254 resonantFrequency.shouldRetry() || frequencyResolution.shouldRetry() || 255 qFactor.shouldRetry() || maxAmplitudes.shouldRetry() || 256 maxEnvelopeEffectSize.shouldRetry() || 257 minEnvelopeEffectControlPointDuration.shouldRetry() || 258 maxEnvelopeEffectControlPointDuration.shouldRetry() || 259 frequencyToOutputAccelerationMap.shouldRetry(); 260 } 261 262 private: 263 template <typename T> logFailure(HalResult<T> result,const char * functionName)264 void logFailure(HalResult<T> result, const char* functionName) const { 265 if (result.isFailed()) { 266 ALOGE("Vibrator HAL %s failed: %s", functionName, result.errorMessage()); 267 } 268 } 269 }; 270 271 class InfoCache { 272 public: get()273 Info get() { 274 return {mCapabilities, 275 mSupportedEffects, 276 mSupportedBraking, 277 mSupportedPrimitives, 278 mPrimitiveDurations, 279 mPrimitiveDelayMax, 280 mPwlePrimitiveDurationMax, 281 mCompositionSizeMax, 282 mPwleSizeMax, 283 mMinFrequency, 284 mResonantFrequency, 285 mFrequencyResolution, 286 mQFactor, 287 mMaxAmplitudes, 288 mMaxEnvelopeEffectSize, 289 mMinEnvelopeEffectControlPointDuration, 290 mMaxEnvelopeEffectControlPointDuration, 291 mFrequencyToOutputAccelerationMap}; 292 } 293 294 private: 295 // Create a transaction failed results as default so we can retry on the first time we get them. 296 static const constexpr char* MSG = "never loaded"; 297 HalResult<Capabilities> mCapabilities = HalResult<Capabilities>::transactionFailed(MSG); 298 HalResult<std::vector<Info::Effect>> mSupportedEffects = 299 HalResult<std::vector<Info::Effect>>::transactionFailed(MSG); 300 HalResult<std::vector<Info::Braking>> mSupportedBraking = 301 HalResult<std::vector<Info::Braking>>::transactionFailed(MSG); 302 HalResult<std::vector<Info::CompositePrimitive>> mSupportedPrimitives = 303 HalResult<std::vector<Info::CompositePrimitive>>::transactionFailed(MSG); 304 HalResult<std::vector<std::chrono::milliseconds>> mPrimitiveDurations = 305 HalResult<std::vector<std::chrono::milliseconds>>::transactionFailed(MSG); 306 HalResult<std::chrono::milliseconds> mPrimitiveDelayMax = 307 HalResult<std::chrono::milliseconds>::transactionFailed(MSG); 308 HalResult<std::chrono::milliseconds> mPwlePrimitiveDurationMax = 309 HalResult<std::chrono::milliseconds>::transactionFailed(MSG); 310 HalResult<int32_t> mCompositionSizeMax = HalResult<int>::transactionFailed(MSG); 311 HalResult<int32_t> mPwleSizeMax = HalResult<int>::transactionFailed(MSG); 312 HalResult<float> mMinFrequency = HalResult<float>::transactionFailed(MSG); 313 HalResult<float> mResonantFrequency = HalResult<float>::transactionFailed(MSG); 314 HalResult<float> mFrequencyResolution = HalResult<float>::transactionFailed(MSG); 315 HalResult<float> mQFactor = HalResult<float>::transactionFailed(MSG); 316 HalResult<std::vector<float>> mMaxAmplitudes = 317 HalResult<std::vector<float>>::transactionFailed(MSG); 318 HalResult<int32_t> mMaxEnvelopeEffectSize = HalResult<int>::transactionFailed(MSG); 319 HalResult<std::chrono::milliseconds> mMinEnvelopeEffectControlPointDuration = 320 HalResult<std::chrono::milliseconds>::transactionFailed(MSG); 321 HalResult<std::chrono::milliseconds> mMaxEnvelopeEffectControlPointDuration = 322 HalResult<std::chrono::milliseconds>::transactionFailed(MSG); 323 HalResult<std::vector<Info::FrequencyAccelerationMapEntry>> mFrequencyToOutputAccelerationMap = 324 HalResult<std::vector<Info::FrequencyAccelerationMapEntry>>::transactionFailed(MSG); 325 326 friend class HalWrapper; 327 }; 328 329 // Wrapper for Vibrator HAL handlers. 330 class HalWrapper { 331 public: 332 using Effect = aidl::android::hardware::vibrator::Effect; 333 using EffectStrength = aidl::android::hardware::vibrator::EffectStrength; 334 using VendorEffect = aidl::android::hardware::vibrator::VendorEffect; 335 using CompositePrimitive = aidl::android::hardware::vibrator::CompositePrimitive; 336 using CompositeEffect = aidl::android::hardware::vibrator::CompositeEffect; 337 using Braking = aidl::android::hardware::vibrator::Braking; 338 using PrimitivePwle = aidl::android::hardware::vibrator::PrimitivePwle; 339 using CompositePwleV2 = aidl::android::hardware::vibrator::CompositePwleV2; 340 using FrequencyAccelerationMapEntry = 341 aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry; 342 HalWrapper(std::shared_ptr<CallbackScheduler> scheduler)343 explicit HalWrapper(std::shared_ptr<CallbackScheduler> scheduler) 344 : mCallbackScheduler(std::move(scheduler)) {} 345 virtual ~HalWrapper() = default; 346 347 /* reloads wrapped HAL service instance without waiting. This can be used to reconnect when the 348 * service restarts, to rapidly retry after a failure. 349 */ 350 virtual void tryReconnect() = 0; 351 352 Info getInfo(); 353 354 virtual HalResult<void> ping() = 0; 355 virtual HalResult<void> on(std::chrono::milliseconds timeout, 356 const std::function<void()>& completionCallback) = 0; 357 virtual HalResult<void> off() = 0; 358 359 virtual HalResult<void> setAmplitude(float amplitude) = 0; 360 virtual HalResult<void> setExternalControl(bool enabled) = 0; 361 362 virtual HalResult<void> alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) = 0; 363 virtual HalResult<void> alwaysOnDisable(int32_t id) = 0; 364 365 virtual HalResult<std::chrono::milliseconds> performEffect( 366 Effect effect, EffectStrength strength, 367 const std::function<void()>& completionCallback) = 0; 368 369 virtual HalResult<void> performVendorEffect(const VendorEffect& effect, 370 const std::function<void()>& completionCallback); 371 372 virtual HalResult<std::chrono::milliseconds> performComposedEffect( 373 const std::vector<CompositeEffect>& primitives, 374 const std::function<void()>& completionCallback); 375 376 virtual HalResult<void> performPwleEffect(const std::vector<PrimitivePwle>& primitives, 377 const std::function<void()>& completionCallback); 378 379 virtual HalResult<std::chrono::milliseconds> composePwleV2( 380 const CompositePwleV2& composite, const std::function<void()>& completionCallback); 381 382 protected: 383 // Shared pointer to allow CallbackScheduler to outlive this wrapper. 384 const std::shared_ptr<CallbackScheduler> mCallbackScheduler; 385 386 // Load and cache vibrator info, returning cached result is present. 387 HalResult<Capabilities> getCapabilities(); 388 HalResult<std::vector<std::chrono::milliseconds>> getPrimitiveDurations(); 389 390 // Request vibrator info to HAL skipping cache. 391 virtual HalResult<Capabilities> getCapabilitiesInternal() = 0; 392 virtual HalResult<std::vector<Effect>> getSupportedEffectsInternal(); 393 virtual HalResult<std::vector<Braking>> getSupportedBrakingInternal(); 394 virtual HalResult<std::vector<CompositePrimitive>> getSupportedPrimitivesInternal(); 395 virtual HalResult<std::vector<std::chrono::milliseconds>> getPrimitiveDurationsInternal( 396 const std::vector<CompositePrimitive>& supportedPrimitives); 397 virtual HalResult<std::chrono::milliseconds> getPrimitiveDelayMaxInternal(); 398 virtual HalResult<std::chrono::milliseconds> getPrimitiveDurationMaxInternal(); 399 virtual HalResult<int32_t> getCompositionSizeMaxInternal(); 400 virtual HalResult<int32_t> getPwleSizeMaxInternal(); 401 virtual HalResult<float> getMinFrequencyInternal(); 402 virtual HalResult<float> getResonantFrequencyInternal(); 403 virtual HalResult<float> getFrequencyResolutionInternal(); 404 virtual HalResult<float> getQFactorInternal(); 405 virtual HalResult<std::vector<float>> getMaxAmplitudesInternal(); 406 virtual HalResult<int32_t> getMaxEnvelopeEffectSizeInternal(); 407 virtual HalResult<std::chrono::milliseconds> getMinEnvelopeEffectControlPointDurationInternal(); 408 virtual HalResult<std::chrono::milliseconds> getMaxEnvelopeEffectControlPointDurationInternal(); 409 virtual HalResult<std::vector<FrequencyAccelerationMapEntry>> 410 getFrequencyToOutputAccelerationMapInternal(); 411 412 private: 413 std::mutex mInfoMutex; 414 InfoCache mInfoCache GUARDED_BY(mInfoMutex); 415 }; 416 417 // Wrapper for the AIDL Vibrator HAL. 418 class AidlHalWrapper : public HalWrapper { 419 public: 420 using IVibrator = aidl::android::hardware::vibrator::IVibrator; 421 using reconnect_fn = std::function<HalResult<std::shared_ptr<IVibrator>>()>; 422 423 AidlHalWrapper( 424 std::shared_ptr<CallbackScheduler> scheduler, std::shared_ptr<IVibrator> handle, 425 reconnect_fn reconnectFn = 426 []() { 427 auto serviceName = std::string(IVibrator::descriptor) + "/default"; 428 auto hal = IVibrator::fromBinder( 429 ndk::SpAIBinder(AServiceManager_checkService(serviceName.c_str()))); 430 return HalResult<std::shared_ptr<IVibrator>>::ok(std::move(hal)); 431 }) HalWrapper(std::move (scheduler))432 : HalWrapper(std::move(scheduler)), 433 mReconnectFn(reconnectFn), 434 mHandle(std::move(handle)) {} 435 virtual ~AidlHalWrapper() = default; 436 437 HalResult<void> ping() override final; 438 void tryReconnect() override final; 439 440 HalResult<void> on(std::chrono::milliseconds timeout, 441 const std::function<void()>& completionCallback) override final; 442 HalResult<void> off() override final; 443 444 HalResult<void> setAmplitude(float amplitude) override final; 445 HalResult<void> setExternalControl(bool enabled) override final; 446 447 HalResult<void> alwaysOnEnable(int32_t id, Effect effect, 448 EffectStrength strength) override final; 449 HalResult<void> alwaysOnDisable(int32_t id) override final; 450 451 HalResult<std::chrono::milliseconds> performEffect( 452 Effect effect, EffectStrength strength, 453 const std::function<void()>& completionCallback) override final; 454 455 HalResult<void> performVendorEffect( 456 const VendorEffect& effect, 457 const std::function<void()>& completionCallback) override final; 458 459 HalResult<std::chrono::milliseconds> performComposedEffect( 460 const std::vector<CompositeEffect>& primitives, 461 const std::function<void()>& completionCallback) override final; 462 463 HalResult<void> performPwleEffect( 464 const std::vector<PrimitivePwle>& primitives, 465 const std::function<void()>& completionCallback) override final; 466 467 HalResult<std::chrono::milliseconds> composePwleV2( 468 const CompositePwleV2& composite, 469 const std::function<void()>& completionCallback) override final; 470 471 protected: 472 HalResult<Capabilities> getCapabilitiesInternal() override final; 473 HalResult<std::vector<Effect>> getSupportedEffectsInternal() override final; 474 HalResult<std::vector<Braking>> getSupportedBrakingInternal() override final; 475 HalResult<std::vector<CompositePrimitive>> getSupportedPrimitivesInternal() override final; 476 HalResult<std::vector<std::chrono::milliseconds>> getPrimitiveDurationsInternal( 477 const std::vector<CompositePrimitive>& supportedPrimitives) override final; 478 HalResult<std::chrono::milliseconds> getPrimitiveDelayMaxInternal() override final; 479 HalResult<std::chrono::milliseconds> getPrimitiveDurationMaxInternal() override final; 480 HalResult<int32_t> getCompositionSizeMaxInternal() override final; 481 HalResult<int32_t> getPwleSizeMaxInternal() override final; 482 HalResult<float> getMinFrequencyInternal() override final; 483 HalResult<float> getResonantFrequencyInternal() override final; 484 HalResult<float> getFrequencyResolutionInternal() override final; 485 HalResult<float> getQFactorInternal() override final; 486 HalResult<std::vector<float>> getMaxAmplitudesInternal() override final; 487 HalResult<int32_t> getMaxEnvelopeEffectSizeInternal() override final; 488 HalResult<std::chrono::milliseconds> getMinEnvelopeEffectControlPointDurationInternal() 489 override final; 490 HalResult<std::chrono::milliseconds> getMaxEnvelopeEffectControlPointDurationInternal() 491 override final; 492 493 HalResult<std::vector<FrequencyAccelerationMapEntry>> 494 getFrequencyToOutputAccelerationMapInternal() override final; 495 496 private: 497 const reconnect_fn mReconnectFn; 498 std::mutex mHandleMutex; 499 std::shared_ptr<IVibrator> mHandle GUARDED_BY(mHandleMutex); 500 501 std::shared_ptr<IVibrator> getHal(); 502 }; 503 504 // ------------------------------------------------------------------------------------------------- 505 506 }; // namespace vibrator 507 508 }; // namespace android 509 510 #endif // ANDROID_OS_VIBRATORHALWRAPPER_H 511