Skip to content

Commit 26e35fc

Browse files
committed
Fix LayerDrawable#mutate
Change-Id: I985b80141ffc96db969eaf36538df938cb093661
1 parent 8dc8a43 commit 26e35fc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

graphics/java/android/graphics/drawable/LayerDrawable.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ public ConstantState getConstantState() {
575575
@Override
576576
public Drawable mutate() {
577577
if (!mMutated && super.mutate() == this) {
578+
if (!mLayerState.canConstantState()) {
579+
throw new IllegalStateException("One or more children of this LayerDrawable does " +
580+
"not have constant state; this drawable cannot be mutated.");
581+
}
582+
mLayerState = new LayerState(mLayerState, this, null);
578583
final ChildDrawable[] array = mLayerState.mChildren;
579584
final int N = mLayerState.mNum;
580585
for (int i = 0; i < N; i++) {
@@ -694,7 +699,7 @@ public final boolean isStateful() {
694699
return stateful;
695700
}
696701

697-
public synchronized boolean canConstantState() {
702+
public boolean canConstantState() {
698703
if (!mCheckedConstantState && mChildren != null) {
699704
mCanConstantState = true;
700705
final int N = mNum;

0 commit comments

Comments
 (0)