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

Commit 6333448e authored by Eric Shih's avatar Eric Shih
Browse files

Set connectingTimePolicy to 1 if audio is allowed

Workaround for audio policy make phone connect SCO and right after
disconnect SCO. Currently call state to Active will remove active device
due to connectingTimePolicy is not allowed.

Bug: 277716404
Bug: 267638425
Test: atest BluetoothInstrumentationTests
Change-Id: If0578fb90638197407c6dcbf56c18e94e78b07ba
parent 5e12b233
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -2246,9 +2246,17 @@ public class HeadsetClientStateMachine extends StateMachine {
         *  2. remote device supports audio policy
         */
        if (getForceSetAudioPolicyProperty()) {
            setAudioPolicy(new BluetoothSinkAudioPolicy.Builder(mHsClientAudioPolicy)
            // set call establish policy and connecting policy to POLICY_ALLOWED if allowed=true,
            // otherwise set them to the default values
            int connectingTimePolicy =
                    allowed
                            ? BluetoothSinkAudioPolicy.POLICY_ALLOWED
                            : getConnectingTimePolicyProperty();

            setAudioPolicy(
                    new BluetoothSinkAudioPolicy.Builder(mHsClientAudioPolicy)
                            .setCallEstablishPolicy(establishPolicy)
                    .setActiveDevicePolicyAfterConnection(getConnectingTimePolicyProperty())
                            .setActiveDevicePolicyAfterConnection(connectingTimePolicy)
                            .setInBandRingtonePolicy(getInBandRingtonePolicyProperty())
                            .build());
        } else {
+1 −7
Original line number Diff line number Diff line
@@ -16,10 +16,7 @@

package com.android.bluetooth.hfpclient;

import static android.bluetooth.BluetoothProfile.STATE_CONNECTED;
import static android.bluetooth.BluetoothProfile.STATE_CONNECTING;
import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTED;
import static android.bluetooth.BluetoothProfile.STATE_DISCONNECTING;

import static com.android.bluetooth.hfpclient.HeadsetClientStateMachine.AT_OK;
import static com.android.bluetooth.hfpclient.HeadsetClientStateMachine.ENTER_PRIVATE_MODE;
@@ -58,16 +55,13 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.R;
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.hfp.HeadsetService;
import com.android.bluetooth.hfp.HeadsetStackEvent;

import org.hamcrest.core.AllOf;
import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -935,7 +929,7 @@ public class HeadsetClientStateMachineTest {
        // Expect: Should send +ANDROID=SINKAUDIOPOLICY,1,2,1 to remote
        mHeadsetClientStateMachine.setForceSetAudioPolicyProperty(true);
        mHeadsetClientStateMachine.setAudioRouteAllowed(true);
        verify(mNativeInterface).sendAndroidAt(mTestDevice, "+ANDROID=SINKAUDIOPOLICY,1,2,1");
        verify(mNativeInterface).sendAndroidAt(mTestDevice, "+ANDROID=SINKAUDIOPOLICY,1,1,1");
    }

    @Test