package com.ss.android.ugc.aweme.legoImp.task;

import X.0HH;
import X.3X4;
import X.AnonymousClass7lW;
import X.AnonymousClass878;
import X.AnonymousClass9FH;
import X.C22428Zd;
import X.C22438Ze;
import X.C25518ec;
import X.C29988lp;
import X.C42869Ft;
import X.C42909Fx;
import X.RY1;
import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.util.LongSparseArray;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.abmock.SettingsManager;
import com.facebook.common.references.SharedReference;
import java.lang.reflect.Field;
import java.util.List;

public class PreloadResCleanerTask implements AnonymousClass9FH, C22438Ze {
    static {
        Covode.recordClassIndex(90570);
    }

    public String[] deps() {
        return null;
    }

    public boolean meetTrigger() {
        return true;
    }

    public String prefix() {
        return "task_";
    }

    public boolean serialExecute() {
        return false;
    }

    public int targetProcess() {
        return 1;
    }

    public List triggerOtherLegoComponents() {
        return null;
    }

    public C42869Ft triggerType() {
        return C22428Zd.LIZ(this);
    }

    public C42909Fx scenesType() {
        return C42909Fx.DEFAULT;
    }

    public C29988lp threadType() {
        return C29988lp.CPU;
    }

    public C25518ec type() {
        return C25518ec.BOOT_FINISH;
    }

    public String key() {
        return getClass().getSimpleName();
    }

    public int priority() {
        if (RY1.LJ.LIZIZ()) {
            return 2;
        }
        return 1;
    }

    public static Context LIZ(Context context) {
        Context applicationContext = context.getApplicationContext();
        if (AnonymousClass7lW.LIZJ && applicationContext == null) {
            return AnonymousClass7lW.LIZ;
        }
        return applicationContext;
    }

    public void run(Context context) {
        int i = 0;
        if (RY1.LJ.LIZIZ() || SettingsManager.LIZ().LIZ("enable_preload_opt", false)) {
            if (Build.VERSION.SDK_INT >= 24) {
                try {
                    Object LIZ = 3X4.LIZ(LIZ(context).getResources(), "mResourcesImpl");
                    if (LIZ != null) {
                        Object LIZ2 = 3X4.LIZ(LIZ, "sPreloadedDrawables");
                        if (LIZ2 instanceof LongSparseArray[]) {
                            LongSparseArray[] longSparseArrayArr = (LongSparseArray[]) LIZ2;
                            int length = longSparseArrayArr.length;
                            while (i < length) {
                                AnonymousClass878.LIZ((Object) longSparseArrayArr[i]);
                                i++;
                            }
                        } else {
                            AnonymousClass878.LIZ((Object) (LongSparseArray) LIZ2);
                        }
                        AnonymousClass878.LIZ(3X4.LIZ(LIZ, "sPreloadedColorDrawables"));
                        AnonymousClass878.LIZ(3X4.LIZ(LIZ, "sPreloadedComplexColors"));
                        Object LIZ3 = 3X4.LIZ(LIZ, "mDrawableCache");
                        if (LIZ3 != null) {
                            AnonymousClass878.LIZ(3X4.LIZ(LIZ3, "mNullThemedEntries"));
                            AnonymousClass878.LIZ(3X4.LIZ(LIZ3, "mThemedEntries"));
                            AnonymousClass878.LIZ(3X4.LIZ(LIZ3, "mUnthemedEntries"));
                        }
                        AnonymousClass878.LIZ(3X4.LIZ(LIZ, "mDrawableCache"));
                        AnonymousClass878.LIZ(3X4.LIZ(LIZ, "mColorDrawableCache"));
                        AnonymousClass878.LIZ(3X4.LIZ(LIZ, "mColorStateListCache"));
                    }
                } catch (Exception e) {
                    0HH.LIZ(e);
                }
            } else if (Build.VERSION.SDK_INT >= 23) {
                try {
                    Resources resources = LIZ(context).getResources();
                    Object LIZ4 = 3X4.LIZ(resources, "sPreloadedDrawables");
                    if (LIZ4 instanceof LongSparseArray[]) {
                        LongSparseArray[] longSparseArrayArr2 = (LongSparseArray[]) LIZ4;
                        int length2 = longSparseArrayArr2.length;
                        while (i < length2) {
                            AnonymousClass878.LIZ((Object) longSparseArrayArr2[i]);
                            i++;
                        }
                    } else {
                        AnonymousClass878.LIZ((Object) (LongSparseArray) LIZ4);
                    }
                    AnonymousClass878.LIZ(3X4.LIZ(resources, "sPreloadedColorDrawables"));
                    AnonymousClass878.LIZ(3X4.LIZ(resources, "sPreloadedColorStateLists"));
                    AnonymousClass878.LIZ(3X4.LIZ(resources, "mDrawableCache"));
                    AnonymousClass878.LIZ(3X4.LIZ(resources, "mColorDrawableCache"));
                    AnonymousClass878.LIZ(3X4.LIZ(resources, "mColorStateListCache"));
                } catch (Exception e2) {
                    0HH.LIZ(e2);
                }
            } else if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 19) {
                try {
                    Object LIZ5 = 3X4.LIZ(LIZ(context).getResources(), "sPreloadedDrawables");
                    if (LIZ5 instanceof LongSparseArray[]) {
                        LongSparseArray[] longSparseArrayArr3 = (LongSparseArray[]) LIZ5;
                        int length3 = longSparseArrayArr3.length;
                        while (i < length3) {
                            AnonymousClass878.LIZ((Object) longSparseArrayArr3[i]);
                            i++;
                        }
                    } else {
                        AnonymousClass878.LIZ((Object) (LongSparseArray) LIZ5);
                    }
                } catch (Exception e3) {
                    0HH.LIZ(e3);
                }
            }
            if (((Boolean) RY1.LIZIZ.getValue()).booleanValue() && Build.VERSION.SDK_INT >= 23) {
                try {
                    Class<?> cls = Class.forName("android.text.Hyphenator");
                    AnonymousClass878.LIZ(LIZ(cls, "sMap").get(cls));
                } catch (Throwable unused) {
                }
            }
            if (((Boolean) RY1.LIZJ.getValue()).booleanValue()) {
                try {
                    AnonymousClass878.LIZ(LIZ(SharedReference.class, "sLiveObjects").get(SharedReference.class));
                } catch (Throwable unused2) {
                }
            }
        }
    }

    public static Field LIZ(Class<?> cls, String str) {
        try {
            Field field = (Field) Class.class.getDeclaredMethod("getDeclaredField", new Class[]{String.class}).invoke(cls, new Object[]{str});
            field.setAccessible(true);
            return field;
        } catch (Throwable unused) {
            return null;
        }
    }
}
