Relaxed nullability requirements for setTintMode APIs for
both PorterDuff.Mode and BlendMode The existing documentation had annotated the PorterDuff.Mode parameter of Drawable#setTintMode to be @NonNull. However, some applications were still passing in null as a parameter. This was fine in previous releases as the default implementation of Drawable#setTintMode did not read this field. With the recent changes to introduce the BlendMode API, the nullability assumption broke for various apps that passed in null, causing NullPointerExceptions to be thrown. Instead, update the documentation to be nullable and internally convert the parameter to the corresponding default for either PorterDuff.Mode or BlendMode. Test: Added CTS tests to verify null behavior for each setTintMode overload Bug: 129446670 Change-Id: I42a4b03d190e5a64df518b5c768b2c22853abf12
This commit is contained in:
@@ -15384,8 +15384,8 @@ package android.graphics.drawable {
|
||||
method public boolean setState(@NonNull int[]);
|
||||
method public void setTint(@ColorInt int);
|
||||
method public void setTintList(@Nullable android.content.res.ColorStateList);
|
||||
method @Deprecated public void setTintMode(@NonNull android.graphics.PorterDuff.Mode);
|
||||
method public void setTintMode(@NonNull android.graphics.BlendMode);
|
||||
method @Deprecated public void setTintMode(@Nullable android.graphics.PorterDuff.Mode);
|
||||
method public void setTintMode(@Nullable android.graphics.BlendMode);
|
||||
method public boolean setVisible(boolean, boolean);
|
||||
method public void unscheduleSelf(@NonNull Runnable);
|
||||
}
|
||||
|
||||
@@ -688,20 +688,20 @@ public abstract class Drawable {
|
||||
* {@link #setColorFilter(int, PorterDuff.Mode)} overrides tint.
|
||||
* </p>
|
||||
*
|
||||
* @param tintMode A Porter-Duff blending mode
|
||||
* @param tintMode A Porter-Duff blending mode to apply to the drawable, a value of null sets
|
||||
* the default Porter-Diff blending mode value
|
||||
* of {@link PorterDuff.Mode#SRC_IN}
|
||||
* @see #setTint(int)
|
||||
* @see #setTintList(ColorStateList)
|
||||
*
|
||||
* @deprecated use {@link #setTintMode(BlendMode)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setTintMode(@NonNull PorterDuff.Mode tintMode) {
|
||||
public void setTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
if (!mSetTintModeInvoked) {
|
||||
mSetTintModeInvoked = true;
|
||||
BlendMode mode = BlendMode.fromValue(tintMode.nativeInt);
|
||||
if (mode != null) {
|
||||
setTintMode(mode);
|
||||
}
|
||||
BlendMode mode = tintMode != null ? BlendMode.fromValue(tintMode.nativeInt) : null;
|
||||
setTintMode(mode != null ? mode : Drawable.DEFAULT_BLEND_MODE);
|
||||
mSetTintModeInvoked = false;
|
||||
}
|
||||
}
|
||||
@@ -716,17 +716,16 @@ public abstract class Drawable {
|
||||
* {@link #setColorFilter(ColorFilter)}
|
||||
* </p>
|
||||
*
|
||||
* @param blendMode
|
||||
* @param blendMode BlendMode to apply to the drawable, a value of null sets the default
|
||||
* blend mode value of {@link BlendMode#SRC_IN}
|
||||
* @see #setTint(int)
|
||||
* @see #setTintList(ColorStateList)
|
||||
*/
|
||||
public void setTintMode(@NonNull BlendMode blendMode) {
|
||||
public void setTintMode(@Nullable BlendMode blendMode) {
|
||||
if (!mSetBlendModeInvoked) {
|
||||
mSetBlendModeInvoked = true;
|
||||
PorterDuff.Mode mode = BlendMode.blendModeToPorterDuffMode(blendMode);
|
||||
if (mode != null) {
|
||||
setTintMode(mode);
|
||||
}
|
||||
setTintMode(mode != null ? mode : Drawable.DEFAULT_TINT_MODE);
|
||||
mSetBlendModeInvoked = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user