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

Commit ae5f17bc authored by Grace Jia's avatar Grace Jia Committed by Android (Google) Code Review
Browse files

Merge "Revert "Avoid entering to the connected state of an inactive device in"" into main

parents d73740be 9b62a3ec
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothLeAudio;
import android.content.Context;
import android.media.AudioDeviceInfo;
import android.os.Message;
@@ -40,10 +40,12 @@ import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.Timeouts;
import com.android.server.telecom.flags.FeatureFlags;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@@ -138,7 +140,7 @@ public class BluetoothRouteManager extends StateMachine {
                Log.w(LOG_TAG, "Entering AudioOff state but device %s appears to be connected. " +
                        "Switching to audio-on state for that device.", erroneouslyConnectedDevice);
                // change this to just transition to the new audio on state
                transitionToActualState(null /* excludeAddress */);
                transitionToActualState();
            }
            cleanupStatesForDisconnectedDevices();
            if (mListener != null) {
@@ -261,7 +263,7 @@ public class BluetoothRouteManager extends StateMachine {
                    case LOST_DEVICE:
                        removeDevice((String) args.arg2);
                        if (Objects.equals(address, mDeviceAddress)) {
                            transitionToActualState(null /* excludeAddress */);
                            transitionToActualState();
                        }
                        break;
                    case CONNECT_BT:
@@ -301,7 +303,7 @@ public class BluetoothRouteManager extends StateMachine {
                    case CONNECTION_TIMEOUT:
                        Log.i(LOG_TAG, "Connection with device %s timed out.",
                                mDeviceAddress);
                        transitionToActualState(null /* excludeAddress */);
                        transitionToActualState();
                        break;
                    case BT_AUDIO_IS_ON:
                        if (Objects.equals(mDeviceAddress, address)) {
@@ -318,7 +320,7 @@ public class BluetoothRouteManager extends StateMachine {
                        if (Objects.equals(mDeviceAddress, address) || address == null) {
                            Log.i(LOG_TAG, "Connection with device %s failed.",
                                    mDeviceAddress);
                            transitionToActualState(address);
                            transitionToActualState();
                        } else {
                            Log.w(LOG_TAG, "Got BT lost message for device %s while" +
                                    " connecting to %s.", address, mDeviceAddress);
@@ -378,7 +380,7 @@ public class BluetoothRouteManager extends StateMachine {
                    case LOST_DEVICE:
                        removeDevice((String) args.arg2);
                        if (Objects.equals(address, mDeviceAddress)) {
                            transitionToActualState(null /* excludeAddress */);
                            transitionToActualState();
                        }
                        break;
                    case CONNECT_BT:
@@ -440,7 +442,7 @@ public class BluetoothRouteManager extends StateMachine {
                    case BT_AUDIO_LOST:
                        if (Objects.equals(mDeviceAddress, address) || address == null) {
                            Log.i(LOG_TAG, "BT connection with device %s lost.", mDeviceAddress);
                            transitionToActualState(address);
                            transitionToActualState();
                        } else {
                            Log.w(LOG_TAG, "Got BT lost message for device %s while" +
                                    " connected to %s.", address, mDeviceAddress);
@@ -769,7 +771,7 @@ public class BluetoothRouteManager extends StateMachine {
                actualAddress)) {
            Log.i(this, "trying to connect to already connected device -- skipping connection"
                    + " and going into the actual connected state.");
            transitionToActualState(null /* excludeAddress */);
            transitionToActualState();
            return null;
        }

@@ -805,10 +807,9 @@ public class BluetoothRouteManager extends StateMachine {
        return null;
    }

    private void transitionToActualState(String excludeAddress) {
    private void transitionToActualState() {
        BluetoothDevice possiblyAlreadyConnectedDevice = getBluetoothAudioConnectedDevice();
        if (possiblyAlreadyConnectedDevice != null
                && !possiblyAlreadyConnectedDevice.getAddress().equals(excludeAddress)) {
        if (possiblyAlreadyConnectedDevice != null) {
            Log.i(LOG_TAG, "Device %s is already connected; going to AudioConnected.",
                    possiblyAlreadyConnectedDevice);
            transitionTo(getConnectedStateForAddress(