mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Adding back auto start setting
This commit is contained in:
parent
a2ec98659d
commit
3e49e0f014
7 changed files with 76 additions and 6 deletions
|
|
@ -123,6 +123,8 @@ class CoreContext
|
|||
MutableLiveData<Event<List<String>>>()
|
||||
}
|
||||
|
||||
private var keepAliveServiceStarted = false
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
private lateinit var coreThread: Handler
|
||||
|
||||
|
|
@ -548,15 +550,19 @@ class CoreContext
|
|||
Log.i("$TAG No configuration migration required")
|
||||
}
|
||||
|
||||
if (corePreferences.keepServiceAlive) {
|
||||
Log.i("$TAG Starting keep alive service")
|
||||
startKeepAliveService()
|
||||
}
|
||||
|
||||
contactsManager.onCoreStarted(core)
|
||||
telecomManager.onCoreStarted(core)
|
||||
notificationsManager.onCoreStarted(core, oldVersion < 600000) // Re-create channels when migrating from a non 6.0 version
|
||||
Log.i("$TAG Started contacts, telecom & notifications managers")
|
||||
|
||||
if (corePreferences.keepServiceAlive) {
|
||||
if (activityMonitor.isInForeground() || corePreferences.autoStart) {
|
||||
Log.i("$TAG Keep alive service is enabled and either app is in foreground or auto start is enabled, starting it")
|
||||
startKeepAliveService()
|
||||
} else {
|
||||
Log.w("$TAG Keep alive service is enabled but auto start isn't and app is not in foreground, not starting it")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
@ -644,6 +650,10 @@ class CoreContext
|
|||
Log.i("$TAG App is in foreground, PUBLISHING presence as Online")
|
||||
core.consolidatedPresence = ConsolidatedPresence.Online
|
||||
}
|
||||
|
||||
if (corePreferences.keepServiceAlive && !keepAliveServiceStarted) {
|
||||
startKeepAliveService()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -855,6 +865,10 @@ class CoreContext
|
|||
|
||||
@WorkerThread
|
||||
fun startKeepAliveService() {
|
||||
if (keepAliveServiceStarted) {
|
||||
Log.w("$TAG Keep alive service already started, skipping")
|
||||
}
|
||||
|
||||
val serviceIntent = Intent(Intent.ACTION_MAIN).setClass(
|
||||
context,
|
||||
CoreKeepAliveThirdPartyAccountsService::class.java
|
||||
|
|
@ -862,6 +876,7 @@ class CoreContext
|
|||
Log.i("$TAG Starting Keep alive for third party accounts Service")
|
||||
try {
|
||||
context.startService(serviceIntent)
|
||||
keepAliveServiceStarted = true
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Failed to start keep alive service: $e")
|
||||
}
|
||||
|
|
@ -877,6 +892,7 @@ class CoreContext
|
|||
"$TAG Stopping Keep alive for third party accounts Service"
|
||||
)
|
||||
context.stopService(serviceIntent)
|
||||
keepAliveServiceStarted = false
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
|
|||
|
|
@ -67,6 +67,13 @@ class CorePreferences
|
|||
config.setInt("app", "config_version", value)
|
||||
}
|
||||
|
||||
@get:WorkerThread @set:WorkerThread
|
||||
var autoStart: Boolean
|
||||
get() = config.getBool("app", "auto_start", true)
|
||||
set(value) {
|
||||
config.setBool("app", "auto_start", value)
|
||||
}
|
||||
|
||||
@get:WorkerThread @set:WorkerThread
|
||||
var checkForUpdateServerUrl: String
|
||||
get() = config.getString("misc", "version_check_url_root", "").orEmpty()
|
||||
|
|
|
|||
|
|
@ -179,6 +179,7 @@ class SettingsViewModel
|
|||
)
|
||||
|
||||
// Advanced settings
|
||||
val startAtBoot = MutableLiveData<Boolean>()
|
||||
val keepAliveThirdPartyAccountsService = MutableLiveData<Boolean>()
|
||||
|
||||
val deviceName = MutableLiveData<String>()
|
||||
|
|
@ -302,6 +303,7 @@ class SettingsViewModel
|
|||
setupTunnel()
|
||||
}
|
||||
|
||||
startAtBoot.postValue(corePreferences.autoStart)
|
||||
keepAliveThirdPartyAccountsService.postValue(corePreferences.keepServiceAlive)
|
||||
|
||||
deviceName.postValue(corePreferences.deviceName)
|
||||
|
|
@ -637,6 +639,16 @@ class SettingsViewModel
|
|||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun toggleStartAtBoot() {
|
||||
val newValue = startAtBoot.value == false
|
||||
|
||||
coreContext.postOnCoreThread {
|
||||
corePreferences.autoStart = newValue
|
||||
startAtBoot.postValue(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun toggleKeepAliveThirdPartyAccountService() {
|
||||
val newValue = keepAliveThirdPartyAccountsService.value == false
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.linphone.utils
|
|||
import android.app.Activity
|
||||
import android.app.Application.ActivityLifecycleCallbacks
|
||||
import android.os.Bundle
|
||||
import androidx.annotation.AnyThread
|
||||
import androidx.annotation.UiThread
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.core.tools.Log
|
||||
|
|
@ -79,6 +80,11 @@ class ActivityMonitor : ActivityLifecycleCallbacks {
|
|||
activities.remove(activity)
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun isInForeground(): Boolean {
|
||||
return mActive
|
||||
}
|
||||
|
||||
private fun startInactivityChecker() {
|
||||
if (mLastChecker != null) mLastChecker!!.cancel()
|
||||
AndroidDispatcher.dispatchOnUIThreadAfter(
|
||||
|
|
|
|||
|
|
@ -60,6 +60,33 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/settings_title_style"
|
||||
android:id="@+id/start_at_boot_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:text="@string/settings_advanced_start_at_boot_title"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
app:layout_constraintTop_toTopOf="@id/start_at_boot_switch"
|
||||
app:layout_constraintBottom_toBottomOf="@id/start_at_boot_switch"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/start_at_boot_switch"/>
|
||||
|
||||
<com.google.android.material.materialswitch.MaterialSwitch
|
||||
style="@style/material_switch_style"
|
||||
android:id="@+id/start_at_boot_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:checked="@{viewModel.startAtBoot}"
|
||||
android:onClick="@{() -> viewModel.toggleStartAtBoot()}"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/settings_title_style"
|
||||
android:id="@+id/keep_alive_service_title"
|
||||
|
|
@ -85,7 +112,7 @@
|
|||
android:checked="@{viewModel.keepAliveThirdPartyAccountsService}"
|
||||
android:onClick="@{() -> viewModel.toggleKeepAliveThirdPartyAccountService()}"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
app:layout_constraintTop_toBottomOf="@id/start_at_boot_switch"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/settings_title_style"
|
||||
|
|
|
|||
|
|
@ -259,6 +259,7 @@
|
|||
<string name="settings_tunnel_mode_auto_label">Auto</string>
|
||||
|
||||
<string name="settings_advanced_title">Paramètres avancés</string>
|
||||
<string name="settings_advanced_start_at_boot_title">Démarrer au lancement du téléphone</string>
|
||||
<string name="settings_advanced_keep_alive_service_title">Garder l\'app en vie via un Service</string>
|
||||
<string name="settings_advanced_device_id">Nom de l\'appareil</string>
|
||||
<string name="settings_advanced_device_id_hint">Caractères alpha-numériques uniquement</string>
|
||||
|
|
|
|||
|
|
@ -298,6 +298,7 @@
|
|||
<string name="settings_tunnel_mode_auto_label">Auto</string>
|
||||
|
||||
<string name="settings_advanced_title">Advanced settings</string>
|
||||
<string name="settings_advanced_start_at_boot_title">Start when device boots</string>
|
||||
<string name="settings_advanced_keep_alive_service_title">Keep app alive using Service</string>
|
||||
<string name="settings_advanced_device_id">Device ID</string>
|
||||
<string name="settings_advanced_device_id_hint">Alpha-numerical characters only</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue