mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 21:48:50 +03:00
Merge pull request #2174 from lomion0815/fix_2100_2
Fix for #2100 and #2246:: Using Ringtone class to control ringtones for incoming calls.
This commit is contained in:
commit
a50bd7421c
4 changed files with 45 additions and 13 deletions
|
@ -20,6 +20,7 @@ Improvements 🙌:
|
||||||
- Considerably faster QR-code bitmap generation (#2331)
|
- Considerably faster QR-code bitmap generation (#2331)
|
||||||
|
|
||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
|
- Fixed ringtone handling (#2100 & #2246)
|
||||||
- Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252)
|
- Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252)
|
||||||
- Search Result | scroll jumps after pagination (#2238)
|
- Search Result | scroll jumps after pagination (#2238)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
package im.vector.app.core.services
|
package im.vector.app.core.services
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.media.Ringtone
|
||||||
|
import android.media.RingtoneManager
|
||||||
import android.media.AudioAttributes
|
import android.media.AudioAttributes
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
|
@ -25,7 +27,26 @@ import androidx.core.content.getSystemService
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class CallRingPlayer(
|
class CallRingPlayerIncoming(
|
||||||
|
context: Context
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val applicationContext = context.applicationContext
|
||||||
|
private var r: Ringtone? = null
|
||||||
|
|
||||||
|
fun start() {
|
||||||
|
val notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)
|
||||||
|
r = RingtoneManager.getRingtone(applicationContext, notification)
|
||||||
|
Timber.v("## VOIP Starting ringing incomming")
|
||||||
|
r?.play()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stop() {
|
||||||
|
r?.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CallRingPlayerOutgoing(
|
||||||
context: Context
|
context: Context
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -44,12 +65,12 @@ class CallRingPlayer(
|
||||||
try {
|
try {
|
||||||
if (player?.isPlaying == false) {
|
if (player?.isPlaying == false) {
|
||||||
player?.start()
|
player?.start()
|
||||||
Timber.v("## VOIP Starting ringing")
|
Timber.v("## VOIP Starting ringing outgoing")
|
||||||
} else {
|
} else {
|
||||||
Timber.v("## VOIP already playing")
|
Timber.v("## VOIP already playing")
|
||||||
}
|
}
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
Timber.e(failure, "## VOIP Failed to start ringing")
|
Timber.e(failure, "## VOIP Failed to start ringing outgoing")
|
||||||
player = null
|
player = null
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,7 +95,7 @@ class CallRingPlayer(
|
||||||
} else {
|
} else {
|
||||||
mediaPlayer.setAudioAttributes(AudioAttributes.Builder()
|
mediaPlayer.setAudioAttributes(AudioAttributes.Builder()
|
||||||
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
|
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
|
||||||
.setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING)
|
.setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
|
||||||
.build())
|
.build())
|
||||||
}
|
}
|
||||||
return mediaPlayer
|
return mediaPlayer
|
||||||
|
|
|
@ -40,7 +40,8 @@ class CallService : VectorService(), WiredHeadsetStateReceiver.HeadsetEventListe
|
||||||
private lateinit var notificationUtils: NotificationUtils
|
private lateinit var notificationUtils: NotificationUtils
|
||||||
private lateinit var webRtcPeerConnectionManager: WebRtcPeerConnectionManager
|
private lateinit var webRtcPeerConnectionManager: WebRtcPeerConnectionManager
|
||||||
|
|
||||||
private var callRingPlayer: CallRingPlayer? = null
|
private var callRingPlayerIncoming: CallRingPlayerIncoming? = null
|
||||||
|
private var callRingPlayerOutgoing: CallRingPlayerOutgoing? = null
|
||||||
|
|
||||||
private var wiredHeadsetStateReceiver: WiredHeadsetStateReceiver? = null
|
private var wiredHeadsetStateReceiver: WiredHeadsetStateReceiver? = null
|
||||||
private var bluetoothHeadsetStateReceiver: BluetoothHeadsetReceiver? = null
|
private var bluetoothHeadsetStateReceiver: BluetoothHeadsetReceiver? = null
|
||||||
|
@ -63,14 +64,16 @@ class CallService : VectorService(), WiredHeadsetStateReceiver.HeadsetEventListe
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
notificationUtils = vectorComponent().notificationUtils()
|
notificationUtils = vectorComponent().notificationUtils()
|
||||||
webRtcPeerConnectionManager = vectorComponent().webRtcPeerConnectionManager()
|
webRtcPeerConnectionManager = vectorComponent().webRtcPeerConnectionManager()
|
||||||
callRingPlayer = CallRingPlayer(applicationContext)
|
callRingPlayerIncoming = CallRingPlayerIncoming(applicationContext)
|
||||||
|
callRingPlayerOutgoing = CallRingPlayerOutgoing(applicationContext)
|
||||||
wiredHeadsetStateReceiver = WiredHeadsetStateReceiver.createAndRegister(this, this)
|
wiredHeadsetStateReceiver = WiredHeadsetStateReceiver.createAndRegister(this, this)
|
||||||
bluetoothHeadsetStateReceiver = BluetoothHeadsetReceiver.createAndRegister(this, this)
|
bluetoothHeadsetStateReceiver = BluetoothHeadsetReceiver.createAndRegister(this, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
callRingPlayer?.stop()
|
callRingPlayerIncoming?.stop()
|
||||||
|
callRingPlayerOutgoing?.stop()
|
||||||
wiredHeadsetStateReceiver?.let { WiredHeadsetStateReceiver.unRegister(this, it) }
|
wiredHeadsetStateReceiver?.let { WiredHeadsetStateReceiver.unRegister(this, it) }
|
||||||
wiredHeadsetStateReceiver = null
|
wiredHeadsetStateReceiver = null
|
||||||
bluetoothHeadsetStateReceiver?.let { BluetoothHeadsetReceiver.unRegister(this, it) }
|
bluetoothHeadsetStateReceiver?.let { BluetoothHeadsetReceiver.unRegister(this, it) }
|
||||||
|
@ -100,16 +103,17 @@ class CallService : VectorService(), WiredHeadsetStateReceiver.HeadsetEventListe
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
ACTION_INCOMING_RINGING_CALL -> {
|
ACTION_INCOMING_RINGING_CALL -> {
|
||||||
mediaSession?.isActive = true
|
mediaSession?.isActive = true
|
||||||
callRingPlayer?.start()
|
callRingPlayerIncoming?.start()
|
||||||
displayIncomingCallNotification(intent)
|
displayIncomingCallNotification(intent)
|
||||||
}
|
}
|
||||||
ACTION_OUTGOING_RINGING_CALL -> {
|
ACTION_OUTGOING_RINGING_CALL -> {
|
||||||
mediaSession?.isActive = true
|
mediaSession?.isActive = true
|
||||||
callRingPlayer?.start()
|
callRingPlayerOutgoing?.start()
|
||||||
displayOutgoingRingingCallNotification(intent)
|
displayOutgoingRingingCallNotification(intent)
|
||||||
}
|
}
|
||||||
ACTION_ONGOING_CALL -> {
|
ACTION_ONGOING_CALL -> {
|
||||||
callRingPlayer?.stop()
|
callRingPlayerIncoming?.stop()
|
||||||
|
callRingPlayerOutgoing?.stop()
|
||||||
displayCallInProgressNotification(intent)
|
displayCallInProgressNotification(intent)
|
||||||
}
|
}
|
||||||
ACTION_NO_ACTIVE_CALL -> hideCallNotifications()
|
ACTION_NO_ACTIVE_CALL -> hideCallNotifications()
|
||||||
|
@ -117,7 +121,8 @@ class CallService : VectorService(), WiredHeadsetStateReceiver.HeadsetEventListe
|
||||||
// lower notification priority
|
// lower notification priority
|
||||||
displayCallInProgressNotification(intent)
|
displayCallInProgressNotification(intent)
|
||||||
// stop ringing
|
// stop ringing
|
||||||
callRingPlayer?.stop()
|
callRingPlayerIncoming?.stop()
|
||||||
|
callRingPlayerOutgoing?.stop()
|
||||||
}
|
}
|
||||||
ACTION_ONGOING_CALL_BG -> {
|
ACTION_ONGOING_CALL_BG -> {
|
||||||
// there is an ongoing call but call activity is in background
|
// there is an ongoing call but call activity is in background
|
||||||
|
@ -125,7 +130,8 @@ class CallService : VectorService(), WiredHeadsetStateReceiver.HeadsetEventListe
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
// Should not happen
|
// Should not happen
|
||||||
callRingPlayer?.stop()
|
callRingPlayerIncoming?.stop()
|
||||||
|
callRingPlayerOutgoing?.stop()
|
||||||
myStopSelf()
|
myStopSelf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,10 @@ class CallAudioManager(
|
||||||
|
|
||||||
fun startForCall(mxCall: MxCall) {
|
fun startForCall(mxCall: MxCall) {
|
||||||
Timber.v("## VOIP: AudioManager startForCall ${mxCall.callId}")
|
Timber.v("## VOIP: AudioManager startForCall ${mxCall.callId}")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupAudioManager(mxCall: MxCall) {
|
||||||
|
Timber.v("## VOIP: AudioManager setupAudioManager ${mxCall.callId}")
|
||||||
val audioManager = audioManager ?: return
|
val audioManager = audioManager ?: return
|
||||||
savedIsSpeakerPhoneOn = audioManager.isSpeakerphoneOn
|
savedIsSpeakerPhoneOn = audioManager.isSpeakerphoneOn
|
||||||
savedIsMicrophoneMute = audioManager.isMicrophoneMute
|
savedIsMicrophoneMute = audioManager.isMicrophoneMute
|
||||||
|
@ -150,7 +154,7 @@ class CallAudioManager(
|
||||||
|
|
||||||
fun onCallConnected(mxCall: MxCall) {
|
fun onCallConnected(mxCall: MxCall) {
|
||||||
Timber.v("##VOIP: AudioManager call answered, adjusting current sound device")
|
Timber.v("##VOIP: AudioManager call answered, adjusting current sound device")
|
||||||
adjustCurrentSoundDevice(mxCall)
|
setupAudioManager(mxCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAvailableSoundDevices(): List<SoundDevice> {
|
fun getAvailableSoundDevices(): List<SoundDevice> {
|
||||||
|
|
Loading…
Reference in a new issue