Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c9b7811 authored by Daniel Jacob Chittoor's avatar Daniel Jacob Chittoor
Browse files

2e: InCallService: Backport to Android 10

The getCommunicationDevice() was exposed post-Android 10. So, retrieve
the device outputs via the getDevices() API and then find the earpiece
output device.

Test: check if volume gains work in-call while on earpiece device
parent f182674d
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -21,12 +21,21 @@ public class VolumeChangeReceiver extends BroadcastReceiver {

    private void handleVolumeStateChange(Intent intent) {
        if (intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1) == AudioManager.STREAM_VOICE_CALL) {
            AudioDeviceInfo callDevice = mAudioManager.getCommunicationDevice();
            if (callDevice.getType() != AudioDeviceInfo.TYPE_BUILTIN_EARPIECE) {

            if (!mAudioManager.isSpeakerphoneOn() && !mAudioManager.isBluetoothScoOn()) {
                // Device is not the built in earpiece, we don't need to do anything.
                return;
            }

            AudioDeviceInfo[] allDevices = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
            AudioDeviceInfo callDevice = null;
            for (AudioDeviceInfo device: allDevices) {
              if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE) {
                  callDevice = device;
                  break;
	      }
	    }

            // Try to get volumeIndex
            int volumeIndex = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, -1);
            if (volumeIndex < 0) {