Merge "vibrator: Support Always-On Effects" am: fe4644ddff am: e2b355aa4c

Change-Id: I315d6dd1df1701a26e20763c841419cca56aa79f
This commit is contained in:
Automerger Merge Worker 2019-12-14 00:26:49 +00:00
commit 912bb28e93
4 changed files with 84 additions and 1 deletions

View file

@ -48,6 +48,10 @@ interface IVibrator {
* Whether compose is supported.
*/
const int CAP_COMPOSE_EFFECTS = 1 << 5;
/**
* Whether alwaysOnEnable/alwaysOnDisable is supported.
*/
const int CAP_ALWAYS_ON_CONTROL = 1 << 6;
/**
* Determine capabilities of the vibrator HAL (CAP_* mask)
@ -165,4 +169,31 @@ interface IVibrator {
*/
void compose(in CompositeEffect[] composite, in IVibratorCallback callback);
/**
* List of supported always-on effects.
*
* Return the effects which are supported by the alwaysOnEnable (an effect
* is expected to be supported at every strength level.
*/
Effect[] getSupportedAlwaysOnEffects();
/**
* Enable an always-on haptic source, assigning a specific effect. An
* always-on haptic source is a source that can be triggered externally
* once enabled and assigned an effect to play. This may not be supported
* and this support is reflected in getCapabilities (CAP_ALWAYS_ON_CONTROL).
*
* @param id The device-specific always-on source ID to enable.
* @param effect The type of haptic event to trigger.
* @param strength The intensity of haptic event to trigger.
*/
void alwaysOnEnable(in int id, in Effect effect, in EffectStrength strength);
/**
* Disable an always-on haptic source. This may not be supported and this
* support is reflected in getCapabilities (CAP_ALWAYS_ON_CONTROL).
*
* @param id The device-specific always-on source ID to disable.
*/
void alwaysOnDisable(in int id);
}

View file

@ -31,7 +31,8 @@ ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) {
LOG(INFO) << "Vibrator reporting capabilities";
*_aidl_return = IVibrator::CAP_ON_CALLBACK | IVibrator::CAP_PERFORM_CALLBACK |
IVibrator::CAP_AMPLITUDE_CONTROL | IVibrator::CAP_EXTERNAL_CONTROL |
IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL | IVibrator::CAP_COMPOSE_EFFECTS;
IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL | IVibrator::CAP_COMPOSE_EFFECTS |
IVibrator::CAP_ALWAYS_ON_CONTROL;
return ndk::ScopedAStatus::ok();
}
@ -151,6 +152,28 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composi
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Vibrator::getSupportedAlwaysOnEffects(std::vector<Effect>* _aidl_return) {
return getSupportedEffects(_aidl_return);
}
ndk::ScopedAStatus Vibrator::alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) {
std::vector<Effect> effects;
getSupportedAlwaysOnEffects(&effects);
if (std::find(effects.begin(), effects.end(), effect) == effects.end()) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
} else {
LOG(INFO) << "Enabling always-on ID " << id << " with " << toString(effect) << "/"
<< toString(strength);
return ndk::ScopedAStatus::ok();
}
}
ndk::ScopedAStatus Vibrator::alwaysOnDisable(int32_t id) {
LOG(INFO) << "Disabling always-on ID " << id;
return ndk::ScopedAStatus::ok();
}
} // namespace vibrator
} // namespace hardware
} // namespace android

View file

@ -38,6 +38,9 @@ class Vibrator : public BnVibrator {
ndk::ScopedAStatus getCompositionSizeMax(int32_t* maxSize);
ndk::ScopedAStatus compose(const std::vector<CompositeEffect>& composite,
const std::shared_ptr<IVibratorCallback>& callback) override;
ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector<Effect>* _aidl_return) override;
ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) override;
ndk::ScopedAStatus alwaysOnDisable(int32_t id) override;
};
} // namespace vibrator

View file

@ -370,6 +370,32 @@ TEST_P(VibratorAidl, CompseSizeBoundary) {
}
}
TEST_P(VibratorAidl, AlwaysOn) {
if (capabilities & IVibrator::CAP_ALWAYS_ON_CONTROL) {
std::vector<Effect> supported;
ASSERT_TRUE(vibrator->getSupportedAlwaysOnEffects(&supported).isOk());
for (Effect effect : kEffects) {
bool isEffectSupported =
std::find(supported.begin(), supported.end(), effect) != supported.end();
for (EffectStrength strength : kEffectStrengths) {
Status status = vibrator->alwaysOnEnable(0, effect, strength);
if (isEffectSupported) {
EXPECT_EQ(Status::EX_NONE, status.exceptionCode())
<< toString(effect) << " " << toString(strength);
} else {
EXPECT_EQ(Status::EX_UNSUPPORTED_OPERATION, status.exceptionCode())
<< toString(effect) << " " << toString(strength);
}
}
}
EXPECT_EQ(Status::EX_NONE, vibrator->alwaysOnDisable(0).exceptionCode());
}
}
INSTANTIATE_TEST_SUITE_P(Vibrator, VibratorAidl,
testing::ValuesIn(android::getAidlHalInstanceNames(IVibrator::descriptor)),
android::PrintInstanceNameToString);