[core] Remove workaround (#903)

close #856
This commit is contained in:
vvb2060 2021-08-15 17:51:36 +08:00 committed by GitHub
parent 02b7b59ac7
commit 4e554affc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 2 additions and 60 deletions

View File

@ -47,7 +47,6 @@ public final class LspModuleClassLoader extends ByteBufferDexClassLoader {
String apk) {
super(dexBuffers, parent);
this.apk = apk;
setDexName(apk);
}
@RequiresApi(Build.VERSION_CODES.Q)
@ -58,7 +57,6 @@ public final class LspModuleClassLoader extends ByteBufferDexClassLoader {
super(dexBuffers, librarySearchPath, parent);
initNativeLibraryDirs(librarySearchPath);
this.apk = apk;
setDexName(apk);
}
private void initNativeLibraryDirs(String librarySearchPath) {
@ -160,7 +158,8 @@ public final class LspModuleClassLoader extends ByteBufferDexClassLoader {
@Override
public Enumeration<URL> getResources(String name) throws IOException {
@SuppressWarnings("unchecked") final var resources = (Enumeration<URL>[]) new Enumeration<?>[]{
@SuppressWarnings("unchecked")
final var resources = (Enumeration<URL>[]) new Enumeration<?>[]{
Object.class.getClassLoader().getResources(name),
findResources(name),
getParent() == null ? null : getParent().getResources(name)};

View File

@ -1,31 +1,10 @@
package hidden;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import dalvik.system.BaseDexClassLoader;
public class ByteBufferDexClassLoader extends BaseDexClassLoader {
static Field pathListField = null;
static Field dexElementsField = null;
static Field dexFileField = null;
static Field nameField = null;
static {
try {
pathListField = BaseDexClassLoader.class.getDeclaredField("pathList");
pathListField.setAccessible(true);
dexElementsField = pathListField.getType().getDeclaredField("dexElements");
dexElementsField.setAccessible(true);
var elementType = dexElementsField.getType().getComponentType();
dexFileField = elementType.getDeclaredField("dexFile");
dexFileField.setAccessible(true);
nameField = dexFileField.getType().getDeclaredField("mFileName");
nameField.setAccessible(true);
} catch (Throwable ignored) {
}
}
public ByteBufferDexClassLoader(ByteBuffer[] dexFiles, ClassLoader parent) {
super(dexFiles, parent);
@ -35,17 +14,6 @@ public class ByteBufferDexClassLoader extends BaseDexClassLoader {
super(dexFiles, librarySearchPath, parent);
}
// Some modules get their module paths from this variable
// They should use `initZygote.modulePath` instead
// Temporarily workaround
// TODO(vvb2060): removed in the next major release
public void setDexName(String name){
try {
nameField.set(dexFileField.get(((Object[]) dexElementsField.get(pathListField.get(this)))[0]), name);
} catch (Throwable ignored) {
}
}
public String getLdLibraryPath() {
return super.getLdLibraryPath();
}

View File

@ -1,7 +0,0 @@
package com.android.internal.os;
public class RuntimeInit {
public static final void main(String[] argv) {
throw new UnsupportedOperationException("STUB");
}
}

View File

@ -1,7 +0,0 @@
package com.android.internal.os;
public class ZygoteInit {
public static void main(String[] argv) {
throw new UnsupportedOperationException("STUB");
}
}

View File

@ -1,19 +1,8 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package dalvik.system;
import java.io.File;
import java.nio.ByteBuffer;
public class BaseDexClassLoader extends ClassLoader {
private Object pathList;
public BaseDexClassLoader(String dexPath, File optimizedDirectory, String librarySearchPath, ClassLoader parent) {
throw new RuntimeException("Stub!");
}
public BaseDexClassLoader(ByteBuffer[] dexFiles, ClassLoader parent) {
throw new RuntimeException("Stub!");
}