Added tests to verify relaxed nullability restrictions on setTintMode
Drawable APIs

Added tests to verify that passing a null PorterDuff.Mode ends up
using the default of BlendMode.SRC_IN. Additionally add test to
verify that passing a null BlendMode ends up with usage of the
default of PorterDuff.Mode.SRC_IN

Test: this
Bug: 129446670
Change-Id: Ib5a4d6870673cb2bafe768ff186e1ffc5f4c8d3b
(cherry picked from commit 142772fc9ac2e03e505f8a0553216f309e8ef146)
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java
index 716e25f..3fb9587 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java
@@ -814,10 +814,10 @@
         // Setting a BlendMode should delegate to the PorterDuff.Mode API
         TestTintDrawable testTintDrawable = new TestTintDrawable();
         testTintDrawable.setTintMode(BlendMode.LUMINOSITY);
-        // 0 times invoking setTintMode because there is no equivalent for the luminosity blend mode
-        // on older API levels
-        assertEquals(0, testTintDrawable.getNumTimesTintModeInvoked());
-        assertEquals(1, testTintDrawable.getNumTimesBlendModeInvoked());
+        // 1 time invoking setTintMode because the default is applied if there is no equivalent for
+        // the luminosity blend mode on older API levels
+        assertEquals(1, testTintDrawable.getNumTimesTintModeInvoked());
+        assertEquals(2, testTintDrawable.getNumTimesBlendModeInvoked());
     }
 
     @Test
@@ -864,6 +864,20 @@
         assertEquals(0, test.getNumTimesBlendModeInvoked());
     }
 
+    @Test
+    public void testNullPorterDuffReturnsDefaultBlendMode() {
+        TestNullBlendModeDrawable d = new TestNullBlendModeDrawable();
+        d.setTintMode((PorterDuff.Mode) null);
+        assertEquals(BlendMode.SRC_IN, d.mode);
+    }
+
+    @Test
+    public void testNullBlendModeReturnsDefaultPorterDuffMode() {
+        TestNullPorterDuffDrawable d = new TestNullPorterDuffDrawable();
+        d.setTintMode((BlendMode) null);
+        assertEquals(PorterDuff.Mode.SRC_IN, d.mode);
+    }
+
     // Since Mockito can't mock or spy on protected methods, we have a custom extension
     // of Drawable to track calls to protected methods. This class also has empty implementations
     // of the base abstract methods.
@@ -952,6 +966,66 @@
         }
     }
 
+    private static class TestNullPorterDuffDrawable extends Drawable {
+
+        public PorterDuff.Mode mode;
+
+        @Override
+        public void draw(Canvas canvas) {
+
+        }
+
+        @Override
+        public void setAlpha(int alpha) {
+
+        }
+
+        @Override
+        public void setColorFilter(ColorFilter colorFilter) {
+
+        }
+
+        @Override
+        public void setTintMode(PorterDuff.Mode tintMode) {
+            mode = tintMode;
+        }
+
+        @Override
+        public int getOpacity() {
+            return 0;
+        }
+    }
+
+    private static class TestNullBlendModeDrawable extends Drawable {
+
+        public BlendMode mode;
+
+        @Override
+        public void draw(Canvas canvas) {
+
+        }
+
+        @Override
+        public void setAlpha(int alpha) {
+
+        }
+
+        @Override
+        public void setColorFilter(ColorFilter colorFilter) {
+
+        }
+
+        @Override
+        public void setTintMode(BlendMode blendMode) {
+            mode = blendMode;
+        }
+
+        @Override
+        public int getOpacity() {
+            return 0;
+        }
+    }
+
     private static class TestBlendModeImplementedDrawable extends Drawable {
 
         private int mSetTintModeInvoked = 0;