Added null checks to LayerDrawable implementation

Added null checks around usages of drawable child layers
within the constructor as well as the isProjected method

Test: Added cts tests to LayerDrawableTest
Bug: 134902243
Change-Id: I94a5fbc896ab53e29f4db4dcd04daf0bf9dd66dc
This commit is contained in:
Nader Jawad
2019-06-18 15:53:26 -07:00
parent a501bbc75c
commit abfcd0aa86

View File

@@ -139,9 +139,12 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
final ChildDrawable[] r = new ChildDrawable[length];
for (int i = 0; i < length; i++) {
r[i] = new ChildDrawable(mLayerState.mDensity);
r[i].mDrawable = layers[i];
layers[i].setCallback(this);
mLayerState.mChildrenChangingConfigurations |= layers[i].getChangingConfigurations();
Drawable child = layers[i];
r[i].mDrawable = child;
if (child != null) {
child.setCallback(this);
mLayerState.mChildrenChangingConfigurations |= child.getChangingConfigurations();
}
}
mLayerState.mNumChildren = length;
mLayerState.mChildren = r;
@@ -416,7 +419,8 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
final ChildDrawable[] layers = mLayerState.mChildren;
final int N = mLayerState.mNumChildren;
for (int i = 0; i < N; i++) {
if (layers[i].mDrawable.isProjected()) {
Drawable childDrawable = layers[i].mDrawable;
if (childDrawable != null && childDrawable.isProjected()) {
return true;
}
}