content: package androidx.appcompat.widget;
  
  import android.graphics.Insets;
  import android.graphics.PorterDuff;
  import android.graphics.Rect;
  import android.graphics.drawable.Drawable;
  import android.graphics.drawable.DrawableContainer;
  import android.graphics.drawable.GradientDrawable;
  import android.graphics.drawable.InsetDrawable;
  import android.graphics.drawable.LayerDrawable;
  import android.graphics.drawable.ScaleDrawable;
  import android.os.Build;
  import androidx.appcompat.graphics.drawable.DrawableWrapper;
  import androidx.core.graphics.drawable.DrawableCompat;
  import androidx.core.graphics.drawable.WrappedDrawable;
  import java.lang.reflect.Field;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  
  public class DrawableUtils {
      private static final int[] CHECKED_STATE_SET = {16842912};
      private static final int[] EMPTY_STATE_SET = new int[0];
      public static final Rect INSETS_NONE = new Rect();
  
      static class Api18Impl {
          private static final Field sBottom;
          private static final Method sGetOpticalInsets;
          private static final Field sLeft;
          private static final boolean sReflectionSuccessful;
          private static final Field sRight;
          private static final Field sTop;
  
          static {
              Method method = null;
              Field field = null;
              Field field2 = null;
              Field field3 = null;
              Field field4 = null;
              boolean z = false;
              try {
                  Class<?> cls = Class.forName("android.graphics.Insets");
                  method = Drawable.class.getMethod("getOpticalInsets", new Class[0]);
                  field = cls.getField("left");
                  field2 = cls.getField("top");
                  field3 = cls.getField("right");
                  field4 = cls.getField("bottom");
                  z = true;
              } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
              }
              if (z) {
                  sGetOpticalInsets = method;
                  sLeft = field;
                  sTop = field2;
                  sRight = field3;
                  sBottom = field4;
                  sReflectionSuccessful = true;
                  return;
              }
              sGetOpticalInsets = null;
              sLeft = null;
              sTop = null;
              sRight = null;
              sBottom = null;
              sReflectionSuccessful = false;
          }
  
          private Api18Impl() {
          }
  
          static Rect getOpticalInsets(Drawable drawable) {
              if (Build.VERSION.SDK_INT < 29 && sReflectionSuccessful) {
                  try {
                      Object invoke = sGetOpticalInsets.invoke(drawable, new Object[0]);
                      if (invoke != null) {
                          return new Rect(sLeft.getInt(invoke), sTop.getInt(invoke), sRight.getInt(invoke), sBottom.getInt(invoke));
                      }
                  } catch (IllegalAccessException | InvocationTargetException e) {
                  }
              }
              return DrawableUtils.INSETS_NONE;
          }
      }
  
      static class Api29Impl {
          private Api29Impl() {
          }
  
          static Insets getOpticalInsets(Drawable drawable) {
              return drawable.getOpticalInsets();
          }
      }
  
      private DrawableUtils() {
      }
  
      public static boolean canSafelyMutateDrawable(Drawable drawable) {
          if (Build.VERSION.SDK_INT >= 17) {
              return true;
          }
          if (Build.VERSION.SDK_INT < 15 && (drawable instanceof InsetDrawable)) {
              return false;
          }
          if (Build.VERSION.SDK_INT < 15 && (drawable instanceof GradientDrawable)) {
              return false;
          }
          if (Build.VERSION.SDK_INT < 17 && (drawable instanceof LayerDrawable)) {
              return false;
          }
          if (drawable instanceof DrawableContainer) {
              Drawable.ConstantState constantState = drawable.getConstantState();
              if (constantState instanceof DrawableContainer.DrawableContainerState) {
                  for (Drawable canSafelyMutateDrawable : ((DrawableContainer.DrawableContainerState) constantState).getChildren()) {
                      if (!canSafelyMutateDrawable(canSafelyMutateDrawable)) {
                          return false;
                      }
                  }
              }
          } else if (drawable instanceof WrappedDrawable) {
              return canSafelyMutateDrawable(((WrappedDrawable) drawable).getWrappedDrawable());
          } else {
              if (drawable instanceof DrawableWrapper) {
                  return canSafelyMutateDrawable(((DrawableWrapper) drawable).getWrappedDrawable());
              }
              if (drawable instanceof ScaleDrawable) {
                  return canSafelyMutateDrawable(((ScaleDrawable) drawable).getDrawable());
              }
          }
          return true;
      }
  
      static void fixDrawable(Drawable drawable) {
          String name = drawable.getClass().getName();
          if (Build.VERSION.SDK_INT == 21 && "android.graphics.drawable.VectorDrawable".equals(name)) {
              forceDrawableStateChange(drawable);
          } else if (Build.VERSION.SDK_INT >= 29 && Build.VERSION.SDK_INT < 31 && "android.graphics.drawable.ColorStateListDrawable".equals(name)) {
              forceDrawableStateChange(drawable);
          }
      }
  
      private static void forceDrawableStateChange(Drawable drawable) {
          int[] state = drawable.getState();
          if (state == null || state.length == 0) {
              drawable.setState(CHECKED_STATE_SET);
          } else {
              drawable.setState(EMPTY_STATE_SET);
          }
          drawable.setState(state);
      }
  
      public static Rect getOpticalBounds(Drawable drawable) {
          if (Build.VERSION.SDK_INT < 29) {
              return Build.VERSION.SDK_INT >= 18 ? Api18Impl.getOpticalInsets(DrawableCompat.unwrap(drawable)) : INSETS_NONE;
          }
          Insets opticalInsets = Api29Impl.getOpticalInsets(drawable);
          return new Rect(opticalInsets.left, opticalInsets.top, opticalInsets.right, opticalInsets.bottom);
      }
  
      public static PorterDuff.Mode parseTintMode(int value, PorterDuff.Mode defaultMode) {
          switch (value) {
              case 3:
                  return PorterDuff.Mode.SRC_OVER;
              case 5:
                  return PorterDuff.Mode.SRC_IN;
              case 9:
                  return PorterDuff.Mode.SRC_ATOP;
              case 14:
                  return PorterDuff.Mode.MULTIPLY;
              case 15:
                  return PorterDuff.Mode.SCREEN;
              case 16:
                  return PorterDuff.Mode.ADD;
              default:
                  return defaultMode;
          }
      }
  }
  