Added a very basic logcat view

This commit is contained in:
Sylvain Berfini 2020-06-08 10:38:59 +02:00
parent a4cb50ea42
commit 3fb833cbfb
8 changed files with 213 additions and 8 deletions

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2010-2020 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.activities.main.logcat.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import org.linphone.activities.main.logcat.viewmodels.LogcatViewModel
import org.linphone.databinding.LogcatFragmentBinding
class LogcatFragment : Fragment() {
private lateinit var binding: LogcatFragmentBinding
private lateinit var viewModel: LogcatViewModel
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = LogcatFragmentBinding.inflate(inflater, container, false)
return binding.root
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
binding.lifecycleOwner = this
viewModel = ViewModelProvider(this).get(LogcatViewModel::class.java)
binding.viewModel = viewModel
}
}

View file

@ -0,0 +1,70 @@
/*
* Copyright (c) 2010-2020 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.activities.main.logcat.viewmodels
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.linphone.core.tools.Log
import org.linphone.utils.LogsUploadViewModel
class LogcatViewModel : LogsUploadViewModel() {
val logcat = MutableLiveData<String>()
init {
viewModelScope.launch { fetchLogcat() }
}
private suspend fun fetchLogcat() = withContext(Dispatchers.IO) {
val process = Runtime.getRuntime().exec("logcat -d")
val reader = BufferedReader(InputStreamReader(process.inputStream))
val logs = StringBuilder()
var line: String? = null
do {
try {
line = reader.readLine()
line ?: break
val split = line.split(" ")
if (split.size > 7) {
val date = split[0]
val time = split[1]
val level = split[4]
var log = StringBuilder()
log.append(line.subSequence(line.indexOf(split[7]), line.length))
log.append("\r\n")
logs.append(log)
} else {
logs.append("$line \r\n")
}
} catch (ioe: IOException) {
Log.e("[Logcat] Read exception: $ioe")
}
} while (line != null)
logcat.postValue(logs.toString())
}
}

View file

@ -83,28 +83,37 @@ class SideMenuFragment : Fragment() {
} }
binding.setAssistantClickListener { binding.setAssistantClickListener {
sharedViewModel.toggleDrawerEvent.value = Event(true) closeSideMenu()
startActivity(Intent(context, AssistantActivity::class.java)) startActivity(Intent(context, AssistantActivity::class.java))
} }
binding.setSettingsClickListener { binding.setSettingsClickListener {
sharedViewModel.toggleDrawerEvent.value = Event(true) closeSideMenu()
findNavController().navigate(R.id.action_global_settingsFragment) findNavController().navigate(R.id.action_global_settingsFragment)
} }
binding.setRecordingsClickListener { binding.setRecordingsClickListener {
sharedViewModel.toggleDrawerEvent.value = Event(true) closeSideMenu()
findNavController().navigate(R.id.action_global_recordingsFragment) findNavController().navigate(R.id.action_global_recordingsFragment)
} }
binding.setAboutClickListener { binding.setAboutClickListener {
sharedViewModel.toggleDrawerEvent.value = Event(true) closeSideMenu()
findNavController().navigate(R.id.action_global_aboutFragment) findNavController().navigate(R.id.action_global_aboutFragment)
} }
binding.setLogcatClickListener {
closeSideMenu()
findNavController().navigate(R.id.action_global_logcatFragment)
}
binding.setQuitClickListener { binding.setQuitClickListener {
requireActivity().finishAndRemoveTask() requireActivity().finishAndRemoveTask()
coreContext.stop() coreContext.stop()
} }
} }
private fun closeSideMenu() {
sharedViewModel.toggleDrawerEvent.value = Event(true)
}
} }

View file

@ -27,10 +27,11 @@ import org.linphone.activities.main.settings.viewmodels.AccountSettingsViewModel
import org.linphone.core.* import org.linphone.core.*
class SideMenuViewModel : ViewModel() { class SideMenuViewModel : ViewModel() {
val showAssistant: Boolean = true val showAssistant = MutableLiveData<Boolean>()
val showSettings: Boolean = true val showSettings = MutableLiveData<Boolean>()
val showRecordings: Boolean = true val showRecordings = MutableLiveData<Boolean>()
val showAbout: Boolean = true val showAbout = MutableLiveData<Boolean>()
val showLogcat = MutableLiveData<Boolean>()
val defaultAccount = MutableLiveData<AccountSettingsViewModel>() val defaultAccount = MutableLiveData<AccountSettingsViewModel>()
val defaultAccountFound = MutableLiveData<Boolean>() val defaultAccountFound = MutableLiveData<Boolean>()
@ -60,6 +61,12 @@ class SideMenuViewModel : ViewModel() {
} }
init { init {
showAssistant.value = true
showSettings.value = true
showRecordings.value = true
showAbout.value = true
showLogcat.value = true
defaultAccountFound.value = false defaultAccountFound.value = false
coreContext.core.addListener(listener) coreContext.core.addListener(listener)
updateAccountsList() updateAccountsList()

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View"/>
<variable
name="viewModel"
type="org.linphone.activities.main.logcat.viewmodels.LogcatViewModel"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{viewModel.logcat}"/>
</ScrollView>
</RelativeLayout>
</layout>

View file

@ -16,6 +16,9 @@
<variable <variable
name="aboutClickListener" name="aboutClickListener"
type="android.view.View.OnClickListener"/> type="android.view.View.OnClickListener"/>
<variable
name="logcatClickListener"
type="android.view.View.OnClickListener" />
<variable <variable
name="quitClickListener" name="quitClickListener"
type="android.view.View.OnClickListener"/> type="android.view.View.OnClickListener"/>
@ -221,6 +224,35 @@
android:layout_height="1dp" android:layout_height="1dp"
android:background="?dividerColor" /> android:background="?dividerColor" />
<LinearLayout
android:onClick="@{logcatClickListener}"
android:visibility="@{viewModel.showLogcat ? View.VISIBLE : View.GONE}"
android:layout_width="match_parent"
android:layout_height="45dp">
<ImageView
android:layout_width="45dp"
android:layout_height="45dp"
android:padding="10dp"
android:contentDescription="@string/logcat"
android:src="@drawable/menu_about" />
<TextView
android:text="@string/logcat"
style="@style/standard_text_font"
android:layout_width="match_parent"
android:layout_height="45dp"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:paddingRight="16dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?dividerColor" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View file

@ -393,5 +393,11 @@
android:name="IsLinking" android:name="IsLinking"
app:argType="boolean" /> app:argType="boolean" />
</fragment> </fragment>
<fragment
android:id="@+id/logcatFragment"
android:name="org.linphone.activities.main.logcat.fragments.LogcatFragment"
tools:layout="@layout/logcat_fragment"
android:label="LogcatFragment" />
<action android:id="@+id/action_global_logcatFragment" app:destination="@id/logcatFragment"/>
</navigation> </navigation>

View file

@ -75,6 +75,7 @@
<string name="assistant">Assistant</string> <string name="assistant">Assistant</string>
<string name="recordings">Recordings</string> <string name="recordings">Recordings</string>
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="logcat">Logcat</string>
<string name="quit">Quit</string> <string name="quit">Quit</string>
<!-- History --> <!-- History -->