diff --git a/app/src/main/java/org/linphone/activities/main/logcat/fragments/LogcatFragment.kt b/app/src/main/java/org/linphone/activities/main/logcat/fragments/LogcatFragment.kt new file mode 100644 index 000000000..f600cc825 --- /dev/null +++ b/app/src/main/java/org/linphone/activities/main/logcat/fragments/LogcatFragment.kt @@ -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 . + */ +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 + } +} diff --git a/app/src/main/java/org/linphone/activities/main/logcat/viewmodels/LogcatViewModel.kt b/app/src/main/java/org/linphone/activities/main/logcat/viewmodels/LogcatViewModel.kt new file mode 100644 index 000000000..9b0fb28c3 --- /dev/null +++ b/app/src/main/java/org/linphone/activities/main/logcat/viewmodels/LogcatViewModel.kt @@ -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 . + */ +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() + + 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()) + } +} diff --git a/app/src/main/java/org/linphone/activities/main/sidemenu/fragments/SideMenuFragment.kt b/app/src/main/java/org/linphone/activities/main/sidemenu/fragments/SideMenuFragment.kt index bb0cdb5b9..f173c7430 100644 --- a/app/src/main/java/org/linphone/activities/main/sidemenu/fragments/SideMenuFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/sidemenu/fragments/SideMenuFragment.kt @@ -83,28 +83,37 @@ class SideMenuFragment : Fragment() { } binding.setAssistantClickListener { - sharedViewModel.toggleDrawerEvent.value = Event(true) + closeSideMenu() startActivity(Intent(context, AssistantActivity::class.java)) } binding.setSettingsClickListener { - sharedViewModel.toggleDrawerEvent.value = Event(true) + closeSideMenu() findNavController().navigate(R.id.action_global_settingsFragment) } binding.setRecordingsClickListener { - sharedViewModel.toggleDrawerEvent.value = Event(true) + closeSideMenu() findNavController().navigate(R.id.action_global_recordingsFragment) } binding.setAboutClickListener { - sharedViewModel.toggleDrawerEvent.value = Event(true) + closeSideMenu() findNavController().navigate(R.id.action_global_aboutFragment) } + binding.setLogcatClickListener { + closeSideMenu() + findNavController().navigate(R.id.action_global_logcatFragment) + } + binding.setQuitClickListener { requireActivity().finishAndRemoveTask() coreContext.stop() } } + + private fun closeSideMenu() { + sharedViewModel.toggleDrawerEvent.value = Event(true) + } } diff --git a/app/src/main/java/org/linphone/activities/main/sidemenu/viewmodels/SideMenuViewModel.kt b/app/src/main/java/org/linphone/activities/main/sidemenu/viewmodels/SideMenuViewModel.kt index e31225072..67150ee80 100644 --- a/app/src/main/java/org/linphone/activities/main/sidemenu/viewmodels/SideMenuViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/sidemenu/viewmodels/SideMenuViewModel.kt @@ -27,10 +27,11 @@ import org.linphone.activities.main.settings.viewmodels.AccountSettingsViewModel import org.linphone.core.* class SideMenuViewModel : ViewModel() { - val showAssistant: Boolean = true - val showSettings: Boolean = true - val showRecordings: Boolean = true - val showAbout: Boolean = true + val showAssistant = MutableLiveData() + val showSettings = MutableLiveData() + val showRecordings = MutableLiveData() + val showAbout = MutableLiveData() + val showLogcat = MutableLiveData() val defaultAccount = MutableLiveData() val defaultAccountFound = MutableLiveData() @@ -60,6 +61,12 @@ class SideMenuViewModel : ViewModel() { } init { + showAssistant.value = true + showSettings.value = true + showRecordings.value = true + showAbout.value = true + showLogcat.value = true + defaultAccountFound.value = false coreContext.core.addListener(listener) updateAccountsList() diff --git a/app/src/main/res/layout/logcat_fragment.xml b/app/src/main/res/layout/logcat_fragment.xml new file mode 100644 index 000000000..93e8b1240 --- /dev/null +++ b/app/src/main/res/layout/logcat_fragment.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/side_menu_fragment.xml b/app/src/main/res/layout/side_menu_fragment.xml index b5634c3a6..3f4f9af43 100644 --- a/app/src/main/res/layout/side_menu_fragment.xml +++ b/app/src/main/res/layout/side_menu_fragment.xml @@ -16,6 +16,9 @@ + @@ -221,6 +224,35 @@ android:layout_height="1dp" android:background="?dividerColor" /> + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cdb0491fd..a3687ec5e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -75,6 +75,7 @@ Assistant Recordings Settings + Logcat Quit