package com.bumptech.glide.request;

import com.bumptech.glide.request.d;

/* loaded from: classes4.dex */
public final class b implements d, c {

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

    /* renamed from: b, reason: collision with root package name */
    private final d f12618b;

    /* renamed from: c, reason: collision with root package name */
    private volatile c f12619c;

    /* renamed from: d, reason: collision with root package name */
    private volatile c f12620d;

    /* renamed from: e, reason: collision with root package name */
    private d.a f12621e;

    /* renamed from: f, reason: collision with root package name */
    private d.a f12622f;

    public b(Object obj, d dVar) {
        d.a aVar = d.a.CLEARED;
        this.f12621e = aVar;
        this.f12622f = aVar;
        this.f12617a = obj;
        this.f12618b = dVar;
    }

    private boolean k(c cVar) {
        d.a aVar;
        d.a aVar2 = this.f12621e;
        d.a aVar3 = d.a.FAILED;
        return aVar2 != aVar3 ? cVar.equals(this.f12619c) : cVar.equals(this.f12620d) && ((aVar = this.f12622f) == d.a.SUCCESS || aVar == aVar3);
    }

    private boolean l() {
        d dVar = this.f12618b;
        return dVar == null || dVar.j(this);
    }

    private boolean m() {
        d dVar = this.f12618b;
        return dVar == null || dVar.c(this);
    }

    private boolean n() {
        d dVar = this.f12618b;
        return dVar == null || dVar.e(this);
    }

    @Override // com.bumptech.glide.request.d
    public void a(c cVar) {
        synchronized (this.f12617a) {
            if (cVar.equals(this.f12620d)) {
                this.f12622f = d.a.FAILED;
                d dVar = this.f12618b;
                if (dVar != null) {
                    dVar.a(this);
                }
                return;
            }
            this.f12621e = d.a.FAILED;
            d.a aVar = this.f12622f;
            d.a aVar2 = d.a.RUNNING;
            if (aVar != aVar2) {
                this.f12622f = aVar2;
                this.f12620d.h();
            }
        }
    }

    @Override // com.bumptech.glide.request.d, com.bumptech.glide.request.c
    public boolean b() {
        boolean z10;
        synchronized (this.f12617a) {
            z10 = this.f12619c.b() || this.f12620d.b();
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.d
    public boolean c(c cVar) {
        boolean z10;
        synchronized (this.f12617a) {
            z10 = m() && k(cVar);
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.c
    public void clear() {
        synchronized (this.f12617a) {
            d.a aVar = d.a.CLEARED;
            this.f12621e = aVar;
            this.f12619c.clear();
            if (this.f12622f != aVar) {
                this.f12622f = aVar;
                this.f12620d.clear();
            }
        }
    }

    @Override // com.bumptech.glide.request.c
    public boolean d(c cVar) {
        if (!(cVar instanceof b)) {
            return false;
        }
        b bVar = (b) cVar;
        return this.f12619c.d(bVar.f12619c) && this.f12620d.d(bVar.f12620d);
    }

    @Override // com.bumptech.glide.request.d
    public boolean e(c cVar) {
        boolean n10;
        synchronized (this.f12617a) {
            n10 = n();
        }
        return n10;
    }

    @Override // com.bumptech.glide.request.c
    public boolean f() {
        boolean z10;
        synchronized (this.f12617a) {
            d.a aVar = this.f12621e;
            d.a aVar2 = d.a.CLEARED;
            z10 = aVar == aVar2 && this.f12622f == aVar2;
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.d
    public void g(c cVar) {
        synchronized (this.f12617a) {
            if (cVar.equals(this.f12619c)) {
                this.f12621e = d.a.SUCCESS;
            } else if (cVar.equals(this.f12620d)) {
                this.f12622f = d.a.SUCCESS;
            }
            d dVar = this.f12618b;
            if (dVar != null) {
                dVar.g(this);
            }
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r2v2, types: [com.bumptech.glide.request.d] */
    /* JADX WARN: Type inference failed for: r2v4 */
    /* JADX WARN: Type inference failed for: r2v5 */
    @Override // com.bumptech.glide.request.d
    public d getRoot() {
        ?? r22;
        synchronized (this.f12617a) {
            d dVar = this.f12618b;
            this = this;
            if (dVar != null) {
                r22 = dVar.getRoot();
            }
        }
        return r22;
    }

    @Override // com.bumptech.glide.request.c
    public void h() {
        synchronized (this.f12617a) {
            d.a aVar = this.f12621e;
            d.a aVar2 = d.a.RUNNING;
            if (aVar != aVar2) {
                this.f12621e = aVar2;
                this.f12619c.h();
            }
        }
    }

    @Override // com.bumptech.glide.request.c
    public boolean i() {
        boolean z10;
        synchronized (this.f12617a) {
            d.a aVar = this.f12621e;
            d.a aVar2 = d.a.SUCCESS;
            z10 = aVar == aVar2 || this.f12622f == aVar2;
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.c
    public boolean isRunning() {
        boolean z10;
        synchronized (this.f12617a) {
            d.a aVar = this.f12621e;
            d.a aVar2 = d.a.RUNNING;
            z10 = aVar == aVar2 || this.f12622f == aVar2;
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.d
    public boolean j(c cVar) {
        boolean z10;
        synchronized (this.f12617a) {
            z10 = l() && cVar.equals(this.f12619c);
        }
        return z10;
    }

    public void o(c cVar, c cVar2) {
        this.f12619c = cVar;
        this.f12620d = cVar2;
    }

    @Override // com.bumptech.glide.request.c
    public void pause() {
        synchronized (this.f12617a) {
            d.a aVar = this.f12621e;
            d.a aVar2 = d.a.RUNNING;
            if (aVar == aVar2) {
                this.f12621e = d.a.PAUSED;
                this.f12619c.pause();
            }
            if (this.f12622f == aVar2) {
                this.f12622f = d.a.PAUSED;
                this.f12620d.pause();
            }
        }
    }
}
