package com.seewo.remote.e.h;

import android.annotation.SuppressLint;
import android.util.Log;
import com.seewo.remote.e.j.a;
import com.seewo.remote.e.j.b;
import com.seewo.remote.e.j.d;
import com.seewo.remote.g.w;
import com.seewo.sdk.model.SDKKeyboardCode;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import java.util.List;

/* JADX INFO: compiled from: MessageDecoder.java */
/* JADX INFO: loaded from: classes.dex */
public class e extends ByteToMessageDecoder {
    private com.seewo.remote.e.c.c b;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private com.seewo.remote.e.j.c f257e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private ChannelHandlerContext f258f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private List<Object> f259g;

    @SuppressLint({"CheckResult"})
    public e(com.seewo.remote.e.c.c cVar) {
        Log.v("MessageDecoder", "machineId1:" + com.seewo.remote.e.c.c.g());
        this.b = cVar;
        com.seewo.remote.e.j.c cVarA = a();
        this.f257e = cVarA;
        if (cVarA != null) {
            cVarA.a().o(new f.a.m.c() { // from class: com.seewo.remote.e.h.b
                @Override // f.a.m.c
                public final void accept(Object obj) throws Exception {
                    this.a.c((byte[]) obj);
                }
            }, new f.a.m.c() { // from class: com.seewo.remote.e.h.a
                @Override // f.a.m.c
                public final void accept(Object obj) {
                    e.c.d.y.e.d("MessageDecoder", (Throwable) obj);
                }
            });
        }
    }

    private com.seewo.remote.e.j.c a() {
        int iC = com.seewo.remote.d.b.b().c();
        if (w.k()) {
            if (iC == 1) {
                a.b bVar = new a.b();
                bVar.b(new byte[]{SDKKeyboardCode.FUNCTION_KEY_BOARD_J});
                return bVar.a();
            }
            if (iC == 0 || iC == -4) {
                b.C0011b c0011b = new b.C0011b();
                c0011b.c(new byte[]{SDKKeyboardCode.FUNCTION_KEY_BOARD_J});
                return c0011b.a();
            }
        }
        if (iC == -3) {
            b.C0011b c0011b2 = new b.C0011b();
            c0011b2.c(new byte[]{SDKKeyboardCode.FUNCTION_KEY_BOARD_J});
            return c0011b2.a();
        }
        if (iC == -2) {
            b.C0011b c0011b3 = new b.C0011b();
            c0011b3.b(new byte[]{-103});
            c0011b3.c(new byte[]{-86});
            return c0011b3.a();
        }
        if (iC == 2) {
            return b();
        }
        if (iC == 4) {
            b.C0011b c0011b4 = new b.C0011b();
            c0011b4.b(new byte[]{126});
            c0011b4.c(new byte[]{SDKKeyboardCode.FUNCTION_KEY_BOARD_J});
            return c0011b4.a();
        }
        if (iC != 8) {
            return null;
        }
        if (com.seewo.remote.d.b.b().e()) {
            return b();
        }
        b.C0011b c0011b5 = new b.C0011b();
        c0011b5.b(new byte[]{-87});
        c0011b5.c(new byte[]{-118});
        return c0011b5.a();
    }

    private com.seewo.remote.e.j.d b() {
        int iG = com.seewo.remote.e.c.c.g();
        Log.v("MessageDecoder", "machineId:" + iG);
        d.b bVar = new d.b();
        bVar.b(new byte[]{SDKKeyboardCode.FUNCTION_KEY_BOARD_F1, (byte) ((iG / 10) + 48), (byte) ((iG % 10) + 48)});
        bVar.c(new byte[]{SDKKeyboardCode.FUNCTION_KEY_BOARD_J});
        return bVar.a();
    }

    private void e(ChannelHandlerContext channelHandlerContext, List<Object> list, byte[] bArr) {
        try {
            if (this.b == null || !this.b.m(channelHandlerContext, bArr)) {
                e.c.d.y.e.a("MessageDecoder", "request message is not illegal");
            } else {
                com.seewo.remote.e.f.a aVarJ = this.b.j(bArr);
                e.c.d.y.e.a("MessageDecoder", "request message: " + com.seewo.remote.e.e.e.w(aVarJ.d()));
                list.add(aVarJ);
            }
        } catch (Exception e2) {
            Log.e("MessageDecoder", e2.getMessage(), e2);
        }
    }

    public /* synthetic */ void c(byte[] bArr) throws Exception {
        e(this.f258f, this.f259g, bArr);
    }

    @Override // io.netty.handler.codec.ByteToMessageDecoder
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) {
        this.f258f = channelHandlerContext;
        this.f259g = list;
        int i2 = byteBuf.readableBytes();
        byte[] bArr = new byte[i2];
        byteBuf.readBytes(bArr);
        e.c.d.y.e.a("MessageDecoder", w.a(bArr));
        if (this.f257e == null) {
            e(channelHandlerContext, list, bArr);
            return;
        }
        for (int i3 = 0; i3 < i2; i3++) {
            byte b = bArr[i3];
            if (com.seewo.remote.d.b.b().c() == 1) {
                this.f257e.b(b);
            } else if (b != 10) {
                this.f257e.b(b);
            }
        }
    }
}
