80

I have an android device acting as a hands free client device using hfp.

Using the following code:

I am able to receive a call and the speakers and mic are working as expected.

My problem is that I can't seem to control the volume.

I tried using the following lines of code to find the correct stream, but none of them seem to work.

I tracked the volume command being sent from the phone to the client in the class HeadsetClientStateMachine , line #1822 in the following link: HeadsetClientStateMachine from lolipop

case EVENT_TYPE_VOLUME_CHANGED:
    if (event.valueInt == HeadsetClientHalConstants.VOLUME_TYPE_SPK) {
        mAudioManager.setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO, event.valueInt2, AudioManager.FLAG_SHOW_UI);
        mVgsFromStack = true;
       Log.d(TAG, "EventVolumeChange STREAM_BLUETOOTH_SCO value: " + event.valueInt2);
    }

When I change the volume on the phone, I do see the log showing the updated value of the sound, which means that the setStreamVolume() method is being called, but the volume doesn't change.

Does anyone know what could be causing this issue?

EDIT:

I am still looking for an answer and am now looking toward the audio HAL implementation. I suspect that the link between the HAL and the audio driver is somehow incorrect... I don't know much about low level implementation and am not sure what I should be looking for.

bwegs
  • 3,711
  • 2
  • 27
  • 31
Distwo
  • 10,755
  • 7
  • 38
  • 60
  • 1
    I forgot to mention: The HFPClient classes are not present in Kitkat: https://android.googlesource.com/platform/frameworks/base/+/kitkat-release/core/java/android/bluetooth/ they were back ported from lollipop, thus the code I use is the same as the lollipop implementation. – Distwo Sep 08 '15 at 16:36
  • 1
    It could be, I m investigating in that direction right now. In parallel I was wondering if there was a known behavior of android with HFP client profile that prevents it from controlling the volume. – Distwo Sep 08 '15 at 16:40
  • 1
    The odd part is the sound works, the bluetooth volume change event is being passed, and the setStreamVolume() method is being called the way it should be. It just can't seem to adjust the volume... – Distwo Sep 08 '15 at 16:47
  • I've tested on different hardware, but all with the same architecture as it's the only one that my custom rom supports... – Distwo Sep 08 '15 at 17:06
  • I wonder if this has anything related to the problem: https://android.googlesource.com/platform/hardware/libhardware/+/73b8a7414afa5ee3f006468f287695d9c2054d76 – Distwo Sep 08 '15 at 21:58
  • if it is playing a , did you tried the specific stream like `STREAM_MUSIC`?music. – Jiang YD Jan 19 '16 at 10:43
  • In my experience, on some devices bluetooth headset volume can be changed only using headset controls. I'm in posession of one such android phone actually. – weaknespase Mar 20 '16 at 13:46
  • @VallyN this is called absolute volume control and is part of AVRCP profile. It's unfortunately not the case in my problem. – Distwo Mar 21 '16 at 16:17
  • It should be audiomanager issue; can you paste some logs? – Guo Xingmin Jul 25 '16 at 08:55

1 Answers1

3

Could you please try below. I did not try myself but sounds similar problem if I understand correctly:

Android Bluetooth Earpiece Volume

"Android is using int 6 for bluetooth volume and not documented. Just use 6 instead of AudioManager.STREAM_VOICE_CALL and try, It should work"

I assume for you will be to replace AudioManager.STREAM_BLUETOOTH_SCO with 6.

Good luck, I hope it will work.

Community
  • 1
  • 1
Adi
  • 29
  • 4