package com.bumptech.glide;

import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import yh.c;
import yh.n;
import yh.s;
import yh.t;
import yh.w;

/* loaded from: classes4.dex */
public class l implements ComponentCallbacks2, n {
    private static final com.bumptech.glide.request.f A = (com.bumptech.glide.request.f) com.bumptech.glide.request.f.m0(Bitmap.class).P();
    private static final com.bumptech.glide.request.f B = (com.bumptech.glide.request.f) com.bumptech.glide.request.f.m0(wh.c.class).P();
    private static final com.bumptech.glide.request.f C = (com.bumptech.glide.request.f) ((com.bumptech.glide.request.f) com.bumptech.glide.request.f.n0(lh.j.f28170c).Y(g.LOW)).g0(true);

    /* renamed from: p, reason: collision with root package name */
    protected final com.bumptech.glide.b f12550p;

    /* renamed from: q, reason: collision with root package name */
    protected final Context f12551q;

    /* renamed from: r, reason: collision with root package name */
    final yh.l f12552r;

    /* renamed from: s, reason: collision with root package name */
    private final t f12553s;

    /* renamed from: t, reason: collision with root package name */
    private final s f12554t;

    /* renamed from: u, reason: collision with root package name */
    private final w f12555u;

    /* renamed from: v, reason: collision with root package name */
    private final Runnable f12556v;

    /* renamed from: w, reason: collision with root package name */
    private final yh.c f12557w;

    /* renamed from: x, reason: collision with root package name */
    private final CopyOnWriteArrayList f12558x;

    /* renamed from: y, reason: collision with root package name */
    private com.bumptech.glide.request.f f12559y;

    /* renamed from: z, reason: collision with root package name */
    private boolean f12560z;

    /* loaded from: classes4.dex */
    class a implements Runnable {
        a() {
        }

        @Override // java.lang.Runnable
        public void run() {
            l lVar = l.this;
            lVar.f12552r.a(lVar);
        }
    }

    /* loaded from: classes4.dex */
    private class b implements c.a {

        /* renamed from: a, reason: collision with root package name */
        private final t f12562a;

        b(t tVar) {
            this.f12562a = tVar;
        }

        @Override // yh.c.a
        public void a(boolean z10) {
            if (z10) {
                synchronized (l.this) {
                    this.f12562a.e();
                }
            }
        }
    }

    public l(com.bumptech.glide.b bVar, yh.l lVar, s sVar, Context context) {
        this(bVar, lVar, sVar, new t(), bVar.g(), context);
    }

    private void x(bi.h hVar) {
        boolean w10 = w(hVar);
        com.bumptech.glide.request.c f10 = hVar.f();
        if (w10 || this.f12550p.p(hVar) || f10 == null) {
            return;
        }
        hVar.b(null);
        f10.clear();
    }

    public k i(Class cls) {
        return new k(this.f12550p, this, cls, this.f12551q);
    }

    public k j() {
        return i(Bitmap.class).a(A);
    }

    public k k() {
        return i(Drawable.class);
    }

    public void l(bi.h hVar) {
        if (hVar == null) {
            return;
        }
        x(hVar);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public List m() {
        return this.f12558x;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public synchronized com.bumptech.glide.request.f n() {
        return this.f12559y;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public m o(Class cls) {
        return this.f12550p.i().e(cls);
    }

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

    @Override // yh.n
    public synchronized void onDestroy() {
        this.f12555u.onDestroy();
        Iterator it = this.f12555u.j().iterator();
        while (it.hasNext()) {
            l((bi.h) it.next());
        }
        this.f12555u.i();
        this.f12553s.b();
        this.f12552r.b(this);
        this.f12552r.b(this.f12557w);
        ei.l.u(this.f12556v);
        this.f12550p.s(this);
    }

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

    @Override // yh.n
    public synchronized void onStart() {
        t();
        this.f12555u.onStart();
    }

    @Override // yh.n
    public synchronized void onStop() {
        s();
        this.f12555u.onStop();
    }

    @Override // android.content.ComponentCallbacks2
    public void onTrimMemory(int i10) {
        if (i10 == 60 && this.f12560z) {
            r();
        }
    }

    public k p(String str) {
        return k().C0(str);
    }

    public synchronized void q() {
        this.f12553s.c();
    }

    public synchronized void r() {
        q();
        Iterator it = this.f12554t.a().iterator();
        while (it.hasNext()) {
            ((l) it.next()).q();
        }
    }

    public synchronized void s() {
        this.f12553s.d();
    }

    public synchronized void t() {
        this.f12553s.f();
    }

    public synchronized String toString() {
        return super.toString() + "{tracker=" + this.f12553s + ", treeNode=" + this.f12554t + "}";
    }

    protected synchronized void u(com.bumptech.glide.request.f fVar) {
        this.f12559y = (com.bumptech.glide.request.f) ((com.bumptech.glide.request.f) fVar.clone()).b();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public synchronized void v(bi.h hVar, com.bumptech.glide.request.c cVar) {
        this.f12555u.k(hVar);
        this.f12553s.g(cVar);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public synchronized boolean w(bi.h hVar) {
        com.bumptech.glide.request.c f10 = hVar.f();
        if (f10 == null) {
            return true;
        }
        if (!this.f12553s.a(f10)) {
            return false;
        }
        this.f12555u.l(hVar);
        hVar.b(null);
        return true;
    }

    l(com.bumptech.glide.b bVar, yh.l lVar, s sVar, t tVar, yh.d dVar, Context context) {
        this.f12555u = new w();
        a aVar = new a();
        this.f12556v = aVar;
        this.f12550p = bVar;
        this.f12552r = lVar;
        this.f12554t = sVar;
        this.f12553s = tVar;
        this.f12551q = context;
        yh.c a10 = dVar.a(context.getApplicationContext(), new b(tVar));
        this.f12557w = a10;
        bVar.o(this);
        if (ei.l.p()) {
            ei.l.t(aVar);
        } else {
            lVar.a(this);
        }
        lVar.a(a10);
        this.f12558x = new CopyOnWriteArrayList(bVar.i().c());
        u(bVar.i().d());
    }
}
