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

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

Merge "AudioDeviceInventory: fix Bluetooth device config change for LE Audio" into main

parents 0a400b05 37cd8b50
Loading
Loading
Loading
Loading
+6 −34
Original line number Diff line number Diff line
@@ -1030,38 +1030,10 @@ public class AudioDeviceBroker {
        }
    }

    BtDeviceInfo createBtDeviceInfo(@NonNull BtDeviceChangedData d, @NonNull BluetoothDevice device,
                int state) {
        int audioDevice;
        int codec = AudioSystem.AUDIO_FORMAT_DEFAULT;
        switch (d.mInfo.getProfile()) {
            case BluetoothProfile.A2DP_SINK:
                audioDevice = AudioSystem.DEVICE_IN_BLUETOOTH_A2DP;
                break;
            case BluetoothProfile.A2DP:
                audioDevice = AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP;
                break;
            case BluetoothProfile.HEARING_AID:
                audioDevice = AudioSystem.DEVICE_OUT_HEARING_AID;
                break;
            case BluetoothProfile.LE_AUDIO:
                if (d.mInfo.isLeOutput()) {
                    audioDevice = AudioSystem.DEVICE_OUT_BLE_HEADSET;
                } else {
                    audioDevice = AudioSystem.DEVICE_IN_BLE_HEADSET;
                }
                break;
            case BluetoothProfile.LE_AUDIO_BROADCAST:
                audioDevice = AudioSystem.DEVICE_OUT_BLE_BROADCAST;
                break;
            case BluetoothProfile.HEADSET:
                // the actual device type is not important at this point and
                // will be set by BtHelper.handleBtScoActiveDeviceChange()
                audioDevice = AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
                break;
            default: throw new IllegalArgumentException("Invalid profile " + d.mInfo.getProfile());
        }
        return new BtDeviceInfo(d, device, state, audioDevice, codec);
    /*package*/ static BtDeviceInfo createBtDeviceInfo(@NonNull BtDeviceChangedData d,
            @NonNull BluetoothDevice device, int state) {
        int audioDevice = BtHelper.getTypeFromProfile(d.mInfo.getProfile(), d.mInfo.isLeOutput());
        return new BtDeviceInfo(d, device, state, audioDevice, AudioSystem.AUDIO_FORMAT_DEFAULT);
    }

    private void btMediaMetricRecord(@NonNull BluetoothDevice device, String state,
@@ -1728,8 +1700,8 @@ public class AudioDeviceBroker {
    }

    // must be called synchronized on mConnectedDevices
    /*package*/ boolean hasScheduledA2dpConnection(BluetoothDevice btDevice) {
        final BtDeviceInfo devInfoToCheck = new BtDeviceInfo(btDevice, BluetoothProfile.A2DP);
    /*package*/ boolean hasScheduledA2dpConnection(BluetoothDevice btDevice, int profile) {
        final BtDeviceInfo devInfoToCheck = new BtDeviceInfo(btDevice, profile);
        return mBrokerHandler.hasEqualMessages(MSG_L_SET_BT_ACTIVE_DEVICE, devInfoToCheck);
    }

+6 −5
Original line number Diff line number Diff line
@@ -987,8 +987,10 @@ public class AudioDeviceInventory {
                "onBluetoothDeviceConfigChange addr=" + address
                    + " event=" + BtHelper.deviceEventToString(event)));

        int deviceType = BtHelper.getTypeFromProfile(btInfo.mProfile, btInfo.mIsLeOutput);

        synchronized (mDevicesLock) {
            if (mDeviceBroker.hasScheduledA2dpConnection(btDevice)) {
            if (mDeviceBroker.hasScheduledA2dpConnection(btDevice, btInfo.mProfile)) {
                AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent(
                        "A2dp config change ignored (scheduled connection change)")
                        .printSlog(EventLogger.Event.ALOGI, TAG));
@@ -996,8 +998,7 @@ public class AudioDeviceInventory {
                        .record();
                return delayMs;
            }
            final String key = DeviceInfo.makeDeviceListKey(
                    AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, address);
            final String key = DeviceInfo.makeDeviceListKey(deviceType, address);
            final DeviceInfo di = mConnectedDevices.get(key);
            if (di == null) {
                Log.e(TAG, "invalid null DeviceInfo in onBluetoothDeviceConfigChange");
@@ -1022,7 +1023,7 @@ public class AudioDeviceInventory {
                                BtHelper.getName(btDevice), codec);
                        if (res != AudioSystem.AUDIO_STATUS_OK) {
                            AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent(
                                    "APM handleDeviceConfigChange failed for A2DP device addr="
                                    "APM handleDeviceConfigChange failed for device addr="
                                            + address + " codec="
                                            + AudioSystem.audioFormatToString(codec))
                                    .printSlog(EventLogger.Event.ALOGE, TAG));
@@ -1033,7 +1034,7 @@ public class AudioDeviceInventory {
                                    BluetoothProfile.STATE_DISCONNECTED));
                        } else {
                            AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent(
                                    "APM handleDeviceConfigChange success for A2DP device addr="
                                    "APM handleDeviceConfigChange success for device addr="
                                            + address
                                            + " codec=" + AudioSystem.audioFormatToString(codec))
                                    .printSlog(EventLogger.Event.ALOGI, TAG));
+23 −0
Original line number Diff line number Diff line
@@ -1291,6 +1291,29 @@ public class BtHelper {
        return 0; // 0 is not a valid profile
    }

    /*package */ static int getTypeFromProfile(int profile, boolean isLeOutput) {
        switch (profile) {
            case BluetoothProfile.A2DP_SINK:
                return AudioSystem.DEVICE_IN_BLUETOOTH_A2DP;
            case BluetoothProfile.A2DP:
                return AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP;
            case BluetoothProfile.HEARING_AID:
                return AudioSystem.DEVICE_OUT_HEARING_AID;
            case BluetoothProfile.LE_AUDIO:
                if (isLeOutput) {
                    return AudioSystem.DEVICE_OUT_BLE_HEADSET;
                } else {
                    return AudioSystem.DEVICE_IN_BLE_HEADSET;
                }
            case BluetoothProfile.LE_AUDIO_BROADCAST:
                return AudioSystem.DEVICE_OUT_BLE_BROADCAST;
            case BluetoothProfile.HEADSET:
                return AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
            default:
                throw new IllegalArgumentException("Invalid profile " + profile);
        }
    }

    /*package */ static Bundle getPreferredAudioProfiles(String address) {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        return adapter.getPreferredAudioProfiles(adapter.getRemoteDevice(address));