Reflection update; change BraveSingleCategorySettings super

This commit is contained in:
wchen342
2021-09-27 21:38:59 +03:00
parent b007339567
commit 0ac05834c7
4 changed files with 84 additions and 1 deletions
@@ -10,6 +10,7 @@ import org.chromium.base.Log;
import java.lang.Class;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
public class BraveReflectionUtil {
private static String TAG = "BraveReflectionUtil";
@@ -37,6 +38,8 @@ public class BraveReflectionUtil {
}
}
Method toInvoke = methodOwner.getDeclaredMethod(method, parameterTypes);
if (!toInvoke.isAccessible())
toInvoke.setAccessible(true);
try {
return toInvoke.invoke(obj, args);
} catch (IllegalAccessException e) {
@@ -53,6 +56,22 @@ public class BraveReflectionUtil {
return null;
}
public static Object getField(Class ownerClass, String fieldName, Object obj){
try {
Field field = ownerClass.getDeclaredField(fieldName);
if(!field.isAccessible())
field.setAccessible(true);
return field.get(obj);
} catch (NoSuchFieldException e) {
Log.e(TAG, "Field not found: " + e);
assert (false);
} catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
Log.e(TAG, "Get field failed: " + e);
assert (false);
}
return null;
}
// Types should be compatible after bytecode patching
@SuppressWarnings("EqualsIncompatibleType")
public static Boolean EqualTypes(Class type1, Class type2) {