package com.ifpdos.autotest.k0;

import android.content.Context;
import android.util.Log;
import com.ifpdos.autotest.model.RequestSession;
import com.seewo.libmcuservice.aidl.model.McuEnum;
import d.n;
import d.n0.c.l;
import d.n0.c.s;
import io.netty.channel.ChannelHandlerContext;
import java.util.concurrent.ConcurrentLinkedQueue;

/* JADX INFO: compiled from: NetWorker.kt */
/* JADX INFO: loaded from: classes.dex */
@n
public final class a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final C0074a f2012a = new C0074a(null);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private com.ifpdos.autotest.k0.b.a f2013b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private com.ifpdos.autotest.k0.b.a f2014c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final ConcurrentLinkedQueue<ChannelHandlerContext> f2015d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final b f2016e;

    /* JADX INFO: renamed from: com.ifpdos.autotest.k0.a$a, reason: collision with other inner class name */
    /* JADX INFO: compiled from: NetWorker.kt */
    @n
    public static final class C0074a {
        private C0074a() {
        }

        public /* synthetic */ C0074a(l lVar) {
            this();
        }
    }

    /* JADX INFO: compiled from: NetWorker.kt */
    @n
    public static final class b implements com.ifpdos.autotest.m0.a {
        b() {
        }

        @Override // com.ifpdos.autotest.m0.a
        public boolean a(ChannelHandlerContext channelHandlerContext) {
            s.e(channelHandlerContext, "handlerContext");
            return true;
        }

        @Override // com.ifpdos.autotest.m0.a
        public void b(RequestSession requestSession) {
            s.e(requestSession, McuEnum.KEY_DATA);
            a.this.d(requestSession);
        }

        @Override // com.ifpdos.autotest.m0.a
        public void c(ChannelHandlerContext channelHandlerContext) {
            s.e(channelHandlerContext, "handlerContext");
            if (a.this.f2015d.contains(channelHandlerContext)) {
                return;
            }
            a.this.f2015d.add(channelHandlerContext);
        }

        @Override // com.ifpdos.autotest.m0.a
        public void d(ChannelHandlerContext channelHandlerContext) {
            s.e(channelHandlerContext, "handlerContext");
            if (a.this.f2015d.contains(channelHandlerContext)) {
                a.this.f2015d.remove();
            }
        }
    }

    public a(Context context) {
        s.e(context, "context");
        this.f2015d = new ConcurrentLinkedQueue<>();
        this.f2016e = new b();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void d(RequestSession requestSession) {
        com.ifpdos.autotest.k0.e.b.a aVar = com.ifpdos.autotest.k0.e.b.a.f2035a;
        RequestSession.RequestType requestType = requestSession.getRequestType();
        s.d(requestType, "requestSession.requestType");
        com.ifpdos.autotest.lancontrol.module.base.b bVarA = aVar.a(requestType);
        if (bVarA != null) {
            bVarA.a(requestSession);
        }
    }

    public final void c() {
        Log.v("NetWorker", "TCP finish");
        com.ifpdos.autotest.k0.b.a aVar = this.f2013b;
        if (aVar != null) {
            s.b(aVar);
            aVar.c();
            this.f2013b = null;
        }
        com.ifpdos.autotest.k0.b.a aVar2 = this.f2014c;
        if (aVar2 != null) {
            s.b(aVar2);
            aVar2.c();
            this.f2014c = null;
        }
    }

    public final void e() {
        Log.v("NetWorker", "TCP work at port: 8688");
        if (this.f2013b == null) {
            this.f2013b = new com.ifpdos.autotest.k0.b.b(8688, this.f2016e);
        }
        com.ifpdos.autotest.k0.b.a aVar = this.f2013b;
        if (aVar != null) {
            aVar.b();
        }
        if (this.f2014c == null) {
            this.f2014c = new com.ifpdos.autotest.k0.b.b(8689, this.f2016e);
        }
        com.ifpdos.autotest.k0.b.a aVar2 = this.f2014c;
        if (aVar2 != null) {
            aVar2.b();
        }
    }
}
