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

Commit e3d2d562 authored by Hall Liu's avatar Hall Liu
Browse files

Tweak hearing aid behavior in Telecom

Add active device cache to be restored after a call
Don't set the active device to null upon ending a call -- only
disconnect SCO if it's active.

Bug: 117244393
Bug: 116725094
Test: unit, manual
Change-Id: Ia34ec7535521565c57f106c9b3ee8de9c6de8231
parent 3177a12f
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -308,6 +308,12 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    mHasUserExplicitlyLeftBluetooth = false;
                    return NOT_HANDLED;
                case SWITCH_FOCUS:
                    // Perform BT hearing aid active device caching/restoration
                    if (mAudioFocusType != NO_FOCUS && msg.arg1 == NO_FOCUS) {
                        mBluetoothRouteManager.restoreHearingAidDevice();
                    } else if (mAudioFocusType == NO_FOCUS && msg.arg1 != NO_FOCUS) {
                        mBluetoothRouteManager.cacheHearingAidDevice();
                    }
                    mAudioFocusType = msg.arg1;
                    return NOT_HANDLED;
                default:
@@ -806,7 +812,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    return HANDLED;
                case SWITCH_FOCUS:
                    if (msg.arg1 == NO_FOCUS) {
                        setBluetoothOff();
                        // Only disconnect SCO audio here instead of routing away from BT entirely.
                        mBluetoothRouteManager.disconnectSco();
                        reinitialize();
                    } else if (msg.arg1 == RINGING_FOCUS
                            && !mBluetoothRouteManager.isInbandRingingEnabled()) {
@@ -1268,7 +1275,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
     */
    private int mDeviceSupportedRoutes;
    private int mAvailableRoutes;
    private int mAudioFocusType;
    private int mAudioFocusType = NO_FOCUS;
    private boolean mWasOnSpeaker;
    private boolean mIsMuted;

+23 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ public class BluetoothDeviceManager {
    private BluetoothRouteManager mBluetoothRouteManager;
    private BluetoothHeadsetProxy mBluetoothHeadsetService;
    private BluetoothHearingAid mBluetoothHearingAidService;
    private BluetoothDevice mBluetoothHearingAidActiveDeviceCache;

    public BluetoothDeviceManager(Context context, BluetoothAdapterProxy bluetoothAdapter) {
        if (bluetoothAdapter != null) {
@@ -224,6 +225,10 @@ public class BluetoothDeviceManager {
                }
            }
        }
        disconnectSco();
    }

    public void disconnectSco() {
        if (mBluetoothHeadsetService == null) {
            Log.w(this, "Trying to disconnect audio but no headset service exists.");
        } else {
@@ -261,4 +266,22 @@ public class BluetoothDeviceManager {
            return false;
        }
    }

    public void cacheHearingAidDevice() {
        if (mBluetoothHearingAidService != null) {
             for (BluetoothDevice device : mBluetoothHearingAidService.getActiveDevices()) {
                 if (device != null) {
                     mBluetoothHearingAidActiveDeviceCache = device;
                 }
             }
        }
    }

    public void restoreHearingAidDevice() {
        if (mBluetoothHearingAidActiveDeviceCache != null && mBluetoothHearingAidService != null) {
            mBluetoothHearingAidService.setActiveDevice(mBluetoothHearingAidActiveDeviceCache);
            mBluetoothHearingAidActiveDeviceCache = null;
        }
    }

}
+12 −0
Original line number Diff line number Diff line
@@ -536,6 +536,18 @@ public class BluetoothRouteManager extends StateMachine {
        sendMessage(DISCONNECT_HFP, args);
    }

    public void disconnectSco() {
        mDeviceManager.disconnectSco();
    }

    public void cacheHearingAidDevice() {
        mDeviceManager.cacheHearingAidDevice();
    }

    public void restoreHearingAidDevice() {
        mDeviceManager.restoreHearingAidDevice();
    }

    public void setListener(BluetoothStateListener listener) {
        mListener = listener;
    }