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

Commit d25e6298 authored by Aritra Sen's avatar Aritra Sen Committed by Gerrit Code Review
Browse files

Merge "Posting the connection change on a handler to make sure that we don't...

Merge "Posting the connection change on a handler to make sure that we don't enter a stack overflow. (If connection disconnects we also remove state machine which is a conflict)." into main
parents b31bf84d 2c0227ed
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -49,7 +49,9 @@ import android.media.BluetoothProfileConnectionInfo;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.sysprop.BluetoothProperties;
import android.util.Log;

@@ -87,6 +89,7 @@ public class A2dpService extends ProfileService {
    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;
    private HandlerThread mStateMachinesThread;
    private Handler mHandler = null;

    private final A2dpNativeInterface mNativeInterface;
    @VisibleForTesting
@@ -167,6 +170,8 @@ public class A2dpService extends ProfileService {
        Log.i(TAG, "Max connected audio devices set to " + mMaxConnectedAudioDevices);

        // Step 3: Start handler thread for state machines
        // Setup Handler.
        mHandler = new Handler(Looper.getMainLooper());
        mStateMachines.clear();
        mStateMachinesThread = new HandlerThread("A2dpService.StateMachines");
        mStateMachinesThread.start();
@@ -1248,6 +1253,10 @@ public class A2dpService extends ProfileService {
        }
    }

    void handleConnectionStateChanged(BluetoothDevice device, int fromState, int toState) {
        mHandler.post(() -> connectionStateChanged(device, fromState, toState));
    }

    void connectionStateChanged(BluetoothDevice device, int fromState, int toState) {
        if ((device == null) || (fromState == toState)) {
            return;
+1 −1
Original line number Diff line number Diff line
@@ -735,7 +735,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);
        mA2dpService.handleConnectionStateChanged(mDevice, prevState, newState);
        Utils.sendBroadcast(mA2dpService, intent, BLUETOOTH_CONNECT,
                Utils.getTempAllowlistBroadcastOptions());
    }