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.AbstractC0651;
import defpackage.AbstractComponentCallbacksC3393;
import defpackage.C0721;
import defpackage.C0764;
import defpackage.C1014;
import defpackage.C1563;
import defpackage.C1685;
import defpackage.C1883;
import defpackage.C3310;
import defpackage.C3580;
import defpackage.C3664;
import defpackage.C3777;
import defpackage.C3936;
import defpackage.C4347;
import defpackage.C4935;
import defpackage.C5151;
import defpackage.C5540;
import defpackage.ComponentCallbacks2C2427;
import defpackage.ExecutorServiceC2288;
import defpackage.InterfaceC5397;
import defpackage.ThreadFactoryC1207;
import defpackage.ThreadFactoryC1568;
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;

/* JADX INFO: renamed from: com.bumptech.glide.ᵲᵶᵳˈ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class ComponentCallbacks2C0017 implements ComponentCallbacks2 {

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public static volatile boolean f993;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public static volatile ComponentCallbacks2C0017 f994;

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public final ˉᵠﹳᵘ f995;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final C3580 f996;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public final ArrayList f997 = new ArrayList();

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final C3777 f998;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final InterfaceC5397 f999;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public final C1883 f1000;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public final C5540 f1001;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public final C0721 f1002;

    public ComponentCallbacks2C0017(Context context, C3580 c3580, C3777 c3777, InterfaceC5397 interfaceC5397, C5540 c5540, C0721 c0721, ˉᵠﹳᵘ r8, int i, ᵠʽᵲ r10, C3310 c3310, List list, List list2, ᵱˉˈ r14, C1014 c1014) {
        this.f996 = c3580;
        this.f999 = interfaceC5397;
        this.f1001 = c5540;
        this.f998 = c3777;
        this.f1002 = c0721;
        this.f995 = r8;
        if (((Map) c1014.f4404).get(ᵫﾞˌ.class) == null) {
            this.f1000 = new C1883(context, c5540, new C0764(this, list2, r14), new C3664(27), r10, c3310, list, c3580, c1014, i);
        } else {
            C1685.m4560();
            throw null;
        }
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static ComponentCallbacks2C0017 m801(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) {
                C4935.m10239("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) {
                C4935.m10239("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) {
                C4935.m10239("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) {
                C4935.m10239("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 {
                        m802(context, generatedAppGlideModule);
                        f993 = false;
                    } catch (Throwable th) {
                        f993 = false;
                        throw th;
                    }
                }
            }
        }
        return f994;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static void m802(Context context, GeneratedAppGlideModule generatedAppGlideModule) {
        List list;
        C3310 c3310 = new C3310(0);
        int i = 1;
        C1563 c1563 = new C1563(1);
        ᵠʽᵲ 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.ᵲᵶᵳˈ();
        }
        ThreadFactoryC1568 threadFactoryC1568 = new ThreadFactoryC1568(i);
        if (ExecutorServiceC2288.f8998 == 0) {
            ExecutorServiceC2288.f8998 = Math.min(4, Runtime.getRuntime().availableProcessors());
        }
        int i2 = ExecutorServiceC2288.f8998;
        if (TextUtils.isEmpty("source")) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("Name must be non-null and non-empty, but given: source");
            return;
        }
        ExecutorServiceC2288 executorServiceC2288 = new ExecutorServiceC2288(new ThreadPoolExecutor(i2, i2, 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new ThreadFactoryC1207(threadFactoryC1568, "source", false)));
        ThreadFactoryC1568 threadFactoryC15682 = new ThreadFactoryC1568(i);
        if (TextUtils.isEmpty("disk-cache")) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("Name must be non-null and non-empty, but given: disk-cache");
            return;
        }
        ExecutorServiceC2288 executorServiceC22882 = new ExecutorServiceC2288(new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new ThreadFactoryC1207(threadFactoryC15682, "disk-cache", true)));
        if (ExecutorServiceC2288.f8998 == 0) {
            ExecutorServiceC2288.f8998 = Math.min(4, Runtime.getRuntime().availableProcessors());
        }
        int i3 = ExecutorServiceC2288.f8998 >= 4 ? 2 : 1;
        ThreadFactoryC1568 threadFactoryC15683 = new ThreadFactoryC1568(i);
        if (TextUtils.isEmpty("animation")) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("Name must be non-null and non-empty, but given: animation");
            return;
        }
        ExecutorServiceC2288 executorServiceC22883 = new ExecutorServiceC2288(new ThreadPoolExecutor(i3, i3, 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue(), new ThreadFactoryC1207(threadFactoryC15683, "animation", true)));
        C4347 c4347 = new C4347(applicationContext);
        C5151 c5151 = new C5151();
        Context context2 = c4347.f16536;
        float f = c4347.f16537;
        ActivityManager activityManager = c4347.f16534;
        int i4 = activityManager.isLowRamDevice() ? 2097152 : 4194304;
        c5151.f19365 = i4;
        int iRound = Math.round(activityManager.getMemoryClass() * 1048576 * (activityManager.isLowRamDevice() ? 0.33f : 0.4f));
        DisplayMetrics displayMetrics = (DisplayMetrics) c4347.f16535.ᵜᵪʾ;
        float f2 = displayMetrics.widthPixels * displayMetrics.heightPixels * 4;
        int iRound2 = Math.round(f2 * f);
        int iRound3 = Math.round(f2 * 2.0f);
        int i5 = iRound - i4;
        if (iRound3 + iRound2 <= i5) {
            c5151.f19364 = iRound3;
            c5151.f19366 = iRound2;
        } else {
            float f3 = i5 / (f + 2.0f);
            c5151.f19364 = Math.round(2.0f * f3);
            c5151.f19366 = Math.round(f3 * f);
        }
        if (Log.isLoggable("MemorySizeCalculator", 3)) {
            Formatter.formatFileSize(context2, c5151.f19364);
            Formatter.formatFileSize(context2, c5151.f19366);
            Formatter.formatFileSize(context2, i4);
            Formatter.formatFileSize(context2, iRound);
            activityManager.getMemoryClass();
            activityManager.isLowRamDevice();
        }
        int i6 = 1;
        ˉᵠﹳᵘ r7 = new ˉᵠﹳᵘ(17);
        int i7 = c5151.f19366;
        InterfaceC5397 c3936 = i7 > 0 ? new C3936(i7) : new C3664(12);
        C5540 c5540 = new C5540(c5151.f19365);
        C3777 c3777 = new C3777(c5151.f19364);
        C3580 c3580 = new C3580(c3777, new ᵧᵙᵤ(applicationContext), executorServiceC22882, executorServiceC2288, new ExecutorServiceC2288(new ThreadPoolExecutor(0, Integer.MAX_VALUE, 10000L, TimeUnit.MILLISECONDS, new SynchronousQueue(), new ThreadFactoryC1207(new ThreadFactoryC1568(i6), "source-unlimited", false))), executorServiceC22883);
        List list3 = Collections.EMPTY_LIST;
        C1014 c1014 = new C1014();
        c1014.f4404 = DesugarCollections.unmodifiableMap(new HashMap(c1563.f6260));
        ComponentCallbacks2C0017 componentCallbacks2C0017 = new ComponentCallbacks2C0017(applicationContext, c3580, c3777, c3936, c5540, new C0721(), r7, 4, r9, c3310, list3, list, generatedAppGlideModule, c1014);
        applicationContext.registerComponentCallbacks(componentCallbacks2C0017);
        f994 = componentCallbacks2C0017;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static ComponentCallbacks2C2427 m803(AbstractComponentCallbacksC3393 abstractComponentCallbacksC3393) {
        Context contextMo2403 = abstractComponentCallbacksC3393.mo2403();
        ᵿᵽᵤ.ːˏᵟᵯ(contextMo2403, "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).");
        C0721 c0721 = m801(contextMo2403).f1002;
        c0721.getClass();
        ᵿᵽᵤ.ːˏᵟᵯ(abstractComponentCallbacksC3393.mo2403(), "You cannot start a load on a fragment before it is attached or after it is destroyed");
        if (!(Looper.myLooper() == Looper.getMainLooper())) {
            return c0721.m2578(abstractComponentCallbacksC3393.mo2403().getApplicationContext());
        }
        if (abstractComponentCallbacksC3393.m7767() != null) {
            c0721.f3276.mo1351(abstractComponentCallbacksC3393.m7767());
        }
        AbstractC0651 abstractC0651M7773 = abstractComponentCallbacksC3393.m7773();
        Context contextMo24032 = abstractComponentCallbacksC3393.mo2403();
        return c0721.f3275.m8375(contextMo24032, m801(contextMo24032.getApplicationContext()), abstractComponentCallbacksC3393.f13058, abstractC0651M7773, abstractComponentCallbacksC3393.m7789());
    }

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

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

    @Override // android.content.ComponentCallbacks2
    public final void onTrimMemory(int i) {
        ᵱˉˈ.ʽˈˋ();
        synchronized (this.f997) {
            try {
                ArrayList arrayList = this.f997;
                int size = arrayList.size();
                int i2 = 0;
                while (i2 < size) {
                    Object obj = arrayList.get(i2);
                    i2++;
                    ((ComponentCallbacks2C2427) obj).getClass();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        this.f998.m8452(i);
        this.f999.mo8261(i);
        this.f1001.m11167(i);
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void m804() {
        ᵱˉˈ.ʽˈˋ();
        this.f998.m10361(0L);
        this.f999.mo8260();
        this.f1001.m11163();
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final void m805(ComponentCallbacks2C2427 componentCallbacks2C2427) {
        synchronized (this.f997) {
            try {
                if (!this.f997.contains(componentCallbacks2C2427)) {
                    throw new IllegalStateException("Cannot unregister not yet registered manager");
                }
                this.f997.remove(componentCallbacks2C2427);
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
