content: package androidx.core.graphics;
  
  import android.content.Context;
  import android.content.res.Resources;
  import android.graphics.Typeface;
  import android.net.Uri;
  import android.os.CancellationSignal;
  import android.util.Log;
  import androidx.collection.SimpleArrayMap;
  import androidx.core.content.res.FontResourcesParserCompat;
  import androidx.core.provider.FontsContractCompat;
  import java.lang.reflect.Array;
  import java.lang.reflect.Constructor;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.nio.ByteBuffer;
  import java.util.List;
  
  class TypefaceCompatApi24Impl extends TypefaceCompatBaseImpl {
      private static final String ADD_FONT_WEIGHT_STYLE_METHOD = "addFontWeightStyle";
      private static final String CREATE_FROM_FAMILIES_WITH_DEFAULT_METHOD = "createFromFamiliesWithDefault";
      private static final String FONT_FAMILY_CLASS = "android.graphics.FontFamily";
      private static final String TAG = "TypefaceCompatApi24Impl";
      private static final Method sAddFontWeightStyle;
      private static final Method sCreateFromFamiliesWithDefault;
      private static final Class<?> sFontFamily;
      private static final Constructor<?> sFontFamilyCtor;
  
      static {
          Method method;
          Constructor<?> constructor;
          Method method2;
          Class<?> cls;
          try {
              cls = Class.forName(FONT_FAMILY_CLASS);
              constructor = cls.getConstructor(new Class[0]);
              method = cls.getMethod(ADD_FONT_WEIGHT_STYLE_METHOD, new Class[]{ByteBuffer.class, Integer.TYPE, List.class, Integer.TYPE, Boolean.TYPE});
              method2 = Typeface.class.getMethod(CREATE_FROM_FAMILIES_WITH_DEFAULT_METHOD, new Class[]{Array.newInstance(cls, 1).getClass()});
          } catch (ClassNotFoundException | NoSuchMethodException e) {
              Log.e(TAG, e.getClass().getName(), e);
              constructor = null;
              method = null;
              cls = null;
              method2 = null;
          }
          sFontFamilyCtor = constructor;
          sFontFamily = cls;
          sAddFontWeightStyle = method;
          sCreateFromFamiliesWithDefault = method2;
      }
  
      TypefaceCompatApi24Impl() {
      }
  
      private static boolean addFontWeightStyle(Object family, ByteBuffer buffer, int ttcIndex, int weight, boolean style) {
          try {
              return ((Boolean) sAddFontWeightStyle.invoke(family, new Object[]{buffer, Integer.valueOf(ttcIndex), null, Integer.valueOf(weight), Boolean.valueOf(style)})).booleanValue();
          } catch (IllegalAccessException | InvocationTargetException e) {
              return false;
          }
      }
  
      private static Typeface createFromFamiliesWithDefault(Object family) {
          try {
              Object newInstance = Array.newInstance(sFontFamily, 1);
              Array.set(newInstance, 0, family);
              return (Typeface) sCreateFromFamiliesWithDefault.invoke((Object) null, new Object[]{newInstance});
          } catch (IllegalAccessException | InvocationTargetException e) {
              return null;
          }
      }
  
      public static boolean isUsable() {
          Method method = sAddFontWeightStyle;
          if (method == null) {
              Log.w(TAG, "Unable to collect necessary private methods.Fallback to legacy implementation.");
          }
          return method != null;
      }
  
      private static Object newFamily() {
          try {
              return sFontFamilyCtor.newInstance(new Object[0]);
          } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
              return null;
          }
      }
  
      public Typeface createFromFontFamilyFilesResourceEntry(Context context, FontResourcesParserCompat.FontFamilyFilesResourceEntry entry, Resources resources, int style) {
          Object newFamily = newFamily();
          if (newFamily == null) {
              return null;
          }
          for (FontResourcesParserCompat.FontFileResourceEntry fontFileResourceEntry : entry.getEntries()) {
              ByteBuffer copyToDirectBuffer = TypefaceCompatUtil.copyToDirectBuffer(context, resources, fontFileResourceEntry.getResourceId());
              if (copyToDirectBuffer == null || !addFontWeightStyle(newFamily, copyToDirectBuffer, fontFileResourceEntry.getTtcIndex(), fontFileResourceEntry.getWeight(), fontFileResourceEntry.isItalic())) {
                  return null;
              }
          }
          return createFromFamiliesWithDefault(newFamily);
      }
  
      public Typeface createFromFontInfo(Context context, CancellationSignal cancellationSignal, FontsContractCompat.FontInfo[] fonts, int style) {
          Object newFamily = newFamily();
          if (newFamily == null) {
              return null;
          }
          SimpleArrayMap simpleArrayMap = new SimpleArrayMap();
          for (FontsContractCompat.FontInfo fontInfo : fonts) {
              Uri uri = fontInfo.getUri();
              ByteBuffer byteBuffer = (ByteBuffer) simpleArrayMap.get(uri);
              if (byteBuffer == null) {
                  byteBuffer = TypefaceCompatUtil.mmap(context, cancellationSignal, uri);
                  simpleArrayMap.put(uri, byteBuffer);
              }
              if (byteBuffer == null || !addFontWeightStyle(newFamily, byteBuffer, fontInfo.getTtcIndex(), fontInfo.getWeight(), fontInfo.isItalic())) {
                  return null;
              }
          }
          Typeface createFromFamiliesWithDefault = createFromFamiliesWithDefault(newFamily);
          if (createFromFamiliesWithDefault == null) {
              return null;
          }
          return Typeface.create(createFromFamiliesWithDefault, style);
      }
  }
  