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
|
<service
|
||||||
android:name=".core.CoreService"
|
android:name=".core.CoreService"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:foregroundServiceType="phoneCall|camera|microphone"
|
android:foregroundServiceType="phoneCall|camera|microphone|dataSync"
|
||||||
android:stopWithTask="false"
|
android:stopWithTask="false"
|
||||||
android:label="@string/app_name" />
|
android:label="@string/app_name" />
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,8 @@ class LinphoneApplication : Application(), ImageLoaderFactory {
|
||||||
context: Context,
|
context: Context,
|
||||||
pushReceived: Boolean = false,
|
pushReceived: Boolean = false,
|
||||||
service: CoreService? = null,
|
service: CoreService? = null,
|
||||||
useAutoStartDescription: Boolean = false
|
useAutoStartDescription: Boolean = false,
|
||||||
|
skipCoreStart: Boolean = false
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (::coreContext.isInitialized && !coreContext.stopped) {
|
if (::coreContext.isInitialized && !coreContext.stopped) {
|
||||||
Log.d("[Application] Skipping Core creation (push received? $pushReceived)")
|
Log.d("[Application] Skipping Core creation (push received? $pushReceived)")
|
||||||
|
@ -96,7 +97,9 @@ class LinphoneApplication : Application(), ImageLoaderFactory {
|
||||||
service,
|
service,
|
||||||
useAutoStartDescription
|
useAutoStartDescription
|
||||||
)
|
)
|
||||||
coreContext.start()
|
if (!skipCoreStart) {
|
||||||
|
coreContext.start()
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -264,6 +264,8 @@ class Api31Compatibility {
|
||||||
Log.e("[Api31 Compatibility] Can't start service as foreground! $fssnae")
|
Log.e("[Api31 Compatibility] Can't start service as foreground! $fssnae")
|
||||||
} catch (se: SecurityException) {
|
} catch (se: SecurityException) {
|
||||||
Log.e("[Api31 Compatibility] Can't start service as foreground! $se")
|
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")
|
Log.e("[Api31 Compatibility] Can't start service as foreground! $fssnae")
|
||||||
} catch (se: SecurityException) {
|
} catch (se: SecurityException) {
|
||||||
Log.e("[Api31 Compatibility] Can't start service as foreground! $se")
|
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) {
|
if (corePreferences.keepServiceAlive) {
|
||||||
Log.i("[Service] Starting as foreground to keep app alive in background")
|
Log.i("[Service] Starting as foreground to keep app alive in background")
|
||||||
if (!ensureCoreExists(
|
val contextCreated = ensureCoreExists(
|
||||||
applicationContext,
|
applicationContext,
|
||||||
pushReceived = false,
|
pushReceived = false,
|
||||||
service = this,
|
service = this,
|
||||||
useAutoStartDescription = false
|
useAutoStartDescription = false
|
||||||
)
|
)
|
||||||
) {
|
if (!contextCreated) {
|
||||||
|
// Only start foreground notification if context already exists, otherwise context will do it itself
|
||||||
coreContext.notificationsManager.startForeground(this, false)
|
coreContext.notificationsManager.startForeground(this, false)
|
||||||
}
|
}
|
||||||
} else if (intent?.extras?.get("StartForeground") == true) {
|
} else if (intent?.extras?.get("StartForeground") == true) {
|
||||||
Log.i("[Service] Starting as foreground due to device boot or app update")
|
Log.i("[Service] Starting as foreground due to device boot or app update")
|
||||||
if (!ensureCoreExists(
|
val contextCreated = ensureCoreExists(
|
||||||
applicationContext,
|
applicationContext,
|
||||||
pushReceived = false,
|
pushReceived = false,
|
||||||
service = this,
|
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.notificationsManager.startForeground(this, true)
|
||||||
}
|
}
|
||||||
coreContext.checkIfForegroundServiceNotificationCanBeRemovedAfterDelay(5000)
|
coreContext.checkIfForegroundServiceNotificationCanBeRemovedAfterDelay(5000)
|
||||||
|
|
Loading…
Reference in a new issue