Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8691b4a7 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi Committed by Automerger Merge Worker
Browse files

Merge "Add method in Handler to remove messages with equal object" into...

Merge "Add method in Handler to remove messages with equal object" into rvc-dev am: 1c21c7c7 am: f5404090 am: f7c94b5e

Change-Id: Ia6a2c0582fb11ebb41c91618b9ccff38bef2d697
parents 4d0925a1 f7c94b5e
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -795,6 +795,17 @@ public class Handler {
        mQueue.removeMessages(this, what, object);
    }

    /**
     * Remove any pending posts of messages with code 'what' and whose obj is
     * 'object' that are in the message queue.  If <var>object</var> is null,
     * all messages will be removed.
     *
     *@hide
     */
    public final void removeEqualMessages(int what, @Nullable Object object) {
        mQueue.removeEqualMessages(this, what, object);
    }

    /**
     * Remove any pending posts of callbacks and sent messages whose
     * <var>obj</var> is <var>token</var>.  If <var>token</var> is null,
@@ -804,6 +815,16 @@ public class Handler {
        mQueue.removeCallbacksAndMessages(this, token);
    }

    /**
     * Remove any pending posts of callbacks and sent messages whose
     * <var>obj</var> is <var>token</var>.  If <var>token</var> is null,
     * all callbacks and messages will be removed.
     *
     *@hide
     */
    public final void removeCallbacksAndEqualMessages(@Nullable Object token) {
        mQueue.removeCallbacksAndEqualMessages(this, token);
    }
    /**
     * Check if there are any pending posts of messages with code 'what' in
     * the message queue.
@@ -828,6 +849,16 @@ public class Handler {
        return mQueue.hasMessages(this, what, object);
    }

    /**
     * Check if there are any pending posts of messages with code 'what' and
     * whose obj is 'object' in the message queue.
     *
     *@hide
     */
    public final boolean hasEqualMessages(int what, @Nullable Object object) {
        return mQueue.hasEqualMessages(this, what, object);
    }

    /**
     * Check if there are any pending posts of messages with callback r in
     * the message queue.
+119 −0
Original line number Diff line number Diff line
@@ -617,6 +617,23 @@ public final class MessageQueue {
        }
    }

    boolean hasEqualMessages(Handler h, int what, Object object) {
        if (h == null) {
            return false;
        }

        synchronized (this) {
            Message p = mMessages;
            while (p != null) {
                if (p.target == h && p.what == what && (object == null || object.equals(p.obj))) {
                    return true;
                }
                p = p.next;
            }
            return false;
        }
    }

    @UnsupportedAppUsage
    boolean hasMessages(Handler h, Runnable r, Object object) {
        if (h == null) {
@@ -686,6 +703,40 @@ public final class MessageQueue {
        }
    }

    void removeEqualMessages(Handler h, int what, Object object) {
        if (h == null) {
            return;
        }

        synchronized (this) {
            Message p = mMessages;

            // Remove all messages at front.
            while (p != null && p.target == h && p.what == what
                   && (object == null || object.equals(p.obj))) {
                Message n = p.next;
                mMessages = n;
                p.recycleUnchecked();
                p = n;
            }

            // Remove all messages after front.
            while (p != null) {
                Message n = p.next;
                if (n != null) {
                    if (n.target == h && n.what == what
                            && (object == null || object.equals(n.obj))) {
                        Message nn = n.next;
                        n.recycleUnchecked();
                        p.next = nn;
                        continue;
                    }
                }
                p = n;
            }
        }
    }

    void removeMessages(Handler h, Runnable r, Object object) {
        if (h == null || r == null) {
            return;
@@ -720,6 +771,41 @@ public final class MessageQueue {
        }
    }

    void removeEqualMessages(Handler h, Runnable r, Object object) {
        if (h == null || r == null) {
            return;
        }

        synchronized (this) {
            Message p = mMessages;

            // Remove all messages at front.
            while (p != null && p.target == h && p.callback == r
                   && (object == null || object.equals(p.obj))) {
                Message n = p.next;
                mMessages = n;
                p.recycleUnchecked();
                p = n;
            }

            // Remove all messages after front.
            while (p != null) {
                Message n = p.next;
                if (n != null) {
                    if (n.target == h && n.callback == r
                            && (object == null || object.equals(n.obj))) {
                        Message nn = n.next;
                        n.recycleUnchecked();
                        p.next = nn;
                        continue;
                    }
                }
                p = n;
            }
        }
    }


    void removeCallbacksAndMessages(Handler h, Object object) {
        if (h == null) {
            return;
@@ -753,6 +839,39 @@ public final class MessageQueue {
        }
    }

    void removeCallbacksAndEqualMessages(Handler h, Object object) {
        if (h == null) {
            return;
        }

        synchronized (this) {
            Message p = mMessages;

            // Remove all messages at front.
            while (p != null && p.target == h
                    && (object == null || object.equals(p.obj))) {
                Message n = p.next;
                mMessages = n;
                p.recycleUnchecked();
                p = n;
            }

            // Remove all messages after front.
            while (p != null) {
                Message n = p.next;
                if (n != null) {
                    if (n.target == h && (object == null || object.equals(n.obj))) {
                        Message nn = n.next;
                        n.recycleUnchecked();
                        p.next = nn;
                        continue;
                    }
                }
                p = n;
            }
        }
    }

    private void removeAllMessagesLocked() {
        Message p = mMessages;
        while (p != null) {