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

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

Merge "indicate in and out audio device connection separately"

parents c0d1fc80 ae4506e9
Loading
Loading
Loading
Loading
+19 −14
Original line number Original line Diff line number Diff line
@@ -4141,8 +4141,9 @@ public class AudioService extends IAudioService.Stub {
                    (device == AudioSystem.DEVICE_OUT_WIRED_HEADPHONE))) {
                    (device == AudioSystem.DEVICE_OUT_WIRED_HEADPHONE))) {
                setBluetoothA2dpOnInt(true);
                setBluetoothA2dpOnInt(true);
            }
            }
            boolean isUsb = ((device & AudioSystem.DEVICE_OUT_ALL_USB) != 0) ||
            boolean isUsb = ((device & ~AudioSystem.DEVICE_OUT_ALL_USB) == 0) ||
                            ((device & AudioSystem.DEVICE_IN_ALL_USB) != 0);
                            (((device & AudioSystem.DEVICE_BIT_IN) != 0) &&
                             ((device & ~AudioSystem.DEVICE_IN_ALL_USB) == 0));
            handleDeviceConnection((state == 1), device, (isUsb ? name : ""));
            handleDeviceConnection((state == 1), device, (isUsb ? name : ""));
            if (state != 0) {
            if (state != 0) {
                if ((device == AudioSystem.DEVICE_OUT_WIRED_HEADSET) ||
                if ((device == AudioSystem.DEVICE_OUT_WIRED_HEADSET) ||
@@ -4159,7 +4160,7 @@ public class AudioService extends IAudioService.Stub {
                            MUSIC_ACTIVE_POLL_PERIOD_MS);
                            MUSIC_ACTIVE_POLL_PERIOD_MS);
                }
                }
            }
            }
            if (!isUsb) {
            if (!isUsb && (device != AudioSystem.DEVICE_IN_WIRED_HEADSET)) {
                sendDeviceConnectionIntent(device, state, name);
                sendDeviceConnectionIntent(device, state, name);
            }
            }
        }
        }
@@ -4175,7 +4176,8 @@ public class AudioService extends IAudioService.Stub {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            String action = intent.getAction();
            int device;
            int outDevice;
            int inDevice;
            int state;
            int state;


            if (action.equals(Intent.ACTION_DOCK_EVENT)) {
            if (action.equals(Intent.ACTION_DOCK_EVENT)) {
@@ -4210,7 +4212,8 @@ public class AudioService extends IAudioService.Stub {
            } else if (action.equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)) {
            } else if (action.equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)) {
                state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
                state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
                                               BluetoothProfile.STATE_DISCONNECTED);
                                               BluetoothProfile.STATE_DISCONNECTED);
                device = AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
                outDevice = AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
                inDevice = AudioSystem.DEVICE_IN_BLUETOOTH_SCO_HEADSET;
                String address = null;
                String address = null;


                BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
@@ -4224,10 +4227,10 @@ public class AudioService extends IAudioService.Stub {
                    switch (btClass.getDeviceClass()) {
                    switch (btClass.getDeviceClass()) {
                    case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
                    case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
                    case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
                    case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
                        device = AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_HEADSET;
                        outDevice = AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_HEADSET;
                        break;
                        break;
                    case BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO:
                    case BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO:
                        device = AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_CARKIT;
                        outDevice = AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_CARKIT;
                        break;
                        break;
                    }
                    }
                }
                }
@@ -4237,7 +4240,9 @@ public class AudioService extends IAudioService.Stub {
                }
                }


                boolean connected = (state == BluetoothProfile.STATE_CONNECTED);
                boolean connected = (state == BluetoothProfile.STATE_CONNECTED);
                if (handleDeviceConnection(connected, device, address)) {
                boolean success = handleDeviceConnection(connected, outDevice, address) &&
                                      handleDeviceConnection(connected, inDevice, address);
                if (success) {
                    synchronized (mScoClients) {
                    synchronized (mScoClients) {
                        if (connected) {
                        if (connected) {
                            mBluetoothHeadsetDevice = btDevice;
                            mBluetoothHeadsetDevice = btDevice;
@@ -4257,8 +4262,8 @@ public class AudioService extends IAudioService.Stub {
                                    : "card=" + alsaCard + ";device=" + alsaDevice);
                                    : "card=" + alsaCard + ";device=" + alsaDevice);


                // Playback Device
                // Playback Device
                device = AudioSystem.DEVICE_OUT_USB_ACCESSORY;
                outDevice = AudioSystem.DEVICE_OUT_USB_ACCESSORY;
                setWiredDeviceConnectionState(device, state, params);
                setWiredDeviceConnectionState(outDevice, state, params);
            } else if (action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) {
            } else if (action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) {
                state = intent.getIntExtra("state", 0);
                state = intent.getIntExtra("state", 0);


@@ -4273,14 +4278,14 @@ public class AudioService extends IAudioService.Stub {


                // Playback Device
                // Playback Device
                if (hasPlayback) {
                if (hasPlayback) {
                    device = AudioSystem.DEVICE_OUT_USB_DEVICE;
                    outDevice = AudioSystem.DEVICE_OUT_USB_DEVICE;
                    setWiredDeviceConnectionState(device, state, params);
                    setWiredDeviceConnectionState(outDevice, state, params);
                }
                }


                // Capture Device
                // Capture Device
                if (hasCapture) {
                if (hasCapture) {
                    device = AudioSystem.DEVICE_IN_USB_DEVICE;
                    inDevice = AudioSystem.DEVICE_IN_USB_DEVICE;
                    setWiredDeviceConnectionState(device, state, params);
                    setWiredDeviceConnectionState(inDevice, state, params);
                }
                }
            } else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) {
            } else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) {
                boolean broadcast = false;
                boolean broadcast = false;
+14 −7
Original line number Original line Diff line number Diff line
@@ -246,7 +246,8 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
    private void setDeviceStateLocked(int headset,
    private void setDeviceStateLocked(int headset,
            int headsetState, int prevHeadsetState, String headsetName) {
            int headsetState, int prevHeadsetState, String headsetName) {
        if ((headsetState & headset) != (prevHeadsetState & headset)) {
        if ((headsetState & headset) != (prevHeadsetState & headset)) {
            int device;
            int outDevice = 0;
            int inDevice = 0;
            int state;
            int state;


            if ((headsetState & headset) != 0) {
            if ((headsetState & headset) != 0) {
@@ -256,15 +257,16 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
            }
            }


            if (headset == BIT_HEADSET) {
            if (headset == BIT_HEADSET) {
                device = AudioManager.DEVICE_OUT_WIRED_HEADSET;
                outDevice = AudioManager.DEVICE_OUT_WIRED_HEADSET;
                inDevice = AudioManager.DEVICE_IN_WIRED_HEADSET;
            } else if (headset == BIT_HEADSET_NO_MIC){
            } else if (headset == BIT_HEADSET_NO_MIC){
                device = AudioManager.DEVICE_OUT_WIRED_HEADPHONE;
                outDevice = AudioManager.DEVICE_OUT_WIRED_HEADPHONE;
            } else if (headset == BIT_USB_HEADSET_ANLG) {
            } else if (headset == BIT_USB_HEADSET_ANLG) {
                device = AudioManager.DEVICE_OUT_ANLG_DOCK_HEADSET;
                outDevice = AudioManager.DEVICE_OUT_ANLG_DOCK_HEADSET;
            } else if (headset == BIT_USB_HEADSET_DGTL) {
            } else if (headset == BIT_USB_HEADSET_DGTL) {
                device = AudioManager.DEVICE_OUT_DGTL_DOCK_HEADSET;
                outDevice = AudioManager.DEVICE_OUT_DGTL_DOCK_HEADSET;
            } else if (headset == BIT_HDMI_AUDIO) {
            } else if (headset == BIT_HDMI_AUDIO) {
                device = AudioManager.DEVICE_OUT_HDMI;
                outDevice = AudioManager.DEVICE_OUT_HDMI;
            } else {
            } else {
                Slog.e(TAG, "setDeviceState() invalid headset type: "+headset);
                Slog.e(TAG, "setDeviceState() invalid headset type: "+headset);
                return;
                return;
@@ -273,7 +275,12 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
            if (LOG)
            if (LOG)
                Slog.v(TAG, "device "+headsetName+((state == 1) ? " connected" : " disconnected"));
                Slog.v(TAG, "device "+headsetName+((state == 1) ? " connected" : " disconnected"));


            mAudioManager.setWiredDeviceConnectionState(device, state, headsetName);
            if (outDevice != 0) {
              mAudioManager.setWiredDeviceConnectionState(outDevice, state, headsetName);
            }
            if (inDevice != 0) {
              mAudioManager.setWiredDeviceConnectionState(inDevice, state, headsetName);
            }
        }
        }
    }
    }