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

Commit 3a6dd377 authored by Hall Liu's avatar Hall Liu
Browse files

Rename HFP_LOST and HFP_IS_ON

Rename these variables since they're being used for hearing aids too,
and are no longer HFP-specific.

Bug: 116725094
Test: manual, added unit tests
Change-Id: I7e2c4d0887a7d576c1b7b757c47d9ebf8119d57a
parent e3d2d562
Loading
Loading
Loading
Loading
+17 −16
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ 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;
@@ -56,8 +55,8 @@ public class BluetoothRouteManager extends StateMachine {
         put(CONNECT_HFP, "CONNECT_HFP");
         put(DISCONNECT_HFP, "DISCONNECT_HFP");
         put(RETRY_HFP_CONNECTION, "RETRY_HFP_CONNECTION");
         put(HFP_IS_ON, "HFP_IS_ON");
         put(HFP_LOST, "HFP_LOST");
         put(BT_AUDIO_IS_ON, "BT_AUDIO_IS_ON");
         put(BT_AUDIO_LOST, "BT_AUDIO_LOST");
         put(CONNECTION_TIMEOUT, "CONNECTION_TIMEOUT");
         put(GET_CURRENT_STATE, "GET_CURRENT_STATE");
         put(RUN_RUNNABLE, "RUN_RUNNABLE");
@@ -96,9 +95,9 @@ public class BluetoothRouteManager extends StateMachine {
    public static final int RETRY_HFP_CONNECTION = 102;

    // arg2: the address of the device that is on
    public static final int HFP_IS_ON = 200;
    // arg2: the address of the device that lost HFP
    public static final int HFP_LOST = 201;
    public static final int BT_AUDIO_IS_ON = 200;
    // arg2: the address of the device that lost BT audio
    public static final int BT_AUDIO_LOST = 201;

    // No args; only used internally
    public static final int CONNECTION_TIMEOUT = 300;
@@ -178,12 +177,13 @@ public class BluetoothRouteManager extends StateMachine {
                    case CONNECTION_TIMEOUT:
                        // Ignore.
                        break;
                    case HFP_IS_ON:
                    case BT_AUDIO_IS_ON:
                        String address = (String) args.arg2;
                        Log.w(LOG_TAG, "HFP audio unexpectedly turned on from device %s", address);
                        transitionTo(getConnectedStateForAddress(address, "AudioOff/HFP_IS_ON"));
                        transitionTo(getConnectedStateForAddress(address,
                                "AudioOff/BT_AUDIO_IS_ON"));
                        break;
                    case HFP_LOST:
                    case BT_AUDIO_LOST:
                        Log.i(LOG_TAG, "Received HFP off for device %s while HFP off.",
                                (String) args.arg2);
                        break;
@@ -284,7 +284,7 @@ public class BluetoothRouteManager extends StateMachine {
                                mDeviceAddress);
                        transitionToActualState();
                        break;
                    case HFP_IS_ON:
                    case BT_AUDIO_IS_ON:
                        if (Objects.equals(mDeviceAddress, address)) {
                            Log.i(LOG_TAG, "HFP connection success for device %s.", mDeviceAddress);
                            transitionTo(mAudioConnectedStates.get(mDeviceAddress));
@@ -292,10 +292,10 @@ public class BluetoothRouteManager extends StateMachine {
                            Log.w(LOG_TAG, "In connecting state for device %s but %s" +
                                    " is now connected", mDeviceAddress, address);
                            transitionTo(getConnectedStateForAddress(address,
                                    "AudioConnecting/HFP_IS_ON"));
                                    "AudioConnecting/BT_AUDIO_IS_ON"));
                        }
                        break;
                    case HFP_LOST:
                    case BT_AUDIO_LOST:
                        if (Objects.equals(mDeviceAddress, address)) {
                            Log.i(LOG_TAG, "Connection with device %s failed.",
                                    mDeviceAddress);
@@ -394,17 +394,18 @@ public class BluetoothRouteManager extends StateMachine {
                    case CONNECTION_TIMEOUT:
                        Log.w(LOG_TAG, "Received CONNECTION_TIMEOUT while connected.");
                        break;
                    case HFP_IS_ON:
                    case BT_AUDIO_IS_ON:
                        if (Objects.equals(mDeviceAddress, address)) {
                            Log.i(LOG_TAG, "Received redundant HFP_IS_ON for %s", mDeviceAddress);
                            Log.i(LOG_TAG,
                                    "Received redundant BT_AUDIO_IS_ON for %s", mDeviceAddress);
                        } else {
                            Log.w(LOG_TAG, "In connected state for device %s but %s" +
                                    " is now connected", mDeviceAddress, address);
                            transitionTo(getConnectedStateForAddress(address,
                                    "AudioConnected/HFP_IS_ON"));
                                    "AudioConnected/BT_AUDIO_IS_ON"));
                        }
                        break;
                    case HFP_LOST:
                    case BT_AUDIO_LOST:
                        if (Objects.equals(mDeviceAddress, address)) {
                            Log.i(LOG_TAG, "HFP connection with device %s lost.", mDeviceAddress);
                            transitionToActualState();
+6 −6
Original line number Diff line number Diff line
@@ -29,8 +29,8 @@ import android.telecom.Logging.Session;

import com.android.internal.os.SomeArgs;

import static com.android.server.telecom.bluetooth.BluetoothRouteManager.HFP_IS_ON;
import static com.android.server.telecom.bluetooth.BluetoothRouteManager.HFP_LOST;
import static com.android.server.telecom.bluetooth.BluetoothRouteManager.BT_AUDIO_IS_ON;
import static com.android.server.telecom.bluetooth.BluetoothRouteManager.BT_AUDIO_LOST;


public class BluetoothStateReceiver extends BroadcastReceiver {
@@ -97,10 +97,10 @@ public class BluetoothStateReceiver extends BroadcastReceiver {
        args.arg2 = device.getAddress();
        switch (bluetoothHeadsetAudioState) {
            case BluetoothHeadset.STATE_AUDIO_CONNECTED:
                mBluetoothRouteManager.sendMessage(HFP_IS_ON, args);
                mBluetoothRouteManager.sendMessage(BT_AUDIO_IS_ON, args);
                break;
            case BluetoothHeadset.STATE_AUDIO_DISCONNECTED:
                mBluetoothRouteManager.sendMessage(HFP_LOST, args);
                mBluetoothRouteManager.sendMessage(BT_AUDIO_LOST, args);
                break;
        }
    }
@@ -144,10 +144,10 @@ public class BluetoothStateReceiver extends BroadcastReceiver {
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = session;
            if (device == null) {
                mBluetoothRouteManager.sendMessage(HFP_LOST, args);
                mBluetoothRouteManager.sendMessage(BT_AUDIO_LOST, args);
            } else {
                args.arg2 = device.getAddress();
                mBluetoothRouteManager.sendMessage(HFP_IS_ON, args);
                mBluetoothRouteManager.sendMessage(BT_AUDIO_IS_ON, args);
            }
        }
    }
+6 −6
Original line number Diff line number Diff line
@@ -265,7 +265,7 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
                SomeArgs args = SomeArgs.obtain();
                args.arg1 = Log.createSubsession();
                args.arg2 = mParams.initialDevice.getAddress();
                sm.sendMessage(BluetoothRouteManager.HFP_LOST, args);
                sm.sendMessage(BluetoothRouteManager.BT_AUDIO_LOST, args);
                when(mHeadsetProxy.getAudioState(eq(mParams.initialDevice)))
                        .thenReturn(BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
                return true;
@@ -403,7 +403,7 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
                .setInitialDevice(DEVICE2)
                .setAudioOnDevice(DEVICE2)
                .setConnectedDevices(DEVICE2, DEVICE1)
                .setMessageType(BluetoothRouteManager.HFP_IS_ON)
                .setMessageType(BluetoothRouteManager.BT_AUDIO_IS_ON)
                .setMessageDevice(DEVICE2)
                .setExpectedListenerUpdates(ListenerUpdate.AUDIO_CONNECTED)
                .setExpectedBluetoothInteraction(NONE)
@@ -417,7 +417,7 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
                .setInitialBluetoothState(BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX)
                .setInitialDevice(DEVICE2)
                .setConnectedDevices(DEVICE2)
                .setMessageType(BluetoothRouteManager.HFP_LOST)
                .setMessageType(BluetoothRouteManager.BT_AUDIO_LOST)
                .setMessageDevice(DEVICE2)
                .setExpectedListenerUpdates(ListenerUpdate.AUDIO_DISCONNECTED)
                .setExpectedBluetoothInteraction(NONE)
@@ -431,7 +431,7 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
                .setInitialBluetoothState(BluetoothRouteManager.AUDIO_CONNECTED_STATE_NAME_PREFIX)
                .setInitialDevice(DEVICE2)
                .setConnectedDevices(DEVICE2, DEVICE1, DEVICE3)
                .setMessageType(BluetoothRouteManager.HFP_LOST)
                .setMessageType(BluetoothRouteManager.BT_AUDIO_LOST)
                .setMessageDevice(DEVICE2)
                .setExpectedListenerUpdates(ListenerUpdate.AUDIO_DISCONNECTED)
                .setExpectedBluetoothInteraction(NONE)
@@ -516,7 +516,7 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
                .setInitialDevice(DEVICE2)
                .setConnectedDevices(DEVICE2, DEVICE1)
                .setAudioOnDevice(DEVICE1)
                .setMessageType(BluetoothRouteManager.HFP_IS_ON)
                .setMessageType(BluetoothRouteManager.BT_AUDIO_IS_ON)
                .setMessageDevice(DEVICE1)
                .setExpectedListenerUpdates(ListenerUpdate.AUDIO_CONNECTED)
                .setExpectedBluetoothInteraction(NONE)
@@ -578,7 +578,7 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
                .setInitialBluetoothState(BluetoothRouteManager.AUDIO_OFF_STATE_NAME)
                .setInitialDevice(null)
                .setConnectedDevices(DEVICE2, DEVICE3)
                .setMessageType(BluetoothRouteManager.HFP_IS_ON)
                .setMessageType(BluetoothRouteManager.BT_AUDIO_IS_ON)
                .setMessageDevice(DEVICE3)
                .setExpectedListenerUpdates(ListenerUpdate.AUDIO_CONNECTED)
                .setExpectedBluetoothInteraction(NONE)