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

Commit 5415fd27 authored by Marie Janssen's avatar Marie Janssen Committed by Jack He
Browse files

A2DP: Only unregister receiver if we registered

If A2DP isn't ever started, A2dpService.cleanup() would try to unregister
when we are not registered.

Bug: 63061079
Test: none
Change-Id: I7229625f19c07dddeb58d7ee0787c83f0164e3e8
(cherry picked from commit 44ba2305)
parent 690ca30b
Loading
Loading
Loading
Loading
+15 −6
Original line number Original line Diff line number Diff line
@@ -48,7 +48,9 @@ public class A2dpService extends ProfileService {
    private A2dpStateMachine mStateMachine;
    private A2dpStateMachine mStateMachine;
    private Avrcp mAvrcp;
    private Avrcp mAvrcp;


    private BroadcastReceiver mConnectionStateChangedReceiver = new BroadcastReceiver() {
    private BroadcastReceiver mConnectionStateChangedReceiver = null;

    private class CodecSupportReceiver extends BroadcastReceiver {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            if (!BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
            if (!BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
@@ -108,9 +110,12 @@ public class A2dpService extends ProfileService {
        mAvrcp = Avrcp.make(this);
        mAvrcp = Avrcp.make(this);
        mStateMachine = A2dpStateMachine.make(this, this);
        mStateMachine = A2dpStateMachine.make(this, this);
        setA2dpService(this);
        setA2dpService(this);
        if (mConnectionStateChangedReceiver == null) {
            IntentFilter filter = new IntentFilter();
            IntentFilter filter = new IntentFilter();
            filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
            filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
            mConnectionStateChangedReceiver = new CodecSupportReceiver();
            registerReceiver(mConnectionStateChangedReceiver, filter);
            registerReceiver(mConnectionStateChangedReceiver, filter);
        }
        return true;
        return true;
    }
    }


@@ -125,9 +130,13 @@ public class A2dpService extends ProfileService {
    }
    }


    protected boolean cleanup() {
    protected boolean cleanup() {
        if (mConnectionStateChangedReceiver != null) {
            unregisterReceiver(mConnectionStateChangedReceiver);
            unregisterReceiver(mConnectionStateChangedReceiver);
            mConnectionStateChangedReceiver = null;
        }
        if (mStateMachine != null) {
        if (mStateMachine != null) {
            mStateMachine.cleanup();
            mStateMachine.cleanup();
            mStateMachine = null;
        }
        }
        if (mAvrcp != null) {
        if (mAvrcp != null) {
            mAvrcp.cleanup();
            mAvrcp.cleanup();