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

Commit da02fac9 authored by Mihai Popa's avatar Mihai Popa Committed by android-build-merger
Browse files

Merge "[Magnifier-38] Avoid deadlock causing ANR" into pi-dev

am: 285797a4

Change-Id: I81474f04a8d33d2cf063aa0d89b7abca255d3864
parents b0765db5 285797a4
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
@@ -393,6 +393,12 @@ public final class Magnifier {
        private int mWindowPositionY;
        private boolean mPendingWindowPositionUpdate;

        // The lock used to synchronize the UI and render threads when a #destroy
        // is performed on the UI thread and a frame callback on the render thread.
        // When both mLock and mDestroyLock need to be held at the same time,
        // mDestroyLock should be acquired before mLock in order to avoid deadlocks.
        private final Object mDestroyLock = new Object();

        InternalPopupWindow(final Context context, final Display display,
                final Surface parentSurface,
                final int width, final int height, final float elevation, final float cornerRadius,
@@ -517,9 +523,11 @@ public final class Magnifier {
         * Destroys this instance.
         */
        public void destroy() {
            synchronized (mDestroyLock) {
                mSurface.destroy();
            }
            synchronized (mLock) {
                mRenderer.destroy();
                mSurface.destroy();
                mSurfaceControl.destroy();
                mSurfaceSession.kill();
                mBitmapRenderNode.destroy();
@@ -567,10 +575,11 @@ public final class Magnifier {
                    final int pendingY = mWindowPositionY;

                    callback = frame -> {
                        synchronized (mLock) {
                        synchronized (mDestroyLock) {
                            if (!mSurface.isValid()) {
                                return;
                            }
                            synchronized (mLock) {
                                mRenderer.setLightCenter(mDisplay, pendingX, pendingY);
                                // Show or move the window at the content draw frame.
                                SurfaceControl.openTransaction();
@@ -583,6 +592,7 @@ public final class Magnifier {
                                }
                                SurfaceControl.closeTransaction();
                            }
                        }
                    };
                } else {
                    callback = null;