Add a workaround for the sym linked vdex files in api 28

In api 28, the vdex files in, e.g. the framework/arm directory are actually
just sym links to a shared vdex file in the framework directory. However,
the sym links use an absolute path, and so they don't resolve correctly in
the loop mounted system image.

As a simple workaround, we'll just search upward one directory in the path
if the vdex file can't be resolved.
This commit is contained in:
Ben Gruver 2019-08-07 13:43:15 -07:00
parent c639d229c6
commit 1ac14a1082

View File

@ -500,9 +500,22 @@ public final class DexFileFactory {
@Nullable @Override public byte[] getVdex() { @Nullable @Override public byte[] getVdex() {
if (!loadedVdex) { if (!loadedVdex) {
if (vdexFile.exists()) { File candidateFile = vdexFile;
if (!candidateFile.exists()) {
// On api 28, for framework files, the vdex file in the architecture-specific directory is just a
// symlink to a common vdex file in the framework directory. When loop-mounting a system image, that
// symlink won't resolve because it uses an absolute path. As a workaround, we'll just search upward
// one directory to see if it's there.
File parentDirectory = candidateFile.getParentFile().getParentFile();
if (parentDirectory != null) {
candidateFile = new File(parentDirectory, vdexFile.getName());
}
}
if (candidateFile.exists()) {
try { try {
buf = ByteStreams.toByteArray(new FileInputStream(vdexFile)); buf = ByteStreams.toByteArray(new FileInputStream(candidateFile));
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
buf = null; buf = null;
} catch (IOException ex) { } catch (IOException ex) {