-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): add filtered logcat to am instrument parser
- Loading branch information
Showing
7 changed files
with
177 additions
and
92 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/AndroidDevice.kt
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
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
42 changes: 42 additions & 0 deletions
42
...oid/src/main/kotlin/com/malinskiy/marathon/android/adam/log/LogcatAccumulatingListener.kt
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,42 @@ | ||
package com.malinskiy.marathon.android.adam.log | ||
|
||
import com.malinskiy.marathon.android.logcat.LogcatListener | ||
import com.malinskiy.marathon.android.logcat.LogcatProducer | ||
|
||
class LogcatAccumulatingListener( | ||
private val logcatProducer: LogcatProducer, | ||
) : LogcatListener { | ||
private val stringBuffer = StringBuffer(4096) | ||
private val allowlist = setOf("AndroidJUnitRunner", "AndroidRuntime") | ||
|
||
override suspend fun onMessage(msg: LogCatMessage) { | ||
if (allowlist.contains(msg.tag)) { | ||
when (msg.logLevel) { | ||
Log.LogLevel.ERROR, Log.LogLevel.WARN -> stringBuffer.appendLine("${msg.logLevel.priorityLetter}/${msg.tag}: ${msg.message}\"") | ||
else -> Unit | ||
} | ||
} | ||
} | ||
|
||
fun setup() { | ||
logcatProducer.addLogcatListener(this) | ||
} | ||
|
||
fun finish() { | ||
logcatProducer.removeLogcatListener(this) | ||
} | ||
|
||
fun start() { | ||
stringBuffer.reset() | ||
} | ||
|
||
fun stop(): String { | ||
val log = stringBuffer.toString() | ||
stringBuffer.reset() | ||
return log | ||
} | ||
|
||
private fun StringBuffer.reset() { | ||
delete(0, length) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...or/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/logcat/LogcatListener.kt
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,9 @@ | ||
package com.malinskiy.marathon.android.logcat | ||
|
||
import com.malinskiy.marathon.android.adam.log.LogCatMessage | ||
|
||
interface LogcatListener : AutoCloseable { | ||
suspend fun onMessage(message: LogCatMessage) | ||
|
||
override fun close() {} | ||
} |
6 changes: 6 additions & 0 deletions
6
...or/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/logcat/LogcatProducer.kt
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,6 @@ | ||
package com.malinskiy.marathon.android.logcat | ||
|
||
interface LogcatProducer { | ||
fun addLogcatListener(listener: LogcatListener) | ||
fun removeLogcatListener(listener: LogcatListener) | ||
} |