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 #define LOG_TAG "VibratorHalWrapper"
18
19 #include <aidl/android/hardware/vibrator/IVibrator.h>
20 #include <hardware/vibrator.h>
21 #include <cmath>
22
23 #include <utils/Log.h>
24
25 #include <vibratorservice/VibratorCallbackScheduler.h>
26 #include <vibratorservice/VibratorHalWrapper.h>
27
28 using aidl::android::hardware::vibrator::Braking;
29 using aidl::android::hardware::vibrator::CompositeEffect;
30 using aidl::android::hardware::vibrator::CompositePrimitive;
31 using aidl::android::hardware::vibrator::CompositePwleV2;
32 using aidl::android::hardware::vibrator::Effect;
33 using aidl::android::hardware::vibrator::EffectStrength;
34 using aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry;
35 using aidl::android::hardware::vibrator::IVibrator;
36 using aidl::android::hardware::vibrator::PrimitivePwle;
37 using aidl::android::hardware::vibrator::VendorEffect;
38
39 using std::chrono::milliseconds;
40
41 namespace android {
42
43 namespace vibrator {
44
45 // -------------------------------------------------------------------------------------------------
46
getInfo()47 Info HalWrapper::getInfo() {
48 getCapabilities();
49 getPrimitiveDurations();
50 std::lock_guard<std::mutex> lock(mInfoMutex);
51 if (mInfoCache.mSupportedEffects.isFailed()) {
52 mInfoCache.mSupportedEffects = getSupportedEffectsInternal();
53 }
54 if (mInfoCache.mSupportedBraking.isFailed()) {
55 mInfoCache.mSupportedBraking = getSupportedBrakingInternal();
56 }
57 if (mInfoCache.mPrimitiveDelayMax.isFailed()) {
58 mInfoCache.mPrimitiveDelayMax = getPrimitiveDelayMaxInternal();
59 }
60 if (mInfoCache.mPwlePrimitiveDurationMax.isFailed()) {
61 mInfoCache.mPwlePrimitiveDurationMax = getPrimitiveDurationMaxInternal();
62 }
63 if (mInfoCache.mCompositionSizeMax.isFailed()) {
64 mInfoCache.mCompositionSizeMax = getCompositionSizeMaxInternal();
65 }
66 if (mInfoCache.mPwleSizeMax.isFailed()) {
67 mInfoCache.mPwleSizeMax = getPwleSizeMaxInternal();
68 }
69 if (mInfoCache.mMinFrequency.isFailed()) {
70 mInfoCache.mMinFrequency = getMinFrequencyInternal();
71 }
72 if (mInfoCache.mResonantFrequency.isFailed()) {
73 mInfoCache.mResonantFrequency = getResonantFrequencyInternal();
74 }
75 if (mInfoCache.mFrequencyResolution.isFailed()) {
76 mInfoCache.mFrequencyResolution = getFrequencyResolutionInternal();
77 }
78 if (mInfoCache.mQFactor.isFailed()) {
79 mInfoCache.mQFactor = getQFactorInternal();
80 }
81 if (mInfoCache.mMaxAmplitudes.isFailed()) {
82 mInfoCache.mMaxAmplitudes = getMaxAmplitudesInternal();
83 }
84 if (mInfoCache.mMaxEnvelopeEffectSize.isFailed()) {
85 mInfoCache.mMaxEnvelopeEffectSize = getMaxEnvelopeEffectSizeInternal();
86 }
87 if (mInfoCache.mMinEnvelopeEffectControlPointDuration.isFailed()) {
88 mInfoCache.mMinEnvelopeEffectControlPointDuration =
89 getMinEnvelopeEffectControlPointDurationInternal();
90 }
91 if (mInfoCache.mMaxEnvelopeEffectControlPointDuration.isFailed()) {
92 mInfoCache.mMaxEnvelopeEffectControlPointDuration =
93 getMaxEnvelopeEffectControlPointDurationInternal();
94 }
95 if (mInfoCache.mFrequencyToOutputAccelerationMap.isFailed()) {
96 mInfoCache.mFrequencyToOutputAccelerationMap =
97 getFrequencyToOutputAccelerationMapInternal();
98 }
99 return mInfoCache.get();
100 }
101
performVendorEffect(const VendorEffect &,const std::function<void ()> &)102 HalResult<void> HalWrapper::performVendorEffect(const VendorEffect&, const std::function<void()>&) {
103 ALOGV("Skipped performVendorEffect because it's not available in Vibrator HAL");
104 return HalResult<void>::unsupported();
105 }
106
performComposedEffect(const std::vector<CompositeEffect> &,const std::function<void ()> &)107 HalResult<milliseconds> HalWrapper::performComposedEffect(const std::vector<CompositeEffect>&,
108 const std::function<void()>&) {
109 ALOGV("Skipped performComposedEffect because it's not available in Vibrator HAL");
110 return HalResult<milliseconds>::unsupported();
111 }
112
performPwleEffect(const std::vector<PrimitivePwle> &,const std::function<void ()> &)113 HalResult<void> HalWrapper::performPwleEffect(const std::vector<PrimitivePwle>&,
114 const std::function<void()>&) {
115 ALOGV("Skipped performPwleEffect because it's not available in Vibrator HAL");
116 return HalResult<void>::unsupported();
117 }
118
composePwleV2(const CompositePwleV2 &,const std::function<void ()> &)119 HalResult<milliseconds> HalWrapper::composePwleV2(const CompositePwleV2&,
120 const std::function<void()>&) {
121 ALOGV("Skipped composePwleV2 because it's not available in Vibrator HAL");
122 return HalResult<milliseconds>::unsupported();
123 }
124
getCapabilities()125 HalResult<Capabilities> HalWrapper::getCapabilities() {
126 std::lock_guard<std::mutex> lock(mInfoMutex);
127 if (mInfoCache.mCapabilities.isFailed()) {
128 mInfoCache.mCapabilities = getCapabilitiesInternal();
129 }
130 return mInfoCache.mCapabilities;
131 }
132
getPrimitiveDurations()133 HalResult<std::vector<milliseconds>> HalWrapper::getPrimitiveDurations() {
134 std::lock_guard<std::mutex> lock(mInfoMutex);
135 if (mInfoCache.mSupportedPrimitives.isFailed()) {
136 mInfoCache.mSupportedPrimitives = getSupportedPrimitivesInternal();
137 if (mInfoCache.mSupportedPrimitives.isUnsupported()) {
138 mInfoCache.mPrimitiveDurations = HalResult<std::vector<milliseconds>>::unsupported();
139 }
140 }
141 if (mInfoCache.mPrimitiveDurations.isFailed() && mInfoCache.mSupportedPrimitives.isOk()) {
142 mInfoCache.mPrimitiveDurations =
143 getPrimitiveDurationsInternal(mInfoCache.mSupportedPrimitives.value());
144 }
145 return mInfoCache.mPrimitiveDurations;
146 }
147
getSupportedEffectsInternal()148 HalResult<std::vector<Effect>> HalWrapper::getSupportedEffectsInternal() {
149 ALOGV("Skipped getSupportedEffects because it's not available in Vibrator HAL");
150 return HalResult<std::vector<Effect>>::unsupported();
151 }
152
getSupportedBrakingInternal()153 HalResult<std::vector<Braking>> HalWrapper::getSupportedBrakingInternal() {
154 ALOGV("Skipped getSupportedBraking because it's not available in Vibrator HAL");
155 return HalResult<std::vector<Braking>>::unsupported();
156 }
157
getSupportedPrimitivesInternal()158 HalResult<std::vector<CompositePrimitive>> HalWrapper::getSupportedPrimitivesInternal() {
159 ALOGV("Skipped getSupportedPrimitives because it's not available in Vibrator HAL");
160 return HalResult<std::vector<CompositePrimitive>>::unsupported();
161 }
162
getPrimitiveDurationsInternal(const std::vector<CompositePrimitive> &)163 HalResult<std::vector<milliseconds>> HalWrapper::getPrimitiveDurationsInternal(
164 const std::vector<CompositePrimitive>&) {
165 ALOGV("Skipped getPrimitiveDurations because it's not available in Vibrator HAL");
166 return HalResult<std::vector<milliseconds>>::unsupported();
167 }
168
getPrimitiveDelayMaxInternal()169 HalResult<milliseconds> HalWrapper::getPrimitiveDelayMaxInternal() {
170 ALOGV("Skipped getPrimitiveDelayMaxInternal because it's not available in Vibrator HAL");
171 return HalResult<milliseconds>::unsupported();
172 }
173
getPrimitiveDurationMaxInternal()174 HalResult<milliseconds> HalWrapper::getPrimitiveDurationMaxInternal() {
175 ALOGV("Skipped getPrimitiveDurationMaxInternal because it's not available in Vibrator HAL");
176 return HalResult<milliseconds>::unsupported();
177 }
178
getCompositionSizeMaxInternal()179 HalResult<int32_t> HalWrapper::getCompositionSizeMaxInternal() {
180 ALOGV("Skipped getCompositionSizeMaxInternal because it's not available in Vibrator HAL");
181 return HalResult<int32_t>::unsupported();
182 }
183
getPwleSizeMaxInternal()184 HalResult<int32_t> HalWrapper::getPwleSizeMaxInternal() {
185 ALOGV("Skipped getPwleSizeMaxInternal because it's not available in Vibrator HAL");
186 return HalResult<int32_t>::unsupported();
187 }
188
getMinFrequencyInternal()189 HalResult<float> HalWrapper::getMinFrequencyInternal() {
190 ALOGV("Skipped getMinFrequency because it's not available in Vibrator HAL");
191 return HalResult<float>::unsupported();
192 }
193
getResonantFrequencyInternal()194 HalResult<float> HalWrapper::getResonantFrequencyInternal() {
195 ALOGV("Skipped getResonantFrequency because it's not available in Vibrator HAL");
196 return HalResult<float>::unsupported();
197 }
198
getFrequencyResolutionInternal()199 HalResult<float> HalWrapper::getFrequencyResolutionInternal() {
200 ALOGV("Skipped getFrequencyResolution because it's not available in Vibrator HAL");
201 return HalResult<float>::unsupported();
202 }
203
getQFactorInternal()204 HalResult<float> HalWrapper::getQFactorInternal() {
205 ALOGV("Skipped getQFactor because it's not available in Vibrator HAL");
206 return HalResult<float>::unsupported();
207 }
208
getMaxAmplitudesInternal()209 HalResult<std::vector<float>> HalWrapper::getMaxAmplitudesInternal() {
210 ALOGV("Skipped getMaxAmplitudes because it's not available in Vibrator HAL");
211 return HalResult<std::vector<float>>::unsupported();
212 }
getMaxEnvelopeEffectSizeInternal()213 HalResult<int32_t> HalWrapper::getMaxEnvelopeEffectSizeInternal() {
214 ALOGV("Skipped getMaxEnvelopeEffectSizeInternal because it's not available "
215 "in Vibrator HAL");
216 return HalResult<int32_t>::unsupported();
217 }
218
getMinEnvelopeEffectControlPointDurationInternal()219 HalResult<milliseconds> HalWrapper::getMinEnvelopeEffectControlPointDurationInternal() {
220 ALOGV("Skipped getMinEnvelopeEffectControlPointDurationInternal because it's not "
221 "available in Vibrator HAL");
222 return HalResult<milliseconds>::unsupported();
223 }
224
getMaxEnvelopeEffectControlPointDurationInternal()225 HalResult<milliseconds> HalWrapper::getMaxEnvelopeEffectControlPointDurationInternal() {
226 ALOGV("Skipped getMaxEnvelopeEffectControlPointDurationInternal because it's not "
227 "available in Vibrator HAL");
228 return HalResult<milliseconds>::unsupported();
229 }
230
231 HalResult<std::vector<FrequencyAccelerationMapEntry>>
getFrequencyToOutputAccelerationMapInternal()232 HalWrapper::getFrequencyToOutputAccelerationMapInternal() {
233 ALOGV("Skipped getFrequencyToOutputAccelerationMapInternal because it's not "
234 "available in Vibrator HAL");
235 return HalResult<std::vector<FrequencyAccelerationMapEntry>>::unsupported();
236 }
237
238 // -------------------------------------------------------------------------------------------------
239
ping()240 HalResult<void> AidlHalWrapper::ping() {
241 return HalResultFactory::fromStatus(AIBinder_ping(getHal()->asBinder().get()));
242 }
243
tryReconnect()244 void AidlHalWrapper::tryReconnect() {
245 auto result = mReconnectFn();
246 if (!result.isOk()) {
247 return;
248 }
249 std::shared_ptr<IVibrator> newHandle = result.value();
250 if (newHandle) {
251 std::lock_guard<std::mutex> lock(mHandleMutex);
252 mHandle = std::move(newHandle);
253 }
254 }
255
on(milliseconds timeout,const std::function<void ()> & completionCallback)256 HalResult<void> AidlHalWrapper::on(milliseconds timeout,
257 const std::function<void()>& completionCallback) {
258 HalResult<Capabilities> capabilities = getCapabilities();
259 bool supportsCallback = capabilities.isOk() &&
260 static_cast<int32_t>(capabilities.value() & Capabilities::ON_CALLBACK);
261 auto cb = supportsCallback ? ndk::SharedRefBase::make<HalCallbackWrapper>(completionCallback)
262 : nullptr;
263
264 auto ret = HalResultFactory::fromStatus(getHal()->on(timeout.count(), cb));
265 if (!supportsCallback && ret.isOk()) {
266 mCallbackScheduler->schedule(completionCallback, timeout);
267 }
268
269 return ret;
270 }
271
off()272 HalResult<void> AidlHalWrapper::off() {
273 return HalResultFactory::fromStatus(getHal()->off());
274 }
275
setAmplitude(float amplitude)276 HalResult<void> AidlHalWrapper::setAmplitude(float amplitude) {
277 return HalResultFactory::fromStatus(getHal()->setAmplitude(amplitude));
278 }
279
setExternalControl(bool enabled)280 HalResult<void> AidlHalWrapper::setExternalControl(bool enabled) {
281 return HalResultFactory::fromStatus(getHal()->setExternalControl(enabled));
282 }
283
alwaysOnEnable(int32_t id,Effect effect,EffectStrength strength)284 HalResult<void> AidlHalWrapper::alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) {
285 return HalResultFactory::fromStatus(getHal()->alwaysOnEnable(id, effect, strength));
286 }
287
alwaysOnDisable(int32_t id)288 HalResult<void> AidlHalWrapper::alwaysOnDisable(int32_t id) {
289 return HalResultFactory::fromStatus(getHal()->alwaysOnDisable(id));
290 }
291
performEffect(Effect effect,EffectStrength strength,const std::function<void ()> & completionCallback)292 HalResult<milliseconds> AidlHalWrapper::performEffect(
293 Effect effect, EffectStrength strength, const std::function<void()>& completionCallback) {
294 HalResult<Capabilities> capabilities = getCapabilities();
295 bool supportsCallback = capabilities.isOk() &&
296 static_cast<int32_t>(capabilities.value() & Capabilities::PERFORM_CALLBACK);
297 auto cb = supportsCallback ? ndk::SharedRefBase::make<HalCallbackWrapper>(completionCallback)
298 : nullptr;
299
300 int32_t lengthMs;
301 auto status = getHal()->perform(effect, strength, cb, &lengthMs);
302 milliseconds length = milliseconds(lengthMs);
303
304 auto ret = HalResultFactory::fromStatus<milliseconds>(std::move(status), length);
305 if (!supportsCallback && ret.isOk()) {
306 mCallbackScheduler->schedule(completionCallback, length);
307 }
308
309 return ret;
310 }
311
performVendorEffect(const VendorEffect & effect,const std::function<void ()> & completionCallback)312 HalResult<void> AidlHalWrapper::performVendorEffect(
313 const VendorEffect& effect, const std::function<void()>& completionCallback) {
314 // This method should always support callbacks, so no need to double check.
315 auto cb = ndk::SharedRefBase::make<HalCallbackWrapper>(completionCallback);
316 return HalResultFactory::fromStatus(getHal()->performVendorEffect(effect, cb));
317 }
318
performComposedEffect(const std::vector<CompositeEffect> & primitives,const std::function<void ()> & completionCallback)319 HalResult<milliseconds> AidlHalWrapper::performComposedEffect(
320 const std::vector<CompositeEffect>& primitives,
321 const std::function<void()>& completionCallback) {
322 // This method should always support callbacks, so no need to double check.
323 auto cb = ndk::SharedRefBase::make<HalCallbackWrapper>(completionCallback);
324
325 auto durations = getPrimitiveDurations().valueOr({});
326 milliseconds duration(0);
327 for (const auto& effect : primitives) {
328 auto primitiveIdx = static_cast<size_t>(effect.primitive);
329 if (primitiveIdx < durations.size()) {
330 duration += durations[primitiveIdx];
331 } else {
332 // Make sure the returned duration is positive to indicate successful vibration.
333 duration += milliseconds(1);
334 }
335 duration += milliseconds(effect.delayMs);
336 }
337
338 return HalResultFactory::fromStatus<milliseconds>(getHal()->compose(primitives, cb), duration);
339 }
340
performPwleEffect(const std::vector<PrimitivePwle> & primitives,const std::function<void ()> & completionCallback)341 HalResult<void> AidlHalWrapper::performPwleEffect(const std::vector<PrimitivePwle>& primitives,
342 const std::function<void()>& completionCallback) {
343 // This method should always support callbacks, so no need to double check.
344 auto cb = ndk::SharedRefBase::make<HalCallbackWrapper>(completionCallback);
345 return HalResultFactory::fromStatus(getHal()->composePwle(primitives, cb));
346 }
347
composePwleV2(const CompositePwleV2 & composite,const std::function<void ()> & completionCallback)348 HalResult<milliseconds> AidlHalWrapper::composePwleV2(
349 const CompositePwleV2& composite, const std::function<void()>& completionCallback) {
350 // This method should always support callbacks, so no need to double check.
351 auto cb = ndk::SharedRefBase::make<HalCallbackWrapper>(completionCallback);
352
353 milliseconds totalDuration(0);
354 for (const auto& primitive : composite.pwlePrimitives) {
355 totalDuration += milliseconds(primitive.timeMillis);
356 }
357
358 return HalResultFactory::fromStatus<milliseconds>(getHal()->composePwleV2(composite, cb),
359 totalDuration);
360 }
361
getCapabilitiesInternal()362 HalResult<Capabilities> AidlHalWrapper::getCapabilitiesInternal() {
363 int32_t cap = 0;
364 auto status = getHal()->getCapabilities(&cap);
365 auto capabilities = static_cast<Capabilities>(cap);
366 return HalResultFactory::fromStatus<Capabilities>(std::move(status), capabilities);
367 }
368
getSupportedEffectsInternal()369 HalResult<std::vector<Effect>> AidlHalWrapper::getSupportedEffectsInternal() {
370 std::vector<Effect> supportedEffects;
371 auto status = getHal()->getSupportedEffects(&supportedEffects);
372 return HalResultFactory::fromStatus<std::vector<Effect>>(std::move(status), supportedEffects);
373 }
374
getSupportedBrakingInternal()375 HalResult<std::vector<Braking>> AidlHalWrapper::getSupportedBrakingInternal() {
376 std::vector<Braking> supportedBraking;
377 auto status = getHal()->getSupportedBraking(&supportedBraking);
378 return HalResultFactory::fromStatus<std::vector<Braking>>(std::move(status), supportedBraking);
379 }
380
getSupportedPrimitivesInternal()381 HalResult<std::vector<CompositePrimitive>> AidlHalWrapper::getSupportedPrimitivesInternal() {
382 std::vector<CompositePrimitive> supportedPrimitives;
383 auto status = getHal()->getSupportedPrimitives(&supportedPrimitives);
384 return HalResultFactory::fromStatus<std::vector<CompositePrimitive>>(std::move(status),
385 supportedPrimitives);
386 }
387
getPrimitiveDurationsInternal(const std::vector<CompositePrimitive> & supportedPrimitives)388 HalResult<std::vector<milliseconds>> AidlHalWrapper::getPrimitiveDurationsInternal(
389 const std::vector<CompositePrimitive>& supportedPrimitives) {
390 std::vector<milliseconds> durations;
391 constexpr auto primitiveRange = ndk::enum_range<CompositePrimitive>();
392 constexpr auto primitiveCount = std::distance(primitiveRange.begin(), primitiveRange.end());
393 durations.resize(primitiveCount);
394
395 for (auto primitive : supportedPrimitives) {
396 auto primitiveIdx = static_cast<size_t>(primitive);
397 if (primitiveIdx >= durations.size()) {
398 // Safety check, should not happen if enum_range is correct.
399 ALOGE("Supported primitive %zu is outside range [0,%zu), skipping load duration",
400 primitiveIdx, durations.size());
401 continue;
402 }
403 int32_t duration = 0;
404 auto status = getHal()->getPrimitiveDuration(primitive, &duration);
405 auto halResult = HalResultFactory::fromStatus<int32_t>(std::move(status), duration);
406 if (halResult.isUnsupported()) {
407 // Should not happen, supported primitives should always support requesting duration.
408 ALOGE("Supported primitive %zu returned unsupported for getPrimitiveDuration",
409 primitiveIdx);
410 }
411 if (halResult.isFailed()) {
412 // Fail entire request if one request has failed.
413 return HalResult<std::vector<milliseconds>>::failed(halResult.errorMessage());
414 }
415 durations[primitiveIdx] = milliseconds(duration);
416 }
417
418 return HalResult<std::vector<milliseconds>>::ok(durations);
419 }
420
getPrimitiveDelayMaxInternal()421 HalResult<milliseconds> AidlHalWrapper::getPrimitiveDelayMaxInternal() {
422 int32_t delay = 0;
423 auto status = getHal()->getCompositionDelayMax(&delay);
424 return HalResultFactory::fromStatus<milliseconds>(std::move(status), milliseconds(delay));
425 }
426
getPrimitiveDurationMaxInternal()427 HalResult<milliseconds> AidlHalWrapper::getPrimitiveDurationMaxInternal() {
428 int32_t delay = 0;
429 auto status = getHal()->getPwlePrimitiveDurationMax(&delay);
430 return HalResultFactory::fromStatus<milliseconds>(std::move(status), milliseconds(delay));
431 }
432
getCompositionSizeMaxInternal()433 HalResult<int32_t> AidlHalWrapper::getCompositionSizeMaxInternal() {
434 int32_t size = 0;
435 auto status = getHal()->getCompositionSizeMax(&size);
436 return HalResultFactory::fromStatus<int32_t>(std::move(status), size);
437 }
438
getPwleSizeMaxInternal()439 HalResult<int32_t> AidlHalWrapper::getPwleSizeMaxInternal() {
440 int32_t size = 0;
441 auto status = getHal()->getPwleCompositionSizeMax(&size);
442 return HalResultFactory::fromStatus<int32_t>(std::move(status), size);
443 }
444
getMinFrequencyInternal()445 HalResult<float> AidlHalWrapper::getMinFrequencyInternal() {
446 float minFrequency = 0;
447 auto status = getHal()->getFrequencyMinimum(&minFrequency);
448 return HalResultFactory::fromStatus<float>(std::move(status), minFrequency);
449 }
450
getResonantFrequencyInternal()451 HalResult<float> AidlHalWrapper::getResonantFrequencyInternal() {
452 float f0 = 0;
453 auto status = getHal()->getResonantFrequency(&f0);
454 return HalResultFactory::fromStatus<float>(std::move(status), f0);
455 }
456
getFrequencyResolutionInternal()457 HalResult<float> AidlHalWrapper::getFrequencyResolutionInternal() {
458 float frequencyResolution = 0;
459 auto status = getHal()->getFrequencyResolution(&frequencyResolution);
460 return HalResultFactory::fromStatus<float>(std::move(status), frequencyResolution);
461 }
462
getQFactorInternal()463 HalResult<float> AidlHalWrapper::getQFactorInternal() {
464 float qFactor = 0;
465 auto status = getHal()->getQFactor(&qFactor);
466 return HalResultFactory::fromStatus<float>(std::move(status), qFactor);
467 }
468
getMaxAmplitudesInternal()469 HalResult<std::vector<float>> AidlHalWrapper::getMaxAmplitudesInternal() {
470 std::vector<float> amplitudes;
471 auto status = getHal()->getBandwidthAmplitudeMap(&litudes);
472 return HalResultFactory::fromStatus<std::vector<float>>(std::move(status), amplitudes);
473 }
474
getMaxEnvelopeEffectSizeInternal()475 HalResult<int32_t> AidlHalWrapper::getMaxEnvelopeEffectSizeInternal() {
476 int32_t size = 0;
477 auto status = getHal()->getPwleV2CompositionSizeMax(&size);
478 return HalResultFactory::fromStatus<int32_t>(std::move(status), size);
479 }
480
getMinEnvelopeEffectControlPointDurationInternal()481 HalResult<milliseconds> AidlHalWrapper::getMinEnvelopeEffectControlPointDurationInternal() {
482 int32_t durationMs = 0;
483 auto status = getHal()->getPwleV2PrimitiveDurationMinMillis(&durationMs);
484 return HalResultFactory::fromStatus<milliseconds>(std::move(status), milliseconds(durationMs));
485 }
486
getMaxEnvelopeEffectControlPointDurationInternal()487 HalResult<milliseconds> AidlHalWrapper::getMaxEnvelopeEffectControlPointDurationInternal() {
488 int32_t durationMs = 0;
489 auto status = getHal()->getPwleV2PrimitiveDurationMaxMillis(&durationMs);
490 return HalResultFactory::fromStatus<milliseconds>(std::move(status), milliseconds(durationMs));
491 }
492
493 HalResult<std::vector<FrequencyAccelerationMapEntry>>
getFrequencyToOutputAccelerationMapInternal()494 AidlHalWrapper::getFrequencyToOutputAccelerationMapInternal() {
495 std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap;
496 auto status = getHal()->getFrequencyToOutputAccelerationMap(&frequencyToOutputAccelerationMap);
497 return HalResultFactory::fromStatus<
498 std::vector<FrequencyAccelerationMapEntry>>(std::move(status),
499 frequencyToOutputAccelerationMap);
500 }
501
getHal()502 std::shared_ptr<IVibrator> AidlHalWrapper::getHal() {
503 std::lock_guard<std::mutex> lock(mHandleMutex);
504 return mHandle;
505 }
506
507 // -------------------------------------------------------------------------------------------------
508
509 }; // namespace vibrator
510
511 }; // namespace android
512