package eh;

import android.net.TrafficStats;
import android.os.Process;
import android.os.SystemClock;
import java.util.concurrent.BlockingQueue;

/* loaded from: classes4.dex */
public class i extends Thread {

    /* renamed from: p, reason: collision with root package name */
    private final BlockingQueue f17108p;

    /* renamed from: q, reason: collision with root package name */
    private final h f17109q;

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

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

    /* renamed from: t, reason: collision with root package name */
    private volatile boolean f17112t = false;

    public i(BlockingQueue blockingQueue, h hVar, b bVar, q qVar) {
        this.f17108p = blockingQueue;
        this.f17109q = hVar;
        this.f17110r = bVar;
        this.f17111s = qVar;
    }

    private void a(n nVar) {
        TrafficStats.setThreadStatsTag(nVar.J());
    }

    private void b(n nVar, u uVar) {
        this.f17111s.a(nVar, nVar.Q(uVar));
    }

    private void c() throws InterruptedException {
        d((n) this.f17108p.take());
    }

    void d(n nVar) {
        long elapsedRealtime = SystemClock.elapsedRealtime();
        nVar.S(3);
        try {
            try {
                try {
                    nVar.e("network-queue-take");
                } catch (Exception e10) {
                    v.d(e10, "Unhandled exception %s", e10.toString());
                    u uVar = new u(e10);
                    uVar.a(SystemClock.elapsedRealtime() - elapsedRealtime);
                    this.f17111s.a(nVar, uVar);
                    nVar.O();
                }
            } catch (u e11) {
                e11.a(SystemClock.elapsedRealtime() - elapsedRealtime);
                b(nVar, e11);
                nVar.O();
            }
            if (nVar.M()) {
                nVar.u("network-discard-cancelled");
                nVar.O();
                return;
            }
            a(nVar);
            k a10 = this.f17109q.a(nVar);
            nVar.e("network-http-complete");
            if (a10.f17117e && nVar.L()) {
                nVar.u("not-modified");
                nVar.O();
                return;
            }
            p R = nVar.R(a10);
            nVar.e("network-parse-complete");
            if (nVar.a0() && R.f17145b != null) {
                this.f17110r.d(nVar.y(), R.f17145b);
                nVar.e("network-cache-written");
            }
            nVar.N();
            this.f17111s.b(nVar, R);
            nVar.P(R);
        } finally {
            nVar.S(4);
        }
    }

    public void e() {
        this.f17112t = true;
        interrupt();
    }

    @Override // java.lang.Thread, java.lang.Runnable
    public void run() {
        Process.setThreadPriority(10);
        while (true) {
            try {
                c();
            } catch (InterruptedException unused) {
                if (this.f17112t) {
                    Thread.currentThread().interrupt();
                    return;
                }
                v.c("Ignoring spurious interrupt of NetworkDispatcher thread; use quit() to terminate it", new Object[0]);
            }
        }
    }
}
