From abfcd0aa86f92afb46db2ffb9f5c4a45bab97a69 Mon Sep 17 00:00:00 2001 From: Nader Jawad Date: Tue, 18 Jun 2019 15:53:26 -0700 Subject: 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 --- graphics/java/android/graphics/drawable/LayerDrawable.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'graphics/java/android') diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index f3a1b0eb52d5..760d554888ee 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -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; } } -- cgit v1.2.3-59-g8ed1b