Skip to content

Commit cd46a2f

Browse files
committed
staging
1 parent fc67140 commit cd46a2f

File tree

9 files changed

+186
-24
lines changed

9 files changed

+186
-24
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ helper/build/
1717
lazybox/build/
1818
avbImpl/build/
1919
bbootimg/build/
20+
aosp/libsparse/sparse/build/
21+
aosp/libsparse/simg2simg/build/
22+
aosp/apksigner/bin/
23+
aosp/boot_signer/bin/
24+
bbootimg/bin/
25+
helper/bin/
26+
build/

bbootimg/src/main/kotlin/packable/MiscImgParser.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory
2020
import rom.misc.MiscImage
2121
import java.io.File
2222
import java.io.RandomAccessFile
23+
import kotlin.io.nameWithoutExtension
2324
import kotlin.io.path.Path
2425
import kotlin.io.path.deleteIfExists
2526

@@ -63,7 +64,7 @@ class MiscImgParser : IPackable {
6364
log.info("${out.name} is ready")
6465
}
6566

66-
override fun flash(fileName: String, deviceName: String) {
67+
fun flash(fileName: String) {
6768
val stem = fileName.substring(0, fileName.indexOf("."))
6869
super.flash("$fileName.new", stem)
6970
}
@@ -72,8 +73,8 @@ class MiscImgParser : IPackable {
7273
super.`@verify`(fileName)
7374
}
7475

75-
override fun pull(fileName: String, deviceName: String) {
76-
super.pull(fileName, deviceName)
76+
fun pull(fileName: String) {
77+
super.pull(fileName, File(fileName).nameWithoutExtension)
7778
}
7879

7980
fun clear(fileName: String) {

bbootimg/src/main/kotlin/rom/misc/MiscImage.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ data class MiscImage(
2626
ret.virtualAB = VirtualABMessage(fis)
2727
} catch (e: IllegalArgumentException) {
2828
log.info(e.toString())
29+
} catch (e: IllegalStateException) {
30+
log.info(e.toString())
2931
}
3032
}
3133
FileInputStream(fileName).use { fis ->

lazybox/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies {
2424
implementation("org.slf4j:slf4j-api:2.0.9")
2525
implementation("org.apache.commons:commons-compress:1.26.0")
2626
implementation("com.github.freva:ascii-table:1.8.0")
27+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
2728
// Use the Kotlin JUnit 5 integration.
2829
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
2930
// Use the JUnit 5 integration.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,132 @@
11
package cfig.lazybox
22

3+
import cfig.lazybox.sysinfo.SysInfo.Companion.runAndWrite
4+
import org.slf4j.LoggerFactory
5+
import java.io.ByteArrayOutputStream
6+
import java.io.File
7+
import java.io.FileOutputStream
8+
39
class AMS {
10+
enum class StandbyBucket(val id: Int) {
11+
STANDBY_BUCKET_EXEMPTED(5),
12+
STANDBY_BUCKET_ACTIVE(10),
13+
STANDBY_BUCKET_WORKING_SET(20),
14+
STANDBY_BUCKET_FREQUENT(30),
15+
STANDBY_BUCKET_RARE(40),
16+
STANDBY_BUCKET_RESTRICTED(45),
17+
STANDBY_BUCKET_NEVER(50);
18+
19+
companion object {
20+
fun fromValue(value: Int): StandbyBucket? = StandbyBucket.entries.firstOrNull { it.id == value }
21+
}
22+
}
23+
24+
companion object {
25+
val log = LoggerFactory.getLogger(AMS::class.qualifiedName)
26+
fun getProcRank(): MutableList<String> {
27+
val pkgRank: MutableList<String> = mutableListOf()
28+
ByteArrayOutputStream().use {
29+
runAndWrite("adb shell procrank", it, true)
30+
it.toString().split("\n").subList(1, 21).forEachIndexed { i, line ->
31+
val pkg = line.trim().split("\\s+".toRegex()).last()
32+
pkgRank.add(pkg)
33+
}
34+
}
35+
36+
//print pkgRank items, with index and content
37+
38+
FileOutputStream("proc_rank.log").use {
39+
pkgRank.forEachIndexed { i, s ->
40+
it.write("$s\n".toByteArray())
41+
}
42+
}
43+
return pkgRank
44+
}
45+
46+
fun getStandbyBucket(): HashMap<StandbyBucket, MutableList<String>> {
47+
val buckets: HashMap<StandbyBucket, MutableList<String>> = hashMapOf(
48+
StandbyBucket.STANDBY_BUCKET_EXEMPTED to mutableListOf(),
49+
StandbyBucket.STANDBY_BUCKET_ACTIVE to mutableListOf(),
50+
StandbyBucket.STANDBY_BUCKET_WORKING_SET to mutableListOf(),
51+
StandbyBucket.STANDBY_BUCKET_FREQUENT to mutableListOf(),
52+
StandbyBucket.STANDBY_BUCKET_RARE to mutableListOf(),
53+
StandbyBucket.STANDBY_BUCKET_RESTRICTED to mutableListOf(),
54+
StandbyBucket.STANDBY_BUCKET_NEVER to mutableListOf(),
55+
)
56+
ByteArrayOutputStream().use {
57+
runAndWrite("adb shell am get-standby-bucket", it, true)
58+
it.toString().trim().split("\n").forEachIndexed { i, line ->
59+
log.info("#$i: $line")
60+
if (line.split(":").size == 2) {
61+
val b = line.split(":").get(0).trim()
62+
val a = line.split(":").get(1).trim()
63+
log.info("[$a]-[$b]")
64+
buckets[StandbyBucket.fromValue(a.toInt())]!!.add(b)
65+
}
66+
}
67+
}
68+
StandbyBucket.entries.forEach {
69+
log.info(it.toString() + "(${it.id})")
70+
buckets[it]!!.apply { sort() }.forEach {
71+
log.info("\t$it")
72+
}
73+
}
74+
return buckets
75+
}
76+
77+
fun getStandbyBucket2(): HashMap<String, StandbyBucket> {
78+
val ret: HashMap<String, StandbyBucket> = HashMap<String, StandbyBucket>()
79+
ByteArrayOutputStream().use {
80+
runAndWrite("adb shell am get-standby-bucket", it, true)
81+
it.toString().trim().split("\n").forEachIndexed { i, line ->
82+
log.info("#$i: $line")
83+
if (line.split(":").size == 2) {
84+
val b = line.split(":").get(0).trim()
85+
val a = line.split(":").get(1).trim()
86+
log.info("[$a]-[$b]")
87+
ret.put(b, StandbyBucket.fromValue(a.toInt())!!)
88+
}
89+
}
90+
}
91+
return ret
92+
}
93+
94+
fun getOom() {
95+
val text = ByteArrayOutputStream().use {
96+
runAndWrite("adb shell dumpsys activity oom", it, true)
97+
it.toString()
98+
}
99+
log.info(text)
100+
val lines = text.trim().split("\n") // Split lines
101+
val regex = Regex("""^ +Proc #\d+: (.*?) +oom: max=\d+ curRaw=(-?\d+) setRaw=(-?\d+) cur=(-?\d+) set=(-?\d+)""") // Match relevant parts
102+
val results = lines.mapNotNull { line ->
103+
val matchResult = regex.matchEntire(line) ?: return@mapNotNull null
104+
val groups = matchResult.groups
105+
// Extract data from groups
106+
val packageName = groups[1]?.value ?: ""
107+
val oomCurValue = groups[2]?.value?.toIntOrNull() ?: 0
108+
val status = groups[3]?.value ?: ""
109+
110+
// Create the Any array
111+
arrayOf(packageName, oomCurValue, status)
112+
log.info("$packageName -> $oomCurValue -> $status")
113+
}
114+
}
115+
116+
117+
fun computeRankAndBucket(rank: MutableList<String>, bkt: HashMap<String, StandbyBucket>) {
118+
val sb = StringBuilder()
119+
rank.forEach {
120+
val bktEntry = bkt.get(it)
121+
if (bktEntry != null) {
122+
sb.append(String.format("%-40s %s\n", it, bktEntry))
123+
} else {
124+
sb.append(String.format("%-40s -\n", it))
125+
}
126+
}
127+
log.info("Writing to rank_bucket.log ...\n$sb")
128+
File("rank_bucket.log").writeText(sb.toString())
129+
}
130+
131+
}
4132
}

lazybox/src/main/kotlin/cfig/lazybox/App.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ fun main(args: Array<String>) {
2424
println("tracecmd : analyze trace-cmd report")
2525
println("cpuinfo : get cpu info from /sys/devices/system/cpu/")
2626
println("sysinfo : get overall system info from Android")
27+
println("\nIncubating usage:")
28+
println("apps : get apk file list from Android")
2729
exitProcess(0)
2830
}
2931
if (args[0] == "cpuinfo") {
@@ -65,4 +67,10 @@ fun main(args: Array<String>) {
6567
}
6668
CompileCommand().run(args[1], args[2])
6769
}
70+
if (args[0] == "apps") {
71+
AppList.retrieveList()
72+
}
73+
if (args[0] == "x") {
74+
AMS.computeRankAndBucket(AMS.getProcRank(), AMS.getStandbyBucket2())
75+
}
6876
}

lazybox/src/main/kotlin/cfig/lazybox/sysinfo/SysInfo.kt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,6 @@ import kotlin.io.path.writeText
1717
import java.io.ByteArrayOutputStream
1818

1919
class SysInfo {
20-
private fun runAndWrite(cmd: String, outStream: OutputStream, check: Boolean) {
21-
Helper.powerRun2(cmd, null).let {
22-
if (it[0] as Boolean) {
23-
outStream.write(it[1] as ByteArray)
24-
} else {
25-
if (check) {
26-
log.warn(String(it[1] as ByteArray))
27-
throw RuntimeException(String(it[2] as ByteArray))
28-
} else {
29-
log.warn(String(it[1] as ByteArray))
30-
log.warn(String(it[2] as ByteArray))
31-
}
32-
}
33-
}
34-
}
3520

3621
fun makeTar(tarFile: String, srcDir: String, fmt: String) {
3722
val pyScript =
@@ -153,5 +138,22 @@ makeTar("%s", "%s")
153138

154139
companion object {
155140
private val log = LoggerFactory.getLogger(SysInfo::class.java)
141+
142+
fun runAndWrite(cmd: String, outStream: OutputStream, check: Boolean) {
143+
Helper.powerRun2(cmd, null).let {
144+
if (it[0] as Boolean) {
145+
outStream.write(it[1] as ByteArray)
146+
} else {
147+
if (check) {
148+
log.warn(String(it[1] as ByteArray))
149+
log.warn(String(it[2] as ByteArray))
150+
throw RuntimeException(String(it[2] as ByteArray))
151+
} else {
152+
outStream.write(it[1] as ByteArray)
153+
outStream.write(it[2] as ByteArray)
154+
}
155+
}
156+
}
157+
}
156158
}
157159
}

tools/factory_image_parser.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
"vendor_boot.img",
3939
"vendor_dlkm.img",
4040
"vendor.img",
41-
"vendor_kernel_boot.img"
41+
"vendor_kernel_boot.img",
42+
"odm.img",
43+
"recovery.img",
4244
]
4345

4446
unknown_list = [
@@ -67,6 +69,10 @@
6769
"ldfw.img", #Pixel8a
6870
"pbl.img", #Pixel8a
6971
"tzsw.img", #Pixel8a
72+
"logo.img", #ADT-3
73+
"super_empty_all.img", #ADT-3
74+
"bootloader.img", #many
75+
"dt.img",
7076
]
7177

7278
tmp2 = "tmp2"

tools/abe renamed to tools/local/bin/abe

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,35 @@ if [[ $# -eq 0 ]]; then
1111
fi
1212

1313
operation=$1
14+
echo arg num: $#
15+
echo "args: $0 $1 $2"
1416

1517
# Determine which operation to perform
1618
case $operation in
1719
"unpack")
18-
if [[ $# -eq 3 ]]; then
20+
if [[ $# -eq 2 ]]; then
21+
file=`realpath $2`
22+
dir=`realpath out`
23+
cd ${baseDir}/../../../
24+
gradle unpack --args="unpackInternal $file $dir"
25+
elif [[ $# -eq 3 ]]; then
1926
file=`realpath $2`
2027
dir=`realpath $3`
21-
cd ${baseDir}/../
28+
cd ${baseDir}/../../../
2229
gradle unpack --args="unpackInternal $file $dir"
2330
else
24-
cd ${baseDir}/../
31+
cd ${baseDir}/../../../
2532
gradle unpack
2633
fi
2734
;;
2835
"pack")
2936
if [[ $# -eq 3 ]]; then
3037
dir=`realpath $2`
3138
file=`realpath $3`
32-
cd ${baseDir}/../
39+
cd ${baseDir}/../../../
3340
gradle pack --args="packInternal $dir $file"
3441
else
35-
cd ${baseDir}/../
42+
cd ${baseDir}/../../../
3643
gradle pack
3744
fi
3845
;;

0 commit comments

Comments
 (0)