Force selecting haptic supported thread when creating HapticGenerator.
HapticGenerator is the haptic-generating effect, which will generate
haptic data based on audio data. As haptic data will be truncated on
non-haptic supported thread, HapticGenerator makes sense only on haptic
supported thread. In that case, force selecting haptic supported thread
when creating HapticGenerator. If there is no thread supporting haptics
channel, return a failure.
Bug: 136490803
Test: make, manually
Change-Id: I865d211c613c793d75d23f5d10c9a01d294fdc36
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index d366bb7..c92bce5 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -595,7 +595,10 @@
+ "_" + std::to_string(mId) + "_T");
#endif
- if (channelMask & AUDIO_CHANNEL_HAPTIC_ALL) {
+ if (thread->supportsHapticPlayback()) {
+ // If the track is attached to haptic playback thread, it is potentially to have
+ // HapticGenerator effect, which will generate haptic data, on the track. In that case,
+ // external vibration is always created for all tracks attached to haptic playback thread.
mAudioVibrationController = new AudioVibrationController(this);
mExternalVibration = new os::ExternalVibration(
mUid, "" /* pkg */, mAttr, mAudioVibrationController);