summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vishnu Nair <vishnun@google.com> 2019-01-24 13:01:24 -0800
committer Vishnu Nair <vishnun@google.com> 2019-01-24 15:55:18 -0800
commit47d2d1e46a5bdcc3c233b90636c4fb8a85b8abcc (patch)
treeb922dea800e7f479583d9742e92491499ea5abe9
parent5d378dfeacb2bf156b3763b2936c88fe55e5adc8 (diff)
[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 e626d58c1b0d09c10d7b5992f5860f7158589ddd)
-rw-r--r--core/java/android/view/ViewRootImpl.java21
1 files changed, 14 insertions, 7 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 6df0173d9684..a1c0967f0ab1 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -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