@@ -13,11 +13,13 @@ import java.io.StringWriter
1313import java.text.SimpleDateFormat
1414import java.util.Date
1515import java.util.Locale
16+ import java.util.zip.Deflater
1617import java.util.zip.ZipEntry
1718import java.util.zip.ZipOutputStream
1819
1920object 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
0 commit comments