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

Commit ee8e422f authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Use STREAM_VOICE_CALL instead of STREAM_BLUETOOTH_SCO" into main

parents ac0fc3f6 a6a262d4
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.bluetooth.hfp;
import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;
import static android.Manifest.permission.MODIFY_PHONE_STATE;
import static android.media.audio.Flags.deprecateStreamBtSco;

import static com.android.modules.utils.build.SdkLevel.isAtLeastU;

@@ -447,7 +448,11 @@ public class HeadsetService extends ProfileService {
                                int streamType =
                                        intent.getIntExtra(
                                                AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
                                if (streamType == AudioManager.STREAM_BLUETOOTH_SCO) {
                                int volStream = AudioManager.STREAM_BLUETOOTH_SCO;
                                if (deprecateStreamBtSco()) {
                                    volStream = AudioManager.STREAM_VOICE_CALL;
                                }
                                if (streamType == volStream) {
                                    doForEachConnectedStateMachine(
                                            stateMachine ->
                                                    stateMachine.sendMessage(
+8 −8
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.MODIFY_PHONE_STATE;
import static android.bluetooth.BluetoothDevice.ACCESS_ALLOWED;
import static android.bluetooth.BluetoothDevice.ACCESS_REJECTED;
import static android.media.audio.Flags.deprecateStreamBtSco;

import static com.android.modules.utils.build.SdkLevel.isAtLeastU;

@@ -86,7 +87,7 @@ class HeadsetStateMachine extends StateMachine {
    static final int VOICE_RECOGNITION_STOP = 6;

    // message.obj is an intent AudioManager.ACTION_VOLUME_CHANGED
    // EXTRA_VOLUME_STREAM_TYPE is STREAM_BLUETOOTH_SCO
    // EXTRA_VOLUME_STREAM_TYPE is STREAM_BLUETOOTH_SCO/STREAM_VOICE_CALL
    static final int INTENT_SCO_VOLUME_CHANGED = 7;
    static final int INTENT_CONNECTION_ACCESS_REPLY = 8;
    static final int CALL_STATE_CHANGED = 9;
@@ -1997,14 +1998,13 @@ class HeadsetStateMachine extends StateMachine {
        if (volumeType == HeadsetHalConstants.VOLUME_TYPE_SPK) {
            mSpeakerVolume = volume;
            int flag = (mCurrentState == mAudioOn) ? AudioManager.FLAG_SHOW_UI : 0;
            int currentVol =
                    mSystemInterface
                            .getAudioManager()
                            .getStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO);
            int volStream =
                    deprecateStreamBtSco()
                            ? AudioManager.STREAM_VOICE_CALL
                            : AudioManager.STREAM_BLUETOOTH_SCO;
            int currentVol = mSystemInterface.getAudioManager().getStreamVolume(volStream);
            if (volume != currentVol) {
                mSystemInterface
                        .getAudioManager()
                        .setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO, volume, flag);
                mSystemInterface.getAudioManager().setStreamVolume(volStream, volume, flag);
            }
        } else if (volumeType == HeadsetHalConstants.VOLUME_TYPE_MIC) {
            // Not used currently
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ java_defaults {

    static_libs: [
        "PlatformProperties",
        "android.media.audio-aconfig-exported-java",
        "androidx.media_media",
        "androidx.room_room-migration",
        "androidx.room_room-runtime",
+23 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.bluetooth.hfp;

import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.media.audio.Flags.FLAG_DEPRECATE_STREAM_BT_SCO;

import static org.mockito.Mockito.*;

@@ -37,6 +38,10 @@ import android.os.CancellationSignal;
import android.os.HandlerThread;
import android.os.UserHandle;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
@@ -87,6 +92,9 @@ public class HeadsetStateMachineTest {

    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    private BluetoothAdapter mAdapter;
    private HandlerThread mHandlerThread;
    private HeadsetStateMachine mHeadsetStateMachine;
@@ -1796,6 +1804,7 @@ public class HeadsetStateMachineTest {
        Assert.assertEquals(mHeadsetStateMachine.mMicVolume, 1);
    }

    @RequiresFlagsDisabled(FLAG_DEPRECATE_STREAM_BT_SCO)
    @Test
    public void testProcessVolumeEvent_withVolumeTypeSpk() {
        when(mHeadsetService.getActiveDevice()).thenReturn(mTestDevice);
@@ -1809,6 +1818,20 @@ public class HeadsetStateMachineTest {
        verify(mockAudioManager).setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO, 2, 0);
    }

    @RequiresFlagsEnabled(FLAG_DEPRECATE_STREAM_BT_SCO)
    @Test
    public void testProcessVolumeEvent_withVolumeTypeSpkAndStreamVoiceCall() {
        when(mHeadsetService.getActiveDevice()).thenReturn(mTestDevice);
        AudioManager mockAudioManager = mock(AudioManager.class);
        when(mockAudioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)).thenReturn(1);
        when(mSystemInterface.getAudioManager()).thenReturn(mockAudioManager);

        mHeadsetStateMachine.processVolumeEvent(HeadsetHalConstants.VOLUME_TYPE_SPK, 2);

        Assert.assertEquals(mHeadsetStateMachine.mSpeakerVolume, 2);
        verify(mockAudioManager).setStreamVolume(AudioManager.STREAM_VOICE_CALL, 2, 0);
    }

    @Test
    @EnableFlags({Flags.FLAG_HFP_ALLOW_VOLUME_CHANGE_WITHOUT_SCO})
    public void testVolumeChangeEvent_fromIntentWhenConnected() {
+1 −0
Original line number Diff line number Diff line
@@ -12,3 +12,4 @@ rule com.android.internal.util.** com.android.bluetooth.jarjar.@0
rule com.android.modules.expresslog.** com.android.bluetooth.jarjar.@0
rule com.android.bluetooth.flags.** com.android.bluetooth.jarjar.@0
rule bluetooth.constants.** com.android.bluetooth.jarjar.@0
rule android.media.audio.Flags com.android.bluetooth.jarjar.audio.Flags
Loading