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

Commit e626d58c authored by Vishnu Nair's avatar Vishnu Nair
Browse files

ViewRoot: Notify app when surface is released from setWindowStopped

NativeActivities do not receive onNativeWindowDestroyed callback when the activity is stopped. If
the app still uses the window object after the window is destroyed, the app can crash.

Test: run native-plasma from Android NDK. Launch activity & press home. Verify from the logs app
receives onNativeWindowDestroyed callback when its stopped.

Bug: b/111948775
Change-Id: I1de76feb7f4974b77b42b56e592ff6444713c699
parent 5c0f4012
Loading
Loading
Loading
Loading
+14 −7
Original line number Original line Diff line number Diff line
@@ -1449,6 +1449,9 @@ public final class ViewRootImpl implements ViewParent,
            }
            }


            if (mStopped) {
            if (mStopped) {
                if (mSurfaceHolder != null) {
                    notifySurfaceDestroyed();
                }
                destroySurface();
                destroySurface();
            }
            }
        }
        }
@@ -2393,13 +2396,7 @@ public final class ViewRootImpl implements ViewParent,
                    }
                    }
                    mIsCreating = false;
                    mIsCreating = false;
                } else if (hadSurface) {
                } else if (hadSurface) {
                    mSurfaceHolder.ungetCallbacks();
                    notifySurfaceDestroyed();
                    SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
                    if (callbacks != null) {
                        for (SurfaceHolder.Callback c : callbacks) {
                            c.surfaceDestroyed(mSurfaceHolder);
                        }
                    }
                    mSurfaceHolder.mSurfaceLock.lock();
                    mSurfaceHolder.mSurfaceLock.lock();
                    try {
                    try {
                        mSurfaceHolder.mSurface = new Surface();
                        mSurfaceHolder.mSurface = new Surface();
@@ -2667,6 +2664,16 @@ public final class ViewRootImpl implements ViewParent,
        mIsInTraversal = false;
        mIsInTraversal = false;
    }
    }


    private void notifySurfaceDestroyed() {
        mSurfaceHolder.ungetCallbacks();
        SurfaceHolder.Callback[] callbacks = mSurfaceHolder.getCallbacks();
        if (callbacks != null) {
            for (SurfaceHolder.Callback c : callbacks) {
                c.surfaceDestroyed(mSurfaceHolder);
            }
        }
    }

    private void maybeHandleWindowMove(Rect frame) {
    private void maybeHandleWindowMove(Rect frame) {


        // TODO: Well, we are checking whether the frame has changed similarly
        // TODO: Well, we are checking whether the frame has changed similarly