mirror of
https://github.com/androidx/media.git
synced 2025-05-06 15:10:34 +08:00
Add missing removeCallbacksAndMessages to RobolectricUtil.
The Util class already handles removeMessages calls but so far ignored calls to removeCallbacksAndMessages. PiperOrigin-RevId: 232312458
This commit is contained in:
parent
f8772fda21
commit
1f476ecef0
@ -37,6 +37,7 @@ import org.robolectric.shadows.ShadowMessageQueue;
|
|||||||
public final class RobolectricUtil {
|
public final class RobolectricUtil {
|
||||||
|
|
||||||
private static final AtomicLong sequenceNumberGenerator = new AtomicLong(0);
|
private static final AtomicLong sequenceNumberGenerator = new AtomicLong(0);
|
||||||
|
private static final int ANY_MESSAGE = Integer.MIN_VALUE;
|
||||||
|
|
||||||
private RobolectricUtil() {}
|
private RobolectricUtil() {}
|
||||||
|
|
||||||
@ -110,7 +111,8 @@ public final class RobolectricUtil {
|
|||||||
boolean isRemoved = false;
|
boolean isRemoved = false;
|
||||||
for (RemovedMessage removedMessage : removedMessages) {
|
for (RemovedMessage removedMessage : removedMessages) {
|
||||||
if (removedMessage.handler == target
|
if (removedMessage.handler == target
|
||||||
&& removedMessage.what == pendingMessage.message.what
|
&& (removedMessage.what == ANY_MESSAGE
|
||||||
|
|| removedMessage.what == pendingMessage.message.what)
|
||||||
&& (removedMessage.object == null
|
&& (removedMessage.object == null
|
||||||
|| removedMessage.object == pendingMessage.message.obj)
|
|| removedMessage.object == pendingMessage.message.obj)
|
||||||
&& pendingMessage.sequenceNumber < removedMessage.sequenceNumber) {
|
&& pendingMessage.sequenceNumber < removedMessage.sequenceNumber) {
|
||||||
@ -179,6 +181,15 @@ public final class RobolectricUtil {
|
|||||||
((CustomLooper) shadowOf(looper)).removeMessages(handler, what, object);
|
((CustomLooper) shadowOf(looper)).removeMessages(handler, what, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public void removeCallbacksAndMessages(Handler handler, Object object) {
|
||||||
|
Looper looper = ShadowLooper.getLooperForThread(looperThread);
|
||||||
|
if (shadowOf(looper) instanceof CustomLooper
|
||||||
|
&& shadowOf(looper) != ShadowLooper.getShadowMainLooper()) {
|
||||||
|
((CustomLooper) shadowOf(looper)).removeMessages(handler, ANY_MESSAGE, object);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class PendingMessage implements Comparable<PendingMessage> {
|
private static final class PendingMessage implements Comparable<PendingMessage> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user