Vibration when incoming call is ringing is now handled by the CoreService in SDK
This commit is contained in:
parent
6ffe3c22e9
commit
63205cb33f
8 changed files with 10 additions and 62 deletions
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
<!-- Needed for full screen intent in incoming call notifications -->
|
<!-- Needed for full screen intent in incoming call notifications -->
|
||||||
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
|
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
|
||||||
<!-- To vibrate while incoming call -->
|
<!-- To vibrate when pressing DTMF keys on numpad -->
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
|
|
@ -30,7 +30,6 @@ import androidx.lifecycle.viewModelScope
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.linphone.LinphoneApplication
|
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
|
@ -149,7 +148,7 @@ class ControlsViewModel : ViewModel() {
|
||||||
somethingClickedEvent.value = Event(true)
|
somethingClickedEvent.value = Event(true)
|
||||||
coreContext.core.currentCall?.sendDtmf(key)
|
coreContext.core.currentCall?.sendDtmf(key)
|
||||||
|
|
||||||
if (vibrator.hasVibrator() && LinphoneApplication.corePreferences.dtmfKeypadVibration) {
|
if (vibrator.hasVibrator() && corePreferences.dtmfKeypadVibration) {
|
||||||
Compatibility.eventVibration(vibrator)
|
Compatibility.eventVibration(vibrator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class CallSettingsViewModel : GenericSettingsViewModel() {
|
||||||
|
|
||||||
val vibrateOnIncomingCallListener = object : SettingListenerStub() {
|
val vibrateOnIncomingCallListener = object : SettingListenerStub() {
|
||||||
override fun onBoolValueChanged(newValue: Boolean) {
|
override fun onBoolValueChanged(newValue: Boolean) {
|
||||||
prefs.vibrateWhileIncomingCall = newValue
|
core.isVibrationOnIncomingCallEnabled = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val vibrateOnIncomingCall = MutableLiveData<Boolean>()
|
val vibrateOnIncomingCall = MutableLiveData<Boolean>()
|
||||||
|
@ -155,7 +155,7 @@ class CallSettingsViewModel : GenericSettingsViewModel() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
deviceRingtone.value = core.ring == null
|
deviceRingtone.value = core.ring == null
|
||||||
vibrateOnIncomingCall.value = prefs.vibrateWhileIncomingCall
|
vibrateOnIncomingCall.value = core.isVibrationOnIncomingCallEnabled
|
||||||
|
|
||||||
initEncryptionList()
|
initEncryptionList()
|
||||||
encryptionMandatory.value = core.isMediaEncryptionMandatory
|
encryptionMandatory.value = core.isMediaEncryptionMandatory
|
||||||
|
|
|
@ -56,11 +56,6 @@ class Api21Compatibility {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
fun vibrate(vibrator: Vibrator) {
|
|
||||||
val pattern = longArrayOf(0, 1000, 1000)
|
|
||||||
vibrator.vibrate(pattern, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun eventVibration(vibrator: Vibrator) {
|
fun eventVibration(vibrator: Vibrator) {
|
||||||
val pattern = longArrayOf(0, 100, 100)
|
val pattern = longArrayOf(0, 100, 100)
|
||||||
vibrator.vibrate(pattern, -1)
|
vibrator.vibrate(pattern, -1)
|
||||||
|
|
|
@ -116,14 +116,6 @@ class Api26Compatibility {
|
||||||
return WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
|
return WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
|
||||||
}
|
}
|
||||||
|
|
||||||
fun vibrate(vibrator: Vibrator) {
|
|
||||||
val effect = VibrationEffect.createWaveform(longArrayOf(0L, 1000L, 1000L), intArrayOf(0, VibrationEffect.DEFAULT_AMPLITUDE, 0), 1)
|
|
||||||
val audioAttrs = AudioAttributes.Builder()
|
|
||||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
|
|
||||||
.build()
|
|
||||||
vibrator.vibrate(effect, audioAttrs)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun eventVibration(vibrator: Vibrator) {
|
fun eventVibration(vibrator: Vibrator) {
|
||||||
val effect = VibrationEffect.createWaveform(longArrayOf(0L, 100L, 100L), intArrayOf(0, VibrationEffect.DEFAULT_AMPLITUDE, 0), -1)
|
val effect = VibrationEffect.createWaveform(longArrayOf(0L, 100L, 100L), intArrayOf(0, VibrationEffect.DEFAULT_AMPLITUDE, 0), -1)
|
||||||
val audioAttrs = AudioAttributes.Builder()
|
val audioAttrs = AudioAttributes.Builder()
|
||||||
|
|
|
@ -114,14 +114,6 @@ class Compatibility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun vibrate(vibrator: Vibrator) {
|
|
||||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
|
||||||
Api26Compatibility.vibrate(vibrator)
|
|
||||||
} else {
|
|
||||||
Api21Compatibility.vibrate(vibrator)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun eventVibration(vibrator: Vibrator) {
|
fun eventVibration(vibrator: Vibrator) {
|
||||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||||
Api26Compatibility.eventVibration(vibrator)
|
Api26Compatibility.eventVibration(vibrator)
|
||||||
|
|
|
@ -23,10 +23,8 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.graphics.PixelFormat
|
import android.graphics.PixelFormat
|
||||||
import android.media.AudioManager
|
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.Vibrator
|
|
||||||
import android.security.keystore.KeyGenParameterSpec
|
import android.security.keystore.KeyGenParameterSpec
|
||||||
import android.security.keystore.KeyProperties
|
import android.security.keystore.KeyProperties
|
||||||
import android.telephony.PhoneStateListener
|
import android.telephony.PhoneStateListener
|
||||||
|
@ -130,7 +128,6 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
private var overlayX = 0f
|
private var overlayX = 0f
|
||||||
private var overlayY = 0f
|
private var overlayY = 0f
|
||||||
private var callOverlay: View? = null
|
private var callOverlay: View? = null
|
||||||
private var isVibrating = false
|
|
||||||
private var previousCallState = Call.State.Idle
|
private var previousCallState = Call.State.Idle
|
||||||
|
|
||||||
private val listener: CoreListenerStub = object : CoreListenerStub() {
|
private val listener: CoreListenerStub = object : CoreListenerStub() {
|
||||||
|
@ -167,19 +164,6 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core.callsNb == 1 && corePreferences.vibrateWhileIncomingCall) {
|
|
||||||
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
|
||||||
if ((audioManager.ringerMode == AudioManager.RINGER_MODE_VIBRATE ||
|
|
||||||
audioManager.ringerMode == AudioManager.RINGER_MODE_NORMAL)) {
|
|
||||||
val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
|
||||||
if (vibrator.hasVibrator()) {
|
|
||||||
Log.i("[Context] Starting incoming call vibration")
|
|
||||||
Compatibility.vibrate(vibrator)
|
|
||||||
isVibrating = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Starting SDK 24 (Android 7.0) we rely on the fullscreen intent of the call incoming notification
|
// Starting SDK 24 (Android 7.0) we rely on the fullscreen intent of the call incoming notification
|
||||||
if (Version.sdkStrictlyBelow(Version.API24_NOUGAT_70)) {
|
if (Version.sdkStrictlyBelow(Version.API24_NOUGAT_70)) {
|
||||||
onIncomingReceived()
|
onIncomingReceived()
|
||||||
|
@ -206,13 +190,6 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
AudioRouteUtils.routeAudioToBluetooth(call)
|
AudioRouteUtils.routeAudioToBluetooth(call)
|
||||||
}
|
}
|
||||||
} else if (state == Call.State.Connected) {
|
} else if (state == Call.State.Connected) {
|
||||||
if (isVibrating) {
|
|
||||||
Log.i("[Context] Stopping vibration")
|
|
||||||
val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
|
||||||
vibrator.cancel()
|
|
||||||
isVibrating = false
|
|
||||||
}
|
|
||||||
|
|
||||||
onCallStarted()
|
onCallStarted()
|
||||||
} else if (state == Call.State.StreamsRunning) {
|
} else if (state == Call.State.StreamsRunning) {
|
||||||
// Do not automatically route audio to bluetooth after first call
|
// Do not automatically route audio to bluetooth after first call
|
||||||
|
@ -234,13 +211,6 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
}
|
}
|
||||||
} else if (state == Call.State.End || state == Call.State.Error || state == Call.State.Released) {
|
} else if (state == Call.State.End || state == Call.State.Error || state == Call.State.Released) {
|
||||||
if (core.callsNb == 0) {
|
if (core.callsNb == 0) {
|
||||||
if (isVibrating) {
|
|
||||||
Log.i("[Context] Stopping vibration")
|
|
||||||
val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
|
||||||
vibrator.cancel()
|
|
||||||
isVibrating = false
|
|
||||||
}
|
|
||||||
|
|
||||||
removeCallOverlay()
|
removeCallOverlay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,6 +312,12 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
|
|
||||||
core.staticPicture = corePreferences.staticPicturePath
|
core.staticPicture = corePreferences.staticPicturePath
|
||||||
|
|
||||||
|
// Migration code
|
||||||
|
if (core.config.getBool("app", "incoming_call_vibration", true)) {
|
||||||
|
core.isVibrationOnIncomingCallEnabled = true
|
||||||
|
core.config.setBool("app", "incoming_call_vibration", false)
|
||||||
|
}
|
||||||
|
|
||||||
initUserCertificates()
|
initUserCertificates()
|
||||||
|
|
||||||
computeUserAgent()
|
computeUserAgent()
|
||||||
|
|
|
@ -221,12 +221,6 @@ class CorePreferences constructor(private val context: Context) {
|
||||||
|
|
||||||
/* Call */
|
/* Call */
|
||||||
|
|
||||||
var vibrateWhileIncomingCall: Boolean
|
|
||||||
get() = config.getBool("app", "incoming_call_vibration", true)
|
|
||||||
set(value) {
|
|
||||||
config.setBool("app", "incoming_call_vibration", value)
|
|
||||||
}
|
|
||||||
|
|
||||||
var acceptEarlyMedia: Boolean
|
var acceptEarlyMedia: Boolean
|
||||||
get() = config.getBool("sip", "incoming_calls_early_media", false)
|
get() = config.getBool("sip", "incoming_calls_early_media", false)
|
||||||
set(value) {
|
set(value) {
|
||||||
|
|
Loading…
Reference in a new issue