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
|
**/.vscode
|
||||||
res/value-hi_IN
|
res/value-hi_IN
|
||||||
linphone-sdk-android/*.aar
|
linphone-sdk-android/*.aar
|
||||||
|
app/debug
|
||||||
app/release
|
app/release
|
||||||
keystore.properties
|
keystore.properties
|
||||||
app/src/main/res/xml/contacts.xml
|
app/src/main/res/xml/contacts.xml
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.linphone
|
package org.linphone
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.content.Context
|
||||||
import org.linphone.core.CoreContext
|
import org.linphone.core.CoreContext
|
||||||
import org.linphone.core.CorePreferences
|
import org.linphone.core.CorePreferences
|
||||||
import org.linphone.core.Factory
|
import org.linphone.core.Factory
|
||||||
|
@ -30,26 +31,35 @@ class LinphoneApplication : Application() {
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var corePreferences: CorePreferences
|
lateinit var corePreferences: CorePreferences
|
||||||
lateinit var coreContext: CoreContext
|
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() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
val appName = getString(R.string.app_name)
|
val appName = getString(R.string.app_name)
|
||||||
android.util.Log.i("[$appName]", "Application is being created")
|
android.util.Log.i("[$appName]", "Application is being created")
|
||||||
|
ensureCoreExists(applicationContext)
|
||||||
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()
|
|
||||||
Log.i("[Application] Created")
|
Log.i("[Application] Created")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||||
|
import org.linphone.LinphoneApplication.Companion.ensureCoreExists
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
|
|
||||||
|
@ -36,6 +37,8 @@ abstract class GenericActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
ensureCoreExists(applicationContext)
|
||||||
|
|
||||||
if (corePreferences.forcePortrait) {
|
if (corePreferences.forcePortrait) {
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.activities.assistant.AssistantActivity
|
import org.linphone.activities.assistant.AssistantActivity
|
||||||
import org.linphone.activities.main.settings.SettingListenerStub
|
import org.linphone.activities.main.settings.SettingListenerStub
|
||||||
|
@ -102,15 +103,8 @@ class SideMenuFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.setQuitClickListener {
|
binding.setQuitClickListener {
|
||||||
val intent = Intent()
|
requireActivity().finishAndRemoveTask()
|
||||||
intent.setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
|
coreContext.stop()
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.activities.main.settings.SettingListenerStub
|
import org.linphone.activities.main.settings.SettingListenerStub
|
||||||
import org.linphone.activities.main.settings.viewmodels.AccountSettingsViewModel
|
import org.linphone.activities.main.settings.viewmodels.AccountSettingsViewModel
|
||||||
import org.linphone.core.*
|
import org.linphone.core.*
|
||||||
import org.linphone.core.tools.Log
|
|
||||||
|
|
||||||
class SideMenuViewModel : ViewModel() {
|
class SideMenuViewModel : ViewModel() {
|
||||||
val showAssistant: Boolean = true
|
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 {
|
init {
|
||||||
defaultAccountFound.value = false
|
defaultAccountFound.value = false
|
||||||
coreContext.core.addListener(listener)
|
coreContext.core.addListener(listener)
|
||||||
|
@ -80,11 +70,6 @@ class SideMenuViewModel : ViewModel() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun quit() {
|
|
||||||
coreContext.core.addListener(quitListener)
|
|
||||||
coreContext.stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateAccountsList() {
|
fun updateAccountsList() {
|
||||||
val list = arrayListOf<AccountSettingsViewModel>()
|
val list = arrayListOf<AccountSettingsViewModel>()
|
||||||
if (coreContext.core.proxyConfigList.isNotEmpty()) {
|
if (coreContext.core.proxyConfigList.isNotEmpty()) {
|
||||||
|
|
|
@ -46,6 +46,7 @@ import org.linphone.utils.AppUtils
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
|
|
||||||
class CoreContext(val context: Context, coreConfig: Config) {
|
class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
|
var stopped = false
|
||||||
val core: Core
|
val core: Core
|
||||||
val handler: Handler = Handler(Looper.getMainLooper())
|
val handler: Handler = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
|
@ -179,6 +180,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
core = Factory.instance().createCoreWithConfig(coreConfig, context)
|
core = Factory.instance().createCoreWithConfig(coreConfig, context)
|
||||||
|
stopped = false
|
||||||
Log.i("[Context] Ready")
|
Log.i("[Context] Ready")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,6 +216,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
|
||||||
|
|
||||||
core.stop()
|
core.stop()
|
||||||
core.removeListener(listener)
|
core.removeListener(listener)
|
||||||
|
stopped = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureCore() {
|
private fun configureCore() {
|
||||||
|
|
|
@ -22,10 +22,12 @@ package org.linphone.core
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import org.linphone.LinphoneApplication.Companion.ensureCoreExists
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
|
|
||||||
class CorePushReceiver : BroadcastReceiver() {
|
class CorePushReceiver : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
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()
|
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() {
|
override fun onDestroy() {
|
||||||
Log.i("[Service] Stopping")
|
Log.i("[Service] Stopping")
|
||||||
coreContext.notificationsManager.service = null
|
coreContext.notificationsManager.service = null
|
||||||
|
|
|
@ -205,6 +205,7 @@ class NotificationsManager(private val context: Context) {
|
||||||
notificationManager.cancel(notifiable.notificationId)
|
notificationManager.cancel(notifiable.notificationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stopForegroundNotification()
|
||||||
coreContext.core.removeListener(listener)
|
coreContext.core.removeListener(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue