Skip to content

Commit 1c375bb

Browse files
Ahmad KhalilAndroid (Google) Code Review
authored andcommitted
Merge "Modify composePwleV2 parameters" into main
2 parents b5963dc + 754a9cc commit 1c375bb

5 files changed

Lines changed: 56 additions & 50 deletions

File tree

services/vibratorservice/VibratorHalWrapper.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
using aidl::android::hardware::vibrator::Braking;
3030
using aidl::android::hardware::vibrator::CompositeEffect;
3131
using aidl::android::hardware::vibrator::CompositePrimitive;
32+
using aidl::android::hardware::vibrator::CompositePwleV2;
3233
using aidl::android::hardware::vibrator::Effect;
3334
using aidl::android::hardware::vibrator::EffectStrength;
35+
using aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry;
3436
using aidl::android::hardware::vibrator::PrimitivePwle;
35-
using aidl::android::hardware::vibrator::PwleV2OutputMapEntry;
36-
using aidl::android::hardware::vibrator::PwleV2Primitive;
3737
using aidl::android::hardware::vibrator::VendorEffect;
3838

3939
using std::chrono::milliseconds;
@@ -131,8 +131,7 @@ HalResult<void> HalWrapper::performPwleEffect(const std::vector<PrimitivePwle>&,
131131
return HalResult<void>::unsupported();
132132
}
133133

134-
HalResult<void> HalWrapper::composePwleV2(const std::vector<PwleV2Primitive>&,
135-
const std::function<void()>&) {
134+
HalResult<void> HalWrapper::composePwleV2(const CompositePwleV2&, const std::function<void()>&) {
136135
ALOGV("Skipped composePwleV2 because it's not available in Vibrator HAL");
137136
return HalResult<void>::unsupported();
138137
}
@@ -243,11 +242,11 @@ HalResult<milliseconds> HalWrapper::getMaxEnvelopeEffectControlPointDurationInte
243242
return HalResult<milliseconds>::unsupported();
244243
}
245244

246-
HalResult<std::vector<PwleV2OutputMapEntry>>
245+
HalResult<std::vector<FrequencyAccelerationMapEntry>>
247246
HalWrapper::getFrequencyToOutputAccelerationMapInternal() {
248247
ALOGV("Skipped getFrequencyToOutputAccelerationMapInternal because it's not "
249248
"available in Vibrator HAL");
250-
return HalResult<std::vector<PwleV2OutputMapEntry>>::unsupported();
249+
return HalResult<std::vector<FrequencyAccelerationMapEntry>>::unsupported();
251250
}
252251

253252
// -------------------------------------------------------------------------------------------------
@@ -360,7 +359,7 @@ HalResult<void> AidlHalWrapper::performPwleEffect(const std::vector<PrimitivePwl
360359
return HalResultFactory::fromStatus(getHal()->composePwle(primitives, cb));
361360
}
362361

363-
HalResult<void> AidlHalWrapper::composePwleV2(const std::vector<PwleV2Primitive>& composite,
362+
HalResult<void> AidlHalWrapper::composePwleV2(const CompositePwleV2& composite,
364363
const std::function<void()>& completionCallback) {
365364
// This method should always support callbacks, so no need to double check.
366365
auto cb = ndk::SharedRefBase::make<HalCallbackWrapper>(completionCallback);
@@ -498,13 +497,13 @@ HalResult<milliseconds> AidlHalWrapper::getMaxEnvelopeEffectControlPointDuration
498497
return HalResultFactory::fromStatus<milliseconds>(std::move(status), milliseconds(durationMs));
499498
}
500499

501-
HalResult<std::vector<PwleV2OutputMapEntry>>
500+
HalResult<std::vector<FrequencyAccelerationMapEntry>>
502501
AidlHalWrapper::getFrequencyToOutputAccelerationMapInternal() {
503-
std::vector<PwleV2OutputMapEntry> frequencyToOutputAccelerationMap;
504-
auto status =
505-
getHal()->getPwleV2FrequencyToOutputAccelerationMap(&frequencyToOutputAccelerationMap);
502+
std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap;
503+
auto status = getHal()->getFrequencyToOutputAccelerationMap(&frequencyToOutputAccelerationMap);
506504
return HalResultFactory::fromStatus<
507-
std::vector<PwleV2OutputMapEntry>>(std::move(status), frequencyToOutputAccelerationMap);
505+
std::vector<FrequencyAccelerationMapEntry>>(std::move(status),
506+
frequencyToOutputAccelerationMap);
508507
}
509508

510509
std::shared_ptr<Aidl::IVibrator> AidlHalWrapper::getHal() {

services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ class Info {
243243
using EffectStrength = aidl::android::hardware::vibrator::EffectStrength;
244244
using CompositePrimitive = aidl::android::hardware::vibrator::CompositePrimitive;
245245
using Braking = aidl::android::hardware::vibrator::Braking;
246-
using PwleV2OutputMapEntry = aidl::android::hardware::vibrator::PwleV2OutputMapEntry;
246+
using FrequencyAccelerationMapEntry =
247+
aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry;
247248

248249
const HalResult<Capabilities> capabilities;
249250
const HalResult<std::vector<Effect>> supportedEffects;
@@ -262,7 +263,7 @@ class Info {
262263
const HalResult<int32_t> maxEnvelopeEffectSize;
263264
const HalResult<std::chrono::milliseconds> minEnvelopeEffectControlPointDuration;
264265
const HalResult<std::chrono::milliseconds> maxEnvelopeEffectControlPointDuration;
265-
const HalResult<std::vector<PwleV2OutputMapEntry>> frequencyToOutputAccelerationMap;
266+
const HalResult<std::vector<FrequencyAccelerationMapEntry>> frequencyToOutputAccelerationMap;
266267

267268
void logFailures() const {
268269
logFailure<Capabilities>(capabilities, "getCapabilities");
@@ -286,8 +287,9 @@ class Info {
286287
"getMinEnvelopeEffectControlPointDuration");
287288
logFailure<std::chrono::milliseconds>(maxEnvelopeEffectControlPointDuration,
288289
"getMaxEnvelopeEffectControlPointDuration");
289-
logFailure<std::vector<PwleV2OutputMapEntry>>(frequencyToOutputAccelerationMap,
290-
"getfrequencyToOutputAccelerationMap");
290+
logFailure<
291+
std::vector<FrequencyAccelerationMapEntry>>(frequencyToOutputAccelerationMap,
292+
"getfrequencyToOutputAccelerationMap");
291293
}
292294

293295
bool shouldRetry() const {
@@ -365,8 +367,8 @@ class InfoCache {
365367
HalResult<std::chrono::milliseconds>::transactionFailed(MSG);
366368
HalResult<std::chrono::milliseconds> mMaxEnvelopeEffectControlPointDuration =
367369
HalResult<std::chrono::milliseconds>::transactionFailed(MSG);
368-
HalResult<std::vector<Info::PwleV2OutputMapEntry>> mFrequencyToOutputAccelerationMap =
369-
HalResult<std::vector<Info::PwleV2OutputMapEntry>>::transactionFailed(MSG);
370+
HalResult<std::vector<Info::FrequencyAccelerationMapEntry>> mFrequencyToOutputAccelerationMap =
371+
HalResult<std::vector<Info::FrequencyAccelerationMapEntry>>::transactionFailed(MSG);
370372

371373
friend class HalWrapper;
372374
};
@@ -381,8 +383,9 @@ class HalWrapper {
381383
using CompositeEffect = aidl::android::hardware::vibrator::CompositeEffect;
382384
using Braking = aidl::android::hardware::vibrator::Braking;
383385
using PrimitivePwle = aidl::android::hardware::vibrator::PrimitivePwle;
384-
using PwleV2Primitive = aidl::android::hardware::vibrator::PwleV2Primitive;
385-
using PwleV2OutputMapEntry = aidl::android::hardware::vibrator::PwleV2OutputMapEntry;
386+
using CompositePwleV2 = aidl::android::hardware::vibrator::CompositePwleV2;
387+
using FrequencyAccelerationMapEntry =
388+
aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry;
386389

387390
explicit HalWrapper(std::shared_ptr<CallbackScheduler> scheduler)
388391
: mCallbackScheduler(std::move(scheduler)) {}
@@ -420,7 +423,7 @@ class HalWrapper {
420423
virtual HalResult<void> performPwleEffect(const std::vector<PrimitivePwle>& primitives,
421424
const std::function<void()>& completionCallback);
422425

423-
virtual HalResult<void> composePwleV2(const std::vector<PwleV2Primitive>& composite,
426+
virtual HalResult<void> composePwleV2(const CompositePwleV2& composite,
424427
const std::function<void()>& completionCallback);
425428

426429
protected:
@@ -450,7 +453,7 @@ class HalWrapper {
450453
virtual HalResult<int32_t> getMaxEnvelopeEffectSizeInternal();
451454
virtual HalResult<std::chrono::milliseconds> getMinEnvelopeEffectControlPointDurationInternal();
452455
virtual HalResult<std::chrono::milliseconds> getMaxEnvelopeEffectControlPointDurationInternal();
453-
virtual HalResult<std::vector<PwleV2OutputMapEntry>>
456+
virtual HalResult<std::vector<FrequencyAccelerationMapEntry>>
454457
getFrequencyToOutputAccelerationMapInternal();
455458

456459
private:
@@ -508,7 +511,7 @@ class AidlHalWrapper : public HalWrapper {
508511
const std::vector<PrimitivePwle>& primitives,
509512
const std::function<void()>& completionCallback) override final;
510513

511-
HalResult<void> composePwleV2(const std::vector<PwleV2Primitive>& composite,
514+
HalResult<void> composePwleV2(const CompositePwleV2& composite,
512515
const std::function<void()>& completionCallback) override final;
513516

514517
protected:
@@ -532,8 +535,9 @@ class AidlHalWrapper : public HalWrapper {
532535
override final;
533536
HalResult<std::chrono::milliseconds> getMaxEnvelopeEffectControlPointDurationInternal()
534537
override final;
535-
HalResult<std::vector<PwleV2OutputMapEntry>> getFrequencyToOutputAccelerationMapInternal()
536-
override final;
538+
539+
HalResult<std::vector<FrequencyAccelerationMapEntry>>
540+
getFrequencyToOutputAccelerationMapInternal() override final;
537541

538542
private:
539543
const reconnect_fn mReconnectFn;

services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
using aidl::android::hardware::vibrator::Braking;
3535
using aidl::android::hardware::vibrator::CompositeEffect;
3636
using aidl::android::hardware::vibrator::CompositePrimitive;
37+
using aidl::android::hardware::vibrator::CompositePwleV2;
3738
using aidl::android::hardware::vibrator::Effect;
3839
using aidl::android::hardware::vibrator::EffectStrength;
40+
using aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry;
3941
using aidl::android::hardware::vibrator::IVibrator;
4042
using aidl::android::hardware::vibrator::IVibratorCallback;
4143
using aidl::android::hardware::vibrator::PrimitivePwle;
42-
using aidl::android::hardware::vibrator::PwleV2OutputMapEntry;
4344
using aidl::android::hardware::vibrator::PwleV2Primitive;
4445
using aidl::android::hardware::vibrator::VendorEffect;
4546
using aidl::android::os::PersistableBundle;
@@ -243,11 +244,11 @@ TEST_F(VibratorHalWrapperAidlTest, TestGetInfoDoesNotCacheFailedResult) {
243244
std::vector<CompositePrimitive> supportedPrimitives = {CompositePrimitive::CLICK};
244245
std::vector<Braking> supportedBraking = {Braking::CLAB};
245246
std::vector<float> amplitudes = {0.f, 1.f, 0.f};
246-
std::vector<PwleV2OutputMapEntry>
247-
frequencyToOutputAccelerationMap{PwleV2OutputMapEntry(/*frequency=*/30.0f,
248-
/*maxOutputAcceleration=*/0.2),
249-
PwleV2OutputMapEntry(/*frequency=*/60.0f,
250-
/*maxOutputAcceleration=*/0.8)};
247+
std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap{
248+
FrequencyAccelerationMapEntry(/*frequency=*/30.0f,
249+
/*maxOutputAcceleration=*/0.2),
250+
FrequencyAccelerationMapEntry(/*frequency=*/60.0f,
251+
/*maxOutputAcceleration=*/0.8)};
251252

252253
std::vector<std::chrono::milliseconds> primitiveDurations;
253254
constexpr auto primitiveRange = ndk::enum_range<CompositePrimitive>();
@@ -329,7 +330,7 @@ TEST_F(VibratorHalWrapperAidlTest, TestGetInfoDoesNotCacheFailedResult) {
329330
.WillOnce(Return(ndk::ScopedAStatus::fromExceptionCode(EX_SECURITY)))
330331
.WillOnce(DoAll(SetArgPointee<0>(PWLE_V2_MIN_REQUIRED_PRIMITIVE_MAX_DURATION_MS),
331332
Return(ndk::ScopedAStatus::ok())));
332-
EXPECT_CALL(*mMockHal.get(), getPwleV2FrequencyToOutputAccelerationMap(_))
333+
EXPECT_CALL(*mMockHal.get(), getFrequencyToOutputAccelerationMap(_))
333334
.Times(Exactly(2))
334335
.WillOnce(Return(ndk::ScopedAStatus::fromExceptionCode(EX_SECURITY)))
335336
.WillOnce(DoAll(SetArgPointee<0>(frequencyToOutputAccelerationMap),
@@ -391,11 +392,11 @@ TEST_F(VibratorHalWrapperAidlTest, TestGetInfoCachesResult) {
391392
constexpr int32_t PWLE_V2_MAX_ALLOWED_PRIMITIVE_MIN_DURATION_MS = 20;
392393
constexpr int32_t PWLE_V2_MIN_REQUIRED_PRIMITIVE_MAX_DURATION_MS = 1000;
393394
std::vector<Effect> supportedEffects = {Effect::CLICK, Effect::TICK};
394-
std::vector<PwleV2OutputMapEntry>
395-
frequencyToOutputAccelerationMap{PwleV2OutputMapEntry(/*frequency=*/30.0f,
396-
/*maxOutputAcceleration=*/0.2),
397-
PwleV2OutputMapEntry(/*frequency=*/60.0f,
398-
/*maxOutputAcceleration=*/0.8)};
395+
std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap{
396+
FrequencyAccelerationMapEntry(/*frequency=*/30.0f,
397+
/*maxOutputAcceleration=*/0.2),
398+
FrequencyAccelerationMapEntry(/*frequency=*/60.0f,
399+
/*maxOutputAcceleration=*/0.8)};
399400

400401
EXPECT_CALL(*mMockHal.get(), getCapabilities(_))
401402
.Times(Exactly(1))
@@ -451,7 +452,7 @@ TEST_F(VibratorHalWrapperAidlTest, TestGetInfoCachesResult) {
451452
.Times(Exactly(1))
452453
.WillOnce(DoAll(SetArgPointee<0>(PWLE_V2_MIN_REQUIRED_PRIMITIVE_MAX_DURATION_MS),
453454
Return(ndk::ScopedAStatus::ok())));
454-
EXPECT_CALL(*mMockHal.get(), getPwleV2FrequencyToOutputAccelerationMap(_))
455+
EXPECT_CALL(*mMockHal.get(), getFrequencyToOutputAccelerationMap(_))
455456
.Times(Exactly(1))
456457
.WillOnce(DoAll(SetArgPointee<0>(frequencyToOutputAccelerationMap),
457458
Return(ndk::ScopedAStatus::ok())));
@@ -754,7 +755,8 @@ TEST_F(VibratorHalWrapperAidlTest, TestPerformPwleEffect) {
754755
}
755756

756757
TEST_F(VibratorHalWrapperAidlTest, TestComposePwleV2) {
757-
auto pwleEffect = {
758+
CompositePwleV2 composite;
759+
composite.pwlePrimitives = {
758760
PwleV2Primitive(/*amplitude=*/0.2, /*frequency=*/50, /*time=*/100),
759761
PwleV2Primitive(/*amplitude=*/0.5, /*frequency=*/150, /*time=*/100),
760762
PwleV2Primitive(/*amplitude=*/0.8, /*frequency=*/250, /*time=*/100),
@@ -773,17 +775,17 @@ TEST_F(VibratorHalWrapperAidlTest, TestComposePwleV2) {
773775
std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
774776
auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
775777

776-
auto result = mWrapper->composePwleV2(pwleEffect, callback);
778+
auto result = mWrapper->composePwleV2(composite, callback);
777779
ASSERT_TRUE(result.isUnsupported());
778780
// Callback not triggered on failure
779781
ASSERT_EQ(0, *callbackCounter.get());
780782

781-
result = mWrapper->composePwleV2(pwleEffect, callback);
783+
result = mWrapper->composePwleV2(composite, callback);
782784
ASSERT_TRUE(result.isFailed());
783785
// Callback not triggered for unsupported
784786
ASSERT_EQ(0, *callbackCounter.get());
785787

786-
result = mWrapper->composePwleV2(pwleEffect, callback);
788+
result = mWrapper->composePwleV2(composite, callback);
787789
ASSERT_TRUE(result.isOk());
788790
ASSERT_EQ(1, *callbackCounter.get());
789791
}

services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace V1_0 = android::hardware::vibrator::V1_0;
3636
using aidl::android::hardware::vibrator::Braking;
3737
using aidl::android::hardware::vibrator::CompositeEffect;
3838
using aidl::android::hardware::vibrator::CompositePrimitive;
39+
using aidl::android::hardware::vibrator::CompositePwleV2;
3940
using aidl::android::hardware::vibrator::Effect;
4041
using aidl::android::hardware::vibrator::EffectStrength;
4142
using aidl::android::hardware::vibrator::IVibrator;
@@ -380,7 +381,8 @@ TEST_F(VibratorHalWrapperHidlV1_0Test, TestPerformPwleEffectUnsupported) {
380381
}
381382

382383
TEST_F(VibratorHalWrapperHidlV1_0Test, TestComposePwleV2Unsupported) {
383-
auto pwleEffect = {
384+
CompositePwleV2 composite;
385+
composite.pwlePrimitives = {
384386
PwleV2Primitive(/*amplitude=*/0.2, /*frequency=*/50, /*time=*/100),
385387
PwleV2Primitive(/*amplitude=*/0.5, /*frequency=*/150, /*time=*/100),
386388
PwleV2Primitive(/*amplitude=*/0.8, /*frequency=*/250, /*time=*/100),
@@ -389,7 +391,7 @@ TEST_F(VibratorHalWrapperHidlV1_0Test, TestComposePwleV2Unsupported) {
389391
std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
390392
auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
391393

392-
ASSERT_TRUE(mWrapper->composePwleV2(pwleEffect, callback).isUnsupported());
394+
ASSERT_TRUE(mWrapper->composePwleV2(composite, callback).isUnsupported());
393395

394396
// No callback is triggered.
395397
ASSERT_EQ(0, *callbackCounter.get());

services/vibratorservice/test/test_mocks.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ using namespace testing;
3636
using aidl::android::hardware::vibrator::Braking;
3737
using aidl::android::hardware::vibrator::CompositeEffect;
3838
using aidl::android::hardware::vibrator::CompositePrimitive;
39+
using aidl::android::hardware::vibrator::CompositePwleV2;
3940
using aidl::android::hardware::vibrator::Effect;
4041
using aidl::android::hardware::vibrator::EffectStrength;
42+
using aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry;
4143
using aidl::android::hardware::vibrator::IVibrator;
4244
using aidl::android::hardware::vibrator::IVibratorCallback;
4345
using aidl::android::hardware::vibrator::PrimitivePwle;
44-
using aidl::android::hardware::vibrator::PwleV2OutputMapEntry;
45-
using aidl::android::hardware::vibrator::PwleV2Primitive;
4646
using aidl::android::hardware::vibrator::VendorEffect;
4747

4848
// -------------------------------------------------------------------------------------------------
@@ -91,16 +91,15 @@ class MockIVibrator : public IVibrator {
9191
MOCK_METHOD(ndk::ScopedAStatus, getPwlePrimitiveDurationMax, (int32_t * ret), (override));
9292
MOCK_METHOD(ndk::ScopedAStatus, getPwleCompositionSizeMax, (int32_t * ret), (override));
9393
MOCK_METHOD(ndk::ScopedAStatus, getSupportedBraking, (std::vector<Braking> * ret), (override));
94-
MOCK_METHOD(ndk::ScopedAStatus, getPwleV2FrequencyToOutputAccelerationMap,
95-
(std::vector<PwleV2OutputMapEntry> * ret), (override));
94+
MOCK_METHOD(ndk::ScopedAStatus, getFrequencyToOutputAccelerationMap,
95+
(std::vector<FrequencyAccelerationMapEntry> * ret), (override));
9696
MOCK_METHOD(ndk::ScopedAStatus, getPwleV2PrimitiveDurationMaxMillis, (int32_t* ret),
9797
(override));
9898
MOCK_METHOD(ndk::ScopedAStatus, getPwleV2PrimitiveDurationMinMillis, (int32_t* ret),
9999
(override));
100100
MOCK_METHOD(ndk::ScopedAStatus, getPwleV2CompositionSizeMax, (int32_t* ret), (override));
101101
MOCK_METHOD(ndk::ScopedAStatus, composePwleV2,
102-
(const std::vector<PwleV2Primitive>& e,
103-
const std::shared_ptr<IVibratorCallback>& cb),
102+
(const CompositePwleV2& e, const std::shared_ptr<IVibratorCallback>& cb),
104103
(override));
105104
MOCK_METHOD(ndk::ScopedAStatus, getInterfaceVersion, (int32_t*), (override));
106105
MOCK_METHOD(ndk::ScopedAStatus, getInterfaceHash, (std::string*), (override));

0 commit comments

Comments
 (0)