Trying not to start Core in Application, only Config

This commit is contained in:
Sylvain Berfini 2022-04-22 16:34:39 +02:00
parent cec6d307d0
commit 72eb711d98
6 changed files with 20 additions and 12 deletions

View file

@ -41,9 +41,8 @@ class LinphoneApplication : Application(), ImageLoaderFactory {
@SuppressLint("StaticFieldLeak")
lateinit var coreContext: CoreContext
fun ensureCoreExists(context: Context, pushReceived: Boolean = false) {
if (::coreContext.isInitialized && !coreContext.stopped) {
Log.d("[Application] Skipping Core creation (push received? $pushReceived)")
private fun createConfig(context: Context) {
if (::corePreferences.isInitialized) {
return
}
@ -70,8 +69,17 @@ class LinphoneApplication : Application(), ImageLoaderFactory {
Factory.instance().loggingService.setLogLevel(LogLevel.Message)
}
Log.i("[Application] Core context created ${if (pushReceived) "from push" else ""}")
coreContext = CoreContext(context, config)
Log.i("[Application] Core config & preferences created")
}
fun ensureCoreExists(context: Context, pushReceived: Boolean = false) {
if (::coreContext.isInitialized && !coreContext.stopped) {
Log.d("[Application] Skipping Core creation (push received? $pushReceived)")
return
}
Log.i("[Application] Core context is being created ${if (pushReceived) "from push" else ""}")
coreContext = CoreContext(context, corePreferences.config)
coreContext.start()
}
}
@ -80,7 +88,7 @@ class LinphoneApplication : Application(), ImageLoaderFactory {
super.onCreate()
val appName = getString(R.string.app_name)
android.util.Log.i("[$appName]", "Application is being created")
ensureCoreExists(applicationContext)
createConfig(applicationContext)
Log.i("[Application] Created")
}

View file

@ -34,7 +34,6 @@ import androidx.window.layout.WindowInfoTracker
import androidx.window.layout.WindowLayoutInfo
import java.util.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
@ -54,6 +53,7 @@ abstract class GenericActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.i("[Generic Activity] Ensuring Core exists")
ensureCoreExists(applicationContext)
lifecycleScope.launch(Dispatchers.Main) {

View file

@ -28,7 +28,6 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.IBinder
import org.linphone.core.tools.Log
// Below classes are required to be able to create our DummySyncService...
internal class DummyAuthenticator(context: Context) : AbstractAccountAuthenticator(context) {
@ -89,7 +88,6 @@ class DummyAuthenticationService : Service() {
override fun onCreate() {
authenticator = DummyAuthenticator(this)
Log.i("[Dummy Auth Service] Authenticator created")
}
override fun onBind(intent: Intent): IBinder {

View file

@ -24,7 +24,6 @@ import android.app.Service
import android.content.*
import android.os.Bundle
import android.os.IBinder
import org.linphone.core.tools.Log
// Below classes are required to be able to use our own contact MIME type entry...
class DummySyncAdapter(context: Context, autoInit: Boolean) : AbstractThreadedSyncAdapter(context, autoInit) {
@ -45,10 +44,8 @@ class DummySyncService : Service() {
override fun onCreate() {
synchronized(syncAdapterLock) {
Log.i("[Dummy Sync Adapter] Sync Service created")
if (syncAdapter == null) {
syncAdapter = DummySyncAdapter(applicationContext, true)
Log.i("[Dummy Sync Adapter] Sync Adapter created")
}
}
}

View file

@ -22,6 +22,7 @@ package org.linphone.core
import android.content.Intent
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.LinphoneApplication.Companion.ensureCoreExists
import org.linphone.core.tools.Log
import org.linphone.core.tools.service.CoreService
@ -29,6 +30,9 @@ class CoreService : CoreService() {
override fun onCreate() {
super.onCreate()
Log.i("[Service] Ensuring Core exists")
ensureCoreExists(applicationContext)
coreContext.notificationsManager.service = this
Log.i("[Service] Created")
}

View file

@ -32,6 +32,7 @@ import org.linphone.core.tools.Log
class NotificationBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val notificationId = intent.getIntExtra(NotificationsManager.INTENT_NOTIF_ID, 0)
Log.i("[Notification Broadcast Receiver] Got notification broadcast for ID [$notificationId]")
if (intent.action == NotificationsManager.INTENT_REPLY_NOTIF_ACTION || intent.action == NotificationsManager.INTENT_MARK_AS_READ_ACTION) {
handleChatIntent(context, intent, notificationId)