- Fixed toggling of speakerphone in API < 31 devices

- Removed hasCallbacks check
This commit is contained in:
Juha Heinanen
2023-01-25 05:34:03 +02:00
parent 8282faeb17
commit 95589ec80f
3 changed files with 10 additions and 16 deletions

View File

@ -107,14 +107,8 @@ class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: Str
}
fun call(status: String): Call? {
for (c in BaresipService.calls)
if (c.status == status) return c
return null
}
fun connectedCall(): Call? {
for (c in BaresipService.calls.reversed())
if (c.status == "connected") return c
if (c.status == status) return c
return null
}

View File

@ -359,7 +359,7 @@ class MainActivity : AppCompatActivity() {
hangupButton.setOnClickListener {
val ua = BaresipService.uas[aorSpinner.selectedItemPosition]
if (Build.VERSION.SDK_INT < 31) {
if (callRunnable != null && callHandler.hasCallbacks(callRunnable!!)) {
if (callRunnable != null) {
callHandler.removeCallbacks(callRunnable!!)
callRunnable = null
am.mode = AudioManager.MODE_NORMAL
@ -1174,12 +1174,6 @@ class MainActivity : AppCompatActivity() {
if (acc.missedCalls)
callsButton.setImageResource(R.drawable.calls_missed)
}
Handler(Looper.getMainLooper()).postDelayed({
if (Utils.isSpeakerPhoneOn(am))
speakerIcon!!.setIcon(R.drawable.speaker_on)
else
speakerIcon!!.setIcon(R.drawable.speaker_off)
}, 750)
if ((Build.VERSION.SDK_INT >= 22 && kgm.isDeviceLocked) ||
(Build.VERSION.SDK_INT < 22 && kgm.isKeyguardLocked && kgm.isKeyguardSecure))
Utils.setShowWhenLocked(this, false)
@ -1264,7 +1258,13 @@ class MainActivity : AppCompatActivity() {
}
R.id.speakerIcon -> {
Utils.toggleSpeakerPhone(mainExecutor, am)
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(this), am)
if (Build.VERSION.SDK_INT < 31 && speakerIcon != null) {
if (am.isSpeakerphoneOn)
speakerIcon!!.setIcon(R.drawable.speaker_on)
else
speakerIcon!!.setIcon(R.drawable.speaker_off)
}
}
R.id.config -> {

View File

@ -942,7 +942,7 @@ object Utils {
"${AudioDeviceInfo.TYPE_BUILTIN_EARPIECE} in mode ${am.mode}")
am.clearCommunicationDevice()
// Restore communication mode
if (Call.connectedCall() != null && am.mode == AudioManager.MODE_NORMAL)
if (Call.call("connected") != null && am.mode == AudioManager.MODE_NORMAL)
am.mode = AudioManager.MODE_IN_COMMUNICATION
Log.d(TAG, "Type of current device is ${am.communicationDevice!!.type}")
} else {