forked from hardcoresushi/DroidFS
Logcat activity
This commit is contained in:
parent
1c15f9fac8
commit
c26ab661c2
@ -53,6 +53,7 @@
|
|||||||
<activity android:name=".file_viewers.AudioPlayer" android:configChanges="screenSize|orientation" />
|
<activity android:name=".file_viewers.AudioPlayer" android:configChanges="screenSize|orientation" />
|
||||||
<activity android:name=".file_viewers.TextEditor" android:configChanges="screenSize|orientation" />
|
<activity android:name=".file_viewers.TextEditor" android:configChanges="screenSize|orientation" />
|
||||||
<activity android:name=".CameraActivity" android:screenOrientation="nosensor" />
|
<activity android:name=".CameraActivity" android:screenOrientation="nosensor" />
|
||||||
|
<activity android:name=".LogcatActivity"/>
|
||||||
|
|
||||||
<service android:name=".WiperService" android:exported="false" android:stopWithTask="false"/>
|
<service android:name=".WiperService" android:exported="false" android:stopWithTask="false"/>
|
||||||
<service android:name=".file_operations.FileOperationService" android:exported="false"/>
|
<service android:name=".file_operations.FileOperationService" android:exported="false"/>
|
||||||
|
88
app/src/main/java/sushi/hardcore/droidfs/LogcatActivity.kt
Normal file
88
app/src/main/java/sushi/hardcore/droidfs/LogcatActivity.kt
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package sushi.hardcore.droidfs
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import sushi.hardcore.droidfs.databinding.ActivityLogcatBinding
|
||||||
|
import java.io.BufferedReader
|
||||||
|
import java.io.BufferedWriter
|
||||||
|
import java.io.InputStreamReader
|
||||||
|
import java.io.InterruptedIOException
|
||||||
|
import java.io.OutputStreamWriter
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
class LogcatActivity: BaseActivity() {
|
||||||
|
private lateinit var binding: ActivityLogcatBinding
|
||||||
|
private var process: Process? = null
|
||||||
|
private val dateFormat by lazy {
|
||||||
|
SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.getDefault())
|
||||||
|
}
|
||||||
|
private val saveAs = registerForActivityResult(ActivityResultContracts.CreateDocument("text/*")) { uri ->
|
||||||
|
uri?.let {
|
||||||
|
saveTo(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
binding = ActivityLogcatBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
|
title = getString(R.string.logcat_title)
|
||||||
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
BufferedReader(InputStreamReader(Runtime.getRuntime().exec("logcat").also {
|
||||||
|
process = it
|
||||||
|
}.inputStream)).forEachLine {
|
||||||
|
binding.content.post {
|
||||||
|
binding.content.append("$it\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_: InterruptedIOException) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
process?.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
menuInflater.inflate(R.menu.logcat, menu)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
return when (item.itemId) {
|
||||||
|
android.R.id.home -> {
|
||||||
|
finish()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
R.id.save -> {
|
||||||
|
saveAs.launch("DroidFS_${dateFormat.format(Date())}.log")
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveTo(uri: Uri) {
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
BufferedWriter(OutputStreamWriter(contentResolver.openOutputStream(uri))).use {
|
||||||
|
it.write(binding.content.text.toString())
|
||||||
|
}
|
||||||
|
launch(Dispatchers.Main) {
|
||||||
|
Toast.makeText(this@LogcatActivity, R.string.logcat_saved, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -120,6 +120,10 @@ class SettingsActivity : BaseActivity() {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
findPreference<Preference>("logcat")?.setOnPreferenceClickListener { _ ->
|
||||||
|
startActivity(Intent(requireContext(), LogcatActivity::class.java))
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
app/src/main/res/drawable/icon_debug.xml
Normal file
5
app/src/main/res/drawable/icon_debug.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<vector android:height="24dp"
|
||||||
|
android:viewportHeight="24" android:viewportWidth="24"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="?attr/colorAccent" android:pathData="M5,16c0,3.87 3.13,7 7,7s7,-3.13 7,-7v-4L5,12v4zM16.12,4.37l2.1,-2.1 -0.82,-0.83 -2.3,2.31C14.16,3.28 13.12,3 12,3s-2.16,0.28 -3.09,0.75L6.6,1.44l-0.82,0.83 2.1,2.1C6.14,5.64 5,7.68 5,10v1h14v-1c0,-2.32 -1.14,-4.36 -2.88,-5.63zM9,9c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM15,9c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1z"/>
|
||||||
|
</vector>
|
20
app/src/main/res/layout/activity_logcat.xml
Normal file
20
app/src/main/res/layout/activity_logcat.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<HorizontalScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
android:typeface="monospace" />
|
||||||
|
|
||||||
|
</HorizontalScrollView>
|
||||||
|
|
||||||
|
</ScrollView>
|
11
app/src/main/res/menu/logcat.xml
Normal file
11
app/src/main/res/menu/logcat.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/save"
|
||||||
|
app:showAsAction="ifRoom"
|
||||||
|
android:icon="@drawable/icon_save"
|
||||||
|
android:title="@string/save" />
|
||||||
|
|
||||||
|
</menu>
|
@ -276,4 +276,7 @@
|
|||||||
<string name="memfd_create_unsupported">Your current kernel does not support memfd_create(). This feature requires a minimum kernel version of %s.</string>
|
<string name="memfd_create_unsupported">Your current kernel does not support memfd_create(). This feature requires a minimum kernel version of %s.</string>
|
||||||
<string name="export_method">Export method</string>
|
<string name="export_method">Export method</string>
|
||||||
<string name="export_method_summary">File export method. Used for sharing, external opening and accessing exposed files.</string>
|
<string name="export_method_summary">File export method. Used for sharing, external opening and accessing exposed files.</string>
|
||||||
|
<string name="debug">Debug</string>
|
||||||
|
<string name="logcat_title">DroidFS Logcat</string>
|
||||||
|
<string name="logcat_saved">Logcat saved</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -93,6 +93,16 @@
|
|||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory android:title="@string/debug">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="logcat"
|
||||||
|
android:title="Logcat"
|
||||||
|
android:summary="View the DroidFS logcat"
|
||||||
|
android:icon="@drawable/icon_debug"/>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/about">
|
<PreferenceCategory android:title="@string/about">
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
@ -110,7 +120,6 @@
|
|||||||
</Preference>
|
</Preference>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="version"
|
|
||||||
android:icon="@drawable/icon_info"
|
android:icon="@drawable/icon_info"
|
||||||
android:title="@string/version"
|
android:title="@string/version"
|
||||||
android:summary="@string/versionName"/> <!--added by gradle at build time-->
|
android:summary="@string/versionName"/> <!--added by gradle at build time-->
|
||||||
|
@ -5,7 +5,7 @@ buildscript {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:8.2.1'
|
classpath 'com.android.tools.build:gradle:8.2.2'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user