package com.bumptech.glide;

import android.R;
import android.app.Activity;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import androidx.fragment.app.o;
import androidx.fragment.app.t;
import com.bumptech.glide.e;
import defpackage.a18;
import defpackage.au5;
import defpackage.bm5;
import defpackage.d18;
import defpackage.dq;
import defpackage.f18;
import defpackage.fq4;
import defpackage.gc1;
import defpackage.gf7;
import defpackage.hda;
import defpackage.ki4;
import defpackage.kv3;
import defpackage.ll5;
import defpackage.ml5;
import defpackage.pv3;
import defpackage.ts;
import defpackage.tz1;
import defpackage.ut5;
import defpackage.vl2;
import defpackage.xa0;
import defpackage.ya0;
import defpackage.ym5;
import defpackage.ys;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public class a implements ComponentCallbacks2 {
    public static volatile a l;
    public static volatile boolean m;
    public final vl2 a;
    public final xa0 b;
    public final ut5 c;
    public final d d;
    public final ys e;
    public final d18 f;
    public final gc1 i;
    public final ArrayList j = new ArrayList();
    public final InterfaceC0078a k;

    /* JADX INFO: renamed from: com.bumptech.glide.a$a, reason: collision with other inner class name */
    public interface InterfaceC0078a {
        f18 build();
    }

    public a(Context context, vl2 vl2Var, ut5 ut5Var, xa0 xa0Var, ys ysVar, d18 d18Var, gc1 gc1Var, int i, InterfaceC0078a interfaceC0078a, ts tsVar, List list, List list2, dq dqVar, e eVar) {
        this.a = vl2Var;
        this.b = xa0Var;
        this.e = ysVar;
        this.c = ut5Var;
        this.f = d18Var;
        this.i = gc1Var;
        this.k = interfaceC0078a;
        this.d = new d(context, ysVar, new f(this, list2, dqVar), new ki4(), interfaceC0078a, tsVar, list, vl2Var, eVar, i);
    }

    public static a b(Context context) {
        GeneratedAppGlideModule generatedAppGlideModule;
        if (l == null) {
            try {
                generatedAppGlideModule = (GeneratedAppGlideModule) GeneratedAppGlideModuleImpl.class.getDeclaredConstructor(Context.class).newInstance(context.getApplicationContext().getApplicationContext());
            } catch (ClassNotFoundException unused) {
                if (Log.isLoggable("Glide", 5)) {
                    Log.w("Glide", "Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored");
                }
                generatedAppGlideModule = null;
            } catch (IllegalAccessException e) {
                throw new IllegalStateException("GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.", e);
            } catch (InstantiationException e2) {
                throw new IllegalStateException("GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.", e2);
            } catch (NoSuchMethodException e3) {
                throw new IllegalStateException("GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.", e3);
            } catch (InvocationTargetException e4) {
                throw new IllegalStateException("GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.", e4);
            }
            synchronized (a.class) {
                if (l == null) {
                    if (m) {
                        throw new IllegalStateException("Glide has been called recursively, this is probably an internal library error!");
                    }
                    m = true;
                    try {
                        d(context, generatedAppGlideModule);
                        m = false;
                    } catch (Throwable th) {
                        m = false;
                        throw th;
                    }
                }
            }
        }
        return l;
    }

    public static d18 c(Context context) {
        gf7.c(context, "You cannot start a load on a not yet attached View or a Fragment where getActivity() returns null (which usually occurs when getActivity() is called before the Fragment is attached or after the Fragment is destroyed).");
        return b(context).f;
    }

    public static void d(Context context, GeneratedAppGlideModule generatedAppGlideModule) {
        List list;
        b bVar = new b();
        Context applicationContext = context.getApplicationContext();
        List list2 = Collections.EMPTY_LIST;
        if (generatedAppGlideModule == null || !(generatedAppGlideModule instanceof GeneratedAppGlideModuleImpl)) {
            ArrayList arrayList = new ArrayList();
            try {
                ApplicationInfo applicationInfo = applicationContext.getPackageManager().getApplicationInfo(applicationContext.getPackageName(), 128);
                if (applicationInfo != null && applicationInfo.metaData != null) {
                    if (Log.isLoggable("ManifestParser", 2)) {
                        Objects.toString(applicationInfo.metaData);
                    }
                    for (String str : applicationInfo.metaData.keySet()) {
                        if ("GlideModule".equals(applicationInfo.metaData.get(str))) {
                            arrayList.add(ym5.a(str));
                        }
                    }
                }
            } catch (PackageManager.NameNotFoundException e) {
                if (Log.isLoggable("ManifestParser", 6)) {
                    Log.e("ManifestParser", "Failed to parse glide modules", e);
                }
            }
            list = arrayList;
        } else {
            list = list2;
        }
        if (generatedAppGlideModule != null && !new HashSet().isEmpty()) {
            HashSet hashSet = new HashSet();
            Iterator it = list.iterator();
            while (it.hasNext()) {
                pv3 pv3Var = (pv3) it.next();
                if (hashSet.contains(pv3Var.getClass())) {
                    if (Log.isLoggable("Glide", 3)) {
                        pv3Var.toString();
                    }
                    it.remove();
                }
            }
        }
        if (Log.isLoggable("Glide", 3)) {
            Iterator it2 = list.iterator();
            while (it2.hasNext()) {
                ((pv3) it2.next()).getClass().toString();
            }
        }
        Iterator it3 = list.iterator();
        while (it3.hasNext()) {
            ((pv3) it3.next()).getClass();
        }
        if (generatedAppGlideModule != null) {
            generatedAppGlideModule.b(applicationContext, bVar);
        }
        if (bVar.g == null) {
            int i = kv3.c;
            kv3.b bVar2 = new kv3.b(false);
            if (kv3.c == 0) {
                kv3.c = Math.min(4, Runtime.getRuntime().availableProcessors());
            }
            int i2 = kv3.c;
            bVar2.b = i2;
            bVar2.c = i2;
            bVar2.f = "source";
            bVar.g = bVar2.a();
        }
        if (bVar.h == null) {
            int i3 = kv3.c;
            kv3.b bVar3 = new kv3.b(true);
            bVar3.b = 1;
            bVar3.c = 1;
            bVar3.f = "disk-cache";
            bVar.h = bVar3.a();
        }
        if (bVar.n == null) {
            if (kv3.c == 0) {
                kv3.c = Math.min(4, Runtime.getRuntime().availableProcessors());
            }
            int i4 = kv3.c < 4 ? 1 : 2;
            kv3.b bVar4 = new kv3.b(true);
            bVar4.b = i4;
            bVar4.c = i4;
            bVar4.f = "animation";
            bVar.n = bVar4.a();
        }
        if (bVar.j == null) {
            bVar.j = new au5(new au5.a(applicationContext));
        }
        if (bVar.k == null) {
            bVar.k = new tz1();
        }
        if (bVar.d == null) {
            int i5 = bVar.j.a;
            if (i5 > 0) {
                bVar.d = new ml5(i5);
            } else {
                bVar.d = new ya0();
            }
        }
        if (bVar.e == null) {
            bVar.e = new ll5(bVar.j.c);
        }
        if (bVar.f == null) {
            bVar.f = new bm5(bVar.j.b);
        }
        if (bVar.i == null) {
            bVar.i = new fq4(applicationContext, 262144000L);
        }
        if (bVar.c == null) {
            bVar.c = new vl2(bVar.f, bVar.i, bVar.h, bVar.g, kv3.a(), bVar.n);
        }
        List list3 = bVar.o;
        if (list3 == null) {
            bVar.o = Collections.EMPTY_LIST;
        } else {
            bVar.o = Collections.unmodifiableList(list3);
        }
        e.a aVar = bVar.b;
        aVar.getClass();
        a aVar2 = new a(applicationContext, bVar.c, bVar.f, bVar.d, bVar.e, new d18(), bVar.k, bVar.l, bVar.m, bVar.a, bVar.o, list, generatedAppGlideModule, new e(aVar));
        applicationContext.registerComponentCallbacks(aVar2);
        l = aVar2;
    }

    public static a18 f(Context context) {
        return c(context).c(context);
    }

    public static a18 g(View view) {
        d18 d18VarC = c(view.getContext());
        d18VarC.getClass();
        char[] cArr = hda.a;
        if (!(Looper.myLooper() == Looper.getMainLooper())) {
            return d18VarC.c(view.getContext().getApplicationContext());
        }
        gf7.c(view.getContext(), "Unable to obtain a request manager for a view without a Context");
        Activity activityA = d18.a(view.getContext());
        if (activityA != null && (activityA instanceof t)) {
            t tVar = (t) activityA;
            ts tsVar = d18VarC.c;
            tsVar.clear();
            d18.b(tVar.getSupportFragmentManager().ak(), tsVar);
            View viewFindViewById = tVar.findViewById(R.id.content);
            o oVar = null;
            while (!view.equals(viewFindViewById) && (oVar = (o) tsVar.get(view)) == null && (view.getParent() instanceof View)) {
                view = (View) view.getParent();
            }
            tsVar.clear();
            return oVar != null ? d18VarC.d(oVar) : d18VarC.e(tVar);
        }
        return d18VarC.c(view.getContext().getApplicationContext());
    }

    public static a18 h(o oVar) {
        return c(oVar.getContext()).d(oVar);
    }

    public final void a() {
        hda.a();
        this.c.b();
        this.b.b();
        this.e.b();
    }

    public final void e(int i) {
        hda.a();
        synchronized (this.j) {
            try {
                Iterator it = this.j.iterator();
                while (it.hasNext()) {
                    ((a18) it.next()).getClass();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        this.c.a(i);
        this.b.a(i);
        this.e.a(i);
    }

    @Override // android.content.ComponentCallbacks
    public final void onConfigurationChanged(Configuration configuration) {
    }

    @Override // android.content.ComponentCallbacks
    public final void onLowMemory() {
        a();
    }

    @Override // android.content.ComponentCallbacks2
    public final void onTrimMemory(int i) {
        e(i);
    }
}
