package X6FRs_4.KQgRr5e_0.Nm6q_10;

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;
/* compiled from: ResourcesFlusher.java */
/* loaded from: classes.dex */
public class IMuAHx_6 {
    public static Class KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static Field f791KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static boolean f792KQgRr5e_0;

    /* renamed from: Mqv2r_3  reason: collision with root package name */
    public static boolean f3179Mqv2r_3;
    public static Field PGPF6hQ_2;

    /* renamed from: PGPF6hQ_2  reason: collision with other field name */
    public static boolean f793PGPF6hQ_2;
    public static Field QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public static boolean f794QxJ9d_1;

    public static void KQgRr5e_0(Resources resources) {
        int i = Build.VERSION.SDK_INT;
        if (i >= 28) {
            return;
        }
        if (i >= 24) {
            Mqv2r_3(resources);
        } else if (i >= 23) {
            PGPF6hQ_2(resources);
        } else if (i >= 21) {
            QxJ9d_1(resources);
        }
    }

    public static void Mqv2r_3(Resources resources) {
        Object obj;
        if (!f3179Mqv2r_3) {
            try {
                Field declaredField = Resources.class.getDeclaredField("mResourcesImpl");
                PGPF6hQ_2 = declaredField;
                declaredField.setAccessible(true);
            } catch (NoSuchFieldException e) {
                Log.e("ResourcesFlusher", "Could not retrieve Resources#mResourcesImpl field", e);
            }
            f3179Mqv2r_3 = true;
        }
        Field field = PGPF6hQ_2;
        if (field == null) {
            return;
        }
        Object obj2 = null;
        try {
            obj = field.get(resources);
        } catch (IllegalAccessException e2) {
            Log.e("ResourcesFlusher", "Could not retrieve value from Resources#mResourcesImpl", e2);
            obj = null;
        }
        if (obj == null) {
            return;
        }
        if (!f792KQgRr5e_0) {
            try {
                Field declaredField2 = obj.getClass().getDeclaredField("mDrawableCache");
                f791KQgRr5e_0 = declaredField2;
                declaredField2.setAccessible(true);
            } catch (NoSuchFieldException e3) {
                Log.e("ResourcesFlusher", "Could not retrieve ResourcesImpl#mDrawableCache field", e3);
            }
            f792KQgRr5e_0 = true;
        }
        Field field2 = f791KQgRr5e_0;
        if (field2 != null) {
            try {
                obj2 = field2.get(obj);
            } catch (IllegalAccessException e4) {
                Log.e("ResourcesFlusher", "Could not retrieve value from ResourcesImpl#mDrawableCache", e4);
            }
        }
        if (obj2 != null) {
            KQgRr5e_0(obj2);
        }
    }

    public static void PGPF6hQ_2(Resources resources) {
        if (!f792KQgRr5e_0) {
            try {
                Field declaredField = Resources.class.getDeclaredField("mDrawableCache");
                f791KQgRr5e_0 = declaredField;
                declaredField.setAccessible(true);
            } catch (NoSuchFieldException e) {
                Log.e("ResourcesFlusher", "Could not retrieve Resources#mDrawableCache field", e);
            }
            f792KQgRr5e_0 = true;
        }
        Object obj = null;
        Field field = f791KQgRr5e_0;
        if (field != null) {
            try {
                obj = field.get(resources);
            } catch (IllegalAccessException e2) {
                Log.e("ResourcesFlusher", "Could not retrieve value from Resources#mDrawableCache", e2);
            }
        }
        if (obj == null) {
            return;
        }
        KQgRr5e_0(obj);
    }

    public static void QxJ9d_1(Resources resources) {
        if (!f792KQgRr5e_0) {
            try {
                Field declaredField = Resources.class.getDeclaredField("mDrawableCache");
                f791KQgRr5e_0 = declaredField;
                declaredField.setAccessible(true);
            } catch (NoSuchFieldException e) {
                Log.e("ResourcesFlusher", "Could not retrieve Resources#mDrawableCache field", e);
            }
            f792KQgRr5e_0 = true;
        }
        Field field = f791KQgRr5e_0;
        if (field != null) {
            Map map = null;
            try {
                map = (Map) field.get(resources);
            } catch (IllegalAccessException e2) {
                Log.e("ResourcesFlusher", "Could not retrieve value from Resources#mDrawableCache", e2);
            }
            if (map != null) {
                map.clear();
            }
        }
    }

    public static void KQgRr5e_0(Object obj) {
        if (!f794QxJ9d_1) {
            try {
                KQgRr5e_0 = Class.forName("android.content.res.ThemedResourceCache");
            } catch (ClassNotFoundException e) {
                Log.e("ResourcesFlusher", "Could not find ThemedResourceCache class", e);
            }
            f794QxJ9d_1 = true;
        }
        Class cls = KQgRr5e_0;
        if (cls == null) {
            return;
        }
        if (!f793PGPF6hQ_2) {
            try {
                Field declaredField = cls.getDeclaredField("mUnthemedEntries");
                QxJ9d_1 = declaredField;
                declaredField.setAccessible(true);
            } catch (NoSuchFieldException e2) {
                Log.e("ResourcesFlusher", "Could not retrieve ThemedResourceCache#mUnthemedEntries field", e2);
            }
            f793PGPF6hQ_2 = true;
        }
        Field field = QxJ9d_1;
        if (field == null) {
            return;
        }
        LongSparseArray longSparseArray = null;
        try {
            longSparseArray = (LongSparseArray) field.get(obj);
        } catch (IllegalAccessException e3) {
            Log.e("ResourcesFlusher", "Could not retrieve value from ThemedResourceCache#mUnthemedEntries", e3);
        }
        if (longSparseArray != null) {
            longSparseArray.clear();
        }
    }
}
