1 package org.robolectric.shadows; 2 3 import static android.os.Build.VERSION_CODES.LOLLIPOP; 4 import static org.robolectric.util.reflector.Reflector.reflector; 5 6 import android.os.Handler; 7 import android.os.Message; 8 import org.robolectric.RuntimeEnvironment; 9 import org.robolectric.annotation.Implementation; 10 import org.robolectric.annotation.Implements; 11 import org.robolectric.annotation.LooperMode; 12 import org.robolectric.annotation.RealObject; 13 14 /** 15 * The shadow {@link Message} for {@link LooperMode.Mode.PAUSED}. 16 * 17 * <p>This class should not be referenced directly. Use {@link ShadowMessage} instead. 18 */ 19 @Implements(value = Message.class, isInAndroidSdk = false) 20 public class ShadowPausedMessage extends ShadowMessage { 21 22 @RealObject private Message realMessage; 23 24 @Implementation getWhen()25 protected long getWhen() { 26 return reflector(MessageReflector.class, realMessage).getWhen(); 27 } 28 internalGetNext()29 Message internalGetNext() { 30 return reflector(MessageReflector.class, realMessage).getNext(); 31 } 32 33 // TODO: Reconsider this being exposed as a public method 34 @Override 35 @Implementation(minSdk = LOLLIPOP) recycleUnchecked()36 public void recycleUnchecked() { 37 if (RuntimeEnvironment.getApiLevel() >= LOLLIPOP) { 38 reflector(MessageReflector.class, realMessage).recycleUnchecked(); 39 } else { 40 reflector(MessageReflector.class, realMessage).recycle(); 41 } 42 } 43 44 @Override setScheduledRunnable(Runnable r)45 public void setScheduledRunnable(Runnable r) { 46 throw new UnsupportedOperationException("Not supported in PAUSED LooperMode"); 47 } 48 49 // We could support these methods, but intentionally do not for now as its unclear what the 50 // use case is. 51 52 @Override getNext()53 public Message getNext() { 54 throw new UnsupportedOperationException("Not supported in PAUSED LooperMode"); 55 } 56 57 @Override setNext(Message next)58 public void setNext(Message next) { 59 throw new UnsupportedOperationException("Not supported in PAUSED LooperMode"); 60 } 61 62 @Implementation getTarget()63 protected Handler getTarget() { 64 return reflector(MessageReflector.class, realMessage).getTarget(); 65 } 66 } 67