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

Commit c6924058 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "A2DP: Stop using intent from StateMachine to Service"

parents f21673af fa44948d
Loading
Loading
Loading
Loading
+1 −29
Original line number Diff line number Diff line
@@ -111,7 +111,6 @@ public class A2dpService extends ProfileService {
    boolean mA2dpOffloadEnabled = false;

    private BroadcastReceiver mBondStateChangedReceiver;
    private BroadcastReceiver mConnectionStateChangedReceiver;

    public static boolean isEnabled() {
        return BluetoothProperties.isProfileA2dpSourceEnabled().orElse(false);
@@ -175,10 +174,6 @@ public class A2dpService extends ProfileService {
        filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
        mBondStateChangedReceiver = new BondStateChangedReceiver();
        registerReceiver(mBondStateChangedReceiver, filter);
        filter = new IntentFilter();
        filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
        mConnectionStateChangedReceiver = new ConnectionStateChangedReceiver();
        registerReceiver(mConnectionStateChangedReceiver, filter);

        // Step 8: Mark service as started
        setA2dpService(this);
@@ -214,8 +209,6 @@ public class A2dpService extends ProfileService {
        setA2dpService(null);

        // Step 7: Unregister broadcast receivers
        unregisterReceiver(mConnectionStateChangedReceiver);
        mConnectionStateChangedReceiver = null;
        unregisterReceiver(mBondStateChangedReceiver);
        mBondStateChangedReceiver = null;

@@ -1250,7 +1243,7 @@ public class A2dpService extends ProfileService {
        }
    }

    private void connectionStateChanged(BluetoothDevice device, int fromState, int toState) {
    void connectionStateChanged(BluetoothDevice device, int fromState, int toState) {
        if ((device == null) || (fromState == toState)) {
            return;
        }
@@ -1276,27 +1269,6 @@ public class A2dpService extends ProfileService {
        }
    }

    /**
     * Receiver for processing device connection state changes.
     *
     * <ul>
     * <li> Update codec support per device when device is (re)connected
     * <li> Delete the state machine instance if the device is disconnected and unbond
     * </ul>
     */
    private class ConnectionStateChangedReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (!BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
                return;
            }
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            int toState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
            int fromState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1);
            connectionStateChanged(device, fromState, toState);
        }
    }

    /**
     * Retrieves the most recently connected device in the A2DP connected devices list.
     */
+1 −0
Original line number Diff line number Diff line
@@ -701,6 +701,7 @@ final class A2dpStateMachine extends StateMachine {
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        mA2dpService.connectionStateChanged(mDevice, prevState, newState);
        Utils.sendBroadcast(mA2dpService, intent, BLUETOOTH_CONNECT,
                Utils.getTempAllowlistBroadcastOptions());
    }