From 06202f270107a43418d06b798411bc5174d5409d Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Tue, 25 Aug 2020 18:11:30 +0700 Subject: [PATCH] Remove unnecessary class --- .../net/kdt/pojavlaunch/MainActivity.java | 8 - .../kdt/pojavlaunch/SecondaryDexLoader.java | 146 ------------------ 2 files changed, 154 deletions(-) delete mode 100644 app/src/main/java/net/kdt/pojavlaunch/SecondaryDexLoader.java diff --git a/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java b/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java index bac0dae09..5c280bf5c 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java +++ b/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java @@ -170,12 +170,6 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener, @Override public void run() { isExited = true; - - try { - SecondaryDexLoader.resetFieldArray(getClassLoader()); - } catch (Throwable th) { - th.printStackTrace(); - } AlertDialog.Builder d = new AlertDialog.Builder(MainActivity.this); d.setTitle(R.string.mcn_exit_title); @@ -1023,10 +1017,8 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener, // GLFW Stub width height javaArgList.add("-Dglfwstub.windowWidth=" + AndroidDisplay.windowWidth); javaArgList.add("-Dglfwstub.windowHeight=" + AndroidDisplay.windowHeight); - javaArgList.add("-Dglfwstub.eglContext=" + Tools.getEGLAddress("Context", AndroidContextImplementation.context)); - String eglDisplay = Tools.getEGLAddress("Display", AndroidContextImplementation.display); if (eglDisplay.equals("1")) { eglDisplay = Tools.getEGLAddress("Display", ((EGL10) EGLContext.getEGL()).eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY)); diff --git a/app/src/main/java/net/kdt/pojavlaunch/SecondaryDexLoader.java b/app/src/main/java/net/kdt/pojavlaunch/SecondaryDexLoader.java deleted file mode 100644 index 8d12f402e..000000000 --- a/app/src/main/java/net/kdt/pojavlaunch/SecondaryDexLoader.java +++ /dev/null @@ -1,146 +0,0 @@ -package net.kdt.pojavlaunch; - -import android.util.*; -import java.io.*; -import java.lang.reflect.*; -import java.util.*; - -/* - * All methods there are from - * https://android.googlesource.com/platform/frameworks/multidex/+/refs/heads/master/library/src/androidx/multidex/MultiDex.java - */ -public class SecondaryDexLoader -{ - public static String TAG = "SecondaryDexLoader"; - - private static int ADDITIONAL_CLASSES = 0; - - public static void install(ClassLoader loader, List additionalClassPathEntries, File optimizedDirectory) throws Throwable { - ADDITIONAL_CLASSES = additionalClassPathEntries.size(); - - /* The patched class loader is expected to be a descendant of - * dalvik.system.BaseDexClassLoader. We modify its - * dalvik.system.DexPathList pathList field to append additional DEX - * file entries. - */ - - Object dexPathList = getDexPathList(loader); - ArrayList suppressedExceptions = new ArrayList(); - expandFieldArray(dexPathList, "dexElements", makeDexElements(dexPathList, - new ArrayList(additionalClassPathEntries), optimizedDirectory, - suppressedExceptions)); - if (suppressedExceptions.size() > 0) { - for (IOException e : suppressedExceptions) { - Log.w(TAG, "Exception in makeDexElement", e); - } - Field suppressedExceptionsField = - findField(loader, "dexElementsSuppressedExceptions"); - IOException[] dexElementsSuppressedExceptions = - (IOException[]) suppressedExceptionsField.get(loader); - if (dexElementsSuppressedExceptions == null) { - dexElementsSuppressedExceptions = - suppressedExceptions.toArray( - new IOException[suppressedExceptions.size()]); - } else { - IOException[] combined = - new IOException[suppressedExceptions.size() + - dexElementsSuppressedExceptions.length]; - suppressedExceptions.toArray(combined); - System.arraycopy(dexElementsSuppressedExceptions, 0, combined, - suppressedExceptions.size(), dexElementsSuppressedExceptions.length); - dexElementsSuppressedExceptions = combined; - } - suppressedExceptionsField.set(loader, dexElementsSuppressedExceptions); - } - } - - private static /* DexPathList */ Object getDexPathList(ClassLoader loader) throws Throwable { - Field pathListField = findField(loader, "pathList"); - return pathListField.get(loader); - } - - /** - * A wrapper around - * {@code private static final dalvik.system.DexPathList#makeDexElements}. - */ - private static Object[] makeDexElements(Object dexPathList, ArrayList files, File optimizedDirectory, ArrayList suppressedExceptions) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { - Method makeDexElements = findMethod(dexPathList, "makeDexElements", ArrayList.class, File.class, ArrayList.class); - return (Object[]) makeDexElements.invoke(dexPathList, files, optimizedDirectory, suppressedExceptions); - } - - - /** - * Locates a given field anywhere in the class inheritance hierarchy. - * - * @param instance an object to search the field into. - * @param name field name - * @return a field object - * @throws NoSuchFieldException if the field cannot be located - */ - private static Field findField(Object instance, String name) throws NoSuchFieldException { - for (Class clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) { - try { - Field field = clazz.getDeclaredField(name); - if (!field.isAccessible()) { - field.setAccessible(true); - } - return field; - } catch (NoSuchFieldException e) { - // ignore and search next - } - } - throw new NoSuchFieldException("Field " + name + " not found in " + instance.getClass()); - } - /** - * Locates a given method anywhere in the class inheritance hierarchy. - * - * @param instance an object to search the method into. - * @param name method name - * @param parameterTypes method parameter types - * @return a method object - * @throws NoSuchMethodException if the method cannot be located - */ - private static Method findMethod(Object instance, String name, Class... parameterTypes) throws NoSuchMethodException { - for (Class clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) { - try { - Method method = clazz.getDeclaredMethod(name, parameterTypes); - if (!method.isAccessible()) { - method.setAccessible(true); - } - return method; - } catch (NoSuchMethodException e) { - // ignore and search next - } - } - throw new NoSuchMethodException("Method " + name + " with parameters " + - Arrays.asList(parameterTypes) + " not found in " + instance.getClass()); - } - /** - * Replace the value of a field containing a non null array, by a new array containing the - * elements of the original array plus the elements of extraElements. - * @param instance the instance whose field is to be modified. - * @param fieldName the field to modify. - * @param extraElements elements to append at the end of the array. - */ - private static Object[] originalDex; - private static void expandFieldArray(Object instance, String fieldName, Object[] extraElements) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { - Field jlrField = findField(instance, fieldName); - originalDex = (Object[]) jlrField.get(instance); - Object[] combined = (Object[]) Array.newInstance( - originalDex.getClass().getComponentType(), originalDex.length + extraElements.length); - System.arraycopy(originalDex, 0, combined, 0, originalDex.length); - System.arraycopy(extraElements, 0, combined, originalDex.length, extraElements.length); - jlrField.set(instance, combined); - } - - public static void resetFieldArray(ClassLoader loader) throws Throwable { - if (originalDex == null) return; - - Object instance = getDexPathList(loader); - - Field jlrField = findField(instance, "dexElements"); - jlrField.set(instance, originalDex); - - originalDex = null; - } -}