@@ -26,27 +26,10 @@ final class TestLooperManagerCompat {
26
26
private static Method messageQueueNextMethod ;
27
27
private static Field messageQueueHeadField ;
28
28
private static Method recycleUncheckedMethod ;
29
- private static Method peekWhenMethod ;
30
- private static Method blockedOnBarrierMethod ;
31
-
32
- private static boolean initTestLooperManager () {
33
- // TODO(b/112000181): update this check and remove reflection when compiling against Baklava
34
- if (VERSION .SDK_INT >= VERSION_CODES .VANILLA_ICE_CREAM ) {
35
- try {
36
- peekWhenMethod = TestLooperManager .class .getDeclaredMethod ("peekWhen" );
37
- blockedOnBarrierMethod =
38
- TestLooperManager .class .getDeclaredMethod ("isBlockedOnSyncBarrier" );
39
- return true ;
40
- } catch (ReflectiveOperationException e ) {
41
- // fall through
42
- }
43
- }
44
- return false ;
45
- }
46
29
47
30
static {
48
31
try {
49
- if (! initTestLooperManager () ) {
32
+ if (VERSION . SDK_INT < VERSION_CODES . BAKLAVA ) {
50
33
messageQueueNextMethod = MessageQueue .class .getDeclaredMethod ("next" );
51
34
messageQueueNextMethod .setAccessible (true );
52
35
messageQueueHeadField = MessageQueue .class .getDeclaredField ("mMessages" );
@@ -76,7 +59,7 @@ private TestLooperManagerCompat(TestLooperManager testLooperManager) {
76
59
}
77
60
78
61
static TestLooperManagerCompat acquire (Looper looper ) {
79
- if (peekWhenMethod != null ) {
62
+ if (VERSION . SDK_INT >= VERSION_CODES . BAKLAVA ) {
80
63
// running on a newer Android version that has the supported TestLooperManagerCompat changes
81
64
Checks .checkState (looper .isCurrentThread ());
82
65
TestLooperManager testLooperManager =
@@ -91,7 +74,7 @@ static TestLooperManagerCompat acquire(Looper looper) {
91
74
Long peekWhen () {
92
75
try {
93
76
if (delegate != null ) {
94
- return ( Long ) peekWhenMethod . invoke ( delegate );
77
+ return delegate . peekWhen ( );
95
78
} else {
96
79
Message msg = legacyPeek ();
97
80
if (msg != null && msg .getTarget () == null ) {
@@ -131,7 +114,7 @@ void release() {
131
114
boolean isBlockedOnSyncBarrier () {
132
115
try {
133
116
if (delegate != null ) {
134
- return ( boolean ) blockedOnBarrierMethod . invoke ( delegate );
117
+ return delegate . isBlockedOnSyncBarrier ( );
135
118
} else {
136
119
Message msg = legacyPeek ();
137
120
return msg != null && msg .getTarget () == null ;
0 commit comments