Fixed crash when device boots on Android 14
This commit is contained in:
parent
5ee9178416
commit
926413992b
4 changed files with 29 additions and 17 deletions
|
@ -175,7 +175,7 @@
|
|||
<service
|
||||
android:name=".core.CoreService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="phoneCall|camera|microphone"
|
||||
android:foregroundServiceType="phoneCall|camera|microphone|dataSync"
|
||||
android:stopWithTask="false"
|
||||
android:label="@string/app_name" />
|
||||
|
||||
|
|
|
@ -80,7 +80,8 @@ class LinphoneApplication : Application(), ImageLoaderFactory {
|
|||
context: Context,
|
||||
pushReceived: Boolean = false,
|
||||
service: CoreService? = null,
|
||||
useAutoStartDescription: Boolean = false
|
||||
useAutoStartDescription: Boolean = false,
|
||||
skipCoreStart: Boolean = false
|
||||
): Boolean {
|
||||
if (::coreContext.isInitialized && !coreContext.stopped) {
|
||||
Log.d("[Application] Skipping Core creation (push received? $pushReceived)")
|
||||
|
@ -96,7 +97,9 @@ class LinphoneApplication : Application(), ImageLoaderFactory {
|
|||
service,
|
||||
useAutoStartDescription
|
||||
)
|
||||
if (!skipCoreStart) {
|
||||
coreContext.start()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -264,6 +264,8 @@ class Api31Compatibility {
|
|||
Log.e("[Api31 Compatibility] Can't start service as foreground! $fssnae")
|
||||
} catch (se: SecurityException) {
|
||||
Log.e("[Api31 Compatibility] Can't start service as foreground! $se")
|
||||
} catch (e: Exception) {
|
||||
Log.e("[Api31 Compatibility] Can't start service as foreground! $e")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,6 +276,8 @@ class Api31Compatibility {
|
|||
Log.e("[Api31 Compatibility] Can't start service as foreground! $fssnae")
|
||||
} catch (se: SecurityException) {
|
||||
Log.e("[Api31 Compatibility] Can't start service as foreground! $se")
|
||||
} catch (e: Exception) {
|
||||
Log.e("[Api31 Compatibility] Can't start service as foreground! $e")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,24 +38,29 @@ class CoreService : CoreService() {
|
|||
|
||||
if (corePreferences.keepServiceAlive) {
|
||||
Log.i("[Service] Starting as foreground to keep app alive in background")
|
||||
if (!ensureCoreExists(
|
||||
val contextCreated = ensureCoreExists(
|
||||
applicationContext,
|
||||
pushReceived = false,
|
||||
service = this,
|
||||
useAutoStartDescription = false
|
||||
)
|
||||
) {
|
||||
if (!contextCreated) {
|
||||
// Only start foreground notification if context already exists, otherwise context will do it itself
|
||||
coreContext.notificationsManager.startForeground(this, false)
|
||||
}
|
||||
} else if (intent?.extras?.get("StartForeground") == true) {
|
||||
Log.i("[Service] Starting as foreground due to device boot or app update")
|
||||
if (!ensureCoreExists(
|
||||
val contextCreated = ensureCoreExists(
|
||||
applicationContext,
|
||||
pushReceived = false,
|
||||
service = this,
|
||||
useAutoStartDescription = true
|
||||
useAutoStartDescription = true,
|
||||
skipCoreStart = true
|
||||
)
|
||||
) {
|
||||
if (contextCreated) {
|
||||
coreContext.start()
|
||||
} else {
|
||||
// Only start foreground notification if context already exists, otherwise context will do it itself
|
||||
coreContext.notificationsManager.startForeground(this, true)
|
||||
}
|
||||
coreContext.checkIfForegroundServiceNotificationCanBeRemovedAfterDelay(5000)
|
||||
|
|
Loading…
Reference in a new issue