mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Added setting to enable/disable logs printing in system logcat
This commit is contained in:
parent
b0dbfbcc3d
commit
865f3b9692
5 changed files with 62 additions and 8 deletions
|
|
@ -347,6 +347,8 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
|
|||
}
|
||||
}
|
||||
|
||||
private var logcatEnabled: Boolean = corePreferences.printLogsInLogcat
|
||||
|
||||
private val loggingServiceListener = object : LoggingServiceListenerStub() {
|
||||
@WorkerThread
|
||||
override fun onLogMessageWritten(
|
||||
|
|
@ -355,12 +357,14 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
|
|||
level: LogLevel,
|
||||
message: String
|
||||
) {
|
||||
when (level) {
|
||||
LogLevel.Error -> android.util.Log.e(domain, message)
|
||||
LogLevel.Warning -> android.util.Log.w(domain, message)
|
||||
LogLevel.Message -> android.util.Log.i(domain, message)
|
||||
LogLevel.Fatal -> android.util.Log.wtf(domain, message)
|
||||
else -> android.util.Log.d(domain, message)
|
||||
if (logcatEnabled) {
|
||||
when (level) {
|
||||
LogLevel.Error -> android.util.Log.e(domain, message)
|
||||
LogLevel.Warning -> android.util.Log.w(domain, message)
|
||||
LogLevel.Message -> android.util.Log.i(domain, message)
|
||||
LogLevel.Fatal -> android.util.Log.wtf(domain, message)
|
||||
else -> android.util.Log.d(domain, message)
|
||||
}
|
||||
}
|
||||
FirebaseCrashlytics.getInstance().log("[$domain] [${level.name}] $message")
|
||||
}
|
||||
|
|
@ -842,4 +846,9 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
|
|||
val sdkUserAgent = "$sdkVersion ($sdkBranch)"
|
||||
core.setUserAgent(userAgent, sdkUserAgent)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun enableLogcat(enable: Boolean) {
|
||||
logcatEnabled = enable
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import org.linphone.R
|
|||
import org.linphone.contacts.ContactLoader.Companion.NATIVE_ADDRESS_BOOK_FRIEND_LIST
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
import org.linphone.core.Factory
|
||||
import org.linphone.core.VersionUpdateCheckResult
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.ui.GenericViewModel
|
||||
|
|
@ -44,6 +45,8 @@ class HelpViewModel @UiThread constructor() : GenericViewModel() {
|
|||
private const val TAG = "[Help ViewModel]"
|
||||
}
|
||||
|
||||
val logcat = MutableLiveData<Boolean>()
|
||||
|
||||
val version = MutableLiveData<String>()
|
||||
|
||||
val appVersion = MutableLiveData<String>()
|
||||
|
|
@ -146,6 +149,7 @@ class HelpViewModel @UiThread constructor() : GenericViewModel() {
|
|||
coreContext.postOnCoreThread { core ->
|
||||
core.addListener(coreListener)
|
||||
|
||||
logcat.postValue(corePreferences.printLogsInLogcat)
|
||||
checkUpdateAvailable.postValue(corePreferences.checkForUpdateServerUrl.isNotEmpty())
|
||||
uploadLogsAvailable.postValue(!core.logCollectionUploadServerUrl.isNullOrEmpty())
|
||||
}
|
||||
|
|
@ -160,6 +164,17 @@ class HelpViewModel @UiThread constructor() : GenericViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun toggleLogcat() {
|
||||
val newValue = logcat.value == false
|
||||
coreContext.postOnCoreThread {
|
||||
corePreferences.printLogsInLogcat = newValue
|
||||
coreContext.enableLogcat(newValue)
|
||||
Factory.instance().enableLogcatLogs(newValue)
|
||||
logcat.postValue(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun cleanLogs() {
|
||||
coreContext.postOnCoreThread { core ->
|
||||
|
|
|
|||
|
|
@ -54,6 +54,34 @@
|
|||
app:layout_constraintStart_toEndOf="@id/back"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/settings_title_style"
|
||||
android:onClick="@{() -> viewModel.toggleLogcat()}"
|
||||
android:id="@+id/logcat_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:text="@string/help_troubleshooting_print_logs_in_logcat"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
app:layout_constraintTop_toTopOf="@id/logcat_switch"
|
||||
app:layout_constraintBottom_toBottomOf="@id/logcat_switch"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/logcat_switch"/>
|
||||
|
||||
<com.google.android.material.materialswitch.MaterialSwitch
|
||||
style="@style/material_switch_style"
|
||||
android:id="@+id/logcat_switch"
|
||||
android:onClick="@{() -> viewModel.toggleLogcat()}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:checked="@{viewModel.logcat}"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/tertiary_button_label_style"
|
||||
android:id="@+id/clean_logs"
|
||||
|
|
@ -95,14 +123,14 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
app:flow_wrapMode="chain"
|
||||
app:flow_horizontalGap="16dp"
|
||||
app:flow_verticalGap="10dp"
|
||||
app:flow_horizontalStyle="spread_inside"
|
||||
app:constraint_referenced_ids="clean_logs, send_logs"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title" />
|
||||
app:layout_constraintTop_toBottomOf="@id/logcat_switch" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/app_version_icon"
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@
|
|||
<string name="help_dialog_update_available_message">Une nouvelle version %s est disponible. Voulez-vous mettre à jour ?</string>
|
||||
<string name="help_quit_title">Quitter l\'application</string>
|
||||
<string name="help_troubleshooting_title">Dépannage</string>
|
||||
<string name="help_troubleshooting_print_logs_in_logcat">Imprimer les journaux dans logcat</string>
|
||||
<string name="help_troubleshooting_clean_logs">Nettoyer les journaux</string>
|
||||
<string name="help_troubleshooting_share_logs">Partager les journaux</string>
|
||||
<string name="help_troubleshooting_app_version_title">Version de l\'application</string>
|
||||
|
|
|
|||
|
|
@ -200,6 +200,7 @@
|
|||
<string name="help_dialog_update_available_message">A new version %s is available. Do you want to update?</string>
|
||||
<string name="help_quit_title">Quit app</string>
|
||||
<string name="help_troubleshooting_title">Troubleshooting</string>
|
||||
<string name="help_troubleshooting_print_logs_in_logcat">Print logs in logcat</string>
|
||||
<string name="help_troubleshooting_clean_logs">Clean logs</string>
|
||||
<string name="help_troubleshooting_share_logs">Share logs</string>
|
||||
<string name="help_troubleshooting_app_version_title">App version</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue