Merge "Fix CTS test for nine patch padding sanity check" into lmp-dev
diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
index 6ebb8b5..a6dbcb0 100644
--- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java
+++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
@@ -626,13 +626,18 @@
mAutoMirrored = autoMirror;
// Sanity check for valid padding when we have optical insets.
- if (mPadding.left < mOpticalInsets.left) {
- mPadding.left = mOpticalInsets.left;
- mPadding.right = mOpticalInsets.right;
- }
- if (mPadding.top < mOpticalInsets.top) {
- mPadding.top = mOpticalInsets.top;
- mPadding.bottom = mOpticalInsets.bottom;
+ if (!opticalInsets.isEmpty()) {
+ if (mPadding == null) {
+ mPadding = new Rect();
+ }
+ if (mPadding.left < opticalInsets.left) {
+ mPadding.left = opticalInsets.left;
+ mPadding.right = opticalInsets.right;
+ }
+ if (mPadding.top < opticalInsets.top) {
+ mPadding.top = opticalInsets.top;
+ mPadding.bottom = opticalInsets.bottom;
+ }
}
}