Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion play-validations/memory-footprint/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.11.0'
implementation 'com.google.guava:guava:33.3.1-jre'
implementation 'commons-cli:commons-cli:1.5.0'
implementation 'com.android.tools.apkparser:binary-resources:31.7.3'
implementation 'com.android.tools.apkparser:binary-resources:32.2.1'
implementation 'com.github.xgouchet:AXML:v1.0.1'
implementation("com.android.tools.build:aapt2-proto:8.7.3-12006047")
implementation("com.google.protobuf:protobuf-java:4.29.3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.google.wear.watchface.dfx.memory

import com.google.common.io.Files
import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceFile
import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue
import com.google.devrel.gmscore.tools.apk.arsc.ResourceFile
import com.google.devrel.gmscore.tools.apk.arsc.ResourceTableChunk
import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue
import java.io.IOException
import java.io.InputStream
import java.nio.file.Path
Expand Down Expand Up @@ -116,9 +116,9 @@ object AndroidResourceLoader {
return typeChunks
.flatMap { it.entries.values.asSequence() }
.filter { RESOURCE_TYPES.contains(it.typeName()) }
.filter { it.value().type() == BinaryResourceValue.Type.STRING }
.filter { it.value()?.type() == ResourceValue.Type.STRING }
.map { entry ->
val path = stringPool.getString(entry.value().data())
val path = stringPool.getString(entry.value()!!.data())
val data = apkFile.getInputStream(ZipEntry(path)).readBytes()
AndroidResource(
entry.parent().typeName,
Expand All @@ -132,7 +132,7 @@ object AndroidResourceLoader {

@JvmStatic
fun loadResourceTable(inputStream: InputStream): ResourceTableChunk {
val resources = BinaryResourceFile.fromInputStream(inputStream)
val resources = ResourceFile.fromInputStream(inputStream)
val chunks = resources.chunks
if (chunks.isEmpty() || chunks[0] !is ResourceTableChunk) {
throw IOException("no res table chunk")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package com.google.wear.watchface.dfx.memory

import com.android.aapt.Resources
import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue
import com.google.devrel.gmscore.tools.apk.arsc.ResourceTableChunk
import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue
import java.lang.RuntimeException
import java.nio.file.Path
import javax.xml.parsers.DocumentBuilderFactory

Expand Down Expand Up @@ -70,18 +71,18 @@ object AndroidResourceResolver {
visited: Set<Int>
): String {
if (visited.contains(resourceId)) {
throw java.lang.RuntimeException("Cyclic resource reference detected for ID $resourceId")
throw RuntimeException("Cyclic resource reference detected for ID $resourceId")
}
val packageId = (resourceId ushr 24) and 0xFF
val typeId = (resourceId ushr 16) and 0xFF
val entryId = resourceId and 0xFFFF

val pkg = resourceTable.packages.firstOrNull { it.id == packageId }
?: throw java.lang.RuntimeException("Package not found for ID $packageId")
?: throw RuntimeException("Package not found for ID $packageId")

val typeChunks = pkg.typeChunks.filter { it.id == typeId }
if (typeChunks.isEmpty()) {
throw java.lang.RuntimeException("Type not found for ID $typeId")
throw RuntimeException("Type not found for ID $typeId")
}

val newVisited = visited + resourceId
Expand All @@ -91,21 +92,21 @@ object AndroidResourceResolver {
if (entry != null) {
val value = entry.value()
if (value != null) {
if (value.type() == BinaryResourceValue.Type.INT_DEC ||
value.type() == BinaryResourceValue.Type.INT_HEX) {
if (value.type() == ResourceValue.Type.INT_DEC ||
value.type() == ResourceValue.Type.INT_HEX) {
return value.data().toString()
} else if (value.type() == BinaryResourceValue.Type.STRING) {
} else if (value.type() == ResourceValue.Type.STRING) {
return resourceTable.stringPool.getString(value.data())
} else if (value.type() == BinaryResourceValue.Type.REFERENCE ||
value.type() == BinaryResourceValue.Type.DYNAMIC_REFERENCE) {
} else if (value.type() == ResourceValue.Type.REFERENCE ||
value.type() == ResourceValue.Type.DYNAMIC_REFERENCE) {
return resolveResourceValue(resourceTable, value.data(), newVisited)
} else {
throw java.lang.RuntimeException("Unsupported resource value type: ${value.type()}")
throw RuntimeException("Unsupported resource value type: ${value.type()}")
}
}
}
}
throw java.lang.RuntimeException("Entry not found for ID $entryId")
throw RuntimeException("Entry not found for ID $entryId")
}

@JvmStatic
Expand Down
Loading