diff options
| author | Vishnu Nair <vishnun@google.com> | 2021-04-22 14:17:32 -0700 |
|---|---|---|
| committer | Vishnu Nair <vishnun@google.com> | 2021-04-22 14:18:37 -0700 |
| commit | 8685ce1deecdd73bb8fc19b620123704df6ae77b (patch) | |
| tree | e99a69584304c80381501565ae08bfe3f6a794d5 /core/java/android/view/ViewRootImpl.java | |
| parent | d78b21c54858a5164fd239097efcd0805f0767ba (diff) | |
Fix SurfaceView callback timings
In R we consolidated SetWindowStopped to use ViewRootImpl
surface changed callbacks. This affected the timings of when
the app would get SurfaceView SurfaceHolder callbacks. The
callbacks would be invoked in ViewRootImpl traversal before
the measure pass. If the app tried to add to the view hierarchy
in the callback, the view would not measure and layout the
new view properly.
To fix this, move the ViewRootImp SurfaceChangedCallback
after the measure pass.
Test: app in bug can add a view from SurfaceHolder.Callback#surfaceCreated
Fixes: 181529599
Change-Id: I06923113f7fc8e90242060c34f1d309d53b5a87b
Diffstat (limited to 'core/java/android/view/ViewRootImpl.java')
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 3cfda571ae6a..a5ce6e0c0b91 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -2854,7 +2854,6 @@ public final class ViewRootImpl implements ViewParent, return; } } - notifySurfaceCreated(); } else if (surfaceDestroyed) { // If the surface has been removed, then reset the scroll // positions. @@ -2894,10 +2893,6 @@ public final class ViewRootImpl implements ViewParent, } } - if (!surfaceCreated && surfaceReplaced) { - notifySurfaceReplaced(); - } - if (mDragResizing != dragResizing) { if (dragResizing) { mResizeMode = freeformResizing @@ -3110,7 +3105,14 @@ public final class ViewRootImpl implements ViewParent, } } - if (surfaceDestroyed) { + // These callbacks will trigger SurfaceView SurfaceHolder.Callbacks and must be invoked + // after the measure pass. If its invoked before the measure pass and the app modifies + // the view hierarchy in the callbacks, we could leave the views in a broken state. + if (surfaceCreated) { + notifySurfaceCreated(); + } else if (surfaceReplaced) { + notifySurfaceReplaced(); + } else if (surfaceDestroyed) { notifySurfaceDestroyed(); } |
