Improved Bluetooth headset connected test

This commit is contained in:
Juha Heinanen
2023-04-14 12:00:28 +03:00
parent 306b25c2af
commit c246d9e702
@@ -1549,14 +1549,13 @@ class BaresipService: Service() {
return audioFocusRequest == null return audioFocusRequest == null
} }
@SuppressLint("MissingPermission")
private fun isBluetoothHeadsetConnected(ctx: Context): Boolean { private fun isBluetoothHeadsetConnected(ctx: Context): Boolean {
return if (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.BLUETOOTH_CONNECT) == if (VERSION.SDK_INT >= 31 &&
PackageManager.PERMISSION_GRANTED) ActivityCompat.checkSelfPermission(ctx, Manifest.permission.BLUETOOTH_CONNECT) ==
btAdapter != null && btAdapter!!.isEnabled && PackageManager.PERMISSION_DENIED)
return false
return btAdapter != null && btAdapter!!.isEnabled &&
btAdapter!!.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothAdapter.STATE_CONNECTED btAdapter!!.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothAdapter.STATE_CONNECTED
else
true
} }
private fun isBluetoothScoOn(am: AudioManager): Boolean { private fun isBluetoothScoOn(am: AudioManager): Boolean {