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

Commit 6261eb44 authored by William Escande's avatar William Escande
Browse files

A2DP: Stop using intent from StateMachine to Service

Bug: 266252291
Test: atest BluetoothInstrumentationTests
Change-Id: I8f3ea0e92eba9d007ae5e6a8457bc377e3ad9728
(cherry picked from commit fa44948d)
Merged-In: I8f3ea0e92eba9d007ae5e6a8457bc377e3ad9728
parent ec7bf15a
Loading
Loading
Loading
Loading
+1 −29
Original line number Original line Diff line number Diff line
@@ -106,7 +106,6 @@ public class A2dpService extends ProfileService {
    boolean mA2dpOffloadEnabled = false;
    boolean mA2dpOffloadEnabled = false;


    private BroadcastReceiver mBondStateChangedReceiver;
    private BroadcastReceiver mBondStateChangedReceiver;
    private BroadcastReceiver mConnectionStateChangedReceiver;


    public static boolean isEnabled() {
    public static boolean isEnabled() {
        return BluetoothProperties.isProfileA2dpSourceEnabled().orElse(false);
        return BluetoothProperties.isProfileA2dpSourceEnabled().orElse(false);
@@ -169,10 +168,6 @@ public class A2dpService extends ProfileService {
        filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
        filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
        mBondStateChangedReceiver = new BondStateChangedReceiver();
        mBondStateChangedReceiver = new BondStateChangedReceiver();
        registerReceiver(mBondStateChangedReceiver, filter);
        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
        // Step 8: Mark service as started
        setA2dpService(this);
        setA2dpService(this);
@@ -208,8 +203,6 @@ public class A2dpService extends ProfileService {
        setA2dpService(null);
        setA2dpService(null);


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


@@ -1242,7 +1235,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)) {
        if ((device == null) || (fromState == toState)) {
            return;
            return;
        }
        }
@@ -1268,27 +1261,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.
     * Retrieves the most recently connected device in the A2DP connected devices list.
     */
     */
+1 −0
Original line number Original line Diff line number Diff line
@@ -701,6 +701,7 @@ final class A2dpStateMachine extends StateMachine {
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        mA2dpService.connectionStateChanged(mDevice, prevState, newState);
        mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT,
        mA2dpService.sendBroadcast(intent, BLUETOOTH_CONNECT,
                Utils.getTempAllowlistBroadcastOptions());
                Utils.getTempAllowlistBroadcastOptions());
    }
    }