Use FEATURE_TELECOM instead of FEATURE_CONNECTION_SERVICE for Android >= 33 + added logs to TelecomHelper
This commit is contained in:
parent
226abd9e19
commit
9fbd4fbc40
6 changed files with 39 additions and 12 deletions
|
@ -282,7 +282,7 @@ class DialerFragment : SecureFragment<DialerFragmentBinding>() {
|
||||||
Log.i("[Dialer] Telecom Manager permissions granted")
|
Log.i("[Dialer] Telecom Manager permissions granted")
|
||||||
if (!TelecomHelper.exists()) {
|
if (!TelecomHelper.exists()) {
|
||||||
Log.i("[Dialer] Creating Telecom Helper")
|
Log.i("[Dialer] Creating Telecom Helper")
|
||||||
if (requireContext().packageManager.hasSystemFeature(PackageManager.FEATURE_CONNECTION_SERVICE)) {
|
if (Compatibility.hasTelecomManagerFeature(requireContext())) {
|
||||||
TelecomHelper.create(requireContext())
|
TelecomHelper.create(requireContext())
|
||||||
} else {
|
} else {
|
||||||
Log.e("[Dialer] Telecom Helper can't be created, device doesn't support connection service!")
|
Log.e("[Dialer] Telecom Helper can't be created, device doesn't support connection service!")
|
||||||
|
|
|
@ -89,18 +89,14 @@ class CallSettingsFragment : GenericSettingFragment<SettingsCallFragmentBinding>
|
||||||
viewLifecycleOwner
|
viewLifecycleOwner
|
||||||
) {
|
) {
|
||||||
it.consume {
|
it.consume {
|
||||||
if (requireContext().packageManager.hasSystemFeature(PackageManager.FEATURE_CONNECTION_SERVICE)) {
|
if (Compatibility.hasTelecomManagerFeature(requireContext())) {
|
||||||
if (!Compatibility.hasTelecomManagerPermissions(requireContext())) {
|
if (!Compatibility.hasTelecomManagerPermissions(requireContext())) {
|
||||||
Compatibility.requestTelecomManagerPermissions(requireActivity(), 1)
|
Compatibility.requestTelecomManagerPermissions(requireActivity(), 1)
|
||||||
} else if (!TelecomHelper.exists()) {
|
} else if (!TelecomHelper.exists()) {
|
||||||
corePreferences.useTelecomManager = true
|
corePreferences.useTelecomManager = true
|
||||||
Log.w("[Telecom Helper] Doesn't exists yet, creating it")
|
Log.w("[Telecom Helper] Doesn't exists yet, creating it")
|
||||||
if (requireContext().packageManager.hasSystemFeature(PackageManager.FEATURE_CONNECTION_SERVICE)) {
|
|
||||||
TelecomHelper.create(requireContext())
|
TelecomHelper.create(requireContext())
|
||||||
updateTelecomManagerAccount()
|
updateTelecomManagerAccount()
|
||||||
} else {
|
|
||||||
Log.e("[Telecom Helper] Telecom Helper can't be created, device doesn't support connection service")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e("[Telecom Helper] Telecom Helper can't be created, device doesn't support connection service!")
|
Log.e("[Telecom Helper] Telecom Helper can't be created, device doesn't support connection service!")
|
||||||
|
@ -139,7 +135,7 @@ class CallSettingsFragment : GenericSettingFragment<SettingsCallFragmentBinding>
|
||||||
} else if (requestCode == 1) {
|
} else if (requestCode == 1) {
|
||||||
if (!TelecomHelper.exists()) {
|
if (!TelecomHelper.exists()) {
|
||||||
Log.w("[Telecom Helper] Doesn't exists yet, creating it")
|
Log.w("[Telecom Helper] Doesn't exists yet, creating it")
|
||||||
if (requireContext().packageManager.hasSystemFeature(PackageManager.FEATURE_CONNECTION_SERVICE)) {
|
if (Compatibility.hasTelecomManagerFeature(requireContext())) {
|
||||||
TelecomHelper.create(requireContext())
|
TelecomHelper.create(requireContext())
|
||||||
} else {
|
} else {
|
||||||
Log.e("[Telecom Helper] Telecom Helper can't be created, device doesn't support connection service")
|
Log.e("[Telecom Helper] Telecom Helper can't be created, device doesn't support connection service")
|
||||||
|
@ -179,7 +175,7 @@ class CallSettingsFragment : GenericSettingFragment<SettingsCallFragmentBinding>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requireContext().packageManager.hasSystemFeature(PackageManager.FEATURE_CONNECTION_SERVICE)) {
|
if (Compatibility.hasTelecomManagerFeature(requireContext())) {
|
||||||
TelecomHelper.create(requireContext())
|
TelecomHelper.create(requireContext())
|
||||||
updateTelecomManagerAccount()
|
updateTelecomManagerAccount()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -31,6 +31,7 @@ import android.graphics.BitmapFactory
|
||||||
import android.media.AudioAttributes
|
import android.media.AudioAttributes
|
||||||
import android.os.VibrationEffect
|
import android.os.VibrationEffect
|
||||||
import android.os.Vibrator
|
import android.os.Vibrator
|
||||||
|
import android.telecom.CallAudioState
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
|
@ -317,9 +318,10 @@ class Api26Compatibility {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun changeAudioRouteForTelecomManager(connection: NativeCallWrapper, route: Int): Boolean {
|
fun changeAudioRouteForTelecomManager(connection: NativeCallWrapper, route: Int): Boolean {
|
||||||
Log.i("[Telecom Helper] Changing audio route [$route] on connection ${connection.callId}")
|
Log.i("[Telecom Helper] Changing audio route [${routeToString(route)}] on connection [${connection.callId}] with state [${connection.stateAsString()}]")
|
||||||
|
|
||||||
val audioState = connection.callAudioState
|
val audioState = connection.callAudioState
|
||||||
|
Log.i("[Telecom Helper] Current audio route is ${routeToString(audioState.route)}")
|
||||||
if (audioState != null && audioState.route == route) {
|
if (audioState != null && audioState.route == route) {
|
||||||
Log.w("[Telecom Helper] Connection is already using this route")
|
Log.w("[Telecom Helper] Connection is already using this route")
|
||||||
return false
|
return false
|
||||||
|
@ -349,5 +351,20 @@ class Api26Compatibility {
|
||||||
fun startForegroundService(context: Context, intent: Intent) {
|
fun startForegroundService(context: Context, intent: Intent) {
|
||||||
context.startForegroundService(intent)
|
context.startForegroundService(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasTelecomManagerFeature(context: Context): Boolean {
|
||||||
|
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_CONNECTION_SERVICE)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun routeToString(route: Int): String {
|
||||||
|
return when (route) {
|
||||||
|
CallAudioState.ROUTE_BLUETOOTH -> "BLUETOOTH"
|
||||||
|
CallAudioState.ROUTE_EARPIECE -> "EARPIECE"
|
||||||
|
CallAudioState.ROUTE_SPEAKER -> "SPEAKER"
|
||||||
|
CallAudioState.ROUTE_WIRED_HEADSET -> "WIRED_HEADSET"
|
||||||
|
CallAudioState.ROUTE_WIRED_OR_EARPIECE -> "WIRED_OR_EARPIECE"
|
||||||
|
else -> "Unknown: $route"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.linphone.compatibility
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
|
||||||
@TargetApi(33)
|
@TargetApi(33)
|
||||||
|
@ -57,5 +58,9 @@ class Api33Compatibility {
|
||||||
Compatibility.hasPermission(context, Manifest.permission.READ_MEDIA_VIDEO) ||
|
Compatibility.hasPermission(context, Manifest.permission.READ_MEDIA_VIDEO) ||
|
||||||
Compatibility.hasPermission(context, Manifest.permission.READ_MEDIA_AUDIO)
|
Compatibility.hasPermission(context, Manifest.permission.READ_MEDIA_AUDIO)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasTelecomManagerFeature(context: Context): Boolean {
|
||||||
|
return context.packageManager.hasSystemFeature(PackageManager.FEATURE_TELECOM)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -409,5 +409,14 @@ class Compatibility {
|
||||||
}
|
}
|
||||||
return Api23Compatibility.getImeFlagsForSecureChatRoom()
|
return Api23Compatibility.getImeFlagsForSecureChatRoom()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasTelecomManagerFeature(context: Context): Boolean {
|
||||||
|
if (Version.sdkAboveOrEqual(Version.API33_ANDROID_13_TIRAMISU)) {
|
||||||
|
return Api33Compatibility.hasTelecomManagerFeature(context)
|
||||||
|
} else if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||||
|
return Api26Compatibility.hasTelecomManagerFeature(context)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ class NativeCallWrapper(var callId: String) : Connection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stateAsString(): String {
|
fun stateAsString(): String {
|
||||||
return intStateToString(state)
|
return stateToString(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCall(): Call? {
|
private fun getCall(): Call? {
|
||||||
|
|
Loading…
Reference in a new issue