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

Commit 99a076a1 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Automerger Merge Worker
Browse files

Merge "server/audio: Add LeAudio support" am: 4fef6084 am: 791c25e7 am:...

Merge "server/audio: Add LeAudio support" am: 4fef6084 am: 791c25e7 am: 4089d3ed am: 1ec83b82 am: 9af21c6e

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1856323

Change-Id: Ic993b44cc2c56c2d95c8e80773bbeba4e865f786
parents d19ec2cb 9af21c6e
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public final class MediaRoute2Info implements Parcelable {
    @IntDef({
            TYPE_UNKNOWN, TYPE_BUILTIN_SPEAKER, TYPE_WIRED_HEADSET,
            TYPE_WIRED_HEADPHONES, TYPE_BLUETOOTH_A2DP, TYPE_HDMI, TYPE_USB_DEVICE,
            TYPE_USB_ACCESSORY, TYPE_DOCK, TYPE_USB_HEADSET, TYPE_HEARING_AID,
            TYPE_USB_ACCESSORY, TYPE_DOCK, TYPE_USB_HEADSET, TYPE_HEARING_AID, TYPE_BLE_HEADSET,
            TYPE_REMOTE_TV, TYPE_REMOTE_SPEAKER, TYPE_GROUP})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Type {}
@@ -201,6 +201,14 @@ public final class MediaRoute2Info implements Parcelable {
     */
    public static final int TYPE_HEARING_AID = AudioDeviceInfo.TYPE_HEARING_AID;

    /**
     * A route type describing a BLE HEADSET.
     *
     * @see #getType
     * @hide
     */
    public static final int TYPE_BLE_HEADSET = AudioDeviceInfo.TYPE_BLE_HEADSET;

    /**
     * A route type indicating the presentation of the media is happening on a TV.
     *
+53 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothLeAudio;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -503,6 +504,18 @@ import java.util.concurrent.atomic.AtomicBoolean;
        }
    }

    /*package*/ static final class BleVolumeInfo {
        final int mIndex;
        final int mMaxIndex;
        final int mStreamType;

        BleVolumeInfo(int index, int maxIndex, int streamType) {
            mIndex = index;
            mMaxIndex = maxIndex;
            mStreamType = streamType;
        }
    };

    /*package*/ static final class BtDeviceConnectionInfo {
        final @NonNull BluetoothDevice mDevice;
        final @AudioService.BtProfileConnectionState int mState;
@@ -711,6 +724,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
        sendIIMsgNoDelay(MSG_II_SET_HEARING_AID_VOLUME, SENDMSG_REPLACE, index, streamType);
    }

     /*package*/ void postSetLeAudioVolumeIndex(int index, int maxIndex, int streamType) {
        BleVolumeInfo info = new BleVolumeInfo(index, maxIndex, streamType);
        sendLMsgNoDelay(MSG_II_SET_LE_AUDIO_OUT_VOLUME, SENDMSG_REPLACE, info);
    }

    /*package*/ void postSetModeOwnerPid(int pid, int mode) {
        sendIIMsgNoDelay(MSG_I_SET_MODE_OWNER_PID, SENDMSG_REPLACE, pid, mode);
    }
@@ -851,6 +869,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
        return mAudioService.getVssVolumeForDevice(streamType, device);
    }

    /*package*/ int getMaxVssVolumeForStream(int streamType) {
        return mAudioService.getMaxVssVolumeForStream(streamType);
    }

    /*package*/ int getDeviceForStream(int streamType) {
        return mAudioService.getDeviceForStream(streamType);
    }
@@ -962,6 +984,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
        sendMsgNoDelay(MSG_DISCONNECT_BT_HEARING_AID, SENDMSG_QUEUE);
    }

    /*package*/ void postDisconnectLeAudio() {
        sendMsgNoDelay(MSG_DISCONNECT_BT_LE_AUDIO, SENDMSG_QUEUE);
    }

    /*package*/ void postDisconnectHeadset() {
        sendMsgNoDelay(MSG_DISCONNECT_BT_HEADSET, SENDMSG_QUEUE);
    }
@@ -983,6 +1009,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
                hearingAidProfile);
    }

    /*package*/ void postBtLeAudioProfileConnected(BluetoothLeAudio leAudioProfile) {
        sendLMsgNoDelay(MSG_L_BT_SERVICE_CONNECTED_PROFILE_LE_AUDIO, SENDMSG_QUEUE,
                leAudioProfile);
    }

    /*package*/ void postCommunicationRouteClientDied(CommunicationRouteClient client) {
        sendLMsgNoDelay(MSG_L_COMMUNICATION_ROUTE_CLIENT_DIED, SENDMSG_QUEUE, client);
    }
@@ -1321,6 +1352,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
                        mBtHelper.setHearingAidVolume(msg.arg1, msg.arg2);
                    }
                    break;
                case MSG_II_SET_LE_AUDIO_OUT_VOLUME: {
                    final BleVolumeInfo info = (BleVolumeInfo) msg.obj;
                    synchronized (mDeviceStateLock) {
                        mBtHelper.setLeAudioVolume(info.mIndex, info.mMaxIndex, info.mStreamType);
                    }
                } break;
                case MSG_I_SET_AVRCP_ABSOLUTE_VOLUME:
                    synchronized (mDeviceStateLock) {
                        mBtHelper.setAvrcpAbsoluteVolumeIndex(msg.arg1);
@@ -1384,6 +1421,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
                        }
                    }
                    break;
                case MSG_DISCONNECT_BT_LE_AUDIO:
                    synchronized(mDeviceStateLock) {
                        mDeviceInventory.disconnectLeAudio();
                    }
                    break;
                case MSG_L_BT_SERVICE_CONNECTED_PROFILE_A2DP:
                    synchronized (mDeviceStateLock) {
                        mBtHelper.onA2dpProfileConnected((BluetoothA2dp) msg.obj);
@@ -1399,6 +1441,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
                        mBtHelper.onHearingAidProfileConnected((BluetoothHearingAid) msg.obj);
                    }
                    break;

                case MSG_L_BT_SERVICE_CONNECTED_PROFILE_LE_AUDIO:
                    synchronized(mDeviceStateLock) {
                        mBtHelper.onLeAudioProfileConnected((BluetoothLeAudio) msg.obj);
                    }
                    break;
                case MSG_L_BT_SERVICE_CONNECTED_PROFILE_HEADSET:
                    synchronized (mSetModeLock) {
                        synchronized (mDeviceStateLock) {
@@ -1586,6 +1634,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
    private static final int MSG_IL_SET_LE_AUDIO_IN_CONNECTION_STATE = 43;
    private static final int MSG_L_LE_AUDIO_DEVICE_OUT_CONNECTION_CHANGE_EXT = 44;
    private static final int MSG_L_LE_AUDIO_DEVICE_IN_CONNECTION_CHANGE_EXT = 45;
    // process set volume for Le Audio, obj is BleVolumeInfo
    private static final int MSG_II_SET_LE_AUDIO_OUT_VOLUME = 46;

    private static final int MSG_L_BT_SERVICE_CONNECTED_PROFILE_LE_AUDIO = 47;
    private static final int MSG_DISCONNECT_BT_LE_AUDIO = 48;

    private static boolean isMessageHandledUnderWakelock(int msgId) {
        switch(msgId) {
+27 −0
Original line number Diff line number Diff line
@@ -887,6 +887,28 @@ public class AudioDeviceInventory {
        }
    }

     /*package*/ void disconnectLeAudio() {
        synchronized (mDevicesLock) {
            final ArraySet<String> toRemove = new ArraySet<>();
            // Disconnect ALL DEVICE_OUT_BLE_HEADSET devices
            mConnectedDevices.values().forEach(deviceInfo -> {
                if (deviceInfo.mDeviceType == AudioSystem.DEVICE_OUT_BLE_HEADSET) {
                    toRemove.add(deviceInfo.mDeviceAddress);
                }
            });
            new MediaMetrics.Item(mMetricsId + "disconnectLeAudio")
                    .record();
            if (toRemove.size() > 0) {
                final int delay = checkSendBecomingNoisyIntentInt(
                        AudioSystem.DEVICE_OUT_BLE_HEADSET, 0, AudioSystem.DEVICE_NONE);
                toRemove.stream().forEach(deviceAddress ->
                        makeLeAudioDeviceUnavailable(deviceAddress,
                            AudioSystem.DEVICE_OUT_BLE_HEADSET)
                );
            }
        }
    }

    // must be called before removing the device from mConnectedDevices
    // musicDevice argument is used when not AudioSystem.DEVICE_NONE instead of querying
    // from AudioSystem
@@ -1195,6 +1217,10 @@ public class AudioDeviceInventory {
            return;
        }

        final int leAudioVolIndex = mDeviceBroker.getVssVolumeForDevice(streamType,
                                    AudioSystem.DEVICE_OUT_BLE_HEADSET);
        final int maxIndex = mDeviceBroker.getMaxVssVolumeForStream(streamType);
        mDeviceBroker.postSetLeAudioVolumeIndex(leAudioVolIndex, maxIndex, streamType);
        mDeviceBroker.postApplyVolumeOnDevice(streamType, device, "makeLeAudioDeviceAvailable");
    }

@@ -1243,6 +1269,7 @@ public class AudioDeviceInventory {
        BECOMING_NOISY_INTENT_DEVICES_SET.add(AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET);
        BECOMING_NOISY_INTENT_DEVICES_SET.add(AudioSystem.DEVICE_OUT_LINE);
        BECOMING_NOISY_INTENT_DEVICES_SET.add(AudioSystem.DEVICE_OUT_HEARING_AID);
        BECOMING_NOISY_INTENT_DEVICES_SET.add(AudioSystem.DEVICE_OUT_BLE_HEADSET);
        BECOMING_NOISY_INTENT_DEVICES_SET.addAll(AudioSystem.DEVICE_OUT_ALL_A2DP_SET);
        BECOMING_NOISY_INTENT_DEVICES_SET.addAll(AudioSystem.DEVICE_OUT_ALL_USB_SET);
        BECOMING_NOISY_INTENT_DEVICES_SET.addAll(AudioSystem.DEVICE_OUT_ALL_BLE_SET);
+24 −0
Original line number Diff line number Diff line
@@ -345,6 +345,10 @@ public class AudioService extends IAudioService.Stub
        return mStreamStates[stream].getIndex(device);
    }

    /*package*/ int getMaxVssVolumeForStream(int stream) {
        return mStreamStates[stream].getMaxIndex();
    }

    private SettingsObserver mSettingsObserver;

    private AtomicInteger mMode = new AtomicInteger(AudioSystem.MODE_NORMAL);
@@ -2991,6 +2995,16 @@ public class AudioService extends IAudioService.Stub
                mDeviceBroker.postSetAvrcpAbsoluteVolumeIndex(newIndex / 10);
            }

            if (device == AudioSystem.DEVICE_OUT_BLE_HEADSET
                    && streamType == getBluetoothContextualVolumeStream()) {
                if (DEBUG_VOL) {
                    Log.d(TAG, "adjustSreamVolume postSetLeAudioVolumeIndex index="
                            + newIndex + " stream=" + streamType);
                }
                mDeviceBroker.postSetLeAudioVolumeIndex(newIndex,
                    mStreamStates[streamType].getMaxIndex(), streamType);
            }

            // Check if volume update should be send to Hearing Aid
            if (device == AudioSystem.DEVICE_OUT_HEARING_AID) {
                // only modify the hearing aid attenuation when the stream to modify matches
@@ -3609,6 +3623,16 @@ public class AudioService extends IAudioService.Stub
                mDeviceBroker.postSetAvrcpAbsoluteVolumeIndex(index / 10);
            }

            if (device == AudioSystem.DEVICE_OUT_BLE_HEADSET
                    && streamType == getBluetoothContextualVolumeStream()) {
                if (DEBUG_VOL) {
                    Log.d(TAG, "adjustSreamVolume postSetLeAudioVolumeIndex index="
                            + index + " stream=" + streamType);
                }
                mDeviceBroker.postSetLeAudioVolumeIndex(index,
                    mStreamStates[streamType].getMaxIndex(), streamType);
            }

            if (device == AudioSystem.DEVICE_OUT_HEARING_AID
                    && streamType == getBluetoothContextualVolumeStream()) {
                Log.i(TAG, "setStreamVolume postSetHearingAidVolumeIndex index=" + index
+13 −0
Original line number Diff line number Diff line
@@ -155,6 +155,7 @@ public class AudioServiceEvents {
        static final int VOL_MODE_CHANGE_HEARING_AID = 7;
        static final int VOL_SET_GROUP_VOL = 8;
        static final int VOL_MUTE_STREAM_INT = 9;
        static final int VOL_SET_LE_AUDIO_VOL = 10;

        final int mOp;
        final int mStream;
@@ -310,6 +311,13 @@ public class AudioServiceEvents {
                            .set(MediaMetrics.Property.INDEX, mVal1)
                            .record();
                    return;
                case VOL_SET_LE_AUDIO_VOL:
                    new MediaMetrics.Item(mMetricsId)
                            .set(MediaMetrics.Property.EVENT, "setLeAudioVolume")
                            .set(MediaMetrics.Property.INDEX, mVal1)
                            .set(MediaMetrics.Property.MAX_INDEX, mVal2)
                            .record();
                    return;
                case VOL_SET_AVRCP_VOL:
                    new MediaMetrics.Item(mMetricsId)
                            .set(MediaMetrics.Property.EVENT, "setAvrcpVolume")
@@ -382,6 +390,11 @@ public class AudioServiceEvents {
                            .append(" index:").append(mVal1)
                            .append(" gain dB:").append(mVal2)
                            .toString();
                case VOL_SET_LE_AUDIO_VOL:
                    return new StringBuilder("setLeAudioVolume:")
                            .append(" index:").append(mVal1)
                            .append(" gain dB:").append(mVal2)
                            .toString();
                case VOL_SET_AVRCP_VOL:
                    return new StringBuilder("setAvrcpVolume:")
                            .append(" index:").append(mVal1)
Loading