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

Commit f8c23ee6 authored by Jack He's avatar Jack He
Browse files

HFP: Add isInbandRingingEnabled() API (4/4)

* Use BluetoothHeadset.isInbandRingingEnabled() API to check whether
  in-band ringing is currently enabled in the system when deciding on
  audio routes for ringtone

Bug: 71646213
Test: make, toggle in-band ringing from Development Settings and observe
      whether Telecom service tries to open SCO when there is an
      incoming call

Change-Id: I2657102b5239f52d64f2f82d9b45f712c28bdba7
parent 876223c6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -68,4 +68,8 @@ public class BluetoothHeadsetProxy {
    public boolean disconnectAudio() {
        return mBluetoothHeadset.disconnectAudio();
    }

    public boolean isInbandRingingEnabled() {
        return mBluetoothHeadset.isInbandRingingEnabled();
    }
}
 No newline at end of file
+9 −9
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.telecom;

import android.app.ActivityManager;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.content.Context;
import android.content.pm.UserInfo;
import android.media.AudioDeviceInfo;
@@ -371,7 +370,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                case SWITCH_BLUETOOTH:
                case USER_SWITCH_BLUETOOTH:
                    if ((mAvailableRoutes & ROUTE_BLUETOOTH) != 0) {
                        if (mAudioFocusType == ACTIVE_FOCUS || mIsInbandRingSupported) {
                        if (mAudioFocusType == ACTIVE_FOCUS
                                || mBluetoothRouteManager.isInbandRingingEnabled()) {
                            String address = (msg.obj instanceof SomeArgs) ?
                                    (String) ((SomeArgs) msg.obj).arg2 : null;
                            // Omit transition to ActiveBluetoothRoute
@@ -568,7 +568,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                case SWITCH_BLUETOOTH:
                case USER_SWITCH_BLUETOOTH:
                    if ((mAvailableRoutes & ROUTE_BLUETOOTH) != 0) {
                        if (mAudioFocusType == ACTIVE_FOCUS || mIsInbandRingSupported) {
                        if (mAudioFocusType == ACTIVE_FOCUS
                                || mBluetoothRouteManager.isInbandRingingEnabled()) {
                            String address = (msg.obj instanceof SomeArgs) ?
                                    (String) ((SomeArgs) msg.obj).arg2 : null;
                            // Omit transition to ActiveBluetoothRoute until actual connection.
@@ -793,7 +794,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    if (msg.arg1 == NO_FOCUS) {
                        setBluetoothOff();
                        reinitialize();
                    } else if (msg.arg1 == RINGING_FOCUS && !mIsInbandRingSupported) {
                    } else if (msg.arg1 == RINGING_FOCUS
                            && !mBluetoothRouteManager.isInbandRingingEnabled()) {
                        setBluetoothOff();
                        transitionTo(mRingingBluetoothRoute);
                    }
@@ -954,7 +956,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    if (msg.arg1 == ACTIVE_FOCUS) {
                        setBluetoothOn(null);
                    } else if (msg.arg1 == RINGING_FOCUS) {
                        if (mIsInbandRingSupported) {
                        if (mBluetoothRouteManager.isInbandRingingEnabled()) {
                            setBluetoothOn(null);
                        } else {
                            transitionTo(mRingingBluetoothRoute);
@@ -1065,7 +1067,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    String address = (msg.obj instanceof SomeArgs) ?
                            (String) ((SomeArgs) msg.obj).arg2 : null;
                    if ((mAvailableRoutes & ROUTE_BLUETOOTH) != 0) {
                        if (mAudioFocusType == ACTIVE_FOCUS || mIsInbandRingSupported) {
                        if (mAudioFocusType == ACTIVE_FOCUS
                                || mBluetoothRouteManager.isInbandRingingEnabled()) {
                            // Omit transition to ActiveBluetoothRoute
                            setBluetoothOn(address);
                        } else {
@@ -1257,8 +1260,6 @@ public class CallAudioRouteStateMachine extends StateMachine {
    private CallAudioState mCurrentCallAudioState;
    private CallAudioState mLastKnownCallAudioState;

    private final boolean mIsInbandRingSupported;

    public CallAudioRouteStateMachine(
            Context context,
            CallsManager callsManager,
@@ -1295,7 +1296,6 @@ public class CallAudioRouteStateMachine extends StateMachine {
            default:
                mDoesDeviceSupportEarpieceRoute = checkForEarpieceSupport();
        }
        mIsInbandRingSupported = BluetoothHeadset.isInbandRingingSupported(mContext);
        mLock = callsManager.getLock();

        mStateNameToRouteCode = new HashMap<>(8);
+16 −0
Original line number Diff line number Diff line
@@ -734,6 +734,22 @@ public class BluetoothRouteManager extends StateMachine {
        return null;
    }

    /**
     * Check if in-band ringing is currently enabled. In-band ringing could be disabled during an
     * active connection.
     *
     * @return true if in-band ringing is enabled, false if in-band ringing is disabled
     */
    @VisibleForTesting
    public boolean isInbandRingingEnabled() {
        BluetoothHeadsetProxy bluetoothHeadset = mDeviceManager.getHeadsetService();
        if (bluetoothHeadset == null) {
            Log.i(this, "isInbandRingingEnabled: no headset service available.");
            return false;
        }
        return bluetoothHeadset.isInbandRingingEnabled();
    }

    private boolean connectAudio(String address) {
        BluetoothHeadsetProxy bluetoothHeadset = mDeviceManager.getHeadsetService();
        if (bluetoothHeadset == null) {
+1 −3
Original line number Diff line number Diff line
@@ -1165,9 +1165,7 @@ public class CallAudioRouteStateMachineTest
    }

    private void setInBandRing(boolean enabled) {
        mComponentContextFixture.putBooleanResource(
                com.android.internal.R.bool.config_bluetooth_hfp_inband_ringing_support,
                enabled);
        when(mockBluetoothRouteManager.isInbandRingingEnabled()).thenReturn(enabled);
    }

    private void resetMocks() {