Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b507d470 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Test reflection

parent 7949ed01
Loading
Loading
Loading
Loading
+23 −8
Original line number Diff line number Diff line
@@ -103,19 +103,23 @@ public final class EntryPoint {
        }

        try {
            Field creatorsField = findField(Parcel.class, "mCreators");
            Field creatorsField = findFieldIfExists(Parcel.class, "mCreators");
            if (creatorsField != null) {
                creatorsField.setAccessible(true);
                Map<?, ?> mCreators = (Map<?, ?>) creatorsField.get(null);
                if (mCreators != null) mCreators.clear();
            }
        } catch (Exception e) {
            Log.e(TAG, "Couldn't clear Parcel mCreators: " + e);
        }

        try {
            Field creatorsField = findField(Parcel.class, "sPairedCreators");
            Field creatorsField = findFieldIfExists(Parcel.class, "sPairedCreators");
            if (creatorsField != null) {
                creatorsField.setAccessible(true);
                Map<?, ?> sPairedCreators = (Map<?, ?>) creatorsField.get(null);
                if (sPairedCreators != null) sPairedCreators.clear();
            }
        } catch (Exception e) {
            Log.e(TAG, "Couldn't clear Parcel sPairedCreators: " + e);
        }
@@ -132,6 +136,17 @@ public final class EntryPoint {
        throw new NoSuchFieldException("Field '" + fieldName + "' not found in class hierarchy of " + Objects.requireNonNull(currentClass).getName());
    }

    private static Field findFieldIfExists(Class<?> currentClass, String fieldName) {
        while (currentClass != null && !currentClass.equals(Object.class)) {
            try {
                return currentClass.getDeclaredField(fieldName);
            } catch (NoSuchFieldException ignored) {
                currentClass = currentClass.getSuperclass();
            }
        }
        return null;
    }

    private static Field getBuildField(String name) {
        Field field;
        try {