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

Commit ced251f3 authored by Tiger Huang's avatar Tiger Huang
Browse files

Call InputEventReceiver.dispose from the right thread

TaskPositioner attaches the InputEventReceiver to the animation thread.
This CL makes it to dispose the receiver in the same thread to avoid
race conditions.

This CL also makes InputEventReceiver.finalize call dispose from the
right thread.

Bug: 122054478
Fix: 122096091
Test: 1. Make a task enter free-form mode.
      2. Drag and drop the task.
      3. Check if InputEventReceiver.dispose and finishInputEvent are
         executed in the same thread.

Change-Id: I2f8831e7fccca4f96562f2abe4962811339d02e9
parent 8ffc40aa
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import android.util.SparseIntArray;


import dalvik.system.CloseGuard;
import dalvik.system.CloseGuard;


import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.ref.WeakReference;


/**
/**
@@ -86,6 +87,7 @@ public abstract class InputEventReceiver {


    /**
    /**
     * Disposes the receiver.
     * Disposes the receiver.
     * Must be called on the same Looper thread to which the receiver is attached.
     */
     */
    public void dispose() {
    public void dispose() {
        dispose(false);
        dispose(false);
@@ -109,6 +111,7 @@ public abstract class InputEventReceiver {
            mInputChannel = null;
            mInputChannel = null;
        }
        }
        mMessageQueue = null;
        mMessageQueue = null;
        Reference.reachabilityFence(this);
    }
    }


    /**
    /**
+3 −1
Original line number Original line Diff line number Diff line
@@ -198,7 +198,9 @@ class TaskPositioningController {
    }
    }


    void finishTaskPositioning() {
    void finishTaskPositioning() {
        mHandler.post(() -> {
        // TaskPositioner attaches the InputEventReceiver to the animation thread. We need to
        // dispose the receiver on the same thread to avoid race conditions.
        mService.mAnimationHandler.post(() -> {
            if (DEBUG_TASK_POSITIONING) Slog.d(TAG_WM, "finishPositioning");
            if (DEBUG_TASK_POSITIONING) Slog.d(TAG_WM, "finishPositioning");


            synchronized (mService.mGlobalLock) {
            synchronized (mService.mGlobalLock) {