Skip to content

Commit b1707d6

Browse files
committed
clean code
1 parent 48cf7dd commit b1707d6

3 files changed

Lines changed: 13 additions & 17 deletions

File tree

app/core/src/main/java/com/topjohnwu/magisk/core/tasks/ExtractImage.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class ExtractImage(
4141
}
4242
}
4343
zipFile.getRawInputStream(payload)
44-
extractFromOTAPackage(payload, channel, outFile)
44+
extractFromOTAPackage(payload, channel)
4545
} else {
46-
extractFromFactoryImage(zipFile, channel, outFile)
46+
extractFromFactoryImage(zipFile, channel)
4747
}
4848
}
4949
}
@@ -52,27 +52,25 @@ class ExtractImage(
5252
private fun extractFromOTAPackage(
5353
payload: ZipArchiveEntry,
5454
channel: DataSourceChannel,
55-
outFile: File,
5655
) {
5756
if (payload.method != ZipMethod.STORED.code) {
5857
throw IOException("payload.bin is compressed, expected STORED method")
5958
}
6059

6160
channel.slice(payload.dataOffset, payload.size).use { payloadChannel ->
62-
Payload(payloadChannel).extract(outFile, { console.add(it) }, { logs.add(it) })
61+
Payload(payloadChannel).extract(outFile, console, logs)
6362
}
6463
}
6564

6665
@Throws(IOException::class)
6766
private fun extractFromFactoryImage(
6867
zipFile: ZipFile,
6968
channel: DataSourceChannel,
70-
outFile: File
7169
) {
7270
console.add("- Processing as factory image package")
7371

7472
findBootImageZipEntry(zipFile)?.let { entry ->
75-
return extractImageFile(zipFile, entry, channel, outFile)
73+
return extractImageFile(zipFile, entry, channel)
7674
}
7775

7876
val imageZipEntry = zipFile.entries.asSequence().find { entry ->
@@ -81,7 +79,7 @@ class ExtractImage(
8179
}
8280
if (imageZipEntry != null) {
8381
zipFile.getRawInputStream(imageZipEntry)
84-
return extractFromInnerImageZip(imageZipEntry, channel, outFile)
82+
return extractFromInnerImageZip(imageZipEntry, channel)
8583
}
8684

8785
throw IOException("inner image ZIP not found in factory image package")
@@ -99,7 +97,6 @@ class ExtractImage(
9997
private fun extractFromInnerImageZip(
10098
entry: ZipArchiveEntry,
10199
channel: DataSourceChannel,
102-
outFile: File
103100
) {
104101
logs.add("Found inner image ZIP: ${entry.name}")
105102

@@ -114,7 +111,7 @@ class ExtractImage(
114111
.get().use { innerZipFile ->
115112
val targetEntry = findBootImageZipEntry(innerZipFile)
116113
?: throw IOException("boot image not found in inner image ZIP")
117-
return extractImageFile(innerZipFile, targetEntry, innerZipChannel, outFile)
114+
return extractImageFile(innerZipFile, targetEntry, innerZipChannel)
118115
}
119116
}
120117
}
@@ -124,7 +121,6 @@ class ExtractImage(
124121
zipFile: ZipFile,
125122
entry: ZipArchiveEntry,
126123
channel: DataSourceChannel,
127-
outFile: File,
128124
) {
129125
console.add("- Found boot image entry: ${entry.name} (${entry.size} bytes)")
130126
console.add("- Downloading")

app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ abstract class MagiskInstallImpl protected constructor(
368368
try {
369369
if (magic.contentEquals("CrAU".toByteArray())) {
370370
DataSourceChannel(channel).use { source ->
371-
Payload(source).extract(boot, { console.add(it) }, { logs.add(it) })
371+
Payload(source).extract(boot, console, logs)
372372
}
373373
} else if (magic.contentEquals("PK\u0003\u0004".toByteArray())) {
374374
ExtractImage(boot, console, logs).consume(DataSourceChannel(channel))

app/core/src/main/java/com/topjohnwu/magisk/core/tasks/Payload.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class Payload(private val channel: DataSourceChannel) {
2323
}
2424

2525
@Throws(IOException::class)
26-
fun extract(outputFile: File, console: (String) -> Unit, logger: (String) -> Unit) {
26+
fun extract(outputFile: File, console: MutableList<String>, logger: MutableList<String>) {
2727
val partition = findPartition()
28-
console("- Found partition ${partition.partition_name}")
28+
console.add("- Found partition ${partition.partition_name}")
2929

3030
val actualHash = extractPartition(outputFile, partition, console)
3131

3232
val newPartitionInfo = partition.new_partition_info
3333
if (newPartitionInfo?.hash == null) {
34-
logger("Hash verification skipped")
34+
logger.add("Hash verification skipped")
3535
return
3636
}
3737

@@ -43,7 +43,7 @@ class Payload(private val channel: DataSourceChannel) {
4343
"Hash mismatch, expected ${toHex(expectedHash)}, but got ${toHex(actualHash)}"
4444
)
4545
}
46-
logger("Hash verification passed")
46+
logger.add("Hash verification passed")
4747
}
4848

4949
@Throws(IOException::class)
@@ -109,7 +109,7 @@ class Payload(private val channel: DataSourceChannel) {
109109
private fun extractPartition(
110110
outputFile: File,
111111
partition: PartitionUpdate,
112-
console: (String) -> Unit,
112+
console: MutableList<String>,
113113
): ByteArray {
114114
FileChannel.open(
115115
outputFile.toPath(),
@@ -124,7 +124,7 @@ class Payload(private val channel: DataSourceChannel) {
124124
val count = partition.operations.size
125125
partition.operations.forEachIndexed { index, operation ->
126126
if (index % 5 == 0 || index == count - 1) {
127-
console("- Downloading ${index + 1}/$count")
127+
console.add("- Downloading ${index + 1}/$count")
128128
}
129129
processOperation(outChannel, operation)
130130
}

0 commit comments

Comments
 (0)