Fix that CSL cache hits produce bad drawables
onState() needs to be called to initialize the color to be drawn
with. ColorStateListDrawable(ColorStateList) does this as part
of the call to setColorStateList(), however this was missing from
ColorStateListDrawable(ColorStateListDrawableState) which is hit
when doing ColorStateListDrawableState#newDrawable() when
Resources has a cache-hit on a drawable to load.
Fixes: 186254988
Test: app in bug
Change-Id: Ifb3626f6f85b03dd66142a2f91ba06bc648bff16
diff --git a/graphics/java/android/graphics/drawable/ColorStateListDrawable.java b/graphics/java/android/graphics/drawable/ColorStateListDrawable.java
index 20cd825..423e66c 100644
--- a/graphics/java/android/graphics/drawable/ColorStateListDrawable.java
+++ b/graphics/java/android/graphics/drawable/ColorStateListDrawable.java
@@ -48,6 +48,12 @@
setColorStateList(colorStateList);
}
+ private ColorStateListDrawable(@NonNull ColorStateListDrawableState state) {
+ mState = state;
+ initializeColorDrawable();
+ onStateChange(getState());
+ }
+
@Override
public void draw(@NonNull Canvas canvas) {
mColorDrawable.draw(canvas);
@@ -286,11 +292,6 @@
}
}
- private ColorStateListDrawable(@NonNull ColorStateListDrawableState state) {
- mState = state;
- initializeColorDrawable();
- }
-
private void initializeColorDrawable() {
mColorDrawable = new ColorDrawable();
mColorDrawable.setCallback(this);