package com.bumptech.glide.request;

import com.bumptech.glide.request.d;

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

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

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

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

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

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

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

    /* renamed from: g, reason: collision with root package name */
    private boolean f12655g;

    public i(Object obj, d dVar) {
        d.a aVar = d.a.CLEARED;
        this.f12653e = aVar;
        this.f12654f = aVar;
        this.f12650b = obj;
        this.f12649a = dVar;
    }

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

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

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

    @Override // com.bumptech.glide.request.d
    public void a(c cVar) {
        synchronized (this.f12650b) {
            if (!cVar.equals(this.f12651c)) {
                this.f12654f = d.a.FAILED;
                return;
            }
            this.f12653e = d.a.FAILED;
            d dVar = this.f12649a;
            if (dVar != null) {
                dVar.a(this);
            }
        }
    }

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

    @Override // com.bumptech.glide.request.d
    public boolean c(c cVar) {
        boolean z10;
        synchronized (this.f12650b) {
            z10 = l() && cVar.equals(this.f12651c) && !b();
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.c
    public void clear() {
        synchronized (this.f12650b) {
            this.f12655g = false;
            d.a aVar = d.a.CLEARED;
            this.f12653e = aVar;
            this.f12654f = aVar;
            this.f12652d.clear();
            this.f12651c.clear();
        }
    }

    @Override // com.bumptech.glide.request.c
    public boolean d(c cVar) {
        if (!(cVar instanceof i)) {
            return false;
        }
        i iVar = (i) cVar;
        if (this.f12651c == null) {
            if (iVar.f12651c != null) {
                return false;
            }
        } else if (!this.f12651c.d(iVar.f12651c)) {
            return false;
        }
        if (this.f12652d == null) {
            if (iVar.f12652d != null) {
                return false;
            }
        } else if (!this.f12652d.d(iVar.f12652d)) {
            return false;
        }
        return true;
    }

    @Override // com.bumptech.glide.request.d
    public boolean e(c cVar) {
        boolean z10;
        synchronized (this.f12650b) {
            z10 = m() && (cVar.equals(this.f12651c) || this.f12653e != d.a.SUCCESS);
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.c
    public boolean f() {
        boolean z10;
        synchronized (this.f12650b) {
            z10 = this.f12653e == d.a.CLEARED;
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.d
    public void g(c cVar) {
        synchronized (this.f12650b) {
            if (cVar.equals(this.f12652d)) {
                this.f12654f = d.a.SUCCESS;
                return;
            }
            this.f12653e = d.a.SUCCESS;
            d dVar = this.f12649a;
            if (dVar != null) {
                dVar.g(this);
            }
            if (!this.f12654f.isComplete()) {
                this.f12652d.clear();
            }
        }
    }

    /* 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.f12650b) {
            d dVar = this.f12649a;
            this = this;
            if (dVar != null) {
                r22 = dVar.getRoot();
            }
        }
        return r22;
    }

    @Override // com.bumptech.glide.request.c
    public void h() {
        synchronized (this.f12650b) {
            this.f12655g = true;
            try {
                if (this.f12653e != d.a.SUCCESS) {
                    d.a aVar = this.f12654f;
                    d.a aVar2 = d.a.RUNNING;
                    if (aVar != aVar2) {
                        this.f12654f = aVar2;
                        this.f12652d.h();
                    }
                }
                if (this.f12655g) {
                    d.a aVar3 = this.f12653e;
                    d.a aVar4 = d.a.RUNNING;
                    if (aVar3 != aVar4) {
                        this.f12653e = aVar4;
                        this.f12651c.h();
                    }
                }
            } finally {
                this.f12655g = false;
            }
        }
    }

    @Override // com.bumptech.glide.request.c
    public boolean i() {
        boolean z10;
        synchronized (this.f12650b) {
            z10 = this.f12653e == d.a.SUCCESS;
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.c
    public boolean isRunning() {
        boolean z10;
        synchronized (this.f12650b) {
            z10 = this.f12653e == d.a.RUNNING;
        }
        return z10;
    }

    @Override // com.bumptech.glide.request.d
    public boolean j(c cVar) {
        boolean z10;
        synchronized (this.f12650b) {
            z10 = k() && cVar.equals(this.f12651c) && this.f12653e != d.a.PAUSED;
        }
        return z10;
    }

    public void n(c cVar, c cVar2) {
        this.f12651c = cVar;
        this.f12652d = cVar2;
    }

    @Override // com.bumptech.glide.request.c
    public void pause() {
        synchronized (this.f12650b) {
            if (!this.f12654f.isComplete()) {
                this.f12654f = d.a.PAUSED;
                this.f12652d.pause();
            }
            if (!this.f12653e.isComplete()) {
                this.f12653e = d.a.PAUSED;
                this.f12651c.pause();
            }
        }
    }
}
