[Magnifier-38] Avoid deadlock causing ANR
A deadlock between the UI and render threads caused by magnifier is currently making the running app to become not responding. The deadlock could happen in the following scenario: 1. The UI thread sets a frame callback and asks mRenderer to sync and draw the current frame. A draw task is enqueued by RenderProxy in the C++ code 2. The UI thread starts an InternalPopupWindow#destroy() on the UI thread and acquires mLock 3. mRenderer#destroy() is called on the UI thread, which enqueues a destroy task in the C++ code. However, this is implemented synchronously, so the UI thread will wait until the destroy task is dequeued and executed 4. Since the draw task was enqueued before the destroy task, this will be executed and the frame callback will be called on the render thread 5. The frame callback tries to acquire mLock. However, this is held by the UI thread, so the render thread has to wait for it. At the same time, the UI thread cannot progress either as it is waiting for its destroy task to execute. The CL adds a new lock which is used by the UI thread to mark its intention to #destroy(), such that the render thread will know about this before trying to acquire mLock and starving. Bug: 75276625 Test: manual testing Test: atest CtsWidgetTestCases:android.widget.cts.MagnifierTest Change-Id: Iedf2948350fcf8dd9c819c085b31b7ccaf2db7c5
Loading
Please register or sign in to comment