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

Commit 695cc44f authored by Ajay Panicker's avatar Ajay Panicker Committed by android-build-merger
Browse files

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

am: d8e8126a

Change-Id: Iefd55728bd7b2a22944de775a2dd24124bfa2bb0
parents 50b1e2c1 d8e8126a
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -3939,6 +3939,7 @@ public class AudioManager {
     * @param device Bluetooth device connected/disconnected
     * @param state  new connection state (BluetoothProfile.STATE_xxx)
     * @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
     * {@link android.bluetooth.BluetoothProfile.A2DP_SINK})
     * @param suppressNoisyIntent if true the
@@ -3948,12 +3949,13 @@ public class AudioManager {
     * {@hide}
     */
    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();
        int delay = 0;
        try {
            delay = service.setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(device,
                state, profile, suppressNoisyIntent);
                state, profile, suppressNoisyIntent, a2dpVolume);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+1 −1
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ interface IAudioService {
    oneway void playerHasOpPlayAudio(in int piid, in boolean hasOpPlayAudio);

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

    oneway void setFocusRequestResultFromExtPolicy(in AudioFocusInfo afi, int requestResult,
            in IAudioPolicyCallback pcb);
+49 −38
Original line number Diff line number Diff line
@@ -3804,7 +3804,7 @@ public class AudioService extends IAudioService.Stub
                            queueMsgUnderWakeLock(mAudioHandler,
                                    MSG_SET_A2DP_SINK_CONNECTION_STATE,
                                    state,
                                    0 /* arg2 unused */,
                                    -1,
                                    btDevice,
                                    delay);
                        }
@@ -4650,22 +4650,22 @@ public class AudioService extends IAudioService.Stub
    public int setBluetoothA2dpDeviceConnectionState(BluetoothDevice device, int state, int profile)
    {
        return setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(
                device, state, profile, false /* suppressNoisyIntent */);
                device, state, profile, false /* suppressNoisyIntent */, -1 /* a2dpVolume */);
    }

    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)) {
            return 0;
        }
        return setBluetoothA2dpDeviceConnectionStateInt(
                device, state, profile, suppressNoisyIntent, AudioSystem.DEVICE_NONE);
                device, state, profile, suppressNoisyIntent, AudioSystem.DEVICE_NONE, a2dpVolume);
    }

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

        synchronized (VolumeStreamState.class) {
@@ -5249,6 +5246,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) {

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

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

@@ -5908,7 +5908,7 @@ public class AudioService extends IAudioService.Stub
        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) {
            Log.d(TAG, "onSetA2dpSinkConnectionState btDevice=" + btDevice+"state=" + state);
@@ -5953,6 +5953,14 @@ public class AudioService extends IAudioService.Stub
                        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(),
                        "onSetA2dpSinkConnectionState");
                setCurrentAudioRouteName(btDevice.getAliasName());
@@ -6055,7 +6063,7 @@ public class AudioService extends IAudioService.Stub
                   // consistent with audio policy manager state
                   setBluetoothA2dpDeviceConnectionStateInt(
                           btDevice, BluetoothA2dp.STATE_DISCONNECTED, BluetoothProfile.A2DP,
                           false /* suppressNoisyIntent */, musicDevice);
                           false /* suppressNoisyIntent */, musicDevice, -1 /* a2dpVolume */);
               }
            }
        }
@@ -6065,6 +6073,9 @@ public class AudioService extends IAudioService.Stub
        // address is not used for now, but may be used when multiple a2dp devices are supported
        synchronized (mA2dpAvrcpLock) {
            mAvrcpAbsVolSupported = support;
            sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE,
                    AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0,
                    mStreamStates[AudioSystem.STREAM_MUSIC], 0);
        }
    }