dev
cfig 2 months ago
parent fc67140c2d
commit cd46a2fe6c

7
.gitignore vendored

@ -17,3 +17,10 @@ helper/build/
lazybox/build/
avbImpl/build/
bbootimg/build/
aosp/libsparse/sparse/build/
aosp/libsparse/simg2simg/build/
aosp/apksigner/bin/
aosp/boot_signer/bin/
bbootimg/bin/
helper/bin/
build/

@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory
import rom.misc.MiscImage
import java.io.File
import java.io.RandomAccessFile
import kotlin.io.nameWithoutExtension
import kotlin.io.path.Path
import kotlin.io.path.deleteIfExists
@ -63,7 +64,7 @@ class MiscImgParser : IPackable {
log.info("${out.name} is ready")
}
override fun flash(fileName: String, deviceName: String) {
fun flash(fileName: String) {
val stem = fileName.substring(0, fileName.indexOf("."))
super.flash("$fileName.new", stem)
}
@ -72,8 +73,8 @@ class MiscImgParser : IPackable {
super.`@verify`(fileName)
}
override fun pull(fileName: String, deviceName: String) {
super.pull(fileName, deviceName)
fun pull(fileName: String) {
super.pull(fileName, File(fileName).nameWithoutExtension)
}
fun clear(fileName: String) {

@ -26,6 +26,8 @@ data class MiscImage(
ret.virtualAB = VirtualABMessage(fis)
} catch (e: IllegalArgumentException) {
log.info(e.toString())
} catch (e: IllegalStateException) {
log.info(e.toString())
}
}
FileInputStream(fileName).use { fis ->

@ -24,6 +24,7 @@ dependencies {
implementation("org.slf4j:slf4j-api:2.0.9")
implementation("org.apache.commons:commons-compress:1.26.0")
implementation("com.github.freva:ascii-table:1.8.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
// Use the Kotlin JUnit 5 integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
// Use the JUnit 5 integration.

@ -1,4 +1,132 @@
package cfig.lazybox
import cfig.lazybox.sysinfo.SysInfo.Companion.runAndWrite
import org.slf4j.LoggerFactory
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileOutputStream
class AMS {
enum class StandbyBucket(val id: Int) {
STANDBY_BUCKET_EXEMPTED(5),
STANDBY_BUCKET_ACTIVE(10),
STANDBY_BUCKET_WORKING_SET(20),
STANDBY_BUCKET_FREQUENT(30),
STANDBY_BUCKET_RARE(40),
STANDBY_BUCKET_RESTRICTED(45),
STANDBY_BUCKET_NEVER(50);
companion object {
fun fromValue(value: Int): StandbyBucket? = StandbyBucket.entries.firstOrNull { it.id == value }
}
}
companion object {
val log = LoggerFactory.getLogger(AMS::class.qualifiedName)
fun getProcRank(): MutableList<String> {
val pkgRank: MutableList<String> = mutableListOf()
ByteArrayOutputStream().use {
runAndWrite("adb shell procrank", it, true)
it.toString().split("\n").subList(1, 21).forEachIndexed { i, line ->
val pkg = line.trim().split("\\s+".toRegex()).last()
pkgRank.add(pkg)
}
}
//print pkgRank items, with index and content
FileOutputStream("proc_rank.log").use {
pkgRank.forEachIndexed { i, s ->
it.write("$s\n".toByteArray())
}
}
return pkgRank
}
fun getStandbyBucket(): HashMap<StandbyBucket, MutableList<String>> {
val buckets: HashMap<StandbyBucket, MutableList<String>> = hashMapOf(
StandbyBucket.STANDBY_BUCKET_EXEMPTED to mutableListOf(),
StandbyBucket.STANDBY_BUCKET_ACTIVE to mutableListOf(),
StandbyBucket.STANDBY_BUCKET_WORKING_SET to mutableListOf(),
StandbyBucket.STANDBY_BUCKET_FREQUENT to mutableListOf(),
StandbyBucket.STANDBY_BUCKET_RARE to mutableListOf(),
StandbyBucket.STANDBY_BUCKET_RESTRICTED to mutableListOf(),
StandbyBucket.STANDBY_BUCKET_NEVER to mutableListOf(),
)
ByteArrayOutputStream().use {
runAndWrite("adb shell am get-standby-bucket", it, true)
it.toString().trim().split("\n").forEachIndexed { i, line ->
log.info("#$i: $line")
if (line.split(":").size == 2) {
val b = line.split(":").get(0).trim()
val a = line.split(":").get(1).trim()
log.info("[$a]-[$b]")
buckets[StandbyBucket.fromValue(a.toInt())]!!.add(b)
}
}
}
StandbyBucket.entries.forEach {
log.info(it.toString() + "(${it.id})")
buckets[it]!!.apply { sort() }.forEach {
log.info("\t$it")
}
}
return buckets
}
fun getStandbyBucket2(): HashMap<String, StandbyBucket> {
val ret: HashMap<String, StandbyBucket> = HashMap<String, StandbyBucket>()
ByteArrayOutputStream().use {
runAndWrite("adb shell am get-standby-bucket", it, true)
it.toString().trim().split("\n").forEachIndexed { i, line ->
log.info("#$i: $line")
if (line.split(":").size == 2) {
val b = line.split(":").get(0).trim()
val a = line.split(":").get(1).trim()
log.info("[$a]-[$b]")
ret.put(b, StandbyBucket.fromValue(a.toInt())!!)
}
}
}
return ret
}
fun getOom() {
val text = ByteArrayOutputStream().use {
runAndWrite("adb shell dumpsys activity oom", it, true)
it.toString()
}
log.info(text)
val lines = text.trim().split("\n") // Split lines
val regex = Regex("""^ +Proc #\d+: (.*?) +oom: max=\d+ curRaw=(-?\d+) setRaw=(-?\d+) cur=(-?\d+) set=(-?\d+)""") // Match relevant parts
val results = lines.mapNotNull { line ->
val matchResult = regex.matchEntire(line) ?: return@mapNotNull null
val groups = matchResult.groups
// Extract data from groups
val packageName = groups[1]?.value ?: ""
val oomCurValue = groups[2]?.value?.toIntOrNull() ?: 0
val status = groups[3]?.value ?: ""
// Create the Any array
arrayOf(packageName, oomCurValue, status)
log.info("$packageName -> $oomCurValue -> $status")
}
}
fun computeRankAndBucket(rank: MutableList<String>, bkt: HashMap<String, StandbyBucket>) {
val sb = StringBuilder()
rank.forEach {
val bktEntry = bkt.get(it)
if (bktEntry != null) {
sb.append(String.format("%-40s %s\n", it, bktEntry))
} else {
sb.append(String.format("%-40s -\n", it))
}
}
log.info("Writing to rank_bucket.log ...\n$sb")
File("rank_bucket.log").writeText(sb.toString())
}
}
}

@ -24,6 +24,8 @@ fun main(args: Array<String>) {
println("tracecmd : analyze trace-cmd report")
println("cpuinfo : get cpu info from /sys/devices/system/cpu/")
println("sysinfo : get overall system info from Android")
println("\nIncubating usage:")
println("apps : get apk file list from Android")
exitProcess(0)
}
if (args[0] == "cpuinfo") {
@ -65,4 +67,10 @@ fun main(args: Array<String>) {
}
CompileCommand().run(args[1], args[2])
}
if (args[0] == "apps") {
AppList.retrieveList()
}
if (args[0] == "x") {
AMS.computeRankAndBucket(AMS.getProcRank(), AMS.getStandbyBucket2())
}
}

@ -17,21 +17,6 @@ import kotlin.io.path.writeText
import java.io.ByteArrayOutputStream
class SysInfo {
private fun runAndWrite(cmd: String, outStream: OutputStream, check: Boolean) {
Helper.powerRun2(cmd, null).let {
if (it[0] as Boolean) {
outStream.write(it[1] as ByteArray)
} else {
if (check) {
log.warn(String(it[1] as ByteArray))
throw RuntimeException(String(it[2] as ByteArray))
} else {
log.warn(String(it[1] as ByteArray))
log.warn(String(it[2] as ByteArray))
}
}
}
}
fun makeTar(tarFile: String, srcDir: String, fmt: String) {
val pyScript =
@ -153,5 +138,22 @@ makeTar("%s", "%s")
companion object {
private val log = LoggerFactory.getLogger(SysInfo::class.java)
fun runAndWrite(cmd: String, outStream: OutputStream, check: Boolean) {
Helper.powerRun2(cmd, null).let {
if (it[0] as Boolean) {
outStream.write(it[1] as ByteArray)
} else {
if (check) {
log.warn(String(it[1] as ByteArray))
log.warn(String(it[2] as ByteArray))
throw RuntimeException(String(it[2] as ByteArray))
} else {
outStream.write(it[1] as ByteArray)
outStream.write(it[2] as ByteArray)
}
}
}
}
}
}

@ -38,7 +38,9 @@ known_list = [
"vendor_boot.img",
"vendor_dlkm.img",
"vendor.img",
"vendor_kernel_boot.img"
"vendor_kernel_boot.img",
"odm.img",
"recovery.img",
]
unknown_list = [
@ -67,6 +69,10 @@ unknown_list = [
"ldfw.img", #Pixel8a
"pbl.img", #Pixel8a
"tzsw.img", #Pixel8a
"logo.img", #ADT-3
"super_empty_all.img", #ADT-3
"bootloader.img", #many
"dt.img",
]
tmp2 = "tmp2"

@ -11,17 +11,24 @@ if [[ $# -eq 0 ]]; then
fi
operation=$1
echo arg num: $#
echo "args: $0 $1 $2"
# Determine which operation to perform
case $operation in
"unpack")
if [[ $# -eq 3 ]]; then
if [[ $# -eq 2 ]]; then
file=`realpath $2`
dir=`realpath out`
cd ${baseDir}/../../../
gradle unpack --args="unpackInternal $file $dir"
elif [[ $# -eq 3 ]]; then
file=`realpath $2`
dir=`realpath $3`
cd ${baseDir}/../
cd ${baseDir}/../../../
gradle unpack --args="unpackInternal $file $dir"
else
cd ${baseDir}/../
cd ${baseDir}/../../../
gradle unpack
fi
;;
@ -29,10 +36,10 @@ case $operation in
if [[ $# -eq 3 ]]; then
dir=`realpath $2`
file=`realpath $3`
cd ${baseDir}/../
cd ${baseDir}/../../../
gradle pack --args="packInternal $dir $file"
else
cd ${baseDir}/../
cd ${baseDir}/../../../
gradle pack
fi
;;
Loading…
Cancel
Save