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

Commit 1b9de57f authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add field to set A2DP device volume on connect (1/2)"

parents 88ee5c93 3ee7b6ca
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -3664,6 +3664,7 @@ public class AudioManager {
     * @param device Bluetooth device connected/disconnected
     * @param device Bluetooth device connected/disconnected
     * @param state  new connection state (BluetoothProfile.STATE_xxx)
     * @param state  new connection state (BluetoothProfile.STATE_xxx)
     * @param profile profile for the A2DP device
     * @param profile profile for the A2DP device
     * @param a2dpVolume New volume for the connecting device. Does nothing if disconnecting.
     * (either {@link android.bluetooth.BluetoothProfile.A2DP} or
     * (either {@link android.bluetooth.BluetoothProfile.A2DP} or
     * {@link android.bluetooth.BluetoothProfile.A2DP_SINK})
     * {@link android.bluetooth.BluetoothProfile.A2DP_SINK})
     * @param suppressNoisyIntent if true the
     * @param suppressNoisyIntent if true the
@@ -3673,12 +3674,13 @@ public class AudioManager {
     * {@hide}
     * {@hide}
     */
     */
    public int setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(
    public int setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(
                BluetoothDevice device, int state, int profile, boolean suppressNoisyIntent) {
                BluetoothDevice device, int state, int profile,
                boolean suppressNoisyIntent, int a2dpVolume) {
        final IAudioService service = getService();
        final IAudioService service = getService();
        int delay = 0;
        int delay = 0;
        try {
        try {
            delay = service.setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(device,
            delay = service.setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(device,
                state, profile, suppressNoisyIntent);
                state, profile, suppressNoisyIntent, a2dpVolume);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -206,7 +206,7 @@ interface IAudioService {
    oneway void playerHasOpPlayAudio(in int piid, in boolean hasOpPlayAudio);
    oneway void playerHasOpPlayAudio(in int piid, in boolean hasOpPlayAudio);


    int setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(in BluetoothDevice device,
    int setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(in BluetoothDevice device,
            int state, int profile, boolean suppressNoisyIntent);
            int state, int profile, boolean suppressNoisyIntent, int a2dpVolume);


    // WARNING: read warning at top of file, it is recommended to add new methods at the end
    // WARNING: read warning at top of file, it is recommended to add new methods at the end
}
}
+49 −38
Original line number Original line Diff line number Diff line
@@ -3476,7 +3476,7 @@ public class AudioService extends IAudioService.Stub
                            queueMsgUnderWakeLock(mAudioHandler,
                            queueMsgUnderWakeLock(mAudioHandler,
                                    MSG_SET_A2DP_SINK_CONNECTION_STATE,
                                    MSG_SET_A2DP_SINK_CONNECTION_STATE,
                                    state,
                                    state,
                                    0 /* arg2 unused */,
                                    -1,
                                    btDevice,
                                    btDevice,
                                    delay);
                                    delay);
                        }
                        }
@@ -4162,22 +4162,22 @@ public class AudioService extends IAudioService.Stub
    public int setBluetoothA2dpDeviceConnectionState(BluetoothDevice device, int state, int profile)
    public int setBluetoothA2dpDeviceConnectionState(BluetoothDevice device, int state, int profile)
    {
    {
        return setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(
        return setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(
                device, state, profile, false /* suppressNoisyIntent */);
                device, state, profile, false /* suppressNoisyIntent */, -1 /* a2dpVolume */);
    }
    }


    public int setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(BluetoothDevice device,
    public int setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(BluetoothDevice device,
                int state, int profile, boolean suppressNoisyIntent)
                int state, int profile, boolean suppressNoisyIntent, int a2dpVolume)
    {
    {
        if (mAudioHandler.hasMessages(MSG_SET_A2DP_SINK_CONNECTION_STATE, device)) {
        if (mAudioHandler.hasMessages(MSG_SET_A2DP_SINK_CONNECTION_STATE, device)) {
            return 0;
            return 0;
        }
        }
        return setBluetoothA2dpDeviceConnectionStateInt(
        return setBluetoothA2dpDeviceConnectionStateInt(
                device, state, profile, suppressNoisyIntent, AudioSystem.DEVICE_NONE);
                device, state, profile, suppressNoisyIntent, AudioSystem.DEVICE_NONE, a2dpVolume);
    }
    }


    public int setBluetoothA2dpDeviceConnectionStateInt(
    public int setBluetoothA2dpDeviceConnectionStateInt(
            BluetoothDevice device, int state, int profile, boolean suppressNoisyIntent,
            BluetoothDevice device, int state, int profile, boolean suppressNoisyIntent,
            int musicDevice)
            int musicDevice, int a2dpVolume)
    {
    {
        int delay;
        int delay;
        if (profile != BluetoothProfile.A2DP && profile != BluetoothProfile.A2DP_SINK) {
        if (profile != BluetoothProfile.A2DP && profile != BluetoothProfile.A2DP_SINK) {
@@ -4195,7 +4195,7 @@ public class AudioService extends IAudioService.Stub
                    (profile == BluetoothProfile.A2DP ?
                    (profile == BluetoothProfile.A2DP ?
                        MSG_SET_A2DP_SINK_CONNECTION_STATE : MSG_SET_A2DP_SRC_CONNECTION_STATE),
                        MSG_SET_A2DP_SINK_CONNECTION_STATE : MSG_SET_A2DP_SRC_CONNECTION_STATE),
                    state,
                    state,
                    0 /* arg2 unused */,
                    a2dpVolume,
                    device,
                    device,
                    delay);
                    delay);
        }
        }
@@ -4693,9 +4693,6 @@ public class AudioService extends IAudioService.Stub
        }
        }
    }
    }


    /** Handles internal volume messages in separate volume thread. */
    private class AudioHandler extends Handler {

    private void setDeviceVolume(VolumeStreamState streamState, int device) {
    private void setDeviceVolume(VolumeStreamState streamState, int device) {


        synchronized (VolumeStreamState.class) {
        synchronized (VolumeStreamState.class) {
@@ -4729,6 +4726,9 @@ public class AudioService extends IAudioService.Stub


    }
    }


    /** Handles internal volume messages in separate volume thread. */
    private class AudioHandler extends Handler {

        private void setAllVolumes(VolumeStreamState streamState) {
        private void setAllVolumes(VolumeStreamState streamState) {


            // Apply volume
            // Apply volume
@@ -5074,7 +5074,7 @@ public class AudioService extends IAudioService.Stub
                    break;
                    break;


                case MSG_SET_A2DP_SINK_CONNECTION_STATE:
                case MSG_SET_A2DP_SINK_CONNECTION_STATE:
                    onSetA2dpSinkConnectionState((BluetoothDevice)msg.obj, msg.arg1);
                    onSetA2dpSinkConnectionState((BluetoothDevice)msg.obj, msg.arg1, msg.arg2);
                    mAudioEventWakeLock.release();
                    mAudioEventWakeLock.release();
                    break;
                    break;


@@ -5312,7 +5312,7 @@ public class AudioService extends IAudioService.Stub
        return mAudioHandler.hasMessages(MSG_BTA2DP_DOCK_TIMEOUT);
        return mAudioHandler.hasMessages(MSG_BTA2DP_DOCK_TIMEOUT);
    }
    }


    private void onSetA2dpSinkConnectionState(BluetoothDevice btDevice, int state)
    private void onSetA2dpSinkConnectionState(BluetoothDevice btDevice, int state, int a2dpVolume)
    {
    {
        if (DEBUG_DEVICES) {
        if (DEBUG_DEVICES) {
            Log.d(TAG, "onSetA2dpSinkConnectionState btDevice=" + btDevice+"state=" + state);
            Log.d(TAG, "onSetA2dpSinkConnectionState btDevice=" + btDevice+"state=" + state);
@@ -5363,6 +5363,14 @@ public class AudioService extends IAudioService.Stub
                        makeA2dpDeviceUnavailableNow(mDockAddress);
                        makeA2dpDeviceUnavailableNow(mDockAddress);
                    }
                    }
                }
                }
                if (a2dpVolume != -1) {
                    VolumeStreamState streamState = mStreamStates[AudioSystem.STREAM_MUSIC];
                    // Convert index to internal representation in VolumeStreamState
                    a2dpVolume = a2dpVolume * 10;
                    streamState.setIndex(a2dpVolume, AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
                            "onSetA2dpSinkConnectionState");
                    setDeviceVolume(streamState, AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP);
                }
                makeA2dpDeviceAvailable(address, btDevice.getName(),
                makeA2dpDeviceAvailable(address, btDevice.getName(),
                        "onSetA2dpSinkConnectionState");
                        "onSetA2dpSinkConnectionState");
                synchronized (mCurAudioRoutes) {
                synchronized (mCurAudioRoutes) {
@@ -5432,7 +5440,7 @@ public class AudioService extends IAudioService.Stub
                   // consistent with audio policy manager state
                   // consistent with audio policy manager state
                   setBluetoothA2dpDeviceConnectionStateInt(
                   setBluetoothA2dpDeviceConnectionStateInt(
                           btDevice, BluetoothA2dp.STATE_DISCONNECTED, BluetoothProfile.A2DP,
                           btDevice, BluetoothA2dp.STATE_DISCONNECTED, BluetoothProfile.A2DP,
                           false /* suppressNoisyIntent */, musicDevice);
                           false /* suppressNoisyIntent */, musicDevice, -1 /* a2dpVolume */);
               }
               }
            }
            }
        }
        }
@@ -5442,6 +5450,9 @@ public class AudioService extends IAudioService.Stub
        // address is not used for now, but may be used when multiple a2dp devices are supported
        // address is not used for now, but may be used when multiple a2dp devices are supported
        synchronized (mA2dpAvrcpLock) {
        synchronized (mA2dpAvrcpLock) {
            mAvrcpAbsVolSupported = support;
            mAvrcpAbsVolSupported = support;
            sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE,
                    AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0,
                    mStreamStates[AudioSystem.STREAM_MUSIC], 0);
        }
        }
    }
    }