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

Commit fb83e5dd authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Fix volume change nullpointer exception in AvrcpTargetService when...

Merge "Fix volume change nullpointer exception in AvrcpTargetService when configured as A2DP sink" am: 25a4a7e1 am: 46fe2802

Change-Id: I4020fff4b0e7a62cfdbac27455f7df6864e35b48
parents 9456e173 46fe2802
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public class AvrcpTargetService extends ProfileService {
                int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
                if (streamType == AudioManager.STREAM_MUSIC) {
                    int volume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
                    BluetoothDevice activeDevice = mFactory.getA2dpService().getActiveDevice();
                    BluetoothDevice activeDevice = getA2dpActiveDevice();
                    if (activeDevice != null
                            && !mVolumeManager.getAbsoluteVolumeSupported(activeDevice)) {
                        Log.d(TAG, "stream volume change to " + volume + " " + activeDevice);
@@ -231,6 +231,23 @@ public class AvrcpTargetService extends ProfileService {
    private void init() {
    }

    private BluetoothDevice getA2dpActiveDevice() {
        A2dpService service = mFactory.getA2dpService();
        if (service == null) {
            return null;
        }
        return service.getActiveDevice();
    }

    private void setA2dpActiveDevice(BluetoothDevice device) {
        A2dpService service = A2dpService.getA2dpService();
        if (service == null) {
            Log.d(TAG, "setA2dpActiveDevice: A2dp service not found");
            return;
        }
        service.setActiveDevice(device);
    }

    void deviceConnected(BluetoothDevice device, boolean absoluteVolume) {
        Log.i(TAG, "deviceConnected: device=" + device + " absoluteVolume=" + absoluteVolume);
        mVolumeManager.deviceConnected(device, absoluteVolume);
@@ -275,7 +292,7 @@ public class AvrcpTargetService extends ProfileService {

    // TODO (apanicke): Add checks to blacklist Absolute Volume devices if they behave poorly.
    void setVolume(int avrcpVolume) {
        BluetoothDevice activeDevice = mFactory.getA2dpService().getActiveDevice();
        BluetoothDevice activeDevice = getA2dpActiveDevice();
        if (activeDevice == null) {
            Log.d(TAG, "setVolume: no active device");
            return;
@@ -289,7 +306,7 @@ public class AvrcpTargetService extends ProfileService {
     * volume.
     */
    public void sendVolumeChanged(int deviceVolume) {
        BluetoothDevice activeDevice = mFactory.getA2dpService().getActiveDevice();
        BluetoothDevice activeDevice = getA2dpActiveDevice();
        if (activeDevice == null) {
            Log.d(TAG, "sendVolumeChanged: no active device");
            return;
@@ -357,7 +374,7 @@ public class AvrcpTargetService extends ProfileService {
        if (device == null) {
            Log.wtf(TAG, "setActiveDevice: could not find device " + device);
        }
        A2dpService.getA2dpService().setActiveDevice(device);
        setA2dpActiveDevice(device);
    }

    /**