content: package androidx.appcompat.app;
  
  import android.content.res.Resources;
  import android.os.Build;
  import android.util.Log;
  import android.util.LongSparseArray;
  import java.lang.reflect.Field;
  import java.util.Map;
  
  class ResourcesFlusher {
      private static final String TAG = "ResourcesFlusher";
      private static Field sDrawableCacheField;
      private static boolean sDrawableCacheFieldFetched;
      private static Field sResourcesImplField;
      private static boolean sResourcesImplFieldFetched;
      private static Class<?> sThemedResourceCacheClazz;
      private static boolean sThemedResourceCacheClazzFetched;
      private static Field sThemedResourceCache_mUnthemedEntriesField;
      private static boolean sThemedResourceCache_mUnthemedEntriesFieldFetched;
  
      static class Api16Impl {
          private Api16Impl() {
          }
  
          static void clear(LongSparseArray longSparseArray) {
              longSparseArray.clear();
          }
      }
  
      private ResourcesFlusher() {
      }
  
      static void flush(Resources resources) {
          if (Build.VERSION.SDK_INT < 28) {
              if (Build.VERSION.SDK_INT >= 24) {
                  flushNougats(resources);
              } else if (Build.VERSION.SDK_INT >= 23) {
                  flushMarshmallows(resources);
              } else if (Build.VERSION.SDK_INT >= 21) {
                  flushLollipops(resources);
              }
          }
      }
  
      private static void flushLollipops(Resources resources) {
          if (!sDrawableCacheFieldFetched) {
              try {
                  Field declaredField = Resources.class.getDeclaredField("mDrawableCache");
                  sDrawableCacheField = declaredField;
                  declaredField.setAccessible(true);
              } catch (NoSuchFieldException e) {
                  Log.e(TAG, "Could not retrieve Resources#mDrawableCache field", e);
              }
              sDrawableCacheFieldFetched = true;
          }
          Field field = sDrawableCacheField;
          if (field != null) {
              Map map = null;
              try {
                  map = (Map) field.get(resources);
              } catch (IllegalAccessException e2) {
                  Log.e(TAG, "Could not retrieve value from Resources#mDrawableCache", e2);
              }
              if (map != null) {
                  map.clear();
              }
          }
      }
  
      private static void flushMarshmallows(Resources resources) {
          if (!sDrawableCacheFieldFetched) {
              try {
                  Field declaredField = Resources.class.getDeclaredField("mDrawableCache");
                  sDrawableCacheField = declaredField;
                  declaredField.setAccessible(true);
              } catch (NoSuchFieldException e) {
                  Log.e(TAG, "Could not retrieve Resources#mDrawableCache field", e);
              }
              sDrawableCacheFieldFetched = true;
          }
          Object obj = null;
          Field field = sDrawableCacheField;
          if (field != null) {
              try {
                  obj = field.get(resources);
              } catch (IllegalAccessException e2) {
                  Log.e(TAG, "Could not retrieve value from Resources#mDrawableCache", e2);
              }
          }
          if (obj != null) {
              flushThemedResourcesCache(obj);
          }
      }
  
      private static void flushNougats(Resources resources) {
          if (!sResourcesImplFieldFetched) {
              try {
                  Field declaredField = Resources.class.getDeclaredField("mResourcesImpl");
                  sResourcesImplField = declaredField;
                  declaredField.setAccessible(true);
              } catch (NoSuchFieldException e) {
                  Log.e(TAG, "Could not retrieve Resources#mResourcesImpl field", e);
              }
              sResourcesImplFieldFetched = true;
          }
          Field field = sResourcesImplField;
          if (field != null) {
              Object obj = null;
              try {
                  obj = field.get(resources);
              } catch (IllegalAccessException e2) {
                  Log.e(TAG, "Could not retrieve value from Resources#mResourcesImpl", e2);
              }
              if (obj != null) {
                  if (!sDrawableCacheFieldFetched) {
                      try {
                          Field declaredField2 = obj.getClass().getDeclaredField("mDrawableCache");
                          sDrawableCacheField = declaredField2;
                          declaredField2.setAccessible(true);
                      } catch (NoSuchFieldException e3) {
                          Log.e(TAG, "Could not retrieve ResourcesImpl#mDrawableCache field", e3);
                      }
                      sDrawableCacheFieldFetched = true;
                  }
                  Object obj2 = null;
                  Field field2 = sDrawableCacheField;
                  if (field2 != null) {
                      try {
                          obj2 = field2.get(obj);
                      } catch (IllegalAccessException e4) {
                          Log.e(TAG, "Could not retrieve value from ResourcesImpl#mDrawableCache", e4);
                      }
                  }
                  if (obj2 != null) {
                      flushThemedResourcesCache(obj2);
                  }
              }
          }
      }
  
      private static void flushThemedResourcesCache(Object cache) {
          if (!sThemedResourceCacheClazzFetched) {
              try {
                  sThemedResourceCacheClazz = Class.forName("android.content.res.ThemedResourceCache");
              } catch (ClassNotFoundException e) {
                  Log.e(TAG, "Could not find ThemedResourceCache class", e);
              }
              sThemedResourceCacheClazzFetched = true;
          }
          Class<?> cls = sThemedResourceCacheClazz;
          if (cls != null) {
              if (!sThemedResourceCache_mUnthemedEntriesFieldFetched) {
                  try {
                      Field declaredField = cls.getDeclaredField("mUnthemedEntries");
                      sThemedResourceCache_mUnthemedEntriesField = declaredField;
                      declaredField.setAccessible(true);
                  } catch (NoSuchFieldException e2) {
                      Log.e(TAG, "Could not retrieve ThemedResourceCache#mUnthemedEntries field", e2);
                  }
                  sThemedResourceCache_mUnthemedEntriesFieldFetched = true;
              }
              Field field = sThemedResourceCache_mUnthemedEntriesField;
              if (field != null) {
                  LongSparseArray longSparseArray = null;
                  try {
                      longSparseArray = (LongSparseArray) field.get(cache);
                  } catch (IllegalAccessException e3) {
                      Log.e(TAG, "Could not retrieve value from ThemedResourceCache#mUnthemedEntries", e3);
                  }
                  if (longSparseArray != null) {
                      Api16Impl.clear(longSparseArray);
                  }
              }
          }
      }
  }
  