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

Commit 47d2d1e4 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

[DO NOT MERGE] 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.
Test: go/wm-smoke

Bug: b/111948775, b/120100553
Change-Id: I1de76feb7f4974b77b42b56e592ff6444713c699
(cherry picked from commit e626d58c)
parent 5d378dfe
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -1354,6 +1354,9 @@ public final class ViewRootImpl implements ViewParent,
            }

            if (mStopped) {
                if (mSurfaceHolder != null) {
                    notifySurfaceDestroyed();
                }
                mSurface.release();
            }
        }
@@ -2227,13 +2230,7 @@ public final class ViewRootImpl implements ViewParent,
                    }
                    mIsCreating = false;
                } else if (hadSurface) {
                    mSurfaceHolder.ungetCallbacks();
                    SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
                    if (callbacks != null) {
                        for (SurfaceHolder.Callback c : callbacks) {
                            c.surfaceDestroyed(mSurfaceHolder);
                        }
                    }
                    notifySurfaceDestroyed();
                    mSurfaceHolder.mSurfaceLock.lock();
                    try {
                        mSurfaceHolder.mSurface = new Surface();
@@ -2497,6 +2494,16 @@ public final class ViewRootImpl implements ViewParent,
        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) {

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