@@ -26,27 +26,10 @@ final class TestLooperManagerCompat {
2626 private static Method messageQueueNextMethod ;
2727 private static Field messageQueueHeadField ;
2828 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- }
4629
4730 static {
4831 try {
49- if (! initTestLooperManager () ) {
32+ if (VERSION . SDK_INT < VERSION_CODES . BAKLAVA ) {
5033 messageQueueNextMethod = MessageQueue .class .getDeclaredMethod ("next" );
5134 messageQueueNextMethod .setAccessible (true );
5235 messageQueueHeadField = MessageQueue .class .getDeclaredField ("mMessages" );
@@ -76,7 +59,7 @@ private TestLooperManagerCompat(TestLooperManager testLooperManager) {
7659 }
7760
7861 static TestLooperManagerCompat acquire (Looper looper ) {
79- if (peekWhenMethod != null ) {
62+ if (VERSION . SDK_INT >= VERSION_CODES . BAKLAVA ) {
8063 // running on a newer Android version that has the supported TestLooperManagerCompat changes
8164 Checks .checkState (looper .isCurrentThread ());
8265 TestLooperManager testLooperManager =
@@ -91,7 +74,7 @@ static TestLooperManagerCompat acquire(Looper looper) {
9174 Long peekWhen () {
9275 try {
9376 if (delegate != null ) {
94- return ( Long ) peekWhenMethod . invoke ( delegate );
77+ return delegate . peekWhen ( );
9578 } else {
9679 Message msg = legacyPeek ();
9780 if (msg != null && msg .getTarget () == null ) {
@@ -131,7 +114,7 @@ void release() {
131114 boolean isBlockedOnSyncBarrier () {
132115 try {
133116 if (delegate != null ) {
134- return ( boolean ) blockedOnBarrierMethod . invoke ( delegate );
117+ return delegate . isBlockedOnSyncBarrier ( );
135118 } else {
136119 Message msg = legacyPeek ();
137120 return msg != null && msg .getTarget () == null ;
0 commit comments