Improved how we use the Application & quit button
This commit is contained in:
parent
1d12c510ac
commit
324399b782
9 changed files with 47 additions and 39 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -21,6 +21,7 @@ res/raw/lpconfig.xsd
|
|||
**/.vscode
|
||||
res/value-hi_IN
|
||||
linphone-sdk-android/*.aar
|
||||
app/debug
|
||||
app/release
|
||||
keystore.properties
|
||||
app/src/main/res/xml/contacts.xml
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.linphone
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import org.linphone.core.CoreContext
|
||||
import org.linphone.core.CorePreferences
|
||||
import org.linphone.core.Factory
|
||||
|
@ -30,26 +31,35 @@ class LinphoneApplication : Application() {
|
|||
companion object {
|
||||
lateinit var corePreferences: CorePreferences
|
||||
lateinit var coreContext: CoreContext
|
||||
|
||||
fun ensureCoreExists(context: Context) {
|
||||
if (::coreContext.isInitialized && !coreContext.stopped) {
|
||||
return
|
||||
}
|
||||
|
||||
Factory.instance().setLogCollectionPath(context.filesDir.absolutePath)
|
||||
Factory.instance().enableLogCollection(LogCollectionState.Enabled)
|
||||
|
||||
corePreferences = CorePreferences(context)
|
||||
corePreferences.copyAssetsFromPackage()
|
||||
|
||||
val config = Factory.instance().createConfigWithFactory(corePreferences.configPath, corePreferences.factoryConfigPath)
|
||||
corePreferences.config = config
|
||||
|
||||
val appName = context.getString(R.string.app_name)
|
||||
Factory.instance().setDebugMode(corePreferences.debugLogs, appName)
|
||||
|
||||
Log.i("[Application] Core context created")
|
||||
coreContext = CoreContext(context, config)
|
||||
coreContext.start()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
val appName = getString(R.string.app_name)
|
||||
android.util.Log.i("[$appName]", "Application is being created")
|
||||
|
||||
Factory.instance().setLogCollectionPath(applicationContext.filesDir.absolutePath)
|
||||
Factory.instance().enableLogCollection(LogCollectionState.Enabled)
|
||||
|
||||
corePreferences = CorePreferences(applicationContext)
|
||||
corePreferences.copyAssetsFromPackage()
|
||||
|
||||
val config = Factory.instance().createConfigWithFactory(corePreferences.configPath, corePreferences.factoryConfigPath)
|
||||
corePreferences.config = config
|
||||
|
||||
Factory.instance().setDebugMode(corePreferences.debugLogs, appName)
|
||||
|
||||
coreContext = CoreContext(applicationContext, config)
|
||||
coreContext.start()
|
||||
ensureCoreExists(applicationContext)
|
||||
Log.i("[Application] Created")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.LinphoneApplication.Companion.ensureCoreExists
|
||||
import org.linphone.R
|
||||
import org.linphone.core.tools.Log
|
||||
|
||||
|
@ -36,6 +37,8 @@ abstract class GenericActivity : AppCompatActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
ensureCoreExists(applicationContext)
|
||||
|
||||
if (corePreferences.forcePortrait) {
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import androidx.fragment.app.Fragment
|
|||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.activities.assistant.AssistantActivity
|
||||
import org.linphone.activities.main.settings.SettingListenerStub
|
||||
|
@ -102,15 +103,8 @@ class SideMenuFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.setQuitClickListener {
|
||||
val intent = Intent()
|
||||
intent.setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
try {
|
||||
startActivity(intent)
|
||||
} catch (ise: IllegalStateException) {
|
||||
Log.e("[Side Menu] Can't start home activity: ", ise)
|
||||
}
|
||||
viewModel.quit()
|
||||
requireActivity().finishAndRemoveTask()
|
||||
coreContext.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.linphone.LinphoneApplication.Companion.coreContext
|
|||
import org.linphone.activities.main.settings.SettingListenerStub
|
||||
import org.linphone.activities.main.settings.viewmodels.AccountSettingsViewModel
|
||||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
|
||||
class SideMenuViewModel : ViewModel() {
|
||||
val showAssistant: Boolean = true
|
||||
|
@ -60,15 +59,6 @@ class SideMenuViewModel : ViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
private val quitListener: CoreListenerStub = object : CoreListenerStub() {
|
||||
override fun onGlobalStateChanged(core: Core, state: GlobalState, message: String?) {
|
||||
if (state == GlobalState.Off) {
|
||||
Log.w("[Side Menu] Core properly terminated, killing process")
|
||||
android.os.Process.killProcess(android.os.Process.myPid())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
defaultAccountFound.value = false
|
||||
coreContext.core.addListener(listener)
|
||||
|
@ -80,11 +70,6 @@ class SideMenuViewModel : ViewModel() {
|
|||
super.onCleared()
|
||||
}
|
||||
|
||||
fun quit() {
|
||||
coreContext.core.addListener(quitListener)
|
||||
coreContext.stop()
|
||||
}
|
||||
|
||||
fun updateAccountsList() {
|
||||
val list = arrayListOf<AccountSettingsViewModel>()
|
||||
if (coreContext.core.proxyConfigList.isNotEmpty()) {
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.linphone.utils.AppUtils
|
|||
import org.linphone.utils.LinphoneUtils
|
||||
|
||||
class CoreContext(val context: Context, coreConfig: Config) {
|
||||
var stopped = false
|
||||
val core: Core
|
||||
val handler: Handler = Handler(Looper.getMainLooper())
|
||||
|
||||
|
@ -179,6 +180,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
|||
|
||||
init {
|
||||
core = Factory.instance().createCoreWithConfig(coreConfig, context)
|
||||
stopped = false
|
||||
Log.i("[Context] Ready")
|
||||
}
|
||||
|
||||
|
@ -214,6 +216,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
|||
|
||||
core.stop()
|
||||
core.removeListener(listener)
|
||||
stopped = true
|
||||
}
|
||||
|
||||
private fun configureCore() {
|
||||
|
|
|
@ -22,10 +22,12 @@ package org.linphone.core
|
|||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import org.linphone.LinphoneApplication.Companion.ensureCoreExists
|
||||
import org.linphone.core.tools.Log
|
||||
|
||||
class CorePushReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
Log.f("[Core Push Receiver] Push received")
|
||||
ensureCoreExists(context.applicationContext)
|
||||
Log.i("[Push Receiver] Push notification received")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,15 @@ class CoreService : CoreService() {
|
|||
coreContext.notificationsManager.stopCallForeground()
|
||||
}
|
||||
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
if (!corePreferences.keepServiceAlive) {
|
||||
Log.i("[Service] Task removed, stopping Core")
|
||||
coreContext.stop()
|
||||
}
|
||||
|
||||
super.onTaskRemoved(rootIntent)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
Log.i("[Service] Stopping")
|
||||
coreContext.notificationsManager.service = null
|
||||
|
|
|
@ -205,6 +205,7 @@ class NotificationsManager(private val context: Context) {
|
|||
notificationManager.cancel(notifiable.notificationId)
|
||||
}
|
||||
|
||||
stopForegroundNotification()
|
||||
coreContext.core.removeListener(listener)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue