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

Commit e95e1778 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "AudioService: fix call volume switching from speaker to hearing aid" into qt-dev

parents eddef669 0cf98c7a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -723,7 +723,8 @@ import com.android.internal.annotations.GuardedBy;
                case MSG_IL_SET_HEARING_AID_CONNECTION_STATE:
                    synchronized (mDeviceStateLock) {
                        mDeviceInventory.onSetHearingAidConnectionState(
                                (BluetoothDevice) msg.obj, msg.arg1);
                                (BluetoothDevice) msg.obj, msg.arg1,
                                mAudioService.getHearingAidStreamType());
                    }
                    break;
                case MSG_BT_HEADSET_CNCT_FAILED:
+7 −6
Original line number Diff line number Diff line
@@ -236,7 +236,7 @@ public final class AudioDeviceInventory {
    }

    /*package*/ void onSetHearingAidConnectionState(BluetoothDevice btDevice,
                @AudioService.BtProfileConnectionState int state) {
                @AudioService.BtProfileConnectionState int state, int streamType) {
        String address = btDevice.getAddress();
        if (!BluetoothAdapter.checkBluetoothAddress(address)) {
            address = "";
@@ -253,7 +253,7 @@ public final class AudioDeviceInventory {
            if (isConnected && state != BluetoothProfile.STATE_CONNECTED) {
                makeHearingAidDeviceUnavailable(address);
            } else if (!isConnected && state == BluetoothProfile.STATE_CONNECTED) {
                makeHearingAidDeviceAvailable(address, BtHelper.getName(btDevice),
                makeHearingAidDeviceAvailable(address, BtHelper.getName(btDevice), streamType,
                        "onSetHearingAidConnectionState");
            }
        }
@@ -719,10 +719,11 @@ public final class AudioDeviceInventory {
    }

    @GuardedBy("mConnectedDevices")
    private void makeHearingAidDeviceAvailable(String address, String name, String eventSource) {
        final int hearingAidVolIndex = mDeviceBroker.getVssVolumeForDevice(AudioSystem.STREAM_MUSIC,
    private void makeHearingAidDeviceAvailable(
            String address, String name, int streamType, String eventSource) {
        final int hearingAidVolIndex = mDeviceBroker.getVssVolumeForDevice(streamType,
                AudioSystem.DEVICE_OUT_HEARING_AID);
        mDeviceBroker.postSetHearingAidVolumeIndex(hearingAidVolIndex, AudioSystem.STREAM_MUSIC);
        mDeviceBroker.postSetHearingAidVolumeIndex(hearingAidVolIndex, streamType);

        AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_HEARING_AID,
                AudioSystem.DEVICE_STATE_AVAILABLE, address, name,
@@ -732,7 +733,7 @@ public final class AudioDeviceInventory {
                new DeviceInfo(AudioSystem.DEVICE_OUT_HEARING_AID, name,
                        address, AudioSystem.AUDIO_FORMAT_DEFAULT));
        mDeviceBroker.postAccessoryPlugMediaUnmute(AudioSystem.DEVICE_OUT_HEARING_AID);
        mDeviceBroker.postApplyVolumeOnDevice(AudioSystem.STREAM_MUSIC,
        mDeviceBroker.postApplyVolumeOnDevice(streamType,
                AudioSystem.DEVICE_OUT_HEARING_AID, "makeHearingAidDeviceAvailable");
        setCurrentAudioRouteNameIfPossible(name);
    }
+19 −4
Original line number Diff line number Diff line
@@ -2078,6 +2078,22 @@ public class AudioService extends IAudioService.Stub
        }
    }

    /*package*/ int getHearingAidStreamType() {
        return getHearingAidStreamType(mMode);
    }

    private int getHearingAidStreamType(int mode) {
        switch (mode) {
            case AudioSystem.MODE_IN_COMMUNICATION:
            case AudioSystem.MODE_IN_CALL:
                return AudioSystem.STREAM_VOICE_CALL;
            case AudioSystem.MODE_NORMAL:
            default:
                break;
        }
        return AudioSystem.STREAM_MUSIC;
    }

    /**
     * Manage an audio mode change for audio devices that use an "absolute volume" model,
     * i.e. the framework sends the full scale signal, and the actual volume for the use case
@@ -2087,14 +2103,10 @@ public class AudioService extends IAudioService.Stub
        if (oldMode == newMode) {
            return;
        }
        int streamType = AudioSystem.STREAM_MUSIC;
        switch (newMode) {
            case AudioSystem.MODE_IN_COMMUNICATION:
            case AudioSystem.MODE_IN_CALL:
                streamType = AudioSystem.STREAM_VOICE_CALL;
                break;
            case AudioSystem.MODE_NORMAL:
                streamType = AudioSystem.STREAM_MUSIC;
                break;
            case AudioSystem.MODE_RINGTONE:
                // not changing anything for ringtone
@@ -2105,6 +2117,9 @@ public class AudioService extends IAudioService.Stub
                // don't know what to do in this case, better bail
                return;
        }

        int streamType = getHearingAidStreamType(newMode);

        final int device = AudioSystem.getDevicesForStream(streamType);
        if ((device & mAbsVolumeMultiModeCaseDevices) == 0) {
            return;