Skip to content

Commit 38bdda4

Browse files
committed
Fix DebugInfoExporter hanging
1 parent c9f8a96 commit 38bdda4

5 files changed

Lines changed: 47 additions & 47 deletions

File tree

app/src/main/java/io/nekohasekai/sfa/bg/DebugInfoExporter.kt

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import java.io.StringWriter
1313
import java.text.SimpleDateFormat
1414
import java.util.Date
1515
import java.util.Locale
16+
import java.util.zip.Deflater
1617
import java.util.zip.ZipEntry
1718
import java.util.zip.ZipOutputStream
1819

1920
object DebugInfoExporter {
2021
private const val TAG = "DebugInfoExporter"
22+
private const val BUFFER_SIZE = 128 * 1024
2123

2224
fun export(context: Context, outputPath: String, packageName: String): String {
2325
Log.i(TAG, "export start: output=$outputPath, package=$packageName")
@@ -94,43 +96,27 @@ object DebugInfoExporter {
9496

9597
private fun addFrameworkEntries(zip: ZipOutputStream, warnings: MutableList<String>): Int {
9698
var count = 0
97-
val roots =
98-
listOf(
99-
File("/system/framework"),
100-
File("/system_ext/framework"),
101-
File("/product/framework"),
102-
File("/vendor/framework"),
103-
)
99+
val root = File("/system/framework")
100+
if (!root.isDirectory) return 0
104101
val targetFiles = setOf("framework.jar", "services.jar")
105-
for (root in roots) {
106-
if (!root.isDirectory) continue
107-
val destPrefix = "framework/${root.name}"
108-
val files = root.listFiles() ?: emptyArray()
109-
for (file in files) {
110-
if (!file.isFile) continue
111-
if (file.name !in targetFiles) continue
112-
if (addFileEntry(zip, file, "$destPrefix/${file.name}", warnings)) {
113-
count++
114-
}
102+
val files = root.listFiles() ?: emptyArray()
103+
for (file in files) {
104+
if (!file.isFile) continue
105+
if (file.name !in targetFiles) continue
106+
if (addFileEntry(zip, file, "framework/${file.name}", warnings, noCompression = true)) {
107+
count++
115108
}
116109
}
117110
return count
118111
}
119112

120113
private fun addApexEntries(zip: ZipOutputStream, warnings: MutableList<String>): Int {
121-
var count = 0
122-
val tetheringApex = File("/apex/com.android.tethering/javalib")
123-
if (!tetheringApex.isDirectory) return 0
124-
val destPrefix = "framework/apex_com.android.tethering"
125-
val files = tetheringApex.listFiles() ?: emptyArray()
126-
for (file in files) {
127-
if (!file.isFile) continue
128-
if (!file.name.lowercase(Locale.US).endsWith(".jar")) continue
129-
if (addFileEntry(zip, file, "$destPrefix/${file.name}", warnings)) {
130-
count++
131-
}
114+
val file = File("/apex/com.android.tethering/javalib/service-connectivity.jar")
115+
if (!file.isFile) {
116+
warnings.add("missing file: ${file.path}")
117+
return 0
132118
}
133-
return count
119+
return if (addFileEntry(zip, file, "framework/apex_com.android.tethering/service-connectivity.jar", warnings, noCompression = true)) 1 else 0
134120
}
135121

136122
private fun addLogEntries(zip: ZipOutputStream, warnings: MutableList<String>, context: Context): Int {
@@ -222,26 +208,34 @@ object DebugInfoExporter {
222208
return count
223209
}
224210

225-
private fun addFileEntry(zip: ZipOutputStream, file: File, entryName: String, warnings: MutableList<String>): Boolean {
211+
private fun addFileEntry(
212+
zip: ZipOutputStream,
213+
file: File,
214+
entryName: String,
215+
warnings: MutableList<String>,
216+
noCompression: Boolean = false,
217+
): Boolean {
226218
if (!file.isFile) {
227219
warnings.add("missing file: ${file.path}")
228220
return false
229221
}
230222
try {
231-
val entry = ZipEntry(entryName)
232-
zip.putNextEntry(entry)
223+
if (noCompression) zip.setLevel(Deflater.NO_COMPRESSION)
224+
zip.putNextEntry(ZipEntry(entryName))
233225
BufferedInputStream(FileInputStream(file)).use { input ->
234-
val buffer = ByteArray(16 * 1024)
226+
val buffer = ByteArray(BUFFER_SIZE)
235227
while (true) {
236228
val read = input.read(buffer)
237229
if (read <= 0) break
238230
zip.write(buffer, 0, read)
239231
}
240232
}
241233
zip.closeEntry()
234+
if (noCompression) zip.setLevel(Deflater.DEFAULT_COMPRESSION)
242235
return true
243236
} catch (e: Throwable) {
244237
warnings.add("zip failed ${file.path}: ${e.message}")
238+
if (noCompression) zip.setLevel(Deflater.DEFAULT_COMPRESSION)
245239
return false
246240
}
247241
}
@@ -263,11 +257,10 @@ object DebugInfoExporter {
263257
command: List<String>,
264258
): CommandResult? = try {
265259
val process = ProcessBuilder(command).redirectErrorStream(true).start()
266-
val entry = ZipEntry(entryName)
267-
zip.putNextEntry(entry)
260+
zip.putNextEntry(ZipEntry(entryName))
268261
var bytes = 0L
269262
process.inputStream.use { input ->
270-
val buffer = ByteArray(16 * 1024)
263+
val buffer = ByteArray(BUFFER_SIZE)
271264
while (true) {
272265
val read = input.read(buffer)
273266
if (read <= 0) break

app/src/main/java/io/nekohasekai/sfa/bg/NeighborEntry.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class NeighborEntry implements Parcelable {
99
@NonNull public final String macAddress;
1010
@NonNull public final String hostname;
1111

12-
public NeighborEntry(@NonNull String address, @NonNull String macAddress, @NonNull String hostname) {
12+
public NeighborEntry(
13+
@NonNull String address, @NonNull String macAddress, @NonNull String hostname) {
1314
this.address = address;
1415
this.macAddress = macAddress;
1516
this.hostname = hostname;

app/src/main/java/io/nekohasekai/sfa/bg/PlatformInterfaceWrapper.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,17 @@ interface PlatformInterfaceWrapper : PlatformInterface {
186186
if (entries == null) return
187187
@Suppress("UNCHECKED_CAST")
188188
val list = entries.list as List<NeighborEntry>
189-
listener.updateNeighborTable(NeighborEntryArray(list.map { entry ->
190-
LibboxNeighborEntry().apply {
191-
address = entry.address
192-
macAddress = entry.macAddress
193-
hostname = entry.hostname
194-
}
195-
}.iterator()))
189+
listener.updateNeighborTable(
190+
NeighborEntryArray(
191+
list.map { entry ->
192+
LibboxNeighborEntry().apply {
193+
address = entry.address
194+
macAddress = entry.macAddress
195+
hostname = entry.hostname
196+
}
197+
}.iterator(),
198+
),
199+
)
196200
}
197201
}
198202
neighborCallback = callback

app/src/main/java/io/nekohasekai/sfa/bg/RootClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ object RootClient {
9595
shell.execTask(task)
9696
} else {
9797
continuation.resumeWithException(
98-
IOException("permission denied")
98+
IOException("permission denied"),
9999
)
100100
}
101101
} catch (e: Exception) {

app/src/main/java/io/nekohasekai/sfa/bg/RootServer.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ class RootServer : RootService() {
149149
when (method.name) {
150150
"hashCode" -> System.identityHashCode(proxyObject)
151151
"equals" -> proxyObject === args?.get(0)
152-
"toString" -> proxyObject.javaClass.name + "@" +
153-
Integer.toHexString(System.identityHashCode(proxyObject))
152+
"toString" ->
153+
proxyObject.javaClass.name + "@" +
154+
Integer.toHexString(System.identityHashCode(proxyObject))
154155
"onClientsChanged" -> {
155156
if (args != null) {
156157
@Suppress("UNCHECKED_CAST")
@@ -194,6 +195,7 @@ class RootServer : RootService() {
194195
if (client == null) continue
195196
try {
196197
val mac = getMacAddress.invoke(client).toString().uppercase()
198+
197199
@Suppress("UNCHECKED_CAST")
198200
val addresses = getAddresses.invoke(client) as List<*>
199201
for (info in addresses) {

0 commit comments

Comments
 (0)