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

Commit 214fffa0 authored by Rahul Sabnis's avatar Rahul Sabnis Committed by Automerger Merge Worker
Browse files

Update Telecom code to account for updated Bluetooth HFP audio state am: 62376fe4 am: b141b357

Original change: https://android-review.googlesource.com/c/platform/packages/services/Telecomm/+/1932965

Change-Id: I84f7c6671e9ee0a1ace2eebcd32fe8349b50f6e5
parents 33dd3ec9 b141b357
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@
    <uses-permission android:name="android.permission.BIND_INCALL_SERVICE"/>
    <uses-permission android:name="android.permission.BIND_INCALL_SERVICE"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED"/>
    <uses-permission android:name="android.permission.BROADCAST_CALLLOG_INFO"/>
    <uses-permission android:name="android.permission.BROADCAST_CALLLOG_INFO"/>
    <uses-permission android:name="android.permission.BROADCAST_PHONE_ACCOUNT_REGISTRATION"/>
    <uses-permission android:name="android.permission.BROADCAST_PHONE_ACCOUNT_REGISTRATION"/>
    <uses-permission android:name="android.permission.CALL_PRIVILEGED"/>
    <uses-permission android:name="android.permission.CALL_PRIVILEGED"/>
+4 −4
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
import android.content.Context;
import android.media.AudioManager;
import android.media.AudioManager;
import android.media.AudioDeviceInfo;
import android.media.AudioDeviceInfo;
@@ -477,10 +478,9 @@ public class BluetoothDeviceManager {
                Log.w(this, "Couldn't set active device to %s", address);
                Log.w(this, "Couldn't set active device to %s", address);
                return false;
                return false;
            }
            }
            if (!mBluetoothHeadset.isAudioOn()) {
            int scoConnectionRequest = mBluetoothHeadset.connectAudio();
                return mBluetoothHeadset.connectAudio();
            return scoConnectionRequest == BluetoothStatusCodes.SUCCESS ||
            }
                scoConnectionRequest == BluetoothStatusCodes.ERROR_AUDIO_DEVICE_ALREADY_CONNECTED;
            return true;
        } else {
        } else {
            Log.w(this, "Attempting to turn on audio for a disconnected device");
            Log.w(this, "Attempting to turn on audio for a disconnected device");
            return false;
            return false;
+2 −1
Original line number Original line Diff line number Diff line
@@ -773,7 +773,8 @@ public class BluetoothRouteManager extends StateMachine {
                hfpAudioOnDevice = device;
                hfpAudioOnDevice = device;
                break;
                break;
            }
            }
            if (bluetoothHeadset.getAudioState(hfpAudioOnDevice)

            if (hfpAudioOnDevice != null && bluetoothHeadset.getAudioState(hfpAudioOnDevice)
                    == BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
                    == BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
                hfpAudioOnDevice = null;
                hfpAudioOnDevice = null;
            } else {
            } else {
+5 −4
Original line number Original line Diff line number Diff line
@@ -20,8 +20,9 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.os.Parcel;
import android.os.Parcel;
import android.telecom.Log;
import android.telecom.Log;
@@ -90,7 +91,7 @@ public class BluetoothRouteManagerTest extends TelecomTestCase {
        setupConnectedDevices(new BluetoothDevice[]{DEVICE1}, null, null, null, null, null);
        setupConnectedDevices(new BluetoothDevice[]{DEVICE1}, null, null, null, null, null);
        when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
        when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
                nullable(ContentResolver.class))).thenReturn(0L);
                nullable(ContentResolver.class))).thenReturn(0L);
        when(mBluetoothHeadset.connectAudio()).thenReturn(false);
        when(mBluetoothHeadset.connectAudio()).thenReturn(BluetoothStatusCodes.ERROR_UNKNOWN);
        executeRoutingAction(sm, BluetoothRouteManager.CONNECT_HFP, DEVICE1.getAddress());
        executeRoutingAction(sm, BluetoothRouteManager.CONNECT_HFP, DEVICE1.getAddress());
        // Wait 3 times: for the first connection attempt, the retry attempt,
        // Wait 3 times: for the first connection attempt, the retry attempt,
        // the second retry, and once more to make sure there are only three attempts.
        // the second retry, and once more to make sure there are only three attempts.
@@ -152,7 +153,7 @@ public class BluetoothRouteManagerTest extends TelecomTestCase {
                              null);
                              null);
        when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
        when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
                nullable(ContentResolver.class))).thenReturn(0L);
                nullable(ContentResolver.class))).thenReturn(0L);
        when(mBluetoothHeadset.connectAudio()).thenReturn(false);
        when(mBluetoothHeadset.connectAudio()).thenReturn(BluetoothStatusCodes.ERROR_UNKNOWN);
        executeRoutingAction(sm, BluetoothRouteManager.CONNECT_HFP, DEVICE2.getAddress());
        executeRoutingAction(sm, BluetoothRouteManager.CONNECT_HFP, DEVICE2.getAddress());
        // Wait 3 times: the first connection attempt is accounted for in executeRoutingAction,
        // Wait 3 times: the first connection attempt is accounted for in executeRoutingAction,
        // so wait twice for the retry attempt, again to make sure there are only three attempts,
        // so wait twice for the retry attempt, again to make sure there are only three attempts,
@@ -234,7 +235,7 @@ public class BluetoothRouteManagerTest extends TelecomTestCase {
        when(mDeviceManager.getBluetoothHearingAid()).thenReturn(mBluetoothHearingAid);
        when(mDeviceManager.getBluetoothHearingAid()).thenReturn(mBluetoothHearingAid);
        when(mDeviceManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter);
        when(mDeviceManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter);
        when(mDeviceManager.getLeAudioService()).thenReturn(mBluetoothLeAudio);
        when(mDeviceManager.getLeAudioService()).thenReturn(mBluetoothLeAudio);
        when(mBluetoothHeadset.connectAudio()).thenReturn(true);
        when(mBluetoothHeadset.connectAudio()).thenReturn(BluetoothStatusCodes.SUCCESS);
        when(mBluetoothAdapter.setActiveDevice(nullable(BluetoothDevice.class),
        when(mBluetoothAdapter.setActiveDevice(nullable(BluetoothDevice.class),
                eq(BluetoothAdapter.ACTIVE_DEVICE_ALL))).thenReturn(true);
                eq(BluetoothAdapter.ACTIVE_DEVICE_ALL))).thenReturn(true);
        when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
        when(mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis(
+3 −2
Original line number Original line Diff line number Diff line
@@ -20,8 +20,9 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.telecom.Log;
import android.telecom.Log;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.SmallTest;
@@ -301,7 +302,7 @@ public class BluetoothRouteTransitionTests extends TelecomTestCase {
                when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.HEADSET)))
                when(mBluetoothAdapter.getActiveDevices(eq(BluetoothProfile.HEADSET)))
                    .thenReturn(Arrays.asList((BluetoothDevice) null));
                    .thenReturn(Arrays.asList((BluetoothDevice) null));
                sm.sendMessage(BluetoothRouteManager.BT_AUDIO_LOST, args);
                sm.sendMessage(BluetoothRouteManager.BT_AUDIO_LOST, args);
                return true;
                return BluetoothStatusCodes.SUCCESS;
            }).when(mDeviceManager).disconnectAudio();
            }).when(mDeviceManager).disconnectAudio();
        }
        }