Skip to content

Commit

Permalink
Fix ResourceID validation check expression
Browse files Browse the repository at this point in the history
  • Loading branch information
hyuns66 committed Sep 9, 2024
1 parent f452e11 commit 6981250
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.res.Resources.Theme;
import android.graphics.drawable.Drawable;
import android.util.Log;

import androidx.annotation.AnyRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -387,8 +389,7 @@ public boolean isAnyResourceSet() {
private Drawable getErrorDrawable() {
if (errorDrawable == null) {
errorDrawable = requestOptions.getErrorPlaceholder();
if (errorDrawable == null && requestOptions.getErrorId() != -1 &&
(requestOptions.getErrorId() & 0xff000000) != 0 && (requestOptions.getErrorId() & 0x00ff0000) != 0) {
if (errorDrawable == null && isValidId(requestOptions.getErrorId())) {
errorDrawable = loadDrawable(requestOptions.getErrorId());
}
}
Expand All @@ -399,8 +400,7 @@ private Drawable getErrorDrawable() {
private Drawable getPlaceholderDrawable() {
if (placeholderDrawable == null) {
placeholderDrawable = requestOptions.getPlaceholderDrawable();
if (placeholderDrawable == null && requestOptions.getPlaceholderId() != -1 &&
(requestOptions.getPlaceholderId() & 0xff000000) != 0 && (requestOptions.getPlaceholderId() & 0x00ff0000) != 0) {
if (placeholderDrawable == null && isValidId(requestOptions.getPlaceholderId())) {
placeholderDrawable = loadDrawable(requestOptions.getPlaceholderId());
}
}
Expand All @@ -411,14 +411,20 @@ private Drawable getPlaceholderDrawable() {
private Drawable getFallbackDrawable() {
if (fallbackDrawable == null) {
fallbackDrawable = requestOptions.getFallbackDrawable();
if (fallbackDrawable == null && requestOptions.getFallbackId() != -1 &&
(requestOptions.getFallbackId() & 0xff000000) != 0 && (requestOptions.getFallbackId() & 0x00ff0000) != 0) {
if (fallbackDrawable == null && isValidId(requestOptions.getFallbackId())) {
fallbackDrawable = loadDrawable(requestOptions.getFallbackId());
}
}
return fallbackDrawable;
}

/**
* @see android.content.res.ResourceId.isValid
*/
private static boolean isValidId(int id) {
return id != -1 && (id & 0xff000000) != 0 && (id & 0x00ff0000) != 0;
}

@GuardedBy("requestLock")
private Drawable loadDrawable(@DrawableRes int resourceId) {
Theme theme =
Expand Down

0 comments on commit 6981250

Please sign in to comment.