25
25
import java .util .List ;
26
26
import java .util .Optional ;
27
27
28
- import dalvik .system .VMRuntime ;
29
-
30
28
@ SuppressWarnings ("JavaReflectionMemberAccess" )
31
29
@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
32
30
@ SdkSuppress (minSdkVersion = Build .VERSION_CODES .P )
33
31
@ RunWith (AndroidJUnit4 .class )
34
32
public class HiddenApiBypassTest {
35
33
34
+ private final Class <?> runtime = Class .forName ("dalvik.system.VMRuntime" );
35
+
36
36
@ Rule
37
37
public ExpectedException exception = ExpectedException .none ();
38
38
39
+ public HiddenApiBypassTest () throws ClassNotFoundException {
40
+ }
41
+
39
42
@ Test
40
43
public void AgetDeclaredMethods () {
41
- List <Executable > methods = HiddenApiBypass .getDeclaredMethods (VMRuntime . class );
44
+ List <Executable > methods = HiddenApiBypass .getDeclaredMethods (runtime );
42
45
Optional <Executable > getRuntime = methods .stream ().filter (it -> it .getName ().equals ("getRuntime" )).findFirst ();
43
46
assertTrue (getRuntime .isPresent ());
44
47
Optional <Executable > setHiddenApiExemptions = methods .stream ().filter (it -> it .getName ().equals ("setHiddenApiExemptions" )).findFirst ();
@@ -52,7 +55,7 @@ public void BusesNonSdkApiIsHiddenApi() throws NoSuchMethodException {
52
55
53
56
@ Test (expected = NoSuchMethodException .class )
54
57
public void CsetHiddenApiExemptionsIsHiddenApi () throws NoSuchMethodException {
55
- VMRuntime . class .getMethod ("setHiddenApiExemptions" , String [].class );
58
+ runtime .getMethod ("setHiddenApiExemptions" , String [].class );
56
59
}
57
60
58
61
@ Test (expected = NoSuchMethodException .class )
@@ -69,6 +72,7 @@ public void ElongVersionCodeIsHiddenApi() throws NoSuchFieldException {
69
72
public void FHiddenApiEnforcementDefaultIsHiddenApi () throws NoSuchFieldException {
70
73
ApplicationInfo .class .getDeclaredField ("HIDDEN_API_ENFORCEMENT_DEFAULT" );
71
74
}
75
+
72
76
@ Test
73
77
public void GtestGetInstanceFields () {
74
78
assertTrue (HiddenApiBypass .getInstanceFields (ApplicationInfo .class ).stream ().anyMatch (i -> i .getName ().equals ("longVersionCode" )));
@@ -112,30 +116,30 @@ public void MclearHiddenApiExemptions() throws NoSuchMethodException {
112
116
assertTrue (HiddenApiBypass .setHiddenApiExemptions ("L" ));
113
117
ApplicationInfo .class .getMethod ("getHiddenApiEnforcementPolicy" );
114
118
assertTrue (HiddenApiBypass .clearHiddenApiExemptions ());
115
- VMRuntime . class .getMethod ("setHiddenApiExemptions" , String [].class );
119
+ runtime .getMethod ("setHiddenApiExemptions" , String [].class );
116
120
}
117
121
118
122
@ Test
119
123
public void NaddHiddenApiExemptionsTest () throws NoSuchMethodException {
120
124
assertTrue (HiddenApiBypass .addHiddenApiExemptions ("Landroid/content/pm/ApplicationInfo;" ));
121
125
ApplicationInfo .class .getMethod ("getHiddenApiEnforcementPolicy" );
122
126
assertTrue (HiddenApiBypass .addHiddenApiExemptions ("Ldalvik/system/VMRuntime;" ));
123
- VMRuntime . class .getMethod ("setHiddenApiExemptions" , String [].class );
127
+ runtime .getMethod ("setHiddenApiExemptions" , String [].class );
124
128
}
125
129
126
130
@ Test
127
131
public void OtestCheckArgsForInvokeMethod () {
128
132
class X {
129
133
}
130
- assertFalse (HiddenApiBypass .checkArgsForInvokeMethod (new Class []{}, new Object []{new Object ()}));
131
- assertTrue (HiddenApiBypass .checkArgsForInvokeMethod (new Class []{int .class }, new Object []{1 }));
132
- assertFalse (HiddenApiBypass .checkArgsForInvokeMethod (new Class []{int .class }, new Object []{1.0 }));
133
- assertFalse (HiddenApiBypass .checkArgsForInvokeMethod (new Class []{int .class }, new Object []{null }));
134
- assertTrue (HiddenApiBypass .checkArgsForInvokeMethod (new Class []{Integer .class }, new Object []{1 }));
135
- assertTrue (HiddenApiBypass .checkArgsForInvokeMethod (new Class []{Integer .class }, new Object []{null }));
136
- assertTrue (HiddenApiBypass .checkArgsForInvokeMethod (new Class []{Object .class }, new Object []{new X ()}));
137
- assertFalse (HiddenApiBypass .checkArgsForInvokeMethod (new Class []{X .class }, new Object []{new Object ()}));
138
- assertTrue (HiddenApiBypass .checkArgsForInvokeMethod (new Class []{Object .class , int .class , byte .class , short .class , char .class , double .class , float .class , boolean .class , long .class }, new Object []{new X (), 1 , (byte ) 0 , (short ) 2 , 'c' , 1.1 , 1.2f , false , 114514L }));
134
+ assertFalse (Helper .checkArgsForInvokeMethod (new Class []{}, new Object []{new Object ()}));
135
+ assertTrue (Helper .checkArgsForInvokeMethod (new Class []{int .class }, new Object []{1 }));
136
+ assertFalse (Helper .checkArgsForInvokeMethod (new Class []{int .class }, new Object []{1.0 }));
137
+ assertFalse (Helper .checkArgsForInvokeMethod (new Class []{int .class }, new Object []{null }));
138
+ assertTrue (Helper .checkArgsForInvokeMethod (new Class []{Integer .class }, new Object []{1 }));
139
+ assertTrue (Helper .checkArgsForInvokeMethod (new Class []{Integer .class }, new Object []{null }));
140
+ assertTrue (Helper .checkArgsForInvokeMethod (new Class []{Object .class }, new Object []{new X ()}));
141
+ assertFalse (Helper .checkArgsForInvokeMethod (new Class []{X .class }, new Object []{new Object ()}));
142
+ assertTrue (Helper .checkArgsForInvokeMethod (new Class []{Object .class , int .class , byte .class , short .class , char .class , double .class , float .class , boolean .class , long .class }, new Object []{new X (), 1 , (byte ) 0 , (short ) 2 , 'c' , 1.1 , 1.2f , false , 114514L }));
139
143
}
140
144
141
145
}
0 commit comments