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

Commit e94f297b authored by Vlad Popa's avatar Vlad Popa
Browse files

HA on voice call have the same range as SCO and LEA

Test: manual
Bug: 416418971
Flag: com.android.media.audio.equal_sco_ha_vc_index_range
Change-Id: I906a32c366df112f9fa441162c9260544f6b01a8
parent 35664fa3
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -34,10 +34,12 @@ import static android.media.AudioSystem.DEVICE_OUT_USB_HEADSET;
import static android.media.AudioSystem.DEVICE_OUT_WIRED_HEADSET;
import static android.media.AudioSystem.isBluetoothScoOutDevice;

import static com.android.media.audio.Flags.equalScoHaVcIndexRange;
import static com.android.media.audio.Flags.equalScoLeaVcIndexRange;
import static com.android.media.audio.Flags.optimizeBtDeviceSwitch;
import static com.android.server.audio.AudioService.BT_COMM_DEVICE_ACTIVE_BLE_HEADSET;
import static com.android.server.audio.AudioService.BT_COMM_DEVICE_ACTIVE_BLE_SPEAKER;
import static com.android.server.audio.AudioService.BT_COMM_DEVICE_ACTIVE_HA;
import static com.android.server.audio.AudioService.BT_COMM_DEVICE_ACTIVE_SCO;
import static com.android.server.utils.EventLogger.Event.ALOGW;

@@ -923,6 +925,10 @@ public class AudioDeviceBroker {
        return isDeviceActiveForCommunication(AudioDeviceInfo.TYPE_BLE_SPEAKER);
    }

    private boolean isBluetoothHaActive() {
        return isDeviceActiveForCommunication(AudioDeviceInfo.TYPE_HEARING_AID);
    }

    /*package*/ boolean isDeviceConnected(@NonNull AudioDeviceAttributes device) {
        synchronized (mDeviceStateLock) {
            return mDeviceInventory.isDeviceConnected(device);
@@ -1505,13 +1511,15 @@ public class AudioDeviceBroker {
        mCurCommunicationPortId = portId;

        @BtCommDeviceActiveType int btCommDeviceActiveType = 0;
        if (equalScoLeaVcIndexRange()) {
        if (equalScoLeaVcIndexRange() || equalScoHaVcIndexRange()) {
            if (isBluetoothScoActive()) {
                btCommDeviceActiveType = BT_COMM_DEVICE_ACTIVE_SCO;
            } else if (isBluetoothBleHeadsetActive()) {
                btCommDeviceActiveType = BT_COMM_DEVICE_ACTIVE_BLE_HEADSET;
            } else if (isBluetoothBleSpeakerActive()) {
                btCommDeviceActiveType = BT_COMM_DEVICE_ACTIVE_BLE_SPEAKER;
            } else if (equalScoHaVcIndexRange() && isBluetoothHaActive()) {
                btCommDeviceActiveType = BT_COMM_DEVICE_ACTIVE_HA;
            }
            mAudioService.postBtCommDeviceActive(btCommDeviceActiveType);
        } else {
+15 −4
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import static com.android.media.audio.Flags.asDeviceConnectionFailure;
import static com.android.media.audio.Flags.audioserverPermissions;
import static com.android.media.audio.Flags.deferWearPermissionUpdates;
import static com.android.media.audio.Flags.disablePrescaleAbsoluteVolume;
import static com.android.media.audio.Flags.equalScoHaVcIndexRange;
import static com.android.media.audio.Flags.equalScoLeaVcIndexRange;
import static com.android.media.audio.Flags.optimizeBtDeviceSwitch;
import static com.android.media.audio.Flags.replaceStreamBtSco;
@@ -826,9 +827,11 @@ public class AudioService extends IAudioService.Stub
    /*package*/ static final int BT_COMM_DEVICE_ACTIVE_BLE_HEADSET = 1 << 1;
    /** The active bluetooth device type used for communication is ble speaker. */
    /*package*/ static final int BT_COMM_DEVICE_ACTIVE_BLE_SPEAKER = 1 << 2;
    /** The active bluetooth device type used for communication is hearing aid. */
    /*package*/ static final int BT_COMM_DEVICE_ACTIVE_HA = 1 << 3;
    @IntDef({
            BT_COMM_DEVICE_ACTIVE_SCO, BT_COMM_DEVICE_ACTIVE_BLE_HEADSET,
            BT_COMM_DEVICE_ACTIVE_BLE_SPEAKER
            BT_COMM_DEVICE_ACTIVE_BLE_SPEAKER, BT_COMM_DEVICE_ACTIVE_HA
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface BtCommDeviceActiveType {
@@ -5277,6 +5280,8 @@ public class AudioService extends IAudioService.Stub
        pw.println("\tcom.android.media.audio.vgsVssSyncMuteOrder - EOL");
        pw.println("\tcom.android.media.audio.replaceStreamBtSco:"
                + replaceStreamBtSco());
        pw.println("\tcom.android.media.audio.equalScoHaVcIndexRange:"
                + equalScoHaVcIndexRange());
        pw.println("\tcom.android.media.audio.equalScoLeaVcIndexRange:"
                + equalScoLeaVcIndexRange());
        pw.println("\tcom.android.media.audio.ringMyCar:"
@@ -9753,7 +9758,7 @@ public class AudioService extends IAudioService.Stub
        }
        public void updateIndexFactors() {
            if (!replaceStreamBtSco() && !equalScoLeaVcIndexRange()) {
            if (!replaceStreamBtSco() && !equalScoLeaVcIndexRange() && !equalScoHaVcIndexRange()) {
                return;
            }
@@ -9767,18 +9772,24 @@ public class AudioService extends IAudioService.Stub
                        mIndexMax = MAX_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO] * 10;
                    }
                    if (!equalScoLeaVcIndexRange() && isStreamBluetoothSco(mStreamType)) {
                    if (!equalScoLeaVcIndexRange() && !equalScoHaVcIndexRange()
                            && isStreamBluetoothSco(mStreamType)) {
                        // SCO devices have a different min index
                        mIndexMin = MIN_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO] * 10;
                        indexMinVolCurve = MIN_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO];
                        indexMaxVolCurve = MAX_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO];
                        mIndexStepFactor = 1.f;
                    } else if (equalScoLeaVcIndexRange() && isStreamBluetoothComm(mStreamType)) {
                    } else if ((equalScoLeaVcIndexRange() || equalScoHaVcIndexRange())
                            && isStreamBluetoothComm(mStreamType)) {
                        // For non SCO devices the stream state does not change the min index
                        if (mBtCommDeviceActive.get() == BT_COMM_DEVICE_ACTIVE_SCO) {
                            mIndexMin = MIN_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO] * 10;
                            indexMinVolCurve = MIN_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO];
                            indexMaxVolCurve = MAX_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO];
                        } else if (equalScoHaVcIndexRange()
                                && mBtCommDeviceActive.get() == BT_COMM_DEVICE_ACTIVE_HA) {
                            mIndexMin = MIN_STREAM_VOLUME[mStreamType] * 10;
                            indexMaxVolCurve = MAX_STREAM_VOLUME[AudioSystem.STREAM_BLUETOOTH_SCO];
                        } else {
                            mIndexMin = MIN_STREAM_VOLUME[mStreamType] * 10;
                        }