More bluetooth related fixes and improvements
This commit is contained in:
@ -13,6 +13,7 @@ import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager
|
||||
import android.database.ContentObserver
|
||||
import android.media.*
|
||||
import android.media.AudioManager.MODE_IN_COMMUNICATION
|
||||
import android.media.AudioManager.MODE_NORMAL
|
||||
import android.media.AudioManager.RINGER_MODE_SILENT
|
||||
import android.net.*
|
||||
@ -46,7 +47,6 @@ import java.util.*
|
||||
import kotlin.concurrent.schedule
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
class BaresipService: Service() {
|
||||
|
||||
internal lateinit var intent: Intent
|
||||
@ -246,23 +246,13 @@ class BaresipService: Service() {
|
||||
when (state) {
|
||||
BluetoothHeadset.STATE_CONNECTED -> {
|
||||
Log.d(TAG, "Bluetooth headset is connected")
|
||||
if (audioFocusRequest != null) {
|
||||
//Handler(Looper.getMainLooper()).postDelayed({
|
||||
//am.startBluetoothSco()
|
||||
startBluetoothSco(am, 1000L)
|
||||
|
||||
//}, 1000)
|
||||
}
|
||||
//Timer("Sco", false).schedule(1000) {
|
||||
// startBluetoothSco(am)
|
||||
// }
|
||||
if (audioFocusRequest != null)
|
||||
startBluetoothSco(am, 1000L, 3)
|
||||
}
|
||||
BluetoothHeadset.STATE_DISCONNECTED -> {
|
||||
Log.d(TAG, "Bluetooth headset is disconnected")
|
||||
if (isBluetoothScoOn(am)) {
|
||||
Log.d(TAG, "Stopping Bluetooth SCO")
|
||||
if (audioFocusRequest != null)
|
||||
stopBluetoothSco(am)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -276,9 +266,6 @@ class BaresipService: Service() {
|
||||
}
|
||||
BluetoothHeadset.STATE_AUDIO_DISCONNECTED -> {
|
||||
Log.d(TAG, "Bluetooth headset audio is disconnected")
|
||||
if (isBluetoothScoOn(am)) {
|
||||
stopBluetoothSco(am)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -778,7 +765,9 @@ class BaresipService: Service() {
|
||||
}
|
||||
"call established" -> {
|
||||
nm.cancel(CALL_NOTIFICATION_ID)
|
||||
Log.d(TAG, "AoR $aor call $callp established")
|
||||
Log.d(TAG, "AoR $aor call $callp established in mode ${am.mode}")
|
||||
if (am.mode != MODE_IN_COMMUNICATION)
|
||||
am.mode = MODE_IN_COMMUNICATION
|
||||
call!!.status = "connected"
|
||||
call.onhold = false
|
||||
if (ua.account.callHistory)
|
||||
@ -1571,7 +1560,7 @@ class BaresipService: Service() {
|
||||
isAudioFocused = true
|
||||
if (isBluetoothHeadsetConnected(ctx) /* && !am.isBluetoothScoOn */) {
|
||||
Log.d(TAG, "Starting Bluetooth SCO")
|
||||
startBluetoothSco(am, 0L)
|
||||
startBluetoothSco(am, 10L, 1)
|
||||
}
|
||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||
//if (type == AudioAttributes.CONTENT_TYPE_SPEECH || isBluetoothHeadsetConnected(ctx))
|
||||
@ -1616,26 +1605,23 @@ class BaresipService: Service() {
|
||||
false
|
||||
}
|
||||
|
||||
private fun startBluetoothSco(am: AudioManager, delay: Long) {
|
||||
Log.d(TAG, "Starting Bluetooth SCO")
|
||||
private fun startBluetoothSco(am: AudioManager, delay: Long, count: Int) {
|
||||
Log.d(TAG, "Starting Bluetooth SCO at count $count")
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
if (VERSION.SDK_INT < 35)
|
||||
if (VERSION.SDK_INT < 31) {
|
||||
am.startBluetoothSco()
|
||||
else
|
||||
} else {
|
||||
Utils.setCommunicationDevice(am, AudioDeviceInfo.TYPE_BLUETOOTH_SCO)
|
||||
if (!isBluetoothScoOn(am)) {
|
||||
Log.d(TAG, "Trying to start Bluetooth SCO again")
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
am.startBluetoothSco()
|
||||
}, delay)
|
||||
}
|
||||
if (!isBluetoothScoOn(am) && count > 1)
|
||||
startBluetoothSco(am, delay, count - 1)
|
||||
}, delay)
|
||||
}
|
||||
|
||||
private fun stopBluetoothSco(am: AudioManager) {
|
||||
Log.d(TAG, "Stopping Bluetooth SCO")
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
if (VERSION.SDK_INT < 35)
|
||||
if (VERSION.SDK_INT < 31)
|
||||
am.stopBluetoothSco()
|
||||
else
|
||||
am.clearCommunicationDevice()
|
||||
|
||||
@ -680,18 +680,8 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
requestPermissionsLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { isGranted: Map<String, Boolean> ->
|
||||
Log.e(TAG, "********** isGranted $isGranted")
|
||||
if (firstRun && isGranted.isEmpty()) {
|
||||
with(MaterialAlertDialogBuilder(this, R.style.AlertDialogTheme)) {
|
||||
setTitle("Permissions")
|
||||
setMessage(getString(R.string.mic_and_bluetooth))
|
||||
setPositiveButton(getString(R.string.ok)) { dialog, _ ->
|
||||
requestPermissionsLauncher.launch(arrayOf(RECORD_AUDIO, BLUETOOTH_CONNECT))
|
||||
dialog.dismiss()
|
||||
}
|
||||
show()
|
||||
}
|
||||
}
|
||||
if (firstRun && isGranted.isEmpty())
|
||||
askMicAndBtPermissions()
|
||||
}
|
||||
|
||||
if (Preferences(applicationContext).displayTheme != AppCompatDelegate.getDefaultNightMode()) {
|
||||
@ -707,31 +697,12 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
if (!Utils.checkPermissions(this, arrayOf(RECORD_AUDIO, BLUETOOTH_CONNECT)))
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, RECORD_AUDIO) ||
|
||||
ActivityCompat.shouldShowRequestPermissionRationale(this, BLUETOOTH_CONNECT)) {
|
||||
layout.showSnackBar(
|
||||
binding.root,
|
||||
if (!Utils.checkPermissions(this, arrayOf(RECORD_AUDIO)) &&
|
||||
!Utils.checkPermissions(this, arrayOf(BLUETOOTH_CONNECT)))
|
||||
getString(R.string.mic_and_bluetooth)
|
||||
else if (!Utils.checkPermissions(this, arrayOf(RECORD_AUDIO)))
|
||||
getString(R.string.no_calls)
|
||||
else
|
||||
getString(R.string.no_bluetooth),
|
||||
Snackbar.LENGTH_INDEFINITE,
|
||||
getString(R.string.ok)
|
||||
) {
|
||||
requestPermissionsLauncher.launch(arrayOf(RECORD_AUDIO, BLUETOOTH_CONNECT))
|
||||
}
|
||||
ActivityCompat.shouldShowRequestPermissionRationale(this, BLUETOOTH_CONNECT)) {
|
||||
askMicAndBtPermissions()
|
||||
} else {
|
||||
requestPermissionsLauncher.launch(
|
||||
arrayOf(
|
||||
RECORD_AUDIO,
|
||||
BLUETOOTH_CONNECT
|
||||
)
|
||||
requestPermissionsLauncher.launch(arrayOf(RECORD_AUDIO, BLUETOOTH_CONNECT)
|
||||
)
|
||||
}
|
||||
else
|
||||
Log.e(TAG, "********** all permissions granted")
|
||||
|
||||
val action = intent.getStringExtra("action")
|
||||
if (action != null) {
|
||||
@ -845,6 +816,18 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun askMicAndBtPermissions() {
|
||||
with(MaterialAlertDialogBuilder(this, R.style.AlertDialogTheme)) {
|
||||
setTitle(getString(R.string.permissions_rationale))
|
||||
setMessage(getString(R.string.mic_and_bt_permissions))
|
||||
setPositiveButton(getString(R.string.ok)) { dialog, _ ->
|
||||
requestPermissionsLauncher.launch(arrayOf(RECORD_AUDIO, BLUETOOTH_CONNECT))
|
||||
dialog.dismiss()
|
||||
}
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun callAction(intent: Intent) {
|
||||
if (Call.calls().isNotEmpty() || BaresipService.uas.size == 0)
|
||||
return
|
||||
|
||||
@ -503,8 +503,7 @@
|
||||
<string name="call_already_active">Sinulla on jo puhelu käynnissä.</string>
|
||||
<string name="start_failed">Sovelluksen käynnistäminen epäonnistui. Tämä voi johtua virheellisestä
|
||||
Asetukset arvosta. Tarkista Kuunteluosoite, TLS-varmennintiedosto ja TLS CA-tiedosto.
|
||||
Sen jälkeen käynnistä baresip uudelleen.
|
||||
</string>
|
||||
Sen jälkeen käynnistä baresip uudelleen.</string>
|
||||
<string name="registering_failed">Tilin \'%1$s\' rekisteröinti epäonnistui.</string>
|
||||
<string name="verify">Todennuspyyntö</string>
|
||||
<string name="verify_sas">Todennatko SAS:n <%1$s>\?</string>
|
||||
@ -513,27 +512,22 @@
|
||||
<string name="call_failed">Puhelu epäonnistui</string>
|
||||
<string name="call_closed">Puhelu on päättynyt</string>
|
||||
<string name="call_not_secure">Tämä puhelu EI ole turvallinen!</string>
|
||||
<string name="peer_not_verified">Tämä puhelu on turvallinen, mutta
|
||||
kohdetta ei ole todennettu!
|
||||
</string>
|
||||
<string name="peer_not_verified">Tämä puhelu on turvallinen, mutta kohdetta ei ole
|
||||
todennettu!</string>
|
||||
<string name="call_is_secure">Tämä pulelu on turvallinen ja kohde on
|
||||
todennettu! Haluatko poistaa todennuksen\?</string>
|
||||
<string name="unverify">Poista todennus</string>
|
||||
<string name="backed_up">Sovelluksen tiedot talletettiin tiedostoon \'%1$s\'. Android
|
||||
versioon 9 saakka tiedosto löytyy Download-kansiosta.
|
||||
</string>
|
||||
versioon 9 saakka tiedosto löytyy Download-kansiosta.</string>
|
||||
<string name="backup_failed">Sovelluksen tietojen talletus epäonnistui. Android versioon 9 saakka
|
||||
Tarkista Asetukset → Sovellukset → baresip → Käyttöluvat → Tallennustila.
|
||||
</string>
|
||||
Tarkista Asetukset → Sovellukset → baresip → Käyttöluvat → Tallennustila.</string>
|
||||
<string name="restart_request">Uudelleenkäynnistyspyyntö</string>
|
||||
<string name="restored">Sovelluksen tiedot palautettiin. baresip pitää käynnistää
|
||||
uudelleen. Käynnistä uudelleen nyt\?
|
||||
</string>
|
||||
uudelleen. Käynnistä uudelleen nyt\?</string>
|
||||
<string name="restore_failed">Sovelluksen tietojen palauttaminen epäonnistui. Tarkista, että
|
||||
annoit oikean salasanan ja että palautustiedosto kuuluu tällä sovellukselle.
|
||||
Android versioon 9 saakka tarkista myös Asetukset → Sovellukset → baresip → Käyttöluvat →
|
||||
Tallennustila ja että tiedosto \'%1$s\' on Download-kansiossa.
|
||||
</string>
|
||||
Tallennustila ja että tiedosto \'%1$s\' on Download-kansiossa.</string>
|
||||
<string name="no_notifications">Et voi käyttää tätä sovellusta ilman Ilmoitukset-lupaa.</string>
|
||||
<string name="no_calls">Et voi soittaa puheluita tai vastata niihin ilman Mikrofoni-lupaa.</string>
|
||||
<string name="no_video_calls">Salli Kamera-lupa jotta voit soittaa videopuheluita ja vastata niihin.</string>
|
||||
@ -544,6 +538,10 @@
|
||||
<string name="no_network">Ei verkkoyhteyttä!</string>
|
||||
<string name="choose_telephony_provider_account">Valitse puhelinpalvelun tarjoava tili</string>
|
||||
<string name="call_details">Puhelutiedot</string>
|
||||
<string name="no_android_contacts">Et voi käyttää Androidin yhteystietoja ilman Yhteystiedot-sovelluslupaa.</string>
|
||||
<string name="no_android_contacts">Et voi käyttää Androidin yhteystietoja ilman Yhteystiedot-lupaa.</string>
|
||||
<string name="audio_focus_denied">Audio fokus evätty!</string>
|
||||
<string name="permissions_rationale">Tarvittavat luvat</string>
|
||||
<string name="mic_and_bt_permissions">baresip tarvitsee Mikrofoni-luvan puheluita varten ja
|
||||
Lähellä olevat laitteet -luvan Bluetooth-mikrofonin/kaiuttimen havaitsemista varten, mikäli
|
||||
sellaista halutaan käyttää.</string>
|
||||
</resources>
|
||||
|
||||
@ -520,6 +520,8 @@
|
||||
<string name="show_password">Show Password</string>
|
||||
<string name="no_network">No network connection!</string>
|
||||
<string name="audio_focus_denied">Audio focus denied!</string>
|
||||
<string name="mic_and_bluetooth">baresip needs \"Microphone\" permission for calls and
|
||||
\"Nearby devices\" permission for Bluetooth detection.</string>
|
||||
<string name="permissions_rationale">Permissions rationale</string>
|
||||
<string name="mic_and_bt_permissions">baresip needs \"Microphone\" permission for voice calls and
|
||||
\"Nearby devices\" permission for Bluetooth microphone/speaker detection if you want to use
|
||||
such a device.</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user