package defpackage;

import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import com.bumptech.glide.d;
import defpackage.fc1;
import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/* JADX INFO: loaded from: classes.dex */
public class a18 implements ComponentCallbacks2, g85, d86<l08<Drawable>> {
    public static final f18 m;
    public static final f18 n;
    public final com.bumptech.glide.a a;
    public final Context b;
    public final y75 c;
    public final g18 d;
    public final e18 e;
    public final rj9 f;
    public final Runnable i;
    public final fc1 j;
    public final CopyOnWriteArrayList k;
    public final f18 l;

    public class a implements Runnable {
        public a() {
        }

        @Override // java.lang.Runnable
        public final void run() {
            a18 a18Var = a18.this;
            a18Var.c.a(a18Var);
        }
    }

    public static class b extends op1<View, Object> {
        @Override // defpackage.nj9
        public final void d(Object obj, cu9 cu9Var) {
        }

        @Override // defpackage.nj9
        public final void i(Drawable drawable) {
        }
    }

    public class c implements fc1.a {
        public final g18 a;

        public c(g18 g18Var) {
            this.a = g18Var;
        }

        @Override // fc1.a
        public final void a(boolean z) {
            if (z) {
                synchronized (a18.this) {
                    g18 g18Var = this.a;
                    for (j08 j08Var : hda.e(g18Var.a)) {
                        if (!j08Var.d() && !j08Var.c()) {
                            j08Var.clear();
                            if (g18Var.c) {
                                g18Var.b.add(j08Var);
                            } else {
                                j08Var.j();
                            }
                        }
                    }
                }
            }
        }
    }

    static {
        f18 f18Var = (f18) new f18().d(Bitmap.class);
        f18Var.s = true;
        m = f18Var;
        f18 f18Var2 = (f18) new f18().d(su3.class);
        f18Var2.s = true;
        n = f18Var2;
    }

    public a18(com.bumptech.glide.a aVar, y75 y75Var, e18 e18Var, Context context) {
        f18 f18Var;
        g18 g18Var = new g18();
        gc1 gc1Var = aVar.i;
        this.f = new rj9();
        a aVar2 = new a();
        this.i = aVar2;
        this.a = aVar;
        this.c = y75Var;
        this.e = e18Var;
        this.d = g18Var;
        this.b = context;
        fc1 fc1VarA = gc1Var.a(context.getApplicationContext(), new c(g18Var));
        this.j = fc1VarA;
        synchronized (aVar.j) {
            if (aVar.j.contains(this)) {
                throw new IllegalStateException("Cannot register already registered manager");
            }
            aVar.j.add(this);
        }
        char[] cArr = hda.a;
        if (Looper.myLooper() == Looper.getMainLooper()) {
            y75Var.a(this);
        } else {
            hda.f().post(aVar2);
        }
        y75Var.a(fc1VarA);
        this.k = new CopyOnWriteArrayList(aVar.d.e);
        d dVar = aVar.d;
        synchronized (dVar) {
            try {
                if (dVar.j == null) {
                    f18 f18VarBuild = dVar.d.build();
                    f18VarBuild.s = true;
                    dVar.j = f18VarBuild;
                }
                f18Var = dVar.j;
            } finally {
            }
        }
        synchronized (this) {
            f18 f18Var2 = (f18) f18Var.clone();
            if (f18Var2.s && !f18Var2.u) {
                throw new IllegalStateException("You cannot auto lock an already locked options object, try clone() first");
            }
            f18Var2.u = true;
            f18Var2.s = true;
            this.l = f18Var2;
        }
    }

    public final l08 b(Class cls) {
        return new l08(this.a, this, cls, this.b);
    }

    public final void j(nj9 nj9Var) {
        if (nj9Var == null) {
            return;
        }
        boolean zQ = q(nj9Var);
        j08 j08VarE = nj9Var.e();
        if (zQ) {
            return;
        }
        com.bumptech.glide.a aVar = this.a;
        synchronized (aVar.j) {
            try {
                Iterator it = aVar.j.iterator();
                while (it.hasNext()) {
                    if (((a18) it.next()).q(nj9Var)) {
                        return;
                    }
                }
                if (j08VarE != null) {
                    nj9Var.h(null);
                    j08VarE.clear();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void k(View view) {
        j(new b(view));
    }

    public final synchronized void l() {
        try {
            Iterator it = hda.e(this.f.a).iterator();
            while (it.hasNext()) {
                j((nj9) it.next());
            }
            this.f.a.clear();
        } catch (Throwable th) {
            throw th;
        }
    }

    public final l08 m(Integer num) {
        PackageInfo packageInfo;
        l08 l08VarB = b(Drawable.class);
        l08 l08VarAj = l08VarB.aj(num);
        Context context = l08VarB.x;
        l08 l08Var = (l08) l08VarAj.v(context.getTheme());
        ConcurrentHashMap concurrentHashMap = gr.a;
        String packageName = context.getPackageName();
        ConcurrentHashMap concurrentHashMap2 = gr.a;
        v25 v25Var = (v25) concurrentHashMap2.get(packageName);
        if (v25Var == null) {
            try {
                packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            } catch (PackageManager.NameNotFoundException e) {
                Log.e("AppVersionSignature", "Cannot resolve info for" + context.getPackageName(), e);
                packageInfo = null;
            }
            ks6 ks6Var = new ks6(packageInfo != null ? String.valueOf(packageInfo.versionCode) : UUID.randomUUID().toString());
            v25 v25Var2 = (v25) concurrentHashMap2.putIfAbsent(packageName, ks6Var);
            v25Var = v25Var2 == null ? ks6Var : v25Var2;
        }
        return (l08) l08Var.s(new rj(context.getResources().getConfiguration().uiMode & 48, v25Var));
    }

    public final l08 n(String str) {
        return b(Drawable.class).aj(str);
    }

    public final synchronized void o() {
        g18 g18Var = this.d;
        g18Var.c = true;
        for (j08 j08Var : hda.e(g18Var.a)) {
            if (j08Var.isRunning()) {
                j08Var.pause();
                g18Var.b.add(j08Var);
            }
        }
    }

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

    @Override // defpackage.g85
    public final synchronized void onDestroy() {
        this.f.onDestroy();
        l();
        g18 g18Var = this.d;
        Iterator it = hda.e(g18Var.a).iterator();
        while (it.hasNext()) {
            g18Var.a((j08) it.next());
        }
        g18Var.b.clear();
        this.c.b(this);
        this.c.b(this.j);
        hda.f().removeCallbacks(this.i);
        com.bumptech.glide.a aVar = this.a;
        synchronized (aVar.j) {
            if (!aVar.j.contains(this)) {
                throw new IllegalStateException("Cannot unregister not yet registered manager");
            }
            aVar.j.remove(this);
        }
    }

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

    @Override // defpackage.g85
    public final synchronized void onStart() {
        p();
        this.f.onStart();
    }

    @Override // defpackage.g85
    public final synchronized void onStop() {
        this.f.onStop();
        o();
    }

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

    public final synchronized void p() {
        g18 g18Var = this.d;
        g18Var.c = false;
        for (j08 j08Var : hda.e(g18Var.a)) {
            if (!j08Var.d() && !j08Var.isRunning()) {
                j08Var.j();
            }
        }
        g18Var.b.clear();
    }

    public final synchronized boolean q(nj9 nj9Var) {
        j08 j08VarE = nj9Var.e();
        if (j08VarE == null) {
            return true;
        }
        if (!this.d.a(j08VarE)) {
            return false;
        }
        this.f.a.remove(nj9Var);
        nj9Var.h(null);
        return true;
    }

    public final synchronized String toString() {
        return super.toString() + "{tracker=" + this.d + ", treeNode=" + this.e + "}";
    }
}
