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

Commit d2731127 authored by Mark Fasheh's avatar Mark Fasheh
Browse files

Message: Don't use sentinel for target

This breaks the check for a barrier (target == null).

Normally we wouldn't care but DeliQueue.nextMessage() can race with remove.
When this happens, we have no way of making a distinction between
a barrier node and a deleted barrier node. Additionally this makes
debugging nextMessage much easier.

Bug: 421623328
Flag: EXEMPT - bugfix
Test: atest CtsOsTestCasesRavenwood:MessageQueueTest#testSyncBarriersWakeup -- --abi x86_64
Change-Id: Ib7497343104b1173acf7942cc16cbe1a7a4dfa02
parent aed1a7f1
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -330,23 +330,6 @@ public class Handler {
        return new Handler(looper, callback, true);
    }

    /**
     * Create a new Handler with all reference fields explicitly provided. This is intended to be
     * used for creating a Handler sentinel object.
     */
    private Handler(Looper looper, MessageQueue queue, Callback callback) {
        mLooper = looper;
        mQueue = queue;
        mCallback = callback;
        mAsynchronous = false;
        mIsShared = false;
    }

    /** @hide */
    static Handler createSentinelHandler() {
        return new Handler(null, null, null);
    }

    /** @hide */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @NonNull
+1 −5
Original line number Diff line number Diff line
@@ -419,7 +419,6 @@ public final class Message implements Parcelable {
    // Sentinel values used to clear reference fields with a valid 'null' value, to avoid grabbing a
    // removed message when matching for 'null' in these fields.
    private static final Object NULL_OBJECT = new Object();
    private static final Handler NULL_HANDLER = Handler.createSentinelHandler();
    private static final Runnable NULL_RUNNABLE = () -> {};

    /**
@@ -433,7 +432,6 @@ public final class Message implements Parcelable {
        replyTo = null;
        sendingThreadName = null;
        data = null;
        target = NULL_HANDLER;
        callback = NULL_RUNNABLE;
    }

@@ -479,9 +477,7 @@ public final class Message implements Parcelable {
     * worry about yours conflicting with other handlers.
     */
    public Handler getTarget() {
        // We assign this first to avoid a data race that could potentially expose NULL_HANDLER.
        final Handler ret = target;
        return ret == NULL_HANDLER ? null : ret;
        return target;
    }

    /**