mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-04-17 21:38:29 +00:00
Add log if foreground service fails to start + finish call activity in onResume if no more call to display
This commit is contained in:
parent
2dde1c2509
commit
c50acdf8bc
5 changed files with 30 additions and 9 deletions
|
|
@ -34,15 +34,17 @@ class Api28Compatibility {
|
|||
companion object {
|
||||
private const val TAG = "[API 28 Compatibility]"
|
||||
|
||||
fun startServiceForeground(service: Service, id: Int, notification: Notification) {
|
||||
fun startServiceForeground(service: Service, id: Int, notification: Notification): Boolean {
|
||||
try {
|
||||
service.startForeground(
|
||||
id,
|
||||
notification
|
||||
)
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Can't start service as foreground! $e")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun enterPipMode(activity: Activity): Boolean {
|
||||
|
|
|
|||
|
|
@ -44,16 +44,18 @@ class Api34Compatibility {
|
|||
id: Int,
|
||||
notification: Notification,
|
||||
foregroundServiceType: Int
|
||||
) {
|
||||
): Boolean {
|
||||
try {
|
||||
service.startForeground(
|
||||
id,
|
||||
notification,
|
||||
foregroundServiceType
|
||||
)
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Can't start service as foreground! $e")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun hasFullScreenIntentPermission(context: Context): Boolean {
|
||||
|
|
|
|||
|
|
@ -52,16 +52,16 @@ class Compatibility {
|
|||
id: Int,
|
||||
notification: Notification,
|
||||
foregroundServiceType: Int
|
||||
) {
|
||||
): Boolean {
|
||||
if (Version.sdkAboveOrEqual(Version.API34_ANDROID_14_UPSIDE_DOWN_CAKE)) {
|
||||
Api34Compatibility.startServiceForeground(
|
||||
return Api34Compatibility.startServiceForeground(
|
||||
service,
|
||||
id,
|
||||
notification,
|
||||
foregroundServiceType
|
||||
)
|
||||
} else {
|
||||
Api28Compatibility.startServiceForeground(service, id, notification)
|
||||
return Api28Compatibility.startServiceForeground(service, id, notification)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -805,12 +805,15 @@ class NotificationsManager
|
|||
Log.i(
|
||||
"$TAG Service found, starting it as foreground using notification ID [$INCOMING_CALL_ID] with type PHONE_CALL"
|
||||
)
|
||||
Compatibility.startServiceForeground(
|
||||
val success = Compatibility.startServiceForeground(
|
||||
service,
|
||||
INCOMING_CALL_ID,
|
||||
notification,
|
||||
Compatibility.FOREGROUND_SERVICE_TYPE_PHONE_CALL
|
||||
)
|
||||
if (!success) {
|
||||
Log.e("$TAG Failed to start incoming call foreground service!")
|
||||
}
|
||||
notificationsMap[INCOMING_CALL_ID] = notification
|
||||
currentInCallServiceNotificationId = INCOMING_CALL_ID
|
||||
inCallServiceForegroundNotificationPublished = true
|
||||
|
|
@ -926,12 +929,15 @@ class NotificationsManager
|
|||
Log.i(
|
||||
"$TAG Service found, starting it as foreground using notification ID [${notifiable.notificationId}] with type(s) [${foregroundServiceTypeMaskToString(mask)}]($mask)"
|
||||
)
|
||||
Compatibility.startServiceForeground(
|
||||
val success = Compatibility.startServiceForeground(
|
||||
service,
|
||||
notifiable.notificationId,
|
||||
notification,
|
||||
mask
|
||||
)
|
||||
if (!success) {
|
||||
Log.e("$TAG Failed to start call foreground service!")
|
||||
}
|
||||
notificationsMap[notifiable.notificationId] = notification
|
||||
currentInCallServiceNotificationId = notifiable.notificationId
|
||||
inCallServiceForegroundNotificationPublished = true
|
||||
|
|
@ -977,12 +983,15 @@ class NotificationsManager
|
|||
Log.i(
|
||||
"$TAG Service found, starting it as foreground using dummy notification ID [$DUMMY_NOTIF_ID]"
|
||||
)
|
||||
Compatibility.startServiceForeground(
|
||||
val success = Compatibility.startServiceForeground(
|
||||
service,
|
||||
DUMMY_NOTIF_ID,
|
||||
notification,
|
||||
Compatibility.FOREGROUND_SERVICE_TYPE_PHONE_CALL
|
||||
)
|
||||
if (!success) {
|
||||
Log.e("$TAG Failed to start dummy call foreground service!")
|
||||
}
|
||||
notificationsMap[INCOMING_CALL_ID] = notification
|
||||
currentInCallServiceNotificationId = DUMMY_NOTIF_ID
|
||||
inCallServiceForegroundNotificationPublished = true
|
||||
|
|
@ -1810,12 +1819,15 @@ class NotificationsManager
|
|||
Log.i(
|
||||
"$TAG Keep alive for third party accounts Service found, starting it as foreground using notification ID [$KEEP_ALIVE_FOR_THIRD_PARTY_ACCOUNTS_ID] with type [SPECIAL_USE]"
|
||||
)
|
||||
Compatibility.startServiceForeground(
|
||||
val success = Compatibility.startServiceForeground(
|
||||
service,
|
||||
KEEP_ALIVE_FOR_THIRD_PARTY_ACCOUNTS_ID,
|
||||
notification,
|
||||
Compatibility.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
|
||||
)
|
||||
if (!success) {
|
||||
Log.e("$TAG Failed to start keep alive foreground service!")
|
||||
}
|
||||
currentKeepAliveThirdPartyAccountsForegroundServiceNotificationId = KEEP_ALIVE_FOR_THIRD_PARTY_ACCOUNTS_ID
|
||||
} else {
|
||||
Log.w("$TAG Keep alive for third party accounts Service hasn't started yet...")
|
||||
|
|
|
|||
|
|
@ -376,6 +376,11 @@ class CallActivity : GenericActivity() {
|
|||
if (::callViewModel.isInitialized) {
|
||||
callViewModel.pipMode.value = isInPipMode
|
||||
}
|
||||
|
||||
if (callsViewModel.callsCount.value == 0) {
|
||||
Log.w("$TAG Call activity is being resumed but no call was found, finishing activity")
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue