Merge "Fix a potential thread safety issue in VectorDrawable" into qt-dev am: 547df6be1e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14880618

Change-Id: I9690abb966d3d972e35015de54fafc6577d43340
This commit is contained in:
John Reck
2021-06-30 15:27:01 +00:00
committed by Automerger Merge Worker

View File

@@ -348,15 +348,19 @@ public class VectorDrawable extends Drawable {
private final Rect mTmpBounds = new Rect(); private final Rect mTmpBounds = new Rect();
public VectorDrawable() { public VectorDrawable() {
this(new VectorDrawableState(null), null); this(null, null);
} }
/** /**
* The one constructor to rule them all. This is called by all public * The one constructor to rule them all. This is called by all public
* constructors to set the state and initialize local properties. * constructors to set the state and initialize local properties.
*/ */
private VectorDrawable(@NonNull VectorDrawableState state, @Nullable Resources res) { private VectorDrawable(@Nullable VectorDrawableState state, @Nullable Resources res) {
mVectorState = state; // As the mutable, not-thread-safe native instance is stored in VectorDrawableState, we
// need to always do a defensive copy even if mutate() isn't called. Otherwise
// draw() being called on 2 different VectorDrawable instances could still hit the same
// underlying native object.
mVectorState = new VectorDrawableState(state);
updateLocalState(res); updateLocalState(res);
} }