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

Commit 11a52b76 authored by Kan-Ru Chen's avatar Kan-Ru Chen Committed by Steve Kondik
Browse files

frameworks: WindowManagerService: Fix out of memory for surface error

Surface.openTransaction and Surface.closeTransaction is not reentrant.
If we are updating the mouse surface when the WindowManager is also
updating the surfaces, the global transaction can be closed too early
by the other side. The results are random runtime exceptions and
unstable surface state.

Move the mouse surface update logic to the big surfaces update
loop, together with the other surfaces update logic.

Change-Id: I38a4f264f8de59899c3ac0fdaf9d8cd520d41947
parent 9c3709a1
Loading
Loading
Loading
Loading
+28 −27
Original line number Diff line number Diff line
@@ -6625,10 +6625,8 @@ public class WindowManagerService extends IWindowManager.Stub
                                //Slog.i(TAG, "Read next event " + ev);
                                dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
                                if (mMouseDisplayed) {
                                    Surface.openTransaction();
                                    mMouseSurface.hide();
                                    Surface.closeTransaction();
                                    mMouseDisplayed = false;
                                    requestAnimationLocked(0);
                                }
                                break;
                            case RawInputEvent.CLASS_MOUSE:
@@ -6636,30 +6634,12 @@ public class WindowManagerService extends IWindowManager.Stub
                                int mcx = (int)mmev.getX();
                                int mcy = (int)mmev.getY();

                                if (mMouseSurface != null && (mMlx != mcx || mMly != mcy)) {
                                    Surface.openTransaction();
                                    if (DEBUG_INPUT)
                                        Slog.i(TAG, "Open transaction for the mouse surface");
                                    WindowState top =
                                        (WindowState)mWindows.get(mWindows.size() - 1);
                                    try {
                                        if (DEBUG_INPUT)
                                            Slog.i(TAG, "Move surf, x: " +
                                                  Integer.toString(mcx) + " y:"
                                                  + Integer.toString(mcy));

                                        mMouseSurface.setPosition(mcx, mcy);
                                        mMouseSurface.setLayer(top.mAnimLayer + 1);
                                        if (!mMouseDisplayed) {
                                            mMouseSurface.show();
                                            mMouseDisplayed = true;
                                        }
                                if (mMlx != mcx || mMly != mcy) {
                                    mMlx = mcx;
                                    mMly = mcy;
                                    } catch ( RuntimeException e) {
                                        Slog.e(TAG, "Failure showing mouse surface",e);
                                    }
                                    Surface.closeTransaction();
                                    if (!mMouseDisplayed)
                                        mMouseDisplayed = true;
                                    requestAnimationLocked(0);
                                }
                                dispatchPointer(ev, (MotionEvent)ev.event, 0, 0);
                                break;
@@ -10737,6 +10717,27 @@ public class WindowManagerService extends IWindowManager.Stub
                mBlurShown = false;
            }

            // FOURTH LOOP: Display Mouse
            if (mMouseSurface != null) {
                if (mMouseDisplayed) {
                    WindowState top =
                        (WindowState)mWindows.get(mWindows.size() - 1);
                    try {
                        if (DEBUG_INPUT)
                            Slog.i(TAG, "Move surf, x: " +
                                   Integer.toString(mMlx) + " y:"
                                   + Integer.toString(mMly));
                        mMouseSurface.show();
                        mMouseSurface.setPosition(mMlx, mMly);
                        mMouseSurface.setLayer(top.mAnimLayer + 1);
                    } catch (RuntimeException e) {
                        Slog.e(TAG, "Failure showing mouse surface", e);
                    }
                } else {
                    mMouseSurface.hide();
                }
            }

            if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION");
        } catch (RuntimeException e) {
            Slog.e(TAG, "Unhandled exception in Window Manager", e);