package com.bumptech.glide;

import android.app.ActivityManager;
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.text.TextUtils;
import android.text.format.Formatter;
import android.util.DisplayMetrics;
import android.util.Log;
import com.bumptech.glide.integration.okhttp3.OkHttpGlideModule;
import defpackage.AbstractC4731;
import defpackage.AbstractComponentCallbacksC3693;
import defpackage.C0519;
import defpackage.C0520;
import defpackage.C0910;
import defpackage.C1200;
import defpackage.C1260;
import defpackage.C2611;
import defpackage.C3480;
import defpackage.C3652;
import defpackage.C3718;
import defpackage.C3889;
import defpackage.C4011;
import defpackage.C4524;
import defpackage.C4699;
import defpackage.C4805;
import defpackage.ComponentCallbacks2C3445;
import defpackage.ExecutorServiceC4470;
import defpackage.InterfaceC2157;
import defpackage.ThreadFactoryC1465;
import defpackage.ThreadFactoryC5506;
import j$.util.DesugarCollections;
import j$.util.Objects;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/* renamed from: com.bumptech.glide.ᵥᵯˎ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class ComponentCallbacks2C0017 implements ComponentCallbacks2 {

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public static volatile boolean f993;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public static volatile ComponentCallbacks2C0017 f994;

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public final ʾᵚᵱ f995;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final ArrayList f996 = new ArrayList();

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final C0519 f997;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final InterfaceC2157 f998;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final C4805 f999;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final C3652 f1000;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final C0520 f1001;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final C4524 f1002;

    public ComponentCallbacks2C0017(Context context, C3652 c3652, C4524 c4524, InterfaceC2157 interfaceC2157, C4805 c4805, C0519 c0519, ʾᵚᵱ r8, int i, ᵥᵵ r10, C1200 c1200, List list, List list2, ˊˉʤﹳ r14, C3718 c3718) {
        this.f1000 = c3652;
        this.f998 = interfaceC2157;
        this.f999 = c4805;
        this.f1002 = c4524;
        this.f997 = c0519;
        this.f995 = r8;
        if (((Map) c3718.f13883).get(ˋˌ.class) == null) {
            this.f1001 = new C0520(context, c4805, new C4699(this, list2, r14), new ˊᵻ(27), r10, c1200, list, c3652, c3718, i);
        } else {
            C0910.m3050();
            throw null;
        }
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public static ComponentCallbacks2C3445 m800(AbstractComponentCallbacksC3693 abstractComponentCallbacksC3693) {
        Context contextMo4691 = abstractComponentCallbacksC3693.mo4691();
        ᵼᵙᵖᵱ.ˏˋٴ(contextMo4691, "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).");
        C0519 c0519 = m802(contextMo4691).f997;
        c0519.getClass();
        ᵼᵙᵖᵱ.ˏˋٴ(abstractComponentCallbacksC3693.mo4691(), "You cannot start a load on a fragment before it is attached or after it is destroyed");
        if (!(Looper.myLooper() == Looper.getMainLooper())) {
            return c0519.m2231(abstractComponentCallbacksC3693.mo4691().getApplicationContext());
        }
        if (abstractComponentCallbacksC3693.m8294() != null) {
            c0519.f2687.mo4475(abstractComponentCallbacksC3693.m8294());
        }
        AbstractC4731 abstractC4731M8298 = abstractComponentCallbacksC3693.m8298();
        Context contextMo46912 = abstractComponentCallbacksC3693.mo4691();
        return c0519.f2689.ᵧᵾˀˈ(contextMo46912, m802(contextMo46912.getApplicationContext()), abstractComponentCallbacksC3693.f13781, abstractC4731M8298, abstractComponentCallbacksC3693.m8287());
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public static void m801(Context context, GeneratedAppGlideModule generatedAppGlideModule) throws PackageManager.NameNotFoundException {
        List list;
        ExecutorServiceC4470 executorServiceC4470;
        C1200 c1200 = new C1200(0);
        C3480 c3480 = new C3480(2);
        ᵥᵵ r9 = new ᵥᵵ(27);
        Context applicationContext = context.getApplicationContext();
        List list2 = Collections.EMPTY_LIST;
        if (generatedAppGlideModule == null || !(generatedAppGlideModule instanceof GeneratedAppGlideModuleImpl)) {
            Log.isLoggable("ManifestParser", 3);
            ArrayList arrayList = new ArrayList();
            try {
                ApplicationInfo applicationInfo = applicationContext.getPackageManager().getApplicationInfo(applicationContext.getPackageName(), 128);
                if (applicationInfo == null || applicationInfo.metaData == null) {
                    Log.isLoggable("ManifestParser", 3);
                } else {
                    if (Log.isLoggable("ManifestParser", 2)) {
                        Objects.toString(applicationInfo.metaData);
                    }
                    for (String str : applicationInfo.metaData.keySet()) {
                        if ("GlideModule".equals(applicationInfo.metaData.get(str))) {
                            arrayList.add(ᵯᵽᵦ.ᐧﾞ(str));
                            Log.isLoggable("ManifestParser", 3);
                        }
                    }
                    Log.isLoggable("ManifestParser", 3);
                }
            } catch (PackageManager.NameNotFoundException unused) {
                Log.isLoggable("ManifestParser", 6);
            }
            list = arrayList;
        } else {
            list = list2;
        }
        if (generatedAppGlideModule != null && !new HashSet().isEmpty()) {
            HashSet hashSet = new HashSet();
            Iterator it = list.iterator();
            while (it.hasNext()) {
                OkHttpGlideModule okHttpGlideModule = (OkHttpGlideModule) it.next();
                if (hashSet.contains(okHttpGlideModule.getClass())) {
                    if (Log.isLoggable("Glide", 3)) {
                        okHttpGlideModule.toString();
                    }
                    it.remove();
                }
            }
        }
        if (Log.isLoggable("Glide", 3)) {
            Iterator it2 = list.iterator();
            while (it2.hasNext()) {
                ((OkHttpGlideModule) it2.next()).getClass().toString();
            }
        }
        Iterator it3 = list.iterator();
        while (it3.hasNext()) {
            ((OkHttpGlideModule) it3.next()).getClass();
        }
        if (generatedAppGlideModule != null) {
            generatedAppGlideModule.ᵥᵯˎ();
        }
        ThreadFactoryC5506 threadFactoryC5506 = new ThreadFactoryC5506(1);
        if (ExecutorServiceC4470.f16682 == 0) {
            ExecutorServiceC4470.f16682 = Math.min(4, Runtime.getRuntime().availableProcessors());
        }
        int i = ExecutorServiceC4470.f16682;
        if (TextUtils.isEmpty("source")) {
            ᵹˉᵞ.ˌᵜᵹᵩ("Name must be non-null and non-empty, but given: source");
            return;
        }
        ExecutorServiceC4470 executorServiceC44702 = new ExecutorServiceC4470(new ThreadPoolExecutor(i, i, 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new ThreadFactoryC1465(threadFactoryC5506, "source", false)));
        ThreadFactoryC5506 threadFactoryC55062 = new ThreadFactoryC5506(1);
        if (TextUtils.isEmpty("disk-cache")) {
            ᵹˉᵞ.ˌᵜᵹᵩ("Name must be non-null and non-empty, but given: disk-cache");
            return;
        }
        ExecutorServiceC4470 executorServiceC44703 = new ExecutorServiceC4470(new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new ThreadFactoryC1465(threadFactoryC55062, "disk-cache", true)));
        if (ExecutorServiceC4470.f16682 == 0) {
            ExecutorServiceC4470.f16682 = Math.min(4, Runtime.getRuntime().availableProcessors());
        }
        int i2 = ExecutorServiceC4470.f16682 >= 4 ? 2 : 1;
        ThreadFactoryC5506 threadFactoryC55063 = new ThreadFactoryC5506(1);
        if (TextUtils.isEmpty("animation")) {
            ᵹˉᵞ.ˌᵜᵹᵩ("Name must be non-null and non-empty, but given: animation");
            return;
        }
        ExecutorServiceC4470 executorServiceC44704 = new ExecutorServiceC4470(new ThreadPoolExecutor(i2, i2, 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new ThreadFactoryC1465(threadFactoryC55063, "animation", true)));
        C4011 c4011 = new C4011(applicationContext);
        C3889 c3889 = new C3889();
        Context context2 = c4011.f15082;
        float f = c4011.f15084;
        ActivityManager activityManager = c4011.f15083;
        int i3 = activityManager.isLowRamDevice() ? 2097152 : 4194304;
        c3889.f14496 = i3;
        int iRound = Math.round(activityManager.getMemoryClass() * 1048576 * (activityManager.isLowRamDevice() ? 0.33f : 0.4f));
        DisplayMetrics displayMetrics = (DisplayMetrics) c4011.f15081.ᵢˇᵭ;
        float f2 = displayMetrics.widthPixels * displayMetrics.heightPixels * 4;
        int iRound2 = Math.round(f2 * f);
        int iRound3 = Math.round(f2 * 2.0f);
        int i4 = iRound - i3;
        if (iRound3 + iRound2 <= i4) {
            c3889.f14498 = iRound3;
            c3889.f14497 = iRound2;
        } else {
            float f3 = i4 / (f + 2.0f);
            c3889.f14498 = Math.round(2.0f * f3);
            c3889.f14497 = Math.round(f3 * f);
        }
        if (Log.isLoggable("MemorySizeCalculator", 3)) {
            executorServiceC4470 = executorServiceC44703;
            Formatter.formatFileSize(context2, c3889.f14498);
            Formatter.formatFileSize(context2, c3889.f14497);
            Formatter.formatFileSize(context2, i3);
            Formatter.formatFileSize(context2, iRound);
            activityManager.getMemoryClass();
            activityManager.isLowRamDevice();
        } else {
            executorServiceC4470 = executorServiceC44703;
        }
        ʾᵚᵱ r7 = new ʾᵚᵱ(17);
        int i5 = c3889.f14497;
        C2611 c2611 = i5 > 0 ? new C2611(i5) : new ˊᵻ(12);
        C4805 c4805 = new C4805(c3889.f14496);
        C4524 c4524 = new C4524(c3889.f14498);
        C3652 c3652 = new C3652(c4524, new ˑᵽʾʦ(applicationContext), executorServiceC4470, executorServiceC44702, new ExecutorServiceC4470(new ThreadPoolExecutor(0, Integer.MAX_VALUE, 10000L, TimeUnit.MILLISECONDS, new SynchronousQueue(), new ThreadFactoryC1465(new ThreadFactoryC5506(1), "source-unlimited", false))), executorServiceC44704);
        List list3 = Collections.EMPTY_LIST;
        C3718 c3718 = new C3718();
        c3718.f13883 = DesugarCollections.unmodifiableMap(new HashMap(c3480.f13034));
        ComponentCallbacks2C0017 componentCallbacks2C0017 = new ComponentCallbacks2C0017(applicationContext, c3652, c4524, c2611, c4805, new C0519(), r7, 4, r9, c1200, list3, list, generatedAppGlideModule, c3718);
        applicationContext.registerComponentCallbacks(componentCallbacks2C0017);
        f994 = componentCallbacks2C0017;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public static ComponentCallbacks2C0017 m802(Context context) {
        if (f994 == null) {
            GeneratedAppGlideModule generatedAppGlideModule = null;
            try {
                generatedAppGlideModule = (GeneratedAppGlideModule) GeneratedAppGlideModuleImpl.class.getDeclaredConstructor(Context.class).newInstance(context.getApplicationContext().getApplicationContext());
            } catch (ClassNotFoundException unused) {
                Log.isLoggable("Glide", 5);
            } catch (IllegalAccessException e) {
                C1260.m3810("GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.", e);
                return null;
            } catch (InstantiationException e2) {
                C1260.m3810("GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.", e2);
                return null;
            } catch (NoSuchMethodException e3) {
                C1260.m3810("GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.", e3);
                return null;
            } catch (InvocationTargetException e4) {
                C1260.m3810("GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.", e4);
                return null;
            }
            synchronized (ComponentCallbacks2C0017.class) {
                if (f994 == null) {
                    if (f993) {
                        throw new IllegalStateException("Glide has been called recursively, this is probably an internal library error!");
                    }
                    f993 = true;
                    try {
                        m801(context, generatedAppGlideModule);
                        f993 = false;
                    } catch (Throwable th) {
                        f993 = false;
                        throw th;
                    }
                }
            }
        }
        return f994;
    }

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

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

    @Override // android.content.ComponentCallbacks2
    public final void onTrimMemory(int i) {
        ˊˉʤﹳ.ᵴᵳ();
        synchronized (this.f996) {
            try {
                ArrayList arrayList = this.f996;
                int size = arrayList.size();
                int i2 = 0;
                while (i2 < size) {
                    Object obj = arrayList.get(i2);
                    i2++;
                    ((ComponentCallbacks2C3445) obj).getClass();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        this.f1002.m9618(i);
        this.f998.mo5789(i);
        this.f999.m10126(i);
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m803() {
        ˊˉʤﹳ.ᵴᵳ();
        this.f1002.m3828(0L);
        this.f998.mo5787();
        this.f999.m10125();
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final void m804(ComponentCallbacks2C3445 componentCallbacks2C3445) {
        synchronized (this.f996) {
            try {
                if (!this.f996.contains(componentCallbacks2C3445)) {
                    throw new IllegalStateException("Cannot unregister not yet registered manager");
                }
                this.f996.remove(componentCallbacks2C3445);
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
