This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
166 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.sanmer.mrepo.app | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import timber.log.Timber | ||
import java.time.LocalDateTime | ||
|
||
object Logcat { | ||
val logfile get() = "MRepo_${LocalDateTime.now()}.log" | ||
|
||
private suspend fun dump(context: Context) = withContext(Dispatchers.IO) { | ||
val uid = context.applicationInfo.uid | ||
val command = arrayOf( | ||
"logcat", | ||
"-d", | ||
"--uid=${uid}" | ||
) | ||
|
||
try { | ||
val process = Runtime.getRuntime().exec(command) | ||
|
||
val result = process.inputStream.use { stream -> | ||
stream.reader().readLines() | ||
.filterNot { it.startsWith("------") } | ||
.joinToString("\n") | ||
} | ||
|
||
process.waitFor() | ||
|
||
result.trim() | ||
} catch (e: Exception) { | ||
"" | ||
} | ||
} | ||
|
||
suspend fun write( | ||
context: Context, | ||
writer: (ByteArray) -> Unit | ||
) = withContext(Dispatchers.IO) { | ||
val logs = dump(context) | ||
writer(logs.toByteArray()) | ||
} | ||
|
||
suspend fun writeTo(context: Context, uri: Uri) = withContext(Dispatchers.IO) { | ||
runCatching { | ||
val cr = context.contentResolver | ||
cr.openOutputStream(uri)?.use { | ||
write(context, it::write) | ||
} | ||
}.onFailure { | ||
Timber.d(it) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:pathData="M9,9v-1a3,3 0,0 1,6 0v1" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="2" | ||
android:strokeColor="#ffff" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="M8,9h8a6,6 0,0 1,1 3v3a5,5 0,0 1,-10 0v-3a6,6 0,0 1,1 -3" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="2" | ||
android:strokeColor="#ffff" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="M3,13l4,0" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="2" | ||
android:strokeColor="#ffff" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="M17,13l4,0" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="2" | ||
android:strokeColor="#ffff" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="M12,20l0,-6" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="2" | ||
android:strokeColor="#ffff" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="M4,19l3.35,-2" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="2" | ||
android:strokeColor="#ffff" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="M20,19l-3.35,-2" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="2" | ||
android:strokeColor="#ffff" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="M4,7l3.75,2.4" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="2" | ||
android:strokeColor="#ffff" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="M20,7l-3.75,2.4" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="2" | ||
android:strokeColor="#ffff" | ||
android:strokeLineCap="round"/> | ||
</vector> |