@@ -34,7 +34,9 @@ public static Object invokeMethod(Object target, Class clazz, String methodName,
34
34
try {
35
35
//LogUtil.e("Method", methodName);
36
36
Method method = clazz .getDeclaredMethod (methodName , paramTypes );
37
- method .setAccessible (true );
37
+ if (!method .isAccessible ()) {
38
+ method .setAccessible (true );
39
+ }
38
40
return method .invoke (target , paramValues );
39
41
} catch (SecurityException e ) {
40
42
e .printStackTrace ();
@@ -54,7 +56,9 @@ public static Object invokeMethod(Object target, Class clazz, String methodName,
54
56
public static Object getFieldObject (Object target , Class clazz , String fieldName ) {
55
57
try {
56
58
Field field = clazz .getDeclaredField (fieldName );
57
- field .setAccessible (true );
59
+ if (!field .isAccessible ()) {
60
+ field .setAccessible (true );
61
+ }
58
62
return field .get (target );
59
63
} catch (SecurityException e ) {
60
64
e .printStackTrace ();
@@ -108,15 +112,19 @@ public static void setFieldObject(Object target, String className, String fieldN
108
112
public static void setFieldObject (Object target , Class clazz , String fieldName , Object fieldValue ) {
109
113
try {
110
114
Field field = clazz .getDeclaredField (fieldName );
111
- field .setAccessible (true );
115
+ if (!field .isAccessible ()) {
116
+ field .setAccessible (true );
117
+ }
112
118
field .set (target , fieldValue );
113
119
} catch (SecurityException e ) {
114
120
e .printStackTrace ();
115
121
} catch (NoSuchFieldException e ) {
116
122
// try supper for Miui, Miui has a class named MiuiPhoneWindow
117
123
try {
118
124
Field field = clazz .getSuperclass ().getDeclaredField (fieldName );
119
- field .setAccessible (true );
125
+ if (!field .isAccessible ()) {
126
+ field .setAccessible (true );
127
+ }
120
128
field .set (target , fieldValue );
121
129
} catch (Exception superE ) {
122
130
e .printStackTrace ();
0 commit comments