Skip to content

Commit

Permalink
Add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithTamim committed Jan 4, 2025
1 parent a3af84c commit 9a90cc3
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 16 deletions.
9 changes: 5 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-sdk
android:minSdkVersion="21"
tools:overrideLibrary="com.tencent.mmkv" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
Expand All @@ -22,6 +21,9 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:targetApi="31">
<activity
android:name=".ui.DebugLogsActivity"
android:exported="false" />
<activity
android:name=".ui.AboutActivity"
android:exported="false" />
Expand All @@ -38,7 +40,6 @@
</intent-filter>
</activity>


<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
Expand Down
77 changes: 77 additions & 0 deletions app/src/main/java/com/nasahacker/steelmind/ui/DebugLogsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.nasahacker.steelmind.ui

import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.widget.TextView
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import com.nasahacker.steelmind.BuildConfig
import com.nasahacker.steelmind.R
import com.nasahacker.steelmind.databinding.ActivityDebugLogsBinding
import kotlinx.coroutines.*
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader

class DebugLogsActivity : AppCompatActivity() {
private val binding by lazy { ActivityDebugLogsBinding.inflate(layoutInflater) }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(binding.root)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

setSupportActionBar(binding.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)

binding.toolbar.setNavigationOnClickListener {
onBackPressedDispatcher.onBackPressed()
}

binding.toolbar.setOnMenuItemClickListener {
if (it.itemId == R.id.deleteAll) {
binding.logstv.text = ""
Toast.makeText(this, getString(R.string.success), Toast.LENGTH_SHORT).show()
}
true
}

startLogcatReader()
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.delete_menu, menu)
return true
}


private fun startLogcatReader() {
lifecycleScope.launch(Dispatchers.IO) {
try {
val process = Runtime.getRuntime().exec("logcat")
val bufferedReader = BufferedReader(InputStreamReader(process.inputStream))
var line: String?
while (bufferedReader.readLine().also { line = it } != null) {
val log = line!!

withContext(Dispatchers.Main) {
binding.logstv.append("\n$log")
}
}
} catch (e: IOException) {
e.printStackTrace()
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class HistoryActivity : AppCompatActivity(), OnClickListener {
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.history_menu, menu)
menuInflater.inflate(R.menu.delete_menu, menu)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class MainActivity : AppCompatActivity() {
R.id.top_history -> startActivity(Intent(this, HistoryActivity::class.java))
R.id.top_export -> handleExportAction()
R.id.top_import -> pickJsonFileLauncher.launch(arrayOf("application/json"))
R.id.debug_logs -> startActivity(Intent(this, DebugLogsActivity::class.java))
R.id.top_license -> LibsBuilder()
.withActivityTitle(getString(R.string.open_source_licenses))
.start(this)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_bug_report_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="@color/iconColor" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@color/iconColor" android:pathData="M20,8h-2.81c-0.45,-0.78 -1.07,-1.45 -1.82,-1.96L17,4.41 15.59,3l-2.17,2.17C12.96,5.06 12.49,5 12,5c-0.49,0 -0.96,0.06 -1.41,0.17L8.41,3 7,4.41l1.62,1.63C7.88,6.55 7.26,7.22 6.81,8L4,8v2h2.09c-0.05,0.33 -0.09,0.66 -0.09,1v1L4,12v2h2v1c0,0.34 0.04,0.67 0.09,1L4,16v2h2.81c1.04,1.79 2.97,3 5.19,3s4.15,-1.21 5.19,-3L20,18v-2h-2.09c0.05,-0.33 0.09,-0.66 0.09,-1v-1h2v-2h-2v-1c0,-0.34 -0.04,-0.67 -0.09,-1L20,10L20,8zM14,16h-4v-2h4v2zM14,12h-4v-2h4v2z"/>

</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/file_export_24px.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
android:tint="@color/iconColor">
<path
android:fillColor="@android:color/white"
android:fillColor="@color/iconColor"
android:pathData="M480,480L480,480Q480,480 480,480Q480,480 480,480L480,480L480,480L480,480Q480,480 480,480Q480,480 480,480L480,480L480,480ZM202,895L146,838L264,720L174,720L174,640L400,640L400,866L320,866L320,777L202,895ZM480,880L480,800L720,800Q720,800 720,800Q720,800 720,800L720,360L520,360L520,160L240,160Q240,160 240,160Q240,160 240,160L240,560L160,560L160,160Q160,127 183.5,103.5Q207,80 240,80L560,80L800,320L800,800Q800,833 776.5,856.5Q753,880 720,880L480,880Z"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/file_open_24px.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
android:tint="@color/iconColor">
<path
android:fillColor="@android:color/white"
android:fillColor="@color/iconColor"
android:pathData="M240,880Q207,880 183.5,856.5Q160,833 160,800L160,160Q160,127 183.5,103.5Q207,80 240,80L560,80L800,320L800,560L720,560L720,360L520,360L520,160L240,160Q240,160 240,160Q240,160 240,160L240,800Q240,800 240,800Q240,800 240,800L600,800L600,880L240,880ZM878,895L760,777L760,866L680,866L680,640L906,640L906,720L816,720L934,838L878,895ZM240,800L240,560L240,560L240,360L240,160L240,160Q240,160 240,160Q240,160 240,160L240,800Q240,800 240,800Q240,800 240,800Z"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/history_24px.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
android:tint="@color/iconColor">
<path
android:fillColor="@android:color/white"
android:fillColor="@color/iconColor"
android:pathData="M480,840Q342,840 239.5,748.5Q137,657 122,520L204,520Q218,624 296.5,692Q375,760 480,760Q597,760 678.5,678.5Q760,597 760,480Q760,363 678.5,281.5Q597,200 480,200Q411,200 351,232Q291,264 250,320L360,320L360,400L120,400L120,160L200,160L200,254Q251,190 324.5,155Q398,120 480,120Q555,120 620.5,148.5Q686,177 734.5,225.5Q783,274 811.5,339.5Q840,405 840,480Q840,555 811.5,620.5Q783,686 734.5,734.5Q686,783 620.5,811.5Q555,840 480,840ZM592,648L440,496L440,280L520,280L520,464L648,592L592,648Z"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/license_24px.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
android:tint="@color/iconColor">
<path
android:fillColor="@android:color/white"
android:fillColor="@color/iconColor"
android:pathData="M480,520Q430,520 395,485Q360,450 360,400Q360,350 395,315Q430,280 480,280Q530,280 565,315Q600,350 600,400Q600,450 565,485Q530,520 480,520ZM240,920L240,611Q202,569 181,515Q160,461 160,400Q160,266 253,173Q346,80 480,80Q614,80 707,173Q800,266 800,400Q800,461 779,515Q758,569 720,611L720,920L480,840L240,920ZM480,640Q580,640 650,570Q720,500 720,400Q720,300 650,230Q580,160 480,160Q380,160 310,230Q240,300 240,400Q240,500 310,570Q380,640 480,640ZM320,801L480,760L640,801L640,677Q605,697 564.5,708.5Q524,720 480,720Q436,720 395.5,708.5Q355,697 320,677L320,801ZM480,739L480,739Q480,739 480,739Q480,739 480,739Q480,739 480,739Q480,739 480,739L480,739L480,739Z"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/more_vert_24px.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
android:tint="@color/iconColor">
<path
android:fillColor="@android:color/white"
android:fillColor="@color/iconColor"
android:pathData="M480,800Q447,800 423.5,776.5Q400,753 400,720Q400,687 423.5,663.5Q447,640 480,640Q513,640 536.5,663.5Q560,687 560,720Q560,753 536.5,776.5Q513,800 480,800ZM480,560Q447,560 423.5,536.5Q400,513 400,480Q400,447 423.5,423.5Q447,400 480,400Q513,400 536.5,423.5Q560,447 560,480Q560,513 536.5,536.5Q513,560 480,560ZM480,320Q447,320 423.5,296.5Q400,273 400,240Q400,207 423.5,183.5Q447,160 480,160Q513,160 536.5,183.5Q560,207 560,240Q560,273 536.5,296.5Q513,320 480,320Z"/>
</vector>
37 changes: 37 additions & 0 deletions app/src/main/res/layout/activity_debug_logs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.DebugLogsActivity">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/delete_menu"
app:title="Debug Logs" />
</com.google.android.material.appbar.AppBarLayout>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/logstv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
android:padding="@dimen/_8sdp"
android:textIsSelectable="true"
tools:text="Hello" />
</ScrollView>

</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/history_menu"
app:menu="@menu/delete_menu"
app:title="History" />
</com.google.android.material.appbar.AppBarLayout>

Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions app/src/main/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
android:id="@+id/top_export"
android:icon="@drawable/file_export_24px"
android:title="Export Data" />
<item
android:id="@+id/debug_logs"
android:icon="@drawable/baseline_bug_report_24"
android:title="Debug Logs" />
<item
android:id="@+id/top_license"
android:icon="@drawable/license_24px"
Expand Down

0 comments on commit 9a90cc3

Please sign in to comment.