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

Commit df1dbb41 authored by Bryce Lee's avatar Bryce Lee
Browse files

Implement setting/getting whether audio can be routed to the HFP HF device.

Bug: 25332357
Change-Id: I2d37d082673255a165dad955aa1ca4b9f00d599e
parent 21faf82f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -41,4 +41,6 @@
    <integer name="gatt_high_priority_max_interval">12</integer>
    <integer name="gatt_low_power_min_interval">80</integer>
    <integer name="gatt_low_power_max_interval">100</integer>

    <bool name="headset_client_initial_audio_route_allowed">true</bool>
</resources>
+26 −0
Original line number Diff line number Diff line
@@ -252,6 +252,24 @@ public class HeadsetClientService extends ProfileService {
            return service.getAudioState(device);
        }

        @Override
        public void setAudioRouteAllowed(boolean allowed) {
            HeadsetClientService service = getService();
            if (service != null) {
                service.setAudioRouteAllowed(allowed);
            }
        }

        @Override
        public boolean getAudioRouteAllowed() {
            HeadsetClientService service = getService();
            if (service != null) {
                return service.getAudioRouteAllowed();
            }

            return false;
        }

        @Override
        public boolean connectAudio() {
            HeadsetClientService service = getService();
@@ -543,6 +561,14 @@ public class HeadsetClientService extends ProfileService {
        return mStateMachine.getAudioState(device);
    }

    public void setAudioRouteAllowed(boolean allowed) {
        mStateMachine.setAudioRouteAllowed(allowed);
    }

    public boolean getAudioRouteAllowed() {
        return mStateMachine.getAudioRouteAllowed();
    }

    boolean connectAudio() {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
        if (!mStateMachine.isConnected()) {
+20 −0
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ import java.util.List;
import java.util.Queue;
import java.util.Set;

import com.android.bluetooth.R;

final class HeadsetClientStateMachine extends StateMachine {
    private static final String TAG = "HeadsetClientStateMachine";
    private static final boolean DBG = false;
@@ -142,6 +144,8 @@ final class HeadsetClientStateMachine extends StateMachine {

    private final AudioManager mAudioManager;
    private int mAudioState;
    // Indicates whether audio can be routed to the device.
    private boolean mAudioRouteAllowed;
    private boolean mAudioWbs;
    private final BluetoothAdapter mAdapter;
    private boolean mNativeAvailable;
@@ -1210,6 +1214,9 @@ final class HeadsetClientStateMachine extends StateMachine {
        mAudioState = BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED;
        mAudioWbs = false;

        mAudioRouteAllowed = context.getResources().getBoolean(
                R.bool.headset_client_initial_audio_route_allowed);

        mIndicatorNetworkState = HeadsetClientHalConstants.NETWORK_STATE_NOT_AVAILABLE;
        mIndicatorNetworkType = HeadsetClientHalConstants.SERVICE_TYPE_HOME;
        mIndicatorNetworkSignal = 0;
@@ -2016,6 +2023,11 @@ final class HeadsetClientStateMachine extends StateMachine {
                    mAudioWbs = true;
                    // fall through
                case HeadsetClientHalConstants.AUDIO_STATE_CONNECTED:
                    if (!mAudioRouteAllowed) {
                        sendMessage(HeadsetClientStateMachine.DISCONNECT_AUDIO);
                        break;
                    }

                    mAudioState = BluetoothHeadsetClient.STATE_AUDIO_CONNECTED;
                    // request audio focus for call
                    int newAudioMode = AudioManager.MODE_IN_CALL;
@@ -2365,6 +2377,14 @@ final class HeadsetClientStateMachine extends StateMachine {
        return (getCurrentState() == mAudioOn);
    }

    public void setAudioRouteAllowed(boolean allowed) {
        mAudioRouteAllowed = allowed;
    }

    public boolean getAudioRouteAllowed() {
        return mAudioRouteAllowed;
    }

    synchronized int getAudioState(BluetoothDevice device) {
        if (mCurrentDevice == null || !mCurrentDevice.equals(device)) {
            return BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED;