package defpackage;

/* JADX INFO: loaded from: classes.dex */
class am2<Z> implements b28<Z> {
    public final boolean a;
    public final boolean b;
    public final b28 c;
    public final a d;
    public final v25 e;
    public int f;
    public boolean i;

    public interface a {
        void a(v25 v25Var, am2 am2Var);
    }

    public am2(b28 b28Var, boolean z, boolean z2, v25 v25Var, a aVar) {
        gf7.c(b28Var, "Argument must not be null");
        this.c = b28Var;
        this.a = z;
        this.b = z2;
        this.e = v25Var;
        gf7.c(aVar, "Argument must not be null");
        this.d = aVar;
    }

    @Override // defpackage.b28
    public final int a() {
        return this.c.a();
    }

    public final synchronized void b() {
        if (this.i) {
            throw new IllegalStateException("Cannot acquire a recycled resource");
        }
        this.f++;
    }

    @Override // defpackage.b28
    public final synchronized void c() {
        if (this.f > 0) {
            throw new IllegalStateException("Cannot recycle a resource while it is still acquired");
        }
        if (this.i) {
            throw new IllegalStateException("Cannot recycle a resource that has already been recycled");
        }
        this.i = true;
        if (this.b) {
            this.c.c();
        }
    }

    @Override // defpackage.b28
    public final Class d() {
        return this.c.d();
    }

    public final void e() {
        boolean z;
        synchronized (this) {
            int i = this.f;
            if (i <= 0) {
                throw new IllegalStateException("Cannot release a recycled or not yet acquired resource");
            }
            z = true;
            int i2 = i - 1;
            this.f = i2;
            if (i2 != 0) {
                z = false;
            }
        }
        if (z) {
            this.d.a(this.e, this);
        }
    }

    @Override // defpackage.b28
    public final Object get() {
        return this.c.get();
    }

    public final synchronized String toString() {
        return "EngineResource{isMemoryCacheable=" + this.a + ", listener=" + this.d + ", key=" + this.e + ", acquired=" + this.f + ", isRecycled=" + this.i + ", resource=" + this.c + '}';
    }
}
