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

Commit 0ab9cc11 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Correct issue with CallAudioRouteController inband ring check.

The existing method being used relied upon BT Device Manger actively
tracking devices, which it no longer does as part of the refactored audio
routing code.

Created a new version that has no dependency on that class tracking.

Test: Ran unit tests.
Test: Manual test for inband ringing.
Flag: com.android.server.telecom.flags.call_audio_communication_device_refactor
Fixes: 391810212
Change-Id: I815d0e106b2bab3c288a7e05e69bafd9b01a8afb
parent 9de798e9
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -938,7 +938,8 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
                    BluetoothDevice device = mBluetoothRoutes.get(route);
                    // Check if in-band ringtone is enabled for the device; if it isn't, move to
                    // inactive route.
                    if (device != null && !mBluetoothRouteManager.isInbandRingEnabled(device)) {
                    if (device != null && !mBluetoothRouteManager
                            .isInbandRingEnabled(route.getType(), device)) {
                        routeTo(false, route);
                    } else {
                        routeTo(true, route);
@@ -946,7 +947,8 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
                } else {
                    // Route is already active.
                    BluetoothDevice device = mBluetoothRoutes.get(mCurrentRoute);
                    if (device != null && !mBluetoothRouteManager.isInbandRingEnabled(device)) {
                    if (device != null && !mBluetoothRouteManager
                            .isInbandRingEnabled(mCurrentRoute.getType(), device)) {
                        routeTo(false, mCurrentRoute);
                    }
                }
@@ -982,8 +984,9 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {

        if (bluetoothRoute != null && bluetoothDevice != null) {
            if (mFocusType == RINGING_FOCUS) {
                routeTo(mBluetoothRouteManager.isInbandRingEnabled(bluetoothDevice) && mIsActive,
                        bluetoothRoute);
                routeTo(mBluetoothRouteManager
                                .isInbandRingEnabled(bluetoothRoute.getType(), bluetoothDevice)
                                && mIsActive, bluetoothRoute);
                mBluetoothAddressForRinging = bluetoothDevice.getAddress();
            } else {
                routeTo(mIsActive, bluetoothRoute);
+28 −0
Original line number Diff line number Diff line
@@ -980,6 +980,34 @@ public class BluetoothDeviceManager {
        return isInbandRingEnabled(activeDevice);
    }

    /**
     * Check if inband ringing is enabled for the specified BT device.
     * This is intended for use by {@link CallAudioRouteController}.
     * @param audioRouteType The BT device type.
     * @param bluetoothDevice The BT device.
     * @return {@code true} if inband ringing is enabled, {@code false} otherwise.
     */
    public boolean isInbandRingEnabled(@AudioRoute.AudioRouteType int audioRouteType,
            BluetoothDevice bluetoothDevice) {
        if (audioRouteType == AudioRoute.TYPE_BLUETOOTH_LE) {
            if (mBluetoothLeAudioService == null) {
                Log.i(this, "isInbandRingingEnabled: no leaudio service available.");
                return false;
            }
            int groupId = mBluetoothLeAudioService.getGroupId(bluetoothDevice);
            return mBluetoothLeAudioService.isInbandRingtoneEnabled(groupId);
        } else {
            if (getBluetoothHeadset() == null) {
                Log.i(this, "isInbandRingingEnabled: no headset service available.");
                return false;
            }
            boolean isEnabled = mBluetoothHeadset.isInbandRingingEnabled();
            Log.i(this, "isInbandRingEnabled: device: %s, isEnabled: %b", bluetoothDevice,
                    isEnabled);
            return isEnabled;
        }
    }

    public boolean isInbandRingEnabled(BluetoothDevice bluetoothDevice) {
        if (mBluetoothRouteManager.isCachedLeAudioDevice(bluetoothDevice)) {
            if (mBluetoothLeAudioService == null) {
+6 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.internal.os.SomeArgs;
import com.android.internal.util.IState;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.server.telecom.AudioRoute;
import com.android.server.telecom.CallAudioCommunicationDeviceTracker;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.Timeouts;
@@ -1179,6 +1180,11 @@ public class BluetoothRouteManager extends StateMachine {
        return mDeviceManager.isInbandRingEnabled(bluetoothDevice);
    }

    public boolean isInbandRingEnabled(@AudioRoute.AudioRouteType int audioRouteType,
            BluetoothDevice bluetoothDevice) {
        return mDeviceManager.isInbandRingEnabled(audioRouteType, bluetoothDevice);
    }

    private boolean addDevice(String address) {
        if (mAudioConnectingStates.containsKey(address)) {
            Log.i(this, "Attempting to add device %s twice.", address);
+6 −3
Original line number Diff line number Diff line
@@ -409,7 +409,8 @@ public class CallAudioRouteControllerTest extends TelecomTestCase {
    @SmallTest
    @Test
    public void testSwitchFocusForBluetoothDeviceSupportInbandRinging() {
        when(mBluetoothRouteManager.isInbandRingEnabled(eq(BLUETOOTH_DEVICE_1))).thenReturn(true);
        when(mBluetoothRouteManager.isInbandRingEnabled(eq(AudioRoute.TYPE_BLUETOOTH_SCO),
                eq(BLUETOOTH_DEVICE_1))).thenReturn(true);

        mController.initialize();
        mController.sendMessageWithSessionInfo(BT_DEVICE_ADDED, AudioRoute.TYPE_BLUETOOTH_SCO,
@@ -910,7 +911,8 @@ public class CallAudioRouteControllerTest extends TelecomTestCase {
    public void testRouteFromBtSwitchInRingingSelected() {
        when(mFeatureFlags.ignoreAutoRouteToWatchDevice()).thenReturn(true);
        when(mBluetoothRouteManager.isWatch(any(BluetoothDevice.class))).thenReturn(true);
        when(mBluetoothRouteManager.isInbandRingEnabled(eq(BLUETOOTH_DEVICE_1))).thenReturn(false);
        when(mBluetoothRouteManager.isInbandRingEnabled(eq(AudioRoute.TYPE_BLUETOOTH_SCO),
                eq(BLUETOOTH_DEVICE_1))).thenReturn(false);

        mController.initialize();
        mController.sendMessageWithSessionInfo(BT_DEVICE_ADDED, AudioRoute.TYPE_BLUETOOTH_SCO,
@@ -1239,7 +1241,8 @@ public class CallAudioRouteControllerTest extends TelecomTestCase {
    @SmallTest
    public void testAbandonCallAudioFocusAfterCallEnd() {
        // Make sure in-band ringing is disabled so that route never becomes active
        when(mBluetoothRouteManager.isInbandRingEnabled(eq(BLUETOOTH_DEVICE_1))).thenReturn(false);
        when(mBluetoothRouteManager.isInbandRingEnabled(eq(AudioRoute.TYPE_BLUETOOTH_SCO),
                eq(BLUETOOTH_DEVICE_1))).thenReturn(false);

        mController.initialize();
        mController.sendMessageWithSessionInfo(BT_DEVICE_ADDED, AudioRoute.TYPE_BLUETOOTH_SCO,