package com.plugin.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@SuppressWarnings("unchecked")
public class RefInvoker {

	@SuppressWarnings("rawtypes")
	public static Object invokeStaticMethod(String className, String methodName, Class[] paramTypes,
			Object[] paramValues) {

		return invokeMethod(null, className, methodName, paramTypes, paramValues);

	}

	@SuppressWarnings("rawtypes")
	public static Object invokeMethod(Object target, String className, String methodName, Class[] paramTypes,
			Object[] paramValues) {

		try {
			Class clazz = Class.forName(className);
			Method method = clazz.getDeclaredMethod(methodName, paramTypes);
			method.setAccessible(true);
			return method.invoke(target, paramValues);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return null;

	}

	@SuppressWarnings("rawtypes")
	public static Object getFieldObject(Object target, String className, String fieldName) {
		Class clazz = null;
		try {
			clazz = Class.forName(className);
			Field field = clazz.getDeclaredField(fieldName);
			field.setAccessible(true);
			return field.get(target);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			//try supper for Miui, Miui has a class named MiuiPhoneWindow
			try {
				Field field = clazz.getSuperclass().getDeclaredField(fieldName);
				field.setAccessible(true);
				return field.get(target);
			} catch (Exception superE) {
				e.printStackTrace();
				superE.printStackTrace();
			}
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return null;

	}

	public static Object getStaticFieldObject(String className, String fieldName) {

		return getFieldObject(null, className, fieldName);
	}

	@SuppressWarnings("rawtypes")
	public static void setFieldObject(Object target, String className, String fieldName, Object fieldValue) {
		Class clazz = null;
		try {
			clazz = Class.forName(className);
			Field field = clazz.getDeclaredField(fieldName);
			field.setAccessible(true);
			field.set(target, fieldValue);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			//try supper for Miui, Miui has a class named MiuiPhoneWindow
			try {
				Field field = clazz.getSuperclass().getDeclaredField(fieldName);
				field.setAccessible(true);
				field.set(target, fieldValue);
			} catch (Exception superE) {
				e.printStackTrace();
				superE.printStackTrace();
			}
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static void setStaticOjbect(String className, String fieldName, Object fieldValue) {
		setFieldObject(null, className, fieldName, fieldValue);
	}

}
@@ -1280,32 +1280,27 @@
 target, 
-String className
+Class clazz
 , String
@@ -1319,72 +1319,13 @@
 %7B%0A%09%09
-Class clazz = null;%0A%09%09try %7B%0A%09%09%09clazz = Class.forName(className);
+try %7B
 %0A%09%09%09
@@ -1524,32 +1524,33 @@
 ption e) %7B%0A%09%09%09//
+ 
 try supper for M
@@ -1944,32 +1944,296 @@
 ntStackTrace();%0A
+%09%09%7D%0A%09%09return null;%0A%0A%09%7D%0A%0A%09@SuppressWarnings(%22rawtypes%22)%0A%09public static Object getFieldObject(Object target, String className, String fieldName) %7B%0A%09%09Class clazz = null;%0A%09%09try %7B%0A%09%09%09clazz = Class.forName(className);%0A%09%09%09return getFieldObject(target, clazz, fieldName);%0A
 %09%09%7D catch (Class
@@ -2863,16 +2863,17 @@
  %7B%0A%09%09%09//
+ 
 try supp

update RefInvoker